{"text": "\\chapter{Dynamic Programming}\n\n\n\n\\section{Introduction}\nThe core philosophy of dp:\n\\begin{enumerate}\n\\item The definition of \\textbf{states} \n\\item The definition of the \\textbf{transition functions} among states \n\\end{enumerate} \n\nThe so called concept dp as memoization of recursion does not grasp the core philosophy of dp. \n\nThe formula in the following section are unimportant. Instead, what is important is the definition of dp array and transition function derivation.\n\\subsection{Common practice}\n\\runinhead{Dummy.} Use dummies to avoid using if-else conditional branch.\n\\begin{enumerate}\n\\item Use $n+1$ dp arrays to reserve space for dummies. \n\\item Iteration range is $[1, n+1)$.\n\\item $n+k$ for k dummies  \n\\end{enumerate}\n\\runinhead{State definition.} Two general sets of state definitions - the state \n\\begin{enumerate}\n\\item ends \\textit{at} index $i$\n\\item ends \\textit{before} index $i$\n\\item ends \\textit{at} or \\textit{before} index $i$\n\\end{enumerate}\n\n\\runinhead{Space optimization.} To avoid MLE, we need to carry out space optimization. Let $o$ be other subscripts, $f$ be the transition function. \n\nFirstly,\n$$\nF_{i, o} = f\\big(F_{i-1, o'}\\big)\n$$\n\nshould be reduced to \n$$\nF_{o} = f\\big(F_{o'}\\big)\n$$\n\nSecondly,\n$$\nF_{i, o} = f\\big(F_{i-1, o'}, F_{i-2. o'}\\big)\n$$\n\nshould be reduced to \n$$\nF_{i, o} = f\\big(F_{(i-1)\\%2, o'}, F_{(i-2)\\%2. o'}\\big)\n$$\n\nMore generally, we can be $(i-b)\\%a$ to reduce the space down to $a$.\n\nNotice:\n\\begin{enumerate}\n\\item Must iterate $o$ \\textbf{backward} to un-updated value. \n\\end{enumerate}\n\n\n\n\\section{Sequence}\\label{dpSequence}\n\n\\subsection{Single-state dp}\n\\runinhead{Longest common subsequence.} Let $F_{i, j}$ be the LCS at string $a[:i]$ and $b[:j]$. We have two situations: $a[i]==b[j]$ or not.\n\\begin{eqnarray*}\nF_{i. j} = \\left\\{ \\begin{array}{rl}\n  F_{i-1, j-1}+1 &\\mbox{// if $a[i]==b[j]$} \\\\\n  \\max\\Big(F_{i-1, j},&\\mbox{// otherwise} \\\\\n  F_{i,j-1}\\Big)\n       \\end{array} \\right.\n\\end{eqnarray*}\n\n\n\\runinhead{Longest common substring.} Let $F_{i, j}$ be the LCS at string $a[:i]$ and\n$b[:j]$. We have two situations: $a[i]==b[j]$ or not.\n\\begin{eqnarray*}\nF_{i. j} = \\left\\{ \\begin{array}{rl}\n  F_{i-1, j-1}+1 &\\mbox{// if $a[i]==b[j]$} \\\\\n  0 &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\n\nBecause it is not necessary that $F_{i,j}\\geq F_{i',j'}, \\forall i,j\\cdot i>i', j>j'$, the $gmax=max\\big(\\{{F_{i,j}\\}\\big)$.\n\\runinhead{Longest increasing subsequence}. Find the longest increasing subsequence of an array $A$.\n\nlet $F_i$ be the LIS length ends at $A_i$. \n\\begin{eqnarray*}\nF_i = \\max(F[j]+1 \\cdot\\forall j < i) \\text{ // if $A_i>A_j$}\n\\end{eqnarray*}\n\nThen the global $maxa$ is:\n$$\nmaxa = \\max(F_i\\cdot \\forall i)\n$$\n\nTime complexity: $O(n^2)$\n\nIn code, notice the \\pyinline{else}.\n\\begin{python}\nF[i] = max(\n    F[j] + 1 if A[i] > A[j] else 1\n    for j in xrange(i)\n)\n\\end{python}\n\nAlternative solution using binary search in $O(n \\log n)$ - Section \\ref{extremeValueProblem}.\n\n\\runinhead{Maximum subarray sum.} Find the maximum subarray sum of $A$. \n\nLet $F_i$  be the maximum subarray sum ending at $A_{i}$\n$$\nF_i = \\max(F_{i-1}+A_{i}, 0)\n$$\n\nThen the global $maxa$ is:\n$$\nmaxa = \\max(F_i\\cdot \\forall i)\n$$\n\n\n\\runinhead{Maximum sum of non-adjacent cells.} Get the maximum sum of non-adjacent\ncells of an array $A$.\n\nLet $F_i$ be the maximum sum of non-adjacent cells for $A[:i]$. You have tow options:\nchoose $A_{i-1}$ or not.\n\\begin{align*}\nF_{i} = \\max\\big(F_{i-1}, F_{i-2}+A_{i-1}\\big)\n\\end{align*}\n\\runinhead{Edit distance} Find the minimum number of steps required to convert words $A$ to $B$ using inserting, deleting, replacing. \n\nLet $F_{i, j}$ be the minimum number\nof steps required to convert $A[:i]$ to $B[:j]$.\n\\begin{eqnarray*}\nF_{i, j} = \\left\\{ \\begin{array}{rl}\n  F_{i-1, j-1} &\\mbox{// if $a[i]==b[j]$} \\\\\n  \\min\\Big(F_{i, j-1}+1, &\\mbox{// otherwise, insert}\\\\\n  F_{i-1, j}+1, &\\mbox{// delete}\\\\\n  F_{i-1, j-1}+1\\Big) &\\mbox{// replace}\\\\\n       \\end{array} \\right.\n\\end{eqnarray*}\n\n\\runinhead{Maximal square.} Find the largest rectangle in the matrix:\n\\begin{lstlisting}\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0\n\\end{lstlisting}\nLet $F_{i, j}$ represents the max square's length ended at $mat_{i, j}$ (lower right corner).\n\\begin{eqnarray*}\nF_{i, j} = \\left\\{ \\begin{array}{rl}\n  \\min\\big(F_{i-1, j-1}, F_{i-1, j}, F_{i, j-1}\\big)+1 &\\mbox{// if $mat_{i, j}==1$} \\\\\n  0 &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\n\n\\subsection{Dual-state dp}\n\\runinhead{Maximal product subarray.} Find the subarray within an array $A$ which has the largest product. \n\\begin{itemize}\n\\item Let $small_i$ be the smallest product end with $A_i$. \n\\item Let $large_i$ be the largest product end with $A_i$.\n\\item The states can be negative. \n\\end{itemize}\n\\begin{eqnarray*}\n&& small_i = \\min\\big( A_i,\\ small_{i-1}\\cdot A_i,\\ large_{i-1}\\cdot A_i \\big)\n\\nonumber \\\\\n&& large_i = \\max\\big( A_i,\\ small_{i-1}\\cdot A_i,\\ large_{i-1}\\cdot A_i \\big)\n\\end{eqnarray*}\n\nIt can be optimized to use space $O(1)$. \n\n\\runinhead{Trapping Rain Water}\nGiven n non-negative integers representing an elevation map where the width of each\nbar is 1, compute how much water it is able to trap after raining.\n\\begin{figure}[]\n    \\centerline{\\includegraphics[height = 1in]{rainwatertrap}}\n    \\caption{Trapping Rain Water}\n  \\label{fig:rainwatertrap}\n\\end{figure}\n\nLet $maxL_i$ be the $\\max(A[:i])$; let $maxR_i$ be the $\\max(A[i:n])$. The dp of obtaining max is trivial. \n\nThe the total volume $vol$:\n$$\nvol = \\sum_i(\\max\\big(0,\\min(maxL_i, maxR_{i+1})-A[i]\\big))\n$$\n\\runinhead{Zigzag subsequence.} Find the max length zigzag subsequence which goes up and down alternately within the array $A$.\n\nLet $U_i$ be the max length of zigzag subsequence end at $A_i \\wedge$ going up.\n\nLet $D_i$ be the max length of zigzag subsequence end at $A_i \\wedge$ going down.\n\\begin{align*}\nU_i &= max(D_j+1 \\cdot \\forall j < i) \\text{ // if $A_i > A_j$} \\\\ \nD_i &= max(U_j+1 \\cdot \\forall j < i) \\text{ // if $A_i < A_j$} \n\\end{align*}\n\nNotice in python implementation, don't use list comprehension since two states are interleaved and interdependent. \n\n\\section{String}\n\\runinhead{Word break.} Given a string $s$ and a dictionary of words $dict$, determine if $s$ can be segmented into a space-separated sequence of $dict$ words.\n\nLet $F_i$ be whether \\pyinline{s[:i]} can be segmented. \n\\begin{eqnarray*}\nF_{i} = \\left\\{ \\begin{array}{rl}\n  F_{i-len(w)} &\\mbox{// if $\\exists w\\in dict$, \\pyinline{s[i-len(w):i]==w}}\n\\\\\n  false &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\nReturn all such possible sentences. In original case, we use a bool array to record whether a dp could be segmented. Now we should use a vector for every dp to record how to construct that dp from another dp.\n\nLet $F_i$ be all possible segmented words ends at \\pyinline{s[i-1]}. $F_i$ is a list. $\\exists F_i$ means $F_i$ is not empty.\n\\begin{eqnarray*}\nF_{i} = \\left\\{ \\begin{array}{rl}\n  F_{i}+[w] &\\mbox{// $\\forall w\\in dict\\cdot$} \\\\\n  & \\mbox{ if \\pyinline{s[i-len(w):i]==w} $\\wedge\\ \\exists\nF_{i-len(w)$ } \\\\\n  F_{i}} &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\n\nReconstruct the sentence from $F_i$. It is like building path for the tree. Using backtracking: \n\\begin{python}\ndef build(self, dp, i, cur, ret):\n    if cur_index == 0:\n        ret.append(\" \".join(list(cur)))\n        return\n\n    # backtracking\n    for word in dp[i]:\n        cur.appendleft(word)\n        self.build(dp, i-len(word), cur, ret)\n        cur.popleft()\n\n\\end{python}\n\n\\runinhead{Is palindrome.} Given a string $s$, use an array to determine whether $s[i:j]$.\n\nLet $P_{i,j}$  indicates whether $s[i:j]$ is palindrome. We have one condition - whether the head and the end letter are equal: \n\\begin{eqnarray*}\nP_{i. j} = P_{i-1, j+1}\\ \\wedge\\ s[i] = s[j-1]\n\\end{eqnarray*}\n\nThe code for palindrome dp is error-prone due to indexing. Notice that $i \\in [0, n), j \\in [i, n+1)$.\n\\begin{python}\nn = len(s)\npa = [[False for _ in xrange(n+1)] for _ in xrange(n)]\nfor i in xrange(n):\n    pa[i][i] = True\n    pa[i][i+1] = True\n\nfor i in xrange(n-2, -1, -1):\n    for j in xrange(i+2, n+1):\n        pa[i][j] = pa[i+1][j-1] and s[i] == s[j-1]\n\\end{python}\n\\runinhead{Minimum palindrome cut.} Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s.\n\nLet $C_i$ be the min cut for $s[:i]$. We have 1 more cut from previous state to make $S[:i]$ palindrome. \n\\begin{eqnarray*}\nC_{i} = \\left\\{ \\begin{array}{rl}\n  \\min\\big(C[k]+1 \\cdot \\forall k<i \\big) &\\mbox{// if $s[k:i]$ is palindrome}\n\\\\\n  0 &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\n\\begin{python}\ndef minCut(self, s):\n  n = len(s)\n\n  P = [[False for _ in xrange(n+1)] for _ in xrange(n+1)]\n  for i in xrange(n+1):  # len 0\n    P[i][i] = True\n  for i in xrange(n):  # len 1\n    P[i][i+1] = True\n\n  for i in xrange(n, -1, -1):  # len 2 and above\n    for j in xrange(i+2, n+1):\n      P[i][j] = P[i+1][j-1] and s[i] == s[j-1]\n\n  C = [i for i in xrange(n+1)]  # max is all cut\n  for i in xrange(n+1):\n    if P[0][i]:\n      C[i] = 0\n    else:\n      C[i] = min(\n          C[j] + 1\n          for j in xrange(i)\n          if P[j][i]\n      )\n\n  return C[n]\n\\end{python}\n\\runinhead{ab string.} Change the char in a str only consists of `a' and `b' to non-decreasing order. Find the min number of char changes. \n\nTwo-state dp: `a' $\\rightarrow$ `b' and  `b' $\\rightarrow$ `a'. 1 cut into 2 segment.\n\n\\runinhead{abc string.} Follow up for ab string. Three-state dp: $chr \\neq a, chr \\neq b, chr \\neq c$. 2 cuts into 3 segments.\n\n\\section{Combinatorics}\n\\subsection{Tree}\n\\runinhead{Number of different BSTs.} It can be solved using Catalan number (Section \\ref{section:catalanNumber}), but here goes the dp solution. \n\\begin{lstlisting}\n   1         3     3      2      1\n    \\       /     /      / \\      \\\n     3     2     1      1   3      2\n    /     /       \\                 \\\n   2     1         2                 3\n\\end{lstlisting}\n\nLet $F_i$ be the \\#BSTs constructed from $i$ elements. The pattern is: \n\\begin{align*}\nF_3 = F_0*F_2 + F_1*F_1 + F_2*F_0\n\\end{align*}\n\nThus, in general, \n\\begin{align*}\nF_i = \\sum(F_{j}*F_{i-1-j} \\cdot \\forall j< i)\n\\end{align*}\n\n\\section{Backpack}\n\\subsection{Classical}\nGiven $n$ items with weight $w_i$ and value $v_i$, an integer $C$ denotes the size of a backpack. What is the max value you can fill this backpack?\n\nLet $F_{i, c}$ be the max value we can carry for index $0..i$ with capacity $c$. We have 2 choices: take the $i$-th item or not.\n\\begin{eqnarray*}\nF_{i, c}= \\max\\big(&&F_{i-1, c}, \\\\\n&&F_{i-1, c-w_i}+v_i\\big)\n\\end{eqnarray*}\nAdvanced backpack problem\\footnote{\\href{http://github.com/tianyicui/pack}{Nine Lectures in Backpack Problem}.}. \n\n\\subsection{Sum}\n\\runinhead{k sum.} Given $n$ distinct positive integers, integer $k$ ($k \\leq n$) and a number target. Find $k$ numbers where sum is target. Calculate the number of solutions. Since we only need the number of solutions, thus it can be solved using dp. If we need to enumerate all possible answers, need to do dfs instead. \n\n$$\nsum{j \\choose i} = v\n$$\n\nLet $F_{i, j, v}$ means the \\#ways of selecting $i$ elements from the first $j$ elements so that their sum equals to $v$. $j$ is the scanning pointer.\n\nYou have two options: either select $A_{j-1}$ or not.\n$$\nF_{i, j, v} = F_{i-1, j-1, v-A_{j-1}} + F_{i, j-1, v}\n$$\nTime complexity: O(n^2 k)\n\\section{Local and Global Extremes}\n\\subsection{Long and short stocks}\nThe following formula derives from the question: Best Time to Buy and Sell Stock IV. Say you have an array for which the $i$-th element is the price of a given stock on day $i$. Design an algorithm to find the maximum profit. You may complete at most $k$ transactions. \n\nLet $local_{i, j}$ be the max profit with $j$ transactions with last transactions \\textbf{ended at} day $i$. Let $global_{i, j}$ be the max profit with transactions \\textbf{ended at} or \\textbf{before} day $i$ with $j$ transactions. \n\nTo derive transition function for $local$, for any given day $i$, you have two options: 1) transact in one day; 2) hold the stock one more day than previous and then transact. The latter option is equivalent to revert yesterday's transaction and instead transact today. \n\nTo derive transition function for $global$, for any given day $i$, you have two options: 1) transact today; 2) don't transact today. \n\\begin{eqnarray*}\n&& local_{i,j} = \\max\\Big(global_{i-1.j-1}+\\Delta, local_{i-1,j}+\\Delta\\Big) \\nonumber \\\\\n&& global_{i,j} = \\max\\Big(local_{i, j}, global_{i-1,j}\\Big)\n\\end{eqnarray*}\n, where $\\Delta$ is the price change (i.e. profit) at day $i$.\\\\\nNotice:\n\\begin{enumerate}\n\\item Consider opportunity costs and reverting transaction.\n\\item The global min is not $glocal[-1]$ but $\\max\\big(\\{global[i]\\}\\big)$.\n\\item You must sell the stock before you buy again (i.e. you can not have higher than 1 in stock position). \n\\end{enumerate}\n\n\\runinhead{Space optimization.}\n\\begin{eqnarray*}\n&& local_{j} = \\max\\Big(global_{j-1} + \\Delta, local_{j}+\\Delta\\Big)\n\\nonumber \\\\\n&& global_{j} = \\max\\Big(local_{j}, global_{j}\\Big)\n\\end{eqnarray*}\n\nNotice,\n\\begin{enumerate}\n\\item Must iterate $j$ \\textbf{backward}; otherwise we will use the updated value. \n\\end{enumerate}\n\n\\runinhead{Alternative definitions.}\nOther possible definitions: let $global_{i, j}$ be the max profit\nwith transactions ended at or before day $i$ with \\textbf{up to} $j$ transactions. Then, \n\\begin{eqnarray*}\n&& local_{i,j} = \\max\\Big(global_{i-1.j-1} + \\max(0, \\Delta), local_{i-1,j}+\\Delta\\Big)\n\\nonumber \\\\\n&& global_{i,j} = \\max\\Big(local_{i, j}, global_{i-1,j}\\Big)\n\\end{eqnarray*}\nand $global[-1]$ is the global max. \n\nThe complexity of the alternative definitions is the same as the original definitions. The bottom line is that different definitions of states result in different transition functions.\n\n\\section{Game theory - multi players}\nAssumption: the opponent take the optimal strategy for herself. \n\n\\subsection{Coin game}\n\\runinhead{Same side} There are $n$ coins with different value in a line. Two players take turns to take 1 or 2 coins from left side. The player who take the coins with the most value wins.\n\nlet $F_i^p$ represents maximum values he can get for index $i..last$, for the person p. There are 2 choices: take the $i$-th coin or take the $i$-th and $(i+1)$-th coin.\n\\begin{eqnarray*}\nF_i^p = \\max\\big(&A_i&+S[i+1:]-F_{i+1}^{p'},  \\\\\n&A_i&+A_{i+1}+S[i+2:]-F_{i+2}^{p'}\\big)\n\\end{eqnarray*}\nThe above equation can be further optimized by merging the sum $S$.\n\n\\runinhead{Dual sides}There are n coins in a line. Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins.\n\nlet $F_{i, j}^p$ represents maximum values he can get for index $i..j$, for\nthe person p. There are 2 choices: take the $i$-th coin or take the $j$-th coin.\n\\begin{eqnarray*}\nF_{i,j}^p = \\max\\big(&A_i&+S[i+1:j]-F_{i+1,j}^{p'},  \\\\\n&A_j&+S[i:j-1]-F_{i,j-1}^{p'}\\big)\n\\end{eqnarray*}\n", "meta": {"hexsha": "75f580e21f07478a6ef2827ca6838505b5936721", "size": 15129, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterDynamicProgramming.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": "chapterDynamicProgramming.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": "chapterDynamicProgramming.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": 36.9, "max_line_length": 322, "alphanum_fraction": 0.6627007733, "num_tokens": 5165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6999548243771726}}
{"text": "\\section{The Riemann-Stieltjes Integral}\n\n\\subsection{Exercise 1}\nWe first note that $\\inf{f(x)} = 0$ on any interval $ [p_{i-1}, p_i] \\subset [a, b]$. Similarly,\n$\\sup{f(x)} = 0$ if $x_0 \\notin [p_{i-1}, p_i]$ and 1 otherwise. Thus, we proceed by constructing a\npartition $P$ of $[a, b]$ such that $x_0 \\in [p_{i-1}, p_i]$ and $\\alpha(p_i) - \\alpha(p_{i-1}) < \\epsilon$.\nThis is possible since $\\alpha$ is continuous at $x_0$, so there exists $\\delta$ such that choosing\n$p_i - p_{i-1} < \\delta$ gives us the previous inequality. We then have that  \n$U(P, f, \\alpha) - L(P, f, \\alpha) < \\epsilon$, so $f \\in \\mathscr{R}(\\alpha)$. Furthermore, since\n$L(P, f, \\alpha) = 0$ for all $P$, we have that $\\int_{a}^{b} f d\\alpha = 0$.\n\n\\subsection{Exercise 2}\nSince we're given $f(x) \\geq 0$ and $\\int_{a}^{b} f(x) dx = 0$, we have that $m = \\inf{f(x)} = 0$. Letting\n$m_i$ and $M_i$ denote the infimum and supremum of $f$ on the interval $[x_{i-1}, x_i] \\subset [a, b]$,\nwe further have that $m_i \\leq m \\implies m_i = 0 \\: \\forall i$. Additionally, since $f$ is continuous\non $[a, b]$ and therefore uniformly continuous (from compactness), we can choose a $\\delta$ such that\n\\begin{align*}\n        \\abs{x_i - x_{i-1}} < \\delta &\\implies \\abs{f(x_i) - f(x_{i-1})} < \\epsilon \\\\\n                                     &\\implies \\abs{M_i - m_i} < \\epsilon \\implies M_i < \\epsilon\n\\end{align*}\nThus, all of the $M_i$ can be made arbitrarily small, implying that $\\sup{f(x)} < \\epsilon$ for every \npositive $\\epsilon$. This gives us that $f(x) = 0$.\n\n\\subsection{Exercise 3}\n(a) Suppose $f(0+) = f(0)$. We consider the partition $P = {x_0, x_1, x_2, x_3}$ where  \n$x_0 = -1, x_1 = 0, x_3 = 1$. Then $U(P, f, \\beta_1) = M_2$ and $L(P, f, \\beta_1) = m_2$, and\nwe have that $M_2 \\to f(0)$ and $m_2 \\to f(0)$ as $x_2 \\to 0$, so $f \\in \\mathscr{R}(\\beta_1)$.\nFor the other direction, if $f \\in \\mathscr{R}(\\beta_1)$, then there exists $P$ such that \n$U(P, f, \\beta_1) - L(P, f, \\beta_1) < \\epsilon$. We can then consider the refinement $P^*$ of $P$ \nthat contains an interval of the form $[0, x_i]$. Suppose now that $\\abs{f(0+) - f(0)} = \\epsilon > 0$.\nThen\n\\begin{align*}\n        M_i - m_i \\geq \\abs{f(0+) - f(0)} > \\epsilon\n\\end{align*}\nwhich is a contradiction, so $f(0+) = f(0)$.\n\n(b) Only difference from (a) is that we need $f(0-) = f(0)$ instead of $f(0+) = f(0)$. The only changes that\nneed to be made to the proof of (a) involve replacing $[0, x_i]$ with $[x_{i-1}, 0]$.\n\n(c) If $f$ is continuous at 0, we can consider the partition $P$ that contains $x_{i-1} < x_i = 0 < x_{i+1}$.\nThen $U(P, f, \\beta_2) = \\frac{M_{i} + M_{i+1}}{2}$ and $L(P, f, \\beta_2) = \\frac{m_i + m_{i+1}}{2}$.\nSince $f$ is continuous at 0, $M_i, M_{i+1}, m_i, m_{i+1} \\to f(0)$ as $x_{i-1} \\to 0$ and $x_{i+1} \\to 0$,\nso $f \\in \\mathscr{R}(\\beta_2)$.\nFor the other direction, we proceed similarly to the proof of (a) and see that\n\\begin{align*}\n        \\frac{1}{2} (M_i + M_{i + 1}) - \\frac{1}{2} (m_i + m_{i + 1}) &= \\frac{1}{2} ((M_i - m_i) + (M_{i+1} - m_{i+1})) \\\\\n                                                                      &\\geq \\frac{1}{2} (\\abs{f(0-) - f(0)} + \\abs{f(0+) - f(0)}) \\\\\n                                                                      &> \\epsilon\n\\end{align*}\nfor some $\\epsilon > 0$ unless $f(0-) = f(0+) = f(0)$, so  $f$ must be continuous at 0 if  $f \\in \\mathscr{R}(\\beta_2)$.\n\n(d) If $f$ is continuous at 0 then we have $f(0+) = f(0-) = f(0)$, so we are done by parts (a)-(c).\n\n\\subsection{Exercise 4}\nFrom the density of the rationals and irrationals in the reals, we have that $M_i - m_i = 1 \\: \\forall i$, so\n$f \\notin  \\mathscr{R}$.\n\n\\subsection{Exercise 5}\nIf we consider $f(x) = 1$ for all rational $x$ and $f(x) = -1$ for all irrational $x$, we have that\n$f^2 \\in \\mathscr{R}$ but $f \\notin \\mathscr{R}$. However, if $f^3 \\in \\mathscr{R}$, then $f \\in \\mathscr{R}$.\nThis is because $m \\leq f^3 \\leq M$ (since $f$ is bounded) and $x^{\\frac{1}{3}}$ is continuous on any\n$[m, M]$, so we can apply Theorem 6.11.\n\n\\subsection{Exercise 6}\n$P$ is compact, so the open cover consisting of neighborhoods around each point of $P$ has a finite subcover.\nThus, $P$ can be covered by finitely many segments. Additionally, the total length of these segments can be\nmade arbitrarily small, since $P$ contains no segments itself. We can then proceed exactly as in the proof of\nTheorem 6.10 to get the desired result.\n\n\\subsection{Exercise 7}\n(a) If $f \\in \\mathscr{R}$, then by Theorem 6.12 (c) we have\n\\begin{align*}\n        \\abs{\\int_{c}^{1} f dx - \\int_{0}^{1} f dx} &= \\abs{\\int_{0}^{c} f dx} \\\\\n                                                    &\\leq cM < \\epsilon \\quad \\text{for} \\:\\:  c < \\frac{\\epsilon}{M}\n\\end{align*}\nWhere $M = \\sup{f}$ on $[0, 1]$.\n\n(b) Consider $f$ such that\n\\begin{align*}\n        f(x) =\n        \\begin{cases}\n                0 & x = 0 \\\\\n                \\frac{1}{x} & 0 < x < \\frac{1}{2} \\\\\n                0 & x = \\frac{1}{2} \\\\\n                -\\frac{1}{x} & \\frac{1}{2} < x \\leq 1\n        \\end{cases}\n\\end{align*}\nThen $\\int_{0}^{1} f dx = 0$, but $\\int_{0}^{1} \\abs{f} dx$ diverges.\n\n\\subsection{Exercise 8}\nWe see that the partition $P = {1, 2, ..., b + 1}$ of the interval $[1, b + 1]$ corresponds to the upper sum\n$U(P, f) = \\sum_{n = 1}^b f(n)$, and $\\int_{1}^{b + 1} f(x) dx \\leq U(P, f)$. \nThus, if $\\sum_{n = 1}^\\infty f(n)$ converges, then we have that \n$\\int_{1}^{b + 1} f(x) dx$ is bounded and monotonically increasing (since $f(x) \\geq 0$),\nso $\\int_{1}^{\\infty} f(x) dx $ converges. For the other direction, we can take the same partition $P$ \nand consider $L(P, f) = \\sum_{n = 1}^b f(n + 1)$. Since $L(P, f) \\leq \\int_{1}^{b + 1} f(x) dx$, if \n$\\int_{1}^{\\infty} f(x) dx$ converges then so does $\\sum_{n = 2}^\\infty f(n)$, and we are done (as\n$f(1) < \\infty$).\n\n\\subsection{Exercise 9}\nTheorem: Let $f$ and $g$ be differentiable functions on $[0, \\infty)$ such that \n$\\lim_{x \\to \\infty} f(x)g(x) = 0$ and $f', g' \\in \\mathscr{R}$ for every $[0, b]$. Then we have that\n\\begin{align*}\n        \\int_{0}^{\\infty} f(x) g'(x) dx = -f(0)g(0) - \\int_{0}^{\\infty} f'(x) g(x) \n\\end{align*}\nif both improper integrals converge.\n\nProof: Take limits on both sides of the integration by parts formula.\n\nLetting $f(x) = \\frac{1}{1 + x}$ and $g'(x) = cos(x)$ in the above formula shows that \n\\begin{align*}\n        \\int_{0}^{\\infty} \\frac{cos(x)}{1 + x} dx = \\int_{0}^{\\infty} \\frac{sin(x)}{(1 + x)^2} dx  \n\\end{align*}\n\nWe have that $\\abs{cos(n)} + \\abs{cos(n + 1)} \\geq c$ for some\nconstant $c$ since $cos(n)$ and $cos(n + 1)$ cannot both be 0. As such, \n$\\sum_{n = 1}^\\infty \\frac{cos(n)}{1 + n}$ diverges since the harmonic series diverges and therefore\nthe integral on the left also diverges by the integral test.\n\n\\subsection{Exercise 10}\n(a) We can use the convexity of $e^x$ to show this. Let $\\lambda = \\frac{1}{p}$ and let $u^p = e^a, v^q = e^b$\nfor some $a, b$ (this is possible because $u, v \\geq 0$). Then we have\n\\begin{align*}\n        e^{\\lambda a + (1- \\lambda) b} &\\leq \\lambda u^p + (1 - \\lambda) v^q \\\\\n        e^{\\lambda a} e^{(1 - \\lambda) b} &\\leq \\frac{u^p}{p} + \\frac{v^q}{q} \\\\\n        uv &\\leq \\frac{u^p}{p} + \\frac{v^q}{q}\n\\end{align*}\n\n(b) From part (a) we have that \n\\begin{align*}\n        f(x) g(x) &\\leq \\frac{f^p(x)}{p} + \\frac{g^q(x)}{q} \\\\\n        \\int_{a}^{b} fg d\\alpha &\\leq 1 \n\\end{align*}\n\n(c) We can use part (a) with  $u = \\frac{\\abs{f(x)}}{\\bigg(\\int_{a}^{b} f^p d\\alpha\\bigg)^{\\frac{1}{p}}}$ \nand $v = \\frac{\\abs{g(x)}}{\\bigg(\\int_{a}^{b} g^q d\\alpha\\bigg)^{\\frac{1}{q}}}$ to get the desired result.\n\n(d) Assuming the limits exist, the inequality follows for impromper integrals by taking limits on both sides\nand then using limit rules.\n", "meta": {"hexsha": "21fa41d3160b116a000d743cb6011f89adbece34", "size": 7717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_6.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_6.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_6.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.1214285714, "max_line_length": 132, "alphanum_fraction": 0.5776856291, "num_tokens": 3000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8688267626522814, "lm_q1q2_score": 0.699954806641055}}
{"text": "\\documentclass[oneside]{book}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{authblk}\r\n\\usepackage{setspace} \r\n\\usepackage{amsmath}\r\n\\usepackage{textcomp}\r\n\\usepackage{amssymb}\r\n\\usepackage{geometry}\r\n\\usepackage{amsthm}\r\n\\usepackage{runic}\r\n\\usepackage{mathtools}\r\n\\usepackage{graphicx}\r\n\\usepackage[breaklinks=true,a4paper=true,pagebackref=true]{hyperref}\r\n\\graphicspath{ {figures/} }\r\n\\geometry{\r\n a4paper,\r\n total={170mm,257mm},\r\n left=20mm,\r\n top=20mm,\r\n}\r\n\\hypersetup{\r\n    colorlinks=true,\r\n    linktoc=true,\r\n    linkcolor=blue,\r\n}\r\n\\title{Libraria Algebrae}\r\n\\author{Liam Gardner}\r\n\\date{\\today}\r\n%\\doublespacing\r\n\\newcommand\\tab[1][1cm]{\\hspace*{#1}}\r\n\\newcommand\\nextline{\\newline\\tab}\r\n\\newcommand\\nextquestion{\\newline\\newline}\r\n\\newcommand\\soln{$\\text{sol}^\\text{n}\\text{ }$}\r\n\\newcommand\\fs{\\mbox{\\large $\\mathrlap{f}s\\,$}\\,}\r\n\\newcommand\\thm[2]{\\section*{Theorem: #1}\\label{sec:#2}\\addcontentsline{toc}{section}{Theorem: #1}}\r\n\\newcommand\\propn[2]{\\section*{Proposition: #1}\\label{sec:#2}\\addcontentsline{toc}{section}{Proposition: #1}}\r\n\\newcommand\\defn{\\textbf{Definition}: }\r\n\r\n\\renewcommand\\mod[1]{\\text{ }\\left(\\text{mod }#1\\right)}\r\n\r\n\r\n\\begin{document}\r\n\\DeclarePairedDelimiter\\abs{\\lvert}{\\rvert}\r\n\r\n\\maketitle\r\n\\tableofcontents\r\n\\chapter{Linear Diophantine Equations in $\\mathbb{Z}^2$}\r\n\\tab\r\nNote that for the general equation $ax+by$, we assume that $ab\\neq0$, since if one is 0, then the equation is trivial. We wish to answer three fundamental problems\r\n\\begin{enumerate}\r\n\\item Does there exist an integer solution?\r\n\\item If the answer is yes, find an integer solution.\r\n\\item Can we find \\textit{all} solutions?\r\n\\end{enumerate}\r\n\\tab\r\nIt is common for existential theorems (those that say solutions exist) to not give a means of how to find said solutions.\r\n\\subsection{Example}\r\nSolve $506x + 391y = 23$. Notice that $\\gcd(506,391)=23$. Thus, by b\\'ezout's\\ lemma, a solution exists. We can use the EEA (Extended Euclidean Algorithm) to find a solution to the equation. \r\n\\newline\r\n\\begin{center}\r\n\\begin{tabular}{|c|c|c|c|}\r\n\\hline\r\n$x$ & $y$ & $r$ & $q$ \\\\\r\n\\hline\r\n\\hline\r\n1 & 0 & 506 & 0 \\\\\r\n0 & 1 & 391 & 0 \\\\\r\n1 & -1 & 115 & 1.0 \\\\\r\n-3 & 4 & 46 & 3.0 \\\\\r\n7 & -9 & 23 & 2.0 \\\\\r\n-17 & 22 & 0 & 2.0 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nThus, we know that $(7,-9)$ is a solution. Now, we can subtract the equation $506x+391y=23$ with $506x_0 + 391y_0=23$, which gives $506(x-x_0) + 391(y-y_0) = 0$. Thus, we get $506(x-x_0) = -391(y-y_0)$. We can divide by the GCD of 506 and 391 to get the equation $22(x-x_0) = -17(y-y_0)$. Since the GCD is a common divisor to 506 and 391, we get that both $\\frac{506}{23}$ and $\\frac{391}{23}$ are integers and are coprime to each other. Now, since we know that $-17\\lvert -17(y-y_0)$, and that $-17(y-y_0)=22(x-x_0)$, we get that $-17\\lvert 22(x-x_0)$. Thus, by CAD, we get $17\\lvert (x-x_0)$. Therefore, we find that $x-x_0 = 17n$ for some $n\\in\\mathbb{Z}$. Thus, a solution for $x$ can be found with $x_0 + 17n$, $\\forall n\\in\\mathbb{Z}$.\r\n\\nextline\r\nFollowing the same process, we get that $y=y_0+22n$. Therefore, all solutions to the Linear Diophantine Equation $506x + 391y = 23$ are given by the points $(7 + 17n, -9 - 22n)$.\r\n\\newline\r\n\\newline\r\nSolve $506x + 391y = 24$.\r\n\\nextline\r\nThere are no \\soln: Since $23=\\gcd(506,391)$, we get that $23\\lvert 506x+391y$ however, $23\\nmid 24$, therefore, we've run into a contradiction.\r\n\\newline\r\n\\newline\r\nSolve $506x + 391y = 46 = 2\\cdot23$. We know that $506\\cdot7 + 391\\cdot(-9) = 23$, thus if we multiply both sides by two, we get that $506(7\\cdot2) + 391(-9\\cdot2) = 2\\cdot23 = 46$. $506(14) + 391(-18) = 46$ gives the \\soln (14,-18).\r\n\r\n\\thm{LDET Part 1}{ldeta}\r\n\r\nSuppose $a,b,c\\in\\mathbb{Z}$ and $ab\\neq0$ then $ax+by=c$ has a \\soln in integers if and only if $\\gcd(a,b)\\lvert c$.\r\n\\subsection{Proof of forwards direction}\r\n\\tab\r\nAssume $ax+by=c$ has an integer \\soln $(x_0, y_0)$. Let $d=\\gcd(a,b)$. Since $d\\lvert a$ and $d\\lvert b$, and since $c=ax_0+by_0$, then by Divsibility of Integer Combinations, $d\\lvert c$.\r\n\\subsection{Proof of backwards direction}\r\n\\tab\r\nLet $d=\\gcd(a,b)$, and assume that $d\\lvert c$, thus $c=kd$ \\fs integer $k$. Then By B\\'ezout's\\ Lemma, we can find $x_0$ and $y_0$ $\\in\\mathbb{Z}$ such that $ax_0+by_0=d$, but then $k(ax_0+by_0)=kd$. Thus $a(kx_0) + b(ky_0) = c$\r\n\\subsection{Remark}\r\n\\tab\r\nif $d\\lvert c$ then the proof tells us how to find a \\soln.\r\n\\begin{enumerate}\r\n\\item solve $ax+by=d$ using EEA to get $(x,y)=(x_0,y_0)$.\r\n\\item take $x=kx_0$ and $y=ky_0$, where $k=\\frac{c}{d}$.\r\n\\end{enumerate}\r\n\r\n\\thm{LDET Part 2}{ldetb}\r\n\r\nSuppose that $(x_0, y_0)$ is a particular solution to the LDE $ax+by=c$.\r\n\\nextline\r\nThen the set of all \\soln $\\in\\mathbb{Z}$ is given by the following set:\r\n$$S = \\left\\{\r\n(x,y) \\Huge\\mid x=x_0 + \\frac{b\\cdot n}{\\gcd(a,b)},\\,\\,\\, y=y_0 - \\frac{a\\cdot n}{\\gcd(a,b)}\r\n\\right\\}$$\r\n\\subsection{Proof}\r\n\\tab\r\nLet $D$ be the set of all integer solutions to $ax+by=c$. I.E.\r\n$$D = \\left\\{(x,y) \\mid x,y,\\in\\mathbb{Z}, ax+by=c \\right\\}$$\r\n\\tab\r\nThis can be proven by showing $S \\subseteq D$ and $D \\subseteq S$\r\n\\newline $S\\subseteq D:$\r\n\\nextline\r\nLet $(x,y) \\in S$, thus $x=x_0 + \\frac{bn}{d}$ and $y=y_0-\\frac{an}{d}$.\r\n$$ax+by = a\\left(x_0+\\frac{bn}{d}\\right) + b\\left(y_0 - \\frac{an}{d}\\right)$$\r\n$$= ax_0 + by_0 = c$$\r\n\\tab\r\nsince by definition, we know that $x_0$ and $y_0$ are a particular solution to the equation. Therefore, $S\\subseteq D$\r\n\\newline $D\\subseteq S:$\r\n\\nextline\r\nLet $(x,y)\\in D$, thus $x,y\\in\\mathbb{Z}$ and $ax+by=c$. Since, $(x_0,y_0)\\in D$, we know that $ax_0 + by_0 = c$. We can subtract $ax_0+by_0=c$ from $ax + by = c$ to get $a(x-x_0) + b(y-y_0) = 0$. Dividing by the GCD of $a$ and $b$, we get that $\\frac{a(x-x_0)}{d} = \\frac{-b(y-y_0)}{d}$. Thus, since $\\frac{b}{d}\\lvert \\frac{a}{d}(x-x_0)$ then by CAD, we get that $\\frac{b}{d}\\lvert (x-x_0)$, since $\\frac{b}{d}$ and $\\frac{a}{d}$ are coprime. Then we get $x-x_0=n\\frac{b}{d}\\Rightarrow x=x_0+\\frac{bn}{d}$ \\fs $n\\in\\mathbb{Z}$. Similarly, we get $y=y_0-\\frac{an}{d}$. Therfore, $(x,y)\\in S$.\r\n\\section{More Examples}\r\n$12x+18y=13$.\r\n\\nextline\r\n$\\gcd(12,18) = 6$. Since $6\\nmid13$ the equation has no \\soln by \\hyperref[sec:ldeta]{LDET1}\r\n\\newline\r\n\\newline\r\n$14x-49y=28$\r\n\\nextline\r\n$\\gcd(14,-49) = 7$. Since $7\\lvert 28$ the equation has solutions by \\hyperref[sec:ldetb]{LDET2}\r\n\\nextline\r\nConsider $14x-49y=7\\Rightarrow 2x-7y=1$ which has \\soln $(4,1)$. If we multiply $14(4) - 49(1) = 7$ by 4, we get that $14(x_0\\cdot4) - 49(y_0\\cdot4) = 7$, and from this we can get all \\soln using LDET2.\r\n\\newline\r\n\\newline\r\n\\tab\r\nFind all \\soln to $15x+35=5$.\r\n\\newline\r\n\\begin{center}\r\n\\begin{tabular}{|c|c|c|c|}\r\n\\hline\r\n$x$ & $y$ & $r$ & $q$ \\\\\r\n\\hline\r\n\\hline\r\n1 & 0 & 15 & 0 \\\\\r\n0 & 1 & 35 & 0 \\\\\r\n1 & 0 & 15 & 0.0 \\\\\r\n-2 & 1 & 5 & 2.0 \\\\\r\n7 & -3 & 0 & 3.0 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nThus, we know that $\\gcd(15,35)=5$, and $5\\lvert 5$, there is a \\soln. By EEA, we find $x=-2, y=1$ is a \\soln. Then, we can find the general solution using\r\n\\hyperref[sec:ldetb]{LDET2}\r\n to be $x=-2+\\frac{35n}{5}\\Rightarrow 7n-2$, $y=1+\\frac{15n}{5}\\Rightarrow 1+3n$\r\n\\subsection{Geometric Understanding}\r\n\\tab\r\nGraphing the line $15x+35y=5$ or $3x+7y=1$, we can rearrange for $y$ to get $y=\\frac{-3}{7}x+\\frac{1}{7}$. Thus, picking any lattice point, we can construct a triangle of length 7 and height 3 from that point to find the next lattice point.\r\n\r\n\\begin{figure}[h]\r\n\\centering\r\n\\includegraphics[width=0.5\\textwidth]{l24f0}\r\n\\caption{Triangle formed from moving between two lattice points}\r\n\\end{figure}\r\n\r\n\\subsection{Nonnegative \\soln}\r\n\\tab\r\nThe solutions to $15x+35y=5$ is given by $(-2+7n, 1-3n)$, these will be nonnegative if $x\\geq0$ and $y\\geq0$.\r\n$$-2+7n\\geq 0 \\iff n\\geq \\frac{2}{7}$$\r\n$$1-3n \\geq 0 \\iff n \\leq \\frac{1}{3}$$\r\nThus, since there are no integer solutions in the range $\\frac{2}{7}\\leq n \\leq \\frac{1}{3}$, as $n\\in\\mathbb{Z}$ there are no nonnegative solutions.\r\n\\subsection{Find all integer \\soln to $15x+35y^2 = 5$}\r\n\\tab\r\nLet $Y=y^2$, then, since we have the \\soln to $15x+35Y=5$, given by $(-2+7n, 1-3n)$, all we have to do is see when $1-3n$ is a perfect square.\r\nOne way to solve this is to say let $z=y^2$ and solve $1-3n=z$. We can also solve this algebraically\r\n\\newline\r\n\\begin{center}\r\n\\begin{tabular}{c c c}\r\n$\\iff$ & $1-3n = y^2$ & \\\\\r\n$\\iff$ & $-3n=y^2-1$ & \\\\\r\n$\\iff$ & $3\\lvert y^2-1$ & by euclid's lemma \\\\\r\n$\\iff$ & $3\\lvert(y-1)(y+1)$ & \\\\\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nBy Euclid's Lemma, we know either $3\\lvert(y-1)$ or $3\\lvert(y+1)$, though not both. Suppose $3\\lvert(y-1) \\iff y-1=3k\\iff y=3k+1\\, \\fs k\\in\\mathbb{Z}$\r\nThen, if $y=3k+1$, we get that $y^2=(1+3k)^2=1-3(-2k-3k^2)$. Let $n=(-2k-3k^2)$, then we get $y^2=1-3n$. Thus, if we take $x=-2+7n=-2+7(-2-3k^2)$ and $y=1-3k$, we get a perfect square \\soln to the diophantine equation. \r\n\\nextline\r\nIf $3\\lvert y+1$, then we have $y=-1+3l\\, \\fs l \\in \\mathbb{Z}$. Then $y^2=(-1+3l)^2=1-3(2l+3l^2)$. Thus, $y=1-3l$ and $x=-2+7(2l+3l^2)$. Therfore, we can generate infinitely many perfect square solutions.\r\n\\chapter{Congruence and Modular Arithmetic}\r\n\\section{Clockwork Arithmetic Analogy}\r\n\\tab\r\nImagine a clock, we know that a clock has 12 spokes. If we look at it and see the hour hand at 2, and we know that 12 has already passed, then we also know that the clock really means it's 14. Thus, we can say $2\\approx14$\r\n\\section{Definition}\r\n\\tab\r\n$\\forall a,b\\in\\mathbb{Z}$, we say that ``$a$ is congruent to $b$ mod(ulo) 12'' if $m\\lvert(a-b)$.\r\n\\nextline\r\nNotation: $a\\equiv b\\mod{m}$\r\n\\section{Examples}\r\n\\tab\r\n$m=1$ then $a\\equiv b\\mod{1} \\iff 1\\lvert (a-b)$ which is true $\\forall a,b\\in\\mathbb{Z}$\r\n\\nextline\r\n$m=2$ then $a\\equiv b\\mod{2} \\iff 2\\lvert (a-b) \\iff a-b$ is even $\\iff a$ and $b$ are both even or both odd.\r\n\\nextline\r\n$2\\equiv-116\\mod{2}$, however $3\\not\\equiv 10024\\mod{2}$\r\n\\nextline\r\n$14\\equiv 2\\mod{12} \\iff 12\\lvert(14-2)$\r\n\\nextline\r\n$6\\equiv 26\\mod{10} \\iff 10\\lvert(6-26)$\r\n\\nextline\r\n$6\\not\\equiv -26\\mod{10} \\implies 10\\nmid(6+26)$\r\n\\propn{Congruence is an Equivalence Relation}{CER}\r\n\\begin{center}\r\n\\begin{tabular}{l|l}\r\n$\\forall m\\in\\mathbb{N}, \\forall a,b,c,\\in\\mathbb{Z}$ & Congruence is \\\\\r\n\\hline\r\n\\hline\r\n$a\\equiv a\\mod{m}$ & symmetric \\\\\r\nif $a\\equiv b\\mod{m}$ and $b\\equiv c\\mod{m}$ then $a\\equiv c\\mod{m}$ & transitive \\\\\r\n$a\\equiv b \\mod{m}\\implies b\\equiv a\\mod{m}$ & Reflexive\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nRemark: Any relation $a\\sim b$ that satisfies all above properties is called an equivalence relation.\r\n\\nextline\r\nIn calculus, we say two functions $f(x)\\sim g(x)$ are an equivalence relation if $f^\\prime(x) = g^\\prime(x)$\r\n\\section{Recap}\r\n\\tab\r\nFix $m\\in\\mathbb{N}$, $\\forall a,b\\in\\mathbb{Z}$\r\n\\nextline\r\n\\begin{tabular}{l c l}\r\n$a\\equiv b\\mod{m}$ & $\\iff$ & $m\\lvert (a-b)$ \\\\\r\n& $\\iff$ & $a-b=mk\\,\\, \\fs k\\in\\mathbb{Z}$ \\\\\r\n& $\\iff$ & $a=b+mk$\r\n\\end{tabular}\r\n\\newline\r\n\\propn{Arithmetic Rules of Congruence}{ARC}\r\nSuppose $a\\equiv a^\\prime \\mod{m}$ and $b\\equiv b^\\prime \\mod{m}$ then,\r\n\\begin{enumerate}\r\n\\item $a+b\\equiv a^\\prime + b^\\prime \\mod{m}$\r\n\\item $a-b\\equiv a^\\prime - b^\\prime \\mod{m}$\r\n\\item $ab\\equiv a^\\prime b^\\prime \\mod{m}$\r\n\\end{enumerate}\r\n\\subsection{Examples}\r\n$$2\\equiv 9\\mod{7}\\land3\\equiv 17\\mod{7}\\implies 2+3\\equiv9+17\\mod{7}\\implies 5=26$$\r\n\\newline\r\n$$56\\cdot30 \\mod{40}$$\r\n$$56=16+40\\equiv 16\\mod{40}$$\r\n$$30=-10\\equiv \\mod{40}$$\r\n$$56\\cdot30 \\equiv 16\\cdot(-10)\\mod{40}$$\r\n$$\\equiv-160\\mod{40}$$\r\n$$\\equiv-40\\cdot4\\mod{40}\\equiv 0\\mod{40}$$\r\n\\subsection{Proof of addition}\r\n\\tab\r\nSince $a\\equiv a^\\prime \\mod{m}$ and $b\\equiv b^\\prime \\mod{m}$ then $m\\lvert(a-a^\\prime)$ and $m\\lvert(b-b^\\prime)$\r\n\\nextline\r\nWe have $(a+b)-(a^\\prime-b^\\prime)=a-a^\\prime + b-b^\\prime$, thus by DIC we get $m\\lvert((a+b)-(a^\\prime+b^\\prime))$. Therefore $a+b\\equiv a^\\prime + b^\\prime \\mod{m}$\r\n\\subsection{Remark on Division}\r\n\\tab Care is needed with division\r\n$ab\\equiv ac\\mod{m} \\not\\implies b\\equiv c\\mod{m}$ even if $a\\not\\equiv 0 \\mod{m}$\r\n\\nextline\r\n$$10\\equiv 4\\mod{6}$$\r\n$$2\\cdot5 \\equiv 2\\cdot2 \\mod{6}$$\r\n$$5\\not\\equiv 2\\mod{6}$$\r\n\\propn{Congruent Division}{CD}\r\n\\tab\r\nIf $ab\\equiv ac\\mod{m}$ and $a$ is coprime to $m$, then $b\\equiv c\\mod{m}$\r\n\\propn{Congruent Powers}{CP}\r\n\\tab\r\n$a\\equiv b\\mod{m}\\implies a^n\\equiv b^n\\mod{m}$\r\n\\subsection{Proof}\r\n\\tab\r\n$$ab\\equiv bc\\mod{m}\\iff m\\lvert (ab-ac)\\iff m\\lvert a(b-c)$$\r\n\\nextline\r\nThen by CAD we get $m\\lvert(b-c)$ since $m$ and $a$ are coprime\\nextline\r\n$\\implies b\\equiv c \\mod{m}$\r\n\\nextline\r\nBy applying the above proposition repeatedly; if $a_1\\equiv a^\\prime_1 \\mod{m}, a_2\\equiv a^\\prime_2 \\mod{m}, \\cdots a_n\\equiv a^\\prime_n \\mod{m}$, then we get the following result\r\n\\begin{enumerate}\r\n\\item $a_1+\\cdots+a_n\\equiv a^\\prime_1 + \\cdots a^\\prime_n \\mod{m}$\r\n\\item $a_1-\\cdots-a_n\\equiv a^\\prime_1 - \\cdots a^\\prime_n \\mod{m}$\r\n\\item $a_1\\cdots a_n\\equiv a^\\prime_1 \\cdots a^\\prime_n \\mod{m}$\r\n\\item (special case) $\\forall q \\in \\mathbb{N}, a^q \\equiv \\left(a^\\prime\\right)^q \\mod{m}$\r\n\\end{enumerate}\r\n\\subsection{More Examples}\r\nSimplify $4^10 \\mod{18}$\\nextline\r\n$4^{10} = \\left(4^2\\right)^5 = 16^5=(18-2)^5$ \\nextline\r\n$(18-2)^5\\equiv-2^5\\mod{18}$ \\nextline\r\n$\\equiv-32\\mod{18}$ \\nextline\r\n$-32+2\\cdot 18\\mod{18}$ \\nextline\r\n$4\\mod{18}$\r\n\\newline\r\n\\newline\r\nIs $3^9 + 62^{2020} - 20$ divisible by 7?\r\n\\nextline\r\nLet $n=3^9+62^{2020}-20$. We know that $7\\lvert n \\iff 7\\lvert(n-0) \\iff n\\equiv0\\mod{7}$\r\n\\nextline\r\nWe can compute $3^9=\\left(3^3\\right)^3=27^3=(28-1)^3$ \\nextline\r\n$\\equiv (-1)^3\\mod{7}$\\nextline\r\n$\\equiv -1\\mod{7}$\\nextline\r\nWe also know that $62^{2020} = (63-1)^{2020} \\equiv (-1)^{2020}\\mod{7} \\equiv 1$ \\nextline\r\n$20=21-1\\equiv -1\\mod{7}$ \\nextline\r\nUsing \\hyperref[sec:ARC]{The arithmetic rules} we get that $n\\equiv -1+1-(-1)\\mod{7}\\equiv1\\mod{7}$ and thus $n$ is not divisible by 7.\r\n\\thm{Congruence and Remainders}{CR}\r\n\\subsection{Example}\r\n\\tab\r\nWhat day of the week is it going to be a year from now?\r\n\\nextline\r\nSince days cycle every 7, let's determine $365\\mod{7}$. We know that $350=50\\cdot7$ and thus \\nextline $365 = 350 + 15$ \\nextline\r\n$=7\\cdot50+14+1$ \\nextline\r\n$=7\\cdot50+7\\cdot2+1$\\nextline\r\n$=7(50+2)+1$\\nextline\r\n$\\equiv 1\\mod{7}$.\\nextline\r\n$365\\equiv1\\mod{7}$\\nextline\r\nTherefore, the day of the week one year from now is the same as the day of the week tomorrow.\r\n\\subsection{Observation}\r\n\\tab\r\nif $n\\in\\mathbb{Z}$ \\nextline\r\nAny block of consecutive numbers will cycle through the numbers 0-6 inclusive:\r\n$$\\{\\cdots,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,\\cdots\\}$$\r\n$$\\equiv\\{\\cdots,0,1,2,3,4,5,6,0,1,2,3,4,5,6,0,1,2,3,4,5,6,\\cdots\\}\\mod{7}$$\r\n\\section{Warning}\r\n\\tab\r\n$\\forall a,b,b^\\prime \\in \\mathbb{N}$, if $b\\equiv b^\\prime \\mod{m}$ then in general $a^b\\not\\equiv a^{b^\\prime}\\mod{m}$\r\n\\subsection{Example}\r\n\\tab\r\n$4\\equiv1\\mod{3}$\\nextline\r\n$2^4=16\\equiv1\\mod{3}$ however $2^1\\equiv 2\\mod{3}$ \\nextline\r\nThus $4\\equiv1\\mod{3}$ however $2^4\\not\\equiv2^1\\mod{3}$\r\n\\propn{Finite Integers}{FI}\r\n$\\forall a,b,\\in\\mathbb{Z} a\\equiv b \\mod{m}\\iff a$ and $b$ have the same remainder after division by $m$\r\n\\subsection{Proof}\r\n\\tab\r\nApplying the division algorithm, we get $a=qm+b$ and $b=q^\\prime m+r^\\prime$ where $0\\leq r,r^\\prime < m$.\\nextline\r\nNotice if $a\\equiv b\\mod{m}$, we get that $m\\lvert(a-b)$ and thus $m\\lvert(qm+r - q^\\prime m - r^\\prime)$\\nextline\r\n$\\implies m\\lvert(m(q+q^\\prime) + (r-r^\\prime))$ Then by DIC it follows that \\nextline\r\n$\\iff m\\lvert (r-r^\\prime)$ \\nextline\r\nNow since $0\\leq r < m$ and $0 \\leq r^\\prime < m$, we get that $-m\\leq r-r^\\prime < m$. Now, since $m\\lvert(r-r^\\prime)$, we get that by BBD, that $m\\leq \\abs{r-r^\\prime}$ and so for both inequalities to hold, $r=r^\\prime$.\r\n\\propn{Congruent if and only if same remainder}{CISR}\r\n\\tab\r\n$a\\equiv b\\mod{m} \\iff a$ and $b$ have the same remainder after division by $m$.\r\n\\propn{Congruent to Remainder}{CTR}\r\n$\\forall a,b\\in\\mathbb{Z}\\,, 0\\leq b \\leq m-1 : a\\equiv b\\mod{m}\\iff$ the remainder of $a$ after division by $m$ is $b$.\r\n\\nextline\r\nConsequently, every $a\\in\\mathbb{Z}$ is congruent to a unique integer in $[0,m-1]\\subseteq\\mathbb{Z}$  mod $m$.\r\n\\subsection{Examples}\r\n\\begin{tabular}{r l l}\r\n25 & $\\equiv 32$ & $\\mod{7}$ \\\\\r\n& $\\equiv 18$ & $\\mod{7}$ \\\\\r\n& $\\equiv 11$ & $\\mod{7}$ \\\\\r\n& $\\equiv \\mathbf{4}$ & $\\mod{7}$ \\\\\r\n& $\\equiv -3$ & $\\mod{7}$ \\\\\r\n& $\\equiv -10$ & $\\mod{7}$ \\\\\r\n& $\\cdots$ & $\\mod{7}$\r\n\\end{tabular}\r\n\\nextline\r\n4 is distinguished, as it is the remainder of 25 after division by 7.\r\n\\newline\r\n\\nextline\r\n\\textit{Find the remainder of $5^{10}$ after division by 7}\r\n\\nextline\r\nWe want to compute $5^{10}\\mod{7}$. Since $5^{10} = \\left(5^2\\right)^5 = 25^5$. We know $25\\equiv 4\\mod{7}$ and by\r\n\\hyperref[sec:CP]{Congruent Powers}\r\nwe get $\\equiv 4^5\\mod{7}$\r\n\\nextline\r\n$\\equiv 4^3\\cdot 4^2\\mod{7}$ \\nextline\r\n$\\equiv (63+1) \\cdot (14+2) \\mod{7}$ \\nextline\r\n$\\equiv 1\\cdot 2 \\mod{7}$ \\nextline\r\n$\\equiv 2\\mod{7}$ \\nextline\r\nTherefore, the remainder of $5^{10}$ after division by 7 is 2.\r\n\\newline\r\n\\nextline\r\n\\textit{Find the remainder of} $77^{100}\\cdot 999 - 6^{83} \\mod{4}$\r\n\\nextline\r\nWe know that $77=80-3\\equiv -3\\mod{4}\\equiv 1\\mod{4}$ by \\hyperref[sec:CP]{Congruent Powers}.\r\n$999=1000-1\\equiv -1\\mod{4}\\equiv 3\\mod{4}$. Now, notice that $6^{83}=6^2\\cdot6^{81}$ and since $6^2\\equiv 0\\mod{4}$ we get that $0\\cdot6^{81}\\equiv 0\\mod{4}$ by \\hyperref[sec:CP]{Congruent Powers}\r\n\\nextline\r\n$77^{100}\\cdot999 - 6^{83} \\equiv 1^{100}\\cdot3 - 0\\mod{4} \\equiv 3\\mod{4}$\r\n\\hyperref[sec:ARC]{Congruence and Multiplication}\r\n\\subsection{Sum of Factorial Example}\r\n\\tab\r\n\\textit{What is the last decimal of the following expression?}\r\n$$\\sum_{n=1}^{100} n!$$\r\n\\nextline\r\nNotice that the last digit of a number is the remainder mod 10. As a smaller example, notice that $7!\\equiv 0\\mod{10}$ because $7!$ contains a factor $2\\cdot5=10$ and thus is a multiple of 10. Therefore, we know that if $k\\geq 5$ we get that $k!\\equiv 0\\mod{10}$\r\n\\nextline\r\nGoing back to our original problem, we can notice that $\\forall n\\geq 5$ the sum of $n!\\mod{10}$ will be zero, and thus we only have to compute $1!+2!+3!+4!=1+2+6+24=33\\equiv 3\\mod{10}$\r\n\\section{Divisibility Rules}\r\n\\subsection{Divisibility by 3}\r\n\\tab\r\n$\\forall a \\in \\mathbb{Z} 3\\lvert a \\iff 3\\lvert$ the digit sum of $a$.\r\n\\nextline\r\n$3\\lvert 2046 \\iff 3\\lvert(2+0+4+6)$. $2+4+6=12$ and since $3\\lvert12$ we know $3\\lvert 2046$. \\nextline\r\n$3\\nmid271 \\iff 3\\nmid(2+7+1)$ $2+7+1=10$ and since we know $3\\nmid 10$ we know $3\\nmid 271$.\r\n\\subsection{Proof of divisibility by 3}\r\n\\tab\r\nIf the digits of $a$ are $d_k, d_{k-1}, d_{k-2}, \\cdots, d_1+d_0$ then $a=10^kd_k + 10^{k-1}d_{k-1}+10^{k-2}d_{k-2}, \\cdots, 10d_1, d_0$. This is called the decimal expansion of $a$. Since $10\\equiv 1\\mod{3}$ we get that \\newline$a\\equiv d_k + d_{k-1} + d_{k-2} + \\cdots + d_1 + d_0\\mod{3}$\r\n\\subsection{Divisibility by 11}\r\n\\tab\r\n$11\\lvert a \\iff 11\\lvert$ the alternatign sum of the digits of $a$\\nextline\r\n$11\\lvert108097\\iff 11\\lvert(1+8+9) - (0+0+7)$ and since $1+8+9-7=11$ and $11\\lvert 11$ we get that $11\\lvert 108097$\\nextline\r\n$11\\nmid133 \\iff 11\\nmid(1+3-3)$, thus $11\\nmid1\\implies 11\\nmid133$\r\n\\subsection{Proof of divisibility by 11}\r\n\\tab take\r\n$a=10^kd_k + 10^{k-1}d_{k-1}+10^{k-2}d_{k-2}, \\cdots, 10d_1+ d_0$ to be the decimal representation of $a$. Since $10\\equiv-1\\mod{11}\\equiv 10\\mod{11}$  thus\r\n$a\\equiv (-1)^kd_k + (-1)^{k-1}d_k-1 + \\cdots + (-1)^1d_1 + 1d_0$. Now, notice that this is the sum of the digits of $a$ indexed by even values of $k$ subtracted by the odd-indexed digits of $a$ mod 11.\r\n\\section{Linear Congruence Relations}\r\n\\subsection{Problem: does $x^3+x^2-x+1=0$ have an integer solution?}\r\n\\tab\r\nSuppse $x=a\\in\\mathbb{Z}$ is a \\soln. Thus, $a^3+a^2-a+1=0$. Thus, since both sides are integers, we know that $\\forall m \\in \\mathbb{N}$, $a^3+a^2-a+1\\equiv 0 \\mod{m}$.\r\n\\nextline\r\nConsider the equation in modulo 3. Notice now that $a$ can be either 0, 1, or 2 (mod 3). If $a\\equiv0\\mod{3}$ we get that $1\\equiv0\\mod{3}$ which is false. If $a\\equiv1\\mod{3}$ we get that $1+1=2\\equiv0\\mod{3}$ which is still false. If $a\\equiv2\\mod{3}$ then $a\\equiv-1\\mod{3}$ and thus we get $-1+1-(-1)+1=2\\equiv0\\mod{3}$ which is still false. Therefore, since there are no integer solutions moldulo 3, there are no integer solutions to the equation $a^3+a^2-a+1=0$.\r\n\\chapter{Linear Congruence}\r\n\\tab $y^2=4x+2$ can be solved over the integers by solving the relation mod m. If there are no solutions for a particular $m$, then there are no solutions over the integers. $y^2\\equiv4x+2\\mod{m}$. There's a finite process to check $y^2 \\equiv 4x+2\\mod{m}$ compared to the infinite process to check $y^2=4x+2$.\r\n\\nextline\r\n\\defn A Linear Congruence Equation is an equation of the form $ax\\equiv c\\mod{m}$ where $a,c\\in\\mathbb{Z}$ and $m\\in\\mathbb{N}$ are fixed and $a\\not\\equiv 0\\mod{m}$. We wish to find \\soln for $x$ over the integers.\r\n\\section{Methods of Solving}\r\n\\subsection{Brute Force}\r\n$5x\\equiv 2\\mod{3}$ \r\n\\begin{center}\r\n\\begin{tabular}{|c|c|c|c|}\r\n$x\\mod{3}$ & 0 & 1 & 2 \\\\\r\n\\hline\r\n$5x$ & 0 & 5 & 10 \\\\\r\n\\hline\r\n$5x\\mod{3}$ & 0 & 2 & 1 \\\\\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nWe see that the only solution to this is when $x\\equiv 1\\mod{3}$.\r\n\\subsection{LDE}\r\n$5x\\equiv 2\\mod{3} \\iff 5x=2+3k$ $\\fs k\\in\\mathbb{Z}$. \\nextline\r\n$\\iff 5x-3k=2$ \\nextline\r\n$\\iff 5x+3y=2$ for $y=-k$ \\nextline\r\nLet $d=\\gcd(5,3)$, then notice that $d\\lvert 2$ thus by \\hyperref[sec:ldeta]{LDET1} there are infinite solutions.\r\nSolve for $x,y$.\r\n\\nextline\r\nBy inspection we see that a particular \\soln is $(x_0,y_0) = (1,-1)$. Using \\hyperref[sec:ldetb]{LDET2} we can get the general solutions given by\r\n$$\\begin{cases}\r\nx=1 + 3n \\\\\r\ny=-1 - 5n\r\n\\end{cases}$$\r\n\\section{Examples}\r\n$2x\\equiv3\\mod{4}$\r\n\\nextline\r\nBy Method 1:\r\n\\begin{center}\r\n\\begin{tabular}{|c|c|c|c|c|}\r\n$x\\mod{4}$ & 0 & 1 & 2 & 3 \\\\\r\n\\hline\r\n$2x$ & 0 & 2 & 4 & 6 \\\\\r\n\\hline\r\n$2x\\mod{4}$ & 0 & 2 & 0 & 2 \\\\\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nSince there is no value of $3$ in the table, there is no \\soln to $2x\\equiv 3\\mod{4}$\r\n\\nextline\r\nBy Method 2:\r\n\\nextline\r\n$2x\\equiv3\\mod{4} \\iff 2x+4y=3$. Since $\\gcd(2,4)\\nmid3$, by \\hyperref[sec:ldeta]{LDET1} there is no \\soln to the equation.\r\n\\thm{Linear Congruence Theorem}{LC}\r\n\\tab\r\nConsider the Linear Congruence Equation $ax\\equiv c\\mod{m}$ where $a,c\\in\\mathbb{Z}$ and $m\\in\\mathbb{N}$ are fixed and $a\\not\\equiv 0\\mod{m}$. Let $d=\\gcd(a,m)$. Then, solutions exist if and only if $d\\lvert c$ by \\hyperref[sec:ldeta]{LDET1}. If $d\\lvert c$ and if $x_0$ is a \\soln then the general solution set is given by the following (using \\hyperref[sec:ldetb]{LDET2})\r\n$$\\left\\{\r\nx\\in\\mathbb{Z}\\mid x=x_0+\\frac{m}{d}n\\, \\fs n\\in\\mathbb{Z}\r\n\\right\\}$$\r\n$$\\left\\{\r\nx\\in\\mathbb{Z}\\mid x\\equiv x_0\\mod{\\frac{m}{d}}\r\n\\right\\}$$\r\n\\tab\r\nNotice for the second set, there are $d$ \\soln mod $m$\r\n\\subsection{Proof}\r\n$ax\\equiv c\\mod{m}\\iff ax+my=c$ so \\soln exist $\\iff d\\lvert c$ by \\hyperref[sec:ldeta]{LDET1}.\\nextline\r\nIf $x_0$ is a \\soln for x, then by \\hyperref[sec:ldetb]{LDET2} the general \\soln set is\r\n$$\\left\\{\r\nx\\in\\mathbb{Z} \\mid x=x_0+\\frac{m}{d}n\\,\\fs n\\in\\mathbb{Z}\r\n\\right\\}$$\r\n\\tab\r\nSince $x=x_0+\\frac{m}{d}n \\iff x\\equiv x_0\\mod{\\frac{m}{d}}$\r\n\\nextline\r\nFinally, if $x=x_0+\\frac{m}{d}n$ then by applying the Division Algorithm, we get $n=qd+r$, $0\\leq r < d$. Thus $x=x_0+\\frac{m}{d}n \\iff x=x_0+(qd+r)\\frac{m}{d} = x_0 + mq + r\\frac{m}{d}$\\nextline\r\n$\\iff x\\equiv x_0+r\\frac{m}{d}\\mod{m}$, $0\\leq r \\leq d-1$\r\n\\newline\r\n\\null\\hfill$\\mathcal{QED}$\r\n\\subsection{More Examples}\r\nSolve $12x\\equiv 9\\mod{15}$\\nextline\r\n\\soln: Step1: (gcd check)\r\n$d=\\gcd(12,15)=3$ and $3\\lvert9$ thus solutions exist\\newline\r\nStep2 (Particular \\soln)\\nextline\r\n$12x+15y=9$. By EEA we get $(x_0, y_0) = (-3,3)$.\\nextline\r\n$x\\equiv x_0\\mod{\\frac{m}{d}}$.\\nextline\r\n$\\equiv -3\\mod{5}$\\nextline\r\n$\\equiv 2\\mod{5}$\\nextline\r\n$x=2+5k$\\nextline\r\nSince the only unique solutions are in the integer range $[0,14]$, we know that the only solutions to $x=2+5k$ in that interval are $x\\equiv2,7,12\\mod{15}$.\r\n\\section{Nonlinear Congruence Equations}\r\n\\tab\r\nThere is no general/efficient method of finding solutions.\\nextline\r\n\\subsection{Examples}\r\n$x^2\\equiv 1\\mod{2}$.\r\n\\begin{center}\r\n\\begin{tabular}{|c|c|c|}\r\n$x$ & 0 & 1 \\\\\r\n\\hline\r\n$x^2$ & 0 & 1\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nThus $x\\equiv 1\\mod{2}$ is the only \\soln\r\n\\nextline\r\n$x^2\\equiv 1\\mod{4}$\r\n\\begin{center}\r\n\\begin{tabular}{|c|c|c|c|c|}\r\n$x$ & 0 & 1 & 2 & 3\\\\\r\n\\hline\r\n$x^2$ & 0 & 1 & 4 & 9 \\\\\r\n\\hline\r\n$x^2\\mod{4}$ & 0 & 1 & 0 & 1\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nTherefore, the solutions are $x\\equiv 1,3\\mod{4}$.\r\n\\nextline\r\nSolving $x^2\\equiv 1\\mod{8}$ gives 4 solutions $\\left(x\\equiv1,3,5,7\\mod{8}\\right)$. Solving $x^2\\equiv 1\\mod{2^k}\\, \\fs k\\geq3$ will have only 4 solutions.\r\n\\end{document}", "meta": {"hexsha": "a6446c20a17b649aaf3fcae10765dd2e1c606137", "size": 24837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Libraria Algebrae/Libraria Algebrae.tex", "max_stars_repo_name": "GardnerLiam/Libraria-Mathematica", "max_stars_repo_head_hexsha": "bfc2b3734230e883e439ea9bfec3b6c4103a01ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-23T20:16:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-23T20:16:39.000Z", "max_issues_repo_path": "Libraria Algebrae/Libraria Algebrae.tex", "max_issues_repo_name": "GardnerLiam/Libraria-Mathematica", "max_issues_repo_head_hexsha": "bfc2b3734230e883e439ea9bfec3b6c4103a01ed", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-17T06:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-17T06:21:41.000Z", "max_forks_repo_path": "Libraria Algebrae/Libraria Algebrae.tex", "max_forks_repo_name": "GardnerLiam/Libraria-Mathematica", "max_forks_repo_head_hexsha": "bfc2b3734230e883e439ea9bfec3b6c4103a01ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.5984990619, "max_line_length": 742, "alphanum_fraction": 0.6494745742, "num_tokens": 10165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478256, "lm_q2_score": 0.8688267711434708, "lm_q1q2_score": 0.6999548053726969}}
{"text": "\\subsection{Total variation}\\label{subsec:total_variation}\n\n\\begin{definition}\\label{def:riemann_stieltjes_integral}\n  The most common generalization of the \\hyperref[def:riemann_integral]{Riemann integral} is the Riemann-Stieltjes integral. It is not as well-behaved, hence we will give the most general definition and not attempt to prove equivalences.\n\n  Let \\( \\mscrX \\) be a real \\hyperref[def:separation_axioms/T2]{Hausdorff} \\hyperref[def:topological_vector_space]{topological vector space}. Fix two \\hyperref[def:function]{functions} \\( f, \\alpha: [a, b] \\to X \\).\n\n  The \\term{Riemann sum} of \\( f \\) with respect to \\( \\alpha \\) corresponding to the \\hyperref[def:riemann_partition/tagged]{tagged partition} \\eqref{eq:def:riemann_partition/tagged} is defined as\n  \\begin{equation*}\n    S(f, \\alpha, \\Delta, \\Xi) \\coloneqq \\sum_{k=1}^n f(\\xi_k) (\\alpha(x_k) - \\alpha(x_{k-1})).\n  \\end{equation*}\n\n  The limit of the net\n  \\begin{equation}\\label{eq:def:riemann_stieltjes_integral/net}\n    \\{ S(f, \\alpha, \\Delta, \\Xi) \\}_{(\\Delta, \\Xi) \\in \\op{tpart}([a, b])},\n  \\end{equation}\n  if it exists, is called the \\term{Riemann-Stieltjes integral} of \\( f \\) with respect to \\( \\alpha \\) and is denoted by\n  \\begin{equation*}\n    \\int_a^b f(x) d \\alpha(x).\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "90632af471eed3aef692741385a9e568115ce795", "size": 1294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/total_variation.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/total_variation.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/total_variation.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.8181818182, "max_line_length": 237, "alphanum_fraction": 0.7117465224, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.699866664977754}}
{"text": "\\section{Linear hypothesis using linear regression}\n\n\\subsection{Data}\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{scatter_plot.png}\n  \\caption{Scatter plot of data}\n  \\label{fig:scatter_plot}\n\\end{figure}\n\n\\subsection{Implementation}\nA linear function given by equation \\ref{eq:simple_linear_model} was selected as the hypothesis.\nLinear regression with learning learning rate($\\alpha$) = 0.01 and gradient descent approach was used for optimizing the parameters.\nThe training stopped after reaching the maximum allowed number of iterations which was 10000.\nFor this specific dataset we can use a threshold of 0.5 to classify the data. The predicting data\ncan be assigned a class 1 (fail) if $h_{\\theta}$(x) $<$ 0.5 and class 2 (pass) otherwise.\n\n\\begin{equation}\n\\label{eq:simple_linear_model}\nY = \\theta_0 + \\theta_1 * X\n\\end{equation}\n\n\\subsection{Observation}\nThe final values of $\\theta$s for a run are as follows:\n\n% Theta 0 final value\n\\begin{equation}\n\\theta_0 = -0.15184881886181856\n\\end{equation}\n\n% Theta 1 final value\n\\begin{equation}\n\\theta_1 = 0.23405702659773173\n\\end{equation}\n\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{regression_line_0_01.png}\n  \\caption{Linear regression line}\n  \\label{fig:regression_line}\n\\end{figure}\n\nThe regression line corresponding to the above $\\theta$s is shown in figure \\ref{fig:regression_line}\n\n\\subsection{Source Code}\n\\lstinputlisting[language=python]{task_1.py}\n", "meta": {"hexsha": "066669b36bd1d0b2e71510a91694102dda5c0627", "size": 1519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/linear_classifier.tex", "max_stars_repo_name": "diwasblack/machine_learning", "max_stars_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/linear_classifier.tex", "max_issues_repo_name": "diwasblack/machine_learning", "max_issues_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/linear_classifier.tex", "max_forks_repo_name": "diwasblack/machine_learning", "max_forks_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7555555556, "max_line_length": 132, "alphanum_fraction": 0.7774851876, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6998666639950148}}
{"text": "% !TeX root = ./apxthy.tex\n\n\n\\section{Least Squares Methods}\n\n\\subsection{Motivation}\n%\nWe first describe least squares methods in abstract terms. Let\n$[a,b]$ be an interval and\n$b_1, \\dots, b_N \\in C([a,b])$ be $N$ linearly independent basis functions\nfor an approximation space\n\\[\n    \\AA_N   := {\\rm span}\\b\\{ b_1, \\dots, b_N \\b\\}.\n\\]\nGiven $w \\in C(a,b) \\cap L^1(a,b)$ (note the open interval!) we can\ndefine a weighted $L^2$-inner product\n\\[\n    \\< f, g \\>_{L^2_w} := \\int_a^b w(x) f(x) g(x)^* \\,dx,\n\\]\nwith associated norm $\\|f\\|_{L^2_w} := \\<f,f\\>_{L^2_w}^{1/2}$. The best\napproximation of a function $f \\in C([a,b])$ with respect to this weighted norm\nis then given by\n\\begin{equation} \\label{eq:lsq:ctslsq}\n    p_N \\in \\min_{p \\in \\AA_N} \\b\\| f - p \\b\\|_{L^2_w}^2.\n\\end{equation}\nWe call this a continuous least squares problem.\n\nComputationally, we typically need to discretise \\eqref{eq:lsq:ctslsq}.\nTo that end, we choose points $x_1, \\dots, x_M \\in [a, b]$ and weights\n$w_1, \\dots w_M$ and define the discrete inner product\n\\begin{equation} \\label{eq:lsq:disip}\n    \\< f, g \\>_{\\ell^2_w} := \\sum_{m = 1}^M w_m f(x_m) g(x_m)^*\n\\end{equation}\nwith associated norm $\\|f\\|_{\\ell^2_w} := \\<f,f \\>_{\\ell^2_w}^{1/2}$. This\ngives the discrete least squares problem\n\\begin{equation}\n    \\label{eq:lsq:dislsq}\n    p_N \\in \\min_{p \\in \\AA_N} \\b\\| f - p \\b\\|_{\\ell_w^2}.\n\\end{equation}\nThis is the typical kind of least squares problem encountered in\nreal applications.\n\nWe distinguish two scenarios:\n\\begin{enumerate}\n\\item {\\bf User Chooses Data: } In this scenario the ``user'' is given a\nfunction $f$ to be approximated. She may then choose the points $x_m$, weights\n$w_m$ and evaluations $f(x_m)$ in order to fine-tune and optimise the fit $p_N$.\nFor example it is then feasible to start from \\eqref{eq:lsq:ctslsq} and design a\ndiscrete LSQ system \\eqref{eq:lsq:dislsq} that approximates\n\\eqref{eq:lsq:ctslsq} in a suitable sense. An arbtirary amount of data $(x_m,\nf(x_m))$ may then be generated to ensure a good fit.\n\n\\item {\\bf Data is provided: } Some data has been collected outside the control\nof the person (``user'') designing the fit. Given the data points $(x_m, f(x_m))$\n(possibly subject to noise, i.e. $y_m = f(x_m) + \\eta_m$ is then provided)\none then needs to choose an appropriate approximation space $\\AA_N$,\napproximation degree $N$ and weights $w_m$ to ensure a good fit in a sense\ndictated by the application.\n\\end{enumerate}\n\nWe will study both scenarios but note that the second one is the more\ntypical in applications.\n\n\\subsection{Solution methods}\n%\n\\label{sec:lsq:soln}\n%\nWe convert \\eqref{eq:lsq:dislsq} into a linear algebra problem.\nBy writing\n\\[\n    Y_m := f(x_m),  \\sqrt{W} := {\\rm diag}(\\sqrt{w_1}, \\dots, \\sqrt{w_m}) \\in \\R^{M \\times M}\n\\]\nand\n\\[\n    p(x_m) = \\sum_{n = 1}^N c_n b_n(x_m) = A c,\n    \\quad \\text{where }  A_{mn} = b_n(x_m),\n\\]\nthen $A \\in \\R^{M \\times N}$ and we obtain\n\\[\n    \\sum_{m = 1}^M w_m | p(w_m) - f(x_m)|^2\n    = \\big\\| \\sqrt{W} A c - \\sqrt{W} Y \\big\\|^2,\n\\]\nwhere $\\|\\cdot\\|$ denotes the standard Euclidean norm in $\\R^M$.\nWe write $\\tilde{A} := \\sqrt{W} A, \\tilde{Y} := \\sqrt{W} Y$ and\nwrite the least squares functional equivalently as\n\\[\n    \\Phi(c) := \\big\\| \\sqrt{W} A c - \\sqrt{W} Y \\big\\|^2\n    = c^T \\tilde{A}^T \\tilde{A} c - 2 c^T \\tilde{A}^T \\tilde{Y} + \\|\\tilde{Y}\\|^2.\n\\]\nA minimiser must satisfy $\\nabla\\Phi(c) = 0$, which gives the linear system\n\\begin{equation} \\label{eq:lsq:normaleqns}\n    \\tilde{A}^T\\tilde{A} c = \\tilde{A}^T \\tilde{Y}.\n\\end{equation}\nThese are called the normal equations, which can be solved using\nthe LU or Cholesky factorisation.\n\nIt turns out that they are often (though not always) ill-conditioned.\nAn alternative approach is therefore to perform the (numerically stable)\n{\\em thin QR factorisation}\n\\[\n    \\tilde{A} = Q R,\n\\]\nwhere $R \\in \\R^{N \\times N}$ is upper triangular and  $Q \\in \\R^{M \\times N}$\nhas ortho-normal columns, i.e., $Q^T Q = I \\in \\R^{N \\times N}$.\nWith the QR factorisation in hand the normal equations can be rewritten as\n\\begin{align*}\n    \\tilde{A}^T\\tilde{A} c &= \\tilde{A}^T \\tilde{Y} \\\\\n    \\Leftrightarrow \\qquad\n    R^T Q^T Q R c &= R^T Q^T \\tilde{Y} \\\\\n    \\Leftrightarrow \\qquad\n    R c &= Q^T \\tilde{Y},\n\\end{align*}\nprovided that $R$ is invertible (which is equivalent to $A^T A$ being invertible\nand to $A$ having full rank). Thus, the solution of the least squares problem\nbecomes\n\\begin{equation}\n    \\label{eq:lsq:qr}\n    R c = Q^T \\sqrt{W} Y, \\qquad \\text{where} \\qquad\n    \\sqrt{W} A = QR.\n\\end{equation}\n\nIt is worthwhile comparing the computational cost of the two approaches.\n\\begin{enumerate}\n\\item The assembly of thenormal equations requires the multiplication\n$A^T A$ which requires $O(M N^2)$ operations, followed by  the\nCholesky factorisation of $A^T A$ which requires $O(N^3)$ operiations.\nThus the cost of solving \\eqref{eq:lsq:normaleqns} is $O(M N^2)$.\n\\item The cost of the QR factorisation in \\eqref{eq:lsq:qr} is\n$O(M N^2)$ as well, while the inversion of $R$ is only $O(N^2)$ and the\nmultiplication with $Q^T$ is $O(NM)$.\n\nThus both algorithms scale like $O(M N^2)$.\n\\end{enumerate}\n\n\n\\subsection{Orthogonal Polynomials}\n%\n\\label{sec:lsq:orthpolys}\n%\nWe have so far encountered orthogonal polynomials in the context of the\nChebyshev basis, which arise naturally due to their connection to trigonometric\npolynomials. More generally, we can consider orthogonal polynomials with respect\nto {\\em any} inner product $\\<\\cdot, \\cdot\\>$. For simplicity we will continue\nto work on the domain $[-1, 1]$. In the context of least squares problems, we\ncan think of \\eqref{eq:lsq:ctslsq} or \\eqref{eq:lsq:dislsq} and the inner\ncontinuous or discrete products associated with these least squares problems.\n\nThe main result we want to discuss here is that the three-point recursion\n\\eqref{eq:poly:chebrecursion} for the Chebyshev basis is not special, but that\nall families of orthogonal polynomials satisfy such a recursion. That is,\ngiven an inner product $\\< \\cdot, \\cdot\\>$ we will construct sequences of\ncoefficients, $A_k, B_k, C_k$ such that the sequence of polynomials given by\n%\n\\begin{equation} \\label{eq:lsq:general_3ptrec}\n    \\phi_{k+1}(x) := (x - B_k) \\phi_k(x) - C_k \\phi_{k-1}(x)\n\\end{equation}\n%\nare orthogonal. By construction, we immediately see that the leading term in\n$\\phi_{k}$ is $x^k$; hence they also span the space of all polynomials.\n\nTaking the inner product of \\eqref{eq:lsq:general_3ptrec} with $\\phi_k$ and then\n$\\phi_{k-1}$ we obtain\n%\n\\begin{align*}\n    0 &= \\< x \\phi_k, \\phi_k \\> -  B_k \\< \\phi_k, \\phi_k \\>, \\\\\n    0 &= \\< \\phi_k, x \\phi_{k-1} \\> - C_k \\< \\phi_{k-1}, \\phi_{k-1} \\>,\n\\end{align*}\n%\nwhich gives expressions for $B_k, C_k$,\n%\n\\begin{equation} \\label{eq:lsq:coeffs_3pt}\n    \\begin{split}\n        B_k &:= \\frac{\\< x \\phi_k, \\phi_k \\>}{\\< \\phi_k, \\phi_k \\>}, \\\\\n        C_k &:= \\frac{\\< \\phi_k, x \\phi_{k-1} \\>}{\\< \\phi_{k-1}, \\phi_{k-1} \\>}.\n    \\end{split}\n\\end{equation}\n%\nIt is worth noting that this construction is simply the Gram-Schmidt procedure,\nbut truncated at a three-term recursion rather than the full recursion to\n$\\phi_0$. In particular, by construction, we have that $\\phi_{k+1} \\perp \\phi_k,\n\\phi_{k-1}$ and it only remains to show that they it is also orthogonal to\n$\\phi_0, \\dots, \\phi_{k-2}$. Concretely we obtain the following result.\n\n\\begin{proposition}\n    Suppose that $\\< \\cdot, \\cdot\\>$ is an inner product on  the space of\n    polynomials such that the operator $p \\mapsto x \\cdot p$ is self-adjoint,\n    (i.e., $\\<x p, q\\> = \\< p, xq\\>$ for all polynomials $p, q$). Suppose,\n    moreover, that $\\phi_0 = 1, \\phi_1 = x - \\<1, x\\>$, and that $\\phi_k, k \\geq 2,$\n    is given by the three-point recursion \\eqref{eq:lsq:general_3ptrec} with\n    coefficients \\eqref{eq:lsq:coeffs_3pt}. Then $\\{ \\phi_k : k \\in \\N \\}$ is\n    a basis of the space of polynomials which is orthogonal with respect to\n    $\\< \\cdot, \\cdot \\>$.\n\\end{proposition}\n\\begin{proof}\n    By construction we have that $\\phi_1 \\perp \\phi_0$ and that $\\phi_{k+1}\n    \\perp \\phi_k, \\phi_{k-1}$ for $k \\geq 2$. Thus, it only remains to prove\n    that, for $k \\geq 2$, $\\phi_{k+1} \\perp \\phi_j$ for $j = 0, \\dots, k-2$.\n\n    By induction we may assume that $\\< \\phi_j, \\phi_i \\> = 0$ for $i \\neq j$\n    and $i \\leq k$. Then, we have\n    \\begin{align*}\n        \\< \\phi_{k+1}, \\phi_j\\>\n        &=\n        \\< x \\phi_k, \\phi_j \\> - B_k \\< \\phi_k, \\phi_j\\> - C_k \\< \\phi_{k-1}, \\phi_j\\> \\\\\n        &=  \\< \\phi_k, x \\phi_j \\>,\n    \\end{align*}\n    where we also used self-adjointness of multiplication by $x$. Since\n    the degree of $x \\phi_j$ is at most $k-1$ and, again by induction, $\\phi_k$\n    is orthogonal to $\\phi_0, \\dots, \\phi_{k-1}$ it follows that\n    $\\< \\phi_k, x \\phi_j \\> = 0$. This completes the proof.\n\\end{proof}\n\n\n\\begin{exercise}\n    Derive a recursion for an {\\em orthonormal} basis of the form\n    \\begin{align*}\n        A_0 \\phi_0 &= 1, \\\\\n        A_1 \\phi_1 &= x - B_1, \\\\\n        A_k \\phi_k &= (x - B_k) \\phi_{k-1} - C_k \\phi_{k-2}.\n    \\end{align*}\n    Make sure to prove that all $A_k$ are non-zero.\n\\end{exercise}\n\n\\begin{exercise}\n    Consider the inner product\n    \\[\n        \\< p, q\\> =  \\int_{-1}^1 pq + p'q' \\, dx;\n    \\]\n    prove that the multiplication operator $p \\mapsto xp$ is not self-adjoint.\n\n    If we were to construct a sequence of orthogonal polynomials by  the\n    Gram-Schmidt procedure, would we again obtain a three-term recursion?\n\n    {\\it Hint: The involved calculations are somewhat boring. You may wish to use\n    a computer algebra system to explore this question.}\n\\end{exercise}\n\n\\begin{remark}\n    A discrete inner product of the form \\eqref{eq:lsq:disip} is not strictly\n    an inner product on the space of all polynomials, but depending on the\n    summation points it may be an inner product on a subspace $\\mathcal{P}_N$.\n    In this case the recursion formula can simply be terminated at degree\n    $k = N$ to obtain an orthogonal (or orthonormal) basis of $\\mathcal{P}_N$.\n\\end{remark}\n\n\n\n\\subsection{Accuracy and Stability I: Least Squares and Nodal Interpolation}\n%\nConsider fitting trigonometric polynomials $\\AA_{2N} = \\TT_N'$ with equispaced\ngrid points $x_n = \\pi n / N$ and uniform weights $w_n = 1$. Then the\nleast squares fit\n\\[\n    \\min \\sum_{n = 0}^{2N-1} |f(x_n) - t(x_n)|^2\n\\]\nis equivalent to trigonometric interpolation, for which we have sharp and error\nestimates that predict a close to optimal rate of approximation.\n\nWe could leave it at this, but it is still interesting to observe what happens\nto the least squares system. The matrix $A$ is now given by\n\\[\n    A_{nk} = e^{ikx_n}\n\\]\nand the entries in the normal equation by\n\\[\n    [A^* A]_{kk'} = \\sum_{n} e^{-ikx_n} e^{ik' x_n} = 2 N \\delta_{kk'}\n\\]\naccording to Exercise~\\ref{exr:trig:trapezoidal rule}(i).\nThis is due to the fact that the discrete inner product\n\\eqref{eq:lsq:disip}  (up to a constant factor) identical to\nthe $L^2(\\TT)$-inner product on the space $\\TT_N'$, that is,\n\\[\n    \\< f, g \\>_{\\ell^2} = 2N \\mint_{-\\pi}^\\pi f g^* \\,dx \\qquad\n    \\forall f, g \\in \\TT_N'.\n\\]\nNo QR factorisation is needed and the lsq fit is given by\n\\[\n    c = (2 N)^{-1} A^* Y,\n\\]\nwhere the operation $(2N)^{-1} A^T Y$ can be performed at $O(N \\log N)$\ncomputational cost using the FFT.\n\nAnalogous observations are of course true for connecting least squares\nmethods and algebraic polynomials.\n\n\n\\subsection{Accuracy and Stability II: Random data}\n%\n\\label{sec:lsq:rand}\n%\nThe situation gets more interesting when we are not allowed to optimise the\npoints at which to fit the approximant. There is an infinite variety of\ndifferent situations that can occur when the provided data is application\ndriven, which goes far beyond the scope of this module. Here, we will assume\nthat the points $x_m$ are distributed according to some probability law. That\nis, they are random. This is in fact a rather common situation in applications\nas well. Note also that we are now in the Case-2 situtation where we are given a\nfixed amount of data $(x_m, f(x_m))_{m = 1}^M$ and should choose $N$ ensure the\nbest possible fit given the data we have. In particular this means that we\nshould not choose $N$ too large!\n\nSpecifically, we shall assume throughout this section that\n\\begin{equation}\n    \\label{eq:lsw:wm_law}\n    x_m \\sim w \\,dx, \\qquad \\text{are iid}, \\quad \\text{for } m = 1, \\dots, M.\n\\end{equation}\n(identically and independently distributed) and without loss of generality that\n$\\int_a^b w \\,dx = 1$ as this can always be achieved by rescaling. We also\nassume that $w \\in C(a,b) \\cap L^1(a,b)$ as before. In this case, we can\nconstruct a sequence of orthogonal polynomials as in \\S~\\ref{sec:lsq:orthpolys}\nwith respect to the $L^2_w$-inner product and we will target best approximation\nwith respect to the same inner product.\n\nWe will discuss two fundamental results due to Cohen, Davenport and Leviatan\n\\cite{Cohen2013-yj}, but we won't prove them.  The first result concerns the\n{\\em stability} of the normal equations. Specifically, we will show that if we\nuse an $L^2_w$-orthogonal basis then $A^T A$ will be close to identity (and in\nparticular invertible) for a sufficiently large number of sample points $x_m$.\n\n\n\n\\begin{theorem}[Stability] \\label{th:lsq:randstab}\n    Let $\\phi_1, \\dots, \\phi_N$ be $L^2_w$-orthonormal, $A_{mk} := \\phi_k(x_m)$,\n    then\n    \\[\n        \\mathbb{P}\\B[ \\| A^* A - I \\|_{\\rm op} > \\delta\\B]\n        \\leq 2 N \\exp\\B( - \\smfrac{C_\\delta M}{K(N)}\\B),\n    \\]\n    where $C_\\delta = (1+\\delta) \\log (1+\\delta) - \\delta$ and\n    \\[\n        K(N) = \\sup_{x \\in [a,b]} \\sum_{k = 1}^N |\\phi_k(x)|^2.\n    \\]\n\\end{theorem}\n\nLet us specifically focus on the Chebyshev measure where $w(x) =\n(1-x^2)^{-1/2}$, the Chebyshev basis $T_k(x)$ on the interval $[a,b]= [-1,1]$.\nSince $|T_k(x)| \\leq 1$ it readily follows that $K(N) \\leq N$. Moreover, the\nrecursion formulat for $T_k$ implies that $T_k(1) = 1$ for all $k$, hence this\nbound is sharp, i.e., $K(N) = N$ in this case.\n\nTo make $N \\exp( - \\smfrac{C_\\delta M}{N})$ small, we therefore need\nto choose $N \\leq \\alpha M / \\log M$. With this choice,\n\\[\n    N \\exp( - \\smfrac{C_\\delta M}{N})\n    =\n    N \\exp\\b( - \\alpha C_\\delta \\log M\\b)\n    \\leq\n    M^{1 -\\alpha C_\\delta} / \\log M\n\\]\nand by choosing $\\alpha$ sufficiently large we can ensure that this value tends\nto zero as $M \\to \\infty$. (the case of sufficiently large amounts of data).\nConversely, if $\\alpha$ is too small, then $M^{1 -\\alpha C_\\delta} / \\log M \\to\n\\infty$ as $M \\to \\infty$ which shows that the choice $N \\leq \\alpha M/\\log M$\nis sharp. This is a very mild restriction!\n\nThe next result  we discuss concerns the approximation $p_{NM} = \\sum_n c_n\n\\phi_n$ we obtain by solving the least squares problem $\\| f - p_{NM}\n\\|_{\\ell^2(\\{x_m\\})}^2 \\to \\min$.\n\n\\begin{theorem} \\label{th:lsq:randerr}\n    There exists a constant $c$ such that, if\n    \\[\n        K(N) \\leq \\frac{c}{1+r} \\frac{M}{\\log M},\n    \\]\n    then,\n    \\[\n        \\mathbb{E}\\b[ \\|f - p_{NM}\\|_{L^2_w}^2 \\b]\n        \\leq\n        (1+\\epsilon(M)) \\|f - \\Pi_N f\\|_{L^2_w}^2\n        + 8 \\|f\\|_{L^\\infty(a,b)}^2 M^{-r},\n    \\]\n    where $\\epsilon(M) \\to 0$ as $M \\to \\infty$, and $\\Pi_N$ denotes the\n    best-approximation operator with respect to the $L^2_w$-norm.\n\\end{theorem}\n\nAs a first comment, we observe that our restriction $N \\leq \\alpha M / \\log M$\nfor sufficiently small $\\alpha$ re-appears. (In fact, this prerequisite is\nrequired to be able to apply Theorem~\\ref{th:lsq:randstab}.)\n\nWe can now ask what consequence the choice $N = \\alpha M / \\log M$ has\non the error. In this case, $\\alpha = c / (1+r)$, or equivalently,\n$r = c/\\alpha - 1$ hence (sacrifycing just a log-factor)\n\\[\n    M^{-r}  \\leq N^{-r} = N^{1 - c/\\alpha} =: N^{-\\alpha'},\n\\]\nwhere $\\alpha' > 0$ provided that $\\alpha$ is chosen sufficiently small. In this\ncase, we can conclude that\n\\[\n    \\mathbb{E}\\b[ \\|f - p_{NM}\\|_{L^2_w}^2 \\b]\n    \\lesssim\n    \\|f - \\Pi_N f\\|_{L^2_w}^2\n    +\n    N^{- \\alpha'}\n\\]\nfor some $\\alpha' > 0$. Thus, for differentiable functions $f$, such a choice is\nquasi-optimal.\n\nHowever, for analytic functions the rate in the error estimate is\nreduced. Let us assume that $f \\in A(E_\\rho)$, then\n$\\| f - \\Pi_N f \\|_{L^2_w} \\lesssim \\rho^{-N}$ hence we must balance the\ntwo constributions\n\\[\n    \\rho^{-N} + M^{-r}.\n\\]\nWe have already seen that $N = \\alpha M/\\log M$ leads to $\\rho^{-N} \\ll M^{-r}$,\nhence we instead attempt to choose $N = a (M/\\log M)^{\\alpha}$ for some $0 < \\alpha < 1$,\nwhich gives\n\\[\n    r = c' (M / \\log M)^{1-\\alpha}.\n\\]\nThus, we wish to balance\n\\begin{align*}\n    \\exp\\B[ - (\\log \\rho) N\\B]  &+ \\exp\\B[ - r \\log M \\B]  \\\\\n    = \\exp\\B[ - c'' M^\\alpha (\\log M)^{-\\alpha} \\B]  &+ \\exp\\B[ - c M^{1-\\alpha} (\\log M)^{-\\alpha} \\B]\n\\end{align*}\nWe can now see that the two terms are balanced when $\\alpha = 1/2$, that is,\nthe quasi-optimal choice of $N$ appears to be\n\\[\n    N = a \\b(M / \\log M\\b)^{1/2}.\n\\]\nThis is also somewhat consistent with the observation that in the $C^j$ case we\nneed to decrease $\\alpha$ for increasing $j$.\n\nThat said, we should remember that we have balanced an error estimate and not\nthe actual error. At this point, it is highly advisable to test these\npredictions numerically, which is done in \\nblsq, where we see --- for some\nlimited examples --- that the stability condition $N \\lesssim M/\\log M$ appears\nto be crucial but the stronger requirement $N \\lesssim (M/\\log M)^{1/2}$ seems\nto not be required.\n\nIn summary, the foregoing analysis is intended to demonstrate how different\ncompeting contributions to approximation by fitting from data can be balanced at\nleast in principle but also the limitations of analysis.\n\n\n\n\n\n\\subsection{Exercises}\n%\n\\label{sec:lsq:exercises}\n%\n", "meta": {"hexsha": "a07be35397b8f1339f0b366a14ab6d223495d854", "size": 17750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/lsq.tex", "max_stars_repo_name": "cortner/MA3J8ApxThyApp", "max_stars_repo_head_hexsha": "9400c557187dbd82468df2dbd0a7da99d7f08f8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-05-22T05:11:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-03T02:47:25.000Z", "max_issues_repo_path": "tex/lsq.tex", "max_issues_repo_name": "cortner/MA3J8ApxThyApp", "max_issues_repo_head_hexsha": "9400c557187dbd82468df2dbd0a7da99d7f08f8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-03T22:23:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T01:58:58.000Z", "max_forks_repo_path": "tex/lsq.tex", "max_forks_repo_name": "cortner/ApxThyApp", "max_forks_repo_head_hexsha": "0b28c5c4370eb4d9c5a9063c2c5c1b938aa54a3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-02T02:44:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T02:44:56.000Z", "avg_line_length": 40.0677200903, "max_line_length": 103, "alphanum_fraction": 0.6656901408, "num_tokens": 6000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.6998666534892025}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Regression}\n\\label{chap:regression}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Linear Regression (OLS)}\n\\label{regression:linear}\n\nLinear regression fits the best hyperplane, or line in 1D,\nto a collection of $m$ points $\\vb{x}_{i}, y_{i}$,\ntypically via the method of least squares.\nIf $\\vb{x}$ has $n$ features we can represent the\nlinear relationship between $\\vb{x}$ and $y$ as:\n\n\\begin{equation}\\label{eq:linear:one_point}\ny_{i} = \\beta_{0} + \\sum_{j=1}^{n}\\, \\beta_{j} x_{ij} + \\epsilon_{i}\\,,\n\\end{equation}\n\n\\noindent where $\\beta_{j}$ are the parameters of the regression\nand $\\epsilon$ represent random errors.\nTransitioning to matrix notation\\footnote{Note\nthat \\textit{linear} regression refers to the linearity in the model parameters\n$\\vb*{\\beta}$, not $\\mathbf{X}$.\nThe components of $\\mathbf{X}_{i}$ can be, and often are,\nnon-linear functions of other input features.}, this is simply:\n\n\\begin{equation}\\label{eq:linear:matrix}\n\\vb{y} = \\mathbf{X} \\vb*{\\beta} + \\vb*{\\epsilon}\\,,\n\\end{equation}\n\n\\noindent where we have set $X_{i0} =1$.\nHere $\\mathbf{X}$ is $m \\times n$,\n$\\vb*{\\beta}$ is $n \\times 1$,\nand $\\vb{y}$, $\\vb*{\\epsilon}$ are $m \\times 1$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Derivation}\n\\label{regression:linear:derivation}\n\nThe ordinary least squares (OLS) estimate\\footnote{When\nthe errors are assumed to be normal,\nas in \\cref{item:regression:linear:exogeneity,item:regression:linear:spherical,item:regression:linear:normality},\nOLS is equivalent to the maximum likelihood estimation (MLE) approach of \\cref{opt:MLE}.\nSee one derivation \\href{https://machinelearningmastery.com/linear-regression-with-maximum-likelihood-estimation/}{here}.} of\nthe parameters $\\hat{\\vb*{\\beta}}$\ncan be found by minimizing the squares of the errors,\n\\ie the objective function $S\\left(\\vb*{\\beta}\\right) = \\norm{\\vb*{\\epsilon}}^{2}$:\n\n\\begin{subequations} \\label{eq:linear:ols}\n\\begin{align}\n\\hat{\\vb*{\\beta}} &= \\argmin_{\\vb*{\\beta}} S\\left(\\vb*{\\beta}\\right)\\,, \\label{eq:linear:argmin} \\\\\nS\\left(\\vb*{\\beta}\\right)\n&= \\norm{\\vb{y} - \\mathbf{X} \\vb*{\\beta}}^{2} = \\left(\\vb{y} - \\mathbf{X} \\vb*{\\beta}\\right)\\transpose \\left(\\vb{y} - \\mathbf{X} \\vb*{\\beta}\\right) \\label{eq:linear:S_matrix} \\\\\n&= \\sum_{i=1}^{m} \\, \\abs{y_{i} - \\sum_{j=0}^{n} \\, \\beta_{j} x_{ij}}^{2}\\,. \\label{eq:linear:S_components}\n\\end{align}\n\\end{subequations}\n\nWe then find the minimum of $S\\left(\\vb*{\\beta}\\right)$ with respect to $\\vb*{\\beta}$\nby taking the gradient and setting it equal to zero:\n\n\\begin{subequations} \\label{eq:linear:ols_derivation}\n\\begin{align}\nS\\left(\\vb*{\\beta}\\right) &=\n \\vb{y}\\transpose \\vb{y}\n-\\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\vb{y}\n-\\vb{y}\\transpose \\mathbf{X} \\vb*{\\beta}\n+\\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta} \\label{eq:linear:S_expand} \\\\\n&= \\vb{y}\\transpose \\vb{y}\n-2\\, \\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\vb{y}\n+\\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta}\\,, \\label{eq:linear:S_expand_simplified} \\\\\n\\partial_{\\vb*{\\beta}} \\, S\\left(\\vb*{\\beta}\\right) &=\n0\n-2\\, \\partial_{\\vb*{\\beta}} \\, \\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\vb{y}\n+\\partial_{\\vb*{\\beta}} \\, \\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta} \\label{eq:linear:grad_S_expand} \\\\\n&= -2\\, \\mathbf{X}\\transpose \\vb{y} + 2\\, \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta} = 0. \\, \\implies \\label{eq:linear:grad_S} \\\\\n\\mathbf{X}\\transpose \\vb{y} &= \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta}\\,, \\label{eq:linear:penultimate}\n\\end{align}\n\\end{subequations}\n\n\\noindent where we have used\\footnote{See \\href{https://economictheoryblog.com/2015/02/19/ols_estimator/}{here}\nand \\href{https://economictheoryblog.com/2018/10/17/derivation-of-the-least-squares-estimator-for-beta-in-matrix-notation-proof-nr-1/}{here}\nfor the component-wise proof, but it is essentially the same as the 1D $\\partial_{x} b x = b$, $\\partial_{x} b x^{2} = 2 b x$.\nAlso note that \\cref{eq:linear:S_expand_simplified} results from $\\vb{y}\\transpose \\mathbf{X} \\vb*{\\beta}$ being scalar\nand thus equal to its own transpose, $\\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\vb{y}$.}:\n\n\\begin{subequations} \\label{eq:grad_relations}\n\\begin{align}\n\\partial_{\\vb*{\\beta}} \\, \\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\vb{y} &= \\mathbf{X}\\transpose \\vb{y}\\,, \\label{eq:grad_relations:1} \\\\\n\\partial_{\\vb*{\\beta}} \\, \\vb*{\\beta}\\transpose \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta} &= 2 \\, \\mathbf{X} \\transpose \\mathbf{X} \\vb*{\\beta}\\,. \\label{eq:grad_relations:2}\n\\end{align}\n\\end{subequations}\n\nConsequently, the optimal $\\hat{\\vb*{\\beta}}$ of \\cref{eq:linear:ols}\nhas a closed form solution\\footnote{The fitted prediction is $\\hat{\\vb{y}} = \\mathbf{X} \\hat{\\vb*{\\beta}}$, with residuals $\\hat{\\vb*{\\epsilon}} = \\vb{y} - \\hat{\\vb{y}}$.}:\n\n\\begin{equation}\\label{eq:linear:betahat_OLS}\n\\hat{\\vb*{\\beta}}^{\\text{OLS}} = \\left(\\mathbf{X}\\transpose\\mathbf{X}\\right)^{-1}\\mathbf{X}\\transpose \\vb{y}\\,,\n\\end{equation}\n\n\\noindent which is the best linear unbiased estimator (BLUE),\nas can be shown with the Gauss-Markov Theorem provided\nthe following assumptions hold\\footnote{For additional details see\n\\href{https://economictheoryblog.com/2015/04/01/ols_assumptions/}{here},\n\\href{http://people.duke.edu/~rnau/testing.htm}{here}, and\n\\href{https://economictheoryblog.com/2015/02/26/markov_theorem/}{here}.}:\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Assumptions}\n\\label{regression:linear:assumptions}\n\n\\begin{enumerate}[noitemsep]\n  \\item The underlying relationship between $\\vb{x}$ and $y$ is linear, and there are no major outliers.\\label{item:regression:linear:linear}\n  \\item The columns of $\\mathbf{X}$, \\ie features, are linearly independent, \\ie $\\mathrm{rank}\\left(\\mathbf{X}\\right) = n$ (no multicollinearity). This allows $\\mathbf{X}\\transpose\\mathbf{X}$ to be inverted.\\label{item:regression:linear:multicollinearity}\n  \\item The errors $\\epsilon$ have conditional mean 0, $\\expvalE{\\epsilon \\mid \\mathbf{X}} = 0$ (exogeneity). The errors thus:\\label{item:regression:linear:exogeneity}\n  \\begin{enumerate}[noitemsep]\n    \\item Have a mean of zero, $\\expvalE{\\epsilon} = 0$.\n    \\item Are not correlated with the input features, $\\expvalE{\\mathbf{X}\\transpose\\epsilon} = 0$.\n  \\end{enumerate}\n  \\item The errors are spherical, $\\mathrm{var}\\left(\\epsilon \\mid \\mathbf{X}\\right) = \\sigma^{2} \\identity$. Thus:\\label{item:regression:linear:spherical}\n  \\begin{enumerate}[noitemsep]\n    \\item Each observation $\\vb{x}_{i}$ has the same constant variance $\\sigma^{2}$ (homoscedasticity).\n    \\item The errors are uncorrelated between observations, $\\expvalE{\\epsilon_{i}\\epsilon_{j \\neq i} \\mid \\mathbf{X}} = 0$ (no autocorrelation).\n  \\end{enumerate}\n  \\item The errors are normally distributed (multivariate normality)\\footnote{This is not required for OLS to be the BLUE, but hypothesis testing works if true.}.\\label{item:regression:linear:normality}\n\\end{enumerate}\n\nIf these assumptions are violated the following issues arise,\nnamely the model may be biased and or have a large or invalid estimated variance:\n\n\\begin{itemize}[noitemsep]\n  \\item[\\cref{item:regression:linear:linear}.] If you are fitting nonlinear data the predictions will have large errors,\nparticularly when extrapolated beyond the range of the fitted data.\nThis will show up as systematic errors in the residuals plot,\nor may be obvious when comparing observed vs predicted values.\nPossible fixes include applying a nonlinear transformation to some of the features to linearize the data, \\eg take the log,\nadding more combinations of features, \\eg higher polynomial terms,\nor finding new independent features which may explain the nonlinearity.\n\n  \\item[\\cref{item:regression:linear:multicollinearity}.] If some of the features are not linearly independent (multicollinearity),\nthey can be biasing the model and should be removed in turn until linear independence is restored.\nMulticollinearity can be spotted in the input feature correlation matrix,\nwith the variance inflation factor of \\cref{regression:linear:VIF},\nor if the residuals correlate to any of the features.\n\n  \\item[\\cref{item:regression:linear:exogeneity}.] If something is wrong with the errors\nsuch that they have a non-zero mean or correlate to the input features\nthe OLS $\\hat{\\vb*{\\beta}}$ is biased and inconsistent.\nThis can happen if there are omitted variables or measurement errors.\nFurthermore, if $\\expvalE{\\epsilon \\mid \\mathbf{X}} = c$ only the $\\beta_{0}$ intercept is affected.\n\n  \\item[\\cref{item:regression:linear:spherical}.] If something is wrong with the errors\nsuch that they have a changing variance or correlate across observations\\footnote{Thus the residuals correlate with row number, \\ie autocorrelation.}\nthe reported confidence intervals on the model parameters may be over or underestimated.\nThe OLS $\\hat{\\vb*{\\beta}}$ remains unbiased and has consistent coefficients, but will be biased for standard errors.\n\n  \\item[\\cref{item:regression:linear:normality}.] If the errors are not normally distributed the confidence intervals are again suspect.\nThis can be diagnosed by comparing the errors to the normal distribution with a normal probability plot, or normal quantile plot,\nor through a statistical method like the Anderson-Darling and Kolmogorov-Smirnov tests.\nNote that violating normality in the errors is not as much of an issue compared to the other assumptions\nsince the fit will still give usable coefficients provided the assumed form of the model is correct.\nProblems of this kind can arise from nonlinear data or influential outliers.\nIf the errors really are non-normal, a generalized linear model (GLM) could be employed to model them correctly.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Goodness of Fit}\n\\label{regression:linear:goodness_of_fit}\n\n\\subsubsection{Coefficient of Determination ($R^{2}$)}\n\\label{regression:linear:goodness_of_fit:R2}\n\nThe coefficient of determination\\footnote{For additional details see\n\\href{https://economictheoryblog.com/2014/11/05/the-coefficient-of-determination-latex-r2/}{here},\n\\href{https://economictheoryblog.com/2014/11/05/proof/}{here}, and\n\\href{http://people.duke.edu/~rnau/rsquared.htm}{here}.}, $R^{2}$,\nmeasures how much of $\\vb{y}$'s variance is explained by the fitted model $\\hat{\\vb{y}}$,\nversus by random errors $\\vb*{\\epsilon}$ or other unknown sources,\nas $\\vb{y} = \\hat{\\vb{y}} + \\vb*{\\epsilon}$.\n$R^{2} \\approx 1$ is ideal and, depending on the particular definition,\nit can take values outside the typical $0 \\leq R^{2} \\leq 1$ range.\n\n\\begin{equation}\\label{eq:regression:linear:goodness_of_fit:R2}\nR^{2} = \\frac{\n\\sum_{i=1}^{m} \\left(\\yhat_{i} - \\expval{\\yhat}\\right)^{2}\n}{\n\\sum_{i=1}^{m} \\left(y_{i} - \\expval{y}\\right)^{2}\n} = 1 - \\frac{\n\\sum_{i=1}^{m} \\hat{\\epsilon}_{i}^{\\,2}\n}{\n\\sum_{i=1}^{m} \\left(y_{i} - \\expval{y}\\right)^{2}\n} = \\rho_{y,\\yhat}^{2}\n\\end{equation}\n\nThe adjusted $R^{2}$, $R^{2}_{\\text{adj}}$, accounts for the degrees of freedom in the\nfitted sample, $m-1$, and in the model, $m-n-1$, and is thus a better metric.\n\n\\begin{equation}\\label{eq:regression:linear:goodness_of_fit:R2_adj}\nR^{2}_{\\text{adj}} = 1 - \\frac{\n\\left(\\sum_{i=1}^{m} \\hat{\\epsilon}_{i}^{\\,2}\\right)/\\left(m-n-1\\right)\n}{\n\\left(\\sum_{i=1}^{m} \\left(y_{i} - \\expval{y}\\right)^{2}\\right)/\\left(m-1\\right)\n}\n= 1 - \\left(1-R^{2}\\right)\\frac{m-1}{m-n-1}\n\\end{equation}\n\n\\subsubsection{Standard Error of the Regression and $\\chi_{\\nu}^{2}$}\n\\label{regression:linear:goodness_of_fit:reduced_chi2}\n\nThe standard error of the regression, $s$,\nand reduced \\chiSqstat, $\\chi_{\\nu}^{2}$,\nare additional ways of quantifying goodness of fit.\n$s$ is a measure of the typical residual, in the units of $y$.\n$\\chi_{\\nu}^{2}$ is a convenient way of reporting this spread in a dimensionless manner,\nparticularly in more sophisticated regressions where each $y_{i}$ has an \\apriori estimated uncertainty, $\\sigma_{i}$.\n\n\\begin{subequations}\\label{eq:regression:linear:goodness_of_fit:s_red_chi2}\n\\begin{align}\ns^{2} &= \\frac{\\norm{\\hat{\\vb*{\\epsilon}}}^{2}}{m-n} = \\frac{1}{m-n} \\sum_{i=1}^{m} \\left(\\yhat_{i} - y_{i}\\right)^{2} \\label{eq:regression:linear:goodness_of_fit:s} \\\\\n\\chi_{\\nu}^{2} &= \\frac{1}{m-n} \\sum_{i=1}^{m} \\frac{\\left(\\yhat_{i} - y_{i}\\right)^{2}}{\\sigma_{i}^{2}} \\label{eq:regression:linear:goodness_of_fit:red_chi2}\n\\end{align}\n\\end{subequations}\n\n$\\chi_{\\nu}^{2}$ can be interpreted as follows:\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{c | p{8cm}}\n$\\chi_{\\nu}^{2} \\gg 1$ & The true model may be different than the fitted model. \\\\\n$\\chi_{\\nu}^{2} > 1$ & Fit doesn't fully explain data (underfitting), or the \\apriori $\\sigma_{i}$ are underestimated. \\\\\n$\\chi_{\\nu}^{2} \\approx 1$ & Good fit! \\\\\n$\\chi_{\\nu}^{2} < 1$ & Fit overexplains data (overfitting), or the \\apriori $\\sigma_{i}$ are overestimated. \\\\\n$\\chi_{\\nu}^{2} \\ll 1$ & Extreme overfitting or overestimated $\\sigma_{i}$.\n  \\end{tabular}\n%  \\caption{}\n  \\label{table:red_chi2_interp}\n\\end{table}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Coefficient Significance}\n\\label{regression:linear:coeff_significance}\n% TODO what is the significance of any particular \\beta_{i} coefficient, via \\ttest, \\chiSqtest, \\Ftest?? Should be able to get distribution of any \\beta_{i} analytically for OLS, but can use bootstrap sampling for more complex models.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Variance Inflation Factor (VIF)}\n\\label{regression:linear:VIF}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Ridge Regression (L2, or Tikhonov)}\n\\label{regression:linear:ridge}\n\nAdding ridge (L2, or Tikhonov) regularization to OLS is much more straight forward than LASSO,\nso we shall discuss it first\\footnote{See \\href{https://stats.stackexchange.com/a/164546}{here} for an interesting geometric explanation.}.\nWe wish to minimize the square errors $\\norm{\\vb*{\\epsilon}}^{2}$,\nnow subject to the condition that $\\norm{\\vb*{\\beta}}^{2} < t$ for some $t \\geq 0$.\nFor any $t \\geq 0$ there is a $\\lambda \\geq 0$ such that minimizing the following\nobjective function $S\\left(\\vb*{\\beta}\\right)$ without conditions is\nequivalent\\footnote{This is sometimes termed soft-thresholding, but is really an application of Lagrange multipliers, as described in \\cref{opt:lagrange_mult}.}:\n\n\\begin{equation} \\label{eq:linear:ridge}\nS\\left(\\vb*{\\beta}\\right) = \\norm{\\vb{y} - \\mathbf{X} \\vb*{\\beta}}^{2} + \\lambda \\norm{\\vb*{\\beta}}^{2}\\,.\n\\end{equation}\n\nAfter taking the gradient, we have the same terms as \\cref{eq:linear:grad_S},\nplus a new term\\footnote{Note the similarity to \\cref{eq:grad_relations:2}.} \\cref{eq:linear:ridge_derivation:new}.\nRearranging \\cref{eq:linear:ridge_derivation:penultimate} we can move the new term in with the old,\nand quickly arrive at a modified version of the OLS solution \\cref{eq:linear:ridge_derivation:betahat}.\n\n\\begin{subequations} \\label{eq:linear:ridge_derivation}\n\\begin{align}\n\\partial_{\\vb*{\\beta}} \\, S\\left(\\vb*{\\beta}\\right)\n&= -2\\, \\mathbf{X}\\transpose \\vb{y} + 2\\, \\mathbf{X}\\transpose \\mathbf{X} \\vb*{\\beta} \\label{eq:linear:ridge_derivation:grad_S_repeat} \\\\\n&+ 2\\,\\lambda \\vb*{\\beta} = 0 \\,\\, \\implies \\label{eq:linear:ridge_derivation:new} \\\\\n\\mathbf{X}\\transpose \\vb{y} &= \\left(\\mathbf{X}\\transpose \\mathbf{X} + \\lambda\\,\\identity\\right) \\vb*{\\beta} \\label{eq:linear:ridge_derivation:penultimate} \\\\\n\\hat{\\vb*{\\beta}}^{\\text{ridge}} &= \\left(\\mathbf{X}\\transpose\\mathbf{X} + \\lambda\\,\\identity\\right)^{-1}\\mathbf{X}\\transpose \\vb{y} \\label{eq:linear:ridge_derivation:betahat}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{LASSO Regression (L1)}\n\\label{regression:linear:lasso}\n\nAs promised, adding LASSO (L1) regularization to OLS is challenging\nas the condition, $\\norm{\\vb*{\\beta}} < t$ for some $t \\geq 0$,\nis not differentiable, see the corners of \\cref{fig:ml:l1l2:l1}, and must be dealt with carefully.\nIn the special case that $\\mathbf{X}$ is orthonormal, $\\mathbf{X}\\transpose \\mathbf{X} = \\identity$,\na closed form solution \\cref{eq:linear:lasso:betahat:1} can be derived on a case-by-case basis\nat the $\\beta_{i}$ coordinate-level\\footnote{See \\href{https://stats.stackexchange.com/questions/17781/derivation-of-closed-form-lasso-solution}{here},\n\\href{https://en.wikipedia.org/wiki/Lasso_(statistics)\\#Orthonormal_covariates}{here},\nand \\href{https://xavierbourretsicotte.github.io/lasso_derivation.html}{here}.}.\nIn the general case, more sophisticated methods can find numerical solutions.\n\n\\begin{subequations} \\label{eq:linear:lasso:betahat_all}\n\\begin{align}\n\\hat{\\vb*{\\beta}}^{\\text{LASSO}}_{j}\n&= \\hat{\\vb*{\\beta}}^{\\text{OLS}}_{j} \\max\\left(0, \\frac{\\lambda}{\\abs{\\hat{\\vb*{\\beta}}^{\\text{OLS}}_{j}}}\\right) \\label{eq:linear:lasso:betahat:1} \\\\\n&= \\sign{\\hat{\\vb*{\\beta}}^{\\text{OLS}}_{j}} \\left(\\abs{\\hat{\\vb*{\\beta}}^{\\text{OLS}}_{j}} - \\lambda\\right)^{+} \\label{eq:linear:lasso:betahat:2} \\\\\n\\hat{\\vb*{\\beta}}^{\\text{OLS}}\n&= \\left(\\mathbf{X}\\transpose\\mathbf{X}\\right)^{-1}\\mathbf{X}\\transpose \\vb{y}\n= \\mathbf{X}\\transpose \\vb{y} \\label{eq:lasso:modified_betahat_OLS}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{LASSO vs Ridge Regression}\n\\label{regression:linear:lasso_vs_ridge}\n\nAll the usual concepts from \\cref{ml_general:reg} apply, but specifically for linear regression\nboth LASSO and ridge allow us to relax the multicollinearity condition.\nLasso tends to use one feature per group of correlated $\\vb{x}_{j}$'s, setting the rest to $\\approx 0$,\nwhile ridge will keep all of the associated $\\beta_{j}$'s at a similar magnitude.\nAs one may expect from LASSO shrinking $\\beta_{j}$'s to zero,\nit does a better job when only some of the $n$ input features infuence \\yhat,\nwhile ridge does better if most of the features have similar importances.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{OLS Example}\n\\label{regression:linear:example}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bayesian Linear Regression}\n\\label{regression:bayesian_linear}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{LASSO and Ridge as Priors}\n\\label{regression:bayesian_linear:lasso_vs_ridge}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Weighted Least Squares}\n\\label{regression:WLS}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Generalized Least Squares (GLS)}\n\\label{regression:GLS}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Generalized Linear Models (GLM)}\n\\label{regression:GLM}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Binomial Regression}\n\\label{regression:GLM:binomial}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Poisson Regression}\n\\label{regression:GLM:poisson}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Gaussian Process Regression (Kriging)}\n\\label{regression:kriging}\n% TODO\n\n% TODO see \\cite{Brochu2010} section 2.6 and the additional references it cites\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Difference in Differences (DID)}\n\\label{regression:DID}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Fixed-Effects Model}\n\\label{regression:fixed_effects}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Mixed-Effects Model}\n\\label{regression:mixed_effects}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Simpson's Paradox}\n\\label{regression:simpsons_paradox}\n% TODO\n", "meta": {"hexsha": "8c95f4a5049abe90ec1381151a46856fa1c7c4aa", "size": 20529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/regression.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/regression.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/regression.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": 52.1040609137, "max_line_length": 256, "alphanum_fraction": 0.6538068099, "num_tokens": 6061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.6998666456098428}}
{"text": "\\section{Direct Sums and Free Modules}\r\n\\begin{definition}\r\n    If $M_1,\\ldots,M_n$ are $R$-modules, then their direct sum $M_1\\oplus\\cdots\\oplus M_n$ is the set $M_1\\times \\cdots\\times M_n$ with entry-wise addition and scalar multiplications.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $R^n$ is simply $R\\oplus\\cdots\\oplus R$ of $n$ copies of $R$.\\\\\r\n    2. If $M_1,M_2\\le M$, then the $R$-module homomorphism $M_1\\oplus M_2\\to M$ by $(m_1,m_2)\\mapsto m_1+m_2$ is an isomorphism iff $M_1\\cap M_2=\\varnothing$ and $M_1+M_2=M$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    If $M=\\bigoplus_{i=1}^nM_n$, and $N_1\\le M_i$.\r\n    Take $N=\\bigoplus_{i=1}^nN_i$, then\r\n    $$M/N\\cong\\bigoplus_{i=1}^nM_i/N_i$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Apply the first isomorphism theorem to the surjective $R$-module map $\\phi:M\\to\\bigoplus_{i=1}^nM_i/N_i$ by $(m_1,\\ldots,m_n)\\mapsto(m_1+N_1,\\ldots,m_n+N_n)$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Taking $R=\\mathbb Z$ then $\\mathbb Z^2=\\mathbb Z\\oplus \\mathbb Z$, then we have $(\\mathbb Z\\oplus\\mathbb Z)/(m\\mathbb Z\\oplus n\\mathbb Z)\\cong(\\mathbb Z/m\\mathbb Z)\\oplus(\\mathbb Z/n\\mathbb Z)$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $m_1,\\ldots,m_n\\in M$.\r\n    The set $\\{m_1,\\ldots,m_n\\}$ is independent if $r_1m_1+\\cdots +r_nm_n=0\\implies \\forall i,r_i=0$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A subset $S$ of an $R$-module $M$ generates $M$ freely if $S$ generates $M$ and any function $\\psi:S\\to N$ for another $R$-module $N$ extends to an $R$-module homomorphism $M\\to N$.\r\n\\end{definition}\r\nNote that if such an extension exists then it is necessarily unique.\r\n\\begin{definition}\r\n    A freely-generated $R$-module is called a free $R$-module.\r\n    The corresponding $S$ is called the free basis.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    For an $R$-module $M$ and a subset $S=\\{m_1,\\ldots,m_n\\}\\subset M$, the followings are equivalent:\\\\\r\n    1. $S$ generates $M$ freely.\\\\\r\n    2. $S$ generates $M$ and $S$ is independent.\\\\\r\n    3. Every $m\\in M$ can be written uniquely in the form $m=r_1m_1+\\cdots +r_nm_n$ for $r_1,\\ldots,r_n\\in R$.\\\\\r\n    4. The $R$-module homomorphism $R^n\\to M$ by $(r_1,\\ldots,r_n)\\mapsto r_1m_1+\\ldots r_nm_n$ is an isomorphism.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $1\\implies 2$: We already knows that $S$ generates $M$, so it suffices to show that $S$ is independent.\r\n    Suppose for sake of contradiction that $r_1m_1+\\ldots+r_nm_n=0$ for some $r_i\\in R$ and some $r_j$ is nonzero.\r\n    Consider the function $\\psi:S\\to R$ by $m_j\\mapsto 1$ and $m_i\\mapsto 0$ for any $i\\neq j$.\r\n    Suppose this extends to an $R$-module map $\\theta:M\\to R$, then $0=\\theta(0)=\\theta(r_1m_1+\\cdots +r_nm_n)=r_j$, contradiction.\\\\\r\n    Remaining implications $2\\implies 3\\implies 1$ and $3\\iff 4$ are just as easy if not easier.\r\n\\end{proof}\r\nSadly not all $R$-modules are free.\r\nEven if it is, the free basis does not behave like what we expect from a vector space.\r\n\\begin{example}[non-example]\r\n    1. Suppose we have a nontrivial finite abelian group $A$, then $A$ is not free as a $\\mathbb Z$-module since it is not isomorphic to $\\mathbb Z^n$ which is infinite.\\\\\r\n    2. The set $\\{2,3\\}\\subset\\mathbb Z$ generates $\\mathbb Z$ as a $\\mathbb Z$-module, but it is not independent and no subset of it gives a free basis.\r\n\\end{example}\r\n\\begin{proposition}[Theorem on Invariant of Dimension]\r\n    Let $R$ be a nonzero ring.\r\n    If $R^m\\cong R^n$ as $R$-modules, then $m=n$.\r\n\\end{proposition}\r\nWe introduce the following general construction: Let $R$ be a ring and $I\\unlhd R$ and $M$ is an $R$-module.\r\nWe write $IM=\\{im:i\\in I,m\\in M\\}\\le M$.\r\nThen the quotient $M/(IM)$ is an $R/I$ module by $(r+I)(m+IM)=rm+IM$.\r\nAlso by Zorn's Lemma, for any proper ideal $I$ in a ring $R$, there is a maximal ideal containing $I$ (this is obvious when $R$ is Noetherian).\r\n\\footnote{I think we can prove the proposition without using AC (or equivalence)}\r\n\\begin{proof}\r\n    Return to our proof, suppose $R^m\\cong R^n$.\r\n    Choose $I\\unlhd R$ maximal, then we have\r\n    $$(R/I)^m\\cong R^m/(IR^m)\\cong R^n/(IR^n)\\cong (R/I)^n$$\r\n    But $R/I$ is a field, so $m=n$.\r\n\\end{proof}", "meta": {"hexsha": "78e19c0df07e54a65db936f9b636868ce354c6a9", "size": 4128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15/free.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": "15/free.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": "15/free.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": 62.5454545455, "max_line_length": 199, "alphanum_fraction": 0.6712693798, "num_tokens": 1511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645723, "lm_q2_score": 0.8824278680004707, "lm_q1q2_score": 0.699858802232432}}
{"text": "\\documentclass{article}\n\\input{preamble}\n\n\\newcommand{\\version}{Draft: 02 April 2020}\n\n\\lhead{\\scriptsize}\n\\chead{\\scriptsize}\n\\rhead{\\scriptsize \\thepage}\n\n\\lfoot{\\scriptsize}\n\\cfoot{\\scriptsize}\n\\rfoot{\\scriptsize \\version}\n\n\n%==============================================================================\n\\begin{document}\n%==============================================================================\n\nWe define the Oneka-type regional flow model by the following discharge potential:\n%\n\\begin{equation}\\label{1}\n    \\Phi(x,y) = A x^2 + B y^2 + C xy + Dx + Ey + F\n\\end{equation}\n%\nEquation~\\eqref{1} is a quadratic form in real variables. We define $z$ and $\\bar{z}$ as\n%\n\\begin{equation}\\label{2}\n    z = x + i y \\qquad \\qquad \\bar{z} = x - i y\n\\end{equation}\n%\nInverting yields\n%\n\\begin{equation}\\label{3}\n    x = \\frac{z + \\bar{z}}{2} \\qquad \\qquad y = \\frac{z - \\bar{z}}{2i}\n\\end{equation}\n%\nSubstituting \\eqref{3} into \\eqref{1} yields\n%\n\\begin{equation}\\label{4}\n    \\Phi(z,\\bar{z})\n    = A \\left(\\frac{z + \\bar{z}}{2}\\right)^2 + B \\left(\\frac{z - \\bar{z}}{2i}\\right)^2 +\n        C \\left(\\frac{z + \\bar{z}}{2}\\right)\\left(\\frac{z - \\bar{z}}{2i}\\right) +\n        D \\left(\\frac{z + \\bar{z}}{2}\\right) + E \\left(\\frac{z - \\bar{z}}{2i}\\right) + F\n\\end{equation}\n%\nRearranging \\eqref{4} yields\n%\n\\begin{equation}\\label{5}\n    \\Phi(z, \\bar{z}) = a z^2 + b \\bar{z}^2 + c z \\bar{z} + d z + e \\bar{z} + f\n\\end{equation}\n%\nwhere\n%\n\\begin{align}\n    a &= \\frac{A - B - iC}{4} \\\\\n    b &= \\frac{A - B + iC}{4} \\\\\n    c &= \\frac{A + B}{2} \\\\\n    d &= \\frac{D - iE}{2} \\\\\n    e &= \\frac{D + iE}{2} \\\\\n    f &= F\n\\end{align}\n%\nAlternatively,\n%\n\\begin{equation}\n    \\frac{1}{4}\n    \\begin{bmatrix}\n    1& -1& -1i& 0& 0& 0 \\\\\n\t1& -1& 1i& 0& 0& 0 \\\\\n\t2& 2& 0& 0& 0& 0 \\\\\n\t0& 0& 0& 2& -2i& 0 \\\\\n\t0& 0& 0& 2& 2i& 0 \\\\\n\t0& 0& 0& 0& 0& 4\n    \\end{bmatrix}\n    \\begin{bmatrix}A \\\\ B \\\\ C \\\\ D \\\\ E \\\\ F \\end{bmatrix}\n    =\n    \\begin{bmatrix}a \\\\ b \\\\ c \\\\ d \\\\ e \\\\ f \\end{bmatrix}\n\\end{equation}\n%\nInverting yields\n%\n\\begin{equation}\n    \\begin{bmatrix}\n\t1& 1& 1& 0& 0& 0 \\\\\n\t-1& -1& 1& 0& 0& 0 \\\\\n\t2i& -2i& 0& 0& 0& 0 \\\\\n\t0& 0& 0& 1& 1& 0 \\\\\n\t0& 0& 0& 1i& -1i& 0 \\\\\n\t0& 0& 0& 0& 0& 1\n    \\end{bmatrix}\n    \\begin{bmatrix}a \\\\ b \\\\ c \\\\ d \\\\ e \\\\ f \\end{bmatrix}\n    =\n    \\begin{bmatrix}A \\\\ B \\\\ C \\\\ D \\\\ E \\\\ F \\end{bmatrix}\n\\end{equation}\n\nNote that $b = \\bar{a}$ and $e = \\bar{d}$, so \\eqref{5} simplifies to\n%\n\\begin{align}\\label{7}\n    \\Phi(z, \\bar{z}) \n    &= a z^2 + \\bar{a} \\bar{z}^2 + c z \\bar{z} + d z + \\bar{d} \\bar{z} + f \\\\\n    &= \\real{a z^2 + d z + f} + c z \\bar{z}\n\\end{align}\n%\nwhere $a$ and $d$ are complex, but $c$ and $f$ are real.\n\n%==============================================================================\n\\end{document}\n%==============================================================================\n\n\n\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", "meta": {"hexsha": "20d0ace9818e8afd4e74aced90f4f1e995797862", "size": 3276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/ComplexOneka.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/ComplexOneka.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/ComplexOneka.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": 24.8181818182, "max_line_length": 88, "alphanum_fraction": 0.4703907204, "num_tokens": 1319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6998587975748708}}
{"text": "\\section{Improper Integrals}\\label{sec:ImproperIntegrals}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\nRecall that the Fundamental Theorem of Calculus says that if $f$ is a \\underline{{\\bf continuous}} function on the closed interval $[a,b]$, then\r\n$$\\ds{\\int_a^b f(x)~dx=F(x)\\bigg|_a^b=F(b)-F(a)},$$\r\nwhere $F$ is any antiderivative of $f$. \r\n\r\nBoth the {\\bf continuity} condition and {\\bf closed interval} must hold to use the Fundamental Theorem of Calculus, and in this case, $\\ds\\int_a^b f(x)\\,dx$ represents the net area under $f(x)$ from $a$ to $b$: \r\n$$\\includegraphics[width=2.25in]{images2/area-under}$$\r\n\r\nWe begin with an example where blindly applying the Fundamental Theorem of Calculus can give an incorrect result.\r\n\r\n\\begin{example}{Using FTC}{Using FTC}\r\nExplain why $\\ds\\int_{-1}^1\\frac{1}{x^2}\\,dx$ is not equal to $-2$.\r\n\\end{example}  \r\n\r\n\\begin{solution}\r\nHere is how one might proceed:  \r\n$$\r\n\\int_{-1}^1\\frac{1}{x^2}\\,dx \r\n~=~ \\int_{-1}^1 x^{-2}\\,dx \r\n~=~ -x^{-1}\\bigg|_{-1}^1 \r\n~=~ -\\frac{1}{x}\\bigg|_{-1}^1 \r\n~=~ \\left(-\\frac{1}{1}\\right) - \\left(-\\frac{1}{(-1)}\\right) \r\n~=~ -2$$  \r\n However, the above answer is {\\bf WRONG!} \r\n Since $f(x)=1/x^2$ is not continuous on $[-1,~1]$, we cannot directly apply the Fundamental Theorem of Calculus.\r\nIntuitively, we can see why $-2$ is not the correct answer by looking at the graph of $f(x)=1/x^2$ on $[-1,~1]$.\r\nThe shaded area appears to grow without bound as seen in the figure below.\r\n$$\\includegraphics[width=2.5in]{images2/improper-integral-example-1}$$\r\n\\end{solution}\r\n\r\nFormalizing this example leads to the concept of an improper integral.\r\nThere are two ways to extend the Fundamental Theorem of Calculus.\r\nOne is to use an {\\bf infinite interval}, i.e., $[a,\\infty)$, $(-\\infty,b]$ or $(-\\infty,\\infty)$.\r\nThe second is to allow the interval $[a,b]$ to contain an infinite {\\bf discontinuity} of $f(x)$.\r\nIn either case, the integral is called an {\\bf improper integral}.  \r\nOne of the most important applications of this concept is probability distributions.  \r\n\r\nTo compute improper integrals, we use the concept of limits along with the Fundamental Theorem of Calculus.\r\n \r\n\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\nIf $f(x)$ is continuous on $[a,\\infty)$, then the improper integral of $f$ over $[a,\\infty)$ is:\r\n$$\\int_{a}^{\\infty} f(x)\\,dx:=\\lim_{R\\to\\infty}\\int_a^R f(x)\\,dx.$$ \r\nIf $f(x)$ is continuous on $(-\\infty,b]$, then the improper integral of $f$ over $(-\\infty,b]$ is:\r\n$$\\int_{-\\infty}^b f(x)\\,dx:=\\lim_{R\\to -\\infty}\\int_R^b f(x)\\,dx.$$\r\n\\end{definition}\r\n\r\nIf the limit exists and is a finite number, we say the improper integral {\\bf converges}. Otherwise, we say the  improper integral {\\bf diverges}.\r\n\r\nTo get an intuitive (though not completely correct) interpretation of improper integrals, we attempt to analyze $\\ds\\int_a^\\infty f(x)\\,dx$ graphically. \r\n Here assume $f(x)$ is continuous on $[a,\\infty)$: \r\n$$\\includegraphics[width=5in]{images2/improper-integral-theory-2}$$ \r\n We let $R$ be a fixed number in $[a,\\infty)$. \r\n Then by taking the limit as $R$ approaches $\\infty$, we get the improper integral:  \r\n$$\\int_a^\\infty f(x)\\,dx:=\\lim_{R\\to\\infty}\\int_a^R f(x)\\,dx.$$ \r\n We can then apply the Fundamental Theorem of Calculus to the last integral as $f(x)$ is continuous on the closed interval $[a,R]$.\r\n\r\nWe next define the improper integral for the interval $(-\\infty,~\\infty)$.\r\n\r\n\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\n If both $\\ds\\int_{-\\infty}^a f(x)\\,dx$ and $\\ds\\int_{a}^{\\infty} f(x)\\,dx$ are convergent, then the improper integral of $f$ over $(-\\infty,\\infty)$ is:\r\n$$\\int_{-\\infty}^{\\infty} f(x)\\,dx:=\\int_{-\\infty}^a f(x)\\,dx+\\int_{a}^{\\infty} f(x)\\,dx$$\r\n\\end{definition}\r\n\r\nThe above definition requires {\\bf both} of the integrals\r\n$$\\int_{-\\infty}^a f(x)\\,dx\\qquad\\mbox{and}\\qquad\\int_{a}^{\\infty} f(x)\\,dx$$\r\nto be convergent for $\\ds\\int_{-\\infty}^{\\infty} f(x)\\,dx$ to also be convergent. \r\n If {\\bf either} of $\\ds\\int_{-\\infty}^a f(x)\\,dx$ or $\\ds\\int_{a}^{\\infty} f(x)\\,dx$ is divergent, then so is $\\ds\\int_{-\\infty}^{\\infty} f(x)\\,dx$.\r\n\r\n\\begin{example}{Improper Integral}{Improper Integral}\r\nDetermine whether $\\ds\\int_1^\\infty\\frac{1}{x}\\,dx$ is convergent or divergent.\r\n\\end{example} \r\n\r\n\\begin{solution}\r\n Using the definition for improper integrals we write this as:\r\n$$\t\\int_1^\\infty \\frac{1}{x}\\,dx= \\lim_{R\\to\\infty} \\int_1^R\\frac{1}{x}\\,dx\r\n\t= \\lim_{R\\to\\infty} \\ln|x|\\bigg|_1^R\r\n\t=\\lim_{R\\to\\infty} \\ln|R| - \\ln|1|\r\n\t= \\lim_{R\\to\\infty} \\ln|R|\r\n\t= +\\infty$$\r\n Therefore, the integral is {\\bf divergent}.\r\n\\end{solution}\r\n\r\n\\begin{example}{Improper Integral}{Improper Integral}\r\nDetermine whether $\\ds\\int_{-\\infty}^\\infty x\\sin(x^2)\\,dx$ is convergent or divergent.\r\n\\end{example}  \r\n\r\n\\begin{solution}\r\n We must compute both $\\ds\\int_0^\\infty x\\sin(x^2)\\,dx$ and $\\ds\\int_{-\\infty}^0 x\\sin(x^2)\\,dx$.  \r\n Note that we don't have to split the integral up at $0$, any finite value $a$ will work.  \r\n First we compute the indefinite integral.  \r\n Let $u=x^2$, then $du=2x\\,dx$ and hence, \r\n$$\\int x\\sin(x^2)\\,dx=\\frac{1}{2} \\int \\sin(u)\\,du=-\\frac{1}{2}\\cos(x^2)+C$$\r\nUsing the definition of improper integral gives: \r\n$$\\int_0^\\infty x\\sin(x^2)\\,dx  =  \\lim_{R\\to\\infty} \\int_0^R x\\sin(x^2)\\,dx \r\n=\\lim_{R\\to\\infty} \\left[-\\frac{1}{2}\\cos(x^2)\\right] \\bigg|_0^R \r\n=  -\\frac{1}{2} \\lim_{R\\to\\infty} \\cos(R^2) +\\frac{1}{2}$$\r\nThis limit does not exist since $\\cos x$ {\\bf oscillates} between $-1$ and $+1$. \r\n In particular, $\\cos x$ does not approach any particular value as $x$ gets larger and larger. \r\n Thus, $\\ds\\int_0^\\infty x\\sin(x^2)\\,dx$ diverges, and hence, $\\ds\\int_{-\\infty}^\\infty x\\sin(x^2)\\,dx$ diverges.\r\n\\end{solution}\r\n\r\nWhen there is a discontinuity in $[a,b]$ or at an endpoint, then the improper integral is as follows.\r\n\r\n\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\nIf $f(x)$ is continuous on $(a,b]$, then the improper integral of $f$ over $(a,b]$ is:  \r\n$$\\int_a^b f(x)\\,dx:=\\lim_{R\\to a^+}\\int_R^b f(x)\\,dx.$$  \r\nIf $f(x)$ is continuous on $[a,b)$, then the improper integral of $f$ over $[a,b)$ is:  \r\n$$\\int_a^b f(x)\\,dx:=\\lim_{R\\to b^-}\\int_a^R f(x)\\,dx.$$\r\n\\end{definition}\r\n\r\nIf the limit above exists and is a finite number, we say the improper integral {\\bf converges}.\r\nOtherwise, we say the improper integral {\\bf diverges}. \r\n\r\nWhen there is a discontinuity in the interior of $[a,b]$, we use the following definition.\r\n\r\n\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\nIf $f$ has a discontinuity at $x=c$ where $c\\in[a,b]$, and both\r\nboth $\\ds\\int_a^c f(x)\\,dx$ and $\\ds\\int_c^b f(x)\\,dx$ are convergent, then $f$ over $[a,b]$ is:  \r\n$$\\int_a^b f(x)\\,dx:=\\int_a^c f(x)\\,dx+\\int_c^b f(x)\\,dx$$\r\n\\end{definition}\r\n\r\nAgain, we can get an intuitive sense of this concept by analyzing $\\ds\\int_a^b f(x)\\,dx$ graphically. \r\nHere assume $f(x)$ is continuous on $(a,b]$ but discontinuous at $x=a$: \r\n$$\\includegraphics[width=5in]{images2/improper-integral-theory-1}$$ \r\n We let $R$ be a fixed number in $(a,b)$. \r\n Then by taking the limit as $R$ approaches $a$ from the {\\bf right},  we get the improper integral: \r\n$$\\int_a^b f(x)\\,dx:=\\lim_{R\\to a^+}\\int_R^b f(x)\\,dx.$$ \r\n Now we can apply FTC to the last integral as $f(x)$ is continuous on $[R,b]$.\r\n\r\n\\begin{example}{A Divergent Integral}{A Divergent Integral}\r\nDetermine if $\\ds\\int_{-1}^1\\frac{1}{x^2}\\,dx$ is convergent or divergent.\r\n\\end{example}  \r\n\r\n\\begin{solution}\r\n The function $f(x)=1/x^2$ has a discontinuity at $x=0$, which lies in $[-1,1]$.  \r\n We must compute $\\ds\\int_{-1}^0 \\frac{1}{x^2}\\,dx$ and $\\ds\\int_0^1 \\frac{1}{x^2}\\,dx$. Let's start with $\\ds\\int_0^1 \\frac{1}{x^2}\\,dx$:  \r\n$$\\int_0^1 \\frac{1}{x^2}\\,dx = \\lim_{R\\to 0^+} \\int_R^1 \\frac{1}{x^2} \\,dx = \\lim_{R\\to 0^+} -\\frac{1}{x}\\bigg|_R^1\r\n= -1 + \\lim_{R\\to 0^+} \\frac{1}{R}$$\r\nwhich diverges to $+\\infty$.\r\n Therefore, $\\ds\\int_{-1}^1\\frac{1}{x^2}\\,dx$ is {\\bf divergent} since one of $\\ds\\int_{-1}^0 \\frac{1}{x^2}\\,dx$ and $\\ds\\int_0^1 \\frac{1}{x^2}\\,dx$ is divergent.\r\n\\end{solution}\r\n\r\n\r\n% % % % % % %\r\n% % The following example 'Integral of the Logarithm' can be replaced with the next example if Integration by Parts is not included in the text adaptation.\r\n\\begin{example}{Integral of the Logarithm}{Integral of the Logarithm}\r\nDetermine if $\\ds\\int_0^1 \\ln x \\,dx$ is convergent or divergent. Evaluate it if it is convergent.\r\n\\end{example}  \r\n\r\n\\begin{solution}\r\nNote that $f(x)=\\ln x$ is discontinuous at the endpoint $x=0$. \r\nWe first use integration by parts to compute $\\ds\\int\\ln x\\,dx$.\r\nWe let $u=\\ln x$ and $dv=dx$.\r\nThen $du=(1/x)dx$, $v=x$, giving:\r\n\\begin{eqnarray*}\r\n\\int \\ln x\\,dx &=& \\ds x\\ln x-\\int x\\cdot\\frac{1}{x}\\,dx\\\\\r\n&=& x\\ln x-\\int 1\\,dx\\\\\r\n&=& x\\ln x-x+C\\\\\r\n\\end{eqnarray*}\r\n Now using the definition of improper integral for $\\ds\\int_0^1 \\ln x \\,dx$: \r\n$$\r\n\t\\int_0^1 \\ln x \\,dx = \\lim_{R\\to 0^+} \\int_R^1 \\ln x\\,dx \r\n\t=  \\lim_{R\\to 0^+} (x\\ln x-x)\\bigg|_R^1 \r\n\t%=  \\lim_{R\\to 0^+} \\left(\\left[\\ln 1-1\\right] - \\left[R\\ln R-R\\right]\\right)\r\n\t=  -1 - \\lim_{R\\to 0^+}(R\\ln R) + \\lim_{R\\to 0^+}R \r\n$$\r\nNote that $\\ds\\lim_{R\\to 0^+}R=0$. \r\nWe next compute $\\ds\\lim_{R\\to 0^+}(R\\ln R)$.\r\nFirst, we rewrite the expression as follows:\r\n$$\\lim_{x\\to0^+}(R\\ln R)=\\lim_{R\\to0^+}\\frac{\\ln R}{1/R}.$$\r\nNow the limit is of the indeterminate type $(-\\infty)/(\\infty)$ and l'H\\^opital's Rule can be applied.  \r\n$$\\lim_{R\\to0^+}(R\\ln R) =\\lim_{R\\to0^+}\\frac{\\ln R}{1/R}\r\n=\\lim_{R\\to0^+}\\frac{1/R}{-1/R^2}\r\n=\\lim_{R\\to0^+}-\\frac{R^2}{R}\r\n=\\lim_{R\\to0^+}(-R)\r\n=0$$\r\nThus, $\\ds\\lim_{R\\to 0^+}(R\\ln R)=0$.\r\nThus\r\n$$\\int_0^1 \\ln x \\,dx = -1,$$ \r\nand the integral is convergent to $-1$. \r\n\r\nGraphically, one might interpret this to mean that the net area under $\\ln x$ on $[0,1]$ is $-1$ (the area in this case lies below the $x$-axis). \r\n$$\\includegraphics[width=2.5in]{images2/improper-integral-example-2}$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Integral of a Square Root}{IntSquareRoot}\r\nDetermine if $\\ds\\int_0^4\\frac{dx}{\\sqrt{4-x}}$ is convergent or divergent. Evaluate it if it is convergent.\r\n\\end{example}\r\n\\begin{solution}\r\nNote that $\\frac{1}{\\sqrt{4-x}}$ is discontinuous at the endpoint $x=4$. We use a $u$-substitution to compute $\\int \\frac{dx}{\\sqrt{4-x}}$. We let $u=4-x$, then $du=-dx$, giving:\r\n\\begin{align*}\r\n\\ds\\int\\frac{dx}{\\sqrt{4-x}}&=\\int-\\frac{du}{u^{1/2}}\t\\\\\r\n&=\\int -u^{-1/2}\\,du\t\\\\\r\n&=-2(u)^{1/2}+C\t\\\\\r\n&=-2\\sqrt{4-x}+C\r\n\\end{align*}\r\nNow using the definition of improper integrals for $\\ds\\int_0^4\\frac{dx}{\\sqrt{4-x}}$:\r\n\\[\\ds\\int_0^4\\frac{dx}{\\sqrt{4-x}}=\\lim_{R\\to4^{-}}(-2\\sqrt{4-x})\\bigg|_0^R=\\lim_{R\\to4^{-}}-2\\sqrt{4-R}+2\\sqrt{4}=4\\]\r\n\\end{solution}\r\n\r\n\\begin{example}{Improper Integral}{ImpIntExample}\r\nDetermine if $\\ds\\int_{1}^{2}\\dfrac{dx}{\\left( x-1\\right) ^{1/3}}$ is\r\nconvergent or divergent. Evaluate it if it is convergent.\r\n\\end{example}\r\n\\begin{solution}\r\nNote that $f\\left( x\\right) =\\dfrac{1}{\\left( x-1\\right) ^{1/3}}$\r\nis discontinuous at the endpoint $x=1.$ We first use substitution to find\r\n$\\ds\\int \\dfrac{dx}{\\left( x-1\\right) ^{1/3}}.$ We let $u=x-1.$ Then $du=dx,$\r\ngiving%\r\n\\begin{equation*}\r\n\\int \\dfrac{dx}{\\left( x-1\\right) ^{1/3}}=\\int \\frac{du}{u^{1/3}}=\\int\r\nu^{-1/3}du=\\frac{3}{2}u^{2/3}+C=\\frac{3}{2}\\left( x-1\\right) ^{2/3}+C.\r\n\\end{equation*}%\r\nNow using the definition of improper integral for $\\ds\\int_{1}^{2}\\dfrac{dx}{%\r\n\t\\left( x-1\\right) ^{1/3}}:$%\r\n\\begin{equation*}\r\n\\int_{1}^{2}\\dfrac{dx}{\\left( x-1\\right) ^{1/3}}=\\lim_{R\\rightarrow\r\n\t1^{+}}\\int_{R}^{2}\\dfrac{dx}{\\left( x-1\\right) ^{1/3}}=\\left.\r\n\\lim_{R\\rightarrow 1^{+}}\\frac{3}{2}\\left( x-1\\right) ^{2/3}\\right\\vert\r\n_{R}^{2}=\\frac{3}{2}-\\lim_{R\\rightarrow 1^{+}}\\frac{3}{2}\\left( R-1\\right)\r\n^{2/3}=\\frac{3}{2},\r\n\\end{equation*}%\r\nand the integral is convergent to $\\frac{3}{2}.$ Graphically, one might\r\ninterpret this to mean that the net area under $\\dfrac{1}{\\left( x-1\\right)\r\n\t^{1/3}}$ on $\\left[ 1,2\\right] $ is $\\frac{3}{2}$.\r\n\r\n$$\\includegraphics[width=8cm]{images/improper-int-example}$$\r\n\\end{solution}\r\n\r\nThe following test allows us to determine convergence/divergence information about improper integrals that are hard to compute by comparing them to easier ones. \r\nWe state the test for $[a,\\infty)$, but similar versions hold for the other improper integrals.\r\n\r\n\\begin{formulabox}[The Comparison Test]\r\nAssume that $f(x)\\geq g(x)\\geq 0$ for $x\\geq a$.\r\n\\begin{enumerate}[(i)]\r\n\\item\tIf $\\ds\\int_a^\\infty f(x)\\,dx$ {\\bf converges}, then $\\ds\\int_a^\\infty g(x)\\,dx$ also {\\bf converges}.\r\n\\item\tIf $\\ds\\int_a^\\infty g(x)\\,dx$ {\\bf diverges}, then $\\ds\\int_a^\\infty f(x)\\,dx$ also {\\bf diverges}. \r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\nInformally, (i) says that if $f(x)$ is larger than $g(x)$, and the area under $f(x)$ is finite (converges), then the area under $g(x)$ must also be finite (converges). \r\nInformally, (ii) says that if $f(x)$ is larger than $g(x)$, and the area under $g(x)$ is infinite (diverges), then the area under $f(x)$ must also be infinite (diverges). \r\n\r\n$$\\includegraphics[width=6in]{images2/improper-integral-theory-3}$$\r\n\r\n\\begin{example}{Comparison Test}{Comparison Test}\r\nShow that $\\ds\\int_2^\\infty \\frac{\\cos^2x}{x^2} \\,dx$ converges.\r\n\\end{example} \r\n\r\n\\begin{solution}\r\nWe use the comparison test to show that it converges. \r\nNote that $0\\leq \\cos^2x\\leq 1$ and hence \r\n$$0 \\leq\\frac{\\cos^2x}{x^2}\\leq\\frac{1}{x^2}.$$\r\nThus, taking $f(x)=1/x^2$ and $g(x)=\\cos^2x / x^2$ we have $f(x)\\geq g(x)\\geq 0$. \r\nOne can easily see that $\\ds\\int_2^\\infty \\frac{1}{x^2}\\,dx$ converges. \r\nTherefore, $\\ds\\int_2^\\infty \\frac{\\cos^2x}{x^2} \\,dx$ also converges.\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:ImproperIntegrals}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n\\begin{ex}\r\n\tDetermine whether $\\ds\\int_1^{\\infty}\\frac{1}{x^2}\\,dx$ is convergent or divergent.\r\n\t\\begin{sol}\r\n\t\tConverges to 1.\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tDetermine whether $\\ds\\int_e^{\\infty}\\frac{1}{x\\sqrt{\\ln x}}\\,dx$ is convergent or divergent.\r\n\t\\begin{sol}\r\n\t\tDiverges.\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tEvaluate the improper integral $\\ds\\int_0^{\\infty}e^{-3x}\\,dx$.\r\n\t\\begin{sol}\r\n\t\t1/3\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tDetermine if $\\ds\\int_1^e\\frac{1}{x(\\ln x)^2}\\,dx$ is convergent or divergent. Evaluate it if it is convergent.\r\n\t\\begin{sol}\r\n\t\tDivergent.\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tShow that $\\ds\\int_0^{\\infty}e^{-x}\\sin^2\\left(\\frac{\\pi x}{2}\\right)\\,dx$ converges.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tEvaluate $\\ds\\int_{-\\infty}^{\\infty}\\frac{1}{x^2+1}\\,dx$ and $\\ds\\int_{-\\infty}^{\\infty}\\frac{x}{x^2+1}\\,dx$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tDetermine whether the following improper integrals are convergent or divergent. Evaluate those that are convergent.\r\n\t\\begin{enumerate}\r\n\t\t\\item\t$\\int_{0}^{\\infty}\\dfrac{1}{x^2+1}\\,dx$\r\n\t\t\\item\t$\\int_{0}^{\\infty}\\dfrac{x}{x^2+1}\\,dx$\r\n\t\t\\item\t$\\int_{0}^{\\infty}e^{-x}(\\cos x+\\sin x)\\,dx$. [Hint: What is the derivative of $-e^{-x}\\cos x?$]\r\n\t\t\\item\t$\\int_{0}^{\\pi/2}\\sec^{2}x\\,dx$\r\n\t\t\\item\t$\\int_{0}^{4}\\dfrac{1}{(4-x)^{2/5}}\\,dx$\r\n\t\\end{enumerate}\r\n\t\\begin{sol}\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item\t$\\pi/2$\r\n\t\t\t\\item\tdivergent (to $\\infty$)\r\n\t\t\t\\item\t1\r\n\t\t\t\\item\tdivergent (to $\\infty$)\r\n\t\t\t\\item\t$\\frac{5}{3}(4^{3/5})$\r\n\t\t\\end{enumerate}\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tProve that the integral $\\int_{1}^{\\infty}\\dfrac{1}{x^p}\\,dx$ is convergent if $p>1$ and divergent if $0<p\\leq 1$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tSuppose that $p>0$. Find all values of $p$ for which $\\int_{0}^{1}\\dfrac{1}{x^p}\\,dx$ converges.\r\n\t\\begin{sol}\r\n\t\t$0<p<1$\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tShow that $\\int_{1}^{\\infty}\\dfrac{\\sin^2 x}{x(\\sqrt{x}+1)}\\,dx$ converges.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "9ac0a9f5ec37902bb6329dea788d7bcf1797fa83", "size": 15928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-7-improper-integrals.old.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7-techniques-of-integration/7-7-improper-integrals.old.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7-techniques-of-integration/7-7-improper-integrals.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": 47.124260355, "max_line_length": 212, "alphanum_fraction": 0.6387493722, "num_tokens": 5987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.6998587948756787}}
{"text": "\\documentclass{article}\n\n% Language setting\n% Replace `english' with e.g. `spanish' to change the document language\n\\usepackage[english]{babel}\n\n\\usepackage{witharrows}\n\n% Set page size and margins\n% Replace `letterpaper' with `a4paper' for UK/EU standard size\n\\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}\n\n% Useful packages\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\n\n\\title{Your Paper}\n\\author{You}\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Uniswapv1}\n\n\\begin{equation}\n   x*y=k \\quad  \\text{where:} \\quad\n   \\begin{gathered}\n   x \\quad \\text{is total amount of asset A} \\\\\n   y \\quad \\text{is total amount of asset B} \\\\\n   k \\quad \\text{is constant} \\\\\n    \\end{gathered}\n\\end{equation}\n\n\\begin{equation}\n  (x+\\Delta x)*(y-\\Delta y)=k \\quad  \\text{where:} \\quad\n  \\begin{gathered}\n   x \\quad \\text{is total amount of asset A} \\\\\n   \\Delta x \\quad \\text{is sold amount of asset A} \\\\\n   y \\quad \\text{is total amount of asset B} \\\\\n   \\Delta y \\quad \\text{is bought amount of asset B} \\\\\n   k \\quad \\text{is constant} \\\\\n    \\end{gathered}\n\\end{equation}\n\n\\begin{equation}\n\\begin{WithArrows}\nx*y = (x+\\Delta x)*(y-\\Delta y) \\\\ \ny-\\Delta y = \\dfrac{x*y}{x+\\Delta x}\n\\end{WithArrows}\n\\end{equation}\n\n\n\\begin{equation}\n\\begin{WithArrows}\n\\Delta y &= y - \\dfrac{x*y}{x+\\Delta x} \\\\\n&= \\dfrac{y*(x+\\Delta x)}{x+\\Delta x} - \\dfrac{x*y}{x+\\Delta x} \\\\\n&= \\dfrac{y*x +y \\Delta x - x*y}{x+\\Delta x} \\\\\n&= \\dfrac{y \\Delta x}{x+\\Delta x}\n\\end{WithArrows}\n\\end{equation}\n\nLet's consider that \\(\\Delta x_f\\) is the sold amount of asset A \\(\\Delta x\\) minus the fees\\\\\n\\begin{equation}\n\\begin{WithArrows}\n   \\Delta x_f &= \\Delta  x - \\Delta x*0,3\\% \\\\\n   &= \\Delta x * (1-0,3\\%) \\\\\n   &= \\Delta x * (\\dfrac{1000}{1000}-\\dfrac{3}{1000}) \\\\\n   &= \\Delta x * \\dfrac{997}{1000}\n \\end{WithArrows}\n\\end{equation}\n\n\\begin{equation}\n\\begin{WithArrows}\n\\Delta y &=  \\dfrac{y \\Delta x_f}{x+\\Delta x_f}\n\\end{WithArrows}\n\\end{equation}\n\n\n\\begin{equation}\n\\begin{WithArrows}\n\\Delta y &=  \\dfrac{y \\Delta x_f}{x+\\Delta x_f} \\\\\n&= \\dfrac{\\dfrac{997*y*\\Delta x}{1000}}{x+\\dfrac{997*\\Delta x}{1000}} \\\\\n&= \\dfrac{997 ’y \\Delta x}{1000 x + 997 \\Delta x}\n\\end{WithArrows}\n\\end{equation}\n\n\n\\end{document}", "meta": {"hexsha": "041b12d04b678b195edc6c18da323e6613fac8a6", "size": 2276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/uniswap-v1/equations.tex", "max_stars_repo_name": "smartcontractkit/defi-minimal", "max_stars_repo_head_hexsha": "7823b93e55ff5031850895b7ba9db940421161dc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2022-03-18T22:39:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T02:33:28.000Z", "max_issues_repo_path": "docs/uniswap-v1/equations.tex", "max_issues_repo_name": "smartcontractkit/defi-minimal", "max_issues_repo_head_hexsha": "7823b93e55ff5031850895b7ba9db940421161dc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-03-21T01:27:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T14:14:58.000Z", "max_forks_repo_path": "docs/uniswap-v1/equations.tex", "max_forks_repo_name": "smartcontractkit/defi-minimal", "max_forks_repo_head_hexsha": "7823b93e55ff5031850895b7ba9db940421161dc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-03-19T18:18:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T13:14:28.000Z", "avg_line_length": 25.2888888889, "max_line_length": 94, "alphanum_fraction": 0.6533391916, "num_tokens": 838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6998587850190022}}
{"text": "%\\begin{appendices}\n\\chapter{Derivation of the objective function $J(\\mu)$}\n\\label{derivation1}\nThe objective function to be minimized is given by\n\\[ \\min_{k \\in K_{conv}} \\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 \\]\nExpanding the norm on the first part of the sum\n\\begin{equation}\n\\begin{split}\n\\min_{k \\in K_{conv}} \\frac{1}{2}\\sum_{i=1}^n \\bigg(\\norm{x_i}^2 - 2*\\sum_{x_j \\in B_i} k_{ij} (x_i \\cdot x_j)  + \\\\ k_i k_i^T \\circ d_i d_i^T \\circ X^TX \\bigg) + \\gamma* \\sum_{i=1}^n \\sum_{x_j \\in B_i} k_{ij} \\norm{x_i-x_j}^2\n\\end{split}\n\\label{new_obj}\n\\end{equation}\nThe notation `$\\circ$' denotes elementwise multiplication of two vectors. Here the summation $\\sum_{i=1}^n \\norm{x_i}^2$ can be discarded, since it is independent of the optimization parameters. Substituting $X^TX = P$, \n\\[\\sum_{x_j \\in B_i} k_{ij} (x_i \\cdot x_j) = k_i \\circ d_i \\circ p_i\\]\nand \n\\[ \\sum_{x_j \\in B_i} k_{ij} \\norm{x_i-x_j}^2 = k_i \\circ d_i \\circ v_i \\]\nin \\ref{new_obj} we will get the simplified objective function\n\\begin{equation}\n\\begin{split}\n\\min_{k \\in K_{conv}} \\sum_{i=1}^n \\bigg( k_i k_i^T \\circ d_i d_i^T \\circ P + \\\\ 2\\big(\\gamma*k_i \\circ v_i \\circ d_i - k_i \\circ p_i \\circ d_i\\big) \\bigg)\n\\end{split}\n\\label{simplified}\n\\end{equation}\nHere $p_i$ and $v_i$ are columns of $P$ and $M$ corresponding to $x_i$ respectively. Substituting $k_i = \\sum_{t=1}^m \\mu_tk_{t,i}$ in \\ref{simplified} we will get\n\\[ \\min_{\\mu \\in \\Delta} \\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 \\]\nwhich is the objective function $J(\\mu)$. Here $[z]_t = \\sum_{i=1}^n (2 \\gamma v_i \\circ d_i - 2 p_i \\circ d_i)^T \\mathit{k}_{t,i} $ 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.\n\n\\chapter{Derivation of cost function $\\mathcal{J}(\\alpha)$ in KFDA}\n\\label{derivation2}\nThe cost function is given as\n\\begin{equation}\n\\mathcal{J}(f) = \\frac{f^TS_B^{\\phi}f}{f^TS_W^{\\phi}f} \n\\label{b_jw}\n\\end{equation}\nWe have\n\\begin{equation}\nf^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\n\\label{b_wmi}\n\\end{equation}\napplying \\ref{b_wmi} in the numerator of \\ref{b_jw} we get\n\\begin{equation*}\n\\begin{aligned}\nf^TS_B^{\\phi}f &= f^T(m_1^{\\phi} - m_2^{\\phi})(m_1^{\\phi} - m_2^{\\phi})^Tf \\\\\n&= (f^T m_1^{\\phi}-f^Tm_2^{\\phi}) \\cdot (f^Tm_1^{\\phi}-f^Tm_2^{\\phi}) \\\\\n&= (\\alpha^T M_1 - \\alpha^T M_2) \\cdot (\\alpha^T M_1 - \\alpha^T M_2) \\\\\n&= \\alpha^T (M_1 - M_2)(M_1 - M_2)^T \\alpha \\\\\n&= \\alpha^T M \\alpha\n\\end{aligned}\n\\end{equation*}\nwhere $M = (M_1-M_2)(M_1-M_2)^T$. Applying $f = \\sum_{i=1}^n \\alpha_i \\phi(x_i)$ in the denominator of \\ref{b_jw}\n\\begin{equation}\nf^TS_W^{\\phi}f = (\\sum_{i=1}^n \\alpha_i \\phi(x_i))^T \\sum_{j=1,2} \\sum_{x \\in X_j} (\\phi(x)-m_j^{\\phi})(\\phi(x)-m_j^{\\phi})^T (\\sum_{i=1}^n \\alpha_i \\phi(x_i))\n\\label{b_wsw}\n\\end{equation}\nTo simplify the notations, define\n\\[ P_{ij} =  \\sum_{x \\in X_i} \\phi(x_j) \\cdot \\phi(x) \\]\nThen \n\\begin{equation}\n\\sum_{i=1}^n \\sum_{j=1,2} \\sum_{x \\in X_j} \\alpha_i(\\phi(x_i) \\cdot \\phi(x)) = \\alpha^TP_1 + \\alpha^T P_2\n\\label{b_alphap}\n\\end{equation}\nApplying \\ref{b_alphap} in \\ref{b_wsw} we get\n\\begin{equation*}\n\\begin{aligned}\nf^TS_W^{\\phi}f &= (\\alpha^T P_1 - \\alpha^T M_1) \\cdot (\\alpha^T P_1 - \\alpha^T M_1) + (\\alpha^T P_2 - \\alpha^T M_2) \\cdot (\\alpha^T P_2 - \\alpha^T M_2) \\\\\n&= \\alpha^T(P_1-M_1)(P_1-M_1)^T \\alpha + \\alpha^T(P_2-M_2)(P_2-M_2)^T \\alpha \\\\\n&= \\alpha^T K_1(I - \\bm{1}_{n_1})K_1^T \\alpha + \\alpha^T K_2(I - \\bm{1}_{n_2})K_2^T \\alpha \\\\\n&= \\alpha^T \\Big(\\sum_{i=1,2} K_i(I - \\bm{1}_{n_i})K_i^T \\Big) \\alpha \\\\\n&= \\alpha^T N \\alpha\n\\end{aligned}\n\\end{equation*}\nwhere $K_j = \\sum_{i=1}^n \\sum_{x \\in X_j} k(x_i, x)$, $I$ is the identity matrix, $\\bm{1}_{n_j}$ is the matrix with with all entries $\\frac{1}{n_j}$ and $N = \\sum_{i=1,2} K_i(I - \\bm{1}_{n_i})K_i^T$. Thus the cost function becomes\n\\[\\mathcal{J}(f) = \\frac{f^TS_B^{\\phi}f}{f^TS_W^{\\phi}f} = \\frac{\\alpha^T M \\alpha}{\\alpha^T N \\alpha} \\]\n%\\end{appendices}\n", "meta": {"hexsha": "e7cd33e9f9d849b7114c984c13e00415a079400a", "size": 4133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/appendix.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/appendix.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/appendix.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": 55.1066666667, "max_line_length": 263, "alphanum_fraction": 0.6331962255, "num_tokens": 1882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6998176931453345}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 7}\n\nSuppose that, instead of sorting an array, we just require that the elements increase on average.\nMore precisely, we call an $n$-element array $A$, \\textbf{k-sorted} if, for all $i = 1, 2, ..., n-k$ Equation \\ref{eq71} holds.\n\n\\begin{equation}\\label{eq71}\n\\frac{\\sum_{j=i}^{i + k - 1} A[j]}{k} \\leq \\frac{\\sum_{j=i+1}^{i + k} A[j]}{k}\n\\end{equation}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item What does it mean for an array to be 1-sorted?\n\\item Give a permutation of the numbers $1$, $2$, $3$, ..., $10$, that is $2$-sorted but not sorted.\n\\item Prove that an $n$-element array is $k$-sorted if and only if $A[i] \\leq A[i+k]$ for all $i = 1, 2, ..., n-k$.\n\\item Give an algorithm that $k$-sorts an $n$-element array in $\\mathcal{O}(n \\log (n/k))$ time.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Using Equation \\ref{eq71} and substituting $k$ with 1 would give Equation \\ref{eq72}.\n\\begin{equation}\\label{eq72}\nA[i] \\leq A[i+1]\n\\end{equation}\nTherefore, any array that is 1-sorted as actually sorted in ascending order.\n\\item One possible permutation of numbers $1$ to $10$ to result in a 2-sorted array is $1$, $6$, $2$, $7$, $3$, $8$, $4$, $9$, $5$ and $10$.\nThis is due that for any $1 \\leq i < 9$, Equation \\ref{eq73} would be valid.\n\\begin{equation}\\label{eq73}\n\\frac{\\sum_{j=i}^{i + 1} A[j]}{2} \\leq \\frac{\\sum_{j=i+1}^{i + 2} A[j]}{2}\n\\end{equation}\n\\item Proof is given by induction on length of array $n$.\n\\begin{enumerate}\n\\item[] \\textit{Base case}: ($n = 2$)\\\\\nWhen length of array is 2, $k = 1$, Equation \\ref{eq71} dictates that $A[i] \\leq A[i+1]$ which confirms the hypothesis.\n\\item[] \\textit{Induction Step}\\\\\nWe form inductive hypothesis as for any array of length $n$, the array is $k$-sorted if and only if $A[i] \\leq A[i+k]$.\nUsing the inductive hypothesis, we will show that the statement would hold true for arrays of length $n + 1$.\n\nAssuming that the $(n+1)$-element array is $k$-sorted, Equation \\ref{eq71} would be available to use.\nSubtracting the inductive hypothesis from Equation \\ref{eq71} would directly lead to $A[j] \\leq A[j+k]$ which is the right-side of the equation.\n\nWe should as well show that using $A[i] \\leq A[i+1]$ and adding the inductive hypothesis, Equation \\ref{eq71} would directly be obtained which shows the array is $k$-sorted.\n\\end{enumerate}\n\\item Inspired by the proposed $2$-sorted array of numbers $1$ to $10$, the algorithm to $k$-sort an $n$-element array is given as follows.\n\nWe first divide the array into $k$ subarrays.\nThis clearly is done in constant time and has no effect on runtime of the algorithm.\nThen, we sort all $k$ subarrays using Merge Sort.\nSince each array has length $\\frac{n}{k}$, the runtime for sorting $k$ subarrays would be $\\mathcal{O}(k\\frac{n}{k}\\log(\\frac{n}{k}))$.\nAll that remains is to reconstruct the final array by picking one element from $k$ subarrays, one in turn.\nThis leading to a run time of $\\mathcal{O}(n)$.\nTherefore the total runtime of this algorithm would be $\\mathcal{O}(n \\log(\\frac{n}{k}) + n ) = \\mathcal{O}(n \\log(\\frac{n}{k}) )$.\n\\end{enumerate}\n", "meta": {"hexsha": "ff9602043f8201cbea0a3f1b7d8fe982c6cc857d", "size": 3472, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q07.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q07.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q07.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": 57.8666666667, "max_line_length": 173, "alphanum_fraction": 0.6667626728, "num_tokens": 1094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997898, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.6998176880653905}}
{"text": "\\chapter{\\proj Wavelet and Multifractal Analysis}\n\\label{ch_fractal}\n\\index{fractal}\n% \\chapterhead{Programs}\n\\markright{Wavelet and Multifractal Analysis}\n\n\\section{Fractal}\n\\subsection{Introduction}\nThe word ``fractal'' was introduced by Mandelbrot \n(1977) \\cite{frac:mandel83}, and\ncomes from the Latin word {\\em fractus} which means ``to break''.\nAccording to Mandelbrot, a fractal is an object which has \na greater dimension than its topological dimension. A typical\nfractal is the Cantor set.\n \n\\subsubsection*{Example: the triadic Cantor set} \n\\label{triadic Cantor set}\nThe Cantor set is built in the following way: considering a\nsegment of dimension $L$, we separate it into three equal parts,\nand suppress the middle part. There remain two segments of size\n${L \\over 3}$. Repeating the process on both segments, we get \nfour segments of size ${3^{-2}L}$. After $n$ iterations, we have\n$2^n$ segments of size ${3^{-n}L}$. The Cantor set is obtained \nwhen $n$ tends to infinity. The set has the following properties:\n\\begin{enumerate}\n\\item It is self-similar.\n\\item It has a fine structure, i.e.\\ detail on arbitrary small\nscales.\n\\item It is too irregular to be described in traditional \ngeometrical language, both locally and globally.\n\\item It is obtained by successive iterations.\n\\item It has an infinite number of points but its length is null.\n\\end{enumerate}\nThese properties define in fact a fractal object. \n\nA real fractal does not exist in the nature, and we always need\nto indicate at which scales we are talking about fractality.\n\n\\subsection{The Hausdorff and Minkowski measure} \n\\label{Hausdorff}\n\\subsubsection*{Measure}\nAn object dimension describes how an object $F$ fills the space.\nA simple manner of measuring the length of\ncurves, the area of surfaces or the volume of objects is to divide the \nspace into small boxes (segment in one dimension, surface in 2D, and cubes\nin 3D)  of diameter $\\delta$ as shown in Figure \\ref{fig_mes} \n\\cite{frac:falconer90}. These boxes\nare chosen so that their diameter is not greater than a given size $\\delta$,\nwhich corresponds to the measure resolution.\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_frac1.ps,bbllx=5cm,bblly=12cm,bburx=16cm,bbury=18cm,height=6cm,width=12cm,clip=}\n}}\n\\caption{Measuring the ``size'' of curves (Feder 1988).}\n\\index{Mallat's multiresolution}\n\\label{fig_mes}\n\\end{figure}\n\nWe consider now the quantity:\n\\begin{eqnarray}\nL_{\\delta}^d(F) = \\sum diam(B_i)^d\n\\end{eqnarray}\nwhere $d$ is a real number, $diam(B_i)$ is the diameter of the  box  $i$.\n$L_{\\delta}^s(F)$ represents an estimation of the size of $F$ at the resolution\n$\\delta$. Depending on the choice of the boxes, the measure is more or less \ncorrect. Generally, it is easier to manipulate the Minkowski-Bouligand \nmeasure which fixes all the boxes to the same size $\\delta$. Using this\nmeasure, the size of $F$ is given by:\n\\begin{eqnarray}\nM^s(F) = \\lim_{\\delta \\rightarrow 0} \\sum diam(B_i)^s = \\delta^s N_B(\\delta)\n\\end{eqnarray}\nwhere $N_B$ is the number of boxes needed to cover the object $F$.\nThen the curves of length $L_\\ast$ in Figure~\\ref{fig_mes}   \ncan be measured by finding the number $N_B(\\delta)$ of line segments\n (respectively squares and cubes for the second and third object)\nof length $\\delta$ needed to cover the object. The three sizes are:\n\\begin{eqnarray}\nL  &  = M^1(F) = & N_B(\\delta) \\delta^1 \\mathop\\rightarrow_{\\delta \\to 0} \n      L_\\ast \\delta^0  \\nonumber  \\\\\nA  & = M^2(F) = & N_B(\\delta) \\delta^2 \\mathop\\rightarrow_{\\delta \\to 0}\n      L_\\ast \\delta^1 \\nonumber \\\\\nV  & = M^3(F) = & N_B(\\delta) \\delta^3  \\mathop\\rightarrow_{\\delta \\to 0}\n      L_\\ast \\delta^2         \n\\end{eqnarray}\n\n\\subsection{The Hausdorff and Minkowski dimension}\n\nThe Hausdorff dimension $d_H$ of the set $F$ is the {\\it\ncritical dimension} for which the measure $H^d(F)$ jumps from infinity\nto zero:\n\\begin{eqnarray}\n  H^d(F) =  \\left\\{ \\begin{array}{ll}\n                      0,      &  d > d_H, \\\\\n                      \\infty, &  d < d_H.\n                   \\end{array}\n           \\right.\n \\label{eq-ch2-1}\n\\end{eqnarray}\nBut $H^{d_H}(F)$ can be finite or infinite. For a simple set \n(segment, square, cube),\nHausdorff dimension is equal to the topological dimension (i.e.\\ 1, 2, \nor 3). This is not true for a more complex set, such as the Cantor set.\nMinkowski dimension $d_M$ (and $d_H (F) \\le d_M(F)$) is defined \nin a similar way using Minkowski measure.\n\nBy definition, we have:\n\\begin{eqnarray}\nM^{d_M} = \\lim_{\\delta \\rightarrow 0} \\delta^{d_M} N_B(\\delta)\n\\end{eqnarray}\nWhen $\\delta \\rightarrow 0$, we have $d_M \\ln M= d_M\\ln{\\delta} + \\ln{N_N(\\delta)}$. If\n$M$ is finite, the Minkowski dimension, also called box-counting,\n can be defined by\n\\begin{eqnarray}\n d_M = \\lim_{\\delta \\rightarrow 0} {\\ln{N_B(\\delta)} \\over - \\ln{\\delta}}\n\\end{eqnarray}\n\nIn the case of the Cantor set, at iteration $n$, we have $2^n$ segments\nof size $3^{-n}$ ($\\delta = 3^{-n}$).  When $n  \\rightarrow  \\infty$, we have\n\\begin{eqnarray}\nd_M (Cantor) = {\\ln{2^n} \\over {- \\ln{3^{-n}}}}  = {\\ln{2} \\over \\ln{3}}\n\\end{eqnarray}\n\n\\section{Multifractality}\nThe multifractal picture is a refinement and\ngeneralization of the fractal properties\nthat arise naturally in the case of self-similar distributions.\nThe singularity spectrum $f(\\alpha)$ can be introduced as a quantity\nwhich characterizes the degree of regularity and homogeneity of a \nfractal measure.\n\n\\subsection{Definition}\n\\subsubsection*{H\\\"older exponent}\nA multifractal measure describes a non-homogeneous set $A$. \nSuch a measure is called multifractal if it is everywhere self-similar, i.e.\\\nif the measure varies locally as a power law, at any point of A. \nDenoting $\\mu$ a measure, we call the H\\\"older exponent or singularity exponent\nat $x_0$  the limit\n\\be\n\\alpha(x_0) =  \\lim_{\\delta \\rightarrow 0} { \\ln{\\mu(B_{x_0}(\\delta))} \n            \\over \\ln{\\delta} }\n\\ee\nwhere $B_{r_0}$ is a box centered at $r_0$ of size $\\delta$.\nWe have:\n\\be\n\\mu(B_{x_0}(\\delta)) \\propto \\delta^{\\alpha(x_0)}\n\\ee\nThe smaller the value $\\alpha(x_0)$, the less the measure is regular around\n$x_0$. For example, if $\\mu$ corresponds to a Dirac distribution centered \nat $0$, \nthen $\\alpha(0) = 0$, and if $\\mu$ corresponds to a Gaussian distribution, then\n$\\alpha(0) = -1$.\n\n\\subsubsection*{Singularity spectrum}\n\nThe singularity spectrum, associated with a measure $\\mu$, is the function\nwhich associates with $\\alpha$ the fractal dimension of \nany point $x_0$ such that\n$\\alpha(x_0) = \\alpha$:\n\\be\nf(\\alpha) = d_F(\\{ x_0 \\in A \\mid \\alpha(x_0) = \\alpha \\})\n\\ee\n The function $f(\\alpha)$ is usually (\\cite{frac:paladin86})\na single-humped\nfunction with the maximum at $max_{\\alpha} f(\\alpha) = D$, \nwhere $D$ is the dimension of the support. In the case\nof a single fractal, the function $f(\\alpha)$ is reduced to\na single point: $f(\\alpha) = \\alpha = D$.\n\nThe singularity spectrum describes statistically the $\\alpha$ exponent\ndistribution on the measure support. For example, if we split the\nsupport into boxes of size $\\delta$, then the number of boxes with a\nmeasure varying as $\\delta^\\alpha$ for a given $\\alpha$ is\n\\be\nN_\\alpha(\\delta) \\propto \\delta^{-f(\\alpha)}\n\\ee\n$f(\\alpha)$ describes the histogram of $N_\\alpha(\\delta)$ when\n$\\delta$ is small. A measure is homogeneous if its singularity spectrum\nis concentrated in a single point. If $f(\\alpha)$ is large, the\nmeasure is multifractal.\n\n\\subsubsection*{Multifractal quantities}\nFrom a practical point of view one does not determine directly the\nspectrum of exponents $[f(\\alpha), \\alpha]$; it is more convenient to\ncompute its Legendre transformation $[\\tau(q),q]$ given by\n\\be\n\\left\\{\n\\begin{array}{l}\n\\label{mf12}\nf(\\alpha) = q \\cdot \\alpha - \\tau(q)\\\\\n\\alpha    = \\frac{d\\tau(q)}{dq}\n\\end{array}\n\\right.\n\\ee\nIn the case of a simple fractal one has $\\alpha=f(\\alpha)=D$.  In\nterms of the Legendre transformation this corresponds to\n\\be\n\\tau(q) = D(q-1)\n\\ee\ni.e.\\ the behavior of $\\tau(q)$ versus $q$ is a straight line with\ncoefficient given by the fractal dimension.\n\n\n\\subsection{Generalized fractal dimension}\n\n\\subsubsection*{Definition}\nThe generalized fractal dimension, also called Reyni dimension of\norder $q$, is given by:\n\\be\nD_q = { \\tau(q) \\over q -1 }\n\\ee\n$D_0$ is also called capacity dimension, and coincides with the\nHausdorff dimension. Dimensions $D_1$, and $D_2$ are respectively \ncalled information and correlation dimension.\n \n\\subsubsection*{Partition function}\nThe partition function $Z$ is defined by:\n\\be\nZ(q,\\delta) = \\sum_{i=1}^{N(\\delta)} \\mu_i^q(\\delta)\n\\ee\nwhere we denote $\\mu_i(\\delta) = \\mu(B_i(\\delta))$.  If the measure\n$\\mu$ is multifractal, $Z$ follows a power law in the limit $\\delta\n\\rightarrow 0$.\n\\be\nZ(q,\\delta) \\propto \\delta^{\\tau(q)} \n% \\label{partition function}\n\\ee\n\nThe box-counting method consists of calculating the partition\nfunction, to derive from $Z$ $\\tau(q)$, and to obtain, the multifractal\nspectrum by a Legendre transform.\n\n\\section{Wavelets and Multifractality}\n\n\\subsection{Singularity analysis}\n\nLet $f(x)$ be the input signal, $x_0$ the singularity location,\n$\\alpha(x_0)$ the H\\\"older exponent at the singularity point $x_0$ and\n$n$ the degree of Taylor development such that\n$n\\leq\\alpha(x_0)<n+1$. We have\n\\be\nf(x) & = & f(x_0) + (x-x_0)\\,f^{(1)}(x_0) + ... +  \\\\ \\nonumber\n     &   & \\frac{(x-x_0)^n}{n!}\\,f^{(n)}(x_0) + C\\,|x-x_0|^{\\alpha(x_0)}\n\\ee\n\nLetting $\\psi$ be the wavelet with $n_\\psi>n$ vanishing moments, then we have\nfor the wavelet transform of $f(x)$ at $x_0$ when the scale goes to 0\n($\\psi$ is orthogonal to polynomials up to order $n$):\n\n\\be\n\\lim_{scale s \\rightarrow 0^+} T_\\psi[f](x_0,s) \\sim {a^{\\alpha(x_0)}}\n% \\label{Mallat Hwang}\n\\ee\n\nOne can prove that if $f$ is $C^\\infty$, then we have\n\n\\be\n\\lim_{scale s \\rightarrow 0^+} T_\\psi[f](x_0,s) \\sim {a^{n_\\psi}}\n\\ee\n\nThus, we have \n\\begin{eqnarray}\n\\left\\{  \\begin{array}{ll}\n \tT_\\psi[f] \\sim s^{n_\\psi} & \\mbox{ where the signal f is regular} \\\\\n\tT_\\psi[f] \\sim s^{\\alpha} (>>s^{n_\\psi}) & \\mbox{ around a singular zone}\n\t\\end{array}\n\t\\right.\n\\end{eqnarray} \n\nFor a fixed scale s, $T_\\psi[f](.,s)$ will be greater when the signal is\nsingular. This local maximum is organized in maxima lines (function of s) \nwhich\nconverges, when s goes to 0, to a singularity of the signal.\nMallat and Hwang (1992) demonstrate that to recover the H\\\"older exponent \n$\\alpha(x_0)$ at $x_0$, one need only study the  wavelet transform along these\nlines of maxima which converge (when the scale goes to 0) towards the singularity\npoint $x_0$.\n\nAlong this maxima line l we have\n\\be\nT_\\psi[f](b,s) \\sim a^{\\alpha(x_0)}, \\,\\,(b,a)\\in l, s\\rightarrow 0^+\n\\ee\nFigure~\\ref{fig_2} displays the function $f(x)=K(x-x_0)^{0.4}$ with a singular\npoint at $x_0$. The H\\\"older exponent at $x_0$ is equal to 0.4.\nIn Figure~\\ref{fig_3}, we display the wavelet transform of $f(x)$ with a wavelet\n$\\psi$ which is the first derivative of a Gaussian. In Figure~\\ref{fig_4}, we\ndisplay $log_2 {|T_\\psi[f](x,s)|}$ as a  function of $\\log_2(s)$. \n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=singul.ps,height=5cm,width=8cm}\n}}\n\\caption{Function $f(x)=K(x-x_0)^{0.4}$ \\cite{frac:arneodo90}.}\n\\label{fig_2}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=WT.ps,height=5cm,width=8cm}\n}}\n\\caption{\nWavelet transform of $f(x)$ with a wavelet $\\psi$ which is the first \nderivative of\na Gaussian. The small scales are at the top. The maxima line converges to the\nsingularity point at $x_0$.}\n\\label{fig_3}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=holder_expo.ps,height=5cm,width=8cm}\n}}\n\\caption{\nEstimation of the H\\\"older exponent $\\alpha(x_0)$ at \n$x_0$ by computing the slope of $\\log_2 {|T_\\psi[f](x,s)|}$ versus\n$\\log_2(s)$ along a maxima line which converges to $x_0$.}\n\\index{Mallat's multiresolution}\n\\label{fig_4}\n\\end{figure}\n\nWhen we compute the slope of the curve $log_2 {|T_\\psi[f](x,s)|}$\nversus $\\log_2(s)$ along a maxima line which converges at $x_0$, \nwe obtain an estimation of the H\\\"older exponent (in this case\n$\\alpha(x_0) \\approx 0.4$\nwhich corresponds to the theoretical value).\n\n\n\\subsection{Wavelet transform of multifractal signals }\n\nThe estimation of the H\\\"older exponent by this method \n becomes inaccurate\nin the case of multifractal signals \\cite{frac:arneodo90}. \nWe need to use a more global\nmethod. One can define the wavelet-based partition function by\n\n\\be\nZ(q,s) = \\sum_{b_i} |T_\\psi[\\mu](b_i,s)|^q\n\\ee\nwhere ${(b_i,s)}_i$ are all local maxima at scale $s$.\n\nLet $\\tau(q)$ be the scaling exponent. We can prove that we have\n\\be\nZ(q,s) \\sim a^{\\tau(q)}\n\\ee\n\nWe can then calculate the singularity spectrum $D(\\alpha)$ by its Legendre\ntransformation \n\\be\nD(\\alpha) = \\underset{q}{\\min} (q\\alpha-\\tau(q))\n\\ee\n \nThis method is called the {\\em Wavelet Transform Modulus Maxima} (WTMM).\n \n\n\\subsection{Numerical applications of WWTM method}\n\nThe calculation of the singularity spectrum of signal f proceeds as follows:\n\\begin{list}{--}{\\itemindent=-5mm \\itemsep=-1mm}\n\\item compute the wavelet transform and the modulus maxima $T_\\psi[f]$ for\nall $(s,q)$. We chain all maxima across scale\nlines of maxima\n\\item compute the partition \nfunction $Z(q,s) = \\sum_{b_i} |T_\\psi[f](b_i,s)|^q$\n\\item compute $\\tau(q)$ with \n$\\log_2{Z(q,s)}\\,\\approx\\,\\tau(q)\\log_2(s)+C(q)$\n\\item compute $D(\\alpha) = \\underset{q}{\\min}  (q\\alpha-\\tau(q))$\n\\end{list}\n\n\\subsubsection*{The triadic Cantor set}\n\nDefinition : The measure associated with the triadic Cantor set is defined by \n$f(x) = \\int_0^x d\\mu$ where $\\mu$ is the uniform measure lying on the triadic \nCantor set described in section \\ref{triadic Cantor set}. To compute $f(x)$, we used the next recursive\nfunction called the Devil's Staircase function \n(which looks like a staircase whose steps are\nuncountable and infinitely small, see Figure~\\ref{fig_5}). \n\n\\begin{eqnarray}\nf(x)=\t\\left\\{   \\begin{array}{ll}\n\tp_1f(3x)       & \\mbox{ if $x \\in [0,\\frac{1}{3}]$}\\\\\n\tp_1            & \\mbox{ if $x \\in [\\frac{1}{3}, \\frac{2}{3}]$ }\\\\\n\tp_1+p_2f(3x-2) & \\mbox{ if $x \\in [\\frac{2}{3}, 1]$}\n\t\\end{array}\n\t\\right.\n% \\label{recursive Cantor func}\n\\end{eqnarray}\n\nThis is a continuous function that increases  from 0 to 1 \non [0,1]. The recursive\nconstruction of $f(x)$ implies that $f(x)$ is self-similar.\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\t\\psfig{figure=DSC3.ps,height=5cm,width=8cm}\n    \\psfig{figure=DSC3ParFun.ps,height=5cm,width=8cm}\n}}\n\\caption{Classical Devil's Staircase function (associated with\ntriadic Cantor set) with $p_1=0.5$ and $p_2=0.5$\n(left) and partition function $Z(q,s)$ for several \nvalues of $q$ (right). The\nwavelet transform is calculated with $\\psi$ equal to the \nfirst derivative of a Gaussian.}\n\\label{fig_5}\n\\end{figure}\n\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\t\\psfig{figure=DSC3ScaExp.ps,height=5cm,width=8cm}\n    \\psfig{figure=DSC3SinSpe.ps,height=5cm,width=8cm}\n}}\n\\caption{Scaling Exponent estimation $\\tau(q)$ (left) and Singularity\nSpectrum $D(\\alpha)$ (right). The Scaling Exponent curve  corresponds\n to the theoretical curve\n$\\tau(q)=(q-1)\\log_2(2)/\\log_2(3)$. Points of the Singularity Spectrum\nwhere $q \\neq \\infty(\\max\\,q)$ and  $q \\neq-\\infty(\\min\\,q)$ are reduced \nto a single point\n($\\alpha=\\log_2(2)/\\log(3), D(\\alpha)=\\log _2(2)/\\log _2(3))$. This point\ncorresponds to\nthe Hausdorff dimension of the triadic Cantor Set.}\n\\label{fig_6}\n\\end{figure}\n\n\n\n\\subsubsection*{The generalized Devil's Staircase with $p_1=0.4$ and $p_2=0.6$}\n\nOne can prove \\cite{frac:arneodo90} that the theoretical singularity spectrum $D(\\alpha)$\nof the generalized Devil's Staircase function $f(x)=\\int_0^x{d\\mu}$ verifies\nthe following: \n\\begin{itemize}\n\\item The singular spectrum is a convex curve with a maximum value\n$\\alpha_{max}$ which corresponds to the fractal dimension of the\nsupport of the measure ($\\mu$). \n\\item The theoretical support of $D(\\alpha)$ is reduced at the interval\n$[\\alpha_{min},\\alpha_{max}]$:\n\n\\begin{eqnarray}\n\\left\\{ \\begin{array}{l}\n \\alpha_{min}=\\min({\\frac{\\ln p_1}{\\ln (1/3)}, \\frac{\\ln p_2}{\\ln (1/3)}})\\\\\n \\alpha_{min}=\\min({\\frac{\\ln p_1}{\\ln (1/3)}, \\frac{\\ln p_2}{\\ln (1/3)}})\n\t\\end{array}\n\t\\right.\n\\end{eqnarray}\n\\end{itemize}\n\nFigure~\\ref{fig_7} displays the generalized Devil's Staircase and its \npartition \nfunction $Z(q,s)$. In Figure~\\ref{fig_8}, we can see the Scaling exponent and\nthe Singularity spectrum. This one is in perfect ``accord'' with \nthe theoretical\nvalues: bell curve, $D(\\alpha)_{max}=\\log_2(2)/\\log_2(3)$,\n$\\alpha_{min}\\approx 0.47$ and $\\alpha_{max}\\approx 0.83$\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n    \\psfig{figure=DSC3b.ps,height=5cm,width=8cm}\n    \\psfig{figure=DSC3bParFun.ps,height=5cm,width=8cm}\n}}\n\\caption{Devil's Staircase function with $p_1=0.4$ and $p_2=0.6$\n(left) and partition function $Z(q,s)$ for several values of $q$ (right). \nThe wavelet transform is calculated\nwith $\\psi$ equal to the first derivative of a Gaussian.}\n\\label{fig_7} \n\\end{figure}\n\n\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\t\\psfig{figure=DSC3bScaExp.ps,height=5cm,width=8cm}\n    \\psfig{figure=DSC3bSinSpe.ps,height=5cm,width=8cm}\n}}\n\\caption{Scaling Exponent estimation $\\tau(q)$ (left) and Singularity\nSpectrum $D(\\alpha)$ (right). The theoretical maximum value of $D(\\alpha)$ is\nobtained for $\\alpha_{max D}=\\log_2(2)/\\log_2(3)$ and\n$D(\\alpha_{max D})=\\log_2(2)/\\log_2(3)$.}\n\\label{fig_8}\n\\end{figure}\n\n\n\\newpage\n\\section{Program}\n\\subsection{Devil's Staircase: mf1d\\_create\\_ds}\n\\index{mf1d\\_create\\_ds}\nProgram {\\em mf1d\\_create\\_ds} creates a Devil's Staircase function lying on the\nCantor sets measure. If the ``-b'' option is set, a border is added, which\nis equal to 0 on the left side, and to 1 on the right side. The size of the\nborder is ${N\\over 3}$ where $N$ is the number of points. Hence the output\nsignal size becomes $N + {2N\\over 3} = {5N\\over 3}$. It is recommended to\nchoose a number of points which can be divided by 3.\n\n{\\bf\n\\begin{center}\nUSAGE:  mf1d\\_create\\_ds options image out\n\\end{center}}\nwhere options are \n\\begin{itemize}\n\\item {\\bf [-n number\\_of\\_points]} \\\\\nNumber of points of Devil's Staircase. Default is 243.\n\\item {\\bf [-p Prob1]} \\\\\nCoefficient $p_1$ of the first interval of the Devil's Staircase. \n$p_2$ is equal to $1 - p_1$. \\\\\nDefault value is $0.5$. \n\\item {\\bf [-b]} \\\\\nAdd a border. Default is no.\n\\item {\\bf [-v]} \\\\\nVerbose. Default is False.\n\\end{itemize}\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item mf1d\\_create\\_ds NameOut \\\\\nCreate a Devil's Staircase  with all default values (243 points,\nprobabilities equal to $0.5$, ...).\n\\item mf1d\\_create\\_ds -p 0.4 NameOut \\\\\nDitto, but probabilities $p_1$ and $p_2$ are respectively equal to $0.4$ and\n$0.6$.\n\\end{itemize}\n\n\n\n\\subsection{Chain maxima wavelet coefficients: mf1d\\_chain}\n\\index{mf1d\\_chain}\n\nProgram {\\em mf1d\\_chain} calculates the wavelet transform of a signal,\nfinds its maxima wavelet coefficients, and chains them. Finally, chains which\ndo not respect some criteria are deleted. Two files are created: the first\ncontains the maxima, and the second the skeleton.\n{\\bf\n\\begin{center}\n USAGE:  mf1d\\_chain options  signal\\_in\n\\end{center}}\nwhere options are \n\\begin{itemize}\n\\item {\\bf [-t type\\_of\\_transform]} \\\\\n0: Gaussian derivative wavelet transform \\\\\n1: Mexican hat wavelet transform  \\\\\nDefault is 0.\n\\item {\\bf [-r min\\_length\\_chain]} \\\\\nRemove chains with length $<$ min\\_length. Default is 0.\n\\item {\\bf [-s  dynamique(\\%)]} \\\\\nRemove points of the skeleton map \nif level $<$ dynamique $*$ max(current scale). \\\\\nDefault is 0.\n% \\item {\\bf [-c]} \\\\\n% Draw chains of max. \\\\\n% Default is false.\n\\item {\\bf [-v]} \\\\\nVerbose\n\\end{itemize}\nWavelet transform file name is {\\bf WTMM\\_signal\\_in.fits}. \\\\\nSkeleton file name is {\\bf WTMMskel\\_signal\\_in.fits}.\n\\subsubsection*{Example:}\n\\begin{itemize}\n\\item mf1d\\_chain Data01.fits \\\\\n Create the files{\\bf WTMM\\_Data01.fits} and {\\bf WTMMskel\\_Data01.fits}.\n\\end{itemize}\n\n\\subsection{Partition function: mf1d\\_repart}\n\\index{mf1d\\_repart}\nProgram {\\em mf1d\\_repart} computes the partition function. It needs the two\noutput files of the {\\em mf1d\\_chain} program (i.e.\\ WTMMxxx.fits \nand WTMMskelxxx.fits), and creates three files:\n\\begin{itemize}\n\\item {\\bf q\\_FileNameOut.fits}: which contains the one-dimensional array $Q$ \nof the $q$ values for which the\npartition function is calculated.\n\\item {\\bf s\\_FileNameOut.fits}: which contains the one-dimensional array $S$\nof the $\\log_2 s$ values for which the\npartition function is calculated.\n\\item {\\bf Z\\_FileNameOut.fits}: which contains the partition functions. It\nis a two dimensional array. $Z(i,j)$ is the partition function value \n for $q = Q(i)$ and $s = S(j)$ ($i$ indexing the x-axis, and $j$ the y-axis).\n\\end{itemize}\n{\\bf\n\\begin{center}\nUSAGE: mf1d\\_repart options MaxFileName MaxSupFileName FileNameOut\n\\end{center}}\nwhere options are \n\\begin{itemize}\n\\item {\\bf [-a q\\_minq]} \\\\\nValue min of vector $q$. Default is -10.00.\n\\item {\\bf [-b q\\_max]} \\\\\nValue max of vector $q$. Default is +10.00.\n\\item {\\bf [-c number\\_of\\_q]} \\\\\nNumber of values of vector $q$. Default is 20.\n\\end{itemize}\n$Z(q,s)$ file name is {\\bf Z\\_FileNameOut.fits} \\\\\n$q$ file name is {\\bf q\\_FileNameOut.fits} \\\\\n$s$ file name is {\\bf s\\_FileNameOut.fits}. \\\\\n\\subsubsection*{Example:}\n\\begin{itemize}\n\\item mf1d\\_chain Data01.fits \\\\\n      mf1d\\_repart  WTMM\\_Data01.fits WTMMskel\\_Data01.fits Repart.fits  \\\\\n Create the files {\\bf Z\\_Data01.fits}, {\\bf q\\_Data01.fits}, and\n {\\bf s\\_Data0.fits}.\n\\end{itemize}\n\n\n\\subsection{Multifractal analysis: mf\\_analyse}\n\\index{mf\\_analyse}\nProgram {\\em mf\\_analyse} realizes the multifractal analysis. It\n computes the scaling\nexponent estimation $\\tau(q)$ and the singularity spectrum $\\alpha(q)$.\nIt needs the three files created by {\\em mf1d\\_repart}. Four files are \ncreated:\n\\begin{itemize}\n\\item {\\bf X\\_Tau.fits}: which contains the x-coordinates of the \n$\\tau(q)$ curve.\n\\item {\\bf Y\\_Tau.fits}: which contains the y-coordinates of the \n$\\tau(q)$ curve.\n\\item {\\bf X\\_FracSpectrum.fits}: which contains the x-coordinates of the \nsingularity spectrum curve (i.e. $\\alpha$ values).\n\\item {\\bf Y\\_FracSpectrum.fits}: which contains y-coordinates of the \nsingularity spectrum curve (i.e. $D(\\alpha)$ values).\n\\end{itemize}\n\n{\\bf \\begin{center}\n USAGE:  mf\\_analyse options FileNameIn\n\\end{center}}\nwhere options are \n\\begin{itemize}\n\\item {\\bf [-d $\\alpha_{min}$]} \\\\\nValue min of vector $\\alpha$. Default is 0.00.\n\\item {\\bf [-e $\\alpha_{max}$]} \\\\\nValue max of vector $\\alpha$. Default is 1.00.\n\\item {\\bf [-f number\\_of\\_$\\alpha$]} \\\\\nNumber of values of vector $\\alpha$. Default is 20.\n\\item {\\bf [-m ind\\_scale\\_min]} \\\\\nind scale min for computing $\\tau$. Default is 30. \n\\item {\\bf [-M ind\\_scale\\_max]} \\\\\nind scale max forn computing $\\tau$. Default is scale\\_max-2.\n\\end{itemize}\n$Z(q,s)$ are read in {\\bf Z\\_FileNameIn.fits} file \\\\\n$q$ are read in {\\bf q\\_FileNameIn.fits} file\\\\\n$s$ are read in {\\bf s\\_FileNameIn.fits} file .\n\\subsubsection*{Example:}\n\\begin{itemize}\n\\item mf1d\\_chain Data01.fits \\\\\n      mf1d\\_repart WTMM\\_Data01.fits WTMMskel\\_Data01.fits Repart  \\\\\n      mf\\_analyse  Repart \\\\\n  Create the files  {\\bf X\\_Tau.fits},{\\bf Y\\_Tau.fits},{\\bf X\\_FracSpectrum.fits},{\\bf Y\\_FracSpectrum.fits},\n  and {\\bf Y\\_TauTheo.fits}.\n\\end{itemize}\n\n\n\\subsection{Examples}\n\n\\subsubsection*{Fractal analysis of Devil's Staircase function}\nCreate Devil's Staircase function with $p_1=.6$ and $p_2=.4$.\n\\begin{verbatim}\nmf1d_create_ds  -p .4 -b DSC3\n\\end{verbatim}\nCompute the wavelet transform WTMM\\_DSC3.fits, the skeleton WTMMskel\\_DSC3.fits\n(default transform: $\\psi$ is the first derivative of a Gaussian).\n\\begin{verbatim}\nmf1d_chain DSC3\n\\end{verbatim}\nCompute the partition function $Z(q,s)$ for $q\\in[-10.,10.]$ with 60 values,\nwrite the $Z(q,s)$ to file Z\\_DSC3.fits, the $s$(scale) file to s\\_DSC3.fits and the\n$q$ file to q\\_DSC3.fits.\n\\begin{verbatim}\nmf1d_repart -c 60 WTMM_DSC3 WTMMskel_DSC3 DSC3\n\\end{verbatim}\nCompute the scaling exponent $\\tau(q)$, write it in X\\_Tau.fits and Y\\_Tau.fits,\ncompute the singularity spectrum $\\alpha(q)$, write it in X\\_FracSpectrum.fits\nand Y\\_FracSpectrum.fits (100 values are used for $\\alpha$).\n\\begin{verbatim}\nmf_analyse -f 100 DSC3\n\\end{verbatim}\n\n\\subsubsection*{Fractal analysis}\n\nCompute the wavelet transform WTMM\\_DSC3.fits, the skeleton WTMMskel\\_DSC3.fits\n(use the Mexican hat for $\\psi$)\n\\begin{verbatim}\nmf1d_chain -t 1 signal\n\\end{verbatim}\nCompute the partition function $Z(q,s)$ for $q\\in[-5.,5.]$ with 100 values,\nwrite the $Z(q,s)$ in file Z\\_signal.fits, the $s$(scale) file in s\\_signal and the\n$q$ file in q\\_signal.\n\\begin{verbatim}\nmf1d_repart -a -5. -b 5. -c 100 WTMM_signal WTMMskel_signal sigout\n\\end{verbatim}\nCompute the scaling exponent $\\tau(q)$, write it in X\\_Tau.fits and Y\\_Tau.fits,\ncompute the singularity spectrum $\\alpha(q)$, write it in X\\_FracSpectrum.fits\nand Y\\_FracSpectrum.fits ($\\alpha \\in [0,2]$, 100 values are used).\n\\begin{verbatim}\nmf_analyse -d 0. -e 2. -f 100 sigout\n\\end{verbatim}\n \n\n\n\n\n\n", "meta": {"hexsha": "4f3205d1d413e16e07a25d2117ffa23812553444", "size": 25068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr1/ch_fractal.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_fractal.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_fractal.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": 35.6079545455, "max_line_length": 110, "alphanum_fraction": 0.709230892, "num_tokens": 8086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.6998176880208329}}
{"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 8, 2014}\n\\maketitle\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\\begin{align*}\n  a_n&\\le b_n\\\\\n  0&\\le b_n-a_n\\\\\n  \\lim_{n\\to\\infty}0&\\le\\lim_{n\\to\\infty}(b_n-a_n)\\\\\n  0&\\le \\lim_{n\\to\\infty}b_n-\\lim_{n\\to\\infty}a_n\\\\\n  \\lim_{n\\to\\infty}a_n&\\le\\lim_{n\\to\\infty}b_n\n\\end{align*}\n\n\\section*{monotone sequences}\ndefinition:\n\na sequence is increasing iff $a_{n+1}\\ge a_n$ for every $n\\in\\mathbb{N}$ strictly increasing ...decreasing if $a_{n+1}\\ge a_n$ for every $n\\in\\mathbb{N}$, strictly decreasing.... monotone if is it any of these types\n\n\\section*{theorem 2.6.1}\nan increasing sequence that is bounded above is convergent. a decreasing sequence that is bounded below is convergent.\n\\subsection*{proof}\nwe are given $\\{a_n\\}_{n=1}^\\infty$, increasing $a_n\\le a_n+1\\forall n\\in\\mathbb{N}$ and bounded above. since it is bdd above it has a supremum $L$. we prove that $\\lim_{n\\to\\infty}a_n=L$.\n\\begin{align*}\n  L&=\\sup\\{a_n:n\\in\\mathbb{N}\\}\n\\end{align*}\n$L$ is the least upper bound. if $M<L$ M cannot be an upper bound.\n\nNeed: $\\lim_{n\\to\\infty}a_n=L$ ie $\\forall\\epsilon>0,\\exists N\\in\\mathbb{N}$ such that $|a_n-L|<\\epsilon\\forall n\\ge N$.\n\n$\\forall a_n,a_n\\le L$\n\n$\\forall \\epsilon>0\\exists N$\n$L-\\epsilon<a_N\\le L\\Rightarrow|a_N-L|<\\epsilon$. If $n\\ge N, L\\ge a_n\\ge a_N>L-\\epsilon$ because $\\{a_n\\}$ is increasing. hence $a_n-L|<\\epsilon, \\forall n\\ge N\\to\\lim_{n\\to\\infty}=L\\Box$\n\\section*{example}\nlet $0<x_1<1$ and define sequence $x_n$ recursively by $x_{n+1}=1-\\sqrt{1-x_n}$. prove that $\\{x_n\\}$ has a limit and find its value\n\nneed to show it's monotone and bounded\n\nif $0<x_n<1$ then $0<1-\\sqrt{1-x_n}<1$\n\n\\begin{align*}\n  \\sqrt{1-x_n}&=1-x_{n+1}\\\\\n  1-x_n&=(1-x_{n+1})^2\\\\\n  1-x_n&=(1-x_{n+1})^2\\le 1-x_{n+1}\\\\\n  x_{n+1}&\\le x_n\\\\\n\\end{align*}\n\nsequence is bounded and decreasing so it has a limit\n\n\\begin{align*}\n  x_{n+1}=1-\\sqrt{-x_{n}}\\\\\n  n\\to\\infty\\\\\n  L=1-\\sqrt{1-L}\\\\\n  \\sqrt{1-L}=1-L\\\\\n  1-L=1-2L+L^2\\\\\n  L^2-L=0\\\\\n  L=0\\text{ or }1\n\\end{align*}\nLimit is 0 since sequence is decreasing\n\n\\section*{example}\nlet $7x_{n+1}=x_n^3+6,n\\ge1$. study whether the limit eists and find it's value if it doest for $x_1=\\frac{1}{2},\\frac{3}{2},\\frac{5}{2}$\n\n\\begin{align*}\n  x_{n+1}=\\frac{x_n^3}{7}+\\frac{6}{7}\n\\end{align*}\nif $0<x_n^3\\le1$ then $0<x_{n+1}\\le1$\n\\begin{align*}\n  \\frac{x_n^3+6}{7}\\le\\ge x_n\\\\\n  x_n^3-7x_n+6=0=(x_n-1)(x_n^2+x_n-6)=(x_n-1)(x_n-2)(x_n-3)\n\\end{align*}\nlook at graph, between -3 and 1 equation is positive so $\\frac{x_n^3+6}{7}\\ge x_n$. between 1 and 2 $\\frac{x_n^3+6}{7}\\le x_n$ and above 2 $\\frac{x_n^3+6}{7}\\ge x_n$\n\nfor $x_1=1/2$ the sequence is increasing and bounded above by 1, for $x_1=3/2$ the sequence is decreasing. for $x_1=5/2$ the sequence is increaasing\n\\begin{align*}\n  x_1=1/2\\\\\n  7L=L^3+6\\\\\n  0=L^3+7L+6\\\\\n  L=-3,1,2\\\\\n  L=1\\text{ because it is bounded above by 1 and is increasing}\n\\end{align*}\n\nfor $x_1=3/2$. possibilities are 1,2,-3, it's between 1 and 2 so it will be 1. assume $1<x_n<2$\n\\begin{align*}\n  1<x_n^3<8\\\\\n  7<x_n^3+6<14\\\\\n  1<\\frac{x_n^3+6}{7}<2\n\\end{align*}\nso it's bounded therefore the limit exists and is one\n\nfor $x_1=5/2$ it is increasing and greater than 3 possible limits\n\\end{document}\n", "meta": {"hexsha": "141899e728460be7da29e1943746b7376eb7ad78", "size": 3464, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "real analysis/analysis-notes-2014-09-08.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-08.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-08.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.3076923077, "max_line_length": 215, "alphanum_fraction": 0.6651270208, "num_tokens": 1487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.9099069980980297, "lm_q1q2_score": 0.6997914994414005}}
{"text": "\\section{Task D}\n\\label{sec:task-d}\n\nThe \\textit{constitutive} component of the tangent matrix relating node \\(a\\) to\nnode \\(b\\) is\n\\begin{equation} \\tag{9.35}\n  \\label{eq:tang-mat-const}\n  \\left[ \\uubar{\\bm{K}}_{c,ab} \\right]_{ij} =\n  \\int_{v^{(e)}} \\sum_{k,l=1}^{3} \\frac{\\partial N_{a}}{\\partial x_{k}}\n  c_{ijkl} \\frac{\\partial N_{b}}{\\partial x_{l}} \\, dv, \\quad i,j = 1,2,3\n\\end{equation}\nThe 4th order elasticity tensor in \\textit{spatial} configuration can be computed\nby pushing forward its counterpart in the \\textit{material} configuration\n\\(\\partial \\utilde{S} / \\partial \\utilde{E}\\):\n\\begin{equation}\n  \\label{eq:elast-tensor-Euler}\n  \\uutilde{c} = J^{-1} \\utilde{F} \\overline{\\otimes} \\utilde{F} \\cdot\n  \\frac{\\partial \\utilde{S}}{\\partial \\utilde{E}} \\cdot\n    \\utilde{F}^{T} \\overline{\\otimes} \\utilde{F}^{T}\n\\end{equation}\n\nFor a CST element of thickness \\(t\\) equation \\eqref{eq:tang-mat-const} can be\nrewritten as\n\\begin{equation}\n  \\label{eq:tang-mat-const-CST}\n  \\uubar{\\bm{K}}_{c,ab} \\approx \\sum_{i=1}^{\\text{nip}} W_{i} \\ubar{\\nabla} N_{a}\n  \\cdot \\uubar{\\bm{D}} \\cdot \\ubar{\\nabla} N_{b} t \n  \\det \\left( \\frac{\\partial \\ubar{\\bm{x}}}{\\partial \\ubar{\\bm{\\xi}}} \\right),\n\\end{equation}\nwhere \\(\\uutilde{c}\\) was rearranged into matrix \\(\\uubar{\\bm{D}}\\) that\nfacilitates computations in the matrix form for 2D case:\n\\begin{equation}\n  \\label{eq:D-matrix}\n  \\uubar{\\bm{D}} = \\left[\n    \\begin{array}{c c c}\n      c_{1111} & c_{1122} & c_{1112} \\\\\n               & c_{2222} & c_{2212} \\\\\n      \\text{sym} &  & c_{1212}\n\t\\end{array} \\right] \n\\end{equation}\n\nThe components of the \\textit{initial stress} matrix are as follows:\n\\begin{equation} \\tag{9.44c}\n  \\label{eq:tang-mat-init}\n  \\left[ \\uubar{\\bm{K}}_{\\sigma,ab} \\right]_{ij} =\n  \\int_{v^{(e)}} \\sum_{k,l=1}^{3} \\frac{\\partial N_{a}}{\\partial x_{k}}\n  \\sigma_{kl} \\frac{\\partial N_{b}}{\\partial x_{l}} \\delta_{ij} \\, dv,\n  \\quad i,j = 1,2,3  \n\\end{equation}\nThen for a CST element this becomes\n\\begin{equation}\n  \\label{eq:tang-mat-init-CST}\n  \\uubar{\\bm{K}}_{\\sigma,ab} \\approx \\sum_{i=1}^{\\text{nip}} W_{i} \\ubar{\\nabla} N_{a}\n  \\cdot \\utilde{\\sigma} \\cdot \\ubar{\\nabla} N_{b} \\utilde{I} t \n  \\det \\left( \\frac{\\partial \\ubar{\\bm{x}}}{\\partial \\ubar{\\bm{\\xi}}} \\right)\n\\end{equation}\n\nThe total tangent matrix is then\n\\begin{equation}\n  \\label{eq:tang-mat}\n  \\uubar{\\bm{K}}_{ab} = \\uubar{\\bm{K}}_{c,ab} + \\uubar{\\bm{K}}_{\\sigma,ab}\n\\end{equation}\n\nThe Matlab implementation of this task can be found in \n\\texttt{get\\_tangent\\_matrices.m} (see section \\ref{app:matlab-code}).\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "e46f292e04f3e5d3eb455915e9fef32c71bf433f", "size": 2628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/task_d.tex", "max_stars_repo_name": "iamrosk/hyperelasticity", "max_stars_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-14T00:14:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T00:14:05.000Z", "max_issues_repo_path": "doc/sec/task_d.tex", "max_issues_repo_name": "iamrosk/hyperelasticity", "max_issues_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/sec/task_d.tex", "max_forks_repo_name": "iamrosk/hyperelasticity", "max_forks_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-14T03:19:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-14T03:19:55.000Z", "avg_line_length": 37.014084507, "max_line_length": 86, "alphanum_fraction": 0.6388888889, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6997914967369111}}
{"text": "\\subsection{Step 1}\nLet's start by rewriting our ADI equation for the Step 1 (given in class 13 slide 13), for an staggered mesh for the vertical velocity $v$:\n\\begin{align*}\n-d_1v_{i-1,j+1/2}^{n+1/2}+(1+2d_1)v_{i,j+1/2}^{n+1/2}-d_1v_{i+1,j+1/2}^{n+1/2}=d_2v_{i,j+3/2}^{n}+(1-2d_2)v_{i,j+1/2}^{n}+d_2v_{i,j-1/2}^{n},\n\\end{align*}\nwhich has the form \n\\begin{align*}\nav_{i-1,j+1/2}^{n}+bv_{i,j+1/2}^{n}+cv_{i+1,j+1/2}^{n}=d,\n\\end{align*}\na tridiagonal system. The staggered mesh for $v$ gives us a matrix $v$ that is $(M+2)\\times(N+1)$. We only need to solve the previous equation for the interior with two $for$ loops in \\textsl{Matlab},\n\\begin{verbatim}\nfor j=2:N\nfor i=2:M+1\n\t\t...\n\tend\nend\n\\end{verbatim}.\nWe will now include the boundary conditions for each case.\n\\subsubsection*{Case $j=2$ and $i=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{1,5/2}^{n+1/2}+(1+2d_1)v_{2,5/2}^{n+1/2}-d_1v_{3,5/2}^{n+1/2}=d_2v_{2,7/2}^{n}+(1-2d_2)v_{2,5/2}^{n}+d_2v_{2,3/2}^{n},\n\\end{align*}\nThe value $v_{1,5/2}^{n+1/2}=-v_{2,5/2}^{n+1/2}$ by the boundary conditions and $v_{2,3/2}^{n}=0$ since it corresponds to the bottom wall. Thus the equation yields\n\\begin{align*}\n(1+3d_1)v_{2,5/2}^{n+1/2}-d_1v_{3,5/2}^{n+1/2}=d_2v_{2,7/2}^{n}+(1-2d_2)v_{2,5/2}^{n},\n\\end{align*}\ngiving $a=0$ and $b=1+3d_1$ for this case, $d$ is given by the right hand side.\n\\subsubsection*{Case $j=2$ and $i\\in [3,M]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{i-1,5/2}^{n+1/2}+(1+2d_1)v_{i,5/2}^{n+1/2}-d_1v_{i+1,5/2}^{n+1/2}=d_2v_{i,7/2}^{n}+(1-2d_2)v_{i,5/2}^{n}+d_2v_{i,3/2}^{n},\n\\end{align*}\nLike in the previous case, the value $v_{i,3/2}^{n}=0$ and $d$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j=2$ and $i=M+1$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{M,5/2}^{n+1/2}+(1+2d_1)v_{M+1,5/2}^{n+1/2}-d_1v_{M+2,5/2}^{n+1/2}=d_2v_{M+1,7/2}^{n}+(1-2d_2)v_{M+1,5/2}^{n}+d_2v_{M+1,3/2}^{n},\n\\end{align*}\nLike in the previous case, the value $v_{M+1,3/2}^{n}=0$. The value of $v_{M+2,5/2}^{n+1/2}=-v_{M+1,5/2}^{n+1/2}$ and the previous equation yields\n\\begin{align*}\n-d_1v_{M,5/2}^{n+1/2}+(1+3d_1)v_{M+1,5/2}^{n+1/2}=d_2v_{M+1,7/2}^{n}+(1-2d_2)v_{M+1,5/2}^{n}.\n\\end{align*}\nThus, $c=0$, $b=1+3d_1$ and $d$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j\\in[3,N-1]$ and $i=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{1,j+1/2}^{n+1/2}+(1+2d_1)v_{2,j+1/2}^{n+1/2}-d_1v_{3,j+1/2}^{n+1/2}=d_2v_{2,j+3/2}^{n}+(1-2d_2)v_{2,j+1/2}^{n}+d_2v_{2,j-1/2}^{n}.\n\\end{align*}\nThe value $v_{1,j+1/2}^{n+1/2}=-v_{2,j+1/2}^{n+1/2}$ by the boundary condition. Thus the equation yields\n\\begin{align*}\n(1+3d_1)v_{2,j+1/2}^{n+1/2}-d_1v_{3,j+1/2}^{n+1/2}=d_2v_{2,j+3/2}^{n}+(1-2d_2)v_{2,j+1/2}^{n}+d_2v_{2,j-1/2}^{n},\n\\end{align*}\ngiving $a=0$, $b=1+3d_1$ and $d$ given by the right hand side.\n\n\\subsubsection*{Case $j\\in[3,N-1]$ and $i\\in[3,M]$}\nIn this case the general equation does not include any boundary conditions, therefore it is unaltered.\n\n\\subsubsection*{Case $j\\in[3,N-1]$ and $i=M+1$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{M,j+1/2}^{n+1/2}+(1+2d_1)v_{M+1,j+1/2}^{n+1/2}-d_1v_{M+2,j+1/2}^{n+1/2}=d_2v_{M+1,j+3/2}^{n}&+(1-2d_2)v_{M+1,j+1/2}^{n}\\\\&+d_2v_{M+1,j-1/2}^{n}.\n\\end{align*}\nThe value $v_{M+2,j+1/2}^{n+1/2}=-v_{M+1,j+1/2}^{n+1/2}$ by the boundary condition. Thus the equation yields\n\\begin{align*}\n-d_1v_{M,j+1/2}^{n+1/2}+(1+3d_1)v_{M+1,j+1/2}^{n+1/2}=d_2v_{M+1,j+3/2}^{n}+(1-2d_2)v_{M+1,j+1/2}^{n}+d_2v_{M+1,j-1/2}^{n},\n\\end{align*}\ngiving $c=0$, $b=1+3d_1$ and $d$ given by the right hand side.\n\n\\subsubsection*{Case $j=N$ and $i=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{1,N+1/2}^{n+1/2}+(1+2d_1)v_{2,N+1/2}^{n+1/2}-d_1v_{3,N+1/2}^{n+1/2}=d_2v_{2,N+3/2}^{n}+(1-2d_2)v_{2,N+1/2}^{n}+d_2v_{2,N-1/2}^{n},\n\\end{align*}\nThe value $v_{1,N+1/2}^{n+1/2}=-v_{2,N+1/2}^{n+1/2}$ by the boundary conditions and $v_{2,N+3/2}^{n}=0$ since it corresponds to the top wall. Thus the equation yields\n\\begin{align*}\n(1+3d_1)v_{2,N+1/2}^{n+1/2}-d_1v_{3,N+1/2}^{n+1/2}=(1-2d_2)v_{2,N+1/2}^{n}+d_2v_{2,N-1/2}^{n},\n\\end{align*}\ngiving $a=0$ and $b=1+3d_1$ for this case, $d$ is given by the right hand side.\n\n\\subsubsection*{Case $j=N$ and $i\\in [3,M]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{i-1,N+1/2}^{n+1/2}+(1+2d_1)v_{i,N+1/2}^{n+1/2}-d_1v_{i+1,N+1/2}^{n+1/2}=d_2v_{i,N+3/2}^{n}+(1-2d_2)v_{i,N+1/2}^{n}+d_2v_{i,N-1/2}^{n},\n\\end{align*}\nLike in the previous case, the value $v_{i,N+3/2}^{n}=0$ and $d$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j=N$ and $i=M+1$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1v_{M,N+1/2}^{n+1/2}+(1+2d_1)v_{M+1,N+1/2}^{n+1/2}-d_1v_{M+2,N+1/2}^{n+1/2}=d_2v_{M+1,N+3/2}^{n}&+(1-2d_2)v_{M+1,N+1/2}^{n}\\\\&+d_2v_{M+1,N-1/2}^{n}.\n\\end{align*}\nBy the boundary conditions, $v_{M+2,N+1/2}^{n+1/2}=-v_{M+1,N+1/2}^{n+1/2}$ and $v_{M+1,N+3/2}^{n}=0$ and the previous equation yields\n\\begin{align*}\n-d_1v_{M,N+1/2}^{n+1/2}+(1+3d_1)v_{M+1,N+1/2}^{n+1/2}=(1-2d_2)v_{M+1,N+1/2}^{n}+d_2v_{M+1,N-1/2}^{n},\n\\end{align*}\nThus, $c=0$, $b=1+3d_1$ and $d$ is the right hand side of the previous equation.\n\n\\subsection{Step 2}\nWe start by rewriting our ADI equation for the Step 1 (given in class 13 slide 14), for an staggered mesh for the vertical velocity $v$:\n\\begin{align*}\n-d_2v_{i,j-1/2}^{n+1}+(1+2d_2)v_{i,j+1/2}^{n+1}-d_2v_{i,j+3/2}^{n+1}=d_1v_{i+1,j+1/2}^{n+1/2}+(1-2d_1)v_{i,j+1/2}^{n+1/2}+d_1v_{i-1,j+1/2}^{n+1/2}\n\\end{align*}\nwhich has the form \n\\begin{align*}\nav_{i,j-1/2}^{n+1}+bv_{i,j+1/2}^{n+1}+cv_{i,j+3/2}^{n+1}=d,\n\\end{align*}\na tridiagonal system. The staggered mesh for $v$ gives vs a matrix $v$ that is $(M+2)\\times(N+1)$. We only need to solve the previous equation for the interior with two $for$ loops in \\textsl{Matlab},\n\\begin{verbatim}\nfor j=2:M+1\nfor i=2:N\n\t\t...\n\tend\nend\n\\end{verbatim}.\nWe will now include the boundary conditions for each case.\n\n\\subsubsection*{Case $i=2$ and $j=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{2,3/2}^{n+1}+(1+2d_2)v_{2,5/2}^{n+1}-d_2v_{2,7/2}^{n+1}=d_1v_{3,5/2}^{n+1/2}+(1-2d_1)v_{2,5/2}^{n+1/2}+d_1v_{1,5/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{2,3/2}^{n+1}=0$ and $v_{1,5/2}^{n+1/2}=-v_{2,5/2}^{n+1/2}$. Thus $a=0$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=2$ and $j\\in[3,N-1]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{2,j-1/2}^{n+1}+(1+2d_2)v_{2,j+1/2}^{n+1}-d_2v_{2,j+3/2}^{n+1}=d_1v_{3,j+1/2}^{n+1/2}+(1-2d_1)v_{2,j+1/2}^{n+1/2}+d_1v_{1,j+1/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{1,j+1/2}^{n+1/2}=-v_{2,j+1/2}^{n+1/2}$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=2$ and $j=N$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{2,N-1/2}^{n+1}+(1+2d_2)v_{2,N+1/2}^{n+1}-d_2v_{2,N+3/2}^{n+1}=d_1v_{3,N+1/2}^{n+1/2}+(1-2d_1)v_{2,N+1/2}^{n+1/2}+d_1v_{1,N+1/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{2,N+3/2}^{n+1}=0$ and $v_{1,N+1/2}^{n+1/2}=-v_{2,N+1/2}^{n+1/2}$. Thus $c=0$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i\\in[3,M]$ and $j=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{i,3/2}^{n+1}+(1+2d_2)v_{i,5/2}^{n+1}-d_2v_{i,7/2}^{n+1}=d_1v_{i+1,5/2}^{n+1/2}+(1-2d_1)v_{i,5/2}^{n+1/2}+d_1v_{i-1,5/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{i,3/2}^{n+1}$ will be zero at the walls and will depend on $v_{i,5/2}^{n+1}$ and $v_{i,7/2}^{n+1}$ for the points at the outlet. Thus, $a=0$ and the values of $b$ and $c$ depend on $i$, $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i\\in[3,M]$ and $j\\in[3,N-1]$}\nIn this case the general equation does not include any boundary conditions, therefore it is unaltered.\n\n\\subsubsection*{Case $i\\in[3,M]$ and $j=N$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{i,N-1/2}^{n+1}+(1+2d_2)v_{i,N+1/2}^{n+1}-d_2v_{i,N+3/2}^{n+1}=d_1v_{i+1,N+1/2}^{n+1/2}+(1-2d_1)v_{i,N+1/2}^{n+1/2}+d_1v_{i-1,N+1/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, the value of $v_{i,N+3/2}^{n+1}$ will depend on $i$. We will pass it to the right hand side and have\n\\begin{align*}\n-d_2v_{i,N-1/2}^{n+1}+(1+2d_2)v_{i,N+1/2}^{n+1}=d_1v_{i+1,N+1/2}^{n+1/2}+(1-2d_1)v_{i,N+1/2}^{n+1/2}+d_1v_{i-1,N+1/2}^{n+1/2}+d_2v_{i,N+3/2}^{n+1}.\n\\end{align*}\nThus, $c=0$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=M+1$ and $j=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{M+1,3/2}^{n+1}+(1+2d_2)v_{M+1,5/2}^{n+1}-d_2v_{M+1,7/2}^{n+1}=d_1v_{M+2,5/2}^{n+1/2}+(1-2d_1)v_{M+1,5/2}^{n+1/2}+d_1v_{M,5/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{M+1,3/2}^{n+1}=0$ and $v_{M+2,5/2}^{n+1/2}=-v_{M+1,5/2}^{n+1/2}$. Thus, $a=0$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=M+1$ and $j\\in[3,N-1]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{M+1,j-1/2}^{n+1}+(1+2d_2)v_{M+1,j+1/2}^{n+1}-d_2v_{M+1,j+3/2}^{n+1}=d_1v_{M+2,j+1/2}^{n+1/2}&+(1-2d_1)v_{M+1,j+1/2}^{n+1/2}\\\\&+d_1v_{M,j+1/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{M+2,j+1/2}^{n+1/2}=-v_{M+1,j+1/2}^{n+1/2}$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=M+1$ and $j=N$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2v_{M+1,N-1/2}^{n+1}+(1+2d_2)v_{M+1,N+1/2}^{n+1}-d_2v_{M+1,N+3/2}^{n+1}=d_1v_{M+2,N+1/2}^{n+1/2}&+(1-2d_1)v_{M+1,N+1/2}^{n+1/2}\\\\+d_1v_{M,N+1/2}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $v_{M+1,N+3/2}^{n+1}=0$ and $v_{M+2,N+1/2}^{n+1/2}=-v_{M+1,N+1/2}^{n+1/2}$. Thus, $c=0$ and $d$ is given by the right hand side.", "meta": {"hexsha": "462ffd1507d2510fe9af372e42d6a7fb51126d72", "size": 9653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/CFD/Homework_7/Latex/v_dev.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/CFD/Homework_7/Latex/v_dev.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/CFD/Homework_7/Latex/v_dev.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.3314917127, "max_line_length": 254, "alphanum_fraction": 0.6173210401, "num_tokens": 5181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6997914873422788}}
{"text": "\n\\subsection{Vertices and edges}\n\nA graph is a set of vertices \\(V\\), a set of edges E which are subset of pairs from V.\n\nundirected so each edge is a set\n\n\\subsubsection{Degree of a vertex}\n\nThe degree of a vertex is the number of edges connections to it.\n\n", "meta": {"hexsha": "922410b9ef535d9774609d91a48c37608d6042bc", "size": 258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/graph/01-01-vertices.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-01-vertices.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-01-vertices.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.5, "max_line_length": 86, "alphanum_fraction": 0.7441860465, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.699791486284205}}
{"text": "\\section{The wedge and smash product of pointed types}\n\n\\begin{defn}\nLet $A$ and $B$ be pointed types.\n\\begin{enumerate}\n\\item We define the \\define{wedge} $A\\vee B$ of $A$ and $B$ to be the pushout\n\\begin{equation*}\n\\begin{tikzcd}\n\\unit \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\nA \\arrow[r] & A\\vee B\n\\end{tikzcd}\n\\end{equation*}\n\\item We define the \\define{smash product} $A\\wedge B$ of $A$ and $B$ to be the cofiber of the cogap map of the square\n\\begin{equation*}\n\\begin{tikzcd}\n\\unit \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\nA \\arrow[r] & A\\times B\n\\end{tikzcd}\n\\end{equation*}\nThat is, the smash product is defined as the cofiber of the canonical map $A\\vee B\\to A\\times B$. \n\\end{enumerate}\n\\end{defn}\n\nFor any two pointed types $A$ and $B$, there is a pointed map\n\\begin{equation*}\n\\mathsf{pair}_\\ast : A \\to_\\ast (B\\to_\\ast A\\wedge B).\n\\end{equation*}\n\n\\begin{thm}\\label{thm:smash_adj}\nLet $A$, $B$, and $X$ be pointed types. Then the pointed map\n\\begin{equation*}\n(A\\wedge B \\to_\\ast X)\\to_\\ast (A \\to_\\ast (B\\to_\\ast X))\n\\end{equation*}\ngiven by $f\\mapsto f\\mathbin{\\circ_\\ast}\\mathsf{pair}_\\ast$ is an equivalence.\nMoreover, these equivalences are natural in $A$, $B$, and $X$ in the sense that...\n\\end{thm}\n\n\\begin{cor}\nFor any $m,n:\\N$ we have an equivalence\n\\begin{equation*}\n\\eqv{{\\sphere{m}}\\wedge{\\sphere{n}}}{\\sphere{m+n}}.\n\\end{equation*}\n\\end{cor}\n\n\\begin{proof}\nWe have\n\\begin{align*}\n({\\sphere{m}}\\wedge{\\sphere{n}}\\to_\\ast X) & \\eqvsym (\\sphere{m}\\to_\\ast (\\sphere{n}\\to_\\ast X)) \\\\\n& \\eqvsym \\loopspace[m]{\\loopspace[n]{X}} \\\\\n& \\eqvsym \\loopspace[m+n]{X} \\\\\n& \\eqvsym (\\sphere{m+n}\\to_\\ast X)\n\\end{align*}\nBy the naturality of the equivalences in \\cref{thm:smash_adj} it follows that the composite equivalence is given by precomposition by the pointed map \n\\begin{equation*}\n\\sphere{m}\\wedge\\sphere{n}\\to_\\ast \\sphere{m+n}\n\\end{equation*}\nthat corresponds to the identity map $\\sphere{m+n}\\to_\\ast \\sphere{m+n}$. Thus it follows by \\cref{ex:yoneda_ptd_types} that this pointed map is an equivalence.\n\\end{proof}\n\n\\begin{thm}\nGiven two pointed spaces, there is an equivalence\n\\begin{equation*}\n\\eqv{\\join{X}{Y}}{\\susp(X\\wedge Y)}.\n\\end{equation*}\n\\end{thm}\n\n\\begin{exercises}\n\\exercise \n\\begin{subexenum}\n\\item Show that $Y$ is equivalent to the mapping cone of $X\\to X\\vee Y$.\n\\item Show that the pushout of $X \\leftarrow X\\vee Y \\rightarrow Y$ is contractible.\n\\end{subexenum}\n\\exercise Let $A$ and $B$ be pointed types. Show that the square\n\\begin{equation*}\n\\begin{tikzcd}\nA+B \\arrow[r] \\arrow[d] & A\\times B \\arrow[d] \\\\\n1+1 \\arrow[r] & A\\wedge B\n\\end{tikzcd}\n\\end{equation*}\nis cocartesian.\n\\exercise 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, where all types, maps and homotopies are pointed, then so is\n\\begin{equation*}\n\\begin{tikzcd}\nS_1\\vee S_2 \\arrow[r] \\arrow[d] & Y_1\\vee Y_2 \\arrow[d] \\\\\nX_1 \\vee X_2 \\arrow[r] & Z_1\\vee Z_2. \n\\end{tikzcd}\n\\end{equation*}\n\\exercise 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 cocartesian square of pointed spaces, then the cofiber of $X\\vee Y\\to Z$ is equivalent to $\\susp(S)$.\n\\exercise Show that there is an equivalence\n\\begin{equation*}\n\\eqv{\\susp(X\\times Y)}{\\susp(X\\vee Y)\\vee \\susp(X\\wedge Y)}\n\\end{equation*}\n\\exercise Show that $\\susp(X\\vee Y)$ is a retract of $\\susp(X\\times Y)$. \n\\exercise Show that if $f:A\\to X$ is a constant of pointed spaces, then $\\eqv{M_f}{X\\vee \\susp(A)}$. \n\\exercise Show that the cofiber of the diagonal $\\delta:\\sphere{1}\\to \\sphere{1}\\times\\sphere{1}$ is equivalent to $\\sphere{2}\\vee\\sphere{2}$.\n\\exercise Show that $\\eqv{\\mathsf{Fin}(n+1)\\wedge \\mathsf{Fin}(m+1)}{\\mathsf{Fin}(n\\cdot m)+\\unit}$.\n\\end{exercises}\n", "meta": {"hexsha": "855d8c93c6979dede497b9ec0e0e7ee3b15f9796", "size": 3888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/smash.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/smash.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/smash.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": 34.7142857143, "max_line_length": 160, "alphanum_fraction": 0.6856995885, "num_tokens": 1484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6997709670422373}}
{"text": "\\subsection{Lipschitz continuity}\\label{subsec:lipschitz_continuity}\n\n\\begin{definition}\\label{def:lipschitz_continuity}\n  Let \\( f: X \\to Y \\) be a function between metric spaces.\n\n  \\begin{thmenum}\n    \\thmitem{def:lipschitz_continuity/holder} We say that \\( f: X \\to Y \\) is \\term{H\\\"older continuous} at \\( x \\in X \\) with constant \\( L \\geq 0 \\) and exponent \\( \\alpha > 0 \\) if\n    \\begin{equation*}\n      \\rho_Y(f(x_1), f(x_2)) \\leq L \\rho_X(x_1, x_2)^\\alpha \\quad\\forall x_1, x_2 \\in X.\n    \\end{equation*}\n\n    We refer to the smallest such constant, if any, as \\enquote{the} H\\\"older constant.\n\n    \\thmitem{def:lipschitz_continuity/locally_holder} We say that \\( f \\) is \\term{locally H\\\"older continuous} if every point has a neighborhood where \\( f \\) is H\\\"older continuous with the same exponent, but possibly with with a different constant.\n\n    \\thmitem{def:lipschitz_continuity/lipschitz} If \\( \\alpha = 1 \\), we say that \\( f \\) is \\term{Lipschitz continuous}.\n\n    \\thmitem{def:lipschitz_continuity/contraction} If \\( X = Y \\) and if \\( f \\) is Lipschitz with constant \\( L < 1 \\), we call \\( f \\) a \\term{contraction mapping}.\n\n    \\thmitem{def:lipschitz_continuity/calm}\\cite[53]{DontchevRockafellar2014} We say that \\( f \\) is \\term{calm} at \\( x \\) if it satisfies the Lipschitz condition with one of the points fixed:\n    \\begin{equation*}\n      \\rho_Y(f(x), f(x')) \\leq L \\rho_X(x, x') \\quad\\forall x' \\in X.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:holder_map_is_uniformly_continuous}\n  A H\\\"older map is uniformly continuous.\n\\end{proposition}\n\\begin{proof}\n  Let \\( f: X \\to Y \\) be a H\\\"older map with constant \\( L \\) and exponent \\( \\alpha \\).\n\n  Fix \\( \\varepsilon > 0 \\). Then is enough to choose \\( \\delta < \\sqrt[\\alpha]{\\frac \\varepsilon L} \\), so that\n  \\begin{equation*}\n    \\rho_X(x_1, x_2) < \\delta \\implies \\rho_Y(f(x_1), f(x_2)) \\leq L \\rho_X(x_1, x_2)^\\alpha < L \\delta^\\alpha < \\varepsilon.\n  \\end{equation*}\n\n  This implies uniform continuity.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:locally_holder_map_is_continuous}\n  A locally H\\\"older map is continuous.\n\\end{corollary}\n\n\\begin{theorem}[Banach's fixed point theorem]\\label{thm:banach_fixed_point_theorem}\\mcite[exer. 4.3.J]{Engelking1989}\n  A contraction \\hyperref[def:lipschitz_continuity/contraction]{mapping} in a \\hyperref[def:complete_metric_space]{complete metric space} has a unique fixed \\hyperref[def:fixed_point]{point}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( f: X \\to X \\) be a contraction mapping. Fix any point \\( x_0 \\in X \\) and inductively define the sequence\n  \\begin{equation*}\n    x_{k+1} \\coloneqq f(x_k), k = 1, 2, \\ldots\n  \\end{equation*}\n\n  Fix \\( \\varepsilon > 0 \\). Since \\( L < 1 \\), there exists an index \\( k_0 > \\log_L(\\varepsilon) \\) such that for positive integers \\( m \\) and \\( k > k_0 \\),\n  \\begin{balign*}\n    \\rho(x_k, x_{k+m})\n     & =\n    \\rho(f^k(x_0), f^{k+m}(x_0))\n    \\leq \\\\ &\\leq\n    L^k \\rho(x_0, x_m)\n    <    \\\\ &<\n    \\varepsilon \\rho(x_0, x_m).\n  \\end{balign*}\n\n  Note that\n  \\begin{balign*}\n    \\rho(x_0, x_m)\n     & \\leq\n    \\sum_{i=1}^m \\rho(x_{i-1}, x_i)\n    \\leq    \\\\ &\\leq\n    \\rho(x_0, x_1) \\sum_{i=1}^m L^{i-1}\n    =       \\\\ &=\n    \\rho(x_0, x_1) \\frac {1 - L^m} {1 - L}\n    \\leq    \\\\ &\\leq\n    \\rho(x_0, x_1) \\frac 1 {1 - L}.\n  \\end{balign*}\n\n  Thus,\n  \\begin{equation*}\n    \\rho(x_k, x_{k+m}) < \\frac {\\varepsilon \\rho(x_0, x_1)} {1 - L}.\n  \\end{equation*}\n\n  The constant on the right is linear in \\( \\varepsilon \\) and does not depend on \\( k \\) or \\( m \\), hence \\( \\{ x_k \\}_{k=0}^\\infty \\) is a fundamental sequence. Since \\( X \\) is complete, the sequence has a limit \\( x \\).\n\n  Because of the continuity of \\( f \\) (see \\fullref{thm:holder_map_is_uniformly_continuous}),\n  \\begin{equation*}\n    f(x) = f(\\lim_{k \\to \\infty} x_k) = \\lim_{k \\to \\infty} f(x_k) = \\lim_{k \\to \\infty} x_{k+1} = x.\n  \\end{equation*}\n\\end{proof}\n", "meta": {"hexsha": "bc41efb40df7cd897aa067894854b4f4011d4ab6", "size": 3935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lipschitz_continuity.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/lipschitz_continuity.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/lipschitz_continuity.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": 43.7222222222, "max_line_length": 251, "alphanum_fraction": 0.6401524778, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.6997709651705798}}
{"text": "\\subsection{Particle Swarm Optimization (PSO)}\nPSO is an algorithm that simulates the sociological behavior of bird flocking. In the search space, we define a swarm $X$, which has many particles $x^p(t) \\in \\{x^1(t), x^2(t), \\ldots, \\gamma\\}$ where $\\gamma$ is a number of particles and $t$ is the $t$th iteration among $T$ total iterations. Each particle $x^p$ consists of many elements, $x^p_i$ where $i = 1,2,3, \\ldots, \\kappa$, with $\\kappa$ is the dimension of a particle.\n\nFirstly, the particles of the swarm are initialized and evaluated by a predefined fitness function. The objective of the PSO is to minimize these fitness function values. In order to move the particle in the search space, a velocity $v^p_j(t)$ is defined. It is the flight speed of the $j$th element of the $p$th particle at the $t$th iteration. Additionally, $x^p_j(t)$ is the current position of that element. The velocity and current position is then calculated by the following formulae:\n\\begin{equation}\nv_{j}^{p}(t) = 2 \\cdot rand() \\cdot (pbest_{j}^{p} - x_{j}^{p}(t-1))\n+ 2 \\cdot rand() \\cdot (gbest_{j} - x_{j}^{p}(t-1))\n\\end{equation}\n\n\\begin{equation}\nx^p_j(t) = x^p_j(t - 1) + v^p_j(t)\n\\end{equation}\n\nAnother improved version of PSO which is introduced in \\cite{eberhart2000comparing}, added two factors: the constriction and inertia which change the velocity calculation to:\n\n\\begin{equation}\nv_{j}^{p}(t) = k \\cdot \\{w \\cdot v^p_j(t-1) + \\varphi_1 \\cdot rand() \\cdot (pbest_{j}^{p} - x_{j}^{p}(t-1))\n+ \\varphi_2 \\cdot rand() \\cdot (gbest_{j} - x_{j}^{p}(t-1)) \\}\n\\end{equation}\n\nwhere $k$ is the constriction factor and $w$ is the inertia factor, $\\varphi_1$ and $\\varphi_2$ are constants.\n\nEven with the improved version of PSO, when the particle coincides with the global best position, the particle will move away from this point if the two factors above are different from zero. Furthermore, the particles will stop moving when their velocities are close to zero and they catch up with the global best position. This phenomena is called $stagination$ \\cite{eberhart1998comparison}. To overcome this phenomena, the mutation process of GA has been added to PSO to form up a Hybrid PSO with Mutation (HPSOM). We will discuss this mutation process among with the Wavelet Mutation in the next section.\n\n\\subsection{Hybrid PSO with Wavelet Mutation}\nThe initial version of PSO with mutation process works as follows: a random particle is selected to be moved to another position in the search space by using mutation under the following operation:\n\\begin{equation}\nmut(x_j) = x_j - \\omega, r < 0\n\\end{equation}\n\\begin{equation}\nmut(x_j) = x_j + \\omega, r \\geq 0\n\\end{equation}\nwhere $x_j$ is a randomly chosen element of the particle above, $\\omega$ is randomly generated in the range of $[0, 0.1 x (para^j_{max} - para^j_{min})]$, $r$ is a random number between +1 and -1, $para^j_{max}$ and $para^j_{min}$ are the upper and lower bounds of each particle element. Therefore, we can see that $\\omega$ represents $1/10$ of the search space.\n\nThis version of PSO can overcome the $stagination$ phenomena. However, it can easily be seen that the mutating space is fixed by $\\omega$. It is not always the best strategy for using the same size mutation space all the time. Therefore, in \\cite{ling2008hybrid}, the author proposed an improvement method to dynamically adjust the mutating size $\\omega$ based on the wavelet theory as follows.\n\n\\subsubsection{Hybrid PSO with Wavelet Mutation}\n\\\nEach particle element has a chance to mutate which is controlled by a probability of mutation $p_m \\in [0, 1]$. For each element, we generate a random number between 0 and 1 $r$, if $r \\leq p_m$, the mutation will take place on that element. In details, let $x^p(t) = [x^p_1(t), x^p_2(t), \\ldots, x^p_k(t)]$ be the current selected particle, with $x^p_j(t)$ is its randomly chosen element, $x^p_j(t) \\in [param^j_{min}, param^j_{min}]$. After the mutation process, the resulting particle is $\\bar{x}^p(t)$\n\n\\[ \\bar{x}^p(t) = \\left\\{ \\begin{array}{ll}\n         x^p_j(t) + \\sigma \\times (para^j_{max} - x^p_j(t)) & \\mbox{if $\\sigma > 0$} \\\\\n        x^p_j(t) + \\sigma \\times (x^p_j(t) - para^j_{min}) & \\mbox{if $\\sigma \\leq 0$}.\\end{array} \\right. \\] \n\nwhere $j \\in 1,2,3, \\ldots k$ is the dimension of the particle and:\n\\begin{equation}\n\t\\sigma = \\frac{1}{\\sqrt{a}}\\psi(\\frac{\\varphi}{a})\n\\end{equation}\n\nwhere $\\psi(x)$ is a wavelet - a continuous time function (see Figure \\ref{fig:fig1}) represents a certain seismic signal that satisfies two properties:\n\n\\begin{equation}\n\t\\int_{-\\infty}^{+\\infty}\\psi(x)dx = 0\n\\end{equation}\n\nand\n\n\\begin{equation}\n\t\\int_{-\\infty}^{+\\infty}|\\psi(x)|^2dx < 0\n\\end{equation}\n\n\\begin{figure} [H]\n\\centering\n\\includegraphics[width=60.72mm]{resources/morlet1}\n\\caption{The original form of the Morlet wavelet}\\label{fig:fig1}\n\\end{figure}\n\nIn this paper, we adapt this approach (HPSOWM) and transform the real-valued particles into binary-based ones. This will be discussed in the next section.", "meta": {"hexsha": "4260245e5083f7c7f548ae911d0aaae392be641b", "size": 5006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/chapters/p5.tex", "max_stars_repo_name": "minhprg/binary-hpsowm", "max_stars_repo_head_hexsha": "c40a7c3575b9560205252b501b3a9b506a715260", "max_stars_repo_licenses": ["MIT"], "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/p5.tex", "max_issues_repo_name": "minhprg/binary-hpsowm", "max_issues_repo_head_hexsha": "c40a7c3575b9560205252b501b3a9b506a715260", "max_issues_repo_licenses": ["MIT"], "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/p5.tex", "max_forks_repo_name": "minhprg/binary-hpsowm", "max_forks_repo_head_hexsha": "c40a7c3575b9560205252b501b3a9b506a715260", "max_forks_repo_licenses": ["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.6176470588, "max_line_length": 609, "alphanum_fraction": 0.7231322413, "num_tokens": 1520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.6997607031784402}}
{"text": "\\chapter{Principal Components Analysis \\label{chapter:pca}}\n\nClustering (Chapter~\\ref{chapter:clustering}) is one approach to uncovering latent structure in data. Another are matrix decomposition methods, the most famous of which is \\textbf{principal components analysis (PCA)}. PCA is a powerful statistical tool for analyzing and visualizing datasets. It has been independently discovered several times over the course of history, and can be formulated mathematically a few different ways.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Principal Components: What are they?}\n\nYou can think of PCA as a rotation of the feature space onto a set of axes that most efficiently represent the data. The \\textbf{principal components} are these axes, or \\textbf{basis vectors}. Here are pictures of the first two principal components for a small dataset. These were borrowed from Andrew Ng's lecture notes for CS229 at Stanford University. \n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/l04-ang-pc1.png}\n\\includegraphics[width=0.7\\textwidth]{img/l04-ang-pc2.png}\n\\end{center}\n\n\\begin{question}{}\nWhat do you notice about principal components 1 (top) and 2 (bottom)? Think in terms of (a) the variance (spread) of the data, and (b) the projection errors (dotted lines). \n\\end{question}\n\nMathematically, PCA is a linear projection of $p$-dimensional datapoints, $x^{(1)}, \\dots, x^{(n)}$ onto a $k$-dimensional space ($k \\leq p$) defined by basis vectors $u_1, \\dots, u_k$ such that:\n\\begin{itemize}\n\\item the projection maximizes the variance from the original dataset that is retained\n\\item the projection minimizes projection error (square loss)\n\\item the basis vectors, $\\left\\{u_1, \\dots, u_k\\right\\}$, are orthogonal (i.e., perpendicular)\n\\end{itemize}\n\nThe number of distinct principal components is the smaller of the number of original variables ($p$) or the number of observations ($n$) minus one.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Definitions}\n\n\\subsection{Feature Vectors}\n\nSay you have $n$ samples in a dataset, and each has dimensionality $p$. Let $x^{(i)}$ be the vector of $p$ features for the $i$th person. We write\n\n$$ x^{(i)} = \\begin{bmatrix}\n           x_{1}^{(i)} \\\\\n           x_{2}^{(i)} \\\\\n           \\vdots \\\\\n           x_{p}^{(i)}\n         \\end{bmatrix} $$\n        \n\\noindent and we can write our entire dataset as a $n \\times p$ matrix like this:\n\n$$ X = \\begin{bmatrix}\nx_1^{(1)} & x_2^{(1)} & \\dots & x_p^{(1)} \\\\\nx_1^{(2)} & x_2^{(2)} & \\dots & x_p^{(2)} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nx_1^{(n)} & x_2^{(n)} & \\dots & x_p^{(n)} \\\\\n\\end{bmatrix} $$ \nsuch that the $i$th row of the matrix is the vector of features for the $i$th person. This is exactly the same notation that we have used in previous chapters.  \n\n\\subsection{Variance and Covariance \\label{ssect:varcovar}}\n\nThe \\textbf{sample covariance} of two features $x_j$ and $x_k$ is given by\n$$ \\text{cov}(x_j, x_k) = S_{jk} = \\frac{1}{n-1} \\sum_{i=1}^{n}\\left(x_j^{(i)}-\\overline{x_j}\\right) \\left(x_k^{(i)}-\\overline{x_k}\\right) $$\nwhere the bar ($\\overline{x_j}$) refers to the mean of $x_j$ across the entire dataset. We can also write it in matrix format as\n$$ S = \\frac{1}{n-1} \\sum_{i=1}^n (x^{(i)} - \\overline{x})(x^{(i)} - \\overline{x})^T. $$\n\nThe covariance can be any real number between positive and negative infinity. One weird thing about it is that it has units - the product of the units of the two features. This means that the covariance depends on the scale that is chosen for each feature, which is somewhat arbitrary. The \\textbf{sample variance} of a given feature is just the covariance in cases where $j = k$ (the covariance of a feature with itself). \n\nThe \\textbf{correlation} (technically the \\textbf{Pearson correlation}) is a unitless, normalized version of the covariance and has the form\n$$ \\text{cor}(x_j, x_k)=\\frac{\\sum_{i=1}^{n}(x_j^{(i)}-\\overline{x_j})(x_k^{(i)}-\\overline{x_k})}{\\sqrt{\\sum_{i=1}^{n}(x_j^{(i)}-\\overline{x_j})^2}{\\sqrt{\\sum_{i=1}^{n}(x_k^{(i)}-\\overline{x_k})^2}}}. $$\n\n\\subsection{Orthogonality}\n\nTwo vectors are \\textbf{orthogonal} if their \\textbf{inner product}, or \\textbf{dot product}, is zero. This is defined as\n$$ \\langle x, y \\rangle = x \\cdot y = \\sum_{i=1}^n x_i y_i $$\nwhere the sum is over the vector components. If this mathematical notation makes you uncomfortable, just think of ``orthogonality'' as ``perpendicularity'' and you'll be able to understand it visually. \n\nIn PCA, the vectors whose inner products we are concerned with will \\emph{not} be the feature vectors for individual samples. They will be, instead, the \\emph{columns} of $X$ -- the values of a single feature for all $n$ samples. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Example: Running PCA in R}\n\nLet's say you have measurements of weight, height, and IQ ($p=3$) for $n=100$ men. Here are the first $10$ rows of the $100$ row dataset:\n\n\\begin{center}\n\\begin{tabular}{cccc}\nPatient ID ($i$) & Height (in) & Weight (lbs) & IQ \\\\\n\\midrule\n1 & 74.9 & 155.6 & 109 \\\\\n2 & 66.5 & 171.6 & 117 \\\\\n3 & 74.4 & 175.2 & 91 \\\\\n4 & 65.8 & 151.3 & 84 \\\\\n5 & 70.2 & 162.7 & 107 \\\\\n6 & 78.8 & 206.4 & 117 \\\\\n7 & 69.1 & 162.7 & 96 \\\\\n8 & 70.6 & 150.3 & 110 \\\\\n9 & 65.2 & 156.2 & 121 \\\\\n10 & 66.8 & 153.3 & 93 \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Here are some scatterplots showing pairwise comparisons of the three features:\n\n\\begin{center}\n\\includegraphics[width=0.32\\textwidth]{img/l04-example-1.png}\n\\includegraphics[width=0.32\\textwidth]{img/l04-example-2.png}\n\\includegraphics[width=0.32\\textwidth]{img/l04-example-3.png}\n\\end{center}\n\n\\noindent The \\textbf{correlation matrix} for these data looks like this:\n\n\\begin{verbatim}\n       height weight     iq\nheight  1.000  0.790 -0.103\nweight  0.790  1.000 -0.078\niq     -0.103 -0.078  1.000\n\\end{verbatim}\n\n\\vspace{2mm}\n\n\\begin{question}{}\nLooking at the correlation matrix, which features are most tightly correlated? What does this imply about the direction of the first principal component, PC1? \n\\end{question}\n\n\\subsection{Centering and Scaling}\n\nPCA is sensitive to the relative scales of the different variables in the original dataset. For this reason, datasets are usually \\emph{scaled} and \\emph{centered} before PCA is performed. All this means is that for each column (feature) of the dataset, we subtract its mean and divide by its standard deviation. The transformed column will have mean 0 and standard deviation 1. \n\nIf the data are scaled and centered, we can rewrite $S$ (the sample covariance matrix from Section~\\ref{ssect:varcovar}) as $X^T X/(n-1)$.\n\n\\vspace{2mm}\n\n\\begin{question}{}\nWhat would happen to the principal components if you didn't center and scale the data?\n\\end{question}\n\n\\begin{question}{}\nWhy do you think the interpretation of the principal components becomes more difficult if you have features measured on lots of different scales (e.g., some categorical, some numeric/roughly normal, some numeric/highly skewed)? \n\\end{question}\n\n\\subsection{Input and Output}\n\nIn R, we can run PCA on our dataset, \\texttt{d}, using the following command:\n\\begin{center}\n\\verb|p <- prcomp(d[,2:4], center = TRUE, scale. = TRUE, rank. = 3)|\n\\end{center}\nwhere \\texttt{rank.} is an optional parameter indicating the number, $k$, of principal components desired. The output looks like this:\n\n\\begin{multicols}{2}\n{\\scriptsize\n\\begin{verbatim}\n> p$sdev\n[1] 1.3454074 0.9899765 0.4580672\n\n> p$rotation\n              PC1         PC2         PC3\nheight  0.6996236 -0.09446119 -0.70823998\nweight  0.6971414 -0.12698944  0.70559726\niq     -0.1565906 -0.98739595 -0.02299201\n\n> p$center\n   height    weight        iq \n 70.74468 174.43346 101.12000 \n \n> p$scale\n   height    weight        iq \n 3.914989 13.853272 14.183701 \n \n> p$x\n                PC1          PC2          PC3\n  [1,] -0.189268854  1.976180297 -0.416704298\n  [2,]  1.794925031  0.710160037  0.575478783\n  [3,] -0.404617344  0.283418147  0.151536071\n  [4,] -0.471675025 -0.710146894  0.347006397\n  [5,] -1.073877096 -0.234684815 -0.638243675\n  [6,] -0.654663317  0.043481120 -0.107082277\n  [7,] -1.705841441  0.368990046 -0.794047654\n  [8,]  2.311353981 -0.501565781  0.033112309\n  [9,] -0.006387264 -0.535422493 -1.126177513\n [10,] -1.557136911  1.399023167 -0.045281059\n [11,]  2.632974868 -1.046037442 -0.239934797\n [12,] -0.978337630 -0.193476727  0.007814938\n [13,] -0.625980903 -0.456274882 -0.305349616\n (continued)\n\\end{verbatim}\n}\n\\end{multicols}\n\n\\begin{question}{}\nDescribe/draw the directions of the three principal component vectors, PC1, PC2, and PC3, in the coordinate system of the original predictors, height, weight, and IQ.\n\\end{question}\n\n\\begin{question}{}\nHere is a picture of the flow cytometry dataset we first encountered in Chapter~\\ref{chapter:clustering}.\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/biomarker-data-big-no-labels.png}\n\\end{center}\nWhat would PC1 and PC2 look like for this dataset? (Why is there no PC3?) How could PCA help you separate the two clusters?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Applications of PCA}\n\n\\subsection{Eigenfaces}\n\nEigenfaces were an early application of PCA to computer vision, specifically image search and retrieval. Here's what you do to create a set of eigenfaces:\n\\begin{enumerate}\n\\item Prepare training set of images taken under the same lighting conditions, with mouths and eyes aligned, resampled to a common pixel resolution.\n\\item Generate a vector for each image by concatenating the pixel intensities across the rows. So if the image is of dimension $r \\times c$, the image vector will have $p = rc$ features.\n\\item Create the data matrix from the $n$ vectors.\n\\item Center the data (Why wouldn't we scale the data?).\n\\item Calculate the eigenvectors and eigenvalues of the sample covariance matrix. Each eigenvector corresponds to one eigenface. \n\\end{enumerate}\n\nSome real eigenfaces are shown below \\footnote{Figure details: (top) some of the original faces from the training set (there were 86 images total); (bottom) the eigenfaces corresponding to the 18 largest eigenvalues of the covariance matrix. From https://www.clear.rice.edu/elec301/Projects99/faces/images.html.}. \n\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{img/l04-eigenfaces-1.png}\\\\[5mm]\n\\includegraphics[width=0.8\\textwidth]{img/l04-eigenfaces-2.png}\n\\end{center}\n\n\\begin{question}{}\nWhat is $X$ for the eigenfaces problem? What are the principal components? How could you use the principal components to match a new face to an existing database of faces?\n\\end{question}\n\n\\subsection{Image Compression}\n\nPCA can also be used for image compression. In that case, the raw pixels for the image are the data matrix, $X$ (so each ``sample'' is one row of the image and each ``feature'' is one column of the image). Generally the data are centered but not scaled here (Why?). A subset of the principal components corresponding to the $r$ largest eigenvalues are used to reconstruct the image. The picture below illustrates the process\\footnote{Figure: Using PCA for image compression. The image is recomposed by adding together many gridlike images like that shown in (a). From \\texttt{https://www.projectrhea.org/rhea/index.php/PCA\\_Theory\\_Examples}.}. \n\n\\begin{center}\n\\includegraphics[width=\\textwidth]{img/l04-compression.png}\n\\end{center}\n\n\\begin{question}{}\nWhat is $X$ for the image compression problem? What are the principal components? How does using PCA help compress the image?\n\\end{question}\n\n\\subsection{Genetic Ancestry}\n\nThere are many awesome population genetics papers that use PCA to locate individuals within the ``space'' of possible genetic mutations. Here's some text from one, a figure from which is shown below\\footnote{From European Journal of Human Genetics (2016) 24, 931-936 (2016).}. Here's a quote from the original paper:\n\n\\begin{quote}\nHere, we analyse genome-wide variation in 173 Armenians and compare them with 78 other worldwide populations. We find that Armenians form a distinctive cluster linking the Near East, Europe, and the Caucasus. We show that Armenian diversity can be explained by several mixtures of Eurasian populations that occurred between ~3000 and ~2000 BCE, a period characterized by major population migrations after the domestication of the horse, appearance of chariots, and the rise of advanced civilizations in the Near East. However, genetic signals of population mixture cease after ~1200 BCE when Bronze Age civilizations in the Eastern Mediterranean world suddenly and violently collapsed. Armenians have since remained isolated and genetic structure within the population developed ~500 years ago when Armenia was divided between the Ottomans and the Safavid Empire in Iran. \n\\end{quote}\n\n\\begin{center}\n\\includegraphics[width=\\textwidth]{img/l04-genetics.jpg}\n\\end{center}\n\n\\begin{question}{}\nWhat is $X$ for the genetic ancestry problem? What are the principal components? How were the principal components used to produce the figure above?\n\\end{question}\n\n\\subsection{Topic Modeling}\n\nPCA also has many uses in natural language processing. It forms the basis for latent semantic indexing (see Deerwester 1990) and can also be used for topic modeling, a form of mixture model (see Section~\\ref{sect:mixturemodels})\\footnote{Figure: Topic modeling French crime fiction. From https://dragonfly.hypotheses.org/530.}.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/l04-topics.png}\n\\end{center}\n\n\\begin{question}{}\nWhat is $X$ for the topic modeling problem? For the latent semantic indexing problem? What do the principal components represent?\n\\end{question}\n\n\\begin{question}{}\nThink of 2-3 different unsupervised learning problems from biology or medicine where PCA makes sense, conceptually at least, for modeling the data. How would you set up the data matrix in each case? What would the principal components correspond to in the data? \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Technical Details (Advanced)}\n\n\\subsection{Eigenvalues and Eigenvectors \\label{ssect:eig}}\n\nOne interpretation of matrix multiplication, $Ax$, where $A$ is an $m \\times m$ square matrix and $x$ a vector of length $m$, is that $A$ linearly transforms $x$ by rotating it, changing its magnitude, or both. An \\textbf{eigenvector} of $A$ is a vector that, when multiplied by $A$, grows or shrinks in magnitude but does not rotate. The multiplier of its magnitude is given by the corresponding \\textbf{eigenvalue}. There are $m$ different eigenvalues and eigenvectors for an $m \\times m$ matrix, although the eigenvalues may not all be distinct. The set of all eigenvalues of $A$ is called the \\textbf{spectrum} of $A$. \n\nFor all eigenvalue-eigenvector pairs, the relationship $Av = \\lambda v$, where $v$ is an eigenvector and $\\lambda$ its corresponding eigenvalue, must hold. To find the $\\lambda$s and $v$s analytically, we can set the determinant $ | A - \\lambda I | $, called the \\textbf{characteristic polynomial}, equal to zero and solve for the eigenvalue and eigenvector corresponding to each root. Note that any scalar multiple of an eigenvector is itself an eigenvector; usually we restrict eigenvectors to have magnitude $1$ for this reason.\n\nIf a matrix is \\textbf{symmetric} and \\textbf{positive semidefinite} (all positive or zero eigenvalues), all of its eigenvectors will be orthogonal.\n\n\\subsection{PCA: Eigendecomposition Version} \n\nThe first way we can find the principal components is by performing an eigen-decomposition identical to the one we performed in Section~\\ref{ssect:eig} on the sample covariance matrix. The principal components will be the eigenvectors of this matrix, and the corresponding eigenvalues tell you how much of the dataset's overall variance is accounted for by each eigenvector.\n\nOne useful fact about the covariance matrix is that, because it is a symmetric matrix, it can be diagonalized:\n\\begin{equation} S = \\frac{1}{n-1} X^T X = V L V^T \\label{eqn:eigendiag} \\end{equation}\nwhere $V$ is a matrix of the $p$ eigenvectors of $S$ (each column is an eigenvector) and $L$ is a diagonal matrix with the eigenvalues of $S$ along the diagonal. This fact will be important later.\n\n\\subsection{PCA: Singular Value Decomposition (SVD) Version}\n\nAlthough the eigendecomposition of the covariance matrix is generally the way PCA is presented, in practice most software uses another matrix decomposition called the \\textbf{singular value decomposition (SVD)}, even though it is slower to compute, because it's more numerically stable.\n\nHere's why the two methods are equivalent. Any matrix, $M$, with real or complex values (we'll focus on real valued matrices here) has an SVD of the form\\footnote{This is in contrast with the eigendecomposition, which works only on positive semidefinite matrices.}:\n$$ M = U D V^T $$\nwhere $U$ is an orthogonal matrix, meaning that $U^TU = I$, $D$ is diagonal and all of its nonzero elements are non-negative real numbers called \\textbf{singular values}, and $V$ is also orthogonal. For a square matrix, the SVD can be viewed as ``breaking up'' the transformation described by a matrix into three separate transformations: a rotation/reflection, a scaling, and another rotation/reflection\\footnote{Figure: Graphical representation of the SVD of a square matrix, $M$. Note that the illustrator here uses $\\Sigma$ instead of $D$ for the middle, diagonal matrix. Attribution: By Georg-Johann (Own work), via Wikimedia Commons.}:\n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/l04-svd.pdf}\n\\end{center}\n\n\\noindent If we perform the SVD on $X$, we obtain a decomposition\n$$ X = U D V^T $$\nwhere $D$ is a diagonal matrix with singular values $d_1, \\dots, d_p$. Knowing this, we can rewrite our covariance matrix as\n\\begin{align*} S &= \\frac{1}{n-1} X^T X \\\\\n&= \\frac{1}{n-1} (UDV^T)^T U D V^T \\\\\n&= \\frac{1}{n-1} V D U^T U D V^T \\\\\n&= V \\frac{D^2}{n-1} V^T. \\end{align*}\n\nComparing this to the form from Equation~\\ref{eqn:eigendiag}, we see that the eigenvectors correspond to the right singular values of the SVD, and the eigenvalues are related to the singular values on the diagonal of $D$ by $\\lambda_i = d_i^2/(n-1)$.\n\nThere are a lot of interpretations of the SVD. The one I like best is that the SVD provides a ``nearest orthogonal matrix'' to the original matrix. It's like the data have a coordinate system of orthogonal axes in which they most like to live, and the SVD tells you what that system is.\n\n", "meta": {"hexsha": "dea260015174a6cdc6e53209f7431039696a65a8", "size": 18672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-principal-components-analysis.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-principal-components-analysis.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-principal-components-analysis.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": 60.2322580645, "max_line_length": 872, "alphanum_fraction": 0.7261675236, "num_tokens": 5140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.6997606940800105}}
{"text": "\n\\subsection{Chapter 5}\n\n\\begin{p}{Show that any 2-form $F$ on $\\R\\times S$ can be uniquely expressed as $B+E\\wedge dt$ in \nsuch a way that for any local coordinates $x^i$ on $S$ we have \n$E=E_i dx^i$ and $B=\\frac{1}{2}B_{ij} dx^i\\wedge dx^j$.}\n\\end{p}\n\nFor some patch $U\\subset S$, we can use the local coordinates $x^i$ along with $t\\in\\R$ to define an\nelement of $\\R^{n+1}$. Any 2-form $F$ can be written as $F=F_{\\alpha\\beta} dx^\\alpha\\wedge dx^\\beta$ where the summation\nruns over $0\\dots n$ and $x^0=t$. We can also express this as $F=F_{0i}dt\\wedge dx^i+F_{i0}dx^i\\wedge dt+F_{ij}dx^i\\wedge dx^j$. \nBut then by \nantisymmetry of the wedge product, we might as well have $F_{i0}=-F_{0i}$. Then defining $E_i=2F_{0i}$ we have\n$F=E_i dx^i\\wedge dt+F_{ij}dx^i\\wedge dx^j$. With $B_{ij}=2F_{ij}$ we obtain $F=E\\wedge dt+B$. This decomposition is unique \nbecause if it were true using different functions $E'_i$ and $B'_{ij}$, then their difference would be zero.\n\n\\begin{p}{Show that for any form $\\om$ on $\\R\\times S$ there is a unique way to write $d\\om=dt\\wedge\\partial_t\\om+d_S\\om$\nsuch that for any local coordinates $x^i$ on $S$, writing $t=x^0$, we have $d_S\\om=\\partial_i \\om_I dx^i\\wedge dx^I$ and\n$dt\\wedge \\partial_t\\om=\\partial_0\\om_I dx^0\\wedge dx^I$.}\n\\end{p}\n\nFirst write $\\om=\\om_I dx^I$ for $I$ a multi-index of length $p$ (i.e. a $p$-tuple whose entries range over $0\\dots n$, where\n$n$ is the dimension of $S$). Then $d_S\\om=\\partial_i \\om_I dx^i\\wedge dx^I$ and $\\partial_t\\om=\\partial_0\\om_I$. Again, uniqueness\nfollows from linearity: if there were two possibilities, their difference would be zero by the linearity of $d$, implying their equality.\n\n\\begin{p}{Use the nondegeneracy of the metric to show that the map from $V$ to $V^*$ given by $v\\mapsto g(v,\\cdot)$ is \nan isomorphism, that is, 1-to-1 and onto.}\\end{p}\n\nNondegeneracy of the metric means that if $g(v,w)=0$ for all $w$, then $v=0$. Now, for the map to be an isomorphism, we have to \ncheck the two conditions. First 1-to-1: different inputs result in different outputs. So we check if the difference of the \noutputs is zero: $g(v,\\cdot)-g(w,\\cdot)=g(v-w,\\cdot)\\neq 0$ unless $v=w$. Next is the onto condition: is every element of $V^*$ the image\nof some $v\\in V$? Yes, consider $\\om\\in V^*$ and consider the action on a basis: $\\om_\\mu=\\om(e_\\mu)$. Setting $\\om_\\mu=g(v,e_\\mu)$, \nwe have to solve for $v$. Expanding $v=v^\\mu e_\\mu$ we obtain $\\om_\\mu=v^\\nu g(e_\\nu,e_\\mu)=v^\\nu g_{\\nu,\\mu}$. But\nthe nondegeneracy of $g$ implies that $g_{\\nu,\\mu}$ is invertible. Suppose we have $g(v,w)=g_{\\mu,\\nu}v^\\mu w^\\nu=0$ for all $w$. Then\n$g_{\\mu,\\nu}v^\\mu=0$ for all $\\nu$. But this only occurs when $v^\\mu=0$ for all $\\mu$, meaning that $g_{\\mu,\\nu}$ never annihilates\nan input vector; it has full rank. Thus, it's invertible.  So we can solve the equation for $v$.\\\\\n\nThere's a more direct proof for the vector spaces we are considering here: by exercise 28, we know the dual space\nhas the same dimension as the original space. Thus, nothing in the dual can be outside the image of the original space, since if\nwere, it would consititute a new basis element.\n\n\\begin{p}{Let $v=v^\\mu e_\\mu$ be a vector field on a chart. Show that the corresponding 1-form $g(v,\\cdot)$ is equal to $v_\\nu f^\\nu$, where $f^\\nu$ is the dual basis of 1-forms and $v_\\nu=g_{\\mu,\\nu}v^\\mu$.}\\end{p}\n\nWe can follow the lines of the previous exercise to derive the form, or simply show that the equation is correct. Choosing an \narbitrary vector field $w$, $g(v,w)=g_{\\mu,\\nu}v^\\mu w^\\nu$ which is equal to $v_\\nu f^\\nu(w)=v_\\nu w^\\nu$.\n\n\\begin{p}{Let $\\om=\\om_\\mu f^\\mu$ be a 1-form on a chart. Show that the corresponding vector field is equal to\n$\\om^\\nu e_\\nu$ where $\\om^\\nu=g^{\\mu,\\nu}\\om_\\mu$.}\\end{p}\n\nFor arbitrary $v$, $\\om(v)=\\om_\\mu f^\\mu(v)=\\om_\\mu v^\\mu$. But there should be a $w$ such that $g(w,v)=\\om_\\mu v^\\mu$. \nUsing the series expression for $v$ and $w$, we obtain $\\om_\\nu v^\\nu=g_{\\mu,\\nu}w^\\mu v^\\nu$. This should hold for arbitrary $v$,\nso $\\om_\\nu=g_{\\mu,\\nu}w^\\mu$, or $w^\\mu=g^{\\mu,\\nu}\\om_\\nu$.\n\n\\begin{p}{Let $\\eta$ be the Minkowski metric on $\\R^4$. Show that its components in the standard basis\nare $\\eta_{\\mu,\\nu}=\\delta_{\\mu,\\nu}(1-2\\delta_{\\mu,0})$.}\\end{p}\n\nThe Minkowski metric is defined for two vectors $v$ and $w$ as $\\eta(v,w)=-v^0w^0+v^1w^1+v^2w^2+v^3w^3$. The\nform of $\\eta_{\\mu,\\nu}$ follows immediately. \n\n\\begin{p}{Show that $g^\\mu_\\nu=\\delta^\\mu_\\nu$.}\\end{p}\n\nIf we start with $g_{\\lambda,\\nu}$ we can raise the first index with the metric, obtaining $g^\\mu_\\nu=g^{\\mu,\\lambda}g_{\\lambda,\\nu}$.\nBut $g^{\\lambda,\\nu}$ is the matrix inverse of $g_{\\lambda,\\nu}$, so the result of the product is the Kronecker delta.\n\n\\begin{p}{Show that the inner product of $p$-forms is nondegenerate by supposing that $(e^1,\\dots,e^n)$ is any\northonormal basis of 1-forms in some chart, with $g(e^i,e^i)=\\epsilon(i)$ for $\\epsilon(i)=\\pm 1$. Show the $p$-fold\nwedge products $e^{i_1}\\wedge\\dots\\wedge e^{i_p}$ form an orthonormal basis of $p$-forms with \n$\\langle e^{i_1} \\wedge\\dots\\wedge e^{i_p},e^{i_1}\\wedge\\dots\\wedge e^{i_p}\\rangle=\\epsilon(i_1)\\cdots\\epsilon(i_p)$.}\\end{p}\n\nFrom exercise 52 we already know that the nondegeneracy of $g$ is equivalent to the invertibility of the matrix of $g$ applied to basis \nelements. The same will be true here.  First recall that the terms in\nthe $p$-fold wedge products must be distinct so that the $p$-form doesn't vanish. \nSuppose we have two basis $p$-forms in which $m$ basis 1-forms\nappear in both. Reordering so that these come first, the matrix of $g(e^{i_j},e^{k_\\ell})$ will be block diagonal with the first\n$m\\times m$ block equal to the identity matrix, and zero everywhere else. This matrix obviously has zero determinant, thus\nthe basis $p$-forms with any distinct elements are orthogonal. Otherwise, the determinant yields the product of the individual\nnormalizations, establishing the last equation posed in the problem. This in turn means that the metric matrix \nfor the basis $p$-forms is diagonal with entries $\\pm 1$, whence it has full rank and is therefore nondegenerate.\n\n\\begin{p}{Let $E=E_j dx^j$ be a 1-form on $\\R^3$ with its Euclidean metric. Show that $\\langle E,E\\rangle=E_x^2+E_y^2+E_z^2$. Similarly, let $B=B_x dy\\wedge dz+B_y dz\\wedge dx+B_z dx\\wedge dy$ be a 2-form. \nShow that $\\langle B,B\\rangle = B_x^2+B_y^2+B_z^2$.}\\end{p}\n\n$\\langle E,E\\rangle=\\delta^{i,j}E_i E_j=E_x^2+E_y^2+E_z^2$.  $\\langle B,B\\rangle=\\langle B_x dy\\wedge dz+B_y dz\\wedge dx+B_z dx\\wedge dy,\nB_x dy\\wedge dz+B_y dz\\wedge dx+B_z dx\\wedge dy\\rangle= B_x^2+B_y^2+B_z^2$ since the different wedge products are orthonormal.\\\\\n\n\\begin{p}{In $\\R^4$ let $F$ be the 2-form given by $F=B+E\\wedge dt$, where $E$ and $B$ are given by the formulas\nin the previous exercise. Using the Minkowski metric, calculate $-\\frac{1}{2}\\langle F,F\\rangle$.}\\end{p}\n\n$\\langle F,F\\rangle=\\langle B+E\\wedge dt,B+E\\wedge dt\\rangle=\\langle B,B\\rangle+\\langle B,E\\wedge dt\\rangle+\\langle E\\wedge dt,B\\rangle\n+\\langle E\\wedge dt,E\\wedge dt\\rangle$. The middle two terms are zero by orthogonality of different wedge products, leaving only the\nlast term to deal with. $\\langle E\\wedge dt,E\\wedge dt\\rangle={\\rm det}\\left(\\begin{array}{cc}\\langle E,E\\rangle & \\langle E,dt\\rangle\\\\\n\\langle dt,E\\rangle & \\langle dt,dt\\rangle\\end{array}\\right)={\\rm det}\\left(\\begin{array}{cc}\\langle E,E\\rangle & 0\\\\\n0 &-1\\end{array}\\right)=-\\langle E,E\\rangle$. Hence $-\\frac{1}{2}\\langle F,F\\rangle=\\frac{1}{2}(\\langle E,E\\rangle-\\langle B,B\\rangle)$,\nwhich is the Lagrangian of the source(charge)-free field.\\\\\n\n\\begin{p}{Show that any even permutation of a given basis has the same orientation, while any odd permutation has the\nopposite orientation.}\n\\end{p}\n\nTo check this we must examine the determinant. Since the determinant of a product is the product of determinants, we can\nbreak up the permutation of basis elements into a product of pairwise swaps, whose individual determinant is minus one. Thus,\nif the permutation has an even number of swaps, the new basis has the same orientation, while an odd number of swaps \nimplies the determinant will equal minus one.\n\n\\begin{p}{Let $M$ be an oriented manifold. Show that we can cover $M$ with oriented charts $\\phi_\\alpha:U_\\alpha\\rightarrow\\rn$, that is,\ncharts such that the basis $dx^\\mu$ of cotangent vectors on $\\rn$, pulled back to $U^\\alpha$ by $\\phi_\\alpha$, is positively\noriented.}\n\\end{p}\n\nThe point here is that the volume form on $\\rn$ can be pulled back to $U_\\alpha$ by $\\phi_\\alpha$. \nSince $M$ is orientable, we can define a volume form $\\om$ on all of $M$ to specify the standard orientation. In the chart\n$U_\\alpha$ we can also define a volume form by pulling back the standard volume form $\\bigwedge_\\mu dx^\\mu$ from $\\rn$. \nIf this specifies a different orientation, just reorder the basis of $\\rn$ so as to have the same orientation as given by $\\om$.\nSince $\\om$ exists in all charts $U_\\alpha$, we can always orient these appropriately.\n\n\\begin{p}{Given a diffeomorphism $\\phi:M\\rightarrow N$ from one oriented manifold to another, we say that $\\phi$ is\norientation-preserving if the pullback of any right-handed basis (standard orientation) of a cotangent space in $N$ is a \nright-handed basis of a cotangent space in $M$. Show that if we can cover $M$ with charts\nsuch that the transition functions $\\varphi_\\alpha\\circ \\varphi_\\beta^{-1}$ are orientation-preserving, we \ncan make $M$ into an oriented manifold by using the charts to transfer the \nstandard orientation on $\\rn$ to an orientation on $M$.}\n\\end{p}\n\nIn each chart pull the standard volume form on $\\rn$ back to $M$. Since\nany two charts are connected by an orientation-preserving transition function, the orientation is\nthe same in any chart and the manifold is oriented everywhere.\\\\\n\n\\begin{p}{Let $M$ be an oriented $n$-dimensional semi-Riemannian manifold and let $\\{e_\\mu\\}$ be an oriented orthonormal\nbasis of cotangent vectors at some point $p\\in M$. Show that $e_1\\wedge\\dots\\wedge e_n={\\rm vol}_p$ where \\emph{vol} is \nthe volume form associated to the metric on $M$, and \\emph{vol}$_p$ is its value at $p$.}\n\\end{p}\n\nThe oriented basis in question can be generated from the standard basis by applying a transformation $T$. Since \nthe input and output are orthonormal bases, $T$ is an orthogonal matrix, implying det$T=\\pm 1$. \nBecause it's orientation preserving, det$T=1$. Since in transforming $e_1\\wedge\\dots\\wedge e_n$ into the standard\nbasis at $p$, we pick up a factor equal to the determinant of $T$,  $e_1\\wedge\\dots\\wedge e_n={\\rm vol}_p$.\n\n\\begin{p}{Show that if we define the Hodge star operator in a chart using the formula $\\star(e^{i_1}\\wedge \\cdots \\wedge\ne^{i_p})=\\pm e^{i_{p+1}}\\wedge \\cdots \\wedge e^{i_n}$, where the second set of indices consists of those not contained in the\nfirst and the $\\pm$ is given by ${\\rm sign}(i_1,\\dots,i_n)\\epsilon(i_1)\\cdots \\epsilon(i_p)$, it satisfies the property $\\om\\wedge\\star\\mu=\n\\langle\\om,\\mu\\rangle{\\rm vol}$.}\n\\end{p}\n\nFirst expand $\\om$ and $\\mu$: $\\om=\\om_\\alpha e^{\\alpha_1}\\wedge\\cdots\\wedge e^{\\alpha_p}$, \n$\\mu=\\mu_\\beta e^{\\beta_1}\\wedge\\cdots\\wedge e^{\\beta_p}$. Now compute their inner product:\n$\\langle \\om,\\mu\\rangle=\\om_\\alpha\\mu_\\beta\\langle e^{\\alpha_1}\\wedge\\cdots\\wedge e^{\\alpha_p}, \ne^{\\beta_1}\\wedge\\cdots\\wedge e^{\\beta_p}\\rangle=\\om_\\alpha\\mu_\\beta\\delta^{\\alpha,\\beta}\\epsilon(\\alpha_1)\\cdots\\epsilon(\\alpha_p)$. \nNow $\\star\\mu=\\pm\\mu_\\alpha e^{\\alpha_{p+1}}\\wedge\\cdots\\wedge \ne^{\\alpha_n}$, and taking the wedge product with $\\om$, one obtains $\\om\\wedge\\star\\mu=\\pm\\om_\\alpha\\mu_\\beta\\delta^{\\alpha,\\beta}\ne^{\\alpha_1}\\wedge\\cdots e^{\\alpha_n}$. Finally, $e^{\\alpha_1}\\wedge\\cdots e^{\\alpha_n}={\\rm sign}(\\alpha_1,\\dots,\\alpha_n){\\rm vol}$, \nso we obtain the desired result.\n\n\\begin{p}{Calculate $\\star d\\om$ when $\\om$ is a 1-form on $\\R^3$.}\\end{p}\n\n$\\star d\\om$ is essentially the curl of $\\om$. \nFirst expand $\\om$ in an orthonormal basis $e^j$: $\\om=\\om_je^j$. $d\\om=\\partial_k\\om_j dx^k\\wedge dx^j$. Finally, $\\star d\\om=\n\\partial_j\\om_k\\, {\\rm sign}(j,k,\\ell)dx^\\ell=\\partial_j\\om_k \\epsilon^{jk}_\\ell dx^\\ell.$ Note that $\\epsilon(i)=1$ for all $i$ in this case.\n\n\\begin{p}{Calculate $\\star d\\,{\\star}\\om$ when $\\om$ is a 1-form on $\\R^3$.}\\end{p}\n\nThis gives the divergence of $\\om$. Expanding $\\om$ in a basis as above, we obtain $\\star\\om=\\om_j\\epsilon^j_{k\\ell}dx^k\\wedge dx^\\ell$.\nApplying $d$ gives $d\\star\\om=\\partial_m\\om_j\\epsilon^j_{k\\ell}dx^m\\wedge dx^k\\wedge dx^\\ell$. Another $\\star$ yields the final\nresult: $\\star d\\star\\om=\\partial_m\\om_j\\epsilon^j_{k\\ell}\\epsilon^{mk\\ell}$ and since $\\epsilon^j_{k\\ell}\\epsilon^{mk\\ell}=\\delta^{jm}$, we\nhave $\\star d\\star\\om=\\partial_j\\om_k\\delta^{jk}$, the divergence.\n\n\\begin{p}{Give $\\R^4$ the Minkowski metric and the orientation in which\n$(dt,dx,dy,dz)$ is positively oriented. Calculate the Holdge star operator on all wedge products of\n$dx^\\mu$'s Show that on $p$-forms $\\star^2=(-1)^{p(4{-}p)+1}$.}\n\\end{p}\n\nFirst we have the definition vol$=dt\\wedge dx\\wedge dy\\wedge dz$. Using this we can make a table\nof the various starred wedge products. \n\n\n\\begin{tabular}{c|c}\n$\\omega$ & $\\star\\omega$\\\\\\hline\n$dt$ & $-dx\\wedge dy\\wedge dz$\\\\\n$dx$ & $-dt\\wedge dy\\wedge dz$ \\\\\n$dy$ & $dt\\wedge dx\\wedge dz$\\\\\n$dz$ & $-dt\\wedge dx\\wedge dy$\\\\\n$dt\\wedge dx$ & $-dy\\wedge dz$\\\\\n$dt\\wedge dy$ & $dx\\wedge dz$ \\\\\n$dt\\wedge dz$ &$-dx\\wedge dy$\\\\\n$dx \\wedge dy$ & $dt\\wedge dz$ \\\\\n$dx \\wedge dz$ & $-dt\\wedge dy$\\\\\n$dy \\wedge dz$ & $dt\\wedge dx$\\\\\n$dt\\wedge dx\\wedge dy$ & $-dz$ \\\\\n$dt\\wedge dx\\wedge dz$ & $dy$\\\\\n$dt\\wedge dy\\wedge dz$ & $-dx$\\\\\n$dx\\wedge dy\\wedge dz$ & $-dt$\n\\end{tabular}\\\\\n\nFrom the table we immediately see that the given condition is fulfilled.\n\n\\begin{p}{Let $M$ be an oriented semi-Riemannian manifold of dimension\n$n$ and signature $(s,n{-}s)$. Show that on $p$-forms $\\star^2=(-1)^{p(n-p)+s}$.}\n\\end{p}\n\n$\\om\\wedge \\star \\om=\\langle \\om,\\om\\rangle {\\rm vol}$ and $\\star\\om \\wedge \\star^2\\om=\\langle \\star\\om,\n\\star\\om\\rangle{\\rm vol}$, so $\\star\\om \\wedge \\star^2\\om=(-1)^{p(n{-}p)}\\star^2\\!\\om\\wedge \\star\\om=\n\\frac{\\langle \\star\\om, \\star\\om\\rangle}{\\langle \\om,\\om\\rangle}\\,\\om\\wedge\\star\\om$. Hence\n$\\star^2=(-1)^{p(n{-}p)}\\frac{\\langle \\star\\om, \\star\\om\\rangle}{\\langle \\om,\\om\\rangle}$. \nTo evaluate this expression,\nlet $\\om$ be a basis $p$-form $e^{i_1}\\wedge\\dots\\wedge e^{i_p}$. \nSetting $\\epsilon(\\mu)=\\langle e^\\mu,e^\\mu\\rangle$, we have \n$\\langle\\om,\\om\\rangle=\\prod_{j=1}^p \\epsilon(i_j)$. On the other hand, \n$\\star\\om=\\pm e^{i_{p+1}}\\wedge\\dots\\wedge e^{i_n}$, so $\\langle \\star\\om,\\star\\om\\rangle=\n\\prod_{j=p+1}^n \\epsilon(i_{p+j})$. Since all the terms in the denominator are $\\pm 1$, we might as\nwell multiply by $\\langle\\om,\\om\\rangle$ instead of dividing. We then obtain\n$\\star^2=(-1)^{p(n{-}p)}\\prod_{j=1}^n \\epsilon(i_j)$. The latter term equals $(-1)^s$ as $s$ is the \nnumber of basis elements with norm $-1$.\n\n\\begin{p}{Let $M$ be an oriented semi-Riemannian manifold of dimension $n$ and signature $(s,n{-}s)$. \nLet $e^\\mu$ be an orthonormal basis of 1-forms on some chart. Define the \nLevi-Civita sympbol for $1\\leq i_j\\leq n$ by \n\\[ \\epsilon_{i_1\\dots i_n}=\\left\\{\n\\begin{array}{ll}\n{\\rm sign}(i_1\\dots i_n) & \\textrm{all $i_j$ distinct}\\\\0 &{\\rm otherwise}\n\\end{array}\n\\right. \\]}\nShow that for any $p$-form $\\om=\\frac{1}{p!}\\om_{i_1\\dots i_p}e^{i_1}\\wedge\\dots\\wedge e^{i_p}$ we\nhave $(\\star\\om)_{j_1\\dots j_{n{-}p}}=\\frac{1}{p!}\\epsilon^{i_1\\dots i_p}_{j_1\\dots j_{n{-}p}}\\om_{i_1\\dots i_p}$.\n\\end{p}\n\nUsing the results of exercise 64, we have $\\star(e^{i_1}\\wedge \\cdots \\wedge\ne^{i_p})=\\epsilon(i_1)\\cdots \\epsilon(i_p)\\epsilon^{i_1\\dots i_p}_{i_{p+1}\\dots i_{n}}e^{i_{p+1}}\\wedge \\cdots \\wedge e^{i_n}$ \n(no sum). Now $(\\star\\om)_{j_1\\dots j_{n{-}p}}=\\epsilon(j_1)\\cdots \\epsilon(j_{n{-}p})\\langle e^{j_1}\\wedge\\dots \\wedge e^{j_{n{-}p}},\\star \\om\\rangle$, so $(\\star\\om)_{j_1\\dots j_{n{-}p}}=\\frac{(-1)^s}{p!}\\epsilon^{i_1\\dots i_p}_{j_1\\dots j_{n{-}p}}\\om_{i_1\\dots i_p}$. \n\n\\begin{p} {Show that the Maxwell equations $\\nabla\\cdot \\vec{E}=\\rho, \\nabla\\times \\vec{B}-\\frac{\\partial \\vec{E}}{\\partial t}=\\vec{j}$ can be rewritten as $\\star_S\\, d_S \\star_S\\! E=\\rho$ and $-\\partial_t E+\\star_S \\,d_S\\star_S\\! B=j$.}\n\\end{p}\n\nStart from $E=E_j dx^j$. For the remainder of the exercise, $\\star$ means $\\star_S$. So $\\star E=\\frac{1}{2}E_j \\epsilon^{j}_{k\\ell}dx^k\\wedge dx^\\ell$. Then $d\\star\\!E=\\frac{1}{2}\\epsilon^j_{k\\ell}\\partial_m E_j dx^m\\wedge dx^k\\wedge dx^\\ell$, and finally $\\star d\\star\\! E=\\frac{1}{2}\\epsilon^{j}_{k\\ell}\\epsilon^{mk\\ell}\\partial_m E_j=\\partial_j E_j=\\nabla\\cdot\\vec{E}$. Meanwhile $B=\\frac{1}{2}\\epsilon^j_{k\\ell} B_j dx^k\\wedge dx^\\ell$. Thus $\\star B=\\frac{1}{2}\\epsilon^j_{k\\ell}\\epsilon^{k\\ell}_m B_j dx^m=B_j dx^j$. Then $d\\star\\!B=\\partial_k B_j dx^k\\wedge dx^j$\nand $\\star d\\star\\!B=\\epsilon^{kj}_\\ell \\partial_k B_j dx^\\ell$, the components of which are simply\n$\\nabla\\times \\vec{B}$.\\\\\n\n\\begin{p}\n{Show that on a  semi-Riemannian manifold $M$ which can\nbe decomposed into $\\R\\times S$, where $S$ is space, the general Maxwell \nequations $dF=0$ and $\\star d\\star F=J$ can be transformed into their ``usual'' \nappearance $d_S E=0, \\partial_t B+d_SE=0, \\star_Sd_S\\star_SE=\\rho,$ and\n$\\star_Sd_S\\star_SB-\\partial_tE=j$.}\n\\end{p}\n\nGiven the decomposition of $M$, we write $F=B+E\\wedge dt$ where $B$ is the\nportion of $F$ defined only on $S$. Similarly $J=j-\\rho dt$. \nThe first equation then reads $dB+dE\\wedge dt=0$. Observe that \n$dB=d_SB+\\partial_t B\\wedge dt$\nwhile $dE\\wedge dt=\\partial_t E dt\\wedge dt+d_S E\\wedge dt$. Thus we have \n$d_S B=0$ and $\\partial_t B+d_S E=0$; the first equation deals with three forms \nonly on space, while the second involves three forms on space and time. \nAssume further that\nthe metric can be decomposed into $g=-dt^2+{}^3g$ \n{\\small (can this always be done when the underlying space is a product? \nThe tangent space can be decomposed, it seems clear, \nfrom the picture of vectors as arrows pointing tangentially to the surface. In the case of\na product space, there are arrows for each manifold, and we take their formal product\nto get the tangent to the total manifold. But from the point of view of vectors \nas derivatives? I think it might be possible by showing that the value of the derivative \nis equal to making changes on each submanifold separately and then adding them. In\nother words, we have a curve $\\gamma(t)$ on $M$, but since $M=\\R\\times S$, we\ncan write this as $(\\gamma_1(t),\\gamma_2(t))$. Now $\\gamma'(t)[f]=\\frac{\\rm d}{{\\rm d}t}f(\\gamma(t))=\\frac{\\rm d}{{\\rm d}t}f(\\gamma_1(t),\\gamma_2(t))=\\frac{\\partial f}{\\partial \\gamma_1}\\frac{\\partial\\gamma_1}{\\partial t}+\\frac{\\partial f}{\\partial \\gamma_2}\\frac{\\partial\\gamma_2}{\\partial t}=\\gamma_1'(t)[f]|_{\\gamma_2(t)}+\\gamma_2'[f]|_{\\gamma_1(t)}\n\\equiv(\\gamma_1'(t),\\gamma_2'(t))[f].$ That's\nwhat we do in $\\R^n$, after all. I guess it's obvious once you map open sets of \nthe manifold to $\\R^n$. But this doesn't mean the metric has to be block diagonal and respect the split; after all that \\emph{doesn't} always happen in $\\R^n$.)}\nNow let $\\star_S$ be the Hodge dual on (differential forms on) $S$. Since $E$ is a one form\non $S$, $\\star E\\wedge dt=\\star_S E$ and similarly since $B$ is a two form on $S$, \n$\\star B=-\\star_S B\\wedge dt$ (using the chart from 67).   So $\\star F=\\star_S E-\\star_S B\\wedge dt$ and then $d\\star F=d_S\\star_S E+\\star_S(\\partial_t E)\\wedge dt-d_S\\star_S B\\wedge dt$. Note that the first term is a three form on space, so $\\star d_S\\star_S E$ must be a one form on time, $\\star d_S\\star_S E=-(\\star_S d_S\\star_S E) dt$, where\nthe minus sign can be determined again by the chart from 67. The second term is a three form on space and time, and due to the ordering we'll have $\\star(\\star_S(\\partial_t E)\\wedge dt)=-\\partial_t E$. The last term is also a three form on space and time and\nwe end up with $\\star(d_S\\star_S B\\wedge dt)=-\\star_S d_S\\star_S B$. Thus $\\star_S d_S\\star_S E=\\rho$ and $-\\partial_t E+\\star_S d_S\\star_SB=j$.\n\n\n\\begin{p}{Show that in a Riemannian 4-dimensional manifold any 2-form $F$ can be written as a sum of self-dual and \nanti-self-dual parts, $F=F_++F_-$ for $\\star F_\\pm=\\pm F_\\pm$, if we take $F_\\pm=(F\\pm\\star F)/2$.}\n\\end{p}\n\nClearly $F=F_++F_-$. And \n$\\star F_\\pm=(\\star F\\pm\\star^2 F)/2=(\\pm F+\\star F)/2=\\pm(F\\pm\\star F)/2=\\pm F_\\pm$.\n\n\\begin{p}{Show that in a Lorentizan 4-manifold any 2-form $F$ can be written as a sum of self-dual and \nanti-self-dual parts, $F=F_++F_-$ for $\\star F_\\pm=\\pm i F_\\pm$.}\n\\end{p}\n\nTake $F_\\pm=(F\\mp \\star i F)/2$. Then $\\star F_\\pm=(\\star F\\mp\\star^2 i F)/2=(\\pm i F+\\star F)/2=\\pm i(F\\mp \\star  i F)/2=\\pm i F_\\pm$.\n\n\\begin{p}{Show that the equations $\\star_S E=iB$ and $\\star_S B=-i E$ are \nequivalent and that they both hold if at every time $t$ we have $E=E_i dx^i$ and $B=-(i/2)\\varepsilon^j_{\\phantom{j}k\\ell}E_j dx^k\\wedge dx^\\ell$.}\n\\end{p}\n\nApplying $\\star_S$ turns one equation into the other, to they are equivalent. \nFrom exercise 69 we know that $\\star_S E=(1/2)\\varepsilon^j_{\\phantom{j}k\\ell}E_j dx^k\\wedge dx^\\ell$ which is clearly equal to $iB$.\n\n\\begin{p}{Show that the second Maxwell equation $\\partial_t B+d_SE=0$ leads to ${}^3k\\wedge E=k_0 B$.}\n\\end{p}\n\nStart with $d_S E=d_S(e^{ik_\\mu x^\\mu}E_j dx^j)=\\partial_k(e^{ik_\\mu x^\\mu}E_j)dx^j\\wedge dx^k=i k_k E_jdx^j\\wedge dx^k=-i{}^3k\\wedge E$. Meanwhile \n$\\partial_t B=ik_0 B$, so $\\partial_t B+d_SE=i(k_0 B-{}^3k\\wedge E)=0$, the desired \nresult.\n\n\\begin{p}%76\n{Show that ${}^3k\\wedge E=-ik_0 \\star_s E$ implies $k_\\mu k^\\mu=0$.}\n\\end{p}\n\nStart from $\\langle {}^3k\\wedge E,{}^3k\\wedge E\\rangle=k_0^2\\langle\\star_s E,\\star_s E\\rangle$. \nNote that the inner product should be antilinear in one of its inputs. Using the coordinate expressions for $E$\nand ${}^3k$ we have $\\langle {}^3k\\wedge E,{}^3k\\wedge E\\rangle=k_\\ell k_{\\ell'}^*E_j E_{j'}^*\\langle dx^\\ell\\wedge dx^j,dx^{\\ell'}\\wedge dx^{j'}\\rangle=k_\\ell k_{\\ell'}^*E_j E_{j'}^*(\\delta^{j j'}\\delta^{\\ell\\ell'}-\\delta^{j'\\ell}\\delta^{j\\ell'})=\\langle {}^3k,{}^3k\\rangle\\,\\langle E,E\\rangle-|\\langle {}^3k,E\\rangle|^2=\\langle {}^3k,{}^3k\\rangle\\,\\langle E,E\\rangle$, since $E$ is orthogonal to ${}^3k$.\nOn the other hand, $k_0^2\\langle\\star_s E,\\star_s E\\rangle=\\frac{k_0^2}{4}\\varepsilon^j_{k\\ell}\\varepsilon^{j'}_{k'\\ell'}E_jE_{j'}\\langle dx^k\\wedge dx^\\ell,dx^{k'}\\wedge dx^{\\ell'}\\rangle=\\frac{k_0^2}{4}\\varepsilon^j_{k\\ell}\\varepsilon^{j'}_{k'\\ell'}E_jE_{j'}(\\delta^{kk'}\\delta^{\\ell \\ell'}-\\delta^{k\\ell'}\\delta^{k'\\ell})=k_0^2\\langle E,E\\rangle$.\nThus, $\\langle {}^3k,{}^3k\\rangle=k_0^2$. Using the metric, we have $k_0^2=-k_0k^0$, and the \nother components are unchanged, so $k_\\mu k^\\mu=0$.\n\n\n\\begin{p}%77\n{Show $\\vec{E}=(0,e^{i(t-x)},-ie^{i(t-x)})$, $\\vec{B}=i\\vec{E}$ satisfy the vacuum Maxwell equations. [corrected from the book]}\n\\end{p}\n\nSince $\\vec{\\nabla}\\cdot \\vec{E}=0$ (by inspection), \n$\\vec{\\nabla}\\cdot \\vec{B}=0$, too. Now $\\vec{\\nabla}\\times \\vec{E}=\\vec{E}$ and $\\partial_t \\vec{B}=i\\partial_t \\vec{E}=-\\vec{E}$, so $\\vec{\\nabla}\\times \\vec{E}+\\partial_t \\vec{B}=0$. Finally,\n$ \\vec{\\nabla}\\times \\vec{B}=i\\vec{E}$, so $\\vec{\\nabla}\\times \\vec{B}-\\partial_t \\vec{E}=0$.\n\n\\begin{p}%{78}\n{Prove that all self-dual and anti-self-dual plane wave solutions are left and right circularly polarized, respectively.}\n\\end{p}\n\nWithout loss of generality we can take ${}^3k$ to point in the $x$ direction. Then the self-dual case is worked\nout in detail in the book. Left circular polarization can be recognized from the form of $E$, namely that the \npolarization vector is proportional to $(1,-i)$; right circular polarization is given by $(1,i)$. \nIn the anti-self-dual case $\\star_S E=-iB$ or, equivalently,\n$\\star_SB=iE$. The first Maxwell equation $d_SB=0$ reads as before, $B\\wedge {}^3k=0$, so\n$\\langle E,{}^3k\\rangle=0$ still holds. The second equation, $\\partial_t B+d_SE=0$, leads to ${}^3k\\wedge E=k_0B$ as before. Rewriting this in terms of $E$ we obtain ${}^3k\\wedge E=ik_0\\star_SE$, which\nagain leads to $\\langle {}^3k\\wedge E,{}^3k\\wedge E\\rangle=k_0^2\\langle\\star_s E,\\star_s E\\rangle$, as \nin exercise 76. Thus we know that $k$ must be lightlike, so we can assume without loss of generality \nthat $k=dt-dx$. $E$ must be orthogonal to ${}^3k$, so $E=a dy+bdz$. We now use the second \nMaxwell equation to determine $a$ and $b$. ${}^3k\\wedge E=-(a dx\\wedge dy+b dx\\wedge dz)$, \nwhile $ik_0\\star_SE=i(a dz\\wedge dx+b dx\\wedge dy)$, so $b=ia$, which is the condition for right circular\npolarization.\n\n\\begin{p}%{79}\n{Let $P:\\R^4\\rightarrow\\R^4$ be the parity transformation $P(t,x,y,z)=(t,-x,-y,-z)$. Show that if $F$ is a self-dual solution of Maxwell's equations, the pullback $P^*F$ is an anti-self-dual solution, and vice versa.}\n\\end{p}\n\nWe don't really need to show both, since the vice versa part follows from $P^*P^*F=F$. To see that $P^*F$ takes a self-dual solution to an anti-self-dual solution, note that $P^*E=-E$, while $P^*B=B$. (This is why\n$B$ is called an axial vector sometimes.) If $F=dE\\wedge dt+B$ was self-dual to begin with, meaning $\\star_SE=iB$,  the new $F'=dE'\\wedge dt'+B'=-dE\\wedge dt+B$ is anti-self-dual: $\\star_SE'=-\\star_SE=-iB=-iB'$. \n\n", "meta": {"hexsha": "921ffcae5e9b240052726d8c01e8cbf55bdb0ac9", "size": 25213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/I5.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/I5.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/I5.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": 73.5072886297, "max_line_length": 571, "alphanum_fraction": 0.6892872724, "num_tokens": 9011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.6997606909101299}}
{"text": "\\subsection{Graph embedding}\\label{subsec:graph_embedding}\n\n\\begin{definition}\\label{def:quiver_geometric_realization}\n  Let \\( Q = (V, A, h, t) \\) be a \\hyperref[def:quiver]{quiver}. Our goal is to construct a \\hyperref[def:topological_space]{topological space} that translates the connectivity properties of \\( Q \\) into their topological equivalents.\n\n  Consider the \\hyperref[def:topological_sum]{topological sum}\n  \\begin{equation*}\n    \\mscrS \\coloneqq \\parens[\\Bigg]{ \\coprod_{a \\in A} [0, 1] } \\amalg \\parens[\\Bigg]{ \\coprod_{\\deg(v) = 0} \\set{ v } }.\n  \\end{equation*}\n\n  The space \\( \\mscrS \\) consists of disjoint unit intervals, one for each arc, and of disjoint points, one for each \\hyperref[def:hypergraph/degree]{isolated vertex}.\n\n  We now want to glue common endpoints of arcs in \\( \\Sigma \\). We define the following function:\n  \\begin{equation}\\label{eq:def:quiver_geometric_realization}\n    \\begin{aligned}\n      &R: V \\cup A \\to \\pow(\\mscrS), \\\\\n      &R(v) \\coloneqq \\begin{cases}\n        \\set[\\Big]{ (v, v) },                                                           &\\deg(v) = 0 \\\\\n        \\set[\\Big]{ (0, a) \\given h(a) = v } \\cup \\set[\\Big]{ (1, a) \\given t(a) = v }, &\\deg(v) > 0,\n      \\end{cases} \\\\\n      &R(a) \\coloneqq \\set[\\Big]{ \\set{ (x, a) } \\given 0 \\leq x \\leq 1 }.\n    \\end{aligned}\n  \\end{equation}\n\n  The family\n  \\begin{equation*}\n    \\mscrX \\coloneqq \\set[\\Big]{ R(v) \\given* v \\in V } \\cup \\set[\\Big]{ \\Int R(a) \\given* a \\in A }.\n  \\end{equation*}\n  is a \\hyperref[def:set_partition]{partition} of \\( \\mscrS \\). For each vertex, there is a single point in \\( \\mscrX \\) (which is a set in \\( \\mscrS \\)) and for each arc, the interior of the arc is a subset of \\( \\mscrX \\).\n\n  We can endow the partition \\( \\mscrX \\) it with a \\hyperref[def:topological_quotient]{quotient topology} \\( \\mscrT \\). We will call the topological space \\( (\\mscrX, \\mscrT, R) \\) endowed with \\( R \\) the \\term{geometric realization} of \\( G \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:quiver_geometric_realization/undirected} For an \\hyperref[def:undirected_multigraph]{undirected multigraph} \\( G = (V, E, \\mscrE) \\), the geometric realization is any of the geometric realizations of its \\hyperref[def:multigraph_orientation]{orientations}. This construction is dependent on a choice function, but fortunately all the geometric realizations are homeomorphic as shown in \\fullref{thm:undirected_multigraph_geometric_realizations_homeomorphic}. Hence, for a lot of purposes, we can speak of \\enquote{the} geometric realization of an undirected multigraph.\n\n    \\thmitem{def:quiver_geometric_realization/drawing} We will call any \\hyperref[def:global_continuity]{continuous function} with domain \\( (\\mscrX, \\mscrT) \\) a \\term{graph drawing}. The term \\enquote{graph drawing} is not standard terminology, but unfortunately non-injective continuous images of the realization have no established name.\n\n    \\thmitem{def:quiver_geometric_realization/embedding} An injective graph drawing is called a \\term{graph embedding}.\n\n    Every graph can be embedded into \\( \\BbbR^3 \\) as shown in \\fullref{thm:quiver_can_be_embedded_into_r3}.\n\n    \\thmitem{def:quiver_geometric_realization/linear} If a graph can be embedded into \\( \\BbbR \\), we say that it is \\term{linear}.\n\n    \\thmitem{def:quiver_geometric_realization/planar} If a graph can be embedded into \\( \\BbbR^2 \\), we say that it is \\term{planar}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:quiver_geometric_realization}\n  We will give a few examples of \\hyperref[def:quiver_geometric_realization/undirected]{quiver geometric realizations}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:quiver_geometric_realization/edgeless} The \\hyperref[def:quiver_geometric_realization/undirected]{geometric realization} of an edgeless quiver is the empty topological space.\n\n    \\thmitem{ex:def:quiver_geometric_realization/positive_integers} Consider the reduced positive integer graph \\eqref{eq:ex:infinite_integer_graphs/positive}. We start with \\( \\aleph_0 \\) copies of \\( [0, 1] \\) and glue both ends of each of them except for the first. Thus, we obtain (a space homeomorphic to)\n    \\begin{equation*}\n      \\bigcup_{k \\geq 0} [k, k + 1] = [0, \\infty).\n    \\end{equation*}\n\n    Therefore, \\eqref{eq:ex:infinite_integer_graphs/positive} is a \\hyperref[def:quiver_geometric_realization/linear]{linear graph}.\n\n    \\thmitem{ex:def:quiver_geometric_realization/k3} The graph with vertices \\( V = \\set{ a, b, c } \\) and arcs \\( \\set{ \\overbrace{a \\to b}^{e_1}, \\overbrace{b \\to c}^{e_2}, \\overbrace{c \\to a}^{e_3} } \\) is more subtle.\n\n    We start with three copies of the interval \\( [0, 1] \\), depicted in \\eqref{eq:ex:def:quiver_geometric_realization/k3/relization} as upward-pointing arrows, and use dashed lines to connect the endpoints that we want to glue together.\n    \\begin{equation}\\label{eq:ex:def:quiver_geometric_realization/k3/relization}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/ex__def__graph_geometric_realization.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    After contracting the dashed lines, we obtain a topological space that can easily be \\hyperref[def:quiver_geometric_realization/embedding]{embedded} into \\( \\BbbR^2 \\). An obvious embedding corresponds to \\enquote{pulling up} \\( e_2 \\) and \\( e_3 \\):\n    \\begin{equation}\\label{eq:ex:def:quiver_geometric_realization/k3/embedding}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/ex__def__graph_geometric_realization.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    This is only one possible embedding of the geometric realization. It is sufficient, however, for proving that the graph is \\hyperref[def:quiver_geometric_realization/planar]{planar}. The underlying undirected graph is the \\hyperref[ex:complete_graph]{complete graph} \\( K_3 \\), hence we have shown that \\( K_3 \\) is also planar.\n\n    \\thmitem{ex:def:quiver_geometric_realization/k4} \\Cref{fig:ex:complete_graph} shows that the complete graph \\( K_4 \\) is planar.\n\n    This is not-at-all obvious from its geometric realization, however.\n    \\begin{equation}\\label{eq:ex:def:quiver_geometric_realization/k4/realization}\n      \\begin{aligned}\n        \\includegraphics[page=3]{output/ex__def__graph_geometric_realization.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    This example shows that constructing embeddings can be a tedious task.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:linear_quiver_equivalence}\n  If finite quiver is \\hyperref[def:quiver_geometric_realization/linear]{linear}, it has degree at most \\( 2 \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( Q = (V, A, t, h) \\) be a quiver and let \\( (\\mscrX, \\mscrT, R) \\) be its geometric realization. Let \\( f: \\mscrX \\to \\BbbR \\) be an injective continuous function, i.e. a topological embedding.\n\n  Suppose that the vertex \\( v \\) has degree larger than \\( 2 \\). It is sufficient to consider the case where \\( a \\), \\( b \\) and \\( c \\) are distinct arcs incident to \\( v \\).\n\n  We have\n  \\begin{equation*}\n    R(v) \\in R(a) \\cap R(b) \\cap R(c)\n  \\end{equation*}\n  thus\n  \\begin{equation*}\n    f(R(v)) \\in f(R(a)) \\cap f(R(b)) \\cap f(R(c))\n  \\end{equation*}\n\n  Since \\( R(a) \\), \\( R(b) \\) and \\( R(c) \\) are \\hyperref[def:connected_space]{connected}, so are their images under \\( f \\). If \\( f(R(a)) \\) has a point to the right of \\( f(R(v)) \\), then \\( f(R(b)) \\) must be left of \\( R(v) \\) and there remains nowhere to place \\( R(c) \\).\n\n  Therefore, \\( \\deg(v) \\leq 2 \\) and, since \\( v \\) was arbitrary, \\( \\deg(Q) \\leq 2 \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:quiver_can_be_embedded_into_r3}\n  Every finite quiver can be embedded into \\( \\BbbR^3 \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( Q = (V, A, t, h) \\) be a finite quiver of order \\( n \\). By definition of cardinality, there exists a bijection from \\( n \\) to \\( V \\).\n\n  Place the vertices of \\( Q \\) along the \\hyperref[thm:moment_curve]{moment curve} by using \\( \\gamma(k) \\) as the position for the \\( k \\)-th vertex of \\( V \\). Then by \\fullref{thm:moment_curve}, no four of these points are \\hyperref[def:collinear_complanar]{complanar}. Hence, if we connect their vertices using a straight line where there is an arc, no two lines would intersect.\n\n  Therefore, this is an embedding.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:quiver_geometric_realization/properties}\n  Let \\( Q = (V, A, h, t) \\) be a \\hyperref[def:quiver]{quiver} and let \\( (\\mscrX, \\mscrT, R) \\) be its \\hyperref[def:quiver_geometric_realization]{geometric realization}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:quiver_geometric_realization/properties/isolated} A vertex \\( v \\in V \\) is isolated in \\( Q \\), i.e. has degree zero, if and only if \\( R(v) \\) is an isolated point of \\( \\mscrX \\).\n\n    \\thmitem{thm:def:quiver_geometric_realization/properties/t1} If \\( Q \\) is \\hyperref[def:hypergraph/degree]{locally finite}, then the space \\( (\\mscrX, \\mscrT) \\) satisfies the \\ref{def:separation_axioms/T1} separation axiom.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:quiver_geometric_realization/properties/isolated} For every isolated vertex \\( v \\), the point \\( R(v) = \\set{ (v, v) } \\) is isolated by definition.\n\n  Now suppose that \\( v \\) is not an isolated vertex. Then \\( R(v) \\) is defined differently in \\eqref{eq:def:quiver_geometric_realization}. If there exists an arc \\( a \\) such that \\( v = h(a) \\), then \\( (a, 0) \\in R(v) \\) and hence there exists no neighborhood of \\( R(v) \\) disjoin from \\( R(a) \\), hence \\( R(v) \\) is not a disjoint point of \\( \\mscrX \\). The case \\( v = t(a) \\) is handled analogously.\n\n  \\SubProofOf{thm:def:quiver_geometric_realization/properties/t1} Let \\( x \\in \\mscrX \\).\n\n  If \\( x = \\set{ (t, a) } \\) for some arc \\( a \\) and \\( 0 < t < 1 \\), then \\( \\set{ x } \\) is closed because \\( [0, 1] \\) satisfies \\hyperref[def:separation_axioms/T1]{T1} and hence \\( \\set{ t } \\) is closed in \\( [0, 1] \\).\n\n  If \\( x = R(v) = \\set{ (v, v) } \\) for some isolated vertex \\( v \\), then \\( R(v) \\) is clopen by definition.\n\n  If \\( x = R(v) \\) for some vertex \\( v \\) of positive degree, then\n  \\begin{equation*}\n    R(v) = \\set[\\Big]{ (0, a) \\given h(a) = v } \\cup \\set[\\Big]{ (1, a) \\given t(a) = v }.\n  \\end{equation*}\n\n  Both \\( \\set{ 0 } \\) and \\( \\set{ 1 } \\) are closed in \\( [0, 1] \\), hence \\( \\set{ 0, 1 } \\) is also closed in \\( [0, 1] \\). Since \\( Q \\) is locally finite, \\( R(v) \\) is the union of finitely many closed sets and is thus itself closed.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:undirected_multigraph_geometric_realizations_homeomorphic}\n  Let \\( G = (V, E, \\mscrE) \\) be an \\hyperref[def:undirected_multigraph]{undirected multigraph}.\n\n  Let \\( (\\mscrX_c, \\mscrT_c, R_c) \\) and \\( (\\mscrX_d, \\mscrT_d, R_d) \\) be geometric realizations corresponding to the \\hyperref[def:multigraph_orientation]{orientations} \\( O_c(G) \\) and \\( O_d(G) \\) of \\( G \\).\n\n  Then \\( (\\mscrX_c, \\mscrT_c) \\) and \\( (\\mscrX_c, \\mscrT_d) \\) are homeomorphic.\n\\end{proposition}\n\\begin{proof}\n  Let \\( h_c \\) and \\( h_d \\) be the head functions from the \\hyperref[def:quiver]{quivers} \\( O_c(G) \\) and \\( O_d(G) \\).\n\n  Define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: \\mscrX_c \\to \\mscrX_d \\\\\n      &f(x) \\coloneqq \\begin{cases}\n        \\set[\\Big]{ (0, e) \\given h_d(e) = v } \\cup \\set[\\Big]{ (1, e) \\given t_d(e) = v }, &x = R_c(v) \\T{and} \\deg(v) > 0 \\\\\n        \\set[\\Big]{ (e, 1 - t) },                                                           &x = \\set{ (e, t) } \\T{and} h_c(e) \\neq h_d(e) \\\\\n        x,                                                                                  &\\T{otherwise.}\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  This function \\enquote{reverses} the direction of some of the intervals in the construction of the realizations and fixes everything else in place. It is clearly bijective. It is also continuous because it satisfies \\fullref{def:global_continuity/closure}. Finally, it is a homeomorphism because the inverse function is defined in the same way by interchanging \\( c \\) and \\( d \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:quiver_geometric_realization_paths}\n  Let \\( Q = (V, A, h, t) \\) be a \\hyperref[def:quiver]{quiver} and let \\( (\\mscrX, \\mscrT, R) \\) be its \\hyperref[def:quiver_geometric_realization]{geometric realization}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:quiver_geometric_realization_paths/quiver_to_realization} If there exists an \\hyperref[def:quiver_path/undirected]{undirected path} \\( p = (v, e_1, \\ldots, e_n) \\) from \\( s \\) to \\( f \\), then there exists a \\hyperref[def:parametric_curve]{continuous path} \\( \\gamma: [0, 1] \\to \\mscrX \\) from \\( R(s)  \\) to \\( R(f) \\).\n\n    \\thmitem{thm:quiver_geometric_realization_paths/realization_to_quiver} If \\( Q \\) is finite and if there exists a simple continuous path \\( \\gamma: [0, 1] \\to \\mscrX \\) from \\( R(s)  \\) to \\( R(f) \\), then there exists a simple undirected path from \\( s \\) to \\( f \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  The case \\( s = f \\) is trivial, hence we assume that \\( s \\neq f \\).\n\n  \\SubProofOf{thm:quiver_geometric_realization_paths/quiver_to_realization} Suppose that \\( p \\) is an undirected path from \\( s \\) to \\( f \\). We will use \\hyperref[rem:induction/well_founded]{strong induction} on the length of \\( p \\) to show that there exists a continuous path between the points \\( R(s) \\) and \\( R(f)  \\) of \\( \\mscrX \\).\n\n  Suppose that the statement holds for paths of length smaller than \\( n \\) and let\n  \\begin{equation*}\n    p = (v, e_1, \\ldots, e_{n-1}, e_n)\n  \\end{equation*}\n  be a path of length \\( n \\) from some vertex \\( s \\) to \\( f \\). The inductive hypothesis holds for the initial segment \\( (e_1, \\ldots, e_{n-1}) \\) of \\( p \\), hence there exists a continuous path \\( \\gamma: [0, 1] \\to \\mscrX \\) from \\( s \\) to an endpoint of \\( e_{n-1} \\).\n  \\begin{itemize}\n    \\item If both \\( e_{n-1} \\) and \\( e_n \\) are positively oriented, then \\( t(e_{n-1}) = h(e_n) \\) and thus \\( \\gamma \\) is a continuous path from \\( R(s)  \\) to \\( R(h(e_n)) \\). We can then append to \\( \\gamma \\) the continuous path from \\( R(h(e_n)) \\) to \\( R(t(e_n)) = R(f)  \\) to obtain a path from \\( R(s)  \\) to \\( R(f)  \\).\n\n    \\item If \\( e_{n-1} \\) is positively oriented but \\( e_n \\) is not, then \\( \\gamma \\) is a continuous path from \\( R(s)  \\) to \\( R(h(e_{n-1})) \\). We can then append to \\( \\gamma \\) the paths from \\( R(h(e_{n-1})) \\) to \\( R(t(e_{n-1})) = R(t(e_n)) \\) and from \\( R(t(e_n)) \\) to \\( R(h(e_n)) = R(f)  \\).\n\n    \\item Similarly, if \\( e_{n-1} \\) is negatively oriented but \\( e_n \\) is not, then \\( \\gamma \\) is a continuous path from \\( R(s)  \\) to \\( R(t(e_{n-1})) \\), and we can append to it the paths from \\( R(t(e_{n-1})) \\) to \\( R(h(e_{n-1})) = R(h(e_n)) \\) and from \\( R(h(e_n)) \\) to \\( R(t(e_n)) \\).\n\n    \\item Finally, if both \\( e_{n-1} \\) and \\( e_n \\) are negatively oriented, then \\( \\gamma \\) is a continuous path from \\( R(s)  \\) to \\( R(t(e_{n-1})) \\), and we can append to it the paths from \\( R(t(e_{n-1})) \\) to \\( R(h(e_{n-1})) = R(t(e_n)) \\) and from \\( R(t(e_n)) \\) to \\( R(h(e_n)) = R(f)  \\).\n  \\end{itemize}\n\n  We have shown that there exists a continuous path from \\( R(s) \\) to \\( R(f)  \\).\n\n  \\SubProofOf{thm:quiver_geometric_realization_paths/realization_to_quiver} Suppose that \\( Q \\) is finite and let \\( \\gamma: [0, 1] \\to \\mscrX \\) be a continuous path from \\( R(s) \\) to \\( R(f) \\). We will show that there is an undirected path from \\( s \\) to \\( f \\).\n\n  \\SubProof*{\\( \\gamma \\) contains no isolated vertices} We have\n  \\begin{equation}\\label{eq:thm:quiver_geometric_realization_paths/full_preimage}\n    \\gamma^{-1}(\\mscrX) = \\bigcup_{a \\in A} \\gamma^{-1}(R(a)) \\cup \\bigcup_{\\mathclap{\\deg(v) = 0}} \\gamma^{-1}(R(v)).\n  \\end{equation}\n\n  For each arc \\( a \\), the set \\( R(a) \\) is closed as a homeomorphic image of the unit interval \\( [0, 1] \\). From \\fullref{thm:def:quiver_geometric_realization/properties/t1} it follows that \\( \\set{ R(v) } \\) is a closed set for every vertex \\( v \\in V \\). Therefore, \\( \\gamma^{-1}(\\mscrX) \\) is a union of disjoint closed sets.\n\n  If we assume that \\( \\gamma \\) passes through an isolated vertex \\( v \\), then \\( \\gamma^{-1}(v) \\) would be a nonempty closed set. Then \\( \\img(\\gamma) = \\set{ v } \\) because otherwise \\( [0, 1] \\) would be the union of finitely many nonempty disjoint closed sets, which would contradict \\fullref{def:connected_space/closed_union} because \\( [0, 1] \\) is \\hyperref[def:connected_space]{connected}.\n\n  But \\( \\gamma \\) passes through at least two vertices because \\( s \\neq t \\), and hence it doesn't pass through any isolated vertex.\n\n  \\SubProof*{\\( \\gamma \\) contains the entirety of each arc it intersects} Suppose that \\( R(a) \\cap \\img(\\gamma) = \\varnothing \\) for some arc \\( a \\).\n\n  Let \\( l \\coloneqq \\inf\\set{ 0 < t < 1 \\given \\gamma(t) \\in R(a) } \\) and \\( r \\coloneqq \\sup\\set{ 0 < t < 1 \\given \\gamma(t) \\in R(a) } \\). The closed interval \\( [l, r] \\) is compact, hence \\( \\gamma([l, r]) \\) is a continuous image of a compact set and hence is itself compact.\n\n  Since \\( \\Int R(a) \\) is a subset of \\( \\gamma([l, r]) \\) and since \\( \\gamma([l, r]) \\) is closed, its closure \\( R(a) \\) is also a subset of \\( \\gamma([l, r]) \\).\n\n  Therefore, if an internal point of an arc belongs to \\( \\img(\\gamma) \\), so does the entire arc.\n\n  \\SubProof*{\\( \\gamma \\) contains an arc} From \\eqref{eq:thm:quiver_geometric_realization_paths/full_preimage} if follows that\n  \\begin{equation*}\n    \\gamma^{-1}(\\mscrX)\n    =\n    \\bigcup_{a \\in A} \\gamma^{-1}(R(a))\n    \\reloset{\\ref{thm:topological_closure_operator_axioms/CO3}} =\n    \\cl\\parens*{ \\bigcup_{a \\in A} \\gamma^{-1}(\\Int R(a)) }.\n  \\end{equation*}\n\n  Hence, \\( \\img(\\gamma) \\) contains at least one internal point of some arc and thus the entire arc.\n\n  \\SubProof*{\\( \\gamma \\) induces an undirected path from \\( s \\) to \\( f \\)} We have that \\( \\gamma(0) = R(s) \\). By what we have already shown, \\( \\img(\\gamma) \\) contains no isolated points, hence \\( \\gamma \\) contains the set \\( R(a) \\), where \\( a \\) is some arc incident to \\( s \\).\n\n  Suppose that \\( h(a) = s \\). Then \\( p = (s, a) \\) is an undirected path from \\( s \\) to \\( t(a) \\). If \\( t(a) = f \\), the proof is finished. Otherwise, define\n  \\begin{equation*}\n    x_0 \\coloneqq \\sup\\set{ x \\in [0, 1] \\given \\gamma(x) = R(t(a)) }\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\delta: [0, 1] \\to \\mscrX, \\\\\n      &\\delta(x) \\coloneqq \\gamma(x_0 + (1 - x_0) x).\n    \\end{aligned}\n  \\end{equation*}\n\n  Then \\( \\delta \\) is a continuous path from \\( R(t(a)) \\) to \\( R(f) \\).\n\n  We now proceed by \\fullref{thm:bounded_transfinite_induction} bounded by the number of arcs to define an undirected path \\( p \\) from \\( s \\) to \\( f \\). Since the path \\( \\gamma \\) is simple, it does not intersect itself and hence the image of the arc \\( a \\) at each step will not be in \\( \\delta \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:quiver_geometric_realization_connectedness}\n  A finite \\hyperref[def:quiver]{quiver} is \\hyperref[def:quiver_connectedness/weak]{weakly connected} if and only if its \\hyperref[def:quiver_geometric_realization/undirected]{geometric realization} is \\hyperref[def:path_connected]{path connected}.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:quiver_geometric_realization_paths}.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:undirected_multigraph_geometric_realization_connectedness}\n  A finite \\hyperref[def:undirected_multigraph]{undirected multigraph} is \\hyperref[def:undirected_multigraph_connectedness]{connected} if and only if its \\hyperref[def:quiver_geometric_realization/undirected]{geometric realization} is a \\hyperref[def:path_connected]{path connected}.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:quiver_geometric_realization_connectedness}.\n\\end{proof}\n", "meta": {"hexsha": "dfe0a2b3594cf085b08255071dc4c74ffdef7a1b", "size": 19928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/graph_embedding.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/graph_embedding.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/graph_embedding.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": 72.9963369963, "max_line_length": 586, "alphanum_fraction": 0.6605279004, "num_tokens": 6465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.6996775412639843}}
{"text": "\\subsection{The Lanczos Tridiagonalization Step}\n\nGolub explains in \\cite{golub13} that one of the problems with the\nPower Method, is that it does not take advantage of the previously\ncalculated information. During the iterations of the Power Method, say\nuntil step $k$, we have calculated already the set of vectors\n$K(A,q_0,k) = \\{A\\vec{q_0},A\\vec{q_1},\\dots,A\\vec{q_k}\\}$; still, they\nare not used \nat all when looking for an estimate of the eigenvector. Such\nlimitation is addressed by the Lanczos Process, named after its\ncreator in 1950 (\\cite{lanczos1950}). The subspace spanned by the\n$K(A,q_0,k)$ is called Krylov Subspace of order $k$ \\footnote{The\n  concept itself of Krylov Spaces is thanks for \n  Krylov and dates back to 1931 (see \\cite{krylov1931})}, which is why\nthe Lanczos Process is usually cataloged as a Krylov Subspace\nmethod.  \\\\\n\nGoing back to Lanczos, this subsection will only explain the iterative\nstep (called Lanczos Tridiagonalization Step). It works as follows; let us\nsuppose that we have an square symmetric matrix $A^{n \\times n}$, and\nthat we want a few of its biggest eigenvalues (as it is the case in LSI\napplications) \\footnote{The Lanczos Process can also calculate a few\n  of the smallest eigenvalues, but we are not interested in such case\n  for LSI applications.}. Each iteration $k$ of the algorithm generates a\ntridiagonal matrix $T_k \\in \\R{k \\times\n  k}$ \\footnote{Matrices with the middle, upper and lower\n  diagonals.}, and the whole sequence ${T_k}$ is  progressively \napproximating the biggest eigenvalues of the original matrix\n$A$. \\\\\n\nThere are several ways of stating the algorithm for the Lanczos\nTridiagonalization Step, the following is taken from Golub \\cite{golub13};\nthough it is not the the most numerically stable. That honor\ncorresponds to the ones created by Paige\n(\\cite{paige71},\\cite{paige76}); we preferred Golub's one for our\nexposition, aiming to have an easier introduction to the procedure: \n\n\\begin{algorithm}\n  \\label{alg:lanczos-step}\n  \\caption{The Lanczos Tridiagonalization Step}\n%\n  \\setstretch{1.5}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\DontPrintSemicolon\n%\n    \\Input{A unit vector $\\vec{q_1} \\in \\R{n}$ and a symmetric matrix $A^{n\n        \\times n}$}\n%\n    \\Output{The sequences $\\{\\alpha_i\\}$, $\\{\\beta_i\\}$ and matrix $Q\n      = [ \\vec{q_1} | \\vec{q_2} | \\cdots ]$ }\n%\n    $k \\gets 0, \\beta_0 \\gets 1, \\vec{q_0} \\gets 0, r_0 \\gets \\vec{q_1}$ \\;\n    \\While {$k = 0 \\lor \\beta_k \\ne 0$}\n    {\n      $\\vec{q_{k+1}} \\gets \\dfrac{\\vec{r_k}}{B_k}$ \\;\n      $k \\gets k + 1$ \\;\n      $\\alpha_k \\gets \\trans{\\vec{q_k}}A\\vec{q_k}$ \\;\n      $\\vec{r_k} \\gets A\\vec{q_k} - \\alpha_kq_k - \\beta_{k-1}\\vec{q_{k-1}}$ \\;\n      $\\beta_k \\gets \\norm{\\vec{r_k}}_2$ \\;\n    }\n%\n    return $(\\{\\alpha_i\\}, \\{\\beta_i\\}, \n             Q = [ \\vec{q_1} | \\vec{q_2} | \\cdots ])$ \\;\n\\end{algorithm}\n\\hfill\n\nThe \\cref{alg:lanczos-step} is essentially applying Gram-Schmidt process,\nbut only against the last two vectors. Golub derives the algorithm\nfrom a relation between tridiagonalization, and the QR factorization of\nthe matrix formed by vectors $K(A,q_0,k)$; see \\cite{golub13} for\nfurther details. \\\\\n\nGolub goes even further in the cited book, and proves the following\nproperties about \\cref{alg:lanczos-step}. We will omit the theorem\nstatement, and just comment directly its results: \\\\\n\n\\begin{itemize}\n  \\item The algorithm runs until $k = m = rank(K(A,q_0,k))$. This contrasts \n    with the unknown number of steps of the Power Method\n    (\\cref{alg:power-method}). \\\\\n\n  \\item For $k = 1:m$ we have $AQ_k = Q_kT_k + \\vec{r_k}\\trans{e_k}$,\n    where $Q = [\\vec{q_1} | \\cdots | \\vec{q_k} ]$ has orthonormal\n    columns that span the Krylov subspace $K(A,\\vec{q_1},k)$, and $e_k\n    = I_n(:,k)$ (the $k$ column of the identity matrix). This\n    justifies the orthogonalization step of the algorithm (line 6),\n    which only considers the last two vectors; whether that is enough to\n    guarantee that all the $\\vec{q}$\\apos{s} will be orthogonal is\n    certainly not evident, and gets proved on the same theorem. \\\\\n\n  \\item The matrix $T_k$ has tridiagonal shape, that is: \\\\\n    \\[\n    \\begin{bmatrix}\n      \\alpha_1 & \\beta_1 & \\cdots      & 0          \\\\\n      \\beta_1  & \\ddots  & \\ddots      & \\vdots     \\\\\n      \\vdots   & \\ddots  & \\ddots      & \\beta_{k-1} \\\\\n      0        & \\cdots  & \\beta_{k-1} & \\alpha_k\n    \\end{bmatrix}\n    \\]\n    \\hfill\n\n    This shape allows us to calculate its eigenvalues with much less\n    effort than for original matrix $A$ (which was the whole\n    motivation on the beginning). There are several options for such\n    calculation, but we will consider only the (implicit) QL Algorithm\n    (see \\cite{dubrulle71}), as that is the one used by Berry for his\n    famous routines in the context of LSI (see further\n    subsections). \n\\end{itemize}\n\\hfill\n\nIn addition to the above properties, which kind of guarantee the\n``correctness'' of the \\cref{alg:lanczos-step} (to some extent); Golub\nalso cites in \\cite{golub13} another theorem that establishes the\napproximation quality of matrix $T_k$ as a function of $k$. This is\nthe result that justifies our original claim that the sequence of\nmatrices $\\{T_k\\}$, approximates better the eigenvalues of $A$ as $k$\nincreases. \\\\\n\nFinally, Golub adds in \\cite{golub13} that not everything is flakes\nand honey with this \nalgorithm; the orthogonality that we expect on vectors \\vec{q}\\apos{s}\nis at jeopardy as $\\tilde{\\beta_k}$, the numerical approximation of\n$\\beta_k$, becomes really small; this is because that implies the\ncancellation of $\\vec{r_k}$). Main credit of this result goes again to\nPaige (\\cite{paige71},\\cite{paige76}), and we will come back to \nit on next subsection, when we show the full Lanczos Algorithm.\n\n\n\n", "meta": {"hexsha": "5c9fbe279c3788e76cc72b67c106ff29bf5c909b", "size": 5798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-lanczos-serial-step.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-lanczos-serial-step.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-lanczos-serial-step.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.9242424242, "max_line_length": 78, "alphanum_fraction": 0.699206623, "num_tokens": 1780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6996775309237148}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\nLet $V=\\R^{3}$ and let\n\\begin{equation*}\nW=\\sspan (S),  \\mbox{ where } S=\\set{\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n-2 \\\\\n2 \\\\\n-2\n\\end{mymatrix},\\begin{mymatrix}{r}\n-1 \\\\\n1 \\\\\n1\n\\end{mymatrix},\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n3\n\\end{mymatrix} }\n\\end{equation*}\nFind a basis of $W$ consisting of vectors in $S$.\n\n\\begin{sol}\nIn this case $\\dim (W)=1$ and a basis for $W$ consisting of vectors in $S$ can be obtained by taking any (non-zero) vector from $S$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 &1  \\\\\n1 & 1\n\\end{mymatrix}\n\\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix}\n\\]\nFind a basis for $\\ker (T)$ and $\\func{im} (T)$.\n\n\\begin{sol}\nA basis for $\\ker (T)$ is\n$\\set{\\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix} }$\nand a basis for $\\func{im} (T)$ is\n$\\set{\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix} }$. \\\\\nThere are many other possibilities for the specific bases, but in this case\n$\\dim (\\ker (T))=1 $ and $\\dim (\\func{im} (T))=1$.\n\\end{sol}\n\n\\end{ex}\n\n\\begin{ex}\n Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0  \\\\\n1 & 1\n\\end{mymatrix}\n\\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix}\n\\]\nFind a basis for $\\ker (T)$ and $\\func{im}\n(T)$.\n\n\\begin{sol}\nIn this case $\\ker (T) =\\set{0}$\nand $\\func{im} (T) = \\R^2$ (pick any basis of $\\R^2$).\n\\end{sol}\n\n\\end{ex}\n\n\\begin{ex}\nLet $V=\\R^{3}$ and let\n\\begin{equation*}\nW=\\sspan\\set{\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n-1 \\\\\n2 \\\\\n-1\n\\end{mymatrix} }\n\\end{equation*}\nExtend this basis of $W$ to a basis of $V$.\n\n\\begin{sol}\nThere are many possible such extensions, one is (how do we know?):\n\\begin{equation*}\n\\set{\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n-1 \\\\\n2 \\\\\n-1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n0  \\\\\n0\\\\\n1\n\\end{mymatrix}\n}\n\\end{equation*}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny \\\\\nz\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 1 & 1 \\\\\n1 & 1 & 1\n\\end{mymatrix}\n\\begin{mymatrix}{r}\nx\\\\\ny \\\\\nz\n\\end{mymatrix}\n\\]\nWhat is $\\dim  ( \\ker (T) )$?\n\n\\begin{sol}\nWe can easily see that $\\dim  ( \\func{im} (T) ) =1$, and thus\n$\\dim  ( \\ker (T) ) = 3 - \\dim  ( \\func{im} (T) ) = 3- 1 = 2$.\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "2257f4d89d45ad2c9996faac4fbbd3c4e1cf0678", "size": 2405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/LinearTransformations-KernelImage.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/VectorSpaces-LinearTransformations-KernelImage.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/VectorSpaces-LinearTransformations-KernelImage.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 15.9271523179, "max_line_length": 132, "alphanum_fraction": 0.6012474012, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430353105599, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.6996775253080721}}
{"text": "\n\nThe description of \\textit{Fuzzy Logic} has been used by Lotfi A. Zadeh for the very first time within his famous published paper \"Fuzzy Sets\" .\n\nZadeh defined Fuzzy Logic ' a kind of logic using graded or qualified statements rather than ones that are strictly true or false . The results of fuzzy reasoning are not as definite as those derived by strict logic but they cover a larger field of discourse ' \\cite{lotfi}  .\n\nFuzzy logic doesn't represents the logic that is fuzzy but the idea that all things can be a member of any cluster at least partly member. The idea behind fuzzy logic describes that all transmissions between clusters (memberhsips) are not so strict that you can change memberships just between 0 and 1. There are also soft and mid transitions between 0-1 .\n\nTo understand fuzzy logic we ought get into crisp sets too. In short comparision of \\textit{Crispt Sets}  and \\textit{Fuzzy Sets} both sets are questioning the classical \"tall men\" problem's memberships according to height of men (See Fig. \\ref{fig:comparison})   .\n\n\\subsection{Crisp Sets and Fuzzy Sets}\n\nIn crisp sets theory a member can be in only one set. For example, for the relationship with the set “A”, the characteristic function gives us 1 (true) if an element named “u” is the member of the set “A” or 0 (false) if an element named “u” is not the member of the set “A” in the crisp logic \\cite{Kasabov:1996:FNN:525657}. Hence, this logic cannot represent vague and ambiguous solutions of any paradoxes.\n\nIn fuzzy set theory all elements can be definitely true or false and partly true or false. Fuzzy Logic uses the continuum of logical values between 0 and 1 . When you put your height(cm) in Fig.\\ref{fig:comparison} you can see that your degree of membership can be fractional and ambiguous .\n\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[scale=.3]{Images/crisp_and_fuzzy.png}\n    \\caption{Crisp and Fuzzy Sets of \"\\textit{tall men}\"}\n    \\label{fig:comparison}\n\\end{figure}\n\n\\subsection{Fundamentals of Fuzzy Logic} \n\nFundamentals of fuzzy decision making can be listed as : Fuzzification , inference and defuzzification.\n\n\n\n\\textit{1) Fuzzification}\n\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[scale=.55]{Images/fuzzification.png}\n    \\caption{Example of nonlinear scaling of an input measurement. \\cite{jantzen} }\n    \\label{fig:fig_fuzzification_jantzen}\n\\end{figure}\n\n\nFuzzification explains the process of converting every data to degrees of membership in one or more membership functions. The fuzzificaiton method thus matches the input data with the conditions of the rules . Every data has its own degree of memberships within a fuzzy set which can be explained with a linguistic term .\n\n\\textit{2) Inference}\n\nAfterwards of fuzzification an inference is made based on rules . The process which called 'inference' basicly combines all results that evaluated from each rule to obtain a final result. This output given after inference step is also called \\textit{fuzzy output set} .\n\n\n\\textit{3) Defuzzification}\n\nAfter the inference there will be fuzzy output sets. But , its not recognizable in real life . In order to make it usable and recognizable in real life  those values should be translated into real values. This translation named \\textit{defuzzification} \\cite{defuzzification} .\n\n", "meta": {"hexsha": "1feb1b54d9437893904303d68af506ab5b86f145", "size": 3324, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Texes/FuzzyLogicAndFuzzySet.tex", "max_stars_repo_name": "ertanturan/Using-artificial-intelligence-for-modeling-of-the-realistic-animal-behaviors-in-a-virtual-island", "max_stars_repo_head_hexsha": "c0389aeeaa900e5c28bff98498f3c9f3637ab2a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-06-27T06:21:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T11:05:04.000Z", "max_issues_repo_path": "Texes/FuzzyLogicAndFuzzySet.tex", "max_issues_repo_name": "ertanturan/Using-artificial-intelligence-for-modeling-of-the-realistic-animal-behaviors-in-a-virtual-island", "max_issues_repo_head_hexsha": "c0389aeeaa900e5c28bff98498f3c9f3637ab2a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Texes/FuzzyLogicAndFuzzySet.tex", "max_forks_repo_name": "ertanturan/Using-artificial-intelligence-for-modeling-of-the-realistic-animal-behaviors-in-a-virtual-island", "max_forks_repo_head_hexsha": "c0389aeeaa900e5c28bff98498f3c9f3637ab2a9", "max_forks_repo_licenses": ["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.7169811321, "max_line_length": 408, "alphanum_fraction": 0.7782791817, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6996775190456946}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[fleqn]{amsmath}\n\\usepackage{textcomp}\n\\usepackage{gensymb}\n\\usepackage{amsfonts}\n\\usepackage{enumitem}\n%\\usepackage{tikz}  % Include for figures.\n%\\usepackage{subfiles}  % Include for subfiles.\n\n\\newcommand{\\HOMEWORKNUM}{5}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-05-28}\n\n\\title{\\vspace{-4\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Let $A$ be the projection matrix that projects onto the plane\n$z = \\sqrt{3}y$ in $\\mathbb{R}^3$. \\\\ Find $A$.}\n\\\\[\\baselineskip]\nNote that $z = \\sqrt{3}y = \\tan(60 \\degree)y$.\n\\begin{gather*}\n\t\\begin{pmatrix} 1 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\\overset{A}{\\longrightarrow}\n\t\\begin{pmatrix} 1 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\\\\\n\t\\begin{pmatrix} 0 \\\\ 1 \\\\ 0 \\end{pmatrix}\n\t\\overset{A}{\\longrightarrow}\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\cos(60 \\degree) \\cos(60 \\degree) \\\\\n\t\t\\cos(60 \\degree) \\sin(60 \\degree)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\frac{1}{4} \\\\\n\t\t\\frac{\\sqrt{3}}{4}\n\t\\end{pmatrix}\n\t\\\\\n\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 1 \\end{pmatrix}\n\t\\overset{A}{\\longrightarrow}\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\cos(-30 \\degree) \\cos(60 \\degree) \\\\\n\t\t\\cos(-30 \\degree) \\sin(60 \\degree)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\frac{\\sqrt{3}}{4} \\\\\n\t\t\\frac{3}{4}\n\t\\end{pmatrix}\n\\end{gather*}\n\\begin{equation*}\n\tA =\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & 0 \\\\\n\t\t\t0 & \\frac{1}{4} & \\frac{\\sqrt{3}}{4} \\\\\n\t\t\t0 & \\frac{\\sqrt{3}}{4} & \\frac{3}{4}\n\t\t\\end{pmatrix}\n\t}\n\\end{equation*}\n\\newpage\n\n\\section*{2.}\n\\textit{Let $B$ be the reflection matrix over the plane\n$z = \\sqrt{3}y$ in $\\mathbb{R}^3$. \\\\ Find $B$.}\n\\\\[\\baselineskip]\nNote (still) that $z = \\sqrt{3}y = \\tan(60 \\degree)y$.\n\\begin{gather*}\n\t\\begin{pmatrix} 1 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\\overset{B}{\\longrightarrow}\n\t\\begin{pmatrix} 1 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\\\\\n\t\\begin{pmatrix} 0 \\\\ 1 \\\\ 0 \\end{pmatrix}\n\t\\overset{B}{\\longrightarrow}\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\cos(2 \\cdot 60 \\degree) \\\\\n\t\t\\sin(2 \\cdot 60 \\degree)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t-\\frac{1}{2} \\\\\n\t\t\\frac{\\sqrt{3}}{2}\n\t\\end{pmatrix}\n\t\\\\\n\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 1 \\end{pmatrix}\n\t\\overset{B}{\\longrightarrow}\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\cos(90 - 2 \\cdot 30 \\degree) \\\\\n\t\t\\sin(90 - 2 \\cdot 30 \\degree)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t\\frac{\\sqrt{3}}{2} \\\\\n\t\t\\frac{1}{2}\n\t\\end{pmatrix}\n\\end{gather*}\n\\begin{equation*}\n\tB =\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & 0 \\\\\n\t\t\t0 & -\\frac{1}{2} & \\frac{\\sqrt{3}}{2} \\\\\n\t\t\t0 & \\frac{\\sqrt{3}}{2} & \\frac{1}{2}\n\t\t\\end{pmatrix}\n\t}\n\\end{equation*}\n\n\\section*{3.}\n\\textit{With $A$ and $B$ from \\textbf{(1)} and \\textbf{(2)},\nfind the following.}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item $A^{100} \\begin{pmatrix} 1 \\\\ 1 \\\\ \\sqrt{3} \\end{pmatrix} =\n\tA \\begin{pmatrix} 1 \\\\ 1 \\\\ \\sqrt{3} \\end{pmatrix} = \n\t\\boxed{\n\t\t\\begin{pmatrix} 1 \\\\ 1 \\\\ \\sqrt{3} \\end{pmatrix}\n\t}$\n\t\\item $B \\begin{pmatrix} 1 \\\\ 1 \\\\ \\sqrt{3} \\end{pmatrix}  =\n\t\\boxed{\n\t\t\\begin{pmatrix} 1 \\\\ 1 \\\\ \\sqrt{3} \\end{pmatrix}\n\t}$\n\t\\item $B^3 \\begin{pmatrix} 10 \\\\ -\\sqrt{3} \\\\ 1 \\end{pmatrix} =\n\tB^2 B \\begin{pmatrix} 10 \\\\ -\\sqrt{3} \\\\ 1 \\end{pmatrix} =\n\tB \\begin{pmatrix} 10 \\\\ -\\sqrt{3} \\\\ 1 \\end{pmatrix} =\n\t\\boxed{\n\t\t\\begin{pmatrix} 10 \\\\ \\sqrt{3} \\\\ -1 \\end{pmatrix}\n\t}$\n\\end{enumerate}\n\n\\section*{4.}\n\\textit{Find the matrix that rotates space $30 \\degree$ about the y-axis in\n$\\mathbb{R}^3$.}\n\\\\[\\baselineskip]\nLet $\\text{Rot}_y(\\theta)$ be the rotation matrix where\n\\begin{equation*}\n\t\\text{Rot}_y(\\theta) =\n\t\\begin{pmatrix}\n\t\t\\cos \\theta & 0 & \\sin \\theta \\\\\n\t\t0 & 1 & 0 \\\\\n\t\t-\\sin \\theta & 0 & \\cos \\theta\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\n\\begin{equation*}\n\t\\text{Rot}_y(30 \\degree)\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(30 \\degree) & 0 & \\sin(30 \\degree) \\\\\n\t\t0 & 1 & 0 \\\\\n\t\t-\\sin(30 \\degree) & 0 & \\cos(30 \\degree)\n\t\\end{pmatrix}\n\t=\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{\\sqrt{3}}{2} & 0 & \\frac{1}{2} \\\\\n\t\t\t0 & 1 & 0 \\\\\n\t\t\t-\\frac{1}{2} & 0 & \\frac{\\sqrt{3}}{2}\n\t\t\\end{pmatrix}\n\t}\n\\end{equation*}\n\n\\end{document}", "meta": {"hexsha": "efa6d3e6213e20d288ad38b91e09b4f4acbbd1b3", "size": 4061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw05/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/hw05/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/hw05/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": 23.2057142857, "max_line_length": 75, "alphanum_fraction": 0.5900024624, "num_tokens": 1791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.6995374000362282}}
{"text": "\\subsection{Trees}\\label{subsec:trees}\n\nIn this section, we will regard the edges of simple undirected graphs as sets of unordered tuples and edges of simple directed graphs as sets of ordered tuples.\n\n\\begin{definition}\\label{def:tree}\n  The possibly infinite \\hyperref[def:undirected_multigraph]{simple undirected graph} \\( T= (E, V, \\mscrE) \\) is called a \\term{tree} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:tree/connected_acyclic} \\( T \\) is \\hyperref[def:undirected_multigraph_connectedness]{connected} and \\hyperref[def:undirected_multigraph_path/cycle]{acyclic}.\n    \\thmitem{def:tree/maximally_acyclic} \\( T \\) is \\term{maximally acyclic}, meaning that adding an edge between existing vertices would create a \\hyperref[def:undirected_multigraph_path/cycle]{cycle}.\n    \\thmitem{def:tree/minimally_connected} \\( T \\) is \\term{minimally connected}, meaning that removing an edge will make the graph \\hyperref[def:quiver_connectedness]{disconnected}.\n    \\thmitem{def:tree/single_path} For every pair of vertices in \\( T \\), there exists a unique \\hyperref[def:undirected_multigraph_path]{path} connecting them.\n\n    This condition motivates the definition of \\hyperref[def:arborescence]{arborescences}.\n  \\end{thmenum}\n\n  It is conventional to use the term \\term{node} for the vertices of a tree.\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:tree/connected_acyclic}{def:tree/maximally_acyclic} Suppose that \\( T \\) is connected and acyclic. There is always an edge not in \\( T \\) because the \\hyperref[ex:complete_graph]{complete graph} \\( K_V \\) contains cycles and \\( T \\) does not. Let \\( \\set{ u, v } \\) be an edge not in \\( T \\) and let \\( T' \\) be the supergraph that adjoins only this new edge.\n\n  Since \\( T \\) is connected, there exists a path \\( p \\) connecting \\( u \\) and \\( v \\). Appending the edge \\( \\set{ u, v } \\) to this path creates a cycle in \\( T' \\).\n\n  Therefore, \\( T' \\) is not acyclic.\n\n  \\ImplicationSubProof{def:tree/maximally_acyclic}{def:tree/connected_acyclic} Suppose that \\( T \\) is maximally acyclic. We will show that it is connected.\n\n  Suppose that \\( T \\) is not connected. Then there exist vertices \\( u \\) and \\( v \\) with no path between them. Let \\( T' \\) be the supergraph that adjoins only the edge \\( \\set{ u, v } \\).\n\n  Since there is no path between \\( u \\) and \\( v \\) in \\( T \\), \\( T' \\) is also acyclic. But this contradicts the maximality of \\( T \\).\n\n  Therefore, \\( T \\) is connected.\n\n  \\ImplicationSubProof{def:tree/connected_acyclic}{def:tree/minimally_connected} Suppose that \\( T \\) is connected and acyclic. Let \\( \\set{ u, v } \\) be any edge of \\( T \\) and let \\( T' \\) be the subgraph that does not contain this edge.\n\n  Suppose that \\( T' \\) is connected. Let \\( w \\) be any vertex and let \\( p \\) be a path in \\( T' \\) from \\( u \\) to \\( w \\). Then adding \\( \\set{ u, v } \\) creates a cycle in \\( T \\), which contradicts our assumption that \\( T \\) is acyclic.\n\n  Therefore, \\( T' \\) is not connected.\n\n  \\ImplicationSubProof{def:tree/minimally_connected}{def:tree/connected_acyclic} Suppose that \\( T \\) is minimally connected. We will show that it is acyclic.\n\n  Suppose that \\( T \\) has a cycle \\( p \\). We can thus remove any edge of \\( p \\) from \\( T \\) and the resulting subgraph will also be connected. This contradicts the minimality of \\( T \\).\n\n  Therefore, \\( T \\) is acyclic.\n\n  \\ImplicationSubProof{def:tree/connected_acyclic}{def:tree/single_path} Suppose that \\( T \\) is connected and acyclic. Since \\( T \\) is connected, there exists at least one path between any two vertices. Since it is acyclic, this path must be unique because otherwise we could easily create a cycle by joining two such paths.\n\n  \\ImplicationSubProof{def:tree/single_path}{def:tree/connected_acyclic} Suppose that, for every pair of vertices in \\( T \\), there exists a unique path connecting them. It is clear that \\( T \\) is connected.\n\n  Suppose that \\( T \\) has a cycle \\( p \\) from \\( u \\) to \\( u \\) passing through \\( v \\). We thus obtain two paths from \\( u \\) to \\( v \\) --- one not containing the first edge in \\( p \\) and one not containing the last edge. But this contradicts our assumption that any two paths from \\( u \\) to \\( v \\) are equal.\n\n  Therefore, \\( T \\) is acyclic.\n\\end{proof}\n\n\\begin{example}\\label{ex:def:tree}\n  The reduced infinite integer graphs \\eqref{eq:ex:infinite_integer_graphs/positive}, \\eqref{eq:ex:infinite_integer_graphs/negative} and \\eqref{eq:ex:infinite_integer_graphs/two_sided} from \\fullref{ex:infinite_integer_graphs} are simple examples of infinite trees.\n\n  Examples of finite trees are \\hyperref[def:proof_tree]{proof trees} from \\fullref{subsec:deductive_systems} and \\hyperref[def:concrete_syntax_tree]{concrete} and \\hyperref[def:abstract_syntax_tree]{abstract syntax trees} from \\hyperref[def:formal_grammar]{formal grammar}.\n\\end{example}\n\n\\begin{definition}\\label{def:arborescence}\\mcite[ch. 4, sec. 3.1]{GondranMinoux1984Graphs}\n  Let \\( T = (V, A) \\) be a \\hyperref[def:quiver/simple]{simple directed graph}. Suppose that there exists a vertex \\( r \\in V \\) such that for every other vertex \\( v \\in V \\), there exists a unique \\hyperref[def:quiver_path/directed]{directed path} from \\( r \\) to \\( v \\). The pair \\( (G, r) \\) is called a (directed) \\term{arborescence}. It is often more convenient to consider the triple \\( T = (V, A, r) \\) instead. The vertex \\( r \\) is called the \\term{root} of the arborescence.\n\n  \\begin{thmenum}\n    \\thmitem{def:arborescence/undirected} A \\hyperref[def:tree]{tree} with a distinguished vertex \\( r \\) is called a \\term{rooted tree}.\n\n    For every tree \\( T \\), as a consequence of \\fullref{def:tree/single_path}, every vertex \\( r \\) of \\( T \\) induces an \\hyperref[def:multigraph_orientation]{orientation} \\( O(T) \\) of \\( T \\) such that \\( O(T) \\) is an arborescence.\n\n    For this reason, we identify rooted trees with their induced arborescences.\n\n    \\thmitem{def:arborescence/depth} The \\term{depth} of a node \\( v \\) is the length of the path from \\( r \\) to \\( v \\). The term \\term{level} is also sometimes used but with a slightly different meaning --- the greater the depth, the lower the level.\n\n    \\thmitem{def:arborescence/ancestry} If \\( v \\) has a strictly greater depth than \\( u \\), we say that \\( u \\) is an \\term{ancestor} of \\( v \\) and that \\( v \\) is a \\term{descendant} of \\( u \\).\n\n    The ancestor of \\( v \\) at the lowest possible level is called the \\term{parent} of \\( v \\). If \\( u \\) is a parent of \\( v \\), \\( u \\) is a \\term{child} of \\( v \\). If a node has no children, we say that it is a \\term{leaf node}.\n\n    Finally, if \\( u \\) and \\( v \\) are on the same level, we call them \\term{siblings}.\n\n    \\thmitem{def:arborescence/height} The \\term{height} or \\term{depth} of the entire tree \\( T \\), if it exists, is the supremum of the depths of all nodes.\n\n    \\thmitem{def:arborescence/width} The \\term{width} or \\term{breadth} of the entire tree \\( T \\), if it exists, is the supremum of the number of siblings among all vertices. It is equal to the degree of \\( T \\) minus \\( 1 \\).\n\n    We use terminology similar to \\fullref{def:relation/arity}, e.g. \\enquote{binary tree}, \\enquote{ternary tree}, \\ldots.\n\n    \\thmitem{def:arborescence/sub-arborescence} A \\hyperref[def:quiver/submodel]{subgraph} of an arborescence that is itself an arborescence is called a \\term{sub-arborescence}. The same holds for rooted subtrees.\n\n    For every node \\( v \\) of \\( T \\), we define the \\term{induced sub-arborescence} of \\( T \\) with root \\( v \\) as the subgraph \\hyperref[def:quiver/submodel]{induced} by \\( V \\setminus \\dom(p) \\), where \\( p \\) is the unique path from \\( r \\) to \\( v \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{theorem}[K\\\"onig's lemma]\\label{thm:konigs_lemma}\n  Every \\hyperref[def:hypergraph/degree]{locally finite} \\hyperref[def:arborescence]{arborescence} of \\hyperref[def:hypergraph/order]{infinite} \\hyperref[def:hypergraph/order]{order} contains a \\hyperref[def:undirected_multigraph_path/simple]{simple path} of infinite length.\n\\end{theorem}\n\\begin{proof}\n  Let \\( T = (V, A, r) \\) be a locally finite infinite arborescence. We will build an infinite simple path\n  \\begin{equation*}\n    p = (p_1, p_2, \\cdots)\n  \\end{equation*}\n  using \\hyperref[rem:natural_number_recursion]{natural number recursion} starting at one. Let \\( c \\) be a \\hyperref[def:choice_function]{choice function} on the family\n  \\begin{equation*}\n    \\pow(V) \\setminus \\set{ \\varnothing }.\n  \\end{equation*}\n\n  Such a choice function exists by the \\hyperref[def:zfc/choice]{axiom of choice}.\n\n  \\begin{itemize}\n    \\item Since \\( T \\) is locally finite, there are finitely many children of \\( r \\). If we suppose that the \\hyperref[def:arborescence/sub-arborescence]{subarborescence} induced by \\( v \\) is finite for every child \\( v \\) of \\( r \\), then we would obtain that \\( T \\) itself is finite, which is a contradiction. Therefore, for at least one child, the induced sub-arborescence is infinite. Using the choice function \\( c \\), pick one such child and denote it by \\( v_1 \\).\n\n    Define \\( p_1 \\) to be the arc \\( r \\to v_1 \\).\n\n    \\item Fix \\( k > 1 \\). Using the same argument on the children of \\( t(e_{k-1}) \\), we can pick a child \\( v_k \\) that has an infinite induced sub-arborescence.\n\n    Define \\( e_k \\) to be the arc \\( t(e_{k-1}) \\to v_k \\). The path\n    \\begin{equation*}\n      (e_1, e_2, \\ldots, e_{k-1}, e_k)\n    \\end{equation*}\n    is simple by construction because \\( T \\) is an arborescence and thus contains no directed cycles.\n  \\end{itemize}\n\n  Thus, we have constructed an infinite simple path.\n\\end{proof}\n", "meta": {"hexsha": "22984cb3113574bff0faa055be8e031eef5ab417", "size": 9690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/trees.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/trees.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/trees.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": 80.0826446281, "max_line_length": 487, "alphanum_fraction": 0.6991744066, "num_tokens": 2910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8438951084436076, "lm_q1q2_score": 0.6995373984090033}}
{"text": "\\chapter{Lagrange's Equations of the Second Kind}\\label{c2}\n\\section{Generalised coordinates}\\label{c2s1}\nIn the previous chapter we observed that in a system of $N$ particles and $r$\nconstraints, the $3N$ virtual displacements $\\delta x^{(n)}_i$ are not \nindependent. Any subset of $f = 3N - r$ virtual displacements is independent. \n$f$ is called the \\emph{number of degrees of freedom} of the system.\n\nConsider a system of two particles connected by a rigid rod. The two particles\neach need three Cartesian coordinates. But the constraint makes only five of\nthem independent. It is not clear which five to choose. Although the lack of\nindependence of virtual displacements in all coordinates is taken into account\nby the Lagrange's equations of the first kind, one still has to describe the \nsystem in terms of $6$ coordinates. This situation gets worse in the case of\na rigid body. If it made up of $N$ particles then we need $3N$ coordinates to\ndescribe its position when only $6$ of them are independent.\n\nGeneralised coordinates are any $f$ numbers that suffice to describe the\nposition of a system of $f$ degrees of freedom. For example, a rigid body\nwith $N$ particles can be described by three Cartesian coordinates of its\ncentre of mass and three Euler angles. We shall denote the $f$ generalised\ncoordiates by $\\{q_1, \\ldots, q_f\\}$.\n\nLet us therefore consider a system of $N$ particles and $f$ degrees of freedom\nand let $q_1, \\ldots, q_f$ be its generalised coordinates. Then the Cartesian\ncoordinates of its particles can be written as\n\\begin{eqnarray}\nx_i &=& x_i(q_1, \\ldots, q_f, t) \\\\\ny_i &=& y_i(q_1, \\ldots, q_f, t) \\\\\nz_i &=& z_i(q_1, \\ldots, q_f, t).\n\\end{eqnarray}\nNote that the Cartesian coordinates of a particle are allowed to depend on \n\\emph{all} generalised coordinates. Unlike their Cartesian counterparts, the\ngeneralised coordinates are not tied to a single particle. Further, note that\nthe Cartesian coordinates may depend on time as well. From these equations\nwe have\n\\begin{eqnarray}\ndx_i &=& \\pd{x_i}{q_j}dq_j + \\pd{x_i}{t}dt \\\\\ndy_i &=& \\pd{y_i}{q_j}dq_j + \\pd{y_i}{t}dt \\\\\ndz_i &=& \\pd{z_i}{q_j}dq_j + \\pd{z_i}{t}dt\n\\end{eqnarray}\nWe have used the summation convention in these three equations. Although\nthe functional forms of $x_i, y_i, z_i$ are arbitrary, the differentials\n$dx_i, dy_i, dz_i$ are linear functions of $dq_j$ and $dt$.\n\nThe three Cartesian velocities are\n\\begin{eqnarray}\n\\dot{x}_i &=& \\pd{x_i}{q_j}\\dot{q}_j + \\pd{x_i}{t} \\label{c2s1e7} \\\\\n\\dot{y}_i &=& \\pd{y_i}{q_j}\\dot{q}_j + \\pd{y_i}{t} \\label{c2s1e8} \\\\\n\\dot{z}_i &=& \\pd{z_i}{q_j}\\dot{q}_j + \\pd{z_i}{t} \\label{c2s1e9}  \n\\end{eqnarray}\nNote that the symbol $\\dot{x}_i$ denotes the total time derivative of $x_i$ and\nit differs from $\\partial x_i/\\partial t$. The generalised coordinates, however,\ndo not depend explicitly on time. The kinetic energy of the system is\n\\begin{eqnarray}\nT &=& \\frac{1}{2}m_i(\\dot{x}_i^2 + \\dot{y}_i^2 + \\dot{z}_i^2) \\nonumber \\\\\n &=& \\frac{1}{2}m_i\\left(\\pd{x_i}{q_j}\\dot{q}_j + \\pd{x_i}{t}\\right)\n                   \\left(\\pd{x_i}{q_k}\\dot{q}_k + \\pd{x_i}{t}\\right) + \n     \\nonumber \\\\\n & & \\frac{1}{2}m_i\\left(\\pd{y_i}{q_j}\\dot{q}_j + \\pd{y_i}{t}\\right)\n                   \\left(\\pd{y_i}{q_k}\\dot{q}_k + \\pd{y_i}{t}\\right) + \n\t \\nonumber \\\\\n & & \\frac{1}{2}m_i\\left(\\pd{z_i}{q_j}\\dot{q}_j + \\pd{z_i}{t}\\right)\n                   \\left(\\pd{z_i}{q_k}\\dot{q}_k + \\pd{z_i}{t}\\right) \n\t \\label{c1s1e10} \n\\end{eqnarray}\nWe now compute the derivative of $T$ with respect to the generalised \nvelocity $\\dot{q}_l$.\n\\begin{eqnarray}\n\\pd{T}{\\dot{q}_l} &=& \n  m_i\\left(\\pd{x_i}{q_j}\\dot{q}_j + \\pd{x_i}{t}\\right)\\pd{x_i}{q_l} +\n m_i\\left(\\pd{y_i}{q_j}\\dot{q}_j + \\pd{y_i}{t}\\right)\\pd{y_i}{q_l} +\n  \\nonumber \\\\\n& &  m_i\\left(\\pd{z_i}{q_j}\\dot{q}_j + \\pd{z_i}{t}\\right)\\pd{z_i}{q_l} \n  \\label{c2s1e11} \n\\end{eqnarray}\nUsing equations \\eqref{c2s1e7}, \\eqref{c2s1e8} and \\eqref{c2s1e9} we get\n\\begin{equation}\\label{c2s1e12}\n\\pd{T}{\\dot{q}_l} = m_i\\left(\\dot{x}_i\\pd{x_i}{q_l} + \\dot{y}_i\\pd{y_i}{q_l} + \n \\dot{z}_i\\pd{z_i}{q_l}\\right).\n\\end{equation}\nWe now take the total time derivative of this equation.\n\\begin{eqnarray}\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) &=& \n  m_i\\left(\\ddot{x}_i\\pd{x_i}{q_l} + \\dot{x}_i\\frac{d}{dt}\n  \\left(\\pd{x_i}{q_l}\\right)\\right)  + \n  m_i\\left(\\ddot{y}_i\\pd{y_i}{q_l} + \\dot{y}_i\\frac{d}{dt}\n  \\left(\\pd{y_i}{q_l}\\right)\\right) + \\nonumber \\\\\n& & m_i\\left(\\ddot{z}_i\\pd{z_i}{q_l} + \\dot{z}_i\\frac{d}{dt}\n  \\left(\\pd{z_i}{q_l}\\right)\\right) \n\\end{eqnarray}\nEvaluating the total time derivatives on the right hand side,\n\\begin{eqnarray}\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) &=& \n m_i\\left(\\ddot{x}_i\\pd{x_i}{q_l} + \n \\dot{x}_i\\dot{q}_k\\frac{\\partial^2 x_i}{\\partial q_k\\partial q_l} +\n \\dot{x_i}\\frac{\\partial}{\\partial q_l}\\pd{x_i}{t}\\right) \\nonumber \\\\\n & & m_i\\left(\\ddot{y}_i\\pd{y_i}{q_l} + \n \\dot{y}_i\\dot{q}_k\\frac{\\partial^2 y_i}{\\partial q_k\\partial q_l} +\n \\dot{y_i}\\frac{\\partial}{\\partial q_l}\\pd{y_i}{t}\\right) \\nonumber \\\\\n & & m_i\\left(\\ddot{z}_i\\pd{z_i}{q_l} + \n \\dot{z}_i\\dot{q}_k\\frac{\\partial^2 z_i}{\\partial q_k\\partial q_l} +\n \\dot{z_i}\\frac{\\partial}{\\partial q_l}\\pd{z_i}{t}\\right) \\label{c2s1e14}\n\\end{eqnarray}\nWe now observe that\n\\[\n\\pd{\\dot{q_1}}{q_k} = \\frac{\\partial}{\\partial t}\\delta_{lk} = 0\n\\]\nso that we can write\n\\begin{eqnarray}\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) &=& \n m_i\\left(\\ddot{x}_i\\pd{x_i}{q_l} + \n \\dot{x}_i\\frac{\\partial}{\\partial q_l}\n \\left(\\dot{q}_k\\pd{x_i}{q_k} + \\pd{x_i}{t}\\right)\\right) \\nonumber \\\\\n & &  m_i\\left(\\ddot{y}_i\\pd{y_i}{q_l} + \n \\dot{y}_i\\frac{\\partial}{\\partial q_l}\n \\left(\\dot{q}_k\\pd{y_i}{q_k} + \\pd{y_i}{t}\\right)\\right) \\nonumber \\\\\n & &  m_i\\left(\\ddot{z}_i\\pd{z_i}{q_l} + \n \\dot{z}_i\\frac{\\partial}{\\partial q_l}\n \\left(\\dot{q}_k\\pd{z_i}{q_k} + \\pd{z_i}{t}\\right)\\right) \\label{c2s1e15}\n\\end{eqnarray}\nUsing equations \\eqref{c2s1e7}, \\eqref{c2s1e8} and \\eqref{c2s1e9} we get\n\\[\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) =\nm_i\\left[\\left(\\ddot{x}_i\\pd{x_i}{q_l} + \\dot{x}_i\\pd{\\dot{x}_i}{{q}_l}\\right) \n + \\nonumber \\\\\n\\left(\\ddot{y}_i\\pd{y_i}{q_l} + \\dot{y}_i\\pd{\\dot{y}_i}{{q}_l}\\right) \n + \\nonumber \\\\\n\\left(\\ddot{z}_i\\pd{z_i}{q_l} + \\dot{z}_i\\pd{\\dot{z}_i}{{q}_l}\\right)\\right].\n\\]\nRearranging it\n\\[\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) =\n\\pd{T}{q_l} + m_i\\left(\\ddot{x}_i\\pd{x_i}{q_l} +\n\\ddot{y}_i\\pd{y_i}{q_l} +\\ddot{z}_i\\pd{z_i}{q_l}\\right)\n\\]\nor\n\\begin{equation}\\label{c2s1e16}\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) - \\pd{T}{q_l} =\n m_i\\left(\\ddot{x}_i\\pd{x_i}{q_l} +\n \\ddot{y}_i\\pd{y_i}{q_l} +\\ddot{z}_i\\pd{z_i}{q_l}\\right)\n\\end{equation}\nMultiplying both sides by $\\delta q_l$,\n\\begin{equation}\\label{c2s1e17}\n\\left(\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) - \\pd{T}{q_l}\\right)\\delta q_l\n= m_i\\left(\\ddot{x}_i\\delta x_i + \\ddot{y}_i\\delta y_i +\n \\ddot{z}_i\\delta z_i\\right)\n\\end{equation}\nComparing with equation \\eqref{c1s2e13} we surmise that the left hand side\nof the above equation is\n\\begin{equation}\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) - \\pd{T}{q_l}\\delta q_l =\nX_i\\delta x_i + Y_i\\delta y_i + Z_i \\delta z_i,\n\\end{equation}\nwhere $(X_i, Y_i, Z_i)$ are components of the external force on the $i$th\nparticle. If this force is conservative, we can write it in terms of a \npotential $V$ as\n\\begin{eqnarray}\n\\frac{d}{dt}\\left(\\pd{T}{\\dot{q}_l}\\right) - \\pd{T}{q_l}\\delta q_l &=&\n\\pd{V}{x_i}\\delta x_i + \\pd{V}{z_i}\\delta y_i + \\pd{V}{z_i} \\delta z_i \\nonumber \\\\\n&=&\n\\pd{V}{x_i}\\pd{x_i}{q_l}\\delta q_l + \\pd{V}{z_i}\\pd{y_i}{q_l}\\delta q_l + \n\\pd{V}{z_i} \\pd{z_i}{q_l}\\delta q_l \\nonumber \\\\\n&=& \\pd{V}{q_1}\\delta q_l \\label{c1s1e20}\n\\end{eqnarray}\nNote that the last term here is not $3\\partial V/\\partial q_l$ because $V$\ndepends on all $x_1, \\ldots, z_N$ and each of these is a function of all \ngeneralised coordinates. If $V$ \\emph{does not} depend on generalised \nvelocities then we can write \\eqref{c1s1e20} as\n\\begin{equation}\\label{c2s1e21}\n\\frac{d}{dt}\\pd{L}{\\dot{q}_l} - \\pd{L}{q_l} = 0,\n\\end{equation}\nwhere the function\n\\begin{equation}\\label{c1s1e22}\nL(q_1, \\ldots, q_f, \\dot{q}_1, \\ldots, \\dot{q}_f) = T - V\n\\end{equation}\nis the Lagrangian of the system and equations \\eqref{c2s1e21} are called\nLagrange's equation of the second kind.\n\nA few remarks about \\eqref{c2s1e21}:\n\\begin{itemize}\n\\item Often times the phrase `second kind' is omitted and equations\nare called Lagrange's equations.\n\\item They equations are presently derived only for conservative forces.\n\\item They do not involve the forces of constraint. Neither do they insist on\nthe Cartesian coordinates. \n\\item They are valid in all frames of references. However $T$ depends on \ngeneralised velocities and will change across frames of reference. Therefore,\n$T$ should always be calculated with respect to an inertial frame of \nreference \\cite[p. 31]{akr}.\n\\end{itemize}\n\nProblems.\n\\begin{enumerate}\n\\item A uniform rod leans against a wall \\cite[Problem 1, chapter 4]{akr}.\nLet $l$ be its length. Its motion is confined to a plane. Its unconstrained\nmotion has three degrees of freedom, the position of its centre of mass and\nits orientation. In the present problem, the $x$ coordinate of its end\ntouching the wall is constrained to be $0$ and the $y$ coordinate of its \nend touching the floor is constrained to be $0$. Therefore, one generalised\ncoordinate suffices to describe the motion. \n\nWe choose $\\theta$ the (smaller) angle made by the rod with the $x$ axis. If\nthe rod is in the first quadrant then it makes and angle $\\pi -\\theta$ with\nthe positive $x$ axis.\n\nThe centre of the rod is at point $(0, l/2)$ when $\\theta = \\pi/2$ and it is\nat $(0, l/2)$ when $\\theta = 0$. It traces the arc of a circle of radius\n$l/2$ as the rod slides down the path.\n\nThe moment of inertia of the rod abouts its centre of mass is $ml^2/12$. \nTherefore, the rotational kinetic energy is\n\\[\nT_r = \\frac{I}{2}\\dot{\\theta}^2 = \\frac{m}{24}l^2\\dot{\\theta}^2\n\\]\nThe translational kinetic energy of its centre of mass is\n\\[\nT_c = \\frac{m}{2}v^2 = \\frac{m}{8}l^2\\dot{\\theta}^2\n\\]\nThe total kinetic energy is \n\\[\nT = \\frac{ml^2}{12}\\dot{\\theta}^2.\n\\]\n\nWe will now find the potential energy. If $dm$ is the mass element of the\nrod at a height $h$ then\n\\[\ndV = gy dm\n\\]\nIf $\\lambda$ be the linear mass density of the rod, $dm = \\lambda ds = mds/l$.\nThus,\n\\[\ndV = \\frac{mg}{l} yds = \\frac{mg}{l}y \\sqrt{(dx)^2 + (dy)^2} = \n\\frac{mg}{l}ydy\\sqrt{1 + \\left(\\frac{dx}{dy}\\right)^2}.\n\\]\nNow the equation of the straight line representing the rod is $y = y_0 -\n\\tan\\theta x$ so that \n\\[\n\\frac{dx}{dy} = \\cot\\theta\n\\]\nso that\n\\[\ndV = \\frac{mg}{l}\\csc\\theta ydy\n\\]\nor\n\\[\nV = \\int_{lsin\\theta}^0 dV = -\\frac{mg}{2}l\\sin\\theta.\n\\]\nTherefore, the Lagrangian is\n\\[\nL = \\frac{ml^2}{12}\\dot{\\theta}^2 + \\frac{mg}{2}l\\sin\\theta\n\\]\nand the equation of motion is\n\\[\n\\frac{ml^2}{6}\\ddot{\\theta} - \\frac{mgl}{2}\\cos\\theta = 0 \\Rightarrow\n\\frac{l}{3}\\ddot{\\theta} - g\\cos\\theta = 0 \\Rightarrow \\ddot{x} = \n\\frac{3g}{l}\\cos\\theta.\n\\]\n\n\\item An old model of the He atom consisted of a fixed nucleus and two\nelectrons on the opposite ends of the diameter of the circle centred at\nthe nucleus \\cite[Problem 3, chapter 4]{akr}. Without the constraints, the\nmotion of the two electrons in a plane would have required four coordinates.\nTheir constraints are:\n\\begin{itemize}\n\\item They are always at the opposite ends of a diameter. This means that\nwe can consider them to be end of a rigid, weightless rod.\n\\item Their centre of mass is fixed at the nucleus. This fixes the two \ncoordinates of their centre of mass.\n\\end{itemize}\nThis leaves the system with just one degree of freedom. If $\\theta$ is the\nangle made by one electron with the positive $x$ axis, the other electron\nmakes an angle $\\theta + \\pi/2$. If $m$ is the mass of the electrons, their\nkinetic energy is\n\\[\nT = \\frac{m}{2}r^2\\dot{\\theta}^2 + \\frac{m}{2}r^2\\dot{\\theta}^2 =\nmr^2\\dot{\\theta}^2.\n\\]\nTheir potential energy is\n\\[\nV = -\\frac{2e^2}{r} - \\frac{2e^2}{r} = -\\frac{4e^2}{r}\n\\]\nso that the Lagrangian is\n\\[\nL = mr^2\\dot{\\theta}^2 + \\frac{4e^2}{r^2}.\n\\]\nThe equation of motion is $\\ddot{\\theta} = 0$ or that $\\theta = \\alpha t + \n\\beta$, where $\\alpha$ and $\\beta$ are the initial conditions.\n\\end{enumerate}\n", "meta": {"hexsha": "0fee44a555c4e92180dde3b48f712a3d8122becf", "size": 12207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cm/lm/c2.tex", "max_stars_repo_name": "amey-joshi/physics", "max_stars_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cm/lm/c2.tex", "max_issues_repo_name": "amey-joshi/physics", "max_issues_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cm/lm/c2.tex", "max_forks_repo_name": "amey-joshi/physics", "max_forks_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2387543253, "max_line_length": 83, "alphanum_fraction": 0.6800196609, "num_tokens": 4617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545427, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.699537395310457}}
{"text": "\\section{Proposed method}\n\n\\begin{frame}{Proposed method}\n    Some mathematics formula\n    \\begin{equation}\n\t\tf(n) =\n            \\begin{cases}\n                n/2       & \\quad \\text{if } n \\text{ is even}\\\\\n                -(n+1)/2  & \\quad \\text{if } n \\text{ is odd}\n            \\end{cases}\n\t\\end{equation}\n\\end{frame}", "meta": {"hexsha": "715c168b4b138f0adb841360fc6981f49da64972", "size": 321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slide-presentation/proposed_method/proposed_method.tex", "max_stars_repo_name": "nhutnamhcmus/project-report-template", "max_stars_repo_head_hexsha": "8dec0d20f00959d1f29a476f6b52fbb3eb75eda3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slide-presentation/proposed_method/proposed_method.tex", "max_issues_repo_name": "nhutnamhcmus/project-report-template", "max_issues_repo_head_hexsha": "8dec0d20f00959d1f29a476f6b52fbb3eb75eda3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slide-presentation/proposed_method/proposed_method.tex", "max_forks_repo_name": "nhutnamhcmus/project-report-template", "max_forks_repo_head_hexsha": "8dec0d20f00959d1f29a476f6b52fbb3eb75eda3", "max_forks_repo_licenses": ["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.75, "max_line_length": 64, "alphanum_fraction": 0.5140186916, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6995002546609446}}
{"text": "%\\columnbreak\n\\section{Model Selection for Clustering}\n\n% ===\nWhat is the appropriate \\#clusters $k$ for my data?\n\n\\emph{General approach:} Measure quality (neg. log-likelihood) for different $k$ \\enspace $\\to$ \\textbf{elbow}.\n\n% ===\n\\subsection{Complexity-based Model Selection}\n\n\\textbf{Strategy:} add a complexity term to neg. log-likelihood\n\n\\textbf{Attention:} MDL/BIC rely on likelihood optimisation $\\to$ \\underline{not generally applicable}\n\n\n\\emph{Ocam's razor:}\\enspace\nChoose the model that provides the shortest description of the data.\n\n% ---\n\\subsubsection{Min. Description Length\\quad (MDL)}\n\nMinimise \\textbf{descr. length}:\\enspace\n$-\\log p(\\bm X\\mid \\theta) - \\log p(\\theta)$\n\nApprox.:\\enspace\n$\\hat k \\in \\arg\\min_k \\highlight*{-\\log p(\\bm X\\mid \\hat\\theta) + \\frac{k'}{2} \\log n}$\n\n% ---\n\\subsubsection{Bayesian Information Crit.\\quad (BIC)}\n\nParametrise likelihood $p(\\bm X\\mid M)$ by $\\theta$:\\\\\n\\enspace $p(\\bm X\\mid M) = \\int_{\\Theta_M} \\! \\exp(\\log p(\\bm X\\mid M, \\theta)) \\cdot p(\\theta\\mid M) \\diff\\theta$\n\nAssume flat prior $p(\\theta\\vert M) \\approx \\mathit{const}$ and\\\\\nexpand log-likelihood by ML estimator $\\hat\\theta$:\\\\\n$\\overline\\ell (\\theta) = \\frac{\\ell(\\theta)}{n} = \\frac1n \\log p(\\bm X\\vert M,\\theta) \\overset{\\text{i.i.d.}}{=} \\frac1n \\sum_i \\ell(\\theta, X_i) \\overset{\\textrm{Taylor}}{\\approx} \\ldots$\n\n$\\implies p(\\bm X\\mid M) = \\mathit{const}_2 \\cdot \\exp( \\highlight*{\\ell (\\hat\\theta) - \\frac{k'}{2} \\log n} )$\\\\\n\\quad where $k'$ : dimension of (trainable) parameters\n\n% ===", "meta": {"hexsha": "99cd49dc39d906ae49df8e6eb03173ffa849e99d", "size": 1520, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/08_model_selection.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/08_model_selection.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/08_model_selection.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": 36.1904761905, "max_line_length": 189, "alphanum_fraction": 0.6776315789, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6995002480642967}}
{"text": "\\section{Delta Method}%\n\\label{sec:delta_method}\n\n\\begin{thm}\n    If $\\sqrt{n}(T_n - \\theta) \\convl N(0, \\tau^2)$ and $f'(\\theta) \\ne 0$, then\n    \\begin{equation*}\n        \\sqrt{n}(f(T_n) - f(\\theta)) \\convl N(0, \\tau^2 [f'(\\theta)]^2).\n    \\end{equation*}\n\\end{thm}\n", "meta": {"hexsha": "cf2f56d5cf6d9e70217e070ed66401c6eb9bd51e", "size": 268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "statistics/inference/src/04-delta-method.tex", "max_stars_repo_name": "jems-lee/notes", "max_stars_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "statistics/inference/src/04-delta-method.tex", "max_issues_repo_name": "jems-lee/notes", "max_issues_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "statistics/inference/src/04-delta-method.tex", "max_forks_repo_name": "jems-lee/notes", "max_forks_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8, "max_line_length": 80, "alphanum_fraction": 0.5634328358, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6994348170442947}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{Homotopy pullbacks}\n\nSuppose we are given a map $f:A\\to B$, and type families $P$ over $A$, and $Q$ over $B$.\nThen any family of maps\n\\begin{equation*}\ng:\\prd{x:A}P(x)\\to Q(f(x))\n\\end{equation*}\ngives rise to a commuting square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n\\sm{x:A}P(x) \\arrow[r,\"{\\total[f]{g}}\"] \\arrow[d,swap,\"\\proj 1\"] & \\sm{y:B}Q(y) \\arrow[d,\"\\proj 1\"] \\\\\nA \\arrow[r,swap,\"f\"] & B\n\\end{tikzcd}\n\\end{equation*}\nwhere $\\total[f]{g}$ is defined as $\\lam{(x,y)}(f(x),g(x,y))$. In the main theorem of this chapter we show that $g$ is a family of equivalences if and only if this square satisfies a certain universal property: the universal property of \\emph{pullback squares}.\n\nPullback squares are of interest because they appear in many situations. Cartesian products, fibers of maps, and substitutions can all be presented as pullbacks. Moreover, the fact that a family of maps $g:\\prd{x:A}P(x)\\to Q(f(x))$ is a family of equivalences if and only if it induces a pullback square has the very useful corollary that a square of the form\n\\begin{equation*}\n  \\begin{tikzcd}\n    C \\arrow[d,swap,\"p\"] \\arrow[r] & D \\arrow[d,\"q\"] \\\\\n    A \\arrow[r,swap,\"f\"] & B\n  \\end{tikzcd}\n\\end{equation*}\nis a pullback square if and only if the induced family of maps between the fibers\n\\begin{equation*}\n  \\prd{x:A}\\fib{p}{x}\\to\\fib{q}{f(x)}\n\\end{equation*}\nis a family of equivalences. This connection between pullbacks and \\emph{fiberwise equivalences} has an important role in the descent theorem\\index{descent} in \\cref{chap:descent}.\n\nA second reason for studying pullback squares is that the dual notion of \\emph{pushouts} is an important tool to construct new types, including the $n$-spheres for arbitrary $n$. The duality of pullbacks and pushouts makes it possible to obtain proofs of many statements about pushouts from their dual statements about pullbacks.\n\n\\subsection{The universal property of pullbacks}\n\n\\begin{defn}\\label{defn:cospan}\n  A \\define{cospan}\\index{cospan|textbf} consists of three types $A$, $X$, and $B$, and maps $f:A\\to X$ and $g:B\\to X$.\n\\end{defn}\n\n\\begin{defn}\n  Consider a cospan\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[r,\"f\"] & X & B \\arrow[l,swap,\"g\"] \n    \\end{tikzcd}\n  \\end{equation*}\n  and a type $C$. A \\define{cone}\\index{cone!on a cospan|textbf} on the cospan $A \\rightarrow X \\leftarrow B$ with \\define{vertex} $C$\\index{vertex!of a cone|textbf} consists of maps $p:C\\to A$, $q:C\\to B$ and a homotopy $H:f\\circ p\\htpy g\\circ q$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      C \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] \\\\\n      A \\arrow[r,swap,\"f\"] & X\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. We write\\index{cone(C)@{$\\mathsf{cone}(\\blank)$}|textbf}\n\\begin{equation*}\n\\mathsf{cone}(C)\\defeq \\sm{p:C\\to A}{q:C\\to B}f\\circ p\\htpy g\\circ q\n\\end{equation*}\nfor the type of cones with vertex $C$.\n\\end{defn}\n\nIt is good practice to characterize the identity type of any type of importance. In the following lemma we give a characterization of the identity type of the type $\\mathsf{cone}(C)$ of cones on $A\\rightarrow X\\leftarrow B$ with vertex $C$. Such characterizations are entirely routine in homotopy type theory.\n\n\\begin{lem}\\label{lem:id_cone}%\n\\index{identity type!of cone@{of $\\mathsf{cone}(C)$}|textit}%\nLet $(p,q,H)$ and $(p',q',H')$ be cones on a cospan $f:A\\rightarrow X \\leftarrow B:g$, both with vertex $C$. Then the type $(p,q,H)=(p',q',H')$ is equivalent to the type of triples $(K,L,M)$ consisting of\n\\begin{align*}\nK & : p \\htpy p' \\\\\nL & : q \\htpy q'\n\\end{align*}\nand a homotopy $M : \\ct{H}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H'}$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nf\\circ p \\arrow[r,\"f\\cdot K\"] \\arrow[d,swap,\"H\"] & f\\circ p' \\arrow[d,\"{H'}\"] \\\\\ng\\circ q \\arrow[r,swap,\"g\\cdot L\"] & g\\circ q'\n\\end{tikzcd}\n\\end{equation*}\nof homotopies commutes.\n\\end{lem}\n\n\\begin{comment}\n\\begin{rmk}\nThe homotopy $M$ is a homotopy of homotopies, and for each $z:C$ the identification $M(z)$ witnesses that the square of identifications\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nf(p(z)) \\arrow[r,equals,\"\\ap{f}{K(z)}\"] \\arrow[d,equals,swap,\"H(z)\"] & f(p'(z)) \\arrow[d,equals,\"{H'(z)}\"] \\\\\ng(q(z)) \\arrow[r,equals,swap,\"\\ap{g}{L(z)}\"] & g(q'(z))\n\\end{tikzcd}\n\\end{equation*}\ncommutes. \n\\end{rmk}\n\\end{comment}\n\n\\begin{proof}\nBy the fundamental theorem of identity types (\\cref{thm:id_fundamental}) it suffices to show that the type\n\\begin{equation*}\n  \\sm{(p',q',H'):\\sm{p':C\\to A}{q':C\\to B}f\\circ p'\\htpy g \\circ q'}{K:p\\htpy p'}{L:q\\htpy q'} \\ct{H}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H'}\n\\end{equation*}\nis contractible. Using associativity of $\\Sigma$-types and commutativity of cartesian products, it is easy to show that this type is equivalent to the type\n\\begin{equation*}\n  \\sm{(p',K):\\sm{p':C\\to A}p\\htpy p'}\\sm{(q',L):\\sm{q':C\\to B}q\\htpy q'}\\sm{H:f\\circ p'\\htpy g \\circ q'}\\ct{H}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H'}\n\\end{equation*}\nNow we observe that the types $\\sm{p':C\\to A}p\\htpy p'$ and $\\sm{q':C\\to B}q\\htpy q'$ are contractible, with centers of contraction\n\\begin{samepage}\n\\begin{align*}\n(p,\\mathsf{htpy\\usc{}refl}_p) & : \\sm{p':C'\\to A} p\\htpy p' \\\\\n(q,\\mathsf{htpy\\usc{}refl}_q) & : \\sm{q':C'\\to B} q\\htpy q'.\n\\end{align*}%\n\\end{samepage}%\nThus we apply \\cref{ex:contr_in_sigma} to see that the type of tuples $((p',K),(q',L),(H',M))$ is equivalent to the type\n\\begin{equation*}\n\\sm{H':f\\circ p'\\htpy g\\circ q'} \\ct{H}{\\mathsf{htpy\\usc{}refl}_{g\\circ q}}\\htpy \\ct{\\mathsf{htpy\\usc{}refl}_{f\\circ p}}{H'}.\n\\end{equation*}\nOf course, the type $\\ct{H}{\\mathsf{htpy\\usc{}refl}_{g\\circ q}}\\htpy \\ct{\\mathsf{htpy\\usc{}refl}_{f\\circ p}}{H'}$ is equivalent to the type $H\\htpy H'$, and $\\sm{H':f\\circ p\\htpy g\\circ q} H\\htpy H'$ is contractible.\n\\end{proof}\n\nGiven a cone with vertex $C$ on a span $A\\stackrel{f}{\\rightarrow} X \\stackrel{g}{\\leftarrow} B$ and a map $h:C'\\to C$, we construct a new cone with vertex $C'$ in the following definition.\n\n\\begin{defn}\nFor any cone $(p,q,H)$ with vertex $C$ and any type $C'$, we define a map\\index{cone map@{$\\mathsf{cone\\usc{}map}$}|textbf}\n\\begin{equation*}\n\\mathsf{cone\\usc{}map}(p,q,H):(C'\\to C)\\to\\mathsf{cone}(C')\n\\end{equation*}\nby $h\\mapsto (p\\circ h,q\\circ h,H\\circ h)$. \n\\end{defn}\n\n\\begin{defn}\nWe say that a commuting 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$ is a \\define{pullback square}\\index{pullback square|textbf}, or that it is \\define{cartesian}\\index{cartesian square|textbf}, if it satisfies the \\define{universal property} of pullbacks\\index{universal property!of pullbacks}, which asserts that the map\n\\begin{equation*}\n\\mathsf{cone\\usc{}map}(p,q,H):(C'\\to C)\\to\\mathsf{cone}(C')\n\\end{equation*}\nis an equivalence for every type $C'$. \n\\end{defn}\n\nWe often indicate the universal property with a diagram as follows:\n\\begin{equation*}\n\\begin{tikzcd}\nC' \\arrow[drr,bend left=15,\"{q'}\"] \\arrow[dr,densely dotted,\"h\"] \\arrow[ddr,bend right=15,swap,\"{p'}\"] \\\\\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*}\nsince the universal property states that for every cone $(p',q',H')$ with vertex $C'$, the type of pairs $(h,\\alpha)$ consisting of $h:C'\\to C$ equipped with $\\alpha:\\mathsf{cone\\usc{}map}((p,q,H),h)=(p',q',H')$ is contractible by \\cref{thm:contr_equiv}.\n\nAs a corollary we obtain the following characterization of the universal property of pullbacks.\n\n\\begin{lem}\\label{thm:pullback_up}\nConsider a commuting 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$\nThen the following are equivalent:\\index{universal property!of pullbacks (characterization)|textit}\n\\begin{enumerate}\n\\item The square is a pullback square.\n\\item For every type $C'$ and every cone $(p',q',H')$ with vertex $C'$, the type of quadruples $(h,K,L,M)$ consisting of a map $h:C'\\to C$, homotopies\n\\begin{align*}\nK & : p\\circ h \\htpy p' \\\\\nL & : q\\circ h \\htpy q',\n\\end{align*}\nand a homotopy $M : \\ct{(H\\cdot h)}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H'}$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nf\\circ p\\circ h \\arrow[r,\"f\\cdot K\"] \\arrow[d,swap,\"H\\cdot h\"] & f\\circ p' \\arrow[d,\"{H'}\"] \\\\\ng\\circ q\\circ h \\arrow[r,swap,\"g\\cdot L\"] & g\\circ q'\n\\end{tikzcd}\n\\end{equation*}\ncommutes, is contractible.\n\\end{enumerate}\n\\end{lem}\n\n\\begin{proof}\nThe map $\\mathsf{cone\\usc{}map}(p,q,H)$ is an equivalence if and only if its fibers are contractible. By \\cref{lem:id_cone} it follows that the fibers of $\\mathsf{cone\\usc{}map}(p,q,H)$ are equivalent the the described type of quadruples ($h,K,L,M)$.\n\\end{proof}\n\nIn the following lemma we establish the uniqueness of pullbacks up to equivalence via a \\emph{3-for-2 property} for pullbacks.\n\n\\begin{lem}\\label{lem:pb_3for2}\\index{pullback!3-for-2 property|textit}\\index{3-for-2 property!of pullbacks|textit}%\nConsider the squares\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] & {C'} \\arrow[r,\"{q'}\"] \\arrow[d,swap,\"{p'}\"] & B \\arrow[d,\"g\"] \\\\\nA \\arrow[r,swap,\"f\"] & X & A \\arrow[r,swap,\"f\"] & X\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies $H:f\\circ p \\htpy g\\circ q$ and $H':f\\circ p'\\htpy g\\circ q'$.\nFurthermore, suppose we have a map $h:C'\\to C$ equipped with\n\\begin{align*}\nK & : p\\circ h \\htpy p' \\\\\nL & : q\\circ h \\htpy q' \\\\\nM & : \\ct{(H\\cdot h)}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H'}.\n\\end{align*}\nIf any two of the following three properties hold, so does the third:\n\\begin{samepage}%\n\\begin{enumerate}\n\\item $C$ is a pullback.\n\\item $C'$ is a pullback.\n\\item $h$ is an equivalence.\n\\end{enumerate}%\n\\end{samepage}%\n\\end{lem}\n\n\\begin{proof}\nBy the characterization of the identity type of $\\mathsf{cone}(C')$ given in \\cref{lem:id_cone} we obtain an identification\n\\begin{equation*}\n\\mathsf{cone\\usc{}map}((p,q,H),h)=(p',q',H')\n\\end{equation*}\nfrom the triple $(K,L,M)$. \nLet $D$ be a type, and let $k:D\\to C'$ be a map. We observe that\n\\begin{align*}\n\\mathsf{cone\\usc{}map}((p,q,H),(h\\circ k)) & \\jdeq (p\\circ (h\\circ k),q\\circ (h\\circ k),H\\circ (h\\circ k)) \\\\\n& \\jdeq ((p\\circ h)\\circ k,(q\\circ h)\\circ k, (H\\circ h)\\circ k) \\\\\n& \\jdeq \\mathsf{cone\\usc{}map}(\\mathsf{cone\\usc{}map}((p,q,H),h),k) \\\\\n& = \\mathsf{cone\\usc{}map}((p',q',H'),k).\n\\end{align*}\nThus we see that the triangle \n\\begin{equation*}\n\\begin{tikzcd}[column sep=-1em]\n(D\\to C') \\arrow[rr,\"{h\\circ \\blank}\"] \\arrow[dr,swap,\"{\\mathsf{cone\\usc{}map}(p',q',H')}\"] & & (D\\to C) \\arrow[dl,\"{\\mathsf{cone\\usc{}map}(p,q,H)}\"] \\\\\n& \\mathsf{cone}(D)\n\\end{tikzcd}\n\\end{equation*}\ncommutes. Therefore it follows from the 3-for-2 property of equivalences established in \\cref{ex:3_for_2}, that if any two of the maps in this triangle is an equivalence, then so is the third. Now the claim follows from the fact that $h$ is an equivalence if and only if $h\\circ\\blank : (D\\to C')\\to (D\\to C)$ is an equivalence for any type $D$, which was established in \\cref{lem:postcomp_equiv}.\n\\end{proof}\n\nPullbacks are not only unique in the sense that any two pullbacks of the same cospan are equivalent, they are \\emph{uniquely unique}\\index{uniquely uniqueness!of pullbacks} in the sense that the type of quadruples $(h,K,L,M)$ as in \\cref{lem:pb_3for2} is contractible.\n\n\\begin{cor}\nSuppose both commuting squares\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] & {C'} \\arrow[r,\"{q'}\"] \\arrow[d,swap,\"{p'}\"] & B \\arrow[d,\"g\"] \\\\\nA \\arrow[r,swap,\"f\"] & X & A \\arrow[r,swap,\"f\"] & X\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies $H:f\\circ p \\htpy g\\circ q$ and $H':f\\circ p'\\htpy g\\circ q'$ are pullback squares.\nThen the type of quadruples $(e,K,L,M)$ consisting of an equivalence $e:\\eqv{C'}{C}$ equipped with\n\\begin{align*}\nK & : p\\circ e \\htpy p' \\\\\nL & : q\\circ e \\htpy q' \\\\\nM & : \\ct{(H\\cdot h)}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H'}.\n\\end{align*}\nis contractible.\n\\end{cor}\n\n\\begin{proof}\nWe have seen that the type of quadruples $(h,K,L,M)$ is equivalent to the fiber of $\\mathsf{cone\\usc{}map}(p,q,H)$ at $(p',q',H')$. By \\cref{lem:pb_3for2} it follows that $h$ is an equivalence. Since $\\isequiv(h)$ is a proposition by \\cref{ex:isprop_isequiv}, and hence contractible as soon as it is inhabited, it follows that the type of quadruples $(e,K,L,M)$ is contractible. \n\\end{proof}\n\n\\subsection{Canonical pullbacks}\n\nFor every cospan we can construct a \\emph{canonical pullback}.\n\n\\begin{defn}\nLet $f:A\\to X$ and $g:B\\to X$ be maps. Then we define\n\\begin{align*}\nA\\times_X B & \\defeq \\sm{x:A}{y:B}f(x)=g(y) \\\\\n\\pi_1 & \\defeq \\proj 1 & & : A\\times_X B\\to A \\\\\n\\pi_2 & \\defeq \\proj 1\\circ\\proj 2 & & : A\\times_X B\\to B\\\\\n\\pi_3 & \\defeq \\proj 2\\circ\\proj 2 & & : f\\circ \\pi_1 \\htpy g\\circ\\pi_2.\n\\end{align*}\nThe type $A\\times_X B$ is called the \\define{canonical pullback}\\index{canonical pullback|textbf} of $f$ and $g$.\n\\end{defn}\n\nNote that $A\\times_X B$ depends on $f$ and $g$, although this dependency is not visible in the notation.\n\n\\begin{rmk}\n  Given $(x,y,p)$ and $(x',y',p')$ in the canonical pullback $A\\times_X B$, the identity type $(x,y,p)=(x',y',p')$ is equivalent to the type of triples $(\\alpha,\\beta,\\gamma)$ consisting of $\\alpha:x=x'$, $\\beta:y=y'$, and an identification $\\gamma:\\ct{p}{\\ap{g}{\\beta}}=\\ct{\\ap{f}{\\alpha}}{p'}$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=large]\n      f(x) \\arrow[r,equal,\"\\ap{f}{\\alpha}\"] \\arrow[d,swap,equal,\"p\"] & f(x') \\arrow[d,equal,\"{p'}\"] \\\\\n      g(y) \\arrow[r,swap,equal,\"\\ap{g}{\\beta}\"] & g(y')\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. The proof of this fact is similar to the proof of \\cref{lem:id_cone}.\n\\end{rmk}\n\n\\begin{thm}\\label{thm:canonical-pullback}\nGiven maps $f:A\\to X$ and $g:B\\to X$, the commuting square\\index{canonical pullback|textit}\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times_X B \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_1\"] & B \\arrow[d,\"g\"] \\\\\nA \\arrow[r,swap,\"f\"] & X,\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{thm}\n\n\\begin{proof}\nLet $C$ be a type. Our goal is to show that the map\n\\begin{equation*}\n\\mathsf{cone\\usc{}map}(\\pi_1,\\pi_2,\\pi_3): (C\\to A\\times_X B)\\to \\mathsf{cone}(C)\n\\end{equation*}\nis an equivalence. Note that we have the commuting triangle\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=-4em]\n    C\\to\\sm{x:A}{y:B}f(x)=g(y) \\arrow[dd,swap,\"\\mathsf{cone\\usc{}map}\"] \\arrow[dr,\"\\mathsf{choice}\"] \\\\\n    & \\sm{p:C\\to A}\\prd{z:C}\\sm{y:B} f(p(z))= g(y) \\arrow[dl,\"\\mathsf{choice}\"] \\\\\n    \\sm{p:C\\to A}{q:C\\to B} f\\circ p \\htpy g\\circ q.\n  \\end{tikzcd}\n\\end{equation*}\nIn this triangle the functions $\\mathsf{choice}$ are equivalences by \\cref{thm:choice}. Therefore, their composite is an equivalence.\n\\end{proof}\n\n\\begin{defn}\nGiven a commuting 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$, we define the \\define{gap map}\\index{gap map|textbf}\\index{pullback!gap map|textbf}\n\\begin{equation*}\n\\mathsf{gap}(p,q,H):C \\to A\\times_X B\n\\end{equation*}\nby $\\lam{z}(p(z),q(z),H(z))$.\n\\end{defn}\n\nThe following theorem provides a useful characterization of pullback squares, because in many situations it is easier to show that the gap map is an equivalence.\n\n\\begin{thm}\\label{thm:is_pullback}\nConsider a commuting 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$. The following are equivalent:\n\\begin{enumerate}\n\\item The square is a pullback square\n\\item There is a term of type\n\\begin{equation*}\n\\mathsf{is\\usc{}pullback}(p,q,H)\\defeq \\isequiv(\\mathsf{gap}(p,q,H)).\n\\end{equation*}\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  Observe that we are in the situation of \\cref{lem:pb_3for2}. Indeed, we have two commuting squares\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A\\times_X B \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_2\"] & B \\arrow[d,\"g\"] &[2em] C \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] \\\\\n      A \\arrow[r,swap,\"f\"] & X & A \\arrow[r,swap,\"f\"] & X,\n    \\end{tikzcd}\n  \\end{equation*}\n  and we have the gap map $\\mathsf{gap}:C\\to A\\times_X B$, which comes equipped with the homotopies\n\\begin{align*}\nK & : \\pi_1\\circ \\mathsf{gap} \\htpy p & K & \\defeq \\lam{z}\\refl{p(z)} \\\\\nL & : \\pi_2\\circ \\mathsf{gap} \\htpy q & L & \\defeq \\lam{z}\\refl{q(z)} \\\\\nM & : \\ct{(\\pi_3\\cdot \\mathsf{gap})}{(g\\cdot L)} \\htpy \\ct{(f\\cdot K)}{H} & M & \\defeq \\lam{z}\\mathsf{right\\usc{}unit}(H(z)).\n\\end{align*}\nSince $A\\times_X B$ is shown to be a pullback in \\cref{thm:canonical-pullback}, it follows from \\cref{lem:pb_3for2} that $C$ is a pullback if and only if the gap map is an equivalence.\n\\end{proof}\n\n\\subsection{Cartesian products and fiberwise products as pullbacks}\n\nAn important special case of pullbacks occurs when the cospan is of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r] & \\unit & B. \\arrow[l]\n\\end{tikzcd}\n\\end{equation*}\nIn this case, the pullback is just the \\emph{cartesian product}.\n\n\\begin{lem}\\label{lem:prod_pb}\nLet $A$ and $B$ be types. Then the square\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times B \\arrow[r,\"\\proj 2\"] \\arrow[d,swap,\"\\proj 1\"] & B \\arrow[d,\"\\mathsf{const}_{\\ttt}\"] \\\\\nA \\arrow[r,swap,\"\\mathsf{const}_{\\ttt}\"] & \\unit\n\\end{tikzcd}\n\\end{equation*}\nwhich commutes by the homotopy $\\mathsf{const}_{\\refl{\\ttt}}$ is a pullback square.\\index{cartesian product!as pullback}\n\\end{lem}\n\n\\begin{proof}\nBy \\cref{thm:is_pullback} it suffices to show that\n\\begin{equation*}\n\\mathsf{gap}(\\proj 1,\\proj2,\\lam{(a,b)}\\refl{\\ttt})\n\\end{equation*}\nis an equivalence. Its inverse is the map $\\lam{(a,b,p)}(a,b)$.\n\\end{proof}\n\nThe following generalization of \\cref{lem:prod_pb} is the reason why pullbacks are sometimes called \\define{fiber products}\\index{fiber product|textbf}.\n\n\\begin{thm}\nLet $P$ and $Q$ be families over a type $X$. Then the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=8em]\n\\sm{x:X}P(x)\\times Q(x) \\arrow[r,\"{\\lam{(x,(p,q))}(x,q)}\"] \\arrow[d,swap,\"{\\lam{(x,(p,q))}(x,p)}\"] & \\sm{x:X}Q(x) \\arrow[d,\"\\proj 1\"] \\\\\n\\sm{x:X}P(x) \\arrow[r,swap,\"\\proj 1\"] & X,\n\\end{tikzcd}\n\\end{equation*}\nwhich commutes by the homotopy\n\\begin{equation*}\nH\\defeq \\lam{(x,(p,q))}\\refl{x},\n\\end{equation*}\nis a pullback square.\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{thm:is_pullback} it suffices to show that the gap map is an equivalence. The gap map is homotopic to the function\n\\begin{equation*}\n\\lam{(x,(p,q))}((x,p),(x,q),\\refl{x}).\n\\end{equation*}\nIt is easy to check that this function is an equivalence. I\nts inverse is the map \n\\begin{equation*}\n\\lam{((x,p),(y,q),\\alpha)}(y,(\\mathsf{tr}_P(\\alpha,p),q)).\\qedhere\n\\end{equation*}\n\\end{proof}\n\n\\begin{cor}\nFor any $f:A\\to X$ and $g:B\\to X$, the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=8em]\n\\sm{x:X}\\fib{f}{x}\\times\\fib{g}{x} \\arrow[r,\"{\\lam{(x,((a,p),(b,q)))}b}\"] \\arrow[d,swap,\"{\\lam{(x,((a,p),(b,q)))}a}\"] & B \\arrow[d,\"g\"]  \\\\\nA \\arrow[r,swap,\"f\"] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{cor}\n\n\\subsection{Fibers of maps as pullbacks}\n\n\\begin{lem}\\label{lem:fib_pb}\nFor any function $f:A\\to B$, and any $b:B$, consider the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n\\fib{f}{b} \\arrow[r,\"\\mathsf{const}_\\ttt\"] \\arrow[d,swap,\"\\proj 1\"] & \\unit \\arrow[d,\"\\mathsf{const}_b\"] \\\\\nA \\arrow[r,swap,\"f\"] & B\n\\end{tikzcd}\n\\end{equation*}\nwhich commutes by $\\proj 2 : \\prd{t:\\fib{f}{b}} f(\\proj 1(t))=b$. This is a pullback square.\\index{fiber!as pullback|textit}\n\\end{lem}\n\n\\begin{proof}\nBy \\cref{thm:is_pullback} it suffices to show that the gap map is an equivalence. The gap map is homotopic to the function\n\\begin{equation*}\n\\mathsf{total}(\\lam{x}{p}(\\ttt,p))\n\\end{equation*}\nThe map $\\lam{x}{p}(\\ttt,p)$ is a family of equivalences by \\cref{ex:contr_in_sigma}, so it induces an equivalence on total spaces by \\cref{thm:fib_equiv}.\n\\end{proof}\n\n\\begin{cor}\nFor any type family $B$ over $A$ and any $a:A$ the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\nB(a) \\arrow[d,swap,\"{\\lam{y}(a,y)}\"] \\arrow[r,\"\\mathsf{const}_\\ttt\"] & \\unit \\arrow[d,\"\\lam{\\ttt}a\"] \\\\\n\\sm{x:A}B(x) \\arrow[r,swap,\"\\proj 1\"] & A\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{cor}\n\n\\begin{proof}\n  To see this, note that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      B(a) \\arrow[rr,\"{\\lam{b}((a,b),\\refl{a})}\"] \\arrow[dr,swap,\"\\mathsf{gap}\"] & & \\fib{\\proj 1}{a} \\arrow[dl,\"\\mathsf{gap}\"] \\\\\n      & \\Big(\\sm{x:A}B(x)\\Big)\\times_A\\unit.\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the top map is an equivalence by \\cref{ex:fib_replacement}, and the map on the right is an equivalence by \\cref{lem:fib_pb}, it follows that the map on the left is an equivalence. The claim follows.\n\\end{proof}\n\n\\subsection{Families of equivalences}\n\n\\begin{lem}\\label{lem:pb_subst}\nLet $f:A\\to B$, and let $Q$ be a type family over $B$. Then the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=6em]\n\\sm{x:A}Q(f(x)) \\arrow[r,\"{\\lam{(x,q)}(f(x),q)}\"] \\arrow[d,swap,\"\\proj 1\"] & \\sm{y:B}Q(b) \\arrow[d,\"\\proj 1\"] \\\\\nA \\arrow[r,swap,\"f\"] & B\n\\end{tikzcd}\n\\end{equation*}\ncommutes by $H\\defeq \\lam{(x,q)}\\refl{f(x)}$. This is a pullback square.\\index{substitution!as pullback|textit}\n\\end{lem}\n\n\\begin{proof}\nBy \\cref{thm:is_pullback} it suffices to show that the gap map is an equivalence. The gap map is homotopic to the function\n\\begin{equation*}\n\\lam{(x,q)}(x,(f(x),q),\\refl{f(x)}).\n\\end{equation*}\nThe inverse of this map is given by $\\lam{(x,((y,q),p))}(x,\\mathsf{tr}_Q(p^{-1},q))$, and it is straightforward to see that these maps are indeed mutual inverses.\n\\end{proof}\n\n\\begin{thm}\\label{thm:pb_fibequiv}\nLet $f:A\\to B$, and let $g:\\prd{a:A}P(a)\\to Q(f(a))$ be a family of maps\\index{family of maps|textit}. The following are equivalent:\n\\begin{enumerate}\n\\item The commuting square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n\\sm{a:A}P(a) \\arrow[r,\"{\\total[f]{g}}\"] \\arrow[d,->>] & \\sm{b:B}Q(b) \\arrow[d,->>] \\\\\nA \\arrow[r,swap,\"f\"] & B\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\item $g$ is a family of equivalences.\\index{family of equivalences|textit}\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nThe gap map is homotopic to the composite\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n\\sm{x:A}P(x) \\arrow[r,\"\\total{g}\"] & \\sm{x:A}Q(f(x)) \\arrow[r,\"{\\mathsf{gap}'}\"] & A \\times_B \\Big(\\sm{y:B}Q(y)\\Big)\n\\end{tikzcd}\n\\end{equation*}\nwhere $\\mathsf{gap}'$ is the gap map for the square in \\cref{lem:pb_subst}. Since $\\mathsf{gap}'$ is an equivalence, it follows by \\cref{ex:3_for_2,thm:fib_equiv} that the gap map is an equivalence if and only if $g$ is a family of equivalences.\n\\end{proof}\n\nOur goal is now to extend \\cref{thm:pb_fibequiv} to\narbitrary pullback squares. Note that every commuting\nsquare\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r,\"h\"] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r,swap,\"i\"] & Y\n\\end{tikzcd}\n\\end{equation*}\nwith $H: i\\circ f ~ g \\circ h$ induces a map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq} : \\prd{x:X} \\fib{f}{x} \\to \\fib{g}{f(x)}\n\\end{equation*}\non the fibers, by\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq}(x,(a,p))\\defeq (h(a),\\ct{H(a)^{-1}}{\\ap{i}{p}}).\n\\end{equation*}\n\n\\begin{thm}\\label{cor:pb_fibequiv}\nConsider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r,\"h\"] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r,swap,\"i\"] & Y\n\\end{tikzcd}\n\\end{equation*}\nwith $H: i\\circ f ~ g \\circ h$. The following are equivalent:\n\\begin{enumerate}\n\\item The square is a pullback square.\\index{pullback square!characterized by families of equivalences|textit}\n\\item The induced map on fibers\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq} : \\prd{x:X} \\fib{f}{x} \\to \\fib{g}{f(x)}\n\\end{equation*}\nis a family of equivalences.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nFirst we observe that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\n\\sm{x:X}\\fib{f}{x} \\arrow[d,swap,\"\\eqvsym\"] \\arrow[r,\"\\total{\\mathsf{fib\\usc{}sq}}\"] &\n\\sm{x:X}\\fib{g}{f(x)} \\arrow[d,\"\\total{\\total{\\mathsf{inv}}}\"] \\\\\nA \\arrow[r,swap,\"\\mathsf{gap}\"] & X \\times_Y B\n\\end{tikzcd}\n\\end{equation*}\ncommutes. To construct such a homotopy, we need to construct an identification\n\\begin{equation*}\n(f(a),h(a),H(a))=(x,h(a),(\\ct{H(a)^{-1}}{\\ap{i}{p}})^{-1})\n\\end{equation*}\nfor every $x : X$, $a : A$, and $p : f(a) = x$. This is shown by path induction on $p : f(a)=x$. Thus, it suffices to show that\n\\begin{equation*}\n(f(a),h(a),H(a))=(f(a),h(a),(\\ct{H(a)^{-1}}{\\refl{i(f(a))}})^{-1}),\n\\end{equation*}\nwhich is a routine exercise. \n\nNow we note that the left and right maps in this square are both equivalences. Therefore it follows that the top map is an equivalence if and only if the bottom map is. The claim now follows by \\cref{thm:fib_equiv}.\n\\end{proof}\n\n\\begin{cor}\\label{cor:pb_trunc}\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*}\nIf $g$ is a $k$-truncated map, then so is $p$. In particular, if $g$ is an embedding then so is $p$.\\index{truncated!map!pullbacks of truncated maps|textit}\\index{embedding!pullbacks of embeddings|textit}\n\\end{cor}\n\n\\begin{proof}\nSince the square is assumed to be a pullback square, it follows from \\cref{cor:pb_fibequiv} that for each $x:A$, the fiber $\\fib{p}{x}$ is equivalent to the fiber $\\fib{g}{f(x)}$, which is $k$-truncated. Since $k$-truncated types are closed under equivalences by \\cref{thm:ktype_eqv}, it follows that $p$ is a $k$-truncated map.\n\\end{proof}\n\n\\begin{cor}\\label{cor:pb_equiv}\nConsider a commuting 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*}\nand suppose that $g$ is an equivalence. Then the following are equivalent:\n\\begin{enumerate}\n\\item The square is a pullback square.\n\\item The map $p:C\\to A$ is an equivalence.\\index{equivalence!pullback of|textit}\n\\end{enumerate}\n\\end{cor}\n\n\\begin{proof}\nIf the square is a pullback square, then by \\cref{thm:pb_fibequiv} the fibers of $p$ are equivalent to the fibers of $g$, which are contractible by \\cref{thm:contr_equiv}. Thus it follows that $p$ is a contractible map, and hence that $p$ is an equivalence.\n\nIf $p$ is an equivalence, then by \\cref{thm:contr_equiv} both $\\fib{p}{x}$ and $\\fib{g}{f(x)}$ are contractible for any $x:X$. It follows by \\cref{ex:contr_equiv} that the induced map $\\fib{p}{x}\\to\\fib{g}{f(x)}$ is an equivalence. Thus we apply \\cref{cor:pb_fibequiv} to conclude that the square is a pullback.\n\\end{proof}\n\n\\begin{thm}\\label{thm:pb_fibequiv_complete}\nConsider 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*}\nThen the type of triples $(i,H,p)$ consisting of a map $i:A\\to B$, a homotopy $H:h\\circ f\\htpy g\\circ i$, and a term $p$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r,\"i\"] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r,swap,\"h\"] & Y.\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square, is equivalent to the type of families of equivalences\n\\begin{equation*}\n\\prd{x:X}\\eqv{\\fib{f}{x}}{\\fib{g}{h(x)}}.\n\\end{equation*}\n\\end{thm}\n\n\\begin{cor}\\label{cor:pb_fibequiv_complete}\nLet $h:X\\to Y$ be a map, and let $P$ and $Q$ be families over $X$ and $Y$, respectively.\nThen the type of triples $(i,H,p)$ consisting of a map \n\\begin{equation*}\ni:\\Big(\\sm{x:X}P(x)\\Big)\\to \\Big(\\sm{y:Y}Q(y)\\Big),\n\\end{equation*}\na homotopy $H:h\\circ \\proj 1\\htpy \\proj 1\\circ i$, and a term $p$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{x:X}P(x) \\arrow[d,swap,\"\\proj 1\"] \\arrow[r,\"i\"] & \\sm{y:Y}Q(y) \\arrow[d,\"\\proj 1\"] \\\\\nX \\arrow[r,swap,\"h\"] & Y.\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square, is equivalent to the type of families of equivalences\n\\begin{equation*}\n\\prd{x:X}\\eqv{P(x)}{Q(h(x))}.\n\\end{equation*}\n\\end{cor}\n\nOne useful application of the connection between pullbacks and families of equivalences is the following theorem, which is also called the \\define{pasting property} of pullbacks.\\index{pasting property!of pullbacks|textit}\n\n\\begin{thm}\\label{thm:pb_pasting}\nConsider a commuting diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"k\"] \\arrow[d,swap,\"f\"] & B \\arrow[r,\"l\"] \\arrow[d,\"g\"] & C \\arrow[d,\"h\"] \\\\\nX \\arrow[r,swap,\"i\"] & Y \\arrow[r,swap,\"j\"] & Z\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies $H:i\\circ f\\htpy g\\circ k$ and $K:j\\circ g\\htpy h\\circ l$, and the homotopy\n\\begin{equation*}\n\\ct{(j\\cdot H)}{(K\\cdot k)}:j\\circ i\\circ f\\htpy h\\circ l\\circ k\n\\end{equation*}\nwitnessing that the outer rectangle commutes. Furthermore, suppose that the square on the right is a pullback square. Then the following are equivalent:\n\\begin{samepage}%\n\\begin{enumerate}\n\\item The square on the left is a pullback square.\n\\item The outer rectangle is a pullback square.\n\\end{enumerate}%\n\\end{samepage}%\n\\end{thm}\n\n\\begin{proof}\nThe commutativity of the two squares and the outer rectangle induces a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\n\\fib{f}{x} \\arrow[rr,\"\\mathsf{fib\\usc{}sq}_{(f,k,H)}(x)\"] \\arrow[dr,swap,\"\\mathsf{fib\\usc{}sq}_{f,l\\circ k,\\ct{(j\\cdot H)}{(K\\cdot k)}}(x)\"] & & \\fib{g}{i(x)} \\arrow[dl,\"\\mathsf{fib\\usc{}sq}_{(g,l,K)}(i(x))\"] \\\\\n& \\fib{h}{j(i(x))}.\n\\end{tikzcd}\n\\end{equation*}\nA homotopy witnessing that the triangle commutes is constructed by a routine calculation.\n\nSince the triangle commutes, and since the map $\\mathsf{fib\\usc{}sq}_{(g,l,K)}(i(x))$ is an equivalence for each $x:X$ by \\cref{cor:pb_fibequiv}, it follows\nby the 3-for-2 property of equivalences that for each $x:X$ the top map in the triangle is an equivalence if and only if the left map is an equivalence.\nThe claim now follows by a second application of \\cref{cor:pb_fibequiv}.\n\\end{proof}\n\n\\subsection{Descent theorems for coproducts and \\texorpdfstring{$\\Sigma$}{Σ}-types}\n\n\\begin{thm}\\label{thm:descent-coprod}\nConsider maps $f:A'\\to A$ and $g:B'\\to B$, a map $h:X'\\to X$, and commuting squares of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA' \\arrow[r] \\arrow[d,swap,\"f\"] & X' \\arrow[d,\"h\"] & B' \\arrow[r] \\arrow[d,swap,\"g\"] & X' \\arrow[d,\"h\"] \\\\\nA \\arrow[r] & X & B \\arrow[r] & X.\n\\end{tikzcd}\n\\end{equation*}\nThen the following are equivalent:\n\\begin{enumerate}\n\\item Both squares are pullback squares.\n\\item The commuting square \n\\begin{equation*}\n\\begin{tikzcd}\nA'+B' \\arrow[d,swap,\"f+g\"] \\arrow[r] & X' \\arrow[d,\"h\"] \\\\\nA+B \\arrow[r] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{cor:pb_fibequiv} it suffices to show that the following are equivalent:\n\\begin{enumerate}\n\\item For each $x:A$ the map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq}:\\fib{f}{x}\\to\\fib{h}{\\alpha_A(x)}\n\\end{equation*}\nis an equivalence, and for each $y:B$ the map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq}:\\fib{g}{y}\\to\\fib{h}{\\alpha_B(y)}\n\\end{equation*}\nis an equivalence.\n\\item For each $t:A+B$ the map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq}:\\fib{f+g}{t} \\to \\fib{h}{\\alpha(t)}\n\\end{equation*}\nis an equivalence.\n\\end{enumerate}\nBy the dependent universal property of coproducts, the second claim is equivalent to the claim that both for each $x:A$ the map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq}:\\fib{f+g}{\\inl(x)}\\to \\fib{h}{\\alpha_A(x)}\n\\end{equation*}\nis an equivalence, and for each $y:B$, the map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq}:\\fib{f+g}{\\inr(y)}\\to \\fib{h}{\\alpha_B(y)} \n\\end{equation*}\nis an equivalence.\n\nWe claim that there is a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=-1em]\n\\fib{f}{x} \\arrow[rr] \\arrow[dr] & & \\fib{f+g}{\\inl(x)} \\arrow[dl] \\\\\n\\phantom{\\fib{f+g}{\\inl(x)}} & \\fib{h}{\\alpha_A(x)}\n\\end{tikzcd}\n\\end{equation*}\nfor every $x:A$. To see that the triangle commutes, we need to construct an identification\n\n\nThe top map is given by\n\\begin{equation*}\n(a',p)\\mapsto (\\inl(a'),\\ap{\\inl}{p}).\n\\end{equation*}\nThe triangle then commutes by the homotopy\n\\begin{equation*}\n(a',p)\\mapsto \\mathsf{eq\\usc{}pair}(\\refl,\\ap{\\mathsf{concat}(H(a')^{-1})}{\\mathsf{ap\\usc{}comp}_{[\\alpha_A,\\alpha_B],inl}})\n\\end{equation*}\nWe note that the top map is an equivalence, so it follows by the 3-for-2 property of equivalences that the left map is an equivalence if and only if the right map is an equivalence. \n\nSimilarly, there is a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=-1em]\n\\fib{g}{y} \\arrow[rr] \\arrow[dr] & & \\fib{f+g}{\\inr(y)} \\arrow[dl] \\\\\n\\phantom{\\fib{f+g}{\\inr(y)}} & \\fib{h}{\\alpha_B(y)}\n\\end{tikzcd}\n\\end{equation*}\nin which the top map is an equivalence, completing the proof.\n\\end{proof}\n\nIn the following corollary we conclude that coproducts distribute over pullbacks. \n\n\\begin{cor}\nConsider a cospan of the form\n\\begin{equation*}\n\\begin{tikzcd}\n& Y \\arrow[d] \\\\\nA+B \\arrow[r] & X.\n\\end{tikzcd}\n\\end{equation*}\nThen there is an equivalence\n\\begin{equation*}\n(A+B)\\times_X Y \\simeq (A\\times_X Y)+(B\\times_X Y).\n\\end{equation*}\n\\end{cor}\n\n\\begin{thm}\\label{thm:descent-Sigma}\nConsider a family of maps $f_i:A'_i\\to A_i$ indexed by a type $I$, a map $h:X'\\to X$, and a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA'_i \\arrow[r] \\arrow[d,swap,\"f_i\"] & X' \\arrow[d,\"h\"] \\\\\nA_i \\arrow[r,swap,\"\\alpha_i\"] & X\n\\end{tikzcd}\n\\end{equation*}\nfor each $i:I$. Then the following are equivalent:\n\\begin{enumerate}\n\\item For each $i:I$ the square is a pullback square.\n\\item The commuting square\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{i:I}A'_i \\arrow[d,swap,\"\\total{f}\"] \\arrow[r] & X' \\arrow[d,\"h\"] \\\\\n\\sm{i:I}A_i \\arrow[r,\"\\alpha\"] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{cor:pb_fibequiv} it suffices to show that the following are equivalent for each $i:I$ and $a:A_i$:\n\\begin{enumerate}\n\\item The map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq} : \\fib{f_i}{a} \\to \\fib{g}{\\alpha_i(a)}\n\\end{equation*}\nis an equivalence.\n\\item The map\n\\begin{equation*}\n\\mathsf{fib\\usc{}sq} : \\fib{\\total{f}}{i,a}\\to \\fib{g}{\\alpha_i(a)}\n\\end{equation*}\nis an equivalence.\n\\end{enumerate}\nTo see this, note that we have a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=-1em]\n\\fib{f_i}{a} \\arrow[rr] \\arrow[dr] & & \\fib{\\total{f}}{i,a} \\arrow[dl] \\\\\n\\phantom{\\fib{\\total{f}}{i,a}} & \\fib{g}{\\alpha_i(a)},\n\\end{tikzcd}\n\\end{equation*}\nwhere the top map is an equivalence by \\cref{lem:fib_total}. Therefore the claim follows by the 3-for-2 property of equivalences.\n\\end{proof}\n\nIn the following corollary we conclude that $\\Sigma$ distributes over coproducts.\n\n\\begin{cor}\nConsider a cospan of the form\n\\begin{equation*}\n\\begin{tikzcd}\n& Y \\arrow[d] \\\\\n\\sm{i:I}A_i \\arrow[r] & X.\n\\end{tikzcd}\n\\end{equation*}\nThen there is an equivalence\n\\begin{equation*}\n\\Big(\\sm{i:I}A_i\\Big)\\times_X Y \\simeq \\sm{i:I} (A_i\\times_X Y).\n\\end{equation*}\n\\end{cor}\n\n\n\n\\begin{exercises}\n\\item \\label{ex:id_pb}\\index{identity type!as pullback}\n\\begin{subexenum}\n\\item Show that the square\\index{identity type!as pullback}\n\\begin{equation*}\n\\begin{tikzcd}\n(x=y) \\arrow[r] \\arrow[d] & \\unit \\arrow[d,\"\\mathsf{const}_y\"] \\\\\n\\unit \\arrow[r,swap,\"\\mathsf{const}_x\"] & A\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\item Show that the square\\index{diagonal!of a type!fibers of}\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n(x=y) \\arrow[r,\"\\mathsf{const}_{x}\"] \\arrow[d,swap,\"\\mathsf{const}_\\ttt\"] & A \\arrow[d,\"\\delta_A\"] \\\\\n\\unit \\arrow[r,swap,\"{\\mathsf{const}_{(x,y)}}\"] & A\\times A\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square, where $\\delta_A:A\\to A\\times A$ is the diagonal of $A$, defined in \\cref{ex:diagonal}.\n\\end{subexenum}\n\\item \\label{ex:trunc_diagonal_map}In this exercise we give an alternative characterization of the notion of $k$-truncated map, compared to \\cref{thm:trunc_ap}. Given a map $f:A\\to X$ define the \\define{diagonal}\\index{diagonal!of a map} of $f$ to be the map $\\delta_f:A\\to A\\times_X A$ given by $x\\mapsto (x,x,\\refl{f(x)})$.\n\\begin{subexenum}\n\\item Construct an equivalence\n\\begin{equation*}\n\\eqv{\\fib{\\delta_f}{(x,y,p)}}{\\fib{\\apfunc{f}}{p}}\n\\end{equation*}\nto show that the square\\index{action on paths!fibers of}\\index{diagonal!of a map!fibers of}\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n\\fib{\\apfunc{f}}{p} \\arrow[r,\"\\mathsf{const}_x\"] \\arrow[d,swap,\"\\mathsf{const}_\\ttt\"] & A \\arrow[d,\"\\delta_f\"] \\\\\n\\unit \\arrow[r,swap,\"{\\mathsf{const}_{(x,y,p)}}\"] & A\\times_X A\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square, for every $x,y:A$ and $p:f(x)=f(y)$.\n\\item Show that a map $f:A\\to X$ is $(k+1)$-truncated if and only if $\\delta_f$ is $k$-truncated.\\index{truncated!map!by truncatedness of diagonal}\n\\end{subexenum}\nConclude that $f$ is an embedding if and only if $\\delta_f$ is an equivalence.\\index{embedding!diagonal is an equivalence}\n\\item Consider a commuting 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$. Show that this square is a pullback square if and only if the square\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r,\"p\"] \\arrow[d,swap,\"q\"] & A \\arrow[d,\"f\"] \\\\\nB \\arrow[r,swap,\"g\"] & X \n\\end{tikzcd}\n\\end{equation*}\nwith $H^{-1}:g\\circ q\\htpy f\\circ p$ is a pullback square.\n\\item Show that any square of the form\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\n\\emptyt \\arrow[r] & X\n\\end{tikzcd}\n\\end{equation*}\ncommutes and is a pullback square. This is the \\emph{descent property} of the empty type.\\index{descent!empty type}\n\\item Consider a commuting 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$. Show that the following are equivalent:\n\\begin{enumerate}\n\\item The square is a pullback square.\n\\item For every type $T$, the commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nC^T \\arrow[r,\"q\\circ\\blank\"] \\arrow[d,swap,\"p\\circ\\blank\"] & B^T \\arrow[d,\"g\\circ\\blank\"] \\\\\nA^T \\arrow[r,swap,\"f\\circ\\blank\"] & X^T\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{enumerate}\nNote: property (ii) is really just a rephrasing of the universal property of pullbacks.\\index{pullback square!universal property}\n\\item \\label{ex:pb_diagonal}Consider a commuting 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$. Show that the following are equivalent:\n\\begin{enumerate}\n\\item The square is a pullback square.\n\\item The square\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r,\"g\\circ q\"] \\arrow[d,swap,\"{\\lam{x}(p(x),q(x))}\"] & X \\arrow[d,\"\\delta_X\"] \\\\\nA\\times B \\arrow[r,swap,\"f\\times g\"] & X\\times X\n\\end{tikzcd}\n\\end{equation*}\nwhich commutes by $\\lam{z}\\mathsf{eq\\usc{}pair}(H(z),\\refl{g(q(z))})$ is a pullback square.\n\\end{enumerate}\n\\item \\label{ex:pb_prod}Consider two commuting squares\\index{pullback!cartesian products of pullbacks}\n\\begin{equation*}\n\\begin{tikzcd}\nC_1 \\arrow[r] \\arrow[d] & B_1 \\arrow[d] & C_2 \\arrow[r] \\arrow[d] & B_2 \\arrow[d] \\\\\nA_1 \\arrow[r] & X_1 & A_2 \\arrow[r] & X_2.\n\\end{tikzcd}\n\\end{equation*}\n\\begin{subexenum}\n\\item Show that if both squares are pullback squares, then the square\n\\begin{equation*}\n\\begin{tikzcd}\nC_1\\times C_2 \\arrow[r] \\arrow[d] & B_1\\times B_2 \\arrow[d] \\\\\nA_1 \\times A_2 \\arrow[r] & X_1\\times X_2. \n\\end{tikzcd}\n\\end{equation*}\nis also a pullback square.\n\\item Show that if there are terms $t_1:A_1\\times_{X_1}B_1$ and $t_2:A_2\\times_{X_2}B_2$, then the converse of (a) also holds.\n\\end{subexenum}\n\\item Consider for each $i:I$ a pullback square\n\\begin{equation*}\n\\begin{tikzcd}\nC_i \\arrow[r,\"q_i\"] \\arrow[d,swap,\"p_i\"] & B_i \\arrow[d,\"g_i\"] \\\\\nA_i \\arrow[r,swap,\"f_i\"] & X_i\n\\end{tikzcd}\n\\end{equation*}\nwith $H_i: f_i\\circ p_i\\htpy g_i\\circ q_i$.\\index{pullback!Pi-type of pullbacks@{$\\Pi$-type of pullbacks}}\\label{ex:pb_pi}\nShow that the commuting square\n\\begin{equation*}\n\\begin{tikzcd}\n\\prd{i:I}C_i \\arrow[r] \\arrow[d] & \\prd{i:I}B_i \\arrow[d] \\\\\n\\prd{i:I}A_i \\arrow[r] & \\prd{i:I}X_i\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n%\\item \n%\\begin{subexenum}\n%\\item Show that \\index{equivalence!type of equivalences!as pullback}\n%\\begin{equation*}\n%\\begin{tikzcd}[column sep=8em]\n%\\eqv{A}{B} \\arrow[r] \\arrow[d] & \\unit \\arrow[d,\"{(\\idfunc[A],\\idfunc[B])}\"] \\\\\n%A^B\\times B^A \\times A^B \\arrow[r,swap,\"{(h,f,g)\\mapsto (h\\circ f,f\\circ g)}\"] & A^A \\times B^B\n%\\end{tikzcd}\n%\\end{equation*}\n%is a pullback square.\n%\\item Show that \\index{contractible!type of contractibility!as pullback}\n%\\begin{equation*}\n%\\begin{tikzcd}[column sep=6em]\n%\\iscontr(A) \\arrow[r,\"\\mathsf{const}_{\\ttt}\"] \\arrow[d,swap,\"\\proj 1\"] & \\unit \\arrow[d,\"{\\lam{\\ttt}\\idfunc[A]}\"] \\\\\n%A \\arrow[r,swap,\"{\\lam{x}\\mathsf{const}_x}\"] & A^A\n%\\end{tikzcd}\n%\\end{equation*}\n%is a pullback square.\n%\\end{subexenum}\n%\\item Consider a commuting square\n%\\begin{equation*}\n%\\begin{tikzcd}\n%C \\arrow[r] \\arrow[d] & A \\arrow[d] \\\\\n%B \\arrow[r] & X.\n%\\end{tikzcd}\n%\\end{equation*}\n%Show that this square is cartesian if and only if the induced map $C\\to A\\times_X B$ has a retraction.\n%\\end{subexenum}\n%\\item Suppose that the squares\n%\\begin{equation*}\n%\\begin{tikzcd}\n%C \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] & {C'} \\arrow[r,\"{q'}\"] \\arrow[d,swap,\"{p'}\"] & B \\arrow[d,\"g\"] \\\\\n%A \\arrow[r,swap,\"f\"] & X & A \\arrow[r,swap,\"f\"] & X\n%\\end{tikzcd}\n%\\end{equation*}\n%with homotopies $H:f\\circ p \\htpy g\\circ q$ and $H':f\\circ p'\\htpy g\\circ q'$ are both pullback squares. Show that the type of equivalences $e:\\eqv{C'}{C}$ equipped with an identification\n%\\begin{equation*}\n%\\mathsf{cone\\usc{}map}((p,q,H),e)=(p',q',H')\n%\\end{equation*}\n%is contractible.\n\\begin{comment}\n\\item Consider a \\define{natural transformation of cospans}\\index{cospan!natural transformation of}, i.e., a commuting diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"f\"] \\arrow[d,swap,\"i\"] & X \\arrow[d,swap,\"j\"] & B \\arrow[l,swap,\"g\"] \\arrow[d,\"k\"] \\\\\nA' \\arrow[r,swap,\"{f'}\"] & X' & B'. \\arrow[l,\"{g'}\"]\n\\end{tikzcd}\n\\end{equation*}\nShow that the map\n\\begin{equation*}\n(a,b,p)\\mapsto (i(a),j(b),\\mathsf{ap}_k(p)): A \\times_X B \\to A'\\times_{X'} B'\n\\end{equation*}\nis $k$-truncated if each of the vertical maps is.\n\\end{comment}\n\\begin{comment}\n\\item \\label{ex:pb_fib}Consider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[d,swap,\"p\"] \\arrow[r,\"q\"] & 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 $h:C\\to A\\times_X B$ be the map given by $h(z)\\defeq (p(c),q(c),H(c))$. \nShow that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=6.5em]\n\\fib{\\mathsf{gap}(p,q,H)}{(a,b,\\alpha)} \\arrow[d,swap,\"\\mathsf{const}_{\\ttt}\"] \\arrow[r,\"{\\lam{(c,\\beta)}(c,\\ap{\\pi_1}{\\beta})}\"] & \\fib{p}{a} \\arrow[d,\"{\\fibf{(f,g,H)}}\"] \\\\\n\\unit \\arrow[r,swap,\"\\mathsf{const}_{(b,\\alpha^{-1})}\"] & \\fib{g}{f(a)}\n\\end{tikzcd}\n\\end{equation*}\n\\end{comment}\n\\item \\label{ex:pb_3by3}Consider a commuting diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA_0 \\arrow[r] \\arrow[d] & B_0 \\arrow[d] & C_0 \\arrow[l] \\arrow[d] \\\\\nA_1 \\arrow[r] & B_1 & C_1 \\arrow[l] \\\\\nA_2 \\arrow[u] \\arrow[r] & B_2 \\arrow[u] & C_2 \\arrow[u] \\arrow[l]\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies filling the (small) squares. Construct an equivalence\n\\begin{align*}\n& (A_0\\times_{B_0} C_0) \\times_{(A_1\\times_{B_1} C_1)} (A_2\\times_{B_2} C_2) \\\\\n& \\qquad \\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{align*}\nThis is also known as the \\define{3-by-3 lemma}\\index{3-by-3 lemma!for pullbacks} for pullbacks.\n\\end{exercises}\n", "meta": {"hexsha": "990842cbdef88b5fb7faef73f2c3794191047dce", "size": 43970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/pullback.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/pullback.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/pullback.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": 40.7884972171, "max_line_length": 397, "alphanum_fraction": 0.6737548328, "num_tokens": 16480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485245, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6993505996583548}}
{"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 1}\n\nA stack supports two operations: \\textsc{Push} and \\textsc{Pop}.\nImplementing the two operations using a linked-list takes $\\mathcal{O}(1)$ time per operation.\nSuppose we are given two stacks, $A$ and $B$ with $n$ and $m$ elements, respectively.\nWe want to implement the following operations:\n\\begin{description}\\itemsep=0pt\n\\item[\\textsc{Push}($A, x$)] Push $x$ elements into $A$.\n\\item[\\textsc{Push}($B, x$)] Push $x$ elements into $B$.\n\\item[\\textsc{MultipopA($k$)}] pop $\\text{min}\\{k,n\\}$ elements from $A$.\n\\item[\\textsc{MultipopB($k$)}] pop $\\text{min}\\{k,m\\}$ elements from $B$.\n\\item[\\textsc{Transfer($k$)}] repeatedly pop an element from $A$ and push it to $B$ until either $k$ elements have been transferred or $A$ is empty.\n\\end{description}\n\\begin{enumerate}[label=(\\alph*)]\n\\item What is the worst-case running time of \\textsc{MultipopA}, \\textsc{MultipopB} and \\textsc{Transfer}?\n\\item Show that the amortized running time per operation is $\\mathcal{O}(1)$ for a sequence of \\textsc{Push}($A,n$) and \\textsc{Transfer}($n$).\nYou may use any technique shown in class on a sequence on $n$ operations.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Operations \\textsc{Push}($A,x$) and \\textsc{Push}($B,x$) have a runtime cost of $\\mathcal{O}(x)$ as \\textsc{Push}() operation with runtime $\\mathcal{O}(1)$ should be performed for $x$ times.\n\nOperations \\textsc{MultipopA}($k$) and \\textsc{MultipopB}($k$) both repeat the \\textsc{Pop()} operation for $\\text{min}(k,n)$ and $\\text{min}(k,m)$ times, respectively.\nIn the worst-case where $n,m < k$, the operations are limited by the number of elements in the stacks.\nTherefore, their worst-case runtime cost are $\\mathcal{O}(n)$ and $\\mathcal{O}(m)$, respectively.\n\nOperation \\textsc{Transfer($k$)} has a worst-case runtime of $\\mathcal{O}(k)$, since worst scenario happens when $k < n$ and $k < m$ and there will be $k$ items to \\textsc{Pop()} from stack $A$ and $k$ items to \\textsc{Push()} to stack $B$.\n\n\\item For \\textsc{Push}($A,n$), amortized runtime would be constant $C$ where $C$ is the cost to push one element to a stack.\nThis can be shown easily using the aggregate method as shown in Eq. \\ref{eq11}.\n\n\\begin{equation}\n\\sum_{i=1}^{n} c_i = \\sum_{i=1}^{n} c = c \\sum_{i=1}^{n} 1 = nc \\Rightarrow \\text{Amortized Cost} = \\frac{nc}{n} = c\n\\label{eq11}\n\\end{equation}\n\nFor \\textsc{Transfer($k$)} operation, the worst case happens when there are at least $k$ elements in stack $k$, in which case amortized cost of the operation can be obtained as given in Eq. \\ref{eq12}.\n\n\\begin{equation}\n\\sum_{i=1}^{k} c_i = \\sum_{i=1}^{k}(c_1 + c_2) = (c_1 + c_2) \\sum_{i=1}^{k} 1 = (c_1 + c_2) k\n\\label{eq12}\n\\end{equation}\n\nSince cost of \\textsc{Pop()} ($c_1$) and \\textsc{Push()} ($c_2$) are $\\mathcal{O}(1)$, amortized cost of \\textsc{Transfer($k$)} is obtained from \\ref{eq12}.\n\n\\begin{equation}\n\\text{Amortized Cost} = \\frac{k(c_1 + c_2)}{k} = c_1 + c_2 = 2\n\\end{equation}\n\n\\end{enumerate}\n", "meta": {"hexsha": "c287954c177fb7f647c3b6a939696d61009d9ae1", "size": 3360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/m02/m02q01.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/m02/m02q01.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/m02/m02q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 56.0, "max_line_length": 240, "alphanum_fraction": 0.6672619048, "num_tokens": 1099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.699350591633295}}
{"text": "\\section{Mathematical basics}\nThis section is going to describe the mathematical concepts of an general computer algebra library which shall be implemented. Although a swath of computer algebra programs is available none of these programs comes with a library the an interested user may simply include in his/her own project.\\\\\n\\indent In addition, as anyone can imagine no single program can provide all objecs which are currently investigated. Worse, the user is forced to delve into each programs programming structures and restrictions and potentially has to change the program if desires and needs are not met.\n\\subsection{Categories and functor}\nAs we briefly outlined in the first chapter, we discuss the functorial approach. Firstly, we like to explain some the features needed.\n\\subsubsection{Basic concepts}\nWe will denote an arbitrary category with $\\mathcal{C}$.\n\\paragraph{Categories} Categories comprise of three concepts or data encoding it:\n\\begin{description}\n\\item[Objects] are the instances of a category. They are not necessarily sets in a set theoretic sense rather classes. They are denoted by $\\mathrm{Obj}_{\\mathcal{C}}$ or $\\objc$.\n\\item[Morphisms] are maps connecting objects in a category sometimes trivially called arrows. These maps are not arbitrary but preserve or respect the structure of each object. The class of morphisms are denoted by $\\morc$.\n\\item[Identity] is a unique map, actually a functor mapping each object $A \\in \\objc$ to its identity morphism $id_A : A \\longrightarrow A$.\n\\end{description}\nThe last point is of utmost importance: the identity map is always a morphism in a given category. Furthermore, given a triple $A, B, C \\in \\objc$ and morhisms $f : A \\longrightarrow B, g : \\longrightarrow C \\in \\morc$ the composition yields a new morphism:\n$$g \\circ f : A \\longrightarrow C \\in \\morc.$$\nSome authors require all five properties to be fulfilled to called a category others omit some.\n\\paragraph{Functors}\nFunctors can be thought of as maps between categories. To specify given two categories $\\mathcal{C}$ and $\\mathcal{D}$, a functor $F$ is a pairing $F : \\mathcal{C} \\longrightarrow \\mathcal{D}$ of these two such that:\n\\begin{description}\n\\item[Variance] For $A, B \\in \\objc$ and $f \\in \\morc$ either of the two diagrams commutes:\n$$\\begin{array}{cc}\n\\xymatrix{\nA \\ar[d]_F\\ar[r]^f& B\\ar[d]^F\\\\\nF(A) \\ar[r]_{(f)} &F(B)\\\\\n} & \\xymatrix{\nA \\ar[d]_F\\ar[r]^f& B\\ar[d]^F\\\\\nF(A)  &F(B).\\ar[l]^{F(f)}\\\\\n} \n\\end{array}\n$$\nThe left diagram represents a so called covariant functor $F$ - the right one a so called contravariant functor.\n\\item[Morphism and identity] The map $F(f) : F(A) \\longrightarrow F(B)$ in the covariant case and the map $F(f) : F(B) \\longrightarrow F(A)$ in the contravariant case are morphisms in $\\mor{\\mathcal{D}}$. In particular, $F(id_A) = id_{F(A)}$ and $F(id_A) = id_{F(B)}$ are a morphisms.\n\\end{description}\nThere are categories consisting of categories or functors. We will leave it to the reader to explore those. In addition, we may get new categories \n\\subsubsection{Examples}\nAs any brief discussion, we will a some examples to illustrate these concepts.\n\\paragraph{The categories $\\mathrm{Set}$ and $\\mathrm{Top}$}\nThe most general category we are going to discuss is the category of all sets, $\\mathrm{Set}$, with morphisms $\\mor{\\mathrm{Set}}$ simply as maps\n$$f \\in \\mathrm{map}(A,B) = B^A \\subset \\mor{\\mathrm{Set}},$$\nfor all $A, B \\in \\obj{\\mathrm{Set}}$.\\\\\nWe call a category $\\calc$ small if the class of all its objects is a set in a set theoretic sense. The above example is not small, therefore appropiately called large (i.e. a large category).\\\\\n\\indent The next example is the category of all topological spaces, $\\mathrm{Top}$, with continuous maps as morphisms:\nFurthermore, we may define two pairings\n$$\\begin{array}{rrcl}\n\\call{O} :& \\mathrm{Top} &\\longrightarrow& \\mathrm{Set},\\\\\n&&&\\\\\n& (A, \\tau) &\\longmapsto &\\left\\{U \\in \\tau :  U\\ \\mathrm{open}\\right\\},\\\\\n&&&\\\\\n\\call{F} :& \\mathrm{Top}&\\longrightarrow& \\mathrm{Set},\\\\\n&&&\\\\\n&(A, \\tau) &\\longmapsto& \\left\\{F \\in \\tau : F \\ \\mathrm{closed}\\right\\}\\\\\n\\end{array}\\\\\n$$\nthen we get a map $f \\in C(A,B) \\subset \\mor{\\mathrm{Top}}$ if and only if the following diagrams:\n$$\\begin{array}{ccc}\n\\xymatrix{\nA \\ar[r]^f\\ar[d]_{\\call{F}} & B\\ar[d]^{\\call{F}}\\\\\n\\call{F}(A) &\\call{F}(B)\\ar[l]^{\\call{F}(f)}\\\\\n}&\\mathrm{and}&\\xymatrix{\nA \\ar[r]^f\\ar[d]_{\\call{O}} & B\\ar[d]^{\\call{O}}\\\\\n\\call{O}(A) &\\call{O}(B)\\ar[l]^{\\call{O}(f)}\\\\\n}\\\\\n\\end{array}\n$$\ncommute. Moreover, what we simply called a pairing from topological spaces with their respetive sub topologies of open or closed sets, respectively, are in fact two contravariant functors.\n\\paragraph{Pointed spaces and partially ordered sets}\nGiven a set $X$ and an element $x_0 \\in X$, we call the pair $(X,x_0)$ a pointed space and $x_0$ its base point. The class of all pointed spaces forms a category $\\mathrm{Pt}$ wrt. to maps preserving base points as morphisms. By this defintion, $\\mathrm{Pt}$ is a proper subcategory of $\\mathrm{Set}$ as the empty set is not a member of its object class. However, the terminal objects are the singletons - objects with exactly one element.\\\\\n\\indent We call a category $\\calc$ with an object $\\cdot$ a category with terminal object $\\cdot$ if and only if for any pair of objects $A, B \\in \\objc$ with arrow $f \\in \\objc(A,B)$ there exist two unique morphisms $\\pi_A : A \\longrightarrow \\cdot, \\pi_B : B \\longrightarrow \\cdot \\in \\morc$ such that the following diagram commutes:\n$$\\xymatrix{\nA \\ar[r]^f \\ar[dr]_{\\pi_A} & B\\ar[d]^{\\pi_B}\\\\\n&\\cdot.\\\\\n}$$\nClearly, each pointed space $(X,x_0)$ is an object with terminal object.\\\\\n\\indent Reversing arrows, we call a category $\\calc$ with object $\\ast$ a category with initial object if for all objects $A, B \\in \\objc$ and arrow $f : B \\longrightarrow A$ there are two unique morphisms $\\iota_A : \\ast \\longrightarrow A, \\iota_B : \\ast \\longrightarrow B \\in \\morc$ such that\n$$\\xymatrix{\nA & B\\ar[l]_f\\\\\n&\\ast\\ar[u]_{\\iota_B} \\ar[ul]^{\\iota_A} .\\\\\n}$$\ncommutes.\\\\\n\\indent We call an object $\\ast \\in \\objc$ a null object if it is initial and terminal. The category of sets, $\\mathrm{Set}$, has the empty set as initial and the class of singletons as terminal object. The category of pointed spaces has its singletons as null object.\\\\\n\\indent A relation $R \\subset X^2$ is called a partial order on a set $X$ if for all $x, y, z \\in X$:\n\\begin{enumerate}\n\\item $x R x$ (reflexive),\n\\item $x R y$ and $y R x$ implies $x = y$ (antisymmetry) and\n\\item $x R y$ and $y R z$ implies $x R z$ (transitivity).\n\\end{enumerate}\nPartially ordered sets are of great importance in conjunction with algebraic categories which we will describe shortly.\n\\paragraph{Algebraic categories}\nIn its very beginning, category theory was mainly an algebraic endeavour. As it became apparent that certain theoremes had a wider application then initially anticipated.\\\\\nSince an algebraic library is the aim of this essay we shall spend some time on algebraic categories.\n\\subparagraph{Semigroups, monoids and groups}\nBefore we start a short definition. We call a category $\\calc$ a category with finite products if for all objects $A, B \\in \\objc$ the set theoretic product \n$$A \\times B = \\{(a,b) : a \\in A, b \\in B\\} \\in \\objc.$$\nIn particular, each canonical projection $\\pi_X : A \\times B \\longrightarrow X$ and their respective embeddings $\\iota_X : X \\longrightarrow A \\times B$, $X = A, B$ are morphisms in $\\calc$.\\\\\n\\begin{enumerate}\n\\item Let $S$ be a set and $m : S \\times S \\longrightarrow S$ be a binary operation. We call a pair $(S, m)$ a semi group if for all $(s, s')$ there is a $s'' \\in S$ such that $m(s,s') = s''$ and the following diagram commutes \n$$\\xymatrix{\nS \\times S \\times S \\ar[rr]^{id_S \\times m}\\ar[d]_{m \\times id_S} && S \\times S\\ar[d]^{m}\\\\\nS \\times S \\ar[rr]_{m} &&S.\\\\\n}$$\nWe call the first property closedness (under operation) and the second associativity. Similarily to the category of sets, the category of semi groups has empty set as initial and singletons as terminal object.\\\\\n\\item Let $(M, m)$ be a semi group. We call $M$ a monoid if there is a initial object $\\ast$ and an embedding $e : \\ast \\longrightarrow M$ such that the following diagram commutes:\n$$\\xymatrix{\n& M \\times M \\ar[dd]_{m}& \\\\\n\\ast \\times M \\ar[ur]^{e \\times id_M}\\ar[dr]_{\\simeq} && M \\times \\ast \\ar[ul]_{id_M \\times e}\\ar[dl]^{\\simeq} \\\\\n&M.&\\\\\n}$$\nThe map $e$ is a morphism in $\\mathrm{Mon}$ and called the unit (map). We denote a monoid with triple $(M, m, e)$. Note that $\\mathrm{Mon}$ is a category with null object (initial and terminal are isomorphic). Moreover, it is a subcategory of pointed spaces with trivial submonoid as null object.\n\\item We call a monoid $(G, m, e)$ a group if there is a map $S : G \\longrightarrow G$ such that the following diagram commutes:\n$$\\xymatrix{\n&G \\ar[ld]_{\\Delta} \\ar[ddd] \\ar[dr]^{\\Delta}&\\\\\nG \\times G \\ar[d]_{S \\times id_G} & & \\ar[d]^{id_G \\times S} G \\times G\\\\\nG \\times G \\ar[dr]_{m} & & \\ar[dl]^{m} G \\times G\\\\\n&\\ast.&\\\\\n}$$\nThe map $S$ is called the antipode or more popularly, the inverse/inversion. It induces a group (anti-) isomorphism:\n$$S : G \\stackrel{\\sim}{\\longrightarrow} G^{\\mathrm{op}},$$\n$$m^{\\mathrm{op}} = m \\circ (S \\times S) \\circ \\tau = \\left[(g, h) \\longmapsto m(h^{-1},g^{-1}) = h^{-1} g^{-1}\\right]$$\nIt is an anti isomorphism if considered as map $G \\longrightarrow G$ and an isomorphism $(G,m,e,S) \\longrightarrow (G^{\\mathrm{op}},m^{\\mathrm{op}},e^{\\mathrm{op}} = e, S^{op} = S)$ (we exchange the multiplication map $m$ with $m^{\\mathrm{op}}$). A group is called abelian if\n$$\\xymatrix{\nG \\times G \\ar[d]_{m^{\\mathrm{op}}} \\ar[r]^{m} &G\\ar[ld]^{S}\\\\\nG \n}$$\ncommutes. They form a proper subcategory of $\\mathrm{Grp}$, denoted $\\mathrm{Abel}$. Again, they have a null object (trivial subgroup). Furthermore, this category has finite products (at least two distinct in as far as):\n$$\\begin{array}{rrcl}\n\\times : &\\mathrm{Grp} \\times \\mathrm{Grp}& \\longrightarrow &\\mathrm{Grp},\\\\ &\\left((G, m_G, e_G, S_G), (H, m_H, e_H, S_H)\\right)& \\longmapsto &(G \\times H, m_{G} \\times m_H, e_{G} \\times e_{H},\\\\\n&&& S_G \\times S_H)\\\\\n&&&\\\\\n\\times_{\\alpha} : &\\mathrm{Grp} \\times \\mathrm{Grp} &\\longrightarrow& \\mathrm{Grp}\\\\\n&(G,m_G,e_G,S_G),(H,m_H,e_H,S_H))&\\longmapsto&(G \\times H, m^{\\alpha}_{G \\times H}, e_G \\times e_H, S_{G} \\times S_{H})\\\\\n\\end{array}$$\nwith\n$$\\begin{array}{rcl}\nm^\\alpha_{G \\times H} &=& (m_G \\times m_H) (id_G \\times \\alpha \\times id_H \\times id_G \\times id_H)\\\\&&(id_G \\times id_H \\times \\tau_{H\\times G}\\times id_H)(id_G \\times \\Delta_H \\times id_G \\times id_H),\\\\\n&&\\\\\n&=& [(g_1,h_1,g_2,h_2) \\longmapsto (g_1,h_1,h_1,g_2,h_2) \\longmapsto (g_1,h_1,g_2,h_1,h_2) \\longmapsto\\\\&&~ (g_1, \\alpha(h_1)(g_2),h_1,h_2) \\longmapsto (g_1 \\alpha(h_1)(g_2), h_1 h_2)] \\ \\mathrm{and}\\\\\n&&\\\\\n\\alpha &=& [h \\longmapsto \\alpha(h)] \\in \\mathrm{Grp}(H,\\mathrm{Aut}_{\\mathrm{Grp}}(G))\\\\\n\\end{array}$$\nThe former product is called direct (only the neutral element is in both groups and both are normal in $G \\times H$), the latter is called the semi direct product for a given group homomorphism $\\alpha : H \\longrightarrow \\mathrm{Aut}(G)$. They coincide if $\\alpha$ reduces to the trivial map\n$$\\alpha = e_{\\mathrm{Aut}(G)} \\circ \\pi_H = [ h \\longmapsto e_H \\longmapsto id_G].$$\n\\end{enumerate}\n", "meta": {"hexsha": "ad6fe184f3e36273cff6c647ab6714d116eca648", "size": 11352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manifesto/impl2.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": "manifesto/impl2.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": "manifesto/impl2.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": 79.3846153846, "max_line_length": 441, "alphanum_fraction": 0.7003171247, "num_tokens": 3578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6992823586853701}}
{"text": "\\paragraph{Population} is a set, of which we would like to learn some properties.\n  \n\\paragraph{Sample} is a subset of a population, on which we calculate the properties and then make\nstatements about the whole population.\n\n\\paragraph{Random sample} is a sample taken in an unpredictable way, i.e. the method of taking the\nsample involves an unpredictable component.\n\n\\paragraph{Self-weighting sample} is a sample taken in such manner that each element of population has equal\nchance of being included in the sample.\n\n\\paragraph{Simple random sample} is a kind of self-weighting sample selected so that all samples of\nsame size have equal chance of being selected.\n\n\\subsection*{Remark}\nFurther on we in most cases assume random sample of size $n$, $X = \\sample$.\n", "meta": {"hexsha": "2ee41e77755a6d5d76b8e2aee2a98a80fc4ccf66", "size": 764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_2a_basics.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_2a_basics.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_2a_basics.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.9411764706, "max_line_length": 108, "alphanum_fraction": 0.7866492147, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.699280439221989}}
{"text": "\n\\section{The conjugate gradient method}\n\n\\begin{intro}\n  Relying on Hilbert space structure more than Richardson's iteration\n  is the \\putindex{conjugate gradient method} (cg), since it uses\n  orthogonal search directions. Nevertheless, it also relies on\n  constructing search directions from residuals, such that a\n  \\putindex{Riesz isomorphism} enters the same way as before and can\n  then be used for preconditioning.\n  \n  The beauty of the conjugate gradient method is, that it is parameter\n  and tuning free, and it converges considerably faster than a linear\n  iteration method.\n\\end{intro}\n\n\\begin{Definition*}{steepest-descent}{Method of steepest descent}\n  Let $a(.,.)$ be a symmetric, positive definite bilinear form on\n  $V$. Then, the method of \\define{steepest descent} for the energy functional\n  \\begin{gather}\n    E(v) = \\tfrac12 a(v,v) - f(v),\n  \\end{gather}\n  reads: given an initial vector $u^{(0)}$,\n  compute % $p^{(1)} = \\nabla E(u^{(0)}) \\in V^*$ and\n  for $k\\ge 0$ iteratively\n  \\begin{xalignat}2\n    \\scal(p^{(k)},v) &= \\scal({-\\nabla E(u^{(k)})},v)_{V^*\\times V} &\\forall v&\\in V \\\\\n    \\alpha_k &= \\operatorname*{argmin}_{\\alpha>0} E\\left(u^{(k)} + \\alpha p^{(k)}\\right)\\\\\n    u^{(k+1)} &= u^{(k)} + \\alpha_k p^{(k)}\n  \\end{xalignat}\n\\end{Definition*}\n\n\\begin{Lemma}{steepest-descent}\n  Let $u\\in V$ be the unique minimizer of the energy functional $E(.)$. Then, there holds for all $k$\n  \\begin{gather}\n    a\\left(u^{(k+1)}-u, p^{(k)}\\right) = a(u^{(k+1)}, p^{(k)}) - f(p^{(k)}) = 0.\n  \\end{gather}\n  With $r^{(k)} = f-a(u^{(k)},.)\\in V^*$, there holds\n  \\begin{gather}\n    \\alpha_k = \\frac{\\scal(r^{(k)},p^{(k)})_{V^*\\times V}}{a\\left(p^{(k)},p^{(k)}\\right)}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Definition}{cg-method}\n  Let $V$ be a Hilbert space and $V^*$ its dual. The \\define{conjugate\n  gradient method} for an iteration vector $u^{(k)} \\in V$ involves the\n  residuals $r^{(k)} \\in V^*$ as well as the update direction $p^{(k)}\n  \\in V$ and the auxiliary vector $w^{(k)} \\in V$. It consists of the\n  steps\n  \\begin{enumerate}\n  \\item Initialization: for $f$ and $u^{(0)}$ given, compute $r^{(0)} = f- a(u^{(0)},.)$ and\n    \\begin{xalignat*}{2}\n      \\scal(p^{(0)}, v) = \\scal(w^{(0)}, v) &= \\scal(r^{(0)},v)_{V^*\\times V} & \\forall v &\\in V.\n    \\end{xalignat*}\n    \\item Iteration step: for $u^{(k)}$, $r^{(k)}$, $w^{(k)}$, and\n      $p^{(k)}$ given, compute\n      \\begin{xalignat*}2\n        u^{(k+1)} &= u^{(k)} + \\alpha_k p^{(k)}\n        &\n        \\alpha_k &= \\frac{\\scal(r^{(k)},w^{(k)})_{V^*\\times V}}{a\\left(p^{(k)},p^{(k)}\\right)} \\\\\n        r^{(k+1)} &= r^{(k)} - \\alpha_k a\\left(p^{(k)},.\\right) \\\\\n      \\scal(w^{(k+1)}, v) &= \\scal(r^{(k+1)},v)_{V^*\\times V} & \\forall v &\\in V \\\\\n      p^{(k+1)} &= w^{(k+1)} + \\beta_k p^{(k)}\n      &\n      \\beta_k &= \\frac{\\scal(r^{(k+1)},w^{(k+1)})_{V^*\\times V}}{\\scal(r^{(k)},w^{(k)})_{V^*\\times V}}\n      \\end{xalignat*}\n  \\end{enumerate}\n\\end{Definition}\n\n% \\begin{remark}\n%   The results on orthogonality and minimization properties of the cg\n%   method in~\\cite{GrossmannRoosStynes07} or~\\cite{Saad00} remain valid in this\n%   context. Differences occur in the interpretation of these\n%   properties. The conjugate gradient method does not necessarily\n%   converge in a finite number of steps, and if the bilinear form is\n%   unbounded, no convergence rate is guaranteed.\n% \\end{remark}\n\n% \\begin{lemma}\n%   Let $a(.,.)$ be symmetric and elliptic. Then, either $u^{(k)}$ is a\n%   solution, or $u^{(k+1)}$ can be computed by a step of the conjugate\n%   gradient method. Furthermore, there are the \n% \\end{lemma}\n\n\\begin{Definition}{pcg-method}\n  The \\define{preconditioned cg method} is obtained from\n  above algorithm by reinterpreting the \\putindex{Riesz isomorphism}\n  in the computation of $w^{(k+1)}$ as a preconditioning operation,\n  much alike Definition~\\ref{definition:richardson:2} of the\n  preconditioned Richardson iteration. Thus, the line defining\n  $w^{(k+1)}$ is replaced by\n  \\begin{xalignat*}2\n    b(w^{(k+1)}, v) &= r^{(k+1)}(v) & \\forall v &\\in V .\n  \\end{xalignat*}\n  Here, like there, the preconditioner enters naturally from the weak\n  form of the algorithm.\n\\end{Definition}\n\n\\begin{Definition}{krylov-space}\n  The $n$th \\define{Krylov space} as subspace of the Hilbert space $V$\n  with inner product $b(.,.)$ of the operator $A$ and seed vector\n  $w \\in V$ is\n  \\begin{gather}\n    \\label{eq:cg:2}\n    \\mathcal K_n = \\mathcal K_n(B^{-1}A, w)\n    = \\operatorname{span}\\left\\{w, B^{-1}A w, (B^{-1}A)^2 w, \\dots, (B^{-1}A w)^{n-1}\\right\\}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{cg-orthogonality}\n  The vectors generated by the conjugate gradient iteration have the\n  following properties: either $u^{(k)}$ is the solution to the\n  linear system or\n  \\begin{alignat}2\n    r^{(k)} &= f - a(u^{(k)},.)\\\\\n    \\scal(r^{(k)},w^{(k)})_{V^*\\times V} &= \\scal(r^{(k)},p^{(k)})_{V^*\\times V} \\\\\n    \\scal(r^{(k)},p^{(j)}) &= 0 & j&<k\\\\\n    a(p^{(k)},p^{(j)}) &= 0 & j&<k\\\\\n    \\scal(r^{(k)},r^{(j)}) &= 0 & j&<k\n  \\end{alignat}\n\\end{Lemma}\n\n\\begin{Lemma}{cg-minimization}\n  The iterates of the cg method have the following minimization\n  properties:\n  \\begin{gather}\n    \\label{eq:cg:3}\n    \\begin{split}\n      \\norm{u^{(k)}-u}_A &= \\min_{v\\in \\mathcal K_k} \\norm{u^{(0)} + v -u}_A \\\\\n      &= \\min_{\\substack{p\\in P_{n-1}\\\\ p(0) = 1}}\n      \\norm{u^{(0)} + p(B^{-1}A) w -u}_A.\n    \\end{split}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Theorem}{cg-convergence}\n  Let the bilinear form $a(.,.)$ be symmetric, and let the\n  \\putindex{spectral equivalence} hold. Then,\n  the preconditioned cg method converges and we have the estimate\n  \\begin{gather}\n    \\label{eq:cg:1}\n    \\norm{u^{(k)} - u}_A \\le 2\n    \\left(\\frac{\\sqrt\\kappa-1}{\\sqrt\\kappa+1}\\right)^k \\norm{u^{(0)} - u}_A.\n  \\end{gather}\n  Here, $\\kappa = \\Lambda/\\lambda$ is the \\putindex{spectral condition\n    number} of the preconditioned problem.\n\\end{Theorem}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "154b3f1f2d112142f8e227473b301f4b33b7cfa2", "size": 5992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "iteration/cg.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iteration/cg.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "iteration/cg.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.1633986928, "max_line_length": 102, "alphanum_fraction": 0.6111481976, "num_tokens": 2176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.6992804304819682}}
{"text": "\\section{Uninformed search}\n\nLet:\n\\begin{itemize}\n  \\item $b$ is the average branching factor \n  \\item $d$ is the depth level\n  \\item $m$ is the maximum depth of the search space\n\\end{itemize}\n\n\nThen:\n\\begin{table}[hb!]\n\\begin{adjustwidth}{-2.5cm}{-2.5cm}\n\\resizebox{1.3\\columnwidth}{!}{\n\\begin{tabular}{lllllll}\n  Strategy & \n  Complete & \n  Time & \n  Space & \n  Optimal & \n  Implementation & \n  Comment \\\\\n  BFS &\n  If $b$ is finite &\n  $O(b^d)$ &\n  $O(b^d)$ &\n  \\multicolumn{1}{p{0.11\\linewidth}}{Yes, if uniform cost} &\n  FIFO &\n  \\multicolumn{1}{p{0.17\\linewidth}}{High memory, exponential time} \\\\\n  DFS &\n  \\multicolumn{1}{p{0.17\\linewidth}}{No, fails in: infinite depth spaces and spaces with loops} & \n  $O(b^m)$ &\n  $O(bm)$ &\n  No &\n  LIFO &\n  \\multicolumn{1}{p{0.18\\linewidth}}{Bad if $m$ is much larger than $d$ but if solutions are dense, may be much faster than BFS} \\\\\n  \\multicolumn{1}{p{0.13\\linewidth}}{Depth limited Search} &\n  &\n  &\n  &\n  &\n  DFS with limit \\\\\n  & \\\\\n  Iterative Deepening &\n  &\n  &\n  &\n  & \n  \\multicolumn{1}{p{0.20\\linewidth}}{Depth deepening with increasing limits} & \n  \\multicolumn{1}{p{0.20\\linewidth}}{Benefits of BFS and DFS} \\\\\n  Uniform cost &\n  \\multicolumn{1}{p{0.20\\linewidth}}{Yes, if solution has finite cost} &\n  $O(b^{C^*/\\varepsilon})$ &\n  \\multicolumn{1}{p{0.18\\linewidth}}{\\# of nodes with $g\\leq C^* \\rightarrow O(b^{C^*/\\varepsilon})$} &\n  Yes &\n  \\multicolumn{1}{p{0.20\\linewidth}}{BFS expanding by cost of path (not of last step)}\n\\end{tabular}}\n\\caption{Uninformed Search Strategies}\n\\label{tab:my_label}\n\\end{adjustwidth}\n\\end{table}\n\n", "meta": {"hexsha": "8b410067fabd4bb90eb2a1f017ea3ee8af649eb1", "size": 1598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/uninformed_search.tex", "max_stars_repo_name": "Calcifer777/columbia-ai", "max_stars_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/uninformed_search.tex", "max_issues_repo_name": "Calcifer777/columbia-ai", "max_issues_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/uninformed_search.tex", "max_forks_repo_name": "Calcifer777/columbia-ai", "max_forks_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3650793651, "max_line_length": 131, "alphanum_fraction": 0.6420525657, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.6992804273654354}}
{"text": "%!TEX root =  ../main.tex\n\n\n\\section{Analytic Geometry}\\label{sec:AG}\n\n\n\\objective{Calculate distances and midpoints on the Cartesian coordinate plane for order pairs from\nfunctions and relations.}\n\n\n\\subsection{Cartesian Plane}\nDescartes did many strange things in philosophy, but he was a real boon for mathematics.  The idea\nof graphing values of one variable ($x$) to the left and right, while simultaneously graphing another\nvariable ($y$) on the up and down is credited to him.  This is called the \\gls{Cartesian plane} \nor ``Rectangular Coordinates''.\n\n\\subsubsection{Quadrants}\nIt is customary to split the coordinate system into four quadrants, numbered with Roman numerals.\nQuadrant I is where $x$ and $y$ are both positive, to the upper right.  Quadrant II is where $x$ is negative\nbut $y$ is positive, to the upper left.  Quadrant III is where both are negative, to the lower left.  Quadrant\nIV is where $x$ is positive and $y$ is negative, to the lower right.\n\n\\subsection{Triangles}\nJust as we might find the middle between two numbers on the number line, \nso too we can find a point midway \nbetween two other points, simply by taking the average of their $x$s and the average of their $y$s.\n\n\\begin{derivation}{Midpoint}\nGiven two points $(x_1,y_1)$ and $(x_2,y_2)$ the arithmetic mean of the $x$'s is $x$ of the midpoint,\nand the same for $y$.\n\nMidpoint $(x,y)=(\\frac{x_1+x_2}{2},\\frac{y_1+y_2}{2})$\n\\end{derivation}\n\nIf we draw a right-triangle with its hypotenuse being the shortest path between two points, and its legs going\nstrictly left-to-right and up-to-down, then calculating their distance is simply the Pythagorean Theorem.\n\n\\begin{derivation}{Pythagorean Theorem}\nThe distance from $(x_1,y_1)$ to $(x_2,y_2)$ is the hypotenuse of a right triangle with legs\n$|x_2-x_1|$ and $|y_2-y_1|$.\n\n\\begin{equation}\nd=\\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\n\\end{equation}\n\\end{derivation}\n\n\\subsection{Functions and Relations}\n\nChapter 1 proper of this textbook is about functions, but even more basic are relations.  \nFor number, it will suffice\nto say that any equation with $x$s and $y$s in it is a \nrelation\\footnote{Note that these need not be ``nice''.  For example,\n$x^2y^2=4$ produces an infinite, four-pointed star, but must be put into the TI-8* as \\texttt{Y1=sqrt(4/x\\^2)} and \n\\texttt{Y2=-sqrt(4/x\\^2)}.}.  \n\nlike \n\\begin{derivation}{Relation}\nA relation between two sets is a collection of ordered pairs containing one object from each set. \nIf the object $x$ is from the first set and the object $y$ is from the second set, then the objects are said to be related if the ordered pair $(x,y)$ is in the relation.\n\\end{derivation}\n\n\\ExSection[Exercises]\n\\begin{exercises}{sec:AG}\n\\index{Absolute Value!of y}\n\\prob{}Graph the relation $x=|y|$.  How could we put this into our TI-8*?\n\n\n\n\\prob{}Use the Pythagorean theorem to find 12 lattice points 5 units from the origin.\n\n\\prob{}Find the relation describing all the ordered pairs 5 units from the origin.\n\n\\prob{}What are the points 5 units away from 4,2 with a y value of 10?\n\n\\prob{}What are the points 6 units away from -2,-1 with a x value of -10\n\n\\prob{}What are the points root 10 units away from 0,2 and root 10 units away from 2,0?\n\\end{exercises}\n", "meta": {"hexsha": "644cd0c9d68f18e39b4dda59548fa9afe451de90", "size": 3226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chAA/appendix04ag.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "chAA/appendix04ag.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chAA/appendix04ag.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": 40.835443038, "max_line_length": 170, "alphanum_fraction": 0.7436453813, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.699280418777809}}
{"text": "\\lab{Algorithms}{The Pseudospectral method for Boundary Value Problems}{The Pseudospectral method for Boundary Value Problems}\n\\label{lab:pseudospectral1}\n\nSuppose we have a set of grid points $\\{x_i\\}_{i=0}^N$ on an interval $I$, and function values $u(x_i)$ at those points.\nWhat is the best way to approximate the derivative $u'(x)$?\n\nHere is one idea: We can construct a polynomial $p(x)$ that interpolates the data $(x_i,u(x_i))$.\nThen $p'(x)$ could be used as an approximation to $u'(x)$.\nHowever, if we recall Runge's phenomena we can easily see that in general $p(x)$ can be a very poor approximation for $u(x)$, and in this case we could hardly expect $p'(x)$ to approximate $u'(x)$ well. \n\nThe key idea we need here is that the grid points $x_i$ must be carefully chosen.\nFor example, consider the interval $I = [-1,1]$.\nInstead of using equally spaced grid points, let the grid $\\{x_i\\}_{i=0}^N$ consist of the Chebychev points \n\\[x_i = \\cos (i \\pi /N), \\quad i = 0, 1, \\ldots, N.\\]\n% They've already seen this in several other labs.\n% We shouldn't repeat it here.\n\\begin{comment}\nExperiment with the following code to view Runge's phenomena and see the convergence when the Chebychev points are used.\n\n\\begin{lstlisting}\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.interpolate import BarycentricInterpolator\n\ndef f(x):\n\treturn 1./(1.+16.*x**2.)\n\nN = 10\n# grid = np.cos(np.pi*np.arange(N+1)/N)\t\t# Chebychev grid\ngrid = np.linspace(-1,1,N+1)\np = BarycentricInterpolator(grid,f(grid) )\n\nx = np.linspace(-1,1,200)\nprint \"The Maximum Error is \", np.max(np.abs((p(x)-f(x))))\nplt.plot(x,f(x),'-k')\nplt.plot(grid,f(grid),'*k')\nplt.plot(x,p(x),'-r')\nplt.show()\n\\end{lstlisting}\n\nAs long as the function $u(x)$ is smooth, the interpolating polynomial $p(x)$ will converge to $u(x)$ rapidly.\nFor example, if $u$ is analytic then $p(x)$ will converge to $u(x)$ at the rate $\\mathcal{O}(k^n)$ where $0<k<1$.\nThis convergence rate is faster than $\\mathcal{O}(1/N^k)$ for any $k$. $p'(x)$ converges to $u'(x)$ at a similar rate. \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=9cm]{equally_spaced_points.png}\n\\caption{Runge's Phenomenon: The polynomial interpolant $p(x)$ of  $1/(1+16x^2)$ at 17 equally spaced grid points has an error of 5.88.\nThis error grows as the number of grid points increases.}\n\\label{fig:Spectral1_equally_spaced_points}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=9cm]{chebychev_points.png}\n\\caption{The polynomial interpolant $p(x)$ of $1/(1+16x^2)$ at 17 chebychev grid points has an error of 0.0175.\nThis error decreases rapidly as the number of grid points increases.}\n\\label{fig:Spectral1_chebychev_points}\n\\end{figure}\n\\end{comment}\n\n\\section*{The Differentation Matrix}\nLet $u$ be a function defined on $[-1,1]$.\nThe polynomial $p(x)$ that interpolates $u$ at the Chebyshev points can be expanded in the form \n\\[p(x) = \\sum_{j=0}^N u(x_j)C_j(x),\\]\nwhere each of the basis functions $C_j$ are cardinal functions, defined to be the polynomials of least degree satisfying\n\\begin{equation*}\nC_j(x_i) = \\begin{cases} 1 & i=j \\\\ 0 & i \\not = j.\n   \\end{cases}\n\\end{equation*}\n\nThen \n\\[u'(x_i) \\approx p'(x_i) = \\sum_{j=0}^N u(x_j)C_j'(x_i) \\quad \\text{ where } i = 0, \\ldots N.\\]\nThis can be written in matrix form as \n\\begin{equation*}\n\t\\left[\\begin{array}{c}p'(x_0) \\\\p'(x_1)\\\\\\vdots \\\\p'(x_N)\\end{array}\\right] =\n\\left[\\begin{array}{cccc}C_0'(x_0) & C_1'(x_0) & \\ldots & C_N'(x_0) \\\\C_0'(x_1) & C_1'(x_1) & \\ldots & C_N'(x_1) \\\\\\vdots &  &  & \\vdots \\\\C_0'(x_N) & C_1'(x_N) & \\ldots & C_N'(x_N)\\end{array}\\right]\n\\left[\\begin{array}{c}u(x_0) \\\\u(x_1)\\\\\\vdots \\\\u(x_N)\\end{array}\\right],\n\\end{equation*}\nor in shorthand as \n\\[U' = D U,\\]\nwhere $U'$ represents the approximation to $u'$ using the polynomial $p'$.\n% Let $U = [u(x_0),\\ldots, u(x_N)]^T$ and $U' = [u'(x_0),\\ldots, u'(x_N)]^T$.\nThe matrix $D$ is given by\n\\begin{equation*}\nD_{ij} = C_j'(x_i) = \\begin{cases} (1+2N^2)/6 & i=j=0 \\\\ -(1+2N^2)/6 & i=j=N \\\\\n-x_j/[2(1-x_j^2)] & i=j, \\, 0<j<N \\\\ \n(-1)^{i+j}\\alpha_i/[\\alpha_j(x_i-x_j)] & i \\not = j\n   \\end{cases}\n\\end{equation*}\nwhere $\\alpha_0 = \\alpha_N = 2,$ and $\\alpha_j = 1$ otherwise. \n\n$u'(x)$ can be approximated for values of $x$ not on the grid by interpolating the values of $p'$ at the grid points.\n% \\begin{equation*}\n% u'(x) \\approx p'(x) =  \\sum_{j=0}^N p'(x_j)C_j(x).\n% \\end{equation*}\n% Thus $p'$ is an analytic function that approximates $u'$, and not just at the grid points. \nTo evaluate $p'(x),$ use barycentric interpolation on the grid $(x_i,p'(x_i))$.\n\n\\begin{problem}\n% They've already done this in the Chebyschev lab.\n\\begin{comment}\nCreate a function \\li{cheb} that takes in a positive integer $N$ and returns the grid $\\{x_j\\}_{j=0}^N$ of Chebychev points and the differentation matrix $D$ associated with that grid.\n\\end{comment}\n\t\nUse the differentiation matrix to find the numerical derivative of $u(x) = e^{x}\\cos(6x)$ on a grid of Chebychev points for several values of $N:$ $N=6, 8, 10.$\nThen use barycentric interpolation to approximate $u'$ on the grid \\li{np.linspace(-1,1,100)}.\nGraphically compare those values to the exact derivative. \n\\end{problem}\n\nTo approximate $u''(x)$ on the grid $\\{x_i\\}$, we use \n\\[U'' \\approx D^2 U.\\]\nSolving the bvp\n\\begin{align*}\nu'' &= f(x), \\\\\nu(-1) &= 0, \\\\\nu(1) &= 0,\n\\end{align*}\non the grid $\\{x_i\\}$ amounts to solving the system \n\\[D^2 U = F,\\]\nwhere $F = [f(x_0),\\ldots, f(x_N)]^T$.\nSince we have Dirichlet boundary conditions of $0$, we can satisfy the boundary condition by forcing $U[0] = U[N] = 0$.\n(We say there are Dirichlet boundary conditions when both boundary conditions are constant values for $u$).\nThis allows us to ignore the first and last equations in the system, giving us the new system \n\\[\\tilde{D}^2 \\tilde{U} = \\tilde{F},\\]\nwhere $\\tilde{D} = D[1:N,1:N]$, $\\tilde{U} = U[1:N]$, and $\\tilde{F} = F[1:N]$.\nSome modifications are necessary to account for nonzero Dirichlet boundary conditions.\n\n\\begin{problem}\nUse the pseudospectral method to solve the boundary value problem \n\\begin{align*}\nu'' &= e^{2x}, \\\\\nu(-1) &= 0, \\\\\nu(1) &= 0\n\\end{align*}\nCompare your numerical solution with the exact solution.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{nonzeroDirichlet.pdf}\n\\caption{The solution of $u'' + u' = e^{3x}$, subject to the boundary conditions \n$u(-1) = 2$, $u(1) = -1$.}\n\\label{fig:nonzeroDirichlet}\n\\end{figure}\n\n\\begin{problem}\nUse the pseudospectral method to solve the boundary value problem \n\\begin{align*}\nu'' + u' &= e^{3x}, \\\\\nu(-1) &= 2, \\\\\nu(1) &= -1.\n\\end{align*}\nCheck that your numerical solution is converging.\nHow many subintervals are required to find the solution correct to three decimal places?\nSee Figure \\ref{fig:nonzeroDirichlet}.\n\t\nHint: Reduce the problem to one with zero Dirichlet conditions by letting $u = U+G$, where $G$ is a (simple) function satisfying the boundary conditions.\n\\end{problem}\n\n\\begin{comment}\n\\section*{The Method of Weighted Residuals}\nWe may write our differential/integral equation in operator notation as \n\\[(Lu)(x) = f(x), \\quad x \\in \\Omega\\]\nwhere $u$ belongs to some infinite-dimensional function space $V.$\nWe seek for an approximation $u_N$ to the solution $u$.\nOur approximation $u_N$ will come from a finite-dimensional function space $S_N$ called the trial space.\nHere we use $N$ to denote the dimension of $S_N \\subset V$. \nThe space $S_N$ can be described by a basis $\\{\\phi_1(x), \\ldots, \\phi_N(x)\\}$.\nThen an approximation $u_N \\in S_N$ has the form \n\\[u_N = \\sum_{j=1}^N \\gamma_j \\phi_j\\]\n\nWe can then define an operator $\\mathcal{R}$ on the trial space $S_N$ by \n\\[\\mathcal{R}u_N(x) = Lu_N(x) - f(x)\\] \n$\\mathcal{R}u_N$ is called the residual or the error of the trial function $u_N$.\nNote that the residual of the true solution $u$ is zero.\nThe method of weighted residuals is a family of methods that determine the coefficients $\\gamma_j$ of the approximate solution $u_N$ by forcing the residual $\\mathcal{R}u_N$ to be zero in some weighted average over $\\Omega$.\nIn other words, given some collection of weight/test functions $\\{w_i\\}_{i=1}^M$, we require that \n\\begin{align}\n\\int_{\\Omega}\\mathcal{R}u_N(x) w_i(x)\\, dx &= 0, \\quad \\text{ for } i = 1, \\ldots M\n\\label{eqn:Spectral1_weightedaverage}\n\\end{align}\n\nAfter doing the integration described by (\\ref{eqn:Spectral1_weightedaverage}), we obtain a system of algebraic equations that may be used to determine the coefficients $\\gamma_i$.\nDifferent choices of the trial space $S_N$ and the weight/test functions $w_i(x)$ result in different methods. \n\nWe obtain the pseudospectral method (or collocation method) by choosing a collection of points $\\{x_i\\}_{i=1}^M$ in our space $\\Omega$ called collocation points.\nThe weight functions $w_i(x)$ are then given by $w_i(x) = \\delta(x-x_i); $ that is, $w_i$ is the Dirac delta function centered at $x_i$.\nThen the equations \\ref{eqn:Spectral1_weightedaverage} are given by \n\\begin{align*}\n\t\\int_{\\Omega} \\mathcal{R}u_N w_i(x) \\, dx &= 0,\\\\\n\t\\int_{\\Omega} \\mathcal{R}u_N \\delta(x-x_i) \\, dx &= 0, \\\\\n\t\\mathcal{R}u_N(x_i) &= 0 \\quad \\text{ for } i = 1, \\ldots, M\n\\end{align*}\nThus the pseudospectral method requires the residual of the approximate solution to be exactly zero at the collocation points.\nAlternatively, the approximate solution satisfies the differential equation exactly at the collocation points. \n\\end{comment}", "meta": {"hexsha": "bb3d298cfb50d7cb120d648bb7f4af7e6fe9a4a1", "size": 9418, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Spectral1/Spectral1.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Spectral1/Spectral1.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Spectral1/Spectral1.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": 47.807106599, "max_line_length": 224, "alphanum_fraction": 0.6983435974, "num_tokens": 3074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152324713956856, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.6992804091513377}}
{"text": "\n\\section{Realizability}\n\\label{sec:realizability}\n\nWe briefly motivate the main idea of (typed) realizability. When we\nrepresent a set of mathematical objects~$S$ in a programming\nlanguage~$\\PL$ there are two natural steps to take: first choose an\n\\emph{underlying type~$\\ut{S}$} of representing values, and second\nspecify how the values of type~$\\ut{S}$ represent, or \\emph{realize},\nelements of the set~$S$. For example, consider how we might represent\nthe set~$D$ of simple finite directed graphs (whose vertices are\nlabeled by integers). As the underlying datatype we might choose\n$\\ut{D} = \\mathtt{int} \\; \\mathtt{list} *\\, (\\mathtt{int} *\n\\mathtt{int}) \\mathtt{list}$, and represent a graph~$G \\in D$ as a\npair of lists $(v,e)$ where $v = [x_1; \\ldots; x_n]$ is the list of\nvertices and $e = [e_1; \\ldots; e_m]$ is the list of edges. Formally,\nwe write\n%\n\\begin{equation*}\n  (v, e) \\rz_D G\n\\end{equation*}\n%\nand read it as ``$(v,e)$ realizes~$G \\in D$''. Observe that each graph\nis realized by at least one pair of lists, and that no pair of lists\nrepresents more than one graph. (As commonly occurs, most graphs are\nrepresented by many different pairs of lists.) This leads us to the definition given\nbelow. We shall abuse notation slightly and write $t \\in \\ut{S}$ to\nmean that $t$ is a closed expression of type $\\ut{S}$.\n\n\n\\begin{figure*}\n\\[\n  \\hspace{-0.5truecm}\n  \\parbox[t]{0.28\\textwidth}{\n\\footnotesize\n    \\begin{align*}\n      \\ut{\\top} &= \\mathtt{unit} \\\\\n      \\ut{\\bot} &= \\mathtt{unit} \\\\\n      \\ut{x =_S y} &= \\mathtt{unit} \\\\\n      \\ut{\\phi \\land \\psi} &= \\ut{\\phi} * \\ut{\\psi} \\\\\n      \\ut{\\phi \\implies \\psi} &= \\ut{\\phi} \\to \\ut{\\psi} \\\\\n      \\ut{\\phi \\lor \\psi} &= \\ut{\\phi} + \\ut{\\psi} \\\\\n      &\\\\\n      \\ut{\\forall x \\in A .\\, \\phi(x)} &= \\ut{A} \\to \\ut{\\phi} \\\\\n      \\ut{\\exists x \\in A .\\, \\phi(x)} &= \\ut{A} \\times \\ut{\\phi}\n    \\end{align*}\n  }\n\\ \\vrule\\ \n  \\parbox[t]{0.5\\textwidth}{\n\\footnotesize\n    \\begin{align*}\n      () \\rz \\top &\n      \\\\\n      &\n      \\\\\n      () \\rz x =_S y\n        &\\quad\\text{iff}\\quad \n      x \\per{S} y\n      \\\\\n      (t_1,t_2) \\rz \\phi \\land \\psi\n        &\\quad\\text{iff}\\quad\n        \\text{$t_1 \\rz \\phi$ and $t_2 \\rz \\psi$}\n      \\\\\n      t \\rz \\phi \\implies \\psi\n        &\\quad\\text{iff}\\quad\n        \\text{for all $u \\in \\ut{\\phi}$, if $u \\rz \\phi$ then $t\\,u\n          \\rz \\psi$}\n      \\\\\n      \\inl{t} \\rz \\phi \\lor \\psi\n        &\\quad\\text{iff}\\quad\n        \\text{$t \\rz \\phi$}\n      \\\\\n      \\inr{t} \\rz \\phi \\lor \\psi\n        &\\quad\\text{iff}\\quad\n        \\text{$t \\rz \\psi$}\n      \\\\\n      t \\rz \\forall x \\in A . \\phi(x)\n        &\\quad\\text{iff}\\quad\n        \\text{for all $u \\in \\ut{A}$, if $u \\rz_A x$ then $t\\,u \\rz \\phi(x)$}\n      \\\\\n      (t_1, t_2) \\rz \\exists x \\in A . \\phi(x)\n        &\\quad\\text{iff}\\quad\n        \\text{$t_1 \\rz_A x$ and $t_2 \\rz \\phi(x)$}\n    \\end{align*}\n  }\n\\]\n  \\caption{Realizability interpretation of logic (outline)}\n  \\label{fig:rz-logic}\n\\end{figure*}\n\n\\begin{definition}\n  A \\emph{modest set}\\footnote{Modest sets were so named by Dana\n    Scott. They are ``modest'' because their size cannot exceed the\n    number of expressions of the underlying datatype.} is a triple\n  $(S, \\ut{S}, {\\rz_S})$ where $S$ is a set, $\\ut{S}$ is a type and\n  $\\rz_S$ is a relation between expressions of type~$\\ut{S}$ and\n  elements of~$S$, satisfying:\n  % \n  \\begin{enumerate}\n  \\item For every $x \\in S$ there is $t \\in \\ut{S}$ such that $t \\rz_S\n    x$.\n  \\item If $t \\rz_S x$ and $t \\rz_S y$ then $x = y$.\n  \\end{enumerate}\n  %\n  A \\emph{realized function} $f : (S, \\ut{S}, {\\rz_S}) \\to (T, \\ut{T},\n  {\\rz_T})$ between modest sets is a function $f : S \\to T$ for which\n  there exists $u \\in \\ut{S} \\to \\ut{T}$ such that\n  %\n  \\begin{equation*}\n    t \\rz_S x \\implies u\\,t \\rz_T f(x) \\;.\n  \\end{equation*}\n  %\n  We say that $u$ \\emph{realizes}~$f$.\n\\end{definition}\n\nThe realizer~$u$ of a realized function~$f$ is more commonly known as\nan ``implementation of~$f$'' or an ``algorithm for computing~$f$''.\n\nModest sets and realized functions form a category of \\emph{modest\n  sets~$\\Mod{\\PL}$}. In realizability theory this is a well known\ncategory with good properties. It is regular and locally bi-cartesian\nclosed, which allows us to interpret first-order logic and a rich type\ntheory. Here we only outline the main ideas behind the realizability\ninterpretation of logic. See e.g.~\\cite{Bauer:00} for details.\n\nIn the realizability interpretation of logic, each formula~$\\phi$ is\nassigned a set of \\emph{realizers} which can be thought of as\ncomputations that witness the validity of~$\\phi$. The situation is\nsomewhat similar (but not equivalent) to the propositions-as-types\ntranslation of logic into type theory, where the proofs of a\nproposition correspond to terms of the corresponding type. More\nprecisely, to each formula~$\\phi$ we assign an underlying type\n$\\ut{\\phi}$ of realizers. However, unlike in the propositions-as-types\ntranslation, not all terms of type $\\ut{\\phi}$ are necessarily valid\nrealizers for~$\\phi$. We write $t \\rz \\phi$ when $t \\in \\ut{\\phi}$ is\na realizer for~$\\phi$. The underlying types and the\nrealizability relation~$\\rz$ are defined inductively on the structure\nof~$\\phi$; an outline is shown in Figure~\\ref{fig:rz-logic}. We say that a\nformula~$\\phi$ is \\emph{valid} in~$\\Mod{\\PL}$ if it has at least one\nrealizer.\n\nWe shall not dwell any further on the technicalities involving the\ncategory of modest sets, but rather proceed to a concrete description\nof our realizability translation. There is one technical point,\nthough, which we first take care of. A modest set is a triple $(S,\n\\ut{S}, {\\rz_S})$ in which~$S$ is an arbitrary set. For an automated\nsystem it would be convenient if it did not have to refer to arbitrary\nsets but rather just to ingredients that are already present in the\nprogramming language, such as types and sets of expressions. Up to\nequivalence of categories, modest sets can be constructed as triples\n$(\\ut{S}, \\tot{S}, {\\per{S}})$ where $\\ut{S}$ is a type, $\\tot{S}$ is\na subset of expressions of type~$\\ut{S}$, called the \\emph{total\n  values},\\footnote{We do \\emph{not} require that a total value must\n  be a terminating expression.} and $\\per{S}$ is an equivalence\nrelation on~$\\tot{S}$. The relationship between this representation of\na modest set and the original one is as follows:\n%\n\\begin{itemize}\n\\item $\\tot{S}$ is the set of those $t \\in \\ut{S}$ that\n  realize something, i.e., there is $x \\in S$ such that $t \\rz_S x$.\n  These correspond to implementations that satisfy\n  the representation invariant, e.g., graphs where the list of edges\n  mentions only integers in the list of nodes, a subset of\n  all values of type $\\mathtt{int} \\; \\mathtt{list} * (\\mathtt{int} *\n\\mathtt{int}) \\; \\mathtt{list}$.\n\\item $t \\per{S} u$ if $t$ and $u$ realize the same element, i.e.,\n  there is $x \\in S$ such that $t \\rz_S x$ and $u \\rz_S x$.\n  This relation equates alternate concrete representations of the same\n  abstract value, e.g., equating two concrete graph representations differing\n  only in the order of the nodes or the order of the edges.\n\\end{itemize}\n%\nThe alternative view of a modest set $(\\ut{S}, \\tot{S}, {\\per{S}})$\nonly refers to objects and concepts from the programming language. It\nis better suited for our purposes.\n\nNote that the equivalence relation on~$\\tot{S}$ is also a\n\\emph{partial} equivalence relation on~$\\ut{S}$, which shows that\nmodest sets are in fact equivalent to PER models.\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"case\"\n%%% End: \n", "meta": {"hexsha": "54aa60dcb0762cb619b608de8ac2a5c1f58bb4a1", "size": 7551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "private/clase/realizability.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/clase/realizability.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/clase/realizability.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": 40.5967741935, "max_line_length": 84, "alphanum_fraction": 0.6587206992, "num_tokens": 2415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6992409177994939}}
{"text": "\n\\subsection{Capsules}\n\n\\subsubsection{Primary capsule layers}\n\nOutputs of convolutions are scalars. however we can also create vectors, if we associate some convolutions with each other\n\neg if we have 6 convolutions, the output of these can be used to create a 6 dimensional vector for each window.\n\n\\subsubsection{Normalisation in primary capsule layers (vector squishing)}\n\nWe can normalise the length of these vectors to between \\(0\\) and \\(1\\).\n\nThe output of this repesents the chance of finding the feature they are looking for, and the orientation\n\nIf the vector length is low, feature not found. if high, feature found.\n\nWe have orientation from vector, and position from window\n\n\\subsubsection{Routing capsule layers}\n\nWe now have a layer of position and orientation of basic shapes (triangles, rectangles etc)\n\nWe want to know which more complex thing they are part of.\n\nSo the output of this step is again a matrix with position and orientation, but of more complex features\n\nTo determine the activation from each basic shape to the next feature we use routing-by-agreement.\n\nThis takes each basic shape and works out what it would look like if the complex feature was present.\n\nIf a complex feature has two basic shapes, they will both have the same predicted complex shape. Otherwise the relationship is spurious and they will not\n\nIf they agree we have a high weight\n\nThis process is complex and computationally expensive.\n\nHowever we don't need pooling layers now\n\n\\subsubsection{caps net}\n\nDoes normal conv first, then primary, then secondary.\n\n\\subsubsection{caps: reconstruction}\n\nWe have vector space of feature position and orietnation. we can recreate output\n\n", "meta": {"hexsha": "3cc883c371225bac586ea3ae8593b4611a52677d", "size": 1682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/03-01-capsules.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/03-01-capsules.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/03-01-capsules.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": 35.0416666667, "max_line_length": 153, "alphanum_fraction": 0.7966706302, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6992409043163748}}
{"text": "\\chapter{Algebraic Integers}\n\t\\setcounter{page}{1}\n\t\\pagenumbering{arabic}\n\t\\section{Integral closure and algebraic integers}\n\t\tHere we present fundamental properties of algebraic integers and related theories. It is not our intention to do a treatise of commutative algebra and Galois theory, so for example there would not be the fundamental theorem of Galois theory, or the definition of Dedekind domain. However, if some theorems are explicitly useful in the future, you will still see the theorem and the proof.\n\t\t\\subsection{Definition and examples}\n\t\t\tProblems in solving polynomial equations give rise to a lot of concepts in algebra and geometry. If we are specifically interested in $\\mds{Z}$, we have the concept of \\textbf{algebraic integers}.\n\t\t\t\\begin{definition}\n\t\t\t\tA finite extension $K$ of the rational number $\\mds{Q}$ is called a \\textbf{number field}. The integral closure of $\\mds{Z}$ in $K$ is called the ring of \\textbf{algebraic integers} of $K$, and is denoted by $\\OK$. To be precise, every element $x \\in \\OK$ is a zero of a monic polynomial $f \\in \\Z[X].$\n\t\t\t\\end{definition}\n\t\t\t\n\t\t\tFor this concept we have a lot of classic examples:\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tIf $K=\\Q$, then $\\OK$ is simply $\\Z$. This is intuitive because suppose $x=a/b \\in \\Q$ is integral over $\\Z$ where $(a,b)=1$, then\n\t\t\t\t\\[\n\t\t\t\tx^n+c_1x^{n-1}+\\cdots+c_n = 0\n\t\t\t\t\\]\n\t\t\t\twhere $c_i \\in \\Z$. Multiplying by $b^n$ yields\n\t\t\t\t\\[\n\t\t\t\ta^n+c_1a^{n-1}b+\\cdots+c_nb = 0\n\t\t\t\t\\]\n\t\t\t\tHence $b$ divides $a^n$. But we also have $(a^n,b)=1$, hence $b=\\pm 1$, which is to say $x \\in \\Z$.\n\t\t\t\t\n\t\t\t\tThere is an more general setting. Since $\\Z$ is a unique factorial domain (UFD), and UFD is integrally closed \\href{https://proofwiki.org/wiki/Unique_Factorization_Domain_is_Integrally_Closed}{[proof]}, we have $\\Z=\\OK$. \n\t\t\t\\end{example}\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tThe Gaussian rational $\\Q(i)=K$. Indeed it is natural to consider Gaussian integer $\\Z[i]$ first. For any $z=m+ni \\in \\Z[i]$, we have\n\t\t\t\t\\[\n\t\t\t\tz^2-2mz+m^2+n^2=0\n\t\t\t\t\\]\n\t\t\t\tHence $\\Z[i] \\subset \\OK$. The converse is similar to our proof when $K=\\Q$.\n\t\t\t\\end{example}\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tQuadratic field $K=\\Q(\\sqrt{d})$, where $d$ is a square-free integer $>1$. This time the algebraic integer ring is different from what you may have thought: $\\OK = \\Z[\\omega]$ where\n\t\t\t\t\\[\n\t\t\t\t\\omega = \\begin{cases}\n\t\t\t\t\t\\frac{1+\\sqrt{d}}{2}, &\\quad d = 4k+1, \\\\\n\t\t\t\t\t\\sqrt{d}, &\\quad \\text{otherwise}.\n\t\t\t\t\\end{cases}\n\t\t\t\t\\]\n\t\t\t\\end{example}\n\t\t\tIt turns out we are studying polynomials such as\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $x^2+1=0$.\n\t\t\t\t\\item $x^2-d=0$.\n\t\t\t\\end{itemize}\n\t\t\tIt also turns out that many properties are not restricted to $\\Z$, but to a specific class of rings. Hence we will investigate some properties in the sense of commutative ring theory. The next example deserves more discussion.\n\t\t\t\n\t\t\t\\subsubsection{The Cyclotomic Fields}\n\t\t\t\tLet $\\omega = e^{2\\pi i/m}$. This is the $m$-th root of $1$. If $\\lambda$ is a conjugate of $\\omega$, i.e. they both are roots of the same irreducible polynomial over $\\Q$, then $\\lambda$ is also an $m$-th root of $1$ and is not an $n$-th root of $1$ whenever $n<m$. If we find these $\\lambda$, we have a better understanding of $\\Q(\\omega)$, which is called the cyclotomic field. We will do this in a general setting.\n\t\t\t\t\n\t\t\t\t\\begin{definition}\n\t\t\t\t\tLet $k$ be a field. By a \\textbf{root of unity} in $k$ we shall mean an element $\\xi \\in k$ such that $\\xi^n=1$ for some integer $n \\ge 1$. Let $n$ be a integer $\\ge 2$ and not divisible by the characteristic. The generator for the cyclic group $\\bm{\\mu}_n$ of $n$-th root of unity is called \\textbf{primitive}.\n\t\t\t\t\\end{definition}\n\t\t\t\t\n\t\t\t\t\\begin{remark}\n\t\t\t\t\tWe shall not ignore the characteristic of $k$. Indeed, if the characteristic is $p$, then the equation\n\t\t\t\t\t\\[\n\t\t\t\t\t\tX^{p^m}-1=0\n\t\t\t\t\t\\]\n\t\t\t\t\thas only one root, namely $1$, and hence there is no $p^m$-th root of unity except $1$.\n\t\t\t\t\\end{remark}\n\t\t\t\t\\begin{remark}\n\t\t\t\t\t$\\bm{\\mu}_n$ has $n$ elements. The derivative of $X^n-1$ is $nX^{n-1} \\ne 0$, and the only root of the derivative is $0$, so there is no common root. In the algebraic closure of $k$, the polynomial $X^n-1$ has $n$ distinct roots, which forms $\\bm{\\mu}_n$.\n\t\t\t\t\\end{remark}\n\t\t\t\t\n\t\t\t\tThe field extension in terms of root of unity can always be characterised for $(\\Z/n\\Z)^\\ast$ as follows:\n\t\t\t\t\n\t\t\t\t\\begin{theorem}\\label{gal-cyclotomic}\n\t\t\t\t\tLet $k$ be any field, let $n$ be not divisible by the characteristic $p$. Let $\\omega$ be a primitive $n$-th root of unity in the algebraic closure $k^\\mathrm{a}$, then $\\gal(k(\\omega)/k)$ is a subgroup of $(\\Z/n\\Z)^\\ast$.\n\t\t\t\t\\end{theorem}\n\t\t\t\t\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tLet $\\sigma$ be an embedding of $k(\\omega)$ in $k^\\mathrm{a}$ over $k$. Then\n\t\t\t\t\t\\[\n\t\t\t\t\t\t(\\sigma\\omega)^n = \\sigma(\\omega^n)=1\n\t\t\t\t\t\\]\n\t\t\t\t\thence $\\sigma\\omega$ is also an $n$-th root of unity. It follows that $\\sigma\\omega=\\omega^i$ for some $i=i(\\sigma)$ as $\\omega$ is primitive. $i(\\sigma)$ is uniquely determined mod $n$. It follows that $\\sigma$ maps $k(\\omega)$ into itself, and hence $k(\\omega)$ is normal over $k$. If $\\tau$ is another automorphism of $k(\\omega)$ over $k$, then\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\sigma\\tau\\omega = \\omega^{i(\\sigma)i(\\tau)}.\n\t\t\t\t\t\\]\n\t\t\t\t\tSince $\\sigma$ and $\\tau$ are isomorphisms, it follows that $i(\\sigma)$ and $i(\\tau)$ are prime to $n$ (otherwise, $\\sigma\\omega$ would have a period smaller than $n$). This yields a homomorphism of $\\gal(k(\\omega)/k)$ and is clearly injective because $i(\\sigma)$ is uniquely determined by $\\sigma$ mod $n$, and the effect of $\\sigma$ on $k(\\omega)$ is determined by its effect on $\\omega$.\n\t\t\t\t\\end{proof}\n\t\t\t\t\n\t\t\t\tFor a specific field $k$, the question arises whether the image of $\\gal(K(\\omega)/K)$ in $(\\Z/n\\Z)^\\ast$ is all of $(\\Z/n\\Z)^\\ast$. Looking at $k=\\mathds{R}$ or $k=\\mathds{C}$, this is not always the case. We give an example on when it is the case.\n\t\t\t\t\\begin{theorem}\n\t\t\t\t\tLet $\\omega$ be a primitive $n$-th root of unity in $\\Q^\\mathrm{a}$, then\n\t\t\t\t\t\\[\n\t\t\t\t\t\t[\\Q(\\omega):\\Q] = \\varphi(n)\n\t\t\t\t\t\\]\n\t\t\t\t\twhere $\\varphi$ is the Euler function.\n\t\t\t\t\\end{theorem}\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tAccording to theorem \\ref{gal-cyclotomic}, $[\\Q(\\omega):\\Q] \\le \\varphi(n)$, hence it suffices to prove the opposite.\n\t\t\t\t\t\n\t\t\t\t\tLet $f(X)$ be the minimal polynomial of $\\omega$ over $\\Q$. Then $f(X)$ divides $X^n-1$, and we can write $X^n-1=f(X)h(X)$, where both $f$ and $h$ have leading coefficient $1$. By the Gauss lemma, $f$ and $h$ have integral coefficients. We shall now prove that if $p$ is a prime number not dividing $n$, then $\\omega^p$ is also a root of $f$.\n\t\t\t\t\t\n\t\t\t\t\tSuppose $\\phi^p$ is not a root of $f$, then it is a root of $h$, and $\\phi$ is a root of $h(X^p)$. Hence $f$ divides $h(X^p)$ as well, so we write\n\t\t\t\t\t\\[\n\t\t\t\t\t\th(X^p)=f(X)g(X).\n\t\t\t\t\t\\]\n\t\t\t\t\tNote $g$ has integral coefficients as well. Since $a^p \\equiv a \\mod p$ for any integer $a$, we have\n\t\t\t\t\t\\[\n\t\t\t\t\t\th(X^p) \\equiv h(X)^p \\mod p,\n\t\t\t\t\t\\]\n\t\t\t\t\tand therefore\n\t\t\t\t\t\\[\n\t\t\t\t\t\th(X)^p \\equiv f(X)g(X) \\mod p.\n\t\t\t\t\t\\]\n\t\t\t\t\tLet $\\overline{f}$ and $\\overline{h}$ be the canonical image of $f$ and $h$ in $\\Z/p\\Z[X]$, we see that $f$ and $h$ are not relatively prime, hence have common factor(s). But if follows that\n\t\t\t\t\t\\[\n\t\t\t\t\t\tX^n-\\overline{1}=\\overline{f}(X)\\overline{g}(X)\n\t\t\t\t\t\\]\n\t\t\t\t\thas multiple rules, which contradicts the remark we have made at the beginning.\n\t\t\t\t\t\n\t\t\t\t\tSince $\\omega^p$ is also a primitive $n$-th root of unity, and any primitive $n$-th root of unity can be obtained by raising $\\omega$ to a succession of prime powers with primes not dividing $n$, this implies that all primitive $n$-th roots of unity are roots of $f$, which forces the degree of $f$ to be not less than $\\varphi(n).$\n\t\t\t\t\t\n\t\t\t\t\\end{proof}\n\t\t\t\n\t\t\t\tIt follows immediately that\n\t\t\t\n\t\t\t\t\\begin{corollary}\n\t\t\t\t\tWe have an isomorphism\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\gal(\\Q(\\omega):\\Q) \\cong (\\Z/n\\Z)^\\ast.\n\t\t\t\t\t\\]\n\t\t\t\t\\end{corollary}\n\t\t\t\n\t\t\t\t\\begin{corollary}\n\t\t\t\t\tIf $n,m$ are relative prime integers $\\ge 1$, then\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\Q(\\omega_n) \\cap \\Q(\\omega_m) = \\Q.\n\t\t\t\t\t\\]\n\t\t\t\t\\end{corollary}\n\t\t\t\n\t\t\t\tWe will prove that the cyclotomic integers (i.e. the algebraic integer with respect to $\\Q(\\omega)/\\Q$) is actually $\\Z[\\omega]$. This is a highly non-trivial result and we can only deliver the proof after further study on prime ideals.\n\t\t\t\t% TODO: Finish this section and the study of Z[\\omega]. Source can be found on Daniel A. Marcus.\n\t\t\\subsection{Algebraic extension and integral closure}\n\t\t\tFirst of all we show that being algebraic almost implies being integral. \n\t\t\t\\begin{lemma}\\label{alg-int}\n\t\t\t\tLet $A$ be a domain, $K$ its quotient field, and $x$ algebraic over $K$. Then there exists an element $c \\ne 0$ of $A$ such that $cx$ is integral over $A$.\n\t\t\t\\end{lemma}\n\t\t\t\\begin{proof}\n\t\t\t\tSince $x$ is algebraic, we have an equation\n\t\t\t\t\\[\n\t\t\t\t\ta_nx^n+\\cdots+a_0=0\n\t\t\t\t\\]\n\t\t\t\twith $a_i \\in A$ and $a_n \\ne 0$. Hence\n\t\t\t\t\\[\n\t\t\t\t\ta_n^{n-1}(a_nx^n+\\cdots+a_0)=(a_nx)^n+\\cdots+a_0a_n^{n-1}=0\n\t\t\t\t\\]\n\t\t\t\twhich is to say $a_nx$ is integral over $A$. \n\t\t\t\\end{proof}\n\t\t\t\n\t\t\tSince finite extensions are algebraic, we are always free to use this lemma for the topic of number field.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{closure-f-g}\n\t\t\t\tLet $A$ be an integrally closed Noetherian ring. Let $L$ be a finite separable extension of its quotient field $K$. Then the integral closure of $A$ in $L$ is finitely generated over $A$.\n\t\t\t\\end{theorem}\n\t\t\n\t\t\tBy being integrally closed we mean the ring is integrally closed in its quotient field. Some mathematicians also say it is being normal, but I think \\textit{normal} does not carry a lot of information.\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tSince $A$ is Noetherian, all submodules of a finitely generated module over $A$ is finitely generated. Hence it suffices to prove that the integral closure of $A$ is contained in a finitely generated $A$-module.\\\\\n\t\t\t\tLet $w_1,\\dots,w_n$ be a basis of $L$ over $K$. After multiplying each $w_i$ by some suitable element of $A$ (see lemma \\ref{alg-int}), we may assume without loss of generality that the $w_i$ are integral over $A$. To study the integral closure of $A$ in $L$, we pick an arbitrary element $z = b_1w_1+\\cdots+b_nw_n$ and study its coefficients. \\\\\n\t\t\t\tSince $L/K$ is separable, the \\href{https://stacks.math.columbia.edu/tag/0BIF}{field trace} form\n\t\t\t\t\\[\n\t\t\t\t\tQ_{L/K}:L \\times L \\to K, \\quad (x,y) \\mapsto \\tr_{L/K}(xy)\n\t\t\t\t\\]\n\t\t\t\tis non-degenerate  \\href{https://stacks.math.columbia.edu/tag/0BIL}{[proof]}, so we claim that $L^\\ast$ is isomorphic to $L$ under $Q_{L/K}$. Indeed, one can define a $K$-linear map\n\t\t\t\t\\[\n\t\t\t\t\td:L \\to L^\\ast, \\quad x \\mapsto (y \\mapsto Q_{L/K}(x,y)=\\tr(xy)).\n\t\t\t\t\\]\n\t\t\t\tThis map is injective because $Q_{L/K}$ is non-degenerate. Since $L$ and $L^\\ast$ has the same dimension, $d$ has to be surjective.\\\\\n\t\t\t\tLet $w^1,\\dots,w^n$ be the dual basis of $w_1,\\dots,w_n$. If we put $v_i=d^{-1}(w^i)$, we have\n\t\t\t\t\\[\n\t\t\t\t\t\\tr(v_i w_j) = \\delta_{ij}.\n\t\t\t\t\\]\n\t\t\t\tLet $c \\ne 0$ be an element of $A$ such that $cv_i$ is integral over $A$, then $cv_iz$ is integral and so is $\\tr(cv_iz)$. Since $\\tr$ is a $K$-valued function, we have\n\t\t\t\t\\[\n\t\t\t\t\t\\tr(czv_i)=c\\tr(v_iz)=c d(v_i)(z) = cb_i \\in A \\implies b_i \\in Ac^{-1}.\n\t\t\t\t\\]\n\t\t\t\tHence\n\t\t\t\t\\[\n\t\t\t\t\tz \\in Ac^{-1}w_1+\\cdots+Ac^{-1}w_n\n\t\t\t\t\\]\n\t\t\t\twhich is to say $z$ is finitely generated. Since $z$ is arbitrarily picked, the closure itself is contained in a finitely generated $A$-module, which finishes the proof. \n\t\t\t\\end{proof}\n\t\t\tNote $Z$ is itself a Noetherian ring and integrally closed. $\\Q$ is the fraction ring of $\\Z$, and finite extensions of $\\Q$ are always separable. It follows (non-trivially) that\n\t\t\t\\begin{corollary}\n\t\t\t\t$\\OK$ is finitely generated over $\\Z$.\n\t\t\t\\end{corollary}\n\t\t\t\n\t\t\tNext we study the rank of $\\OK$ over $\\Z$. Being finitely generated is not exactly what we want.\n\t\t\t\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A$ be a principal ideal ring, and $L$ a finite separable extension of its quotient field $K$, of degree $n$. Let $B$ be the integral closure of $A$ in $L$. Then $B$ is a free module of rank $n$ over $A$. \n\t\t\t\\end{theorem}\n\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tSince $A$ is contained in $K$, $B$ is contained in $L$, whenever $ab=0$ with $a \\in A$, $b \\in B$, we have $a=0$ or $b=0$. Hence $B$ is torsion-free. Therefore as a finitely generated (theorem \\ref{closure-f-g}) torsion-free module, $B$ is a free module over $A$ \\href{http://du.ac.in/du/uploads/departments/mathematics/study-material/MMATH18-201\\%20_MT_PID.pdf}{[Theorem 2.7]}. Since $L$ is a $n$-dimensional vector space over $K$, for $y \\in L$ we have\n\t\t\t\t\\[\n\t\t\t\t\ty = c_1e_1+\\cdots+c_ne_n\n\t\t\t\t\\]\n\t\t\t\twhere $e_1,\\dots,e_n$ is a basis and $c_1,\\cdots,c_n \\in K$. When $y \\in B$, we must have $c_1,\\cdots,c_n \\in A$, which is to say $B$ has rank $[L:K]=n$.\n\t\t\t\\end{proof}\n\t\t\tHence the rank of $\\OK$ over $\\Z$ is determined by $[K:\\Q]$.\n\t\t\n\t\t\\subsection{Localisation}\n\t\t\n\t\t\t\\begin{theorem}\\label{int-clo-loc}\n\t\t\t\tLet $A \\subset B$ be rings, and $S$ a multiplicatively closed subset of $A$. If $B$ is integral over $A$, then $S^{-1}B$ is integrally closed in $S^{-1}A$. If $C$ is the integral closure of $A$ in $B$, then $S^{-1}C$ is the integral closure of $S^{-1}A$. \n\t\t\t\\end{theorem}\n\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tFirst we assume $B$ is integral over $A$. Pick $x/s \\in S^{-1}B$ with $x \\in B$ and $s \\in S$. By definition we have\n\t\t\t\t\\[\n\t\t\t\t\tx^n + a_1x^{n-1}+\\cdots + a_n = 0\n\t\t\t\t\\]\n\t\t\t\twith $a_i \\in A$. Multiplying by $(1/s)^n$ gives\n\t\t\t\t\\[\n\t\t\t\t\t(x/s)^n + (a_1/s)(x/s)^{n-1}+\\cdots+a_n/s^n = 0\n\t\t\t\t\\]\n\t\t\t\twhich shows that $x/s$ is integral over $S^{-1}A$. Hence the first statement is proved. \\\\\n\t\t\t\tNow we assume $C$ is the integral closure of $A$ in $B$. By the first statement we see $S^{-1}C$ is integral over $S^{-1}A$. Suppose $b/s \\in S^{-1}B$ is integral over $S^{-1}A$, we have an equation of the form\n\t\t\t\t\\[\n\t\t\t\t\t(b/s)^n+(a_1/s_1)(b/s)^{n-1}+\\cdots+a_n/s_n=0.\n\t\t\t\t\\]\n\t\t\t\tMultiplying by $(st)^n$ where $t=s_1\\cdots s_n$ gives an equation of integral independence for $bt$ over $A$. Hence $bt \\in C$. But $b/s = bt/st$, hence $b/s \\in S^{-1}C$ and we are done. \n\t\t\t\\end{proof}\n\t\t\n\t\t\tIf $S$ happens to be a complement of a prime ideal $\\mfk{p}$, we have a satisfying result\n\t\t\t\n\t\t\t\\begin{corollary}\\label{int-loc}\n\t\t\t\tIf $B$ is integral over $A$, then $B_\\mfk{p}$ is integral over $A_\\mfk{p}$.\n\t\t\t\\end{corollary}\n\t\t\t\n\t\t\tIf $B$ is replaced by a field extension $L$ of the quotient field of $A$, and $C$ is replaced by the integral closure of $A$, we have the following corollary:\n\t\t\t\n\t\t\t\\begin{corollary}\n\t\t\t\tIf $B$ is the integral closure of $A$ in some field extension $L$ of the quotient field of $A$, then $S^{-1}B$ is the integral closure of $S^{-1}A$ in $L$.\n\t\t\t\\end{corollary}\n\t\t\t\n\t\t\tBeing integrally closed is also a local property. And we will use it to prove that the algebraic integers in the field $\\Q(\\omega)$ is $\\Z[\\omega]$.\n\t\t\t\\begin{corollary}\n\t\t\t\tLet $A$ be an integral domain. Then the following are equivalent:\n\t\t\t\t\\begin{enumerate}\n\t\t\t\t\t\\item $A$ is integrally closed.\n\t\t\t\t\t\\item $A_\\mfk{p}$ is integrally closed for each prime ideal $\\mfk{p}$. \n\t\t\t\t\t\\item $A_\\mfk{m}$ is integrally closed for each maximal ideal $\\mfk{m}$.\n\t\t\t\t\\end{enumerate}\n\t\t\t\\end{corollary}\n\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tLet $K$ be the quotient field of $A$, let $C$ be the integral closure of $A$ in $K$, and let $f:A \\to C$ be the canonical embedding. Then $A$ is integrally closed if and only if $f$ is surjective.\n\t\t\t\t\n\t\t\t\tOn the other hand, by theorem \\ref{int-clo-loc}, $A_\\mfk{p}$ (respectively $A_\\mfk{m}$) is integrally closed if and only if $f_\\mfk{p}$ (respectively $f_\\mfk{m}$) is surjective.\n\t\t\t\t\n\t\t\t\tHowever, a $A$-module homomorphism $\\phi:M \\to N$ being surjective is a local property \\href{https://www.maths.usyd.edu.au/u/de/AGR/CommutativeAlgebra/pp600-610.pdf}{[proof]}. Therefore we have\n\t\t\t\t\\[\n\t\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\tA \\text{ is integrally closed } &\\iff f \\text{ is surjective } \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&\\iff f_\\mfk{p} \\text{ is surjective } \\iff A_\\mfk{p} \\text{ is integrally closed } \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&\\iff f_\\mfk{m} \\text{ is integrally closed } \\iff A_\\mfk{m} \\text{ is integrally closed.}\n\t\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\\end{proof}\n\t\t\t\n\t\t\t% TODO: ADD SOME EXAMPLES\n\t\t\\subsection{Prime Ideals}\n\t\t\tBy theorem \\ref{closure-f-g}, $\\OK$ is a finitely-generated $\\Z$-module, hence is a Noetherian domain. By transitivity of integral closures, $\\OK$ is integrally closed. We are now interested in the Krull dimension of $\\OK$. To do this, we investigate more of the prime ideal with respect to integral closure. \n\t\t\t\\begin{definition}\n\t\t\t\tLet $B$ be a ring containing a ring $A$. Let $\\mfk{p}$ be a prime ideal of $A$ and $\\mfk{P}$ a prime ideal of $B$. We say that $\\mfk{P}$ \\textbf{lies above} $\\mfk{p}$ if $\\mfk{P} \\cap A = \\mfk{p}$ and we then write $\\mfk{P}|\\mfk{p}$.\n\t\t\t\\end{definition}\n\t\t\t\n\t\t\tIf $\\mfk{P}|\\mfk{p}$, we have a commutative diagram:\n\t\t\t\\[\n\t\t\t\\begin{tikzcd}\n\t\t\t\tB \\arrow[r, \"\\pi'\"]               & B/\\mathfrak{P}                  \\\\\n\t\t\t\tA \\arrow[r, \"\\pi\"] \\arrow[u, \"i\"] & A/\\mathfrak{p} \\arrow[u, \"i'\"']\n\t\t\t\\end{tikzcd}\n\t\t\t\\]\n\t\t\twhere $i$ and $i'$ are inclusions, $\\pi$ and $\\pi'$ are canonical homomorphisms. \\\\\n\t\t\tIf $B$ is integral over $A$, then $B/\\mfk{P}$ is integral over $A/\\mfk{p}$, this is because of the following lemma if we take $\\sigma$ to be $\\pi$:\n\t\t\t\\begin{lemma}\n\t\t\t\tLet $A \\subset B$ be rings, and $\\sigma:B \\to C$ be a homomorphism. If $B$ is integral over $A$, then $\\sigma(B)$ is integral over $\\sigma(A)$.\n\t\t\t\\end{lemma}\n\t\t\t\\begin{proof}\n\t\t\t\tIf $B$ is integral over $A$, then for any $x \\in B$ there is an equation\n\t\t\t\t\\[\n\t\t\t\tx^n + a_{n-1}x^{n-1}+\\cdots+a_0 = 0.\n\t\t\t\t\\]\n\t\t\t\tTherefore\n\t\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\sigma(x^n+a_{n-1}x^{n-1}+\\cdots+a_0) &= \\sigma(x^n)+\\sigma(a_{n-1}x^{n-1})+\\cdots+\\sigma(a_0) \\\\\n\t\t\t\t\t&= \\sigma(x)^n + \\sigma(a_{n-1})\\sigma(x)^{n-1}+\\cdots+\\sigma(\\sigma) \\\\\n\t\t\t\t\t&= 0.\n\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tHence $\\sigma(x)$ is integral in $\\sigma(A)$.\n\t\t\t\\end{proof}\n\t\t\t\n\t\t\tWe want to show that prime ideals of $\\OK$ is maximal, and they should be corresponded to prime ideals in $\\Z$, which is maximal. For this reason we show the existence of lying-above prime ideals.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{lying-above}\n\t\t\t\tLet $A$ be a ring, $\\mfk{p}$ a prime ideal, and $B \\supset A$ integral over $A$. Then $\\mfk{p}B \\ne B$, and there exists a prime ideal $\\mfk{P}$ of $B$ lying above $\\mfk{p}$. \n\t\t\t\\end{theorem}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tWe know that $B_\\mfk{p}$ is integral over $A_\\mfk{p}$ (corollary \\ref{int-loc}) and that $A_\\mfk{p}$ is local with maximal ideal $\\mfk{m}_\\mfk{p}=\\mfk{p}A_\\mfk{p}$. It follows that\n\t\t\t\t\\[\n\t\t\t\t\\mfk{p}B_\\mfk{p}=\\mfk{p}A_\\mfk{p}B = \\mfk{p}A_\\mfk{p}B_\\mfk{p}=\\mfk{m}_\\mfk{p}B_\\mfk{p}.\n\t\t\t\t\\]\n\t\t\t\tHence it suffices to prove our assertion when $A$ is local. If $\\mfk{p}B=B$, we have an equation\n\t\t\t\t\\[\n\t\t\t\t1 = a_1b_1+\\cdots+a_nb_n\n\t\t\t\t\\]\n\t\t\t\twith $a_i \\in \\mfk{p}$ and $b_i \\in B$. Let $B_0 = A[b_1,\\cdots,b_n]$. Then $\\mfk{p}B_0=B_0$ and $B_0$ is a finitely generated $A$-module. Hence by Nakayama's lemma, $B_0=0$, which is absurd.\n\t\t\t\t\n\t\t\t\tTo prove the existence of $\\mfk{P}$, consider the following commutative diagram:\n\t\t\t\t\\[\n\t\t\t\t\\begin{tikzcd}\n\t\t\t\t\tB \\arrow[r]           & B_\\mathfrak{p}           \\\\\n\t\t\t\t\tA \\arrow[r] \\arrow[u] & A_\\mathfrak{p} \\arrow[u]\n\t\t\t\t\\end{tikzcd}\n\t\t\t\t\\]\n\t\t\t\twhere all arrows are natural inclusions. As is proved, $\\mfk{m}_\\mfk{p}B_\\mfk{p} \\ne B_\\mfk{p}$. Hence $\\mfk{m}_\\mfk{p}B_\\mfk{p}$ is contained in a maximal ideal $\\mfk{M}$ of $\\mfk{p}$, and therefore $\\mfk{M} \\cap A_\\mfk{p}$ contains $\\mfk{m}_\\mfk{p}$. And we pick $\\mfk{P}=\\mfk{M} \\cap B$. Then $\\mfk{P}$ is a prime ideal of $B$, and taking intersection with $A$ going both ways around our diagram shows that $\\mfk{M} \\cap A = \\mfk{p}$, so that\n\t\t\t\t\\[\n\t\t\t\t\\mfk{P} \\cap A = \\mfk{p},\n\t\t\t\t\\]\n\t\t\t\tas was to be shown.\n\t\t\t\\end{proof}\n\t\t\t\n\t\t\tNow we proceed to the crucial theorem to determine whether a prime lying above is maximal.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{lie-above-maximal}\n\t\t\t\tLet $A$ be a subring of $B$, and assume $B$ is integral over $A$. Let $\\mfk{P}$ be a prime ideal of $B$ lying over a prime ideal $\\mfk{p}$ of $A$. Then $\\mfk{P}$ is maximal $\\iff$ $\\mfk{p}$ is maximal.\n\t\t\t\\end{theorem}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\t$\\implies$: Note $B/\\mfk{P}$ is a field and is integral over the ring $A/\\mfk{p}$. Were $A/\\mfk{p}$ not a field, there would be a non-trivial ideal $\\mfk{m}$ of it, and $B/\\mfk{P}$ would have a prime ideal $\\mfk{M}$ lying above $\\mfk{m}$, by theorem \\ref{lying-above}. A contradiction. \\\\\n\t\t\t\t$\\impliedby$: Note $A/\\mfk{p}$ is a field. It suffices to prove that a ring $R$ which is integral over a field $k$ is a field. If $k$ is a field and non-zero $x \\in R$ is integral over $k$, we have a minimal polynomial\n\t\t\t\t\\[\n\t\t\t\tx^n+c_{n-1}y^{n-1}+\\cdots+c_0=0\n\t\t\t\t\\]\n\t\t\t\twith $c_i \\in k$. Since $R$ is integral, we have $c_0 \\ne 0$. We can clearly write\n\t\t\t\t\\[\n\t\t\t\tx^{-1}=-c_0^{-1}(x^{n-1}+c_{n-1}y_{n-2}+\\cdots+c_1) \\in R,\n\t\t\t\t\\]\n\t\t\t\twhich is to say $R$ is integral, and the theorem is therefore proved.\n\t\t\t\\end{proof}\n\t\t\tBy using local properties, we can show the stability of prime ideals lying above:\n\t\t\t\\begin{corollary}\n\t\t\t\tLet $A \\subset B$ be rings, $B$ integral over $A$; Let $\\mfk{P}$ and $\\mfk{P}'$ be prime ideals of $B$ such that $\\mfk{P} \\subset \\mfk{P}'$ and both $\\mfk{P}$ and $\\mfk{P}'$ lie above a prime ideal $\\mfk{p}$ of $A$, then $\\mfk{P}=\\mfk{P}'$. \n\t\t\t\\end{corollary}\n\t\t\t\\begin{proof}\n\t\t\t\tBy corollary \\ref{int-loc}, $B_\\mfk{p}$ is integral over $A_\\mfk{p}$. Let $\\mfk{m}$ be the extension of $\\mfk{p}$ in $A_\\mfk{p}$ and $\\mfk{M},\\mfk{M}'$ be the extensions of $\\mfk{P}$ and $\\mfk{P}'$ respectively in $B_\\mfk{p}$. Then $\\mfk{m}$ is the maximal ideal of $A_\\mfk{p}$; $\\mfk{M} \\subset \\mfk{M}'$, and $\\mfk{M}$, $\\mfk{M}'$ lies above $\\mfk{m}$. Hence by theorem \\ref{lie-above-maximal}, $\\mfk{M}$ and $\\mfk{M}'$ are both maximal, hence equal. This reduces to $\\mfk{P}=\\mfk{P}'$.\n\t\t\t\\end{proof}\n\t\t\tIf the context is exactly localisation, we have a finer result:\n\t\t\t\\begin{theorem}\\label{loc-corr}\n\t\t\t\tLet $A$ be a commutative ring, $S \\subset A$ be a multiplicatively closed set. We have a $1-1$-correspondence of prime ideals $\\mfk{p}$ do not intersect $S$ and prime ideals of $S^{-1}A$:\n\t\t\t\t\\[\n\t\t\t\t\t\\mfk{p} \\mapsto S^{-1}\\mfk{p}, \\quad \\mfk{P} \\mapsto \\mfk{P} \\cap A.\n\t\t\t\t\\]\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tTo prove that $S^{-1}\\mfk{p}=\\mfk{P}$ is prime, suppose that $(a/s)(b/t)=ab/st = p/u \\in \\mfk{P}$. By definition there exists some $r \\in S$ such that $r(abu-stp)=0$. It follows that $rabu=rstp \\in \\mfk{p}$. But $r,u$ are not in $\\mfk{p}$, hence we can only have $ab \\in \\mfk{p}$, which gives that $a \\in \\mfk{p}$ or $b \\in \\mfk{p}$, and as a result $a/s \\in \\mfk{P}$ or $b/t \\in \\mfk{P}$. Besides we have $\\mfk{p} = \\mfk{P} \\cap A$. $\\subset$ inclusion is clear, but for the converse inclusion, note that if $p/s=a/1 \\in \\mfk{P} \\cap A$, we have $up=uas$ for some $u \\in S$, which forces $a$ to be an element of $\\mfk{p}$. (Note we implicitly used the fact that $\\mfk{p}$ does not intersect $S$.)\n\t\t\t\t\n\t\t\t\tFor the converse, first note that $\\mfk{p}=\\mfk{P} \\cap A$ is indeed a prime ideal. For any $(a/1)(b/1) \\in \\mfk{p} \\subset \\mfk{P}$, we must have $a/1 \\in \\mfk{P}$ or $b/1 \\in \\mfk{P}$, but both $a/1$ and $b/1$ are in $A$. Also, $\\mfk{p}$ does not intersect $S$ because if $s \\in S \\cap \\mfk{p}$, then $(1/s)s=1\\in \\mfk{p}$, which is absurd. It remains to show that $\\mfk{P} = S^{-1}\\mfk{p}$. It is clear that $S^{-1}\\mfk{p} \\subset \\mfk{P}$. For the converse, pick any $a/s \\in \\mfk{P}$, we have $a/1=(a/s)(s/1) \\in \\mfk{p}$, and therefore $a/s=a(1/s) \\in S^{-1}\\mfk{p}$.\n\t\t\t\\end{proof}\n\t\t\tIn particular, we can also study the localised ring.\n\t\t\t\\begin{corollary}\n\t\t\t\tLet $\\mfk{m}_\\mfk{p}=\\mfk{p}A_\\mfk{p}$ be the maximal ideal of $A_\\mfk{p}$. We have a canonical embedding\n\t\t\t\t\\[\n\t\t\t\t\tA/\\mfk{p} \\hookrightarrow A_\\mfk{p}/\\mfk{m}_\\mfk{p} \\cong K(A/\\mfk{p})\n\t\t\t\t\\]\n\t\t\t\twhere $K(B)$ is the field of fractions of $B$. In particular, if $\\mfk{p}$ is maximal, one has an isomorphism for all $n \\ge 1$:\n\t\t\t\t\\[\n\t\t\t\t\tA/\\mfk{p}^n \\cong A_\\mfk{p}/\\mfk{m}_\\mfk{p}^n.\n\t\t\t\t\\]\n\t\t\t\\end{corollary}\n\t\t\t\\begin{proof}\n\t\t\t\tSince $\\mfk{p} = \\mfk{m}_\\mfk{p} \\cap A$, the canonical map\n\t\t\t\t\\[\n\t\t\t\t\ta \\mod \\mfk{p} \\mapsto a/1 \\mod \\mfk{m}_\\mfk{p}\n\t\t\t\t\\] \n\t\t\t\tis injective. $A_\\mfk{p}/\\mfk{m}_\\mfk{p}$ can be identified as the field of fraction of $A/\\mfk{p}$ because given any non-zero $a/1 \\mod \\mfk{m}_\\mfk{p}$, we see $a \\in A \\setminus \\mfk{p}$, hence $1/a \\mod \\mfk{m}_\\mfk{p}$ is exactly the inverse of $a/1 \\mod \\mfk{m}_\\mfk{p}$.\n\t\t\t\t\n\t\t\t\tNext we assume that $\\mfk{p}$ is maximal and consider the canonical map\n\t\t\t\t\\[\n\t\t\t\t\t\\varphi:a \\mod \\mfk{p}^n \\mapsto a/1 \\mod \\mfk{m}_\\mfk{p}^n.\n\t\t\t\t\\]\n\t\t\t\tIf $n=1$, then both $A/\\mfk{p}$ and $A_\\mfk{p}/\\mfk{m}_\\mfk{p}$ are fields, and the field of fractions of a field is itself. To prove it for all $n \\ge 0$, we need the fact that $s \\mod \\mfk{p}^n$ is a unit whenever $n \\ge 0$ and $s \\in A \\setminus \\mfk{p}$, which will be shown later as a lemma.\n\t\t\t\t\n\t\t\t\t$\\varphi$ is injective because if $a/1 \\in \\mfk{m}_\\mfk{p}^n$, i.e. $a/1 = b/s$ where $b \\in \\mfk{p}^n$ and $s \\not \\in \\mfk{p}$, then there exits some $u \\not\\in \\mfk{p}$ such that $uas = ub \\in \\mfk{p}^n$. Since both $ u \\mod \\mfk{p}^n$ and $s \\mod \\mfk{p}^n$ are units, we see $a \\mod \\mfk{p}^n$ is zero in $A/\\mfk{p}^n$. \n\t\t\t\t\n\t\t\t\t$\\varphi$ is surjective because given $a/s \\in A_\\mfk{p}$ with $a \\in A$ and $s \\not\\in \\mfk{p}$, there exists some $a' \\in A$ such that $a \\equiv a's \\mod \\mfk{p}^n$. Indeed, let $t \\mod \\mfk{p}^n$ be the inverse of $s \\mod \\mfk{p}^n$, we can put $a' = at$. Therefore $a/s \\equiv a' \\mod \\mfk{p}^nA_\\mfk{p}$ (by theorem \\ref{loc-corr}), which is equivalent to say that $a/s \\mod \\mfk{m}_\\mfk{p}^n$ lies in the image of $\\varphi$.\n\t\t\t\\end{proof}\n\t\t\t\\begin{lemma}\n\t\t\t\tLet $A$ be a ring and $\\mfk{p}$ is a maximal ideal. Then $\\mfk{p}^n+sA=A$ for all $n \\ge 1$ and $s \\in A \\setminus \\mfk{p}$. Besides, this implies that $s \\mod \\mfk{p}^n$ is a unit in $A/\\mfk{p}^n$.\n\t\t\t\t\\end{lemma}\n\t\t\t\\begin{proof}\n\t\t\t\tWhen $n=1$, note $\\mfk{p} \\subsetneqq \\mfk{p}+sA$, while $\\mfk{p}$ is maximal, we must have $\\mfk{p}+sA=A$. When $n \\ge 2$, suppose it holds for $n-1$, then we have\n\t\t\t\t\\[\n\t\t\t\tA = \\mfk{p}^{n-1}+sA \\implies \\mfk{p}=\\mfk{p}A = \\mfk{p}(\\mfk{p}^{n-1}+sA) \\subsetneqq \\mfk{p}^n+sA,\n\t\t\t\t\\]\n\t\t\t\twhich forces $\\mfk{p}^n+sA$ to be $A$ itself.\n\t\t\t\t\n\t\t\t\tNow we consider $A$-modules\n\t\t\t\t\\[\n\t\t\t\t\\mfk{p}^n+sA = A.\n\t\t\t\t\\]\n\t\t\t\tBy taking the quotient, we obtain\n\t\t\t\t\\[\n\t\t\t\t\\overline{s}A/\\mfk{p}^n=A/\\mfk{p}^n.\n\t\t\t\t\\]\n\t\t\t\tIt follows that $s \\mod \\mfk{p}^n$ is a unit in $A/\\mfk{p}^n$.\n\t\t\t\\end{proof}\n\t\t\tAnd now we are more than ready to prove that $\\OK$ is Dedekind.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{o_k-dedekind}\n\t\t\t\tEvery prime ideal $\\mfk{P}$ in $\\OK$ is maximal. Hence $\\OK$ is of Krull dimension $1$ and is therefore Dedekind.\n\t\t\t\\end{theorem}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tNote it suffices to prove that every prime ideal $\\mfk{P}$ of $\\OK$ lies above some prime ideal of $\\Z$, since $\\Z$ has Krull dimension $1$, and the proof follows from theorem \\ref{lie-above-maximal}. All we need to do is to prove that $\\mfk{P} \\cap \\Z$ is non-zero: since the inverse image of a prime ideal is prime, we are done. For each $x \\in \\mfk{P}$, we have a minimal polynomial $f \\in \\Z[X]$ such that\n\t\t\t\t\\[\n\t\t\t\tf(x) = x^n+c_{n-1}x^{n-1}+\\cdots+c_0=0\n\t\t\t\t\\]\n\t\t\t\twith $c_i \\in \\Z$ and $c_0 \\ne 0$. It follows that\n\t\t\t\t\\[\n\t\t\t\tc_0=-(x^n+c_{n-1}x^{n-1}+\\cdots+c_1x) \\in \\mfk{P} \\cap \\Z,\n\t\t\t\t\\]\n\t\t\t\twhich is to say $\\mfk{P} \\cap \\Z$ is indeed non-zero. This concludes the proof.\n\t\t\t\\end{proof}\n\t\t\t\\begin{example}\n\t\t\t\tAs a classic example, consider $K=\\Q(\\sqrt{-5})$ and $\\OK = \\Z[\\sqrt{-5}]$. This ring is not a unique factorial domain because we have\n\t\t\t\t\\[\n\t\t\t\t6 = 2 \\cdot 3 = (1-\\sqrt{-5}) \\cdot (1+\\sqrt{-5}).\n\t\t\t\t\\]\n\t\t\t\tBut if we view it in the sense of product of ideals, we still have some uniqueness. Let $\\mfk{m}$ be the maximal ideal containing $6$, then\n\t\t\t\t\\[\n\t\t\t\t\\mfk{m} = (2,1-\\sqrt{-5})(2,1+\\sqrt{-5})\n\t\t\t\t\\]\n\t\t\t\tis unique. Note two ideals on the right hand side are indeed maximal (hence prime) because\n\t\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\frac{\\Z[\\sqrt{-5}]}{(2,1-\\sqrt{-5})} &\\cong \\frac{\\Z[X]/(X^2+5)}{(2,1-X,X^2+5)/(X^2+5)} \\\\\n\t\t\t\t\t&\\cong \\frac{\\Z[X]}{(2,1-X,X^2+5)} \\cong \\frac{\\Z_2[X]}{(1-X,X^2-1)} \\cong \\frac{\\Z_2[X]}{(1-X)} \\cong \\Z_2.\n\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tLikewise,\n\t\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\frac{\\Z[\\sqrt{-5}]}{(3,1+\\sqrt{-5})} &\\cong \\frac{\\Z[X]/(X^2+5)}{(3,1+X,X^2+5)/(X^2+5)} \\\\\n\t\t\t\t\t&\\cong \\frac{\\Z[X]}{(3,1+X,X^2+5)} \\cong \\frac{\\Z_3[X]}{(1+X,X^2-1)} \\cong \\frac{\\Z_3[X]}{(1+X)} \\cong \\Z_3.\n\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\\end{example}\n\t\t\tWe will see when a Dedekind domain is UFD in the future.\n\t\\section{Galois extensions}\n\t\t\\subsection{Special subgroups of the Galois group}\n\t\t\tIn this subsection we study the behaviour of Galois group with respect to integral closure, which can of course help us study number field and algebraic integers if we are interested in the extension itself.\n\t\t\n\t\t\tIf $K$ is a Galois extension of $\\Q$, then the Galois group allows us to transform amongst prime ideals in a natural way. This is because of the following theorem.\n\t\t\t\\[\n\t\t\t\t\\begin{tikzcd}\n\t\t\t\t\t\\mathfrak{P} \\arrow[rr, \"\\exists \\sigma \\in G\"] &                                    & \\mathfrak{Q} \\\\\n\t\t\t\t\t& \\mathfrak{p} \\arrow[lu] \\arrow[ru] &             \n\t\t\t\t\\end{tikzcd}\n\t\t\t\\]\n\t\t\t\\begin{theorem}\\label{galois-lie-above}\n\t\t\t\tLet $A$ be a ring, integrally closed in its quotient field $K$. Let $L$ be a finite Galois extension of $K$ with group $G$. Let $\\mfk{p}$ be a maximal ideal of $A$, and let $\\mfk{P}$, $\\mfk{Q}$ be prime ideals of the integral closure of $A$ in $L$ lying above $\\mfk{p}$. Then there exists $\\sigma \\in G$ such that $\\sigma\\mfk{P} = \\mfk{Q}$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tSuppose that $\\mfk{P}=\\sigma\\mfk{Q}$ for all $\\sigma \\in G$. By the Chinese remainder theorem, we have some $x \\in B$ such that \n\t\t\t\t\\[\n\t\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\tx &\\equiv 0 \\mod \\mfk{P} \\\\\n\t\t\t\t\t\tx &\\equiv 1 \\mod \\sigma\\mfk{Q}, \\quad \\forall \\sigma \\in G.\n\t\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tThen the norm\n\t\t\t\t\\[\n\t\t\t\t\tN_K^L(x) = \\prod_{\\sigma \\in G}\\sigma{x}\n\t\t\t\t\\]\n\t\t\t\tlies in $B \\cap K = A$ since $A$ is integrally closed, and lies in $\\mfk{P} \\cap A = \\mfk{p}=\\mfk{Q} \\cap A \\subset \\mfk{Q}$. But we also have $\\sigma{x} \\not\\in \\mfk{Q}$ for all $\\sigma \\in G$, hence $N_K^L(x) \\not \\in \\mfk{Q}$, a contradiction.\n\t\t\t\\end{proof}\n\t\t\tIf one localise, the consideration on whether a prime ideal is maximal is not required. Besides, if $A$ is of Krull dimension $1$, then one has no need to consider as well. Since we have shown that $\\OK$ is a Dedekind domain, this theorem can be applied as well. Next we show the finiteness of prime ideals lying above.\n\t\t\t\n\t\t\t\\begin{corollary} \n\t\t\t\tLet $A$ be an integrally closed domain whose field of fraction is $K$. Let $E$ be a finite separable extension of $K$, and $B$ the integral closure of $A$ in $E$. Let $\\mfk{p}$ be a maximal ideal of $A$. Then there exists only a finite number of prime ideals of $B$ lying above $\\mfk{p}$.\n\t\t\t\\end{corollary}\n\t\t\t\\begin{proof}\n\t\t\t\t If $E$ is Galois over $K$, then by theorem \\ref{galois-lie-above}, $\\sigma\\mfk{P}_1 = \\mfk{P}_2$ for some $\\sigma \\in \\gal(E/K)$. Suppose $\\mfk{P}_1|\\mfk{p}$, then the set of prime ideals lying above $\\mfk{p}$ is contained in the set\n\t\t\t\t\\[\n\t\t\t\t\t\\{\\mfk{Q} \\subset B: \\mfk{Q}=\\sigma\\mfk{P}_1,\\sigma\\in\\gal(E/K)\\},\n\t\t\t\t\\]\n\t\t\t\thence is finite because $\\gal(E/K)$ is finite. If $E$ is not necessarily Galois, we can pick the smallest Galois extension $L/K$ containing $E$, which is a finite extension as well. Let $C$ be the integral closure of $A$ in $L$. Suppose $\\mfk{P},\\mfk{Q} \\in \\spec(B)$ are two distinct prime ideals lying above $\\mfk{p}$, and $\\mfk{P}',\\mfk{Q}' \\in \\spec(C)$ lying above $\\mfk{P}$ and $\\mfk{Q}$ respectively. Note $\\mfk{P}' \\ne \\mfk{Q}'$ because if not then $\\mfk{P}=\\mfk{Q}$, a contradiction. Therefore the distinct prime ideals of $B$ lying above $\\mfk{p}$ are less than the distinct prime ideals of $C$ lying above $\\mfk{p}$, which proves our assertion.\n\t\t\t\t\\[\n\t\t\t\t\t\\begin{tikzcd}\n\t\t\t\t\t\t\\mathfrak{P}'          &                                    & \\mathfrak{Q}'          & C                   \\\\\n\t\t\t\t\t\t\\mathfrak{P} \\arrow[u] &                                    & \\mathfrak{Q} \\arrow[u] & B \\arrow[u, dashed] \\\\\n\t\t\t\t\t\t& \\mathfrak{p} \\arrow[lu] \\arrow[ru] &                        & A \\arrow[u, dashed]\n\t\t\t\t\t\\end{tikzcd}\n\t\t\t\t\\]\n\t\t\t\\end{proof}\n\t\t\t\\begin{example}\\label{gauss-int-1}\n\t\t\t\tNow take $K=\\Q(i)$, $\\OK=\\Z[i]$ and $\\mfk{p}=(5)$. Since $\\gal(K/\\Q)=\\{1,\\sigma\\}$ where $\\sigma$ is the complex conjugation, there are at most two prime ideals lying above $\\mfk{p}$. First of all $5\\Z[i]$ is not prime because \n\t\t\t\t\\[\n\t\t\t\t\t5+0i = (2-i)(2+i).\n\t\t\t\t\\]\n\t\t\t\tSince $\\Z[i]$ is a PID, we only need to consider Gaussian integers that divide $5$. Keeping in mind that $\\Z[i]$ is also an Euclidean domain, we have two non-trivial solutions up to units in $\\Z[i]$:\n\t\t\t\t\\[\n\t\t\t\t\t5 = (2-i)(2+i).\n\t\t\t\t\\]\n\t\t\t\t\n\t\t\t\tAs ideals, we have $(2-i)=(1+2i)=(-2+i)$. Since $2-i$ is irreducible in $\\Z[i]$, we have found a prime ideal $\\mfk{P}=(2-i)$ lies above $\\mfk{p}$, and $\\mfk{P}'=\\sigma\\mfk{P}=(2+i)$ has to be the remaining one. Note we have also established the factorisation of $5\\Z[i]$ in the Dedekind domain $\\OK$.\n\t\t\t\t\t\n\t\t\t\\end{example}\n\t\t\n\t\t\tThis example also shows that the norm defined in theorem \\ref{galois-lie-above} makes sense, because we have\n\t\t\t\\[\n\t\t\tN_{\\Q}^{K}(a+bi)=\\prod_{\\sigma \\in \\gal(K/\\Q)}\\sigma(a+bi) = (a+bi)(a-bi)=a^2+b^2.\n\t\t\t\\]\n\t\t\tWe will study norm extensively in the future. %TODO: add reference if it is needed.\n\t\t\t\n\t\t\tLet $A$ be an integrally closed ring with quotient field $K$, and $B$ its integral closure in a finite Galois extension $L$. Then firstly $\\sigma{B}=B$ for all $\\sigma \\in \\gal(L/K)$ (Proof: $\\sigma{B} \\subset L$ is integral over $\\sigma{A}=A$, hence has to be $B$ itself). Automorphisms fixing base field give rise to Galois group, and now we are interested in automorphisms that also fix ideals. \n\t\t\t\n\t\t\t\\subsubsection{Decomposition groups and fields}\n\t\t\t\n\t\t\t\t\\begin{definition}\n\t\t\t\t\tNotations being above, let $\\mfk{p}$ be a maximal ideal of $A$, $\\mfk{P}$ maximal in $B$ lying above $\\mfk{p}$. Then the subgroup\n\t\t\t\t\t\\[\n\t\t\t\t\t\tG_\\mfk{P} = \\{\\sigma \\in \\gal(L/K):\\sigma\\mfk{P}=\\mfk{P}\\}\n\t\t\t\t\t\\]\n\t\t\t\t\tis called the \\textbf{decomposition group} of $\\mfk{P}$. Its fixed field will be denoted by $L^d$, and will be called the \\textbf{decomposition field} of $\\mfk{P}$. \n\t\t\t\t\\end{definition}\n\t\t\t\tTwo non-trivial examples are given, abelian and non-abelian. We will frequently return to these examples after new concepts are introduced. \n\t\t\t\t% TODO: expand details of these two examples.\n\t\t\t\t\\begin{example}\n\t\t\t\t\tConsider $K = \\Q(\\sqrt{-1},\\sqrt{2},\\sqrt{5})$, whose Galois group is isomorphic to $\\Z/2\\Z \\times \\Z/2\\Z \\times \\Z/2\\Z$. The decomposition field of $(5)$ is\n\t\t\t\t\t\\[\n\t\t\t\t\t\tK^d = \\Q(\\sqrt{-1},\\sqrt{2}).\n\t\t\t\t\t\\]\n\t\t\t\t\\end{example}\n\t\t\t\t\\begin{example}\n\t\t\t\t\tConsider $K = \\Q(\\sqrt[3]{19},\\omega)$ where $\\omega = e^{2\\pi i/3}$. The Galois group is $S_3$. The decomposition fields of $(3)$ are\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\Q(\\sqrt[3]{19}),\\quad \\Q(\\omega\\sqrt[3]{19}),\\quad\\Q(\\omega^2\\sqrt[3]{19}).\n\t\t\t\t\t\\]\n\t\t\t\t\tAt this point we can only compute the field manually but after introducing ramification index things are much easier. \n\t\t\t\t\\end{example}\n\t\t\t\n\t\t\t\tIt is natural to think whether a decomposition group is normal, when the Galois group is non-abelian. For this question we have an pretty elegant result. \n\t\t\t\t\n\t\t\t\t\\begin{theorem}\n\t\t\t\t\tNotation still being above, the decomposition group of $\\sigma\\mfk{P}$ where $\\sigma \\in \\gal(L/K)$ is $\\sigma G_\\mfk{P}\\sigma^{-1}$, i.e.\n\t\t\t\t\t\\[\n\t\t\t\t\t\tG_{\\sigma\\mfk{P}} = \\sigma G_\\mfk{P}\\sigma^{-1}.\n\t\t\t\t\t\\]\n\t\t\t\t\\end{theorem}\n\t\t\t\tThis theorem says, the Galois group acting on itself by conjugation yields all decomposition groups of primes of $B$ lying above a certain prime of $A$.\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tWe can write $\\gal(L/K) = \\bigcup\\sigma_jG_\\mfk{P}$ as a coset decomposition. We claim this decomposition determines distinct prime ideals lying above $\\mfk{p}$. Note\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\sigma\\mfk{P}=\\tau\\mfk{P} \\iff \\tau^{-1}\\sigma\\mfk{P}=\\mfk{P} \\iff \\tau^{-1}\\sigma \\in G_\\mfk{P}\n\t\t\t\t\t\\]\n\t\t\t\t\twhich is equivalent to say $\\tau$ and $\\sigma$ lie in the same coset mod $G_\\mfk{P}$. \n\t\t\t\t\t\n\t\t\t\t\tThis claim actually proves this theorem. On one hand, pick $\\lambda \\in G_\\mfk{P}$, then\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\sigma\\lambda\\mfk{P} = \\sigma\\lambda\\sigma^{-1}\\sigma\\mfk{P} = \\sigma\\mfk{P}\n\t\t\t\t\t\\]\n\t\t\t\t\tHence $\\sigma G_{\\mfk{P}}\\sigma^{-1} \\subset G_{\\sigma\\mfk{P}}$. Note we have used the fact that $\\sigma\\lambda,\\sigma \\in \\sigma G_\\mfk{P}$. \n\t\t\t\t\t\n\t\t\t\t\tOn the other hand, if $\\lambda\\sigma\\mfk{P} = \\sigma\\mfk{P}$, we have $\\lambda\\sigma \\in \\sigma G_\\mfk{P}$, hence $\\lambda \\in \\sigma G_\\mfk{P}\\sigma^{-1}$, which is equivalent to say $G_{\\sigma\\mfk{P}} \\subset \\sigma G_\\mfk{P} \\sigma^{-1}$.\n\t\t\t\t\\end{proof}\n\t\t\t\n\t\t\t\tAs for the field, we have a pretty concrete result:\n\t\t\t\t\t\n\t\t\t\t\\begin{theorem}\n\t\t\t\t\tAssume $L/K$ is Galois and finite. The field $L^d$ is the smallest $E$ subfield of $L$ containing $K$ such that $\\mfk{P}$ is the only prime of $B$ lying above $\\mfk{P} \\cap E$. \n\t\t\t\t\\end{theorem}\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tLet $E$ be the smallest subfield of $L$ satisfying the property above, and write $\\mfk{q} = \\mfk{P} \\cap E$. By the fundamental theorem of Galois theory ($L/E$ is Galois) and theorem \\ref{galois-lie-above}, prime ideals of $B$ lying above $\\mfk{q}$ differs by an element of $\\gal(L/E)$. But by assumption there is only one such prime $\\mfk{P}$, hence $H \\subset G_\\mfk{P}$ and therefore $E \\supset L^d$.\n\t\t\t\t\t\n\t\t\t\t\tOn the other hand, let $B^d$ be the integral closure of $A$ in $L^d$ (which is Dedekind as well), and let $\\mfk{Q}=\\mfk{P} \\cap B^d$. By theorem \\ref{galois-lie-above}, $\\mfk{P}$ is the only prime of $B$ lying above $\\mfk{Q}$ in $B^d$. Hence $E \\subset L^d$, which proves the theorem.\n\t\t\t\t\\end{proof}\n\t\t\t\t\n\t\t\t\tWe are not done yet: the result can be even much sharpener:\n\t\t\t\t\n\t\t\t\t\\begin{theorem}\\label{residue-iso}\n\t\t\t\t\tNotation being above, the canonical injection $\\varphi:A/\\mfk{p} \\to B^d/\\mfk{Q}$ is an isomorphism.\n\t\t\t\t\\end{theorem}\n\t\t\t\t\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tFirst of all we clarify what we mean by canonical injection:\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\varphi:x + \\mfk{p} \\mapsto x + \\mfk{Q}.\n\t\t\t\t\t\\]\n\t\t\t\t\t\n\t\t\t\t\tThis is indeed injective because if if $\\varphi(x+\\mfk{p})=\\mfk{Q}$, we have $x \\in \\mfk{Q}$. This gives\n\t\t\t\t\t\\[\n\t\t\t\t\t\tx \\in \\mfk{Q} \\cap A = (\\mfk{P} \\cap A) \\cap B^d = \\mfk{p} \\cap B^d = \\mfk{p}.\n\t\t\t\t\t\\]\n\t\t\t\t\t\n\t\t\t\t\tIt remains to prove that $\\varphi$ is surjective. Given $x + \\mfk{Q} \\in B^d/\\mfk{Q}$, we need to find an element $z \\in A$ such that $\\varphi(z) = x + \\mfk{Q}$. \n\t\t\t\t\t\n\t\t\t\t\tPick $\\sigma \\in \\gal(L/K) \\setminus G_\\mfk{P}$. Let\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\mfk{Q}_\\sigma = \\sigma^{-1}\\mfk{P} \\cap B^d.\n\t\t\t\t\t\\]\n\t\t\t\t\tThen $\\mfk{Q}_\\sigma \\ne \\mfk{Q}$ (note $\\mfk{P}$ is assumed to be maximal hence so are $\\mfk{Q}$ and $\\mfk{Q}_\\sigma$). Let $x$ be an element of $B^d$. By Chinese remainder theorem, there exists an element $y \\in B^d$ such that\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\t\ty &\\equiv x \\mod \\mfk{Q}, \\\\\n\t\t\t\t\t\t\ty &\\equiv 1 \\mod \\mfk{Q}_\\sigma.\n\t\t\t\t\t\t\\end{aligned}\n\t\t\t\t\t\\]\n\t\t\t\t\tHence in particular,\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\t\ty &\\equiv x \\mod \\mfk{P}, \\\\\n\t\t\t\t\t\t\ty &\\equiv 1 \\mod \\sigma^{-1}\\mfk{P}.\n\t\t\t\t\t\t\\end{aligned}\n\t\t\t\t\t\\]\n\t\t\t\t\tThe second congruence gives\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\sigma{y} \\equiv 1 \\mod \\mfk{P}.\n\t\t\t\t\t\\]\n\t\t\t\t\tNote this holds for all $\\sigma \\not \\in G_\\mfk{P}$. For $\\lambda \\in G_\\mfk{P}$, we have $\\sigma{y}=y \\equiv x \\mod \\mfk{Q}$. Thus we obtain\n\t\t\t\t\t\\[\n\t\t\t\t\t\tz=N_K^L(y) \\equiv x \\mod \\mfk{P}.\n\t\t\t\t\t\\]\n\t\t\t\t\tFirst of all $z \\in K$ by definition of norm. Since $z$ is integral over $A$, it has to be an element in $A$. We also have % TODO: 'definition of norm' deserves more explanation.\n\t\t\t\t\t\\[\n\t\t\t\t\t\tz \\equiv x \\mod \\mfk{Q}\n\t\t\t\t\t\\]\n\t\t\t\t\tbecause both $z$ and $x$ lie in $B^d$. Hence we obtain $\\varphi(z) = x + \\mfk{P}$ as we wanted.\n\t\t\t\t\\end{proof}\n\t\t\t\t\n\t\t\t\t% TODO: examples.\n\t\t\t\n\t\t\t\\subsubsection{Inertia groups and fields}\n\t\t\t\tWe are concerned about the homomorphism induced by the decomposition group.\n\t\t\t\t\\begin{theorem}\n\t\t\t\t\tNotation still being above, $\\overline{B}=B/\\mfk{P}$ is a normal extension of $\\overline{A}=A/\\mfk{p}$, and the map $\\sigma \\to \\overline{\\sigma}$ induces a homomorphism of $G_\\mfk{P}$ onto $\\gal(\\overline{B}/\\overline{A})$\n\t\t\t\t\\end{theorem}\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tAny element of $\\overline{B}$ can be written as $\\overline{x}$ for some $x \\in B$. Let $\\overline{x}$ generate a separable subextension of $\\overline{A}$, and let $f$ be the irreducible polynomial for $x$ over $K$. The coefficient of $f$ lie in $A$ because $x$ is integral over $A$, and all the roots of $f$ are integral over $A$. Thus\n\t\t\t\t\t\\[\n\t\t\t\t\tf(X) = \\prod_{i=1}^{m}(X-x_i)\n\t\t\t\t\t\\]\n\t\t\t\t\tsplits into linear factors in $B$. Since\n\t\t\t\t\t\\[\n\t\t\t\t\t\\bar{f}(X)=\\prod_{i=1}^{m}(X-\\overline{x}_i)\n\t\t\t\t\t\\]\n\t\t\t\t\tand all the $\\overline{x}_i$ lie in $\\overline{B}$, it follows that $\\bar{f}$ splits into linear factors in $\\overline{B}$. We observe that $f(x)=0 \\implies \\bar{f}(x)=0$. Hence $\\overline{B}$ is normal over $\\overline{A}$, and\n\t\t\t\t\t\\[\n\t\t\t\t\t[\\overline{A}(\\overline{x}):\\overline{A}] \\le [K(x):K] \\le [L:K].\n\t\t\t\t\t\\]\n\t\t\t\t\tThis implies that the maximal separable subextension of $\\overline{A}$ in $\\overline{B}$ is of finite degree over $A$ by the primitive element theorem, and in fact is always bounded by $[L:K]$.\n\t\t\t\t\t\n\t\t\t\t\tIt remains to prove that $\\sigma \\mapsto \\overline{\\sigma}$ is actually a surjective homomorphism. By theorem \\ref{residue-iso}, it suffices to take $K=L^d$ and $\\gal(L/K)=G_\\mfk{P}$. Take a generator $\\overline{x}$ of the maximal subextension of $\\overline{B}$ over $\\overline{A}$, for some $x \\in B$. Let $f$ be the irreducible polynomial of $x$ over $K$. Any automorphism of $\\overline{B}$ is determined by its effect on $\\overline{x}$, and maps $\\overline{x}$ to some root of $\\bar{f}$. Suppose that $x=x_1$. Given any root $x_i$ of $f$, there exists an element $\\sigma$ of $G_\\mfk{P}$ such that $\\sigma x = x_i$. Hence $\\overline{\\sigma}\\overline{x}=\\overline{x}_i$. Hence the automorphism of $\\overline{B}$ over $\\overline{A}$ is induced by elements of $G$ operate transitively on the root of $\\bar{f}$. Hence they give us all automorphisms of the residue class field, and the proof is complete.\n\t\t\t\t\\end{proof}\n\t\t\t\tThis enables us to work on algebraic closure with some ease:\n\t\t\t\t\\begin{corollary}\n\t\t\t\t\tLet $\\phi:A \\to A/\\mfk{p}$ be the canonical homomorphism, and let $\\psi_1$, $\\psi_2$ be two homomorphisms of $B$ extending $\\varphi$ in a given algebraic closure of $A/\\mfk{p}$. Then there exists an automorphism $\\sigma$ of $L$ over $K$ such that\n\t\t\t\t\t\\[\n\t\t\t\t\t\t\\psi_1 = \\psi_2 \\circ \\sigma\n\t\t\t\t\t\\]\n\t\t\t\t\\end{corollary}\n\t\t\t\t\\begin{proof}\n\t\t\t\t\tThe kernels of $\\psi_1$ and $\\psi_2$ are prime ideals of $B$ and according to theorem \\ref{galois-lie-above} they differ by an automorphism. Hence there exists $\\tau \\in \\gal(L/K)$ such that $\\psi_1$ and $\\psi_2$ have the same kernel $\\mfk{P}$. Hence there exists an automorphism $\\omega$ of $\\psi_1(B)$ onto $\\psi_2(B)$ such that $\\omega \\circ \\psi_1 = \\psi_2$. There exists an element $\\sigma$ of $G_\\mfk{P}$ such that $\\omega \\circ \\psi_1 = \\psi_1 \\circ \\sigma$, which proves what we want.\n\t\t\t\t\\end{proof}\n\t\t\t\n\t\t\t\t\\begin{definition}\n\t\t\t\t\tLet $\\overline{G}_\\mfk{P}$ be the automorphism group of $B/\\mfk{P}$. The kernel of the map\n\t\t\t\t\t\\[\n\t\t\t\t\t\tG_\\mfk{P} \\to \\overline{G}_\\mfk{P}\n\t\t\t\t\t\\]\n\t\t\t\t\tis called the inertia group. That is, these elements induce the trivial automorphism in $B/\\mfk{P}$.\n\t\t\t\t\\end{definition}\n\t\t\\subsection{Automorphisms}\n\t\\section{Dedekind domain}\n\t\n\t\t\\subsection{Operations of ideals}\n\t\t% TODO: Daniel Chapter 3.\n\t\t\\subsection{Ramification index}\n\t\t\n\t\t\\subsection{The norm and trace}\n\t\t\tWe used the concept of norm and trace at the very beginning. Here is a good chance to study them extensively. Recall for $\\mathds{C}$ and $\\mathds{R}$ we have a natural faithful representation\n\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\rho:\\mathds{C} &\\to End(\\mathds{R}^2) \\\\\n\t\t\t\t\t\t\ta+bi   &\\mapsto \\begin{pmatrix} a & -b \\\\ b & a \\end{pmatrix}.\n\t\t\t\t\\end{aligned}\n\t\t\t\\]\n\t\t\tNote $|\\rho(a+bi)|=a^2+b^2$, which is pretty close to the norm in analysis. It is not a good idea to take square root in the sense of algebra so we directly use the determinant. We will also be using trace of such matrices.\n\t\t\t\\begin{definition}\n\t\t\t\tLet $E$ be a finite extension of $k$, which we view as a finite dimensional vector space over $k$. Each $\\alpha \\in E$ induces a linear map by multiplication:\n\t\t\t\t\\[\n\t\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\tm_\\alpha : E &\\to E \\\\\n\t\t\t\t\t\t\t\tx &\\mapsto \\alpha{x}.\n\t\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tWe define the norm and trace from $E$ to $k$ by\n\t\t\t\t\\[\n\t\t\t\t\t\\det(m_\\alpha)=N_k^E(\\alpha), \\quad \\tr(m_\\alpha)=\\tr_k^E(\\alpha).\n\t\t\t\t\\]\n\t\t\t\\end{definition}\n\t\t\t\n\t\t\tNote this has nothing to do with norm in the sense of topology. The reason is, the norm lies in $k$, which is an arbitrary field. And a field alone has nothing to do with real numbers. Besides, consider the group field $\\Q(\\sqrt{2})/\\Q$. In this field, the we have the matrix representation of $1+\\sqrt{2}$ to be\n\t\t\t\\[\n\t\t\t\t1+\\sqrt{2} \\mapsto \\begin{pmatrix} 1 & 2 \\\\ 1 & 1 \\end{pmatrix}\n\t\t\t\\]\n\t\t\twhose determinant is $-1$. It makes little sense to compare this to norm in topology.\n\t\t\n\t\t\t% TODO: formula of norm and trace.\n\t\t\t% TODO: further properties.\n\t\t\\subsection{Discrete valuation rings}\n\t\t\tA \\textbf{discrete valuation ring} can be considered as a localisation of Dedekind domain. Indeed, if $A$ is a discrete valuation ring, then $A$ is Noetherian and of Krull dimension $1$, and is integrally closed, hence Dedekind. If $A$ is local and Dedekind, then $A$ is a discrete valuation ring. In general, a Noetherian domain $A$ of Krull dimension one is Dedekind if and only if the localisation $A_\\mfk{p}$ is a discrete valuation ring for all prime $\\mfk{p}$. With respect to localisation we have a natural result:\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A$ be a Dedekind ring and $M,N$ two modules over $A$. If $M_\\mfk{p} \\subset N_\\mfk{p}$ for all prime $\\mfk{p}$, then $M \\subset N$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tLet $a \\in M$. For each $\\mfk{p}$ we can find $x_\\mfk{p} \\in N$ and $s_\\mfk{p} \\in A \\setminus \\mfk{p}$ such that $a = x_\\mfk{p}/s_\\mfk{p}$. Let $\\mfk{b}$ be the ideal generated by the $s_\\mfk{p}$, ranging through all $\\mfk{p} \\in \\spec(A)$. Then $\\mfk{b}$ is the unit ideal $A$, and we can write\n\t\t\t\t\\[\n\t\t\t\t\t1 = \\sum_{\\mfk{p} \\in \\spec(A)} y_\\mfk{p}s_\\mfk{p}\n\t\t\t\t\\]\n\t\t\t\twith elements $y_\\mfk{p} \\in A$ all but a finite number of which are $0$. This yields\n\t\t\t\t\\[\n\t\t\t\t\ta = \\sum_{\\mfk{p} \\in \\spec(A)} y_\\mfk{p}s_\\mfk{p}a = \\sum_{\\mfk{p} \\in \\spec(A)} y_\\mfk{p}x_\\mfk{p} \\in N\n\t\t\t\t\\]\n\t\t\t\tas desired.\n\t\t\t\\end{proof}\n\t\t\n\t\t\tNow we study torsion-free modules over a discrete valuation ring. If $A$ is a discrete valuation ring, then in particular, $A$ is a principal ideal ring, and any finitely generated torsion-free module $M$ over $A$ is free. If its rank is $n$, and if $\\mfk{p}$ is the maximal idea, then $M/\\mfk{p}M$ is a free module of rank $n$. Further, we have\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A$ be a local ring and $M$ a free module of rank $n$ over $A$. Let $\\mfk{p}$ be the maximal ideal of $A$. Then $M/\\mfk{p}M$ is a vector space of dimension $n$ over $A/\\mfk{p}$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tLet $\\{x_1,\\dots,x_n\\}$ be a basis of $M$ over $A$, then\n\t\t\t\t\\[\n\t\t\t\t\tM \\cong \\bigoplus_{i}Ax_i\n\t\t\t\t\\]\n\t\t\t\tand\n\t\t\t\t\\[\n\t\t\t\t\tM/\\mfk{p}M \\cong \\bigoplus_{i}(A/\\mfk{p})\\overline{x}_i\n\t\t\t\t\\]\n\t\t\t\twhere $\\overline{x}_i$ is the residue class of $x_i$ mod $\\mfk{p}$.\n\t\t\t\\end{proof}\n", "meta": {"hexsha": "8ba21a324b326b75a4e0f64c98341bba812ef564", "size": 47913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Ch01.tex", "max_stars_repo_name": "Admiraldesvl/algebraic-number-theory-note", "max_stars_repo_head_hexsha": "95afd3f2d8b52e317af7382860f58bbe4195b0c8", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/Ch01.tex", "max_issues_repo_name": "Admiraldesvl/algebraic-number-theory-note", "max_issues_repo_head_hexsha": "95afd3f2d8b52e317af7382860f58bbe4195b0c8", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-27T00:20:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-27T10:40:49.000Z", "max_forks_repo_path": "Chapters/Ch01.tex", "max_forks_repo_name": "Admiraldesvl/algebraic-number-theory-note", "max_forks_repo_head_hexsha": "95afd3f2d8b52e317af7382860f58bbe4195b0c8", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-26T15:24:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-26T15:24:03.000Z", "avg_line_length": 63.1264822134, "max_line_length": 906, "alphanum_fraction": 0.6249660844, "num_tokens": 17159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.6992408968722957}}
{"text": "\\chapter{Solution design}\n\\label {solutiondesign}\n\nThe executor contains of two parts: the main node and the agents. The agent runs on the created VMs, manages starting / updating / removing of the docker containers, executing of the distributed plan and provides information about current allocation and docker inspect output. The main node manages executing of the monolithic plan, and also provides current allocation and docker inspect output. The main node provides the allocation by sending requests to each known agent and aggregating answers.\n\n\\section{Problems}\n\\subsection{Bin packing problem}\n  The monolithic approach given current allocation and the monolithic plan (resource demand for each tier) should do creation / deletion of VMs and allocation containers on them. This problem is similar to well-known Bin packing problem. A VM for us is a bin and a container is an object which we need to pack in the bin. The container has two dimensions: CPU cores and RAM, so this is 2D bin packing problem. The main difference to bin packing problem is that we have initial allocation (initial packing) and we should not only minimize number of bins used, but also number of movements required to reach the final allocation from the initial one.\n  \n  The linear optimisation problem was formulated to solve this 2d bin packing problem:\n  \n\\begin{equation*}\n\\text{minimize } \\displaystyle\\sum\\limits_{i \\in I}^{}\\sum\\limits_{j \\in J}^{} (w_{0ij} \\alpha_{0ij} + w_{1ij} \\alpha_{1ij}) + \\sum\\limits_{i \\in I}^{} (w_{2i} \\beta_{0i} + w_{3i} \\beta_{1i})\n\\end{equation*}\n\\begin{equation*}\n\\begin{array}{ll@{}ll}\n\\text{subject to} & & &\\\\\n\\text{(1)}           & \\displaystyle\\sum\\limits_{j \\in J}^{} x_{ij} \\leq m_{0i} \\beta_{0i}  & & \\forall i \\in I\\\\\n\\text{(2)}           & \\displaystyle\\sum\\limits_{j \\in J}^{} y_{ij} \\leq m_{1i} \\beta_{0i} & & \\forall i \\in I\\\\\n\\text{(3)}           & \\displaystyle  x_{ij} \\leq m_{0i} \\alpha_{ij} & & \\forall i \\in I, j \\in J\\\\\n\\text{(4)}           & \\displaystyle y_{ij} \\leq m_{1i} \\alpha_{ij} & & \\forall i \\in I, j \\in J\\\\\n\\text{(5)}           & \\displaystyle\\sum\\limits_{i \\in I}^{} x_{ij} = d_{0j} & & \\forall j \\in J\\\\\n\\text{(6)}           & \\displaystyle\\sum\\limits_{i \\in I}^{} y_{ij} = d_{1j} & & \\forall j \\in J\\\\\n\\text{(7)}           & \\displaystyle m_{1i} x_{ij} \\geq y_{ij} & & \\forall i \\in I, j \\in J\\\\\n\\text{(8)}           & \\displaystyle m_{0i} y_{ij} \\geq x_{ij} & & \\forall i \\in I, j \\in J\\\\\n\\text{(9)}           & \\displaystyle \\alpha_{0ij} + \\alpha_{1ij} = 1 & & \\forall i \\in I, j \\in J\\\\\n\\text{(10)}          & \\displaystyle \\beta_{0i} + \\beta_{1i} = 1 & & \\forall i \\in I\\\\\n                     & \\alpha_{0ij} \\in \\{0, 1\\}  & & \\forall i \\in I, j \\in J\\\\\n                     & \\alpha_{1ij} \\in \\{0, 1\\}  & & \\forall i \\in I, j \\in J\\\\\n                     & \\beta_{0i} \\in \\{0, 1\\}  & & \\forall i \\in I\\\\\n                     & \\beta_{1i} \\in \\{0, 1\\}  & & \\forall i \\in I\\\\\n                     & x_{ij} \\in \\mathbb{Z}  & x_{ij} \\geq 0 & \\forall i \\in I, j \\in J\\\\\n                     & y_{ij} \\in \\mathbb{Z}  & y_{ij} \\geq 0 & \\forall i \\in I, j \\in J\\\\\n\\end{array}\n\\end{equation*}\nwhere \\\\\n\\indent $I$ is the set of VMs,\\\\\n\\indent $J$ is the set of Tiers,\n\\begin{sloppypar} $\\alpha_{0ij}$ is \"tier\\_is\\_used\" binary variable that is true if we allocate container for tier[j] on VM[i],\n\\indent $\\alpha_{1ij}$ is \"tier\\_is\\_idle\" binary variable that is true only if $\\alpha_{0ij}$ is false, the equation (9) links them together,\n\\indent $\\beta_{0i}$ is \"vm\\_is\\_used\" binary variable that is true if we allocate any container for any tier on VM[i],\n\\indent $\\beta_{1i}$ is \"vm\\_is\\_idle\" binary variable that is true only if $\\beta_{0i}$ is false, the equation (10) links them together,\n\\indent $x_{ij}$ is \"cpu\\_usage\" variable: the number of CPU cores that tier[j] uses on VM[i],\n\\indent $y_{ij}$ is \"mem\\_usage\" variable: \"the number of RAM units (1 unit = 512Mb) that tier[j] uses on VM[i],\n\\indent (1) is CPU availability constraint and constraint for activation of \"vm\\_is\\_used\" variable, constant $m_{0i}$ is the number of CPU cores on VM[i] (maximum allowed value for $x_{ij}$),\n\\indent (2) is the same as (1), but for the RAM units, constant $m_{1i}$ is the number of RAM units on VM[i] (maximum allowed value for $y_{ij}$) \n\\indent (3) and (4) are activation of $\\alpha_{ij}$ constraints similar to (1) and (2). (3) is for CPU cores, (4) is for RAM units,\n\\indent (6) is the RAM units demand equation, where $d_{1j}$ is the RAM units demand from the plan for the tier[j],\n\\indent (5) is the same as (4), but for the CPU cores, $d_{0j}$ is the CPU cores demand from the plan for the tier[j],\n\\indent (7) says that if tier[j] uses some RAM on VM[i], then it must use some CPU cores,\n\\indent (8) is the same as constraint (7), but other way round: if tier[j] uses some CPU cores on VM[i], then it must use some RAM units.\n\\end{sloppypar}\n\nThis formulation of the problem requires us to know the number of VMs beforehand, which we do not know. So the upper bound number of VMs is calculated and provided to the ILP solver. VMs that are used in the initial allocation are already created, but there are also VMs that are empty and are only going to be created if there will be some container on it.\n\nConsidering the initial allocation is done by constants $w_{0ij}, w_{1ij}, w_{2i}, w_{3i}$.\nWhere $w_{0ij}$ is the constant for using tier[j] on VM[i], so knowing initial allocation we can set this constant to the cost of the container creation if there is no tier[j] on VM[i] in the initial allocation, and the cost of the container update if there is tier[j] on VM[i] in the initial allocation. Here is a pitfall that if in the initial allocation container was used on the VM, and we use it in the new allocation, we can not differentiate if the value of CPU cores and RAM units used has changed (we need to run container update command) or is not changed (we need do nothing).\n\nThe weight constant $w_{1ij}$ is the cost of removing container of the tier[j] from the VM[i], this weight should be 0 if the tier[j] was not on the VM[i] in the initial allocation.\n\nThe weight $w_{2i}$ is the cost of VM[i] creation. if VM[i] is already used in the initial allocation this constant is 0.\n\nThe weight $w_{3i}$ is the cost of using the VM[i]. This cost is 0, if \nthe VM is not created yet, and it was not used in the initial allocation.\n\nConsidering NFR-2, the weights for actions should follow these rules: \n\\begin{enumerate}\n    \\item container delete \\textless{ } container update \\textless{ } container create\n    \\item VM delete \\textless{ } VM use \\textless{ } VM create\n    \\item VM delete + container delete  + container create \\textless{ } \\\\ VM use + container update\n\\end{enumerate}\n\n \\begin{sloppypar} The rule number 3 is introduced, because it is possible a situation when for example we can remove some VM[p], this VM had in the initial allocation 1 container. The weight of vm\\_usage=30, the weight of vm\\_deletion=25, the weight of container\\_update=10, the weight of container\\_deletion=5, the weight of container\\_create=15. So to continue to use this VM the objective function will have $vm\\_usage + container\\_update=30 + 10 = 40$, and to remove this container in the worst case we need to create container in another place: $vm\\_deletion + container\\_deletion + container\\_create = 25 + 5 + 15 = 45$. So ILP minimizing the objective function will choose not to remove the VM[p], but keep it. This is against our requirement NFR-0 and we want to keep the minimum number of VMs possible. \n \\end{sloppypar}\n \n Also NFR-2 requires weight of \"container use\" be less than \"container update\", but I could not found the easy way to differentiate them in ILP. As we have initial allocation as constants, for example $c_{ij}$ is CPU cores used by container[j] on VM[i] and $m_{ij}$ is the same for RAM units. The new allocation in the ILP are variables $x_{ij}$ and $y_{ij}$ for CPU cores and RAM units accordingly. So to differentiate \"container use\" from \"container update\", we need either $x_{ij} + y_{ij} \\neq c_{ij} + m_{ij}$ or $abs(x_{ij} + y_{ij} - c_{ij} - m_{ij}) > 0$ or some \"if\" constraint that all makes our ILP non linear. The effective workaround to solve this issue is considered out of scope of this paper.\n\n\\subsection{Scalability}\nThe tier can be scalable or not. The not scalable tier can have only 1 or 0 containers. If the tier is absent in the plan, it will have 0 containers, otherwise it will be 1, whilst the scalable tier can have any number of containers $\\geq 0$ allocated on different VMs. In the ILP formulation not scalable containers are not considered, so the current workaround is too \n\n\\subsection{Limitation of the ILP formulation}\nThis ILP formulation has some limitations:\n\\begin{enumerate}\n    \\item This formulation of the problem requires us to know the number of VMs beforehand, which we do not know. But we can make upper-bound estimation.\n    \\item This formulation does not differentiate between \"container update\" and \"container use\" (do nothing with container). \n    \\item Weights should be chosen wisely to satisfy NFR-0.\n    \\item Bin packing problem is NP-hard\n    \\item We have 1 optimal solution and can not choose between several different solutions\n\\end{enumerate}\n\n\\subsection{Hooks}\nHooks are scripts that trigger on the tier / container scaling. The goal is to adjust the application's configuration after the allocation is changed.\n\nWe tried to extract and describe use cases of adjusting required:\n\\begin{enumerate}\n    \\item Jboss needs to adapt the number of threads considering the number of CPU allocated.\n    \\item LoadBalancer needs to be provided with the list of Jboss containers and resources allocated to adapt it weights.\n    \\item Jboss needs to be provided with the DB address on container creation / change.\n\\end{enumerate}\n\nThe adjustment 1 should be run for the container after it is created or updated. We call this adjustment \"scale-hook\" or \"on\\_node\\_scale\" hook. The script should be provided with 4 arguments: previous CPU cores allocated, previous RAM memory units allocated, and new CPU cores and RAM memory units allocated.\n\nIn the 2nd adjustment   the LoadBalancer tier depends on the Jboss tier. So the dependencies should be specified. Also the dependent node (LoadBalancer) should wait until all the containers of the dependee are processed (JBOSS). After that the adjustment script should be run on all the containers of the dependent node (LoadBalancer). We call this adjustment \"tier-hook\" or \"on\\_dependency\\_scale\" hook.\n\nThe 3d adjustment should be run only on the container start. To simpliy the first version of the application we decided not to implement this adjustment for the dependecy 1-to-n. Only for the dependencies n-to-1 and 1-to-1 after the dependee tier is processed, the ip of the dependee tier is provided to the dependent node on the creation (parameter \"add-host\"). \n\nThis creates some limitations: the dependee container should be processed before dependent containers. For example, if the first plan will have only dependent containers, in the next plan it will be added dependee container, and in the last plan the dependence between them will be specified, then \"add-host\" feature will not be propagated and the dependee containers will not know about the dependant one.\n\nSimilar problem if we decided to remove the not-scalable tier from the plan, the dependee containers will have not valid \"add-host\" link and even if later we put the \"not-scalable\" tier back to the plan, it will have another IP address.\n\nSo considering these limitations we suggest one of the two workarounds.\n\nThe first is to manage the DB dependencies out of the topology and provide the IP address in the topology as \"docker parameter\".\n\nThe second is just use docker \"add-host\" feature as it. So if the dependent container is removed, or the dependency is added, the user should be aware that \"add-host\" will not be specified.\n\n\\subsection{Dependencies}\nConsidering the requirement FR-9 only 1-to-1, 1-to-n and n-to-1 dependencies are supported. The dependencies between scalable tiers are not supported. The dependencies are only used to manager tier-hooks and . \nThe flow for container allocation and hooks execution should be:\n\\begin{enumerate}\n    \\item get tiers dependency graph (G)\n    \\item get set of Tiers without outgoing dependencies (T)\n    \\item run container create / update / delete for each tier in T\n    \\item run scale hooks if needed for each tier container in T\n    \\item run tier hooks if needed for each tier container in T\n    \\item remove T from G\n    \\item if G is not empty go to 2\n\\end{enumerate}\n\n\\section{Approaches}\nBesides the ILP approach to solve container allocation problem discussed above it was also tried another approache: Constraint Satisfaction Problem.\n\n\\subsection{Constraint Satisfaction Problem}\n\nCSP is defined as a triple \\textless X, D, C\\textgreater, where $X$ is a set of variables, $D$ is a set of the respective domains of values, $C$ is a set of constraints.\n\nIn our context we have 2 matrices of variables as $X$: \\\\\n$x_{ij}$ is a matrix that specify how many CPU is used by Tier[j] on VM[i],\\\\\n$y_{ij}$ is a matrix that specify how many RAM units are used by Tier[j] on VM[i].\n\nThe domain $D$ for us is all possible values of CPU cores and RAM units. For example if we have AWS t2.medium with 2 CPU cores and 8 RAM units, we have: \\\\\n$d_{0ij}$ is $\\{0, 1, 2\\}$ for CPU cores,\\\\\n$d_{1ij}$ is $\\{0, 1, 2, 3, 4, 5, 6, 7, 8\\}$ for RAM mem units.\n\nFor a set of constraints $C$ we should consider similar to ILP:\n\\begin{itemize}\n    \\item availability constraints on each VM for CPU cores and for RAM mem units\n    \\item demand constraint considering the plan\n    \\item 0 CPU cores with RAM \\textgreater{} 0 or other way round\n\\end{itemize}\n\n\\subsection{Limitation of the CSP}\nThis CSP formulation has also some limitations:\n\\begin{enumerate}\n    \\item Comparing to ILP, changing domain to continuous values may cause problems.\n    \\item The solution of the CSP is a list of different solutions, that can differ only by a permutation. We can have a factorial number of different solutions which we need to look to found the optimal one considering the initial allocation.\n    \\item The problem is NP-Hard and the complexity growth is much faster than the ILP.\n\\end{enumerate}\n\nThe CSP formulation has one insuperable problem that it does not scale. If we have 10 Tiers, 10 VMs, and 16 CPU cores and 64 RAM mem units, the CSP solution does not complete in appropriate time.\n\n\\section{Architecture}\n\n\\begin{figure}[ht]\n  \\centering\n    \\includegraphics[width=350px,natwidth=688,natheight=617]{./pictures/architecture}\n    \\caption{Architecture}\n\\end{figure}\n\nThe architecture consists of two main components: Executor Main Node and Executor Agent. The main node accepts a monolithic plan, orchestrates agents \nand has a whole picture of VMs allocated. The agent node can accept a distributed plan to execute, can run / start / stop docker containers, provides the allocation information and output of docker inspect command.\n\nThese executor nodes are \"Execute\" part of the autonomous system MAPE framework. The Monitor component measures different metrics of applications that are\nrunning in the containers on the Executor agents, and provide this information to the Analyze component. The Plan component together with the Analyze component produce a new plan (a resource demand for tiers) which is sent to Executor.\n\n\\clearpage\n\\subsection{Components}\n\\begin{figure}[ht]\n  \\centering\n    \\includegraphics[width=350px,natwidth=553,natheight=303]{./pictures/main-classes}\n    \\caption{Executor main node classes}\n\\end{figure}\n\n\\begin{figure}[ht]\n  \\centering\n    \\includegraphics[height=150px,natwidth=113,natheight=203]{./pictures/agent-classes}\n    \\caption{Executor agent node classes}\n\\end{figure}", "meta": {"hexsha": "098c9beff18bac556f39e5d34da3d2463c280fa3", "size": 15924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "solutiondesign.tex", "max_stars_repo_name": "n43jl/thesis", "max_stars_repo_head_hexsha": "f7da3a5e8a01f6d9a83edabc6778683a5c225a5f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "solutiondesign.tex", "max_issues_repo_name": "n43jl/thesis", "max_issues_repo_head_hexsha": "f7da3a5e8a01f6d9a83edabc6778683a5c225a5f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solutiondesign.tex", "max_forks_repo_name": "n43jl/thesis", "max_forks_repo_head_hexsha": "f7da3a5e8a01f6d9a83edabc6778683a5c225a5f", "max_forks_repo_licenses": ["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.7021276596, "max_line_length": 813, "alphanum_fraction": 0.7319140919, "num_tokens": 4202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.69919403376114}}
{"text": "\\subsection{ReLU Fourier representation }%-- Simple version}\n\nWe introduce the Taylor expansion of $e^{iz}$ with integral remainder as follows.\n\\begin{lemma}\nFor $|z|\\leq c$, \n\\begin{equation}  \ne^{iz} -  iz -1\n= \n- \\int_{0}^c\\left[(z - u)_+e^{iu} + (-z - u)_+e^{-iu} \\right]du.\n\\end{equation}  \n\\end{lemma}\n\\begin{proof}  \nBy the Taylor expansion with integral remainder,\n\\begin{equation} \ne^{iz} = 1 + iz  - \\int_0^z e^{iu}(z-u)du.\n\\end{equation}\nLet $u_+=\\max (u, 0)$ and $u_-=\\min(u,0)$. Then, $u_-=-(-u)_+$ and \n$$\nz-u=(z-u)_+ + (z-u)_-=(z-u)_+ - (u-z)_+.\n$$\nIt follows that\n\\begin{equation}\n\\begin{split}\n\\int_{0}^z (z-u)e^{iu} du=&\\int_{0}^z (z-u)_+e^{iu} du + \\int_{0}^z -(u-z)_+e^{iu} du\n\\\\\n=&\\int_{0}^z (z-u)_+e^{iu} du + \\int_{0}^{-z}  (-u-z)_+e^{-iu} du\n\\\\\n=&\\int_{0}^c (z-u)_+e^{iu} du + (-u-z)_+e^{-iu} du.\n\\end{split}\n\\end{equation}\nThus,\n\\begin{equation}  \ne^{iz} - 1 - iz \n= \n-\\int_{0}^c\\left[(z - u)_+e^{iu} + (-z - u)_+e^{-iu} \\right]du,\n\\end{equation}  \nwhich completes the proof.\n\\end{proof}\n\nLet $z=\\omega\\cdot x$, $u=\\|\\omega\\|_{\\ell_1}t$ and $\\bar \\omega={\\omega\\over \\|\\omega\\|_{\\ell_1}}$. If $\\Omega$ is bounded, say $|x|\\le T$, $|\\bar \\omega \\cdot x|\\le T$. There exists the following expansion for $e^{i\\omega\\cdot x}$.\n\\begin{lemma}\\label{lm:talorcomplex}\nIf $|x|\\le T$,\n\\begin{equation}  \ne^{i\\omega\\cdot x} - 1 -  i\\omega\\cdot x \n= \n- \\|\\omega\\|_{\\ell_1}^2\\int_{0}^T\\left[(\\bar \\omega\\cdot x - t)_+e^{i\\|\\omega\\|_{\\ell_1}t}\n+ (-\\bar \\omega\\cdot x - t)_+e^{-i\\|\\omega\\|_{\\ell_1}t} \\right]dt.\n\\end{equation} \nDenote \n$$\nD^\\alpha = \\partial_1^{\\alpha_1}\\partial_2^{\\alpha_2}\\cdots \\partial_d^{\\alpha_d},\\quad \\omega^\\alpha = \\omega_1^{\\alpha_1}\\omega_2^{\\alpha_2}\\cdots \\omega_d^{\\alpha_d},\\quad \\alpha!=\\alpha_1!\\alpha_2!\\cdots \\alpha_d!.\n$$\n\\end{lemma}\nIt follows  the following Taylor expansion with an integral remainder.\n\\begin{lemma}\\label{lm:probabilityexpan}\nSuppose $|x|\\le T$. There exists\n\\begin{equation}\nf(x) = f(0) + \\nabla f(0)\\cdot x\n+  \\int_{\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d}}  g(x, \\theta)\\lambda(\\theta)d\\theta  \n\\end{equation}  \nwith  $g(x,\\theta)$ and $\\lambda(\\theta)$ defined in \\eqref{eq:straglam}.\n\\end{lemma}\n\\begin{proof}\nSince $\n f(x) = \\int_{\\mathbb{R}^d} e^{i\\omega\\cdot x}\\hat{f}(\\omega)d\\omega\n$\nand \n$\n\\nabla f(x)=\\int_{\\mathbb{R}^d} i^{|\\alpha|}\\omega  e^{i\\omega\\cdot x}\\hat{f}(\\omega)d\\omega,\n$\n\\begin{eqnarray}\n\\nabla  f(0)\\cdot x=\\int_{\\mathbb{R}^d} i\\omega\\cdot  x\\hat{f}(\\omega)d\\omega.\n\\end{eqnarray} \n It follows that\n\\begin{equation}\n\\nabla  f(0) \\cdot x=i \\int_{\\mathbb{R}^d} \\omega\\cdot x\\hat{f}(\\omega)d\\omega\n=  \\int_{\\mathbb{R}^d} i\\omega\\cdot x\\hat{f}(\\omega)d\\omega.\n\\end{equation} \nLet $\\hat{f}(\\omega)=|\\hat{f}(\\omega)|e^{ib(\\omega)}$. Then, $e^{i\\|\\omega\\|_{\\ell_1}t}\\hat{f}(\\omega) = |\\hat{f}(\\omega)|e^{i(\\|\\omega\\|_{\\ell_1}t + b(\\omega))}$.\nBy Lemma \\ref{lm:talorcomplex},\n\\begin{equation}\\label{eq:fftaylor}\n\\begin{split}\n&f(x) - f(0) - \\nabla  f(0) \\cdot x\n\\\\\n= &\\int_{\\mathbb{R}^d} \\big (e^{i\\omega\\cdot x} - 1 - i\\omega\\cdot x \\big )\\hat{f}(\\omega)d\\omega.\n\\\\\n=&{\\rm Re} \\bigg (-\\int_{\\mathbb{R}^d} \\int_{0}^T\\left[(\\bar \\omega\\cdot x - t)_+e^{i\\|\\omega\\|_{\\ell_1}t}\n+ (-\\bar \\omega\\cdot x - t)_+e^{-i\\|\\omega\\|_{\\ell_1}t} \\right]\\hat{f}(\\omega)\\|\\omega\\|_{\\ell_1}^{2}dt d\\omega\\bigg )\n\\\\\n=& \\int_{\\{-1,1\\}}\\int_{\\mathbb{R}^d} \\int_{0}^T (z\\bar \\omega\\cdot x - t)_+ s(zt,\\omega)  |\\hat{f}(\\omega)|\\|\\omega\\|_{\\ell_1}^{2}dtd\\omega dz\n\\end{split}\n\\end{equation}\nwith $\\int_{\\{-1, 1\\}} r(z) dz = r(-1) + r(1)$ and\n\\begin{equation} \ns(zt,\\omega)= -\\cos(z\\|\\omega\\|_{\\ell_1}t + b(\\omega)) \n\\end{equation} \nDefine $G=\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d}$, $\\theta=(z, t, \\omega)\\in G$,\n\\begin{equation}\\label{eq:straglam}\ng(x,\\theta)= (z\\bar \\omega\\cdot x - t)_+ {\\rm sgn} s(zt,\\omega),\\qquad \\lambda(\\theta)={\\rho(\\theta)\\over \n\\int_{\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d}} \\rho(\\theta)d\\theta}.\n\\end{equation}\nwith $\\rho(\\theta) = |s(zt,\\omega)||\\hat{f}(\\omega)|\\|\\omega\\|_{\\ell_1}^{2}$. \n\nThen \\eqref{eq:fftaylor} can be written as \n\\begin{equation}\\label{eq:reluintegral}\nf(x) = f(0) +  \\nabla  f(0) \\cdot x\n+  \\int_{\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d}}  g(x, \\theta)\\lambda(\\theta)d\\theta,  \n\\end{equation}   \nwhich completes the proof.\n\\end{proof}\n\nAn application of the Monte Carlo method in Lemma \\ref{MC} to the integral \\eqref{eq:reluintegral} gives the following estimate.\n\\begin{theorem} \nSuppose $|x|\\le T$ and \n$$\n \\int_{\\mathbb{R}^{d}} |\\hat{f}(\\omega)|\\|\\omega\\|_{\\ell_1}^{2} d\\omega<\\infty.\n$$\nThere exist  $\\|\\bar \\omega_j\\|_{\\ell_1}=1$, $t\\in [0,T]$ such that \n$$\nf_n(x)= f(0) + \\nabla  f(0) \\cdot x  + {1\\over n}\\sum_{j=1}^{n} (\\bar \\omega_j\\cdot x - t_j)_+\n$$ \nsatisfies the following estimate \n\\begin{equation}\n\\|f - f_n \\|_{L^2(\\Omega)} \\leq C n^{-{1\\over 2}}.\n\\end{equation} \n%\\begin{equation}\n%\\|D^\\beta (f(x)- f_n(x))\\|_{L^2(\\Omega)}\\le \\sqrt{2^{m-k-2}(2m-k)\\over k!(m-k)!}|\\Omega|^{1/2} n^{-{1\\over 2}-{1\\over d}},\\quad |\\beta|=k\\le m.\n%\\end{equation}\n\\end{theorem}\n\n\\iffalse\n\\noindent\\textbf{A modified analysis using stratified sampling}\n\nAccording to \\eqref{eq:straglam}, the main ingredient $(z\\bar \\omega\\cdot x - t)_+$ of $g(x,\\theta)$  only includes the direction $\\bar\\omega$ of $\\omega$ which belongs to a bounded domain  $\\mathbb{S}^{d-1}$. Thanks to the continuity of $(z\\bar \\omega\\cdot x - t)_+$ with respect to $(z, \\bar\\omega, t)$ and the boundedness of $\\mathbb{S}^{d-1}$,\nthe application of the stratified sampling to the residual term of the Taylor expansion leads to the following approximation property.\n\\begin{theorem}\\label{est:stratify}\nSuppose $|x|\\le T$ and \n$$\n \\int_{\\mathbb{R}^{d}} |\\hat{f}(\\omega)|\\|\\omega\\|_{\\ell_1}^{2} d\\omega<\\infty.\n$$\nThere exist $\\beta_j\\in [-2^d,2^d]$, $\\|\\bar \\omega_j\\|_{\\ell_1}=1$, $t\\in [0,T]$ such that \n$$\nf_n(x)= f(0) + \\nabla  f(0) \\cdot x  + {1\\over n}\\sum_{j=1}^{n}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+\n$$ \nsatisfies the following estimate \n\\begin{equation}\n\\|f - f_n \\|_{L^2(\\Omega)} \\leq C n^{-{1\\over 2}-{1\\over d}}.\n\\end{equation} \n%\\begin{equation}\n%\\|D^\\beta (f(x)- f_n(x))\\|_{L^2(\\Omega)}\\le \\sqrt{2^{m-k-2}(2m-k)\\over k!(m-k)!}|\\Omega|^{1/2} n^{-{1\\over 2}-{1\\over d}},\\quad |\\beta|=k\\le m.\n%\\end{equation}\n\\end{theorem}\n\\begin{proof}\nBy Lemma \\ref{lem:stratifiedapprox}, for any decomposition $G=\\cup_{i=1}^M G_i$, there exist $\\{\\theta_i\\}_{i=1}^n$ and $\\{\\beta_i\\}_{i=1}^n\\in [0,1]$ such that \n\\begin{equation}\n\\|  f - f_n\\|_{L^2(\\Omega)} = \\|  r - r_{n}\\|_{L^2(\\Omega)} \\leq {1\\over n^{1/2}}\\max_{1\\le j\\le M}\\sup_{\\theta_{j},\\theta_{j}'\\in G_j} \\|   g(x,\\theta_j) - g(x,\\theta_j') \\|_{L^2(\\Omega)} \n\\end{equation}\nwith \n$$\nf_n(x)= f(0) +  \\nabla  f(0) \\cdot x + r_{n}(x), \\qquad r_{n}(x)={1\\over n}\\sum_{j=1}^{n}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+, \n$$\n$$\nr(x)=\\int_{\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d}}  g(x, \\theta)\\lambda(\\theta)d\\theta.\n$$\nConsider a particular decomposition $G=\\cup_{i=1}^M G_i$ as follows. \nThe variable $z$ is in the set $\\{-1,1\\}$, which can be divided into two subsets $\\{-1\\}$ and $\\{1\\}$. \nGiven a positive integer $n$, for the random variable $t$, the interval  $ [0,T]$ can be divided into $n_t$ subintervals $\\{G_i^t\\}_{i=1}^{n_t}$ such that \n$$\n|t-t'|<{1\\over 2}n^{-{1\\over d}}\\quad t,t'\\in G_i^t,\\quad 1\\leq i\\leq n_t\n$$ \nfor $n_t>2\\lceil T  n^{1\\over d}\\rceil$. \nFor variable $\\bar \\omega=\\omega/\\|\\omega\\|_{\\ell_1}\\in \\mathbb{S}^{d-1}$ where $\\mathbb{S}^{d-1}=\\{\\bar \\omega\\in \\mathbb{R}^d: \\|\\bar \\omega\\|_{\\ell_1}=1\\}$. Note that $\\mathbb{S}^{d-1}$ can be divided into $n_\\alpha$ subdomains $\\{G_i^s \\}_{i=1}^{n_s}$ such that\n$$\n\\|\\bar \\omega- \\bar \\omega'\\|_{\\ell_1}\\leq {1\\over 2}n^{-{1\\over d}}\\qquad \\bar \\omega, \\bar \\omega' \\in G_i^s,\\quad 1\\leq i\\leq n_s\n$$\nfor $(2n^{1\\over d})^{d-1}\\leq n_s\\leq \\lceil (5n^{1\\over d})^{d-1}\\rceil$ \\cite{klusowski2016uniform}.\nThen \n$$\nG=\\displaystyle \\cup \\{G_{ijk\\ell}: 1\\leq i\\leq 2,\\ 1\\leq j\\leq n_t,\\ 1\\leq k\\leq n_s,\\ 1\\le \\ell\\le 2\\}\n$$\nwith \n\\begin{equation}\nG_{ijk\\ell} = \\{(z, t, \\omega): z=(-1)^i,\\ t\\in G_j^t, \\bar \\omega \\in G_k^s,\\ {\\rm sgn} s(zt,\\omega)=(-1)^\\ell\\}.\n\\end{equation}\nDenote this decomposition of $G$ by $G=\\cup_{i=1}^{M} G_i$ with $M=4n_sn_t\\le 2^{d}n$. For each $G_i$,\n\\begin{equation}\nz=z',\\ |t-t'|<{1\\over 2}n^{-{1\\over d}},\\ \\|\\bar \\omega  - \\bar \\omega'\\|_{\\ell^1}<{1\\over 2}n^{-{1\\over d}}\\qquad \\forall \\theta=(z, t, \\omega),\\ \\theta'=(z', t', \\omega')\\in G_i.\n\\end{equation}\nFor any $\\theta_i, \\theta'_i\\in G_i$ and $|\\alpha |=1$,  \n$$\n| g(x,\\theta_i) - g(x,\\theta_i') | =  | \\bar\\omega  -   \\bar\\omega' |\\le n^{-{1\\over d}}.\n$$  \nThus, there exist $\\theta_{i,j}$ such that\n\\begin{equation}\n\\| f - f_n\\|_{L^2(\\Omega)} \\le C  n^{-{1\\over 2}-{1\\over d}}.\n\\end{equation}\nwith\n$$\nf_n(x)=  f(0) + \\nabla f(0) \\cdot x + {1\\over  n}\\sum_{j=1}^{n}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+\n$$ \nwith $\\beta_j\\in [-2^d,2^d]$,\nwhich completes the proof.\n\\end{proof}\n\n\n\\fi\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "df7ae607d44d95437944fd614ce94db8924771b2", "size": 8910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ReLUFourierSimple.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/ReLUFourierSimple.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/ReLUFourierSimple.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7767857143, "max_line_length": 347, "alphanum_fraction": 0.598989899, "num_tokens": 3947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6991940300992219}}
{"text": "\\section{Useful Languages}\n\n\\paragraph{Dyck Language} $S \\rarr bSeS | \\epsilon$\n\\paragraph{Palindromes} $S \\rarr aSa | bSb | a | b | \\epsilon$.\n\\paragraph{Antisymmetric} For $a^nb^m$ with $0 \\le n \\le m \\le kn$: $S \\rarr aSb | \\ldots | aSb^k | \\epsilon$ (this is ambiguous, impose an order, from $aXb$ to $aYb^k$, on the rules to avoid that).\n\\paragraph{Math Expressions}\n\\begin{align*}\n    E &\\rarr E + T | T \\\\\n    T &\\rarr T * F | F \\\\\n    F &\\rarr (E) | i\n\\end{align*}\nThe operators in this example are left-associative.\n", "meta": {"hexsha": "ab881be26ca92ba0db40f71380d0679d76bce040", "size": 525, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grammars/useful-languages.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": "grammars/useful-languages.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": "grammars/useful-languages.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.3846153846, "max_line_length": 198, "alphanum_fraction": 0.6419047619, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.699159745239766}}
{"text": "\\part{Calculation commands reference}\\label{part:Rechenbefehle}\r\n\r\nWhen using calculation commands in Warteschlangensimulator,\r\nit is distinguished between \\textbf{expressions} and \\textbf{comparisons}.\r\nExpressions are used to calculate a numerical values, which are e.g.\\ used as periods of time.\r\nComparisons provide a yes/no decision (for example, whether a client should be directed\r\nin a particular direction). Unlike expressions, comparisons always contain at least one comparison operator.\r\n\r\nAll commands presented below are each recognized in \\textbf{any case}.\r\nThere is no distinction between different case types.\r\n\r\n\r\n\r\n\\chapter{Constants}\r\n\r\nThe following constants are available in all calculation commands:\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{e}: Returns the basis of the exponential function $e^x$. It is\r\n$e\\approx 2.718281828459$.\r\n\r\n\\item\r\n\\cmd{pi}: Returns the value of the circle constant $\\pi$. It is\r\n$\\pi\\approx 3.1415926535898$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\chapter{Variables}\r\n\r\nWhen calculating values in the context of a concrete client, the variables\r\n\\begin{itemize}\r\n\\item\r\n\\cmd{w} for the \\textbf{previous waiting time} of the client,\r\n\\item\r\n\\cmd{t} for the \\textbf{previous transfer time} of the client ant\r\n\\item\r\n\\cmd{p} for the \\textbf{previous operating time} of the client are always available.\r\n\\end{itemize}\r\n\r\nIf the calculation is done for getting a clients score, the variable \\cmd{w} does not contain\r\nthe total waiting time of the current client but the waiting time of the current client at the\r\ncurrent station.\r\n\r\nFurthermore, all variables that are defined by an assignment element are always available.\r\nBefore the first assignment of a value to a variable, it has the value 0.\r\n\r\n\r\n\r\n\\chapter{Basic arithmetic operations}\r\n\r\nSupported instructions for the basic arithmetic operations:\r\n\\begin{itemize}\r\n\\item Addition: \\cmd{$+$}\r\n\\item Subtraction: \\cmd{$-$}\r\n\\item Multiplication: \\cmd{$*$}\r\n\\item Division: \\cmd{$/$}\r\n\\item Potentiate: \\cmd{$\\hat~$}\r\n\\end{itemize}\r\n\r\nThe rule \\textbf{point before line calculation} is taken into account.\r\nTo enforce deviating evaluations, \\textbf{brackets} can be set.\r\n\r\n\r\n\r\n\\chapter{Trailing instructions}\r\n\r\nThe following expressions can be written directly behind a number:\r\n\r\n\\begin{itemize}\r\n\\item\r\n\\cmd{\\%}:\r\nThe numerical value left to this symbol is interpreted as a percent value,\r\nfor example $30\\%=0.3$.\r\n\r\n\\item\r\n\\cmd{$^2$}:\r\nExponentiate number by 2.\r\n\r\n\\item\r\n\\cmd{$^3$}:\r\nExponentiate number by 3.\r\n\r\n\\item\r\n\\cmd{!}:\r\nCalculate factorial of the number, for example\\ $4!=1\\cdot2\\cdot3\\cdot4=24$.\r\n\r\n\\item\r\n\\cmd{$^{\\circ}$}:\r\nConverts the value left to this symbol from grad to radian, for example $180^{\\circ}=3.1415\\ldots$.\\\\\r\n(See also section \\ref{sec:Winkelfunktionen} in which the supported\r\ntrigonometric functions are presented.)\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\chapter{General functions}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{abs(x)}:\r\nAbsolute value, for example \\cm{abs(-5)=5}.\r\n\r\n\\item\r\n\\cmd{ceil(x)}:\r\nRound to next bigger integer number, for example \\cm{ceil(2.1)=3}\r\n\r\n\\item\r\n\\cmd{exp(x)}:\r\nExponential function $e^x$.\r\n\r\n\\item\r\n\\cmd{factorial(x)}:\r\nFactorial, for example $4!=1\\cdot2\\cdot3\\cdot4=24$.\r\n\r\n\\item\r\n\\cmd{binom(n;k)}:\r\nBinomial coefficient\r\n\r\n\\item\r\n\\cmd{floor(x)}:\r\nRound to next smaller integer number, for example \\cm{floor(2.9)=2}\r\n\r\n\\item\r\n\\cmd{frac(x)}:\r\nFraction part, for example \\cm{frac(1.3)=0,3}\r\n\r\n\\item\r\n\\cmd{gamma(x)}:\r\nGamma funkcion, for example \\cm{gamma(5)=4!=24}\r\n\r\n\\item\r\n\\cmd{int(x)}:\r\nInteger part, for example \\cm{int(2.9)=2}\r\n\r\n\\item\r\n\\cmd{log(x)}:\r\nLogarithm to the base $e$.\r\n\r\n\\item\r\n\\cmd{log(x;b)}:\r\nLogarithm to the base $b$.\r\n\r\n\\item\r\n\\cmd{ld(x)}:\r\nLogarithm to the base $2$, for example \\cm{ld(256)=8}.\r\n\r\n\\item\r\n\\cmd{lg(x)}:\r\nLogarithm to the base $10$, for example \\cm{lg(100)=2}.\r\n\r\n\\item\r\n\\cmd{ln(x)}:\r\nLogarithm to the base $e$.\r\n\r\n\\item\r\n\\cmd{modulo(a;b)} oder \\cmd{mod(a;b)}:\r\nDivision reminder when dividing a/b\r\n\r\n\\item\r\n\\cmd{pow(x;y)}:\r\nExponentiate $x^y$.\r\n\r\n\\item\r\n\\cmd{round(x)}:\r\nRound, for example \\cm{round(4.4)=4} and \\cm{round(4.5)=5}.\r\n\r\n\\item\r\n\\cmd{sign(x)}:\r\nSign of a number, for example \\cm{sign(3)=1} and \\cm{sign(-3)=-1}.\r\n\r\n\\item\r\n\\cmd{sqrt(x)}:\r\nSquare root, for example \\cm{sqrt{81}=9}.\r\n\r\n\\item\r\n\\cmd{sqr(x)}:\r\nSquare the number, for example \\cm{sqr(4)=16}.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Random numbers}\r\n\r\nThe following commands can be used to generate random numbers\r\nthat are \\textbf{equally distributed} in a certain area.\r\nSection \\ref{sec:Wahrscheinlichkeitsverteilungen} introduces\r\nadditional functions for generating random numbers according\r\nto certain distribution functions.\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{random()}:\r\nRandom number between 0 (inclusive) and 1 (exclusive).\r\n\r\n\\item\r\n\\cmd{random(x)}:\r\nRandom number between 0 (inclusive) and x (exclusive).\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\r\n\r\n\\chapter{Trigonometric functions}\\label{sec:Winkelfunktionen}\r\n\r\nThe trigonometric functions always refer to $2\\pi$ as a full circle (radians).\r\nIf angles in degrees ($360^\\circ$ for the full circle) are to be specified\r\nin the elementary trigonometric functions,\r\nthese have to be converted to radians using the angle functions, for example\r\n\\cm{sin($90^\\circ$)=1}.\r\n\r\n\r\n\r\n\\section{Elementary trigonometric functions}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{sin(x)}:\r\nSine\r\n\r\n\\item\r\n\\cmd{cos(x)}:\r\nCosine\r\n\r\n\\item\r\n\\cmd{tan(x)}:\r\nTangent\r\n\r\n\\item\r\n\\cmd{cot(x)}:\r\nCotangent\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Hyperbolic trigonometric functions}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{sinh(x)}:\r\nSine hyperbolicus\r\n\r\n\\item\r\n\\cmd{cosh(x)}:\r\nCosine hyperbolicus\r\n\r\n\\item\r\n\\cmd{tanh(x)}:\r\nTangent hyperbolicus\r\n\r\n\\item\r\n\\cmd{coth(x)}:\r\nCotangent hyperbolicus\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Inverse of the elementary trigonometric functions}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{arcsin(x)}:\r\nArcus sine\r\n\r\n\\item\r\n\\cmd{arccos(x)}:\r\nArcus cosine\r\n\r\n\\item\r\n\\cmd{arctan(x)}:\r\nArcus tangent\r\n\r\n\\item\r\n\\cmd{arccot(x)}:\r\nArcus cotangent\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Inverse of the hyperbolic trigonometric functions}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{arcsinh(x)}:\r\nArcus sine hyperbolicus\r\n\r\n\\item\r\n\\cmd{arccosh(x)}:\r\nArcus cosine hyperbolicus\r\n\r\n\\item\r\n\\cmd{arctanh(x)}:\r\nArcus-Tangent hyperbolicus\r\n\r\n\\item\r\n\\cmd{arccoth(x)}:\r\nArcus-Cotangent hyperbolicus\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\chapter{Functions with multiple parameters}\r\n\r\nThe following functions can accept any number of parameters.\r\nThe individual parameters have to be specified separately by semicolon \";\".\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{Min(a;b;c;...)}:\r\nCalculates the minimum of the given numbers.\r\n\r\n\\item\r\n\\cmd{Max(a;b;c;...)}:\r\nCalculates the maximum of the given numbers.\r\n\r\n\\item\r\n\\cmd{Sum(a;b;c;...)}:\r\nCalculates the sum of the given numbers.\r\n\r\n\\item\r\n\\cmd{Mean(a;b;c;...)}:\r\nCalculates the mean value of the given numbers.\r\n\r\n\\item\r\n\\cmd{Median(a;b;c;...)}:\r\nCalculates the median of the given numbers.\r\n\r\n\\item\r\n\\cmd{Var(a;b;c;...)}:\r\nCalculates the sample variance of the given numbers.\r\n\r\n\\item\r\n\\cmd{SD(a;b;c;...)}:\r\nCalculates the sample standard deviation of the given numbers.\r\n\r\n\\item\r\n\\cmd{SCV(a;b;c;...)}:\r\nCalculates the squared coefficient of variation of the given numbers.\r\n\r\n\\item\r\n\\cmd{CV(a;b;c;...)}:\r\nCalculates the coefficient of variation of the given numbers.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\chapter{Probability distributions}\\label{sec:Wahrscheinlichkeitsverteilungen}\r\n\r\nBy using the following commands both values of the density and the cumulative distribution function\r\nof the following probability distributions can be calculated as well as random numbers are based on\r\none of these probability distributions:\r\n\r\n\r\n\r\n\\section{Hypergeometric distribution \\texorpdfstring{$Hg(N,K,n)$}{Hg(N,K,n)}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{HypergeometricDist(k;N;K;n)}:\r\nCalculates the counting probability density at $k$.\r\n\r\n\\item\r\n\\cmd{HypergeometricDist(N;K;n)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Binomial distribution \\texorpdfstring{$B(n,p)$}{B(n,p)}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{BinomialDist(k;n;p)}:\r\nCalculates the counting probability density at $k$.\r\n\r\n\\item\r\n\\cmd{BinomialDist(n;p)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Poisson distribution \\texorpdfstring{$P(l)$}{P(l)}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{PoissonDist(k;l)}:\r\nCalculates the counting probability density at $k$.\r\n\r\n\\item\r\n\\cmd{PoissonDist(l)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Exponential distribution with mean \\texorpdfstring{$a$}{a}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{ExpDist(x;a;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{ExpDist(x;a;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{ExpDist(a)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{ExpDistRange(min;max;a)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Uniform distribution in the interval \\texorpdfstring{$[a;b]$}{[a;b]}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{UniformDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{UniformDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{UniformDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Normal distribution with mean \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{NormalDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{NormalDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{NormalDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{NormalDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Log-normal distribution with mean \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{LogNormalDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{LogNormalDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{LogNormalDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{LogNormalDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Gamma distribution with parameters \\texorpdfstring{$\\alpha=a$}{a} and \\texorpdfstring{$\\beta=b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{GammaDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{GammaDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{GammaDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{GammaDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Gamma distribution with mean \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{GammaDistDirect(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{GammaDistDirect(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{GammaDistDirect(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{GammaDistDirectRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Erlang distribution with parameters \\texorpdfstring{$n$}{n} and \\texorpdfstring{$\\lambda=l$}{l}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{ErlangDist(x;n;l;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{ErlangDist(x;n;l;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{ErlangDist(n;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{ErlangDistRange(min;max;n;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Beta distribution in the interval \\texorpdfstring{$[a;b]$}{[a;b]} and with parameters \\texorpdfstring{$\\alpha=c$}{c} and \\texorpdfstring{$\\beta=d$}{d}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{BetaDist(x;a;b;c;d;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{BetaDist(x;a;b;c;d;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{BetaDist(a;b;c;d)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Beta distribution in the interval \\texorpdfstring{$[a;b]$}{[a;b]} and with mean \\texorpdfstring{$c$}{c} and standard deviation \\texorpdfstring{$d$}{d}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{BetaDistDirect(x;a;b;c;d;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{BetaDistDirect(x;a;b;c;d;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{BetaDistDirect(a;b;c;d)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Weibull distribution with parameters Scale=\\texorpdfstring{$a$}{a} and Form=\\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{WeibullDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{WeibullDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{WeibullDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{WeibullDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Cauchy distribution with mean \\texorpdfstring{$a$}{a} and Scale=\\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{CauchyDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{CauchyDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{CauchyDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{CauchyDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{\\texorpdfstring{Chi$^2$}{Chi2} distribution with \\texorpdfstring{$n$}{n} degrees of freedom}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{ChiSquareDist(x;n;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{ChiSquareDist(x;n;1)}:\r\nChi$^2$ distribution with $n$ degrees of freedom.\r\n\r\n\\item\r\n\\cmd{ChiSquareDist(n)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{ChiSquareDistRange(min;max;n)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Chi distribution with \\texorpdfstring{$n$}{n} degrees of freedom}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{ChiDist(x;n;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{ChiDist(x;n;1)}:\r\nChi distribution with $n$ degrees of freedom.\r\n\r\n\\item\r\n\\cmd{ChiDist(n)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{ChiDistRange(min;max;n)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{F distribution with \\texorpdfstring{$a$}{a} degrees of freedom for the numerator and \\texorpdfstring{$b$}{b} degrees of freedom for the denominator}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{FDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{FDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{FDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{FDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Johnson SU distribution with parameters \\texorpdfstring{$\\gamma=a$}{a}, \\texorpdfstring{$\\xi=b$}{b}, \\texorpdfstring{$\\delta=c$}{c} and \\texorpdfstring{$\\lambda=d$}{d}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{JohnsonSUDist(x;a;b;c;d;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{JohnsonSUDist(x;a;b;c;d;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{JohnsonSUDist(a;b;c;d)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{JohnsonSUDistRange(min;max;a;b;c;d)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Triangular distribution over \\texorpdfstring{$[a;c]$}{[a;c]} with most likely value \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{TriangularDist(x;a;b;c;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{TriangularDist(x;a;b;c;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{TriangularDist(a;b;c)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Pert distribution over \\texorpdfstring{$[a;c]$}{[a;c]} with most likely value \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{PertDist(x;a;b;c;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{PertDist(x;a;b;c;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{PertDist(a;b;c)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Laplace distribution with mean \\texorpdfstring{$mu$}{mu} and scale factor \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{LaplaceDist(x;mu;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{LaplaceDist(x;mu;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{LaplaceDist(mu;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{LaplaceDistRange(min;max;mu;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Pareto distribution with scale parameter \\texorpdfstring{$x_{\\rm min}=xmin$}{xmin} and shape parameter \\texorpdfstring{$\\alpha=a$}{a}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{ParetoDist(x;xmin;a;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{ParetoDist(x;xmin;a;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{ParetoDist(xmin;a)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Logistic distribution with mean \\texorpdfstring{$\\mu=mu$}{mu} and scale parameter \\texorpdfstring{$s$}{s}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{LogisticDist(x;mu;s;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{LogisticDist(x;mu;s;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{LogisticDist(mu;s)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{LogisticDistRange(min;max;mu;s)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\t\r\n\\section{Inverse gaussian distribution with \\texorpdfstring{$\\lambda=l$}{l} and mean \\texorpdfstring{$mu$}{mu}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{InverseGaussianDist(x;l;mu;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{InverseGaussianDist(x;l;mu;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{InverseGaussianDist(l;mu)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{InverseGaussianDist(min;max;l;mu)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Rayleigh distribution with mean \\texorpdfstring{$mu$}{mu}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{RayleighDist(x;mu;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{RayleighDist(x;mu;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{RayleighDist(mu)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{RayleighDistRange(min;max;mu)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Log-Logistic distribution with \\texorpdfstring{$\\alpha$}{alpha} and mean \\texorpdfstring{$\\beta$}{beta}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{LogLogisticDist(x;alpha;beta;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{LogLogisticDist(x;alpha;beta;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{LogLogisticDist(alpha;beta)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{LogLogisticDistRange(min;max;alpha;beta)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Power distribution on \\texorpdfstring{$[a;b]$}{[a;b]} with exponent \\texorpdfstring{$c$}{c}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{PowerDist(x;a;b;c;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{PowerDist(x;a;b;c;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{PowerDist(a;b;c)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Gumbel distribution with expected value \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{GumbelDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{GumbelDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{GumbelDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{GumbelDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Fatigue life distribution with location parameter \\texorpdfstring{$\\mu$}{mu}, scale parameter \\texorpdfstring{$\\beta$}{beta} and form parameter \\texorpdfstring{$\\gamma$}{gamma}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{FatigueLifeDist(x;mu;beta;gamma;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{FatigueLifeDist(x;mu;beta;gamma;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{FatigueLifeDist(mu;beta;gamma)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{FatigueLifeDistRange(min;max;mu;beta;gamma)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Frechet distribution with location parameter \\texorpdfstring{$\\delta$}{delta}, scale parameter \\texorpdfstring{$\\beta$}{beta} and form parameter \\texorpdfstring{$\\alpha$}{alpha}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{FrechetDist(x;delta;beta;alpha;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{FrechetDist(x;delta;beta;alpha;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{FrechetDist(delta;beta;alpha)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{FrechetDistRange(min;max;delta;beta;alpha)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Hyperbolic secant distribution with mean \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{HyperbolicSecantDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{HyperbolicSecantDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{HyperbolicSecantDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\item\r\n\\cmd{HyperbolicSecantDistRange(min;max;a;b)}:\r\nGenerates a random number based on this distribution but limits the range of the value to $min\\ldots max$.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Left sawtooth distribution over \\texorpdfstring{$[a;b]$}{[a;b]}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{LeftSawtoothDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{LeftSawtoothDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{LeftSawtoothDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Left sawtooth distribution with mean \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{LeftSawtoothDistDirect(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{LeftSawtoothDistDirect(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{LeftSawtoothDistDirect(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Right sawtooth distribution over \\texorpdfstring{$[a;b]$}{[a;b]}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{RightSawtoothDist(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{RightSawtoothDist(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{RightSawtoothDist(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Right sawtooth distribution with mean \\texorpdfstring{$a$}{a} and standard deviation \\texorpdfstring{$b$}{b}}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{RightSawtoothDistDirect(x;a;b;0)}:\r\nCalculates the probability density at $x$.\r\n\r\n\\item\r\n\\cmd{RightSawtoothDistDirect(x;a;b;1)}:\r\nCalculates the cumulative distribution function at $x$.\r\n\r\n\\item\r\n\\cmd{RightSawtoothDistDirect(a;b)}:\r\nGenerates a random number based on this distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\section{Distribution based on empirical values}\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{EmpiricalDensity(x;value1;value2;value3;...;max)}:\\\\\r\nCalculates the probability density at $x$.\r\nThe specified values will be used for the density in the range from 0 to $max$.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistribution(x;value1;value2;value3;...;max)}:\\\\\r\nCalculates the cumulative distribution function at $x$.\r\nThe specified values will be used for the density in the range from 0 to $max$.\r\n\r\n\\item\r\n\\cmd{EmpiricalRandom(value1;value2;value3;...;max)}:\\\\\r\nGenerates a random number based on this distribution.\r\nThe specified values will be used for the density in the range from 0 to $max$.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistributionMean(value1;value2;value3;...;max)}:\\\\\r\nCalculates the expected value of the distribution.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistributionMedian(value1;value2;value3;...;max)}:\\\\\r\nCalculates the median of the distribution.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistributionQuantil(value1;value2;value3;...;max;p)}:\\\\\r\nCalculates the quantil for the probability p of the distribution.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistributionSD(value1;value2;value3;...;max)}:\\\\\r\nCalculates the standard deviation of the distribution.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistributionVar(value1;value2;value3;...;max)}:\\\\\r\nCalculates the variance of the distribution.\r\n\r\n\\item\r\n\\cmd{EmpiricalDistributionCV(value1;value2;value3;...;max)}:\\\\\r\nCalculates the coefficient of variation of the distribution.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\chapter{Erlang C calculator}\r\n\r\nBy using the following command some performance indicators can be calculated\r\nusing the extended Erlang C formula:\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{ErlangC(lambda;mu;nu;c;K;-1)}:\\\\\r\nCalculates the average queue length $\\E[N_Q]$. \r\n\r\n\\item\r\n\\cmd{ErlangC(lambda;mu;nu;c;K;-2)}:\\\\\r\nCalculates the average number of clients in the system $\\E[N]$.\r\n\r\n\\item\r\n\\cmd{ErlangC(lambda;mu;nu;c;K;-3)}:\\\\\r\nCalculates the average waiting time $\\E[W]$.\r\n\r\n\\item\r\n\\cmd{ErlangC(lambda;mu;nu;c;K;-4)}:\\\\\r\nCalculates the average residence time $\\E[V]$.\r\n\r\n\\item\r\n\\cmd{ErlangC(lambda;mu;nu;c;K;-5)}:\\\\\r\nCalculates the average accessibility $1-P(A)$.\r\n\r\n\\item\r\n\\cmd{ErlangC(lambda;mu;nu;c;K;t)}:\\\\\r\nCalculates the the probability for the service level at the $t$ seconds threshold $P(W\\le t)$.\r\n\r\n\\end{itemize}\r\n\r\nThe parameters have the following meanings:\r\n\\begin{itemize}\r\n\\item\r\n\\cm{lambda}:\\\\\r\nArrival rate $\\lambda$ (in clients per time unit), i.e.\\ inverse of the mean inter-arrival time.\r\n\\item\r\n\\cm{mu}:\\\\\r\nService rate $\\mu$ (in clients per time unit), i.e.\\ inverse of the mean service time.\r\n\\item\r\n\\cm{nu}:\\\\\r\nCancelation rate $\\nu$ (in clients per time unit), i.e.\\ inverse of the mean waiting time tolerance.\r\n\\item\r\n\\cm{c}:\\\\\r\nNumber of available parallel operating servers.\r\n\\item\r\n\\cm{K}:\\\\\r\nNumber of available places in the system (waiting and processing places together, i.e.\\ it is $K\\ge c$).\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\chapter{Allen-Cunneen approximation formula}\r\n\r\nBy using the following command some performance indicators can be calculated\r\nusing the Allen-Cunneen approximation formula:\r\n\r\n\\begin{itemize}\r\n\r\n\\item\r\n\\cmd{AllenCunneen(lambda;mu;cvI;cvS;c;-1)}:\\\\\r\nCalculates the average queue length $E[N_Q]$. \r\n\r\n\\item\r\n\\cmd{AllenCunneen(lambda;mu;cvI;cvS;c;-2)}:\\\\\r\nCalculates the average number of clients in the system $\\E[N]$.\r\n\r\n\\item\r\n\\cmd{AllenCunneen(lambda;mu;cvI;cvS;c;-3)}:\\\\\r\nCalculates the average waiting time $\\E[W]$.\r\n\r\n\\item\r\n\\cmd{AllenCunneen(lambda;mu;cvI;cvS;c;-4)}:\\\\\r\nCalculates the average residence time $\\E[V]$.\r\n\\end{itemize}\r\n\r\nThe parameters have the following meanings:\r\n\\begin{itemize}\r\n\\item\r\n\\cm{lambda}:\\\\\r\nArrival rate $\\lambda$ (in clients per time unit), i.e.\\ inverse of the mean inter-arrival time.\r\n\\item\r\n\\cm{mu}:\\\\\r\nService rate $\\mu$ (in clients per time unit), i.e.\\ inverse of the mean service time.\r\n\\item\r\n\\cm{cvI}:\\\\\r\nCoefficient of variation of the inter-arrival times $\\CV[I]$ (small values mean that the inter-arrival times are very homogeneous).\r\n\\item\r\n\\cm{cvS}:\\\\\r\nCoefficient of variation of the service times $\\CV[S]$ (small values mean that the operations are very homogeneous).\r\n\\item\r\n\\cm{c}:\\\\\r\nNumber of available parallel operating servers.\r\n\\end{itemize}", "meta": {"hexsha": "cdff58044a4cc5a30aaa6d55213bfb6681640e80", "size": 29973, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Simulator/build/Help/Scripting/en/Calculation1.tex", "max_stars_repo_name": "A-Herzog/Warteschlangensimulator", "max_stars_repo_head_hexsha": "fd83d400944a59147a465a4683b2f9258c3de5d0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-14T05:36:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T14:24:12.000Z", "max_issues_repo_path": "Simulator/build/Help/Scripting/en/Calculation1.tex", "max_issues_repo_name": "A-Herzog/Warteschlangensimulator", "max_issues_repo_head_hexsha": "fd83d400944a59147a465a4683b2f9258c3de5d0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-06-17T22:09:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T23:02:50.000Z", "max_forks_repo_path": "Simulator/build/Help/Scripting/en/Calculation1.tex", "max_forks_repo_name": "A-Herzog/Warteschlangensimulator", "max_forks_repo_head_hexsha": "fd83d400944a59147a465a4683b2f9258c3de5d0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-06-08T04:26:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-15T22:42:59.000Z", "avg_line_length": 23.289044289, "max_line_length": 188, "alphanum_fraction": 0.7104727588, "num_tokens": 8652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.699159217123702}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\hbadness=99999\n\\voffset=-1in\n\\oddsidemargin=5pt\n\\textwidth=450pt\n\\textheight=700pt\n\n\\begin{document}\n\\title{Linear Algebra: Week 4 Notes and Exercises}\n\\author{Christopher Aytona}\n\\maketitle\n\n\\section{Notes}\nNotes\\\\\n\nVector Space\\\\\n1) $\\vec{0} \\in V$\\\\\n2) $\\vec{u}, \\vec{v} \\in V$ then must have $\\vec{u} + \\vec{v} \\in V$\\\\\n3) $c \\in \\mathbb{R}, \\vec{u} \\in V$ then must have $c \\vec{u} \\in V$\\\\\nExercise\\\\\n\n2) a) True because scaling $\\vec{u}$ with either a positive or negative value will still be in $W$.\\\\\n$\\vec{u} = \\begin{bmatrix}\nx_1\\\\\ny_1\n\\end{bmatrix}, x_1 \\geq 0, y_1 \\geq 0$\\\\\n$c \\begin{bmatrix}\nx_1\\\\\ny_1\n\\end{bmatrix} = \\begin{bmatrix}\ncx_1\\\\\ncy_1\n\\end{bmatrix}$\\\\\n$c \\geq 0 \\Rightarrow cx_1 \\geq 0 \\Rightarrow cy_1 \\geq 0$\\\\\n$c \\leq 0 \\Rightarrow cx_1 \\leq 0 \\Rightarrow cy_1 \\leq 0$\\\\\nb)Let $\\vec{u} = \\begin{bmatrix}\n4\\\\\n2\n\\end{bmatrix}$, $\\vec{v} = \\begin{bmatrix}\n-1\\\\\n-8\n\\end{bmatrix}$ $\\therefore \\vec{u} + \\vec{v} = \\begin{bmatrix}\n3\\\\\n-6\n\\end{bmatrix}$ which is not in any of the quadrants associated with $W \\therefore W$ is not a vector space .\\\\\n\n6) $p(t) = a + t^2$\\\\\n$V = \\begin{bmatrix}\nx_1&x_2&x_3\n\\end{bmatrix} \\in \\mathbb{R}^3 | x_1 \\in \\mathbb{R}, x_2 = 0, x_3 = 1$\\\\\n$\\begin{bmatrix}\na&0&1\n\\end{bmatrix}$\nIts not a vector space because scaling or adding vectors will change the $x_3$.\\\\\n\n\\section{Exercises}\n\n1. Let $V$ be the first quadrant in the $xy$-plane; that is let $V = \\{\n\\begin{bmatrix}\nx\\\\\ny\n\\end{bmatrix} : x \\geq 0, y \\geq 0 \\} $\\\\\na) If $u$ and $v$ are in $V$, is $u+v$ in $V$? Why?\\\\\nIf $\\vec{u}, \\vec{v} \\in V$ is $\\vec{u} + \\vec{v} \\in V$\\\\\n$\\vec{u} \\in V \\Rightarrow \\vec{u} = \\begin{bmatrix}\nx_1\\\\\ny_1\n\\end{bmatrix}, x_1 \\geq 0, y_1 \\geq 0$\\\\\n$\\vec{v} \\in V \\Rightarrow \\vec{v} = \\begin{bmatrix}\nx_2\\\\\ny_2\n\\end{bmatrix}, x_2 \\geq 0, y_2 \\geq 0$\\\\\n$\\vec{u} + \\vec{v} = \\begin{bmatrix}\nx_1\\\\\ny_1\n\\end{bmatrix} + \\begin{bmatrix}\nx_2\\\\\ny_2\n\\end{bmatrix} = \\begin{bmatrix}\nx_1 + x_2\\\\\ny_1 + y_2\n\\end{bmatrix} = x_1 + x_2 \\geq 0, y_1 + y_2 \\geq 0$\\\\\n$\\Rightarrow \\vec{u} + \\vec{v} \\in V$\\\\\nb) Find a specific vector $u$ in $V$ and a specific scalar $c$ such that $cu$ is not in $V$. (This is enough to show that $V$ is not a vector space.)\\\\\nLet $\\vec{u} = \\begin{bmatrix}\n1\\\\\n1\n\\end{bmatrix}$ then $\\vec{u} \\in V$,\\\\\nLet $c = -1$ then $c\\vec{u} = -1\\begin{bmatrix}\n1\\\\\n1\n\\end{bmatrix} = \\begin{bmatrix}\n-1\\\\\n-1\n\\end{bmatrix} \\notin V$\\\\\n2. Let $W$ be the union of the first and third quadrants in the $xy$-plane. That is, let $W = \\{\\begin{bmatrix}\nx\\\\\ny\n\\end{bmatrix} : xy \\geq 0 \\}$\\\\\na) If $u$ is in $W$ and $c$ is any scalar, is $cu$ in W? Why?\\\\\nIf $\\vec{u} \\in W, c \\in \\mathbb{R}$, is $c\\vec{u} \\in W$\\\\\nLet $\\vec{u} = \\begin{bmatrix}\nx_1\\\\\ny_1\n\\end{bmatrix}, x_1y_1 \\geq 0$, Let $c \\in \\mathbb{R}$\\\\\n$cu = c\\begin{bmatrix}\nx_1\\\\\ny_1\n\\end{bmatrix} = \\begin{bmatrix}\ncx_1\\\\\ncy_1\n\\end{bmatrix}$\\\\\n$(cx_1)(cy_1) = c^2x_1y_1$\\\\\nBut $c^2 \\geq 0, \\forall c \\in \\mathbb{R}$\\\\\n$c^2x_1y_1 \\geq 0 \\Rightarrow c\\vec{u}\\in W$\\\\\nb) Find specific vectors $u$ and $v$ in $W$ such that $u + v$ is not in $W$. This is enough to show that $W$ is not a vector space.\\\\\nLet $\\vec{u} = \\begin{bmatrix}\n1\\\\\n2\n\\end{bmatrix}$, let $\\vec{v} = \\begin{bmatrix}\n-2\\\\\n-1\n\\end{bmatrix}$\\\\\nThen $\\vec{u} + \\vec{v} = \\begin{bmatrix}\n1-2\\\\\n2-1\n\\end{bmatrix} = \\begin{bmatrix}\n-1\\\\\n1\n\\end{bmatrix} \\notin W, since (-1)(1) = -1$\\\\\n\nIn Exercise 5-8, determine if the given set is a subspace of $\\mathbb{P}_n$ for an appropriate value of $n$. Justify your answers.\\\\\nAll polynomials $p(t) = at^2$, $a \\in \\mathbb{R}$\\\\\n5. All polynomials of the form $p(t) = at^2$, where $a$ is in $\\mathbb{R}$\\\\\nIf $a = 0, p(t) = 0t^2 = \\vec{0}$ $\\therefore \\vec{0} \\in \\{p(t)\\}$\\\\\nIf $u(t) = a_1t^2$, $v(t) = a_2t^2$, then $\\vec{u} + \\vec{v} = a_1t^2+a_2t^2 = (a_1+a_2)t^2 \\in \\{ p(t) \\}$\\\\\nIf $u(t) = a_1t^2$ and $c \\in \\mathbb{R}$, $c\\vec{u} = ca_1t^2 = (ca_1)t^2 \\in \\{p(t)\\}$\\\\\n$\\therefore \\{p(t)\\}$ is a subspace\\\\\n6. All polynomials of the form $p(t) = a + t^2$, where $a$ is in $\\mathbb{R}$\\\\\n$\\vec{0} = 0+0t+t^2$ is not in $\\{p(t)\\}$\\\\\nIf $n(t) = a_1 + t^2$, $c = 0$\\\\\n$c\\vec{u} = 0(a_1 + t^2) = 0 \\notin \\{p(t)\\}$\\\\\n$\\therefore$ not in subspace\\\\\n7. All polynomials of degree at most 3, with integers of coefficients.\\\\\nIf the scalars are any number in $\\mathbb{R}$ then $c = \\frac{1}{10}$, $p(t) = 1+x+x^2 \\Rightarrow cp(t) = \\frac{1}{10} + \\frac{1}{10}x + \\frac{1}{10}x^2 \\notin$ the set.\\\\\nBut if we restrict scalars to the set of integers then it will be a subspace.\\\\\n8. All polynomials in $\\mathbb{P}_n$ such that $p(0) = 0$.\\\\\n$\\vec{0} = 0+0t+0t^2 \\cdots , \\vec{0} = 0$\\\\\nFor $u(t) = a_0 +a_1t+ \\cdots , u(0) = 0$\\\\\n$v(t) = b_0 + b_1t+ \\cdots, v(0) = 0$\\\\\n$u(t) + v(t) = a_0+b_0 + (a_1+b_1)t + \\cdots , (u + v) = 0$\\\\\nif $u(0) = 0$, $c \\in \\mathbb{R}$ then $cu(0) = c(0) = 0$\\\\\n$\\therefore$ is a subspace.\\\\\n9. Let $H$ be the set of all vectors of the form $\\begin{bmatrix}\n-2t\\\\\n5t\\\\\n3t\n\\end{bmatrix}$. Find a vector $v$ in $\\mathbb{R}^3$ such that $H = Span\\{v\\}$. Why does this show that $H$ is a subspace of $\\mathbb{R}^3$?\\\\\n$\\vec{v} = t\\begin{bmatrix}\n-2\\\\\n5\\\\\n3\n\\end{bmatrix}$\\\\\n$t = 0 \\Rightarrow \\begin{bmatrix}\n-2(0)\\\\\n5(0)\\\\\n3(0)\n\\end{bmatrix} = \\begin{bmatrix}\n0\\\\\n0\\\\\n0\n\\end{bmatrix} \\in H$, so $\\vec{0} \\in H$\\\\\n$\\vec{u} = \\begin{bmatrix}\n-2t_1\\\\\n5t_1\\\\\n3t_1\n\\end{bmatrix}$, $\\vec{v} = \\begin{bmatrix}\n-2t_2\\\\\n5t_2\\\\\n3t_2\n\\end{bmatrix} \\Rightarrow \\vec{u} + \\vec{v} = \\begin{bmatrix}\n-2(t_1+t_2)\\\\\n5(t_1+t_2\\\\\n3(t_1+t_2)\n\\end{bmatrix} \\in H$\\\\\n$\\forall c \\in \\mathbb{R}$ $c \\vec{u} = \\begin{bmatrix}\n-2(ct)\\\\\n5(ct)\\\\\n3(ct)\n\\end{bmatrix} \\in H$\\\\\n$\\therefore H$ is a subspace.\\\\\n\nWhich of the following sets are linearly independent?\\\\\nWhich form a basis for $\\mathbb{R}^3$\\\\\n$\\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}$, $\\begin{bmatrix}\n2\\\\\n3\\\\\n0\n\\end{bmatrix}$\n$\\begin{bmatrix}\n1&2&|&0\\\\\n0&3&|&0\\\\\n0&0&|&0\n\\end{bmatrix}$\n$\\frac{1}{2}R_2 = \\begin{bmatrix}\n1&2&|&0\\\\\n0&1&|&0\\\\\n0&0&|&0\n\\end{bmatrix}$\n$R_1 - R_2 = \\begin{bmatrix}\n1&0&|&0\\\\\n0&1&|&0\\\\\n0&0&|&0\n\\end{bmatrix}$\\\\\n$t$ has no free parameter.\\\\\n$\\therefore$ are linearly independent.\\\\\n$\\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}$, $\\begin{bmatrix}\n2\\\\\n3\\\\\n0\n\\end{bmatrix}$, $\\begin{bmatrix}\n4\\\\\n5\\\\\n6\n\\end{bmatrix}$\\\\\n$\\begin{bmatrix}\n1&2&4&|&0\\\\\n0&3&5&|&0\\\\\n0&0&6&|&0\n\\end{bmatrix}$\n$\\frac{1}{6}R_3 = \\begin{bmatrix}\n1&2&4&|&0\\\\\n0&3&5&|&0\\\\\n0&0&1&|&0\n\\end{bmatrix}$\n$R_1 - 4R_3 = \\begin{bmatrix}\n1&2&0&|&0\\\\\n0&3&5&|&0\\\\\n0&0&1&|&0\n\\end{bmatrix}$\n$R_2 - 5R_3 = \\begin{bmatrix}\n1&2&0&|&0\\\\\n0&3&0&|&0\\\\\n0&0&1&|&0\n\\end{bmatrix}$\n$\\frac{1}{3}R_2 = \\begin{bmatrix}\n1&2&0&|&0\\\\\n0&1&0&|&0\\\\\n0&0&1&|&0\n\\end{bmatrix}$\n$R_1 - 2R_2 = \\begin{bmatrix}\n1&0&0&|&0\\\\\n0&1&0&|&0\\\\\n0&0&1&|&0\n\\end{bmatrix}$\\\\\n$t$ has no free parameter, $\\therefore$ are linearly independent.\\\\\n$\\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}$, $\\begin{bmatrix}\n2\\\\\n3\\\\\n0\n\\end{bmatrix}$, $\\begin{bmatrix}\n4\\\\\n5\\\\\n6\n\\end{bmatrix}$, $\\begin{bmatrix}\n7\\\\\n8\\\\\n9\n\\end{bmatrix}$\\\\\n4 Vectors in $\\mathbb{R}^3$ must have at least 1 free parameter. $\\therefore$ linearly dependent.\\\\\n\\end{document}", "meta": {"hexsha": "b1c529b9b348af9921b8e05db711e79874c767d1", "size": 7107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Week4/Week4.tex", "max_stars_repo_name": "aytona/LinearAlgebra", "max_stars_repo_head_hexsha": "2a278b2957bc12456eb4bbc3f4d13b3c06d8d8d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/Week4/Week4.tex", "max_issues_repo_name": "aytona/LinearAlgebra", "max_issues_repo_head_hexsha": "2a278b2957bc12456eb4bbc3f4d13b3c06d8d8d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/Week4/Week4.tex", "max_forks_repo_name": "aytona/LinearAlgebra", "max_forks_repo_head_hexsha": "2a278b2957bc12456eb4bbc3f4d13b3c06d8d8d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7630662021, "max_line_length": 172, "alphanum_fraction": 0.5934993668, "num_tokens": 3464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6991591982744857}}
{"text": "\\newpage\n\n\\section{Earley Method}\n\nIt works on any grammar (even nondeterministic ones) by using a vector of sets.\n\nIt builds a vector of size $n+1$ where $n=|x|$ where $E[i]$ is a set of $\\langle s,j \\rangle$ with $j<i$: $\\langle q_A,j \\rangle \\in E[i]$ means that $x_{j+1\\ldots i}$ is derived from $A$ via $0_A\\rarr q_A$ in $M_A$.\n\n\\begin{algorithm*}[H]\n    \\caption{TerminalShift(E, i)}\n    \\SetAlgoLined\n    \\For{$\\langle p,j \\rangle \\in E[i-1], q\\in Q \\text{ s.t. } p \\xrightarrow{x_i} q$}{\n        add pair $\\langle q,j \\rangle$ to $E[i]$\\;\n    }\n\\end{algorithm*}\nAdd new elements based on terminal shifts, keeping the same \\emph{key}.\n\n\\begin{algorithm*}[H]\n    \\caption{Closure(E, i)}\n    \\SetAlgoLined\n    \\For{$\\langle p,j \\rangle \\in E[i], X\\in V, q\\in Q \\text{ s.t. } p \\xrightarrow{X} q$}{\n        add pair $\\langle 0_X,i \\rangle$ to $E[i]$\\;\n    }\n\\end{algorithm*}\nLike the closure of Pilot, resetting the \\emph{key} to the current index.\n\n\\begin{algorithm*}[H]\n    \\caption{NonTerminalShift(E, i)}\n    \\SetAlgoLined\n    \\For{$\\langle f,j \\rangle \\in E[i], X\\in V \\text{ s.t. } f \\text{ is final for } X$}{\n        \\For{$\\langle p,l \\rangle \\in E[j], q\\in Q \\text{ s.t. } p \\xrightarrow{X} q$}{\n            add pair $\\langle q,l \\rangle$ to $E[i]$\\;\n        }\n    }\n\\end{algorithm*}\nFor each final state $\\langle q_X,j \\rangle$ of the current set, go back to $j$ and search if there is some item that can be advanced using $X$, keep the key found in $j$.\n\n\\begin{algorithm*}[H]\n    \\caption{Completion(E, i)}\n    \\SetAlgoLined\n    \\Do{some pair has been added}{\n        Closure(E, i)\\;\n        NonTerminalShift(E, i)\\;\n    }\n\\end{algorithm*}\n\n\\begin{algorithm*}[H]\n    \\caption{Earley}\n    \\SetAlgoLined\n    $E[0] = \\{\\langle 0_S, 0 \\rangle \\}$\\;\n    \\For{$i = 1$ \\KwTo $n$}{\n        E[i] = \\{\\}\n    }\n    Completion(E, 0)\\;\n    $i = 1$\\;\n    \\While{$i \\le n \\land E[i-1] \\ne \\emptyset$}{\n        TerminalShift(E, i)\\;\n        Completion(E, i)\\;\n        $i = i + 1$\\;\n    }\n\\end{algorithm*}\n\nThe input is accepted iff $\\langle f_S, 0 \\rangle \\in E[n]$ (where $f_S$ is final).\n", "meta": {"hexsha": "8123dbb88846bdba8c383883c56d0d819a5707eb", "size": 2090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parsing/Earley.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/Earley.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/Earley.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": 32.65625, "max_line_length": 216, "alphanum_fraction": 0.5851674641, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6991171315774046}}
{"text": "\\chapter{Conclusion and Summary}\n\nIn this study, we proposed an alternative approach to the static unequal area facility layout problem, which was previously solved using, among other approaches, genetic algorithms and particle swarm optimization. Our approach utilizes the grey wolf optimization to solve the problem. We have introduced modifications to this metaheuristic in order for it to be able to produce feasible solutions. We have conducted experiments varying the value of the $c$ parameter of our proposed GWO approach, and compared this approach against a GA-based hybrid approach and a PSO approach. Results from our experiment indicate that the value of the $c$ parameter impacts the performance of our approach, and that the appropriate value for the parameter is correlated with the size of the bounding region used. Additionally, we have found that the GA-based approach is generally better than our modified GWO approach and the PSO approach. However, they showed that there is promise in GWO as an algorithm for solving FLPs. The GA approach was shown to take longer to finish as the number of buildings increase. The PSO approach is the fastest among the three, but produces the worst solutions on average. Our approach, on the other hand, is the second best in both speed and solution quality. Hence, it provides a balance in speed and balance. Our approach is also simpler, making it easier to understand and experiment with. In the future, our proposed modified GWO may be further improved to produce significantly better results. Additionally, GWO is relatively new to the field, providing researchers with plentiful opportunities to improve the algorithm. Modifying the equations of our modified GWO, such as the decay rate of $\\alpha$, is one avenue in which researchers may take to build upon our study. Another avenue is to identify whether the $c$ parameter's value can be mathematically modelled instead of being a parameter.\n", "meta": {"hexsha": "f552bb02ef88f7b8a9660e0f28dc45bc5c1350ca", "size": 1956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter8_sum.con.tex", "max_stars_repo_name": "seanballais/undergraduate-thesis-manuscript", "max_stars_repo_head_hexsha": "d2ae4c524b93ed1cb7a5fb6eedcfd3db3f90799d", "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": "chapter8_sum.con.tex", "max_issues_repo_name": "seanballais/undergraduate-thesis-manuscript", "max_issues_repo_head_hexsha": "d2ae4c524b93ed1cb7a5fb6eedcfd3db3f90799d", "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": "chapter8_sum.con.tex", "max_forks_repo_name": "seanballais/undergraduate-thesis-manuscript", "max_forks_repo_head_hexsha": "d2ae4c524b93ed1cb7a5fb6eedcfd3db3f90799d", "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": 489.0, "max_line_length": 1921, "alphanum_fraction": 0.8154396728, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.6991171274302621}}
{"text": "\\section{Exercises in Probability}\\label{S:xsProbability}\n\\begin{ExerciseList}\n\\Exercise\n{In English language text, the twenty six letters in the alphabet occur with the following frequencies:\n{\\footnotesize $$\n\\mathsf{\n\\begin{array}{cccccccccccccccccc}\n\\sf E   &       13      \\%&     \\sf R   &       7.7     \\%&     \\sf A   &       7.3     \\%&     \\sf H   &       3.5     \\%&     \\sf F   &       2.8     \\%&     \\sf M    &      2.5     \\%&     \\sf W   &       1.6     \\%&     \\sf X   &       0.5     \\%&     \\sf J   &       0.2     \\%\\\\\n\\sf T   &       9.3     \\%&     \\sf O   &       7.4     \\%&     \\sf S   &       6.3     \\%&     \\sf L   &       3.5     \\%&     \\sf P   &       2.7     \\%&     \\sf Y    &      1.9     \\%&     \\sf V   &       1.3     \\%&     \\sf K   &       0.3     \\%&     \\sf Z   &       0.1     \\%\\\\\n\\sf N   &       7.8     \\%&     \\sf I   &       7.4     \\%&     \\sf D   &       4.4     \\%&     \\sf C   &       3       \\%&     \\sf U   &       2.7     \\%&     \\sf G    &      1.6     \\%&     \\sf B   &       0.9     \\%&     \\sf Q   &       0.3     \\%&             &               \\\\\n\\end{array}\n}\n$$}\nSuppose you pick one letter at random from a randomly chosen English\nbook from our central library with\n$\\Omega=\\{\\mathsf{A,B,C,\\ldots,Z}\\}$ (ignoring upper/lower cases),\nthen what is the probability of these events?\n\\begin{itemize}\n\\item[(a)]$\\P(\\{\\mathsf{Z}\\})$\n\\item[(b)]$\\P(\\textrm{`picking any letter'})$\n\\item[(c)] $\\P(\\{\\mathsf{E},\\mathsf{Z}\\})$\n\\item[(d)]$\\P(\\textrm{`picking a vowel'})$\n\\item[(e)]$\\P(\\textrm{`picking any letter in the word WAZZZUP'})$\n\\item[(f)]$\\P(\\textrm{`picking any letter in the word WAZZZUP or a vowel'})$.\n\\end{itemize}\n}\n\\label{Ex:RandomEnglishLetter}\n\\Answer\n{\\bit\n\\item[(a)] $\\P(\\{\\mathsf{Z}\\})=0.1\\%=\\frac{0.1}{100}=0.001$\n\\item[(b)] $\\P(\\textrm{`picking any letter'})= \\P(\\Omega) = 1$\n\\item[(c)] $\\P(\\{\\mathsf{E},\\mathsf{Z}\\}) =\\P(\\{\\mathsf{E}\\} \\cup\n    \\{\\mathsf{Z}\\} ) =  \\P(\\{\\mathsf{E}\\})+\\P(\\{\\mathsf{Z}\\}) =\n    0.13+0.001=0.131$, by Axiom~(3)\n\\item[(d)] $\\P(\\textrm{`picking a\n    vowel'})=\\P(\\{\\mathsf{A,E,I,O,U}\\})=(7.3\\%+13.0\\%+7.4\\%+7.4\\%+2.7\\%)=37.8\\%$,  by the addition rule for mutually exclusive events, rule (2).\n\\item[(e)] $\\P(\\textrm{`picking any letter in the word\n    WAZZZUP'})=\\P(\\{\\mathsf{W,A,Z,U,P}\\})=14.4\\%$,  by the\n  addition rule for mutually exclusive events, rule (2).\n\\item[(f)] $\\P(\\textrm{`picking any letter in the word WAZZZUP or a vowel'})=$\\\\\n$\\P(\\{\\mathsf{W,A,Z,U,P}\\})+\\P(\\{\\mathsf{A,E,I,O,U}\\})-\\P(\\{\\mathsf{A,U}\\})\n  = 14.4\\% + 37.8\\% - 10\\% = 42.2\\%$,  by the addition rule for two\narbitrary events, rule (3).\n\\eit\n}\n\n\n\\Exercise\nFind the sample spaces  for the following experiments:\n\\begin{enumerate}\n\\item Tossing 2 coins whose faces are sprayed with black paint denoted by $\\mathsf{B}$ and white paint denoted by $\\mathsf{W}$.\n\\item Drawing 4 screws from a bucket  of left-handed and right-handed screws\n  denoted by $\\mathsf{L}$ and $\\mathsf{R}$, respectively.\n\\item Rolling a die and recording the number on the upturned face  until the first $\\mathsf{6}$ appears.\n\\end{enumerate}\n\\Answer\n\\be\n\\item $\\{\\mathsf{BB},\\mathsf{BW},\\mathsf{WB},\\mathsf{WW}\\}$\n\n\\item $\\begin{aligned}\\{\\mathsf{ RRRR,RRRL,RRLR,RLRR,LRRR,RLRL,RRLL,LLRR,}\n    \\\\ \\mathsf{LRLR,LRRL,RLLR,LLLL, LLLR,LLRL,LRLL,RLLL}\\}\\end{aligned}$\n\\item $\\{6,16,26,36,46,56,116, 126,136, 146, 156,\n      216, 226, 236, 246, 256, \\,\\ldots\\}$\n\\ee\n\n\n\\Exercise\nSuppose we pick a letter at random from the word WAIMAKARIRI. \n\\begin{enumerate}\n\\item What is the sample space $\\Omega$?\n\\item  What probabilities should be assigned to the outcomes?\n\\item What is the probability of {\\emph not} choosing the letter  R?\n\\end{enumerate}\n\\Answer\n\n\\be\n\\item The sample space $\\Omega=\\{\\mathsf{W},\\mathsf{A},\\mathsf{I},\\mathsf{M},\\mathsf{K},\\mathsf{R}\\}$.\n\\item   Since there are eleven letters in WAIMAKARIRI the probabilities are:\n\\cen{ $\\P(\\sf\\{W\\})=\\frac{1}{11}$, $\\P(\\sf\\{ A\\})=\\frac{3}{11}$, $\\P( \\sf\\{ I\\})\n=\\frac{3}{11}$,\n    $\\P(\\sf\\{ M\\})=\\frac{1}{11}$, $\\P(\\sf\\{ K\\})=\\frac{1}{11}$, $\\P(\\sf\\{\n    R\\})=\\frac{2}{11}$\\,.}\n\n\\item By the complementation rule, the probability of not choosing\n    the letter R is:  \\[1\\,-\\,\\P(\\text{choosing the letter R})\\,=\\,1\\,-\\, \\frac{2}{11}\\,=\\,\\frac{9}{11}\\,.\\]\n\n\\ee\n\n\n\\Exercise\nThere are seventy five balls in total inside the Bingo Machine.  \nEach ball is labelled by one of the following five letters: \n$\\mathsf{B}$, $\\mathsf{I}$, $\\mathsf{N}$, $\\mathsf{G}$, and $\\mathsf{O}$.  \nThere are fifteen balls labelled by each letter.  \nThe letter on the first ball that comes out of a BINGO machine after it has been well-mixed is the outcome of our experiment. \n\\begin{itemize}\n\\item[(a)] Write down the sample space of this experiment.\n\\item[(b)] Find the probabilities of each simple event.\n\\item[(c)] Show that $\\P(\\Omega)$ is indeed $1$.\n\\item[(d)] Check that the addition rule for mutually exclusive events holds for the simple events $\\{B\\}$ and $\\{I\\}$. \n\\item[(e)]Consider the following events: \n$C = \\{\\mathsf{B},\\mathsf{I},\\mathsf{G}\\}$ and $D = \\{\\mathsf{G},\\mathsf{I},\\mathsf{N}\\}$.  \nUsing the addition rule for two arbitrary events, find  $\\P(C \\cup D)$.\n\\end{itemize}\n\n\\Answer\n\\be\n\\item\nFirst, the sample space is: $\\Omega=\\{ {\\mathsf{B}, \\mathsf{I},\n  \\mathsf{N}, \\mathsf{G}, \\mathsf{O} } \\} \\enspace . $\n\\medskip\n\n\\item The probabilities of simple events are:\n$$\n\\P(\\mathsf{B} )\\;=\\;\\P(\\mathsf{I})\\;=\\;\\P(\\mathsf{N})\\;=\\;\\P(\\mathsf{G})\\;=\\;\\P(\\mathsf{O})\\;=\\;{\\frac{15}{75}\\;=\\;\\frac{1}{5}} \\enspace .\n$$\n\n\\item \n\n%Axiom~(1):\n%$${0\\leq \\P(\\mathsf{B})\\;=\\;\\P(\\mathsf{I})\\;=\\;\\P(\\mathsf{N})\\;=\\;\\P(\\mathsf{G})\\;=\\;\\P(\\mathsf{O})\\;=\\;\\frac{1}{5} \\leq 1 \\enspace .}\n%$$\n\n%Axiom~(2): \nUsing the addition rule for mutually exclusive events,\n\\begin{eqnarray*}\n\\P(\\Omega)\n&=& \\P(\\mathsf{\\{B,I,N,G,O\\}})\\\\\n&=& \\P(\\{\\sf{B}\\} \\cup\\{\\sf{I}\\}\\cup \\{\\sf{N}\\} \\cup \\{\\sf{G}\\} \\cup \\{\\sf{O}\\})\\\\\n&=& \\P(\\sf B)+\\P(\\sf I)+\\P(\\sf N)+\\P(\\sf G)+\\P(\\sf O) \\quad \\text{simplifying notation} \\\\\n&=& \\frac{1}{5}+\\frac{1}{5}+\\frac{1}{5}+\\frac{1}{5}+\\frac{1}{5}\\\\\n&=& 1\n\\end{eqnarray*}\n\n\\item Since the   events $\\{\\sf B\\}$ and $\\{\\sf I\\}$ are disjoint,\n$$\n\\P(\\{\\sf{B}\\} \\cup \\{\\sf{I}\\})\\;=\\;\\P(\\sf B)+\\P(\\sf I)\\;=\\;\\frac{1}{5}+\\frac{1}{5}\\;=\\;\\frac{2}{5}\\,.\n$$\n\n\n\\medskip\n\n\n\\item  Using the addition rule for two arbitrary events we get,\n\\begin{eqnarray*}\n\\P(C \\cup D) &=& \\P(C)+\\P(D)-\\P(C\\cap D)\\\\& =& \\P(\\{\\sf{B},\\sf{I},\\sf{G}\\}) + \\P(\\{\\sf{G},\\sf{I},\\sf{N}\\}) - \\P(\\{\\sf{G},\\sf{I}\\})\\\\\n& =& \\frac{3}{5} +\\frac{3}{5} - \\frac{2}{5}\\\\& = &\\frac{4}{5} \\enspace .\n\\end{eqnarray*}\n\\ee\n\n\n\\end{ExerciseList}\n\n\n\n", "meta": {"hexsha": "9a5172dabd1d94411435b7b750270581c7e90eba", "size": 6594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInProbability.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/ExsInProbability.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/ExsInProbability.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": 42.2692307692, "max_line_length": 284, "alphanum_fraction": 0.5526235972, "num_tokens": 2634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8962513689768735, "lm_q1q2_score": 0.6990697046449852}}
{"text": "%Correct the file name.\n%X: book number\n%Y: part number\n%ZZZ: page number in three digits. So page 3 would be 003.\n\n\\documentclass[11pt]{amsbook}\n\n\\usepackage{../HBSuerDemir}\t% ------------------------\n\n\\begin{document}\n\n% ++++++++++++++++++++++++++++++++++++++\n\\hPage{b2p1/213}\n% ++++++++++++++++++++++++++++++++++++++\n\n\\noindent b) the ellipsoid $4x^2+y^2+z^2=16$\n\n\\begin{hSolution}\n \\includegraphics[width=0.45\\textwidth]{images/b2p1-213-fig01}\\\\\na) The center is at $\\hPairingParan{-1,0,2}$ and radius is equal to $2$. \\\\\n \\includegraphics[width=0.45\\textwidth]{images/b2p1-213-fig02}\\\\\nb) Writing it in the form\n$$\n\\frac{x^2}{2^2}+\\frac{y^2}{4^2}+\\frac{z^2}{4^2}=1\n$$\none has $a=2$, $b=4$, $c=4$ and that part in the I. octant is shown in the figure. \n\n\\end{hSolution}\n\n\\begin{exmp}\nSketch the quadrics:\\\\\n\n\\begin{tabular}{ll}\na) $\\frac{x^2}{4}-\\frac{y^2}{9}-\\frac{z^2}{4}=1$\\quad \\quad \\quad \\quad \nb)  $\\frac{x^2}{4}-z^2=2y$\n\\end{tabular}\n\\begin{hSolution}\n \\includegraphics[width=0.45\\textwidth]{images/b2p1-213-fig03}\\\\\na) The surface is a hyperboloid of two sheets with semi axes $a=2$, $b=3$, $c=2$ admitting $0x$ as axis. Cross sections // yz-plane cease to exist when $-2<x<2$.\\\\\n \\includegraphics[width=0.45\\textwidth]{images/b2p1-213-fig04}\\\\\nb)The surface is a hyperbolic paraboloid (or a saddle shaped surface).\\\\\n$x=0 \\implies y=-\\frac{z^2}{2}$ (a parabola)\\\\\n$z=0 \\implies y=x^2/8$ (a parabola)\n \n\\end{hSolution}\n\\end{exmp}\n\\section*{E. SECOND DEGREE SURFACES}\nThe quadrics being second degree surfaces, their equations are included in the general equation \n\\end{document}  ", "meta": {"hexsha": "24077fcc2643226757426f0e55dc46cc74ebdcc6", "size": 1593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw2/non-merged/OKAY DEMIR_38243_assignsubmission_file_/2012400048/pages/b2p1-213.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/OKAY DEMIR_38243_assignsubmission_file_/2012400048/pages/b2p1-213.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/OKAY DEMIR_38243_assignsubmission_file_/2012400048/pages/b2p1-213.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": 32.5102040816, "max_line_length": 163, "alphanum_fraction": 0.6421845574, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257127, "lm_q2_score": 0.8962513752119936, "lm_q1q2_score": 0.6990697003411223}}
{"text": "Given that many of the techniques presented in the dissertation were based on the concepts based on Aitchison geometry, we will provide a brief overview behind Aitchison geometry.\n\nAitchison geometry is a framework focused on the analysis of quantities including proportions, percentages, probabilities and concentrations.  These quantities are also referred to as compositions.  At the heart of the framework is the characterization of the Aitchison simplex, where each element of the space is a composition.  A composition can be thought of as a set of proportions, or percentages.\n\nLinear operations can be defined on compositions, known as ``perturbation'' and ``powering operations''.  These operations are linear in the Aitchison simplex and can be transformed into traditional addition and multiplication operations in Euclidean space through the use of log-ratio transformations.  Inner products can be defined in the Aitchison simplex, giving rise to the distance metrics such as the Aitchison distance.  It can also be shown that the Aitchison simplex forms a finite Hilbert space \\cite{Pawlowsky-Glahn2015-qb}.\n\n\\section{Definition}\nThe Aitchison simplex is formally defined for D species as follows\n\\[\\mathcal{S}^D=\\left\\{\\mathbf{x}=[x_1,x_2,\\dots,x_D]\\in\\mathbb{R}^D \\,\\left|\\, x_i>0,i=1,2,\\dots,D; \\sum_{i=1}^D x_i=\\lambda \\right. \\right\\}. \\]\nWhere $\\lambda>0$ can be any positive real-valued constant.  By definition, the compositions are the quantities denoted by $\\mathbf{x}$.\n\n \\begin{figure}[H]\n         \\centering\n         \\includegraphics[width=0.5\\textwidth]{appendix_c/Aitchison-simplex.jpg}\n         \\caption[An illustration of the Aitchison simplex.]\n                 {An illustration of the Aitchison simplex.  Here, there are 3 parts, $x_1, x_2,  x_3$ represent values of different proportions.  A, B, C, D and E are 5 different compositions within the simplex.  A, B and C are all equivalent and D and E are equivalent.}\n         \\label{figcS1}\n \\end{figure}\nThere are three core axioms that the Aitchison simplex, namely\n\n\\subsection{Scale invariance}\nWhether data is represented as proportions, percentages or probabilities, in the context of the Aitchison simplex all of these measurements are equivalent since they only differ by a constant scaling factor.\n\n\\subsection{Subcompositional coherence}\nObservations on shared species should be consistent. For example, supposed that there are 2 biologists that visited the exact same rainforest to count insects.  One biologist observed 3 species of spiders and 10 species of ants whereas the other biologist only observed 2 species of spiders and 7 species of ants.  If these biologists observed the same 2 spider species and the same 7 species of ants, their conclusions about those species should be the same.  For instance, they should notice that the ratio of those two spider species are consistent between their observations.  While the universal formal definition is still not clearly established, this concept can be formalized to distance metrics as follows\n\n  \\[\nd(x_k, y_k) \\leq d(x, y) \\qquad\n\\forall x, y \\in S^D, \\; x_k, y_k \\in S^k, \\; S^k \\subset S^D\n\\]\n\n\\subsection{Permutation invariance}\nThe ordering of how the proportions or were measured or counted doesn't matter.  This is analogous to how combinations are invariant to the order of selection.\n\n\n\\section{Vector Space Structure}\n\\subsection{Properties}\nThe Aitchison simplex has the following operators defined using the \\textbf{closure} operation as follows\n\n\\subsubsection{Perturbation}\n\\[ x \\oplus y = [\\frac{x_1 y_1}{\\sum_{i=1}^D x_i y_i},\\frac{x_2}{\\sum_{i=1}^D x_i y_i}, \\dots,\\frac{x_D y_D}{\\sum_{i=1}^D x_i y_i}] =\nC[x_1 y_1, ..., x_D y_D]  \\qquad \\forall x, y \\in S^D\n\\]\n\n\\subsubsection{Powering}\n\n\\[\n\\alpha \\odot x = [\\frac{x_1^{\\alpha}}{\\sum_{i=1}^D x_i^{\\alpha}},\\frac{x_2^{\\alpha}}{\\sum_{i=1}^D x_i^{\\alpha}}, \\dots,\\frac{x_D^{\\alpha}}{\\sum_{i=1}^D x_i^{\\alpha}}] =\nC[x_1 y_1, ..., x_D y_D]  \\qquad \\forall x \\in S^D, \\quad \\alpha \\in \\mathbb{R}\n\\]\n\n\\subsubsection{Inner product}\n\n\\[\n\\langle x, y \\rangle = \\frac{1}{2D}\n\\sum\\limits_{i=1}^{D}\n\\sum\\limits_{j=1}^{D}\n\\log \\frac{x_i}{x_j}\n\\log \\frac{y_i}{y_j}\n\\qquad \\forall x, y \\in S^D\n\\]\n\nUnder these these operations alone, it is sufficient to show that the Aitchison simplex forms a Euclidean vector space.\n\n\\subsection{Orthonormal bases}\nSince the Aitchison simplex forms a finite Hilbert space, it is possible to construct orthonormal bases in the simplex. Every composition can be decomposed as follows\n\n\\[ x = \\bigoplus_{i=1}^D x_i \\odot e_i \\]\n\nWhere $e_1, \\ldots e_{D-1} $ forms an orthonormal basis in the simplex \\cite{ilr}.\n\n\\section{Linear transformations}\n\nThere are 3 well-characterized isomorphisms that transform from the Aitchison simplex to real space.  All of these transforms satisfy linearity and as given below\n\n\\subsection{Additive Logratio Transform}\nThe additive log ratio (alr) transform is an where $alr: S^D \\rightarrow \\mathbb{R}^{D-1} $.  This is given by\n\n\\[ alr(x) = \\big[ \\log \\frac{x_1}{x_D} \\ldots \\log \\frac{x_{D-1}}{x_D} \\big]\\]\n\nThe choice of denominator component is arbituary, and could be any specified component.\nThis transform is commonly used in chemistry with measurements such as pH.  In addition, this is the transform most commonly used for Multinomial logistic regression.  The alr transform is not an isometry, meaning that distances on transformed values will not be equivalent to distances on the original compositions in the simplex.\n\n\\subsection{Center Logratio Transform}\nThe center log ratio (clr) tranform is both an isomorphism and an isometry where \\\\$clr: S^D \\rightarrow \\mathbb{U}, \\quad U \\subset \\mathbb{R}^{D} $\n\n\\[clr(x) = \\big[ \\log \\frac{x_1}{g(x)} \\ldots \\log \\frac{x_{D-1}}{g(x)} \\big] \\]\n\nThe inverse of this function is also known as the softmax function commonly used in neural networks.\n\n\\subsection{Isometric Logratio Transform}\nThe isometric log ratio (ilr) tranform is both an isomorphism and an isometry where $ilr: S^D \\rightarrow \\mathbb{R}^{D-1} $\n\n\\[\nilr(x) = \\big[ \\langle x, e_1 \\rangle, \\ldots \\langle x, e_{D-1} \\rangle]\n\\]\n\nThere are multiple ways to construct orthonormal bases, including using the Gram–Schmidt process Singular-value decomposition of clr transformed data.\nAnother alternative is to construct log contrasts from a bifurcating tree.  If are given a bifurcating tree, we can construct a basis from the internal nodes in the tree.\n\n \\begin{figure}[H]\n         \\centering\n         \\includegraphics[width=0.5\\textwidth]{appendix_c/Orthogonal-tree-basis.jpg}\n         \\caption[An illustration of the bifurcating trees as an orthonormal basis.]\n                 {A representation of a tree in terms of its orthogonal components. l represents an internal node, an element of the orthonormal basis. This is a precursor to using the tree as a scaffold for the ilr transform.}\n         \\label{figcS1}\n \\end{figure}\n\nEach vector in the basis would be determined as follows\n\n\\[e_l = C[exp( \\underbrace{0,...0}_{k}, \\underbrace{a,...,a}_{r},\\underbrace{b,...,b}_s,\\underbrace{0,...0)}_t]\\]\n\nThe elements within each vector are given as follows\n\n\\[a = \\frac{\\sqrt{s}}{\\sqrt{r(r+s)}} \\quad \\textrm{and} \\quad b = \\frac{-\\sqrt{r}}{\\sqrt{s(r+s)}}\\]\n\nwhere $k, r, s, t$ are the respective number of tips in the corresponding subtrees shown in the figure.  It can be shown that the resulting basis is orthonormal \\cite{groups_of_parts}.\n\nOnce the basis $\\Psi$ is built, the ilr transform can be calculated as follows\n\n\\[\nilr(x) = C[\\exp(clr(x) \\Psi)]\n\\]\n\n\nwhere each element in the ilr transformed data is of the following form\n\n\n\\[\nb_i = \\sqrt{\\frac{rs}{r+s}} \\log \\frac{g(x_R)}{g(x_S)}\n\\]\n\nwhere $ x_R$ and $ x_S$ are the set of values corresponding to the tips in the subtrees $R$ and $S$.\n", "meta": {"hexsha": "18ca8519c64ce717019f7983283d2ac9646b49fe", "size": 7792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendixc.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": "appendixc.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": "appendixc.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": 58.1492537313, "max_line_length": 714, "alphanum_fraction": 0.7416581109, "num_tokens": 2167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6990561832163016}}
{"text": "\\section{Some classic CNN models}\\label{sec:CNNs}\nIn this section, we will use the notation introduced above to \ngive a brief description of some classic CNN models.\n\n\\subsection{LeNet-5, AlexNet and VGG}\nThe  LeNet-5 \\cite{lecun1998gradient}, AlexNet \\cite{krizhevsky2012imagenet} and VGG \\cite{simonyan2014very}\ncan be written as:\n\t\\begin{equation}\n\t\\begin{cases}\n\tf^{1,0} &= \\theta^0(f), \\\\\n\tf^{\\ell,i} &= \\theta^{\\ell,i} \\circ \\sigma (f^{\\ell, j-1}), \\quad i = 1:\\nu_\\ell ~\\text{and}~ \\ell = 1:J,\\\\\n\tf^{\\ell+1,0} &= R_\\ell^{\\ell+1}( f^{\\ell,m+\\ell}).  \\\\\n\t\\end{cases}\n\t\\end{equation}\n\twhere $R_\\ell^{\\ell+1}$ can be general pooling operators and $\\theta^{\\ell,i}$ can be convolution with stride 1, \n\tor fully connected operators.  \n\tThen the CNN model will be defined by\n\t\\begin{equation}\\label{eq:cnndefine}\n\tH_0(f) = f^{L,\\nu_\\ell}.\n\t\\end{equation}\n\tIn these three classic CNN models, they still need some \n\textra fully connected layers in nonlinear mapping $H_0$ before the logistic regression as it contains \n\ta fully connected layer as in \\eqref{eq:log_reg}. \n\tThese fully connected layers are removed in ResNet to be described below.\n\\subsection{ResNet}\nThe ResNet \\cite{he2016deep} can be written as\n\t\\begin{equation}\\label{ori-ResNet}\n\t\\begin{cases}\n\tf^{1,0} &=R_{\\rm max}\\circ \\sigma \\circ \\theta^0(f), \\\\\n\tf^{\\ell,i} &= \\sigma \\left( f^{\\ell, i-1} + \\mathcal{F}^{\\ell, i} (f^{\\ell,i-1}) \\right), \\quad i = 1:\\nu_\\ell ~\\text{and}~ \\ell = 1:J ,\\\\\n\tf^{\\ell+1,0} &= \\sigma \\left( R_\\ell^{\\ell+1} (f^{\\ell, \\nu_\\ell} )+ \\mathcal{F}^{\\ell, 0} (f^{\\ell, \\nu_\\ell} ) \\right), \\quad \\ell = 1:J-1,\\\\\n\tH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\t\\end{cases}\n\t\\end{equation}\n\tHere\n\t$$\n\t\\mathcal{F}^{\\ell,i} (f^{i-1}) = \\xi^{i} \\circ \\sigma \\circ \\eta^{i} (f^{i-1}).\n\t$$\n\tGenerally, $\\xi^{\\ell,i}$ and $\\eta^{\\ell,i}$ takes the form of \\label{eq:conv-1} with zero padding and stride 1,\n\texcept, $\\eta^{\\ell,0}$  is taken as convolution with stride 2 with the same output dimension of $R_\\ell^{\\ell+1}$.\n\t\n\\subsection{iResNet} \n\tThe iResNet\\cite{he2016identity} can be written as:\n\t\\begin{equation}\\label{eq:iResNet1}\n\t\\begin{cases}\n\tf^{1,0} &=R_{\\rm max}\\circ \\sigma \\circ \\theta^0(f), \\\\\n\tf^{\\ell,i} &= f^{\\ell, i-1} + \\mathcal{F}^{\\ell, i} (f^{\\ell,i-1}), \\quad i = 1:\\nu_\\ell ~\\text{and}~ \\ell = 1:J ,\\\\\n\tf^{\\ell+1,0} &=  R_\\ell^{\\ell+1} (f^{\\ell, \\nu_\\ell} )+ \\mathcal{F}^{\\ell, 0} (f^{\\ell, \\nu_\\ell} ) , \\quad \\ell = 1:J-1,\\\\\n\tH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\t\\end{cases}\n\t\\end{equation}\n\twhere\n\t$$\n\t\\mathcal{F}^{\\ell,i} (f^{\\ell,i -1}) = \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} \\sigma (f^{\\ell,i-1}).\n\t$$\n\tThe only difference between ResNet and iResNet can be viewed as \n\tputting a $\\sigma$ in different places. \n\tThe connection of those three models are often shown with next diagrams:\n\t\\begin{figure}[!htb]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=.6\\textwidth, height=.13\\textheight]{comparison-net} \n\t\t\\end{center}\n\t\t\\caption{Comparison of CNN Structures}\n\t\\end{figure}\n\t\n\nWithout loss of generality, we extract the key \nfeedforward steps on the same grid in different CNN models as follows.\n\\begin{description}\n\t\\item[Classic CNN] \n\t\\begin{equation}\\label{eq:cCNN}\n\tf^{\\ell,i} = \\xi^i \\circ \\sigma (f^{\\ell,i-1}) \\quad \\text{or} \\quad f^{\\ell,i} = \\sigma \\circ \\xi^{i} (f^{\\ell,i-1}) .\n\t\\end{equation}\n\t\\item[ResNet] \n\t\\begin{equation}\\label{eq:ResNet}\n\tf^{\\ell,i} = \\sigma( f^{\\ell,i-1} + \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}(f^{\\ell,i-1})).\n\t\\end{equation}\n\t\\item[iResNet]\n\t\\begin{equation}\\label{eq:iResNet}\n\tf^{\\ell,i} = f^{\\ell,i-1} + \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma(f^{\\ell,i-1}).\n\t\\end{equation}\n\\end{description} \n\n", "meta": {"hexsha": "f3273461ddbc2271f3b37850f02ed5622348d1e5", "size": 3690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_classicalCNN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/mgnet_classicalCNN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/mgnet_classicalCNN.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.9285714286, "max_line_length": 144, "alphanum_fraction": 0.6365853659, "num_tokens": 1441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.699056181007234}}
{"text": "% chapters/dp.tex\n\n\\chapter{Dynamic Programming}\t\\label{chapter:dp}\n\n\\input{algs/dp/binom-recursive}\n\n\\begin{figure}[h]\n  \\includegraphics[width = 0.75\\textwidth]{figs/binom-4-2}\n  \\caption{Calculate $\\binom{4}{2}$ recursively.}\n  \\label{fig:binom-recursive}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\includegraphics[width = 0.65\\textwidth]{figs/pascal}\n  \\caption{Pascal triangle for binomial coefficients.}\n  \\label{fig:pascal}\n\\end{figure}\n\n\\input{algs/dp/binom-dp}\n\n\\[\n  (n-k+1) + (k) + k (n-k) = nk - k^2 + n + 1\n\\]\n\n\\input{algs/dp/max-subarray-origin}\n\\input{algs/dp/max-subarray}\n", "meta": {"hexsha": "705059a688c88e627c88f57187ba67f09a913c1c", "size": 580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/dp.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/dp.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/dp.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": 21.4814814815, "max_line_length": 58, "alphanum_fraction": 0.6879310345, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.875787001374006, "lm_q1q2_score": 0.6990416046129629}}
{"text": "%% Chapter 4 : Wind Energy Estimation\n\n\\section{Kinetic Energy of Air:}\n\\\n\\\n\\\n\\\nThe wind turbine converts kinetic energy of air into electrical energy. The kinetic energy possessed by the air is due to the flow of winds. The eq (\\ref{W1}) gives the kinetic energy of the air\n\n\\begin{equation}\n\\label{W1}\n\\text{K.E.(Joules)}=\\frac{1}{2}mV^2\n\\end{equation}\\\\\nwhere,\\\\\n$ m $ = Mass of Air $ (kg) $\\\\\n$ V $ = Velocity of air $ (m/s) $\\\\\n\n\n\\section{Power in Wind:}\n\\\n\\\n\\\n\\\nThe flow of the mass of air passing through the cross-section of the wind turbine blades is given by the eq (\\ref{W2})\n\n\\begin{equation}\n\\label{W2}\n\\text{mass flowrate} (kg/sec) = mass flow per sec = \\rho\\times A\\times V\n\\end{equation}\n\nThe volumetric flow rate of air is given by the eq (\\ref{W3})\n\n\\begin{equation}\n\\label{W3}\n\\text{volumetric flowrate} (m^3/sec) = A \\times V\n\\end{equation}\\\\\nwhere,\\\\\n$ \\rho $ = Air Density $ (kg/m^{3}) $\\\\\n$ A $ = Swept Area of Rotor $ (m^{2}) $\\\\\n\nThe mass flow rate of air through the cross-section of the wind turbine blades provides for the energy which is converted to electricity.\\\\\n\n\nThe eq (\\ref{W4}) gives us the relationship between power and energy.\n\n\\begin{equation}\n\\label{W4}\n\\text{Power} = \\frac{Energy}{Time}\n\\end{equation}\n\nThe power contained in wind (moving air) is given by eq (\\ref{W5}), which is the combination of eq (\\ref{W1},\\ref{W2},\\ref{W3},\\ref{W4}).\n\n\\begin{equation}\n\\label{W5}\n\\text{Power in moving air(Watts)} = \\left(\\frac{1}{2}\\right)\\times (mass flow per second)\\times V^2 \n\\end{equation}\n\nThe eq (\\ref{W6}) combines eq (\\ref{W5},\\ref{W3}) to give the mechanical power in wind in terms of air density, area and wind velocity; this is a more convenient equation for wind power computations.\n\n\\begin{equation}\n\\label{W6}\n\\text{Mechanical power in wind(Watts)} = \\left(\\frac{1}{2}\\right) \\times (\\rho \\times A ) \\times V^3\n\\end{equation}\n\nThe area in eq (\\ref{W6}) in context of wind turbine blades is the rotor-swept area (defined later in the text), but a more general equation of power in wind independent of the area variable is given in the eq (\\ref{W7}). It gives the power in wind per meter square of area.\n\n\\begin{equation}\n\\label{W7}\n\\text{Specific wind power of a site} (W/m^2) = \\left(\\frac{1}{2}\\right) \\times \\rho \\times V^3 \n\\end{equation}\\\\\n\n\n\n\\section{Power Extracted from Wind:}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{figc5h1}) illustrates the different components of a typical Wind Turbine.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Wind11}\n\\caption{Wind Turbine [6]}\n\\label{figc5h1} %% to refer use, \\ref{}\n\\end{figure}\n\nAs the wind passes through the cross-section of the wind turbine blades, some portion of its kinetic energy is captured by the wind turbine blades and converted to electricity. In this process the wind loses some of its velocity due to loss of kinetic energy giving us two different wind velocities of upstream (wind velocity in front of the wind turbine) and downstream (wind velocity behind the wind turbine). Hence, the power extracted by the wind turbine from the wind is given by eq (\\ref{W8}).\n\n\\begin{equation}\n\\label{W8}\nP_0 = \\left(\\frac{1}{2}\\right) \\times \\text{(mass flow per sec)} \\times (V^2 - {V_0}^2)\n\\end{equation}\\\\\nwhere,\\\\\n$P_0$ = mechanical power extracted by the rotor (Watts)\\\\\n$ V $ = upstream wind velocity at the entrance of rotor\\\\\n$V_0$ = downstream wind velocity at the exit of rotor \\\\\n\nThe mass of the air passing through the rotor blades is given by the eq (\\ref{W9}).\n\n\\begin{equation}\n\\label{W9}\n\\text{Mass  of air through the rotor blades} (kg/sec) = \\rho \\times A \\times \\left(\\frac{V + V_0}{2}\\right)\n\\end{equation}\n\nCombining the eq (\\ref{W8},\\ref{W9}) we get a detailed equation for the mechanical power extracted by the wind turbine rotor from the wind in terms of the eq (ref{W99}).\n\n\\begin{equation}\n\\label{W99}\nP_{0}= \\frac{1}{2}\\left[\\rho A \\frac{\\left(V+V_{0} \\right)}{2} \\right]\\left(V^{2}-V_{0}^{2} \\right)\n\\end{equation}\n\nOn further rearranging the eq (\\ref{W99}) we get the eq (\\ref{W88}).\n\n\\begin{equation}\n\\label{W88}\nP_{0} =\\frac{1}{2} \\rho A V^(3) \\frac{\\left(1 + \\frac{V_0}{V}\\right)\\times \\left[1 - \\left(\\frac{V_0}{V}\\right)^2\\right]}{2}\n\\end{equation}\\\\\n\nNow the power extracted by the wind turbine rotor blades is expressed as a fraction of upstream wind power in eq (\\ref{W10}).\n\n\\begin{equation}\n\\label{W10}\nP_0 = \\left(\\frac{1}{2}\\right) \\times \\rho \\times A \\times V^3 \\times C_p\n\\end{equation}\nwhere,\\\\\n$C_P$ = Wind Turbine Power Co-efficient\\\\\n\nThe wind Turbine Power Co-efficient is an important variable which depends on the mechanical design of the rotor blades and is given by the eq (\\ref{W11}).\n\n\\begin{equation}\n\\label{W11}\nC_p = \\frac{\\left(1 + \\frac{V_0}{V}\\right)\\times \\left[1 - \\left(\\frac{V_0}{V}\\right)^2\\right]}{2}\n\\end{equation}\n\nMaximum power extracted from the wind:\n\n\\begin{equation}\n\\label{W12}\nP_{max} = \\left(\\frac{1}{2}\\right) \\times \\rho \\times A \\times V^3 \\times 0.59\n\\end{equation}\\\\\n\nTheoretical max. value of $C_p = 0.59$ is called the Betz Limit.\n\nIf $C_p = 0.5$, maximum output power of the wind turbine is given by the eq (\\ref{W13}).\n\n\\begin{equation}\n\\label{W13}\n\\text{$P_{max} (Watts/m^2)$}= \\left(\\frac{1}{4}\\right) \\times \\rho \\times V^3 \n\\end{equation}\\\\\n\n\n\\section{Effect of Rotor-Swept Area on Wind Power}\n\\\n\\\n\\\n\\\nThe rotor-swept area is the cross-sectional area covered by the wind turbine rotor blades. For a horizontal axis wind turbine the rotor-swept area demarcates a circle, and is given by the eq (\\ref{W14}).\n\t\n\\begin{equation}\n\\label{W14}\n\t\\text{Rotor swept area}(m^2) = A_H = \\left(\\frac{\\Pi}{4}\\right) \\times D^2\n\\end{equation}\n\nFrom eq (\\ref{W10}) we observe that the amount of power extracted by the wind turbine rotor from the wind is directly proportional to the rotor-swept area. Hence, to increase power extraction capacity of a wind turbine the lengths of its rotor blades can be increased.\n\n\\section{Effect of Air Density on Wind Power}\n\\\n\\\n\\\n\\\nFrom eq (\\ref{W10}) we can see that the power extracted by a wind turbine is directly proportional to the air density. Hence, denser the air more will be the power extracted from the wind.\\\\\n\nHowever, the density of air depends on the on the pressure and temperature of the location as given by the ideal gas law in eq (\\ref{W16}).\n\n\\begin{equation}\n\\label{W16}\n\\rho = \\frac{P}{R \\times T}\n\\end{equation}\\\\\nwhere,\\\\\n$ P $ = Air pressure $ (atm) $\\\\\n$ T $ = Temperature $ (K) $\\\\\n$ R $ = Gas constant $ 8.205745 \\time 10^{-5} m^{3} atm K^{-1} mol^(-1) $\\\\\n\nThe air density at sea-level at $1$ atm  $15 \\deg$Celsius is $1.2250 kg/m^3$. Using this as a reference $\\rho$ is corrected, for the site specific temperature and pressure.Hence, the density of air now is directly proportional to pressure and inversely proportional to temperature of the location.\\\\\n\nTemperature and pressure both vary with \"altitude\". Their combined effect is given by the eq (\\ref{W17}), which is valid upto $6000$m or $20000$ft of site elevation above sea-level. This equation is however approximate, and the detailed effect of both temperature and pressure on the air density is given in the subsequent sections of the text.\n\n\\begin{equation}\n\\label{W17}\n\\rho = \\rho_0 \\times e^{-{\\left(\\frac{0.297\\times H_m}{3048}\\right)}}\n\\end{equation}\\\\\nwhere,\\\\\n$ \\rho $ = Air Density at new height $(kg/m^3)$ \\\\ \n$ \\rho_{o} $ = Air Density at sea level $(kg/m^3)$ \\\\\n$ H_{m} $ = Altitude of the location $(m)$\\\\\n\n\n\\subsection{Correction for Pressure:}\n\\\n\\\n\\\n\\\n\nTo correct the air density at a given specific location, we first compute the air pressure at the location using its altitude in the eq (\\ref{W19}). this gives us the pressure at the specific location.\n\n\\begin{equation}\n\\label{W19}\nP = P_{o} \\times e^{(-1.185 \\times 10^{-4} \\times H)}\n\\end{equation}\\\\\nwhere,\\\\\n$ P $ = Pressure at new height $(atm)$ \\\\ \n$ P_{o} $ = Pressure at sea level $(atm)$ \\\\\n$ H_{m} $ = Altitude of the location $(m)$\\\\\n\n\n\\subsection{Correction for Temperature}\n\\\n\\\n\\\n\\\nAfter correcting the air pressure for altitude of the location, we use this pressure in the ideal gas law equation along with the temperature of the specific location as given in eq (\\ref{W20}).\n\n\\begin{equation}\n\\label{W20}\n\\rho = \\frac{P \\times M.W \\times 10^{-3}}{R \\times T}\\\\\n\\end{equation}\\\\\nwhere,\\\\\n$ M.W $ = Molecular weight of air $  $\\\\\n\nThe eq (\\ref{W20}) computes the air density at the specific location accurately as it takes into account both the correction in pressure and temperature.\n\n\n\\section{Effect of Hub-Height on Wind Power:}\n\\\n\\\n\\\n\\\n\nThe wind shear at a ground level surface causes the wind speed to increase with height in accordance with eq (\\ref{W36}).\n\n\\begin{equation}\n\\label{W36}\nV_2 = V_1 \\times \\left(\\frac{h_2}{h_1}\\right)^\\alpha\n\\end{equation}\\\\\nwhere,\\\\\n$V_1 = \\text{wind speed measured at the reference height} \\,h_1$\\\\\n$V_2 = \\text{wind speed estimated at height} \\,h_2$\\\\\n$\\alpha = \\text{ground surface friction coefficient}$\\\\\n\nThe Table (\\ref{c5Tab1}) gives different values of $\\alpha$ for different ground surface roughness class.\n\n\\begin{table}[H]\n  \\centering\n  \\caption{Ground Surface Friction Co-Efficient Claassification}\n    \\begin{tabular}{|l|c|}\n    \\hline\n    \\textbf{Terrain Characteristics} & \\multicolumn{1}{l|}{\\textbf{Friction Coefficient (α)}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Smooth hard ground, calm water } & 0.1 \\bigstrut\\\\\n    \\hline\n    \\textbf{Tall grass on level ground } & 0.15 \\bigstrut\\\\\n    \\hline\n    \\textbf{High crops, hedges and shrubs } & 0.2 \\bigstrut\\\\\n    \\hline\n    \\textbf{Wooded countryside, many trees } & 0.25 \\bigstrut\\\\\n    \\hline\n    \\textbf{Small town with trees and shrubs } & 0.3 \\bigstrut\\\\\n    \\hline\n    \\textbf{Large city with tall buildings } & 0.4 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{c5Tab1}%\n\\end{table}%\n\nFrom the eq (\\ref{W36}) we can observe that the velocity of wind increases with height. Moreover, as the power extracted from the wind by the wind turbine is directly proportional to the cube of the wind velocity, increasing the hub height has a huge improvement in the power extraction capacity of a wind turbine.\\\\\n\t     \n\\section{Wake Effect Models:}\n\\\n\\\n\\\n\\\nThe wake effect is one of the biggest factors for reduction in power capture capacity of wind turbines in a wind farm. The wake effect has two main impacts on the wind farm; firstly there is reduction of wind speed as we move towards the down stream turbines, sometimes causing the downstream turbines to completely stop this causes a considerable amount of loss in power capturing capacity of the wind farm and secondly the the downstream wind is more turbulent causing structural fatigue and eventually lower lifespan of wind turbines. Modeling of Wake Effect helps in the computation of downstream wind velocity deficit (helps in calculating the reduced power capture) and the turbulence patterns so that the wind turbines in a wind farm are arranged spatially to optimize the the power capture. The Fig (\\ref{figc5h10}) shows a wake effect simulation in a wind farm.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{WakeEffect1}\n\\caption{Wake effect Simulation}\n\\label{figc5h10} %% to refer use, \\ref{}\n\\end{figure}\n\n\\subsection{Jensen's Model:}\n\\\n\\\n\\\n\\\n\nThe analytical wake model developed by Jensen is simple and requires less inputs as compared other complex wake models. It is used in mostly is optimizing position of the wind turbines within a wind farm. It is based on the global momentum conservation and on the assumption that the wake has a linearly expanding diameter.\\\\\n\nThe Fig (\\ref{figc5h11}) illustrates the principle of Jensen's wake model.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{WakeEffect2}\n\\caption{Jensen - Wake Model Principle [56]}\n\\label{figc5h11} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref(W44),\\ref(W45),\\ref(W47),\\ref(W48)) describe the Jensen wake model.\n\n\\begin{equation}\n\\label{W44}\n\tD_{wake} = D(1 + 2ks)\\\\\n\\end{equation}\\\\\n    \n\\begin{equation}\n\\label{W45}\n    u_{def} = U_{\\infty}\\left[\\frac{1-\\sqrt{1-C_T}}{(1 + 2ks)^2}\\right]\\\\\n\\end{equation}\\\\ \n    \n\\begin{equation}\n\\label{W46}\n     u = U_{\\infty}\\left[1 - \\frac{1-\\sqrt{1-C_T}}{(1 + 2ks)^2}\\right]\\\\\n\\end{equation}\\\\\n    \n\\begin{equation}\n\\label{W47}\n     s = x/D\\\\\n\\end{equation}\\\\\n    where,\\\\\n    $ D_{wake} $ = Wake Diameter $ (m) $ \\\\\n    $ D $ = Rotor Diameter $ (m) $ \\\\\n    $ k $ = Wake Decay Constant (onshore=0.075 and offshore=0.05) \\\\\n    $ s $ = Normalized downstream distance from turbine $ (m) $ \\\\\n    $ x $ = Axial Distance between Turbines $ (m) $ \\\\    \n    $ u_{def} $ = Velocity deficit in fully developed Wake $ (m/s) $ \\\\\n    $ U_{\\infty} $ = Wind Speed $ (m/s) $ \\\\\n    $ C_{T} $ = Induction Factor of Turbine \\\\\n    $ u $ = Wind Speed after Wake effect $ (m/s) $ \\\\\n    \n       \t \t     \n\\subsection{Frandsen's Model:}\n\\\n\\\n\\\n\\\nThe analytical wake model developed by Frandsen has been adopted in the Storpark Analytical Model (SAM). This model predicts the wind speed deficit in large offshore wind farms using a rectangular site area and straight rows of wind turbines with equidistant spacing between the wind turbines and rows. This model is more accurate than the Jensen model, but requires more input variables.\\\\\n\nThe eq (\\ref(W48),\\ref(W49),\\ref(W50),\\ref(W51)) describe the Frandsen wake model.\n\n\\begin{equation}\n\\label{W48}\n\tD_{wake} = D(\\beta ^{(k/2)} + \\alpha s)^{\\frac{1}{k}}\\\\\n\\end{equation}\\\\\n\t\n\\begin{equation}\n\\label{W49}\n\t\\beta = \\frac{1 + \\sqrt{1-C_T}}{2 \\sqrt{1-C_T}}\\\\\n\\end{equation}\\\\\n\t\n\\begin{equation}\n\\label{W50}\n\tu_{def} = \\frac{U_{\\infty}}{2} \\left(1 \\pm \\sqrt{1 - 2 \\frac{A}{A_{wake}} C_T}\\right)\\\\\n\\end{equation}\\\\\t\n    \n\\begin{equation}\n\\label{W51}\n     s = x/D\\\\\n\\end{equation}\\\\\n    where,\\\\\n    $ D_{wake} $ = Wake Diameter $ (m) $ \\\\\n    $ D $ = Rotor Diameter $ (m) $ \\\\\n    $ k $ = Wake Decay Constant $ k=2 \\text{, for Schlichting solution to the wake expansion; } k=3 \\text{, for square root shape chosen } $ \\\\\n    $ \\alpha $ = Initial Wake expansion \\\\\n    $ s $ = Normalized downstream distance from turbine $ (m) $ \\\\\n    $ x $ = Axial Distance between Turbines $ (m) $ \\\\    \n    $ u_{def} $ = Velocity deficit in fully developed Wake $ (m/s) $ \\\\\n    $ U_{\\infty} $ = Wind Speed $ (m/s) $ \\\\\n    $ C_{T} $ = Induction Factor of Turbine \\\\\n    $ A $ = Swept area of rotor $ (m^{2}) $ \\\\     \n    $ A_{wake} $ = Swept area of Wake $ (m^{2}) $ \\\\\n    \n\\newpage    \n    \n\\section{Concept of TSR:}\n\\\n\\\n\\\n\\\nTip Speed Ratio (TSR) is defined as the ratio of the angular speed of the wind turbine rotor blade to the wind velocity, it is given by the eq (\\ref{W38}).\n\n\\begin{equation}\n\\label{W38}\nTSR = \\frac{\\text{Linear speed of the blade's outermost tip}}{\\text{Free upstream wind velocity}}\n\\end{equation}\\\\\n\nThe TSR in terms of rotor radius and angular speed in rads/s is given by the eq (\\ref{W39}).\n\n\\begin{equation}\n\\label{W39}\nTSR = \\frac{\\omega \\times R}{V}\n\\end{equation}\\\\\nwhere,\\\\\n$ R $ = rotor radius $ (m) $\\\\\n$\\omega$ = angular speed of the rotor $(rads/s)$\\\\\n\nThe TSR is an important quantity in determining the amount of power extracted from wind by the wind turbine, as the Wind Turbine Power Co-efficient $(C_{P})$ is a function of the TSR. The relationship between TSR and $C_{P}$ is dealt with in detail in the next section.\\\\  \n\n\n\\subsection{Power Coefficient Analysis:}\n\\\n\\\n\\\n\\\nThe power extracted from the wind by the wind turbine is directly proportional to the the Wind Turbine Power Co-efficient $(C_{P})$ as seen in the eq (\\ref{W10}). $C_{P}$ is experimentally measured by the Wind Turbine Manufactures and its graph is provided in the data-sheet.\\\\\n \n$C_{P}$ describes the aerodynamic behaviour of the wind turbine rotor blades. It is a highly non-linear function of TSR and the blade pitch angle $(\\theta)$. For a given $\\theta$ the $C_{P}$ is plotted for a range of TSR values. The relationship between $C_{P}$, TSR and $\\theta$ differs from turbine to turbine; however, its knowledge helps in designing maximum power tracking controllers which try to maintain $C_{P}$ at its maximum value under the given wind speed condition by adjusting the blade pitch angle (Pitch Control) and/or the gear ratio (Speed Control).\\\\\n\nThe eq (\\ref{W41},\\ref{W42}) gives a detailed analytical model for the relationship between $C_{P}$, TSR and $\\theta$, it is developed by (Anderson & Bose, 1983).\n\n\\begin{equation}\n\\label{W41}\nC_p(\\lambda , \\theta) = C_1\\times(C_2  \\frac{1}{\\beta} - C_3 \\beta \\theta - C_4 \\theta ^x - C_5)e^{-C_6 \\frac{1}{\\beta}}\\\\\n\\end{equation}\\\\\n\n\\begin{equation}\n\\label{W42}\n\\frac{1}{\\beta} = \\frac{1}{\\lambda + 0.08\\theta} - \\frac{0.035}{1 + \\theta ^3}\\\\\n\\end{equation}\\\\\nwhere,\\\\\n$ C_{P} $ = Wind Turbine Power Coefficient \\\\\n$ C_{1},C_{2},C_{3},C_{4},C_{5},C_{6} \\text{ and }x_ $ = Turbine rotor design dependent constants \\\\\n$ \\lambda $ = Tip speed ratio \\\\\n\nThe eq (\\ref{W43}) describes another simpler analytical model for C_{P}, which does not take into account physical design differences between the wind turbine rotor blades; it is also developed by (Anderson & Bose, 1983).\n\n\\begin{equation}\n\\label{W43}\n\tC_p = \\frac{1}{2}(\\lambda - 0.022\\theta ^2 - 5.6)e^{-0.17\\lambda}\\\\\n\\end{equation}\\\\\t\nwhere,\\\\ \t\n$\\lambda = \\frac{V_w \\text{ (mph) }}{\\omega _{b}  (rads_-1) }$\\\\\nwhere,\\\\\n$ \\lambda $ = Tip Speed Ratio \\\\\n$ V_w $ = Wind speed $ (mph) $  \\\\\n$ \\omega_b $ = Angular speed of turbine rotor $ (rads/s) $ \\\\      \n    \n\\section{Weibull Wind Speed Distribution:}\n\\\n\\\n\\\n\\\nThe variation in wind speed distribution is best described by the Weibull probability distribution function 'h' with two parameters:\n\n\\begin{enumerate}\n\\item \\blindtext The shape parameter 'k'\n\\item \\blindtext The scale parameter 'c'\n\\end{enumerate}\n\n\nThe probability of wind speed being $\\upsilon$ during any time interval is given by eq (\\ref{W21})\n\n\\begin{equation}\n\\label{W21}\nh(\\upsilon) = \\left(\\frac{k}{c}\\right) \\times \\left(\\frac{\\upsilon}{c}\\right)^{k-1} \\times \\exp{\\left(\\frac{\\upsilon}{c}\\right)}^k \\text{, for $0< \\upsilon < \\infty$}\n\\end{equation}\\\\\n\nThe eq (\\ref{W21}) tells us the probability of occurrence of a particular wind speed. As it is a probability distribution, hence its summation from infinity to infinity is 1. Therefore, we can multiply it with time parameter to get probability of wind speed in terms of hours in a year (if multiplied by 8760) or any other time parameter which fits best for the wind speed being described by the probability distribution.\\\\\n\nWeibull probability distribution changes its shape according to the shape parameter $k$ as follows:\n\n\\begin{enumerate}\n\\item \\blindtext \t$k=1$ makes it the exponential distribution, \\,$h = \\lambda \\times e^{-(\\lambda\\upsilon)},\\, where \\, \\lambda = \\frac{1}\t\t\t{c}$\n\\item \\blindtext $k=2$ makes it the Rayleigh distribution, \\,$h = 2 \\times \\lambda^2 \\times \\upsilon \\times e^{-(\\lambda\\upsilon)^2}$\n\\item \\blindtext $k>3$ makes it approach a normal bell-shaped distribution\n\\end{enumerate}\n\nThe eq (\\ref{W25}) gives the relationship between the shape parameter (k), scale parameter (c) and the mean wind speed for a give period of time for which the wind data was gathered. Knowing $V_{mean}$ and adjusting the shape parameter (k) so as to come close to the actual wind speed distribution the scale parameter (c) can be computed.\n\n\\begin{equation}\n\\label{W25}\nV_{mean} = c \\times \\sqrt{\\left(1 + \\frac{1}{k}\\right)}\n\\end{equation}\\\\\n\n\nRoot mean cube wind speed is defined in similar manner as $V_(rms)$ in AC electrical circuits, it is given by eq (\\ref{W28}).\n\n\\begin{equation}\n\\label{W28}\n\tV_(rmc) = 3 \\times \\sqrt{\\frac{1}{8760}\\int\\limits_0^\\infty h\\upsilon^3 \\, d\\upsilon}\n\\end{equation}\\\\\n\nUsing $V_{rmc}$ the 'annual average power generation' can be computed as given in eq (\\ref{W29}).\n\n\\begin{equation}\n\\label{W29}\n\tP_{rmc} = \\frac{1}{4}\\times \\rho \\times {V_{rmc}}^3\n\\end{equation}\\\\\n\nFurthermore, using eq (\\ref{W30}) we can compute the average annual energy production of the specific site.\n\t\n\\begin{equation}\n\\label{W30}\n\t\\text{Average annual energy production of the site} = P_{rmc} \\times \\text{total number of hours per year}\n\\end{equation}\\\\\n\nSo, using the concepts of Weibull Distribution and Root Mean Cube Wind Speed, we can estimate the potential of a site for setting up a wind farm with minimum amount of data (just annual mean wind speed can suffice for performing the analysis).\\\\\n\n\\newpage \n\t\t\n\\section{Power Flow through Wind Turbine Grid Connected System}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{Windloss}) illustrates the power flow through a Wind Turbine grid connected system and the various losses incurred in the this system.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{WindLoss1}\n\\caption{Flow Diagram - Power Flow and Power Losses in a Wind Turbine Grid Connected System}\n\\label{WindLoss} %% to refer use, \\ref{}\n\\end{figure}\n\n\\subsection{Wind Speed Correction}\n\\\n\\\n\\\n\\\nThe wind speed measured in a Wind Turbine Power Plant by a weather station at ground level. In order to know the exact wind speed at the height of the wind turbine rotors, correction has to be implemented as directed by the eq (\\ref{}).\n\nMoreover, wake effect has to be taken into account to incorporate the downstream wind velocity deficit as explained in the section (5.7), either using Jensen or Frandsen wake effect models.\n\n\\subsection{Power Curve Correction}\n\\\n\\\n\\\n\\ \nAs discussed in the section (5.5), the air density has a direct proportion to the power extracted by the wind turbine from the wind. The Power vs Wind Speed curves provided by the manufacturers are experimentally measured at sea level at a controlled temperature of $15^{\\circ}C$. However the the altitude and the temperature at the specific wind farm location is different, hence power curve correction based on the air density correction has to performed for more accurate power estimation from the wind turbines.\n\n\\subsection{Ohmic and Transformer Losses}\n\\\n\\\n\\\n\\\t\nAC cabling is done to connect wind turbines to the transformer. All these cables add to the resistance of the Wind Turbine 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\nTransformers are another indispensible part of the grid connected Wind Turbine systems. They step-up the voltage of the Wind Turbine 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{figc5h4} ) depicts an simplified flowchart of the algorithm which is developed for the creation of the Wind Energy Estimation Application. \t      \t \t\n  \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{WindScheme}\n\\caption{Wind Turbine Energy Estimation Schematic}\n\\label{figc5h4} %% to refer use, \\ref{}\n\\end{figure}\n\nBased on the theory discussed in previous sections of this chapter and the algorithm developed as illustrated in Fig (\\ref{WindLoss1},\\ref{figc5h4}); a GUI based application for energy estimation of grid connected wind turbine 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\\newpage\n\n\\section{Results}\n\\\n\\\n\\\n\\\nThe Wind Energy Estimation App has been tested with a hypothetical wind turbine power plant, and the Weibull Distribution sub-module has been tested with random site information. The results obtained are doumented in the following sections.\n\n\\subsection{Wind Turbine Power Plant Site Potential Estimation using Weibull Distribution App}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{WinResImg1}) shows the site potential estimation performed by the Weibull Distribution sub-module for monthly data.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{Weibull_Monthly}\n\\caption{Weibull Distribution-Monthly Simulation }\n\\label{WinResImg1} %% to refer use, \\ref{}\n\\end{figure}\n\nThe Fig (\\ref{WinResImg2}) shows the site potential estimation performed by the Weibull Distribution sub-module for yearly data.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{Weibull_Yearly}\n\\caption{ Weibull Distribution-Yearly Simulation }\n\\label{WinResImg2} %% to refer use, \\ref{}\n\\end{figure}\n\n\\subsection{Cp Curve Generator App}\n\\\n\\\n\\\n\\\nThe Table (\\ref{CpCurveTab1}) gives the rotor information used to generate C_{P} curves using equation (\\ref{W41}).\n\n\\begin{table}[htbp]\n  \\centering\n  \\caption{Cp Curve Generator App - Equation 1 Simulation Parameters}\n    \\begin{tabular}{|l|l|}\n    \\hline\n    \\multicolumn{2}{|c|}{\\textbf{Cp Curve Equation 1}} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{1}{|c|}{\\textbf{Parameters }} & \\multicolumn{1}{c|}{\\textbf{Value}} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{1}{|c|}{Number of Rotor Types} & 3 \\bigstrut\\\\\n    \\hline\n    c1 & 0.5,0.7,0.3 \\bigstrut\\\\\n    \\hline\n    c2 & 116,150,85 \\bigstrut\\\\\n    \\hline\n    c3 & 0.4,0.6,0.2 \\bigstrut\\\\\n    \\hline\n    c4 & 0,0,0 \\bigstrut\\\\\n    \\hline\n    c5 & 5,10,3 \\bigstrut\\\\\n    \\hline\n    c6 & 21,31,11 \\bigstrut\\\\\n    \\hline\n    x  & 0,0,0 \\bigstrut\\\\\n    \\hline\n    Theta & 1,2,3,4 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{CpCurveTab1}%\n\\end{table}%\n\nThe Fig (\\ref{WinResImg3},\\ref{WinResImg4},\\ref{WinResImg5}) shows the C_{P} curve graphs obtained from the Cp Curve Generator App for different values of the blade pitch angles.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{CpCurve_Eq1_1}\n\\caption{CpCurve Generator App-Equation 1 Rotor 1 Simulation}\n\\label{WinResImg3} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{CpCurve_Eq1_2}\n\\caption{CpCurve Generator App-Equation 1 Rotor 2 Simulation}\n\\label{WinResImg4} %% to refer use, \\ref{}\n\\end{figure}\n\\begin{figure}[H]\n\n\\centering\n\\includegraphics[scale=0.5]{CpCurve_Eq1_3}\n\\caption{CpCurve Generator App-Equation 1 Rotor 3 Simulation}\n\\label{WinResImg5} %% to refer use, \\ref{}\n\\end{figure}\n\nThe Table (\\ref{CpCurveTab2}) gives the rotor information used to generate C_{P} curves using equation (\\ref{W43}).\n\n\\begin{table}[htbp]\n  \\centering\n  \\caption{Cp Curve Generator App - Equation 2 Simulation Parameters}\n    \\begin{tabular}{|l|l|}\n    \\hline\n    \\multicolumn{2}{|c|}{\\textbf{Cp Curve Equation 2}} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{1}{|c|}{\\textbf{Parameters }} & \\multicolumn{1}{c|}{\\textbf{Value}} \\bigstrut\\\\\n    \\hline\n    Number of Rotor Types &  \\bigstrut\\\\\n    \\hline\n    c1 & 0.5 \\bigstrut\\\\\n    \\hline\n    c2 & 116 \\bigstrut\\\\\n    \\hline\n    c3 & 0.4 \\bigstrut\\\\\n    \\hline\n    c4 & 0 \\bigstrut\\\\\n    \\hline\n    c5 & 5 \\bigstrut\\\\\n    \\hline\n    c6 & 21 \\bigstrut\\\\\n    \\hline\n    x  & 0 \\bigstrut\\\\\n    \\hline\n    Theta & 0,5,10,15,20 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{CpCurveTab2}%\n\\end{table}%\n\nThe Fig (\\ref{WinResImg6}) shows the C_{P} curve graphs obtained from the Cp Curve Generator App for different values of the blade pitch angles.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{CpCurve_Eq2_1}\n\\caption{CpCurve Generator App-Equation 2 Simulation }\n\\label{WinResImg6} %% to refer use, \\ref{}\n\\end{figure}\n\n\n\\subsection{Hypothetical Wind Turbine Plant Information}\n\\\n\\\n\\\n\\\nThe Table (\\ref{DataTab1}) gives the information of the hypothetical wind power plant, which was fed into the Data Acquisition App and the Wind Energy Estimation App for testing purposes due lack of real WTPP data.\n\n\\begin{table}[H]\n  \\centering\n  \\captionHypothetical Wind Turbine Power Plant Information Table}\n    \\begin{tabular}{|l|l|l|l|l|}\n    \\hline\n    \\multicolumn{5}{|c|}{\\textbf{HYPOTHETICAL WIND TURBINE POWER PLANT}} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{5}{|c|}{\\textbf{SITE INFORMATION}} \\bigstrut\\\\\n    \\hline\n    \\textbf{LATITUDE} & \\multicolumn{4}{l|}{23.275} \\bigstrut\\\\\n    \\hline\n    \\textbf{LONGITUDE} & \\multicolumn{4}{l|}{72.682} \\bigstrut\\\\\n    \\hline\n    \\textbf{ALTITUDE (m)} & \\multicolumn{4}{l|}{100} \\bigstrut\\\\\n    \\hline\n    \\textbf{PLANT CAPACITY (MW)} & \\multicolumn{4}{l|}{138} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{5}{|c|}{\\textbf{WIND TURBINE PLANT INFORMATION}} \\bigstrut\\\\\n    \\hline\n    \\textbf{PARAMETERS} & \\multicolumn{4}{c|}{\\textbf{WIND GENERATOR TYPES}} \\bigstrut\\\\\n    \\hline\n       & \\textbf{Type1} & \\textbf{Type2} & \\textbf{Type3} & \\textbf{Type4} \\bigstrut\\\\\n    \\hline\n    \\textbf{No. of Sub-Models} & 1  & 2  & 3  & 4 \\bigstrut\\\\\n    \\hline\n    \\textbf{No. of Turbines} & 5  & 5,10 & 5,10,15 & 5,10,15,20 \\bigstrut\\\\\n    \\hline\n    \\textbf{Cut-In Wind Speed} & 4  & 4,4 & 4,4,4 & 4,4,4,3.5 \\bigstrut\\\\\n    \\hline\n    \\textbf{Cut-Out Wind Speed} & 24 & 24,19 & 24,19,25 & 24,19,25,23 \\bigstrut\\\\\n    \\hline\n    \\textbf{Rotor Radius} & 38.5 & 38.5,19.5 & 38.5,19.5,35.5 & 38.5,19.5,35.5,38.5 \\bigstrut\\\\\n    \\hline\n    \\textbf{Hub-Height} & 80 & 80,55 & 80,55,73 & 80,50,73,80 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{DataTab1}%\n\\end{table}%\n\n\n\n\\subsection{Wind Turbine Power Curve GUI}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{WinResImg7},\\ref{WinResImg8},\\ref{WinResImg9},\\ref{WinResImg10}) illustrates the Power (kW) vs Wind Speed (m/s) graphs of the four different wind turbines used in the simulation as observed in the Wind Power Curves sub-module.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{NegMicon}\n\\caption{Power vs Wind Speed Curve-Neg Micon 1.5MW}\n\\label{WinResImg7} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{Vestas}\n\\caption{Power vs Wind Speed Curve-Vestas 0.6MW}\n\\label{WinResImg8} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{Enercon}\n\\caption{Power vs Wind Speed Curve-Enercon 2MW }\n\\label{WinResImg9} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{GE}\n\\caption{Power vs Wind Speed Curve-GE 1.5MW}\n\\label{WinResImg10} %% to refer use, \\ref{}\n\\end{figure}\n\n\n\\subsection{Wind Energy Estimation App Output}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{WinResImg11}) shows the monthly energy output to the grid obtained from the four different types of wind turbines present in the type four category of the hypothetical wind power plant as computed in the Wind Energy Estimation App. The wind speed data was randomly generated and the temperature data was taken from Meteonorm, both at the temporal resolution of 60 minutes.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{WindGraph1}\n\\caption{Hypothetical Wind Plant Month Wise Energy Estimation For Different Wind Generator Types}\n\\label{WinResImg11} %% to refer use, \\ref{}\n\\end{figure}\n\nWe can clearly see that the energy output of the Enercon and GE  compared to Neg Micon and Vestas is higher, as the number of these turbines is higher.\n\n\n\n\n", "meta": {"hexsha": "f1542d496725e9801834d9e1b9191bd7a351d450", "size": 30851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8_ProjectReport/2_ProjectProposal/Latex Support Files/Chapters/Ch5.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/Ch5.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/Ch5.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": 38.3718905473, "max_line_length": 870, "alphanum_fraction": 0.7047421477, "num_tokens": 9480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.6990416025107693}}
{"text": "%---------------------------Edge Ratio----------------------------------\n\\section{Edge Ratio}\n\nThe edge ratio of a tetrahedron is: \n\\[\n\\frac{L_{\\max}}{L_{\\min}}.\n\\]\n\n\\tetmetrictable{edge 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{--}%                   Citation\n{v\\_tet\\_edge\\_ratio}%  Verdict function name\n\n", "meta": {"hexsha": "c809884dc7404e91f33590d3650517baf0f0581a", "size": 462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetEdgeRatio.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/TetEdgeRatio.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/TetEdgeRatio.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": 25.6666666667, "max_line_length": 72, "alphanum_fraction": 0.4567099567, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6990416004085753}}
{"text": "\\lab{Simplex Method}{Simplex Method}\n\\objective{Implement the Simplex Algorithm to solve linear constrained optimization problems.}\n\\label{lab:Simplex}\n\nThe Simplex Algorithm numbers among the most important algorithms invented within the last 100 years.\nIt provides a straightforward method for finding optimal solutions to linear constrained optimization problems.\nThe algorithm obtains the solution by traversing the edges of the feasible region defined by the constraints.\nThe theory of convex optimization guarantees that the optimal point will be found among the vertices of the feasible\nregion, and so a carefully implemented Simplex Algorithm will discover the exact solution in a finite number of steps.\n\n\\section*{Standard Form}\nThe Simplex Algorithm accepts a linear constrained optimization problem, also known as a \\emph{linear program},\nin the form given below:\n\n\\begin{align*}\n\\text{maximize}\\qquad &c^Tx \\\\\n\\text{subject to}\\qquad A&x \\leq b \\\\\n &x \\geq 0\n\\end{align*}\nNote that any linear program can be converted to standard form, so there is no loss of\ngenerality in restricting our attention to this particular formulation.\n\nSuch an optimization problem defines a region in space called the \\emph{feasible region}, the set of points\nsatisfying the constraints. Because the constraints are all linear, the feasible region forms a geometric object\ncalled a \\emph{polytope}, having flat faces and edges (see Figure \\ref{fig:polytope}).\nThe Simplex Algorithm jumps among the vertices of the feasible region searching for an optimal point.\nIt does this by moving along the edges of the feasible region in such a way that the objective function\nis always increased after each move.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{feasiblePolytope.pdf}\n\\caption{The feasible region for a linear program. The optimal point\nis one of the vertices of the polytope.}\n\\label{fig:polytope}\n\\end{figure}\n\nImplementing the Simplex Algorithm is straightforward, provided one carefully follows the procedure.\nWe will break the algorithm into several small steps, and write a function to perform each one.\nTo become familiar with the execution of the Simplex algorithm, it is helpful to work several examples by hand.\n\n\\section*{The Simplex Solver}\nOur program will be more lengthy than many other lab exercises and will consist of a collection of functions working\ntogether to produce a final result.\nIt is important to clearly define the task of each function and how all the functions will work together.\nIf this program is written haphazardly, it will be much longer and more difficult to read than it needs to be.\nWe will walk you through the steps of implementing the Simplex Algorithm as a Python class.\n%Since the Simplex Algorithm assumes that all the variables are non-negative, we do not need any special logic for it.\n%what is this previous statement saying? What 'special logic' would you need if the variables were negative?\n\nFor demonstration purposes, we will use the following linear program.\n\\begin{align*}\n\\text{maximize}\\qquad & 3x_0 + 2x_1 \\\\\n\\text{subject to}\\qquad\n& x_0 - x_1 \\leq 2 \\\\\n& 3x_0 + x_1 \\leq 5 \\\\\n& 4x_0 + 3x_1 \\leq 7 \\\\\n& x_0, x_1 \\geq 0.\n\\end{align*}\n\n\\subsection*{Accepting a Linear Program}\nOur first task is to determine if we can even use the Simplex algorithm.\nAssuming that the problem is presented to us in standard form, we need\nto check that the feasible region is nonempty.\n\n% Problem 1: Check Feasibility\n\\begin{problem}\nWrite a class that accepts the arrays \\li{c}, \\li{A}, and \\li{b} of a linear optimization problem in standard form.\nIn the constructor, check that the system is feasible at the origin\\footnote{For simplicity, we only check feasibility at the origin. A more robust solver sets up the auxiliary problem and solves it to find a starting point if the origin is infeasible.}.\nThat is, check that $Ax \\leq b$ componentwise when $x = 0$. % TODO: bell <=\nRaise a \\li{ValueError} if the problem is not feasible at the origin.\n\\label{prob:initsolver}\n\\end{problem}\n\n\\subsection*{Adding Slack Variables}\nOur next step is to convert the inequality constraints $Ax \\leq b$ into equality constraints\nby introducing one slack variable for each constraint.\nIf the constraint matrix $A$ is an $m \\times n$ matrix, then there are $m$ slack variables,\none for each row of $A$.\nGrouping all of the slack variables into a vector of length $m$, denoted $z$, our\nconstraints now take the form $Ax + z = b$.\nIn our example, this gives \n\\[\n\\z = \\begin{bmatrix}\n x_2 \\\\\n x_3 \\\\\n x_4\n\\end{bmatrix},\n\\]\n\nWhen adding slack variables, it is useful to represent all of your variables, both the original primal variables and\nthe additional slack variables, in a convenient manner.\nOne effective way is to refer to a variable by its subscript.\nFor example, we can use the integers $0$ through $n-1$ to refer to the original (non-slack) variables $x_0$ through\n$x_{n-1}$, and we can use the integers $n$ through $n+m-1$ to track the slack variables (where the slack variable\ncorresponding to the $i$-th row of the constraint matrix is represented by the index $n+i-1$).\n\nWe also need some way to track which variables are basic (non-zero) and which variables are nonbasic (those that have value $0$).\nA useful representation for the variables is a Python list (or NumPy array), where the elements of the list are integers.\nSince we know how many basic variables we have ($m$, to be precise), we can partition the list so that all the basic\nvariables are kept in the first $m$ locations, and all the non-basic variables are stored at the end of the list.\nThe ordering of this list is important. In particular, if $i \\leq m$, the $i$-th element of the list represents\nthe basic variable corresponding to the $i$-th row of $A$. Henceforth we will refer to this list as the \\emph{index list}.\n\nInitially, the basic variables are simply the slack variables, and their values correspond to the values of the matrix $b$.\nIn our example, we have 2 primal variables $x_0$ and $x_1$, and we must add 3 slack variables.\nThus, we instantiate the following index list:\n\\begin{lstlisting}\n>>> L = [2, 3, 4, 0, 1]\n\\end{lstlisting}\nNotice how the first $3$ entries of the index list are $2, 3, 4$, the indices representing the slack variables.\nThis reflects the fact that the basic variables at this point are exactly the slack variables.\n\nAs the Simplex Algorithm progresses, however, the basic variables change, and it will be necessary to swap\nelements in our index list. Suppose the variable represented by the index $4$ becomes nonbasic, while\nthe variable represented by index $0$ becomes basic. We must swap these two entries in the index list.\nThis can be done in a single, efficient line of Python code:\n\\begin{lstlisting}\n>>> L[2], L[3] = L[3], L[2]\n>>> L\n[2, 3, 0, 4, 1]\n\\end{lstlisting}\nNow our index list tells us that the current basic variables have indices $2, 3, 0$.\n\n% Problem 2: Slack variables.\n\\begin{problem}\nDesign and implement a way to store and track all of the basic and non-basic variables.\n\nHint: Using integers that represent the index of each variable is useful for Problem \\ref{prob:blands}.\n\\label{prob:slackvars}\n\\end{problem}\n\n\\subsection*{Creating a Tableau}\nAfter we have determined that our program is feasible, we need to create the \\emph{tableau} (sometimes called the \\emph{dictionary}, a construct that tracks the state of the algorithm.\nYou may structure the tableau to suit your specific implementation.\nRemember that your tableau will need to include in some way the slack variables that you created in Problem \\ref{prob:slackvars}.\n\nThere are many different ways to build your tableau.\nOne way is to mimic the tableau that is often used when performing the Simplex Algorithm by hand.\nDefine\n\\[\n\\bar{A} = \\begin{bmatrix}\n  A & I_m\n\\end{bmatrix},\n\\]\nwhere $I_m$ is the $m \\times m$ identity matrix,\nand define\n\\[\n\\bar{c} = \\begin{bmatrix}\n  c\\\\\n  0\\\\\n  \\vdots\\\\\n  0\n\\end{bmatrix}.\n\\]\nThat is, $\\bar{c} \\in \\mathbb{R}^{n+m}$ such that the first $n$ entries are $c$ and the final $m$ entries are zeros.\nThen the initial tableau has the form\n\\begin{equation}\nT = \\begin{bmatrix}\n    0 & -\\bar{c}^T & 1  \\\\\n    b & \\bar{A} & 0\n    \\end{bmatrix}.\n\\label{eqn:hand_tab}\n\\end{equation}\n\nThe columns of the tableau correspond to each of the variables (both primal and slack), and the rows of the tableau\ncorrespond to the basic variables. Using the convention introduced above\nof representing the variables by indices in the index list, we have the following correspondence:\n\\[\n\\text{column } i \\Leftrightarrow \\text{index } i-2, \\qquad i = 2, 3, \\ldots, n+m+1,\n\\]\nand\n\\[\n\\text{row } j \\Leftrightarrow L_{j-1}, \\qquad j = 2, 3, \\ldots, m+1,\n\\]\nwhere $L_{j-1}$ refers to the $(j-1)$-th entry of the index list.\n\nFor our example problem, the initial index list is\n\\[\nL = (2, 3, 4, 0, 1),\n\\]\nand the initial tableau is\n\\begin{equation*}\nT = \\begin{bmatrix}\n    0 & -3 & -2 & 0 & 0 & 0 & 1\\\\\n    2 & 1 & -1 & 1 & 0 & 0 & 0\\\\\n    5 & 3 & 1 & 0 & 1 & 0 & 0\\\\\n    7 & 4 & 3 & 0 & 0 & 1 & 0\n    \\end{bmatrix}.\n\\end{equation*}\nThe third column corresponds to index $1$, and the fourth row corresponds to index $4$, since this is the\nthird entry of the index list.\n\nThe advantage of using this kind of tableau is that it is easy to check the progress of your algorithm by hand.\nThe disadvantage is that pivot operations require careful bookkeeping to track the variables and constraints.\n\n% I (Jared) propose that we don't introduce the below tableau in the lab. It is less intuitive, and I think could lead to more confusion.\n\\begin{comment}\nWe can also use a tableau of the following format:\n\\begin{equation}\nT = \\begin{bmatrix}\n    0 & c^T  & 0 \\\\\n    0 & I_n & 0\\\\\n    b & -A  & 0\n\\end{bmatrix}.\n\\label{eqn:matrix_tab}\n\\end{equation}\nHere, $T$ is a square matrix of size $(n+m+1) \\times (n+m+1)$.\nThe advantage of this form of the tableau is that all the pivot bookkeeping is built into the matrix.\nFor our example problem, the initial tableau of this form is\n\\begin{equation}\nT = \\begin{bmatrix}\n        0 & 3 & 2 & 0 & 0 & 0 \\\\\n        0 & 1 & 0 & 0 & 0 & 0 \\\\\n        0 & 0 & 1 & 0 & 0 & 0 \\\\\n        2 &-1 & 1 & 0 & 0 & 0 \\\\\n        5 &-3 &-1 & 0 & 0 & 0 \\\\\n        7 &-4 &-3 & 0 & 0 & 0\n\\end{bmatrix}.\n\\label{eqn:matrix_inittab}\n\\end{equation}\n\\end{comment}\n\n\\begin{problem}\nAdd a method to your Simplex solver that will create the initial tableau that you will use.\nUsing a NumPy array to represent your tableau will simplify several parts of the Simplex algorithm.\n\\label{prob:maketableau}\n\\end{problem}\n\n\\subsection*{Pivoting}\nPivoting is the mechanism that really makes Simplex useful.\nPivoting refers to the act of swapping basic and nonbasic variables, and transforming the tableau appropriately.\nThis has the effect of moving from one vertex of the feasible polytope to another vertex in a way that increases\nthe value of the objective function.\nDepending on how you store your variables, you may need to modify a few different parts of your solver to reflect this swapping.\n\nWhen initiating a pivot, you need to determine which variables will be swapped.\nIn the tableau representation, you first find a specific element on which to pivot, and the row and column that contain the pivot\nelement correspond to the variables that need to be swapped.\nRow operations are then performed on the tableau so that the pivot column becomes an elementary vector.\n\nLet's break it down, starting with the pivot selection. We need to use some care when choosing the pivot element.\nTo find the pivot column, search from left to right along the top row of the tableau\n(ignoring the first column), and stop once you encounter the first negative value. The index corresponding\nto this column will be designated the \\emph{entering index}, since after the full pivot operation, it will enter\nthe basis and become a basic variable.\n\nUsing our initial tableau $T$ in the example, we stop at the second column:\n\\[ T = \\left[ \\:\n\\begin{array}{*{7}{c}}\n\\cline{2-2}\n0 & \\multicolumn{1}{|c}{-3} & \\multicolumn{1}{|c}{-2} & 0 & 0 & 0 & 1\\\\\n2 & \\multicolumn{1}{|c}{1} & \\multicolumn{1}{|c}{-1} & 1 & 0 & 0 & 0\\\\\n5 & \\multicolumn{1}{|c}{3} & \\multicolumn{1}{|c}{1} & 0 & 1 & 0 & 0\\\\\n7 & \\multicolumn{1}{|c}{4} & \\multicolumn{1}{|c}{3} & 0 & 0 & 1 & 0\\\\\n\\cline{2-2}\n\\end{array}\n\\right] \\]\nWe now know that our pivot element will be found in the second column. Our entering index is thus $0$.\n\nNext, we select the pivot element from among the positive entries in the pivot column (ignoring the entry in the first row).\n\\emph{If all entries in the pivot column are non-positive, the problem is unbounded and has no solution.} In this case, the algorithm\nshould terminate.\nOtherwise, assuming our pivot column is the $j$-th column of the tableau and that the positive entries of this column are\n$T_{i_1, j}, T_{i_2, j}, \\ldots, T_{i_k, j}$, we calculate the ratios\n\\[\n\\frac{T_{i_1,1}}{T_{i_1,j}}, \\frac{T_{i_2,1}}{T_{i_2,j}}, \\ldots, \\frac{T_{i_k,1}}{T_{i_k,j}},\n\\]\nand we choose our pivot element to be one that minimizes this ratio. If multiple entries minimize the ratio, then we utilize\n\\emph{Bland's Rule}, which instructs us to choose the entry in the row corresponding to the smallest index.\n(Obeying this rule is important, as it prevents the possibility of the algorithm cycling back on itself infinitely.)\nThe index corresponding to the pivot row is designated as the \\emph{leaving index}, since after the full pivot operation,\nit will leave the basis and become a nonbasic variable.\n\nIn our example, we see that all entries in the pivot column (ignoring the entry in the first row, of course) are positive,\nand hence they are all potential choices for the pivot element. We then calculate the ratios, and obtain\n\\[\n\\frac{2}{1} = 2,\\quad \\frac{5}{3} = 1.66...,\\quad \\frac{7}{4} = 1.75.\n\\]\nWe see that the entry in the third row minimizes these ratios. Hence, the element in the second column, third row is our designated\npivot element, and our leaving index is $L_2 = 3$:\n\n\\[ T = \\left[ \\:\n\\begin{array}{*{7}{c}}\n\n0 & -3 & -2 & 0 & 0 & 0 & 1\\\\\n2 & 1 & -1 & 1 & 0 & 0 & 0\\\\\\cline{2-2}\n5 & \\multicolumn{1}{|c}{3} & \\multicolumn{1}{|c}{1} & 0 & 1 & 0 & 0\\\\\\cline{2-2}\n7 & 4 & 3 & 0 & 0 & 1 & 0\\\\\n\\end{array}\n\\right] \\]\n\n\\begin{comment}\nIf we are using the tableau representation in equation \\ref{eqn:matrix_tab}, pivot operations are reduced to a simple matrix equation:\n\\[T = T + T_m \\otimes T_n,\\]\nwhere $T_m$ is the column corresponding to the variable entering the basis and $T_n$ is a normalized vector corresponding to the variable leaving the basis.  The result of the equation is the new tableau.\n\nFor example, for the initial tableau, \\ref{eqn:matrix_inittab}, we will demonstrate the first pivot operation.\nWe can do the entire pivot with a single outer product.\nthe first pivot should occur with $x_1$ leaving and $x_4$ entering.\nIn other words, we want to pivot at row $i = 4$ and column $j = 1$ in the tableau (the indices are offset by one because of the objective function and the row of constraints).\n\nThe row corresponding to $x_4$ is\n\\[\n\\begin{bmatrix} 5 &-3 &-1 & 0 & 0 & 0\\end{bmatrix}.\n\\]\nThis represents the equation\n\\[\nx_4 = 5 - 3x_1 - x_2.\n\\]\nOur eventual goal is to solve for $x_1$ and substitute into the remaining rows of the tableau.\nA simple method to accomplish this is to rewrite the equation so that we have zero on the left-hand side:\n\\[\n0 = 5 - 3x_1 - x_2 - x_4.\n\\]\nNow, we can normalize this equation so that the coefficient of $x_1$ is $-1$.\nThis is always accomplished by dividing the equation by the negative of the coefficient of $x_1$:\n\\begin{equation}\n0 = \\frac{5}{3} - x_1 - \\frac{1}{3}x_2 - \\frac{1}{3}x_4.\n\\label{eq:zero-equation}\n\\end{equation}\nThis is represented by the vector\n\\[\n\\begin{bmatrix} 5/3 & -1 & -1/3 & 0 & -1/3 & 0\\end{bmatrix}.\n\\]\nSince this left-hand side is zero, I can add any scalar multiple of this equation to any of the equations for $x_i$ and still have an equation for $x_i$.\nFor example, the equation for $x_5$ is\n\\[\nx_5 = 7 - 4x_1 - 3x_2.\n\\]\nThus, I can add $-4$ times \\eqref{eq:zero-equation} to this equation without changing the left-hand side:\n\\[ x_5 = 7 - 4x_1 - 3x_2 = 7 - 4x_1 - 3x_2 + -4\\left(\\frac{5}{3} - x_1 - \\frac{1}{3}x_2 - \\frac{1}{3}x_4\\right) = \\frac{1}{3} - \\frac{5}{3}x_2 + \\frac{4}{3} x_4.\n\\]\nNotice that we end up with an equation that does not include $x_1$ and now has $x_4$, just like we wanted.\nIn fact, this works in all of our equations, including those for the objective function and even for $x_1$!\nSince the coefficient of $x_1$ in \\eqref{eq:zero-equation} is $-1$, when we scale it by the coefficient of $x_1$ in any particular row, the $x_1$ cancels out.\n\\[\nT = T + \\begin{bmatrix}3 \\\\ 1 \\\\ 0 \\\\ -1 \\\\ -3 \\\\ -4\\end{bmatrix}\\begin{bmatrix} 5/3 & -1 & -1/3 & 0 & -1/3 & 0\\end{bmatrix}.\n\\]\nThe column vector is just the second column of $T$, which is the column containing the coefficients of $x_1$ in each row.\nWhen we compute this sum, we obtain the tableau.\n\\[\nT = \\begin{bmatrix}\n        5 &  0 & 1 & 0 & -1 & 0 \\\\\n        5/3 & 0 &-1/3 & 0 &-1/3 & 0 \\\\\n        0 & 0 & 1 & 0 & 0 & 0 \\\\\n        1/3 & 0 & 4/3 & 0 & 1/3 & 0 \\\\\n        0 & 0 & 0 & 0 & 1 & 0 \\\\\n        1/3 & 0 & -5/3 & 0 & 4/3 & 0\n\\end{bmatrix}.\n\\]\n\\end{comment}\n\\begin{problem}\nWrite a method that will determine the pivot row and pivot column according to Bland's Rule.\n\\begin{comment}\n\\begin{definition}[Bland's Rule]\nChoose the nonbasic variable with the smallest index that has a positive coefficient in the objective function\nas the leaving variable.  Choose the basic variable with the smallest index among all the binding basic variables.\n\\end{definition}\n\nBland's Rule is important in avoiding cycles when performing pivots.\nThis rule guarantees that a feasible Simplex problem will terminate in a finite number of pivots.\n\\end{comment}\n\\label{prob:blands}\n\\end{problem}\n\nThe next step is to swap the entering and leaving indices in our index list.\nIn the example, we determined above that these indices are $0$ and $3$. We swap these two elements in our index list,\nand the updated index list is now\n\\[\nL = (2, 0, 4, 3, 1),\n\\]\nso the basic variables are now given by the indices $2, 0, 4$.\n\nFinally, we perform row operations on our tableau in the following way: divide the pivot row by the value of the pivot entry.\nThen use the pivot row to zero out all entries in the pivot column above and below the pivot entry. In our example, we first divide\nthe pivot row by 3, and then zero out the two entries above the pivot element and the single entry below it:\n\\begin{align*}\n\\begin{bmatrix}\n    0 & -3 & -2 & 0 & 0 & 0 & 1\\\\\n    2 & 1 & -1 & 1 & 0 & 0 & 0\\\\\n    5 & 3 & 1 & 0 & 1 & 0 & 0\\\\\n    7 & 4 & 3 & 0 & 0 & 1 & 0\n    \\end{bmatrix} &\\rightarrow\n\\begin{bmatrix}\n    0 & -3 & -2 & 0 & 0 & 0 & 1\\\\\n    2 & 1 & -1 & 1 & 0 & 0 & 0\\\\\n    5/3 & 1 & 1/3 & 0 & 1/3 & 0 & 0\\\\\n    7 & 4 & 3 & 0 & 0 & 1 & 0\n    \\end{bmatrix}\\rightarrow\\\\\n\\begin{bmatrix}\n    5 & 0 & -1 & 0 & 1 & 0 & 1\\\\\n    2 & 1 & -1 & 1 & 0 & 0 & 0\\\\\n    5/3 & 1 & 1/3 & 0 & 1/3 & 0 & 0\\\\\n    7 & 4 & 3 & 0 & 0 & 1 & 0\n    \\end{bmatrix} &\\rightarrow\n\\begin{bmatrix}\n    5 & 0 & -1 & 0 & 1 & 0 & 1\\\\\n    1/3 & 0 & -4/3 & 1 & -1/3 & 0 & 0\\\\\n    5/3 & 1 & 1/3 & 0 & 1/3 & 0 & 0\\\\\n    7 & 4 & 3 & 0 & 0 & 1 & 0\n    \\end{bmatrix}\\rightarrow\\\\\n\\begin{bmatrix}\n    5 & 0 & -1 & 0 & 1 & 0 & 1\\\\\n    1/3 & 0 & -4/3 & 1 & -1/3 & 0 & 0\\\\\n    5/3 & 1 & 1/3 & 0 & 1/3 & 0 & 0\\\\\n    1/3 & 0 & 5/3 & 0 & -4/3 & 1 & 0\n    \\end{bmatrix}.\n\\end{align*}\nThe result of these row operations is our updated Tableau, and the pivot operation is complete.\n\n% Problem 5: Pivoting\n\\begin{problem}\nAdd a method to your solver that checks for unboundedness and performs a single pivot operation from start to completion.\nIf the problem is unbounded, raise a \\li{ValueError}.\n\\end{problem}\n\n\\subsection*{Termination and Reading the Tableau}\nUp to this point, our algorithm accepts a linear program, adds slack variables, and creates the initial tableau. After\ncarrying out these initial steps, it then performs the pivoting operation iteratively until the optimal point is found.\nBut how do we determine when the optimal point is found? The answer is to look at the top row of the tableau. More specifically,\nbefore each pivoting operation, check whether all of the entries in the top row of the tableau (ignoring the entry in the first\ncolumn) are nonnegative. If this is the case, then we have found an optimal solution, and so we terminate the algorithm.\n\nThe final step is to report the solution. The ending state of the tableau and index list tell us everything we need to know.\nThe maximum value attained by the objective function is found in the upper leftmost entry of the tableau. The nonbasic variables,\nwhose indices are located in the last $n$ entries of the index list, all have the value $0$. The basic variables, whose indices\nare located in the first $m$ entries of the index list, have values given by the first column of the tableau. Specifically, the basic\nvariable whose index is located at the $i$-th entry of the index list has the value $T_{i+1, 1}$.\n\nIn our example, suppose that our algorithm terminates with the tableau and index list in the following state:\n\\[\nT = \\begin{bmatrix}\n5.2 & 0 & 0 & 0 & .2 & .6 & 1\\\\\n.6 & 0 & 0 & 1 & -1.4 & .8 & 0\\\\\n1.6 & 1 & 0 & 0 & .6 & -.2 & 0\\\\\n.2 & 0 & 1 & 0 & -.8 & .6 & 0\\\\\n\\end{bmatrix}\n\\]\n\\[\nL = (2, 0, 1, 3, 4).\n\\]\nThen the maximum value of the objective function is $5.2$. The nonbasic variables have indices $3, 4$ and have the value $0$.\nThe basic variables have indices $2, 0,$ and $1$, and have values $.6, 1.6$, and $.2$, respectively.\nIn the notation of the original problem statement, the solution is given by\n\\begin{align*}\nx_0 &= 1.6\\\\\nx_1 &= .2.\n\\end{align*}\n\n% SimplexSolver.solve()\n\\begin{problem}\nWrite an additional method in your solver called \\li{solve()} that obtains the optimal solution, then returns the maximum value, the basic variables, and the nonbasic variables.\nThe basic and nonbasic variables should be represented as two dictionaries that map the index of the variable to its corresponding value.\n\nFor our example, we would return the tuple \\li{(5.2, \\{0: 1.6, 1: .2, 2: .6\\}, \\{3: 0, 4: 0\\})}.\n%The correct format of this tuple is critical, as this tuple of information will be used judge whether or not your solver works!\n\\end{problem}\n\nAt this point, you should have a Simplex solver that is simple to use. The following code demonstrates how your solver is\nexpected to behave:\n\n\\begin{lstlisting}\n>>> import SimplexSolver\n\n# Initialize objective function and constraints.\n>>> c = np.array([3., 2])\n>>> b = np.array([2., 5, 7])\n>>> A = np.array([[1., -1], [3, 1], [4, 3]])\n\n# Instantiate the simplex solver, then solve the problem.\n>>> solver = SimplexSolver(c, A, b)\n>>> sol = solver.solve()\n>>> print(sol)\n(5.200,\n {0: 1.600, 1: 0.200, 2: 0.600},\n {3: 0, 4: 0})\n\\end{lstlisting}\n\nIf the linear program were infeasible at the origin or unbounded, we would expect the solver to alert the user by raising an error.\n\nNote that this simplex solver is \\emph{not} fully operational.\nIt can't handle the case of infeasibility at the origin.\nThis can be fixed by adding methods to your class that solve the \\emph{auxiliary problem}, that of finding an initial feasible tableau when the problem is not feasible at the origin.\nSolving the auxiliary problem involves pivoting operations identical to those you have already implemented, so adding this functionality\nis not overly difficult.\n\n\\section*{The Product Mix Problem}\nWe now use our Simplex implementation to solve the \\emph{product mix problem}, which in its basic form can be expressed as a simple linear program.\nSuppose that a manufacturer makes $n$ products using $m$ different resources (labor, raw materials, machine time available, etc).\nThe $i$-th product is sold at a unit price $p_i$, and there are at most $m_j$ units\nof the $j$-th resource available. Additionally, each unit of the $i$-th product requires $a_{j,i}$ units of resource $j$.\nGiven that the demand for product $i$ is $d_i$ units per a certain time period, how do we choose the optimal amount\nof each product to manufacture in that time period so as to maximize revenue, while not exceeding the available resources?\n\nLet  $x_1, x_2, \\ldots, x_n$ denote the amount of each product to be manufactured.\nThe sale of product $i$ brings revenue in the amount of $p_ix_i$.\nTherefore our objective function, the profit, is given by\n\\[\n\\sum_{i=1}^n p_ix_i.\n\\]\nAdditionally, the manufacture of product $i$ requires $a_{j,i}x_i$ units of resource $j$.\nThus we have the resource constraints\n\\[\n\\sum_{i=1}^n a_{j,i}x_i \\leq m_j  \\text{ for } j = 1, 2, \\ldots, m.\n\\]\n\nFinally, we have the demand constraints which tell us not to exceed the demand for the products:\n\\[\nx_i \\leq d_i \\text{ for } i = 1, 2, \\ldots, n\n\\]\n\nThe variables $x_i$ are constrained to be nonnegative, of course. We therefore have a linear program in the appropriate form that is feasible at the origin.\nIt is a simple task to solve the problem using our Simplex solver.\n\n\\begin{problem}\nSolve the product mix problem for the data contained in the file \\li{productMix.npz}. In this problem, there are 4 products and 3 resources.\nThe archive file, which you can load using the function\n\\li{np.load}, contains a dictionary of arrays. The array with key \\li{'A'} gives the resource coefficients $a_{i,j}$ (i.e. the $(i,j)$-th entry\nof the array give $a_{i,j}$). The array with key \\li{'p'} gives the unit prices $p_i$. The array with key \\li{'m'} gives the available resource\nunits $m_j$. The array with key \\li{'d'} gives the demand constraints $d_i$.\n\nReport the number of units that should be produced for each product.\n\\end{problem}\n%---------------------------------------------------------------------------------------------------\n%\n%\n% \\section*{Auxiliary Problems}\n%\n% When one of the entries of $b$ is negative, we need to run an auxiliary problem to find a feasible point.\n% Try adding $x_0$ as the last variable.\n% That way you just need to add a single row and column to your current tableau $T$.\n% You can check that subtracting $x_0$ from each of the constraints is the same as adding $x_0$ to each of the expressions for the slack variables.\n% Since we also need write $x_0$ in terms of itself ($x_0 = x_0$), this is equivalent to setting the last column equal to 1 for all the rows corresponding to slack variables, plus one new row.\n% We also need to change the objective function to $-x_0$.\n% Let's let $N$ be the matrix for the auxiliary problem.\n% Then we can construct it from $T$ using the code\n% \\begin{lstlisting}\n% >>> N = zeros((s+1,s+1))\n% >>> N[0:s,0:s] = T\n% >>> N[n:s+1,s] = 1\n% >>> N[0,s] = -1\n% \\end{lstlisting}\n%\n% Before you run simplex on this auxiliary tableau, make sure you do a pivot on the last column and the row corresponding to the smallest entry of $b$.\n% Check that the objective function value is 0 when simplex finishes running.\n% If not, your initial problem is infeasible.\n% If the problem is feasible, get the system of equations from $N$ and put them back into $T$, leaving off the last row and column of $N$ (for $x_0$) and the first row (corresponding to the objective function).\n% \\begin{lstlisting}\n% T[1:s,0:s] = N[1:s,0:s]\n% \\end{lstlisting}\n% The last thing you need to do is insert your previous objective function.\n% However, you need to re-write it in terms of the current nonbasic variables.\n% Fortunately, $T$ currently contains all of your variables written in terms of the nonbasic variables.\n% You can check (mathematically, or however you want to satisfy yourself) that\n% \\begin{lstlisting}\n% T[0,0:s] = T[0,0:s]*T\n% \\end{lstlisting}\n% will put the objective function into the first row, now written in terms of the new nonbasic variables.\n\n\\section*{Beyond Simplex}\nThe \\emph{Computing in Science and Engineering} journal listed Simplex as one of the top ten algorithms of the twentieth century \\cite{Nash2000}.\nDespite its popularity, like any other algorithm, Simplex has its drawbacks.\n\nIn 1972, Victor Klee and George Minty Cube published a paper with several examples of worst-case polytopes for the Simplex algorithm \\cite{Klee1972}.\nIn their paper, they give several examples of polytopes that the Simplex algorithm struggles to solve.\n\nConsider the following linear program from Klee and Minty.\n\\begin{align*}\n\\text{max } & 2^{n-1}x_1 & + & 2^{n-2}x_2  & + & \\cdots & + & 2x_{n-1} & + & x_n\\\\\n\\text{subject to } & x_1 &  &  &  &  &  &  &  &\\leq 5\\\\\n& 4x_1 & + & x_2 &  &  &  &  &  &\\leq 25\\\\\n& 8x_1 & + & 4x_2 & + & x_3 &  &  &  &\\leq 125\\\\\n& \\vdots & &      &   &     &  &  &  &\\vdots\\\\\n& 2^n x_1 & + & 2^{n-1} x_2 & + & \\cdots & + & 4x_{n-1} & + x_n &\\leq 5\\\\\n\\end{align*}\n\n% When $n = 3$, we have the initial tableau\n% \\begin*{equation*}\n% \\begin{bmatrix}\n% 0 & 4 & 2 & 1 & 0 & 0 & 0\\\\\n% 0 & 1 & 0 & 0 & 0 & 0 & 0\\\\\n% 0 & 0 & 1 & 0 & 0 & 0 & 0\\\\\n% 0 & 0 & 0 & 1 & 0 & 0 & 0\\\\\n% 5 & -1 & 0 & 0 & 0 & 0 & 0\\\\\n% 25 & -4 & -1 & 0 & 0 & 0 & 0\\\\\n% 125 & -8 & -4 & -1 & 0 & 0 & 0\\\\\n% \\end{bmatrix}\n% \\end{equation*}\n%\n% After the first pivot with $x_1$ leaving and $s_1$ entering, we have the tableau\n%\n% \\begin{equation*}\n% \\begin{bmatrix}\n% 20 & 0 & 2 & 1 & -4 & 0 & 0\\\\\n% 5 & 0 & 0 & 0 & -1 & 0 & 0\\\\\n% 0 & 0 & 1 & 0 & 0 & 0 & 0\\\\\n% 0 & 0 & 0 & 1 & 0 & 0 & 0\\\\\n% 0 & 0 & 0 & 0 & 1 & 0 & 0\\\\\n% 5 & 0 & -1 & 0 & 4 & 0 & 0\\\\\n% 85 & 0 & -4 & -1 & 8 & 0 & 0\\\\\n% \\end{bmatrix}\n% \\end{equation*}\n%\n% \\begin{problem}\n% What is the final tableau for this Klee-Minty example with $n=3$?\n% How many iterations does it take to arrive at the final tableau?\n% \\end{problem}\n%\n% \\begin{problem}\n% Using problem 1 as a guide, guess the optimum value of the Klee-Minty example with $n=20$.\n% Then find the maximum value for the Klee-Minty example with $n=20$.\n% How many iterations does it take to arrive at the final tableau?\n% How long does the program take to run for only $20$ variables?\n% \\end{problem}\n\nKlee and Minty show that for this example, the worst case scenario has exponential time complexity.\nWith only $n$ constraints and $n$ variables, the simplex algorithm goes through $2^n$ iterations.\nThis is because there are $2^n$ extreme points, and when starting at the point $x=0$, the simplex algorithm goes through all of the extreme points before reaching the optimal point $(0,0,\\dots, 0, 5^n)$.\nOther algorithms, such as interior point methods, solve this problem much faster because they are not constrained to follow the edges.\n\n\\printbibliography\n", "meta": {"hexsha": "959e015ebaaf7c38e75e83c47afbef558169476d", "size": 30561, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2B/Simplex/Simplex.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2B/Simplex/Simplex.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2B/Simplex/Simplex.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": 49.0545746388, "max_line_length": 254, "alphanum_fraction": 0.7063904977, "num_tokens": 9235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.6990415832655008}}
{"text": "% !TEX root = Main.tex\n\\section{Word Embeddings}\n\\textbf{Distributional Model:}\\\\\n$p_\\theta(w|w')$ = Pr[$w$ occurs in context of $w'$]\\\\\n\\textbf{Log-likelihood:}\\\\\n$L(\\theta; \\mathbf{w}) = \\sum_{t=1}^T\\sum_{\\Delta \\in I}{\\log p_\\theta(w^{(t+\\Delta)}|w^{(t)})}$\\\\\n\\textbf{Latent Vector Model:} $w \\rightarrow (\\mathbf{x}_w, b_w) \\in \\mathbb{R}^{D+1} \\\\p_{\\theta}(w|w') = \\frac{\\exp[\\langle \\mathbf{x}_w,\\mathbf{x}_{w'}\\rangle + b_w]}{\\sum_{v\\in V}{\\exp[\\langle \\mathbf{x}_v,\\mathbf{x}_{w'}\\rangle + b_v ]}}$ (soft-max).\\\\\n\\textbf{Modifications:}\\\\\n$\\log p_{\\theta}(w|w') = \\langle  y_{w} , x_{w'} \\rangle + b_w$,  word $y_w$, c'txt $x_{w'}$\\\\\nuse GloVe objective\\\\\nnegative sampling (logistic classification)\n\n\\subsection*{GloVe (Weighted Square Loss)}\n\\textbf{Co-occurence Matrix:}\\\\\n$\\mathbf{N} = (n_{ij}) \\in \\mathbb{R}^{|V|\\times|C|} = \\# of word w_i$ in context $w_j$\\\\\n\\textbf{Objective:} $H(\\theta;\\mathbf{N})$\\\\\n$= \\sum_{n_{ij} > 0} f(n_{ij})(\\log n_{ij} - \\log \\exp[\\langle \\mathbf{x}_i, \\mathbf{y}_j \\rangle + b_i + d_j])^2$\\\\\nwith $f(n) = \\min\\{1, (\\frac{n}{n_{max}})^\\alpha\\}$, $\\alpha \\in (0;1]$.\\\\\nunnormalized distr. $\\rightarrow$ 2-sided loss function\\\\\n1. sample $(i,j) u.a.r, s.t. n_{ij}>0$\\\\\n2. $\\mathbf{x}_i^{new} \\leftarrow \\mathbf{x}_i + 2\\eta f(n_{ij})(\\log n_{ij} - \\langle \\mathbf{x}_i, \\mathbf{y}_j \\rangle)\\mathbf{y}_j$\\\\\n3. $\\mathbf{y}_j^{new} \\leftarrow \\mathbf{y}_j + 2\\eta f(n_{ij})(\\log n_{ij} - \\langle \\mathbf{x}_i, \\mathbf{y}_j \\rangle)\\mathbf{x}_i$\n\n\\subsection*{Discussion}\nWord embeddings can model analogies and relatedness, but antonyms are usually not well captured.\n", "meta": {"hexsha": "a9533732e9fca587cd6025f237ff2f68ca2ec7ac", "size": 1607, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WordEmbedding.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": "WordEmbedding.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": "WordEmbedding.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": 61.8076923077, "max_line_length": 257, "alphanum_fraction": 0.6253889235, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154530420204, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6989398515326197}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Appendix}\\label{appx:expe}\n\n%-----------------------------\n%\\subsection*{Bernoulli's law of large numbers}\\label{subsec:}\n\nIn the proof of Theorem~\\ref{thm:wlln}, we used Chebyshev's inequality to show that\n\\[\n\\prob(|\\bar{X}_n - \\mu| \\geq \\epsilon) \\leq \\frac{\\sigma^2}{n\\epsilon^2} \\qquad\\forall\\ \\epsilon>0.\n\\]\nWe say that the \\emph{rate} at which $\\bar{X}_n\\to\\mu$ is of order $O(1/n)$ as $n\\to\\infty$.\n%\nIn the proof of the following theorem, we use Bernstein's inequality to show that the sample mean of Bernoulli random variables satisfies\n\\[\n\\prob\\left(|\\bar{X}_n - \\mu| > \\epsilon\\right) \\leq e^{-\\frac{1}{2}n\\epsilon^2}  \\qquad\\forall\\ \\epsilon>0.\n\\]\nIn this case, the rate at which $\\bar{X}_n\\to\\mu$ as $n\\to\\infty$ is said to be \\emph{exponentially fast}. \n\n% theorem\n\\begin{theorem}[Bernoulli's Law of Large Numbers]\\label{thm:bernoulli_lln}\nLet $X_1,X_2,\\ldots$ be independent, with each $X_i\\sim\\text{Bernoulli}(p)$, and let $\\bar{X}_n = \\frac{1}{n}\\sum_{i=1}^n X_i$ be the sample mean of the first $n$ variables in the sequence.\nThen for every $\\epsilon > 0$, \n\\[\n\\prob(|\\bar{X}_n - p| > \\epsilon) \\to 0 \\text{\\quad as\\quad} n\\to\\infty.\n\\]\n\\end{theorem}\n\n% proof\n\\begin{proof}\nLet $\\epsilon>0$ and define $S_n=\\sum_{i=1}^n X_i$. Then\n\\[\n\\prob\\left(\\bar{X}_n - p > \\epsilon\\right)\n\t= \\prob\\big[S_n > n(p+\\epsilon)\\big]\n\\]\n\n%\\bit\n%\\it Recall Bernstein's inequality: $\\prob(X>a) \\leq e^{-ta}\\expe(e^{tX})$ for all $t>0$.\n%\\eit\n\nApplying Bernstein's inequality (Theorem~\\ref{thm:bernstein}) to the random variable $S_n$ with $a = n(p+\\epsilon)$,\n\\begin{align*}\n\\prob\\big[S_n > n(p+\\epsilon)\\big]\n\t& \\leq e^{-tn(p+\\epsilon)}\\expe(e^{tS_n}) \\\\\n\t& = e^{-tn(p+\\epsilon)}\\big[1-p+pe^t\\big]^n \\\\\n\t& = e^{-tn\\epsilon}\\big[ e^{-tp}(1-p+pe^t) \\big]^n \\\\\n\t& = e^{-tn\\epsilon}\\big[ (1-p)e^{-tp} + pe^{t(1-p)} \\big]^n\n\\end{align*}\n\nUsing the inequality $e^x \\leq x + e^{x^2}$, which holds for all $x\\in\\R$, % (see exercises),\n\\begin{align*}\n(1-p)e^{-tp} + pe^{t(1-p)}  \n\t& \\leq (1-p)\\big[-tp + e^{t^2p^2}\\big] + p\\big[t(1-p) + e^{t^2(1-p)^2}\\big] \\\\\n\t& = (1-p)e^{t^2p^2} + pe^{t^2(1-p)^2} \\\\\n\t& \\leq (1-p)e^{t^2} + pe^{t^2} \\\\\n\t& = e^{t^2}.\n\\end{align*}\nHence, for all $t>0$,\n\\[\n\\prob\\left(\\bar{X}_n -p > \\epsilon\\right) = \\prob\\big[S_n > n(p+\\epsilon)\\big] \\leq e^{-tn\\epsilon}e^{t^2n} = e^{tn(t-\\epsilon)}.\n\\]\n\\bit\n\\it This inequality is valid for all $t>0$. \n\\it We choose $t$ so that the right-hand side is made as small as possible. \n\\it Because $e^x$ is an increasing function, this corresponds to the minimum value of the exponent. \n\\it We differentiate the exponent $tn(t-\\epsilon)$ with respect to $t$ and set this equal to zero.\n\\eit\n\nThis yields the value $t = \\frac{1}{2}\\epsilon$, so\n\\[\n\\prob\\left(\\bar{X}_n -p > \\epsilon\\right) = \\prob\\big[S_n > n(p+\\epsilon)\\big] \\leq e^{-\\frac{1}{4}n\\epsilon^2}.\n\\]\nA similar argument shows that \n\\[\n\\prob\\left(\\bar{X}_n -p < -\\epsilon\\right) = \\prob\\big[S_n < n(p-\\epsilon)\\big] \\leq e^{-\\frac{1}{4}n\\epsilon^2},\n\\]\nThus we have\n\\[\n\\prob\\left(|\\bar{X}_n - p| > \\epsilon\\right) \\leq e^{-\\frac{1}{2}n\\epsilon^2} \\to 0 \\text{\\quad as $n\\to\\infty$,}\n\\]\nas required.\n\\end{proof}\n", "meta": {"hexsha": "c3c544c395c209a8d6c7e6efe87debaaa5aa8852", "size": 3208, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/06D_appendix.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/06D_appendix.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/06D_appendix.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": 38.1904761905, "max_line_length": 189, "alphanum_fraction": 0.6119077307, "num_tokens": 1266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.884039278690883, "lm_q1q2_score": 0.6988598527000132}}
{"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*{error\\_ellipse.m} \n\n\\begin{par}\nERROR\\_ELLIPSE - plot an error ellipse, or ellipsoid, defining confidence region    ERROR\\_ELLIPSE(C22) - Given a 2x2 covariance matrix, plot the    associated error ellipse, at the origin. It returns a graphics handle    of the ellipse that was drawn.\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}  ERROR_ELLIPSE(C33) - Given a 3x3 covariance matrix, plot the\n  associated error ellipsoid, at the origin, as well as its projections\n  onto the three axes. Returns a vector of 4 graphics handles, for the\n  three ellipses (in the X-Y, Y-Z, and Z-X planes, respectively) and for\n  the ellipsoid.\\end{verbatim}\n    \n\\begin{verbatim}  ERROR_ELLIPSE(C,MU) - Plot the ellipse, or ellipsoid, centered at MU,\n  a vector whose length should match that of C (which is 2x2 or 3x3).\\end{verbatim}\n    \n\\begin{verbatim}  ERROR_ELLIPSE(...,'Property1',Value1,'Name2',Value2,...) sets the\n  values of specified properties, including:\n    'C' - Alternate method of specifying the covariance matrix\n    'mu' - Alternate method of specifying the ellipse (-oid) center\n    'conf' - A value betwen 0 and 1 specifying the confidence interval.\n      the default is 0.5 which is the 50% error ellipse.\n    'scale' - Allow the plot the be scaled to difference units.\n    'style' - A plotting style used to format ellipses.\n    'clip' - specifies a clipping radius. Portions of the ellipse, -oid,\n      outside the radius will not be shown.\\end{verbatim}\n    \n\\begin{verbatim}  NOTES: C must be positive definite for this function to work properly.\\end{verbatim}\n    \\begin{par}\nby AJ Johnson \\begin{verbatim}http://www.mathworks.de/matlabcentral/fileexchange/4705\\end{verbatim}\n\\end{par} \\vspace{1em}\n\n\\begin{lstlisting}\nfunction h=error_ellipse(varargin)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\ndefault_properties = struct(...\n  'C', [], ... % The covaraince matrix (required)\n  'mu', [], ... % Center of ellipse (optional)\n  'conf', 0.95, ... % Percent confidence/100\n  'scale', 1, ... % Scale factor, e.g. 1e-3 to plot m as km\n  'style', '', ...  % Plot style\n  'clip', inf); % Clipping radius\n\nif length(varargin) >= 1 & isnumeric(varargin{1})\n  default_properties.C = varargin{1};\n  varargin(1) = [];\nend\n\nif length(varargin) >= 1 & isnumeric(varargin{1})\n  default_properties.mu = varargin{1};\n  varargin(1) = [];\nend\n\nif length(varargin) >= 1 & isnumeric(varargin{1})\n  default_properties.conf = varargin{1};\n  varargin(1) = [];\nend\n\nif length(varargin) >= 1 & isnumeric(varargin{1})\n  default_properties.scale = varargin{1};\n  varargin(1) = [];\nend\n\nif length(varargin) >= 1 & ~ischar(varargin{1})\n  error('Invalid parameter/value pair arguments.')\nend\n\nprop = getopt(default_properties, varargin{:});\nC = prop.C;\n\nif isempty(prop.mu)\n  mu = zeros(length(C),1);\nelse\n  mu = prop.mu;\nend\n\nconf = prop.conf;\nscale = prop.scale;\nstyle = prop.style;\n\nif conf <= 0 | conf >= 1\n  error('conf parameter must be in range 0 to 1, exclusive')\nend\n\n[r,c] = size(C);\nif r ~= c | (r ~= 2 & r ~= 3)\n  error(['Don''t know what to do with ',num2str(r),'x',num2str(c),' matrix'])\nend\n\nx0=mu(1);\ny0=mu(2);\n\n% Compute quantile for the desired percentile\nk = sqrt(qchisq(conf,r)); % r is the number of dimensions (degrees of freedom)\n\nhold_state = get(gca,'nextplot');\n\nif r==3 & c==3\n  z0=mu(3);\n\n  % Make the matrix has positive eigenvalues - else it's not a valid covariance matrix!\n  if any(eig(C) <=0)\n    error('The covariance matrix must be positive definite (it has non-positive eigenvalues)')\n  end\n\n  % C is 3x3; extract the 2x2 matricies, and plot the associated error\n  % ellipses. They are drawn in space, around the ellipsoid; it may be\n  % preferable to draw them on the axes.\n  Cxy = C(1:2,1:2);\n  Cyz = C(2:3,2:3);\n  Czx = C([3 1],[3 1]);\n\n  [x,y,z] = getpoints(Cxy,prop.clip);\n  h1=plot3(x0+k*x,y0+k*y,z0+k*z,prop.style,'linewidth',2);hold on\n  [y,z,x] = getpoints(Cyz,prop.clip);\n  h2=plot3(x0+k*x,y0+k*y,z0+k*z,prop.style,'linewidth',2);hold on\n  [z,x,y] = getpoints(Czx,prop.clip);\n  h3=plot3(x0+k*x,y0+k*y,z0+k*z,prop.style,'linewidth',2);hold on\n\n\n  [eigvec,eigval] = eig(C);\n\n  [X,Y,Z] = ellipsoid(0,0,0,1,1,1);\n  XYZ = [X(:),Y(:),Z(:)]*sqrt(eigval)*eigvec';\n\n  X(:) = scale*(k*XYZ(:,1)+x0);\n  Y(:) = scale*(k*XYZ(:,2)+y0);\n  Z(:) = scale*(k*XYZ(:,3)+z0);\n  h4=surf(X,Y,Z);\n  colormap gray\n  alpha(0.3)\n  camlight\n  if nargout\n    h=[h1 h2 h3 h4];\n  end\nelseif r==2 & c==2\n  % Make the matrix has positive eigenvalues - else it's not a valid covariance matrix!\n  if any(eig(C) <=0)\n    error('The covariance matrix must be positive definite (it has non-positive eigenvalues)')\n  end\n\n  [x,y,z] = getpoints(C,prop.clip);\n  h1=plot(scale*(x0+k*x),scale*(y0+k*y),prop.style,'linewidth',2);\n  set(h1,'zdata',z+1)\n  if nargout\n    h=h1;\n  end\nelse\n  error('C (covaraince matrix) must be specified as a 2x2 or 3x3 matrix)')\nend\n%axis equal\n\nset(gca,'nextplot',hold_state);\n\n%---------------------------------------------------------------\n% getpoints - Generate x and y points that define an ellipse, given a 2x2\n%   covariance matrix, C. z, if requested, is all zeros with same shape as\n%   x and y.\n\\end{lstlisting}\n\n\\begin{lstlisting}\nfunction [x,y,z] = getpoints(C,clipping_radius)\n\nn=100; % Number of points around ellipse\np=0:pi/n:2*pi; % angles around a circle\n\n[eigvec,eigval] = eig(C); % Compute eigen-stuff\nxy = [cos(p'),sin(p')] * sqrt(eigval) * eigvec'; % Transformation\nx = xy(:,1);\ny = xy(:,2);\nz = zeros(size(x));\n\n% Clip data to a bounding radius\nif nargin >= 2\n  r = sqrt(sum(xy.^2,2)); % Euclidian distance (distance from center)\n  x(r > clipping_radius) = nan;\n  y(r > clipping_radius) = nan;\n  z(r > clipping_radius) = nan;\nend\n\n%---------------------------------------------------------------\nfunction x=qchisq(P,n)\n% QCHISQ(P,N) - quantile of the chi-square distribution.\nif nargin<2\n  n=1;\nend\n\ns0 = P==0;\ns1 = P==1;\ns = P>0 & P<1;\nx = 0.5*ones(size(P));\nx(s0) = -inf;\nx(s1) = inf;\nx(~(s0|s1|s))=nan;\n\nfor ii=1:14\n  dx = -(pchisq(x(s),n)-P(s))./dchisq(x(s),n);\n  x(s) = x(s)+dx;\n  if all(abs(dx) < 1e-6)\n    break;\n  end\nend\n\n%---------------------------------------------------------------\nfunction F=pchisq(x,n)\n% PCHISQ(X,N) - Probability function of the chi-square distribution.\nif nargin<2\n  n=1;\nend\nF=zeros(size(x));\n\nif rem(n,2) == 0\n  s = x>0;\n  k = 0;\n  for jj = 0:n/2-1;\n    k = k + (x(s)/2).^jj/factorial(jj);\n  end\n  F(s) = 1-exp(-x(s)/2).*k;\nelse\n  for ii=1:numel(x)\n    if x(ii) > 0\n      F(ii) = quadl(@dchisq,0,x(ii),1e-6,0,n);\n    else\n      F(ii) = 0;\n    end\n  end\nend\n\n%---------------------------------------------------------------\nfunction f=dchisq(x,n)\n% DCHISQ(X,N) - Density function of the chi-square distribution.\nif nargin<2\n  n=1;\nend\nf=zeros(size(x));\ns = x>=0;\nf(s) = x(s).^(n/2-1).*exp(-x(s)/2)./(2^(n/2)*gamma(n/2));\n\n%---------------------------------------------------------------\nfunction properties = getopt(properties,varargin)\n%GETOPT - Process paired optional arguments as 'prop1',val1,'prop2',val2,...\n%\n%   getopt(properties,varargin) returns a modified properties structure,\n%   given an initial properties structure, and a list of paired arguments.\n%   Each argumnet pair should be of the form property_name,val where\n%   property_name is the name of one of the field in properties, and val is\n%   the value to be assigned to that structure field.\n%\n%   No validation of the values is performed.\n%\n% EXAMPLE:\n%   properties = struct('zoom',1.0,'aspect',1.0,'gamma',1.0,'file',[],'bg',[]);\n%   properties = getopt(properties,'aspect',0.76,'file','mydata.dat')\n% would return:\n%   properties =\n%         zoom: 1\n%       aspect: 0.7600\n%        gamma: 1\n%         file: 'mydata.dat'\n%           bg: []\n%\n% Typical usage in a function:\n%   properties = getopt(properties,varargin{:})\n\n\n% Process the properties (optional input arguments)\nprop_names = fieldnames(properties);\nTargetField = [];\nfor ii=1:length(varargin)\n  arg = varargin{ii};\n  if isempty(TargetField)\n    if ~ischar(arg)\n      error('Propery names must be character strings');\n    end\n    f = find(strcmp(prop_names, arg));\n    if length(f) == 0\n      error('%s ',['invalid property ''',arg,'''; must be one of:'],prop_names{:});\n    end\n    TargetField = arg;\n  else\n    % properties.(TargetField) = arg; % Ver 6.5 and later only\n    properties = setfield(properties, TargetField, arg); % Ver 6.1 friendly\n    TargetField = '';\n  end\nend\nif ~isempty(TargetField)\n  error('Property names and values must be specified in pairs.');\nend\n\\end{lstlisting}\n", "meta": {"hexsha": "6e5640c159984a82651d956fe9a878fef4f865a4", "size": 8663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/error_ellipse.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/error_ellipse.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/error_ellipse.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.4967105263, "max_line_length": 252, "alphanum_fraction": 0.6321135865, "num_tokens": 2685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6988598478696351}}
{"text": "\\chapter{Generalized eigenvectors maximize signal-to-noise}\n\\label{apx:GEvecs-maximise-SNR}\n\nIn this appendix, we show that the weight vector that maximizes the ratio of signal to noise variance (i.e. the solution $\\what$ to \\cref{eq:argmax_R}) is equivalent to the first generalized eigenvector $\\w_1$ of the ordered pair of covariance matrices $(\\Rss, \\Rnn)$ (as defined in \\cref{sec:generalized-eigenproblem}).\n\nThis ratio of variances in \\cref{eq:argmax_R} is a quotient of quadratic forms, namely the so called ``generalized Rayleigh quotient'' of $(\\Rss, \\Rnn)$.\n\nFormally, the generalized Rayleigh quotient of a non-zero vector $\\w \\in \\reals^N$ and the ordered, symmetric matrix pair $(\\A,\\B)$ is the scalar $r(\\w)$ defined as:\n%\n\\begin{equation}\n\\label{eq:Rayleigh}\nr(\\w) = \\frac{\\w^T \\A \\w}\n             {\\w^T \\B \\w}\n\\end{equation}\n\nRecall that a vector $\\w_i$ is a generalized eigenvector of $(\\A,\\B)$, with corresponding generalized eigenvalue $\\lambda_i$, if\n%\n\\begin{equation}\n\\label{eq:generalized-eigenproblem-AB}\n\\A \\w_i = \\lambda_i \\B \\w_i\n\\end{equation}\n\nWe must then prove the following:\n\n\n\n\\section{Theorem}\n\nThe generalized eigenvector $\\w_1$ corresponding to the largest generalized eigenvalue $\\lambda_1$ of $(\\A,\\B)$, is also the vector $\\what$ that maximises the generalized Rayleigh quotient $r(\\w)$ of $(\\A,\\B)$.\n\n\n\n\n\\section{Proof}\n\nAs a first step, we will show that if $\\what$ is the maximum of $r(\\w)$, that it is indeed an eigenvector of $(\\A,\\B)$. In the second step, we will show that the largest eigenvalue $\\lambda_1$ of $(\\A,\\B)$ corresponds to the maximum of $r(\\w)$.\n\nIf $\\what$ is a maximum of $r(\\w)$, then\n\\begin{equation}\n\\label{eq:critical}\n\\grad{r(\\what) = \\vb{0}}.\n\\end{equation}\n\nWorking out the partial derivatives that comprise the gradient of $r(\\w)$, we find:\n\\begin{align*}\n\\grad{r(\\w)} &= \\frac{2 \\A \\w \\qty(\\w^T \\B \\w) \n                      - 2 \\B \\w \\qty(\\w^T \\A \\w)}\n                     {\\qty(\\w^T \\B \\w)^2}\n\\end{align*}\n\nWith \\cref{eq:critical}, we then have the following condition for our maximising vector $\\what$:\n\\[\n2 \\A \\what \\qty(\\what^T \\B \\what) = 2 \\B \\what \\qty(\\what^T \\A \\what)\n\\]\nor\n\\begin{align*}\n\\A \\what &= \\frac{\\what^T \\A \\what}\n                 {\\what^T \\B \\what} \\; \\B \\what  \\\\[1em]\n\\A \\what &= r(\\what) \\; \\B \\what\n\\end{align*}\nThis is the generalized eigenvalue/eigenvector definition (\\cref{eq:generalized-eigenproblem-AB}) for $\\w_i = \\what$ and $\\lambda_i = r(\\what)$.\n\nWe have thus shown that if $\\what$ is a maximum of $r(\\w)$, that it is an eigenvector of $(\\A,\\B)$, with $r(\\what)$ its corresponding eigenvalue.\n\nAs the second step, we now show that $r(\\what)$ is the \\emph{largest} eigenvalue of $(\\A,\\B)$. We follow the reasoning of \\citeauthor{Trefethen1997}, who prove a related result for the ordinary Rayleigh quotient \\cite[p. 204]{Trefethen1997}.\n\nWe will rewrite the generalized Rayleigh quotient $r(\\w)$ by writing the arbitrary vector $\\w$ as a linear combination of the generalized eigenvectors $\\w_i$ of $(\\A,\\B)$: $\\w = \\sum_i c_i \\w_i$. Then:\n\\begin{align*}\nr(\\w) &= \\frac{\\qty(\\sum_i c_i \\w_i)^T \\A \\qty(\\sum_i c_i \\w_i)}\n              {\\qty(\\sum_i c_i \\w_i)^T \\B \\qty(\\sum_i c_i \\w_i)} \\\\[1em]\n              % \n      &= \\frac{\\sum_i c_i^2 \\w_i^T \\A \\w_i}\n              {\\sum_i c_i^2 \\w_i^T \\B \\w_i} \\\\[1em]\n              % \n      &= \\frac{\\sum_i c_i^2 \\lambda_i \\w_i^T \\B \\w_i}\n              {\\sum_i c_i^2 \\w_i^T \\B \\w_i}.\n\\end{align*}\n\nGeneralized eigenvectors are defined up to a scaling factor. We may therefore define our $\\w_i$ to be scaled such that $\\w_i^T \\B \\w_i = 1$. We then have:\n\\[\nr(\\w) = \\frac{\\sum_i c_i^2 \\lambda_i}{\\sum_i c_i^2}.\n\\]\n%\nEach generalized Rayleigh quotient is thus a convex combination of generalized eigenvalues $\\lambda_i$. The maximum of a convex combination of one-dimensional points is obtained in the largest of these points. If $\\lambda_1$ is thus the largest generalized eigenvalue of $(\\A,\\B)$, then $\\max{r(\\w)} = \\lambda_1$.\n\nWe have thus shown that $\\argmax r(\\w) = \\w_1$, where $\\w_1$ is an eigenvector of $(\\A,\\B)$, and that its corresponding eigenvalue $\\lambda_1 = \\max r(\\w)$ is the largest of the eigenvalues of $(\\A,\\B)$.\n\n\\qed\n", "meta": {"hexsha": "6782fc8c280bfb1d474bbb8574ccee766d7a23a4", "size": 4186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Appendices/GEVecs-maximise-SNR.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/Appendices/GEVecs-maximise-SNR.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/Appendices/GEVecs-maximise-SNR.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": 47.0337078652, "max_line_length": 320, "alphanum_fraction": 0.6602962255, "num_tokens": 1362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6988370768114492}}
{"text": "\\section{Duality in Optimization}\n\n\\subsection{The Primal Problem}\n\n\\begin{frame}\n  \\frametitle{The Primal Problem}\n \n  \\begin{itemize}\n    \\item Consider the \\structure{\\emph{primal optimization problem}}: \\\\[.4cm]\n      \\begin{center}\n        \\tikz[baseline]{\n          \\node[fill=bl1!100,anchor=base,rounded corners=3pt] (d1) {\n            \\color{bl3}\n            $\\begin{aligned}\n               \\displaystyle \n               \\mbox{minimize~}  & \\qquad f_0(\\vec{x}) \\\\[.3cm]\n               \\mbox{subject to} & \\qquad f_i(\\vec{x}) \\leq 0, \\quad i=1,2,\\dots, m \\\\\n                                 & \\qquad h_i(\\vec{x}) = 0,    \\quad i=1,2,\\dots, p\n             \\end{aligned}$\n          };\n        }\\\\[.4cm]\n      \\end{center}\n      with variable $\\vec{x}\\in\\real^n$. \\\\[.5cm]\n    \\item The function $f_0(\\vec{x})$ is \\structure{not} required to be \\structure{convex}.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{The Lagrangian}\n\n\\begin{frame}\n  \\frametitle{The Lagrangian}\n \n  \\begin{citeblock}{Lagrangian}\n\n    The \\structure{\\emph{Lagrangian} $L$} of the aforementioned problem is defined as\n    \\begin{displaymath}\n      L(\\vec{x},\\vec{\\lambda}, \\vec{\\nu}) = \n      f_0(\\vec{x}) + \\sum_{i=1}^m \\lambda_i f_i(\\vec{x}) + \\sum_{i=1}^p \\nu_i h_i(\\vec{x})\n    \\end{displaymath}\n    \\pause\n \n    \\begin{itemize}\n      \\item $\\lambda_i$ is the Lagrange multipliers associated with the $i$-th \\structure{inequality} \\\\\n        constraint $f_i(\\vec{x})\\leq 0$. \\\\[.15cm] \\pause\n      \\item $\\nu_i$ is the Lagrange multiplier associated with the $i$-th \\structure{equality} constraint $h_i(\\vec{x})= 0$. \\\\[.15cm] \\pause\n      \\item The vectors $\\vec{\\lambda}$ and $\\vec{\\nu}$ are called {\\em Lagrange multiplier vectors} \\\\\n        or simply \\structure{\\emph{dual variables}}. \n    \\end{itemize}\n  \\end{citeblock}\n\\end{frame}\n\n\n\\subsection{Lagrange Dual Function}\n\n\\begin{frame}\n  \\frametitle{Langrange Dual Function}\n  \n  \\begin{citeblock}{Lagrange dual function}\n\n     The \\structure{\\emph{Lagrange dual function}} is defined as the infimum of the Lagrangian \\\\\n     over $\\vec{x}$\n     \\begin{eqnarray*}\n       g(\\vec{\\lambda,\\nu}) \n         & = & \\inf_{\\vec{x}}L(\\vec{x},\\vec{\\lambda}, \\vec{\\nu}) \\\\ \\pause \n         & = & \\inf_{\\vec{x}} \\left(   \n                                f_0(\\vec{x}) + \\sum_{i=1}^m\\lambda_i f_i(\\vec{x}) + \n                                \\sum_{i=1}^p\\nu_i h_i(\\vec{x})\n                              \\right)\n    \\end{eqnarray*}\n  \\end{citeblock}\n  \\pspread\n  \n  \\structure{Note:} \n  \n  \\begin{itemize}\n    \\item The Lagrange dual function is a \\structure{pointwise affine function} \\\\\n      in the dual variables. \\pause \n    \\item The \\structure{Lagrange dual function is concave} \\\\\n      (even if the original problem is not convex).\n  \\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}{Optimal Value and Lower Bound}\n\n  \\begin{lemma}\n    Let $p^*$ be the optimal value of the optimization problem. \\\\\n    For any $\\vec\\lambda \\succeq 0$ and any $\\vec \\nu$ the following bound is valid:\n    \\begin{displaymath}\n      g(\\vec{\\lambda,\\nu}) \\leq p^* \n    \\end{displaymath} \n  \\end{lemma}\n\\end{frame}\n\n\n\\begin{frame}{Optimal Value and Lower Bound \\cont}\n  \n  \\begin{center}\n    \\resizebox{.8\\linewidth}{!}{\n      \\alt<13->{\n        \\input{\\texfigdir/lagrange13.pstex_t}\n      }{\\alt<12>{\n        \\input{\\texfigdir/lagrange12.pstex_t}\n      }{\\alt<11>{\n        \\input{\\texfigdir/lagrange11.pstex_t}\n      }{\\alt<10>{\n        \\input{\\texfigdir/lagrange10.pstex_t}\n      }{\\alt<9>{\n        \\input{\\texfigdir/lagrange09.pstex_t}\n      }{\\alt<8>{\n        \\input{\\texfigdir/lagrange08.pstex_t}\n      }{\\alt<7>{\n        \\input{\\texfigdir/lagrange07.pstex_t}\n      }{\\alt<6>{\n        \\input{\\texfigdir/lagrange06.pstex_t}\n      }{\\alt<5>{\n        \\input{\\texfigdir/lagrange05.pstex_t}\n      }{\\alt<4>{\n        \\input{\\texfigdir/lagrange04.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/lagrange03.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/lagrange02.pstex_t}\n      }{\n        \\input{\\texfigdir/lagrange01.pstex_t}\n      }}}}}}}}}}}}\n    }\n  \\end{center}\n\\end{frame}  \n\n\n\\begin{frame}{Optimal Value and Lower Bound \\cont}\n\n  \\begin{columns}\n    \\column{.6\\linewidth}\n      \\begin{center}\n        \\resizebox{\\linewidth}{!}{\n          \\input{\\texfigdir/dual.pstex_t}\n        }\n      \\end{center}\n    \\column{.4\\linewidth}\n      \\vspace{.3cm}\n      \\begin{itemize}\n        \\item Neither $f_0(x)$ nor $f_1(x)$ is convex,\n        \\item but the dual function $g(\\lambda)$ is concave!\n      \\end{itemize}\n  \\end{columns}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Optimal Value and Lower Bound \\cont}\n\n  Let $\\tilde{\\vec{x}}$ be a \\structure{feasible point} of the optimization problem. \\\\[.3cm]\n  If $\\vec{\\lambda}\\succeq 0$, we have due to the \\structure{$m$ inequality} and \\structure{$p$ equality} constraints:\n  \\begin{displaymath}\n    \\sum_{i=1}^m \\lambda_i f_i(\\tilde{\\vec{x}}) + \n    \\sum_{i=1}^p\\nu_i h_i(\\tilde{\\vec{x}}) \n    \\leq 0~,\n  \\end{displaymath}\n  \\pause\n\n  Thus we have\n  \\begin{displaymath}\n    L(\\tilde{\\vec{x}},\\vec{\\lambda},\\vec{\\nu}) =\n    f_0 ({\\tilde{\\vec{x}}}) + \n    \\sum_{i=1}^m\\lambda_i f_i(\\tilde{\\vec{x}}) + \n    \\sum_{i=1}^p\\nu_i h_i(\\tilde{\\vec{x}}) \n    \\leq f_0 ({\\tilde{\\vec{x}}})~.\n  \\end{displaymath}\n\\end{frame}\n  \n  \n\\begin{frame}\n  \\frametitle{Optimal Value and Lower Bound \\cont}\n  \n  Using the \\structure{definition of the dual function} we get:\n  \n  \\begin{displaymath}\n    g(\\vec{\\lambda,\\nu}) = \n    \\inf_{{\\vec{x}}} L({\\vec{x}},\\vec{\\lambda}, \\vec{\\nu}) \\leq\n    L(\\tilde{\\vec{x}}, \\vec{\\lambda}, \\vec{\\nu}) \\leq\n%    f_0(\\tilde{\\vec{x}}) + \n%    \\sum_{i=1}^m\\lambda_i f_i(\\tilde{\\vec{x}}) + \n%    \\sum_{i=1}^p\\nu_i h_i(\\tilde{\\vec{x}}) \\leq \n    f_0(\\tilde{\\vec{x}})\n  \\end{displaymath}\n  \\pause\n  \n  \\vspace{.25cm}\n  The inequality $g(\\vec{\\lambda,\\nu}) \\leq f_0(\\tilde{\\vec{x}})$ holds for \\structure{every feasible point $\\tilde{\\vec{x}}$}.\\\\[.5cm]\n  \\pause\n\n  Consequently, the dual function $g(\\vec{\\lambda,\\nu})$ is also smaller or equal to the optimal value $p^*$:\n  \n  \\begin{displaymath}\n    g(\\vec{\\lambda,\\nu}) \\leq p^*\n  \\end{displaymath}\n  \\hfill \\qed %\\structure{\\ensuremath{\\blacksquare}}\n\\end{frame}\n\n\n\\subsection{The Lagrange Dual Problem}\n\n\\begin{frame}\n  \\frametitle{The Lagrange Dual Problem}\n \n  \\structure{Problem:} how to find the best lower bound for the primal problem \\\\[1cm]\n \n  The Lagrange dual problem is given by the optimization problem:\n  \n  \\begin{eqnarray*}\n    \\mbox{maximize}   & & g(\\vec{\\lambda}, \\vec{\\nu}) \\\\[.3cm]\n    \\mbox{subject to} & & \\vec{\\lambda}\\succeq 0\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{The Lagrange Dual Problem \\cont}\n  \n  \\begin{citeblock}{Optimal duality gap}\n\n    Let  ${p}^*$ be the optimal value of the primal problem and \\\\\n    ${d}^*$ the optimal value of the Lagrange dual problem. \\\\[.3cm] \\pause\n    \n    \\begin{itemize}\n      \\item The difference $p^*-d^*$ is the \\structure{\\emph{optimal duality gap}}. \\\\[.3cm] \\pause\n      \\item If $p^*=d^*$, the duality gap is zero. \\\\\n        In this case we talk about \\structure{\\emph{strong duality}}. \\\\[.3cm] \\pause\n      \\item If $p^*> d^*$, we have \\structure{\\emph{weak duality}}.\n     \\end{itemize}\n  \\end{citeblock}\n\\end{frame}\n\n\n\\subsection{Slater's condition}\n\n\\begin{frame}\n  \\frametitle{Slater's Condition}\n\n  \\begin{citeblock}{Theorem}\n\n    Given a \\structure{\\emph{convex} primal optimization problem}:\n    \\small\n    \\begin{eqnarray*}\n      \\mbox{minimize~}  & & \\quad f_0(\\vec{x}) \\\\\n      \\mbox{subject to} & & \\quad f_i(\\vec{x}) \\leq 0, \\quad i=1,2,\\dots, m \\\\\n                        & & \\quad \\mat{A} \\vec{x} = \\vec{b}\n    \\end{eqnarray*}\n    \\normalsize\n    with $f_0, f_1, \\ldots, f_m$ being convex. \\\\[.3cm]\n\n    If there exists an $\\vec{x} \\in \\text{relint}~\\big\\{\\mathcal{D} = \\cap_{i=0}^m \\text{dom}(f_i) \\big\\}$ with\n    \\small\n    \\begin{align*}\n      & f_i(\\vec{x}) < 0, \\quad i=1,\\dots,m \\\\\n      & \\mat{A}\\vec{x} = \\vec{b} \n    \\end{align*}\n    then \\structure{strong duality} holds.\n  \\end{citeblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Refinement of Slater's Condition}\n\n  \\begin{citeblock}{Theorem}\n\n    Given a \\structure{\\emph{convex} primal optimization problem}. \\\\[.2cm]\n\n    If the first $k$ constraint functions $f_1, \\ldots, f_k$ are \\structure{\\emph{affine}}, and \\\\\n    if there exists an $\\vec{x} \\in \\text{relint}~\\mathcal{D}$ with\n    \\small\n    \\begin{displaymath}\n      \\renewcommand\\arraystretch{1.4}      \n      \\begin{array}{l l}\n        f_i(\\vec{x}) \\le 0, \\quad i=1,\\dots,k                   & \\text{\\footnotesize (affine constraints)}\\\\\n        f_i(\\vec{x}) <   0, \\quad i=k+1, \\ldots, m \\qquad \\quad & \\text{\\footnotesize (convex constraints)}\\\\\n        \\mat{A}\\vec{x} = \\vec{b} & \\\\\n      \\end{array}\n    \\end{displaymath}\n    then \\structure{strong duality} holds.\n  \\end{citeblock}\n  \\pause\n\n  \\vspace{.3cm} \n  \\structure{Note:} the refined Slater's condition reduces to \\structure{feasibility} when the constraints are all linear equalities and inequalities, and $\\text{dom}(f_0)$ is open.  \n\\end{frame}\n\n\n\\subsection{KKT Optimality Conditions}\n\n\\begin{frame}\n  \\frametitle{Karush-Kuhn-Tucker Optimality Conditions}\n\n  Let $\\vec x^*$ be a primal and $(\\vec \\lambda^*, \\vec \\nu^*)$ dual optimal points with zero duality gap. \\\\[.3cm]\n\n  For the primal optimal point $\\vec x^*$, the gradient with respect to $\\vec x$ of $L(\\vec x, \\vec \\lambda^*, \\vec \\nu^*)$ is \\vec{0}:\n \n  \\begin{displaymath}\n    \\nabla L(\\vec x^*, \\vec \\lambda^*, \\vec \\nu^*) = \n    \\nabla f_0(\\vec{x}^*) + \n    \\sum_{i=1}^m \\lambda_i^* \\nabla f_i(\\vec{x}^*) + \n    \\sum_{i=1}^p \\nu_i^* \\nabla h_i(\\vec{x}^*) = \n    \\vec{0}\n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Karush-Kuhn-Tucker Optimality Conditions}\n  \n  The following four conditions are called KKT conditions: \\\\[3mm] \\pause\n  \n  \\begin{enumerate}\n    \\item \\structure{Primal constraints:} \n      \\begin{itemize}\n        \\item $f_i(\\vec{x}) \\leq 0, \\quad i = 1, 2, \\dots, m$\n        \\item $h_i(\\vec{x}) =    0, \\quad i = 1, 2, \\dots, p$ \\\\[3mm] \\pause\n      \\end{itemize}\n    \\item \\structure{Dual constraints:} $\\vec \\lambda \\succeq 0$ \\\\[3mm] \\pause\n    \\item \\structure{Complementary slackness:} $ \\lambda_i \\, f_i(\\vec{x})= 0$ \\\\[3mm] \\pause\n    \\item \\structure{Gradient of the Lagrangian $L$ is zero:}\n      \\begin{displaymath}\n        \\nabla L(\\vec x, \\vec \\lambda, \\vec \\nu) = \n        \\nabla f_0(\\vec{x}) + \n        \\sum_{i=1}^m\\lambda_i \\nabla f_i(\\vec{x}) +        \n        \\sum_{i=1}^p\\nu_i \\nabla h_i(\\vec{x}) = \n        \\vec{0}\n      \\end{displaymath}\n  \\end{enumerate}\n   \\pause\n    \n   If strong duality holds and if $\\vec x^*$ and $(\\vec \\lambda^*, \\vec \\nu^*)$ are optimal points, \\\\\n   then the KKT conditions hold.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Karush-Kuhn-Tucker Optimality Conditions}\n\n  \\alt<15->{\n    \\structure{Complementary slackness:} {\\color{gr3} $\\lambda_i^* \\cdot f_i(\\vec{x}^*) = 0$}\n  }{\n    \\structure{Complementary slackness}\n  }\n \n  \\def\\phan{\\phantom{\\stackrel{\\color{red} =}{\\cancel{\\color{black} \\le}}}}\n\n  \\begin{eqnarray*}\n    \\alt<10->{ \n      \\tikz[baseline]{ \n        \\node[fill=bl1,anchor=base,rounded corners=2pt] (start) {\n          \\color{bl3} $ f_0(\\vec{x}^*) $\n        };\n      }\n    }{\n      \\tikz[baseline]{ \n        \\node[fill=white,anchor=base,rounded corners=2pt] (res) {\n          \\color{black} $ f_0(\\vec{x}^*) $\n        };\n      }\n    }\n    \\pause\n      & = & g(\\vec{\\lambda}^*, \\vec{\\nu}^*) \\\\ \\pause\n      & = & \\inf_{\\vec{x}} \\Bigg( f_0(\\vec{x}) + \\sum_{i=1}^m \\lambda_i^*  f_i(\\vec{x}) + \\sum_{i=1}^p \\nu_i^* h_i(\\vec{x}) \\Bigg) \\\\ \\pause\n      \\alt<12->{\n        & \\stackrel{\\color{red} =}{\\cancel{\\color{black} \\le}} &  \n      }{\n        &\\le& \n      }\n        f_0(\\vec{x}^*) + \n        \\alt<15>{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=gr1,anchor=base,rounded corners=2pt] (c1) {\n              \\color{gr3} $ \\displaystyle \\sum_{i=1}^m $ \n              \\tikz \\node[fill=white,anchor=base, rounded corners=2pt] (cs) {\\color{gr3} $ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.35cm}, decorate, color=gr3] (cs.west) -- node[pos=0.5,xshift=0mm,yshift=-5.5mm]  {\n              \\tiny $= 0$\n            } (cs.east);  \n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=black] (c1.west) -- node[pos=0.5,xshift=.4mm,yshift=-1.1cm]  {\n              \\scriptsize $\\stackrel{\\color{red}=}{\\cancel{\\color{black}\\le}} 0$\n            } (c1.east);  \n          }\n        }{\\alt<14>{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=gr1,anchor=base,rounded corners=2pt] (c1) {\n              \\color{gr3} $ \\displaystyle \\sum_{i=1}^m $ \n              \\tikz \\node[anchor=base, rounded corners=2pt] (cs) {\\color{gr3} $ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=black] (c1.west) -- node[pos=0.5,xshift=.4mm,yshift=-1.1cm]  {\n              \\scriptsize $\\stackrel{\\color{red}=}{\\cancel{\\color{black}\\le}} 0$\n            } (c1.east);  \n          }\n        }{\\alt<13>{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=white,anchor=base,rounded corners=2pt] (c1) {\n              $ \\displaystyle \\sum_{i=1}^m $\n              \\tikz \\node[anchor=base, rounded corners=2pt] (cs) {$ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=black] (c1.west) -- node[pos=0.5,xshift=.4mm,yshift=-1.1cm]  {\n              \\scriptsize $\\stackrel{\\color{red}=}{\\cancel{\\color{black}\\le}} 0$\n            } (c1.east);  \n          }\n        }{\\alt<9->{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=white,anchor=base,rounded corners=2pt] (c1) {\n              $ \\displaystyle \\sum_{i=1}^m$\n              \\tikz \\node[anchor=base, rounded corners=2pt] (cs) {$ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=black] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize $\\phan\\le 0\\phan$} (c1.east);  \n          }\n        }{\\alt<8>{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=bl1,anchor=base,rounded corners=2pt] (c1) {\n              \\color{bl3} $ \\displaystyle \\sum_{i=1}^m$\n              \\tikz \\node[fill=bl1, anchor=base, rounded corners=2pt] (cs) {$ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=bl3] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize $\\phan\\le 0\\phan$} (c1.east);  \n          }\n        }{\\alt<7>{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=bl1,anchor=base,rounded corners=2pt] (c1) {\n              \\color{bl3} $ \\displaystyle \\sum_{i=1}^m$\n              \\tikz \\node[fill=bl1, anchor=base, rounded corners=2pt] (cs) {$ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=white] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize \\phantom{$\\le 0$}} (c1.east);  \n          }\n        }{\n          \\tikz[baseline,remember picture]{ \n            \\node[fill=white,anchor=base,rounded corners=2pt] (c1) {\n              \\color{black} $ \\displaystyle \\sum_{i=1}^m $\n              \\tikz \\node[anchor=base, rounded corners=2pt] (cs) {$ \\lambda_i^*  f_i(\\vec{x}^*) $};\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=white] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize \\phantom{$\\le 0$}} (c1.east);  \n          }\n        }}}}}}\n        + \n        \\alt<7->{\n          \\tikz[baseline]{ \n            \\node[fill=white,anchor=base,rounded corners=2pt] (c1) {\n              $ \\displaystyle \\sum_{i=1}^p \\nu_i^* h_i(\\vec{x}^*) $\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=black] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize $= 0$} (c1.east);  \n          }\n        }{\\alt<6->{\n          \\tikz[baseline]{ \n            \\node[fill=bl1!100,anchor=base,rounded corners=2pt] (c1) {\n              \\color{bl3} $ \\displaystyle \\sum_{i=1}^p \\nu_i^* h_i(\\vec{x}^*) $\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=bl3] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize $= 0$} (c1.east);  \n          }\n        }{\\alt<5>{\n          \\tikz[baseline]{ \n            \\node[fill=bl1!100,anchor=base,rounded corners=2pt] (c1) {\n              \\color{bl3} $ \\displaystyle \\sum_{i=1}^p \\nu_i^* h_i(\\vec{x}^*) $\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=white] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize \\phantom{$= 0$}} (c1.east);  \n          }\n        }{\n          \\tikz[baseline]{ \n            \\node[fill=white,anchor=base,rounded corners=2pt] (c1) {\n              \\color{black} $ \\displaystyle \\sum_{i=1}^p \\nu_i^* h_i(\\vec{x}^*) $\n            };\n            \\draw [thick, decoration={brace, mirror, raise=0.75cm}, decorate, color=white] (c1.west) -- node[pos=0.5,yshift=-1.1cm]  {\\scriptsize \\phantom{$= 0$}} (c1.east);  \n          }\n        }}} \\\\\n      \\alt<11->{\n        & \\stackrel{\\color{red} =}{\\cancel{\\color{black} \\le}} &  \n      }{\\alt<9->{\n        &\\le& \n      }{}}\n      \\alt<10->{ \n        \\tikz[baseline]{ \n          \\node[fill=bl1,anchor=base,rounded corners=2pt] (res) {\n            \\color{bl3} $ f_0(\\vec{x}^*) $\n          };\n        }\n      }{\\alt<9>{\n        \\tikz[baseline]{ \n          \\node[fill=white,anchor=base,rounded corners=2pt] (res) {\n            \\color{black} $ f_0(\\vec{x}^*) $\n          };\n        }\n      }{}} \n      \\phan\n  \\end{eqnarray*}\n\n  \\onslide<15>\n    \\hfill \\qed\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Karush-Kuhn-Tucker Optimality Conditions \\cont}\n\n  \\structure{Conclusions \\scriptsize ~(Boyd 2004, Sec. 5.5.3)}\n\n  \\begin{itemize}\n    \\item For \\structure{\\emph{any} optimization problem} with differentiable objective and constraint functions for which strong duality obtains, any pair of primal and dual optimal points must satisfy the KKT conditions. \\\\[.2cm] \\pause\n    \\item For \\structure{any \\emph{convex} optimization problem} with differentiable objective and and constraint functions, any points that satisfy the KKT conditions are primal and dual optimal, and have zero duality gap. \\\\[.2cm] \\pause\n    \\item If a \\structure{\\emph{convex} optimization problem} with differentiable objective and constraint functions satisfies Slater's condition, then the KKT conditions provide necessary and sufficient conditions for optimality.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Lessons Learned}\n\n\\begin{frame}\n  \\frametitle{Lessons Learned}\n  \n  \\begin{itemize}\n    \\item Formalization of the primal problem using the Lagrangian \\\\[.5cm]\n    \\item Lagrange dual function \\\\[.5cm]\n    \\item Duality gap \\\\[.5cm]\n    \\item Karush-Kuhn-Tucker optimality conditions\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 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 Lagrangian of a constrained objective function? \\\\[1cm]\n    \\item What is the Lagrange dual function? \\\\[1cm]\n    \\item What is the duality gap? \\\\[1cm]\n    \\item What are the Karush-Kuhn-Tucker optimality conditions?\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "cdd74dd0af53fe95c6ade32929266e7e93296353", "size": 19915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13_optimization_2.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": "13_optimization_2.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": "13_optimization_2.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": 35.8828828829, "max_line_length": 239, "alphanum_fraction": 0.5751443635, "num_tokens": 6853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587668, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6988370712565576}}
{"text": "\\section{Co-Synthesis of Encodings} \\label{sec:co-synthesis}\n%\nThe functions described in the previous section only makes\nsense in the context of a fixed encoding, but in general, a\ndata type accepts more than one.\n%\nAs encodings are just expressions we would like to\nautomatically derive them as a result of synthesis.\n%\nTo do so we first need to find a way to give an abstract\nspecification of the meaning of a data type and we need to\ndo it in a way that is independent of an underlying\nencoding.\n%\nIn the following, we see how we can extend the ideas\npresented in \\cref{sec:synthesis} to express these abstract\nspecifications in a natural way.\n\nIn general, our approach consist of specifying the behavior\nof data types in relation with the functions that operates\non them.\n%\nWe call this a \\emph{co-specification} of a data type and\nits functions.\n%\nWe also refer to the process of synthesizing an encoding\ntogether with the functions that operate on it as\n\\emph{co-synthesis}.\n\nOur next key insight is that we can build natural and\nconcise co-specifications by looking at the introduction and\nelimination forms of a data type.\n%\nConsider booleans for example.\n%\nTheir introduction corresponds to the values \\true and \\false\nand their elimination corresponds to case analysis using the\nif-then-else (\\f{ite}) function.\n%\nUsing the ideas presented in \\cref{sec:io} we can co-specify\n\\true, \\false and \\f{ite} as:\n%\n\\begin{align*}\n  \\f{?ite}\\;\\f{?true}\\;x\\;y &\\equiv x \\\\\n  \\f{?ite}\\;\\f{?false}\\;x\\;y &\\equiv y\n\\end{align*}\n\nThe co-specification for natural numbers requires a little\nbit more work.\n%\nFirst, we identify $0$ and \\f{succ} as the introduction\nforms of natural numbers in its usual inductive definition.\n%\nSecond, we note that the elimination form of natural numbers\ncorrespond to the ability of defining recursive functions on\nthem.\n%\nInstead of spelling out a general recursive principle we\nspecify the recursive behavior by picking a particular\nrecursive definition.\n%\nIn our case we specify the elimination form in terms of the\nrecursive definition of the function \\f{plus}.\n%\nWe can now co-specify $0$, \\f{succ} and \\f{plus} as:\n\\begin{align*}\n  \\f{?plus}\\;\\f{?}0\\;y &\\equiv y\\\\\n  \\f{?plus}\\;(\\f{?succ}\\;x)\\;y &\\equiv \\f{?succ}\\;(\\f{?plus}\\;x\\;y)\\\\\n\\end{align*}\n\nWe conclude by showing how these ideas also apply to\nnon-recursive data types by showing a co-specification for pairs.\n%\nThe introduction form corresponds to the constructor\n\\f{pair} and the elimination forms to the first and\nsecond projections.\n%\n\\begin{align*}\n  \\f{?first}\\;(\\f{?pair}\\;x\\;y) &\\equiv x\\\\\n  \\f{?second}\\;(\\f{?pair}\\;x\\;y) &\\equiv y\\\\\n\\end{align*}\n", "meta": {"hexsha": "1cf689804181c5b02e23c223415975a58e153e61", "size": 2648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/co-synthesis.tex", "max_stars_repo_name": "DavidThien/elsa", "max_stars_repo_head_hexsha": "2bf97839d1fc210d12dac919b34ec4e0143f80e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/co-synthesis.tex", "max_issues_repo_name": "DavidThien/elsa", "max_issues_repo_head_hexsha": "2bf97839d1fc210d12dac919b34ec4e0143f80e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/co-synthesis.tex", "max_forks_repo_name": "DavidThien/elsa", "max_forks_repo_head_hexsha": "2bf97839d1fc210d12dac919b34ec4e0143f80e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2926829268, "max_line_length": 69, "alphanum_fraction": 0.7454682779, "num_tokens": 734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579722, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.698837059452375}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage{dsfont}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{geometry}\n\\geometry{a4paper}\n\\usepackage[parfill]{parskip}\n\\usepackage{graphicx}\n\\usepackage{epstopdf}\n\\usepackage{listings}\n\\lstset{language = C++}\n\\usepackage{url}\n\n\\newcommand{\\re}[1]{\\ensuremath{\\operatorname{Re}(#1)}}\n\\newcommand{\\im}[1]{\\ensuremath{\\operatorname{Im}(#1)}}\n\n%\\newcommand{\\Vr}{\\re{V}}\n%\\newcommand{\\Vi}{\\im{V}}\n%\\newcommand{\\Ir}{\\re{I}}\n%\\newcommand{\\Ii}{\\im{I}}\n%\\newcommand{\\Sr}{\\ensuremath{P}}\n%\\newcommand{\\Si}{\\ensuremath{Q}}\n\n\\newcommand{\\Vr}{{V_R}}\n\\newcommand{\\Vi}{{V_I}}\n\\newcommand{\\Ir}{{I_R}}\n\\newcommand{\\Ii}{{I_I}}\n\\newcommand{\\Sr}{\\ensuremath{P}}\n\\newcommand{\\Si}{\\ensuremath{Q}}\n\n\\newcommand{\\Id}{\\mathds{1}}\n\n\\title{Power Flow Theory}\n\\author{Dan Gordon}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\section{Nomenclature}\n\\begin{align*}\nV &= \\Vr + \\Vi = \\text{complex voltage.} \\\\\nI &= \\Ir + j\\Ii = \\text{complex current.} \\\\\nS &= P + jQ = \\text{complex power.} \\\\\ny &= g + jb = \\text{complex admittance} \\\\\nZ &= R + jX = \\text{complex impedance} \\\\\ny_{ik} &= \\text{complex admittance between buses $i$ and $k$.} \\\\\nY_{ik} &= G_{ik} + jB_{ik} = \\text{nodal admittance matrix element $i, k$.} \\\\\n\\theta_{i} &= \\text{the voltage angle of bus $i$.} \\\\\n\\theta_{ik} &= \\theta_i - \\theta_k = \\text{the voltage angle difference between buses $i$ and $k$.} \\\\\nI_{\\text{ZIP},i} &= \\text{total complex current injection from load at bus $i$.} \\\\\nI_{\\text{gen},i} &= \\text{complex current injection due to the voltage controlled generation at bus $i$.} \\\\\nS_{\\text{gen},i} &= \\text{complex power injection due to the voltage controlled generation at bus $i$.} \\\\\nS_{ci} &= \\text{constant power injection ZIP component of load at bus $i$.} \\\\\nI_{ci} &= \\text{constant current injection ZIP component of load.} \\\\\ny_{ci} &= \\text{constant impedance ZIP component of load.} \\\\\n\\delta_{ik} &= \\text{the Kronecker delta, $\\delta_{ik} = 1$ if $i = k$, 0 otherwise.}\n\\end{align*}\n\n\\section{AC power}\nFor AC power, we can write $V(t) = V_\\text{max} \\cos(\\theta_V + \\omega t)$ and $I(t) = I_\\text{max} \\cos(\\theta_I + \\omega t)$, where $V_\\text{max}$ and $I_\\text{max}$ are the maximum power and voltage over a cycle. However, it is more usual to use RMS quantities $V_\\text{RMS} = V_\\text{max}/\\sqrt{2}$ and $I_\\text{RMS} = I_\\text{max}/\\sqrt{2}$, because the average power over a cycle then mimics the usual relationships such as $P = V^2/R$\\footnote{For a resistive load, the average power over a cycle works out to be $P_\\text{avg} = I_\\text{RMS}V_\\text{RMS}$, replicating the usual relationship for DC power. If we used the maximum rather than RMS values of $V$ and $I$, then this relationship would have an extra factor of 1/2. All the other usual DC relationships also hold for the RMS values, such as $V_\\text{RMS} = I_\\text{RMS}R$. We are not often concerned with knowing the instantaneous voltage and current, so the factors of $\\sqrt{2}$ in Eq. \\ref{EQ_V_I_RMS} are not too inconvenient.}, so,\n\\begin{align}\n\tV(t) &= \\sqrt{2}V_\\text{RMS} \\cos(\\theta_V + \\omega t), \\notag \\\\\n\tI(t) &= \\sqrt{2}I_\\text{RMS} \\cos(\\theta_I + \\omega t)\n\t\\label{EQ_V_I_RMS}\n\\end{align}\n\nIt is convenient to use the complex phasor notation $V := V_\\text{RMS} \\exp(j\\theta_V), \\, I := I_\\text{RMS} \\exp(j\\theta_I)$, which allows us to unambiguously code the voltage magnitude and phase shift in a single complex number. If we ever need to recover, for example, the instantaneous voltage, we can use\n\\begin{align}\n\tV(t) = \\sqrt{2}\\re{V \\exp(j\\omega t)}\n\\end{align}\n\nThe instantaneous power is\n\\begin{align}\n\tP(t) &= 2I_\\text{RMS}V_\\text{RMS}\\cos(\\theta_I + \\omega t)\\cos(\\theta_V + \\omega t) \\notag \\\\\n\t     &= I_\\text{RMS}V_\\text{RMS}\\left[\\cos(\\theta_V - \\theta_I) + \\cos(\\theta_V + \\theta_I + 2 \\omega t)\\right] \\notag \\\\\n\t\t &= \\re{I^*V + IV\\exp(2j \\omega t)}\n\\end{align}\nThis inspires us to define the instantaneous complex power,\n\\begin{align}\n\tS(t) &= I^*V + IV\\exp(2j \\omega t)\n\\end{align}\nwhose average over a cycle is\n\\begin{align}\n\tS &= I^*V,\n\\end{align}\nWe define the real power and reactive power phasors to be \n\\begin{align}\n\tP := \\re{S} = I_\\text{RMS}V_\\text{RMS}\\cos(\\theta_V - \\theta_I), \\notag \\\\\n\tQ := \\im{S} = I_\\text{RMS}V_\\text{RMS}\\sin(\\theta_V - \\theta_I)\n\\end{align}\nwhich shows that $P$ and $Q$ are ``in phase'' and ``out of phase'' components of the product of $I$ and $V$. $P$ is just the average power dissipated by the resistive component of the load, while $Q$ is the magnitude of the instantaneous power absorbed by the reactive part of the load.\n\n\\subsection{Reactive power, voltage and line losses}\nThe loss of real power over a section of transmission line is given by\n\\begin{align}\n\tP_\\text{loss} &= \\left|I\\right|^2 R\n\\end{align}\nWe can express $I$ as a function of the voltage and power injection to the downstream (or upstream) bus, e.g.\n\\begin{align}\n\tI &= \\frac{S^*_\\text{out}}{V^*_\\text{out}}\n\\end{align}\nTherefore, we have\n\\begin{align}\n\tP_\\text{loss} &= \\frac{\\left|S_\\text{out}\\right|^2}{\\left|V_\\text{out}\\right|^2}R\n\\end{align}\n\nThis equation explains, firstly, why transmission lines are more efficient at high voltage (because, e.g. doubling the voltage means the line loss is reduced by a factor of four), and secondly, why utilities are keen to reduce the reactive power flowing through lines (because doubling the reactive power multiplies the line losses by four). Line losses are bad for three reasons: they are a waste of energy, they correspond to dissipated heat and therefore thermal limits, and they also correspond to voltage drops in the line.\n\nWe have\n\\begin{align}\n\t\\left|\\frac{V_\\text{out}}{V_\\text{in}}\\right|^2 &= \\left|\\frac{V_\\text{in} - IZ}{V_\\text{in}}\\right|^2 \\notag \\\\\n\t&= \\left|1 - \\frac{S^*_\\text{in}Z}{\\left|V_\\text{in}\\right|^2}\\right|^2 \\notag \\\\\n\t&= 1 - \\frac{2(PR + QX)}{\\left|V_\\text{in}\\right|^2} + \\frac{\\left|S\\right|^2\\left|Z\\right|^2}{\\left|V_\\text{in}\\right|^4}\n\\end{align}\nAt high voltages, the middle term in the sum dominates the voltage drop. High voltage lines normally also have a larger reactance than resistance, and in such cases we see that reactive power is a more significant contributor to the voltage drop than is real power.\n\\section{Three phase balanced power}\nIn balanced positive sequence three-phase systems, the phase to neutral voltages (or, simply, the phase voltages), at a bus, are \n\\begin{align}\n(V_A, V_B, V_C) = (V_A, V_A\\exp(-j2\\pi/3), V_A\\exp(j2\\pi/3)).\n\\end{align}\nThe line to line voltages, also just called the line voltages, are \n\\begin{align}\n(V_{AB}, V_{BC}, V_{CA}) &= (V_A - V_B, V_B - V_C, V_C - V_A) \\notag \\\\\n&= \\sqrt{3}\\exp(j\\pi/6)(V_A, V_B, V_C).\n\\end{align}\nThus, the line to line voltages have a magnitude $\\sqrt{3}$ times that of the phase voltages, and they also form a positive sequence set.\n\nLoads and sources can be connected in either $\\Delta$ or $Y$ configuration. Fig. \\ref{FIG_YY_DD} shows these connections.\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[width=(12cm)]{YSrcYLd.png}\n\t\t\\includegraphics[width=(12cm)]{DSrcDLd.png}\n\t\\end{center}\n\t\\caption{\n\t\tTop: A Y-connected source connected to a Y-connected load. Bottom: A $\\Delta$-connected source connected to a $\\Delta$-connected load.\n\t}\n\t\\label{FIG_YY_DD}\n\\end{figure}\n\nThe currents along the phase wires, $I_A, I_B, I_C$ are known as the ``line currents''. Note that this can be confusing when compared to the use of ``line voltage'' to mean line to line voltage.\n\nFor a $\\Delta$-connected load or source operating under balanced positive sequence conditions, we can easily show, using Ohm's law, that $I_{BC} = \\exp(-j2\\pi/3) I_{AB}$ and $I_{CA} = \\exp(j2\\pi/3) I_{AB}$, i.e. the delta currents also form a positive sequence set. Kirchoff's current law can then be used to show that,\n\\begin{align}\n(I_{AB}, I_{BC}, I_{CA}) &= \\frac{1}{\\sqrt{3}}\\exp\\left(j\\pi/6\\right)(I_A, I_B, I_C)\n\\end{align}\nmeaning the $\\Delta$ currents are a factor of $\\sqrt{3}$ less than the line currents. Note that this is opposite to the relationship that holds for phase voltages vs line to line voltages.\n\nNote that for every $\\Delta$ connected load, there is an equivalent $Y$-connected load. For balanced power flow, if the impedance on each arm of the $Y$ is $Z_Y$, then the equivalent impedance for each side of the $\\Delta$ is $Z_\\Delta = 3Z_Y$.\n\n\\section{Symmetric components}\nLet \n\\begin{align}\n\tA &= \\left[\n\t\t\\begin{array}{lll}\n\t\t\t1 & 1 & 1 \\\\\n\t\t\t1 & \\alpha^2 & \\alpha \\\\\n\t\t\t1 & \\alpha & \\alpha^2\n\t\t\\end{array}\n\t\\right],\\;\n\tA^{-1} = \\frac{1}{3}\\left[\n\t\t\\begin{array}{lll}\n\t\t\t1 & 1 & 1 \\\\\n\t\t\t1 & \\alpha & \\alpha^2 \\\\\n\t\t\t1 & \\alpha^2 & \\alpha\n\t\t\\end{array}\n\t\\right]\n\\end{align}\nwhere $\\alpha := \\exp(j2\\pi/3)$.\n\nWe define a transformation to symmetric components:\n\\begin{align}\n\tV_{012} = A^{-1}V_{ABC}\n\\end{align}\nwhich applies for all vectors e.g. to $I$ as well as $V$, and\n\\begin{align}\n\tZ_{012} = A^{-1}Z_{ABC}A\n\\end{align}\nwhich applies for matrices, for example, impedance matrices $Z$, as shown above.\n\nSuppose we have a balanced positive sequence voltage $V^+_{ABC} = V_A[1, \\alpha^2, \\alpha]^T$. Then, under the transformation to symmetric components, we find $V_{012} = V_A[0, 1, 0]^T$. Similarly, a negative sequence voltage $V^-_{ABC} = V_A[1, \\alpha, \\alpha^2]^T$ transforms to $V_{012} = V_A[0, 0, 1]^T$. Finally, the unbalanced \\emph{zero sequence} voltage $V^-_{ABC} = V_A[1, 1, 1]^T$ transforms to $V_{012} = V_A[1, 0, 0]^T$. Therefore, the transformation $A^{-1}$ decomposes $V_{ABC}$ into a positive sequence component $V_1$, a negative sequence component $V_2$, and a zero sequence component $V_0$. In summary:\n\\begin{align}\nV_{ABC}^+ = V_A\\left[\\begin{array}{l} \n\t1 \\\\ \\alpha^2 \\\\ \\alpha \n\\end{array}\\right] &\\Longleftrightarrow \nV_{012}^+ = V_A\\left[\\begin{array}{l} \n\t0 \\\\ 1 \\\\ 0\n\\end{array}\\right] & \\text{(positive sequence voltage)}\\notag \\\\\nV_{ABC}^- = V_A\\left[\\begin{array}{l} \n\t1 \\\\ \\alpha \\\\ \\alpha^2\n\\end{array}\\right] &\\Longleftrightarrow \nV_{012}^- = V_A\\left[\\begin{array}{l} \n\t0 \\\\ 0 \\\\ 1\n\\end{array}\\right] & \\text{(negative sequence voltage)}\\notag \\\\\nV_{ABC}^0 = V_A\\left[\\begin{array}{l} \n\t1 \\\\ 1 \\\\ 1\n\\end{array}\\right] &\\Longleftrightarrow \nV_{012}^0 = V_A\\left[\\begin{array}{l} \n\t1 \\\\ 0 \\\\ 0\n\\end{array}\\right] & \\text{(zero sequence voltage)}\\notag \\\\\n\\end{align}\n\n\\subsection{Reduction of a three-phase balanced problem to single phase}\n\nIn balanced power flow, there is only a positive sequence component, which suggests that symmetric components could be used to reduce a three-phase problem to an equivalent single-phase problem, since the negative and zero sequence components will always be zero. However, using the treatment above, it turns out that we then need to remember to multiply by an extra factor of three when calculating the total power. This is not ideal, because total power is an important physical quantity that corresponds to the amount of actual energy consumed or generated. Therefore, we shall develop a non-standard treatment of symmetric components.\n\nLet the scaled sequence transformation matrix $B$ be defined as\n\\begin{align}\n\tB := \\frac{1}{\\sqrt{3}}A &= \\frac{1}{\\sqrt{3}}\\left[\n\t\t\\begin{array}{lll}\n\t\t\t1 & 1 & 1 \\\\\n\t\t\t1 & \\alpha^2 & \\alpha \\\\\n\t\t\t1 & \\alpha & \\alpha^2\n\t\t\\end{array}\t\\right], \\notag \\\\\n\tB^{-1} := \\sqrt{3} A^{-1} &=\\frac{1}{\\sqrt{3}}\\left[\n\t\t\\begin{array}{lll}\n\t\t\t1 & 1 & 1 \\\\\n\t\t\t1 & \\alpha & \\alpha^2 \\\\\n\t\t\t1 & \\alpha^2 & \\alpha\n\t\t\\end{array} \\right]\n\\end{align}\nNote that $B^{-1} = B^\\dag$, so $B$ is a unitary matrix\\footnote{$B$ being unitary implies that the transformation that it describes will have nice properties like preserving scalar (dot) products. The total power, $S$, is a scalar product: $S = I^\\dag V$, so this transformation preserves the value obtained for the total power.}. The transformation to scaled symmetric components is:\n\\begin{align}\n\tV_{012'} &= B^{-1}V_{ABC} \\notag \\\\\n\tZ_{012'} &= B^{-1}Z_{ABC}B\n\\end{align}\n\nUnder this transformation, positive, negative and zero sequence voltages transform as follows\n\\begin{align}\nV_{ABC}^+ = V_A\\left[\\begin{array}{l} \n\t1 \\\\ \\alpha^2 \\\\ \\alpha \n\\end{array}\\right] &\\Longleftrightarrow \nV_{012'}^+ = \\sqrt{3}V_A\\left[\\begin{array}{l} \n\t0 \\\\ 1 \\\\ 0\n\\end{array}\\right] & \\text{(positive sequence voltage)}\\notag \\\\\nV_{ABC}^- = V_A\\left[\\begin{array}{l} \n\t1 \\\\ \\alpha \\\\ \\alpha^2\n\\end{array}\\right] &\\Longleftrightarrow \nV_{012'}^- = \\sqrt{3}V_A\\left[\\begin{array}{l} \n\t0 \\\\ 0 \\\\ 1\n\\end{array}\\right] & \\text{(negative sequence voltage)}\\notag \\\\\nV_{ABC}^0 = V_A\\left[\\begin{array}{l} \n\t1 \\\\ 1 \\\\ 1\n\\end{array}\\right] &\\Longleftrightarrow \nV_{012'}^0 = \\sqrt{3}V_A\\left[\\begin{array}{l} \n\t1 \\\\ 0 \\\\ 0\n\\end{array}\\right] & \\text{(zero sequence voltage)}\\notag \\\\\n\\end{align}\nSo for example, a positive sequence balanced three phase voltage will have a single nonzero sequence component, the positive sequence component $V_1 = \\sqrt{3}V_A$, with magnitude equal to the line voltage. A similar relationship holds for the line currents: a positive sequence balanced three phase current will have $I_1 = \\sqrt{3}I_A$, however, this time, there is no simple interpretation of $\\sqrt{3}I_A$ that is analogous to $\\sqrt{3}V_A$ being the line to line voltage.\n\nNow consider a three phase transmission line. The equation for the voltage drop in each wire is:\n\\begin{align}\n\t\\Delta V = ZI\n\\end{align}\nwhere $Z$ is the phase impedance matrix for the line. If the power flow is to be perfectly balanced, then there must be a symmetry under exchange of any two phases, meaning all wires must either be equidistant from each other, or else transposed\\footnote{Line transposition occurs in transmission systems, where the physical locations of the phases on the poles on are interchanged at regular intervals, so for example the lines are arranged as ABC--BCA--CAB.}, and must have equal impedances and symmetrical mutual impedances. $Z$ must therefore have the form:\n\\begin{align}\n\tZ_{ABC} = \\left[\n\t\t\t\\begin{array}{lll}\n\t\t\t\tz & m & m \\\\\n\t\t\t\tm & z & m \\\\\n\t\t\t\tm & m & z\n\t\t\t\\end{array}\n\t\t\\right]\n\t\t\\label{EQ_ZABC}\n\\end{align}\nwhere $z$ is the single line impedance, and $m$ is the mutual coupling impedance. Under the transformation to scaled symmetric components, this becomes\n\\begin{align}\n\tZ_{012} = \\left[\n\t\t\t\\begin{array}{lll}\n\t\t\t\tz+2m & 0 & 0 \\\\\n\t\t\t\t0 & z-m & 0 \\\\\n\t\t\t\t0 & 0 & z-m\n\t\t\t\\end{array}\n\t\t\\right]\n\t\t\\label{EQ_Z012}\n\\end{align}\nThis matrix is diagonal, which confirms that a perfectly symmetric network can be decomposed into three independent networks: a positive sequence network, a negative sequence network, and a zero sequence network. Note also that the positive and negative sequences are equal. In balanced power flow, a single positive sequence impedance only needs to be specified for normal operation, whereas the zero-sequence impedance needs to be additionally specified for unbalanced conditions such as non-symmetric faults. Shunt impedances or loads can be represented in a similar manner, but have $m = 0$. $\\Delta$ connected shunt impedances or loads can be treated using the equivalent $Y$ impedance: each impedance in the $\\Delta$ load must be divided by 3 to get the equivalent $Y$-impedance.\n\nIn summary, we can model a balanced three phase power problem as a single phase problem by making the following interpretations:\n\\begin{itemize}\n\t\\item The voltage in the equivalent single phase system is the line to line voltage in the three phase system (but, to be pedantic, with the same angle as A). To get the phase A voltage, divide the single phase voltage by $\\sqrt{3}$.\n\t\\item To get the current along each phase of a three phase line, divide the single phase current by $\\sqrt{3}$. This is most important when considering line limits.\n\t\\item Power in the equivalent single phase system is the \\emph{total} power of all phases in the three phase system. Thus, for example, the power at an equivalent single phase $PQ$ bus is the sum of the power for all phases in the three phase system. This is regardless of whether the load or source is $\\Delta$ or $Y$-connected.\n\t\\item Three-phase lines represented as in Eq. \\ref{EQ_ZABC} have an equivalent single phase impedance of $z - m$.\n\t\\item A Y-connected load/shunt impedance, with impedance $z$ on each phase, becomes a single impedance $z$ in the equivalent single phase system.\n\t\\item A $\\Delta$-connected load/shunt impedance, with impedance $z$ between each pair of phases, becomes a single load impedance $z/3$ in the equivalent single phase system.\n\t\n\\end{itemize}\n\n\\section{The powerflow problem}\n\nWe start with a collection \\emph{buses} -- terminal-like conductors that have a single associated voltage, $V_i$, where $i$ is the bus index. We can consider \\emph{ground} to be a special bus (to which we assign index 0), at which $V$ is always zero.\n\nCurrent can flow between buses, via the network. The current flowing from bus $i$ to $k$ is $I_{ik}$. \n\nCurrent that flows into a bus from ground is an \\emph{injection} into the bus. We use the notation $I_{\\text{inj},i}$ to denote a current injection from ground to bus $i$. The generated power is $S_{\\text{inj}, i} = I_{\\text{inj}, i}^*(V_i - V_i)$. The generated power -- that is, the power \\emph{injection} into the bus -- is the negative of this: $S_{\\text{inj},i} := I_{\\text{inj},i}^*V_i$.\n\n\\emph{Kirchoff's current law} states that the total current flowing into a bus (from other buses and ground) is zero -- in other words, current in equals current out; electrical charges don't accumulate at buses. Thus\n\\begin{align}\n\tI_{i} - \\sum_{k \\ne i}{I_{ik}} &= 0\n\t\\label{EQ_KCL}\n\\end{align}\n\nThe aim of the powerflow problem is, essentially, to find all bus voltages and currents\\footnote{This will also trivially allow us to calculate power flows in the system -- we will discuss this later.}. To do so, we need to define the properties of the network to provide a functional relationship between current and voltage at the buses. We start with a simple formulation, where the current flow between any two buses is ohmic: it is defined by a fixed impedance between them. This describes a network of passive \\emph{lines}. Later we will generalise this relationship, so that, for example, we can include transformers.\n\nSuppose that $y_{ik} = y_{ki}$ is an impedance between buses $i$ and $k$. Then Ohm's law states that\n\\begin{align}\n\tI_{ik} &= y_{ik}(V_i - V_k)\n\\end{align}\nSubstituting this into KCL, Eq. (\\ref{EQ_KCL}), gives\n\\begin{align}\n\tI_{\\text{inj},i} - \\sum_{k \\ne i}{y_{ik}(V_i - V_k)} &= 0\n\t\\label{EQ_PF_1}\n\\end{align}\nwhich can be written as the matrix equation\n\\begin{align}\n\tI_\\text{inj} - YV &= 0\n\\end{align}\nwhere\n\\begin{align}\n\tY_{ik} &=\n\t\t\\begin{cases}\n\t\t\t-y_{ik}&\\text{if $i \\ne k$} \\\\\n\t\t\t\\sum_{l \\ne i} y_{il}& \\text{if $i = k$}\n\t\t\\end{cases}\n\t\\label{EQ_YNODE_OHMIC}\n\\end{align}\nHowever, in what follows, we do not make further use of the particular form of $Y$ expressed in Eq. (\\ref{EQ_YNODE_OHMIC}) above. We simply require that $Y$ be a constant matrix, so that there is a linear relationship between $I$ and $V$. We shall see later that including components such as shunts and transformers allows us to retain the linear relationship while modifying the particular form of $Y$.\n\nDue to the basic relation $S = I^*V$, the power loss between bus $i$ and $k$ is $S_{ik} = I_{ik}^*(V_i - V_k)$. Note that power is a scalar: if we reverse the order of the buses, then the power loss is unchanged, in contrast to, say, a current, where reversing the order of the buses will negate the current.\n\nMore commonly, though, we deal with the power entering or leaving a bus rather than the power lost in a line. Consider a current leaving a bus. If the current is a draw to ground, or if the system is radial and the current is in the direction of the downstream loads, all of this current will eventually end up at ground. The voltage drop in this process will just be the voltage of the bus. Thus, the power eventually transferred to ground will be \n\\begin{align}\n\tS_\\text{draw} = I_\\text{draw}^*V_\\text{bus}\n\\end{align}\nor, equivalently, for injections\n\\begin{align}\n\tS_\\text{inj} = I_\\text{inj}^*V_\\text{bus}\n\\end{align}\nNote the way in which this concept of power is different to the concept of power loss in a line: the voltage in the equation is always the voltage of a bus relative to ground, and the current is always an injection or draw on a bus (rather than between two buses). There is an implied directionality: if the power draw from a bus is positive, then power is considered to be flowing from the bus to ground and we have a load.\n\nThe one piece of the puzzle we haven't yet dealt with is the current injections $I_\\text{inj}$ into the buses. If the current injections were all constant, then the powerflow equations could be immediately solved by standard linear algebra. However, typically, the current injections from ground will depend on the bus voltage, and it is here that the real complexity of powerflow modelling comes into play.\n\nCurrent injections take the form of \\emph{loads} or \\emph{generation}. Load currents can often be modeled using the \\emph{ZIP} model:\n\\begin{align}\n\tI_\\text{ZIP} = \\frac{I_cV}{|V|} + \\frac{S^*_c}{V^*} - y_cV\n\\end{align}\nWhere $I_\\text{ZIP}$ is the total current injection of the ZIP, $I_c$ and $S_c$ are constant current\\footnote{Note the expression $I_cV/|V|$ for the constant current component. The voltage dependence ensures that the complex power $S$ does not depend on the absolute phase of the voltage. Instead we have $S = I^*_c |V|$, which is much more reasonable for realistic devices.} and power injections and $y_c$ is a constant impedance. The ZIP model is a good model for many types of load, but could also be used for certain types of generation - e.g. fixed power generation. If the real power injection $P = \\re{I_\\text{ZIP}^*V}$ is negative, then we have a load; if it is positive, then we have a generator.\n\nIn addition to the ZIP loads at a bus, we may include generators that apply some kind of extra voltage control on the bus to maintain power stability in the system. A bus that only has a ZIP load is termed a PQ bus. The term PQ means constant P, constant Q.\\footnote{Confusingly, though, the presence of fixed current and fixed impedance components of the ZIP means that the total power injection may not be constant. This confusion arises because ZIP loads provide a generalisation to the original concept of PQ buses.}\n\nWe consider two other types of generator bus: SL (slack/swing/infinite/reference) buses, and PV buses. SL generators keep the total complex voltage of the bus fixed by injecting variable $P$ and $Q$. $PV$ buses keep the voltage magnitude $V$ and power $P$ fixed, while injecting a variable current\\footnote{Note that the voltage angle is relative to the slack bus, and so is a non-local property of the network, hence it usually does not make sense to control it anywhere except at the slack bus.}. We write the additional generator current as a power $S_{gen}$ to simplify the later analysis.\n\\begin{align}\nI_{gen} &= \\frac{S_{gen}^*}{V^*}\n\\end{align}\nNote that SL and PV buses may also have ZIP loads attached.\n\nWe now write the final form of the powerflow equations:\n\\begin{align}\nI_{\\text{inj},i} &= \\frac{S^*_{ci} + S^*_{\\text{gen},i}}{V^*_i} + \\frac{I_{ci}V_i}{|V_i|} - y_{ci}V_i - \\sum_{k=0}^NY_{ik}V_k = 0\n\\label{EQ_POWERFLOW_COMPLEX}\n\\end{align}\nThe term $-y_{ci}V_i$ may in practice be absorbed into $Y$ by adding $y_{ci}$ to $Y_{ii}$; we retain it here as an explicit bus shunt for bookkeeping purposes.\n\nReal and imaginary components are:\n\\begin{align}\n\t\\Ir_i &= \\frac{(P_{ci} + P_{\\text{gen},i})\\Vr_i + (Q_{ci} + Q_{\\text{gen},i})\\Vi_i}{|V|^2_i} \\notag \\\\\n\t      &+ \\frac{\\Ir_{ci}\\Vr_{i} - \\Ii_{ci}\\Vi_i}{|V_i|} -g_{ci}\\Vr_i + b_{ci}\\Vi_i \\notag \\\\\n\t      &+ \\sum_{k=0}^N\\left(-G_{ik}\\Vr_k + B_{ik}\\Vi_k\\right) = 0\\\\\n\t\\Ii_i &= \\frac{(P_{ci} + P_{\\text{gen},i})\\Vi_i - (Q_{ci} + Q_{\\text{gen},i})\\Vr_i}{|V|^2_i} \\notag \\\\\n\t      &+ \\frac{\\Ir_{ci}\\Vi_{i} + \\Ii_{ci}\\Vr_{i}}{|V_i|} -g_{ci}\\Vi_i - b_{ci}\\Vr_i \\notag \\\\\n\t&+ \\sum_{k=0}^N\\left(-G_{ik}\\Vi_k - B_{ik}\\Vr_k\\right) = 0\n\\end{align}\n\nThe possible unknowns are the generator power $P_\\text{gen}, Q_\\text{gen}$ and the voltages $\\Vr, \\Vi$.\n\n\\subsection{PQ buses}\nFor PQ buses, there is no additional (non-ZIP) generation, and hence $S_{\\text{gen}}$ can be set to zero. The unknown variables are the components of $V$.\n\\subsection{Slack buses}\nFor SL buses, $V$ is constant and the power flow equations give an explicit expression for $S$. All quantities at slack buses can immediately be found and are therefore considered constants in the powerflow equations.\n\\subsection{PV buses}\nFor PV buses, the power flow equations also hold, with both components of $V$ being unknown as was the case for PQ buses. $Q_{\\text{gen}}$ is an additional variable, and an extra constraint also applies:\n\\begin{align}\n\\Delta |V|^2 = \\Vr^2 + \\Vi^2 - V_\\text{PV}^2 = 0\n\\label{EQ_POWERFLOW_PV_CONSTRAINT}\n\\end{align}\nwhere $V_{\\text{PV}}$ is the voltage magnitude setpoint for the PV bus.\n\n\\subsection{Newton-Raphson equations}\nConsidering PQ buses only for the moment, the unknowns are the real and imaginary parts of $V$, and these equations can be solved using the Newton-Raphson method. Letting the function to which we want to find the zero be $f = [\\Ir, \\Ii]$, the unknows be $x = [\\Vr, \\Vi]$, we wish to solve $f(x) = 0$. Using the Jacobian\n\\begin{align}\nJ_{ik}(x) = \\frac{\\partial f_i(x)}{\\partial x_k}\n\\end{align}\nthe NR method calculates the update to $x$ at each iteration as the solution to the linear equations\n\\begin{align}\n-f_{(n)} &= J(x_{(n)})(x_{(n+1)}-x_{(n)}) = J(x_{(n)})\\Delta x_{(n,n+1)}\n\\label{EQ_NR}\n\\end{align}\nThe Jacobian elements for variables $V$ are given by:\n\\begin{align}\n\t\\frac{\\partial \\Ir_i}{\\partial \\Vr_{k}} \n\t\t&= \\left[-\\frac{2\\Vr_k[(P_{ck} + P_{\\text{gen},k})\\Vr_k + (Q_{ck} + Q_{\\text{gen},k})\\Vi_k]}{|V|_k^4} + \\frac{(P_{ck} + P_{\\text{gen},k})}{|V|_k^2}\\right]\\delta_{ik} \\notag \\\\\n\t\t&+ \\frac{\\Vi_i(\\Ii_i\\Vr_i + \\Ir_i\\Vi_i)}{|V_i|^3}\\delta_{ik} \\notag \\\\\n\t\t&- (G_{ik} + g_{ci}\\delta_{ik}) \\\\\n\t\\frac{\\partial \\Ir_i}{\\partial \\Vi_{k}} \n\t\t&= \\left[-\\frac{2\\Vi_k[(P_{ck} + P_{\\text{gen},k})\\Vr_k + (Q_{ck} + Q_{\\text{gen},k})\\Vi_k]}{|V|_k^4} + \\frac{(Q_{ck} + Q_{\\text{gen},k})}{|V|_k^2} \\right]\\delta_{ik} \\notag \\\\\n\t\t&- \\frac{\\Vr_i(\\Ii_i\\Vr_i + \\Ir_i\\Vi_i)}{|V_i|^3}\\delta_{ik} \\notag \\\\\n\t\t&+ (B_{ik} + b_{ci}\\delta_{ik}) \\\\\n\t\\frac{\\partial \\Ii_i}{\\partial \\Vr_{k}}\n\t\t&= \\left[-\\frac{2\\Vr_k[(P_{ck} + P_{\\text{gen},k})\\Vi_k - (Q_{ck} + Q_{\\text{gen},k})\\Vr_k]}{|V|_k^4} - \\frac{(Q_{ck} + Q_{\\text{gen},k})}{|V|_k^2} \\right]\\delta_{ik} \\notag \\\\\n\t\t&+ \\frac{\\Vi_i(\\Ii_i\\Vi_i - \\Ir_i\\Vr_i)}{|V_i|^3}\\delta_{ik} \\notag \\\\\n\t\t&- (B_{ik} + b_{ci}\\delta_{ik}) \\\\\n\t\\frac{\\partial \\Ii_i}{\\partial \\Vi_{k}}\n\t\t&= \\left[-\\frac{2\\Vi_k[(P_{ck} + P_{\\text{gen},k})\\Vi_k - (Q_{ck} + Q_{\\text{gen},k})\\Vr_k]}{|V|_k^4} + \\frac{(P_{ck} + P_{\\text{gen},k})}{|V|_k^2} \\right] \\delta_{ik} \\notag \\\\\n\t\t&+ \\frac{\\Vr_i(\\Ir_i\\Vr_i - \\Ii_i\\Vi_i)}{|V_i|^3}\\delta_{ik} \\notag \\\\\n\t\t&- (G_{ik} + g_{ci}\\delta_{ik})\n\\end{align}\n\n\\subsubsection{Treatment of the slack bus}\nThere are no variables associated with the slack bus. The voltage is constant, and the power can be found after the rest of the buses are solved.\n\n\\subsubsection{Treatment of PV buses}\nAs explained earlier, $PV$ buses add an extra variable, $Q_g$. This adds the following non-zero elements to the Jacobian:\n\\begin{align}\n\\frac{\\partial \\Ir_k}{\\partial Q_{\\text{gen},k}} &= \\frac{\\Vi_k}{|V|_k^2} \\\\\n\\frac{\\partial \\Ii_k}{\\partial Q_{\\text{gen},k}} &= -\\frac{\\Vr_k}{|V|_k^2}\n\\end{align}\nThere is also an extra constraint, Eq. (\\ref{EQ_POWERFLOW_PV_CONSTRAINT}), reproduced here:\n\\begin{align}\n\\Delta |V|^2 = \\Vr^2 + \\Vi^2 - V_\\text{PV}^2 = 0\n\\label{EQ_POWERFLOW_PV_CONSTRAINT_AGAIN}\n\\end{align}\nwith corresponding elements in the Jacobian being:\n\\begin{align}\n\\frac{\\partial \\Delta|V|^2_k}{\\partial \\Vr_k} &= 2 \\Vr_k \\notag \\\\\n\\frac{\\partial \\Delta|V|^2_k}{\\partial \\Vi_k} &= 2 \\Vi_k\n\\label{EQ_PV_JAC_Q}\n\\end{align}\nThe NR update corresponding to this constraint row is:\n\\begin{align}\n\t-\\Vr_k^2 - \\Vi_k^2 + V_{\\text{PV},k}^2 &= 2\\Vr_k\\Delta\\Vr_k + 2\\Vi_k\\Delta\\Vi_k\n\\end{align}\nwhich gives\n\\begin{align}\n\\Delta \\Vr_k &= \\frac{V^2_{\\text{PV},k} - \\Vr_k^2 - \\Vi_k^2- 2\\Vi_k\\Delta \\Vi_k}{2\\Vr_k}\n\\end{align}\n\nUsing these expressions, $\\Delta \\Vr$ may be eliminated from the NR equations for the PV bus. First write the Jacobian as if all buses were PQ. Let $k$ be any PV bus. Take the column corresponding to $\\Delta \\Vr_k$, and add its product with $-\\Vi_k/\\Vr_k$ to the matching column for  $\\Delta \\Vi_k$. Add its product with $(|V|^2_{\\text{PV},k} - \\Vr_k^2 - \\Vi_k^2)/(2\\Vr_k)$ to $f$ in Eq. (\\ref{EQ_NR}). The column and the corresponding element of $x$ for $\\Delta \\Vr_k$ will now be replaced with a column and elment for $\\Delta Q_{\\text{gen},k}$. Set the column to zero, and then set the block diagonal elements, using Eq. (\\ref{EQ_PV_JAC_Q}). Reinterpret the corresponding element of $\\Delta x$ in Eq. (\\ref{EQ_NR}) as now corresponding to $\\Delta Q_{\\text{gen},k}$ instead of $\\Delta \\Vr_k$.\n\n\\section{Power flow in polar coordinates}\nThe preceding section treated the power flow problem in rectangular coordinates, in which the mathematical expressions are simpler and the Newton-Raphson method works well in rectangular coordinates. In fact, it is more common to work in polar coordinates. Doing so can give a clearer physical insight, and is conducive to the development of approximations such as are used in the DC approximation or fast decoupled power flow. Taking the complex conjugate of Eq. \\ref{EQ_POWERFLOW_COMPLEX} and multiplying by $V_i$ gives\n\\newcommand{\\M}[1]{\\ensuremath{|V_{#1}|}}\n\\newcommand{\\cs}[1]{\\ensuremath{\\cos(\\theta_{#1})}}\n\\newcommand{\\sn}[1]{\\ensuremath{\\sin(\\theta_{#1})}}\n\\begin{align}\n\tS_i &= S_{ci} + S_{gi} + I^*_{ci}\\M{i} - y^*_{ci}\\M{i}^2 - V_i\\sum_{k = 0}^N{Y^*_{ik}V^*_k} \\notag \\\\\n\t&= S_{ci} + S_{gi} + I^*_{ci}M_i - y^*_{ci}\\M{i}^2 - \\M{i}\\sum_{k = 0}^N{Y^*_{ik}\\M{k}\\exp{(j\\theta_{ik})}}\n\\end{align}\nwhere we introduce the polar notation $V_i := \\M{i} \\exp{(j\\theta_i)}$ and $\\theta_{ik} := \\theta_i - \\theta_k$. $S_i$ is the \\emph{total} power injection into a bus, including all loads, branch flows and generation, and should be zero in a correct power flow solution. The real and reactive components of this are:\n\\begin{align}\n\tP_i &= P_{ci} + P_{gi} + \\Ir_{ci}\\M{i} - g_i\\M{i}^2 \\notag \\\\\n\t&- \\M{i}\\sum_{l = 0}^N{\\left[G_{il}\\cs{il} + B_{il}\\sn{il}\\right]\\M{l}} \\notag \\\\\n\tQ_i &= Q_{ci} + Q_{gi} - \\Ii_{ci}\\M{i} + b_i\\M{i}^2 \\notag \\\\\n\t&- \\M{i}\\sum_{l = 0}^N{\\left[G_{il}\\sn{il} - B_{il}\\cs{il}\\right]\\M{l}} \\notag \\\\\n\\end{align}\nHowever, for PV buses, $Q_{g}$ is a free variable, and can immediately be set to the value that makes the error $Q_i$ zero.\n\nWe first solve:\n\\begin{align}\n\tP_i &= P_{ci} + P_{gi} + \\Ir_{ci}\\M{i} - g_i\\M{i}^2 \\notag \\\\\n\t&- \\M{i}\\sum_{l = 0}^N{\\left[G_{il}\\cs{il} + B_{il}\\sn{il}\\right]\\M{l}}  , & i \\in \\mathrm{PQ} \\cup \\mathrm{PV}\\notag \\\\\n\tQ_i &= Q_{ci} - \\Ii_{ci}\\M{i} + b_i\\M{i}^2 \\notag \\\\\n\t&- \\M{i}\\sum_{l = 0}^N{\\left[G_{il}\\sn{il} - B_{il}\\cs{il}\\right]\\M{l}}, & i \\in \\mathrm{PQ}\n\\end{align}\nfor variables $\\{\\M{\\text{PQ}}, \\theta_\\text{PQ, PV}\\}$. These equations are independent of $Q_g$, which can be therefore be calculated in a single final step as:\n\\begin{align}\n\tQ_{gi} &= -Q_{ci} + \\Ii_{ci}\\M{i} - b_i\\M{i}^2 \\notag \\\\\n\t&+ \\M{i}\\sum_{l = 0}^N{\\left[G_{il}\\sn{il} - B_{il}\\cs{il}\\right]\\M{l}}, & i \\in \\mathrm{PV}\n\\end{align}\n\nNote for computations (particularly in what follows), it may be more efficient to cache $\\sin(\\theta)$ and $\\cos(\\theta)$, and to use\n\\begin{align}\n\t\\sin(\\theta_{il}) &:= \\sin(\\theta_i)\\cos(\\theta_l) - \\cos(\\theta_i)\\sin(\\theta_l) \\notag \\\\\n\t\\cos(\\theta_{il}) &:= \\cos(\\theta_i)\\cos(\\theta_l) + \\sin(\\theta_i)\\sin(\\theta_l)\n\\end{align}\n\n\n\\subsection{The NR method in polar coordinates}\nFor PQ buses, the possible unknowns are $\\M{}$ and $\\theta$. For PV buses, the possible unknowns are $Q_g$ and $\\theta$. The Jacobian is therefore\n\\begin{align}\n\t\\frac{\\partial P_i}{\\partial \\M{k}} &= \n\t\t\\begin{cases}\n\t\t\t-\\M{i}\\left[G_{ik}\\cs{ik} + B_{ik}\\sn{ik}\\right] & k \\ne i \\\\\n\t\t\t\\Ir_{ci} - 2g_i\\M{i} - 2 \\M{i}G_{ii} - \\sum_{\\stackrel{l = 0}{l \\ne i}}^N{\\left[G_{il}\\cs{il} + B_{il}\\sn{il}\\right]\\M{l}} & k = i\n\t\t\\end{cases} & k \\in \\text{PQ} \\notag \\\\\n\t\\frac{\\partial P_i}{\\partial \\theta_k} &=\n\t\t\\begin{cases}\n\t\t\t\\M{i}\\left[-G_{ik}\\sn{ik} + B_{ik}\\cs{ik}\\right]\\M{k}, &k \\ne i \\\\\n\t\t\t\\M{i}\\sum_{\\stackrel{l = 0}{l \\ne i}}^N{\\left[G_{il}\\sn{il} - B_{il}\\cs{il}\\right]\\M{l}}, &k = i\n\t\t\\end{cases} \\notag \\\\\n\t\\frac{\\partial Q_i}{\\partial \\M{k}} &= \n\t\t\\begin{cases}\n\t\t\t-\\M{i}\\left[G_{ik}\\sn{ik} - B_{ik}\\cs{ik}\\right], & k \\ne i \\\\\n\t\t\t-\\Ii_{ci} + 2b_i\\M{i} + 2\\M{i}B_{ii} - \\sum_{l = 0}^N{\\left[G_{il}\\sn{il} - B_{il}\\cs{il}\\right]\\M{l}}, & k = i, \\\\\n\t\t\\end{cases} &  i, k \\in \\text{PQ} \\notag \\\\\n\t\\frac{\\partial Q_i}{\\partial \\theta_k} &= \n\t\t\\begin{cases}\n\t\t\t\\M{i}\\left[G_{ik}\\cs{ik} + B_{ik}\\sn{ik}\\right]\\M{k}, & k \\ne i \\\\\n\t\t\t-\\M{i}\\sum_{\\stackrel{l = 0}{l \\ne i}}^N{\\left[G_{il}\\cs{il} + B_{il}\\sn{il}\\right]\\M{l}}, & k = i \\\\\n\t\t\\end{cases}, & i \\in PQ\n\\end{align}\n\nThis gives us enough information to carry out the NR method for polar coordinates. Note that the value of $Q_g$ is not needed for any of the iterations, and so can be calculated once-only after convergence is achieved.\n\n\\subsection{Fast-decoupled load flow}\nEspecially in transmission networks, we have that $G_{ik} \\ll B_{ik}$ and $\\theta_{ik} \\approx 0$. We also assume that shunts are mainly reactive (i.e. there are no large resistive loads), so that $g_i \\approx 0$, and that there are no large constant current loads, so that $I_c \\approx 0$. Under these conditions, the Jacobian above can be simplified:\n\\begin{align}\n\t\\frac{\\partial P_i}{\\partial \\M{k}} &= 0, & k \\in \\text{PQ} \\notag \\\\\n\t\\frac{\\partial P_i}{\\partial \\theta_k} &= \n\t\t\\begin{cases}\n\t\t\t\\M{i}B_{ik}\\M{k}, & i \\ne k \\\\\n\t\t\t-\\M{i}\\sum_{\\stackrel{l = 0}{l \\ne i}}^NB_{il}\\M{l}, &i = k\n\t\t\\end{cases} \\notag \\\\\n\t\\frac{\\partial Q_i}{\\partial \\M{k}} &= \n\t\t\\begin{cases}\n\t\t\t\\M{i}B_{ik}, & k \\ne i \\\\\n\t\t\t-\\Ii_{ci} + 2b_i\\M{i} + 2 \\M{i}B_{ii} + \\sum_{\\stackrel{l = 0}{l \\ne i}}^N{B_{il}\\M{l}}, & k = i,\n\t\t\\end{cases} & i, k \\in \\text{PQ} \\notag \\\\\n\t\\frac{\\partial Q_i}{\\partial \\theta_k} &= 0, & i \\in PQ\n\\end{align}\nNote that the problem then separates into two independent problems: one for $\\{P, \\theta\\}$ and one for $\\{Q, \\M{}\\}$. \n\nFor a flat-start, we have $\\M{k} \\approx 1$, and the Jacobian simplifies further. The fast decoupled load flow method normally uses this flat start Jacobian throughout the iteration process. The error function $f$ is assumed to be unchanged from the full NR method, so if it converges, it will converge to the correct solution to the full AC power flow problem. In practice it requires many more iterations than the full NR method, but each iteration is much faster, and the convergence properties can be much better.\n\n\\section{Generalised Power Flow Theory}\nLet the voltage at bus $i$ be $V_i$, and let the voltage difference between buses $i$ and $k$ be $V_{ik} := V_i - V_k$. We represent ground as a special bus, with index zero, which must always have a voltage of zero: $V_0 = 0$. Let $S^*_{g,i}$ be the power injected into bus $i$. Let $y_{c,ik}$ be a constant admittance between buses $i$ and $k$, $S_{c,ik}$ be a constant power flow between these buses and $I_{c,ik}$ be a constant magnitude current flow whose phase varies with $V$, so that the resulting actual current is\\footnote{This ensures that the controlled current loads can't have a power that depends on the local absolute phase.} $I_{c,ik}V_{ik}/|V_{ik}|$.\n\nThe generated current injection at bus $i$ is then equal to the sum of the current flowing from $i$ to all other connected buses:\n\\begin{align}\n\t\\frac{S^*_{g,i}}{V^*_i} - \\sum_{k \\ne i} \\left[y_{c,ik}V_{ik} + \\frac{S^*_{c,ik}}{V^*_{ik}} + \\frac{I_{c,ik}V_{ik}}{|V_{ik}|}\\right] = 0\n\t\\label{EQ_POWERFLOW_B}\n\\end{align}\n\nTo simplify the calculation for the terms proportional to $y$, we define the bus admittance matrix, $Y$:\n\\begin{align}\n\tY_{c,ik} &=\n\t\t\\begin{cases}\n\t\t\t-y_{c,ik}&\\text{if $i \\ne k$} \\\\\n\t\t\t\\sum_{l \\ne i} y_{c,il}& \\text{if $i = k$}\n\t\t\\end{cases}\n\t\\label{EQ_YNODE_OHMIC_B}\n\\end{align}\nThe sum over $k$ in this equation includes the special ground bus, $k = 0$. Such terms represent shunt admittances to ground. Equation \\ref{EQ_POWERFLOW_B} then becomes\n\\begin{align}\n\t\\frac{S^*_{g,i}}{V^*_i} - \\sum_{k \\ne 0}{Y_{c,ik}V_{k}} - \\sum_{k \\ne i}\\left[\\frac{S^*_{c,ik}}{V^*_{ik}} + \\frac{I_{c,ik}V_{ik}}{|V_{ik}|}\\right] = 0\n\t\\label{EQ_POWERFLOW_B1}\n\\end{align}\nSince ground is treated implicitly, there is no need to consider terms where $i = 0$, and, because $V_0$ = 0, we may safely omit terms in the first sum where $k = 0$, as shown in the equation. Note that the second sum \\emph{does} include terms with $k = 0$; these are usual constant current and constant power components of a ZIP load model. However, this equation allows more general loads than the usual ZIP model, as constant current and power components are also possible \\emph{between} buses, not just from a single bus to ground. This allows us to consider FACTS devices, as well as various types of delta loads, for example.\n\n\\subsection{NR method in rectangular coordinates}\nLet the mismatch, $\\Delta I$, equal the LHS of Eq. \\ref{EQ_POWERFLOW_B1}:\n\\begin{align}\n\\Delta I_i = \\frac{S^*_{g,i}}{V^*_i} - \\sum_{k \\ne 0}{Y_{c,ik}V_{k}} - \\sum_{k \\ne i}\\left[\\frac{S^*_{c,ik}}{V^*_{ik}} + \\frac{I_{c,ik}V_{ik}}{|V_{ik}|}\\right]\n\\label{EQ_MISMATCH}\n\\end{align}\n\nConsidering for the moment PQ buses only, the unknowns are the real and imaginary voltage components, $x = [\\Vr, \\Vi]$. We wish to find values for these variables such that the mismatch, $\\Delta I$, is zero. Using the Jacobian\n\\begin{align}\nJ_{ik}(x) = \\frac{\\partial \\Delta I_i(x)}{\\partial x_k},\n\\end{align}\nthe NR method calculates the update to $x$ at each iteration as the solution to the linear equations\n\\begin{align}\n-\\Delta I_{(n)} &= J(x_{(n)})(x_{(n+1)}-x_{(n)}) \\notag \\\\\n                &= J(x_{(n)})\\Delta x_{(n,n+1)}\n\\label{EQ_NR}\n\\end{align}\n\nThe Jacobian is given below:\n\\begin{align}\n\t\\frac{\\partial \\Delta I_i}{\\partial \\Vr_l} \n\t\t&= \\delta_{il}\\frac{-S^*_{g,i}}{{V^*_i}^2} \\notag \\\\\n\t\t&- Y_{c,il} \\notag \\\\\n\t\t&+ \\delta_{il} \\sum_{k \\ne i}{\\frac{S^*_{c,ik}}{{V^*_{ik}}^2}} \\notag \\\\\n\t\t&+ (1-\\delta_{il})\\frac{-S^*_{c,il}}{{V^*_{il}}^2} \\notag \\\\\n\t\t&+ \\delta_{il} \\sum_{k \\ne i}{\\frac{I_{c,ik}(-|V_{ik}|^2 + \\Vr_{ik}V_{ik})}{|V_{ik}|^3}} \\notag \\\\\n\t\t&+ (1 - \\delta_{il})\\frac{I_{c,il}(|V_{il}|^2 - \\Vr_{il}V_{il})}{|V_{il}|^3} \\notag \\\\\n\t\\frac{\\partial \\Delta I_i}{\\partial \\Vi_l} \n\t\t&= \\delta_{il}\\frac{j S^*_{g,i}}{{V^*_i}^2} \\notag \\\\\n\t\t&- j Y_{c,il} \\notag \\\\\n\t\t&+ \\delta_{il} \\sum_{k \\ne i}{\\frac{-j S^*_{c,ik}}{{V^*_{ik}}^2}} \\notag \\\\\n\t\t&+ (1-\\delta_{il}) \\frac{j S^*_{c,il}}{{V^*_{il}}^2} \\notag \\\\\n\t\t&+ \\delta_{il} \\sum_{k \\ne i}{\\frac{I_{c,ik}(-j|V_{ik}|^2 + \\Vi_{ik}V_{ik})}{|V_{ik}|^3}} \\notag \\\\\n\t\t&+ (1 - \\delta_{il})\\frac{I_{c,il}(j|V_{il}|^2 - \\Vi_{il}V_{il})}{|V_{il}|^3}\t\n\\end{align}\nTo solve these equations, we transform each complex row of the mismatch vector and the Jacobian into separate real and imaginary rows, and then use a sparse solver on the resulting system of real equations.\n\n\\subsubsection{Treatment of the slack bus}\nThere are no variables associated with the slack bus. The voltage is constant, and the power can be found after the rest of the buses are solved.\n\n\\subsubsection{Treatment of the ground bus}\nSimilarly, there are no variables associated with the special ground bus, and indeed this bus may be treated completely implicitly. Its voltage is, of course, zero. We have already seen how constant admittance shunts to ground are absorbed into the definition of the bus admittance matrix, $Y$. Similarly, there are columns in $S_c$ and $I_c$ involving the ground bus that need to be taken into account in various sums.\n\n\\subsubsection{Treatment of PV buses}\nAs explained earlier, $PV$ buses add an extra variable, $Q_g$. This adds the following non-zero elements to the Jacobian:\n\\begin{align}\n\\frac{\\partial \\Delta I_i}{\\partial Q_{g,l}} &= \\delta_{il}\\frac{-i}{V^*_i}\n\\end{align}\nThere is also an extra constraint, Eq. (\\ref{EQ_POWERFLOW_PV_CONSTRAINT}), reproduced here:\n\\begin{align}\n\\Delta |V|^2 = |V|^2 - V_\\text{PV}^2 = 0\n\\label{EQ_POWERFLOW_PV_CONSTRAINT_AGAIN}\n\\end{align}\nwith corresponding elements in the Jacobian being:\n\\begin{align}\n\\frac{\\partial \\Delta|V|^2_k}{\\partial \\Vr_k} &= 2 \\Vr_k \\notag \\\\\n\\frac{\\partial \\Delta|V|^2_k}{\\partial \\Vi_k} &= 2 \\Vi_k\n\\label{EQ_PV_JAC_Q}\n\\end{align}\nThe NR update corresponding to this constraint row is:\n\\begin{align}\n\t-|V_k|^2 + V_{\\text{PV},k}^2 &= 2\\Vr_k\\Delta\\Vr_k + 2\\Vi_k\\Delta\\Vi_k\n\\end{align}\nwhich gives\n\\begin{align}\n\\Delta \\Vr_k &= \\frac{V^2_{\\text{PV},k} - |V_k|^2- 2\\Vi_k\\Delta \\Vi_k}{2\\Vr_k}\n\\end{align}\n\nUsing these expressions, $\\Delta \\Vr$ may be eliminated from the NR equations for the PV bus. First write the Jacobian as if all buses were PQ. Let $k$ be any PV bus. Take the column corresponding to $\\Delta \\Vr_k$, and add its product with $-\\Vi_k/\\Vr_k$ to the matching column for  $\\Delta \\Vi_k$. Add its product with $(|V|^2_{\\text{PV},k} - \\Vr_k^2 - \\Vi_k^2)/(2\\Vr_k)$ to $f$ in Eq. (\\ref{EQ_NR}). The column and the corresponding element of $x$ for $\\Delta \\Vr_k$ will now be replaced with a column and elment for $\\Delta Q_{g,k}$. Set the column to zero, and then set the block diagonal elements, using Eq. (\\ref{EQ_PV_JAC_Q}). Reinterpret the corresponding element of $\\Delta x$ in Eq. (\\ref{EQ_NR}) as now corresponding to $\\Delta Q_{g,k}$ instead of $\\Delta \\Vr_k$.\n\n\\section{Formalism for modelling branches}\n\\subsection{Branch admittance ($Y$) parameters}\nConsider a network consisting of three buses, $a$, $b$ and $c$. Due to the linear nature of the nodal admittance relation, the nodal admittance matrix for the network $Y$, can be decomposed as follows:\n\\begin{align}\n\tY = \\begin{bmatrix}\n\t\tY^{ab}_{00} & Y^{ab}_{01} & 0 \\\\ Y^{ab}_{10} & Y^{ab}_{11} & 0 \\\\ 0 & 0 & 0\n\t\\end{bmatrix} + \\begin{bmatrix}\n\t\tY^{ac}_{00} & 0 & Y^{ac}_{01} \\\\ 0 & 0 & 0 \\\\ Y^{ac}_{10} & 0 &  Y^{ac}_{11}\n\t\\end{bmatrix} + \\begin{bmatrix}\n\t\t0 & 0 & 0 \\\\ 0 & Y^{bc}_{00} & Y^{bc}_{01} \\\\ 0 & Y^{bc}_{10} &  Y^{bc}_{11}\n\t\\end{bmatrix}\n\t\\label{EQ_BRANCH_DECOMP}\n\\end{align}\nwhere, e.g., $Y^{ab}$, is the nodal admittance matrix for buses $a$ and $b$ in isolation from the rest of the network. If nodes $a$ and $b$ were connected by a line with admittance $y_{ab}$, then we would have\n\\begin{align}\n\tY^{ab} &= \n\t\\begin{bmatrix}\n\t\ty_{ab} & -y_{ab} \\\\\n\t\t-y_{ab} & y_{ab}\n\t\\end{bmatrix}\n\\end{align}\nIn this kind of decomposition, the matrix $Y^{ab}$ represents the properties of the \\emph{branch} between nodes $a$ and $b$ and is termed the \\emph{branch admittance matrix}. The global properties of the full $Y$ matrix are reduced to the elements of the $2 \\times 2$ branch admittance matrices, which can be derived in isolation from each other.\n\nWhat about three phase systems? A three-phase bus can be represented as a set of three single phase buses. A three phase branch links two three phase buses, and thus involves six single phase buses; it is represented by a $6 \\times 6$ branch admittance matrix. Considering the network for these six buses in isolation from all other buses allows us to derive its elements, which could, for example, represent the properties of a three-wire overhead transmission line.\n\nThe modelling task is then to derive expressions for the branch admittance matrices of all the different kinds of lines and transformers. The full $Y$ matrix may then always be reconstructed from these components. \n\nSometimes, instead of using the branch admittance matrix representation, alternate expressions are used. Often, the inverse of the branch matrix, the $Z$ matrix, is used\n\\begin{align}\n\tZ = Y^{-1}\n\\end{align}\n\nAnother common representation is the ``ABCD'' representation, where\n\\begin{align}\n\t\\begin{bmatrix}\n\t\tV_1 \\\\ I_1\n\t\\end{bmatrix} &= \\begin{bmatrix}\n\t\tA & -B \\\\ C & -D\n\t\\end{bmatrix}\\begin{bmatrix}\n\t\tV_2 \\\\ I_2\n\t\\end{bmatrix}\n\\end{align}\n$V_1, I_1$ and $V_2, I_2$ are the current and voltage at buses $1$ and $2$ respectively.\\footnote{Take care: in most treatments, you will not see the negative signs on $B$ and $D$. This is because in these treatments $I_1$ is the current \\emph{into} bus 1 and $I_2$ is the current \\emph{out of} bus 2. To avoid choosing arbitrary directions of current flow, we have instead been working with the convention that all currents and powers are \\emph{injections into} a bus.} For multi-phase buses, these are vector quantities, and $A, B, C, D$ are matrices. We can reconstruct the $Y$ matrix as follows:\n\\begin{align}\n\tY = \\begin{bmatrix}\n\t\tDB^{-1} & C - DB^{-1}A \\\\\n\t\t-B^{-1} & B^{-1}A\n\t\\end{bmatrix}\n\\end{align}\nGiven a $Y$ matrix, we can also construct the $ABCD$ matrix:\n\\begin{align}\n\t\\begin{bmatrix} A & -B \\\\ C & -D \\end{bmatrix} &=\n\t\\begin{bmatrix}\n\t\t-Y_{21}^{-1}Y_{22} & -Y_{21}^{-1} \\\\\n\t\tY_{12} - Y_{11}Y_{21}^{-1}Y_{22} & -Y_{11}Y_{21}^{-1}\n\t\\end{bmatrix}\n\\end{align}\nwhere, again, all elements may be considered to be block submatrices.\n\nThe main point of the ABCD representation is that branches may be ``cascaded'' together. For example, consider two n-phase lines that are joined head to tail at a central n-phase bus. We can eliminate the central bus by multiplying the ABCD matrices:\n\\begin{align}\n\t\\begin{bmatrix}\n\t\tV_1 \\\\ I_1\n\t\\end{bmatrix} &=\n\t\\begin{bmatrix}\n\t\tA_{12} & -B_{12} \\\\ C_{12} & -D_{12}\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\tV_2 \\\\ I_2\n\t\\end{bmatrix} \\notag \\\\\n\t&=\n\t\\begin{bmatrix}\n\t\tA_{12} & -B_{12} \\\\ C_{12} & -D_{12}\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\tA_{23} & -B_{23} \\\\ C_{23} & -D_{23}\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\tV_3 \\\\ I_3\n\t\\end{bmatrix}\n\\end{align}\nThis defines a composition law for $ABCD$ parameters.\n\\section{Transmission Lines}\n\\subsection{Single phase transmission lines}\nShort transmission lines (below 80 km in length) can be modelled as a single admittance $y$ (or equivalently an impedance $z = 1/y$) between two buses:\n\\begin{align}\n\tY = \\begin{bmatrix}\n\t\ty & -y \\\\ -y & y\n\t\\end{bmatrix}\n\\end{align}\nThe real part of $z$ is positive (a resistance), and the imaginary part is also positive (an inductive reactance). Both the resistance and the inductive reactance are proportional to the length of the line. The inductive reactance is usually larger than the resistance.\n\nLonger transmission lines ($> 80$ km) also develop a capacitance between the line and ground. If the length is less than about 240 km, then this is often modelled using the $\\pi$-model, see Fig. \\ref{FIG_PI_LINE}. The $Y$-matrix is:\n\\begin{align}\n\tY = \\begin{bmatrix}y_s + \\frac{j b_c}{2} & -y_s \\\\ -y_s & y_s + \\frac{j b_c}{2} \\end{bmatrix}\n\\end{align}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[width=(5cm)]{pi_line}\n\t\\end{center}\n\t\\caption{\n\t\tThe $\\pi$ model of a transmission line.\n\t}\n\t\\label{FIG_PI_LINE}\n\\end{figure}\nVery long lines require a more complex \\emph{distributed model}.\n\n\\subsection{Multi-phase transmission lines}\nThe equations above apply also to multi-phase lines, except that the scalar elements become block submatrices whose size is the number of phases.\n\n\\subsection{Line parameters}\nWe have discussed above the structure of the $Y$ matrix for transmission lines -- but we still need to know how to find the values of the admittances in our equations. \\emph{Carson's Equations} allow us to do this, for N-phase lines which may also contain one or more multi-grounded neutral wires. They take into account the geometry of the transmission line and the conductivity of the ground. We do not, however, go into these equations in this document.\n\n\\section{Transformers}\n\\subsection{Single phase transformers}\nFor an ideal transformer with a single (possibly complex) turns ratio $n = n_1/n_0$, we have, using the ABCD parameters:\n\\begin{align}\n\\begin{bmatrix}V_1 \\\\ I_1\\end{bmatrix} &= \\begin{bmatrix}n & 0 \\\\ 0 & 1/n^*\\end{bmatrix}\\begin{bmatrix}V_0 \\\\ I_0 \\end{bmatrix}\n\\end{align}\nThis can't be modelled correctly in the formalism of nodal admittance matrices, in the same way that a line with zero impedance can't. Two equivalent circuits for an ideal transformer are shown in Fig. \\ref{FIG_IDEAL_TRANS_EQUIV}.\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[width=(\\textwidth-2cm)]{ideal_transformer_equiv.png}\n\t\\end{center}\n\t\\caption{\n\t\tTwo equivalent circuits for an ideal transformer.\n\t}\n\t\\label{FIG_IDEAL_TRANS_EQUIV}\n\\end{figure}\nThe relationships could be included in the power flow equations specially, but more commonly real transformers are used, as described below; these may be expressed in the nodal admittance formalism.\n\nA real transformer includes a leakage impedance (due to finite resistance of copper windings and core losses) and a shunt magnetising impedance. There are various ways of drawing an equivalent circuit. We use the general branch model described in Section \\ref{SEC_GEN_BRANCH_MODEL}, with the series admittance set to a leakage admittance $y_l$ (mainly inductive) and the shunt admittances forming the magnetising admittance $y_m$, see Fig. \\ref{FIG_REAL_TRANS}.\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[width=(\\textwidth-2cm)]{transformer.png}\n\t\\end{center}\n\t\\caption{\n\t\tAn equivalent circuit for a real transformer.\n\t}\n\t\\label{FIG_REAL_TRANS}\n\\end{figure}\n\nThe nodal admittance matrix is:\n\\begin{align}\n\\begin{bmatrix}I_0 \\\\ I_1 \\end{bmatrix} &= \n\\begin{bmatrix}\\frac{y_l + \\frac{1}{2}y_m}{|n|^2} & -\\frac{y_l}{n^*} \\\\ -\\frac{y_l}{n} & y_l + \\frac{1}{2}y_m\\end{bmatrix}\n\\begin{bmatrix}V_0 \\\\ V_1 \\end{bmatrix}\n\\label{EQ_REAL_TRANS}\n\\end{align}\nwhere $n = n_1/n_0$ is the ideal turns ratio, $y_l$ is the leakage impedance and $y_m$ is the magnetising admittance. Often, the magnetising admittance is very small and is neglected. $y_l$ can be found by short circuiting the secondary, while $y_m$ can be found using an open circuit test.\n\n\\subsection{Three-phase transformers}\nThe nodal admittance matrices of three-phase transformers may be derived from the single-phase expression, above, combined with information about the connections between phases.\n\\subsubsection{Wye-Wye}\nWe have\n\\begin{align}\nI_{A} &= \\frac{y_l}{|n|^2}V_A - \\frac{y_l}{n^*}V_a \\\\\nI_{B} &= \\frac{y_l}{|n|^2}V_B - \\frac{y_l}{n^*}V_b \\\\\nI_{C} &= \\frac{y_l}{|n|^2}V_C - \\frac{y_l}{n^*}V_c \\\\\nI_a &= -\\frac{y_l}{n}V_A + y_l V_a \\\\\nI_b &= -\\frac{y_l}{n}V_B + y_l V_b \\\\\nI_c &= -\\frac{y_l}{n}V_C + y_l V_c \\\\\n\\end{align}\nso we can immediately write down the nodal admittance relationship:\n\\begin{align}\n\\begin{bmatrix}I_A \\\\ I_B \\\\ I_C \\\\ I_a \\\\ I_b \\\\ I_c\\end{bmatrix} &=\ny_l \\begin{bmatrix}\n\t1/|n|^2 & 0 & 0 & -1/n^* & 0 & 0 \\\\\n\t0 & 1/|n|^2 & 0 & 0 & -1/n^* & 0 \\\\\n\t0 & 0 & 1/|n|^2 & 0 & 0 & -1/n^* \\\\\n\t-1/n & 0 & 0 & 1 & 0 & 0 \\\\\n\t0 & -1/n & 0 & 0 & 1 & 0 \\\\\n\t0 & 0 & -1/n & 0 & 0 & 1\n\\end{bmatrix}\n\\begin{bmatrix}V_A \\\\ V_B \\\\ V_C \\\\ V_a \\\\ V_b \\\\ V_c\\end{bmatrix}\n\\end{align}\nwith the nodal admittance matrix being specified by the matrix on the right, including the factor of $y_l$.\n\n\\subsubsection{Delta-Delta}\nWe have\n\\begin{align}\nI_{AB} &= \\frac{y_l}{|n|^2}(V_A - V_B) - \\frac{y_l}{n^*}(V_a - V_b) \\\\\nI_{BC} &= \\frac{y_l}{|n|^2}(V_B - V_C) - \\frac{y_l}{n^*}(V_b - V_c) \\\\\nI_{CA} &= \\frac{y_l}{|n|^2}(V_C - V_A) - \\frac{y_l}{n^*}(V_c - V_a) \\\\\nI_{ab} &= -\\frac{y_l}{n}(V_A - V_B) + y_l (V_a - V_b) \\\\\nI_{bc} &= -\\frac{y_l}{n}(V_B - V_C) + y_l (V_b - V_c) \\\\\nI_{ca} &= -\\frac{y_l}{n}(V_C - V_A) + y_l (V_c - V_a)\n\\end{align}\nAlso, by the KCL, we have\n\\begin{align}\nI_A &= I_{AB} - I_{CA} \\\\ &= \\frac{y_l}{|n|^2}(2V_A - V_B - V_C) - \\frac{y_l}{n^*}(2V_a - V_b - V_c) \\\\\nI_B &= I_{BC} - I_{AB} \\\\ &= \\frac{y_l}{|n|^2}(2V_B - V_C - V_A) - \\frac{y_l}{n^*}(2V_b - V_c - V_a) \\\\\nI_C &= I_{CA} - I_{BC} \\\\ &= \\frac{y_l}{|n|^2}(2V_C - V_A - V_B) - \\frac{y_l}{n^*}(2V_c - V_a - V_b) \\\\\nI_a &= I_{ab} - I_{ca} \\\\ &= -\\frac{y_l}{n}(2V_A - V_B - V_C) + y_l(2V_a - V_b - V_c) \\\\\nI_b &= I_{bc} - I_{ab} \\\\ &= -\\frac{y_l}{n}(2V_B - V_C - V_A) + y_l(2V_b - V_c - V_a) \\\\\nI_c &= I_{ca} - I_{bc} \\\\ &= -\\frac{y_l}{n}(2V_C - V_A - V_B) + y_l(2V_c - V_a - V_b)\n\\end{align}\nso we can immediately write down the nodal admittance relationship:\n\\begin{align}\n\\begin{bmatrix}I_A \\\\ I_B \\\\ I_C \\\\ I_a \\\\ I_b \\\\ I_c\\end{bmatrix} &=\ny_l \\begin{bmatrix}\n\t2/|n|^2 & -1/|n|^2 & -1/|n|^2 & -2/n^* & 1/n^* & 1/n^* \\\\\n\t-1/|n|^2 & 2/|n|^2 & -1/|n|^2 & 1/n^* & -2/n^* & 1/n^* \\\\\n\t-1/|n|^2 & -1/|n|^2 & 2/|n|^2 & 1/n^* & 1/n^* & -2/n^* \\\\\n\t-2/n & 1/n & 1/n & 2 & -1 & -1 \\\\\n\t1/n & -2/n & 1/n & -1 & 2 & -1 \\\\\n\t1/n & 1/n & -2/n & -1 & -1 & 2\n\\end{bmatrix}\n\\begin{bmatrix}V_A \\\\ V_B \\\\ V_C \\\\ V_a \\\\ V_b \\\\ V_c\\end{bmatrix}\n\\end{align}\nwith the nodal admittance matrix being specified by the matrix on the right, including the factor of $y_l$.\n\n\\subsubsection{Delta-GWye}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=7cm]{DeltaGWye.pdf}\n\\caption{Schematic of a Delta-GWye transformer}\n\\label{FIG_DELTA_GWYE}\n\\end{center}\n\\end{figure}\nConsidering Fig. \\ref{FIG_DELTA_GWYE} and neglecting the magnetising impedance, we have,\n\\begin{align}\nI_{AB} &= \\frac{y_l}{|n|^2}(V_A - V_B) - \\frac{y_l}{n^*}V_a \\\\\nI_{BC} &= \\frac{y_l}{|n|^2}(V_B - V_C) - \\frac{y_l}{n^*}V_b \\\\\nI_{CA} &= \\frac{y_l}{|n|^2}(V_C - V_A) - \\frac{y_l}{n^*}V_c \\\\\nI_a &= -\\frac{y_l}{n}(V_A - V_B) + y_l V_a \\\\\nI_b &= -\\frac{y_l}{n}(V_B - V_C) + y_l V_b \\\\\nI_c &= -\\frac{y_l}{n}(V_C - V_A) + y_l V_c \\\\\n\\end{align}\nAlso, by the KCL, we have\n\\begin{align}\nI_A &= I_{AB} - I_{CA} \\\\\n&= \\frac{y_l}{|n|^2}(2V_A - V_B - V_C) + \\frac{y_l}{n^*}(V_c - V_a) \\\\\nI_B &= I_{BC} - I_{AB} \\\\\n&= \\frac{y_l}{|n|^2}(2V_B - V_C - V_A) + \\frac{y_l}{n^*}(V_a - V_b) \\\\\nI_C &= I_{CA} - I_{BC} \\\\\n&= \\frac{y_l}{|n|^2}(2V_C - V_A - V_B) + \\frac{y_l}{n^*}(V_b - V_c)\n\\end{align}\nso we can immediately write down the nodal admittance relationship:\n\\begin{align}\n\\begin{bmatrix}I_A \\\\ I_B \\\\ I_C \\\\ I_a \\\\ I_b \\\\ I_c\\end{bmatrix} &=\ny_l \\begin{bmatrix}\n\t2/|n|^2 & -1/|n|^2 & -1/|n|^2 & -1/n^* & 0 & 1/n^* \\\\\n\t-1/|n|^2 & 2/|n|^2 &  -1/|n|^2 & 1/n^*  & -1/n^* & 0 \\\\\n\t-1/|n|^2 &  -1/|n|^2 & 2/|n|^2 & 0 & 1/n^*  & -1/n^* \\\\\n\t-1/n & 1/n & 0 & 1 & 0 & 0 \\\\\n\t0 & -1/n & 1/n & 0 & 1 & 0 \\\\\n\t1/n & 0 & -1/n & 0 & 0 & 1\n\\end{bmatrix}\n\\begin{bmatrix}V_A \\\\ V_B \\\\ V_C \\\\ V_a \\\\ V_b \\\\ V_c\\end{bmatrix}\n\\end{align}\nwith the nodal admittance matrix being specified by the matrix on the right, including the factor of $y_l$.\n\n\\subsubsection{Open Delta-open Delta}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=7cm]{OpenDelta.png}\n\\caption{Schematic of an open-delta transformer connection. The complex turns ratios (primary/secondary) are $n_A$ and $n_C$, and the leakage admittances are $y_{LA}$ and $y_{LC}$. There is a tie admittance $y_\\text{tie}$ between the middle terminals.}\n\\label{FIG_OPEN_DELTA}\n\\end{center}\n\\end{figure}\nWe use the open delta model shown in \\ref{FIG_OPEN_DELTA}. Note that the two middle phases are tied together using an admittance, to prevent a floating neutral. There are other grounding options available, for example, to ground the middle phase, and the model can be easily modified for these. Using Eq. (\\ref{EQ_REAL_TRANS}) (and neglecting magnetising impedance),  we can derive the following equations:\n\\begin{align}\n\tI_A &= \\frac{y_{LA}}{|n_A|^2}(V_A - V_B) - \\frac{y_{LA}}{n_A^*}(V_a - V_b) \\notag \\\\\n\t&= V_A\\left(\\frac{y_{LA}}{|n_A|^2}\\right) + V_B\\left(-\\frac{y_{LA}}{|n_A|^2}\\right) + V_a\\left(-\\frac{y_{LA}}{n_A^*}\\right) + V_b\\left(\\frac{y_{LA}}{n_A^*}\\right) \\notag \\\\\n\t%\n\tI_B &= y_\\text{tie}(V_B - V_b) - I_A - I_C \\notag \\\\\n\t&= V_A\\left(-\\frac{y_{LA}}{|n_A|^2}\\right) + V_B \\left(y_\\text{tie} + \\frac{y_{LA}}{|n_A|^2} + \\frac{y_{LC}}{|n_C|^2}\\right) + V_C\\left(-\\frac{y_{C}}{|n_C|^2}\\right) \\notag \\\\\n\t&+ V_a\\left(\\frac{y_{LA}}{n_A^*}\\right) + V_b\\left(-y_\\text{tie} -\\frac{y_{LA}}{n_A^*} - \\frac{y_{LC}}{n_C^*}\\right) + V_c\\left(\\frac{y_{LC}}{n_C^*}\\right) \\notag \\\\\n\t%\n\tI_C &= \\frac{y_{LC}}{|n_C|^2}(V_C - V_B) - \\frac{y_{LC}}{n_C^*}(V_c - V_b) \\notag \\\\\n\t&= V_B\\left(-\\frac{y_{LC}}{|n_C|^2}\\right) + V_C\\left(\\frac{y_{LC}}{|n_C|^2}\\right) + V_b\\left(\\frac{y_{LC}}{n_C^*}\\right) +  V_c\\left(-\\frac{y_{LC}}{n_C^*}\\right) \\notag \\\\\n\t%\n\tI_a &= -\\frac{y_{LA}}{n_A}(V_A - V_B) + y_{LA}(V_a - V_b) \\notag \\\\\n\t&= V_A\\left(-\\frac{y_{LA}}{n_A}\\right) + V_B\\left(\\frac{y_{LA}}{n_A}\\right) + V_a\\left(y_{LA}\\right) + V_b\\left(-y_{LA}\\right)\\notag \\\\\n\t%\n\tI_b &= -y_\\text{tie}(V_B - V_b) - I_a - I_c \\notag \\\\\n\t&= V_A\\left( \\frac{y_{LA}}{n_A}\\right) + V_B\\left(-y_\\text{tie} - \\frac{y_{LA}}{n_A} - \\frac{y_{LC}}{n_C}\\right) + V_C\\left( \\frac{y_{LC}}{n_C}\\right) \\notag \\\\\n\t&+ V_a\\left(-y_{LA}\\right) + V_b\\left(y_\\text{tie} + y_{LA} + y_{LC}\\right) + V_c\\left(-y_{LC}\\right) \\notag \\\\\n\t%\n\tI_c &= -\\frac{y_{LC}}{n_C}(V_C - V_B) + y_{LC}(V_c - V_b) \\notag \\\\\n\t&= V_B\\left(\\frac{y_{LC}}{n_C}\\right) + V_C\\left( -\\frac{y_{LC}}{n_C}\\right) + V_b\\left(-y_{LC}\\right)  + V_c\\left(y_{LC}\\right)\n\\end{align}\nSince $I = YV$, we can deduce the bus admittance matrix $Y$ as:\n\\begin{align}\nY &= \n\\begin{bmatrix}\n\t\\frac{y_{LA}}{|n_A|^2} & -\\frac{y_{LA}}{|n_A|^2} & 0 & -\\frac{y_{LA}}{n_A^*} & \\frac{y_{LA}}{n_A^*} & 0 \\\\\n\t%\n\t-\\frac{y_{LA}}{|n_A|^2} & \\left(y_\\text{tie} + \\frac{y_{LA}}{|n_A|^2} + \\frac{y_{LC}}{|n_C|^2}\\right) & -\\frac{y_{C}}{|n_C|^2} & \\frac{y_{LA}}{n_A^*} & \\left(-y_\\text{tie} -\\frac{y_{LA}}{n_A^*} - \\frac{y_{LC}}{n_C^*}\\right) & \\frac{y_{LC}}{n_C^*} \\\\\n\t%\n\t0 & -\\frac{y_{LC}}{|n_C|^2} & \\frac{y_{LC}}{|n_C|^2} & 0 & \\frac{y_{LC}}{n_C^*} &  -\\frac{y_{LC}}{n_C^*} \\\\\n\t%\n\t-\\frac{y_{LA}}{n_A} & \\frac{y_{LA}}{n_A} & 0 & y_{LA} & -y_{LA} & 0 \\\\\n\t%\n\t\\frac{y_{LA}}{n_A} & \\left(-y_\\text{tie} - \\frac{y_{LA}}{n_A} - \\frac{y_{LC}}{n_C}\\right) & \\frac{y_{LC}}{n_C} & -y_{LA} & \\left(y_\\text{tie} + y_{LA} + y_{LC}\\right) & -y_{LC} \\\\\n\t%\n\t0 & \\frac{y_{LC}}{n_C} & -\\frac{y_{LC}}{n_C} & 0 & -y_{LC}\\ & y_{LC}\n\\end{bmatrix}\n\\end{align}\n\n\\section{General single phase branch model}\n\\label{SEC_GEN_BRANCH_MODEL}\nSingle phase transformers and transmission lines can both be incorporated within a single general branch model, shown in Fig. \\ref{FIG_GEN_BRANCH_MODEL}.\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[width=(9cm)]{branch.png}\n\t\\end{center}\n\t\\caption{\n\t\tA general branch model, similar but more general than that used by {\\sc Matpower}.\n\t}\n\t\\label{FIG_GEN_BRANCH_MODEL}\n\\end{figure}\nThe $Y$ matrix for this model is defined by the following equation:\n\\begin{align}\n\t\\begin{bmatrix}I_0 \\\\ I_1\\end{bmatrix} &=\n\t\\begin{bmatrix}\\frac{y_a + y_b}{|n|^2} & -\\frac{y_a}{n^*} \\\\ -\\frac{y_a}{n} & y_a + y_c \\end{bmatrix}\n\t\\begin{bmatrix}V_0 \\\\ V_1\\end{bmatrix}\n\\end{align}\nNormally, $y_c = y_b$ for both transformers and transmission lines, as per the {\\sc Matpower} manual. For a transmission line, $y_b$ is capacitative, and for a transformer it has a resistive and an inductive component and is associated with the ``no load'' current needed in the primary windings. For both transformers and lines, $y_a$ has a resistive component and an inductive component.\n\n\\section{Units and the per-unit system}\nThe following self-consistent system of units is often used in modelling electricity networks:\n\\begin{description}\n\t\\item[Voltage:]kV (kilovolts)\n\t\\item[Power:]MW/MVAR/MVA (megawatts etc.)\n\t\\item[Current:]kA (kiloamps)\n\t\\item[Resistance:]$\\Omega$ (ohms)\n\t\\item[Admittance:]$S$ (siemens)\n\\end{description}\nUnder this system, relationships like Ohm's Law hold without the need to include any additional constants. The alternative is to use SI units ($V/W/A/\\Omega/S$\\ldots).\n\nThe \\emph{per-unit} system is also often used. The idea is to express electrical quantities as a \\emph{per-unit} dimensionless quantity times a \\emph{base unit}, e.g.\n\\begin{align}\nV &= V_\\text{pu}V_\\text{base} \\notag \\\\\nS &= S_\\text{pu}P_\\text{base} \\notag \\\\\nI &= I_\\text{pu}I_\\text{base} \\notag \\\\\n&\\text{etc.}\n\\end{align}\n\nBase units $V_\\text{base}$ and $P_\\text{base}$ are normally first defined for the network. $V_\\text{base}$ is set to the nominal operating voltage of a bus (e.g. 11~kV), which means that $V_\\text{base}$ may vary from bus to bus. On the other hand, a single network-wide value for $P_\\text{base}$ is usually chosen to be a convenient value such as 100~MVA. Other base quantities may then be derived:\n\\begin{align}\n\tI_\\text{base} &= P_\\text{base}/V_\\text{base} \\notag \\\\\n\tZ_\\text{base} &= V_\\text{base}^2 / P_\\text{base} \\notag \\\\\n\tY_\\text{base} &= P_\\text{base} / V_\\text{base}^2\n\\end{align}\nNote that there is some ambiguity about which bus $V_\\text{base}$ is referenced to in the expressions above. Consider for example a line that runs between two buses: logically there could be several ways to define the per-unit current: using the voltage at the first bus, the voltage at the second bus, or the voltage drop on the line. Depending on how things are done, different equations will need to be used for the network. The ambiguity is removed if we distinguish the power entering bus A along a line AB as being distinct from the power entering bus B along the same line, i.e. we only work with bus injections as opposed to line flows. A set of conventions consistent with \\textsc{Matpower} is given below:\n\\begin{itemize}\n\\item Per-unit quantities in lines are calculated using the base-voltage at the second (to) bus. This makes sense in Matpower, since a common branch model is used where all transformers occur at the first (from) bus, with the bulk of the line occurring between the transformer and the second (to) bus.\n\\item Per-unit quantities associated with buses (such as bus shunt admittance, current loads etc. are calculated, naturally enough, using the base voltage of the bus.\n\\end{itemize}\n\n\\section{The Swing Equations}\nA synchronous generator has a flywheel with moment of inertia $J$. There is a mechanical torque (e.g. from the turbine) $T_m$ pushing the rotor and an electrical torque $T_e$ that comes from the alternator and usually acts against the mechanical torque. We define the torque imbalance $\\Delta T = T_m - T_e$. When $\\Delta T$ is positive the rotor will speed up and when it is negative it will slow down. We define the rotor angle $\\theta$ which is assumed to be zero at $t = 0$. Its first time derivative is the angular velocity $\\omega = \\dot{\\theta}$.\n\nThe equation \\footnote{For those not familiar with the notation, a dot above a variable indicates a time derivative, e.g. $\\dot{\\theta} := \\partial \\theta / \\partial t$. Similarly, a double dot indicates a second time derivative, etc.} governing the motion of the rotor is\n\\begin{align}\n\tJ \\ddot{\\theta} &= \\Delta T\n\\end{align}\nwhich is analogous to Newton's $F = ma$.\n\nFor a rotor running at the constant mandated network angular frequency $\\omega_\\text{nom}$, we have $\\theta = \\omega_\\text{nom} t$. Because the rotor may deviate from this frequency, we define the angular error\n\\begin{align}\n\t\\Delta \\theta &= \\theta - \\omega_\\text{nom} t. \\label{EQ_DEFN_DELTA_THETA}\n\\end{align}\nThis quantity is basically equal to the voltage phase of the generator internal bus. In terms of this new variable, the generator equation is:\n\\begin{align}\n\tJ \\Delta \\ddot{\\theta} &= \\Delta T\n\\end{align}\n\nSince the power $P = \\omega T$, we multiply both sides of the second equation by $\\omega$ to obtain a relation for the power mismatch:\n\\begin{align}\n\tJ\\omega \\Delta \\ddot{\\theta} &= \\Delta P \\notag \\\\\n\tJ\\left(\\omega_\\text{nom} + \\Delta \\dot{\\theta}\\right) \\Delta\\ddot{\\theta} &= \\Delta P\n\\end{align}\nwhere $\\Delta P$ is the input mechanical power minus the electrical power supplied to the network. When the rotor is running far from the mandated frequency, then this equation would need to be applied as is. However, at frequencies near the network frequency, $\\omega_\\text{nom} \\gg \\dot{\\theta}$, and so we can write\n\\begin{align}\n\tJ\\omega_\\text{nom} \\Delta\\ddot{\\theta} &= L_\\text{nom} \\Delta\\ddot{\\theta} = \\Delta P \\label{EQ_SWING}\n\\end{align}\nwhere $L_\\text{nom} = J \\omega_\\text{nom}$ is the angular momentum of the rotor at the network frequency. This is the swing equation, and when solved will give the bus internal voltage angle as a function of time.\n\nA note about units: if, as is common, we measure power in $\\mathrm{MVA}$, then $L$ will need to be measured in commensurate units of $\\mathrm{Mkg\\cdot m^{-2}}$, i.e. we will need to divide the SI value by $10^6$.\n\n\\subsection{Multiple-pole generators}\nGenerators may have multiple pairs of north-south magnetic dipoles. In such cases, the rotor angular frequency will be scaled with respect to the network frequency. For example, a generator with two dipoles running on a 50~Hz network will turn at 25~Hz, because the north-south fields will pass the coils at twice the rate of the rotor's rotation.\n\nSuch cases are easily taken care of by absorbing the scaling factor into an effective moment of inertia $J_\\text{eff} = NJ$, where N is the number of dipoles.\n\n\\subsection{The swing equations and the power flow equations}\nWe derive the electrical power at all generators using the power flow equations. The phase angle $\\phi$ is fixed at the generator buses by the swing equations. The voltage magnitude $V$ could also be fixed (either to its fixed value, or scaled according to the current frequency), making all of the generator buses into effective slack buses. To ensure feasibility of the AC power flow equations, we could then convert all or some ZIP loads into constant impedance loads, or add a high constant impedance component to all loads to ensure feasibility.\n\n\\subsection{The swing equations at a three phase bus}\nFor three phase problems, the three terminals of the bus are connected to a single rotor, with a given angular momentum. The phase relationship between the bus terminals is enforced by the windings in the stator. The problem is what to do with this situation, in regards to the swing equations etc.\n\nThe answer is the obvious: that there is a single machine at each generator, which is input for the swing equations. \n\\end{document}", "meta": {"hexsha": "2e88d4781122cb7b9e32c6a7ce6f538a56f99339", "size": 66103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/background/power_flow_theory.tex", "max_stars_repo_name": "dexterurbane/SmartGridToolbox", "max_stars_repo_head_hexsha": "ff2eb98e28b0c0ea9690ec6f522ccf1c306f79b7", "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/background/power_flow_theory.tex", "max_issues_repo_name": "dexterurbane/SmartGridToolbox", "max_issues_repo_head_hexsha": "ff2eb98e28b0c0ea9690ec6f522ccf1c306f79b7", "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/background/power_flow_theory.tex", "max_forks_repo_name": "dexterurbane/SmartGridToolbox", "max_forks_repo_head_hexsha": "ff2eb98e28b0c0ea9690ec6f522ccf1c306f79b7", "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.4278752437, "max_line_length": 1002, "alphanum_fraction": 0.6887887085, "num_tokens": 22081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6988370556333305}}
{"text": "%!TEX root = paper.tex\n% \\section{Synthesizing \\DIs}\n\n\\subsubsection{PCA-inspired \\View Derivation}\\label{candidatesec}\n\n\n\\setlength{\\textfloatsep}{0mm}\n\\begin{algorithm}[t]\n\t\\caption{Procedure to generate linear \\views.}\n\t\\label{fig:pca}\n\t\\LinesNumbered\n\t\\small{ \n    \t\\SetKwInOut{Inputs}{Inputs}\n\t\t\\SetKwInOut{Output}{Output}\n\t\t\\Inputs{\n\t\t\tA dataset $D \\subset \\DDom^m$\n\t\t}\n\t\t\\Output{\n                    A set $\\{(F_1,\\gamma_1),\\ldots,(F_K,\\gamma_K)\\}$ of \\views and importance factors\n    \t}\n                $D_N  \\gets D {\\mbox{ after dropping non-numerical attributes}}$  \\label{algo2:line1}\\\\ \n                $D'_N  \\gets [\\vec{1} ; D_N]$ \\label{algo2:line2} \\\\\n                $\\{\\vec{w}_1,\\ldots,\\vec{w}_K\\} \\gets {\\mbox{ eigenvectors of }} {D_N'}^T D_N'$ \\label{algo2:line31} \\\\\n\t\t\t\t\\ForEach{$1 \\le k \\le K$}{\n\t\t\t\t\t$\\vec{w}_k' \\gets {\\mbox{ $\\vec{w}_k$ with first element removed}}$\\label{algo2:line32} \\\\\n                                        $F_k \\gets \\lambda\\vec{A}: \\frac{\\vec{A}^T\\vec{w}_k'}{||\\vec{w}_k'||}$\\label{algo2:line33} \\\\\n\t\t\t\t\t%{\\mbox{ for $i=1,\\ldots,k$}}$ \\label{algo2:line3} \\\\\n\t\t\t\t\t$\\gamma_k \\gets \\frac{1}{\\log(2+\\stddev{F_k(D_N)})}$ \\label{algo2:line34}\n\t\t\t\t\t%\\af{I fixed it with $\\log$ since that is what we do.  Any argument needed for that? Also, I fixed $\\stddev{F_i(D)}$ to $\\stddev{F_i(D_N)}$. Check if that's correct.}\n\t\t\t\t\t% {\\mbox{ for $i=1,\\ldots,k$}}$ \\label{algo2:line4} \\\\\n\t\t\t\t}\n                \\Return $\\{(F_1,\\frac{\\gamma_1}{Z}),\\ldots,(F_K,\\frac{\\gamma_K}{Z})\\}$, where\n                $Z = \\sum_k \\gamma_k$\\label{algo2:line35}\n\t}\n\\end{algorithm}\n\\setlength{\\textfloatsep}{5pt}\n \nTheorem~\\ref{THM:MAIN} sets the requirements for good \\views (see\nalso~\\cite{tveten2019principal, tveten2019tailored,\nDBLP:journals/tnn/KunchevaF14} that make similar observations in different\nways). It indicates that we can start with any arbitrary \\views and then\niteratively improve them. However, we can get the desired set of best \\views in\none shot using an algorithm inspired by principal component analysis (PCA).\n\\revisetwo{PCA relies on computing eigenvectors. \\label{pcadetails} There exist\ndifferent algorithms for computing eigenvectors (from the infinite space of\npossible vectors). The general mechanism involves applying numerical approaches\nto iteratively converge to the eigenvectors (up to a desired precision) as no\nanalytical solution exists in general.} Algorithm~\\ref{fig:pca}  returns \\views that\ncorrespond to the principal components of a\nslightly modified version of the given dataset: % (Fig.~\\ref{fig:pcadetails}).\n% Algorithm~\\ref{fig:pca} details our approach for discovering \\views for\n% constructing \\dis:\n\n% The\n% only additional technical point is the addition of a dummy attribute (column)\n% to the dataset, which is set to the constant $1$ for each tuple. This is done\n% because we are not normalizing the data (e.g., to make the mean of each column\n% zero). It turns out that adding a constant dummy column\n% lets us avoid normalizing the data. % achieves the same effect.\n% We avoid normalizing just to keep the values unchanged so that the generated \\di is\n% interpretable on original values.  In detail, we have:\n\\smallskip\n\n\\begin{description}\n\t%\n    \\looseness-1\n    \\item[Line~\\ref{algo2:line1}] Drop all non-numerical attributes from $D$ to\n    get the numeric dataset $D_N$. This is necessary because PCA only applies\n    to numerical values. Instead of dropping, one can also consider embedding\n    techniques to convert non-numerical attributes to numerical ones.\n\n    \\item[Line~\\ref{algo2:line2}] Add a new column to $D_N$ that consists of\n    the constant $1$, to obtain the modified dataset $D_N' := [\\vec{1} ; D_N]$,\n    where $\\vec{1}$ denotes the column vector with $1$ everywhere. We do this\n    transformation to capture the additive constant within principal\n    components, which ensures that the approach works even for unnormalized\n    data.\n\n    \\item[Line~\\ref{algo2:line31}] Compute $K$ eigenvectors of the square\n    matrix ${D_N'}^{T}D_N'$, where $K$ denotes the number of columns in $D'_N$.\n\tThese eigenvectors provide coefficients to construct \\views.\n\n    \\item[Lines~\\ref{algo2:line32}--\\ref{algo2:line33}] Remove the first\n    element (coefficient for the newly added constant column) of all\n    eigenvectors and normalize them to generate \\views. Note that we no longer\n    need the constant element of the eigenvectors since we can appropriately\n    adjust the bounds, $\\lb$ and $\\ub$, for each \\view by evaluating it on\n    $D_N$.\n        %% bounds of\n    %% the \\dis by shifting the mean by the corresponding constant amount. \n        % (The\n %    2-norm $||\\vec{w}'_k||$ is $\\sqrt{{\\vec{w}_k}^{'T} \\vec{w}'_k}$.)\n\n    \\item[Line~\\ref{algo2:line34}] Compute importance factor for each \\view.\n    Since \\views with smaller standard deviations are more discerning (i.e.,\n    stronger), we assign each \\view an importance factor ($\\gamma$) that is\n    inversely proportional to its standard deviation over $D_N$.\n\n    \\item[Line~\\ref{algo2:line35}] Return the linear \\views with corresponding\n    normalized importance factors.\n\n\\end{description}\n% \\\\\n% (a) Drop all non-numerical attributes from $D$ to get $D_N$ (line~\\ref{algo2:line1}).\n% %Let $\\vec{w}$ denote the unknown weights that define\n% %the linear \\view $F(\\vec{A}) = \\vec{A}^T\\vec{w}$ on $D_N$. We prefer $\\vec{w}$\n% %that minimizes $\\stddev{D_N\\vec{w}}$.\n% %\n% %\n% %\n% %We are interested in learning linear functionals $F(A_1,\\ldots,A_k)$ of the form\n% %$w_0 + w_1 A_1  + w_2 A_2 + \\cdots + w_k A_k$, where $x1,\\ldots,A_k$ are the $k$ numerical columns\n% %in $D_N$ and $w_0, w_1,\\ldots,w_k$ are $k+1$ unknown weights.\n% %%Since data can be noisy, we want to allow for the equality relation to be not necessarily an exact equality.\n% %\n% %Without loss of generality, we ignore the constant term $w_0$ in the \\invariant. This is because\n% %We find $\\vec{w}$ as follows:\n% \\\\\n% %\n% (b) Add a new column to $D_N$ that consists of the constant $1$, that is,\n% $D_N' := [\\vec{1} ; D_N]$, where $\\vec{1}$ denotes the column vector with $1$\n% everywhere (line~\\ref{algo2:line2}).\n% %If $D_N$ has $k-1$ columns, then $D_N'$ has $k$ columns.\n% %\n% \\\\\n% %\n% (c) Compute $k$ eigenvectors of the square matrix ${D_N'}^{T}D_N'$, where $k$\n% denotes the number of columns in $D'_N$\n% (line~\\ref{algo2:line31}). % $\\vec{v} := [v_1;v_2;\\ldots;v_k]$ corresponding to the lowest\n% %eigenvalue,\n% %\n% \\\\\n% %\n% (d) Remove the first element from each eigenvector (line~\\ref{algo2:line32})\n% and normalize them to generate \\views (line~\\ref{algo2:line33}). (The 2-norm\n% $||\\vec{v}||$ of $\\vec{v}$ is $\\sqrt{\\vec{v}^T\\vec{v}}$.)\n% \\\\ (e) Compute\n% importance factor for each \\view (line~\\ref{algo2:line34}).\n% \\\\ (f) Return the\n% linear \\views with corresponding normalized importance factors\n% (line~\\ref{algo2:line35}).\n\n\\smallskip\n\nWe now claim that the \\views returned by Algorithm~\\ref{fig:pca} include the\n\\view with minimum standard deviation and \n%. Furthermore, if $D$ is sufficiently large, then \nthe correlation between any two \\views \n%returned Algorithm~\\ref{fig:pca} \nis 0. This indicates that we cannot further improve\nthe \\views, and, thus they are optimal.\n%,and $[a;b]$ denotes $\\left[\\begin{matrix}a \\\\ b\\end{matrix}\\right]$.\n\n\\begin{theorem}[Correctness of Algorithm~\\ref{fig:pca}]\\label{THM:ALGO2-CORRECTNESS}\n\t%\n    Given a numerical dataset $D$ over the schema $\\mathcal{R}$, let\n    $\\mathcal{F} = \\{F_1,F_2,\\ldots, F_K\\}$ be the set of linear \\views\n    returned by Algorithm~\\ref{fig:pca}. Let $\\sigma^* =\n    \\min_k^{K}\\stddev{F_k(D)}$. If $\\mu(A_k(D)) = 0$ for all attribute $A_k$ in\n    $\\mathcal{R}$, then,\\footnote{When the condition $\\forall A_k \\;\n    \\mu(A_k(D)) = 0$ does not hold, slightly modified variants of the claim\n    hold. However, by normalizing $D$ (i.e., by subtracting attribute mean\n    $\\mu(A_k(D))$ from each $A_k(D)$), it is always possible to satisfy the\n    condition.}\n%\n\t\\begin{enumerate}[label=(\\arabic*)]\n            \\item $\\sigma^* \\leq \\stddev{F(D)}$ $\\forall F=\\vec{A}^T\\vec{w}$ where $||\\vec{w}||\\geq 1$, and\n    \\item $\\forall F_j, F_k \\in \\mathcal{F}$ s.t.\\ $F_j\\neq F_k$, \n        % the corresponding eigenvalues $\\varepsilon_j \\neq \\varepsilon_k$, \n        $\\rho_{F_j, F_k} = 0$.\n\t\t% (assuming, wlog, Algorithm~\\ref{fig:pca} always picks                orthogonal eigenvectors).\n        % $\\lim_{|D| \\to \\infty} \\rho_{F_j, F_k} = 0$, \\textcolor{red}{under the assumption that\n                % the columns of $D$ converge to some mean value and the\n                % eigenvalues of $D^TD$ converge to some fixed values.}\n\t\\end{enumerate}\n    % Furthermore, any linear \\view $F$ s.t.\\ $\\stddev{F(D)} = \\sigma^*$ \n    % is equal to a linear\n    % combination of $F_j$'s whose standard deviation is $\\sigma^*$ on $D$.\n\\end{theorem}\n% Let $\\vecw$ be the (column) vector consisting of the unknown weights $w_1,\\ldots,w_k$.\n% Since $d\\vecw$ may not identically be $0$ for all $d\\in D_N$, \n% we can cast the problem of finding $w_1,\\ldots,w_k$ as an optimization problem\n% that tries to minimize the sum $\\sum_{d\\in D_N} (d\\vecw)^2$, which we shall call {\\em{error}}.  \n% In matrix notation, this error can be written\n% as $\\vecw^T D_N^TD_N \\vecw$.\n% We restrict $\\vecw$ to unit vectors to make the optimization problem well posed.\n\n\n\n\n\\ignore{\nIn Algorithm~\\ref{fig:pca}, we use the above procedure to compute linear \\views.\n\\af{I will pull this before, and will describe the procedure while referring\nto the corresponding lines in the algorithm. I can do it if you agree.}\nAlgorithm~\\ref{fig:pca} computes \\views using {\\em{all}} eigenvectors, rather\nthan just the eigenvector corresponding to the lowest eigenvalue. \n\\endignore}\n\nUsing \\views $F_1, \\ldots, F_K$, and importance factors\n$\\gamma_1,\\ldots,\\gamma_K$, returned by Algorithm~\\ref{fig:pca}, we generate\nthe simple (conjunctive) \\invariant with $K$ conjuncts:\n%\n$\n \\bigwedge_k  \\lb_k \\leq F_k(\\vec{A}) \\leq \\ub_k\n$.\n%\nWe compute the bounds $\\lb_k$ and $\\ub_k$ following Section~\\ref{synth-bounds}\nand use the importance factor $\\gamma_k$ for the $k^{th}$ conjunct in the\nquantitative semantics.\n\n\\begin{example}\\label{ex:int} Algorithm~\\ref{fig:pca} finds the projection of the \\di of\nExample~\\ref{ex:tml}, but in a different form. The actual airlines dataset has\nan attribute $\\mathtt{distance}\\; (\\mathtt{DIS})$ that represents miles travelled by a flight. In\nour experiments, we found the following \\di\\footnote{For ease of exposition, we\nuse $F(\\vec{A}) \\approx 0$ to denote $\\epsilon_1 \\le F(\\vec{A}) \\le\n\\epsilon_2$, where $\\epsilon_i \\approx 0$.} over the dataset of daytime flights:\n%\n{\n\\begin{align}\\label{eq:one}\n0.7 \\times \\mathtt{AT} - 0.7 \\times \\mathtt{DT} - 0.14 \\times \\mathtt{DUR} - 0.07 \\times \\mathtt{DIS} \\approx 0\n\\end{align}\n}\n%\nThis \\invariant is not quite interpretable by itself, but it is in fact a\nlinear combination of two expected and interpretable\n\\invariants:~\\footnote{\\revisetwo{We developed a tool~\\cite{DBLP:conf/sigmod/FarihaTRG20} to explain causes of\nnon-conformance.~\\citeTechRep}}\n%\n{\n\\begin{align}\n\t\\mathtt{AT} - \\mathtt{DT} - \\mathtt{DUR} &\\approx 0 \\label{eq:two}\\\\\n\t\\mathtt{DUR} - 0.12 \\times \\mathtt{DIS} &\\approx 0 \\label{eq:three}\n\\end{align}\n}\n%\nHere, (\\ref{eq:two}) is the one mentioned in Example~\\ref{ex:tml} and\n(\\ref{eq:three}) follows from the fact that average aircraft speed is about\n$500$ mph implying that it requires $0.12$ minutes per mile. $0.7$ $\\times$\n(\\ref{eq:two}) + $0.56$ $\\times$ (\\ref{eq:three}) yields:\n%\n{\n\\begin{align*}\n&0.7 \\times (\\mathtt{AT} - \\mathtt{DT} - \\mathtt{DUR}) + 0.56 \\times \\mathtt{DUR} - 0.56 \\times 0.12 \\times \\mathtt{DIS} \\approx 0 \\\\\n\\implies & 0.7 \\times \\mathtt{AT} - 0.7 \\times \\mathtt{DT} - 0.14 \\times \\mathtt{DUR} - 0.07 \\times \\mathtt{DIS} \\approx 0\n\\end{align*}\n}\n%\nWhich is exactly the \\di~(\\ref{eq:one}). Algorithm~\\ref{fig:pca} found the\noptimal \\view of~(\\ref{eq:one}), which is a linear combination of the \\views\nof~(\\ref{eq:two}) and~(\\ref{eq:three}). The reason is: there is a correlation\nbetween the \\views of~(\\ref{eq:two}) and~(\\ref{eq:three}) over the dataset\n(Theorem~\\ref{THM:MAIN}). One possible explanation of this correlation is:\nwhenever there is an error in the reported duration of a tuple, it violates\nboth~(\\ref{eq:two}) and~(\\ref{eq:three}). Due to this natural correlation,\nAlgorithm~\\ref{fig:pca} returned the optimal \\view of~(\\ref{eq:one}), that\n``covers'' both \\views of~(\\ref{eq:two}) or~(\\ref{eq:three}).\n\n%\n\\end{example}\n\n\\ignore{ \n\nThe reason for including \\views corresponding to all eigenvalues in the\nsimple \\invariant---in addition to the one with smallest standard\ndeviation---is that it only strengthens the \\invariant. Note that we use importance factors $\\gamma_i$ to give\nmore importance to the \\views with smaller standard deviations. One obvious\nquestion is: can our procedure miss some linear \\views with small standard\ndeviations? The following result states that we do not miss any linear \\views\ncorresponding to the {\\em{smallest}} achievable standard deviation.\n\n% Consider the eigenvalues and eigenvectors of the positive semi-definite matrix $D_N^TD_N$.\n% Let $\\eig_1,\\ldots,\\eig_k$ be the $k$ eigenvalues, and \n% $\\vecv_1, \\ldots,\\vecv_k$ be the corresponding $k$ eigenvectors of $D_N^TD_N$. Assuming that the eigenvectors are normalized to have norm $1$, we have\n% $$\n % \\vecv_j^T D_N^TD_N \\vecv_j = \\vecv_j^T \\eig_j\\vecv_j = \\eig_j\n% $$\n% Since $D_N^TD_N$ is real-valued, symmetric, and positive semi-definite, we know that $\\eig_j$'s are all non-negative reals.\n% WLOG, assume $\\eig_1 \\leq \\eig_2 \\leq \\cdots \\leq \\eig_k$.\n% Define $k$ linear functionals $f_1,f_2,\\ldots,f_k$,\n% where $f_i$ is defined as $f_i(A_1,\\ldots,A_k) = \\vecv_{j1}A_1 + \\cdots + \\vecv_{jk}A_k$.\n% For these $k$ choices,\n% the spectrum, $\\eig_1, \\ldots, \\eig_k$, of the matrix $D_N^TD_N$, provides us with different choices for the error value. \n% %\n% Since we want to minimize error \\af{I don't think this argument is correct. As\n% mentioned in Section 2, we want neither overfit nor underfit \\invariants. If we\n% wanted to minimize error, you could always learn a NULL \\invariant, why even\n% just one with lowest eigenvalue?}, we should pick $\\vecv_1$, the eigenvector\n% corresponding to $\\eig_1$, to construct our \\invariant. In fact, we should\n% use all eigenvectors corresponding to small eigenvalues, since some prior\n% work~\\cite{tveten2019principal, tveten2019tailored,\n% DBLP:journals/tnn/KunchevaF14} showed that low eigenvalue principal components\n% are more sensitive to a general change. Rather than use some heuristic to\n% determine which eigenvalues are ``small'' and which are not, in our\n% implementation, we just use all eigenvectors \\af{I think we can get rid of\n% defer it to the Experiment section where I would keep a subsection for\n% implementation specifics.}, but {\\em{weigh them differently}} according to the\n% standard deviation of $f_i(D_N)$, as we stated before. \\todo{Talk about\n% $\\gamma$ being $\\frac{1}{\\log(2 + \\stddev{D})}$. And then talk about\n% normalizing them}. Note that the above derivation shows that $\\stddev{f_j}$ is\n% related to the value $\\eig_j$ of the corresponding eigenvalue.\n% Algorithm~\\ref{fig:pca} summarizes the procedure for computing the linear\n% functionals from a data set $D$, which are then used to define the actual\n% \\invariants as described in previous section.\\af{I am not sure if the algorithm\n% is very useful, as PCA is a very well known technique.}\\af{This is the heart of\n% this section, and one of our core novelty. I think we should revise this with\n% better justification and intuition. At present, it looks very weak.}\n\n\\begin{theorem}\n    Let $D$ be a dataset and\n    $F_1,F_2,\\ldots$ be the linear \\views returned by the procedure in Algorithm~\\ref{fig:pca} \n    when on $D$.\n    Let $\\sigma^* = \\min(\\{\\stddev{F_i(D)} | i=1,2,\\ldots\\})$.\n    If there is a linear \\view $F$ s.t. $\\stddev{F(D)} = \\sigma^*$, then $F$ will be in the linear subspace spanned by all the linear\n     $F_j$ with standard deviation $\\sigma^*$ on $D$.\n\\end{theorem}\n\\af{I now have high level idea of what this theorem is trying to say, but I still \nthink we can omit it in this paper.}\n% .. Dw.Dw = Dv.Dv and ||w||=||v||=1\n% ||av + bw||^2 = a^2 + b^2 + 2ab cos(theta)\n% D(av+bw).D(av+bw) = (aDv + bDw).(aDv + bDw) = a^2 S + b^2 S + 2ab (Dv.Dw) = aaS + bbS + 2abS v^Tw = S!!\n\n\nWe observe that the most common way in which PCA is used involves {\\em{throwing\naway}} the low variance components, whereas we give {\\em{most importance}} to\nthese components. This role reversal is one of our key insights in synthesizing good\n\\dis.\n\n\\endignore}\n\n\n\n\\subsection{Compound \\DIs}\\label{sec:disjunctive}\n% We now describe computation of \\emph{disjunctive} linear \\invariants. \nThe quality of our PCA-based simple linear \\invariants relies on how many low\nvariance linear \\views we are able to find on the given dataset. For many\ndatasets, it is possible we find very few, or even none, such linear \\views. In\nthese cases, it is fruitful to search for compound \\invariants; we first focus\non {\\em{disjunctive \\invariants}} (defined by $\\psi_A$ in our language grammar).\n\nThe PCA-based approach fails in cases where there exist different piecewise linear\ntrends within the data, as it will result into low-quality \\invariants, with\nvery high variances. In such cases, partitioning the dataset and then learning\n\\invariants separately on each partition will result in significant improvement\nof the learned \\invariants. A disjunctive \\invariant is a compound \\invariant\nof the form $\\bigvee_k((A = c_k) \\maxand \\phi_k)$, where each $\\phi_k$ is a\n\\invariant for a specific partition of $D$. Finding disjunctive \\invariants\ninvolves horizontally partitioning the dataset $D$ into smaller disjoint\ndatasets $D_1, D_2, \\ldots, D_L$. Our strategy for partitioning $D$ is to use\ncategorical attributes with a small domain in $D$; in our implementation, we\nuse those attributes $A_j$ for which $|\\{t.A_j | t\\in D\\}|\\le50$. If $A_j$ is\nsuch an attribute with values $v_1, v_2, \\ldots, v_L$, we partition $D$ into\n$L$ disjoint datasets $D_1, D_2,\\ldots, D_L$, where $D_l = \\{t \\in D | t.A_j =\nv_l\\}$. Let $\\phi_1, \\phi_2, \\ldots, \\phi_L$ be the $L$ simple \\dis we learn\nfor $D_1, D_2, \\ldots, D_L$ using Algorithm~\\ref{fig:pca}, respectively. We\ncompute the following disjunctive \\di for $D$:\\\\\n%  (recall that the quantitative semantics\n% of \\dis does not satisfy the typical Boolean algebra laws for $\\vee$\n% and $\\wedge$)\n%\n\\indent $\n ((A_j = v_1) \\maxand \\phi_1) \\vee \n ((A_j = v_2) \\maxand \\phi_2) \\vee \n\\cdots \\vee\n ((A_j = v_L) \\maxand \\phi_L)\\\\[-0.7em]\n$\n\n\\looseness-1 We repeat this process and partition $D$ across multiple\nattributes and generate a compound disjunctive \\invariant for each attribute.\nThen we generate the final compound conjunctive \\di ($\\Psi$) for $D$, which is\nthe conjunction of all these disjunctive \\invariants. Intuitively, this final\n\\di forms a set of \\emph{overlapping} hyper-boxes around the data tuples.\n\n\n\\subsection{Theoretical Analysis}\\label{sec:complexity} \n\n\\subsubsection{Runtime Complexity}\\looseness-1 Computing simple \\invariants\ninvolves two computational steps: (1)~computing $X^TX$, where $X$ is an\n$n\\times m$ matrix with $n$ tuples and $m$ attributes, which~takes\n$\\mathcal{O}(nm^2)$ time, and (2)~computing the eigenvalues and eigenvectors of\nan $m\\times m$ positive definite matrix, which has complexity\n$\\mathcal{O}(m^3)$~\\cite{DBLP:conf/stoc/PanC99}. Once we obtain the linear\n\\views using the above two steps, we need to compute the mean and variance of\nthese \\views on the original dataset, which takes $\\mathcal{O}(nm^2)$ time. In\nsummary, the overall procedure is cubic in the number of attributes and linear\nin the number of tuples.\n%\nFor computing disjunctive \\invariants, we greedily pick attributes that take at\nmost $L$ (typically small) distinct values, and then run the above procedure\nfor simple \\invariants at most $L$ times. This adds just a constant factor\noverhead per attribute.\n\n\\subsubsection{Memory Complexity} The procedure can be implemented in\n$\\mathcal{O}(m^2)$ space. The key observation is that $X^T X$ can be computed\nas $\\sum_{i=1}^{n} t_i t_i^T$, where $t_i$ is the $i^{th}$ tuple in the\ndataset. Thus, $X^TX$ can be computed incrementally by loading only one tuple\nat a time into memory, computing $t_i t_i^T$, and then adding that to a running\nsum, which can be stored in $\\mathcal{O}(m^2)$ space. Note that instead of such\nan incremental computation, this can also be done in an embarrassingly parallel\nway where we horizontally partition the data (row-wise) and each partition is\ncomputed in parallel.\n\n% Due to such low time and memory complexity, our approach\n% scales gracefully to large datasets.\n\n\\revisetwo{\\subsubsection{Implication, Redundancy, and Minimality}\\label{sec:impl}\nDefinition~\\ref{def:stronger} gives us the notion of \\emph{implication} on\n\\dis: for a dataset $D$, satisfying $\\phi_1$ that is stronger than $\\phi_2$\nimplies that $D$ would satisfy $\\phi_2$ as well.\n%\nLemma~\\ref{LEMMA:MAIN} and Theorem~\\ref{THM:MAIN} associate \\emph{redundancy}\nwith correlation: correlated projections can be combined to construct a new\nprojection that makes the correlated projections redundant.\nTheorem~\\ref{THM:ALGO2-CORRECTNESS} shows that our PCA-based procedure finds\na non-redundant (orthogonal and uncorrelated) set of projections. For disjunctive\n\\invariants, it is possible to observe redundancy across partitions. However,\nour quantitative semantics ensures that redundancy does not affect the\nviolation score.\n%\nAnother notion relevant to data profiles (e.g., FDs) is \\emph{minimality}. In\nthis work, we do not focus on finding the minimal set of \\dis. Towards\nachieving minimality for \\dis, a future direction is to explore techniques for\noptimal data partitioning. However, our approach computes only $m$ \\dis for\neach partition. Further, for a single tuple, only $m_N \\cdot m_C$ \\dis are applicable,\nwhere $m_{N}$ and $m_C$ are the number of numerical and categorical attributes\nin $D$ (i.e., $m = m_{N} + m_C$). The quantity $m_N \\cdot m_C$ is upper-bounded by\n$\\frac{m^2}{4}$. }\n\n\n", "meta": {"hexsha": "6913cf966252b8d683295bfdcc2aa0c7f15f57d0", "size": 22212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Paper/4_synthesizing-data-invariants_2.tex", "max_stars_repo_name": "afariha/ConformanceConstraintsReproducibility", "max_stars_repo_head_hexsha": "ee419285ab32464f063225fbdeba005a043d2033", "max_stars_repo_licenses": ["MIT"], "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/4_synthesizing-data-invariants_2.tex", "max_issues_repo_name": "afariha/ConformanceConstraintsReproducibility", "max_issues_repo_head_hexsha": "ee419285ab32464f063225fbdeba005a043d2033", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-09T09:30:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-09T09:30:49.000Z", "max_forks_repo_path": "Paper/4_synthesizing-data-invariants_2.tex", "max_forks_repo_name": "afariha/ConformanceConstraintsReproducibility", "max_forks_repo_head_hexsha": "ee419285ab32464f063225fbdeba005a043d2033", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T05:22:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T05:22:18.000Z", "avg_line_length": 51.7762237762, "max_line_length": 171, "alphanum_fraction": 0.7097965064, "num_tokens": 6871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6988000800013552}}
{"text": "\\section{Asymptotic Theory}\n\nAsymptotic theory, large sample theory, or limit theory, deals with the question of the limiting behavior of sequences of random variables. \n\nThe notion of convergence for random variables is more involved than is usual for, for example, a sequence of numbers or functions in calculus. There are different types of convergence, and they do not necessarilty imply one another.\n\nThe chain of implication is:\n\n\\begin{equation}\n\\mathrm{quadratic\\ mean} \\rightarrow \\mathrm{probability} \\rightarrow \\mathrm{distribution}\n\\end{equation}\n\nFor point mass distributions only, convergence in distribution implies convergence in probability. Similarlty, implication rules exist for functions of random variables when convergence for the underlying random variables is given. See Theorems 5.4, 5.5 and 5.17 in \\citeasnoun{wasserman2013all} (pages 73-74, 81). \n\n\\subsection{Preasymptotics}\nThe behavior in the intermediate regime, for example where $n$ large but not yet asymptotic. Asymptotic behavior kicks in at very different rates for different underlying processes. The ``baseline\" in terms of speed is represented by normally distributed random variables.\n\n\n%convergence in probability\n\\subsection{Convergence in Probability}\n\n\\begin{equation}\n\\mathbb{P}(|X_n - X| > \\epsilon) \\rightarrow 0\n\\end{equation}\n\nas $n\\rightarrow \\infty$. Convergence in Probability means that the distribution of $X_n$ becomes sharper and sharper around $X$ as $n\\rightarrow \\infty$. At $n=\\infty$, it has point mass distribution concentrated at $X$.\n\n\n% convergence in distribution\n\\subsection{Convergence in Distribution}\nWhere $F$ is the CDF of $X_n$,\n\n\\begin{equation}\n\\lim_{n\\rightarrow \\infty} F_n(t) = F(t)\n\\end{equation}\n\nFor all $t$ for which $F$ is continuous. That means, convergence is satisfied even when the equality is violated at points of discontinuity.\n\n\n% convergence in quadratic mean\n\\subsection{Convergence in Quadratic Mean, Convergence in $L_2$}\n\n\\begin{equation}\n\\mathbb{E}(X_n - X)^2 \\rightarrow 0\n\\end{equation}\n\nas $n\\rightarrow \\infty$.\n\n\n% almost sure convergence \n\\subsection{Almost Sure Convergence}\n\n$X_n$ converges \\textit{almost surely} to $X$ if:\n\n\\begin{equation}\n\\mathbb{P}(\\{\\omega: X_n(\\omega) \\rightarrow X(\\omega) \\}) = 1\n\\end{equation}\n\nWhich I would read as the value of the measurable map $X_n$ converging to the value of the measurable map $X$ everywhere on the probability space except possibly on a set of probability measure $0$.\n\n\n% l1 convergence\n\\subsection{$L_1$ Convergence}\n\n$L_1$ convergence requires $\\mathbb{E}|X_n - X| \\rightarrow 0$ as $n\\rightarrow 0$.\n\n\n\n% WLLN\n\\subsection{Weak Law of Large Numbers}\n\nThe sample mean of i.i.d. variables  $\\overline{X}_n$ converges in probability to the mean of the distribution $\\mu$i. It can be proven with Chebyshev's inequality that:\n\n\\begin{equation}\n\\mathbb{P}(|\\overline{X}_n-\\mu|>\\epsilon) \\leq \\frac{\\mathbb{V}(\\overline{X}_n)}{\\epsilon^2}=\\frac{\\sigma^2}{n \\epsilon^2}\n\\end{equation}\n\nIn words, the probability that the sample mean deviates from the population mean by more than $\\epsilon$ has an upper bound that decreases inversely proportional to $n\\epsilon^2$. The probability becomes more and more centered around the mean $\\mu$.\n\n% SLLN\n\\subsection{Strong Law of Large Numbers}\nThe strong law of large number gives almost surely convergence of the sample mean to the population mean.\n\nIf $\\mathbb{E}|X_1| < \\infty$, then $\\overline{X_n}\\xrightarrow{as}\\mu$.\n\n\n\n% CLT\n\\subsection{Central Limit Theorem}\nThe distribution of the sample mean converges in distribution to a normal distribution with variance $\\sigma^2/n$ and mean $\\mu$.\n\nIf $Z_n = \\frac{\\overline{X}_n - \\mu}{\\sqrt{\\mathbb{V}(\\overline{X}_n)}}$ then $\\lim_{n\\rightarrow \\infty} \\mathbb{P}(Z_n \\leq z) = \\Phi(z)$, where $\\Phi(z)$ is the CDF of a standard normal distribution. \n\nIt turns out that when $Z_n$ is obtained by normalizing not by the (most likely unknown) population variance $\\sigma$ but by the sample variance $S_n^2$, the CLT still holds. The accuracy of this is given by the Berry-Ess\\'een Inequality.\n\n\n% multivariate CLT\n\\subsection{Multivariate Central Limit Theorem}\nGiven $\\mathbf{X_1, ... ,X_n}$ i.i.d random vectors where each vector:\n\n\\begin{equation}\n\\mathbf{X_i} = \\left(\\begin{array}{c}X_{1i}\\\\ X_{2i} \\\\ \\vdots \\\\ X_{ki} \\end{array}\\right)\n\\end{equation}\n\nThen the population mean:\n\n\\begin{equation}\n\\mathbf{\\mu} = \\left(\\begin{array}{c} \\mu_1 \\\\ \\mu_2 \\\\ \\vdots \\\\ \\mu_k \\end{array} \\right) =  \\left(\\begin{array}{c} \\mathbb{E}(X_{i1}) \\\\ \\mathbb{E}(X_{i2}) \\\\ \\vdots \\\\ \\mathbb{E}(X_{ik}) \\end{array} \\right)\n\\end{equation}\n\nThe variance is given by the matrix $\\Sigma$ as before. The sample mean:\n\n\\begin{equation}\n\\overline{\\mathbf{X}} = \\left(\\begin{array}{c}\\overline{X_{1}}\\\\ \\overline{X_{2}} \\\\ \\vdots \\\\ \\overline{X_{k}} \\end{array}\\right)\n\\end{equation}\n\nThen $\\sigma^{-\\frac{1}{2}} (\\overline{X}-\\mu)$ converges in distribution ot $\\mathscr{N}(0,1)$.\n\n\n% proof\n\\subsection{Proof of the Central Limit Theorem}\n\\citeasnoun{wasserman2013all}, page 81.\n\nGiven i.i.d random variables $X_i$, the transformation $Y_i = \\frac{X_i-\\mu}{\\sigma}$ gives i.i.d. random variables with zero mean and unit variance. Let $\\psi(t)$ be the MGF of $Y_i$. Since $Y_i$ are i.i.d., the sum $\\sum_{i=1}^n Y_i$ has MGF $\\psi(t)^n$. The normalized sample mean $Z_n = \\frac{1}{\\sqrt{n}}\\sum_{i=1}^n Y_i$ has MGF $\\Xi_n(t)=\\psi(t/\\sqrt{n})^n$. Two random variables that have the same MGF in an open interval about the point $t=0$ have the same distribution, probably because the Laplace transform is injective. Therefore, if $\\psi_n(t)\\rightarrow \\psi(t)$ in some open interval around $t=0$, then their underlying random variables $Z_n \\xrightarrow{dist}Z_n$ converge in distribution. Taking the Taylor expansion of $\\epsilon_n(t)$:\n\n\\begin{equation}\n\\epsilon_n(t) = \\left(1+0+\\frac{t^2}{2! n} + ... \\right)^n \\rightarrow e^{t^2/2}\n\\end{equation}\n\nWhich is the MGF of $\\mathscr{N}(0,1)$\n\n% Delta Method\n\\subsection{Delta Method}\n\nThe delta method allows statements regarding the convergence of functions of random variables, whenever the input random variable converges in distribution to a normal distribution. \n\nIf $Y_n$ has a limiting normal distribution, and $g(Y_n )$ is a smooth function so that $g'(\\mu) \\neq 0$, then if:\n\n\\begin{equation}\n\\frac{\\sqrt{n}(Y_n - \\mu)}{\\sigma} \\xrightarrow{dist} \\mathscr{N}(0,1)\n\\end{equation}\n\nThen:\n\n\\begin{equation}\n\\frac{\\sqrt{n}(g(Y_n)-g(\\mu))}{|g'(\\mu)|\\sigma}\\xrightarrow{dist}\\mathscr{N}(0,1)\n\\end{equation}\n\nRewriting, if $Y_n \\xrightarrow{dist}\\mathscr{N}(\\mu,\\frac{\\sigma^2}{n})$ then $g(Y_n)\\xrightarrow{dist}\\mathscr{N}(g(\\mu),(g'(\\mu))^2\\frac{\\sigma^2}{n})$.\n\n\\subsubsection{Multivariate Delta Method}\n\nIf $\\mathbf{Y_n} \\xrightarrow{dist}\\mathscr{\\mathbf{\\mu},\\mathbf{\\Sigma}}$ then the scalar-valued function $g(\\mathbf{Y_n}) \\xrightarrow{dist}\\mathscr{N}(g(\\mathbf{\\mu}),\\frac{1}{n} (\\nabla g(\\mu))^T \\mathbf{\\Sigma} (\\nabla g(\\mu)) )$.\n\nUse case would be functions of several sample means, where the underlying samples have non-trivial covariance (cf. \\cite{wasserman2013all}, p. 80).\n\n", "meta": {"hexsha": "bed36cf1366bae43822862375982e707f5c8b177", "size": 7126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_asymptotictheory.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_asymptotictheory.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_asymptotictheory.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": 45.3885350318, "max_line_length": 754, "alphanum_fraction": 0.7301431378, "num_tokens": 2139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.6987925671191849}}
{"text": "\\section{Technical Cryptography}\n\\label{sec:tech_crypto}\n\nIn this section we present in detail the specifics of the\ncryptography we will be using for MadNetwork.\nAt times we will be verbose in our algorithmic details\nand design choices to allow for others to understand our decisions.\n\nWe will begin by comparing this work with the\nEthereum Distributed Key Generation whitepaper~\\cite{ethdkg}\nin Sec.~\\ref{ssec:ethdkg_comparison};\nour design is based this paper.\nSome of the implementation-specific details are covered in\nSec.~\\ref{ssec:pk_curve_specifics}.\nIn Sec.~\\ref{ssec:math_def}, we discuss the mathematics\nrelated to pairing-based cryptography; this is integral to\nour work as it is required for our group signatures.\nWe describe the distributed key generation protocol in\nSec.~\\ref{ssec:dkg};\nthe specific method of shared secret encryption is\ndescribed in Sec.~\\ref{ssec:secret_enc}.\nWe discuss how to construct group signatures in\nSec.~\\ref{ssec:crypto_group_sig}.\nGroup signatures from pairing-based cryptography require\na hash-to-curve function, and we talk about our construction\nbased on~\\cite{ft2012bnhashtocurve,boneh2019h2cBLS12}\nin Sec.~\\ref{ssec:hash-to-curve}.\n\nWe follow~\\cite{ethdkg} in our definition of\n$\\parens{t,n}$-thresholded system, where we need $t+1$ actors\nfor consensus.\nUnfortunately, this is different than what was used previously,\nwhere $\\parens{t,n}$-thresholded system meant $t$ actors were\nneeded to agree.\nWe keep this difference for ease of comparison with the referenced paper.\n\n\\input{tex/tcrypt_comparison.tex}\n\\input{tex/tcrypt_spec_imp.tex}\n\\input{tex/tcrypt_math_def.tex}\n\\input{tex/tcrypt_dkg.tex}\n\\input{tex/tcrypt_sse.tex}\n\\input{tex/tcrypt_grpsig.tex}\n\\input{tex/tcrypt_h2c.tex}\n", "meta": {"hexsha": "ec238e70b836edbd39aa4dfe83a5f6208e93ca72", "size": 1732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/technical_crypto.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/technical_crypto.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/technical_crypto.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": 39.3636363636, "max_line_length": 73, "alphanum_fraction": 0.8013856813, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6986271757486662}}
{"text": "\\chapter{Exponential and Logarithmic Functions}\n\\section{Exponential Functions}\nAn exponential function is a defined as any function, $f(x)$ such that the\nindependent variable $x$ is bound up somewhere in the exponent.  $f(x)=3^x$ is\nan example of such a function:\n\n\\graph{3^x}\n\nThis classification of functions have a few simple properties:\n\n\\begin{itemize}\n  \\item{They are defined for all $x\\in(-\\infty,\\infty)$}\n  \\item{Their range is: $(0, \\infty)$}\n  \\item{They have intercepts at $(0,1)$}\n  \\item{They are increasing on their entire domain}\n  \\item{The $x$-axis serves as a horizontal asymptote}\n  \\item{They are smooth and continuous}\n\\end{itemize}\n\n\\subsection{Interest Functions}\nThese types of functions have applications in a few different areas.  For us, we\nwill be primarily concerned with manually and continually compouding interest:\n\n\\begin{itemize}\n  \\item{For $n$ compoundings per year: $A=P(1+\\frac{r}{n})^{nt}$}\n  \\item{For coninuous compounding: $A=Pe^{rt}$}\n\\end{itemize}\n\n\\section{Logarithmic Functions}\nThe parent function of the logarithmic family is defined as follows:\n\\begin{equation}\n  f(x)=\\log_ax\n\\end{equation}\n\n\\graph{ln(x)}\n\n\\subsection{Properties of Logarithms}\n\\begin{itemize}\n  \\item{$\\log_a1=0$}\n  \\item{$\\log_a=1$}\n  \\item{$\\log_aa^x=x$}\n  \\item{If $\\log_ax=\\log_ay$ then $x=y$}\n\\end{itemize}\n\n\\section{Properties of Logarithms}\nA logarithm of any base $a$ can be represented as a quotient of two other\nlogarithms of base $b$, according to the following (Change of Base rule)\n\\begin{equation}\n  \\log_ax=\\frac{\\log_bx}{\\log_ba}\n\\end{equation}\n\nThe product property states that you can expand a logarithm that is the product\nof two numbers $u$ and $v$ into two logarithms that are added together, as in\nthe following generalization:\n\\begin{equation}\n  \\log_a(uv)=\\log_au+\\log_av\n\\end{equation}\n\nThe quotient property states what is already implied, that a logarithm\nrepresented as a quotient of two numbers $u$ and $v$ can be expanded equally as\na an expression of two logarithms which get subtracted, as in the following\ngeneralization:\n\\begin{equation}\n  \\log_a(\\frac{u}{v})=\\log_au-\\log_av\n\\end{equation}\n\nThe power property is implied from the product rule.  You can expand out a power\nwrapped up in a logarithm into a scalar that is multiplied to the logarithmic\nexpression, as in the following generalization:\n\\begin{equation}\n  \\log_au^n=n\\log_au\n\\end{equation}\n\n\\section{Solving Logarithmic Functions}\nYou can apply the rules that have been previously explained in order to solve\nfor expressions bound up in logarithmic or exponential expressions.  The genral\ncase for solving these types of problems is explained below:\n\n\\begin{enumerate}\n  \\item{Reduce all variables that are bound in exponential expressions to\n    loosely hanging variables that are included in logarithmic expressions}\n  \\item{Apply the three rules that are stated above}\n  \\item{Expand}\n  \\item{Simplify}\n\\end{enumerate}\n", "meta": {"hexsha": "b569a39dbc566f91de0b6d652391f13030bfcdc2", "size": 2939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/3_exponential_logarithmic_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/3_exponential_logarithmic_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/3_exponential_logarithmic_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": 34.1744186047, "max_line_length": 80, "alphanum_fraction": 0.7567199728, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6986127760006858}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Transformations}\\label{sec:transfs}\n\nRandom variables can be transformed into other random variables, and the distribution of a transformed variable can be deduced from the distribution of the original variable. Transformations of discrete distributions are relatively straightforward: here we focus on transformations of continuous distributions.\n\nApplying a transformation $g:\\R\\to\\R$ to a random variable $X:\\Omega\\to\\R$ involves the \\emph{composition} of these two functions,\n\\[\n\\begin{array}{rlcl}\ng(X) : \t& \\Omega & \\to \t\t& \\R \\\\\n\t\t& \\omega & \\mapsto\t& g\\big[X(\\omega)\\big],\n\\end{array}\n\\]\n\nThis can be interpreted in two ways:\n\\ben \n\\it $g(X)$ is a random variable on the probability space $(\\Omega,\\prob)$;\n\\it $g$ is a random variable on the probability space $(\\R,\\prob_X)$,\n\\een\nwhere $\\prob_X$ is the distribution of $X$. Here we focus on the first interpretation with $Y=g(X)$ denoting the transformed variable.\n\n%-----------------------------\n\\subsection{Support}\nMany PDFs are non-zero only over certain subsets of $\\R$. When we transform continuous distributions we need only consider these subsets, provided we ensure that those over which PDFs are zero are carried over correctly into the transformed space. For technical reasons, it is not quite enough to focus on the \\emph{range} of the random variable in question: instead we must consider the smallest closed set that contains the range (a closed set is one that contains all its limit points). This is called the \\emph{support} of the associated PDF.\n\n\\begin{definition}\nThe \\emph{support} of an arbitrary function $h:\\R\\to\\R$, denoted by $\\supp(h)$, is the smallest closed set for which $h(x)=0$ for all $x\\notin\\supp(h)$. \n\\end{definition}\n\nLet $Y = g(X)$ where $g:\\R\\to\\R$ is a transformation, and let $f_X$ and $f_Y$ denote the PMFs/PDFs of $X$ and $Y$ respectively. The support of the transformed variable $Y = g(X)$ is given by\n\\[\n\\supp(f_Y) = \\big\\{g(x) : x\\in\\supp(f_X)\\big\\}.\n\\]\nIn fact, $\\supp(f_Y)$ should be defined as the \\emph{closure} of this set, which is obtained by adding in its limit points where necessary. We will not pursue such matters here.\n\n%-----------------------------\n\\subsection{Linear transformations}\n\nLet $X$ be a random variable and let $Y = aX + b$ where $a\\neq 0$. \n\nThe CDF of of the transformed variable $Y$ can be expressed in terms of the CDF of $X$ as follows:\n\\[\nF_Y(y) \n\t= \\prob(Y\\leq y) \n\t= \\prob(aX+b\\leq y)\n\t= \\begin{cases}\n\t\t\\displaystyle\\prob\\left(X\\leq\\frac{y-b}{a}\\right) = \\phantom{1 -\\ } F_X\\left(\\frac{y-b}{a}\\right)\t\t& \\text{if $a>0$,} \\\\[3ex]\n\t\t\\displaystyle\\prob\\left(X>\\frac{y-b}{a}\\right)\t = 1 - F_X\\left(\\frac{y-b}{a}\\right)\t& \\text{if $a<0$.}\n\t\\end{cases}\n\\]\nUsing the chain rule, the PDF of $Y$ can then be expressed in terms of the PDF of $X$:\n\\smallskip\n\\[\nf_Y(y) = \\frac{d}{dy}F_Y(y) = \n\t\\left\\{\n\t\\begin{array}{ll}\n\t\t\\phantom{-}\\displaystyle\\frac{1}{a}f_X\\left(\\frac{y-b}{a}\\right)\t& \\text{if $a>0$,} \\\\[3ex]\n\t\t-\\displaystyle\\frac{1}{a}f_X\\left(\\frac{y-b}{a}\\right)\t\t\t\t& \\text{if $a<0$.}\n\t\\end{array}\n\t\\right\\}\n\t= \\frac{1}{|a|}f_X\\left(\\frac{y-b}{a}\\right).\n\\]\n% example: linear transf.\n\\begin{example}\nLet $X\\sim\\text{Uniform}[0,1]$. Find the distribution of the random variable $Y = 3X + 7$.\n\\begin{solution}\nLet $g(x) = 3x+7$ denote the transformation. The PDF of $X\\sim\\text{Uniform}[0,1]$ is\n\\[\nf_X(x) = \\begin{cases}\n\t1\t& 0\\leq x\\leq 1 \\\\\n\t0\t& \\text{otherwise.}\n\\end{cases}\n\\]\nFirst we see that $\\supp(f_X)$ is transformed as follows:\n\\[\n\\supp(f_Y) = \\{g(x) : x\\in\\supp(f_X)\\} = \\{3x+7 : x\\in [0,1]\\} = [7,10].\n\\]\nFrom the above discussion,\n\\[\nf_Y(y) = \\displaystyle\\frac{1}{3}f_X\\left(\\frac{y-7}{3}\\right) \n\t= \\begin{cases}\n\t\t1/3\t& \\text{if $7\\leq y\\leq 10$,} \\\\\n\t\t0\t& \\text{otherwise,}\n\t\\end{cases}\n\\]\nso $Y\\sim\\text{Uniform}[7,10]$. We see that the original distribution has been scaled by a factor of $3$ and shifted $7$ units to the right.\n\\end{solution}\n\\end{example}\n\nThese ideas can be extended to any one-to-one transformation of $X$.\n\n%-----------------------------\n\\subsection{Transformations of CDFs}\n\n\\begin{theorem}\\label{thm:transf_cdf}\nIf $g:\\R\\to\\R$ is one-to-one over $\\supp(f_X)$ the CDF of $Y=g(X)$ is\n\\[\nF_Y(y) = \\begin{cases}\nF_X\\big[g^{-1}(y)\\big]\t\t& \\text{if $g$ is increasing, and} \\\\[1ex]\n1 - F_X\\big[g^{-1}(y)\\big]\t& \\text{if $g$ is decreasing.} \n\\end{cases}\n\\]\n\\end{theorem}\n\n\\begin{proof}\n\\ben\n\\it If $g$ is increasing, $g(x)\\leq y$ implies that $x\\leq g^{-1}(y)$ so\n\\[\nF_Y(y) \n\t= \\prob(Y\\leq y) \n\t= \\prob\\big[g(X)\\leq y\\big] \n\t= \\prob\\big[X\\leq g^{-1}(y)\\big]\n\t= F_X\\big[g^{-1}(y)\\big].\n\\]\n\\it If $g$ is decreasing, $g(x)\\leq y$ implies that $x\\geq g^{-1}(y)$ so\n\\begin{align*}\nF_Y(y) \n\t= \\prob(Y\\leq y) \n\t= \\prob\\big[g(X)\\leq y\\big] \n\t& = \\prob\\big[X\\geq g^{-1}(y)\\big] \\\\\n\t& = 1 - \\prob\\big[X\\leq g^{-1}(y)\\big] \\quad\\text{(because $X$ is a continuous r.v.)}\\\\\n\t& = 1 - F_X\\big[g^{-1}(y)\\big].\n\\end{align*}\n\\een\n\\end{proof}\t\n\n\\begin{example}\nLet $X\\sim\\text{Uniform}[0,1]$ and let $Y = -\\displaystyle\\frac{1}{\\lambda}\\log X$ where $\\lambda>0$. Show that $Y\\sim\\text{Exponential}(\\lambda)$ where $\\lambda$ is a rate parameter.\n\\begin{solution}\nThe CDF and PDF of $X\\sim\\text{Uniform}[0,1]$ are, respectively,\n\\[\\begin{array}{lcl}\nF_X(x) = \\begin{cases}\n\t0\t& x < 0, \\\\ \n\tx\t& 0\\leq x\\leq 1 \\\\\n\t1\t& x > 1\n\\end{cases}\n& \\text{and} &\nf_X(x) = \\begin{cases}\n\t1\t& 0\\leq x\\leq 1 \\\\\n\t0\t& \\text{otherwise.}\n\\end{cases}\n\\end{array}\\]\nLet $g(x) = -\\log x/\\lambda$ denote the transformation. Because $\\lambda>0$ we see that $\\supp(f_X)$ is transformed to\n\\[\n\\supp(f_Y) = \\{g(x) : x\\in\\supp(f_X)\\} =\\{-\\log/\\lambda : x\\in[0,1]\\} = [0,\\infty).\n\\]\nThe transformation is strictly decreasing over $\\supp(f_X)$, and its inverse is $g^{-1}(y) = e^{-\\lambda y}$ over $\\supp(f_Y)$. Hence, by Theorem~\\ref{thm:transf_cdf},\n\\[\nF_Y(y) \n\t= 1 - F_X\\big[g^{-1}(y)\\big]\n\t= 1 - F_X(e^{-\\lambda y})\n\t= 1 - e^{-\\lambda y} \\quad\\text{for}\\quad y\\geq 0.\n\\]\nThis is the CDF of the $\\text{Exponential}(\\lambda)$ distribution (where $\\lambda$ is a rate parameter).\n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{Transformations of PDFs}\n\n\\begin{theorem}\\label{thm:transf_pdfs}\nIf $g:\\R\\to\\R$ is one-to-one over $\\supp(f_X)$ the PDF of $Y=g(X)$ is\n\\[\nf_Y(y) = f_X\\big[g^{-1}(y)\\big]\\left|\\frac{d}{dy}g^{-1}(y)\\right| %\\quad\\text{for all}\\quad y\\in \\supp(f_Y).\n\\]\n\\end{theorem}\n\n\\begin{proof}\nFor clarity of notation, let $h(y)$ denote the inverse function $g^{-1}(y)$.\n\\ben\n\\it If $g$ is increasing then $F_Y(y) = F_X\\big[g^{-1}(y)\\big]$, so by the chain rule (and using the fact that $h$ is also increasing),\n\\begin{align*}\nf_Y(y)\n\t= \\frac{d}{dy} F_Y(y)\n\t& = \\frac{d}{dy} F_X\\big[h(y)\\big] \\\\\n\t& = \\frac{d}{dh(y)} F_X\\big[h(y)\\big]\\cdot \\frac{dh(y)}{dy} \\\\\n\t& = f_X\\big[h(y)\\big]\\left|\\frac{dh(y)}{dy}\\right|, \\text{\\qquad\\qquad because } \\frac{dh(y)}{dy}>0\\text{ over $\\supp(f_Y)$.}\n\\end{align*}\n\n\\it If $g$ decreasing, $F_Y(y) = 1 - F_X\\big[g^{-1}(y)\\big]$, so by the chain rule  (and using the fact that $h$ is also decreasing),\n\\begin{align*}\nf_Y(y)\n\t= \\frac{d}{dy} F_Y(y)\n\t& = \\frac{d}{dy} \\big[1 - F_X[h(y)]\\big] \\\\\n\t& = 0 - \\frac{d}{dh(y)} F_X\\big[h(y)\\big]\\cdot \\frac{dh(y)}{dy} \\\\\n\t& = - f_X\\big[h(y)\\big] \\frac{dh(y)}{dy} \\\\\n\t& = f_X\\big[h(y)\\big]\\left|\\frac{dh(y)}{dy}\\right|, \\text{\\qquad\\qquad because} \\frac{dh(y)}{dy}<0\\text{ over $\\supp(f_Y)$.}\n\\end{align*}\n\\een\n\\end{proof}\n\n% remark\n\\begin{remark}\nThe term $\\left|\\frac{d}{dy}g^{-1}(y)\\right|$ in Theorem~\\ref{thm:transf_pdfs} is a \\emph{scale factor}, which ensures that $f_Y$ integrates to one.\n\\end{remark}\n\n\\begin{example}\nLet $X$ be a continuous random variable with the following PDF,\n\\[\nf_X(x) = \\begin{cases}\n\t1/x^2\t& \\text{for $x > 1$,} \\\\\n\t0\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nFind the PDF of $Y=1/X$.\n\\end{example}\n\n\\begin{solution}\nLet $g(x) = 1/x$. Since $\\supp(f_X)=[x,\\infty)$, the support of $f_Y$ is \n\\[\n\\supp(f_Y) = \\{g(x): x\\in\\supp(f_X)\\} = \\{1/x :x\\in[0,\\infty)\\} = [0,1].\n\\]\nThe transformation is one-to-one over $\\supp(f_X)$, and its inverse is $g^{-1}(y) = 1/y$ over $\\supp(f_Y)$. Hence, by Theorem~\\ref{thm:transf_pdfs}, the PDF of $Y$ is given by\n\\begin{align*}\nf_Y(y)\n\t& = f_X\\big[g^{-1}(y)\\big]\\left|\\frac{d}{dy}g^{-1}(y)\\right| \\\\\n\t& = f_X\\left(\\frac{1}{y}\\right)\\left|\\frac{d}{dy}\\left(\\frac{1}{y}\\right)\\right| \\\\\n\t& = y^2 \\left|-\\frac{1}{y^2}\\right| \n\t= \\begin{cases}\n\t\t1\t& \\text{for } 0<y<1 \\\\\n\t\t0\t& \\text{otherwise.}\n\t\\end{cases}\n\\end{align*}\nThus $Y\\sim\\text{Uniform}(0,1)$.\n\\end{solution}\n\n\n%-----------------------------\n\\subsection{The probability integral transform}\n\nWhat happens when a random variable is transformed using its own CDF? \n\n\\begin{theorem}%[The Probability Integral Transform]\nLet $X$ be a continuous random variable, and suppose that the inverse of its CDF exists for all $x\\in\\R$. Then the random variable $U=F(X)$ has the uniform distribution on $[0,1]$.\n\\end{theorem}\n\n\\begin{proof}\nBecause $F(x)=P(X\\leq x)$ is a CDF we know that $F(x)\\in [0,1]$ for all $x\\in\\R$. In particular, $\\prob(U<0)=0$ and $\\prob(U>1)=0$. For $u\\in[0,1]$, because the inverse $F^{-1}$ exists for all $x\\in\\R$ we have that\n\\begin{align*}\nF_U(u) = P(U\\leq u) \n\t& = P\\big(F(X)\\leq u\\big) \\\\\n\t& = P\\big(X\\leq F^{-1}(u)\\big) \\\\\n\t& = F\\big(F^{-1}(u)\\big) \\\\\n\t& = u,\n\\end{align*}\nwhich is the CDF of the continuous uniform distribution on $[0,1]$.\n\\end{proof}\n\n% corollary\n\\begin{corollary}\nLet $F$ be a CDF whose inverse exists for all $x\\in\\R$, and let $U\\sim\\text{Uniform}[0,1]$. Then $F$ is the CDF of the random variable $X = F^{-1}(U)$.\n\\end{corollary}\n\nAlthough it is difficult to generate truly random numbers, there are fast deterministic algorithms which generate numbers that are approximately random - such numbers are called \\emph{pseudo-random numbers}. Many such algorithms can generate numbers that are approximately uniformly distributed in $[0,1]$. Using the probability integral transform we can convert these into pseudo-random numbers from other continuous distributions.\n\n\\ben\n\\it First we obtain a uniformly distributed pseudo-random number $u\\in [0,1]$.\n\\it The number $x = F^{-1}(u)$ is then a pseudo-random number from the distribution $F$.\n\\een\n\n% example: \n\\begin{example}\nGiven an algorithm which generates uniformly distributed pseudo-random numbers in the range $[0,1]$, show how to obtain a pseudo-random number from the exponential distribution having rate parameter $2$.\n\\begin{solution}\nThe CDF of the exponential distribution with rate parameter $2$ is\n\\[\nF(x) = \\begin{cases}\n\t1 - e^{-2x}\t& x>0 \\\\\n\t0\t\t\t& \\text{otherwise.}\n\\end{cases}\t\n\\]\nFirst we invert $F$:\n\\begin{align*}\nu = 1 - e^{-2x} \n\t& \\iff e^{-2x} = 1-u \\\\\n\t& \\iff e^x = \\frac{1}{\\sqrt{1-u}} \\\\\n\t& \\iff x = \\log\\left(\\frac{1}{\\sqrt{1-u}}\\right)\n\\end{align*}\nThen we generate a pseudo-random number $u$ from the $\\text{Uniform}[0,1]$ distribution and\n\\[\nx = \\log\\left(\\frac{1}{\\sqrt{1-u}}\\right)\n\\]\nwhich is a pseudo-random number from the $\\text{Exponential}(\\lambda)$ distribution.\n\\end{solution}\n\\end{example}\n\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question % transf\nLet $X\\sim\\text{Uniform}(-1,1)$. Find the CDF and PDF of $X^2$.\n\n\\begin{answer}\nThe PDF of $X$ is \n\\[\nf_X(x) = \\left\\{\\begin{array}{ll}\n\t1/2\t& -1\\leq x\\leq 1 \\\\\n\t0\t& \\text{otherwise}\n\\end{array}\\right.\t\n\\]\t\nFor $x\\in[-1,1]$, \n\\[\n\\prob(X\\leq x) \n\t= \\int_{-\\infty}^x f_X(t)\\,dt\n\t= \\int_{-1}^x \\frac{1}{2}\\,dt\n\t= \\left[\\frac{t}{2}\\right]_{-1}^x\n\t= \\frac{1}{2}(x+1).\n\\]\nThe CDF of $X$ is:\n\\[\nF(x) = \\left\\{\\begin{array}{ll}\n\t0\t\t\t\t \t& x < -1, \\\\\n\t\\frac{1}{2}(x+1) \t& -1\\leq x\\leq 1, \\\\\n\t1\t\t\t\t\t& x > 1.\n\\end{array}\\right.\t\n\\]\nLet $Y=X^2$. For $0\\leq y\\leq 1$ we have\n\\begin{align*}\n\\prob(Y\\leq y)\n\t= \\prob(X^2\\leq y)\n\t& = \\prob(-\\sqrt{y}\\leq X\\leq\\sqrt{y}) \\\\\n\t& = \\prob(X\\leq\\sqrt{y}) - \\prob(X\\leq-\\sqrt{y}) \\\\\n\t& = \\sqrt{y}.\n\\end{align*}\nHence the CDF of $Y$ is\n\\[\nF_Y(y) = \\left\\{\\begin{array}{ll}\n\t0\t\t \t& y < 0, \\\\\n\t\\sqrt{y} \t& 0\\leq y\\leq 1, \\\\\n\t1\t\t\t& y > 1.\n\\end{array}\\right.\t\n\\]\nand the PDF of $Y$ is\n\\[\nf_Y(y) = \\left\\{\\begin{array}{ll}\n\\frac{1}{2}y^{-1/2}\t& 0\\leq y\\leq 1, \\\\\n0\t\t\t\t\t& \\text{otherwise}.\n\\end{array}\\right.\t\n\\]\n\\end{answer}\n\n\\question % transf\nSuppose that $X$ has the exponential distribution with rate parameter $\\lambda>0$. (The PDF of $X$ is $f(x) = \\lambda\\exp(-\\lambda x)$ for $x \\geq 0$ and zero otherwise.)\n%\\[\n%f(x) = \\left\\{\\begin{array}{ll}\n%\t\\lambda\\exp(-\\lambda x)\t& \\text{for } x \\geq 0, \\\\\n%\t0\t\t\t\t\t\t& \\text{otherwise.}\n%\\end{array}\\right.\n%\\]\nFind the PDFs of $Y=X^2$ and $Z=e^X$.\n\n\\begin{answer}\n\\ben\n\\it % << (i)\nThe transformation $g(x)=x^2$ is one-to-one and increasing over $[0,\\infty)$; its inverse function is\n\\[\ng^{-1}(y) =  \\sqrt{y},\\text{\\quad which has first derivative \\quad} \\frac{d}{dy}g^{-1}(y) = \\frac{1}{2\\sqrt{y}}.\n\\]\n\nSince $\\supp(f_X)=[0,\\infty)$ it follows immediately that $\\supp(f_Y)=[0,\\infty)$.\n\\par\nFor $y>0$, \n\\[\nf_Y(y) \n\t= f_X\\big[g^{-1}(y)\\big]\\left|\\frac{d}{dy}g^{-1}(y)\\right| \n\t= \\lambda\\exp(\\lambda\\sqrt{y}) \\left| \\frac{1}{2\\sqrt{y}}\\right|\n\t= \\frac{\\lambda}{2\\sqrt{y}}\\exp(-\\lambda\\sqrt{y}).\n\\]\nHence the PDF of $Y=X^2$ is given by\n\\[\nf_Y(y) = \\left\\{\\begin{array}{ll}\n\t\\displaystyle\\frac{\\lambda}{2\\sqrt{y}}\\exp(-\\lambda\\sqrt{y}) & y\\geq 0, \\\\[2ex]\n\t0 & \\text{otherwise}.\n\\end{array}\\right.\n\\]\n\n\\it % << (ii)\nThe transformation $g(x)=e^x$ is one-to-one and increasing over $[0,\\infty)$; its inverse function is\n\\[\ng^{-1}(z) = \\log y \\text{\\quad and\\quad} \\frac{d}{dy}g^{-1}(z) = \\frac{1}{z}.\n\\]\n\nSince $\\supp(f_X)=[0,\\infty)$ it follows immediately that $\\supp(f_Z)=[1,\\infty)$.\n\\par\nFor $z\\geq 1$,\n\\[\nf_Z(z) \n\t= f_X\\big[g^{-1}(z)\\big]\\left|\\frac{d}{dz}g^{-1}(z)\\right|\n\t= \\lambda\\exp(-\\lambda\\log z)\\left|\\frac{1}{z}\\right| \n\t= \\lambda z^{-(\\lambda+1)}.\n\\]\nHence the PDF of $Z=e^X$ is given by\n\\[\nf_Z(z) = \\left\\{\\begin{array}{ll}\n\t\\lambda z^{-(\\lambda+1)} & z\\geq 1, \\\\\n\t0 & \\text{otherwise}.\n\\end{array}\\right.\n\\]\n\\een\n\\end{answer}\n\n\\question % transf\nA continuous random variable $U$ has PDF\n$f(u) = 12u^{2}(1-u)$ for $0 < u < 1$ and zero otherwise.\n%\\[\n%f(u) = \\left\\{\\begin{array}{ll}\n%\t12u^{2}(1-u) \t& \\text{for}\\quad 0 < u < 1, \\\\\n%\t0\t\t\t\t& \\text{otherwise.}\n%\\end{array}\\right.\t\n%\\]\nFind the PDF of $V = (1 - U)^{2}$.\n\\begin{answer}\n\\bit\n\\it The transformation $g(u) = (1 - u)^{2}$ is one-to-one and decreasing over $[0,1]$.  \n\\it The inverse transformation is $g^{-1}(v) = 1 - v^{1/2}$, for which $\\displaystyle \\frac{d}{dv}g^{-1}(v) = -\\frac{1}{2v^{1/2}}$.\n\\it Since $\\supp(f_U)=(0,1)$ it follows that $\\supp(f_V)=(0,1)$. \n\\eit\nHence for $0<v<1$ the PDF of $V$ is \n\\begin{align*}\nf_V(v)\n\t& = f_U\\big[g^{-1}(v)\\big]\\left|\\frac{d}{dv}g^{-1}(v)\\right| \\\\\n\t& = 12(1-v^{1/2})^2 v^{1/2}\\left|-\\frac{1}{2v^{1/2}}\\right| \\\\\n\t& = 6(1-v^{1/2})^2,\n\\end{align*}\nand zero otherwise. \n\\end{answer}\n\n\\question % probability integral transform\nThe CDF of a random variable $X$ is $F(x) = 1-1/x^3$ for $x\\geq 1$ and zero otherwise.\n%\\[\n%F_X(x) = \\left\\{\\begin{array}{ll}\n%\t\\displaystyle 1-\\frac{1}{x^3}\t\t& \\text{for $x\\geq 1$,} \\\\\n%\t0\t\t\t\t\t\t\t\t& \\text{otherwise.}\n%\\end{array}\\right.\n%\\]\nFind the CDF of the random variable $Y=1/X$, then describe how a pseudo-random number from the distribution of $Y$ can be obtained using an algorithm that generates uniformly distributed pseudo-random numbers in the range $[0,1]$.\n\\begin{answer}\nLet $g(x) = 1/x$ denote the transformation. \n\\bit\n\\it $\\supp(f_X) = [1,\\infty] \\Rightarrow\\ \\supp(f_Y) = [0,1]$.\n\\it The inverse transformation: $g^{-1}(y) = 1/y$.\n\\eit\n\\par\nBecause $g(x)$ is a decreasing function over $\\supp(f_X)$,\n\\[\nF_Y(y) \n\t= 1 - F_X\\big[g^{-1}(y)\\big]\n\t= 1 - F_X\\left(\\frac{1}{y}\\right)\n\t= \\left\\{\\begin{array}{ll}\n\t\t0\t& y < 0 \\\\\n\t\ty^3\t& 0\\leq y\\leq 1 \\\\\n\t\t1\t& y > 1.\n\t\\end{array}\\right.\n\\]\nFor the second part we use the fact that $F_Y(Y)\\sim\\text{Uniform}(0,1)$. First we invert $F_Y$ by letting $u=F_Y(y)$ from which we obtain.\n\\[\ny = F_Y^{-1}(u) = u^{1/3}.\n\\]\nNext we obtain a pseudo-random number $u$ from the $\\text{Uniform}[0,1]$ distribution, then compute\n\\[\ny = u^{1/3},\n\\]\nwhich is a pseudo-random number from the distribution of $Y$.\n\\end{answer}\n\n\\end{questions}\n\\end{exercise}\n", "meta": {"hexsha": "4e4284f29cd9a549a82071c2160c38b5f035d8cb", "size": 16119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/03C_transformations.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/03C_transformations.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/03C_transformations.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": 34.2957446809, "max_line_length": 546, "alphanum_fraction": 0.6211923817, "num_tokens": 6169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.9019206679615432, "lm_q1q2_score": 0.6986127632379403}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage[utf8x]{luainputenc}\n\\usepackage{aeguill}\n%\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\\usepackage{fullpage}\n\\usepackage{fancyhdr}\n\\setlength{\\headheight}{12pt}\n\\pagestyle{fancy}\n\\chead{Linear Algebra}\n\\lhead{September 23, 2015}\n\\rhead{Jon Allen}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n%\\renewcommand{\\labelenumii}{\\alph{enumii}.}\n%\\renewcommand{\\labelenumiii}{\\alph{enumiii}.}\n%\\renewcommand{\\labelenumi}{(\\arabic{enumi})}\n\\section*{Excercise Set 1}\n\\begin{enumerate}\n\\item\nProve the matrix\n\\[A=\\left[\\begin{array}{cc}a&b\\\\c&d\\end{array}\\right]\\]\nis invertible if and only if $ad-bc\\ne 0$. Find $A^{-1}$ in this case by solving a system of two equations with two unknowns.\n\nWe need some matrix $A^{-1}$ such that $AA^{-1}=I_2$.\nAssume $A^{-1}$ exists, then let $A^{-1}=\\left[\\begin{array}{cc}a'&b'\\\\c'&d'\\end{array}\\right]$ and we have\n\\begin{align*}\n  AA^{-1}&= \\left[\\begin{array}{cc}a&b\\\\c&d\\end{array}\\right]\n            \\left[\\begin{array}{cc}a'&b'\\\\c'&d'\\end{array}\\right]\\\\\n  &=\\left[\\begin{array}{cc}aa'+bc'&ab'+bd'\\\\ca'+dc'&cb'+dd'\\end{array}\\right]\n  =\\left[\\begin{array}{cc}1&0\\\\0&1\\end{array}\\right]\\\\\n\\end{align*}\nIn particular\n\\begin{align*}\n  aa'+bc'&=1&\n  ca'+dc'&=0\\\\\n\\end{align*}\nNow if $c=0$ then $d=0$ or $c'=0$. We know that $d\\ne 0$ because $cb'+dd'=1$. And so if $c=0$ then $c'=0$. But then $aa'+bc'=1$ so $a\\ne 0$ in this case. We will proceed in two cases then for $c\\ne 0$ and $a\\ne 0$.\n\nIf we assume that $c\\ne 0$ then we have\n\\begin{align*}\n  ca'+dc'&=0&\n  a'+\\frac{d}{c}c'&=0&\n  -aa'-\\frac{ad}{c}c'&=0\\\\\n\\end{align*}\nNow if we add $aa'+bc'=1$ to the above result we get $\\left(b-\\frac{ad}{c}\\right)c'=1$. Solving for $c'$ gives us $c'=-\\frac{c}{ad-bc}$. Using we can solve $ca'+dc'=0$ to find $a'=\\frac{d}{ad-bc}$. Moving on we have\n\\begin{align*}\n  cb'+dd'&=1&b'+\\frac{d}{c}d'&=\\frac{1}{c}&-ab'-\\frac{ad}{c}d'&=-\\frac{a}{c}\n\\end{align*}\nAdding in $ab'+bd'=0$ leads us to $\\frac{bc-ad}{c}d'=\\frac{-a}{c}$, or $d'=\\frac{a}{ad-bc}$. And finally substituting $d'$ in for $cb'+dd'=1$ leads to $cb'+d\\frac{a}{ad-bc}=cb'+1+\\frac{bc}{ad-bc}=1$ or $b'=-\\frac{b}{ad-bc}$.\n\nThe case when $a\\ne 0$ is similar.\n\\begin{align*}\n  ab'+bd'&=0&cb'+dd'&=1\\\\\n  -cb'-\\frac{cb}{a}d'&=0&cb'+dd'&=1\\\\\n  \\left(d-\\frac{cb}{a}\\right)d'&=1&d'&=\\frac{a}{ad-bc}\\\\\n\\end{align*}\nIf we continue as we did when $c\\ne 0$ then we will arrive at $A^{-1}=\\frac{1}{ad-bc}\\left[\\begin{array}{cc}d&-b\\\\-c&a\\end{array}\\right]$ just as we did when $c\\ne 0$.\n\nIn this way we see that when we assume that $A^{-1}$ exists and that $ad-bc=0$ we arrive at a contradiction. Namely that $\\frac{1}{ad-bc}$ is undefined and therefore $A^{-1}$ can't exist. However, if we assume that $ad-bc\\ne 0$ we find our inverse, and so it must exist. Thus we have proven both directions of the hypothesis.\n$\\Box$\n\\item\nLet\n\\[A=\\left[\\begin{array}{ccc}0&0&1\\\\1&0&2\\\\0&1&-3\\end{array}\\right]\\]\n  \\begin{enumerate}\n  \\item\n  Show that $A^3+3A^2-2A-I_3=\\mathbf{0}$\n  \\begin{align*}\n    A^3+3A^2-2A-I_3&=0\\\\\n    (A^2+3A-2I_3)A&=I_3\\\\\n    \\left( \\left[\\begin{array}{ccc}0&0&1\\\\1&0&2\\\\0&1&-3\\end{array}\\right]^2\n    +3\\left[\\begin{array}{ccc}0&0&1\\\\1&0&2\\\\0&1&-3\\end{array}\\right]\n    +\\left[\\begin{array}{ccc}-2&0&0\\\\0&-2&0\\\\0&0&-2\\end{array}\\right]\n    \\right)A&=I_3\\\\\n    \\left( \\left[\\begin{array}{ccc}0&1&-3\\\\0&2&-5\\\\1&-3&11\\end{array}\\right]\n    +\\left[\\begin{array}{ccc}0&0&3\\\\3&0&6\\\\0&3&-9\\end{array}\\right]\n    +\\left[\\begin{array}{ccc}-2&0&0\\\\0&-2&0\\\\0&0&-2\\end{array}\\right]\n    \\right)A&=I_3\\\\\n    \\left[\\begin{array}{ccc}-2&1&0\\\\3&0&1\\\\1&0&0\\end{array}\\right]\n    \\left[\\begin{array}{ccc}0&0&1\\\\1&0&2\\\\0&1&-3\\end{array}\\right]&=I_3\\\\\n    \\left[\\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\end{array}\\right]&=I_3\n  \\end{align*}\n  \\item\n  Use part (a) to see that $A$ is invertible and compute $A^{-1}$\n  \n  Obviously $A^{-1}=A^2+3A-2I_3=\\left[\\begin{array}{ccc}-2&1&0\\\\3&0&1\\\\1&0&0\\end{array}\\right]$\n  \\end{enumerate}\n\\item\nLet $A\\in \\mathcal{M}_n$ be a diagonal matrix. Prove that $A$ is invertible if and only if $\\text{ent}_{ii}(A)\\ne0$ for all $i\\le n$. Find $A^{-1}$ in this case.\n\nLet us assume that there exists some $\\text{ent}_{ii}(A)=0$ and that $A^{-1}$ exists with $\\text{ent}_{jk}(A^{-1})=a_{jk}^{-1}$ and $\\text{ent}_{jk}(A)=a_{jk}$. Then $\\text{ent}_{ii}(AA^{-1})=\\sum\\limits_{k=1}^n{a_{ik}a_{ki}^{-1}}=\\sum\\limits_{k=1}^n{0a_{ki}^{-1}}=0$. But $AA^{-1}=I_n$ and $\\text{ent}_{ii}(I_n)=1$ and so we have a contradiction.\n\nNow lets assume that $\\text{ent}_{ii}(A)=c_i$ with $i\\le n$ and $c_i\\ne 0$. Lets choose another diagonal matrix and name it $A^{-1}$. We will assign $\\text{ent}_{ii}(A^{-1})=c_{i}^{-1}$. Now we see that if we choose any $i\\le n,j\\le n$ such that $j\\ne i$ then we see that $\\text{ent}_{ij}(AA^{-1})=\\sum\\limits_{k=1}^n{a_{ik}a_{kj}^{-1}}=0+\\dots+a_{ii}a_{ij}^{-1}+a_{ij}a_{jj}^{-1}+\\dots0=0+\\dots+a_{ii}0+0a_{jj}^{-1}+\\dots0=0$.\nBut $\\text{ent}_{ii}(AA^{-1})=\\sum\\limits_{k=1}^n{a_{ik}a_{ki}^{-1}}=0+\\dots+a_{ii}a_{ii}^{-1}+\\dots+0=cc^{-1}=1$. And so we see that $AA^{-1}$ is a diagonal matrix with all ones for its entries. But that is $I_n$ and so we have found the inverse of $A^{-1}$.\n$\\Box$\n\\item\nIf $A,B\\in \\mathcal{M_n}$ are invertible such that $A+B\\ne 0$, does it follow that $(A+B)^{-1}$ exists? Prove or find a counterexample.\n\n\\[\n\\left[\\begin{array}{cc}3&2\\\\8&4\\end{array}\\right]+\n\\left[\\begin{array}{cc}3&2\\\\4&4\\end{array}\\right]\n=\\left[\\begin{array}{cc}6&4\\\\12&16\\end{array}\\right]\n\\]\n\nNotice that $3\\cdot 4-8\\cdot 2=-4$ and $3\\cdot 4-2\\cdot 4=4$ but $6\\cdot8-4\\cdot 12=6\\cdot4\\cdot2-4\\cdot2\\cdot6=0$ and so by excercise 1 we have found a counterexample.\n\\end{enumerate}\n\\section*{Excercise Set 2}\n\n\\[A=\n\\left[\\begin{array}{ccccc}\n  a_{11}&a_{12}&a_{13}&a_{14}&a_{15}\\\\\n  a_{21}&a_{22}&a_{23}&a_{24}&a_{25}\\\\\n  a_{31}&a_{32}&a_{33}&a_{34}&a_{35}\\\\\n  a_{41}&a_{42}&a_{43}&a_{44}&a_{45}\n\\end{array}\\right]\\]\n\n\\begin{enumerate}\n\\item\nFor the matrix $A$ in the example above, determine $E_{3\\to c3}$ where $c$ is any nonzero real number.\n\n\\[E_{3\\to c3}=\\left[\\begin{array}{cccc}1&0&0&0\\\\0&1&0&0\\\\0&0&c&0\\\\0&0&0&1\\\\\\end{array}\\right]\\]\n\n\\item\nFor the matrix $A$ in the example above, determine $E_{4\\to4+c2}$ where $c$ is any nonzero real number.\n\n\\[E_{4\\to 4+c2}=\\left[\\begin{array}{cccc}1&0&0&0\\\\0&1&0&0\\\\0&0&1&0\\\\0&c&0&1\\\\\\end{array}\\right]\\]\n\n\\item\nProve that each of $E_{i\\leftrightarrow k},E_{i\\to ci}, E_{i\\to i+ck}$ is invertible by finding an inverse. Prove that the inverse of an elementary matrix is an elementary matrix. \n\nWe assume that $i\\ne k$.\nWe posit that $E_{i\\leftrightarrow k}$ is the identity matrix, save that $\\text{ent}_{ii}E_{i\\leftrightarrow k}=\\text{ent}_{kk}E_{i\\leftrightarrow k}=0$ and $\\text{ent}_{ki}E_{i\\leftrightarrow k}=\\text{ent}_{ik}E_{i\\leftrightarrow k}=0$\n\nWe shall now verify this claim.\nFirst we choose some $j\\not\\in\\{i,k\\}$ and any $l$.\nNow we see that for any $A\\in \\mathcal{M}_n$ we have $\\text{ent}_{jl}(E_{i\\leftrightarrow k}A)=\\sum\\limits_{m=1}^n{\\text{ent}_{jm}(E_{i\\leftrightarrow k})a_{ml}}=a_{jl}$ because all entries in the elementary matrix row are zero except the $j$ element which is one.\nAnd so as we wish $E_{i\\leftrightarrow k}$ leaves everything off of rows $i$ and $k$ undisturbed.\nNow lets see what happens for $\\text{ent}_{il}(E_{i\\leftrightarrow k}A)$ and $\\text{ent}_{kl}(E_{i\\leftrightarrow k}A)$.\n\\begin{align*}\n  \\text{ent}_{il}(E_{i\\leftrightarrow k}A)\n  &=\\sum\\limits_{m=1}^n{\\text{ent}_{im}(E_{i\\leftrightarrow k})a_{ml}}=a_{kl}\\\\\n  \\text{ent}_{kl}(E_{i\\leftrightarrow k}A)\n  &=\\sum\\limits_{m=1}^n{\\text{ent}_{km}(E_{i\\leftrightarrow k})a_{ml}}=a_{il}\n\\end{align*}\nThus we see that the $i$ and $k$ rows of $A$ and its product with the elementary matrices have been switched. This occurs because $\\text{ent}_{ki}(E_{i\\leftrightarrow k})=\\text{ent}_{ik}(E_{i\\leftrightarrow k})=1$ but all other entries on these two rows is zero.\n\nNow that we know what $E_{i\\leftrightarrow k}$ is, we see that for\n$i\\ne l$ we have $\\text{ent}_{il}(E_{i\\leftrightarrow k}E_{i\\leftrightarrow k})=\\text{ent}_{kl}(E_{i\\leftrightarrow k})=0$.\nAnd we have $\\text{ent}_{ii}(E_{i\\leftrightarrow k}E_{i\\leftrightarrow k})=\\text{ent}_{ki}(E_{i\\leftrightarrow k})=1$.\nSimilarly \nwe have $\\text{ent}_{kl}(E_{i\\leftrightarrow k}E_{i\\leftrightarrow k})=\\text{ent}_{il}(E_{i\\leftrightarrow k})=0$ when $k\\ne l$ and\n$\\text{ent}_{kk}(E_{i\\leftrightarrow k}E_{i\\leftrightarrow k})=\\text{ent}_{ik}(E_{i\\leftrightarrow k})=1$ when $k=l$. Thus $E_{i\\leftrightarrow k}^{2}=I_n$ and so this matrix is it's own inverse.\n\nFor the matrix $E_{i\\to ci}$ we must have $c\\ne 0$.\nNow if we take the identity matrix, but change $\\text{ent}_{ii}$ to be $c$ then I claim we have our elementary matrix.\nAs above, when $j\\ne i$ we have $\\text{ent}_{jk}(E_{i\\to ci}A)=a_{jk}$ for any  $A\\in \\mathcal{M}_n$ and $k\\le n$.\nAnd so our matrix leaves all rows but $i$ untouched. Now if we examine row $i$ we see that $\\text{ent}_{ik}(E_{i\\to ci}A)=\\sum\\limits_{l=1}^n{\\text{ent}_{il}(E_{i\\to ci})a_{li}}=ca_{ik}$ as desired. So we have found our elementary matrix.\n\nNow let us examine $E_{i\\leftrightarrow (1/c)i}E_{i\\leftrightarrow ci}$. We have already seen that $\\text{ent}_{jk}(E_{i\\leftrightarrow (1/c)i}E_{i\\to ci})=\\text{ent}_{jk}(E_{i\\to ci})=\\text{ent}_{jk}(I_n)$. And $\\text{ent}_{ik}(E_{i\\leftrightarrow (1/c)i}E_{i\\to ci})=\\frac{1}{c}\\text{ent}_{ik}(E_{i\\to ci})$. Of course when $k\\ne i$ then this is zero and when $k=i$ then this entry will be $\\frac{1}{c}c=1$. Thus we have exactly the identity matrix. And so we have found our inverse.\n\nFinally we look at $E_{i\\to i+ck}$. As before we start with the identity matrix. This time the only entry on $I_n$ that we change is $\\text{ent}_{ik}(E_{i\\to i+ck})=c$.\n\nObviously if we have $j\\ne i, l\\le n$ and any $A\\in\\mathcal{M}_n$ then $\\text{ent}_{jl}(E_{i\\to i+ck}A)=\\sum\\limits_{m=1}^n{\\text{ent}_{jm}(E_{i\\to i+ck})a_{ml}}=a_{jl}$.\nBut $\\text{ent}_{il}(E_{i\\to i+ck}A)=\\sum\\limits_{m=1}^n{\\text{ent}_{im}(E_{i\\to i+ck})a_{ml}}=a_{il}+ca_{kl}$. Fantastic, we have found something that takes the entry from row k and multiplies it by c and adds it to the entry in row i, then places the result in row i. This then is the elementary matrix we require.\n\nNow if we take $E_{i\\to i-ck}$ for \n$j\\ne i, l\\le n$ we have $$\\text{ent}_{jl}(E_{i\\to i-ck}E_{i\\to i+ck})=\\sum\\limits_{m=1}^n{\\text{ent}_{jm}(E_{i\\to i-ck})\\text{ent}_{jm}(E_{i\\to i+ck})}=\\text{ent}_{jl}(I_n)$$\n\nAnd $\\text{ent}_{il}(E_{i\\to i-ck}E_{i\\to i+ck})=\\sum\\limits_{m=1}^n{\\text{ent}_{im}(E_{i\\to i-ck})\\text{ent}_{im}(E_{i\\to i+ck})}=\\text{ent}_{il}(E_{i\\to i+ck})-c\\cdot\\text{ent}_{kl}(E_{i\\to i+ck})$. Of course if $i=l$ then this will give us $1-0=1$ and if $k=l$ then we have $c-c=0$. This will leave us with our identity. And so we have our inverse.\n\nFor each of the three elementary matrices we have found an inverse, and thus one must exist. Further, these inverses are simply elementary matrices themselves.\n$\\Box$\n\\item\nDefine a relation $\\sim$ on $\\mathcal{M}_{m\\times n}$ given by $A\\sim B$ if and only if there exists a $P\\in \\mathcal{M}_{m\\times n}$ such that $A=PB$ where $P\\in \\mathcal{M}_{m\\times n}$ is a product of elementary matrices.\n\nWe know that $A=I_nA$ and $I_n$ is an elementary matrix and so this relation is reflexive.\n\nWe also know that every elementary matrix has an inverse and that inverse is an elementary matrix. And so if $P=E_1E_2\\dots E_n$ then $P^{-1}$ exists. In fact $P^{-1}=E_n^{-1}\\dots E_1^{-1}$ which is the product of elementary matrices also. Therefore if $A=PB$ then $P^{-1}A=B$ and so commutativity is preserved with this relation.\n\nNow of we have $P_1,P_2$ both products of elementary matrices, then it follows that $P_1P_2$ is also the product of elementary matrices. And so if $A=P_1B$ and $B=P_2C$ then $A=P_1(P_2C)=(P_1P_2)C$ and so the relation is transitive.\n\nThose are the three properties we need for the relation to fit the definition of an equivalence relation.\n$\\Box$\n\\end{enumerate}\n\\end{document}\n%hw 1.5:1,2b,3ce,10,11,13,14,15\n", "meta": {"hexsha": "e0742841b8b2024eb58d36de127ac65e4fe361c7", "size": 12075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear/linear-hw-2015-09-23.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": "linear/linear-hw-2015-09-23.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": "linear/linear-hw-2015-09-23.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": 62.5647668394, "max_line_length": 485, "alphanum_fraction": 0.6573913043, "num_tokens": 4815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8807970826714614, "lm_q1q2_score": 0.6985653994377389}}
{"text": "\\section{Arc Length}{}{}\\label{sec:Arc Length}\nHere is another geometric application of the integral: Find the length\nof a portion of a curve. As usual, we need to think about how we might\napproximate the length, and turn the approximation into an integral.\n\nWe already know how to compute one simple arc length, that of a line\nsegment. If the endpoints are $\\ds P_0(x_0,y_0)$ and $\\ds P_1(x_1,y_1)$\nthen the length of the segment is the distance between the points,\n$\\ds \\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$, from the Pythagorean theorem, as\nillustrated in Figure~\\ref{fig:length of a line segment}.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 5, y from 0 to 3\n\\axis bottom /\n\\axis left /\n\\putrule from 2 1 to 4.5 1\n\\putrule from 4.5 1 to 4.5 2.5\n\\plot 2 1 4.5 2.5 /\n\\put {$(x_1,y_1)$} [bl] <3pt,3pt> at 4.5 2.5\n\\put {$(x_0,y_0)$} [tr] <-3pt,-3pt> at 2 1\n\\put {$x_1-x_0$} [t] <0pt,-3pt> at 3.25 1\n\\put {$y_1-y_0$} [l] <3pt,0pt> at 4.5 1.75\n\\put {$\\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$} [br] <-3pt,3pt> at 3.25 1.75\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:length of a line segment}\n%\\htmlfigure{Integration_applications-arc_length.html}\n\\caption{\\label{fig:length of a line segment}\nThe length of a line segment.}\n%\\endcaption\n\\endfigure\n\nNow if the graph of $f$ is ``nice'' (say, differentiable) it appears\nthat we can approximate the length of a portion of the curve with line\nsegments, and that as the number of segments increases, and their\nlengths decrease, the sum of the lengths of the line segments will\napproach the true arc length; see \nFigure~\\ref{fig:approximating arc length}.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1.5truecm,0.8truecm>\n\\setplotarea x from 0 to 8, y from 0 to 5\n\\axis bottom /\n\\axis left /\n\\setquadratic\\plot \n1.000 1.000 1.150 1.953 1.300 2.694 1.450 3.246 1.600 3.636 \n1.750 3.884 1.900 4.012 2.050 4.041 2.200 3.990 2.350 3.874 \n2.500 3.711 2.650 3.515 2.800 3.299 2.950 3.075 3.100 2.853 \n3.250 2.644 3.400 2.454 3.550 2.290 3.700 2.157 3.850 2.060 \n4.000 2.000 4.150 1.979 4.300 1.996 4.450 2.050 4.600 2.138 \n4.750 2.255 4.900 2.396 5.050 2.554 5.200 2.721 5.350 2.886 \n5.500 3.039 5.650 3.168 5.800 3.258 5.950 3.294 6.100 3.261 \n6.250 3.140 6.400 2.912 6.550 2.556 6.700 2.051 6.850 1.374 \n7.000 0.500 /\n\\multiput {$\\bullet$} at 1 1 2.050 4.041 3.250 2.644\n4.300 1.996 5.500 3.039 6.250 3.140 7 0.5 /\n\\setlinear\\plot\n1 1 2.050 4.041 3.250 2.644\n4.300 1.996 5.500 3.039 6.250 3.140 7 0.5 /\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:approximating arc length}\n%\\htmlfigure{Integration_applications-arc_length_line_segments.html}\n\\caption{\\label{fig:approximating arc length}\nApproximating arc length with line segments.}\n%\\endcaption\n\\endfigure\n\nNow we need to write a formula for the sum of the lengths of the line\nsegments, in a form that we know becomes an integral in the limit.  So\nwe suppose we have divided the interval $[a,b]$ into $n$ subintervals\nas usual, each with length $\\Delta x =(b-a)/n$, and endpoints $\\ds\na=x_0$, $\\ds x_1$, $\\ds x_2$, \\dots, $\\ds x_n=b$.  The length of a\ntypical line segment, joining $\\ds (x_i,f(x_i))$ to $\\ds\n(x_{i+1},f(x_{i+1}))$, is $\\ds\\sqrt{(\\Delta x )^2\n  +(f(x_{i+1})-f(x_i))^2}$.  By the Mean Value Theorem, %(\\xrefn{thm:mvt}), \nthere is a number $\\ds t_i$ in $\\ds (x_i,x_{i+1})$\nsuch that $\\ds f'(t_i)\\Delta x=f(x_{i+1})-f(x_i)$, so the length of\nthe line segment can be written as\n$$\n  \\sqrt{(\\Delta x)^2 + (f'(t_i))^2\\Delta x^2}=\n  \\sqrt{1+(f'(t_i))^2}\\,\\Delta x.\n$$\nThen arc length is:\n$$\n  \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} \\sqrt{1+(f'(t_i))^2}\\,\\Delta x=\n  \\int_a^b \\sqrt{1+(f'(x))^2}\\,dx.\n$$\nNote that the sum looks a bit different than others we have\nencountered, because the approximation contains a $\\ds t_i$ instead of an\n$\\ds x_i$. In the past we have always used left endpoints (namely, $\\ds x_i$)\nto get a representative value of $f$ on $\\ds [x_i,x_{i+1}]$; now we are\nusing a different point, but the principle is the same.\n\nTo summarize, to compute the length of a curve on the interval\n$[a,b]$, we compute the integral\n$$\\int_a^b \\sqrt{1+(f'(x))^2}\\,dx.$$ \nUnfortunately, integrals of this form are typically difficult or\nimpossible to compute exactly, because usually none of our methods for\nfinding antiderivatives will work. In practice this means that the\nintegral will usually have to be approximated.\n\n\\begin{example}{Circumference of a Circle}{Circumference of a Circle}\\label{Circumference of a Circle} \nLet $\\ds f(x) = \\sqrt{r^2-x^2}$, the upper half circle of radius\n$r$. The length of this curve is half the circumference, namely $\\pi\nr$. Compute this with the arc length formula.\n\\end{example}\n\n\\begin{solution}\nThe derivative $f'$ is $\\ds \\ds -x/\\sqrt{r^2-x^2}$ so the integral is\n$$\n  \\int_{-r}^r \\sqrt{1+{x^2\\over r^2-x^2}}\\,dx\n  =\\int_{-r}^r \\sqrt{r^2\\over r^2-x^2}\\,dx\n  =r\\int_{-r}^r \\sqrt{1\\over r^2-x^2}\\,dx.\n$$\nUsing a trigonometric substitution, we find the antiderivative, namely\n$\\ds \\arcsin(x/r)$. Notice that the integral is improper at both\nendpoints, as the function $\\ds \\sqrt{1/(r^2-x^2)}$ is undefined when\n$x=\\pm r$. So we need to compute\n$$\n  \\lim_{D\\to-r^+}\\int_D^0  \\sqrt{1\\over r^2-x^2}\\,dx +\n  \\lim_{D\\to r^-}\\int_0^D  \\sqrt{1\\over r^2-x^2}\\,dx.\n$$\nThis is not difficult, and has value $\\pi$, so the original integral,\nwith the extra $r$ in front, has value $\\pi r$ as expected.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Arc Length}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $\\ds f(x)=x^{3/2}$ on $[0,2]$.\n\\begin{sol}\n $\\ds (22\\sqrt{22}-8)/27$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $\\ds f(x) = x^2/8-\\ln x$\non $[1,2]$.\n\\begin{sol}\n $\\ln(2)+3/8$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n\nFind the arc length of $\\ds f(x) = (1/3)(x^2 +2)^{3/2}$\non the interval $[0,a]$.\n\\begin{sol}\n $\\ds a+a^3/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $f(x)=\\ln(\\sin x)$ on the\ninterval $[\\pi/4,\\pi/3]$.\n\\begin{sol}\n $\\ds \\ln((\\sqrt2+1)/\\sqrt3)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Let $a>0$. Show that the length of $y=\\cosh x$ on\n$[0,a]$ is equal to $\\ds \\int _0 ^a \\cosh x\\,dx$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $f(x)=\\cosh x$ on $[0, \\ln 2]$.\n\\begin{sol}\n $3/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Set up the integral to find the arc length of $\\sin x$ \non the interval $[0,\\pi]$; do not evaluate the integral. If you have\naccess to appropriate software, approximate the value of the integral.\n\\begin{sol}\n $\\approx 3.82$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Set up the integral to find the arc length of $\\ds y=xe^{-x}$\non the interval $[2,3]$; do not evaluate the integral. If you have\naccess to appropriate software, approximate the value of the integral.\n\\begin{sol}\n $\\approx 1.01$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $\\ds y=e^x$ on the interval $[0,1]$.\n(This can be done exactly; it is a bit tricky and a bit long.)\n\\begin{sol}\n $\\ds \\sqrt{1+e^2}-\\sqrt2+\n{1\\over2}\\ln\\left({\\sqrt{1+e^2}-1\\over\\sqrt{1+e^2}+1}\\right)+\n{1\\over2}\\ln(3+2\\sqrt2)$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "c4251843795df3a0a50f31c5bf9c854ace1a3498", "size": 7337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-7-arclength.old2.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-7-arclength.old2.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-7-arclength.old2.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6088888889, "max_line_length": 103, "alphanum_fraction": 0.6673027123, "num_tokens": 2827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8807970670261976, "lm_q1q2_score": 0.6985653956439885}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amssymb,amsmath}\n\\usepackage{pdflscape}\n\\usepackage{subfigure}\n\\usepackage{dcolumn}\n%\\usepackage{rotating}\n\\usepackage{fancyhdr}\n\\pagestyle{fancyplain}\n\n\\newcommand\\T{\\rule{0pt}{2.6ex}}\n\\newcommand\\B{\\rule[-1.2ex]{0pt}{0pt}}\n\n\\begin{document}\n\\rhead{Prepared by Adam Beardsley on \\today}\n\n\\centerline{\\sc \\large Interpreting Discrete Fourier Transforms}\n\\vspace{.5pc}\n\n\\begin{abstract}\nWe present a systematic way of interpreting the discrete Fourier transform as an approximation to the continuous Fourier transform.  The argument is made for general conventions, and several examples are given.\n\\end{abstract}\n\n\\section{Introduction}\n\nOften times it is necessary to approximate a continuous Fourier transform (CFT) with a discrete Fourier transform (DFT) when an analytic form of the data is not available.  For example, a DFT can be performed on a sampling of time-ordered electric field measurements to approximate the frequency spectrum of the field.  In order to perform these transforms, we utilize the numerical packages of programming languages such as IDL, MATLAB, or Mathematica.  However, the definition of a Fourier transform is not completely constrained, and freedoms exist that give rise to multiple conventions in the normalization\\footnote{There are of course constraints limiting these freedoms, but for this argument we will leave them completely free.}, and scaling of the Fourier domain variables.  In particular, the numerical package being used may not follow the desired convention.  Below we outline a method for interpreting the results of a DFT, in terms of the CFT desired.  Then we provide several examples of common conventions.\n\n\\section{Derivation}\\label{sec:derivation}\n\nWe start by assuming we have a continuous function, $f_c(x)$, of which we would like to compute a continuous Fourier transform of the form\n\\begin{equation}\n\\label{eq:continuous}\nF_c(u;C_c,p_c)=C_c\\int_{-\\infty}^{\\infty}dx \\ f_c(x) e^{i p_c u x}\n\\end{equation}\nwhere the constants $C_c$ and $p_c$ are determined by convention of the transform.  However, in reality we often have a discrete sample of the continuous function, $f_d(j)$, where $j$ indexes the samples and runs from $0$ to $N-1$, $N$ being the number of samples.  Then it is necessary to use a discrete Fourier transform.  Numerical packages have various conventions for their DFTs, but in general they can be expressed in the form\n\\begin{equation}\n\\label{eq:discrete}\nF_d(k;C_d,p_d)=C_d\\sum\\limits_{j=0}^{N-1}f_d(j)e^{i p_d j k}\n\\end{equation}\nwhere $k$ indexes the Fourier domain samples, and also runs from $0$ to $N-1$.  In some cases, the indices can be shifted.  For example, MATLAB counts arrays from 1 rather than 0, so the sum would run from $1$ to $N$, and the values in the exponent are adjusted accordingly.  For simplicity, we assume counting from 0.  The translation is straighforward, and an example is given in Section \\ref{sec:examples}.  We wish to approximate the CFT with the DFT.\n\nIn order to proceed, we assume the function $f_c(x)$ is only significantly non-zero within a domain $\\mathcal{D}$.  Furthermore, we will assume $\\mathcal{D}=[0,x_{max}]$.  This constraint is not actually necessary, and a translation of the domain results in a phase in the Fourier transform, as seen in Section \\ref{sec:shifting}.  Then we can relate the indices in Eq. \\eqref{eq:discrete} to the axis values with the following expressions:\n\\begin{subequations}\n\\label{eq:axes}\n\\begin{align}\nx(j)=j\\Delta x \\label{eq:x_axis}\\\\\nu(k)=k\\Delta u \\label{eq:u_axis}\n\\end{align}\n\\end{subequations}\nwhere $\\Delta x = x_{max}/(N-1)$, and $\\Delta u$ will be derived below.  We can now approximate the CFT with a finite sum.\n\n\\begin{eqnarray}\n\\label{eq:approx_cont}\nF_c(u;C_c,p_c) \t& \\approx\t&\tC_c\\int_0 ^{x_{max}} dx \\ f_c(x)e^{i p_c u x} \\nonumber \\\\\n\t\t\t\t\t\t\t\t& \\approx\t&\tC_c\\sum\\limits_{j=0}^{N-1}\\Delta x f_c(x(j))e^{i p_c u j \\Delta x} \\nonumber \\\\\n\t\t\t\t\t\t\t\t& =\t\t\t\t&\tC_c \\Delta x \\sum\\limits_{j=0}^{N-1} f_d(j) e^{i p_c u j \\Delta x}\n\\end{eqnarray}\n\nIn order to force the sum in Eq. \\eqref{eq:approx_cont} to the form of the DFT (Eq. \\eqref{eq:discrete}), we write $u(k)$ in the following way.\n\n\\begin{eqnarray}\n\\label{eq:delta_u}\nu(k) = k\\Delta u\t&\t= & \\frac{p_d k}{p_c \\Delta x} \\nonumber \\\\\n\t\t\\Rightarrow\t\\Delta u\t&\t=\t&\t\\frac{p_d}{p_c \\Delta x} \n\\end{eqnarray}\n\nThis expression for $\\Delta u$ defines our Fourier axis, which is an extremely important part of interpreting a Fourier transform and in particular comparing to other computational conventions.\n\nWe can now simplify Eq. \\ref{eq:approx_cont}.  \n\n\\begin{eqnarray}\n\\label{eq:related}\nF_c(u;C_c,p_c)\t&\t\\approx\t&\tC_c \\Delta x \\sum\\limits_{j=0}^{N-1}f_d(j)e^{i p_d j k} \\nonumber \\\\\n\t\t\t\t\t\t\t\t&\t=\t\t\t\t&\t\\frac{C_c}{C_d} \\Delta x F_d(k;C_d,p_d) \\nonumber \\\\\n\t\t\t\t\t\t\t\t&\t=\t\t\t\t&\t\\frac{C_c}{C_d} \\Delta x F_d(u / \\Delta u;C_d,p_d)\n\\end{eqnarray}\n\nIn the first line of Eq. \\ref{eq:related} we introduced an intermediate index $k=u/\\Delta u$ for clarity in replacing the sum with the DFT.  Of course any computer package will compute the DFT for integer values of $k$, and it should be noted that this approximation for the CFT is only used for $u$ equal to integer multiples of $\\Delta u$.\n\nTo summarize, we have related an arbitrary convention of the continuous Fourier transform to an arbitrary convention of the discrete Fourier transform (Eq. \\ref{eq:related}).  In addition, we have shown the resulting Fourier axis is described by Eq. \\ref{eq:delta_u}.  For reference, several examples are discussed in Section \\ref{sec:examples}.\n\n\\section{Shifting Domains}\\label{sec:shifting}\n\nThe above derivation applied to functions significantly non-zero only within a domain $\\mathcal{D}=[0,x_{max}]$.  We can relax that condition slightly by allowing $\\mathcal{D}\\rightarrow[x_{min},x_{max}]$.  The same process can be followed as in Section \\ref{sec:derivation}, with a simple translation of the variable of integration.  The result is a mode-dependent phase, and we can generalize Eq. \\ref{eq:related} as\n\\begin{equation}\n\\label{eq:related_general}\nF_c(u;C_c,p_c) \\approx \\frac{C_c}{C_d} \\Delta x e^{i p_c u x_{min}}F_d(u / \\Delta u;C_d,p_d)\n\\end{equation}\nwhere now $\\Delta x = (x_{max}-x_{min})/(N-1)$.\n\nA particular case of interest is to shift the real and Fourier domains such that they are centered at zero.  This can be achieved by a couple shifts of the arrays.  In this case, $x_{min} = -\\Delta x (N-1)/2$.  The phases in Eq. \\ref{eq:related_general} are now negative, but can be shifted properly to make them positive.  This amounts to exchanging the positive and negative $x$ data in $f_d(j)$.  This is illustrated in Step A in Fig. \\ref{fig:shifting}.\n\nOnce the DFT is performed, our approximation for $F_c(u)$ is still only valid for positive (or in some cases only negative) values of $u$.  But we note that by the periodic nature of a complex phase, for $k>(N-1)/2$, and for $p_d = 2 \\pi / N$ (as is normally the case), we can make the substituion $k\\rightarrow-N+k$ and the sum in Eq. \\ref{eq:discrete} remains unchanged.  In other words, we can relabel and shift our $u$ axis to center our Fourier axis on $u=0$, as shown in Steps C and D in Fig. \\ref{fig:shifting}.  All these operations can be easily implemented using shifting functions built into many software packages.  In MATLAB, for example, \\texttt{ifftshift} (Step A) and \\texttt{fftshift} (Step D) are provided for this very reason.\n\n\n\\begin{figure}\n\\begin{center}\n\\centerline{\\includegraphics[width=7in]{FFT_shifts.jpg}}\n\\end{center}\n\\caption{Centering axes on 0.  \\emph{Step A}: Shift the real axis to be fed into DFT package.  \\emph{Step B}: Perform discrete Fourier transform.  \\emph{Step C}: Relabel Fourier modes to equivalent negative modes.  \\emph{Step D}: Shift Fourier axis to recover correct order.}\n\\label{fig:shifting}\n\\end{figure}\n\n\\section{Examples}\\label{sec:examples}\n\nHere we apply the interpretation of Section \\ref{sec:derivation} specifically to the default MATLAB discrete Fourier transform.  Further examples are listed in Table \\ref{table:examples}.  For the forward DFT, MATLAB uses the convention\n\n\\begin{equation}\nF_d(k) = \\sum\\limits_{j=1}^N f_d(j)e^{-2 \\pi i (j-1)(k-1)/N}, \\nonumber\n\\end{equation}\nso that $C_d=1$ and $p_d = -2 \\pi / N$.  Note the shift in indices due to the fact that MATLAB counts from 1, rather than zero.  This can be accounted for by writing the axes as\n\\begin{eqnarray}\nx(j) = (j-1)\\Delta x \\nonumber \\\\\nu(k) = (k-1)\\Delta u \\nonumber\n\\end{eqnarray}\nwhere $\\Delta u = p_d/(p_c \\Delta x) = -2 \\pi / (p_c N \\Delta x)$.\n\nLet us now assume that we have sampled a function of position, $f_d(j)$, with resolution $\\Delta x = 3$m, and $N = 1001$ ($x_{range} = 3000$m).  We are interested in the Fourier transform of the form\n\\begin{equation}\nF_c(u) = \\frac{1}{\\sqrt{2 \\pi}}\\int_{-\\infty}^{\\infty} dx \\ f_c(x) e^{i u x} \\nonumber\n\\end{equation}\nso that $C_c=1/\\sqrt{2\\pi}$ and $p_c=1$.  Then we use Eq. \\ref{eq:related} to approximate the CFT as\n\\begin{equation}\nF_c(u) \\approx \\frac{3\\mbox{m}}{\\sqrt{2\\pi}} F_d(-u \\frac{3003\\mbox{m}}{2\\pi}+1;1,2\\pi/N) \\nonumber\n\\end{equation}\nwhere $F_d(k,1,2\\pi/N)$ is the array output from MATLAB's \\texttt{fft} function, given $f_d(j)$.  Note that because the sign of $p_c$ is opposite the sign of $p_d$, the approximation for the CFT will only be valid for negative Fourier modes.  In most applications this difference will not be significant, but in some cases it may be important to account for the axis reversal.\n\nSimilar steps can be taken for any DFT convention, and some common default parameters are listed in Table \\ref{table:examples}.  We also list several common CFT conventions and their corresponding conversions from common numerical packages in Table \\ref{table:applied_examples}.\n\n\n%Figure format\n%\\begin{figure}\n%\\begin{center}\n%\\includegraphics[width=4in]{file.jpg}\n%\\end{center}\n%\\caption{Put a caption here, if you dare}\n%\\label{fig:figure_label}\n%\\end{figure}\n\n\n%appendix if needed\n%\\clearpage\n%\\appendix\n%\\section{appendix section}\\label{app_section}\n\n\n\\begin{table}\n\\begin{center}\n\\centerline{\\begin{tabular}{c c c c c c} \n\\hline\nPackage\t\\T \\B\t\t\t&\t$F_d(k)$\t&\t$C_d$\t&\t$p_d$\t&\t$x(j)$\t&\t$u(k)$\t\\\\ \\hline\nIDL\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{N}\\sum\\limits_{j=0}^{N-1} f_d(j)e^{-2\\pi i j k /N}$\t\t\t\t\t&\t$1/N$\t\t\t\t\t\t\t\t\t&\t$-2\\pi/N$\t&\t$j\\Delta x$\t\t\t&\t$-k\\frac{2\\pi}{p_c N \\Delta x}$\t\t\t \\\\\nMATLAB\t\\T \\B\t\t\t&\t$\\sum\\limits_{j=1}^N f_d(j)e^{2\\pi i (j-1)(k-1)/N}$\t\t\t\t\t\t\t\t\t\t&\t1\t\t\t\t\t\t\t\t\t\t\t&\t$-2\\pi/N$\t&\t$(j-1)\\Delta x$\t&\t$-(k-1)\\frac{2\\pi}{p_c N \\Delta x}$\t \\\\\nMathematica\t\\T \\B\t&\t$\\frac{1}{\\sqrt{N}}\\sum\\limits_{j=1}^N f_d(j)e^{2\\pi i (j-1)(k-1)/N}$\t&\t$\\frac{1}{\\sqrt{N}}$\t&\t$2\\pi/N$\t&\t$(j-1)\\Delta x$\t&\t$(k-1)\\frac{2\\pi}{p_c N \\Delta x}$\t \\\\\nPython (numpy) \\T \\B & $\\sum\\limits_{j=0}^{N-1} f_d(j)e^{-2\\pi i j k /N}$\t\t\t\t\t&\t1\t\t\t\t\t\t\t\t\t&\t$-2\\pi/N$\t&\t$j\\Delta x$\t\t\t&\t$-k\\frac{2\\pi}{p_c N \\Delta x}$\t\t\t \\\\\n\\hline\n\\end{tabular}}\n\\caption{Example default parameters for the forward discrete Fourier transform for various numerical packages}\n\\label{table:examples}\n\\end{center}\n\\end{table}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{c c c c}\n\\hline\nDFT Package\t\\T \\B\t&\t$F_c(u)$ Desired\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t&\tAmplitude Factor\t\t\t\t\t&\t$\\left|\\Delta u\\right|$\t\t\\\\ \\hline\nIDL\t\t\\T \\B\t\t\t\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{i u x}$\t&\t$\\Delta x N/\\sqrt{2\\pi}$\t&\t$2\\pi/(N\\Delta x)$ \t\t\t\t\\\\\n\t\t\t\\T \\B\t\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{i u x}$\t\t\t\t&\t$\\Delta x N/2\\pi$\t\t\t\t\t&\t$2\\pi/(N\\Delta x)$\t\t\t\t\\\\\n\t\t\t\\T \\B\t\t\t\t&\t$\\int dx \\ f_c(x) e^{2\\pi i u x}$\t\t\t\t\t\t\t\t\t&\t$\\Delta x N$\t\t\t\t\t\t\t&\t$1/(N\\Delta x)$\t\t\t\t\t\t\\\\ \\hline\nMATLAB\t\\T \\B\t\t\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{i u x}$\t&\t$\\Delta x/\\sqrt{2\\pi}$\t\t&\t$2\\pi/(N\\Delta x)$\t\t\t \t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{i u x}$\t\t\t\t&\t$\\Delta x/2\\pi$\t\t\t\t\t\t&\t$2\\pi/(N\\Delta x)$\t\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{2\\pi i u x}$\t\t\t\t\t\t\t\t\t&\t$\\Delta x$\t\t\t\t\t\t\t\t&\t$1/(N\\Delta x)$\t\t\t\t\t\t\\\\ \\hline\nMathematica\t\\T \\B\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{i u x}$\t&\t$\\Delta x\\sqrt{N/2\\pi}$\t\t&\t$2\\pi/(N\\Delta x)$ \t\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{i u x}$\t\t\t\t&\t$\\Delta x\\sqrt{N}/2\\pi$\t\t&\t$2\\pi/(N\\Delta x)$\t\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{2\\pi i u x}$\t\t\t\t\t\t\t\t\t&\t$\\Delta x\\sqrt{N}$\t\t\t\t&\t$1/(N\\Delta x)$\t\t\t\t\t\t\\\\ \\hline\nPython (numpy)\t\\T \\B\t\t\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{i u x}$\t&\t$\\Delta x/\\sqrt{2\\pi}$\t\t&\t$2\\pi/(N\\Delta x)$\t\t\t \t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{i u x}$\t\t\t\t&\t$\\Delta x/2\\pi$\t\t\t\t\t\t&\t$2\\pi/(N\\Delta x)$\t\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{2\\pi i u x}$\t\t\t\t\t\t\t\t\t&\t$\\Delta x$\t\t\t\t\t\t\t\t&\t$1/(N\\Delta x)$\t\t\t\t\t\t\\\\ \\hline\n\\end{tabular}\n\\caption{Common CFT conventions listed with the normalization factor and axis scaling factors for sample numerical packages.}\n\\label{table:applied_examples}\n\\end{center}\n\\end{table}\n\n\\section{Inverse Fourier Transform}\n\nThe above argument holds for the inverse Fourier transform as well.  Define the inverse CFT as\n\\begin{equation}\n\\label{eq:inverse_continuous}\nf_c(x;C'_c,p'_c)=C'_c\\int_{-\\infty}^{\\infty}du \\ F_c(k) e^{i p'_c u x}\n\\end{equation}\nand the inverse DFT as\n\\begin{equation}\n\\label{eq:inverse_discrete}\nf_d(j;C'_d,p'_d)=C'_d\\sum\\limits_{k=0}^{N-1}F_d(k)e^{i p'_d j k}.\n\\end{equation}\nThen the result for the approximation of the inverse CFT is\n\\begin{equation}\n\\label{eq:inverse_related}\nf_c(x;C'_c,p'_c) \\approx \\frac{C'_c}{C'_d} \\Delta u f_d(x / \\Delta x;C'_d,p'_d)\n\\end{equation}\nwhere $\\Delta x = p_d'/p_c' \\Delta u$.\n\nWe summarize the default parameters for the inverse DFT for various numerical packages in Table \\ref{table:inverse_examples}, and provide a few applied examples to common CFTs in Table \\ref{table:inverse_applied_examples}.\n\n\\begin{table}\n\\begin{center}\n\\centerline{\\begin{tabular}{c c c c c c}\n\\hline\nPackage\t\\T \\B\t\t\t&\t$f_d(j)$\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t&\t$C'_d$\t\t\t\t\t\t\t\t&\t$p'_d$\t\t&\t$u(k)$\t\t\t\t\t&\t$x(j)$\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\\ \\hline\nIDL\t\t\t\\T \\B\t\t\t&\t$\\sum\\limits_{k=0}^{N-1} F_d(k)e^{2\\pi i j k /N}$\t\t\t\t\t\t\t\t\t\t\t\t&\t$1$\t\t\t\t\t\t\t\t\t\t&\t$2\\pi/N$\t&\t$k\\Delta u$\t\t\t&\t$j\\frac{2\\pi}{p'_c N \\Delta u}$\t\t\t\t\\\\\nMATLAB\t\\T \\B\t\t\t&\t$\\frac{1}{N}\\sum\\limits_{k=1}^N F_d(k)e^{-2\\pi i (j-1)(k-1)/N}$\t\t\t\t\t&\t$1/N$\t\t\t\t\t\t\t\t\t&\t$2\\pi/N$\t&\t$(k-1)\\Delta u$\t&\t$(j-1)\\frac{2\\pi}{p'_c N \\Delta u}$\t\t\\\\\nMathematica\t\\T \\B\t&\t$\\frac{1}{\\sqrt{N}}\\sum\\limits_{k=1}^N F_d(k)e^{-2\\pi i (j-1)(k-1)/N}$\t&\t$\\frac{1}{\\sqrt{N}}$\t&\t$-2\\pi/N$\t&\t$(k-1)\\Delta u$\t&\t$-(j-1)\\frac{2\\pi}{p'_c N \\Delta u}$ \t\\\\\nPython (numpy)\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{N}\\sum\\limits_{k=0}^{N-1} F_d(k)e^{2\\pi i j k /N}$\t\t\t\t\t\t\t\t\t\t\t\t&\t$1/N$\t\t\t\t\t\t\t\t\t\t&\t$2\\pi/N$\t&\t$k\\Delta u$\t\t\t&\t$j\\frac{2\\pi}{p'_c N \\Delta u}$\t\t\t\t\\\\\n\\hline\n\\end{tabular}}\n\\caption{Example default parameters for the inverse discrete Fourier transform for various numerical packages}\n\\label{table:inverse_examples}\n\\end{center}\n\\end{table}\n\n\n\\begin{table}\n\\begin{center}\n\\centerline{\\begin{tabular}{c c c c}\n\\hline\nDFT Package\t\\T \\B\t&\t$f_c(x)$ Desired\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t&\tAmplitude Factor\t\t\t\t\t&\t$\\left|\\Delta x\\right|$\t\\\\ \\hline\nIDL\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{-i u x}$\t&\t$\\Delta u/\\sqrt{2\\pi}$\t\t&\t$2\\pi/(N \\Delta u)$\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{-i u x}$\t\t\t\t\t\t\t\t\t\t\t\t&\t$\\Delta u$\t\t\t\t\t\t\t\t&\t$2\\pi/(N \\Delta u)$\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{-2\\pi i u x}$\t\t&\t$\\Delta u/2\\pi$\t\t\t\t\t\t&\t$1/(N \\Delta u)$\t\t\t\t\\\\ \\hline\nMATLAB\t\\T \\B\t\t\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{-i u x}$\t&\t$\\Delta u N/\\sqrt{2\\pi}$\t&\t$2\\pi/(N \\Delta u)$ \t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{-i u x}$\t\t\t\t\t\t\t\t\t\t\t\t&\t$\\Delta u N$\t\t\t\t\t\t\t&\t$2\\pi/(N \\Delta u)$\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{-2\\pi i u x}$\t\t&\t$\\Delta u N/2\\pi$\t\t\t\t\t&\t$1/(N \\Delta u)$\t\t\t\t\\\\ \\hline\nMathematica\t\\T \\B\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{-i u x}$\t&\t$\\Delta u\\sqrt{N/2\\pi}$\t\t&\t$2\\pi/(N \\Delta u)$ \t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{-i u x}$\t\t\t\t\t\t\t\t\t\t\t\t&\t$\\Delta u\\sqrt{N}$\t\t\t\t&\t$2\\pi/(N \\Delta u)$\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{-2\\pi i u x}$\t\t&\t$\\Delta u\\sqrt{N}/2\\pi$\t\t&\t$1/(N \\Delta u)$\t\t\t\t\\\\ \\hline\nPython (numpy)\t\\T \\B\t\t\t&\t$\\frac{1}{\\sqrt{2\\pi}}\\int dx \\ f_c(x) e^{-i u x}$\t&\t$\\Delta u N/\\sqrt{2\\pi}$\t&\t$2\\pi/(N \\Delta u)$ \t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\int dx \\ f_c(x) e^{-i u x}$\t\t\t\t\t\t\t\t\t\t\t\t&\t$\\Delta u N$\t\t\t\t\t\t\t&\t$2\\pi/(N \\Delta u)$\t\t\t\\\\\n\t\t\t\t\\T \\B\t\t\t&\t$\\frac{1}{2\\pi}\\int dx \\ f_c(x) e^{-2\\pi i u x}$\t\t&\t$\\Delta u N/2\\pi$\t\t\t\t\t&\t$1/(N \\Delta u)$\t\t\t\t\\\\ \\hline\n\\end{tabular}}\n\\caption{Common inverse CFT conventions listed with the normalization factor and axis scaling factors for sample numerical packages.}\n\\label{table:inverse_applied_examples}\n\\end{center}\n\\end{table}\n\n\n\n\\end{document}", "meta": {"hexsha": "af6a20a3f4398f4a62224381f1b94670d59f5f53", "size": 16644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "001_DFT_Interpretation/DFT_Interpretation.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": "001_DFT_Interpretation/DFT_Interpretation.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": "001_DFT_Interpretation/DFT_Interpretation.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": 66.843373494, "max_line_length": 1022, "alphanum_fraction": 0.6521869743, "num_tokens": 6042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.698510432345327}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\n% Packages\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{gensymb}\n\\usepackage{amsmath}\n\\usepackage{MnSymbol}\n\\usepackage{pgfplots}\n\n\\title{\\textbf{Mathematical proofs}}\n\\author{Michal Špano}\n\\date{March 2022}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{The inner angle of an $n-sided$ convex regular polygon}\n\n% Introduction\nSuppose an $n-sided$ convex regular polygon. Its 4 consecutive vertices are shown in the figures, $N_1, N_2, N_3, ..., N_i$ respectively. \nThus $\\Delta_{N_1,N_2,S} \\cong \\Delta_{N_2,N_3,S}$, i.e. such $n-sided$ polygon consists of $n$ congruent isosceles triangles. \nThat is, $|\\measuredangle N_2 N_1 S| = |\\measuredangle N_1 N_2 S| \\Rightarrow |\\measuredangle N_1 N_2 S| = |\\measuredangle S N_2 N_3|$, denoted as $\\beta, \\beta'$ respectively. \n\n% Section I\nAn angle $\\alpha = |\\measuredangle N_1 S N_2| = \\cfrac{360}{n}$, since such an angle multiplied by $n$ makes for a perfect circle of $360\\degree$. Likewise $\\alpha = 180\\degree - 2 \\beta$.\n\n% Section I\nLet $\\Phi$ be an inner angle of the polygon, such that $\\phi = 2 \\beta$ (shown in the figure at the vertex $N_2$).\n\n% Steps of computations\nExpress in terms of $\\beta$: $\\alpha = 180 - 2 \\beta \\iff \\beta = \\cfrac{-\\alpha + 180}{2}$\n\nSubstitute $\\alpha$ for $\\alpha = \\cfrac{360}{n}$: $\\beta = \\cfrac{-\\cfrac{360}{n} + 180}{2} \\iff \\beta = \\cfrac{180n - 360}{2n}$\n\nExpress in terms of $\\Phi$: $\\Phi = 2 \\beta = 2 \\Big( \\cfrac{180n - 360}{2n} \\Big) = \\cfrac{180n - 360}{n}$ \\\\\n\nThe expression can be further simplified to the following form:\n\n% End of the proof\n$$\\Phi = \\cfrac{(n-2) \\pi}{n}$$.\n\n% Include a picture of a unit circle\n\\begin{figure}[htp]\n    \\centering\n    \\includegraphics[width=4.cm]{polygon_export.png}\n    \\caption{$n-sided$ polygon with its 4 vertices in a plane}\n\\end{figure}\n\n\\newpage\n\n\\section*{The number of diagonals of an $n-sided$ convex regular polygon}\n\nSuppose a geometrical locus of $n$ points on the plane, \n% Steps of the proof\ni.e. a set of points $A_1, A_2, ..., A_n$ \nsuch that $A_1, A_2, ..., A_n$ create an $n-sided$ convex regular polygon.\nThe number of different abscissas in the geometrical locus is ${n \\choose 2}$ \nand denoted as $N_a$. It implies that no abscissa in the locus is given by more than two points, \ni.e. each point is unique. Likewise, $\\overlinesegment{A_1A_2} \\equiv \\overlinesegment{A_2A_1}$ \nholds for any 2 points in the locus, thus such abscissas are counted as one. It can be inferred \nthat the number of diagonals, denoted as $N_D$, is the same as \\textit{the difference of the number of \nabscissas and the number of sides}: \n\n% End of the proof\n$$N_D = N_s - n$$\n\n\\section*{The similarity coefficient}\n\n% Start of the proof\nSuppose a scalene triangle $\\Delta_{ABC}$. We assume that there exists a triangle $\\Delta_{A'B'C'}$,\nsuch that $\\Delta_{ABC} \\cong \\Delta_{A'B'C'}$. It implies that there exists some constant $c$,\nsuch that any abscissa created in the locus of points (from the original triangle) is equal to the\nproduct of $c$ and the corresponding abscissa of the similar triangle. Symbolically: \n\n% General expression\n$\\exists! c \\in \\mathbb{Q}: |V_1 V_2| = c \\times |V_1' V_2'| \\land c \\gneqq 1$, where $V_1, V_2$ \nare the vertices of the original triangle.\n\n% Section 1 - perimeters\nThen, it can be easily inferred, that for the \\textbf{perimeters} of the triangles \nholds the following: Let $P = \\overlinesegment{AB} + \\overlinesegment{BC} + \\overlinesegment{AC}$, similarly \n$P' = \\overlinesegment{A'B'} + \\overlinesegment{B'C'} + \\overlinesegment{A'C'}$. Likewise\n% Enumerating the similar sides with a constant\n$\n\\overlinesegment{AB} = c \\times \\overlinesegment{A'B'} \\land \n\\overlinesegment{BC} = c \\times \\overlinesegment{B'C'} \\land\n\\overlinesegment{AC} = c \\times \\overlinesegment{A'C'}\n$. \\\\\n\n% Steps of computation - perimeter\n$P = c \\times \\overlinesegment{A'B'} + c \\times \\overlinesegment{B'C'} + c \n\\times \\overlinesegment{A'C'} \\Rightarrow$\n$P = c \\times \\Big( \\overlinesegment{A'B'} + \\overlinesegment{B'C'} + \\overlinesegment{A'C'} \\Big) = c \\times P'$\n\n$$P = c \\times P'$$.\n\n% Conclusion of section 1\nIt implies that the ratio of the lengths of the sides of the similar triangles, \ni.e. the ratio of their perimeters, is equal to the similarity coefficient:\n$c = \\cfrac{P}{P'}$. \\\\\n\n% Section 2 - areas\nSimilar methodology is applied to the similarity coefficient of the areas of the triangles:\n\n% Steps of computation - area\nLet $A = \\dfrac{\\overlinesegment{AB} \\times \\overlinesegment{H_{AB}}}{2} \\land \nA' = \\dfrac{\\overlinesegment{A'B'} \\times \\overlinesegment{H'_{AB}}}{2}$,\nwhere $H_{AB}$ and $H'_{AB}$ are the heights of the triangles. Thus,\n$A = \\dfrac{c \\times \\overlinesegment{A'B'} c \\times \\overlinesegment{H'_{AB}}}{2} = \nc^2 \\times \\Bigg( \\dfrac{\\overlinesegment{A'B'} \n\\times \\overlinesegment{H'_{AB}}}{2} \\Bigg) = c^2 \\times A'$\n\n$$A = c^2 \\times A'$$\n\n% Conclusion of section 2\nIt implies, that the ratio of the areas equals to the similarity coefficient \ntaken to the second power: $c^2 = \\cfrac{A}{A'}$. \\\\\n\n% Conclusion\nTo sum up, such a methodology is also applicable to derive the similarity coefficient \nof the volume of the tetrahedron. Moreover, it is also applicable to derive the similarity coefficient\nof any planar polygon or solid figure (a scalene triangle per the given example is just an exemplary instance). \nStill, the following holds: $P = c \\times P' \\land A = c^2 \\times A' \\land V = c^3 \\times V'$ \nbased on the principles of \\textbf{congruence}.\n\n% End of the proof\n\n\\section*{Function bounded above and/or below}\n\n% Start of the proof - bounded above and/or below function\n\nSuppose a function $f$ which has a finite domain, say $D_f$. A function is bounded above if: \n$\\exists! a \\in \\mathbb{R}, \\forall x \\in D_f \\subset \\mathbb{R}: f(x) \\leq a$. That is to say,\nthat every function value is smaller or equal to some constant, say $a$. Similarly, a function\nis bounded below if: $\\exists! b \\in \\mathbb{R}, \\forall x \\in D_f \\subset \\mathbb{R}: f(x) \n\\geq b$. That implies, that every function value is greater or equal to some constant, say $b$.\nLastly, a function is bounded if both of the previous statements hold, i.e.:\n$\\exists! a \\in \\mathbb{R}, \\exists! b \\in \\mathbb{R}, \\forall x \\in D_f \\subset \\mathbb{R}:\nf(x) \\leq a \\land f(x) \\geq b$. Hence, some bounded function $f$ has the following range of \nvalues: $[b;a]$, where $\\{a,b\\} \\in \\mathbb{R}$. For example, the function $f(x) = sin(x)$ \nis bounded, such that $[-1;1]$ is its range of values. \\\\\n\n% Sample sin(x) plot\n\\begin{figure}[htp]\n    \\begin{center}  % Center the image\n        \\begin{tikzpicture}\n            \\begin{axis}[domain=0:2*pi,samples=100,smooth,xlabel={$x$},ylabel={$f(x)$}]\n                \\addplot[color=blue] {sin(deg(x))};  % sine function\n                \\addplot[color=black] {0};  % vertical line y = 0\n            \\end{axis}\n        \\end{tikzpicture}\n    \\end{center}\n\n    % Caption the figure\n    \\caption{$sin(x)$, where $x \\in [0;2 \\pi]$}\n\\end{figure}\n\n% End of the proof\n\n\\newpage\n\n\\section*{The standard rules of logarithms}\n\n% Start of the proof - standard rules of logarithms\n\nThe following rules of logarithms hold for $x,y,a,s$, such that:\n\n% Variable enumeration\n\\[\\forall x,y \\in\\mathbb{R^+}, \\forall a > 0 \\land a \\neq 1, \\forall s \\in\\mathbb{R}\\]\n\n\\begin{enumerate}\n    \\item{$\\boldsymbol{\\log_a 1 = 0}$}  % Rule number 1\n\n    For any $a$ holds the following $a^0 = 1$. Therefore $log_a 1 = 0$.\n    \n    \\item{$\\boldsymbol{\\log_a a = 1}$}  % Rule number 2\n\n    For any $a$ holds the following $a^1 = a$. Therefore $log_a a = 1$.\n\n    \\item{$\\boldsymbol{a^{\\log_a x} = x}$}  % Rule number 3\n\n    Let $l = \\log_a x$. Therefore $a^{l} = x$. Combining the two rules, we obtain the following:\n    $a^{\\log_a x} = x$.\n\n    \\item{$\\boldsymbol{\\log_a (x \\times y) = \\log_a x + \\log_a y}$}  % Rule number 4\n    \n    Suppose some $x,y$, where $x = a^{\\log_a x}$, $y = a^{\\log_a y}$. If we compute the product\n    of them, we obtain that $x \\times y = a^{\\log_a x} \\times a^{\\log_a y}$. Furthermore, we \n    have that $a^{\\log_a x + \\log_a y} = x \\times y$. According to the previous rule, we \n    obtain that $\\log_a (x \\times y) = \\log_a x + \\log_a y$.\n\n    \\item{$\\boldsymbol{\\log_a \\Big( \\frac{x}{y} \\Big) = \\log_a x - \\log_a y}$}  % Rule number 5\n    \n    Similarly, suppose some $x,y$, where $x = a^{\\log_a x}$, $y = a^{\\log_a y}$. If we compute \n    the quotient of them, we obtain that $\\cfrac{x}{y} = \\cfrac{a^{\\log_a x}}{a^{\\log_a y}}$. \n    Furthermore,  we obtain that $a^{\\log_a x - \\log_a y} = \\cfrac{x}{y}$. According to the third \n    rule, we have that $\\log_a \\big(\\frac{x}{y}\\big) = \\log_a x - \\log_a y$.\n\n    \\item{$\\boldsymbol{\\log_a x^{s} = s \\times \\log_a x}$}  % Rule number 6\n\n    Suppose some $x$, where $x = a^{\\log_a x}$. Power both sides of the equation by $s$, we \n    obtain that $x^{s} = (a^{\\log_a x})^{s}$. Therefore $a^{s \\times \\log_a x} = x^{s}$.\n    Having applied the third rule, it can be inferred that $\\log_a x^{s} = s \\times \\log_a x$.\n\n    \\item{$\\boldsymbol{\\log_a x = \\dfrac{\\log_b x}{\\log_b a}}$}  % Rule number 7\n\n    Suppose some $x$, where $x = a^{\\log_a x}$. Then, for some $\\log$ with the base $b$ and the \n    argument $x$ holds $\\log_b x = \\log_b a^{\\log_a x}$. Applying the sixth rule, we obtain that\n    $\\log_b x = \\log_b a \\times \\log_a x$. Divide the equation by $\\log_b a$, thus obtaining\n    $\\log_a x = \\cfrac{\\log_b x}{\\log_b a}$.\n\n\\end{enumerate}\n    \n% End of the pr\n\n\\newpage\n\n% Start of the proof - sum of n terms of an arithmetic sequence\n\\section*{The sum of $n$ terms of an arithmetic sequence}\n\nSuppose an arithmetic sequence (also called a progression or a series) $\\{a_{n}\\}_{n=1}^{\\infty}$. That is, a sequence of $n$ terms, where:\n$$\\exists! d \\in \\mathbb{R} - \\{0\\}, \\forall i,j \\in \\mathbb{N}: d = a_{i} - a_{j} \\land i - j = 1$$ \n\nThat implies, that there exists exactly one constant, say $d$, such that the difference between every 2\nconsecutive terms is $d$. We label the sum of the first $n$ terms of the sequence as $S_{n}=\\sum_{i=1}^n a_{i}$.\nMore explicitly, we have $S_{n} = a_{1} + a_{2} + \\dots + a_{n-1} + a_{n}$. Similarly, if we reverse the \nsequence, we obtain $S_{n} = a_{n} + a_{n-1} + \\dots + a_{2} + a_{1}$. Add the two sums, we obtain:\n\n$$2 \\times S_{n} = (a_{1} + a_{n}) + (a_{2} + a_{n-1}) + \\dots + (a_{n-1} + a_{2}) + (a_{n} + a_{1})$$\n\nObserve the similarity between the sums. E. g.\n$(1 + 4) + (2 + 3) + \\dots + (n + k) = (k + n) + \\dots + (3 + 2) + (4 + 1)$\nThus, it can be infered that $2 \\times S_{n} = n \\times (a_{n} + a_{1})$.\nLastly, we have that: $$S_{n} = \\cfrac{n \\times (a_{n} + a_{1})}{2}$$\n\n\\textbf{Conclusion:} The sum of $n$ terms of an arithmetic sequence is $\\dfrac{n}{2} (a_{n} + a_{1})$.\n\n% End of the proof\n\n% Start of the proof - sum of n terms of an arithemtic sequence by mathematical induction\n\n\\section*{The sum of $n$ terms of an arithmetic sequence (proof)}\n\nSuppose you are given a simple arithmetic sequence, where the difference between every 2 consecutive terms \n$d$ is 1. We assume the following (using the notation from the previous section): \n$$S_{n} = 1 + 2 + \\dots + (n - 1) + n = \\sum_{i=1}^{n} i = \\frac{n}{2} (n + 1)$$\n\nFormulate a statement, say $S(n)$, which is to be proven.\n\n$$S(n): \\forall n \\in \\mathbb{N}: 1 + 2 + \\dots + n = \\frac{n}{2} (n + 1)$$\n\nFirst and foremost, we let $n=1$: $S(1): 1 = \\frac{1}{2} (1 + 1)$. That is true. \\linebreak  % Step 1\nSecondly, assume that $S(k)$ holds for some arbitrary $k \\in \\mathbb{N}$.  % Step 2\nThat is our \\textbf{induction hypothesis} (also called the induction assumption). We obtain:\n$$S(k): 1 + 2 + \\dots + k = \\frac{k}{2} (k + 1)$$\n\nThirdly, $S(k) \\implies S(k^{+})$, so we let $n=k+1$. Steps of the proof:  % Step 3\n\n$$S(k + 1): 1 + 2 + \\dots + k + (k + 1) = \\cfrac{(k+1)(k+2)}{2}$$  % Steps of the proof\n$$S(k + 1): S(k) + (k + 1) = \\cfrac{(k+1)(k+2)}{2}$$\n$$S(k + 1): \\frac{k}{2} (k + 1) + (k + 1) = \\cfrac{(k+1)(k+2)}{2}$$\n$$S(k + 1): \\cfrac{k(k+1) + 2(k+1)}{2} = \\cfrac{(k+1)(k+2)}{2}$$\n$$S(k + 1): \\cfrac{(k+1)(k+2)}{2} = \\cfrac{(k+1)(k+2)}{2}$$\n\nWe obtain that $S(k+1)$ holds and so must $S(k)$ (our induction hypothesis). That suffices to prove $S(n)$.\nFinally, we have that $S(n)$ holds for all $n \\in \\mathbb{N}$, and thus \\textbf{the proof is complete}.  % Step 4\n\n% End of the proof\n\n\\end{document}\n", "meta": {"hexsha": "002b3d4ca6f17bced64c56387e4cb5978038a2c3", "size": 12391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study-materials/Mathematics/proofs/src/main.tex", "max_stars_repo_name": "michalspano/study-materials", "max_stars_repo_head_hexsha": "a1d69bcf84ae654ba247587f717168225aefd588", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-02-10T07:33:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T15:29:13.000Z", "max_issues_repo_path": "study-materials/Mathematics/proofs/src/main.tex", "max_issues_repo_name": "michalspano/study-materials", "max_issues_repo_head_hexsha": "a1d69bcf84ae654ba247587f717168225aefd588", "max_issues_repo_licenses": ["MIT"], "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-materials/Mathematics/proofs/src/main.tex", "max_forks_repo_name": "michalspano/study-materials", "max_forks_repo_head_hexsha": "a1d69bcf84ae654ba247587f717168225aefd588", "max_forks_repo_licenses": ["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.2226277372, "max_line_length": 188, "alphanum_fraction": 0.6503914131, "num_tokens": 4314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6985104202237826}}
{"text": "\\subsection{part a}\n\nWe used get\\_fog and opt\\_app to find first order time delay transfer function (FOTF).\n\\begin{itemize}\n    \\item frequency\n    $$\n    G(s) =  e^{-1.45s} \\dfrac{0.375}{0.9587s + 1}\n    $$\n    \\item transfer function\n    $$\n    G(s) =  e^{-1.39s} \\dfrac{0.375}{0.9428s + 1}\n    $$\n    \\item optimum\n    $$\n    G(s) =  e^{-1.38s} \\dfrac{0.383}{s + 1.021}\n    $$\n\\end{itemize}\n\\begin{figure}[H]\n    \\caption{system and FOTD step responde}\n    \\centering\n    \\includegraphics[width=12cm]{../Figure/Q1/a/FOTD.png}\n\\end{figure}\nI used below cost function to see witch one fits better.\n$$\n\\text{Cost} = \\int_{0}^{8} \\vert G(t) - G'(t)\\vert dt,\\qquad \\text{$G'$ is FOTD transfer function}\n$$\n\\begin{itemize}\n    \\item frequency\n    \n    Cost = 1.5949\n    \\item transfer function\n    \n    Cost = 1.3208\n    \\item optimum\n    \n    Cost = 1.0345\n\\end{itemize}\nOptimum hase minimum cost so we choise FOTD that used optimum function.\n", "meta": {"hexsha": "2dd00f0d70f6f2077bc552c5418d6ecdf760bb26", "size": 941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW VI/Report/Q1/a.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 VI/Report/Q1/a.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 VI/Report/Q1/a.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": 24.1282051282, "max_line_length": 98, "alphanum_fraction": 0.6110520723, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6984815754176438}}
{"text": "\\section{Elliptic systems: linear elasticity}\n\nIn this section we review the foundations of the analysis of elliptic\n(systems of) partial differential equations (\\putindex{PDE}) and apply\nthem, again with the purpose of reminding us of the analytical tools\nin mind, to the Lamé-Navier-equations of linear elasticity. While this\nis expected to be knowledge you already bring into this class, it will\nhelp us putting the analysis of mixed finite element methods into\nperspective.  A short derivation of the Lamé-Navier equations is in\n\\cref{sec:lame-navier} in the appendix. For comparison,\nconsider~\\cite{Braess97,Braess13}.\n\n\\subsection{Example: weak form of the Lamé-Navier equations}\n\\begin{Definition}{weak-lame-navier}\n  The weak formulation of the Lamé-Navier boundary value problem in\n  linear elasticity with homogeneous displacement boundary conditions,\n  namely\n  \\begin{gather}\n    \\label{eq:mixedintro:lame1}\n    \\begin{aligned}\n      -\\div \\sigma(\\vx) &= \\vf(\\vx) & \\vx&\\in\\domain,\\\\\n      \\sigma(\\vx) &= 2\\mu \\strain \\vu(\\vx) + \\lambda \\operatorname{tr} \\strain \\vu(\\vx) \\id\\\\\n%      \\vu(\\vx) &= 0 & x&\\in\\Gamma_D,\n    \\end{aligned}\n  \\end{gather}\n  is: find $\\vu\\in \\vV = \\vH^1_{0}(\\domain;\\R^d)$ such that\n  \\begin{gather}\n    \\label{eq:mixedintro:lame2}\n    a(\\vu,\\vv) \\equiv 2\\mu\\form(\\strain \\vu, \\strain \\vv)\n    + \\lambda \\form(\\div \\vu, \\div \\vv)\n    = \\form(\\vf,\\vv)\n    \\quad\\forall \\vv\\in \\vV.\n  \\end{gather}\n    Here, $\\strain \\vu = \\nicefrac12\\bigl(\\nabla u + (\\nabla u)^\\transpose\\bigr)$ is the symmetric gradient.\n\\end{Definition}\n\n\\begin{Problem}{frobenius}\n  Given the vector space of square matrices $X = \\R^{d\\times d}$ with the\n  Frobenius inner product\n  \\begin{gather}\n    \\label{eq:mixedintro:frobenius}\n    \\scal(A,B) = A:B = \\sum_{ij} a_{ij}b_{ij}.\n  \\end{gather}\n  Show that the subspaces of symmetric and skew-symmetric matrices,\n  respectively, are orthogonal to each other and $X$ is the direct sum\n  of those.\n\\begin{solution}\n\\begin{enumerate}\n\\item First, we note that for every matrix $A$, there holds\n  \\begin{gather}\n    A = A_S + A_A, \\quad A_S = \\frac{A+A^\\transpose}2, \\quad A_A = \\frac{A-A^\\transpose}2.\n  \\end{gather}\n  Furthermore, we see that $A_S$ is symmetric and $A_A$ is\n  skew-symmetric. The sum of two symmetric matrices is symmetric,\n  the same for skew-symmetric. Thus, the sets $X_S$ and $X_A$ of\n  symmetric and skew-symmetric matrices, respectively, are vector\n  spaces and $X=X_S+X_A$.\n  \n\\item The only matrix which is symmetric and skew-symmetric is\n  zero. Thus, $X=X_S\\oplus X_A$.\n  \n\\item It remains to show orthogonality. To this end, we first note\n  that for any skew-symmetric matrix $A$, there holds $a_{ii}=0$\n  for all diagonal elements. Thus, the inner product of $A$ with a\n  symmetric matrix $S$ is\n  \\begin{align}\n    \\scal(A,S) &= \\sum_{i\\neq j} a_{ij}s_{ij}\\\\\n               &= \\sum_{i<j} (a_{ij}s_{ij} + a_{ji}s_{ji})\\\\\n               &= \\sum_{i<j} (a_{ij}-a_{ji})s_{ij}\\\\\n               &= 0.\n  \\end{align}\n\\end{enumerate}\n\\end{solution}\n\\end{Problem}\n\n\\begin{Problem}{weak-lame-navier}\n  Show that the weak formulation equation~\\eqref{eq:mixedintro:lame2}\n  in \\slideref{Definition}{weak-lame-navier} indeed is indeed obtained\n  from the classical formulation ~\\eqref{eq:mixedintro:lame2} in that\n  definition by integration by parts and the application of boundary\n  conditions.\n\\end{Problem}\n\n\\begin{Definition}{lame-galerkin}\n  The \\define{conforming} \\define{Galerkin approximation} of the weak\n  formulation in \\slideref{Definition}{weak-lame-navier} consists of the following steps:\n  \\begin{enumerate}\n  \\item Choose a finite dimensional subspace $\\vV_h\\subset \\vV$\n  \\item Find $\\vu_h \\in \\vV_h$, such that for all $\\vv\\in \\vV_h$ there holds\n  \\begin{gather}\n    \\label{eq:mixedintro:lame3}\n    a(\\vu_h,\\vv_h) \\equiv 2\\mu\\form(\\strain{\\vu_h}, \\strain{\\vv_h})\n    + \\lambda \\form(\\div{\\vu_h}, \\div{\\vv_h})\n    = \\form(\\vf,\\vv_h).\n  \\end{gather}\n  \\end{enumerate}\n\\end{Definition}\n\n\\begin{Problem}{weak-lame-well-posedness}\n  Without reading any further in the notes, try to remember the means\n  of analyzing the well-posedness of this weak formulation. What are\n  the assumptions on the weak formulation?\n\n  Also, try to remember the means of analyzing well-posedness and\n  approximation properties for the conforming Galerkin\n  approximation. What are the assumptions on the weak formulation?\n\\end{Problem}\n\n\\subsection{The finite element toolbox}\n\nWe review the abstract setting of Galerkin approximations and the\nfinite element method and apply those to the Lamé-Navier equations.\n\n\\begin{Notation}{vh-finite}\n  Spaces with subscript $h$ in these notes always denote finite\n  dimensional spaces used for discretization.\n\n  If nothing else is stated, we denote the solution of the PDE\n  boundary value problem by $u$\\index{u@$u, \\vu$} or $\\vu$, while\n  $u_h$ or $\\vu_h$ \\index{uh@$u_h, \\vu_h$} denote its finite element\n  discretization.\n\n  The index $h$ is related to a finite element mesh $\\mesh_h$, where\n  $h$ indicates the mesh size. We use this notation even for adaptive\n  and high order finite elements, where there is no single mesh size\n  characterizing the discretization.\n\\end{Notation}\n\n\\begin{Definition}{elliptic-abstract-weak}\n  The \\define{weak formulation} of a \\define{boundary value problem}\n  for a PDE in abstract form involves a function space $V$, a bilinear\n  form $a(\\cdot,\\cdot)$ on $V$, and a right hand side $f\\in V^*$. It\n  reads: find $u\\in V$ such that\n  \\begin{gather}\n    \\label{eq:elliptic-abstract-weak}\n    a(u,v) = f(v) \\qquad\\forall v\\in V.\n  \\end{gather}\n  For its \\define{Galerkin approximation}, choose a subspace\n  $V_h\\subset V$ and solve: find $u_h\\in V_h$ such that\n  \\begin{gather}\n    \\label{eq:elliptic-abstract-galerkin}\n    a(u_h,v_h) = f(v_h) \\qquad\\forall v_h\\in V_h.\n  \\end{gather}\n\\end{Definition}\n\nIt turns out that the analysis of the weak formulation as well as its\nGalerkin approximation hinges on a single set of assumptions, which we\npresent here.\n\n\\begin{Assumption}{coercive}\n  Let $V$ be a Hilbert space and let $a(.,.)$ be a \\putindex{bilinear\n    form} on $V$.  The bilinear form is\n  \\textbf{bounded}\\index{bilinear form!bounded}, i. e. there is a\n  constant $M$ such that\n  \\begin{gather}\n    a(u,v) \\le M \\norm{u}_V \\norm{v}_V \\qquad \\forall u,v\\in V.\n  \\end{gather}\n  The bilinear form is \\textbf{coercive}\\index{bilinear form!coercive}\n  or \\textbf{elliptic}\\index{bilinear form!elliptic}, i.e. there is a\n  constant $\\ellipa > 0$ such that\n  \\begin{gather}\n    \\label{eq:infsup:elliptic}\n    a(u,u) \\ge \\ellipa \\norm{u}_V^2 \\qquad \\forall u\\in V.\n  \\end{gather}\n\\end{Assumption}\n\nNote that typically the space $V$ and its inner product are chosen\nsuch that the assumption holds, not the other way round.\n\nThe analytical results can be summarized by\n\n\\begin{Theorem*}{fem-toolbox}{The finite element toolbox (elliptic)}\n  Let \\slideref{Assumption}{coercive} hold. Let furthermore\n  $V_h\\subset V$. Then, there holds\n  \\begin{enumerate}\n  \\item (\\putindex{Lax-Milgram lemma}) There is a unique solution to\n    the weak formulation in\n    \\slideref{Definition}{elliptic-abstract-weak}. By the subspace\n    property, this result is inherited by the Galerkin\n    approximation. There holds\n    \\begin{gather}\n      \\norm{u}_V \\le \\tfrac1{\\ellipa} \\norm{f}_{V^*},\n      \\qquad\n      \\norm{u_h}_V \\le \\tfrac1{\\ellipa} \\norm{f}_{V^*}.\n    \\end{gather}\n  \\item (\\putindex{Céa's lemma}) The error of the Galerkin\n    approximation admits the estimate (\\putindex{quasi-optimality})\n    \\begin{gather}\n      \\norm{u-u_h}_V \\le \\tfrac{M}{\\ellipa}\\inf_{v_h\\in V_h}\\norm{u-v_h}_V.\n    \\end{gather}\n  \\end{enumerate}\n\\end{Theorem*}\n\n\\begin{intro}\n  The form $a(\\cdot,\\cdot)$ is symmetric and thus semi-definite on $V$. It can\n  also be bounded easily by the $H^1$-norm. But, for well-posedness of\n  the weak formulation, we also require ellipticity. This question is\n  indeed not trivial and rests on the fact that for a function\n  $u\\in V$, such that $\\nabla u$ is skew-symmetric everywhere, there\n  holds $\\strain u\\equiv 0$. Thus, such functions must be excluded by\n  the boundary conditions. Note, that in particular for rigid body\n  translations and rotations $\\strain u = 0$. Therefore, the Dirichlet\n  boundary conditions must exclude such solutions.\n  \n  The condition needed for well-posedness is called Korn inequality,\n  and it will be posed as an assumption. We will give a proof for a\n  simple case and refer the readers to a plethora of articles on more\n  complicated cases.\n\\end{intro}\n\n% \\begin{Lemma*}{korn-inequality}{Korn inequality}\n%   There is a constant $c_K>0$ such that\n%   \\begin{gather}\n%     \\label{eq:mixedintro:korn}\n%     c_K \\norm{\\vv}_{\\vH^1(\\domain)}\n%     \\le \\norm{\\strain \\vv}_{\\vL^2(\\Omega)}\n%     \\qquad\\forall \\vv\\in \\vH^1_0(\\domain) \\cap \\vH^2(\\domain).\n%   \\end{gather}\n% \\end{Lemma*}\n\n\\begin{Problem*}{korn-inequality}{Korn inequality}\n  Prove that the inequality\n  \\begin{gather}\n    \\label{eq:mixedintro:korn}\n    c_K \\norm{\\vv}_{\\vH^1(\\domain)}\n    \\le \\norm{\\strain \\vv}_{\\vL^2(\\Omega)}\n    \\qquad\\forall \\vv\\in \\vH^1_0(\\domain) \\cap \\vH^2(\\domain).\n  \\end{gather}\n  holds with a constant\n  \\begin{gather}\n    c_K = \\frac1{\\sqrt2(1+c_P)},\n  \\end{gather}\n  where $c_P$ is the constant of the \\putindex{Poincaré-Friedrichs inequality}.\n  Use the intermediate result\n  \\begin{gather}\n    2 \\norm{\\strain u}^2_{L^2(\\domain)} = \\norm{\\nabla u}_{L^2(\\domain)}^2\n    + \\norm{\\div u}_{L^2(\\domain)}^2,\n  \\end{gather}\n  and prove it by integration by parts.\n\\end{Problem*}\n\nWhile the inequality is of high importance in the mathematical and\nnumerical analysis of problems in continuum mechanics, it a peripheral\ntopic to this class. We point out, that there is a whole family of\nKorn inequalities ensuring the definiteness of the strain bilinear\nform on certain spaces. We have only stated the simplest version\nhere. See~\\cite{DuvautLions76,DesvillettesVillani02} for some indepth\nanalysis.\n\n\\begin{Problem}{elasticity-standard-h1}\n  Let the space $V=H^1_0(\\domain;\\R^d)$ be equipped with its standard inner\n  product $\\scal(\\vu,\\vv)$ with the bilinear form of the\n  Lamé-Navier equations and the corresponding norm $\\norm{.}_{\\vH^1}$.\n\n  Show using the elliptic finite element toolbox in \\slideref{Theorem}{fem-toolbox}\n  \\begin{enumerate}\n  \\item The weak formulation has a unique solution for which there holds\n    \\begin{gather}\n      \\norm{\\vu}_{\\vH^1} \\le \\frac1{2c_K\\mu} \\norm{\\vf}_{\\vH^{-1}}.\n    \\end{gather}\n  \\item There holds the error estimate\n    \\begin{gather}\n      \\norm{\\vu-\\vu_h}_{\\vH^1}\n      \\le \\frac{2\\mu+d\\lambda}{2c_K\\mu}\n      \\inf_{\\vv_h\\in V_h} \\norm{\\vu-\\vv_h}_{\\vH^1}.\n    \\end{gather}\n    Hint: there are divergence-free functions ($\\div \\vv=0$) and others.\n  \\end{enumerate}\n  \\begin{solution}\n    \\begin{enumerate}\n    \\item For well-posedness, we want to apply the Lax-Milgram\n      lemma. Thus, we have to show that the bilinear form is bounded\n      and elliptic.\\marginpar{Todo}\n   \\item For the $H^1$-error estimate we make use of Korn's inequality to note\\marginpar{Todo: this is outdated}\n   \\begin{align}\n    \\norm{u}_V^2=2\\mu\\norm{\\strain u}_0^2+ \\lambda \\norm{\\div u}_0^2\\geq\n    2\\mu(c_K^2\\norm{u}_1^2-\\norm{u}_0^2)\n   \\end{align}\n   and on the other hand\n   \\begin{align}\n    \\norm{u}_V^2=2\\mu\\norm{\\strain u}_0^2+ \\lambda \\norm{\\div u}_0^2\\leq\n    (2\\mu+\\lambda d^2)\\norm{u}_1^2\n   \\end{align}\n   where we used\n   \\begin{align}\n    \\norm{\\nabla \\cdot u}_0^2 = \\norm{\\sum_i \\partial_i u_i}_0^2 &\\leq (\\sum_{i,j} \\norm{\\partial_j u_i}_0\\delta_{i,j})^2\\\\\n    & \\leq \\sum_{i,j} \\left(\\norm{\\partial_j u_i}_0^2\\right) d^2 \\leq \\norm{u}_1^2 d^2.\n   \\end{align}\n   Using Poincaré's inequality\n   \\begin{align}\n    \\norm{u}_0\\leq C_P |u|_1\n   \\end{align}\n   we further notice\n   \\begin{align}\n    \\norm{u}_V^2+2\\mu\\norm{u}_0^2\\leq (1+C_P^2) \\norm{u}_V^2.\n   \\end{align}\n   Combining these estimates gives\n   \\begin{align}\n   2\\mu c_K^2\\norm{u}_1^2\\leq\n    \\norm{u}_V^2+2\\mu \\norm{u}_0^2\\leq\n    (1+C_P^2)\\norm{u}_V^2\\leq\n    (1+C_P^2)(2\\mu+\\lambda d^2)\\norm{u}_1^2.\n   \\end{align}\n   and therefore\n   \\begin{align}\n    \\norm{u-u_h}_1^2\\leq \\inf_{v\\in V_h} \\frac{(1+C_P^2)(2\\mu+\\lambda d^2)}{2\\mu c_K^2}\\norm{u-v_h}_1^2.\n   \\end{align}\n   If the solution is even $H_0^1(\\Omega)$-regular, we can improve the estimate to\n   \\begin{align}\n    \\norm{u}_1^2\\leq \\inf_{v\\in V_h}\\frac{(\\mu+(\\lambda+\\mu) d^2)}{\\mu}\\norm{u-v_h}_1^2.\n   \\end{align}\n   by using the identity\n   \\begin{align}\n    (\\strain u, \\strain v) = (\\nabla u, \\nabla v) + (\\nabla \\cdot u, \\nabla \\cdot v).\n   \\end{align}\n\n   \\item A more refined estimate would be\n   \\begin{align}\n    \\norm{u-u_h}_1^2\\leq \\inf_{v\\in V_h}\\frac{(1+C_P^2)}{2\\mu c_K^2}\\left(2\\mu\\norm{u-v_h}_1^2+\\lambda \\norm{\\nabla\\cdot (u-v_h)}_0^2\\right).\n   \\end{align}\n   Choosing a divergence-preserving interpolation operator, the second term vanishes.\n  \\end{enumerate}\n\\end{solution}\n\\end{Problem}\n\nIf the bilinear form is symmetric, there is an even more elegant way of\ndoing the analysis: we can use the bilinear form as an inner product\nitself. This leads to our second, albeit somewhat more restricted toolbox.\n\n\\begin{Theorem*}{fem-toolbox-riesz}{The finite element toolbox (symmetric)}\n  Let $a(\\cdot,\\cdot)$ be a symmetric, positive definite bilinear form\n  on a space $V$. We equip $V$ with this bilinear form and the \\define{energy norm}:\n  \\begin{gather}\n    \\scal(u,v)_V = a(u,v)\n    ,\\qquad \\norm{v}_V = \\sqrt{a(v,v)} \\qquad \\forall u,v\\in V.\n  \\end{gather}\n  Let furthermore $V_h\\subset V$. Then, there holds\n  \\begin{enumerate}\n  \\item (Riesz representation theorem) There is a unique solution to\n    the continuous and discrete weak formulations in\n    \\slideref{Definition}{elliptic-abstract-weak}, respectively. There holds\n    \\begin{gather}\n      \\norm{u}_V = \\norm{f}_{V^*},\n      \\qquad\n      \\norm{u_h}_V = \\norm{f}_{V^*}.\n    \\end{gather}\n  \\item (\\putindex{Céa's lemma}) The approximation error admits the\n    estimate\n    \\begin{gather}\n      \\norm{u-u_h}_V \\le \\inf_{v_h\\in V_h}\\norm{u-v_h}_V.\n    \\end{gather}\n  \\end{enumerate}\n\\end{Theorem*}\n\n\\begin{Problem}{elasticity-standard}\n  Let the space $V=H^1_0(\\domain;\\R^d)$ be equipped with the inner\n  product $\\scal(\\vu,\\vv) = a(\\vu,\\vv)$, the bilinear form of the\n  Lamé-Navier equations and the corresponding norm $\\norm{.}_\\vV$.\n\n  Show using the symmetric finite element toolbox \\slideref{Theorem}{fem-toolbox-riesz}\n  \\begin{enumerate}\n  \\item The weak formulation has a unique solution for which there holds\n    \\begin{gather}\n      \\norm{\\vu}_\\vV \\le \\norm{\\vf}_{\\vV^*}.\n    \\end{gather}\n  \\item The ``energy estimate'' for conforming finite element\n    approximation with a space $\\vV_h\\subset \\vV$\n    \\begin{gather}\n      \\norm{\\vu-\\vu_h}_\\vV = \\inf_{\\vv_h\\in \\vV_h} \\norm{\\vu-\\vv_h}_\\vV.\n    \\end{gather}\n  \\end{enumerate}\n\\begin{solution}\nWe consider the problem:\n  Find $u\\in V = H^1_{\\Gamma_D}(\\domain;\\R^d)$ such that\n  \\begin{gather}\n    a(u,v) \\equiv 2\\mu\\form(\\strain u, \\strain v)\n    + \\lambda \\form(\\div u, \\div v)\n    = \\form(f,v)\n    \\quad\\forall v\\in V.\n  \\end{gather}\n  where the norm on $V$ is given through $a$ as\n  \\begin{align}\n    \\norm{u}_V^2=a(u,u)=2\\mu\\norm{\\strain u}_0^2+ \\lambda \\norm{\\div u}_0^2\n    \\end{align}\n  \\begin{enumerate}\n   \\item Testing symmetrically ($v=u$) gives\n   \\begin{align}\n   \\norm{u}_V=\\frac{a(u,u)}{\\norm{u}_V}= \\frac{\\form(f,u)}{\\norm{u}_V} \\leq \\norm{f}_{V^*}.\n   \\end{align}\n   \\item Applying Céa's lemma gives\n   \\begin{align}\n   \\norm{u-u_h}_V&=\\frac{a(u-u_h, u-u_h)}{\\norm{u-u_h}_V}\\\\\n               &=\\frac{a(u-u_h, u-v_h)}{\\norm{u-u_h}_V}\\leq \\norm{u-v_h}_V\\quad \\forall v_h \\in V_h\n   \\end{align} and hence $\\norm{u-u_h}_V = \\inf_{v_h\\in V_h} \\norm{u-v_h}_V$.\n   \\item For the $H^1$-error estimate we make use of Korn's inequality to note\n   \\begin{align}\n    \\norm{u}_V^2=2\\mu\\norm{\\strain u}_0^2+ \\lambda \\norm{\\div u}_0^2\\geq\n    2\\mu(c_K^2\\norm{u}_1^2-\\norm{u}_0^2)\n   \\end{align}\n   and on the other hand\n   \\begin{align}\n    \\norm{u}_V^2=2\\mu\\norm{\\strain u}_0^2+ \\lambda \\norm{\\div u}_0^2\\leq\n    (2\\mu+\\lambda d^2)\\norm{u}_1^2\n   \\end{align}\n   where we used\n   \\begin{align}\n    \\norm{\\nabla \\cdot u}_0^2 = \\norm{\\sum_i \\partial_i u_i}_0^2 &\\leq (\\sum_{i,j} \\norm{\\partial_j u_i}_0\\delta_{i,j})^2\\\\\n    & \\leq \\sum_{i,j} \\left(\\norm{\\partial_j u_i}_0^2\\right) d^2 \\leq \\norm{u}_1^2 d^2.\n   \\end{align}\n   Using Poincaré's inequality\n   \\begin{align}\n    \\norm{u}_0\\leq C_P |u|_1\n   \\end{align}\n   we further notice\n   \\begin{align}\n    \\norm{u}_V^2+2\\mu\\norm{u}_0^2\\leq (1+C_P^2) \\norm{u}_V^2.\n   \\end{align}\n   Combining these estimates gives\n   \\begin{align}\n   2\\mu c_K^2\\norm{u}_1^2\\leq\n    \\norm{u}_V^2+2\\mu \\norm{u}_0^2\\leq\n    (1+C_P^2)\\norm{u}_V^2\\leq\n    (1+C_P^2)(2\\mu+\\lambda d^2)\\norm{u}_1^2.\n   \\end{align}\n   and therefore\n   \\begin{align}\n    \\norm{u-u_h}_1^2\\leq \\inf_{v\\in V_h} \\frac{(1+C_P^2)(2\\mu+\\lambda d^2)}{2\\mu c_K^2}\\norm{u-v_h}_1^2.\n   \\end{align}\n   If the solution is even $H_0^1(\\Omega)$-regular, we can improve the estimate to\n   \\begin{align}\n    \\norm{u}_1^2\\leq \\inf_{v\\in V_h}\\frac{(\\mu+(\\lambda+\\mu) d^2)}{\\mu}\\norm{u-v_h}_1^2.\n   \\end{align}\n   by using the identity\n   \\begin{align}\n    (\\strain u, \\strain v) = (\\nabla u, \\nabla v) + (\\nabla \\cdot u, \\nabla \\cdot v).\n   \\end{align}\n\n   \\item A more refined estimate would be\n   \\begin{align}\n    \\norm{u-u_h}_1^2\\leq \\inf_{v\\in V_h}\\frac{(1+C_P^2)}{2\\mu c_K^2}\\left(2\\mu\\norm{u-v_h}_1^2+\\lambda \\norm{\\nabla\\cdot (u-v_h)}_0^2\\right).\n   \\end{align}\n   Choosing a divergence-preserving interpolation operator, the second term vanishes.\n  \\end{enumerate}\n\\end{solution}\n\\end{Problem}\n\n\\begin{Theorem*}{interpolation-elliptic}{Interpolation estimate}\n  Let $\\mesh_h$ be a finite element mesh of size $h$, that is, the\n  maximal diameter of a mesh cell is $h$. Let the finite element space\n  be chosen piecewise polynomial such that\n  \\begin{gather}\n    V_h = \\bigl\\{ v \\in H^1_0(\\domain) \\;\\big|\\;\n    v_{|\\cell} \\in \\mathcal P(\\cell) \\;\\forall \\cell\\in\\mesh_h \\bigr\\}.\n  \\end{gather}\n  For each cell $\\cell\\in\\mesh_h$, let $\\mathcal P(\\cell)$ be a\n  polynomial space containing $\\P_k$. Then, there is an interpolation\n  operator $I_h\\colon H^1_0(\\domain)\\cap H^{k+1}(\\domain)\\to V_h$,\n  such that for $m\\le k$ there holds\n  \\begin{gather}\n    \\abs{u-I_h u}_{m} \\le c_I h^{k+1-m}\\abs{u}_{k+1},\n  \\end{gather}\n  with an \\define{interpolation constant} $c_I$ independent of $h$ and\n  $u$, but depending on $k$, $m$, and \\putindex{shape regularity} of the mesh.\n\\end{Theorem*}\n\n\\begin{Theorem}{elliptic-convergence}\n  On a sequence of meshes $\\mesh_h$ with $h\\to 0$ and uniform shape\n  regularity, the error of the finite element solution $\\vu_h$ of the\n  Lamé-Navier equations is bounded by\n  \\begin{gather}\n    \\norm{\\vu-\\vu_h}_{1} \\le c_I h^k \\frac{2\\mu+d\\lambda}{2c_K\\mu}\n    \\abs{\\vu}_{k+1},\n  \\end{gather}\n  if the true solution $\\vu$ is sufficiently regular.\n\\end{Theorem}\n\n\\subsection{Where things go wrong}\n\\begin{example}\n  We study the finite element approximation of the following problem:\n  a square sheet of elastic material is hanging from the top, subject\n  to gravity acting as body force pointing downward. We choose $\\mu=1$\n  and vary $\\lambda$ from 1 to\n  $10^5$. Figure~\\ref{fig:elasticity-compressibility} shows\n  approximations with standard bilinear finite elements (red) and a\n  ``good'' approximation (blue). In fact, the red solution for\n  $\\lambda = 10^5$ is almost identical with the undeformed\n  configuration, although the material is not as hard. This phenomenon\n  was discovered early in finite element history and is called\n  ``locking''.\n\\end{example}\n\n\\begin{figure}[tp]\n  \\centering\n  \\subfigure[{$\\lambda = 1$}]{\\includegraphics[width=.45\\textwidth]{./graph/elasticity/stalactite-0}}\n  \\subfigure[{$\\lambda = 10$}]{\\includegraphics[width=.45\\textwidth]{./graph/elasticity/stalactite-1}}\n  \\subfigure[{$\\lambda = 100$}]{\\includegraphics[width=.45\\textwidth]{./graph/elasticity/stalactite-2}}\n  \\subfigure[{$\\lambda = 1000$}]{\\includegraphics[width=.45\\textwidth]{./graph/elasticity/stalactite-3}}\n  \\subfigure[{$\\lambda = 10000$}]{\\includegraphics[width=.45\\textwidth]{./graph/elasticity/stalactite-4}}\n  \\subfigure[{$\\lambda = 100000$}]{\\includegraphics[width=.45\\textwidth]{./graph/elasticity/stalactite-5}}\n  \\caption{Approximation with standard finite elements (red) and\n    ``good'' elements (blue) for $\\mu=1$ and different values of\n    $\\lambda$.}\n  \\label{fig:elasticity-compressibility}\n\\end{figure}\n\n\\begin{example}\n  In a second example, we cook up a right hand side function $\\vf$\n  such that we know the solution to the Lamé-Navier equations. Indeed,\n  we take a given solution $\\vu$ and apply the differential operator\n  to compute $\\vf$.\n\n  The \\cref{fig:elasticity-locking} shows the $H^1$-seminorm of the\n  error over the mesh size (represented by its negative dyadic\n  logarithm). The black triangle denotes the convergence order $h$,\n  the expected convergence of the bilinear finite elements used in\n  this example.\n\n  We see that for $\\lambda=1$ and $\\lambda=10$, we get the expected\n  curves with the correct convergence rate. For larger values of\n  $\\lambda$ things seem to go wrong. There is no convergence in the\n  beginning, but it seems that the expected rates are recovered on\n  finer meshes.\n\\end{example}\n\n\\begin{figure}[tp]\n  \\centering\n  \\includegraphics[width=.9\\textwidth]{mixed/graph/elasticity/locking}\n  \\caption{Errors for a manufactured solution with different values of $\\lambda$.}\n  \\label{fig:elasticity-locking}\n\\end{figure}\n\n\\begin{intro}\n  As we could see in the preceding examples, approximation\n  of the solution to the Lamé-Navier equations becomes difficult, if\n  $\\lambda \\gg \\mu$. In this case, the material is called almost\n  incompressible, since the divergence measures compression or\n  dilation and the dominating divergence term forces the divergence of\n  the solution to be small. These cases are important in engineering\n  and they initiated a lot of the research that resulted in the topics\n  of this class. The phenomenon observed here, that the approximation\n  of the solution to an elasticity problem deteriorates with\n  increasing $\\lambda$ is called \\define{locking}.\n\\end{intro}\n\n\\begin{Problem}{divergence-q1}\n  On $\\domain = (-1,1)^2$ use the finite element mesh\n  \\begin{center}\n  \\includegraphics[width=.25\\textwidth]{./fig/patch1m.tikz}, \n  \\end{center}\n  and on each cell the bilinear shape function space $\\Q_1$, that is\n  \\begin{gather}\n    \\vV_h = \\bigl\\{ \\vv\\in \\vH^1_0(\\domain) \\;\\big|\\;\n    \\vv_{|\\cell_i} \\in \\Q_1\\quad i=1,2,3,4\\bigr\\}.\n  \\end{gather}\n  Show that for functions in $\\vV_h$ there holds\n  \\begin{gather}\n    \\norm{\\div \\vv_h}_{L^2(\\domain)} = 0\n    \\qquad\\Rightarrow\\qquad\n    \\vv_h = 0.\n  \\end{gather}\n\\end{Problem}\n\n\\subsection{A mixed formulation}\n\n\\begin{Definition}{robust-discretization}\n  We call a discretization of a parameterized (system of) PDE robust\n  with respect to the parameters or simply \\define{robust}, if in an\n  error estimate of the abstract form\n  \\begin{gather}\n    \\norm{u-u_h}_X \\le c h^\\alpha \\norm{u}_Y\n  \\end{gather}\n  the constant $c$ is independent of the parameters.\n\\end{Definition}\n\nA way to approach this problem is the introduction of an auxiliary variable\n\\begin{gather}\n  p = -\\lambda \\div u.\n\\end{gather}\nEntering this definition into the Lamé-Navier equations, we obtain\nthe following weak formulation.\n\n\\begin{Definition}{displacement-pressure}\n  The \\define{displacement-pressure formulation} of the Lamé-Navier\n  equations reads: find a pair $(u,p) \\in V\\times Q$ such that\n  \\begin{subequations}\n  \\begin{gather}\n    \\label{eq:lame-navier-mixed}\n    \\begin{aligned}\n      2\\mu\\form(\\strain u, \\strain v) &- \\form(p,\\div v) &=&\\form(f,v)\n      &\\forall v&\\in V = \\vH^1_0(\\domain)\\\\\n      -\\form(q,\\div u) &-\\tfrac1\\lambda \\form(p,q) &=&0\n      &\\forall q&\\in Q \\subset L^2(\\domain).\\\\\n    \\end{aligned}\n  \\end{gather}\n  \\pause\n  Equivalently, we write this in a single equation as\n  \\begin{multline}\n    2\\mu\\form(\\strain u, \\strain v) - \\form(p,\\div v)\n    - \\form(q,\\div u) -\\tfrac1\\lambda \\form(p,q)\n    = \\form(f,v)\n    \\\\\n    \\qquad\\forall v\\in V, q\\in Q,\n  \\end{multline}\n  \\pause\n  or in the nonsymmetric, (semi-)definite version\n  \\begin{multline}\n    2\\mu\\form(\\strain u, \\strain v) + \\form(p,\\div v)\n    - \\form(q,\\div u) +\\tfrac1\\lambda \\form(p,q)\n    = \\form(f,v)\n    \\\\\n    \\qquad\\forall v\\in V, q\\in Q,\n  \\end{multline}    \n  \\end{subequations}\n\\end{Definition}\n\n\\begin{remark}\n  The three forms have different purposes and will be used\n  accordingly. The first one highlights the fact that we now have a\n  system of equations, each equation tested with its own test\n  function. The second and third stress the fact that we now have a\n  bilinear form on the product space $X=V\\times Q$.\n  \n  The second form is symmetric, but we will see later that is\n  indefinite. Thus, non of our tools from functional analysis\n  apply. In contrast, the third form is nonsymmetric, but we have\n  \\begin{multline}\n    2\\mu\\form(\\strain u, \\strain u) + \\form(p,\\div u)\n    - \\form(p,\\div u) +\\tfrac1\\lambda \\form(p,p)\n    \\\\\n    = 2\\mu\\form(\\strain u, \\strain u) + \\tfrac1\\lambda \\form(p,p)\n    \\ge \\tfrac{2\\mu}{c_K} \\norm{u}_{H^1}^2 + \\tfrac1\\lambda \\form(p,p).\n  \\end{multline}\n  Thus, we have ellipticity with respect to the norm\n  \\begin{gather}\n    \\norm{(u,p)}_X^2 = \\norm{u}_{H^1}^2 + \\norm{p}_{L^2}^2.\n  \\end{gather}\n  Nevertheless, the ellipticity constant depends on $\\lambda$, and for\n  large $\\lambda$, we loose sharpness of estimates again.\n\\end{remark}\n\n\\begin{Definition}{lame-navier-strong}\n  Integrating the first equation by parts, we obtain the\n  \\textbf{strong form} of the \\putindex{displacement-pressure\n    formulation}\n  \\begin{gather}\n    \\arraycolsep.2ex\n    \\begin{matrix}\n% Check signs\n      - 2\\mu \\div \\strain u &+& \\nabla p &=& f \\\\\n      \\div u &+& \\tfrac1\\lambda p &=& 0\n    \\end{matrix}\n  \\end{gather}\n\\end{Definition}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Stokes equations}\n\n\\begin{intro}\n  When we write the Lamé-Navier equations in \\putindex{displacement-pressure formulation} according to\n  \\slideref{Definition}{displacement-pressure}, there is no\n  parameter $\\lambda$ tending to infinity when the material becomes\n  less and less compressible. Instead, there is the parameter\n  $1/\\lambda$ tending to zero. Thus, we can simply consider the case\n  of incompressible material by setting $1/\\lambda=0$ or, in our\n  abstract framework~\\eqref{eq:mixedintro:1} setting $c(\\cdot,\\cdot) = 0$. The\n  resulting system is not only important for incompressible\n  elasticity, but also models the slow flow of a very viscous liquid,\n  so called \\putindex{creeping flow}.\n\\end{intro}\n\n\\begin{Definition}{stokes-eq1}\n  The \\define{Stokes equations} in strong form are\n    \\begin{gather}\n      \\label{eq:mixedintro:stokes-strong1}\n      \\arraycolsep.2ex\n      \\begin{matrix}\n        -2\\mu \\div \\strain \\vu &+& \\nabla p &=& \\vf \\\\\n        \\div \\vu && &=& 0.\n      \\end{matrix}\n    \\end{gather}\n    In weak form, they are: find $\\vu\\in \\vV \\subset \\vH^1(\\domain)$\n    and $p\\in Q \\subset L^2(\\domain)$ such that\n  \\begin{gather}\n    \\label{eq:mixedintro:stokes-weak1}\n    \\begin{aligned}\n      2\\mu\\form(\\strain \\vu, \\strain \\vv) &- \\form(\\div \\vv,p) &=&\\form(\\vf,\\vv)\n      + \\text{bdry}\n      &\\forall \\vv&\\in \\vV\\\\\n      -\\form(\\div \\vu,q) & &=&0+ \\text{bdry}\n      &\\forall q&\\in Q.\\\\      \n    \\end{aligned}\n  \\end{gather}\n  The subspaces $\\vV$ and $Q$ are determined by boundary conditions.\n\\end{Definition}\n\n\\begin{Definition}{solenoidal}\n  A vector-valued function $\\vu$ is called \\define{divergence-free} or\n  \\define{solenoidal}, if there holds\n  \\begin{gather}\n    \\div \\vu = 0.\n  \\end{gather}\n  Flow described by a solenoidal function is called\n  \\define{incompressible}.\n\\end{Definition}\n\n\\begin{Lemma}{stokes-equivalence}\n  Let $\\vV=\\vH^1_0(\\domain)\\cap \\vH^2(\\domain)$. Then, for any\n  solenoidal function $\\vu\\in vV$ there holds\n  \\begin{gather}\n    \\label{eq:mixedintro:6}\n    2\\mu\\form(\\strain \\vu, \\strain \\vv) = \\mu\\form(\\nabla \\vu, \\nabla \\vv)\n    \\qquad\\forall \\vv\\in \\vV.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  We have ('$:$' denoting the \\putindex{double contraction} of\n  \\putindex{Frobenius inner product})\n  \\begin{align}\n    \\strain \\vu: \\strain \\vv\n    &= \\frac14\\sum_{i,j=1}^d\\left[ (\\d_i u_j+\\d_j u_i) (\\d_i v_j+\\d_j v_i)\n      \\right]\n    \\\\\n    &= \\frac12\\sum_{i,j=1}^d\\left[ \\d_i u_j\\d_iv_j + \\d_i u_j\\d_j v_i\\right].\n  \\end{align}\n  The first term is the desired result, thus we have to eliminate the\n  other one. We integrate by parts to obtain\n  \\begin{align}\n    \\int_\\domain \\d_i u_j\\d_j v_i \\dx\n    &= - \\int_\\domain \\d_{ij}u_j v_i \\dx\n%     \\\\ &\n    = \\int_\\domain \\d_j u_j \\d_i v_i \\dx \n  \\end{align}\n  Entering in the\n  previous equation and summing over $i$ and $j$, we obtain\n  \\begin{gather}\n    2(\\strain \\vu,\\strain \\vv)\n    = (\\nabla \\vu,\\nabla \\vv)+(\\div \\vu,\\div \\vv)\n                           = (\\nabla \\vu,\\nabla \\vv).\n  \\end{gather}\n\\end{proof}\n\n\\begin{intro}\n  In order to simplify subsequent discussion, it is customary to use\n  the previous lemma to simplify the Stokes equations and to replace\n  the strain tensor by the gradient. As a result, we can avoid the use\n  of a Korn inequality and operate directly with the inner product of\n  $\\vH^1$. We note though that this formulation, while mathematically\n  simpler, is physically wrong if $\\vu\\neq \\vH^1_0(\\domain)$, that is,\n  having nonzero boundary values.\n\\end{intro}\n\n\\begin{Definition}{stokes-eq2}\n  The simplified \\define{Stokes equations} in strong form are\n    \\begin{gather}\n      \\label{eq:mixedintro:stokes-strong2}\n      \\arraycolsep.2ex\n      \\begin{matrix}\n        - \\nu \\Delta \\vu &+& \\nabla p &=& \\vf \\\\\n        \\div \\vu && &=& 0.\n      \\end{matrix}\n    \\end{gather}\n    In weak form, they are: find $\\vu\\in \\vV \\subset \\vH^1(\\domain)$\n    and $p\\in Q \\subset L^2(\\domain)$ such that\n  \\begin{gather}\n    \\label{eq:mixedintro:stokes-weak2}\n    \\begin{aligned}\n      \\nu\\form(\\nabla \\vu, \\nabla \\vv) &- \\form(\\div \\vv,p) &=&\\form(\\vf,\\vv)\n      + \\text{bdry}\n      &\\forall \\vv&\\in \\vV\\\\\n      -\\form(\\div \\vu,q) & &=&0+ \\text{bdry}\n      &\\forall q&\\in Q.\\\\      \n    \\end{aligned}\n  \\end{gather}\n  The subspaces $V$ and $Q$ are determined by boundary conditions.\n\\end{Definition}\n\n\\begin{Definition}{stokes-boundary2}\n  Typical boundary conditions for the Stokes problem are\n  \\begin{xalignat}3\n    \\text{no-slip:}&& \\vu &= 0,\\\\\n    \\text{free:}&& \\d_n \\vu + p \\n &= 0 ,\\\\\n    \\text{slip:}&& \\vu_n &= 0 & \\d_n \\vu_\\tau &= 0,\\\\\n    \\text{friction:}&& \\vu_n &= 0 & \\d_n \\vu_\\tau &= \\alpha \\vu_\\tau.\n  \\end{xalignat}\n  Here, $\\vu_n$ and $\\vu_\\tau$ are the normal and tangential components of\n  $\\vu$ at the boundary.\n\\end{Definition}\n\n\\begin{remark}\n  Very much the same way as for elliptic equations, boundary\n  conditions on the function $\\vu$ itself are essential boundary\n  conditions which have to be incorporated into the space $V$, while\n  those involving normal derivatives are the result of integration by\n  parts and thus of the type of natural boundary conditions.\n\n  All of the conditions above can also be imposed with nonzero data,\n  where the physical meaning of such a condition might be debatable in\n  some cases. Mathematically, inhomogeneous essential boundary\n  conditions are achieved by lifting an arbitrary function with this\n  boundary condition and modifying the right hand side of the\n  equation, while inhomogeneous conditions on the normal derivative\n  are implemented by boundary integrals on the right hand side.\n\\end{remark}\n\n\\begin{remark}\n  Physically, the condition $\\vu_n=0$ models an impermeable wall. It\n  says in particular, that no mass is lost through this boundary and\n  is thus related to the first principle of mass conservation.\n\n  The conditions on the tangential velocity model the fact that\n  molecules very close to the wall stick to the wall. While this claim\n  is not supported by a first principle, it has been verified by\n  measurements to very high accuracy. Nevertheless, in the study of\n  turbulent flow, a friction condition comes up quite naturally.\n\\end{remark}\n\n\\begin{Lemma}{divergence-compatibility}\n  For any solenoidal $\\vu$ function there holds\n  \\begin{gather}\n    \\int_{\\d\\domain} \\vu\\cdot \\n\\ds = 0.\n  \\end{gather}\n  Furthermore, if the space $\\vV$ in the Stokes equations is chosen such that for any $\\vv\\in \\vV$ there holds $\\vv_n=0$ on the whole\n  boundary $\\d\\domain$, then the pressure $p$ is determined by the\n  Stokes equations only up to a constant.\n\\end{Lemma}\n\n\\begin{proof}\n  The first statement is simple application of the Gauss theorem\n  \\begin{gather}\n    \\int_{\\domain} \\div \\vu\\dx = \\int_{\\d\\domain} \\vu\\cdot \\n\\ds.\n  \\end{gather}\n  For the second statement, we note that the only term in the\n  equations which determines the pressure is $\\form(\\div \\vv,\n  p)$. Integrating by parts and using the boundary condition, we\n  obtain\n  \\begin{gather}\n    \\int_\\domain \\div \\vv\\,p\\dx\n    = -\\int_\\domain \\vv\\cdot\\nabla p\\dx +\n    \\int_{\\d\\domain} \\vv\\cdot \\n \\,p\\ds\n    = -\\int_\\domain \\vv\\cdot \\nabla p\\dx.\n  \\end{gather}\n  Since the gradient of a constant is zero, we can add any constant\n  function to a given solution $p$ without changing the term\n  $\\form(\\div \\vv,p)$, thus leaving $p$ determined only up to a\n  constant.\n\\end{proof}\n\n\\begin{Notation}{pressure-constant}\n  If in Definition~\\ref{Definition:stokes-eq2} the space $\\vV$ is chosen\n  such that for all $\\vv\\in \\vV$ there holds $\\vv\\cdot \\n =0$ on the whole\n  boundary $\\d\\domain$, then the pressure solution $p$ cannot be\n  determined uniquely in $L^2(\\domain)$. In such cases, we choose the\n  pressure space\n  \\begin{gather}\n    L^2_0(\\domain) = L^2(\\domain)/\\R\n    = \\biggl\\{q\\in L^2(\\domain)\\bigg| \\int_\\domain q\\dx = 0\\bigg\\}. \n  \\end{gather}\n\\end{Notation}\n\n\\begin{remark}\n  As we could see from the preceding lemma, solvability of\n  equation~\\eqref{eq:mixedintro:stokes-weak2} depends on some\n  compatibility of the spaces $\\vV$ and $Q$ we had not seen in the\n  elliptic case. Indeed, we need a whole new tool from functional\n  analysis to replace the Lax-Milgram lemma. This tool will be studied\n  in Chapter~\\ref{sec:mixed-wellposedness}.\n\\end{remark}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "2faed5bb6fddaf716dc0e439e525aa7a931d891f", "size": 34515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mixed/mixedintro.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/mixedintro.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/mixedintro.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": 39.4006849315, "max_line_length": 141, "alphanum_fraction": 0.6813849051, "num_tokens": 11375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.6982585427510372}}
{"text": "\\documentclass{article}\n\n\\usepackage[stdmargin, noindent]{../../rajeev}\n\\usepackage{mathtools}\n\\usepackage{dirtytalk}\n\n\\pagestyle{fancy}\n\\rhead{\\today}\n\\lhead{Math 291H HW \\#2}\n\n\\begin{document}\n\n\\begin{center}\n    \\Large \\textbf{Math 291H Homework \\#2}\n\\end{center}\n\\begin{center}\n    \\Large Rajeev Atla\n\\end{center}\n\n\nHonors Pledge Statement: \\say{The writeup of this submission is my own work alone.}\n\n\\problem{1.19}\n\n\\subsection*{a}\n\n\\begin{align*}\n  \\pars{1, 1, 0} + t \\pars{1, -1, 2} &= \\pars{2, 0, 2} + s \\pars{-1, 1, 0} \\\\\n  \\pars{t, -t, 2t} - \\pars{-s, s, 0} &= \\pars{1, -1, 2} \\\\\n  \\pars{t + s, -t-s, 2t} &= \\pars{1, -1, 2} \\\\\n\\end{align*}\n\nThis implies that $t=1$, which means that $s=0$.\nResubstituting, we find the point of intersection to be \\boxed{\\pars{2, 0, 2}}.\n\n\\subsection*{b}\n\nLet $\\bm{v}_1 = \\pars{1, -1, 2}$ and $\\bm{v}_2 = \\pars{-1, 1, 0}$.\nBoth these vectors are in the plane.\nWe next find the normal vector $\\bm{n}$.\n\n$$\n\\bm{n} = \\bm{v}_1 \\times \\bm{v}_2 = \\pars{-2, -2, 0}\n$$\n\nThe general form of a plane is $\\bm{n} \\cdot \\bm{x} = d$.\nSubstituting $\\bm{x} = \\pars{1, 1, 0}$, we see that $d=-4$.\nThe equation for the plane is therefore\n\n$$\n-2 x + -2y = -4\n$$\n\nWe can simplify this a little to get\n\n$$\n\\boxed{x + y = 2}\n$$\n\n\\problem{1.20}\nDefining $\\bm{n} := \\pars{2, -1, 3}$ and $\\bm{x}_0 := \\pars{2, 0, 0}$, we can write the given equation as\n\n$$\n\\bm{n} \\cdot \\pars{\\bm{x} - \\bm{x}_0} = 0\n$$\n\nWe normalize $\\bm{n}$, getting\n\n$$\n\\bm{u} = \\frac{1}{\\sqrt{14}} \\pars{2, -1, 3}\n$$\n\nThe minimal distance between this plane and $\\bm{p}$ is then\n\n$$\n\\abs{\\pars{\\bm{x}_0 - \\bm{p}} \\cdot \\bm{u}} = \\frac{1}{\\sqrt{14}} \\abs{\\pars{2, 3, 0} \\cdot \\pars{2, -1, 3}} = \\boxed{\\frac{1}{\\sqrt{14}}}\n$$\n\n\n\\problem{1.24}\n\nLet $k \\in \\RR$, so that\n\n$$\nh_{\\bm{u}} \\pars{\\bm{x}} = k \\bm{e}_1\n$$\n\nSince $\\norm{h_{\\bm{u}} \\pars{\\bm{x}}} = \\norm{\\bm{x}}$, \\boxed{k= \\pm 7}.\n\nBy construction of the Householder reflection,\n\n\\begin{align*}\n  \\bm{u} &= \\pm \\frac{\\bm{x} - k \\bm{e}_1 }{\\norm{\\bm{x} - k \\bm{e}_1}} \\\\\n         &= \\pm \\frac{\\pars{5 \\pm 7, 2, 4, 2}}{\\norm{\\pars{5 \\pm 7, 2, 4, 2}}} \\\\\n  &= \\boxed{\\frac{\\pars{6, 1, 2, 1}}{\\sqrt{42}}, -\\frac{\\pars{6, 1, 2, 1}}{\\sqrt{42}}, \\frac{\\pars{-1, 1, 2, 1}}{\\sqrt{10}}, - \\frac{\\pars{-1, 1, 2, 1}}{\\sqrt{10}} }\\\\\n\\end{align*}\n\n(In the first two lines, the outer $\\pm$ signs are independent of the inner ones.)\n\n\\problem{1.27}\nWe define the orthonormal basis\n\n\\begin{align*}\n  \\bm{u}_1 &= \\frac{\\bm{v}_1 \\times \\bm{v}_2}{\\norm{\\bm{v}_1 \\times \\bm{v}_2}} \\\\\n           &= \\frac{1}{\\sqrt{14}}\\pars{-3, -2, 1} \\\\\n  \\bm{u}_2 &= \\frac{1}{\\norm{\\bm{v}_1}} \\bm{v}_1 \\times \\bm{u}_1 \\\\\n           &= \\frac{1}{ \\sqrt{10}} \\pars{-1, 0, -3} \\\\\n  \\bm{u}_3 &= \\bm{u}_1 \\times \\bm{u}_2 \\\\\n           &= \\frac{1}{\\sqrt{35}} \\pars{3, -5, -1} \\\\\n\\end{align*}\n\nWe can then define\n\n$$\n\\bm{b} = \\bm{x}_1 - \\bm{x}_2 = \\pars{0, 3, 1}\n$$\n\nWe then have\n\n$$\nt = \\frac{\\bm{b} \\cdot \\bm{u}_2}{\\bm{v}_2 \\cdot \\bm{u}_2} = \\frac{-5}{10} = - \\frac{1}{2}\n$$\n\nThe point on the first line that corresponds to this $t$-value is\n$$\n\\boxed{\\pars{\\frac{3}{2}, -\\frac{1}{2}, -\\frac{5}{2}}}\n$$\n\nSimilarly,\n\n$$\ns = \\frac{ t \\pars{\\bm{v}_2 - \\bm{b} } \\cdot \\bm{u}_3 }{\\bm{v}_1 \\cdot \\bm{u}_3} = \\frac{- \\frac{1}{2} \\pars{-1, 0, 2} \\cdot \\pars{3, -5, -1}}{\\pars{1, -4, -2} \\cdot \\pars{3, -5, -1}} = \\frac{\\frac{5}{2}}{25}  = \\frac{1}{10}\n$$\n\n$$\n\\boxed{\\pars{\\frac{33}{10}, \\frac{3}{2}, \\frac{9}{10}}}\n$$\n\nThe distance between these points is\n\n$$\n\\abs{\\bm{b} \\cdot \\bm{u}_1} = \\boxed{\\frac{5}{\\sqrt{14}}}\n$$\n\n\n\\problem{1.29}\n\n\\subsection*{a}\n\nIt's easy to see that $\\norm{\\bm{u}_i} = 1$.\nIn addition, we can compute\n\n\\begin{align*}\n  \\bm{u}_1 \\cdot \\bm{u}_2 &= \\frac{1}{9} \\pars{1 \\cdot 2 + 2 \\cdot 1 - 2 \\cdot 2} = 0 \\\\\n  \\bm{u}_1 \\cdot \\bm{u}_3 &= \\frac{1}{9} \\pars{1 \\cdot 2 + 2 \\cdot \\pars{-2} -2 \\cdot \\pars{-1}} = 0 \\\\\n  \\bm{u}_2 \\cdot \\bm{u}_3 &= \\frac{1}{9} \\pars{2 \\cdot 2 + 1 \\cdot \\pars{-2} + 2 \\cdot \\pars{-1}} = 0 \\\\\n\\end{align*}\n\nWe see that\n\n$$\n\\bm{u}_1 \\times \\bm{u}_2 = \\frac{1}{3} \\pars{2, -2, -1} = \\bm{u}_3\n$$\n\nTherefore, this is a right-handed orthonormal basis.\n\n\\subsection*{b}\n\n$$\n\\bm{u} = \\frac{\\bm{u}_1 - \\bm{e}_1}{\\norm{\\bm{u}_1 - \\bm{e}_1}} = \\frac{\\frac{1}{3} \\pars{-2, 2, -2}}{\\frac{1}{3} \\norm{\\pars{-2, 2, -2}}} = \\boxed{\\frac{1}{\\sqrt{3}} \\pars{-1, 1, -1}}\n$$\n\n\\subsection*{c}\n\n\\begin{align*}\n  h_{\\bm{u}} \\pars{\\bm{u}_2} &= \\bm{u}_2 - 2 \\pars{\\bm{u}_2 \\cdot \\bm{u}} \\bm{u} \\\\\n                             &= \\frac{1}{3} \\pars{2, 1, 2} - \\frac{2}{9} \\pars{-3} \\pars{-1, 1, -1} \\\\\n                             &= \\pars{\\frac{2}{3}, \\frac{2}{3}, \\frac{1}{3}} + \\pars{-\\frac{2}{3}, \\frac{2}{3}, -\\frac{2}{3}} \\\\\n                             &= \\boxed{\\pars{0, 1, 0} = \\bm{e}_2} \\\\\n  h_{\\bm{u}} \\pars{\\bm{u}_3} &= \\bm{u}_3 - 2 \\pars{\\bm{u}_3 \\cdot \\bm{u}} \\bm{u} \\\\\n                             &= \\frac{1}{3} \\pars{2, -2, -1} - \\frac{2}{9} \\pars{-3} \\pars{-1, 1, -1} \\\\\n                             &= \\pars{\\frac{2}{3}, - \\frac{2}{3}, - \\frac{1}{3}} + \\pars{- \\frac{2}{3}, \\frac{2}{3}, - \\frac{2}{3}} \\\\\n                             &= \\boxed{\\pars{0, 0, 1} = \\bm{e}_1} \\\\\n\\end{align*}\n\n\n\n\\problem{1.32}\n\n\\subsection*{a}\n\nDefine $V := V_1 \\cap V_2$.\nSuppose we have vectors $\\bm{r}_1, \\bm{r}_2 \\in V$ and scalars $a, b \\in \\RR$.\nBy definition, $\\bm{r}_1 \\in V_1, V_2$ and $\\bm{r}_2 \\in V_1, V_2$.\nBy definition of a subspace, $a \\bm{r}_1 \\in V_1, V_2$ and $b \\bm{r}_1 \\in V_1, V_2$.\nSince these vectors are in both subspaces, we can say that\n\n$$\na \\bm{r}_1 + b \\bm{r}_2 \\in V_1, V_2\n$$\n\nThis is what we wanted to show.\n\n\\subsection*{b}\n\nIf we scale up $\\bm{z}$ by a factor of $\\alpha$, we get\n\n$$\n\\alpha \\bm{z} = \\alpha \\bm{x} + \\alpha \\bm{y}\n$$\n\nSince $\\alpha \\bm{x} \\in V_1$ and $\\alpha \\bm{x} \\in V_2$ by the definition of a subspace, $\\alpha \\bm{z} \\in V_1 + V_2$ by the construction of $V_1 + V_2$.\nSimilarly, let\n\n$$\n\\bm{z'} = \\bm{z}_1 + \\bm{z}_2 = \\bm{x}_1 + \\bm{y}_1 + \\bm{x}_2 + \\bm{y}_2 = \\pars{\\bm{x}_1 + \\bm{x}_1} + \\pars{\\bm{y}_1 + \\bm{y}_2}\n$$\n\nBy the definition of a subspace, $\\bm{x}_1 + \\bm{x}_2 \\in V_1$.\nSimilarly, $\\bm{y}_1 + \\bm{y}_2 \\in V_2$.\nTherefore, by construction, $\\bm{z}_1 + \\bm{z}_2 \\in V_1 + V_2$.\n\n\\problem{1.33}\n\nDefine $V_3 := V_1 + V_2$ and $V := V_1 \\cap V_2$.\nWe then define an orthonormal basis for $V$.\n\n$$\n\\set{\\bm{u}_1, \\dots, \\bm{u}_p}\n$$\n\nTherefore, $\\dim \\pars{V} = p$.\nWe can extend $\\set{\\bm{u}_1, \\dots, \\bm{u}_p}$ to find orthonormal bases for $V_1$ and $V_2$.\nBy definition, $V \\subseteq V_1$ and $V \\subseteq V_2$.\nTherefore, $\\spn V \\subseteq \\spn V_1$ and $\\spn V \\subseteq \\spn V_2$.\nSimilarly, $\\spn V_1 \\subseteq \\spn V_3$ and $\\spn V_2 \\subseteq V_3$.\nWe can therefore write and define\n\n\\begin{align*}\n  S &:= \\set{\\bm{u}_1, \\cdots, \\bm{u}_p, \\bm{v}_1, \\cdots, \\bm{v}_q} \\\\\n  T &:= \\set{\\bm{u}_1, \\cdots, \\bm{u}_p, \\bm{w}_1, \\cdots, \\bm{w}_r} \\\\\n  V_1 &= \\spn \\set{\\bm{u}_1, \\cdots, \\bm{u}_p, \\bm{v}_1, \\cdots, \\bm{v}_q} \\\\\n  V_2 &= \\spn \\set{\\bm{u}_1, \\cdots, \\bm{u}_p, \\bm{w}_1, \\cdots, \\bm{w}_r} \\\\\n\\end{align*}\n\nIt's easy to see that $V_1 \\subseteq \\spn \\pars{S \\cup T}$ and $V_2 \\subseteq \\spn \\pars{S \\cup T}$.\nTherefore, $V_3 \\subseteq \\spn \\pars{S \\cup T} $.\nIn addition, $\\pars{S \\cup T} \\subseteq V_3$, so $\\spn \\pars{S \\cup T} \\subseteq V_3$.\nTherefore,\n\n\\begin{align*}\n  V_3 &= \\spn \\pars{S \\cup T} \\\\\n      &= \\spn \\set{\\bm{u}_1, \\cdots, \\bm{u}_p, \\bm{v}_1, \\cdots, \\bm{v}_q, \\bm{w}_1, \\cdots, \\bm{w}_r} \\\\\n  \\dim V_3 &= p+q+r \\\\\n\\end{align*}\n\nWe can now verify that\n\n\\begin{align*}\n  \\dim V_3 + \\dim V &= \\dim V_1 + \\dim V_2 \\\\\n  \\pars{p + q + r} + \\pars{p} &= \\pars{p+q} + \\pars{p+r} \\\\\n\\end{align*}\n\n\n\n\n\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "d3abcdb60e27ac76ed02550160734153498c0e3d", "size": 7633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Assignment 2/hw2.tex", "max_stars_repo_name": "RajeevAtla/Math-291", "max_stars_repo_head_hexsha": "1aab6358d90b23ef62d57d8e67ae22124961a903", "max_stars_repo_licenses": ["MIT"], "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/Assignment 2/hw2.tex", "max_issues_repo_name": "RajeevAtla/Math-291", "max_issues_repo_head_hexsha": "1aab6358d90b23ef62d57d8e67ae22124961a903", "max_issues_repo_licenses": ["MIT"], "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/Assignment 2/hw2.tex", "max_forks_repo_name": "RajeevAtla/Math-291", "max_forks_repo_head_hexsha": "1aab6358d90b23ef62d57d8e67ae22124961a903", "max_forks_repo_licenses": ["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.9597069597, "max_line_length": 224, "alphanum_fraction": 0.5367483296, "num_tokens": 3475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.6982585419947454}}
{"text": "\\section*{Problem 1: Gaussian Random Projections and Inner Products}\n\nLet $\\phi(x) = \\frac{1}{\\sqrt{m}}Ax$ represent our random projection of\n$x \\in \\mathbb{R}^d$, with $A$ an $m \\times d$ projection matrix with each entry\nsampled i.i.d from $N\\left(0,1\\right)$. Note that each row of $A$ is a random\nprojection vector, $v^{(i)}$.\n\nThe \\emph{norm preservation theorem} states that for all $x \\in \\mathbb{R}^d,$\nthe norm of the random projection $\\phi\\left(x\\right)$ approximately maintains\nthe norm of the original $x$ with high probability:\n\\begin{equation}\n  \\mathbb{P}\\left(\n    (1 - \\epsilon) \\lVert x \\rVert^2\n    \\leq\n    \\lVert \\phi\\left(x\\right) \\rVert^2\n    \\leq\n    \\left(1 + \\epsilon\\right) \\lVert x \\rVert^2\n  \\right)  \n  \\geq 1 - 2\\exp\\left(-\\left(\\epsilon^2 - \\epsilon^3\\right)m/4\\right),\n  \\label{eqn:1thm}\n\\end{equation}\nwhere $\\epsilon \\in \\left(0,1/2\\right).$\n\nUsing the norm preservation theorem, prove that for any $u, v \\in \\mathbb{R}^d$\nsuch that $\\lVert u \\rVert \\leq 1$ and $\\lVert v \\rVert \\leq 1$,\n\\begin{equation}\n  \\mathbb{P}\\left(\\lvert u \\cdot v - \\phi\\left(u\\right)\\cdot\\phi\\left(v\\right)\\rvert \\geq \\epsilon\\right) \\leq 4\\exp\\left(\n    -\\left(\\epsilon^2 - \\epsilon^3\\right)m/4\n  \\right)\n  \\label{eqn:1}\n\\end{equation}\n\n\\subsection*{Solution}\n\\begin{proof}\n  First note that\n  \\begin{equation*}\n      (1 - \\epsilon) \\lVert u + v \\rVert^2\n      \\leq\n      \\lVert \\phi\\left(u + v\\right) \\rVert^2\n      \\leq\n      \\left(1 + \\epsilon\\right) \\lVert u + v \\rVert^2\n    \\end{equation*}\n    implies that\n    \\begin{equation}\n      \\lVert u + v \\rVert^2 - 2\\epsilon\n      \\leq\n      \\lVert \\phi\\left(u + v\\right) \\rVert^2\n      \\leq\n      \\lVert u + v \\rVert^2 + 2\\epsilon\n      \\label{eqn:1sup}\n    \\end{equation}\n    by triangle inequality and the assumption of the norms of $u$ and $v$.\n\n    Thus, the probability of the event in Equation \\ref{eqn:1sup} than that of\n    Equation \\ref{eqn:1thm}.\n      \n    Using this and taking the additive inverse, we have that\n  \\begin{align}\n    \\mathbb{P}\\left(\n    \\left\\lVert \\phi(u + v) \\right\\rVert^2\n    \\not\\in\n    \\left[\n    \\lVert u + v \\rVert^2 - 2\\epsilon,\n    \\lVert u + v \\rVert^2 + 2\\epsilon\n    \\right]\n    \\right)\n    &\\leq 2\\exp\\left(-\\left(\\epsilon^2 - \\epsilon^3\\right)m/4\\right)\n      \\label{eqn:1conda}\\\\\n    \\mathbb{P}\\left(\n    \\left\\lVert \\phi(u - v) \\right\\rVert^2\n    \\not\\in\n    \\left[\n    \\lVert u - v \\rVert^2 - 2\\epsilon,\n    \\lVert u - v \\rVert^2 + 2\\epsilon\n    \\right]\n    \\right)\n    &\\leq 2\\exp\\left(-\\left(\\epsilon^2 - \\epsilon^3\\right)m/4\\right).\n      \\label{eqn:1condb}\n  \\end{align}\n\n  By the countable sub-additivity property of probability distributions, we have\n  that the probability of both these events occurring is at most\n  $4\\exp\\left(-\\left(\\epsilon^2 - \\epsilon^3\\right)m/4\\right)$. Thus, we are\n  done if we can show\n  $\\left\\{\\left\\lvert u \\cdot v - \\phi(u) \\cdot \\phi(v) \\right\\rvert \\geq\n    \\epsilon\\right\\}$ subsets these two conditions.\n\n  If we have the pair\n  \\begin{align}\n    \\left\\lVert \\phi(u + v) \\right\\rVert^2\n    &\\leq \\left\\lVert\n      u + v\n      \\right\\rVert^2 - 2\\epsilon \\Rightarrow\n      \\left\\lVert\n      u + v\n      \\right\\rVert^2 -\n      \\left\\lVert \\phi(u + v) \\right\\rVert^2\n      \\geq\n      2\\epsilon\n    \\\\\n    \\left\\lVert \\phi(u - v) \\right\\rVert^2\n    &\\geq \\left\\lVert\n      u - v\n      \\right\\rVert^2 + 2\\epsilon \\Rightarrow\n      \\left\\lVert\n      u - v\n      \\right\\rVert^2 -\n      \\left\\lVert \\phi(u - v) \\right\\rVert^2\n      \\geq\n      2\\epsilon,\n  \\end{align}\n  we can use the linearity of $\\phi$ and the expansion\n  $\\lVert u \\pm v \\rVert^2 = \\lVert u \\rVert^2 + \\lVert v \\rVert^2 \\pm 2u \\cdot\n  v$, we can add the two inequalities to obtain\n  \\begin{align}\n    4\\left(\n    u \\cdot v\n    -\n    \\phi\\left(u\\right)\\cdot\\phi\\left(v\\right)\n    \\right)\n    \\geq 4\\epsilon.\n    \\nonumber\n  \\end{align}\n\n  Thus, we have that the conditions in Equations \\ref{eqn:1conda} and\n  \\ref{eqn:1condb} imply\n  $u \\cdot v - \\phi\\left(u\\right)\\cdot\\phi\\left(v\\right) \\geq \\epsilon$.\n\n  Similarly, we show that the pair\n  \\begin{align}\n    \\left\\lVert \\phi(u + v) \\right\\rVert^2\n    &\\geq \\left\\lVert\n      u + v\n      \\right\\rVert^2 + 2\\epsilon \n    \\\\\n    \\left\\lVert \\phi(u - v) \\right\\rVert^2\n    &\\leq \\left\\lVert\n      u - v\n      \\right\\rVert^2 - 2\\epsilon\n  \\end{align}\n  implies\n  $u \\cdot v - \\phi\\left(u\\right)\\cdot\\phi\\left(v\\right) \\leq -\\epsilon$, which\n  gives us\n  $\\left\\lvert u \\cdot v - \\phi\\left(u\\right)\\cdot\\phi\\left(v\\right)\n  \\right\\rvert \\geq \\epsilon.$\n\\end{proof}\n", "meta": {"hexsha": "89d8c042cba08342e9a7c48b60cb133be54019a7", "size": 4526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3/problem1/problem1.tex", "max_stars_repo_name": "kspathak/cse547", "max_stars_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_stars_repo_licenses": ["MIT"], "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/problem1/problem1.tex", "max_issues_repo_name": "kspathak/cse547", "max_issues_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_issues_repo_licenses": ["MIT"], "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/problem1/problem1.tex", "max_forks_repo_name": "kspathak/cse547", "max_forks_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-18T01:39:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-18T01:39:20.000Z", "avg_line_length": 30.7891156463, "max_line_length": 122, "alphanum_fraction": 0.6129032258, "num_tokens": 1731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.6981715271795728}}
{"text": "\\chapter{Shortest Path}\n\nGiven a weighted graph, one interesting problem is to find the\npath with minimal weight.\n\n\\section{Single Source}\n\nThis instance of the shortest path problem begins at a specific vertex\nin the graph, hence ``Single Source.''\n\n\\subsection{Dijkstra's Algorithm}\n\nGiven an acyclic graph $G=(V,E)$ in which every edge has a positive\nweight and a single vertex $s$ from which to start the path, we begin\nby labeling all vertices $u \\in E | weight(u) = \\infty$, then label\n$weight(s) = 0$.  We also create a min-heap of the vertices using\nweight as key.\n\nWe pop-best a vertex $v$ from our heap.  For each edge $e$ incident to\n$v$ and some other vertex $u$, we check if $weight(v) + weight(e)$ is\nless than $weight(u)$, in which case we set $weight(u) = weight(v) +\nweight(e)$ and decrease the key of $u$ in our heap.  We continue this\nprocess until no vertices remain in the heap.\n\nIt should be easy to see that if we have a particular target vertex,\nwe can halt the algorithm as soon as our target is the root of the\nheap, because we have found the shortest path to it.\n\n\\subsection{Analysis of Dijkstra's Algorithm}\n\nIntuitively, this algorithm has an upper bound of $O(|V|)$ times\nhowever long it takes us to extract the minimum vertex from our heap,\nplus $O(|E|)$ times however long it takes us to decrease the key,\nsince we have to check every vertex and we may have to check every\nedge.  Using a standard heap, this gives us $O(|V|log|V| +\n|E|log|V|)$.\n\n\\section{All Sources}\n\nThis instance of the shortest path problem is concerned with several\nsources, in which case Dijkstra's Algorithm does not suffice.\n\n\\subsection{Floyd-Warshall Algorithm}\n\nThe Floyd-Warshall Algorithm is\n\\hyperlink{sec:floyd_warshall}{discussed in detail in the chapter on\n  Dynamic Programming}.\n\n\\section{Arbitrary Weights}\n\nA keen reader will have noticed that both Dijkstra's and Floyd\nWarshall Algorithms assume positive edge weights.  Neither of which\nare generally useful when there may be edges of negative weight.\n\n\\subsection{Bellman-Ford Algorithm}\n\nThe Bellman-Ford Algorithm can be applied with edges of arbitrary\nweight.  Note that even Bellman-Ford doesn't deal with cycles of\nnegative weight, since these can be used to make any path have an\narbitrarily small total weight.\n\nThe Bellman-Ford Algorithm is beyond the scope of these notes, for\nmore information please see\n\\href{https://en.wikipedia.org/wiki/Bellman-Ford}{Wikipedia's entry on\n  the Bellman-Ford Algorithm}, or CLRS.\n", "meta": {"hexsha": "f8424a4c2769b197c6e14e18f7e49a4e9af7da3b", "size": 2498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "shortest_path.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "shortest_path.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "shortest_path.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.8484848485, "max_line_length": 70, "alphanum_fraction": 0.7646116894, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6981715033798943}}
{"text": "\n%These notes summarize the lecture notes from the Linear Modelling course at Sheffield's School of Mathematics and Statistics, MSc degree programme. The original notes were written by Dr.\\ Kevin Walters and Dr.\\ Jeremy Oakley. This summary is completely derived from these notes and from other MSc sources. Any errors are most probably mine.\n\n%Everything is in matrix form unless a lower case letter with a subscript (such as $x_i$) is used (even there, I might deviate from this convention if I need to index sub-matrices; it's best to look at the context to decide what is meant).\n\n\n\\section{Background}\n\n\\subsection{Derivations of combinations of functions}\n\n\\begin{equation}\n  (uv)' = uv' + vu'\n\\end{equation}\n\n\\begin{equation}\n(u/v)' = \t\\frac{vu' - uv'}{v^2}\n\\end{equation}\n\n\n\\subsection{Some key distributional results}\n\n\n\\subsection{Some very basic matrix algebra facts}\n\n\\textbf{Inverse (2x2)}: \n\n$\\begin{pmatrix}\na & b \\\\\nc & d\\\\\n\\end{pmatrix}^{-1}\n= \\frac{1}{ad-bc} \n\\begin{pmatrix}\nd & -b \\\\\n-c & a\\\\\n\\end{pmatrix}$\n\n\n\\textbf{Inverse of non-singular matrices}. \nIf A and B are non-singular matrices then $(AB)^{?1} = B^{-1}A^{-1}$.\n\n\\textbf{Symmetric square matrix}: $A=A^T$. \n\nIf a symmetric matrix A is non-singular then $A^{-1}$ is also symmetric.\n\n$AA^{-1}=A^{-1}A=I$ given A is square and invertible.\n \n If the symmetric matrix $A$ is non-singular then $A^{-1}$ is also symmetric.\n \n \\textbf{Multiplication is distributive}: Multiplication is distributive over addition and subtraction, so $(A-B)(C-D)=AC -BC-AD+BD$.\n\n\\textbf{Transpose}: $(A+B)^T =A^T+B^T$ and $(AB)^T =B^TA^T$\n\n\\textbf{Sum of squares}: $\\sum x_i^2 = \\mathbf{x}^T \\mathbf{x}$.\n\n\\textbf{Symmetry under multiplication}: If A is $n\\times p$, then $AA^T$ and $A^TA$ are symmetric.\n\n\n\n\n\\textbf{Trace of a square matrix}: \n\n\\begin{enumerate}\n\\item\n$tr(A)=\\sum a_{ii}$\n\\item\n$tr(A + B) = tr(A) + tr(B)$\n\\item \n$tr(cA) = ctr(A)$\n\\item\n$tr(AB) = tr(BA)$\n\\end{enumerate}\n\n\\textbf{Idempotent}:  $A^2 = AA = A$. Example: $A = I_n$; this is the only non-singular idempotent matrix. \n\nIf A is idempotent and if $A\\neq I_n$, then A is singular and its trace is equal to its rank $n-p$, for some $p>0$.\n\n\\textbf{Inverse of a matrix product}:\nIf A and B are non-singular matrices then $(AB)^{-1} = B^{-1}A^{-1}$.\n\n\\textbf{Rank}: the number of linearly independent columns or rows of A.\n\nHow to determine linear independence: \n\n\\section{Basic facts}\n\n\\begin{equation}\ny=X\\beta+\\epsilon\n\\end{equation}\n\n\\begin{tabular}{@{}ll@{}ll@{}}\n$E(y) = X\\beta = \\mu$ &  & $E(\\epsilon)=0$  \\\\\n$Var(y) = \\sigma^2 I_n $ & & $Var(\\epsilon) = \\sigma^2 I_n$ \\\\\n%y+X\\hat{\\beta} + e$ \\\\\n%%$E(y) = X\\beta = \\mu$ & Var\\\\\n% $\\epsilon \\sim N_p (0,\\sigma^2I_n)$  & No \\verb!\\part! divisions. \\\\\n%\\verb!article! & No \\verb!\\part! or \\verb!\\chapter! divisions. \\\\\n%\\verb!letter!  & Letter (?). \\\\\n%\\verb!slides!  & Large sans-serif font.\n\\end{tabular}\n\n\\begin{equation}\ny = X\\hat{\\beta} + e\n\\end{equation}\n\n\\begin{fmpage}{\\linewidth}\nNote that $S_{xx}=\\frac{1}{(X'X)^{-1}}$, and \n$G=(X'X)^{-1}$, so that $S_{xx}=\\frac{1}{G}$.\n\\end{fmpage}\n\n\\begin{tabular}{@{}ll@{}ll@{}}\nResults for $\\hat{\\beta}$ & Results for $e$\\\\\n$E(\\hat{\\beta}) = \\beta$ & $E(e) = 0$\\\\\n$Var(\\hat{\\beta}) = \\sigma^2 (X^T X)^{-1} = \\frac{\\sigma^2}{S_{xx}}=\\sigma^2G$ & $Var(e)=\\sigma^2 M$  \\\\\n$\\hat{\\beta} \\sim N_p(\\beta,\\sigma^2 (X^T X)^{-1})$ & $Var(e_i)=\\sigma^2 m_{ii} $\\\\ \n&  $E(e_i^2)= \\sigma^2 m_{ii}$\\\\\n$\\hat{\\beta} = (X^T X)^{-1} X^T y$, $X$ has full rank  & $E(\\sum e_i^2) = \\sigma^2 (n-p)$\\\\\n\\end{tabular}\n\n\\medskip\n\\textbf{Sum of Squares}:\n\n\\begin{equation}\nS(\\hat{\\beta}) = \\sum e_i^2 = e^T e = (y-X\\hat{\\beta})^T (y-X\\hat{\\beta})  = y^T y - y^T X \\hat{\\beta} = S_r\n\\end{equation}\n\nAlternatively: $S_r= y^Ty - \\hat{\\beta}^T X^T X\\hat{\\beta}=y^Ty - \\hat{\\beta}^T X^T y$ (see review exercises 2).\n\n\\textbf{Estimation of error variance: $e=My$}\n\n\\begin{equation}\ne = y - X\\hat{\\beta} = y - X (X^T X)^{-1} X^T y = My\n\\end{equation}\n\n\\noindent\nwhere\n\n\\begin{equation}\nM = I_n -  X (X^T X)^{-1} X^T \n\\end{equation}\n\nM is symmetric, idempotent $n\\times n$.\n\nNote that $MX=0$, which means that \n\n\\begin{equation}\nE(e)=E(My) = ME(y)= MX\\beta = 0\n\\end{equation}\n\nAlso, $Var(e) = Var(My) = M Var(y) M^T = \\sigma^2 I_n M$.\n\n\\medskip\n\\textbf{Important properties of M}:\n\n\\begin{itemize}\n\\item $M$ is singular because every idempotent matrix except $I_n$ is singular.\n\\item $trace(M)=rank(M)=n-p$.\n\\end{itemize}\n\n\\medskip\n\n\n\\textbf{Residual mean square}:\n\\begin{equation}\n\\hat{\\sigma}^2 = \\frac{\\sum e_i^ 2}{n-p} \\quad E(\\hat{\\sigma}^2)=\\sigma^2\n\\end{equation}\n\nThe square root of $\\hat{\\sigma}^2$, $\\hat{\\sigma}$ is the \\textbf{residual standard error}.\nNote: The phrase ``standard error'' here should not be misinterpreted to mean standard error in the sense of ``SE''. \n\n\\textbf{Variance-covariance matrix}:\n\nIn a model like \\begin{verbatim}fm<-lm(Maint ~ Age, data = data)\\end{verbatim}, the variance-covariance matrix is:\n\n\\begin{equation}\n\\begin{pmatrix}\nVar(\\hat{\\beta}_0) & Cov(\\hat{\\beta}_0,\\hat{\\beta}_1) \\\\\nCov(\\hat{\\beta}_0,\\hat{\\beta}_1) & Var(\\hat{\\beta}_1)\\\\\n\\end{pmatrix}\n\\end{equation}\n\nThe correlation between the two parameter estimates is therefore:\n\n\\begin{equation}\nCorr(\\hat{\\beta}_0,\\hat{\\beta}_1) = \\frac{Cov(\\hat{\\beta}_0,\\hat{\\beta}_1)}{SE(\\hat{\\beta}_0) SE(\\hat{\\beta}_1)}\n\\end{equation}\n\n\nExample (tractor data):\n\n\\begin{verbatim}\n> vcov(fm)\n            (Intercept)     Age\n(Intercept)       21591 -4624.0\nAge               -4624  1267.9\n\\end{verbatim}\n\nWe can check the correlation calculation using\n\n\\begin{verbatim}\n> cov2cor(vcov(fm))\n            (Intercept)      Age\n(Intercept)     1.00000 -0.88378\nAge            -0.88378  1.00000\n\\end{verbatim}\n\n\n\n\\subsection{Some short-cuts for hand-calculations}\n\n\\begin{tabular}{@{}ll@{}}\n$S_{xx} = \\sum (x_i - \\bar{x})^2$  & $= \\sum x_i^2 - n\\bar{x}^2$\\\\\n$S_{yy} = \\sum (y_i - \\bar{y})^2$ & $= \\sum y_i^2 - n\\bar{y}^2$\\\\ \n$S_{xy} = \\sum (x_i -\\bar{x})(y_i -\\bar{y})$ & = $\\sum x_i y_i - n\\bar{x}\\bar{y}$\\\\\n\\end{tabular}\n\n\\begin{equation}\n\\hat{\\beta} = (X^T X)^{-1} X^T y = \n\\begin{pmatrix} \n\\bar{y} - \\bar{x} \\frac{S_{xy}}{S_{xx}}\\\\\n\\frac{S_{xy}}{S_{xx}}\n\\end{pmatrix}\n\\end{equation}\n\n\\begin{equation}\nX^T X = \\begin{pmatrix}\nn & \\sum_{i=1}^n x_i\\\\\n\\sum_{i=1}^n x_i & \\sum_{i=1}^n x_i^2\\\\\n\\end{pmatrix}\n\\end{equation}\n\n\\begin{equation}\n(X^T X)^{-1} = \\frac{1}{nS_{xx}} \n\\begin{pmatrix}\n S_{xx}+n\\bar{x}^2 & -n\\bar{x} \\\\\n -n\\bar{x} & n\\\\\n\\end{pmatrix}\n\\end{equation}\n\n\\noindent\nNote that $\\sum_{i=1}^n x_i = n\\bar{x}$.\n\n\\begin{equation}\nX^T  y = \\begin{pmatrix}\nn\\bar{y} \\\\\nS_{xy} + n\\bar{x}\\bar{y}\n\\end{pmatrix}\n\\end{equation}\n\n\nSee \\cite[25]{DraperSmith} for a full exposition.\n\n\\subsection{Gauss-Markov conditions}\n\nThis imposes distributional assumptions on $\\epsilon = y - X \\beta$.\n\n$E(\\epsilon)=0$ and $Var(\\epsilon)=\\sigma^2 I_n$,\n\n\\subsection{Gauss-Markov theorem}\n\nLet $a$ be any $p \\times 1$ vector and suppose that $X$ has rank $p$. Of all estimators of $\\theta = a^T \\beta$ that are unbiased and linear functions of $y$, the estimator $\\hat{\\theta} = a^T \\hat{\\beta}$ has minimum variance. Note that $\\theta$ is a scalar.\n\nNote: no normality assumption required! But if $\\epsilon \\sim N(0,\\sigma^2)$, $\\hat{\\beta}$ have smaller variances than any other estimators.\n\n\\textbf{Minimum variance unbiased linear estimators}:\nto-do\n\n\\subsection{$R^2$ or Coefficient of determination}\n\n\\begin{tabular}{@{}ll@{}}\n$S_{TOTAL} = (y-\\bar{y})^T(y-\\bar{y})$  $= y^T y - n\\bar{y}^2$ & \\\\\n$S_{REG} = (X\\hat{\\beta}-\\bar{y})^T (X\\hat{\\beta}-\\bar{y})$ & \\\\\n$S_r = \\sum e_i^2 = (y-X\\hat{\\beta})^T (y-X\\hat{\\beta})$ & \\\\\n\\end{tabular}\n\n\\begin{equation}\nS_{TOTAL} = S_{REG}+ S_r\n\\end{equation}\n\n\\begin{equation}\nR^2 = \\frac{S_{TOTAL}-S_r}{S_{TOTAL}} = \\frac{S_{REG}}{S_{TOTAL}}\n\\end{equation}\n\nFor $y = 1_n \\beta_0 + \\epsilon$, then $R^2 = \\frac{S_{REG}}{S_{TOTAL}} = 0$ because $X\\hat{\\beta} = \\bar{y}$. So $S_{REG} = (X\\hat{\\beta} - \\bar{y})^T (X\\hat{\\beta} - \\bar{y}) = 0$.\n\nIn simple linear regression, $R^2 = r^2$.  $R^2$ is a generalization of $r^2$.\n\nAdjusted $R^2= R_{Adj}^2$.  $R_{Adj}^2= 1-\\frac{S_r/(n-p)}{S_{TOTAL}/(n-1)}$. \n\n$R^2$ increases with increasing numbers of explanatory variables, therefore $R_{Adj}^2$ is better. \n\n\n\\section{Hypothesis testing}\n\n\\subsection{Some theoretical background}\n\n\\textbf{Multivariate normal}:\n\nLet $X^T = < X_1,\\dots,X_p>$, where $X_i$ are univariate random variables.\n\nX has a multivariate normal distribution if and only if every component of $X$ has a univariate normal distribution.\n\n\n\\textbf{Linear transformations}:\n\nLet $A, b$ be constants. Then, $Ax + b\\sim N_q (A\\mu + b, A\\Sigma A^T)$.\n\n\\textbf{Standardization}:\n\nNote that $\\Sigma$ is positive definite (it's a variance covariance matrix), so $\\Sigma = CC^T$. \n$C$ is like a square root (not necessarily unique).\n \nIt follows ``immediately'' that \n\n\\begin{equation}\nC^{-1} (X-\\mu) \\sim N_p (0_p, I_p)\n\\end{equation}\n\nIf $\\Sigma$ is a diagonal matrix, then $X_1,\\dots,X_n$ are independent and uncorrelated.\n\n\\textbf{Quadratic forms}:\n\nRecall distributional result: If we have $n$ independent standard normal random variables, their sum of squares is $\\chi_n^2$.\n\nLt $z = C^{-1} (X-\\mu)$, and $\\Sigma=CC^T$. The sum of squares $z^T z$ is:\n\n\\begin{equation}\n\\begin{split}\nz^T z & = [C^{-1} (X-\\mu)]^T [C^{-1} (X-\\mu)]\\\\\n& = (X-\\mu)^T [C^{-1}]^T [C^{-1}](X-\\mu) \\quad \\dots (AB)^T=B^T A^T\\\\\n\\end{split}\n\\end{equation} \n\nNote that $ [C^{-1}]^T =  [C^{T}]^{-1}$. Therefore, \n\n\\begin{equation}\n\\begin{split}\n[C^{-1}]^T [C^{-1}] & = [C^T]^{-1} [C^{-1}]\\\\\n& = (C^T C)^{-1}\\\\\n& = (C C^T)^{-1}\\\\\n& = \\Sigma^{-1}\\\\\n\\end{split}\n\\end{equation} \n\nTherefore: $z^T z = (X-\\mu)^T  \\Sigma^{-1} (X-\\mu)\\sim \\chi_p^2$, where $p$ is the number of parameters.\n\n\\textbf{Quadratic expressions involving idempotent matrices}\n\nGiven a matrix $K$ that is idempotent, symmetric. Then:\n\n\\begin{equation}\nx^T K x = x^T K^2 x = x^T K^T K x\n\\end{equation}\n\nLet $x\\sim N_n(\\mu,\\sigma^2 I_n)$, and let $K$ be a symmetric, idempotent $n \\times n$ matrix such that $K\\mu=0$. Let $r$ be the rank or trace of $K$. Then we have the \n\n\\begin{fmpage}{\\linewidth}\n\\textbf{sum of squares property}:\n\n\\begin{equation}\nx^T K x \\sim \\sigma^2 \\chi_r^2\n\\end{equation}\n\\end{fmpage}\n\nThe above generalizes the fact that if we have $n$ independent standard normal random variables, their sum of squares is $\\chi_n^2$.\n\nTwo points about the sum of squares property:\n\\begin{itemize}\n\\item\nRecall that the expectation of a chi-squared random variable is its degrees of freedom. It follows that:\n\n\\begin{equation}\nE(x^T K x) =  \\sigma^2 r \n\\end{equation}\n\nIf $K\\mu\\neq 0$, $E(x^T K x) =  \\sigma^2 r+\\mu^T K\\mu$. \n\n\\item If $K$ is idempotent, so is $I-K$. This allows us to split $x^T x$ into two components sums of squares:\n\n\\begin{equation}\nx^T x = x^T K x+x^T (I-K) x\n\\end{equation}\n\\end{itemize}\n\n\\textbf{Partition sum of squares}:\n\n[helps prove independence of SSs] \n\n\\begin{enumerate}\n\\item Let $K_1, K_2,\\dots, K_q$ be \\textbf{symmetric idempotent $n \\times n$ matrices} such that\n\\item $\\sum K_i= I_n$ and \n\\item $K_iK_j =0$, for all $i\\neq j $. \n\\item Let $x\\sim N_n(\\mu, \\sigma^2I_n)$.\n \\end{enumerate}\n \n Then we have the following partitioning into \\textbf{independent} sums of squares:\n \n  \\begin{equation}\nx^T x = \\sum x^T K_i x\n\\end{equation}\n\nIf $K_i \\mu = 0$, then $ x^T K_i x\\sim \\sigma^2 \\chi_{r_i}^2$, where $r_i$ is the rank of $K_i$.\n\n\\textbf{Example}:\n\n\\begin{equation}\ny^T y  = y^T M y + y^T (I-M) y \n\\end{equation}\n\nLet $K_1 = M$ and $K_2 = (I-M)$. It is easy to check that all four conditions above are satisfied; therefore the sums of squares are independent.\n\nNote that \n\n\\begin{equation}\n y^T M y  = e^T e \\sim \\chi^2_{n-p}\n\\end{equation}\n\nand\n\n\\begin{equation}\n y^T (I-M y)  = \\hat{\\beta}^T (X^T X) \\hat{\\beta} \\sim \\chi^2_{p}\n\\end{equation}\n\nRecall distributional result: if $X\\sim \\chi_v^2, Y\\sim \\chi_w^2$ and $X,Y$ independent then $\\frac{X/v}{Y/w}\\sim F_{v,w}$.  \n\nTherefore, $ \\frac{\\frac{y^T (I-M y)}{n-p}}{\\frac{y^T M y}{p}}\\sim F_{p,n-p}$.\n\n\\subsection{Confidence intervals for $\\hat{\\beta}$}\n\nNote that $\\hat{\\beta} \\sim N_p (\\beta,\\sigma^2 (X^T X)^{-1})$, and that \n$\\frac{\\hat{\\sigma}^2}{\\sigma^2} \\sim  \\frac{\\chi^2_{n-p}}{n-p}$.\n\nFrom distributional theory we know that $T=\\frac{X}{\\sqrt{Y/v}}$, when $X\\sim N(0,1)$ and $Y\\sim \\chi^2_{v}$. \n\nLet \n $x_i$ be a column vector containing the values of the explanatory/regressor variables for a new observation $i$. Then if we define:\n\n\\begin{equation}\nX=\\frac{x_i^T \\hat{\\beta} - x_i^T \\beta}{\\sqrt{\\sigma^2 x_i^T (X^T X)^{-1}x_i}} \\sim N(0,1)\n\\end{equation}\n\n\\noindent\nand \n\n\\begin{equation}\nY=\\frac{\\hat{\\sigma}^2}{\\sigma^2} \\sim  \\frac{\\chi^2_{n-p}}{n-p}\n\\end{equation}\n\n\nIt follows that  $T=\\frac{X}{\\sqrt{Y/v}}$:\n\n\\begin{equation}\nT=  \\frac{x_i^T \\hat{\\beta} - x_i^T \\beta}{\\sqrt{\\hat{\\sigma}^2 x_i^T (X^T X)^{-1}x_i}} = \n\\frac{  \\frac{x_i^T \\hat{\\beta} - x_i^T \\beta}{\\sqrt{\\sigma^2 x_i^T (X^T X)^{-1}x_i}}}{\\sqrt{\\frac{\\hat{\\sigma}^2}{\\sigma^2}}}\n \\sim t_{n-p}\n\\end{equation}\n\nI.e., a 95\\% CI:\n\n\\begin{equation}\nx_i^T \\hat{\\beta} \\pm t_{n-p,1-\\alpha/2}\\sqrt{\\hat{\\sigma}^2 x_i^T(X^T X)^{-1}x_i}\n\\end{equation}\n\nCf.\\ a prediction interval:\n\n\\begin{equation}\nx_i^T \\hat{\\beta} \\pm t_{n-p,1-\\alpha/2}\\sqrt{\\hat{\\sigma}^2 (1+x_i^T(X^T X)^{-1}x_i)}\n\\end{equation}\n\nNote that \n\n\\begin{enumerate}\n\\item\nA prediction interval will be wider about the edges; this is because the term $\\hat{\\sigma}^2 (1+x_i^T(X^T X)^{-1}x_i)$ in the prediction interval formula is minimized at the mean value of the \npredictor variable. When $x_i = \\bar{x}$ we have the smallest value for the term, and so the further away the $x_i$ value from $\\bar{x}$, the larger the interval. \n\\item \nThe width of the prediction interval stays much more constant around the range of observed values.\nThis is because 1 is much larger than $x_i^T(X^T X)^{-1}x_i)$; so if $x_i$ is near the mean value for $x$ then this term will not change much. \n\n\\end{enumerate}\n\n\\subsection{Distributions of estimators and residuals}\n\nCovar$(\\hat{\\beta},e)=0$: \n\n         Var$\\begin{pmatrix}\n\t \\hat{\\beta} \\\\\n\te \\\\\n\t\\end{pmatrix}\n\t= \n\t\\begin{pmatrix}\n\t Var(\\hat{\\beta}) & 0 \\\\\n\t 0 & Var(e) \\\\\n\t\\end{pmatrix}\n\t= \n\t\\begin{pmatrix}\n\t \\sigma^2 (X^T X)^{-1} & 0 \\\\\n\t 0 & \\sigma^2 M \\\\\n\t\\end{pmatrix}\n\t$.\n\t\n\\textbf{Confidence intervals for components of $\\beta$}\t\n\n\nLet $G=(X^T X)^{-1}$, and $g_{ii}$ the $i$-th diagonal element. \n\n\\begin{equation}\n\\hat{\\beta}_i \\sim N(\\beta_i, \\sigma^2 g_{ii})\n\\end{equation}\n\nSince $\\hat{\\beta}$ and $S_r$ are independent, we have:\n\n\\begin{equation}\n\\frac{\\hat{\\beta}_i - \\beta_i}{\\hat{\\sigma}\\sqrt{g_{ii}}} \\sim t_{n-p}\n\\end{equation}\n\nThe 95\\% CI:\n\n\n\\begin{equation}\n\\hat{\\beta}_i \\pm t_{n-p,(1-\\alpha)/2} \\hat{\\sigma} \\sqrt{g_{ii}} \n\\end{equation}\n\n\\subsection{Maximum likelihood estimators}\n\nFor $\\sigma^2$:\n\n\nLet $X_i$, $i=1,\\dots,n$ be a random variable with PDF $f(x; \\sigma) = \\frac{1}{2\\sigma} exp (-\\frac{\\mid x \\mid}{\\sigma})$. Find $\\hat \\sigma$, the MLE of $\\sigma$.\n\n\n\\begin{equation}\n\tL(\\sigma) = \\prod f(x_i; \\sigma) = \\frac{1}{(2\\sigma)^n} exp (-\\sum \\frac{(x_i - \\mu)^2}{\\sigma^2})\n\\end{equation}\n\nLet $\\ell$ be log likelihood. Then:\n\n\\begin{equation}\n\t\\ell (x; \\sigma) = - n\\log 2 - n\\log \\sigma - \\sum (x_i - \\mu)^2 /\\sigma^2\n\\end{equation}\n\nDifferentiating and equating to zero to find maximum:\n\n\\begin{equation}\n\t\\ell ' (\\sigma) =  - \\frac{n}{\\sigma} +  \\sum (x_i - \\mu)^2 /\\sigma^3 =\n\t 0\n\\end{equation}\n\nRearranging the above, the MLE for $\\sigma$ is:\n\n\\begin{equation}\n\t\\hat \\sigma^2 =  \\sum (x_i - \\mu)^2 /n\n\\end{equation}\n\nSince $S_r\\sim \\chi^2_{n-p}$, $E(S_r)=\\sigma^2 (n-p)$. So we need to correct $S_r$ as $S_r/n-p$ to get $E(S_r)=\\sigma^2$. \n\n\\subsection{Hypothesis testing}\n\nA general format for specifying null hypotheses: $H_0: C\\beta = c$, where $C$ is a $q\\times p$ matrix and $c$ is a $q\\times 1$ vector of known constants. The matrix $C$ effectively asserts specific values for $q$ linear functions of $\\beta$. In other words, it asserts $q$ null hypotheses stated in terms of (components of) the parameter vector $\\beta$.\n\n E.g., given:\n\n\\begin{equation}\ny_i = \\beta_0 + \\beta_1 x_i + \\beta_2 x_i^2+\\epsilon_i\n\\end{equation}\n\n\\noindent\nwe can test $H_0: \\beta_1=1, \\beta_2=2$ by setting \n\n$C=\\begin{pmatrix} \n0 & 1 & 0\\\\\n0 & 0 & 1\\\\\n\\end{pmatrix}$\nand $c=\\begin{pmatrix} \n1\\\\\n2\\\\\n\\end{pmatrix}$.\n\nThe alternative is usually the negation of the null, i.e., $H_1: C\\beta\\neq c$, which means that at least one of the $q$ linear functions does not take its hypothesized value. \n\n\\textbf{Constructing a test}:\n\n\\begin{equation}\nC\\hat{\\beta} \\sim N_q (c,\\sigma^2 C (X^T X)^{-1} C^T)\n\\end{equation}\n\nSo, if $H_0$ is true, by sum of squares property:\n\n\\begin{equation}\n(C\\hat{\\beta} - c)^T [C (X^T X)^{-1} C^T]^{-1} (C\\hat{\\beta} - c) \\sim \\sigma^2 \\chi_q^2\n\\end{equation}\n\nIn other words:\n\n\\begin{equation}\n\\frac{(C\\hat{\\beta} - c)^T [C (X^T X)^{-1} C^T]^{-1} (C\\hat{\\beta} - c)}{ \\sigma^2} \\sim \\chi_q^2\n\\end{equation}\n\nNote that $\\hat{\\beta}$ is independent of $\\hat{\\sigma}^2$, and recall that\n\n\\begin{equation}\n\\frac{\\hat{\\sigma}^2 }{\\sigma^2} \\sim \\frac{\\chi_{n-p}^2}{n-p}  \\Leftrightarrow \n\\frac{\\hat{\\sigma}^2 (n-p)}{\\sigma^2} \\sim \\chi_{n-p}^2\n\\end{equation} \n\nRecall distributional result: if $X\\sim \\chi_v^2, Y\\sim \\chi_w^2$ and $X,Y$ independent then $\\frac{X/v}{Y/w}\\sim F_{v,w}$.  \n\n\nIt follows that if $H_0$ is true,  and setting\n$X=\\frac{(C\\hat{\\beta} - c)^T [C (X^T X)^{-1} C^T]^{-1} (C\\hat{\\beta} - c)}{ \\sigma^2}$,\n$Y=\\frac{\\hat{\\sigma}^2 (n-p)}{\\sigma^2}$, and setting the degrees of freedom to $v=q$ and $w=n-p$:\n\n\\begin{equation}\n\\frac{X/v}{Y/w}=\n\\frac{\\frac{(C\\hat{\\beta} - c)^T [C (X^T X)^{-1} C^T]^{-1} (C\\hat{\\beta} - c)}{ \\sigma^2}/q}{\\frac{\\hat{\\sigma}^2 (n-p)}{\\sigma^2}/(n-p)}\n\\end{equation}\n\nSimplifying:\n\n\\begin{equation}\n\\frac{(C\\hat{\\beta} - c)^T [C (X^T X)^{-1} C^T]^{-1} (C\\hat{\\beta} - c)}{q\\hat{\\sigma}^2} \\sim F_{q,n-p}\n\\end{equation}\n\n%The above test is the \\textbf{generalized likelihood ratio test}.\n\nThis is a \\textbf{one-sided test} even though the original alternative was two-sided.\n\n\\textbf{Special cases of hypothesis tests}:\n\nWhen $q$ is 1, we have only one hypothesis to test, the $i$-th element of $\\beta$. Given:\n\n\\begin{equation}\ny_i = \\beta_0 + \\beta_1 x_i + \\beta_2 x_i^2+\\epsilon_i\n\\end{equation}\n\n\\noindent\nwe can test $H_0: \\beta_1=0$ by setting \n\n$C=\\begin{pmatrix} \n0 & 1 & 0\\\\\n\\end{pmatrix}$\nand $c=0$.\n\n\nUsing the fact that $X\\sim t(v)\\Leftrightarrow X^2 \\sim F(1,v)$, we have\n\n\n\\begin{equation}\n\\frac{\\hat{\\beta}_i - c_i}{\\hat{\\sigma}\\sqrt{g_{ii}}} \\sim t_{n-p}\n\\end{equation}\n \n\\subsection{Sum of squares}\n\nThis is a very important section!\n\n\\begin{fmpage}{\\linewidth}\n\nRecall:\nIf $K$ is idempotent, so is $I-K$. This allows us to split $x^T x$ into two components sums of squares:\n\n\\begin{equation}\nx^T x = x^T K x+x^T (I-K) x\n\\end{equation}\n\n Let $K_1, K_2,\\dots, K_q$ be symmetric idempotent $n \\times n$ matrices such that\n $\\sum K_i= I_n$ and $K_iK_j =0$, for all $i\\neq j $. Let $x\\sim N_n(\\mu, \\sigma^2)$.\n Then we have the following partitioning into independent sums of squares:\n \n  \\begin{equation}\nx^T x = \\sum x^T K_i x\n\\end{equation}\n\nIf $K_i \\mu = 0$, then $ x^T K_i x\\sim \\sigma^2 \\chi_{r_i}^2$, where $r_i$ is the rank of $K_i$.\n\\end{fmpage}\n\nWe can use the sum of squares property just in case $K$ is idempotent, and $K\\mu =0$ . Below, $K=M$ and $\\mu=E(y)=X\\beta$.\n\nConsider the sum of squares partition:\n\n\\begin{equation}\ny^T y = \\explain{\\underline{y^T M y}}{S_r= e^T e} + \\explain{\\underline{y^T (I-M) y}}{\\hat{\\beta}^T (X^T X)\\hat{\\beta}}\n\\end{equation}\n\nNote that the preconditions for sums of squares partitioning are satisfied:\n\\begin{enumerate}\n\\item $M$ is idempotent  (and symmetric), rank=trace=$n-p$.\n\\item $I-M$ is idempotent (and symmetric), rank=trace=$p$.\n\\item $ME(y) = 0$ because $ME(y)=MX\\beta$ and $MX=0$.\n\\end{enumerate}\n\nWe can therefore partition the sum of squares into two independent sums of squares:\n\n\\begin{equation}\ny^T y = \\explain{\\underline{y^T M y}}{e^T e \\sim \\sigma^2 \\chi_{n-p}^2} \\hbox{~~~~~~~~}+\\hbox{~~~~~~~~} \n\\explain{\\underline{y^T (I-M) y}}{ \\sim \\sigma^2 \\chi_p^2 \\newline \\hbox{ iff } X\\beta=0, i.e., \\beta=0}\n\\end{equation}\n\nSo, iff we have $H_0: \\beta=0$, we can partition sum of squares as above. Saying that $\\beta=0$ is equivalent to saying that $X$ has rank $p$ and $X\\beta=0$.\n\n\\subsection{Testing the effect of a subset of regressor variables}\n\nLet:\n\n\\begin{equation}\nC= (0_{p-q} I_q) \\quad c=0, \\hbox{ and } \\beta=\\begin{pmatrix} \\beta_1\\\\ \\beta_2 \\end{pmatrix}\n\\end{equation}\n\n\nHere, $\\beta_{1,2}$ are vectors (sub-vectors?), not components of the $\\beta$ vector.\nThen, $C\\times \\beta = \\beta_2$ and $H_0: \\beta_2=0$. Note that order of elements in $\\beta$ is arbitrary; i.e., any subset of $\\beta$ can be tested.\n\nSince  $C\\times \\beta = \\beta_2$ and $c=0$, we can construct a sum of squares:\n\n\\begin{equation}\n(C\\hat{\\beta} - c)^T [C (X^T X)^{-1} C^T]^{-1} (C\\hat{\\beta} - c) \\sim \\sigma^2 \\chi_q^2\n\\end{equation}\n\nThis becomes (since $C\\beta=\\hat{\\beta}_2$):\n\n\\begin{equation}\n\\hat{\\beta}_2^T [C (X^T X)^{-1} C^T]^{-1} \\hat{\\beta}_2 \\sim \\sigma^2 \\chi_q^2\n\\end{equation}\n\nWe can rewrite this as: $\\hat{\\beta}_2^T G_{qq}^{-1} \\hat{\\beta}_2$, where $G_{qq}= C (X^T X)^{-1} C^T$ ($G_{qq}$ should not be confused with $g_{ii}$) is a $q\\times q$ submatrix of $G=(X^T X)^{-1}$. \n\nNote that $\\hat{\\beta}$ is independent of $\\hat{\\sigma}^2$, and \nrecall that  $\\frac{\\hat{\\sigma}^2 (n-p)}{\\sigma^2} \\sim \\chi_{n-p}^2$. We can now construct the F-test as before:\n\n\\begin{equation}\n\\frac{\\hat{\\beta}_2^T C (X^T X)^{-1} C^T \\hat{\\beta}_2}{q\\hat{\\sigma}^2} = \n\\frac{\\hat{\\beta}_2^T G \\hat{\\beta}_2}{q\\hat{\\sigma}^2}\n \\sim F_{q,n-p}\n\\end{equation}\n\n\n\\textbf{Sums of squares}:\n\nWe can construct three idempotent matrices:\n\n\\begin{itemize}\n\\item\n$M = I_n - X(X^T X)^{-1} X^T$\n\\item\n$M_1 =  X(X^T X)^{-1} X^T -   [X(X^T X)^{-1} C^T]  [\\explain{\\underline{C (X^T X)^{-1} C^T}}{G}]^{-1}  \n[C(X^T X)^{-1} X^T]$\n\n(that is: $M_1 =  X(X^T X)^{-1} X^T - M_2$)\n\n\\item $M_2 = [X(X^T X)^{-1} C^T]  [\\explain{\\underline{C (X^T X)^{-1} C^T}}{G}]^{-1}  \n[C(X^T X)^{-1} X^T]$\n\\end{itemize}\n\nNote that $M+M_1+M_2=I_n$ and $MM_1=MM_2=M_1M_2=0$. I.e., sum of squares partition property applies. We have three independent sums of squares:\n\n\\begin{enumerate}\n\\item $S_r = y^T M y$\n\\item $S_1 = y^T M_1 y = \\hat{\\beta}^T X^T X \\hat{\\beta}-  \\hat{\\beta}_2^T G_{qq}^{-1} \\hat{\\beta}_2$\n\\item $S_2 = y^T M_2 y =  \\hat{\\beta}_2^T G_{qq}^{-1} \\hat{\\beta}_2$\n\\end{enumerate}\n\nSo: $y^T y = S_r + S_1 + S_2$.  Then:\n\n\\begin{itemize}\n\\item It is unconditionally true that $S_r \\sim \\sigma^2 \\chi^2_{n-p}$.\n\\item If $H_0: \\beta=0$ is true, then $E(\\hat{\\beta}_2) = \\beta_2 = 0$. It follows from the sum of squares property that $S_2 \\sim \\sigma^2 \\chi_q^2$.  \n\\item Regarding $S_1$: \nWe can prove that $M_1 = X_1 (X_1^T X_1)^{-1}X_1^T$, where $X_1$ contains the first $p-q$ columns of $X$. It follows that:\n\n$S_1 = y^T M_1 y =y^T X_1 (X_1^T X_1)^{-1}X_1^T  y$\n\nNote that $X_1 (X_1^T X_1)^{-1}X_1^T$ is idempotent. If $\\beta=0$, i.e., if $E(y) =X\\beta = 0$, we can use the  sum of squares property and conclude that\n\n$S_1 \\sim \\sigma^2 \\chi_{p-q}^2$\n\nThe degrees of freedom are $p-q$ because the rank=trace of  $X_1 (X_1^T X_1)^{-1}X_1^T$ is $n-p$.\n\n\\textbf{Thus, $S_1$ is testing $\\beta_1=0$ but under the assumption that $\\beta_2=0$}.\n\n\\end{itemize}\n\n\\textbf{Analysis of variance}\n\n%\\begin{table}[htdp]\n%\\caption{default}\n%\\begin{center}\n\\begin{tabular}{|l|c|c|c|c|}\n\\hline\nSources & SS & df & MS & MS ratio\\\\\n of variation & & & & \\\\\n\\hline\nDue to $X_1$  & $S_1$ & $p-q$ & $S_1/(p-q)$ & $F_1$ \\\\\nif $\\beta_2=0$   d& & & & $F_{p-q,n-p}$\\\\\n\\hline\nDue to $X_2$ & $S_2$ & $q$ & $S_2/q$ & $F_2$\\\\\n& & & &  $F_{q,n-p}$\\\\\n\\hline\nResiduals   & $S_r$ & $n-p$ & $\\hat{\\sigma}^2$ & \\\\\n\\hline\nTotal           & $y^T y$  & n &  &\\\\\n\\hline\n\\end{tabular}\n%\\end{center}\n%\\label{default}\n%\\end{table}%\n\nNote:\n\n\\begin{enumerate}\n\\item \nThe ANOVA tests are \\textbf{performed in order}:  First we test $H_0: \\beta_2=0$. Then, if this test does not reject the null, we test $H_0: \\beta_1 = 0$ \\textbf{on the assumption (which may or may not be true)} that $\\beta_2=0$. \n\\item What happens if we reject the first hypothesis?\n\\end{enumerate}\n\n\\textbf{The null or minimal model (constant term)}\n\nWe can set $C=I_p$ and $c=0$. This tests whether all coefficients are zero. But this states that $E(y)=0$, whereas it should have a non-zero value (e.g., reading times).  We include the constant term to accommodate this desire to have $E(y)=\\mu=\\neq 0$. In matrix format: let $\\beta$ be the parameter vector; then, $\\beta_1=\\mu$ is the first, constant, term, and the rest of the parameters are the vector $\\beta_2$ ($p-1\\times 1$).\nThe first column of $X$ will be $X_1=1_n$.\n\n\\begin{enumerate}\n\\item\n$S_1=y^T (X_1^T X_1)^{-1} X_1^T y = (\\sum y)^2/n = n\\bar{y}^2$\n\\item\n$S_r = y^Ty - \\hat{\\beta}^T X^T X\\hat{\\beta}$\n\\item\n$S_2 = y^T y -S_1 - S_r = \\hat{\\beta}^T X^T X\\hat{\\beta}-n\\bar{y}^2$\n\\end{enumerate}\n\nIt is normal to omit the row in the ANOVA table corresponding to the constant term.\n\n\\medskip\n\\textbf{Testing whether all predictors (besides the constant term) are zero}\n\nTo test whether $p$ predictor variables have any effect on $y$,we set $q=p-1$, and our anova table looks like this:\n\n\\begin{tabular}{|l|l|l|l|l|}\n\\hline\nSources & SS & df & MS & MS \\\\\nof variation  & & & & ratio \\\\\n\\hline\n%Due to $X_1$ if $\\beta_2=0$ & $S_1$ & $p-q$ & $S_1/(p-q)$ & ($F_1$) $  F_{p-q,n-p}$\\\\\n%\\hline\nDue & $S_2$ & $p-1$ & $\\frac{S_2}{(p-1)}$ & $F_2$\\\\\n to regressors & & & &  $F_{p-1,n-p}$\\\\\n\\hline\nResiduals   & $S_r$ & $n-p$ & $\\hat{\\sigma}^2$ & \\\\\n\\hline\nTotal        & $S_{yy}=$  & n-1 &  &\\\\\n (\\textbf{adjusted})    & $(y-\\bar{y})^T(y-\\bar{y})$ & & & \\\\\n& $=y^T y - n\\bar{y}^2$ & & & \\\\\n\\hline\n\\end{tabular}\n\nNote that $S_{yy}=\\sum (y_i - \\bar{y})^2$ is the residual sum of squares that we get after fitting the constant $\\hat{\\mu}=\\bar{y}$.\n\n\\medskip\n\\textbf{Testing a subset of predictors $\\beta_2$}\n\n\\begin{tabular}{|l|l|l|l|l|}\n\\hline\nSources & SS & df & MS & MS \\\\\nof variation  & & & & ratio \\\\\n\\hline\nDue to $X_1$   & $S_1$ & $p-q-1$ & $\\frac{S_1}{(p-q-1)}$ & ($F_1$) \\\\\nif $\\beta_2=0$ & & & & $F_{p-q-1,n-p}$\\\\\n(test of $\\beta_1$) & & & & \\\\\n\\hline\nDue & $S_2$ & $q$ & $\\frac{S_2}{q}$ & $F_2$\\\\\n to $X_2$ & & & &  $F_{q,n-p}$\\\\\n(test of $\\beta_2$) & & & & \\\\\n\\hline\nResiduals   & $S_r$ & $n-p$ & $\\hat{\\sigma}^2$ & \\\\\n\\hline\nTotal        & $S_{yy}$  & n-1 &  &\\\\\n\\hline\n\\end{tabular}\n%Note: the lecture notes have total SS as $y^T y$ but I think that's a typo.\n\n%Used at the very beginning of a document:\n%\\verb!\\documentclass{!\\textit{class}\\verb!}!.  Use\n%\\verb!\\begin{document}! to start contents and \\verb!\\end{document}! to\n%end the document.\n\n\n\\section{Checking model assumptions}\n\n\\subsection{Standardized residuals (\\texttt{stdres} in R)}\n\nRecall that $Var(e)=\\sigma^2 M$, where $M = I_n -  X (X^T X)^{-1} X^T \\quad \\hbox{M is symmetric, idempotent } n\\times n$. The diagonals of $M$ are all less than 1, and are not all equal (i.e., not equal variance), and off-diagonals are not 0 (i.e., the residuals are correlated). Correcting for unequal variance is done by the \\textbf{scaled residual}:\n\n\\begin{equation}\ne_i* = \\frac{e_i}{\\sqrt{m_{ii}}}\n\\end{equation}\n\nNote: $Var(e_i*) = \\sigma^2$ because $e_i \\sim N(0,\\sigma^2 m_{ii})$, therefore $e_i=\\frac{e_i}{\\sqrt{m_{ii}}}*\\sim N(0,\\sigma^2)$. \n\n\nThe \\textbf{standardized residuals} are \n\n\\begin{equation}\ns_i = \\frac{e_i*}{\\hat{\\sigma}}\n\\end{equation}\n\nThis is approximately $t_{n-p}$ (approximately because $e_i*$ and  $\\hat{\\sigma}$ are not independent).\nSince $s_i\\sim t_{n-p}$, we can designate a residual as an outlier if $\\mid s_i \\mid > t_{crit}$ where $t_{crit}$ is the critical t-value.\n\n\\subsection{Standardized deletion residuals (\\texttt{studres} in R)}\n\nThis is a more exact way to test for outliers than the above discussion. Define:\n\n\\begin{equation}\n\\hat{\\beta}_{-i} = (X_{-i}^T X_{-i})^{-1} X_{-i}^T y_{-i}\n\\end{equation}\n\n\\noindent\nwhere the $-i$ refers to removing data point $i$.\nStandardized deletion residuals are\n\n\\begin{equation}\ns_{-i} = \\frac{e_i}{\\hat{\\sigma}_{-i}\\sqrt{m_{ii}}}\n\\end{equation}\n\nWe can compute $s_{-i}$ from $s_{i}$:\n\n\\begin{equation}\ns_{-i} = \\frac{s_i \\sqrt{n-p-1}}{\\sqrt{n-p-s_{i}^2}} \\sim t_{n-p-1}\n\\end{equation}\n\nIf $n$ is large, $s_{-i}\\approx s_i$. \n\n\\subsection{Correcting for multiple testing}\n\n\\v{S}id\\'ak correction: \n``suppose we are performing $n$ tests and in each test we specify the probability of making a type I error to be $\\beta$ (note: don't confuse this as type II error). Then, if the tests are independent, the probability of at least one false positive claim in the $n$ tests is given by \n\n\\begin{equation}\n1-(1-\\beta)^n = \\alpha \\Leftrightarrow \\beta = 1-(1-\\alpha)^{1/n}\n\\end{equation}\n\nThis correction ``has a stronger bound [than the Bonferroni] and so has greater statistical power.''\n\n\\subsection{Checks}\n\n\\begin{enumerate}\n\\item Normality: qqnorm etc. Hist is a useful addition to qqplot in large samples. For small samples, use scaled or standardized residuals if sample size is small (not sure why).\n\\item Independence: index-plots: residuals against observation number. Not useful for small samples. Or: compute correlation between $e_i, e_{i+1}$ pairs of residuals.\n\\item Homoscedasticity: residuals against fitted. Fan out suggests violation. A quadratic trend in a plot of residuals against predictor x could suggest that a quadratic predictor term is needed; note that $X^T e = 0$. (review exercises 3), so we will never have a perfect straight line in such a plot. Alternative: Bartlett's test.\n\\end{enumerate}\n\n\\subsection{Formal tests of normality}\n\nKomogorov-Smirnov and Shapiro-Wilk. Only useful for large samples ; not very powerful and not much better than diagnostic plots. Tests may be useful as follow-ups if non-normality is suspected.\n\n\\subsection{Influence and leverage (\\texttt{lm.influence\\$hat} in R)}\n\nA point can influence the parameter estimates without being an exceptional outlier. Influence does not depend on ``outlyingness''. Potential to influence (e.g., by being an extreme x value) is called leverage; once the y value is also extreme, we have influence. I.e., it takes an extreme x and y value to be influential, and it takes only an extreme x value to have leverage.\n\nLeverage more formally defined: recall that $M = I_n -  X (X^T X)^{-1} X^T$. Define a hat matrix $H=I-M=X (X^T X)^{-1} X^T$. It's called a hat matrix because it puts a hat on y: $\\hat{y} = X \\hat{\\beta} = Hy$.\nSince $x_i^T$  is the $i$-th row of $X$, we have $h_{ii} = x_i^T (X^T X)^{-1}x_i$. The measure for leverage is:\n\n\\begin{equation}\nh_{ii} = 1 - m_{ii}\n\\end{equation}\n\nNotice that $h_{ii}$ is a scalar, so $\\hbox{trace}(h_{ii}=h_{ii}$.\nSo (because for a square matrix A,B, tr(AB)= tr(BA)):\n\n\\begin{equation}\nh_{ii} = tr(x_i^T (X^T X)^{-1}x_i)=tr(x_i^T x_i (X^T X)^{-1})\n\\end{equation}\n\nSince $X^T X = \\sum_{i=1}^n x_i x_i^T$, $h_{ii}$ represents the magnitude of $ x_i x_i^T$ relative to the sum of the values for all observations. Note that $h_{ii}$ only depends on X. \n\nAlso note that\n\n\\begin{equation}\n\\sum_{i=1}^n h_{ii} = tr(X^T X (X^T X)^{-1}) = tr(I_p)=p \\quad mean(h_{ii})=p/n\n\\end{equation}\n\n$h_{ii}$ measures leverage because $Var(e_i)=\\sigma^2 m_{ii} = \\sigma^2(1-h_{ii})$ and $Var(\\hat{y}_i) = \\sigma^2 h_{ii}$. Therefore $h_{ii}$ has to lie between 0 and 1. When it is close to one, the fitted value will be close to the actual value of $y_i$---signalling potential for leverage (aside by SV: the explanation sounds circular to me---this statement says it has leverage by definition. Also, I don't know why I should care that a data point has \\textit{potential} to influence the estimates).  \n\nA cutoff one can use to identify high leverage points is $h_{ii} > 2p/n$ or $h_{ii} > 3p/n$.\n\nThe leverage of a data point is directly related to how far away it is from the mean:\n\n\\begin{equation}\nh_{ii} = n^{-1} + \\frac{(x_i - \\bar{x})^2}{S_{xx}}\n\\end{equation}\n\nIn \\texttt{lm.influence}, ``coefficients is the matrix whose i-th row contains the change in the estimated coefficients which results when the i-th case is dropped from the regression. sigma is a vector whose i-th element contains the estimate of the residual standard error obtained when the i-th case is dropped from the regression'' (p.\\ 71 of lecture notes).\n\n\\subsection{Cook's distance D: A measure of influence}\n\nLet $s_i$ be the i-th standardized residual, $\\hat{\\beta}_{-i}$ the estimate of the vector of parameters with the i-th row removed.\n\n\\begin{equation}\nD_i =  \\frac{(\\hat{\\beta}-\\hat{\\beta}_{-i})^T(X^T X)^{-1}(\\hat{\\beta}-\\hat{\\beta}_{-i})}{p\\hat{\\sigma}^2} = \\frac{s_i^2 h_{ii}}{p(1-h_{ii})}\n\\end{equation}\n\nA data point is influential if it is outlying as well as high leverage. Cutoff for Cook's distance is $\\frac{4}{n}$.\n\n\\textbf{Procedure for checking model fit}:\nto-do, see p 73\n\n\\subsection{Transformations}\n\nSuppose $Y$ is a random variable whose variance depends on its mean. I.e., $E(y)=\\mu, Var(y)=g(\\mu)$.\nThe function $g(\\cdot)$ is known.\n\nWe seek a transformation from $y$ to $z = f(y)$ such that $Var(z)$ is (approximately) constant. \n\nExpand $f(\\cdot)$ in a Taylor series expansion, keeping only the first-order term:\n\n\\begin{equation}\nz= f(y)\\approx f(\\mu) + (y-\\mu)f'(\\mu)\n\\end{equation}\n\nThen: $E(z)=f(\\mu)$ and $Var(z)=g(\\mu) f'(\\mu)^2$. The variance needs to be constant at, say, $k^2$:\n\n\\begin{equation}\nk^2 = g(\\mu) f'(\\mu)^2 \\Rightarrow f'(\\mu)=\\frac{k}{\\sqrt{g(\\mu)}}\n\\end{equation}\n\nSo, \n\n\\begin{equation}\nf(\\mu) = \\int f'(\\mu) = k\\int \\frac{1}{\\sqrt{g(\\mu)}}\n\\end{equation}\n\n\\begin{fmpage}{\\linewidth}\n\\begin{equation}\nf(\\mu) =  k\\int [\\sqrt{g(\\mu)}]^{-1/2}\\, d\\mu\n\\end{equation}\n\\end{fmpage}\n\n\\textbf{Example 1}: Let $g(\\mu)=a\\mu$; then $f(\\mu)=2k\\sqrt{\\frac{\\mu}{a}}$. So, $z=\\sqrt{\\mu}$.\n\n\\textbf{Example 2}: Let $g(\\mu)=a\\mu^2$; then $f(\\mu)=k\\sqrt{\\frac{1}{a}}\\log \\mu$. So, $z=\\log \\mu$.\n\n\\textbf{Estimating a transformation}: $\\exists \\lambda$ such that \n\n\\begin{equation}\nf_\\lambda (y_i) = x_i^T \\beta + \\epsilon_i \\quad \\epsilon_i \\sim N(0, \\sigma^2)\n\\end{equation}\n\nWe use maximum likelihood estimation to estimate $\\lambda$. Note that\n\n$L(\\beta_\\lambda, \\sigma^2_\\lambda, \\lambda; y) \\propto$\n\n\\begin{equation}\n(\\frac{1}{\\sigma})^n \\exp [-\\frac{1}{2\\sigma^2} \\sum [f_\\lambda(y_i)-  x_i^T \\beta ]^2] [\\prod \\explain{f'_\\lambda(y_i)}{\\hbox{Jacobian}}] \n\\end{equation}\n\nFor fixed $\\lambda$, we estimate $\\hat{\\beta}$ and $\\hat{\\sigma}^2$ in the usual MLE way, and then we turn our attention to $\\lambda$:\n\n\\begin{equation}\nL(\\hat{\\beta}_\\lambda, \\hat{\\sigma}^2_\\lambda, \\lambda; y) = S_\\lambda^{-n/2}\\prod f'_\\lambda(y_i) \n\\end{equation}\n\nTaking logs:\n\n\\begin{equation}\n\\ell = c-\\frac{n}{2} \\log S_\\lambda + \\sum \\log f'_\\lambda(y_i)\n\\end{equation}\n\n\\textbf{Box-Cox family}:\n\n\\begin{equation}\nf_\\lambda (y) = \\left\\{ \n\\begin{array}{l l}\n       \\frac{y^\\lambda - 1}{\\lambda}   & \\lambda \\neq 0\\\\\n       \\log y & \\quad \\lambda=0\\\\\n\\end{array}\n\\right.\n\\end{equation}\n\nWe assume that $f_\\lambda (y) \\sim N(x_i^T \\beta,\\sigma^2)$. So we have to just estimate $\\lambda$ by MLE, along with $\\beta$.\n\n\\textbf{Box-Cox by hand}:\n\nSince $f_\\lambda=\\frac{y^\\lambda-1}{\\lambda}$, it follows that $f'_\\lambda(y)= y^{\\lambda-1}$.\n\nNow, for different $\\lambda$ you can figure out the log likelihoods by hand by solving this equation:\n\n\\begin{equation}\n\\ell = c-\\frac{n}{2} \\log \\explain{S_\\lambda}{\\hbox{Residual sum of squares}} + (\\lambda-1)\\sum \\log (y_i)\n\\end{equation}\n\n\\section{Factors}\n\n\\subsection{Overcoming multicollinearity through parameterization}\n\nto-do: multicollinearity explanation\n\nIf the model matrix $X$ is not full rank (this is true when we include a column for the intercept), then we can put constraints on the predictors (through parameterization). E.g., treatment contrasts (corner-point constraints), sum contrasts, etc.\n\nto-do constraints on p.\\ 94-95\n\n%\\subsection{Merging factor levels}\n\n%This is done to increase group size. \n\n\\subsection{Model selection}\n\n\\textbf{$S_r$ and $R^2$ can't be used for model selection}:\n``$S_r$ will always decrease when we add more regressor variables, so the best fitting model is always the full model which contains all the possible regressor variables - so $S_r$ is not a good model selection tool. For the same reason, the coefficient of determination $R^2$ is not a useful measure in model selection. $R^2$ will not decrease as the number of parameters increases (i.e. it is a non-decreasing function of the number of parameters in the model).''\n\n\\textbf{Penalized likelihood methods for model comparison}:\n\nWe can compare models using log likelihood: \n\n\\begin{equation}\n\\ell = n \\log \\hat{\\sigma}^2 + z(p)\n\\end{equation}\n\n\\noindent\nwhere $z$ is some penalty function. ``Then we declare that the optimal model is that which minimizes $\\ell$. We can think of $z$ as an ad hoc adjustment that tries to give simpler models credit for having fewer regressor variables.''\n\nAIC etc cannot be used to compare across datasets, but can be used to compare non-nested models (cf.\\ ANOVA, which allows only nested models to be compared).\n\n\\textbf{AIC}: here, $z(p)= 2p$. To calculate AIC:\n\n\\begin{equation}\nAIC = 2p + n\\log \\frac{S_r}{n}\n\\end{equation}\n\n[Note: does not match up with the AIC function output in R.]\n\n\\textbf{Where does AIC come from?} From the fact that maximum likelihood of $\\hat{\\sigma}^2$ is:\n\n\\begin{equation}\n  L(\\sigma) \\propto  (\\hat{\\sigma}^2)^{-n/2}\n\\end{equation}\n\n$-2\\times loglik=n\\log \\hat{\\sigma}^2=n\\log \\frac{S_r}{n}$ is a good model selection tool: smaller values (smaller $S_r$) will mean better fit.\n\n\\textbf{BIC}:  $z(p)= p\\log n$. This penalty will be large for large $n$, compared to AIC. \n\n\\textbf{Mallow's $C_p$}: \n\n\\begin{equation}\nC_p = \\frac{S_r}{\\hat{\\sigma}_f^2} - n + 2p_r\n\\end{equation}\n\n$\\hat{\\sigma}_f^2$ is the residual mean square of the full model, $S_r$ is residual \nsums of squares of  reduced model, $p_r$ is the number of regressors in the reduced model.  \n\nWe want a small $C_p$ and $C_p \\approx p$. \n\n\\textbf{Best subsets method}: in leaps library, regsubsets command.\n\n\\begin{verbatim}\nb<-regsubsets(model specification)\nsummary(b)$rsq, $cp, $bic\n\\end{verbatim}\n\n\\textbf{Backward elimination}: fit full model, and remove the t-value that's smallest, and so on.\nForward elimination goes in the other direction.\n\n\\textbf{Stepwise selection}: step function in MASS. Incrementally add a predictor as above, but once one is added, try removing other predictors with smallest t-value. Repeat until nothing can be added or deleted.\n\n\\begin{verbatim}\nstep(fm,scope=list(upper/lower=formula),\n        direction=\"forward/backward/both\")\n\\end{verbatim}\n\n\\section{Generalized least squares}\n\nLet $Var(\\epsilon)=\\sigma^2 \\Sigma$, where  $\\Sigma$ is known and non-singular. If $\\Sigma\\neq I_n$ then we either have correlation or non-equal variance or both. If $\\Sigma$ is known, we only need to estimate $\\sigma$ and we are back in least squares theory, with some modification:\n\n\\begin{equation}\ny \\sim N(X\\beta,\\sigma^2 \\Sigma)\n\\end{equation}\n\nLikelihood $L(\\beta,\\sigma^2; y)$ is now:\n\n\\begin{equation}\n (2\\pi)^{-n/2}\\mid \\sigma^2 \\Sigma\\mid^{-1/2} \\exp[-\\frac{1}{2\\sigma^2}(y-X\\beta)^T \\Sigma^{-1}  (y-X\\beta)]\n\\end{equation}\n\nThe MLE of $\\beta$ minimizes:\n\n\\begin{equation}\nS=(y-X\\beta)^T \\Sigma^{-1}  (y-X\\beta)\n\\end{equation}\n\ninstead of $(y-X\\beta)^T (y-X\\beta)$.\n\n\\textbf{Least squares estimators}:\n\n$\\hat{\\beta}: (X^T \\Sigma^{-1} X)^{-1}X^T \\Sigma^{-1} y$\n\n$E(\\hat{\\beta})=\\beta$\n\n$Var(\\hat{\\beta})=\\sigma^2 (X^T \\Sigma^{-1}X)^{-1}$\n\n\nEstimator of $\\sigma^2$ is $\\frac{S_v}{n-p}$, where\n\n$S_v=y^T \\Sigma^{-1} y - \\hat{\\beta}^T X^T \\Sigma^{-1} X\\hat{\\beta} = y^T \\Sigma^{-1} y - \\hat{\\beta}^T X^T \\Sigma^{-1} y$.\n\n\\subsection{Weighted least squares}\n\nSuppose $\\Sigma=diag(c1,\\dots,cn)$ (uncorrelated, but not homoscedastic) and so $\\Sigma^{-1}=diag(1/\nc1,\\dots,1/cn)$. Let $w_i = 1/c_i$. \n\nThe sum of squares will be \n$S=\\sum_{i=1}^n w_i (y_i - x_i^T \\beta)^2$. So each squared residual is weighted by that observation's variance; observations with large variance are less reliable, and are down-weighted.\n\nCompared to $X^T X = \\sum x_i x_i^T$ in WLS we have  $X^T \\Sigma^{-1} X = \\sum w_i x_i x_i^T$. \nAnd instead of $X^T y = \\sum x_i y_i$ in WLS we have $X^T \\Sigma^{-1}y = \\sum w_i x_i y_i$.\n\nSo $\\hat{\\beta}=(X^T \\Sigma^{-1}  X)^{-1}X^T \\Sigma^{-1}y= ( \\sum w_i x_i x_i^T)^{-1} (\\sum w_i x_i y_i)$\n\n``Weighted LS is appealing because it allows us to adjust for different (known) variances in the observations in an intuitive way that is easy to implement. The variances of the different observations might be known from pilot or previous studies'' (or are estimated from data).\n\n[SV: I don't get this ``known variance'' business. How can we ever \\textbf{know} what the variance is? Pilot or previous data will only yield estimates.]\n\nThe main disadvantage of WLS is that weights have to specified in advance.\n\n\\subsection{OLS vs WLS}\n\nWith dataset wls1.txt, if we fit:\n\n\\begin{verbatim}\nsummary(m0<-lm(y~X.x,data))\nsummary(m0.wls<-lm(y~X.x,data,\n                   weights=I(1/X.x^2)))\n\\end{verbatim}\n\nThe coefs will be the same in each, but SEs of coefs will be smaller in WLS fit (because $S_r$ will be down-weighted.\n\n\\textbf{Effect of scaling weights}:\n\nMultiplying the weights by some constant will change residual standard error, but leaves SEs and coefs unchanged. This is because $Var(\\hat{\\beta})=\\sigma^2 (X^T \\Sigma^{-1} X)^{-1}$, so whatever factor $\\sigma^2$ gets multiplied by, it will be cancelled out because it also appears in $ \\Sigma^{-1}$.\n\nDifferently put:\n\n``Let $w_i'$ be the scaled weights, $\\hat{\\sigma}'$ be the residual standard error in the analysis with the scaled weights, $S_r'$ be the residual sum of squares for the scaled analysis and $(\\Sigma^{-1})'$ be the weight matrix for the scaled analysis. Then if $w_i' = 16w_i$, we see that $\\hat{\\sigma}' = 4\\hat{\\sigma}$ since $S_r' = 16S_r$.''\n\nThe SEs will not change because: ``If \n$(\\Sigma^{-1})'=16\\Sigma^{-1}$ and \n$\\hat{\\sigma}' = 4\\hat{\\sigma}$ \nthen $Var(\\hat{\\beta}') = \n(\\hat{\\sigma}^2)' (X^T (\\Sigma^{-1})'X)^{-1} =\n(\\hat{\\sigma}^2)  (X^T (\\Sigma^{-1})X)^{-1}$.\nSo the standard errors don’t change.''\n\n\\begin{verbatim}\nsummary(m0.wls<-lm(y~X.x,data,\n                   weights=I(16*1/X.x^2)))\n\\end{verbatim}\n\n\\begin{enumerate}\n\\item\nIf you get the weights wrong, SEs will increase. So, if unsure about weights use OLS.\n\\item\n``If looking at the standardized residuals shows that there are observations that may be outliers and they reside in regions that will be given high weight then it may be safer to use OLS rather than WLS.''\n\\item One can estimate the weights from the data, but one needs lots of replicates for this, with fewer replicates the SEs will increase.\n\\item If you don't have enough replicates, you can group x values close to each other.\n\\item Outliers can dramatically influence estimates in WLS.\n\\end{enumerate}\n\nConclusion: WLS is a powerful tool, if weights are known, but outliers must be studied carefully.\n\n\\subsection{Using group means in WLS with replicated data}\n\nWithout replicates in the data, we have:\n\n\\begin{equation}\nX^T y = \\sum_i^n x_i y_i\n\\end{equation}\n\nIf we have $k$ replicates:\n\n\\begin{equation}\nX^T y = \\sum_{i=1}^k \\sum_{j=1}^{n_i} x_i y_{ij} =  \n\\sum_{i=1}^k x_i  \\sum_{j=1}^{n_i}  y_{ij} \n= \\sum_{i=1}^k n_i x_i \\bar{y}_i\n\\end{equation}\n\nThis is equivalent to having $\\bar{y}_i$ as observations for the replicate sets, and $n_i$ as weights in WLS.\nIf we had $\\bar{y}_i$ as observations, then their variances would be $\\sigma^2/n_i$, so we would have unequal variances and would use WLS with $w_i = n_i$. \\textbf{Example}: tractor data.\n\n\\subsection{Replication}\n\nDefine replicates here as repeated measurements that are mutually independent (cf.\\ replicates which are not independent, as in linear mixed model theory).\nSince all $x_i^T$ within a replicate set come from the same distribution, their variance should be an estimate of $\\sigma^2$.\n\nLet $y_{ij}$ be the $j$th observation in the $i$th replicate set, where $j=1,\\dots,n_i$ and $n_i$ is the size of the $i$th replicate set ($i=1,\\dots,k$). When $n_i = 1$ we have no replication, and for higher values we have replication. \\textit{Within} each replicate, we can produce an estimator:\n\n\\begin{equation}\n\\hat{\\sigma}^2 =  (n_i - 1)^{-1}  \\sum_{j=1}^{n_{i}} (y_{ij} - \\bar{y}_i)^2 = (n_i - 1)^{-1}S_i\n\\end{equation}\n\n$\\bar{y}_i=n_i^{-1} \\sum_{j=1}^{n_i} y_{ij}$  is the mean of the replicate set.\n$S_i \\sim \\sigma^2 \\chi_{n_i - 1}^2$.\n\nIn a one-factor model, $S_r = \\sum_{i=1}^k S_i$ and dfs are $n-k = \\sum_{i=1}^k (n_i -1)$. \nSo, in the general case,  $df_r=n-k$,  $S_r = \\sum_{i=1}^k S_i\\sim \\chi_{df_R}^2$. The ratio $\\hat{\\sigma}^2/df_R$ is an unbiased estimator of $\\sigma^2$.\n\nThe distributional fact being used here is that the sum of independent chi-squared distributions has a chi-squared distribution, and the degrees of freedom is the sum of dfs of the RVs being summed.\n\n\\textbf{The replication estimator}: $\\hat{\\sigma}_R^2=\\frac{S_R}{df_R}$ is the replication estimator of $\\sigma^2$.\n\n``The $\\hat{\\sigma}_R^2$ is independent of the particular form that we have used for the model. We obtain the same replication sum of squares with the same degrees of freedom whether we postulate a linear, quadratic, or some other relationship between Maintenance cost and Age.'' (to-do: don't get this). This is the strength of the replication sum of squares.\n\nThe $S_R$ is in general not equal to $S_r$.\n\n\\subsection{Partitioning replication sum of squares}\n\nto-do\n\n\\bibliographystyle{plain}\n\\bibliography{/Users/shravanvasishth/Dropbox/Bibliography/bibcleaned}\n", "meta": {"hexsha": "894d4ae963d7d5151556dc65b7b51236f3c4a89c", "size": 45728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LinearModels.tex", "max_stars_repo_name": "vasishth/MScStatisticsNotes", "max_stars_repo_head_hexsha": "bd4f4076fa785785b419c13580fe214120e4087e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2015-02-14T09:10:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T14:38:57.000Z", "max_issues_repo_path": "LinearModels.tex", "max_issues_repo_name": "ma0511/MScStatisticsNotes", "max_issues_repo_head_hexsha": "33acde1f79d3ec803f6491b7fee0897e126ddbe6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LinearModels.tex", "max_forks_repo_name": "ma0511/MScStatisticsNotes", "max_forks_repo_head_hexsha": "33acde1f79d3ec803f6491b7fee0897e126ddbe6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2015-02-14T12:07:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-21T08:30:19.000Z", "avg_line_length": 34.800608828, "max_line_length": 504, "alphanum_fraction": 0.6599457663, "num_tokens": 16465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6981372705678371}}
{"text": "\\section{Options, Part 2}\n\n\\subsection*{Binomial model: risk-neutral pricing}\n\n\nSolve by replication $\\delta$ shares of the stock, $b$ dollars of riskless bond\n\n$\\delta u S_0 + b (1+r) = C_u$ \\\\\n$\\delta d S_0 + b (1+r) = C_d$\n\nSolution: $\\delta = \\frac{C_u-C_d}{(u-d)S_0}$ , \n$b=\\frac{1}{1+r}\\frac{uC_d-dC_u}{u-d}$ \\\\\nThen: $C_0 = \\delta S_0 + b$ \\\\\n$ C_0 = \\frac{C_u-C_d}{(u-d)} + \\frac{1}{1+r} \\frac{uC_d-dC_u}{u-d}$ \\\\\n\n\\subsection*{Risk neutral probability}\n\n$q_u=\\frac{(1+r)-d}{u-d}$, $q_d = \\frac{u-(1+r)}{u-d}$ Then\n\n$C_0=\\frac{q_u C_u + q_d C_d}{1+r} = \\frac{E^Q[C_T]}{1+r}$ \nwhere $E^Q[\\cdot]$ is the expectation under probability $Q=(1,1-q)$, which is\ncalled the risk-neutral probability\n\n\\subsection*{State prices and risk-neutral probabilities}\n$\\Phi_u = \\frac{q}{1+r}$ , $\\Phi_d = \\frac{1-q}{1+r}$\n\n$\\Phi_{uu} = \\frac{q^2}{(1+r)^2}$ , $\\Phi_{ud} = \\Phi_{du} = \\frac{q(1-q)}{(1+r)^2}$ , $\\Phi_{dd} = \\frac{(1-q)^2}{(1+r)^2}$\nWith state prices, can price any state-contingent payoff as a portfolio of\nstate-contingent claims: mathematically equivalent to the risk-neutral\nvaluation formula.\n\n\n\\subsection*{Implementing binominal model}\n\n\\begin{itemize}\n\t\\item As we reduce the length of the time step, holding the maturity fixed, the\n\tbinomial distribution of log returns converges to Normal distribution.\n\t\\item Key model parameters $u$, and $d$ need to be chosen to reflect the\n\tdistribution of the stock return\n\\end{itemize}\n\nOnce choice is:  $u=exp(\\sigma \\frac{T}{n})$, $d=\\frac{1}{u}$, $p=\\frac{1}{2} + \\frac{1}{2} \\frac{u}{\\sigma} \\sqrt{\\frac{T}{n}}$\n\n\\subsection*{Black-Scholes-Merton formula}\n\n$C_0 = S_0 N(x) - K e^{-rT} N (x-\\sigma \\sqrt(T))$ \\\\\n$x = \\frac{ln(\\frac{S_0}{K e^{-rT}})}{\\sigma \\sqrt{T}} + \\frac{1}{2} \\sigma \\sqrt{T}$ \\\\\n\nIn Excel \\texttt{$N(x)$=NORM.S.DIST(x,TRUE)}\nThe call is equivalent to a levered long position in the stock;\n $S_0 N(x) $ is the amount invested in the stock;\n$K e^{-rT} N (x-\\sigma \\sqrt(T))$ is the dollar amount borrowed.\n\nEquivalent formulation:\n$ C(S_t, t) = N(d_1)S_t - N(d_2)Ke^{-r(T - t)} $ \\\\\n$ d_1 = \\frac{1}{\\sigma\\sqrt{T - t}}\\left[\\ln\\left(\\frac{S_t}{K}\\right) + \\left(r + \\frac{\\sigma^2}{2}\\right)(T - t)\\right] $\\\\\n$ d_2 = d_1 - \\sigma\\sqrt{T - t} $ \n\nThe price of a corresponding put option based on put-call parity  is:\n$ P(S_t, t) = Ke^{-r(T - t)} - S_t + C(S_t, t) =  N(-d_2) Ke^{-r(T - t)} - N(-d_1) S_t $\n\n\\subsection*{Option Greeks}\n\nDelta: $\\delta = \\frac{\\partial C}{\\partial S}$\nOmega: $\\Omega = \\frac{\\partial C}{\\partial S} \\frac{S}{C}$\nGamma: $\\Gamma = \\frac{\\partial \\delta}{\\partial S} = \\frac{\\partial^2 C}{\\partial S^2} $\nTheta: $\\Theta = \\frac{\\partial C}{\\partial S}$\nVega:  $\\mathcal{V} = \\frac{\\partial C}{\\partial S}$\n", "meta": {"hexsha": "20458728cbe20c398c63c87f5fa4a5970f2400c8", "size": 2712, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.415.2x/assets/week_13.tex", "max_stars_repo_name": "j053g/cheatsheets", "max_stars_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-14T08:49:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T17:26:15.000Z", "max_issues_repo_path": "15.415.2x/assets/week_13.tex", "max_issues_repo_name": "j053g/cheatsheets", "max_issues_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15.415.2x/assets/week_13.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": 39.3043478261, "max_line_length": 128, "alphanum_fraction": 0.6286873156, "num_tokens": 1015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6981372705678371}}
{"text": "\\section{Multi-class Case}\nWe now consider the situation where there are $k > 2$ classes. \n\nWe now define the analogous notion of `margin,' which will be important when we introduce the SVM model later.\n\\begin{definition}\\label{margin_k_classes}\n Suppose that $k$ subsets of $\\mathbb{R}^n$, $A_1,...,A_k$ are linearly separable by the matrix $W$ and vector $b$,\n and let $d$ be a metric on $\\mathbb{R}^n$ as before. The margin of separation with respect to\n $d$ is given by\n \\begin{equation}\n  m(W,b; A_1,..., A_k) = \\sup \\{\\epsilon:\\text{$A^{\\epsilon}_1,..., A^\\epsilon_k$ are still linearly separated by $W$ and $b$}\\}\n \\end{equation}\nwhere, as before, the $\\epsilon$-enlargement of $A_i$ is given by\n\\begin{equation}\n A^\\epsilon_i = \\{y:\\text{there is an $x\\in A_i$ such that $\\|x-y\\| < \\epsilon$}\\}\n\\end{equation}\n\\end{definition}\nThis notion of margin measures how much we can perturb each data point without triggering a misclassification. This is \nquite a useful notion especially given the freedom to choose the metric $d$.\n\nWe close this section with a technical lemma relating compactness and the margin of separation, which can safely be skipped.\n\\begin{lemma}{\\label{kclass_margin}}\n Suppose that the sets $A_1,...,A_k$ are separated by the matrix $W$ and vector $b$ and that $A_1,...,A_k$ are compact\n with respect to the topology induced by a metric $d$. Then\n \\begin{equation}\n  m(W,b; A_1,...,A_k) > 0\n\\end{equation}\n\n\\end{lemma}\n\n\\begin{proof}\n\tAccording to Lemma \\ref{Interplation}, we only need to prove that for each $A_i$, there exists a positive number $\\epsilon_i$ such that $A_i^{\\epsilon_i}$ are still in $\\Gamma_i(W,b)$. In fact, $\\Gamma_i(W,b)$ is an open set, so $(\\Gamma_i(W,b))^C$ and $A_i$ are two disjoint closed set. Thus we have\n\t\\begin{equation}\n\td_i = d(A_i,(\\Gamma_i(W,b))^C) > 0\n\t\\end{equation}\n\tWe can take $\\epsilon_i = d_i$. Actually, $d_i$ is the largest value that $\\epsilon_i $ can take. And we have\n\t\\begin{equation}\n\tm(W,b; A_1,...,A_k) =  \\min_{i}~d_i > 0\n\t\\end{equation}\n\\end{proof}\n\n\n\\subsection{k-class hard-margin Case}\nIn our examination of the $k$-class case, we first consider the situation where our data is linearly separable.\n\nAssuming that our dataset is finite, and thus compact, we see that there exists an $\\epsilon > 0$ such that\n\\begin{equation}\n w_i x+b_i \\geq w_jx+b_j + \\epsilon\n\\end{equation}\nfor all $x\\in A_i$ and $j\\neq i$, and a rescaling of $W$ and $b$ by $2\\epsilon^{-1}$ means that we can assume without loss of \ngenerality that\n\\begin{equation}\n w_i x+b_i \\geq w_jx+b_j + 2\n\\end{equation}\nfor all $x\\in A_i$ and $j\\neq i$. Or we can formulate it as\n\\begin{equation}\\label{separation_constraint_k}\nw_i x+b_i \\geq \\max_{j\\neq i} (w_jx + b_j) + 2,~~\\forall x\\in A_i.\n\\end{equation}\n\n%In order to simplify notation, we index our data points $x_1,...,x_N$ and introduce labels $y_1,...,y_N$, where\n%\\begin{equation}\n% y_i = e_j~\\text{if $x_i\\in A_j$}\n%\\end{equation}\n%i.e. $y_i$ is the standard basis vector corresponding to the class to which $x_i$ belongs. A clever and compact way of writing\n%the linear separation constraint is now\n%\\begin{equation}\\label{separation_constraint_k}\n %(y_i - e_j)\\cdot (Wx_i+b) \\geq \\|y_i - e_j\\|_1\n%\\end{equation}\n%for all $i = 1,...,N$ and $j = 1,...,k$.\n\nWe note that the condition (\\ref{separation_constraint_k}) is a collection of $Nk$ linear constraints on the matrix $W$ and\nvector $b$. This means that we can determine whether our data is linearly separable by checking whether a given linear\nprogram is feasible.\n\nOf course, if our data is linearly separable, then we would like to find a matrix $W$ and vector $b$ which maximizes the\nmargin of separation as defined in Definition \\ref{margin_k_classes}. To this end, we have the following lemma.\n\\begin{lemma}\n Assume that our data is separated by the matrix $W$ and vector $b$, and that (\\ref{separation_constraint_k}) holds.\n Then the margin of separation is bounded below by\n \\begin{equation}\n  m(W,b;A_1,...,A_k)\\geq \\frac{1}{\\max_{1\\leq i\\leq k}\\|w_i\\|}\n \\end{equation}\n where $\\|w_i\\|$ is the dual norm of the $i$-th row of $w$.\n\\end{lemma}\n\n\\begin{proof}\n\tUse the notations in the proof of lemma \\ref{kclass_margin}. Because $m(W,b, A_1,...,A_k) =  \\min_{i}~d_i$, we only need to prove for each $i$, $d_i = d(A_i,\\partial\\Gamma_i(W,b)) \\geq 1/\\max_{1\\leq i\\leq k}\\|w_i\\|$.\\\\\n\tTake a point $x$ from $A_i$ and a point $y$ from $\\partial\\Gamma_i(W,b)$ arbitrarily. There exists $j\\neq i$ such that\n\t$y \\in H_{ij}$. So we have\n\t\\begin{equation}\n\t\\|x-y\\| \\geq d(x^i,H_{ij}) = \\frac{|(w_i-w_j)x+(b_i-b_j)|}{\\|w_i-w_j\\|}\\geq \\frac{2}{\\|w_i-w_j\\|}\\geq\n\t\\frac{1}{\\max_{1\\leq i\\leq k}\\|w_i\\|}.\n\t\\end{equation}\n    So we have\n\t\\begin{equation}\n\td_i = \\inf_{y\\in \\partial\\Gamma_i(W,b)} \\|x-y\\| \\geq \\frac{1}{\\max_{1\\leq i\\leq k}\\|w_i\\|}.\n\t\\end{equation}\n\tAbove all, we can obtain\n\t\\begin{equation}\n\tm_d(W,b;A_1,...,A_k) = \\min_i~d_i \\geq  \\frac{1}{\\max_{1\\leq i\\leq k}\\|w_i\\|}.\n\t\\end{equation}\n\t\n\\end{proof}\n\nThis leads to the following convex optimization problem\n\\begin{align}{\\label{kclass_hard_op}}\n \\min_{W,~b~}~~&\\max_{1\\leq i\\leq k}\\|w_i\\|\\\\\n s.t.~~&w_i x+b_i \\geq \\max_{j\\neq i} (w_jx + b_j) + 2,~~\\forall x\\in A_i.\n\\end{align}\nNaturally, we are interested in the relation between (\\ref{kclass_hard_op}) for $k=2$ and $(\\ref{2class_hard_op})$. It seems that we have done some relaxation in (\\ref{kclass_hard_op}), but actually it is equivalent to $(\\ref{2class_hard_op})$ in 2-class situations.\n\\begin{lemma}\nThe optimization problem (\\ref{kclass_hard_op}) is equivalent to the problem $(\\ref{2class_hard_op})$ when $k=2$.\n\\end{lemma} \n\\begin{proof}\nWe'll set $k=2$ in the following statement. When $k=2$, the constraint (\\ref{separation_constraint_k}) is equivalent to the constraint (\\ref{separation_condition_2}), So we use (\\ref{separation_condition_2}) to denote the constraint of both two problems. \\\\\nWe define three sets $\\Omega,\\Omega_1,\\Omega_2$ as\n\\begin{gather}\n\\Omega = \\{w~|~\\exists b\\in \\mathbb{R},~\\text{s.t.}~wx+b\\geq 2, \\forall x \\in A_1~\\text{and}~wx+b\\leq -2, \\forall x\\in A_2\\}.\\\\\n\\Omega_1 = \\{(w_1,w_2)~|~w_1-w_2\\in\\Omega\\}\\\\\n\\Omega_2 = \\{(w_1,w_2)~|~w_1-w_2\\in\\Omega~\\text{and}~w_1 = -w_2\\}\n\\end{gather}\nThe constraint (\\ref{separation_condition_2}) can be written as\n\\begin{equation}\n(w_1,w_2)\\in \\Omega_1.\n\\end{equation}\nObserving that $\\Omega_2 \\subset\\Omega_1$, we'll show that for problem (\\ref{kclass_hard_op}), nothing will change if we use the subset $\\Omega_2$ to replace $\\Omega_1$ in the constraint.\\\\\nTake $(w_1,w_2)\\in \\Omega_1$ arbitrarily, and denote \n\\[\n\\tilde{w}_1 = \\frac{w_1-w_2}{2},~\\tilde{w}_2 = -\\frac{w_1-w_2}{2},\n\\]\nthen we have $(\\tilde{w}_1,\\tilde{w}_2)\\in \\Omega_2$ and\n\\begin{equation}\n\\max_{1\\leq i\\leq 2}\\|\\tilde{w}_i\\| = \\frac{1}{2} \\|\\tilde{w}_1-\\tilde{w}_2\\| = \\frac{1}{2}\\|w_1-w_2\\| \\leq \\max_{1\\leq i\\leq 2}\\|w_i\\|.\n\\end{equation}\nThe inequalities above show that the element in $\\Omega_1\\backslash\\Omega_2$ won't affect the solution of (\\ref{kclass_hard_op}) at all. So we can use  $\\Omega_2$ to replace $\\Omega_1$ in problem (\\ref{kclass_hard_op}), which means (\\ref{kclass_hard_op}) is equivalent to \n\\begin{equation}\\label{proof_op1}\n\t\\min_{(w_1,w_2)\\in\\Omega_2} \\max_{1\\leq i\\leq 2}\\|w_i\\|.\n\\end{equation}\nAlso, easy to observe that the problem (\\ref{separation_condition_2}) is equivalent to \n\\begin{equation}\\label{proof_op2}\n\\min_{(w_1,w_2)\\in \\Omega_2} \\| w_1-w_2\\|.\n\\end{equation}\nFor all $(w_1,w_2)\\in \\Omega_2$, we have\n\\begin{equation}\n\t\\max_{1\\leq i\\leq 2}\\|w_i\\| = \\frac{1}{2} \\| w_1-w_2\\|,\n\\end{equation}\nwhich implies that the problem (\\ref{proof_op1}) is equivalent to the problem (\\ref{proof_op2}). \\\\\nConsequently, the problem (\\ref{2class_hard_op}) is equivalent to the problem (\\ref{kclass_hard_op}) when $k=2$.\n\\end{proof}\n\n\\subsection{k-class soft-margin Case}\nIf the data is not max-mat linearly separable, then we replace the hard constraint (\\ref{separation_constraint_k})\nby a penalty term. A common choice of penalty is the hinge or ReLU loss, which only penalizes those constraints which are\nnot satisfied and leads to an optimization problem of the form\n\\begin{equation}{\\label{kclass_soft_op}}\n \\min_{W,~b}\\max_{1\\leq i\\leq k}\\|w_i\\| + C\\displaystyle\\sum_{i=1}^k\\displaystyle\\sum_{x\\in A_i}\\text{ReLU}\\Big( \\max_{j\\neq i} (w_jx + b_j) + 2 - (w_ix+b_i)\\Big)\n\\end{equation}\nwhere $C$ is a parameter controlling how much the penalty term is weighted.\n\nWhen $k =2$, denoting $w_1-w_2$ as $w$, $b_1-b_2$ as $b$, we can write the 2-class soft margin optimization as \n\\begin{equation}{\\label{2-class soft-margin optimization}}\n\\min_{w,b} \\|w\\| + C\\sum_{i=1}^2 \\sum_{x\\in A_i} ReLU((-1)^i (wx+b)+2)\n\\end{equation}\n\n\\section{Optimizaiton Problem in SVM}\nFrom the discussion above, we transformed the classification problem into some optimization problems. In this section, we'll use Lagrange duality to transform the primal  problem into dual problem.  That will provide convinience for introducing the kernel method in SVM.\\\\\nWe first take a look at the hard-margin case as a transition to the soft-margin case.  Trivially, the problem (\\ref{kclass_hard_op}) is equivalent to the following problem:\n\\begin{equation}\n\\begin{aligned}\n\\min_{W,~b} ~~& \\max_{1\\leq i\\leq k}\\|w_i\\|,\\\\\ns.t.               ~~& \\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)\\leq 0,~\\forall i,j.\\\\\n\\end{aligned}\n\\end{equation}\nFor the introduction of inner product, here we take $\\|\\cdot\\|=\\|\\cdot\\|_2$, and use $\\displaystyle\\sum_{l=1}^k \\|w_i\\|_2^2$ to replace $\\max_{1\\leq i\\leq k}\\|w_i\\|$. We can obtain a convex quadratic optimization problem for hard-margin case:\n\\begin{equation}{\\label{kclass_hard_CQP}}\n\\begin{aligned}\n\\min_{W,~b} ~~& \\frac{1}{2}\\displaystyle\\sum_{l=1}^k \\|w_l\\|_2^2,\\\\\ns.t.               ~~& \\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)\\leq 0,~\\forall i,j.\\\\\n\\end{aligned}\n\\end{equation}\n\nNow let's turn to the soft-margin case. Similarly, we take $\\|\\cdot\\|=\\|\\cdot\\|_2$, and use $\\displaystyle\\sum_{l=1}^k \\|w_i\\|_2^2$ to replace $\\max_{1\\leq i\\leq k}\\|w_i\\|$.\n\n\\begin{equation}{\\label{kclass_soft_OP}}\n\\min_{W,~b}  \\frac{1}{2}\\displaystyle\\sum_{i=1}^k \\|w_i\\|_2^2 + C\\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k\\text{ReLU}\\Big(\\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)\\Big)\n\\end{equation}\n\n\\begin{theorem}[Representer Theorem]\nThe solution of (\\ref{kclass_soft_OP}) must belong to $span\\{x_1,\\cdots,x_N\\}$, which means for each $i = 1,2,\\cdots,k$, if $w_i^*$ is the optimal $w_i$ of (\\ref{kclass_soft_OP}), then there must exist $\\alpha_1^i,\\cdots,\\alpha_N^i\\in \\mathbb{R}$, such that  \n\\[\nw_i^* = \\sum_{j = 1}^N \\alpha_j^i x_j.\n\\]\n\\end{theorem}\n\n\\begin{proof}\nDenote $span\\{x_1,\\cdots,x_N\\}$ as $X$ and the orthogonal projection operater on $X$ in $\\mathbb{R}^n$ as $P$. Denote the objective function as $L(w_1,\\cdots,w_k,b)$.\\\\\nIn fact, for each $i = 1,\\cdots,k$, we have\n\\begin{align}\n\\|w_i\\|_2^2 = ~&\\|Pw_i + (w_i-Pw_i)\\|_2^2 = \\|Pw_i\\|_2^2+\\|w_i-Pw_i\\|_2^2\\geq \\|Pw_i\\|_2^2,\\\\\nw_ix+b_i &= (Pw_i) x + b_i,~~\\forall x \\in\\{x_1,\\cdots,x_N\\}.\n\\end{align}\nSo easy to observe that\n\\begin{align}\n\\sum_{i=1}^k &\\|Pw_i\\|_2^2\\leq \\sum_{i=1}^k \\|w_i\\|_2^2,\\\\\n\\max_{j\\neq i} &((Pw_j)x + b_j) + 2 - ((Pw_i)x+b_i) = \\max_{j\\neq i} (w_jx + b_j) + 2 - (w_ix+b_i).\n\\end{align}\nSo we have\n\\begin{equation}\nL(Pw_1,\\cdots,Pw_k,b)\\leq L(w_1,\\cdots,w_k,b),\n\\end{equation}\nwhich means the optimal $w_i$ for each $i\\in\\{1,\\cdots,k\\}$ must belong to $X$.\n\\end{proof}\n\nWe can obtain a similar convex quadratic optimization problem to (\\ref{kclass_hard_CQP}) by introducing some slack variables $\\xi$.\n\n\\begin{equation}{\\label{kclass_soft_CQP}}\n\\begin{aligned}\n\\min_{W,b,\\xi} ~~& \\frac{1}{2}\\displaystyle\\sum_{j=1}^k \\|w_j\\|_2^2+C\\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k \\xi_{ij},\\\\\ns.t.               ~~& \\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)-\\xi_{ij} \\leq 0,~\\forall i,j.\\\\\n                        & \\xi_{ij} \\geq 0,~\\forall i,j.\n\\end{aligned}\n\\end{equation}\n\n\\begin{lemma}\nThe problem (\\ref{kclass_soft_CQP}) is equivalent to the probelm (\\ref{kclass_soft_OP}).\n\\end{lemma}\n\\begin{proof}\nDenote the objetive functions as $f_1,f_2$:\n\\begin{equation}\n\\begin{split}\n&f_1(W,b) = \\frac{1}{2}\\displaystyle\\sum_{j=1}^k \\|w_j\\|_2^2 + C\\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k\\text{ReLU}\\Big(\\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)\\Big)\\\\\n&f_2(W,b,\\xi) = \\frac{1}{2}\\displaystyle\\sum_{j=1}^k \\|w_j\\|_2^2+C\\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k \\xi_{ij}.\n\\end{split}\n\\end{equation}\nEasy to observe that \n\\begin{equation}\n\tf_2(W,b,\\xi)\\leq f_1(W,b),\n\\end{equation}\nequality holds iff \n\\begin{equation}\n    \\xi_{ij} = \\text{ReLU}\\Big(\\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)\\Big).\n\\end{equation}\n\\end{proof}\n\n\nIt's easy to observe that the Slater's condition holds in the problem (\\ref{kclass_soft_CQP}). That means we can obtain the optimal points of problem (\\ref{kclass_soft_CQP}) by solving its dual problem.\\\\\nThe Lagrangian function of (\\ref{kclass_soft_CQP}) is\n\\begin{equation}\n\\begin{aligned}\n\t&L(W,b,\\xi,\\lambda,\\mu) \\\\\n\t= &\\frac{1}{2}\\displaystyle\\sum_{j=1}^k \\|w_j\\|_2^2+C\\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k \\xi_{ij} + \\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k \\lambda_{ij}\\Big(\\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)-\\xi_{ij}\\Big) - \\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k \\mu_{ij} \\xi_{ij}\\\\\n\t= &\\frac{1}{2}\\displaystyle\\sum_{j=1}^k \\|w_j\\|_2^2 + \\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k (C-\\lambda_{ij}-\\mu_{ij})\\xi_{ij} + \\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k \\lambda_{ij}\\Big(\\|y_i - e_j\\|_1 - (y_i - e_j)\\cdot (Wx_i+b)\\Big)\\\\\n\t= &\\frac{1}{2}\\displaystyle\\sum_{j=1}^k \\|w_j\\|_2^2 + \\displaystyle\\sum_{i=1}^N\\displaystyle\\sum_{j=1}^k (C-\\lambda_{ij}-\\mu_{ij})\\xi_{ij} + \\displaystyle\\sum_{i=1}^N\\Big(\\delta_i-t_i\\cdot (Wx_i)-t_i\\cdot b\\Big)\n\\end{aligned}\n\\end{equation}\nwhere $\\delta_i = \\sum_{j=1}^k\\lambda_{ij}\\|y_i - e_j\\|_1$, $t_i = \\sum_{j=1}^k\\lambda_{ij}(y_i - e_j)$, and $\\lambda_{ij},\\mu_{ij}\\geq 0$.\\\\\nThe dual problem of (\\ref{kclass_soft_CQP}) is \n\\begin{equation}{\\label{dual_problem}}\n\\max_{\\lambda,\\mu\\geq 0} \\min_{W,b,\\xi} L(W,b,\\xi,\\lambda,\\mu). \n\\end{equation}\nAccording to KKT conditions, we have \n\\begin{equation}\n\\begin{aligned}\n\\nabla_{W}L(W^*,b^*,\\xi^*,\\lambda,\\mu) &= W_* - \\displaystyle\\sum_{i=1}^N t_ix_i^{T} = 0,\\\\\n\\nabla_{b}L(W^*,b^*,\\xi^*,\\lambda,\\mu)  &= -\\displaystyle\\sum_{i=1}^N t_i = 0,\\\\\n\\nabla_{\\xi_{ij}}L(W^*,b^*,\\xi^*,\\lambda,\\mu)  &= C-\\lambda_{ij}-\\mu_{ij} = 0,~\\forall i,j..\n\\end{aligned}\n\\end{equation}\nTake the equations above into dual problem (\\ref{dual_problem}), we have\n\\begin{equation}\n\\begin{aligned}\n&\\min_{W,b,\\xi} L(W,b,\\xi,\\lambda,\\mu) \\\\\n= &L(W^*,b^*,\\xi^*,\\lambda,\\mu)\\\\ \n= &\\frac{1}{2} Tr\\Big((\\displaystyle\\sum_{i=1}^N t_i x_i^T)(\\displaystyle\\sum_{l=1}^N x_l t_l^T)\\Big) -\\displaystyle\\sum_{i=1}^N t_i\\cdot\\Big((\\displaystyle\\sum_{l=1}^N t_l x_l^T)x_i\\Big)+ \\displaystyle\\sum_{i=1}^N \\delta_i\\\\\n= &-\\frac{1}{2}\\displaystyle\\sum_{i=1}^N\\sum_{l=1}^N (t_i\\cdot t_l)(x_i\\cdot x_l)+ \\displaystyle\\sum_{i=1}^N \\delta_i\\\\\n= &-\\frac{1}{2}\\displaystyle\\sum_{i=1}^N\\sum_{l=1}^N\\Big(\\displaystyle\\sum_{j=1}^k\\sum_{m=1}^k \\lambda_{ij}\\lambda_{lm}(y_i-e_j)\\cdot(y_l-e_m)\\Big)(x_i\\cdot x_l)+ \\displaystyle\\sum_{i=1}^N\\sum_{j=1}^k\\lambda_{ij}\\|y_i - e_j\\|_1\n\\end{aligned}\n\\end{equation}\nSo our dual problem can be transformed into the following form:\n\\begin{equation}{\\label{SVM_dual}}\n\\begin{aligned}\n\\min_{\\lambda}&~~ -\\frac{1}{2}\\displaystyle\\sum_{i=1}^N\\sum_{l=1}^N\\Big(\\displaystyle\\sum_{j=1}^k\\sum_{m=1}^k \\lambda_{ij}\\lambda_{lm}(y_i-e_j)\\cdot(y_l-e_m)\\Big)(x_i\\cdot x_l)+ \\displaystyle\\sum_{i=1}^N\\sum_{j=1}^k\\lambda_{ij}\\|y_i - e_j\\|_1,\\\\\ns.t.&~~\\displaystyle \\sum_{i=1}^N\\sum_{j=1}^k\\lambda_{ij}(y_i - e_j) = 0,\\\\\n     &~~0\\leq \\lambda_{ij}\\leq C,~\\forall i,j.\n\\end{aligned}\n\\end{equation}\n\n\\section{Kernel Methods}\nWe denote the input space as $X$. Recalling that in the beginning of this chapter, we mentioned that a common way of obtaining a nonlinear classification model is to set $\\mathscr{H} = \\{\\bm{f}: \\bm{f}(x) = W\\bm{\\phi}(x)+b\\}$, where $\\bm{\\phi}$ is a feature mapping from $X$ to a feature space $\\mathcal{H}$. In other words, we use two steps to obtain a nonlinear classification model. First, we map input space $X$ to a feature space $\\mathcal{H}$. Second, use linear classifier to do classification on $\\bm\\phi(X)\\subset \\mathcal{H}$.\\\\\nNotice that if we use SVM on feature space, the optimization problem (\\ref{SVM_dual}) turns to be\n\\begin{equation}{\\label{SVM_dual}}\n\\begin{aligned}\n\\min_{W,~b}&~~ -\\frac{1}{2}\\displaystyle\\sum_{i=1}^N\\sum_{l=1}^N\\Big(\\displaystyle\\sum_{j=1}^k\\sum_{m=1}^k \\lambda_{ij}\\lambda_{lm}(y_i-e_j)\\cdot(y_l-e_m)\\Big)\\langle\\bm\\phi(x_i),\\bm\\phi(x_l)\\rangle+ \\displaystyle\\sum_{i=1}^N\\sum_{j=1}^k\\lambda_{ij}\\|y_i - e_j\\|_1,\\\\\ns.t.&~~\\displaystyle \\sum_{i=1}^N\\sum_{j=1}^k\\lambda_{ij}(y_i - e_j) = 0,\\\\\n&~~0\\leq \\lambda_{ij}\\leq C,~\\forall i,j.\n\\end{aligned}\n\\end{equation}\nAn interesting thing is that we actually only need to use the inner product of feature space in computation. That inspires us to focus on the inner product in feature space instead of the feature mapping itself.  We regard the inner product in feature space as a binary function on $X\\times X$ and define it as a kernel function. In other words, a kernel function is $k: X\\times X \\rightarrow \\mathbb{R}$ which\n\\begin{equation}\nk(x,x) = \\langle\\bm\\phi(x),\\bm\\phi(x')\\rangle.\n\\end{equation}\n\n\\begin{definition}\nLet $X$ be a non-empty set. Then a function $k:X\\times X \\rightarrow\\mathbb{K}$ is\ncalled a \\textbf{kernel} on $X$ if there exists a $\\mathbb{K}$-Hilbert space $\\mathcal{H}$ and a map $\\bm{\\phi}:X\\rightarrow \\mathcal{H}$ such that for all $x \\in X$ we have\n\\begin{equation}\nk(x,x) = \\langle\\bm\\phi(x),\\bm\\phi(x')\\rangle.\n\\end{equation}\nWe call $\\bm{\\phi}$ a feature map and $\\mathcal{H}$ a feature space of k.\n\\end{definition}\n\n\\begin{lemma}\nLet $X$ be a non-empty set and $f_n:X\\times X \\rightarrow \\mathbb{K}, n\\in \\mathbb{N}$, be functions such that $(f_n(x))\\in l_2$ for all $x\\in X$. Then \n\\begin{equation}\nk(x,x'):= \\sum_{n=1}^{\\infty} f_n(x) \\overline{f_n(x')},~x,x'\\in X,\n\\end{equation}\ndefines a kernel on $X$.\n\\end{lemma}\n\n\\begin{definition}\nA function $k:X\\times X \\rightarrow \\mathbb{R}$ is called \\textbf{positive definite} if for all $n\\in \\mathbb{N}, ~\\alpha_1,\\cdots,\\alpha_n\\in \\mathbb{R}$ and all $x_1,\\cdots,x_n \\in X$, we have\n\\begin{equation}{\\label{positive_definite_kernel}}\n\\displaystyle\\sum_{i=1}^n\\sum_{j=1}^n\\alpha_i \\alpha_j k(x_j,x_i)\\geq 0.\n\\end{equation}\nFurthermore, $k$ is said to be \\textbf{strictly positive definite} if, for mutually distinct $x_1,\\cdots,x_n \\in X$, equality in (\\ref{positive_definite_kernel}) only holds for $\\alpha_1=\\cdots=\\alpha_n=0$. Finnaly, $k$ is called \\textbf{symmetric} if $k(x,x')=k(x',x)$ for all $x,x' \\in X$.\n\\end{definition}\n\n\\begin{theorem}\nA function $k:X\\times X \\rightarrow \\mathbb{R}$ is a kernel if and only if it is symmetric and postive definite.\n\\end{theorem}\n\\begin{proof}\nIt is trivial that a kernel is a symmetric and postive definite function. We will mainly show the reverse implication.\\\\\nAssuming $k$ is a positive definite kernel defined on $X$, we'll proceed to construct a feature mapping $\\bm\\phi$ into a Hilbert space for which $k$ is the kernel. We'll suppose that $X$ is an infinite set in the following discussion.\n\\begin{enumerate}\n\t\\item Define the feature mapping $\\bm\\phi$ and construct a vector space $H_{pre}$.\\\\\n\tWe define\n\t$$\\bm\\phi:x\\longmapsto k(\\cdot,x)$$\n\tAccording to this mapping, we span the image set to a vector space\n\t$$H_{pre}=\\Big\\{\\sum_{i=1}^{n}\\alpha_{i}k(\\cdot,x_{i}):n\\in\\mathbb{N},\\ \\bm x_{i}\\in X,~\\alpha_{i}\\in\\mathbf{R},~i=1,\\cdots,N \\Big\\}$$\n\t\\item Make $H_{pre}$ an inner product space by defining inner product on $H_{pre}$.\\\\\n\tWe define a binary function \"$<\\cdot,\\cdot>$\" on $H_{pre}$: for any $f,g\\in \\bm F$\n\t$$ f(\\cdot)=\\sum_{i=1}^{n}\\alpha_{i}k(\\cdot,x_{i}) $$\n\t$$ g(\\cdot)=\\sum_{j=1}^{m}\\beta_{i}k(\\cdot,x_{j}) $$\n\t$$ <f,g>=\\sum_{i=1}^{n}\\sum_{j=1}^{m}\\alpha_{i}\\beta_{j}k(x'_{j},x_{i}) $$\n\tThe bilinearity and symmetry are easy to prove. Because the function$k$ is positive definite, we have\n\t$$ <f,f>=\\sum_{i,j=1}^{m}\\alpha_{i}\\alpha_{j}k(x_{i},x_{j}),\\forall\\ f\\in H_{pre} $$\\\\\n\tUse the symetric and positive definite property of Gram matrix, we can prove the Cauchy-Schwarz inequality\n\t\\begin{equation}\n\t<f,g>^2\\leqslant<f,f><g,g>\n\t\\end{equation}\n\tNotice that\n\t\\begin{equation}\\label{reproducing property}\n\t<f, k(\\cdot,x)>=\\sum_{i=1}^{m}\\alpha_{i}k(x_{i},x)=f(x)\n\t\\end{equation}\n\tTake $g(\\cdot)=k(\\cdot,x)$ into (45), we have\n\t$$ <f,k(\\cdot,x)>^2=|f(x)|^2\\leq <f,f>k(x,x) $$\n\tSo $<f,f>=0$ implies $f(x)\\equiv 0$.\n\tAbove all, binary function \"$\\bm\\cdot$\" satisfies bilinearity, symmetry and positive definiteness which suffices to show that \"$<\\cdot,\\cdot>$\" is an inner product on $H_{pre}$. \\\\\n\tNow vector space $H_{pre}$ equipped with inner product \"$<\\cdot,\\cdot>$\" is an inner product space.\n\t\\item Complete the inner product space $H_{pre}$, we can get a Hilbert space $H$.\\\\\n\tLet $H$ be a completion of $H_{pre}$ and $I:H_{pre} \\rightarrow H$ be the corresponding isometric embedding. Then $H$ is a Hilbert space and we have\n\t$$\n\t<Ik(\\cdot,x'),Ik(\\cdot,x)>_H=<k(\\cdot,x'),k(\\cdot,x)>_{H_{pre}}=k(x,x')\n\t$$\n\tfor all $x,x'\\in X, i.e., x\\mapsto Ik(\\cdot,x), x\\in X$, defines a feature map of $k$.\n\tThis Hilbert space is called $\\textbf{reproducing\\ kernel\\ Hilbert\\ space\\ (RKHS)}$ because it satisfies equation (\\ref{reproducing property}) which is called \\textbf{reproducing property}.\n\\end{enumerate}\n\\end{proof}\n\n\\section{Relationship between SVM and Logistic Regression}\n\\includepdf[pages=-]{6DL/SVM-LR.pdf}\n", "meta": {"hexsha": "32ad9efa958708d47f986cb2c26f775a9ad7e493", "size": 21683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DL-SVM-k.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/DL-SVM-k.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/DL-SVM-k.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.4447439353, "max_line_length": 538, "alphanum_fraction": 0.6830696859, "num_tokens": 8193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6981372686776913}}
{"text": "\\section{Principles of Data Reduction}\n\nIn this chapter, we explore how we can use functions of a sample $\\vec{X}$ to make inferences about an unknown parameter (of the distribution of the sample) $\\theta$.\n\n\\begin{definition}[Statistic]\n    A statistic is any function of the data.\n\\end{definition}\n\nA statistic $T$ forms a partition of the sample space $\\X$ according to its image, $\\mathcal{T} = \\{t: \\exists \\vec{x} \\in \\X{} \\text{ s.t. } t = T(\\vec{x})\\}$. In this way a statistic provides a method of data reduction. An experimenter who observes only $T$ will treat as equal two samples $\\vec{x}, \\vec{y}$ for which $T(\\vec{x}) = T(\\vec{y})$.\n\n\\subsection{The Sufficiency Principle}\n\n\\begin{definition}[Sufficient Statistic]\n    A statistic $T(\\vec{X})$ is a \\emph{sufficient statistic} for $\\theta$ if the conditional distribution of the sample $\\vec{X}$ given $T(\\vec{X})$ does not depend on $\\theta$.\n\\end{definition}\n\n\\begin{remark}\n    We ignore the fact that all points have 0 probability for continuous distributions.\n\\end{remark}\n\n\\begin{definition}[The Sufficiency Principle]\n    If $T(\\vec{X})$ is a sufficient statistic for $\\theta$, then any inference about $\\theta$ should depend on the sample $\\vec{X}$ only through $T(\\vec{X})$.\n\\end{definition}\n\n\\begin{theorem}\n    If $p(\\vec{x}\\vert{}\\theta)$ is the pmf/pdf of the sample $\\vec{X}$ and $q(t\\vert{} \\theta)$ is the pmf/pdf of $T(\\vec{X})$, then $T(\\vec{X})$ is a sufficient statistic for $\\theta$ if $\\forall \\vec{x} \\in \\X{}$, $p(\\vec{x}\\vert{}\\theta) / q(t\\vert{}\\theta)$ is constant as  a function of $\\theta$.\n\\end{theorem}\n\n\\begin{remark}[Niceness of the exponential family]\n    It turns out that outside of the exponential family, it is rare to have a sufficient statistic that is of smaller dimension than the size of the sample.\n\\end{remark}\n\n\\begin{theorem}[Factorisation Theorem]\n    Let $f(\\vec{x} \\vert{} \\theta)$ denote the pmf/pdf of a sample $\\vec{X}$. A statistic $T(\\vec{X})$ is a sufficient statistic for $\\theta$ if and only if there exists functions $g(t \\vert{} \\theta)$ and $h(\\vec{x})$ such that $\\forall \\vec{x} \\in \\X{}$, $\\forall \\theta \\in \\Theta$\n    \\[\n        f(\\vec{x} \\vert{} \\theta) = g(T(\\vec{x}) \\vert{} \\theta)h(\\vec{x}).\n    \\]\n\\end{theorem}\n\n\\begin{remark}\n    This theorem shows that the identity is a sufficient statistic. It is straightforward to show from this that any bijection of a sufficient statistic is a sufficient statistic.\n\\end{remark}\n\n\\begin{theorem}\n    Let $X_1, \\dots, X_n$ be iid observations from a pmf/pdf $f(x \\vert{} \\theta)$ from an exponential family \n    \\[\n        f(x|\\vec{\\theta}) = h(x)c(\\vec{\\theta})\\exp\\left( \\sum_{i=1}^k w_i(\\vec{\\theta}) t_i(x) \\right),\n    \\]\n    where $\\vec{\\theta} = (\\theta_1, \\dots, \\theta_d)$, $d \\leq k$. Then $\\vec{T}(\\vec{X})$ defined by\n    \\[\n        T_i(\\vec{X}) = \\sum_{j=1}^k t_i(\\vec{X}_j)\n    \\]\n    is a sufficient statistic for $\\vec{\\theta}$.\n\\end{theorem}\n\n\\begin{definition}[Minimal sufficient statistic]\n    A sufficient statistic $T(\\vec{X})$ is called a \\emph{minimal sufficient statistic} if, for any other sufficient statistic $T'(\\vec{X})$, $T$ is a function of $T'$.\n\\end{definition}\n\n\\begin{remark}\n    By `function of' we mean that if $T'(\\vec{x}) = T'(\\vec{y})$ then $T(\\vec{x}) = T(\\vec{y})$ -- $T$ varies with respect to $X$ only insofar as it varies with $T'$. This means that each tile of the partition of the sample space according to the image of $T'$ is a subset of some tile in the partition according to $T$. This means that minimal sufficient statistics provide the coarsest possible tiling of the sample space and thus are the sufficient statistics that provide the greatest data reduction.\n\\end{remark}\n\n\\begin{theorem}\n    Let $f(\\vec{x} \\vert{} \\theta)$ be the pmf/pdf of a sample $\\vec{X}$. Suppose there exists a function $T(\\vec{X})$ such that $\\forall \\vec{x}, \\vec{y} \\in \\X{}$ the ratio $f(\\vec{x}\\vert{}\\theta)/f(\\vec{y}\\vert{}\\theta)$ is constant as a function of $\\theta$ if an only if $T(\\vec{x}) = T(\\vec{y})$. Then $T(\\vec{X})$ is a minimal sufficient statistic for $\\theta$.\n\\end{theorem}\n\n\\begin{definition}[Necessary Statistic]\n    A statistic is \\emph{necessary} if it can be written as a function of every sufficient statistic.\n\\end{definition}\n\n\\begin{theorem}\n    A statistic is minimal sufficient if and only if it is a necessary and sufficient statistic.\n\\end{theorem}\n\n\\begin{definition}[Ancillary Statistic]\n    A statistic $S(\\vec{X})$ whose distribution does not depend on the parameter $\\theta$ is called an \\emph{ancillary statistic}.\n\\end{definition}\n\n\\begin{definition}[First Order Ancillary]\n    A statistic $V(\\vec{X})$ is \\emph{first order ancillary}  if $\\E{}[V(\\vec{X})]$ is independent of $\\theta$.\n\\end{definition}\n\n\\begin{definition}[Complete Statistic]\n    Let $f(t \\vert{} \\theta)$ be a family of pdfs or pmfs for a statistic $T(\\vec{X})$. The family of probability distributions is called \\emph{complete} if for every (measurable) function $g$\n    \\[\n        \\E{}[g(T)] = 0  \\,\\, \\forall \\theta \\implies \\P{}(g(T) = 0) = 1 \\,\\, \\forall \\theta.\n        \\]\n    Equivalently, $T(\\vec{X})$ is called a $\\emph{complete statistic}$.\n\\end{definition}\n\n(It is left unsaid that the function $g$ must be independent of $\\theta$.)\n\n\\begin{theorem}[Basu's Theorem]\n    If $T(\\vec{X})$ is a complete and minimal sufficient statistic, then $T(\\vec{X})$ is independent of every ancillary statistic.\n\\end{theorem}\n\n\\begin{theorem}[Complete statistics in the exponential family]\n    Let $X_1, \\dots, X_n$ be iid observations from a pmf/pdf $f(x \\vert{} \\theta)$ from an exponential family \n    \\[\n        f(x|\\vec{\\theta}) = h(x)c(\\vec{\\theta})\\exp\\left( \\sum_{i=1}^k w_i(\\vec{\\theta}) t_i(x) \\right),\n    \\]\n    where $\\vec{\\theta} = (\\theta_1, \\dots, \\theta_d)$, $d \\leq k$. Then $\\vec{T}(\\vec{X})$ defined by\n    \\[\n        T_i(\\vec{X}) = \\sum_{j=1}^k t_i(\\vec{X}_j)\n    \\]\n    is complete if $\\{(w_1(\\vec{\\theta}), \\dots, w_n(\\vec{\\theta}))\\}$ contains an open set in $\\R{}^k$.\n\\end{theorem}\n\n\\begin{remark}\n    The open set criteria excludes curved exponential families.\n\\end{remark}\n\n\\begin{theorem}\n    If a minimal sufficient statistic exists, then every complete statistic is minimal sufficient.\n\\end{theorem}\n\n\n    \n\\subsection{The Likelihood Principle}\n\n\\begin{definition}[Likelihood]\n    Let $f(\\vec{x}\\vert{} \\theta)$ denote the pmf/pdf of the sample $\\vec{X}$. Then the \\emph{likelihood function}, given an observation $\\vec{X} = \\vec{x}$, is\n    \\[\n        L(\\theta \\vert{} \\vec{x}) = f(\\vec{x} \\vert{} \\theta)\n    \\]\n    as a function of $\\theta$.\n\\end{definition}\n\n\\begin{definition}[Likelihood Principle]\n    If $\\vec{x}$ and $\\vec{y}$ are two sample points such that $L(\\theta \\vert{} \\vec{x})$ is proportional to $L(\\theta \\vert{} \\vec{y})$, that is, there exists a constant $C(\\vec{x}, \\vec{y})$ such that \n    \\[\n        L(\\theta \\vert{} \\vec{x}) = C(\\vec{x}, \\vec{y})L(\\theta \\vert{} \\vec{y}) \\quad \\forall \\theta,\n    \\]\n    then the conclusions drawn from $\\vec{x}$ and $\\vec{y}$ should be identical.\n\\end{definition}\n\n\\subsection{A Slightly More Formal Construction}\n\\begin{definition}[Experiment]\n    We define an \\emph{experiment} $E$ to be a triple $(\\vec{X}, \\theta, f(\\vec{x}\\vert{}\\theta))$, where $\\vec{X}$ is a random vector with pmf/pdf $f$.\\\\\n    \n    Knowing what experiment $E$ was performed, an experimenter will observer $\\vec{X} = \\vec{x}$. The conclusions they draw about $\\theta$ will be denoted $\\text{Ev}(E, \\vec{x})$, which stands for \\emph{the evidence about $\\theta$ arising from $E$ and $\\vec{x}$}.\n\\end{definition}\n\n\\begin{definition}[Formal Sufficiency Principle]\n    Consider an experiment $E = (\\vec{X}, \\theta, f(\\vec{x}\\vert{}\\theta))$ and suppose that $T(\\vec{X})$ is a sufficient statistic for $\\theta$. If $\\vec{x}$ and $\\vec{y}$ are sample points satisfying $T(\\vec{x}) = T(\\vec{y})$, then $\\text{Ev}(E, \\vec{x}) = \\text{Ev}(E, \\vec{y})$.\n\\end{definition}\n\n\\begin{definition}[Conditionality Principle]\n    Suppose that $E_1 = \\{X_1, \\theta, f_1(x_1\\vert{} \\theta)\\}$ and $E_2 = \\{X_2, \\theta, f_2(x_2\\vert{} \\theta)\\}$ are two experiments, where only the unknown parameter $\\theta$ need be common between the two experiments. Consider the mixed experiment in which the random variable $J$ is observed, where $\\P{}(J = 1) = \\P{}(J = 2) = \\frac12$ (independent of $\\vec{X}_1, \\vec{X}_2, \\theta$), and then the experiment $E_J$ is performed. Formally, the experiment performed is $E^* = (\\vec{X}^*, \\theta, f(\\vec{x}^* \\vert{} \\theta))$, where $\\vec{X}^* = (j, \\vec{X})j$ and $f^*(\\vec{x}^* \\vert{} \\theta) = f^*((j, \\vec{x}_j)\\vert{} \\theta) = \\frac12 f_j(\\vec{x}_j \\vert{}\\theta)$. Then\n    \\[\n        \\text{Ev}(E^*, (j, \\vec{x}_j)) = \\text{Ev}(E_j, \\vec{x_j}).\n    \\]\n    That is, information about $\\theta$ depends only on the experiment run (not on the fact that the particular experiment was chosen).\n\\end{definition}\n\n\\begin{definition}{Formal Likelihood Principle}\n    Suppose that we have two experiments, $E_1 = (\\vec{X}_1, \\theta, f_1(\\vec{x}_1 \\vert{} \\theta))$ and $E_2 = (\\vec{X}_2, \\theta, f_2(\\vec{x}_2 \\vert{} \\theta))$ where the unknown parameter $\\theta$ is the same in both experiments. Suppose that $\\vec{x}_1^*$ and $\\vec{x}_2^*$ are sample points from $E_1$ and $E_2$ respectively, such that \n    \\[\n        L(\\theta \\vert{} \\vec{x}_2^*) = CL(\\theta \\vert{} \\vec{x}_1^*)\n    \\]\n    for all $\\theta$ and for some constant $C(\\vec{x}_1^*, \\vec{x}_2^*)$ that is independent of $\\theta$. Then\n    \\[\n        \\text{Ev}(E_1, \\vec{x}_1^*) = \\text{Ev}(E_2, \\vec{x}_2^*).\n    \\]\n\\end{definition}\n\n\\begin{remark}\n    Note that this is more general from the other likelihood principle since it concerns two experiments (that we can of course set to be equal).\n\\end{remark}\n\n\\begin{corollary}[Likelihood Principle Corollary]\n    If $E = (\\vec{X}, \\theta, f(\\vec{x} \\vert{} \\theta))$ is an experiment then $\\text{Ev}(E, \\vec{x})$ should depend on $E$ and $\\vec{x}$ only through $L(\\theta \\vert{} \\vec{x})$.\n\\end{corollary}\n\n\\begin{theorem}[Birnbaum's Theorem]\n    The Formal Likelihood Principle follows from the Formal Sufficiency Principle and the Conditionality Principle. The converse is also true.\n\\end{theorem}\n\n\\begin{remark}\n    Many common statistical procedures violate the Formal Likelihood Principle -- the topic of the applicability of these principles is not settled. For instance, checking the residuals of a model (to grade the model) violates the Sufficiency Principle. These notions are model dependent, so may not be applicable until \\emph{after} we have decided on a model.\n\\end{remark}\n    \n\\subsection{The Equivariance Principle}\n\n\\begin{definition}[Measurement Equivariance]\n    Inferences should not depend on the measurement scale used.\n\\end{definition}\n\n\\begin{definition}[Formal Invariance]\n    If two inference problems have the same formal structure, in terms of the mathematical model used, then the same inference procedure should be used, regardless of the physical realisation.\n\\end{definition}\n\n\\begin{definition}[Equivariance Principle]\n    If $\\vec{Y} = g(\\vec{X})$ is a change of measurement scale such that the model $\\vec{Y}$ has the same formal structure  as the model $\\vec{X}$, then an inference procedure should be both measurement equivariant and formally invariant.\n\\end{definition}\n\n\\begin{definition}\n    Let $\\mathcal{F} = \\{f(\\vec{x} \\vert{} \\theta): \\theta \\in \\Theta\\}$ be a set of pdfs or pmfs for $\\vec{X}$, and let $\\mathcal{G}$ be  group of transformations on the sample space $\\X{}$. Then $\\mathcal{F}$ is \\emph{invariant under the group} $\\mathcal{G}$ if for every $\\theta \\in \\Theta$ and $g \\in \\mathcal{G}$ there exists a unique $\\theta' \\in \\Theta$ such that $\\vec{Y} = g(\\vec{X})$ has the distribution $f(\\vec{y} \\vert{} \\theta')$ if $\\vec{X}$ has the distribution $f(\\vec{x} \\vert{} \\theta')$.\n\\end{definition}\n\n\n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n\n    \n    \n    \n    \n    ", "meta": {"hexsha": "61f27b47e62f44f2579b9b5720cd17771a15f42d", "size": 11963, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter6/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/chapter6/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/chapter6/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": 54.1312217195, "max_line_length": 683, "alphanum_fraction": 0.6660536655, "num_tokens": 3588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6980327407708696}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 2.1 Using Cadabra's own product rule}\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   # templates for covariant derivatives\n\n   deriv1 := \\nabla_{a}{A?^{b}} -> \\partial_{a}{A?^{b}}\n                                 + \\Gamma^{b}_{c a} A?^{c}.\n\n   deriv2 := \\nabla_{a}{A?_{b}} -> \\partial_{a}{A?_{b}}\n                                 - \\Gamma^{c}_{b a} A?_{c}.\n\n   # create an object\n\n   uv := \\nabla_{a}{v_{b} u^{b}}\n       - \\partial_{a}{v_{b} u^{b}}.      # cdb (ex-0201.101,uv)\n\n   # apply the rules, then simplify\n\n   product_rule   (uv)                   # cdb (ex-0201.102,uv)\n   substitute     (uv,deriv1)            # cdb (ex-0201.103,uv)\n   substitute     (uv,deriv2)            # cdb (ex-0201.104,uv)\n   distribute     (uv)                   # cdb (ex-0201.105,uv)\n   sort_product   (uv)                   # cdb (ex-0201.106,uv)\n   rename_dummies (uv)                   # cdb (ex-0201.107,uv)\n\\end{cadabra}\n\n\\begin{align}\n   \\cdb{ex-0201.101} &= \\Cdb{ex-0201.102}\\\\\n                     &= \\Cdb{ex-0201.103}\\\\\n                     &= \\Cdb{ex-0201.104}\\\\\n                     &= \\Cdb{ex-0201.105}\\\\\n                     &= \\Cdb{ex-0201.106}\\\\\n                     &= \\Cdb{ex-0201.107}\n\\end{align}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 2.1 Using hand crafted product rules}\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   # templates for covariant derivatives\n\n   deriv1 := \\nabla_{a}{A?^{b}} -> \\partial_{a}{A?^{b}}\n                                 + \\Gamma^{b}_{c a} A?^{c}.\n\n   deriv2 := \\nabla_{a}{A?_{b}} -> \\partial_{a}{A?_{b}}\n                                 - \\Gamma^{c}_{b a} A?_{c}.\n\n   # tempaltes for product rules\n\n   deriv3 := \\nabla_{a}{A?_{b} B?^{c}} -> B?^{c} \\nabla_{a}{A?_{b}}\n                                        + A?_{b} \\nabla_{a}{B?^{c}}.\n\n   deriv4 := \\partial_{a}{A?_{b} B?^{c}} -> B?^{c} \\partial_{a}{A?_{b}}\n                                          + A?_{b} \\partial_{a}{B?^{c}}.\n\n   # create an object\n\n   uv := \\nabla_{a}{v_{b} u^{b}}\n       - \\partial_{a}{v_{b} u^{b}}.      # cdb (ex-0201.201,uv)\n\n   # apply the rules, then simplify\n\n   substitute     (uv,deriv3)            # cdb (ex-0201.202,uv)\n   substitute     (uv,deriv4)            # cdb (ex-0201.203,uv)\n   substitute     (uv,deriv1)            # cdb (ex-0201.204,uv)\n   substitute     (uv,deriv2)            # cdb (ex-0201.205,uv)\n   distribute     (uv)                   # cdb (ex-0201.206,uv)\n   sort_product   (uv)                   # cdb (ex-0201.207,uv)\n   rename_dummies (uv)                   # cdb (ex-0201.208,uv)\n\\end{cadabra}\n\n\\begin{align}\n   \\cdb{ex-0201.201} &= \\Cdb{ex-0201.202}\\\\\n                     &= \\Cdb{ex-0201.203}\\\\\n                     &= \\Cdb{ex-0201.204}\\\\\n                     &= \\Cdb{ex-0201.205}\\\\\n                     &= \\Cdb{ex-0201.206}\\\\\n                     &= \\Cdb{ex-0201.207}\\\\\n                     &= \\Cdb{ex-0201.208}\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "d62ce3e0cf4166f33ce8df5421cecd81676b9457", "size": 3436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0201.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-0201.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-0201.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.359223301, "max_line_length": 94, "alphanum_fraction": 0.440628638, "num_tokens": 1155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.6980327356372167}}
{"text": "\\section{Abstract}\n\nA \\emph{Support Vector Machine} is a learning model used both for \\emph{classification} and \\emph{regression} tasks whose goal is to construct a \\emph{maximum margin separator}, i.e., a decision boundary with the largest distance from the nearest training data points.\n\nThe aim of this report is to compare the \\emph{primal}, the \\emph{Wolfe dual}~\\cite{fletcher2009support} and the \\emph{Lagrangian dual} formulations of this model in terms of \\emph{complexity}.\n\nFirstly, a detailed mathematical derivation of the model for all these formulations is given, then three algorithms are described to solve the optimization problem in case of \\emph{primal}, \\emph{Wolfe dual} or \\emph{Lagrangian dual} formulation of the problem, explaining their theoretical properties, i.e., \\emph{convergence rate} and \\emph{complexity}.\n\nFinally, some experiments are shown for \\emph{linearly} and \\emph{nonlinearly} separable generated datasets to compare the performance with different \\emph{hyperparameters} and different \\emph{kernels}, also comparing the \\emph{custom} results with \\emph{liblinear}~\\cite{fan2008liblinear} for the \\emph{primal} formulations, \\emph{libsvm}~\\cite{chang2011libsvm} and \\emph{cvxopt}~\\cite{vandenberghe2010cvxopt} for the \\emph{dual} ones.", "meta": {"hexsha": "0606e7bf74763c0a8438028e3948b209ebb30c49", "size": 1278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/abstract.tex", "max_stars_repo_name": "DonatoMeoli/NumericalOptimization", "max_stars_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-22T09:17:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T18:23:56.000Z", "max_issues_repo_path": "notebooks/optimization/tex/abstract.tex", "max_issues_repo_name": "DonatoMeoli/NumericalOptimization", "max_issues_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-25T08:29:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T09:03:13.000Z", "max_forks_repo_path": "notebooks/optimization/tex/abstract.tex", "max_forks_repo_name": "DonatoMeoli/NumericalOptimization", "max_forks_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-10T13:38:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T20:23:37.000Z", "avg_line_length": 142.0, "max_line_length": 436, "alphanum_fraction": 0.7957746479, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.6980093103929351}}
{"text": "\\lab{Algorithm}{The Knapsack Problem}{The Knapsack Problem}\n\\label{Ch:Knapsack}\n\n\\objective{This section teaches about NP-hard problems using the knapsack problem as an example.}\n\n\\section*{The Knapsack Problem}\n\n%Lab \\ref{Knapsack}\n\nThe two dimensional Knapsack problem is you are given a knapsack that can only hold a certain weight. You have a plethera of items that have value and weight. The goal is to find the combination of items that have the most value with out exceeding the weight.\n\nA three dimensional version the items would have volume and the knapsack can only hold an certain volume as well as weight. \n\nThis problem is has many different applications for disecion making in a wide variety of fields. Two examples are finding the least wasteful way to cut raw materials and the selection of capital investments and financial portfolios.\n\n\\begin{problem}\nWrite a function that solves the Knapsack problem by testing all the combination and choosing the one with the most value that meets the weight constraint. Only test it up to 15 objects.\n\\end{problem}\n\nThis way finds the optimal solution, but there is a problem. Given $n$ objects the number of combinations is $2^n$. The complecity of the problem grows fast. For example, if you had 50 items, it would take more than 10 years to compute the optimal solution. For all the following timing problems let your items have vaules between 1 and 100 and the weights between 1 and $\\frac{Capacity}{10}$.\n\n\\begin{problem}\nTime the Knapsack problem for $11-20$ items with a carrying capacity of $10,000$. Plot the times. What is the complexity of the algorithm for increasing the number of items?\n\\end{problem}\n\n\\begin{problem}\nTime that algorithm for the carrying capacities $10,000-90,000$ every mutiple of $10,000$ with $15$ items. Plot the times. What is the complexity of the algorithm for increasing the weight?\n\\end{problem}\n\n\\section*{NP-Hard}\n\nAny problem that is not polynomial time is know as NP-hard. The Knapsack Problem is a NP-hard problem. Using the branch and bound approach we can find the optimal solution in psuedo-polynomial time.\n\n\\section*{Branch and Bound method}\nWe calculate the optimal solution using only the first i items for weights 0 through W (where W is the max weight the knapsack can hold)\n\nWe do this by intializing 0th row to being empty.\nFor i$>$0 row we go through j (being the weight) from 1 thorugh W. If the ith element's weight is more than j then the optimal combination is the same as it was for i-1. If ith element's weight is less than j, then we compare the combination at i-1 at wieght j to the combination i-1 at the weight j-the ith element weight plus the ith element. Whichever one has a higher value is the optimal combination using the first ith elements less than or equal to the wieght of j. You continue this until you have done all n elements. The combination using n items with a weight of W is guaranteed to be the optimal combination.\n\nThis only does $W*n$ checks, so it is a lot faster. This works by eliminating combinations that could not be the optimal solution\n\n\\begin{problem}\nWrite a function that solves the Knapsack problem using the branch and bound method.\n\\end{problem}\n\n\\begin{problem}\nTime the Knapsack problem for $11-20$ items with a carrying capacity of $10,000$. Plot the times. What is the complexity of the algorithm for increasing the number of items? For the items use the same specifications as in the previous timing problems.\n\\end{problem}\n\n\\begin{problem}\nTime that algorithm for the carrying capacities $10,000-90,000$ every mutiple of $10,000$ with $15$ items. Plot the times. What is the complexity of the algorithm for increasing the weight?\n\\end{problem}\n", "meta": {"hexsha": "52133ecfce228cfb7e9f57814e01d4cadbe6570a", "size": 3709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Knapsack/Knapsack.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/Knapsack/Knapsack.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/Knapsack/Knapsack.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.9811320755, "max_line_length": 620, "alphanum_fraction": 0.7851172823, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8918110375304408, "lm_q1q2_score": 0.697987037391166}}
{"text": "\\section*{Exercises}\n\n\\label{LU}\n\n\\begin{ex} \\label{p7.1}Find an $LU$ factorization of $\\begin{mymatrix}{rrr}\n1 & 2 & 0 \\\\\n2 & 1 & 3 \\\\\n1 & 2 & 3\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{ccc}\n1 & 2 & 0 \\\\\n2 & 1 & 3 \\\\\n1 & 2 & 3\n\\end{mymatrix} = \\begin{mymatrix}{ccc}\n1 & 0 & 0 \\\\\n2 & 1 & 0 \\\\\n1 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 0 \\\\\n0 & -3 & 3 \\\\\n0 & 0 & 3\n\\end{mymatrix}\n\\]\n\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of $\\begin{mymatrix}{rrrr}\n1 & 2 & 3 & 2 \\\\\n1 & 3 & 2 & 1 \\\\\n5 & 0 & 1 & 3\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{cccc}\n1 & 2 & 3 & 2 \\\\\n1 & 3 & 2 & 1 \\\\\n5 & 0 & 1 & 3\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n1 & 1 & 0 \\\\\n5 & -10 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & 2 & 3 & 2 \\\\\n0 & 1 & -1 & -1 \\\\\n0 & 0 & -24 & -17\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix $\\begin{mymatrix}{rrrr}\n1 & -2 & -5 & 0 \\\\\n-2 & 5 & 11 & 3 \\\\\n3 & -6 & -15 & 1\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrrr}\n1 & -2 & -5 & 0 \\\\\n-2 & 5 & 11 & 3 \\\\\n3 & -6 & -15 & 1\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n-2 & 1 & 0 \\\\\n3 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & -2 & -5 & 0 \\\\\n0 & 1 & 1 & 3 \\\\\n0 & 0 & 0 & 1\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix $\\begin{mymatrix}{rrrr}\n1 & -1 & -3 & -1 \\\\\n-1 & 2 & 4 & 3 \\\\\n2 & -3 & -7 & -3\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrrr}\n1 & -1 & -3 & -1 \\\\\n-1 & 2 & 4 & 3 \\\\\n2 & -3 & -7 & -3\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n-1 & 1 & 0 \\\\\n2 & -1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & -1 & -3 & -1 \\\\\n0 & 1 & 1 & 2 \\\\\n0 & 0 & 0 & 1\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix $\\allowbreak \\allowbreak\n\\begin{mymatrix}{rrrr}\n1 & -3 & -4 & -3 \\\\\n-3 & 10 & 10 & 10 \\\\\n1 & -6 & 2 & -5\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n \\begin{mymatrix}{rrrr}\n1 & -3 & -4 & -3 \\\\\n-3 & 10 & 10 & 10 \\\\\n1 & -6 & 2 & -5\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n-3 & 1 & 0 \\\\\n1 & -3 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & -3 & -4 & -3 \\\\\n0 & 1 & -2 & 1 \\\\\n0 & 0 & 0 & 1\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix\n$\\begin{mymatrix}{rrrr}\n1 & 3 & 1 & -1 \\\\\n3 & 10 & 8 & -1 \\\\\n2 & 5 & -3 & -3\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrrr}\n1 & 3 & 1 & -1 \\\\\n3 & 10 & 8 & -1 \\\\\n2 & 5 & -3 & -3\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n3 & 1 & 0 \\\\\n2 & -1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & 3 & 1 & -1 \\\\\n0 & 1 & 5 & 2 \\\\\n0 & 0 & 0 & 1\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix $\\begin{mymatrix}{rrr}\n3 & -2 & 1 \\\\\n9 & -8 & 6 \\\\\n-6 & 2 & 2 \\\\\n3 & 2 & -7\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n3 & -2 & 1 \\\\\n9 & -8 & 6 \\\\\n-6 & 2 & 2 \\\\\n3 & 2 & -7\n\\end{mymatrix} = \\begin{mymatrix}{rrrr}\n1 & 0 & 0 & 0 \\\\\n3 & 1 & 0 & 0 \\\\\n-2 & 1 & 1 & 0 \\\\\n1 & -2 & -2 & 1\n\\end{mymatrix}  \\begin{mymatrix}{rrr}\n3 & -2 & 1 \\\\\n0 & -2 & 3 \\\\\n0 & 0 & 1 \\\\\n0 & 0 & 0\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix $\\begin{mymatrix}{rrr}\n-3 & -1 & 3 \\\\\n9 & 9 & -12 \\\\\n3 & 19 & -16 \\\\\n12 & 40 & -26\n\\end{mymatrix}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find an $LU$ factorization of the matrix $\\begin{mymatrix}{rrr}\n-1 & -3 & -1 \\\\\n1 & 3 & 0 \\\\\n3 & 9 & 0 \\\\\n4 & 12 & 16\n\\end{mymatrix}$.\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n-1 & -3 & -1 \\\\\n1 & 3 & 0 \\\\\n3 & 9 & 0 \\\\\n4 & 12 & 16\n\\end{mymatrix} = \\begin{mymatrix}{rrrr}\n1 & 0 & 0 & 0 \\\\\n-1 & 1 & 0 & 0 \\\\\n-3 & 0 & 1 & 0 \\\\\n-4 & 0 & -4 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n-1 & -3 & -1 \\\\\n0 & 0 & -1 \\\\\n0 & 0 & -3 \\\\\n0 & 0 & 0\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the $LU$ factorization of the coefficient matrix using Dolittle's\nmethod and use it to solve the system of equations.\n\\begin{equation*}\n\\begin{array}{c}\nx+2y=5 \\\\\n2x+3y=6\n\\end{array}\n\\end{equation*}\n\\begin{sol}\nAn $LU$ factorization of the coefficient matrix is\n\\[\n\\begin{mymatrix}{cc}\n1 & 2 \\\\\n2 & 3\n\\end{mymatrix} =  \\begin{mymatrix}{cc}\n1 & 0 \\\\\n2 & 1\n\\end{mymatrix} \\begin{mymatrix}{cc}\n1 & 2 \\\\\n0 & -1\n\\end{mymatrix}\n\\]\nFirst solve\n\\[\n\\begin{mymatrix}{cc}\n1 & 0 \\\\\n2 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nu \\\\\nv\n\\end{mymatrix} =\\begin{mymatrix}{c}\n5 \\\\\n6\n\\end{mymatrix}\n\\]\nwhich gives $\\begin{mymatrix}{c}\nu \\\\\nv\n\\end{mymatrix} =$ $\\begin{mymatrix}{r}\n5 \\\\\n-4\n\\end{mymatrix}$. Then solve\n\\[\n\\begin{mymatrix}{rr}\n1 & 2 \\\\\n0 & -1\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{r}\n5 \\\\\n-4\n\\end{mymatrix}\n\\]\nwhich says that $y=4$ and $x=-3$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the $LU$ factorization of the coefficient matrix using Dolittle's\nmethod and use it to solve the system of equations.\n\\begin{equation*}\n\\begin{array}{c}\nx+2y+z=1 \\\\\ny+3z=2 \\\\\n2x+3y=6\n\\end{array}\n\\end{equation*}\n\\begin{sol}\nAn $LU$ factorization of the coefficient matrix is\n\\[\n\\begin{mymatrix}{rrr}\n1 & 2 & 1 \\\\\n0 & 1 & 3 \\\\\n2 & 3 & 0\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n2 & -1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 1 \\\\\n0 & 1 & 3 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n\\]\nFirst solve\n\\[\n \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n2 & -1 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nu \\\\\nv \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n6\n\\end{mymatrix}\n\\]\nwhich yields $u=1,v=2,w=6$. Next solve\n\\[\n\\begin{mymatrix}{rrr}\n1 & 2 & 1 \\\\\n0 & 1 & 3 \\\\\n0 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n6\n\\end{mymatrix}\n\\]\nThis yields $z=6,y=-16,x=27$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the $LU$ factorization of the coefficient matrix using Dolittle's\nmethod and use it to solve the system of equations.\n\\begin{equation*}\n\\begin{array}{c}\nx+2y+3z=5 \\\\\n2x+3y+z=6 \\\\\nx-y+z=2\n\\end{array}\n\\end{equation*}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the $LU$ factorization of the coefficient matrix using Dolittle's\nmethod and use it to solve the system of equations.\n\\begin{equation*}\n\\begin{array}{c}\nx+2y+3z=5 \\\\\n2x+3y+z=6 \\\\\n3x+5y+4z=11\n\\end{array}\n\\end{equation*}\n\\begin{sol}\nAn $LU$ factorization of the coefficient matrix is\n\\[\n\\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n2 & 3 & 1 \\\\\n3 & 5 & 4\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n2 & 1 & 0 \\\\\n3 & 1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n0 & -1 & -5 \\\\\n0 & 0 & 0\n\\end{mymatrix}\n\\]\nFirst solve\n\\[\n \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n2 & 1 & 0 \\\\\n3 & 1 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nu \\\\\nv \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{c}\n5 \\\\\n6 \\\\\n11\n\\end{mymatrix}\n\\]\nSolution is: $\\begin{mymatrix}{c}\nu \\\\\nv \\\\\nw\n\\end{mymatrix} =$ $\\begin{mymatrix}{c}\n5 \\\\\n-4 \\\\\n0\n\\end{mymatrix}$. Next solve\n\\[\n\\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n0 & -1 & -5 \\\\\n0 & 0 & 0\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n5 \\\\\n-4 \\\\\n0\n\\end{mymatrix}\n\\]\nSolution is: $\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n7t-3 \\\\\n4-5t \\\\\nt\n\\end{mymatrix} ,t\\in \\R$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Is there only one $LU$ factorization for a given matrix? \\textbf{\nHint:\\ }Consider the equation\n\\begin{equation*}\n\\begin{mymatrix}{rr}\n0 & 1 \\\\\n0 & 1\n\\end{mymatrix} =\\begin{mymatrix}{rr}\n1 & 0 \\\\\n1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rr}\n0 & 1 \\\\\n0 & 0\n\\end{mymatrix} .\n\\end{equation*}\nLook for all possible $LU$ factorizations.\n\\begin{sol}\nSometimes there is more than one $LU$ factorization as is the case in this\nexample. The given equation clearly gives an $LU$ factorization. However, it\nappears that the following equation gives another $LU$ factorization.\n\\[\n\\begin{mymatrix}{cc}\n0 & 1 \\\\\n0 & 1\n\\end{mymatrix} =\\begin{mymatrix}{cc}\n1 & 0 \\\\\n0 & 1\n\\end{mymatrix} \\begin{mymatrix}{cc}\n0 & 1 \\\\\n0 & 1\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "5e89fe95ebea1d1daae9cf568d9bccdad2528fc2", "size": 7839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/Matrices-LUFactorizationMultiplier.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/Matrices-LUFactorizationMultiplier.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/Matrices-LUFactorizationMultiplier.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.9308855292, "max_line_length": 81, "alphanum_fraction": 0.5604031126, "num_tokens": 3708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.785308583400079, "lm_q1q2_score": 0.697949916043552}}
{"text": "\\section{Computing Limits: Graphically}\\label{sec:LimitsGraphically}\r\n\r\nIn this section we look at an example to illustrate the concept of a limit \\ifont{graphically}. \r\n\r\nThe graph of a function $f(x)$ is shown below.  We will\r\nanalyze the behaviour of $f(x)$ around $x=-5$, $x=-2$, $x=-1$ and $x=0$, and $x=4$. % and also as $x\\to\\pm\\infty$.\r\n\r\n$$\\includegraphics[width=5.5in]{images/limits-graphically}$$\r\n\r\nObserve that $f(x)$ is indeed a function (it passes the vertical line test). We now analyze the function at each point separately.\r\n\r\n$\\ifont{x=-5:}$ Observe that at $x=-5$ there is no closed circle, thus $f(-5)$ is undefined.\r\nFrom the graph we see that as $x$ gets closer and closer to $-5$ from the left, then $f(x)$ approaches $2$, so\r\n$$\\lim_{x\\to -5^-}f(x)=2.$$\r\nSimilarly, as $x$ gets closer and closer $-5$ from the right, then $f(x)$ approaches $-3$, so\r\n$$\\lim_{x\\to -5^+}f(x)=-3.$$\r\nAs the right-hand limit and left-hand limit are not equal at $-5$, we know that\r\n$$\\lim_{x\\to -5}f(x)\\quad\\mbox{does not exist.}$$\r\n\r\n$\\ifont{x=-2:}$ Observe that at $x=-2$ there is a closed circle at $0$, thus $f(-2)=0$.\r\nFrom the graph we see that as $x$ gets closer and closer to $-2$ from the left, then $f(x)$ approaches $3.5$, so\r\n$$\\lim_{x\\to -2^-}f(x)=3.5.$$\r\nSimilarly, as $x$ gets closer and closer $-2$ from the right, then $f(x)$ again approaches $3.5$, so\r\n$$\\lim_{x\\to -2^+}f(x)=3.5.$$\r\nAs the right-hand limit and left-hand limit are both equal to $3.5$, we know that\r\n$$\\lim_{x\\to -2}f(x)=3.5.$$\r\n\r\nDo not be concerned that the limit does not equal 0. This is a discontinuity, which is completely valid, and will be discussed in a later section.\r\n\r\nWe leave it to the reader to analyze the behaviour of $f(x)$ for $x$ close to $-1$ and $0$.\r\n \r\nSummarizing, we have:\r\n\\hspace{-2.3cm}{\r\n$$\\begin{array}{|c|c|c|c|}\r\n\\hline&~&~&~\\\\\r\nf(-5)~\\mbox{is undefined} & f(-2)=0 & f(-1)=-2 & f(0)=-2  \\\\\r\n~&~&~&~\\\\\r\n\\ds{\\lim_{x\\to -5^-}f(x)=2} & \\ds{\\lim_{x\\to -2^-}f(x)=3.5} & \\ds{\\lim_{x\\to -1^-}f(x)=0} & \\ds{\\lim_{x\\to 0^-}f(x)=-2}  \\\\\r\n~&~&~&~\\\\\r\n\\ds{\\lim_{x\\to -5^+}f(x)=-3} & \\ds{\\lim_{x\\to -2^+}f(x)=3.5} & \\ds{\\lim_{x\\to -1^+}f(x)=-2} & \\ds{\\lim_{x\\to 0^+}f(x)=-2}\\\\\r\n~&~&~&~\\\\\r\n\\ds{\\lim_{x\\to -5}f(x)=\\mbox{DNE}} & \\ds{\\lim_{x\\to -2}f(x)=3.5} & \\ds{\\lim_{x\\to -1}f(x)=\\mbox{DNE}} & \\ds{\\lim_{x\\to 0}f(x)=-2}\\\\\r\n~&~&~&~\\\\\r\n\\hline\r\n\\end{array}$$\r\n}\r\n%\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:LimitsGraphically}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate the expressions by reference to this graph:\r\n$$\\includegraphics[width=3.5in]{images/limit-exercise-graph}$$\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds \\lim_{x\\to 4} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to -3} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0^-} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\t\\item\t$\\ds f(-2)$\r\n\t\\item\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to -2^-} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0} f(x+1)$\r\n\t\\item\t$\\ds f(0)$\r\n\t\\item\t$\\ds \\lim_{x\\to 1^-} f(x-4)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0^+} f(x-2)$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$8$\r\n\t\\item\t$6$\r\n\t\\item\tdne\r\n\t\\item\t$-2$\r\n\t\\item\t$-1$\r\n\t\\item\t$8$\r\n\t\\item\t$7$\r\n\t\\item\t$6$\r\n\t\\item\t$3$\r\n\t\\item\t$-3/2$\r\n\t\\item\t$6$\r\n\t\\item\t$2$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "fe6763c4da82a8e0bbcb65e7abdf401a097dbc93", "size": 3455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-3-limits-graphically.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-3-limits-graphically.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-3-limits-graphically.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": 35.9895833333, "max_line_length": 147, "alphanum_fraction": 0.5858176556, "num_tokens": 1423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6979390545496509}}
{"text": "\\documentclass[cyan,normal,en]{elegantnote}\n\n\\title{Computer Graphic Note}\n\\author{Jiechang Shi}\n\\version{1.1}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Class 1: Overview}\n\\begin{enumerate}\n\t\\item Frame Buffer\n\t\\begin{itemize}\n\t\t\\item Pixel: One element of a frame buffer\n\t\t\\item Pixel depth: Number of bytes per-pixel in the buffer\n\t\t\\item Resolution: Width $\\times$ Height\n\t\t\\item Buffer size: Total memory allocated for frame buffer\n\t\t\\item \\textbf{Exam Question}: Given Resolution and Pixel depth, Asked Buffer size\n\t\t\\item Z Value: For solving the hidden-surface removal(HSR) problem\n\t\\end{itemize}\n\\end{enumerate}\n\\newpage\n\\section{Class 2,3: Rasterization}\n\\begin{enumerate}\n\t\\item For each pixel on screen, the sample point of that pixel is the center point of that pixel, which have \\textbf{integer} coordinates. For examples, $(3,2)$.\n\t\\item A simple problem: Rasterizing Lines \\\\\n\t\\textbf{Program Description}: Given two endpoints, $P = (x_0,y_0)$ , $R=(x_1,y_1)$ find the pixels that make up the line. \\\\\n\t\\textbf{Note that}: Lines are infinitely thin so they rarely fall on pixel sample point.\\\\\n\t\\textbf{A Feasible Description}: Rasterize lines as \\textbf{closest} pixels to actual lines, with 2 requirement\n\t\\begin{itemize}\n\t\t\\item No Gap\n\t\t\\item Minimize error(distance to true line)\n\t\\end{itemize}\n\t\\textbf{To make this question simplify}: Only consider situation that $|x_1 - x_0| \\geq |y_1 - y_0| \\geq 0 \\land |x_1-x_0| \\neq 0$, which means the $-1 \\leq slope \\leq 1$. Otherwise we just exchange $x$ and $y$. \\\\\n\t\\textbf{A basic Algorithm}: $k=\\frac{y_1-y_0}{x_1-x_0}$, $d=y_0-kx_0$, for each $x_0 \\leq x \\leq x_1$, $y=ROUND(kx+d)$. This method by brute force is inefficient because of the multiplication and the function $ROUND()$.\\\\\n\t\\textbf{Basic Incremental Algorithm}: for each $x_0 \\leq x_i < x_{i+1} \\leq x_1$, $y_{i+1} = y_i +k$, However, the successsive addition of a real number can lead to a \\textbf{cumulative error buildup}!\\\\\n\t\\textbf{Midpoint Line Algorithm}: \n\t\\begin{itemize}\n\t\t\\item For $0 \\leq k \\leq 1$\n\t\t\\item For one approximate point $P=(x,y)$, we only have 2 choices for the next point $E=(x+1,y)$ and $NE=(x+1,y+1)$, we should choose the one which is closer to $k(x+1)+d$\n\t\t\\item Calculate the middle point $M=(x+1,y+\\frac{1}{2})$\n\t\t\\item If the \\textbf{Intersection point} $Q$ is below $M$, take $E$ as next, otherwise take $NE$ as next.\n\t\t\\item Note that: we consider this equation:\n\t\t$$ f(x,y)=ax+by+c=(y_1-y_0)x - (x_1-x_0)y + (x_1y_0-y_1x_0)$$\n\t\tWe assume $a>0$\n\t\t\\item For a point $(x,y)$\\\\\n\t\tif $f(x,y)=0$, $(x,y)$ lies on the line.\\\\\n\t\tif $f(x,y)<0$, $(x,y)$ lies upon the line.\\\\\n\t\tif $f(x,y)>0$, $(x,y)$ lies below the line.\n\t\t\\item So we have to test $f(M)=a(x+1)+b(y+\\frac{1}{2})+c=f(Former)+a+\\frac{b}{2}$\n\t\t\\item Assum $a>0$, if $f(M) > 0$ choose $NE$ otherwise choose $E$\n\t\t\\item Update $f(Former)$:\\\\\n\t\tIf we choose $E$, $f(Former)=f(Former)+a$\\\\\n\t\tIf we choose $NE$, $f(Former)=f(Former)+a+b$\\\\\n\t\tNote that:$a$ and $b$ are \\textbf{constant integer}, so here is no \\textbf{cumulative error issuse}\n\t\\end{itemize}\n\t\\item A harder problem: Triangles Rasterization\\\\\n\t\\textbf{Why Triangle}:\n\t\\begin{itemize}\n\t\t\\item Triangles (\\textit{tris}) are a simple explicit 3D surface representation.\n\t\t\\item Convex and concave polygons (\\textit{polys}) can be decomposed into triangles.\n\t\t\\item Tris are planar and unambiguously defined by three vertex(\\textit{verts}) coordinates (\\textit{coords}).\n\t\\end{itemize}\n\t\\textbf{Definition}: Find and draw \\textbf{pixel} samples \\textbf{inside} \\textit{tri} edges and interpolate parameters defined at \\textit{verts}\n\t\\item \\textbf{Rasterizxation and Hidden Surface Removal(HSR) Algorithm Classes}:\n\t\\begin{itemize}\n\t\t\\item Image order rasterization: ray tracing/ ray casting \\\\\n\t\t\\underline{traverse} pixel, process each in world-space\\\\\n\t\t\\underline{transform} rays from image-space to world-space\n\t\t\\item Object order rasterization: scan-line / LEE \\\\\n\t\t\\underline{traverse} triangles, process each in image-space\\\\\n\t\t\\underline{transform} objects from model-space to image-space\n\t\\end{itemize}\n\t\\item \\textbf{LEE Linear Expression Evaluation Algorithm}:\n\t\\begin{itemize}\n\t\t\\item We already discussed in \\textit{Midpoint Line Algorithm} that how to determine a point is on the left(up) or right(below) the line, just \\textit{a quick review here}:\\\\\n\t\tAssume the lien have a positive $slope$\\\\\n\t\tFor an Edge Equation $E$, for point $(x,y)$: $E(x,y)=dY(x-X)-dX(y-Y)$\\\\\n\t\tif $E(x,y)=0$, $(x,y)$ lies on the line.\\\\\n\t\tif $E(x,y)<0$, $(x,y)$ lies right(below) the line.\\\\\n\t\tif $E(x,y)>0$, $(x,y)$ lies left(up) the line.\n\t\t\\item For \\textbf{Rasterization}:\\\\\n\t\tCompute LEE result for all three edges.\\\\\n\t\tPixels with \\textbf{consistent sign} for all three edges are inside the \\textit{tri}.\\\\\n\t\tInclude \\textbf{edge pixels} on left or right edges.\n\t\t\\item LEE need to check every pixel in the bounding box.\n\t\t\\item LEE is very good in parallel(SIMD) system.\n\t\t\\item Furthermore: Given 3 random \\textit{verts} how to find CW edge cycle\\\\\n\t\tDetermine L/R and Top/Bot edges for edge-pixel ownership\n\t\\end{itemize}\n\t\\item \\textbf{Scan Line Rasterizer}:\n\t\\begin{itemize}\n\t\t\\item Sort vets by Y\n\t\t\\item Setup edge DDAs for edges\n\t\t\\item Sort edges by L or R(The long edge on left or right)\n\t\t\\item Start from Top Vertice, and switch DDA when hit the middle vertice.\t\t\n\t\\end{itemize}\n\t\\item \\textbf{Interpolate Z}:\\\\\n\tA general 3D plane equation has 4 terms: $Ax+By+Cz+D=0$\\\\\n\t$(A,B,C)$ is the normal of that plane, so $(X,Y,Z)_0 \\times (X,Y,Z)_1 = (A,B,C)$\\\\\n\tThen plug any vertex coord into equation and solve for $D$.\\\\\n\tGiven $(A,B,C,D)$ and any point $(x,y)$ can solve $z$\n\t\\item \\textbf{Used $Z$-buffer to remove hidden surfaces}\\\\\n\tInitial $Z$-buffer to MAXINT at the begining of every frame\\\\\n\tInterpolate vertex $Z$ values to get $Z_{pix}$\\\\\n\tOnly write new pixel to the buffer if $Z_{pix}<Z_{buffer}$\\\\\n\tNotice that $Z$ should always \\textbf{bigger or equal to zero!}\n\t\\item Hidden Line Removal(HLR):\\\\\n\tSimple z-buffer does not work when the render only draws edge(outlines of polygons).\\\\\n\tNeed edge-crossing and object sorting methods.\n\t\\item \\textbf{Painter's Algorithm}: render in order front to back\\\\\n\tA object is in front of another object means:\\\\\n\tZ of all verts of one object is less than the other.\\\\\n\tThis algorithm not work if Z-sort is ambiguous.\n\t\\item \\textbf{Warnock Algorithm}:\\\\\n\tSubdivide screen untril a leaf region has a simple front/back relationship.\\\\\n\tLeaf regions have one or zero surfaces visible, and the smallest region is usually a pixel\\\\\n\tUsually use quad tree subdivision\n\t\\item \\textbf{BSP-Tree}:\\\\\n\tView-Independent binary tree(pre-calculated) allows a view-dependent front-to-back or back-to-front traversal of surfaces.\\\\\n\tUse Painter Algorithm to do back-to-front traversal.\\\\\n\tUseful for \\textbf{transparency} - full depth-sort of all surface.\n\t\\item \\textbf{Culling}:\n\t\\begin{itemize}\n\t\t\\item Culling with portals: pre-compute the invisible part.\n\t\t\\item Culling by View Frustum: Skip a triangle iff all its vertices are beyond \\textbf{the same screen edge}!\\\\\n\t\t\\textbf{Pitfall:} If the vertices are beyond different edge, some part of the \\textit{tri} might still in the screen. Image a giant \\textit{tri} that cover the whole screen.\n\t\t\\item Backface Culling: For \\textbf{closed(water-tight)} objects, surfaces with \\textbf{oriented-normals facing away} from the camera are never visible.\\\\\n\t\t\\textbf{Pitfall}: BF Culling only work for water-tight object!\n\t\t\\item Frustum: Only visible triangles are drawn into the frame buffer.\n\t\\end{itemize}\n\\end{enumerate}\n\\newpage\n\\section{Class 4,5,6,7:Transformations}\n\\begin{itemize}\n\t\\item Linear transformations (\\textit{Xforms}) define a mapping of coordinates (\\textit{coords}) in one coordinate frame to another.\n\t$$V_b=X_{ba}V_a$$\n\t\\item \\textbf{Homogeneous Vector} ($V$) is $4\\times 1$ columns $(x,y,z,w)^T$\n\t\\item \\textbf{Homogeneous Transforms} ($X$) is $4 \\times 4$ matrix\n\t\\item From Homogeneous Vector to 3D Vector:\n\t$$x=\\frac{x}{w} , y=\\frac{y}{w},z=\\frac{z}{w}$$\n\t\\item \\textbf{Why} we use Homogeneous Vector?\\\\\n\tWe want to uniform the transform matrix including translation, scaling, rotation in the same form of matrix.\n\\end{itemize}\n\\subsection{Transformation Matrix}\n\\begin{enumerate}\n\t\\item \\textbf{Translation}:\n\t$$T(t_x,t_y,t_z)\\Rightarrow \n\t\\begin{bmatrix}\n\t1 & 0 & 0 & t_x \\\\\n\t0 & 1 & 0 & t_y \\\\\n\t0 & 0 & 1 & t_z \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix},\n\tT^{-1}(t_x,t_y,t_z)=T(-t_x,-t_y,-t_z)\n\t$$\n\t\\item \\textbf{Scaling}:\n\t$$S(s_x,s_y,s_z)\\Rightarrow \n\t\\begin{bmatrix}\n\ts_x & 0 & 0 & 0 \\\\\n\t0 & s_y & 0 & 0 \\\\\n\t0 & 0 & s_z & 0 \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix},\n\tS^{-1}(s_x,s_y,s_z)=S(\\frac{1}{s_x},\\frac{1}{s_y},\\frac{1}{s_z})\n\t$$\n\t\\item \\textbf{Rotation, CCW}:\n\t$$R_x(\\theta)\\Rightarrow \n\t\\begin{bmatrix}\n\t1 & 0 & 0 & 0 \\\\\n\t0 & cos\\theta & -sin\\theta & 0 \\\\\n\t0 & sin\\theta & cos\\theta & 0 \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix},\n\tR^{-1}_x(\\theta)=R^T_x(\\theta)\n\t$$\n\t$$R_y(\\theta)\\Rightarrow \n\t\\begin{bmatrix}\n\tcos\\theta & 0 & sin\\theta & 0 \\\\\n\t0 & 1 & 0 & 0 \\\\\n\t-sin\\theta & 0 & cos\\theta & 0 \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix},\n\tR^{-1}_y(\\theta)=R^T_y(\\theta)\n\t$$\n\t$$R_z(\\theta)\\Rightarrow \n\t\\begin{bmatrix}\n\tcos\\theta & -sin\\theta & 0 & 0 \\\\\n\tsin\\theta & cos\\theta & 0 & 0 \\\\\n\t0 & 0 & 1 & 0 \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix},\n\tR^{-1}_z(\\theta)=R^T_z(\\theta)\n\t$$\n\t\\item Pitfall: \\underline{commutative} property is for S,R only.\\\\\n\tHere assume \\textbf{uniform scaling} in all dimensions. \\\\\n\tIf S is not an uniform scaling matrix. S,R don't have commutative property.\n\\end{enumerate}\n\\subsection{Spaces Transformation}\n\\begin{enumerate}\n\t\\item \\textbf{NDC to Output Device}\n\t$$X_{sp}\\Rightarrow \n\t\\begin{bmatrix}\n\t\\frac{xs}{2} & 0 & 0 & \\frac{xs}{2} \\\\\n\t0 & -\\frac{ys}{2} & 0 & \\frac{ys}{2} \\\\\n\t0 & 0 & MAXINT & 0 \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix}\n\t$$\n\tNote that:\\\\\n\tOutput Device is \\textbf{RH coords} and origin in \\textbf{upper left}.$X\\in [0,xs), Y\\in [0,ys), Z\\in [0,MAXINT]$\\\\\n\tNDC is \\textbf{LH coords} and origin at screen center. $X,Y \\in [-1,1],Z \\in[0,1]$\n\t\\item \\textbf{Perspective Projection}\n\t$$X_{pi}\\Rightarrow \n\t\\begin{bmatrix}\n\t1 & 0 & 0 & 0 \\\\\n\t0 & 1 & 0 & 0 \\\\\n\t0 & 0 & \\frac{1}{d} & 0 \\\\\n\t0 & 0 & \\frac{1}{d} & 1\n\t\\end{bmatrix}\n\t$$\n\t\\textbf{What} is $d$ And \\textbf{Why} there are two \\textbf{$\\frac{1}{d}$}?\n\t\\begin{itemize}\n\t\t\\item Assume camera is on $(0,0,-d)$, perspective(also image) plane is $z=0$, a object in world space is $(X,Y,Z)$\n\t\t\\item Defined FOV(field of view) as the angle the camera can see.\n\t\t\\item Note: $X\\in [-1,1]$, so the distant($d$) from Forcus point to view plane can be calculate by this equation:\n\t\t$$\\frac{1}{d}=tan(\\frac{FOV}{2})$$\n\t\t\\item Futher More: The object project to view plane can be calculate by these equations:\n\t\t$$\\frac{X}{Z+d}=\\frac{x}{d} \\Rightarrow x=\\frac{X}{\\frac{Z}{d}+1}$$\n\t\t$$\\frac{Y}{Z+d}=\\frac{y}{d} \\Rightarrow y=\\frac{Y}{\\frac{Z}{d}+1}$$\n\t\t$$\\frac{Z}{Z+d}=\\frac{z}{d} \\Rightarrow z=\\frac{Z}{\\frac{Z}{d}+1}$$\n\t\t$$(x,y,z)=(\\frac{X}{\\frac{Z}{d}+1},\\frac{Y}{\\frac{Z}{d}+1},\\frac{Z}{\\frac{Z}{d}+1})$$\n\t\t\\item Write this 3D vector to Homogeneous Vector:\n\t\t$$(x,y,z,w)=(X,Y,Z,\\frac{Z}{d}+1)$$\n\t\t\\item Futher: We forcus on the \\textbf{range} of Z now is $z\\in (-\\infty,d)$.\\\\\n\t\tBut in NDC we hope $z \\in [0,1)$ So:\\\\\n\t\tWe delete all vector that $Z<0$, because they cannot project to the view plane.\\\\\n\t\tFor $z>=0$, we define $z'=\\frac{z}{d}$\n\t\t\\item $(x,y,z',w)=(X,Y,\\frac{Z}{d},\\frac{Z}{d}+1)=X_{pi}*(X,Y,Z,1)$\n\t\\end{itemize}\n\t\\textbf{Pitfall}: \\textbf{Do Z interpolation in Perspective Plane!}\\\\\n\t\\textbf{Why} we need the farest plane?\\\\\n\tAsymptotic curve of $Z$ $vs.$ $z$, that z increase slower when Z is large.\\\\\n\tIt might map different $Z$ to the same $z$\n\\end{enumerate}\n\\subsection{Camera Matrix}\n\\begin{enumerate}\n\t\\item Assume camera position is $c$, camera look-at point is $l$, here $c$ and $l$ are both in world coordinate. And the world up vector is $\\vec{up}$\n\t\\item Camera Z-axis \\textbf{in world coordinate} is $$\\vec{Z}=\\frac{\\vec{cl}}{||\\vec{cl}||}$$\n\t\\item Camera Y-axis \\textbf{in world coordinate} is the orthogonal(vertical) part of world-up vector to Z-axis which is $$\\vec{up'}=\\vec{up}-(\\vec{up}\\cdot \\vec{Z})\\vec{Z}$$\n\t$$\\vec{Y}=\\frac{\\vec{up'}}{||\\vec{up'}||}$$\n\t\\item Camera X-axis \\textbf{in world coordinate} is orthogonal to both Y and Z axises. So:\n\t$$\\vec{X}=\\vec{Y}\\times\\vec{Z}$$\n\t\\item Build the $X_{wi}$ from camera space to world space:\\\\\n\tX-axis vector $[1,0,0]$ in camera space should be $\\vec{X}$ in world space, also for Y,Z-axis vectors, So:\n\t$$X_{wi}\\Rightarrow \n\t\\begin{bmatrix}\n\tX_x & Y_x & Z_x & 0 \\\\\n\tX_y & Y_y & Z_y & 0 \\\\\n\tX_z & Y_z & Z_z & 0 \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix}\n\t$$\n\t\\item Also we need to add the translation of the camera to the Matrix:\n\t$$X_{wi}\\Rightarrow \n\t\\begin{bmatrix}\n\tX_x & Y_x & Z_x & c_x \\\\\n\tX_y & Y_y & Z_y & c_y \\\\\n\tX_z & Y_z & Z_z & c_z \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix}\n\t$$\n\t\\item Now we can get the inverst matrix $X_{iw}$:\n\t$$X_{iw}\\Rightarrow \n\t\\begin{bmatrix}\n\tX_x & X_y & X_z & -X\\cdot c \\\\\n\tY_x & Y_y & Y_z & -Y\\cdot c \\\\\n\tZ_x & Z_y & Z_z & -Z\\cdot c \\\\\n\t0 & 0 & 0 & 1\n\t\\end{bmatrix}\n\t$$\n\t\\item In this proof we know that: If we know the X,Y,Z-axis in world coordinate for a specific space, we can easily build and inverst the translation from or to that space.\\\\\n\tThis method can also be used to \\textbf{proof the general rotation matrix}. \n\t\\item Orbit a Model about a Point\\\\\n\tThe idea is the same as place camera.\\\\\n\tNeed to care about \\textbf{which space} you current in!\n\\end{enumerate}\n\\newpage\n\n\\section{Class8-10 Illumination and Shading}\n\\begin{enumerate}\n\t\\item Global vs. Local Illumination\\\\\n\tGlobal: Models indirect illumination and occlusions\n\tLocal: Only models direct illumination\n\t\\item Irradiance\n\t$$E=\\int_{\\Omega} I(x,\\omega) cos \\theta dx$$\n\tNote: $I(x,\\omega)$ is the light intensity arriving from all directions and entering the hemisphere $\\Omega$ over unit serface area.\\\\\n\tAlso we only care the vertical(normal) part of the light, we dismiss all lights parallel to the surface by using $\\cos \\theta$\n\t\\item Simplified lighting:\\\\\n\tAssume all lights are distant-point light.\n\t\\begin{itemize}\n\t\t\\item Source have \\textbf{uniform} intensity distribution\n\t\t\\item Neglect distance fallout\n\t\t\\item Direction to source is constant within scene\n\t\t\\item Using 2 parameters to define a light:\\\\\n\t\t$direction(x,y,z)$ vector from surface to light source\\\\\n\t\t$intensity(r,g,b)$ of the light\n\t\\end{itemize}\n\t\\item specular reflection and diffuse reflection\n\t\\begin{itemize}\n\t\t\\item Color shift by attenuation of RPG components for all reflection\n\t\t\\item Specular Reflection Model(View-Dependent):\\\\\n\t\t$$L_j(V) = L_e \\cdot K_s \\cdot (V\\cdot R)^{spec}$$\n\t\t$$R=2(N\\cdot L)N-L$$\n\t\tNote: $V$ and $R$ should be normalized.\\\\\n\t\tDirection: Reflection occurs mainly in the \"mirror\" R direction, but there is some spread in similar directions $V$.\\\\\n\t\t$spec$ controls the distribution of intensity about R. Higher value of $spec$ make the surface smoother\\\\\n\t\t$K_s$ controls the color attenuation of Surface.\n\t\t\\item Diffuse Reflection Models(View-Independent):\\\\\n\t\t$$L_j = L_e \\cdot K_d (L\\cdot N)$$\n\t\tDirection: All \\textbf{output} directions are the same. But we only care vertical \\textbf{input} light.\\\\\n\t\t$L$ and $N$ should be normalized.\\\\\n\t\t$K_d$ is the surtface attenuation component.\n\t\t\\item Ambient Light\\\\\n\t\t$$L_j = L_a \\cdot K_a$$\n\t\tDirection: All input and output directions are the same.\\\\\n\t\tOnly one ambient light is needed and allowed.\n\t\t\\item Complete Shading Equation:\n\t\t$$Color=(K_s\\sum{ L_e \\cdot (V\\cdot R)^{spec}}) + (K_d\\sum{ L_e \\cdot (L\\cdot N)}) + (L_a \\cdot K_a)$$\t\n\t\\end{itemize}\n\t\\item Detail about HW4(Lighting Implementation)\n\t\\begin{itemize}\n\t\t\\item $\\vec{L}$ denotes the direction to a infinity-far point-light source\n\t\t\\item $\\vec{E}$ denotes the camera direction. If camera is far away, $\\vec{E}$ is constant(In HW4.)\n\t\t\\item $\\vec{N}$ is specified at triangle vertices.\n\t\t\\item $\\vec{R}$ must be computed for each lighting calculation (at \\textbf{a point}).\\\\\n\t\tCalculation of $\\vec{R}$:\\\\\n\t\t$$\\vec{R}=2(\\vec{N}\\cdot \\vec{L})\\vec{N}-\\vec{L}$$\\\\\n\t\tAvoiding sqrt-root in this calculation\n\t\t\\item Choosing a Shading Space: Wee need all $\\vec{L},\\vec{E},\\vec{N},\\vec{R}$ in some affine(pre-perspective) space \\\\\n\t\tSuggest use \\textbf{Image Space} for HW4. \\\\\n\t\t\\textbf{Model space} is also a reasonable choice since Normal vectors are already in that space. This is most \\textbf{efficient}!\n\t\t\\item \\textbf{Image Space Lighting (ISL)}\\\\\n\t\tCreate a Transformation stack from model space to image space.\\\\\n\t\tNeed to \\textbf{normalized the Scale and delete translation} for each matrix, \\textbf{only maintain the rotation}, before push into this stack!\n\t\t\\item \\textbf{Check} the sign of \\textbf{$\\vec{N}\\cdot\\vec{E}$} and \\textbf{$\\vec{N}\\cdot\\vec{L}$}:\\\\\n\t\tBoth positive: Compute lighting model.\\\\\n\t\tBoth negative: \\textbf{Flip normal($\\vec{N}$)} and compute lighting model.\\\\\n\t\tDifferent sign: Skip it.\n\t\t\\item \\textbf{Check} the sign of \\textbf{$\\vec{R}\\cdot\\vec{E}$}: If negative, set to 0.\n\t\t\\item \\textbf{Check} color overflow($>1.0$): Set to 1.\n\t\t\\item \\textbf{Compute Color} at all pixels:\\\\\n\t\t\\textbf{Per Face} - flat shading\\\\\n\t\t\\textbf{Per Vertex} - interpolate vertex colors, Gouraud Shading(specular highlights are undersampled, aliased).\\\\\n\t\t\\textbf{Per Pixel} - interpolate normals, Phong Shading (Expensive computation, but better sampling)\\\\\n\t\tSet \\textbf{Shading Modes Parameter} for different lighting calculation.\n\t\t\\item \\textbf{Pitfall} in \\textbf{Phong} Interpolation:\\\\\n\t\tNeed to \\textbf{normalize} the interpolation normal vector.\n\t\\end{itemize}\n\\end{enumerate}\n\\subsection{Class10: Something More About Shading}\n\\begin{enumerate}\n\t\\item Non-Uniform Scaling: \\\\\n\t\\textbf{A non-uniform scaling alters the relationship between the surface orientation and the Normal Vector.}\\\\\n\tSo we \\textbf{cannot} use the same matrix M for transformation of the Normals and the vertex coordinates.\\\\\n\tWe can fix this by using a different transformation $Q=f(M)$ for transforming the Normals.\n\t\\item How to create a matrix for Normals:\\\\\n\tIn HW4, We create a matrix \\textbf{dismiss all} scale matrix.\\\\\n\tFor Detail:\\\\\n\tAs the definition of Normals: \n\t$$\\vec{N}^T\\cdot\\vec{P}=0$$\n\tAfter include the transform matrix: \n\t$$(Q\\vec{N})^T\\cdot(M\\vec{P})=0$$\n\tBy Definition of Matrix Multiplyer:\n\t$$\\vec{N}^T \\cdot Q^T \\cdot M \\cdot \\vec{P}=0$$\n\tSince we already know $\\vec{N}^T\\cdot\\vec{P}=0$ we only need the inner part equal to identity matrix:\n\t$$Q^T \\cdot M= I,Q=(M^{-1})^T$$\n\tNote that: If we only used uniform scaling: $S=I$ after normalization.\\\\\n\tIf we compute $Q$ for each $M$ pushed on the $X_{im}$ transform stack, the resulting $X_n$ stack has $Q$ and therefore allows non-uniform scaling.\t\n\t\\item Model Space Lighting(MSL): \\\\\n\tOnly need to transform Global lighting parameters once per models.\\\\\n\tAlso need to transform Eye/camera direction into model space.\n\\end{enumerate}\n\\newpage\n\n\\section{Class 11-13: Texture Mapping}\n\\subsection{Screen-Space Parameter Interpolation}\n\\begin{enumerate}\n\t\\item In Z-buffer interpolation, we know that linear interpolation for $z$ is \\textbf{wrong in image space}, we need to interpolate in \\textbf{perspective space}.\n\t\\item Accurate interpolation of RGB color or Normal vectors should also take perspective into account.\\\\\n\tBut we can ignore the color and normal interpolation error.\n\t\\item Interpolation for \\textbf{Texture Function}: checkerboard Example: Using Linear Interpolation for $u\\&v$ is also wrong!\n\t\\item How to compute perspective-correct interpolation of $u,v$ at each pixel.\n\t\\begin{itemize}\n\t\t\\item For each parameter $P$, we used $P^s$ to denote the value in perspective space.\n\t\t\\item Note that: For Z interpolation $V_z^s=\\frac{V_z}{\\frac{V_z}{d}+1}=\\frac{V_z \\cdot d}{V_z+d}$\n\t\t\\item Rescale $V_z^s$ to $V_z^s \\in [0,Z_{max}]$ \n\t\t$$V_z^s=\\frac{V_z \\cdot d}{V_z+d} \\cdot (\\frac{Z_{max}}{d})=\\frac{V_z \\cdot Z_{max}}{V_z+d}$$\n\t\t\\item We can also get the invert equation:\n\t\t$$V_z=\\frac{V_z^s \\cdot d}{Z_{max} - V_z^s}$$\n\t\t\\item For parameter from image space to perspective space:\n\t\t$$P^s=\\frac{P}{\\frac{V_z}{d}+1}=\\frac{Pd}{V_z+d}$$\n\t\t\\item Also we can get inver equation:\n\t\t$$P=\\frac{P^s(V_z+d)}{d}$$\n\t\t\\item We don't have $V_z$ but we already calculated $V_z^s$ in HW2, so we can used that:\n\t\t$$P^s=\\frac{P}{(\\frac{V_z^s}{Z_{max} - V_z^s}+1)}$$\n\t\t$$P=P^s \\cdot \\frac{V_z^s}{Z_{max} - V_z^s}+1$$\n\t\t\\item Note that we only have $V_z^s$ and $Z_{max}$ in this equation that we already know the value, we don't need to care $d$ and some other parameter.\n\t\t\\item We used $V_z' = \\frac{V_z^s}{Z_{max} - V_z^s}$ to simplify the equation:\n\t\t$$P^s=\\frac{P}{V_z' +1}$$\n\t\t$$P=P^s \\cdot(V_z'+1)$$\n\t\\end{itemize}\n\t\\item The Step for Parameter interpolation:\\\\\n\tGet $V_z^p$ for each vertex.\\\\\n\tTransform $P$ to perspective space $P^s$ for each vertex.\\\\\n\tInterpolate $V_z^p$ for each pixel.\\\\\n\tInterpolate $P^s$ for each pixel. \\\\\n\tTransform $P^z$ back to $P$ by using $V_z^p$ for each pixel.\n\\end{enumerate}\n\\newpage\n\\subsection{Texture}\n\\begin{enumerate}\n\t\\item Scale $u,v$ to Texture Image Size:\\\\\n\t$(u,v)$ coords range over $[0,1]$\\\\\n\t2D Image is a pixel array of $xs-1,ys-1$\\\\\n\tBut $u*(xs-1)$ might not be Integer so we need to interpolate the color for non-Integer $(u,v)$ coordinate from nearest 4 Integer point.\n\t$$Color(p)=(1-s)(1-t)A+s(1-t)B+stC+(1-s)tD$$\n\t\\item For Phong Shading, using texture function $f(u,v)$ to replace $k_d$ and $k_a$\n\t\\item For Gouraud Shading, using $f(u,v)$ to replace all $k_s$, $k_d$ and $k_a$\n\t\\item Procedural Texture\n\t\\item Bump Texture:\n\t\\begin{itemize}\n\t\t\\item Alter normals at each pixel to create bump.\n\t\t\\item Normal Perturbation($\\vec{P}$): $N'=N+P$, $\\vec{P}$ should be in the same space as N. But $\\vec{P}$ should not be in model space.\n\t\t\\item Better spaces for $\\vec{P}$ are Surface Coordinates, Tangent Space.\n\t\\end{itemize}\n\t\\item Surface Coordinates:\n\t\\item Normal Space encodes the surface normal rather than perturbation.\n\t\\item Noise Texture:\n\t\\begin{itemize}\n\t\t\\item Perlin Noise:(Ref(Chinese): \\href{https://www.cnblogs.com/leoin2012/p/7218033.html}{https://www.cnblogs.com/leoin2012/p/7218033.html}\n\t\t\\item Input: $(x,y,z)$ for 3D and $(u,v)$ in 2D\n\t\t\\item Output: double value between 0 and 1\n\t\t\\item We have 2 Pseudo Random Grid for each Integer Point(x,y,z are integers):\n\t\t\\begin{itemize}\n\t\t\t\\item Noise Matrix($d$): The color of Point for noise\n\t\t\t\\item Gradient Matrix($g$): A random unit vector for each Point\n\t\t\\end{itemize}\n\t\t\\item For each input vector$(u,v)$, if $(u,v)$ isn't Integer, we found 4-corners Integer Point: $(i,j),(i+1,j),(i,j+1),(i+1,j+1)$\n\t\t\\item For each Integer Point, we use \\textbf{dot product} of distant vector(from $(u,v)$ to Integer Point) and gradient vector to get the noise value.\n\t\t\\item In perlin noise every interpolation is in 1-D. So 2-D need first interpolate y-axis(twice) and then interpolate x-axis. 3-D need 7 interpolation.\n\t\tWe used linear-interpolation in slides but we can use \\textbf{Fade} function(easy curves) for better interpolation.\n\t\t\\item Turbulence: Sum noise with diminishing ampitude:\n\t\t$$turbulence(x)=\\sum_{k}^{i=0} \\frac{1}{2^i}|noise(2^i x)|$$\n\t\\end{itemize}\n\t\\item Evironment(Reflection) Mapping:\n\t\\begin{itemize}\n\t\t\\item Basic Idea: During rendering, compute the reflection of Eye vector(not the light vector)\n\t\t\\item \\textbf{Ignore the position of surface point} in scene. We assume all points are on center point of the scene.\n\t\t\\item Light and scenery are all merge into environment texture.\n\t\t\\item No object inter-reflection or shadow\n\t\t\\item Blur texture to simulate diffuse reflection\n\t\t\\item Sharp texture to simulate specular reflection\n\t\\end{itemize}\n\t\\item Cube Map:\n\t\\begin{itemize}\n\t\t\\item Transform each Eye reflection vector R back to world space\n\t\t\\item Find Max component: indicated which face of cube it would intersect\n\t\t\\item Compute intersection of R with cube face:\\\\\n\t\tMove all Reflection ray tail to center of cube.\n\t\tRescale the max component(for example$y$) of vector R to 1.0.\\\\\n\t\tThe other 2 component($x,z$) indicate the texture-pixel.\n\t\\end{itemize}\n\t\\item Refraction Map:\n\t\\begin{itemize}\n\t\t\\item Use Snell's law to compute refraction vector\n\t\t\\item Color aberration simulated with $f(\\lambda)$ refraction angle for multiple color bands\n\t\\end{itemize}\n\\end{enumerate}\n\\subsection{Implementation Of Texutre(HW5)}\n\\begin{enumerate}\n\t\\item Step1: Texture coordinates: surface point $\\rightarrow$ $(u,v)$\\\\\n\tInput: vertex in image space\\\\\n\tOutput: $(u,v)$\n\t\\item Step2: $(u,v)$ $\\rightarrow$ RGB color\\\\\n\tInput: $(u,v)$\n\tOutput: RGB color from image LUT\n\t\\item Interpolation of $(u,v)$ need to be in perspective space.\n\t\\item Interpolation of 4-corner for non-Integer $(u,v)$ is needed.\n\\end{enumerate}\n\\newpage\n\n\\section{Class14-16 Antialiasing}\n\\subsection{The Source of Aliasing}\n\\begin{enumerate}\n\t\\item Quantization error arise from insufficient accuracy of sample\n\t\\item Aliasing error arise from insufficient samples\n\t\\item Nyquist Theorem: Sample at least twice the rate of highest frequency present in the signal.\\\\\n\tf(t) filtered for cutoff freq $\\omega_F$(Remove high frequencies before sampling)\\\\\n\tSample Rate $\\frac{1}{T_0}$ is greater than $2\\omega_F$\\\\\n\tReconsturct(interpolate) with $sinc$ function\n\t\\item Solution: Band-limit the input signal before sampling.\n\\end{enumerate}\n\\subsection{Implement Antialiasing(HW6)}\n\\begin{enumerate}\n\t\\item Antialiasing by jitter supersampling\n\t\\item Sample a pixel several with different center and weight\n\\end{enumerate}\n\\subsection{Texture Antialiasing}\n\\begin{enumerate}\n\t\\item Sample Rate Mismatch: Texture sampling rate generally does not match screen pixel sample rate (Texel:Pixel ratio)\n\t\\item Projected texture in screen image should sample near same rate(1:1) to texture map.\\\\\n\t1 Texel: Many Pixel: No aliasing problem, But blur. Fix by using higher resolution textures.\\\\\n\t1 Pixel: Many Texel: Aliasing problem. Fix by sample rate is twice highest freq in texture.\n\t\\item Mip Map: Pre-compute filtered version of texture image at octave scale/size intervals.\\\\\n\tUsing average color of $2 \\times 2$ texels.\\\\\n\tThe space cost is only $33\\%$ more.\\\\\n\tScale for each level of Mip Map:\n\t$$Scale=\\frac{dU}{dX}=\\frac{dV}{dY}$$\n\tPixel Scale is more complex since it is non-axis-aligned(after rotation and projection):\n\t$$PixelScale=(\\frac{dU}{dX},\\frac{dU}{dY},\\frac{dV}{dX},\\frac{dV}{dY})$$\n\tAn approach to match Scale and PixelScale is choosing the highest PixelScale component.(Blur is better than aliasing!)\n\t\\item 3D Interpolation: If the Pixel Scale is between 2 Texel Scales, we need to interpolate between 2 texture samples.\n\t\\item Anisotropic Interpolation: Combine more than $2 \\times 2$ pixel in each texture samples.\n\t\\item Summed-Area Table(SAT):Compute a texture table T so that each texel has sum of \\textbf{all texels above and left}\\\\\n\tSAT provide an approximation approach to get the avagerage color in O(1).\\\\\n\tNote that: the texels sample might not be axis-aligned since\t the pixel to texel projection. But the different is strictly less than $\\frac{1}{2}$.\n\\end{enumerate}\n\\newpage\n\n\\section{Final Exam Review}\n\\begin{enumerate}\n\t\\item Shading Equation:\n\t$$Color=(K_s\\sum{ L_e \\cdot (E\\cdot R)^{spec}}) + (K_d\\sum{ L_e \\cdot (L\\cdot N)}) + (L_a \\cdot K_a)$$\n\tKnow the meaning for every terms:\n\t\\begin{itemize}\n\t\t\\item $K_s,K_a,K_d$\n\t\t\\item $L_e,L_a$\n\t\t\\item $s$\n\t\t\\item $N,L,R,E$\n\t\t\\item Equation1: $R=2(N\\cdot L) N-L$\n\t\\end{itemize}\n\t\\item Shading Mode:(Flat, Gouraud, Phong)\n\t\\item Texture\n\t\\item Calculate the normal: With Non-translate and Non-scale Matrix To Image Space\n\t\\item Other Topic:\n\t\\begin{itemize}\n\t\t\\item Enviroment Shading \n\t\\end{itemize}\n\\end{enumerate}\n\\newpage\n\n\\section{BRDF}\n\nReference for this section(In Chinese): \\href{https://blog.csdn.net/yjr3426619/article/details/81098626}{https://blog.csdn.net/yjr3426619/article/details/81098626}\n\\subsection{What is BRDF}\n\\begin{itemize}\n\t\\item Basic Idea of BRDF: The reflect rate for a surface is based on input vector and camera vector.\n\t$$f(l,v)=\\frac{dL_0(v)}{dE}(ForNonPointLight)=\\frac{L_o(v)}{E_L cos\\theta_i}(ForPointLight)$$\n\t\\begin{itemize}\n\t\t\\item $l$: input light vector\n\t\t\\item $v$: camera vector\n\t\t\\item $L_0$: Output Radiance(Color)\n\t\t\\item $E_l$: Input Irradiance(Color*$\\pi$ in Unity)\n\t\t\\item $\\theta_i$: angle between input vector and surface normal\n\t\\end{itemize}\n\t\\item Properties of $f(l,v)$\n\t\\begin{itemize}\n\t\t\\item $f(l,v)\\geq 0$\n\t\t\\item $f(l,v)=f(v,l)$\n\t\t\\item $R(l)=\\int_\\phi f(l,v) cos\\theta_0 d\\omega \\leq 1$, Discussed later\n\t\\end{itemize}\n\t\\item How to calculate color based on BRDF:\n\t\\begin{itemize}\n\t\t\\item In Point Light, Point Camera:\n\t\t$$L_0(v)=\\sum_k f(l_k)\\times E_l cos\\theta_{ik}$$\n\t\\end{itemize}\n\t\\item Directional-hemispherical reflectance:\n\t\\begin{itemize}\n\t\t\\item Definition:\n\t\t$$R(l)=\\int_\\phi f(l,v) cos\\theta_0 d\\omega$$\n\t\t\\begin{itemize}\n\t\t\t\\item $\\phi$ is the hemispherical in surface normal half\n\t\t\t\\item $\\theta_0$ is the angel between camera view and surface normal\n\t\t\t\\item $\\omega$ is the space angle\n\t\t\\end{itemize}\n\t\t\\item Basically, $R(l)$ is \\textbf{the sum of the (directional) energy} of all output light in hemisphere.\n\t\t\\item The output energy \\textbf{should be equal or less than} the input energy so:\n\t\t$$R(l)\\leq 1$$\n\t\\end{itemize}\n\\end{itemize}\n\\subsection{How to calculate BRDF}\n\\subsubsection{From Lambertian Model}\n\\begin{itemize}\n\t\\item \\textbf{Lambertian Model}: Only Diffuse Color, No Specular Color. All output direction are the Same.\n\t\\item In this model, we assume the output energy is part of input energy. So We can build this equation:\n\t$$R(l)=C_{diff}$$\n\tSo:\n\t$$C_{diff}=R(l)=\\int_\\phi f(l,v) cos\\theta_0 d\\omega$$\n\tWe know $f(l,v)$ and $C_{diff}$ are both constant number:\n\t$$f(l,v) \\cdot \\int_\\phi cos\\theta_0 d\\omega=C_{diff}$$\n\t$$f(l,v)=\\frac{C_{diff}}{\\pi}$$\n\\end{itemize}\n\\subsubsection{A little bit harder: Phong Model}\n\\begin{itemize}\n\t\\item We assume the ambient light equal to 0 then the shading equation is:\n\t$$L_0=(cos\\theta_i * C_{diff} + (cos\\alpha_r)^{spec}*C_{spec})\\times B_L$$\n\t\\begin{itemize}\n\t\t\\item first part is \\textbf{Lambertian model}\n\t\t\\item $\\alpha_r$ is the angel between reflection vector and camera vector\n\t\\end{itemize}\n\t\\item And we have shading equation in BRDF format:\n\t$$L_0(v)= f(l,v)\\times E_l cos\\theta_{ik}$$\n\t\\item So we have a basic equation for $f(l,v)$ that:\n\t$$f(l,v)=\\frac{C_{diff}}{\\pi}+\\frac{(cos\\alpha_r)^{spec}*C_{spec}}{\\pi * cos\\theta_i}$$\n\t\\item Notices that: If we need to normalize this equation, let $R_{spec}(l) = C_{spec}$\n\t\\item First: When $\\theta_i=\\frac{\\pi}{2}$, $f(l,v)=+\\inf$, which is implausible, so we times $cos\\theta_i$ and a constant $k$:\n\t$$f_{spec}(l,v)=k * \\frac{(cos\\alpha_r)^{spec}*C_{spec}}{\\pi}$$\n\t\\item Second:\n\t$$C_{spec}=R(l)=\\int_\\phi k*f_{spec}(l,v) cos\\theta_0 d\\omega=k*C_{spec}/\\pi * \\int_\\phi(cos\\alpha_r)^{spec} cos\\theta_0d\\omega$$\n\t\\item It's very hard to do this calculation, by experience we can get:\n\t$$k=\\frac{spec+2}{2}$$\n\t\\item So in Phong Model:\n\t$$f(l,v)=\\frac{C_{diff}}{\\pi} + \\frac{(spec+2)C_{spec}*(cos\\alpha_r)^{spec}}{2\\pi}$$\n\\end{itemize}\n\\subsubsection{A little bit more harder: Blinn-Phong Model}\n\\begin{itemize}\n\t\\item We define $\\vec{H}$ is the Halfway-Vector(Normalize the vector of the middle point) of input vector and camera vector.\n\t$$H=\\frac{L+V}{|L+V|}$$ \n\t\\item Shading equation:\n\t$$L_0=(cos\\theta_i * C_{diff} + (cos\\beta)^{spec}*C_{spec})\\times B_L$$\n\t$\\beta$ is the angel between $H$ and surface normal vector.\n\t\\item Follow the step in Phong Model:\n\t$$k=\\frac{spec+8}{8}$$\n\t\\item And:\n\t$$f(l,v)=\\frac{C_{diff}}{\\pi} + \\frac{(spec+8)C_{spec}*(cos\\beta)^{spec}}{8\\pi}$$\n\\end{itemize}\n\\subsubsection{Microfacet Model in \\href{https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf}{Disney Paper}}\n\\begin{itemize}\n\t\\item Equation First:\n\t$$f(l,v)=diffuse + \\frac{D(\\theta_h)F(\\theta_d)G(\\theta_l,\\theta_v)}{4cos\\theta_l cos\\theta_v}$$\n\t\\item Microfacet Model: The surface is an aggregate of many microfacet, each microfacet have different normal and you can only see part of the microfacet, and some microfacet might be blocked by others.\n\t\\item How many microfacets you can see is define by $D(\\theta_h)$\n\t\\item How many microfacets is blocked by other microfacets is define by $G(\\theta_l,\\theta_v)$\n\t\\item The fraction of reflaction energy in the total input energy is define by $F(\\theta_d)$ \n\t\\item $\\frac{1}{4cos\\theta_l cos\\theta_v}$ is a normalize factor. \n\\end{itemize}\n\\subsubsection{BRDF With Physics Based Render}\n\\begin{itemize}\n\t\\item In Disney's paper Section 5.3~5.6, it present how \\textbf{roughness} can affect diffuse function and G function.\n\t\\item Diffuse Function:\n\t$$diffuse=\\frac{baseColor}{\\pi}(1+(F_{D90}-1)(1-cos\\theta_l)^5)(1+(F_{D90}-1)(1-cos\\theta_v)^5)$$\n\t$$F_{D90}=0.5+2*cos\\theta^2_d*roughness$$\n\t\\item D Function:\n\t$$D_GTR=\\frac{c}{(\\alpha^2cos^2\\theta_h +sin^2\\theta_h)^\\gamma}$$\n\t$$\\alpha=roughness^2$$\n\t\\item F Function:\n\t$$F_{Schlick}=F_0 + (1-F_0)(1-cos\\theta_d)^5$$\n\t\\item G Function: Using GGX Function\\\\\n\tReference: \\textit{Microfacet Models for Refraction through Rough Surfaces }\n\t$$\\alpha_g=(0.5+roughness/2)^2$$\n\\end{itemize}\n\\section{Next Step:}\n\\begin{itemize}\n\t\\item Build the BRDF shading function in unity.\n\t\\item Find a better diffuse,D,F,G Function\n\t\\item Put some new variable into diffuse,D,F,G\n\\end{itemize}\n\\newpage\n\\section{finalEquation}\n$$\n\\begin{aligned}\nf_{disneyBRDF}(\\vec{L},\\vec{N},\\vec{V})&=(1-metallic)(\\frac{basecolor}{\\pi}(f_d*(1-subsurface)+f_{ss}*subsurface)+f_{sh})\\\\\n&+\\frac{F_s*G_s*D_s}{4*\\vec{N}\\cdot\\vec{L}*\\vec{N}\\cdot\\vec{V}}+\\frac{clearcoat}{4}*\\frac{F_c*G_c*D_c}{4*\\vec{N}\\cdot\\vec{L}*\\vec{N}\\cdot\\vec{V}}\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nf_d&=(1+(F_{D90}-1)(1-\\vec{N}\\cdot\\vec{L})^5)(1+(F_{D90}-1)(1-\\vec{N}\\cdot\\vec{V})^5)\\\\\nF_{D90}&=0.5+2*\\cos^2(\\vec{N}\\cdot\\vec{H})*roughness\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nf_{ss}&=1.25(((1+(F_{ss90}-1)(1-\\vec{N}\\cdot\\vec{L})^5)(1+(F_{ss90}-1)(1-\\vec{N}\\cdot\\vec{V})^5))(\\frac{1}{\\vec{N}\\cdot\\vec{L}+\\vec{N}\\cdot\\vec{V}}-0.5)+0.5)\\\\\nF_{ss90}&=\\cos^2(\\vec{N}\\cdot\\vec{H})*roughness\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nf_{sh}&=(white*(1-sheenTint)+\\frac{baseColor}{lum(baseColor)}*sheenTint)*sheen*(1-\\vec{N}\\cdot\\vec{H})^5\\\\\nC_{tint}&=\\frac{baseColor}{lum(baseColor)}\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nF_{s}&=C_{s}+(1-C_{s})(1-\\vec{N}\\cdot\\vec{H})^5\\\\\nC_{s}&=(1-metallic)*0.08specular((1-specularTint)white+specularTint\\frac{baseColor}{lum(baseColor)})+metallic*baseColor\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nG_{s}&=\\frac{1}{\\vec{N}\\cdot\\vec{V}+\\sqrt{\\alpha_{G}^2+(\\vec{N}\\cdot\\vec{V})^2-\\alpha_{G}(\\vec{N}\\cdot\\vec{V})}}\\\\\n\\alpha_{G}&=\\frac{1+roughness}{2}^2\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nD_{s}&=\\frac{1}{\\pi*roughness^4*((\\frac{\\vec{H}\\cdot\\vec{X}}{roughness^2/a}+\\frac{\\vec{H}\\cdot\\vec{Y}}{roughness^2*a})^2+(\\vec{N}\\cdot\\vec{H})^2)^2}\\\\\na&=\\sqrt{1-0.9*anisotropic}\n\\end{aligned}\n$$\n$$\nF_{c}=0.04+0.96*(1-\\vec{V}\\cdot\\vec{H})^5\n$$\n$$\nD_{c}=\\frac{(0.1-0.09clearCoatGloss)^2-1}{2\\pi\\ln(0.1-0.09clearCoatGloss)*((0.1-0.09clearCoatGloss)^2*(\\vec{N}\\cdot\\vec{V})^2+(1-(\\vec{N}\\cdot\\vec{H})^2))}\n$$\n$$\nG_{c}=\\frac{1}{\\vec{N}\\cdot\\vec{V}+\\sqrt{(0.5+roughness*0.5)^4+({\\vec{N}\\cdot\\vec{V})^4-(0.5+roughness*0.5)^2*({\\vec{N}\\cdot\\vec{V})^2}}}}\n$$\n\\newpage\n\\subsection{FullyExpent}\n$\nf_{disneyBRDF}(\\vec{L},\\vec{N},\\vec{V})=(1-metallic)(\\frac{basecolor}{\\pi}(((1+((0.5+2*\\cos^2(\\vec{N}\\cdot\\vec{H})*roughness)-1)(1-\\vec{N}\\cdot\\vec{L})^5)(1+((0.5+2*\\cos^2(\\vec{N}\\cdot\\vec{H})*roughness)-1)(1-\\vec{N}\\cdot\\vec{V})^5))*(1-subsurface)+(1.25(((1+(\\cos^2(\\vec{N}\\cdot\\vec{H})*roughness-1)(1-\\vec{N}\\cdot\\vec{L})^5)(1+(\\cos^2(\\vec{N}\\cdot\\vec{H})*roughness-1)(1-\\vec{N}\\cdot\\vec{V})^5))(\\frac{1}{\\vec{N}\\cdot\\vec{L}+\\vec{N}\\cdot\\vec{V}}-0.5)+0.5))*subsurface)+((white*(1-sheenTint)+\\frac{baseColor}{lum(baseColor)}*sheenTint)*sheen*(1-\\vec{N}\\cdot\\vec{H})^5))+(1-metallic)*0.08specular((1-specularTint)white+specularTint\\frac{baseColor}{lum(baseColor)})+metallic*baseColor+(1-(1-metallic)*0.08specular((1-specularTint)white+specularTint\\frac{baseColor}{lum(baseColor)})+metallic*baseColor)(1-\\vec{N}\\cdot\\vec{H})^5*\\frac{1}{\\vec{N}\\cdot\\vec{V}+\\sqrt{\\frac{1+roughness}{2}^4+(\\vec{N}\\cdot\\vec{V})^2-\\frac{1+roughness}{2}^2(\\vec{N}\\cdot\\vec{V})}}*(\\frac{1}{\\pi*roughness^4*((\\frac{\\vec{H}\\cdot\\vec{X}}{roughness^2\\sqrt{1-0.9*anisotropic}}+\\frac{\\vec{H}\\cdot\\vec{Y}}{roughness^2\\sqrt{1-0.9*anisotropic}})^2+(\\vec{N}\\cdot\\vec{H})^2)^2})/(4*\\vec{N}\\cdot\\vec{L}*\\vec{N}\\cdot\\vec{V})+\\frac{clearcoat}{4}*(0.04+0.96*(1-\\vec{V}\\cdot\\vec{H})^5)/(\\vec{N}\\cdot\\vec{V}+\\sqrt{(0.5+roughness*0.5)^4+({\\vec{N}\\cdot\\vec{V})^4-(0.5+roughness*0.5)^2*({\\vec{N}\\cdot\\vec{V})^2}}})*((0.1-0.09clearCoatGloss)^2-1)/(2\\pi\\ln(0.1-0.09clearCoatGloss)*((0.1-0.09clearCoatGloss)^2*(\\vec{N}\\cdot\\vec{V})^2+(1-(\\vec{N}\\cdot\\vec{H})^2))))/(4*\\vec{N}\\cdot\\vec{L}*\\vec{N}\\cdot\\vec{V})\n$\n\\end{document}", "meta": {"hexsha": "ebcb0e11b250699c85c4975f7ba57d56b47a7f54", "size": 36960, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NoteForComputerGraph.tex", "max_stars_repo_name": "billcshi/ComputerGraph", "max_stars_repo_head_hexsha": "88d7b1acc3f95f1f31e1da6ad4b9ab79362344e4", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-09-25T20:39:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-26T01:11:18.000Z", "max_issues_repo_path": "NoteForComputerGraph.tex", "max_issues_repo_name": "billcshi/ComputerGraph", "max_issues_repo_head_hexsha": "88d7b1acc3f95f1f31e1da6ad4b9ab79362344e4", "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": "NoteForComputerGraph.tex", "max_forks_repo_name": "billcshi/ComputerGraph", "max_forks_repo_head_hexsha": "88d7b1acc3f95f1f31e1da6ad4b9ab79362344e4", "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": 50.6995884774, "max_line_length": 1561, "alphanum_fraction": 0.6911255411, "num_tokens": 13000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938819, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.6979390524361355}}
{"text": "\\section{Queueing}\n\\label{sec:queueing}\n\\index{queue}\n\nDespite its didactic qualities, aggregate analysis (see\npage~\\pageref{par:aggregate}) is less frequently applied when the data\nstructures are not directly connected to numeration. We propose to\nextend its scope by showing a compelling case study on\n\\emph{functional queues}\n\\citep{Burton_1982,Okasaki_1995,Okasaki_1998b}. A functional queue is\na linear data structure that is used in functional languages, whose\nsemantics force the programmer to model a \\emph{queue} with two\nstacks. Items can be pushed only on one stack and popped only on the\nother:\n\\begin{equation*}\n\\begin{array}{@{}l@{}r@{\\;}cc|c|c|c|c|c|cc@{\\;}l@{}}\n\\cline{4-9}\n& \\text{Push, Pop (top)}\n& \\leftrightsquigarrow & & a & b & c & d & e &&&\\\\\n\\cline{4-9}\n\\end{array}\n\\end{equation*}\nA queue is like a stack where items are added, or \\emph{enqueued}, at\none end, called \\emph{rear}, but taken out, or \\emph{dequeued}, at the\nother end, called \\emph{front}:\n\\begin{equation*}\n\\begin{array}{@{}l@{}r@{\\;}cc|c|c|c|c|c|cc@{\\;}l@{}}\n\\cline{4-10}\n& \\text{Enqueue (rear end)}\n                & \\rightsquigarrow & & a & b & c & d & e &\n& \\rightsquigarrow & \\text{Dequeue (front end).}\\\\\n\\cline{4-10}\n\\end{array}\n\\end{equation*}\nLet us implement a queue with two stacks: one for enqueueing, called\nthe \\emph{rear stack}\\index{queue!rear stack}\\index{stack!rear\n  $\\sim$|see{queue}}, and one for dequeueing, called the \\emph{front\n  stack}\\index{queue!front stack}\\index{stack!front\n  $\\sim$|see{queue}}. The previous ideal queue is equivalent to the\nfunctional queue\n\\begin{equation*}\n\\begin{array}{r@{\\;}cc|c|c|c|c|c|c|cc@{\\;}l}\n  \\cline{3-6}\\cline{8-10}\n  \\text{Enqueue (rear)} & \\rightsquigarrow & & a & b & c & & d & e & &\n  \\rightsquigarrow & \\text{Dequeue (front).}\\\\\n  \\cline{3-6}\\cline{8-10}\n\\end{array}\n\\end{equation*}\nEnqueueing is now pushing on the rear stack and dequeueing is popping\non the front stack. In the latter case, if the front stack is empty\nand the rear stack is not, we swap the stacks and reverse the new\nfront stack. Graphically, dequeueing in the configuration\n\\begin{equation*}\n\\begin{array}{c|c|c|c|c|c} \\cline{1-4}\\cline{6-6} & a & b & c &\n&\\\\ \\cline{1-4}\\cline{6-6}\n\\end{array}\n\\end{equation*}\nrequires first to make\n\\begin{equation*}\n\\begin{array}{c|c|c|c|c|c}\n  \\cline{1-1}\\cline{3-6}\n  & & a & b & c &\\\\\n  \\cline{1-1}\\cline{3-6}\n\\end{array}\n\\end{equation*}\nand then dequeue~\\(c\\).\n\nLet us model a queue as we modelled the operation push by a function\n\\fun{cons/2}\\index{cons@\\fun{cons/2}} without a definition, on\npage~\\pageref{par:stacks}. We shall use the name\n\\fun{q/2}\\index{q@\\fun{q/2}} and the call \\(\\fun{q}(r,f)\\) denotes a\nfunctional queue with rear stack~\\(r\\) and front\nstack~\\(f\\). Enqueueing is performed by the function\n\\fun{enq/2}\\index{enq@\\fun{enq/2}}:\n\\begin{equation}\n\\fun{enq}(x,\\fun{q}(r,f)) \\rightarrow \\fun{q}(\\cons{x}{r},f).\n\\label{def:enq}\n\\end{equation}\nDequeueing requires the result to be a \\emph{pair}\\index{functional\n  language!pair} made of the dequeued item and the new queue without\nit. Actually, the new queue is the first component of the pair, to fit\nhow the operation is depicted in the figures as a rightwards arrow.\n%% We could denote the mathematical pair \\((x,y)\\) by\n%% \\(\\fun{pair}(x,y)\\), but a more symbolic notation is handy:\n%% \\(\\pair{x}{y}\\). The angle brackets allow us to avoid writing\n%% \\(f((x,y))\\) when we mean \\(f(\\pair{x}{y})\\).\nLet us call \\fun{deq/1}\\index{deq@\\fun{deq/1}} the\ndequeueing function:\n\\begin{equation}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n  \\fun{deq}(\\fun{q}(\\cons{x}{r},\\el))\n& \\xrightarrow{\\smash{\\theta}}\n& \\fun{deq}(\\fun{q}(\\el,\\fun{rcat}(r,[x])));\\\\\n  \\fun{deq}(\\fun{q}(r,\\cons{x}{f}))\n& \\xrightarrow{\\smash{\\iota}}\n& \\pair{\\fun{q}(r,f)}{x}.\n\\end{array}\n\\label{def:deq}\n\\end{equation}\nSee page~\\pageref{def:rev} for the definition~\\eqref{def:rev}\nof~\\fun{rcat/2}\\index{rcat@\\fun{rcat/2}}. We shall say that the queue\nhas size~\\(n\\) if the total number of items in both stacks\nis~\\(n\\). The cost of enqueueing\\index{enq@$\\C{\\fun{enq}}{n}$} is\n\\(\\C{\\fun{enq}}{n} = 1\\). The minimum\ncost\\index{deq@$\\B{\\fun{deq}}{n}$} for dequeueing is\n\\(\\B{\\fun{deq}}{n} = 1\\), by rule~\\(\\iota\\). The maximum cost is\n\\(\\W{\\fun{deq}}{n} = n+2\\), as seen with the trace\n\\(\\theta\\eta^{n-1}\\zeta\\iota\\). Let~\\(\\A{n}\\) be the cost of a\nsequence of \\(n\\)~updates on a functional queue originally empty. A\nfirst attempt at assessing~\\(\\A{n}\\) consists in ignoring any\ndependence on previous operations and take the maximum individual\ncost. Since \\(\\C{\\fun{enq}}{k} \\leqslant \\C{\\fun{deq}}{k}\\), we\nconsider a series of \\(n\\)~dequeueings in their worst case, that is,\nwith all the items located in the rear stack. Besides, after\n\\(k\\)~updates, there may be at most \\(k\\)~items in the queue, so\n\\begin{equation*}\n\\A{n} \\leqslant \\sum_{k=1}^{n-1}{\\W{\\fun{deq}}{k}} =\n\\frac{1}{2}{(n-1)(n+4)} \\sim \\frac{1}{2}{n^2}.\n\\end{equation*}\n\n\\paragraph{Aggregate analysis}\n\\index{cost!amortised $\\sim$}\n\\index{queue!amortised cost}\n\nActually, this is overly pessimistic and even unrealistic. First, one\ncannot dequeue on an empty queue, therefore, at any time, the number\nof enqueueings since the beginning is always greater or equal than the\nnumber of dequeueings and the series must start with one\nenqueueing. Second, when dequeueing with the front being empty, the\nrear stack is reversed onto the front stack, so its items cannot be\nreversed again during the next dequeueing, whose cost will\nbe~\\(1\\). Moreover, as remarked above, \\(\\C{\\fun{enq}}{k} \\leqslant\n\\C{\\fun{deq}}{k}\\), so the worst case for a series of\n\\(n\\)~operations occurs when the number of dequeueings is maximum,\nthat is, when it is \\(\\lfloor{n/2}\\rfloor\\). If we denote by~\\(e\\) the\nnumber of enqueueings and by~\\(d\\) the number of dequeueings, we have\nthe relationship \\(n = e + d\\) and the two requisites for a worst case\nbecome \\(e=d\\) (\\(n\\)~even) or \\(e=d+1\\) (\\(n\\)~odd). The former\ncorresponds graphically to a \\emph{Dyck path}\\index{Dyck path} and the\nlatter to a \\emph{Dyck meander}\\index{Dyck meander}.\n\n\\paragraph{Dyck path}\n\\index{Dyck path}\n\nLet us depict updates as in \\fig~\\vref{fig:enq_deq}.\n\\begin{figure}\n\\centering\n\\subfloat[Enqueue\\label{fig:enqueue}]{%\n  \\includegraphics[bb=69 662 132 721,scale=0.75]{enqueue}\n}\n\\qquad\n\\subfloat[Dequeue\\label{fig:dequeue}]{%\n  \\includegraphics[bb=69 662 132 721,scale=0.75]{dequeue}\n}\n\\caption{Graphical representations of operations on\n  queues\\label{fig:enq_deq}}\n\\end{figure}\nTextually, we represent an enqueueing as an opening parenthesis and a\ndequeueing as a closing parenthesis. For example,\n\\texttt{((()()(()))())} can be represented in \\fig~\\ref{fig:dyck_path}\n\\begin{figure}\n\\centering\n\\includegraphics[bb=75 570 508 727,scale=0.7]{dyck_path}\n\\caption{Dyck path modelling queue operations (cost \\(24\\))\n\\label{fig:dyck_path}}\n\\end{figure}\nas a Dyck path\\index{Dyck path}. For a broken line to qualify\nas a Dyck path of length~\\(n\\), it has to start at the origin\n\\((0,0)\\) and end at coordinates \\((n,0)\\). In terms of a \\emph{Dyck\n  language}, an enqueueing is called a \\emph{rise}\\index{Dyck\n  path!rise} and a dequeueing is called a \\emph{fall}\\index{Dyck\n  path!fall}. A rise followed by a fall, that is, \\texttt{()}, is\ncalled a \\emph{peak}\\index{Dyck path!peak}. For instance, in\n\\fig~\\ref{fig:dyck_path}, there are four peaks. The number near each\nrise or fall is the cost incurred by the corresponding operation. The\nabscissa axis bears the ordinal of each operation.\n\nWhen \\(e=d\\), the line is a Dyck path of length \\(n=2e=2d\\). In order\nto deduce the total cost in this case, we must find a\n\\emph{decomposition}\\index{Dyck path!decomposition} of the path, by\nwhich we mean to identify patterns whose costs are easy to calculate\nand which make up any path, or to associate any path to another path\nwhose cost is the same but easy to find. \\Fig~\\ref{fig:dyck_eq}\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[bb=75 570 508 727,scale=0.7]{dyck_eq}\n\\caption{Dyck path equivalent to \\fig~\\ref{fig:dyck_path}\n\\label{fig:dyck_eq}}\n\\end{figure}\nshows how the previous path is mapped to an equivalent path only made\nof a series of isosceles triangles whose bases belong to the abscissa\naxis. Let us call them \\emph{mountains}\\index{Dyck path!mountain} and\ntheir series a \\emph{range}\\index{Dyck path!range}. The mapping is\nsimple: after the first series of falls, if we are back to the\nabscissa axis, we have a mountain and we proceed with the rest of the\npath. Otherwise, the next operation is a rise and we exchange it with\nthe first fall after it. This brings us down by~\\(1\\) and the process\nresumes until the abscissas are reached. We call this méthod\n\\emph{rescheduling}\\index{Dyck path!rescheduling} because it amounts,\nin operational terms, to reordering subsequences of operations a\nposteriori.\n\nFor instance, \\fig~\\vref{fig:rescheduling}\n\\begin{figure}\n\\centering\n\\subfloat[Initial\\label{fig:initial}]{%\n  \\includegraphics[scale=0.75,bb=48 588 218 726]{mount0}}\n\\qquad\n\\subfloat[Swapping \\(4\\nearrow 5\\) and \\(5\\searrow 6\\)]{%\n  \\includegraphics[scale=0.75,bb=48 588 218 726]{mount1}}\\\\\n\\subfloat[Swapping \\(5\\nearrow 6\\) and \\(8 \\searrow 9\\)\\label{fig:valley}]{%\n  \\includegraphics[scale=0.75,bb=48 588 218 726]{mount2}}\n\\qquad\n\\subfloat[Last one]{%\n  \\includegraphics[bb=13 645 180 782,scale=0.75]{mount3}}\n\\caption{Rescheduling of \\fig~\\ref{fig:dyck_path} into\n  \\fig~\\ref{fig:dyck_eq}\\label{fig:rescheduling}}\n\\end{figure}\ndisplays the rescheduling of \\fig~\\vref{fig:dyck_path}. Note that two\ndifferent paths can be rescheduled into the same path. What makes\n\\fig~\\ref{fig:valley} equivalent to \\fig~\\ref{fig:initial} is the\ninvariance of the cost because all operations have cost~\\(1\\). This\nalways holds because enqueueings always have cost~\\(1\\) and the\ndequeueings involved in a rescheduling have cost~\\(1\\), because they\nfound the front stack non\\hyp{}empty after a peak. We proved that all\npaths are equivalent to a range with the same cost, therefore, the\nmaximum cost can be found on ranges alone.\n\nLet us note \\(e_1, e_2, \\dots, e_k\\) the maximal subsequences of\nrises; for example, in \\fig~\\ref{fig:dyck_eq}, we have \\(e_1=3\\),\n\\(e_2 = 3\\) and \\(e_3 = 1\\). Of course, \\(e = e_1 + e_2 + \\dots +\ne_k\\). The fall making up the \\(i\\)th peak incurs the\ncost\\index{deq@$\\W{\\fun{deq}}{n}$} \\(\\W{\\fun{deq}}{e_i} = e_i + 2\\),\ndue to the front being empty because we started the rises from the\nabscissa axis. The next \\(e_i-1\\) falls have all cost~\\(1\\), because\nthe front is not empty. For the \\(i\\)th mountain, the cost is thus\n\\(e_i+(e_i+2)+(e_i-1) = 3e_i+1\\). Then \\(\\A{e,k} =\n\\sum_{i=1}^{k}{(3e_i+1)} = 3e + k\\). The maximum cost is obtained by\nmaximising \\(\\A{e,k}\\) for a given~\\(e\\):\n\\begin{equation*}\n\\W{}{e,e} := \\max_{1 \\leqslant k \\leqslant e}{\\A{e,k}} = \\A{e,e} = 4e\n= 2n,\\,\\; \\text{with \\(n=e+d=2e\\)},\n\\end{equation*}\nwhere \\(\\W{}{e,e}\\) is the maximum cost when there are\n\\(e\\)~enqueueings and \\({d=e}\\) dequeueings. In other words, the worst\ncase when \\(e=d=7\\) is the saw\\hyp{}toothed Dyck path shown in\n\\fig~\\vref{fig:max_dyck}.\n\\begin{figure}\n\\centering\n\\includegraphics[bb=86 657 507 726,scale=0.7]{max_dyck}\n\\caption{Worst case when \\(e=d=7\\) (cost \\(28\\))\n\\label{fig:max_dyck}}\n\\end{figure}\nImportantly, there are no other Dyck paths whose rescheduling lead to\nthis worst case and the reason is that the reverse transformation from\nranges to general Dyck paths works on dequeueings of cost~\\(1\\) and\nthe solution we found is the only one with no dequeueing equal\nto~\\(1\\).\n\n\\paragraph{Dyck meander}\n\\index{Dyck meander}\n\nAnother worst case occurs if \\(e = d + 1\\) and the line is then a Dyck\nmeander whose extremity ends at ordinate \\(e-d=1\\). An example is\ngiven in \\fig~\\ref{fig:meander1},\n\\begin{figure}[t]\n\\centering\n\\includegraphics[bb=75 570 480 727,scale=0.82]{meander1}\n\\caption{Dyck meander modelling queue operations (total cost~\\(21\\))\\label{fig:meander1}}\n\\end{figure}\nwhere the last operation is a dequeueing. The dotted line delineates\nthe result of applying the rescheduling we used on Dyck paths. Here,\nthe last operation becomes an enqueueing.\n\nAnother possibility is shown in \\fig~\\ref{fig:meander2},\n\\begin{figure}[t]\n\\centering\n\\includegraphics[bb=75 570 480 727,scale=0.82]{meander2}\n\\caption{Dyck meander modelling queue operations (total cost\n  \\(23\\))\\label{fig:meander2}}\n\\end{figure}\nwhere the last operation is left unchanged. The difference between the\ntwo examples lies in the fact that the original last dequeueing has,\nin the former case, a cost of~\\(1\\) (thus is changed) and, in the\nlatter case, a cost greater than~\\(1\\) (thus is invariant). The third\nkind of Dyck meander is one ending with an enqueueing, but because\nthis enqueueing must start from the abscissa axis, this is the same\nsituation as the result of rescheduling a meander ending with a\ndequeueing with cost~\\(1\\) (see dotted line in \\fig~\\ref{fig:meander1}\nagain). Therefore, we are left to compare the results of rescheduling\nmeanders ending with a dequeueing, that is, we envisage two cases.\n\\begin{itemize}\n\n  \\item If we have a range of \\(n-1\\)~operations followed by an\n    enqueueing, the maximum cost of the range is the cost of a\n    saw\\hyp{}toothed Dyck path, that is,\n    \\(\\W{}{e-1,e-1}=4(e-1)=2n-2\\), because \\(n=e+d=2e-1\\), followed by\n    an enqueueing, totalling \\(2n-1\\).\n\n  \\item Otherwise, we have a range of \\(n-3\\)~operations followed by\n    two rises and one fall (of cost~\\(6\\)). The cost is\n    \\(\\W{}{e-2,e-2}+6=2n\\), which is marginally greater than the\n    previous case.\n\n\\end{itemize}\n\n\\mypar{Amortised cost}\n\\index{cost!amortised $\\sim$}\n\\index{queue!amortised cost}\n\nThe cost~\\(\\A{n}\\) of a series of \\(n\\)~queue updates, starting on an\nempty queue, is tightly bounded as\\index{queue@$\\A{n}$}\n\\begin{equation*}\nn \\leqslant \\A{n} \\leqslant 2n,\n\\end{equation*}\nwhere the lower bound is tight if all updates are enqueueings and the\nupper bound when a saw\\hyp{}toothed range is followed by one\nenqueueing or else two enqueueings and one dequeueing. By definition,\nthe amortised cost of one operation is~\\(\\A{n}/n\\) and lies between\n\\(1\\)~and~\\(2\\), which is less than our first analysis (\\(\\sim\nn/2\\)). We published a slightly different analysis on the same\nexamples \\citep{Rinderknecht_2011}.\n\n\\paragraph{Side note}\n\nWe can gain some more abstraction by using a dedicated constructor for\nthe empty queue, \\(\\fun{nilq/0}\\), and changing accordingly the\ndefinition of \\fun{enq/2} in~\\eqref{def:enq} \\vpageref{def:enq} so it\nhandles this case:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{enq}(x,\\fun{nilq}()) & \\rightarrow & \\fun{q}([x],\\el);\\\\\n\\fun{enq}(x,\\fun{q}(r,f)) & \\rightarrow & \\fun{q}(\\cons{x}{r},f).\n\\end{array}\n\\end{equation*}\nWe can improve this a little by pushing~\\(x\\) directly into the front\nstack:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{enq}(x,\\fun{nilq}()) & \\rightarrow & \\fun{q}(\\el,[x]);\\\\\n\\fun{enq}(x,\\fun{q}(r,f)) & \\rightarrow & \\fun{q}(\\cons{x}{r},f).\n\\end{array}\n\\end{equation*}\n\n\\paragraph{Exercises}\n\\begin{enumerate}\n\n  \\item Let \\(\\fun{nxt}(q)\\)\\index{nxt@\\fun{nxt/1}} be the next item\n    to be dequeued from~\\(q\\):\n    \\begin{equation*}\n      \\begin{array}{r@{\\;}l@{\\;}l}\n        \\fun{nxt}(\\fun{q}(\\cons{x}{r},\\el)) & \\rightarrow\n        & \\fun{nxt}(\\fun{q}(\\el,\\fun{rcat}(r,[x])));\\\\\n        \\fun{nxt}(\\fun{q}(r,\\cons{x}{f})) & \\rightarrow & x.\n        \\index{q@\\fun{q/2}}\n      \\end{array}\n    \\end{equation*}\n    Modify \\fun{enq/2}\\index{enq@\\fun{enq/2}},\n    \\fun{deq/1}\\index{deq@\\fun{deq/1}} and\n    \\fun{nxt/1}\\index{nxt@\\fun{nxt/1}} in such a way that\n    \\(\\C{\\fun{nxt}}{n} = 1\\)\\index{nxt@$\\C{\\fun{nxt}}{n}$}, where\n    \\(n\\)~is the number of items in the queue.\n\n    \\item Find~\\(\\A{n}\\) using the slightly different definition\n      \\begin{equation*}\n        \\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n          \\fun{deq}(\\fun{q}(\\cons{x}{r},\\el))\n          & \\rightarrow\n          & \\fun{deq}(\\fun{q}(\\el,\\fun{rev}(\\cons{x}{r})));\\\\\n          \\fun{deq}(\\fun{q}(r,\\cons{x}{f}))\n          & \\rightarrow\n          & \\pair{\\fun{q}(r,f)}{x}.\n        \\end{array}\n      \\end{equation*}\n\n\\end{enumerate}\n", "meta": {"hexsha": "09f03b4e2ec6dda2e817815b69226d82a2bdebbb", "size": 16141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "queueing.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": "queueing.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": "queueing.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": 42.8143236074, "max_line_length": 89, "alphanum_fraction": 0.693327551, "num_tokens": 5589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.6979390474357863}}
{"text": "\n\\subsection{Simulated annealing}\n\n\\subsubsection{Introduction}\n\nWe can use a version of Metropolis-Hastings to find the global maximum of a function \\(f(x)\\).\n\nWe start with an arbitrary point \\(x_0\\).\n\nWe move randomly from this to identiy a candidate point \\(x_c\\).\n\nWe accept this with probability depending on the the relationship between \\(x_0\\) and \\(x_c\\).\n\nThis process will converge on the global maximum.\n\n\\subsubsection{Hyperparameter}\n\nThere is a hyperparameter for selection. At the extreme this becomes a greedy function.\n\n", "meta": {"hexsha": "b1fae4bf4e6c1378a6844f0ef98ba484c5775292", "size": 538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/optimisation/01-03-annealing.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-03-annealing.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-03-annealing.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": 94, "alphanum_fraction": 0.7713754647, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6979294196409046}}
{"text": "\\chapter{Numerical Integrators} \\label{Ch:NumericalIntegrators}\r\n\r\n\\section{Runge-Kutta Integrators} \\index{Numerical\r\nintegrators!Runge-Kutta}\r\n\r\nThe Runge-Kutta integration scheme is a single step method used to\r\nsolve  differential equations for $n$ coupled variables of the\r\nform\r\n\r\n\\[{{dr^i}\\over{dt}} = f(t,r)\\]\r\n\r\n(The superscript in this discussion refers to the variables; hence\r\n$f^i$ is the $i^{th}$ variable, and $r^{(n)}$ refers to all $n$\r\nvariables.) The method takes an integration step, $h$, by breaking\r\nthe  interval into several stages (usually of smaller size) and\r\ncalculating  estimates of the integration result at each stage.\r\nThe later stages use the  results of the earlier stages. The\r\ncumulative effect of the integration is  an approximate total step\r\n$\\delta t$, accurate to a given order in the  series expansion of\r\nthe differential equation, for the state variables  $r_i(t+\\delta\r\nt)$ given the state $r_i(t)$.\r\n\r\nThe time increment for a given stage is given as a multiple $a_i$\r\nof the  total time step desired; thus for the $i^{th}$ stage the\r\ninterval used  for the calculation is $a_i \\delta t$; the estimate\r\nof the integrated  state at this stage is given by\r\n\r\n\\[ k_i^{(n)} = \\delta t f(t+a_i\\delta t, r^{(n)}(t) + \\sum_{j=1}^{i-1}b_{ij}k_j^{(n)}) \\]\r\n\r\nwhere $b_{ij}$ contains a set of coefficients specific to the\r\nRunge-Kutta instance being calculated. Given the results of the\r\nstage calculations, the  total integration step can be calculated\r\nusing another set of coefficients, $c_j$ and the formula\r\n\r\n\\[ r^{(n)}(t+\\delta t) = r^{(n)}(t) + \\sum_{j=1}^{stages}c_j k_j^{(n)} \\]\r\n\r\nThe error control for these propagators is implemented by\r\ncomparing the  results of two different orders of integration. The\r\ndifference between the  two steps provides an estimate of the\r\naccuracy of the step; a second set of  coefficients corresponding\r\nto this second integration scheme can be used to obtain a solution\r\n\r\n\\[r'^{(n)}(t+\\delta t) = r^{(n)}(t) + \\sum_{j=1}^{stages}c_j^* k_j^{*(n)}\\]\r\n\r\nWith care, the stage estimates $k_j$ and $k_j^*$ can be selected\r\nso  that they are the same; in that case, the estimate of the\r\nerror in the  integration $\\Delta^{(n)}$ can be written\r\n\r\n\\[ \\Delta^{(n)} = \\left| \\sum_{j=1}^{stages}(c_j - c_j^*) k_j^{(n)} \\right| \\]\r\n\r\n(The difference between the coefficients $c_j - c_j^*$ is the\r\narray of  error estimate coefficients (ee) in this code.)\r\n\r\nOnce the estimated error has been calculated, the size of the\r\nintegration  step can be adapted to a size more appropriate to the\r\ndesired accuracy of the  integration. If the step results in a\r\nsolution that is not accurate enough, the step needs to be\r\nrecalculated with a smaller step size. Labeling the desired\r\naccuracy $\\alpha$ and the obtained accuracy $\\epsilon$\r\n(calculated, for instance, as the largest element of the array\r\n$\\Delta$), the new step used by the Runge-Kutta integrator is\r\n\r\n\\[\\delta t_{new}= \\sigma\\delta t\\left({{\\alpha}\\over{\\epsilon}}\\right)^{1/(m-1)}\\]\r\n\r\nwhere $m$ is the order of truncation of the series expansion of\r\nthe  differential equations being solved. The factor $\\sigma$ is a\r\nsafety  factor incorporated into the calculation to avoid\r\nunnecessary iteration over attempted steps. Common practice is to\r\nset this factor to 0.9; that is the default value used in this\r\nimplementation.\r\n\r\nSimilarly, if the step taken does not result in the desired\r\naccuracy, you may  want to increase the step size parameter for\r\nthe next integration step. The  new estimate for the desired\r\nstepsize is given by\r\n\r\n\\[\\delta t_{new}= \\sigma\\delta t\\left({{\\alpha}\\over{\\epsilon}}\\right)^{1/(m)}\\]\r\n\r\nSometimes you do not want to increase the stepsize in this manner;\r\nfor example,  you may want to keep the maximum step taken at some\r\nfixed value. This  implementation provides a mechanism for\r\nspecifying a maximum allowed step.\r\n\r\nSometimes it is convenient to request steps of a specified size,\r\nregardless  of the stepsize control algorithm or the calculation\r\nof the \\char`\\\"{}best step\\char`\\\"{}  described above. This\r\nimplementation accomplishes that task by taking  multiple error\r\ncontrolled steps is necessary to step across the requested\r\ninterval.\r\n\r\nBoth of these features are implemented using the boolean flags\r\ndescribed in  the base class for the integrators. See the\r\ndocumentation for the {\\bf Integrator} {\\rm\r\n(p.\\,\\pageref{classIntegrator})} class for more information about\r\nthese flags.\r\n\r\n\r\n\r\n\\subsection{Constructor \\& Destructor Documentation}\r\n\\subsubsection{\\setlength{\\rightskip}{0pt plus 5cm}Runge\\-Kutta::Runge\\-Kutta (int {\\em st}, int {\\em order})}\\label{classRungeKutta_a0}\r\n\r\n\r\n\r\nProvides the greatest relative error in the state vector.\r\n\r\nThis method takes the state vector and calculates the error in\r\neach  component. The error is then divided by the change in the\r\ncomponent. The function returns the largest of the resulting\r\nrelative errors.\r\n\r\nOverride this method if you want a different error estimate for\r\nthe stepsize  control. For example, we are using\r\n\r\n\\[error_i = \\left({{\\Delta_i(t+\\delta t)}\\over {r_i(t+\\delta t) - r_i(t)}}\\right)\\]\r\n\r\nAnother popular approach is to divide the estimated error\r\n$\\Delta_i$ by  the norm of the corresponding 3-vector; for\r\ninstance, divide the error in x  by the magnitude of the\r\ndisplacement in position for the step.\r\n\r\n\r\n\\section{Prince-Dormand Integrators}\r\n\r\n\\section{Adams Bashforth Moulton}  \\index{Numerical\r\nintegrators!Adams-Bashforth-Moulton}\r\n\r\nImplementation of the Adams-Bashford-Moulton Predictor-Corrector.\r\n\r\nThis code implements a fourth-order Adams-Bashford predictor /\r\nAdams-Moulton corrector pair to integrate a set of first order\r\ndifferential equations. The algorithm is found at  {\\tt\r\nhttp://chemical.caeds.eng.uml.edu/onlinec/white/math/s1/s1num/s1num.html}\r\nor in Bate, Mueller and White, pp. 415-417.\r\n\r\nThe predictor step extrapolates the next state $r_{i+1}$ of the\r\nvariables using the the derivative information $(f)$ at the\r\ncurrent state and three  previous states of the variables, by\r\napplying the equation\r\n\r\n\\[ r_{i+1}^{*j} = r_i^j + {{h}\\over{24}}\\left[55 f_n^j - 59 f_{n-1}^j + 37 f_{n-2}^j - 9 f_{n-3}^j \\right] \\]\r\n\r\nThe corrector uses derivative information evaluated for this\r\nstate, along  with the derivative information at the original\r\nstate and two preceding  states, to tune this state, giving the\r\nfinal, corrected state:\r\n\r\n\\[ r_{i+1}^{j} = r_i^j + {{h}\\over{24}}\\left[9 f_{n+1}^{*j} + 19 f_{n}^j - 5 f_{n-1}^j + 1 f_{n-2}^j \\right] \\]\r\n\r\nBate, Mueller and White give the estimated accuracy of this\r\nsolution to be\r\n\r\n\\[ee = {{19}\\over{270}} \\left|r_{i+1}^{*j} - r_{i+1}^{j}\\right|\\]\r\n\r\nMethod used to fire the step refinement (the corrector phase).\r\n\r\n\\section{Bulirsch-Stoer} \\index{Numerical integrators!Bulirsch-Stoer}\r\n\r\n\\section{Stopping Condition Algorithm} \\index{Numerical integrators!Stopping condition algorithm}\r\n\\index{Stopping condition algorithm}\r\n\r\n\\section{Integrator Coefficients} \\index{Numerical integrators!Coefficients}\r\n\r\n\r\n\\input{PD45Coefficients}\r\n\\input{PD56Coefficients}\r\n\\input{RKF56Coefficients}\r\n%\\clearpage\r\n\\input{PD78Coefficients}\r\n", "meta": {"hexsha": "31c290fe68613a224a8c2457329667e2e744610a", "size": 7162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/NumericalIntegrators.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/NumericalIntegrators.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/NumericalIntegrators.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.3786982249, "max_line_length": 137, "alphanum_fraction": 0.7338732198, "num_tokens": 1921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6978985003973862}}
{"text": "\\section{Math}\n\\subsection{Euler Function}\n\\lstinputlisting{\"./math/euler.c\"}\n\n\\subsection{Chinese Remainder Theorem}\n\\[\n\tx \\equiv a_i \\quad (\\mathrm{mod}\\;m_i)\n\\]\n\\lstinputlisting{\"./math/crt.c\"}\n\n\\subsection{FFT}\n\\lstinputlisting{\"./math/fft.cc\"}\n\n\\subsection{Number Theory Inverse}\n\\lstinputlisting{\"./math/inv.cc\"}\n\n\\subsection{Linear Programming}\n\\lstinputlisting{\"./math/lp.cc\"}\n", "meta": {"hexsha": "dca07b5237eeb72e872f35b1c57bd61e230cda2a", "size": 385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math.tex", "max_stars_repo_name": "Abreto/acm-icpc-template", "max_stars_repo_head_hexsha": "43552abf6d03aa5958dfca785aa538548a0e563b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math.tex", "max_issues_repo_name": "Abreto/acm-icpc-template", "max_issues_repo_head_hexsha": "43552abf6d03aa5958dfca785aa538548a0e563b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math.tex", "max_forks_repo_name": "Abreto/acm-icpc-template", "max_forks_repo_head_hexsha": "43552abf6d03aa5958dfca785aa538548a0e563b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2631578947, "max_line_length": 39, "alphanum_fraction": 0.7272727273, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6978532064113593}}
{"text": "\n\n\nThis chapter contains routines for geometric optics solutions of reflection and refraction of rays at dielectric interfaces. All of these solutions are fundamentally based on Snell's law. Specifically, these routines will compute the reflection or reflection point on an interface given the positions of a source and observer as inputs. These algorithms are especially useful for radar scattering and subsurface imaging problems. Many of these solutions are well known. In general, very fast, and much better, codes for geometric optics can be found in the computer graphics literature.\n\nThis chapter contains: 1) routines for computing the reflection point on a plane and sphere, 2) derivations and two routines for solving for the refraction point through the plane: one is analytical, one is iterative, 3) an analytical solution for the refraction point on a circular interface given a pair of interior and exterior source and observation points, 4) a vectorized iterative solution for refraction through a circular interface, and 5) a simple coordinate transform for the solution for the refraction point on a sphere.\n\n\n\n\\section{Snell's Law}\n\nSnell's law of refraction at a flat dielectric half-space is given by \n\\eq{ \\dfrac{\\sin\\theta_1}{\\sin\\theta_2} =  \\dfrac{n_2}{n_1} }\n\n\\noindent where $\\theta_1$ is the angle measured from normal in medium 1 with index of refraction, $n_1$, and $\\theta_2$ is the angle measured from normal in medium 2 with index of refraction, $n_2$. Recall $n = \\sqrt{\\epsilon_r}$, where $\\epsilon_r$ is the relative permittivity.\n\n\n%\n%\\noindent This has the alternate form\n%\n%\\[1 + \\cot^2(\\theta_t) = (1 + \\cot^2(\\theta_i)) \\epsilon_r  \\]\n\n\n\n\\section{Reflection Point - Flat Interface}\n\nHere we find the ray-solution for the specular point for two arbitrary points above a flat surface. One point could be a source, the other a receiver. This can be solved a number of ways, including the image method or by enforcing equal incident and reflected angles relative to the normal of the specular point.\n\nLet two points $\\bb{r}_1$ and $\\bb{r}_2$ be above a flat surface that is parallel to the XY plane at level $z = z_o$. Each half space has a different index of refraction. Define the following quantities \n\\ea{h_1 &=&z_1-z_o \\\\\nh_2 &=& z_2-z_o \\\\\nL &=& \\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2} \\\\\n\\hat{u} &=& \\dfrac{(x_2-x_1)  \\hat{x} + (y_2-y_1)\\hat{y}}{L} }\n\n\\noindent where $\\hat{u}$ is the transverse unit vector from $\\bb{r}_1$ and $\\bb{r}_2$. Define the transverse distance from $\\bb{r}_1$ to the reflection point as $u_1$ and from $\\bb{r}_2$ to the reflection point as $u_2$.  Then for equal incident and reflected angles relative to normal\n\\ea{ \\tan\\theta &=& \\dfrac{u_1}{h_1} \\\\\n\\tan\\theta &=& \\dfrac{u_2}{h_2} }\n\n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=3in]{ReflectionRefraction/Figures/reflectionPlane} \n   \\caption{Geometry for the solution of the planar reflection point, $\\bb{r}$, which is unknown.}\n\\end{figure}\n\nEquating the sines, using the fact that $L = u_1 +u_2$, and solving for $u_1$, we get\n\\eq{u_1 = \\dfrac{h_1 L}{(h_2 + h_1)} }\n\nFrom which the reflection point $\\bb{r}$ is found by reprojecting\n\\eq{\\bb{r} = x_1 \\hat{x} + y_1 \\hat{y} + u_1 \\hat{u} + z_o \\hat{z_o}}\n\nThe routine \\texttt{reflectionPlane} takes as input the two points, $\\bb{r}_1$, $\\bb{r}_2$, and the level of the plane, $z_o$, and returns the reflection point, $\\bb{r}$, as well as $\\theta$ and the lengths of the vectors $l_1$ and $l_2$.  This routine is vectorized for any number of pairs of source and receiver points.  \n\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{ReflectionRefraction/Figures/reflectionraysplane} \n   \\caption{Geometry for the solution of the planar reflection point, $\\bb{r}$, which is unknown off a plane at level $z_o = 0$.}\n\\end{figure}\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/ReflectionRefraction/reflectionPlane.m}\n}\n\n\n\\section{Reflection Point - Sphere}\n\nComputing the reflection point on a sphere is often needed in Earth and planetary remote sensing, for example, when determining the specular point on a body between a source and receiver. The solution here is the one derived in \\cite{reflection_sphere}, and summarized next. The reflection point on a circle can be found with this method by restricting the source and receiver points to a plane.\n\nLet a sphere with radius $r$ be centered at the origin. $\\bb{r}_1$ and $\\bb{r}_2$ are radius-normalized vectors to exterior points 1 and 2, respectively, which can be a source and receiver.  Next, define the following coefficients \n\\ea{a &=& \\bb{r}_1\\cdot\\bb{r}_1 \\\\\nb &=& \\bb{r}_1\\cdot\\bb{r}_2 \\\\\nc &=& \\bb{r}_2\\cdot\\bb{r}_2}\n\nAfter enforcing the reflection condition on the sphere, the solution comes from finding the roots of the following quartic polynomial\n\\eq{\\sum_{n=0}^{4} a_n y^n = 0}\n\\ea{a_4 &=& 4c(ac-b^2) \\\\\na_3 &=& -4(ac-b^2) \\\\\na_2 &=& a+2b+c-4ac \\\\\na_1 &=& 2(a-b) \\\\\na_0 &=& a-1}\n\nOnce the roots are known, the positive roots with zero imaginary part are kept, call these $\\bar{y}$. This is used to compute a second quantity\n\\eq{\\bar{x} = \\dfrac{-2 c \\bar{y}^2 + \\bar{y} + 1}{2 b \\bar{y} + 1}}\n\nThe solution is the pair $(\\bar{x},\\bar{y})$ for which both are positive. Then the reflection point on the sphere is \n\\eq{\\bb{r} = r (\\bar{x} \\bb{r}_1 + \\bar{y} \\bb{r}_2 )}\n\n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=4.5in]{ReflectionRefraction/Figures/reflectonraysphere} \n   \\caption{Geometry for the reflection point on a sphere.}\n\\end{figure}\n\n\\paragraph{Line-Sphere Intersection} \n\nWe exclude shadowed points by using the line-sphere intersection solution, \\cite{linesphereintersect}. The equation for a line that originates at $\\bb{r}_1$ and passes through $\\bb{r}_2$ is\n\\eq{\\bb{u}(l)  = \\bb{r}_1 + l \\hat{u} }\n\n\\noindent where $l$ is the distance along the line and $\\hat{u}$ is\n\\eq{\\hat{u} = \\dfrac{\\bb{r}_2 - \\bb{r}_1}{\\vert \\bb{r}_2 - \\bb{r}_1\\vert}}\n\nFor a sphere with center, $\\bb{c}$, and radius, $r$, the solutions for $l$ are\n\\ea{l &=& -\\hat{u} \\cdot(\\bb{r}_1-\\bb{c}) \\pm \\sqrt{\\Delta} \\\\\n\\Delta &=& \\left(\\hat{u} \\cdot(\\bb{r}_1-\\bb{c})\\right)^2 - \\left(\\Vert \\bb{r}_1 - \\bb{c} \\Vert^2 - r^2\\right)}\n\nIf $\\Delta < 0$ then there are no intersections. If $\\Delta = 0$ then the line is tangent to the sphere. If $\\Delta > 0$ then the line intersects the sphere at two places. In the last case, the reflection point is determined by checking which of the two intersection points is closer to the source.\n\n\\paragraph{Routine}\nThe routine \\texttt{reflectionSphere} solves for the reflection point on a sphere that is centered at the origin. It takes as input the Cartesian points $\\bb{r}_1$, $\\bb{r}_2$, and the sphere radius, $r$, and returns the reflection point, $\\bb{r}$, which lies on the surface of the sphere. The routine is vectorized to take multiple pairs of points at once, and returns \\texttt{nan} if the points are shadowed or interior to the sphere. Shadowing is determined by the routine \\texttt{lineIntersectSphere}, not copied here, that implements the line-sphere intersection solution above. \n\n{\\footnotesize\n\\VerbatimInput{\\code/ReflectionRefraction/reflectionSphere.m}\n}\n\n\n\\section{Refraction Point - Flat Interface}\n\nWe derive two solutions for the refraction point through a flat dielectric interface given two arbitrary points on either side of the interface. The first solution is in terms of the roots of a quartic polynomial, \\cite{heliere2007radio}. The second is an iterative algorithm, \\cite{lei20202}. Practical applications of this are subsurface SAR processing, e.g. radar sounding through ice, ground penetrating radar, or through-wall imaging, where the propagation phase between two points across a dielectric interface needs to be computed for focusing. In these cases, the refraction point is really an intermediate result in order to obtain the incidence and transmission angles and propagation distances along the bent-ray path.  \n\nThe geometry is shown in Figure \\ref{fig9a}. The dielectric interface is parallel to the $XY$ plane at level $z = z_o$. Let two points $\\bb{r}_1$ and $\\bb{r}_2$ be above and below the interface in mediums 1 and 2 each having an index of refraction, $n_1$ and $n_2$, respectively. Next define the following quantities, \n\\ea{h &=& z_1 - z_o \\\\\nd &=& z_2 - z_o \\\\\nL &=& \\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2} \\\\\n\\hat{u} &=& \\dfrac{(x_2-x_1)  \\hat{x} + (y_2-y_1)\\hat{y} }{L}}\n \n\\noindent \\noindent where $h$ is the height of $\\bb{r}_1$ above the interface, $d$ is the depth of $\\bb{r}_2$ below the interface, $\\hat{u}$ is the transverse unit vector and $L$ is the transverse distance from point 1 to point 2. Finally, $u$ is the transverse distance along $\\hat{u}$ between the projection of $\\br_1$ on the interface and the refraction point.\n \n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=3in]{ReflectionRefraction/Figures/refractionPlane} \n   \\caption{Geometry for the solution of the planar refraction point, $\\bb{r}$, which is unknown.}\n   \\label{fig9a}\n\\end{figure}\n\n\\subsubsection{Quartic Solution}\n \nStart with the observations that \n\\begin{eqnarray} \n\\sin\\theta_1 &=& \\dfrac{u}{\\sqrt{h^2 + u^2}} \\nonumber \\\\\n\\sin\\theta_2 &=& \\dfrac{L-u}{\\sqrt{d^2 + (L-u)^2}} \\nonumber\n\\end{eqnarray}\n\nThese are equated though Snell's law\n\\eq{\\dfrac{u}{\\sqrt{h^2 + u^2}}   = \\dfrac{n_2}{n_1}\\dfrac{L-u}{\\sqrt{d^2 + (L-u)^2}} } \n\nAfter squaring both sides, this can be rearranged as a fourth order polynomial in $u$:\n\n\\eq{ a u^4 + b u^3 + c u^2 + d u + e = 0}\n\\begin{eqnarray} \na &=& n_1^2 - n_2^2 \\nonumber \\\\\nb &=& -2 L (n_1^2 - n_2^2) \\nonumber \\\\\nc &=& n_1^2(L^2  + d^2) - n_2^2( L^2 + h^2) \\nonumber \\\\\nd &=& 2 n_2^2 L h^2 \\nonumber \\\\\ne &=& -n_2^2 L^2 h^2  \\nonumber\n\\end{eqnarray}\n\nThe roots can be found with a root finding algorithm or analytically. The solution is the positive real root for which $u < L$.  This solution is good for either $n_1 > n_2$ or $n_1 < n_2$. Once found, $u$ is reprojected to give the refraction point: \n\\eq{\\bb{r} = x_1 \\hat{x} + y_1 \\hat{y} + u \\hat{u} + z_o \\hat{z}}\n\n\\subsubsection{Iterative Solution}\nFor the iterative solution, we use the facts that  \n\\begin{eqnarray} \nu &=& h \\tan \\theta_1 \\\\\nu &=& L - d \\tan \\theta_2 \n\\end{eqnarray}\n\nStart with the straight-ray approximation for $\\theta_1$, then with the addition of Snell's law, we can build the following iteration\n\\begin{eqnarray}\n\\textrm{Initialize:} \\quad \\quad \\theta_1 &\\leftarrow &\\arctan\\left( \\dfrac{L}{h + d}\\right) \\ \\nonumber \\\\\n\\textrm{Iterate:} \\quad \\quad\\theta_2 &\\leftarrow &\\arcsin\\left(\\dfrac{n_1}{n_2} \\sin\\theta_1\\right) \\nonumber  \\\\\nu & \\leftarrow &L - d \\tan\\theta_2 \\nonumber  \\\\\n\\theta_1 &\\leftarrow&  \\arctan\\left( \\dfrac{u}{h}\\right) \\nonumber\n\\end{eqnarray}\n\nThis is an alternating sequence for $u$ (and $\\theta_1$, $\\theta_2$). The physical interpretation is that the value of $u$ bounces closer to the true solution at every iteration. This is effectively a Newton iteration of the transcendental equation for $\\theta_1$ without a nonlinear optimization algorithm. The solution is lightning fast (requiring maybe 10 iterations), when it works. The solution does not always converge, which happens when $h$ is too close to the interface relative to values of $d$ and $L$. In other words, this solution is valid when $d,L \\le h$. Also, as written, this should only be used when $n_1 < n_2$.  \n\n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=3.5in]{ReflectionRefraction/Figures/refractionraysplane} \n   \\caption{Refraction through a plane, $n_1 = 1$, $n_2 = 2$.}\n\\end{figure}\n\\subsubsection{Routine}\n\nThe routine \\texttt{refractionPlane} takes as input the coordinates of $\\bb{r}_1$, $\\bb{r}_2$, $z_o$, $n_1$ and $n_2$, and returns the coordinates of the refraction point $\\bb{r}$ on the interface, the angles $\\theta_1$, $\\theta_2$, and lengths of the vectors to the refraction point, $l_1$ and $l_2$. The quartic solution is used by default. Use the optional string switch \\texttt{'it'} for the iterative solution. For the latter, the routine estimates the required number of iterations by testing a point with the largest free-space $\\theta_1$, then applies that number of iterations to all other points in parallel.  The routine is vectorized to take one point, $\\bb{r}_1$, while the coordinates of subsurface points, $\\bb{r}_2$, can be arrays of any size (all the same size). Outputs are the same size as the $\\bb{r}_2$ coordinates. This assumes $n_1$ and $n_2$ are real. The case when $\\bb{r}_2$ is at or above the boundary is handled separately. \n\n\n\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/ReflectionRefraction/refractionPlane.m}\n}\n\n\n\n\\section{Refraction Point - Circular Interface}\nWe provide two solutions for the refraction point on circular interface. The first is a semi-analytical solution in terms of the roots of a sixth degree polynomial. The second is a vectorized iterative solution that is valid for weak refraction. \n\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Refraction Point - Circular Interface - Analytical}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\\label{sec:refractdir}\nA semi-analytic solution for the refraction point on a circular interface is derived for an arbitrary interior and exterior point. This is based on satisfying Snell's law at the interface. Similar to the quartic solution for the refraction point on a flat surface, the solution is found in terms of the roots of a sixth degree polynomial. An alternative approach is to apply the principle of least action to the total electrical path length of the rays. Both approaches give the same result.\n\nThe geometry is shown in Figure \\ref{refractthroughcircle}. Let a circle be centered at the origin with radius $r$. The indices of refraction outside and inside the circle are $n_1$ and $n_2$, respectively. Let the exterior and interior points be, $\\bb{r}_1$, $\\bb{r}_2$, and the refraction point on the circle, $\\bb{r}$.  Arbitrary  exterior/interior points are rotated so that the exterior point is aligned with the $y$ axis. Once the refraction point is found in this geometry, it is rotated back. Start with \n\\ea{\\bb{r}_1 &=& y_1 \\hat{y} \\\\\n\\bb{r}_2 &=& x_2 \\hat{x} + y_2 \\hat{y} \\\\\n\\bb{r} &=& r_x \\hat{x} + r_y \\hat{y} }\n\n\\noindent where $y_1 > r$ and $r^2 = r_x^2 + r_y^2$.  Also, define the vectors $\\bb{v}_1 = \\bb{r}_1 - \\bb{r}$ and $\\bb{v}_2 = \\bb{r}_2 - \\bb{r}$.  The sine of the incident and transmission angles at the refraction point can be written as the following cross products:\n\\ea{\\sin\\theta_1 \\hat{z} &=& \\dfrac{\\bb{r} \\times \\bb{v}_1}{\\vert \\bb{r} \\vert \\vert \\bb{v}_1\\vert } \\\\\n\\sin\\theta_2 \\hat{z} &=& \\dfrac{(-\\bb{r}) \\times \\bb{v}_2}{\\vert \\bb{r} \\vert \\vert \\bb{v}_2\\vert }  }\n\n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=2.5in]{ReflectionRefraction/Figures/refractionCircle} \n   \\caption{Geometry for refraction through a circle. }\n   \\label{refractthroughcircle}\n\\end{figure}\n\nEquating through Snell's law, expanding the cross products, and squaring both sides, we get \n\\eq{\\dfrac{r_x^2 y_1^2}{r_x^2 + (y_1-r_y)^2} = \\left(\\dfrac{n_2}{n_1}\\right)^2 \\dfrac{(r_xy_2 - r_y x_2)^2}{(x_2 - r_x)^2 + (y_2-r_y)^2}} \n\nNext, expand the squares, substitute $r_y^2 = r^2 - r_x^2$, and collect terms to get \n\n%\\eq{\\dfrac{r_x^2 y_1^2}{r_x^2 + r_y^2 - 2r_y y_1 + y_1^2} = \\left(\\dfrac{n_2}{n_1}\\right)^2 \\dfrac{(r_xy_2 - r_y x_2)^2}{x_2^2 - 2x_2r_x + r_x^2 + r_y^2 - 2r_y y_2 + y_2^2}} \n%\n%\\eq{\\dfrac{(n_1^2/n_2^2)  y_1^2r_x^2 }{r^2 - 2r_y y_1 + y_1^2} =   \\dfrac{ r_x^2y_2^2 -2r_y x_2r_xy_2 +  (r^2 - r_x^2) x_2^2}{x_2^2 - 2x_2r_x + r^2 - 2r_y y_2 + y_2^2}} \n%\n%\\eq{\\dfrac{(n_1^2/n_2^2)  y_1^2r_x^2}{r^2+ y_1^2 - 2 y_1r_y } =   \\dfrac{ (y_2^2 -  x_2^2)r_x^2 -2 x_2y_2r_yr_x +  r^2x_2^2  }{x_2^2 + y_2^2+ r^2 - 2x_2 r_x  - 2y_2 r_y }} \n\n\\eq{\\dfrac{c_1 r_x^2}{c_2  + c_3 r_y } =   \\dfrac{ c_4 r_x^2 + c_5 r_yr_x +  c_6 }{c_7 + c_8 r_x  + c_9 r_y }} \n\n\\noindent where $c_n = \\left\\{(n_1^2/n_2^2)  y_1^2, r^2+ y_1^2, - 2y_1, y_2^2 -  x_2^2, -2 x_2y_2, r^2x_2^2, x_2^2 + y_2^2+ r^2, - 2x_2, - 2y_2\\right\\}, n = 1... 9$. To proceed, multiply through by the denominators, substitute $r_y^2$ again where it occurs, and collect $r_y$ on one side of the equation, then \n\\eq{b_1 r_x^3 + b_2 r_x^2  + b_3 r_x +b_4 = (b_5 r_x^2 + b_6 r_x + b_7 )r_y}\n\n\\noindent where $b_n = \\left\\{c_3 c_5 + c_1 c_8,  c_1 c_7 - c_2 c_4, -c_3 c_5 r^2, -c_2c_6, c_3c_4 - c_1 c_9, c_2c_5, c_3c_6\\right\\}, n = 1...7$.  Squaring both sides once more, substituting $r_y^2$ a third time, this can be written as a sixth degree polynomial in $r_x$ as\n\\eq{\\sum_{n=0}^6 a_n r_x^n = 0}\n\\ea{a_6 &=& b_1^2 + b_5^2  \\\\\na_5 &=& 2 b_1 b_2 + 2 b_5 b_6  \\\\\na_4 &=&  b_2^2 - b_5^2 r^2 + 2 b_7 b_5 + b_6^2 + 2 b_1 b_3  \\\\\na_3 &=& - 2 b_5 b_6 r^2 + 2 b_1 b_4 + 2 b_2 b_3 + 2 b_6 b_7 \\\\\na_2 &=& b_3^2 - b_6^2 r^2 + b_7^2 - 2 b_5 b_7 r^2 + 2 b_2 b_4 \\\\ \na_1 &=& - 2 b_6 b_7 r^2 + 2 b_3 b_4 \\\\\na_0 &=& b_4^2 - b_7^2 r^2 }\n\n%\\ea{c_1 &=& (n_1^2/n_2^2)  y_1^2  \\\\\n%c_2 &=&  r^2+ y_1^2  \\\\\n%c_3 &=& - 2y_1 \\\\\n%c_4&=& y_2^2 -  x_2^2 \\\\ \n%c_5&=& -2 x_2y_2 \\\\\n%c_6 &=& r^2x_2^2  \\\\\n%c_7 &=& x_2^2 + y_2^2+ r^2 \\\\\n%c_8 &=& - 2x_2 \\\\\n%c_9 &=& - 2y_2}\n%\\ea{b_1 &=& c_3 c_5 + c_1 c_8  \\\\\n%b_2 &=&  c_1 c_7 - c_2 c_4  \\\\\n%b_3 &=& -c_3 c_5 r^2 \\\\\n%b_4&=& -c_2c_6 \\\\ \n%b_5 &=& c_3c_4 - c_1 c_9 \\\\\n%b_6 &=& c_2c_5  \\\\\n%b_7 &=& c_3c_6 }\n\n%\\ea{a_6 &=& b_1^2 + b_5^2  \\\\\n%a_5 &=& 2 b_1 b_2 + 2 b_5 b_6  \\\\\n%a_4 &=&  b_2^2 - b_5^2 r^2 + 2 b_7 b_5 + b_6^2 + 2 b_1 b_3  \\\\\n%a_3 &=& - 2 b_5 b_6 r^2 + 2 b_1 b_4 + 2 b_2 b_3 + 2 b_6 b_7 \\\\\n%a_2 &=& b_3^2 - b_6^2 r^2 + b_7^2 - 2 b_5 b_7 r^2 + 2 b_2 b_4 \\\\ \n%a_1 &=& - 2 b_6 b_7 r^2 + 2 b_3 b_4 \\\\\n%a_0 &=& b_4^2 - b_7^2 r^2 }\n\nOnce the roots are computed, they are sifted to find the valid solution, because squaring twice created extraneous solutions. Roots with a non-zero imaginary part are rejected. Then $r_y$ is computed and only solutions that satisfy Snell's law at the boundary are kept. In the event of a tie, the refraction point that gives the smallest electrical distance is kept, consistent with the principle of least action. Finally, we check that $\\theta_1 < \\pi/2$ to make sure the ray does not pass through the circle twice (this angle is computed with the dot product of $\\bb{r}$ and $\\bb{v}_1$ to safely handle $\\pm \\hat{x}$ solutions). \n\n\n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=3.5in]{ReflectionRefraction/Figures/refractionrayscircle} \n   \\caption{Refraction into a circle between two points. Exterior index of refraction $n_1 = 1$, interior index of refraction $n_2 = 2$, and radius $r = 1$. }\n\\end{figure}\n\n\nThe routine \\texttt{refractionCircle} takes as input the coordinates of an arbitrary exterior point, $\\bb{r}_1$, an arbitrary interior point, $\\bb{r}_2$, index of refractions $n_1$, $n_2$ and radius $r$, and returns the coordinates of the refraction point on the circle, the incident and transmission angles $\\theta_1$ and $\\theta_2$ in radians, and the magnitudes of the vectors $\\bb{v}_1$ and $\\bb{v}_2$. It first rotates the points to align them with the $y$ axis. It returns \\texttt{nan} if no solution exists. It also assumes $n_1$ and $n_2$ are real.  Because this relies on \\texttt{roots} it is not vectorized. \n\n{\\footnotesize\n\\VerbatimInput{\\code/ReflectionRefraction/refractionCircle.m}\n}\n\n%\n%\\newpage\n%\n%\\section{Refraction Point - Circular Interface}\n%\n%\\ea{\\bb{r}_1 &=& x_1 \\hat{x} + y_1 \\hat{y} \\\\\n%\\bb{r}_2 &=& x_2 \\hat{x} + y_2 \\hat{y} \\\\\n%\\bb{r} &=& r_x \\hat{x} + r_y \\hat{y} }\n%\n%\\noindent where $r^2 = r_x^2 + r_y^2$.  Define the vectors\n%\\ea{\\bb{v}_1 &=& \\bb{r}_1 - \\bb{r} \\\\\n%\\bb{v}_2 &=& \\bb{r}_2 - \\bb{r} }\n%\n%The total electrical path length is \n%\\eq{L = n_1 v_1 + n_2 v_2}\n%\n%We want the point $(r_x,r_y)$ that gives the minimum of $L$.  Writing out the magnitudes of the vectors, substituting $r_y = \\sqrt{r^2 + r_x^2}$, differentiating with respect to $r_x$, setting the derivative to zero, moving one term to the other side of the equation, squaring both sides, and collecting terms, one can arrive at \n%\n%\\eq{\\dfrac{ c_1 r_x^2 + c_2 r_x \\sqrt{r^2 - r_x^2}  + c_3}{c_4 r_x + c_5 \\sqrt{r^2 - r_x^2} + c_6} = \\dfrac{c_7 r_x^2 + c_8 r_x   \\sqrt{r^2 - r_x^2}+ c_9}{c_{10} r_x + c_{11} \\sqrt{r^2 - r_x^2} + c_{12}}}\n%\n%\\ea{c_1 &=& n_1^2 x_1^2 - n_1^2 y_1^2 \\\\\n%c_2 &=& 2 n_1^2 x_1 y_1 \\\\\n%c_3 &=& -n_1^2 r^2 x_1^2 \\\\\n%c_4 &=& 2 x_1 \\\\\n%c_5 &=& 2 y_1 \\\\\n%c_6 &=& -r^2 - x_1^2 - y_1^2 \\\\\n%}\n%\n%\\noindent where $c_7...c_{12}$ are the same as $c_1...c_6$ except subscript 1 is changed to 2.  Next, multiplying through by the denominators, simplifying, and collecting factors of $r_x$ and $\\sqrt{r^2 - r_x^2}$, one can get \n%\\eq{b_1 r_x^3 + b_2 r_x^2 + b_3 r_x + b_4 = \n%(b_5 r_x^2  + b_6 r_x + b_7) \\sqrt{r^2 - r_x^2}}\n%\n%\\ea{b_1 &=& c_1 c_{10} - c_4 c_7 - c_2 c_{11} + c_5 c_8 \\\\\n%b_2 &=& c_1 c_{12} - c_6 c_7\\\\\n%b_3 &=& c_3 c_{10} - c_4 c_9 + (c_2 c_{11} - c_5 c_8) r^2\\\\\n%b_4 &=& c_3 c_{12} - c_6 c_9\\\\\n%b_5 &=& c_4 c_8 + c_5 c_7 - c_1 c_{11} - c_2 c_{10}\\\\\n%b_6 &=& c_6 c_8 - c_2 c_{12}\\\\\n%b_7 &=& c_5 c_9 - c_3 c_{11}}\n%\n%Finally, squaring both sides again and collecting powers of $r_x$, this can be written as a sixth degree polynomial as\n%\n%\\eq{\\sum_{n=0}^6 a_n r_x^n = 0}\n%\\ea{a_6 &=& b_1^2 + b_5^2  \\\\\n%a_5 &=& 2 (b_1 b_2 + b_5 b_6)\\\\\n%a_4 &=& b_2^2 - b_5^2 r^2 + 2 b_7 b_5 + b_6^2 + 2 b_1 b_3\\\\\n%a_3 &=& 2 (-b_5 b_6 r^2 + b_1 b_4 + b_2 b_3 + b_6 b_7)\\\\\n%a_2 &=& 2 b_2 b_4 - r^2 (b_6^2 + 2 b_5 b_7) + b_3^2 + b_7^2\\\\\n%a_1 &=& 2 (-b_6 b_7 r^2 + b_3 b_4)\\\\\n%a_0 &=& b_4^2 - b_7^2 r^2 }\n%\n%(This was all done with a symbolic tool of course). Once the roots are found, they need to be sifted to find the valid solution, because the effect of squaring twice has introduced extraneous solutions. Roots with an imaginary part are rejected. Then $r_y$ is computed and then $\\sin(\\theta_1)$ and $\\sin(\\theta_2)$ are computed from the cross products of the vectors. Only solutions that satisfy Snell's law are kept. In the event of a tie, the refraction point that gives the smallest electrical distance is kept, consistent with the principle of least action. Finally, we check that $\\theta_1 < \\pi/2$ to make sure the ray does not pass through the circle twice, where the angle is computed with the dot product of $\\bb{r}$ and $\\bb{v}_1$ to safely handle $\\pm$ coordinate solutions.  \n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Refraction Point - Circular Interface - Iterative}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\\label{sec:refractit}\nWhile the solution for refraction through a circular interface in the previous section is exact, the code could not be vectorized because it required the roots of a sixth degree polynomial. However, like the planar interface, a vectorized iterative solution can be derived. Its validity is restricted to mild refraction and small angles but it is lightning fast when it works. The primary application for this is subsurface SAR focusing in, for instance, radar sounding through ice at planetary bodies, where the body curvature needs to be included in the refraction for a large number of subsurface focal points.  \n\nUsing the geometry in Figure \\ref{refractthroughcircle}, define:\n\\ea{h &=& y_1 - r \\\\\nd &=& r - y_2}\n\nUsing the fact that \n\\eq{\\sin\\theta_1 = \\dfrac{r + h}{r}\\sin\\theta_l}\n\nwe can build an iteration as\n\\begin{eqnarray}\n\\textrm{Initialize:} \\quad \\quad \\theta_l &\\leftarrow &\\arctan\\left( \\dfrac{x_2}{h + d}\\right) \\ \\nonumber \\\\\n\\textrm{Iterate:} \\quad \\quad\\theta_1 &\\leftarrow &\\arcsin\\left( \\dfrac{r + h}{r}\\sin\\theta_l \\right) \\nonumber  \\\\\n\\theta_2  &\\leftarrow & \\arcsin\\left( \\dfrac{n_2}{n_1} \\sin\\theta_1 \\right) \\\\\n\\theta_p  &\\leftarrow & \\theta_2 - (\\theta_1 - \\theta_l) \\\\\n(r_x, r_y) &\\leftarrow & \\textrm{ComputeIntersection}(\\theta_p) \\\\\n\\theta_l  &\\leftarrow &  \\arctan\\left( \\dfrac{r_x}{h + r  - r_y}\\right) \\nonumber\n\\end{eqnarray}\n\n\\noindent where $\\theta_p$ is the angle from the perpendicular at the refraction point to the interior point, and $\\textrm{ComputeIntersection}(\\theta_p)$ computes the point at which a line from the interior point with slope corresponding to $\\theta_p$ intersects the circle.  \n\nThis iteration starts with the straight ray approximation for the look angle $\\theta_l$ from which it computes the incident angle on the circle, $\\theta_1$. With this, the transmission angle, $\\theta_2$, is computed via Snell's law. Next, $\\theta_p$ is the portion of $\\theta_2$ relative to the perpendicular.  Using this, we project a line from the interior point to intersect the circle. The slope of the line corresponds to the angle $\\theta_p$. With the new point on the circle, the look angle is computed again and the process repeats.  This is again a Newton iteration of the transcendental solution for one of the variables. As before, the solution is not the most robust and should be used when the refraction is mild.\n\n\\begin{figure}[h] \n   \\centering\n   \\subfigure{\\includegraphics[width=2in]{ReflectionRefraction/Figures/refractioncirclethetap}}\n   \\subfigure{\\includegraphics[width=3in]{ReflectionRefraction/Figures/refractionrayscircleiterative}}\n   \\caption{Left: Angles at the refraction point for iterative solution. Right:Refraction into a circle between multiple points using the vectorized iterative solution. Exterior index of refraction $n_1 = 1$, interior index of refraction $n_2 = 2$, and radius $r = 1$.  }\n\\end{figure}\n\n\n\n%\n%\\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=2in]{ReflectionRefraction/Figures/refractioncirclethetap} \n%   \\caption{Angles at the refraction point for iterative solution.}\n%\\end{figure}\n%\n%\n%\\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=3in]{ReflectionRefraction/Figures/refractionrayscircleiterative} \n%   \\caption{Refraction into a circle between multiple points using the vectorized iterative solution. Exterior index of refraction $n_1 = 1$, interior index of refraction $n_2 = 2$, and radius $r = 1$. }\n%\\end{figure}\n\n\n\\clearpage\n\\paragraph{Intersection of Circle and Line}\n\nGiven a line $y = mx + b$ and a circle $(x-p)^2 + (y-q)^2 = r^2$, the point of intersection $(X,Y)$ is found by substituting the first equation into the second and solving the resulting quadratic for $x$:\n\\begin{eqnarray}\nA &=& m^2 + 1 \\nonumber \\\\\nB &=& 2(mb - mq - p) \\nonumber \\\\\nC &=& q^2 - r^2 + p^2 - 2bq +b^2 \\nonumber \\\\\nX &=& \\dfrac{-B \\pm \\sqrt{B^2 - 4AC}}{2A} \\nonumber \\\\\nY &=& mX + b \\nonumber\n\\end{eqnarray}\n\n\\paragraph{ComputeIntersection($\\theta_p$)}\nLet the center of the circle be the origin $(p,q)=(0,0)$. The line with slope corresponding to angle $\\theta_p$ passing though the interior point at $(x_2, y_2)$ is given by \n\\eq{y = -\\cot\\theta_p(x - x_2) + y_2  }\n\nThe parameters used in the equations above for the intersection of the line and circle are therefore\n\\begin{eqnarray}\nm &=& -\\cot \\theta_p \\nonumber \\\\\nb &=& x_2\\cot\\theta_p + y_2 \\nonumber \\\\\nA &=& m^2 + 1 \\nonumber \\\\\nB &=& 2mb \\nonumber \\\\\nC &=& -r^2 + b^2 \\nonumber \n\\end{eqnarray}\n\nFor this problem, the choice of quadratic root is determined by the sign of $x_2$. Furthermore, if the $y$ coordinate of the refraction point is negative at any point in the iteration, then the other root is chosen. Points that are collinear with the origin and the source, where there is no refraction, need to be handled separately. Finally, in this geometry, the look angle is given by \n\\eq{\\tan\\theta_l = \\dfrac{r_x}{h + r - r_y} }\n\n\nThe routine \\texttt{refractionCircleIterative} is a vectorized implementation of the routine above. It takes an input pairs of $\\bb{r}_1$, $\\bb{r}_2$, the index of refraction $n_1$, $n_2$, radius $r$, and number of iterations, \\texttt{nit}, and returns the refraction points, $\\bb{r}$, incident and transmission angles $\\theta_1$, $\\theta_2$, $\\theta_l$, and the lengths of the vectors $\\bb{v}_1$ and $\\bb{v}_2$. The point arrays can be any size. This assumes $n_1$ and $n_2$ are real. This should only be used in its present form for large radii, and depths that are less than or equal to the heights. Set \\texttt{nit} to be 10 or larger, it defaults to 40. The algorithm rotates points to align the exterior points to the $y$ axis, to be consistent with the solution as written, then rotates them back.\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/ReflectionRefraction/refractionCircleIterative.m}\n}\n\n\n\\section{Refraction Point - Sphere}\n\nWe can adapt the solution for the refraction point over a circle to that for an arbitrary interior and exterior points over a sphere.  Let $\\bb{r}_1$ be the exterior point, $\\bb{r}_2$ be the interior point, and $\\bb{r}$ be the point of refraction on the sphere.  The sphere has radius $r$ centered at the origin.  Define a new coordinate system $[\\hat{u}, \\hat{v}, \\hat{w}]$ in the $\\bb{r}_1$-$\\bb{r}_2$ plane such that \n\\ea{\\hat{v} &=& \\hat{r}_1  \\\\\n\\hat{w} &=& \\dfrac{\\bb{r}_2 \\times \\hat{v}}{\\vert \\bb{r}_2 \\times \\hat{v} \\vert }  \\\\\n\\hat{u} &=& \\hat{v} \\times \\hat{w} \n}\n\nThe exterior and interior points are represented in this frame as\n\\ea{\\bb{r}_1' &=& \\vert \\bb{r}_1 \\vert \\hat{v}  \\\\\n\\bb{r}_2' &=& \\left( \\bb{r}_2 \\cdot \\hat{u}  \\right)\\hat{u}  + \\left( \\bb{r}_2 \\cdot \\hat{v}  \\right)\\hat{v}   }\n\nThe coordinates of $\\bb{r}_1'$ and $\\bb{r}_2'$ can now be used as inputs to either of the two circular refraction routines from Section \\ref{sec:refractdir} or \\ref{sec:refractit}. The magnitude of $\\bb{r}_1'$ in the $\\hat{v}$ direction corresponds to the $y$-coordinate of the exterior point in both routines, while $\\left( \\bb{r}_2 \\cdot \\hat{u}  \\right) $ and $\\left( \\bb{r}_2 \\cdot \\hat{v}  \\right)$ correspond to the $x$ and $y$ coordinates, respectively, of the interior point in both routines. Once solved, the $x$ and $y$ coordinates of the refraction point on the 2D circle, $r_x$ and $r_y$, are mapped back to the original 3D frame as \n\\eq{ \\bb{r} = r_x \\hat{u} + r_y \\hat{v}}\n\nThe routine \\texttt{refractionSphere} computes the refraction through a sphere that is centered at the origin. It takes as input the Cartesian coordinates of pairs of exterior and interior points of any array size, the index of refraction for the exterior and interior, $n_1$, $n_2$, respectively, and the radius of the sphere $r$. The outputs are the coordinates of the refraction point on the sphere, incident angle, transmission angle, and look angle which measured from the radial line of the exterior point, as well as the two path lengths inside and outside the sphere. The routine transforms the input coordinates using the mapping above in order to use the circle refraction algorithms, \\texttt{refractionCircle} or \\texttt{refractionCircleIterative}. The routine defaults to the direct circle refraction solution which loops over each pair of points. The direction solution can also be chosen using the string switch \\texttt{'dir'}. Use string switch \\texttt{'it'} to select the vectorized iterative circle refraction solution which can also take an optional input argument for the number of iterations.  \n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{ReflectionRefraction/Figures/refractionspheredirect} \n   \\caption{Refraction into a sphere between multiple points. Exterior index of refraction $n_1 = 1$, interior index of refraction $n_2 = 2$, and sphere radius $r = 1$. }\n\\end{figure}\n\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/ReflectionRefraction/refractionSphere.m}\n}\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "bd19a14a141a6f606b14ba608fae79aba94cbe64", "size": 31312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/ReflectionRefraction/ReflectionRefraction.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/ReflectionRefraction/ReflectionRefraction.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/ReflectionRefraction/ReflectionRefraction.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": 66.3389830508, "max_line_length": 1114, "alphanum_fraction": 0.7067258559, "num_tokens": 10552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.6978219518686223}}
{"text": "\\lab{Algorithms}{GMRES}{GMRES}\n\\label{lab:GMRES}\n\\objective{In this lab we will learn how to use the GMRES algorithm.}\n\nThe GMRES (``Generalized Minimal Residuals\") algorithm solves linear systems of the form $Ax=b$ for nonsymmetric matrices that are so\nlarge that either they cannot be stored in memory, or direct methods cannot run to completion in a reasonable time.\nIt is an iterative method that relies on Krylov subspaces to reduce a high-dimensional problem to a sequence of smaller dimensional\nproblems.\n\n\\section*{The Arnoldi Iteration and Approximate Solutions}\nThe basic idea of GMRES is as follows.\nLet $A$ be an $m\\times m$ matrix (real or complex), where $m$ is very large,\nand let $b \\in \\mathbb{F}^m$ ($\\mathbb{F}$ may either be the real or complex numbers).\nLet $\\mathcal{K}_n$ denote the order-$n$ Krylov subspace generated by $A$ and $b$.\nIn each iteration, we consider the least squares problem\n\\begin{equation}\n\\underset{x \\in \\mathcal{K}_n}{\\text{minimize}}\\qquad \\|b-Ax\\|_2.\n\\label{eq:GMRES_lstsq1}\n\\end{equation}\nNow if $x \\in K_n$, then $x$ can be expressed as a linear combination of basis vectors $b, Ab, \\ldots, A^{n-1}b$, i.e.\n\\[\nx = y_1b + y_2Ab + \\cdots + y_nA^{n-1}b.\n\\]\nIf we let $K_n$ be the matrix whose columns are $b, Ab, A^{2}b, \\cdots, A^{n-1}b$, then we can write this simply as\n$x = K_n y$.\nThen the solution of the least squares problem is the vector $K_{n}y$ such that $\\|b-A K_{n}y\\|_2$ is minimized.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{LeastSquares}\n\\caption{GMRES involves solving the least squares problem repeatedly.}\n\\end{figure}\n\nThe major drawback of this approach is that it relies on the matrix $K_n$, which tends to be ill-conditioned due to its columns\nbeing far from orthogonal (as discussed in Lab \\ref{lab:kry_arnoldi}).\n%To see this, suppose there is an eigenbasis for $A$ with associated eigenvalues, and suppose $\\lambda$ is the largest eigenvalue.\n%Then $\\lambda^n$ is an eigenvalue of $A^n$.\n%Since $\\lambda$ is bigger than the other eigenvalues of $A$, $\\lambda^n$ may be much, much bigger than the other eigenvalues of $A^n$,\n%which are simply the eigenvalues of $A$ raised to the $n$th power.\n%Thus the eigenvector associated with $\\lambda$ often begins to dominate as we progress, with the end result being that the columns of\n%$K_n$ become nearly linearly dependent.\nThe easiest fix in this situation is to use the Arnoldi iteration so that we have an orthonormal basis for $\\mathcal{K}_n$ to work with.\nNot only does this alleviate the problem of ill-conditioning, it also allows us to optimize in other ways, due to the special\nstructure of the matrices produced.\n\nLet $q_1,\\ldots, q_n$ be the orthonormal basis for $\\mathcal{K}_n$ obtained by the Arnoldi iteration, and let $Q_n$ be the matrix\nhaving these vectors as its columns.\nRecall that $q_1 = b/\\|b\\|_2$.\nFinally, let $H_n$ be the $(n+1)\\times n$ upper Hessenberg matrix generated by the Arnoldi iteration, and let $e_1=(1,0,\\cdots,0)$.\n\nIn this orthonormal basis, $x \\in \\mathcal{K}_n$ implies that there is some vector $y$ such that $x = Q_n y$.\nFurther, it is not hard to check that the matrices generated by the Arnoldi iteration satisfy the equation\n\\[\nAQ_n = Q_{n+1}H_n.\n\\]\nWe also have the identity\n\\[\nb = \\|b\\|_2q_1 = \\|b\\|_2Q_{n+1}e_1.\n\\]\nPutting all of this together, we can rewrite the objective function of our least squares problem as follows:\n\\begin{align*}\n\\|b - Ax\\|_2 &= \\|Ax - b\\|_2\\\\\n&= \\|AQ_ny - b\\|_2\\\\\n&= \\|Q_{n+1}H_ny - \\left(\\|b\\|_2Q_{n+1}e_1\\right)\\|_2\\\\\n&= \\|Q_{n+1}\\left(H_n y - \\|b\\|_2e_1\\right)\\|_2.\n\\end{align*}\n\nThe matrix $Q_{n+1}$ has orthonormal columns, but it does not have enough columns to be a unitary matrix.\nLet us extend the set $q_1,\\ldots, q_{n+1}$ to an orthonormal basis $q_1,\\ldots,q_{n+1},q_{n+2},\\ldots,q_m$\nof our space, and let $Q'$ be the matrix whose columns are equal to these vectors.\nThen $Q'$ is now a unitary matrix, and hence preserves the norm, i.e. $\\|Q'z\\|_2 = \\|z\\|_2$ for all $z \\in \\mathbb{F}^m$.\nGiven $x \\in \\mathbb{F}^{n+1}$, if we define $x' \\in \\mathbb{F}^m$ to be\n\\[\nx' =\n\\begin{bmatrix}\n  x\\\\\n  0\\\\\n  \\vdots\\\\\n  0\n\\end{bmatrix},\n\\]\nthen you can easily check that\n\\[\nQ'x' = Q_{n+1}x.\n\\]\nFrom this, we deduce that\n\\begin{align*}\n\\|Q_{n+1}x\\|_2 &= \\|Q'x'\\|_2\\\\\n& = \\|x'\\|_2\\\\\n&= \\|x\\|_2.\n\\end{align*}\nHence, we conclude that\n\\[\n\\|Q_{n+1}\\left(H_n y - \\|b\\|_2e_1\\right)\\|_2 = \\|H_n y - \\|b\\|_2e_1\\|_2.\n\\]\nThus, the least squares problem given by \\ref{eq:GMRES_lstsq1} is equivalent to the problem\n\\begin{equation}\n\\underset{y \\in \\mathbb{F}^n}{\\text{minimize}}\\qquad \\|H_n y - \\|b\\|_2e_1\\|_2.\n\\label{eq:GMRES_lstsq2}\n\\end{equation}\nIf $y$ is the solution to this problem, then the solution to \\ref{eq:GMRES_lstsq1}, and hence an approximate\nsolution to $Ax = b$ is given by $x=Q_n y$.\n\nWe can measure how good our approximate solution is by considering the residual, which we define to be\n\\[\n\\frac{\\|Ax-b\\|_2}{\\|b\\|_2}.\n\\]\nWe can express this residual in terms of $y$ as follows:\n\\begin{equation}\n\\frac{\\|H_n y - \\|b\\|_2e_1\\|_2}{\\|b\\|_2}.\n\\label{eq:GMRES_residual}\n\\end{equation}\n\\section*{The GMRES Algorithm}\nTo summarize the discussion in the previous section, the GMRES algorithm combines the Arnoldi iteration with linear least squares,\ngenerating successive approximations to the solution of $Ax = b$.\nWe fully present GMRES in Algorithm \\ref{alg:gmres}.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{gmres}{$Amul, b, k=100, tol=1E-8$}\n\t\\State $m \\gets b.size$\t\t\t\t\t\t\\Comment{Some initialization steps}\n\t\\State $Q \\gets \\text{empty}\\left(m, k+1\\right)$\n\t\\State $H \\gets \\text{zeros}\\left(k+1, k\\right)$\n\t\\State $q_0 = b/\\|b\\|_2$\n    \\For{$n=1,2,\\ldots, k$}\n        \\State Set entries of $Q$ and $H$ as in Arnoldi iteration.\n        \\State Calculate least squares solution $y$ of \\ref{eq:GMRES_lstsq2}.\n        \\State Calculate the residual $r$ given by Equation \\ref{eq:GMRES_residual}.\n        \\If{$r < tol$}\n            \\State \\pseudoli{return} $Q_ny, \\,\\, r$\n        \\EndIf\n    \\EndFor\n    \\State \\pseudoli{return} $Q_ny, \\,\\, r$\t\t\t\t\t\t\n\\EndProcedure\n\\end{algorithmic}\n\\caption{GMRES}\n\\label{alg:gmres}\n\\end{algorithm}\n\n%\\begin{warn}\n%The Python function \\li{linalg.lstsq} solves a least squares problem, returning not only the vector, $y$, but also the residual,\n%the rank of the matrix, and the singular values.\n%Be careful when you write your code that you access the correct results and don't just assume that \\li{linalg.lstsq} returns the\n%vector that you want.\n%The least squares solver also returns a residual, but it's not the number we reference in this book, so be sure to take the square\n%root of the residual reported by the solver and divide by $\\norm{b}$ to get $res=\\norm{Ax-b}/\\norm{b}$.\n%\\end{warn}\n\n\\begin{problem}\nImplement the GMRES algorithm as presented above. For simplicity, assume that we are only dealing with real-valued matrices and vectors.\nWrite a function \\li{gmres} which accepts a function handle $Amul$ that computes the matrix-vector multiplication $Ax$ for any $x$,\na vector $b$, the maximum number of iterations to perform, and an error tolerance $tol$.\nUse the GMRES algorithm to compute an approximate solution to the system of equations $Ax = b$, and return this solution, as well as\nthe residual.\n\nAssume that the matrix is invertible, and ignore the possibility of dividing by zero for now, as this will occur very infrequently.\nYou may use the built-in least squares solver in \\li{scipy.linalg} to solve the least squares problem, but check the documentation\nfor its correct use.\n\nThe following function generates an $n \\times n$ array with randomly distributed real eigenvalues between $-1$ and $1$.\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nfrom scipy import linalg as la\ndef rand_eigs(n):\n    \"\"\" Make an nxn array with random eigenvalues between -1 and 1. \"\"\"\n    A = rand(n) * 2 - 1\n    X = rand(n, n)\n    return la.lu_solve(la.lu_factor(X), (X * A).T, trans=1).T\n\\end{lstlisting}\n\nTest your algorithm on a $100\\times 100$ matrix with random eigenvalues and a random vector $b$ and $tol=10^{-3}$.\nAllow only a maximum of 90 iterations.\nDon't expect convergence before 90 iterations in this case, for reasons that will be explained shortly.\n\\label{prob:MyGMRES}\n\\end{problem}\n\n\\section*{Convergence of GMRES}\nAt the $n$-th iteration, GMRES computes the best approximate solution to $Ax = b$ within the order-$n$ Krylov subspace\n$\\mathcal{K}_n$.\nIf $A$ is full rank, then the order-$m$ Krylov subspace is all of  $\\mathbb{F}^m$.\nTherefore, we are guaranteed an exact solution, up to rounding error, after $m$ iterations.\nThis is not very useful, however, because $m$ is prohibitively large in practice.\nInstead, we hope to converge to a close approximate solution in $n \\ll m$ steps.\n\nThe convergence of GMRES for reasonably small $n$ depends highly on the eigenvalues of $A$, and we expect rapid convergence whenever\nthe eigenvalues are clumped together in several places in the complex plane and if the eigenvalues are not too close to zero.\nThe worst case is when the eigenvalues are uniformly distributed around the origin.\nThis is, in fact, the reason that the algorithm failed to converge even after ninety iterations in problem 1.\nIf you come across a problem with such poorly-distributed eigenvalues, it is best to look for another algorithm, such as conjugate\ngradient applied to the normal equations (CGN).\n\n\\begin{problem}\nInstead of testing GMRES on completely random matrices, test it on matrices with ``nice,'' clumped eigenvalues.\nHere's one idea of how to design such a matrix for testing.\n\\begin{lstlisting}\n# Generate a random matrix with nice eigenvalues\ndef rand_clumps(m, q, r):\n    \"\"\" Generate a random mxm matrix with q distinct groups\n    of eigenvalues around different natural numbers. \"\"\"\n    A = rand(m, m)\n    Lambda = np.repeat(np.arange(2, q+2), m / q + 1)[:m]\n    variation = (rand(m) - .5) * (2 * r)\n    Lambda += variation\n    Q = la.qr(A)[0]\n    return (Q * Lambda).dot(Q.T)\n\\end{lstlisting}\nConstructing a matrix this way often takes much longer than actually running GMRES to get the solution, especially once we\nintroduce restarts later on in the lab.\nTest GMRES on matrices of this kind for $100\\times 100$ matrices.\nConvergence should now occur in relatively few iterations.\nTry out larger matrices and different values of the parameters to see how this algorithm behaves for these kinds of matrices.\n\\label{prob:GMRESClumps}\n\\end{problem}\n\n\\section*{Breakdowns in GMRES}\nOne of the selling points of GMRES is that it can't break down unless it has reached an exact solution.\nWhy is this the case?\nBreakdowns can occur as we try to expand to larger Krylov subspaces.\nIn each iteration, we have already converted $b,Ab,A^{2}b,\\cdots, A^{n-1}b$ into an orthonormal set $q_0,q_1,\\cdots,q_{n-1}$.\nAfter computing $A^nb,$ we will try to make it orthogonal to each of the $q_i$.\nBut what if $A^{n}b$ is already a linear combination of the $q_i$? In other words, what if $A^{n}b$ lies in $\\mathcal{K}_{n-1}$?\nThis means that\n\\[\n\\mathcal{K}_{n-1}=\\mathcal{K}_n=\\mathcal{K}_{n+1}=\\cdots,\n\\]\nso we have reached an \\emph{invariant subspace},\nand the algorithm cannot proceed without modification.\nIt also means that $A^{n}b = c_0 b + c_1 A b + \\cdots + c_{n-1}A^{n-1}b$.\nRearranging this, we have that $c_0 b = c_1 A b + c_2 A^{2} b + \\cdots + A^{n}b$, so that $b$ lies in $\\mathcal{K}_{n+1}$.\nTherefore, $b$ lies in $A\\mathcal{K}_n$, so the least-squares problem will actually deliver an exact solution, up to rounding errors,\nin this case.\nTo summarize: \\emph{GMRES only breaks down when it has found an exact solution}.\n\n\\begin{problem}\nIf necessary, update your solution to \\ref{prob:MyGMRES} to deal with breakdowns.\nConsider any division by zero cases in your code.  Make the necessary adjustments to avoid any such cases.\n\\label{prob:GMRES3}\n\\end{problem}\n\n\\section*{Optimizing Least-Squares for GMRES (Optional)}\nThe Hessenberg structure and the Krylov subspace relations enable us to save time on the least-squares part of the problem if we use QR factorization.\nObserve that if $H_n$ can be factored as $Q_n R_n$, where $Q_n$ is not the same matrix as above and $R_n$ is invertible upper triangular, we may solve the least squares problem by simply solving $R_n x_n=\\norm{b} Q_{n}^{H}e_1$ via back substitution.\nThere are two ways in which we can speed up this process.\nFirst, we take advantage of the Hessenberg structure by using the techniques from Problem \\ref{prob:givens_hessenberg} in Lab \\ref{lab:givens}.\nRecall that the technique in this situation was to use Givens rotations to eliminate the subdiagonal elements one at a time.\nThis process, which was part of a previous lab, reduces the operation count from $O(n^3)$ to $O(n^2)$.\nThe second speedup comes from the fact that we already know the QR factorization for $H_{n-1}$ from the previous step of the algorithm.\nThis means that we can simply update the QR factorization from the previous step rather than computing it all over again.\nSince $H_{n}$ has only one more column and row than $H_{n-1},$ all we need to do is update the last column by performing all previous Givens rotations on just the last column of $H_n$, which requires only $O(n)$ work.\nThen we perform one final Givens rotation on $H_n$ to eliminate the new subdiagonal entry which was not present in $H_{n-1}$.\nThus, the QR factorization of $H_n$ can be reduced from an $O(n^3)$ process to only $O(n)$ using these special techniques.\n\nThe back substitution necessary to solve the least squares problem can also be reduced to an operation of $O(n)$.\n\nThe speedup from $O(n^3)$ to $O(n)$ is very good, but it can only partially alleviate the problems that come with a problem that is ill-suited for GMRES.\nIt may still be useful because it allows us to perform more iterations in a reasonable amount of time.\nIn many situations, the simple technique of the next section will keep $n$ low enough that the optimizations from this section are not critical.\n%\n% \\begin{problem}\n% \\label{prob:GMRES2}\n% (Optional) Modify MyGMRES to incorporate these optimizations, and call this program MyGMRES1.\n% Run both programs on a series of five random $100\\times 100$ matrices and compare the time each requires.\n% Are the gains substantial?\n% Try it again matrices of size $1000\\times 1000$ or larger, and see how substantial the difference becomes.\n% Try the same thing using the techniqes of the next section.\n% Explain why the difference in performance is less dramatic this time.\n% \\end{problem}\n\n\\section*{GMRES(k)}\nOne of the serious drawbacks of GMRES is that it requires a lot of storage.\nAt step $n$, we need to store $H_n$ and $Q_n$, so the storage is $O(n^2)$.\nIt is also true that the complexity of the each iteration increases as $n$ increases, a fact that can substantially slow down the process.\nIf we want the iteration to proceed over many steps, these challenges can become prohibitive, so there is a modification called GMRES(k), or GMRES with restarts, that seeks to alleviate these difficulties by restarting the algorithm, but with an improved initial guess.\nIt then builds the Krylov subspaces generated by this improved initial guess and repeats the process as many times as needed.\nHere's the outline of the algorithm:\n\\begin{enumerate}\n\\item \\emph{Set} $k$, the maximum number of iterations before memory requirements or complexity are too large\n\\item \\emph{Set} $b$, the initial guess\n\\item \\emph{while} $i<k$ and convergence is not yet reached and the number of times through this while loop is less than a set maximum\n\\subitem Run GMRES for up to $k$ iterations, starting with initial guess\n\\subitem If convergence has not yet occurred, \\emph{set} initial guess to equal the most recent estimate of the solution\n\\end{enumerate}\n\nThis process keeps storage under control and ensures that each iteration stays fast, but at the cost of reliability.\nThus, when GMRES(k) does converge, it may be much quicker and require less storage than GMRES without restarts, but in situations where the true solution, $x$ is nearly orthogonal to the first $k$ Krylov subspaces, not much improvement is made at each iteration, so convergence is slow or may fail entirely.\nThis is, however, an important variation of GMRES and is frequently used.\n\n\\begin{problem}\nAdapt your prior implementation of GMRES to include restarts.\nIt should also take the additional argument $k$, the number of iterations before restarting.\nTest its speed on the special $1000\\times 1000$ matrices we constructed to test GMRES and compare its speed to GMRES without restarts.\nNo general statement can be made about the comparative speed of these two algorithms.\nHow do they compare in the case of these matrices with $k=10$ and $A$ has dimension $1000\\times 1000$?\n\\label{prob:GMRES3}\n\\end{problem}\n\n\\section*{Industrial-grade GMRES package}\nIn practice, of course, you will most frequently use GMRES algorithms written by specialists rather than writing your own version.\nIn python, one option is the function \\li{scipy.sparse.linalg.gmres}.\nIt also includes an option to specify whether restarts are needed.\n\n\\begin{problem}\nTest your GMRES algorithm against SciPy's GMRES algorithm on random $500\\times 500$ matrices, and report any difference on how quickly convergence is reached.\n\\label{prob:GMRES4}\n\\end{problem}\n\n\\section*{Summary}\nIn this lab, we developed the mathematical basis for GMRES, practiced implementing and working with the algorithm, and explored several variations and optimizations which, when used in conjunction and in the right situations, make GMRES the go-to algorithm for many, many applications.\nAvoid falling into the trap of thinking that GMRES is a universal solution to all systems of equations dilemmas, since we have already seen that even for simple random matrices, GMRES has horrendous performance.\nLearning and knowing when to apply a variety of algorithms is key to effective computing with large matrices.\n", "meta": {"hexsha": "36e1ccba4f309b5415b6b2669f0c9f4c5009c3d2", "size": 17991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/GMRES/GMRES.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/GMRES/GMRES.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/GMRES/GMRES.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": 58.035483871, "max_line_length": 307, "alphanum_fraction": 0.7448168529, "num_tokens": 5063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.6978219516006179}}
{"text": "%!TEX root = paper.tex\n\nThe problem we will analyze in this paper is that of a billiard ball bouncing around inside a square billiard table in the absence of any external forces (e.g. gravity) and/or any dissipative forces (e.g. friction). Before delving into the analysis, we must first clarify the problem statement.\n\n\\subsection{Setup}\n\nThe ball and table will be idealized in the following manner: we will represent the ball as a point moving around in $\\R^2$ and the board as the unit square $[0,1]^2$. The ball will start with an initial position $\\bvec{x}_0 \\in [0,1]^2$ and initial velocity $\\bvec{u}_0$. Because there are no external forces and/or dissipative forces, the speed of the ball is constant and irrelevant to the problem.\n\nAny time the position of the ball (point) coincides with the edge of the table (unit square), we will say that the ball collides with that edge of the table. During this collision, the ball is reflected off the edge of the table in such a manner that the outgoing direction vector is a reflection of the incoming direction vector across the line perpendicular to the edge of the table at the point of collision. In more technical terms, the angle of incidence is equal to the angle of reflection in all ball-table collisions. Collisions at corners of the table are undefined and so we will ignore any such trajectories that intersect corners of the table. Figure \\ref{fig:collision-angle} shows the general mechanics of a collision.\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[keepaspectratio,width=2in]{particle_collision.png}\n  \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:collision-angle}Mechanics of the ball colliding with a table edge.}\n\\end{figure}\n\nIntroducing some notation to the problem, we will label the horizontal edges of the table $h$ and the vertical edges of the table $v$. Whenever the ball collides with a horizontal edge, we will call the resulting collision an $h$ collision. Likewise, collisions with vertical edges will be denoted as $v$ collisions.\n\n\\begin{definition}\n  A \\emph{collision sequence} ($\\alpha$) for a ball is the sequence of sides that the ball collides with ($\\alpha_i \\in \\cbracket{v, h}$). This sequence is ordered by increasing collision time. In this paper, ball trajectories are idealized and infinite, but we will only look at finite subsequences of the infinite collision sequences formed by these trajectories. Furthermore, we will only look at finite collision sequences that start and end with h.\n\\end{definition}\n\n\\subsection{An Example Collision Sequence}\n\nFor the reader to better understand the basic properties of collision sequences, we will consider an example trajectory and form a collision sequence from a short segment of the trajectory. Consider a ball with initial position $\\bvec{x}_0 = (0.75, 0.75)$ and initial velocity $\\bvec{u}_0 = (4.6, 1)$.\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[keepaspectratio,width=3in]{example.png}\n  \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:example}Example trajectory, $x_0 = (0.75, 0.75)$, $u_0 = (4.6, 1)$.}\n\\end{figure}\n\nThe collision sequence corresponding to this trajectory segment is the following:\n\n\\begin{equation}\n\t\\alpha = (v, h, v, v, v, v, v, h, v, v, v, v, v, h, v, v, v)\n\\end{equation}\n", "meta": {"hexsha": "c6cc22666abc5bae1365657a838e641d3d64b67c", "size": 3332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/introduction.tex", "max_stars_repo_name": "spectralflight/billiards", "max_stars_repo_head_hexsha": "429865070b490940fda4d475bb12d1f888bd190b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-19T01:48:14.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-19T01:48:14.000Z", "max_issues_repo_path": "paper/introduction.tex", "max_issues_repo_name": "spectralflight/billiards", "max_issues_repo_head_hexsha": "429865070b490940fda4d475bb12d1f888bd190b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/introduction.tex", "max_forks_repo_name": "spectralflight/billiards", "max_forks_repo_head_hexsha": "429865070b490940fda4d475bb12d1f888bd190b", "max_forks_repo_licenses": ["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.3333333333, "max_line_length": 732, "alphanum_fraction": 0.7638055222, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.6978219402213462}}
{"text": "%\n% setting up at Nov. 2011\n%\n%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Introduction to Hermite Polynomials}\n\\label{sec:hermite_polynomials}\n\nIn the mathematics, Hermite polynomials is a series of orthogonal functions\nthat form an orthogonal basis of the Hilbert space, it's also a complete \northogonal function system so that we can use it to expand a lot of functions.\nIn quantum chemistry, the Hermite polynomials are used in the integral\ncalculation. Hence here a brief summary for its properties will be given.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Definition}\nThe Hermite polynomials are defined as:\n\\begin{equation}\n \\label{hermite_definition_eq:1}\nH_{n}(x) = (-1)^{n}e^{x^{2}}\\frac{d^{n}}{dx^{n}}e^{-x^{2}}\n\\end{equation}\nThis relation could be derived from a generation function:\n\\begin{equation}\n\\label{hermite_definition_eq:2}\n e^{2xt-t^{2}} = \\sum_{t=0}^{\\infty}H_{n}(x)\\frac{t^{n}}{n!}\n\\end{equation}\nwhen we make $n$th derivatives for the $e^{2xt-t^{2}}$, $H_{n}(x)$\ncould be generated:\n\\begin{equation}\n \\label{hermite_definition_eq:3}\nH_{n}(x) =  \\left. \\frac{\\partial^{n} (e^{2xt-t^{2}}) }{\\partial\nt^{n}}\\right|_{t=0}\n\\end{equation}\nBy setting the $e^{2xt-t^{2}} = e^{-(t-x)^{2} + x^{2}}$, then through\nthe $n$th derivatives we can get the \\ref{hermite_definition_eq:1}.\n\nFor this polynomial we have some recursive relation from its definition:\n\\begin{equation}\n \\label{hermite_definition_eq:4}\nH_{n}^{'}(x) = 2xH_{n}(x) - H_{n+1}(x)\n\\end{equation}\nBy using the relation that $\\frac{\\partial \ne^{2xt-t^{2}} }{\\partial x} = 2te^{2xt-t^{2}}$, then we can bring this form\ninto \\ref{hermite_definition_eq:3} and expand the higher derivatives for\n$2te^{2xt-t^{2}}$; we get:\n\\begin{equation}\n \\label{hermite_definition_eq:5}\nH_{n}^{'}(x) = 2nH_{n-1}(x)\n\\end{equation}\nTherefore we arrive at some final recursive expression:\n\\begin{equation}\n \\label{hermite_definition_eq:6}\n2nH_{n-1}(x) = 2xH_{n}(x) - H_{n+1}(x)\n\\end{equation}\nwe note that such derivative relation could also be expressed in terms of \nits derivatives. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Orthogonality} \n%\n%\n%\nHermite polynomials has one important property, is that they are orthogonal with \neach other by a weight function:\n\\begin{equation}\n\\label{hermite_orthogonality_eq:1}\n \\int^{+\\infty}_{-\\infty} H_{m}(x)H_{n}(x)e^{-x^{2}} = \n 2^{n}n!\\delta_{mn}  \n\\end{equation}\n\nThe orthogonality could be derived through partial integral(suppose that $n\\neq m$):\n\\begin{align}\n \\label{hermite_orthogonality_eq:2}\n \\int^{+\\infty}_{-\\infty} H_{m}(x)H_{n}(x)e^{-x^{2}} dx &= \n(-1)^{n} \\int^{+\\infty}_{-\\infty} H_{m}(x) \\frac{d^{n}}{dx^{n}}e^{-x^{2}}dx \\nonumber \\\\\n&=  (-1)^{n-1} 2m\\int^{+\\infty}_{-\\infty} H_{m-1}(x)\\frac{d^{n-1}}{dx^{n-1}}e^{-x^{2}}dx \n\\nonumber \\\\\n&= (-1)^{n-m} 2^{m}m!\\int^{+\\infty}_{-\\infty} H_{0}(x)\\frac{d^{n-m}}{dx^{n-m}}e^{-x^{2}}dx \n\\nonumber \\\\\n&= 0\n\\end{align}\nSuch derivation uses the relation in the \\ref{hermite_definition_eq:5}.\n \n\n", "meta": {"hexsha": "3ff85e08d0c9033fe1647afe327fa23f62a88341", "size": 3094, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm/math/hermite.tex", "max_stars_repo_name": "murfreesboro/fenglai-note", "max_stars_repo_head_hexsha": "7bdf943f681e54948cd68775a31e4c93a53a13f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-16T07:23:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-16T07:23:48.000Z", "max_issues_repo_path": "algorithm/math/hermite.tex", "max_issues_repo_name": "murfreesboro/fenglai-note", "max_issues_repo_head_hexsha": "7bdf943f681e54948cd68775a31e4c93a53a13f8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algorithm/math/hermite.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": 35.5632183908, "max_line_length": 91, "alphanum_fraction": 0.6308985133, "num_tokens": 1046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6978189145716118}}
{"text": "\\subsection{Sparse Contrastive PCA}\n\nThe sparse contrastive PCA (scPCA) procedure applies SPCA with minimal\nmodifications \\edit{to a pair of target and background datasets' contrastive \ncovariance matrix $\\mathbf{C}_\\gamma$}. The numerical solution to the SPCA \ncriterion of Equation \\eqref{eq:spca} is obtained by the following\nalternating algorithm until convergence of the sparse loadings \\citep{Zou2006},\n\\edit{where $\\mathbf{A}_{p\\times k}$ is initialized as the matrix of loadings \ncorresponding to the $k$ leading principal components of $\\mathbf{C}_\\gamma$:}\n\n\\textbf{For fixed} $\\mathbf{A}$:\n\\edit{Relying on the results of Equation \\eqref{eq:cov_mat_spca}, the\nelastic net solution for the $j^{\\text{th}}$ loading vector is\n\\begin{equation*}\n  \\beta_j^\\star = \\argmin_{\\beta_j} \\lVert \\mathbf{C}_\\gamma^{\\frac{1}{2}}\\alpha_j - \\mathbf{C}_\\gamma^{\\frac{1}{2}}\n  \\beta_j \\rVert_2^2 + \\lambda_0 \\lVert \\beta_j \\rVert_2^2 + \\lambda_{1, j}\n  \\lVert \\beta_j \\rVert_1.\n\\end{equation*}}\nGenerally, for ease of computation, $\\lambda_{1, j} = \\lambda_1$, for\n$j=1, \\ldots, k$. The entries of the loading matrix $\\mathbf{B}$ are independent of\nthe choice for the $\\ell_2$ penalty (ridge) parameter $\\lambda_0$\n\\citep{Zou2006}, which is used only for numerical reasons. The ridge penalty is set to zero when\n$\\mathbf{C}^{\\frac{1}{2}}_\\gamma$ is of full rank; otherwise, a small constant\nvalue is used to remedy issues of indeterminacy that arise when fitting the\nelastic net.\n\n\\textbf{For fixed} $\\mathbf{B}$: Only the first term of the SPCA criterion of\nEquation \\eqref{eq:spca} must be minimized with respect to $\\mathbf{A}$. The\nsolution is given by the reduced rank form of the Procrustes rotation, computed\nas $\\mathbf{A}^\\star = \\mathbf{U}\\mathbf{V}^\\top$ \\citep{Zou2006}. The matrices\nof left and right singular vectors are obtained from the following singular\nvalue decomposition:\n\\begin{equation*}\n  \\mathbf{C}_\\gamma\\mathbf{B} = \\mathbf{U}\\mathbf{D}\\mathbf{V}^\\top.\n\\end{equation*}\nGenerally, $\\mathbf{C}_\\gamma$ is not positive-semidefinite and its square root\nis undefined. Instead, a positive-semidefinite matrix\n$\\widetilde{\\mathbf{C}}_\\gamma$, approximating $\\mathbf{C}_\\gamma$, is used.\n$\\widetilde{\\mathbf{C}}_\\gamma$ is obtained by replacing the diagonal matrix in\nthe eigendecomposition of $\\mathbf{C}_\\gamma$ by a diagonal matrix in which\nnegative eigenvalues are replaced by zeros \\citep{elasticnet}:\n\\begin{align*}\n  \\mathbf{C}_\\gamma &= \\mathbf{V}\\mathbf{\\Lambda}\\mathbf{V}^\\top \\\\\n  \\widetilde{\\mathbf{C}}_\\gamma &= \\mathbf{V}\\mathbf{D}\\mathbf{V}^\\top \\\\\n\\end{align*}\n\\begin{equation*}\n\\text{where } \\text{D}_{ii} =\n  \\begin{cases}\n    \\Lambda_{ii}, & \\text{if $\\Lambda_{ii} > 0$} \\\\\n    0, & \\text{otherwise}\n  \\end{cases},\n  \\qquad \n  \\text{for } i = 1, \\ldots, p.\n\\end{equation*}\n\nThus, the directions of variation given by the negative eigenvalues of\n$\\mathbf{C}_\\gamma$ are discarded, as they correspond to those which are dominated by the variance in the background dataset. This procedure can be viewed as a preliminary thresholding of the eigenvectors of $\\mathbf{C}_\\gamma$,\nwhere the cutoff is an additional hyperparameter corresponding to a non-negative\nreal number. Explicitly defining a small positive threshold may prove useful for\ndatasets that possess many eigenvalues near zero, which correspond to sources of\ntechnical and biological noise remaining after the contrastive step.\nEmpirically, however, providing a wide range of contrastive parameters $\\gamma$ has been found to have a similar effect as using\nmultiple cutoff values, that is, larger values of $\\gamma$ naturally produce\nsparser matrices $\\widetilde{\\mathbf{C}}_{\\gamma}$.\n\nFor the purpose of contrastive analysis, a direction's importance is\ncharacterized by its target-background variance coupling; higher target variance\nand lower background variance pairs produce the best directions \\citep{Abid2018}\nand correspond to the largest positive eigenvalues. The elimination of directions with\nnegative eigenvalues therefore guarantees that the sparse contrastive PCs (scPCs) are\nrotations of the target data relying on the sparse directions most\nvariable in the target data but least variable in the background data, making\na cutoff of zero a natural choice for the thresholding operation.\n\n\\subsection{Framework for Hyperparameter Tuning}\\label{hyp_tune}\n\nThe scPCA algorithm relies on two hyperparameters: the contrastive parameter $\\gamma$ and the $\\ell_1$ penalty parameter $\\lambda_1$. To select the optimal combination of $\\gamma$ and $\\lambda_1$ from a grid of \\textit{a priori} specified values, we propose to cluster the $n$ observations of the target dataset based on their first $k$ scPCs, selecting as optimal the combination $\\{\\gamma, \\lambda_1\\}$ producing the ``strongest'' cluster assignments. This framework casts the selection of $\\{\\gamma, \\lambda_1\\}$ in terms of a choice of clustering algorithm, distance metric (based on $\\widetilde{\\mathbf{C}}_{\\gamma}$), and clustering strength criterion. For ease of application, we propose to select $\\{\\gamma, \\lambda_1\\}$ by maximization of the average silhouette width over clusterings of the reduced-dimension representation of the target data. This procedure implicitly requires the choice of a clustering algorithm, such as $k$-means~\\citep{kmeans}, to be applied to the representation of the data in the first $k$ scPCs. Such methods require an appropriate choice for the number of clusters, which we contend will generally not be a limiting factor in the use of scPCA. Indeed, reasonable choices for the number of clusters can often be inferred in \\textit{omics} settings from sample annotation variables accompanying the data or from previously available biological knowledge. In Section~\\ref{results}, we empirically demonstrate that the results of the algorithm are robust to the choice of the number of clusters. Additionally, scPCA has no particular dependence on average silhouette width as a criterion, that is, alternative criteria for assessing clustering strength could be used when appropriate. %(e.g., when the data contains sub-clusters~\\citep{Liu2010}).\nNaturally, this proposed hyperparameter tuning approach can be applied to cPCA by setting $\\lambda_1$ to zero.\n\nTo address concerns of overfitting and to avoid discovering non-generalizable patterns from the data, we propose the use of cross-validation. For a grid of \\textit{a priori} specified contrastive parameters $\\gamma$ and $\\ell_1$ penalty parameters $\\lambda_1$, \\edit{$W$-fold} cross-validation may be performed as follows:\n\\begin{enumerate}\n  \\itemsep0pt\n  \\item Partition each of the target and     \n     background datasets into \\edit{$W$} roughly\n     equally-sized subsets.\n   \\item Randomly pair each of the target \\edit{$W$} subsets with one of the\n     background subsets; these pairs form the fold-specific \\edit{validation sets}.\n   \\item Iteratively perform scPCA over the \n     observations of the target and\n     background data not contained in the validation set (i.e., the training sets),\n     for each pair of contrastive parameters and $\\ell_1$ penalty parameters in\n     the hyperparameter grid.\n  \\item Project the target validation data onto the low-dimensional space using\n     the loading matrices obtained in the prior step.\n  \\item Compute a clustering strength criterion (e.g., average\n  silhouette width) for a clustering of the target validation data with the \\textit{a priori}\n  specified number of clusters.\n  \\item Finally, compute the cross-validated average of the clustering\n  strength criteria (e.g., cross-validated average of average silhouette width)\n  across the validation sets for each pair of hyperparameters, selecting the\n  pair that maximizes the value of the criterion.\n\\end{enumerate}\n\n\\edit{We note two caveats of this cross-validation framework: (1) it increases the computation time, and (2) each fold is assumed to be representative of the process which generated the data. For large datasets and say 5 to 10 folds, (2) is not a grave concern; however, as the number of samples decreases, this assumption becomes less tenable. In such a situation, the non-cross-validated framework should be used, or the number of folds reduced. Examples and results are provided in Section~\\ref{cv_algo_example}.}\n\n\\subsection{Algorithm and Software Implementation}\n\n\\edit{The implementation of the scPCA algorithm is presented in\nAlgorithm~\\ref{algo1} of the supplement. Algorithm~\\ref{algo2},\nalso in the supplement, details the cross-validated variant.}\n\n\\edit{Regarding the computational complexity of scPCA (and cPCA), we note that\nthe number of observations in the target and background data are not limiting\nfactors. Indeed, these algorithms are applied to a $p \\times p$\ncontrastive covariance matrix, a function of the target and background covariance\nmatrices. The computation time of these covariance matrices increases linearly in\nthe number of observations $n$ and quadratically in the number of features $p$. The\nmethods' computational efficiency are therefore most impacted by the number of\nfeatures and the size of the hyperparameter grid. A note on cPCA's and\nscPCA's running time is provided in Section~\\ref{run_time}, as is a comparison\nto competing methods.}\n\nA free and open-source software implementation of scPCA is\navailable in the \\texttt{scPCA} package for the \\texttt{R} language and\nenvironment for statistical computing~\\citep{R}. The \\texttt{scPCA} package\n\\edit{has been released} as part of the Bioconductor Project\n\\citep{gentleman2004bioconductor,gentleman2006bioinformatics,huber2015orchestrating} (\\url{https://bioconductor.org/packages/scPCA}).\n\nThe code and data used to generate this manuscript are publicly available on\nGitHub (\\url{https://github.com/PhilBoileau/EHDBDscPCA}).", "meta": {"hexsha": "f55bfa385d91ddb5f89d8ea36f8f991b6c3eb2e7", "size": 9804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/methods.tex", "max_stars_repo_name": "PhilBoileau/EHDBDscPCA", "max_stars_repo_head_hexsha": "d2b291a22bb78e91524e1b50cd198b8e17cdbbca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-18T10:33:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-18T10:33:51.000Z", "max_issues_repo_path": "manuscript/methods.tex", "max_issues_repo_name": "PhilBoileau/EHDBDscPCA", "max_issues_repo_head_hexsha": "d2b291a22bb78e91524e1b50cd198b8e17cdbbca", "max_issues_repo_licenses": ["MIT"], "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/methods.tex", "max_forks_repo_name": "PhilBoileau/EHDBDscPCA", "max_forks_repo_head_hexsha": "d2b291a22bb78e91524e1b50cd198b8e17cdbbca", "max_forks_repo_licenses": ["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.4153846154, "max_line_length": 1780, "alphanum_fraction": 0.7773357813, "num_tokens": 2467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.6978189043410711}}
{"text": "\\chapter{Lattice gauge theory}\n\\label{chap:latticeqcd}\n\n\\section{Gauge invariance} \nNevertheless, a naive discretization of the Yang-Mills action from Equation \\cref{yangmills}, in which one replaces all the partial derivatives appearing in the field strengths $F^{\\mu\\nu}$ with finite differences leads to the loss of gauge invariance \\cite{schwartz, peskin}. \n\n\\begin{remark}\nThis is a consequence of imposing local gauge symmetry, with a $\\textsf{SU}(3)$ gauge transformation given by Equation \\cref{gaugetransf}, of the fields\n\\begin{align*}\n    \\phi(x)\\mapsto \\textsf{U}(x)\\phi(x).\n\\end{align*}\nFields at different space-time points cannot directly be compared. Because of this, the partial derivative, which contains the difference between fields at different points, is not well defined. By introducing a quantity which gauge transform as\n\\begin{align}\\label{latt3}\n    \\textsf{W}(x,y)\\mapsto\\textsf{U}(x)\\textsf{W}(x,y)\\textsf{U}^\\dagger(y),\n\\end{align}\none may now properly define the covariant derivative as\\footnote{Notice that with this definition, the covariant derivative transforms as\n\\begin{align}\\label{latt1}\n    \\textsf{D}_\\mu\\phi(x)\\mapsto\\textsf{U}(x)\\textsf{D}_\\mu\\phi(x).\n\\end{align}\n}\n\n\\begin{definition}[Covariant derivative]\n\\begin{align}\\label{latt2}\n    \\textsf{D}_{\\mu} \\phi(x)\\overset{\\Delta}{=} \\lim _{\\delta \\epsilon^{\\mu} \\rightarrow 0} \\frac{\\textsf{W}(x, x+\\epsilon) \\phi(x+\\epsilon)-\\phi(x)}{\\epsilon^\\mu}.\n\\end{align}\n\\end{definition}\n\\noindent We choose $\\textsf{W}(x,x)=\\mathds{1}$ and then write an expansion in terms of the gauge fields\\footnote{If we plug in this relation back in Equation \\cref{latt2} and then in Equation \\cref{latt1}, we deduce the gauge transformation of the gauge fields from Equation \\cref{gaugefields}.}\n\\begin{align*}\n    \\textsf{W}(x,x+\\epsilon)=1+ig\\epsilon^\\mu A_\\mu+\\mathcal{O}(\\epsilon^2).\n\\end{align*}\n\\end{remark}\n\nThis enables us to express the {\\sffamily\\color{maincolor}Wilson line} as\\footnote{Where the fields may further be written as $A_{\\mu}=A_{\\mu}^aT^a$ in the fundamental representation.}\n\\boxedeqlabel{latt5}{\n    \\textsf{W}(x,y)=\\mathcal{P}\\exp{i g \\int_{y}^{x} \\mathrm{d} z^{\\mu} A_{\\mu}(z) }\n}\n\n\\begin{remark}\nThe {\\sffamily\\color{maincolor}path-ordering} operator $\\mathcal{P}\\{\\ldots\\}$ is necessary due to the non-Abelian nature of the fields. More clearly, after writing a Taylor expansion, the path-ordering operator acts as\n\n\\begin{align*}\n    \\begin{aligned}\n    \\textsf{W}(x, y)=& 1+i g \\int_{0}^{1} \\frac{\\mathrm{d} z^{\\mu}_\\lambda}{\\mathrm{d} \\lambda} A_{\\mu}^{a}(z_\\lambda^\\mu) T^{a} \\mathrm{d} \\lambda-\\frac{1}{2} g^{2} \\int_{0}^{1} \\mathrm{d} \\lambda \\int_{0}^{1} \\mathrm{d} \\tau \\frac{\\mathrm{d} z^{\\mu}_\\lambda}{\\mathrm{d} \\lambda} \\frac{\\mathrm{d} z^{\\nu}_\\tau}{\\mathrm{d} \\tau}\\times\\\\\n    & \\times A_{\\mu}^{a}(z_\\lambda^\\mu) A_{\\nu}^{b}(z_\\tau^\\nu)\\left[T^{a} T^{b} \\theta(\\lambda-\\tau)+T^{b} T^{a} \\theta(\\tau-\\lambda)\\right]+\\cdots.\n\\end{aligned}\n\\end{align*}\n\\end{remark}\n\nA Wilson line taken along a closed path $\\gamma$ is called a {\\sffamily\\color{maincolor}Wilson loop} and it's given by\n\\boxedeqlabel{latt4}{\n    \\textsf{W}_\\gamma=\\mathcal{P}\\exp{i g \\oint\\limits_{\\gamma} \\mathrm{d} x^{\\mu} A_{\\mu}(x)}\n}\n\nIt is important to emphasize that the trace of a Wilson loop is gauge invariant\\footnote{This may easily be proven by inserting Equation \\cref{latt4} back in Equation \\cref{latt3} and using the invariance of the trace under cyclic permutations.}.\n\n\\section{Real-time lattice gauge theory} \nLet us begin by discretizing the Minkowski space-time on a hypercubic lattice\\footnote{The lattice spacing along direction $\\mu$, with the unit vector is $\\hat{e}^\\mu$, is $a^\\mu$. This enables us to write $\\hat{a}^{\\mu}=a^\\mu\\hat{e}^\\mu$. More concisely, $a^0$ is the time step and $a^i$ denote the spatial lattice spacings.} whose points are given by\n\\begin{align*}\n    \\textsf{X}^4=\\left\\{x \\mid x=\\sum_{\\mu=0}^{3} n_{\\mu} \\hat{a}^{\\mu}, \\quad n_{\\mu} \\in \\mathbb{Z}\\right\\}.\n\\end{align*}\n\nA field $\\phi(x)$ which resides on the lattice will be denoted as $\\phi_x$, with $x\\in\\textsf{X}^4$. The gauge transformation $\\textsf{U}(x)$ will become, upon discretization, $\\textsf{U}_x$. The discretized action and corresponding field equations written in terms of $A_\\mu$ will not remain gauge invariant.\n\nNevertheless, a gauge invariant lattice action may be constructed. Instead of using the gauge fields $A_\\mu$, along with the corresponding conjugate momenta $P_\\mu$, as the main degrees of freedom, one may simply seek for a more suitable quantity which is already gauge invariant and preserves gauge invariance upon discretization. An action built from such a quantity will inherently be gauge invariant. The simplest choice is the trace of a Wilson line, as given in Equation \\cref{latt4}. We already saw that such a construction is gauge invariant.\n\n% Diagrams included directly as .tikz images generated from Tikzit\n\\begin{figure}\n    \\centering\n    \\subfloat[\\centering {\\sffamily 2d} plaquette]{{\\includegraphics[width=0.45\\textwidth]{tikzit/plaquette_2d.tikz}}}%\n    \\qquad\n    \\subfloat[\\centering {\\sffamily 3d} plaquette]{{\\includegraphics[width=0.45\\textwidth]{tikzit/plaquette_3d.tikz}}}%\n    \\caption{Schematic representations of a plaquette, the shortest Wilson loop on a rectangular lattice.}%\n    \\label{fig:plaquettes}%\n\\end{figure}\n\n\n% Diagrams included using .pdf files saved from Tikzit\n%\\begin{figure}\n%    \\centering\n%    \\subfloat[\\centering {\\sffamily 2d} plaquette]{{\\includegraphics[width=0.45\\textwidth]{plaquette_2d.pdf}}}%\n%    \\qquad\n%    \\subfloat[\\centering {\\sffamily 3d} plaquette]{{\\includegraphics[width=0.45\\textwidth]{plaquette_3d.pdf}}}%\n%    \\caption{Schematic representations of a plaquette, the shortest Wilson loop on a rectangular lattice.}%\n%    \\label{fig:plaquettes}%\n%\\end{figure}\n\nA Wilson line taken between two neighboring lattice points, namely $x$ and $x+\\hat{a}^{\\mu}$, is called a {\\sffamily\\color{maincolor}gauge link} and it's given by\\footnote{Here $\\overline{\\mathcal{P}}\\{\\ldots\\}$ denotes the anti-path-ordering. We introduce the notation\n\\begin{align*}\n    \\textsf{W}_{x,\\mu}\\overset{\\Delta}{=}\\textsf{W}(x,x+\\hat{a}^{\\mu})\n\\end{align*}\nand similarly for $A_{x,\\mu}$.\n}\n\\begin{align*}\n    \\textsf{W}_{x, \\mu}=\\overline{\\mathcal{P}} \\exp{i g \\int\\limits_{x}^{x+\\hat{a}^{\\mu}} d x^{\\mu} A_{x,\\mu}}.\n\\end{align*}\n\n\\begin{remark}\nIn a similar manner, we may also introduce a gauge link along the opposite direction, which would yield\n\\begin{align}\\label{latt6}\n    W_{x,\\mu}^{\\dagger}=\\textsf{W}_{x+\\mu,-\\mu}.\n\\end{align}\nA gauge link transforms as\n\\begin{align*}\n    \\textsf{W}_{x, \\mu} \\rightarrow \\textsf{U}_{x} \\textsf{W}_{x, \\mu} \\textsf{U}_{x+\\mu}^{\\dagger}.\n\\end{align*}\nOne may express a gauge link and afterwards expand it, see Equation \\cref{latt5}, as\n\\begin{equation*}\n    \\begin{aligned}\n     \\textsf{W}_{x,\\mu}&=\\exp{iga^\\mu A_{x,\\mu}}\\approx \\mathds{1}+iga^\\mu A_{x,\\mu(x)}-\\frac{1}{2}g^2a^\\mu a^\\nu A_{x,\\mu}A_\n     {x,\\nu}+\\mathcal{O}(a^3).\n\\end{aligned}\n\\end{equation*}\n\\end{remark}\n\nThe simplest non-trivial\\footnote{The shortest Wilson line would just go back and forth between two neighbouring sites but such a combination would simply yield the trivial result\n\\begin{align*}\n    \\textsf{W}_{x,\\mu}\\textsf{W}_{x+\\mu,-\\mu}\\stackrel{\\text{\\cref{latt6}}}{=\\joinrel=}\\mathds{1}.\n\\end{align*}\n} Wilson loop on the lattice may be constructed along the path connecting neighbouring points on a rectangular {\\sffamily\\color{maincolor}plaquette}, see Figure \\cref{fig:plaquettes}, as\n\\begin{align*}\n    \\textsf{W}_{x, \\mu \\nu}&=\\textsf{W}_{x, \\mu} \\textsf{W}_{x+\\mu, \\nu} \\textsf{W}^\\dagger_{x+\\mu,\\mu}\\textsf{W}^\\dagger_{x,\\nu}\\\\\n    &\\stackrel{\\text{\\cref{latt6}}}{=\\joinrel=}\\textsf{W}_{x, \\mu} \\textsf{W}_{x+\\mu, \\nu} \\textsf{W}_{x+\\mu+\\nu,-\\mu} \\textsf{W}_{x+\\nu,-\\nu},\n\\end{align*}\nwhich may further be expressed as\n\\begin{align*}\n    \\textsf{W}_{x, \\mu \\nu} \\approx \\exp{ig a^{\\mu} a^{\\nu} F_{x,\\mu \\nu}+\\mathcal{O}\\left(a^{3}\\right)}.\n\\end{align*}\n\n\\begin{proof}\nWe may write the discretized Wilson loop as\\footnote{\nUsing the Campbell-Baker-Hausdorff formula\n\\begin{align*}\n    \\exp{\\textsf{A}}\\exp{\\textsf{B}}\\approx\\exp{\\textsf{A}+\\textsf{B}+\\frac{1}{2}[\\textsf{A}, \\textsf{B}]+\\cdots}.\n\\end{align*}\n}\n\\begin{align*}\n    \\textsf{W}_{x,\\mu\\nu}&\\approx\\exp\\Bigg\\{ig(A_{x,\\mu}+A_{x+\\mu,\\nu}-A_{x+\\nu,\\mu}-A_{x,\\nu})+\\\\\n    &\\phantom{\\approx\\exp\\Bigg\\{}+\\frac{g^2}{2}\\Big(\\big[A_{x,\\nu}+A_{x+\\nu,\\mu},A_{x+\\mu,\\nu}+A_{x,\\mu}\\big]-\\\\\n    &\\phantom{\\approx\\exp\\Bigg\\{}-\\big[A_{x,\\nu},A_{x+\\nu,\\mu}\\big]-\\big[A_{x+\\mu,\\nu},A_{x,\\mu}\\big]\\Big)\\Bigg\\}.\n\\end{align*}\nBy making use of the expansion \n\\begin{align*}\n    A_{x+\\mu,\\nu}\\approx A_{x,\\nu}+a^\\mu\\partial_\\mu A_{x,\\nu}+\\mathcal{O}(a^2),   \n\\end{align*}\nwe may then derive\n\\begin{align*}\n     \\textsf{W}_{x,\\mu\\nu}&\\approx\\exp\\Big\\{iga^\\mu a^\\nu\\underbrace{\\big(\\partial_\\mu A_{x,\\nu}-\\partial_\\nu A_{x,\\mu}-ig[A_{x,\\nu},A_{x,\\mu}]\\big)}_{\\mathclap{\\textstyle F_{x,\\mu\\nu}}}+\\mathcal{O}(a^3)\\Big\\}.\n\\end{align*}\nThis may further be approximated as\n\\begin{align*}\n    \\textsf{W}_{x,\\mu\\nu}=\\mathds{1}+ig a^\\mu a^\\nu F_{x,\\mu \\nu}-\\frac{1}{2}(ga^\\mu a^\\nu)^2 F_{x,\\mu \\nu}^2+\\mathcal{O}(a^5).\n\\end{align*}\nin the limit of small lattice spacings.\n\\end{proof}\n\nTherefore, we may construct a gauge invariant quantity, since in contains Wilson lines traced over, under the discretized gauge transformation $\\textsf{U}_x$ as\n\n\\begin{align}\\label{latt7}\n    \\textsf{Tr}\\big\\{2-\\textsf{W}_{x, \\mu \\nu}-\\textsf{W}_{x, \\mu \\nu}^{\\dagger}\\big\\} \\approx\\left(g a^{\\mu} a^{\\nu}\\right)^{2} \\textsf{Tr}\\big\\{F_{x,\\mu \\nu}^{2}\\big\\}+\\mathcal{O}(a^{6}).\n\\end{align}\n\nThe Yang-Mills action from Equation \\cref{yangmills} may be split into an electric and a magnetic part\n\\begin{align*}\n    \\textsf{S}=\\underbrace{\\int \\mathrm{d}^{4}x \\sum_{i}\\textsf{Tr}\\big\\{F_{0i}^2(x)\\big\\}}_{\\mathclap{\\textstyle \\textsf{S}_\\textsf{E}}}+\\underbrace{\\int \\mathrm{d}^{4}x\\sum_{i, j} \\frac{1}{2} \\textsf{Tr}\\big\\{F_{ij}^2(x)\\big\\}}_{\\mathclap{\\textstyle \\textsf{S}_\\textsf{B}}}.\n\\end{align*}\nUpon discretization, they become\\footnote{By making the replacement\n\\begin{align*}\n    \\int \\mathrm{d}^{4}x(\\ldots)\\mapsto \\underbrace{\\prod\\limits_{\\mu}a^\\mu}_{\\mathclap{\\textstyle \\textsf{V}}}\\sum_x(\\ldots)\n\\end{align*}\nand using the result from Equation \\cref{latt7}.\n}\n\\begin{align*}\n    \\textsf{S}_\\textsf{E}& \\approx V \\sum_{x} \\sum_{i} \\frac{1}{\\left(g a^{0} a^{i}\\right)^{2}} \\textsf{Tr}\\big\\{2-\\textsf{W}_{x, 0 i}-\\textsf{W}_{x, 0 i}^{\\dagger}\\big\\}, \\\\\n    \\textsf{S}_\\textsf{B}& \\approx V \\sum_{x} \\sum_{i, j} \\frac{1}{2\\left(g a^{i} a^{j}\\right)^{2}} \\textsf{Tr}\\big\\{2-\\textsf{W}_{x, i j}-\\textsf{W}_{x, i j}^{\\dagger}\\big\\}.\n\\end{align*}\nThus, the Yang-Mills action on the lattice is given by\n\n\\shadedeq{\n\\textsf{S}=V \\sum_{x}\\Big( \\sum_{i} \\frac{1}{\\left(g a^{0} a^{i}\\right)^{2}} \\textsf{Tr}\\big\\{2-\\textsf{W}_{x, 0 i}-\\textsf{W}_{x, 0 i}^{\\dagger}\\big\\} -\\sum_{i, j} \\frac{1}{2\\left(g a^{i} a^{j}\\right)^{2}}\\textsf{Tr}\\big\\{2-\\textsf{W}_{x, i j}-\\textsf{W}_{x, i j}^{\\dagger}\\big\\}\\Big)\n}\n", "meta": {"hexsha": "4cf61e53fa3d089f520fe65008d8af34dad1e944", "size": 11107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FPUB thesis template/latticeqcd.tex", "max_stars_repo_name": "ctp-fpub/LaTeXTemplates", "max_stars_repo_head_hexsha": "8f01709658c05a2271bfb88431dbfc7562454c6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "FPUB thesis template/latticeqcd.tex", "max_issues_repo_name": "ctp-fpub/LaTeXTemplates", "max_issues_repo_head_hexsha": "8f01709658c05a2271bfb88431dbfc7562454c6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-04-04T17:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-04T17:37:37.000Z", "max_forks_repo_path": "FPUB thesis template/latticeqcd.tex", "max_forks_repo_name": "ctp-fpub/LaTeXTemplates", "max_forks_repo_head_hexsha": "8f01709658c05a2271bfb88431dbfc7562454c6f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-02T14:54:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-04T16:42:49.000Z", "avg_line_length": 61.364640884, "max_line_length": 550, "alphanum_fraction": 0.6860538399, "num_tokens": 4020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6978188968357301}}
{"text": "%!TEX root = main.tex\n\\paragraph{Boundary integral formulation of electrostatics in molecular solvation}\\label{s:formulation}\n\nBiomolecules in an ionic solvent or water can be represented with a model where the solvent is a continuous dielectric: the so-called implicit-solvent model.\nThe molecule (solute) is a dielectric cavity with partial charges at the atomic locations,  represented as a collection of Dirac delta functions.\nIn  the sketch of Figure \\ref{fig:implicit_solvent}, the molecular cavity is region $\\Omega_1$, the infinite medium  is $\\Omega_2$, and the point charges are $q_k$.\nThe interface $\\Gamma$ represents the molecular surface and can be determined through several approaches: van der Waals radii, Gaussian surface, solvent-accessible surface, and solvent-excluded surface. \nWe use the latter.\nA solvent-excluded surface is built by tracking the contact points of a (virtual) spherical probe of  $\\sim$ 1.4 \\AA\\ in radius, the size of a water molecule, as it rolls around the solute's atoms (with their corresponding van der Waals radii). \nIn this setup, we can compute the change in electrostatic potential as the interior region is charged up with the solute's partial charges.\nThe solvent usually consists of water (dielectric constant $\\epsilon_2\\approx80$) with salt ions that are free to move around, forced by the electric field. \nAt equilibrium, the salt ions are in a Boltzmann distribution, leading to the linearized Poisson-Boltzmann equation for the potential in $\\Omega_2$, considering a screening factor known as the inverse of the Debye length ($\\kappa$). \nThe electrostatic potential in the solute cavity follows Poisson's equation in a low dielectric medium ($\\epsilon_1\\approx2\\textrm{--}4$), with the solute's point charges as sources.\nWith interface conditions on the molecular surface $\\Gamma$, where the potential and electric displacement must be continuous, this results in the following system of equations:\n%\n\\begin{align} \\label{eq:pde}\n\\nabla^2\\phi_1 &= \\frac{1}{\\epsilon_1}\\sum_k q_k\\delta(\\mathbf{r},\\mathbf{r}_k) \\text{ in the solute ($\\Omega_1$),}\\nonumber\\\\\n(\\nabla^2-\\kappa^2)\\phi_2 &= 0 \\text{ in the solvent ($\\Omega_2$),}\\nonumber\\\\\n\\phi_1 &= \\phi_2 \\quad \\epsilon_1\\frac{\\partial \\phi_1}{\\partial\\mathbf{n}} = \\epsilon_2\\frac{\\partial \\phi_2}{\\partial\\mathbf{n}} \\text{ on the interface ($\\Gamma$)}.\n\\end{align}\n%\n\n%\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.2\\textwidth]{implicit_solvent.pdf}\n\\caption{Representation of a dissolved molecule with the implicit-solvent model. The solute ($\\Omega_1$) and solvent ($\\Omega_2$) regions are interfaced by the solvent-excluded surface ($\\Gamma$), and $q_k$ and $r_{vdW}$ are the atomic charge and radii, respectively.}\n\\label{fig:implicit_solvent}\n\\end{figure}\n\nEquation \\eqref{eq:pde} can be re-written as an integral equation on $\\Gamma$ via Green's second identity, yielding:\n%\n\\begin{align} \\label{eq:volume_potential}\n\\phi_{1}+ K_{L}^{\\Omega_1}(\\phi_{1,\\Gamma}) -  V_{L}^{\\Omega_1} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}  \\phi_{1,\\Gamma}  \\right) & = \\frac{1}{\\epsilon_1} \\sum_{k=0}^{N_q}  \\frac{q_k}{4\\pi|\\mathbf{r}_{\\Omega_1} - \\mathbf{r}_k|}  \\quad \\text{on $\\Omega_1$,} \\nonumber \\\\\n\\phi_{2} - K_{Y}^{\\Omega_2}(\\phi_{2,\\Gamma}) + V_{Y}^{\\Omega_2} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{2,\\Gamma} \\right) & = 0 \\quad \\text{on $\\Omega_2$,}\n\\end{align}\n%\nwhere $\\phi_{1,\\Gamma} = \\phi_1(\\mathbf{r}_\\Gamma)$ and $\\phi_{2,\\Gamma} = \\phi_2(\\mathbf{r}_\\Gamma)$ are evaluated on $\\Gamma$ approaching from $\\Omega_1$ and $\\Omega_2$, respectively. $K$ and $V$ are the double- and single-layer potentials for the Laplace (subscript $L$) and Yukawa (subscript $Y$) kernels, defined as:\n%\n\\begin{align}\\label{eq:single_double}\nV^\\Omega_{L,Y}(\\varphi) = \\oint_\\Gamma g_{L,Y}(\\mathbf{r}_\\Omega,\\mathbf{r}')\\varphi(\\mathbf{r}')d\\mathbf{r}'\\nonumber\\\\\nK^\\Omega_{L,Y}(\\varphi) = \\oint_\\Gamma \\frac{\\partial g_{L,Y}}{\\partial\\mathbf{n}'}(\\mathbf{r}_\\Omega,\\mathbf{r}')\\varphi(\\mathbf{r}')d\\mathbf{r}',\\nonumber\\\\\n\\end{align}\n%\nwhere $\\varphi(\\mathbf{r})$ is a distribution over $\\Gamma$, and $g_L(\\mathbf{r},\\mathbf{r}')=\\frac{1}{4\\pi|\\mathbf{r}-\\mathbf{r}'|}$ and $g_Y(\\mathbf{r},\\mathbf{r}')=\\frac{e^{-\\kappa|\\mathbf{r}-\\mathbf{r}'|}}{4\\pi|\\mathbf{r}-\\mathbf{r}'|}$ are the free-space Green's function of the Laplace and linearized Poisson-Boltzmann equations, respectively. \n\nWe can use Equation \\eqref{eq:volume_potential} to compute $\\phi_\\Gamma$ and $\\partial\\phi_\\Gamma/\\partial\\mathbf{n}$ with either the \\emph{direct}~\\cite{YoonLenhoff1990} or \\emph{derivative}~\\cite{JufferETal1991} (also known as \\emph{Juffer}) formulations.\nThe simpler direct formulation results from evaluating $\\phi_1$ and $\\phi_2$ in the limit as $\\mathbf{r}$ approaches $\\Gamma$, and applying the interface conditions from Equation \\eqref{eq:pde}, giving:\n%\n\\begin{align} \\label{eq:direct}\n\\frac{\\phi_{1,\\Gamma}}{2}+ K_{L}^{\\Gamma}(\\phi_{1,\\Gamma}) -  V_{L}^{\\Gamma} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}  \\phi_{1,\\Gamma}  \\right) & = \\frac{1}{\\epsilon_1} \\sum_{k=0}^{N_q}  \\frac{q_k}{4\\pi|\\mathbf{r}_{\\Gamma} - \\mathbf{r}_k|} \\nonumber \\\\\n\\frac{\\phi_{1,\\Gamma}}{2} - K_{Y}^{\\Gamma}(\\phi_{1,\\Gamma}) + \\frac{\\epsilon_1}{\\epsilon_2}V_{Y}^{\\Gamma} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1,\\Gamma} \\right) & = 0\n\\end{align}\n%\nThis formulation is ill-conditioned, since the condition number of the resulting matrix grows unbounded with the number of discretization elements. \nAn alternative with better conditioning was derived by Juffer \\emph{et al.} \\cite{JufferETal1991} by taking the normal derivative of Equation \\eqref{eq:volume_potential}, and coupling both $\\phi$ and $\\partial\\phi/\\partial\\mathbf{n}$ on the boundary as follows:\n\n\\begin{align}\\label{eq:juffer}\n    &\\begin{multlined}[t][0.48\\textwidth] \\frac{\\phi_{1,\\Gamma}}{2}\\left(1+\\frac{\\epsilon_2}{\\epsilon_1}\\right) - \\left(\\frac{\\epsilon_2}{\\epsilon_1}K_Y^\\Gamma - K_L^\\Gamma\\right)(\\phi_{1,\\Gamma}) \\\\\n    + \\left(V_Y^\\Gamma - V_L^\\Gamma\\right)\\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1,\\Gamma} \\right) = \\sum_{k=0}^{N_q}  \\frac{q_k}{4\\pi\\epsilon_1|\\mathbf{r}_{\\Gamma} - \\mathbf{r}_k|}\n    \\end{multlined} \\nonumber \\\\\n    &\\begin{multlined}[t][0.48\\textwidth] - \\left(W_Y^\\Gamma - W_L^\\Gamma\\right)(\\phi_{1,\\Gamma}) +  \\frac{1}{2}\\frac{\\phi_{1,\\Gamma}}{\\partial\\mathbf{n}}\\left(1+\\frac{\\epsilon_1}{\\epsilon_2}\\right) \\\\\n    + \\left(\\frac{\\epsilon_1}{\\epsilon_2}K_Y^{\\prime\\Gamma} - K_L^{\\prime\\Gamma}\\right)\\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1,\\Gamma} \\right) = \\sum_{k=0}^{N_q}  \\frac{\\partial}{\\partial\\mathbf{n}_\\mathbf{r}}\\left(\\frac{q_k}{4\\pi\\epsilon_1|\\mathbf{r}_{\\Gamma} - \\mathbf{r}_k|}\\right)\n    \\end{multlined}\n\\end{align}\n%\nHere, we use the adjoint double-layer ($K'$) and hypersingular ($W$) operators, which are defined as\n%\n\\begin{align}\\label{eq:adj_hyp}\nK^{\\prime\\Gamma}_{L,Y}(\\varphi) = \\oint_\\Gamma \\frac{g_{L,Y}}{\\partial\\mathbf{n}}(\\mathbf{r}_\\Gamma,\\mathbf{r}')\\varphi(\\mathbf{r}')d\\mathbf{r}'\\nonumber\\\\\nW^\\Gamma_{L,Y}(\\varphi) = \\oint_\\Gamma \\frac{\\partial^2 g_{L,Y}}{\\partial\\mathbf{n}'\\partial\\mathbf{n}}(\\mathbf{r}_\\Gamma,\\mathbf{r}')\\varphi(\\mathbf{r}')d\\mathbf{r}'\\nonumber\\\\\n\\end{align}\n%\nA slightly modified version of Equation \\eqref{eq:juffer} is used in the work from Lu and coworkers~\\cite{LuETal2006,LuETal2009,ZhangETal2019}, where they scale the expressions by $\\epsilon_1/\\epsilon_2$, and solve for the exterior field. This gives\n%\n\\begin{align}\\label{eq:lu}\n    &\\begin{multlined}[t][0.48\\textwidth] \\frac{\\phi_{2,\\Gamma}}{2}\\left(\\frac{\\epsilon_1}{\\epsilon_2}+1\\right) - \\left(K_Y^\\Gamma - \\frac{\\epsilon_1}{\\epsilon_2}K_L^\\Gamma\\right)(\\phi_{2,\\Gamma}) \\\\\n    + \\left(V_Y^\\Gamma - V_L^\\Gamma\\right)\\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{2,\\Gamma} \\right) = \\sum_{k=0}^{N_q}  \\frac{q_k}{4\\pi\\epsilon_2|\\mathbf{r}_{\\Gamma} - \\mathbf{r}_k|}\n    \\end{multlined} \\nonumber \\\\\n    &\\begin{multlined}[t][0.48\\textwidth] -\\frac{\\epsilon_1}{\\epsilon_2}\\left(W_Y^\\Gamma - W_L^\\Gamma\\right)(\\phi_{2,\\Gamma}) +  \\frac{1}{2}\\frac{\\phi_{2,\\Gamma}}{\\partial\\mathbf{n}}\\left(1+\\frac{\\epsilon_1}{\\epsilon_2}\\right) \\\\\n    + \\left(\\frac{\\epsilon_1}{\\epsilon_2}K_Y^{\\prime\\Gamma} - K_L^{\\prime\\Gamma}\\right)\\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{2,\\Gamma} \\right) = \\sum_{k=0}^{N_q}  \\frac{\\partial}{\\partial\\mathbf{n}_\\mathbf{r}}\\left(\\frac{q_k}{4\\pi\\epsilon_2|\\mathbf{r}_{\\Gamma} - \\mathbf{r}_k|}\\right)\n    \\end{multlined}\n\\end{align}\n\nAs we charge up the cavity, the solvent ions rearrange and polarize.\nThe resulting electrostatic potential is called a \\emph{reaction} potential ($\\phi_{reac}$), and we can write the following decomposition in $\\Omega_1$ :\n%\n\\begin{equation}\n\\phi_1 = \\phi_{reac} + \\phi_{coul},\n\\end{equation}\n%\nwhere $\\phi_{coul}$ is the Coulombic potential from the solute point charges only.\nHaving $\\phi_{1,\\Gamma}$ and $\\partial\\phi_{1,\\Gamma}/\\partial\\mathbf{n}$ from Equation \\eqref{eq:direct} or Equation \\eqref{eq:juffer}, we can compute $\\phi_{reac}$ by subtracting out the Coulombic contribution in the right-hand side of Equation \\eqref{eq:volume_potential}:\n%\n\\begin{equation}\\label{eq:phi_reac}\n\\phi_{reac} = -K_{L}^{\\Omega_1}(\\phi_{1,\\Gamma}) +  V_{L}^{\\Omega_1} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}  \\phi_{1,\\Gamma}  \\right) \n\\end{equation}\n\nThe thermodynamic work required to dissolve a molecule, known as solvation free energy, is usually divided into nonpolar and polar components.\nThe nonpolar part generates the empty solute-shaped cavity in the solvent, which is then charged by placing the partial charges inside the cavity, giving rise to a polar term in the energy. \nThe work in charging is performed under $\\phi_{reac}$, and it can be computed as:\n%\n\\begin{equation} \\label{eq:energy}\n\\Delta G^{polar}_{solv} = \\frac{1}{2}\\int_{\\Omega_1} \\rho\\phi_{reac}d\\mathbf{r} = \\frac{1}{2}\\sum_{k=1}^{N_q}q_k\\phi_{reac}(\\mathbf{r}_k).\n\\end{equation}\n", "meta": {"hexsha": "f7f05cddeb23e7ebceb287857c0b397dbcfaffcd", "size": 9948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/methods_formulation.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/methods_formulation.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/methods_formulation.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": 93.8490566038, "max_line_length": 350, "alphanum_fraction": 0.7111982308, "num_tokens": 3370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6977959098331131}}
{"text": "\\newpage\n\n\\section*{Part C: Implementing SVM Variation [20 points] (Yichong and Prakhar) }\n\\textbf{Please attach your code as appendix to this problem.}\\\\\nIn the last homework, we derived a variant of SVM that explicitly maximizes the margin.\nYou can use any library on quadratic optimization (e.g., CVXOPT for python or \\textsf{quadprog} for MATLAB) for this problem. Here is an instruction on CVXOPT.\n\nInstallation instructions of CVXOPT can be found \\href{http://cvxopt.org/install/index.html}{here}. CVXOPT provides an easy interface for quadratic programming: The function \\textsf{qp(P, q[, G, h[, A, b]])} solves the optimization problem\n\\begin{align*}\n\\text{minimize}_{x \\in \\mathbb{R}^n}\\;  & (1/2) x^TPx+q^Tx \\\\\n\\text{subject to } & Gx \\preceq h \\\\\n& Ax=b\n\\end{align*}\nfor $P\\in \\mathbb{R}^{n\\times n}, q\\in \\mathbb{R}^n, G\\in \\mathbb{R}^{m_1\\times n}, h \\in \\mathbb{R}^{m_1}, A \\in \\mathbb{R}^{m_2\\times n}, b \\in \\mathbb{R}^{m_2}$.\nHere $\\preceq$ means pointwise less than or equal; i.e., if $a \\preceq b $ for $a,b \\in \\mathbb{R}^n$, then $a_i\\leq b_i \\forall i=1,2,...,n$, where the subscript indicates coordinates. Look into \\href{http://cvxopt.org/examples/tutorial/qp.html}{here} for a concrete example including all details.\n\nIn last homework we want to solve the following primal problem:\n\\begin{align}\n\\min_{\\boldsymbol{w}, \\boldsymbol{\\xi}, \\rho}&\\quad \\frac{1}{2} {\\boldsymbol{||w||}}_2^2 + \\frac{1}{2}b^2- \\rho + \\frac{\\lambda}{2} \\sum_{i=1}^n \\xi_i^2\\label{eqn:primal}\\\\\n\\text{subject to} &\\quad y_i(w^T \\boldsymbol{x_i} + b) \\ge \\rho - \\xi_i,\\quad i = 1,\\dotsc,n \t\\nonumber\n\\end{align}\n\n\nWe derived a dual program of (\\ref{eqn:primal}) in homework 2. (Have a look at the solutions if you did not solve it - we will release it soon.) Implement the dual program using CVXOPT. Compute results for both $\\lambda=1$ and $\\lambda=10$. The data is a toy dataset *train\\_data.csv* in {\\color{red}csv} format of size $\\mathbb{R}^{100\\times 2}$, and the training label is contained in the file *train\\_label.csv* of size $\\mathbb{R}^{100\\times 1}$. Be careful that CVXOPT uses a slightly different matrix format than numpy; so either create your matrix in CVXOPT format, or use a numpy array and convert it into CVXOPT format using \\textsf{A = cvxopt.matrix(A)}. \\\\\n\\textbf{Answer:}\\\\\nFrom last homework, we know the dual form of this variant SVM as below:\n$$\\argmin_{\\vec{\\alpha}}\\frac{1}{2}||\\sum_{i=1}^{n}\\alpha_iy_i\\vec{x}_i||_2^2 + \\frac{1}{2}(\\sum_{i=1}^{n}\\alpha_iy_i)^2 + \\frac{1}{2\\lambda}\\sum_{i=1}^{n}\\alpha_i^2 $$\ns.t.\n$$\\sum_{i=1}^{n}\\alpha_i=1$$\n$$\\alpha_i \\geq 0$$\nTherefore, we can use CVXOPT to solve this dual problem to get $\\vec{\\alpha}$:\n\nAssume the data matrix and label matrix as below:\n$$$$\n\\begin{equation}\n\\nonumber\n\\begin{array}{rcl}\nX & = & [\\vec{x}_1,\\vec{x}_2,\\dots,\\vec{x}_n]^T \\\\\nY & = & \\left[\\begin{array}{cccc}\ny_1 & 0 & \\dots & 0 \\\\\n0 & y_2 & \\dots & 0 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n0 & 0 & \\dots & y_n\n\\end{array}\\right]\n\\end{array}\n\\end{equation}\n\nThen we can convert the dual form into the CVXOPT form using the following configuration:\n\\begin{equation}\n\\nonumber\n\\begin{array}{rcl}\nP & = & Y^TXX^TY+\\vec{y}\\vec{y}^T+I/\\lambda \\\\\n\\vec{q} & = & \\vec{0} \\\\\nG & = & -I \\\\\nh & = & \\vec{0} \\\\\nA & = & [1,1,\\dots,1] \\\\\nb & = & 1 \\\\\n\\end{array}\n\\end{equation}\n\n(a) \\textbf{[4 points]} Suppose you use $\\boldsymbol{\\alpha}$ as the Lagrange multipliers in dual program. Given the dual solution $\\boldsymbol{\\alpha}$, compute the primal solution $\\boldsymbol{w}, \\boldsymbol{\\xi}, \\rho$ in terms of training data, $\\lambda$ and $\\boldsymbol{\\alpha}$. (Hint: This has been computed in last homework, and you do not need to redo them.) \\\\\n\\textbf{Answer:}\\\\\nFrom last homework, we know that:\n\\begin{equation}\n\\nonumber\n\\sum_{i=1}^{n}\\alpha_i \\vec{z}_i=\\left[\n\\begin{array}{c}\n\\vec{w}^* \\\\\nb^* \\\\\n\\sqrt{\\lambda}\\vec{\\xi}\n\\end{array}\\right],~~where~\\vec{z}_{i}=\\left[\\begin{array}{c}\ny_{i}\\vec{x}_{i}\\\\\ny_{i}\\\\\n\\frac{1}{\\sqrt{\\lambda}}\\vec{e}_{i}\n\\end{array}\\right]\n\\end{equation}\nTherefore, \n\\begin{equation}\n\\nonumber\n\\begin{array}{rcl}\n\\vec{w} & = & X^TY\\vec{\\alpha}\\\\\nb & = & \\vec{\\alpha}^T\\vec{y}\\\\\n\\vec{\\xi} & = & \\vec{\\alpha}\\frac{1}{\\lambda} \\\\\n\\end{array}\n\\end{equation}\nFor any $\\alpha_i\\neq0$, $y_i(\\vec{w}^T\\vec{x}_i+b)=\\rho-\\xi_i$ (complementary slackness); therefore, we can derive $\\rho$ as below:\n$$\\rho = \\min_i(y_i(\\vec{w}^T\\vec{x}_i+b)+\\xi_i)$$\n\n(b) \\textbf{[8 points]} For each value of $\\lambda$, draw a scatter plot of the data and plot the decision border  (where\nthe predicted class label changes) as well as the boundaries of the margin (the area in which\nthere is a nonzero penalty for predicting any label). Use different colors for margins and border. Also use different colors for positive ($y=1$) and negative ($y=-1$) samples.\\\\\n\\textbf{Answer:}\\\\\nSee Fig.\\ref{fig:svm}\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{./img/svm.eps}\n\t\\caption{The Figure of Problem C.b}\n\t\\label{fig:svm}\n\\end{figure}\n\n(c) \\textbf{[4 points]} Report the test error on the test set *test\\_data.csv* and *test\\_label.csv* for each value of $\\lambda$.\\\\\n\\textbf{Answer:}\\\\\n\\begin{itemize}\n\t\\item $\\lambda = 1$: 0.15\n\t\\item $\\lambda = 10$: 0.13\n\t\\item $\\lambda = 100$: 0.15\n\t\\item $\\lambda = 1000$: 0.15\n\\end{itemize}\n\n(d) \\textbf{[4 points]} What is the difference between the result obtained in $\\lambda=1$ and $\\lambda=10$? Why is that?\n\\textbf{Answer:}\\\\\nFrom the figure, we know that the margin area shrinks as the $\\lambda$ increases, because higher $\\lambda$ will less tolerate the slackness and thus shrink the margin area to remove more points from it. The test error of the SVM with $\\lambda=10$ is lower than that with $\\lambda=1$; however, this decreasing trend does not hold for the SVMs with $\\lambda = 100$ and $\\lambda = 1000$.\n\n\\newpage\n\n\\subsection*{Appendix: Code}\n\n\n\\lstinputlisting[language=Python]{./Python/hw3.py}", "meta": {"hexsha": "e58db7c303149c544cf37c65429fb3bc17ce72e7", "size": 5916, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homeworks/HW3/programming.tex", "max_stars_repo_name": "MengwenHe-CMU/17S_10701_MachineLearning", "max_stars_repo_head_hexsha": "613a3087a57a206b83d79855cec359e04cb440f7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-04T01:53:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-14T09:17:05.000Z", "max_issues_repo_path": "Homeworks/HW3/programming.tex", "max_issues_repo_name": "MengwenHe-CMU/17S_10701_MachineLearning", "max_issues_repo_head_hexsha": "613a3087a57a206b83d79855cec359e04cb440f7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homeworks/HW3/programming.tex", "max_forks_repo_name": "MengwenHe-CMU/17S_10701_MachineLearning", "max_forks_repo_head_hexsha": "613a3087a57a206b83d79855cec359e04cb440f7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-20T15:07:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-20T15:07:29.000Z", "avg_line_length": 49.7142857143, "max_line_length": 667, "alphanum_fraction": 0.6817106153, "num_tokens": 2046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6977958963736683}}
{"text": "\\subsection{Notation}\n\n$E_{21}$ is the location at row 2 and column 1, used to eliminate this value.\n\n\\subsection{Inverse}\n\n\\[AA^{-1}=I=A^{-1}A\\]\n\nMatrix multiplication is not commutative:\n\n\\[\\left(A B^{-1}\\right)\\left(B A^{-1}\\right)=A I A^{-1}=I\\]\n\nTranspose inverse fact:\n\n\\[\\boxed{(A^{-1})^TA^T=I}\\]\n\n\\subsection{Concept}\n\nGiven $E_{21}A=U$, where $U$ is upper-triangular, $E^{-1}_{21}A=E^{-1}_{21}U$ gives:\n\n\\[\\boxed{A=LU\\text{ where }L=E^{-1}_{21}}\\]", "meta": {"hexsha": "a3833945177c40a5be447fd6f31d602756137f00", "size": 456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/3_alu.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/3_alu.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/3_alu.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": 21.7142857143, "max_line_length": 84, "alphanum_fraction": 0.6271929825, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6977784255560103}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 10.3 Complex Fourier Transform\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis subroutine computes Fourier transforms for complex data in up to\n6~dimensions using the fast Fourier transform. The relation between values $z$\nand Fourier coefficients $\\zeta $ is defined by%\n\\begin{multline*}\n z(j_1,j_2,\\ldots,j_{ND})= \\sum_{k_1=0}^{N_1-1} \\cdots\\\\\n\\sum_{k_{ND}=0}^{N_{ND}-1}\n\\zeta (k_1,k_2,...,k_{ND})W_1^{j_1k_1} \\cdots\nW_{ND}^{j_{ND}k_{ND}},\\text{ and}\n\\end{multline*}\\vspace{-20pt}\n\\begin{multline*}\n\\zeta(k_1,k_2,\\ldots,k_{ND})=\\frac 1N_1 \\cdots \\frac 1N_{ND}\n\\sum_{j_1=0}^{N_1-1} \\cdots\\\\\n\\sum_{j_{ND}=0}^{N_{ND}-1}\n z(j_1,\\ldots,j_{ND}) W^{-j_1k_1} \\cdots W^{-j_{ND}k_{ND}}\n\\end{multline*}\nwhere $N_\\ell =2^{\\text{M}(\\ell)}$, $W_\\ell =e^{2\\pi i/N_\\ell}$, $%\n0\\leq j_\\ell,\\ k_\\ell \\leq N_\\ell -1$, and $z$ and $\\zeta $ are complex.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[\\bf COMPLEX]  \\ {\\bf A}$(N_1$, $N_2$, ..., $\\geq N_{ND})$\n\\ \\ $[N_k=2^{\\text{M}(k)}]$\n\\item[\\bf REAL]  \\ {\\bf S}$(\\geq \\max (\\nu _1${\\bf , $\\nu _2$, ..., $\\nu\n_{ND})-1)$} $[\\nu _k=2^{\\text{M}(k)-2}]$\n\\item[\\bf INTEGER]  \\ {\\bf M}$(\\geq {\\textstyle ND})${\\bf , ND, MS}\n\\item[\\bf CHARACTER]  \\ {\\bf MODE$*(\\geq {\\textstyle ND})$}\n\\end{description}\nOn the initial call set MS to~0 to indicate the array S($)$ does not yet\ncontain a sine table. Assign values to A(), MODE, M, and ND.\n$$\n\\fbox{{\\bf CALL SCFT(A, MODE, M, ND, MS, S)}}\n$$\nA() will contain computed results. S($)$ will contain the sine table used in\ncomputing the Fourier transform. MS may have been changed.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A()]  [inout] If the argument MODE selects analysis in all dimensions,\nA() contains values $z$ on entry, and Fourier coefficients $\\zeta $ on exit.\nIf MODE selects analysis in all dimensions, A() contains Fourier\ncoefficients $\\zeta $ on entry, and values $z$ on exit. When A() contains $z$%\n, A($j_1+1$, $j_2+1$, ..., $j_{ND}+1)=z(j_1$, $j_2$, ..., $j_{ND})$, and\nwhen A() contains $\\zeta $, A($k_1+1$, $k_2+1$, ..., $k_{ND}+1)=\\zeta (k_1$,\n$k_2$, ..., $k_{ND})$, 0\\ $\\leq j_i,k_i\\leq 2^{\\text{M}(i)}-1$, $i=0$, 1, ..., ND.\n\n\\item[MODE]  [in] The character MODE$(k{:}k)$ selects Analysis or Synthesis\nin the $k^{th}$ dimension. 'A' or 'a' selects Analysis, transforming $%\nz$'s to $\\zeta $'s. 'S' or 's' selects Synthesis,\ntransforming $\\zeta $'s to $z^{\\prime }s.$\n\n\\item[M($)$]  [in] Defines $N_k=2^{\\text{M}(k)}$, the number of complex data points\nin the $k^{th}$ dimension. Require 0$\\ \\leq \\text{M}(k)\\leq 30$ for\nall $k$. No action is taken in dimensions for which M($k)=0.$\n\n\\item[ND]  [in] Number of dimensions. Require 1 $\\leq $ ND $\\leq $ 6.\n\n\\item[MS]  [inout] Gives the state of the sine table in $S()$.  Let\n$\\text{MS}_{in}\\text{ and MS}_{out}$ denote the values of MS on entry\nand return respectively. If the sine table has not previously been\ncomputed, set $\\text{MS}_{in} = 0$ or $-$1 before the call. Otherwise\nthe value of $\\text{MS}_{out}$ from the previous call using the same\nS() array can be used as $\\text{MS}_{in}$ for the current call.\n\nCertain error conditions described in Section E cause the subroutine\nto set $\\text{MS}_{out} = -2$ and return.  Otherwise, with $\\max _i\n\\{\\text{M}(i)\\} > 0$, the subroutine sets $\\text{MS}_{out} = \\max ($M(1),\nM(2), ..., M(ND), $\\text{MS}_{in}).$\n\nIf $\\text{MS}_{out} > \\max (2, \\text{MS}_{in}),$ the subroutine sets\nNT = $2^{\\text{MS}_{out}-2}$ and fills S() with NT $-$ 1 sine values.\n\nIf $\\text{MS}_{in}=-1$, the subroutine returns after the above\nactions, not transforming the data in A().  This is intended to allow\nthe use of the sine table for data alteration before a subsequent Fourier\ntransform, as discussed in Section G of Chapter~16.0.\n\n\\item[S($)$]  [inout] When the sine table has been computed, S($j)=\\sin \\pi\nj/(2\\times {\\textstyle NT})$, $j=1$, 2, ..., NT $-$ 1, see MS above.\n\\end{description}\n\\subsubsection{Modifications for Double Precision}\n\nChange SCFT to DCFT and the REAL type statement to DOUBLE PRECISION. If it\nis available, one can change the COMPLEX type statement to DOUBLE PRECISION\nCOMPLEX. For portability, (or out of necessity) one can change the COMPLEX\nstatement to DOUBLE PRECISION and change the first dimension to be twice as\nbig. The data should then be stored in A with the imaginary parts of the\ncomplex numbers following immediately after the real parts.  This\nrepresentation is compatible with the representation used in Fortran\n90, and with most compilers that extend Fortran~77 to provide a double\nprecision complex type.\n\n\\subsection{Examples and Remarks}\n\nEstimate the spectral composition of%\n$$\nf(t)=[\\sin 2\\pi (t+0.1)+4\\cos 2\\pi (\\sqrt{2}\\,t+0.3)]+0i\n$$\nwhere we make the same assumptions and use the same $\\Delta t$ and N as in\nthe example for SRFT1. Differences between the results given here and those\nobtained for SRFT1 are due to the use of sigma factors in SRFT1. (It is more\nefficient to use SRFT1 when $f$ is a real function. A real function was used\nhere to show the effect of the sigma factors.) Note that the peaks are\nslightly sharper here than they are for SRFT1, but that as one leaves the\npeaks the coefficients do not tend to zero nearly as rapidly as when the\nsigma factors are used. The program to do these calculations and the results\nare given at the end of this chapter.\n\n\\subsection{Functional Description}\n\nThe multi-dimensional complex transform involves calling SFFT to compute\none-dimensional complex transforms with respect to each dimension. For ND $=\n1$, the formulas are given by Eqs.\\,(9) and (10) in Chapter~16.0. For ${%\n\\textstyle ND} \\geq 1$, the formula for $z$ given $\\zeta $ is given in\nPurpose above.  More details can be found in \\cite{Krogh:1970:CFT}.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nRequire 1 $\\leq $ ND $\\leq $ 6 and 0 $\\leq $ M($k)\\leq 30$ for all $k$.\nMODE must have one of its allowed values. If any of these conditions are\nviolated, the subroutine will issue an error message using the error\nprocessing procedures of Chapter~19.2 with severity level~2\nto cause execution to stop. A return is made with $\\text{MS}=-2$\ninstead of stopping if the statement ``CALL\\ ERMSET($-$1)'' is executed\nbefore 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} \\\\\nDCFT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n DCFT, DFFT, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSCFT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n ERFIN, ERMSG, IERM1, IERV1, SCFT, SFFT}\\\\\n\\end{tabular}\n\nSubroutine designed and written by: Fred T. Krogh, JPL, October~1969,\nrevised January~1988.\n\n\n\\begcodenp\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSCFT}\\vspace{0pt}\n\\lstinputlisting{\\codeloc{scft}}\n\n\\vspace{5pt}\\centerline{\\bf \\large ODSCFT}\\vspace{5pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{scft}}\n\\end{document}\n", "meta": {"hexsha": "6b1b5e5e7709c316c4b6b9ad32acd14d2d7e5f1a", "size": 7476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch10-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/ch10-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/ch10-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": 42.9655172414, "max_line_length": 98, "alphanum_fraction": 0.7013108614, "num_tokens": 2462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6976784521710638}}
{"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 26, 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\\end{document}\n\n", "meta": {"hexsha": "b6cd329936f46d435d94067034092f97f2ecf2bc", "size": 1653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-09-29.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-29.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-29.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": 43.5, "max_line_length": 314, "alphanum_fraction": 0.6509376891, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.6976769002241618}}
{"text": "\\section{The Ergodic Theorem}\r\nWe want to study the long-term average behaviour of a Markov chain.\r\nRecall the strong law of large numbers:\r\n\\begin{theorem}[Strong Law of Large Numbers]\r\n    Let $(Y_i)_{i=0,1,\\ldots}$ be a sequence of i.i.d. non-negative random variables, with $\\mathbb EY_i=\\mu\\in[0,\\infty]$, then\r\n    $$\\mathbb P\\left[ \\frac{Y_1+\\cdots+Y_n}{n}\\to\\mu\\text{ as }n\\to\\infty \\right]=1$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\nThe ergodic theorem is a sorta similar thing, but with some twists.\r\nWrite $V_i(n)=\\sum_{k=0}^{n-1}1_{X_k=i}$ as the number of visits to $i$ before $n^{th}$ step, then\r\n\\begin{theorem}[Ergodic Theorem]\\label{ergodic}\r\n    Let $P$ be irreducible and $\\lambda$ be any distribution.\r\n    Take a Markobv chain $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$, then\r\n    $$\\mathbb P\\left[ \\frac{V_i(n)}{n}\\to\\frac{1}{m_i}\\text{ as }n\\to\\infty \\right]=1$$\r\n\\end{theorem}\r\n\\begin{remark}\r\n    1. This does not follow directly from the law of large numbers as $1_{X_k=i}$ are not i.i.d. random variables.\\\\\r\n    2. In particular, if $P$ is positive recurrent, then we know that $\\pi_i=1/m_i$, so it translated to\r\n    $$\\mathbb P\\left[ \\frac{V_i(n)}{n}\\to\\pi_i\\text{ as }n\\to\\infty \\right]=1$$\r\n    which is pretty intuitive.\r\n\\end{remark}\r\n\\begin{proof}\r\n    If $P$ is transient, then $\\mathbb P[V_i<\\infty]=1$ where $V_i=\\sum_{k=0}^\\infty 1_{X_n=i}$ is the total number visits to $i$.\r\n    Therefore $m_i=\\infty$ for any $i$, which means\r\n    $$\\mathbb P\\left[ \\frac{V_i(n)}{n}\\le\\frac{V_i}{n}\\to 0=\\frac{1}{m_i} \\right]=1$$\r\n    as desired.\r\n    If $P$ is recurrent and $\\lambda=\\delta_i$, we shall show that\r\n    $$\\mathbb P\\left[ \\frac{n}{V_i(n)}\\to m_i\\text{ as }n\\to\\infty \\right]=1$$\r\n    Let $S_i^{(r)}$ be the $r^{th}$ excursion length between visits to $i$.\r\n    We know $S_i^{(1)},S_i^{(2)},\\ldots$ are i.i.d. from Theorem \\ref{strong_markov}.\r\n    Also $\\mathbb ES_i^{(r)}=m_i$, so by strong law of large numbers,\r\n    $$\\mathbb P_i\\left( \\frac{S_i^{(1)}+\\cdots S_i^{(n)}}{n}\\to m_i\\text{ as }n\\to\\infty \\right)$$\r\n    To see this implies what we want, note that $S_i^{(1)}+\\cdots S_i^{(V_i(n))}\\ge n$ and $S_i^{(1)}+\\cdots S_i^{(V_i(n)-1)}\\le n-1$, so by dividing both sides of both inequalities by $V_i(n)$ and using $\\mathbb P[V_i(n)\\to\\infty]=1$, we get the desired result.\\\\\r\n    For the general case for a recurrent $P$, note that we have $\\mathbb P[T_i<\\infty]=1$.\r\n    Therefore consider $(X_{T_i+n})_{n\\ge 0}\\sim\\operatorname{Markov}(\\delta_i,P)$ by Theorem \\ref{strong_markov}.\r\n    It is indepenedent of $X_0,\\ldots,X_{T_i}$ by the same theorem.\r\n    The result then follows since the limit of $V_i(n)/n$ as $n\\to\\infty$ is not affected if $(X_n)_{n\\ge 0}$ is replaced by $(X_{T_i+n})_{n\\ge 0}$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    In the case where $P$ is positive recurrent, for any bounded function $f:I\\to\\mathbb R$,\r\n    $$\\mathbb P\\left[ \\frac{1}{n}\\sum_{k=0}^{n-1}f(X_k)\\to\\bar{f}\\text{ as }n\\to\\infty\\right]=1,\\bar{f}=\\sum_{i\\in I}\\pi_if(i)$$\r\n\\end{corollary}\r\nThis gives us ways to estimate the theorectical average of $f$ in the Markov chain by observing how it runs.\r\n\\begin{proof}\r\n    WLOG $|f|\\le 1$.\r\n    Then for any $J\\subset I$ we have\r\n    \\begin{align*}\r\n        \\left|\\frac{1}{n}\\sum_{k=0}^{n-1}f(X_k)-\\bar f\\right|&=\\left|\\sum_{i\\in I}\\left( \\frac{V_i(n)}{n}-\\pi_i \\right) f(i)\\right|\\\\\r\n        &\\le \\sum_{i\\in J}\\left|\\frac{V_i(n)}{n}-\\pi_i\\right|+\\sum_{i\\notin J}\\left( \\frac{V_i(n)}{n}+\\pi_i \\right)\\\\\r\n        &\\le 2\\sum_{i\\in J}\\left|\\frac{V_i(n)}{n}-\\pi_i\\right|+2\\sum_{i\\notin J}\\pi_i\r\n    \\end{align*}\r\n    For any $\\epsilon>0$ choose $J\\subset I$ finite such that $\\sum_{i\\notin J}\\pi_i<\\epsilon$ (for example just take $J=I$) and a random variable $N=N(\\omega)$ large enough such that\r\n    $$\\mathbb P\\left[ \\sum_{i\\in J}\\left|\\frac{V_i(n)}{n}-\\pi_i\\right|<\\epsilon\\text{ for }n\\ge N \\right]=1$$\r\n    Therefore\r\n    $$\\mathbb P\\left[ \\left|\\frac{1}{n}\\sum_{k=0}^{n-1}f(X_k)-\\bar f\\right|<4\\epsilon\\text{ for }n\\ge N \\right]=1$$\r\n    which shows the theorem.\r\n\\end{proof}", "meta": {"hexsha": "d564dcc99fb3f35ac2158c1393f440b9f2153d13", "size": 4076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/ergodic.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": "10/ergodic.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": "10/ergodic.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": 69.0847457627, "max_line_length": 265, "alphanum_fraction": 0.6373895976, "num_tokens": 1552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.6976768996865089}}
{"text": "\\section{Correlation Estimation}\n\\subsection{Biased and unbiased ACF and correlogram spectral}\nFig.\\ref{fig:1_3_a} illustrates both unbiased and biased estimations of autocorrelation function (ACF) and correlogram spectral with WGN, filtered WGN and noisy sinusoidal signals.  Observing the ACF diagrams, the biased and unbiased estimations are same when the lag $k$ is approximately less than 200. As the lag $k$ increases, the tendency is getting to separate in aspect of biased estimation increasing in value and the unbiased tending to zero, which verifies the Eq. \\ref{proof:biase} and\\ref{proof:unbiase} based on the Eq. (12)-(13) in instruction.\n\\begin{align}\n\\text{biased: } \\mathbb{E}\\left\\{\\hat r_{xx}(k)\\right\\} & =\\frac{1}{N} \\sum_{n=k+1}^{N} \\mathbb{E} \\left\\{x(n)x^*(n-k) \\right \\} = \\frac{N-k}{N}\\ r_{xx}\\label{proof:biase}\\\\\n\\text{unbiased: }\\mathbb{E}\\left\\{\\hat r_{xx}(k)\\right\\} & =\\frac{1}{N-k} \\sum_{n=k+1}^{N} \\mathbb{E} \\left\\{x(n)x^*(n-k) \\right \\} = r_{xx}\\label{proof:unbiase}\n\\end{align}\nAs to  correlograms of these two ACF, the biased ACF guarantees the non-negative PSD due to the positive semi-definite of ACF. However, the unbiased ACF accords to true mean of PSD, resulting to highly erratic for large lags $k$. Thus, the ACF is not positive definite and causes negative values of the PSD, which are inappropriate with theory. \n\\begin{figure}[htb]\n\\centering\n\\includegraphics[width=\\textwidth]{fig/13/13a.eps}\n\\caption{Standard and Bartlett Method of EEG Periodograms}\n\\label{fig:1_3_a}\n\\end{figure}\\\\\n\\subsection{PSD estimation with several realisations}\nThe PSD estimations of the signal $x(n)$ in Eq.\\ref{proof:x} are plotted in Fig.\\ref{fig:1_3_b} with 100 realisitions.\n\\begin{equation}\nx(n)=sin(2\\pi2n)+sin(2\\pi3n)+1.5*sin(2\\pi4n)+ \\omega (n) \\quad \\omega \\sim \\mathcal{N} (0,1)\n\\label{proof:x}\n\\end{equation}\nThe mean and standard deciation of the PSD are highlighted. The signal $x(n)$ has three frequency components with $f_1=2 Hz$, $f_2=3 Hz$ and $f_3=4Hz$ which are successfully detected in the PSD. It is obvious that the variance and noise are reduced by taking mean and standard deviation. Howerver, the peak value of the PSD is to sharp. Thus, the interval between realisitions is narrow and indistinct when the PSD estimations is in magnitude scale.\n\\begin{figure}[htb]\n     \\centering\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/13/13b1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/13/13b2.eps}\n     \\end{subfigure}\n        \\caption{PSD estimations with mean and standard deviation}\n        \\label{fig:1_3_b}\n\\end{figure}\n\\subsection{PSD estimation in dB}\nRepeating the process in previous section, the PSD estimations are shown in Fig.\\ref{fig:1_3_c} in decibels scale. Observing the peak value of realisations, it was compressed to a large extent.  As a consequence, the amplitudes of three sinusoid signals seem to be same. Meanwhile, the noise fluctuations are significantly amplified, which increases the variance of the PSD due to the logarithm. Overall, it is an admissible and advantageous presentations to plot the PSD estimations in dB since both large and small features are visible and distinct.\n\\begin{figure}[htbp]\n     \\centering\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/13/13c1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/13/13c2.eps}\n     \\end{subfigure}\n        \\caption{PSD estimations in dB}\n        \\label{fig:1_3_c}\n\\end{figure}\n\\subsection{Peak detection with window resolution}\nFig.\\ref{fig:1_3_d1} depicts the periodograms of peak detection of complex-valued signal by varying the number of sample. It is obvious that the two peaks are becoming with incremental of samples ($N$), since the frequency resolution is proportional to $\\frac{1}{N}$. In this experiment, the rectangular window was applied whose 3$dB$ bandwidth is defined as $0.89(\\frac{2\\pi}{N})$. Therefore, with two frequencies in $0.3Hz$ and $0.32Hz$ in radian, the theoretical number of samples are $N =0.89/(0.32-0.3)=44.5$. Hence, the peaks can be successfully identified when the samples are larger than 45. However, when $N$ is 40 as shown in Fig.\\ref{fig:1_3_d1}, peaks are still detected which is probably caused by the sidelobes of the window.\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=1\\textwidth]{fig/13/13d1.eps}\n    \\caption{Periodogram: peak detection of varying samples}\n    \\label{fig:1_3_d1}\n\\end{figure}\\\\\nFig.\\ref{fig:1_3_d2} illustrates the peak detection with varying frequency interval from $0.32\\sim0.35$. When fixing $N$ to 30, the theoretical frequency interval $\\Delta f= 0.89/30 \\approx 0.3$. As shown in Fig.\\ref{fig:1_3_d2}, the results consist with the theory analyse where the peaks are detectable with $f2 \\ge 0.33$.\\\\\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=1\\textwidth]{fig/13/13d2.eps}\n    \\caption{Periodogram: peak detection of varying frequencies}\n    \\label{fig:1_3_d2}\n\\end{figure}\n\\subsection{Frequency estimation by MUSIC}\nThe Multiple Signal (MUSIC) algorithm is an subspace method which focusing on the eigenvectors. A complex signal with AWGN can be expressed as $\\mathbf x(n)=\\mathbf A \\mathbf e +\\mathbf w$ on vector notation. Thus, its autocorrelation matrix is calculated and decomposed into the sum of signal subspace and noise subspace, as shown below. \n\\begin{equation}\n\\mathbb {E}(\\mathbf{x x}^H)=\\mathbf R_{xx}=\\mathbf{EDE^H+\\sigma^2I}=\\mathbf{E_sD_sE^H_s+E_nD_nE^H_n}\n\\label{proof:Rxx}\n\\end{equation}\nwhere $\\mathbf{E_s=[e_1,...e_p]}$ is the eigenvectors of signal, $\\mathbf{E_s=[v_{p+1},...v_M]}$ is the eigenvectors of noise and $\\mathbf{D}=diag\\mathbf {[A_1,...A_p,\\sigma^2_{p+1}...\\sigma^2_M]}$ is the eigenvalues of subspace. Due to independence between signal and noise vectors, the signal subspace and noise subspace are orthogonal, expressing in $\\mathbf {e_k^Hv_i=0}$. Therefore, the MUSIC algorithm is introduced by\n\\begin{equation}\n{\\hat P_{MU}(\\omega)}=\\frac {1}{\\sum_{i=p+1}^M \\left | \\mathbf{e}^H \\mathbf{v}_i\\right |^2}\n\\label{proof:music}\n\\end{equation}\\\\\nIn this experiment, the function \\texttt{corrmtx} is used to calculated the autocorrelation matrix $\\mathbf R_{xx}$ in Eq.\\ref{proof:Rxx} and \\texttt{pmusic} is the MUSIC function to get the peak frequency in Eq.\\ref{proof:music}. Meanwhile, the $M$ is 14 and $p$ is 2 which are defined as the total dimension of the subspace and the dimension of the signal subspace respectively.\\\\\nFig.\\ref{fig:1_3_e} depicts the estimation of the MUSIC function which is successfully detect the peaks. Comparing with the periodogram method, the MUSIC is using biased estimation and has less variance. Moreover, it can deal with less samples signal, while the periodogram method could only use long length signal due to the window resolution. However, the dimension of signal subspace $p$ need to be determined in advance, which is not practical in general cases. On the contrast, the periodogram method does not require the information of the signal.\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{fig/13/13e.eps}\n    \\caption{Periodogram: MUSIC algorithm}\n    \\label{fig:1_3_e}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "9761a8d4757037a40394a23737c7f37e83fa5c0f", "size": 7450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part1/13.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/13.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/13.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": 83.7078651685, "max_line_length": 739, "alphanum_fraction": 0.7408053691, "num_tokens": 2212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.8740772368049822, "lm_q1q2_score": 0.6976768847485612}}
{"text": "\\subsection{A Functional to obtain Initial Conditions}\n\tThe interesting thing about the equation (\\ref{kolmogorov}), is that there is no standard way to define an initial condition. For this problem, a functional is defined that acts in the initial condition, and because there are different ways of defining this functional, the method may change. For this work, the following functional was chosen \n\t\\begin{align*}\n\t\tu^{z_0}_0 (g) := g(z_0), \\hspace{2mm} \\text{for fixed} \\hspace{2mm} z_0 \\in [0, 1].\n\t\\end{align*}\n\t\n\tTo construct the initial condition, the following set of points is considered \n\t\\begin{align*}\n\t\tP = \\{ z_i, \\hspace{1mm} 0 \\leq i \\leq p \\hspace{1mm} : \\hspace{1mm} z_0 = 0, \\hspace{1mm} z_p = 1 \\}\n\t\\end{align*}\n\t\n\t\\noindent Then for each point $z_i \\in P$ such that $X_0 (z_i) = X(0, z_i)$ set $u_0 (x)$ as the evaluation functional $z_i \\longrightarrow X^x_t (z_i)$. Then from (\\ref{solution_kolmogorov}) we obtain\n\t\\begin{align}\n\t\tu(0, x) = \\mathbb{E}[u^{z_i}_0 (X^x_0)] = X^x (0, z_i) = x(z_i)\n\t\\end{align}\n\tFor other hand\n\t\\begin{align*}\n\t\tu (0, x) = \\displaystyle \\sum _{n \\in \\mathcal{J}^{M, N}} u_{n}(0) H_n (x)\n\t\\end{align*}\n\tmultiplying for $H_m (x)$ and integrating over space $\\mathcal{L}^2 (\\mathcal{H}, \\mu)$ \n\t\\begin{align*}\n\t\tu_m (0) = \\displaystyle \\int_{\\mathcal{H}} x(z_i) H_m (x) \\mu (dx)\n\t\\end{align*}\n\t\n\t\\noindent Note that in the direction of the eigenfunction $e_k$ the expression $x$ can be written as $(x, e_k )_{\\mathcal{H}} e_k$, then we can write $H_m (x) x (z_i)$ in the direction $e_k$ as $P_{m_k} (\\xi_k) (x, e_k )_{\\mathcal{H}} e_k (z_i)$ with $\\xi_k = (x, \\Lambda^{-\\frac{1}{2}} e_k) = \\| \\lambda_k \\| (x, e_k )_{\\mathcal{H}}$ and $P_{m_k}$ is given by (\\ref{hermite_polynomials}). Then we have\n\t\\begin{align*}\n\t\tu^{z_i}_m (0) &= \\displaystyle \\int_{\\mathcal{H}} x(z_i) H_m (x) \\mu (dx) \\\\\n\t\t&= \\int_{\\mathbb{R}^N} \\sum_{k=1}^{\\infty} P_{m_k} (\\xi_k) (x, e_k )_{\\mathcal{H}} e_k (z_i) \\mu (d\\xi_1, d\\xi_2, \\cdots) e_k \\\\\n\t\t&= \\int_{\\mathbb{R}^N} \\sum_{k=1}^{\\infty} P_{m_k} (\\xi_k) \\frac{\\xi_k}{\\lambda_k} e_k (z_i) \\mu (d\\xi_1, d\\xi_2, \\cdots) e_k \\\\\n\t\t&= \\sum_{k=1}^{\\infty} \\frac{e_k}{\\lambda_k} \\int_{\\mathbb{R}}  P_{m_k} (\\xi_k) \\xi_k (z_i) \\mu (d\\xi_k)\n\t\\end{align*}\n\ttruncating the above expression we have\n\t\\begin{align}\n\t\t\\label{IC_approx}\n\t\tu^{z_i}_m (0) \\approx \\displaystyle \\sum_{k=1}^{M} \\frac{e_k}{\\lambda_k} \\int_{\\mathbb{R}}  P_{m_k} (\\xi_k) \\xi_k (z_i) \\mu (d\\xi_k)\n\t\\end{align} \n\t\n\t\\noindent Setting the equation (\\ref{IC_approx}) for each element from $u^{z_i}_m$ as $u^{z_i}_{m_j} (0) = u_j (0)$, $1 \\leq j \\leq M$ and by (\\ref{solution_finite_system}) evaluated for $t=0$, then the initial condition can be written as\n\t\\begin{equation*}\t\n\t\t\\begin{pmatrix}\n\t\t\tu_1 (0) \\\\ u_2 (0) \\\\ \\vdots \\\\ u_{M-1} (0) \\\\\tu_M (0)\n\t\t\\end{pmatrix}\n\t\t= \n\t\t\\begin{pmatrix}\n\t\t\tV1 & V2 & \\dots & V_{M-1} & V_M\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tc_1 \\\\ c_2 \\\\ \\vdots \\\\ c_{M-1} \\\\ c_M\n\t\t\\end{pmatrix}\n\t\\end{equation*}\n\tand the constants $c_j$ are calculated as\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\tc_1 \\\\ c_2 \\\\ \\vdots \\\\ c_{M-1} \\\\ c_M \n\t\t\\end{pmatrix}\n\t\t=\t\n\t\t\\begin{pmatrix}\n\t\t\tV1 & V2 & \\dots & V_{M-1} & V_M\n\t\t\\end{pmatrix}^{-1}\n\t\t\\begin{pmatrix}\n\t\t\tu_1 (0) \\\\ u_2 (0) \\\\ \\vdots \\\\ u_{M-1} (0) \\\\\tu_M (0)\n\t\t\\end{pmatrix}\n\t\\end{equation*}", "meta": {"hexsha": "2ead20b60b7955d63d901f217a28c5651a338795", "size": 3300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/stochastic/numerical_experiments/Initial_Condition.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/Initial_Condition.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/Initial_Condition.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": 52.380952381, "max_line_length": 403, "alphanum_fraction": 0.6275757576, "num_tokens": 1409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6976580472231461}}
{"text": "\\section{Discrete Distributions}\r\n\\begin{definition}\r\n    Let $(\\Omega,\\mathscr F,\\mathbb P)$ be a probability space where $\\Omega$ is a countable set (we will most likely take it as finite), $\\Omega=\\{\\omega_1,\\omega_2,\\ldots\\}$ and $\\mathscr F=2^\\Omega$.\r\n    In order to determine $\\mathbb P$, it sufficed to determine all $p_i=\\mathbb P(\\{\\omega_i\\})$.\r\n    We call $p_i$ as a discrete distribution.\r\n\\end{definition}\r\nNote that $p_i\\ge 0$ and $\\sum_ip_i=1$.\r\n\\subsection{Examples of Useful Distributions}\r\n\\begin{definition}\r\n    $\\Omega=\\{0,1\\}$ and $p_1=p,p_0=1-p$ gives the Bernoulli distribution $\\operatorname{Bern}(p)$.\r\n    This comes from flipped a $p$-coin.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Toss $N$ $p$-coins and count the number of $1$'s (heads).\r\n    So $\\Omega=\\{0,1,\\ldots,N\\}$ and\r\n    $$p_k=\\binom{N}{k}p^k(1-p)^{N-k}$$\r\n    this is called the Binomial distribution $\\operatorname{Bin}(N,p)$.\r\n\\end{definition}\r\nNote that\r\n$$\\sum_{i=0}^Np_k=\\sum_{i=0}^N\\binom{N}{k}p^k(1-p)^{N-k}=1$$\r\nby Binomial Theorem.\r\n\\begin{definition}\r\n    Consider $k$ boxes and we throw $N$ independent balls in them randomly, and $p_i$ is the probability that one of the balls fall into box $i$.\r\n    So $\\Omega=\\{(n_1,n_2,\\ldots,n_k)\\in\\mathbb N_0^k:\\sum_{r=1}^kn_r=N\\}$ and we have\r\n    $$\\mathbb P((n_1,n_2,\\ldots,n_k))=\\binom{N}{n_1,n_2,\\ldots,n_k}p_1^{n_1}\\cdots p_k^{n_k}$$\r\n    This is the multinomial distribution.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Toss a fair coin until we reach a head.\r\n    So $\\Omega=\\{1,2,\\ldots\\}$ and\r\n    $$p_k=\\mathbb P(\\text{tossed $k$ coins until there is a head})=(1-p)^{k-1}p$$\r\n    Sometimes we shift it by $1$ and say $\\Omega=\\{0,1,\\ldots\\}$ and\r\n    $$p_k=\\mathbb P(\\text{tossed $k$ coins before there is a head})=(1-p)^kp$$\r\n    This is called the geometric distribution $\\operatorname{Geom}(p)$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The Poisson distribution is used to model the number of occurences of events in a given period of time.\r\n    For example, number of customer entering a shop in a day.\\\\\r\n    We take $\\Omega=\\{0,1,2\\ldots\\}$ and\r\n    $$\\mathbb P(\\{k\\})=e^{-\\lambda}\\frac{\\lambda^k}{k!}$$\r\n    We call this the Poisson distribution $\\operatorname{Pois}(\\lambda)$ of parameter $\\lambda$.\r\n\\end{definition}\r\nConsider the partition of $[0,1]$ in $n$ intervals of length $1/n$ and in each interval customer arrives with probability $p$ and at most $n$ customers will arrive, then\r\n$$\\mathbb P(\\text{$k$ customers arrived})=\\binom{n}{k}p^k(1-p)^{n-k}$$\r\nwhich is $\\operatorname{Bin}(n,p)$.\r\nBut if we take $p=\\lambda/n$, we have\r\n\\begin{proposition}\r\n    $\\operatorname{Bin}(n,\\lambda/n)\\to\\operatorname{Pois}(\\lambda)$ as $n\\to\\infty$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Fix $k$, then\r\n    \\begin{align*}\r\n        \\mathbb P(\\{k\\})&=\\binom{n}{k}\\frac{\\lambda^k}{n^k}\\left(1-\\frac{\\lambda}{n}\\right)^{n-k}\\\\\r\n        &=\\frac{\\lambda^k}{k!}\\frac{n!}{n^k(n-k)!}(1+\\frac{-\\lambda}{n})^{n-k}\\\\\r\n        &\\to\\frac{\\lambda_k}{k!}e^{-\\lambda}\r\n    \\end{align*}\r\n    as $n\\to\\infty$, which is exactly the Poisson distribution.\r\n\\end{proof}\r\n\\subsection{Random Variables}\r\n\\begin{definition}\r\n    Let $(\\Omega,\\mathscr F,\\mathbb P)$ be a probability space, a random variable $X$ is a function $\\Omega\\to\\mathbb R$ such that\\\\\r\n    1. $\\forall x\\in\\mathbb R, \\{X\\le x\\}=\\{\\omega\\in\\Omega:X(\\omega)\\le x\\}\\in\\mathscr F$.\r\n    \\footnote{Sometimes we also write $\\{X\\in A\\}=\\{\\omega\\in\\Omega:X(\\omega)\\in A\\}$}\r\n\\end{definition}\r\n\\begin{example}\r\n    Given $A\\in\\mathscr F$, the indicator of $A$ is a function $1_A:\\Omega\\to\\{0,1\\}$ with\r\n    $$1_A(\\omega)=\\begin{cases}\r\n        1\\text{, if $\\omega\\in A$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    This is a random variable\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $X$ be a random variable, then the probability distribution function of $X$ to be a function $F_X:\\mathbb R\\to [0,1]$ given by $F_X(x)=\\mathbb P(X\\le x)=\\mathbb P(\\{\\omega\\in\\Omega:X(\\omega)\\le x\\})$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    1. $F_X(x)\\to 1$ as $x\\to\\infty$ and $F_X(x)\\to 0$ as $x\\to -\\infty$.\\\\\r\n    2. $F_X$ is increasing.\\\\\r\n    3. $F_X$ is right continuous, that is,\r\n    $$\\lim_{u\\to 0^+}F_X(x+u)=F_X(x)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $(\\Omega,\\mathscr F,\\mathbb P)$ be a probability space and $(X_1,X_2,\\ldots,X_n)$ is called a random variable in $\\mathbb R^n$ if it is a function $\\Omega\\to\\mathbb R^n$ and for any $(x_1,x_2\\ldots,x_n)\\in\\mathbb R^n$,\r\n    $$\\{X_1\\le x_1,\\ldots,X_n\\le x_n\\}=\\{\\omega\\in\\Omega:X_1(\\omega)\\le x_1,\\ldots,X_n(\\omega)\\le x_n\\}\\in\\mathscr F$$\r\n    Or equivalently, each $X_i$ is a random variable in $\\mathbb R$.\r\n\\end{definition}\r\n\\subsection{Discrete Random Variables}\r\n\\begin{definition}\r\n    We call $X$ a discrete random variable if it is a real random variable and the probablity space is discrete.\\\\\r\n    In this case, we define the function $p_k=\\mathbb P(X=x)=\\mathbb P(\\{\\omega\\in\\Omega:X(\\omega)=x\\})$ as the probability mass function of $X$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The discrete random variables $X_1,X_2,\\ldots,X_n$ are independent if\r\n    $$\\mathbb P(X_1=x_1,\\ldots,X_n=x_n)=\\mathbb P(X_1=x_1)\\cdots\\mathbb P(X_n=x_n)$$\r\n\\end{definition}\r\n\\begin{example}\r\n    If we toss a $p$-coin $n$ times independently, then $p_{\\omega_1,\\ldots,\\omega_n}=\\sum_{k=1}^n p^{\\omega_k}(1-p)^{1-\\omega_k}$ where $(\\omega_1,\\ldots,\\omega_n)\\in\\{0,1\\}^n$.\\\\\r\n    Define $X_k(\\omega_1,\\ldots,\\omega_n)=\\omega_k$, then $\\mathbb P(X_k=1)=p$ and $\\mathbb P(X_k=0)=p$, so $X_k$ has distribution $\\operatorname{Bern}(p)$.\r\n    Furthermore, any $X_k$ are independent.\\\\\r\n    For $\\omega=\\omega_1,\\ldots,\\omega_n$, let $S_n(\\omega)=\\sum_kX_k(\\omega)$, so $S_n$ counts the number of heads and has distribution $\\operatorname{Bin}(n,p)$ as we have $\\mathbb P(S_n=k)=\\binom{n}{k}p^k(1-p)^{n-k}$.\r\n\\end{example}\r\n\\subsection{Discrete Expectation}\r\nConsider a discrete probability space $(\\Omega,\\mathscr F,\\mathbb P)$ and a random variable $X:\\Omega\\to\\mathbb R$, then\r\n\\begin{definition}\r\n    $X$ is called nonnegative if $X(\\Omega)\\subset\\mathbb R_{\\ge 0}$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    For a non-negative random variable $X$, the expectation of $X$ is the sum\r\n    $$\\mathbb E[X]=\\sum_{\\omega\\in\\Omega}X(\\omega)\\mathbb P(\\{\\omega\\})$$\r\n    Since $X$ is nonnegative, this sum is either $0$ or approaches $+\\infty$.\r\n\\end{definition}\r\n\\begin{lemma}\\label{expectation_formula}\r\n    $$\\mathbb E[X]=\\sum_{x\\in\\Omega_X}x\\mathbb P(X=x)$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write $\\Omega_X=\\{X(\\omega):\\omega\\in\\Omega\\}$, then we immediately have\r\n    $$\\Omega=\\bigcup_{x\\in\\Omega_X}\\{X=x\\}\\left( =\\coprod_{x\\in\\Omega_X}\\{X=x\\} \\right)$$\r\n    from definition.\r\n    Use this to expand the formula yields\r\n    \\begin{align*}\r\n        \\mathbb E[X]&=\\sum_{\\omega\\in\\Omega}X(\\omega)\\mathbb P(\\{\\omega\\})\\\\\r\n        &=\\sum_{x\\in\\Omega_X}\\sum_{\\omega\\in\\{X=x\\}}x\\mathbb P(\\{\\omega\\})\\\\\r\n        &=\\sum_{x\\in\\Omega_X}x\\sum_{\\omega\\in\\{X=x\\}}\\mathbb P(\\{\\omega\\})\\\\\r\n        &=\\sum_{x\\in\\Omega_X}x\\mathbb P(X=x)\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nAs one may expect, the expectation can be interpreted as a weighted average of the values taken by the random variable by the respective probabilities.\r\n\\begin{example}\r\n    1. Suppose $X\\sim\\operatorname{Bin}(n,p)$, then\r\n    \\begin{align*}\r\n        \\mathbb E[X]&=\\sum_{k=0}^nk\\binom{n}{k}p^k(1-p)^{n-k}\\\\\r\n        &=\\sum_{k=1}^nn\\binom{n-1}{k-1}p^k(1-p)^{n-k}\\\\\r\n        &=np\\sum_{i=0}^{n-1}\\binom{n-1}{i}p^i(1-p)^{n-i-1}\\\\\r\n        &=np(p+1-p)^{n-1}=np\r\n    \\end{align*}\r\n    2. Suppose $X\\sim\\operatorname{Pois}(\\lambda)$, then\r\n    \\begin{align*}\r\n        \\mathbb E[X]&=\\sum_{n=0}^\\infty n\\frac{\\lambda^n}{n!}e^{-\\lambda}\\\\\r\n        &=\\lambda\\sum_{n=1}^\\infty\\frac{\\lambda^{n-1}}{(n-1)!}e^{-\\lambda}\\\\\r\n        &=\\lambda\r\n    \\end{align*}\r\n\\end{example}\r\nLet $X$ be a general random variable, we can try to define its expectation by decomposing the positive and negative parts, that is\r\n\\begin{definition}\r\n    We decompose $X$ into $X_+=\\max\\{X,0\\}=(X+|X|)/2$ and $X_-=\\max\\{-X,0\\}=(|X|-X)/2$, then $X=X_+-X_-$ and $|X|=X_++X_-$.\r\n    If either $\\mathbb E[X_+]$ or $\\mathbb E[X_-]$ is finite, we define $\\mathbb E[X]=\\mathbb E[X_+]-\\mathbb E[X_-]$.\\\\\r\n    Also, if $\\mathbb E[|X|]<\\infty$, we call $X$ integrable..\r\n\\end{definition}\r\n\\begin{lemma}\r\n    We still have Lemma \\ref{expectation_formula}.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Direct calculation.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    1. $X\\ge 0\\implies \\mathbb E[X]\\ge 0$.\r\n    In particular, if $X\\ge 0$ and $\\mathbb E[X]=0$, then $\\mathbb P(X=0)=1$.\\\\\r\n    2. Let $c\\in\\mathbb R$, then $\\mathbb E[cX]=c\\mathbb E[X]$ and $\\mathbb E[c+X]=\\mathbb c+E[X]$.\r\n    In particular $\\mathbb E[c]=c$.\\\\\r\n    3. Let $X,Y$ be random variables, then $\\mathbb E[X+Y]=\\mathbb E[X]+\\mathbb E[Y]$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n2 and 3 are called \\textit{linearity of expectation}.\r\nAnd in fact, we can extend it and say for a sequence of random variables $X_i$ we have $\\mathbb E\\left[\\sum_nX_n\\right]=\\sum_n\\mathbb E[X_n]$.\r\n\\begin{proposition}\r\n    1. $\\forall A\\in\\mathscr F$, we have $\\mathbb E[1_A]=\\mathbb P(A)$.\\\\\r\n    2. (Law Of The Unconscious Statistician, LOTUS) Let $g:\\mathbb R\\to\\mathbb R$ be a function and $X$ a random variable, then\r\n    $$\\mathbb E[g(X)]=\\sum_{x\\in\\Omega_X}g(x)\\mathbb P(X=x)$$\r\n    3. If a random variable $X$ only takes integral value, then\r\n    $$\\mathbb E(X)=\\sum_{k=1}^\\infty\\mathbb P(X\\ge k)=\\sum_{k=0}^\\infty\\mathbb P(X>k)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1 is from definition.\r\n    For 2, we have\r\n    \\begin{align*}\r\n        \\mathbb E[g(X)]&=\\sum_{y\\in\\Omega_{g(X)}}y\\mathbb P(Y=y)\\\\\r\n        &=\\sum_{y\\in\\Omega_{g(X)}}y\\mathbb P(\\{\\omega:g(X(\\omega))=y\\})\\\\\r\n        &=\\sum_{y\\in\\Omega_{g(X)}}y\\mathbb P(\\{\\omega:X(\\omega)\\in g^{-1}(\\{y\\})\\})\\\\\r\n        &=\\sum_{y\\in\\Omega_{g(X)}}\\sum_{x\\in g^{-1}(\\{y\\})}y\\mathbb P(X=x)\\\\\r\n        &=\\sum_{x\\in\\Omega_X}g(x)\\mathbb P(X=x)\r\n    \\end{align*}\r\n    3 is obvious since we can decompose $X=\\sum_{k=1}^\\infty 1_{\\{X\\ge k\\}}$.\r\n\\end{proof}\r\nOne of the usage of 1 above is to give the following proof of Inclusion-Exclusion.\r\n\\begin{proof}[Another Proof of Inclusion-Exclusion]\r\n    The indicator function satisfies $1_{A^c}=1-1_A,1_{A_1\\cap\\cdots\\cap A_n}=1_{A_1}\\cdots 1_{A_n}$, therefore\r\n    $$1_{A_1\\cup\\cdots\\cup A_n}=1_{(A_1^c\\cap\\cdots\\cap A_n^c)^c}=1-\\prod_{i=1}^n(1-1_{A_i})$$\r\n    Expanding and taking expectation gives the result.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $X$ be a random variable and $n\\in\\mathbb N$, we call $\\mathbb E[X^n]$ the $n^{th}$ moment of $X$, if it is well-defined.\r\n\\end{definition}\r\n\\subsection{Variance}\r\n\\begin{definition}\r\n    Let $X$ be a random variable such that $\\mathbb E[X]$ exists and is finite, then the variance of $X$ is defined as $\\operatorname{Var}(X)=\\mathbb E[(X-\\mathbb E[X])^2]$.\r\n\\end{definition}\r\nIntuitively, the variance is the measure of how ``spread out'' the random variable is.\r\nSo a smaller variance would mean that the random variable is largely concentrated in its expected value.\r\nIndubitably $\\operatorname{Var}(X)\\ge 0$, so we can define\r\n\\begin{definition}\r\n    The standard deviation is defined as $\\operatorname{SD}(X)=\\sqrt{\\operatorname{Var}(X)}$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    1. If $\\operatorname{Var}(X)=0$, then $\\mathbb P(X=\\mathbb E[X])=1$.\\\\\r\n    2. Let $c\\in\\mathbb R$, then $\\operatorname{Var}(cX)=c^2\\operatorname{Var}(X)$.\\\\\r\n    3. $\\operatorname{Var}(X)=\\mathbb E[X^2]-(\\mathbb E[X])^2$.\\\\\r\n    4. $\\forall x\\in\\mathbb R,\\operatorname{Var}(X)\\le \\mathbb E[(X-x)^2]$ and equality hold iff $x=\\mathbb E[X]$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. For $X\\sim\\operatorname{Bin}(n,p)$, we have\r\n    \\begin{align*}\r\n        \\operatorname{Var}(X)&=\\mathbb E[X^2]-(\\mathbb E[X])^2\\\\\r\n        &=\\mathbb E[X(X-1)]+\\mathbb E[X]-(\\mathbb E[X])^2\\\\\r\n        &=\\sum_{k=0}^nk(k-1)\\binom{n}{k}p^k(1-p)^{n-k}+np-n^2p^2\\\\\r\n        &=p^2n(n-1)\\sum_{k=0}^n\\binom{n-2}{k-2}p^{k-2}(1-p)^{n-k}+np-n^2p^2\\\\\r\n        &=np(1-p)\r\n    \\end{align*}\r\n    2. For $X\\sim\\operatorname{Pois}(\\lambda)$, we can calculate\r\n    \\begin{align*}\r\n        \\operatorname{Var}(X)&=\\mathbb E[X(X-1)]+\\mathbb E[X]-(\\mathbb E[X])^2\\\\\r\n        &=\\sum_{k=0}^\\infty k(k-1)\\frac{\\lambda^k}{k!}e^{-\\lambda}+\\lambda-\\lambda^2\\\\\r\n        &=\\lambda^2+\\lambda-\\lambda^2\\\\\r\n        &=\\lambda\r\n    \\end{align*}\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $X,Y$ be two random variables, we define the covariance to be\r\n    $$\\operatorname{Cov}(X,Y)=\\mathbb E[(X-\\mathbb E[X])(Y-\\mathbb E[Y])]$$\r\n\\end{definition}\r\nThe covariance is a measure of the interdependence of $X,Y$.\r\n\\begin{proposition}\r\n    1. $\\operatorname{Cov}(X,Y)=\\operatorname{Cov}(Y,X)$.\\\\\r\n    2. $\\operatorname{Cov}(X,X)=\\operatorname{Var}(X)$.\\\\\r\n    3. $\\operatorname{Cov}(X,Y)=\\mathbb E[XY]-\\mathbb E[X]\\mathbb E[Y]$.\\\\\r\n    4. Suppose $c$ is a constant, then $\\operatorname{Cov}(cX,Y)=c\\operatorname{Cov}(X,Y),\\operatorname{Cov}(c+X,Y)=\\operatorname{Cov}(X,Y)$.\\\\\r\n    5. $\\operatorname{Var}(X+Y)=\\operatorname{Var}(X)+\\operatorname{Var}(Y)+2\\operatorname{Cov}(X,Y)$.\r\n    Easy to generalize it to finite sums\\\\\r\n    6. For any constant $c$, $\\operatorname{Cov}(c,X)=0$.\\\\\r\n    7. $\\operatorname{Cov}(X+Z,Y)=\\operatorname{Cov}(X,Y)+\\operatorname{Cov}(Z,Y)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    $X,Y$ are called independent if $\\mathbb P(X=x,Y=y)=\\mathbb P(X=x)\\mathbb P(Y=y)$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Let $X,Y$ be independent and $f,g$ be nonnegative functions, then $\\mathbb E[f(X)g(Y)]=\\mathbb E[f(X)]\\mathbb E[g(Y)]$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    \\begin{align*}\r\n        \\mathbb E[f(X)g(Y)]&=\\sum_{x,y}f(x)g(y)\\mathbb P(X=x,Y=y)\\\\\r\n        &=\\sum_{x,y}f(x)g(y)\\mathbb P(X=x)\\mathbb P(Y=y)\\\\\r\n        &=\\left( \\sum_xf(x)\\mathbb P(X=x) \\right)\\left( \\sum_yf(y)\\mathbb P(Y=y) \\right)\\\\\r\n        &=\\mathbb E[f(X)]\\mathbb E[g(Y)]\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nIn particular, if $X,Y$ are independent, then $\\operatorname{Cov}(X,Y)=0$.\r\nThe converse, however, is not true.\r\n\\begin{example}[Non-example]\r\n    Let $X_1,X_2,X_3\\sim\\operatorname{Bern}(1/2)$.\r\n    Define $Y_1=2X_1-1,Y_2=2X_2-1,Z_1=Y_1X_3,Z_2=Y_2X_3$.\r\n    Now $\\operatorname{Cov}(Z_1,Z_2)=0$ but $Z_1,Z_2$ are not independent as $\\mathbb E[Z_1=0,Z_2=0]=1/2\\neq1/4=\\mathbb E[Z_1=0]\\mathbb E[Z_2=0]$.\r\n\\end{example}\r\n", "meta": {"hexsha": "d7101ed0d6f40b9c52694cf8ffb8adf20038d368", "size": 14595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/discrete.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": "4/discrete.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": "4/discrete.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": 53.0727272727, "max_line_length": 227, "alphanum_fraction": 0.626173347, "num_tokens": 5416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6976580360418103}}
{"text": "\\documentclass[]{article}\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage[cache=false]{minted}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\graphicspath{ {./images/} }\n\\usepackage{multirow}\n\\usepackage{framed}\n\\usepackage{cancel, xcolor}\n%\n\\usepackage{tikz}\n\\usetikzlibrary{calc,arrows}\n\\newcommand{\\tikzmark}[1]{%\n\t\\tikz[overlay,remember picture]\\node(#1){};}\n%\n\\newcommand\\hcancel[2][black]{\\setbox0=\\hbox{$#2$}%\n\t\\rlap{\\raisebox{.45\\ht0}{\\textcolor{#1}{\\rule{\\wd0}{1pt}}}}#2} \n%\n\\begin{document}\n\\section{Properties and Operations}\n\\subsection{Special Matrices}\n\t\\begin{align*}\n\t\tO_{mn} &=\n\t\t\t\\begin{bmatrix}\n\t\t\t\t0_{11} & \\cdots & 0_{1n} \\\\\n\t\t\t\t\\vdots & \\ddots & \\vdots \\\\\n\t\t\t\t0_{m1 }& \\cdots & 0_{mn} \\\\\n\t\t\t\\end{bmatrix}\n\t\t\\\\\n\t\tI &=\n\t\t\t\\begin{bmatrix}\n\t\t\t\t1      & 0      & \\cdots & 0      \\\\\n\t\t\t\t0      & 1      & \\ddots & \\vdots \\\\\n\t\t\t\t\\vdots & \\ddots & 1      & 0      \\\\\n\t\t\t\t0      & \\cdots & 0      & 1      \\\\\n\t\t\t\\end{bmatrix}\n\t\\end{align*}\n\\subsection{List of Basic Property Theorems}\n\\subsubsection{Properties of Matrix Addition and Scalar Multiplication}\n\t\\begin{align}\n\t\tA + B &= B + A \\\\\n\t\tA + (B + C) &= (A + B) + C \\\\\n\t\t(cd)A &= c(dA) \\\\\n\t\t1A &= A \\\\\n\t\tc(A + B) &= cA + cB \\\\\n\t\t(c + d)A &= cA + dA\n\t\\end{align}\n\\subsubsection{Properties of Zero Matrices}\n\t\\begin{align}\n\t\tA + O_{mn} &= A \\\\\n\t\tA + (-A) &= O_{mn} \\\\ \n\t\t\\text{If } cA &= O_{mn} \\text{ then } c = 0 \\text{ or } A = O_{mn}\n\t\\end{align}\n\\subsubsection{Properties of Matrix Multiplication}\n\t\\begin{align}\n\t\tA ( BC ) &= ( AB ) C \\\\\n\t\tA ( B + C ) &= AB + AC \\\\\n\t\t( A + B ) C &= AC + BC \\\\\n\t\tc ( AB ) = ( &cA ) B = A ( cB )\n\t\\end{align}\n\\subsubsection{Properties of Identity Matrix}\n\t\\begin{align}\n\t\tAI_{n} &= A \\\\\n\t\tI_{m}A &= A\n\t\\end{align}\n\\subsection{Transposition}\n\t\\begin{align*}\n\tA &= \n\t\t\\begin{bmatrix}\n\t\t\ta & b & c \\\\\n\t\t\td & e & f \\\\\n\t\t\tg & h & i \\\\\n\t\t\\end{bmatrix}\n\t\\\\\n\tA^T &= \n\t\t\\begin{bmatrix}\n\t\t\ta & d & g \\\\\n\t\t\tb & e & h \\\\\n\t\t\tc & f & i \\\\\n\t\t\\end{bmatrix}\n\t\\end{align*}\n\\subsubsection{Properties of Transposed Matrix}\n\t\\begin{align}\n\t\t( A^T )^T &= A \\\\\n\t\t( A + B )^T &= A^T + B^T \\\\\n\t\t( cA )^T &= c ( A^T ) \\\\\n\t\t( AB )^T &= B^T A^T\n\t\\end{align}\n\\subsection{Inverse Matrices}\n\\subsubsection{Properties of Inverse Matrices}\n\t\\begin{align}\n\t\t( A^{−1} )^{−1} &= A  \\\\\n\t\t( A^k )^{−1} = A^{−1} A^{−1}  &\\cdots A^{−1}  = ( A^{−1})^k \\\\\n\t\t( cA )^{−1} &= \\frac{1}{c}A^{−1} \\\\\n\t\t( A^T )^{−1} &= ( A^{−1} )^T \\\\\n\t\t(AB)^{−1} &= B^{−1}A^{−1} \\\\\n\t\tAC = BC &\\rightarrow A = B \\text{  if C is inversible} \\\\\n\t\tCA = CB &\\rightarrow A = B \\text{  if C is inversible} \n\t\\end{align}\nSystems of Equations \n$Ax = y$ \nhave a unique solution \n$x = A^{-1}b$.\n\t\\begin{framed}\n\t\tExample: \\\\\n\t\t\\begin{align*}\n\t\t\ta_{11}x_1 + a_{12}x_2 + a_{13}x_3 &= y_1 \\\\\n\t\t\ta_{21}x_1 + a_{22}x_2 + a_{23}x_3 &= y_2 \\\\\n\t\t\ta_{31}x_1 + a_{32}x_2 + a_{33}x_3 &= y_3\n\t\t\\end{align*}\n\t\t\\begin{center}\n\t\t$ \n\t\t\tA^{-1} \n\t\t\t\\begin{bmatrix} y_1 \\\\ y_2 \\\\ y_3 \\end{bmatrix} = \n\t\t\t\\begin{bmatrix} x_1 & x_2 & x_3 \\end{bmatrix} \n\t\t$\n\t\t\\end{center}\n\t\\end{framed}\t\n\t\n\\subsubsection{Using Gauss-Jordan Elimination}\n\t\\begin{align*}\n\tA &= \n\t\t\\begin{bmatrix}\n\t\t\ta_{11} & a_{12} & a_{13} \\\\\n\t\t\ta_{21} & a_{22} & a_{23} \\\\\n\t\t\ta_{31} & a_{32} & a_{33} \\\\\n\t\t\\end{bmatrix}\n\t\\\\\n\t\t\\begin{bmatrix}\n\t\t\ta & b & c &1&0&0 \\\\\n\t\t\td & e & f &0&1&0 \\\\\n\t\t\tg & h & i &0&0&1 \\\\\n\t\t\\end{bmatrix}\n\t&\\rightarrow\n\t\t\\begin{bmatrix}\n\t\t\t1&0&0& a\\prime & b\\prime & c\\prime  \\\\\n\t\t\t0&1&0& d\\prime & e\\prime & f\\prime  \\\\\n\t\t\t0&0&1& g\\prime & h\\prime & i\\prime  \\\\\n\t\t\\end{bmatrix}\n\t\\\\\n\t\\begin{bmatrix} A & I \\end{bmatrix} \n\t&=\n\t\\begin{bmatrix} I & A^{-1} \\end{bmatrix}\n\t\\\\\n\tA^{-1} &=\n\t\t\\begin{bmatrix}\n\t\t\ta\\prime & b\\prime & c\\prime  \\\\\n\t\t\td\\prime & e\\prime & f\\prime  \\\\\n\t\t\tg\\prime & h\\prime & i\\prime  \\\\\n\t\t\\end{bmatrix}\n\t\\end{align*}\n\n\\subsubsection{2x2 Quick Solution}\nFirst is a square matrix which can be inverted using a simple rearrangement and multiplication by the inverse of the \\textbf{Determinant}.\n\t\\begin{align*}\n\t\tA &= \n\t\t\t\\begin{bmatrix}\n\t\t\t\ta & b \\\\\n\t\t\t\tc & d \\\\\n\t\t\t\\end{bmatrix}\n\t\t\\\\\n\t\tA^{-1} &= \n\t\t\t\\frac{1}{ad - bc}\n\t\t\t\\begin{bmatrix}\n\t\t\t\t d &-b \\\\\n\t\t\t\t-c & a \\\\\n\t\t\t\\end{bmatrix}\n\t\\end{align*}\n\\section{Elementary Matrices}\nAre one single operation away from the I matrix: \\\\\n$$\n\\begin{bmatrix}\n\t1      & 0      & \\cdots & 0      \\\\\n\t0      & 1      & \\ddots & \\vdots \\\\\n\t\\vdots & \\ddots & 1      & 0      \\\\\n\t0      & \\cdots & 0      & 1      \\\\\n\\end{bmatrix}\n$$\\\\\nEvery elementary matrix $E$ is invertible and $E^{-1}$ is also an elementary matrix.\n\\subsection{Matrices as Products of Elementary Matrices}\n\n\\subsection{LU Factorization}\n$ A = LU $ \\\\\nMatrix $A$ is equal to the product of a Lower corner and Upper corner factor. \\\\\n$$ A =\n\\begin{bmatrix}\n\t1 & -3 & 0 \\\\\n\t0 &  1 & 3 \\\\\n\t2 & -10 & 2 \\\\\n\\end{bmatrix}\n$$\n\t$$\n\t\\begin{bmatrix}\n\t\t1 & -3 & 0 \\\\\n\t\t0 &  1 & 3 \\\\\n\t\t0 & -4 & 2 \\\\\n\t\\end{bmatrix}\n\t\\hspace{1.5em}\n\tR_3+(-2)R_1 \\rightarrow R_3\n\t\\hspace{2em} E_1 =\n\t\\begin{bmatrix}\n\t\t 1 & 0 & 0 \\\\\n\t\t 0 & 1 & 0 \\\\\n\t\t-2 & 0 & 0 \\\\\n\t\\end{bmatrix}\n\t$$\\\\\n\t$$\n\t\\begin{bmatrix}\n\t\t1 & -3 & 0 \\\\\n\t\t0 &  1 & 3 \\\\\n\t\t0 &  0 & 14 \\\\\n\t\\end{bmatrix}\n\t\\hspace{1.5em}\n\tR_3+(4)R_2 \\rightarrow R_3 \n\t\\hspace{2em} E_2 =\n\t\\begin{bmatrix}\n\t\t1 & 0 & 0 \\\\\n\t\t0 & 1 & 0 \\\\\n\t\t0 & 4 & 0 \\\\\n\t\\end{bmatrix}\n\t$$\\\\\nThe final matrix on the left is $L$.\\\\\n$ L = E_n \\cdots E_2E_1A $ \\\\\n$ U = E_1^{-1} E_2^{-1} \\cdots E_n^{-1} $\n\\section{Determinants}\n\n\\subsection{Minors}\nMinors are the determinant of entries in a matrix that do not share a column or row with the current position. \\\\\n$$\n\\begin{bmatrix}\n\ta_{11} & \\hcancel[red]{a_{12}} & a_{13} \\\\\n\t\\hcancel[red]{a_{21}} & \\textcolor{red}{a_{22}} & \\hcancel[red]{a_{23}} \\\\\n\ta_{31} & \\hcancel[red]{a_{32}} & a_{33} \\\\\n\\end{bmatrix}\n\\rightarrow\nM_{22} = \n\\begin{vmatrix}\n\ta_{11} & a_{13} \\\\\n\ta_{31} & a_{33} \\\\\n\\end{vmatrix}\n$$\n$$\n\\begin{bmatrix}\n\t\\textcolor{red}{a_{11}} & \\hcancel[red]{a_{12}} & \\hcancel[red]{a_{13}} \\\\\n\t\\hcancel[red]{a_{21}} & a_{22} & a_{23} \\\\\n\t\\hcancel[red]{a_{31}} & a_{32} & a_{33} \\\\\n\\end{bmatrix}\n\\rightarrow\nM_{11} = \n\\begin{vmatrix}\n\ta_{22} & a_{23} \\\\\n\ta_{32} & a_{33} \\\\\n\\end{vmatrix}\n$$\n\\subsection{Cofactors}\n$ C_{ij} = (-1)^{i+j} M_{ij} $ \\\\\nThis follows the following sign pattern: \\\\\n$$\n\t\\begin{bmatrix}\n\t\t+&-&+&-&+&-&\\cdots\\\\\n\t\t-&+&-&+&-&+&\\cdots\\\\\n\t\t+&-&+&-&+&-&\\cdots\\\\\n\t\t-&+&-&+&-&+&\\cdots\\\\\n\t\t+&-&+&-&+&-&\\cdots\\\\\n\t\t\\vdots&\\vdots&\\vdots&\\vdots&\\vdots&\\vdots&\\ddots\\\\\n\t\\end{bmatrix}\n$$\n\\subsection{Determinants of Larger Matrices}\nThe generalized Equation: \\\\\n$$\ndet(A) = |A| =\n\\sum_{j=1}^{n}a_{1j}C_{1j} = \na_{11}C_{11} + a_{12}C_{12} + \\cdots + a_{1n}C_{1n}\n$$ \\\\\nThis can be applied to any single row or column. \\emph{Choose wisely.}\n\\subsubsection{Alternate Method}\n$$\ndet(A) =\n\\left|A\\right| =\n\t\\begin{vmatrix}\n\t\t\\tikzmark{s1}a_{11} & a_{12}\\tikzmark{n2} \\\\\n\t\t\\tikzmark{s2}a_{21} & a_{22}\\tikzmark{n1} \\\\\n\t\\end{vmatrix}\n= a_{11}\\tikzmark{e1}a_{22} - a_{12}\\tikzmark{e2}a_{21} $$\n\t\\begin{tikzpicture}[overlay,remember picture]\n\t\t\\draw[->,blue]\n\t\t\t($(s1.north west)+(0.1,0.1)$) -- \n\t\t\t($(n1.south east)+(0.1,-0.1)$) -| \n\t\t\t($(e1.south)+(-0.1,0)$) ;\n\t\t\\draw[->,red]\n\t\t\t($(s2.south east)+(-0.1,0.1)$) -- \n\t\t\t($(n2.north west)+(0.1,0.2)$) -| \n\t\t\t($(e2.north)+(0,0.1)$) ;\n\t\\end{tikzpicture}\n\n\\hspace{5em} Subtract these products\n$$\n\t\\begin{bmatrix}\n\t\t\\tikzmark{downS}a_{11} & a_{12} & \\tikzmark{upE}a_{13} & a_{11} & a_{12} \\\\\n\t\ta_{21} & a_{22} & a_{23} & a_{21} & a_{22} \\\\\n\t\t\\tikzmark{upS}a_{31} & a_{32} & \\tikzmark{downE}a_{33} & a_{31} & a_{32} \\\\\n\t\\end{bmatrix}\n$$\n\\begin{tikzpicture}[overlay,remember picture]\n\t\\draw[->,blue]($(upS.south west)+(0,0)$) -> ($(upE.north east)+(0.2,0.1)$);\n\t\\draw[->,blue]($(upS.south west)+(1,0)$) -> ($(upE.north east)+(1.2,0.1)$);\n\t\\draw[->,blue]($(upS.south west)+(2,0)$) -> ($(upE.north east)+(2.2,0.1)$);\n\t\\draw[->,red]($(downS.north west)+(0,0.1)$) -> ($(downE.south east)+(0.1,0)$);\n\t\\draw[->,red]($(downS.north west)+(1,0.1)$) -> ($(downE.south east)+(1.1,0)$);\n\t\\draw[->,red]($(downS.north west)+(2,0.1)$) -> ($(downE.south east)+(2.1,0)$);\n\\end{tikzpicture}\n\\hspace{5em} Add these products \\\\\n$ ∣A∣= \na_{11}a_{22}a_{33} + \na_{12}a_{23}a_{31} + \na_{13}a_{21}a_{32} − \na_{31}a_{22}a_{13} − \na_{32}a_{23}a_{11} − \na_{33}a_{21}a_{12} $\n\n\\subsection{Adjoint Matrices}\nAdjoint matrices are the transpose of a matrix of Cofactors: \\\\\n$ adj(A) =\n\\begin{bmatrix}\n\tC_{11} & C_{21} & C_{n1} \\\\\n\tC_{12} & C_{22} & C_{n2} \\\\\n\tC_{1n} & C_{2n} & C_{nn} \\\\\n\\end{bmatrix} $\n\n\\subsection{Properties of Determinants}\n\\begin{align}\n\t|A||B| &= |AB| \\\\\n\t|cA| &= c^n|A| \\\\\n\t|A| &= |A^T| \\\\\n\t|A^{-1}| &= \\frac{1}{|A|} \\\\\n\tA^{-1} &= \\frac{1}{|A|}adj(A) \\\\\t\n\\end{align}\n\n\\subsection{Cramer's Rule}\nFor a system of equations: \\\\\n\\begin{align*}\n\ta_{11}x_1 + a_{12}x_2 + a_{13}x_3 &= b_1 \\\\\n\ta_{21}x_1 + a_{22}x_2 + a_{23}x_3 &= b_2 \\\\\n\ta_{31}x_1 + a_{32}x_2 + a_{33}x_3 &= b_3 \\\\\n\\end{align*}\n\\begin{align*}\n\tx_1 &= \\frac{|A_1|}{|A|} \\\\\n\tx_2 &= \\frac{|A_2|}{|A|} \\\\\n\t\t&\\cdots \\\\\n\tA_1 &=\n\t\t\\begin{bmatrix}\n\t\t\t\\color{red}{b_1} & a_{12} & a_{13} \\\\\n\t\t\t\\color{red}{b_{2}} & a_{22} & a_{23} \\\\\n\t\t\t\\color{red}{b_{3}} & a_{32} & a_{33} \\\\\n\t\t\\end{bmatrix} \\\\\n\tA_2 &=\n\t\t\\begin{bmatrix}\n\t\t\ta_{11} & \\color{red}{b_{1}} & a_{13} \\\\\n\t\t\ta_{21} & \\color{red}{b_{2}} & a_{23} \\\\\n\t\t\ta_{31} & \\color{red}{b_{3}} & a_{33} \\\\\n\t\t\\end{bmatrix} \n\\end{align*}\n\n\\subsection{Applications of Determinants}\n\\subsubsection{Area of a Triangle}\nFor a triangle with points $(x_1,y_1)$,$(x_2,y_2)$, and $(x_3,y_3)$ \\\\\n\\begin{align*}\n\t\\text{Area} = \\pm\\frac{1}{2}\n\t\t\\begin{vmatrix}\n\t\t\tx_{1} & y_{1} & 1 \\\\\n\t\t\tx_{2} & y_{2} & 1 \\\\\n\t\t\tx_{3} & y_{3} & 1 \\\\\n\t\t\\end{vmatrix} \n\\end{align*} \\\\\nThis can likewise be used to solve for the volume of a \ntetrahedron in 3-dimensional space. \\\\\n\\begin{align*}\n\t\\text{Area} = \\pm\\frac{1}{6}\n\t\t\\begin{vmatrix}\n\t\t\tx_{1} & y_{1} & z_1 & 1 \\\\\n\t\t\tx_{2} & y_{2} & z_2 & 1 \\\\\n\t\t\tx_{3} & y_{3} & z_3 & 1 \\\\\n\t\t\tx_4 & y_4 & z_4 & 1\n\t\t\\end{vmatrix} \n\\end{align*} \\\\\n\n\\subsubsection{Colinearity}\nIf \\\\\n\\begin{align*}\n\t\\begin{vmatrix}\n\t\tx_{1} & y_{1} & 1 \\\\\n\t\tx_{2} & y_{2} & 1 \\\\\n\t\tx_{3} & y_{3} & 1 \\\\\n\t\\end{vmatrix}\n\t= 0 \n\\end{align*} \\\\\nThen the 3 points are on the same line. \nLikewise solving the following for $x$ and $y$ \nwill give the equation of the line that passes through the other two points. \\\\\n\\begin{align*}\n\t\\begin{vmatrix}\n\t\tx_{1} & y_{1} & 1 \\\\\n\t\tx_{2} & y_{2} & 1 \\\\\n\t\tx & y & 1 \\\\\n\t\\end{vmatrix}\n\t= 0 \n\\end{align*} \\\\\nThis can also be used to test for Coplanar points in 3D space\nusing the same expansion to 4x4 as seen above.\n\n\n\\section{Vector Space}\n\n\\subsection{Properties of Vector Addition and Scalar Multiplication in a Plane}\n\nLet $v$, $u$, and $w$  be vectors and $c$ and $d$ be scalars. \\\\\n\\begin{align}\n\tv + u &= u + v \\\\\n\t( u + v ) + w &= u + ( v + w ) \\\\\n\tv + u &= (v_1 + u_1),(v_2 + u_2) \\\\\n\tu + 0 &= u \\\\\n\tu + (-u) &= 0 \\\\\n\tc ( u + v ) &= cu + cv \\\\\n\t( c + d ) u &= cu + du \\\\\n\tc ( du ) &= ( cd ) u \\\\ \n\\end{align} \\\\\n\\textbf{Summary of important Vector Spaces} \\\\\n\\begin{align*}\nR &= \\text{set of all real numbers}\\\\\nR^2 &= \\text{set of all ordered pairs}\\\\\nR^3 &= \\text{set of all ordered triples}\\\\\nR^n &= \\text{set of all n-tuples}\\\\\nC ( − \\inf , \\inf ) &= \n\t\t\\text{set of all continuous functions defined on the real number line} \\\\\nC [ a, b ] &= \n\t\t\\text{set of all continuous functions defined on a closed interval }[ a, b ] , \\\\\n\t\t& \\text{where } a \\neq b \\\\\nP &= \\text{set of all polynomials}\\\\\nP_n &= \\text{set of all polynomials of degree} ≤ n \n\t\t\\text{(together with the zero polynomial)} \\\\\nM_{m,n} &= \\text{set of all } m × n \\text{matrices} \\\\\nM_{n,n} &= \\text{set of all } n × n \\text{square matrices} \\\\\n\\end{align*} \\\\\n\n\\subsection{Subspaces}\n\n\\textbf{The Test for Subspace} \\\\\n\\begin{enumerate}\n\t\\item If Subspace is non-empty. (Includes the 0 vector)\n\t\\item If $u$ and $v$ are in $W$, then $u+v$ is in $W$. (Closed by Addition)\n\t\\item If $u$ is in $W$ and $c$ is any scalar, then $cu$ is in $W$ (Closed by Multiplication)\n\\end{enumerate}\n\n\\subsection{Linear Combinations of Vectors}\nVector v in vector space V is a linear combination of vectors if\nit can be written in the following form: \\\\\n$v = c_1 u_1 + c_2 u_2 + \\ldots + c_k u_k$ \\\\\nSolvable by matrix method: \\\\\n$$ u_1 = ( u_{11}, u_{12}, u_{13}) \\\\\n\\begin{bmatrix}\n\tu_{11} & u_{21} & u_{31} & v_1 \\\\\n\tu_{12} & u_{22} & u_{32} & v_2 \\\\\n\tu_{13} & u_{23} & u_{33} & v_3 \\\\\n\\end{bmatrix} $$\n** Note that the matrix is built transposed from the way in\nwhich most matrices have been built in this course. \\\\\nOnce built, solve for row-echelon form. If the bottom row is\n0s then the remainder has infinitely many solutions with a form\nof $c_it + \\ldots$ from the rest of the matrix solution.\n\n\\subsection{Spanning Sets}\n\nA set spans $R^2$ if its coefficient matrix has a non-zero determinant. \\\\\nSame is true of $R^3$.\n\n\\subsection{Linear Dependence and Independence}\n\nFor a set $S = {v_1, v_2, \\ldots, v_n}$ \\\\\nwhere there exists a non-trivial solution to: \\\\\n$ c_1v_1 + c_2v_2 + \\ldots + c_nv_n = 0 $ \\\\\n(The trivial solution is for $c_{1 \\cdots n}=0$ )\\\\\nIs Linearly Dependant. \\\\\nIf only the trivial solution exists it is linearly-independent. \\\\\n\\textbf{Testing for Dependence} \\\\\nIf the coefficient matrix can reduced to identity matrix: \\\\\n$$\\begin{bmatrix}\n\tu_{11} & u_{21} & u_{31} & v_1 \\\\\n\tu_{12} & u_{22} & u_{32} & v_2 \\\\\n\tu_{13} & u_{23} & u_{33} & v_3 \\\\\n\\end{bmatrix} \n\\rightarrow\n\\begin{bmatrix}\n\t1 & 0 & 0 & 0 \\\\\n\t0 & 1 & 0 & 0 \\\\\n\t0 & 0 & 1 & 0 \\\\\n\\end{bmatrix}$$ \\\\\nThere will only be the trivial solution. \\\\\nIf the Gaussian reduction yields a all zero row there are infinitely many solutions, therefor a non-trivial solution, and the set is linearly-dependent.\n\n\\subsection{Basis for Vector Space}\nThe standard basis for $R^n \\text{is } M_{n,n} $ in the identity matrix form.\nThe standard basis for $P_n \\text{is } S={1,x,x^2,\\ldots,x^n} $.\n\n\\textbf{Testing for Alternative Bases} \\\\\nAnd alternative basis will be Linearly-Independent\nand will be a spanning set. \\\\\n\n\\section{Inner Product Spaces}\n\n\\subsection{Length and Dot Product}\nVector Length is the result of a Pythagorean-like series. \\\\\n$\\left\\|V_n\\right\\| =\\sqrt{v_1^2 + v_2^2 + v_3^2 \\cdots v_n^2}$ \\\\\n\nInner Product: \\\\\n$\\left\\langle X,Y\\right\\rangle = x_1y_1 + x_2y_2 + \\cdots x_ny_n$ \\\\\n\nUnit Vectors have the same direction as the source vector but a length of 1. \\\\\n$ u = \\frac{v}{\\left\\|v\\right\\| } $ \\\\\nShown by: \\\\\n\\begin{align*}\t\n\t\\left\\| u\\right\\| &= \\left\\|\\frac{v}{\\left\\|v\\right\\|}\\right\\|  \\\\\n\t\t&= \\frac{1}{\\left\\|v\\right\\|}\\left\\|v\\right\\| \\\\\n\t\t&= 1 \\\\\n\t\\text{*Note that: } \\\\\n\t\\left\\|cv\\right\\| &= |c|\\left\\|v\\right\\|  \\\\\n\\end{align*} \\\\\n\nThe distance between two vectors in $R^n$ space is:\n$ d(u,v) = \n\\left\\| u-v \\right\\| = \n\\sqrt{(u_1-v_1)^2 + (u_2-v_2)^2 \\cdots (u_n-v_n)^2} $\\\\\n\n\\subsection{Properties of Dot Products}\n\\begin{align*}\n\tu \\cdot v &= u_1v_1 + u_2v_2 + \\ldots + u_nv_n \\\\\n\tu \\cdot v &= v \\cdot u \\\\\n\tu \\cdot (v + w) &= u \\cdot v + u \\cdot w \\\\\n\tc(u \\cdot v) = (cu) &\\cdot v = u \\cdot (cv) \\\\\n\tv \\cdot v &= \\left\\|v\\right\\|^2 \\\\\n\tv \\cdot v \\geq 0 \\text{, and } v \\cdot v &= 0 \\text{ if and only if } v = 0\n\\end{align*}\n\n\\subsection{Cauchy-Schwarz Inequality}\nIf $u$ and $v$ are vectors in $R^n$, then \\\\\n$\\left|u \\cdot v\\right| \\leq \\left\\|u\\right\\| \\left\\|v\\right\\|$ \\\\\nwhere $\\left|u \\cdot v\\right|$ \ndenotes the \\emph{absolute value} of $u \\cdot v$.\n\\\\\n\n\\subsection{Angle Between Vectors}\nThe Cauchy-Schwarz inequality must be verified in order to use the following method to find the angle between two vectors. \\\\\n$ \\cos\\theta = \\frac{u \\cdot v}{\\left\\| u \\right\\| \\left\\| v \\right\\|} $,\n$ 0 < \\theta < \\pi$\\\\\n\n\\includegraphics[width=\\linewidth]{AngleRef}\n\\includegraphics[width=0.5\\linewidth]{UnitCircle} \n%\\includegraphics[width=0.5\\linewidth]{TrigFuncRef} \n*Remember $(cos\\theta,sin\\theta)$ \\\\\n\n\\textbf{Orthogonal Unit Vectors:} \\\\\nIn $R^2$, $v = (v_1, v_2)$, the Orthogonal vector is: $(v_2, −v_1)$ \\\\\nTherefor the Orthogonal Unit vectors are:\n$ \\left\\langle \n\t\\frac{v_1}{\\left\\| v\\right\\| },\n  - \\frac{v_2}{\\left\\| v\\right\\| }\n  \\right\\rangle $ and\n$ \\left\\langle \n  - \\frac{v_1}{\\left\\| v\\right\\| },\n\t\\frac{v_2}{\\left\\| v\\right\\| }\n\\right\\rangle $\n\n\\subsection{Inner Products}\nAxioms of Inner Products:\n\\begin{align*}\n\t\\left\\langle u,v \\right\\rangle &= \n\t\\left\\langle v,u \\right\\rangle \\\\\n\t\\left\\langle u,v+w \\right\\rangle &= \n\t\\left\\langle u,v \\right\\rangle + \\left\\langle u,w \\right\\rangle \\\\\n\tc\\left\\langle u,v \\right\\rangle &= \n\t\\left\\langle cu,v \\right\\rangle \\\\\n\t\\left\\langle v,v \\right\\rangle \\geq 0 \\text{, and }\n\t\\left\\langle v,v \\right\\rangle &= 0 \n\t\\text{ if and only if } v=0 \\\\\n\\end{align*}\n\n\\subsection{Definitions in Inner Product Space}\n\\begin{align*}\n\t\\text{\\textbf{Length} of $u$: } \\left\\| u\\right\\| &= \n\t\t\\sqrt{\\left\\langle u,u \\right\\rangle} \\\\\n\t\\text{\\textbf{Distance} between $u$ and $v$: } d(u,v) &=\n\t\t\\left\\| u-v \\right\\|  \\\\ &= \n\t\t\\sqrt{\\left\\langle u-v,u-v \\right\\rangle} \\\\\n\t\\text{\\textbf{Angle} between $u$ and $v$: } \\cos\\theta &= \n\t\t\\frac{\\left\\langle u,v \\right\\rangle}\n\t\t\t{\\left\\| u\\right\\| \\left\\| v\\right\\|} \\\\\n\t\\text{$u$ and $v$ are orthogonal when }\\left\\langle u,v\\right\\rangle &=0 \\\\\n\t\\text{Cauchy-Schwarz Inequality: } \n\t\t\\left| \\left\\langle u,v \\right\\rangle \\right| &\\leq\n\t\t\\left\\| u\\right\\| \\left\\| v\\right\\| \\\\\n\t\\text{Triangle inequality: } \\left\\| u + v\\right\\| &\\leq\n\t\t\\left\\| u\\right\\| + \\left\\| v\\right\\| \\\\\n\t\\text{Pythagorean Theorem: $u$ and }&\n\t\\text{$v$ are orthogonal if and only if} \\\\\n\t\t\\left\\| u + v\\right\\|^2 &= \\left\\| u\\right\\|^2 \\left\\| v\\right\\|^2 \\\\\n\\end{align*}\n\n\\subsubsection{Orthogonal Projection}\nLet $u$ and $v$ be vectors in an inner product space $V$, such that $v \\neq 0$.\nThen the orthogonal projection of $u$ onto $v$ is \\\\\n$\\text{proj}_vu = \\frac\n\t{\\left\\langle u,v \\right\\rangle}\n\t{\\left\\langle v,v \\right\\rangle}\nv $\n\n\\subsection{Gram-Schmitz Orthonormalization Process}\n\\begin{enumerate}\n\t\\item Let $B = \\left\\lbrace  v_1,v_2, \\ldots, v_n\\right\\rbrace $ \n\t\tbe a basis for product space $V$.\n\t\\item Let $B' = \\left\\lbrace w_1,w_2, \\ldots, w_n\\right\\rbrace $, where \\\\\n\t\t$w_1 = v_1$ \\\\\n\t\t$w_2 = v_2 - \\frac{v_2 \\cdot w_1}{w_1 \\cdot w_1}w_1 $ \\\\\n\t\t$w_3 = v_3 - \\frac{v_3 \\cdot w_1}{w_1 \\cdot w_1}w_1 \n\t\t\t\t   - \\frac{v_3 \\cdot w_2}{w_2 \\cdot w_2}w_2 $ \\\\\n\t\t$w_n = v_n - \\frac{v_n \\cdot w_1}{w_1 \\cdot w_1}w_1 \n\t\t           - \\frac{v_n \\cdot w_2}{w_2 \\cdot w_2}w_2 - \\cdots\n\t\t           - \\frac{v_n \\cdot w_n}{w_n \\cdot w_n}w_n $ \\\\\n\t\t$B'$ is the \\emph{orthoganal basis} for $V$.\n\t\\item Let $u_i = \\frac{w_i}{\\left\\| w_i\\right\\| } $ and \\\\\n\t\t$B\" = \\left\\lbrace  u_1,u_2, \\ldots, u_n\\right\\rbrace $ \\\\\n\t\t$B\"$ is the \\emph{orthonormal basis} for $V$.\n\\end{enumerate}\n\n\\section{Eigenvectors and Eigenvalues}\n\\subsection{Definitions}\n$ Ax = \\lambda x $ \\\\\nWhere $A$ is an $n \\times n$ matrix, \\\\\n$\\lambda$ is the Eigenvalue, and \\\\\n$x$ is the non-zero Eigenvector.\n\n\\begin{align*}\n\t\\left| \\lambda I - A \\right| &= 0 \\\\\n\t( \\lambda I - A )x &= 0 \\\\\n\\end{align*}\n\nThe \\textbf{characteristic equation} is $\\left| \\lambda I - A = 0 \\right| $ solving this from polynomial form will give Eigenvalues. \n\n\\subsubsection{Examples}\n\\textbf{Eigenvalues:}\\\\\n$$ A =\n\t\\begin{bmatrix}\n\t\ta & b \\\\ c & d \\\\\n\t\\end{bmatrix} $$ \\\\\nThe characteristic polynomial is: \\\\\n$$ \\left| \\lambda I - A \\right| = \n\t\\begin{vmatrix}\n\t\t\\lambda -a & -b \\\\ -c & \\lambda -d \\\\\n\t\\end{vmatrix} =\n\t\\lambda^2 -a\\lambda -d\\lambda + (-b)(-c) =\n\t(\\lambda + i)(\\lambda + j) = 0 $$ \\\\\nThe result is that Matrix $A$ has the Eigenvalues $\\lambda_1 = -i$ \nand $\\lambda_2 = -j$. \\\\\n\\textbf{Eigenvectors:}\\\\\n$$ (\\lambda_1)I-A = \n\t\\begin{bmatrix}\n\t\t\\lambda_1 -a & -b \\\\ -c & \\lambda_1 -d \\\\\n\t\\end{bmatrix} $$\nReduce this matrix into Row-Echelon form, or as near as possible.\n$$ \t\\begin{bmatrix}\n\t\t\\lambda_1 -a & -b \\\\ -c & \\lambda_1 -d \\\\\n\t\\end{bmatrix}\n\t\t\\rightarrow\n\t\\begin{bmatrix}\n\t\ti & j \\\\ 0 & 0 \\\\\n\t\\end{bmatrix} $$\nEach row is set equal to zero and a variable will be assigned. \\\\\nIn this case $x_2 = t $ \\\\\n$$ x_1 - 4x_2 = 0 \\\\\n\tx = \n\t\\begin{bmatrix} x_1 \\\\ x_2 \\end{bmatrix} =\n\t\\begin{bmatrix} 4t \\\\ t \\end{bmatrix} =\n\tt\\begin{bmatrix} 4 \\\\ 1 \\end{bmatrix}, \n\tt \\neq 0 $$ \\\\\nThis must be done for each Eigenvalue.\n\n\\section{Linear Programming}\n\n\\subsection{Systems of Linear Equations}\n\\textbf{Linear Equation between two points:} \\\\\n$ (y_1-y_2)x + (x_2-x_1)y + x_1y_2-x_2y_1 = 0 $\n\n\\end{document}", "meta": {"hexsha": "bf388aa50ea97a270593e65e97f7cdab93e48903", "size": 20276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2020-Spr Linear Algebra/Notes.tex", "max_stars_repo_name": "bhosley/Schoolwork", "max_stars_repo_head_hexsha": "7c4eb909d2e6c65cd93b1c7fa744a183cebfc952", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2020-Spr Linear Algebra/Notes.tex", "max_issues_repo_name": "bhosley/Schoolwork", "max_issues_repo_head_hexsha": "7c4eb909d2e6c65cd93b1c7fa744a183cebfc952", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2020-Spr Linear Algebra/Notes.tex", "max_forks_repo_name": "bhosley/Schoolwork", "max_forks_repo_head_hexsha": "7c4eb909d2e6c65cd93b1c7fa744a183cebfc952", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2582972583, "max_line_length": 152, "alphanum_fraction": 0.5863582561, "num_tokens": 8365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317473, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6976580254115097}}
{"text": "\\documentclass[]{article}\n\\usepackage{amssymb,amsmath}\n\\begin{document}\n\\section{Complete Elliptic Integrals of First, Second, and Third\nKind}\n\\begin{eqnarray*}\n\\mathbf{G}(k',p,a,b) & = & \\displaystyle\n\\int_0^\\infty \\frac{a+b\\xi^2}{(1+p\\xi^2)\\sqrt{(1+\\xi^2)(1+{k'}^2\\xi^2)}}\n\\, d\\xi  \\\\[3mm]\n& = & \\displaystyle \\int_0^{\\pi/2} \\frac{a \\cos^2 \\phi + b \\sin^2 \\phi}\n{\\cos^2 \\phi + p \\sin^2 \\phi} \\frac{d\\phi}\n{\\sqrt{\\cos^2 \\phi + {k'}^2 \\sin^2 \\phi}} \\qquad ({k'}^2 > 0).\n\\end{eqnarray*}\nFor $p < 0$, this integral is defined by its principal value.\nSee {\\bf Notes} for special cases.\n\n{\\bf The functions K(k) and E(k):}\n\\begin{eqnarray*}\n\\mathrm{K}(k) & = & \\displaystyle \\int_0^{\\pi/2}\n\\frac{d\\psi}{\\sqrt{1-k^2\\sin^2 \\psi}} \\qquad (|k| < 1), \\\\\n\\mathrm{E}(k) & = & \\displaystyle \\int_0^{\\pi/2}\n\\sqrt{1-k^2\\sin^2 \\psi} \\, d\\psi \\qquad (|k| \\le 1).\n\\end{eqnarray*}\n\nOther common definitions of the complete elliptic integrals and their\nrelations to $\\mathbf{F}_1^*$, $\\mathbf{F}_2^*$, $\\mathbf{F}_3^*$ are\nlisted here for convenience ($k^2+{k'}^2 = 1$): \\\\[2mm]\n{\\bf First kind:}\n$$ \\begin{array}{rcl}\nF(k,\\pi/2) & = & \\mathrm{K}(k) \\quad = \\quad \\mathbf{F}_1^*(k') \\qquad\n(|k| < 1), \\\\[6mm]\n\\widehat{F}(1,k) & = & \\displaystyle \\int_0^1\n\\frac{d\\eta}{\\sqrt{(1-\\eta^2)(1-k^2\\eta^2)}} \\quad = \\quad\n\\mathbf{F}_1^*(k') \\qquad (|k| < 1).\n\\end{array} $$\n{\\bf Second kind:}\n$$ \\begin{array}{rcl}\nE(k,\\pi/2) & = & \\mathrm{E}(k) \\quad = \\quad \\mathbf{F}_2^*(k',1,{k'}^2)\n\\qquad (|k| \\le 1), \\\\[6mm]\n\\widehat{E}(1,k) & = & \\displaystyle \\int_0^1\n\\sqrt{\\frac{1-k^2 \\eta^2}{1-\\eta^2}} \\, d\\eta \\quad = \\quad\n\\mathbf{F}_2^*(k',1,{k'}^2) \\qquad (|k| \\le 1).\n\\end{array} $$\n{\\bf Third kind:}\n$$ \\begin{array}{rclcl}\n\\Pi(\\pi/2,h,k) & = & \\displaystyle \\int_0^{\\pi/2}\n\\frac{d\\psi}{(1+h\\sin^2 \\psi)\\sqrt{1-k^2\\sin^2 \\psi}} & = &\n\\mathbf{F}_3^*(k',h+1) \\qquad (|k| < 1), \\\\[6mm]\n\\widehat{\\Pi}(1,h,k) & = & \\displaystyle \\int_0^1\n\\frac{d\\eta}{(1+h\\eta^2)\\sqrt{(1-\\eta^2)(1-k^2\\eta^2)}} & = &\n\\mathbf{F}_3^*(k',h+1) \\qquad (|k| < 1).\n\\end{array} $$\n\n{\\tt FUNCTION} subprograms \\\\\nUser Entry Names:\n\nThe redundant parameter {\\tt AK2} in {\\tt RELI3C} and {\\tt DELI3C}\npermits improved accuracy when $k^2$ is small, i.e. $k' \\approx 1$. In\nthis case, $\\mathtt{AK2} = k^2$ should be calculated using\nhigher-precision arithmetic and then truncated before calling the\nsubprogram.\nSpecial examples are\n$$\\begin{array}{rcl}\n\\mathrm{K}(k)                           & = & \\mathbf{G}(k',1,1,1), \\\\[1mm]\n\\mathrm{E}(k)                           & = & \\mathbf{G}(k',1,1,{k'}^2)\\\\[2mm]\n(\\mathrm{K}(k)-\\mathrm{E}(k))/k^2       & = & \\mathbf{G}(k',1,0,1), \\\\[3mm]\n(\\mathrm{K}(k)-{k'}^2\\mathrm{E}(k))/k^2 & = & \\mathbf{G}(k',1,1,0), \\\\[4mm]\n\\Pi(h,k)                                & = & \\mathbf{G}(k',h+1,1,1),\\\\[5mm]\n(\\mathrm{K}(k)-\\Pi(h,k))/h              & = & \\mathbf{G}(k',h+1,0,1),\n\\end{array} $$\nIf $ab \\ge 0$ then $\\mathbf{G}$ will evaluate any linear\ncombination of K$(k)$, E$(k)$, $\\Pi(h,k)$ without cancellation\n(such as would occur, for example, if (K$(k)-$E$(k))/k^2$ were to be\ncomputed from values of K$(k)$ and E$(k)$ which had been computed\nseparately.\n\nOther functions which can be represented by $\\mathbf{G}$ are the Jacobian\nZeta function $\\mathbf{Z}(\\Phi,k)$ and the Heuman Lambda function\n$\\Lambda_0(\\Phi,k)$ (see Ref. 5):\n$$\\begin{array}{rcl@{\\qquad}l}\n\\mathbf{Z}(\\Phi,k) & = & \\displaystyle k^2 \\,\n\\frac{\\sin \\Phi \\cos \\Phi}{\\mathrm{K}(k)} \\, \\mathbf{G}(k',q,0,\\sqrt{q})\n& (q = \\cos^2 \\Phi + {k'}^2 \\sin^2 \\Phi) \\\\[4mm]\n\\Lambda_0(\\Phi,k) & = & \\displaystyle \\frac{2}{\\pi}\n\\sqrt{q} \\sin \\Phi \\ \\mathbf{G}(k',q,1,{k'}^2) &\n(q = 1 + k^2 \\tan^2 \\Phi).\n\\end{array} $$\n{\\it (Quoted from Ref. 3, slightly modified)}.\\\\\n\nThe subprograms for $\\mathbf{F}_1^*$, $\\mathbf{F}_2^*$ are based on the\nAlgol60 procedures {\\it cel1, cel2} in Ref. 1, those for\n$\\mathbf{F}_3^*$ on {\\it cel3} in Ref. 2, and those for $\\mathbf{G}$\non {\\it cel} in Ref. 3.\n\n\\begin{enumerate}\n\\item R. Bulirsch, Numerical calculation of elliptic integrals and\nelliptic functions, Numer. Math. {\\bf 7} (1965) 78--90.\n\\item R. Bulirsch, Numerical calculation of elliptic integrals and\nelliptic functions II, Numer. Math. {\\bf 7} (1965) 353--354.\n\\item R. Bulirsch, Numerical calculation of elliptic integrals and\nelliptic functions III, Numer. Math. {\\bf 13} (1969) 305--315.\n\\item W.J. Cody, Chebyshev approximations for the complete elliptic\nintegrals $K$ and $E$, Math. Comp. {\\bf 19} (1965) 105--112.\n\\item P.F. Byrd and M.D. Friedman, Handbook of elliptic integrals\nfor engineers and scientists, 2nd ed., Springer-Verlag Berlin (1971)\n33--37.\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "960c401b192af88fd071a04c70480e3e24b6ce01", "size": 4622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "shortwrups/a.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/a.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/a.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": 42.4036697248, "max_line_length": 78, "alphanum_fraction": 0.599307659, "num_tokens": 1934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6975859732278872}}
{"text": "\n\\subsection{Other}\n\n\\subsubsection{Production functions}\n\nA firm produces \\(Q\\) using inputs \\(X\\).\n\n\\(Q=f(X_1,...,X_n)\\)\n\n\\subsubsection{Marginal products}\n\nThis is the marginal utility, adapted for the production setting.\n\n\\(MP=\\dfrac{\\delta }{\\delta x_1}f(\\mathbf x)\\)\n\n\\subsubsection{Diminishing marginal returns}\n\nThis says that marginal returns decrease as the use of a factor increases.\n\n\\(\\dfrac{\\delta^2 }{{\\delta x_1}^2}f(\\mathbf x)<0\\)\n\n", "meta": {"hexsha": "eb95e894342ab589b0b55f704dd25945e0d04d58", "size": 449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/intermediate/05-03-other.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/intermediate/05-03-other.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/intermediate/05-03-other.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.4090909091, "max_line_length": 74, "alphanum_fraction": 0.714922049, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6975354186445122}}
{"text": "\\section{Decision Trees}\n\\begin{frame}\n   \\frametitle{Decision Trees}\n   Decision tree inducers provide an algorithm to solve classification and regression problems.\n   \\begin{itemize}\n      \\item  A binary decision tree $T$ splits the data: $s_T(x) = x_{i_T} \\leq t_{T}$ unless $T$ is a leaf\n      \\item If $T$ is a leaf, it predicts $T(x) = c_T$ for some constant $c_T$\n      \\item If $T$ is not a leaf, it creates two subtrees $T_{left}$ and $T_{right}$, and predicts:\n      \\[   \n      T(x) = \n            \\begin{cases}\n\n               T_{left}(x) &\\quad\\text{if}\\:  s_T(x) = \\text{TRUE} \\\\\n               T_{right}(x) &\\quad\\text{if}\\:  s_T(x) = \\text{FALSE} \\\\\n            \\end{cases}\n      \\]\n      \\item This defines the capacity of the model\n   \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n   \\frametitle{Decision Trees - Example}\n   \\begin{center}\n      \\includegraphics[height=150px]{img/true_vs_learned_regulartree.png}\n   \\end{center}\n   \\textit{Left:} Training data of an artificial classification problem. \n   \\textit{Right:} Learned function of a decision tree\n\\end{frame}\n\n\n\\begin{frame}\n   \\frametitle{Decision Trees - Learning}  \n   \\begin{itemize}\n   \\item Fitting a tree is an optimization problem\n   \\item Many exact solutions are NP hard: e.g. finding a minimal tree that fits the data\n   \\item Instead of exact solutions: greedy algorithms (bottom up vs top down)\n   \\item Different loss functions have been proposed: \\newline\n   InformationGain, Gini Index,  Likelihood-Ratio Chi–Squared Statistics, DKM Criterion, Gain Ratio, ...- see \\cite{rokach_decision_2005}\n   \\item This project evaluates the Information Bottleneck as loss function \n   \\end{itemize}\n\\end{frame}\n\n\n\n\\begin{frame}[fragile]\n   \\frametitle{Decision Trees - Top Down}  \n   \\begin{lstlisting}[language=Python, basicstyle=\\small]\nclass DecisionTree():\n  def fit(self, X, Y):\n    best_loss = infinity\n    for d in range(X.shape[1]): # O(D) \n      loss, thresh, left_split, right_split = \\\n        best_split(X[:,d], Y) # O(N)\n      if loss_d < best_loss:\n        update best_loss, X_l, Y_l, X_r, Y_r, t_T, i_T\n    if stopping_criterion is fulfilled:\n      self.c_T = best_constant_estimator(Y)\n      return self\n    self.left = DecisionTree().fit(X_l, Y_l)\n    self.right = DecisionTree().fit(X_r, Y_r)\n    self.prune()\n    return self\n\\end{lstlisting}\n\nImportant property of the loss: $J(Y, T(X)) = \\frac{|Y_{left}|}{|Y|}J(Y_{left}, T(X_{left})) + \\frac{|Y_{right}|}{|Y|}J(Y_{right}, T(X_{right}))$\n\\end{frame}\n", "meta": {"hexsha": "3a61ae0493c9a1aa7fd8b4d716a319be24a04d16", "size": 2501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/02_decision_trees.tex", "max_stars_repo_name": "nielsrolf/InformationBottleneckTree", "max_stars_repo_head_hexsha": "c92d66b7865b06817e59b122adace12e0d131667", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-29T06:49:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-14T06:35:21.000Z", "max_issues_repo_path": "slides/02_decision_trees.tex", "max_issues_repo_name": "nielsrolf/InformationBottleneckTree", "max_issues_repo_head_hexsha": "c92d66b7865b06817e59b122adace12e0d131667", "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/02_decision_trees.tex", "max_forks_repo_name": "nielsrolf/InformationBottleneckTree", "max_forks_repo_head_hexsha": "c92d66b7865b06817e59b122adace12e0d131667", "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.7794117647, "max_line_length": 145, "alphanum_fraction": 0.6569372251, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6974473305741005}}
{"text": "\\subsection{Numerical Experiments}\nNow that we've finally slogged through the presentation of the theory, we can\nproduce a few numerical experiments. Take, for example, the linear least squares\nregression problem with $A \\in \\mathbb{R}^{n \\times m}, x \\in \\mathbb{R}^m$ and\n$b \\in \\mathbb{R}^n$:\n\\[\n  f(x) = \\frac{1}{2}\\norm{Ax-b}_2^2 \n  = \\sum_{k=1}^n \n  \\underbrace{ \\frac{1}{2} (A_ix - b_i)^2 }_{f_i(x)}\n\\]\nThis is a particularily interesting example, as when we examing the stochastic\ndescent direction of this loss function:\n\\[\n  \\nabla f_i(x) = A_{i*}^T(A_{i*}x - b_i), \n  \\text{ where }\n  A = \n  \\begin{bmatrix}\n    A_{1*} \\\\\n    \\vdots \\\\\n    A_{n*}\n  \\end{bmatrix}\n\\]\nwe notice that the sparsity pattern of $\\nabla f_i(x)$ is entirely controlled by\nby the sparsity pattern of the rows of $A$. This makes this problem\nparticularily convinient when trying to understand the effect of sparsity on the\nasynchronous noise generated by \\hogwild. The original paper \\cite{2011NRRW}'s\nresults required strict assumptions on the sparsity pattern of $\\nabla f_i(x)$\nin order to guarantee convergence, but as we saw in Theorem\n\\ref{thm:convexconv}, as long as certain regularity properties are satisfied,\nthere's no need for such an assumption. Indeed $f$ does satisfy the above,\nassuming that $A$ is of full rank%\n\\footnote{\n  One subtle note is that the second condition is actually equivalent to having\n  upper bounded maximal eigenvalue. I think we proved this back when we were\n  discussing Nesterov's method, and also can be found at this stackexchange\n  \\url{https://math.stackexchange.com/a/1699082/245618}.\n}. Therefore, when $A$ is both sparse and dense, we should see\na $\\mathcal{O}(1/k)$ convergence rate, and indeed see Figure\n\\ref{fig:convergence} for the validation of that.\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=.8\\textwidth]{./resources/convergence}\n  \\caption{\n    The matrix Sparse$(d = 0.1)$ is generated by the command {\\tt\n    sprand(n,m,.01)}. Playing with the density parameter doesn't change the\n    shape of the convergence line, but note that denser matrices (since the\n    entries are Gaussian) produce a higher initial loss and suffer from more\n    asynchronous noise, and therefore require more iterations.\n  } \\label{fig:convergence}\n\\end{figure}\n\n\\subsubsection{Asynchronous Noise as a Function of Bandedness}\nSo now that we've seen that, indeed, dense updates enjoy the same convergence\nproperties as sparser ones, we can also investigate the relationship of\nasynchronous noise as a function of sparsity. Since the sampling of the next\ndata point to be used in a stochastic iterate is done uniformly and\nindependently, we note that in the interest of minimizing asynchronous noise,\nthe exact pattern matters less than the number of non-zero elements. Therefore,\nan interesting way to represent different sparsity patterns in our linear\nregression, is in choosing $A$ banded, and then varying the size of that band.\n\\begin{definition}\n  Let $k \\geq 1$ and $A \\in \\mathbb{R}^{n \\times n}$. We denote $A$ as\n  a $(k-1)$-banded matrix if $k$ is the maximal integer greater than zero such\n  that either the $k$th or the $-k$th diagonal are not-identically zero.\n\\end{definition}\nNow consider the operation of \\hogwild\\ with two simultaneous threads on the\nloss function defined above, with $A$ $k$-banded. Then an lower-bound to the\nprobability that these two threads do not share an component of $x_i$, which\nthey need to read/write from/to, is (assuming sampling with replacement) the\nprobability of picking $i_1, i_2$ uniformly from $[|k+1, \\dots, n-k|]$ such that\n$[|i_1-k, i_1+k|] \\cap [|i_2-k, i_2+k|] = \\varnothing$. Via a simple counting\nargument, we find that this is:\n\\[\n  \\Prob{[|i_1-k, i_1+k|] \\cap [|i_2-k, i_2+k|] = \\varnothing}\n  =\n  \\frac{\\left((n-2k)-(2k+1)\\right)_+}{n-2k}\n  =\n  \\frac{\\left(n-4k-1\\right)_+}{n-2k}\n\\]\nwhere $(\\cdot)_+ = \\max(0, \\cdot)$. This lower-bound gives us an upperbound on\nthe probability that they do share a necessary component, one minus the above.\nThis confirms something we already know, that if $k << n$, then the two threads\nare very unlikely to have asynchronous noise. However, with even just $k = n/4$,\nthen the above probability is zero, and this is just for $P = 2$. I had wanted\nto calculate the $k$ taking the above to zero as a function of $P$, but the\nanalysis quickly becomes intractible for $P \\geq 3$, barring a nice counting\nargument I don't see. Regardless, as long as we can measure asynchronous noise,\nwe can get an idea of how it increases as a function of $k$.\n\nTo construct an experiment to see this, let $x_k$ ($k$ not a component, but an\nparameter) be the final iterate of \\hogwild, as applied to the linear regression\nproblem with $A$ $k$-banded. Then supposing we hold some solution $x^*$ constant\namong all $k$, then we can view $f(x_k)$ as a random-variable, whose variance\ncharacterizes the amount of asynchronous noise experienced throughout\ncomputation, as the sequential algorithm (assuming the random choice of\nstochastic data points is seeded between intervals) will have $\\Var{f(x_k)} = 0,\n\\forall k$. See Figure \\ref{fig:variances} for the results of such an\nexperiment.\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=.8\\textwidth]{./resources/banded_asyncnoise}\n  \\caption{\n  } \\label{fig:variances}\n\\end{figure}\n", "meta": {"hexsha": "313563b116bdc64adc54b300f99adb273f06989c", "size": 5354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TeXsrc/src/convergence/numerical.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/numerical.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/numerical.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": 50.9904761905, "max_line_length": 80, "alphanum_fraction": 0.7392603661, "num_tokens": 1520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.6974473298659837}}
{"text": "\\section{Spline Fitting Method}\n\\label{Spline_1}\n\nIn this paper there are 2 methods of fusing IMU data and Monocular camera. First of which is spline fitting using scale factor with the data of IMU and Monocular camera depending on the reliability of the data from both sources to estimate distance. So here we did simulation of whole system with arbitrary value of data considering linear moment of robot with noisy data. Matlab simulations can be seen in the result section. Initially, theory behind curve fitting is explained to have an algebraic background of the types of curve fitting and their applications. We use spline in curve fitting because we get discrete data from sensors and camera but tracing spline helps for interpolation and extrapolation to have continuous high probability data of path.\n\nSpline is fitted on the data points which is output of sensor in our case. Spline fitting also helps in reducing error due to noise. For improving accuracy we can increase number of spline but this will also result in an increase in computation. So we have to trade off between accuracy and computation.\nSpline fitting is useful to give smooth curve. N degree spline may have N-1 curves in its shape. So if spline has $X^3$ term that means it can have 2 curves in its spline. Ideal method to cover n points in a plain is by tracing $n^{th}$ order spline which will result into zero error. So spline will pass through all the points and will have a general equation as\n\n\\begin{equation}\n\\ A_{0} +A_{1}X +A_{2}X^{2}+A_{3}X^{3} + ... + A_{n}X^{n} = Y\n\\end{equation} \n\nThis problem then converts in simple Ax = B form. we can get values of n terms by plugging in n points values.\n\nWhere\n\n\\begin{equation}\nA = \n\\begin{pmatrix}\n  1 & X_{1} & X_{1}^{2} & \\cdots & X_{1}^{n} \\\\\n  1 & X_{2} & X_{2}^{2} & \\cdots & X_{2}^{n} \\\\\n  1 & X_{3} & X_{3}^{2} & \\cdots & X_{3}^{n} \\\\\n  : & :     &     :     & \\cdots &    :      \\\\\n  1 & X_{n} & X_{n}^{2} & \\cdots & X_{n}^{n} \\\\\n \\end{pmatrix}\nB = \n\\begin{pmatrix}\n  A_{0} \\\\\n  A_{1} \\\\\n  A_{2} \\\\\n  : \t\\\\\n  A_{n} \\\\\n \\end{pmatrix}\n C = \n\\begin{pmatrix}\n  Y_{0} \\\\\n  Y_{1} \\\\\n  Y_{2} \\\\\n  : \t\\\\\n  Y_{n} \\\\\n \\end{pmatrix}\n\\end{equation}\n\nBut for practical applications we use other methods and do not plot n degree spline as it is computationally expensive .Secondly if there is more noise in system it will give wrong results. \nFor practical application there are 3 kinds of spline fitting according to the application:-\n\n\\subsection{Types of curve fitting}\n\\subsubsection{Maximum error}\nThis is the method where spline is fit in a way where the point with maximum error is reduced and curve moves towards the outlier point. If there exist in order to reduce maximum error of a point. This on the other hand results into\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth]{./figures/Maxerror.PNG}\n\\caption{Curve Fitting with Maximum error }\n\\end{figure}\n\n\\begin{equation}\nE(f)=|max (f(xi)-yi)|  where\\ i\\ goes\\ from\\ 1\\ to\\ n\n\\end{equation}\n\nDue to one outlier here, the line is shifted in order to reduce maximum error. Although not a reliable process, it is easy to compute.\n\n\\subsubsection{Average error}\nThis method is used to minimize average and fit the spline with minimum error conditions.\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth]{./figures/average.PNG}\n\\caption{Curve Fitting with Average error }\n\\end{figure}\n\n\\begin{equation}\nE(f)=\\frac{1}{n}*\\Sigma|f(x_k)-Y_k| \n\\end{equation}\n\nActually due to one outlier here line shifted in order to reduce maximum error. So this is not reliable process but is easy to compute.\n\n\\subsubsection{RMS (Least square method)}\nThis is the most efficient method to minimize the error called as least square method.\nHence this is mostly used in curve fitting.\nWe have also created an algorithm with the help of same type of curve fitting.\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth]{./figures/RMS.PNG}\n\\caption{Curve Fitting with RMS error }\n\\end{figure}\n\n\\begin{equation}\nE(f)={\\lbrace\\frac{1}{n}*\\Sigma|f(x_k)-Y_k|\\rbrace}^\\frac{1}{2} \n\\end{equation}\n\n\\subsection{IMU Reading}\nAs we don’t have real IMU data we simulate virtual readings for this. We take X, Y, Z as a function on time \n\n\\begin{equation}\n\\label{For_x}\nX_1=A_x t^2+B_x t +C_x\n\\end{equation}\n\n\\begin{equation}\nY_1=A_y t^2+B_y t +C_y\n\\end{equation}\n\n\\begin{equation}\nZ_1=A_z t^2+B_z t +C_z\n\\end{equation}\n\nWith this treatment we will add some random noise to all the terms so that the data can be similar to what we obtain from a real IMU.\n\n\\begin{equation}\nnoise=A*(rand(1,n)-0.5)\n\\end{equation}\n\nSo our noise will range from -A/2 to A/2.\nAs function is rand() so it will change for every point.\n\n\\begin{equation}\nX=X_1+noise\n\\end{equation}\n\n\\begin{equation}\nY=Y_1+noise\n\\end{equation}\n\n\\begin{equation}\nZ=Z_1+noise\n\\end{equation}\nWe also took some random points of camera pose. And provided our system with data set.\\\\\n\nProof of Least square method in our case:\nLet’s consider optimization of X first. From equation \\eqref{For_x} we have\n\nHere $A$, $B$, $C$ are known\nWe have data set of X with respect to t.\nTo calculate error in RMS we have\n \n\\begin{equation} \n Error_x={\\lbrace\\displaystyle\\sum_{i=1}^{n}(|X_i-(A_xt_i^2+B_x t_i +C_x)|)^2\\rbrace}^\\frac{1}{2} \n\\end{equation}\n\n\nWhen we differentiate some quantity and equate it to zero it goes to either minima or maxima\nAnd if double derivative is positive it goes to minima.\n\nSo in this case if we take partial derivatives of error with respect to Ax , Bx , Cx\n\n\\begin{equation} \n \\frac{\\partial Error_x}{\\partial A_x} = {\\lbrace\\displaystyle\\sum_{i=1}^{n}2(|X_i-(A_xt_i^2+B_x t_i +C_x)|)\\rbrace}({-t_i^2})\n\\end{equation}\n\n\\begin{equation} \n\\displaystyle\\sum_{i=1}^{n}(|{-t_i^2}X_i+(A_x t_i^4+B_x t_i^3+C_x t_i^2)|) = 0\n\\end{equation}\n\n\\begin{equation} \n \\frac{\\partial Error_x}{\\partial B_x} = {\\lbrace\\displaystyle\\sum_{i=1}^{n}2(|X_i-(A_xt_i^2+B_x t_i +C_x)|)\\rbrace}({-t_i})\n\\end{equation}\n\n\\begin{equation} \n\\displaystyle\\sum_{i=1}^{n}(|{-t_i}X_i+(A_x t_i^3+B_x t_i^2+C_x t_i^1)|) = 0\n\\end{equation}\n\n\\begin{equation} \n \\frac{\\partial Error_x}{\\partial C_x} = {\\lbrace\\displaystyle\\sum_{i=1}^{n}2(|X_i-(A_xt_i^2+B_x t_i +C_x)|)\\rbrace}({-1})\n\\end{equation}\n\n\\begin{equation} \n\\displaystyle\\sum_{i=1}^{n}(|-X_i+(A_x t_i^2+B_x t_i+C_x)|) = 0\n\\end{equation}\n\nSo we can compute matrix in such a way that the problem changes to \n\n$Ax=B$\n\nWhere, \n\n\\begin{equation}\nA = \n\\begin{pmatrix}\n  \\Sigma t^4 & \\Sigma t^3 & \\Sigma t^2\\\\\n  \\Sigma t^3 & \\Sigma t^2 & \\Sigma t\\\\\n  \\Sigma t^2 & \\Sigma t & \\Sigma 1\\\\\n \\end{pmatrix}\nB = \n\\begin{pmatrix}\n  A_x \\\\\n  B_x \\\\\n  C_x \\\\\n \\end{pmatrix}\n C = \n\\begin{pmatrix}\n  \\Sigma X_i t ^2 \\\\\n  \\Sigma X_i t \\\\\n  \\Sigma X_i \\\\\n \\end{pmatrix}\n\\end{equation}\n\nFrom this equation we can calculate X matrix.Similarly,We can get X matrix of Y and Z axis.\n\n\\begin{equation}\nA = \n\\begin{pmatrix}\n  \\Sigma t^4 & \\Sigma t^3 & \\Sigma t^2\\\\\n  \\Sigma t^3 & \\Sigma t^2 & \\Sigma t\\\\\n  \\Sigma t^2 & \\Sigma t & \\Sigma 1\\\\\n \\end{pmatrix}\nB = \n\\begin{pmatrix}\n  A_y \\\\\n  B_y \\\\\n  C_y \\\\\n \\end{pmatrix}\n C = \n\\begin{pmatrix}\n  \\Sigma Y_i t ^2 \\\\\n  \\Sigma Y_i t \\\\\n  \\Sigma Y_i \\\\\n \\end{pmatrix}\n\\end{equation}\n\n\\begin{equation}\nA = \n\\begin{pmatrix}\n  \\Sigma t^4 & \\Sigma t^3 & \\Sigma t^2\\\\\n  \\Sigma t^3 & \\Sigma t^2 & \\Sigma t\\\\\n  \\Sigma t^2 & \\Sigma t & \\Sigma 1\\\\\n \\end{pmatrix}\nB = \n\\begin{pmatrix}\n  A_z \\\\\n  B_z \\\\\n  C_z \\\\\n \\end{pmatrix}\n C = \n\\begin{pmatrix}\n  \\Sigma Z_i t ^2 \\\\\n  \\Sigma Z_i t \\\\\n  \\Sigma Z_i \\\\\n \\end{pmatrix}\n\\end{equation}\n\nBy this treatment we converted given points into equation with least square method here we used condition of \n\n\\begin{equation}\nmin\n\\begin{pmatrix}\n  A_x t^2 + B_x t + C_x -\\lambda_i X_c \\\\\n  A_y t^2 + B_y t + C_y -\\lambda_i Y_c \\\\\n  A_z t^2 + B_z t + C_z -\\lambda_i Z_c \\\\\n \\end{pmatrix}^2\n \\end{equation}\n \n Here in this formula we have different value for different spline according to accuracy of camera data and IMU reading.\n\n\\subsection{Results}\n \n In our case we simulated the results and found following outputs.\nPlotting the second order curve for given data of IMU with just least square method. We get the following graph~\\ref{imures1}.\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth,height=7cm,keepaspectratio]{./figures/lsm.jpg}\n\\caption{In this case Blue is actual curve traced by IMU this are points with noise.And green is plotted curve. With least square method.}\n\\label{imures1}\n\\end{figure}\n\nThen according to the paper we fused data of camera and IMU so we get following graph~\\ref{fig:multipleSpline}.\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth,height=7cm,keepaspectratio]{./figures/AllOutput.jpg}\n\\caption{Multiple spline fit}\n\\label{fig:multipleSpline}\n\\end{figure}\n\nIn Figure~\\ref{fig:multipleSpline} we have 3 curves fitted as shown as red which gives better results and it also uses data of camera shown with black dots. So here according to the above formula scale factor of different section is different it is according to the quality of reading by camera.\nFor example, in our case \n\\begin{equation}\n\\lambda_1=0.5 ,\\lambda_2=0.5 ,\\lambda_3=0.1\n\\end{equation}\n\nIn 3rd section camera readings were not accurate so taken into smaller scalar value. This camera data further improved the result. And we get minimum error and good fit. With the given spline fitting method.\n\nSo if we look into different error methods with traditional Least square method with Jung and Taylor method, it gives us good results with output similar to the research paper.\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth,height=7cm,keepaspectratio]{./figures/ErrorC.jpg}\n\\caption{\\textbf{a}. Red curve for method with one curve and least square method. \n\\textbf{b}. Green curve is using the given method by Jung and Taylor.}\n\\label{fig:errorc1}\n\\end{figure}\n\nThe graph in Figure 12 has error comparison with and without Jung and Taylor method of split curve fitting and scaling camera input.\nSo it is better to follow the given first method in the paper. It results into considerable reduction in error which is clearly seen in graph.\n\nWith the same approach we can optimize and plot spline in 3 dimension so when we use this algorithm for 3D space we get the following result where we get an second order optimized curve. We also included considerable noise and tested our algorithm.\n  \n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth,height=7cm,keepaspectratio]{./figures/3DCurve.jpg}\n\\caption{Actual 3D path with noise vs Optimized spline fit}\n\\label{fig:errorc1}\n\\end{figure}", "meta": {"hexsha": "a4678cf792a939309e7c10438f61d958964f965a", "size": 10516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/text/Spline_fitting.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/Spline_fitting.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/Spline_fitting.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": 35.288590604, "max_line_length": 759, "alphanum_fraction": 0.7222327881, "num_tokens": 3207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6974473150097285}}
{"text": "\\chapter{Discussion}\n\n\\section{Complexity and optimality}\n\\label{sec:disc:complexity}\n\nGeneric join guarantees worst-case optimality with respect to the output size.\nOur relational \\ematching preserves this optimality. In particular, we have the following theorem:\n\\newtheorem{theorem}{Theorem}\n\\begin{theorem}\nRelational \\ematching is worst-case optimal; that is, fix a pattern $p$, let $M(p,E)$ be the set of substitutions yielded by \\ematching on an \\egraph $E$ with $n$ nodes, relational \\ematching runs in time $\\tilde O(\\max_E(|M(p,E)|))$.\n\\end{theorem}\n\\begin{proof}\n\nNotice that there is an one-to-one correspondence between an output atoms of the generated conjunctive query and the \\ematching. Therefore, the worst-case bound is the same across an \\ematching pattern and the conjunctive query it generated. Because generic join is worst-case optimal, relational \\ematching also runs in worst-case optimal time with respect to the output size.\n\\end{proof}\n\n\n\\section{Other join algorithms}\n\nAlthough we choose generic join algorithm in relational \\ematching, there are also other choices in the design space. For example, traditional two-way join plans are efficient on acyclic queries, and extensive research has been done on synthesizing highly efficient query plans. Moreover, Yannakakis' algorithm \\citep{yannakakis} is an optimal algorithm on ayclic queries, running in time equal to the size of the output (with possible log factors). However, both of the queries suffer on cyclic conjunctive queries. Two-way join plans spend time enumerating unsatisfying terms, while Yannakakis' algorithm are not applicable to cyclic conjunctive queries. It is possible to choose different join algorithms based on the cyclicity of the query to take advantages each algorithms. However, we currently does not implement this.\n\n\\section{Comparison to graph pattern matching}\n\nThe idea of representing graph data structure as relational databases are not new. For example, many Datalog programs represent nodes and edges as their own relations to use relational joins to support efficient queries on graph database, known as graph pattern matching. Compared to the common encoding of graphs, our relational representation of \\egraphs in a relational database is slightly different and specialized for \\egraphs. It is a future work to absorb researches on graph pattern matching for relational \\ematching.\n\n", "meta": {"hexsha": "05bf3842040eb7361cb0c76005ec85d3ac952774", "size": 2405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/5-discussions.tex", "max_stars_repo_name": "yihozhang/UWThesis", "max_stars_repo_head_hexsha": "286aa777bd528b8da3ec86b717dc1f7f39d89816", "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/5-discussions.tex", "max_issues_repo_name": "yihozhang/UWThesis", "max_issues_repo_head_hexsha": "286aa777bd528b8da3ec86b717dc1f7f39d89816", "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/5-discussions.tex", "max_forks_repo_name": "yihozhang/UWThesis", "max_forks_repo_head_hexsha": "286aa777bd528b8da3ec86b717dc1f7f39d89816", "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": 92.5, "max_line_length": 826, "alphanum_fraction": 0.8066528067, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6972565422362415}}
{"text": "% !TEX root = scombinatorics.tex\n\\documentclass[scombinatorics.tex]{subfiles}\n\\begin{document}\n\\chapter{Set systems}\n\\label{sperner}\n\n\n\n\\def\\medrel#1{\\parbox[t]{6ex}{$\\displaystyle\\hfil #1$}}\n\\def\\ceq#1#2#3{\\parbox[t]{40ex}{$\\displaystyle #1$}\\medrel{#2}{$\\displaystyle #3$}}\n\n\\def\\separatore{\\hfil o \\rule[0.5ex]{4ex}{0.1ex} o \\rule[0.5ex]{4ex}{0.1ex} o}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Sperner's Theorem}\\label{sperner}\n\nWe say that $\\phi(A\\,;b)_{b\\in\\V}$ is an \\emph{antichain\\/} if there is no pair of distinct elements $b,b'\\in\\V$ such that $\\phi(A\\,;b)\\subset\\phi(A\\,;b')$.\nAntichains are also called \\emph{Sperner systems.}\n\nIf all sets in $\\phi(A\\,;b)_{b\\in\\V}$ are distinct and of equal cardinality, then we clearly have an antichain.\nIf $|A|=n$, the cardinality of a collection of subsets of $A$, all of cardinality $k$, is maximal when $k=\\lfloor n/2\\rfloor$ or $k=\\lceil n/2\\rceil$.\nIn this case\\smallskip\n\n\\ceq{\\hfill\\big|\\phi(A\\,;b)_{b\\in\\V}\\big|}\n{=}\n{{n\\choose\\lfloor n/2\\rfloor}}\n\n\\ceq{}\n{=}\n{{n\\choose\\lceil n/2\\rceil}.}\\smallskip\n\nBy the following classical theorem, this bound holds for all antichain.\nThis is one of the first results of external combinatorics (though the term has been coined a few years later).\n\n\\def\\ceq#1#2#3{\\parbox[t]{36ex}{$\\displaystyle #1$}\\medrel{#2}{$\\displaystyle #3$}}\n\n\\begin{void_thm}[Sperner's Theorem]\n  Let $A\\subseteq\\U$ have cardinality $n$, finite.\n  If $\\phi(A\\,;b)_{b\\in\\V}$ is an antichain then\n  \n  \\ceq{\\hfill\\big|\\phi(A\\,;b)_{b\\in\\V}\\big|}\n  {\\le}\n  {{n\\choose\\lfloor n/2\\rfloor}.}\n\\end{void_thm}\n\\smallskip\n\\begin{proof}\n   Clearly, $\\phi(A\\,;b)_{b\\in\\V}$ is the disjoint union of the sets \\smash{$\\displaystyle{A\\choose k}\\cap\\phi(A\\,;b)_{b\\in\\V}$} for $k$ ranging over $\\{0,\\dots,n\\}$.\n   Then \n\n   \\ceq{\\hfill\\big|\\phi(A\\,;b)_{b\\in\\V}\\big|}{\\le}{\\sum^n_{k=0}\\bigg|{A\\choose k}\\cap\\phi(A\\,;b)_{b\\in\\V}\\bigg|.}\n\n   As for every $k\\le n$\n   \n   \\ceq{\\hfill{n\\choose k}}{\\le}{{n\\choose\\lfloor n/2\\rfloor},}\n\n   the theorem follows immediately from the LYM inequality that we prove below.\n\\end{proof}\n\nThe acronym LYM stands for Lubell-Yamamoto-Meshalkin.\n\n\\begin{lemma}[(LYM inequality)]\n   Let $A\\subseteq\\U$ have cardinality $n$, finite.\n   If $\\phi(A\\,;b)_{b\\in\\V}$ is an antichain then\n   \n   % \\ceq{\\hfill\\sum^n_{k=0}\\frac{\\big|\\phi(A\\,;b)_{b\\in\\V}\\ \\cap\\  A^{(k)}\\big|}{\\big|A^{(k)}\\big|}}{\\le}{1.}\n\n   \\ceq{\\hfill\\sum^n_{k=0}\\bigg|{A\\choose k}\\cap\\phi(A\\,;b)_{b\\in\\V}\\bigg|\\cdot{n\\choose k}^{\\kern-.8ex -1}\\kern-.8ex}{\\le}{1.}\n\\end{lemma}\n\\smallskip\n\\begin{proof}\n   Let $\\Pi$ be uniform random variable that ranges over the set of permutations of $A=\\{a_1,\\dots,a_n\\}$.\n   For any $\\phi(A\\,;b)$ of cardinality $k$\n   \n   \\ceq{\\hfill\\Pr\\bigg(\\Pi\\{a_1,\\dots,a_k\\}=\\phi(A\\,;b)\\bigg)\\kern-.8ex}{=}{ {n\\choose k}^{\\kern-.8ex -1}\\kern-1.5ex.}\n\n   The events above are disjoint for distinct sets $\\phi(A\\,;b)$, hence \n\n   \\ceq{\\hfill\\Pr\\bigg(\\Pi\\{a_1,\\dots,a_k\\}\\in\\phi(A\\,;b)_{b\\in\\V} \\bigg)\\kern-.8ex}{=}{\\bigg|{A\\choose k}\\cap\\phi(A\\,;b)_{b\\in\\V}\\bigg|\\cdot{n\\choose k}^{\\kern-.8ex -1}\\kern-1.5ex. }\n\n   As $\\phi(A\\,;b)_{b\\in\\V}$ is an antichain, for distinct $k$ the events above are disjoint, hence\n\n   \\ceq{\\hfill\\Pr\\bigg(\\bigcup^n_{k=0}\\Pi\\{a_1,\\dots,a_k\\}\\in\\phi(A\\,;b)_{b\\in\\V} \\bigg)\\kern-.8ex}{=}{\\sum^n_{k=0}\\bigg|{A\\choose k}\\cap\\phi(A\\,;b)_{b\\in\\V}\\bigg|\\cdot{n\\choose k}^{\\kern-.8ex-1}\\kern-1.5ex. }\n\n   Now, the inequality is evident.\n\\end{proof}\n\nLet $\\Pr_k$ be the probability measure on the subsets of $A$ that is concentrated and uniform on $A^{(k)}$.\nNamely, for $A'\\subseteq A$\n\n\\ceq{\\hfill{\\Pr}_k\\big(\\{A'\\}\\big)}\n{=}\n{\\left\\{\n\\begin{array}{ll}\n   \\kern1.5ex0&\\textrm{if}\\kern1.5ex |A'|\\neq k\\\\\n   \\displaystyle{n\\choose k}^{\\kern-.8ex-1} &\\textrm{if}\\kern1.5ex |A'|= k\\\\\n\\end{array}\\right.}\n\nThen the the LYM inequality asserts that if $\\phi(A\\,;b)_{b\\in\\V}$ is an antichain then\n\n\n\\ceq{\\hfill\\sum^n_{k=0}{\\Pr}_k\\big(\\phi(A\\,;b)_{b\\in\\V}\\big)}{\\le}{1.}\n\nThis inequality is strict when $\\phi(A\\,;b)_{b\\in\\V}=A^{(k)}$ for some $k$. \nIn the next section we show that these are the only cases.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The Erd\\H{o}s-Ko-Rado Theorem}\\label{ErdosKoRado}\n\n\\def\\medrel#1{\\parbox[t]{4ex}{$\\displaystyle\\hfil #1$}}\n\\def\\ceq#1#2#3{\\parbox[t]{20ex}{$\\displaystyle #1$}\\medrel{#2}{$\\displaystyle #3$}}\n\n\\begin{lemma}[(Peter J.~Cameron)]\n   Let $G$ be a $1$-transitive finite graph.\n   If $G$ contains a clique of cardinality $m$, then every subgraph $H\\subseteq G$ contains a clique of cardinality \n   \n   \\ceq{}{\\ge}{m\\frac{|H|}{|G|}.}\n\\end{lemma}\n\n\\begin{proof}\n   Let $C$ be a clique in $G$ of cardinality $m$.\n   Let $k$ the cardinality of the largest clique in $H$.\n   Let $n=|\\Aut(G)|$.\n   By $1$-transitivity, the sets $\\{f\\in\\Aut(G): fa=b\\}$, for any fixed $a\\in G$ and $b$ ranging over $G$, have all the same cardinality. \n   Hence, for any given pair $\\<a,b\\>$, they have cardinality $n/|G|$.\n\n   Count the pairs $\\<a,f\\>\\in C\\times\\Aut(G)$ such that $fa\\in H$.\n   For every $a\\in C$ there are $n\\cdot|H|$ automorphisms.\n   So the number of pairs is $m\\cdot n\\cdot|H|/|G|$\n\n   On the other hand for each $f\\in\\Aut(G)$ there are at most $k$ choices of $a\\in C$.\n   So $m\\cdot n\\cdot|H|/|G|\\le k\\,n$.\n\\end{proof}\n\n\n\n\\begin{void_thm}[Erd\\H{o}s-Ko-Rado Theorem]\n   Let $A\\subseteq\\U$ be a finite set of cardinality $n$. \n   Let $k\\le n/2$.\n   Let $\\phi(A\\,;b)_{b\\in\\V}$ be an intersecting family of sets of cardinality $k$.\n   Then \n   \n   \\ceq{\\hfill\\Big|\\phi(A\\,;b)_{b\\in\\V}\\Big|}{\\le}{{n-1\\choose k-1}.}\n\\end{void_thm}\n   \n\\begin{proof}\n   Let $m=\\Big|\\phi(A\\,;b)_{b\\in\\V}\\Big|$.\n   Consider the graph \n   \n   \\ceq{\\hfill G}{=}{{A\\choose k},}\n   \n   \\ceq{\\hfill E(G)}{=}{\\Big\\{\\{A',A''\\}\\ :\\  A'\\cap A''\\neq\\0\\Big\\}.}\n\n   Enumerate the elements of $A$, say $A=\\{a_0,\\dots,a_{n-1}\\}$.\n   Consider the following subgraph of $G$ \n   \n   \\ceq{\\hfill H}{=}{\\Big\\{\\{a_i,\\dots,a_{i+k-1}\\}\\ :\\  0\\le i<n\\Big\\},}\n\n   where the indices are intended modulo $n$.\n   As $k\\le n$, the largest clique in $H$ has cardinality $k$.\n   As $\\phi(A'\\,;b)_{b\\in\\V}$ is a clique of $G$, by the lemma above, \n\n   \\ceq{\\hfill k}{\\ge}{m\\frac{|H|}{|G|}}\\medrel{=}$\\displaystyle m\\cdot n\\cdot {n\\choose k}^{\\!-1}$\n   \n   therefore\n\n   \\ceq{\\hfill m}{\\le}{{n-1\\choose k-1}}\n\\end{proof}\n\\end{document}\n", "meta": {"hexsha": "b7a62c869d44a1c41eafcc7af8447f91f2354c65", "size": 6480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sperner.tex", "max_stars_repo_name": "LorenzoNot/scombinatorics", "max_stars_repo_head_hexsha": "64392c4f5793019b479376acb5eb248115335b93", "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": "sperner.tex", "max_issues_repo_name": "LorenzoNot/scombinatorics", "max_issues_repo_head_hexsha": "64392c4f5793019b479376acb5eb248115335b93", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sperner.tex", "max_forks_repo_name": "LorenzoNot/scombinatorics", "max_forks_repo_head_hexsha": "64392c4f5793019b479376acb5eb248115335b93", "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.0, "max_line_length": 209, "alphanum_fraction": 0.6016975309, "num_tokens": 2620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8577681122619885, "lm_q1q2_score": 0.69725167251813}}
{"text": "\\newpage\n\\section{Matrix Operations}\n\n\\begin{Operator}[cofactor]{COFACTOR}\n\\index{matrix}\nThe operator \\name{cofactor} returns the cofactor of the element in row\n\\meta{row} and column \\meta{column} of a \\nameref{matrix}.  Errors occur\nif \\meta{row} or \\meta{column} do not evaluate to integer expressions or if\nthe matrix is not square.\n\n\\begin{Syntax}\n\\name{cofactor}\\(\\meta{matrix\\_expression},\\meta{row},\\meta{column}\\)\n% COFACTOR(EXPRN:matrix_expression,ROW:integer,COLUMN:integer):algebraic\n\\end{Syntax}\n\n\\begin{Examples}\ncofactor(mat((a,b,c),(d,e,f),(p,q,r)),2,2); & A*R - C*P \\\\\ncofactor(mat((a,b,c),(d,e,f)),1,1); &  ***** non-square matrix\n\\end{Examples}\n\\end{Operator}\n\n\n\\begin{Operator}[det]{DET}\n\\index{matrix}\\index{determinant}\nThe \\name{det} operator returns the determinant of its \n(square \\nameref{matrix}) argument.\n\n\\begin{Syntax}\n\\name{det}\\(\\meta{expression}\\) or \\name{det} \\meta{expression}\n\\end{Syntax}\n\n\\meta{expression} must evaluate to a square matrix.\n\n\\begin{Examples}\n\nmatrix m,n; \\\\\n\nm := mat((a,b),(c,d));      &  \\begin{multilineoutput}{4cm}\nM(1,1) := A\nM(1,2) := B\nM(2,1) := C\nM(2,2) := D\n                               \\end{multilineoutput}\\\\\ndet m;                      &      A*D - B*C \\\\\nn := mat((1,2),(1,2));      &  \\begin{multilineoutput}{4cm}\nN(1,1) := 1\nN(1,2) := 2\nN(2,1) := 1\nN(2,2) := 2\n                               \\end{multilineoutput} \\\\\n\ndet(n);                     &      0 \\\\\n\ndet(5);                     &      5\n\\end{Examples}\n\n\\begin{Comments}\nGiven a numerical argument, \\name{det} returns the number.  However, given a\nvariable name that has not been declared of type matrix, or a non-square\nmatrix, \\name{det} returns an error message.\n\\end{Comments}\n\\end{Operator}\n\n\n\\begin{Operator}[mat]{MAT}\n\\index{matrix}\nThe \\name{mat} operator is used to represent a two-dimensional \n\\nameref{matrix}.\n\\begin{Syntax}\n\\name{mat}\\(\\(\\meta{expr}\\{,\\meta{expr}\\}\\optional\\)%\n            \\{\\(\\meta{expr}\\{\\name{,}\\meta{expr}\\}\\optional\\)\\}\\optional\\)\n\\end{Syntax}\n\n\n\\meta{expr} may be any valid REDUCE scalar expression.\n\n\\begin{Examples}\nmat((1,2),(3,4));            & \n\\begin{multilineoutput}{6cm}\nMAT(1,1) := 1\nMAT(2,3) := 2\nMAT(2,1) := 3\nMAT(2,2) := 4\n\\end{multilineoutput}\\\\\nmat(2,1);                    & \\begin{multilineoutput}{6cm}\n***** Matrix mismatch\nCont? (Y or N) \n\\end{multilineoutput}\\\\\nmatrix qt;  \\\\\nqt := ws;                    & \\begin{multilineoutput}{6cm}\nQT(1,1) := 1\nQT(1,2) := 2\nQT(2,1) := 3\nQT(2,2) := 4 \n\\end{multilineoutput}\\\\\nmatrix a,b; \\\\\na := mat((x),(y),(z));       & \\begin{multilineoutput}{6cm}\nA(1,1) := X\nA(2,1) := Y\nA(3,1) := Z \n\\end{multilineoutput}\\\\\nb := mat((sin x,cos x,1));   & \\begin{multilineoutput}{6cm}\nB(1,1) := SIN(X)\nB(1,2) := COS(X)\nB(1,3) := 1\n\\end{multilineoutput}\n\\end{Examples}\n\n\\begin{Comments}\nMatrices need not have a size declared (unlike arrays).  \\name{mat}\nredimensions a matrix variable as needed.  It is necessary, of course,\nthat all rows be the same length.  An anonymous matrix, as shown in the\nfirst example, must be named before it can be referenced (note error\nmessage).  When using \\name{mat} to fill a \\IFTEX{$1 \\times n$}{1 x n}\nmatrix, the row of values must be inside a second set of parentheses, to\neliminate ambiguity.\n\\end{Comments}\n\\end{Operator}\n\n\n\\begin{Operator}[mateigen]{MATEIGEN}\n\\index{matrix}\\index{eigenvalue}\nThe \\name{mateigen} operator calculates the eigenvalue equation and the\ncorresponding eigenvectors of a \\nameref{matrix}.\n\\begin{Syntax}\n\\name{mateigen}\\(\\meta{matrix-id},\\meta{tag-id}\\)\n\\end{Syntax}\n\n\n\\meta{matrix-id} must be a declared matrix of values, and \\meta{tag-id} must be \na legal REDUCE identifier.\n\n\\begin{Examples}\naa := mat((2,5),(1,0))\\$ \\\\\nmateigen(aa,alpha);          & \n\\begin{multilineoutput}{2cm}\n\\{\\{ALPHA^{2} - 2*ALPHA - 5,\n  1,\n  MAT(1,1) := \\rfrac{5*ARBCOMPLEX(1)}{ALPHA - 2},\n\n  MAT(2,1) := ARBCOMPLEX(1)\n  \\}\\}\n\\end{multilineoutput}\\\\\ncharpoly := first first ws;  &       CHARPOLY := ALPHA^{2} - 2*ALPHA - 5 \\\\\nbb := mat((1,0,1),(1,1,0),(0,0,1))\\$ \\\\\nmateigen(bb,lamb);          &  \n\\begin{multilineoutput}{6cm}\n\\{\\{LAMB - 1,3,\n  [      0      ]\n  [ARBCOMPLEX(2)]\n  [      0      ]\n  \\}\\}\n\\end{multilineoutput}\n\\end{Examples}\n\n\n\\begin{Comments}\nThe \\name{mateigen} operator returns a list of lists of three\nelements.  The first element is a square free factor of the characteristic\npolynomial; the second element is its multiplicity; and the third element\nis the corresponding eigenvector.  If the characteristic polynomial can be\ncompletely factored, the product of the first elements of all the sublists\nwill produce the minimal polynomial.  You can access the various parts of\nthe answer with the usual list access operators.\n\nIf the matrix is degenerate, more than one eigenvector can be produced for\nthe same eigenvalue, as shown by more than one arbitrary variable in the\neigenvector.  The identification numbers of the arbitrary complex variables\nshown in the examples above may not be the same as yours.  Note that since\n\\name{lambda} is a reserved word in REDUCE, you cannot use it as a {\\it\ntag-id} for this operator.\n\\end{Comments}\n\\end{Operator}\n\n\n\\begin{Declaration}[matrix]{MATRIX}\nIdentifiers are declared to be of type \\name{matrix}.\n\\begin{Syntax}\n\\name{matrix} \\meta{identifier} \\&option \\(\\meta{index},\\meta{index}\\)\\\\\n          \\{,\\meta{identifier} \\&option\n          \\(\\meta{index},\\meta{index}\\)\\}\\optional\n\\end{Syntax}\n\n\\meta{identifier} must not be an already-defined operator or array or \nthe name of a scalar variable.  Dimensions are optional, and if used appear \ninside parentheses.  \\meta{index} must be a positive integer. \n\n\\begin{Examples}\nmatrix a,b(1,4),c(4,4); \\\\\nb(1,1);                      &          0 \\\\\na(1,1);                      &          ***** Matrix A not set \\\\\na := mat((x0,y0),(x1,y1));   & \\begin{multilineoutput}{6cm}\nA(1,1) := X0\nA(1,2) := Y0\nA(2,1) := X0\nA(2,2) := X1\n\\end{multilineoutput}\\\\\nlength a;                    &          \\{2,2\\} \\\\\nb := a**2;                   & \\begin{multilineoutput}{6cm}\nB(1,1) := X0^{2} + X1*Y0\nB(1,2) := Y0*(X0 + Y1)\nB(2,1) := X1*(X0 + Y1)\nB(2,2) := X1*Y0 + Y1^{2}\n\\end{multilineoutput}\n\\end{Examples}\n\n\\begin{Comments}\nWhen a matrix variable has not been dimensioned, matrix elements cannot be\nreferenced until the matrix is set by the \\nameref{mat} operator.  When a\nmatrix is dimensioned in its declaration, matrix elements are set to 0.\nMatrix elements cannot stand for themselves.  When you use \\nameref{let} on\na matrix element, there is no effect unless the element contains a\nconstant, in which case an error message is returned.  The same behavior\noccurs with \\nameref{clear}.  Do \\meta{not} use \\nameref{clear} to try to\nset a matrix element to 0. \\nameref{let} statements can be applied to\nmatrices as a whole, if the right-hand side of the expression is a matrix\nexpression, and the left-hand side identifier has been declared to be a matrix.\n\nArithmetical operators apply to matrices of the correct dimensions.  The\noperators \\name{+} and \\name{-} can be used with matrices of the same\ndimensions.  The operator \\name{*} can be used to multiply\n\\IFTEX{$m \\times n$}{m x n} matrices by \\IFTEX{$n \\times p$}{n x p}\nmatrices.  Matrix multiplication is non-commutative.  Scalars can also be\nmultiplied with matrices, with the result that each element of the matrix\nis multiplied by the scalar.  The operator \\name{/} applied to two\nmatrices computes the first matrix multiplied by the inverse of the\nsecond, if the inverse exists, and produces an error message otherwise.\nMatrices can be divided by scalars, which results in dividing each element\nof the matrix.  Scalars can also be divided by matrices when the matrices\nare invertible, and the result is the multiplication of the scalar by the\ninverse of the matrix.  Matrix inverses can by found by \\name{1/A} or\n\\name{/A}, where \\name{A} is a matrix.  Square matrices can be raised to\npositive integer powers, and also to negative integer powers if they are\nnonsingular.\n\nWhen a matrix variable is assigned to the results of a calculation, the\nmatrix is redimensioned if necessary.\n\\end{Comments}\n\\end{Declaration}\n\n\n\\begin{Operator}[nullspace]{NULLSPACE}\n\\index{matrix}\n\\begin{Syntax}\n\\name{nullspace}(\\meta{matrix\\_expression})\n\\end{Syntax}\n\n\\meta{nullspace} calculates for its \\nameref{matrix} argument, \n\\name{a}, a list of\nlinear independent vectors (a basis) whose linear combinations satisfy the\nequation $a x = 0$.  The basis is provided in a form such that as many\nupper components as possible are isolated.\n\n\\begin{Examples}\nnullspace mat((1,2,3,4),(5,6,7,8)); &\n\\begin{multilineoutput}{6cm}\n       \\{\n         [ 1  ]\n         [    ]\n         [ 0  ]\n         [    ]\n         [ - 3]\n         [    ]\n         [ 2  ]\n         ,\n         [ 0  ]\n         [    ]\n         [ 1  ]\n         [    ]\n         [ - 2]\n         [    ]\n         [ 1  ]\n        \\}\n\\end{multilineoutput}\n\\end{Examples}\n\n\\begin{Comments}\nNote that with \\name{b := nullspace a}, the expression \\name{length b} is\nthe {\\em nullity\\/} of A, and that \\name{second length a - length b}\ncalculates the {\\em rank\\/} of A.  The rank of a matrix expression can\nalso be found more directly by the \\nameref{rank} operator.\n\nIn addition to the REDUCE matrix form, \\name{nullspace} accepts as input a\nmatrix given as a \\nameref{list} of lists, that is interpreted as a row matrix.  If\nthat form of input is chosen, the vectors in the result will be\nrepresented by lists as well.  This additional input syntax facilitates\nthe use of \\name{nullspace} in applications different from classical linear\nalgebra.\n\\end{Comments}\n\n\\end{Operator}\n\n\n\\begin{Operator}[rank]{RANK}\n\\index{matrix}\n\\begin{Syntax}\n\\name{rank}(\\meta{matrix\\_expression})\n\\end{Syntax}\n\\name{rank} calculates the rank of its matrix argument.\n\n\\begin{Examples}\nrank mat((a,b,c),(d,e,f));  & 2\n\\end{Examples}\n\n\\begin{Comments}\nThe argument to \\name{rank} can also be a \\nameref{list} of lists, interpreted\neither as a row matrix or a set of equations.  If that form of input is\nchosen, the vectors in the result will be represented by lists as well.\nThis additional input syntax facilitates the use of \\name{rank} in\napplications different from classical linear algebra.\n\\end{Comments}\n\n\\end{Operator}\n\n\n\\begin{Operator}[tp]{TP}\n\\index{transpose}\\index{matrix}\nThe \\name{tp} operator returns the transpose of its \\nameref{matrix}\n argument.\n\\begin{Syntax}\n\\name{tp} \\meta{identifier} or  \\name{tp}\\(\\meta{identifier}\\)\n\\end{Syntax}\n\n\\meta{identifier} must be a matrix, which either has had its dimensions set\nin its declaration, or has had values put into it by \\name{mat}.\n\n\\begin{Examples}\nmatrix m,n; \\\\\nm := mat((1,2,3),(4,5,6))\\$ \\\\\nn := tp m;                   &\n\\begin{multilineoutput}{6cm}\nN(1,1) := 1\nN(1,2) := 4\nN(2,1) := 2\nN(2,2) := 5\nN(3,1) := 3\nN(3,2) := 6\n\\end{multilineoutput}\n\\end{Examples}\n\\begin{Comments}\nIn an assignment statement involving \\name{tp}, the matrix identifier on the\nleft-hand side is redimensioned to the correct size for the transpose.\n\\end{Comments}\n\\end{Operator}\n\n\n\\begin{Operator}[trace]{TRACE}\n\\index{matrix}\nThe \\name{trace} operator finds the trace of its \\nameref{matrix} argument.\n\\begin{Syntax}\n\\name{trace}\\(\\meta{expression}\\) or \\name{trace} \\meta{simple\\_expression}\n\\end{Syntax}\n\n\\meta{expression} or \\meta{simple\\_expression} must evaluate to a square\nmatrix.\n\n\\begin{Examples}\nmatrix a; \\\\\na := mat((x1,y1),(x2,y2))\\$ \\\\\ntrace a;                     &         X1 + Y2\n\\end{Examples}\n\\begin{Comments}\nThe trace is the sum of the entries along the diagonal of a square matrix.\nGiven a non-matrix expression, or a non-square matrix, \\name{trace} returns\nan error message.\n\\end{Comments}\n\\end{Operator}\n\n\n", "meta": {"hexsha": "e465e31352676bdb87ea70de8410202dae12064c", "size": 11698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matrix.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": "matrix.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": "matrix.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": 31.6162162162, "max_line_length": 83, "alphanum_fraction": 0.6723371516, "num_tokens": 3547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6972516686295656}}
{"text": "\\chapter{CT Fourier Transform}\n\nRecall the complex exponential $e^{st}$ for $s\\in\\mathbb{C}$ is the Eigenfunction of CT LTI systems. If we can decompose an input into a (possibly infinite) sum of such signals, we can easily determine the output using the superposition principle. In this section we consider the decomposition when the input is aperiodic, called the CT \\emph{Fourier Transform} (CTFT).\n\nIn contrast to the CT Fourier series, in this case the complex exponent of the Eigenfunction becomes $s = j\\omega$ a continuous variable, and the decomposition is an uncountably infinite sum (integral). This gives the input-output relationship for a stable LTI system as\n\\[\nx(t) = \\frac{1}{2\\pi}\\int\\limits_{-\\infty}^{\\infty} X(j\\omega) \\, e^{j \\omega t}\\; d\\omega \\;\\longrightarrow\\; y(t) = \\frac{1}{2\\pi}\\int\\limits_{-\\infty}^{\\infty} H(j\\omega) X(j\\omega) \\, e^{j \\omega t}\\; d\\omega\n\\]\nwhere $H(j \\omega)$ are the Eigenvalues, again called the \\emph{frequency response}. We now turn to determining under what circumstances the decomposition exists and how to find the function $X(j\\omega)$.\n\n\\textbf{Note:} The difference in notation between $X(\\omega)$ and $X(j\\omega)$ is superficial. They generally are the same function. The latter just emphasizes that $s \\rightarrow j\\omega$. For example\n\\[\nH(j\\omega) = \\frac{1}{1+(j\\omega)^2} = \\frac{1}{1-\\omega^2} = H(\\omega) \n\\]\nare the same function since $j^2 = -1$.\n\n\\section{Synthesis and Analysis Equation}\n\nConsider the aperiodic signal\n\\[\nx(t) = \\begin{cases}\n  p(t) & A < t < B\\\\\n  0 & \\text{else}\n\\end{cases}\n\\]\nand it's periodic extension with fundamental frequency $\\omega_0 = \\frac{2\\pi}{T_0}$\n\\[\nx_p(t) = \\sum\\limits_{m = -\\infty}^{\\infty} x(t-mT_0)\n\\]\nwhere $T_0 > B-A$.\nFor example:\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/ctfs_derivation.pdf}\n\\end{center}\nThe CT Fourier series coefficients are\n\\begin{align*}\n  a_k &= \\frac{1}{T_0} \\int\\limits_{T_0} x_p(t) e^{-jk\\omega_0 t}\\; dt\\\\\n  &= \\frac{1}{T_0} \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-jk\\omega_0 t}\\; dt \\mbox{ since } x(t) = 0 \\mbox{ outside the interval } (A,B)\\\\\n\\end{align*}\nDefine the \\emph{CT Fourier Transform} of $x(t)$ as\n\\[\n\\boxed{X(\\omega) = \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t}\\; dt}\n\\]\nso that\n\\[\na_k = \\frac{1}{T_0} X(k\\omega_0)\n\\]\nare samples of $X(\\omega)$ spaced at frequencies $\\omega_0$. By the CT Fourier series synthesis equation\n\\[\nx(t) = \\sum\\limits_{k = -\\infty}^{\\infty} \\frac{1}{T_0} X(k\\omega_0) e^{jk\\omega_0 t} \n\\]\nNow, let $T_0 \\rightarrow \\infty$ so that the periodic copies move toward $\\infty$ and $x_p(t) \\rightarrow x(t)$. At the same time the frequency sample spacing becomes infinitesimal and\n\\[\nX(k\\omega_0) e^{jk\\omega_0 t} \\rightarrow X(\\omega) e^{j\\omega t}\\; d\\omega\n\\]\nTo give the \\emph{Inverse Fourier Transform}\n\\[\n\\boxed{x(t) = \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty} X(\\omega)e^{j\\omega t}\\; d\\omega}\n\\]\nThis gives the \\emph{Fourier Transform Pair}:\n\\[\n\\underbrace{X(\\omega) = \\mathcal{F}\\{x(t)\\} = \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t}\\; dt}_{\\text{Forward Transform / Analysis Equation}}\n\\hspace{3em}\n\\underbrace{x(t) = \\mathcal{F}^{-1}\\{X(\\omega)\\} = \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty} X(\\omega)e^{j\\omega t}\\; d\\omega}_{\\text{Inverse Transform / Synthesis Equation}}\n\\]\nThe forward transform decomposes $x(t)$ into an infinite number of complex sinusoids. The inverse transform synthesizes a signal as an infinite sum of the sinusoids. It is an example of an \\emph{Integral Transform}. Note the signal $x(t)$ and $X(\\omega)$ are the same signal, just represented in different \\emph{domains}, the time-domain and frequency-domain respectively. \n\nSimilar to the CT Fourier series, the function $X(\\omega)$ is called the \\emph{spectrum} of the signal $x(t)$. The magnitude spectrum is the function $|X(\\omega)|$ and the phase spectrum is the function $\\angle X(\\omega)$. It is common to plot the spectrum as the combination of the magnitude and phase spectrum.\n\n\\begin{example}\n  Consider the signal $x(t) = \\delta(t)$. The Fourier transform is\n  \\begin{align*}\n    X(\\omega) &= \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t}\\; dt\\\\\n    &= \\int\\limits_{-\\infty}^{\\infty} \\delta(t) e^{-j\\omega t}\\; dt\\\\\n    &= e^{-j\\omega (0)} \\mbox{ by the sifting property}\\\\\n    &= 1\n  \\end{align*}\n  $\\blacksquare$\n\\end{example}\n\\begin{example}\nConsider the signal $x(t) = e^{at}u(t)$ for $a\\in \\mathbb{R}$.  The Fourier transform is\n  \\begin{align*}\n    X(\\omega) &= \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t}\\; dt\\\\\n    &= \\int\\limits_{0}^{\\infty}  e^{at} \\, e^{-j\\omega t}\\; dt\\\\\n    &= \\int\\limits_{0}^{\\infty}  e^{(a-j\\omega) t}\\; dt\\\\\n    &= \\frac{1}{a-j\\omega } e^{(a-j\\omega) t} \\Big|_{0}^{\\infty}\\\\\n    &= \\frac{1}{a-j\\omega } \\left[ \\lim_{T\\rightarrow\\infty} e^{(a-j\\omega) T} - \\underbrace{e^{(a-j\\omega) (0)}}_{1}\\right]\n  \\end{align*}\n  This example raises the question, of when does the Fourier Transform exist? Note if $a < 0$ then the limit above converges to zero, otherwise the integral diverges. In the former case we say the Fourier transform exists, and in the latter that it does not. Thus\n  \\[\n  X(\\omega) = \\frac{-1}{a-j\\omega } = \\frac{1}{j\\omega-a} \\mbox{ for } a < 0\\;.\n  \\]\n  Note when $a < 0$, $x(t)$ is an energy signal. A sufficient, but not necessary condition for the Fourier transform to exist is that the signal be an energy signal. For this example, let's examine the spectrum, noting\n  \\[\n  |X(\\omega)| = \\frac{1}{(a^2 + \\omega^2)^\\frac{1}{2}} \\hspace{2em}\\mbox{and}\\hspace{2em} \\angle X(\\omega) = -\\arctan\\left( \\frac{\\omega}{-a}\\right)\n  \\]\n  plotted below for $a = -1$.\n  \\begin{center}\n\\includegraphics[scale=0.6]{graphics/ctft_example1.png}\n  \\end{center}\n  $\\blacksquare$\n\\end{example}\n\\begin{example}\nConsider the signal $x(t) = e^{j\\omega_0 t}$ for $\\omega_0\\in \\mathbb{R}$.  The Fourier transform is\n  \\begin{align*}\n    X(\\omega) &= \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t}\\; dt\\\\\n    &= \\int\\limits_{-\\infty}^{\\infty}  e^{j\\omega_0 t} \\, e^{-j\\omega t}\\; dt\\\\\n    &= \\int\\limits_{-\\infty}^{\\infty}  e^{-j(\\omega_0-\\omega) t}\\; dt\n  \\end{align*}\n  For $\\omega \\neq \\omega_0$ this integral evaluates to\n  \\begin{align*}\n    X(\\omega) &= \\int\\limits_{-\\infty}^{\\infty}  \\cos((\\omega-\\omega_0) t)\\; dt + j \\int\\limits_{-\\infty}^{\\infty}  \\sin((\\omega-\\omega_0) t)\\; dt\\\\\n    &= 0\n  \\end{align*}\n  since the average value of a sinusoid is zero. When $\\omega = \\omega_0$ this integral diverges\n  \\[\n  \\int\\limits_{-\\infty}^{\\infty}  e^{-j(\\omega_0-\\omega) t}dt = \\int\\limits_{-\\infty}^{\\infty}  e^{-j(0) t} dt= \\int\\limits_{-\\infty}^{\\infty} dt = \\infty \n  \\]\n  What signal is zero everywhere, but infinite at one point (I am hand-waving a bit here)? The delta function\n  \\[\n  X(\\omega) = A\\delta(\\omega-\\omega_0) \\mbox{ for some constant } A.\n  \\]\n  To find the constant we can use the inverse transform\n  \\begin{align*}\n    x(t) &= \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty} X(\\omega)e^{j\\omega t}\\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty}  A\\delta(\\omega-\\omega_0) e^{j\\omega t}\\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} A e^{j\\omega_0 t}\\\\\n    &= e^{j\\omega_0 t}\n  \\end{align*}\n  which implies $A = 2\\pi$.\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\n  Consider the signal $x(t) = \\cos(\\omega_0 t)$ for $\\omega_0\\in \\mathbb{R}$.  The Fourier transform can be found using the result in the previous example by noting\n  \\begin{align*}\n    X(\\omega) &= \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t}\\; dt\\\\\n    &= \\int\\limits_{-\\infty}^{\\infty}  \\cos(\\omega_0 t) \\, e^{-j\\omega t}\\; dt\\\\\n    &= \\frac{1}{2}\\int\\limits_{-\\infty}^{\\infty}   e^{j\\omega_0 t} \\, e^{-j\\omega t}\\; dt + \\frac{1}{2}\\int\\limits_{-\\infty}^{\\infty} e^{-j\\omega_0 t} \\, e^{-j\\omega t}\\; dt\\\\\n    &= \\frac{1}{2} 2\\pi \\delta(\\omega-\\omega_0) + \\frac{1}{2} 2\\pi \\delta(\\omega+\\omega_0)\\\\\n    &= \\pi \\delta(\\omega-\\omega_0) + \\pi \\delta(\\omega+\\omega_0)\n  \\end{align*}\n  This example highlights that the cosine signal is composed of exactly two frequencies.\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\n  Consider the signal\n  \\[\n  X(\\omega) = \\begin{cases}\n    1 & |\\omega| < \\omega_0\\\\\n    0 & \\text{else}\n  \\end{cases}\n  \\]\n  The Inverse Fourier transform is\n  \\begin{align*}\n    x(t) & = \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty} X(\\omega)e^{j\\omega t}\\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} \\int\\limits_{-\\omega_0}^{\\omega_0} e^{j\\omega t}\\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} \\frac{1}{jt} \\left[ e^{j\\omega_0 t} - e^{-j\\omega_0 t}\\right]\\\\\n    &= \\frac{1}{\\pi t} \\left[ \\frac{1}{2j}e^{j\\omega_0 t} - \\frac{1}{2j} e^{-j\\omega_0 t}\\right]\\\\\n    &= \\frac{1}{\\pi t} \\sin(\\omega_0 t)\\\\\n    &= \\frac{\\omega_0}{\\pi} \\frac{\\sin(\\omega_0 t)}{\\omega_0 t}\\\\\n    &= \\frac{\\omega_0}{\\pi} \\mbox{sinc}(\\omega_0 t)\n  \\end{align*}\n  where $\\mbox{sinc}()$ is the (unnormalized) \\emph{sinc function}.\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\section{Existence of the CT Fourier Transform}\n\nThe example of the real exponential above showed that for the Fourier transform to exist, the Fourier (analysis) integral must exist. Similar to the Fourier series some mild conditions, called the Dirichlet conditions, are a sufficient prerequisite for the Fourier transform of a signal $x(t)$ to exist:\n\\begin{itemize}\n\\item $x(t)$ is absolutely integrable\n  \\[\n  x(t) = \\int\\limits_{-\\infty}^{\\infty} |x(t)|\\; dt < \\infty\n  \\]\n\\item $x(t)$ has a finite number of minima and maxima over any finite interval\n\\item $x(t)$ has a finite number of finite-valued discontinuities over any finite interval\n\\end{itemize}\n\nThese conditions are not necessary however, and we can extend the Fourier transform to a broader class of signals, if we allow delta functions in the transform, as in the cosine example above. \n\n\\section{Properties of the CT Fourier Transform}\n\nThere are several useful properties of the CT Fourier Transform that, when combined with a table of transforms (see Table 4.2, page 329 of OW), allow us to take the Fourier transform of  wide array of signals, and one, the convolution property, that allows us to determine the output of a system in the frequency domain easily. We state these here without proof in rough order of usefulness. See the course text for detailed derivations.\n\nWe use the notation $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ to indicate the signals are related by a Fourier Transform pair.\n\\begin{itemize}\n\\item Linearity: if $x_1(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_1(\\omega)$ and $x_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_2(\\omega)$ then\n  \\[\n  ax_1(t) + bx_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} aX_1(\\omega) + bX_2(\\omega)\n  \\]\n\\item Convolution: if $x_1(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_1(\\omega)$ and $x_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_2(\\omega)$ then\n  \\[\n  x_1(t) * x_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_1(\\omega)X_2(\\omega)\n  \\]\n  Note in particular if one signal is the system input and the other is the impulse response, the output is the product of the Fourier transforms of each, where the Fourier transform of $h(t)$ is $H(\\omega)$, the Eigenvalue or frequency response.\n\\item Differentiation if $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ then\n  \\[\n  \\frac{dx}{dt}(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} j\\omega X(\\omega)\n  \\]\n  This allows us to easily determine the Eigenvalues/Frequency Response from a stable differential equation.\n\\item Multiplication: if $x_1(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_1(\\omega)$ and $x_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_2(\\omega)$ then\n  \\[\n  x_1(t) \\cdot x_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\frac{1}{2\\pi} X_1(\\omega)*X_2(\\omega)\n  \\]\n  where $X_1(\\omega)*X_2(\\omega)$ is convolution in the frequency domain\n  \\[\n  X_1(\\omega)*X_2(\\omega) = \\int\\limits_{-\\infty}^{\\infty} X_1(\\gamma)*X_2(\\omega-\\gamma)\\;d\\gamma \n  \\]\n\\item Time-Shift: if $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ then\n  \\[\n  x(t-t_0) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)e^{-j\\omega t_0}\n  \\]\n\\item Conjugate Symmetry: if $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ then\n  \\[\n  x^*(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X^*(-\\omega)\n  \\]\n  This implies that if $x(t)$ is real, then the magnitude spectrum is an even function, and the phase spectrum is an odd function.\n\n\\item Integration: if $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ then\n  \\[\n  \\int\\limits_{-\\infty}^t x(\\tau)\\; d\\tau \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\frac{1}{j\\omega} X(\\omega) + \\pi X(0) \\delta(\\omega)\n  \\]\n\\item Time and Frequency Scaling: if $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ then if $a$ is a real constant\n  \\[\n  x(at) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\frac{1}{|a|} X\\left(\\frac{\\omega}{a}\\right)\n  \\]\n\\item Parseval's Relation: if $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(\\omega)$ then\n  \\[\n  \\int\\limits_{0-\\infty}^{\\infty} |x(t)|^2\\; dt =  \\frac{1}{2\\pi}\\int\\limits_{0-\\infty}^{\\infty} |X(\\omega)|^2\\;d\\omega\n  \\]\n\\end{itemize}\n\n\n\\section{CT Fourier Transform of a Periodic Signal}\n\nEven though the Fourier transform was derived in the case of an a-periodic signal, the linearity property of the transform, combined with one of our examples above shows us that we can take the Fourier Transform of a periodic signal. Consider a periodic signal with Fourier series expansion\n\\[\nx(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k e^{jk\\omega_0 t}\n\\]\nTaking the Fourier Transform\n\\[\n\\mathcal{F}\\{x(t)\\} = \\mathcal{F}\\left\\{\\sum\\limits_{k = -\\infty}^{\\infty} a_k e^{jk\\omega_0 t}\\right\\} = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\mathcal{F}\\{e^{jk\\omega_0 t}\\} = \\sum\\limits_{k = -\\infty}^{\\infty} a_k 2\\pi \\delta(\\omega-k\\omega_0) \n\\]\nThus the discrete Fourier series coefficients become the weights of the corresponding delta functions centered at the harmonic frequency.\n\n", "meta": {"hexsha": "eb3c4d839717aabde3d2d78410b67fba3cd5c0aa", "size": 13957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-ctft.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": "16-ctft.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": "16-ctft.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": 56.2782258065, "max_line_length": 437, "alphanum_fraction": 0.6696281436, "num_tokens": 4823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.6972516510527945}}
{"text": "\\chapter{Thermodynamics and Statistical Mechanics}\n\n\\section{Laws of Thermodynamics}\n\n\t\\subsection{Zeroth Law}\n\tIf system $A$ is in equilibrium with system $B$ and system $C$ is also in equilibrium with system $B$, then system $A$ is in equilibrium with system $C$.\n\t\t\n\t\\subsection{First Law}\n\tThe total change in the energy of the system can be expressed as,\n\t\\begin{equation}\n\t\t\\mathrm{d}E = T\\mathrm{d}S - p\\mathrm{d}V + \\sum_i\\mu_i\\mathrm{d}N_i.\n\t\\end{equation}\n\t\t\n\t\\subsection{Second Law}\n\t\\subsection{Third Law}\n\n\\section{Adiabatic Processes}\n\\newthought{An adiabatic process} in thermodynamics is a reversible process where no heat is added to (or removed from) the gas system by its surroundings, the system evolves \\textit{slowly} enough that it evolves through a sequence of states in thermal equilibrium, and the pressure and volume satisfy $pV^{\\gamma}=\\text{constant}$. \n\nIn the context of MHD (or hydrodynamics), we say that each fluid element is \\textit{always} in local thermal equilibrium. This is consistent with the assumption of long times scales for the MHD (fluid) equations (i.e. long compared to the collisional/thermalization time scales in this case.)\n\n\\section{Equipartition Theorem}\n\\newthought{The equipartition theorem} states that at temperature $T$, the average energy of any quadratic degree of freedom is $(1/2)k_BT$. Note that the equipartition theorem applies to only those systems whose energy is in the form of quadratic degrees of freedom of the form $E(q) = cq^2$, where $c$ is some constant and $q$ is the degree of freedom (e.g. $x,p_y,L_z$ etc.).\n\n\\section{Boltzmann Distribution}\n\\newthought{Recall that the entropy} can be expressed as $S=k_B\\ln{\\Omega}$, where $\\Omega$ is the multiplicity. This just states that the entropy increases with the multiplicity of the system, or the number of possible accessible microstates. We regard each microstate as equally probable. Thus, the probability of being in a particular state $s^{'}$ is proportional to the multiplicity of $s^{'}$. We can write the ratio of probabilities of being in states $s_2$ and $s_1$ as\n\\begin{equation}\n\t\\frac{P(s_1)}{P(s_2)} = \\frac{\\Omega(s_2)}{\\Omega(s_1)}.\n\\end{equation}\nWe can then write this ratio in terms of the entropy,\n\\begin{equation}\n\t\\frac{P(s_1)}{P(s_2)} = \\exp{\\left(\\frac{S(s_2) - S(s_1)}{k_B}\\right)}.\n\\end{equation}\nRecalling the first law, we can write the change in entropy as, letting $\\mathrm{d}N\\to0$ and neglecting $p\\mathrm{d}V$ as small compared to $\\mathrm{d}E$, $\\mathrm{d}S=\\mathrm{d}E/T$. Plugging this into our above expression,\n\\begin{equation}\n\t\\frac{P(s_1)}{P(s_2)} = \\exp{\\left(-\\frac{E(s_2) - E(s_1)}{k_BT}\\right)},\n\\end{equation}\nwhere the negative sign comes from the fact that the change in the reservoir energy is equal and opposite of that to the change in the energy of the single atom system. We call these exponential terms Boltzmann factors,\n\\begin{equation}\n\t\\text{Boltzmann factor} = \\exp{\\left(-\\frac{E(s)}{k_BT}\\right)}.\n\\end{equation}\nSeparating factors of $s_1,s_2$, it can be seen that the LHS and RHS are independent, meaning they can be set equal to a constant which we will call $Z$. Thus, the probability of state $s$ can be written as \n\\begin{equation}\n\tP(s) = \\frac{1}{Z}\\exp{(-E(s)/k_BT)}.\n\\end{equation}\nUsing the fact that $\\sum_sP(s)=1$, we can determine $Z$ such that\n\\begin{equation}\n\tP(s) = \\frac{\\exp{(-E(s)/k_BT)}}{\\sum_s\\exp{(-E(s)/k_BT)}}.\n\\end{equation}\nThis is the so-called Boltzmann distribution, or canonical distribution.\n\n\\section{Maxwellian}\n\\newthought{Using Boltzmann factors,} we can express the velocity distribution in thermal equilibrium as\n\\begin{equation}\n\tf_M(v) = (\\frac{m}{2\\pi k_BT})^{3/2}4\\pi v^2\\exp{(-mv^2/2k_BT)}.\n\\end{equation}\nThis distribution goes to zero as $v\\to0$ and $V\\to\\infty$. It peaks at the thermal velocity, $v_T=\\sqrt{2k_BT/m}$.\n", "meta": {"hexsha": "2d713a0c0b9815dc9eedae6b7f8b9a10fa7827d1", "size": 3855, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch_stat_mech.tex", "max_stars_repo_name": "wtbarnes/space_plasma_notes", "max_stars_repo_head_hexsha": "ad608d603b4a523ce49ff0c2af5605c3af46bac6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-28T15:37:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-28T15:37:23.000Z", "max_issues_repo_path": "chapters/ch_stat_mech.tex", "max_issues_repo_name": "wtbarnes/space_plasma_notes", "max_issues_repo_head_hexsha": "ad608d603b4a523ce49ff0c2af5605c3af46bac6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-16T07:34:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-16T07:34:46.000Z", "max_forks_repo_path": "chapters/ch_stat_mech.tex", "max_forks_repo_name": "wtbarnes/space_plasma_notes", "max_forks_repo_head_hexsha": "ad608d603b4a523ce49ff0c2af5605c3af46bac6", "max_forks_repo_licenses": ["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.4655172414, "max_line_length": 477, "alphanum_fraction": 0.7395590143, "num_tokens": 1149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.697251650041538}}
{"text": "\n\\subsection{Indefinite (pseduo) and split orthognal groups \\(O(n,m,F)\\)}\n\n\\subsubsection{Recap: Metric-preserving transformations}\n\nThe bilinear form is:\n\n\\(u^TMv\\)\n\nThe transformations which preserve this are:\n\n\\(P^TMP=M\\)\n\n\\subsubsection{The metric}\n\nIf the metric is:\n\n\\(M=\\begin{bmatrix}-1 & 0 & 0 & 0\\\\0 & 1 & 0 & 0\\\\0 & 0 & 1 & 1\\\\0 & 0 & 0 & 1\\end{bmatrix}\\)\n\nThen we have the indefinite orthogonal group \\(O(3,1)\\)\n\n\\subsubsection{The split orthogonal group}\n\nWhere \\(n=m\\) we have the split orthogonal group.\n\n\\(O(n,n,F)\\)\n\n\\subsubsection{Signatures}\n\n\n", "meta": {"hexsha": "5c2fd3064dc801308945ff340ebe73a8bfe8f82f", "size": 563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/02-06-OIndef.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-06-OIndef.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-06-OIndef.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.1612903226, "max_line_length": 93, "alphanum_fraction": 0.674955595, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6972017728582834}}
{"text": "\\subsection{Asymptotes and Other Things to Look For}\\label{sec:Asymptotes}\nA vertical asymptote\\index{asymptote} is a place where the function\nbecomes infinite, typically because the formula for the function has a\ndenominator that becomes zero.  For example, the reciprocal function\n$f(x)=1/x$ has a vertical asymptote at $x=0$, and the function $\\tan\nx$ has a vertical asymptote at $x=\\pi/2$ (and also at $x=-\\pi/2$,\n$x=3\\pi/2$, etc.).  Whenever the formula for a function contains a\ndenominator it is worth looking for a vertical asymptote by \nchecking to see if the denominator can ever be zero, and then checking\nthe limit at such points. Note that there is not always a vertical\nasymptote where the derivative is zero: $f(x)=(\\sin x)/x$ has a zero\ndenominator at $x=0$, but since $\\ds \\lim_{x\\to 0}(\\sin x)/x=1$ there is\nno asymptote there.\n\nA horizontal asymptote is a horizontal line to which $f(x)$ gets closer and\ncloser as $x$ approaches $\\infty$ (or as $x$ approaches $-\\infty$).  For\nexample, the reciprocal function has the $x$-axis for a horizontal\nasymptote.  Horizontal asymptotes can be identified by computing \nthe limits $\\ds \\lim_{x \\to \\infty}f(x)$ and $\\ds \\lim_{x \\to -\\infty}f(x)$.\nSince $\\ds \\lim_{x \\to \\infty}1/x=\\lim_{x \\to -\\infty}1/x=0$, the line\n$y=0$ (that is, the $x$-axis) is a horizontal asymptote in both directions.\n\nSome functions have asymptotes that are neither horizontal nor\nvertical, but some other line. Such asymptotes are somewhat more\ndifficult to identify and we will ignore them.\n\nIf the domain of the function does not extend out to infinity, we should\nalso ask what happens as $x$ approaches the boundary of the domain.  For\nexample, the function $\\ds y=f(x)=1/\\sqrt{r^2-x^2}$ has domain $-r<x<r$, and\n$y$ becomes infinite as $x$ approaches either $r$ or $-r$. In this\ncase we might also identify this behavior because when $x=\\pm r$ the\ndenominator of the function is zero.\n\nIf there are any points where the derivative fails to exist (a cusp or\ncorner), then we should take special note of what the function does at such\na point.\n\nFinally, it is worthwhile to notice any symmetry.  A function $f(x)$ that\nhas the same value for $-x$ as for $x$, i.e., $f(-x)=f(x)$, is called an\n``even function.''  Its graph is symmetric with respect to the $y$-axis.\nSome examples of even functions are: $\\ds x^n$ when $n$ is an even number,\n$\\cos x$, and $\\ds \\sin^2x$.  On the other hand, a function that satisfies the\nproperty $f(-x)=-f(x)$ is called an ``odd function.''  Its graph is\nsymmetric with respect to the origin.  Some examples of odd functions are:\n$x^n$ when $n$ is an odd number, $\\sin x$, and $\\tan x$.  Of course, most\nfunctions are neither even nor odd, and do not have any particular\nsymmetry.", "meta": {"hexsha": "28b0aed7bce25eb88d827cb28eb1c6eec3eba8e7", "size": 2751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-6-4-asymptotes-other.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-4-asymptotes-other.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-4-asymptotes-other.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.5319148936, "max_line_length": 78, "alphanum_fraction": 0.7306434024, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.6971898755507655}}
{"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 8}\n\nProve that the \\textsc{Hitting Set} problem, explained below, is NP-complete.\n\\begin{itemize}\\itemsep=0pt\n\\item[] \\textit{Instance:} A collection $C$ of subsets of a set $S$ together with a positive integer $K$.\n\\item[] \\textit{Question:} Does $S$ contain a hitting set for $C$ of size $K$ or less? i.e.\nIs there a subset $S' \\subseteq S$ with $|S'| \\leq K$ such that $S'$ contains at least one element of each set $c \\in C$?\n\\end{itemize}\n\n\\subsection*{Solution}\n\nWe will first prove \\textsc{Hitting Set} is in NP and then will show that the \\textsc{Vertex Cover} problem can be polynomially reduced to this problem which proves \\textsc{Hitting Set} is NP-Hard.\n\\begin{enumerate}[label=(\\alph*)]\n\\item To show that \\textsc{Hitting Set} is in NP, we must show there as an algorithm that verifies in polynomial time if for a given finite set $S$, a collection $C$ of its subsets, a number $K$ and a final subset $S'$, intersection of $S'$ with each set $c \\in C$ is non-empty.\nSince $S'$ is given, we need only to check if there are at most $K$ sets $c \\in C$ whose intersection with $S'$ is not empty.\nAssuming there are $|C|$ elements in $C$, since finding intersection of two sets $c_1$ and $c_2$ is $\\mathcal{O}(\\max\\{|c_1|, |c_2|\\}^2)$, runtime to obtain size of $S'$ would be $\\mathcal{O}(n^3)$ which is polynomial.\nTherefore, \\textsc{Hitting Set} is satisfiable in polynomial time and is thus in NP.\n\\item To show \\textsc{Hitting Set} is NP-Hard we reduce the NP-Hard problem of \\textsc{Vertex Cover} in polynomial time to \\textsc{Hitting Set}.\nSuppose $V$ is a vertex cover of size at most $K$ for graph $G(V, E)$.\nSince $V$ is a vertex cover, for any edge $e = (u,v)$ either $u$ or $v$ is in $V$.\nWe can now think of $e$ as a collection $c \\in C$ with size 2.\nSince for each $c$, one of the elements is in $V$, graph $G=(V,E)$ has a hitting set of size at most $K$.\nSince the reduction takes linear time to the size of the input $S$, it is a polynomial-time reduction.\nHence, \\textsc{Hitting Set} is at least as hard as \\textsc{Vertex Cover} which is NP-Complete.\n\\end{enumerate}\nTherefore we have shown \\textsc{Hitting Set} is in NP and is NP-hard which concludes it is NP-Complete.\n", "meta": {"hexsha": "993af28c97d3a6bc8de5947e6cd5792f533bca26", "size": 2570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q08.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/hw06q08.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/hw06q08.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 75.5882352941, "max_line_length": 278, "alphanum_fraction": 0.6828793774, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.6971898708124046}}
{"text": "\\section{Model Description}\n\nThe Bore Angle Calculation model uses vector mathematics in order to calculate the miss angle from a boresight on the spacecraft to its desired target. The model also calculates the azimuth angle of the boresight.\n\n\\begin{figure}[H]\n\t\\centerline{\n\t\t \\includegraphics[height = 3in]{Figures/missAngleImg.JPG}\n\t}\n\t\\caption{All of the vectors and the miss angle are labeled here. $\\bm O$ is the vector that represents the boresight of the instrument that the test is interested in. $\\bm{L}$ is the direction that the spacecraft should be pointing its boresight in. $\\bm M$ is the miss angle of the boresight to its desired direction. All of the $\\bm r$ vectors are various position vectors designated by their subscripts.} \n\t\\label{fig:Fig1}\n\\end{figure}\n\nThe model begins by creating a direction cosine martix to represent the pointing frame from the inertial frame. Then the boresight vector is projected into this frame, and the miss angle and the azimuth angle are calculated using standard trigonometry. These calculations are performed in the following way:\n\nFirst, the unit relative position vector of the spacecraft is calculated relative to the celestial body that the spacecraft is supposed to be pointing at. Using Equation \\ref{eq:rePos}. Where $\\hat{\\bm r}_{B/S}$ is the unit relative position of the spacecraft to the planet, $\\bm r_{N/S}$ is the position of the celestial body in the inertial frame, and $\\bm r_{N/B}$ is the position of the spacecraft in the inertial frame. \n\n \\begin{equation}\n \t\\label{eq:rePos}\n \t\\hat{\\bm r}_{B/S} = \\frac{\\bm r_{N/S} - \\bm r_{N/B}}{\\vert \\bm r_{N/S} - \\bm r_{N/B} \\vert}\n\\end{equation}\n\nNext, the unit relative velocity of the spacecraft is calculated in the same manner.\n\n \\begin{equation}\n \t\\label{eq:reVel}\n \t\\hat{\\bm v}_{B/S} = \\frac{\\bm v_{N/S} - \\bm v_{N/B}}{\\vert \\bm v_{N/S} - \\bm v_{N/B} \\vert}\n\\end{equation}\n\nThen, direction cosine matrix from the inertial frame to the pointing frame is constructed. The first row of the direction cosine matrix is set to be the unit relative position vector calculated in the first step. The last row of the direction cosine matrix is set to be the result of the cross product of the relative unit position vector with the cross product of the relative position vector with the relative velocity vector. Then, the second row of the direction cosine matrix is set to be the cross product of the first and last row of the direction cosine matrix, as show in Equation \\ref{eq:dcm3}\n\n \\begin{equation}\n \t\\label{eq:dcm3}\n \t[\\bm{PN}] =  \\begin{bmatrix}\n    \\hat{ \\bm r}_{B/S}^T \\\\\n     ((\\hat{\\bm r}_{B/S}  \\times  (\\bm r_{B/S}  \\times \\bm v_{B/S})) \\times \\hat{ \\bm r}_{B/S}) ^T\\\\\n    (\\hat{\\bm r}_{B/S}  \\times  (\\bm r_{B/S}  \\times \\bm v_{B/S}))^T\n    \\end{bmatrix}\n\\end{equation}\n\n Once the direction cosine matrix has been created, the direction cosine matrix from the body frame to the pointing frame is created by multiplying the direction cosine matrix from the body frame to the inertial frame and the inertial frame to the pointing frame together. Then the boresight vector, $\\bm O$ (which is shown in Figure \\ref{fig:Fig1}), is projected into the pointing frame by dotting the new direction cosine matrix with the boresight vector in the body frame. This is shown in Equation \\ref{eq:boreSight}.\n\n \\begin{equation}\n \t\\label{eq:boreSight}\n \t\\leftexp{P}{\\bm {O}} = [\\bm{PB}] \\cdot\\leftexp{B}{\\bm {O}}\n\\end{equation}\n\nFrom there, the boresight vector is multiplied by the baseline vector in the pointing frame. Where the baseline vector in the pointing frame is defined as $\\bm L = \\hat{\\bm i}$. Then the product of the boresight vector and the baseline vector is passed through the arccosine function to get the boresight miss angle. As shown in Equation \\ref{eq:missAng}.\n\n \\begin{equation}\n \t\\label{eq:missAng}\n \tM = \\arccos(\\bm O \\cdot \\bm L)\n\\end{equation}\n\n\\begin{figure}[H]\n\t\\centerline{\n\t\t \\includegraphics[height = 2.5in]{Figures/azi.JPG}\n\t}\n\t\\caption{The azimuth angle, A is shown here with respect to the pointing coordinate frame and the vectors used to construct the azimuth angle.}\n\t\\label{fig:Fig2}\n\\end{figure}\n \nThe azimuth angle is calculated by passing the product of the last two components of the borsight vector. This is shown in Equation \\ref{eq:azAng} and in Figure \\ref{fig:Fig2}.\n\n \\begin{equation}\n \t\\label{eq:azAng}\n \tA = \\arctan\\bigg(\\frac{\\bm O_{\\hat k}}{\\bm O_{\\hat j}}\\bigg)\n\\end{equation}", "meta": {"hexsha": "205b7573c452d678f358bc24805dab1475fb1a53", "size": 4446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/dynamics/DynOutput/boreAngCalc/_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/DynOutput/boreAngCalc/_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/DynOutput/boreAngCalc/_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": 66.3582089552, "max_line_length": 604, "alphanum_fraction": 0.7393162393, "num_tokens": 1238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6971886537586005}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      5 & 7 \\\\\n      -4 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the characteristic polynomial $p(\\eigenvar)$, and compute\n  $p(A)$.\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 2 & -1 \\\\\n      0 & 1 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the characteristic polynomial $p(\\eigenvar)$, and compute\n  $p(A)$.\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}\n  \\item Let $A$ be a $2\\times 2$-matrix. Prove that $A^2$ is a linear\n    combination of $A$ and $I$.\n  \\item Given an example of a $3\\times 3$-matrix $A$ such that $A^2$\n    is not a linear combination of $A$ and $I$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item The characteristic polynomial of $A$ is a quadratic\n      polynomial, and therefore it is of the form\n      $p(\\eigenvar) = \\eigenvar^2 + b\\eigenvar + c$, for some\n      $r,s\\in\\R$. By the Cayley-Hamilton theorem, $p(A)=0$, therefore\n      $A^2 = -bA - cI$. This proves that $A^2$ is a linear combination\n      of $A$ and $I$.\n    \\item $A=\\begin{mymatrix}{rrr}\n        0 & 1 & 0 \\\\\n        0 & 0 & 1 \\\\\n        0 & 0 & 0 \\\\\n      \\end{mymatrix}$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "633f409bd07e3023293a4ba55146cac31d88d5c3", "size": 1294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-CayleyHamilton.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-CayleyHamilton.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-CayleyHamilton.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.8846153846, "max_line_length": 70, "alphanum_fraction": 0.5641421947, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.8006920116079208, "lm_q1q2_score": 0.6970802835188341}}
{"text": "\\documentclass[12pt]{mmalatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Quadratic convergence of Newton-Raphson iterations}\n\nThis is a simple example that uses Mathematica to demonstrate the quadratic converegnce of Newton-Raphson iterations to the exact root of a non-linear equation.\n\n\\vspace{10pt}\n\n\\begin{mathematica}\n   f[x_] = N[x - Exp[-x] , 200];                                (* work to 200 decimal digits *)\n   a = NestList[(# - f[#]/f'[#]) &, SetPrecision[1/2,200], 6];  (* list of x values *)\n   b = f /@ a;                                                  (* list of f values *)\n   c = #^2 & /@ b;                                              (* list of f^2 values *)\n   (* mmaBeg(table) *)\n   Print[OutputForm[\n         ToString[0] <> \"&\" <>\n         ToString[NumberForm[a[[1]], 25]] <> \"&\" <>\n         ToString[ScientificForm[b[[1]], 11, NumberFormat -> (SequenceForm[#1, \"e\", #3] &)]] <>\n         \"\\\\\\\\\"\n         ]]\n   Do[Print[OutputForm[\n            ToString[i-1] <> \"&\" <>\n            ToString[NumberForm[a[[i]], 25]] <> \"&\" <>\n            ToString[ScientificForm[b[[i]], 11, NumberFormat -> (SequenceForm[#1, \"e\", #3] &)]] <> \"&\" <>\n            ToString[NumberForm[b[[i]]/c[[i - 1]], 5]] <>\n            \"\\\\\\\\\"\n            ]], {i, 2, 7}]\n   (* mmaEnd(table) *)\n\\end{mathematica}\n\n\\clearpage\n\nNote the clear quadratic convergence in the iterations -- the last column settles to approximately $-0.11546$ independent of the number of iterations. This behaviour would not be seen using normal floating point computations as they are normally limited to no more than 18 decimal digits. This computation used 200 decimal digits.\n\n\\def\\eps{\\epsilon}\n\\def\\RuleA{\\vrule depth0pt  width0pt height14pt}\n\\def\\RuleB{\\vrule depth8pt  width0pt height14pt}\n\\def\\RuleC{\\vrule depth10pt width0pt height16pt}\n\n\\setlength{\\tabcolsep}{0.025\\textwidth}%\n\n\\begin{center}\n\\begin{tabular}{cccc}%\n   \\noalign{\\hrule height 1pt}\n   \\multicolumn{4}{c}{\\RuleC\\rmfamily\\bfseries%\n   Newton-Raphson iterations \\quad%\n   $x_{n+1} = x_n - f_n/f'_n\\ ,\\quad f(x) = x-e^{-x}$}\\\\\n   \\noalign{\\hrule height 1pt}\n   \\RuleB$n$&$x_n$&$ \\eps_{n} =  x_{n} - e^{-x_{n}}$&$\\eps_{n}/\\eps_{n-1}^2$\\\\\n   \\noalign{\\hrule height 0.5pt}\n   \\mma{table}\n   \\noalign{\\hrule height 1pt}\n\\end{tabular}\n\\end{center}\n\n\\vspace{20pt}\n\n\\begin{minipage}[t]{0.75\\textwidth}\n\\begin{latex}\n   \\def\\eps{\\epsilon}\n   \\def\\RuleA{\\vrule depth0pt  width0pt height14pt}\n   \\def\\RuleB{\\vrule depth8pt  width0pt height14pt}\n   \\def\\RuleC{\\vrule depth10pt width0pt height16pt}\n\n   \\setlength{\\tabcolsep}{0.025\\textwidth}%\n\n   \\begin{center}\n   \\begin{tabular}{cccc}%\n      \\noalign{\\hrule height 1pt}\n      \\multicolumn{4}{c}{\\RuleC\\rmfamily\\bfseries%\n      Newton-Raphson iterations \\quad%\n      $x_{n+1} = x_n - f_n/f'_n\\ ,\\quad f(x) = x-e^{-x}$}\\\\\n      \\noalign{\\hrule height 1pt}\n      \\RuleB$n$&$ x_n$&$\\eps_{n} =  x_{n} - e^{-x_{n}}$&$\\eps_{n}/\\eps_{n-1}^2$\\\\\n      \\noalign{\\hrule height 0.5pt}\n      \\mma{table}\n      \\noalign{\\hrule height 1pt}\n   \\end{tabular}\n   \\end{center}\n\\end{latex}\n\\end{minipage}\n\n\\end{document}\n", "meta": {"hexsha": "ba5b399983057f30ce34f41b33756dfd7ed73cc3", "size": 3087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematica/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": "mathematica/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": "mathematica/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": 35.4827586207, "max_line_length": 330, "alphanum_fraction": 0.5931324911, "num_tokens": 1034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6970802746197239}}
{"text": "\\section{Identity types}\\label{chap:identity}\n\n\\index{identity type|(}\n\\index{inductive type!identity type|(}\nFrom the perspective of types as proof-relevant propositions, how should we think of \\emph{equality} in type theory? Given a type $A$, and two terms $x,y:A$, the equality $\\id{x}{y}$ should again be a type. Indeed, we want to \\emph{use} type theory to prove equalities. \\emph{Dependent} type theory provides us with a convenient setting for this: the equality type $\\id{x}{y}$ is dependent on $x,y:A$. \n\nThen, if $\\id{x}{y}$ is to be a type, how should we think of the terms of $\\id{x}{y}$. A term $p:\\id{x}{y}$ witnesses that $x$ and $y$ are equal terms of type $A$. In other words $p:\\id{x}{y}$ is an \\emph{identification} of $x$ and $y$. In a proof-relevant world, there might be many terms of type $\\id{x}{y}$. I.e., there might be many identifications of $x$ and $y$. And, since $\\id{x}{y}$ is itself a type, we can form the type $\\id{p}{q}$ for any two identifications $p,q:\\id{x}{y}$. That is, since $\\id{x}{y}$ is a type, we may also use the type theory to prove things \\emph{about} identifications (for instance, that two given such identifications can themselves be identified), and we may use the type theory to perform constructions with them. As we will see shortly, we can give every type a groupoidal structure.\n\nClearly, the equality type should not just be any type dependent on $x,y:A$. Then how do we form the equality type, and what ways are there to use identifications in constructions in type theory? The answer to both these questions is that we will form the identity type as an \\emph{inductive} type, generated by just a reflexivity term providing an identification of $x$ to itself. The induction principle then provides us with a way of performing constructions with identifications, such as concatenating them, inverting them, and so on. Thus, the identity type is equipped with a reflexivity term, and further possesses the structure that are generated by its induction principle and by the type theory. This inductive construction of the identity type is elegant, beautifully simple, but far from trivial!\n\nThe situation where two terms can be identified in possibly more than one way is analogous to the situation in \\emph{homotopy theory}, where two points of a space can be connected by possibly more than one \\emph{path}. Indeed, for any two points $x,y$ in a space, there is a \\emph{space of paths} from $x$ to $y$. Moreover, between any two paths from $x$ to $y$ there is a space of \\emph{homotopies} between them, and so on. This leads to the homotopy interpretation of type theory, outlined in \\cref{tab:homotopy_interpretation}. The connection between homotopy theory and type theory been made precise by the construction of homotopical models of type theory, and it has led to the fruitful research area of \\emph{synthetic homotopy theory}, the subfield of \\emph{homotopy type theory} that is the topic of this course.\n\n\\begin{table}\n\\begin{center}\n\\caption{\\label{tab:homotopy_interpretation}The homotopy interpretation\\index{Homotopy interpretation}}\n\\begin{tabular}{ll}\n\\toprule\n\\emph{Type theory} &  \\emph{Homotopy theory} \\\\\n\\midrule\nTypes  & Spaces \\\\\nDependent types & Fibrations \\\\\nTerms & Points \\\\\nDependent pair type & Total space \\\\\nIdentity type & Path fibration\\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\subsection{The inductive definition of identity types}\n\n\\begin{defn}\n  Consider a type $A$ and let $a:A$. Then we define the \\define{identity type} of $A$ at $a$ as an inductive family of types $a =_A x$\\index{a = x@{$a = x$}|see {identity type}} indexed by $x:A$, of which the constructor is\\index{refl@{$\\refl{}$}}\\index{identity type!refl@{$\\refl{}$}}\n  \\begin{equation*}\n    \\refl{a}:a=_Aa.\n  \\end{equation*}\n  The induction principle of the identity type\\index{identity type!induction principle}\\index{induction principle!of the identity type} postulates that for any family of types $P(x,p)$ indexed by $x:A$ and $p:a=_A x$, there is a function\\index{path-ind@{$\\pathind$}}\\index{identity type!path-ind@{$\\pathind$}}\n  \\begin{equation*}\n    \\pathind_a:P(a,\\refl{a}) \\to \\prd{x:A}\\prd{p:a=_A x} P(x,p)\n  \\end{equation*}\n  that satisfies $\\pathind_a(p,a,\\refl{a})\\jdeq p$.\n\n  A term of type $a=_A x$ is also called an \\define{identification}\\index{identification}\\index{identity type!identification} of $a$ with $x$, and sometimes it is called a \\define{path}\\index{path}\\index{identity type!path} from $a$ to $x$.\nThe induction principle for identity types is sometimes called \\define{identification elimination}\\index{identification elimination}\\index{induction principle!identification elimination}\\index{identity type!identification elimination} or \\define{path induction}\\index{path induction}\\index{identity type!path induction}\\index{induction principle!path induction}. We also write $\\idtypevar{A}$\\index{Id A@{$\\idtypevar{A}$}|see {identity type}} for the identity type on $A$, and often we write $a=x$ for the type of identifications of $a$ with $x$, omitting reference to the ambient type $A$.\n\\end{defn}\n\n\\begin{rmk}\n  We see that the identity type is not just an inductive type, like the inductive types $\\N$, $\\emptyt$, and $\\unit$ for example, but it is and inductive \\emph{family} of types. Even though we have a type $a=_A x$ for any $x:A$, the constructor only provides a term $\\refl{a}:a=_A a$, identifying $a$ with itself. The induction principle then asserts that in order to prove something about all identifications of $a$ with some $x:A$, it suffices to prove this assertion about $\\refl{a}$ only. We will see in the next sections that this induction principle is strong enough to derive many familiar facts about equality, namely that it is a symmetric and transitive relation, and that all functions preserve equality.\n\\end{rmk}\n\n\\begin{rmk}\n  \\index{rules!identity type|(}\\index{identity type!rules|(}\n  Since the identity types require getting used to, we provide the formal rules\n  for identity types. The identity type is formed by the formation rule:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash a=_A x~\\type$}\n  \\end{prooftree}\n  The constructor of the identity type is then given by the introduction rule:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\UnaryInfC{$\\Gamma\\vdash \\refl{a}:a=_A a$}\n  \\end{prooftree}\n  The induction principle is now given by the elimination rule:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\AxiomC{$\\Gamma,x:A,p:a=_A x\\vdash P(x,p)~\\type$}\n    \\BinaryInfC{$\\Gamma\\vdash \\pathind_a:P(a,\\refl{a})\\to\\prd{x:A}\\prd{p:a=_A x}P(x,p)$}\n  \\end{prooftree}\n  And finally the computation rule is:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\AxiomC{$\\Gamma,x:A,p:a=_A x\\vdash P(x,p)~\\type$}\n    \\BinaryInfC{$\\Gamma\\vdash \\pathind_a(p,a,\\refl{a})\\jdeq p : P(a,\\refl{a})$}\n  \\end{prooftree}\n  \\index{rules!identity type|)}\\index{identity type!rules|)}\n\\end{rmk}\n\n\\begin{rmk}\n  One might wonder whether it is also possible to form the identity type at a \\emph{variable} of type $A$, rather than at a term. This is certainly possible: since we can form the identity type in \\emph{any} context, we can form the identity type at a variable $x:A$ as follows:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma,x:A\\vdash x:A$}\n    \\UnaryInfC{$\\Gamma,x:A,y:A\\vdash x=_A y~\\type$}\n  \\end{prooftree}\n  In this way we obtain the `binary' identity type. Its constructor is then also indexed by $x:A$. We have the following introduction rule\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma,x:A\\vdash x:A$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash \\refl{x}:x=_A x$}\n  \\end{prooftree}\n  and similarly we have elimination and computation rules.\n\\end{rmk}\n\n\\subsection{The groupoidal structure of types}\\label{sec:groupoid}\n\\index{groupoid laws!of identifications|(}\nWe show that identifications can be \\emph{concatenated} and \\emph{inverted}, which corresponds to the transitivity and symmetry of the identity type.\n\n\\begin{defn}\\label{defn:id_concat}\nLet $A$ be a type. We define the \\define{concatenation}\\index{concatenation!for identifications}\\index{concat@{$\\concat$}} operation\n\\begin{equation*}\n\\concat : \\prd{x,y,z:A} (\\id{x}{y})\\to(\\id{y}{z})\\to (\\id{x}{z}).\n\\end{equation*}\nWe will write $\\ct{p}{q}$ for $\\concat(p,q)$.\n\\end{defn}\n\n\\begin{constr}\nWe construct the concatenation operation by path induction. It suffices to construct\n\\begin{equation*}\n\\concat(\\refl{x}):\\prd{z:A} (x=z)\\to(x=z).\n\\end{equation*}\nHere we take $\\concat(\\refl{x})_z \\jdeq \\idfunc[(x=z)]$. \nExplicitly, the term we have constructed is\n\\begin{equation*}\n\\lam{x}\\pathind_x(\\lam{z}\\idfunc[(\\id{x}{z})]):\\prd{x,y:A} (x=y)\\to \\prd{z:A} (y=z)\\to (x=z).\n\\end{equation*}\nTo obtain a term of the asserted type we need to swap the order of the arguments $p:x=y$ and $z:A$, using \\cref{ex:swap}.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_inv}\nLet $A$ be a type. We define the \\define{inverse operation}\\index{inverse operation!for identifications}\\index{inv@{$\\invfunc$}}\n\\begin{equation*}\n\\invfunc:\\prd{x,y:A} (x=y)\\to (y=x).\n\\end{equation*}\nMost of the time we will write $p^{-1}$ for $\\invfunc(p)$.\n\\end{defn}\n\n\\begin{constr}\nWe construct the inverse operation by path induction. It suffices to construct\n\\begin{equation*}\n\\invfunc(\\refl{x}): x=x,\n\\end{equation*}\nfor any $x:A$. Here we take $\\invfunc(\\refl{x})\\defeq \\refl{x}$.\n\\end{constr}\n\nThe next question is whether the concatenation and inverting operations on paths behave as expected. More concretely, is path concatenation associative, does it satisfy the unit laws, and is the inverse of a path indeed a two-sided inverse?\n\nFor example, in the case of associativity we are asking to compare the paths\n\\begin{equation*}\n  \\ct{(\\ct{p}{q})}{r}\\qquad\\text{and}\\qquad\\ct{p}{(\\ct{q}{r})}\n\\end{equation*}\nfor any $p:x=y$, $q:y=z$, and $r:z=w$ in a type $A$. The computation rules of path induction are not strong enough to conclude that $\\ct{(\\ct{p}{q})}{r}$ and $\\ct{p}{(\\ct{q}{r})}$ are judgmentally equal. However, both $\\ct{(\\ct{p}{q})}{r}$ and $\\ct{p}{(\\ct{q}{r})}$ are terms of the same type: they are identifications of type $x=w$. Since the identity type is a type like any other, we can ask whether there is an \\emph{identification}\n\\begin{equation*}\n\\ct{(\\ct{p}{q})}{r}=\\ct{p}{(\\ct{q}{r})}.\n\\end{equation*}\nThis is a very useful idea: while it is often impossible to show that two terms of the same type are judgmentally equal, it may be the case that those two terms can be \\emph{identified}. Indeed, we identify two terms by constructing a term of the identity type, and we can use all the type theory at our disposal in order to construct such a term. In this way we can show, for example, that addition on the natural numbers or on the integers is associative and satisfies the unit laws. And indeed, here we will show that path concatenation is associative and satisfies the unit laws.\n\n\\begin{defn}\\label{defn:id_assoc}\n  Let $A$ be a type and consider three consecutive paths\n  \\begin{equation*}\n    \\begin{tikzcd}\n      x \\arrow[r,equals,\"p\"] & y \\arrow[r,equals,\"q\"] & z \\arrow[r,equals,\"r\"] & w\n    \\end{tikzcd}\n  \\end{equation*}\n  in $A$. We define the \\define{associator}\\index{associativity!of path concatenation}\n  \\begin{equation*}\n    \\assoc(p,q,r) : \\ct{(\\ct{p}{q})}{r}=\\ct{p}{(\\ct{q}{r})}.\n  \\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nBy path induction it suffices to show that\n\\begin{equation*}\n\\prd{z:A}\\prd{q:x=z}\\prd{w:A}\\prd{r:z=w} \\ct{(\\ct{\\refl{x}}{q})}{r}= \\ct{\\refl{x}}{(\\ct{q}{r})}.\n\\end{equation*}\nLet $q:x=z$ and $r:z=w$. Note that by the computation rule of the path induction principle we have a judgmental equality $\\ct{\\refl{x}}{q}\\jdeq q$. Therefore we conclude that\n\\begin{equation*}\n  \\ct{(\\ct{\\refl{x}}{q})}{r}\\jdeq \\ct{q}{r}.\n\\end{equation*}\nSimilarly we have a judgmental equality $\\ct{\\refl{x}}{(\\ct{q}{r})}\\jdeq \\ct{q}{r}$. Thus we see that the left-hand side and the right-hand side in\n\\begin{equation*}\n  \\ct{(\\ct{\\refl{x}}{q})}{r}=\\ct{\\refl{x}}{(\\ct{q}{r})}\n\\end{equation*}\nare judgmentally equal, so we can simply define $\\assoc(\\refl{x},q,r)\\defeq\\refl{\\ct{q}{r}}$.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_unit}\nLet $A$ be a type. We define the left and right \\define{unit law operations}\\index{unit law operations!for identifications}, which assigns to each $p:x=y$ the terms\\index{left unit@{$\\leftunit$}}\\index{right unit@{$\\rightunit$}}\n\\begin{align*}\n\\leftunit(p) & : \\ct{\\refl{x}}{p}=p \\\\\n\\rightunit(p) & : \\ct{p}{\\refl{y}}=p,\n\\end{align*}\nrespectively.\n\\end{defn}\n\n\\begin{constr}\nBy identification elimination it suffices to construct\n\\begin{align*}\n\\leftunit(\\refl{x}) & : \\ct{\\refl{x}}{\\refl{x}} = \\refl{x} \\\\\n\\rightunit(\\refl{x}) & : \\ct{\\refl{x}}{\\refl{x}} = \\refl{x}.\n\\end{align*}\nIn both cases we take $\\refl{\\refl{x}}$.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_invlaw}\nLet $A$ be a type. We define left and right \\define{inverse law operations}\\index{inverse law operations!for identifications}\\index{left inv@{$\\leftinv$}}\\index{right inv@{$\\rightinv$}}\n\\begin{align*}\n\\leftinv(p) & : \\ct{p^{-1}}{p} = \\refl{y} \\\\\n\\rightinv(p) & : \\ct{p}{p^{-1}} = \\refl{x}.\n\\end{align*}\n\\end{defn}\n\n\\begin{constr}\nBy identification elimination it suffices to construct\n\\begin{align*}\n\\leftinv(\\refl{x}) & : \\ct{\\refl{x}^{-1}}{\\refl{x}} = \\refl{x} \\\\\n\\rightinv(\\refl{x}) & : \\ct{\\refl{x}}{\\refl{x}^{-1}} = \\refl{x}.\n\\end{align*}\nUsing the computation rules we see that\n\\begin{equation*}\n\\ct{\\refl{x}^{-1}}{\\refl{x}}\\jdeq \\ct{\\refl{x}}{\\refl{x}}\\jdeq\\refl{x},\n\\end{equation*}\nso we define $\\leftinv(\\refl{x})\\defeq \\refl{\\refl{x}}$. Similarly it follows from the computation rules that\n\\begin{equation*}\n\\ct{\\refl{x}}{\\refl{x}^{-1}} \\jdeq \\refl{x}^{-1}\\jdeq \\refl{x}\n\\end{equation*}\nso we again define $\\rightinv(\\refl{x})\\defeq\\refl{\\refl{x}}$. \n\\end{constr}\n\n\\begin{rmk}\n  We have seen that the associator, the unit laws, and the inverse laws, are all proven by constructing an identification of identifications. And indeed, there is nothing that would stop us from considering identifications of those identifications of identifications. We can go up as far as we like in the \\emph{tower of identity types}\\index{tower of identity types}\\index{identity type!tower of identity types}, which is obtained by iteratively taking identity types.\n\n  The iterated identity types give types in homotopy type theory a very intricate structure. One important way of studying this structure is via the homotopy groups of types, a subject that we will gradually be working towards.\n\\end{rmk}\n\\index{groupoid laws!of identifications|)}\n\n\\subsection{The action on paths of functions}\n\n\\index{action on paths|(}\n\\index{identity type!action on paths|(}\nUsing the induction principle of the identity type we can show that every function preserves identifications.\nIn other words, every function sends identified terms to identified terms.\nNote that this is a form of continuity for functions in type theory: if there is a path that identifies two points $x$ and $y$ of a type $A$, then there also is a path that identifies the values $f(x)$ and $f(y)$ in the codomain of $f$. \n\n\\begin{defn}\\label{defn:ap}\nLet $f:A\\to B$ be a map. We define the \\define{action on paths}\\index{function!action on paths} of $f$ as an operation\\index{ap f@{$\\apfunc{f}$}|see {action on paths}}\n\\begin{equation*}\n\\apfunc{f} : \\prd{x,y:A} (\\id{x}{y})\\to(\\id{f(x)}{f(y)}).\n\\end{equation*}\nMoreover, there are operations\\index{ap-id@{$\\apid$}}\\index{action on paths!ap-id@{$\\apid$}}\\index{ap-comp@{$\\apcomp$}}\\index{action on paths!ap-comp@{$\\apcomp$}}\n\\begin{align*}\n\\apid_A & : \\prd{x,y:A}\\prd{p:\\id{x}{y}} \\id{p}{\\ap{\\idfunc[A]}{p}} \\\\\n\\apcomp(f,g) & : \\prd{x,y:A}\\prd{p:\\id{x}{y}} \\id{\\ap{g}{\\ap{f}{p}}}{\\ap{g\\circ f}{p}}.\n\\end{align*}\n\\end{defn}\n\n\\begin{constr}\nFirst we define $\\apfunc{f}$ by identity elimination, taking\n\\begin{equation*}\n\\apfunc{f}(\\refl{x})\\defeq \\refl{f(x)}.\n\\end{equation*}\nNext, we construct $\\apid_A$ by identity elimination, taking\n\\begin{equation*}\n\\apid_A(\\refl{x}) \\defeq \\refl{\\refl{x}}.\n\\end{equation*}\nFinally, we construct $\\apcomp(f,g)$ by identity elimination, taking\n\\begin{equation*}\n\\apcomp(f,g,\\refl{x}) \\defeq \\refl{g(f(x))}.\\qedhere\n\\end{equation*}\n\\end{constr}\n\n\\begin{defn}\\label{defn:ap-preserve}\nLet $f:A\\to B$ be a map. Then there are identifications\\index{ap-refl@{$\\aprefl$}}\\index{ap-inv@{$\\apinv$}}\\index{ap-concat@{$\\apconcat$}}\\index{action on paths!ap-refl@{$\\aprefl$}}\\index{action on paths!ap-inv@{$\\apinv$}}\\index{action on paths!ap-concat@{$\\apconcat$}}\n\\begin{align*}\n\\aprefl(f,x) & : \\id{\\ap{f}{\\refl{x}}}{\\refl{f}(x)} \\\\\n\\apinv(f,p) & : \\id{\\ap{f}{p^{-1}}}{\\ap{f}{p}^{-1}} \\\\\n\\apconcat(f,p,q) & : \\id{\\ap{f}{\\ct{p}{q}}}{\\ct{\\ap{f}{p}}{\\ap{f}{q}}}\n\\end{align*}\nfor every $p:\\id{x}{y}$ and $q:\\id{x}{y}$.\n\\end{defn}\n\n\\begin{constr}\nTo construct $\\aprefl(f,x)$ we simply observe that ${\\ap{f}{\\refl{x}}}\\jdeq {\\refl{f}(x)}$, so we take\n\\begin{equation*}\n\\aprefl(f,x)\\defeq\\refl{\\refl{f(x)}}.\n\\end{equation*}\nWe construct $\\apinv(f,p)$ by identification elimination on $p$, taking\n\\begin{equation*}\n\\apinv(f,\\refl{x}) \\defeq \\refl{\\ap{f}{\\refl{x}}}.\n\\end{equation*}\nFinally we construct $\\apconcat(f,p,q)$ by identification elimination on $p$, taking\n\\begin{equation*}\n\\apconcat(f,\\refl{x},q)  \\defeq \\refl{\\ap{f}{q}}.\\qedhere\n\\end{equation*}\n\\end{constr}\n\\index{action on paths|)}\n\\index{identity type!action on paths|)}\n\n\\subsection{Transport}\n\nDependent types also come with an action on paths: the \\emph{transport} functions.\nGiven an identification $p:\\id{x}{y}$ in the base type $A$, we can transport any term $b:B(x)$ to the fiber $B(y)$.\nThe transport functions have many applications, which we will encounter throughout this course.\n\n\\begin{defn}\nLet $A$ be a type, and let $B$ be a type family over $A$.\nWe will construct a \\define{transport}\\index{transport}\\index{family!transport}\\index{identity type!transport} operation\\index{tr B@{$\\tr_B$}}\n\\begin{equation*}\n\\tr_B:\\prd{x,y:A} (\\id{x}{y})\\to (B(x)\\to B(y)).\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nWe construct $\\tr_B(p)$ by induction on $p:x=_A y$, taking\n\\begin{equation*}\n\\tr_B(\\refl{x}) \\defeq \\idfunc[B(x)].\\qedhere\n\\end{equation*}\n\\end{constr}\n\nThus we see that type theory cannot distinguish between identified terms $x$ and $y$, because for any type family $B$ over $A$ one gets a term of $B(y)$ as soon as $B(x)$ has a term.\n\nAs an application of the transport function we construct the \\emph{dependent} action on paths\\index{dependent action on paths}\\index{dependent function!dependent action on paths} of a dependent function $f:\\prd{x:A}B(x)$. Note that for such a dependent function $f$, and an identification $p:\\id[A]{x}{y}$, it does not make sense to directly compare $f(x)$ and $f(y)$, since the type of $f(x)$ is $B(x)$ whereas the type of $f(y)$ is $B(y)$, which might not be exactly the same type. However, we can first \\emph{transport} $f(x)$ along $p$, so that we obtain the term $\\tr_B(p,f(x))$ which is of type $B(y)$. Now we can ask whether it is the case that $\\tr_B(p,f(x))=f(y)$. The dependent action on paths of $f$ establishes this identification.\n\n\\begin{defn}\\label{defn:apd}\nGiven a dependent function $f:\\prd{a:A}B(a)$ and a path $p:\\id{x}{y}$ in $A$, we construct a path\\index{apd f@{$\\apdfunc{f}$}}\n\\begin{equation*}\n\\apd{f}{p} : \\id{\\tr_B(p,f(x))}{f(y)}.\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nThe path $\\apd{f}{p}$ is constructed by path induction on $p$. Thus, it suffices to construct a path\n\\begin{equation*}\n\\apd{f}{\\refl{x}}:\\id{\\tr_B(\\refl{x},f(x))}{f(x)}.\n\\end{equation*}\nSince transporting along $\\refl{x}$ is the identity function on $B(x)$, we simply take $\\apd{f}{\\refl{x}}\\defeq\\refl{f(x)}$. \n\\end{constr}\n\n\\begin{exercises}\n\\exercise\n  \\begin{subexenum}\n  \\item State Goldbach's Conjecture\\index{Goldbach's Conjecture} in type theory.\n  \\item State the Twin Prime Conjecture\\index{Twin Prime Conjecture} in type theory.\n  \\end{subexenum}\n\\exercise \\label{ex:inv_assoc}Show that the operation inverting paths distributes over the concatenation operation, i.e., construct an identification\n  \\index{distributivity!of inv over concat@{of $\\invfunc$ over $\\concat$}}\n  \\index{identity type!distributive-inv-concat@{$\\distributiveinvconcat$}}\n  \\begin{align*}\n    \\distributiveinvconcat(p,q):\\id{(\\ct{p}{q})^{-1}}{\\ct{q^{-1}}{p^{-1}}}.\n  \\end{align*}\n  for any $p:\\id{x}{y}$ and $q:\\id{y}{z}$.\n\\exercise \\label{ex:inv_con}For any $p:x=y$, $q:y=z$, and $r:x=z$, construct maps\n  \\index{identity type!inv-con@{$\\invcon$}}\n  \\index{inv-con@{$\\invcon$}}\n  \\index{identity type!con-inv@{$\\coninv$}}\n  \\index{con-inv@{$\\coninv$}}\n  \\begin{align*}\n    \\invcon(p,q,r) & : (\\ct{p}{q}=r)\\to (q=\\ct{p^{-1}}{r}) \\\\\n    \\coninv(p,q,r) & : (\\ct{p}{q}=r)\\to (p=\\ct{r}{q^{-1}}).\n  \\end{align*}\n\\exercise Let $B$ be a type family over $A$, and consider a path $p:\\id{x}{x'}$ in $A$. Construct for any $y:B(x)$ a path\\index{lift@{$\\lift$}}\\index{identity type!lift@{$\\lift$}}\n  \\begin{equation*}\n    \\lift_B(p,y) : \\id{(x,y)}{(x',\\tr_B(p,y))}.\n  \\end{equation*}\n  In other words, a path in the \\emph{base type} $A$ \\emph{lifts} to a path in the total space $\\sm{x:A}B(x)$ for every term over the domain, analogous to the path lifting property for fibrations in homotopy theory.\n\\exercise \\label{ex:semi-ring-laws-N}In this exercise we show that the operations of addition and multiplication on the natural numbers satisfy the laws of a commutative \\define{semi-ring}.%\n  \\index{semi-ring laws!for N@{for $\\N$}}%\n  \\index{natural numbers!semi-ring laws}%\n  \\index{associativity!of addition on N@{of addition on $\\N$}}%\n  \\index{unit laws!for addition on N@{for addition on $\\N$}}%\n  \\index{commutativity!of addition on N@{of addition on $\\N$}}%\n  \\index{associativity!of multiplication on N@{of multiplication on $\\N$}}%\n  \\index{unit laws!for multiplication on N@{for multiplication on $\\N$}}%\n  \\index{commutativity!of multiplication on N@{of multiplication on $\\N$}}%\n  \\index{distributivity!of mulN over addN@{of $\\mulN$ over $\\addN$}}%\n  \\begin{subexenum}\n  \\item Show that addition satisfies the following laws:\n    \\begin{align*}\n      m+0 & = m & m+\\succN(n) & = \\succN(m+n) \\\\\n      0+m & = m & \\succN(m)+n & = \\succN(m+n).\n    \\end{align*}\n  \\item Show that addition is associative and commutative, i.e., show that we have identifications\n    \\begin{align*}\n      (m+n)+k & = m+(n+k) \\\\\n      m+n & = n+m.\n    \\end{align*}\n  \\item Show that multiplication satisfies the following laws:\n    \\begin{align*}\n      m\\cdot 0 & = 0 & m\\cdot 1 & = m & m\\cdot \\succN(n) & = m+m\\cdot n \\\\\n      0\\cdot m & = 0 & 1\\cdot m & = m & \\succN(m)\\cdot n & = m\\cdot n+n.\n    \\end{align*}\n  \\item Show that multiplication on $\\N$ is commutative:\n    \\begin{equation*}\n      m\\cdot n=n\\cdot m.\n    \\end{equation*}\n  \\item Show that multiplication on $\\N$ distributes over addition from the left and from the right, i.e., show that we have identifications\n    \\begin{align*}\n      m\\cdot (n+k) & = m\\cdot n + m\\cdot k \\\\\n      (m+n)\\cdot k & = m\\cdot k + n\\cdot k.\n    \\end{align*}\n  \\item Show that multiplication on $\\N$ is associative:\n    \\begin{align*}\n      (m\\cdot n)\\cdot k & = m\\cdot (n\\cdot k).\n    \\end{align*}\n  \\end{subexenum}\n\\exercise Consider four consecutive identifications\n  \\begin{equation*}\n    \\begin{tikzcd}\n      a \\arrow[r,equals,\"p\"] & b \\arrow[r,equals,\"q\"] & c \\arrow[r,equals,\"r\"] & d \\arrow[r,equals,\"s\"] & e\n    \\end{tikzcd}\n  \\end{equation*}\n  in a type $A$. In this exercise we will show that the \\define{Mac Lane pentagon}\\index{Mac Lane pentagon}\\index{identity type!Mac Lane pentagon} for identifications commutes.\n  \\begin{subexenum}\n  \\item Construct the five identifications $\\alpha_1,\\ldots,\\alpha_5$ in the pentagon\n    \\begin{equation*}\n      \\begin{tikzcd}[column sep=-1.5em]\n        &[-2em] \\ct{(\\ct{(\\ct{p}{q})}{r})}{s} \\arrow[rr,equals,\"\\alpha_4\"] \\arrow[dl,equals,swap,\"\\alpha_1\"] & & \\ct{(\\ct{p}{q})}{(\\ct{r}{s})} \\arrow[dr,equals,\"\\alpha_5\"] &[-2em] \\\\\n        \\ct{(\\ct{p}{(\\ct{q}{r})})}{s} \\arrow[drr,equals,swap,\"\\alpha_2\"] & & & & \\ct{p}{(\\ct{q}{(\\ct{r}{s})})}, \\\\\n        & & \\ct{p}{(\\ct{(\\ct{q}{r})}{s})} \\arrow[urr,equals,swap,\"\\alpha_3\"]\n      \\end{tikzcd}\n    \\end{equation*}\n    where $\\alpha_1$, $\\alpha_2$, and $\\alpha_3$ run counter-clockwise, and $\\alpha_4$ and $\\alpha_5$ run clockwise.\n  \\item Show that\n    \\begin{equation*}\n      \\ct{(\\ct{\\alpha_1}{\\alpha_2})}{\\alpha_3} = \\ct{\\alpha_4}{\\alpha_5}.\n    \\end{equation*}\n  \\end{subexenum}\n\\end{exercises}\n\n%\\item In this exercise we show that the action on paths of a function preserves the groupoid-structure of a type.\n%\\begin{subexenum}\n%\\item Construct an identification\n%\\begin{equation*}\n%\\mathsf{ap.assoc}(f,p,q,r)\n%\\end{equation*}\n%witnessing that the diagram\n%\\begin{equation*}\n%\\begin{tikzcd}[column sep=large]\n%\\ap{f}{\\ct{(\\ct{p}{q})}{r}} \\arrow[r,equals,\"\\ap{\\apfunc{f}}{\\assoc(p,q,r)}\"] \\arrow[d,swap,equals,\"{\\mathsf{ap.ct}(f,%\\ct{p}{q},r)}\"] & \\ap{f}{\\ct{p}{(\\ct{q}{r})}} \\arrow[d,equals,\"{\\mathsf{ap.ct}(f,p,\\ct{q}{r})}\"] \\\\ \n%\\ct{\\ap{f}{\\ct{p}{q}}}{\\ap{f}{r}} \\arrow[dd,equals,near start,\"{\\mathsf{whisk\\usc{}r}(\\mathsf{ap.ct}(f,p,q),\\ap{f}{r})}\"]   & %\\ct{\\ap{f}{p}}{\\ap{f}{\\ct{q}{r}}} \\arrow[dd,equals,swap,near end,\"{\\mathsf{whisk\\usc{}l}(\\ap{f}{p},\\mathsf{ap.ct}(f,q,r))}\"]  %\\\\\n%\\\\\n%\\ct{(\\ct{\\ap{f}{p}}{\\ap{f}{q}})}{\\ap{f}{r}} \\arrow[r,equals,swap,\"{\\assoc(\\ap{f}{p},\\ap{f}{q},\\ap{f}{r})}\"yshift=-1em] & \\ct{\\ap{f}{p}}{(\\ct{\\ap{f}{q}}{\\ap{f}{r}})}\n%\\end{tikzcd}\n%\\end{equation*}\n%commutes.\n%\\end{subexenum}\n\n\\index{identity type|)}\n\\index{inductive type!identity type|)}\n\\index{inductive type|)}\n", "meta": {"hexsha": "7aaae442f744e69c2ecd02dd0605cc4456f9c86c", "size": 25600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/identity.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/identity.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/identity.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": 58.3143507973, "max_line_length": 822, "alphanum_fraction": 0.6869921875, "num_tokens": 8509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.697080257655739}}
{"text": "% how to compile: pdflatex Template.tex. This will create a Template.pdf file.\n\\documentclass[11pt,fleqn]{article}\n\\usepackage{cite}\n\\usepackage{microtype}                  % improved microtypography\n\\usepackage[utf8]{inputenc}             % utf8 encoding\n\\usepackage{newtxtext}\n\\usepackage{newtxmath} \n\\gdef\\ttdefault{cmtt}%                                       \n\\usepackage{graphicx}                   % graphics\n\\usepackage{xcolor}                     % colors\n\\usepackage{amsmath}                    % ams math commands\n\\usepackage[margin=3cm]{geometry}       % page layout\n\\usepackage[english]{babel}             % english typographic rules\n\\usepackage{listings,xcolor}\n\\usepackage{booktabs}\n\n%----------------------------------------------\n% title page\n\\title{FEM Solver with Matlab}\n\\author{John Lian, Orginally written in April 2015}\n\n%-------------------------------------------\n\\begin{document}\n\\maketitle                              % creates title page\n\n\\section{The exercise}\n\nThis document was part of a homework assignment originally submitted for MECH 546 - Finite Element Methods in Solid Mechanics at McGill University. \nThe aim of the exercise was to build the stiffness matrix of the system depicted in Figure \\ref{fig:exercise}. The mesh was to be generated using FreeFem++ and imported into Matlab using the linear triangular T3 finite  elements and assuming plane strains and a standard steel. The external force stems from (1) the vertical gravity with $g$ = 1000 m/s\\textsuperscript{2} and (2) a constant pressure $P = 10^4$ N/m\\textsuperscript{2}.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics{exercise.png}\n    \\caption{System of interest. Distances are expressed in meters}\n    \\label{fig:exercise}\n\\end{figure}\n\n\\section{The solver and the methods} \n\nThe system depicted was meshed in FreeFem++ with, essentially, a difference between a circle and an ellipse with a cut-off on the right. The circle has a radius of $R = 13$ and the ellipse is given by \n\n\\begin{equation}\n\t\\left(\\frac{x-12}{12}\\right)^2 + \\frac{y^2}{5^2} = 1,\n\\end{equation}\n\nthus, the ellipse is described with $a = 12$ and $b = 5$. The mesh was implemented in FreeFem++ using \n\n\\begin{verbatim}\nborder aa(t=0,2*sqrt(R^2-9^2)){x=-9;y=ya-t;label=1;};\nborder bb(t=0,21){x=-9+t;y=-1*sqrt(R^2-x^2);label=2;};\nborder cc(t=0,12){x=12-t;y=-b*sqrt(1-(t/a)^2);label=3;};\nborder dd(t=0,12){x=t;y=b*sqrt(1-((t-12)/a)^2);label=4;};\nborder ee(t=0,21){x=12-t;y=sqrt(R^2-x^2);label=5;};\n\\end{verbatim}\n\nA FEM solver was then implemented in MATLAB. In order to make the implementation more efficient (fewer for loops), some \\emph{tricks} were employed. To begin, let $[T^e]$ be the triangle geometric matrix defined as \n\n\\begin{equation}\n\t[T^e] = \n\\left[\n\\begin{array}{ccc}\n1 & 1 & 1 \\\\\nx^e_1 & x^e_2 & x^e_3 \\\\\ny^e_1 & y^e_2 & y^e_3\n\\end{array}\n\\right].\n\\end{equation}\n\nThus, the area of the triangle is given as $|T^e|$. With that, the elemental stiffness matrix is given as\n\n\\begin{equation}\n\t[K^e] = \\dfrac{1}{4|T^e|}[B]^T[D][B]\n\\end{equation}\n\nfor a T3 element. It can be computed simultaneously for all indices using the fact that\n\n\\begin{equation}\n\\left[\n\\begin{array}{cc}\n\\frac{\\partial N_1^{4Q}}{\\partial x} & \\frac{\\partial N_1^{4Q}}{\\partial y} \\\\\n\\frac{\\partial N_2^{4Q}}{\\partial x} & \\frac{\\partial N_2^{4Q}}{\\partial y} \\\\\n\\frac{\\partial N_3^{4Q}}{\\partial x} & \\frac{\\partial N_3^{4Q}}{\\partial y}\n\\end{array}\n\\right]\n=\n\\left[\n\\begin{array}{ccc}\n1 & 1 & 1 \\\\\nx^e_1 & x^e_2 & x^e_3 \\\\\ny^e_1 & y^e_2 & y^e_3\n\\end{array}\n\\right]^{-1}\n\\left[\n\\begin{array}{cc}\n0 & 0 \\\\\n1 & 0 \\\\\n0 & 1\n\\end{array}\n\\right]\n= \\frac{1}{2|T^e|}\n\\left[\n\\begin{array}{ccc}\ny_2^e-y_3^e & x_3^e-x_2^e \\\\\ny_3^e-y_1^e & x_1^e-x_3^e \\\\\ny_1^e-y_2^e & x_2^e-x_1^e\n\\end{array}\n\\right]\n\\end{equation}\n\nThen, the assembly operation for the global stiffness matrix is given by\n\n\\begin{equation}\n\t[K_{ij}] = \\sum_{T \\in \\Omega} [K^e_{ij}],\n\\end{equation}\n\nwhere $T$ denotes T3 elements. \n\nUsing similar logic, the force vector is given by\n\n\\begin{equation}\n\t(F_i) = \\sum_{T \\in \\Omega} (F_{\\Omega i}^e) + \\sum_{E \\in \\partial\\Omega} (F_{\\partial \\Omega i}^e),\n\\end{equation}\n\nwhere $E$ are edges of the domain. \n\nAssuming body forces $f_{\\Omega} = (f_1, f_2)$ are given at the mesh nodes, the integral can be approximated by \n\n\\begin{equation}\n\\int_\\Omega [N^e]^T f_{\\Omega} d\\Omega = \\frac{1}{6} \n\\left|\n\\begin{array}{ccc}\nx_2^e - x_1^e & x_3^e - x_1^e \\\\\ny_2^e - y_1^e & y_3^e - y_1^e\n\\end{array}\n\\right|\nf_i(x_c,y_c), \\quad j=\\mod(i-1,2)+1\n\\end{equation}\n\nwhere $(x_c,y_c)$ is the centre of mass of the triangle $T$. With the assumption on $f$,\n\n\\begin{equation}\n\tf_j(x_s, y_s) = (f_j(x_1, y_1) + f_j(x_2, y_2) + f_j(x_3, y_3))/3,\n\\end{equation}\n\nwe can compute the body force using vectorization techniques given in \\cite{koko2007vectorized}.\n\nIntegrals involving Neumann conditions can be approximated using the value of $f_{\\partial \\Omega}$ at the centre of the edge $E$\n\n\\begin{equation}\n\t\\int_{\\partial \\Omega} [N^e]^T f_{\\partial \\Omega} d\\Omega = \\frac{1}{2} |E| g_j(x_c,y_c), \\quad j=\\mod(i-1,2)+1\n\\end{equation}\n\nwith $f_{\\partial\\Omega} = (g_1, g_2)$. Since the pressure force in this system acts normally on the edge of the domain, the external force could not be easily generalized in MATLAB. Each border was examined separately and the pressure force was applied more or less with \\emph{brute force}. Additionally, the mesh edge data needed to be extracted from the FreeFem++ .msh file deliberately. Please see the attached files.\n\nLastly, the nodal displacement can be solved by solving the linear system of equations like in Exercise 1.  The stresses and the von Mises stresses can be obtained from the displacement solution via\n\n\\begin{equation}\n\\left[\n\\begin{array}{c}\n\t\\sigma_{1}^e \\\\\n\t\\sigma_{2}^e \\\\\n\t\\sigma_{12}^e\n\\end{array}\n\\right]\n= [D][B^e](d^e)\n\\end{equation}\n\nand\n\n\\begin{equation}\n\t\\sigma_v = \\sqrt{\\sigma_1^2- \\sigma_1\\sigma_2+ \\sigma_2^2+3\\sigma_{12}^2}\n\\end{equation}\n\n\\subsection{Number of elements needed to ensure convergence in stress} \n\nA convergence of stress was sought. After trial and error, it was determined that about 33053 elements are needed for the maximum von Mises stress value to converge. Interestingly, increasing the number of elements causes the maximum von Mises stress value to fluctuate semi-randomly, but the increased computational time for each cycle prevented further analysis to be performed. Please see Table~\\ref{table:convergence} for details.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{@{}lllll@{}}\n\\toprule\nNumber of Elements & FreeFem++ $\\sigma_v$ & MATLAB $\\sigma_v$ & FreeFem++ $v$  & MATLAB $v$  \\\\ \\midrule\n220                & $4.63664\\times 10^8$     &$ 4.7143\\times 10^8$   & -0.0464092    & -0.0463    \\\\\n1393               & $7.66613\\times 10^8$     &$ 7.7227\\times 10^8$   & -0.0505296    & -0.0506    \\\\\n5592               & $1.10681\\times 10^9$     &$ 1.1077\\times 10^9$   & -0.0516523    & -0.0517    \\\\\n12541              & $1.43700\\times 10^9$     &$ 1.4367\\times 10^9$   & -0.0520871    & -0.0521    \\\\\n15018              & $1.49578\\times 10^9$     &$ 1.5015\\times 10^9$   & -0.0521518    & -0.0522    \\\\\n22486              & $1.71684\\times 10^9$     &$ 1.7169\\times 10^9$   & -0.0521216    & -0.0521    \\\\ \n33053              & $1.82630\\times 10^9$     &$ 1.8262\\times 10^9$   & -0.0523231    & -0.0523    \\\\\n\\bottomrule\n\\end{tabular}\n\\caption{Relationship between number of elements used and resulting stresses}\n\\label{table:convergence}\n\\end{table}\n\n\\subsection{Highest von Mises stress} \n\nThe highest von Mises stress is located at the bottom left corner of the system, as expected. Please see Figure~\\ref{fig:matlab}. The point is highlighted on the figure. On the FreeFem++ result it is located at the same place. Please see Figure~\\ref{fig:freefem}. \n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{freefem.eps}\n\\caption{Converged von Mises stress field superimposed over deformation visualization from FreeFem++ for 33053 elements}\n\\label{fig:freefem}\n\\end{figure}\n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{matlab.png}\n\\caption{Converged von Mises stress field superimposed over deformation visualization from MATLAB for 33053 elements}\n\\label{fig:matlab}\n\\end{figure}\n\n\\subsection{Largest displacement}\n\nThe largest displacement is located at the bottom right tip of the system, as expected. Please see Figure~\\ref{fig:matlab}. The point is highlighted on the figure. On the FreeFem++ result it is located at the same place. Please see Figure~\\ref{fig:freefem}. \n\n\\clearpage\n\n\\bibliographystyle{apalike}\n\\bibliography{references}\n\n\\end{document}", "meta": {"hexsha": "6b6386e562eb7e02cde72fcfe4243cbae2d8162d", "size": 8663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/main.tex", "max_stars_repo_name": "jlian/fem-solver", "max_stars_repo_head_hexsha": "f833dc19a78397d4061c47a3f005c9b796fd8caa", "max_stars_repo_licenses": ["MIT"], "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/main.tex", "max_issues_repo_name": "jlian/fem-solver", "max_issues_repo_head_hexsha": "f833dc19a78397d4061c47a3f005c9b796fd8caa", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "jlian/fem-solver", "max_forks_repo_head_hexsha": "f833dc19a78397d4061c47a3f005c9b796fd8caa", "max_forks_repo_licenses": ["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.8475336323, "max_line_length": 434, "alphanum_fraction": 0.6773634999, "num_tokens": 2862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6970523860618882}}
{"text": "\\documentclass[notitlepage]{simple}\n\n\\author{Matt McCarthy\\\\\\href{mailto:matthew.mccarthy.12@cnu.edu}{matthew.mccarthy.12@cnu.edu}}\n\\title{Derivatives of Arctan at 0}\n\\date{Februrary, 2016}\n\n\\begin{document}\n\\maketitle\n\n\\section{Statement of Problem}\n\nDefine $f(x):=\\arctan x$.\nFind $f^{(n)}(0)$.\n\n\\section{Background}\n\nFor this problem we will need two theorems.\nFirstly, we need Taylor's Theorem.\n\\begin{thm}[Taylor's Theorem on a disk in $\\CC$]\\label{t-thm}\n\tLet $f:\\CC\\rightarrow\\CC$ be analytic on a disk of radius $r$ about $z_0$.\n\tThen there exists a unique power series such that\n\t\\[\n\t\tf(z)=\\sum_{k=0}^\\infty \\frac{f^{(k)}(z_0)}{k!}(z-z_0)^k\n\t\\]\n\tfor all $z$ such that $|z-z_0|<r$.\n\\end{thm}\nFurthermore, we need an additional Taylor expansion.\n\\begin{thm}\\label{t-exp}\n\tDefine\n\t\\[\n\t\tf(z):=\\frac{1}{1-z}.\n\t\\]\n\tThen,\n\t\\[\n\t\tf(z)=\\sum_{k=0}^\\infty z^k\n\t\\]\n\tfor any $z\\in\\CC$ with $|z|<1$.\n\\end{thm}\n\n\\section{Solution}\n\nDefine $g(x):=f'(x)$.\nWe know that\n\\[\n\tg(x)=f'(x)=\\frac{1}{1+x^2} = \\frac{1}{1-(-x^2)}.\n\\]\nFrom here we can invoke \\autoref{t-exp} to get\n\\[\n\tg(x) = \\sum_{n=0}^\\infty (-x^2)^n = \\sum_{n=0}^\\infty (-1)^n (x-0)^{2n}.\n\\]\nFurthermore, we know that this power series representation is unique by \\autoref{t-thm}.\nThus,\n\\[\n\tg(x)=\\sum_{n=0}^\\infty \\frac{g^{(n)}(0)}{n!}(x-0)^n=\\sum_{n=0}^\\infty (-1)^n (x-0)^{2n}.\n\\]\nUsing \\autoref{t-thm}, we notice that $g^{(2n+1)}(0)=0$ since no odd terms appead in the Taylor expansion.\nMoreover, by \\autoref{t-thm} we get\n\\[\n\t\\frac{g^{(2n)}(0)}{(2n)!}=(-1)^n.\n\\]\nTherefore, $g^{(2n)}(0)=(-1)^n(2n)!$.\nHowever, by definition of $g=f'$, we have $f^{(2n+2)}(0)=0$ and $f^{(2n+1)}(0)=(-1)^n(2n)!$.\n\\end{document}\n", "meta": {"hexsha": "dcb07d5210f910bc7effb2a1efdc97854d079c0a", "size": 1664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-spring/derivatives-of-arctan-at-zero/arctan.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/derivatives-of-arctan-at-zero/arctan.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/derivatives-of-arctan-at-zero/arctan.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": 26.0, "max_line_length": 106, "alphanum_fraction": 0.6189903846, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587668, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.696885706377098}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS671: Machine Learning\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nDetermine the interior, closure and border of the following sets:\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $S_1 = \\{x \\in \\mathbb{R}^2 | x_1^2 + x_2^2 \\leqslant 1, x_2 > 1 \\}$\n\n\\item $S_2 = \\{x \\in \\mathbb{R}^2 | x_1^2 + x_2^2 \\leqslant 1, x_1 + x_2 = 1.4 \\}$\n\n\\item $S_3 = \\{x \\in \\mathbb{R}^2 | x_1^2 + x_2^2 \\leqslant 1, x_1 + x_2 = 1.5 \\} $\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Set $S_1$ can be represented as the intersection of two sets $S_{\\text{sub}_1} = \\{x \\in \\mathbb{R}^2 | x_1^2 + x_2^2 \\leqslant 1 \\}$ and $S_{\\textbf{sub}_2} = \\{x \\in \\mathbb{R}^2 | x_2 > 1 \\}$.\nSuppose $x_0(t_1, t_2) \\in S_{\\textbf{sub}_2}$.\nThis means $t_2 > 1$ and therefore $t_2^2 > 1$.\nHence, regardless of the choice of $t_1$, $t_1^2 + t_2^2 > 1$ and therefore $x_0 \\notin S_{\\textbf{sub}_1}$.\nConsequently, $S_1 = S_{\\text{sub}_1} \\cap S_{\\text{sub}_2} = \\emptyset$.\nTherefore, $K(S) = I(S) = \\partial S = \\emptyset$.\n\n\\item Set $S_2$ can be represented as the intersection of two sets $S_{\\text{sub}_1} = \\{x \\in \\mathbb{R}^2 | x_1^2 + x_2^2 \\leqslant 1 \\}$ (which represents closure of a circle) and $S_{\\textbf{sub}_2} = \\{x \\in \\mathbb{R}^2 | x_1 + x_2 = 1.4\\}$ which is a line.\nFigure \\ref{fig11} shows how the two sets intersect.\nWe first obtain the points where the circle and line intersect by solving Eq. \\ref{eq11} for $x_1$ and $x_2$.\n\n\\begin{equation}\n\\left\\{ \\begin{array}{ll} x_1^2 + x_2^2 = 1 \\\\ x_1 + x_2 = 1.4 \\end{array} \\right.\n\\label{eq11}\n\\end{equation}\n\nEq. \\ref{eq11} translates to $2x_2^2 - 2.8x_2 + 0.96 = 0$ and yields to $x = (0.6, 0.8)$ and $x = (0.8, 0.6)$.\nTherefore the set $S$ is the set of points on the closed segment $[(0.6,0.8),(0.8,0.6)]$.\n\nAs the endpoints of the line segment are included in $S$, $S$ is closed in $\\mathbb{R}^2$, therefore, $K(S) = S$.\nAs well, because $S$ is a line segment in $\\mathbb{R}^2$, its interior is $S - \\{(0.6,0.8),(0.8,0.6)\\}$ and its boundary is $S$.\n\n\\begin{figure}[H]\\centering\n\\begin{tikzpicture}\n\\draw [thick] (0,0) circle (1cm);\n\\draw [thick] (0,1.4) coordinate (a_1) -- (1.4,0) coordinate (a_2);\n\\draw [->,thick] (0,-1.5) -- (0,2) node (yaxis) [above] {y};\n\\draw [->,thick] (-1.5, 0) -- (2, 0) node (xaxis) [right] {x};\n\\fill[black] (a_1) circle (2pt) node[left] {$(0, 1.4)$};\n\\fill[black] (a_2) circle (2pt) node[below right] {$(1.4, 0)$};\n\\fill[black] (0.6,0.8) circle (2pt) node[above right] {$(0.6, 0.8)$};\n\\fill[black] (0.8,0.6) circle (2pt) node[right] {$(0.8, 0.6)$};\n\\end{tikzpicture}\n\\caption{Intersection of $S_{\\text{sub}_1}$ and $S_{\\text{sub}_2}$}\\label{fig11}\n\\end{figure}\n\n\\item Set $S_2$ can be represented as the intersection of two sets $S_{\\text{sub}_1} = \\{x \\in \\mathbb{R}^2 | x_1^2 + x_2^2 \\leqslant 1 \\}$ (which represents closure of a circle) and $S_{\\textbf{sub}_2} = \\{x \\in \\mathbb{R}^2 | x_1 + x_2 = 1.5\\}$ which is a line.\nThe two sets are shown in Figure \\ref{fig12}.\nAs is shown, the two sets do not intersect which means $S_1 = S_{\\text{sub}_1} \\cap S_{\\text{sub}_2} = \\emptyset$.\nTherefore, $K(S) = I(S) = \\partial S = \\emptyset$.\n\n\\begin{figure}[H]\\centering\n\\begin{tikzpicture}\n\\draw [thick] (0,0) circle (1cm);\n\\draw [thick] (0,1.5) coordinate (a_1) -- (1.5,0) coordinate (a_2);\n\\draw [->,thick] (0,-1.5) -- (0,2) node (yaxis) [above] {y};\n\\draw [->,thick] (-1.5, 0) -- (2, 0) node (xaxis) [right] {x};\n\\fill[black] (a_1) circle (2pt) node[left] {$(0, 1.5)$};\n\\fill[black] (a_2) circle (2pt) node[below right] {$(1.5, 0)$};\n\\end{tikzpicture}\n\\caption{$S_{\\text{sub}_1}$ and $S_{\\text{sub}_2}$}\\label{fig12}\n\\end{figure}\n\nWe can as well mathematically support our deduction by showing no real solution exists for the following equation.\n\n\\begin{equation}\n\\left\\{ \\begin{array}{ll} x_1^2 + x_2^2 = 1 \\\\ x_1 + x_2 = 1.5 \\end{array} \\right.\n\\label{eq12}\n\\end{equation}\n\nEq. \\ref{eq12} translates to $2x_2^2 - 3x_2 + 1.25 = 0$ and yields to $x_2 = 0.75 + 0.25j$ and $x_2 = 0.75 - 0.25j$ which shows the two sets never intersect.\n\n\\end{enumerate}\n", "meta": {"hexsha": "47b7dacb257a008eb3fa92eb97b8161194aef9d4", "size": 4359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 50.6860465116, "max_line_length": 263, "alphanum_fraction": 0.6152787337, "num_tokens": 1851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6968856995243188}}
{"text": "\\documentclass{amsart}\n\\usepackage{amsaddr}\n\\usepackage[style=numeric,backend=biber]{biblatex}\n\\addbibresource{../sources.bib}\n\n\\input{../packages.tex}\n\\input{../commands.tex}\n\n\\numberwithin{equation}{section}\n\n\\graphicspath{{figures/}}\n\n\\begin{document}\n\n\\title{Fast Simulation of Multistage Clonal Expansion Models}\n\n%    Remove any unused author tags.\n\n%    author one information\n\\author{Lukas K\\\"ostler}\n\\email{lukas.koestler@tum.de}\n\\address{Technical University of Munich (TUM)}\n\n\n%\\keywords{Multistage Clonal Expansion, Filtered Poisson process}\n\n\\date{\\today}\n\n\n\\begin{abstract}\nWe derive and demonstrate a method to simulate Multistage Clonal Expansion (MSCE) models. The method is faster than previous ones while retaining similar accuracy.\n\\end{abstract}\n\n\\maketitle\n\n\n\\section{Derivation}\n\n\\subsection{Poisson process with random start time}\nWe will consider a non-homogeneous Poisson process with rate $\\lambda\\br{t} > 0$ which has a random start time $\\tau \\geq 0$ with distribution $p$. For fixed $\\tau$ the number of occurrences at time $t \\geq \\tau$ given start time $\\tau$, $N\\br{t} \\vert \\tau$ has the characteristic function \\cite[chapter 4, eqn. (2.1)]{parzen1962stochastic}\n\\begin{align}\\label{eqn:nonhompoisson}\n\\begin{split}\n\\varphi_{N\\br{t} \\vert \\tau}\\br{u} &= \\exp\\brr{m\\br{t - \\tau} \\left\\{e^{i u} - 1\\right\\}} \\\\\nm\\br{t} &= \\int_0^t \\lambda\\br{s} \\ds \\, .\n\\end{split}\n\\end{align}\nThe by the law of total expectation, the characteristic function of $N\\br{t}$ is given by\n\\begin{align*}\n\\varphi_{N\\br{t}}\\br{u} &= \\E{\\varphi_{N\\br{t} \\vert \\tau}\\br{u}} \\\\\n&=\\int_0^t \\exp\\brr{m\\br{t - \\tau} \\left\\{e^{i u} - 1\\right\\}} p \\br{\\tau} \\, \\dtau + \\int_t^\\infty p \\br{\\tau} \\, \\dtau \\, .\n\\end{align*}\nComparing this expression to a Poisson process with different rate yields the first theorem.\n\\begin{theorem}\\label{thm:iteratedpoisson}\nLet $N\\br{t}$ follow a non-homogeneous Poisson process with rate $\\lambda\\br{t} \\geq 0$ starting at a random time $\\tau \\geq 0$ with probability density function $p\\br{\\tau}$. Let $M\\br{t}$ follow a non-homogeneous Poisson process starting at time $0$ with rate\n\\begin{equation}\n\\nu\\br{t} = \\int_0^t\\lambda\\br{t-\\tau} p\\br{\\tau} \\ds = \\br{\\lambda \\ast p}\\br{t} \\ .\n\\end{equation}\nThen, for the characteristic functions $\\varphi_{N\\br{t}}$ and $\\varphi_{M\\br{t}}$ there holds\n\\begin{equation}\n\\max_{t \\in \\brr{0, \\sigma}} \\fabs{\\varphi_{N\\br{t}} - \\varphi_{M\\br{t}}}\n\\leq 2 \\br{\\fexp{2 m\\br{\\sigma}} - 2m\\br{\\sigma} - 1}\n= O (m\\br{\\sigma}^2) \\,\n\\end{equation}\nwhere $m$ is the mean value function of $N\\br{t}$ as defined in eqn. \\eqref{eqn:nonhompoisson}.\n\\end{theorem}\n\\begin{proof}\nLet $h$ be the mean value function (eqn. \\eqref{eqn:nonhompoisson}) of $M\\br{t}$, then there holds\n\\begin{align*}\n\\frac{d}{dt} \\int_0^t m\\br{t - \\tau} p\\br{\\tau} \\dtau = \\int_0^t m'\\br{t - \\tau} p \\br{\\tau} \\dtau = \\int_0^t\\lambda\\br{t-\\tau} p\\br{\\tau} \\dtau = \\frac{d}{dt} \\nu\\br{t} \\, .\n\\end{align*}\nWe used the Leibniz integration rule and $m\\br{0} = 0$ in the first step. Because $h\\br{0} = 0$ has to hold, we get\n\\begin{equation*}\nh\\br{t} = \\int_0^t m\\br{t - \\tau} p\\br{\\tau} \\dtau = \\br{m \\ast p}\\br{t}\n\\end{equation*}\\\\\n\n\\noindent For $\\varphi_{N\\br{t}}\\br{u}$, using $k := \\left\\{e^{i u} - 1\\right\\}$, we obtain\n\\begin{align*}\n\\varphi_{N\\br{t}}\\br{u}\n&=\\int_0^t \\exp\\brr{m\\br{t - \\tau} k} p \\br{\\tau} \\, \\dtau + \\int_t^\\infty p \\br{\\tau} \\, \\dtau \\\\\n&= 1 + k \\int_0^t m\\br{t - \\tau} p \\br{\\tau} \\, \\dtau + \\sum_{j=2}^\\infty \\frac{k^j}{j!} \\int_0^t m\\br{t - \\tau}^j p \\br{\\tau} \\, \\dtau \\, .\n\\end{align*}\\\\\n\n\\noindent For $\\varphi_{M\\br{t}}\\br{u}$ we obtain\n\\begin{align*}\n\\varphi_{M\\br{t}}\\br{u}\n&= \\fexp{h\\br{t} k}\n= 1 + k h\\br{t} + \\sum_{j=2}^\\infty \\frac{k^j}{j!} h\\br{t}^j \\, .\n\\end{align*}\\\\\n\n\\noindent Let $t \\in \\brr{0, \\sigma}$ then there holds\n\\begin{align*}\n\\fabs{\\varphi_{N\\br{t}} - \\varphi_{M\\br{t}}}\n&= \\Big \\vert \\sum_{j=2}^\\infty \\frac{k^j}{j!} \\int_0^t m\\br{t - \\tau}^j p \\br{\\tau} \\, \\dtau - \\sum_{j=2}^\\infty \\frac{k^j}{j!} h\\br{t}^j \\Big \\vert \\\\\n&\\leq \\sum_{j=2}^\\infty \\frac{\\fabs{k}^j}{j!} \\Big\\vert \\int_0^t m\\br{t - \\tau}^j p \\br{\\tau} \\, \\dtau - \\br{ \\int_0^t m\\br{t - \\tau} p \\br{\\tau} \\, \\dtau }^j \\Big\\vert \\\\\n&\\leq \\sum_{j=2}^\\infty \\frac{\\fabs{k}^j}{j!} \\br{\\fabs{m\\br{\\sigma}}^j + \\fabs{m\\br{\\sigma}}^j} \\\\\n&=2 \\sum_{j=2}^\\infty \\frac{\\br{2 m\\br{\\sigma}}^j}{j!}\\\\\n&=2 \\br{\\fexp{2 m\\br{\\sigma}} - 2m\\br{\\sigma} - 1} \\, .\n\\end{align*}\nWe used that $\\int_0^t p\\br{\\tau} \\dtau = 1$ and that $m\\br{\\cdot}$ is positive and monotonically increasing.\n\\end{proof}\n\n\\begin{remark}\n\\autoref{thm:iteratedpoisson} is useful if $m\\br{\\sigma} \\ll 1$ because it then implies that a Poisson process with random start time can be viewed (and simulated) as a Poisson process with rate $h = \\br{m \\ast p}$. This makes intuitive sense, because if $m\\br{\\sigma}$, i.e. the expected number of occurrences for $N\\br{\\sigma}$ starting at $0$, is much smaller than $1$ the correlation that is introduced through the random starting time is negligible.\\\\\n\n\\noindent The formulas for the mean and the variance are\n\\begin{align*}\n\\E{N\\br{\\sigma}} &= h\\br{\\sigma} \\, ,\\\\\n\\E{M\\br{\\sigma}} &= h\\br{\\sigma} \\, ,\\\\\nVar\\br{N\\br{\\sigma}} &= h\\br{\\sigma} + \\int_0^\\sigma m^2\\br{t-\\tau} p\\br{\\tau} \\dtau - \\br{\\int_0^\\sigma m\\br{t-\\tau} p\\br{\\tau} \\dtau}^2 \\, , \\\\\nVar\\br{M\\br{\\sigma}} &= h\\br{\\sigma} \\, .\n\\end{align*}\nWhile the mean is consistent, the difference in variance is of second order in $m$.\n\\end{remark}\n\n\n\n\\subsection{Two Stage Poisson Process}\nWe will consider a two stage Poisson process. The first process has rate $\\nu\\br{t}$ and each occurrence of the first process is the starting point of a second-stage process with rate $\\lambda\\br{t}$. We are interested in the number $N\\br{t}$ of occurrences from the first process and the arrival times of the second-stage processes. It is vital that we do not need the arrival times of the first process.\n\n\\begin{theorem}\\label{thm:twostagepoisson}\nLet $N\\br{t}$ be the number of occurrences of a non-homogeneous Poisson process with rate $\\nu\\br{t}$, mean value function $\\eta\\br{t}$ starting at time $0$. Let $u_1, \\dots, u_{N\\br{t}}$ denote the arrival times of this process.\n\nFor each $j = 1, \\dots, N\\br{t}$ let $Y\\br{t, u_j}$ denote the number of occurrences of a non-homogeneous Poisson process with rate $\\lambda\\br{t}$, mean value function $m\\br{t}$ starting at time $u_j$.\n\nThe process\n\\[\n    Y\\br{t} = \\sum_{j=1}^{N\\br{t}} Y\\br{t, u_j}\n\\]{}\nis called a filtered Poisson process \\cite[chapter 4, eqn. (5.42)]{parzen1962stochastic}.\nFor $t \\in \\brr{0, \\sigma}$, if we neglect terms of order $O(m\\br{\\sigma}^2)$, there holds:\n\n\\begin{enumerate}\n% \\item[i)] The process $Y\\br{t}$ is a Poisson process with rate\n% \\[\n%     \\mu\\br{t} = \\br{\\nu \\ast \\lambda}\\br{t} \\, .\n% \\]\n\\item[i)] Conditioned on $N\\br{\\sigma}$ the process $Y\\br{t}$ follows a Poisson process with rate\n\\[\n    \\mu_{N}\\br{t} = \\frac{N\\br{\\sigma}}{\\eta\\br{\\sigma}} \\br{\\nu \\ast \\lambda}\\br{t} \\qquad \\forall t \\in \\brr{0, \\sigma} \\, .\n\\]\n\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\nBy Proposition 2.206 in \\cite[p. 147]{intro2015Stoch} (\\emph{actually this only guarantees the property for a homogeneous process. I am quite certain that this also holds for the non-homogeneous case but I am lacking a source.}) we have that conditioned on $N\\br{\\sigma}$ the distribution for $u_j$ (note that the $u_j$ are not ordered) is given by $p\\br{u} = \\nu\\br{u} / \\eta\\br{\\sigma}$ and all $u_j$ are i.i.d.. Then we know by \\autoref{thm:iteratedpoisson} that $Y\\br{t, u_j}$ can be approximated up to order $2$ by a Poisson process with rate\n\\begin{equation*}\n\\mu_j\\br{t} = \\int_0^t\\lambda\\br{t-u} \\frac{\\nu\\br{u}}{\\eta\\br{\\sigma}} \\mathrm{d}u = \\frac{\\br{\\lambda \\ast \\nu}}{\\eta\\br{\\sigma}} \\br{t} \\qquad \\forall t \\in \\brr{0, \\sigma} \\, .\n\\end{equation*}\nBecause the sum of $N\\br{\\sigma}$ independent Poisson process is again a Poisson process, we know that $Y\\br{t}$ can be approximated up to order $2$ by a Poisson process with rate\n\\[\n    \\mu_{N}\\br{t} = \\frac{N\\br{\\sigma}}{\\eta\\br{\\sigma}} \\br{\\nu \\ast \\lambda}\\br{t} \\, .\n\\]{}\n\\end{proof}\n\\begin{remark}\n\\autoref{thm:twostagepoisson} is useful if $m\\br{\\sigma} \\ll 1$ because it then implies that a two stage Poisson process can be simulated as follows. a) Draw $N\\br{\\sigma}$ at random from a Poisson distribution with mean $\\eta\\br{\\sigma}$. b) Simulate a Poisson process with rate\n\\[\n\\frac{N\\br{\\sigma}}{\\eta\\br{\\sigma}} \\br{\\nu \\ast \\lambda}\\br{t} \\, .\n\\]\nThe direct solution would be to simulate the first Poisson process fully and obtain arrival times $u_j$. For each arrival time one would simulate a Poisson process with rate $\\lambda\\br{t-u_j}$. This means on average $\\eta\\br{\\sigma}$ many Poisson process simulations. The method proposed here can, under the circumstances described, generate a very good approximation with only two Poisson process simulations. This advantage comes from marginalizing out (approximately) the arrival times $u_j$.\\\\\n\n\\noindent For the Colorectal cancer model from \\cite{jeon2008evaluation} the first rate is of order $10^2$, $\\sigma=50$ and the second rate is of order $10^{-6}$. The direct approach results in approximately $5000$ Poisson process simulations. The approximate method yields a theoretic speedup factor of 1000. Also $m\\br{\\sigma} \\approx 10^{-4}$ and thus the approximation is extremely accurate.\n\\end{remark}\n\n\n\\newpage\n\\section{Numerical Experiments}\nIn this section we present numerical experiments for all theorems presented in this paper.\n\n\\subsection{Poisson process with random start time}\n\\label{sec:numPoissProcOne}\nIn Figure \\ref{fig:numPoissProcOne} the model as described in \\autoref{thm:iteratedpoisson} is simulated with a sample size of $10^7$. For $\\lambda = 10^{-2}$ the approximation is already very accurate. The relative error in variance is $\\lambda/6 \\approx 1.7 \\times 10^{-3}$ for $\\lambda = 10^{-2}$.\n\\begin{figure}[ht]\n    \\centering\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc01_0_1.eps}\n        \\caption{$\\lambda \\equiv 1$}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc01_0_2.eps}\n        \\caption{$\\lambda \\equiv 1$. Log-Scale.}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc01_1_1.eps}\n        \\caption{$\\lambda \\equiv 10^{-1}$.}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc01_1_2.eps}\n        \\caption{$\\lambda \\equiv 10^{-1}$. Log-Scale.}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc01_2_1.eps}\n        \\caption{$\\lambda \\equiv 10^{-2}$.}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc01_2_2.eps}\n        \\caption{$\\lambda \\equiv 10^{-2}$. Log-Scale.}\n    \\end{subfigure}\n    \\caption{$10^7$ samples. $\\sigma = 1$. $\\tau \\sim \\text{unif}\\br{0,1}$. For this example there holds $\\E{N} = \\lambda / 2$ and $Var\\br{N} = \\lambda/2 + \\lambda^2/12$. The blue histogram represents the values from the direct simulation with $10^7$ samples, i.e. the \"ground truth\". The red line is a Poisson distribution with parameter $\\E{M} = \\lambda / 2$, i.e. the approximation. Because the approximation is just a Poisson process, the distribution of $M$ is Poisson and can be obtained without sampling.}\n    \\label{fig:numPoissProcOne}\n\\end{figure}\n\n\n\\subsection{Two Stage Poisson Process}\\label{sec:numPoissProcTwo}\nWe consider a two-stage Poisson process with homogeneous rates, i.e. $\\nu\\br{t} \\equiv 10^3$, $\\lambda\\br{t} \\equiv 10^{-3}$. We choose $\\sigma = 2$.\\\\\n\n\\noindent Because the two-stage Poisson process is a filtered Poisson process, we can use the formulas from \\cite[chapter 4, eqn. (5.43)--(5.45)]{parzen1962stochastic} to analytically calculate the mean and variance of the true process $N$. For the approximation $M$ we use the law of total expectation and obtain\n\\begin{align}\\label{eqn:numPoissProcTwoEVar}\n\\begin{split}\n\\E{N\\br{\\sigma}} &= \\frac{\\nu \\lambda \\sigma^2}{2} \\,, \\\\\nVar\\br{N\\br{\\sigma}} &= \\frac{\\nu \\lambda \\sigma^2}{2} \\br{1 + \\frac{2 \\sigma \\lambda}{3}} \\,, \\\\\n\\E{M\\br{\\sigma}} &= \\frac{\\nu \\lambda \\sigma^2}{2} \\,,\\\\\nVar\\br{M\\br{\\sigma}} &= \\frac{\\nu \\lambda \\sigma^2}{2} \\br{1 + \\frac{\\sigma \\lambda}{2}} \\, .\n\\end{split}\n\\end{align}\nThe relative error in variance is thus $\\frac{\\sigma \\lambda}{6} \\approx 0.8 \\%$. The results for the sampling the real and approximate process with $10^6$ samples are shown in \\autoref{tab:numPoissProcTwo} and \\autoref{fig:numPoissProcTwo}.\\\\\n\n\\noindent If we would have used a normal Poisson process as approximation, the variance would be exactly the mean and the relative error in Variance would be $\\sigma \\lambda$, i.e. six times higher. More significant would be that by direct simulation we would not obtain the number of occurrences in the intermediate stage, which is needed for further computation.\\\\\n\n\\noindent The runtime\\footnote{This experiment was carried out on one core of a Intel Xeon X5680 at 3.33GHz that was launched in 2010.} is approximately $4.8 \\times 10^{-4}$ seconds per sample for the direct method and $1.4 \\times 10^{-6}$ seconds per sample for the approximate method. This is a speed up by a factor of ca. 100. It should be noted that for this experiment only the number of occurrences $N$ was computed and not their arrival times, therefore the speedup is probably even more substantial for the real simulation.\\\\\n\n\\noindent From \\autoref{eqn:numPoissProcTwoEVar} it can be seen that by simulating the approximation with $\\hat{\\nu} = \\frac{3}{4} \\nu$ and $\\hat{\\lambda} = \\frac{4}{3} \\lambda$ mean and variance of the approximation will be correct. The numerical experiments (\\autoref{tab:numPoissProcTwoChnaged} and \\autoref{fig:numPoissProcTwo}) indicate that the effect of this change is small.\n\n\\begin{table}\n    \\begin{tabular}{ |c|c|r|r| }\n    \\hline\n    \\textbf{Statistic} & \\textbf{Approximation} & \\textbf{Type} & \\textbf{Value}\\\\\n    \\hline\\hline\n    \\input{tables/poissproc02.tex}\n    \\hline\n    \\end{tabular}\n    \\caption{Two stage Poisson process with $\\nu \\equiv 10^3$, $\\lambda \\equiv 10^{-3}$, $\\sigma = 2$ and a total of $10^6$ samples.}\n    \\label{tab:numPoissProcTwo}\n\\end{table}\n\n\\begin{table}\n    \\begin{tabular}{ |c|c|r|r| }\n    \\hline\n    \\textbf{Statistic} & \\textbf{Approximation} & \\textbf{Type} & \\textbf{Value}\\\\\n    \\hline\\hline\n    \\input{tables/poissproc02_changed.tex}\n    \\hline\n    \\end{tabular}\n    \\caption{Two stage Poisson process with $\\nu \\equiv 10^3$, $\\lambda \\equiv 10^{-3}$, $\\sigma = 2$ and a total of $10^6$ samples. For the approximate simulation $\\hat{\\nu} = \\frac{3}{4} \\nu$ and $\\hat{\\lambda} = \\frac{4}{3} \\lambda$ were used. Therefore, the analytic mean and variance are identical for direct and approximate simulation.}\n    \\label{tab:numPoissProcTwoChnaged}\n\\end{table}\n\n\\begin{figure}[ht]\n    \\centering\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc02_1.eps}\n        \\caption{Bar-chart for the number of occurrences.}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc02_2.eps}\n        \\caption{Bar-chart for the number of occurrences. Log-Scale.}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc02_changed_1.eps}\n        \\caption{Bar-chart for the number of occurrences. $\\hat{\\nu} = \\frac{3}{4} \\nu$ and $\\hat{\\lambda} = \\frac{4}{3} \\lambda$.}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[t]{0.475\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{poissproc02_changed_2.eps}\n        \\caption{Bar-chart for the number of occurrences. $\\hat{\\nu} = \\frac{3}{4} \\nu$ and $\\hat{\\lambda} = \\frac{4}{3} \\lambda$. Log-Scale.}\n    \\end{subfigure}\n    \\caption{Two stage Poisson process with $\\nu \\equiv 10^3$, $\\lambda \\equiv 10^{-3}$. For the direct simulation $\\nu$, $\\lambda$ were used. For the approximate simulation $\\nu$, $\\lambda$ were used in (A) and (B) and $\\hat{\\nu} = \\frac{3}{4} \\nu$ and $\\hat{\\lambda} = \\frac{4}{3} \\lambda$ were used for (C) and (D). $\\sigma = 2$ and a total of $10^6$ samples was used.}\n    \\label{fig:numPoissProcTwo}\n\\end{figure}\n\n\\clearpage\n\\printbibliography\n\\end{document}\n", "meta": {"hexsha": "cf8473a2e36679c1abcb19863214fe0e11b297a0", "size": 16701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/paper/paper.tex", "max_stars_repo_name": "lkskstlr/msce", "max_stars_repo_head_hexsha": "feb20a1648b119caea97ba8e2d56d8adf5a77d94", "max_stars_repo_licenses": ["MIT"], "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/paper/paper.tex", "max_issues_repo_name": "lkskstlr/msce", "max_issues_repo_head_hexsha": "feb20a1648b119caea97ba8e2d56d8adf5a77d94", "max_issues_repo_licenses": ["MIT"], "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/paper/paper.tex", "max_forks_repo_name": "lkskstlr/msce", "max_forks_repo_head_hexsha": "feb20a1648b119caea97ba8e2d56d8adf5a77d94", "max_forks_repo_licenses": ["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.7889273356, "max_line_length": 547, "alphanum_fraction": 0.6787018741, "num_tokens": 5736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.6968856982749565}}
{"text": "\\section{$\\bigotimes$}\nWelcome to algebraic topology! This is family weekend, so welcome. Today'll be more about algebra, and there'll be very little topology, I'm afraid. Today'll be about tensor products. I got your permission to talk about modules over a commutative ring. We're always going to let $R$ be a commutative ring (they're going to be simple; for example, $\\QQ,\\FF_p,\\Z,\\Z/n\\Z,\\cdots,\\text{PIDs}$).\n\nI want to tell you that the category of $R$-modules is what's called a ``categorical ring'', where the addition corresponds to the direct sum, the zero element is the zero module, $1$ is $R$ itself, and multiplication is where you put a circle around a multiplication symbol.\n\nThe reason we do this is because of bilinear maps. Let me recall the definition of a bilinear map.\n\\begin{definition}\nIf I have $M,N,P$ are $R$-modules, then a bilinear (or if you want to be annoying, $R$-bilinear) map is a map $\\beta:M\\times N\\to P$ such that $\\beta(x+x^\\prime,y)=\\beta(x,y)+\\beta(x^\\prime,y)$ and $\\beta(x,y+y^\\prime)=\\beta(x,y)+\\beta(x,y^\\prime)$, and such that $\\beta(rx,y)=r\\beta(x,y)$ and $\\beta(x,ry)=r\\beta(x,y)$.\n\\end{definition}\n\\begin{example}\n$\\RR^n\\times\\RR^n\\to\\RR$ given by the dot product is a $\\RR$-bilinear map. The cross product $\\RR^3\\times\\RR^3\\to\\RR$ is $\\RR$-bilinear. More generally, if $R$ is a ring then the multiplication $R\\times R\\to R$ is $R$-bilinear, and the multiplication on an $R$-module $M$ given by $R\\times M\\to M$ is $R$-bilinear. This enters into topology because the map $ H_n(X;R)\\times H_n(Y;R)\\xrightarrow{\\times} H_{m+n}(X\\times Y;R)$ is $R$-bilinear.\n\\end{example}\nWouldn't it be great to reduce stuff about bilinear maps to linear maps? We're going to do this by means of the universal property.\n\\begin{definition}\nLet $M,N$ be $R$-modules. A \\emph{tensor product} of $M,N$ is a $R$-module $P$ and a bilinear map $M\\times N\\xrightarrow{\\beta_0}P$ such that for every bilinear map $M\\times N\\xrightarrow{\\beta}Q$ there is a unique factorization.\n\\begin{equation*}\n\\xymatrix{M\\times N\\ar[r]^{\\beta_0}\\ar[dr]^\\beta & P\\ar@{-->}[d]^f\\\\\n & Q}\n\\end{equation*}\nthrough an $R$-module homomorphism $f$. It's easy to check that $f\\circ\\beta_0$ is bilinear.\n\\end{definition}\nSo $\\beta_0$ is universal bilinear map out of $M\\times N$. Instead of $\\beta_0$ we're going to write $M\\times N\\xrightarrow{\\otimes}P$. This means that $\\beta(x,y)=f(x\\otimes y)$ in the above diagram. There are lots of things to say about this. When you have something that is defined via a universal property, you first have to check that it exists!\n\\begin{construction}\nI want to construct an $R$-bilinear map out of $M\\times N$. I guess I should say it like this. Let $\\beta:M\\times N\\to Q$ be any $R$-bilinear map. This $\\beta$ isn't linear. Maybe we should first extend it to a linear map. Consider $R\\langle M\\times N\\rangle$, the free $R$-module generated by $M\\times N$. Well, $\\beta$ is a map of sets, so there's a unique $R$-linear homomorphism $\\overline{\\beta}:R\\langle M\\times N\\rangle\\to Q$. Then I get a factorization:\n\\begin{equation*}\n\\xymatrix{M\\times N\\ar[rr]^\\beta\\ar[dr]^{[-]} & & Q\\\\\n& R\\langle M\\times N\\rangle\\ar[ur]^{\\overline{\\beta}} &}\n\\end{equation*}\nThe map $[-]$ isn't bilinear. So we should quotient $R\\langle M\\times N\\rangle$ by a submodule $S$ of relations. More precisely, $S$ is the sub $R$-module generated by the relations needed to map $[-]$ a $R$-bilinear map, namely:\n\\begin{enumerate}\n\\item $[(x+x^\\prime,y)]-[(x,y)]-[(x^\\prime-y)]$.\n\\item $[(x,y+y^\\prime)]-[(x,y)]-[(x,y^\\prime)]$.\n\\item $[(rx,y)]-r[(x,y)]$.\n\\item $[(x,ry)]-r[(x,y)]$\n\\end{enumerate}\nfor all $x,x^\\prime\\in M$ and $y,y^\\prime\\in N$. Now, this map $[-]$ is bilinear - we've quotiented out by all things that made it false! Now the map $R\\langle M\\times N\\rangle\\to Q$ factors through via $R\\langle M\\times N\\rangle\\to R\\langle M\\times N\\rangle/S\\xrightarrow{f} Q$ because the map $\\overline{\\beta}$ is linear, and $f$ is unique because the $\\overline{\\beta}$ is unique, so there's at most one factorization. We just checked that there was one, so we're done. We'll also write the composition $M\\times N\\xrightarrow{[-]}R\\langle M\\times N\\rangle\\to R\\langle M\\times N\\rangle/S$ as $\\otimes$.\n\\end{construction}\nYou're never going to use this construction to compute anything. If you find yourself using this construction, stop and think about what you're doing.\n\\begin{remark}\nNote that the image of $(m,n)$ in $R\\langle M\\times N\\rangle/S$ generates $R\\langle M\\times N\\rangle/S$ as an $R$-module. The $R$-module $R\\langle M\\times N\\rangle/S$ contains elements of the form $x\\otimes y$ with $x\\in M$ and $y\\in N$ because they generate $R\\langle M\\times N\\rangle$, and $R\\langle M\\times N\\rangle/S$ is a quotient of that.\n\nThese $x\\otimes y$ are called ``decomposable tensors''. (I've heard them called pure tensors.)\n\\end{remark}\nWhat are the properties of $R\\langle M\\times N\\rangle/S=:P$?\n\\begin{enumerate}\n\\item How many maps are there that make the following diagram commute?\n\\begin{equation*}\n\\xymatrix{& P\\ar@{-->}[dd]\\\\\nM\\otimes N\\ar[ur]^\\otimes\\ar[dr]_\\otimes & \\\\\n& P}\n\\end{equation*}\nBy the uniqueness statement, there's only one map, namely the identity!\n\\item Suppose that we have two tensor products of $M$ and $N$, say $P$ and $P^\\prime$. We have\n\\begin{equation*}\n\\xymatrix{& P\\ar@{-->}[dd]^b\\\\\nM\\otimes N\\ar[ur]^\\otimes\\ar[dr]_\\otimes & \\\\\n& P^\\prime\\ar@{-->}[uu]_{b^\\prime}}\n\\end{equation*}\nAnd $b,b^\\prime$ are unique. If you compose $b$ and $b^\\prime$, you'll see that you get the identity of $P$ and $P^\\prime$, depending on how you compose the maps. More precisely, you have:\n\\begin{equation*}\n\\xymatrix{& P\\ar@{-->}[d]^b\\\\\nM\\otimes N\\ar[ur]^\\otimes\\ar[dr]_\\otimes & P^\\prime\\ar[d]^{b^\\prime}\\\\\n& P^\\prime}\n\\end{equation*}\nand\n\\begin{equation*}\n\\xymatrix{& P^\\prime\\ar@{-->}[d]^{b^\\prime}\\\\\nM\\otimes N\\ar[ur]^\\otimes\\ar[dr]_\\otimes & P\\ar[d]^{b}\\\\\n& P^\\prime}\n\\end{equation*}\nThus $bb^\\prime=1$ and $b^\\prime b=1$. So $b,b^\\prime$ are isomorphisms, i.e., $P\\cong P^\\prime$. We say that there is a canonical\\footnote{This means god given, but here it means that it's naturally constructed.} isomorphism between any two constructions of a tensor products. The universal property defines the object up to canonical isomorphism. This is a general principle.\n\nWe can thus write the tensor product as if it just depended on just $M$ and $N$. We write $M\\otimes N$. A general element is a finite sum $\\sum_i x_i\\otimes y_i$. To be really honest, we'll write $M\\otimes_R N$. If $R$ is understood, we'll omit it. I'll usually forget to add the $\\otimes_R$, and simply write $\\otimes$.\n\\item Functoriality. If I have homomorphisms $M\\times N\\xrightarrow{f\\times g}M^\\prime\\times N^\\prime$. I have:\n\\begin{equation*}\n\\xymatrix{M\\times N\\ar[d]^{f\\times g}\\ar[r]^\\otimes\\ar[dr] & M\\otimes N\\ar@{-->}[d]\\\\\nM^\\prime\\times N^\\prime\\ar[r]^\\otimes & M^\\prime\\otimes N^\\prime}\n\\end{equation*}\nThe dotted map exists because the diagonal map is $R$-bilinear. We write the map $M\\otimes N\\to M^\\prime \\otimes N^\\prime$ as $f\\otimes g$. We need to check stuff though.\n\\begin{equation*}\n\\xymatrix{M\\times N\\ar[d]^{f\\times g}\\ar[r]^\\otimes\\ar[dr] & M\\otimes N\\ar@{-->}[d]^{f\\otimes g}\\\\\nM^\\prime\\times N^\\prime\\ar[r]^\\otimes\\ar[d]^{f^\\prime\\times g^\\prime} & M^\\prime\\otimes N^\\prime\\ar@{-->}[d]^{f\\otimes g}\\\\\nM^{\\prime\\prime}\\times N^{\\prime\\prime}\\ar[r]^\\otimes & M^{\\prime\\prime}\\otimes N^{\\prime\\prime}}\n\\end{equation*}\nAnd the composite matches up, i.e., $(f^\\prime\\otimes g^\\prime)(f\\otimes g)=(f^\\prime f)\\otimes g^\\prime g$.\n\\item I said that this was gonna be a categorical ring, so we need to check this. Well, $R\\otimes_R M$ should be isomorphic to $M$. Let's think about this for a minute. I just need to check the universal property. Suppose I have an $R$-bilinear map $\\beta:R\\times M\\to P$. We already have a universal $R$-bilinear map $\\varphi:R\\times M\\to M$. I have to construct a universal factorization $f:M\\to P$. Just let $f(x)=\\beta(1,x)$. It's $R$-bilinear. We can check that this diagram commutes now because $f(\\varphi(r,x))=f(rx)=\\beta(1,rx)=r\\beta(1,x)=\\beta(r,x)$. Well, this map $R\\times M\\to M$ is surjective, so there's at most one factorization. So we're done. There are other checks that are extremely boring, but they're part of the toolkit.\n\nI need to check that $L\\otimes(M\\otimes N)\\cong (L\\otimes M)\\otimes N$ that's compatible with $L\\times (M\\times N)\\cong (L\\times M)\\times N$. There's a canonical isomorphism. I don't know how to not say that this is trivial. Also, we need to check that $M\\otimes N\\cong N\\otimes M$. (Just do this yourself. It's really easy.)\n\\item What happens with $M\\otimes\\left(\\bigoplus_{\\alpha\\in A}N_\\alpha\\right)$? It might be a finite direct sum, or maybe an uncountable collection. How does this relate to $\\bigoplus_{\\alpha\\in A}(M\\otimes N_\\alpha)$? Let's construct a map $\\displaystyle\\bigoplus_{\\alpha\\in A}(M\\otimes N_\\alpha)\\to M\\otimes\\left(\\bigoplus_{\\alpha\\in A}N_\\alpha\\right)$. We just need to define maps $M\\otimes N_\\alpha\\to M\\otimes\\left(\\bigoplus_{\\alpha\\in A}N_\\alpha\\right)$ because direct sums are coproducts. Let this map be $1\\otimes\\text{in}_\\alpha$ where $\\mathrm{in}_\\alpha:N_\\alpha\\to \\bigoplus_{\\alpha\\in A}N_\\alpha$. These give you a map $f:\\bigoplus_{\\alpha\\in A}(M\\otimes N_\\alpha)\\to M\\otimes\\left(\\bigoplus_{\\alpha\\in A}N_\\alpha\\right)$\n\nWhat about a map the other way? This is a bit trickier. An element of $M\\otimes\\left(\\bigoplus_{\\alpha\\in A}N_\\alpha\\right)$ is $x\\otimes(y_\\alpha)_{\\alpha\\in A}$, where you note that $y_\\alpha=0$ for all but finitely many $\\alpha\\in A$. Define $g:M\\otimes\\left(\\bigoplus_{\\alpha\\in A}N_\\alpha\\right)\\to \\bigoplus_{\\alpha\\in A}(M\\otimes N_\\alpha)$ via $x\\otimes(y_\\alpha)_{\\alpha\\in A}\\mapsto (x\\otimes y_\\alpha)_{\\alpha\\in A}$. It's up to you to check that these are inverses and that you can extend to a general nondecomposable tensor by linearity.\n\\end{enumerate}\nWe have not done any computations yet. I guess I should end with the statement that $S_\\ast(X;M):=S_\\ast(X)\\otimes_R M$ if $M$ is an $R$-module. We'll discuss on Monday the question we raised last time, namely:\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}\n", "meta": {"hexsha": "5fa65607fd8cf1d1dc63fb9f7d26c25329aa292a", "size": 10267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-20-tensor-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-20-tensor-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-20-tensor-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": 105.8453608247, "max_line_length": 743, "alphanum_fraction": 0.7054641083, "num_tokens": 3437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.696885696408398}}
{"text": "\\chapter{Propulsion}\n\n\\section{Piston Engine}\n\nPiston engine manifold absolute pressure due to engine revolution speed and normalized throttle position is approximated by the following formula.\n\\begin{equation}\n  p_{MAP}\n  =\n  p \\left( h \\right)\n  +\n  \\left(\n    4 \\cdot 10^5 \\hat \\delta_{throttle}\n    -\n    4.05 \\cdot 10^5\n  \\right)\n  \\frac{n}{n_{max}}\n\\end{equation}\n\nFuel to air ratio is approximated by the following expression: \\cite{Allerton2009}\n\\begin{equation}\n  FAR = 0.1 \\left( 2 - {\\hat \\delta}_{mixture}^2 \\right) \\frac{\\rho_0}{\\rho}\n\\end{equation}\n\nEngine static power is approximated as:\n\\begin{equation}\n  P_S =\n  1.093 \\cdot 10^{-5} \\left( 1 + C_{\\Delta P} \\right) P_{max} p_{MAP}\n  \\left( \\frac{n}{n_{max}} - 0.05 \\right)\n\\end{equation}\n\nPower losses can be calculated using following formula:\n\\begin{equation}\n  \\Delta P = P_{max} C_{\\Delta P} \\left( \\frac{n}{n_{max}} \\right)^2\n\\end{equation}\n\nEngine net power is given as:\n\\begin{equation}\n  P = P_S - \\Delta P\n\\end{equation}\n\n\\section{Propeller}\n\nThrust generated by the propeller and power required by the propeller are given by the following equations. \\cite{Allerton2009, Raymer1992} Propeller revolution speed n is expressed in revolutions per second.\n\\begin{align}\n  T &= \\rho n^2 D^4 C_T \\\\\n  P &= \\rho n^3 D^5 C_P\n\\end{align}\n\nWhere thrust $C_T$ and power $C_P$ coefficients are functions of advance ratio and blade angle.\n\nAdvance ratio is given by the following formula: \\cite{Allerton2009, Raymer1992, Torenbeek1982}\n\\begin{equation}\n  J = \\frac{V}{nD}\n\\end{equation}\n\nThe propeller torque required is given as: \\cite{ResnickHalliday2011}\n\\begin{equation}\n  Q = \\frac{P}{2 \\pi n}\n\\end{equation}\n\n\\subsection{Propeller Induced Velocity}\n\nThe pressure jump across the propeller disk can be expressed as:\n\\begin{equation}\n  \\Delta p = \\frac{1}{2} \\rho \\left[ \\left( V + V_i \\right)^2 - V^2 \\right]\n\\end{equation}\n\nHence:\n\\begin{align}\n  T &= \\Delta p A \\\\\n  \\label{eq-prop-induced-velocity-thrust}\n  T &= \\frac{1}{2} \\rho A \\left[ \\left( V + V_i \\right)^2 - V^2 \\right]\n\\end{align}\n\nInduced velocity can be found by solving equation (\\ref{eq-prop-induced-velocity-thrust}).\n\n% \\section{Jet Engine}\n\n% TODO\n\n% \\section{Turboshaft Engine}\n\n% TODO\n", "meta": {"hexsha": "ad7783b28cf6341e813b2e9b0dd2aec0875b27d8", "size": 2225, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/fdm_7.tex", "max_stars_repo_name": "marek-cel/mscsim-docs", "max_stars_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-12-01T02:27:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-09T07:02:20.000Z", "max_issues_repo_path": "tex/fdm_7.tex", "max_issues_repo_name": "marek-cel/mscsim-docs", "max_issues_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/fdm_7.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": 26.4880952381, "max_line_length": 208, "alphanum_fraction": 0.7002247191, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6968393774988106}}
{"text": "\\chapter{Mixture models and the EM algorithm}\n\\label{chap:EM-algorithm}\n\n\n\\section{Latent variable models}\nIn Chapter \\ref{chap:DGM} we showed how graphical models can be used to define high-dimensional joint probability distributions. The basic idea is to model dependence between two variables by adding an edge between them in the graph. (Technically the graph represents conditional\nindependence, but you get the point.)\n\nAn alternative approach is to assume that the observed variables are correlated because they arise from a hidden common “cause”. Model with hidden variables are also known as \\textbf{latent variable models} or \\textbf{LVM}s. As we will see in this chapter, such models are harder to fit than models with no latent variables. However, they can have significant advantages, for two main reasons.\n\\begin{itemize}\n\\item{First, LVMs often have fewer parameters than models that directly represent correlation in the visible space.}\n\\item{Second, the hidden variables in an LVM can serve as a \\textbf{bottleneck}, which computes a compressed representation of the data. This forms the basis of unsupervised learning, as we will see. Figure \\ref{fig:latent-variable-model} illustrates some generic LVM structures that can be used for this purpose.}\n\\end{itemize}\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.60]{latent-variable-model.png}\n\\caption{A latent variable model represented as a DGM. (a) Many-to-many. (b) One-to-many. (c) Many-to-one. (d) One-to-one.}\n\\label{fig:latent-variable-model} \n\\end{figure}\n\n\n\\section{Mixture models}\nThe simplest form of LVM is when $z_i \\in \\{1,\\cdots,K\\}$, representing a discrete latent state. We will use a discrete prior for this, $p(zi)=\\mathrm{Cat}(\\pi)$. For the likelihood, we use $p(\\vec{x}_i|z_i =k)=p_k(\\vec{x}_i)$, where $p_k$ is the $k$'th \\textbf{base distribution} for the observations; this can be of any type. The overall model is known as a \\textbf{mixture model}, since we are mixing together the $K$ base distributions as follows:\n\\begin{equation}\np(\\vec{x}_i|\\vec{\\theta})=\\sum\\limits_{k=1}^K \\pi_kp_k(\\vec{x}_i|\\vec{\\theta})\n\\end{equation}\n\nDepending on the form of the likelihood $p(\\vec{x}_i|\\vec{z}_i)$ and the prior $p(\\vec{z}_i)$, we can generate a variety of different models, as summarized in Table \\ref{tab:popular-directed-latent-variable-models}.\n\n\\begin{table}\n\\centering\n\\begin{tabular}{llll}\n\\hline\\noalign{\\smallskip}\n$p(\\vec{x}_i|\\vec{z}_i)$ & $p(\\vec{z}_i)$ & \\textbf{Name} & \\textbf{Section} \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nMVN & Discrete & Mixture of Gaussians & 11.2.1 \\\\\nProd. Discrete & Discrete & Mixture of multinomials & 11.2.2 \\\\\n\\multirow{2}{*}{Prod. Gaussian} & \\multirow{2}{*}{Prod. Gaussian} & Factor analysis/ & \\multirow{2}{*}{12.1.5} \\\\\n                                &                                 & probabilistic PCA&  \\\\\n\\multirow{2}{*}{Prod. Gaussian} & \\multirow{2}{*}{Prod. Laplace} & Probabilistic ICA/& \\multirow{2}{*}{12.6} \\\\\n                                &                                & sparse coding     &  \\\\\nProd. Discrete & Prod. Gaussian & Multinomial PCA & 27.2.3 \\\\\n\\multirow{2}{*}{Prod. Discrete} & \\multirow{2}{*}{Dirichlet} & Latent Dirichlet & \\multirow{2}{*}{27.3}\\\\\n                                &                            & allocation       &  \\\\\nProd. Noisy-OR & Prod. Bernoulli & BN20/ QMR & 10.2.3 \\\\\nProd. Bernoulli & Prod. Bernoulli & Sigmoid belief net & 27.7 \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\caption{Summary of some popular directed latent variable models. Here “Prod” means product, so “Prod. Discrete” in the likelihood means a factored distribution of the form $\\prod_j \\mathrm{Cat}(x_{ij}|\\vec{z}_i)$, and “Prod. Gaussian” means a factored distribution of the form $\\prod_j \\mathcal{N}(x_{ij}|\\vec{z}_i)$.}\n\\label{tab:popular-directed-latent-variable-models}\n\\end{table}\n\n\n\\subsection{Mixtures of Gaussians}\n\\begin{equation}\np_k(\\vec{x}_i|\\vec{\\theta})=\\mathcal{N}(\\vec{x}_i|\\vec{\\mu}_k,\\Sigma_k)\n\\end{equation}\n\n\n\\subsection{Mixtures of multinoullis}\n\\begin{equation}\np_k(\\vec{x}_i|\\vec{\\theta})=\\prod\\limits_{j=1}^D \\mathrm{Ber}(x_{ij}|\\mu_{jk})=\\prod\\limits_{j=1}^D \\mu_{jk}^{x_{ij}}(1-\\mu_{jk})^{1-x_{ij}}\n\\end{equation}\nwhere $\\mu_{jk}$ is the probability that bit $j$ turns on in cluster $k$.\n\nThe latent variables do not have to any meaning, we might simply introduce latent variables in order to make the model more powerful. For example, one can show that the mean and covariance of the mixture distribution are given by\n\\begin{align}\n\\mathbb{E}[\\vec{x}] & = \\sum\\limits_{k=1}^K \\pi_k\\vec{\\mu}_k \\\\\n\\mathrm{Cov}[\\vec{x}] & = \\sum\\limits_{k=1}^K \\pi_k(\\Sigma_k+\\vec{\\mu}_k\\vec{\\mu}_k^T)-\\mathbb{E}[\\vec{x}]\\mathbb{E}[\\vec{x}]^T\n\\end{align}\nwhere $\\Sigma_k=\\mathrm{diag}(\\mu_{jk}(1-\\mu_{jk}))$. So although the component distributions are factorized, the joint distribution is not. Thus the mixture distribution can capture correlations between variables, unlike a single product-of-Bernoullis model.\n\n\n\n\n\\subsection{Using mixture models for clustering}\nThere are two main applications of mixture models, black-box density model(see Section 14.7.3 TODO) and clustering(see Chapter 25 TODO).\n\n\\textbf{Soft clustering}\n\\begin{equation}\\begin{split}\nr_{ik} & \\triangleq p(z_i=k|\\vec{x}_i,\\vec{\\theta})=\\dfrac{p(z_i=k,\\vec{x}_i|\\vec{\\theta})}{p(\\vec{x}_i|\\vec{\\theta})} \\\\\n       & =\\dfrac{p(z_i=k|\\vec{\\theta})p(\\vec{x}_i|z_i=k,\\vec{\\theta})}{\\sum_{k'=1}^K p(z_i=k'|\\vec{\\theta})p(\\vec{x}_i|z_i=k',\\vec{\\theta})}\n\\end{split}\\end{equation}\nwhere $r_{ik}$ is known as the \\textbf{responsibility} of cluster $k$ for point $i$.\n\n\\textbf{Hard clustering}\n\\begin{equation}\nz_i^* \\triangleq \\arg\\max_k r_{ik}=\\arg\\max_k p(z_i=k|\\vec{x}_i,\\vec{\\theta})\n\\end{equation}\n\nThe difference between generative classifiers and mixture models only arises at training time: in the mixture case, we never observe $z_i$, whereas with a generative classifier, we do observe $y_i$(which plays the role of $z_i$).\n\n\n\\subsection{Mixtures of experts}\nSection 14.7.3 TODO described how to use mixture models in the context of generative classifiers. We can also use them to create discriminative models for classification and regression. For example, consider the data in Figure \\ref{fig:mixture-of-experts}(a). It seems like a good model would be three different linear regression functions, each applying to a different part of the input space. We can model this by allowing the mixing weights and the mixture densities to be input-dependent:\n\\begin{align}\np(y_i|\\vec{x}_i,z_i=k,\\vec{\\theta}) & =\\mathcal{N}(y_i|\\vec{w}_k^T\\vec{x},\\sigma_k^2) \\\\\np(z_i | \\vec{x}_i,\\vec{\\theta}) & = \\mathrm{Cat}(z_i|\\mathcal{S}(\\vec{V}^T\\vec{x}_i))\n\\end{align}\n\nSee Figure \\ref{fig:mixture-of-experts2}(a) for the DGM.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.60]{mixture-of-experts-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{mixture-of-experts-b.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{mixture-of-experts-c.png}}\n\\caption{(a) Some data fit with three separate regression lines. (b) Gating functions for three different “experts”. (c) The conditionally weighted average of the three expert predictions.}\n\\label{fig:mixture-of-experts} \n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{mixture-of-experts2.png}\n\\caption{(a) A mixture of experts. (b) A hierarchical mixture of experts.}\n\\label{fig:mixture-of-experts2} \n\\end{figure}\n\nThis model is called a \\textbf{mixture of experts} or MoE (Jordan and Jacobs 1994). The idea is that each submodel is considered to be an “expert” in a certain region of input space. The function $p(z_i | \\vec{x}_i,\\vec{\\theta})$ is called a \\textbf{gating function}, and decides which expert to use, depending on the input values. For example, Figure \\ref{fig:mixture-of-experts}(b) shows how the three experts have “carved up” the 1d input space, Figure \\ref{fig:mixture-of-experts}(a) shows the predictions of each expert individually (in this case, the experts are just linear regression models), and Figure \\ref{fig:mixture-of-experts}(c) shows the overall prediction of the model, obtained using\n\\begin{equation}\np(y_i|\\vec{x}_i,\\vec{\\theta})=\\sum\\limits_{k=1}^K p(z_i=k | \\vec{x}_i,\\vec{\\theta})p(y_i|\\vec{x}_i,z_i=k,\\vec{\\theta})\n\\end{equation}\n\nWe discuss how to fit this model in Section TODO 11.4.3.\n\n\n\\section{Parameter estimation for mixture models}\n\n\n\\subsection{Unidentifiability}\n\n\n\\subsection{Computing a MAP estimate is non-convex}\n\n\n\\section{The EM algorithm}\n\n\n\\subsection{Introduction}\nFor many models in machine learning and statistics, computing the ML or MAP parameter estimate is easy provided we observe all the values of all the relevant random variables, i.e., if we have complete data. However, if we have missing data and/or latent variables, then computing the ML/MAP estimate becomes hard.\n\nOne approach is to use a generic gradient-based optimizer to find a local minimum of the NLL$(\\vec{\\theta})$. However, we often have to enforce constraints, such as the fact that covariance matrices must be positive definite, mixing weights must sum to one, etc., which can be tricky. In such cases, it is often much simpler (but not always faster) to use an algorithm called \\textbf{expectation maximization},or \\textbf{EM} for short (Dempster et al. 1977; Meng and van Dyk 1997; McLachlan and Krishnan 1997). This is is an efficient iterative algorithm to compute the ML or MAP estimate in the presence of missing or hidden data, often with closed-form updates at each step. Furthermore, the algorithm automatically enforce the required constraints.\n\nSee Table \\ref{tab:summary-of-the-applications-of-EM} for a summary of the applications of EM in this book.\n\n\\begin{table}\n\\caption{Some models discussed in this book for which EM can be easily applied to find the ML/ MAP parameter estimate.}\n\\label{tab:summary-of-the-applications-of-EM}\n\\centering\n\\begin{tabular}{ll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Model} & \\textbf{Section} \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nMix. Gaussians & 11.4.2 \\\\\nMix. experts & 11.4.3 \\\\\nFactor analysis & 12.1.5 \\\\\nStudent T & 11.4.5 \\\\\nProbit regression & 11.4.6 \\\\\nDGM with hidden variables & 11.4.4 \\\\\nMVN with missing data & 11.6.1 \\\\\nHMMs & 17.5.2 \\\\\nShrinkage estimates of Gaussian means & Exercise 11.13 \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table}\n\n\n\\subsection{Basic idea}\nEM exploits the fact that if the data were fully observed, then the ML/ MAP estimate would be easy to compute. In particular, each iteration of the EM algorithm consists of two processes: The E-step, and the M-step. \n\\begin{itemize}\n\\item{In the \\textbf{E-step}, the missing data are inferred given the observed data and current estimate of the model parameters. This is achieved using the conditional expectation, explaining the choice of terminology.}\n\\item{In the \\textbf{M-step}, the likelihood function is maximized under the assumption that the missing data are known. The missing data inferred from the E-step are used in lieu of the actual missing data.}\n\\end{itemize}\n\nLet $\\vec{x}_i$ be the visible or observed variables in case $i$, and let $\\vec{z}_i$ be the hidden or missing variables. The goal is to maximize the log likelihood of the observed data:\n\\begin{equation}\n\\ell(\\vec{\\theta})=\\log p(\\mathcal{D}|\\vec{\\theta})=\\sum\\limits_{i=1}^N \\log p(\\vec{x}_i|\\vec{\\theta})=\\sum\\limits_{i=1}^N \\log{\\sum\\limits_{\\vec{z}_i} p(\\vec{x}_i,\\vec{z}_i|\\vec{\\theta})}\n\\end{equation}\n\nUnfortunately this is hard to optimize, since the log cannot be pushed inside the sum.\n\nEM gets around this problem as follows. Define the \\textbf{complete data log likelihood} to be\n\\begin{equation}\n\\ell_c(\\vec{\\theta})=\\sum\\limits_{i=1}^N \\log p(\\vec{x}_i,\\vec{z}_i|\\vec{\\theta})\n\\end{equation}\n\nThis cannot be computed, since $\\vec{z}_i$ is unknown. So let us define the \\textbf{expected complete data log likelihood} as follows:\n\\begin{equation}\\label{eqn:auxiliary-function}\nQ(\\vec{\\theta},\\vec{\\theta}^{t-1}) \\triangleq \\mathbb{E}_{\\vec{z}|\\mathcal{D},\\theta^{t-1}}\\left[\\ell_c(\\vec{\\theta})\\right]=\\mathbb{E}\\left[\\ell_c(\\vec{\\theta})| \\mathcal{D},\\theta^{t-1}\\right]\n\\end{equation}\nwhere $t$ is the current iteration number. $Q$ is called the \\textbf{auxiliary function}(see Section \\ref{sec:Derivation-of-the-Q-function} for derivation). The expectation is taken wrt the old parameters, $\\vec{\\theta}^{t-1}$, and the observed data $\\mathcal{D}$. The goal of the E-step is to compute $Q(\\vec{\\theta},\\vec{\\theta}^{t-1})$, or rather, the parameters inside of it which the MLE(or MAP) depends on; these are known as the \\textbf{expected sufficient statistics} or \\textbf{ESS}. In the M-step, we optimize the $Q$ function wrt $\\vec{\\theta}$:\n\\begin{equation}\n\\vec{\\theta}^t=\\arg\\max_{\\vec{\\theta}} Q(\\vec{\\theta},\\vec{\\theta}^{t-1})\n\\end{equation}\n\nTo perform MAP estimation, we modify the M-step as follows:\n\\begin{equation}\n\\vec{\\theta}^t=\\arg\\max_{\\vec{\\theta}} Q(\\vec{\\theta},\\vec{\\theta}^{t-1})+\\log p(\\vec{\\theta})\n\\end{equation}\nThe E step remains unchanged.\n\nIn summary, the EM algorithm's pseudo code is as follows\n\n\\begin{algorithm}[htbp]\n    \\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n    \\Input{observed data $\\mathcal{D}=\\{\\vec{x}_1,\\vec{x}_2,\\cdots, \\vec{x}_N$\\},joint distribution $P(\\vec{x},\\vec{z}|\\vec{\\theta})$}\n\t\\Output{model's parameters $\\vec{\\theta}$}\n\n\t// 1. identify hidden variables $\\vec{z}$, write out the log likelihood function $\\ell(\\vec{x},\\vec{z}|\\vec{\\theta})$ \\\\\n\t$\\vec{\\theta}^{(0)}$ = ... // initialize \\\\\n\t\n\t\\While{(!convergency)} {\n\t    // 2. E-step: plug in $P(\\vec{x},\\vec{z}|\\vec{\\theta})$, derive the formula of $Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})$ \\\\\n\t    $Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})=\\mathbb{E}\\left[\\ell_c(\\vec{\\theta})| \\mathcal{D},\\theta^{t-1}\\right]$ \\\\\n\t    // 3. M-step: find \\vec{\\theta} that maximizes the value of $Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})$ \\\\\n\t\t$\\vec{\\theta}^t=\\arg\\max\\limits_{\\vec{\\theta}} Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})$ \\\\\n\t}\n\t\n\\caption{EM algorithm}\n\\end{algorithm}\n\nBelow we explain how to perform the E and M steps for several simple models, that should make things clearer.\n\n\n\\subsection{EM for GMMs}\n\n\\subsubsection{Auxiliary function}\n\\begin{align}\nQ(\\vec{\\theta}, \\vec{\\theta}^{t-1}) & =\\mathbb{E}_{z|\\mathcal{D},\\theta^{t-1}}\\left[\\ell_c(\\vec{\\theta})\\right] \\nonumber \\\\\n    & = \\mathbb{E}_{z|\\mathcal{D},\\theta^{t-1}}\\left[\\sum\\limits_{i=1}^N \\log p(\\vec{x}_i,z_i|\\vec{\\theta})\\right] \\nonumber \\\\\n\t& = \\sum\\limits_{i=1}^N \\mathbb{E}_{z|\\mathcal{D},\\theta^{t-1}}\\left\\{\\log\\left[\\prod\\limits_{k=1}^K \\left(\\pi_kp(\\vec{x}_i|\\vec{\\theta}_k)\\right)^{\\mathbb{I}(z_i=k)}\\right]\\right\\} \\nonumber \\\\\n\t& = \\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{\\mathbb{E}[\\mathbb{I}(z_i=k)]\\log\\left[\\pi_kp(\\vec{x}_i|\\vec{\\theta}_k)\\right]}} \\nonumber \\\\\n\t& = \\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{p(z_i=k|\\vec{x}_i,\\vec{\\theta}^{t-1})\\log\\left[\\pi_kp(\\vec{x}_i|\\vec{\\theta}_k)\\right]}} \\nonumber \\\\\n\t& = \\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log \\pi_k}}+\\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log p(\\vec{x}_i|\\vec{\\theta}_k)}} \\label{eqn:Q-miture-model}\n\\end{align}\nwhere $r_{ik} \\triangleq \\mathbb{E}[\\mathbb{I}(z_i=k)]=p(z_i=k|\\vec{x}_i,\\vec{\\theta}^{t-1})$ is the \\textbf{responsibility} that cluster $k$ takes for data point $i$. This is computed in the E-step, described below.\n\n\n\\subsubsection{E-step}\nThe E-step has the following simple form, which is the same for any mixture model:\n\\begin{equation}\\begin{split}\nr_{ik} & =p(z_i=k|\\vec{x}_i,\\vec{\\theta}^{t-1})=\\frac{p(z_i=k,\\vec{x}_i|\\vec{\\theta}^{t-1})}{p(\\vec{x}_i|\\vec{\\theta}^{t-1})} \\\\\n  & =\\frac{\\pi_kp(\\vec{x}_i|\\vec{\\theta}_k^{t-1})}{\\sum_{k'=1}^K \\pi_{k'}p(\\vec{x}_i|\\vec{\\theta}_k^{t-1})}\n\\end{split}\\end{equation}\n\n\\subsubsection{M-step}\nIn the M-step, we optimize $Q$ wrt $\\vec{\\pi}$ and $\\vec{\\theta}_k$.\n\nFor $\\vec{\\pi}$, grouping together only the terms that depend on $\\pi_k$, we find that we need to maximize $\\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log \\pi_k}}$. However, there is an additional constraint $\\sum\\limits_{k=1}^K{\\pi_k}=1$, since they represent the probabilities $\\vec{\\pi}_k=P(z_i=k)$. To deal with the constraint we construct the Lagrangian\n\\begin{equation}\n\\mathcal{L}(\\vec{\\pi})=\\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log \\pi_k}}+\\beta\\left(\\sum\\limits_{k=1}^K{\\pi_k}-1\\right) \\nonumber\n\\end{equation}\nwhere $\\beta$ is the Lagrange multiplier. Taking derivatives, we find\n\\begin{equation}\n\\hat{\\vec{\\pi}}_k=\\frac{\\sum\\limits_{i=1}^N \\hat{r}_{ik}}{N}\n\\end{equation}\nThis is the same for any mixture model, whereas $\\vec{\\theta}_k$ depends on the form of $p(\\vec{x}|\\vec{\\theta}_k)$.\n\nFor $\\vec{\\theta}_k$, plug in the pdf to Equation \\ref{eqn:Q-miture-model}\n\\begin{equation*}\\begin{split}\nQ(\\vec{\\theta}, \\vec{\\theta}^{t-1}) & =\\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log \\pi_k}}-\\frac{1}{2}\\sum\\limits_{i=1}^N  \\sum\\limits_{k=1}^K  r_{ik}\\left[\\log |\\vec{\\Sigma}_k| + \\right. \\\\\n & \\quad \\left. (\\vec{x}_i-\\vec{\\mu}_k)^T\\vec{\\Sigma}_k^{-1}(\\vec{x}_i-\\vec{\\mu}_k)\\right]\n\\end{split}\\end{equation*}\n\nTake partial derivatives of $Q$ wrt $\\vec{\\mu}_k$, $\\vec{\\Sigma}_k$ and let them equal to 0, we can get\n\\begin{align}\n\\frac{\\partial Q}{\\partial \\vec{\\mu}_k} & = -\\frac{1}{2}\\sum\\limits_{i=1}^N{r_{ik}\\left[(\\vec{\\Sigma}_k^{-1}+\\vec{\\Sigma}_k^{-T})(\\vec{x}_i-\\vec{\\mu}_k)\\right]} \\nonumber \\\\\n    &  =-\\sum\\limits_{i=1}^N{r_{ik}\\left[\\vec{\\Sigma}_k^{-1}(\\vec{x}_i-\\vec{\\mu}_k)\\right]}=0 \\Rightarrow \\nonumber \\\\\n\\hat{\\vec{\\mu}}_k & = \\frac{\\sum_{i=1}^N \\hat{r}_{ik}\\vec{x}_i}{\\sum_{i=1}^N \\hat{r}_{ik}}\n\\end{align}\n\n\\begin{align}\n\\frac{\\partial Q}{\\partial \\vec{\\Sigma}_k} & = -\\frac{1}{2}\\sum\\limits_{i=1}^N{r_{ik}\\left[\\frac{1}{\\vec{\\Sigma}_k}-\\frac{1}{\\vec{\\Sigma}_k^2}(\\vec{x}_i-\\vec{\\mu}_k)(\\vec{x}_i-\\vec{\\mu}_k)^T\\right]}=0 \\Rightarrow \\nonumber \\\\\n\\hat{\\vec{\\Sigma}}_k & = \\frac{\\sum_{i=1}^N \\hat{r}_{ik}(\\vec{x}_i-\\vec{\\mu}_k)(\\vec{x}_i-\\vec{\\mu}_k)^T}{\\sum_{i=1}^N \\hat{r}_{ik}} \\\\\n & =\\frac{\\sum_{i=1}^N \\hat{r}_{ik}\\vec{x}_i\\vec{x}_i^T}{\\sum_{i=1}^N \\hat{r}_{ik}}-\\vec{\\mu}_k\\vec{\\mu}_k^T\n\\end{align}\n\n\n\\subsubsection{Algorithm pseudo code}\n\n\\begin{algorithm}[htbp]\n    \\SetAlgoNoLine\n    \\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n    \\Input{observed data $\\mathcal{D}=\\{\\vec{x}_1,\\vec{x}_2,\\cdots, \\vec{x}_N$\\},GMM}\n\t\\Output{GMM's parameters $\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma}$}\n\n\t// 1. initialize \\\\\n\t$\\vec{\\pi}^{(0)}$ = ... \\\\\n\t$\\vec{\\mu}^{(0)}$ = ...  \\\\\n\t$\\vec{\\Sigma}^{(0)}$ = ...  \\\\\n\tt = 0 \\\\\n\t\\While{(!convergency)} {\n\t    // 2. E-step \\\\\n\t    $\\hat{r}_{ik}=\\frac{\\pi_kp(\\vec{x}_i|\\vec{\\theta}_k^{t-1})}{\\sum_{k'=1}^K \\pi_{k'}p(\\vec{x}_i|\\vec{\\mu}_k^{t-1},\\vec{\\Sigma}_k^{t-1})}$ \\\\\n\t    // 3. M-step \\\\\n        $\\hat{\\vec{\\pi}}_k=\\frac{\\sum_{i=1}^N \\hat{r}_{ik}}{N}$ \\\\\n\t\t$\\hat{\\vec{\\mu}}_k  = \\frac{\\sum_{i=1}^N \\hat{r}_{ik}\\vec{x}_i}{\\sum_{i=1}^N \\hat{r}_{ik}}$ \\\\\n\t\t$\\hat{\\vec{\\Sigma}}_k =\\frac{\\sum_{i=1}^N \\hat{r}_{ik}\\vec{x}_i\\vec{x}_i^T}{\\sum_{i=1}^N \\hat{r}_{ik}}-\\vec{\\mu}_k\\vec{\\mu}_k^T$ \\\\\n        ++t \\\\\n\t}\n\t\n\\caption{EM algorithm for GMM}\n\\end{algorithm}\n\n\n\\subsubsection{MAP estimation}\nAs usual, the MLE may overfit. The overfitting problem is particularly severe in the case of GMMs. An easy solution to this is to perform MAP estimation. The new auxiliary function is the expected complete data log-likelihood plus the log prior:\n\\begin{equation}\\begin{split}\nQ(\\vec{\\theta}, \\vec{\\theta}^{t-1}) & = \\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log \\pi_k}}+\\sum\\limits_{i=1}^N{\\sum\\limits_{k=1}^K{r_{ik}\\log p(\\vec{x}_i|\\vec{\\theta}_k)}} \\\\\n & +\\log p(\\vec{\\pi})+\\sum\\limits_{k=1}^K{\\log p(\\vec{\\theta}_k)}\n\\end{split}\\end{equation}\n\nIt is natural to use conjugate priors. \n\\begin{align*}\np(\\vec{\\pi}) & = \\mathrm{Dir}(\\vec{\\pi}|\\vec{\\alpha}) \\\\\np(\\vec{\\mu}_k,\\vec{\\Sigma}_k) & = \\mathrm{NIW}(\\vec{\\mu}_k,\\vec{\\Sigma}_k|\\vec{m}_0,\\kappa_0,\\nu_0,\\vec{S}_0)\n\\end{align*}\n\nFrom Equation \\ref{eqn:Dir-MAP} and Section \\ref{sec:Posterior-distribution-of-mu-and-Sigma}, the MAP estimate is given by\n\\begin{align}\n\\hat{\\pi}_k & = \\frac{\\sum_{i=1}^N r_{ik}+\\alpha_k-1}{N+\\sum_{k=1}^K \\alpha_k-K} \\\\\n\\hat{\\vec{\\mu}}_k & = \\frac{\\sum_{i=1}^N r_{ik}\\vec{x}_i + \\kappa_0\\vec{m}_0}{\\sum_{i=1}^N r_{ik} + \\kappa_0} \\\\\n\\hat{\\vec{\\Sigma}}_k & = \\frac{\\vec{S}_0+\\vec{S}_k+\\frac{\\kappa_0r_k}{\\kappa_0+r_k}(\\bar{\\vec{x}}_k-\\vec{m}_0)(\\bar{\\vec{x}}_k-\\vec{m}_0)^T}{\\nu_0+r_k+D+2} \\\\\n\\text{where } & r_k \\triangleq \\sum_{i=1}^N r_{ik}, \\bar{\\vec{x}}_k \\triangleq \\frac{\\sum_{i=1}^N r_{ik}\\vec{x}_i}{r_k}, \\nonumber \\\\\n  & \\vec{S}_k \\triangleq \\sum_{i=1}^N r_{ik} (\\vec{x}_i-\\bar{\\vec{x}}_k)(\\vec{x}_i-\\bar{\\vec{x}}_k)^T \\nonumber\n\\end{align}\n\n\n\\subsection{EM for K-means}\n\\label{sec:K-means}\n\n\\subsubsection{Representation}\n\\begin{equation}\ny_j=k \\text{ if } \\|\\vec{x}_j-\\vec{\\mu}_k\\|_2^2 \\text{ is minimal}\n\\end{equation}\nwhere $\\vec{\\mu}_k$ \\ is\\ the centroid of cluster k.\n\n\n\\subsubsection{Evaluation}\n\\begin{equation}\n\\arg\\min\\limits_{\\vec{\\mu}} \\sum_{j=1}^N {\\sum_{k=1}^K}\\gamma_{jk}{\\|\\vec{x}_j-\\vec{\\mu}_k\\|_2^2}\n\\end{equation}\n\nThe hidden variable is $\\gamma_{jk}$, which's meanining is:\n\\begin{equation} \\nonumber\n\\gamma_{jk}=\\begin{cases}\n1, & \\text{if } \\|\\vec{x}_j-\\vec{\\mu}_k\\|_2 \\text{ is minimal for } \\vec{\\mu}_k \\\\\n0, & \\text{otherwise}\n\\end{cases}\n\\end{equation}\n\n\n\\subsubsection{Optimization}\nE-Step:\n\\begin{equation}\n\\gamma_{jk}^{(i+1)}=\\begin{cases} \n1, & \\text{if } \\|\\vec{x}_j-\\vec{\\mu}_k^{(i)}\\|_2 \\text{ is minimal for } \\vec{\\mu}_k^{(i)} \\\\ \n0, & \\text{otherwise}\n\\end{cases}\n\\end{equation}\n\nM-Step:\n\\begin{equation}\n\\vec{\\mu}_{k}^{(i+1)}= \\frac{\\sum_{j=1}^N{\\gamma_{jk}^{(i+1)}\\vec{x}_j}}{\\sum \\gamma_{jk}^{(i+1)}}\n\\end{equation}\n\n\n\\subsubsection{Tricks}\n\n\\textbf{Choosing $k$}\n\nTODO\n\n\\textbf{Choosing the initial centroids(seeds)}\n\n\\begin{enumerate}\n\\item  \\textbf{K-means++}.\n\nThe intuition that spreading out the k initial cluster centers is a good thing is behind this approach: the first cluster center is chosen uniformly at random from the data points that are being clustered, after which each subsequent cluster center is chosen from the remaining data points with probability proportional to its squared distance from the point's closest existing cluster center\\footnote{\\url{http://en.wikipedia.org/wiki/K-means++}}.\n\nThe exact algorithm is as follows:\n\\begin{enumerate}\n\\item Choose one center uniformly at random from among the data points.\n\\item For each data point \\vec{x}, compute $D(\\vec{x})$, the distance between \\vec{x} and the nearest center that has already been chosen.\n\\item Choose one new data point at random as a new center, using a weighted probability distribution where a point \\vec{x} is chosen with probability proportional to $D(\\vec{x})^2$.\n\\item Repeat Steps 2 and 3 until $k$ centers have been chosen.\n\\item Now that the initial centers have been chosen, proceed using standard k-means clustering.\n\\end{enumerate}\n\\item TODO\n\\end{enumerate}\n\n\n\\subsection{EM for mixture of experts}\n\n\n\\subsection{EM for DGMs with hidden variables}\n\n\n\\subsection{EM for the Student distribution *}\n\n\n\\subsection{EM for probit regression *}\n\n\n\\subsection{Derivation of the $Q$ function}\n\\label{sec:Derivation-of-the-Q-function}\n\n\\begin{theorem}\n(\\textbf{Jensen's inequality}) Let $f$ be a convex function(see Section \\ref{sec:Convexity}) defined on a convex set $\\mathcal{S}$ . If $\\vec{x}_1, \\vec{x}_2, \\cdots , \\vec{x}_n \\in \\mathcal{S}$ and $\\lambda_1, \\lambda_2, \\cdots , \\lambda_n \\geq 0$ with $\\sum\\limits_{i=1}^n \\lambda_i=1$,\n\\begin{equation}\nf\\left(\\sum\\limits_{i=1}^n \\lambda_i\\vec{x}_i\\right) \\leq \\sum\\limits_{i=1}^n {\\lambda_i f(\\vec{x}_i)}\n\\end{equation}\n\\end{theorem}\n\n\\begin{proposition}\n\\begin{equation}\n\\log\\left(\\sum\\limits_{i=1}^n \\lambda_i\\vec{x}_i\\right) \\geq \\sum\\limits_{i=1}^n {\\lambda_i \\log(\\vec{x}_i)}\n\\end{equation}\n\\end{proposition}\n\nNow let's proof why the $Q$ function should look like Equation \\ref{eqn:auxiliary-function}:\n\\begin{align}\n\\ell(\\vec{\\theta}) &= \\log{P(\\mathcal{D}|\\vec{\\theta})}  \\nonumber \\\\\n                &= \\log{{\\sum\\limits_{\\vec{z}} P(\\mathcal{D},\\vec{z}|\\vec{\\theta})}} \\nonumber \\\\\n\t\t\t\t&= \\log{{\\sum\\limits_{\\vec{z}} P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})}} \\nonumber \\\\\n\\ell(\\vec{\\theta})-\\ell(\\vec{\\theta}^{t-1}) &= \\log\\left[\\sum\\limits_{\\vec{z}} P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})\\right] - \\log{P(\\mathcal{D}|\\vec{\\theta}^{t-1})} \\nonumber \\\\\n                &= \\log\\left[\\sum\\limits_{\\vec{z}} P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})\\dfrac{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})}{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})}\\right] \\nonumber \\\\\n\t\t\t\t& \\quad -\\log{P(\\mathcal{D}|\\vec{\\theta}^{t-1})} \\nonumber \\\\\n\t\t\t\t&= \\log\\left[\\sum\\limits_{\\vec{z}} P(\\vec{z}|\\mathcal{D},\\theta^{t-1})\\dfrac{P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})}{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})}\\right] \\nonumber \\\\\n\t\t\t\t& \\quad - \\log{P(\\mathcal{D}|\\vec{\\theta}^{t-1})} \\nonumber \\\\\n\t\t\t\t&\\geq \\sum\\limits_{\\vec{z}} P(\\vec{z}|\\mathcal{D},\\theta^{t-1})\\log\\left[\\dfrac{P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})}{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})}\\right] \\nonumber \\\\\n\t\t\t\t& \\quad - \\log{P(\\mathcal{D}|\\vec{\\theta}^{t-1})} \\nonumber \\\\\n\t\t\t\t&= \\sum\\limits_{\\vec{z}} \\left\\{P(\\vec{z}|\\mathcal{D},\\theta^{t-1}) \\right. \\nonumber \\\\\n\t\t\t\t& \\quad \\left. \\log\\left[\\dfrac{P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})}{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})P(\\mathcal{D}|\\vec{\\theta}^{t-1})}\\right]\\right\\} \\nonumber\n\\end{align}\n\\begin{align}\nB(\\vec{\\theta},\\vec{\\theta}^{t-1}) & \\triangleq \\ell(\\vec{\\theta}^{t-1})+ \\nonumber \\\\\n & \\sum\\limits_{\\vec{z}} P(\\vec{z}|\\mathcal{D},\\theta^{t-1})\\log\\left[\\dfrac{P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})}{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})P(\\mathcal{D}|\\vec{\\theta}^{t-1})}\\right] \\nonumber \\\\\n\\Rightarrow & \\nonumber\n\\end{align}\n\n\\begin{align}\n\\vec{\\theta}^t &= \\arg\\max\\limits_{\\vec{\\theta}} B(\\vec{\\theta},\\vec{\\theta}^{t-1})  \\nonumber \\\\\n                &= \\arg\\max\\limits_{\\vec{\\theta}}\\left\\{ \\ell(\\vec{\\theta}^{t-1})+\\right. \\nonumber \\\\\n\t\t\t\t & \\quad \\left. \\sum\\limits_{\\vec{z}} P(\\vec{z}|\\mathcal{D},\\theta^{t-1})\\log\\left[\\dfrac{P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})}{P(\\vec{z}|\\mathcal{D},\\theta^{t-1})P(\\mathcal{D}|\\vec{\\theta}^{t-1})}\\right]\\right\\} \\nonumber \\\\\n\t\t\t\t& \\text{Now drop terms which are constant w.r.t. } \\vec{\\theta} \\nonumber \\\\\n\t\t\t\t&= \\arg\\max\\limits_{\\vec{\\theta}}{\\left\\{\\sum\\limits_{\\vec{z}} P(\\vec{z}|\\mathcal{D},\\theta^{t-1})\\log\\left[P(\\mathcal{D}|\\vec{z},\\vec{\\theta})P(\\vec{z}|\\vec{\\theta})\\right]\\right\\}} \\nonumber \\\\\n\t\t\t\t&= \\arg\\max\\limits_{\\vec{\\theta}}{\\left\\{\\sum\\limits_{\\vec{z}} P(\\vec{z}|\\mathcal{D},\\theta^{t-1})\\log\\left[P(\\mathcal{D},\\vec{z}|\\vec{\\theta})\\right]\\right\\}} \\nonumber \\\\\n\t\t\t\t&= \\arg\\max\\limits_{\\vec{\\theta}}{\\left\\{\\mathbb{E}_{\\vec{z}|\\mathcal{D},\\theta^{t-1}}\\log\\left[P(\\mathcal{D},\\vec{z}|\\vec{\\theta})\\right]\\right\\}} \\\\\n\t\t\t\t&\\triangleq \\arg\\max\\limits_{\\vec{\\theta}}{Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})}\n\\end{align}\n\n\n\\subsection{Convergence of the EM Algorithm *}\n\n\\subsubsection{Expected complete data log likelihood is a lower bound}\n\nNote that $\\ell(\\vec{\\theta}) \\geq B(\\vec{\\theta},\\vec{\\theta}^{t-1})$, and $\\ell(\\vec{\\theta}^{t-1}) \\geq B(\\vec{\\theta}^{t-1},\\vec{\\theta}^{t-1})$, which means $B(\\vec{\\theta},\\vec{\\theta}^{t-1})$ is an lower bound of $\\ell(\\vec{\\theta})$. If we maximize $B(\\vec{\\theta},\\vec{\\theta}^{t-1})$, then $\\ell(\\vec{\\theta})$ gets maximized, see Figure \\ref{fig:EM-algorithm}.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{EM-algorithm.png}\n\\caption{Graphical interpretation of a single iteration of the EM algorithm: The function $B(\\vec{\\theta},\\vec{\\theta}^{t-1})$ is bounded above by the log likelihood function $\\ell(\\vec{\\theta})$. The functions are equal at $\\vec{\\theta} = \\vec{\\theta}^{t-1}$. The EM algorithm chooses $\\vec{\\theta}^{t-1}$ as the value of $\\vec{\\theta}$ for which $B(\\vec{\\theta},\\vec{\\theta}^{t-1})$ is a maximum. Since $\\ell(\\vec{\\theta}) \\geq B(\\vec{\\theta},\\vec{\\theta}^{t-1})$ increasing $B(\\vec{\\theta},\\vec{\\theta}^{t-1})$ ensures that the value of the log likelihood function $\\ell(\\vec{\\theta})$ is increased at each step.}\n\\label{fig:EM-algorithm} \n\\end{figure}\n\nSince the expected complete data log likelihood $Q$ is derived from $B(\\vec{\\theta},\\vec{\\theta}^{t-1})$ by dropping terms which are constant w.r.t. $\\vec{\\theta}$, so it is also a lower bound to a lower bound of $\\ell(\\vec{\\theta})$.\n\n\n\\subsubsection{EM monotonically increases the observed data log likelihood}\n\n\n\\subsection{Generalization of EM Algorithm *}\nEM algorithm can be interpreted as F function's maximization-maximization algorithm, based on this interpretation there are many variations and generalization, e.g., generalized EM Algorithm(GEM).\n\n\n\\subsubsection{F function's maximization-maximization algorithm}\n\\begin{definition}\nGiven the probability distribution of the hidden variable $Z$ is $\\tilde{P}(Z)$, define \\textbf{F function} as the following:\n\\begin{equation}\nF(\\tilde{P},\\vec{\\theta})=\\mathbb{E}_{\\tilde{P}}\\left[\\log{P(X,Z|\\theta)}\\right]+H(\\tilde{P})\n\\end{equation}\nWhere $H(\\tilde{P})=-\\mathbb{E}_{\\tilde{P}}\\log\\tilde{P}(Z)$, which is $\\tilde{P}(Z)$'s entropy. Usually we assume that $P(X,Z|\\theta)$ is continuous w.r.t. $\\vec{\\theta}$, therefore $F(\\tilde{P},\\vec{\\theta})$ is continuous w.r.t. $\\tilde{P}$ and $\\vec{\\theta}$.\n\\end{definition}\n\n\\begin{lemma}\n\\label{lemma:F-function}\nFor a fixed $\\vec{\\theta}$, there is only one distribution $\\tilde{P}_{\\theta}$ which maximizes $F(\\tilde{P},\\vec{\\theta})$\n\\begin{equation}\n\\tilde{P}_{\\theta}(Z)=P(Z|X, \\vec{\\theta})\n\\end{equation}\nand $\\tilde{P}_{\\theta}$ is continuous w.r.t. $\\vec{\\theta}$.\n\\end{lemma}\n\n\\begin{proof}\nGiven a fixed $\\vec{\\theta}$, we can get $\\tilde{P}_{\\theta}$ which maximizes $F(\\tilde{P},\\vec{\\theta})$. we construct the Lagrangian\n\\begin{equation}\\begin{split}\n\\mathcal{L}(\\tilde{P}, \\vec{\\theta}) & =\\mathbb{E}_{\\tilde{P}}\\left[\\log{P(X,Z|\\theta)}\\right]-\\mathbb{E}_{\\tilde{P}}\\log\\tilde{P}_{\\theta}(Z) \\\\\n                                     & \\quad +\\lambda\\left[1-\\sum\\limits_Z{\\tilde{P}(Z)}\\right]\n\\end{split}\\end{equation}\n\nTake partial derivative with respect to $\\tilde{P}_{\\theta}(Z)$ then we get\n\\begin{equation}\n\\dfrac{\\partial \\mathcal{L}}{\\partial{\\tilde{P}_{\\theta}(Z)}}=\\log{P(X,Z|\\theta)}-\\log\\tilde{P}_{\\theta}(Z)-1-\\lambda  \\nonumber\n\\end{equation}\n\nLet it equal to 0, we can get\n\\begin{equation}\n\\lambda=\\log{P(X,Z|\\theta)}-\\log\\tilde{P}_{\\theta}(Z)-1 \\nonumber\n\\end{equation}\n\nThen we can derive that $\\tilde{P}_{\\theta}(Z)$ is proportional to $P(X,Z|\\theta)$\n\\begin{eqnarray}\n\\dfrac{P(X,Z|\\theta)}{\\tilde{P}_{\\theta}(Z)} &=& e^{1+\\lambda} \\nonumber \\\\\n\\Rightarrow \\tilde{P}_{\\theta}(Z) &=& \\dfrac{P(X,Z|\\vec{\\theta})}{e^{1+\\lambda}} \\nonumber \\\\\n\\sum\\limits_Z{\\tilde{P}_{\\theta}(Z)}=1 & \\Rightarrow & \\sum\\limits_Z{\\dfrac{P(X,Z|\\vec{\\theta})}{e^{1+\\lambda}}}=1 \\Rightarrow P(X|\\vec{\\theta})=e^{1+\\lambda} \\nonumber \\\\\n\\tilde{P}_{\\theta}(Z) &=& \\dfrac{P(X,Z|\\vec{\\theta})}{e^{1+\\lambda}} = \\dfrac{P(X,Z|\\vec{\\theta})}{P(X|\\vec{\\theta})}=P(Z|X, \\vec{\\theta}) \\nonumber\n\\end{eqnarray}\n\\end{proof}\n\n\\begin{lemma}\nIf $\\tilde{P}_{\\theta}(Z)=P(Z|X, \\vec{\\theta})$, then\n\\begin{equation}\nF(\\tilde{P},\\vec{\\theta})=\\log P(X|\\vec{\\theta})\n\\end{equation}\n\\end{lemma}\n\n\\begin{theorem}\nOne iteration of EM algorithm can be implemented as F function's maximization-maximization.\n\nAssume $\\vec{\\theta}^{t-1}$ is the estimation of $\\vec{\\theta}$ in the $(t-1)$-th iteration, $\\tilde{P}^{t-1}$ is the estimation of $\\tilde{P}$ in the $(t-1)$-th iteration. Then in the $t$-th iteration two steps are:\n\\begin{enumerate}\n\\item for fixed $\\vec{\\theta}^{t-1}$, find $\\tilde{P}^t$ that maximizes $F(\\tilde{P},\\vec{\\theta}^{t-1})$;\n\\item for fixed $\\tilde{P}^t$, find $\\vec{\\theta}^t$ that maximizes $F(\\tilde{P}^t,\\vec{\\theta})$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n(1) According to Lemma \\ref{lemma:F-function}, we can get\n\\begin{equation}\n\\tilde{P}^t(Z)=P(Z|X, \\vec{\\theta}^{t-1}) \\nonumber\n\\end{equation}\n\n(2) According above, we can get\n\\begin{eqnarray}\nF(\\tilde{P}^t,\\vec{\\theta}) &=& \\mathbb{E}_{\\tilde{P}^t}\\left[\\log{P(X,Z|\\theta)}\\right]+H(\\tilde{P}^t) \\nonumber \\\\\n    &=& \\sum\\limits_Z{P(Z|X,\\vec{\\theta}^{t-1})\\log{P(X,Z|\\theta)}}+H(\\tilde{P}^t) \\nonumber \\\\\n\t&=& Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})+H(\\tilde{P}^t)\\nonumber\n\\end{eqnarray}\n\nThen\n\\begin{equation}\n\\vec{\\theta}^t=\\arg\\max\\limits_{\\theta}F(\\tilde{P}^t,\\vec{\\theta})=\\arg\\max\\limits_{\\theta}Q(\\vec{\\theta}, \\vec{\\theta}^{t-1}) \\nonumber\n\\end{equation}\n\\end{proof}\n\n\n\\subsubsection{The Generalized EM Algorithm(GEM)}\nIn the formulation of the EM algorithm described above, $\\vec{\\theta}^t$ was chosen as the value of $\\vec{\\theta}$ for which $Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})$ was maximized. While this ensures the greatest increase in $\\ell(\\vec{\\theta})$, it is however possible to relax the requirement of maximization to one of simply increasing $Q(\\vec{\\theta}, \\vec{\\theta}^{t-1})$ so that $Q(\\vec{\\theta}^t, \\vec{\\theta}^{t-1}) \\geq Q(\\vec{\\theta}^{t-1}, \\vec{\\theta}^{t-1})$. This approach, to simply increase and not necessarily maximize $Q(\\vec{\\theta}^t, \\vec{\\theta}^{t-1})$ is known as the Generalized Expectation Maximization (GEM) algorithm and is often useful in cases where the maximization is difficult. The convergence of the GEM algorithm is similar to the EM algorithm.\n\n\n\\subsection{Online EM}\n\n\n\\subsection{Other EM variants *}\n\n\n\\section{Model selection for latent variable models}\n\\label{sec:Model-selection-for-LVM}\nWhen using LVMs, we must specify the number of latent variables, which controls the model complexity. In particular, in the case of mixture models, we must specify $K$, the number of clusters. Choosing these parameters is an example of model selection. We discuss some approaches below.\n\n\n\\subsection{Model selection for probabilistic models}\nThe optimal Bayesian approach, discussed in Section \\ref{sec:Bayesian-model-selection}, is to pick the model with the largest marginal likelihood, $K^*=\\arg\\max_k p(\\mathcal{D}|k)$.\n\nThere are two problems with this. First, evaluating the marginal likelihood for LVMs is quite difficult. In practice, simple approximations, such as BIC, can be used (see e.g., (Fraley and Raftery 2002)). Alternatively, we can use the cross-validated likelihood as a performance measure, although this can be slow, since it requires fitting each model $F$ times, where Fis the number of CV folds.\n\nThe second issue is the need to search over a potentially large number of models. The usual approach is to perform exhaustive search over all candidate values ofK. However, sometimes we can set the model to its maximal size, and then rely on the power of the Bayesian Occam’s razor to “kill off” unwanted components. An example of this will be shown in Section TODO 21.6.1.6, when we discuss variational Bayes.\n\nAn alternative approach is to perform stochastic sampling in the space of models. Traditional approaches, such as (Green 1998, 2003; Lunn et al. 2009), are based on reversible jump MCMC, and use birth moves to propose new centers, and death moves to kill off old centers. However, this can be slow and difficult to implement. A simpler approach is to use a Dirichlet process mixture model, which can be fit using Gibbs sampling, but still allows for an unbounded number of mixture components; see Section TODO 25.2 for details.\n\nPerhaps surprisingly, these sampling-based methods can be faster than the simple approach of evaluating the quality of eachKseparately. The reason is that fitting the model for each $K$ is often slow. By contrast, the sampling methods can often quickly determine that a certain value of $K$ is poor, and thus they need not waste time in that part of the posterior.\n\n\n\\subsection{Model selection for non-probabilistic methods}\nWhat if we are not using a probabilistic model? For example, how do we choose $K$ for the K-means algorithm? Since this does not correspond to a probability model, there is no likelihood, so none of the methods described above can be used.\n\nAn obvious proxy for the likelihood is the \\textbf{reconstruction error}. Define the squared reconstruction error of a data set $\\mathcal{D}$, using model complexity $K$, as follows:\n\\begin{equation}\nE(\\mathcal{D}, K) \\triangleq \\frac{1}{|\\mathcal{D}|}\\sum\\limits_{i=1}^N \\lVert\\vec{x}_i-\\hat{\\vec{x}}_i\\rVert^2\n\\end{equation}\n\nIn the case of K-means, the reconstruction is given by $\\hat{\\vec{x}}_i=\\vec{\\mu}_{z_i}$, where $z_i=\\arg\\min_k \\lVert\\vec{x}_i-\\hat{\\vec{\\mu}}_k\\rVert^2$, as explained in Section 11.4.2.6 TODO.\n\nIn supervised learning, we can always use cross validation to select between non-probabilistic models of different complexity, but this is not the case with unsupervised learning. The most common approach is to plot the reconstruction error on the training set versus $K$, and to try to identify a \\textbf{knee} or \\textbf{kink} in the curve. \n\n\n\\section{Fitting models with missing data}\nSuppose we want to fit a joint density model by maximum likelihood, but we have “holes” in our data matrix, due to missing data (usually represented by NaNs). More formally, let $O_{ij} =1$ if component $j$ of data case $i$ is observed, and let $O_{ij} =0$ otherwise. Let $\\vec{X}_v=\\{x_{ij}: \\vec{O}_{ij} =1\\}$ be the visible data, and $X_h=\\{x_{ij}: \\vec{O}_{ij} =0\\}$ be the missing or hidden data. Our goal is to compute\n\\begin{equation}\n\\hat{\\vec{\\theta}}=\\arg\\max_{\\vec{\\theta}} p(\\vec{X}_v|\\vec{\\theta}, \\vec{O})\n\\end{equation}\n\nUnder the missing at random assumption (see Section \\ref{sec:Dealing-with-missing-data}), we have\n\nTODO\n\n\\subsection{EM for the MLE of an MVN with missing data}\nTODO", "meta": {"hexsha": "7068735f710ec55286569d0792f73f63ccb7957c", "size": 37836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "static/stat661/chapterEM.tex", "max_stars_repo_name": "UrbanStudy/stat2019_website", "max_stars_repo_head_hexsha": "9d41d5caf4ece4c62bf0c301eb8c90429b17ce7d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-29T12:51:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-29T12:51:19.000Z", "max_issues_repo_path": "static/stat661/chapterEM.tex", "max_issues_repo_name": "UrbanStudy/stat2019_website", "max_issues_repo_head_hexsha": "9d41d5caf4ece4c62bf0c301eb8c90429b17ce7d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "static/stat661/chapterEM.tex", "max_forks_repo_name": "UrbanStudy/stat2019_website", "max_forks_repo_head_hexsha": "9d41d5caf4ece4c62bf0c301eb8c90429b17ce7d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.0262295082, "max_line_length": 776, "alphanum_fraction": 0.6844539592, "num_tokens": 12810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6968270133768818}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2-1}{n^3+7}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac1{n}$ is a $p$-series which diverges by the $p$-series test. If we use $a_n = \\frac{n^2-1}{n^3+7}$ and $b_n = \\frac1{n}$, then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{n^2-1}{n^3+7} \\cdot \\frac{n}{1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{n^3-n}{n^3+7} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac{3n^2-1}{3n^2} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{6n}{6n} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} 1\\\\\r\n&= 1\r\n\\end{align*}\r\nSo by the Limit Comparison Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2-1}{n^3+7}$ diverges.\r\n\r\n\\subsection*{Solution 2 (comment of method)}\r\n\r\nThe Direct Comparison Test will also work, but will involve finding first finding a fixed value of $K > 0$ such that\r\n\\[ \\frac{n^2-1}{n^3+7} \\geq K \\cdot \\frac1n.\\]\r\nAs the previous several series have shown, this will involve a bit of work to the point that the Limit Comparison Test (solution 1) will be easier/quicker.\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": "e540cd38a86faa146815e951c06e07da164fc93e", "size": 2046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/n5.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/n5.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/n5.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 34.1, "max_line_length": 165, "alphanum_fraction": 0.6329423265, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.6968270105065467}}
{"text": "\\subsection{Integrated Y Estimates}\n\nGiven a 3D radial model, we can also compute the spherically integrated Compton-y parameter, $Y_{\\it sph}(R)$\n\n\\begin{eqnarray}\nY_{\\it sph}(R) &=& {{\\sigma_T}\\over{m_e c^2}}\\integral{R}{0}{P(r)}{V}\\\\\\nonumber\n\\label{eq:ysph}\n     &=& {{\\sigma_T}\\over{m_e c^2}}\\integral{R}{0}{P(r) 4\\pi r^2}{r}\\\\\\nonumber\n     &=& {{\\sigma_T P_0}\\over{m_e c^2}}\\integral{R}{0}{p(r)4\\pi r^2}{r}\\\\\n     &=& y(0){1\\over{D_A\\theta_c}}{1\\over{I(0)}}\\integral{R}{0}{p(r)4\\pi r^2}{r}\n\\end{eqnarray}\n\nif we substitute $P_e(0)$ from Eq.~\\ref{eq:ytop}.  If we make the transformation $x = r/r_c$, to transform to dimensionless coordinates, we have:\n\n\\begin{eqnarray}\nY_{\\it sph}(R) &=& y(0){1\\over{D_A\\theta_cI(0)}}r^3_c\\integral{x_R}{0}{p(x)4\\pi x^2}{x}\\\\\\nonumber\n               &=& y(0){1\\over{D_A\\theta_cI(0)}}D^3_A\\theta^3_c\\integral{x_R}{0}{p(x)4\\pi x^2}{x}\\\\\\nonumber\n               &=& y(0)D^2_A\\theta^2_c{1\\over{I(0)}}\\integral{x_R}{0}{p(x)4\\pi x^2}{x}\\\\\\nonumber\n\\end{eqnarray}\n\nfor which we require the cosmology (i.e., $D_A$).\n\n\\subsection{Mass estimates}\n\nSimilarly, we see that\n\n\\begin{eqnarray}\nY_{\\it sph}(R) &=& {{\\sigma_T}\\over{m_e c^2}}\\integral{R}{0}{P_e(r)}{V}\\\\\\nonumber\n     &=& {{\\sigma_T}\\over{m_e c^2}}\\integral{R}{0}{P_e(r) 4\\pi r^2}{r}\\\\\\nonumber\n     &=& {{\\sigma_T P_e(0)}\\over{m_e c^2}}\\integral{R}{0}{p(r)4\\pi r^2}{r}\\\\\\nonumber\n     &=& {{k_B\\sigma_T T_e(0)}\\over{m_e c^2}}{1\\over{m_p\\mu_e}}\\integral{R}{0}{n_e(0)m_p\\mu_ep(r)4\\pi r^2}{r}\\\\\\nonumber\n     &=& {{k_B\\sigma_T T_e(0)}\\over{m_e c^2}}{1\\over{m_p\\mu_e}}\\Mgas(R)\\\\\\nonumber\n\\end{eqnarray}\n\nfrom which we have\n\n\\begin{eqnarray}\n\\Mgas(R) &=& m_p\\mu_e \\left({{m_e c^2}\\over{k_B T_e(0)}}\\right)\\left({{1}\\over{\\sigma_T}}\\right)Y_{\\it sph}(R)\\\\\\nonumber\n\\end{eqnarray}\n\nor\n\n\\begin{eqnarray}\n\\Mgas(R) &=& m_p\\mu_e {{y(0)}\\over{I(0)}}\\left({{m_e c^2}\\over{k_B T_e(0)}}\\right)\\left({{D^2_A\\theta^2_c}\\over{\\sigma_T}}\\right)\\integral{x_R}{0}{p(x)4\\pi x^2}{x}\n\\label{eq:mgas}\n\\end{eqnarray}\n\nfor which we require the cosmology (i.e., $D_A$) and the temperature normalization ($T_e(0)$).  Here $\\mu_e$ is the mean molecular weight per electron, defined as the ratio of the mean particle mass per electron to the mass of the hydrogen atom.\n\n", "meta": {"hexsha": "2dc13667df7ec0e5c2b63535c825d0d4bd368212", "size": 2230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/integrated.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/integrated.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/integrated.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": 44.6, "max_line_length": 245, "alphanum_fraction": 0.6282511211, "num_tokens": 955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6967788590967786}}
{"text": "\\problemname{Stand Behind Braum!}\n\nBraum is a tank character in the Multiplayer Online Battle Arena game League of Legends. Braum’s task is to absorb as\nmuch damage from the enemy so that his allies may win the fight. Recently, Braum's performance has fallen off and he just isn't as\ndominant as he once was. Refusing to be upset, Braum instead decides to hunker down and figure out some strategies so that he can \nbe a better tank. He decides that if he can calculate the amount of incoming damage, he can adjust his item purchases to\nbetter protect his allies.\\\\\n\nGiven an incoming onslaught of attacks, Braum wants to calculate the Total Damage he’ll take.\nAttacks come in three damage types, \\textbf{Physical Damage}, \\textbf{Magical Damage}, and \\textbf{True Damage}.\nWe can calculate the Total Damage Taken as a sum of the Physical, Magical, and True Damage Taken:\n\n\\begin{align*}\n    \\text{Physical Damage Taken} &= \\text{Physical Damage} \\cdot \\left( \\frac{100}{100 + \\text{Armor}}\\right) \\\\\n    \\text{Magical Damage Taken} &= \\text{Magical Damage} \\cdot \\left( \\frac{100}{100 + \\text{MR}}\\right) \\\\\n    \\text{True Damage Taken} &= \\text{True Damage}\n\\end{align*}\n\nBraum notices that the total damage posseses the following relationship, $\\alpha + \\beta + \\tau = 1$ . And furthermore\nwhere the values of $\\alpha, \\beta, \\tau$ possess the following relationships:\n\\begin{align*}\n    \\alpha &= \\frac{\\text{Physical Damage}}{\\text{Total Damage}} \\\\\n    \\beta &= \\frac{\\text{Magical Damage}}{\\text{Total Damage}} \\\\\n    \\tau  &= \\frac{\\text{True Damage}}{\\text{Total Damage}}\\\\\n\\end{align*}\n\n\\section*{Input}\nYou will be given two lines of input. The first line contains $\\alpha$, $\\beta$, $\\tau$, and $x$ representing the\npercent of Physical, Magical, True, and Total damage. The second line contains the Armor and MR values that Braum has.\n\n\\section*{Output}\nOutput the Total Damage Taken by Braum from the incoming attacks, rounded down to the nearest integer value.\n", "meta": {"hexsha": "3cd2be3b85444dbfa09bbb363790aeac594edf24", "size": 1974, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "standbehindbraum/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": "standbehindbraum/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": "standbehindbraum/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": 59.8181818182, "max_line_length": 130, "alphanum_fraction": 0.73556231, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6967749947277854}}
{"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 5.} Sequential games with complete information I: Backward Induction}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\n\\subsection*{Exercise 1: Sequential prisoner's dilemma with remorse}\n\nRevisit the prisoner's dilemma with remorse (Example 2.13 from the lecture). The\npayoff matrix is:\n\n\\begin{equation*}\n    \\begin{blockarray}{ccc}\n        & \\text{Silence} & \\text{Confess} \\\\\n        \\begin{block}{c(cc)}\n            \\text{Silence} & (3, 3) & (0, 0) \\\\\n            \\text{Confess} & (4, 0) & (1, 1) \\\\\n        \\end{block}\n    \\end{blockarray}\n\\end{equation*}\n\nWe already know that if both players move simultaneously, then the only Nash\nequilibrium is (Confess, Confess).\n\n\\textbf{Now solve this game with backward induction, assuming that}\n\n\\begin{enumerate}\n    \\item the row player moves first,\n    \\item the column player moves first,\n\\end{enumerate}\n\n\\textbf{and interpret the result.}\n\n\\subsection*{Exercise 2: Ultimatum bargain in 2 rounds}\n\nThere is a good that is worth 1\\euro~to the buyer and 0\\euro~to the seller.\nSequence of moves:\n\n\\begin{enumerate}\n    \\item Seller names a price \\(p \\in \\{0.01, 0.02, \\dots, 0.99\\}\\).\n    \\item Buyer accepts or rejects the offer. If buyer accepts, the payoffs are\n    \\(p\\) for the seller, \\(1 - p\\) for the buyer and the game is over.\n    \\item Otherwise, the buyer names a price \\(p \\in \\{0.01, 0.02, \\dots,\n    0.99\\}\\).\n    \\item Seller accepts or rejects the offer. If the seller accepts, the\n    payoffs are \\(p - \\delta\\) for the seller, and \\(1 - p - \\delta\\) for the buyer\n    where \\(\\delta=0.045\\) reflects the cost of having to go through a long\n    negotiation. If the seller rejects, the payoff of both players is\n    \\(-\\delta\\).\n\\end{enumerate}\n\n\\textbf{Solve by backward induction, and interpret the result.}\n\n\\subsection*{Exercise 3: Stackelberg Duopoly}\n\nSimilar to the Cournot duopoly game consider the following situation:\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\nHowever, now assume that Firm 1 decides first, and Firm 2 observes Firms 1's\ndecision before choosing an action.\n\n\\textbf{Solve the game by backward induction (for \\(a=10, b=1, c=1\\)) and\ncompare the result to the Nash equilibrium of the Cournot duopoly\n(\\(\\hat x^{(1)} = \\hat x ^{(2)}  = 3)\\)}.\n\n[Hint: First you should find the best response of Firm 2. That is, for any given\noutput \\(x^{(1)}\\) of Firm 1, compute how Firm 2 would react if it wants to maximize\nits payoffs. Using this, compute how Firm 1 can maximize its own payoff when it\ntakes into account that Firm 2 will react according to its best response.]\n\n\\subsection*{Bonus Exercise 1: Properties of backward induction}\n\n\\textbf{\nProve that for any finite game with perfect information (i.e. in any game in which\nbackward induction can be applied) the solution defined by backward induction\nis a Nash equilibrium.}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "ae1f8916ed9bc78ad56649fb7d59adb67bb00bbb", "size": 3427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w5.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/w5.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/w5.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": 33.5980392157, "max_line_length": 100, "alphanum_fraction": 0.6898161657, "num_tokens": 1042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.6967393408150124}}
{"text": "\\section{Model Description}\n\nThe eclipse module is responsible for determining whether or not a spacecraft is within the shadow of a solar eclipse and if so, how much. The module finds the states of the sun, spacecraft and planets of interest, allowing each body's postition to be related and the construction of the conical shadow model. This provides the means for computing what percent of the spacecraft is illuminated where a shadow factor of 0.0 represents a total eclipse and 1.0 represents no eclipse.\n\nTo determine the states of the bodies in question, messages are passed into the code. For the spacecraft, Cartesian vectors provide the position and velocity of its center of mass. For the sun and planets, a time is chosen and input into the module along with SPK, LSK, and PCK files, indicating ephemeris data, leapsecond information, and reference frame orientation. The planets desired to be used in the module are specified through the Basilisk messaging system, where corresponding strings (e.g. \"venus\", \"earth\", or \"mars barycenter\") are input as Spice Objects. This allows the state data to be obtained at the given time, using Spice and the kernel files. The kernels used when testing are given in the Test Parameters section. Fig. \\ref{fig:ConShad} illustrates how the states are represented and will be identified in the mathematical model. Calculations in this model are taken from Montenbruck and Gill's \\textit{Satellite Orbits Models, Methods and Applications} text \\cite{bib:1}.\n\\begin{figure}[ht]\n\t\\centering\n\t\\captionsetup{justification=centering}\n\t\\includegraphics[width=0.9\\textwidth]{Figures/conical_shadow.png}\n\t\\caption{Representation of a Conical Shadow}\\label{fig:ConShad}\n\\end{figure} \n\\subsection{Mathematical model}\n\n\\subsubsection{Determining States}\nThe initial step in the eclipse module is to obtain the celestial bodies' state data and transform them into usable terms. The relationships shown below remove the dependancy on relating position to the inertial frame \\textit{N} and instead utilize the planet \\textit{P}, spacecraft body \\textit{B}, and helio \\textit{H} frames.\n\\begin{equation} \\label{eq:1}\n\\bm{s}_{P/H} = \\bm{r}_{N/H} - \\bm{r}_{N/P}\n\\end{equation}\n\\begin{equation} \\label{eq:2}\n\\bm{r}_{B/H} = \\bm{r}_{N/H} - \\bm{r}_{N/B}\n\\end{equation}\n\\begin{equation} \\label{eq:3}\n\\bm{s}_{P/B} = \\bm{r}_{N/B} - \\bm{r}_{N/P}\n\\end{equation}\n\nThe previous three equations provide coordinates for the sun with respect to both the occulting planet and occulted spacecraft as well as the spacecraft's position with respect to the planet, respectively. The parameters on the right side of these equations come from the input state data where $\\bm{r}_{N/H}$, $\\bm{r}_{N/P}$, and $\\bm{r}_{N/B}$ are the sun, planet, and spacecraft positions in the inertial frame.\n\nThis module supports the use of multiple occulting bodies, so it is important to analyze only the planet with the highest potential to cause an eclipse. Thus, the closest planet is determined by comparing the magnitude of each planet's distance to the spacecraft, $|\\bm{s}_{P/B}|$. Note that if the spacecraft is closer to the sun than the planet, i.e. $|\\bm{r}_{B/H}| < |\\bm{s}_{P/H}|$, an eclipse is not possible and the shadow fraction is immediately set to 1.0.\n\n\\subsection{Eclipse Conditions}\nWhen analyzing the conical shadow model, there are critical distances and conical dimensions that must be considered. These parameters are determined by first knowing the planet's equatorial radius $r_P$, which is used to solve for the angles of the shadow cones. Angles $f_1$ and $f_2$ are computed as shown below, where the subscript 1 relates to the cone of the penumbra and 2 relates to the umbra.\n\\begin{equation} \\label{eq:7}\nf_1 = \\frac{\\arcsin(r_H + r_P)}{|\\bm{s}_{P/H}|}\n\\end{equation}\n \\begin{equation} \\label{eq:8}\n f_2 = \\frac{\\arcsin(r_H - r_P)}{|\\bm{s}_{P/H}|}\n \\end{equation}\n\nHere $r_H$ indicates the equatorial radius of the sun, which is 695000 km. Both the sun and planet radii must be input in terms of meters.\n\nAs shown by Fig. \\ref{fig:ConShad}, the fundamental plane is perpendicular to the shadow axis and coincident with the spacecraft body. The distance between the plane-axis intersection and the center of the planet is given by $s_0$ as shown by Eq. \\ref{eq:9}.\n\\begin{equation} \\label{eq:9}\ns_0 = \\frac{-\\bm{s}_{P/B} \\cdot \\bm{s}_{P/H}}{|\\bm{s}_{P/H}|} \n\\end{equation}\n\nThis distance and the shadow cone angles can now be used to determine the distances, $c_1$ and $c_2$, between the fundamental plane and the cones' vertices $V_1$ and $V_2$. These are calculated as follows:\n\\begin{equation} \\label{eq:10}\nc_1 = s_0 + \\frac{r_P}{\\sin(f_1)}\n\\end{equation}\n\\begin{equation} \\label{eq:11}\nc_2 = s_0 - \\frac{r_P}{\\sin(f_2)}\n\\end{equation}\n\nAs shown in Eq. \\ref{eq:12} and \\ref{eq:13}, these are then used to find the radii, $l_1$ and $l_2$, of the shadow cones in the fundamental plane.\n\\begin{equation} \\label{eq:12}\nl_1 = c_1 \\tan(f_1)\n\\end{equation}\n\\begin{equation} \\label{eq:13}\nl_2 = c_2 \\tan(f_2)\n\\end{equation}\n\nFinding these parameters provides insight into the type of eclipse that the spacecraft is experiencing. To determine the type, it is useful to compare the cone radii to the distance between the spacecraft and the shadow axis, which is given by $l$.\n\\begin{equation}\\label{eq:14}\nl = \\sqrt{|\\bm{s}_{P/B}|^2 - s^2_0}\n\\end{equation}\nTotal and annular eclipses both require the spacecraft to be relatively close to the shadow axis, where $|l|<|l_2|$. The difference between these two types is that the planet is closer to the spacecraft for a total eclipse ($c_2 < 0$) than during an annular eclipse ($c_2 > 0$). If the spacecraft is further from the shadow axis but still within a cone radius ($|l|<|l_1|$), it is experiencing a partial eclipse.\n\n\\subsection{Percent Shadow}\nWith the eclipse type determined, the shadow fraction can now be found. To find the shadow fraction, the apparent radii of the sun and planet and the apparent seperation of both bodies are needed. These are given, respectively, by $a$, $b$, and $c$ in the equations below.\n\\begin{equation} \\label{eq:15}\na = \\arcsin(\\frac{r_H}{|\\bm{r}_{B/H}|})\n\\end{equation}\n\\begin{equation} \\label{eq:16}\nb = \\arcsin(\\frac{r_P}{|\\bm{s}_{P/B}|})\n\\end{equation}\n\\begin{equation} \\label{eq:17}\nc = \\arccos(\\frac{-\\bm{s}_{P/B} \\cdot \\bm{r}_{B/H}}{|\\bm{s}_{P/B}| |\\bm{r}_{B/H}|})\n\\end{equation}\nFig. \\ref{fig:disk} below illustrates the overlapping disk model that represents the occultation, where the solid orange line indicates the sun and the dotted blue line indicates the planet.\n\\begin{figure}\n\t\t\\centering\n\t\\captionsetup{justification=centering}\n\t\\includegraphics[width=0.9\\textwidth]{Figures/diskModel.png}\n\t\\caption{Occultation Disk Model}\\label{fig:disk}\n\\end{figure}\n\\subsubsection{Total Eclipse ($c < b-a$)}\n\nThis type assumes that the apparent radius of the planet is larger than that of the sun ($b>a$). A total eclipse produces a total shadow, so the shadow fraction is 0.0.\n\\subsubsection{Annular Eclipse ($c < a-b$)}\n\nThis type assumes the apparent radius of the sun is larger than that of the planet ($a>b$). Use the equation for a circular area, $A = \\pi r^2$, to find the area of the sun and planet faces, replacing $r$ with the corresponding apparent radius. The shadow fraction is then just the ratio of the planet's area to the sun's area.\n\\begin{equation} \\label{eq:18}\nShadow Fraction = \\frac{A_P}{A_H}\n\\end{equation}\n\\subsubsection{Partial Eclipse ($c < a+ b$)}\n\nFor a partial eclipse, the occulted area is given by Eq. \\ref{eq:19}.\n\\begin{equation} \\label{eq:19}\nA = a^2 \\arccos(\\frac{x}{a}) + b^2 \\arccos(\\frac{c-x}{b}) - cy\n\\end{equation}\nParameters a, b, and c are those calculated previously in Eq. \\ref{eq:15}, \\ref{eq:16}, and \\ref{eq:17}. The values x and y are given by the following equations.\n\\begin{equation}\nx = \\frac{c^2 + a^2 - b^2}{2c}\n\\end{equation}\n\\begin{equation}\ny = \\sqrt{a^2 - x^2}\n\\end{equation}\n\nLike with the annular partial eclipse, the shadow factor for this type is the ratio between the occulted area and the sun's apparent area. This is given by the equation below.\n\\begin{equation}\nShadow Fraction = 1 - \\frac{A}{\\pi a^2}\n\\end{equation}", "meta": {"hexsha": "421eaed3e6255e8ac2b57a7edf14924ebffd746f", "size": 8194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/environment/eclipse/_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/environment/eclipse/_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/environment/eclipse/_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": 73.1607142857, "max_line_length": 994, "alphanum_fraction": 0.7456675616, "num_tokens": 2343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.6967293762175119}}
{"text": "\n\\subsection{Group action}\n\nWe have a group \\(G\\) and a set \\(S\\).\n\nWe have a function \\(g.s\\) which maps onto \\(S\\) such that:\n\n\\begin{itemize}\n\\item \\(I.s=s\\)\n\\item \\((gh).s=g(h.s)\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "dce5384664fc2048a9fa119a0854fdb8dddef47f", "size": 200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/07-01-groupAction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/07-01-groupAction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/07-01-groupAction.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.3846153846, "max_line_length": 59, "alphanum_fraction": 0.6, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6966302010756839}}
{"text": "\n\\subsection{Length of paths in Riemann manifolds}\n\nWe can work out the length of a path through a Riemann manifold.\n\nThe geodesic is the shortest such path.\n\nThe Riemann metric between two points is the length of the geodesic.\n\n\n", "meta": {"hexsha": "a0b142fd4b4ecf3d96c58fc436ecbfa4110dfe67", "size": 230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-03-paths.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-03-paths.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-03-paths.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.9090909091, "max_line_length": 68, "alphanum_fraction": 0.7826086957, "num_tokens": 58, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6965920389453091}}
{"text": "\\documentclass{amsart}\r\n\\usepackage{hyperref,amsmath,amsfonts}\r\n\r\n\\begin{document}\r\n\\title{Library for Quadratic Programming}\r\n\\author{Vojt\\v{e}ch Franc\\\\ xfrancv at cmp.felk.cvut.cz} \r\n\\maketitle\r\n%\\tableofcontents\r\n\r\n\\def\\x{\\mathbf x}\r\n\\def\\f{\\mathbf f}\r\n\\def\\a{\\mathbf a}\r\n\\def\\H{\\mathbf H}\r\n\\def\\Sequ{\\rm S_{\\rm equ}}\r\n\\def\\Sneq{\\rm S_{\\rm neq}}\r\n\\renewcommand{\\Re}{\\mathbb{R}}\r\n\r\n\\section*{Introduction}\r\n\r\nLIBQP is C library which implements algorithms for solving two special instances of\r\nconvex Quadratic Programming (QP):\r\n\r\n%\\begin{enumerate}\r\n % \\item \r\n\r\n\\large\r\n\\subsection*{QP task with simplex constraints} This QP task is defined as follows\r\n\\[\r\n   \\begin{array}{lrcll}\r\n     \\mbox{minimize} &\\multicolumn{4}{l}{\\displaystyle\\frac{1}{2}\\x^T \\H \\x +\r\n       \\x^T \\f} \\\\ \\\\\r\n     \\mbox{subject to} \r\n     & \\displaystyle\\sum_{i\\in I_k} x_i & = & b_k\\:, & k\\in \\Sequ \\\\ \r\n     & \\displaystyle\\sum_{i\\in I_k} x_i & \\leq & b_k\\:, & k\\in \\Sneq \\\\\r\n     & x_i & \\geq & 0\\:, & i\\in I \\:.\r\n   \\end{array}\r\n\\]\r\nwhere \\(\\x = (x_1,\\ldots,x_n)\\in\\Re^n\\) is the optimized vector, \\(\\H\r\n\\in\\Re^{n\\times n}\\) is a symmetric positive semi-definite matrix,\r\n\\(\\f\\in\\Re^n\\) is a vector, \\(I =\r\n\\{1,\\ldots,n\\}\\) is an index set, \\(\\{I_1,\\ldots,I_m\\}\\) are subsets of \\(I\\)\r\nsuch that  \\(I_1\\cup \\ldots \\cup I_k = I\\) and \\(I_1 \\cap \\ldots \\cap I_k =\r\n\\emptyset\\), \\(\\Sequ\\) and \\(\\Sneq\\) are index sets such that  \r\n\\(\\Sequ \\cup \\Sneq = \\{1,\\ldots,m\\}\\) and \\(\\Sequ \\cap \\Sneq = \\emptyset\\),\r\n\\((b_1,\\ldots,b_m)\\in\\Re^m\\) are positive numbers.\r\n\r\n\r\nThe implemented solver (\\verb|libqp_splx.c|) is a generalization of the method\r\nproposed in~\\cite{Franc-TR-2006-04,Fan-JMLR05}. It is based on the Sequential Minimal\r\nOptimization (SMO) algorithm with an improved working set selection\r\nstrategy. Solving instances of this QP task is required, for example, in machine \r\nlearning methods like Structured SVM learning, Bundle Methods for Risk\r\nMinimization, binary SVM with L2-soft margin, etc. \r\n\r\n\\subsection*{QP task with box constraints and a single linear equality constraint}\r\nThis QP task is defined as follows\r\n\\[\r\n  \\begin{array}{lrcl}\r\n    \\mbox{minimize} &\\multicolumn{3}{l}{\\displaystyle\\frac{1}{2}\\x^T \\H \\x +\r\n      \\x^T \\f} \\\\ \\\\\r\n    \\mbox{subject to} \r\n    & \\displaystyle\\x^T \\a & = & b\\:, \\\\ \r\n    & \\multicolumn{3}{c}{\\displaystyle l_i \\leq x_i \\leq u_i\\:, \\qquad i=1,\\ldots,n}\\:,\r\n  \\end{array}\r\n\\]\r\nwhere \\(\\x = (x_1,\\ldots,x_n)\\in\\Re^n\\) is the optimized vector, \\(\\H\r\n\\in\\Re^{n\\times n}\\) is a symmetric positive semi-definite matrix,\r\n\\(\\f\\in\\Re^n\\) is a vector, $\\a\\in\\Re^n$ is a vector with non-zero entries,\r\n$b\\in\\Re$ is a scalar, $(l_1,\\ldots,l_n)\\in(\\Re \\cup \\{-\\infty\\})^n$ and\r\n$(u_1,\\ldots,u_n)\\in(\\Re\\cup\\{\\infty\\})^n$ are lower and upper bounds,\r\nrespectively. \r\n\r\nThe solver (\\verb|libqp_gsmo.c|) is the exact implementation of the \r\nGeneralized Sequential Minimal Optimizer proposed in~\\cite{Keerthi-00}.\r\nSolving this QP task is required, for example, when training binary \r\nSVM with L1-soft margin. \r\n\r\n\\section*{Interfaces}\r\n\r\nLIBQP is implemented in C language and interfaces to Matlab.\r\n\r\n\\section*{Platforms}\r\n\r\nGNU/Linux. It should run also under Windows though not tested.\r\n\r\n\\section*{Installation}\r\n\r\nLIBQP can be downloaded from \\url{http://cmp.felk.cvut.cz/~xfrancv/libqp/libqp.zip}.\r\n\r\n\\subsection*{MATLAB}\r\n\r\n\\begin{enumerate}\r\n  \\item Run Matlab and go to the folder \\verb|libqp_root/matlab|\r\n    \\begin{verbatim}\r\n      cd libqp_root/matlab\r\n    \\end{verbatim}\r\n  \\item Compile mex files by running\r\n    \\begin{verbatim}\r\n      libqp_compile\r\n    \\end{verbatim}\r\n\\end{enumerate}\r\nNow you can use \\verb|libqp_splx| and \\verb|libqp_gsmo| solvers located in\r\n\\verb|libqp_root/matlab|. To make these function visible from Matlab you \r\nneed to add \r\n\\begin{verbatim}\r\n    addpath('libqp_root/matlab')\r\n\\end{verbatim}\r\nto your \\verb|startup.m| file. \r\n\r\n\\noindent\r\nTo test the solvers run scripts\r\n\\begin{verbatim}\r\n  libqp_splx_test\r\n  libqp_gsmo_test\r\n\\end{verbatim}\r\n\r\n\r\n\\subsection*{Example application}\r\n\r\n\\begin{enumerate}\r\n  \\item Go to the folder \\verb|libqp_root/examples|\r\n    \\begin{verbatim}      \r\n      cd libqp_root/examples\r\n    \\end{verbatim}\r\n  \\item Issue make \r\n    \\begin{verbatim}      \r\n      make\r\n    \\end{verbatim}\r\n\\end{enumerate}\r\nNow you can run test script\r\n\\begin{verbatim}      \r\n    ./run_test\r\n\\end{verbatim}\r\n\r\n\r\n\\section*{License}\r\n\r\nLIBQP is licensed under the GPL version 3 (\\url{http://gplv3.fsf.org/}).\r\n\r\n\r\n\\begin{thebibliography}{00}\r\n\\bibitem[1]{Franc-TR-2006-04}\r\nV. Franc, V. Hlavac. A Novel Algorithm for Learning Support Vector Machines\r\nwith Structured Output Spaces. Research Report K333 22/06, CTU-CMP-2006-04. \r\nMay, 2006. \r\n\\url{ftp://cmp.felk.cvut.cz/pub/cmp/articles/franc/Franc-TR-2006-04.ps}\r\n\\bibitem[2]{Fan-JMLR05}\r\nR.-E. Fan, P.-H. Chen, C.-J. Lin. Working Set Selection Using Second Order \r\nInformation for Training SVM. JMLR. vol 6. 2005.\r\n\\url{TBA}\r\n\\bibitem[3]{Keerthi-00}\r\nS.-S. Keerthi, E.G.Gilbert. Convergence of a Generalized SMO Algorithm for SVM \r\nClassifier Design. Technical Report CD-00-01, Control Division, Dept. of Mechanical \r\nand Production Engineering, National University of Singapore, 2000. \r\n\\url{http://citeseer.ist.psu.edu/keerthi00convergence.html}\r\n\\end{thebibliography}\r\n\\end{document}\r\n", "meta": {"hexsha": "bb84379985a9c4085874fa3bd5846ca9468c3592", "size": 5315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tonic-suite/img/flandmark-master/learning/libqp/doc/libqp.tex", "max_stars_repo_name": "csb1024/djinn_csb", "max_stars_repo_head_hexsha": "de50d6b6bc9c137e9f4b881de9048eba9e83142d", "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": "tonic-suite/img/flandmark-master/learning/libqp/doc/libqp.tex", "max_issues_repo_name": "csb1024/djinn_csb", "max_issues_repo_head_hexsha": "de50d6b6bc9c137e9f4b881de9048eba9e83142d", "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": "tonic-suite/img/flandmark-master/learning/libqp/doc/libqp.tex", "max_forks_repo_name": "csb1024/djinn_csb", "max_forks_repo_head_hexsha": "de50d6b6bc9c137e9f4b881de9048eba9e83142d", "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.6392405063, "max_line_length": 88, "alphanum_fraction": 0.6748824083, "num_tokens": 1751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6965621422928022}}
{"text": "\\section{ReLU multigrid method for nonnegative solution}\nConsidering $f = (1, 1, ..., 1)^\\top$,\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$(u^{1}, u^2, \\cdots, u^J) = {\\text{MG0}}(f; u^0; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-ReLUSlash0}\n\t\\begin{algorithmic}\n\t\t\\State Set up\n\t\t$$\n\t\tf^1 = f, \\quad u^{1}=u^0.\n\t\t$$\n\t\t\\State Smoothing and restriction from fine to coarse level (nested)\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\tu^{\\ell} \\leftarrow u^{\\ell} + S^\\ell \\ast \\text{Relu}( (f^\\ell - A_\\ell \\ast u^{\\ell})).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Form restricted residual and set initial guess:\n\t\t$$\n\t\tu^{\\ell+1,0} \\leftarrow 0, \\quad f^{\\ell+1} \\leftarrow R \\ast_2 (f^\\ell -  A_\\ell \\ast u^{\\ell}), A_{\\ell+1} = R \\ast_2 A_\\ell \\ast (R\\ast_2^\\top).\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nAlgorithm 5 is not convergent.\n\n\\newpage\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$(u^{1}, u^2, \\cdots, u^J) = {\\text{MG0}}(f; u^0; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-ReLUSlash1}\n\t\\begin{algorithmic}\n\t\t\\State Set up\n\t\t$$\n\t\tf^1 = f, \\quad u^{1}=u^0.\n\t\t$$\n\t\t\\State Smoothing and restriction from fine to coarse level (nested)\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\tu^{\\ell} \\leftarrow u^{\\ell} +\\text{Relu}( S^\\ell \\ast  (f^\\ell - A_\\ell \\ast u^{\\ell})).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Form restricted residual and set initial guess:\n\t\t$$\n\t\tu^{\\ell+1,0} \\leftarrow 0, \\quad f^{\\ell+1} \\leftarrow R \\ast_2 (f^\\ell -  A_\\ell \\ast u^{\\ell}), A_{\\ell+1} = R \\ast_2 A_\\ell \\ast (R\\ast_2^\\top).\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nAlgorithm 6 is convergent, the iterative steps is list below. $l = 2$\n\\\\\n\\begin{tabular}{c|c|c|}\n\tJ &MG& Algorithm 6\\\\ \\hline\n\t2 & 15 & 27 \\\\\\hline\n\t3 & 16 & 35 \\\\\\hline\n\t4 & 17 & 38 \\\\\\hline\n\\end{tabular}\n\n\n\\subsection{$\\Pi$ is interpolation}\n\\textbf{Not Convergent}\n\t\t\\begin{equation}\n\t\tu^{\\ell,i} \\leftarrow u^{\\ell,i-1} + \\text{Relu}\\circ B_{\\ell,i}  ({f^\\ell -  A^{\\ell} (u^{\\ell,i-1})}).\n\t\t\\end{equation}\n\t \\begin{equation}\n\t u^{\\ell,i} \\leftarrow u^{\\ell,i-1} + B_{\\ell,i}\\circ\\text{Relu}({f^\\ell -  A^{\\ell} (u^{\\ell,i-1})}).\n\t \\end{equation}\n\\textbf{Almost the same as without Relu}\n\t \\begin{equation}\n\t u^{\\ell,i} \\leftarrow u^{\\ell,i-1} +B_{\\ell,i}  ({f^\\ell -   \\text{Relu}\\circ A^{\\ell} (u^{\\ell,i-1})}).\n\t \\end{equation}\n\t \\begin{equation}\n\t u^{\\ell,i} \\leftarrow u^{\\ell,i-1} + B_{\\ell,i}  ({f^\\ell -  A^{\\ell} \\circ\\text{Relu}(u^{\\ell,i-1})}).\n\t \\end{equation}", "meta": {"hexsha": "fc62516234540f2e78c887061e06ca3cdfdc9e45", "size": 2564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.13-ReLU-multigrid.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.13-ReLU-multigrid.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.13-ReLU-multigrid.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": 33.2987012987, "max_line_length": 149, "alphanum_fraction": 0.6010140406, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6965621166373209}}
{"text": "\\chapter{Exponents}\n\nLet's quickly review exponents. Ancient scientists started coming up\nwith a lot of formulas that involved multiplying the same number\nseveral times.  For example, if they knew that if a sphere was $r$\ncentimeters in radius, its volume in milliliters was\n\n$$V = \\frac{4}{3} \\times \\pi \\times r \\times r \\times r$$\n\nThey did two things to make the notation less messy.  First, they\ndecided that if two numbers were written next to each other, the\nreader would assume that meant ``multiply them''.  Second, they came\nup with the exponent, a little number that was lifted up off the\nbaseline of the text, that meant ``multiply it by itself''.  For\nexample $5^3$ was the same as $5 \\times 5 \\times 5$.\\index{exponents}\n\nNow the formula for the volume of a sphere is written\n\n$$V = \\frac{4}{3} \\pi r^3$$\n\nTidy, right? In an exponent expression like this, we say that $r$ is\n\\textit{the base} and $3$ is \\textit{the exponent}.\n\n\\section{Identities for Exponents}\n\nWhat about exponents of exponents?  What is $\\left(5^3\\right)^2$?\n\n$$\\left(5^3\\right)^2 = (5 \\times 5 \\times 5)^2 = (5 \\times 5 \\times 5)(5 \\times 5 \\times 5) = 5^6$$\n\nIn general, for any $a$, $b$, and $c$:\n\n$$\\left(a^b\\right)^c = a^{(bc)}$$\n\nIf you have $\\left( 5^3 \\right) \\left(5^4 \\right)$ that is just $5 \\times 5 \\times 5 \\times 5 \\times 5 \\times 5 \\times 5$ or $5^7$\n\nThe general rule is, for any $a$, $b$, and $c$\n\n$$\\left(a^b\\right)\\left(a^c\\right) = a^{(b + c)}$$\n\nMathematicians \\textit{love} this rule, so we keep extending the idea\nof exponents to keep this rule true. For example, at some point\nsomeone asked ``What about $5^0$?'' According to the rule, $5^{2}$\nmust equal $5^{(2 + 0)}$ which must equal\n$\\left(5^2\\right)\\left(5^0\\right)$.  Thus, $5^2$ must be 1. So\nmathematicians declared ``Anything to the power of 0 is 1''.\\index{exponents!zero}\n\nActually, we don't typically assume that $0^0 = 1$. It is just too\nweird. So we say, that for any $a$ not equal to zero,\n\n$$a^0 = 1$$\n\nWhat about $5^{(-2)}$?  By our beloved rule, we know that\n$\\left(5^{-2}\\right)\\left(5^5\\right)$ must be equal to $5^3$, right?\nSo $5^{-2}$ must be equal to $\\frac{1}{5^2}$.\\index{exponents!negative}\n\nWe say, for any $a$ not equal to zero and any $b$,\n\n$$a^{-b} = \\frac{1}{a^{b}}$$\n\nThis make dividing one exponentional expression by another (with the same base) easy:\n\n$$\\frac{a^b}{a^c} = a^{(b-c)}$$\n\nWe often say ``cancel out'' for this.  Here I can ``cancel out'' $x^2$:\n\n$$\\frac{x^5}{x^2} = x^3$$\n\nWhat about $5^{\\frac{1}{3}}$? By the beloved rule, we know that $5^{\\frac{1}{3}}5^{\\frac{1}{3}}5^{\\frac{1}{3}}$ must equal $5^1$. Thus $5^{\\frac{1}{3}} = \\sqrt[3]{5}$.\\index{exponents!fractions}\n\nWe say, for any $a$ and $b$ not equal to zero and any $c$ greater than zero,\n\n$$a^{\\frac{b}{c}} = a^b \\sqrt[c]{a}$$\n\nBefore you go on to the exercises, note that the beloved rule demands a common base.\n\\begin{itemize}\n\\item We can combine these: $\\left(5^2\\right)\\left(5^4\\right) = 5^6$\n\\item We cannot combine: $\\left(5^2\\right)\\left(3^5\\right)$\n\\end{itemize}\n\nWith that said, we note that, for any $a$,$b$, and $c$:\n\n$$\\left(ab\\right)^c = \\left(a^c\\right) \\left(b^c\\right)$$\n\nSo, for example, if I were asked to simplify\n$\\left(3^4\\right)\\left(6^2\\right)$, I would note that $6 = 2 \\times\n3$, so\n\n$$\\left(3^4\\right)\\left(6^2\\right) = \\left(3^4\\right)\\left(3^2\\right)\\left(2^2\\right)  = \\left(3^6\\right)\\left(2^2\\right)$$\n\n\nIf these ideas are new to you (or maybe they have been forgotten),\nwatch the Khan Academy's \\textbf{Intro to rational exponents} video at\n\\url{https://youtu.be/lZfXc4nHooo}.\n\n\n", "meta": {"hexsha": "cf4fe517ad39033cd6dff9f962a80cdbdd8bd296", "size": 3577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Spreadsheets/exponents_review-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/exponents_review-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/exponents_review-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.2604166667, "max_line_length": 194, "alphanum_fraction": 0.6645233436, "num_tokens": 1276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936435, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.6965348673475567}}
{"text": "\n% \\section*{Why $S^1$ is a double cover of the Mobius strip.}\n% \\newpage\n\\section{Galois covers}\n\\label{sec:GaloisCovers}\n\nWe  will assume that all our maps are simplicial and all our group actions are via simplicial maps.\nFor a space $X$, denote by $X_0$, $X_1$, $X_2$ the vertices, edges, and faces of $X$.\nAll our spaces are connected and locally finite.\n\nWe can construct covering maps using group actions.\nA left group action of a group  $G$ on a space $Y$, denoted $G \\groupaction Y$, is a collection of simplicial maps\n\\begin{align*}\n  g \\cdot (-) : Y &\\longrightarrow Y\n\\end{align*}\nfor $g \\in G$ satisfying\n\\begin{enumerate}\n  \\item ${\\mathbb{1}} \\cdot (-) = \\id$,\n  \\item $g \\cdot (h \\cdot (-)) = (gh) \\cdot (-)$.\n\\end{enumerate}\n\\begin{qbox}\n  Show that a group always acts via isomorphisms i.e. $g \\cdot (-) : Y \\rightarrow Y$ is an isomorphism.\n\\end{qbox}\n\n\\begin{definition}\n  We say that the action of $G$ on $Y$ is \\emph{free} if the induced group action on sets $Y_0$, $Y_1$, and $Y_2$ is free.\n  The \\emph{quotient space} $Y/G$ is the space with vertices, edges, and faces given by $Y_0/G$, $Y_1/G$, and $Y_2/G$ respectively.\n\\end{definition}\n\n\\begin{ex}\n  If $d | n$ then the cyclic group $\\bbz/d$ acts freely on $nS^1$ and the quotient space is precisely $(n/d)S^1$.\n\\end{ex}\n\n\\begin{qbox}\n  Check that if $G \\groupaction Y$ is free then $Y \\rightarrow Y/G$ is a cover.\\tablefootnote{For groups acting via continuous maps (and not simplicial maps) it is not true that $Y \\rightarrow Y / G$ is always a covering space. We further require the group action to be \\emph{properly discontinuous}. Fortunately, a group action via simplicial maps is always properly discontinuous.}\n\\end{qbox}\n\\begin{definition}\n  We say that a cover $p:Y \\rightarrow X$ is \\emph{Galois} if there exists a left group action $G \\groupaction Y$ such that $X \\cong Y/G$.\n\\end{definition}\nThis definition is less that ideal as it relies on the existence of an abstract group $G$.\nWe will find an equivalent criterion for $p:Y \\rightarrow X$ to be Galois which is completely intrinsic to the cover $p$.\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Paths and covers}\nFor the rest of Section \\ref{sec:GaloisCovers}, fix a connected cover $p: Y \\longrightarrow X$.\n\n\\begin{definition}\n  For a vertex $x$ in $X$, $p^{-1}(x)$ is the \\emph{fiber} over $x$.\n\\end{definition}\n\n\n\nA \\emph{path} of length $k$ in $X$ is a finite sequence of edges $\\gamma = e_1 e_2 \\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$.\nDefine $d_0 \\gamma = d_0 e_1$ and $d_1 \\gamma = d_1 e_k$.\nDenote by $\\gamma^{-1}$ the reverse path $e_k^{-1} \\dots e_2^{-1} e_1^{-1}$.\n% Two paths $\\gamma_1, \\gamma_2$ with $d_1 \\gamma_1 = d_0 \\gamma_2$ can be concatenated to get a path $\\gamma_1 \\cdot \\gamma_2$ from $d_0 \\gamma_1$ to $d_1 \\gamma_2$.\n% For $x \\in X$, we'll denote by $\\mathbb{1}_x$ the ``path of length 0'' at $x$.\n\n\n  \\begin{theorem}[Unique lifting of paths]\n    \\label{theorem:uniqueLiftingPaths}\n    For every vertex $x$ in $X$, every path $\\gamma$ in $X$ starting at $x$, and every vertex $y$ in the fiber $p^{-1}(x)$, there exists a unique path $\\widetilde{\\gamma}$ in $Y$ such that\n    \\begin{align*}\n      \\widetilde{\\gamma} & \\mbox{ starts at } y, \\\\\n      p (\\widetilde{\\gamma}) &= \\gamma.\n    \\end{align*}\n    $\\widetilde{\\gamma}$ is called a \\emph{lift} of $\\gamma$.\n  \\end{theorem}\n\n  \\begin{qbox}\n    Pick a path $\\gamma$ of length 5 in $S^1 \\vee S^1$.\n    Draw lifts of $\\gamma$ starting at the three different vertices in cover $(10)$ in Figure \\ref{fig:CoveringsOfS1S1}.\n  \\end{qbox}\n\n  \\begin{proof}[Proof of Theorem \\ref{theorem:uniqueLiftingPaths}]\n    Proof is by induction on the length of $\\gamma$.\n\n    \\emph{Base case: length of $\\gamma = 1$.}\n    Let $\\gamma = e$ with $d_0 e = x$.\n    Because $p$ is a covering map, there is a neighborhood of $x$ that is evenly covered. Hence, there is a unique edge (possibly an inverse) $\\widetilde{e}$ with $d_0 \\widetilde{e} = y$ and $p(\\widetilde{e}) = e$. Then $\\widetilde{\\gamma} = \\widetilde{e}$ is the required lift.\n    \\begin{qbox}\n      Complete the induction step.\n    \\end{qbox}\n  \\end{proof}\n\n    \\begin{corollary}\n      \\label{corollary:surjectivityOfCovers}\n      $p:Y \\rightarrow X$ is surjective.\n    \\end{corollary}\n    \\begin{qbox}\n      Prove that $p:Y_0 \\rightarrow X_0$ is surjective by lifting appropriate paths. (Optional: Extend this proof to edges and faces.)\n    \\end{qbox}\n    \\begin{corollary}\n      \\label{corollary:cardinalityOfFibers}\n      Every path $\\gamma$ from $x_0$ to $x_1$ in $X$ naturally defines a bijection\n      \\begin{align*}\n        p^{-1}(x_0) \\longrightarrow p^{-1}(x_1).\n      \\end{align*}\n      Hence, the fibers over any two vertices $x_0$, $x_1 \\in X_0$, have the same cardinality.\n    \\end{corollary}\n    \\begin{qbox}\n      Prove Corollary \\ref{corollary:cardinalityOfFibers} using the lift of an appropriate path and it's inverse.\n    \\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Deck transformations}\n% Our goal is to come up with a criterion for $p$ being Galois.\n% There is a very intricate relation between covering spaces and paths in the base space.\n\n\n\n\n\\begin{definition}\n  A \\emph{deck transformation} of $p$ is a simplicial map $\\varphi: X \\rightarrow X$ that commutes with $p$ i.e. $p = p \\circ \\varphi$.\n  \\begin{equation*}\n    \\begin{tikzcd}\n      Y \\ar[rr, \"\\varphi\"] \\ar[rd, \"p\"'] & & Y \\ar[ld,\"p\"] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{qbox}\n  Show that deck transformations of $p$ form a group.\n\\end{qbox}\nLet $\\Gal(Y|X)$ denote the group of deck transformations of $p: Y \\rightarrow X$.\nThere is a natural left action of the group $\\Gal(Y|X)$ on the space $Y$.\n\n\\begin{ex}\n  For example, the Galois groups of the covers $(1)$, $(3)$, $(5)$ of $S^1 \\vee S^1$ in Figure \\ref{fig:CoveringsOfS1S1} are $\\bbz/2$, $\\set{\\mathbb{1}}$, $\\bbz/3$ respectively.\n\\end{ex}\n\n\n\\begin{qbox}\n  Find the group of deck transformations of the covers $(2)$, $(6)$, $(7)$, $(8)$, $(9)$, $(10)$, $(11)$ of $S^1 \\vee S^1$ in Figure \\ref{fig:CoveringsOfS1S1}.\n  For each of these covers $Y$, find quotient $Y / G$ where $G=\\Gal(Y| S^1 \\vee S^1)$.\n\\end{qbox}\n\n\\begin{qbox}\n  Prov that for any vertex $x \\in X$ and every deck transformation $\\varphi \\in \\Gal(Y|X)$, we have $\\varphi(p^{-1}(x)) = p^{-1}(x)$.\n  Hence, the deck transformations permute the fibers over $x$.\\tablefootnote{\n  One can think of this as shuffling a deck of cards, hence the name ``deck'' transformations.}\n\\end{qbox}\n\n% \\begin{ex}\n%   If $G \\groupaction X$ freely then every element $ g \\in G$ defines a decktransformation of $p: X \\rightarrow G \\backslash X$.\n% \\end{ex}\n\n\\begin{theorem}\n  \\label{theorem:freenessGaloisAction}\n  The action of $\\Gal(Y|X)$ on $Y$ is free.\n\\end{theorem}\n\\begin{proof}\n  We will show that if a deck transformation $\\varphi \\in \\Gal(Y|X)$ does not act freely on $ Y$, then $\\varphi$ fixes everything and hence is the identity element in $\\Gal(Y|X)$.\n\n  Suppose the action of $\\varphi$ is not free. It suffices to assume that $g$ fixes some vertex, as if $\\varphi$ fixes some edge or a face then it also fixes the vertices of the edge or the face respectively. Suppose $\\varphi y_0 = y_0$ for $y_0 \\in Y$.\n\n  Consider another vertex $y$ in $Y$. Let $x_0 = p(y_0)$ and $x = p(y)$.\n  \\begin{qbox}\n    Using a path $\\gamma$ in $Y$ from $y_0$ to $y$ show that $\\varphi$ fixes $y$, thereby completing the proof of the proposition.\n  \\end{qbox}\n\\end{proof}\n\n\n\\begin{corollary}\n  \\label{cor:deckTransforms}\n  Let $y$ be a vertex in $Y$ and let $\\varphi, \\varphi' \\in \\Gal(Y|X)$ be two deck transformations. If $\\varphi(y) = \\varphi'(y)$ then $\\varphi = \\varphi'$. Hence, a deck transformation is completely determined by where it sends one vertex!\n\\end{corollary}\n\\begin{qbox}\n  Prove this.\\hint{Look at $\\varphi^{-1} \\circ \\varphi'$.}\n\\end{qbox}\n\n\\begin{theorem}\n  \\label{theorem:GaloisCriterion}\n  A cover $p:Y \\rightarrow X$ is Galois if and only if $\\Gal(Y|X)$ acts freely, transitively on each of the sets $p^{-1}(x)$ where $x$ is a vertex, an edge, or a face in $X$.\n\\end{theorem}\n\\begin{proof}\n  This is equivalent to showing that $p:Y \\rightarrow X$ is Galois if and only if for any two $y_1$, $y_2 \\in p^{-1}(x)$ there is a unique deck transformation $g \\in \\Gal(Y|X)$ such that $g \\cdot y_1 = y_2$.\n\n  $(\\Leftarrow)$ As $\\Gal(Y|X)$ acts freely on $Y$, we can form the quotient $Y / \\Gal(Y|X)$. Because the action is transitive, $X$ is isomorphic to $Y/G$.\n  This proves one direction.\n\n  $(\\Rightarrow)$ Suppose $p$ is Galois and $X = Y/G$. We will show that the group of deck transformations of $p: Y \\rightarrow Y/G$ is precisely $G$.\n  Let $y$ be a vertex in $Y$ and let $x = p(y)$ be a vertex in $X$.\n  By definition, The elements of $G$ act freely, transitively on the fiber $p^{-1}(x)$.\n  By Corollary \\ref{cor:deckTransforms} there can be no other deck transformations.\n  Hence, $\\Gal(Y|X) = G$.\n  This proves the other direction.\n\\end{proof}\n\n\\begin{qbox}\n  Which of the covers in Figure \\ref{fig:CoveringsOfS1S1} are Galois?\n\\end{qbox}\n\\begin{qbox}\n  Show that the 2-covers\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  are all Galois.\n\\end{qbox}\n\nGalois covers are completely symmetric covers.\nBy the evenly covered property of a covering space, small. neighborhoods of points in the fiber $p^{-1}(x)$ look the same as neighborhoods of $x$.\nBut in a Galois cover, the entire space $Y$ looks the same ``as seen from any point in the fiber''.\nIn general, an oject being Galois means that it is as symmetric as possible.\n\n\n\\begin{remark}\n  The analogy with field theory is very clear here.\n  We study field extensions $E \\rightarrow F$ in the Galois extensions of fields.\n  The deck transformations are replaced by automorphisms of $F$ which fix $E$, group quotients are replaced by fixed points.\n  An extension is Galois precisely when $F^{\\Gal(E|F)} = E$.\n\\end{remark}\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  % \\label{fig:CoveringsOfS1S1}\n\\end{figure}\n", "meta": {"hexsha": "c095f7b74c37450dd158c026056a9eb0501461d2", "size": 10314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02.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": "02.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": "02.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": 41.5887096774, "max_line_length": 383, "alphanum_fraction": 0.6783982936, "num_tokens": 3385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6965348612011236}}
{"text": "\\section{Introduction}\n\nThis short tutorial shows how to make a simple calculator.\nThe calculator will compute basic mathematical expressions (\\verb|+, -, *, /|) possibly nested in parenthesis.\nWe assume the reader is familiar with regular expressions.\n\n\\section{Defining the grammar}\n\nExpressions are defined with a grammar.\nFor example an expression is a sum of terms and a term is a product of factors. A factor is either a number or a complete expression in parenthesis.\n\nWe describe such grammars with rules. A rule describe the composition of an item of the language. In our grammar we have 3 items (Expr, Term, Factor). We will call these items `symbols' or `non terminal symbols'. The decomposition of a symbol is symbolized with $\\to$.\nThe grammar of this tutorial is given in figure~\\ref{tut:gramsymb_calc}.\n\n\\begin{tableau}\n\\caption{Grammar for expressions}                           \\label{tut:gramsymb_calc}\n\\begin{tabular}{| l | p{7cm} |}\n\\hline\n    Grammar rule & Description \\\\\n\\hline\n\\hline\n    $Expr~\\to~Term~(('+'|'-')~Term)*$\n        & An expression is a term eventually followed with a plus ($'+'$) or a minus ($'-'$) sign and an other term any number of times ($*$ is a repetition of an expression 0 or more times). \\\\\n\\hline\n    $Term~\\to~Fact~(('*'|'/')~Fact)*$\n        & A term is a factor eventually followed with a $'*'$ or $'/'$ sign and an other factor any number of times. \\\\\n\\hline\n    $Fact~\\to~number~|~'('~Expr~')'$\n        & A factor is either a number or an expression in parenthesis. \\\\\n\\hline\n\\end{tabular}\n\\end{tableau}\n\nWe have defined here the grammar rules (i.e. the sentences of the language). We now need to describe the lexical items (i.e. the words of the language). These words - also called \\emph{terminal symbols} - are described using regular expressions. In the rules we have written some of these terminal symbols ($+, -, *, /, (, )$). We have to define \\emph{number}. For sake of simplicity numbers are integers composed of digits (the corresponding regular expression can be $[0-9]+$).\nTo simplify the grammar and then the Python script we define two terminal symbols to group the operators (additive and multiplicative operators). We can also define a special symbol that is ignored by TPG. This symbol is used as a separator. This is generaly usefull for white spaces and comments. The terminal symbols are given in figure~\\ref{tut:token_calc}\n\n\\begin{tableau}\n\\caption{Terminal symbol definition for expressions}        \\label{tut:token_calc}\n\\begin{tabular}{| l | l | l |}\n\\hline\n    Terminal symbol & Regular expression & Comment \\\\\n\\hline\n\\hline\n    number & $[0-9]+$ or $\\backslash d+$ & One or more digits \\\\\n\\hline\n    add & $[+-]$ & a $+$ or a $-$ \\\\\n\\hline\n    mul & $[*/]$ & a $*$ or a $/$ \\\\\n\\hline\n    spaces & $\\backslash s+$ & One or more spaces \\\\\n\\hline\n\\end{tabular}\n\\end{tableau}\n\nThis is sufficient to define our parser with TPG. The grammar of the expressions in TPG can be found in figure~\\ref{tut:recognizer}.\n\n\\begin{code}\n\\caption{Grammar of the expression recognizer}              \\label{tut:recognizer}\n\\begin{verbatimtab}[4]\nclass Calc(tpg.Parser):\n    r\"\"\"\n\n    separator spaces: '\\s+' ;\n    token number: '\\d+' ;\n    token add: '[+-]' ;\n    token mul: '[*/]' ;\n\n    START -> Expr ;\n\n    Expr -> Term ( add Term )* ;\n\n    Term -> Fact ( mul Fact )* ;\n\n    Fact -> number | '\\(' Expr '\\)' ;\n\n    \"\"\"\n\\end{verbatimtab}\n\\end{code}\n\n\\emph{Calc} is the name of the Python class generated by TPG. \\emph{START} is a special non terminal symbol treated as the \\emph{axiom}\\footnote{The axiom is the symbol from which the parsing starts} of the grammar.\n\nWith this small grammar we can only recognize a correct expression. We will see in the next sections how to read the actual expression and to compute its value.\n\n\\section{Reading the input and returning values}\n\nThe input of the grammar is a string. To do something useful we need to read this string in order to transform it into an expected result.\n\nThis string can be read by catching the return value of terminal symbols. By default any terminal symbol returns a string containing the current token. So the token $'\\backslash('$ always returns the string $'('$. For some tokens it may be useful to compute a Python object from the token. For example \\emph{number} should return an integer instead of a string, \\emph{add} and \\emph{mul} should return a function corresponding to the operator. That why we will add a function to the token definitions. So we associate \\emph{int} to \\emph{number} and \\emph{make\\_op} to \\emph{add} and \\emph{mul}.\n\n\\emph{int} is a Python function converting objects to integers and \\emph{make\\_op} is a user defined function (figure~\\ref{tut:make_op}).\n\n\\begin{code}\n\\caption{\\emph{make\\_op} function}                          \\label{tut:make_op}\n\\begin{verbatimtab}[4]\ndef make_op(s):\n    return {\n        '+': lambda x,y: x+y,\n        '-': lambda x,y: x-y,\n        '*': lambda x,y: x*y,\n        '/': lambda x,y: x/y,\n    }[s]\n\\end{verbatimtab}\n\\end{code}\n\nTo associate a function to a token it must be added after the token definition as in figure~\\ref{tut:tokens}\n\n\\begin{code}\n\\caption{Token definitions with functions}                  \\label{tut:tokens}\n\\begin{verbatimtab}[4]\n    separator spaces: '\\s+' ;\n    token number: '\\d+' int ;\n    token add: '[+-]' make_op;\n    token mul: '[*/]' make_op;\n\\end{verbatimtab}\n\\end{code}\n\nWe have specified the value returned by the token. To read this value after a terminal symbol is recognized we will store it in a Python variable. For example to save a \\emph{number} in a variable \\emph{n} we write \\emph{number/n}.\nIn fact terminal and non terminal symbols can return a value. The syntax is the same for both sort of symbols. In non terminal symbol definitions the return value defined at the left hand side is the expression return by the symbol. The return values defined in the right hand side are just variables to which values are saved. A small example may be easier to understand (figure~\\ref{tut:ret_val}).\n\n\\begin{tableau}\n\\caption{Return values for (non) terminal symbols}          \\label{tut:ret_val}\n\\begin{tabular}{| l | p{9cm} |}\n\\hline\n    Rule & Comment \\\\\n\\hline\n    \\verb!X/x ->!           & Defines a symbol \\emph{X}. When \\emph{X} is called, \\emph{x} is returned. \\\\\n    \\verb!Y/y!              & \\emph{X} starts with a \\emph{Y}. The return value of \\emph{Y} is saved in \\emph{y}. \\\\\n    \\verb!Z/z!              & The return value of \\emph{Z} is saved in \\emph{z}. \\\\\n    \\verb!$ x = y+z $!      & Computes \\emph{x}. \\\\\n    \\verb!;!                & Returns \\emph{x}. \\\\\n\\hline\n\\end{tabular}\n\\end{tableau}\n\nIn the example described in this tutorial the computation of a \\emph{Term} is made by applying the operator to the factors, this value is then returned:\n\n\\begin{verbatimtab}[4]\n    Expr/t -> Term/t ( add/op Term/f $t=op(t,f)$ )* ;\n\\end{verbatimtab}\n\nThis example shows how to include Python code in a rule. Here \\verb!$...$! is copied verbatim in the generated parser.\n\nFinally the complete parser is given in figure~\\ref{tut:parser}.\n\n\\begin{code}\n\\caption{Expression recognizer and evaluator}               \\label{tut:parser}\n\\begin{verbatimtab}[4]\nclass Calc(tpg.Parser):\n    r\"\"\"\n\n    separator spaces: '\\s+' ;\n\n    token number: '\\d+' int ;\n    token add: '[+-]' make_op ;\n    token mul: '[*/]' make_op ;\n\n    START -> Expr ;\n\n    Expr/t -> Term/t ( add/op Term/f $t=op(t,f)$ )* ;\n\n    Term/f -> Fact/f ( mul Fact/a $f=op(f,a)$ )* ;\n\n    Fact/a -> number/a | '\\(' Expr/a '\\)' ;\n\n    \"\"\"\n\\end{verbatimtab}\n\\end{code}\n\n\\section{Embeding the parser in a script}\n\nSince TPG 3 embeding parsers in a script is very easy since the grammar is the doc string\\footnote{It may be a good pratice to use only raw strings. This will ease the pain of writing regular expressions.} of a class (see figure~\\ref{tut:build_scheme}).\n\n\\begin{code}\n\\caption{Writting TPG grammars in Python}             \\label{tut:build_scheme}\n\\begin{verbatimtab}[4]\nimport tpg\n\nclass MyParser(tpg.Parser):\n    r\"\"\" # Your grammar here \"\"\"\n\n# You can instanciate your parser here\nmy_parser = MyParser()\n\\end{verbatimtab}\n\\end{code}\n\nTo use this parser you now just need to instanciate an object of the class \\emph{Calc} as in figure~\\ref{tut:calc}.\n\n\\begin{code}\n\\caption{Complete Python script with expression parser}     \\label{tut:calc}\n\\begin{verbatimtab}[4]\nimport tpg\n\ndef make_op(s):\n    return {\n        '+': lambda x,y: x+y,\n        '-': lambda x,y: x-y,\n        '*': lambda x,y: x*y,\n        '/': lambda x,y: x/y,\n    }[s]\n\nclass Calc(tpg.Parser):\n    r\"\"\"\n\n    separator spaces: '\\s+' ;\n\n    token number: '\\d+' int ;\n    token add: '[+-]' make_op ;\n    token mul: '[*/]' make_op ;\n\n    START/e -> Term/e ;\n    Term/t -> Fact/t ( add/op Fact/f $t=op(t,f)$ )* ;\n    Fact/f -> Atom/f ( mul/op Atom/a $f=op(f,a)$ )* ;\n    Atom/a -> number/a | '\\(' Term/a '\\)' ;\n\n    \"\"\"\n\ncalc = Calc()\nexpr = raw_input('Enter an expression: ')\nprint expr, '=', calc(expr)\n\\end{verbatimtab}\n\\end{code}\n\n\\clearpage\n\n\\section{Conclusion}\n\nThis tutorial shows some of the possibilities of TPG.\nIf you have read it carefully you may be able to start with TPG.\nThe next chapters present TPG more precisely.\nThey contain more examples to illustrate all the features of TPG.\n\nHappy TPG'ing!\n", "meta": {"hexsha": "f19fbdc908acf835d8ae2ef117861e27941d0ead", "size": 9286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reference/TPG-3.2.2/doc/tutorial.tex", "max_stars_repo_name": "JaDogg/__py_playground", "max_stars_repo_head_hexsha": "416f88db10e03f5380bcb5cfcad0bca50ffa657c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-28T00:00:16.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-28T00:00:16.000Z", "max_issues_repo_path": "reference/TPG-3.2.2/doc/tutorial.tex", "max_issues_repo_name": "JaDogg/__py_playground", "max_issues_repo_head_hexsha": "416f88db10e03f5380bcb5cfcad0bca50ffa657c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reference/TPG-3.2.2/doc/tutorial.tex", "max_forks_repo_name": "JaDogg/__py_playground", "max_forks_repo_head_hexsha": "416f88db10e03f5380bcb5cfcad0bca50ffa657c", "max_forks_repo_licenses": ["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.8540772532, "max_line_length": 595, "alphanum_fraction": 0.6725177687, "num_tokens": 2535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6965348574142696}}
{"text": "\\chapter{Introduction to Modules}\n\\section{\\textbf{Definition of Module}}\n\\begin{defn}  [\\textbf{Left Module}]\n\n Let $ R $ be a ring with identity and $ M $ be an abelian group with addition. We say $ M $ is a left $R-$module if there exists a mapping\\footnote{often called as scaler multiplication.}\n\\begin{equation*}\nR \\times M \\rightarrow M\n\\end{equation*}\t\ndefined by\n\\begin{equation*}\n(a \\ , \\ x) \\rightarrow ax\n\\end{equation*}\\marginnote[-2em]{$\\forall \\ a \\in \\ R$ and $x$ $\\in \\ M$}\nsatisfying following properties :\n\\begin{align}\n(a+b) x =& ax + bx \\\\ a(x+y) =& ax + ay \\\\ (ab)x =& a(bx) \\\\ 1x =& x\n\\end{align}\\marginnote[-7em]{\\large{$\\forall$ $ a\\ , \\ b \\in R$ \\newline $x \\ , y \\ \\in M$}}\nand denoted by $_{R}M$\n\\end{defn}\n\\bigskip\n\\begin{defn}[\\textbf{Right Module}]\n Let $ R $ be a ring with identity and $ M $ be an abelian group with addition. We say $ M $ is a right $R-$module if there exists a mapping\n\\begin{equation*}\nM \\times R \\rightarrow M\n\\end{equation*}\t\ndefined by\n\\begin{equation*}\n(x \\ ,\\ a) \\rightarrow xa\n\\end{equation*}\n\\marginnote[-1em]{$ \\forall \\ a$ $\\in$ $R$ and $x$ $\\in$ $M$} satisfying following properties\\marginnote[4em]{\\large{$\\forall$ $ a\\ , \\ b \\in R$ \\newline $x \\ , y \\ \\in M$}} :\n\\begin{align}\nx (a+b)  &= xa + xb \\\\ (x+y) a &= xa + ya \\\\ x (ab) &= (xa)b \\\\ x1 &= x\n\\end{align}\nand denoted by $M_{R}$.         \\end{defn}\n\n\\subsection{Examples :}\n\\begin{enumerate}\n\\item Let $V$ be a vector space over a field $F$ then $V$ is a left as well as right $F-$Module.\\newline \\bigskip\n\\item Let $G$ be any abelian group under addition , then $G$ is a $\\mathbb{Z-}$Module where $\\mathbb{Z}$ is set of integers.\\newline \\bigskip\n\\item Let $R$ be ring and $M= R[x]$ \\marginnote{Suppose ring $R$ is a field then $R-$Module $R[x]$ is a vector space over field $R$.} where $R[x]$ is a group of all polynomials with coefficents in $R$ then $M$ is a left as well as a right $R-$Module with scaler multiplication being usual multiplication.\\newline \\bigskip\n\\item Let $M$ be collection of all $m \\times n $ matrices over ring $R$ , then $M$ is left $R-$Module where scaler multiplication being usual multiplication of a scaler to a matrix. \\newline\n\\bigskip\nIn particular, if $M$ is a set of $1 \\times n$ matrices over $R$ or $M = R^n$(set of $n-$tuples) then $R^n$ is a left $R-$module.\n\\end{enumerate}\n\\bigskip\n\\begin{remark}\n\tLet $R$ be a commutative ring then every left $R-$module can be transformed to right $R-$module and vice-versa.\n\t\\end{remark}\n\\begin{proof} Let $M$ be left $R-$module and $R$ be a commutative ring. \\newline\n\tso, $\\exists$ a mapping\n\\begin{equation*}\nR \\times M \\rightarrow M\n\\end{equation*}\t\ndefined by\n\\begin{equation*}\n(a \\ , \\ x) \\rightarrow ax\n\\end{equation*}\nfor each $a$ $\\in$ $R$ and $x$ $\\in$ $M$ satisfying following properties :\n\\marginnote{$\\forall$ $ a\\ , \\ b \\in R$ and $x \\ , y \\ \\in M$  }\n\\begin{eqnarray*}\n(a+b) x &=& ax + bx \\\\ a(x+y) &=& ax + ay \\\\ (ab)x &=& a(bx) \\\\ 1x &=& x\n\\end{eqnarray*}\n$\\because \\ R$ is a commutative ring.\\newline\nNow, Define an another mapping\n \\begin{equation*}\n M \\times R \\rightarrow M\n \\end{equation*}\t\n defined by\n \\begin{equation*}\n (x \\ ,\\ a) \\rightarrow x*a \\ = \\ ax\n \\end{equation*}\nTo check $M$ is a right $R-$Module , we need to verify properties number \\eqref{eq1.5}-\\eqref{eq1.8}\n \\begin{description}\n \t\\item[(i) Distribuitive Law]\n \t\\begin{align*}\n \t\tx*(a+b) &= (a+b)x \\\\ &= ax + bx \\\\ &= (x*a) + (x*b)\n \t\\end{align*}\n \t\\item[(ii) Distributive Law] \\begin{align*}\n \t\t(x+y)*a &= a(x+y) \\\\ &= ax + ay \\\\ &= (x*a) + (y*a)\n \t      \\end{align*}\n       \\item[(iii)]  \\begin{align*}\n       x*(ab) &= (ab)x \\\\ &= (ba)x \\\\ &= b(ax) \\\\ &= (ax)*b\n       \\end{align*}\n   \\item[(iv)] \\begin{align*}\n   x*1 &= 1x \\\\  &= x\n   \\end{align*}\nThus, $_{R}M$ is transformed to $M_R$.\\newline\nSimilarly, Converse statement can be verified.\n\\end{description}\n\\end{proof} \\bigskip\n\\begin{remark}\n\tLet $S$ be a subring of ring $R$ then $_{S}M$ exists \\marginnote{by existance means $M$ is a valid left module over mentioned ring or subring. i.e. satisfying those four properties.}  only if $_{R}M$ exists.\n\\end{remark} \\bigskip\n\\begin{remark}\n\tSame Abelian group\\marginnote{For Instance,  The field $\\mathbb{R}$ is $\\mathbb{R}-$module,$\\mathbb{Q}-$module and $\\mathbb{Z}-$module.} can have the structure of a Module for a number of different rings.\n\\end{remark} \\bigskip\n\\begin{remark}\nLet $I$ be left ideal of $R$ then quotient ring $\\bigslant{R}{I}$ is a left $R$-module.\\marginnote{Here scaler multiplication is \\newline \\begin{equation*}\n\tR \\times \\bigslant{R}{I} \\rightarrow \\bigslant{R}{I}\n\t\\end{equation*}\ndefined as\n\\begin{equation*}\n(a \\ , \\ x+I) \\rightarrow ax+I\n\\end{equation*}\n\n$\\forall \\ a \\in R$ and $\\forall \\ x+I \\in \\bigslant{R}{I}$}\n\n\\end{remark}\n\\begin{proof}[verification:]\n\tLeft to reader\\newline \\bigskip\n\t\\textbf{Hint:} you need to verify those four properties: \\eqref{eq1.1}-\\eqref{eq1.4}\n\\end{proof}\n\\bigskip\n\n\\begin{thm}{\\textbf{(Elementry Properties:)}}\\newline\n\tLet $M$ be a left $R$-module . Suppose $0_m \\ \\text{and} \\ 0_r$ denotes additive identities of $M$ and $R$ respectively. Then,  for each $x \\ \\in M$ and $r \\ \\in R$ \\newline\n\\begin{description}\n\\item (i)\n\t\\begin{equation*}\n\t0_m = 0_r\\ x = r\\ 0_m\n\t\\end{equation*}\n\\item (ii)\n\t\\begin{equation*}\n\tr(-x) =  (-r)x = -rx\n\t\\end{equation*}\n\\end{description}\n\\end{thm}\n\\begin{proof}\n\t\\begin{description}\n\t\t\\item[(i)]\nAs $0_m$ is the additive identity of $M$. so, $0_m = 0_m + 0_m$\\newline\nConsider \\marginnote{$ \\because \\ (r\\ ,\\ 0_m)\\rightarrow r\\ 0_m \\in M$\\newline so, $r\\ 0_m = r\\ 0_m + 0_m$}\n $ r(0_m + 0_m) = r\\ 0_m  = r\\ 0_m +0_m $\\newline\nbut, $r(0_m + 0_m) = (r\\ 0_m) +(r\\ 0_m)$ \\marginnote{\n\t$ \\because \\ M$ is a left $R$-module.\\newline (using distribuitive property)}\\newline\nso, we have \\begin{equation*}\nr\\ 0_m +r\\ 0_m = r\\ 0_m + 0_m\n\\end{equation*}\nas ($M,+$) is an abelian group so left and right cancellation law holds.\n\\begin{eqnarray*}\n\\cancel{r\\ 0_m} +r\\ 0_m &=& \\cancel{r\\ 0_m} + 0_m \\\\ r\\ 0_m &=& 0_m\n\\end{eqnarray*}\na similiar argument can be used to prove $0_m = 0_r\\ x$.\n\\item[(ii)]\nas $M$ is a left $R$-module so $(r \\ , x )\\ \\rightarrow rx \\in M$ \\newline\nNow, Consider $(-r)x + rx$\n\\begin{eqnarray*}\n\\text{using distribuitive law} \\\\ (-r)x + rx &=& (-r + r)x \\\\  &=& 0_r \\ x \\\\ &=& 0_m\n\\end{eqnarray*}\ni.e. $(-r)x$ is additive inverse of  $(rx)$ but additive inverse of $(rx)$ is $-rx$ and it is unique for an abelian group($M$ here)\n\\begin{equation*}\n\\therefore \\ (-r)x = -rx\n\\end{equation*}\na similar argument can be used to prove that $r(-x)  = -r x$.\n\\end{description}\n\\end{proof}\n\\bigskip\n\\begin{defn}[ \\textbf{Ring Homomorphism}]\n\tLet\\marginnote{often called as ring homo} $R$ and $S$ be two rings with identities $1_r \\ , 1_s$ respectively then a map(say $f$)\n\t\\begin{equation*}\n\tf : R \\rightarrow S\n\t\\end{equation*}\n\tis said to be a ring homomorphism or ring linear map if for every $a \\ ,\\ b \\in R$ following properties holds\\marginnote[-2.55em]{if $R$ = $S$ then we call ring homo as ring endomorphism. For instance , let $f$ be ring homo from $R$ to $R$ . we say $f$ is endomorphism of $R$ and denoted by $End \\ R$}\n\t\\begin{description}\n\t\t\\item[(i) \\centering{Preserves Addition}]\\begin{equation*}\n\t\t(a+b)f = (a)f +(b)f\n\t\t\\end{equation*}\n\t\t\\item[(ii) \\centering{Preservers Multiplication} ]\\begin{equation*}\n\t\t(ab)f = (a)f . (b)f\n\t\t\\end{equation*}\n\t\t\\item[(iii) \\centering{ Maps identity to identity}]\\begin{equation*}\n\t\t(1_r)f = 1_s\n\t\t\\end{equation*}\n\t\\end{description}\n\\end{defn}\n\\begin{remark}\n\tSuch a mapping need not to be bijective. if it is bijective then we say it is a ring isomorphism or rings are isomorphic.\n\\end{remark}\n\\bigskip\n\\begin{thm}\n\tLet\\marginnote{\\[ M \\ \\text{is a right R-module} \\] \\[\\centering\\Updownarrow \\] \\[\\newline\\exists \\ f: R \\ \\xrightarrow[\\text{Homo}]{\\text{Ring}} End \\ M \\] } $R$ be a ring and $M$ be any abelian group with addition. then $M$ is a right $R$-module if and only if there exists a map which is ring homomorphism from $R$ to $End \\ M$\n\\end{thm}\n\\begin{proof}\n\\begin{description}\n\t\\item[(Forward Part)\\newline]\n\tLet us suppose that $ M $ is a right $ R $-module.\\newline\n\t\\textbf{Claim:} there exists a map which is ring homomorphism from $R$ to $End \\ M$\\newline\n   $ \\because \\ M  $ is a left $ R $-module , so there exist a map\\newline\n   \\[ f: M \\times R \\rightarrow M  \\]\n   defined by\n   \\[ (x \\ , a) \\rightarrow ax \\]\n   satisfying following properties:\n    \\begin{align*} (x+y)a &= (x)a+(y)a \\\\\n     x(a+b)\\mathnote{ $$\\forall \\ x , y \\ \\in M \\ \\&  \\ a ,b \\in R$$ } &= xa + xb \\\\\n     x(ab) &= (xa)b \\\\\n     x 1 &= x\n     \\end{align*}\n   for each $ a \\in R $ , define a map(say $\\phi_a $)\n   \\[ \\phi_a: M\\rightarrow\\ M \\]\n   such that for each $x\\in  M$\n   \\[ (x )\\phi_a = xa \\in \\ M \\]\n   Now, we'll show that $ \\phi_a \\in \\ End \\ M $\\newline\n   Let $ x , y \\in M $ \\newline Consider  $  (x+y)\\phi_a$\n   \\begin{align*}\n   \t&= (x+y)a  \\\\ &= xa + ya  \\\\ &= (x)\\phi_a + (y)\\phi_a\n   \\end{align*}\\marginnote[-5.5em]{using defination of $\\phi_a$} \\marginnote[-4em]{using \\eqref{eq1.9}}\n   so, $\\phi_a$ preserves addition and is a group homo from $M$ to $M$.\n   \\newline i.e. $\\phi_a \\in End \\ M$ \\newline\n   Now, we can define a map (say $f$)\n   \\begin{align*}\n   &f : R \\rightarrow End \\ M \\\\ \\text{defined as} \\\\&(a)f \\rightarrow \\phi_a \\mathnote{$\\forall a \\in R$ and $\\phi_a \\in End \\ M$}\n   \\end{align*}\nNow, We'll show that $ f $ is a ring homomorphism.\\newline\n\\begin{description}\n\t\\item[(A)]\n\t  \\begin{align*}\n\t(a+b)f &= \\phi_{a+b}\n\t\\mathnote{\\[ \\text{for each}\\  x \\in M \\ \\text{we have,}\\] \\begin{align*}\n\t\t(x)\\phi_{a+b} &= x(a+b) \\ =xa+xb \\\\ &=(x)\\phi_a +(y)\\phi_b \\\\ \\therefore \\ \\phi_{a+b} &= \\phi_a +\\phi_b\n\t\t\\end{align*}}\n\t\t  \\\\  &= \\phi_a +\\phi_b \\\\&= (a)f +(b)f\n\t\\end{align*}\n    \\item[(B)] \\begin{align*}\n    (ab)f &= \\phi_{ab}\\mathnote{\\[ \\text{for each}\\  x \\in M \\ \\text{we have,}\\] \\begin{align*} (x)\\phi_{ab} &= x(ab)   = (xa)b \\\\ &= (xa)\\phi_b = (x)\\phi_a \\circ\\phi_b \\\\ \\therefore \\ \\phi_{ab} &= \\phi_a\\circ\\phi_b \\end{align*} } \\\\  &= \\phi_a\\circ\\phi_b \\\\&= (a)f\\ (b)f\n    \\end{align*}\n\\item[(C)] \\begin{align*}\n(1)f\\mathnote{\\[ \\text{for each}\\  x \\in M \\ \\text{we have,}\\] \\begin{align*} (x)\\phi_{1} &= x(1) \\\\&=x \\end{align*}\\[ \\therefore \\ \\phi_{1} \\ \\text{is identity of}End \\ M \\]} &= \\phi_{1}\n\\end{align*}\n\n   \\end{description}\n\\bigskip\nThus, Forward Part is proved.\\newline\\bigskip\n\\item[(Converse Part)]\n\\bigskip\nAssume that $\\exists$ a ring homo.( say $f$)\n\\[ f: R\\xrightarrow[\\text{Homo}]{\\text{Ring}} End \\ M \\]\nfor any $a \\in R$,we denote the $(a)f$ by $f_a \\in End \\ M$\\newline\n\\textbf{Claim:} $M$ is a right $R$-module.\\newline\nso let's define a map\n\\[ R\\times M \\longrightarrow M \\] defined by\n\\[ (a , x ) \\rightarrow x*a = (x)f_a \\]\nto prove $M$ is a right $R$-module , we need to verify four properties $\\eqref{eq1.5}$- $\\eqref{eq1.9}$ of right $R$-module.\n\\begin{description}\n\t\\item[(i)]\n\\end{description}\n\\begin{align*}\n(x+y)*a &= (x+y)f_a \\\\& = (x)f_a +(y)f_a \\mathnote{\\[ \\because\\ f_a \\ \\in End \\ M \\]}\\\\& = x*a + y*a\n\\end{align*}\n   \\item{(ii)}\n   \\begin{align*}\n   x*(a+b) &= (x)f_{a+b} \\\\ &= (x)(f_a + f_b) \\mathnote{\\[ \\because\\ f_a \\ , \\ f_b \\in End \\ M \\]} \\\\&=(x)f_a + (x)f_b\n \\\\ &= (x*a) + (x*b)   \\end{align*}\n \\item{(iii)}\n \\begin{align*}\n x*(ab) &= (x)f_{ab} \\\\ & = (x)f_a\\circ f_b \\\\&=(x f_a)f_b \\\\&= (x*a)*b\n \\end{align*}\n \\item{(iv)}\n \\[ x*1 = (x)f_1  = x\\]\\marginnote{\\[ \\because\\ f_1 \\text{is identity in} End \\ M \\]}\nThus, $ M $ is a right $R$-module.\n\\end{description}\n\\end{proof}\n\\begin{definition}[\\textbf{Anti-Ring Homomorphism}]\n\tLet $R$ and $S$ be two rings with identities $1_r$ and $1_s$ respectively. Define a map $f$\n\t\\[ f : R \\rightarrow S \\] satisfying following properties, for each $a , b \\in R$ \\newline\n\t\\begin{description}\n\t\t\\item[(i)] \\[ (a+b)f = (a)f +(b)f \\]\n\t\t\\item[(ii)] \\[ (ab)f  = (b)f\\ (a)f \\]\n\t\t\\item[(iii)] \\[ (1_r)f = 1_s \\]\n  \t\n\t\\end{description}\n\t Then, $f$\tis called anti-ring homomorphism.\n\\end{definition}\n\\begin{thm}\n\tLet\\marginnote{\\[ M \\ \\text{is a left R-module} \\] \\[\\centering\\Updownarrow \\] \\[\\newline\\exists \\ f: R \\ \\xrightarrow[\\text{Homo}]{\\text{Anti-Ring}} End \\ M \\] } $R$ be a ring and $M$ be any abelian group with addition. then $M$ is a left $R$-module if and only if there exists a map which is anti-ring homomorphism from $R$ to $End \\ M$.\n\\end{thm}\n\\begin{proof}\n\tLeft to reader.\n\\end{proof}\n\\bigskip\n\\begin{definition}[\\textbf{SubModule}]\n\tLet $M$ be a left (right) $R$-module then a subset $N$ of $M$ is called a submodule of $M$ if \\underline{$N$ is a left (right) $R$-module} \\underline{under the operation induced from $M$.}\\newline \\bigskip\n\tIn other words, A subset $N$ of $M$ is called submodule of $M$ if\n\t\\begin{description}\n\t\t\\item[(i)] $N$ is subgroup of $M$.\n\t\t\\item[(ii)] $N$ is closed under induced scaler multiplication from $M$.\n\t\\end{description}\n\\end{definition}\n\\bigskip\n\\begin{thm}[\\textbf{Criterion for Checking Modules}]\n\n\tLet $M$ be a left (right) $R$-module and $N$ be a subset of $M$ then $N$ is a submodule of $M$ if and only if\n\t\\begin{description}\n\t\t\\item[(i)]\n\t\t\\marginnote[2.5em]{\\[ \\forall \\ x , y  \\in N \\] } \\[ x-y \\in N \\]\n\t\t\\item[(ii)]\n\t\t\\marginnote[2.5em]{\\[ \\forall \\ a \\in R \\ \\&\\ x \\in N \\]} \\[ a x \\in N \\]\n\t\\end{description}\n\\end{thm}\n\\begin{proof}\n\tLeft to reader.\n\\end{proof}\n\\bigskip\n\\subsection{Examples:}\n\\begin{enumerate}\n\t\\item As every Vector Space $V$ over a Field $F$ is a $F$-module. So, submodules of $V$ are subspaces of $V$.\n\t\\item As every abelian group $G$ is a $\\mathbb{Z}$-module. So, all subgroups of $G$ are submodules.\n\t\\item Let $R$ be a ring then $R$ is a left as well as right $R$-module then left (right) ideals of $R$ are left (right) submodules of $R$.\n\t\\item $\\left\\{0\\right\\}$ and $M$ are trivial submodules of any left (right) $R$-module $M$.\n\\end{enumerate}\n\\bigskip\n\\begin{remark}\\qquad\n\t\\begin{enumerate}\n\t\t\\item Union of two submodules need not to be a submodule.\\marginnote{Think an example !}\n\t\t\n\t\t\\item Intersection of any number of submodules is again a submodule.\\marginnote{\\textbf{Hint:} Verify using criterion for checking modules.}\n\t\\end{enumerate}\n\\end{remark}\n\\bigskip\t\n\n\\begin{remark}\\textbf{(Smallest Submodule containing a set)}\\newline\n\t  \t\tLet $M$ be any left (right) $R$-module and $S$ be any subset of $M$. Suppose $\\mathcal{F}$ be the family of all submodules of $M$ containing $S$. \\[  \\text{Let} \\; P=\\bigcap_{N \\in \\mathcal{F}}N  \\] then $P$ is a submodule of $M$ containing $S$ as being intersection of an indexed family of submodules containing $S$.\\newline \\bigskip Moreover, $P$ is the smallest submodule of $M$ containing $S$. i.e. for any arbitrary submodule $K \\in \\mathcal{F}$ , we have $ P \\subseteq K$. Such submodule $P$ of $M$ is said to be generated by set $S$ and is denoted by \\[ P = \\left\\langle S \\right\\rangle  = (S) \\]\n\\end{remark}\n\\bigskip\n\\begin{remark}\\qquad\n\t\\begin{description}\n\t\\item Let $S$ be any subset of left $R$-module $M$ and $\\left\\langle S \\right\\rangle $ is the smallest submodule of $M$ containing $S$.\\newline\n\t\\begin{enumerate}\n\t\t\\item if $S$ is non-empty and finite , $S = \\left\\lbrace x_1,x_2,x_3, \\cdots , x_n \\right\\rbrace $ \\[ \\left\\langle S \\right\\rangle = \\left\\langle \\left\\lbrace x_1,x_2,x_3, \\cdots , x_n \\right\\rbrace \\right\\rangle  = \\left\\langle x_1,x_2,x_3, \\cdots , x_n \\right\\rangle \\] is said to be a finitely generated by $S$ and is smallest submodule of $M$ containing $S$.\n\t\t\\item if $S = \\phi$ \\quad i.e. $S$ is an empty set \\[ \\left\\langle S \\right\\rangle = \\left\\langle \\phi \\right\\rangle = \\left\\lbrace 0 \\right\\rbrace \\]\n\t\t\\item if $S = \\left\\lbrace a\\right\\rbrace $ \\quad i.e. $S $ is singleton then $\\left\\langle S \\right\\rangle = \\left\\langle a\\right\\rangle $ is said to be a \\underline{cyclic submodule}.\n\t\\end{enumerate}\n\\end{description}\n\\end{remark}\n\\bigskip\n\\begin{definition}[\\textbf{Cyclic module}]   \\cite{Cohn2005}\n\tA module $M$ is said to be a cyclic module if it can be   generated by a single element.\n\\end{definition}\n\\textit{For Example:}\n\tA ring $R$ over itself is a module and can be generated by identity element $ \\left\\lbrace 1\\right\\rbrace $ so is a cyclic module.\n\\bigskip\n\\begin{thm}\n\tLet $M$ be left $R$ module and $S$ being any subset of $M$.\n\t\\begin{equation*} \\left\\langle S\\right\\rangle = \\begin{cases}\n\t\\left\\lbrace 0\\right\\rbrace & \\text{if $S = \\phi$} \\\\ \\left\\lbrace \\sum\\limits_{i \\in J_n} a_i x_i \\ \\middle\\vert \\  a_i \\in R \\ , x_i \\in S\\right\\rbrace  & \\text{otherwise}\n\t\\end{cases}\n\t\\end{equation*}\n\\end{thm}\n\\begin{proof}\n\\begin{description}\n\t\\item[Case-I] Let us suppose that $S = \\phi $ ,as $ \\left\\langle S\\right\\rangle $ is the intersection of all the submodules of $ M $ containing $S$\\marginnote[-2em]{i.e. Every submodule of $M$ will contain $S$}. \\newline \\bigskip In particular, $ \\left\\lbrace 0\\right\\rbrace  $ also contains $S$ i.e. \\[ \\left\\lbrace 0\\right\\rbrace  \\in\\mathnote{$\\because \\ \\mathcal{F} \\ \\text{is a collection of all submodules of}\\ M \\newline \\text{containing}\\ S$ } \\mathcal{F}  \\]\n\tso, \\begin{align*} \\left\\langle S\\right\\rangle &= \\bigcap_{N \\in \\mathcal{F}}N  \\\\& = \\left\\lbrace 0\\right\\rbrace   \\end{align*}\n    \\item[Case-II] Suppose $S$ is non-empty and let    \\[ P = \\left\\lbrace \\sum\\limits_{i \\in J_n} a_i x_i \\ \\middle\\vert \\  a_i \\in R \\ , x_i \\in S\\right\\rbrace\\]\n         First , we'll show that $S\\subseteq P$ \\newline\n         Let $x \\in\\ S$ then it can be expressed in following form:\n         \\[x = 1.x = \\sum\\limits_{i \\in J_1} a_i x_i \\] \\marginnote[-2.5em]{with $a_1 = 1$ and $x_1 = x $}\n         \\[\\therefore x \\in  P \\Rightarrow S \\subseteq P \\]  \\marginnote[-2em]{$\\because x$ was chosen arbitirary.}\n         Now ,we'll show that $P$ is a submodule of $M$ using submodule criterion.           \\newline\n         Let $u\\ ,\\ v \\in P$ . so, we need to show $u + \\alpha v \\in P$ \\marginnote{for any $\\alpha\\in R$}\n         \\[u = \\sum\\limits_{i\\in J_n} a_i x_i\\] \\marginnote[-2em]{$\\forall x_i \\in S \\ \\&\\ a_i \\in R$}\n          \\[v = \\sum\\limits_{j\\in J_m} b_j y_j\\]  \\marginnote[-2em]{$\\forall y_j \\in S \\ \\&\\ b_j \\in R$}\n          define, for any $\\alpha \\in R$\n          \\begin{align*} z_k = x_k \\qquad ,\\qquad c_k = a_k     \\mathnote{$k \\in J_n$}  \\\\\n           z_{k+j} = y_j \\qquad , \\qquad c_{k+j} = \\alpha b_j    \\mathnote{$j \\in J_m$}  \\end{align*}\n          Thus, we have\n           \\begin{align*}\n            u+ \\alpha v &= \\sum\\limits_{i\\in J_n}a_i x_i + \\alpha \\sum\\limits_{j\\in J_m}b_j y_j  \\\\\n             & =\\sum\\limits_{i\\in J_n}a_i x_i + \\sum\\limits_{j\\in J_m}\\alpha b_j y_j  \\\\\n             &= \\sum\\limits_{k\\in J_n}c_k z_k + \\sum\\limits_{k = n+1}^{n+m} c_k z_k  \\\\\n             &=  \\sum\\limits_{k \\in J_{n+m}} c_k z_k\n          \\end{align*}\n          so, $P$ is a submmodule of $M$ containing $S$.\n          \\newline Now, we'll show that $P$ is \\underline{smallest} submmodule of $M$ containing $S$.\n          \\newline \\bigskip\n          Let $K$ be any arbitirary submodule of $M$ containing $S$\n           \\[\\text{i.e.} \\ K \\ \\in \\mathcal{F}\\]\n          $\\because  \\ \\ \\ K $ is a submodule and $S \\subseteq K$ \\newline\n          $\\therefore \\  K$  is closed under scaler multiplication and addition.\n          \\[\\text{i.e}\\qquad \\sum\\limits_{i \\in J_n} a_i x_i  \\in K \\]  \\marginnote[-2.5em]{$\\forall \\ a_i \\in R \\ \\& \\ x_i \\in S $}\n          so , \\[P =\\left\\langle S\\right\\rangle \\subseteq K \\]\n               Hence,  $P$ is smallest submmodule of $M$ containing $S$.\n           \\end{description}\t\n\t\n\t\n\\end{proof}\n\\bigskip\n\\begin{defn}[\\textbf{Generating Set / Set of Generators}]\nA set of generators for a left (right) $R$-module $M$ is a subet $S$ of $M$ such that\n\\[M = \\left\\langle S\\right\\rangle \\]\nif no proper submodule of $M$ contains $S$ then $S$ generates $M$ (verify ?)\n\\end{defn}\n\\bigskip\n\\subsection{Examples}\n\\begin{description}\n  \\item[1.] A   ring $R$ considered as left (right) $R$-module is generated by identity element $\\lbrace1\\rbrace$\n\n  \\item[2.] $\\mathbb{Z}\\times \\mathbb{Z}$  over $ \\mathbb{Z}  $ can be generated by\n  \\[S =\\left\\lbrace(0,1),(1,0)\\right\\rbrace\\]\n  \\item[3.] All finite dimensional vector space can be generated by it's basis (finite), so is finitely generated submodule.\n  \\item[4.] Let $R$ be a ring, $I$ be left(right) ideal of $R$ then it is a left(right) $R$-module. So, every  finitely  generated left(right) ideals of $R$ are finitely generated submodule.\n  \\item[5.] A submodule of left $R$-module is cyclic iff it is prinicipal ideal of $_RR$.\n\\end{description}\n\\bigskip\n\\begin{defn}\n  Let $M$ be a left $R$-module and $\\left\\lbrace N_\\alpha\\right\\rbrace_{\\alpha \\in \\Omega }$ \\marginnote{where $\\Omega$ is indexing set. } be family of submodules of $M$ then sum $\\sum\\limits_{\\alpha \\in \\Omega } N_\\alpha $ is defined to be a submodule of $M$ generated by $\\bigcup\\limits_{\\alpha \\in \\Omega}N_\\alpha $  \\[\\left\\langle \\bigcup_{\\alpha \\in \\Omega}N_\\alpha \\right\\rangle = \\sum\\limits_{\\alpha \\in \\Omega } N_\\alpha \\] \\bigskip\n   Moreover, $\\sum\\limits_{\\alpha \\in \\Omega } N_\\alpha $ is smallest submodule of $M$ containing $N_\\alpha $ \\marginnote[-2em]{for each $\\alpha \\in \\Omega$}\n  \\end{defn} \\bigskip\n  \\begin{prop}\n    Let $M$ be a left $R$-module and $\\left\\lbrace N_\\alpha\\right\\rbrace_{\\alpha \\in \\Omega }$ \\marginnote{where $\\Omega$ is indexing set. } be family of submodules of $M$ then sum \\[\\sum\\limits_{\\alpha \\in \\Omega } N_\\alpha =\\left\\lbrace \\sum\\limits_{\\alpha \\in \\Omega } x_\\alpha \\middle\\vert\\, x_\\alpha \\in N_\\alpha \\quad ,\\  x_\\alpha = 0 \\; \\textmd{for almost all} \\; \\alpha  \\right\\rbrace \\] \\marginnote[-2em]{for each $\\alpha \\in \\Omega$}\n    \\begin{proof}\n      Let \\[P = \\left\\lbrace \\sum\\limits_{\\alpha \\in \\Omega } x_\\alpha \\middle\\vert\\, x_\\alpha \\in N_\\alpha \\quad , \\ x_\\alpha = 0 \\; \\textmd{for almost all} \\; \\alpha\\right\\rbrace \\]\n      We need to show that $P$ is smallest submodule of $M$ containing each $N_\\alpha$\n      \\newline  \\bigskip\n      \\textbf{Claim 1 :}.  \\qquad $P$ is submodule of $M$  \\newline Clearly, $P$ is non-emptpy. Taking $x_\\alpha = 0$ for each $\\alpha \\in \\Omega$, we have \\[\\Rightarrow0 \\in P\\] Also, for a fixed but arbitirary $\\alpha \\in \\Omega $ \\newline Let $x\\in N_\\alpha$ and  choose \\[ x_i = \\begin{cases}\n                                 x, & \\mbox{if } i =\\alpha \\\\\n                                 0, & \\mbox{otherwise}.\n                               \\end{cases}\\]\n            so $x =\\sum x_i \\in P$  we have $N_\\alpha \\subseteq P \\qquad \\forall \\alpha \\in \\Omega$ \\marginnote{$\\because \\ \\alpha$ was arbitrary chosen}\n      \\newline  \\bigskip\n      Now , we'll show that $P$ is submodule of $M$ using submodule criterion.\\newline\n      \\begin{description}\n        \\item[\\textbf{$P$ is closed under addition and scaler multiplication}]   Let $u\\ , \\ v$ be two elements of $P$\n        \\[u = \\sum_{\\alpha} x_\\alpha \\] \\marginnote[-2.5em]{where $x_\\alpha \\in N_\\alpha$ and \\newline $x_\\alpha = 0$ for almost all $\\alpha$}\n        \\begin{align*} v &= \\sum_{\\beta} y_\\beta \\mathnote{where $y_\\beta \\in N_\\beta$ and \\newline $y_\\beta = 0$ for almost all $\\beta$}\n       \\end{align*} \\newpage\n        Let $\\Omega_1$ ,  $\\Omega_2$ be finite subsets of  $\\Omega$ for which  $x_\\alpha$ and $y_\\beta$ are non-zero respectively.\n        \\[x_\\alpha = \\begin{cases}\n           \\text{non-zero}, & \\mbox{if } \\alpha \\in \\Omega_1 \\\\\n          0, & \\mbox{otherwise}.\n        \\end{cases} \\qquad , \\qquad y_\\beta = \\begin{cases}\n          \\text{non-zero}, & \\mbox{if } \\beta \\in \\Omega_2 \\\\\n          0, & \\mbox{otherwise}.\n        \\end{cases} \\]\n        Also for any arbitirary scaler $c \\in R$ , define\n        \\[z_r = \\begin{cases}\n                  x_r, & \\mbox{if } r \\in \\Omega_1 \\\\\n                  c y_r, & \\mbox{if } r \\in \\Omega_2.\n\n                   \\end{cases} \\qquad \\Rightarrow z_r = x_r + c y_r \\qquad \\forall r\\ \\in \\Omega_1 \\cap \\Omega_2\\]\n        Now ,  \\begin{align*}u + c v & = \\sum_{\\alpha} x_\\alpha + c \\sum_{\\beta} y_\\beta \\\\ & = \\sum_{\\alpha \\in \\Omega_1} x_\\alpha + c \\sum_{\\beta \\in \\Omega_2} y_\\beta \\\\ & = \\sum_{\\alpha \\in \\Omega_1} x_\\alpha +  \\sum_{\\beta \\in \\Omega_2} c y_\\beta \\\\& = \\sum_{r \\in \\Omega_1} x_r +  \\sum_{r \\in \\Omega_2} c y_r + \\sum_{r \\in \\Omega_1 \\cap \\Omega_2} (x_r + c y_r)      \\\\ \\text{Thus , We have}\\\\ u+cv &= \\sum_{r \\in \\Omega_1 \\cup \\Omega_2} z_r   \\in P \\mathnote{$z_r = 0 \\quad \\text{for almost all } r \\newline \\because \\Omega_1 \\cup \\Omega_2 \\text{ is also finite.}$}\n        \\end{align*}\n         \\end{description}\n      \\textbf{Claim 2 :}.  \\qquad $P$ is smalleat submodule of $M$ containing each $N_\\alpha$. \\newline \\bigskip\n      Let $N$ be any submodule of $M$ containing each $N_\\alpha$ \\newline $\\therefore \\ N$ is closed under addition   so $N$ contains all finite sum of the form $\\sum\\limits_{\\alpha}x_\\alpha $  where $ x_\\alpha \\in N_\\alpha \\quad \\& \\quad x_\\alpha = 0 \\ ,\\text{for almost all }\\alpha $ \\newline  It follows that  $P \\subseteq N$     \\marginnote{$\\because \\ N$ was chosen arbitirary}\n      \\newline \\bigskip Thus, $P$ is smallest submodule of $M$ containing each $N_\\alpha$ \\end{proof}   \\end{prop}\n      \\bigskip\n      \\begin{defn}[\\textbf{Maximal Submodule}]\n      Let $N$ be a submodule of left $R$-module $M$ then $N$ is said to be a maximal submodule of $M$ if there does not exist any proper submodule of $M$.\\newline\\bigskip\n      In other words , for any sumodule $K$ of $M$ satisfing\n      $N\\subseteq K \\subseteq M$ \\newline we must have \\[\\text{either  } N = K \\quad \\text{or  } K = M  \\] for $N$ to be a maximal submodule of $M$.\n      \\end{defn}\n                   \\bigskip\n\n      \\begin{thm}\n        Let $M$ be a finitely generated left $R$-module then every proper submodule of $M$ is contained in maximal submodule of $M$.\\newline In particular , if $M$ is non-trivial then $M$ contains a maximal submodule.\n      \\end{thm}\n       \\begin{proof}\n         Left to Reader.\n       \\end{proof}\n       \\bigskip\n       \\begin{remark}\n         $\\mathbb{Q} $ is not finitely generated $\\mathbb{Z}$-module.\n       \\end{remark}\n       \\begin{description}\n         \\item[Verification:] Let  $\\mathbb{Q} $ is finitely generated over $\\mathbb{Z}$ by\n         \\[ \\left\\lbrace\\frac{p_i}{q_i} \\ \\middle\\vert\\ p_i , q_i \\in \\mathbb{Z} \\ , \\ q_i \\neq 0 \\quad \\forall \\ i \\in J_n\\right\\rbrace \\]      Without loss of generality , Assume that \\[q_1 , q_2 , q_3 , \\cdots , q_n > 0\\] then we can always choose an integer (say $k$) such that\n         \\[k = q_1  q_2  q_3  \\cdots  q_n > 0 \\]\n         <incomlete>\n       \\end{description} ", "meta": {"hexsha": "5aa3914d3b77eb3c8541c815c0adea203ff55669", "size": 26479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/chapter01.tex", "max_stars_repo_name": "sirkapil/module-theory", "max_stars_repo_head_hexsha": "bfb1b6a9aafd9360a4aad8752e0cdc82da946470", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-01-12T14:01:13.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-12T14:01:13.000Z", "max_issues_repo_path": "Chapters/chapter01.tex", "max_issues_repo_name": "sirkapil/module-theory", "max_issues_repo_head_hexsha": "bfb1b6a9aafd9360a4aad8752e0cdc82da946470", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-01-15T03:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-15T09:13:04.000Z", "max_forks_repo_path": "Chapters/chapter01.tex", "max_forks_repo_name": "sirkapil/module-theory", "max_forks_repo_head_hexsha": "bfb1b6a9aafd9360a4aad8752e0cdc82da946470", "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.7002141328, "max_line_length": 608, "alphanum_fraction": 0.6242682881, "num_tokens": 9538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.6963804028862558}}
{"text": "\\subsection{Variance analysis in backward propagation phase}\nRecall the loss function\n$$\nL(\\theta)=\\mathbb{E}_{(x, y) \\sim D} \\ell \\left(\\operatorname{softmax}\\left(f^{L}\\right), y\\right),\n$$\nwhere $ f^{L}(x; \\theta) $  is the DNN function defined by \n$$\n\\left\\{\\begin{array}{l}f^{1}(x)=W^{1} x+b^{1} \\\\ f^{l}(x)=W^{l} \\sigma\\left(f^{l-1}(x)\\right)+b^{l} \\quad \\forall l=2, \\cdots L\\end{array}\\right. .\n$$\nThen we have the following backward propagation (\"BP\") formula\n$\n\\frac{\\partial L(\\theta)}{\\partial W^{l}}=\\frac{\\partial L}{\\partial f^{l}} \\cdot \\frac{\\partial f^{l}}{\\partial W^{l}},\n$\nwhere \n$\\frac{\\partial L}{\\partial t^{l}} \\in \\mathbb{R}^{n_e}, \\frac{\\partial f}{\\partial W^{l}} \\in \\mathbb{R}^{n_{e} \\times\\left(n_{e} \\times n_{e-1}\\right)}$. More Precisely,\n$$\n\\frac{\\partial L(\\theta)}{\\partial W_{s t}^{l}}=\\sum\\limits_{i=1}^{n_{l}}\\left(\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}} \\cdot \\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}\\right).\n$$\nAssume that\n\\begin{enumerate}\n\\item $\\left\\{\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}} \\cdot \\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{L}}\\right\\}_{i=1}^{n_{e}}$ are independent\n\\item For each i,   $ \\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}  $ and $\\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}$ are independent \n\\end{enumerate}\nActually, we can not such make general assumptions as $L(\\theta), f_{i}^{l}, \\frac{\\partial f_{i}^{l}}{\\partial W_{st}} \\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}$   are all fixed. We still make these assumption here to get some idea of the choice of $W_{s t}^{l}$. \n\\begin{lemma}\\label{th:idnormal2}\nIf $\\sigma =id$ and  the above assumption holds,\n$$\\mathbb{V}\\left[\\frac{\\partial L (\\theta)}{\\partial W_{s t}^{l}}\\right] = \\prod\\limits_{j=l+1}^{L-1} n_{j} \\mathbb{V}\\left[W_{s t}^{j}\\right] \\left(\\mathbb{V}\\left[W_{s t}^{L}\\right]\\sum\\limits_{k=1}^{n_{L}} \\mathbb{E}\\left[\\left(\\frac{\\partial L(\\theta)}{\\partial f_{k}^{2}}\\right)^{2}\\right]\\right) \n\\prod\\limits_{j=2}^{l-1} n_{j} \\mathbb{V}\\left[W_{s t}^{j}\\right] \\left(\\mathbb{V}\\left[W_{s t}^{1}\\right]\\sum\\limits_{R=1}^{d} \\mathbb{E}\\left[ X_{k}^{2}\\right]\\right).\n$$\n\\end{lemma}\n\\begin{proof}\nThe assumption leads to\n\\begin{equation}\\label{normale0}\n\\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial W_{st}^{l}}\\right]=\\sum\\limits_{i=1}^{n_{l}}\\left( \\mathbb{E}\\left[\\left(\\frac{\\partial L(\\theta)}{\\partial f^{l}_{i}}\\right)^{2}\\right] \\mathbb{E}\\left[\\left(\\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}\\right)^{2}\\right] - \\left(\\mathbb{E}\\left[\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}\\right] \\mathbb{E}\\left[\\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}\\right]\\right)^{2}\\right) .\n\\end{equation}\nThis implies that we only need to consider $ \\mathbb{E}\\left[\\left(\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}\\right)^{2}\\right] $ and  $ \\mathbb{E}\\left[\\left(\\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}\\right)^{2}\\right]$.\n\\begin{enumerate}\n\\item Consider $ \\mathbb{E}\\left[\\left(\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}\\right)^{2}\\right] $. By chain rule:\n\t$$\n\t\\begin{aligned} \n\t\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}} &=\\frac{\\partial L(\\theta)}{\\partial f^{l+1}}\\cdot \\frac{\\partial f^{l+1}}{\\partial f_{i}^{l}} =\\sum_{j=1}^{n_{l+1}} \\frac{\\partial L(\\theta)}{\\partial f_{j}^{l+1}} \\frac{\\partial f_{j}^{l+1}}{\\partial f_{i}^{l}}\n\t \\\\ &=\\sum_{j=1}^{n_{l+1}} W_{j i}^{l+1} \\sigma^{\\prime}\\left(f_{i}^{l}\\right) \\frac{\\partial L(\\theta)}{\\partial f_{j}^{l+1}}=\\sum\\limits_{j=1}^{n_{l+1}} W_{j i}^{l+1} \\frac{\\partial L(\\theta)}{\\partial f_{j}^{l+1}}(\\mbox{ if }\\sigma=id)\n\t\\end{aligned} \n\t$$\n\tKeep doing this:\n\t$$\n\t\\frac{\\partial L(\\theta)}{\\partial f^{l}}=\\left[W^{l+1}\\right]^{\\top} \\cdot\\left[W^{l+2}\\right]^{\\top} \\cdots\\left[W^{L}\\right]^{T} \\frac{\\partial L(\\theta)}{\\partial f^{L}}\n\t$$\n\tAssume the independence of $ \\frac{\\partial L(\\theta)}{\\partial f^{L}} $  with $W^{l+i}, i= 1,2, \\dots$.\n\t( Still we make this assumption although this can not be ture, as $ \\frac{\\partial L(\\theta)}{\\partial f^{l}} $ contains  $W^{l+i}$.) Then \n\t$$\n\t\\mathbb{E}\\left[\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}\\right]=\\sum\\limits_{j} \\mathbb{E}\\left[W_{j i}^{l+1}\\right] \\mathbb{E}\\left[\\frac{\\partial L(\\theta)}{\\partial f_{j}^{l }}\\right]=0\n\t$$\n\t\\begin{equation}\\label{normale1}\n\t\\mathbb{E}\\left[\\left(\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}\\right)^{2}\\right]=\\mathbb{V}\\left[{\\frac{\\partial L(\\theta)}{\\partial f_{i}^{l}}}\\right]=\\prod\\limits_{j=l+1}^{L-1} n_{j} \\mathbb{V}\\left[W_{s t}^{j}\\right] \\cdot\\left(\\mathbb{V}\\left[W_{s t}^{L}\\right] \\sum\\limits_{i=1}^{n_{L}} \\mathbb{E}\\left[\\left(\\frac{\\partial L( \\theta)}{\\partial f_{i}^{L}}\\right)^{2}\\right]\\right)\n\t\\end{equation}\n    \\item Consider $ \\mathbb{E}\\left[\\left(\\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}\\right)^{2}\\right]\n    $. By definition, \n    $\n    \\frac{\\partial f_{i}^{l}}{\\partial W_{s t}^{l}}=\\delta_{i s} \\sigma\\left(f_{t}^{l-1}\\right)\n    $\n    namely, only\n\t$\n\t\\frac{\\partial f_{s}^{l}}{\\partial W_{s t}^{l}} \\not = 0,\n\t$\n\tand $\\frac{\\partial f_{s}^{l}}{\\partial W_{s t}^{l}} = \\sigma\\left(f^{l-1}_{t}\\right)$. If $ \\sigma $=id, apply the forward results\n\t\t\\begin{enumerate}\n\t\t\\item Expectation: \n\t\t$$\n\t\t\\mathbb{E}\\left[\\left(\\frac{\\partial f_{s}^{l}}{\\partial W_{s t}^{l}}\\right)\\right]=0.\n\t\t$$\n\t\t\\item Variance:\n\t\t\\begin{equation}\\label{normale2}\n\t\t\\begin{split}\n\t\t\\mathbb{E}\\left[\\left(\\frac{\\partial f_{s}^{l}}{\\partial W_{s t}^{l}}\\right)^{2}\\right]& =\\mathbb{E}\\left[\\left(f_{t}^{l-1}\\right)^{2}\\right]=\\mathbb{V}\\left[ f_{t}^{l-1}\\right]\n\t\t\\\\\n\t\t&=\\prod\\limits_{j=2}^{l-1} n_{j-1} \\mathbb{V}\\left[W_{s t}^{j}\\right] \\cdot\\left(\\mathbb{V}\\left[W_{s t}^{1}\\right] \\sum\\limits_{k=1}^{d} \\mathbb{E}\\left[X_k^{2}\\right]\\right).\n\t\t\\end{split}\n\t\t\\end{equation}\n\t\t\\end{enumerate} \n\\end{enumerate}\nA combination of \\eqref{normale0}, \\eqref{normale1} and \\eqref{normale2} completes the proof.\n\\end{proof}\n\nNext we consider $ \\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial W^{l} _{st}}\\right] $.\n\t\\begin{equation*}\n\t\\begin{split} \n\t&\\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial W^{l} _{st}}\\right] =\\mathbb{V}\\left[\\frac{\\partial L (\\theta)}{\\partial f_{s}^{l}}\\right] \\cdot \\mathbb{V}\\left[f^{l-1}_{t}\\right] \n\t\\\\\n\t =& \\prod\\limits_{j=l+1}^{L-1} n_{j} \\mathbb{V}\\left[W_{s t}^{j}\\right] \\left(\\mathbb{V}\\left[W_{s t}^{L}\\right]\\sum\\limits_{k=1}^{n_{L}} \\mathbb{E}\\left[\\left(\\frac{\\partial L(\\theta)}{\\partial f_{k}^{L}}\\right)^{2}\\right]\\right) \\times \\prod\\limits_{j=2}^{l-1} n_{j} V\\left[W_{s t}^{j}\\right] \\left(\\mathbb{V}\\left[W_{s t}^{1}\\right]\\sum\\limits_{R=1}^{d} \\mathbb{E}\\left[ X_{k}^{2}\\right]\\right),\n\t\\end{split}\n\t\\end{equation*}\n\twhere $ \\mathbb{V}_{1}=\\left(\\mathbb{V}\\left[W_{s t}^{1}\\right]\\sum\\limits_{k=1}^{d} \\mathbb{E}\\left[ X_{k}^{2}\\right]\\right)\t$,\n$  \\mathbb{V}_{L}=\\mathbb{V}\\left[W_{s t}^{L}\\right]\\sum\\limits_{k=1}^{n_{L}} \\mathbb{E}\\left[ (\\frac{\\partial L(\\theta)}{\\partial f_{k}^{L}})^{2}\\right]$.\n\n\nWe consider\n$$\n\t\\mathbb{V}\\left[W_{s t}^{l}\\right]=f\\left(n_{l}, n_{l-1}\\right).\n\t$$\n We summarize Lemma \\ref{th:idnormal} and Lemma \\ref{th:idnormal2} as below\n \\begin{enumerate}\n\\item \n$ \n\\mathbb{V}\\left[f_{i}^{l}\\right]  =\\prod\\limits_{j=2}^{l} n_{j-1} f\\left(n_{j}, n_{j-1}\\right)\\left(\\mathbb{V}\\left[W_{s t}^{1}\\right]\\sum\\limits_{k=1}^{d} \\mathbb{E}\\left[ X_{k}^{2}\\right]\\right) \n$\n\\item $\\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial f_{i}^{2}}\\right]= \\prod\\limits_{j=1+1}^{L-1} n_{j} f\\left(n_{j}, n_{j-1}\\right)\\cdot\\left(\\mathbb{V}\\left[W_{s t}^{L}\\right] \\sum\\limits_{i=1}^{n_{L}} \\mathbb{E}\\left[\\left(\\frac{\\partial L( \\theta)}{\\partial f_{i}^{l}}\\right)^{2}\\right]\\right) \n$\n\\item $ \\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial W^{l} _{st}}\\right] = \\prod\\limits_{j=l+1}^{L-1}n_{j} \\cdot f\\left(n_{j}, n_{j-1}\\right) \\cdot \\prod\\limits_{j=2}^{l-1}n_{j-1}f\\left(n_{j}, n_{j-1}\\right) \\times \\mathbb{V}_{1} \\times \\mathbb{V}_{L}\n$\n\\end{enumerate}\nBased on the equations above, we have different choice of $\\mathbb{V}\\left[W_{s t}^{l}\\right]$\n\\begin{enumerate}\n\t\\item If $f\\left(n_{1}, n_{j-1}\\right)=\\frac{1}{n_{j-1}}$ (control $W[f_{i}^{l}]$), \n\t$\\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial W_{s t}^{l}}\\right]$ will decrease as $l$ grow up. (Notice that $n_{l}>n_{k}$ if $l>k$)\n\t\\item If $f\\left(n_{j}, n_{j-1}\\right)=\\frac{1}{n_{j}}$ (control $V[\\frac{\\partial L(\\theta)}{ \\partial f_{i}^{L}} ]$),\n\t$\n\t\\mathbb{V}\\left[\\frac{\\partial L(\\theta)}{\\partial W_{s t}^{l}}\\right]$\t\n\t still decrease!\n\t\\item If $f\\left(n_{j}, n_{j-1}\\right)=\\frac{2}{n_{j}+n_{j-1}}( \\leq \\frac{1}{\\sqrt{n_{j} n_{j-1}}})$,\n\t$\n\t\\mathbb{V}\\left[\\frac{\\partial L (\\theta)}{\\partial W^{l}_{st}}\\right]=\\frac{\\sqrt{n_{L-1}} \\cdot \\sqrt{n_{1}}}{\\sqrt{n_{l}} \\cdot \\sqrt{n_{l-1}}} \\times \\mathbb{V}_{1} \\times \\mathbb{V}_{L}\n\t$\n\tdecrease!\n\\end{enumerate}\n\t\n\\paragraph{Question}\nCan we design some other choices of  $ \\mathbb{V}\\left[ W^{l} _{st}\\right]$ such  that  $\\mathbb{V} \\left[\\frac{\\partial L(\\theta)}{\\partial W^{l} _{st}}\\right]$ admits the following properties:\n\\begin{itemize}\n\t\\item Keep constant,\n\t\\item Increase,\n\t\\item Change with certain scale.\n\\end{itemize}", "meta": {"hexsha": "0fe798a18acec3509ef7af34ada0743fdfdf1b3f", "size": 9099, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Init_Backward.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/Init_Backward.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/Init_Backward.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": 68.4135338346, "max_line_length": 443, "alphanum_fraction": 0.6136938125, "num_tokens": 3788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6962967941367117}}
{"text": "\\subsection{Goal Objective}\n\\label{text:approach/objective/goal}\nThe goal objective gives an incentive for the optimizer to choose a solution that targets the goal state. It simply consists of the squared L2-norm between each robot trajectory point and the goal state $\\goal$, normalized over the full planning horizon $T$:\n\n\\begin{equation}\nJ_{goal}(\\x_{0:T}) = \\frac{1}{T} \\sum_{t = 0}^T (\\x_t - \\goal)^2\n\\label{eq:goal_unweighted}\n\\end{equation}\n\nBy normalization, the cost is independent of the length of the planning horizon $T$ and thus allows us to use the same weight $w_{goal}$ for different planning horizons.\n\n\\subsubsection{Horizon weighting}\nIntuitively, as discussed in Chapter \\ref{text:introduction} for socially aware navigation, socially aware objectives should be higher weighted than traditional control effort or travel time objectives. This is especially true at the beginning of the planning horizon. For this reason, a horizon-dependent weighting $\\lambda_t$ is introduced into the stage cost of the goal objective, which is small at the beginning of the horizon and large at its end:\n\n\\begin{equation}\nJ_{goal}(\\x_{0:T}) = \\frac{1}{T} \\sum_{t = 0}^T \\lambda_t (\\x_t - \\goal)^2\n\\label{eq:goal_weighted}\n\\end{equation}\n\nAs shown later on, this modification empowers a fast convergence to the robot's evasive movements, when necessary, to avoid unsafe situations. At the same time, properties of $J_{goal}(\\cdot)$, such as, most importantly, convexity, remain unchanged. \n\n\\subsubsection{Gradient}\nSince the goal objective $J_{goal}(\\x_{0:T})$ is only a function of the robot's planned trajectory and the goal state, its Jacobian can be derived without further knowledge of the pedestrian prediction model, merely using the (known) robot dynamics. As described in Section \\ref{text:approach/overview}, the robot controls are optimized. Hence by applying the chain rule, we get:\n\n\\begin{equation}\n\\nabla J_{goal} = \\pd{J_{goal}}{\\u_{0:T-1}} = \\pd{J_{goal}}{\\x_{0:T}} \\cdot \\pd{\\x_{0:T}}{\\u_{0:T-1}}\n\\end{equation}\n\nAs demonstrated, the goal-objectives gradient can be derived by multiplying the gradient of the objective with respect to the robot's trajectory with the gradient of the robot's trajectory with respect to its control inputs. Since the goal-objective directly depends on the trajectory, deriving the first term is straightforward to derive. The second term $\\delta \\x_{0:T} / \\delta \\u_{0:T-1}$ is not trivial because of the iterative structure of rolling out state trajectories based on dynamics, and as the robot's dynamics $\\f(\\cdot)$ can be arbitrary. However, as described in Section \\ref{text:approach/formulation}, double integrator dynamics are assumed for the robot so that the whole trajectory $\\x_{0:T}$ can be expressed as a function of the initial state $\\x_0$ and the control inputs $\\u_{0:T-1}$ only, as shown in Equation \\ref{eq:dynamics_stacked}. Then the term $\\delta \\x_{0:T} / \\delta \\u_{0:T-1}$ simplifies to a constant term:\n\n\\begin{align}\n\\pd{J_{goal}}{\\x_{0:T}} &= \\pd{}{\\x_{0:T}} \\frac{1}{N} \\sum_{t = 0}^N (\\x_t - \\goal)^2 \\\\\n&= \\frac{2}{T} \\begin{bmatrix} (\\x_1 - \\goal) & \\hdots & (\\x_T - \\goal) \\end{bmatrix}^T\n\\end{align}\n\\begin{align}\n\\pd{\\x_{0:T}}{\\u_{0:T-1}} &= \\pd{}{\\u_{0:T-1}} \\begin{bmatrix} A \\x_0 \\\\ A_n \\x_0 + B_n \\u_{0:T-1} \\end{bmatrix} \\\\\n&= \\begin{bmatrix} \\boldsymbol{0}_{n \\times m} \\\\ B_n \\end{bmatrix}\n\\label{eq:goal_gradient_dynamics}\n\\end{align}\n\nwith $A_n, B_n$, the stacked state-space description matrices as described in Section \\ref{text:approach/runtime/unrolling}.\n\\newline\nOverall, the goal objective and its gradient are very efficient, cheap to compute, having linear complexity with the length of the planning horizon $T$, and independent of the number of pedestrians. Furthermore, it is strictly convex, which improves the optimization convergence speed. Therefore, it is quite valuable for warm-starting the optimization algorithm, as further explained in Section \\ref{text:approach/runtime/warm_starting}.\n", "meta": {"hexsha": "e9b8ae25b72d6af255606e9da1ae677a494a55c7", "size": 4005, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/objective_goal.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_goal.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_goal.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": 91.0227272727, "max_line_length": 945, "alphanum_fraction": 0.750062422, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6962967935362493}}
{"text": "\n\\section{The \\selectionsort algorithm}\n\\Label{sec:selectionsort}\n\nOur version of the \\selectionsort algorithm has the signature\n\n\\begin{lstlisting}[style = acsl-block]\n\n  void selection_sort(value_type* a, size_type n);\n\\end{lstlisting}\n\nThe \\selectionsort algorithm sorts an array in increasing order, left to\nright, by selecting in each step the minimum element of the remaining segment\nand \\emph{swaps} it with its first element.\n%\nThis implies that each member of the increasingly ordered initial segment is less or equal than\neach member of the remaining segment.\n\n\\begin{figure}[hbt]\n\\begin{center}\n\\includegraphics[width=0.65\\textwidth]{Figures/selection_sort.pdf}\n\\caption{An iteration of \\selectionsort}\n\\Label{fig:selectionsort-example}\n\\end{center}\n\\end{figure}\n\n\\FloatBarrier\n\nFigure~\\ref{fig:selectionsort-example} shows a typical situation in an\nexample run.\nThe algorithm will swap the \\inl{28} at position \\inl{i} with the\n\\inl{9} at position \\inl{min} to extend the increasingly ordered initial segment\none field to the right.\n\n\\subsection{Formal specification of \\selectionsort}\n\nThe following listing shows the specification of \\selectionsort.\n\n\\input{Listings/selection_sort.h.tex}\n\n\\clearpage\n\n\n\\subsection{Implementation of \\selectionsort}\n\nThe implementation of \\selectionsort is shown in the next listing.\n%\nWe use \\specref{minelement} to find the minimum element of the remaining array segment.\n\n\\input{Listings/selection_sort.c.tex}\n\nThe loop invariants \\inl{increasing} and \\inl{lower} establish that the\ninitial segment \\inl{a[0..i-1]} is in increasing order and, respectively,\nstate that \\inl{a[i-1]} is a lower bound of the remaining segment \\inl{a[i..n-1]}.\nSince the \\minelement call uses an address offset, we had\nto employ again the \\emph{shift lemmas} from the collection \\logicref{ArrayBoundsShift}.\n\nThe loop invariant \\inl{reorder}, on the other hand, states that the multiset of values in the\narray \\inl{a} are only \\emph{rearranged} during the algorithm.\n%\nWhile this is intuitively most obvious (as the call to the \\specref{swap}\nroutine, is the only code that modifies~\\inl{a}),\nit took considerable effort to prove it formally; including a statement contract\nthat captures the effects of calling \\swap.\n\nThe main reason for introducing the statement contract is that it\n\\emph{transforms} the postcondition of the call to \\specref{swap}\ninto the hypotheses for the lemma \\logicref{MultisetSwapMiddle}.\nThis lemma, which relies on the lemmas about \\logicref{MultisetReorder},\ncaptures the fact that \\emph{swapping two elements of an array} is a \\emph{reordering}.\n\n\\clearpage\n\n", "meta": {"hexsha": "66bd593c894b8ae1fe44f5bed89951642cd80e9b", "size": 2619, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/sorting/selection_sort.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/sorting/selection_sort.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/sorting/selection_sort.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 35.3918918919, "max_line_length": 95, "alphanum_fraction": 0.7873234059, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.6962961537376688}}
{"text": "\\Lecture{Jayalal Sarma}{Oct 26, 2020}{23}{Extremal Problems In Graphs-Three Proofs,Mantels Theorem}{Praharsh Allada}{$\\alpha$}{JS}\n\\section{Introduction}\nThis week we are going to look at some extremal problems in graphs.The techniques we use to Solve the problems are more important than the problems themselves.In fact we will look at multiple ways of proving the same statement using different techniques to prove.\\\\\n\\section{Some Examples}\n\\textbf{Example 1:-}\\\\\nSuppose an Undirected Graph G ,does not have triangle(no $k_3$), what is the maximum number of edges the graph G can have?\\\\\n(OR)\\\\ \nWhat is the minimum number of edges that a graph G with n vertices should have so that it always contains at least 1 triangle?\\\\\n\\textbf{Solution:-}\\\\\nThe graph can be divided Into 2 sets of vertices of size $\\frac{n}{2}$ and from all the possible edges from one set to another.In this case we put in $\\frac{n^2}{4}$ edges.(From a little thought and AM$ \\geq $GM we can see that the highest number of edges are produced when each set contains $\\frac{n}{2}$ vertices).The answer to the question is this the best we can do is yes,this is the best that we can do, we can not have more than $\\frac{n^2}{4}$ edges with no triangle in the graph.\n\\section{Mantel's theorem}\n\\begin{theorem}\nAny graph G on n vertices having more than $\\frac{n^2}{4}$ edges must contain a triangle\n\\end{theorem}\n\\begin{proof}\nLet us prove Mantel's theorem using three simple techniques and shifting argument.Let us look at the three different techniques in this lecture and then look at shifting argument in the next.Later let us also look at generalisation of Mantel's theorem.The three techniques  we will be using are double counting argument(we will be using cauchy schwarz inequality),Arithmetic Mean-Geometric Mean Inequality,An application of P.H.P.\\\\\n\\textbf{Proof1:-Double Counting argument}\\\\\nWe define a mathematical quantity and find its upper and lower bound using two different methods thus calculating an inequality for the parameters involved.\\\\\nLet m be the number of edges in a graph G that does not have any triangles we have to show that $m \\le \\frac{n^2}{4}$\\\\\nLet, x,y $\\in$ V and G contains the edge between x and y the x and y cannot have an edge with a common vertex.(i.e, adjacent vertices can not have common neighbours).\nIn other words d(x)+d(y)$\\le$ n (Since,they cannot have any other common neighbours d(x)+d(y) $\\leq$ n-2 without counting edge (x,y) and then we add 2 for the edge (x,y))\\\\\nNow the quantity we are going to double count is $\\sum_{x \\in V} d(x)^2$\nFirst let us find the Upper bound for this.Now the above quantity can be thought as d(x) being summed d(X) times\\\\\n$$\\implies \\sum_{x \\in V}d(x)^2=\\sum_{(x,y) \\in E}(d(x)+d(y)) \\leq m*n(Since,\\sum_{(x,y)\\in E} \\leq n)$$\nNow we will calculate the lower bound on the above quantity in terms of m so that the upper and lower bounds to gather w=might give us a bound on m\nNow for this let us first take a look at cauchy schwarz inequality.\\\\\n\\begin{theorem}\n\\textbf{cauchy schwarz inequality:-}\\\\\nlet u,v $\\in R^n, $$< u,v >=\\sum_{i=1}^n\nu_i*v_i$, $||u||=< u,u >=\\sum_{i=1}^n u_i^2$\\\\\n$$|< u,v >|^2 \\leq ||u||*||v||$$\n$$i.e,(\\sum_{i=1}^n u_i*v_i)^2 \\leq (\\sum_{i=1}^n u_i^2)(\\sum_{i=1}^n v_i^2)$$\n\\begin{proof}\nlet us assume $u \\neq 0$ and $\\lambda \\in \\mathbb{R}$\\\\\n$0\\leq <\\lambda u-v ,\\lambda u-v >=\\lambda^2 <u,u> -\\lambda <u,v> -\\lambda <v,u> +<v,v>\\\\\n=\\lambda^2 <u,u> -2\\lambda <u,v>+<v,v>$\\\\\nChoose $\\lambda=\\frac{<u,v>}{<u,u>} $ substituting in the equation yields \n$$\\frac{<u,v>^2}{<u,u>}-2\\frac{<u,v>^2}{<u,u>}+<v,v> \\geq 0$$\n$$\\implies <u,v>^2 \\leq <u,u><v,v>$$\n\\end{proof}\n\\newpage\nNow let us use the cauchy schwarz inequality to obtain the lower bound.\nLet $V={x_1,x_2,....x_n}$ now let us define $u=(d(x_1),d(x_2),.....d(x_n),v=(1,1,1,...,1)$\\\\\n$u_iv_i=d(x_i)\\\\\n\\implies \\sum (u_i*v_i)^2=(\\sum d(x))^2 \\implies \\sum (d(x)^2) \\geq \\frac{(\\sum d(x)^2)}{n}=\\frac{(2m)^2}{n}=\\frac{4m^2}{n} \\implies \\frac{4m^2}{n}\\leq mn \\implies m \\leq \\frac{n^2}{4}$\n\\end{theorem}\n\n\\textbf{Proof 2:- AM-GM Inequality}\n\nNeighbours of any vertex x $\\in$ V can not have any edges among themselves.(i.e, they must form an independent set). Let A be the largest independent set in the graph, then we have $\\forall x$\nd(x) $\\leq |A|$ .If we consider B=V-A then every edge has at least one end point in B(since we can not have edges between the vertices of A from definition).Sets such as B are vertex covers.If A is the largest Independent Set then B is the smallest vertex cover.Anyway, $|E| \\leq \\sum_{x \\in B} d(x) \\leq |B|*|A|\\leq (\\frac{|A|+|B|}{2})^2=\\frac{n^2}{4}$\\\\\n\\textbf{Proof 3:- Using P.H.P}\\\\\nLet us consider a graph with 2*n vertices and every such graph with more than $n^2+1$ edges must have a triangle.\\\\\nLet us prove by Induction on n,\\\\\n\\textbf{Base case (n=1)}\\\\\nIf 2 vertex graph has $1^2+1=2$ vertices has edges from A to B and B to A making it a triangle with a 0 edge as the 3rd side\\\\\n\\textbf{Induction step}\\\\\nAssume it is true for n=k and try to prove for n=k+1,\nnumber of vertices =2*(k+1)=2k+2 and the number of edges =$(k+1)^2+1=k^2+2k+2$\nNow let us consider an edge (x,y) $\\in$ E and call the remaining graph and the edges among themselves as H.\\\\\n\\textbf{Case1:-}\\\\\nIf H has more than $k^2+1$ edges then since we know that the statement is true for k by induction and now since H has a triangle G also has a triangle and hence the statement is true for n=k+1\n\\textbf{Case2:-}\\\\\nIf H has less than $k^2+1 $ edges therefore number of edges between the vertices x,y to H are \ntotal edges-(edges in H)-edge (x,y)$\\geq (k+1)^2+1-k^2-1=2k+1$.Now if we consider each of the vertex in H as a Hole and the number of pigeons in a given hole as number of edges it has with vertices x,y  now since there are 2n holes (2k vertices in H) and at least 2k+1 pigeons (each pigeon represents a distinct edge) there exists a hole with more than 1 pigeon which means there exists a vertex with more than one edge to x,y which makes it a common neighbour to both x and y  (making (x,z) $\\in$ E and (y,z) $\\in$ E)thus forming a triangle and hence the statement is true for k+1\n\\textbf{conclusion} any graph with 2*n vertices and more than $n^2+1$ edges must have a triangle for all values of n.\n\\end{proof}\n\n\n\n\\Lecture{Jayalal Sarma}{Oct 28, 2020}{24}{The Shifting technique}{Praharsh Allada}{$\\alpha$}{JS}\n\n\\section{Introduction}\nIn the last lecture we have seen 3 different techniques for mantel's theorem based on Double counting,AM-GM Inequality and Pigeon Hole principle.In this lecture we are going to look at a new technique to prove the existence of things in general.This technique is based on a principle called averaging principle which is like a cousin to pigeon hole principle.\\\\\n\n\\section{ proving existence using shifting technique}\n\\textbf{Averaging Principle}\nThe averaging principle states that every set of numbers contain at least one number which is as large as the average and one number which is as small as the average .\\\\\nTo Prove some Good object exist\\\\\n* Assign weights to objects such that Objects with large weights are good\\\\\n* Show that the average weight is large enough for it to be a good object \nand hence there exists at least one object with as much weight as average and hence proved that at least one good object exists\\\\\nShifting would be used in computing the sum and finding the average.\n\n\\section{Some examples using Shifting technique}\n\\textbf{Example 1:-}\\\\\nLet $n\\leq m \\leq 2n$ where m is the number of pigeons and n is number of hole.For any distribution where no hole is left empty there can be at most 2*(m-n) pigeons which are happy (Happy pigeons are not alone)\\\\\n\\textbf{Proof}\\\\\nlet us try to maximise the number of happy pigeon,consider any distribution of pigeons such that no hole is empty.if some hole contains grater than 2 pigeons then shift one of the pigeons from that hole to another hole with an unhappy pigeon.(thus increasing the number of happy pigeons by 1).Therefore the distribution which maximises the number of happy pigeons must necessarily have less than or equal to 2 pigeons in each hole.which  naturally gives the configuration which can be obtained bu putting one pigeon in each hole and then putting the remaining (m-n) pigeons in different holes thus making the total number of happy pigeons per filled hole as 2 and thus making the maximum number of happy pigeons as 2*(m-n)\\\\\n\\textbf{Example2:-}\\\\\n\\textbf{Graham and kleitman} Trail of a graph  is a walk in a graph without repeating edges.If the edges of a complete graph $k_n $ is labelled with distinct numbers ${1,2,3,....,{n\\choose 2}}$,with no repetition then there is a trail of length n-1 with an increasing sequence of edge labels.\\\\\nFor n=3, take a triangle ABC  let us try to label the edges to avoid a trail of length 2 (n-1=2). If AB=1, in both the cases of BC=2 and CA=2 we will clearly have a trail of increasing edge labels.\\\\\nFor n=4, take a square ABCD with diagonals AC and BD and label the edges from 1 to 6 by trying to avoid 3 length trails of increasing length let us start with BD=1 and AC=2 to keep it disconnected then AD=3 because where ever we put 3 tail length will increase by 1 DC  cant be 4 because ADCA will form a trail of length 3 and also AB cant be 4 because in that case BCAB will from a trail of length 3 hence let us put BD=4.But now we cant get put CD=5 since CBDC will form a trail of length 3 with increasing labels  and also we cant put AB=5 since ACBA will form a trail of length 3 with increasing labels hence a trail of length 3 with  increasing labels is unavoidable.\\\\\n\\textbf{Proof}\\\\\nWe assign a weight to each vertex,x $\\in$ v $->$ $W_x$ is it's weight.Where $W_x$ is the length of the longest increasing trail ending at x.Now, it suffices to argue $\\exists x \\in V,$such that $W_x\\geq n-1$. Now we have to find argue the average weight,if we prove $\\frac{1}{n}\\sum_{x \\in V} W_x \\geq n-1$\nthe by averaging principle we have show the existence.This is equivalent to proving $\\sum_{x \\in V} W_x \\geq n*(n-1)$.Shifting algorithm is problem dependent so in this case let us consider building the graph by adding edges one after the other.Let us add the edges in the order of increasing labels which keeps modifying the weights of vertices.\nInitially $W_x = 0 \\forall x$ we add edges in the increasing label order.\\\\\nAt some later instant let us say (x,y) is the edge being added now.So already some edges have been added so let us say there is a path ending at x and y the length of which is the weight of x and y respectively. SO now we update $W_x and W_y$.\\\\\n\\textbf{Case1:-} if\n$W_x=W_y$  and all the already existing edges have smaller labels since edges are added in that order. Increase both $W_x and W_y by 1$.$W'_x=W_x+1 and W'_y=W_y+1$\\\\\n\\textbf{Case2:-}\nif $W_x<W_y$ since now edge (x,y) is present the trail previously ending at y plus the edge (x,y) forms a new trail of length $W_y+1 >W_x$  ending at x and hence $W'_x=W_y+1 and W'_y=W_y$\\\\\n\\textbf{Case3:-}\nif $W_x>W_y$ since now edge (x,y) is present the trail previously ending at x plus the edge (x,y) forms a new trail of length  $W_x+1 >W_y$ ending at y and hence $W'_y=W_x+1$ and $W'_x=W_x$\\\\\n\\newpage\n\\textbf{Observation}\\\\\nThe value of $W_x+W_y$ increase by 2 in case one and in case 2 it increased by $W_y-W_x+1$ and in case 3 it increased by  $W_x-W_y+1$ which are grater than or equal to 2 therefore for each edge added the value of $\\sum_{x \\in V} W_x$ increased by at least 2. Therefore by the time we add ${n \\choose 2}$ edges the value of  $\\sum_{x \\in V} W_x \\geq 2*{n \\choose 2} \\geq n*(n-1) $.Hence,Graham and kleitman has been proved\n\n\n\n\n\n\n\n\n\\Lecture{Jayalal Sarma}{Oct 29, 2020}{25}{Fourth Proof of Mantels Theorem, Turans Theorem}{Venkat Nikhil Kotagiri}{$\\alpha$}{JS}\n\\section{Introduction}\nIn previous lectures, we have seen three different proofs of Mantel's theorem. In this lecture we will see a fourth proof using \\textit{shifting method}.\\\\\n\n\\section{Proof of Mantel's theorem using shifting method}\n\\begin{theorem}\nAny simple graph with $2n$ vertices and $\\ge n^2+1$ edges must have a triangle.\n\\end{theorem}\n\\begin{proof}\nLet $G$ be a simple graph on $2n$ vertices with no triangles.Let $m$ be number of edges in $G$.\\\\\nIt suffices to prove that $m\\le n^2$.\n\nShifting argument includes assignment of weights to objects, and shifting those weight to maximize/minimize an objective function. The weights assignment, constraints we chose are problem dependent.\n\nIn this proof, for each vertex $x \\in V$, we'll assign a weight \n$w_x \\in [0,1]$, such that $\\sum_{x\\in V}w_x=1$.\\\\\nLet $S=\\sum_{(x,y)\\in E}w_xw_y$ and $S_{max}$ be the max value of $S$.\\\\\nConsider the weight assignment in which every vertex is assigned equal weight, i.e.,\\\\ $w_x=\\frac{1}{2n}, \\forall x\\in V$\\\\\nValue of $S$ in this case is \n\\begin{align*}\n    S&=\\sum_{(x,y)\\in E}w_xw_y\\\\\n    S&=\\sum_{(x,y)\\in E}\\frac{1}{4n^2}\\\\\n    S&=\\frac{m}{2n^2} ~~~~~~~~~~~~~ (\\textit{each edge is counted twice})\n\\end{align*}\nTherefore, lower bound for $S_{max}$ is $\\frac{m}{2n^2}$,i.e.,\n\\begin{equation}\n    S_{max}\\ge \\frac{m}{2n^2}\n\\end{equation}\n\nWe'll now use shifting argument to prove that $S_{max}\\le \\frac{1}{2}$.\nConsider two vertices $x,y\\in V$ such that $(x,y)\\notin E$.\nLet $\\Gamma_x$ denote the sum of weights of neighbours of $x$, and $\\Gamma_y$ denote the sum of weights of neighbours of $y$. $\\Gamma_x=\\sum_{(x,z)\\in E}w_z, \\Gamma_y=\\sum_{(y,z)\\in E}w_z$.\nThe contribution of $w_x$ towards $S$ is $w_x\\sum_{(x,z)\\in E}w_z = w_x\\Gamma_x$. Similarly the contribution of $w_y$ towards $S$ is $w_y\\Gamma_y$.\n\nWithout loss of generality assume that $\\Gamma_x \\ge \\Gamma_y$, then by shifting a small weight $\\epsilon$ from $y$ to $x$, the change in $S$ is equal to \n\\begin{align*}\n    &=( (w_x+\\epsilon)\\Gamma_x + (w_y-\\epsilon)\\Gamma_y ) - ( w_x\\Gamma_x + w_y\\Gamma_y )\n    &= \\epsilon(\\Gamma_x-\\Gamma_y)\n    &\\ge 0~~~~~~~~~~~~~~~~(\\textit{since $\\epsilon \\ge 0$ and $\\Gamma_x\\ge \\Gamma_y$})\n\\end{align*}\nTherefore, by shifting $\\epsilon$ weight from $w_y$ to $w_x$, we have not decreased the value of $S$.\n\n\\begin{claim}\nMax S is achieved when the weight is concentrated on a edge.\n\\end{claim}\n\\begin{proof}\nUsing the above argument,we can keep shifting the weight from vertex $y$ to vertex $x$ until $w_y$ becomes zero,without decreasing $S$.\nRepeat this $\\forall u,v \\in V$ satisfying $(u,v)\\notin E, w_u>0, w_v>0$.\\\\\nNow, for two vertices $u,v$, if $w_u>0$ and $w_y>0$ then the edge $(u,v)$ must be present in $E$.\\\\\nTherefore the weight is concentrated on a clique.\n\\end{proof}\n\nUsing the above claim, and using the fact that $G$ is triangle free, we can conclude that the total weight is\nconcentrated over a single edge (say (x,y)).\n\\begin{align*}\n    S_{max} &\\le max\\{w_xw_y+w_yw_x|(x,y)\\in E, w_x+w_y=1 \\}\\\\\n    S_{max} &\\le \\frac{1}{4}+\\frac{1}{4}\\\\\n    S_{max} &\\le \\frac{1}{2} ~\\footnotemark\\\\\n\\end{align*}\n \nTherefore using equation (25.88),\n\\begin{align*}\n    \\frac{m}{2n^2} &\\le S_{max} \\le \\frac{1}{2} \\\\\n    \\frac{m}{2n^2} &\\le \\frac{1}{2}\\\\\n    m &\\le n^2\n\\end{align*}\n\n\\end{proof}\n\\footnotetext{$S_{max}=\\frac{1}{2}$ if the graph contains at least one edge, otherwise $S_{max}=0$.}\n\\section{Generalization of Mantel's Theorem: Tur\\'an’s theorem}\nIn this section we will see a generalization of Mantel's theorem, called Tur\\'an’s theorem.\n\\begin{theorem}\nIf a simple graph $G=(V,E)$ with $n$ vertices has no k-cliques, the $|E|\\le (1-\\frac{1}{k-1})\\frac{n^2}{2}$\n\\end{theorem}\n\\begin{proof}\nWe will restate the theorem as follows: If $G$ has no (k+1)-clique then $|E|\\le (1-\\frac{1}{k})\\frac{n^2}{2}$.\\\\\nWe will use induction on number of vertices $n$.\\\\\n\\textbf{Induction hypothesis:} Assume that the threorem is true $\\forall n^{'} < n$.\n\nConsider $G$ that has max number of edges but still does not have a (k+1)-clique. Then $G$ must have a k-clique.Let $A\\subseteq V, |A|=k$, be a k-clique in $G$. Let $B=V\\setminus A$.\nLet $E_A, E_B, E_{AB}$ denote the edges in $A$, edges in $B$, edges across $AB$ respectively. Clearly $E_A, E_B, E_{AB}$ is a partition of $E$. Therefore, we can write,\n\\begin{align*}\n    |E| = |E_A|+|E_B|+|E_{AB}|\n\\end{align*}\nSince $A$ is a k-clique, $E_A= \\binom{k}{2}$\\\\\n\\textbf{Estimating $|E_{AB}|$}: \n\nIf a vertex $u$ in $B$ is connected to all the vertices in $A$, then $A \\cup u$ is (k+1)-clique, which is a contradiction. Therefore every vertex in $B$ is connected to at-most $k-1$ vertices in $A$. Therefore, $|E_{AB}|\\le |B|(k-1)=(n-k)(k-1)$.\\\\\n\\textbf{Estimating $|E_{B}|$}: \n\nSince $B$ is simple graph which does not have (k+1)-cliques, we can use the induction hypothesis to estimate $E_B$.\n$E_B \\le (1-\\frac{1}{k})\\frac{(n-k)^2}{2}$\\\\\nTherefore,\n\\begin{align*}\n    |E| &\\le \\binom{k}{2} + (n-k)(k-1) + (1-\\frac{1}{k})\\frac{(n-k)^2}{2}\\\\\n    |E| &\\le (1-\\frac{1}{k})\\frac{n^2}{2}\n\\end{align*}\n\n\\end{proof}\n\n\\section{Complementary of Tur\\'an’s theorem}\nFor a simple graph $G$, let $\\alpha(G)$ be the maximum number of pairwise non-adjacent vertices of $G$. If $G$ has $n$ vertices and $\\frac{nk}{2}$ edges then,\n$\\alpha(G) \\le \\frac{n}{k+1}$.\\\\\\\\\nWe will prove this by using \\textit{probabilistic method}.\\\\\nBefore that, we will do a quick recap of probability.\n\n\\section{Recap of probability}\n\nThe set of all possible outcomes is called sample space($\\Omega$). Events are subsets of sample space.\\\\\nThe probability distribution assigns values in $\\Omega$ to $[0,1]$, such that \n$\\sum_{x\\in \\Omega}p(x)=1$.\\\\\n\n\\textbf{Random variable:} Random variable(X) is function that assigns real values to elements in the sample space.\n$$X:\\Omega\\rightarrow \\R$$\n\n\\textbf{Expected value of a Random variable:}The expected value of X, where X is a random variable, is the weighted average of the possible values that X can take, each value being weighted according to the probability of that event occurring.\n$$E[X]=\\sum_{w\\in \\Omega}p(w)X(w)$$\n\\textit{Linearity of Expectation:}\\\\\nIf $X_1,X_2$ are random variables such that $X_1,X_2: \\Omega \\rightarrow \\R$, then\n$$E[c_1X_1+c_2X_2]=c_1E[X_1]+c_2E[X_2]$$\nOne way to interpret averaging argument is that,\\\\\n$$\\exists w\\in \\Omega ~~\\textit{such that}~~ X(w)\\ge E[X]$$\n\n%\\Lecture{Jayalal Sarma}{Oct 29, 2020}{26}{Expectation method, Independence number}{Venkat Nikhil Kotagiri}{$\\alpha$}{JS}\n\\section{Expection Method, Independence Number}\nIn this lecture, we will use expectation method to prove the complementary of Tur\\'an’s theorem discussed in the previous lecture.\nBefore that, let's see an example on how to use expectation method.\\\\\n\\textbf{Statement:} $\\exists$ graph $G$ that has $n$ vertices and at least 3 connected components.\n\nLet each edge $(x,y)$ be present with probability $p$ and be absent with probability $1-p$. This is called random graph model.\n\nThe sample space $\\Omega=$ set of all graphs with $n$ vertices.\nConsider a random variable $X$, which maps an element $G$ in $\\Omega$ to number of components in $G$,i.e, $X(G)=$ number of components in G.\n\nTo prove that there exists a graph with at least 3 connected components, we need to prove that $E(X)\\ge 3$.\\\\\n\n\\section{Complementary of Tur\\'an’s theorem}\n\\begin{theorem}\nLet $G$ be a graph on $n$ vertices and let $d_i$ denote the degree of the $i^{th}$ vertex. Let $\\alpha(G)$ be the Independence number (cardinality of the largest independent set) of $G$. Then $\\alpha(G)\\ge \\sum_{i=1}^{n}\\frac{1}{d_i+1}$ \n\\end{theorem}\nOur earlier statement is slightly different from the above theorem.\\\\\n\\textbf{Statement:} If $G$ has $n$ vertices and $\\frac{nk}{2}$ edges then $\\alpha(G)\\ge \\frac{n}{k+1}$\n\\begin{claim}\nThis statement can be derived from the above theorem.\n\\end{claim}\n\\begin{proof}\nThe theorem states that \n\\begin{equation}\n    \\alpha(G)\\ge \\sum_{i=1}^{n}\\frac{1}{d_i+1}\n\\end{equation}\nLet $d_i=k~\\forall 1\\le i\\le n$, Then number of edges= $\\frac{1}{2}\\sum_{i=1}^{n}d_i=\\frac{nk}{2}$.\\\\\nUsing equation (26.89),\n\\begin{align*}\n    \\alpha(G) &\\ge \\sum_{i=1}^{n}\\frac{1}{d_i+1}\\\\\n    \\alpha(G) &\\ge \\sum_{i=1}^{n}\\frac{1}{k+1}\\\\\n    \\alpha(G) &\\ge \\frac{n}{k+1}\n\\end{align*}\n\\end{proof}\nWe will now prove the above theorem.\n\\begin{proof}\nBefore moving forward with the proof, let's recall the recipe of a proof using expectation method\n\\begin{itemize}\n  \\item Set up an experiment\n  \\item Relate the quantity that we want to expectation\n  \\item Bound expectation\n\\end{itemize}\n\\textbf{Setting up the experiment:}\n\nLet $V=\\{1,2,\\dots,n\\}$, let $\\pi:V\\rightarrow V$ be a permutation of $V$.\n\n\\textit{Experiment:} Chose a permutation uniformly at random.\\\\\\\\\n\\textbf{Relating the required quantity to expectation:}\n\nLet $A_i$ be the event that all neighbours $j$ of vertex $i$ are greater than $i$ in the ordering,i.e., $\\forall j:(i,j)\\in E, \\pi(j)>\\pi(i)$\\\\\nProbability of event $A_i$ happening is $Pr(A_i)=\\binom{n}{d_i+1}\\frac{d_i!(n-d_i-1)!}{n!}$.\\\\\\\\\n\\textit{Idea:} If for x,y, $A_x$ and $A_y$ holds then $(x,y)\\notin E$.\\\\\\\\\n\\textit{Aim:} To show that $\\exists u\\subseteq V$ such that $|u|\\ge\\sum_{i=1}^{n}\\frac{1}{d_i+1}$, and for no vertex inside $u$, the event holds.\\\\\\\\\nUsing the expectation method, let $U$ be the set of vertices $i$ such that $A_i$ holds.\\\\\nDefine random variable,\n$X_i =\n\\left\\{\n\t\\begin{array}{ll}\n\t\t1  & \\mbox{if } A_i ~~\\text{holds} \\\\\n\t\t0  & \\mbox{otherwise }\n\t\\end{array}\n\\right.$\n\n\\begin{align*}\n    E[|U|] &= E[X_1+X_2+\\dots,X_n]\\\\\n           &= \\sum_{i=1}^{n}E[X_i] \\\\\n           &= \\sum_{i=1}^{n}\\sum_{w\\in\\Omega}X_i(w)Pr(w) \\\\\n           &= \\sum_{i=1}^{n}0.pr[X_i==0]+1.pr[X_i==1] \\\\\n           &= \\sum_{i=1}^{n}Pr[A_i] \\\\\n           &= \\sum_{i=1}^{n}\\binom{n}{d_i+1}\\frac{d_i!(n-d_i-1)}{n!}\\\\\n           &= \\sum_{i=1}^{n}\\frac{n!}{(d_i+1)!(n-d_i-1)!}\\frac{d_i!(n-d_i-1)!}{n!}\\\\\n           &= \\sum_{i=1}^{n}\\frac{1}{d_i+1}\n\\end{align*}\nSo, there must exist $u\\subseteq V$ such that, $|u|\\ge \\sum_{i=1}^{n}\\frac{1}{d_i+1}$ and $\\forall x \\in u$, the event $A_x$ happens for a permutation. That implies $\\exists$ an independent set $|u|\\ge\\sum_{i=1}^{n}\\frac{1}{d_i+1}$. Therefore $$\\alpha(G)\\ge \\sum_{i=1}^{n}\\frac{1}{d_i+1}$$\n\\end{proof}\n", "meta": {"hexsha": "3adbdd613478aefdd1e0fee794d107a639359564", "size": 22057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week08.tex", "max_stars_repo_name": "Achyuth-Prakash/theory-toolkit", "max_stars_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week08.tex", "max_issues_repo_name": "Achyuth-Prakash/theory-toolkit", "max_issues_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-08T07:34:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-30T06:06:12.000Z", "max_forks_repo_path": "week08.tex", "max_forks_repo_name": "Achyuth-Prakash/theory-toolkit", "max_forks_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2020-09-25T01:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-28T11:22:06.000Z", "avg_line_length": 70.0222222222, "max_line_length": 724, "alphanum_fraction": 0.7005939158, "num_tokens": 7069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8723473647220786, "lm_q1q2_score": 0.6962961404929159}}
{"text": "\\subsection{Calibration of the Time Series Generation Process}\n\\label{params}\n\nIndependent of the concrete forecasting models, the time series generation\n    must be calibrated.\nWe concentrate our forecasts on the pickup side for two reasons.\nFirst, the restaurants come in a significantly lower number than the\n    customers resulting in more aggregation in the order counts and thus a\n    better pattern recognition.\nSecond, from an operational point of view, forecasts for the pickups are more\n    valuable because of the waiting times due to meal preparation.\nWe choose pixel sizes of $0.5~\\text{km}^2$, $1~\\text{km}^2$, $2~\\text{km}^2$,\n    and $4~\\text{km}^2$, and time steps covering 60, 90, and 120 minute windows\n    resulting in $H_{60}=12$, $H_{90}=9$, and $H_{120}=6$ time steps per day\n    with the platform operating between 11 a.m. and 11 p.m. and corresponding\n    frequencies $k_{60}=7*12=84$, $k_{90}=7*9=63$, and $k_{120}=7*6=42$ for the\n    vertical time series.\nSmaller pixels and shorter time steps yield no recognizable patterns, yet would\n    have been more beneficial for tactical routing.\n90 and 120 minute time steps are most likely not desirable for routing; however,\n    we keep them for comparison and note that a UDP may employ such forecasts\n    to activate more couriers at short notice if a (too) high demand is\n    forecasted in an hour from now.\nThis could, for example, be implemented by paying couriers a premium if they\n    show up for work at short notice.\nDiscrete lengths of 3, 4, 5, 6, 7, and 8 weeks are chosen as training\n    horizons.\nWe do so as the structure within the pixels (i.e., number and kind of\n    restaurants) is not stable for more than two months in a row in the\n    covered horizon.\nThat is confirmed by the empirical finding that forecasting accuracy\n    improves with longer training horizon but this effect starts to\n    level off after about six to seven weeks.\nSo, the demand patterns of more than two months ago do not resemble more\n    recent ones.\n\nIn total, 100,000s of distinct time series are forecast in the study.\n", "meta": {"hexsha": "329075ae9bd8725b2ba843f900ff04c594d4670b", "size": 2088, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/4_stu/3_params.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/4_stu/3_params.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/4_stu/3_params.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.9473684211, "max_line_length": 80, "alphanum_fraction": 0.7485632184, "num_tokens": 522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6962681116680425}}
{"text": "\\documentclass{article}\n\\author{Vaibhav Pujari}\n\\title{Categories}\n\\begin{document}\n\\section{Category of Vector Spaces}\n\\begin{itemize}\n\\item \\textbf{Objects}\n\n  Each vector space is an object\n\n\\item \\textbf{Morphisms}\n\n  Transformations (represented as matrices) between vector spaces\n\n\\item \\textbf{Identities}\n\n  The identity matrix for each vector space\n\n\\item \\textbf{Composition}\n\n  Matrix multiplication\n\n\\end{itemize}\n\n\\section{Monoid of Integers on Addition}\nThis is a singleton category - it contains only one object\n\\begin{itemize}\n\\item \\textbf{Objects}\n\n  $Integer$\n\n  Note the abstraction here. We are not specifying which integer. So, for\n  example both $20$ and $25$ are things which happen to be represented by the\n  same object $Integer$ in this category.\n\n\\item \\textbf{Morphisms}\n\n  Set of integers, $Z$\n\n  This is interesting. Here, the morphisms are just simple integers. So, for\n  example to go from an object, say $20$ to an object, say $25$ (both are same\n  objects because of our abstraction), we apply the morphism $5$. In case of a\n  monoid category, we always start and end at the same object since there is\n  only one object.\n\n\\item \\textbf{Identities}\n\n  The integer $0$ for our only object $Integer$\n\n\\item \\textbf{Composition}\n\n  Integer addition\n\n  That is, to compose say two morphisms $4$ and $6$, we add them to get a third\n  morphism $10$\n\n\\end{itemize}\n\n\n\\section{Rubik's cube: Another Monoid}\n\\begin{itemize}\n\\item \\textbf{Objects}\n\n  Rubik's cube\n\n  The abstraction here allows for any configuration of Rubik's cube to be\n  represented by the singleton object\n\n\\item \\textbf{Morphisms}\n\n  An action on Rubik's cube is a morphism. We can see that its possible to\n  combine two actions to produce a more complex action, and so on. In that way,\n  from any configuration of Rubik's cube, there always exists a single\n  (sufficiently complex) action, or morphism that solves the cube. Again a\n  solved cube is no different than an unsolved cube as far as its significance\n  in category is concerned\n\n\\item \\textbf{Identities}\n\n  A no-op action, which actually does not change the cube's configuration at\n  all. We can think of it as maybe an action of touching the cube and putting it\n  back. This is something I have performed many times :)\n\n\\item \\textbf{Composition}\n\n  Composition here is equivalent to sequencing the morphisms. I guess now its\n  getting clearer that not always can we have a composition that forgets its parts\n\n\\end{itemize}\n\n\\section{Factors}\n\\begin{itemize}\n\\item \\textbf{Objects}\n\n  A set of natural numbers, $N$\n\n\\item \\textbf{Morphisms}\n\n  There is a single morphism between any two natural numbers $a$ and $b$ if $b$\n  is a multiple of $a$\n\n\\item \\textbf{Identities}\n\n  Since every natural number is a multiple of itself (we get the same number\n  when we multiply it by 1), there is an identity for each object in this category\n\n\\item \\textbf{Composition}\n\n  Composition here will simply represent a transitive relationship. If $a$ is a\n  factor of $b$ and $b$ is a factor of $c$ then it implies that $a$ is a factor\n  of $c$, which means there exists a morphism between $a$ and $c$\n\n\\end{itemize}\n\\end{document}\n", "meta": {"hexsha": "8982475b841f136981236b443f055cac4eb60ccd", "size": 3177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02-category-examples.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": "02-category-examples.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": "02-category-examples.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": 27.6260869565, "max_line_length": 82, "alphanum_fraction": 0.7456720176, "num_tokens": 849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6962289925733351}}
{"text": "\\section{Characteristics}\r\n\\subsection{Well-Posed Cauchy Problems}\r\nSolving PDEs depends on the equation and the boundary/initial data.\r\nA Cauchy problem is a PDF together with auxiliary data specified on a surface in 3D or a curve in 2D (known as the Cauchy data).\r\n\\begin{definition}\r\n    A Cauchy problem is well-posed if:\\\\\r\n    1. A solution exists.\\\\\r\n    2. The solution is unique.\\\\\r\n    3. The solution depends continuously on the auxiliary data.\r\n\\end{definition}\r\n\\subsection{Method of Characteristics}\r\nSuppose we have a curve $C$ parameterised by $(x(s),y(s))$ in space and a tangent $v=(x^\\prime(s),y^\\prime(s))$ to the curve at some point $P$.\r\nFor a function $\\phi(x,y)$, we can define a directional derivative\r\n$$\\left.\\frac{\\mathrm d\\phi}{\\mathrm ds}\\right|_C=x^\\prime(s)\\frac{\\partial\\phi}{\\partial x}+y^\\prime(s)\\frac{\\partial\\phi}{\\partial y}=v\\cdot \\nabla\\phi|_C$$\r\nIf $v\\cdot\\nabla\\phi=0$, then $\\mathrm d\\phi/\\mathrm ds=0$ and $\\phi$ is constant along $C$.\r\nNow suppose we have a vector field $u=(\\alpha(x,y),\\beta(x,y))$ with its family of integral curves (i.e. curves which tangent to the field at any point) non-intersecting and filling $\\mathbb R^2$.\r\nNow find a curve $B$ by $(x(t),y(t))$ tranverse to $u$ such that its tangent vector $w=(x^\\prime(t),y^\\prime(t))$ is never parallel to $u$.\r\nLabel each integral curve $C$ of $u$ using $t$ at the intersection point with $B$ and then use $s$ to parameterise along the curve (i.e. take $s=0$ at $B$).\r\nOur integral curves then satisfy $x^\\prime(s)=\\alpha(x,y),y^\\prime(s)=\\beta(x,y)$, solving which gives a family of characteristic curves along whcih $t$ remains constant.\r\nIn some sense, we are creating a new coordinate $(s,t)$ at which the PDE is in a nice form.\r\n\\subsection{Characteristics of a First-Order PDE}\r\nConsider the first-order PDE\r\n$$\\alpha(x,y)\\frac{\\partial\\phi}{\\partial x}+\\beta(x,y)\\frac{\\partial\\phi}{\\partial y}=0$$\r\nwith specified Cauchy data on an initial curve $B$ parameterised by $(x(t),y(t))$.\r\nNote that we immediately have $\\alpha\\phi_x+\\beta\\phi_y=u\\cdot\\nabla\\phi=\\phi^\\prime(s)|_C$ where $C$ is an integral curve of $u=(\\alpha,\\beta)$.\r\nThese are called characteristic curves of the PDE.\r\nThe PDE then gives $\\phi^\\prime(s)=\\alpha\\phi_x+\\beta\\phi_y=0$, therefore $\\phi$ is constant along the curve $C$.\r\nTherefore the Cauchy data $f(t)$ defined on (sufficiently nice) $B$ at $s=0$ will be propagated constantly along $C$ to give the solution $\\phi(s,t)=\\phi(x(s,t),y(s,t))=f(t)$.\r\nTo get $\\phi$, simply invert $s=s(x,y),t=t(x,y)$ (provided it has nonzero Jacobian) and we have $\\phi(x,y)=f(t(x,y))$.\r\n\\begin{example}\r\n    1. Consider the simple ODE $\\partial\\phi/\\partial x=0$ with $\\phi(0,y)=h(y)$ given on the $y$-axis.\r\n    The family of curves we want are the integral curves $x^\\prime(s)=\\alpha=1,y^\\prime(s)=\\beta=0$.\r\n    The $y$ axis is parameterised as $(x(t),y(t))=(0,t)$.\r\n    Therefore at $s=0$ we need $(x,y)=(0,t)$, hence the family of curves $C$ are characterised as $x=s,y=t$ (simple indeed).\r\n    Therefore $\\phi(s,t)=h(t)$, and by inversion $\\phi(x,y)=h(t)$.\\\\\r\n    2. Let's do some example that are a bit less simple.\r\n    We turn our attention to $e^x\\phi_x+\\phi_y=0$ with $\\phi(x,0)=\\cosh x$.\r\n    The characteristic equation is $x^\\prime(s)=e^x,y^\\prime(s)=1$.\r\n    The initial curve is parameterised as $x(t)=t,y(t)=0$ which shall apply when $s=0$.\r\n    Solving these gives $e^{-x}=e^{-t}-s,y=s$.\r\n    $\\phi^\\prime(s)=0$ gives $\\phi(s,t)=\\cosh t$.\r\n    The inversion gives $s=y,t=-\\log(y+e^{-x})$, so $\\phi(x,y)=\\cosh(-\\log(y+e^{-x}))$.\r\n\\end{example}\r\nSo the homogeneous case is easy enough.\r\nHow about inhomogeneous ones?\r\nOf course we can do the good old \"guess and superposition\" manoeuvre, but we can do better.\\\\\r\nWe want to solve $\\alpha(x,y)\\phi_x+\\beta(x,y)\\phi_y=\\gamma(x,y)$ with specified Cauchy data $\\phi(x(t),y(t))=f(t)$ on a curve $B$.\r\nThe characteristic curves $C$ satisfy the same system as usual, but there is a twist:\r\n$\\phi^\\prime(s)|_C=u\\cdot\\nabla\\phi=\\gamma(x,y)$ instead of $0$.\r\nSo $f(t)$ is no longer propagating constantly and we must actually solve the ODE.\r\n\\begin{example}\r\n    Consider $\\phi_x+2\\phi_y=ye^x$ with $\\phi=\\sin x$ along $y=x$.\r\n    The characteristic equations are $x^\\prime(s)=1,y^\\prime(s)=2$.\r\n    On $y=x$, we parameterise $(x(t),y(t))=(t,t)$, which then gives $x=s+t,y=2s+t$.\r\n    Now we turn to $\\phi^\\prime(s)=\\gamma=ye^x=(2s+t)e^{s+t}$ subject to $\\phi=\\sin t$ at $s=0$.\r\n    By simple integration we obtain $\\phi=(2s-2+t)e^{s+t}+C$ where $C$ is constant in $s$.\r\n    The initial conditions then gives $\\phi(s,t)=(2s-2+t)e^{s+t}+\\sin t+(2-t)e^t$.\r\n    With inversion $s=y-x,t=2x-y$ gives\r\n    $$\\phi(x,y)=(y-2)e^x+(y-2x+2)e^{2x-y}+\\sin(2x-y)$$\r\n\\end{example}\r\n\\subsection{Classification of Second-Order Linear PDEs}\r\nIn $\\mathbb R^2$, the general homogeneous second order linear PDE has the form\r\n$$0=\\mathcal L\\phi=a\\frac{\\partial^2\\phi}{\\partial x^2}+2b\\frac{\\partial^2\\phi}{\\partial x\\partial y}+c\\frac{\\partial^2\\phi}{\\partial y^2}+d\\frac{\\partial\\phi}{\\partial x}+e\\frac{\\partial\\phi}{\\partial y}+f\\phi$$\r\nThe principal part of this ODE is defined as\r\n$$\\sigma_p(x,y,k_x,k_y)=k^\\top Ak=\\begin{pmatrix}\r\n    k_x&k_y\r\n\\end{pmatrix}\\begin{pmatrix}\r\n    a(x,y)&b(x,y)\\\\\r\n    b(x,y)&c(x,y)\r\n\\end{pmatrix}\\begin{pmatrix}\r\n    k_x\\\\\r\n    k_y\r\n\\end{pmatrix}$$\r\nThe PDEs are classified by the properties of the eigenvalues of $A$.\r\nIf $b^2-ac<0$, then the eigenvalues have the same sign, so the equation is elliptic.\r\nIf $b^2-ac>0$, then the eignevalues have different signs and the equation is called hyperbolic.\r\nIf $b^2-ac=0$, then some eigenvalue is $0$, and the equation is called parabolic.\r\n\\begin{example}\r\n    The wave equation is hyperbolic.\r\n    The heat equation is parabolic.\r\n    The Laplace equation is elliptic.\r\n\\end{example}\r\nA curve defined by $f(x,y)$ being constant is a characteristic curve for this second order PDE if $(\\nabla f)A(\\nabla f)^\\top =0$.\r\nIf the curve can be written as $y=y(x)$, then $f_x/f_y=\\mathrm dy/\\mathrm dx$, so a substitution gives $a(y^\\prime)^2-2by^\\prime+c=0$ and hence $y^\\prime(x)=(b\\pm\\sqrt{b^2-ac})/a$.\r\nTherefore this classification makes sense as the sign of $b^2-ac$ determines the behaviour of characteristics.\r\nIf the equation is hyperbolic, then $b^2-ac>0$ which gives two distinct solutions;\r\nif it is parabolic, then we get exactly one solution;\r\nbut if it is elliptic, then there is simply no (real) characteristic curves in this form.\\\\\r\nIf we can transform these to characteristic coordinates $(u,v)$, the PDE will take the canonical form\r\n$$0=\\frac{\\partial^2\\phi}{\\partial u\\partial v}+\\text{lower order terms}$$\r\n\\begin{example}\r\n    Consider $-y\\phi_{xx}+\\phi_{yy}=0$ which is hyperbolic for $y>0$, elliptic for $y<0$ and parabolic for $y=0$.\r\n    We are interested in the hyperbolic $y>0$ case.\r\n    Then $\\mathrm dy/\\mathrm dx=\\pm y^{-1/2}$ by quadratic formula.\r\n    Integrating gives $(2/3)y^{3/2}\\pm x=C_\\pm$, $C_\\pm$ constants.\r\n    The characteristic coordinates are then set as $u=(2/3)y^{3/2}+ x,v=(2/3)y^{3/2}- x$.\r\n    After a lot of calculations using chain rule, the equation can be transformed into\r\n    $$\\phi_{uv}+\\frac{1}{6(u+v)}(\\phi_u+\\phi_v)=0$$\r\n\\end{example}\r\n\\subsection{General Solution for Wave Equation}\r\nGoing back to our old friend\r\n$$\\frac{1}{c^2}\\frac{\\partial^2\\phi}{\\partial t^2}-\\frac{\\partial^2\\phi}{\\partial x^2}=0$$\r\nwith initial conditions $\\phi(x,0)=f(x),\\phi_t(x,0)=g(x)$.\r\nThen the characteristic equation is $\\mathrm dx/\\mathrm dt=\\pm C$, $C$ constant.\r\nTherefore we can do the change of coordinate $u=x-ct,v=x+ct$ which just gives\r\n$$\\frac{\\partial^2\\phi}{\\partial u\\partial v}=0\\implies \\phi=G(u)+H(v)=G(x-ct)+H(x+ct)$$\r\nFor differentiable $G,H$.\r\nThe initial conditions then give the eqautions\r\n$$\\begin{cases}\r\n    f(x)=\\phi(x,0)=G(x)+H(x)\\\\\r\n    g(x)=\\phi_t(x,0)=-cG^\\prime(x)+cH^\\prime(x)\r\n\\end{cases}$$\r\nCombining them gives\r\n$$H(x)=\\frac{1}{2}(f(x)-f(0))+\\frac{1}{2c}\\int_0^xg(y)\\,\\mathrm dy,G(x)=\\frac{1}{2}(f(x)+f(0))-\\frac{1}{2c}\\int_0^xg(y)\\,\\mathrm dy$$\r\nSo\r\n$$\\phi(x,t)=\\frac{f(x-ct)+f(x+ct)}{2}+\\frac{1}{2c}\\int_{x-ct}^{x+ct}g(y)\\,\\mathrm dy$$\r\nThis means that the wave propagates at $v=c$ and $\\phi$ is fully determined by the values of $f,g$ (which is the initial data at $t=0$) in the interval $[x-ct,x+ct]$.\r\nThis can be interpreted as the light cone, which gives the causal structure of relativity.\r\nThat is, data at $x=x_0$ only influence $[x_0-ct,x_0+ct]$ after time $t$.", "meta": {"hexsha": "d467498e4fa3c85b1f03c3da219dcb2093a5902b", "size": 8487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9/char.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": "9/char.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": "9/char.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.3193277311, "max_line_length": 213, "alphanum_fraction": 0.6713797573, "num_tokens": 2806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.696228983860171}}
{"text": "\\chapter{ElegantBook Writing Sample}\n\n\\begin{introduction}\n\\item Theorem Class Envrionments\n\\item Cross Reference\n\\item Math Environments\n\\item List Environments\n\\item Logo and Base \n\\item $a^2+b^2=c^2$\n\\end{introduction}\n\n\n\\lipsum[1]\n% source: https://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/Theorems.html\n\n\\section{Writing Sample}\n\nWe will define the integral of a measurable function in three steps. First, we define the integral of a nonnegative simple function. Let $E$ be the measurable set in $\\mathcal{R}^N$.\n\n\\begin{definition}{Left Coset}{}\nLet $H$ be a subgroup of a group~$G$.  A \\emph{left coset} of $H$ in $G$ is a subset of $G$ that is of the form $xH$, where $x \\in G$ and $xH = \\{ xh : h \\in H \\}$. Similarly a \\emph{right coset} of $H$ in $G$ is a subset of $G$ that is of the form $Hx$, where $Hx = \\{ hx : h \\in H \\}$ $\\hbar$\n\\end{definition}\n\n\\begin{note}\nNote that a subgroup~$H$ of a group $G$ is itself a left coset of $H$ in $G$.\n\\end{note}\n\n\\lipsum[2]\n\n\\begin{theorem}{Lagrange's Theorem}{}\nLet $G$ be a finite group, and let $H$ be a subgroup of $G$.  Then the order of $H$ divides the order of $G$.\n\\end{theorem}\n\n\\lipsum[3]\n\n   \n\\begin{proposition}{Size of Left Coset}{}\nLet $H$ be a finite subgroup of a group $G$.  Then each left coset of $H$ in $G$ has the same number of elements as $H$.\n\\end{proposition}\n\n\\begin{proof}\nLet $z$ be some element of $xH \\cap yH$.  Then $z = xa$ for some $a \\in H$, and $z = yb$ for some $b \\in H$. If $h$ is any element of $H$ then $ah \\in H$ and $a^{-1}h \\in H$, since $H$ is a subgroup of $G$. But $zh = x(ah)$ and $xh = z(a^{-1}h)$ for all $h \\in H$. Therefore $zH \\subset xH$ and $xH \\subset zH$, and thus $xH = zH$.  Similarly $yH = zH$, and thus $xH = yH$, as required. \n\\end{proof}\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{scatter.pdf}\n  \\caption{Matplotlib: Scatter Plot Example\\label{fig:scatter}}\n\\end{figure}\n\nRegression analysis is a powerful statistical method that allows you to examine the relationship between two or more variables of interest. While there are many types of regression analysis, at their core they all examine the influence of one or more independent variables on a dependent variable. The process of performing a regression allows you to confidently determine which factors matter most, which factors can be ignored, and how these factors influence each other.\n\nLet's continue using our application training example. In this case, we'd want to measure the historical levels of satisfaction with the events from the past three years or so, as well as any information possible in regards to the independent variables. \n\n\n\\begin{table}[htbp]\n  \\small\n  \\centering\n  \\caption{Auto MPG and Price \\label{tab:reg}}\n    \\begin{tabular}{lcc}\n    \\toprule\n                    &       (1)         &        (2)      \\\\\n    \\midrule\n    mpg             &    -238.90***     &      -49.51     \\\\\n                    &     (53.08)       &      (86.16)    \\\\\n    weight          &                   &      1.75***    \\\\\n                    &                   &      (0.641)    \\\\\n    constant        &     11,253***     &       1,946     \\\\\n                    &     (1,171)       &      (3,597)   \\\\\n    obs             &        74         &         74     \\\\\n    $R^2$           &      0.220        &       0.293    \\\\\n    \\bottomrule\n    \\multicolumn{3}{l}{\\scriptsize Standard errors in parentheses} \\\\\n    \\multicolumn{3}{l}{\\scriptsize *** p<0.01, ** p<0.05, * p<0.1} \\\\\n    \\end{tabular}%\n\\end{table}%\n\n\\lipsum[1-2]\n\n\\begin{itemize}\n  \\item Routing and resource discovery;\n       \\begin{itemize} \n             \\item Language Models\n            \\item Vector Space Models\n         \\end{itemize}\n  \\item Resilient and scalable computer networks;\n  \\item Distributed storage and search.\n\\end{itemize}\n\n\\begin{problemset}\n  \\item Solve the equation $5(- 3x - 2) - (x - 3) = -4(4x + 5) + 13$.\n  \\item Find the distance between the points $(-4 , -5)$ and $(-1 , -1)$.\n  \\item Find the slope of the line $5x - 5y = 7$.\n\\end{problemset}\n\n\n", "meta": {"hexsha": "acdf2fe3fa595d4accd406af50ab52ca30cbb591", "size": 4053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "body/en-ch4.tex", "max_stars_repo_name": "yoczhang/latexBook-template", "max_stars_repo_head_hexsha": "2893eb15c8f3faaf1ea0a0ddfef21e9b94fd5d41", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-29T03:10:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-29T03:10:52.000Z", "max_issues_repo_path": "body/en-ch4.tex", "max_issues_repo_name": "yoczhang/latexBook-template", "max_issues_repo_head_hexsha": "2893eb15c8f3faaf1ea0a0ddfef21e9b94fd5d41", "max_issues_repo_licenses": ["LPPL-1.3c"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "body/en-ch4.tex", "max_forks_repo_name": "yoczhang/latexBook-template", "max_forks_repo_head_hexsha": "2893eb15c8f3faaf1ea0a0ddfef21e9b94fd5d41", "max_forks_repo_licenses": ["LPPL-1.3c"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.7835051546, "max_line_length": 473, "alphanum_fraction": 0.6141130027, "num_tokens": 1253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.6962289667026197}}
{"text": "\\section{Model Selection}\n\\subsection{Bias-Variance Tradeoff \\& Sweet Spot}\n\\paragraph{Bias} error from \\textbf{erroneous assumptions} in learning algorithm. Error can range from inaccurate assumption to simplification of model.\n\\paragraph{Variance} error from \\textbf{sensitivity to small fluctuations} in training set.\n\\begin{itemize}\n\t\\item Idea: \n\t\\begin{itemize}\n\t\t\\item models \\textbf{too simple} will have \\textbf{high bias} on training data, \\textbf{low variance} on test data.  $\\rightarrow$ \\textbf{Underfitting}\n\t\t\\item models \\textbf{too complex} will have \\textbf{low bias} on training data, \\textbf{high variance} on test data. $\\rightarrow$ \\textbf{Overfitting}\n\t\\end{itemize}\n\t\n\t$\\rightarrow$ find the sweet spot $\\rightarrow$ \\textbf{low bias \\& low variance}\n\t\n\t\\item \\textbf{Goal} of Model Selection: \\textbf{optimize} bias-variance tradeoff\n\t\\item Criterion Metrics: \\textbf{minimize} f(fitting error from given data) + g(model complexity)\n\t\\begin{itemize}\n\t\t\\item \\textbf{Akaike Information Criterion(AIC)}: $AIC = -2\\ln(L) + 2\\cdot \\#parameters$\n\t\t\\item \\textbf{Minimum Description Length} given the same quality: Kolmogorov Complexity\n\t\\end{itemize}\n\\end{itemize}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{bias-variance.png}\n\\end{figure}\n\n\\section{Evaluation}\n\\subsection{Evaluation Methods of Model}\n\\begin{itemize}\n\t\\item Goal of evaluation: how good is the model on \\textbf{new data}?\n\t\\item Evaluation methods: how to get the \\textbf{test data}?\n\t\\begin{itemize}\n\t\t\\item on training set\n\t\t\\item Holdout set (stratified / repeated)\n\t\t\\item k-Fold Cross-Validation (w/o stratified)\n\t\t\\item Leave-One-Out Validation \n\t\t\\item Bootstrap\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Evaluation Directly on Training Set: Not Preferred}\n\\begin{itemize}\n\t\\item might cause \\textbf{overfitting}.\n\t\\item evaluation too optimistic, the actual error rate is higher.\n\\end{itemize}\n$\\rightarrow$ not preferred!!\n\n\\subsubsection{Evaluation using Holdout Set}\n\\begin{itemize}\n\t\\item reserve data from whole data. rule of thumb: $\\frac{1}{3}$ of whole.\n\t\\item holdout set method:\n\t\\begin{itemize}\n\t\t\\item \\textbf{stratified Holdout}: considers \\textbf{distribution of classes}. split the training/test data \\textbf{proportionally} according to the ratio of classification results. \n\t\t\\item \\textbf{repeated Holdout}: \\textbf{randomly} select holdout set \\textbf{repeatedly} and estimate through \\textbf{average error}.\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Evaluation using (stratified) k-fold Cross Validation}\nProcess:\n\\begin{itemize}\n\t\\item \\textbf{partition} the data (\\textbf{proportionally, if stratified}) into $k$ complementary subsets. \n\t\\item \\textbf{train} on $(k-1)$ subsets, \\textbf{test} on 1 subset.\n\t\\item repeat until each subset is tested once.\n\t\\item calculate the \\textbf{average error rate}.\n\\end{itemize}\n\n\\subsubsection{Evaluation using Leave-One-Out Validation}\n\\begin{itemize}\n\t\\item Use-case: when data is \\textbf{scarce}.\n\t\\item a \\textbf{n-fold cross validation}: test on 1 instance, train on $(n-1)$ instances.\n\t\\item Advantages:\n\t\\begin{itemize}\n\t\t\\item maximum use of data for training, especially when data is scarce.\n\t\t\\item deterministic\n\t\\end{itemize}\n\tDisadvantages:\n\t\\begin{itemize}\n\t\t\\item high computational cost\n\t\t\\item non-stratified samples\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Evaluation using Boostrap}\nProcess:\n\\begin{itemize}\n\t\\item draw $n$ \\textbf{random samples with replacement} as test data.\n\t\\item test and calculate the error rate.\n\t\\item repeat the random sampling for many times.\n\t\\item calculate the variance/confidence interval of the sample.\n\\end{itemize}\nComparison to k-fold cross validation: sampling \\textbf{without} replacement. \n\n\\subsubsection{Significance between Models: Paired T-Test}\n\\begin{itemize}\n\t\n\t\n\t\\item Goal: compare the \\textbf{error rate} of 2 models \n\t\n\t$\\rightarrow$ see which model fits better to the \\textbf{training data}\n\t\n\t$\\rightarrow$ better model will predict on \\textbf{test data}.\n\t\n\t\\item Idea: results of a validation may be considered as \\textbf{random chance}.\n\t\n\t$\\rightarrow$ only \\textbf{significant difference} counts! $\\rightarrow$ significance test\n\t\n\\end{itemize}\n\\paragraph{Paired T-test: }\n\\subparagraph{Significantly Different? two-sided Test}\n\\begin{itemize}\n\t\\item $H_0$: $\\mu_d = 0$\n\t\n\t$H_1$: $\\mu_d \\neq 0$ \n\t\\item test statistic: \n\t$$t = \\frac{\\bar{d} - \\mu_d}{s_d / \\sqrt{n}}$$\n\t\\item critical value: $t_{1-\\frac{\\alpha}{2}, n-1}$\n\t\\item Reject $H_0$: $|t| \\geq t_{1-\\frac{\\alpha}{2}, n-1}$\n\\end{itemize}\n\\subparagraph{Significantly Better? one-sided Test}\n\\begin{itemize}\n\t\\item $H_0$: $\\mu_{C1 - C0} \\leq 0$, classifier 1 is not significantly better than baseline classifier.\n\t\n\t$H_1$: $\\mu_{C1 - C0} > 0$, classifier 1 is significantly better than baseline classifier\n\t\\item critical value: $t_{1-\\alpha, n-1}$\n\t\\item Reject $H_0$: $t \\geq t_{1-\\alpha, n-1}$\n\\end{itemize}\n\\subsection{Quality Metrics of Model on Test Data}\n\n\\subsubsection{Confusion Matrix}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.65\\textwidth]{confusion.png}\n\\end{figure}\n\\textbf{Overall Diagonally}:\n\\subparagraph{Accuracy} $$\\text{Accuracy} = \\frac{TP + TN}{N}$$\n\\subparagraph{Error Rate} $$\\text{Error Rate} = 1 - \\text{Accuracy} = \\frac{FP + FN}{N}$$\n\n\\textbf{Specific Horizontally}:\n\\subparagraph{True Positive Rate / Recall / Hit Rate} $$\\text{True Positive Rate/Recall} = \\frac{TP}{TP + FN}$$\n\\subparagraph{True Negative Rate / Specificity} $$\\text{True Negative Rate/Specificity} = \\frac{TN}{TN + FP}$$\n\\subparagraph{False Positive Rate / False Alarm Rate} $$\\text{False Positive Rate/False Alarm Rate} = 1- \\text{Specificity} = \\frac{FP}{TN + FP}$$\n\n\\textbf{Specific Vertically}:\n\\subparagraph{Precision} $$\\text{Precision} = \\frac{TP}{TP + FP}$$\n\n\n\\textbf{Cost-Sensitive Learning}:\n\\begin{itemize}\n\t\\item Goal of general test data evaluation: minimize \\textbf{overall error rate}\n\t\n\t$\\rightarrow$ same weight on each prediction\n\t\n\t\\item Idea in cost-sensitive learning: \n\t\\begin{itemize}\n\t\t\\item unbalanced data\n\t\t\\item prediction has different cost\n\t\\end{itemize}\n\t\\item Goal in cost-sensitive learning: minimize \\textbf{cost}\n\t\\item Solution:\n\t\\begin{itemize}\n\t\t\\item \\textbf{weighting} of instance according to cost\n\t\t\\item \\textbf{resampling} of instance according to cost\n\t\t\\item \\textbf{predict probabilities} instead of predicting classes. minimize the cost by selecting a better \\textbf{cutoff-value} (default: 0.5)\n\t\\end{itemize}\n\t$\\rightarrow$ the model \\textbf{biased towards cost-sensitive} prediction. \n\t\n\t$\\rightarrow$ eg: in churn prediction, better predict more churns (more false positives as false negatives)\n\\end{itemize}\n\n\n\\subsubsection{Gain Curve}\n\\begin{itemize}\n\t\\item Idea: visualize results of \\textbf{different cutoffs}.\n\t\n\t$\\rightarrow$ the \\textbf{gain most of the targets} by just taking \\textbf{a percentage of the whole dataset}, no need to go through the whole.\n\t\n\t$\\rightarrow$ evaluate models in \\textbf{cost-sensitive learning}\n\t\\item Process:\n\t\\begin{itemize}\n\t\t\\item predict probabilities instead of classes.\n\t\t\\item \\textbf{sort} instances by probability \\textbf{in descending order}\t\n\t\\end{itemize}\n\t\\item x-axis: percentage of the dataset \n\t\\item y-axis: percentage of \\textbf{actual true} instances in the whole given dataset\n\\end{itemize}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.55\\textwidth]{gain.png}\n\\end{figure}\n\\subsubsection{Lift Curve}\n\\begin{itemize}\n\t\\item Idea: visualize \\textbf{how much better} sorting and taking the q\\% of data set is than random sampling q\\%.\n\t\n\t\\item x-Axis: percentage of the dataset $q$\n\t\\item y-Axis: Ratio of sorting and taking the q\\% to random sampling \n\t\t\n\t$\\rightarrow$ min(Lift) = 1\n\t\t\n\t$$\\text{Lift}(q) = \\frac{\\text{Gain}(q)}{q}$$\n\n\\end{itemize}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.55\\textwidth]{lift.png}\n\\end{figure}\n\\subsubsection{ROC Curve}\n\\begin{itemize}\n\t\\item Idea: go through all sizes of samples\n\t\\item x-Axis: false positive rate\n\t\\item y-Axis: true positive rate\n\t\\item Process: \n\t\\begin{itemize}\n\t\t\\item \\textbf{sort} the predicted probability (the given table might be unsorted).\n\t\t\\item increase the sample size \\textbf{step-wise} as a cutoff for positive prediction, \n\t\t\\begin{itemize}\n\t\t\t\\item with one more true positive (+), \\textbf{go up} one step.\n\t\t\t\\item with one more false positive(-), \\textbf{go right} one step\n\t\t\\end{itemize}\n\t\t \n\t\\end{itemize}\n\t\\item Choosing cut-off value: choose the \\textbf{percentage that bends to the left the most}.\n\t\\item Comparing 2 models: choose the model that \\textbf{bends to the left} the most.\n\t\\item Mark the cut-off value: find the corresponding \\textbf{instance predicted at cut-off value}.\n\\end{itemize}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.55\\textwidth]{roc.png}\n\\end{figure} \n", "meta": {"hexsha": "604b03edb3a0abea4abe0c1eaf97b77fc6fed124", "size": 8843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/dataevaluate.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/dataevaluate.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/dataevaluate.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": 38.7850877193, "max_line_length": 184, "alphanum_fraction": 0.7401334389, "num_tokens": 2658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.6961820060371482}}
{"text": "\\chapter{Syntax of Propositional Logic}\n\n\\section{Propositional Languages}\n\n\t\\begin{enumerate}[\\thesection.1]\n\t\n\t\t\\item As we said in the introduction, formal languages are the result of abstracting away from the logically irrelevant aspects of ordinary language to arrive at an abstract, mathematical language with well-defined symbols and grammatical rules.  We also mentioned in the introduction that propositional logic is the logic of `not,' `and,' `or,' `if \\dots, then \\dots,' and `iff'---the so-called \\emph{sentential operators}. Correspondingly, to define formal languages for propositional logic, we abstract away from everything but the structure required for the sentential operators. \n\t\t\n\t\t\\item What is this structure? ---First, note that the sentential operators connect sentences to form new sentences. The operator `not,' for example, takes a sentence and makes a new one out of it, it takes us from ``two plus two equals four'' to ``two plus two doesn't equal four.'' The operator `and,' instead takes two sentences to form a new one; from ``two plus two equals four'' and ``four is even,'' we get to ``two plus two equals four and four is even.'' Next, note that for validity in propositional logic, it actually doesn't matter what the sentences are that an operator connects. Take, for example, inference (1) from the introduction:\n\t\t\\begin{enumerate}[(1)]\n\t\t\n\t\t\t\\item The letter is either in the left drawer or in the right drawer, and it's not in the left drawer. So, the letter is in the right drawer.\n\t\t\n\t\t\\end{enumerate}\nThis inference remains valid if we replace \t``the letter is in the left drawer'' and ``the letter is in the right drawer'' with any statements we please. The following inference, for example, is equally valid:\t\n\t\t\\begin{enumerate}[(1')]\n\t\t\n\t\t\t\\item The cat is either on the mat or the dog dances tango, and the cat isn't on the mat. So, the dog dances tango.\n\t\t\n\t\t\\end{enumerate}\nTo see this, just go through the reasoning we used to see that (1) is valid and replace ``the letter is in the left drawer'' everywhere with ``the cat is on the mat'' and ``the letter is in the right drawer'' with ``the dog dances tango.'' \n\n\\item So, we can abstract away from the concrete sentences in an inference, and replace them with \\emph{sentence letters}, typically written $p,q,r,\\mathellipsis.$ The sentential operators, then, are represented by the following formal symbols: \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{c | c | c}\n\t\t\tSymbol & Name & Reading\\\\ \\hline\n\t\t\t\n\t\t\t$\\neg$ & Negation & not\\\\\n\t\t\t$\\land$ & Conjunction & and\\\\\n\t\t\t$\\lor$ & Disjunction & or\\\\\n\t\t\t$\\to$ & Conditional & if \\dots, then \\dots\\\\\n\t\t\t$\\leftrightarrow$ & Biconditional & iff\n\t\t\t\\end{tabular}\n\t\t\\end{center}\nSo, the sentence ``the letter is either in the left drawer or in the right drawer'' becomes the formula $(p\\lor q)$ and the sentence ``the letter is not in the left drawer'' becomes $\\neg p$. If we use the symbol $\\therefore$ to stand for the natural language expression ``so,'' we can therefore fully formally represent the inference (1) as:\n \t\\[(p\\lor q),\\neg p\\therefore q\\]\nThe abstraction process just described is the translation from natural language into the  language of propositional logic, which is known as \\emph{formalization}. We will now first define the notion of a propositional language, a formal language of propositional logic, and then discuss how to formalize natural language claims in a propositional language.\n\n\t\t\\item To define formal language (in propositional logic and beyond) we need to do two things: we need to specify a \\emph{vocabulary}---the symbols we can use to form expression of the language---and we need to define a \\emph{grammar}, which tells us which expressions of the symbols from the vocabulary are \\emph{well-formed}.\n\t\t\n\t\t\\item For a propositional language, typically denoted $\\mathcal{L}$, the vocabulary consists of the following:\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item a (non-empty) set $\\mathcal{P}$ of sentence letters,\\footnote{In the following, we'll always assume that $\\mathcal{P}$ only contains lower case letters $p,q,r, \\mathellipsis$ and, in particular that $\\neg,\\land,\\lor,\\to,\\leftrightarrow,(,)\\notin\\mathcal{P}$.}\n\t\t\t\n\t\t\t\\item the \\emph{sentential operators} $\\neg,\\land,\\lor,\\to,$ and $\\leftrightarrow$, and \n\t\t\t\n\t\t\t\\item the \\emph{parentheses} $($ and $)$.\n\t\t\n\t\t\\end{enumerate}\n\t\tEvery expression in $\\mathcal{L}$ is constructed from the symbols in its vocabulary.\n\t\t\n\t\t\\item The grammar of $\\mathcal{L}$, then, is given by an inductive definition: we inductively define the set of well-formed formulas, typically denoted (somewhat ambiguously) simply $\\mathcal{L}$. Remember that in order to recursively define a set, we need to give a set of initial elements and a set of constructions to form new elements from old ones. Well, in the case of a propositional language, the initial elements are simply the sentence letters and the constructions are given by the sentential operators. So, the set of well-formed formulas of $\\mathcal{L}$ is defined as the smallest set $X$, such that:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item $\\mathcal{P}\\subseteq X$\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\n\t\t\t\t\t\\item if $\\phi\\in X$, then $\\neg \\phi\\in X$\n\t\t\t\t\t\n\t\t\t\t\t\\item if $\\phi,\\psi\\in X$, then $(\\phi\\land\\psi), (\\phi\\lor\\psi),(\\phi\\to\\psi),(\\phi\\leftrightarrow\\psi)\\in X$.\n\t\t\n\t\t\t\t\\end{enumerate}\t\t\n\t\t\n\t\t\\end{enumerate}\nNote the presence of the parentheses in (ii.b)---we'll have to talk about them in some more detail later. It's a bit tedious to write out (ii.b) in full, so we sometimes use the following notation, in which $\\circ$ is a variable ranging over the sentential connectives:\n\\begin{enumerate}[(i)]\n\t\t\\setcounter{enumii}{1}\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\t\t\\setcounter{enumiii}{1}\n\t\t\t\t\t\n\t\t\t\t\t\\item if $\\phi,\\psi\\in X$, then $(\\phi\\circ\\psi)\\in X$, for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$.\n\t\t\n\t\t\t\t\\end{enumerate}\t\t\n\t\t\n\t\t\\end{enumerate}\nSo, for example, if $\\mathcal{P}$ is the set $\\{p,q,r\\}$, we have $p, \\neg\\neg q, (p\\land (r\\lor q)), (p\\to (r\\lor (p\\land (q\\leftrightarrow r)))), \\mathellipsis\\in\\mathcal{L}$.\t\n\n\t\\item Note that there are many different propositional languages, one for each set of propositional letters. For example, the language defined over $\\mathcal{P}=\\{p\\}$ is different from the language defined over $\\mathcal{P}=\\{p,q\\}$. The latter, for example, contains $(p\\land q)$ as a formula, while the former does not. In the following, we'll always assume that we're dealing with a fixed propositional language $\\mathcal{L}$, which has $p,q,r,\\mathellipsis\\in\\mathcal{P}$.\n\n\t\\item There is another way of writing the grammar of a propositional language, which you should have seen. This is the so-called \\emph{Backus-Naur-Form} or \\emph{BNF}, for short, which is especially important in programming and computer science. The BNF of a propositional language is given as follows:\n\t\\[\\phi::=p~|~\\neg \\phi~|~(\\phi\\land\\phi)~|~(\\phi\\lor\\phi)~|~(\\phi\\to\\phi)~|~(\\phi\\leftrightarrow\\phi)\\]\nThis BNF means precisely the same thing as our official recursive definition, it is just written differently. The idea is that an object of type $\\phi$ (formula) is either a sentence letter, $p\\in\\mathcal{P}$, the result of taking an object of type $\\phi$ and writing a $\\neg$ in front of it, or the result of taking an object of type $\\phi$ another object of type $\\phi$ and writing a sentential operator between the two and packaging the result in parentheses.\n\t\n\t\\item With the official definition of $\\mathcal{L}$ in place, we can straight-forwardly show that an expression is a formula by constructing it from the sentence letters using the sentential operators. For example, we can show that $(p\\land (q\\lor r))\\in\\mathcal{L}$ (assuming that $p,q,r\\in\\mathcal{P}$) as follows :\n\t\\begin{itemize}\n\t\n\t\t\\item We have $q,r\\in\\mathcal{P}$, therefore $q,r\\in\\mathcal{L}$.\n\t\t\n\t\t\\item Since $q,r\\in\\mathcal{L}$, we have that $(q\\lor r)\\in\\mathcal{L}$.\n\t\t\n\t\t\\item We have $p\\in\\mathcal{P}$ and therefore $p\\in\\mathcal{L}$.\n\t\t\n\t\t\\item Since $(q\\lor r), p\\in\\mathcal{L}$, we get that $(p\\land (q\\lor r))\\in\\mathcal{L}$.\n\t\n\t\\end{itemize} \nAnd we can also show that an expression is not a formula, roughly like we showed that something is not a natural number. Here, as an example, we'll show that $(p\\land\\neg)\\notin\\mathcal{L}$ (even if $p\\in\\mathcal{P}$):\n\n\t\\begin{proposition}\n\tLet $\\mathcal{L}$ be a propositional language. Then $(p\\land \\neg)\\notin\\mathcal{L}$.\n\t\\end{proposition}\n\t\\begin{proof}\n\tLet $X$ be a set such that $X$ satisfies conditions (i) and (ii) from the definition of $\\mathcal{L}$ and $(p\\land \\neg)\\in X$. We claim that then the set $Y$ defined by: \\[Y=X\\setminus \\{(p\\land \\neg), \\neg\\}\\] also satisfies conditions (i) and (ii) and $Y\\subset X$. We need to show two things. First, we show that (i) $\\mathcal{P}\\subseteq Y$. To see this, note that $\\mathcal{P}\\subseteq X$ and $(p\\land \\neg), \\neg\\notin\\mathcal{P}$. So it follows that for all $p\\in\\mathcal{P}$, $p\\in X$ and $p\\notin  \\{(p\\land \\neg), \\neg\\}$. Hence, $p\\in Y$, meaning $\\mathcal{P}\\subseteq Y$.\n\t\n\tTo see that $Y$ satisfies condition (ii.a), let's suppose that $\\phi\\in Y$. Since $Y= X\\setminus \\{(p\\land \\neg), \\neg\\}$, it follows that $\\phi\\in X$. And since $X$ is closed under negation, we can conclude that $\\neg\\phi\\in X$. But clearly $\\neg \\phi\\notin \\{(p\\land \\neg), \\neg\\}$. Hence, $\\phi\\in X\\setminus  \\{(p\\land \\neg), \\neg\\}$, meaning $\\phi\\in Y$.\n\t\n\tTo see that $Y$ satisfies condition (ii.b), assume that $\\phi,\\psi\\in Y$. We now need to show four different cases (a) $(\\phi\\land\\psi)\\in Y$, (b) $(\\phi\\lor\\psi)\\in Y$, (c) $(\\phi\\to\\psi)\\in Y$, and (d) $(\\phi\\leftrightarrow\\psi)\\in Y$. But for cases (b--d), this is easy. Since $\\phi,\\psi\\in Y$, we get that $\\phi,\\psi\\in X$. Since $X$ satisfies (ii.b), we get that $(\\phi\\circ\\psi)\\in X$ for $\\circ=\\lor,\\to,\\leftrightarrow$. And trivially, for  $\\circ=\\lor,\\to,\\leftrightarrow$, $(\\phi\\circ\\psi)\\notin \\{(p\\land \\neg), \\neg\\}$. Hence $(\\phi\\circ\\psi)\\in Y$, as desired. (Why trivially? We'll look at the form of the members of $\\{(p\\land \\neg), \\neg\\}$\\dots)\n\t\n\tOnly in case (a), we need to reason a bit more. We again easily get from $\\phi,\\psi\\in Y$ to $\\phi,\\psi\\in X$ and from there via (ii.b) to $(\\phi\\land\\psi)\\in X$. But can $(\\phi\\land\\psi)$ be in $\\{(p\\land \\neg), \\neg\\}$? Well, only if $\\phi=p$ and $\\psi=\\neg$. But remember that $\\psi\\in Y=X\\setminus \\{(p\\land \\neg), \\neg\\}$. Hence if $\\psi=\\neg$, then $\\psi\\notin Y$, which contradicts our assumption that $\\psi\\in Y$. Hence, using proof by contradiction, we can conclude that $(\\phi\\land\\psi)\\notin\\{(p\\land \\neg), \\neg\\}$. Hence $(\\phi\\land\\psi)\\in Y$, as desired.\n\t\n\tSo, if $X$ satisfies (i) and (ii) and $(p\\land \\neg)\\in X$, then $X$ is not the smallest set that satisfies conditions (i) and (ii). Hence $X\\neq \\mathcal{L}$. For a final proof by contradiction, suppose that $(p\\land \\neg)\\in\\mathcal{L}$. By our observation, it would follow that $\\mathcal{L}\\neq\\mathcal{L}$, which is a contradiction. Hence $(p\\land \\neg)\\notin\\mathcal{L}$.\n\t\n\t\\end{proof}\n\t\n\tAs you can see, it's quite tedious to show that something isn't a formula. In the following, we'll develop some techniques for proving that expressions aren't formulas that are a bit more ``user friendly.''\n\t\t\n\t\\item But first, let's talk about formalization. As we said above, formalization is the process of abstracting a natural language expression into an expression of a formal language. We don't do this just for fun (even though it is fun), but with a particular aim in mind: we want to check inferences couched in natural language for validity. How to actually check for validity will be covered in the following chapter. For now you can note that in order for us to be able to draw any conclusion from our formal language expeditions back to ordinary language, we need to make sure that, whatever we do in our formalization, we can always reverse it---we want to be able to ``translate backwards.'' In order to guarantee this, every formalization begins with a \\emph{translation key}, which is basically like a cipher in cryptography. A translation key tells us for each sentence letter which natural language sentence it stands for. \n\t\nHere's an example of a translation key:\n\t\\begin{center}\n\t\\begin{tabular}{c c c}\n\t$p$ & : & the letter is in the left drawer\\\\\n\t$q$ & : & the letter is in the right drawer\n\t\\end{tabular}\n\t\\end{center}\nThis is just one possible key, the following one is also perfectly fine:\n\t\\begin{center}\n\t\\begin{tabular}{c c c}\n\t$p$ & : & the letter is in the right drawer\\\\\n\t$q$ & : & the letter is in the left drawer\n\t\\end{tabular}\n\t\\end{center}\t\nThe only thing you're not allowed to do in your translation key is to use a sentence letter to stand for an expression that is formed from simpler sentences using sentential connectives. So the following key is \\emph{not} valid:\n\t\\begin{center}\n\t\\begin{tabular}{c c c}\n\t$p$ & : & the letter is in the left drawer\\\\\n\t$q$ & : & the letter is in the right drawer\\\\\n\t$r$ & : & the letter is not in the left drawer\n\t\\end{tabular}\n\t\\end{center}\nNote that if a sentence is not directly formed from simpler sentences using the connectives, it is also translated by a sentence letter. For example, the sentence ``necessarily, it's not the case that humans fly'' get's translated as a sentence letter. Otherwise, there is no such thing as a correct key, only a useful one.\n\n\\item The rest of the process of formalization in propositional logic basically consists in finding the sentence operator that corresponds best to the operators used to form the sentence. There are no clear rules for doing so, but I can give you some guidelines. In the following examples, I use the translation key:\n\t\\begin{center}\n\t\\begin{tabular}{c c c}\n\t$p$ & : & the letter is in the left drawer\\\\\n\t$q$ & : & the letter is in the right drawer\n\t\\end{tabular}\n\t\\end{center}\nHere are some simple sentences and their corresponding translations:\t\\begin{longtable}{p{8cm} c c}\n\tThe letter isn't in the left drawer & $\\leadsto$ & $\\neg p$\\\\[1ex]\n\tIt's not the case that the letter is in the left drawer & $\\leadsto$ & $\\neg p$\\\\[1ex]\n\tThe letter is in the left and in the right drawer & $\\leadsto$ & $(p\\land q)$\\\\[1ex]\n\tThe letter is not in the left drawer, but it's also not in the right one & $\\leadsto$ & $(\\neg p\\land \\neg q)$\\\\[1ex]\n\tThe letter is in the left or in the right drawer & $\\leadsto$ & $(p\\lor q)$\\\\[1ex]\n\tThe letter is neither in the left nor in the right drawer  & $\\leadsto$ & $(\\neg p\\land \\neg q)$\\\\[1ex]\n\tIf the letter is in the left drawer, then it's not in the right drawer & $\\leadsto$ & $(p\\to \\neg q)$\\\\[1ex]\n\tThe letter is in the left drawer, if it's not in the right one & $\\leadsto$ & $(\\neg q\\to p)$\\\\[1ex]\n\tThe letter is only in the left drawer, if it's not in the right one & $\\leadsto$ & $(p\\to \\neg q)$\\\\[1ex]\n\tThe letter is in the left drawer iff it's not in the right one & $\\leadsto$ & $(p\\leftrightarrow \\neg q)$\\\\\n\t\\end{longtable}\n\tAs you can see, $\\neg,\\land,\\lor,\\to,\\leftrightarrow$ are basically used like their natural language counterparts. There are some special cases, however. Note, for example, that ``The letter is not in the left drawer, but it's also not in the right one'' becomes $(\\neg p\\land \\neg q)$. This is because, from the perspective or propositional logic, the ``but'' only carries the information that both sentences are true---the implicit sense of surprise implied by the use of ``but'' is something we don't care about from a logical perspective.\n\t\n\t\\item A very special case is the one of ``either \\dots or \\dots.'' This expression is ambiguous in English between an inclusive reading (one of the two or both) and an exclusive reading (one of the two but not both). The inclusive reading is translated as $\\lor$ (by logical convention). So, ``the letter is either in the left drawer or in the right drawer'' would be translated as $(p\\lor q)$ if read inclusively. But in this case, an \\emph{exclusive} reading seems more appropriate. This reading would be translated as $((p\\lor q)\\land \\neg (p\\land q))$. It's usually possible from the context to determine which reading is intended, but sometimes there is simply a remaining ambiguity in natural language.\\footnote{Just check [dictionary].}\n\t\n\t\\item To conclude our brief treatment of formalization, let me say that being able to provide a good formalization is much like translating well from one language to another. It requires a good understanding of both and a careful attention to linguistic subtlety. As such, formalization is something you'll have to learn, slowly. You'll be much better at it, once you've properly understood how formal languages work, what the meaning of formal expressions is, given by their semantics, and so on. For now, my advice is just: exercise, exercise, exercise.\n\n\t\\end{enumerate}\n\t\n\\section{Proof by Induction on Formulas}\n\n\\emph{The following section contains the first treatment of one of the most important principles of this course: proof by induction on formulas. Our entire treatment of mathematical induction was in preparation for this. So, before you embark on this section, make sure that you got as much as possible from our treatment of mathematical induction in the previous chapter.}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item We will now develop the technique of proof by induction on formulas, or as we'll often simply call it from now on ``proof by induction.'' The principle is essentially the same as for $\\mathbb{N}$ or the gargles, just applied to the formulas of a propositional language. So, remember that induction is a method for proving something for all members of an inductively defined set. We do so by showing first that the claim holds for all initial elements of the set and that it's preserved under its constructions. Spelled out for formulas, this leads to the following induction principle:\n\t\t\\begin{theorem}\n\t\tLet $\\Phi$ be a condition on formulas. If we can show:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item For all $p\\in\\mathcal{P}$, $\\Phi(p)$.\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\\item For all $\\phi\\in\\mathcal{L}$, if $\\Phi(\\phi)$, then $\\Phi(\\neg\\phi)$.\n\n\t\t\t\\item For all $\\phi,\\psi\\in\\mathcal{L}$, if $\\Phi(\\phi)$ and $\\Phi(\\psi)$, then $\\Phi((\\phi\\circ\\psi))$, for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$.\n\t\t\n\t\t\\end{enumerate}\n\t\t\\end{enumerate}\n\t\tThen we can conclude that for all $\\phi\\in\\mathcal{L}$, $\\Phi(\\phi)$.\n\t\t\\end{theorem}\n\t\t\\begin{proof}\n\t\tLet $\\Phi$ be an arbitrary condition on formulas satisfying conditions (i) and (ii), Consider the set $\\{x:\\Phi(x)\\}$. By the conditions (i) and (ii) of our theorem, $\\{x:\\Phi(x)\\}$ satisfies conditions (i) and (ii) from the definition of $\\mathcal{L}$. Since $\\mathcal{L}$ is the smallest set satisfying those conditions, we have that $\\mathcal{L}\\subseteq\\{x:\\Phi(x)\\}$. But now, it easily follows that for all $\\phi\\in\\mathcal{L}$, we have that $\\Phi(\\phi)$. For let $\\phi\\in\\mathcal{L}$ be an arbitrary formula. Since $\\mathcal{L}\\subseteq\\{x:\\Phi(x)\\}$, it follows that $\\phi\\in\\{x:\\Phi(x)\\}$. But that just means that $\\Phi(\\phi)$, as desired.\n\t\t\\end{proof}\n\t\t\n\t\t\\item We're going to use induction on formulas \\emph{a lot} in this course. Almost always when I ask you ``how are we going to prove this?,'' the answer is going to be ``by induction, of course!'' So, let's be clear on how you write a proof by induction:\n\t\t\t\\begin{enumerate}[1.]\n\t\t\n\t\t\t\\item State clearly that you're using induction to prove the claim.\n\t\t\t\n\t\t\t\\item Prove the base case, i.e. show that all sentence letters have the property.\n\t\t\t\n\t\t\t\\item State clearly that you're now considering the induction steps. In each sub-case, begin by stating your induction hypothesis and then use it to derive the claim about the constructed element, i.e.\n\t\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\t\\item derive that $\\neg\\phi$ has the property from the induction hypothesis that $\\phi$ has the property, and\n\t\t\t\t\n\t\t\t\t\\item derive that $(\\phi\\circ\\psi)$ has the property (for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$) from the induction hypotheses that $\\phi$ and $\\psi$ has the property.\n\t\t\t\n\t\t\t\\end{itemize}\n\t\t\t\n\t\t\t\\item State clearly that you're using induction to infer that the claim in question holds for all elements of the set.\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\\item We're now going through some applications of induction on formulas---but not just for the sake of it, there's going to be a purpose. We want to establish some criteria for determining that an expression isn't a formula. \n\t\n\t\\item First, we're going to note a fact about parentheses, which essentially depends on the fact that for every opening parentheses, there has to be a corresponding closing one in a proper formula. The fact is the following:\n\t\\begin{proposition}\n\tLet $\\phi\\in\\mathcal{L}$ be a formula. Then $\\phi$ contains an even number of parentheses.\n\t\\end{proposition}\n\t\\begin{proof}\n\tWe prove this by induction on formulas. \n\t\n\t\\begin{itemize}\n\t\n\t\t\\item \\emph{Base case}. No sentence letter contains any parentheses. So for each $p\\in\\mathcal{P}$, the number of parentheses in $p$ is zero. But zero is an even number. So, the base case holds.\n\t\t\n\t\t\\item \\emph{Induction steps.}\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item Suppose the induction hypothesis that $\\phi\\in\\mathcal{L}$ contains an even number of parentheses. Consider the formula $\\neg\\phi$. Note the number of parentheses in $\\neg\\phi$ are exactly the same as in $\\phi$, since no new ones have been added. So, also $\\neg\\phi$ contains an even number of parentheses, as desired.\n\t\t\t\n\t\t\t\\item Suppose the induction hypothesis that $\\phi,\\psi\\in\\mathcal{L}$ contain an even number of parentheses. Consider the formulas $(\\phi\\circ\\psi)$. The number of parentheses in $(\\phi\\circ\\psi)$ are precisely the number of parentheses in $\\phi$, plus the number of parentheses in $\\psi$, plus two. But that's the sum of three even numbers, and as such (as you proved as an exercise in the previous chapter) even, as desired.\n\t\t\n\t\t\\end{itemize}\n\t\n\t\\end{itemize}\n\t\n\tWe conclude by induction on formulas that for every $\\phi\\in\\mathcal{L}$, the number of parentheses in $\\phi$ is even.\n\t\n\t\\end{proof}\n\t\n\tThis proposition already gives us a useful criterion for formula-hood: if an expression contains an odd number of parentheses, it cannot be a formula.\n\t\n\t\\begin{corollary}\n\tLet $\\phi$ be an expression. If $\\phi$ contains an odd number of parentheses, then $\\phi\\notin\\mathcal{L}$.\n\t\\end{corollary}\n\t\\begin{proof}\n\tImmediate from the previous proposition via contrapositive proof.\n\t\\end{proof}\n\tUsing this result, we can show, for example, that $((\\neg(p\\lor q)\\land (p\\leftrightarrow\\neg\\neg s))\\notin\\mathcal{L}$. Proving this with our definitional technique (the technique from 4.1.9) would be \\emph{tedious}. But is it the best we can do using parentheses? Why, no! You will prove an even sharper result as an exercise at the end of this chapter.\n\t\t\t\n\t\\item Before we move to the next section, we will prove one more useful result for proving that something isn't a formula. Note that we said that every formula of $\\mathcal{L}$ is made up of symbols from its vocabulary. It's high-time, we proved this:\n\t\\begin{proposition}\n\tLet $\\phi\\in\\mathcal{L}$ be a formula. Then $\\phi$ only contains symbols from the vocabulary of $\\mathcal{L}$.\n\t\\end{proposition}\t\n\t\t\\begin{proof}\n\t\tWe prove this, again, by induction.\n\t\t\n\t\t\\begin{itemize}\n\t\n\t\t\\item \\emph{Base case}. All the members of $\\mathcal{P}$ are part of the vocabulary of $\\mathcal{L}$. So, the base case holds.\n\t\t\n\t\t\\item \\emph{Induction steps.}\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item Suppose the induction hypothesis that $\\phi\\in\\mathcal{L}$ only contains symbols from $\\mathcal{L}$'s vocabulary. Consider the formula $\\neg\\phi$. Note the symbols in $\\neg\\phi$ are exactly the same as in $\\phi$ with the sole addition of $\\neg$. But $\\neg$ is a symbol of $\\mathcal{L}$'s vocabulary. So also $\\neg\\phi$ only contains symbols from $\\mathcal{L}$'s vocabulary.\n\t\t\t\n\t\t\t\\item Suppose the induction hypotheses that $\\phi,\\psi\\in\\mathcal{L}$ only contain symbols from $\\mathcal{L}$'s vocabulary. Consider the formula $(\\phi\\circ\\psi)$, for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$. Note the symbols in $(\\phi\\circ\\psi)$ are exactly the same as in $\\phi$ and $\\psi$ with the  addition of $(,\\circ,$ and $)$. But  $(,\\circ,$ and $)$ are all symbols of $\\mathcal{L}$'s vocabulary. So also $(\\phi\\circ\\psi)$ only contains symbols from $\\mathcal{L}$'s vocabulary.\n\t\t\n\t\t\\end{itemize}\n\t\n\t\\end{itemize}\n\t\n\tWe conclude the theorem by the principle of induction on formulas.\n\t\t\n\t\t\\end{proof}\t\n\t\t\t\n\tAlso this result leads to a necessary condition for formula-hood:\n\t\n\t\\begin{corollary}\n\tLet $\\phi$ be an expression. Then, if $\\phi$ contains a symbol not from $\\mathcal{L}$'s vocabulary, then $\\phi\\notin\\mathcal{L}$.\n\t\\end{corollary}\n\t\\begin{proof}\n\tImmediate from the previous proposition via contrapositive reasoning.\n\t\\end{proof}\n\t\n\tThis criterion allows us to exclude a whole range of expressions from $\\mathcal{L}$, such as, for example, $(p\\leftrightarrow (q\\to \\neg\\neg\\clubsuit))$. Again, this could be done using our definition method (4.1.9) but it would be tedious. In the next section, as an off-shoot from an important theoretical concept to do with readability, we'll get our strongest criterion for formula-hood---an actual algorithm we can use to figure out whether an expression is a formula.\n\t\t\t\n\t\\end{enumerate}\n\n\\section{Unique Readability and Parsing Trees}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item Remember the issues of gargle-readability (3.7.14). The problem was that some gargle could be constructed in more than one ways, which lead to a problem with function recursion over the gargles. We won't run into the same problem with formulas, but that's a fundamental fact about them---the so-called \\emph{unique readability theorem}. Essentially, the theorem states that for each formula, there is a unique way to construct that formula from the sentence letters using the sentential connectives. Importantly, this makes formal languages computer-readable: it means that a computer, who lacks human intuition and context-sensitivity, can always precisely figure out what a given formula is supposed to say.\n\t\t\n\t\t\\item The unique readability theorem is, in effect, a consequence of our tidy use of parentheses. To illustrate how, consider the ``formula'' $p\\land q\\lor r$, which is of course not a proper formula, but suppose for a second that we would allow expressions like this. Well, there would be two ways of ``reading'' or \\emph{parsing} that formula:\n\t\t\n\t\t\\begin{center}\n\t\t\n\t\t\\begin{tabular}{c c c}\n\t\t\\begin{tikzpicture}\n\t\t{\\Tree [.$p\\land q\\lor r$ [.$p$ ] [.$q\\lor r$ [.$q$ ] [.$r$ ] ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t& \n\t\t\n\t\t\\qquad \\raisebox{7.5ex}{vs.} \\qquad \n\t\t\t\t\\begin{tikzpicture}\n\n\t\t{\\Tree [.$p\\land q\\lor r$ [.$p\\land q$ [.$p$ ] [.$q$ ] ] [.$r$ ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t\\end{tabular}\n\t\t\\end{center}\nThis is not only bad for function recursion (for issues we discussed in the context of the gargles) but also messes up our intended \\emph{informal} reading of the formula. Suppose we use a translation key where $p$ stands for ``I drink a coffee,'' $q$ for ``I have toast,'' and $r$ for ``I have eggs.'' Then, our two ways of parsing the sentence correspond to two very different informal meanings:\n\t\\begin{itemize}\n\t\n\t\t\\item I have a coffee and either toast or eggs.\n\t\t\n\t\t\\item Either I have a coffee and toast or I have eggs.\n\t\n\t\\end{itemize}\nThe two are really very different in meaning: in the former case you have a beverage and food and in the second either you have a beverage and food or just some food.\n\nBut this is just a cautionary tale: the problem actually doesn't arise in propositional logic, as long as we use our parentheses properly---which is what we're going to prove in this section.\n\n\t\\item To state the unique readability theorem, we will make use of the notion of a \\emph{parsing tree}. And before that, the notion of a \\emph{tree}.\\footnote{Mathematicians call the structure that we're studying here (more correctly) a \\emph{directed rooted} tree, but for simplicity we'll just drop the modifiers.} Roughly speaking, a tree is a structure of the following form:\n\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree [.$\\bullet$ [.$\\bullet$  [.$\\bullet$ {$\\vdots$} {$\\vdots$} ]  [.$\\bullet$ {$\\vdots$} ] ] [.$\\bullet$  [.$\\bullet$ [.$\\bullet$ ] ]  [.$\\bullet$ {$\\vdots$} ]  [.$\\bullet$ ] ] ]\n\\end{tikzpicture}\n\\end{center}\n\nSome terminology about trees: \n\t\\begin{itemize}\n\t\t\n\t\t\\item The dots are called the {\\it nodes} of the tree and the lines connecting them the {\\it edges}. \n\t\t\n\t\t\\item The upper-most node is called the {\\it root} of the tree and the lower-most nodes its {\\it leaves}. \n\t\t\n\t\t\\item If $x$ is a node in the tree and $y$ is directly above $x$, i.e. there is an edge pointing from $y$ to $x$, then $x$ is called a {\\it child} of $y$ and $y$ the \\emph{parent} of $x$. \n\t\t\n\t\t\\item A {\\it path} in the tree is a sequence of nodes which are connected by edges. \n\t\t\n\t\\end{itemize}\nNote that in a tree, there's never a ``loop,'' i.e. a (non-trivial) path that both begins and ends at the same node. We're not going to bother giving a mathematically precise definition of a tree, but instead we're going to put the concept immediately to (good) use.\n\n\t\\item To define the parsing tree of a formula, we will, for the first time, make use of function recursion over $\\mathcal{L}$. So let's briefly remind ourselves how this works in general (remember 3.7.12--13). In order to recursively define a function over an inductively defined set:\n\t\n\t\\begin{enumerate}[1.]\n\t\t\n\t\t\t\\item We say what the value of our function is on the initial elements.\n\t\t\t\n\t\t\t\\item We say how to calculate the value of the function for an element built by a construction, where we can reference to the values of the function for the elements the element is constructed from.\n\t\t\n\t\t\\end{enumerate}\n\tIn the case of $\\mathcal{L}$, this means we have to give the values of the function for all sentence letters and we have to say how the function behaves under the sentential operators. Note that we will have to prove that this actually defines a function on $\\mathcal{L}$---remember the unique readability issue. We'll do in a moment. For now, we will pretend that it does and justify that assumption \\emph{ex post}, i.e. afterwards.\n\t\n\t\\item We will now use function recursion to define a function $T$, which maps any formula $\\phi\\in\\mathcal{L}$ to its parsing tree:\n\t\n\\begin{center}\n\\begin{tikzpicture}\n\\node at (-2,1) {(i)};\n\n\\node at (0,1) {$T(p)=$};\n\\node at (1.5,1) {\\Tree [.$p$ ]};\n\\node at (4,1) {for $p\\in\\mathcal{P}$};\n\n\\node at (-2,-1) {(ii.a)};\n\\node at (0,-1) {$T(\\neg \\phi)=$};\n\\node at (2,-1) {\\Tree [.$\\neg \\phi$ [.$T(\\phi)$ ] ]};\n\n\\node at (-2,-3) {(ii.b)};\n\\node at (0,-3) {$T((\\phi\\circ\\psi))=$};\n\\node at (2,-3) {\\Tree [.$(\\phi\\circ\\psi)$ [.$T(\\phi)$ ] [.$T(\\psi)$ ] ]};\n\\node at (5,-3) {for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$};\n\\end{tikzpicture}\n\\end{center}\n\n\tWhat a parsing tree does is, essentially, tell us how the formula in question was constructed. To see how, it's best to look at some examples.\n\t\n\t\\item One useful piece of terminology: the first sentential operator who's rule is applied when we construct the parsing tree for a formula is called the \\emph{main} operator of that formula. This operator will become particularly important when we do semantics in the next chapter. For now, it will allow us to refer to statements based on their main operator:\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{c | c}\n\t\t\tMain operator & Kind of statement\\\\\\hline\n\t\t\t$\\neg$ & a negation\\\\\n\t\t\t$\\land$ & a conjunction\\\\\n\t\t\t$\\lor$ & a disjunction\\\\\n\t\t\t$\\to$ & a conditional\\\\\n\t\t\t$\\leftrightarrow$ & a biconditional\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\n\t\\item \\emph{Examples}. Here are some examples of parsing trees:\n\t\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\\item \\\n\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {$T(((p\\land (p\\to q)) \\to \\neg q))=$};\n\\node at (5,0) {\\Tree [.$((p\\land (p\\to q))\\to \\neg q)$ [.$(p\\land (p\\to q))$ [.$p$ ] [.$(p\\to q)$ [.$p$ ] [.$q$ ] ] ] [.$\\neg q$ [.$q$ ] ] ]};\n\n\\end{tikzpicture}\n\nMain operator: $\\to$\n\\end{center}\n\n\t\t\\item \\\n\t\t\n\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {$T((p\\land (q\\lor \\neg q)))=$};\n\\node at (5,0) {\\Tree [.$(p\\land (q\\lor \\neg q))$ [.$p$ ] [.$(q\\lor \\neg q)$ [.$q$ ] [.$\\neg q$ [.$q$ ] ] ] ]};\n\n\\end{tikzpicture}\n\nMain operator: $\\land$\n\\end{center}\n\n\t\t\\item \\\n\t\t\n\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,1) {$T(((p\\to q)\\lor (q\\to r)))=$};\n\\node at (5,1) {\\Tree [.$((p\\to q)\\lor (q\\to r))$ [.$(p\\to q)$ [.$p$ ] [.$q$ ] ] [.$(q\\to r)$ [.$q$ ] [.$r$ ] ] ] };\n\n\\end{tikzpicture}\n\nMain operator: $\\lor$\n\\end{center}\n\n\t\t\t\n\t\t\\item \\\n\t\t\t \n\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,1) {$T(\\neg\\neg\\neg\\neg q)=$};\n\\node at (5,1) {\\Tree [.$\\neg\\neg\\neg\\neg q$ [.$\\neg\\neg\\neg q$ [.$\\neg\\neg q$ [.$\\neg q$ [.$q$ ] ] ] ] ]};\n\n\\end{tikzpicture}\n\nMain operator: $\\neg$\n\\end{center}\n\nIn each of these cases, you can read the tree from bottom to top to get a construction of the formula in question from the sentence letters. This is the precise sense in which a parsing tree tracks the construction of a formula.\n\t\t\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\\emph{The following point is the most difficult in this chapter. If you don't get it immediately, don't despair! Follow the advice on reading math: try to think this through, consider examples, draw pictures, etc. And then move on. The details of this proof are not the most important thing to take out of this chapter---the content of the main theorem is!}\n\t\t\n\t\\item We will now prove that our recursive definition of $T$ indeed assigns to each formula $\\phi$ a unique parsing tree, i.e. we prove that $T$ is a function. We do this in two steps, by proving two central lemmas. In order to properly state these lemmas, we need to read (i) and (ii) from (4.3.5) as \\emph{conditions} on something being a tree for a formula---otherwise, we'd already assume the truth of these lemmas. The idea is that, for example, (4.3.5.i) says that a tree $T$ is a parsing tree of $p$ iff $T=p$. And (4.3.5.ii.a) says that $T$ is a parsing tree for $\\neg\\phi$ iff $T$ is of the form \n\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {\\Tree [.$\\neg \\phi$ [.$T'$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nwhere $T'$ is a parsing tree for $\\phi$. Similarly for (4.3.5.ii.b). With this understanding in mind, we can prove the following two lemmas:\n\n\t\t\\begin{lemma}[Existence Lemma]\n\t\tFor each $\\phi\\in\\mathcal{L}$, $T(\\phi)$ exists, i.e. there exists a tree that satisfies the conditions (i--ii) from (4.3.5).\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\tWe prove the claim using induction.\n\t\t\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\n\t\t\t\t\\item \\emph{Base case}. Let $p\\in\\mathcal{P}$ be a sentence letter. By (4.3.5.i), $T(p)=p$. And, indeed, $p$ is a tree with $p$ as its only node. Hence, the base case holds.\n\t\t\t\t\n\t\t\t\t\\item \\emph{Induction steps}.\n\t\t\t\t\n\t\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\n\t\t\t\t\t\t\\item Suppose the induction hypothesis that $T(\\phi)$ exists. We need to show that $T(\\neg \\phi)$ exists. By (4.3.5.ii.a), we have that: \n\t\t\t\t\t\t\n\t\t\t\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,1) {$T(\\neg \\phi)=$};\n\\node at (2,1) {\\Tree [.$\\neg \\phi$ [.$T(\\phi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nBut by the induction hypothesis $T(\\phi)$ exists. But if $T(\\phi)$ is a tree, so is $T(\\neg\\phi)$.\n\n\t\t\t\t\\item Suppose the induction hypotheses that $T(\\phi)$ and $T(\\psi)$ exist. We need to show that $T((\\phi\\circ\\psi))$ exists for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$. By (4.3.5.ii.b), we have that: \n\t\t\t\t\t\t\n\t\t\t\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,1) {$T((\\phi\\circ\\psi))=$};\n\\node at (2,1) {\\Tree [.$(\\phi\\circ\\psi)$ [.$T(\\phi)$ ] [.$T(\\psi)$ ] ]};\n\\node at (5,1) {for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$};\n\\end{tikzpicture}\n\\end{center}\nBut by the induction hypothesis $T(\\phi)$ and $T(\\psi)$ both exist. But if $T(\\phi)$ is a tree and $T(\\psi)$ is a tree, so is $T((\\phi\\circ\\psi))$.\t\t\t\t\t\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\tUsing induction on formulas, we conclude that for each $\\phi\\in\\mathcal{L}$, $T(\\phi)$ exists.\n\t\t\\end{proof}\n\t\\begin{lemma}[Uniqueness Lemma]\n\tLet $\\phi\\in\\mathcal{L}$. Then $T(\\phi)$ is unique, i.e. if $T_1(\\phi)$ and $T_2(\\phi)$ are two trees that satisfy the conditions (i--ii) from (4.3.5), then $T_1(\\phi)=T_2(\\phi)$.\n\t\\end{lemma}\n\t\n\t\\begin{proof}\n\tWe prove this, once more, using induction.\n\t\t\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\n\t\t\t\t\\item \\emph{Base case}. Let $p\\in\\mathcal{P}$ be a sentence letter, and $T_1(p)$ and $T_2(p)$ two trees satisfying the  conditions (i--ii) from (4.3.5). But condition (4.3.5.i) says that $T(p)=p$, so $T_1(p)=p=T_2(p)$, which is what we needed to show.\n\t\t\t\t\t\t\t\t\n\t\t\t\t\\item \\emph{Induction steps}.\n\t\t\t\t\n\t\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\n\t\t\t\t\t\\item Suppose the induction hypothesis that if $T_1(\\phi)$ and $T_2(\\phi)$ are two trees for $\\phi$ which satisfy  conditions (i--ii) from (4.3.5), then $T_1(\\phi)=T_2(\\phi)$. Now consider two trees for $\\neg \\phi$, i.e. $T_1(\\neg\\phi)$ and $T_2(\\neg \\phi)$. By (4.3.5.ii.a), we have that:\t\n\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,1) {$T_1(\\neg \\phi)=$};\n\\node at (1.5,1) {\\Tree [.$\\neg \\phi$ [.$T_1(\\phi)$ ] ]};\n\\node at (3,1) { and};\n\\node at (5,1) {$T_2(\\neg \\phi)=$};\n\\node at (6.5,1) {\\Tree [.$\\neg \\phi$ [.$T_2(\\phi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nwhere $T_1(\\phi)$ and $T_2(\\phi)$ are trees for $\\phi$ which satisfy the conditions  (i--ii) from (4.3.5). But then, by the induction hypothesis, $T_1(\\phi)=T_2(\\phi)$. And so, $T_1(\\neg\\phi)=T_2(\\neg \\phi),$ as desired.\n\n\t\t\t\t\t\n\t\t\t\t\t\t\\item Suppose the first induction hypothesis that if $T_1(\\phi)$ and $T_2(\\phi)$ are two trees for $\\phi$ which satisfy  conditions (i--ii) from (4.3.5), then $T_1(\\phi)=T_2(\\phi)$. And suppose further that if $T_1(\\psi)$ and $T_2(\\psi)$ are two trees for $\\psi$ which satisfy  conditions (i--ii) from (4.3.5), then $T_1(\\psi)=T_2(\\psi)$.\n\t\t\t\t\t\t\n\t\t\t\t\t\tNow consider two trees for $(\\phi\\circ\\psi)$, for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$, $T_1((\\phi\\circ\\psi))$ and $T_2((\\phi\\circ\\psi))$. By (4.3.5.ii.a), we have that:\t\n\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,1) {$T_1((\\phi\\circ\\psi))=$};\n\\node at (2,1) {\\Tree [.$(\\phi\\circ\\psi)$ [.$T_1(\\phi)$ ] [.$T_1(\\psi)$ ] ]};\n\\node at (3.3,1) { and};\n\\node at (5,1) {$T_2((\\phi\\circ\\psi))=$};\n\\node at (7,1) {\\Tree [.$(\\phi\\circ\\psi)$ [.$T_2(\\phi)$ ] [.$T_2(\\psi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nwhere $T_1(\\phi)$ and $T_2(\\phi)$ are trees for $\\phi$ which satisfy the conditions  (i--ii) from (4.3.5), and $T_1(\\psi)$ and $T_2(\\psi)$ are trees for $\\psi$ which satisfy the conditions  (i--ii) from (4.3.5). But then, by the induction hypotheses, $T_1(\\phi)=T_2(\\phi)$ and $T_1(\\psi)=T_2(\\psi)$. And so, $T_1((\\phi\\circ\\psi))=T_2((\\phi\\circ\\psi)),$ as desired.\n\n\t\\end{enumerate}\n\t\n\t\\end{enumerate}\n\t\nWe conclude by using (i) and (ii) to infer by induction that the parsing tree for every formula is unique.\n\t\n\\end{proof}\n\t\n\tPut together, the two lemmas yield our unique readability theorem:\n\t\\begin{theorem}\n\tFor each formula $\\phi\\in\\mathcal{L}$ there exists a unique parsing tree, $T(\\phi)$ as defined by (4.3.5).\n\t\\end{theorem}\n\t\n\tThis theorem is of fundamental importance for what we're doing in propositional logic. Essentially, it guarantees that we can use function recursion on $\\mathcal{L}$. Why? Because the theorem tells us that we can calculate a recursively defined function on $\\mathcal{L}$ following the formulas parsing tree---\\emph{and this is the only way in which the function can be calculated}. In fact, this theorem guarantees that propositional logic can be computer implemented---a computer can construct the parsing tree for a formula in order to ``understand'' it.\n\t\n\t\\item We'll conclude the section by discussing an \\emph{algorithm} for determining whether a given expression $\\sigma$ is a formula. First, let's clarify what we understand under the term ``algorithm.'' In mathematics, an algorithm is typically understood as a finite set of precise instructions which, if followed, are supposed to complete a specific task. Hence an algorithm itself is not a computer program but the procedure that underlies the computer program. We can thus describe an algorithm in natural language without focusing on a specific \\emph{implementation} of the algorithm in a programming language. \n\t\n\t\\item The task that our algorithm is supposed to fulfill is to determine whether a given expression is a formula. We hereby assume that the expression is formed entirely out of symbols from the alphabet, since by 4.2.5, if it's not, we can already exclude that it's a formula. Here is our algorithm:\n\t\\begin{enumerate}[1.]\n\t\t\t\n\t\t\t\t\\item Write down the expression $\\sigma$ and look at it. Proceed to step 2.\n\t\t\t\t\n\t\t\t\t\\item Does the expression you're currently looking at contain the same number of $($'s and $)$'s?\n\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\t\\item If not, terminate: $\\sigma$ is not a formula!\n\t\t\t\t\t\n\t\t\t\t\t\\item If yes, proceed to step 3.\n\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\t\n\t\t\t\t\\item Is the expression you're currently looking at of the form $p$?\n\t\t\t\t\n\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\t\\item If not, proceed to step 4.\n\t\t\t\t\n\t\t\t\t\t\\item If yes, write a $\\checkmark$ next to it and proceed to step 6.\n\t\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\t\n\t\t\t\t\\item Is the expression you're currently looking at of the form $\\neg \\tau$?\n\n\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\t\\item If not, proceed to step 5.\n\n\t\t\t\t\t\n\t\t\t\t\t\\item If yes, apply the following rule:\n\t\t\t\t\t\\begin{center}\n\t\t\t\t\t\\Tree [.$\\neg \\tau\\checkmark$ [.$\\tau$ ] ]\n\t\t\t\t\t\\end{center}\n\t\t\t\t\tThen proceed to step 6.\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\t\t\t\t\t\t\t\t\n\t\n\t\t\t\\item Is the expression you're currently looking at of the form $(\\tau\\circ\\pi)$, $\\circ=\\land,\\lor,\\to,\\leftrightarrow$,  and there is no other connective $\\square=\\land,\\lor,\\to,\\leftrightarrow$ such that the expression is of the form $(\\tau'\\square\\pi')$ and $\\square$ is enclosed in fewer parentheses than $\\circ$?\t\t\t\t\n\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\t\\item If not, terminate: $\\sigma$ is not a formula!\n\t\t\t\t\n\t\t\t\t\\item If yes, apply the following rule:\n\t\t\t\n\t\t\t\t\\begin{center}\n\t\t\t\t\\Tree [.$(\\tau\\circ\\pi)\\checkmark$ [.$\\tau$ ] [.$\\pi$ ] ]\n\t\t\t\t\\end{center}\n\t\t\t\n\t\t\t\tThen proceed to step 6.\t\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\n\t\t\t\\item In the tree you've constructed so far, is there an expression at a leaf without a $\\checkmark$ next to it?\n\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item If no, terminate: $\\sigma$ is a formula \\smiley\t\t\n\t\t\t\t\n\t\t\t\t\\item If yes, then pick one and look at it. Go back to step 2.\n\t\t\t\n\t\t\n\t\t\t\\end{enumerate}\n\t\n\t\t\\end{enumerate}\n\t\t\n\t\\item We will not prove that this algorithm actually completes its task, we won't \\emph{formally verify} the algorithm. To do so, is actually not that hard given all the facts we've already observed. But it's tedious and so we'll leave the task to the interested reader. Note that what you would need to show are three things: (i) the algorithm always terminates, (ii) if the algorithm terminates and says that the expression is a formula, then it is indeed a formula, and (iii) if the algorithm terminates and says that the expression is not a formula, then it is indeed not a formula. Here we simply observe (again without proof) that the algorithm, if applied to a formula, actually yields the parsing tree of that formula. To see this, try it out! Apply the algorithm to some formulas and see what you get. Here we give just one example:\n\t\\begin{center}\n\t\\Tree[.$(p\\lor (q\\lor (r\\leftrightarrow (\\neg s\\land t))))\\checkmark^{5.b}$ [.{$p\\checkmark^{3.b}$} ] [.{$(q\\lor (r\\leftrightarrow (\\neg s\\land t)))\\checkmark^{5.b}$} [.{$q\\checkmark^{3.b}$} ] [.{$(r\\leftrightarrow (\\neg s\\land t))\\checkmark^{5.b}$} [.$r\\checkmark^{3.b}$ ] [.$(\\neg s\\land t)\\checkmark^{5.b}$ [.$\\neg s\\checkmark^{4.b}$ [.$s\\checkmark^{3.b}$ ] ] [.$t\\checkmark^{3.b}$ ] ] ] ] ]\n\t\n\t\\emph{Note that in the first step (5.b), we parse according to the first $\\lor$ because it's in fewer parentheses than the second $\\lor$, the $\\leftrightarrow$ and the $\\land$.}\n\t\\end{center}\n\tSo, effectively, what the algorithm does is what a computer would do (described on a very abstract level) if given an expression and asked whether it makes sense in propositional logic.\n\t\n\t\\item We conclude the section with two example applications of the algorithm to illustrate how it can be used to show that something \\emph{isn't} a formula:\n\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item \\emph{Claim}. $((p\\land q)\\to (r))\\notin\\mathcal{L}$\n\t\t\t\n\t\t\t\\item[] \\emph{Algorithmic proof}.\n\n\t\t\t\\begin{center}\t\t\n\t\t\t\t\\Tree [.$((p\\land q)\\to \\neg(r))\\checkmark^{5.b}$ [.$(p\\land q)\\checkmark^{5.b}$ [.$p\\checkmark^{3.b}$ ] [.$q\\checkmark^{3.b}$ ] ] [.$\\neg(r)\\checkmark^{4.b}$ [.$(r)\\frownie^{5.a}$ ] ] ] \n\t\t\t\\end{center}\n\t\t\t\n\t\t\t\\item \\emph{Claim}. $\\neg\\neg(p(\\leftrightarrow) q)\\notin\\mathcal{L}$.\n\t\t\t\n\t\t\t\\item[] \\emph{Algorithmic proof}.\n\t\t\t\n\t\t\t\t\\begin{center}\n\t\t\t\t\\Tree [.${\\neg\\neg(p(\\leftrightarrow) q)}\\checkmark^{4.b}$ [.${\\neg(p(\\leftrightarrow) q)}\\checkmark^{4.b}$ [.${(p(\\leftrightarrow) q)}\\checkmark^{5.b}$ [.$(p(\\frownie^{2.a}$ ] [.$)q)\\frownie^{2.a}$ ] ] ] ]\n\t\t\t\t\\end{center}\n\t\t\\end{enumerate}\n\t\n\t\\end{enumerate}\n\t\n\t\n\\section{Function Recursion on Propositional Languages}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item In the previous section, we've given a justification for using function recursion on $\\mathcal{L}$. Now, we'll define two important syntactic functions, i.e. functions with domain $\\mathcal{L}$. The importance of these functions derives from their wide-spread use in logical literature (way beyond propositional logic). But also in our course, they will play an important role here and there.\n\t\t\n\t  \\item The first of the two functions, we'll define a function that maps each formula to the set of formulas it was constructed from.\n\t\tThese formulas are called the \\emph{sub-formulas} of the formula in question.\n\t\tWe define the function as follows using function recursion:\n\t\t\\begin{enumerate}[(i)]\n\t\t  \\item%\n\t\t\t$sub(p)=\\{p\\}$ for $p\\in\\mathcal{P}$\n\t\t  \\item%\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t  \\item%\n\t\t\t\t$sub(\\neg\\phi)= sub(\\phi)\\cup\\{\\neg \\phi\\}$\n\t\t\t  \\item%\n\t\t\t\t$sub((\\phi\\circ\\psi))= sub(\\phi)\\cup sub(\\psi)\\cup\\{(\\phi\\circ\\psi)\\}$\n\t\t\t\\end{enumerate}\n\t\t\\end{enumerate}\n\t\tLet's consider two examples.\n\t\tWe have:\n\t\t\\begin{itemize}\n\t\t  \\item%\n\t\t\t$sub(\\neg \\neg p)=\\{p,\\neg p, \\neg\\neg p\\}$\n\t\t  \\item%\n\t\t\t$sub(((p\\land q)\\lor r))=\\{p,q,r,(p\\land q), ((p\\land q)\\lor r)\\}$\n\t\t\\end{itemize}\n\t\tIn order to understand this definition,\n\t\tfollow the advice for understanding a definition from lecture 2!\n\n\t\\item One thing that might help us understanding sub-formulas better is to compare them to notions we've previously introduced. For this purpose, we'll prove the following proposition:\n\t\n\t\t\\begin{proposition}\n\t\tLet $\\phi\\in\\mathcal{L}$ be a formula. Then the elements of $sub(\\phi)$ are precisely the formulas that occur in $T(\\phi)$.\n\t\t\\end{proposition}\n\t\t\\begin{proof}\n\t\tWe prove this fact using---surprise---induction.\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item \\emph{Base case}. Let $p\\in\\mathcal{P}$ be a sentence letter. Then $sub(p)=\\{p\\}$ and $T(p)=p$. Hence $sub(p)$ is precisely the set of formulas that occur in $T(p)$.\n\t\t\t\n\t\t\t\\item \\emph{Induction steps}. \n\t\t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\t\\item Assume the induction hypothesis that $sub(\\phi)$ are precisely the formulas that occur in $T(\\phi)$. Now consider $\\neg \\phi$. We know by definition of $sub$, that $sub(\\neg\\phi)=sub(\\phi)\\cup\\{\\neg\\phi\\}$. By the (ii.a) definition of parsing trees, we know furthermore that:\n\t\t\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {$T(\\neg \\phi)=$};\n\\node at (2,0) {\\Tree [.$\\neg \\phi$ [.$T(\\phi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nHence the formulas that occur in $T(\\neg\\phi)$ are precisely the formulas that occur in $T(\\phi)$ plus the formula $\\neg\\phi$. But this is just another way of saying that the formulas in $T(\\neg\\phi)$ are  $sub(\\phi)\\cup\\{\\neg\\phi\\}=sub(\\neg\\phi),$ as desired.\n\n\t\t\t\\item Assume the induction hypotheses that $sub(\\phi)$ are precisely the formulas that occur in $T(\\phi)$ and $sub(\\psi)$ are precisely the formulas ocuring in $T(\\psi)$. Now consider $(\\phi\\circ\\psi)$, for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$. We know by definition of $sub$, that $sub((\\phi\\circ\\psi))=sub(\\phi)\\cup sub(\\psi)\\cup\\{(\\phi\\circ\\psi)\\}$. By the (ii.a) definition of parsing trees, we know furthermore that:\n\t\t\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {$T((\\phi\\circ\\psi))=$};\n\\node at (2,0) {\\Tree [.$(\\phi\\circ\\psi)$ [.$T(\\phi)$ ] [.$T(\\psi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nHence the formulas that occur in $T((\\phi\\circ\\psi))$ are precisely the formulas that occur in $T(\\phi)$, plus the formulas in $T(\\psi)$, plus $(\\phi\\circ\\psi)$. But this is just another way of saying that the formulas in $T((\\phi\\circ\\psi))$ are $sub(\\phi)\\cup sub(\\psi)\\cup\\{(\\phi\\circ\\psi)\\}=sub((\\phi\\circ\\psi)),$ as desiderd.\n\n\t\t\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\tWe can thus use induction to infer that the claim holds for all $\\phi$.\t\t\n\t\t\\end{proof}\n\n\t\\item We move to the second important syntactic function, the so-called measure of \\emph{complexity}. In order to define this function, we make use of the maximum function $max:\\mathbb{N}^2\\to\\mathbb{N}$, which is defined as follows:\n\t\\[max(n,m)=\\begin{cases} n &\\text{if }n>m\\\\ m &\\text{if }m>n\\\\n& \\text{if }n=m\\end{cases}\\] So, we get, for example, $max(2,3)=3, max(3,2)=3, max(2,2)=2$, and so on. Using $max$, the (recursive) definition of the complexity function $c:\\mathcal{L}\\to\\mathbb{N}$ is as follows:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item $c(p)=0$ for $p\\in\\mathcal{P}$\n\t\t\n\t\t\\item \\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $c(\\neg\\phi)=c(\\phi)+1$\n\t\t\t\n\t\t\t\\item $c((\\phi\\circ\\psi))=max(c(\\phi), c(\\psi))+1$, for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$.\n\t\t\n\t\t\\end{enumerate}\n\t\n\t\\end{enumerate}\nLet's consider some examples. We have:\n\t\\begin{itemize}\n\t\n\t\t\\item $c(\\neg p)=1$, $c((p\\land q))=1, c((p\\lor q)=1, \\mathellipsis$\n\t\t\n\t\t\\item $c(\\neg\\neg p)=2$, $c(\\neg (p\\land q))=2$, $c((\\neg p\\land \\neg q))=2, \\mathellipsis$\n\t\n\t\\end{itemize}\n\t\n\tCan we somehow narrow down what $c$ precisely measures? Think about it before you read the next point. \n\n\t\\item We will now prove a proposition that gives us an intuitive reading of the function $c$:\n\t\n\t\\begin{proposition}\n\tLet $\\phi\\in\\mathcal{L}$ be a formula. Then $c(\\phi)$ is the length of the longest path in $T(\\phi)$ which starts from the root (counted in number of edges travelled). In other words, $c(\\phi)$ gives us the \\emph{height} of the parsing tree $T(\\phi)$.\n\t\\end{proposition}\n\t\\begin{proof}\n\tHow are we going to prove this? You know it!\n\t\n\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item \\emph{Base case}. Let $p\\in\\mathcal{P}$ be a sentence letter. Then $T(p)=p$. But the only path you can travel from the root in $p$ is the trivial path of length zero, which just stops immediately at $p$. Since $c(p)=0$, this just means that the base case holds.\n\t\t\t\n\t\t\t\\item \\emph{Induction steps}. \n\t\t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\t\\item Assume the induction hypothesis that $c(\\phi)$ is the length of the longest path from the root in $T(\\phi)$. Now consider $\\neg \\phi$. By the (ii.a) definition of parsing trees, we know that:\n\t\t\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {$T(\\neg \\phi)=$};\n\\node at (2,0) {\\Tree [.$\\neg \\phi$ [.$T(\\phi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nNow think about the longest path you can travel from the root in $T(\\neg\\phi)$. Well, it's going to be the longest path you can travel in $T(\\phi)$ plus one edge to the new root, i.e. $\\neg\\phi$. Since $c(\\neg\\phi)=c(\\phi)+1$, this means that, by the induction hypothesis, the claim holds.\n\n\t\t\t\\item Assume the induction hypotheses that $c(\\phi)$ is the length of the longest path from the root in $T(\\phi)$ and $c(\\psi)$ is the length of the longest path from the root in $T(\\psi)$. By the (ii.a) definition of parsing trees, we know that:\n\t\t\t\t\t\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {$T((\\phi\\circ\\psi))=$};\n\\node at (2,0) {\\Tree [.$(\\phi\\circ\\psi)$ [.$T(\\phi)$ ] [.$T(\\psi)$ ] ]};\n\\end{tikzpicture}\n\\end{center}\nNow think about the longest path you can travel in $T((\\phi\\circ\\psi))$. Well, take the longest path you can find in either $T(\\phi)$ or $T(\\psi)$. Let's suppose that the path is in $T(\\phi)$ (if it is in $T(\\psi)$, the argument is completely analogous). The longest path you can travel from the root in $T((\\phi\\circ\\psi))$ is going to be precisely this path plus the one new edge connecting $T(\\phi)$ to the new root $(\\phi\\circ\\psi)$. Since $c((\\phi\\circ\\psi))=max(c(\\phi),c(\\psi))+1$, this just means that the claim also holds here. \n\t\t\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\tWe can thus use induction to infer that the claim holds for all $\\phi$.\t\t\t\n\t\\end{proof}\n\t\n\t\\item This completes our discussion of function recursion on $\\mathcal{L}$ by means examples. In order to get a real good grip on how the method works, it's best for you to try your hand at it, i.e. try to define your own syntactic functions using function recursion. Among the exercises, you can find some functions you can try to define.\n\n\t\\end{enumerate}\n\n\\section{Some Useful Notational Conventions}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item So far, we've been very precise about our use of parentheses. And for good reason: as we discussed in \\S4.3, our tidy use of parentheses is what guaranteed unique readability. But, at the same time, writing all of these parentheses can be exhausting. And, as I said in the lecture, logicians are lazy: they don't like to do unnecessary things. So, over the years, some generally agreed upon conventions have emerged for leaving out parentheses, which we'll briefly discuss in this section.\n\t\t\n\t\t\\item Before we begin, note that conventional notation is only ever allowed outside the context of syntax theory, i.e. in semantics and proof theory. And even there, it's often better to be safe than sorry. As we said a couple of times by now: the parentheses are there for a reason. It's much easier to make mistakes using conventional notation than it is in official notation. That being said, conventional notation can be a real boon on your wrist.\n\t\t\n\t\t\\item The first convention is that you can always omit any outermost parentheses. So, instead of $(p\\land q)$, you can simply write $p\\land q$. The reasoning behind this is that these are easy to fill in: if a logician writes $p\\lor q$, it's pretty clear what they mean: $(p\\lor q$).\n\t\t\n\t\t\\item The second convention is that in a series of $\\lor$'s or $\\land$'s, you can leave out the repeatedly nested parentheses. So, for example, instead of the official $((p\\land (q\\land (r\\land (s\\land t)))))$, we can simply write $p\\land q\\land r\\land s\\land t$ (also applying the convention about outermost parentheses). Note that this convention really introduces some ambiguity into our language. The conventional formula $p\\lor q\\lor r$ has indeed two ways of being parsed:\n\t\t\\begin{center}\n\t\t\n\t\t\\begin{tabular}{c c c}\n\t\t\\begin{tikzpicture}\n\t\t{\\Tree [.$p\\lor q\\lor r$ [.$p$ ] [.$q\\lor r$ [.$q$ ] [.$r$ ] ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t& \n\t\t\n\t\t\\qquad \\raisebox{7.5ex}{vs.} \\qquad \n\t\t\t\t\\begin{tikzpicture}\n\n\t\t{\\Tree [.$p\\lor q\\lor r$ [.$p\\lor q$ [.$p$ ] [.$q$ ] ] [.$r$ ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t\\end{tabular}\n\t\t\\end{center}\nThis makes the convention a bit harder to justify. But note that the two different ``readings'' of the formula don't really say anything different. Take the following two sentences: \n\t\\begin{itemize}\n\n\t\t\\item I have toast, or I have eggs or pancakes\n\t\t\n\t\t\\item I have toast or eggs, or I have pancakes\n\n\t\\end{itemize}\nThey really seem to say the same thing. We'll only be able to properly justify the convention in the next chapter, when we talk about logical equivalence, but for now, I hope these examples illustrate why we can allow for this little bit of ambiguity. Note that in \\emph{mixed} series of $\\land$ and $\\lor$, we \\emph{cannot} omit parentheses. I.e. $p\\land (q\\lor r)$ needs to stay just that.\n\n\t\t\\item Finally, the most complicated convention concerns the interaction of the connectives. The idea is that if we agree upon which connective we should read first, we can drop a bunch of parentheses. For example, if we say that we always read $\\to$ before $\\land$ if there's an ambiguity, then the previously ambiguous expression $p\\land q\\to r$, with the two readings\n\t\t\t\t\\begin{center}\n\t\t\n\t\t\\begin{tabular}{c c c}\n\t\t\\begin{tikzpicture}\n\t\t{\\Tree [.$p\\land q\\to r$ [.$p$ ] [.$q\\to r$ [.$q$ ] [.$r$ ] ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t& \n\t\t\n\t\t\\qquad \\raisebox{7.5ex}{vs.} \\qquad \n\t\t\t\t\\begin{tikzpicture}\n\n\t\t{\\Tree [.$p\\land q\\to r$ [.$p\\land q$ [.$p$ ] [.$q$ ] ] [.$r$ ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t\\end{tabular}\n\t\t\\end{center}\nnow unambiguously, gets the second of the two readings. That is, $p\\land q\\to r$ is then simply read as $(p\\land q)\\to r$. This is the idea of \\emph{binding strength}: we say that $\\land$ \\emph{binds stronger} than $\\to$. This idea allows us to leave out a bunch of parentheses, which we can easily fill in by reading the right operator first. \n\n\t\\item The relative binding strength of the operators is given in the following diagram:\n\\[{\\neg}>{\\land}={\\lor}>{\\to}>{\\leftrightarrow}.\\] Explicitly, this means that, in a case of conflict, you always read the $\\leftrightarrow$ first, then $\\to$, then $\\lor$ and $\\land$, and only finally $\\neg$. Note that $\\land$ and $\\lor$ have precisely the same binding strength, so in expressions like $p\\land (q\\lor r)$, we really can't leave out any parentheses. But if we consider an expression like $((p\\land q)\\leftrightarrow (p\\leftrightarrow q))$, we can easily leave out a some:\n\t\\begin{itemize}\n\t\n\t\t\\item According to the first convention, we can leave out the outermost parentheses, yielding $(p\\land q)\\leftrightarrow (p\\leftrightarrow q)$.\n\t\t\n\t\t\\item Now, since we know that we'll always parse according to $\\leftrightarrow$ before $\\land$, this means that we can leave out the parentheses around the $\\land$, giving us $p\\land q\\leftrightarrow (p\\leftrightarrow q)$.\n\t\t\n\t\t\\item Can we also leave out the last pair of parentheses? ---No! For in $p\\land q\\leftrightarrow p\\leftrightarrow q$, there would be a conflict between two readings:\n\t\\begin{center}\n\t\t\n\t\t\\begin{tabular}{c c c}\n\t\t\\begin{tikzpicture}\n\t\t{\\Tree [.$p\\land q\\leftrightarrow p\\leftrightarrow q$ [.$p\\land q$ [.$p$ ] [.$q$ ] ] [.$p\\leftrightarrow q$ [.$p$ ] [.$q$ ] ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t& \n\t\t\n\t\t\\qquad \\raisebox{7.5ex}{vs.} \\qquad & \n\t\t\t\t\\begin{tikzpicture}\n\t\t{\\Tree [.$p\\land q\\leftrightarrow p\\leftrightarrow q$ [.$p\\land q\\leftrightarrow p$ [.$p\\land q$ [.$p$ ] [.$q$ ] ] [.$p$ ] ] [.$q$ ] ]}\n\t\t\\end{tikzpicture}\n\n\t\t\\end{tabular}\n\t\t\\end{center}\n\t\t\n\t\t\\item So, the best we can do is $p\\land q\\leftrightarrow (p\\leftrightarrow q)$.\n\t\n\t\\end{itemize}\n\t\n\t\\item These ideas need some getting used to. For that reason, there are plenty of exercises included at the end of this section (4.8.9 and 4.8.10), solutions for which can be found in the appendix.\n\t\n\t\\item We conclude with a last remark about conventional notation. You might wonder: Well, these are pretty clear conventions. Surely, a computer can learn them. Why can't we devise an official definition that has unique readability and respects these conventions? ---And you would be right! This \\emph{is} possible. It's just not very practical for most purposes. The official definition of a formula would thereby become much more complicated. This would have the consequence that proofs by induction and function recursion would become horribly complicated to carry out, too. Additionally, if we care about efficiency (as we often do with computers), it turns out to be way more efficient to use our official definition and to translate between official and conventional notation that to carry out everything in conventional notation. And you can essentially see why: because \\emph{every} recursive definition would become more complicated---and we need \\emph{a lot} of them. So, we'll stick to our official notation for official purposes and use conventional notation for fun. \n\n\t\\end{enumerate}\n\n\\section{Core Ideas}\n\n\\begin{itemize}\n\n\t\\item A formal language is defined by a vocabulary (symbols) and a grammar (rules for well-formed expressions).\n\t\n\t\\item The vocabulary of a propositional language consists of a set of sentence letters $\\mathcal{P}$, the sentential connectives $\\neg,\\land,\\lor,\\to,\\leftrightarrow$, and the parentheses $($ and $)$.\n\t\n\t\\item The set $\\mathcal{L}$ of formulas is inductively defined as the smallest set containing the sentence letters and which is closed under the sentential connectives. \n\t\n\t\\item Formalization is the process of abstracting ordinary language expressions into a propositional language. \\emph{Use the guidelines}.\n\t\n\t\\item Syntactic recursion works by specifying the value for the sentence letters and how to calculate the value for a complex formula from the values for its subformulas.\n\t\n\t\\item The parsing tree of a formula gives you its internal structure: it shows how the formula was constructed.\n\t\n\t\\item The unique readability theorem guarantees that syntactic recursion works and that formulas are computer readable. It states that every formula has a unique parsing tree.\n\t\n\t\\item There is a useful algorithm for checking whether an expression is a formula.\n\t\n\t\\item Outside of syntax theory, the notational conventions are useful. But use them with caution.\n\n\\end{itemize}\n\n\\section{Self Study Questions}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item Suppose that an expression contains absolutely no parentheses. What is the best we can say about the expression?\n\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\\item The expression is not a formula.\n\t\t\t\t\n\t\t\t\t\\item If the expression is a formula, then it is a sentence letter.\n\t\t\t\t\n\t\t\t\t\\item If the expression is a formula, then it cannot contain $\\land,\\lor,\\to,\\leftrightarrow$.\n\t\t\t\t\n\t\t\t\t\\item There is an even number of negations in the expression.\n\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\\item You're asked to determine whether an expression is a formula. In which order would you apply the following techniques?\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item Try to prove it definitionally (as in 4.1.9)\n\t\t\n\t\t\t\\item Check whether the expression contains symbols not from the vocabulary (using Proposition 4.2.5).\n\t\t\t\n\t\t\t\\item Apply the algorithm (4.3.10).\n\t\t\t\n\t\t\t\\item Check whether the expression contains as many $($'s as $)$'s (using the solution to exercise (4.8.8)).\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\\item Can you always see whether a formula is written in conventional notation?\n\t\n\t\\begin{enumerate}[(a)]\n\t\n\t\t\\item Yes, I simply construct the parsing tree for the expression.\n\t\t\n\t\t\\item No, because a formula written in notational convention does  not need to contain an even number of parentheses.\n\t\n\t\t\\item Yes, you can apply the algorithm (4.3.10) for that.\n\t\n\t\t\\item No, it needs to be clear from the context.\n\t\n\t\\end{enumerate}\n\t\n\t\\item A formula has complexity four. Which of the following can you infer from that?\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item The formula contains at least four connectives.\n\t\t\t\n\t\t\t\\item The formulas contains at most four connectives.\n\t\t\t\n\t\t\t\\item The formula contains at most four negations.\n\t\t\t\n\t\t\t\\item The parsing tree of the formula has at most four nodes.\n\n\t\t\t\\item The parsing tree of the formula has exactly four nodes.\n\t\t\t\n\t\t\t\\item The parsing tree of the formula has at least five nodes.\n\t\t\n\t\t\\end{enumerate}\n\n\t\\end{enumerate}\n\\section{Exercises}\n\n\n\t\\begin{enumerate}[\\thesection.1]\n\t\n\t\t\\item $[h]$ Translate the following statements into a suitable propositional language! Don't forget the translation key.\n\t\t\t\n\t\t\t\\begin{enumerate}\n\n\t\t\t\t\\item Alan Turing built the first computer but Ada Lovelace invented the first computer algorithm.\n\t\t\t\n\t\t\t\t\\item Only if Alan Turing built the first computer, it's Monday today.\n\t\t\t\n\t\t\t\t\\item Either Alan Turing or Ada Lovelace is your favorite computer scientist.\n\t\t\t\n\t\t\t\t\\item Today is Monday if and only if both yesterday was Tuesday and tomorrow is Saturday.\n\t\t\t\n\t\t\t\\end{enumerate}\n\n\t\t\\item $[h]$ Translate the following statements into English/Dutch. Use the following translation key: \n\t\t\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{c c l}\n\t\t\n\t\t\t $p$ & : & I'm happy/Ik ben blij\\\\[1ex]\n\t\t\t\n\t\t\t $q$ & : & I clap my hands/Ik klap in mijn handen\\\\[1ex]\n\t\t\t\n\t\t\t $r$ & : & You're happy/Jij bent blij\\\\[1ex]\n\t\t\t\n\t\t\t $s$ & : & You clap your hands/Jij klapt in je handen\\\\[1ex]\n\t\t\t\n\t\t\t $t$ & : & We both clap our hands/Wij klappen in onze handen\n\t\t\t \\end{tabular}\n\t\t\n\t\t\\end{center}\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $\\neg\\neg (p\\land q)$\n\t\t\n\t\t\t\\item $(\\neg p\\to \\neg q)$\n\t\t\t\n\t\t\t\\item $(p\\leftrightarrow (\\neg r\\land q))$\n\t\t\t\n\t\t\t\\item $((q\\land s)\\to t)$\n\t\t\n\t\t\t\\item $((q\\land s)\\to (p\\lor r))$\n\t\t\t\n\t\t\t\\item $(((p\\land q)\\lor (r\\land s))\\land \\neg ((p\\land q\\land r\\land s)))$\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item Give an inductive definition of the set of all formulas of $\\mathcal{L}$ that only contain $p,q,\\neg,\\land,(,$ and $)$.\n\t\t\n\t\t\\item Use the algorithm from 4.3.10 to decide whether the following expressions are formulas:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $(q\\leftrightarrow (p\\land (q\\lor (r\\land \\neg s)))$\n\t\t\n\t\t\t\n\t\t\t\\item $((p\\land q)\\lor (p\\land (q\\to\\neg q)))$\n\t\t\t\n\t\t\t\\item $(p\\to (p\\to ((p\\land p)\\leftrightarrow p\\lor p)))$\n\t\t\t\n\t\t\t\\item $\\neg\\neg (\\neg\\neg p\\land (q\\lor q) )$\n\t\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item Use function recursion to define the following syntactic functions:\n\t\t\n\t\t\\begin{enumerate}\n\t\t\n\t\t\t\\item $[h]$ the function $\\#_{conn}:\\mathcal{L}\\to\\mathbb{N}$, which counts the number of sentential connectives in a formula $\\phi$.\n\t\t\t\n\t\t\t\\item the function $\\#_(:\\mathcal{L}\\to\\mathbb{N}$, which counts the number of left brackets in a formula $\\phi$. \n\t\t\t\n\t\t\t\\item the function $\\#_{\\mathcal{P}}:\\mathcal{L}\\to\\mathbb{N}$, which counts the number of sentence letters in a formula $\\phi$.\n\t\t\t\n\t\t\t\\item the function $\\mathbf{1}_p:\\mathcal{L}\\to\\{0,1\\}$, which assigns one to a formula $\\phi$ if $p\\in sub(\\phi)$ and zero otherwise.\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item $[\\nosym]$ Consider the following recursively defined functions on $\\mathcal{L}$. What do they (in ordinary words) measure?\n\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item $f:\\mathcal{L}\\to\\mathbb{N}$ defined by:\n\t\t\t\t\n\t\t\t\t\t\\begin{enumerate}[(i)]\n\n\t\t\t\t\t\\item $f(p)=1,$ for $p\\in\\mathcal{P}$\n\n\t\t\t\t\t\\item \t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\t\\item $f(\\neg \\phi)=f(\\phi)+1,$\n\n\t\t\t\t\t\\item $f((\\phi\\circ \\psi))=f(\\phi)+f(\\psi)+3,$ for $\\circ=\\land,\\lor,\\to,\\leftrightarrow.$\n\t\t\t\t\t\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\t\t\n\t\t\t\t\\item $g:\\mathcal{L}\\to\\mathbb{N}$ defined by:\n\t\t\t\t\n\t\t\t\t\t\\begin{enumerate}[(i)]\n\n\t\t\t\t\t\\item $g(p)=0,$ for $p\\in\\mathcal{P}$\n\n\t\t\t\t\t\\item \t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\t\\item $g(\\neg \\phi)=g(\\phi)+1,$\n\n\t\t\t\t\t\\item $g((\\phi\\circ \\psi))=g(\\phi)+g(\\psi),$ for $\\circ=\\land,\\lor,\\to,\\leftrightarrow.$\n\t\t\t\t\t\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\t\t\n\t\t\t\t\t\\item (this is a tricky one) $h:\\mathcal{L}\\to\\{0,1\\}$ defined by:\n\t\t\t\t\n\t\t\t\t\t\\begin{enumerate}[(i)]\n\n\t\t\t\t\t\\item $h(p)=1,$ for $p\\in\\mathcal{P}$\n\n\t\t\t\t\t\\item \t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\t\\item $h(\\neg \\phi)=\\begin{cases}\n\t\t\t\t\t0 &\\text{if }h(\\phi)=1\\\\\n\t\t\t\t\t1 & \\text{if }h(\\phi)=0\n\t\t\t\t\t\\end{cases}$\n\n\t\t\t\t\t\\item $h((\\phi\\circ \\psi))=\\begin{cases}\n\t\t\t\t\t1&\\text{if }h(\\phi)=1\\text{ and }h(\\psi)=1\\\\\n\t\t\t\t\t1&\\text{if }h(\\phi)=0\\text{ and }h(\\psi)=0\\\\\n\t\t\t\t\t0 & \\text{otherwise}\n\t\t\t\t\t\\end{cases}$ \n\t\t\t\t\t\n\t\t\t\t\t\\item[] for $\\circ=\\land,\\lor,\\to,\\leftrightarrow.$\n\t\t\t\t\t\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\end{enumerate} \n\t\t\n\t\t\\item Use proof by induction to prove that the number of elements in $sub(\\phi)$ is at most $2\\cdot \\#_{conn}(\\phi)+1$.\n\n\t\t\\item $[h]$ Prove (using induction on formulas) that for each formula $\\phi\\in\\mathcal{L}$, the number of $($'s and the number of $)$'s is equal. Derive as a corollary a necessary condition for formula-hood and discuss why the condition is better than the one given in (4.2.4).\n\t\t\n\t\t\\item Translate the following formulas written using the notational conventions into official notation:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\n\t\t\\item  $\\neg p\\land q$\n\n\t\t\\item  $\\neg(p\\land q\\to \\neg p\\lor\\neg q)$\n\t\t\n\t\t\\item  $p\\lor p\\leftrightarrow \\neg p$\n\n\t\t\\item  $(p\\lor q)\\land r$\n\t\t\n\t\t\\item $p\\to p\\leftrightarrow p\\to p$\n\n\t\t\\item  $\\neg p \\land (q\\lor r\\to p\\leftrightarrow q)$\n\t\t\n\t\t\\item $p\\land (p\\lor q)$ \n\n\t\t\\item $p\\to q\\lor q\\leftrightarrow r$\n\n\t\t\\item $p\\to q\\leftrightarrow \\neg q\\to \\neg p$  \n\n\t\t\\item $\\neg\\neg\\neg p$\n\n\t\t\\item ${p} \\to {p} \\leftrightarrow {p}\\lor \\neg {p}$\n\n\t\t\\item $p\\lor q\\to \\neg r\\land (s\\leftrightarrow {p})$\n\n\t\t\\end{enumerate}\n\t\t\n\t\\item Take the following formulas and write them according to our notational conventions:\n\t\n\t\t\\begin{enumerate}\n\t\t\n\t\t\t\\item $(p\\land q)$\n\t\t\n\t\t\t\\item $\\neg\\neg q$\n\t\t\t\n\t\t\t\\item $(p\\land (r\\lor q))$\n\t\t\t\n\t\t\t\\item $(p\\to (r\\lor (p\\land (q\\leftrightarrow r))))$\n\t\t\t\n\t\t\t\\item $(p\\lor \\neg (p\\lor q))$\n\t\t\t\n\t\t\t\\item $((p\\land q)\\to r)$\n\t\t\t\n\t\t\t\\item $(((p\\lor q)\\to \\neg q)\\leftrightarrow r)$\n\t\t\t\n\t\t\t\\item $((p\\land q)\\land r)$\n\t\t\t\n\t\t\t\\item $(p\\land (q\\land r))$\n\t\t\t\n\t\t\t\\item $(p\\lor (q\\lor r))$\n\t\t\t\n\t\t\t\\item $(p\\land (q\\lor r))$\n\t\t\t\n\t\t\t\\item $(p\\land (q\\to r))$\n\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item (This is a real challenge, only try this is you have enough time and energy): Write an algorithm that translates a formula from conventional into official notation. \n\n\t\\end{enumerate}\n\n\\section{Further Readings}\n\nWe're starting to get into logic proper. Recommendations for further readings that I can give you at this point will be chapters from other logic books, which cover the same material but in slightly different way. Note, however, that if you look into another logic textbook, you will (most likely) encounter different ways of doing things. Here are just some examples of what I mean:\n\t\\begin{itemize}\n\t\n\t\t\\item Some authors use different terminology. For example, they may call sentence letters ``propositional variables'' or sentential connectives ``propositional connectives.''\n\t\t\n\t\t\\item Some authors may have different definitions of formulas. It's possible, for example, to demand that also negations are enclosed by parentheses, so that $\\neg p$ is not a formula only $(\\neg p)$ is.\n\t\n\t\t\\item Some authors use different symbols for the connectives, such as $\\supset$ instead of our $\\to$ or $\\equiv$ instead of our $\\leftrightarrow$. \n\t\t\n\t\t\\item Some authors use $A,B,C,\\mathellipsis$ for formulas, rather than our $\\phi,\\psi,\\theta,\\mathellipsis.$\n\t\t\n\t\t\\item Some authors might use proof by induction in a different (but equivalent) way. For example, they might use mathematical induction on the complexity of formulas instead of our method, which is known in the literature as \\emph{structural} induction.\n\t\t\n\t\t\\item Some authors may use terminology in a slightly different way. For example, complexity is sometimes defined so that it doesn't correspond to the height of the parsing tree but rather the number of logical connectives in the formula. \n\t\t\n\t\t\\item They might prove different theorems or the same theorems in different ways.\n\t\n\t\\end{itemize}\n\t\nThese are really just some of the possible differences you may encounter. If you continue with my literature recommendations, you have to brace yourself for that. But there are also some reasons for why it's a good idea to look at other texts despite these potential obstacles:\n\t\\begin{itemize}\n\t\n\t\t\\item Regardless of these differences, the books that I'm recommending are dealing with the same subject matter---just in a slightly different way. And this different perspective might help you understand better what's going on.\n\t\t\n\t\t\\item When you continue your studies, you will see that there are  many, many different notations or, more generally, ways of doing things around. This equally applies in logic, mathematics, computer science, and other related disciplines. The earlier you get used to the plurality, the better.\n\t\t\t\n\t\t\\item Other textbooks are a great source of additional exercises (though typically without solutions, as I mentioned in the lecture).\t\n\t\t\t\n\t\\end{itemize}\nSo, here are my recommendations for book-chapters that deal with the same material in comparable ways. \n\n\t\\begin{itemize}\n\t\n\t\t\\item Section 2.1 of Dalen, Dirk van. 2013. \\emph{Logic and Structure}. 5$^\\text{th}$ edition. London, UK: Springer.\n\t\t\n\t\t\\item Sections 1.0, 1.1 and 1.3 of Enderton, Herbert. 2001. \\emph{A Mathematical Introduction to Logic}. 2$^\\text{nd}$ edition. San Diego, CA: Harcourt/Academic Press.\n\t\t\n\t\t\\item The reader \\emph{Parvulae Logicales INDUCTIE} by Albert Visser, Piet Lemmens, and Vincent van Oostrom from the 2015 installment of the course. You can find this on blackboard.\n\t\n\t\\end{itemize}\nOne last thing: don't buy these books until you really feel like the book will help you a lot. Look at them in the library first (or online, if possible)!\n\n\n\\vfill\n\n\\hfill \\rotatebox[origin=c]{180}{\n\\fbox{\n\\begin{minipage}{0.5\\linewidth}\n\n\\subsection*{Self Study Solutions}\n\n\\emph{Some explanations in the appendix.}\n\n\\begin{enumerate}\n\n\t\\item[4.7.1] (c)\n\t\n\t\\item[4.7.2]  first (b), then (d), then (c), then (a)\n\t\n\t\\item[4.7.3] (d) \n\t\n\t\\item[4.7.4] (a), (f)\n\t\t\n\\end{enumerate}\n\n\n\\end{minipage}}}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"../../logic.tex\"\n%%% End:\n", "meta": {"hexsha": "14e15683231bc8873a8a7febd8f05388f4d07a3a", "size": 73308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lib/notes/tex/mainmatter/prop-language.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/mainmatter/prop-language.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/mainmatter/prop-language.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": 57.3615023474, "max_line_length": 1081, "alphanum_fraction": 0.6913297321, "num_tokens": 21717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6961820044198214}}
{"text": "\\chapter{Insertion Sort}\n\\label{chap:insertion}\n\\index{tri!$\\sim$ par insertions|(}\n\nIf we have a stack of totally ordered, distinct keys, it is easy to\ninsert one more key so the stack remains ordered by comparing it with\nthe first on top, then, if necessary, with the second, the third\netc. For example, inserting~\\(1\\) into \\([3,5]\\) requires\ncomparing~\\(1\\) with~\\(3\\) and results in \\([1,3,5]\\), without\nrelating~\\(1\\) to~\\(5\\). The algorithm called \\emph{insertion sort}\n\\citep{Knuth_1998}\\index{sorting|see{insertion sort}}\\index{insertion\n  sort} consists in inserting thusly keys one by one in a stack\noriginally empty. The playful analogy is that of sorting a hand in a\ncard game: each card, from left to right, is moved leftwards until it\nreaches its place.\n\n\\section{Straight insertion}\n\\label{sec:straight_ins}\n\\index{insertion sort!straight $\\sim$|(}\n\nLet~\\(\\fun{ins}(s,x)\\)\\index{ins@\\fun{ins/2}} (not to be confused with\nthe function of same name and arity in section~\\ref{sec:opt_sort}) be\nthe increasingly ordered stack resulting from the straight insertion\nof~\\(x\\) into the stack~\\(s\\). Function \\fun{ins/2} can be defined\nassuming a minimum and a maximum function,\n\\fun{min/2}\\index{min@\\fun{min/2}} and\n\\fun{max/2}\\index{max@\\fun{max/2}}:\n\\begin{equation*}\n\\fun{ins}(x,\\el)         \\rightarrow [x];\\qquad\n\\fun{ins}(x,\\cons{y}{s}) \\rightarrow\n   \\cons{\\fun{min}(x,y)}{\\fun{ins}(\\fun{max}(x,y),s)}.\n\\end{equation*}\nTemporarily, let us restrict ourselves to sorting natural numbers in\nincreasing order. We need to provide definitions to calculate the\nminimum and maximum:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n  \\fun{max}(0,y) & \\rightarrow & y; & \\fun{min}(0,y) & \\rightarrow & 0;\\\\\n  \\fun{max}(x,0) & \\rightarrow & x; & \\fun{min}(x,0) & \\rightarrow & 0;\\\\\n  \\fun{max}(x,y) & \\rightarrow & 1 + \\fun{max}(x-1,y-1).\n& \\fun{min}(x,y) & \\rightarrow & 1 + \\fun{min}(x-1,y-1).\n\\end{array}\n\\end{equation*}\nWhile this approach fits in our functional language, it is both\ninefficient and bulky, hence it is worth extending our language so\nrewrite rules are selected by pattern matching only if some optional\nassociated comparison holds. We can then\ndefine~\\fun{isrt/1}\\index{isrt@\\fun{isrt/1}|(} (\\emph{insertion sort})\nand redefine~\\fun{ins/2}\\index{ins@\\fun{ins/2}|(} as\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n  \\fun{ins}(\\cons{y}{s},x)\n& \\smashedrightarrow{\\kappa}\n& \\cons{y}{\\fun{ins}(s,x)}, \\,\\text{if \\(x \\succ y\\)};\n& \\fun{isrt}(\\el)\n& \\smashedrightarrow{\\mu}\n& \\el;\\\\\n  \\fun{ins}(s,x)\n& \\smashedrightarrow{\\lambda}\n& \\cons{x}{s}.\n& \\fun{isrt}(\\cons{x}{s})\n& \\smashedrightarrow{\\nu}\n& \\fun{ins}(\\fun{isrt}(s),x).\n\\end{array}\n\\end{equation*}\nLet us consider a short example in \\fig~\\vref{fig:isrt_312}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{isrt}([3,1,2])\n& \\xrightarrow{\\smash{\\nu}} & \\fun{ins}(\\fun{isrt}([1,2]),3)\\\\\n& \\xrightarrow{\\smash{\\nu}}\n& \\fun{ins}(\\fun{ins}(\\fun{isrt}([2]),1),3)\\\\\n& \\xrightarrow{\\smash{\\nu}}\n& \\fun{ins}(\\fun{ins}(\\fun{ins}(\\fun{isrt}(\\el),2),1),3)\\\\\n& \\xrightarrow{\\smash{\\mu}}\n& \\fun{ins}(\\fun{ins}(\\fun{ins}(\\el,2),1),3)\\\\\n& \\xrightarrow{\\smash{\\lambda}}\n& \\fun{ins}(\\fun{ins}([2],1),3)\\\\\n& \\xrightarrow{\\smash{\\lambda}}\n& \\fun{ins}([1,2],3)\\\\\n& \\xrightarrow{\\smash{\\kappa}}\n& [1|\\fun{ins}([2],3)]\\\\\n& \\xrightarrow{\\smash{\\kappa}}\n& [1,2|\\fun{ins}(\\el,3)]\\\\\n& \\xrightarrow{\\smash{\\lambda}}\n& [1,2,3].\n\\end{array}}\n\\end{equation*}\n\\caption{\\(\\fun{isrt}([3,1,2]) \\twoheadrightarrow [1,2,3]\\)\n\\label{fig:isrt_312}\\index{insertion sort!straight $\\sim$!example}}\n\\end{figure}\n\\index{isrt@\\fun{isrt/1}|)}\n\\index{ins@\\fun{ins/2}|)}\n\nLet \\(\\C{\\fun{isrt}}{n}\\)\\index{isrt@$\\C{\\fun{isrt}}{n}$|(} be the cost\nof sorting by straight insertion \\(n\\)~keys, and \\(\\C{\\fun{ins}}{i}\\)\nthe cost of inserting one key in a stack of length~\\(i\\). We directly\nderive from the functional program the following recurrences:\n\\begin{equation*}\n\\C{\\fun{isrt}}{0}   \\eqn{\\smash{\\mu}} 1;\\qquad\n\\C{\\fun{isrt}}{i+1} \\eqn{\\smash{\\nu}} 1 + \\C{\\fun{ins}}{i} +\n  \\C{\\fun{isrt}}{i}.\n\\end{equation*}\nThe latter equation assumes that the length of \\(\\fun{isrt}(s)\\) is\nthe same as~\\(s\\) and the length of \\(\\fun{ins}(s,x)\\) is the same as\n\\(\\cons{x}{s}\\). We deduce\n\\begin{equation}\n\\C{\\fun{isrt}}{n} = 1 + n + \\sum_{i=0}^{n-1}\\C{\\fun{ins}}{i}.\n\\label{eq:cost_isrt}\n\\end{equation}\nA look up at the definition of~\\fun{ins/2} reveals that\n\\(\\C{\\fun{ins}}{i}\\) cannot be expressed only in terms of~\\(i\\)\nbecause it depends on the relative order of all the keys. Instead, we\nresort to the minimum, maximum and average\ncosts.\\index{isrt@$\\C{\\fun{isrt}}{n}$|)}\n\n\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Minimum cost}\n\\index{insertion sort!straight $\\sim$!minimum cost}\n\nThe best case does not exert rule~\\(\\kappa\\), which is recursive,\nwhilst \\(\\lambda\\)~rewrites to a value. In other words, in\nrule~\\(\\nu\\), each key~\\(x\\) to be inserted in a non\\hyp{}empty,\nsorted stack \\(\\fun{isrt}(s)\\)\\index{isrt@\\fun{isrt/1}} would be lower\nthan or equal to the top of the stack. This rule also inserts the keys\nin reverse order:\n\\begin{equation}\n\\fun{isrt}([x_1,\\dots,x_n]) \\twoheadrightarrow\n\\fun{ins}(\\fun{ins}(\\dots(\\fun{ins}(\\el,x_n)\\dots),x_2),x_1).\n\\label{inv_isrt}\n\\end{equation}\nAs a consequence, \\emph{the minimum cost results from the input stack\n  being already increasingly sorted,} that is, the keys in the result\nare increasing, but may be repeated. Then \\(\\B{\\fun{ins}}{n} =\n\\len{\\lambda} = 1\\)\\index{ins@$\\B{\\fun{ins}}{n}$} and\n  equation~\\eqref{eq:cost_isrt} implies that straight insertion sort\n  has a linear cost in the best case:\n\\begin{equation*}\n\\B{\\fun{isrt}}{n} = 2n+1 \\sim 2n.\n\\end{equation*}\n\n\\paragraph{Maximum cost}\n\\index{insertion sort!straight $\\sim$!maximum cost}\n\nThe worst case must exert rule~\\(\\kappa\\) as much as possible, which\nimplies that \\emph{the worst case happens when the input is a stack\n  decreasingly sorted}. We have\\index{ins@$\\W{\\fun{ins}}{n}$|(}\n\\begin{equation*}\n\\W{\\fun{ins}}{n} = \\len{\\kappa^n\\lambda} = n + 1.\n\\end{equation*}\nSubstituting maximum costs in equation~\\eqref{eq:cost_isrt} then\nimplies that straight insertion sort has a quadratic cost in the worst\ncase:\n\\begin{equation*}\n\\W{\\fun{isrt}}{n} = \\frac{1}{2}{n^2} + \\frac{3}{2}{n} + 1\n\\sim \\frac{1}{2}{n^2}.\n\\end{equation*}\nAnother way is to take the length of the longest trace:\n\\begin{equation*}\n\\W{\\fun{isrt}}{n}\n = \\left\\lvert\\nu^n\\mu \\prod_{i=0}^{n-1}\\kappa^i\\lambda\\right\\rvert\n = \\len{\\nu^n\\mu} + \\sum_{i=0}^{n-1}\\len{\\kappa^i\\lambda}\n = \\frac{1}{2}{n^2} + \\frac{3}{2}{n} + 1.\n\\end{equation*}\nThis cost should not be surprising because\n\\fun{isrt/1}\\index{isrt@\\fun{isrt/1}} and\n\\fun{rev\\(_0\\)/1}\\index{rev0@\\fun{rev\\(_0\\)/1}}, in\nsection~\\ref{sec:reversal}, yield the same kind of partial rewrite, as\nseen by comparing~\\eqref{inv_isrt}, \\vpageref{inv_isrt},\nand~\\eqref{eq:rev0} \\vpageref{eq:rev0}, and also \\(\\C{\\fun{cat}}{n} =\n\\W{\\fun{ins}}{n}\\),\\index{cat@$\\C{\\fun{cat}}{n}$}\\index{ins@$\\W{\\fun{ins}}{n}$}\nwhere \\(n\\)~is the size of their first argument. Hence\n\\(\\W{\\fun{isrt}}{n} = \\W{\\fun{rev}_0}{n}\\).\n\\index{rev0@$\\W{\\fun{rev}_0}{n}$}\\index{ins@$\\W{\\fun{ins}}{n}$|)}\n\\index{isrt@$\\W{\\fun{isrt}}{n}$}\n\n\\paragraph{Average cost}\n\\label{par:ave_isrt}\n\\index{insertion sort!straight $\\sim$!average cost}\n\nThe average cost obeys equation~\\eqref{eq:cost_isrt} because all\npermutations \\((x_1,\\dots,x_n)\\) are equally likely, hence\n\\begin{equation}\n\\M{\\fun{isrt}}{n} = 1 + n + \\sum_{i=0}^{n-1}\\M{\\fun{ins}}{i}.\n\\label{eq:mean_isrt}\n\\end{equation}\nWithout loss of generality,\n\\(\\M{\\fun{ins}}{i}\\)\\index{ins@$\\M{\\fun{ins}}{n}$|(} is the cost of\ninserting the key \\(i+1\\) into all permutations of \\((1,\\dots,i)\\),\ndivided by \\(i+1\\). (This is how the set of\npermutations\\index{permutation} of a given length is inductively built\non page~\\pageref{par:permutations}.)  The partial\nevaluation~\\eqref{inv_isrt}\\index{functional\n  language!evaluation!partial $\\sim$} on page~\\pageref{inv_isrt} has\nlength \\(\\len{\\nu^n\\mu}=n+1\\). The trace for inserting in an empty\nstack is~\\(\\mu\\). If the stack has length~\\(i\\), inserting on top has\ntrace~\\(\\lambda\\); just after the first key, \\(\\kappa\\lambda\\)\netc. until after the last key, \\(\\kappa^i\\lambda\\). Therefore, the\naverage cost for inserting one key is, for \\(i \\geqslant 0\\),\n\\begin{equation}\n\\M{\\fun{ins}}{i} = \\frac{1}{i+1}\\sum_{j=0}^{i}\\len{\\kappa^j\\lambda}\n                 = \\frac{i}{2}+1.\n\\label{eq:ins}\n\\end{equation}\nThe average cost for inserting \\(n\\)~keys in an empty stack is\ntherefore \\(\\sum_{i=0}^{n-1}\\M{\\fun{ins}}{i} = \\frac{1}{4}n^2 +\n\\frac{3}{4}n\\). Finally, from equation~\\eqref{eq:mean_isrt}, the\naverage cost of sorting \\(n\\)~keys by straight insertion is\n\\begin{equation*}\n\\M{\\fun{isrt}}{n} = \\frac{1}{4}n^2 + \\frac{7}{4}n + 1.\n\\end{equation*}\n\\index{ins@$\\M{\\fun{ins}}{n}$|)}\n\n\\paragraph{Assessment}\n\\index{permutation!inversion|(}\n\\index{insertion sort!inversion|see{permutation}}\n\nDespite the average cost being asymptotically equivalent to~\\(50\\%\\)\nof the maximum cost, it is nevertheless quadratic. On a positive note,\nstraight insertion is quite efficient when the data is short or nearly\nsorted \\citep{CookKim_1980}. It is a typical example of an\n\\emph{adaptive sorting algorithm}\n\\citep{EstivillWood_1992,MoffatPetersson_1992}\\index{insertion\n  sort!adaptive}. The natural measure of sortedness for insertion sort\nis the number of inversions. Indeed, the partial\nevaluation~\\eqref{inv_isrt}, \\vpageref{inv_isrt} shows that the keys\nare inserted in reverse order. Thus, in rule~\\(\\kappa\\), we know that\nthe key \\(x\\)~was originally before~\\(y\\), but \\(x \\succ\ny\\). Therefore, one application of \\emph{rule~\\(\\kappa\\) removes one\n  inversion from the input.} As a corollary, the average number of\ninversions in a random permutation of \\(n\\)~objects is\n\\begin{equation*}\n\\belowdisplayskip=-4pt\n\\sum_{j=0}^{n-1}\\frac{1}{j+1}\\sum_{i=0}^{j}\\len{\\kappa^i} =\n\\frac{n(n-1)}{4}.\n\\end{equation*}\n\\index{permutation!inversion|)}\n\n\\paragraph{Exercises}\n\\begin{enumerate*}\n\n  \\item A sorting algorithm that preserves the relative order of equal\n    keys is said \\emph{stable}. Is\n    \\fun{isrt/1}\\index{isrt@\\fun{isrt/1}} stable?\n\n  \\item Prove \\(\\fun{len}(\\cons{x}{s}) \\equiv\n    \\fun{len}(\\fun{ins}(x,s))\\).\\index{len@\\fun{len/1}}\n\n  \\item Prove \\(\\fun{len}(s) \\equiv \\fun{len}(\\fun{isrt}(s))\\).\n\n  \\item Traditionally, textbooks about the analysis of algorithms\n    assess the cost of sorting procedures by counting the comparisons,\n    not the function calls. Doing so allows one to compare with the\n    same measure different sorting algorithms as long as they perform\n    comparisons, even if they are implemented in different programming\n    languages. (There are sorting techniques that do not rely on\n    comparisons.) Let\n    \\(\\OB{\\fun{isrt}}{n}\\)\\index{isrt@$\\OB{\\fun{isrt}}{n}$},\n    \\(\\OW{\\fun{isrt}}{n}\\)\\index{isrt@$\\OW{\\fun{isrt}}{n}$} and\n    \\(\\OM{\\fun{isrt}}{n}\\)\\index{isrt@$\\OM{\\fun{isrt}}{n}$} be the\n    minimum, maximum and average numbers of comparisons needed to sort\n    by straight insertion a stack of length~\\(n\\). Establish that\n    \\begin{equation*}\n      \\OB{\\fun{isrt}}{n} = n - 1; \\quad\n      \\OW{\\fun{isrt}}{n} = \\frac{1}{2}n(n - 1); \\quad\n      \\OM{\\fun{isrt}}{n} = \\frac{1}{4}n^2 + \\frac{3}{4}n - H_n,\n    \\end{equation*}\n    where \\(H_n := \\sum_{k=1}^n{1/k}\\) is the \\(n\\)th \\emph{harmonic\n      number}\\index{harmonic@$H_n$|see{harmonic\n        number}}\\index{harmonic number} and, by convention, \\(H_0 :=\n    0\\). \\emph{Hint:} the use of rule~\\(\\lambda\\) implies a comparison\n    if, and only if, \\(s\\)~is not empty.\n\n\\end{enumerate*}\n\n\\addcontentsline{toc}{subsection}{Soundness}\n\\paragraph{Ordered stacks}\n\nAs we did for the proof of the soundness\\index{insertion\n  sort!soundness|(} of \\fun{cut/2}\\index{cut@\\fun{cut/2}}\n\\vpageref{par:cut_sound}, we need to express the characteristic\nproperties we expect on the output of \\fun{isrt/1}, and relate them to\nsome assumptions on the input, first informally, then formally. We\nwould say that `The stack \\(\\fun{isrt}(s)\\)\\index{isrt@\\fun{isrt/1}}\nis totally, increasingly ordered and contains all the keys in~\\(s\\),\nbut no more.'  This captures all what is expected from any sorting\nprogram.\n\nLet us name \\(\\pred{Ord}{s}\\)\\index{Ord@\\predName{Ord}|(} the\nproposition `The stack~\\(s\\) is sorted increasingly.' To define\nformally this concept, let us use \\emph{inductive logic\n  definitions}\\index{induction!definition by $\\sim$}. We employed this\ntechnique to formally define stacks, on page~\\pageref{def:stack}, in a\nway that generates a simple well\\hyp{}founded order used by structural\ninduction, to wit, \\(\\cons{x}{s} \\succ x\\) and \\(\\cons{x}{s} \\succ\ns\\). Here, we similarly propose that, for \\(\\pred{Ord}{s}\\) to hold,\n\\(\\pred{Ord}{t}\\) must hold with~\\(s \\succ t\\). We defined \\fun{cut/2}\nin section~\\ref{sec:cutting}, \\vpageref{sec:cutting}, using the same\ntechnique and relying on inference rules. All three cases, namely,\ndata structure, proposition and function, are instances of inductive\ndefinitions. Let us constructively define \\(\\predName{Ord}\\) by the\naxioms \\(\\TirName{Ord}_0\\) and \\(\\TirName{Ord}_1\\), and the inference\nrule \\(\\TirName{Ord}_2\\):\\label{def:Ord}\n\\begin{mathpar}\n\\inferrule*{}{\\pred{Ord}{\\el}}\n\\;\\TirName{Ord}_0\n\\qquad\n\\inferrule*{}{\\pred{Ord}{[x]}}\n\\;\\TirName{Ord}_1\n\\qquad\n\\inferrule\n  {x \\prec y \\and \\pred{Ord}{\\cons{y}{s}}}\n  {\\pred{Ord}{\\cons{x,y}{s}}}\n\\,\\TirName{Ord}_2\n\\end{mathpar}\nNote that this system is parameterised by the well\\hyp{}founded order\n(\\(\\prec\\)) on the keys such that \\(x \\prec y :\\Leftrightarrow y \\succ\nx\\). Rule \\(\\TirName{Ord}_2\\) could equivalently be \\((x \\prec y\n\\mathrel{\\wedge} \\pred{Ord}{\\cons{y}{s}}) \\Rightarrow\n\\pred{Ord}{\\cons{x,y}{s}}\\) or \\(x \\prec y \\Rightarrow\n(\\pred{Ord}{\\cons{y}{s}} \\Rightarrow \\pred{Ord}{\\cons{x,y}{s}})\\) or\n\\(x \\prec y \\Rightarrow \\pred{Ord}{\\cons{y}{s}} \\Rightarrow\n\\pred{Ord}{\\cons{x,y}{s}}\\). Because the set of ordered stacks is\nexactly generated by this system, if the statement\n\\(\\pred{Ord}{\\cons{x,y}{s}}\\) holds, then, necessarily,\n\\(\\TirName{Ord}_2\\) has been used to produce it, hence \\(x \\prec y\\)\nand \\(\\pred{Ord}{\\cons{y}{s}}\\) are true as well. This usage of an\ninductive definition is called an \\emph{inversion\n  lemma}\\index{induction!inversion lemma} and can be understood as\ninferring necessary conditions for a putative formula, or as\n\\emph{case analysis on inductive definitions}.\\index{Ord@\\predName{Ord}|)}\n\n\n\\paragraph{Equivalent stacks}\n\\index{stack!equivalence}\n\nThe second part of our informal definition above was: `The stack\n\\(\\fun{isrt}(s)\\)\\index{isrt@\\fun{isrt/1}} contains all the keys\nin~\\(s\\), but no more.'  In order to provide a general criterion\nmatching this concept, we should abstract it as: `The stack~\\(s\\)\ncontains all the keys in the stack~\\(t\\), but no more.' Permutations\nallow us to clarify the meaning with a mathematical phrasing: `Stacks\n\\(s\\)~and~\\(t\\) are permutations of each other,' which we note \\(s\n\\approx t\\) and \\(t \\approx s\\). Since the role of~\\(s\\) do not differ\nin any way from that of~\\(t\\), we expect the relation \\((\\approx)\\) to\nbe symmetric: \\(s \\approx t \\Rightarrow t \\approx s\\). Moreover, we\nexpect it to be \\emph{transitive} as well: \\(s \\approx u\\) and \\(u\n\\approx t\\) imply \\(s \\approx t\\). Also, we want (\\(\\approx\\)) to be\n\\emph{reflexive}, that is, \\(s \\approx s\\). By definition, a binary\nrelation which is reflexive, symmetric and transitive is an\n\\emph{equivalence relation}\\index{equivalence!$\\sim$ relation}.\n\nThe relation (\\(\\approx\\)) can be defined in different ways. The idea\nhere consists in defining a permutation as a series of\n\\emph{transpositions}\\index{transposition}, namely, exchanges of\nadjacent keys. This approach is likely to work here because insertion\ncan be thought of as adding a key on top of a stack and then\nperforming a series of transpositions until the total order is\nrestored.\n\\begin{mathpar}\n\\inferrule*{}{\\el \\approx \\el}\n\\;\\TirName{Pnil}\n\\qquad\n\\inferrule*{}{\\cons{x,y}{s} \\approx \\cons{y,x}{s}}\n\\;\\TirName{Swap}\\\\\n\\inferrule\n  {s \\approx t}\n  {\\cons{x}{s} \\approx \\cons{x}{t}}\n\\,\\TirName{Push}\n\\qquad\n\\inferrule\n  {s \\approx u \\and u \\approx t}\n  {s \\approx t}\n\\,\\TirName{Trans}\n\\end{mathpar}\nWe recognise \\TirName{Pnil} and \\TirName{Swap} as axioms, the latter\nbeing synonymous with transposition. Rule \\TirName{Trans} is\ntransitivity and offers an example with two premises, so a derivation\nusing it becomes a \\emph{binary tree}\\index{tree!binary\n  $\\sim$|see{binary tree}}\\index{binary tree}, as shown in\n\\fig~\\vref{fig:proof_trees}.\n\\begin{figure}\n\\centering\n\\subfloat[Extended tree\\label{fig:perm_proof}]{\n  \\includegraphics[bb=135 672 369 723]{proof}}\n\\qquad\n\\subfloat[Pruned tree\\label{fig:312eq231}]{\n  \\includegraphics[bb=70 670 131 723]{312eq231}}\n\\caption{Proof tree of \\({[}3,1,2{]} \\protect\\approx {[}2,3,1{]}\\)\n\\label{fig:proof_trees}}\n\\end{figure}\nAs an exception to the convention about tree layouts, proof\ntrees\\index{tree!proof $\\sim$} have their root at the bottom of the\nfigure.\n\nWe must now prove the \\emph{reflexivity} of~\\((\\approx)\\),\nnamely\\index{Refl@\\predName{Refl}|(} \\(\\pred{Refl}{s} \\colon s \\approx\ns\\), by induction\\index{induction!example|(} on the structure of the\nproof. The difference with the proof of the soundness of\n\\fun{cut/2}\\index{cut@\\fun{cut/2}}, \\vpageref{par:cut_sound}, is that,\ndue to \\TirName{Trans} having two premises, the induction hypothesis\napplies to both of them. Also, the theorem is not explicitly an\nimplication. First, we start by proving \\predName{Refl} on the axioms\n(the leaves of the proof trees) and proceed with the induction on the\nproper inference rules, to wit, reflexivity is conserved while moving\ntowards the root of the proof tree.\n\\begin{itemize}\n\n  \\item Axiom \\TirName{Pnil} proves \\(\\pred{Refl}{\\el}\\).\n    Axiom~\\TirName{Swap} proves \\(\\pred{Refl}{\\cons{x,x}{s}}\\).\n\n  \\item Let us assume now that \\predName{Refl}~holds for the premise\n    in \\TirName{Push}, namely, \\(s = t\\). Clearly, the conclusion\n    implies \\(\\pred{Refl}{\\cons{x}{s}}\\).\n\n  \\item Let us assume that \\predName{Refl}~holds for the \\emph{two}\n    antecedents in \\TirName{Push}, that is, \\(s=u=t\\). The conclusion\n    leads to\n    \\(\\pred{Refl}{s}\\)\\index{Refl@\\predName{Refl}|)}.\\hfill\\(\\Box\\)\n\n\\end{itemize}\n\nLet us prove the \\emph{symmetry} of~\\((\\approx)\\) using the same\ntechnique. Let\\index{Sym@\\predName{Sym}} \\(\\pred{Sym}{s,t}\\colon s\n\\approx t \\Rightarrow t \\approx s\\). We deal with an implication here,\nso let us suppose that \\(s \\approx t\\), that is, we have a proof\ntree~\\(\\Delta\\) whose root is \\(s \\approx t\\), and let us establish\n\\(t \\approx s\\). In the following, we overline variables from the\ninference system.\n\\begin{itemize}\n\n  \\item If \\(\\Delta\\) ends with \\TirName{Pnil}, then \\(\\el = s = t\\),\n    which trivially implies \\(t \\approx s\\).\n\n  \\item If \\(\\Delta\\) ends with \\TirName{Swap}, then\n    \\(\\cons{\\overline{x},\\overline{y}}{\\overline{s}} = s\\) and\n    \\(\\cons{\\overline{y},\\overline{x}}{\\overline{s}} = t\\), so \\(t\n    \\approx s\\).\n\n  \\item If \\(\\Delta\\) ends with \\TirName{Push}, then\n    \\(\\cons{\\overline{x}}{\\overline{s}} = s\\) and\n    \\(\\cons{\\overline{x}}{\\overline{t}} = t\\). The induction\n    hypothesis applies to the premise, \\(\\overline{s} \\approx\n    \\overline{t}\\), hence \\(\\overline{t} \\approx \\overline{s}\\)\n    holds. An application of \\TirName{Push} with the latter premise\n    implies \\(\\cons{\\overline{x}}{\\overline{t}} \\approx\n    \\cons{\\overline{x}}{\\overline{s}}\\), that is, \\(t \\approx s\\).\n\n  \\item If \\(\\Delta\\) ends with \\TirName{Trans}, then the induction\n    hypothesis applies to its prem\\-ises and we deduce \\(u \\approx s\\)\n    and \\(t \\approx u\\), which can be premises for \\TirName{Trans}\n    itself and lead to \\(t \\approx s\\).\\hfill\\(\\Box\\)\n\n\\end{itemize}\n\n\\paragraph{Soundness}\n\nLet us now turn our attention to our main objective, which we may call\n\\(\\pred{Isrt}{s}\\colon \\pred{Ord}{\\fun{isrt}(s)} \\mathrel{\\wedge}\n\\fun{isrt}(s) \\approx s\\).\\index{Isrt@\\predName{Isrt}} Let us tackle\nits proof by structural induction on~\\(s\\).\n\\begin{itemize}\n\n  \\item The basis is~\\(\\pred{Isrt}{\\el}\\) and it is showed to hold\n    twofold. First, we have \\(\\fun{isrt}(\\el)\n    \\xrightarrow{\\smash{\\mu}} \\el\\) and \\(\\pred{Ord}{\\el}\\) is axiom\n    \\(\\TirName{Ord}_0\\). The other conjunct holds as well since\n    \\(\\fun{isrt}(\\el) \\approx \\el \\Leftrightarrow \\el \\approx \\el\\),\n    which is axiom \\TirName{Pnil}.\n\n  \\item Let us assume \\(\\pred{Isrt}{s}\\) and establish\n    \\(\\pred{Isrt}{\\cons{x}{s}}\\). In other words, let us assume\n    \\(\\pred{Ord}{\\fun{isrt}(s)}\\) and \\(\\fun{isrt}(s) \\approx s\\). We\n    have\n    \\begin{equation}\n      \\fun{isrt}(\\cons{x}{s}) \\xrightarrow{\\smash{\\nu}}\n      \\fun{ins}(\\fun{isrt}(s),x).\\label{eq:B}\n    \\end{equation}\n    Since we want \\(\\pred{Ord}{\\fun{isrt}(\\cons{x}{s})}\\), assuming\n    \\(\\pred{Ord}{\\fun{isrt}(s)}\\), we realise that we need the lemma\n    \\(\\pred{Ord}{s} \\Rightarrow \\pred{Ord}{\\fun{ins}(s,x)}\\), which we\n    may name \\(\\pred{InsOrd}{s}\\)\\index{InsOrd@\\predName{InsOrd}}. To\n    prove the conjunct \\(\\fun{isrt}(\\cons{x}{s}) \\approx\n    \\cons{x}{s}\\), assuming \\(\\fun{isrt}(s) \\approx s\\), we need the\n    lemma \\(\\pred{InsCmp}{s} \\colon \\fun{ins}(s,x) \\approx\n    \\cons{x}{s}\\). In particular, \\(\\pred{InsCmp}{\\fun{isrt}(s)}\\) is\n    \\(\\fun{ins}(\\fun{isrt}(s),x) \\approx \\cons{x}{\\fun{isrt}(s)}\\). We\n    have\n    \\begin{itemize*}\n\n      \\item Rule \\TirName{Push} and the induction hypothesis\n        \\(\\fun{isrt}(s) \\approx s\\) imply \\(\\cons{x}{\\fun{isrt}(s)}\n        \\approx \\cons{x}{s}\\).\n\n      \\item By the transitivity of~\\((\\approx)\\), we draw\n        \\(\\fun{ins}(\\fun{isrt}(s),x) \\approx \\cons{x}{s}\\),\n\n      \\item by rewrite~\\eqref{eq:B}, \\(\\fun{isrt}(\\cons{x}{s})\n        \\approx \\cons{x}{s}\\) and \\(\\pred{Isrt}{\\cons{x}{s}}\\)\n        follow.\n\n    \\end{itemize*}\n    By the induction principle, we conclude \\(\\forall s \\in\n    S.\\pred{Isrt}{s}\\).\\hfill\\(\\Box\\)\n\n\\end{itemize}\n\n\\paragraph{Insertion adds a key}\n\nTo complete the previous proof, we prove the\nlemma\\index{InsCmp@\\predName{InsCmp}} \\(\\pred{InsCmp}{s} \\colon\n\\fun{ins}(s,x) \\approx \\cons{x}{s}\\) by structural induction on~\\(s\\).\n\\begin{itemize*}\n\n  \\item The basis \\(\\pred{InsCmp}{\\el}\\) stands because\n    \\(\\fun{ins}(\\el,x) \\xrightarrow{\\smash{\\lambda}} [x] \\approx\n          [x]\\), by composing rules \\TirName{Pnil} and \\TirName{Push}.\n\n  \\item Let us assume \\(\\pred{InsCmp}{s}\\) and deduce\n    \\(\\pred{InsCmp}{\\cons{y}{s}}\\), that is,\n    \\begin{equation*}\n      \\fun{ins}(s,x) \\approx \\cons{x}{s} \\Rightarrow\n      \\fun{ins}(\\cons{y}{s},x) \\approx \\cons{x,y}{s}.\n    \\end{equation*}\n    There are two cases to analyse.\n    \\begin{itemize*}\n\n    \\item If \\(y \\succ x\\), then \\(\\fun{ins}(\\cons{y}{s},x)\n      \\xrightarrow{\\smash{\\lambda}} \\cons{x,y}{s} \\approx\n      \\cons{x,y}{s}\\), by rule~\\TirName{Swap}.\n\n    \\item Otherwise, \\(x \\succ y\\) and \\(\\fun{ins}(\\cons{y}{s},x)\n      \\xrightarrow{\\smash{\\kappa}} \\cons{y}{\\fun{ins}(s,x)}\\).\n      \\begin{itemize*}\n\n        \\item We deduce \\(\\cons{y}{\\fun{ins}(s,x)} \\approx\n          \\cons{y,x}{s}\\) by using the induction hypothesis as the\n          premise of rule \\TirName{Push}.\n\n        \\item Furthermore, \\TirName{Swap}~yields \\(\\cons{y,x}{s}\n          \\approx \\cons{x,y}{s}\\).\n\n        \\item Transitivity of~\\((\\approx)\\) applied to the two last\n          statements leads to \\(\\fun{ins}(\\cons{y}{s},x) \\approx\n          \\cons{x,y}{s}\\).\n\n      \\end{itemize*}\n      Note that we do not need to assume that \\(s\\)~is sorted: what\n      matters here is that \\(\\fun{ins/2}\\) loses no key it inserts,\n      but misplacement is irrelevant.\\hfill\\(\\Box\\)\n\n    \\end{itemize*}\n\n\\end{itemize*}\n\n\n\\paragraph{Insertion preserves order}\n\nTo complete the soundness proof, we must prove the\nlemma~\\(\\pred{InsOrd}{s} \\colon \\pred{Ord}{s} \\Rightarrow\n\\pred{Ord}{\\fun{ins}(s,x)}\\) by induction on the\nstructure\\index{induction!example} of~\\(s\\), meaning that insertion\npreserves order.\n\n\\begin{itemize*}\n\n  \\item The basis \\(\\pred{InsOrd}{\\el}\\) is easy to check:\n    \\(\\TirName{Ord}_0\\)~states \\(\\pred{Ord}{\\el}\\); we have the\n    rewrite \\(\\fun{ins}(\\el,x) \\xrightarrow{\\smash{\\lambda}} [x]\\) and\n    \\(\\TirName{Ord}_1\\)~is \\(\\pred{Ord}{[x]}\\).\n\n  \\item Let us prove \\(\\pred{InsOrd}{s} \\Rightarrow\n    \\pred{InsOrd}{\\cons{x}{s}}\\) by assuming\n    \\begin{equation*}\n      (H_0) \\;\\; \\pred{Ord}{s},\\qquad\n      (H_1) \\;\\; \\pred{Ord}{\\fun{ins}(s,x)},\\qquad\n      (H_2) \\;\\; \\pred{Ord}{\\cons{y}{s}},\n    \\end{equation*}\n    and deriving \\(\\pred{Ord}{\\fun{ins}(\\cons{y}{s},x)}\\).\n\n    \\noindent Two cases arise from comparing \\(x\\)~to~\\(y\\):\n    \\begin{itemize*}\n\n      \\item If \\(y \\succ x\\), then \\(H_2\\)~implies\n        \\(\\pred{Ord}{\\cons{x,y}{s}}\\), by rule\n        \\(\\TirName{Ord}_2\\). Since \\(\\fun{ins}(\\cons{y}{s},x)\n        \\xrightarrow{\\smash{\\lambda}} \\cons{x,y}{s}\\), we have\n        \\(\\pred{Ord}{\\fun{ins}(\\cons{y}{s},x)}\\).\n\n      \\item Otherwise, \\(x \\succ y\\) and we derive\n        \\begin{equation}\n          \\fun{ins}(\\cons{y}{s},x) \\xrightarrow{\\smash{\\kappa}}\n          \\cons{y}{\\fun{ins}(s,x)}.\\label{eq:A}\n        \\end{equation}\n        Here, things get more complicated because we need to consider\n        the structure of~\\(s\\).\n        \\begin{itemize*}\n\n        \\item If \\(s=\\el\\), then \\(\\cons{y}{\\fun{ins}(s,x)}\n          \\xrightarrow{\\smash{\\lambda}} [y,x]\\). Furthermore, \\(x\n          \\succ y\\), \\(\\TirName{Ord}_1\\) and \\(\\TirName{Ord}_2\\) imply\n          \\(\\pred{Ord}{[y,x]}\\), so\n          \\(\\pred{Ord}{\\fun{ins}(\\cons{y}{s},x)}\\).\n\n          \\item Else, there exists a key~\\(z\\) and a stack~\\(t\\) such\n            that \\(s = \\cons{z}{t}\\).\n            \\begin{itemize*}\n\n              \\item If \\(z \\succ x\\), then\n                \\begin{equation}\n                  \\cons{y}{\\fun{ins}(s,x)} =\n                  \\cons{y}{\\fun{ins}(\\cons{z}{t},x)}\n                  \\xrightarrow{\\smash{\\lambda}} \\cons{y,x,z}{t} =\\!\n                  \\cons{y,x}{s}.\\label{eq:C}\n                \\end{equation}\n                \\(H_0\\)~is \\(\\pred{Ord}{\\cons{z}{t}}\\), which, with\n                \\(z \\succ x\\) and rule \\(\\TirName{Ord}_2\\), implies\n                \\(\\pred{Ord}{\\cons{x,z}{t}}\\). Since~\\(x \\succ\\! y\\),\n                another application of~\\(\\TirName{Ord}_2\\) yields\n                \\(\\pred{Ord}{\\cons{y,x,z}{t}}\\), that is,\n                \\(\\pred{Ord}{\\cons{y,x}{s}}\\). This and\n                rewrite~\\eqref{eq:C} entail that\n                \\(\\pred{Ord}{\\cons{y}{\\fun{ins}(s,x)}}\\). Finally, due\n                to rewrite~\\eqref{eq:A},\n                \\(\\pred{Ord}{\\fun{ins}(\\cons{y}{s},x)}\\) holds.\n\n              \\item The last remaining case to examine is when~\\(x\n                \\succ z\\):\n                \\begin{equation}\n                  \\cons{y}{\\fun{ins}(s,x)} \\!=\\!\n                  \\cons{y}{\\fun{ins}(\\cons{z}{t},x)}\n                  \\!\\xrightarrow{\\smash{\\kappa}}\\!\n                  \\cons{y,z}{\\fun{ins}(t,x)}.\\label{eq:D}\n                \\end{equation}\n                Hypothesis~\\(H_2\\) is \\(\\pred{Ord}{\\cons{y,z}{t}}\\),\n                which, by means of the inversion lemma of\n                rule~\\(\\TirName{Ord}_2\\), leads to~\\(y \\succ z\\). By\n                the last rewrite, hypothesis~\\(H_1\\) is equivalent to\n                \\(\\pred{Ord}{\\cons{z}{\\fun{ins}(t,x)}}\\), which,\n                with~\\(y \\succ z\\), enables the use of\n                rule~\\(\\TirName{Ord}_2\\) again, leading to\n                \\(\\pred{Ord}{\\cons{y,z}{\\fun{ins}(t,x)}}\\).\n                Rewrite~\\eqref{eq:D} then yields\n                \\(\\pred{Ord}{\\cons{y}{\\fun{ins}(s,x)}}\\), which,\n                together with rewrite~\\eqref{eq:A} yields\n                \\(\\pred{Ord}{\\fun{ins}(\\cons{y}{s},x)}\\).\\index{induction!example|)}\\hfill\\(\\Box\\)\n\n      \\end{itemize*}\n    \\end{itemize*}\n  \\end{itemize*}\n\\end{itemize*}\n\n\\paragraph{Assessment}\n\nPerhaps the most striking feature of the soundness proof is its\nlength. More precisely, two aspects may give rise to questions. First,\nsince the program is four lines long and the specification (the\n\\(S_i\\)~and~\\(P_j\\)) consists in a total of seven cases, it may be\nunclear how the proof raises our confidence in the program. Second,\nthe proof itself is rather long, which leads us to wonder whether any\nerror is hiding in it. The first concern can be addressed by noting\nthat the two parts of the specification are disjoint and thus as easy\nto comprehend as the program. Moreover, specifications, being logical\nand not necessarily computable, are likely to be more abstract and\ncomposable than programs, so a larger proof may reuse them in\ndifferent instances. For example, the predicate~\\(\\predName{Isrt}\\)\ncan easily be abstracted (higher\\hyp{}order) over the sorting function\nas \\(\\pred{Isrt}{f,s} \\colon \\pred{Ord}{f(s)} \\mathrel{\\wedge} f(s)\n\\approx s\\)\\index{Isrt@\\predName{Isrt}}\\index{Ord@\\predName{Ord}} and\nthus applies to many sorting algorithms, with the caveat\nthat~\\((\\approx)\\) is probably not always suitably defined by\ntranspositions. The second concern can be completely taken care of by\nrelying on a \\emph{proof assistant}, like\\index{Coq@\\textsf{Coq}}\n\\textsf{Coq} \\citep{BertotCasteran_2004}. For instance, the formal\nspecification of~\\((\\approx)\\) and the automatic proofs (by means\nof~\\texttt{eauto}) of its reflexivity and symmetry consists in the\nfollowing script, where \\verb|x::s| stands for~\\(\\cons{x}{s}\\),\n(\\verb|->|) is~\\((\\Rightarrow)\\), \\verb|perm s t| is~\\(s \\approx t\\)\nand \\verb|List| is synonymous with stack:\n\\begin{verbatim}\nSet Implicit Arguments.\nRequire Import List.\nVariable A: Type.\n\nInductive perm: list A -> list A -> Prop :=\n  Pnil  : perm nil nil\n| Push  : forall x s t, perm s t -> perm (x::s) (x::t)\n| Swap  : forall x y s, perm (x::y::s) (y::x::s)\n| Trans : forall s t u, perm s u -> perm u t -> perm s t.\n\nHint Constructors perm.\n\nLemma reflexivity: forall s, perm s s.\nProof. induction s; eauto. Qed.\n\nLemma symmetry: forall s t, perm s t -> perm t s.\nProof. induction 1; eauto. Qed.\n\\end{verbatim}\n\\index{insertion sort!soundness|)}\n\n\\mypar{Termination}\n\\index{termination!insertion sort|(}\n\\index{insertion sort!straight $\\sim$!termination|(}\n\nInformally, what soundness means is that, if some program terminates,\nthen the result is what was expected. This property is called\n\\emph{partial correctness} when it is relevant to distinguish it from\n\\emph{total correctness}\\index{correctness!total\n  $\\sim$|see{termination}}, which is partial correctness and\ntermination. Let us prove the termination of \\fun{isrt/1} by the\ndependency pairs\\index{termination!dependency pair} method\n(section~\\ref{flattening:termination},\npage~\\pageref{flattening:termination}). The pairs to order are\n\\((\\fun{ins}(\\cons{y}{s},x), \\fun{ins}(s,x))_\\kappa\\),\n\\((\\fun{isrt}(\\cons{x}{s}), \\fun{isrt}(s))_\\nu\\) and\n\\((\\fun{isrt}(\\cons{x}{s}), \\fun{ins}(\\fun{isrt}(s), x))_\\nu\\). By\nusing the proper subterm\\index{induction!proper subterm order}\nrelation on the first parameter of \\fun{ins/2}\\index{ins@\\fun{ins/2}},\nwe order the first pair:\n\\begin{equation*}\n\\fun{ins}(\\cons{y}{s},x) \\succ \\fun{ins}(s,x) \\Leftrightarrow\n\\cons{y}{s} \\succ s.\n\\end{equation*}\nThis is enough to prove that \\fun{ins/2} terminates. The second pair\nis similarly oriented:\n\\begin{equation*}\n\\fun{isrt}(\\cons{x}{s}) \\succ \\fun{isrt}(s) \\Leftrightarrow\n\\cons{x}{s} \\succ s.\n\\end{equation*}\nThe third pair is not worth considering after all, because we already\nknow that \\fun{ins/2} terminates, so the second pair is enough to\nentail the termination of \\fun{isrt/1}\\index{isrt@\\fun{isrt/1}}. In\nother words, since \\fun{ins/2} terminates, it can be considered, as\nfar as termination analysis is concerned, as a data constructor, so\nthe third pair becomes useless:\n\\begin{equation*}\n\\fun{isrt}(\\cons{x}{s}) \\succ \\underline{\\fun{ins}}(\\fun{isrt}(s), x)\n\\Leftrightarrow \\fun{isrt}(\\cons{x}{s}) \\succ \\fun{isrt}(s)\n\\Leftrightarrow \\cons{x}{s} \\succ s,\n\\end{equation*}\nwhere \\(\\fun{\\ufun{ins}/2}\\) stands for\n\\fun{ins/2}\\index{ins@\\fun{ins/2}} considered as a constructor. (We\nhave used this notation in \\fig~\\vref{fig:ver}.)\\index{insertion\n  sort!straight $\\sim$!termination|)}\\index{termination!insertion\n  sort|)}\\index{insertion sort!straight $\\sim$|)}\\hfill\\(\\Box\\)\n\n\\section{2-way insertion}\n\\label{sec:2-way}\n\\index{insertion sort!2-way $\\sim$|(}\n\nLet us recall the definition of sorting by straight insertion:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\qquad}r@{\\;}l@{\\;}l@{}}\n  \\fun{ins}(\\cons{y}{s},x)\n& \\xrightarrow{\\smash{\\kappa}}\n& \\cons{y}{\\fun{ins}(s,x)}, \\,\\text{if \\(y \\succ x\\)};\n& \\fun{isrt}(\\el)\n& \\xrightarrow{\\smash{\\mu}}\n& \\el;\\\\\n  \\fun{ins}(s,x)\n& \\xrightarrow{\\smash{\\lambda}}\n& \\cons{x}{s}.\n& \\fun{isrt}(\\cons{x}{s})\n& \\xrightarrow{\\smash{\\nu}}\n& \\fun{ins}(\\fun{isrt}(s),x).\n\\end{array}\n\\end{equation*}\nThe reason why \\fun{ins/2}\\index{ins@\\fun{ins/2}} is called straight\ninsertion is because keys are compared in one direction only: from the\ntop of the stack towards its bottom. We may wonder what would happen\nif we could move up or down, \\emph{starting from the previously\n  inserted key}. Conceptually, this is like having a finger pointing\nat the last inserted key and the next insertion resuming from that\npoint, up or down the stack. Let us call it \\emph{two\\hyp{}way\n  insertion} and name \\fun{i2w/1}\\index{i2w@\\fun{i2w/1}} the sorting\nfunction based upon it. The stack with finger can be simulated by\nhaving two stacks, \\(t\\)~and~\\(u\\), such that\n\\(\\fun{rcat}(t,u)\\)\\index{rcat@\\fun{rcat/2}} stands for the currently\nsorted stack, corresponding to\n\\(\\fun{isrt}(s)\\)\\index{isrt@\\fun{isrt/1}} in rule~\\(\\nu\\). (In\nsection~\\ref{sec:queueing}, \\vpageref{sec:queueing}, we used two\nstacks to simulate a queue.) Let us call\n\\(\\fun{rcat}(t,u)\\)\\index{rcat@\\fun{rcat/2}} the \\emph{simulated\n  stack}\\index{stack!simulated $\\sim$}; stack~\\(t\\) is a\n\\emph{reversed prefix}\\index{stack!reversed prefix} of the simulated\nstack and stack~\\(u\\) is a \\emph{suffix}\\index{stack!suffix}. For\nexample, a finger pointing at~\\(5\\) in the simulated stack\n\\([0,2,4,5,7,8,9]\\) would be represented by \\([4,2,0]\\) and\n\\([5,7,8,9]\\). The reversing of the first stack is best visually\nunderstood by drawing it with the top facing the \\emph{right} side of\nthe page:\n\\begin{equation*}\n\\abovedisplayskip=0pt\n%\\abovedisplayshortskip=0pt\n%\\belowdisplayskip=0pt\n\\begin{array}{@{}r|c|c|c|ccc|c|c|c|c|l@{}}\n  \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{}\n& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{}\n& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{\\downarrow}\\\\\n\\cline{2-5}\\cline{7-11}\nt = & 0 & 2 & 4 & & & & 5 & 7 & 8 & 9 & = u\\\\\n\\cline{2-5}\\cline{7-11}\n\\end{array}\n\\end{equation*}\nGiven some key~\\(x\\), it is straightly inserted either in~\\(t\\)\n(minding it is sorted in reverse order) or in~\\(u\\). If we want to\ninsert~\\(1\\), we should pop~\\(4\\) and push it on the right stack, same\nfor~\\(2\\) and then push~\\(1\\) on the right stack, as, by convention,\nthe finger always points to the top of the right stack, where the last\ninserted key is:\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\begin{array}{@{}|c|ccc|c|c|c|c|c|c|c|@{}}\n  \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{}\n& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{\\downarrow}\\\\\n\\cline{1-2}\\cline{4-11}\n0 & & & & 1 & 2 & 4 & 5 & 7 & 8 & 9\\\\\n\\cline{1-2}\\cline{4-11}\n\\end{array}\n\\end{equation*}\n\nLet \\(\\fun{i2w}(s)\\)\\index{i2w@\\fun{i2w/1}} (\\emph{insertion going two\n  ways}) be the sorted stack corresponding to stack~\\(s\\). Let\n\\(\\fun{i2w}(s,t,u)\\)\\index{i2w@\\fun{i2w/3}} be the sorted stack\ncontaining all the keys from~\\(s\\), \\(t\\) and~\\(u\\), where \\(s\\)~is a\nsuffix of the original (probably unsorted) stack and\n\\(\\fun{rcat}(t,u)\\)\\index{rcat@\\fun{rcat/2}} is the current simulated\nstack, that is, \\(t\\)~is the left stack (reversed prefix) and~\\(u\\)\nthe right stack (suffix). The function\n\\fun{i2w/1}\\index{i2w@\\fun{i2w/1}} is defined in\n\\fig~\\vref{fig:i2w_def}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}ll}\n\\fun{i2w}(s)         & \\xrightarrow{\\smash{\\xi}}\n                     & \\fun{i2w}(s,\\el,\\el).\\\\\n\\fun{i2w}(\\el,\\el,u) & \\xrightarrow{\\smash{\\pi}}\n                     & u;\\\\\n\\fun{i2w}(\\el,\\cons{y}{t},u)\n                     & \\xrightarrow{\\smash{\\rho}}\n                     & \\fun{i2w}(\\el,t,\\cons{y}{u});\\\\\n\\fun{i2w}(\\cons{x}{s},t,\\cons{z}{u})\n                     & \\xrightarrow{\\smash{\\sigma}}\n                     & \\fun{i2w}(\\cons{x}{s},\\cons{z}{t},u),\n                     & \\text{if \\(x \\succ z\\)};\\\\\n\\fun{i2w}(\\cons{x}{s},\\cons{y}{t},u)\n                     & \\xrightarrow{\\smash{\\tau}}\n                     & \\fun{i2w}(\\cons{x}{s},t,\\cons{y}{u}),\n                     & \\text{if \\(y \\succ x\\)};\\\\\n\\fun{i2w}(\\cons{x}{s},t,u)\n                     & \\xrightarrow{\\smash{\\upsilon}}\n                     & \\fun{i2w}(s,t,\\cons{x}{u}).\n\\end{array}}\n\\end{equation*}\n\\caption{Sorting with 2-way insertion \\fun{i2w/1}\n\\label{fig:i2w_def}}\n\\end{figure}\nRule~\\(\\xi\\) introduces the two stacks used for insertion. Rules\n\\(\\pi\\)~and~\\(\\rho\\) could be replaced by \\(\\fun{i2w}(\\el,t,u)\n\\rightarrow \\fun{rcat}(t,u)\\), but we opted for a self\\hyp{}contained\ndefinition. Rule~\\(\\sigma\\) is used to move keys from the right stack\nto the left stack. Rule~\\(\\tau\\) moves them the other\nway. Rule~\\(\\upsilon\\) performs the insertion itself, namely, on top\nof the right stack. \\Fig~\\vref{fig:i2w2314} shows the evaluation of\n\\(\\fun{i2w}([2,3,1,4])\\), whose trace \\index{functional\n  language!evaluation!trace} is then \\((\\xi)(\\upsilon)(\\sigma\\upsilon)\n(\\tau\\upsilon)(\\sigma^3\\upsilon)(\\rho^3\\pi)\\). The number of times\nrule~\\(\\rho\\) is used is the number of keys on the left\nstack after there are no more keys to sort. Rule~\\(\\pi\\) is used once.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[bb=71 523 257 721]{i2w2314}\n\\caption{\\(\\fun{i2w}([2,3,1,4]) \\twoheadrightarrow [1,2,3,4]\\)\n\\label{fig:i2w2314}}\n\\end{figure}\n\n\\mypar{Extremal costs}\n\\index{insertion sort!2-way $\\sim$!minimum cost|(}\n\nLet us find the minimum and maximum costs for an input stack of\n\\(n\\)~keys. The best case will exert minimally rules\n\\clause{\\sigma}~and~\\clause{\\tau}, and this minimum number of calls\nturns out to be zero when the two comparisons are false. The first key\ninserted does not use rules \\clause{\\sigma}~and~\\clause{\\tau}, but\nonly rule~\\clause{\\upsilon}, so, right after, the reversed prefix is\nempty and the suffix contains this key. If we want to insert the\nsecond key without moving the first key, and go straight to use\nrule~\\clause{\\upsilon}, the second key must be smaller than the\nfirst. Based on the same argument, the third key must be smaller than\nthe second etc. In the end, this means that \\emph{the input, in the\n  best case, is a stack sorted non\\hyp{}increasingly.} The last steps\nconsisting in the reversal of the prefix, such prefix being empty, we\ndo not even use rule~\\clause{\\rho} at all --~only rule~\\clause{\\pi}\nonce. In other words, the evaluation trace is\n\\(\\zeta\\epsilon^n\\alpha\\) and, if we note \\(\\B{\\fun{i2w}}{n}\\) the\ncost when the stack contains \\(n\\)~keys in non\\hyp{}increasing order,\nthen we have\n\\begin{equation*}\n\\B{\\fun{i2w}}{n} = \\len{\\zeta\\epsilon^n\\alpha} = n + 2.\n\\end{equation*}\n\\index{insertion sort!2-way $\\sim$!minimum cost|)}\n\n\\index{insertion sort!2-way $\\sim$!maximum cost|(} Let us assume that\nthe input stack is noted \\([x_0, x_1, \\dots, x_{n-1}]\\) and \\(x \\prec\ny\\) means \\(y \\succ x\\). The worst case must exert maximally rules\n\\clause{\\sigma}~and~\\clause{\\tau}, on the one hand, and rules\n\\clause{\\pi}~and~\\clause{\\rho}, on the other hand. Let us focus first\non maximising the use of \\clause{\\sigma}~and~\\clause{\\tau}. Since\n\\(x_0\\)~is the first key, it is always pushed on the suffix stack by\nrule~\\clause{\\upsilon}. The second key, \\(x_1\\), in order to travel\nthe furthest, has to be inserted below~\\(x_0\\). By doing so,\nrule~\\clause{\\sigma} is used once and then~\\clause{\\upsilon},\ntherefore, as a result, \\(x_0\\)~is on the left (the reversed prefix)\nand \\(x_1\\)~on the right (the suffix). In other words: we have\n\\([x_0]\\) and \\([x_1]\\). Because of this symmetry, in pursuit of the\nworst case, we can now move either \\(x_0\\)~or~\\(x_1\\) to the facing\nstack, that is, choose either to set \\(x_2 \\prec x_0\\) or \\(x_1 \\prec\nx_2\\).\n\\begin{itemize}\n\n\\item If \\(x_2 \\prec x_0\\), rule~\\clause{\\tau} is used once, then\n  rule~\\clause{\\upsilon}. As a result, we have the configuration\n  \\(\\el\\) and \\([x_2, x_0, x_1]\\). This translates as \\(x_2 \\prec x_0\n  \\prec x_1\\). The fourth key, \\(x_3\\), must be inserted at the bottom\n  of the right stack, which must be first reversed on top of the left\n  stack by rule~\\clause{\\sigma}: we then obtain \\([x_1, x_0, x_2]\\)\n  and \\([x_3]\\), that is, \\(x_2 \\prec x_0 \\prec x_1 \\prec\n  x_3\\). Finally, the left stack is reversed on top of the second by\n  rule~\\clause{\\rho} and rule~\\clause{\\pi} is last. The evaluation\n  trace is\n  \\((\\xi)(\\upsilon)(\\sigma\\upsilon)(\\tau\\upsilon)(\\sigma^3\\upsilon)\n  (\\rho^3\\pi)\\), whose length is~\\(14\\).\n\n\\item If \\(x_1 \\prec x_2\\), we would have \\([x_1, x_0]\\) and\n  \\([x_2]\\), then the stacks \\(\\el\\) and \\([x_3, x_0, x_1, x_2]\\),\n  that is, \\(x_3 \\prec x_0 \\prec x_1 \\prec x_2\\). The complete\n  evaluation trace is\n  \\((\\xi)(\\upsilon)(\\sigma\\upsilon)(\\sigma\\upsilon)(\\tau^2\\upsilon)\n  (\\pi)\\). The length of this trace is~\\(10\\), which is shorter than\n  the previous trace.\n\n\\end{itemize}\nAs a conclusion, the choice \\(x_2 \\prec x_0\\) leads to a worse\ncase. But what if the input stack contains an odd number~\\(n\\) of\nkeys? To guess what happens, let us insert~\\(x_4\\) assuming either\n\\(x_1 \\prec x_2\\) or \\(x_2 \\prec x_0\\).\n\\begin{itemize}\n\n\\item If \\(x_2 \\prec x_0\\), we move all the keys out of the left\n  stack, yielding the configuration \\([x_4]\\) and \\([x_2, x_0, x_1,\n  x_3]\\), so \\(x_4 \\prec x_2 \\prec x_0 \\prec x_1 \\prec x_3\\),\n  corresponding to the trace\n  \\((\\xi)(\\upsilon)(\\sigma\\upsilon)(\\tau\\upsilon)(\\sigma^3\\upsilon)\n  (\\tau^3\\upsilon)(\\rho\\pi)\\), whose length is~\\(16\\).\n\n\\item If \\(x_1 \\prec x_2\\), we want to insert~\\(x_4\\) at the bottom of\n  the right stack, thus obtaining \\([x_2, x_1, x_0, x_3]\\) and\n  \\([x_4]\\): \\(x_3 \\prec x_0 \\prec x_1 \\prec x_2 \\prec x_4\\),\n  corresponding to the trace \\((\\xi)(\\upsilon)\n  (\\sigma\\upsilon)(\\sigma\\upsilon)(\\tau^2\\upsilon)(\\sigma^4\\upsilon)\n  (\\rho^4\\pi)\\), whose length is~\\(19\\). It is perhaps better\n  visualised by means of oriented edges, revealing a spiral in\n  \\fig~\\vref{fig:spiral}.\n    \\begin{figure}\n      \\centering\n      \\includegraphics[bb=71 671 185 716]{a3a0a1a2a4}\n      \\caption{Worst case for \\fun{i2w/1} if \\(n=5\\) (\\(x_1 \\prec x_2\\))\n               \\label{fig:spiral}}\n    \\end{figure}\n\n\\end{itemize}\nTherefore, it seems that when the number of keys is odd, having \\(x_1\n\\prec x_2\\) leads to the maximum cost, whilst \\(x_2 \\prec x_0\\) leads\nto the maximum cost when the number of keys is even. Let us determine\nthese costs for any~\\(n\\) and find out which is the greater. Let us\nnote \\(\\W{x_1 \\prec x_2}{2p+1}\\) the former cost and \\(\\W{x_2 \\prec\n  x_0}{2p}\\) the latter.\n\\begin{itemize}\n\n\\item If \\(n = 2p+1\\) and \\(x_1 \\prec x_2\\), then the evaluation trace\n  is\n    \\begin{equation*}\n    (\\xi)(\\upsilon)(\\sigma\\upsilon)(\\sigma\\upsilon)\n    (\\tau^2\\upsilon)(\\sigma^4\\upsilon)(\\tau^4\\upsilon) \\ldots\n    (\\sigma^{2p-2}\\upsilon)(\\tau^{2p-2}\\upsilon)(\\sigma^{2p}\\upsilon)\n    (\\rho^{2p}\\pi),\n    \\end{equation*}\n    as a partial evaluation with~\\(p=3\\) suggests:\n    \\begin{equation*}\n      \\!\\begin{array}{@{}r@{\\;}c@{\\;}l@{}}\n        \\fun{i2w}([x_0,x_1,x_2,x_3,x_4,x_5,x_6])\n        & \\xrightarrow{\\smash{\\xi}}\n        & \\fun{i2w}(\\el,\\el,[x_0,x_1,x_2,x_3,x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}(\\el,[x_0],[x_1,x_2,x_3,x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\sigma}}\n        & \\fun{i2w}([x_0],\\el,[x_1,x_2,x_3,x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}([x_0],[x_1],[x_2,x_3,x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\sigma}}\n        & \\fun{i2w}([x_1,x_0],\\el,[x_2,x_3,x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}([x_1,x_0],[x_2],[x_3,x_4,x_5,x_6])\\\\\n        & \\stackrel{\\smash{\\tau^{\\smash{2}}}}{\\twoheadrightarrow}\n        & \\fun{i2w}(\\el,[x_0,x_1,x_2],[x_3,x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}(\\el,[x_3,x_0,x_1,x_2],[x_4,x_5,x_6])\\\\\n        & \\stackrel{\\smash{\\sigma^{\\smash{4}}}}{\\twoheadrightarrow}\n        & \\fun{i2w}([x_2,x_1,x_0,x_3],\\el,[x_4,x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}([x_2,x_1,x_0,x_3],[x_4],[x_5,x_6])\\\\\n        & \\stackrel{\\smash{\\tau^{\\smash{4}}}}{\\twoheadrightarrow}\n        & \\fun{i2w}(\\el,[x_3,x_0,x_1,x_2,x_4],[x_5,x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}(\\el,[x_5,x_3,x_0,x_1,x_2,x_4],[x_6])\\\\\n        & \\stackrel{\\smash{\\sigma^{\\smash{6}}}}{\\twoheadrightarrow}\n        & \\fun{i2w}([x_4,x_2,x_1,x_0,x_3,x_5],\\el,[x_6])\\\\\n        & \\xrightarrow{\\smash{\\upsilon}}\n        & \\fun{i2w}([x_4,x_2,x_1,x_0,x_3,x_5],[x_6],\\el).\n      \\end{array}\n    \\end{equation*}\n    If we omit rules~\\clause{\\xi}, \\clause{\\upsilon}, \\clause{\\pi}\n    and~\\clause{\\rho}, we can see a pattern emerge from the subtrace\n    \\((\\sigma^2\\tau^2)(\\sigma^4\\tau^4)(\\sigma^6\\tau^6) \\ldots\n    (\\sigma^{2p-2}\\tau^{2p-2})(\\sigma^{2p})\\). Rule~\\clause{\\upsilon}\n    is used \\(n\\)~times because it inserts the key in the right\n    place. So the total cost is\n    \\begin{align*}\n      \\W{x_1 \\prec x_2}{2p+1}\n        &= \\len{\\xi} + \\len{\\upsilon^{2p+1}}\n           + \\sum_{k=1}^{p-1}{\\left(\\len{\\sigma^{2k}} + \\len{\\tau^{2k}}\\right)}\n           + \\len{\\sigma^{2p}} + \\len{\\rho^{2p}\\pi}\\\\\n        &= 1 + (2p + 1) + \\sum_{k=1}^{p-1}{2(2k)} + (2p) + (2p + 1)\\\\\n        &= 2p^2 + 4p + 3.\n    \\end{align*}\n\n  \\item If \\(n = 2p\\) and \\(x_2 \\prec x_0\\), then the evaluation trace is\n    \\begin{equation*}\n      (\\xi)(\\upsilon)(\\sigma\\upsilon)(\\tau\\upsilon)\n      (\\sigma^3\\upsilon)(\\tau^3\\upsilon)\n      \\ldots (\\sigma^{2p-1}\\upsilon)(\\rho^{2p-1}\\pi),\n    \\end{equation*}\n    as the following partial evaluation with~\\(p=3\\) suggests (first\n    difference with the previous case is in boldface type):\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}c@{\\;}l@{}}\n\\fun{i2w}([x_{0},x_{1},x_{2},x_{3},x_{4},x_{5}])\n& \\rightarrow\n& \\fun{i2w}(\\el,\\el,[x_{0},x_{1},x_{2},x_{3},x_{4},x_{5}])\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\fun{i2w}(\\el,[x_{0}],[x_{1},x_{2},x_{3},x_{4},x_{5}])\\\\\n& \\xrightarrow{\\smash{\\sigma}}\n& \\fun{i2w}([x_{0}],\\el,[x_{1},x_{2},x_{3},x_{4},x_{5}])\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\fun{i2w}([x_{0}],[x_{1}],[x_{2},x_{3},x_{4},x_{5}])\\\\\n& \\xrightarrow{\\smash{\\tau}}\n& \\boldsymbol{\\fun{i2w}(\\el,[x_{0},x_{1}],[x_{2},x_{3},x_{4},x_{5}])}\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\fun{i2w}(\\el,[x_{2},x_{0},x_{1}],[x_{3},x_{4},x_{5}])\\\\\n& \\stackrel{\\smash{\\sigma^{\\smash{3}}}}{\\twoheadrightarrow}\n& \\fun{i2w}([x_{1},x_{0},x_{2}],\\el,[x_{3},x_{4},x_{5}])\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\fun{i2w}([x_{1},x_{0},x_{2}],[x_{3}],[x_{4},x_{5}])\\\\\n& \\stackrel{\\smash{\\tau^{\\smash{3}}}}{\\twoheadrightarrow}\n& \\fun{i2w}(\\el,[x_{2},x_{0},x_{1},x_{3}],[x_{4},x_{5}])\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\fun{i2w}(\\el,[x_{4},x_{2},x_{0},x_{1},x_{3}],[x_{5}])\\\\\n& \\stackrel{\\smash{\\sigma^{\\smash{5}}}}{\\twoheadrightarrow}\n& \\fun{i2w}([x_{3},x_{1},x_{0},x_{2},x_{4}],\\el,[x_{5}])\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\fun{i2w}([x_{3},x_{1},x_{0},x_{2},x_{4}],[x_{5}],\\el)\n\\end{array}\n\\end{equation*}\nIf we omit rules~\\clause{\\xi}, \\clause{\\upsilon}, \\clause{\\pi}\nand~\\clause{\\rho}, we can see a pattern emerge from the subtrace\n\\((\\sigma^1\\tau^1)(\\sigma^3\\tau^3)(\\sigma^5\\tau^5) \\ldots\n(\\sigma^{2p-3}\\tau^{2p-3})(\\sigma^{2p-1})\\). Rule~\\clause{\\upsilon} is\nused \\(n\\)~times because it inserts the key in the right place. So the\ntotal cost is\n\\begin{align*}\n\\W{x_2 \\prec x_0}{2p}\n   &= \\len{\\xi} + \\len{\\upsilon^{2p}}\n           + \\sum_{k=1}^{p-1}{\\left(\\len{\\sigma^{2k-1}} + \\len{\\tau^{2k-1}}\\right)}\n           + \\len{\\sigma^{2p-1}} + \\len{\\rho^{2p-1}\\pi}\\\\\n   &= 1 + (2p) + \\sum_{k=1}^{p-1}{2(2k-1)} + (2p-1) + ((2p - 1) + 1)\\\\\n   &= 2p^2 + 2p + 2.\n\\end{align*}\n\\end{itemize}\nThese formulas hold for all \\(p \\geqslant 0\\). We can now conclude\nthis discussion about the worst case of \\fun{i2w/1}:\n\\begin{itemize}\n\n\\item If \\(n = 2p\\), the worst case happens when the keys satisfy the\n  total order \\(x_{2p} \\prec x_{2p-2} \\prec \\dots \\prec x_0 \\prec x_1\n  \\prec x_3 \\prec \\dots \\prec x_{2p-3} \\prec x_{2p-1}\\) and\n  \\(\\W{\\fun{i2w}}{2p} = 2p^2 + 2p + 2\\), that is, \\(\\W{\\fun{i2w}}{n} =\n  \\frac{1}{2}{n^2} + n + 2\\).\n\n\\item If \\(n = 2p+1\\), the worst case happens when the keys satisfy\n  the order \\(x_{2p-1} \\prec x_{2p-3} \\prec \\dots \\prec x_3 \\prec x_0\n  \\prec x_1 \\prec x_2 \\prec \\dots \\prec x_{2p-2} \\prec x_{2p}\\) and\n  \\(\\W{\\fun{i2w}}{2p+1} = 2p^2 + 4p + 3\\), that is, \\(\\W{\\fun{i2w}}{n}\n  = \\frac{1}{2}{n^2} + n + \\frac{3}{2}\\).\n\n\\end{itemize}\nThe first case yields the maximum cost:\n\\begin{equation*}\n%\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n  \\W{\\fun{i2w}}{n} = \\frac{1}{2}{n^2} + n + 2 = \\W{\\fun{isrt}}{n} - n\n  + 1 \\sim\n  \\W{\\fun{isrt}}{n} \\sim \\frac{1}{2}{n^2}.\n\\end{equation*}\n\\index{insertion sort!2-way $\\sim$!maximum cost|)}\n\n\n\\mypar{Average cost}\n\\index{insertion sort!2-way $\\sim$!average cost|(}\n\nLet \\(\\M{\\fun{i2w}}{n}\\)\\index{i2w@$\\M{\\fun{i2w}}{n}$} be the average\ncost of the call \\(\\fun{i2w}(s)\\)\\index{i2w@\\fun{i2w/1}}, where the\nstack~\\(s\\) has length~\\(n\\). We are going to use the same assumption\nas with \\(\\M{\\fun{isrt}}{n}\\), namely, we look for the cost for\nsorting all permutations of \\((1,2,\\dots,n)\\), divided by~\\(n!\\). The\ninsertions are illustrated by the \\emph{evaluation\n  tree}\\index{tree!evaluation $\\sim$} in \\fig~\\ref{fig:2way_unbal},\n\\begin{figure}[t]\n\\centering\n\\includegraphics{2way_unbal}\n\\caption{Sorting \\([a,b,c]\\) (first argument of \\fun{i2w/3} hidden)\n\\label{fig:2way_unbal}}\n\\end{figure}\nwhere the keys \\(a\\), \\(b\\) and~\\(c\\) are inserted in this order in a\nstack originally empty, with all possible total orders. Note how all\npermutations are attained exactly once at the external\nnodes\\index{tree!node!external $\\sim$} (see\npage~\\pageref{def:external_node}). For example, \\([a,b,c]\\) and\n\\([c,b,a]\\) are external nodes. The total cost is the \\emph{external\n  path length}\\index{tree!external path\n  length}\\label{external_path_length} of the tree, that is, the sum of\nthe lengths of the paths from the root to all the external nodes,\nwhich is the same as the sum of the lengths of all possible\ntraces\\index{functional\n  language!evaluation!trace}\\index{tree!evaluation $\\sim$}:\n\\(\\len{\\xi\\upsilon\\sigma\\upsilon\\sigma\\upsilon\\rho^2\\pi} +\n\\len{\\xi\\upsilon\\sigma\\upsilon\\tau\\upsilon\\pi} +\n\\len{\\xi\\upsilon\\sigma\\upsilon^2\\rho\\pi} +\n\\len{\\xi\\upsilon^2\\sigma^2\\upsilon\\rho^2\\pi} +\n\\len{\\xi\\upsilon^2\\sigma\\upsilon\\rho\\pi} + \\len{\\xi\\upsilon^3\\pi} =\n44\\), so the average cost of sorting \\(3\\)~keys is \\(44/3! = 22/3\\).\n\nGiven a left stack of \\(p\\)~keys and a right stack of \\(q\\)~keys, let\nus characterise all the possible traces for the insertion of one more\nkey, stopping before another key is inserted or the final stack is\nmade. In the left stack, an insertion is possible after the first key,\nafter the second etc. until after the last. After the \\(k\\)th key,\nwith \\(1 \\leqslant k \\leqslant p\\), the trace is thus\n\\(\\tau^k\\upsilon\\). In the right stack, an insertion is possible on\ntop, after the first key, after the second etc. until after the\nlast. After the \\(k\\)th key, with \\(0 \\leqslant k \\leqslant q\\), the\ntrace is hence \\(\\sigma^k\\upsilon\\). All the possible traces are thus\n\\begin{equation*}\n\\sum_{k=1}^{p}{\\tau^k\\upsilon} + \\sum_{k=0}^{q}{\\sigma^k\\upsilon},\n\\end{equation*}\nwhose cumulated lengths amount to\n\\begin{equation*}\nC_{p,q} := \\sum_{k=1}^{p}\\len{\\tau^k\\upsilon} +\n\\sum_{k=0}^{q}\\len{\\sigma^k\\upsilon}\n= (p+q+1) + \\frac{1}{2}p(p+1) + \\frac{1}{2}q(q+1).\n\\end{equation*}\nThere are \\(p+q+1\\) insertion loci, so the average cost of one\ninsertion in the configuration \\((p,q)\\) is\n\\begin{equation}\n\\M{}{p,q} := \\frac{C_{p,q}}{p+q+1}\n           = 1 + \\frac{p^2 + q^2 + p + q}{2p + 2q + 2}.\n\\label{eq:Mpq}\n\\end{equation}\nBy letting \\(k := p + q\\), we can re\\hyp{}express this cost as\n\\begin{equation*}\n\\M{}{q-k,q} = \\frac{1}{k+1}{q^2} - \\frac{k}{k+1}{q} + \\frac{k+2}{2}.\n\\end{equation*}\nThe left stack is reversed after the last insertion, so the subsequent\ntraces are \\(\\rho^{p-k}\\pi\\), with \\(1 \\leqslant k \\leqslant p\\), if\nthe last insertion took place on the left, otherwise\n\\(\\rho^{p+k}\\pi\\), with \\(0 \\leqslant k \\leqslant q\\), that is,\n\\(\\rho^0\\pi\\), \\(\\rho^1\\pi\\), \\ldots, \\(\\rho^{p+q}\\pi\\). In other\nwords, after an insertion, all possible configurations are uniquely\nrealised (only the right stack being empty is invalid, due to\nrule~\\(\\upsilon\\)). As a consequence, we can average the average costs\nof inserting one key over all the partitions of~\\(k\\) into~\\(p + q\\),\nwith \\(q \\neq 0\\), so the average cost of inserting one key in a\nsimulated stack of \\(k\\)~keys is\n\\begin{equation*}\n\\M{}{0} := 1;\\quad\n\\M{}{k} := \\frac{1}{k}\\!\\sum_{p+q=k}\\M{}{p,q}\n         = \\frac{1}{k}\\sum_{q=1}^{k}\\M{}{q-k,q}\n         = \\frac{1}{3}k + \\frac{7}{6},\n\\end{equation*}\nminding that \\(\\sum_{q=1}^{k}{q^2} = k(k+1)(2k+1)/6\\) (see\nequation~\\eqref{eq:sum_of_squares} \\vpageref{eq:sum_of_squares}). The\ncost of the final reversal is also averaged over all possible\nconfigurations, here of \\(n>0\\) keys:\n\\begin{equation*}\n\\M{\\curvearrowright}{n} = \\frac{1}{n}\\sum_{k=0}^{n-1}\\len{\\rho^k\\pi}\n                        = \\frac{n+1}{2}.\n\\end{equation*}\nFinally, we know that all traces start with~\\(\\xi\\), then proceed with\nall the insertions and conclude with a reversal. This means that the\naverage cost \\(\\M{\\fun{i2w}}{n}\\)\\index{i2w@$\\M{\\fun{i2w}}{n}$} of\nsorting \\(n\\)~keys is defined by the following equations:\n\\begin{equation*}\n\\M{\\fun{i2w}}{0} = 2;\\quad\n\\M{\\fun{i2w}}{n} = 1 + \\sum_{k=0}^{n-1}{\\M{}{k}} + \\M{\\curvearrowright}{n}\n                 = \\frac{1}{6}n^2 + \\frac{3}{2}n + \\frac{4}{3}\n                 \\sim \\frac{1}{6}n^2.\n\\end{equation*}\nWe can check that \\(\\M{\\fun{i2w}}{3} = 22/3\\), as expected. As a\nconclusion, in average, sorting with 2-way insertions is faster than\nwith straight insertions, but the cost is still asymptotically\nquadratic.\\index{insertion sort!2-way $\\sim$!average\n  cost|)}\\index{insertion sort!2-way $\\sim$|)}\n\n\n\\paragraph{Exercises}\n\\begin{enumerate}\n\n  \\item When designing~\\fun{i2w/3}\\index{i2w@\\fun{i2w/3}}, we chose to\n    always push the key to be inserted on top of the right stack in\n    rule~\\(\\upsilon\\). Let us modify slightly this strategy and push\n    instead onto the left stack when it is empty. See\n    rule~(\\(\\leadsto\\)) in \\fig~\\vref{fig:i2w1}.\n    \\begin{figure}[b]\n    \\begin{equation*}\n      \\boxed{%\n      \\begin{array}{r@{\\;}l@{\\;}ll}\n        \\fun{i2w}_1(s) & \\rightarrow\n                      & \\fun{i2w}_1(s,\\el,\\el).\\\\\n        \\fun{i2w}_1(\\el,\\el,u) & \\rightarrow & u;\\\\\n        \\fun{i2w}_1(\\el,\\cons{y}{t},u)\n                     & \\rightarrow\n                     & \\fun{i2w}_1(\\el,t,\\cons{y}{u});\\\\\n        \\fun{i2w}_1(\\cons{x}{s},t,\\cons{z}{u})\n                     & \\rightarrow\n                     & \\fun{i2w}_1(\\cons{x}{s},\\cons{z}{t},u),\n                     & \\text{if \\(x \\succ z\\)};\\\\\n        \\fun{i2w}_1(\\cons{x}{s},\\el,u)\n                     & \\leadsto\n                     & \\fun{i2w}_1(s,[x],u);\\\\\n        \\fun{i2w}_1(\\cons{x}{s},\\cons{y}{t},u)\n                     & \\rightarrow\n                     & \\fun{i2w}_1(\\cons{x}{s},t,\\cons{y}{u}),\n                     & \\text{if \\(y \\succ x\\)};\\\\\n        \\fun{i2w}_1(\\cons{x}{s},t,u)\n                     & \\rightarrow\n                     & \\fun{i2w}_1(s,t,\\cons{x}{u}).\n      \\end{array}}\n    \\end{equation*}\n    \\caption{Variation \\fun{i2w\\(_1\\)/1} on \\fun{i2w/1} (see\n      (\\(\\leadsto\\)))\\label{fig:i2w1}}\n    \\end{figure}\n    Prove that the average cost satisfies now the equation\n    \\index{i2w1@\\fun{i2w\\(_1\\)/1}} \\index{i2w1@\\fun{i2w\\(_1\\)/3}}\n    \\index{i2w1@$\\M{\\fun{i2w}_1}{n}$}\n    \\begin{equation*}\n      \\M{\\fun{i2w}_1}{n} = \\M{\\fun{i2w}}{n} - H_n + 2.\n    \\end{equation*}\n    \\emph{Hint:} write down the examples similar to the ones in\n    \\fig~\\vref{fig:2way_unbal}, determine the average path length and\n    observe that the difference with\n    \\fun{i2w/1}\\index{i2w@\\fun{i2w/1}} is that the configuration with\n    an empty left stack is replaced with a configuration with a\n    singleton left stack, to wit, \\(\\M{}{0,k}\\) is replaced\n    with~\\(\\M{}{1,k-1}\\) in the definition of~\\(\\M{}{k}\\).\n\n  \\item In rule~\\(\\upsilon\\) of~\\fun{i2w/3}\\index{i2w@\\fun{i2w/3}},\n    the key~\\(x\\) is pushed on the right stack. Consider in\n    \\fig~\\vref{fig:i2w2} (rule~(\\(\\leadsto\\))) the variant where it is\n    pushed on the left stack instead. Show very simply that the\n    average cost satisfies\\index{i2w2@\\fun{i2w\\(_2\\)/1}}\n    \\index{i2w2@\\fun{i2w\\(_2\\)/3}} \\index{i2w2@$\\M{\\fun{i2w}_2}{n}$}\n    \\begin{equation*}\n      \\M{\\fun{i2w}_2}{n} = \\M{\\fun{i2w}}{n} + 1.\n    \\end{equation*}\n    \\begin{figure}[h]\n    \\begin{equation*}\n      \\boxed{%\n      \\begin{array}{r@{\\;}l@{\\;}ll}\n        \\fun{i2w}_2(s)         & \\rightarrow\n                               & \\fun{i2w}_2(s,\\el,\\el).\\\\\n        \\fun{i2w}_2(\\el,\\el,u) & \\rightarrow\n                               & u;\\\\\n        \\fun{i2w}_2(\\el,\\cons{y}{t},u)\n                               & \\rightarrow\n                               & \\fun{i2w}_2(\\el,t,\\cons{y}{u});\\\\\n        \\fun{i2w}_2(\\cons{x}{s},t,\\cons{z}{u})\n                               & \\rightarrow\n                               & \\fun{i2w}_2(\\cons{x}{s},\\cons{z}{t},u),\n                               & \\text{if \\(x \\succ z\\)};\\\\\n        \\fun{i2w}_2(\\cons{x}{s},\\cons{y}{t},u)\n                               & \\rightarrow\n                               & \\fun{i2w}_2(\\cons{x}{s},t,\\cons{y}{u}),\n                               & \\text{if \\(y \\succ x\\)};\\\\\n        \\fun{i2w}_2(\\cons{x}{s},t,u)\n                               & \\leadsto\n                               & \\fun{i2w}_2(s,\\cons{x}{t},u).\n      \\end{array}}\n    \\end{equation*}\n    \\caption{Variation \\fun{i2w\\(_2\\)/1} on \\fun{i2w/1} (see\n      (\\(\\leadsto\\)))\\label{fig:i2w2}}\n    \\end{figure}\n\n\\end{enumerate}\n\n\\section{Balanced 2-way insertion}\n\\index{insertion sort!2-way $\\sim$!balanced $\\sim$|(}\n\nWhen sorting with 2-way insertions, keys are inserted from whence the\nfinger is on the simulated stack. We could maintain the finger at the\nmiddle of the stack, leading to what we call \\emph{balanced 2-way\n  insertions}. The adjective `balanced' refers to the shape of the\ncomparison tree.\n\nOur best effort to keep the two stacks about the same length must lead\nto two cases: either (\\textsl{a})~they are exactly of the same length,\nor (\\textsl{b})~one of them, say the right one, contains one more\nkey. Let us envisage how to maintain this invariant through\ninsertions. Let us suppose we are in case~(\\textsl{b}). Then, if the\nkey has to be inserted in the left stack, the resulting stacks will\nhave equal lengths, which means case~(\\textsl{a}); otherwise, we move\nthe top of the right stack to the top of the left stack, in addition\nto the insertion itself, and we are back to case~(\\textsl{a}) as\nwell. If we are in case~(\\textsl{a}) and the insertion takes place in\nthe right stack, no rebalancing has to be done; otherwise, the top of\nthe left stack is moved to the top of the right: in both events, we\nare in case~(\\textsl{b}). What if the key has to be inserted at the\nfinger position?  If the two stacks have same length, that is,\ncase~(\\textsl{a}), we push the key on top of the right one and go back\nto case~(\\textsl{b}); otherwise, it means that the right stack exceeds\nthe left by one, that is, case~(\\textsl{b}), so it is best to push it\non the left stack: as a result, the stacks end having equal lengths\nand we are back to case~(\\textsl{a}).\n\nTo program this algorithm, we need a variant\n\\fun{idn/2}\\index{idn@\\fun{idn/2}} (\\emph{insert downwardly})\nof~\\fun{ins/2}\\index{ins@\\fun{ins/2}} because the left stack is sorted\ndecreasingly. Let us rename~\\fun{ins/2}\ninto~\\fun{iup/2}\\index{iup@\\fun{iup/2}} (\\emph{insert upwardly}).\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n  \\fun{iup}(\\cons{y}{s},x)\n& \\xrightarrow{\\smash{\\kappa_0}}\n& \\cons{y}{\\fun{iup}(s,x)},\\,\\text{if \\(y \\succ x\\)};\n& \\fun{iup}(s,x)\n& \\xrightarrow{\\smash{\\lambda_0}} & \\cons{x}{s}.\\\\\n  \\fun{idn}(\\cons{y}{s},x)\n& \\xrightarrow{\\smash{\\kappa_1}}\n& \\cons{y}{\\fun{idn}(s,x)},\\,\\text{if \\(x \\succ y\\)};\n& \\fun{idn}(s,x)\n& \\xrightarrow{\\smash{\\lambda_1}} & \\cons{x}{s}.\n\\end{array}\n\\end{equation*}\nFurthermore, we need an additional parameter that represents the\ndifference in length between the two stacks: \\(0\\)~if they have the\nsame length and \\(1\\)~if the right contains one more key. Let us call\nthe new function\n\\fun{i2wb/1}\\index{i2wb@\\fun{i2wb/1}}\\index{i2wb@\\fun{i2wb/3}}, whose\ndefinition is displayed in \\fig~\\vref{fig:i2wb}.\n\\begin{figure}[t]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}ll}\n\\fun{i2wb}(s)\n& \\xrightarrow{\\smash{\\xi}} & \\fun{i2wb}(s,\\el,\\el,0).\\\\\n\\fun{i2wb}(\\el,\\el,u,d)\n& \\xrightarrow{\\smash{\\pi}} & u;\\\\\n\\fun{i2wb}(\\el,\\cons{y}{t},u,d)\n& \\xrightarrow{\\smash{\\rho}} & \\fun{i2wb}(\\el,t,\\cons{y}{u},d);\\\\\n\\fun{i2wb}(\\cons{x}{s},t,\\cons{z}{u},0)\n& \\xrightarrow{\\smash{\\sigma}} &\n\\fun{i2wb}(s,t,\\cons{z}{\\fun{iup}(u,x)},1),\n& \\text{if \\(x \\succ z\\)};\\\\\n\\fun{i2wb}(\\cons{x}{s},\\cons{y}{t},u,0)\n& \\xrightarrow{\\smash{\\tau}} &\n\\fun{i2wb}(s,\\fun{idn}(t,x),\\cons{y}{u},1),\n& \\text{if \\(y \\succ x\\)};\\\\\n\\fun{i2wb}(\\cons{x}{s},t,u,0)\n& \\xrightarrow{\\smash{\\upsilon}} & \\fun{i2wb}(s,t,\\cons{x}{u},1);\\\\\n\\fun{i2wb}(\\cons{x}{s},t,\\cons{z}{u},1)\n& \\xrightarrow{\\smash{\\phi}}\n& \\fun{i2wb}(s,\\cons{z}{t},\\fun{iup}(u,x),0),\n& \\text{if \\(x \\succ z\\)};\\\\\n\\fun{i2wb}(\\cons{x}{s},\\cons{y}{t},u,1)\n& \\xrightarrow{\\smash{\\chi}}\n& \\fun{i2wb}(s,\\cons{y}{\\fun{idn}(t,x)},u,0),\n& \\text{if \\(y \\succ x\\)};\\\\\n\\fun{i2wb}(\\cons{x}{s},t,u,1) & \\xrightarrow{\\smash{\\psi}} &\n\\fun{i2wb}(s,\\cons{x}{t},u,0).\n\\end{array}}\n\\end{equation*}\n\\caption{Balanced 2-way insertion \\label{fig:i2wb}}\n\\end{figure}\nIn \\fig~\\vref{fig:2way_bal}\n\\begin{figure}\n\\centering\n\\includegraphics{2way_bal}\n\\caption{Sorting \\([a,b,c]\\) by balanced 2-way insertions\n\\label{fig:2way_bal}}\n\\end{figure}\nare shown all the possible traces\\index{tree!evaluation $\\sim$} and\noutcomes of sorting \\([a,b,c]\\). Note that the tree is not\nperfect\\index{tree!perfect $\\sim$}, but balanced, as some arrows\ncorrespond to two rewrites. The \\emph{internal path\n  length}\\label{insertion__internal_path_length}\n\\index{binary tree!internal path length} of the tree is~\\(43\\), that\nis the sum of the lengths of the paths from the root to each internal\nnode, so the average cost is~\\(43/6\\).\n\n\\mypar{Minimum cost}\n\nLet us continue by finding what is the minimum cost of\n\\fun{i2wb/1}. Let us assume that we have the input \\([x_0, x_1, x_2,\nx_3, x_4]\\) and we want it to minimise the rewrites, which means not\nto use rules~\\clause{\\sigma}, \\clause{\\tau}, \\clause{\\phi}\nand~\\clause{\\chi}; also, the usage of rule~\\clause{\\rho} should be\nminimum. The latter rule is not an issue because it reverses the left\nstack and, by design, the right stack has the same length as the left,\nor exceeds it at most by one key. A simple diagram with the two stacks\ninitially empty suffices to convince us that the keys must go\nalternatively to the right and then to the left, leading, for example,\nto \\([x_3 , x_1]\\) and \\([x_4, x_2, x_0]\\). This is perhaps better\nvisualised by means of oriented edges revealing a whirlpool in\n\\fig~\\vref{fig:whirlpool},\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=71 671 185 716]{a1a3a4a2a0}\n\\caption{Best case for \\fun{i2wb/1} if \\(n=5\\)\n\\label{fig:whirlpool}}\n\\end{figure}\nto be contrasted with the spiral in \\fig~\\vref{fig:spiral} for\n\\fun{i2w/1}.\n\nThe rule definining \\fun{i2w/1} has to be used first. Then each key is\ninserted, alternatively by means of rule~\\clause{\\upsilon}\nand~\\clause{\\psi}. Finally, the left stack is reversed by\nrules~\\clause{\\pi} and~\\clause{\\rho}, so the question hinges on\ndetermining the length of the left stack in the best case. By design,\nif the total number of keys is even, then the two stacks will end up\ncontaining, before using rule~\\clause{\\rho}, exactly half of them,\nbecause the stacks have the same length. If the total is odd, the left\nstack contains the integral part of this number halved. Technically,\nlet us note \\(\\B{\\fun{i2wb}}{n}\\) the cost of any call\n\\(\\fun{i2wb}(s)\\), where the stack~\\(s\\) contains \\(n\\)~keys. If \\(p\n\\geqslant 0\\), then\n\\begin{equation*}\n\\B{\\fun{i2wb}}{2p}   = 1 +     2p + p = 3p + 1,\\quad\n\\B{\\fun{i2wb}}{2p+1} = 1 + (2p+1) + p = 3p + 2.\n\\end{equation*}\nAnother, more compact, way to put it is: \\(\\B{\\fun{i2wb}}{n} = 1 + n\n+ \\floor{n/2} \\sim \\tfrac{3}{2}{n}\\). The equivalence is correct\nbecause \\(n/2-1 < \\floor{n/2} \\leqslant n/2\\).\n\n\\paragraph{Exercise}\n\nThe worst case occurs when insertions are repeatedly performed at the\nbottom of the longest stack. Find \\(\\W{\\fun{i2wb}}{n}\\) and\ncharacterise the worst case.\n\n\\mypar{Average cost}\n\nLet us consider the average cost when \\(n=2p\\). Then\\index{i2wb@$\\M{\\fun{i2wb}}{n}$}\n\\begin{equation*}\n\\M{\\fun{i2wb}}{2p} =\n  1 + \\sum_{k=0}^{2p-1}{\\M{}{k}} + \\M{\\curvearrowright}{p},\n\\end{equation*}\nwhere \\(\\M{}{k}\\)~is the average cost of inserting a key into a\nsimulated stack of \\(k\\)~keys and\n\\(\\M{\\curvearrowright}{p}\\)~is\\index{rev@$\\M{\\curvearrowright}{n}$}\nthe cost of reversing \\(p\\)~keys from left to right. The variable~\\(p\\)\nin~\\(\\M{\\curvearrowright}{p}\\) is correct since there are\n\\(\\floor{n/2}\\)~keys in the left stack after all insertions are\nover. Clearly,\n\\begin{equation*}\n\\M{\\curvearrowright}{p} = p + 1.\n\\end{equation*}\nThe determination of~\\(\\M{}{k}\\) requires the consideration of only\ntwo cases: \\(k\\)~is even or not. When analysing the average cost of\n\\fun{i2w/1}, there were much more configurations to take into account\nbecause not all the insertions lead to balanced stacks. If \\(k\\)~is\neven, then there exists an integer~\\(j\\) such that \\(k=2j\\) and\n\\begin{equation*}\n\\M{}{2j} = \\M{}{j,j},\n\\end{equation*}\nwhere \\(\\M{}{j,j}\\) is the average number of rewrites to insert a\nrandom number into a configuration of two stacks of length~\\(j\\). We\nalready computed~\\(\\M{}{p,q}\\) in equation~\\eqref{eq:Mpq}\n\\vpageref{eq:Mpq}. Consequently,\n\\begin{equation*}\n\\M{}{2j} = \\frac{j^2 + 3j + 1}{2j+1}\n         = \\frac{1}{2}{j} - \\frac{1}{4} \\cdot \\frac{1}{2j+1} +\n         \\frac{5}{4}.\n\\end{equation*}\nThe case \\(k=2j+1\\) is similarly derived: \\(\\M{}{2j+1} =\n(j+3)/2\\). Hence:\n\\begin{align}\n\\M{\\fun{i2wb}}{2p}\n  &= 1 + \\sum_{k=0}^{2p-1}{\\M{}{k}} + (p+1)\n   = 2 + p + \\sum_{j=0}^{p-1}{(\\M{}{2j} + \\M{}{2j+1})}\\notag\\\\\n  &= \\frac{1}{2}{p^2} + \\frac{13}{4}{p} + 2 -\n             \\frac{1}{4}\\sum_{j=0}^{p-1}{\\frac{1}{2j+1}}.\n\\label{eq:i2wb_2p}\n\\end{align}\nWe need to find the value of this sum. Let \\(H_n :=\n\\sum_{k=1}^n{1/k}\\) be the \\(n\\)th \\emph{harmonic\n  number}\\index{harmonic number}. Then\n\\begin{equation*}\nH_{2p} = \\sum_{j=0}^{p-1}{\\frac{1}{2j+1}} + \\sum_{j=1}^{p}{\\frac{1}{2j}}\n      = \\sum_{j=0}^{p-1}{\\frac{1}{2j+1}} + \\frac{1}{2}{H_{p}}.\n\\end{equation*}\nWe can now replace our sum by harmonic numbers in\nequation~\\eqref{eq:i2wb_2p}:\n\\begin{equation*}\n\\M{\\fun{i2wb}}{2p}\n  = \\frac{1}{2}{p^2} + \\frac{13}{4}{p} - \\frac{1}{4}{H_{2p}}\n    + \\frac{1}{8}{H_p} + 2.\n\\end{equation*}\nThe remaining case is to find \\(\\M{\\fun{i2wb}}{2p+1}\\), which, by the\nsame reckoning, is\n\\begin{equation*}\n\\M{\\fun{i2wb}}{2p+1}\n  = 1 + \\sum_{k=0}^{2p}{\\M{}{k}} + \\M{\\curvearrowright}{p}.\n\\end{equation*}\nLet us reuse previous calculations:\n\\begin{equation*}\n\\M{\\fun{i2wb}}{2p+1}\n   = \\M{\\fun{i2wb}}{2p} + \\M{}{2p}\n   = \\frac{1}{2}{p^2} + \\frac{15}{4}{p} - \\frac{1}{4}{H_{2p+1}}\n     + \\frac{1}{8}{H_p} + \\frac{13}{4}.\n\\end{equation*}\nWe have \\(1 + x < e^x\\), for all real \\(x \\neq 0\\). In particular,\n\\(x=1/i\\), for~\\(i>0\\) integer, leads to \\(1 + 1/i < e^{1/i}\\). Both\nsides being positive, we deduce \\(\\prod_{i=1}^{n}(1+1/i) <\n\\prod_{i=1}^{n}{e^{1/i}} \\Leftrightarrow n+1 < \\exp(H_n)\\). Finally,\n\\(\\ln(n+1) < H_n\\). An upper bound of~\\(H_n\\) can be similarly derived\nby replacing~\\(x\\) by~\\(-1/i\\):\n\\begin{equation}\n\\ln(n+1) < H_n < 1 + \\ln n.\\label{ineq:Hn}\n\\end{equation}\nWe can now express the bounds on\n\\(\\M{\\fun{i2wb}}{n}\\)\\index{i2wb@$\\M{\\fun{i2wb}}{n}$} without~\\(H_n\\):\n\\begin{align*}\n\\ln(p+1) - 2\\ln(2p) + 14\n&< 8 \\cdot \\M{\\fun{i2wb}}{2p} - 4{p^2} - 26{p}\\\\\n& < \\ln p - 2\\ln(2p+1) + 17;\\\\\n\\ln(p+1) - 2\\ln(2p+1) + 24\n&< 8 \\cdot \\M{\\fun{i2wb}}{2p+1} - 4{p^2} - 30{p}\\\\\n&< \\ln{p} - 2\\ln(2p+2) + 27.\n\\end{align*}\nSetting \\(n=2p\\) and \\(n=2p+1\\) leads to the respective bounds\n\\begin{align*}\n-2\\ln n + \\ln(n+2) + 4 &< \\varphi(n) < -2\\ln(n+1) + \\ln n + 7,\\\\\n-2\\ln n + \\ln(n+1)     &< \\varphi(n) < -2\\ln(n+1) + \\ln(n-1) + 3,\n\\end{align*}\nwhere \\(\\varphi(n) := 8 \\cdot \\M{\\fun{i2wb}}{n} - n^2 - 13n - 10 + \\ln\n2\\). We retain the minimum of the lower bounds and the maximum of the\nupper bounds of~\\(\\varphi(n)\\) so,\n\\begin{equation*}\n\\ln(n+1) - 2\\ln n < \\varphi(n) < -2\\ln(n+1) + \\ln n + 7.\n\\end{equation*}\nWe can weaken the bounds a little bit with \\(\\ln n < \\ln(n+1)\\) and\nsimplify:\n\\begin{equation*}\n0 < 8 \\cdot \\M{\\fun{i2wb}}{n} - n^2 - 13n + \\ln 2n - 10 < 7.\n\\end{equation*}\nTherefore, for all \\(n > 0\\), there exists~\\(\\epsilon_n\\) such that\n\\(0 < \\epsilon_n < 7/8\\) and\n\\begin{equation}\n\\M{\\fun{i2wb}}{n}\n  = \\frac{1}{8}(n^2 + 13n - \\ln 2n + 10) + \\epsilon_n.\n\\label{eq:ave_i2wb}\n\\end{equation}\n\\index{insertion sort!2-way $\\sim$!balanced $\\sim$|)}\n\\index{tri!$\\sim$ par insertions|)}\n", "meta": {"hexsha": "1c9912d188f5e12b18dd41aad1f09a72d62e265a", "size": 69718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "insertion.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": "insertion.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": "insertion.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.9583858764, "max_line_length": 98, "alphanum_fraction": 0.6329355403, "num_tokens": 25604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6961819939095701}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{listings}\n\n\\setlength{\\parindent}{0cm}\n\n\\begin{document}\n\n\\title{CPSC 449 Assignment 4 \\\\ J. Gallagher T01 MW 1400-1450}\n\\author{Andrew Helwer}\n\\date{Winter 2011}\n\\maketitle\n\n\\lstset{language=Haskell, frame=single}\n\n\\section{Question 2}\n\nUsing structural induction on $ys$, prove that for all finite lists $ys$ and $zs$\n\\begin{lstlisting}\nmap f (ys++zs) = map f ys ++ map f zs\n\\end{lstlisting}\n\nBase Case: $ys = []$\n\n\\begin{align*}\n& \\text{map f ([]++(z:zs))} \\\\\n& \\rightsquigarrow \\text{map f (z:zs)} \\\\\n& \\rightsquigarrow \\text{f z : map f zs}\t&\\text{(map.2)} \n\\end{align*}\n\\begin{align*}\n& \\text{map f [] ++ map f (z:zs)} \\\\\n& \\rightsquigarrow \\text{[] ++ map f (z:zs)}\t&\\text{(map.1)} \\\\\n& \\rightsquigarrow \\text{[] ++ f z : map f zs}\t&\\text{(map.2)} \\\\\n& \\rightsquigarrow \\text{f z : map f zs}\n\\end{align*}\n\nThus the base case holds.\n\nInductive Case:\n\nInductive Hypothesis - assume the equation holds for the finite list $ys$ \n\n\\begin{align*}\n& \\text{map f ((y:ys)++zs)} \\\\\n& \\text{f y : map f (ys++zs)}\t\t\t&\\text{(map.2)} \\\\\n& \\text{f y : ((map f ys) ++ (map f zs))}\t&\\text{(IH)} \\\\\n\\end{align*}\n\\begin{align*}\n& \\text{(map f (y:ys)) ++ (map f zs)} \\\\\n& \\text{(f y : map f ys) ++ (map f zs)} \t&\\text{(map.2)} \\\\\n& \\text{f y : ((map f ys) ++ (map f zs)} \\\\\n\\end{align*}\n\nThus the inductive step holds.\n\nThus by structural induction on $ys$, the equation holds for all finite lists $ys$ and $zs$. $\\square$\n\\end{document}\n", "meta": {"hexsha": "d27e942edcf3f187d238addc6c9bf8a92206cb63", "size": 1503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cpsc449/as4/cpsc449as4.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": "cpsc449/as4/cpsc449as4.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": "cpsc449/as4/cpsc449as4.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": 25.4745762712, "max_line_length": 102, "alphanum_fraction": 0.624085163, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.6961807867921523}}
{"text": "\n\\section{The \\maxelement algorithm with predicates}\n\\Label{sec:maxelementii}\n\nIn this section we present another specification of the \\maxelement algorithm.\nThe main difference is that we employ the predicate \\logicref{UpperBound}\nwhich basically expresses that a given value is greater or equal than all\nelements of a given array.\nClosely related to the predicate \\UpperBound is the predicate \\logicref{StrictUpperBound}.\n\nWe also employ the predicate \\logicref{MaxElement}.\nThis predicate states that the element at a given index \\inl{max} is an \n\\emph{upper bound} of the sequence \\inl{a[0..n-1]}, and, by\nconstruction, a member of that sequence.\n\n\\subsection{Formal specification of \\maxelementii}\n\nThe formal specification of \\specref{maxelementii} is shown in the following listing.\nNote that we also use the predicate  \\logicref{StrictUpperBound}\nin order to express that \\maxelementii returns the \\emph{first} maximum position in \\inl{a[0..n-1]}.\n\n\\input{Listings/max_element2.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\maxelementii}\n\nThe implementation of \\implref{maxelementii} is of course\nvery similar to that of \\implref{maxelement}---except that the\nloop invariants now also use the above mentioned predicates.\n\n\\input{Listings/max_element2.c.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "15a1da7130c6300d5fe67679c71a118d8c011adf", "size": 1284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/maxmin/max_element2.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/maxmin/max_element2.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/maxmin/max_element2.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": 35.6666666667, "max_line_length": 100, "alphanum_fraction": 0.7959501558, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6961807793824877}}
{"text": "\\documentclass{article}\n\\title{The Mathematics of Digital Cash}\n\\date{2018-12-23}\n\\author{Joey Yandle}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n%\\usepackage{overunderset}\n\\newcommand\\Set[2]{\\{\\,#1\\mid#2\\,\\}}\n\\newcommand\\underoverset[3]{\\underset{#1}{\\overset{#2}{#3}}}\n\\usepackage{geometry}\n \\geometry{\n   a4paper,\n   total={170mm,257mm},\n   left=20mm,\n   top=20mm,\n }\n\\begin{document}\n\\begin{figure}\n  \\includegraphics[width=\\linewidth]{digitalcash.png}\n\\end{figure}\n\\maketitle\n\nWhile traditional cryptocurrencies were groundbreaking in many ways, they lacked the privacy protections that cash inherently provides.  This document will explore the math which can provide some of those protections.  The goal is to build a cryptocurrency which deserves the name Digital Cash.\n\nThere are many papers which outline, define, use, mutate, expand on, or cite the following techniques.  But these papers invariably use different terminology, swapping variable names and using various subsets as needed.  In this document, I will endeavor to be both thorough and strongly consistent, which should not only make the math easier to understand, but also expose the deep connections and demonstrate how each piece builds on the previous.\n\\newpage\n\n\n\\section{\n  Notation\n}\n\nWe define a hash function $H_n$ as a function that maps an unbounded list of arbitrarily-sized binary inputs to an output set $O$ of $n$ bits:\n\\begin{align}\n  H_n \\coloneqq \\Set{i_1, i_2, ...}{b \\in \\{0,1\\}, k \\in \\mathbb{N}, i \\in {b_1b_2...b_k}} \\mapsto \\Set{b_1b_2...b_n}{b \\in \\{0,1\\}}\\nonumber\n\\end{align}\n\nIf we do not define $n$, then we assume it is implementation dependent, but that the output set is still bounded at some $n$ bits:\n\\begin{align}\n  H \\coloneqq \\Set{i_1, i_2, ...}{b \\in \\{0,1\\}, k \\in \\mathbb{N}, i \\in {b_1b_2...b_k}} \\mapsto \\Set{b_1b_2...b_n}{b \\in \\{0,1\\}}\\nonumber\n\\end{align}\n\n\n\\section{\n  Schnorr Proofs and the Fiat Shamir Transform\n}\n\nSchnorr proofs \\cite{schnorr} allow the owner of a private key to demonstrate that ownership to someone who knows the corresponding public key.  It is an interactive 3-move protocol, i.e. a Sigma protocol.  But like all Sigma protocols, it can be made non-interactive using the Fiat-Shamir transform \\cite{fiatshamir}.  This allows the protocol to function as a signature.\n\nLet $g$ be a generator in a finite group $G$ of prime order $p \\in \\mathbb{P}$, with private key $x \\in \\mathbb{Z}_p$, and public key $y = g^x$. The prover chooses a random $v \\in Z_p$, then sets $t = g^v$.\n\nIn the interactive version of the protocol, the prover sends $t$ to the verifier, who responds with the challenge $c$.  This way the prover cannot choose $t$ after seeing $c$, which would allow the prover to cheat.  To make this non-interactive, Fiat and Shamir proposed to choose $c$ based on a hash including $t$, which prevents the prover from cheating, since $c$ depends on $t$:\n\\begin{align}\n  c = H(g,y,t)\n\\end{align}\n\nThe prover then defines $r$ as below, and calculates it from $(v, c, x)$:\n\\begin{align}\n  r = v - cx\n\\end{align}\n \nThis is equivalent algebraically to\n\\begin{align}\n  v = r + cx \\nonumber\n\\end{align}\n\nWe can use this derived expression for $v$ to expand $t$:\n\\begin{align}\n  t = g^v= g^{r + c x} = g^r g^{cx} = g^r g^{xc} = g^r (g^x)^c = g^r y^c\n\\end{align}\n\nSo if $t = g^r y^c$, then the prover must have known $x$.  Otherwise the prover would not have been able to construct a proper $r$, allowing the equation to balance.  The set $(r,c,t)$ thus forms the proof of ownership of $y$.\n\n\n\n\\section{Ring signatures}\n\nA Schnorr proof allows us to sign a public key, proving we know the corresponding private key.  But the signature is tied to a single key, which is bad for privacy.  It would be better to construct a one out of many signature, to prove that we knew the private key for one out of $N$ public keys.  Such a signature is called a ring signature \\cite{cryptonote}.\n\nStart with public key $y$ for which the prover knows the private key $x$, and as before, choose a random $v \\in \\mathbb{Z}_p$ . To mix in an additional key $y_1$ whose private key $x_1$ is unknown, select a random $r_1$ and $c_1$.  The prover sets $c$ as follows, using the values known to calculate it:\n\\begin{align}\n  c = H(g^v, g^{r_1} y^{c_1}) - c_1\n\\end{align}\n\nThis is equivalent algebraically to:\n\\begin{align}\n  c + c_1 = H(g^v, g^{r_1} y^{c_1})\\nonumber\n\\end{align}\n\nNow that the prover has c, r is as before:\n\\begin{align}\n  r = v - cx\n\\end{align}\n\nThe prover then sends $(y, r, c, y_1, r_1, c_1)$ to the verifier, who then calculates the hash\n\\begin{align}\n  H(g^r y^c, g^{r_1} y_1^{c_1})\\nonumber\n\\end{align}\n\nSince $g^v = g^r y^c$, the two hashes are identical.  Thus \n\\begin{align}\n  c + c_1 = H(g^r y^c, g^{r_1} y_1^{c_1})\n\\end{align}\n\nSo if $\\sum c$ is equal to the hash, then the prover must have known $x$ for some $y$.  And since the prover can put the real $(y,r,c)$ in either position, there is no way for the verifier to know which key was actually signed.\n\nWe can do the same for any number of additional public keys $y_k$: choose a random $(r_k,c_k)$ which is added to the hash in the form of $g^{r_k}y_k^{c_k}$ then subtracting the new $c_k$ from the hash to form the real $c$. Then $\\sum c$ will be equal to the hash for both prover and verifier.\n\n\n\n\\subsection{Linkable Ring Signatures}\n\nNow that we can use ring signatures to hide which public key is being signed, we have a new problem: assuming each public key corresponds to a spendable output, how do we know which output was actually spent?  We need a way to track this to prevent double spends, but in such a way that we preserve the privacy which the ring signature grants.\n\nFirst we construct a key image \\cite{cryptonote}, which is a commitment to the public key used but cannot be used to find the public or private keys, and is unique:\n\\begin{align}\n  I = H(y)^x\n\\end{align}\n\nWe then add a term to the hash for each $y$ that uses the key image.  For the real $y$, we know that\n\\begin{align}\n  H(y)^v &= H(y)^r H(y)^{cx}\\nonumber\\\\\n         &= H(y)^r (H(y)^x)^c\\nonumber\\\\\n         &= H(y)^r I^c\n\\end{align}\n\nPutting the real $y$ first, the prover hash becomes:\n\\begin{align}\n  H(g^v, H(y)^v, g^{r_1} y^{c_1}, H(y_1)^{r_1} I^{c_1})\n\\end{align}\n\nWe define $c$ as before, then solve for the hash:\n\\begin{align}\n  c &= H(g^v, H(y)^v, g^{r_1} y^{c_1}, H(y_1)^{r_1} I^{c_1}) - c_1\\\\\n  c_1 + c &= H(g^v, H(y)^v, g^{r_1} y^{c_1}, H(y_1)^{r_1} I^{c_1})\\nonumber\n\\end{align}\n\nSo as before, $\\sum c$ is equal to the hash.  The prover now sends $(I, y, r, c, y_1, r_1, c_1)$ to the verifier, who can check that their hash is still equal to $\\sum c$:\n\\begin{align}\n  c + c_1 = H(g^r y^c, H(y)^r I^c, g^{r_1} y^{c_1}, H(y)^{r_1} I^{c_1})\n\\end{align}\n\nSince the key image $I$ is now tied to the signature, any attempt to sign two different ring signatures with the same y will result in the same $I$, so preventing double spends is easy.  You just keep track of which key images have previously been used, and reject any new signatures with a previously used $I$.\n\n\n\\subsection{Linkable Spontaneous Anonymous Group Signatures}\n\nLinkable ring signatures do a good job of proving ownership while obscuring origins, but they get large as the number of mixins rises. LSAG signatures address this by constructing the $c$ terms via an iterative process, so it is only necessary to send one of them.  For a large ring, this results in nearly 33\\% space savings.\n\nConsider a set of public keys $y_i, i \\in \\{0, …, n-1\\}$ with a secret index $j$ which denotes the public key to which we know the corresponding private key $x$.  As before, choose random $v$, and $r_i$ $\\forall i \\ne j$.  As with linkable signatures, define $I = H(y_j)^x$. Then define\n\\begin{align}\n      L_j &= g^v\\\\\n      R_j &= H(y_j)^v\\\\\n  c_{j+1} &= H(L_j,R_j)\n\\end{align}\n\nFor the remaining $i \\in \\{j+1, …, n, …, j-1\\}$ ($\\mod{n}$ so $n$ goes to zero, then back to $j$)\n\\begin{align}\n  L_i &= g^{r_i} {y_i}^{c_i}\\\\\n  R_i &= H(y_i)^{r_i} I^{c_i}\\\\\n  c_{i+1} &= H(L_i,R_i)\\\\\n  &... \\nonumber\\\\\n  c_j &= H(L_{j-1}, R_{j-1})\n\\end{align}\n\nNow that we have $c_j$, we can define\n\\begin{align}\n  r_j = v - c_j x\n\\end{align}\n\nThen we can calculate $L_j$ and $R_j$ as we did for all $L_i$ and $R_i$, using $r_j$ and $c_j$, and the values should be equal to the original $L_j$ and $R_j$ calculated using $v$. The prover now sends $(I, y_0, r_0, …, y_{n-1}, r_{n-1}, c_0)$ to the verifier.  The verifier can reconstruct all $(c_i, L_i, R_i)$ and then check that $c_0 = c_n$.\n\n\n\\subsection{Multilayered LSAG Signatures}\n\nLSAG signatures allow a compact representation of a linked ring signature, but each real key needs its own signature, and there is no way to associate the real keys with interleaved data.\n\nThe MLSAG solves this by using key vectors rather than single keys \\cite{ringct}.  So key $y_i$ is instead a vector of $m$ keys\n\\begin{align}\n  y_i = (y_{i,0}, ..., y_{i,m-1})\n\\end{align}\n\nAs before, there exists a secret index $j$, for which we know the private keys to each public key.  Each $r_i$ is now also a vector, and\n\\begin{align}\n  r_i = (r_{i,0}, ..., r_{i,m-1})\n\\end{align}\n\n$\\forall i \\ne j$, $r_i$ consists of random numbers.\n\nThe prover proceeds as with an LSAG, starting with index $j$.  $v$ is now a vector of $m$ elements.  The $L_{j,k}$ and $R_{j,k}$ entries are calculated in the same way, but using $y_{j,k}$ and $v_k$.  $c_{j+1}$ is calculated using all $L_{j,k}$ and $R_{j,k}$:\n\\begin{align}\n  L_{j,k} &= g^{v_k}\\\\\n  R_{j,k} &= H(y_{j,k})^{v_k}\\\\\n  c_{j+1} &= H(L_{j,0}, R_{j,0}, ..., L_{j,m-1}, R_{j,m-1})\n\\end{align}\n\nAs before, the prover calculates the remaining $L_i$ and $R_i$ using the corresponding $c_i$, $r_i$, and $I$, and the hash for $c_{i+1}$ contains the full set of $L_{i,k}$ and $R_{i,k}$:\n\\begin{align}\n  L_{i,k} &= g^{r_{i,k}} y_{i,k}^{c_i}\\\\\n  R_{i,k} &= H(y_i)^{r_{i,k}} I^{c_i}\\\\\n  c_{i+1} &= H(L_{i,0}, R_{i,0}, ..., L_{i,m-1}, R_{i,m-1}) \\\\\n  &... \\\\\n  c_j &= H(L_{j-1,0}, R_{j-1,0}, ..., L_{j-1,m-1}, R_{j-1,m-1}) \n\\end{align}\n\nNow that we have $c_j$, we can calculate the $r_{j,k}$ as before:\n\\begin{align}\n  r_{j,k} = v_k - c_j x_k\n\\end{align}\n\nThe prover sends the same set of $(I, y_0, r_0, ..., y_{m-1}, r_{m-1}, c_0)$ as for LSAG, but each $y_i$ and $r_i$ is now a vector.  The verifier again calculates the full set of $c_i$, with corresponding $L_i$ and $R_i$, and checks that $c_0 = c_n$.\n\n\n\\subsection{Signing external data}\n\nSchnorr proofs and ring signatures do a good job of signing public keys, with a variety of options for obfuscating mixins and consolidating space.  But it is often desirable to sign external data, such as a transaction body.  This way the signature validates not only ownership of the inputs, but also locks the signature to the spent outputs, amounts, or any other metadata which is necessary to prevent transaction malleability.\n\nTo sign external data $d$, take a hash of it then prepend it to the signature hash.  But hashing the external data directly can lead to collisions, which obviates the point of hashing.  So it is common to use domain separators in the hash:\n\\begin{align}\n  m = H(\\textsf{\"transaction body\"}, d)\n\\end{align}\n\nFor a standard linkable ring signature, the prover would do the following:\n\\begin{align}\n  c + c1 = H(m, g^v, H(y)^v, g^{r_1} y^{c_1}, H(y)^{r_1} I^{c_1})\n\\end{align}\n\nThe verifier also has access to the external data, and does the same calculation:\n\\begin{align}\n  m &= H(\\textsf{\"transaction body\"}, d)\\\\\n  c+c1 &= H(m, g^r y^c, H(y)^r I^c, g^{r_1} y^{c_1}, H(y)^{r_1} I^{c_1})\n\\end{align}\n\nThis links the signature to the external data, and if the data is altered the verifier signature will fail validation.\n\n\n\n\\section{Confidential Transactions}\n\nUsing linkable ring signatures, we can obscure (but not hide) the real inputs to a transaction.  However, the amounts of each input must be visible in order to show that the transaction does not generate free coins: the sum of the inputs must equal the sum of the outputs.  How can we hide the actual amounts, while keeping the ability to check that the transaction is balanced?\n\n\n\\subsection{Pedersen Commitments}\n\nWe can again use the difficulty of solving discrete logarithms to hide the real amounts behind a commitment.  The naive approach would be to simply raise our group generator $g$ to the value $v$:\n\\begin{align}\n  C=g^v\n\\end{align}\n\nThen we can check that the sum of the input values is equal to the sum of the outputs:\n\\begin{align}\n  v_{i_1} + v_{i_2} &= v_{o_1} + v_{o_2}\\\\\n  g^{v_{i_1} + v_{i_2}} &= g^{v_{o_1} + v_{o_2}}\\\\\n  g^{v_{i_1}} g^{v_{i_2}} &= g^{v_{o_1}} g^{v_{o_2}}\\\\\n  C_{i_1} C_{i_2} &= C_{o_1} C_{o_2}\n\\end{align}\n  \nSo to check that the transaction is balanced, we check the product of the input commitments against the product of the output commitments: if they are equal, then the transaction is balanced.\n\nThis simple approach does not work, however, because the range of values in a cryptocurrency is usually only $[0, 2^{64})$.  So an attacker can brute force any commitment by trying all $2^{64}$ possible values.  To prevent this, we add a random blinding factor $s$ to the commitment \\cite{ringct}:\n\\begin{align}\n  C = g^s h^v\n\\end{align}\n  \nThis requires another generator $h$, which is usually defined as a hash-to-group of the generator $g$.  If the group is a prime order group, then any element of the group is a generator, and so a simple hash will suffice.  Otherwise, care must be made to assure that $h$ is orthogonal to $g$.\n\nNow when we check the transaction balance, we end up with\n\\begin{align}\n  \\frac{C_{i_1} C_{i_2}}{C_{o_1} C_{o_2}} &= \\frac{g^{s_{i_1}} h^{v_{i_1}} g^{s_{i_2}} h^{v_{i_2}}}{g^{s_{o_1}} h^{v_{o_1}} g^{s_{o_2}} h^{v_{o_2}}}\\\\\n                                          &= g^{s_{i_1} + s_{i_2} - s_{o_1} - s_{o_2}} h^{v_{i_1} + v_{i_2} - v_{o_1} - v_{o_2}}\n\\end{align}\n\nBut if the transaction is balanced, then $v_{i_1} + v_{i_2} - v_{o_1} - v_{o_2} = 0$, so\n\\begin{align}\n  \\frac{C_{i_1} C_{i_2}}{C_{o_1} C_{o_2}} = g^{s_{i_1} + s_{i_2} - s_{o_1} - s_{o_2}}\n\\end{align}\n\nWe define the sum of the input blinding factors minus the output blinding factors to be\n\\begin{align}\n  z = s_{i_1} + s_{i_2} - s_{o_1} - s_{o_2}\n\\end{align}\n\nWhich means that the ratio of the product of the commitments is now just $g^z$, and thus we know the private key $z$ which corresponds to the public key generated from the commitments:\n\\begin{align}\n  \\frac{C_{i_1} C_{i_2}}{C_{o_1} C_{o_2}} = g^z\n\\end{align}\n\nWe already know how to sign a public key if we know the private key, which means we can sign this commitment to zero, and a verifier can check it.  This allows a verifier to validate the transaction is balanced.\n\n\n\\subsection{Range Proofs}\n\nNow that the values can be hidden, we have a new problem.  Since we are checking that the sum of the inputs matches the sum of the outputs, what happens if one of the output values is negative?  The transaction will be balanced, but we will end up minting new coins.  How can we prevent this?  The answer is via the use of range proofs \\cite{ringct}.\n\nFirst, consider a $n$-bit binary expansion of $v$:\n\\begin{align}\n  v = b_0 2^0 + b_1 2^1 + ... + b_{n-1} 2^{n-1}\n\\end{align}\n\nIf $v$ is in the range $[0, 2^{64})$ then we know that each $b_k \\in {0, 1}$.  Remember that we committed to $v$ with $C = g^s h^v$.  Choose a series of $s_k$ such that\n\\begin{align}\n  \\sum_0^{n-1} s_k = s \n\\end{align}\n\nThen write commitments for each bit in the binary expansion thus\n\\begin{align}\n  C_k = g^{s_k} h^{b_k 2^k}\n\\end{align}\n\nAs before, the sum of the values in these commitments will be equal to $v$, but also the sum of the bit blinding factors $s_k$ will also equal $s$.  So\n\\begin{align}\n  C_k = C\n\\end{align}\n\nThis allows the validator to check that the binary expansion is valid.  And if each $b_k \\in {0, 1}$, then one of the following must be a commitment to zero:\n\\begin{align}\n  \\{g^{s_k} h^{b_k 2^k}, g^{s_k} h^{b_k 2^k - 2^k}\\}\n\\end{align}\n\nSo either the first or the second terms will reduce to $g^{s_k}$, and since the prover know $s_k$ he can sign the ring.  We don't need linkability, so we can use basic ring signatures of size $2$. The prover of course knows which term is actually a commitment to zero, and can sign accordingly.\n\nThe range proof thus consists of the $n$ bit commitments $C_i$ and corresponding ring signatures.  The verifier checks the validity of each bit proof, and then verifies that\n\\begin{align}\n  C = \\prod{C_i}\n\\end{align}\n\n\n\n\\section{Bulletproofs}\n\nRange proofs allow us to verify that output commitments are not negative, but they use a lot of space; each output range proof consists of $64$ separate ring signatures.  It would be preferable to somehow consolidate them, and there are a variety of techniques to do so.  Bulletproofs \\cite{bulletproofs} are a compact way to represent aggregated range proofs, and result in significant space savings.\n\nBulletproofs are not just useful as aggregated range proofs; more generally, they also have the ability to represent arbitrary arithmetic circuits.  They have similar functionality with zkSNARKs, but require no trusted setup.\n\n\\subsection{Notation}\n\nThe bulletproofs paper uses several notation systems.  Some were innovative, like the use of boldfaced group elements to represent that they were arrays.  Some were just obscure, like using the $\\circ$ operator to denote pairwise multiplication of vectors,  But other, like using the python$[:n]$ array slicing operator were verbose and annoying.  So pretty much everyone who implented, or tried to explain bulletproofs, ended up replacing something with their own.  Here I will limit myself to replacing the $[:n]$ operator with $B$ for the bottom half and $T$ for the top.  We can do this because we are only ever dealing with powers of two, so it is never ambiguous.\n\n\\subsection{Improved Inner Product Argument}\n\nThe heart of a bulletproof is a vector commitment that links a committed value with an inner product.  The prover uses a recursive protocol that at every step cuts the size of the vectors in half and generates a new commitment, until only a single element remains, then sends the final values with the corresponding generators and commitment as the proof.  The verifier checks that the final commitment is valid, then unwinds the stack.\n\nSo for some $(\\textbf{g}, \\textbf{h}) \\in \\mathbb{G}^n$, $(\\textbf{a}, \\textbf{b}) \\in \\mathbb{Z}_p^n$, $(u, P) \\in \\mathbb{G}$, $c \\in \\mathbb{Z}_p$, let $P = \\textbf{g}^\\textbf{a} \\textbf{h}^\\textbf{b}$ and $c = \\left<\\textbf{a}, \\textbf{b}\\right>$.  The goal is to find a way to prove knowledge of $\\textbf{a}$ and $\\textbf{b}$ to someone who knows $P$ and $c$, without revealing them.  To do this, the prover adds the inner product to the commitment itself:\n\\begin{align}\n  P = \\textbf{g}^\\textbf{a} \\textbf{h}^\\textbf{b} \\cdot u^{\\left<\\textbf{a}, \\textbf{b}\\right>}\n\\end{align}\n\nSince the goal is to shrink the problem in half, let $n' = n/2$.  Since $(\\textbf{g}, \\textbf{h})$ are still size $n$, split each into bottom $(\\textbf{g}_{B}, \\textbf{h}_{B})$ and top $(\\textbf{g}_{T}, \\textbf{h}_{T})$, with the first $n'$ elements in the bottom vector and the second $n'$ in the top.  Then for some $\\textbf{a}_1, \\textbf{a}'_2, \\textbf{b}_1, \\textbf{b}'_2 \\in \\mathbb{Z}_p^n$, define the function $H$ to operate on the split vectors. \n\\begin{align}\n  H(\\textbf{a}_1, \\textbf{a}'_2, \\textbf{b}_1, \\textbf{b}'_2, c) = \\textbf{g}_{B}^{\\textbf{a}_1} \\textbf{g}_{T}^{\\textbf{a}'_2} \\textbf{h}_{B}^{\\textbf{b}_1} \\textbf{h}_{T}^{\\textbf{b}'_2} \\cdot u^c\n\\end{align}\n\nWe can define $P$ in terms of $H$, splitting the real $(\\textbf{a}, \\textbf{b})$ as well into bottom and top:\n\\begin{align}\n  P &= \\textbf{g}^{\\textbf{a}} \\textbf{h}^{\\textbf{b}} \\cdot u^{\\left<a, \\textbf{b}\\right>}\\\\\n    &= \\textbf{g}_{B}^{\\textbf{a}_{B}} \\textbf{g}_{T}^{\\textbf{a}_{T}} \\textbf{h}_{B}^{\\textbf{b}_{B}} \\textbf{h}_{T}^{\\textbf{b}_{T}} \\cdot u^{\\left<\\textbf{a}, \\textbf{b}\\right>}\\\\\n    &= H(\\textbf{a}_{B}, \\textbf{a}_{T}, \\textbf{b}_{B}, \\textbf{b}_{T}, \\left<\\textbf{a}, \\textbf{b}\\right>)\n\\end{align}\n\n$H$ is additively homomorphic:\n\\begin{align}\n  H(\\textbf{a}_1, & \\textbf{a}'_1, \\textbf{b}_1, \\textbf{b}'_1, c_1) \\cdot H(\\textbf{a}_2, \\textbf{a}'_2, \\textbf{b}_2, \\textbf{b}'_2, c_2) = H(\\textbf{a}_1 + \\textbf{a}_2, \\textbf{a}'_1 + \\textbf{a}'_2, \\textbf{b}_1 + \\textbf{b}_2, \\textbf{b}'_1 + \\textbf{b}'_2, c_1 + c_2)\n\\end{align}\n\nNow define $L, R \\in \\mathbb{G}$:\n\\begin{align}\n  L &= H(\\textbf{0}^{n'}, \\textbf{a}_{B}, \\textbf{b}_{T}, \\textbf{0}^{n'}, \\left<\\textbf{a}_{B}, \\textbf{b}_{T}\\right>)\\\\\n  R &= H(\\textbf{a}_{T}, \\textbf{0}^{n'}, \\textbf{0}^{n'}, \\textbf{b}_{B}, \\left<\\textbf{a}_{T}, \\textbf{b}_{B}\\right>)\n\\end{align}\n\nProver sends $(L, R)$ to the verifier, who responds with the challenge $x \\in \\mathbb{Z}_p$.  Prover then combines the left and right parts of (\\textbf{a}, \\textbf{b}) into single vectors using the challenge:\n\\begin{align}\n  \\textbf{a}' &= x \\textbf{a}_{B} + x^{-1} \\textbf{a}_{T}\\\\\n  \\textbf{b}' &= x^{-1} \\textbf{b}_{B} + x \\textbf{b}_{T}\n\\end{align}\n\nProver sends $(\\textbf{a}', \\textbf{b}')$ to verifier, who first computes $P'$ from $(P, L, R, x)$:\n\\begin{align}\n  P' = L^{(x^2)} \\cdot P \\cdot R^{(x^{-2})}\n\\end{align}\n\nVerifier then uses $(x, \\textbf{a}', \\textbf{b}')$ to calculate $Q'$:\n\\begin{align}\n  Q' = H(x^{-1} \\textbf{a'}, x \\textbf{a'}, x \\textbf{b'}, x^{-1} \\textbf{b'}, \\left<\\textbf{a'}, \\textbf{b'}\\right>)\n\\end{align}\n\nVerifier validates if $P' = Q'$.  If we expand $Q'$ we can see why:\n\\begin{align}\n  Q' = H(&x^{-1}(x \\textbf{a}_{B} + x^{-1} \\textbf{a}_{T}), x(x \\textbf{a}_{B} + x^{-1} \\textbf{a}_{T}),\n         x(x^{-1} \\textbf{b}_{B} + x \\textbf{b}_{T}), x^{-1}(x^{-1} \\textbf{b}_{B} + x \\textbf{b}_{T}),\\nonumber\\\\\n         &\\left<x \\textbf{a}_{B} + x^{-1} \\textbf{a}_{T}, x^{-1} \\textbf{b}_{B} + x \\textbf{b}_{T}\\right>)\\nonumber\\\\\n     = H(&\\textbf{a}_{B} + x^{-2} \\textbf{a}_{T}, x^2 \\textbf{a}_{B} + \\textbf{a}_{T},\n          \\textbf{b}_{B} + x^2 \\textbf{b}_{T}, x^{-2} \\textbf{b}_{B} + \\textbf{b}_{T},\n          x^2 \\left<\\textbf{a}_{B}, \\textbf{b}_{T}\\right> + \\left<\\textbf{a}, \\textbf{b}\\right> + x^{-2} \\left<\\textbf{a}_{T}, \\textbf{b}_{B}\\right>)\n\\end{align}\n\nIt's because we get the same thing when we expand $P'$:\n\\begin{align}\n  P' = H(&\\textbf{0}^{n'}, x^2 \\textbf{a}_{B}, x^2 \\textbf{b}_{T}, \\textbf{0}^{n'}, x^2 \\left<\\textbf{a}_{B}, \\textbf{b}_{T}\\right>) \\cdot \n       H(\\textbf{a}_{B}, \\textbf{a}_{T}, \\textbf{b}_{B}, \\textbf{b}_{T}, \\left<\\textbf{a}, \\textbf{b}\\right>) \\cdot \\nonumber\\\\\n       H(&x^{-2} \\textbf{a}_{T}, \\textbf{0}^{n'}, \\textbf{0}^{n'}, x^{-2} \\textbf{b}_{B}, x^{-2} \\left<\\textbf{a}_{T}, \\textbf{b}_{B}\\right>)\\nonumber\\\\\n     = H(&\\textbf{a}_{B} + x^{-2} \\textbf{a}_{T}, x^2 \\textbf{a}_{B} + \\textbf{a}_{T},\n          \\textbf{b}_{B} + x^2 \\textbf{b}_{T}, x^{-2} \\textbf{b}_{B} + \\textbf{b}_{T},\n          x^2 \\left<\\textbf{a}_{B}, \\textbf{b}_{T}\\right> + \\left<\\textbf{a}, \\textbf{b}\\right> + x^{-2} \\left<\\textbf{a}_{T}, \\textbf{b}_{B}\\right>)\n\\end{align}\n\nSo if the prover can construct $(L, R, \\textbf{a'}, \\textbf{b'})$ such that $P' = Q'$, then he must have known $(\\textbf{a}, \\textbf{b})$.\n\n\n\\subsection{Range Proof Using Inner Product}\n\nLet $\\textbf{a}_L$ be a vector with the $n$ bits of $v$.  Then the following must all be true:\n\\begin{align}\n  \\left<\\textbf{a}_L, 2^n\\right> = v ; \\textbf{a}_L \\circ  \\textbf{a}_R = \\textbf{0}^n ; \\textbf{a}_R = \\textbf{a}_L - \\textbf{1}^n\n\\end{align}\n  \n$\\textbf{a}_R$ is defined to be the negation of $\\textbf{a}_L$: $0$ where $1$, and $-1$ where $0$.  So any pairwise multiplication between $\\textbf{a}_R$ and $\\textbf{a}_L$ will be $0$.\n\nGiven a verifier chosen $y \\in \\mathbb{G}$, these relations are equivalent to:\n\\begin{align}\n  \\left<\\textbf{a}_L, 2^n\\right> = v ; \\left<\\textbf{a}_L, \\textbf{a}_R \\circ y^n\\right> = 0 ; \\left<\\textbf{a}_L - \\textbf{1}^n - \\textbf{a}_R, \\textbf{y}^n\\right> = 0\n\\end{align}\n\nAs before, pairwise multiplication between $\\textbf{a}_R$ and $\\textbf{a}_L$ will be $0$, regardless of multiplying by $\\textbf{y}^n$, and summing the dot product will likewise be $0$. And solving the third relation for $0$ gives us another dot product of $0$ with our new $\\textbf{y}^n$.\n\nUsing another verifier chosen $z \\in \\mathbb{G}$, we can combine these into one relation:\n\\begin{align}\n  z^2 \\cdot \\left<\\textbf{a}_L, 2^n\\right> + z \\cdot \\left<\\textbf{a}_L - 1^n - \\textbf{a}_R, y^n\\right> + \\left<\\textbf{a}_L, \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v\n\\end{align}\n\nMultiplying the first relation by $z^2$ gives us the $z^2 v$ term, and since the other two relations were $0$ we can add them for free (swapping order and multiplying one by $z$).\n\nIf we expand the inner products, then start isolating prover and verifier terms, we get:\n\\begin{align}\n  z^2 \\cdot \\left<\\textbf{a}_L, \\textbf{2}^n\\right> + z \\cdot \\left<\\textbf{a}_L, \\textbf{y}^n\\right> - z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right> - z \\cdot \\left<\\textbf{a}_R, \\textbf{y}^n\\right> + \\left<\\textbf{a}_L, \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v\\nonumber\\\\\n  z^2 \\cdot \\left<\\textbf{a}_L, \\textbf{2}^n\\right> + z \\cdot \\left<\\textbf{a}_L, \\textbf{y}^n\\right> - z \\cdot \\left<\\textbf{a}_R, \\textbf{y}^n\\right> + \\left<\\textbf{a}_L, \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right>\\nonumber\n\\end{align}\n\nSince an inner product $\\left<\\textbf{a}, \\textbf{b}\\right>$ can be broken into a pairwise/inner product $\\left<\\textbf{1}^n, \\textbf{a} \\textbf{b}\\right>$:\n\\begin{align}\n  z^2 \\cdot \\left<\\textbf{a}_L, \\textbf{2}^n\\right> + z \\cdot \\left<\\textbf{a}_L, \\textbf{y}^n\\right> - z \\cdot \\left<\\textbf{1}^n, \\textbf{a}_R \\circ \\textbf{y}^n\\right> + \\left<\\textbf{a}_L, \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right>\\nonumber\\\\\n  \\left<\\textbf{a}_L, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n\\right> + \\left<\\textbf{a}_L - z \\cdot \\textbf{1}^n, \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right>\\nonumber\n\\end{align}\n\nIn order to merge the inner products via the first term, add $\\left<-z \\textbf{1}^n, z^2 \\textbf{2}^n + z \\textbf{y}^n\\right>$:\n\\begin{align}\n  \\left<\\textbf{a}_L - z \\cdot \\textbf{1}n, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n + \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right> + \\left<-z \\cdot \\textbf{1}^n, z2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n\\right>\\nonumber\\\\\n  \\left<\\textbf{a}_L - z \\cdot \\textbf{1}n, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n + \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right> - z \\cdot \\left<\\textbf{1}^n, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n\\right>\\nonumber\\\\\n  \\left<\\textbf{a}_L - z \\cdot \\textbf{1}^n, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n + \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + z \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right> - z3 \\cdot \\left<\\textbf{1}^n, \\textbf{2}^n\\right> - z^2 \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right>\\nonumber\\\\\n  \\left<\\textbf{a}_L - z \\cdot \\textbf{1}^n, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n + \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + (z - z^2) \\cdot \\left<\\textbf{1}^n, \\textbf{y}^n\\right> - z^3 \\left<\\textbf{1}^n, \\textbf{2}^n\\right>\\nonumber\n\\end{align}\n  \nLet $d(y,z) = (z - z^2) \\left<\\textbf{1}^n, \\textbf{y}^n\\right> - z^3 \\left<\\textbf{1}^n, \\textbf{2}^n\\right>$, and we get the final form:\n\\begin{align}\n  \\left<\\textbf{a}_L - z \\cdot \\textbf{1}^n, z^2 \\cdot \\textbf{2}^n + z \\cdot \\textbf{y}^n + \\textbf{a}_R \\circ \\textbf{y}^n\\right> = z^2 v + d(y,z)\n\\end{align}\n\nThe verifier can calculate the right side (using the commitment $V$ for $v$), and the problem is now reduced to an inner product argument.\n\n\n\\subsection{Blinding the inner product}\n\nWe have shown how to make a logarithmically efficient inner product argument, and how to reduce a range proof to an inner product.  But the inner product argument is not zero knowledge, so we can't use it directly; we must first blind the parameters.\n\nLet $(\\textbf{s}_L, \\textbf{s}_R)$ be vectors of integers:\n\\begin{align}\n  (\\textbf{s}_L, \\textbf{s}_R) \\leftarrow \\mathbb{Z}_p^n\n\\end{align}\n\nReplace $\\textbf{a}_L$ with $(\\textbf{a}_L + \\textbf{s}_L x)$ and $\\textbf{a}_R$ with $(\\textbf{a}_R + \\textbf{s}_R x)$, and the inner product becomes:\n\\begin{align}\n  \\left<(\\textbf{a}_L + \\textbf{s}_L x) - z \\textbf{1}^n, z^2 \\textbf{2}^n + z \\textbf{y}^n + (\\textbf{a}_R + \\textbf{s}_R x)\\circ\\textbf{y}^n\\right> = z^2 v + d(y,z)\n\\end{align}\n\nThen construct vector polynomials $l(x)$ and $r(x)$ from the two sides of the inner product:\n\\begin{align}\n  l(x) &= \\textbf{a}_L + \\textbf{s}_L x - z \\textbf{1}^n\\\\\n  r(x) &= z^2 \\textbf{2}^n + z \\textbf{y}^n + (\\textbf{a}_R+ \\textbf{s}_R x)\\circ\\textbf{y}^n\n\\end{align}\n\nThe zeros of these vector polynomials are just the unblinded inner product terms:\n\\begin{align}\n  l(0) &= \\textbf{a}_L - z \\textbf{1}^n\\\\\n  r(0) &= z^2 \\textbf{2}^n + z \\textbf{y}^n + \\textbf{a}_R\\circ\\textbf{y}^n\n\\end{align}\n\nThe inner product then becomes\n\\begin{align}\n  \\left<l(0), r(0)\\right> = z^2 v + d(y,z)\n\\end{align}\n\nWe can express $l(x)$ and $r(x)$ as generic degree one polynomials\n\\begin{align}\n  l(x) &= l_0 + l_1 x\\\\\n  r(x) &= r_0 + r_1 x\n\\end{align}\n\nWhere\n\\begin{align}\n  l_0 &= \\textbf{a}_L - z \\textbf{1}^n\\\\\n  l_1 &= \\textbf{s}_L\\\\\n  r_0 &= z^2 \\textbf{2}^n + z \\textbf{y}^n + \\textbf{a}_R\\circ\\textbf{y}^n\\\\\n  r_1 &= \\textbf{s}_R\\circ\\textbf{y}^n\\\\\n\\end{align}\n\nIf we define $t(x)$ as the inner product of the blinded vector polynomials, we get\n\\begin{align}\n  t(x) = \\left<l(x), r(x)\\right> \n\\end{align}\n\nWe can express this in terms of x:\n\\begin{align}\n  t(x) = t_0 + t_1 x + t_2 x^2\n\\end{align}\n\nWhere\n\\begin{align}\n  t_0 &= \\left<l_0, r_0\\right> = z^2 v + d(y,z)\\\\\n  t_2 &= \\left<l_1, r_1\\right>\\\\\n  t_1 &= \\left<l_0 + l_1, r_0 + r_1\\right> - t_0 - t_2\n\\end{align}\n\nProving the blinded inner product range proof now depends on simply verifying that both \n\\begin{align}\n  t_0 &= z^2 v + d(y,z)\\\\\n  t(x) &= \\left<l(x), r(x)\\right> = t_0 + t_1 x + t_2 x^2\n\\end{align}\n\n\n\n\\section{CryptoNote}\n\nCryptoNote \\cite{cryptonote} is a privacy focused cryptocurrency system which implements many of the techniques explored above, plus a novel method for tying long term public keys to one time addresses.  CryptoNote is defined to use elliptic curves rather than exponentials, but I will break with that to maintain consistency with the rest of the document, and use exponentials in this section.\n\n\n\\subsection{One time addresses}\n\nA CryptoNote key consists of a pair of public keys $(A, B)$ with their associated private keys $(a, b)$.  To construct a one time address, the creator of a transaction starts with a transaction private key $r$, and an associated transaction public key $R$:\n\\begin{align}\n  R=g^r\n\\end{align}\n\nThe creator then uses this, with the destination public key $(A, B)$, to construct the one time address $y$.  This address is a public key, with an associated private key $x$:\n\\begin{align}\n  y = g^x = g^{H(rA)} B\n\\end{align}\n\nThe owner of the destination key $(A, B)$ can scan the transaction one time addresses to determine if he is the owner.  He first uses his private key $(a, b)$ to attempt to recover the one time private key $x$:\n\\begin{align}\n\tx = H(Ra) + b\n\\end{align}\n\nThen raise $g$ to this power to reconstruct the public key $y$:\n\\begin{align}\n  g^x = g^{H(Ra)} g^b\n\\end{align}\n\nIf $y = g^x$, then the destination key was the same one used to construct the one time address, and the key owner is the owner of the one time address.  Since the owner knows the private key $x$, he is able to sign the key $y$ in a ring signature, allowing him to spend it.\n\n\n\\subsection{View keys}\n\nOne time addresses allow a user to find the transaction outputs which he owns.  But this requires the user to scan the entire blockchain, looking at every output.  For users with limited storage and bandwidth, this can be problematic.  It would be preferable to allow a trusted node to do the scanning for the user, while preventing the node from being able to spend the output.\n\nTo do this, the user can pass a tuple of his private key $a$ with his public key $B$:\n\\begin{align}\n  V = (a, B)\n\\end{align}\n\nThe node can then look at each transaction, and use the view key with the transaction public key $R$ to attempt to reconstruct the one time public key $y$:\n\\begin{align}\n  Y = g^{H(Ra)} B\n\\end{align}\n\nIf $Y = y$, then the node knows that the one time key belongs to the user, and returns it.\n\n\n\\subsection{Ring signatures}\n\nCryptoNote uses linkable ring signatures, with external data.  It defines a transaction prefix to be all of the transaction data except for the ring signatures themselves, which includes the input and output public keys, with the transaction public key and amounts.  The transaction prefix is serialized then hashed to create the signed message m.\n\n\n\n\\section{Monero}\n\nMonero is a privacy focused cryptocurrency.  In its initial implementation, it used a vanilla implementation of cryptonote \\cite{cryptonote}.  Later iterations added confidential transactions, with standard range proofs \\cite{ringct}.  Recent work includes upgrading the range proofs with bulletproofs for significant space savings.\n\n\n\\subsection{RingCT}\n\nThe Monero implementation of confidential transactions is called RingCT \\cite{ringct}.  It uses MLSAG signatures that tie a set of Pedersen Commitments to a set of input keys.  This is necessary because to verify a confidential transaction, it is required to have a full set of the commitments used in order to recover $g^z$.  Without the MLSAG, any attempt to include the commitments would either be unable to recover $g^z$, or would expose the real input keys.\n\nTo accomplish this, the MLSAG signature adds the corresponding commitments to the public key vectors, then passes them in the signature output:\n\\begin{align}\n  y_i = ((y_{i,0}, C_{i,0}), ..., (y_{i,m-1}, C_{i,m-1}))\n\\end{align}\n\nWhen constructing the hashes, the prover signs a final term which is the sum of the input commitments minus the sum of the output commitments:\n\\begin{align}\n  g^z &= \\frac{C_i}{C_o}\\\\\n  L_{j,m} &= g^{v_m}\\\\\n  c_{j+1} &= H(L_{j,0}, R_{j,0}, ... , L_{j,m-1}, R_{j, m-1}, L_{j,m})\n\\end{align}\n\nAs before, if this sum is a commitment to zero, then it will take the form of a public key $g^z$, where the user knows the private key $z$.  So it can be signed like any other public key in a ring signature.  Since the commitment does not need to be linkable, it is not necessary to include a $R_{j,m}$ term, or a key image.  It will be necessary to create a new $v_m$ and include an additional $r_{j,m}$ in the signature:\n\\begin{align}\n  r_{j,m} = v_m - c_j z\n\\end{align}\n\nThe verifier uses this additional $r_{j,m}$ and $c_j$ to build a standard Schnorr term:\n\\begin{align}\n  c_{j+1} = H(L_{j,0}, L_{j,0}, ... , L_{j,0}, L_{j,0}, g^{r_{j,m}} y^{c_j})\n\\end{align}\n\nAs before, if the sum was a commitment to zero, then this term will be the same in the prover and verifier hashes.\n\n\n\n\\section{Zcash}\n\nZcash is one of the more technically advanced cryptosystems available on current exchanges.  It uses zero-knowledge proofs to allow for completely hidden transactions, that can still be validated externally.  It divides its address space into t-addresses, whose details are transparent, and z-addresses, which are hidden from all but the participants.  Money that passes from a t-address to a z-address cannot be tracked, even if it later goes back to a t-address.\n\n\n\\subsection{zkSNARKs}\n\nA zkSNARK is a zero-knowledge, short, non-interactive argument of knowledge.  It allows the prover to create a representation of an arbitrary arithmetic or logic circuit, then make proofs about assertions relative to that circuit.  The proofs are computationally difficult to construct, though easier to evaluate, and require a trusted setup between prover and verifier.\n\n\n\n\\section{Lelantus}\n\nThere is a new Zerocoin based cryptocurrency system called Lelantus \\cite{lelantus}, released 2018-12-22.  It uses confidential transactions, and claims to be able to hide the inputs fully while still being auditable.  \n\nAs per Zerocoin, Lelantus uses the output commitments as the transaction inputs/outputs themselves, rather than associating the commitments with a one time address as in RingCT.  It is thus necessary to reveal the commitment secret during the spend, similar to the way that CryptoNote reveals the key image.  So it is necessary to make the commitments double blind, or else after secret reveal it would be possible to brute force the values as per the naive approach to Pedersen commitments.  Adapting Lelantus to a more CryptoNote-ish system could obviate this need, and allow single blinded commitments.\n\n\n\\subsection{$\\Sigma$-protocol for commitment to $0$ or $1$}\n\nConsider a commitment to a message $m$ with random blinding factor $r$:\n\\begin{align}\n  c=Com(m, r)\n\\end{align}\n\nTo prove that $c$ opens to $0$ or $1$, pick random $(a,s,t)$ and use them to construct $(c_a, c_b)$:\n\\begin{align}\n  a,s,t &\\in \\mathbb{Z}_p\\\\\n  c_a &= Com(a, s)\\\\\n  c_b &= Com(am, t)\n\\end{align}\n\nIn an interactive protocol, the prover would send $(c_a,c_b)$ to the verifier, who would respond with the challenge $x$.  To make it non-interactive, hash $(c, c_a, c_b)$:\n\\begin{align}\n  x = H(c, c_a, c_b)\n\\end{align}\n\nEither way, the prover uses $x$ to construct $(f, z_a, z_b)$ and sends it to the verifier:\n\\begin{align}\n  f &= mx + a\\\\\n  z_a &= rx + s\\\\\n  z_b &= r(x-f) + t\n\\end{align}\n\nThe verifier now has the full set of $(c, c_a, c_b, x, f, z_a, z_b)$ and accepts the proof if both of the following are true:\n\\begin{align}\n  c^x c_a &= Com(f, z_a)\\\\\n  c^{x-f} c_b &= Com(0, z_b)\n\\end{align}\n\nThis follows as \n\\begin{align}\n  c^x c_a &= Com(xm,xr) \\cdot Com(a,s)\\\\\n          &= Com(xm+a, xr+s)\\\\\n          &= Com(f, za)\\\\\n  c^{x-f} c_b &= Com((x-f)m, (x-f)r) \\cdot Com(am, t)\\\\\n              &= Com(xm - fm + am, (x-f)r + t)\\\\\n              &= Com(xm - (mx + a)m + am, z_b)\\\\\n              &= Com(xm - m^2 x, z_b)\n\\end{align}\n\nSince $x$ is not $0$, then $x (m-m^2)$ is only $0$ when $(m-m^2)$ is $0$, or when\n\\begin{align}\n  m = m^2\n\\end{align}\n\nThis is only true $\\forall m \\in {0,1}$.  So if $c^{x-f} c_b = Com(0,zb)$, $m \\in {0,1}$.\n\n\n\\subsection{One out of Many $\\Sigma$-proofs}\n\nRing signatures allow hiding a signature in a set of mixins.  But they grow in size linearly with the mixin set size.  So the mixin set must be limited, and cannot contain every transaction in the ledger.  Merkle proofs offer a logarithmic sized proof for ledger inclusion, but are not zero knowledge.  It would be ideal to be able to demonstrate both ownership and leder inclusion with a single proof.  One out of many proofs do this, in logarithmic size.  So every output in the ledger functions as a mixin, and the proof size scales logarithmically with the ledger size.\n\nConsider a set of $N$ commitments:\n\\begin{align}\n  c_i = g^{s_i} h^{v_i}\n\\end{align}\n\nIf we know that this set contains a commitment to $0$, then we know an index $l$ such that\n\\begin{align}\n  c_l = \\prod_{i=0}^{N-1} c_i^{\\delta_{il}}\n\\end{align}\n\nis a commitment to zero.  This is true because $\\delta_{ll} = 1$, while all other $\\delta_{il} = 0$. So this product is simply $c_l$ as the rest of the $c_i$ are canceled by raising to $0$.\n\nAssuming $N = 2^n$, extending as necessary, expand $i$ and $l$ in binary:\n\\begin{align}\n  i = i_1...i_n\\\\\n  l = l_1...l_n\n\\end{align}\n\nWe can now express $\\delta_{il}$ in terms of these bits:\n\\begin{align}\n  \\delta_{il} = \\prod_{j=1}^{n} \\delta_{i_jl_j}\n\\end{align}\n  \nCombining these two terms, our commitment to $0$ $C$ becomes\n\\begin{align}\n  C = \\prod_{i=0}^{N-1}c_i^{\\prod_{j=1}^{n} \\delta_{i_jl_j}}\n\\end{align}\n\nNext we iterate over all $n$ bits, committing to the bits of $l$ and proving they are all zero or one using the previous protocol.  After getting the challenge $x$ we will generate an $f$, but now there is one for each bit of $l$:\n\\begin{align}\n  f_j = l_j x + a_j\n\\end{align}\n\nWe can further define $f_{j, i_j}$ as a function of $f_j$ that depends on $i_j$:\n\\begin{align}\n  f_{j,1} = f_j = l_j x + a_j\\\\\n  f_{j,0} = x - f_j = (1 - l_j) x - a_j\n\\end{align}\n\nFor each $i$, we can take the product $p_i(x)$ of the $f_{j, i_j}$ terms:\n\\begin{align}\n  p_i(x) = \\prod_{j=1}^{n} f_{j, i_j}\n\\end{align}\n\nIn all cases, $f_{j, i_j}$ will be a linear function of $x$, so $p_i(x)$ will be a polynomial in $x$ of degree $n$; but the $x$ term will cancel $\\forall j$ such that $l_j \\ne i_j$.  So $\\forall i \\ne l$, at least one of the $x$ terms will cancel; thus\n\\begin{align}\n  p_i(x) = \\prod_{j=1}^n f_{j,i_j} = {\\prod_{j=1}^{n}\\delta_{i_jl_j} x} + \\sum_{k=0}^{n-1}{p_{i,k} x^k}\n\\end{align}\n\nIf we have $x$, then we can calculate this product directly.  But before we have $x$, we can still evaluate this polynomial algebraically.  If we do so, we can determine the $p_{i,k}$ parameters in terms of $a_j$.  This allows us to use $p_{i,k}$ once we have $a_j$:\n\nFor all $j = (1, ..., n)$ with $k = j - 1$:\n\\begin{align}\n  (&r_j, a_j, s_j, t_j, \\rho_j) \\longleftarrow \\mathbb{Z}_q\\\\\n  &c_{l_j} = Com(l_j; r_j)\\\\\n  &c_{a_j} = Com(a_j; s_j)\\\\\n  &c_{b_j} = Com(l_j a_j; t_j)\\\\\n  &c_{d_k} = \\prod_{i=0}^{N-1}{c_i^{p_{i,k}}} \\cdot Com(0; \\rho_k)\n\\end{align}\n\nThe verifier responds with the challenge $x$, or it is generated via Fiat-Shamir.  Prover then uses $x$ as per the previous protocol to construct, $\\forall j$:\n\\begin{align}\n  f_j &= l_j + a_j\\\\\n  z_{a_j} &= r_j x + s_j\\\\\n  z_{b_j} &= r_j (x - f_j) + t_j\n\\end{align}\n\nThe prover then constructs the final value:\n\\begin{align}\n  z_d = r x^n - \\sum_{k=0}^{n-1}{\\rho_k x^k}\n\\end{align}\n\nThe verifier must check the individual bit proofs:\n\\begin{align}\n  c_{l_j}^x c_{a_j} &= Com(f_j; z_{a_j})\\\\\n  c_{l_j}^{x-f_j} c_{b_j} &= Com(0; z_{b_j})\n\\end{align}\n    \nAs before, the first line proves knowledge of $l_j$, and the second proves it was binary.  Finally, the verifier checks $z_d$ against $c_{d_k}$ using $c_i$ and $f_{j,i_j}$:\n\\begin{align}\n  \\prod_{i=0}^{N-1}{c_i^{\\prod_{j=1}^{n}{f_{j,i_j}}}} \\prod_{k=0}^{n-1}{c_{d_k}^{-x^k}} = Com(0; z_d)\n\\end{align}\n\nIf we simplify using $p_i(x)$ and expand we can see why this is true:\n\\begin{align}\n  \\prod_{i=0}^{N-1}{c_i^{\\prod_{j=1}^{n}{f_{j,i_j}}}} &  \\prod_{k=0}^{n-1}{c_{d_k}^{-x^k}} = \\prod_{i=0}^{N-1}{c_i^{p_i(x)}} \\prod_{k=0}^{n-1}{(\\prod_{i=0}^{N-1}{c_i^{p_{i,k}}} Com(0; \\rho_k))^{-x^k}}\\\\\n      &= \\prod_{i=0}^{N-1}{c_i^{  \\underoverset{j=1}{n}{\\prod}{\\delta_{i_jl_j} x} + \\underoverset{k=0}{n-1}{\\sum}{p_{i,k} x^k}   }} \\prod_{k=0}^{n-1}{(\\prod_{i=0}^{N-1}{c_i^{p_{i,k}}} Com(0; \\rho_k))^{-x^k}}\\\\\n      &= c_l^{x^n} \\prod_{i=0}^{N-1}{c_i^{ \\underoverset{k=0}{n-1}{\\sum}{p_{i,k} x^k} }}        \\prod_{k=0}^{n-1}{ Com(0; \\rho_k)^{-x^k}}         \\prod_{k=0}^{n-1}{(\\prod_{i=0}^{N-1}{c_i^{p_{i,k}}})^{-x^k}}\\\\\n      &= Com(0; r x^n) \\prod_{k=0}^{n-1}{ Com(0; \\rho_k)^{-x^k}}      \\prod_{k=0}^{n-1}{\\prod_{i=0}^{N-1}{c_i^{p_{i,k}  x^k}}}          \\prod_{k=0}^{n-1}{\\prod_{i=0}^{N-1}{c_i^{-p_{i,k} x^k}}}\\\\\n      &= Com(0; r x^n) \\prod_{k=0}^{n-1}{ Com(0; \\rho_k)^{-x^k}}\\\\\n  Com(0; z_d) &= Com(0; rx^n - \\sum_{k=0}^{n-1}{\\rho_k x^k})\\\\\n      &= Com(0; rx^n) \\prod_{k=0}^{n-1}{Com(0; \\rho_k)^{-x^k}}\n\\end{align}\n\n\n\\subsection{Hiding Transaction Amounts and Origins}\n \nConfidential Transactions are good at hiding amounts, but it is necessary to reveal the commitments themselves in order to prove that a transaction is balanced, i.e. that the sum of the inputs equals the sum of the outputs.  RingCT obfuscates the actual input commitments in a ring of mixins (with both addresses and commitments), but the data is still present and subject to analysis.  It would be better to be able to prove both input ownership and transaction balance without ever showing the input commitments.\n\nLelantus accomplishes this via a two step process.  It establishes input ownership via a set of one out of many $\\Sigma$-proofs, then uses elements of the $\\Sigma$-proofs to to establish a balance proof.  At no time are the input commitments themselves revealed to the verifier.\n\nTo show how the balance proof arises from the elements of the $\\Sigma$-proofs, consider the following values:\n\\begin{align}\n  z_i &= v_i x^n - \\sum_{k=0}^{n-1}{\\rho_k^i x^k}\\\\\n  Com(0, \\rho_k^i) &= g^0 h^{\\rho_k^i}\n\\end{align}\n\nThe verifier can then compute the following:\n\\begin{align}\n  A &= (\\prod_{i=1}^{N_{new}}{C_{o_i}})^{x^n} = (\\prod_{i=1}^{N_{new}}{g^{s_{o_i}} h^{v_{o_i}}})^{x^n}  =  g^{(\\Sigma s_o) x^n}  h^{(\\Sigma v_o) x^n}\\\\\n  B &= Com(0, \\sum_{i=1}^{N_{old}}{z_i}) \\prod_{i=1}^{N_{old}}{(\\prod_{k=0}^{n-1} Com(0, \\rho_k^i)^{x^k})}\\\\\n    &= g^0 h^{(\\sum{v_i}) x^n} \\prod_{i=1}^{N_{old}}{h^{-\\sum_{k=0}^{n-1}{\\rho_k^i x^k}}} \\prod_{i=1}^{N_{old}}{(\\prod_{k=0}^{n-1}{g^0 h^{\\rho_k^i x^k}})}\\\\\n    &= h^{(\\sum{v_i}) x^n} \\prod_{i=1}^{N_{old}}{h^{-\\sum_{k=0}^{n-1}{\\rho_k^i x^k}}}  \\prod_{i=1}^{N_{old}}{h^{\\sum_{k=0}^{n-1}{\\rho_k^i x^k}}}\\\\\n    &= h^{(\\sum{v_i}) x^n}\n\\end{align}\n\nThe ratio of A to B is thus:\n\\begin{align}\n  \\frac{A}{B} = \\frac{g^{(\\sum{s_o}) x^n} g^{(\\sum{v_o}) x^n}}{g^{(\\sum{v_i}) x^n}}\n\\end{align}\n  \nAs before, if the transaction is balanced then \n\\begin{align}\n  \\sum{v_i} = \\sum{v_o}\n\\end{align}\n\nAnd thus\n\\begin{align}\n  \\frac{A}{B} = g^{(\\sum{s_o}) x^n}\n\\end{align}\n\nSince the prover knows the output serial numbers, this is a public key to which he knows the private key.  So it suffices to provide a regular Schnorr proof for this ratio to prove that the transaction is balanced, and no input commitments have been revealed.\n\n\n\n\\section{Mimblewimble}\n\nSome of the most recently released cryptocurrencies use a relatively new system called Mimblewimble \\cite{mimblewimble}.  The goals are to implement a system with the benefits of RingCT, but with a pruned blockchain that still verifies even after removing spent outputs.  As a downside, the sender and receiver of a transaction must complete an interactive protocol.\n\n\n\\subsection{One Way Aggregate Signatures}\n\nWhile RingCT uses ring signatures with mixins to obscure the links between inputs and outputs, Mimblewimble rather aggregates all of the transactions in a block via a technique they call One Way Aggregate Signatures \\cite{increasingBitcoinAnonymity}.  Thus the individual links between the inputs and outputs of the transactions is lost, and only the block level linking is still present.  This happens naturally as a result of the transaction format.\n\nConsider a transaction with input commitments $C_i$ and output commitments $C_o$.  As with all implementations of confidential transactions, the sum of the input commitments minus the outputs will be the ratio of their products, and this will be a public key to which the owner knows the private key:\n\\begin{align}\n  \\frac{\\prod C_i}{\\prod C_o} = g^{s_i - s_o} = g^z = C_T\n\\end{align}\n\nThe transaction format is thus the set $(C_{i_1}, ..., C_{i_N}, C_{o_1}, ..., C_{o_M}, C_T)$, with a signature on CT to prove the balance.  Given this format, it is trivial to combine transactions; you can simply add the new input, output, and balance commitments to the existing set, and the balance check should still succeed with the combined sets:\n\\begin{align}\n  \\prod (\\frac{\\prod C_i}{\\prod C_o})_k= \\prod (C_T)_k\n\\end{align}\n\nA verifier can check the signatures on the individual $C_T$ and the aggregated balance check; if they all succeed, the aggregated transaction set is still valid.\n\nUsing this technique, miners will aggregate all of the transactions in a block into a single set with a single aggregated signature.  After the new block is formed, nodes can again merge the transactions from the new block into the set of all transactions.  Once this is done, any spent outputs will appear in both the output list and the input list.  Such outputs can be safely pruned from both lists, and a balance check over the entire ledger will still be valid.  This is clear, as any such transactions will appear in both the top and bottom of the input/output ratio, and will thus cancel each other out.  \n\nThanks to this pruning, Mimblewimble achieves its goal of maintaining a lightweight ledger, with only unspent outputs and no inputs.  This makes the ledger small, only growing with the UTXO set.  And for observers who want to analyze the ledger, there is no way to link transactions.\n\nHowever, any observer who sees the advertised transactions (either a peer or a miner) has full visibility into the money flow, and can easily link transactions, since the inputs and outputs are directly listed with no obfuscation.  And all node operators get a list of the inputs and outputs in every block, which gives them obfuscated access to the same data (though on a per block rather than per transaction level).\n\nSince spent outputs will be removed, it will no longer be possible to validate a block using normal merkle tree semantics, since this requires having all leaf nodes to construct the root hash.  So every output will need a separate merkle proof, to tie it to the root hash at time of block creation.  Validating a block will require validating each remaining output's merkle proof.\n\nFinally, while there are indeed space savings from removing inputs and spent outputs, it is necessary to store all balance commitments $C_T$ and their associated Schnorr proofs forever.  This set grows monotonically with each added transaction.  \n\n\n\n\\section{MobileCoin}\n\nMobileCoin is a new cryptocurrency, whose goals are privacy, convenience, and provable correctness.  The proof of concept implementation uses CryptoNote as a transaction format, with the Stellar Consensus Protocol to achieve blockchain consensus, rather than a wasteful proof of work.  All computation on the nodes uses a secure enclave, to prevent even node operators from having access to view keys or rings.  \n\nFor maximal convenience, MobileCoin will be introduced directly into secure messaging apps, using mobile devices' secure storage for keys.  Since there is no mining, transactions will be confirmed quickly.  A user will be able to open a messaging app and quickly send untraceable money, usually within a matter of seconds.\n\nThe main weakness of CryptoNote is that the ring signatures contain the actual inputs used in the transaction, though these are obscured by a number of mixins.  So anyone with access to the ledger can perform a number of attacks, linking payments to their eventual destinations.  This can be used in the common Overseer scenario, where collusion between two parties can unmask the owners of coins sent by one and cashed out at the other.  So the FBI could send coins to a suspect address, then wait for those coins to make their way to an exchange, at which point the identity of the owner of the suspect address can be determined.\n\nTo address this, MobileCoin currently drops the inputs from transactions before writing them to the ledger, indeed before the transactions even leave the secure enclave.  This guarantees full privacy from ledger analysis, at the cost of external verifiability.  The consensus quorum becomes the arbiter of correctness, and since the software is open source and anyone can run a node, this functions to attest to the correctness of the ledger.\n\n\n\n\\section{Acknowledgements}\n\nThe author would like to thank Toby Segaran for initial help on ring signatures, and Isis Lovecruft for the initial review.\n\n\n\\newpage\n\\begin{thebibliography}{8}\n\n\\bibitem{schnorr}\n  \\emph{Schnorr signature}.\n  \\texttt{https://en.wikipedia.org/wiki/Schnorr\\%5Fsignature}\n\n\\bibitem{fiatshamir}\n  \\emph{Fiat Shamir heuristic}.\n  \\texttt{https://en.wikipedia.org/wiki/Fiat\\%2DShamir\\%5Fheuristic}\n\n\\bibitem{cryptonote}\n  Nicolas van Saberhagen.\n  \\emph{CryptoNote} v$2.0$ October 17, 2013.\n  \\texttt{https://www.bytecoin.org/old/whitepaper.pdf}\n\n\\bibitem{ringct}\n  Shen Noether, Adam Mackenzie, the Monero Research Lab.\n  \\emph{Ring Confidential Transactions for Monero} DOI 10.5195/LEDGER.2016.34.\n  \\texttt{http://eprint.iacr.org/2015/1098}\n\n\\bibitem{bulletproofs}\n  Benedikt Bünz, Jonathan Bootle, Dan Boneh, Andrew Poelstra, and Greg Maxwell.\n  \\emph{Bulletproofs: Short proofs for confidential transactions and more} Cryptology ePrint Archive, Report 2017/1066, 2017.\n  \\texttt{https://eprint.iacr.org/2017/1066}\n\n\\bibitem{lelantus}\n  Aram Jivanyan.\n  \\emph{Lelantus: Private transactions with hidden origins and amounts based on DDH} 2018.12.22.\n  \\texttt{https://lelantus.io/lelantus.pdf}\n\n\\bibitem{increasingBitcoinAnonymity}\n  Dr. Yuan Horas Mouton.\n  \\emph{Increasing Anonymity in Bitcoin}.\\\\\n  \\texttt{https://download.wpsoftware.net/bitcoin/wizardry/horasyuanmouton-owas.pdf}\n\n\\bibitem{mimblewimble}\n  Tom Elvis Jedusor.\n  \\emph{MIMBLEWIMBLE} 19 July, 2016.\\\\\n  \\texttt{https://download.wpsoftware.net/bitcoin/wizardry/mimblewimble.txt}\n\n\\end{thebibliography}\n\n\\end{document}\n\n", "meta": {"hexsha": "4439c35beb05e14e484206b0e7ae55fb7de6d4e5", "size": 53046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "digitalcash.tex", "max_stars_repo_name": "xoloki/digitalcash", "max_stars_repo_head_hexsha": "19490aaed26f05b465df7e65c1736ecdd9faac2b", "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": "digitalcash.tex", "max_issues_repo_name": "xoloki/digitalcash", "max_issues_repo_head_hexsha": "19490aaed26f05b465df7e65c1736ecdd9faac2b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "digitalcash.tex", "max_forks_repo_name": "xoloki/digitalcash", "max_forks_repo_head_hexsha": "19490aaed26f05b465df7e65c1736ecdd9faac2b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4090909091, "max_line_length": 669, "alphanum_fraction": 0.689118878, "num_tokens": 17815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6961416070472807}}
{"text": "\\section{Initial Value Problems}\r\n\\noindent\r\nWe can see that since solving a differential equation will mean integrating to get rid of derivatives, the $+ C$ from integration will gives us multiple solutions. We call these sets of solutions that differ only in these constants \"solution families\". If we want to find one specific solution, we need more information about the value of the function and it's derivatives. This type of problem where a differential equation is coupled with function values is called an initial value problem (IVP).\\\\\r\n\r\n\\noindent\r\nAn initial value problem has the general form.\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\ta_ny^{(n)} + a_{n-1}y^{(n-1)} + \\ldots + a_0y = f(x) \\\\\r\n\t\ty(x_0) = y_0 \\\\\r\n\t\ty'(x_1) = y_1 \\\\\r\n\t\t\\vdots \\\\\r\n\t\ty^{(n)}(x_n) = y_n\r\n\t\\end{cases}\r\n\\end{equation*}\r\nOften, each $x_i$ is 0.\r\n\r\n\\ifodd\\includeBasicsExamples\\input{./basics/IVPs/IVPs_example1.tex}\\fi\r\n\r\n\\begin{theorem}[Existence and Uniqueness of Solutions to 1st Order IVPs]\r\n\tConsider the IVP\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\t\\dd{x}{y} = f(x,y) \\\\\r\n\t\t\ty(x_0) = y_0\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\tIf $f(x,y)$ and $\\frac{\\partial}{\\partial y}f$ are both continuous on some rectangular region containing the point $(x_0, y_0)$, then the IVP has a unique solution $y = y(x)$ on some open interval containing $x_0$.\r\n\\end{theorem}\r\n\r\n\\ifodd\\includeBasicsExamples\\input{./basics/IVPs/IVPs_example2.tex}\\fi", "meta": {"hexsha": "ca407e2d40c8d040f7f00e63d90644902fbf4867", "size": 1418, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/IVPs/IVPs.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/basics/IVPs/IVPs.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/basics/IVPs/IVPs.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": 45.7419354839, "max_line_length": 501, "alphanum_fraction": 0.706629055, "num_tokens": 443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6961374250281592}}
{"text": "% \\chapter{Review on GCN}\n\n\\section{Introduction}\n\nThe primary work of the paper is based on the findings of T. M. Kipf and M. Welling, \nwho invented measures for classification in graph network. \n\nGraph network classification is different from original graphical classification in that graphical data is mostly pixels or matrix which lines up into Euclidean Structure. Original classification models, such as the Convolution Neutral Network, apply convolution operators on the Euclidean Structure to substract features from pixels, as shown in Figure \\ref{cnn-illustration}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.8\\textwidth]{figures/cnn-illustration.png}\n    \\caption{Convolution on pixels in CNN}\n    \\label{cnn-illustration}\n\\end{figure}\n\n\\section{Fourier Transformation and Graph Convolution}\n\nWhile graph data consists of node features and edge features, which are non-Euclidean Structure, the original convolution cannot apply on the data. In the work T. M. Kipf and M. Welling, the covolution operators are re-applied through different methods. The spectral graph theory provides fourier transformation and inverse fourier transformation, given discrete graph adjacency matrix $A$.\n\n\\begin{equation}\n    \\hat{f} = U^T f\n    \\label{discrete-fourier-transformation}\n\\end{equation}\n    \n\\begin{equation}\n    f = U \\hat{f}\n    \\label{discrete-inverse-fourier-transformation}\n\\end{equation}\n\nwhere $U$ is the eigenvector matrix in normalized symmetry graph Laplacian\n\n\\begin{equation}\n    L = I_N - D^{-\\frac{1}{2}}AD^{-\\frac{1}{2}} = U\\Lambda U^T\n    \\label{normalized-sysmetry-graph-laplacian}\n\\end{equation}\n\nThe character of fourier tranformation brings sound transformation between convolution operators and fourier operators in non-Euclidean field. \n\n\\begin{equation}\n    \\begin{aligned}\n        \\mathcal{F} (h \\ast f) & = \\mathcal{F} (h) \\cdot \\mathcal{F} (f) \\\\\n        (h \\ast f)_G & = U\\left(U^T(h)\\odot U^T(f)\\right) \\\\\n    \\end{aligned}\n    \\label{graph-convolution}\n\\end{equation}\n\nwhere $\\odot$ is the Hadamard Product. \n\nThe calculation of graph convolution can be simplified throught the work of Hammond et al. on \\textit{Wavelets on Graphs via Spectral Graph Theory}\\cite{Hammond2009WaveletsOG}, gaining Equation \\ref{approximated-graph-convolution}.\n\n\\begin{equation}\n    (h \\ast f)_{G'} = \\sum _ {k=0} ^ K h' _ k T _ k (\\tilde{L}) x\n    \\label{approximated-graph-convolution}\n\\end{equation}\n\nwhere $T_k (x)$ denotes the $k$th Chebyshev polynomials, $h'$'s denote the Chebyshev coefficient vectors, $\\tilde{L} = \\frac{2}{\\lambda_{max}}L - I_N$, $\\lambda_{max}$ denotes the maximum eigenvalues of $L$, the normalized symmetry Laplacian. The detailed exploration should refer to work of Kipf et al.\\cite{DBLP:journals/corr/KipfW16}\n", "meta": {"hexsha": "435747ed3d80bea77b3a5f211c1707b785077d44", "size": 2775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapters/chapter-1-review-on-gcn.tex", "max_stars_repo_name": "primus2019/BDTA-Course-Project", "max_stars_repo_head_hexsha": "e455bb554d22319b4dbbcc2430970b890a67faaa", "max_stars_repo_licenses": ["MIT"], "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/chapter-1-review-on-gcn.tex", "max_issues_repo_name": "primus2019/BDTA-Course-Project", "max_issues_repo_head_hexsha": "e455bb554d22319b4dbbcc2430970b890a67faaa", "max_issues_repo_licenses": ["MIT"], "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/chapter-1-review-on-gcn.tex", "max_forks_repo_name": "primus2019/BDTA-Course-Project", "max_forks_repo_head_hexsha": "e455bb554d22319b4dbbcc2430970b890a67faaa", "max_forks_repo_licenses": ["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.8448275862, "max_line_length": 390, "alphanum_fraction": 0.7459459459, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6961374189665575}}
{"text": "%This chapter was modified on 4/2/97.\r%\\setcounter{chapter}{1}\r\\chapter{Continuous Probability Densities}\\label{chp 2}\r\r\\section{Simulation of Continuous Probabilities}\\label{sec 2.1}\r\rIn this section we shall show how we can use computer simulations for\rexperiments that have a whole continuum\\index{continuum} of possible outcomes.\r\r\\subsection*{Probabilities}\r\r\\begin{example}\\label{exam 2.1.1}\rWe begin by constructing a spinner\\index{spinner}, which consists of a circle of \\emx {unit \rcircumference} and a pointer as shown in Figure~\\ref{fig 2.05}.  We pick a point on\rthe circle and label it 0, and then label every other point on the circle with the\rdistance, say $x$, from 0 to that point, measured counterclockwise.  The experiment consists of\rspinning the pointer and recording the label of the point at the tip of the\rpointer.  We let the random variable $X$ denote the value of this outcome.   The sample space\ris clearly the interval $[0, 1)$.  We would like to construct a probability model in which\reach outcome is equally likely to occur.\r\\par\rIf we proceed as we did in Chapter~\\ref{chp 1} for experiments with a finite number of\rpossible outcomes, then we must assign the probability 0 to each outcome, since otherwise,\rthe sum of the probabilities, over all of the possible outcomes, would not equal 1.  (In\rfact, summing an uncountable number of real numbers is a tricky business; in particular, \rin order for such a sum to have any meaning, at most countably many of the summands can be\rdifferent than 0.)  However, if all of the assigned probabilities are 0, then the sum is 0,\rnot 1, as it should be.\r\\putfig{2truein}{PSfig2-12arc}{A spinner.}{fig 2.05}\r\\par\rIn the next section, we will show how to construct a probability model in this situation. \rAt present, we will assume that such a model can be constructed.  We will also assume that\rin this model, if $E$ is an arc of the circle, and $E$ is of length $p$, then the model \rwill assign the probability $p$ to $E$.  This means that if the pointer is spun, the\rprobability that it ends up pointing to a point in $E$ equals $p$, which is certainly a\rreasonable thing to expect.\r\\par\rTo simulate this experiment on a computer is an easy matter.  Many computer software\rpackages have a function which returns a random real number in the interval $[0, 1]$. \rActually, the returned value is always a rational number, and the values are determined by\ran algorithm, so a sequence of such values is not truly random.  Nevertheless,\rthe sequences produced by such algorithms behave much like theoretically random sequences,\rso we can use such sequences in the simulation of experiments.  On occasion, we will need\rto refer to such a function.  We will call this function $rnd$\\index{rnd}.\r\\end{example}\r\r\\subsection*{Monte Carlo Procedure and Areas}\r\rIt is sometimes desirable to estimate quantities whose exact values are difficult or \rimpossible to calculate exactly.  In some of these cases, a procedure involving chance, called \ra \\emx {Monte Carlo procedure}, can be used to provide such an estimate.\r\r\\begin{example}\\label{exam 2.1.2}\rIn this example we show how simulation can be used to estimate areas\r\\index{area, estimation of} of\rplane figures.  Suppose that we program our computer to provide a pair $(x,y)$ or\rnumbers, each chosen independently at random from the interval $[0,1]$.  Then\rwe can interpret this pair $(x,y)$ as the coordinates of a point chosen \\emx {at\rrandom} from the unit square.  Events are subsets of the unit square. \rOur experience with Example~\\ref{exam 2.1.1} suggests that the point is\requally likely to fall in subsets of equal area.  Since the total area of the\rsquare is 1, the probability of the point falling in a specific subset $E$ of\rthe unit square should be equal to its area.  Thus, we can estimate the area of\rany subset of the unit square by estimating the probability that a point chosen\rat random from this square falls in the subset.\r\\par\rWe can use this method to estimate the area of the region $E$ under the curve\r$y = x^2$ in the unit square (see Figure~\\ref{fig 2.3}).  We choose a large number of\rpoints $(x,y)$ at random and record what fraction of them fall in the region $E\r= \\{\\,(x,y):y \\leq x^2\\,\\}$.\r\\par\rThe program {\\bf MonteCarlo}\\index{MonteCarlo (program)} will carry out this experiment for us. \rRunning this program for 10{,}000 experiments gives an estimate of .325 (see\rFigure~\\ref{fig 2.4}).                     \r\r\\putfig{3truein}{PSfig2-3}{Area under $y = x^2.$}{fig 2.3}\r\rFrom these experiments we would estimate the area to be about 1/3.  Of course,\rfor this simple region we can find the exact area by calculus.  In fact,\r$$\r\\mbox{Area of}\\ E = \\int_0^1 x^2\\,dx = \\frac13\\ .\r$$\rWe have remarked in Chapter~\\ref{chp 1} that,\rwhen we simulate an experiment of this type $n$ times to estimate a probability, we can \rexpect the answer to be in error by at most $1/\\sqrt n$ at least 95 percent of the\rtime. For 10{,}000 experiments we can expect an accuracy of 0.01, and our simulation\rdid achieve this accuracy.\r\r\\putfig{3truein}{PSfig2-4}{Computing the area by simulation.}{fig 2.4}  \r\rThis same argument works for any region $E$ of the unit square.  For example,\rsuppose $E$ is the circle with center $(1/2,1/2)$ and radius 1/2. \rThen the probability that our random point $(x,y)$ lies inside the circle\ris equal to the area of the circle, that is,\r$$\rP(E) = \\pi{\\Bigl(\\frac{1}{2}\\Bigr)}^2 = \\frac{\\pi}{4}\\ .\r$$\rIf we did not know the value of $\\pi$, we could estimate\\index{$\\pi$, estimation of|(} \rthe value by performing this\rexperiment a large number of times!\r\\end{example}\r\rThe above example is not the only way of estimating the value of $\\pi$ by a\rchance experiment.  Here is another way, discovered by Buffon.\\footnote{G. L.\rBuffon, in ``Essai d'Arithm\\'etique Morale,\" \\emx {Oeuvres Compl\\`etes de\rBuffon avec Supplements,} tome~iv, ed. Dum\\'enil (Paris, 1836).}\r\r\\subsection*{Buffon's Needle}\\index{BUFFON, G. L.}\r\\index{Buffon's needle|(}\r\r\\begin{example}\\label{exam 2.1.3}\rSuppose that we take a card table and draw across the top surface a set of parallel\rlines a unit distance apart.  We then drop a common needle of unit length at\rrandom on this surface and observe whether or not the needle lies across one of\rthe lines.  We can describe the possible outcomes of this experiment by\rcoordinates as follows:  Let $d$ be the distance from the center of the needle\rto the nearest line.  Next, let $L$ be the line determined by the needle, and define $\\theta$\ras the acute angle that the line $L$ makes with the set of parallel lines.  (The reader should\rcertainly be wary of this description of the sample space.  We are attempting to coordinatize\ra set of line segments.  To see why one must be careful in the choice of coordinates, see\rExample~\\ref {exam 2.1.5}.)  Using this description, we have $0\r\\leq d \\leq 1/2$, and $0 \\leq\r\\theta \\leq \\pi/2$.  Moreover, we see that the needle lies across the\rnearest line if and only if the hypotenuse of the triangle (see Figure~\\ref\r{fig 2.6}) is less than half the length of the needle, that is, \r$$\r\\frac d{\\sin\\theta} < \\frac12\\ .\r$$\r\r\\putfig{4.5truein}{PSfig2-6}{Buffon's experiment.}{fig 2.6}\r\rNow we assume that when the needle drops, the pair $(\\theta,d)$ is chosen at\rrandom from the rectangle $0 \\leq \\theta \\leq \\pi/2$, $0 \\leq d \\leq 1/2$.  We\robserve whether the needle lies across the nearest line (i.e., whether $d \\leq\r(1/2)\\sin\\theta$).  The probability of this event $E$ is the fraction of\rthe area of the rectangle which lies inside $E$ (see Figure~\\ref{fig 2.7}).             \rNow the area of the rectangle is $\\pi/4$, while the area of $E$ is\r$$\r\\mbox{Area} = \\int_0^{\\pi/2}\\frac12\\sin\\theta\\,d\\theta = \\frac 12\\ .\r$$\rHence, we get\r$$\rP(E) = \\frac{1/2}{\\pi/4} = \\frac2\\pi\\ .\r$$\r\r\\putfig{3.5truein}{PSfig2-7}\r{Set $E$ of pairs $(\\theta, d)$ with $d < {\\frac{1}{2}} \\sin \\theta$.}{fig 2.7}\r\rThe program {\\bf BuffonsNeedle}\\index{BuffonsNeedle (program)} simulates this experiment.  In\rFigure~\\ref{fig 2.8}, we show the position of every 100th needle in a run of the program in\rwhich 10{,}000 needles were ``dropped.\"  Our final estimate for $\\pi$ is 3.139.  While this was\rwithin 0.003 of the  true value for $\\pi$ we had no right to expect such accuracy.  The reason\rfor this is that our simulation estimates $P(E)$.  While we can expect this estimate to be in\rerror by at most 0.001, a small error in $P(E)$ gets magnified when we use this to compute $\\pi =\r2/P(E)$.  Perlman\\index{PERLMAN, M. D.} and Wichura\\index{WICHURA, M. J.}, in their article\r``Sharpening Buffon's Needle,\"\\footnote{M. D. Perlman and M. J. Wichura, ``Sharpening\rBuffon's Needle,\" \\emx {The American Statistician,} vol.~29, no.~4 (1975), pp.~157--163.}\rshow that we can expect to have an error of not more than $5/\\sqrt n$ about 95 percent of\rthe time.  Here $n$ is the number of needles dropped.  Thus for 10{,}000 needles we should\rexpect an error of no more than 0.05, and that was the case here.  We see that a large\rnumber of experiments is necessary to get a decent estimate for\r$\\pi$.\\index{$\\pi$, estimation of|)}\r\\index{Buffon's needle|)}\r\\end{example}\r\r\\putfig{4truein}{PSfig2-8}{Simulation of Buffon's needle experiment.}{fig 2.8}\r\rIn each of our examples so far, events of the same size are equally likely. \rHere is an example where they are not.  We will see many other such examples later.\r\\begin{example}\\label{exam 2.1.4.5}\rSuppose that we choose two random real numbers in $[0,1]$ and add them together.  Let $X$\rbe the sum.  How is $X$ distributed?\r\\par\rTo help understand the answer to this question, we can use the program {\\bf\rAreabargraph}\\index{Areabargraph (program)}.  This  program produces a bar graph with the\rproperty that on each interval, the \\emx {area},  rather than the height, of the bar is equal to\rthe fraction of outcomes that fell in the corresponding interval.  We have carried out this\rexperiment 1000 times; the data is shown in Figure~\\ref{fig 2.8.5}.  It appears that the\rfunction defined by\r$$f(x) = \\left \\{ \\begin{array}{ll}\r                  x,   & \\mbox{if $0 \\le x \\le 1$,}  \\\\\r                  2-x, & \\mbox{if $1 < x \\le 2$} \r                  \\end{array}\r         \\right.\r$$\rfits the data very well.  (It is shown in the figure.)  In the next section, we will see \rthat this function is the ``right\" function. By this we mean that if $a$ and $b$ are any\rtwo real numbers between $0$ and $2$, with $a \\le b$, then we can use this function to\rcalculate the probability that\r$a \\le X \\le b$.  To understand how this calculation might be performed, we again consider\rFigure~\\ref{fig 2.8.5}.  Because of the way the bars were constructed, the sum of the areas of the\rbars corresponding to the interval $[a, b]$ approximates the probability that $a \\le X \r\\le b$.  But the sum of the areas of these bars also approximates the integral\r$$\\int_a^b f(x)\\,dx\\ .$$  This suggests that for an experiment with a continuum of possible outcomes, \rif we find a function with the above property, then we will be able to use it to calculate\rprobabilities.  In the next section, we will show how to determine the function\r\\linebreak[4]$f(x)$.\r\\putfig{3.5truein}{PSfig2-8-5}{Sum of two random numbers.}{fig 2.8.5}\r\\end{example}\r\r\\begin{example}\\label{exam 2.1.4.6}\rSuppose that we choose 100 random numbers in $[0, 1]$, and let $X$ represent their sum.  \rHow is $X$ distributed?  We have carried out this experiment 10000 times; the results are\rshown in  Figure~\\ref{fig 2.8.6}.  It is not so clear what function fits the bars in this\rcase.  It turns out that the type of function which does the job is called a \\emx {normal\rdensity}\\index{normal density} function.  This type of function is sometimes referred to as a\r``bell-shaped\"\\index{bell-shaped} curve.  It is among the most important functions in the\rsubject of probability, and will be formally defined in Section~\\ref{sec 5.2}\rof Chapter~\\ref{chp 5}.\r\\putfig{3.5truein}{PSfig2-8-6}{Sum of 100 random numbers.}{fig 2.8.6}\r\\end{example}\r\\par\rOur last example explores the fundamental question of how probabilities are\rassigned.\r\r\\subsection*{Bertrand's Paradox}\\index{Bertrand's paradox|(}\r\r\\begin{example}\\label{exam 2.1.5} \rA chord of a circle is a line segment both of whose endpoints lie on the\rcircle.  Suppose that a chord is drawn \\emx {at random}\\index{chord, random} in a unit circle. \rWhat is the probability that its length exceeds $\\sqrt 3$?\r\rOur answer will depend on what we mean by \\emx {random,} which\rwill depend, in turn, on what we choose for coordinates.  The sample space\r$\\Omega$ is the set of all possible chords in the circle.  To find coordinates\rfor these chords, we first introduce a rectangular coordinate system with\rorigin at the center of the circle (see Figure~\\ref{fig 2.10}).  We note that a chord\rof a circle is perpendicular to the radial line containing the midpoint of the\rchord.  We can describe each chord by giving:\r \r\\begin{enumerate}\r\\item The rectangular coordinates $(x,y)$ of the midpoint $M$, or\r\\item The polar coordinates $(r,\\theta)$ of the midpoint $M$, or\r\\item The polar coordinates $(1,\\alpha)$ and $(1,\\beta)$ of the endpoints $A$\rand $B$.\r \r\\end{enumerate}\rIn each case we shall interpret \\emx {at random} to mean: choose these\rcoordinates at random.\r\rWe can easily estimate this probability by computer simulation.  In programming this \rsimulation, it is convenient to include certain simplifications, which we describe in turn:\r\r\\putfig{2.5truein}{PSfig2-10}{Random chord.}{fig 2.10}\r\r\\begin{enumerate}\r\\item To simulate this case, we choose values for $x$ and $y$ from $[-1,1]$ at\rrandom.  Then we check whether $x^2 + y^2 \\leq 1$.  If not, the point $M =\r(x,y)$ lies outside the circle and cannot be the midpoint of any chord, and we\rignore it.  Otherwise, $M$ lies inside the circle and is the midpoint of a\runique chord, whose length $L$ is given by the formula:\r$$\rL = 2\\sqrt{1 - (x^2 + y^2)}\\ .\r$$\r\\item To simulate this case, we take account of the fact that any rotation of\rthe circle does not change the length of the chord, so we might as well assume\rin advance that the chord is horizontal.  Then we\rchoose $r$ from $[-1,1]$ at random, and compute the length of the resulting\rchord with midpoint $(r,\\pi/2)$ by the formula:\r$$\rL = 2\\sqrt{1 - r^2}\\ .\r$$\r\\item To simulate this case, we assume that one endpoint, say $B$, lies at\r$(1, 0)$ (i.e., that $\\beta = 0$).  Then we choose a value for $\\alpha$ from\r$[0,2\\pi]$ at random and compute the length of the resulting chord, using the\rLaw of Cosines, by the formula:\r$$\rL = \\sqrt{2 - 2\\cos\\alpha}\\ .\r$$\r\\end{enumerate}\r\rThe program {\\bf BertrandsParadox}\\index{BertrandsParadox (program)} carries out this\rsimulation.  Running this program produces the results shown in Figure~\\ref{fig 2.11}.  In the\rfirst  circle in this figure, a smaller circle has been drawn.  Those chords which intersect this\rsmaller circle have length at least $\\sqrt 3$.  In the second circle in the figure, the\rvertical line intersects all chords of length at least $\\sqrt 3$.  In the third circle,\ragain the vertical line intersects  all chords of length at least $\\sqrt 3$.\r\rIn each case we run the experiment a large number of times and record the\rfraction of these lengths that exceed $\\sqrt 3$.  We have printed the results\rof every 100th trial up to 10{,}000 trials.\r\r\\putfig{4.5truein}{PSfig2-11}{Bertrand's paradox.}{fig 2.11}\r\rIt is interesting to observe that these fractions are \\emx {not} the same in\rthe three cases; they depend on our choice of coordinates.  This phenomenon was\rfirst observed by Bertrand, and is now known as \\emx {Bertrand's\rparadox.}\\index{BERTRAND, J.}\\footnote{J. Bertrand, \\emx {Calcul des Probabilit\\'es}\r(Paris: Gauthier-Villars, 1889).}  It is actually not a paradox at all; it is merely a\rreflection of the fact that different choices of coordinates will lead to\rdifferent assignments of probabilities.  Which assignment is ``correct\"\rdepends on what application or interpretation of the model one has in mind.\r\\par\rOne can imagine a real experiment involving throwing long straws at a circle\rdrawn on a card table.  A ``correct\" assignment of coordinates should not depend on \rwhere the circle lies on the card table, or where the card table sits in the room. \rJaynes\\index{JAYNES, E. T.}\\footnote{E. T. Jaynes, ``The Well-Posed Problem,\" in \\emx\r{Papers on Probability, Statistics and Statistical Physics,} R.~D.~Rosencrantz, ed.\r(Dordrecht: D.~Reidel, 1983), pp.~133--148.} has shown that the only assignment which\rmeets this requirement is (2).  In this sense, the assignment (2) is the natural, or\r``correct\" one (see Exercise~\\ref{exer\r2.1.11}).                                             \r\\par\rWe can easily see in each case what the true probabilities are if we note that\r$\\sqrt 3$ is the length of the side of an inscribed equilateral triangle. \rHence, a chord has length $L > \\sqrt 3$ if its midpoint has distance $d < 1/2$\rfrom the origin (see Figure~\\ref{fig 2.10}).  The following calculations determine\rthe probability that $L > \\sqrt 3$ in each of the three cases.\r\\begin{enumerate}\r\\item $L > \\sqrt 3$ if$(x,y)$ lies inside a circle of radius 1/2, which occurs with \rprobability\r$$\rp = \\frac{\\pi(1/2)^2}{\\pi(1)^2} = \\frac14\\ .\r$$\r\\item $L > \\sqrt 3$ if $|r| < 1/2$, which occurs with probability\r$$\r\\frac{1/2 - (-1/2)}{1 - (-1)} = \\frac12\\ .\r$$\r\\item $L > \\sqrt 3$ if $2\\pi/3 < \\alpha < 4\\pi/3$, which occurs with probability\r$$\r\\frac{4\\pi/3 - 2\\pi/3}{2\\pi - 0} = \\frac13\\ .\r$$\r\\end{enumerate}\rWe see that our simulations agree quite well with these theoretical values.\\index{Bertrand's\rparadox|)}\r\\end{example}\r\r\\subsection*{Historical Remarks}\r\rG.~L.~Buffon\\index{BUFFON, G. L.|(} (1707--1788) was a natural scientist in the eighteenth\rcentury who applied probability to a number of his investigations.  His work is found in\rhis monumental 44-volume \\emx {Histoire Naturelle} and its\rsupplements.\\footnote{G.~L.~Buffon, \\emx {Histoire Naturelle, Generali et\rParticular avec le Descripti\\'on du Cabinet du Roy,} 44~vols. (Paris:\rL`Imprimerie Royale, 1749--1803).}  For example, he presented a number of\rmortality tables and used them to compute, for each age group, the expected\rremaining lifetime.  From his table he observed: the expected remaining\rlifetime of an infant of one year is 33 years, while that of a man of 21 years\ris also approximately 33 years.  Thus, a father who is not yet 21 can hope to\rlive longer than his one year old son, but if the father is 40, the odds are\ralready 3 to 2 that his son will outlive him.\\footnote{G.~L.~Buffon, ``Essai\rd'Arithm\\'etique Morale,\" p.~301.}\r\\par\rBuffon wanted to show that not all probability calculations rely only on\ralgebra, but that some rely on geometrical calculations.  One such problem\rwas his famous ``needle problem\"\\index{Buffon's needle|(} as discussed in this\rchapter.\\footnote{ibid., pp.~277--278.}  In his original formulation, Buffon describes a game\rin which two gamblers drop a loaf of French bread on a wide-board floor and bet on\rwhether or not the loaf falls across a crack in the floor.  Buffon asked: what\rlength $L$ should the bread loaf be, relative to the width $W$ of the\rfloorboards, so that the game is fair.  He found the correct answer ($L =\r(\\pi/4)W$) using essentially the methods described in this chapter.  He also\rconsidered the case of a checkerboard floor, but gave the wrong answer in this\rcase.  The correct answer was given later by Laplace.\\index{BUFFON, G. L.|)}\\index{LAPLACE,\rP. S.}\r\\par\rThe literature contains descriptions of a number of experiments that were\ractually carried out to estimate $\\pi$ by this method of dropping needles.\rN.~T.~Gridgeman\\index{GRIDGEMAN, N. T.}\\footnote{N.~T.~Gridgeman, ``Geometric Probability and\rthe Number $\\pi$\" \\emx {Scripta Mathematika,} vol.~25, no.~3, (1960),\rpp.~183--195.} discusses the experiments shown in Table~\\ref{table 2.1}.\r\\begin{table}\r\\centering\r$$ \r\\begin{tabular}{llrll}\r               &  Length of              &  Number of       &  Number of      &  Estimate  \\\\\rExperimenter   &  needle                 & casts\\,\\,\\,\\,\\,\\,&  crossings      &  for $\\pi$  \\\\ \\hline\rWolf, 1850     &  \\hspace{.073in}.8      & 5000\\,\\,\\,\\,\\,\\, &  2532                  & 3.1596      \\\\\rSmith, 1855    &  \\hspace{.073in}.6      & 3204\\,\\,\\,\\,\\,\\, &  1218.5                & 3.1553      \\\\\rDe Morgan, c.1860& 1.0                   & 600\\,\\,\\,\\,\\,\\,  &  \\hspace{.075in}382.5  & 3.137       \\\\\rFox, 1864      &  \\hspace{.078in}.75     & 1030\\,\\,\\,\\,\\,\\, &  \\hspace{.075in}489    & 3.1595      \\\\\rLazzerini, 1901&  \\hspace{.078in}.83     & 3408\\,\\,\\,\\,\\,\\, &  1808                  & 3.1415929   \\\\\rReina, 1925    &  \\hspace{.083in}.5419   & 2520\\,\\,\\,\\,\\,\\, &  \\hspace{.075in}869    & 3.1795  \\\\ \\hline\r\\end{tabular}\r$$\r\\caption{Buffon needle experiments to estimate $\\pi$.}\r\\label{table 2.1}\r\\end{table}\r(The halves for the number of crossing comes from a compromise when it could\rnot be decided if a crossing had actually occurred.)  He observes, as we have,\rthat 10{,}000 casts could do no more than establish the first decimal place of\r$\\pi$ with reasonable confidence.  Gridgeman points out that, although none of\rthe experiments used even 10{,}000 casts, they are surprisingly good, and in some\rcases, too good.  The fact that the number of casts is not always a round number\rwould suggest that the authors might have resorted to clever stopping to get a\rgood answer.  Gridgeman comments that Lazzerini's estimate turned out to agree\rwith a well-known approximation to $\\pi$, $355/113 = 3.1415929$, discovered by\rthe fifth-century Chinese mathematician, Tsu Ch'ungchih.  Gridgeman says that\rhe did not have Lazzerini's original report, and while waiting for it (knowing\ronly the needle crossed a line 1808 times in 3408 casts) deduced that the\rlength of the needle must have been 5/6.  He calculated this from Buffon's\rformula, assuming $\\pi = 355/113$:\r$$\rL = \\frac{\\pi P(E)}2 =\r\\frac12\\left(\\frac{355}{113}\\right)\\left(\\frac{1808}{3408}\\right) = \\frac56 =\r.8333\\ .\r$$\rEven with careful planning one would have to be extremely lucky to be able to\rstop so cleverly\\index{Buffon's needle|)}.\r\\par\rThe second author likes to trace his interest in probability theory to the Chicago\rWorld's Fair\\index{Chicago World's Fair} of 1933 where he observed a mechanical device dropping\rneedles and displaying the ever-changing estimates for the value of $\\pi$.  (The first author\rlikes  to trace his interest in probability theory to the second author.)\r\r\\exercises\r\\begin{LJSItem}\r\r\\istar\\label{exer 2.1.1} In the spinner problem (see Example~\\ref{exam 2.1.1})   \rdivide the unit circumference into three arcs of length 1/2, 1/3, and 1/6. \rWrite a program to simulate the spinner experiment 1000 times and print out what\rfraction of the outcomes fall in each of the three arcs.  Now plot a bar graph\rwhose bars have width 1/2, 1/3, and 1/6, and areas equal to the corresponding\rfractions as determined by your simulation.  Show that the heights of the bars\rare all nearly the same.\r\r\\i\\label{exer 2.1.2} Do the same as in Exercise~\\ref{exer 2.1.1}, \rbut divide the unit\rcircumference into five arcs of length 1/3, 1/4, 1/5, 1/6, and 1/20.\r\r\\i\\label{exer 2.1.3} Alter the program {\\bf MonteCarlo} to estimate the area of the\rcircle of radius 1/2 with center at $(1/2,1/2)$ inside the unit square by\rchoosing 1000 points at random.  Compare your results with the true value of\r$\\pi/4$.  Use your results to estimate the value of $\\pi$.  How accurate is\ryour estimate?\r\r\\i\\label{exer 2.1.4} Alter the program {\\bf MonteCarlo} to\restimate the area under the graph of $y = \\sin\\pi x$ inside the unit square by\rchoosing 10{,}000 points at random.  Now calculate the true value of this\rarea and use your results to estimate the value of $\\pi$.  How accurate is your estimate?\r\r\\i\\label{exer 2.1.5} Alter the program {\\bf MonteCarlo} to estimate the area under the\rgraph of $y = 1/(x + 1)$ in the unit square in the same way as in Exercise~\\ref\r{exer 2.1.4}.   Calculate the true value of this area and use\ryour simulation results to estimate the value of $\\log 2$.  How accurate is your\restimate?\r\r\\i\\label{exer 2.1.6} To simulate the Buffon's needle\\index{Buffon's needle} problem we choose\rindependently the distance~$d$ and the angle $\\theta$ at random, with $0 \\leq d\r\\leq 1/2$ and $0 \\leq \\theta \\leq \\pi/2$, and check whether $d \\leq\r(1/2)\\sin\\theta$.  Doing this a large number of times, we estimate $\\pi$ as\r$2/a$, where $a$ is the fraction of the times that $d \\leq (1/2)\\sin\\theta$. \rWrite a program to estimate $\\pi$ by this method.  Run your program several\rtimes for each of 100, 1000, and 10{,}000 experiments.  Does the accuracy of the\rexperimental approximation for $\\pi$ improve as the number of experiments\rincreases?\r\r\\i\\label{exer 2.1.7} For Buffon's needle problem\\index{Buffon's needle}, Laplace\\index{LAPLACE,\rP. S.}\\footnote{P. S. Laplace, \\emx {Th\\'eorie Analytique des Probabilit\\'es} (Paris: Courcier,\r1812).} considered a grid with \\emx {horizontal} and \\emx {vertical} lines one unit apart.  He\rshowed that the probability that a needle of length $L \\leq 1$ crosses at least\rone line is\r$$\rp = \\frac{4L - L^2}\\pi\\ .\r$$\rTo simulate this experiment we choose at random an angle $\\theta$ between\r0~and $\\pi/2$ and independently two numbers $d_1$ and $d_2$ between 0 and\r$L/2$. \r(The two numbers represent the distance from the center of the needle to the\rnearest horizontal and vertical line.)  The needle crosses a line if either\r$d_1 \\leq (L/2)\\sin\\theta$ or $d_2 \\leq (L/2)\\cos\\theta$.  We do this a large\rnumber of times and estimate $\\pi$ as\r$$\r\\bar \\pi = \\frac{4L - L^2}a\\ ,\r$$\rwhere $a$ is the proportion of times that the needle crosses at least one\rline.  Write a program to estimate $\\pi$ by this method, run your program for\r100, 1000, and 10{,}000 experiments, and compare your results with Buffon's\rmethod described in Exercise~\\ref{exer 2.1.6}.    \r(Take $L = 1$.)\r\r\\i\\label{exer 2.1.8} A long needle\\index{Buffon's needle} of length $L$ much bigger than 1 is\rdropped on a grid with horizontal and vertical lines one unit apart.  We will see \r(in Exercise~\\ref{sec 6.3}.\\ref{exer 6.3.29}) that the average number $a$ of lines crossed\ris approximately\r$$\ra = \\frac{4L}\\pi\\ .\r$$\rTo estimate $\\pi$ by simulation, pick an angle $\\theta$ at random between 0 and\r$\\pi/2$ and compute $L\\sin\\theta + L\\cos\\theta$.  This may be used for the\rnumber of lines crossed.  Repeat this many times and estimate $\\pi$ by\r$$\r\\bar \\pi = \\frac{4L}a\\ ,\r$$\rwhere $a$ is the average number of lines crossed per experiment.  Write a\rprogram to simulate this experiment and run your program for the number of\rexperiments equal to 100, 1000, and 10{,}000.  Compare your results with the\rmethods of Laplace or Buffon for the same number of experiments.  (Use $L = 100$.)\r\r\\medbreak\\noindent\rThe following exercises involve experiments in which not all outcomes are\requally likely.  We shall consider such experiments in detail in the next\rsection, but we invite you to explore a few simple cases here.\r\r\\i\\label{exer 2.1.9} A large number of waiting time problems have an\r\\emx {exponential distribution}\\index{exponential density}\\index{density function!exponential}\rof outcomes.  We shall see (in Section~\\ref{sec 5.2})  that such outcomes are simulated by\rcomputing\r$(-1/\\lambda)\\log(\\mbox{rnd})$, where $\\lambda > 0$.  For waiting times produced\rin this way, the average waiting time is $1/\\lambda$.  For example, the times\rspent waiting for a car to pass on a highway, or the times between emissions of particles \rfrom a radioactive source, are simulated by a sequence of random numbers, each of\rwhich is chosen by computing $(-1/\\lambda)\\log(\\mbox{rnd})$, where $1/\\lambda$ is\rthe average time between cars or emissions.  Write a program to simulate the\rtimes between cars when the average time between cars is 30 seconds.  Have your\rprogram compute an area bar graph for these times by breaking the time interval from\r0 to 120 into 24 subintervals.  On the same pair of axes, plot the function\r$f(x) = (1/30)e^{-(1/30)x}$.  Does the function fit the bar graph well?\r\r\\i\\label{exer 2.1.10.5} In Exercise~\\ref{exer 2.1.9},\rthe distribution came ``out of a hat.\"  In this problem, we will again consider an\rexperiment whose outcomes are not equally likely.  We will determine a function\r$f(x)$ which can be used to determine the probability of certain events. \rLet $T$ be the right triangle in the plane with vertices at the points $(0, 0),\\ (1, 0),$\rand $(0,1)$.  The experiment consists of picking a point at random in the interior\rof $T$, and recording only the $x$-coordinate of the point.  Thus, the sample space is\rthe set $[0,1]$, but the outcomes do not seem to be equally likely.  We can simulate this\rexperiment by asking a computer to return two random real numbers in $[0,\r1]$, and recording the first of these two numbers if their sum is less than 1. \rWrite this program and run it for 10{,}000 trials.  Then make a bar graph of the\rresult, breaking the interval $[0, 1]$ into 10 intervals.  Compare the bar graph with the\rfunction $f(x) = 2 - 2 x$.  Now show that there is a constant $c$ such that the\rheight of $T$ at the $x$-coordinate value $x$ is $c$ times $f(x)$ for every $x$ in\r$[0, 1]$.  Finally, show that  $$\\int_0^1 f(x)\\,dx = 1\\ .$$\rHow might one use the function $f(x)$ to determine the probability that the\routcome is between $.2$ and $.5$?\r\r\\i\\label{exer 2.1.11} Here is another way to pick a chord\\index{chord, random} \\emx {at random}\ron the circle of unit radius.  Imagine that we have a card table whose sides are of\rlength 100.  We place coordinate axes on the table in such a way that each side of\rthe table is parallel to one of the axes, and so that the center of the table is the\rorigin.  We now place a circle of unit radius on the table so that the center of the \rcircle is the origin.  Now pick out a point\r$(x_0,y_0)$ at random in the square, and an angle\r$\\theta$ at random in the interval $(-\\pi/2,\\pi/2)$.  Let $m = \\tan\\theta$. \rThen the equation of the line passing through $(x_0,y_0)$ with slope $m$ is\r$$\ry = y_0 + m(x - x_0)\\ ,\r$$\rand the distance of this line from the center of the circle (i.e., the origin)\ris\r$$\rd = \\left|\\frac{y_0 - mx_0}{\\sqrt{m^2 + 1}}\\right|\\ .\r$$\r\rWe can use this distance formula to check whether the line intersects the\rcircle (i.e., whether $d < 1$).  If so, we consider the resulting chord a {\\em\rrandom} chord.  This describes an experiment of dropping a long straw at\rrandom on a table on which a circle is drawn.\r\rWrite a program to simulate this experiment 10000 times and estimate the\rprobability that the length of the chord is greater than $\\sqrt3$.  How does\ryour estimate compare with the results of Example~\\ref{exam 2.1.5}?  \r\\end{LJSItem}\r\r\r\\section{Continuous Density Functions}\\label{sec 2.2}\r\rIn the previous section we have seen how to simulate experiments with a whole\rcontinuum of possible outcomes and have gained some experience in thinking\rabout such experiments.  Now we turn to the general problem of assigning\rprobabilities to the outcomes and events in such experiments.  We shall\rrestrict our attention here to those experiments whose sample space can be\rtaken as a suitably chosen subset of the line, the plane, or some other\rEuclidean space.  We begin with some simple examples.\r\r\\subsection*{Spinners}\r\r\\begin{example}\\label{exam 2.2.1}\rThe spinner\\index{spinner} experiment described in Example~\\ref{exam 2.1.1} has the interval\r$[0, 1)$ as  the set of possible outcomes.  We would like to construct a probability model in\rwhich  each outcome is equally likely to occur.  We saw that in such a model, it is necessary\rto assign the probability 0 to each outcome.  This does not at all mean that the probability\rof \\emx {every} event must be zero.  On the contrary, if we let the random variable $X$\rdenote the outcome, then the probability\r$$P(\\,0 \\leq X \\leq 1)$$\rthat the head of the spinner comes to rest \\emx {somewhere} in the circle, should be \requal to 1.  Also, the probability that it comes to rest in the upper half of the circle\rshould be the same as for the lower half, so that\r$$\rP\\biggl(0 \\leq X < \\frac12\\biggr) = P\\biggl(\\frac12 \\leq X <\r1\\biggr) = \\frac12\\ .\r$$\rMore generally, in our model, we would like the equation\r$$\rP(c \\leq X < d) = d - c\r$$\rto be true for every choice of $c$ and $d$.\r\\par\rIf we let $E = [c, d]$, then we can write the above formula in the form\r$$P(E) = \\int_E f(x)\\,dx\\ ,$$ where $f(x)$ is the constant function with value 1.  \rThis should remind the reader of the corresponding formula in the discrete case \rfor the probability of an event:\r$$P(E) = \\sum_{\\omega \\in E} m(\\omega)\\ .$$\rThe difference is that in the continuous case, the quantity being integrated, $f(x)$,\ris not the probability of the outcome $x$.  (However, if one uses infinitesimals, one\rcan consider $f(x)\\,dx$ as the probability of the outcome $x$.)  \r\\par\rIn the continuous case, we will use the following convention.  If the set of outcomes is a\rset of real numbers, then the individual outcomes will be referred to by small Roman letters\rsuch as $x$.  If the set of outcomes is a subset of $R^2$, then the individual\routcomes will be denoted by $(x, y)$.  In either case, it may be more convenient to refer to\ran individual outcome by using $\\omega$, as in Chapter \\ref{chp 1}.\r\\putfig{3.5truein}{PSfig2-16-5}{Spinner experiment.}{fig 2.16.5}\r\\par\rFigure \\ref{fig 2.16.5} shows the results of 1000 spins of the spinner.  The function \r$f(x)$ is also shown in the figure.  The reader will note that the area under $f(x)$ and\rabove a given interval is approximately equal to the fraction of outcomes that fell in\rthat interval.  The function $f(x)$ is called the \\emx {density function}\\index{density\rfunction} of the random variable $X$.  The fact that the area under $f(x)$ and above an\rinterval corresponds to a probability is  the defining property of density functions.  A\rprecise definition of density functions will be given shortly.\r\\end{example}\r\r\\subsection*{Darts}\r\r\\begin{example}\\label{exam 2.2.2}\rA game of darts\\index{darts} involves throwing a dart at a circular target of \\emx {unit\rradius.}  Suppose we throw a dart once so that it hits the target, and we\robserve where it lands.\r\rTo describe the possible outcomes of this experiment, it is natural to take as\rour sample space the set $\\Omega$ of all the points in the target.  It\ris convenient to describe these points by their rectangular coordinates,\rrelative to a coordinate system with origin at the center of the target, so\rthat each pair $(x,y)$ of coordinates with $x^2 + y^2 \\leq 1$ describes a\rpossible outcome of the experiment.  Then $\\Omega = \\{\\,(x,y) : x^2 + y^2 \\leq\r1\\,\\}$ is a subset of the Euclidean plane, and the event $E = \\{\\,(x,y) : y >\r0\\,\\}$, for example, corresponds to the statement that the dart lands in the\rupper half of the target, and so forth.  Unless there is reason to believe\rotherwise (and with experts at the game there may well be!), it is natural to\rassume that the coordinates are chosen \\emx {at random.}  (When doing this with\ra computer, each coordinate is chosen uniformly from the interval $[-1, 1]$.  \rIf the resulting point does not lie inside the unit circle, the point is not counted.)  \rThen the arguments used in the preceding example show that the probability of any \relementary event, consisting of a single outcome, must be zero, and suggest that the\rprobability of the event that the dart lands in any subset $E$ of the target\rshould be determined by what fraction of the target area lies in $E$.  Thus,\r$$\rP(E) = \\frac{\\mbox{area\\ of}\\ E}{\\mbox{area\\ of\\ target}} = \\frac{\\mbox{area\\ of}\\ \rE}\\pi\\ .\r$$\rThis can be written in the form\r$$P(E) = \\int_E f(x)\\,dx\\ ,$$\rwhere $f(x)$ is the constant function with value $1/\\pi$.\rIn particular, if $E = \\{\\,(x,y) : x^2 + y^2 \\leq a^2\\,\\}$ is the event that\rthe dart lands within distance $a < 1$ of the center of the target, then\r$$\rP(E) = \\frac{\\pi a^2}\\pi = a^2\\ .\r$$\rFor example, the probability that the dart lies within a distance 1/2 of the\rcenter is 1/4.\r\\end{example}\r\r\\begin{example}\\label{exam 2.2.3}\rIn the dart\\index{darts} game considered above, suppose that, instead of\robserving where the dart lands, we observe how far it lands from the center of\rthe target.\r\\par\rIn this case, we take as our sample space the set $\\Omega$ of all circles with\rcenters at the center of the target.  It is convenient to describe these\rcircles by their radii, so that each circle is identified by its radius $r$, $0\r\\leq r \\leq 1$.  In this way, we may regard $\\Omega$ as the subset $[0,1]$ of\rthe real line.\r\\par\rWhat probabilities should we assign to the events $E$ of $\\Omega$?  If \r$$E = \\{\\,r : 0 \\leq r \\leq a\\,\\}\\ ,$$ \rthen $E$ occurs if the\rdart lands within a distance $a$ of the center, that is, within the circle of\rradius $a$, and we saw in the previous example that under our assumptions the\rprobability of this event is given by\r$$\rP([0,a]) = a^2\\ .\r$$\rMore generally, if \r$$E = \\{\\,r : a \\leq r \\leq b\\,\\}\\ ,$$ \rthen by our basic assumptions,\r\\begin{eqnarray*}\rP(E) = P([a,b]) & = & P([0,b]) - P([0,a]) \\\\\r              & = & b^2 - a^2 \\\\\r              & = & (b - a)(b + a) \\\\\r              & = & 2(b - a)\\frac{(b + a)}2\\ .\r\\end{eqnarray*}\r\rThus, $P(E) = $2(length of $E$)(midpoint of $E$).  Here we see that the\rprobability assigned to the interval $E$ depends not only on its length but\ralso on its midpoint (i.e., not only on how long it is, but also on where it\ris).  Roughly speaking, in this experiment, events of the form $E = [a,b]$ are\rmore likely if they are near the rim of the target and less likely if they are\rnear the center.  (A common experience for beginners!  The conclusion might\rwell be different if the beginner is replaced by an expert.)\r\rAgain we can simulate this by computer.  \rWe divide the target area into ten concentric regions of equal thickness.\r\r\\putfig{5truein}{PSfig2-15}{Distribution of dart distances in 400 throws.}{fig 2.15}\r\\par\rThe computer program {\\bf Darts}\\index{Darts (program)} throws $n$ darts and records what\rfraction of the total falls in each of these concentric regions.  The\rprogram {\\bf Areabargraph} then plots a bar graph with the \\emx {area} of\rthe $i$th bar equal to the fraction of the total falling in the $i$th region. \rRunning the program for 1000 darts resulted in the bar graph of Figure~\\ref{fig 2.15}.\r\\par\rNote that here the heights of the bars are not all equal, but grow\rapproximately linearly with $r$.  In fact, the linear function $y = 2r$ appears\rto fit our bar graph quite well.  This suggests that the probability that the\rdart falls within a distance $a$ of the center should be given by the {\\em\rarea} under the graph of the function $y = 2r$ between 0 and $a$.  This area\ris $a^2$, which agrees with the probability we have assigned above to this\revent.\r\\end{example}\r\r\\subsection*{Sample Space Coordinates}\r\rThese examples suggest that for continuous experiments of this sort we should\rassign probabilities for the outcomes to fall in a given interval by means of the\rarea under a suitable function.\r\\par\rMore generally, we suppose that suitable coordinates can be introduced into the\rsample space $\\Omega$, so that we can regard $\\Omega$ as a subset of\r${\\bf R}^n$.  We call such a sample space a \\emx {continuous sample space.}\\index{sample\rspace!continuous}  We let\r$X$ be a random variable which represents the outcome of the experiment.  Such a\rrandom variable is called a \\emx {continuous random variable.}\\index{random\rvariable!continuous}  We then define a density function for $X$ as follows.   \r\r\\subsection*{Density Functions of Continuous Random Variables}\r\r\\begin{definition}\rLet $X$ be a continuous real-valued random variable.  A \\emx {density function}\\index{density\rfunction} for\r$X$  is a real-valued function $f$ which satisfies\r$$P(a \\le X \\le b) = \\int_a^b f(x)\\,dx$$\rfor all $a,\\ b \\in {\\bf R}$.\r\\end{definition}\rWe note that it is \\emx {not} the case that all continuous real-valued random variables \rpossess density functions.  However, in this book, we will only consider continuous random\rvariables for which density functions exist.\r\\par\rIn terms of the density $f(x)$, if $E$ is a subset of \r${\\mat R}$, then\r$$\rP(X \\in E) = \\int_Ef(x)\\,dx\\ .\r$$\rThe notation here assumes that $E$ is a subset of ${\\mat R}$ for which $\\int_E\rf(x)\\,dx$ makes sense.  \r\r\\begin{example}(Example~\\ref{exam 2.2.1} continued)\\label{exam 2.2.5}\rIn the spinner\\index{spinner} experiment, we choose for our set of outcomes the\rinterval $0 \\leq x < 1$, and for our density function\r$$\rf(x) =  \\left \\{ \\begin{array}{ll}\r                     1, & \\mbox{if $0 \\leq x < 1$,} \\\\\r                     0, & \\mbox{otherwise.}\r                      \\end{array} \r             \\right.\r$$\rIf $E$ is the event that the head of the spinner falls in the upper half of the\rcircle, then $E = \\{\\,x : 0 \\leq x \\leq 1/2\\,\\}$, and so\r$$\rP(E) = \\int_0^{1/2} 1\\,dx = \\frac12\\ .\r$$\rMore generally, if $E$ is the event that the head falls in the interval\r$[a,b]$, then\r$$\rP(E) = \\int_a^b 1\\,dx = b - a\\ .\r$$\r\\end{example}\r\r\\begin{example}(Example~\\ref{exam 2.2.2} continued)\r\\label{exam 2.2.6}\rIn the first dart\\index{darts} game experiment, we choose for our sample space a disc of\runit radius in the plane and for our density function the function\r$$\rf(x,y) = \\left \\{ \\begin{array}{ll}\r                1/\\pi, & \\mbox{if $x^2 + y^2 \\leq 1$,} \\\\\r                0,     & \\mbox{otherwise.}\r                  \\end{array}\r         \\right.\r$$\rThe probability that the dart lands inside the subset $E$ is then given by\r\\begin{eqnarray*}\rP(E) & = & \\int\\,\\int_E \\frac1\\pi \\,dx\\,dy\\\\\r     & = & \\frac1\\pi \\cdot (\\mbox{area\\,\\,\\, of}\\,\\,\\,E)\\ .\r\\end{eqnarray*}\r\\end{example}\r\rIn these two examples, the density function is constant and does\rnot depend on the particular outcome.  It is often the case that experiments in which the\rcoordinates are chosen \\emx {at random} can be described by \\emx {constant}\rdensity functions, and, as in Section~\\ref{sec 1.2},\rwe call such density functions \\emx {uniform}\\index{density function!uniform}\\index{uniform\rdensity function} or \\emx {equiprobable.} Not all experiments are of this type, however.\r \r\\begin{example}(Example~\\ref{exam 2.2.3} continued)\r\\label{exam 2.2.7} \rIn the second dart\\index{darts} game experiment, we choose for our sample space the unit\rinterval on the real line and for our density the function\r$$f(r) = \\left \\{ \\begin{array}{ll}\r                 2r, & \\mbox{if  $0 < r < 1$,} \\\\\r                 0,  & \\mbox{otherwise.}\r                  \\end{array}\r         \\right.\r$$\rThen the probability that the dart lands at distance $r$, $a \\leq r \\leq b$,\rfrom the center of the target is given by\r\\begin{eqnarray*}\rP([a,b]) & = & \\int_a^b 2r\\,dr\\\\\r       & = & b^2 - a^2\\ .\r\\end{eqnarray*}\rHere again, since the density is small when\r$r$ is near 0 and large when $r$ is near 1, we see that in this experiment the\rdart is more likely to land near the rim of the target than near the center. \rIn terms of the bar graph of Example~\\ref{exam 2.2.3}, the heights of the bars\rapproximate the density function, while the areas of the bars approximate the\rprobabilities of the subintervals (see Figure~\\ref{fig 2.15}).\r\\end{example}\r\\par\rWe see in this example that, unlike the case of discrete sample spaces, the\rvalue $f(x)$ of the density function for the outcome $x$\ris \\emx {not} the probability of $x$ occurring (we have seen that this\rprobability is always 0) and in general $f(x)$ is \\emx {not a probability\rat all.}  In this example, if we take $\\lambda = 2$ then $f(3/4) = 3/2$,\rwhich being bigger than 1, cannot be a probability.\r\\par\rNevertheless, the density function $f$ does contain all the\rprobability information about the experiment, since the probabilities of all\revents can be derived from it.  In particular, the probability that the outcome\rof the experiment falls in an interval $[a,b]$ is given by\r$$\rP([a,b]) = \\int_a^b f(x)\\,dx\\ ,\r$$\rthat is, by the \\emx {area} under the graph of the density function in the\rinterval $[a,b]$.  Thus, there is a close connection here between probabilities\rand areas.  We have been guided by this close connection in making up our bar\rgraphs; each bar is chosen so that its \\emx {area,} and not its height,\rrepresents the relative frequency of occurrence, and hence estimates the\rprobability of the outcome falling in the associated interval.\r\\par\rIn the language of the calculus, we can say that the probability of occurrence\rof an event of the form $[x, x + dx]$, where $dx$ is small,\ris approximately given by\r$$\rP([x, x+dx]) \\approx f(x)dx\\ ,\r$$\rthat is, by the area of the rectangle under the graph of $f$.  Note that as\r$dx \\to 0$, this probability $\\to 0$, so that the probability\r$P(\\{x\\})$ of a single point is again 0, as in Example~\\ref{exam 2.2.1}.\r\\par\rA glance at the graph of a density function tells us immediately\rwhich events of an experiment are more likely.  Roughly speaking, we can say\rthat where the density is large the events are more likely, and where it is\rsmall the events are less likely.  In Example~\\ref{exam 2.1.4.5} the density function\ris largest at 1.  Thus, given the two intervals $[0, a]$ and $[1, 1+a]$, where $a$ is \ra small positive real number, we see that $X$ is more likely to take on a value in the \rsecond interval than in the first.\r\r\\subsection*{Cumulative Distribution Functions of Continuous Random\\\\ Variables}\rWe have seen that density functions are useful when considering continuous random \rvariables.  There is another kind of function, closely related to these density functions,\rwhich is also of great importance.  These functions are called \\emx {cumulative\rdistribution}\\index{cumulative distribution function} functions.\r\\begin{definition}\rLet $X$ be a continuous real-valued random variable.  Then the cumulative distribution \rfunction of $X$ is defined by the equation\r$$F_X(x) = P(X \\le x)\\ .$$\r\\end{definition}\rIf $X$ is a continuous real-valued random variable which possesses a density function, \rthen it also has a cumulative distribution function, and the following theorem shows that the\rtwo functions are related  in a very nice way.\r\\begin{theorem}  Let $X$ be a continuous real-valued random variable with density function \r$f(x)$.  Then the function defined by\r$$F(x) = \\int_{-\\infty}^x f(t)\\,dt$$\ris the cumulative distribution function of $X$.  Furthermore, we have\r$${{d\\ }\\over{dx}} F(x) = f(x)\\ .$$\r\\proof  By definition, \r$$F(x) = P(X \\le x)\\ .$$\rLet $E = (-\\infty, x]$.  Then\r$$P(X \\le x) = P(X \\in E)\\ ,$$\rwhich equals\r$$\\int_{-\\infty}^x f(t)\\,dt\\ .$$\r\\par\rApplying the Fundamental Theorem of Calculus to the first equation in the statement of \rthe theorem yields the second statement.\r\\end{theorem}\r\\par\rIn many experiments, the density function of the relevant random variable is easy to \rwrite down.  However, it is quite often the case that the cumulative distribution function\ris easier to obtain than the density function.  (Of course, once we have the cumulative\rdistribution function, the density function can easily be obtained by differentiation, as\rthe above theorem shows.)  We now give some examples which exhibit this phenomenon.\r\\begin{example}\\label{exam 2.2.7.1}\rA real number is chosen at random from $[0, 1]$ with uniform probability, and then this \rnumber is squared.  Let $X$ represent the result.  What is the cumulative distribution\rfunction of $X$?   What is the density of $X$?\r\\par\rWe begin by letting $U$ represent the chosen real number.  Then $X = U^2$.  If $0 \\le x \r\\le 1$, then we have\r\\begin{eqnarray*}\rF_X(x) & = & P(X \\le x) \\\\\r& = & P(U^2 \\le x) \\\\\r& = & P(U \\le \\sqrt x) \\\\\r& = & \\sqrt x\\ .\r\\end{eqnarray*}\rIt is clear that $X$ always takes on a value between 0 and 1, so the cumulative \rdistribution function of $X$ is given by\r$$\rF_X(x) = \\left \\{ \\begin{array}{ll}\r                                 0, & \\mbox{if $x \\le 0$}, \\\\\r                         {\\sqrt x}, & \\mbox{if $0 \\le x \\le 1$}, \\\\\r                                 1, & \\mbox{if $x \\ge 1$}.\r                    \\end{array}\r           \\right.\r$$\rFrom this we easily calculate that the density function of $X$ is\r$$\rf_X(x) = \\left \\{ \\begin{array}{ll}\r                                      0, & \\mbox{if $x \\le 0$}, \\\\\r                         1/(2{\\sqrt x}), & \\mbox{if $0 \\le x \\le 1$}, \\\\\r                                      0, & \\mbox{if  $x > 1$}.\r                    \\end{array}\r           \\right.\r$$\rNote that $F_X(x)$ is continuous, but $f_X(x)$ is not.  (See Figure~\\ref{fig 5.5}.)\r\\putfig{4.5truein}{PSfig5-5}{Distribution and density for $X = U^2$.}{fig 5.5} \r\\end{example}\r\rWhen referring to a continuous random variable $X$ (say with a uniform\rdensity function), it is  customary to say that ``$X$ is uniformly\r\\emx {distributed}\ron the interval $[a, b]$.\"  It is also customary to refer to the cumulative\rdistribution function of $X$ as the distribution function of\r$X$.  Thus, the word ``distribution\" is being used in several different ways in the\rsubject of probability.  (Recall that it also has a meaning when discussing discrete\rrandom variables.)  When referring to the cumulative distribution function of a\rcontinuous random variable $X$, we will always use the word ``cumulative\" as a\rmodifier, unless the use of another modifier, such as ``normal\" or ``exponential,\"\rmakes it clear.  Since the phrase ``uniformly densitied on the interval\r$[a, b]$\" is not acceptable English, we will have to say ``uniformly distributed\"\rinstead.\r\r\r\\begin{example}\\label{exam 2.2.7.2}\rIn Example~\\ref{exam 2.1.4.5}, we considered a random variable, defined to be the\rsum\\index{uniform random variables!sum of two continuous} of two random real numbers chosen\runiformly from $[0, 1]$.  Let the random variables $X$ and $Y$ denote the two chosen real\rnumbers.  Define $Z = X + Y$.  We will now derive expressions for the cumulative distribution\rfunction and the density function of\r$Z$.\r\r\\putfig{3truein}{PSfig2-15-5}\r{Calculation of distribution function for Example \\protect\\ref{exam\r2.2.7.2}\\protect.}{fig 2.15.5} \r\r\r\\putfig{4.5truein}{PSfig5-6}\r{Distribution and density functions for Example \\protect\\ref{exam\r2.2.7.2}\\protect.}{fig 5.6} \r\r\\par\rHere we take for our sample space $\\Omega$ the unit square in %${\\rm{\\bf R}}^2$\r$\\mat{R}^2$ \rwith uniform density.  A point $\\omega \\in \\Omega$ then consists of a pair $(x, y)$\rof numbers chosen at random.  Then $0 \\leq Z\\leq 2$.  Let $E_z$ denote the event\rthat $Z \\le z$.  In Figure~\\ref{fig 2.15.5}, we show the set $E_{.8}$.  The event $E_z$,\rfor any $z$ between 0 and 1, looks very similar to the shaded set in the figure.  For $1 < z\r\\le 2$, the set $E_z$ looks like the unit square with a triangle removed from the upper\rright-hand corner.  We can now calculate the probability distribution $F_Z$ of $Z$; it is\rgiven by\r\\begin{eqnarray*}\rF_Z(z) & = & P(Z \\le z) \\\\\r       & = & \\mbox {Area\\ of\\ }E_z \\\\\r       & = & \\left \\{\\begin{array}{ll}\r                               0, & \\mbox{if  $z < 0$}, \\\\\r                        (1/2)z^2, & \\mbox{if  $0 \\le z \\le 1$}, \\\\\r                1 - (1/2)(2-z)^2, & \\mbox{if  $1 \\le z \\le 2$}, \\\\\r                               1, & \\mbox{if  $2 < z$}.\r                     \\end{array}\r             \\right.\r\\end{eqnarray*}\rThe density function is obtained by differentiating this function:\r$$\rf_Z(z)  = \\left \\{\\begin{array}{ll}\r                        0, & \\mbox{if  $z < 0$}, \\\\\r                        z, & \\mbox{if  $0 \\le z \\le 1$}, \\\\\r                    2 - z, & \\mbox{if  $1 \\le z \\le 2$}, \\\\\r                        0, & \\mbox{if  $2 < z$}.\r                  \\end{array}\r          \\right.\r$$\rThe reader is referred to Figure~\\ref{fig 5.6} for the graphs of these functions.\r\\end{example}\r\r\\begin{example}\\label{exam 2.2.7.3}\rIn the dart\\index{darts} game described in Example~\\ref{exam 2.2.2}, %{exam 2.2.2}, \rwhat is the distribution\rof the distance of the dart from the center of the target?  What is its\rdensity?\r\r\\putfig{2.5truein}{PSfig5-8}\r{Calculation of $F_{z}$ for Example~\\protect\\ref{exam 2.2.7.3}\\protect.}{fig 5.8} \r\rHere, as before, our sample space $\\Omega$ is the unit disk in %${\\rm{\\bf R}}^2$,\r$\\mat{R}^2$,\rwith coordinates $(X, Y)$.  Let $Z = \\sqrt{X^2 + Y^2}$ represent the\rdistance from the center of the target.  Let $E$ be the event $\\{Z \\le z\\}$.  Then the \rdistribution function $F_Z$ of $Z$ (see Figure~\\ref{fig 5.8}) is given by\r\\begin{eqnarray*}\rF_Z(z) & = & P(Z \\le z) \\\\\r       & = & {{\\mbox {Area\\ of\\ }E}\\over \\mbox {Area\\ of\\ target}}\\ .\r\\end{eqnarray*}\rThus, we easily compute that\r$$\rF_Z(z) = \\left \\{ \\begin{array}{ll}\r                           0, & \\mbox{if  $z \\le 0$}, \\\\\r                         z^2, & \\mbox{if  $0 \\le z \\le 1$}, \\\\\r                           1, & \\mbox{if  $z > 1$}.\r                    \\end{array}\r           \\right.\r$$\rThe density $f_Z(z)$ is given again by the derivative of $F_Z(z)$:\r$$\rf_Z(z) = \\left \\{ \\begin{array}{ll}\r                          0, & \\mbox{if  $z \\le 0$}, \\\\\r                         2z, & \\mbox{if  $0 \\le z \\le 1$}, \\\\\r                          0, & \\mbox{if  $z > 1$}.\r                    \\end{array}\r           \\right.\r$$\rThe reader is referred to Figure~\\ref{fig 5.9} for the graphs of these functions.\r\\par\rWe can verify this result by simulation, as follows: We choose values for $X$\rand $Y$ at random from $[0,1]$ with uniform distribution, calculate $Z =\r\\sqrt{X^2 + Y^2}$, check whether $0 \\leq Z \\leq 1$, and present the results in a\rbar graph (see Figure~\\ref{fig 5.10}).\r\\putfig{5truein}\r{PSfig5-9}\r{Distribution and density for $Z =\\protect\\sqrt{X^2 + Y^2}\\protect$.}{fig 5.9}\r\\putfig{3.5truein}{PSfig5-10}\r{Simulation results for Example~\\protect\\ref{exam 2.2.7.3}\\protect.}{fig 5.10} \r\\end{example}\r\r\\begin{example}\\label{exam 2.2.7.4} %{exam 5.2.6}\rSuppose Mr.\\ and Mrs.\\ Lockhorn\\index{Lockhorn, Mr.\\ and Mrs.} agree to meet at the Hanover\rInn\\index{Hanover Inn} between 5:00 and 6:00~{\\footnotesize P.M.} on Tuesday.  Suppose each\rarrives at a time between 5:00 and 6:00 chosen at random with uniform probability.  What is the\rdistribution function for the length of time that the first to arrive has to\rwait for the other?  What is the density function?\r\\par\rHere again we can take the unit square to represent the sample space, and $(X, Y)$ \ras the arrival times (after 5:00~{\\footnotesize P.M.}) for the Lockhorns.  Let \r$Z = |X - Y|$.  Then we have\r$F_X(x) = x$ and $F_Y(y) = y$.   Moreover (see Figure~\\ref{fig 5.11}),\r\\begin{eqnarray*}\rF_Z(z) & = & P(Z \\leq z) \\\\\r       & = & P(|X - Y| \\leq z) \\\\\r       & = & \\mbox {Area\\ of\\ }E\\ .\r\\end{eqnarray*}\rThus, we have\r$$\rF_Z(z) = \\left \\{ \\begin{array}{ll}\r                         0, & \\mbox{if  $z \\le 0$}, \\\\\r             1 - (1 - z)^2, & \\mbox{if  $0 \\le z \\le 1$}, \\\\\r                         1, & \\mbox{if  $z > 1$}.\r                    \\end{array}\r           \\right.\r$$\r\\putfig{3.5truein}{PSfig5-11}{Calculation of $F_{Z}$.}{fig 5.11} %4truein \rThe density $f_Z(z)$ is again obtained by differentiation:\r$$\rf_Z(z) = \\left \\{ \\begin{array}{ll}\r                         0, & \\mbox{if  $z \\le 0$}, \\\\\r                    2(1-z), & \\mbox{if  $0 \\le z \\le 1$}, \\\\\r                         0, & \\mbox{if  $z > 1$}.\r                    \\end{array}\r           \\right.\r$$\r\r\\end{example}\r\r\\begin{example}\\label{exam 2.2.7.5}\rThere are many occasions where we observe a sequence of occurrences which occur at\r``random\"  times.  For example, we might be observing emissions of a radioactive\risotope\\index{radioactive isotope}, or cars  passing a milepost on a highway\\index{cars on a\rhighway}, or light bulbs\\index{light bulb} burning out.  In such cases, we might define a\rrandom variable $X$ to denote the time between successive occurrences.  Clearly,\r$X$ is a continuous random variable whose range consists of the non-negative real\rnumbers.  It is often the case that we can  model $X$ by using the \\emx {exponential\rdensity}\\index{exponential density}\\index{density function!exponential}.  This density is given\rby the formula\r$$f(t) = \\left \\{ \\begin{array}{ll}\r                         \\lambda e^{-\\lambda t}, & \\mbox{if  $t \\ge 0$}, \\\\\r                                              0, & \\mbox{if  $t < 0$}.\r                    \\end{array}\r         \\right. \r$$\rThe number $\\lambda$ is a non-negative real number, and represents the reciprocal of the \raverage value of $X$.  (This will be shown in Chapter~\\ref{chp 6}.)  Thus, if the average\rtime between occurrences is 30 minutes, then $\\lambda = 1/30$.  A graph of this density\rfunction with $\\lambda = 1/30$ is shown in Figure~\\ref{fig 2.16}.\r\\putfig{3.5truein}{PSfig2-16}{Exponential density with $\\lambda = 1/30$.}{fig 2.16} \rOne can see from the figure that even though the average value is 30, occasionally much \rlarger values are taken on by $X$.\r\\par\rSuppose that we have bought a computer that contains a Warp 9 hard drive\\index{hard drive,\rWarp 9}.  The salesperson says that the average time between breakdowns of this type of hard\rdrive is 30 months.  It is often  assumed that the length of time between breakdowns is\rdistributed according to the exponential density.   We will assume that this model applies\rhere, with\r$\\lambda = 1/30$.\r\\par\rNow suppose that we have been operating our computer for 15 months.  We assume that the \roriginal hard drive is still running.  We ask how long we should expect the hard drive to\rcontinue to run.  One  could reasonably expect that the hard drive will run, on the\raverage, another 15 months.  (One might also guess that it will run more than 15 months,\rsince the fact that it has already run for 15 months implies that we don't have a lemon.) \rThe time which we have to wait is a new random variable, which we will call\r$Y$.  Obviously, $Y = X - 15$.  We can write a computer program to produce a sequence of \rsimulated $Y$-values.  To do this, we first produce a sequence of $X$'s, and discard those\rvalues which are  less than or equal to 15 (these values correspond to the cases where the\rhard drive has quit running before 15 months).  To simulate a value of\r$X$, we compute the value of the expression\r$$\\Bigl(-{1\\over{\\lambda}}\\Bigr)\\log(rnd)\\ ,$$\rwhere $rnd$ represents a random real number between 0 and 1.  (That this expression has \rthe exponential density will be shown in Chapter \\ref{chp 5}.)   Figure \\ref{fig 2.17}\rshows an area bar graph of 10{,}000 simulated $Y$-values.\r\\par\rThe average value of $Y$ in this simulation is 29.74, which is closer to the original\raverage life span of 30 months than to the value of 15 months which was guessed above.  \rAlso, the distribution of $Y$ is seen to be close to the distribution of $X$.  It is in\rfact the case that \r$X$ and $Y$ have the same distribution.  This property is called the \\emx {memoryless \rproperty}\\index{memoryless property}, because the amount of time that we have to wait for an\roccurrence does not depend on how long we have already waited.  The only continuous density\rfunction with this property is the exponential density. \r\\putfig{3.5truein}{PSfig2-17}{Residual lifespan of a hard drive.}{fig 2.17} \r\\end{example}\r\r\\subsection*{Assignment of Probabilities}\r\rA fundamental question in practice is: How shall we choose the probability\rdensity function in describing any given experiment?  The answer depends to a\rgreat extent on the amount and kind of information available to us about the\rexperiment.  In some cases, we can see that the outcomes are equally likely. \rIn some cases, we can see that the experiment resembles another already\rdescribed by a known density.  In some cases, we can run the experiment a large\rnumber of times and make a reasonable guess at the density on the basis of the\robserved distribution of outcomes, as we did in Chapter~\\ref{chp 1}.  \rIn general, the problem of choosing the right density function for a given\rexperiment is a central problem for the experimenter and is not always easy to\rsolve (see Example~\\ref{exam 2.1.5}).  \rWe shall not examine this question in detail here but instead shall assume that the\rright density is already known for each of the experiments under study.\r\rThe introduction of suitable coordinates to describe a continuous sample space,\rand a suitable density to describe its probabilities, is not always\rso obvious, as our final example shows.\r\r\\subsection*{Infinite Tree}\r\r\\begin{example}\\label{exam 2.2.12}\rConsider an experiment in which a fair coin is tossed repeatedly, without\rstopping.  We have seen in Example~\\ref{exam 1.5}\rthat, for a coin tossed $n$ times, the natural sample space is a binary tree\rwith $n$ stages.  On this evidence we expect that for a coin tossed repeatedly,\rthe natural sample space is a binary tree\\index{tree diagram!infinite binary} with an infinite\rnumber of stages, as indicated in Figure~\\ref{fig 2.23}.\r\rIt is surprising to learn that, although the $n$-stage tree is obviously a\rfinite sample space, the unlimited tree can be described as a continuous\rsample space.  To see how this comes about, let us agree that a typical outcome\rof the unlimited coin tossing experiment can be described by a sequence of the\rform $\\omega = \\{\\mbox{H H T H T T H}\\dots\\}$.  If we write 1 for H and 0 for\rT, then $\\omega = \\{1\\ 1\\ 0\\ 1\\ 0\\ 0\\ 1\\dots\\}$.  In this way, each outcome is\rdescribed by a sequence of 0's and 1's.\r\r\\putfig{4truein}{PSfig2-23}{Tree for infinite number of tosses of a coin.}{fig 2.23}\r\\par\rNow suppose we think of this sequence of 0's and 1's as the binary expansion of\rsome real number $x = .1101001\\cdots$ lying between 0 and 1.  (A \\emx {binary\rexpansion}\\index{binary expansion} is like a decimal expansion but based on 2 instead of 10.) \rThen each outcome is described by a value of $x$, and in this way $x$ becomes a\rcoordinate for the sample space, taking on all real values between 0 and 1.  (We note that\rit is possible for two different sequences to correspond to the same real number; for example,\rthe sequences $\\{\\mbox{T H H H H H}\\ldots\\}$ and $\\{\\mbox{H T T T T T}\\ldots\\}$ both\rcorrespond to the real number $1/2$.  We will not concern ourselves with this apparent problem\rhere.)\r\\par\rWhat probabilities should be assigned to the events of this sample space? \rConsider, for example, the event $E$ consisting of all outcomes for which the\rfirst toss comes up heads and the second tails.  Every such outcome has the\rform $.10****\\cdots$, where $*$ can be either 0 or 1.  Now if $x$ is our\rreal-valued coordinate, then the value of $x$ for every such outcome must lie\rbetween $1/2 = .10000\\cdots$ and $3/4 = .11000\\cdots$, and moreover, every\rvalue of $x$ between 1/2 and 3/4 has a binary expansion of the form\r$.10****\\cdots$.  This means that $\\omega\\in E$ if and only if $1/2 \\leq x <\r3/4$, and in this way we see that we can describe $E$ by the interval\r$[1/2,3/4)$.  More generally, every event consisting of outcomes for which the\rresults of the first $n$ tosses are prescribed is described by a binary\rinterval of the form $[k/2^n,(k+1)/2^n)$.\r\\par\rWe have already seen in Section~\\ref{sec 1.2} that in the\rexperiment involving $n$ tosses, the probability of any one outcome must be\rexactly $1/2^n$.  It follows that in the unlimited toss experiment, the\rprobability of any event consisting of outcomes for which the results of the\rfirst $n$ tosses are prescribed must also be $1/2^n$.  But $1/2^n$ is exactly\rthe length of the interval of $x$-values describing $E$!  Thus we see that,\rjust as with the spinner experiment, the probability of an event $E$ is\rdetermined by what fraction of the unit interval lies in $E$.\r\rConsider again the statement: The probability is 1/2 that a fair coin will turn\rup heads when tossed.  We have suggested that one interpretation of this\rstatement is that if we toss the coin indefinitely the proportion of heads will\rapproach 1/2.  That is, in our correspondence with binary sequences we expect\rto get a binary sequence with the proportion of 1's tending to 1/2.  The event\r$E$ of binary sequences for which this is true is a proper subset of the set of all\rpossible binary sequences.  It does not contain, for example, the sequence\r$011011011\\ldots$ (i.e., (011) repeated again and again).  The event $E$ is\ractually a very complicated subset of the binary sequences, but its probability\rcan be determined as a limit of probabilities for events with a finite number\rof outcomes whose probabilities are given by finite tree measures.  When the\rprobability of $E$ is computed in this way, its value is found to be 1.  This\rremarkable result is known as the \\emx {Strong Law of Large Numbers}\\index{Law of Large\rNumbers!Strong}\\index{Strong Law of Large\\\\ Numbers} (or\r\\emx {Law of Averages})\\index{Law of Averages} and is one justification for our frequency\rconcept of probability\\index{frequency concept of probability}.  We shall prove a weak form of\rthis theorem in Chapter~\\ref{chp 8}.\r\\end{example}\r\r\\exercises\r\\begin{LJSItem}\r \r\\i\\label{exer 2.2.1} Suppose you choose \\emx {at random} a real number\r$X$ from the interval $[2,10]$.\r\r\\begin{enumerate}\r\\item Find the density function $f(x)$ and the probability\rof an event $E$ for this experiment, where $E$ is a subinterval $[a,b]$ of\r$[2,10]$.\r\r\\item From (a), find the probability that $X > 5$,\rthat $5 < X < 7$, and that $X^2 - 12X + 35 > 0$.\r\\end{enumerate}\r\r\\i\\label{exer 2.2.2} Suppose you choose a real number $X$ from the interval\r$[2,10]$ with a density function of the form\r$$\rf(x) = Cx\\ ,\r$$\rwhere $C$ is a constant.\r\\begin{enumerate}\r\r\\item Find $C$.\r\r\\item Find $P(E)$, where $E = [a,b]$ is a subinterval of $[2,10]$.\r\r\\item Find $P(X > 5)$, $P(X < 7)$, and $P(X^2 - 12X + 35 > 0)$.\r\\end{enumerate}\r\r\\i\\label{exer 2.2.100} Same as Exercise \\ref{exer 2.2.2}, but suppose\r$$\rf(x) = \\frac Cx\\ .\r$$\r\r\\i\\label{exer 2.2.4} Suppose you throw a dart\\index{darts} at a circular target of\rradius 10 inches.  Assuming that you hit the target and that the coordinates of\rthe outcomes are chosen at random, find the probability that the dart falls\r\r\\begin{enumerate}\r\\item within 2 inches of the center.\r\r\\item within 2 inches of the rim.\r\r\\item within the first quadrant of the target.\r\r\\item within the first quadrant and within 2 inches of the rim.\r\\end{enumerate}\r\r\\i\\label{exer 2.2.5} Suppose you are watching a radioactive source\\index{radioactive isotope}\rthat emits particles at a rate described by the exponential density\r$$\rf(t) = \\lambda e^{-\\lambda t}\\ ,\r$$\rwhere $\\lambda = 1$, so that the probability $P(0,T)$ that a particle will appear \rin the next $T$ seconds is $P([0,T]) = \\int_0^T\\lambda e^{-\\lambda t}\\,dt$.  Find the\rprobability that a particle (not necessarily the first) will appear\r\r\\begin{enumerate}\r\\item within the next second.\r\r\\item within the next 3 seconds.\r\r\\item between 3 and 4 seconds from now.\r\r\\item after 4 seconds from now.\r\\end{enumerate}\r\r\\i\\label{exer 2.2.6} Assume that a new light bulb\\index{light bulb} will burn out after $t$\rhours, where $t$ is chosen from $[0,\\infty)$ with an exponential density\r$$\rf(t) = \\lambda e^{-\\lambda t}\\ .\r$$\rIn this context, $\\lambda$ is often called the \\emx {failure rate} of the bulb.\r\r\\begin{enumerate}\r\\item Assume that $\\lambda = 0.01$, and find the probability that the bulb\rwill \\emx {not} burn out before $T$ hours.  This probability is often called\rthe \\emx {reliability} of the bulb.\r\r\\item For what $T$ is the reliability of the bulb $ = 1/2$?\r\\end{enumerate}\r\r\\i\\label{exer 2.2.7} Choose a number $B$ \\emx {at random} from the\rinterval $[0,1]$ with uniform density.  Find the probability that\r\\begin{enumerate}\r\\item $1/3 < B < 2/3$.\r\r\\item $|B - 1/2| \\leq 1/4$.\r\r\\item $B < 1/4$ or $1 - B < 1/4$.\r\r\\item $3B^2 < B$.\r\\end{enumerate}\r\r\\i\\label{exer 2.2.8} Choose independently two numbers $B$ and $C$\r\\emx {at random} from the interval $[0,1]$ with uniform density.  Note that\rthe point $(B,C)$ is then chosen \\emx {at random} in the unit square.  Find the\rprobability that\r\r\\begin{enumerate}\r\\item $B + C < 1/2$.\r\r\\item $BC < 1/2$.\r\r\\item $|B - C| < 1/2$.\r\r\\item $\\max\\{B,C\\} < 1/2$.\r\r\\item $\\min\\{B,C\\} < 1/2$.\r\r\\item $B < 1/2$ and $1 - C < 1/2$.\r\r\\item conditions (c) and (f) both hold.\r\r\\item $B^2 + C^2 \\leq 1/2$.\r\r\\item $(B - 1/2)^2 + (C - 1/2)^2 < 1/4$.\r\\end{enumerate}\r\r\\i\\label{exer 2.2.8.5}  Suppose that we have a sequence of occurrences.  We assume\rthat the time $X$ between occurrences is exponentially distributed with $\\lambda = 1/10$,\rso on the average, there is one occurrence every 10 minutes (see Example \\ref{exam 2.2.7.5}).  \rYou come upon this system at time 100, and wait until the next occurrence.  Make a conjecture \rconcerning how long, on the average, you will have to wait.  Write a program to see if\ryour conjecture is right.\r\r\\i\\label{exer 2.2.8.6}  As in Exercise \\ref{exer 2.2.8.5}, assume that we have a sequence\rof occurrences, but now assume that the time $X$ between occurrences is uniformly distributed\rbetween 5 and 15.  As before, you come upon this system at time 100, and wait until the next\roccurrence.  Make a conjecture concerning how long, on the  average, you will have to wait.  \rWrite a program to see if your conjecture is right.\r\r\\i\\label{exer 2.2.11} For examples such as those in Exercises \\ref{exer 2.2.8.5} and \r\\ref{exer 2.2.8.6}, it might seem that at least you should not have to wait on average \\emx {more}\rthan 10 minutes if the average time between occurrences is 10 minutes.  Alas, even this is not \rtrue.  To see why, consider the following assumption\rabout the times between occurrences.  Assume that the time between occurrences is  3\rminutes with probability .9 and 73 minutes with probability .1.  Show by\rsimulation that the average time between occurrences is 10 minutes, but that if you come upon this\rsystem at time 100, your average waiting time is more than 10 minutes.\r\r\\i\\label{exer 2.2.13} Take a stick\\index{stick of unit length} of unit length and break it into\rthree pieces, choosing the break points at random.  (The break points are assumed\rto be chosen simultaneously.)  What is the probability that the three pieces \rcan be used to form a triangle?  \\emx {Hint}: \rThe sum of the lengths of any two pieces must exceed the length\rof the third, so each piece must have length $< 1/2$.  Now use Exercise~\\ref{exer 2.2.8}(g). \r\r\\i\\label{exer 2.2.14} Take a stick of unit length\\index{stick of unit length} and break it into\rtwo pieces, choosing the break point at random.  Now break the longer of the\rtwo pieces at a random point.  What is\rthe probability that the three pieces can be used to form a triangle?  \r\r\\i\\label{ex:cr} Choose independently two numbers $B$ and $C$ \\emx {at random} from the\rinterval $[-1,1]$ with uniform distribution, and consider the quadratic\requation\\index{quadratic equation, roots of}\r$$\rx^2 + Bx + C = 0\\ .\r$$\rFind the probability that the roots of this equation\r\\begin{enumerate}\r\\item are both real.\r\r\\item are both positive.\r\\end{enumerate}\r\r\\emx {Hints}: (a) requires $0 \\leq B^2 - 4C$,\r(b) requires $0 \\leq B^2 - 4C$, $B \\leq 0$, $0 \\leq C$.\r\r\\i\\label{ex:cs} At the Tunbridge World's Fair, a coin toss game works as follows. \rQuarters are tossed onto a checkerboard.  The management keeps all the\rquarters, but for each quarter landing entirely within one square of the\rcheckerboard the management pays a dollar.  Assume that the edge of each\rsquare is twice the diameter of a quarter, and that the outcomes are described\rby coordinates chosen \\emx {at random.}  Is this a fair game?\r\r\\i\\label{exer 2.2.16} Three points are chosen \\emx {at random} on a\rcircle of \\emx {unit circumference.}  What is the probability that the\rtriangle\\index{triangle!acute} defined by these points as vertices has three acute angles? \r\\emx {Hint}: One of the angles is obtuse if and only if all three points lie in the same\rsemicircle.  Take the circumference as the interval $[0,1]$.  Take one point\rat 0 and the others at $B$ and $C$.\r\r\\i\\label{exer 2.2.17} Write a program to choose a random number $X$ in\rthe interval $[2,10]$ 1000 times and record what fraction of the outcomes\rsatisfy $X > 5$, what fraction satisfy $5 < X < 7$, and what fraction satisfy\r$x^2 - 12x + 35 > 0$.  How do these results compare with Exercise \\ref{exer 2.2.1}? \r\r\\i\\label{exer 2.2.18} Write a program to choose a point $(X,Y)$ \\emx {at random} in a \rsquare of side 20 inches, doing this 10{,}000 times, and recording what fraction of the\routcomes fall within 19 inches of the center; of these, what fraction fall\rbetween 8 and 10 inches of the center; and, of these, what fraction fall within\rthe first quadrant of the square.  How do these results compare with those of\rExercise~\\ref{exer 2.2.4}?\r\r\\i\\label{exer 2.2.19} Write a program to simulate the problem describe in \rExercise~\\ref{exer 2.2.7}  (see Exercise~\\ref{exer 2.2.17}).\rHow do the simulation results compare with the results of Exercise~\\ref{exer 2.2.7}?\r\r\\i\\label{exer 2.2.20} Write a program to simulate the problem described in Exercise \\ref{exer\r2.2.13}.  \r\r\\i\\label{exer 2.2.21} Write a program to simulate the problem described in Exercise \\ref{exer\r2.2.16}.\r\r\\i\\label{exer 2.2.22} Write a program to carry out the following experiment.  A coin is tossed\r100 times and the number of heads that turn up is recorded.  This experiment is\rthen repeated 1000 times.  Have your program plot a bar graph for the\rproportion of the 1000 experiments in which the number of heads is $n$, for\reach $n$ in the interval $[35,65]$.  Does the bar graph look as though it can be fit with a\rnormal  curve?\r\r\\item\\label{exer 2.2.23} Write a program that picks a random number between 0 and 1 and computes\rthe negative of its logarithm.  Repeat this process a large number of times and\rplot a bar graph to give the number of times that the outcome falls in each\rinterval of length 0.1 in $[0,10]$.  On this bar graph plot a graph of the\rdensity $f(x) = e^{-x}$.  How well does this density fit your graph?\r\r\\end{LJSItem}\r%\\end{document}\r\r", "meta": {"hexsha": "9198907d0cafc1166fd476f6e4760ae386d41a4b", "size": 73966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ch2.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/ch2.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/ch2.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": 73966.0, "max_line_length": 73966, "alphanum_fraction": 0.706838277, "num_tokens": 22713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.8397339676722394, "lm_q1q2_score": 0.6960880780179117}}
{"text": "% !TEX root = ./Basilisk-avsLibrary20170812.tex\n\n\n\n\n\\section{Library Description}\nThe AVS lab has released a set of astrodynamics C-functions\\footnote{\\url{http://hanspeterschaub.info/AVS-Code.html}} that facilitate common orbital or rotational dynamics evaluations.  The functions are openly available, and are included with the AIAA Education Series textbook \\emph{Analytical Mechanics of Space Systems}\\cite{schaub} since the first release in 2003.  The most up to date public versions are found on the AVS web page.\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.   The library provides common matrix and vector manipulation tools such as performing a matrix product, including the transpose operators, as well as doing the matrix inverse operations.  The vector library supports doing dot and cross product operations, as well as taking a norm of a vector.  Helper functions are provided to initial zero or identity matrices, as well as check if the matrix elements are zero\n\n\n\n\n\n\\subsection{{\\tt rigidBodyKinematics} Library}\nThe rigid body kinematics library provides a range of functions related to mapping between attitude coordinates descriptions, compute the addition or subtraction of orientations, as well as returning the differential kinematic equations.  This library has been included with Reference~\\citenum{schaub} since 2003 and has been used extensively across a range of research projects.  Reference~\\citenum{schaub} provides all the mathematical details of the transformation used here in Chapter 3, while Appendix E provides a comprehensive discussion of all the algorithms included.\n\n\n\n\\subsection{{\\tt orbitalMotion} Library}\nCommon celestial mechanics tools are implemented in the {\\tt orbitalMotion} library, including transforming between anomaly angles, converting between inertial Cartesian position and velocity vector components and classical orbit elements, as well as evaluating simple space environment parameters.  The following developments use the notation and formulation of Chapter 9 in Reference~\\citenum{schaub}.  The variable naming is reflected within the software code.  \n\n\n\\subsubsection{Classical Orbital Elements}\nThe classcial orbit elements are given by \n$$\n\t(a, e, i, \\Omega, \\omega, f)\n$$\nwhere $a$ is the semi-major axis or SMA, $e$ is the eccentricity, $(\\Omega, i, \\omega)$ are the 3-1-3 Euler angle orbit plane orientation angles called the ascending node $\\Omega$, the inclination angle $i$ and the argument of periapses $\\omega$ which are illustrated in Figure~\\ref{fig:orbit313}.   The semi-latus rectum $p$ is defined as\n\\begin{equation}\n\tp = a (1-e^{2})\n\\end{equation}\n\\begin{figure}[t]\n\t\\centering\n\t\\subfigure[Orbit Frame Orientation Illustration]\n\t{\\label{fig:orbit313} \n\t\\includegraphics[width=0.45\\textwidth]{Figures/orbit313}}  \t\n\t\\\\\t\n\t\\subfigure[Classical orbital parameter Illustration for an Elliptic Orbit]\n\t{\\label{fig:orbitElliptic}\n\t\\includegraphics[width=0.45\\textwidth]{Figures/orbitEllipse}} \n\t\\subfigure[Classical orbital parameter Illustration for a Hyperbolic Orbit]\n\t{\\label{fig:orbitHyperbolic} \n\t\\includegraphics[width=0.45\\textwidth]{Figures/orbitHyperbola}}  \n\t\\caption{Orbit Elements, Axes and Frames Illustrations.\\cite{schaub}}\n\t\\label{fig:orbitParameters}\n\\end{figure}\n\nFinally, the true anomaly angle is given by $f$, while the eccentric anomaly angle is expressed through $E$ as illustrated in Figure~\\ref{fig:orbitElliptic} for an elliptic orbit scenario.  The true and eccentric anomaly are related through\\cite{schaub}\n\\begin{equation}\n\t\\tan\\left( \\frac{f}{2} \\right) = \\sqrt{ \\frac{1+e}{1-e} } \\tan\\left( \\frac{E}{2} \\right) \n\\end{equation}\nThe mean anomaly angle $M$ relates to the eccentric anomaly angle $E$ through\\cite{schaub}\n\\begin{equation}\n\tM = E - e \\sin E\n\\end{equation}\n\nThe classical orbit elements for a hyperbolic scenario are shown in Figure~\\ref{fig:orbitHyperbolic}.  Note that the convention is used where the SMA is a negative value for a hyperbolic orbit, and thus $a < 0$ in this case.  The true anomaly angle $f$ definition is universal for all orbit types, while the hyperbolic anomaly $H$ relates to $f$ through\n\\begin{equation}\n\t\\tanh\\left( \\frac{f}{2} \\right) = \\sqrt{ \\frac{e+1}{e-1}} \\tanh\\left( \\frac{H}{2} \\right) \n\\end{equation}\nThe hyperbolic mean anomaly is defined in terms of the hyperbolic anomaly through\n\\begin{equation}\n\tN = e \\sinh H - H\n\\end{equation}\n\n\nWhile mapping from eccentric or hyperbolic anomalies to mean anomalies is analytical, the inverse is not.  The sub-routines use Newton's method to numerically solve from mean anomalies to the corresponding eccentric or hyperbolic anomalies.  This is called solving Kepler's equation.  The iterations continue until a change tolerance of $10^{-13}$ radians is achieved, or a maximum of 200 iterations are performed.  Note that solving this Kepler's equation for most cases converges very quickly within 3-5 iterations.  \n\n\n\n\n\\subsubsection{Orbit Element to Cartesian Coordinate Conversions}\nLet $\\leftexp{N}{\\bm r}_{C/N}$ and $\\leftexp{N}{\\bm v}_{C/N}$ be the inertial spacecraft center of mass $C$ position and velocity vector matrix representations, expressed with respect to inertial frame \\frameDefinition{N} components.  Functions are provided to map from classical orbit elements to these Cartesian coordinates through {\\tt elem2rv()}, as well as the inverse mapping from Cartesian to classical orbit elements through {\\tt rv2elem()}.  \n\n\\paragraph{{\\tt elem2rv()} Function}\nThe general conversion of classical orbit elements to the inertial Cartesian components is outlined in detail in section 9.6.2 of Reference~\\citenum{schaub}.  Given the true anomaly angle $f$, the orbit radius is for any orbit type given by\n\\begin{equation}\n\tr = \\frac{p}{1 + e \\cos f}\n\\end{equation}\nThe true latitude angle $\\theta$ is given by\n\\begin{equation}\n\t\\theta = \\omega + f\n\\end{equation}\nThe inertial position vector is then given by\\cite{schaub}\n\\begin{equation}\n\\bm r_{C/N} =r {\\begin{matrix} ~ \\\\ ~ \\\\ ~\n\\end{matrix}}^{\\cal N}\\!\\!\\!\\!  \\begin{pmatrix}\n\\cos\\Omega\\cos\\theta \n- \\sin\\Omega\\sin\\theta\\cos i \\\\ \n\\sin\\Omega\\cos\\theta + \\cos\\Omega\\sin\\theta\\cos \ni \\\\\n \\sin\\theta\\sin i \n \\end{pmatrix}\n\\label{eq:tb:r2}\n\\end{equation}\nwhile the inertial velocity vector is\n\\begin{equation}\n\\dot{\\bm r}_{C/N} = -\\frac{\\mu}{h}\n{\\begin{matrix} ~ \\\\ ~ \\\\ ~\n\\end{matrix}}^{\\cal N}\\!\\!\\!\\!  \\begin{pmatrix}\n\\cos\\Omega (\\sin\\theta + e\\sin\\omega ) + \\sin\\Omega \n(\\cos\\theta+e\\cos\\omega )\\cos i \\\\\n\\sin\\Omega (\\sin\\theta + e\\sin\\omega ) - \\cos\\Omega ( \\cos\\theta \n+ e\\cos\\omega )\\cos i \\\\\n-(\\cos\\theta + e\\cos\\omega )\\sin i\n\\end{pmatrix}\n\\label{eq:tb:dr2}\n\\end{equation}\nwhere $\\mu$ is the gravitational constant and $h$ is the massless orbital angular momentum $\\bm h = \\bm r \\times \\dot{\\bm r}$.  \n\n\nThe {\\tt elem2rv()} function checks for a special rectilinear motion case.  Here the eccentricity is $e = 1$ while the SMA is positive with $a>0$.  Under this condition the spacecraft is moving purely along a radial direction relative to the planet, and the true anomaly angle no longer can be used to determine the spacecrafts location.  In this scenario the Eccentric anomaly angle $E$ can still be used to determine spacecraft position, and the {\\tt elem2rv()} function assumes here that the anomaly angle provided is $E$ and not $f$.  The orbit radius is here computed using\\cite{schaub}\n\\begin{equation}\n\tr = a (1 - e \\cos E)\n\\end{equation}\nThe radial unit direction vector along which all rectilinear motion is occuring is\n\\begin{equation}\n\t\\leftexp{N}{\\hat{\\bm\\imath}}_{r}=\\leftexp{N\\!\\!\\!}{\\begin{pmatrix}\n\\cos\\Omega\\cos\\omega \n- \\sin\\Omega\\sin\\omega\\cos i \\\\ \n\\sin\\Omega\\cos\\omega + \\cos\\Omega\\sin\\omega\\cos \ni \\\\\n \\sin\\theta\\sin i \n \\end{pmatrix}}\n\\end{equation}\nThe inertial position vector is then given by\n\\begin{equation}\n\\leftexp{N}{\\bm r}_{C/N} =r \\ \\leftexp{N}{\\hat{\\bm\\imath}}_{r}\n\\end{equation}\n\n\nThe velocity magnitude $v$ is determined through the orbit energy equation as\\cite{schaub}\n\\begin{equation}\n\tv = \\sqrt{ \\frac{2 \\mu}{r} - \\frac{\\mu}{a} }\n\\end{equation}\nThe inertial velocity vector is a function of the eccentric anomaly $E$ through\n\\begin{equation}\n\t\\leftexp{N}{\\bm v}_{C/N} = \\begin{cases}\n\t\t-v \\ \\leftexp{N}{\\hat{\\bm\\imath}}_{r}  & 0 \\le E \\le \\pi \\\\\n\t\t+v  \\ \\leftexp{N}{\\hat{\\bm\\imath}}_{r} & -\\pi \\le E \\le 0\n\t\\end{cases}\n\\end{equation}\n\n\n\n\n\n\\paragraph{{\\tt rv2elem()} Function}\nTo convert from the inertial position and velocity vectors to the corresponding classical orbit elements, the following algorithm is used.  First the semi-latus rectum is computed using\n\\begin{equation}\n\tp = \\frac{\\bm h \\cdot \\bm h}{\\mu}\n\\end{equation}\nThe line of nodes vector $\\bm n$ is \n\\begin{equation}\n\t\\bm n = \\hat{\\bm n}_{3} \\times \\bm h\n\\end{equation}\nThe eccentricity vector $\\bm e$ is computed using\\cite{schaub}\n\\begin{equation}\n\t\\bm e = \\frac{\\dot{\\bm r} \\times \\bm h}{\\mu} - \\frac{\\bm r}{r}\n\\end{equation}\nThe eccentricity is then simply\n\\begin{equation}\n\te = |\\bm e|\n\\end{equation}\nWithin this function the orbit radius is set through\n\\begin{equation}\n\tr = \\frac{\\bm r_{C/N}}{ | \\bm r_{C/N}|}\n\\end{equation}\nand the radius at periapses is set to\n\\begin{equation}\n\tr_{p} = \\frac{p}{1 + e}\n\\end{equation}\n\nThe SMA is computed using a robust method where first the inverse of the SMA, called $\\alpha$, is evaluated using\\cite{schaub}\n\\begin{equation}\n\t\\alpha = \\frac{2}{r} - \\frac{v^{2}}{\\mu}\n\\end{equation}\nIf $\\alpha$ is non-zero, then the orbit is not parabolic and $a$ is determined through\n\\begin{equation}\n\ta = \\frac{1}{\\alpha}\n\\end{equation}\nwhile the radius at apoapses is set to\n\\begin{equation}\n\tr_{a} = \\frac{p}{1 - e}\n\\end{equation}\nIf $\\alpha$ is zero, then the motion is parabolic and the SMA is not defined (i.e. is infinite).  In this case the code sets \n$$\n\ta = -r_{p}\n$$\nwhile $r_{a} = -1.0$ is returned as a value that is not defined in this case.\n\n\nNext the orbit frame orientation angles $\\Omega$, $i$ and $\\omega$ must be determined.  As classical elements are used, care must be given for particular singular orientations where some angles are ill-defined.  First, assume a non-circular non-equatorial orbit scenario.  In this case $\\Omega$ is the angle between $\\hat{\\bm n}_{1}$ and $\\bm n$ where care must be taken that the right quadrant is used.  The argument of periapses is the angle between $\\hat{\\bm n}$ and $\\bm e$, where again quadrants must be checked.  Finally, the inclination angle $i$ is the angle between $\\bm h$ and $\\hat{\\bm n}_{3}$, but here no quadrants must be checked as this angle is defined as $0 \\le i \\le \\pi$.  To find the true anomaly angle, the angle between $\\bm r$ and $\\bm e$ is determine while checking for quadrants again.\n\nThe 3-1-3 Euler angles representing the orbit frame orientation have singular configurations.  The following list discusses how each case is handled:\n\\begin{itemize}\n\t\\item {\\bfseries Equatorial non-circular orbit:} Here the ascending node $\\Omega$ is ill-defined, and is  set to 0.0 radians.  \n\t\\item {\\bfseries Inclined circular orbit:}  Here the argument of periapses $\\omega$ is ill-defined, and is set to 0.0 radians.\n\t\\item {\\bfseries Equatorial circular orbit:} Here both $\\Omega$ and $\\omega$ are ill-defined are are each set to 0.0 radians.\n\\end{itemize}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsubsection{Space Environment Parameters}\n\\paragraph{Atmospheric Density}\nThis program computes the atmospheric density based on altitude  supplied by user.  This function uses a 7-th order polynomial curve fit based on  atmospheric data from the Standard Atmosphere 1976 Data. This function is valid for altitudes ranging from 100km to 1000km.\n\n\\paragraph{Mean Debye Length}\nThis program computes the Debye Length length for a given  altitude and is valid for altitudes ranging  from 200 km to GEO (35000km).  However, all values above   1000 km are HIGHLY speculative at this point.\n\n\\paragraph{Atmospheric Drag Acceleration}\nThis program computes the atmospheric drag acceleration   vector $\\leftexp{N}{\\bm a}_{d}$ acting on a spacecraft.   Note the acceleration vector output is inertial, and is   only valid for altitudes up to 1000 km.   Afterwards the drag force is zero. Only valid for Earth.  The disturbance acceleration is defined as\n\\begin{equation}\n\t\\bm a_{d} = -\\frac{\\rho}{2} C_{d} \\frac{A v^{2}}{m} \\cdot \\frac{\\dot{\\bm r}}{|\\bm r|}\n\\end{equation}\nwhere $\\rho$ is the local atmospheric density, $C_{d}$ is the drag coefficient, $A$ is the projected area into the flight direction, and $m$ is the spacecraft mass.\n\n\n\\paragraph{Gravitational Zonal Harmonics}\nThis function computes Earth's zonal harmonics from $J_{2}$ through $J_{6}$.  For other planets only their $J_{2}$ value is used, while the higher order harmonics are set to zero.  The gravitational zonal harmonic accelerations are then given by\\cite{schaub}\n\\begin{align}\n\t\\bm a_{J_{2}} &=   -\\frac{3}{2} J_{2} \n\t\\left(\\frac{\\mu}{r^{2}}\\right)\n\t\\left( \\frac{r_{eq}}{r}\\right)^{2}\n\t\\leftexp{N\\!\\!\\!}{\n\t\\begin{pmatrix}\n\t\t\\left(1-5\\left(\\frac{z}{r}\\right)^{2}\\right) \\frac{x}{r} \\\\\n\t\t\\left(1-5\\left(\\frac{z}{r}\\right)^{2}\\right) \\frac{y}{r} \\\\\n\t\t\\left(3-5\\left(\\frac{z}{r}\\right)^{2}\\right) \\frac{z}{r}\n\t\\end{pmatrix}}\n\t\\label{eq:gm:aJ2}\n\t\\\\\n\t\\bm a_{J_{3}} &=  -\\frac{1}{2} J_{3} \n\t\\left(\\frac{\\mu}{r^{2}}\\right)\n\t\\left( \\frac{r_{eq}}{r}\\right)^{3}\n\t\\leftexp{N\\!\\!\\!}{\n\t\\begin{pmatrix}\n\t\t5\\left(7 \\left(\\frac{z}{r}\\right)^{3} - 3 \\left(\\frac{z}{r}\\right) \n\t\t\\right) \\frac{x}{r} \\\\\n\t\t5\\left(7 \\left(\\frac{z}{r}\\right)^{3} - 3 \\left(\\frac{z}{r}\\right) \n\t\t\\right) \\frac{y}{r} \\\\\n\t\t3\\left(10\\left(\\frac{z}{r}\\right)^{2} - \\frac{35}{3} \n\t\t\\left(\\frac{z}{r}\\right)^{4} - 1 \\right) \n\t\\end{pmatrix}}\n\t\\label{eq:gm:aJ3}\n\t\\\\\n\t\\bm a_{J_{4}} &=  -\\frac{5}{8} J_{4} \n\t\\left(\\frac{\\mu}{r^{2}}\\right)\n\t\\left( \\frac{r_{eq}}{r}\\right)^{4}\n\t\\leftexp{N\\!\\!\\!}{\n\t\\begin{pmatrix}\n\t\t\\left(3-42 \\left(\\frac{z}{r}\\right)^{2} +63 \\left(\\frac{z}{r}\\right)^{4} \n\t\t\\right) \\frac{x}{r} \\\\\n\t\t\\left(3-42 \\left(\\frac{z}{r}\\right)^{2} +63 \\left(\\frac{z}{r}\\right)^{4} \n\t\t\\right) \\frac{y}{r} \\\\\n\t\t-\\left(15-70\\left(\\frac{z}{r}\\right)^{2} + 63 \n\t\t\\left(\\frac{z}{r}\\right)^{4}  \\right) \\frac{z}{r}\n\t\\end{pmatrix}}\n\t\\label{eq:gm:aJ4}\n\t\\\\\n\t\\bm a_{J_{5}} &=  -\\frac{J_{5}}{8}  \n\t\\left(\\frac{\\mu}{r^{2}}\\right)\n\t\\left( \\frac{r_{eq}}{r}\\right)^{5}\n\t\\leftexp{N\\!\\!\\!}{\n\t\\begin{pmatrix}\n\t\t3\\left(35\\left(\\frac{z}{r}\\right) - 210 \n\t\t\\left(\\frac{z}{r}\\right)^{3} +231 \\left(\\frac{z}{r}\\right)^{5}\n\t\t\\right) \\frac{x}{r} \\\\\n\t\t3\\left(35\\left(\\frac{z}{r}\\right) - 210 \n\t\t\\left(\\frac{z}{r}\\right)^{3} +231 \\left(\\frac{z}{r}\\right)^{5}\n\t\t\\right) \\frac{y}{r} \\\\\n\t\t\\left(15- 315\\left(\\frac{z}{r}\\right)^{2} \\!\\!+ 945 \n\t\t\\left( \\frac{z}{r}\\right)^{4}\\!\\! -693 \\left(\\frac{z}{r}\\right)^{6} \n\t\t\\right) \n\t\\end{pmatrix}}\n\t\\label{eq:gm:aJ5}\n\t\\\\\n\t\\bm a_{J_{6}} &=  \\frac{J_{6}}{16}  \n\t\\left(\\frac{\\mu}{r^{2}}\\right)\\!\n\t\\left( \\frac{r_{eq}}{r}\\right)^{6}\\!\n\t\\leftexp{N\\!\\!\\!}{\n\t\\begin{pmatrix}\n\t\t\\left(35 - 945 \\left(\\frac{z}{r}\\right)^{2} \\!\\!\n\t\t+ 3465 \\left(\\frac{z}{r}\\right)^{4} \\!\\!\n\t\t- 3003 \\left(\\frac{z}{r}\\right)^{6} \n\t\t\\right) \\frac{x}{r} \\\\\n\t\t\\left(35 - 945 \\left(\\frac{z}{r}\\right)^{2} \\!\\!\n\t\t+ 3465 \\left(\\frac{z}{r}\\right)^{4} \\!\\!\n\t\t- 3003 \\left(\\frac{z}{r}\\right)^{6}  \n\t\t\\right) \\frac{y}{r} \\\\\n\t\t\\left( 3003 \\left(\\frac{z}{r}\\right)^{6} \\!\\!\n\t\t-4851 \\left(\\frac{z}{r}\\right)^{4}\\!\\!\n\t\t+ 2205 \\left(\\frac{z}{r}\\right)^{2}\\!\\!\n\t\t- 315\n\t\t\\right) \\frac{z}{r}\n\t\\end{pmatrix}}\n\t\\label{eq:gm:aJ6}\n\\end{align}\n\n\\paragraph{Solar Radiation Disturbance Acceleration}\nA simple solar disturbance acceleration $\\bm a_{d}$ function is implemented where\n\\begin{equation}\n\t\\bm a_{d} = - \\frac{C_{r} A \\Pi}{m c s^{3}} \\bm s\n\\end{equation}\nwhere $C_{r} = 1.3$ is the radiation pressure coefficient,  $c = 299792458$m/s is the speed of light, $\\Pi = 1372.5398$ W/m$^{2}$ is the solar radiation flux and $\\bm s$ is the sun position vector relative to the spacecraft in units of AU.  The area $A$ is the projected area towards the sun.\n\n\n\n%120 linear algebra\n%9 orbital anomalies\n%8 orbital elements\n%9 environment\n%234 rigid body kinematics", "meta": {"hexsha": "129968a929b06b2f960402df524f78f3f9a3c550", "size": 16190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/utilitiesSelfCheck/_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/utilitiesSelfCheck/_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/utilitiesSelfCheck/_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": 49.5107033639, "max_line_length": 810, "alphanum_fraction": 0.7071031501, "num_tokens": 5131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.6960880777939655}}
{"text": "\\subsection{$||\\delta_i||_{\\infty}$ minimizer}\n  Naive algorithms result in $c'_i \\leq x_i$, thus according to the Invariability Theorem (\\ref{invariability}),\n  $||\\delta_i||_1$ is invariable for any of the possible results $C'$ of these algorithms and the resulting norms are not\n  necessarily the minimum possible. The following algorithm concentrates on finding a configuration $C'$ that achieves $F' = F\n  - V$ while minimizing the $||\\delta_i||_\\infty$ norm.\n\n  \\subimport{common/algorithms/}{dinfmincode.tex}\n\n  Since trust should be considered as a continuous unit and binary search bisects the interval containing the solution\n  on each recursive call, inclusion of the $\\epsilon$-parameters in \\texttt{BinSearch} is necessary for the algorithm to\n  complete in a finite number of steps.\n\n  \\subimport{common/algorithms/}{dinfbinsearchcode.tex}\n\n  Let $\\delta \\in \\left[0, \\max\\limits_{1 \\leq i \\leq n}{\\{c_i\\}}\\right]$. Furthermore, let $C'$ such that $\\forall i \\in\n  \\left[n\\right], c'_i = \\max{\\left(0, c_i - \\delta\\right)}$. We define $maxFlow\\left(\\delta\\right) =\n  maxFlow_{\\mathcal{G}'}\\left(A, B\\right) = F'$ and $MaxFlow\\left(\\delta\\right) = X'$. Conventions similar to $F$, $X$ and $C$\n  hold for $F'$, $X'$ and $\\delta$ as far as subscripts are concerned.\n  \\subimport{common/lemmas/}{maxflowmonotonicitylemma.tex}\n  \\subimport{common/proofsketches/}{maxflowmonotonicityproofsketch.tex}\n  From the previous lemma we deduce that, given a $V \\in \\left(0, F\\right)$, if we determine a $\\delta$ such that\n  $maxFlow\\left(\\delta\\right) = F - V$, this $\\delta$ is unique. Furthermore,\n  \\begin{equation*}\n    ||\\delta_i||_\\infty = \\max\\limits_{1 \\leq i \\leq n}{\\delta_i} = \\max\\limits_{1 \\leq i \\leq n}{\\left(c_i - c'_i\\right)} =\n    \\max\\limits_{1 \\leq i \\leq n}{\\left(c_i - \\max{\\left(0, c_i - \\delta\\right)}\\right)} = \\delta \\enspace.\n  \\end{equation*}\n  It is proven that the two algorithms work as expected, that is an invocation of \\texttt{dinfmin} with valid inputs returns a\n  capacity $C'$ that yields the desired $maxFlow$ and minimizes $||\\delta_i||_\\infty$. The complexity of \\texttt{BinSearch} is\n  $O\\left(\\left(maxFlow + n\\right)\\log_2\\left(\\frac{top - bot}{\\epsilon_1 + \\epsilon_2}\\right)\\right)$ and the complexity of\n  \\texttt{dinfmin} is $O\\left(\\left(maxFlow + n\\right)\\log_2\\left(\\frac{\\delta_{max}}{\\epsilon_1 + \\epsilon_2}\\right)\\right)$.\n\n", "meta": {"hexsha": "24862dba9fe387aeba015559152280155b2801c0", "size": 2378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "may31deliverable/riskinvalgs/dinfminimizer.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/dinfminimizer.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/dinfminimizer.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": 74.3125, "max_line_length": 126, "alphanum_fraction": 0.7073170732, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.6960880744692401}}
{"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\n\\title{\\textbf{Week 2.} Static games with complete information I: Elimination of dominated strategies}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\vspace{-1cm}\n\n\\subsection*{Exercise 1: Cournot Duopoly}\nThere are two firms that produce a given good for a given market. Each firm needs\nto decide how much of the good they want to produce (which can be a continuous quantity between 0 and \\(\\infty\\)).\n\nProducing one unit of the good comes at a cost of \\(c > 0\\). The price for which the\ngood can be sold is a decreasing function of the total amount of good produced,\n\\(p = a - b x\\), where \\(x\\) is the total amount of the good produced by the\ntwo firms.\n\n\\textbf{Translate this into a game, who are the players, what are the actions, what are the payoffs?}\n\n\\underline{\\textbf{Bonus question:}} Are there any dominated actions?\n\n\n\\subsection*{Exercise 2: Symmetric games}\nIn the lecture we have defined for a 2-players game with finitely many actions\nwhat it means to be symmetric. Basically, it means that the players' positions do not\nmean anything. You could switch the roles of the player 1 and 2, and the payoffs would\nremain the same.\n\n\\textbf{Can you come up with a definition of what it means that a \\(n-\\)players game is symmetric?}\n\n[Hint: For this it might be useful to use the concept of a permutation. A permutation\nis a bijective map \\(\\tau: \\{1, \\dots, n\\} \\rightarrow \\{1, \\dots, n\\}\\). Any re-ordering\nof players can thus be described as a permutation.]\n\n\n\\subsection*{Exercise 3: Dominated strategies}\n\\textbf{Show that in the following game the pure strategy \\(M\\) is dominated.}\n\n\\[\n\\begin{blockarray}{ccc}\n& L & R \\\\\n\\begin{block}{c(cc)}\n    U & (3, 0) & (0, 0) \\\\\n    M & (1, 1) & (1, 1) \\\\\n    D & (0, 0) & (3, 0) \\\\\n\\end{block}\n\\end{blockarray}\n\\]\n\n\\textbf{Show that it is no longer dominated if all ``1''s are changed to ``2''s.}\n\n\\subsection*{Exercise 4: Iterated elimination of dominated strategies I}\n\n\\textbf{Construct a 2-player game such that:}\n\n\\begin{enumerate}\n    \\item Both players have 3 actions.\n    \\item The game cannot be solved by elimination of dominated strategies.\n    \\item The game can be solved by iterated elimination of dominated strategies.\n\\end{enumerate}\n\n\\subsection*{Exercise 5: Iterated elimination of dominated strategies II}\nConsider the following 3-players game. Here the first player chooses a row,\nthe second player chooses a column, and the third player chooses a matrix.\n\n\\textbf{Can you solve this game using iterated elimination of strategies?}\n\n\\begin{equation*}\n\\begin{blockarray}{ccc}\n    & \\BAmulticolumn{2}{c}{\\text{Matrix } 1} \\\\ [1em]\n    & \\text{Col } 1 & \\text{Col } 2 \\\\\n    \\begin{block}{c(cc)}\n        \\text{Row } 1 & (2, 1, 6) & (3, 2, 3) \\\\\n        \\text{Row } 2 & (0, 4, 0) & (1, 0, 0) \\\\\n    \\end{block}\n\\end{blockarray}\\qquad\n%\n\\begin{blockarray}{ccc}\n    & \\BAmulticolumn{2}{c}{\\text{Matrix } 2} \\\\ [1em]\n    & \\text{Col } 1 & \\text{Col } 2 \\\\\n    \\begin{block}{c(cc)}\n        \\text{Row } 1 & (1, -1, 4) & (2, 1, 4) \\\\\n        \\text{Row } 2 & (-1, 4, 0) & (0, 0, 3) \\\\\n    \\end{block}\n\\end{blockarray}\n\\end{equation*}\n\n\\end{document}\n\n", "meta": {"hexsha": "99281a66f4c2a1079fffe1244f3899285a160d3f", "size": 3402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w2.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/w2.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/w2.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": 33.3529411765, "max_line_length": 114, "alphanum_fraction": 0.6901822457, "num_tokens": 1061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.6960880576216665}}
{"text": "\\subsection{Orthogonal projections}\n\nAn important use of the Gram-Schmidt Process is in orthogonal projections, the focus of this section.\n\nYou may recall that a subspace of $\\R^n$ is a set of vectors\nwhich contains the zero vector, and is closed under addition and\nscalar multiplication. Let's call such a subspace $W$. In particular,\na plane in $\\R^n$ which contains the origin, $ (0,0,\\ldots,0)$, is a subspace of $\\R^n$.\n\nSuppose a point $Y$ in $\\R^n$ is not contained in $W$, then what\npoint $Z$ in $W$ is closest to $Y$? Using the Gram-Schmidt Process, we\ncan find such a point. Let $\\vect{y}, \\vect{z}$ represent the position\nvectors of the points $Y$ and $Z$ respectively, with\n$\\vect{y}-\\vect{z}$ representing the vector connecting the two points\n$Y$ and $Z$.  It will follow that if $Z$ is the point on $W$ closest\nto $Y$, then $\\vect{y} - \\vect{z}$ will be perpendicular to $W$ (can you see why?); in\nother words, $\\vect{y} - \\vect{z}$ is orthogonal to $W$ (and to every\nvector contained in $W$) as in the following diagram.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[fill=lightgray](-3,0,2)--(-2,0.75,0)--(2,0.75,0)--(1,0,2)--(-3,0,2);\n\\draw(-2,0,0) rectangle (-1.8, 0.2,0);\n\\draw[thick,->](0,0,0)--(-2,0,0);\n\\draw[thick,->](0,0,0)--(-2,2,0);\n\\draw[red,thick,->](-2,2,0)--(-2,0,0);\n\\node[right] at (0,0,0){$0$};\n\\node[above] at (-2,2,0){$Y$};\n\\node[below left] at (-2,0,0){$Z$};\n\\node[below] at (-1,0,0){$\\vect{z}$};\n\\node[above right] at (-1,1,0){$\\vect{y}$};\n\\node[left] at (-2,1,0){$\\vect{y}-\\vect{z}$};\n\\node at (1,0.5,0){$W$};\n\\end{tikzpicture}\n\\end{center}\n\nThe vector $\\vect{z}$ is called the \\textbf{orthogonal projection} of\n$\\vect{y}$ on $W$. The definition is given as follows.\n\n\\begin{definition}{Orthogonal projection}{orthogonal-projection}\nLet $W$ be a subspace of $\\R^n$, and $Y$ be any point in\n$\\R^n$. Then the orthogonal projection of $Y$ onto $W$ is given by\n\\[\n\\vect{z} = \\proj_{W}(\\vect{y})\n=\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_1}{ \\norm{\\vect{w}_1}^2}} \\vect{w}_1\n+\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_2}{ \\norm{\\vect{w}_2}^2}} \\vect{w}_2\n+\n\\ldots\n+\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_m}{ \\norm{\\vect{w}_m}^2}} \\vect{w}_m\n\\]\nwhere $\\set{\\vect{w}_1, \\vect{w}_2,\\ldots, \\vect{w}_m}$ is any orthogonal basis of $W$.\n\\end{definition}\n\nTherefore, in order to find the orthogonal projection, we must first\nfind an orthogonal basis for the subspace. Note that one could use an\northonormal basis, but it is not necessary in this case since as you\ncan see above the normalization of each vector is included in the\nformula for the projection.\n\nBefore we explore this further through an example, we show that the\northogonal projection does indeed yield a point $Z$ (the point whose position\nvector is the vector $\\vect{z}$ above) which is the point of $W$\nclosest to $Y$.\n\n\\begin{theorem}{Approximation theorem}{approximation}\nLet $W$ be a subspace of $\\R^n$ and $Y$ any point in\n$\\R^n$. Let $Z$ be the point whose position vector is the\northogonal projection of $Y$ onto $W$. \\\\\nThen, $Z$ is the point in $W$ closest to $Y$.\n\\end{theorem}\n\n\\begin{proof}\nFirst $Z$ is certainly a point in $W$  since it is in the span of a basis of $W$.\n\nTo show that $Z$ is the point in $W$ closest to $Y$, we wish to show\nthat $|\\vect{y}-\\vect{z}_1| > |\\vect{y}-\\vect{z}|$ for all $\\vect{z}_1\n\\neq \\vect{z} \\in W$.  We begin by writing $\\vect{y}-\\vect{z}_1 =\n(\\vect{y} - \\vect{z}) + (\\vect{z} -\n\\vect{z}_1)$.  Now, the vector $\\vect{y} - \\vect{z}$ is orthogonal to\n$W$, and $\\vect{z} - \\vect{z}_1$ is contained in $W$. Therefore these\nvectors are orthogonal to each other. By the Pythagorean Theorem, we\nhave that\n\\[\n\\norm{\\vect{y} - \\vect{z}_1}^2 = \\norm{\\vect{y} - \\vect{z}} ^2 + \\norm{\\vect{z} -\\vect{z}_1} ^2 > \\norm{\\vect{y} - \\vect{z}}^2\n\\]\nThis follows because $\\vect{z} \\neq \\vect{z}_1$ so\n$\\norm{\\vect{z} -\\vect{z}_1}^2 > 0$.\n\nHence, $\\norm{\\vect{y} - \\vect{z}_1}^2 > \\norm{\n\\vect{y} - \\vect{z}}^2$. Taking the square root of each\nside, we obtain the desired result.\n\\end{proof}\n\nConsider the following example.\n\n\\begin{example}{Orthogonal projection}{orthogonal-projection}\nLet $W$ be the plane through the origin given by the equation $x - 2y\n+ z = 0$. \\\\\nFind the point in $W$ closest to the point $Y = (1,0,3)$.\n\\end{example}\n\n\\begin{solution}\nWe must first find an orthogonal basis for $W$. Notice that $W$ is\ncharacterized by all points $(a,b,c)$ where $c = 2b-a$. In other\nwords,\n\\[\nW =\n\\begin{mymatrix}{c}\na \\\\\nb \\\\\n2b - a\n\\end{mymatrix}\n=\na \\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix}\n+\nb \\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n2\n\\end{mymatrix},\n\\;\na,b \\in \\R\n\\]\n\nWe can thus write $W$ as\n\\begin{eqnarray*}\nW &=& \\mbox{span} \\set{\\vect{u}_1, \\vect{u}_2 } \\\\\n &=& \\mbox{span}\n\\set{\n\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n2\n\\end{mymatrix}\n}\n\\end{eqnarray*}\n\nNotice that this span is a basis of $W$ as it is linearly\nindependent. We will use the Gram-Schmidt Process to convert this to\nan orthogonal basis, $\\set{\\vect{w}_1, \\vect{w}_2 }$. In this\ncase, as we remarked it is only necessary to find an orthogonal basis, and it is not\nrequired that it be orthonormal.\n\n\\[\n\\vect{w}_1 = \\vect{u}_1 = \\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix}\n\\]\n\\begin{eqnarray*}\n\\vect{w}_2 &=& \\vect{u}_2 - \\paren{\\frac{ \\vect{u}_2 \\dotprod \\vect{w}_1}{\\norm{\\vect{w}_1}^2}}  \\vect{w}_1\\\\\n&=& \\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n2\n\\end{mymatrix}\n-\n\\paren{\n\\frac{-2}{2}}\n\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix}\n\\\\\n&=&\n\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n2\n\\end{mymatrix}\n+\n\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{eqnarray*}\n\nTherefore an orthogonal basis of $W$ is\n\\[\n\\set{\\vect{w}_1, \\vect{w}_2 } =\n\\set{\n\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n}\n\\]\n\nWe can now use this basis to find the orthogonal projection of the\npoint $Y=(1,0,3)$ on the subspace $W$. We will write the position\nvector $\\vect{y}$ of $Y$ as $\\vect{y} = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 3\n\\end{mymatrix}$. Using Definition~\\ref{def:orthogonal-projection}, we compute the projection as follows:\n\\begin{eqnarray*}\n\\vect{z} &=& \\proj_{W}(\\vect{y})\\\\\n&=&\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_1}{ \\norm{\\vect{w}_1}^2}} \\vect{w}_1\n+\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_2}{ \\norm{\\vect{w}_2}^2}} \\vect{w}_2 \\\\\n&=&\n\\paren{\\frac{-2}{2}} \\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix}\n+\n\\paren{\\frac{4}{3}}\n\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{c}\n\\vspace{0.05in}\\frac{1}{3} \\\\\n\\vspace{0.05in}\\frac{4}{3} \\\\\n\\vspace{0.05in}\\frac{7}{3}\n\\end{mymatrix}\n\\end{eqnarray*}\n\nTherefore the point $Z$ on $W$ closest to the point $(1,0,3)$  is $\\paren{\\frac{1}{3}, \\frac{4}{3}, \\frac{7}{3}}$.\n\n\\end{solution}\n\nRecall that the vector $\\vect{y} - \\vect{z}$ is perpendicular\n(orthogonal) to all the vectors contained in the plane $W$. Using a\nbasis for $W$, we can in fact find all such vectors which are\nperpendicular to $W$. We call this set of vectors the\n\\textbf{orthogonal complement}\\index{orthogonal complement} of $W$ and\ndenote it $W^{\\perp}$.\n\n\\begin{definition}{Orthogonal complement}{orthogonal-complement}\nLet $W$ be a subspace of $\\R^n$. Then the orthogonal\ncomplement of $W$, written $W^{\\perp}$, is the set of all vectors\n$\\vect{x}$ such that $\\vect{x} \\dotprod \\vect{z} = 0$ for all vectors\n$\\vect{z}$ in $W$.\n\\[\nW^{\\perp} = \\set{\\vect{x} \\in \\R^n \\; \\mbox{such that} \\;\n\\vect{x} \\dotprod \\vect{z} = 0 \\; \\mbox{for all} \\; \\vect{z} \\in W}\n\\]\n\\end{definition}\n\nThe orthogonal complement is defined as the set of all vectors which are orthogonal to all vectors in the original subspace. It turns out that it is sufficient that the vectors in the orthogonal complement be orthogonal to a spanning set of the original space.\n\n\\begin{proposition}{Orthogonal to spanning set}{orthogonal-spanning-set}\nLet $W$ be a subspace of $\\R^n$ such that $W = \\sspan \\set{\\vect{w}_1, \\vect{w}_2,\\ldots, \\vect{w}_m }$. Then $W^{\\perp}$ is the set of all vectors which are orthogonal to each $\\vect{w}_i$ in the spanning set.\n\\end{proposition}\n\nThe following proposition demonstrates that the orthogonal complement of a subspace is itself a subspace.\n\n\\begin{proposition}{The orthogonal complement}{subspace-complement}\nLet $W$ be a subspace of $\\R^n$. Then the orthogonal complement $W^{\\perp}$ is also a subspace of $\\R^n$.\n\\end{proposition}\n\nConsider the following proposition.\n\n\\begin{proposition}{Orthogonal complement of $\\R^n$}{complement-of-rn}\nThe complement of $\\R^n$ is the set containing the zero vector:\n\\[\n (\\R^n)^{\\perp} = \\set{\\vect{0} }\n\\]\nSimilarly,\n\\[\n\\set{\\vect{0} }^{\\perp} = (\\R^n)\n\\]\n\\end{proposition}\n\n\\begin{proof}\nHere, $\\vect{0}$ is the zero vector of $\\R^n$.\nSince $\\vect{x}\\dotprod\\vect{0}=0$ for all $\\vect{x}\\in\\R^n$,\n$\\R^n\\subseteq\\set{\\vect{0}}^{\\perp}$.\nSince $\\set{\\vect{0}}^{\\perp}\\subseteq\\R^n$, the equality follows,\ni.e., $\\set{\\vect{0}}^{\\perp}=\\R^n$.\n\nAgain, since $\\vect{x}\\dotprod\\vect{0}=0$ for all $\\vect{x}\\in\\R^n$,\n$\\vect{0}\\in (\\R^n)^{\\perp}$, so $\\set{\\vect{0}}\\subseteq(\\R^n)^{\\perp}$.\nSuppose $\\vect{x}\\in\\R^n$, $\\vect{x}\\neq\\vect{0}$.\nSince $\\vect{x}\\dotprod\\vect{x}=||\\vect{x}||^2$ and $\\vect{x}\\neq\\vect{0}$,\n$\\vect{x}\\dotprod\\vect{x}\\neq 0$, so $\\vect{x}\\not\\in(\\R^n)^{\\perp}$.\nTherefore $(\\R^n)^{\\perp}\\subseteq \\set{\\vect{0}}$, and thus\n$(\\R^n)^{\\perp}=\\set{\\vect{0}}$.\n\\end{proof}\n\nIn the next example, we will look at how to find\n$W^{\\perp}$.\n\n\\begin{example}{Orthogonal complement}{orthogonal-complement}\nLet $W$ be the  plane through the origin given by the equation  $x - 2y + z = 0$. Find\na basis for the orthogonal complement of $W$.\n\\end{example}\n\n\\begin{solution}\n\nFrom Example~\\ref{exa:orthogonal-projection} we know that we can write $W$ as\n\\[\nW = \\mbox{span} \\set{\\vect{u}_1, \\vect{u}_2 } = \\mbox{span}\n\\set{\n\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n-1\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n2\n\\end{mymatrix}\n}\n\\]\n\nIn order to find $W^{\\perp}$, we need to find all $\\vect{x}$ which are orthogonal to every vector in this span.\n\nLet $\\vect{x} = \\begin{mymatrix}{c}\nx_1 \\\\\nx_2 \\\\\nx_3\n\\end{mymatrix}$.\nIn order to satisfy $\\vect{x} \\dotprod \\vect{u}_1 = 0$, the following equation must hold.\n\\[\nx_1 - x_3 = 0\n\\]\n\nIn order to satisfy $\\vect{x} \\dotprod \\vect{u}_2 = 0$, the following equation must hold.\n\\[\nx_2 + 2x_3 = 0\n\\]\n\nBoth of these equations must be satisfied, so we have the following system of equations.\n\\[\n\\begin{array}{c}\nx_1 - x_3 = 0 \\\\\nx_2 + 2x_3 = 0\n\\end{array}\n\\]\n\nTo solve, set up the augmented matrix.\n\n\\[\n\\begin{mymatrix}{rrr|r}\n1 & 0 & -1 & 0 \\\\\n0 & 1 & 2 & 0\n\\end{mymatrix}\n\\]\n\nUsing Gaussian Elimination, we find that $W^{\\perp} = \\mbox{span} \\set{\\begin{mymatrix}{r}\n1 \\\\\n-2 \\\\\n1\n\\end{mymatrix}\n}$, and hence\n$\\set{\\begin{mymatrix}{r}\n1 \\\\\n-2 \\\\\n1\n\\end{mymatrix}\n}$ is a basis for  $W^{\\perp}$.\n\\end{solution}\n\nThe following results summarize the important properties of the orthogonal projection.\n\n\\begin{theorem}{Orthogonal projection}{orthogonal-projection}\nLet $W$ be a subspace of $\\R^n$, $Y$ be any point in $\\R^n$, and let $Z$ be the point in $W$ closest to $Y$. Then,\n\\begin{enumerate}\n\\item\nThe position vector $\\vect{z}$ of the point $Z$ is given by $\\vect{z} = \\proj_{W}(\\vect{y})$\n\\item\n$\\vect{z} \\in W$ and $\\vect{y} - \\vect{z} \\in W^{\\perp}$\n\\item\n$| Y - Z | < | Y - Z_1 |$ for all $Z_1 \\neq Z \\in W$\n\\end{enumerate}\n\\end{theorem}\n\nConsider the following example of this concept.\n\n\\begin{example}{Find a vector closest to a given vector}{vector-closest-vector}\n\nLet\n\\[ \\vect{x}_1=\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 0 \\end{mymatrix},\n\\vect{x}_2=\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 1 \\end{mymatrix},\n\\vect{x}_3=\\begin{mymatrix}{c} 1\\\\ 1\\\\ 0\\\\ 0 \\end{mymatrix},\n\\mbox{ and }\n\\vect{v}=\\begin{mymatrix}{c} 4\\\\ 3\\\\ -2\\\\ 5 \\end{mymatrix}. \\]\nWe want to find the vector in\n$W =\\sspan\\set{\\vect{x}_1, \\vect{x}_2,\\vect{x}_3}$\nclosest to $\\vect{y}$.\n\\end{example}\n\n\\begin{solution}\nWe will first use the Gram-Schmidt Process to construct the orthogonal basis, $B$, of $W$:\n\\[ B=\\set{\n\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 0 \\end{mymatrix},\n\\begin{mymatrix}{c} 0\\\\ 0\\\\ 0\\\\ 1 \\end{mymatrix},\n\\begin{mymatrix}{r} 1\\\\ 2\\\\ -1\\\\ 0 \\end{mymatrix}\n}.\\]\n\nBy Theorem~\\ref{thm:orthogonal-projection},\n\\[ \\proj_U(\\vect{v}) =\n\\frac{2}{2} \\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 0 \\end{mymatrix} +\n\\frac{5}{1}\\begin{mymatrix}{c} 0\\\\ 0\\\\ 0\\\\ 1 \\end{mymatrix} +\n\\frac{12}{6}\\begin{mymatrix}{r} 1\\\\ 2\\\\ -1\\\\ 0 \\end{mymatrix}\n= \\begin{mymatrix}{r} 3\\\\ 4\\\\ -1\\\\ 5 \\end{mymatrix}\n\\]\nis the vector in $U$ closest to $\\vect{y}$.\n\\end{solution}\n\nConsider the next example.\n\n\\begin{example}{Vector written as a sum of two vectors}{sum-of-two-vectors}\nLet $W$ be a subspace given by $W = \\mbox{span} \\set{\n\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1 \\\\\n0 \\\\\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n2 \\\\\n\\end{mymatrix}\n}$, and $Y = (1,2,3,4)$. \\\\\nFind the point $Z$ in $W$ closest to $Y$, and moreover write $\\vect{y}$ as the sum of a  vector in $W$ and a vector in $W^{\\perp}$.\n\\end{example}\n\n\\begin{solution}\nFrom Theorem~\\ref{thm:approximation}, the point $Z$ in $W$ closest to\n$Y$ is given by $\\vect{z} = \\proj_{W}(\\vect{y})$.\n\nNotice that since the above vectors already give an orthogonal basis for $W$, we have:\n\n\\begin{eqnarray*}\n\\vect{z} &=& \\proj_{W}(\\vect{y})\\\\\n&=&\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_1}{ \\norm{\\vect{w}_1}^2}} \\vect{w}_1\n+\n\\paren{\\frac{\\vect{y} \\dotprod \\vect{w}_2}{ \\norm{\\vect{w}_2}^2}} \\vect{w}_2 \\\\\n&=&\n\\paren{\\frac{4}{2}} \\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n+\n\\paren{\\frac{10}{5}}\n\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n2\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{c}\n2 \\\\\n2 \\\\\n2 \\\\\n4\n\\end{mymatrix}\n\\end{eqnarray*}\n\nTherefore the point in $W$ closest to $Y$ is $Z = (2,2,2,4)$. \\\\\n\nNow, we need to write $\\vect{y}$ as the sum of a vector in $W$ and a\nvector in $W^{\\perp}$. This can easily be done as follows:\n\\[\n\\vect{y} = \\vect{z} + (\\vect{y} - \\vect{z})\n\\]\nsince $\\vect{z}$ is in $W$ and as we have seen $\\vect{y} - \\vect{z}$ is in  $W^{\\perp}$. \\\\\nThe vector $\\vect{y} - \\vect{z}$ is given by\n\\[\n\\vect{y} - \\vect{z} = \\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n3 \\\\\n4\n\\end{mymatrix}\n-\n\\begin{mymatrix}{c}\n2 \\\\\n2 \\\\\n2 \\\\\n4\n\\end{mymatrix}\n =\n\\begin{mymatrix}{r}\n-1 \\\\\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n\\]\nTherefore, we can write $\\vect{y}$ as\n\\[\n\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n3 \\\\\n4\n\\end{mymatrix}\n=\n\\begin{mymatrix}{c}\n2 \\\\\n2 \\\\\n2 \\\\\n4\n\\end{mymatrix}\n+\n\\begin{mymatrix}{r}\n-1 \\\\\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n\\]\n\\end{solution}\n\n\\begin{example}{Point in a plane closest to a given point}{closest-plane}\nFind the point $Z$ in the plane $3x+y-2z=0$ that is closest to\nthe point $Y=(1,1,1)$.\n\\end{example}\n\n\\begin{solution}\nThe solution will proceed as follows.\n\\begin{enumerate}\n\\item Find a basis $X$ of the subspace $W$ of $\\R^3$ defined by\nthe equation  $3x+y-2z=0$.\n\\item Orthogonalize the basis $X$ to get an orthogonal basis\n$B$ of $W$.\n\\item Find the projection on $W$ of the position vector of\nthe point $Y$.\n\\end{enumerate}\n\nWe now begin the solution.\n\\begin{enumerate}\n\\item $3x+y-2z=0$ is a system of one equation in three variables.\nPutting the augmented matrix in {\\rref}:\n\\[\n\\begin{mymatrix}{rrr|r} 3 & 1 & -2 & 0 \\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr|r} 1 & \\frac{1}{3} & -\\frac{2}{3} & 0 \\end{mymatrix}\n\\]\ngives general solution $x=\\frac{1}{3}s+\\frac{2}{3}t$, $y=s$, $z=t$\nfor any $s,t\\in\\R$.\nThen\n\\[\nW=\\sspan \\set{\n\\begin{mymatrix}{r} -\\frac{1}{3} \\\\ 1 \\\\ 0 \\end{mymatrix},\n\\begin{mymatrix}{r} \\frac{2}{3} \\\\ 0 \\\\ 1 \\end{mymatrix}}\n\\]\nLet\n$X=\\set{\n\\begin{mymatrix}{r} -1 \\\\ 3 \\\\ 0 \\end{mymatrix},\n\\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}}$.\nThen $X$ is linearly independent and $\\sspan(X)=W$, so $X$ is a basis of $W$.\n\n\\item Use the Gram-Schmidt Process to get an\northogonal basis of $W$:\n\n\\[ \\vect{f}_1=\\begin{mymatrix}{r} -1 \\\\ 3 \\\\ 0 \\end{mymatrix}\n\\mbox{ and }\n\\vect{f}_2 =\n\\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n-\\frac{-2}{10}\\begin{mymatrix}{r} -1 \\\\ 3 \\\\ 0 \\end{mymatrix}\n=\\frac{1}{5}\\begin{mymatrix}{r} 9 \\\\ 3 \\\\ 15 \\end{mymatrix}.\\]\nTherefore\n$B=\\set{\\begin{mymatrix}{r} -1 \\\\ 3 \\\\ 0 \\end{mymatrix},\n\\begin{mymatrix}{r} 3 \\\\ 1 \\\\ 5 \\end{mymatrix} }$ is\nan orthogonal basis of $W$.\n\\item To find\nthe point $Z$ on $W$ closest to $Y=(1,1,1)$, compute\n\\begin{eqnarray*}\n\\proj_{W}\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n& = &\n\\frac{2}{10} \\begin{mymatrix}{r} -1 \\\\ 3 \\\\ 0 \\end{mymatrix}\n+ \\frac{9}{35}\\begin{mymatrix}{r} 3 \\\\ 1 \\\\ 5 \\end{mymatrix}\\\\\n& = &\n\\frac{1}{7}\\begin{mymatrix}{r} 4 \\\\ 6 \\\\ 9 \\end{mymatrix}.\n\\end{eqnarray*}\nTherefore, $Z=\\paren{\\frac{4}{7}, \\frac{6}{7}, \\frac{9}{7}}$.\n\\end{enumerate}\n\\end{solution}\n", "meta": {"hexsha": "497ae7102742b6f6d45141ae23d04a285ea06362", "size": 16600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsOrthogonalityProjections.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/RnVectorsOrthogonalityProjections.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/RnVectorsOrthogonalityProjections.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.2577996716, "max_line_length": 260, "alphanum_fraction": 0.6397590361, "num_tokens": 6411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.9184802484881361, "lm_q1q2_score": 0.6960191724793793}}
{"text": "% !TEX root = ../main.tex\n\n\\section{Graph metrics}\n\nWhat is essential on the graph?\n\nTypes of properties:\n\\begin{enumerate}\n  \\item Local: property of the surrounding node\n  \\item Global: characteristic of the entire graph\n\\end{enumerate}\n\n\\subsection{Graph metrics}\n\\subsubsection{Degree}\n\nDegree $d_j$ of node $j$: number of neighbours of $j$\n\n\\begin{figure}\n  \\centering\n  \\begin{tikzpicture}\n    \\node[state] (1) {1};\n    \\node[state, right = 2 of 1] (3) {3};\n    \\node[state, below right = of 1] (2) {2};\n    \\node[state, below right = of 3] (4) {4};\n    \\node[state, below = 2 of 1] (6) {6};\n    \\node[state, below = 2 of 3] (5) {5};\n\n    \\draw[-]    (1)   edge    (3)\n                      edge[bend right]    (2)\n                      edge    (6)\n                (2)   edge[bend left]     (6)\n                      edge[bend left]     (5)\n                      edge    (3)\n                (5)   edge    (4)\n                      edge[bend left]     (6)\n                (4)   edge    (3);\n                    \n  \\end{tikzpicture}\n\\end{figure}\n\n$$\n\\sum_{j=1}^N d_j = 2L\n$$\n\nAverage degree in $\\mathcal{G}$ equals:\n$$\nE[D] = \\frac{1}{N} \\sum_{j=1}^N d_j = \\frac{2L}{N}\n$$\n\nBounds (connected graph):\n$$\n2 - \\frac{2}{N} \\le E[D] \\le N-1\n$$\n\n$$\nL(K_N) = \n\\begin{pmatrix}\n  N \\\\ 2\n\\end{pmatrix} = \\frac{N (N-1)}{2}\n$$\n\nDegree vector (row sum A): $d = Au$\n\\begin{itemize}\n  \\item Coordinate representation of the vector: $u = (1, 1, ..., 1)$\n  \\item Matrix representation of the vector $u^T = [1 1 ... 1]$. A vector in $m$ dimensions is\n  a $m \\times 1$ matrix (elements in a column)\n\\end{itemize}\n\n\\emph{Basic law of the degree}:\n$$\nu^T d = 2L \\xRightarrow{thus} u^Td = u^T Au = 2L\n$$\n\n\\begin{itemize}\n  \\item At least two nodes in G have the same degree\n  \\begin{itemize}\n    \\item A degree $N-1$ node excludes the existence of a zero degree node\n  \\end{itemize}\n  \\item The number of nodes with \\textbf{odd} degree is \\textbf{even}\n\\end{itemize}\n\nYou can also create a histogram plotting all the degrees. This allows you to have the average\nand the variance of the degrees (slide 6).\n\nExample: degree of an airport\nThe probability is almost linear in a log scale. It has been found that many real life problems\nhave an almost linear degree distribution.\n$$\nPr[D_{\\text{Air}} = k] \\sim k^{-1.21}\n$$\n\nInternet:\n$$\nPr[D_{\\text{Internet}} = k] \\sim k^{-\\tau}, \\quad \\tau \\in (2.2, 2.5)\n$$\n\nMany networks have a power law degree distribution (scale-free networks)\n\n\\subsubsection{Clustering coefficient}\nThe degree can be seen as a global metric. This one goes a bit step further.\n\nThe clustering coefficient of node $v$ is \n$$\nc_G(v) = \\frac{2y}{d_v(d_v - 1)} = \\frac{y}{y_{max}}\n$$\n\nwhere $y$ is the number of links between neighbors and \n$\ny_{max} = \\begin{pmatrix}\n  d_v \\\\ 2\n\\end{pmatrix}\n$\n\nThis number tells you how connected your environment is. The clustering coefficient of a graph G:\n$$\nc_G = \\frac{1}{N} \\sum_{v = 1}^N c_G(v)\n$$\n\n\\subsubsection{Adjacency matrix A and walks}\n\\begin{itemize}\n  \\item Walk of length $k$ from node $i$ to $j$: succession of $k$ links (arcs)\n  $n_0 \\rightarrow n_1)(n_1 \\rightarrow n_2) ... (n_{k-1} \\rightarrow n_k)$ where $n_0 = i$ and\n  $n_k = j$.\n  \\item Path: a walk in which all nodes/vertices are different\n  \\item Number of $k$-hop walks between node $i$ and $j$: $(A^k)_{ij}$\n  \\item Total number of $k$-hop walks in G: $N_k = u^T A^k u = \\sum_{i=1}^N \\sum_{j=1}^N (A^k)_{ij}$\n  \\item Total number of closed $k$-hop walks in G:\n  $$\n  W_k = \\sum_{j=1}^N (A^k)_{jj} = \\text{trace}(A^k)\n  $$\n\\end{itemize}\n\n\\subsubsection{Weight of a path P}\nConsider a weighted graph, where each link $l$ has a link weight $w_l$.\n\nThe weight of a path P is defined as:\n$$\nw(P) = \\sum_{l \\in P} w_l\n$$\n\nwhere $l = n_i \\rightarrow n_j$ is a link in $G$ from node $n_i$ to $n_j$ and part of the path\n$P = (n_0 \\rightarrow n_1)(n_01 \\rightarrow n_2)...(n_i \\rightarrow n_j)...(n_{h-1} \\rightarrow n_h)$\nThe path $P = P_{n_0 \\rightarrow n_h}$ from node $n_0$ to $n_h$ consists of $h$ \\emph{different, \nconsecutive} links\n\n\\subsubsection{Hopcount}\n\\begin{itemize}\n  \\item Hopcount of a path $P$ is $h(P) = \\sum_{l \\in P} 1$, this link weight $w_l = 1$. \n  \\item Hopcount from node $i$ to node $j$: \n  $H_{i \\rightarrow j} = \\min_{P_{i \\rightarrow j}} h(P_{i \\Rightarrow j}) \n  = h(P_{i \\rightarrow j}^{*})$ where $P_{i \\rightarrow j}^*$ is the shortest hop path from\n  $i$ to $j$\n  \\item Number of $k$-hop walks between node $i$ and $j$: $(A^k)_{ij}$\n\\end{itemize}\n\nAlgebraic algorithm to find the shortest path\n$$\n\\begin{pmatrix}\n  (A)_{ij} = 0 \\\\\n  (A^2)_{ij} = 0 \\\\\n  \\vdots \\\\\n  (A^{k -1})_{ij} = 0 \\\\\n  (A^k)_{ij} = m > 0\n\\end{pmatrix}\n$$\n\nThe sequence tells us that there are no walks between $i$ and $j$ with less than $k$ hops.\n\nHence: the shortest walk between $i$ and $j$ is also a shortest path, with hopcount $H_{ij} = k$\n\nThere are $m$ different shortest paths with $k$ hops\n\n\\subsubsection{Hopcount \\& Distance matrix}\nA distance matrix $H$ satisfies vector norm or distance relations:\n\\begin{enumerate}\n  \\item $h_{ij} \\ge 0$\n  \\item zero diagonal elements: $h_{ij} = 0$\n  \\item triangle inequality: $h_{ik} + h_{kj} \\ge h_{ij}$\n\\end{enumerate}\n\n\\textbf{Diameter} $\\rho$: \n\\begin{itemize}\n  \\item Sequence with most zeros (or maximum $k$)\n  \\item All elements in $\\sum_{k =0}^{\\rho} f_k A^k$ with all $f_k > 0$ are positive\n\\end{itemize}\n\nChoose $f_k = \\begin{pmatrix}\n  \\rho \\\\ k\n\\end{pmatrix} > 0$\nthen $\\sum_{k = 0}^{\\rho} \\begin{pmatrix}\n  \\rho \\\\ k\n\\end{pmatrix} A^k = (I + A)^{\\rho}$.\n\nThe \\textbf{small world problem}:\n\\begin{itemize}\n  \\item 160 letters: 1 target (name, address, occupation, personal info)\n  \\item 160 random starters\n  \\item Each starter forwards a letter to a single acquaintance\n  \\item Outcome experiment: Average hops of path = 6: everybody is connected by (on average) 6 hops.\n\\end{itemize}\n\n\\subsubsection{Betweenness}\n\nThe betweenness $B_l(B_n)$ of a link $l$ (node $n$) equals the number of shortest paths traversink\nlink $l$ (node $n$) in $G$).\n\nThe average betweenness is related to the average hopcount:\n$$\nH_G = \\sum_{i = 1}^N \\sum_{j = i + 1}^N H_{ij} = \\sum_{l = 1}^L B_l\n\\implies\nE[B_l] = \\frac{1}{L} \\sum_{l = 1}^L B_l = \\frac{1}{L}\n\\begin{pmatrix}\n  N \\\\ 2\n\\end{pmatrix}\nE[H_G] \\ge E[H_G]\n$$\n\nIf there are many shortest paths we need to adjust the definition. If there are $k$ shortest\npaths you count each one of them as $\\frac{1}{k}$ \n\n\\subsubsection{Linear correlation coefficient}\nConsider $n$ realizations $\\{(x_i, y_i)\\}_{1 \\le i\\le m}$ of two random variables $X$ and $Y$.\n\nGoodness of the fit can be expressed by the linear correlation coefficient\n$$\n\\rho(X, Y) = \\frac{E[XY] - E[X]E[Y]}{\\sqrt{Var[X]}\\sqrt{Var[Y]}}\n$$\n\n\\begin{itemize}\n  \\item $\\rho(X,Y) = 0$: No linear correlation\n  \\item $\\rho(X, Y) = 1$: Perfect fit\n\\end{itemize}\n\n\\subsubsection{Degree assortativity}\n\nCorrelation between the left part of the link and the right part. How are the degrees $D_i$ \nand $D_j$ at both sides of a link $l$ correlated?\n\n\\begin{itemize}\n  \\item A network is assortative if $\\rho_D > 0$\n  \\item A network is disassortative if $\\rho_D < 0$\n\\end{itemize}\n\n$$\n\\rho_D = \\frac{N_1 N_3 - N_2^2}{N_1 \\sum_{j=1}^N d_j^3 - N_2^2}\n$$\n\nWhere $N_k = u^T A^k u$ is the total number of walks with $k$ hops\n\n\\subsubsection{Degree preserving rewiring}\nBetween two pairs of nodes you keep the degree, however you rewire the network, and, by doing\nthat you change the shape of the network and the connectivity. How many rewiring do you have to \nmake in order to change the network from assortative to disassortative?\n\n\\subsubsection{Connectivity of the complement $G^C$}\nIf the graph G is disconnected, then ist complement $G^C$ is connected\n\n", "meta": {"hexsha": "ec5285d9a3c2981478b1ce6c94b09e5e1b6aec59", "size": 7711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Networking/lectures/lecture_02.tex", "max_stars_repo_name": "jmigual/APATeoria", "max_stars_repo_head_hexsha": "acea91e3d339165855742dd5c5d6961158d5c391", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/Networking/lectures/lecture_02.tex", "max_issues_repo_name": "jmigual/APATeoria", "max_issues_repo_head_hexsha": "acea91e3d339165855742dd5c5d6961158d5c391", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-08-05T10:35:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-05T10:35:08.000Z", "max_forks_repo_path": "Notes/Networking/lectures/lecture_02.tex", "max_forks_repo_name": "jmigual/APATeoria", "max_forks_repo_head_hexsha": "acea91e3d339165855742dd5c5d6961158d5c391", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-10-10T08:40:56.000Z", "max_forks_repo_forks_event_max_datetime": "2016-10-14T12:10:40.000Z", "avg_line_length": 29.8875968992, "max_line_length": 101, "alphanum_fraction": 0.6440150434, "num_tokens": 2661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790619, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.6959471953551409}}
{"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\nLet $\\mathcal{X}$, the set of examples, be the set of natural numbers.\nThe hypotheses space $H$ consists of all intervals of the form $[a,b]$ with $a \\leq b$.\nThe concept that must be learned is an interval $[c,d]$, where all examples reside.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Let $h_1$, $h_2$ be two hypotheses.\nWhat does it mean in this context that $h_1$ is more specific than $h_2$?\n\\item Design an algorithm that learns the target concept.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Since hypotheses space $H$ is the set of intervals of the form $[a, b]$ with $a \\leq b$, let us present hypothesis $h_1$ and $h_2$ as intervals $[x_1, y_1]$ and $[x_2, y_2]$ respectively, where $x_1 \\leq y_1$ and $x_2 \\leq y_2$.\n\nBy definition, hypothesis $h_1$ is more specific than $h_2$ if for every concept (natural number) $i \\in h_1$, $i \\in h_2$ as well.\nFor this to happen, for any integer $i$ in the interval $[x_1, y_1]$ we should have $i \\in [x_2, y_2]$.\nAlternatively, $h_1$ is more specific than $h_2$ when $[x_1, y_1] \\subseteq [x_2, y_2]$.\n\n\\item The objective is to propose an algorithm to find the consistent hypothesis (target concept) using both positive and negative examples.\nTo achieve this objective, we initialize most general hypothesis as the interval $[-\\infty, \\infty]$ and least general hypothesis as the empty set $\\emptyset$.\nFor any concept $c$, consistent hypothesis can be updated using \\textsc{Update-Concept} algorithm whose pseudo-code is given in Algorithm 1 and in which \\textit{SB} and \\textit{GB} are respectively maximally specific and maximally general positive hypothesis boundaries.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{LearnExample($c$)}}\\label{euclid}\n\\begin{algorithmic}[1]\n\\If {concept is positive}\n\\State add concept to SB\n\\For {$i \\leftarrow 1$ to number of GB intervals}\n\\If {concept $\\notin$ interval $i$}\n\\State remove interval $i$ from GB\n\\EndIf\n\\EndFor\n\\Else\n\\For {$i \\leftarrow 1$ to number of GB intervals}\n\\If {concept $\\in$ interval $i$}\n\\State remove concept from interval $i$\n\\Comment divides interval $i$ into two intervals\n\\EndIf\n\\EndFor\n\\EndIf\n\\end{algorithmic}\n\\end{algorithm}\n\n\\end{enumerate}\n", "meta": {"hexsha": "0892bb920ff91b31696f3f41ed328f49a61f5fc3", "size": 2567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 46.6727272727, "max_line_length": 270, "alphanum_fraction": 0.6984807168, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.695947189963926}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\graphicspath{ {./} }\n\\usepackage{amsmath}\n\n\\title{ACSL Final Test}\n\\author{Alexander Sun}\n\\date{April 2019}\n\n\\begin{document}\n\\maketitle\n\n\\newpage\n\n\\section{Computer Number Systems}\n\\begin{enumerate}\n    \\item{Problem 1 (3) Let $N$ be the number of positive integers that are less than or equal to $2003$ and whose base-$2$ representation has more $1$'s than $0$'s. Find the remainder when $N$ is divided by $1000$}\n    \n    \\item{Problem 2 (2) Convert to base 4, 8, 16 and 32}\n    \n    010111010100010101110101010001010111010100010001011110010010010101010101010010100\n    \n    101001110100010\n\\end{enumerate}\n\\section{Recursive Functions}\n\\begin{enumerate}\n\n    \\item{Problem 1 (3) Find A(4,3):}\n    \n    Ackerman's function is defined as:\n\n\\[ A(x,y)  \\left\\{\n\\begin{array}{ll}\n      y + 1 & if x = 0 \\\\\n      A(x - 1, 1) & if x \\neq 0 and y = 0 \\\\\n      A(x - 1,A(x, y - 1)) & if x \\neq 0 and  y \\neq 0 \\\\\n\\end{array} \n\\right. \\]\n\n    \\item{Problem 2 (1) Find hanoi(26)}\n    \\[ hanoi(x)  \\left\\{\n\\begin{array}{ll}\n      1 & if x = 1 \\\\\n      2 * hanoi(n-1) + 1 & if x > 1 \\\\\n      \n\\end{array} \n\\right. \\]\n\\end{enumerate}\n\\section{Program Simulation}\n\\begin{enumerate}\n    \\item {Problem 1 (1) Find C[4]}\n    \\begin{description}\n    \\item A(0) = 12: A(1) = 41: A(2) = 52\n\\item A(3) = 57: A(4) = 77: A(5) = -100\n\\item B(0) = 17: B(1) = 34: B(20 = 81\n\\item J = 0: K = 0: N = 0\n\\item while A(J) $\\textgreater$ 0\n\\item while B(K) $\\leq$ A(J)\n\\item C(N) = B(K)\n\\item N = N + 1\n\\item k = k + 1\n\\item end while\n\\item C(N) = A(J): N = N + 1: J = J + 1\n\\item end while\nC(N) = B(K)\n    \\end{description}\n    \\item{Problem 2 (1) Find the final value of NUM}\n    \\begin{description}\n    \\item A = “BANANAS”\n    \\item NUM = 0: T = “”\n    \\item for J = len(A) - 1 to 0 step –1\n    \\item T = T + A[j]\n    \\item next \n    \\item for J = 0 to len(A) - 1\n    \\item if A[J] == T[J] then NUM = NUM + 1\n \\item next\n    \\end{description}\n\\end{enumerate}\n\n\n\n\n\\section{Prefix/Postfix/Infix (Satan  Math)}\n\\begin{enumerate}\n    \\item{Problem 1 (1) Evaluate}\n    \n    Define  @ a b c $= Max(a,b) / Min(b,c)$\n    \n    Define $!\\:a = a!$\n    $$@\\:(@\\:4\\:19\\:3)\\:(\\wedge\\:+\\:*\\:3\\:4\\:/\\:8\\:2\\:–\\:7\\:5)\\:(!\\:@\\:7\\:9\\:12)$$\n    \\bigskip\n    \n     \\item{Problem 2 (1) Convert to Prefix and Infix}\n    $$\\frac{a * b^2}{c+1} - \\frac{a + b}{a^2 * b}$$\n    \\bigskip\n\n\\end{enumerate}\n\n\\section{Bit String Flicking}\n\\begin{enumerate}\n    \\item{Problem 1 (3) What combination of operations does X represent?}\n    \n    1111110111000 XNOR (111010111111 NOR (0001010001001 XOR NOT LCIRC-4 ((RSHIFT-3 1111111111111) OR 00000000000000)))\n    = X(1110111011111)\n\\end{enumerate}\n\\section{LISP}\n\\begin{enumerate}\n    \\item{Problem 1 (1) Solve:}\n    Given the function definitions for HY and FY as follows:\n    \n    (DEF HY(PARMS)(REVERSE(CDR PARMS)))\n    \n    (DEF FY(PARMS)(CAR(HY(CDR PARMS))))\n    \n    What is the value of the following?\n    \n    (FY'(DO RE(MI FA)SO))\n    \\item{Problem 2 (1)}\n    Evaluate the following expression:\n    \n    (EXP ( MULT 2(SUB 5(DIV(ADD 5 3 4) 2 )) 3) 3)\n\\end{enumerate}\n\\section{Boolean Algebra}\n\\begin{enumerate}\n    \\item{Problem 1 (3)} \n    Prove:\n    $$\\overline{x} + \\overline{y} + xy\\overline{z} = \\overline{x} + \\overline{y} + \\overline{z}$$\n    \\bigskip\n    \\bigskip\n    \n    \\item{Problem 2 (2)}\n    Simplify: \n    $$(p + q)(\\overline{pq})$$\n    \\bigskip\n    \n    \\item{Problem 3 (1)}Assume a 50/50 probability for the value of each variable. What is the probability that x = 0?:\n    $$X = (A+B)(A+\\overline{C})(A+D)(A+\\overline{E})(A+F)(A+\\overline{G})....$$\n   \n    \n    \\bigskip\n    \\bigskip\n    \\bigskip\n    \n    \n\\end{enumerate}\n\\section{Data Structures}\n\\begin{enumerate}\n    \\item{Problem 1 (2)} Put the following phrase into a Min-Heap, What are the letters that fill the bottom row and of what frequency?\n    \n    wecanonlyseeashortdistanceaheadbutwecanseeplentytherethatneedstobedonebyalanturing\n    \n    \\bigskip\n    \\item{Problem 2 (2)} What would be its external path and internal path length?\n    \\bigskip\n    \\item{Problem 3 (2)} What search algorithms are derived from a stack and a queue, and what are they used for and why within each algorithm?\n    \\bigskip\n    \n    \n\\end{enumerate}\n\n\n\\section{FSA/Regular Expressions}\n\\begin{enumerate}\n    \\item{Problem 1 (2) Simplify the following regex expression(no plus symbol)}\n    \n    $$a*(ba*)* (d*c*)* (e* U f)*(gh)*g(ij U ik)$$\n    \n    \\item{Problem 2 (1) Does the following string comply with the regex above?}\n    \n    $$aabadccddceeeffggghghij$$\n\n\\end{enumerate}\n\\section{Graph Theory}\n\\begin{enumerate}\n    \\item {Problem 1 (1) Multiply the following matrices}\n    $$\n    \\begin{bmatrix} \n    -1 & 2 \\\\\n    5 & 4 \\\\\n    -4 & -3 \\\\\n    -1 & 0\n    \\end{bmatrix}\n    \\begin{bmatrix} \n    7 & 8 & 9 \\\\\n    4 & -3 & 2 \n    \\end{bmatrix}\n    $$\n    \\item {Problem 2 (1) Multiply the following matrices}\n     $$\n    \\begin{bmatrix} \n    1 & 0 & 1 & 0 & 0 & 0 \\\\\n    0 & 1 & 1 & 1 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 1\\\\\n    1 & 0 & 1 & 0 & 0 & 0 \\\\ \n    1 & 0 & 1 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 1\n    \\end{bmatrix}\n    \\begin{bmatrix} \n    1 & 0 & 1 & 0 & 0 & 0 \\\\\n    0 & 1 & 1 & 1 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 1\\\\\n    1 & 0 & 1 & 0 & 0 & 0 \\\\ \n    1 & 0 & 1 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 1\n    \\end{bmatrix}\n    $$\n\\end{enumerate}\n\n\\section{Digital Electronics}\n\\begin{enumerate}\n    \\item {Problem 1 (2)}\n    \n    \\includegraphics[scale=.75]{DigitalElectronicsACSL}\n\\end{enumerate}\n\\section{Assembly Language}\n\\begin{enumerate}\n    \\item {Problem 1 (2) Write the following Assembly code as a piece wise function as find what is printed at the end(Ignore the messed up indentation)}\n\n\\begin{description}\n\\item X\\quad\\quad\\enspace DC \\quad\\quad\\quad\\enspace 3\n\\item Y\\quad\\quad\\enspace DC \\quad\\quad\\quad\\enspace 5\n\\item Check LOAD \\quad\\quad\\enspace X\n\\item \\quad\\quad\\quad BE \\quad\\quad\\quad\\enspace Yellow\n\\item  \\quad\\quad\\quad LOAD\\quad\\quad\\enspace Y\n\\item \\quad\\quad\\quad BE \\quad\\quad\\quad\\enspace Red\n\\item \\quad\\quad\\quad BU \\quad\\quad\\quad\\enspace Blue\n\\item Blue \\space\\space LOAD \\quad\\quad\\enspace X\n\\item \\quad\\quad\\quad ADD \\quad\\quad\\enspace\\enspace 1\n\\item \\quad\\quad\\quad STORE \\quad\\enspace X\n\\item \\quad\\quad\\quad LOAD\\quad\\quad\\enspace Y\n\\item \\quad\\quad\\quad SUB \\quad\\quad\\enspace\\enspace 1\n\\item \\quad\\quad\\quad STORE \\quad\\enspace Y\n\\item Red \\space\\space LOAD\\quad\\quad\\enspace X\n\\item \\quad\\quad\\quad  SUB \\quad\\quad\\enspace\\enspace 1\n\\item \\quad\\quad\\quad STORE \\quad\\enspace X\n\\item Yellow LOAD\\quad\\quad\\enspace X\n\\item \\quad\\quad\\quad  ADD  \\quad\\quad\\enspace\\enspace 1\n\\item \\quad\\quad\\quad STORE \\quad\\enspace X\n\\item \\quad\\quad\\quad PRINT \\quad\\enspace X\n\\end{description}\n    \\item{Problem 2 (1) Define LOC, OPCODE, LABEL, and ACC and place them in order of a command}\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "391efac27900a00c0063495c7e82ddbc1e5e7537", "size": 6898, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ACSL_FinalTest.tex", "max_stars_repo_name": "sanjit-bhat/AB-ACSL", "max_stars_repo_head_hexsha": "ab9bf7e5526cc5863c0173ab518138dada2dc1ef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-12T03:01:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T03:01:29.000Z", "max_issues_repo_path": "ACSL_FinalTest.tex", "max_issues_repo_name": "sanjit-bhat/AB-ACSL", "max_issues_repo_head_hexsha": "ab9bf7e5526cc5863c0173ab518138dada2dc1ef", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ACSL_FinalTest.tex", "max_forks_repo_name": "sanjit-bhat/AB-ACSL", "max_forks_repo_head_hexsha": "ab9bf7e5526cc5863c0173ab518138dada2dc1ef", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0406504065, "max_line_length": 215, "alphanum_fraction": 0.6127863149, "num_tokens": 2591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859265, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6959320690100073}}
{"text": "\\section{Elements of Numerical Integration}\n\\begin{align*}\n    \\int_a^bf(x)\\D x &= \\int_a^b\\sum_{i=0}^nf(x_i)L_i(x)\\D x + \\int_a^b\\prod_{i=0}^n(x-x_i)\\frac{f^{(n+1)}(\\xi(x))}{(n+1)!}\\D x \\\\\n    &= \\int_a^ba_if(x_i)\\D x + \\frac{1}{(n+1)!}\\int_a^b\\prod_{i=0}^n(x-x_i)f^{(n+1)}(\\xi(x)\\D x,\n\\end{align*}\nwhere $a_i=\\int_a^bL_i(x)\\D x$ for each $i=0,1,\\ldots,n$.\n\n\\subsection{The Trapezoidal Rule}\nTo derive the Trapezoidal rule for approximating $\\int_a^bf(x)\\D x$, let $x_0=a$, $x_1=b$, $h=b-a$.\n\\begin{align*}\n    \\int_a^bf(x)\\D x &= \\int_a^b\\left[\\frac{(x-x_0)}{(x_1-x_0)f(x_1)}+\\frac{(x-x_1)}{(x_0-x_1)f(x_0)}\\right]\\D x + \\frac{1}{2}\\int_a^b(x-x_0)(x-x_1)f''(\\xi(x))\\D x \\\\\n    &= \\int_{x_0}^{x_1}\\frac{(x-x_0)f(x_1)-(x-x_1)f(x_0)}{x_1-x_0}\\D x + \\frac{f''(\\xi)}{2}\\left[\\frac{x^3}{3}-\\frac{(x_0+x_1)}{2}x^2+x_0x_1x\\right]_{x_0}^{x_1} \\\\\n    &= \\left[\\frac{(x-x_0)^2f(x_1)-(x-x_1)^2f(x_0)}{2(x_0-x_1)}\\right]_{x_0}^{x_1} - \\frac{h^3}{12}f''(\\xi) \\\\\n    &= \\frac{h}{2}\\left[f(x_0)+f(x_1)\\right]-\\frac{h^3}{12}f''(\\xi).\n\\end{align*}\n\n\\subsection{Simpson's Rule}\n\\begin{align*}\n    \\int_{x_0}^{x_2}f(x)\\D x &= \\left[f(x_1)(x-x_1)+\\frac{f'(x_1)}{2}(x-x_1)^2+\\frac{f''(x_1)}{6}(x-x_1)^3+\\frac{f^{(3)}(x_1)}{24}(x-x_1)^4\\right]_{x_0}^{x_2} \\\\\n    &\\phantom{=} + \\frac{1}{24}\\int_{x_0}^{x_2}f^{(4)}(\\xi(x))(x-x_1)^4\\D x \\\\\n    &= 2hf(x_1) + \\frac{h^3}{3}f''(x_1) + \\frac{f^{(4)}(\\xi_1)}{60}h^5 \\\\\n    &= 2hf(x_1)+\\frac{h^3}{3}\\left\\{\\frac{1}{h^2}\\left[f(x_0)-2f(x_1)+f(x_2)\\right]-\\frac{h^2}{12}f^{(4)}(\\xi_2)\\right\\} + \\frac{f^{(4)}(\\xi_1)}{60}h^5 \\\\\n    &= \\frac{h}{3}\\left[f(x_0)+4f(x_1)+f(x_2)\\right]-\\frac{h^5}{12}\\left[\\frac{1}{3}f^{(4)}(\\xi_2)-\\frac{1}{5}f^{(4)}(\\xi_1)\\right] \\\\\n    &= \\frac{h}{3}\\left[f(x_0)+4f(x_1)+f(x_2)\\right]-\\frac{h^5}{90}f^{(4)}(\\xi)\n\\end{align*}\n\n\\subsection{Measuring Precision}\n\\begin{defn}[The degree of accuracy or precision]\\hfill\\\\\nThe largest positive integer $n$ such that the formula is exact for $x^k$ for $k=0,1,\\ldots,n$.\n\\end{defn}\n\n\\subsection{New-tom-Cotes Formulas}\nThe Trapezoidal and Simpson's rules are examples of a class of methods known as Newton-Cotes formulas. There are two types of Newton-Cotes formulas, open and closed.\n\n\\subsubsection{Closed Newton-Cotes Formulas}\nThe $(n+1)$-point closed Newton-Cotes uses nodes $x_i=x_0+ih$, for $i=0,1,\\ldots,n$, where $x_0=a$, $x_n=b$ and $h=(b-a)/n$.\n\\begin{theo}\nIf $n$ is even and $f\\in C^{n+2}[a,b]$\n\\[\n\\int_a^bf(x)\\D x=\\sum_{i=0}^na_if(x_i)+\\frac{h^{n+3}f^{(n+2)}(\\xi)}{(n+2)!}\\int_0^nt^2(t-1)\\ldots(t-n)\\D t.\n\\]\nIf $n$ is odd and $f\\in C^{n+1}[a,b]$\n\\[\n\\int_a^bf(x)\\D x=\\sum_{i=0}^na_if(x_i)+\\frac{h^{n+2}f^{(n+1)}(\\xi)}{(n+1)!}\\int_0^nt(t-1)\\ldots(t-n)\\D t.\n\\]\n\n$\\xi\\in(a,b)$.\n\\end{theo}\n\n\\begin{enumerate}[n=1]\n    \\item Trapezoidal rule\n        \\begin{align*}\n        \\int_{x_0}^{x_1}f(x)\\D x=\\frac{h}{2}\\left[f(x_0)+f(x_1)\\right]-\\frac{h^3}{12}f''(\\xi)\n        \\end{align*}\n    \\item Simpson's rule\n        \\begin{align*}\n        \\int_{x_0}^{x_2}f(x)\\D x=\\frac{h}{3}\\left[f(x_0)+4f(x_1)+f(x_2)\\right]-\\frac{h^5}{90}f^{(4)}(\\xi)\n        \\end{align*}\n    \\item Simpson's Three-Eighths rule\n        \\begin{align*}\n        \\int_{x_0}^{x_3}f(x)\\D x=\\frac{3h}{8}\\left[f(x_0)+3f(x_1)+3f(x_2)+f(x_3)\\right]-\\frac{3h^5}{80}f^{(4)}(\\xi)\n        \\end{align*}\n    \\item \\phantom{Unknown Name}\n        \\begin{align*}\n        \\int_{x_0}^{x_4}f(x)\\D x=\\frac{2h}{45}\\left[7f(x_0)+32f(x_1)+12f(x_2)+32f(x_3)+7f(x_4)\\right]-\\frac{8h^7}{945}f^{(6)}(\\xi)\n        \\end{align*}\n\\end{enumerate}\n\n\n\n\\subsubsection{Open Newton-Cotes Formulas}\nThe open Newton-Cotes formulas do not include the endpoints of $[a,b]$ as nodes. They use the nodes $x_i=x_0+ih$, for $i=0,1,\\ldots,n$, where $h=(b-a)/(n+2)$ and $x_0=a+h$, $x_n=b-h$.\n\\begin{theo}\nIf $n$ is even and $f\\in C^{n+2}[a,b]$\n\\[\n\\int_a^bf(x)\\D x=\\sum_{i=0}^na_if(x_i)+\\frac{h^{n+3}f^{(n+2)}(\\xi)}{(n+2)!}\\int_{-1}^{n+1}t^2(t-1)\\ldots(t-n)\\D t.\n\\]\nIf $n$ is odd and $f\\in C^{n+1}[a,b]$\n\\[\n\\int_a^bf(x)\\D x=\\sum_{i=0}^na_if(x_i)+\\frac{h^{n+2}f^{(n+1)}(\\xi)}{(n+1)!}\\int_{-1}^{n+1}t(t-1)\\ldots(t-n)\\D t.\n\\]\n\n$\\xi\\in(a,b)$.\n\\end{theo}\n\n\\begin{enumerate}[n=1]\\addtocounter{enumi}{-1}\n    \\item Midpoint rule\n        \\begin{align*}\n        \\int_{x_{-1}}^{x_1}f(x)\\D x=2hf(x_0)+\\frac{h^3}{3}f''(\\xi)\n        \\end{align*}\n    \\item \\phantom{Unknown Name}\n        \\begin{align*}\n        \\int_{x_{-1}}^{x_2}f(x)\\D x=\\frac{3h}{2}\\left[f(x_0)+f(x_1)\\right]-\\frac{3h^3}{4}f''(\\xi)\n        \\end{align*}\n    \\item \\phantom{Unknown Name}\n        \\begin{align*}\n        \\int_{x_{-1}}^{x_3}f(x)\\D x=\\frac{4h}{3}\\left[2f(x_0)-f(x_1)+2f(x_2)\\right]+\\frac{14h^5}{45}f^{(4)}(\\xi)\n        \\end{align*}\n    \\item \\phantom{Unknown Name}\n        \\begin{align*}\n        \\int_{x_{-1}}^{x_4}f(x)\\D x=\\frac{5h}{24}\\left[11f(x_0)+f(x_1)+f(x_2)+11f(x_3)\\right]+\\frac{95h^7}{144}f^{(4)}(\\xi)\n        \\end{align*}\n\\end{enumerate}\n", "meta": {"hexsha": "d8553ec1009bdf829f6807f5e198933545a5ea10", "size": 4829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/4.3_Elements_of_numerical_integration.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/4.3_Elements_of_numerical_integration.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "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/sections/4.3_Elements_of_numerical_integration.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["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.4326923077, "max_line_length": 183, "alphanum_fraction": 0.5620211224, "num_tokens": 2351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6959320633647066}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Basic Arithmetic Operations}\nThe simplest math operations in Jac.\n\\begin{description}\n    \\item[Code] \\texttt{}\n          \\begin{lstlisting}[caption={Basic arithmetic operations}]\nwalker init {\n    a = 4 + 4;\n    b = 4 * -5;\n    c = 4 / 4;  # Evaluates to a floating point number\n    d = 4 - 6;\n    e = a + b + c + d;\n    std.out(a, b, c, d, e);\n}\n    \\end{lstlisting}\n    \\item[Output] \\texttt{ }\n          \\begin{lstlisting}[language=shell]\n8 -20 1.0 -2 -13.0\n        \\end{lstlisting}\n    \\item[Description] \\texttt{}\n\\end{description}\n\n\\noindent Additionally, Jac supports power and modulo operations.\n\\begin{description}\n    \\begin{lstlisting}[caption={Additional arithmetic operations}]\nwalker init {\n    a = 4 ^ 4; b = 9 % 5; std.out(a, b);\n}\n    \\end{lstlisting}\n    \\item[Output] \\texttt{ }\n          \\begin{lstlisting}[language=shell]\n256 4\n        \\end{lstlisting}\n    \\item[Description] \\texttt{}\n\\end{description}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Comparison Operations}\n\\begin{description}\n    \\begin{lstlisting}[caption={Comparision operations}]\nwalker init {\n    a = 5; b = 6;\n    std.out(a == b,\n            a != b,\n            a < b,\n            a > b,\n            a <= b,\n            a >= b,\n            a == b-1);\n}\n    \\end{lstlisting}\n    \\item[Output] \\texttt{ }\n          \\begin{lstlisting}[language=shell]\nfalse true true false true false true\n        \\end{lstlisting}\n    \\item[Description] \\texttt{}\n\\end{description}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Logical Operations}\n\\begin{description}\n    \\begin{lstlisting}[caption={Logical operations}]\nwalker init {\n    a = true; b = false;\n    std.out(a,\n            !a,\n            a && b,\n            a || b,\n            a and b,\n            a or b,\n            !a or b,\n            !(a and b));\n}\n    \\end{lstlisting}\n    \\item[Output] \\texttt{ }\n          \\begin{lstlisting}[language=shell]\ntrue false false true false true false true\n        \\end{lstlisting}\n    \\item[Description] \\texttt{}\n\\end{description}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Assignment Operations}\n\\begin{description}\n    \\begin{lstlisting}[caption={Assignment operations}]\nwalker init {\n    a = 4 + 4; std.out(a);\n    a += 4 + 4; std.out(a);\n    a -= 4 * -5; std.out(a);\n    a *= 4 / 4; std.out(a);\n    a /= 4 - 6; std.out(a);\n\n    # a := here; std.out(a);\n    # Noting existence of copy assign, described later\n}\n    \\end{lstlisting}\n    \\item[Output] \\texttt{ }\n          \\begin{lstlisting}[language=shell]\n8\n16\n36\n36.0\n-18.0\n        \\end{lstlisting}\n    \\item[Description] \\texttt{}\n\\end{description}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Foreshadowing Unique Graph Operations}\n\\begin{description}\n    \\begin{lstlisting}[caption={Preview of graph operators},\n        label={code:moremath}]\nedge back;\n\nwalker init {\n    node_a = spawn node;\n    here --> node_a;\n    here <-[back]- node_a;\n\n    node_b = spawn here <-> node;\n    node_b --> node_a\n}\n    \\end{lstlisting}\n    \\item[Output] \\texttt{ }\n    \\item[Description] \\texttt{}\n\n          \\begin{tikzpicture}[node distance = {1.0cm and 1.5cm}, v/.style = {draw, circle}]\n              \\graph[nodes={circle, draw}, grow right=2.25cm, branch down=1.75cm]{\n              H -> A,\n              A -> [\"back\"] H,\n              H -- B,\n              B -> A,\n              };\n          \\end{tikzpicture}\n\\end{description}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Precedence}\n\n\\begin{table}[h]\n    \\small\n    \\centering\n    \\begin{tabular}{l l l}\n        \\toprule\n        \\textbf{Rank} & \\textbf{Symbol}          & \\textbf{Description}                           \\\\\n        \\midrule\n        1             & () [] . :: --> <-- spawn & Parenthetical/grouping, node/edge manipulation \\\\\n        2             & \\textasciicircum         & Exponent                                       \\\\\n        3             & * / \\%                   & Multiplication, division, modulo               \\\\\n        4             & + -                      & Addition, subtraction                          \\\\\n        5             & == != >= <= > <          & Comparison                                     \\\\\n        6             & \\&\\& || and or           & Logical                                        \\\\\n        7             & = += -= *= /= :=         & Assignment                                     \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\caption{Precedence of operations in Jac}\n    \\label{tab:jacprecedence} % Unique label used for referencing the table in-text\n    %\\addcontentsline{toc}{table}{Table \\ref{tab:jacprecedence}} % Uncomment to add the table to the table of contents\n\\end{table}", "meta": {"hexsha": "3c4cafbdd4656c3e0d33b6261cee3bfff51ac215", "size": 4672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archive/old_book/tex/sec/sec-jacnumbers.tex", "max_stars_repo_name": "Gim3l/jaseci", "max_stars_repo_head_hexsha": "cca187ed3e6aae31514c6c0353a7844f7703d039", "max_stars_repo_licenses": ["MIT"], "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/old_book/tex/sec/sec-jacnumbers.tex", "max_issues_repo_name": "Gim3l/jaseci", "max_issues_repo_head_hexsha": "cca187ed3e6aae31514c6c0353a7844f7703d039", "max_issues_repo_licenses": ["MIT"], "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/old_book/tex/sec/sec-jacnumbers.tex", "max_forks_repo_name": "Gim3l/jaseci", "max_forks_repo_head_hexsha": "cca187ed3e6aae31514c6c0353a7844f7703d039", "max_forks_repo_licenses": ["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.487804878, "max_line_length": 118, "alphanum_fraction": 0.4963613014, "num_tokens": 1261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6959200152795546}}
{"text": "\\subsection{Matrices}\r\n\\noindent\r\nMatrices are an array of mathematical objects, most often numbers.\r\nThey are often used to represent linear transformations between two spaces and systems of linear equations.\r\nWe denote the size of a matrix by saying the number of rows followed by the number of columns.\r\n\r\n\\begin{example}\r\n\tBelow is a 2 x 4 matrix.\r\n\t\\begin{equation*}\r\n\t\t\\begin{bmatrix}\r\n\t\t\t1 & 3 & 2 & -1 \\\\\r\n\t\t\t-5 & 7 & 3 & 0 \\\\\r\n\t\t\\end{bmatrix}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\r\n% Types of matrices\r\n\\input{../common/vectorsMatrices/typesOfMatrices.tex}\r\n% Row Reduction\r\n\\input{../common/vectorsMatrices/rowReduction.tex}\r\n% Determinants\r\n\\input{../common/vectorsMatrices/determinants.tex}\r\n% Eigenvalues/vectors\r\n\\input{../common/vectorsMatrices/eigenvaluesEigenvectors.tex}", "meta": {"hexsha": "3157003a2b60f2cf3530b7f9850d4d11b38b737d", "size": 785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/vectorsMatrices/matrices.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/vectorsMatrices/matrices.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/vectorsMatrices/matrices.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": 32.7083333333, "max_line_length": 108, "alphanum_fraction": 0.7324840764, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6959200050205705}}
{"text": "\\section{Procedures}\n\n\\begin{itemize}\n\t\n\t\\item A procedure is a named block of code used for structure and to enable reuse\n\t\n\t\\item Given $ \\Procedure ~ R() \\defeq S $ and $ w : [P, Q] \\refsto S $, we have that $ w : [P, Q] \\refsto R $\n\t\n\t\\item The \\textit{formal} parameter is used in the function and the \\textit{actual} parameter is what's passed in\n\t\n\t\\item Parameter types\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ \\Value $\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item Sets the formal parameter to the value of a variable or expression when the procedure runs\n\t\t\t\n\t\t\t\\item Modifying the formal parameter in the procedure doesn't affect the actual parameter\n\t\t\t\n\t\t\t\\item Given $ \\Procedure ~ R(\\Value ~ z) \\defeq S $  and $ w, z : [P, Q] \\refsto S$:\\\\\n\t\t\t$ ~~~~ w : [P[z \\backslash a], Q[z_0 \\backslash a_0]] \\refsto R(a) $ where $ a_0 = a[w \\backslash w_0] $\n\t\t\t\n\t\t\t\\item The postcondition $ Q $ should not contain $ z $ since it is local to $ R $\n\t\t\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t\\item $ \\Result $\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item The actual parameter takes the value of the formal parameter when the procedure terminates\n\t\t\t\n\t\t\t\\item The actual parameter must be a variable, not an expression and its initial value is not defined\n\t\t\t\n\t\t\t\\item Given $ \\Procedure ~ R(\\Result z) \\defeq S $ and $ w, z : \\refsto S $:\\\\\n\t\t\t$ ~~~~ w : [P, Q[z \\backslash a]] \\refsto R(a) $\n\t\t\t\n\t\t\t\\item The precondition $ P $ should not contain $ z $, and the postcondition $ Q $ should not contain $ z_0 $\n\t\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t\\item $ \\ValueResult $\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item The formal parameter takes the value of the actual parameter when the procedure starts\n\t\t\t\n\t\t\t\\item The actual parameter takes the value of the formal parameter when the procedure terminates\n\t\t\t\n\t\t\t\\item Given $ \\Procedure ~ R(\\ValueResult ~ z) \\defeq S $ and $ w, z : [P, Q] \\refsto S $:\\\\\n\t\t\t$ ~~~~ w, a : [P[z \\backslash a], Q[z_0, z \\backslash a_0, a]] \\refsto R(a) $\n\t\t\t\n\t\t\t\\item There are no constraints on how $ z $ and $ z_0 $ may appear in $ P $ and $ Q $\n\t\t\t\n\t\t\\end{itemize}\n\t\n\t\t\\item A procedure may have multiple parameters of different types\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item e.g. $ \\Procedure ~ R(\\Result ~ x, y; \\Value ~ z) \\defeq x, y := 0, z + 1 $\n\t\t\t\n\t\t\\end{itemize}\n\t\t\n\t\\end{itemize}\n\n\t\\item Introducing procedures and procedure calls when refining\n\t\n\t\\begin{enumerate}\n\t\t\n\t\t\\item Identify a suitable specification $ x, y, z : [P, Q] $ and choose a name $ R $\n\t\t\n\t\t\\item Identify parameters and their types\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item Variables in $ P $ only are likely $ \\Value $ parameters\n\t\t\t\n\t\t\t\\item Variables in $ Q $ only are likely $ \\Result $ parameters\n\t\t\t\n\t\t\t\\item Variables in both are likely $ \\ValueResult $ parameters\n\t\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t$ \\Procedure ~ R(\\Value ~ x; \\Result ~ y; \\ValueResult ~ z) \\defeq x, y, z : [P, Q] $\n\t\t\n\t\t\\item If the formal parameter appears only in the precondition, use a $ \\Value $ parameter\n\t\t\n\t\t\\item Refine the body of $ R $ to code\n\t\t\n\t\t\\item Refine the main program with variables $ a, b, c $ to the specification:\\\\\n\t\t$ ~~~~ b, c : [P[x, z \\backslash a, c], Q[x_0, y, z_0, z \\backslash a_0, b, c_0, c]]$\n\t\t\n\t\t\\item Replace the above specification with $ R(a, b, c) $\n\t\t\n\t\\end{enumerate}\n\t\n\\end{itemize}\n\n\\newpage\n\n\\subsection{Recursion}\n\n\\begin{itemize}\n\t\n\t\\item Procedures may be called recursively (i.e. from within themselves), as per any procedure call\n\t\n\t\\item Need to use a variant $ V $ to ensure the recursion reaches a base case\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item The variant may refer to variables including parameters (aside from $ \\Result $ parameters)\n\t\t\n\t\t\\item Given procedure $ R $ with specification $ w : [P, Q] $, let $ V = N $ when the procedure is first called\n\t\t\n\t\t\\item Then to refine to a call outside the function, $ R $ has specification $ w : [P \\land (V = N), Q] $\n\t\t\n\t\t\\item To refine to a recursive call within $ R $, we require the specification $ w : [P \\land (0 \\le V < N), Q] $\n\t\t\n\t\\end{itemize}\n\t\n\\end{itemize}\n\n$ ~ $\n\nExample: $ \\Procedure ~ Factorial(\\Value ~ n, \\Result ~ f) \\defeq n : f [n \\ge 0, f = n_0!] $.\n\nLet $ n $ be the variant and introduce $ n = N $ into the precondition (for the initial call).\\\\\n\\form{n, f : [n \\ge 0 \\land n = N, f = n_0!]}\n\\hint{\\refsto}{Selection: $ n \\ge 0 \\land n = N \\entails n = 0 \\lor n > 0 $}\n\\gcl{0}{\\If ~ n = 0 \\rightarrow n, f : [n \\ge 0 \\land n = 0 \\land n = N, f = n_0!]}\n\\gcl{0}{\\Choice ~ n > 0 \\rightarrow n, f : [n \\ge 0 \\land n > 0 \\land n = N, f = n_0!]}\n\\gcl{0}{\\Fi}\n\\hint{\\refsto}{Assignment: $ n \\ge 0 \\land n = 0 \\land n = N \\entails (f = n_0!)[f \\backslash 1] $}\n\\gcl{0}{\\If ~ n = 0 \\rightarrow f := 1}\n\\gcl{0}{\\Choice ~ n > 0 \\rightarrow n, f : [n \\ge 0 \\land n > 0 \\land n = N, f = n_0!]}\n\\gcl{0}{\\Fi}\n\nThe remaining specification $ n, f : [n \\ge 0 \\land n > 0 \\land n = N, f = n_0!] $ is refined as follows:\n\\form{n, f : [n \\ge 0 \\land n > 0 \\land n = N, f = n_0!]}\n\\hint{\\refsto}{Contract frame: $ n $}\n\\form{f : [n \\ge 0 \\land n > 0 \\land n = N, f = n!]}\n\\hint{\\refsto}{Following assignment: $ f := f \\times n $}\n\\gcl{0}{f : [n \\ge 0 \\land n > 0 \\land n = N, (f = n!)[f \\backslash f \\times n]]; f := f \\times n}\n\nThe remaining specification $ f : [n \\ge 0 \\land n > 0 \\land n = N, (f \\times n) = n!] $ is refined into a recursive call:\\\\\n\\form{f : [n \\ge 0 \\land n > 0 \\land n = N, (f \\times n) = n!]}\n\\hint{\\refsto}{Apply substitution}\n\\form{f : [n \\ge 0 \\land n > 0 \\land n = N, (f \\times n) = n!]}\n\\hint{\\refsto}{Divide both sides of $ f \\times n = n! $ by $ n $}\n\\form{f : [n \\ge 0 \\land n > 0 \\land n = N, f = (n - 1)!]}\n\\hint{\\refsto}{Weaken precondition: $ n \\ge 0 \\land n > 0 \\land n = N \\entails n - 1 \\ge 0 \\land (0 \\le n - 1 < N) $}\n\\form{f : [n - 1 \\ge 0 \\land (0 \\le n - 1 < N), f = (n - 1)!]}\n\\hint{\\refsto}{Apply substitution backwards}\n\\form{f : [(n \\ge 0 \\land (0 \\le n < N))[n \\backslash n - 1], (f = n!)[n_0, f \\backslash n_0 - 1, f]]}\n\\hint{\\refsto}{Introduce recursive call with $ \\Value $ parameter $ n $ and $ \\Result $ parameter $ f $}\n\\form{Factorial(n - 1, f)}\n\nThis produces the final program:\\\\\n\\gcl{0}{\\If ~ n = 0 \\rightarrow f := 1}\n\\gcl{0}{\\Choice ~ n > 0 \\rightarrow Factorial(n - 1, f); f := f \\times n}\n\\gcl{0}{\\Fi}", "meta": {"hexsha": "6f581dcbba207129612ea778d308b9dd6a85fbea", "size": 6167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSSE3100/procedures.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/procedures.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/procedures.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": 37.3757575758, "max_line_length": 124, "alphanum_fraction": 0.605967245, "num_tokens": 2193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.6957593891915217}}
{"text": "\\section{A Real Time Spectrum Analyser Using Least Mean Square}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n\n%% a)\n\\item\n%\n\nLet the $L_{2}$-norm of the prediction error being the objective function $\\mathcal{J}$:\n\n\\begin{equation}\n    \\mathcal{J}(\\vw) = \\| \\vy - \\hat{\\vy} \\|^{2} = \\| \\vy - \\mathbf{F} \\vw \\|^{2} = (\\vy - \\mathbf{F} \\vw)^{H} (\\vy - \\mathbf{F} \\vw)\n\\label{eq:J_OLS}\n\\end{equation}\n\nIn order to minimise the objective function $\\mathcal{J}$ with respect to the parameters (weights) $\\vw$, the first order condition is:\n\n\\begin{equation}\n    \\frac{\\partial \\mathcal{J}(\\vw)}{\\partial \\vw} \\bigg\\vert_{\\vw=\\vw_{*}}  = 0\n\\end{equation}\n\nSubstituting from (\\ref{eq:J_OLS}):\n\n\\begin{align}\n    \\frac{\\partial}{\\partial \\vw} \\bigg( \\vy^{H} \\vy - \\vy^{H} \\mathbf{F} \\vw - \\vw^{H} \\mathbf{F}^{H} \\vy + \\vw^{H} \\mathbf{F}^{H} \\mathbf{F} \\vw \\bigg) \\bigg\\vert_{\\vw=\\vw_{*}}  &= 0 \\\\\n    0 - \\mathbf{F}^{H} \\vy - \\mathbf{F}^{H} \\vy + 2 \\mathbf{F}^{H} \\mathbf{F} \\vw_{*} &= 0\n\\end{align}\n\nAssuming that $\\mathbf{F}^{H} \\mathbf{F}$ is invertible (\\textbf{semi}-positive as covariance matrix), we solve for $\\vw_{*}$, concluding the proof:\n\n\\begin{equation}\n    \\vw_{*} = \\bigg( \\mathbf{F}^{H} \\mathbf{F} \\bigg)^{-1} \\mathbf{F}^{H} \\vy\n\\label{proof:OLS}\n\\end{equation}\n\nThe Inverse Discrete Fourier Transform (IDFT) of a signal $x(n)$ is given by:\n\n\\begin{align}\n    \\hat{x}(n)  &= \\frac{1}{\\sqrt{N}} \\sum_{k=0}^{N-1} X(k) e^{j \\frac{2\\pi}{N} n k}\n                 = \\frac{1}{\\sqrt{N}} \\sum_{k=0}^{N-1} X(k) F_{N}^{nk}\n\\end{align}\n\nwhere $F_{N} = e^{j \\frac{2\\pi}{N}}$. If we define:\n\n\\begin{equation}\n    \\renewcommand\\arraystretch{1.5}\n    \\vf_{n}^{H} = \\frac{1}{\\sqrt{N}}\n    \\begin{bmatrix}\n        1, & F_{N}^{n}, & F_{N}^{2n}, & \\ldots, & F_{N}^{n(N-1)}\n    \\end{bmatrix}\n\\end{equation}\n\nArranging the sample estimates in a vector, we obtain:\n\n\\begin{equation}\n    \\renewcommand\\arraystretch{1.5}\n    \\hat{\\vx} =\n    \\begin{bmatrix}\n        \\hat{x}(0) \\\\ \\hat{x}(1) \\\\ \\vdots \\\\ \\hat{x}(N-1)\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        \\vf_{0}^{H} \\mathbf{X} \\\\ \\vf_{1}^{H} \\mathbf{X} \\\\ \\vdots \\\\ \\vf_{N-1}^{H} \\mathbf{X}\n    \\end{bmatrix}\n    =\n    \\mathbf{F} \\mathbf{X}\n\\label{eq:DFT_OLS}\n\\end{equation}\n\nwhere:\n\n\\begin{equation}\n    \\renewcommand\\arraystretch{1.5}\n    \\mathbf{F} =\n    \\begin{bmatrix}\n        \\vf_{0}^{H} \\\\ \\vf_{1}^{H} \\\\ \\vdots \\\\ \\vf_{N-1}^{H}\n    \\end{bmatrix}\n    = \\frac{1}{\\sqrt{N}}\n    \\begin{bmatrix}\n        1 & 1 & 1 & \\cdots & 1 \\\\\n        1 & F_{N} & F_{N}^{2} & \\cdots & F_{N}^{N-1} \\\\\n        \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n        1 & F_{N}^{N-1} & F_{N}^{2(N-1)} & \\cdots & F_{N}^{(N-1)^{2}} \\\\\n    \\end{bmatrix}\n\\end{equation}\n\nHence from (\\ref{eq:DFT_OLS}), we conclude that IDFT is a linear transformation, where $\\mathbf{F}$ the transformation matrix comprises of N harmonically related sinusoids,\nwith mutually orthonormal columns\\footnote{Note that the $\\frac{1}{\\sqrt{N}}$ term is introduce to deal with unit-length columns.}. Then the Fourier coefficients, $\\mathbf{X}$, are given by (\\ref{proof:OLS}):\n\n\\begin{equation}\n    \\mathbf{X} = \\bigg( \\mathbf{F}^{H} \\mathbf{F} \\bigg)^{-1} \\mathbf{F}^{H} \\hat{\\vx} = \\mathbf{F}^{H} \\hat{\\vx}\n\\label{proof:DFT_as_OLS}\n\\end{equation}\n\nwhere the fact that $\\mathbf{F}$ is unitary is used\\footnote{See Problem \\& Answer Sets for the proof.}.\nTherefore, since (\\ref{proof:OLS}) is the optimal least mean squares solution, minimising the squared error and the Fourier coefficients, $\\vw$, follow (\\ref{proof:OLS}),\nthen Inverse Discrete Fourier Transform, $\\hat{x}(n)$, is a linear approximation of the original signal $x(n)$, minimising the squared error:\n\n\\begin{equation}\n    \\underset{\\mathbf{X}}{min} \\| \\vx - \\hat{\\vx} \\|^{2}\n\\end{equation}\n\n% The Discrete Fourier Transform (DFT) of a signal $x(n)$ is given by:\n\n% \\begin{align}\n%     X(k)    &= \\frac{1}{\\sqrt{N}} \\sum_{n=0}^{N-1} x(n) e^{-j \\frac{2\\pi}{N} n k}\n%              = \\frac{1}{\\sqrt{N}} \\sum_{n=0}^{N-1} x(n) W_{N}^{nk}\n% \\end{align}\n\n% where $W_{N} = e^{-j \\frac{2\\pi}{N}}$. If we define:\n\n% \\begin{equation}\n%     \\renewcommand\\arraystretch{1.5}\n%     \\vw_{k}^{H} = \\frac{1}{\\sqrt{N}}\n%     \\begin{bmatrix}\n%         1, & W_{N}^{k}, & W_{N}^{2k}, & \\ldots, & W_{N}^{k(N-1)}\n%     \\end{bmatrix}\n% \\end{equation}\n\n% Arranging the DFT coefficients in a vector, we obtain:\n\n% \\begin{equation}\n%     \\renewcommand\\arraystretch{1.5}\n%     \\mathbf{X} =\n%     \\begin{bmatrix}\n%         X(0) \\\\ X(1) \\\\ \\vdots \\\\ X(N-1)\n%     \\end{bmatrix}\n%     =\n%     \\begin{bmatrix}\n%         \\vw_{0}^{H} \\vx \\\\ \\vw_{1}^{H} \\vx \\\\ \\vdots \\\\ \\vw_{N-1}^{H} \\vx\n%     \\end{bmatrix}\n%     =\n%     \\mathbf{W} \\vx\n% \\end{equation}\n\n% where:\n\n% \\begin{equation}\n%     \\renewcommand\\arraystretch{1.5}\n%     \\mathbf{W} =\n%     \\begin{bmatrix}\n%         \\vw_{0}^{H} \\\\ \\vw_{1}^{H} \\\\ \\vdots \\\\ \\vw_{N-1}^{H}\n%     \\end{bmatrix}\n%     = \\frac{1}{\\sqrt{N}}\n%     \\begin{bmatrix}\n%         1 & 1 & 1 & \\cdots & 1 \\\\\n%         1 & W_{N} & W_{N}^{2} & \\cdots & W_{N}^{N-1} \\\\\n%         \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%         1 & W_{N}^{N-1} & W_{N}^{2(N-1)} & \\cdots & W_{N}^{(N-1)^{2}} \\\\\n%     \\end{bmatrix}\n% \\end{equation}\n\n\n\n\n% The Fourier estimation of a signal $x(n)$, or equivalently its Inverse Discrete Fourier Transform (IDFT), satisfy:\n\n% \\begin{align}\n%     \\hat{x}(n)  &= \\frac{1}{\\sqrt{N}} \\sum_{k=0}^{N-1} X(k) e^{j 2\\pi k n / N} \\\\\n%                 &= \\frac{1}{\\sqrt{N}} \\bigg[ X(0) + X(1) e^{j 2\\pi n / N} + X(2) e^{(j 2\\pi n / N) 2} + \\ldots + X(N-1) e^{(j 2\\pi n / N) (N-1)} \\bigg]\n% \\end{align}\n\n% Rewriting the equation above in matrix form:\n\n% \\begin{align}\n%     \\renewcommand\\arraystretch{1.5}\n%     \\begin{bmatrix}\n%         \\hat{x}(0) \\\\ \\hat{x}(1) \\\\ \\vdots \\\\ \\hat{x}(N-1)\n%     \\end{bmatrix}\n%     = \\frac{1}{\\sqrt{N}}\n%     \\begin{bmatrix}\n%         1 & 1 & \\cdots & 1 \\\\\n%         1 & e^{j \\frac{2\\pi}{N}(1)(1)} & \\cdots & e^{j \\frac{2\\pi}{N}(1)(N-1)} \\\\\n%         \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%         1 & e^{j \\frac{2\\pi}{N}(1)(N-1)} & \\cdots & e^{j \\frac{2\\pi}{N}(N-1)(N-1)}\n%     \\end{bmatrix}\n%     \\begin{bmatrix}\n%         X(0) \\\\ X(1) \\\\ \\vdots \\\\ X(N-1)\n%     \\end{bmatrix}\n% \\end{align}\n\n% Letting $a = e^{j\\frac{2\\pi}{N}}$, we notice a pattern, such that:\n\n% \\begin{align}\n%     \\renewcommand\\arraystretch{1.5}\n%     \\underbrace{\n%         \\begin{bmatrix}\n%             \\hat{x}(0) \\\\ \\hat{x}(1) \\\\ \\vdots \\\\ \\hat{x}(N-1)\n%         \\end{bmatrix}\n%     }_{\\hat{\\vx}}\n%     = \\frac{1}{\\sqrt{N}}\n%     \\underbrace{\n%         \\begin{bmatrix}\n%             1 & 1 & \\cdots & 1 \\\\\n%             1 & a & \\cdots & a^{(N-1)} \\\\\n%             \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%             1 & a^{(N-1)} & \\cdots & a^{(N-1)(N-1)}\n%         \\end{bmatrix}\n%     }_{\\mathbf{F}}\n%     \\underbrace{\n%         \\begin{bmatrix}\n%             X(0) \\\\ X(1) \\\\ \\vdots \\\\ X(N-1)\n%         \\end{bmatrix}\n%     }_{\\vw}\n% \\end{align}\n\n% We conclude that the IDFT is a linear transformation, where $\\mathbf{F}$ the transformation matrix comprises of N harmonically related sinusoids, with mutually orthonormal columns\\footnote{Note that the\n% $\\frac{1}{\\sqrt{N}}$ term is introduce to deal with unit-length columns.}. Then the Fourier coefficients, $\\vw$, are given by (\\ref{proof:OLS}):\n\n% \\begin{equation}\n%     \\vw = \\bigg( \\mathbf{F}^{H} \\mathbf{F} \\bigg)^{-1} \\mathbf{F}^{H} \\vx = \\mathbf{F}^{H} \\vx\n% \\end{equation}\n\n% where the fact that $\\mathbf{F}$ is unitary is used\\footnote{See Problem \\& Answer Sets for the proof.}.\n\n% Hence, since (\\ref{proof:OLS}) is the optimal least mean squares solution, minimising the squared error and the Fourier coefficients, $\\vw$, follow (\\ref{proof:OLS}),\n% then Inverse Discrete Fourier Transform, $\\hat{x}(n)$, is a linear approximation of the original signal $x(n)$, minimising the squared error:\n\n% \\begin{equation}\n%     \\underset{\\vw}{min} \\| \\vx - \\hat{\\vx} \\|^{2}\n% \\end{equation}\n\n%% b)\n\\item\n%\n\nAccording to equation (\\ref{proof:DFT_as_OLS}), the Fourier coefficients, $\\mathbf{X}$, are a linear combination of the columns of the transformation matrix $\\mathbf{F}$, whose columns are orthonormal:\n\n\\begin{equation}\n    \\vf_{k}^{H} \\vf_{l} = \\frac{1}{N} \\sum_{k=0}^{N-1} e^{j \\frac{2\\pi}{N} (k-l)} = \\left\\{\n    \\begin{array}{ll}\n      1 & \\text{if } k=l\\\\\n      0 & \\text{otherwise}\n\\end{array} \\right.\n\\end{equation}\n\nTherefore DFT operation can be seen as a projection of a vector, $\\vx$, in time domain to the $\\mathbf{F}$ matrix subspace, spanned by their orthonormal columns,\nrepresenting $N$ harmonically related sinusoids, wnere each sinusoid is a multiple of the frequency $\\frac{f_{s}}{N}$, with $f_{s}$ the sampling frequency.\n\n%% c)\n\\item\n%\n\nThe $K$-points DFT-CLMS method is applied to the frequency modulated (FM) non-stationary signal, $f(n)$. Figure \\ref{fig:4_3_c_1} illustrates the time-frequency diagram obtained.\nThe algorithm adapts perfectly to the behaviour of the frequency signal, $f(n)$, for $n < 500$, where the frequency is constant over time, while for larger values we notice\nthat the trends (both linear and quadratic) are generally captured. Surprisingly though, once a strong frequency component is picked up by the DFT-CLMS filter, this component is not updated,\nhence the diagram has Fourier coefficients superimposed over time. CLMS is a gradient algorithm, which updates weights (DFT coefficients)\ntowards the mean squared error descent direction. The coefficients are not block-based calculated, but in an adaptive manner, hence error back-propagation is slow, causing this\nlasting effect. Moreover, the $K$-points DFT-CLMS filter has $K$ dimensional weights, where $K=2048$, thus the curse of dimensionality prevents error gradients to propagate back and update the weights.\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/a-real-time-spectrum-analyser-using-least-mean-square/assets/c/dft_clms-gamma_0.00}.pdf}\n    \\end{subfigure}\n    \\caption{FM: DFT-CLMS time-frequency plot with $\\gamma = 0$ (unbiased).}\n    \\label{fig:4_3_c_1}\n\\end{figure}\n\nRegularisation, such as adding a leakage coefficient $\\gamma$, similar to the Leaky LMS variant, enables accurate time-frequency modelling, as shown in figure \\ref{fig:4_3_c_2}.\nThis is achieved thanks to the forget mechanism that the Leaky CLMS algorithm provides:\n\n\\begin{equation}\n    \\vw(n+1) = (1 -\\gamma \\mu) \\vw(n) + \\mu e^{*}(n) \\vx(n)    \n\\end{equation}\n\nwhere the greater $\\gamma$ values allow to ignore, forget previous timestep's weights $\\vw(n)$.\n\nNote that for very small values of the leakage coefficient (i.e $\\gamma = 0.01$) the Fourier coefficient superimposing effect is still visible.\nHowever, larger values of $\\gamma$ (i.e $\\gamma = 0.05, 0.1$) introduce some bias, but obtain correct modelling. Finally, bias for larger values of $\\gamma$ (i.e $\\gamma \\geq 0.5$) lead to inaccurate results.\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/a-real-time-spectrum-analyser-using-least-mean-square/assets/c/dft_clms-gamma_0.01}.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/a-real-time-spectrum-analyser-using-least-mean-square/assets/c/dft_clms-gamma_0.05}.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/a-real-time-spectrum-analyser-using-least-mean-square/assets/c/dft_clms-gamma_0.10}.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/a-real-time-spectrum-analyser-using-least-mean-square/assets/c/dft_clms-gamma_0.50}.pdf}\n    \\end{subfigure}\n    \\caption{FM: DFT-CLMS time-frequency plot with $\\gamma > 0$ (biased).}\n    \\label{fig:4_3_c_2}\n\\end{figure}\n\n%% d)\n\\item\n%\n\nThe $K$-points DFT-CLMS algorithm is applied to the EEG \\texttt{POz} data, of length $N=1200$.\nThe time-frequency diagrams for different $\\gamma$ values are obtained and illustrated in figure \\ref{fig:4_3_d}.\nThe Leaky CLMS does not perform any better than the standard CLMS algorithm, due to the stationary nature of the signal\nunder study.\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/a-real-time-spectrum-analyser-using-least-mean-square/assets/d/dft_clms-gamma_0.000}.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/a-real-time-spectrum-analyser-using-least-mean-square/assets/d/dft_clms-gamma_0.001}.pdf}\n    \\end{subfigure}\n    \\caption{EEG \\texttt{POz}: DFT-CLMS time-frequency plots.}\n    \\label{fig:4_3_d}\n\\end{figure}\n\nThe strong $50 Hz$ component is visible in both implementations and so are the first two harmonics of SSEVP, at\nfrequencies $f_{1} = 13 Hz$ and $f_{2} = 26 Hz$, respectively. The third harmonic is not distinguishable though, with any\nof the two algorithms.\n\n%\n\\end{enumerate}", "meta": {"hexsha": "ce375907719d07237e1eec22f4cd52bc01d96dea", "size": 13561, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/widely-linear-filtering-and-adaptive-spectrum-estimation/a-real-time-spectrum-analyser-using-least-mean-square/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/a-real-time-spectrum-analyser-using-least-mean-square/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/a-real-time-spectrum-analyser-using-least-mean-square/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": 41.3445121951, "max_line_length": 208, "alphanum_fraction": 0.6276823243, "num_tokens": 4784, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.6957593843362115}}
{"text": "\\section{Prologue}\n\n\\subsection{Exercises}\n\n\\subsubsection{Exercise 1}\nThe first graph has exactly 2 vertices of odd degree, so it has a Eulerian path. The second graph has 4 \nvertices of odd degree, so it does not. \n\n\\subsection{Problems}\n\n\\subsubsection{Problem 1}\nEach edge in a finite graph increases the total sum of the graph's vertex degrees by 2. Thus, this sum must\nbe an even number, so we cannot have an odd number of vertices with odd degree (otherwise the sum would be odd).\n\n\\subsubsection{Problem 2}\nConsider a finite simple graph with $n$ vertices. Each vertex can have a degree between 1 and $n - 1$, since\nwe cannot have multiple edges or self-loops. Thus, by the pigeonhole principle, at least two of the $n$ \nvertices must have the same degree (there is no bijection between the $n$ vertices and the $n - 1$ degree\noptions).\n\n\\subsubsection{Problem 3}\nIf every vertex has even degree, we can construct a set of covering cycles as follows. Choose an arbitrary\nvertex with non-zero degree and traverse a cycle starting at that vertex, while deleting all edges traversed along the way.\nRepeat this procedure until all edges have been deleted. We are guaranteed to be able to find the\naforementioned cycles since the graph is connected; an edge \"leaving\" a vertex can be paired with an edge\n\"coming in\" to the vertex.\n\nOnce we have a set of covering cycles, we can combine them into a single cycle as follows. Consider a cycle\nstarting at vertex $a$ and another, edge-disjoint cycle starting at vertex $b$ such that $b$ also occurs\nin the cycle starting at $a$. We can then combine the two cycles by starting at vertex $a$ and traversing\nits cycle until arriving at vertex $b$, at which point we traverse the cycle starting at vertex $b$. Finally,\nwe finish the rest of vertex $a$'s cycle from $b$ onwards. Since cycles $a$ and $b$ were edge-disjoint, this\ncombined cycle does not visit any edge twice. We can repeat this cycle combination procedure until only a\nsingle cycle is left, which is the Eulerian cycle.\n", "meta": {"hexsha": "fb456e1d6d1838302d4babb715baea5849421374", "size": 2030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Nature_of_Computation_Moore_Mertens/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": "Nature_of_Computation_Moore_Mertens/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": "Nature_of_Computation_Moore_Mertens/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": 58.0, "max_line_length": 123, "alphanum_fraction": 0.7743842365, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.6957593770565618}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Stability of perturbed systems}\nWe consider perturbed systems on the form\n\\begin{equation}\n\t\\dot{x} = f(t,x) + g(t,x)\n\\end{equation}\nwith \\emph{nominal} systems\n\\begin{equation}\n\t\\dot{x} = f(t,x)\n\t.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Vanishing perturbation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Lemma 9.1}\n\\begin{itemize}\n\t\\item The origin is an ES equilibrium of the nominal system.\n\t\\item $V(t,x)$ is an LF of the nominal system, and satisfies\n\t\t\\begin{equation}\n\t\t\tc_1 \\norm{x}^2 \\leq V(t,x) \\leq c_2 \\norm{x}^2\n\t\t\\end{equation}\n\t\tand\n\t\t\\begin{equation}\n\t\t\t\\norm{\\pd{V}{x}} \\leq c_4 \\norm{x}\n\t\t\t.\n\t\t\\end{equation}\n\t\\item The perturbation $g(t,x)$ satisfies\n\t\t\\begin{equation}\n\t\t\t\\norm{g(t,x)} \\leq \\gamma \\norm{x}, \\quad \\gamma < \\frac{c_3}{c_4}\n\t\t\t.\n\t\t\\end{equation}\n\\end{itemize}\nThen $x^* = 0$ of the perturbed system is ES. If the assumptions hold globally, $x = 0$ is GES.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Nonvanishing perturbation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", "meta": {"hexsha": "07f474b64cd00e46abec82f8ab5eda9226a73ed5", "size": 1054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-stability-of-perturbed-systems.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4150 Nonlinear control systems/sec-stability-of-perturbed-systems.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4150 Nonlinear control systems/sec-stability-of-perturbed-systems.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0256410256, "max_line_length": 95, "alphanum_fraction": 0.5977229602, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6957593746322216}}
{"text": "\\section{Neural networks\\enskip\n$\\color{section-text-color} \\phi_j(x_i) \\leftrightarrow \\phi(x_i,\\theta)$}\n\nParameterize feature map: $\\phi(x,\\theta)$ instead of $\\phi(x)$, usually: \\highlight*{$\\phi(x,\\theta) = \\varphi(\\theta^\\top x)$} $= \\varphi(z)$\\\\\n$\\Rightarrow w^* = \\arg\\min\\limits_{w,\\theta} \\sum_{i=1}^n \\ell(y_i; \\underbracket[.7pt][.7pt]{\\textstyle \\sum_{j=1}^m w_j \\,\\phi(x_i, \\theta_j)}_{f(x;w,\\theta)})$\n\n% ===\n\\emph{Activation functions $\\color{emph-text-color} \\varphi(z)$}\n\n\\textbf{Sigmoid:} $\\frac{1}{1+\\exp(-z)} {\\color{gray} \\,\\in [0,1]}$, \\enskip {\\small $\\varphi'(z) = (1 \\!-\\! \\varphi(z))\\cdot\\varphi(z)$}\\par\n\\textbf{Tanh:} $\\varphi(z) = \\tanh(z) = \\frac{\\exp(z)-\\exp(-z)}{\\exp(z)+\\exp(-z)} \\color{gray} \\,\\in [-1,1]$\\par\n\\textbf{ReLu:}  $\\varphi(z) = \\max(z,0) \\color{gray} \\;\\to \\text{not smooth}$\n\n% ===\n\\emph{Predict: forward propagation}\n\\setstretch{0.9}\n\\begin{highlightbox}\n    \\begin{enumerate}\n        \\item $v^{(0)} = x$\n        \\item $v^{(l)} = \\varphi(z^{(l)})$, $z^{(l)} = W^{(l)}v^{(l-1)}${,\n            \\small $\\color{gray}\\text{for }l = 1:L\\!-\\!1$}\n        \\item $f = z^{(L)} = W^{(l)} v^{(L\\!-\\!1)}$\n        \\item \\textbf{Pred.}: $\\hat y \\!=\\! f$ (Regr.) \\textit{or}\n        \\begin{minipage}{.4\\linewidth}\n    \t\t\\small\\vspace*{-10pt}\n    \t\t$\\quad\\begin{cases}\n    \t\t\t\\hat y = \\operatorname{sign}(f) \\textit{ or}\\\\\n    \t\t\t\\hat y = \\arg\\max\\limits_i(f_i)\n    \t\t\\end{cases}$\n    \t\\end{minipage}\n    \\end{enumerate}\n\\end{highlightbox}\n\n% ===\n\\emph{Compute gradient: \\normalfont\\sffamily backpropagation}\n\\begin{highlightbox}\n\t\\textbf{Output}: {\\footnotesize$[\\cdots\\highlight*{\\delta_k^{(L)}}\\!\\cdots] =$} $\\delta^{(L)} \\!=\\! \\ell'(f)$ {\\footnotesize$= [\\cdots\\ell_k'(f_k)\\cdots]$}\n\t\n\t\\textbf{Hidden layer}: for $\\normalfont l=L{-}1 : 1$, \\\\\n\t$\n\t\\highlight*{\\delta_k^{(l)}\\!} {=} \\varphi'(z_k)\\cdot \\hspace{-12pt} \\sum\\limits_{j\\in\\textrm{layer}_{(l+1)}} \\hspace{-12pt} w_{jk}\\delta_j\n\t\\enskip\n\t\\text{\\normalcolor \\textbf{Grad.}:} \\pderiv{\\ell}{w_{j,k}} \\!\\!=\\! \\delta_j^{(l)}v_k^{(l\\!-\\!1)}\n\t$\n\\end{highlightbox}\n\n$W \\!=\\! [w_{jk}^{(L)} \\cdots w_{jk}^{(1)}]_{jk}$, \\hfill $L(W) \\!\\equiv\\! L = \\sum_j\\ell_j(y_j,f_j)$\n\n% ===\n\\emph{Learning with momentum}\n\\begin{highlightbox}\n\t\\textbf{1.} $a \\leftarrow {\\color{OrangeRed}m} a + \\eta_t \\nabla_W \\ell(W;y,x)$\\enskip\n\t\\textbf{2.} $W \\leftarrow W \\!-\\! a$\n\\end{highlightbox}\n\n% ===\n\\emph{Convolutional NNs}\n\n$\\to$ $\\overbracket[.7pt][.7pt]{\\text{conv. $\\to$ pooling}}^{\\text{repeat $n$ times}}$\n$\\to$ $\\overbracket[.7pt][.7pt]{\\text{fully connected}}^{\\text{Perceptron ($m$ times)}}$ $\\to$ out\n\n\\textbf{Convolution}: for edge regions $\\to$ 0-padding\n\n\\textbf{pooling} (subsampling): e.g. `max' pooling\n\n\\textbf{output dim's}:\n$\\alpha = \\frac{n+2p-f}{s}+1$\\\\\n{\\small\nwhere $m$: \\# $f\\times f$ filters,\\enskip\n$n$: img. dim.,\\enskip\n$p$: padding, \\# of added zeros,\\enskip\n$s$: strides (amount by which filter shifts)\n}\n", "meta": {"hexsha": "fd9c4cd1160dde07da54ae13dcb1ee628cdc0222", "size": 2900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/NeuralNetworks.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/NeuralNetworks.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/NeuralNetworks.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.1891891892, "max_line_length": 163, "alphanum_fraction": 0.5851724138, "num_tokens": 1195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6957488460244893}}
{"text": "\n \\FloatBarrier\n\n\\section{Maximization problems}\\label{sec:maximization}\n\n\n\n\nThe evolutionary dynamics can be used to solve convex optimization problems. \nWe can use the properties of population games to design games that maximize some function $f(\\bs{z})$, where $\\bs{z}\\in\\mathbb{R}^{n}$ is a vector of $n$ variables, i.e., $\\bs{z} = [z_1, \\ldots, z_k, \\ldots, z_n]$. Below we show two alternatives to solve this optimization problem using either a single population or $n$ populations.\n\n\n\n\\subsection{Single Population Case}\n\nFirst, let us consider a population where each agent can choose one of the $n+1$ strategies. In this case, the first $n$ strategies correspond one variable of the objective function and the $n+1\\th$ strategy can be seen as a slack variable. \nThus, $x_k$ is the proportion of agents that use the $k\\th$ strategy, and it corresponds to the $k\\th$ variable, i.e., $x_k = z_k$.\nWe define the fitness function of the $k\\th$ strategy $F_k$ as the derivative of the objective function with respect to the $k\\th$ variable, thus, $F_k(\\bs{x}) \\equiv \\frac{\\partial }{\\partial x_k} f(\\bs{x})$.\n\nNote that if $f(\\bs{x})$ is a concave function, then its gradient is a decreasing function. \nRecall that users attempt to increase their fitness by adopting the most profitable strategy in the population, say the $k\\th$ strategy. This lead to an increase of $x_k$, which in turns decrease the fitness  $F_k(\\bs{x})$. \n\nFurthermore, the equilibrium is reached when all agents that belong to the same population have the same fitness.\nThus, at the equilibrium $F_i(\\bs{x}) = F_j(\\bs{x})$, where $i,j\\in\\{1, \\ldots, n \\}$.\nIf we define $F_{n+1}(\\bs{x}) = 0$, then at the equilibrium we have $F_i(\\bs{x}) = 0$  for every strategy $i\\in\\{1, \\ldots, n\\}$. \n%\nSince the fitness function decreases with the action of users, we can conclude that the strategy of the population evolves to make the gradient of the objective function equal to zero (or as close as possible). This resembles a gradient method to solve optimization problems.\n\n% A characteristic of this implementation is that the  function of users depends on their strategy. Specifically, there are $n+1$ different strategy functions. \n\nRecall that the he evolution of the strategies lies in the simplex, that is, $\\sum_{i \\in S^p} z_i = m$. Hence, this implementation solves the following optimization problem:\n\\begin{equation}\n\\begin{aligned}\n& \\underset{\\bs{z}}{\\text{maximize}}\n& &  f(\\bs{z}) \\\\\n& \\text{subject to}\n& & \\sum_{i=1}^n z_i \\leq m,\n\\end{aligned}\n\\label{eq:opt_problem}\n\\end{equation}\nwhere m is the total mass of the population.\n%Next we present a different implementation in which each user of the same population has the same fitness function.\n%\nFigure \\ref{fig:maximization_a} shows an example of the setting described above for the  function\n\\begin{equation}\\label{eq:objective_f}\n f(\\bs{z}) = - (z_1-5)^2 - (z_2-5)^2.\n\\end{equation}\nThe simulation is executed during $0.6$ time units. \n\n\\begin{figure}[htb]\n\\centering\n \\includegraphics[width=.5\\textwidth]{./images/maximization_a.eps}\n \\caption{Evolution of the maximization setting using only one population.}\n \\label{fig:maximization_a}\n\\end{figure}\n\n\n\n\\subsection{Multi-population Case}\n\n\n\nLet us consider $n$ populations where each agent can choose one of two strategies. \nWe define a population per each variable of the maximization problem and also $n$ additional strategies that resemble slack variables.\nThus, $x_i^p$ is the proportion of agents that use the $i\\th$ strategy in the $p\\th$ population. In this case $x_1^k$ corresponds to the $k\\th$ variable, that is, $x_1^k = z_k$, while $x_2^k$ is a slack variable.\n%\nThe fitness function $F_1^k$ of the $k\\th$ population is defined as the derivative of the objective function with respect to the $k\\th$ variable, that is, $F_1^k(\\bs{x}) \\equiv \\frac{\\partial }{\\partial x_1^k} f(\\bs{x})$. On the other hand, $F_2^k(\\bs{x}) = 0$.\nThis implementation solves the following optimization problem:\n\\begin{equation}\n\\begin{aligned}\n& \\underset{\\bs{z}}{\\text{maximize}}\n& &  f(\\bs{z}) \\\\\n& \\text{subject to}\n& & z_i \\leq m^i, i =\\{1,\\ldots,n\\}.\n\\end{aligned}\n\\label{eq:opt_problem}\n\\end{equation}\n\n\nFigure \\ref{fig:maximization_b} shows an example of the setting described above for the function in Eq. (\\ref{eq:objective_f}).\nThe simulation is executed during $0.6$ time units. Note that the implementation using multiple populations reach the optimal value faster than the single population implementation.\n\\begin{figure}[htb]\n\\centering\n \\includegraphics[width=.5\\textwidth]{./images/maximization_b.eps}\n \\caption{Evolution of the the maximization setting using $n$ populations.}\n \\label{fig:maximization_b}\n\\end{figure}\n\n\nThe speed of convergence to the optimum depends on the dynamics and their parameters. For instance, we observed that the equilibrium of the BNN dynamics might be closer to the optimal solution $\\bs{z}^*$ if the mass of the population $m^p$ is close to $\\sum_{i=1}^N z_i$. Note that close to the optimum $\\hat{F}^p$ is small, and if $m^p$ is too large, then the slack variable, such as  $x_2^k$, might be too large, making $x_1^k$ small. These conditions might hinder the convergence to the optimum because updates in the strategies are too small.", "meta": {"hexsha": "00391f7e5f3e6a4afc0d49626e7a32738e1241c4", "size": 5265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/maximization.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/maximization.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/maximization.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": 58.5, "max_line_length": 546, "alphanum_fraction": 0.7416904084, "num_tokens": 1450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741041, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6956934382582004}}
{"text": "\\lab{Markov Chains}{Markov Chains}\n\\label{lab:Markov}\n\\objective{\nA \\emph{Markov chain} is a collection of states with specified probabilities for transitioning from one state to another.\nThey are characterized by the fact that the future behavior of the system depends only on its current state.\nMarkov chains have far ranging applications.\nIn this lab, we learn to construct, analyze, and interact with Markov chains and apply a Markov chain to natural language processing.}\n\n\\section*{State Space Models} % ===============================================\n\nMany systems can be described by a finite number of states.\nFor example, a board game where players move around the board based on die rolls can be modeled by a Markov chain.\nEach space represents a state, and a player is said to be in a state if their piece is currently on the corresponding space.\nIn this case, the probability of moving from one space to another only depends on the players current location: where the player was on a previous turn does not affect their current turn.\n\n% A Markov chain is a collection of states, together with the probabilities of moving from one state to another.\nFinite Markov chains have an associated \\emph{transition matrix} that stores the information about the transitions between the states in the chain.\nThe $(ij)^{th}$ entry of the matrix gives the probability of moving from state $i$ to state $j$.\nThus the rows of the transition matrix must sum to 1.\n\n\\begin{info} % Row / column stochasticity\nA transition matrix where the rows sum to 1 is called \\emph{row stochastic} (or \\emph{right stochastic}).\nThe columns of a \\emph{column stochastic} (or \\emph{left stochastic}) transition matrix each sum to 1 and the $(i,j)^{th}$ entry of the matrix gives the probability of moving from state $j$ to state $i$.\nBoth representations are common, but in this lab we exclusively use row stochastic transition matrices for consistency.\n\\end{info}\n\nConsider a very simple weather model where the probability of being hot or cold depends on the weather of the previous day.\nIf the probability that tomorrow is hot given that today is hot is 0.7, and the probability that tomorrow is cold given that today is cold is 0.4, then by assigning hot to the $0^{th}$ row and column, and cold to the $1^{st}$ row and column, this Markov chain has the following transition matrix:\n%\n\\begin{align*}\n\\begin{blockarray}{ccc}\n& \\text{\\textcolor{red}{hot tomorrow}} & \\text{\\textcolor{blue}{cold tomorrow}} \\\\\n\\begin{block}{c(cc)}\n\\text{\\textcolor{red}{hot today}}   & 0.7 & 0.3 \\\\\n\\text{\\textcolor{blue}{cold today}} & 0.6 & 0.4 \\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nIf it is hot today, we examine the $0^{th}$ row of the matrix.\nThere is a $70\\%$ chance that tomorrow will be hot ($0^{th}$ column) and a $30\\%$ chance that tomorrow will be cold ($1^{st}$ column).\nConversely, if it is cold today, there is a $60\\%$ chance that tomorrow will be hot and a $40\\%$ chance that tomorrow will be cold.\n\nMarkov chains can be represented by a \\emph{state diagram}, a type of directed graph.\nThe nodes in the graph are the states, and the edges indicate the state transition probabilities.\nThe Markov chain described above has the following state diagram.\n%\n% TODO: Turn this into a tikzpicture.\n\\begin{figure}[H]\n    \\includegraphics[width=.5\\linewidth]{figures/WeatherChain.pdf}\n\\end{figure}\n%\n\\begin{problem} % Problem: stochasticity.\nTransition matrices for Markov chains are efficiently stored as NumPy arrays.\nWrite a function that accepts a dimension $n$ and returns the transition matrix for a random Markov chain with $n$ states.\n\\\\\n(Hint: use array broadcasting to avoid looping.)\n\\end{problem}\n\n\\subsection*{Simulating State Transitions} % ----------------------------------\n\n% TODO: Use the binomial distribution instead of uniform. (?)\nSince the rows of a transition matrix sum to $1$, the entries of each row partition the interval $[0, 1]$.\nWe can thus choose the next state to move to by generating a random number between $0$ and $1$.\n\nConsider again the simple weather model and suppose that today is hot.\nThe row that corresponds to ``hot''in the transition matrix is $[0.7, 0.3]$.\nIf we generate a random number and it is smaller than $0.3$, then the simulation indicates that tomorrow will be cold.\nConversely, if the random number is between $0.3$ and $1$, then the simulation says that tomorrow will be hot.\n\n\\begin{lstlisting}\nimport numpy as np\n\ndef forecast():\n\t\"\"\"Forecast tomorrow's weather given that today is hot.\"\"\"\n\ttransition_matrix = np.array([[0.7, 0.3], [0.6, 0.4]])\n\t# Sample from the standard uniform distribution to choose a new state.\n\tif np.random.random() < transition_matrix[0, 1]:\n\t\treturn 1              # Tomorrow will be cold.\n\telse:\n\t\treturn 0              # Tomorrow will be hot.\n\\end{lstlisting}\n\n\\begin{problem} % Problem: Forecasting over several days.\nModify \\li{forecast()} so that it accepts a parameter \\li{days} and runs a simulation of the weather for the number of days given.\nReturn a list containing the day-by-day weather predictions (0 for hot, 1 for cold).\nAssume the first day is hot, but do not include the data from the first day in the list of predictions.\nThe resulting list should therefore have \\li{days} entries.\n\\end{problem}\n\n\\subsection*{Larger Chains} % -------------------------------------------------\n\nThe \\li{forecast()} function makes one random draw from a \\emph{uniform} distribution to simulate a state change.\nLarger Markov chains require draws from a \\emph{multinomial} distribution, a multivariate generalization of the binomial distribution.\n\nA single draw from a binomial distribution with parameter $p$ indicates successes or failure of a single experiment with probability $p$ of success.\nThe classic example is a coin flip, where the $p$ is the probability that the coin lands heads side up.\nA single draw from a multinomial distribution with parameters $\\left(p_1, p_2, ..., p_n \\right)$ indicates which of $n$ outcomes occurs.\nIn this case the classic example is a dice roll, with $6$ possible outcomes instead of the $2$ in a coin toss.\n\n\\begin{lstlisting}\n# To simulate a single dice roll, store the probabilities of each outcome.\n>>> die_probabilities = np.array([1./6, 1./6, 1./6, 1./6, 1./6, 1./6])\n\n# Make a single random draw (roll the die once).\n>>> np.random.multinomial(1, die_probabilities)\narray([0, 0, 0, 1, 0, 0])                       # The roll resulted in a 4.\n\\end{lstlisting}\n\n\\begin{problem} % Problem: 4 states instead of 2. Multinomial transitioning.\nLet the following be the transition chain for a Markov chain modeling weather with four states: hot, mild, cold, and freezing.\n\n\\begin{align*}\n\\begin{blockarray}{ccccc}\n& \\text{\\textcolor{red}{hot}} & \\text{\\textcolor[rgb]{0,.6,0}{mild}} & \\text{\\textcolor{blue}{cold}} & \\text{\\textcolor{cyan}{freezing}} \\\\\n\\begin{block}{c(cccc)}\n\\text{\\textcolor{red}{hot}}                 & 0.5 & 0.3 & 0.2 & 0 \\\\\n\\text{\\textcolor[rgb]{0,.6,0}{mild}}       & 0.3 & 0.3 & 0.3 & 0.1 \\\\\n\\text{\\textcolor{blue}{cold}}               & 0.1 & 0.3 & 0.4 & 0.2 \\\\\n\\text{\\textcolor{cyan}{freezing}}           & 0 & 0.3 & 0.5 & 0.2 \\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nWrite a new function that accepts a parameter \\li{days} and runs the same kind of simulation as \\li{forecast()}, but that uses this new four-state transition matrix.\nThis time, assume the first day is mild.\nReturn a list containing the day-to-day results (0 for hot, 1 for mild, 2 for cold, and 3 for freezing).\n\\label{prob:makov-state-transition}\n\\end{problem}\n\n% TODO: instead of crappy empirical analysis, teach briefly about steady states and raising the transition matrix to a large power.\n\n\\begin{problem} % Problem: Analysis of results.\nWrite a function that investigates and interprets the results of the simulations in the previous two problems.\nSpecifically, find the average percentage of days that are hot, mild, cold, and freezing in each simulation.\nDoes changing the starting day alter the results?\nPrint a report of your findings.\n\\end{problem}\n\n\\section*{Using Markov Chains to Simulate English} % ==========================\n% TODO: is it okay to make this reference?\nOne of the original applications of Markov chains was to study natural languages.\\footnote{In computer science, a \\emph{natural language} is a spoken language, like English or Russian. See \\url{http://langvillea.people.cofc.edu/MCapps7.pdf} for some details on the early applications of Markov chains, including the study of natural languages.}\nIn the early $20^{th}$ century, Markov used his chains to model how Russian switched from vowels to consonants.\nBy mid-century, they had been used as an attempt to model English.\nIt turns out that Markov chains are, by themselves, insufficient to model very good English.\nHowever, they can approach a fairly good model of bad English, with sometimes amusing results.\n\nBy nature, a Markov chain is only concerned with its current state.\nThus a Markov chain simulating transitions between English words is completely unaware of context or even of previous words in a sentence.\nFor example, a Markov chain's current state may be the word ``continuous.''\nThen the chain would say that the next word in the sentence is more likely to be ``function'' rather than ``raccoon.''\nHowever, without the context of the rest of the sentence, even two likely words stringed together may result in gibberish.\n\nWe restrict ourselves to a subproblem of modeling the English of a specific file.\nThe transition probabilities of the resulting Markov chain will reflect the sort of English that the source authors speak.\nThus the Markov chain built from \\emph{The Complete Works of William Shakespeare} will differ greatly from, say, the Markov chain built from a collection of academic journals.\nWe will call the source collection of works in the next problems the \\emph{training set}.\n\n\\subsection*{Making the Chain} % ----------------------------------------------\n\nWith the weather models of the previous sections, we chose a fixed number of days to simulate.\nHowever, English sentences are of varying length, so we do not know beforehand how many words to choose (how many state transitions to make) before ending the sentence.\nTo capture this feature, we include two extra states in our Markov model: a \\emph{start state} (\\textcolor[rgb]{0,.6,0}{\\$tart}) marking the beginning of a sentence, and a \\emph{stop state} (\\textcolor{red}{\\$top}) marking the end.\nThus if a training set has $N$ unique words, the transition matrix will be $(N+2) \\times (N+2)$.\n\nThe start state should only transition to words that appear at the beginning of a sentence in the training set, and only words that appear at the end a sentence in the training set should transition to the stop state.\nThe stop state is called an \\emph{absorbing state} because once we reach it, we cannot transition back to another state.\n% Because every state has a possible path to the stop state, this model is called an \\emph{absorbing Markov chain}.\n\nAfter determining the states in the Markov chain, we need to determine the transition probabilities between the states and build the corresponding transition matrix.\nConsider the following small training set as an example.\n\n\\begin{lstlisting}\n<<I am Sam Sam I am.\nDo you like green eggs and ham?\nI do not like them, Sam I am.\nI do not like green eggs and ham.>>\n\\end{lstlisting}\n\nIf we include punctuation (so ``ham?'' and ``ham.'' are counted as distinct words) and do not alter the capitalization (so ``Do'' and ``do'' are also different), there are 15 unique words in this training set:\n%\n\\begin{align*}\n\\text{I\\quad am\\quad Sam\\quad am.\\quad Do\\quad you\\quad like\\quad green}\n\\\\\n\\text{eggs\\quad and\\quad ham?\\quad do\\quad not\\quad them,\\quad ham.}\n\\end{align*}\n\nWith start and stop states, the transition matrix should be $17 \\times 17$.\nEach state must be assigned a row and column index in the transition matrix.\nAs easy way to do this is to assign the states an index based on the order that they appear in the training set.\nThus our states and the corresponding indices will be as follows:\n%\n\\begin{align*}\n\\begin{array}{ccccccc}\n\\text{\\textcolor[rgb]{0,.6,0}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & \\ldots & \\text{ham.} & \\text{\\textcolor{red}{\\$top}}\n\\\\\n0 & 1 & 2 & 3 & \\ldots & 15 & 16\n\\end{array}\n\\end{align*}\n\nThe start state should transition to the words ``I'' and ``Do'', and the words ``am.'', ``ham?'', and ``ham.'' should each transition to the stop state.\nWe first count the number of times that each state transitions to another state:\n\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{0,.6,0}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & & \\text{ham.} & \\text{\\textcolor{red}{\\$top}} \\\\\n\\begin{block}{c(ccccccc)}\n\\text{\\textcolor[rgb]{0,.6,0}{\\$tart}} \t& 0 & 3 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{I} \t\t& 0 & 0 & 1 & 0 & \\ldots & 0 & 0\\\\\n\\text{am} \t\t& 0 & 0 & 0 & 1 & \\ldots & 0 & 0\\\\\n\\text{Sam} \t\t& 0 & 2 & 0 & 1 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\text{ham.} \t& 0 & 0 & 0 & 0 & \\ldots & 0 & 1\\\\\n\\text{\\textcolor{red}{\\$top}} \t\t& 0 & 0 & 0 & 0 & \\ldots & 0 & 1\\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nNow we divide each row by its sum so that each row sums to 1.\n\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{0,.6,0}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & & \\text{ham.} & \\text{\\textcolor{red}{\\$top}} \\\\\n\\begin{block}{c(ccccccc)}\n\\text{\\textcolor[rgb]{0,.6,0}{\\$tart}} & 0 & 3/4 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{I}        & 0 & 0 & 1/5 & 0 & \\ldots & 0 & 0\\\\\n\\text{am}       & 0 & 0 & 0 & 1 & \\ldots & 0 & 0\\\\\n\\text{Sam}      & 0 & 2/3 & 0 & 1/3 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\text{ham.}     & 0 & 0 & 0 & 0 & \\ldots & 0 & 1\\\\\n\\text{\\textcolor{red}{\\$top}}        & 0 & 0 & 0 & 0 & \\ldots & 0 & 1\\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nThe $3/4$ indicates that 3 out of 4 times, the sentences in the training set start with the word ``I''.\nSimilarly, the $2/3$ and $1/3$ tell us that ``Sam'' is followed by ``I'' twice and by ``Sam'' once in the training set.\nNote that ``am'' (without a period) always transitions to ``Sam'' and that ``ham.'' (with a period) always transitions the stop state.\nFinally, to avoid a row of zeros, we place a 1 in the bottom right hand corner of the matrix (so the stop state always transitions to itself).\n\nThe entire procedure of creating the transition matrix for the Markov chain with words from a file as states is summarized below in Algorithm \\ref{alg:MarkovSentencesTransitionMatrix}.\n\n\\begin{algorithm} % Read a file and convert it into a Markov chain.\n\\begin{algorithmic}[1]\n\\Procedure{MakeTransitionMatrix}{}\n\\State Count the number of unique words in the training set.\n\\State Initialize a square array of zeros of the appropriate size to be the transition \\par\\quad matrix (remember to account for the start and stop states).\n\\State Initialize a list of states, beginning with \\li{\"\\$tart\"}.\n\\For {each sentence in the training set}\n    \\State Split the sentence into a list of words.\n    \\State Add each \\emph{new} word in the sentence to the list of states.\n    \\State Convert the list of words into a list of indices indicating which row and \\par\\qquad\\enspace column of the transition matrix each word corresponds to.\n    \\State Add 1 to the entry of the transition matrix corresponding to\n    \\par\\qquad\\enspace transitioning from the start state to the first word of the sentence.\n    \\For {each consecutive pair $(i, j)$ of words in the list of words}\n        \\State Add 1 to the entry of the transition matrix corresponding to \\par\\qquad\\qquad transitioning from state $i$ to state $j$.\n    \\EndFor\n    \\State Add 1 to the entry of the transition matrix corresponding to\n    \\par\\qquad\\enspace transitioning from the last word of the sentence to the stop state.\n\\EndFor\n\\State Make sure the stop state transitions to itself.\n\\State Normalize each row by dividing by the row sums (Hint: array broadcasting).\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Convert a training set of sentences into a Markov chain.}\n\\label{alg:MarkovSentencesTransitionMatrix}\n\\end{algorithm}\n\n\\begin{problem} % Problem: Class that makes a Markov chain from a file.\nWrite a class called \\li{SentenceGenerator}.\nThe constructor should accept a filename (the training set).\nRead the file and build a transition matrix from its contents.\nYou may assume that the file has one complete sentence written on each line.\n\\label{problem:markov-random-sentences-init}\n\\end{problem}\n\n\\begin{problem} % Problem: Create random sentences\nAdd a method to the \\li{SentenceGenerator} class called \\li{babble()}.\nBegin at the start state and use the strategy from Problem \\ref{prob:makov-state-transition} to repeatedly transition through the object's Markov chain.\nKeep track of the path through the chain and the corresponding sequence of words.\nWhen the stop state is reached, stop transitioning to terminate the simulation.\nReturn the resulting sentence as a single string.\n\\newpage\nFor example, your \\li{SentenceGenerator} class should be able to create random sentences that sound somewhat like Yoda speaking.\n\n\\begin{lstlisting}\n>>> yoda = SentenceGenerator(\"Yoda.txt\")\n>>> for i in xrange(5):\n... \tprint(yoda.babble())\n...\n<<\nImpossible to my size, do not!\nFor eight hundred years old to enter the dark side of Congress there is.\nBut beware of the Wookiees, I have.\nFear leads to eat as well.\nBut agree on this, we must, and find your weapon!>>\n\\end{lstlisting}\n\n\\label{prob:markov-random-sentences-babble}\n\\end{problem}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Large Training Sets} % -------------------------------------------\n\nThe approach in Problems \\ref{problem:markov-random-sentences-init} and \\ref{prob:markov-random-sentences-babble} begins to fail as the training set grows larger.\nFor example, a single Shakespearean play may not be large enough to cause memory problems, but \\emph{The Complete Works of William Shakespeare} certainly will.\n\nTo accommodate larger data sets, consider use a sparse matrix for the transition matrix in instead of a regular NumPy array. %(use the \\li{lil_matrix} from the \\li{scipy.sparse} library). % Why lil_matrix?\nEnsure that the process still works on small training sets, then proceed to larger training sets.\nHow are the resulting sentences different if a very large training set is used instead of a small training set?\n\n\\subsection*{Variations on the English Model} % -------------------------------\n\nChoosing a different state space for the English Markov model produces different results.\nConsider modifying your \\li{SentenceGenerator} class so that it can determine the state space in a few different ways.\nThe following ideas are just a few possibilities.\n\n\\begin{itemize}\n\\item Let each punctuation mark have its own state.\nIn the example training set, instead of having two states for the words ``ham?'' and ``ham.'', there would be three states: ``ham'', ``?'', and ``.'', with ``ham'' transitioning to both punctuation states.\n\\item Model paragraphs instead of sentences.\nAdd a \\textcolor[rgb]{0,.6,0}{\\$tartParagraph} state that always transitions to \\textcolor[rgb]{0,.6,0}{\\$tartSentence} and a \\textcolor{red}{\\$topParagraph} state that is sometimes transitioned to from \\textcolor{red}{\\$topSentence}.\n\\item Let the states be individual letters instead of individual words.\nBe sure to include a state for the spaces between words.\nWe will explore this particular state space choice more in Volume III.\n\\end{itemize}\n\n\\subsection*{Natural Language Processing Tools} % -----------------------------\n\nThe Markov model of Problems \\ref{problem:markov-random-sentences-init} and \\ref{prob:markov-random-sentences-babble} is an example of \\emph{natural language processing}.\nThe \\li{nltk} module (natural language toolkit) has many tools for parsing and analyzing text.\nFor example, \\li{nltk.sent_tokenize()} reads a single string and splits it up by sentence.\n\n\\begin{lstlisting}\n>>> from nltk import sent_tokenize\n>>> with open(\"Yoda.txt\", 'r') as yoda:\n...     sentences = sent_tokenize(yoda.read())\n...\n>>> print(sentences)\n<<['Away with your weapon!',\n 'I mean you no harm.',\n 'I am wondering - why are you here?',\n ...>>\n\\end{lstlisting}\n\nThe \\li{nltk} module is \\textbf{not} part of the Python standard library.\nFor instructions on downloading, installing, and using \\li{nltk}, visit \\url{http://www.nltk.org/}.\n", "meta": {"hexsha": "494bdee07f9c3fb5104a934e12e2f7facb2bb343", "size": 20572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/MarkovChains/MarkovChains.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2A/MarkovChains/MarkovChains.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2A/MarkovChains/MarkovChains.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 59.2853025937, "max_line_length": 344, "alphanum_fraction": 0.7237993389, "num_tokens": 5377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.695693417049399}}
{"text": "\\chapter{Assignment: \\protect\\\\ Hierarchical Clustering}\n\\label{hw:arheo_hierarchical_clustering}\n\n\\newthought{Shards belong to different time periods}. Periods are described with 22 numeric variables, each defining the likelihood of a shard belonging to the said period. First, let us visualize the data in a visualization that shows the value of numeric variables with color - the higher the value, the brighter the number. Such a visualization is called a \\widget{Heat Map}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.35]{heat-map-original.png}\n    \\caption{$\\;$} % empty caption for proper page setting\n\\end{figure}\n\nBy default, Heat Map shows each data instance in a row and maps the values to the color scale. But our data is so unorganized, there is no way we can make sense of it! First, since we have many rows in our data set, let us join together rows that are the most similar. We will do this with \\textit{Merge by k-means} option and set the number of clusters to 100. This is keep only 100 most different rows.\n\nVisualization got simpler, but it is still unorganized. Would it be nice to have similar rows closer together? Of course it would! We can use hierarchical clustering to re-order rows, so that similar rows will be put next to each other. Use \\textit{Clustering (opt. ordering)} - the plot now makes much more sense!\n\n\\begin{wrapfigure}{o}{1.05\\textwidth}\n    \\vspace{-0.1cm}\n    \\includegraphics[scale=0.4]{heat-map-clustered.png}\n\\end{wrapfigure}\n\nIn the top left corner, we have shards from the early periods. In the bottom central part shards from Roman and Hellenic periods. And in the middle right part recent or unidentified shards.\n\nWe can repeat the same, but a more exact procedure, with \\widget{Hierarchical Clustering}. First, let us pass the data to \\widget{Distances} to compute the distance matrix. As our data has a fair number of dimensions (22 to be precise), we will use \\textit{cosine distance} and \\textit{Ward linkage} for the measure of cluster similarity.\n\nIn Hierarchial Clustering, we see a large dendrogram. To make it easier to read, set \\textit{Max depth} to 10 (this will cut the tree at the tenth split). Use Zoom to zoom out as much as possible.\n\n\\begin{figure*}[h]\n    \\centering\n    \\includegraphics[scale=0.45]{hierarchical-clustering.png}\n    \\caption{$\\;$} % empty caption for proper page setting\n\\end{figure*}\n\n\\newpage\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.6]{workflow.png}\n    \\caption{$\\;$} % empty caption for proper page setting\n\\end{figure}\n\n\\subsection{Assignment}\n\nUse Box Plot to explore the clusters:\n\\begin{itemize}\n    \\item What is a good number of clusters? Why?\n    \\item Cut the dendrogram at the desired level (up to you). Which period(s) does each of the clusters represent? Could you name them?\n    \\item What defines each period? Use Box Plot with \\textit{Data} output to find out.\n\\end{itemize}\n", "meta": {"hexsha": "c6ef5f8859f839facdf14f521a75d48a6edd9faa", "size": 2924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignments/arheo-003-hierarchical-clustering/hierarchical-clustering.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": "assignments/arheo-003-hierarchical-clustering/hierarchical-clustering.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": "assignments/arheo-003-hierarchical-clustering/hierarchical-clustering.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": 59.6734693878, "max_line_length": 404, "alphanum_fraction": 0.7571819425, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.6956934155550599}}
{"text": "\\section{Universal cover}\n\nThe following two theorems summarize our results about covering spaces.\n\n\\begin{theorem}[Galois Correspondence of Covering Spaces]\n  There is a 1-1 correspondence between the subgroups of $\\Gal(Y|X)$ and covers of $X$ that lie between $Y$ and $X$, given by the following maps\n  \\begin{align*}\n    \\{\\mbox{ subgroups of $\\Gal(Y|X)$ } \\} &\\longleftrightarrow  \\{\\mbox{ covers lying between $Y$ and $X$ } \\}\\\\\n    H &\\longmapsto Y/H \\\\\n    \\Gal(Y|Z) & \\longmapsfrom Z\n  \\end{align*}\n  Under this correspondence, the normal subgroups of $\\Gal(X|Y)$ correspond to Galois covers of $X$.\n\\end{theorem}\n\n\\begin{theorem}[Monodromy action of the fundamental group]\n  \\label{theorem:fundamentalGroupQuotient2}\n  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    \\begin{tikzcd}\n      1 \\ar[r] & \\pi_1(Y,y) \\ar[r, \"p_*\"] & \\pi_1(X,x) \\ar[r,\"M\"] &  \\Gal(Y|X) \\ar[r] & 1\n    \\end{tikzcd}\n  \\end{equation*}\n  where the map $p_*$ is sending a loop $\\gamma$ in $Y$ to $p(\\gamma)$ and $M$ is the monodromy action.\n\\end{theorem}\n\nWe will assume the following for now without proof.\n\\begin{theorem}[Existence of universal cover]\n  For any space $X$, there exists a space $\\widetilde{X}$ with a covering map $P:\\widetilde{X} \\rightarrow X$ satisfying the following properties:\n  \\begin{enumerate}\n    \\item $P$ is Galois.\n    \\item $\\pi_1(\\widetilde{X})$ is trivial. (We say that $\\widetilde{X}$ is simply connected.)\n    \\item Every cover $Y$ of $X$ lies between $\\widetilde{X}$ and $X$.\n  \\end{enumerate}\n  Such a space $\\widetilde{X}$ is called the \\emph{universal cover} of $X$.\n\\end{theorem}\n\nSeveral corrolaries follow immediately from this statement.\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Classification of all covers}\n\n\n\n\\begin{proposition}\n  $\\Gal(\\widetilde{X} | X) \\cong \\pi_1(X,x)$.\n\\end{proposition}\n\\begin{proof}\n  Apply Theorem \\ref{theorem:fundamentalGroupQuotient2} to the cover $P:\\widetilde{X} \\rightarrow X$.\n\\end{proof}\n\n\\begin{theorem}[Galois correspondence \\#2]\n  \\label{theorem:GaloisCorrespondence2}\n  There is a 1-1 correspondence between the subgroups of $\\pi_1(X,x)$ and covers of $X$, given by the following maps\n  \\begin{align*}\n    \\{\\mbox{ subgroups of $\\pi_1(X,x)$ } \\} &\\longleftrightarrow  \\{\\mbox{ covers of $X$ } \\}\\\\\n    H &\\longmapsto \\widetilde{X}/H \\\\\n    \\pi_1(Z,z) & \\longmapsfrom Z\n  \\end{align*}\n  Under this correspondence, the normal subgroups of $\\pi_1(X,x)$ correspond to Galois covers of $X$.\n\\end{theorem}\n\n\n\n\n\n\n\\subsection{Subgroups of a free group}\nDenote by $F_n$ the free group with $n$ generators.\n\\begin{theorem}\n  Every subgroup of a finitely generated free group is free.\n\\end{theorem}\n\\begin{proof}\n  Let $G = \\mathrm{Free}(S)$ be a finitely generated free group with $|S|=k$.\n  Let $X$ be a wedge of $k$ circles, so that $\\pi_1(X) = G$.\n  \\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.5]\n     \\input{images/bouquet5.tex}\n    \\end{tikzpicture}\n    \\caption{Wedge of 5 circles $\\bigvee \\limits_5 S^1$ has fundamental group $F_5$.}\n  \\end{figure}\n  Every cover of $X$ is a graph, and the fundamental group of a graph is a free group (as there are no faces).\n  Hence, by Theorem \\ref{theorem:GaloisCorrespondence2} every subgroup of $G$ is free.\n\\end{proof}\n\n\n\n\n\n\n\n\\begin{theorem}\n  If $F_m \\triangleleft F_n$ then $n - 1 | m - 1$ and the index of $F_m$ inside $F_n$ is $(m-1)/(n-1)$.\n\\end{theorem}\n\\begin{proof}\n  A normal subgroup $H$ of $G$ corresponds to a Galois cover $X$ of $\\bigvee \\limits_n S^1$, of some degree, say $d$.\n  As $X$ is a cover, one can check by simple edge conting, that $X$ is free group on $(n-1)d + 1$ generators.\n  The result follows.\n\\end{proof}\n\n\n\n\n\n\n\n\n\n\\subsection{Universal property of the universal cover}\n\nWe say that a space $Y$ is simply connected if $\\pi_1(Y) \\cong \\set{\\mathbb{1}}$.\n\\begin{proposition}\n  Let $p:Y \\rightarrow X$ be a Galois cover such that $Y$ is simply-connected.\n  Further suppose that $p_2:Z \\rightarrow X$ is another cover then $Z$ is a subcover of $Y$.\n  \\begin{equation*}\n    \\begin{tikzcd}\n      Y \\ar[rd, dashed, \"\\exists\"] \\ar[dd, \"p\"']\\\\\n        & Z \\ar[ld,\"p_2\"] \\\\\n      X\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  We will explicitly construct a map $p_1: Y \\rightarrow Z$.\n  Pick vertices $y_0$ in $Y$, $x_0$ in $X$, and $z_0$ in $Z$ such that $p(y_0) = x_0 = p_2(z_0)$.\n  We define $p_1(y_0) = z_0$.\n\n  Let $y$ be a vertex in $Y$. Let $\\gamma$ be a path in $Y$.\n  We push down $\\gamma$ to X then lift it up to $X$ and set $p_1(y) = d_1 \\widetilde{p(\\gamma)}$.\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\gamma \\ar[dd, mapsto]\\\\\n        & \\widetilde{p(\\gamma)}  \\\\\n      p(\\gamma) \\ar[ur, mapsto]\n    \\end{tikzcd}\n  \\end{equation*}\n\n  We need to check that the map defined this way is well-defined i.e. it does not depend on the choice of the path $\\gamma$.\n  Suppose there are two paths $\\gamma_1$ and $\\gamma_2$ connecting $y_0$ to $y$.\n  Then $\\gamma_1^{-1} \\gamma_2$ is a loop at $y$ and hence is (upto conjugation) a boundary of a face.\n  It follows from this that the lifts of both $\\gamma_1$ and $\\gamma_2$ have the same endpoints.\n\\end{proof}\n\n\nAnd so a universal cover of $X$ is any cover $\\widetilde{X}$ of $X$ that is simply-connected.\nThere is a theorem of existence of the universal space of a general space, but in practice we simply construct these spaces by hand.\n\n\\begin{ex}\n  The universal cover of $S^1$ is $\\bbr^1$.\n\\end{ex}\n\n\\begin{ex}\n  The universal cover of a cylinder (and hence also a Mobius strip) is $\\bbr^1 \\times [0,1]$.\n\\end{ex}\n\n\\begin{ex}\n  The universal cover of a torus (and hence also a Klein bottle) is $\\bbr^2$.\n\\end{ex}\n\n\\begin{ex}\n  The universal cover of a real projective space is $S^2$.\n\\end{ex}\n\n\\begin{ex}\n  The universal cover of a bouquet of $k$ circles is the Cayley graph of the free group with $k$ generators.\n  \\begin{figure}[H]\n  \\centering\n    % \\includegraphics[width=0.5\\textwidth]{example-image}\n    \\includegraphics[width=0.5\\textwidth]{CayleyF2.png}\n    \\caption{Universal cover of $F_2$}\n  \\end{figure}\n\\end{ex}\n\n\\begin{ex}\n  A universal cover of a graph $X$ (space with no faces) can be constructed as follows:\n  \\begin{enumerate}\n    \\item Pick a vertex $x$.\n    \\item $\\widetilde{X}$ is a graph whose vertices are paths in $X$ that start at $x$.\n    \\item There is an edge from $\\gamma$ and $\\gamma'$ if $\\gamma = \\gamma' \\cdot e$ for some edge $e$.\n    \\item The covering map $P:\\widetilde{X} \\rightarrow X$ is the map $\\gamma \\mapsto d_1 \\gamma$.\n  \\end{enumerate}\n  \\begin{qbox}\n    Show that the $\\widetilde{X}$ defined above is a simply-connected space and that $P$ is a covering map, and hence $\\widetilde{X}$ is a universal cover.\n  \\end{qbox}\n  This method can be generalized to spaces with faces. In this case, instead of taking all paths we need to take equivalence classes of paths with respect to boundaries of faces.\n  \\begin{equation*}\n    \\widetilde{X}_x = \\set{ \\mbox{paths starting at } x} / \\mbox{faces}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{remark}\n  Finally, here is a comparison of the Galois correspondences for algebra and topology from Terrence Tao's blog \\cite{TerrenceTao}.\n  \\begin{figure}[H]\n  \\centering\n    \\includegraphics[width=0.8\\textwidth]{TerryTao1.png}\n    \\includegraphics[width=0.8\\textwidth]{TerryTao2.png}\n  \\end{figure}\n\n\\end{remark}\n\n\\begin{thebibliography}{9}\n\\bibitem{Szamuely}\nTam\\'as Szamuely, \\emph{Galois Groups and Fundamental Groups}, Cambridge Studies in Advanced Mathematics, 2007.\n\n\\bibitem{TerrenceTao}\nTerrence Tao, \\emph{Trying to understand the Galois correspondence},\\\\ \\url{https://terrytao.wordpress.com/2018/08/28/trying-to-understand-the-galois-correspondence/}.\n\\end{thebibliography}\n\n\n% In this section, we'll prove that for every (connected) space $Y$ and a vertex $y \\in Y$, there exists a simply-connected space $\\widetilde{Y}_y$ with a covering map\n% \\begin{align*}\n%   \\widetilde{Y}_y \\rightarrow Y\n% \\end{align*}\n%\n% By Theorem \\ref{theorem:liftingOfCovers} this cover is universal, in the sense that every cover $Z \\rightarrow Y$ lies between $\\widetilde{Y}_y$ and $Y$.\n% \\begin{equation*}\n%   \\begin{tikzcd}\n%     & Z \\ar[d] \\\\\n%     \\widetilde{Y}_y \\ar[ur,\"\\exists !\",dashrightarrow] \\ar[r, \"p'\"']& Y\n%   \\end{tikzcd}\n% \\end{equation*}\n%\n% The following lemmas are more or less true by definition.\n% \\begin{lemma}\n%   The fundamental group of a graph (=space with only vertices and edges) is a free group.\n% \\end{lemma}\n%\n% \\begin{lemma}\n%   Every cover of a graph is a graph.\n% \\end{lemma}\n", "meta": {"hexsha": "b8ddd8b496f8a7b8388b4ad3097de379c5042b87", "size": 8568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05.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": "05.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": "05.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": 35.5518672199, "max_line_length": 178, "alphanum_fraction": 0.6823062558, "num_tokens": 2828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.800691997339971, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.695662641369538}}
{"text": "The previous chapter developed a mathematical relationship between the position of a point $P$ in a scene (expressed in world frame coordinates $P_W$), and the corresponding point $p$ in pixel coordinates that gets projected onto the image plane of the camera. This relationship was derived based on the pinhole camera model, and required knowledge about the camera's intrinsic and extrinsic parameters. Nonetheless, even in the case where all of these camera parameters are known it is still impossible to reconstruct the depth of $P$ with a single image (without additional information).\nHowever, in the context of robotics, recovering 3D information about the structure of the robot's environment through computer vision is often a very important task (e.g. for obstacle avoidance). Two approaches for using cameras to gather 3D information are therefore presented in this chapter, namely \\textit{stereo vision} and \\textit{structure from motion}\\cite{SiegwartNourbakhshEtAl2011}\\cite{ForsythPonce2011}.\n\n\n\\notessection{Stereo Vision and Structure From Motion}\nRecovering scene structure from images is extremely important for mobile robots to safely operate in their environment and successfully perform tasks. While a number of other sensors can also be used to recover 3D scene information, such as ultrasonic sensors or laser rangefinders, cameras capture a broad range of information that goes beyond depth sensing. Additionally, cameras are a well developed technology and can be an attractive option for robotics based on cost or size.\n\nUnfortunately, unlike sensors that are specifically designed to measure depth like laser rangefinders, the camera's projection of 3D data onto a 2D image makes it impossible to gather some information from a single image\\footnote{Unless you are willing to make some strong assumptions, for example that you know the physical dimensions of the objects in the environment.}. Techniques for extracting 3D scene information from 2D images have therefore been developed that leverage \\textit{multiple} images of a scene. Examples of such techniques include \\textit{depth-from-focus} (uses images with different focuses), \\textit{stereo vision} (uses images from different viewpoints), or \\textit{structure from motion} (uses images captured by a moving camera).\n\n\n\\subsection{Stereo Vision}\nStereopsis (from \\textit{stereo} meaning solidity, and \\textit{opsis} meaning vision or sight) is the process in visual perception leading to the sensation of depth from two slightly different projections of the world onto the retinas of the two eyes. The difference in the two retinal images is called horizontal \\textit{disparity}, retinal disparity, or binocular disparity, and arise from the eyes' different positions in the head. It is the disparity that makes our brain fuse (perceive as a single image) the two retinal images, making us perceive the object as one solid object. For example, if you hold your finger vertically in front of you and alternate closing each eye you will see that the finger jumps from left to right. The distance between the left and right appearance of the finger is the disparity.\n\nComputational stereopsis, or \\textit{stereo vision}, is the process of obtaining depth information of a 3D scene via images from two cameras which look at the same scene from different perspectives. This process consists of two major steps: fusion and reconstruction. Fusion is a problem of correspondence, in other words how do you correlate each point in the 3D environment to their corresponding pixels in \\textit{each} camera. Reconstruction is then a problem of \\textit{triangulation}, which uses the pixel correspondences to determine the full position of the source point in the scene (including depth).\n\n\\subsubsection{Epipolar Constraints}\nAs previously mentioned, the first step in the stereo vision process is to fuse the two (or more) images and generate point correspondences\\footnote{This generally assumes that the perspective of each image is only a slight variation from the other, such that the features appear similarly in each.}. This task can be quite challenging, and erroneously matching features can lead to large errors in the reconstruction step. Therefore, several techniques are leveraged to make this task simpler. The most important simplifying technique is to impose an \\textit{epipolar constraint}.\n\n\\begin{figure}[ht]\n  \\begin{center}\n\t\\includegraphics[width=.8\\textwidth]{tex/figs/ch09_figs/stereo.png}\n  \\end{center}\n  \\caption{The point $P$ in the scene, the optical centers $O$ and $O'$ of the two cameras, and the two images $p$ and $p'$ of $P$ all lie in the same plane, referred to as the epipolar plane. The lines $l$ and $l'$ are the epipolar lines of the points $p$ and $p'$, respectively. Note that if the point $p$ is observed in one image, the corresponding point in the second image must lie on the epipolar line $l'$!}\n  \\label{fig:epi}\n\\end{figure}\n\nConsider the images $p$ and $p'$ of a point $P$ observed by two cameras with optical centers $O$ and $O'$ (see Figure \\ref{fig:epi}). These five points all belong to the \\textit{epipolar plane} defined by the two intersecting rays $OP$ and $O'P$. \nIn particular, the point $p$ lies on the line $l$ where the epipolar plane and the image plane intersect. The line $l$ is referred to as the \\textit{epipolar line} associated with the point $p$, and it passes through the point $e$ (referred to as the \\textit{epipole}).\nBased on this geometry, if $p$ and $p'$ are images of the same point $P$, then $p$ must lie on the epipolar line $l$ and $p'$ must lie on the epipolar line $l'$. \n\nTherefore, when searching for correspondences between $p$ and $p'$ for a particular point $P$ in the scene it makes sense to restrict the search to the corresponding epipolar line. This is referred to as an \\textit{epipolar constraint}, and greatly simplifies the correspondence problem by restricting the possible candidate points to a line rather than the entire image (i.e. a one dimensional search rather than a two dimensional search).\nMathematically, the epipolar constraints can be written as:\n\\begin{equation}\n\\overline{Op} \\cdot [\\overline{OO'} \\times \\overline{O'p'}] = 0, \n\\end{equation}\nsince $\\overline{Op}$, $\\overline{O'p'}$, and $\\overline{OO'}$ are coplanar. Assuming the world reference frame is co-located with camera 1 (with an origin at point $O$) this constraint can be written as:\n\\begin{equation} \\label{eq:epiconst}\n    p^\\top  F p'=0,\n\\end{equation}\nwhere $F$, referred to as the \\textit{fundamental matrix}, has seven degrees of freedom and is singular. For a derivation of the epipolar constraint see Section 7.1 from Forsyth et al.\\cite[]{ForsythPonce2011}. Additionally, the matrix $F$ is only dependent on the intrinsic camera parameters for each camera and the geometry that defines their relative positioning, and can be assumed to be constant. The expression for the fundamental matrix in terms of the camera intrinsic parameters is:\n\\begin{equation}\n    F = K^{-\\top}EK'^{-1}, \\quad E = \\begin{bmatrix}\n    0 & -t_3 & t_2 \\\\\n    t_3 & 0 & -t_1 \\\\\n    -t_2 & t_1 & 0\n    \\end{bmatrix}R,\n\\end{equation}\nwhere $K$ and $K'$ are the intrinsic parameter matrices for cameras 1 and 2 respectively, and $R$ and $t = [t_1, t_2, t_3]^\\top $ are the rotation matrix and translation vector that map camera 2 frame coordinates into camera 1 frame coordinates.\nNote that with the epipolar constraint defined by the fundamental matrix \\eqref{eq:epiconst}, the epipolar lines $l$ and $l'$ can be expressed by $l = Fp'$ and $l' = F^\\top p$. Additionally, it can be shown that $F^\\top e = Fe' = 0$ where $e$ and $e'$ are the epipoles in the image frames of cameras 1 and 2, since by definition the translation vector $t$ is parallel to the coordinate vectors of the epipoles in the camera frames. This in turn guarantees that the fundamental matrix $F$ is singular.\n\nIf the parameters $K$, $K'$, $R$, and $t$ are not already known, the fundamental matrix $F$ can be determined in a manner similar to the intrinsic parameter matrix $K$ in the previous chapter. Suppose a number of corresponding points $p^h = [u, v, 1]^\\top $ and $(p^h)'= [u',v',1]^\\top $ are known and are expressed as homogeneous coordinates. Each pair of points has to satisfy the epipolar constraint \\eqref{eq:epiconst}, which can be written as:\n\\begin{equation*}\n\\begin{bmatrix}\nu & v & 1\n\\end{bmatrix} \\begin{bmatrix}\nF_{11} & F_{12} & F_{13} \\\\\nF_{21} & F_{22} & F_{23} \\\\\nF_{31} & F_{32} & F_{33}\n\\end{bmatrix} \\begin{bmatrix}\nu' \\\\ v' \\\\ 1\n\\end{bmatrix} = 0    \n\\end{equation*}\nThis expression can then be equivalently expressed by reparameterizing the matrix $F$ in vector form $f$ as:\n\\begin{equation}\n\\begin{bmatrix}\nuu' & uv' & u & vu' & vv' & v & u' & v' & 1\n\\end{bmatrix}f = 0\n\\end{equation}\nwhere $f = [F_{11}, \\:F_{12} , \\: F_{13}, \\:F_{21}, \\:F_{22}, \\:F_{23}, \\:F_{31}, \\:F_{32}, \\:F_{33}]^\\top $. For $n$ known correspondences $(p,p')$ these constraints can be stacked to give:\n\\begin{equation}\n    Wf = 0,\n\\end{equation}\nwhere $W \\in \\R^{n \\times 9}$.\nGiven $n \\geq 8$ correspondences, an estimate $\\tilde{F}$ of the fundamental matrix estimate is given by:\n\\begin{equation} \\label{eq:fopt}\n\\begin{split}\n\\min_{f} \\:\\:& \\lVert Wf \\rVert^2, \\\\\n\\text{s.t.} \\:\\:& \\lVert f \\rVert^2 = 1.\n\\end{split}\n\\end{equation}\nNote that the estimate $\\tilde{F}$ computed by \\eqref{eq:fopt} is not guaranteed to be singular. A second step is therefore taken to enforce this additional condition. In particular it is desirable to find the matrix $F$ that is closest to the estimate $\\tilde{F}$ that has a rank of two:\n\\begin{equation}\n\\begin{split}\n   \\min_F \\:\\:& \\lVert F-\\tilde{F}\\rVert^2, \\\\\n\\text{s.t.} \\:\\:& \\text{det}(F) = 0,\n\\end{split}\n\\end{equation}\nwhich can be accomplished by computing a singular value decomposition of the matrix $\\tilde{F}$.\n\n\\subsubsection{Image Rectification}\nGiven a pair of stereo images, epipolar rectification is a transformation of each image plane such that all corresponding epipolar lines become colinear and parallel to one of the image axes, for convenience usually the horizontal axis. The resulting rectified images can be thought of as acquired by a new stereo camera obtained by rotating the original cameras about their optical centers. The great advantage of the epipolar rectification is the correspondence search becomes simpler and computationally less expensive because the search is done along the horizontal lines of the rectified images. The steps of the epipolar rectification algorithm are illustrated in Figure \\ref{fig:rect}. Observe that after the rectification, all the epipolar lines in the left and right image are colinear and horizontal.\nFor an in-depth discussion on algorithms for image rectification see \\cite{Fusiello2000}\\cite{LoopZhang1999}.\n\\begin{figure}[ht]\n  \\begin{center}\n\t\\includegraphics[width=0.7\\textwidth]{tex/figs/ch09_figs/rectification.png}  \\end{center}\n  \\caption{Epipolar rectification example from Loop et al. (1999).}\n  \\label{fig:rect}\n\\end{figure}\n\n\\subsubsection{Correspondence Problem}\nEpipolar constraints and image rectification are commonly used in stereo vision to address the problem of correspondence, which is the problem of determining the pixels $p$ and $p'$ from two different cameras with different perspectives that correspond to the same scene feature $P$. While these concepts make finding correspondences easier, there are still several challenges that must be overcome. These include challenges related to feature occlusions, repetitive patterns, distortions, and others.\n\n\\subsubsection{Reconstruction Problem}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{tex/figs/ch09_figs/triangulation.png}\n\\caption{Triangulation with rectified images (horizontal view on the left, top-down view on the right).}\n\\label{fig:recttri}\n\\end{figure}\nIn a stereo vision setup, once a correspondence between the two images is identified it is possible to reconstruct the 3D scene point based on \\textit{triangulation}. This process of triangulation has already been covered by the discussion on the epipolar geometry. However if the images have also be rectified such that the epipolar lines become parallel to the horizontal image axis the triangulation problem becomes simpler. This occurs, for example, when the two cameras have the same orientation, are placed with their optical axes parallel, and are separated by some distance $b$ called the \\textit{baseline} (see Figure \\ref{fig:recttri}).\n\nIn Figure \\ref{fig:recttri}, a point $P$ on the object is described as being at coordinate $(x,y,z)$ with respect to the origin located in the left camera at point $O$. The horizontal pixel coordinate in the left and right image are denoted by $p_u$ and $p'_u$ respectively. Based on the geometry the depth of the point $P$ can be computed from the properties of similar triangles:\n\\begin{align}\n  \\frac{z}{b} &= \\frac{z-f}{b-p_u+p'_u},\n\\end{align}\nwhich can be algebraically simplified to:\n\\begin{equation}\n    z = \\frac{bf}{p_u-p'_u},\n\\end{equation}\nwhere $f$ is the focal length. Generally a small baseline $b$ will lead to larger depth errors, but a large baseline $b$ may cause features to be visible from one camera but not the other. The difference in the image coordinates, $p_u-p'_u$, is referred to as \\textit{disparity}. This is an important term in stereo vision, because it is only by measuring disparity that depth information can be recovered. The disparity can also be visually represented in a \\textit{disparity map} (for example see Figure \\ref{fig:disparity}), which is simply a map of the disparity values for each pixel in an image. The largest disparities occur from nearby objects (i.e. since disparity is inversely proportional to $z$).\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=0.95\\textwidth]{tex/figs/ch09_figs/disparitymap.png}\n\\caption{Disparity map from a pair of stereo images. Notice that the lighter values of the disparity map represent larger disparity, and correspond to the point in the scene that are closer to the cameras. The black points represent points that were occluded from one of the images and therefore no correspondence could be made. Images from Scharstein et al. (2003) \\nocite{ScharsteinSzeliski2003}.}\n\\label{fig:disparity}\n\\end{figure}\n\n\\subsection{Structure From Motion (SFM)}\nThe structure from motion (SFM) method uses a similar principle as stereo vision, but uses \\textit{one} camera to capture multiple images from different perspectives while moving within the scene. In this case, the intrinsic camera parameter matrix $K$ will be constant, but the extrinsic parameters (i.e. the rotation matrix $R$ and relative position vector $t$) will be different for each image.\n\\begin{figure}[ht]\n  \\begin{center}\n\t\\includegraphics[width=0.75\\textwidth]{tex/figs/ch09_figs/sfm.png}  \\end{center}\n  \\caption{A depiction of the structure from motion (SFM) method. A single camera is used to take multiple images from different perspectives, which provides enough information to reconstruct the 3D scene.}\n  \\label{sfm}\n\\end{figure}\nConsider a case where $m$ images of $n$ fixed 3D points are taken from different perspectives. This would involve $m$ homography matrices $M_k$ and $n$ 3D points $P_j$ that would need to be determined by leveraging the relationships:\n\\begin{equation*}\n    p_{j,k}^h = M_k P^h_j, \\quad j = 1,\\dots,n, \\quad k=1,\\dots,m.\n\\end{equation*}\n\nHowever, SFM also has some unique disadvantages, such as an ambiguity in the absolute scale of the scene that cannot be determined. For example a bigger object at a longer distance and a smaller object at a closer distance may yield the same projections.\n\nOne application of the SFM concept is known as \\textit{visual odometry}. Visual odometry estimates the motion of a robot by using visual inputs (and possible additional information). This approach is commonly used in practice, for example by rovers on Mars, and is useful because it not only allows for 3D scene reconstruction but also to recover the motion of the camera.\n", "meta": {"hexsha": "a2c497e9d4cb23021a69cf3f8cfb348a76a21d1e", "size": 16095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch09.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/ch09.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/ch09.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": 111.0, "max_line_length": 817, "alphanum_fraction": 0.7707362535, "num_tokens": 4077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.695606279399351}}
{"text": "\\subsection{Exponential separation of $\\braket{X}$-Isomorphism-QMDD}\n\nIn this section, we separate $\\braket{X}$-Isomorphism-QMDD from QMDD by giving a quantum state which requires $2^{\\Omega(\\sqrt{n})}$ as a QMDD, but has an $\\braket{X}$-Isomorphism-QMDD with only $\\mathcal O(n)$ nodes.\nBy $\\braket{X}$-Isomorphism-QMDD, we mean that the only isomorphisms that are allowed to appear on the diagram's Isomorphism nodes are of the form $A_1\\otimes\\cdots\\otimes A_n$ where $A_i$ is either $I=\\begin{smallmat}1 & 0 \\\\ 0 & 1\\end{smallmat}$ or $X=\\begin{smallmat}0 & 1 \\\\ 1 & 0\\end{smallmat}$.\n\nDuris et al. show the following lower bound on the size of nondeterministic branching programs.\n\\begin{theorem}[\\v{D}uri\\v{s} et al.\\cite{vdurivs2004multi}]\n\t\\label{thm:random-vector-space-hard-for-bdd}\n\tThe characteristic function $f_V$ of a randomly chosen vector space $V$ in $\\mathbb F_2^n$ needs a (non-) deterministic branching program of size $2^{\\Omega(n)}/(2n)$ with high probability.\n\\end{theorem}\nFor us, it suffices to use the fact that the bound holds for deterministic branching programs, because it implies the following.\n% this means that the uniform superposition over $A_n$ is a quantum state which has a large QMDD.\n\\begin{theorem}\n\tFor a random vector space $S\\subseteq \\{0,1\\}^n$, the uniform superposition $\\ket{S}$ has QMDDs of size $2^{\\Omega(n)}/(2n)$, with\n\t\\begin{align}\n\t\t\\ket{S}= \\frac{1}{\\sqrt{|S|}} \\sum_{x\\in S}\\ket{x}\n\t\\end{align}\n\\end{theorem}\n\\begin{proof}[Proof sketch]\n\tThe idea is that BDDs are QMDDs taking values in $\\{0,1\\}$.\n\tConversely, whenever the amplitudes of a state $\\ket{\\phi}$ have values only in $\\{0,z\\}$ for some $z\\in \\mathbb C$, then, up to a phase, we have $\\ket{\\phi}=\\ket{S}$, for some set of bitstrings $S\\subseteq\\{0,1\\}^n$.\n\tIn this case, the QMDD has the same structure as the BDD of the indicator function $f_S$, namely, the weights on its edges are all in $\\{0,1\\}$, and they have the same number of nodes.\n\tBy taking $S$ to be a random vector space, the result follows from \\autoref{thm:random-vector-space-hard-for-bdd} because all BDDs are branching programs.\n\\end{proof}\n\nOn the other hand, these states are compactly represented by $\\braket{X}$-Isomorphism QMDDs, because they are stabilizer states.\nFor context, we note that the theorem proved by \\v{D}uri\\v{s} et al. is much stronger than what we need.\nNamely, they show that, even if the qubits do not need to be ordered, and even if the diagram is allowed to flip nondeterministic coins, then it still holds that almost all vector spaces have exponential-size diagrams.\n\n\\paragraph{Vector spaces and stabilizer states}\nA \\emph{vector space} of $\\{0,1\\}^n$ is a set $S\\subseteq\\{0,1\\}^n$ which contains the bitstring $0\\in S$, and is closed under bitwise XOR, i.e., for each $a,b\\in S$, it holds that $(a\\oplus b)\\in S$.\nEach vector space has a basis, and has exactly $2^k$ elements for some $1\\leq k\\leq n$.\nThe uniform superposition over $S$ is the $n$-qubit state $\\ket{S}_n$,\n\\begin{align}\n\t\\ket{S}_n =\\frac{1}{\\sqrt{|S|}} \\sum_{x\\in S}\\ket{x}\n\\end{align}\n\\begin{theorem}\nIf $S$ is a vector space, then $\\ket{S}$ is a stabilizer state.\n\\end{theorem}\n\\begin{proof}\n\tFor $n=1$, the statement holds trivially.\n\t\n\tFor $n>1$, \n\t\n\t(Zelf denk ik dat de volgende route het snelst is: Een vector space bestaat uit de oplossingen van een stelsel lineaire vergelijkingen. Neem de eerste variabele, $x_1$. Dan kan je kijken naar $x_1:=0$ en $x_1:=1$, en dan krijg je weer twee stelsels lineaire vergelijkingen. Maar die zijn \"hetzelfde\", als ze allebei oplossingen hebben, namelijk de ene krijg je door de oplossingen van de ander te XORen met een slim gevonden bitstring. Deze uitleg is heel slecht).\n\\end{proof}", "meta": {"hexsha": "2209b08185b9285cf068b8ae11186d2297206af3", "size": 3718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Src/CS/sections/X_iso_qmdd_lower_bound_2.tex", "max_stars_repo_name": "Katafotic/latex_parsing", "max_stars_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Src/CS/sections/X_iso_qmdd_lower_bound_2.tex", "max_issues_repo_name": "Katafotic/latex_parsing", "max_issues_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/CS/sections/X_iso_qmdd_lower_bound_2.tex", "max_forks_repo_name": "Katafotic/latex_parsing", "max_forks_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.8260869565, "max_line_length": 465, "alphanum_fraction": 0.7286175363, "num_tokens": 1186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6955981580932928}}
{"text": "%---------------------------Edge Ratio-----------------------------\n\\section{Edge Ratio}\n\nThe edge ratio of a triangle is: \n\\[\n\\frac{L_{\\max}}{L_{\\min}}.\n\\]\n\n\\trimetrictable{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$}%                                      Square\n{\\cite{pebay:03}}%                          Citation\n{v\\_tri\\_edge\\_ratio}%                            Verdict function name\n\n", "meta": {"hexsha": "f4cc465fe3a3395f4ac10b14c7c7067834f5e37d", "size": 591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriEdgeRatio.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/TriEdgeRatio.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/TriEdgeRatio.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.8333333333, "max_line_length": 71, "alphanum_fraction": 0.358714044, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6955760852160159}}
{"text": "\\subsection{Probability Calculation}\r\n\\def\\E{\\mathbb{E}}\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n  \\begin{columns}\r\n    \\begin{column}{0.65\\textwidth}\r\n      \\begin{itemize}\r\n        \\item<2->\r\n          We just discuss the discrete case\r\n        \\item<3->\r\n          Probability space {\\color{MainA}$\\Omega$} with {\\color{MainA}elementary (simple) events}\r\n        \\item<4->\r\n          Events {\\color{MainA}$e$} have probabilities $\\ldots$\\\\\r\n          {\\color{MainA}\\[\\sum_{e \\in \\Omega} P(e) = 1\\]}\r\n        \\item<5->\r\n          The probability for a subset of events\r\n          {\\color{MainA}$E \\subseteq \\Omega$} is\r\n          {\\color{MainA}\\[P(E) = \\sum_{e \\in E} P(e) \\mid e \\in E\\]}\r\n      \\end{itemize}\r\n    \\end{column}\r\n    \\begin{column}{0.35\\textwidth}\r\n      \\onslide <6->\r\n      \\begin{table}[!h]\r\n        \\caption{throwing a dice}\r\n        \\label{tab:probabilities:rolling_dice}\r\n        \\begin{tabularx}{0.5\\linewidth}{c|c}\r\n          {\\color{MainA}$e$} & {\\color{MainA}$P(e)$}\\\\\r\n          \\midrule\r\n          1 & $\\sfrac{1}{6}$\\\\\r\n          2 & $\\sfrac{1}{6}$\\\\\r\n          3 & $\\sfrac{1}{6}$\\\\\r\n          4 & $\\sfrac{1}{6}$\\\\\r\n          5 & $\\sfrac{1}{6}$\\\\\r\n          6 & $\\sfrac{1}{6}$\\\\\r\n        \\end{tabularx}\r\n      \\end{table}\r\n    \\end{column}\r\n  \\end{columns}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n  \\begin{columns}\r\n    \\begin{column}{0.65\\linewidth}\r\n      \\textbf{Example:}\r\n      \\begin{itemize}\r\n        \\item<2->\r\n          Rolling a dice twice ({\\color{MainA}$\\Omega = \\{1,\\dots,6\\}^2$})\r\n        \\item<3->\r\n          Each event {\\color{MainA}$e \\in \\Omega$} has the probability\r\n          {\\color{MainA}$P(e) = \\sfrac{1}{36}$}\r\n        \\item<4->\r\n          {\\color{MainA}$E =$} if both results are even,\r\n          then {\\color{MainA}$P(E)=$}\r\n      \\end{itemize}\r\n    \\end{column}\r\n    \\onslide<3->\r\n    \\begin{column}{0.35\\linewidth}\r\n      \\begin{table}[!h]\r\n        \\caption{throwing a dice twice}\r\n        \\label{tab:probabilities_rolling_dice_twice}\r\n        \\begin{tabularx}{0.8\\linewidth}{c|c}\r\n          {\\color{MainA}$e$} & {\\color{MainA} $P(e)$}\\\\\r\n          \\midrule\r\n          $(1, 1)$ & $\\sfrac{1}{36}$\\\\\r\n          $(1, 2)$ & $\\sfrac{1}{36}$\\\\\r\n          $(1, 3)$ & $\\sfrac{1}{36}$\\\\\r\n          $\\dots$ & $\\dots$\\\\\r\n          $(6, 5)$ & $\\sfrac{1}{36}$\\\\\r\n          $(6, 6)$ & $\\sfrac{1}{36}$\\\\\r\n        \\end{tabularx}\r\n      \\end{table}\r\n    \\end{column}\r\n  \\end{columns}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n  \\begin{columns}\r\n    \\begin{column}{0.55\\linewidth}\r\n      \\textbf{Example:}\r\n      \\begin{itemize}\r\n      \\setlength\\itemsep{1em}\r\n      \\item<1->\r\n        Random variable\r\n        \\begin{itemize}\r\n        \\item<2->\r\n          Assigns a number to the result of an experiment\r\n        \\item<3->\r\n          For example: {\\color{MainA}$X =$}\r\n          Sum of results for rolling twice\r\n        \\item<4->\r\n          {\\color{MainA}$X = 12$} and {\\color{MainA}$X \\geq 7$}\r\n          are regarded as events\r\n        \\item<5->\r\n          Example 1: {\\color{MainA}$P(X = 2) = $}\r\n        \\item<6->\r\n          Example 2: {\\color{MainA}$P(X = 4) = $}\r\n        \\end{itemize}\r\n      \\end{itemize}\r\n    \\end{column}\r\n    \\onslide<4->\r\n    \\begin{column}{0.45\\linewidth}\r\n      \\begin{table}[!h]\r\n        \\caption{throwing a dice twice}\r\n        \\label{tab:probabilities:rolling_dice_twice2}\r\n        \\begin{tabularx}{0.95\\linewidth}{c|cc}\r\n          {\\color{MainA}$e$} & {\\color{MainA}$P(e)$} &\r\n          {\\color{MainA}$X$}\\\\\r\n          \\midrule\r\n          $(1, 1)$ & $\\sfrac{1}{36}$ & 2\\\\\r\n          $(1, 2)$ & $\\sfrac{1}{36}$ & 3\\\\\r\n          $(1, 3)$ & $\\sfrac{1}{36}$ & 4\\\\\r\n          $\\dots$ & $\\dots$ & $\\dots$\\\\\r\n          $(6, 5)$ & $\\sfrac{1}{36}$ & 11\\\\\r\n          $(6, 6)$ & $\\sfrac{1}{36}$ & 12\\\\\r\n        \\end{tabularx}\r\n      \\end{table}\r\n    \\end{column}\r\n  \\end{columns}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n%% \\begin{frame}{Universal Hashing}{Probability Calculation}\r\n%%   \\begin{columns}\r\n%%     \\begin{column}{0.55\\linewidth}\r\n%%       \\textbf{Example:}\r\n%%       \\vspace{1em}\r\n%%       \\begin{itemize}\r\n%%         \\item\r\n%%           {\\color{MainA}$E = \\{e_{(i,\\,j)} \\in \\Omega\r\n%%           \\mid X \\;\\mathrm{mod}\\; 2 = 0\\}$}\\\\\r\n%%           {\\color{MainA}$P(E) =$}\r\n%%       \\end{itemize}\r\n%%     \\end{column}\r\n%%     \\begin{column}{0.45\\linewidth}\r\n%%       \\begin{table}[!h]\r\n%%         \\caption{Throwing a dice twice}\r\n%%         \\label{tab:probabilities:rolling_dice_twice3}\r\n%%         \\begin{tabularx}{0.95\\linewidth}{c|cc}\r\n%%           {\\color{MainA}$e_{(i,\\,j)}$} & {\\color{MainA}$P(e_{(i,\\,j)})$} &{\\color{MainA} $X = i + j$}\\\\\r\n%%           \\midrule\r\n%%           $(1, 1)$ & $\\sfrac{1}{36}$ & 2\\\\\r\n%%           $(1, 2)$ & $\\sfrac{1}{36}$ & 3\\\\\r\n%%           $(1, 3)$ & $\\sfrac{1}{36}$ & 4\\\\\r\n%%           $\\dots$ & $\\dots$ & $\\dots$\\\\\r\n%%           $(6, 5)$ & $\\sfrac{1}{36}$ & 11\\\\\r\n%%           $(6, 6)$ & $\\sfrac{1}{36}$ & 12\\\\\r\n%%         \\end{tabularx}\r\n%%       \\end{table}\r\n%%     \\end{column}\r\n%%   \\end{columns}\r\n%% \\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n  \\onslide<1->\r\n  \\textbf{Expected value} is defined as  {\\color{MainA}$\\E(X)  = \\sum \\left(k \\cdot P(X = k)\\right)$}\r\n  \\vspace*{0em}\r\n  \\begin{itemize}\r\n    \\item <2->\r\n      Intuitive: the weighted average of possible values of {\\color{MainA}$X$}, where\r\n      the weights are the probabilities of the values\r\n  \\end{itemize}\r\n  \\vspace*{-1.0em}\r\n  \\onslide <3->\r\n \\begin{columns}\r\n   \\begin{column}{0.5\\linewidth}\r\n     \\begin{table}[!h]\r\n       \\small{\r\n     \\caption{throwing a dice once}\r\n    \\label{tab:probabilities:value_rolling_dice_once}\r\n    \\begin{tabularx}{0.25\\linewidth}{c|cc}\r\n      {\\color{MainA}$X$} & {\\color{MainA}$P(X)$}\\\\\r\n      \\midrule\r\n      1 & $\\sfrac{1}{6}$\\\\\r\n      2 & $\\sfrac{1}{6}$\\\\\r\n      3 & $\\sfrac{1}{6}$\\\\\r\n      4 & $\\sfrac{1}{6}$\\\\\r\n      5 & $\\sfrac{1}{6}$\\\\\r\n      6 & $\\sfrac{1}{6}$\\\\\r\n    \\end{tabularx}}\r\n  \\end{table}  \r\n   \\end{column}\r\n   \\begin{column}{0.5\\linewidth}\r\n     \\begin{table}[!h]\r\n       \\small{\r\n    \\caption{throwing a dice twice}\r\n    \\label{tab:probabilities:value_rolling_dice_twice}\r\n    \\begin{tabularx}{0.275\\linewidth}{c|cc}\r\n      {\\color{MainA}$X$ }&{\\color{MainA} $P(X)$}\\\\\r\n      \\midrule\r\n      2 & $\\sfrac{1}{36}$\\\\\r\n      3 & $\\sfrac{2}{36}$\\\\\r\n      4 & $\\sfrac{3}{36}$\\\\\r\n      $\\dots$ & $\\dots$\\\\\r\n      11 & $\\sfrac{2}{36}$\\\\\r\n      12 & $\\sfrac{1}{36}$\\\\\r\n    \\end{tabularx}}\r\n   \\end{table}\r\n   \\end{column}\r\n \\end{columns}\r\n \\begin{itemize}\r\n \\vspace*{-1.0em}\r\n \\item<4-> Example \"rolling once\": \\onslide<5->\r\n  {\\color{MainA}$\\E(X) = 1 \\cdot \\frac{1}{6} + 2 \\cdot \\frac{1}{6}\r\n    + \\dots + 6 \\cdot \\frac{1}{6} = 3.5$}\r\n \\item<6-> Example \"rolling twice\": \\rlap{\\onslide<7->{\\color{MainA}$\\E(X) = 2 \\cdot \\frac{1}{36} + 3 \\cdot \\frac{2}{36}    + \\dots + 12 \\cdot \\frac{1}{36} = 7$}}\r\n   \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n%% \\begin{frame}{Universal Hashing}{Probability Calculation}\r\n%%   \\textbf{Expected value:}\r\n%%   {\\color{MainA}\\[E(X)\r\n%%     = \\sum \\left(k \\cdot P(X = k)\\right)\\]}\r\n%%   \\begin{itemize}\r\n%%     \\item\r\n%%       The weighted average of all possible resulting values {\\color{MainA}$X$}\r\n%%     \\item\r\n%%       The weight factor is the result value {\\color{MainA}$X$} itself\r\n%%   \\end{itemize}\r\n%% \\end{frame}\r\n\r\n%% %-------------------------------------------------------------------------------\r\n\r\n%% \\begin{frame}{Universal Hashing}{Probability Calculation}\r\n%%   \\vspace*{-1.5em}\r\n%%   \\begin{table}[!h]\r\n%%     \\caption{Throwing a dice once}\r\n%%     \\label{tab:probabilities:value_rolling_dice_once}\r\n%%     \\begin{tabularx}{0.25\\linewidth}{c|cc}\r\n%%       {\\color{MainA}$X$} & {\\color{MainA}$P(X)$}\\\\\r\n%%       \\midrule\r\n%%       1 & $\\sfrac{1}{6}$\\\\\r\n%%       2 & $\\sfrac{1}{6}$\\\\\r\n%%       3 & $\\sfrac{1}{6}$\\\\\r\n%%       4 & $\\sfrac{1}{6}$\\\\\r\n%%       5 & $\\sfrac{1}{6}$\\\\\r\n%%       6 & $\\sfrac{1}{6}$\\\\\r\n%%     \\end{tabularx}\r\n%%   \\end{table}\r\n%%   \\onslide<1>\r\n%%   Throwing the dice once:\r\n%%   {\\color{MainA}\\[E(X) = 1 \\cdot \\frac{1}{6} + 2 \\cdot \\frac{1}{6}\r\n%%     + \\dots + 6 \\cdot \\frac{1}{6} = 3.5\\]}\r\n%% \\end{frame}\r\n\r\n%% %-------------------------------------------------------------------------------\r\n\r\n%% \\begin{frame}{Universal Hashing}{Probability Calculation}\r\n%%   \\vspace*{-1.5em}\r\n%%   \\begin{table}[!h]\r\n%%     \\caption{Throwing a dice twice}\r\n%%     \\label{tab:probabilities:value_rolling_dice_twice}\r\n%%     \\begin{tabularx}{0.275\\linewidth}{c|cc}\r\n%%       {\\color{MainA}$X$ }&{\\color{MainA} $P(X)$}\\\\\r\n%%       \\midrule\r\n%%       2 & $\\sfrac{1}{36}$\\\\\r\n%%       3 & $\\sfrac{2}{36}$\\\\\r\n%%       4 & $\\sfrac{3}{36}$\\\\\r\n%%       $\\dots$ & $\\dots$\\\\\r\n%%       11 & $\\sfrac{2}{36}$\\\\\r\n%%       12 & $\\sfrac{1}{36}$\\\\\r\n%%     \\end{tabularx}\r\n%%   \\end{table}\r\n%%   Throwing the dice twice:\r\n%%   {\\color{MainA}\\[E(X) = 2 \\cdot \\frac{1}{36} + 3 \\cdot \\frac{2}{36}\r\n%%     + \\dots + 12 \\cdot \\frac{1}{36} = 7\\]}\r\n%% \\end{frame}\r\n\r\n%% %-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n   \\textbf{Sum of expected values:}\r\n   for arbitrary discrete random variables {\\color{MainA}$X_1,\\dots,X_n$} we can write:\r\n     {\\color{MainA}\\[\\E\\left(X_1+\\dots+X_n\\right)\r\n       = \\E(X_1) + \\dots + \\E(X_n)\\]}\r\n   \\onslide<2->\r\n   \\textbf{Example:} throwing two dice\r\n   \\begin{itemize}\r\n     \\item<3->\r\n       {\\color{MainA}$X_1$}: result of dice {\\color{MainA}$1$}: {\\color{MainA}$\\E(X_1) = 3.5$}\r\n     \\item<4->\r\n       {\\color{MainA}$X_2$}: result of dice {\\color{MainA}$2$}: {\\color{MainA}$\\E(X_2) = 3.5$}\r\n     \\item<5->\r\n       {\\color{MainA}$X = X_1 + X_2$}:  total number\r\n     \\item<5-> Expected number when rolling two dices: \r\n       {\\color{MainA}\\[\\E(X)\r\n         = \\E(X_1 + X_2)\r\n         = \\E(X_1) + \\E(X_2) = 3.5 + 3.5 = 7\\]}\r\n   \\end{itemize}\r\n\\end{frame}\r\n\r\n%% %-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n  \\onslide<1->\r\n  \\begin{block}{Corollary:}\r\n    The probability of the event $E$ is $p = P(E)$.\r\n    Let $X$ be the occurences of the event $E$ and $n$ be the number\r\n    of executions of the experiment. Then {\\color{MainA}$\\E(X) = n \\cdot P(E) = n \\cdot p$}\r\n  \\end{block}\r\n  \\onslide<2->\r\n  \\begin{example}[Rolling the dice 60 times]\r\n    \\[\\E\\left(\\text{occurences of 6}\\right) = \\frac{1}{6} \\cdot 60 = 10\\]\r\n  \\end{example}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Probability Calculation}\r\n  \\begin{proof}[Proof Corollary:]\r\n    Indicator variable: $X_i$\\\\\r\n    \\vspace*{-1.5em}\r\n    \\onslide<2->\r\n    \\begin{align*}\r\n      X_i &=\r\n        \\left\\lbrace\r\n          \\begin{array}{ll}\r\n            1, & \\text{if event occurs}\\\\\r\n            0, & \\text{else}\r\n          \\end{array}\r\n          \\right. \\hspace{1.5em}\\\\\r\n        \\Rightarrow \\; X = \\sum_{i=1}^{n} X_i\r\n    \\end{align*}\r\n    \\vspace*{-1.0em}\r\n    \\onslide<3->\r\n    \\begin{align*}\r\n      \\E(X) &= \\E\\left(\\sum_{i=1}^{n} X_i\\right)\r\n        = \\sum_{i=1}^{n} \\E(X_i)\r\n        \\stackrel{\\text{def. $\\E$-value}}{=}\r\n        \\sum_{i=1}^{n} p = n \\cdot p\r\n    \\end{align*}\r\n    \\qedhere\r\n    \\onslide<4->\r\n    \\vspace*{-1.0em}\r\n    \\begin{align*}\r\n        \\text{Def. $\\E$-value: }  \\E(X_i) &= \\; 0 \\cdot P(X_i = 0) + 1 \\cdot P(X_i = 1) &= \\; P(X_i = 1) \\\\[0.5em]   \r\n    \\end{align*}\r\n  \\end{proof}\r\n\\end{frame}\r\n", "meta": {"hexsha": "41670731bc87cfee3937f6a79108f5c04c548b1d", "size": 11893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-5/Chapter/eng/040_ProbabilityCalculation.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/040_ProbabilityCalculation.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/040_ProbabilityCalculation.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.3728323699, "max_line_length": 163, "alphanum_fraction": 0.4658202304, "num_tokens": 4121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6955760795522917}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Vector-Valued Functions}\n        \\begin{definition}{Vector-Valued Functions}{}\n                A vector valued function is a function \\(\\vec{r}:I \\to \\mathbb{R}^n\\), where \\(I \\subseteq \\mathbb{R}\\). A vector valued function in \\(\\mathbb{R}^3\\) may be written in the form\n                \\[\n                \\vec{r}(t)=x(t)\\i + y(t)\\j + z(t)\\k\n                \\]\n        \\end{definition}\n        \\begin{definition}{Continuity}{}\n                A vector valued function \\(\\vec{r}(t)=x(t)\\i + y(t)\\j + z(t)\\k\n\\) is \\emph{continuous} on \\(I\\) if and only if \\(x(t)\\), \\(y(t)\\), and \\(z(t)\\) are all continuous on \\(I\\).\n        \\end{definition}\n        \\begin{definition}{Velocity \\& Acceleration}{}\n                Given some vector valued function \\(\\vec{r}(t)\\), there exists a corresponding \\emph{velocity} \\(\\vec{v}(t)\\) equal to \\(\\vec{r}'(t)\\) and a corresponding \\emph{acceleration} \\(\\vec{a}(t)\\) equal to \\(\\vec{r}''(t)\\), or equivalently \\(\\vec{v}'(t)\\). The magnitude of \\(\\vec{v}(t)\\) is a scalar quantity sometimes called the \\emph{speed} of \\(\\vec{r}\\).\n        \\end{definition}\n        A stright line is described by the parameterization\n        \\begin{equation*}\n                \\vec{r}(t)=\\vec{r}_0 + t\\vec{v}\n        \\end{equation*}\n        but may also be equivalently parameterized like\n        \\begin{equation*}\n                \\vec{r}(t)=\\vec{r}_0 + 2t\\vec{v}\n        \\end{equation*}\n        which describes the same curve, but has a different velocity. Generally, the parameterization of a curve is not unique.\n        \n        A helix is descibed by the parameterization\n        \\begin{equation*}\n                \\vec{r}(t) = \\cos{t}\\i + \\sin{t}\\j + t\\k\n        \\end{equation*}\n        which corresponds to uniform circular motion in the x-y plane coupled with downward motion in the z direction with constant velocty, resulting in a curve with a helical shape. \\(z(t)\\) may be modified to change the ``compression\" of the helix. For instance,\n        \\begin{equation*}                        \n                \\vec{r}(t) = \\cos{t}\\i + \\sin{t}\\j + t^3\\k\n        \\end{equation*}\n        is much less compressed at large values of \\(z\\), and highly compressed near \\(0\\).\n        \\begin{example}{}{}\n        Parameterize the curve of intersection of \\(x^2+y^2=9\\) with \\(z = x + y\\).\n        \\tcblower\n        In the x-y plane, the path is circular, so we have\n        \\begin{align*}\n                x &= 3\\cos{t}\\\\\n                y &= 3\\sin{t}\n        \\end{align*}\n        and due to the fact that the curve lies on the surface \\(z = x + y\\), it must be that\n        \\[z = 3\\cos{t} + 3\\sin{t}\\]\n        which is a parameterization on the interval \\([0,2\\pi]\\).\n        \\end{example}\n        \\begin{example}{}{}\n        Parameterize the intersection of \\(z = x^2 + y^2\\) and \\(x = 2y\\).\n        \\tcblower\n        The intersection of these curves is a parabola, so we may simply set\n        \\[y=t\\]\n        which then yields equations for \\(x\\) and \\(z\\)\n        \\begin{align*}\n                x &= 2t\\\\\n                z &= 5t^2\n        \\end{align*}\n        \\end{example}\n        \\begin{definition}{Differentiation Rules}{}\n                The differentiation of vector valued functions proceeds by differentiating each of the components, so the normal rules of differentiation apply, namely\n                \\[(\\vec{u}+\\vec{v})' = \\vec{u}' + \\vec{v}'\\]\n                \\[(\\vec{u}\\cdot\\vec{v})' = \\vec{u}'\\cdot\\vec{v}+\\vec{u}\\cdot\\vec{v}'\\]\n                and similarly for the cross product\n                \\[(\\vec{u}\\times\\vec{v})' = \\vec{u}'\\times\\vec{v}+\\vec{u}\\times\\vec{v}'\\]\n        \\end{definition}\n\\end{document}\n", "meta": {"hexsha": "be38e47632883cbfe931c7b104d404722a7cfbc6", "size": 3715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_1.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_1.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_1.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": 54.6323529412, "max_line_length": 368, "alphanum_fraction": 0.5518169583, "num_tokens": 1113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.80563219364797, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.6955760753044984}}
{"text": "\\section{The Dirac Delta Function}\r\n\\subsection{Definition}\r\nWe want to define a generalised function $\\delta(x-\\xi)$ with the following properties:\r\n$$\\forall x\\neq\\xi,\\delta(x-\\xi)=0,\\int_{-\\infty}^\\infty\\delta(x-\\xi)\\,\\mathrm dx=1$$\r\nSo $\\delta(x-\\xi)$ can be thought as a ``function'' with an infinite spike at $x=\\xi$.\r\nOf course, it would be ridiculous to use it really as a function.\r\nAlmost always, we use it in conjunction with an integral, so we can take it as a linear operator having the property that\r\n$$\\left( \\int_{-\\infty}^\\infty\\mathrm dx\\,\\delta(x-\\xi) \\right)f(x)=\\int_{-\\infty}^\\infty\\delta(x-\\xi)f(x)\\,\\mathrm=f(\\xi)$$\r\n\\begin{note}\r\n    The $\\delta$ function is some sort of ``generalised function'', or ``distribution'' which admits rigorous mathematical formulation.\r\n    However, this will not be discussed here.\r\n\\end{note}\r\nWe want the $\\delta$ function to represent a unit point source or an impulse in physical situations.\r\nLoosely, we can take $\\delta$ as the ``limit'' of a family of well-defined functions.\r\nFor example, we can consider\r\n$$\\delta_\\epsilon(x)=\\frac{1}{\\epsilon\\sqrt{\\pi}}\\exp\\left( -\\frac{x^2}{\\epsilon^2} \\right)$$\r\nSo we can interpret $\\delta$ as saying\r\n$$\\int_{-\\infty}^\\infty\\delta(x)f(x)\\,\\mathrm dx=\\lim_{\\epsilon\\to 0}\\int_{-\\infty}^\\infty\\delta_\\epsilon(x)f(x)\\,\\mathrm dx=f(0)$$\r\nwhich, as one can verify, works for sufficiently nice $f$.\r\nThis is known as the Gaussian approximation.\r\nThere are some other (discrete) choices of $\\delta$ too, for example,\r\n$$\\delta_n(x)=\\frac{n}{2}1_{|x|\\le 1/n},\\delta_n(x)=\\frac{\\sin(nx)}{\\pi x}=\\frac{1}{2\\pi}\\int_{-n}^ne^{ikx}\\,\\mathrm dk,\\delta_n(x)=\\frac{n}{2}\\operatorname{sech}^2(nx)$$\r\n\\subsection{Properties}\r\nWe interpret the integral of $\\delta$ to be the Heaviside function\r\n$$H(x)=\\begin{cases}\r\n    1\\text{, for $x\\ge 0$}\\\\\r\n    0\\text{, for $x<0$}\r\n\\end{cases}=\\int_{-\\infty}^x\\delta(t)\\,\\mathrm dt$$\r\nOne can verify that the integral of $\\delta_n(x)=n\\operatorname{sech}^2(x)/2$, that is $(\\tanh(nx)+1)/2$, tends to $H(x)$ as $n\\to\\infty$.\\\\\r\nWe are gonna do something more sacrilegeous, that would be\r\n$$\\int_{-\\infty}^\\infty\\delta^\\prime(x-\\xi)f(x)\\,\\mathrm dx=-\\int_{-\\infty}^\\infty\\delta(x-\\xi)f^\\prime(x)\\,\\mathrm dx=-f^\\prime(\\xi)$$\r\nfor a sufficiently nice $f$.\r\n\\footnote{And a sufficiently nice crowd of students who does not have access to life-threatening weapons. Cure yourself by checking out some rigorous theories formulated by Dirac, Schwartz and Temple.}\r\n\\begin{example}\r\n    For the Gaussian approximation,\r\n    $$\\delta_\\epsilon^\\prime(x)=-\\frac{2x}{\\epsilon^3\\sqrt{\\pi}}e^{-x^2/\\epsilon^2}$$\r\n    which one can plot and have an idea of what the heck is going on with $\\delta^\\prime$.\r\n\\end{example}\r\nAlso, we have the sampling property\r\n$$\\int_a^bf(x)\\delta(x-\\xi)\\,\\mathrm dx=\\begin{cases}\r\n    f(\\xi)\\text{, for $\\xi\\in(a,b)$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nAlso $\\delta$ is even and $\\delta^\\prime$ is odd.\r\nIn addition we have the scaling property\r\n$$\\int_{-\\infty}^\\infty f(x)\\delta(a(x-\\xi))\\,\\mathrm dx=\\frac{1}{|a|}f(\\xi)$$\r\nand its advanced version:\r\nIf $g$ has $n$ isolated zeros as $x_1,\\ldots,x_n$ with $g^\\prime(x_i)\\neq 0$ for all $i$, then\r\n$$\\delta(g(x))=\\sum_{i=1}^n\\frac{\\delta(x-x_i)}{|g^\\prime(x_i)|}$$\r\n\\begin{example}\r\n    Take $g(x)=x^2-1$, then\r\n    \\begin{align*}\r\n        \\int_{-\\infty}^\\infty f(x)\\delta(x^2-1)\\,\\mathrm dx&=\\int_{1-\\epsilon}^{1+\\epsilon}\\frac{f(x)}{2|x|}\\delta(x-1)\\,\\mathrm dx+\\int_{-1-\\epsilon}^{-1+\\epsilon}\\frac{f(x)}{|2x|}\\delta(x+1)\\\\\r\n        &=\\frac{f(1)+f(-1)}{2}\r\n    \\end{align*}\r\n\\end{example}\r\nThere is also this isolation property: $g(x)\\delta(x)=g(0)\\delta(x)$ given that $g$ is continuous at $0$.\r\n\\begin{example}\r\n    We have\r\n    $$\\int_0^\\infty\\delta^\\prime(x^2-1)x^2\\,\\mathrm dx=-\\frac{1}{4}$$\r\n\\end{example}\r\n\\subsection{Eigenfunction Expansions}\r\nFor $-L\\le x<L$, if we want to represent\r\n$$\\delta(x)=\\sum_{n\\in\\mathbb Z}c_ne^{in\\pi x/L}$$\r\nThen the coefficients are\r\n$$c_n=\\frac{1}{2L}\\int_{-L}^L\\delta(x)e^{-in\\pi x/L}\\,\\mathrm dx=\\frac{1}{L}\\implies \\delta(x)=\\frac{1}{2L}\\sum_{n\\in\\mathbb Z}e^{in\\pi x/L}$$\r\nWe obvious want to check that it has compatible properties.\r\nIndeed, if $f(x)=\\sum_{n\\in\\mathbb Z}d_ne^{in\\pi x/L}$ on $[-L,L)$, then\r\n\\begin{align*}\r\n    \\langle f,\\delta\\rangle&=\\int_{-L}^Lf^*(x)\\delta(x)\\,\\mathrm dx\\\\\r\n    &=\\frac{1}{2L}\\sum_{n\\in\\mathbb Z}d_n\\int_{-L}^Le^{-in\\pi x/L}e^{in\\pi x/L}\\,\\mathrm dx\\\\\r\n    &=\\sum_{n\\in\\mathbb Z}d_n\\\\\r\n    &=f(0)\r\n\\end{align*}\r\nNote that we only defined $\\delta$ on $[-L,L)$, so we can use the Fourier series to extend it periodically to the whole real line and obtain what is called a Dirac comb:\r\n$$\\sum_{m\\in\\mathbb Z}\\delta(x-2mL)=\\sum_{n\\in\\mathbb Z}e^{in\\pi x/L}$$\r\nFor general eigenfunctions $\\{y_n\\}$, suppose we have\r\n$$\\delta(x-\\xi)=\\sum_{n=1}^\\infty a_ny_n(x)$$\r\nfor $x,\\xi\\in [a,b]$, then the coefficients are\r\n\\begin{align*}\r\n    a_n&=\\left. \\int_a^bw(x)y_n(x)\\delta(x-\\xi)\\,\\mathrm dx \\middle/ \\int_a^bwy_n^2\\,\\mathrm dx\\right.\\\\\r\n    &=\\left. w(\\xi)y_n(\\xi) \\middle/ \\int_a^bwy_n^2\\,\\mathrm dx\\right.=w(\\xi)Y_n(\\xi)\r\n\\end{align*}\r\nwhere $Y_n$ is the normalised eigenfunctions.\r\nSo\r\n$$\\delta(x-\\xi)=w(\\xi)\\sum_{n=1}^\\infty Y_n(\\xi)Y_n(x)=w(x)\\sum_{n=1}^\\infty Y_n(\\xi)Y_n(x)$$\r\nsince, by the isolation property, $w(x)\\delta(x-\\xi)/w(\\xi)=\\delta(x-\\xi)$.\r\nIn other words,\r\n$$\\delta(x-\\xi)=w(x)\\int_{n=1}^\\infty\\frac{y_n(\\xi)y_n(x)}{N_n},N_n=\\int_a^bwy_n^2\\,\\mathrm dx$$\r\n\\begin{example}\r\n    Consider the Fourier sine series with $y(0)=y(1)=0$ and $y_n(x)=\\sin n\\pi x$, then we have\r\n    $$\\delta(x-\\xi)=2\\sum_{n=1}^\\infty\\sin(n\\pi\\xi)\\sin(x\\pi x)$$\r\n    for $\\xi\\in (0,1)$.\r\n    Integrate both sides over $[0,1]$ with $\\xi=1/2$ gives\r\n    $$\\frac{\\pi}{4}=\\sum_{n=1}^\\infty\\frac{(-1)^{m+1}}{2m-1}$$\r\n\\end{example}\r\nAnother interesting observation to make is that if we integrate the series in previous example twice, we obtained a Green's function we've seen before:\r\n$$G(x,\\xi)=2\\sum_{n=1}^\\infty\\frac{\\sin(n\\pi x)\\sin(n\\pi\\xi)}{(n\\pi)^2}$$", "meta": {"hexsha": "e5cf287a994ec2b394b5ee53aa054506118213f3", "size": 6022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/dirac.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": "6/dirac.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": "6/dirac.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": 61.4489795918, "max_line_length": 202, "alphanum_fraction": 0.6477914314, "num_tokens": 2175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.6955760723111476}}
{"text": "\\section*{Ex.3.4}\n\\subsection*{Is multiply--Shift strongly universal}\n\nWe want to show that it is not by showing it does not hold for $c=1$. We do this by showing that the distinct keys does not hash independently.\n\nSo assume that it is strongly universal, then by definition  for any distinct keys $x,y$ and any possibly non-distinct hash values $q,r$ the probability $P((h_b(x) = q) \\cap (h_b(y) = r)) = \\frac{1}{m^2}>0$. As strong universality holds for any key, we pick $x=0, q=1$ and $y\\neq 0$. Furthermore; it is easy to see that $h_b(0)=0$ for all values of $b$. As we assumed $h$ is strongly universal, then the keys hash independently and\n$$\nP((h_b(0) = 1) \\cap (h_b(y) = r)) = P(h_b(0) = 1) P(h_b(y) = r) = 0 P(h_b(y) = r) = 0.\n$$\n\nHence by assuming strong universality we have now shown\n$$\n0< \\frac{1}{m^2} = P((h_b(0) = 1) \\cap (h_b(y) = r)) = 0 P(h_b(y) = r) = 0.\n$$\n\nwhich is a contradiction.\n\nAs our only assumption is that $h$ is strongly universal, that assumption must be false. Hence we have proven that $h$ is \\emph{not} strongly universal.", "meta": {"hexsha": "f6edd714c7b4af3b6e9dfb813e77be4d1f131e73", "size": 1060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.3.4.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.3.4.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.3.4.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": 58.8888888889, "max_line_length": 431, "alphanum_fraction": 0.6764150943, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.6955760629983003}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[top=35mm,left=3cm,right=3cm]{geometry}\n\\usepackage{graphicx}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{color}\n\\usepackage{verbatim}\n\\usepackage[colorlinks=true,\n            linkcolor=blue,\n            citecolor=blue,\n            urlcolor=blue]{hyperref}\n\n\\newcommand{\\todo}[1]{\\textcolor{red}{\\begin{center}TODO : #1\\end{center}}}\n\\newcommand{\\selfref}[1]{\\href{#1}{#1}}\n\\setlength{\\parindent}{0cm} % no indentation\n\n\\begin{document}\n\n\\title{Rate Gyro Model}\n\\maketitle\n\n\\section{Dynamics}\n\nThe dynamics of a rate gyroscope  takes the\nform\\footnote{A. Lawrence, Modern Inertial Technoogy:\n              Navigation, Guidance, and Control (2nd edition),\n              Mechanical Engineering Series, 1998,\n              Chapter 7, Rate Gyro Dynamics (page 100)}\n\\begin{equation}\n\\label{eq:dyn:gyro}\n    I_a \\ddot{\\theta} + c \\dot{\\theta} + K_{tb} \\theta = H \\omega,\n\\end{equation}\nwhere $\\theta$ is the gimbal angle, $\\omega$ is the input angular velocity,\n$H$ is the wheel angular momentum, $I_a$ is the gimbal moment of inertia about\nthe output axis (OA), $c$ is the damping constant about the OA and $K_{tb}$ is\nthe torsion bar spring constant. The output of the gyro is\n\\begin{equation}\n\\label{eq:gyr:output}\n    \\hat{y} = \\theta K_{po} + B,\n\\end{equation}\nwhere $K_{po}$ is the pickoff sensitivity and $B$ is the measurement bias.\nThe idea of a rate gyroscope is that by measuring $\\hat{y}$ one can get \ninformation about $\\omega$. \\\\\n\nAssume that the value of the bias $B$ is known\nand consider the debiased gyro output $y = \\hat{y} - B$.\nClearly, ${y}$ satisfies a differential equation similar to $\\theta$:\n\\begin{eqnarray*}\n    {y} &=& K_{po}\\theta ,\\\\\n    \\dot{{y}} &=& K_{po} \\dot{\\theta},\\\\\n    \\ddot{{y}} &=& K_{po} \\ddot{\\theta} = \\frac{K_{po}}{I_a} \n    (H\\omega - c\\dot{\\theta} - K_{tb}\\theta) \n    = \\frac{K_{po}}{I_a} \\left(H\\omega - \\frac{c}{K_{po}} \n      \\dot{{y}} - \\frac{K_{tb}}{K_{po}} y \\right),\n\\end{eqnarray*}\nor\n\\begin{equation}\n\\label{eq:gyro:harm1}\n    \\ddot{{y}} + \\frac{c}{I_a} \\dot{{y}} + \\frac{K_{tb}}{I_a} {y} \n    = \\frac{H K_{po}}{I_a} \\omega \\,.\n\\end{equation}\nIf the gyroscope is well-designed, its dynamics will be critically damped with \na gain close to $1$. This will make $y$ converge quickly to $\\omega$ (more \nprecisely, $y(t)-\\omega(t)\\rightarrow 0$, $t\\rightarrow 0$ when $\\omega$ \nchanges slowly or is constant). \\\\\n\nBy introducing \n$a_1 = c/I_a$, $a_2 = K_{tb}/I_a$, $b_1 = H/(I_aK_{po})$,\nwe can rewrite~\\eqref{eq:gyro:harm1} in the ``standard'' form\n\\begin{equation}\n\\label{eq:out:gyro}\n    \\ddot{y} + a_1 \\dot{y} + a_2 y = b_1 \\dot{u}\\,.\n\\end{equation}\nHere we also introduced $\\dot{u} = \\omega$, which is meant to emphasize that \nthe quantity to be estimated is the angular displacement $u$ instead of the \nangular velocity ($\\omega$). Now, the right-hand side is critically damped \nwith a gain of $1$ if the following holds:\n\\begin{equation}\n\\label{eq:cd}\n\\begin{split}\n    \\textrm{gain} = \\frac{b_1}{a_2} = 1 \n    \\quad , \\quad\n    D = a_1^2 - 4 a_2 = 0 .\n\\end{split}    \n\\end{equation}\nThus, if we are interested in estimating the parameters, we only need to \nestimate one parameter as the others can then be determined from~\\eqref{eq:cd}.\n\n\\section{Simulation}\n\nThe behavior of the gyro is given by the ODE described by \\eqref{eq:out:gyro}\nwith the initial condition $y(t_0) = y_0$, $\\dot{y}(t_0) = \\dot{y}_0$,\nwere $y_0,\\dot{y}_0$ are the known initial conditions (usually, they would be\n$(0,0)$, assuming a resting robot). \\\\\n\nIn order to simulate this ODE, we first transform it to a (multi-dimensional)\nfirst order ODE. Second, we will need to deal with the issue that \nthe angular velocity ($\\dot{u}$) is not available, just the angles ($u$). \\\\\n \nTo deal with this second issue, we integrate \n($\\ref{eq:out:gyro}$) respect to the time and get\n\\begin{equation}\n    \\dot{y} + a_1 y + a_2 \\int y = b_1 u .\n\\end{equation}\nNext, by introducing  $w_1 = \\int y$ and $w_2 = y$, we  rewrite this system as:\n\\begin{equation} \\begin{split}\n    \\dot{w}_1 &= w_2\\,, \\\\\n    \\dot{w}_2 &= - a_1 w_2 - a_2 w_1 + b_1 u\\,,\n\\end{split} \\end{equation}\nwhere $w_1(t_0) = w_2(t_0) = 0$. This can be further transformed into the\n\\begin{equation}\n    \\dot{w} = E w + F u\n\\end{equation}\nfirst order ODE form, where $w = [w_1,w_2]^T$ and\n\\begin{equation}\n    E = \\left[ \\begin{array}{cc}\n            0 & 1 \\\\\n            -a_2 & -a_1\n        \\end{array} \\right]\n        \\quad , \\quad\n        F = \n        \\left[ \\begin{array}{c}\n            0 \\\\\n            b_1\n        \\end{array} \\right] .\n\\end{equation}\n\n\\end{document}\n\n", "meta": {"hexsha": "ab3c28dac07a1d4509a0f27873a7e95a85ef9394", "size": 4614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/rategyro-model/rategyro-model.tex", "max_stars_repo_name": "gabalz/segway", "max_stars_repo_head_hexsha": "c5feaabf6cc63a84a45ef09b26af8362ead598ff", "max_stars_repo_licenses": ["MIT"], "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/rategyro-model/rategyro-model.tex", "max_issues_repo_name": "gabalz/segway", "max_issues_repo_head_hexsha": "c5feaabf6cc63a84a45ef09b26af8362ead598ff", "max_issues_repo_licenses": ["MIT"], "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/rategyro-model/rategyro-model.tex", "max_forks_repo_name": "gabalz/segway", "max_forks_repo_head_hexsha": "c5feaabf6cc63a84a45ef09b26af8362ead598ff", "max_forks_repo_licenses": ["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.4923076923, "max_line_length": 79, "alphanum_fraction": 0.6497615951, "num_tokens": 1597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.6955246859703954}}
{"text": "\\section{Matrix Iteration Method}\\label{sec:mim}\nThe matrix iteration method assumes that the natural frequencies are distinct\nand well separated such that \\(\\omega_1 < \\omega_2 < \\dots < \\omega_n\\).\nThe iteration starting by selecting a trial vector \\(\\vec{\\mathbf{X}}_{1}\\),\nwhich is then pre-multiplied by the dynamical matrix \\([D]\\).\nThe resulting column vector is then normalized, usually by making one of its\ncomponents equal to unity.\nThe normalized column vector is pre-multiplied by \\([D]\\) to obtain a third\ncolumn vector, which is normalized in the same way as before and become still\nanother trial column vector.\nThe process is repeated until the successive column vectors converge to a common\nvector: the fundamental eigenvector.\nAccording to the expansion theorem, any arbitrary \\(n\\)-dimensional vector\n\\(\\vec{\\mathbf{X}}_{1}\\) can be expressed as linear combination of the \\(n\\)\northogonal eigenvectors of the system \\(\\vec{\\mathbf{X}}^{(i)}\\).\n\\begin{equation}\\label{eq:expasniontheorem}\n\t\\sum_{i = 1}^{n} = c_{i}\\,\\vec{\\mathbf{X}}^{(n)}\n\\end{equation}\nwhere \\(c_{i}\\) are unknown constant number to be determined.\nAs view before, it is possible pre-multiply \\(\\vec{\\mathbf{X}}_{1}\\) by matrix\n\\([D]\\) obtaining:\n\\begin{equation}\\label{eq:equationmultiply}\n\t[D] \\vec{\\mathbf{X}}_{1} = \tc_{1}\\, [D] \\,\\vec{\\mathbf{X}}_{(1)} +\n\t\t\t\t\t\t\t\tc_{2}\\, [D] \\,\\vec{\\mathbf{X}}_{(2)} + \\dots +\n  \t\t\t\t\t\t\tc_{n}\\, [D] \\,\\vec{\\mathbf{X}}_{(n)}\\\\\n\\end{equation}\nIn according with the equation \\(\\lambda\\,[I]\\,\\vec{X} = [D]\\,\\vec{X}\\), then\nwe obtain\n\\(\\vec{X}^{(n)} = \\lambda\\,[I]\\,\\vec{X}^{(n)} = \\frac{1}{\\omega^{2}_{n}}\n\\vec{X}^{(n)}\\), thus after having substituted it in the equation\n\\eqref{eq:equationmultiply} one comes to the:\n\\begin{align}\\label{eq:equationsubs}\n  \t[D]\\,\\vec{\\mathbf{X}}_{1} &= \\vec{\\mathbf{X}}_{2}\\\\[0.75em]\n      \t\t\t\t\t\t&= \\frac{c_{1}}{\\omega^{2}_{1}}\\,\\vec{\\mathbf{X}}^{(1)} +\n\t\t\\frac{c_{2}}{\\omega^{2}_{2}}\\,\\vec{\\mathbf{X}}^{(2)} + \\dots +\n\t\t\\frac{c_{n}}{\\omega^{2}_{n}}\\,\\vec{\\mathbf{X}}^{(n)}\n\\end{align}\nBy repeating the process we obtain, after \\(r_{th}\\) iteration,\n\\begin{align}\\label{eq:equationrth}\n  \t[D]\\,\\vec{\\mathbf{X}}_{r} &= \\vec{\\mathbf{X}}_{r+1}\\\\[0.75em]\n      \t\t\t\t\t\t&= \\frac{c_{1}}{\\omega^{2r}_{1}}\\,\\vec{\\mathbf{X}}^{(1)} +\n\t\t\\frac{c_{2}}{\\omega^{2r}_{2}}\\,\\vec{\\mathbf{X}}^{(2)} + \\dots +\n\t\t\\frac{c_{n}}{\\omega^{2r}_{n}}\\,\\vec{\\mathbf{X}}^{(n)}\n\\end{align}\nSince the natural frequencies are are assumed \\(\\omega_1 < \\omega_2 < \\dots <\n\\omega_n\\), a sufficiently large value of \\(r\\) yields \\(\\frac{1}{\\omega_1^{2r}}\n>> \\frac{1}{\\omega_2^{2r}} >> \\dots >> \\frac{1}{\\omega_n^{2r}}\\). Thus the first\nterm in right-hand side of equation \\eqref{eq:equationrth} becomes the only\nsignificant one.\nWhich means that the \\((r+1)_{th}\\) trial vector becomes identical to the\nfundamental modal vector to within a multiplicative constant\n\\(\\vec{\\mathbf{X}}_{r} = \\frac{c_1}{\\omega^{2(r-1)}_{1}}\\vec{\\mathbf{X}}^{(1)}\\).\nThen the fundamental natural frequency \\(\\omega_1\\) can be found by taking the\nratio of any two corresponding components in the vectors \\(\\vec{\\mathbf{X}}_{r}\\)\nand \\(\\vec{\\mathbf{X}}_{r+1}\\):\n\\begin{equation}\n  \\omega_1^{2} \\simeq \\frac{\\vec{\\mathbf{X}}_{n,r}}{\\vec{\\mathbf{X}}_{n,r+1}}\n\\end{equation}\nwhere \\(\\vec{\\mathbf{X}}_{n,r}\\) and \\(\\vec{\\mathbf{X}}_{n,r+1}\\) are the\n\\(n_{th}\\) elements of vector \\(\\vec{\\mathbf{X}}_{r}\\) and\n\\(\\vec{\\mathbf{X}}_{r+1}\\), respectively.\n\\subsection{Intermediate natural frequencies}\nOnce the first natural frequency \\(\\omega_1\\) and the corresponding eigenvector\n\\(\\vec{\\mathbf{X}}^{(1)}\\) are determined, it is possible proceed to find the\nhigher natural frequencies and the corresponding mode shapes.\nTo find the eigenvector \\(\\vec{\\mathbf{X}}^{(i)}\\), the previous eigenvector\n\\(\\vec{\\mathbf{X}}^{(i-1)}\\) is normalized with respect to the mass matrix such\nthat \\(\\vec{\\mathbf{X}}^{(i-1)^\\top}\\,[m]\\,\\vec{\\mathbf{X}}^{(i-1)} = 1\\).\nThe deflated matrix \\([D_i]\\) is the constructed as is used.\n\\begin{equation}\n  [D_i] =\n  [D_i] - \\lambda_{i-1}\\vec{\\mathbf{X}}^{(i-1)}\\,\\vec{\\mathbf{X}}^{(i-1)^\\top}[m]\n\\end{equation}\nwhere \\([D_1] = [D]\\).\nOnce \\([D_i]\\) is constructed the iterative scheme\n\\begin{equation}\n  \\vec{\\mathbf{X}}^{(r+1)} = [D_i]\\,\\vec{\\mathbf{X}}^{(r)}\n\\end{equation}\n%\n\\subsection{Result}\n\\label{ssec:resultmim}\nThe whole procedure is performed for the case of free damping where natural \nfrequencies obtained: \\(\\omega_{1} = 8.27843\\) [\\si{\\radian\\per\\second}], \n\\(\\omega_{2}= 27.41224\\) [\\si{\\radian\\per\\second}], \\(\\omega_{3} = 41.85486\\)\n[\\si{\\radian\\per\\second}].\nThe mode shapes results are shown in \\eqref{eq:mimmodefree}.\n\\begin{equation}\\label{eq:mimmodefree}\n [\\mathbf{U}] = \\begin{bmatrix*}[r]\n\t1.00000 & 1.00000 & 1.00000 \\\\\n\t0.86540 & 0.21230 &-0.85499 \\\\\n\t0.61945 &-0.30643 &-0.30390 \\\\\n\t \\end{bmatrix*}\n\\end{equation}\n%\nIn the case of proportional damping natural frequencies are:\n\\(\\omega_{1} = 8.27799\\) [\\si{\\radian\\per\\second}], \\(\\omega_{2} = 27.40863\\)\n[\\si{\\radian\\per\\second}], \\(\\omega_{3} = 41.91576\\) [\\si{\\radian\\per\\second}].\nThe mode shapes results are shown in \\eqref{eq:mimmodeprop}.\n \\begin{equation}\\label{eq:mimmodeprop}\n [\\mathbf{U}] = \\begin{bmatrix*}[r]\n\t1.00000 & 1.00000 & 1.00000 \\\\\n\t0.86499 &-0.48006 &-2.46147 \\\\\n\t0.61907 &-1.28528 & 2.16954 \\\\\n\t \\end{bmatrix*}\n\\end{equation}\n\\subsection{Observation}\\label{ssec:observationmim}\nAlthough it is theoretically necessary to have \\(r\\rightarrow\\infty\\) for the \nconvergence of the method, in practice only a finite number of iterations\nsuffices to obtain a reasonably good estimate of \\(\\omega_{1}\\).\nThe actual number of iterations necessary to find the value of \\(\\omega_1\\) to\nwithin a desired degree of accuracy depends on how closely the arbitrary trial\nvector \\(\\vec{\\mathbf{X}}_{1}\\) resembles the mode and how well \\(\\omega_1\\)\nand \\(\\omega_2\\) are separated.\nThe required number of iterations is less if \\(\\omega_2\\) is very large compared\nto \\(\\omega_{1}\\).\nThe method has a distinct advantage in that any computational errors made do not\nyield incorrect results. Any error made in pre-multiplying\n\\(\\vec{\\mathbf{X}}_{i}\\) by \\([D]\\) results in a vector other than the desired\none, \\(\\vec{\\mathbf{X}}_{i+1}\\).\nBut this wrong vector can be considered as a new trial vector.\nThis may delay the convergence but does not produce wrong results.\n", "meta": {"hexsha": "965b3c1649dfaf4ae6c7952d66496fa0fda3ef69", "size": 6353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/matrixiterationmethod.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/matrixiterationmethod.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/matrixiterationmethod.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": 52.0737704918, "max_line_length": 81, "alphanum_fraction": 0.6700771289, "num_tokens": 2208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6954939956025658}}
{"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 10: Second Derivative Test}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\nHow do we know the global maximum or minimum values of a function?\n\nSimilar to single-variable functions, the global max/min value of a \nmultivariable function can be the function value of:\n\\begin{itemize}\n  \\item Either a local max/min point.\n  \\item Or the boundary or infinity.\n\\end{itemize}\n\nWe know that local max/min points are critical points. Then how do we determine \nthe type of a critical point? Except the method we talked about in the previous \nlecture, there is a systematic way to do it, called \n\\textbf{Second Derivative Test}.\n\n\\section{A Simple Case: Quadratic Functions}\n\nSuppose that we have a quadratic multivariable function \n\\begin{equation*}\n  z = f(x, y) = ax^2 + bxy + cy^2, a \\neq 0\n\\end{equation*}\nWe can calculate its partial derivatives and find that $(0, 0)$ is a critical \npoint of the function:\n\\begin{gather*}\n  \\frac{\\partial f}{\\partial x} = 2ax + by \\\\\n  \\frac{\\partial f}{\\partial y} = 2cy + bx \\\\\n  \\frac{\\partial f}{\\partial x}(0, 0) = 0 \\\\\n  \\frac{\\partial f}{\\partial y}(0, 0) = 0 \\\\\n\\end{gather*}\nThe value of the function on the critical point $(0, 0)$ is \n\\begin{equation*}\n  z = f(0, 0) = a \\cdot 0^2 + b \\cdot 0 \\cdot 0 + c \\cdot 0^2 = 0\n\\end{equation*}\nLet's try to find the type of this critical point.\n\\begin{equation*}\n  \\begin{split}\n    z &= ax^2 + bxy + cy^2 \\\\\n      &= a(x^2 + \\frac{b}{a}xy) + cy^2 \\\\\n      &= a(x^2 + \\frac{b}{a}xy + \\frac{b^2}{4a^2}y^2) + (c - \\frac{b^2}{4a})y^2 \\\\\n      &= a(x + \\frac{b}{2a}y)^2 + \\frac{1}{4a}(4ac - b^2)y^2 \\\\\n      &= \\frac{1}{4a}[4a^2(x + \\frac{b}{2a}y)^2 + (4ac - b^2)y^2] \\\\\n  \\end{split}\n\\end{equation*}\nWe can see that the quadratic function is actually a sum of two terms:\n\\begin{itemize}\n  \\item $4a^2(x + \\frac{b}{2a}y)^2$, which is always greater than or equal to 0.\n  \\item $(4ac - b^2)y^2$, which is either always greater than or equal to 0, or \n    always less than or equal to 0, depending on the sign of $(4ac - b^2)$.\n\\end{itemize}\nTherefore, we can discuss different cases here:\n\\begin{itemize}\n  \\item If $4ac - b^2 < 0$, the two terms would have different signs, no matter \n    what sign the factor $\\frac{1}{4a}$ has. Therefore, starting from the \n    critical point $(0, 0)$, in one direction (perpendicular to the direction \n    represented by the positive term) the function value would increase, and in \n    another direction (perpendicular to the direction represented by the \n    negative term) the function value would decrease. Therefore, the critical \n    point $(0, 0)$ is actually a \\textbf{saddle point}.\n  \\item If $4ac - b^2 = 0$, the function is actually $a(x + \\frac{b}{2a}y)^2$. \n    Therefore, the function would have degenerate critical points along a \n    direction, which is perpendicular to the direction represented by the left \n    term, and it means along the direction the function value won't change.\n  \\item If $4ac - b^2 > 0$, both of the two terms are either $\\leq 0$, or \n    $\\geq 0$, depending on the sign of the factor $\\frac{1}{4a}$. Therefore,\n    \\begin{itemize}\n      \\item When $a > 0$, both terms are positive, then the critical point \n        $(0, 0)$ is a \\textbf{local minimum point}.\n      \\item When $a < 0$, both terms are negative, then the critical point\n        $(0, 0)$ is a \\textbf{local maximum point}.\n    \\end{itemize}\n\\end{itemize}\n\n\\section{General Cases: Second Derivative Test}\n\n\\subsection{Second Derivatives}\n\n\\textbf{Second derivatives} are partial derivatives of partial derivatives of \nmultivariable functions. For multivariable functions with two independent \nvariables, there are four second derivatives:\n\\begin{gather*}\n  \\frac{\\partial^2 f}{\\partial x^2} = f_{xx} \\\\\n  \\frac{\\partial^2 f}{\\partial x \\partial y} = f_{xy} \\\\\n  \\frac{\\partial^2 f}{\\partial y \\partial x} = f_{yx} \\\\\n  \\frac{\\partial^2 f}{\\partial y^2} = f_{yy} \\\\\n\\end{gather*}\n\nA property of second derivatives is:\n\\begin{equation*}\n  \\frac{\\partial^2 f}{\\partial x \\partial y} = \\frac{\\partial^2 f}{\\partial y \\partial x}\n\\end{equation*}\nwhich means the order of partial derivatives taken doesn't affect the result.\n\n\\subsection{Rules of Second Derivative Test}\n\nAt a critical point $(x_0, y_0)$ of a multivariable function $f$, let\n\\begin{gather*}\n  A = f_{xx}(x_0, y_0) \\\\\n  B = f_{xy}(x_0, y_0) \\\\\n  C = f_{yy}(x_0, y_0) \\\\\n\\end{gather*}\nThe conclusions are as follows:\n\\begin{itemize}\n  \\item If $AC - B^2 < 0$, then the critical point is a saddle point.\n  \\item If $AC - B^2 = 0$, then the type of the critical point is unknown.\n  \\item If $AC - B^2 > 0$, then\n    \\begin{itemize}\n      \\item If $A > 0$, then the critical point is a local minimum point.\n      \\item If $A < 0$, then the critical point is a local maximum point.\n    \\end{itemize}\n\\end{itemize}\n\nWe can verify that the second derivative test is consistent with the conclusions \nwe get from the simple quadratic function case in the previous section.\n\\begin{gather*}\n  z = f(x, y) = ax^2 + bxy + cy^2 \\\\\n  f_x = 2ax + by \\\\\n  f_y = 2cy + bx \\\\\n  f_{xx} = 2a \\\\\n  f_{xy} = b \\\\\n  f_{yx} = b \\\\\n  f_{yy} = 2c \\\\\n\\end{gather*}\nTherefore\n\\begin{gather*}\n  A = f_{xx} = 2a \\\\\n  B = f_{xy} = b \\\\\n  C = f_{yy} = 2c \\\\\n  AC - B^2 = 4ac - b^2 \\\\\n\\end{gather*}\n\n\\subsection{Ideas behind Second Derivative Test}\n\nThe reason why the second derivative test holds can be explained by quadratic \napproximation. According to quadratic approximation, the function value around \na point $(x_0, y_0)$ can be approximated as\n\\begin{gather*}\n  f \\approx f(x_0, y_0) + f_x(x - x_0) + f_y(y - y_0) + \\frac{1}{2}f_{xx}(x - x_0)^2 + f_{xy}(x - x_0)(y - y_0) + \\frac{1}{2}f_{yy}(y - y_0)^2\n\\end{gather*}\n\nFor critical points, $f_x = f_y = 0$, hence the approximation formula becomes \n\\begin{gather*}\n  f \\approx f(x_0, y_0) + \\frac{1}{2}f_{xx}(x - x_0)^2 + f_{xy}(x - x_0)(y - y_0) + \\frac{1}{2}f_{yy}(y - y_0)^2\n\\end{gather*}\nTherefore, the general case reduces to a quadratic function case.\n\nQuadratic approximation also explains why we cannot draw any conclusion about \nthe critical point when $AC - B^2 = 0$, i.e. the degenerate cases. In those cases, \nthe function values along the direction are actually affected by the high-order \nterms that we ignored in the quadratic approximation. Therefore, we do not \nreally know what the shape of the function graph is around the critical point.\n\n\\begin{example}\n  Find the global maximum and minimum values of the function \n  $f(x, y) = x + y + \\frac{1}{xy}, x > 0, y > 0$.\n\n  Solution: \\\\\n  \\begin{gather*}\n    f_x = 1 - \\frac{1}{x^2y} \\\\\n    f_y = 1 - \\frac{1}{xy^2} \\\\\n    f_{xx} = \\frac{2}{x^3y} \\\\\n    f_{xy} = \\frac{1}{x^2y^2} \\\\\n    f_{yy} = \\frac{2}{xy^3} \\\\\n  \\end{gather*}\n  Solving the system of equations\n  \\begin{equation*}\n    \\begin{cases}\n      f_x = 1 - \\frac{1}{x^2y} = 0 \\\\\n      f_y = 1 - \\frac{1}{xy^2} = 0 \\\\\n    \\end{cases}\n  \\end{equation*}\n  we find that there are only one critical point $(1, 1)$, whose value is $3$.\n\n  According to the second derivative test,\n  \\begin{gather*}\n    A = f_{xx}(1, 1) = 2 \\\\\n    B = f_{xy}(1, 1) = 1 \\\\\n    C = f_{yy}(1, 1) = 2 \\\\\n    AC - B^2 = 3 > 0 \\\\\n    A > 0 \\\\\n  \\end{gather*}\n  Therefore, the critical point $(1, 1)$ is a local minimum point. \n  \n  Then let's check the boundary and infinity:\n  \\begin{gather*}\n    \\lim_{x \\to 0}f(x, y) = \\infty \\\\\n    \\lim_{y \\to 0}f(x, y) = \\infty \\\\\n    \\lim_{x \\to \\infty}f(x, y) = \\infty \\\\\n    \\lim_{y \\to \\infty}f(x, y) = \\infty \\\\\n  \\end{gather*}\n\n  Therefore, the global minimum point is the only local minimum point $(1, 1)$, \n  whose value is $3$, and the global maximum point is the boundary or infinity, \n  where the function value is $\\infty$.\n\\end{example}\n\n\\end{document}", "meta": {"hexsha": "d50717ca23524863251bd464ae6f229ebf8e96eb", "size": 8108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture10.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": "lecture10.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": "lecture10.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": 37.0228310502, "max_line_length": 142, "alphanum_fraction": 0.6558954119, "num_tokens": 2721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.6954939810673445}}
{"text": "\\chapter{Some Basic Properties of Bessel Functions}\\label{chap:Besselfunctions}\nBelow, we collect some important properties of Bessel functions that have been heavily used in solving the radiation problem with a cylindrical boundary condition. \nDetailed properties of Bessel functions may be found in Ref.~\\cite{Watson1995}.\n\nDifferential equations define Bessel functions are in the following general form,\n\\begin{align}\nx^2\\sdd{R(x)}{x}+x\\dd{R(x)}{x}+(x^2-m^2)R(x)=0,\n\\end{align}\nwhere $R(x)$ is a Bessel function with index $m$. \n\nRecurrence relations for the first kind of Bessel functions:\n\\begin{align}\nJ_m(x)=\\frac{m+1}{x}J_{m+1}(x)+\\dd{J_{m+1}(x)}{x}=\\frac{m-1}{x}J_{m-1}-\\dd{J_{m-1}(x)}{x}.\n\\end{align}\n\nDerivatives of Bessel functions:\n\\begin{align}\nJ_m^\\prime(x)&=\\frac{1}{2}(J_{m-1}(x)-J_{m+1}(x))\\\\\n{H^{(1)}_m}^\\prime (x) &=\\frac{1}{2}({H^{(1)}_{m-1}}^\\prime (x)-{H^{(1)}_{m+1}}^\\prime(x)).\n\\end{align}", "meta": {"hexsha": "ef8429cbb0bb011629a9cc708196084a5ca4e0ec", "size": 915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "append/BesselFunctions.tex", "max_stars_repo_name": "i2000s/PhD_Thesis", "max_stars_repo_head_hexsha": "a9bc6bc4213896c70c90cbb3d9b533782d428761", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-26T01:58:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:11:43.000Z", "max_issues_repo_path": "append/BesselFunctions.tex", "max_issues_repo_name": "i2000s/PhD_Thesis", "max_issues_repo_head_hexsha": "a9bc6bc4213896c70c90cbb3d9b533782d428761", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-07-18T01:47:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-18T01:47:21.000Z", "max_forks_repo_path": "append/BesselFunctions.tex", "max_forks_repo_name": "i2000s/PhD_Thesis", "max_forks_repo_head_hexsha": "a9bc6bc4213896c70c90cbb3d9b533782d428761", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-17T21:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-17T21:55:09.000Z", "avg_line_length": 45.75, "max_line_length": 164, "alphanum_fraction": 0.6918032787, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6954909224906387}}
{"text": "\\subsection{Partial Fractions}\r\n\\noindent\r\nIf we have a function of two polynomials $f(x) = \\frac{P(x)}{Q(x)}$, it's often easier to break this quotient into a sum of parts where the denominator is a linear or quadratic factor and the numerator is always a smaller degree than the denominator.\r\n\r\n\\ifodd\\includeBackgroundReviewExamples\\input{./backgroundReview/algebraPreCalc/partialFractions_example.tex}\\fi\r\n\r\n\\noindent\r\nOne natural way to find these small denominators comes from the linear factors of the denominator where we keep quadratics with complex roots. This way, when making a common denominator, we get back the original big denominator. However, 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": "e2581cbe16066d7d6ea2a24d84ac71a5db9913bb", "size": 1050, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/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": "diffEq/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": "diffEq/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": 70.0, "max_line_length": 293, "alphanum_fraction": 0.8104761905, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648678, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6954666280044368}}
{"text": "\\section{Expectation Maximization}\n\\smallskip \\hrule height 2pt \\smallskip\n\nA clever method for maximizing marginal likelihood, where you alternate between computing an expectation and a maximization. \n\nIt is not magic: it is still optimizing a non-convex function with lots of local optima.  The computations are just easier. \n\n\\begin{itemize}\n\t\\item as in GMM, the objective is: \n\t\t$$ \\argmax_{\\theta} \\prod_i P(x^j; \\theta) = \\argmax \\prod_j \\sum_{i=1}^k P(y^j=i, x^j; \\theta) $$\n\t\\item \\textbf{E step:} Compute the expectations to \"fill in\" the missing $y$ values according to the current parameters. \\hfill \\\\\n\t\tFor all examples $j$ and values $i$ for $y$, compute: $P(y^j = i | x^j, \\theta)$. \n\t\\item \\textbf{M step:}\n\t\tRe-estimate the parameters with \"weighted\" MLE estimates:\n\t\tSet \n\t\t\t$$\\theta = \\argmax_{\\theta} \\sum_j \\sum_{i=1}^k P(y^j = i | x^j, \\theta) log P(y^j = i, x^j | \\theta )$$ \n\t\\item this is especially useful when the E and M steps have closed form solutions. \n\\end{itemize}", "meta": {"hexsha": "85e11487b2125a4c2fdaa41e5785d2db0ad9a4fb", "size": 998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/expectation_maximization.tex", "max_stars_repo_name": "JanetMatsen/Machine-Learning", "max_stars_repo_head_hexsha": "12e1f701eb7de89b97d5caffe86b0267731e4cb5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2016-02-07T23:35:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-26T05:13:33.000Z", "max_issues_repo_path": "tex/expectation_maximization.tex", "max_issues_repo_name": "JanetMatsen/Machine-Learning", "max_issues_repo_head_hexsha": "12e1f701eb7de89b97d5caffe86b0267731e4cb5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/expectation_maximization.tex", "max_forks_repo_name": "JanetMatsen/Machine-Learning", "max_forks_repo_head_hexsha": "12e1f701eb7de89b97d5caffe86b0267731e4cb5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2016-08-29T00:15:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-06T22:36:19.000Z", "avg_line_length": 55.4444444444, "max_line_length": 131, "alphanum_fraction": 0.7004008016, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6953398641007127}}
{"text": "\\section{Comparison with integer factorization}\nWhile computing discrete logarithms within a field and computing the integer factorization of a composite number are distinct problems, they share some characteristics:\n\\begin{itemize}\n\t\\item Both concern cases of the small subgroup problem for finite commutative groups;\n\t\\item Both are NP-hard problems, despite the existence of efficient algorithms on quantum computers;\n\t\\item Both have been extensively used to construct strong encryption systems still valid today.\n\\end{itemize}\n\nFurthermore, some algorithms to break integer factorization also have practical application in solving discrete logarithms, such as index-calculus. Shank and Pollard, on the other hand, have both developed different methods to solve the two problems.\n\nSolving the discrete logarithm problem would actually solve the integer factorization problem, and vice versa, for the two following reasons:\n\\begin{enumerate}\n\t\\item One system can be reduced to the other, since they both work on groups using the modulo operation;\n\t\\item Both are assumed to be in the same computation class of NP, therefore solving any NP-hard problem would imply there exist an efficient way to consequently solve all the others.\n\\end{enumerate}\n\nSince the RSA cryptography extensively rely on integer factorization, it is considered equally hard to break as the discrete logarithm. Both algorithms, therefore, are considered strong enough for safe encryption purposes and have similar performance.\n\nThe nature of Diffie-Hellman, however, makes it susceptible to man-in-the-middle attacks, since it does not authenticate involved parts during the exchange and requires additional confirmation.\n\nRSA, on the other hand, allows digital signatures, although still needs the exchange of a public key beforehand. \n\n\\section{Final considerations}\nDiscrete logarithm has been proved to be secure against both active and passive attacks: the only effective way to break this problem would be to come up with new algorithms, since the key length can be arbitrarily increased to resist modern hardware. \n\nHowever, there are some problems:\n\\begin{itemize}\n\t\\item Is Decisional Diffie-Hellman equally hard as discrete logarithm, when dealing with preprocessing attacks?\n\t\\item Is quantum computing an efficient way to reduce computational time?\n\t\\item Would attacks on elliptic curves also influence discrete logarithm?\n\\end{itemize}\n\nHaving these open questions allow space for urther research and development, while still ensuring computation infeasibility. ", "meta": {"hexsha": "a106566e4244e1d816fe1a260702175f26b68f48", "size": 2554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/conclusion.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/conclusion.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/conclusion.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": 77.3939393939, "max_line_length": 252, "alphanum_fraction": 0.8206734534, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6953398619806787}}
{"text": "\\chapter{Special types of space}\n\\pagebreak[4]\n\\section{p112 - Exercise}\n\\begin{tcolorbox}\nDeduce from $4.110.$ that the Gaussian curvature of a $V_2$ positive-definite metric is given by $$ G = \\frac{R_{1212}}{a_{11}a_{22}-a_{12}^2}$$\n\\end{tcolorbox}\nFrom p. 86 (exercise) we know that all the components of $R_{mnrs}$ can be expressed as terms of $R_{1212}$ (or vanish). \\\\\nSo by $4.110.$, \n\\begin{align}\nK\\left({a_{11}a_{22}-a_{12}a_{21}}\\right) = R_{1212}\n\\end{align}\nand from page 96 $3.415.$ we know that for $V_2$, $K=G$. Hence,\n\\begin{align}\nG = \\frac{R_{1212}}{\\left(a_{11}a_{22}-a_{12}a_{21}\\right)}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p113 - Exercise}\n\\begin{tcolorbox}\nProve that, in a space $V_N$ of constant curvature $K$,$$\\mathbf{4.115.}\\spatie R_{mn} = -\\left(N-1\\right)Ka_{mn}, \\quad R = -N\\left(N-1\\right)K$$\n\\end{tcolorbox}\nWe have\n\\begin{align}\nR_{mn} = R^s_{.mns} = a^{sk}R_{kmns}\n\\end{align}\nFrom $4.114.$\n\\begin{align}\nR_{kmns} &= K\\left(a_{kn}a_{ms}-a_{ks}a_{mn}\\right)\\\\\n&= K \\left(\\underbrace{\\delta^s_n a_{ms}}_{a{mn}}-Na_{mn}\\right)\\\\\n&= K\\left(1-N\\right)a_{mn}\n\\end{align}\nand \n\\begin{align}\nR &= R^n_{.n}\\\\\n&= a^{kn}R{kn}\\\\\n&= -\\underbrace{a^{kn}a_{kn}}_{N}\\left( N-1 \\right)K\\\\\n&= -N\\left( N-1 \\right)K\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p113 - Clarification}\n\\begin{tcolorbox}\n$$\\mathbf{4.117.}\\spatie \\frac{\\delta^2 \\eta^r}{\\delta s^2} + \\epsilon K\\eta^r =0$$\n\\end{tcolorbox}\nWe have\n\\begin{align}\nR^r_{.smn} &= a^{rk} R_{ksmn}\\\\\n\\text{(4.114)}\\Rightarrow \\spatie &= a^{rk} K\\left(a_{km}a_{sn}-a_{kn}a_{sm}\\right)\\\\\n&= K\\left(\\delta^r_m a_{sn}-\\delta^r_n a_{sm}\\right)\n\\end{align}\n\\begin{align}\n\\text{(3.311) and (3)}\\spatie 0 &=\\frac{\\delta^2 \\eta^r}{\\delta s^2} +  K\\left(\\delta^r_m a_{sn}-\\delta^r_n a_{sm}\\right)p^s\\eta^m p^n\\\\\n\\Leftrightarrow\\spatie 0 &=\\frac{\\delta^2 \\eta^r}{\\delta s^2} +  K\\left(\\delta^r_m \\eta^m \\underbrace{a_{sn}p^s p^n}_{=\\epsilon}-\\delta^r_n \\underbrace{a_{sm}p^s\\eta^m}_{=0} p^n\\right)\\\\\n\\Leftrightarrow\\spatie 0 &=\\frac{\\delta^2 \\eta^r}{\\delta s^2} +  K\\epsilon\\underbrace{\\delta^r_m \\eta^m}_{=\\eta^r} \\\\\n\\Leftrightarrow\\spatie 0 &=\\frac{\\delta^2 \\eta^r}{\\delta s^2} +  K\\epsilon\\eta^r\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p114 - Clarification}\n\\begin{tcolorbox}\n$$\\mathbf{4.118.}\\spatie \\dv[2]{\\left(X_r\\eta^r\\right)}{s} + \\epsilon K\\left(X_r\\eta^r\\right) =0$$\n\\end{tcolorbox}\nWe know that $\\frac{\\delta X_r}{\\delta s} = 0$ (parallel transport)\n\\begin{align}\n\\frac{\\delta \\left(X_r\\eta^r\\right)}{\\delta s}&= \\eta^r\\underbrace{\\frac{\\delta X_r}{\\delta s}}_{=0}+X_r\\frac{\\delta \\eta^r}{\\delta s}\\\\\n\\Rightarrow\\spatie \\frac{\\delta^2 \\left(X_r\\eta^r\\right)}{\\delta s}&= \\underbrace{\\frac{\\delta X_r}{\\delta s}}_{=0}\\frac{\\delta \\eta^r}{\\delta s}+X_r\\frac{\\delta^2 \\eta^r}{\\delta s^2}\\\\\n\\Rightarrow\\spatie X_r\\frac{\\delta^2 \\eta^r}{\\delta s^2}&= \\frac{\\delta^2 \\left(X_r\\eta^r\\right)}{\\delta s^2}\\\\\n\\text{but}\\spatie \\frac{\\delta^2 \\left(X_r\\eta^r\\right)}{\\delta s^2} &=  \\dv[2]{X_r\\eta^r}{s} \\quad \\text{ as } X_r\\eta^r \\text{ is an invariant}\\\\\n\\Rightarrow X_r\\frac{\\delta^2 \\eta^r}{\\delta s^2}&=\\dv[2]{X_r\\eta^r}{s}\\\\\n\\text{and so}\\spatie \\frac{\\delta^2 \\left(\\eta^r\\right)}{\\delta s^2}X_r + \\epsilon K\\left(X_r\\eta^r\\right) &= \\dv[2]{X_r\\eta^r}{s}+ \\epsilon K\\left(X_r\\eta^r\\right) = 0\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p115 - Exercise}\n\\begin{tcolorbox}\nBy taking an orthonormal set of $N$ unit vectors propagated parallely along the geodesic, deduce from $4.120a$ that the magnitude $\\eta$ of the vector $\\eta^r$ is given by $$ \\eta = C\\left|\\sin \\left(s\\sqrt{\\epsilon K}\\right)\\right|$$ where $C$ is a constant.\n\\end{tcolorbox}\nWe have by $4.120a$\n\\begin{align}\nX_r \\eta^r &= A\\sin \\left(s\\sqrt{\\epsilon K}\\right)\n\\end{align}\nWe choose $N$ different $X^{(k)}_r$ $(k= 1,2,\\dots, N)$ which are orthonormal.\nApplying $(1)$ $N$ times with the different $X^{(k)}_r$ $(k= 1,2,\\dots, N)$, we get\n\\begin{align}\nX^{(k)}_r \\eta^r &= A^{(k)}\\sin \\left(s\\sqrt{\\epsilon K}\\right)\n\\end{align}\nBut as the $X^{(k)}_r$ are orthonormal and are used as a basis at the considered point of the geodesic we have \n\\begin{align}\nX^{(k)}_r &= \\delta^k_r\n\\end{align}\nSo, $(2)$ becomes\n\\begin{align}\n\\eta^k &= A^{(k)}\\sin \\left(s\\sqrt{\\epsilon K}\\right)\n\\end{align}\nwhich are the components of the displacement vector in the orthonormal basis. By $\\mathbf{2.301.}$ :\n\\begin{align}\nY^2 &= \\epsilon a_{mn} Y^m Y^n\\\\\n\\Rightarrow \\spatie \\eta^2 &= \\epsilon a_{mn} A^{(m)} A^{(n)}\\sin^2 \\left(s\\sqrt{\\epsilon K}\\right)\\\\\n\\Rightarrow \\spatie \\eta &= C\\left|\\sin \\left(s\\sqrt{\\epsilon K}\\right)\\right|\\\\\n\\text{with}\\spatie C&= \\sqrt{\\left|\\epsilon a_{mn} A^{(m)} A^{(n)}\\right|}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p118 - Exercise}\n\\begin{tcolorbox}\nExamine the limit of the form $\\mathbf{4.130}$ as $R$ tends to infinity, and interpet the result.\n\\end{tcolorbox}\nWe have $$\\mathbf{4.130.}\\spatie ds^2 = dr^2+R^2\\sin^2\\left(\\frac{r}{R}\\right)\\left(d\\theta^2 + \\sin^2\\theta d\\phi^2\\right)$$\nBut $\\sin \\epsilon \\approx \\epsilon$ for $\\epsilon  \\ll 1$. So\n\\begin{align}\n \\lim_{R\\rightarrow \\infty} ds^2 &= dr^2+R^2\\left(\\frac{r}{R}\\right)^2\\left(d\\theta^2 + \\sin^2\\theta d\\phi^2\\right)\\\\\n &= dr^2+\\left(r d\\theta^2 \\right) + \\left(r\\sin\\theta d\\phi\\right)^2\n \\end{align}\n This is the metric form for an Euclidean 3-space with spherical polar coordinates (see $\\mathbf{2.532.}$ page 54).\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p119 - Exercise}\n\\begin{tcolorbox}\nShow that a transformation of a homogeneous coordinate system  into another homogeneous system is necessarily linear. (Use the transformation equation $\\mathbf{2.507}$ for Christoffel symbols, noting that all Christoffel symbols vanish  when the coordinates are homogeneous).\n\\end{tcolorbox}\nBy $2.507$ we have the transformation rule \n\\begin{align}\n\\Gamma^{'a}_{bc} = \\Gamma^{r}_{mn}\\partial_r z^a\\partial_b z^m \\partial_c z^n + \\partial_r z^a\\frac{\\partial^2 z^r}{\\partial z^b \\partial z^c} \n\\end{align}\nBut, as both coordinate system are homogeneous, all Christoffel symbols vanish and so\n\\begin{align}\n\\Gamma^{'a}_{bc} = \\partial_r z^a\\frac{\\partial^2 z^r}{\\partial z^b \\partial z^c} &=0\\\\\n\\Rightarrow \\spatie \\partial_r z^a\\frac{\\partial^2 z^r}{\\partial z^b \\partial z^c} &=0\n\\end{align}\nAs the Jacobian can't vanish the possibility of having $\\partial_r z^a=0$ $\\forall a, r$ is excluded. Hence we must have $\\frac{\\partial^2 z^r}{\\partial z^b \\partial z^c} =0$. And have a linear solution of the form\n\\begin{align}\nz^r = A_k z^{'k}+C\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p120 - Exercise}\n\\begin{tcolorbox}\nIf $z_r, z^{'}_r$ are two systems of rectangular Cartesian coordinates in Euclidean 3-space, what is the geometrical interpretation of the constants in $\\mathbf{4.204}$ and of the orthogonality conditions $\\mathbf{4.209}$ ?\n\\end{tcolorbox}\nWe have \n\\begin{align}\nz^{'}_m &= A_{mn}z_n+A_m \n\\end{align}\nAs we assume that the Jacobian of the transformation does not vanish and thus the mapping is bijective, in an Euclidean 3-space $A_m$ will perform a $\\mathit{translation}$ while $A_{mn}$ can be interpreted as a combination rotation/reflection/stretching/contraction/shearing. I.e. the mapping is an $\\mathit{affine}$ transformation.\\\\\nThe condition $\\mathbf{4.209}$ restricts the action of $A_{mn}$ to a combination of rotation/reflection. Indeed, a rotation/reflection can be represented by $R= R_x\\left(\\gamma\\right) \\circ R_y\\left(\\beta\\right)\\circ  R_z\\left(\\alpha\\right)$ with \n\\begin{align}\nR_x = \\begin{pmatrix}\n\\pm 1&0  &0  \\\\\n0&\\cos\\gamma & -\\sin\\gamma \\\\\n 0&\\sin\\gamma & \\cos\\gamma   \\\\\n\\end{pmatrix}\nR_y = \\begin{pmatrix}\n\\cos\\beta & 0& -\\sin\\beta \\\\\n 0& \\pm 1&0 \\\\\n \\sin\\beta & 0& \\cos\\beta\\\\\n\\end{pmatrix}\nR_z = \\begin{pmatrix}\n\\cos\\alpha & -\\sin\\alpha  & 0 \\\\\n \\sin\\alpha & \\cos\\alpha  & 0 \\\\\n  0&0  & \\pm 1 \\\\\n\\end{pmatrix}\n\\end{align}\nNote that for every axis, $R_k^{T} R_k^{} = \\mathbb{I}_3$.\\\\\nBe $A_{mn} = R_x\\left(\\gamma\\right) \\circ R_y\\left(\\beta\\right)\\circ  R_z\\left(\\alpha\\right)$\nWe have by $\\mathbf{4.209}$, $A_{mq}A_{mq}= \\delta_{pq}$ which can be expressed as \n\\begin{align}\nA^{T}A &= \\mathbb{I}_3\\\\\n\\Rightarrow \\spatie \\mathbb{I}_3 &= \\left( R_x R_y R_z\\right)^T R_xR_yR_z\\\\\n&=  \\underbrace{R_z^T \\underbrace{R_y^T\\underbrace{R_x^TR_x}_{= \\mathbb{I}} R_y}_{= \\mathbb{I}}R_z}_{= \\mathbb{I}_3}\n\\end{align}\nThe identity yields, and interpret the coefficients of the orthogonal transformation as an Euclidean orthogonal transformation. \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p123 - Clarification}\n\\begin{tcolorbox}\nIf $A_{n}A_{n} =0$ it follows from $\\mathbf{2.445}$ and $\\mathbf{2.446}$ that the straight line is a geodesic null line.\n\\end{tcolorbox}\nWe have \n\\begin{align}\n\\text{(2.446)}\\spatie & a_{mn}\\dv{x^m}{u}\\dv{x^n}{u}=0 \\spatie \\dv{x^m}{u}= \\dv{z_m}{u} = A_m\\\\\n\\text{(4.215)}\\spatie & a_{mn}=\\delta_{mn}\\\\\n\\text{(1),(2) \\ }\\Rightarrow \\spatie &\\delta_{mn}\\dv{z_m}{u}\\dv{z_n}{u}=0\\\\\n\\Rightarrow \\spatie &A_nA_n=0\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p123 - Clarification}\n\\begin{tcolorbox}\nIt is easy to see ... viz., $$\\mathit{the \\ straight \\ line \\ joining \\ any \\ two \\ points \\ in \\ a \\ plane \\ lies \\ entirely \\ in \\ the \\ plane.}$$ \n\\end{tcolorbox}\nThe plane is identified by \n\\begin{align}\nA_n z_n+B=0\n\\end{align}\nand a line by\n\\begin{align}\nz_n = C_nu+D_n\n\\end{align}\nTake two points at $u=0$ and $u=p$ lying in the plane:\n\\begin{align}\n& \\left\\{ \\begin{array}{l}\nA_nC_np+A_nD_n+B=0\\\\\nA_nD_n+B=0\n\\end{array} \\right.\\\\\n\\Rightarrow\\spatie & \\left\\{ \\begin{array}{l}\nA_nC_np=0\\\\\nA_nD_n+B=0\n\\end{array} \\right.\n\\end{align}\nAnd as $p\\neq 0 \\ \\Rightarrow A_nC_n = 0$. So for any arbitrary $u$ of this line we have\n\\begin{align}\n\\underbrace{A_nC_n}_{=0}u+\\underbrace{A_nD_n}_{=0}+B=0\n\\end{align}\nhence, all points of the line lie in the plane.\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p123 - Exercise}\n\\begin{tcolorbox}\nShow that a one-flat is a straight line.\n\\end{tcolorbox}\nA one-flat means $(N-1)$ equations \n\\begin{align}\nA^{(k)}_nz_n + B^{(k)} =0 \\quad k=1,\\dots,N-1\\quad n= 1,\\dots,N\n\\end{align}\nThis is a set of $(N-1)$ linear equation in $N$ unknown $z_n$. So we have one degree of freedom.\\\\\nE.g. put $z_N=u$ with u the free parameter. then,\n\\begin{align}\nA^{(k)}_{\\alpha}z_{\\alpha}+ A^{(k)}_{N}u+ B^{(k)} =0 \\quad \\alpha=1,\\dots,N-1\n\\end{align}\nIf $detA^{(k)}_{\\alpha} \\neq0$ we get a solution of the et of equation\n\\begin{align}\nAz&=B \\quad\\text{with}\\quad B \\text{ a linear function in } u\\\\\n\\Rightarrow\\spatie z_m&= \\left(A^{-1}B\\right)_m\n\\end{align}\nwith $\\left(A^{-1}B\\right)_m$ of the form $C_mu+D_m$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p126 - Exercise}\n\\begin{tcolorbox}\nShow that the null cone with vertex at the origin in space-time has the equation $$\\mathbf\\spatie y^2_1+y^2_2+y^2_3-y^2_4=0$$\nProve that this null cone divides space-time into three regions such that \\\\\n$\\mathit{a.}$ Any two points (events) both lying in one region can be joined by a continuous curve which does not cut the null cone.\\\\\n$\\mathit{b.}$ All continuous curves joining two given points (events) which lie in different regions, cut the null cone.\\\\\nShow further that the three regions may be further classified into past, present, and future as follows: If $A$ and $B$ are any two points in the past, then the straight segment $AB$ lies entirely in the past. If $A$ and $B$ are any two points in the future, then the straight segment $AB$ lies entirely in the future. If $A$ is any point in the present, there exist at least one point $B$ in the present that the straight segment $AB$ cuts the null cone.\n\\end{tcolorbox}\n\nWe first prove \n$$\\mathbf\\spatie y^2_1+y^2_2+y^2_3-y^2_4=0$$\nThe null geodesic equations:\n\\begin{align}\n& \\left\\{ \\begin{array}{l}\n\\frac{\\delta^2 x^r}{\\delta u^2} = \\dv[2]{x_r}{u} =0 \\quad \\text{ as we use homogeneous coordinates}\\\\\\\\\na_{mn} \\dv{x_m}{u}\\dv{x_n}{u}=0\\\\\n\\end{array} \\right.\\\\\n\\Rightarrow \\spatie & \\left\\{ \\begin{array}{l}\nx_r = A_ru+B_r\\quad \\text{( put } B_r=0 \\text{ by aqequate choice of the origin )} \\\\\\\\\nA_1^2+A_2^2+A_1^2+A_3^2-A_4^2=0\\\\\n\\end{array} \\right.\\\\\n\\Rightarrow \\spatie &\\frac{\\left((x_1)^2+(x_2)^2+(x_3)^2-(x_4)^2\\right)}{u^2} = 0\\quad \\text{ for } u\\neq 0\\\\\n\\Rightarrow \\spatie &(x_1)^2+(x_2)^2+(x_3)^2-(x_4)^2 = 0\n\\end{align}\n$$\\lozenge$$\nAbout the existence of three regions. First let's investigate the case in a $V_3$ space-time manifold in order to have a more intuitive grasp.\\\\\nConsider a family of events $(p_1,p_2,u)$ with $u\\in\\left(-\\infty,\\infty\\right)$ (see the line $P^{'}P^{\"}$ in figure 1.1.)\n\\begin{figure}[H]\n\\input{D:/MathLatex/images/fig_p126_Ex1_a.tex}\n\\caption{Regions delimited by the light cone in a $V_3$ space-time manifold}\n\\label{fig:fig_p96_3415_a}\n\\end{figure}\nBe $R^2 = y_1^2 +y_2^2$. The light cone has the the equation $R^2- y_3^2=0$. Only the events at $ u_0 = \\pm R(p_1,p_2)$ will lie on the light-cone.\\\\\nWe can distinguish three regions:\\\\\nRegion I where $u > u_0 = R$: the events $(p_1,p_2,u)$ will lie on the line above point $P^{'}$.\\\\\nRegion II where $ u < -u_0 = -R$: the events $(p_1,p_2,u)$ will lie on the line below point $P^{\"}$.\\\\\nRegion III where $ -R= -u_0 < u < u_0 = R$: the events $(p_1,p_2,u)$ will lie on the segment $P^{'}P^{\"}$.\\\\\nLet's generalize this now for a $V_4$ space-time manifold.\\\\\nPut $R^2 = (y_1)^2+(y_2)^2+(y_3)^2$ and consider $\\phi(y_1,y_2,y_3,y_4)= (y_1)^2+(y_2)^2+(y_3)^2-(y_4)^2$ so $\\phi(y_1,y_2,y_3,y_4)= R^2-(y_4)^2$.\\\\\nFor $\\phi=0$ we lie on the light-cone.\\\\\nFor $\\phi>0 \\quad\\Rightarrow R^2 > y_4^2$ and so $-R<y_4<R$ defines one region (region III).\\\\\nFor $\\phi<0 \\quad\\Rightarrow R^2 < y_4^2$ and so   $y_4>R$ and $y_4<-R$ define two  regions (region I and II).\\\\$$\\lozenge$$\\\\\\\\\n\\textbf{We now show statement $\\mathit{a.}$ of the exercise.}\\\\\nConsider $2$ events $P_0,\\ P_1$ with coordinates $(y_1^{(0)},y_2^{(0)},y_3^{(0)},y_4^{(0)})$ and $(y_1^{(1)},y_2^{(1)},y_3^{(1)},y_4^{(1)})$  and a curve defined by \n\\begin{align}y_i= \\pm\\sqrt{\\left(\\left(y_i^{(1)}\\right)^2-\\left(y_i^{(0)}\\right)^2\\right)u + \\left(y_i^{(0)}\\right)^2}\\spatie u\\in \\left[0,1\\right]\n\\end{align}\nwhere the $\\pm$ is chosen so that $y_i(0) = y_i^{(0)}$ and $y_i(1) = y_i^{(1)}$ and that the sign only changes when $y_i(u)=0$ and $sign\\left(y_i^{(0)}\\right) \\neq sign\\left(y_i^{(1)}\\right)$. Such curve will be continuous.\nPut\n\\begin{align}\nR^2&= \\left(y_1\\right)^2+\\left(y_2\\right)^2+\\left(y_3\\right)^2\\\\\n{R_{0}}^2&= \\left(y^0_1\\right)^2+\\left(y^0_2\\right)^2+\\left(y^0_3\\right)^2\\\\\n{R_{1}}^2&= \\left(y^1_1\\right)^2+\\left(y^1_2\\right)^2+\\left(y^1_3\\right)^2\n\\end{align}\nFor the points on the curve defined by  (5), $R^2$ can then be written as \n\\begin{align}\nR^2&= \\left(R_1^2-R_0^2\\right)u+R_0^2\n\\end{align}\nBe $\\phi(u)= R^2-y_4^2$.\\\\\n\\textbf{Case a1: $P_0, P_1$ both lie in region I or both in region II.} Then,\\\\\n\\begin{align}\n\\phi(u) & < 0\\quad \\forall \\ u\\in \\left[0,1\\right]\\\\\n\\Rightarrow\\quad R_0^2 < (y_4^{0})^2 \\quad &\\wedge \\quad  R_1^2 < (y_4^{1})^2 \\\\ \\text{ with }   (y_4^{0}>0 \\  \\wedge \\ y_4^{1}>0)\\text{ in Region I}\\quad &\\vee \\quad (y_4^{0}<0\\quad \\wedge \\quad y_4^{1}<0)  \\text{ in Region II}\n\\end{align}\nThen, $$\\cancel{\\exists } \\  u \\in \\left[0,1\\right]: \\phi(u)=0$$\nIndeed,\n\\begin{align}\n\\phi(u) &= \\left(R_1^2-R_0^2\\right)u+R_0^2 + \\left(\\left(y_4^{(0)}\\right)^2   -\\left(y_4^{(0)}\\right)^2 \\right)u -\\left(y_4^{(0)}\\right)^2\\\\\n\\phi(u)=0\\spatie \\Rightarrow u&= -\\frac{R_0^2- \\left(y_4^{(0)}\\right)^2}{R_1^2-R_0^2  -\\left(y_4^{(1)}\\right)^2  +\\left(y_4^{(0)}\\right)^2}\n\\end{align}\nLet's simplify notationally the last equation. Put $R_0^2- \\left(y_4^{(0)}\\right)^2=-\\tau $ and $R_1^2- \\left(y_4^{(1)}\\right)^2=-\\sigma$ with both $\\tau, \\sigma > 0$. $(14)$ can be written as\n\\begin{align}\nu&=\\frac{\\tau}{\\tau-\\sigma}\\\\\n &=\\frac{1}{1-\\frac{\\sigma}{\\tau}}\\\\\n\\Rightarrow\\spatie \\left|u\\right| & > 1 \\spatie \\text{ as } \\frac{\\sigma}{\\tau} >0\n\\end{align}\nNote, that in the case $\\tau=\\sigma$ we have $\\phi(u)= \\tau = \\text{ constant}$ and can't reach $0$.\nSo, there exist no $u\\in\\left[0,1\\right]$ for which $\\phi(u)=0$ and the curve does not intersect the null cone.\\\\\\\\\n\\textbf{Case a2: $P_0, P_1$ both lie in region III.} Then,\\\\\n\\begin{align}\n\\phi(u) & > 0\\quad \\forall \\ u\\in \\left[0,1\\right]\\\\\n\\Rightarrow\\quad R_0^2 > (y_4^{0})^2 \\quad &\\wedge \\quad  R_1^2 > (y_4^{1})^2 \n\\end{align}\nThen, $$\\cancel{\\exists } \\  u \\in \\left[0,1\\right]: \\phi(u)=0$$\nIndeed,\nLet's simplify  notationally the  equation (14) by now by puting $R_0^2- \\left(y_4^{(0)}\\right)^2=\\tau $ and $R_1^2- \\left(y_4^{(1)}\\right)^2=\\sigma$ with both $\\tau, \\sigma > 0$. $(14)$ can be written again as\n\\begin{align}\nu& =\\frac{1}{1-\\frac{\\sigma}{\\tau}}\n\\end{align}\nand follow the same reasoning as in case 1.\nSo, there exist no $u\\in\\left[0,1\\right]$ for which $\\phi(u)=0$ and the curve does not intersect the null cone.\\\\\\\\\n\\\\$$\\lozenge$$\\\\\\\\\n\\textbf{We now show statement $\\mathit{b.}$ of the exercise.}\\\\\\\\\n\n\\textbf{Case b1: $P_0$ lies in region I, $P_1$  lies in region II.} \\\\\nThose two regions are separated by the $3$-flat (plane) $y_4=0$. So it's suffice that $R^2=0$ for $\\phi(u)$ being zero. Hence $y_i=0$, $  i=1,2,3$, and the cruve will cut the cone at it's apex.\n\\\\\\\\\n\\textbf{Case b2: $P_0$ lies in region I or II, $P_1$  lies in region III.} \\\\\nWe have \n\\begin{align}\nR_0^2 > (y_4^{0})^2\\quad R_1^2 < (y_4^{1})^2\n\\end{align}\nPut $R_0^2 - (y_4^{0})^2= \\tau$ and $R_1^2 - (y_4^{1})^2 =-\\sigma$ with $\\tau,\\sigma >0$. We get\n\\begin{align}\n\\phi(u)&=0\\\\\n\\Rightarrow \\spatie u&=-\\frac{\\tau}{-\\sigma-\\tau}\\\\\n&= \\frac{1}{1+\\frac{\\sigma}{\\tau}}\n\\end{align}\nSo, there is a solution $u\\in \\left[0,1\\right]$ for which $\\phi(u)=0$ and the curve intersects the null cone.\n\\\\$$\\lozenge$$\\\\\\\\\n\n\\textbf{We now investigate the straight segment questions.} \\\\\nCase 1: $A$ and $B$ both lie in the the present (region I) or in the past (region II)\\\\\nConsider $2$ events $P_0,\\ P_1$ with coordinates $(y_1^{(0)},y_2^{(0)},y_3^{(0)},y_4^{(0)})$ and $(y_1^{(1)},y_2^{(1)},y_3^{(1)},y_4^{(1)})$  and a segment  defined by \n\\begin{align}y_i= \\left(y_i^{(1)}-y_i^{(0)}\\right)u + y_i^{(0)}\\spatie u\\in \\left[0,1\\right]\n\\end{align}\nBe $\\phi(u)= y_1^2+y_2^2+y_3^2-y_4^2$.\\\\\nThen,\n \\begin{align}\n\\phi(u) &= \\left\\{\\begin{array}{l} \\ \\ \\left[\\left(y_1^{(1)}-y_1^{(0)}\\right)u + y_1^{(0)}\\right]^2\\\\\n+\\left[\\left(y_2^{(1)}-y_2^{(0)}\\right)u + y_2^{(0)}\\right]^2\\\\\n+\\left[\\left(y_3^{(1)}-y_3^{(0)}\\right)u + y_3^{(0)}\\right]^2\\\\\n-\\left[\\left(y_4^{(1)}-y_4^{(0)}\\right)u + y_4^{(0)}\\right]^2\\\\\n\\end{array}\\right.\\\\\n&= \\left\\{\\begin{array}{l} \\ \\ \n\\left(y_1^{(1)}\\right)^2 u^2+\\left(y_1^{(0)}\\right)^2 u^2 - 2y_1^{(1)}y_1^{(0)}u^2 + 2y_1^{(1)}y_1^{(0)}u-  2\\left(y_1^{(0)}\\right)^2 u+ \\left(y_1^{(0)}\\right)^2\\\\\n+\\left(y_2^{(1)}\\right)^2 u^2+\\left(y_2^{(0)}\\right)^2 u^2 - 2y_2^{(1)}y_2^{(0)}u^2 + 2y_2^{(1)}y_2^{(0)}u-  2\\left(y_2^{(0)}\\right)^2 u+ \\left(y_2^{(0)}\\right)^2\\\\\n+\\left(y_3^{(1)}\\right)^2 u^2+\\left(y_3^{(0)}\\right)^2 u^2 - 2y_3^{(1)}y_3^{(0)}u^2 + 2y_3^{(1)}y_3^{(0)}u-  2\\left(y_3^{(0)}\\right)^2 u+ \\left(y_3^{(0)}\\right)^2\\\\\n-\\left(y_4^{(1)}\\right)^2 u^2-\\left(y_4^{(0)}\\right)^2 u^2 + 2y_4^{(1)}y_4^{(0)}u^2 - 2y_4^{(1)}y_4^{(0)}u+  2\\left(y_4^{(0)}\\right)^2 u- \\left(y_4^{(0)}\\right)^2\\\\\n\\end{array}\\right.\n\\end{align}\nPut $\\phi_0 = \\left(y_1^{(0)}\\right)^2+\\left(y_2^{(0)}\\right)^2+\\left(y_3^{(0)}\\right)^2-\\left(y_4^{(0)}\\right)^2$ and $\\phi_1 = \\left(y_1^{(1)}\\right)^2+\\left(y_2^{(1)}\\right)^2+\\left(y_3^{(1)}\\right)^2-\\left(y_4^{(1)}\\right)^2$. \\\\\nThen,\n\\begin{align}\n\\phi(u)= \\left\\{\\begin{array}{l} \\ \\ \n\\phi_1u^2+\\phi_0u^2-2\\left(y_1^{(1)}y_1^{(0)}+y_2^{(1)}y_2^{(0)}+y_3^{(1)}y_3^{(0)}-y_4^{(1)}y_4^{(0)}\\right)u^2 \\\\\n-2\\phi_0 u + 2 \\left(y_1^{(1)}y_1^{(0)}+y_2^{(1)}y_2^{(0)}+y_3^{(1)}y_3^{(0)}-y_4^{(1)}y_4^{(0)}\\right)u\\\\\n+\\phi_0\n\\end{array}\\right.\n\\end{align}\nLet's put $\\kappa = y_1^{(1)}y_1^{(0)}+y_2^{(1)}y_2^{(0)}+y_3^{(1)}y_3^{(0)}-y_4^{(1)}y_4^{(0)}$, we get the expression\n\\begin{align}\n\\phi(u)&= \n\\left(\\phi_1 +\\phi_0-2\\kappa\\right) u^2 + 2 \\left(\\kappa- \\phi_0\\right)u\n+\\phi_0\n\\end{align}\n\n\nThe function $\\phi(u)$ is a parabola. \n\\begin{figure}[H]%\n    \\centering\n    \\subfloat[]{\\input{D:/MathLatex/images/fig_p126_Ex1_c1.tex}}\n\t\\qquad\n    \\subfloat[]{\\input{D:/MathLatex/images/fig_p126_Ex1_c2.tex}}\n    \\qquad\n    \\subfloat[]{\\input{D:/MathLatex/images/fig_p126_Ex1_c3.tex}}\n\\caption{Non problematic null cone parametric functions.}\n\\label{fig:fig_p126_1a}\n\\end{figure}\n\\begin{figure}[H]%\n    \\centering\n    \\subfloat[]{\\input{D:/MathLatex/images/fig_p126_Ex1_c4.tex}}\n\\caption{Problematic null cone parametric functions.}\n\\label{fig:fig_p126_1b}\n\\end{figure}From the parabola's in figure $1.2.$ it is clear that the function can't reach $0$ in $u\\in(0,1)$  and hence that the segment will not intersect the null cone.\\\\\nOne problematic could occur as represented in figure $1.3$.\nFor such a parabola, we have :\n\\begin{align}\n\\left\\{\\begin{array}{l} \\ \\ \n\\phi(u)= au^2+bu+c\\\\\\\\\na = \\left(\\phi_1 +\\phi_0-2\\kappa\\right) <0\\\\\\\\\nb=2 \\left(\\kappa- \\phi_0\\right)\\\\\\\\\nc=\\phi_0\\\\\\\\\na+b=\\phi_1-\\phi_0\\\\\\\\\n\\phi_0<0\\\\\\\\\n\\phi_1 < 0\n\\end{array}\\right.\n\\end{align}\nFrom the $3$ known inequalities \n\\begin{align}\n\\left\\{\\begin{array}{l} \\ \\ \na < 0\\\\\\\\\n\\phi_0<0\\\\\\\\\n\\phi_1 < 0\n\\end{array}\\right.\n\\end{align}\nwe get\n\\begin{align}\n\\left\\{\\begin{array}{l} \\ \\ \na < 0\\quad\\Rightarrow\\quad \\kappa > \\frac{\\phi_1+\\phi_0}{2} \\\\\\\\ b=2 \\left(\\kappa- \\phi_0\\right)\\quad \\Rightarrow\\quad b > \\phi_1-\\phi_0\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nNote that there is nothing special in the choice of $\\phi_1, \\ \\phi_0$ as the segment is not oriented and as $\\phi_1,\\phi_0 <0$ we can put arbitrarily $b \\geq0$ with $\\phi_1 \\geq \\phi_0$.\\\\ \nLet's examine if there is a value $u_{max} \\in (0,1)$ such that $\\phi(u_{max})\\geq 0$ and let us investigate whether the relation between the coefficients $a,b$ does not lead to a contradiction for such value of $u_{max} \\in (0,1)$.  \n\\begin{align}\n\\dv{\\phi(u)}{u}&=0\\\\\n\\Rightarrow\\spatie u_{max} &= -\\frac{b}{2a}\\quad\\text{ with } 0<b < -2a\\\\\n\\phi(u_{max}) &= -\\frac{b^2}{4a}+\\phi_0\n\\end{align}\nIs it possible to have $\\phi(u_{max}) \\geq 0$ with $u_{max} \\in (0,1)$? One straightforward condition to have this possible is that the discriminant of the quadratic equation os $b^2-4ac>=0$.\nHence,\n\\begin{align}\nD &= \\left[2 \\left(\\kappa- \\phi_0\\right)\\right]^2-4\\left(\\phi_1 +\\phi_0-2\\kappa\\right)\\phi_0\\\\\n&= 4\\kappa^2+ 4\\phi_0^2-8\\kappa\\phi_0-4\\phi_1\\phi_0 -4\\phi_0^2+8\\kappa\\phi_0\\\\\n&= 4\\left(\\kappa^2-\\phi_1\\phi_0\\right)\\\\\n&= \\left\\{\\begin{array}{l} \\ \\ \n4\\left[\\left(y_1^{(0)}y_4^{(1)}-y_4^{(0)}y_1^{(1)}\\right)^2\n+\\left(y_4^{(0)}y_2^{(1)}-y_2^{(0)}y_4^{(1)}\\right)^2\n+\\left(y_4^{(0)}y_3^{(1)}-y_3^{(0)}y_4^{(1)}\\right)^2\\right]\\\\\\\\\n-4\\left[\\left(y_2^{(0)}y_1^{(1)}-y_1^{(0)}y_2^{(1)}\\right)^2\n+\\left(y_3^{(0)}y_1^{(1)}-y_1^{(0)}y_3^{(1)}\\right)^2\n+\\left(y_3^{(0)}y_2^{(1)}-y_2^{(0)}y_3^{(1)}\\right)^2\\right]\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nObviously, this path of proving leads to nothing as $D$ can be positive even for a segment lying entirely in zone $I$ or $II$. To see that, take two events, stationary in  the space  at the point $P\\left(0,0,y_3^{(0)}\\right)$. The negative term in (39) disappears and obviously $D>0$.\\\\'\nWHAT IS THE ANALYTICAL WAY TO PROVE THIS? IS $a>0$ A CONDITION?\n\\begin{comment}\n\\begin{figure}[H]\n\\input{D:/MathLatex/images/fig_p126_Ex1_b.tex}\n\\caption{Travelling between two points in region III (present) in a  $V_3$ space-time manifold}\n\\label{fig:fig_p96_3415_b}\n\\end{figure}\n\\end{comment}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p133 - Exercise}\n\\begin{tcolorbox}\nIn a space of two dimensions prove the relation\n$$\\mathbf{4.318.}\\spatie \\epsilon_{mp}\\epsilon_{mq} = \\delta_{pq}$$\n\\end{tcolorbox}\nSuppose $p=q$, then in the summation the term is $0$ if $m=p=q$ and the remaining term is $1\\times 1$ or $-1\\times -1$ giving indeed $\\delta_{pq}=1$.\\\\ \nIf  $p\\neq q$ we get either $m=p$ or $m=q$ in each term of the summation and hence all terms vanish.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p135 - Clarification}\n\\begin{tcolorbox}\n$$\\mathbf{4.324.}\\spatie P_{mn}= \\epsilon_{mnrs}X_rY_s$$\nIn 4.323 a skew-symmetric tensor is formed.\n\\end{tcolorbox}\nLet's check whether $P_{mn}$ is indeed a tensor and if it is an oriented one.\nBe an orthogonal transformation (proper or not)\n\\begin{align}\nX^{'}_r = A_{rm}X_m+A_r\n\\end{align}\nand let's check how the expression $P^{'}_{mn}= P_{rs}\\partial_m X_r \\partial_n X_s$ behaves.\n\n\\begin{align}\nP^{'}_{mn}&= P_{rs}\\partial_m z_r \\partial_n z_s\\\\\n\\mathbf{(4.303.)\\ }\\Rightarrow \\spatie &= \\epsilon_{rspq}X_pY_q A_{mr}A_{ns}\n\\end{align}\nFrom (4.302.) we have\n\\begin{align}\nX_p = A_{kp}X^{'}_k -  A_{kp}A_k\n\\end{align}\nReplacing this in (3)\n\\begin{align}\nP^{'}_{mn}&=  \\epsilon_{rspq}\\left(A_{kp}X^{'}_k -  A_{kp}A_k\\right)\\left(A_{tq}Y^{'}_t -  A_{tq}A_t\\right) A_{mr}A_{ns}\\\\\n&=\\left\\{\\begin{array}{l}\n\\epsilon_{rspq}A_{mr}A_{ns}A_{kp}A_{tq}X^{'}_kY^{'}_t \\\\\\\\\n-\\epsilon_{rspq}A_{mr}A_{ns}A_{kp}A_{tq}X^{'}_kA_t \\\\\\\\\n-\\epsilon_{rspq}A_{mr}A_{ns}A_{kp}A_{tq}Y^{'}_tA_k \\\\\\\\\n+\\epsilon_{rspq}A_{mr}A_{ns}A_{kp}A_{tq}A_kA_t \n\\end{array}\\right.\\\\\n&= \\epsilon_{rspq}A_{mr}A_{ns}A_{kp}A_{tq}\\left(X^{'}_k-A_k\\right)\\left(Y^{'}_t-A_t\\right)\n\\end{align}\nA analogous reasoning as in (4.316.) gives us $\\epsilon_{mnkt}\\left|A_{mr}\\right|=\\epsilon_{rspq}A_{mr}A_{ns}A_{kp}A_{tq}$ and so \n\\begin{align}\nP^{'}_{mn}&= \\epsilon_{mnkt}\\left|A_{mr}\\right| \\left(X^{'}_k-A_k\\right)\\left(Y^{'}_t-A_t\\right)\n\\end{align}\nApparently, even with $\\left|A_{mr}\\right| =1$ , $P_{mn}$ does not behave like a tensor due to the $ \\left(X^{'}_k-A_k\\right)\\left(Y^{'}_t-A_t\\right)$ components. But of course, this is consequence of the sloppy use of the transformation equation: equation (1) is the transformation rule for a point in the $V_4$ space but the object $P_{mn}$ takes two vectors as input. If we consider a vector as an object defined by an ordered pair i.e. $X\\equiv \\left(z^{(1)}_{(X)}, z^{(0)}_{(X)}\\right)$ then $P_{mn}$ should be defined as $P_{mn}= \\epsilon_{mnrs}\\left(z^{(1)}_{(X)r}- z^{(0)}_{(X)r}\\right)\\left(z^{(1)}_{(Y)s}- z^{(0)}_{(Y)s}\\right)$. This means that when using the transformation rule (1) we will get $$X^{'}\\equiv \\left(z^{'(1)}_{(X)}, z^{'(0)}_{(X)}\\right)$$ giving as components \n\\begin{align}X^{'}_r &= z^{'(1)}_{(X)r}- z^{'(0)}_{(X)r}\\\\&=   A_{rm}z^{(1)}_{(X)m}+A_r-A_{rm}z^{(0)}_{(X)m}-A_r\\\\\n&= A_{rm}\\left(z^{(1)}_{(X)m} -z^{(0)}_{(X)m}\\right)\n\\end{align}\nReplacing all this we get as a more correct representation of $p_{mn}$ and $P^{'}_{mn}$:\n\\begin{align}\n\\left\\{\\begin{array}{l}\nP_{mn}= \\epsilon_{mnrs}\\left(z^{(1)}_{(X)r}- z^{(0)}_{(X)r}\\right)\\left(z^{(1)}_{(Y)s}- z^{(0)}_{(Y)s}\\right)\\\\\\\\\nP^{'}_{mn}= \\epsilon_{mnkt}\\left|A_{mr}\\right| \\left(z^{'(1)}_{(X)r}- z^{'(0)}_{(X)r}\\right)\\left(z^{'(1)}_{(Y)s}- z^{'(0)}_{(Y)s}\\right)\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nWe see that indeed $P_{mn}$ is an oriented Cartesian tensor.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p135 - Exercise}\n\\begin{tcolorbox}\nWrite out the six independent non-zero components of $P_{mn}$ as given by $\\mathbf{4.324.}$\n\\end{tcolorbox}\nWe have \n\\begin{align}\n\\mathbf{4.324.}\\spatie P_{mn}= \\in_{mnrs}X^rY^s\\\\\n\\text{with}\\quad \\spatie m=n \\quad \\Rightarrow \\quad P_{mn}= 0\n\\end{align}\nSo, the six independent components are in the set $\\{mn\\}= \\left\\{12,13,14,23,24,34 \\right\\}$ as $P_{nm}=-P_{mn}$.\n\\begin{align}\n&\\left\\{\\begin{array}{l}\\\\\nP_{12} = \\in_{1234}X^3Y^4+\\in_{1243}X^4Y^3\\\\\\\\\nP_{13} = \\in_{1324}X^2Y^4+\\in_{1342}X^4Y^2\\\\\\\\\nP_{14} = \\in_{1423}X^2Y^3+\\in_{1432}X^3Y^2\\\\\\\\\nP_{23} = \\in_{2314}X^1Y^4+\\in_{2341}X^4Y^1\\\\\\\\\nP_{24} = \\in_{2413}X^1Y^3+\\in_{2431}X^3Y^1\\\\\\\\\nP_{34} = \\in_{3412}X^1Y^2+\\in_{3421}X^2Y^1\\\\\\\\\n\\end{array}\\right.\\\\\n&\\left\\{\\begin{array}{l}\\\\\nP_{12} = X^3Y^4-X^4Y^3\\\\\\\\\nP_{13} = -X^2Y^4+X^4Y^2\\\\\\\\\nP_{14} = X^2Y^3-X^3Y^2\\\\\\\\\nP_{23} = X^1Y^4-X^4Y^1\\\\\\\\\nP_{24} = -X^1Y^3+X^3Y^1\\\\\\\\\nP_{34} = X^1Y^2-X^2Y^1\\\\\\\\\n\\end{array}\\right.\n\\end {align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p136 - Exercise}\n\\begin{tcolorbox}\nTranslate the well-known vector relations\n$$A\\times (B\\times C)= B(A.  C)-C(A.B)$$\n$$\\nabla \\times (\\nabla \\times V)= \\nabla (\\nabla .  V )-\\nabla^2V$$\ninto Cartesian tesnor form, and prove the by use of $4.329$.\n\\end{tcolorbox}\nWe have \n\\begin{align}\n\\mathbf{4.329.}\\spatie \\in_{mrs}\\in_{mpq} = \\delta_{rp}\\delta_{sq}-\\delta_{rq}\\delta_{sp}\n\\end{align}\nThe first identity\n\\begin{align}\nA\\times (B\\times C)= B(A.  C)-C(A.B)\\\\\n\\Leftrightarrow\\spatie \\in_{npm}\\in_{mrs}A_p B_r C_s = A_p\\left(B_n C_p-C_n B_p\\right)\n\\end{align}\nIndeed,\n\\begin{align}\n(B\\times C)_m &= \\in_{mrs}B_rC_s\\\\\n\\Rightarrow\\spatie \\left(A\\times (B\\times C)\\right)_n &=\\in_{npm}A_p \\in_{mrs}B_rC_s\\\\\n&=-\\in_{mpn}\\in_{mrs}A_p \\in_{mrs}B_r C_s\\\\\n&= -\\delta_{pr}\\delta_{ns}A_pB_rC_s+\\delta_{ps}\\delta_{nr}A_pB_rC_s\\\\\n&= A_pB_nC_p-A_pB_pC_n\\\\\n\\Leftrightarrow\\spatie & B(A.  C)-C(A.B)\n\\end{align}\nThe second identity\n\\begin{align}\n\\nabla \\times (\\nabla \\times V)&= \\nabla (\\nabla .  V )-\\nabla^2V\\\\\n\\Leftrightarrow \\spatie \\in_{nrm}\\in_{mpq}V_{q,pr} &= V_{p,pn}- V_{n,pp}\n\\end{align}\nIndeed,\n\\begin{align}\n\\left(\\nabla \\times V\\right)_m &= \\in_{mpq}V_{q,p}\\\\\n\\Rightarrow\\spatie \\left(\\nabla  \\times (\\nabla \\times V)\\right)_n &=\\in_{nrm}\\left(\\in_{mpq}V_{q,p}\\right)_{,r}\\\\\n &=\\in_{nrm}\\in_{mpq}V_{q,pr}\\\\\n &=\\delta_{rq}\\delta_{np}V_{q,pr}-\\delta_{pr}\\delta_{nq}V_{q,pr}\\\\\n &= V_{p,pn}-V_{n,pp}\n\\end{align}\nWe have also\n\\begin{align}\n\\left(\\nabla V\\right) &= V_{p,p}\\\\\n\\Rightarrow\\spatie \\left(\\nabla (\\nabla .  V )\\right)_n &= \\left(V_{p,p}\\right)_n\\\\\n&= V_{p,pn}\n\\end{align}\nand \n\\begin{align}\n\\nabla^2 V_n  & \\equiv  V_{n,pp} \\\\\n\\Rightarrow\\spatie \\left(\\nabla (\\nabla .  V )\\right)_n- \\nabla^2 V_n &= V_{p,pn}- V_{n,pp}\n\\end{align}\nwhich corresponds to (15).\nSo the tensor expression in Cartesian tensor form can be written as \n$$\\in_{nrm}\\in_{mpq}V_{q,pr} = V_{p,pn}- V_{n,pp}$$\n\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p139 - Exercise 1.}\n\\begin{tcolorbox}\nShow that, in a 3-space of constant curvature $-\\frac{1}{R^2}$ and positive definite metric form, the line element in polar coordinate is \n$$ds^2= dr^2+R^2\\sinh^2\\left(\\frac{r}{R}\\right)\\left(d\\theta^2+\\sin^2\\theta d\\phi^2\\right)$$\n\\end{tcolorbox}\nWe have by $4.120c$\n\\begin{align}\nX_r \\eta^r &= A\\sinh \\left(s\\sqrt{-\\epsilon K}\\right)\n\\end{align}\nWe choose $N$ different $X^{(k)}_r$ $(k= 1,2,\\dots, N)$ which are orthonormal.\nApplying $(1)$ $N$ times with the different $X^{(k)}_r$ $(k= 1,2,\\dots, N)$, we get\n\\begin{align}\nX^{(k)}_r \\eta^r &= A^{(k)}\\sinh \\left(s\\sqrt{-\\epsilon K}\\right)\n\\end{align}\nBut as the $X^{(k)}_r$ are orthonormal and are used as a basis at the considered point of the geodesic we have \n\\begin{align}\nX^{(k)}_r &= \\delta^k_r\n\\end{align}\nSo, $(2)$ becomes\n\\begin{align}\n\\eta^k &= A^{(k)}\\sinh \\left(s\\sqrt{-\\epsilon K}\\right)\n\\end{align}\nwhich are the components of the displacement vector in the orthonormal basis. By $\\mathbf{2.301.}$ :\n\\begin{align}\nY^2 &= \\epsilon a_{mn} Y^m Y^n\\\\\n\\Rightarrow \\spatie \\eta^2 &= \\epsilon a_{mn} A^{(m)} A^{(n)}\\sinh^2 \\left(s\\sqrt{-\\epsilon K}\\right)\\\\\n\\Rightarrow \\spatie \\eta &= C\\left|\\sinh \\left(s\\sqrt{-\\epsilon K}\\right)\\right|\\\\\n\\text{with}\\spatie C&= \\sqrt{\\left|\\epsilon a_{mn} A^{(m)} A^{(n)}\\right|}\n\\end{align}\nAs $\\epsilon =1$ (positive-definite metric) and $K=-\\frac{1}{R^2}$\nwe have\n\\begin{align}\n\\eta &= C\\left|\\sinh \\left(\\frac{s}{R}\\right)\\right|\n\\end{align}\nFrom this and using the very same reasoning from $4.126.$ to $4.130.$ (pages 117-119) we get \n$$ds^2= dr^2+R^2\\sinh^2\\left(\\frac{r}{R}\\right)\\left(d\\theta^2+\\sin^2\\theta d\\phi^2\\right)$$\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p139 - Exercise 2.}\n\\begin{tcolorbox}\nShow that the volume of an antipodal 3-space of positive-definite metric form and positive constant curvature $\\frac{1}{R^2}$ is $2\\pi^2R^3$. (Use the equation 4.130. to find the area of a sphere $r= \\text{constant}$ in polar coordinates. Multiply by $dr$ and integrate for $0\\leq r \\leq \\pi R$ to get the volume). What is the volume if the space is polar?\n\\end{tcolorbox}\nWe have  $4.130$\n\\begin{align}\nds^2= dr^2+R^2\\sin^2\\left(\\frac{r}{R}\\right)\\left(d\\theta^2+\\sin^2\\theta d\\phi^2\\right)\n\\end{align}\nHaving a positive-definite metric form, the space can be locally considered as Euclidean and an elementary area of a  surface with constant $r (\\rightarrow dr=0)$ can be calculated as $dS=ds_{d\\theta=0}ds_{d\\phi=0}$ and get by (1)\n\\begin{align}\ndS &= R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin\\theta d\\phi d\\theta\\\\\n\\Rightarrow\\spatie\\frac{S}{8} &= R^2\\sin^2\\left(\\frac{r}{R}\\right)\\int^{\\frac{\\pi}{2}}_{0}\\int^{\\frac{\\pi}{2}}_{0} \\sin\\theta d\\phi d\\theta\\\\ \n&= R^2\\sin^2\\left(\\frac{r}{R}\\right)\\frac{\\pi}{2} \\left.\\left(-\\cos\\theta \\right)\\right|^{\\frac{\\pi}{2}}_{0}\\\\\n\\Rightarrow\\spatie S&= 4\\pi R^2\\sin^2\\left(\\frac{r}{R}\\right)\n\\end{align}\nWe see that the area is a cyclic function of $r$ having zeros' at $r= k\\frac{\\pi}{R }, k=1,2,\\dots$\n\\begin{figure}[H]\n\\begin{center}\n\\input{D:/MathLatex/images/fig_p138_Ex2.tex}\n\\caption{Area of an antipodal 3-space of positive-definite metric form}\n\\label{fig:fig_p138_Ex2}\n\\end{center}\n\\end{figure}\nSo, there are good reasons to restrict $r$ to $[0,\\pi R]$ as otherwise all space of that type would have infinite volume, whatever it's curvature. So, we get as volume \n\\begin{align}\nV &= 4\\pi R^2\\int^{\\pi R}_{0}\\sin^2\\left(\\frac{r}{R}\\right)dr\\\\\n&= 4\\pi R^3\\int^{\\pi R}_0\\sin^2\\left(\\frac{r}{R}\\right)d\\left(\\frac{r}{R}\\right)\\\\\n&= 4\\pi R^3\\left.\\left( \\half x - \\frac{1}{4}\\sin2x \\right)\\right|^{\\pi}_0\\\\\n&= 2\\pi^2 R^3\n\\end{align}\nFo a polar space, the volume would be half of that of an antipodal one (with same curvature of course) as in (3) we would consider only 4 quadrants instead of 8.\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p139 - Exercise 3.}\n\\begin{tcolorbox}\nBy direct calculation of the tensor $R_{rsmn}$ verify that $\\mathbf{4.130.}$ is the metric form of a space of constant curvature.\n\\end{tcolorbox}\nWe have  $4.130$\n\\begin{align}\nds^2&= dr^2+R^2\\sin^2\\left(\\frac{r}{R}\\right)\\left(d\\theta^2+\\sin^2\\theta d\\phi^2\\right)\\\\\n\\Rightarrow\\spatie &\n\\ (a_{mn}) = \\begin{pmatrix}\n 1& 0 & 0\\\\\n0 & R^2\\sin^2\\left(\\frac{r}{R}\\right) & 0 \\\\\n0 & 0 & R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta \\\\\n\\end{pmatrix}\n\\end{align}\nNow for $R_{rsmn}$ we refer to exercise 7 page 109 of chapter 3, where the curvature tensor was calculated for a general case of the form \n$$ ds^2= (h_1dx^1)^2+(h_2dx^2)^2+(h_3dx^3)^2$$ where $h_1, h_2, h_3$ are functions of the three coordinates.\nWe have then for our case\n\\begin{align}\n\\left\\{\\begin{array}{l}\nh_1 = 1\\\\\\\\\nh_2 = R\\sin\\left(\\frac{r}{R}\\right)\\\\\\\\\nh_3 = R\\sin\\left(\\frac{r}{R}\\right)\\sin\\theta\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nIn the exercise we got for the non-vanishing curvature tensors\n\\begin{align}\nR_{1212}&=\n-h_2\\partial_{11}^2(h_2)-h_1\\partial_{22}^2(h_1)\n+\\frac{h_2}{h_1}\\partial_1 h_1\\partial_1 h_2+\\frac{h_1}{h_2}\\partial_2 h_1\\partial_2 h_2-\\frac{h_1 h_2}{h_3^2}\\partial_3 h_1\\partial_3 h_2\\\\\nR_{2323}&=\n-h_3\\partial_{22}^2(h_3)-h_2\\partial_{33}^2(h_2)\n+\\frac{h_3}{h_2}\\partial_2 h_2\\partial_2 h_3+\\frac{h_2}{h_3}\\partial_3 h_2\\partial_3 h_3-\\frac{h_2 h_3}{h_1^2}\\partial_1 h_2\\partial_1 h_3\\\\\nR_{1313}&=\n-h_3\\partial_{11}^2(h_3)-h_1\\partial_{33}^2(h_1)\n+\\frac{h_3}{h_1}\\partial_1 h_1\\partial_1 h_3+\\frac{h_1}{h_3}\\partial_3 h_1\\partial_3 h_3-\\frac{h_1 h_3}{h_2^2}\\partial_2 h_1\\partial_2 h_3\n\\end{align}\n\\begin{align}\nR_{1213}&=-h_1\\partial_{32}^2(h_1)+\\frac{h_1}{h_3}\\partial_2 h_3\\partial_3 h_1+\\frac{h_1}{h_2}\\partial_2 h_1\\partial_3 h_2\\\\\nR_{1223}&=h_2\\partial_{31}^2(h_2)-\\frac{h_2}{h_1}\\partial_1 h_2\\partial_3 h_1-\\frac{h_2}{h_3}\\partial_3 h_2\\partial_1 h_3\\\\\nR_{1323}&=\n-h_3\\partial_{21}^2(h_3)+\\frac{h_3}{h_1}\\partial_1 h_3\\partial_3 h_1+\\frac{h_3}{h_2}\\partial_2 h_3\\partial_1 h_2\n\\end{align}\nClearly $\\partial_{k}^2(h_1)=0$ and $\\partial_{mn}^2(h_1)=0$ and considering $h_2 = h_2(r), \\ h_3 = h_3(r,\\theta)$\nwe can simplify \n\\begin{align}\nR_{1212}&=\n-h_2\\partial_{11}^2(h_2)\\\\\nR_{2323}&=\n-h_3\\partial_{22}^2(h_3)\n-\\frac{h_2 h_3}{h_1^2}\\partial_1 h_2\\partial_1 h_3\\\\\nR_{1313}&=\n-h_3\\partial_{11}^2(h_3)\n\\end{align}\n\\begin{align}\nR_{1213}&=0\\\\\nR_{1223}&=0\\\\\nR_{1323}&=\n-h_3\\partial_{21}^2(h_3)+\\frac{h_3}{h_2}\\partial_2 h_3\\partial_1 h_2\n\\end{align}\nwith \n\\begin{align}\n\\left\\{\\begin{array}{l}\n\\partial_1 h_2=\\cos\\left(\\frac{r}{R}\\right)\\\\\\\\\n\\partial_1 h_3=\\cos\\left(\\frac{r}{R}\\right)\\sin\\theta\\\\\\\\\n\\partial_2 h_3=R\\sin\\left(\\frac{r}{R}\\right)\\cos\\theta\\\\\\\\\n\\partial^2_{11} h_2=-\\frac{1}{R}\\sin\\left(\\frac{r}{R}\\right)\\\\\\\\\n\\partial^2_{11} h_3=-\\frac{1}{R}\\sin\\left(\\frac{r}{R}\\right)\\sin\\theta\\\\\\\\\n\\partial^2_{21} h_3=\\cos\\left(\\frac{r}{R}\\right)\\cos\\theta\\\\\\\\\n\\partial^2_{22} h_3=-R\\sin\\left(\\frac{r}{R}\\right)\\sin\\theta\\\\\\\\\n\\end{array}\\right.\n\\end{align}\ngiving\n\\begin{align}\nR_{1212}&=\n\\sin^2\\left(\\frac{r}{R}\\right)\\\\\nR_{2323}&=\nR^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta \n-R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\cos^2\\left(\\frac{r}{R}\\right)\\\\\n&= R^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\nR_{1313}&=\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\nR_{1213}&=0\\\\\nR_{1223}&=0\\\\\nR_{1323}&=\n-R\\sin\\left(\\frac{r}{R}\\right)\\sin\\theta\\cos\\left(\\frac{r}{R}\\right)\\cos\\theta+\\sin\\theta R\\sin\\left(\\frac{r}{R}\\right)\\cos\\theta\\cos\\left(\\frac{r}{R}\\right)\\\\&=0\n\\end{align}\nand considering the symmetries\n\\begin{align}\nR_{1212}&=-R_{1221}=-R_{2112}=\n\\sin^2\\left(\\frac{r}{R}\\right)\\\\\nR_{2323}&=-R_{2332}=-R_{3223}= R^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\nR_{1313}&=-R_{1331}=-R_{3113}=\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\n\\end{align}\nBy $\\mathbf{4.114.}$\n\\begin{align}\nR_{rsmn}&= K\\left(a_{rm}a_{sn}-a_{rn}a_{sm}\\right)\\\\\n\\Rightarrow\\spatie &\\left\\{\\begin{array}{l}\nR_{1212}= K\\left(a_{11}a_{22}-a_{12}a_{21}\\right)\\\\\nR_{2323}= K\\left(a_{22}a_{33}-a_{23}a_{32}\\right)\\\\\nR_{1313}= K\\left(a_{11}a_{33}-a_{13}a_{31}\\right)\n\\end{array}\\right.\\\\\n\\Rightarrow\\spatie &\\left\\{\\begin{array}{l}\nR_{1212}= K R^2\\sin^2\\left(\\frac{r}{R}\\right)\\\\\nR_{2323}= K R^2\\sin^2\\left(\\frac{r}{R}\\right)R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\nR_{1313}= K R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow\\spatie &\\left\\{\\begin{array}{l}\nR_{1212}= K R^2\\sin^2\\left(\\frac{r}{R}\\right)\\\\\nR_{2323}= K R^4\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\nR_{1313}= K R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\n\\end{array}\\right.\n\\end{align}\n replacing (25), (26) and (27) in (32) we get\n \\begin{align}\n\\left\\{\\begin{array}{l}\n\\sin^2\\left(\\frac{r}{R}\\right)= K R^2\\sin^2\\left(\\frac{r}{R}\\right)\\\\\nR^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta= K R^4\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\n\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta= K R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\n\\end{array}\\right.\n\\end{align}\ngiving indeed for the three curvature tensors $K=\\frac{1}{R^2}$\\\\\nWith this, the question of the  exercise is answered but we go a little bit further and investigate for this practical case the equations of $\\mathbf{4.115.}$ and  calculate $R=a^{mn}R_{mn}$. With $R$, the curvature invariant. To avoid confusion with the curvature $R$ itself we use $\\mathfrak{R}$ for the curvature invariant.\\\\\nAs the metric tensor is diagonal:\n\n\\begin{align}\n\\mathfrak{R}=a^{11}R_{11}+a^{22}R_{22}+a^{33}R_{33}\\\\\n\\end{align}\nand \n\\begin{align}\nR_{mn}&= a^{sn}R_{srmn}\\\\\n\\Rightarrow\\spatie &\n\\left\\{\\begin{array}{l}\nR_{11} = a^{11}R_{1111}+a^{22}R_{2112}+a^{33}R_{3113}\\\\\\\\\nR_{22} = a^{11}R_{1221}+a^{22}R_{2222}+a^{33}R_{3223}\\\\\\\\\nR_{33} = a^{11}R_{1331}+a^{22}R_{2332}+a^{33}R_{3333}\\\\\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow\\spatie &\\left\\{\\begin{array}{l}\nR_{11} = -a^{22}\\sin^2\\left(\\frac{r}{R}\\right)-a^{33}\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\\\\\nR_{22} = -a^{11}\\sin^2\\left(\\frac{r}{R}\\right)-a^{33}R^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\\\\\nR_{33} = -a^{11}\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta-a^{22}R^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow\\spatie &\\left\\{\\begin{array}{l}\nR_{11} = -\\frac{\\sin^2\\left(\\frac{r}{R}\\right)}{R^2\\sin^2\\left(\\frac{r}{R}\\right)}-\\frac{\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta}{R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta}\\\\\\\\\nR_{22} = -\\sin^2\\left(\\frac{r}{R}\\right)-\\frac{R^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta}{R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta}\\\\\\\\\nR_{33} = -\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta-\\frac{R^2\\sin^4\\left(\\frac{r}{R}\\right)\\sin^2\\theta}{R^2\\sin^2\\left(\\frac{r}{R}\\right)}\\\\\\\\\n\\end{array}\\right.\n\\end{align}\ngiving\n\\begin{align}\n\\left\\{\\begin{array}{l}\nR_{11} = -\\frac{2}{R^2}\\\\\\\\\nR_{22} = -2\\sin^2\\left(\\frac{r}{R}\\right)\\\\\\\\\nR_{33} = -2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nhence\n\\begin{align}\n\\mathfrak{R}&=a^{11}R_{11}+a^{22}R_{22}+a^{33}R_{33}\\\\\n\\Rightarrow\\spatie \\mathfrak{R}&= -\\frac{2}{R^2}-2\\frac{\\sin^2\\left(\\frac{r}{R}\\right)}{R^2\\sin^2\\left(\\frac{r}{R}\\right)}-2\\frac{\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta}{R^2\\sin^2\\left(\\frac{r}{R}\\right)\\sin^2\\theta }\\\\\n&= -\\frac{6}{R^2}\n\\end{align}\nThe equations in (40) and (43) are indeed in accordance with $\\mathbf{4.115}$ .\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p139 - Exercise 4}\n\\begin{tcolorbox}\nShow that if $V_N$ has positive-definite metric form and constant positive curvature $K$, then coordinates $y^r$ exist so that\n$$ds^2=\\frac{dy^m dy^m}{\\left(1+\\kwart y^n y^n\\right)^2}$$\n(Starting with a coordinate system $x^r$ which is locally Cartesian at $O$, take at any point $P$ the coordinates\n$$y^r=p^r\\frac{2}{\\sqrt{K}}\\tan\\left(\\half r \\sqrt{K}\\right)$$\nwhere $p^r$ ar the the components of the unit tangent vector $\\left(\\dv{x^r}{s}\\right)$ at $O$ to the geodesic $OP$ and $r$ is the geodesic distance $OP$.)\n\\end{tcolorbox}\nLet us first understand what happens. Fig.1.5 for a $V_3$ will help us understand.\nLet $P$ and $P+dP$ be two points separated by an infinitesimal distance. Consider the two geodesics initiated from the origin and joining these two points. Be $X$ and $X^{'}$ the two tangents unit vectors  to these geodesics. Those vectors have components $p^r=\\dv{x^r}{s}$ taken along their respective geodesics.  By the considered transformation the points $P$ and $P+dP$ are mapped on the  points  $\\tau (P)$ and $\\tau (P+dP)$ with $\\left|O\\tau (P)\\right|$ and $\\left|O\\tau (P+dP)\\right|$ collinear with the  two tangents unit vectors  $X$ and $X^{'}$ . \\\\\nObserve also the segment $PN$ which corresponds to the geodesic displacement $\\eta$ for the geodesic distance $r=OP$. As the metric form is positive-definite, we can consider that the infinitesimal triangle $\\left|\\widehat{PNP+dP}\\right|$ lies in an infinitesimally Euclidean space and  we can express $ds^2=\\eta^2+ dr^2$ as $\\left|NP+dP\\right| = dr$. Observe now, the triangle $\\left|\\widehat{\\tau(P)\\tau(N)\\tau(P+dP)}\\right|$. There also we have $\\left|\\tau(P+dP)\\tau(P)\\right|^2 = \\left|\\tau(P)\\tau(N)\\right|^2+\\left|\\tau(P+dP)\\tau(N)\\right|^2$. Can we find a relationship between these two triangle?\\\\\n\\begin{figure}[H]\n\\begin{center}\n\\input{D:/MathLatex/images/fig_p139_Ex4.tex}\n\\caption{Coordinate system in constant curvature space}\n\\label{fig:fig_p139_Ex4}\n\\end{center}\n\\end{figure}\n\nLet's define $\\alpha (r) = \\frac{2}{\\sqrt{K}}\\tan\\left(\\half r \\sqrt{K}\\right)$ so that $y^k = \\alpha (r)p^k$\nWe have \n\\begin{align}\n\\left\\{\\begin{array}{l}\n\\left|OX^{'}\\right|= \\left|OX^{}\\right|=1\\\\\\\\\n\\left|O\\tau (N)\\right|= \\left|O\\tau (P)\\right|=\\alpha (r)\\\\\\\\\n \\left|O\\tau (P+dP)\\right|=\\alpha (r+dr)\\\\\\\\\n\\end{array}\n\\right.\n\\end{align}\nExpanding the last equation in a Taylor series we get as first order term\n\\begin{align}\n\\left|\\tau (N)\\tau (P+dP)\\right|= \\frac{1}{\\cos^2(\\half r \\sqrt{K})}dr\n\\end{align}\nAlso,\n\\begin{align}\n\\left|\\tau (N)\\tau (P)\\right|= 2\\alpha (r)\\sin \\frac{\\chi}{2}  \\approx \\alpha (r) \\chi \n\\end{align}\nFrom $\\mathbf{4.124}$ we have $\\chi=\\left(\\dv{\\eta}{r}\\right)_{r=0}= C\\sqrt{K}$  .\nBut note also that from $\\mathbf{4.122}$ we have for the geodesic displacement $\\eta = C\\left|\\sin r\\sqrt{K}\\right|$. \n\\begin{align}\nC&= \\frac{\\eta }{\\left|\\sin r\\sqrt{K}\\right|}\\\\\n\\Rightarrow \\spatie \\chi&=\\frac{\\eta }{\\left|\\sin r\\sqrt{K}\\right|}\\sqrt{K}\\\\\n\\Rightarrow \\spatie \\left|\\tau (N)\\tau (P)\\right|&=\\eta\\frac{\\sqrt{K} }{\\left|\\sin r\\sqrt{K}\\right|}\\alpha (r) \n\\end{align}\nLet's put $\\left|\\tau (N)\\tau (P)\\right|=\\hat{\\eta}$.\n\\begin{align}\n\\hat{\\eta}&=\\eta\\frac{\\sqrt{K} }{\\left|\\sin r\\sqrt{K}\\right|}\\alpha (r) \n\\end{align}\nAt the point $P$ we have $\\left|PN\\right| = \\eta$ and so\n\\begin{align}\nds^2=\\eta^2+ dr^2\n\\end{align}\nLet's put $\\left|\\tau(P+dP)\\tau(P)\\right|^2=d\\hat{s}^2$.\n\\begin{align}\nd\\hat{s}^2 &= \\hat{\\eta}^2+\\left|\\tau(P+dP)\\tau(N)\\right|^2\\\\\n\\text{(2) and (7) }\\Rightarrow\\spatie &= \\eta^2\\frac{K }{\\sin^2 (r\\sqrt{K})}\\frac{4}{K}\\frac{\\sin^2 (\\half r \\sqrt{K})}{\\cos^2 (\\half r \\sqrt{K})}+ \\frac{1}{\\cos^4(\\half r \\sqrt{K})}dr^2\\\\\n\\sin r\\sqrt{K} &= 2\\sin (\\half r\\sqrt{K})\\cos (\\half r\\sqrt{K})\\\\\n\\Rightarrow\\spatie  d\\hat{s}^2 &= \\eta^2\\frac{1}{\\cos^4 (\\half r \\sqrt{K})}+ \\frac{1}{\\cos^4(\\half r \\sqrt{K})}dr^2\\\\\n\\Rightarrow\\spatie \\eta^2+dr^2 &= d \\hat{s}^2 \\cos^4(\\half r \\sqrt{K})\\\\\n\\Rightarrow\\spatie ds^2 &= d \\hat{s}^2 \\cos^4(\\half r \\sqrt{K})\n\\end{align}\nIt is easy to see that $d \\hat{s}^2 =  dy^k dy^k$ and also\n\\begin{align}\n\\cos^4(\\half r \\sqrt{K}) &= \\left(\\cos^2(\\half r \\sqrt{K})\\right)^2\\\\\n &= \\left(\\frac{\\cos^2(\\half r \\sqrt{K})}{\\cos^2(\\half r \\sqrt{K})+\\sin^2(\\half r  \\sqrt{K})}\\right)^2\\\\\n&= \\left(\\frac{1}{1+\\tan^2(\\half r  \\sqrt{K})}\\right)^2\n\\end{align}\nWe note that $\\frac{2}{\\sqrt{K}}\\tan(\\half r  \\sqrt{K})$ is the size of the vector $\\left|O\\tau(P)\\right|$ and can express this as (as we use local Cartesian coordinates at the origin) $\\left|O\\tau(P)\\right|^2 = y^ky^k$ and thus $\\tan^2(\\half r  \\sqrt{K}) =\\frac{K}{4}y^ky^k$. Combining this with (14) and (17) gives:\n\\begin{align}\nds^2 &= d \\hat{s}^2\\left(\\frac{1}{1+\\frac{K}{4}y^ky^k}\\right)^2\n\\end{align} \nwhich gives as final expression \n\\begin{align}\nds^2 &= \\frac{dy^k dy^k}{\\left(1+\\frac{K}{4}y^ky^k\\right)^2}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p140 - Exercise 5}\n\\begin{tcolorbox}\nShow that in a flat $V_n$ the straight line joining any two points of a $P$-flat $(P>N)$ lies entirely in the P-flat.\n\\end{tcolorbox}\nFor a $P$-flat we have by an appropriate re indexing of the variables $z_k$\n\\begin{align}\nA_{mp}z_p+B_p =0 \\spatie m=1,\\dots,P\n\\end{align}\nA straight line has as equation $z_p=C_p u + D_p$. As we have two points in the $P$-flat we have two $u_1, u_2$ for which yields\n\\begin{align}\n&\\left\\{ \\begin{array}{ll}\nA_{mp}\\left(C_p u_1 + D_p\\right) +B_p =0&\\\\\n & \\spatie m=1,\\dots,P\\\\\nA_{mp}\\left(C_p u_2 + D_p\\right) +B_p =0& \n\\end{array}\\right.\n\\end{align} \nSubtracting the corresponding equations in $m$ for the two sets $u_1, u_2$ gives \n\\begin{align}\n&A_{mp}C_p\\left( u_1-u_0 \\right) =0&\\\\\n\\Rightarrow\\spatie &A_{mp}C_p=0\\spatie &\\text{ for }m=1,\\dots,P\\\\\n\\text{(4) in (2) }\\Rightarrow\\spatie &A_{mp}D_p +B_p =0 \\spatie &\\text{ for }m=1,\\dots,P\n\\end{align} \nSo for an arbitrary $u$ we get from (1),(4) and (5)\n\\begin{align}\nA_{mp}\\left(C_p u + D_p\\right) +B_p = \\underbrace{A_{mp}C_p}_{=0} u + \\underbrace{A_{mp}D_p +B_p}_{=0} \\spatie &\\text{ for }m=1,\\dots,P\n\\end{align}\n\\begin{align}\n\\Rightarrow\\spatie A_{mp}\\left(\\underbrace{C_p u + D_p}_{z_p}\\right) +B_p =0 \\spatie &\\text{ for }m=1,\\dots,P\n\\end{align}\nSo the points $z_p$ lying on the line satisfy the conditions for the  $P$-flat and lie therefore in the  $P$-flat.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p140 - Exercise 6}\n\\begin{tcolorbox}\nShow that in four dimensions the transformation$$\\begin{array}{l}\nz^{'}_1 = z_1\\cosh \\phi + i z_4\\sinh \\phi\\\\\nz^{'}_2 = z_2\\\\\nz^{'}_3 = z_3\\\\\nz^{'}_4 = -iz_1\\sinh \\phi +  z_4\\cosh \\phi\n\\end{array}$$\nis orthogonal, $\\phi$ being any constant. Putting $z_1=x,\\ z_2 =y, \\ z_3 = z, \\ z_4 = ict, \\ \\phi = \\frac{v}{c}$, obtain the transformation connecting $(x^{'},y^{'},z^{'},t^{'})$ and $(x^{},y^{},z^{},t^{})$. This is the $\\mathit{Lorentz \\ transformation} $ of the special theory of relativity.\n\\end{tcolorbox}\nWe can represent the transformation with the matrix\n\\begin{align}\n\\left(A_{mn}\\right) &=\n\\begin{pmatrix}\n \\cosh \\phi&  0& 0 & i \\sinh \\phi \\\\\n 0& 1 & 0 &0  \\\\\n 0& 0 &  1&  0\\\\\n -i\\sinh \\phi&  0& 0 &  \\cosh \\phi \\\\\n\\end{pmatrix}\n\\end{align}\nWe use $\\mathbf{4.210.}$ i.e. $A_{pm}A_{qm} = \\delta _{pq}$ as a condition for the orthogonality of a transformation. This can be written in matrix form\n\\begin{align}\n\\left(A_{mn}\\right)\\left(A_{mn}\\right)^{T}= \\mathbf{I}\n\\end{align}\nand get\n\n\\begin{align}\n\\left(A_{mn}\\right)\\left(A_{mn}\\right)^{T}&=\n\\begin{pmatrix}\n \\cosh \\phi&  0& 0 & i \\sinh \\phi \\\\\n 0& 1 & 0 &0  \\\\\n 0& 0 &  1&  0\\\\\n -i\\sinh \\phi&  0& 0 &  \\cosh \\phi \\\\\n\\end{pmatrix}\\begin{pmatrix}\n \\cosh \\phi&  0& 0 & -i \\sinh \\phi \\\\\n 0& 1 & 0 &0  \\\\\n 0& 0 &  1&  0\\\\\n i\\sinh \\phi&  0& 0 &  \\cosh \\phi \\\\\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n \\cosh^2 \\phi- \\sinh ^2\\phi &  0& 0 & -i \\cosh \\phi\\sinh \\phi +i \\cosh \\phi\\sinh \\phi  \\\\\n 0& 1 & 0 &0  \\\\\n 0& 0 &  1&  0\\\\\n i \\cosh \\phi\\sinh \\phi -i \\cosh \\phi\\sinh \\phi  &  0& 0 &  -\\sinh^2 \\phi + \\cosh^2 \\phi \\\\\n\\end{pmatrix}\\\\\n&= \\mathbf{I}\n\\end{align}\nWe now calculate the Lorentz transformation.\\\\\nFirst note that \n\\begin{align}\n&\\left \\{\\begin{array}{l}\n\\cosh y = \\frac{e^y+e^{-y}}{2}\\\\\n\\sinh y = \\frac{e^y-e^{-y}}{2}\\\\\n\\tanh^{-1}  x = \\half \\log \\left(\\frac{1+x}{1-x}\\right)\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow\\spatie  &\\left \\{ \\begin{array}{l}\n\\cosh\\left(\\tanh^{-1}  x \\right) = \\frac{1}{\\sqrt{1-x^2}}\\\\\n\\sinh\\left(\\tanh^{-1}  x \\right) = \\frac{x}{\\sqrt{1-x^2}}\n\\end{array}\\right.\n\\end{align}\nReplacing $x$ with $\\tanh \\phi = \\frac{v}{c}$ gives\n\\begin{align}\n\\left \\{ \\begin{array}{l}\n\\cosh \\phi = \\frac{1}{\\sqrt{1-\\frac{v^2}{c^2}}}\\\\\n\\sinh \\phi = \\frac{v}{c\\sqrt{1-\\frac{v^2}{c^2}}}\n\\end{array}\\right.\n\\end{align}\nand the transformation becomes\n$$\\begin{array}{l}\nx^{'} = \\frac{x- vt}{\\sqrt{1-\\frac{v^2}{c^2}}}\\\\\ny{'} = y\\\\\nz^{'} = z\\\\\nt^{'} = \\frac{t-\\frac{vx}{c^2}}{\\sqrt{1-\\frac{v^2}{c^2}}} \n\\end{array}$$\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p140 - Exercise 7}\n\\begin{tcolorbox}\nProve that in a flat space a plane, defined by $\\mathbf{4.22}$, is itself a flat space f $N-1$ dimensions.\n\\end{tcolorbox}\nFor a $N-1$-flat we have $\\mathbf{4.22}$\n\\begin{align}\nA^{'}_r z_r+B^{'}=0\n\\end{align}\nSuppose that $A_N \\ne 0$ then we can express $Z_N$, by dividing the equation $(1)$ by $A_N$ as \n\\begin{align}\nz_N = A_{\\gamma} z_{\\gamma}+B \\spatie \\text{ with } \\gamma = 1,2, \\dots, N-1\n\\end{align}\nThen $\\phi = z_nz_n$ becomes\n\\begin{align}\n\\phi &= d z_{\\gamma}dz_{\\gamma}+ dz_N dz_N\\\\\n&=d z_{\\gamma}dz_{\\gamma} + \\left(A_{\\gamma} dz_{\\gamma}\\right)\\left(A_{\\tau} dz_{\\tau}\\right)\\\\\n&=d z_{\\gamma}dz_{\\gamma} + A_{\\gamma \\tau} dz_{\\gamma} dz_{\\tau}\n\\end{align}\nSo $\\phi$ can be expressed as $\\phi = a_{\\gamma \\tau}dz_{\\gamma}dz_{\\tau}$.\\\\\nBut as $a_{\\gamma \\tau}$ are constants, the Christoffel symbols vanish and so does the curvature tensor $R^{\\alpha}_{\\beta \\gamma \\delta}$ in the $N-1$ space. Hence, the $V_{N-1}$ space delimited by equation (1) is flat.\\\\\nQuestion: can we find the right orthogonal transformation so that the metric form in (5) can be made homogeneous?\\\\\nThe metric form in (5) can be represented as\n\\begin{align}\n\\left(a_{mn}\\right) &= \\begin{pmatrix}\n 1-A_1^2& \\half A_1A_{2} & \\dots &  \\half A_1A_{N-1}\\\\\n \\half A_1A_{2}&  1-A_2^2&  \\dots& \\half A_2A_{N-1}\\\\\n \\vdots& \\vdots &  \\ddots& \\vdots\\\\\n \\half A_1A_{N-1}&\\half A_2A_{N-1}  & \\dots & 1-A_{N-1}^2 \\\\\n\\end{pmatrix}\n\\end{align}\n\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p140 - Exercise 8}\n\\begin{tcolorbox}\nShow that in a flat space of positive-definite metric form, a sphere of zero radius consists of a single point, but that if the metric form is indefinite, a sphere of zero radius extends to infinity.\n\\end{tcolorbox}\nA sphere is determined by $ z_kz_k= \\pm R^2$ with $+$ for a positive definite metric and $\\pm$ if the metric is indefinite.\\\\\nFor a positive definite metric a zero radius sphere has the equation $ z_n z_n= 0$. It is obvious that as $z_n= \\sqrt{\\epsilon}y_k = y_k$, each term in the summation is non-negative , and so only $z_k=0 \\ \\forall n$ holds this equation.\\\\\nIn an indefinite metric form space, at least two $\\epsilon_n$ differ so the zero sphere can be written as $y_py_p=y_ny_n$, the indices $p, n$ regrouped in a way the left side has positive $\\epsilon$ and the right side negative $\\epsilon$. So the $y_k$ can span the whole real line.\\\\\nNote that the case where all $\\epsilon$ are negative means that  the metric form is positive definite. Indeed, from the definition $\\mathbf{2.105.}$, page 29   we have $ds^2= \\epsilon \\phi =\\epsilon a_{mn}dx^m dx^s, ds >0$. So the epsilons are in fact an artefact to get $ds^2$ positive in any case and if all $\\epsilon_n$ are $-1$ we can multiply them straight away with the $\\epsilon$ of $\\mathbf{2.105.}$ ensuring that $ds^2 >0$. \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p140 - Exercise 9}\n\\begin{tcolorbox}\nProve that in two dimensions\n$$\\epsilon_{mn}\\epsilon_{pq}= \\delta_{mp}\\delta_{nq}-\\delta_{mq}\\delta_{np}$$\n\\end{tcolorbox}\nSuppose first  that $m=n$ or $p=q$ : the left side will vanish but also the right side as we will have an expression $\\delta_{Mp}\\delta_{Mq}-\\delta_{Mq}\\delta_{Mp}  = 0$ (we use capital indices to emphasise that no summation occurs with repeated indices).\\\\\nSuppose now that $m\\ne n$ and $p\\ne q$.\\\\\n If $mn$ and $pq$ are no permutation, the left side will be $1$ but in the right side the negative term will vanish as $m=p$ and $n=q$ so $ m\\ne q$ while the left term will be $1$. The same yields with $mn$ and $pq$ are both  permutations as the same reasoning is valid for the right side and the left side is equal to $(-1)(-1)=1$.\\\\\n If only one of $mn$ or $pq$ is a  permutation  e.g. $m\\ne p$ then the positive term in the right side will vanish while the negative will be $-1$ and the left term will be $(-1)(1)=-1$.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p140 - Exercise 10}\n\\begin{tcolorbox}\nIf, in a space of four dimensions, $F_{mn}$ is a skew-symmetric Cartesian tensor, and $$\\hat{F}_{mn} = \\half \\epsilon_{rsmn} F_{rs}$$\nprove that the differential equations $$ F_{mn,r}+F_{nr,m}+F_{rm,n}=0$$ may be written $$\\hat{F}_{mn,n} =0$$\n\\end{tcolorbox}\nLet's us express $F_{mn}$ as the result of expression $\\mathbf{4.324.} $ i.e $$F_{mn} = \\epsilon_{mnks} X_kY_s$$ or simplified $$F_{mn} = \\epsilon_{mnks} Z_{ks}$$\nThis expression gives indeed skew-symmetric tensors.\\\\\\\\\n\\textit{NOTE:  at first glance this way of representation is  a restriction as the  skew-symmetric Cartesian tensor $F_{mn}$ should moreover be an oriented Cartesian tensor. This can be circumvent by the result of clarification 4.14 where we found that the tensor character  of the quantities $F_{mn}$ was only influenced by the determinant of an orthogonal transformation. So if in the case we are dealing with non-proper orthogonal transformation,  we replace the given identity by   $ \\left|A_{mn}\\right|F_{mn,r}+\\left|A_{mn}\\right|F_{nr,m}+\\left|A_{mn}\\right|F_{rm,n}=0$ and define $\\hat{F}_{mn} = \\half \\epsilon_{rsmn}\\left|A_{mn}\\right| F_{rs}$ the following reasoning will still be valid.}\\\\\\\\\n We have:\n\\begin{align}\n&\\left\\{\\begin{array}{l}\nF_{mn} = \\epsilon_{mnks} Z_{ks}\\\\\\\\\nF_{nr} = \\epsilon_{nrks} Z_{ks}\\\\\\\\\nF_{rm} = \\epsilon_{rmks} Z_{ks}\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nAnd so, \n\\begin{align}\nF_{mn,r}+F_{nr,m}+F_{rm,n}&=\\left\\{\\begin{array}{l}\n\\ \\epsilon_{mnks} Z_{ks,r}\\\\\\\\\n+\\epsilon_{nrks} Z_{ks,m}\\\\\\\\\n+\\epsilon_{rmks} Z_{ks,n}\\\\\\\\\n\\end{array}\\right.\n\\end{align}\n\nMultiplying (2) with $\\epsilon_{mnrt}$ \n\\begin{align}\n\\left(F_{mn,r}+F_{nr,m}+F_{rm,n}\\right)\\epsilon_{mnrt}&=\\left\\{\\begin{array}{l}\n\\ \\epsilon_{mnks} \\epsilon_{mnrt} Z_{ks,r}\\\\\\\\\n+\\epsilon_{nrks} \\epsilon_{mnrt} Z_{ks,m}\\\\\\\\\n+\\epsilon_{rmks}\\epsilon_{mnrt} Z_{ks,n}\\\\\\\\\n\\end{array}\\right.\\\\\n&=3\\epsilon_{rmks}\\epsilon_{rmnt} Z_{ks,n}\\\\\n&=3\\epsilon_{rmnt} \\left(\\underbrace{\\epsilon_{rmks}Z_{ks}}_{=F_{rm}} \\right)_{,n}\\\\\n&=3\\left(\\underbrace{\\epsilon_{rmnt} F_{rm}}_{=2\\hat{F}_{nt}}  \\right)_{,n}\\\\\n&=-6\\hat{F}_{tn,n}\n\\end{align}\nAs $\\left(F_{mn,r}+F_{nr,m}+F_{rm,n}\\right)\\epsilon_{mnrt}=0$ we have indeed $$\\hat{F}_{tn,n}=0$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p140 - Exercise 11}\n\\begin{tcolorbox}\nWrite out explicitly and simplify the expressions $$F_{mn}F_{mn}, \\ \\epsilon_{mnrs} F_{mn}F_{rs} $$ where  $F_{mn}$ is a skew-symmetric oriented Cartesian tensor.\\\\\nWhat is the tensor character of these expressions?\n\\end{tcolorbox}\n\\textit{REMARK: although not explicitly stated we assume that we are in a $V_4$-space.}\\\\\nLet's us express $F_{mn}$ as the result of expression $\\mathbf{4.324.} $ i.e $$F_{mn} = \\epsilon_{mnks} X_kY_s$$ or simplified $$F_{mn} = \\epsilon_{mnks} Z_{ks}$$\nFirst we note that by a same reasoning for $\\mathbf{4.329.}$ we have\n\\begin{align}\n\\epsilon_{mnrs}\\epsilon_{mnpq} &= 2\\left(\\delta_{rp}\\delta_{sq}-\\delta_{rq}\\delta_{sp}\\right)\n\\end{align} \nThe factor $2$ arising from the fact that we are dealing in $V_4$ with a sum over the ordered pair $(mn)$.\\\\\n We have for the first  expression $F_{mn}F_{mn}$:\n\\begin{align}\n\\half F_{mn}F_{mn}&=\\half\\epsilon_{mnrs}\\epsilon_{mnpq} Z_{rs} Z_{pq}\\\\\n&=\\delta_{rp}\\delta_{sq}Z_{rs} Z_{pq}-\\delta_{rq}\\delta_{sp}Z_{rs} Z_{pq}\\\\\n&=\\delta_{sq}Z_{rs} Z_{rq}-\\delta_{sp}Z_{rs} Z_{pr}\\\\\n&=Z_{rs} Z_{rs}-Z_{rp} Z_{pr}\\\\\n\\Rightarrow \\spatie F_{mn}F_{mn}&=2\\left(X_r X_r Y_s Y_s - \\left(X_r Y_r\\right)^2\\right)\n\\end{align}\n\\textbf{$F_{mn}F_{mn}$ is an oriented Cartesian invariant.}\n\n\nWe have for the second  expression $\\epsilon_{mnrs} F_{mn}F_{rs}$:\n\\begin{align}\n\\epsilon_{mnrs} F_{mn}F_{rs}&=\\underbrace{\\epsilon_{mnrs}\\epsilon_{mnpq}}_{2\\left(\\delta_{rp}\\delta_{sq}-\\delta_{rq}\\delta_{sp}\\right) }\\epsilon_{rsuv} Z_{pq} Z_{uv}\\\\\n&=2\\left(\\delta_{rp}\\delta_{sq}\\epsilon_{rsuv}-\\delta_{rq}\\delta_{sp}\\epsilon_{rsuv}\\right)Z_{pq} Z_{uv}\\\\\n&=2\\left(\\epsilon_{pquv}-\\epsilon_{qpuv}\\right)Z_{pq} Z_{uv}\\\\\n&=4\\epsilon_{pquv}Z_{pq} Z_{uv}\\\\\n\\Rightarrow \\spatie \\epsilon_{mnrs} F_{mn}F_{rs}&=4\\epsilon_{pquv}X_p  Y_q X_uY_v\n\\end{align}\n\\textbf{$\\epsilon_{mnrs} F_{mn}F_{rs}$ is an oriented Cartesian invariant.}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p141 - Exercise 12}\n\\begin{tcolorbox}\nShow that in a flat space with positive-definite metric form all spheres have positive constant curvature. Show that if the metric is indefinite then some spheres have positive constant curvature and some have negative constant curvature. Discuss the Riemannian curvature of the null-cone.\n\\end{tcolorbox}\nA sphere is determined by $ z_kz_k= C$ (see $\\mathbf{4.224.}$).\\\\\nFor a \\textbf{positive definite} metric it is obvious that as $z_k= \\sqrt{\\epsilon_k}y_k = y_k$, each term in the summation is non-negative , and so only $C>0$ holds for this equation. From chapter $\\mathbf{4.4}$ is follows that a sphere has constant curvature $\\frac{1}{C} >0$\\\\\nIn an \\textbf{indefinite metric} form space, at least two $\\epsilon_k$ differ so the zero sphere can be written as $y_py_p=C +y_ny_n$, the indices $p, n$ regrouped in a way the left side has positive $\\epsilon {'}s$ and the right side negative $\\epsilon {'}s$. So $C$ can be either positive or negative while still representing a sphere in $V_n$.\\\\\nFor the \\textbf{null-cone}, we have $C=0$, so the Riemannian curvature becomes infinite as $$K = \\lim_{C\\to 0}\\frac{1}{C}= \\infty$$.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p141 - Exercise 13}\n\\begin{tcolorbox}\nShow that in any space of three dimensions the permutation symbols transform according to\n$$\\epsilon^{'}_{mnr}= \\epsilon^{}_{stu}J^{'}\\partial_m x^s\\partial_n x^t\\partial_r x^u, \\spatie J^{'}= \\left|\\frac{\\partial x^{'p}}{\\partial x^{q}}\\right|$$\nor\n$$\\epsilon^{'}_{mnr}= \\epsilon^{}_{stu}J^{}\\partial_s x^{'m}\\partial_t ^{'n}\\partial_u x^{'r}, \\spatie J^{}= \\left|\\frac{\\partial x^{p}}{\\partial x^{'q}}\\right|$$\nUsing the result of Exercises II, 12, deduce that in a Riemannian 3-space the quantities $\\eta_{mnr}$ and $\\eta^{mnr}$ defined by \n$$ \\eta_{mnr}= \\epsilon^{}_{mnr}\\sqrt{a}, \\quad \\eta^{mnr}= \\frac{\\epsilon^{}_{mnr}}{\\sqrt{a}}, \\quad a=\\left|a_{pq}\\right|$$\nare components of covariant and contravariant oriented tensors .\n\\end{tcolorbox}\nFirst remember that $J^{'}= \\frac{1}{J}$.\\\\\nThe reasoning is completely analogous as to the reasoning from $\\mathbf{4.312}$ till $\\mathbf{4.317}$ except that the $\\frac{\\partial z^{m}}{\\partial z^{'s}}$ are held and not replaced by the $A_{mn}$.\\\\\n$\\mathbf{4.316}$ becomes\n\\begin{align}\n\\epsilon^{'}_{mnr}J^{}&= \\epsilon^{}_{stu}\\partial_m x^s\\partial_n x^t\\partial_r x^u, \\spatie J^{}= \\left|\\frac{\\partial x^{p}}{\\partial x^{'q}}\\right|\\\\\nJ^{}= \\frac{1}{J^{'}}\\quad \\Rightarrow\\spatie\\epsilon^{'}_{mnr}&= \\epsilon^{}_{stu}J^{'}\\partial_m x^s\\partial_n x^t\\partial_r x^u, \\spatie J^{'}= \\left|\\frac{\\partial x^{'p}}{\\partial x^{q}}\\right|\n\\end{align}\nFollowing Exercises II, 12  we have $a^{'} = aJ^2$. So,\n\\begin{align}\n\\eta^{'}_{mnr} &=\\eta^{}_{uvw} \\partial_m x^u\\partial_n x^v\\partial_r x^w\\\\\n&=\\sqrt{a}\\ \\underbrace{\\epsilon^{}_{uvw}\\partial_m x^u\\partial_n x^v\\partial_r x^w}_{= \\frac{1}{J^{'}}\\epsilon^{'}_{mnr}}\\\\\n&=\\sqrt{a}\\ J^{}\\epsilon^{'}_{mnr}\\\\\n\\sqrt{a^{'}} = \\sqrt{aJ^2}\\quad\\Rightarrow\\spatie&= \\sqrt{a^{'}}\\ \\epsilon^{'}_{mnr}\n\\end{align}\nThe same reasoning applies to the contravariant counterpart.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p141 - Exercise 14}\n\\begin{tcolorbox}\nTranslate into Cartesian tensor form and thus verify the following well known vector relations.\n$$ \\nabla .  \\left( \\phi V \\right) = \\phi  \\nabla . V + V .\\nabla \\phi $$\n$$ \\vdots$$\n\\end{tcolorbox}\n$$ \\mathbf{\\nabla .  \\left( \\phi V \\right) = \\phi  \\nabla .V + V .\\nabla \\phi }$$\n\\begin{align}\n\\nabla .  \\left( \\phi V \\right) &\\equiv \\partial_k \\phi V_k\\\\\n&= \\phi\\partial_k V_k+V_k\\partial_k\\phi\\\\\n&\\equiv \\phi\\nabla.V+V.\\nabla\\phi\n\\end{align}\n$$\\lozenge$$\n$$ \\mathbf{\\nabla \\times  \\left( \\phi V \\right) = \\phi  \\nabla \\times V + V \\times \\nabla \\phi }$$\n\\begin{align}\n\\left( \\nabla \\times  \\left( \\phi V \\right)\\right)_m &\\equiv \\epsilon_{mnr}\\partial_n \\phi V_r\\\\\n&= \\phi\\epsilon_{mnr}\\partial_n V_r+\\epsilon_{mnr}V_r\\partial_n\\phi\\\\\n&\\equiv \\phi\\nabla\\times V+\\nabla\\phi \\times V\\\\\n&= \\phi\\nabla\\times V-  V\\times\\nabla\\phi\n\\end{align}\n$$\\lozenge$$\n$$ \\mathbf{\\nabla . \\left( U\\times V \\right) = V .\\left( \\nabla \\times U\\right) -  U .\\left( \\nabla \\times V\\right)}$$\n\\begin{align}\n\\nabla . \\left( U\\times V \\right) &\\equiv \\partial_m \\left(\\epsilon_{mnr}U_n V_r\\right)\\\\\n&=  U_n\\epsilon_{mnr} \\partial_m  V_r+ V_r\\epsilon_{mnr} \\partial_mU_n\\\\\n&=  -U_n\\underbrace{\\epsilon_{nmr} \\partial_m  V_r}_{\\equiv \\left(\\nabla \\times V\\right)_n}+ V_r\\underbrace{\\epsilon_{rmn} \\partial_m U_n}_{\\equiv \\left(\\nabla \\times U\\right)_r}\\\\\n&\\equiv V .\\left( \\nabla \\times U\\right) -  U .\\left( \\nabla \\times V\\right)\n\\end{align}\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla \\times  \\left( U\\times V \\right) = V . \\nabla U -  U . \\nabla V+U\\nabla . V-V\\nabla.U}$$\n\\begin{align}\n\\left(\\nabla \\times  \\left( U\\times V \\right) \\right)_k &\\equiv \\epsilon_{kpm}\\partial_p \\epsilon_{mnr}U_n V_r\\\\\n&=  \\underbrace{\\epsilon_{kpm}}_{= \\epsilon_{mkp}}\\epsilon_{mnr}V_r\\partial_p U_n + \\underbrace{\\epsilon_{kpm}}_{= \\epsilon_{mkp}}\\epsilon_{mnr}U_n\\partial_p V_r \\\\\n&= \\delta_{kn}\\delta_{pr}V_r\\partial_p U_n -\\delta_{kr}\\delta_{pn}V_r\\partial_p U_n +\\delta_{kn}\\delta_{pr}U_n\\partial_p V_r-\\delta_{kr}\\delta_{pn}U_n\\partial_p V_r\\\\\n&= \\underbrace{V_p\\partial_p U_k}_{\\equiv \\left(V .\\nabla U\\right)_k} -\\underbrace{V_k\\partial_n U_n}_{\\equiv \\left(V\\nabla .U\\right)_k} +\\underbrace{U_k\\partial_r V_r}_{\\equiv \\left(U\\nabla .V\\right)_k}-\\underbrace{U_p\\partial_p V_k}_{\\equiv \\left(U .\\nabla V\\right)_k}\\\\\n&\\equiv V .\\nabla U-U .\\nabla V+U\\nabla .V-V\\nabla .U\n\\end{align}\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla \\left( U. V \\right) = U . \\nabla V + V . \\nabla U+U\\times\\left(\\nabla \\times V\\right)+V\\times\\left(\\nabla \\times U\\right)}$$\n\\begin{align}\n\\left(\\nabla \\left( U. V \\right) \\right)_p &\\equiv \\partial_p U_k V_k\\\\\n&=  V_k\\partial_p U_k +U_k\\partial_p  V_k\\\\\n\\left(U\\times\\left(\\nabla\\times V\\right)\\right)_p &\\equiv \\epsilon_{pkm} U_k\\epsilon_{mnr}\\partial_n V_r\\\\\n&=\\epsilon_{mpk} \\epsilon_{mnr}U_k\\partial_n V_r\\\\\n&=\\delta_{pn}\\delta_{kr}U_k\\partial_n V_r-\\delta_{pr}\\delta_{kn}U_k\\partial_n V_r\\\\\n&=U_r\\partial_p V_r-U_n\\partial_n V_p\\\\\n\\Rightarrow\\spatie \\left(U\\times\\left(\\nabla\\times V\\right)\\right)_p &\\equiv U_r\\partial_p V_r-\\underbrace{U_n\\partial_n V_p}_{\\equiv \\left(U.\\nabla V\\right)_p}\n\\end{align}\nPlugging (23) in (18) twice (with interchanging U and V) gives\n\\begin{align}\n\\nabla \\left( U. V \\right)  =U\\times\\left(\\nabla\\times V\\right)+U.\\nabla V+V\\times\\left(\\nabla\\times U\\right)+V.\\nabla U\n\\end{align}\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla \\times \\left(\\nabla\\phi \\right) = 0}$$\n\\begin{align}\n\\left(\\nabla \\times \\left(\\nabla\\phi \\right)\\right)_k&\\equiv \\epsilon_{kmn}\\partial_m \\partial_n\\phi\n\\end{align}\nWe just have to note that if $m=n$ the terms in the sum are zero and that when $m\\ne n$ we will have two terms which add as $\\epsilon_{kMN}\\partial_M \\partial_N\\phi + \\epsilon_{kNM}\\partial_N \\partial_M\\phi $ which obviously is zero. And so $\\nabla \\times \\left(\\nabla\\phi \\right) = 0$.\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla . \\left(\\nabla\\times V \\right)= 0}$$\n\\begin{align}\n\\nabla . \\left(\\nabla\\times V \\right)&\\equiv \\partial_p\\epsilon_{pmn} \\partial_mV_n\\\\\n&=\\epsilon_{npm} \\partial_p \\partial_m V_n\n\\end{align}\nWe apply the same reasoning as in the previous identity. And so $\\nabla . \\left(\\nabla\\times V \\right) = 0$.\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla \\times \\left(\\nabla\\times V \\right)= \\nabla\\nabla.V-\\nabla^2V}$$\n\\begin{align}\n\\left(\\nabla \\times \\left(\\nabla\\times V \\right)\\right)_m&\\equiv \\epsilon_{mkr} \\partial_k \\epsilon_{ruv} \\partial_uV_v\\\\\n&=\\epsilon_{rmk} \\epsilon_{ruv}\\partial_k  \\partial_u V_v\\\\\n&=\\delta_{mu}\\delta_{kv}\\partial_k  \\partial_u V_v-\\delta_{mv}\\delta_{ku}\\partial_k  \\partial_u V_v\\\\\n&=\\underbrace{\\partial_m  \\partial_v V_v}_{\\left(\\nabla\\nabla.V\\right)_m}-\\underbrace{\\partial_k  \\partial_k V_m}_{\\left(\\nabla^2 V\\right)_m}\n\\end{align}\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla .r= 3}$$\nwhere r is the vector with components equal to the Cartesian coordinates $z_1,z_2,z_3$\n\\begin{align}\n\\nabla .r &\\equiv \\partial_k z_k\\\\\n&=\\delta_{kk}\\\\\n&=3\n\\end{align}\n$$\\lozenge$$\n\n$$ \\mathbf{\\nabla \\times r= 0}$$\nwhere r is the vector with components equal to the Cartesian coordinates $z_1,z_2,z_3$\n\\begin{align}\n\\left(\\nabla \\times r\\right)_m &\\equiv \\epsilon_{mns}\\partial_n z_s\\\\\n&=\\epsilon_{mns}\\delta_{ns}\\\\\n\\end{align}\nThis sum is zero as when $n=s$, $\\delta_{ns}=1$ but $\\epsilon_{mNN}=0$ and when $n\\ne s$, $\\delta_{ns}=0$.\n$$\\lozenge$$\n\n$$ \\mathbf{V .\\nabla r= 0}$$\nwhere r is the vector with components equal to the Cartesian coordinates $z_1,z_2,z_3$\n\\begin{align}\n\\left(V .\\nabla r\\right)_m &\\equiv V_n \\partial_n r_m\\\\\n&=V_n \\delta_{nm}\\\\\n&=V_m\\\\\n\\end{align}\n$$\\lozenge$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p141 - Exercise 15}\n\\begin{tcolorbox}\nProve that $$\\epsilon_{amn}\\epsilon_{ars}+\\epsilon_{ams}\\epsilon_{anr}=\\epsilon_{amr}\\epsilon_{ans}$$\n\\end{tcolorbox}\n\\begin{align}\n\\epsilon_{amn}\\epsilon_{ars}+\\epsilon_{ams}\\epsilon_{anr}&=\n\\left(\\delta_{mr}\\delta_{ns}-\\delta_{ms}\\delta_{nr}\\right)\n+\\left(\\delta_{mn}\\delta_{sr}-\\delta_{mr}\\delta_{sn}\\right)\\\\\n&=\\delta_{mn}\\delta_{sr}-\\delta_{ms}\\delta_{nr}\\\\\n&=\\epsilon_{amr}\\epsilon_{anr}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage", "meta": {"hexsha": "477d12ce4ec318fc1748937e4f21ec1062fd56eb", "size": 67078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter4.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": "chapter4.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": "chapter4.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": 49.9092261905, "max_line_length": 788, "alphanum_fraction": 0.6566236322, "num_tokens": 27560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6952924482784434}}
{"text": "The Ising model is a way of modeling phase transitions at finite temperatures of magnetic systems. When modeling, we set up a chain or a lattice of particles and allow them to have either spin up or spin down. From this, one can sample energy and magnetization, and measure several quantities such as the heat capacity or magnetic susceptibility. Our focus will be on predicting the energy coupling constant for a 1D lattice, and the phase of a 2D-lattice.\n\nPeriodic boundary conditions is given in both cases, such that $j=N=0$, where $j$ is the lattice site and $N$ is the lattice size.\n\n\\subsubsection{1-dimensional Ising model} \\label{sec:1d-ising-model}\nEnergy for a 1 dimensional Ising model is given as\n\\begin{align}\n    E = - J\\sum^N_{j=1} s_j s_{j+1}\n    \\label{eq:1d-ising-energy}\n\\end{align}\nwhere the $N$ is the number of particles(or lattice size) and s$_j=\\pm1$ is the j'th spin. Our goal will be to predict $J$, but in order to do so, we must recast the problem as a linear regression problem.\n\nWe begin by labeling each site as coupled with $J$.\n\\begin{align}\n    E_\\mathrm{model}[\\bm{s}^i] = -\\sum^N_{j=1} \\sum^N_{k=1} J_{j,k} s^i_j s^i_k,\n\\end{align}\nwhere $i$ is the index over lattice configurations. The coupling strength $J_{j,k}$  can now be cast as a matrix, and we end up with\n\\begin{align}\n    E_\\mathrm{model}^i \\equiv \\bm{X}^i \\cdot \\bm{J},\n    \\label{eq:1d-ising-linreg}\n\\end{align}\nwhere $\\bm{X}^i$ is the design matrix consisting of all two-body interactions $\\{s^i_j s^i_k\\}^N_{j,k=1}$, and $\\bm{J}$ the weight matrix we wish to find later using machine learning techniques.\n\n\\subsubsection{2-dimensional Ising model} \\label{sec:2d-ising-model}\nThe 2D Ising model has its energy stated as,\n\\begin{align}\n    E = - J\\sum^N_{<kl>} s_k s_l,\n    \\label{eq:2d-ising-energy}\n\\end{align}\nwhere $<kl>$ indicates a sum over the nearest neighbors. That is, written out,\n\\begin{align}\n    E = - J\\sum^N_{i,j} 2 s_{i,j} (s_{i+1,j} + s_{i-1,j} + s_{i,j+1} + s_{i,j-1}),\n    \\label{eq:2d-ising-energy-shortened}\n\\end{align}\nwhere we have used the symmetry that $s_{i,j} s_{i+1,j}=s_{i+1,j} s_{i,j}$. $J$ is, as in the 1D model, a coupling constant, but will not be our main focus when studying the 2D Ising model. This time, we will focus on its property of exhibiting phase transitions. Below a critical temperature of $T_C \\approx 2.269$ found analytically by \\citep{onsager1944crystal}, the lattice will exhibit an ordered state, one in which the spins is \\textit{locked} or \\textit{frozen} into place. Above $T_C$ the lattice exhibit a disordered phase, as the spins will be fluctuating randomly.\n\nWe will investigate the classification of states below $T<2.0$ and $T>2.5$. The phase for states between we will dub as being in a \\textit{critical phase}.", "meta": {"hexsha": "b74f7a963a5ae2046870c0ae5e64a4906c0da4db", "size": 2775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory/ising_model.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/ising_model.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/ising_model.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": 75.0, "max_line_length": 576, "alphanum_fraction": 0.7272072072, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6952924434059413}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\section{Gradient Calculations for All Models}\n\nFor all models, the negative log likelihood function for a vector of parameters\n$\\theta$ holding fixed a dataset consisting of $N$ tuples of the form\n$(x^2_i, t^2_i, x^1_i, t^1_i, y_i)$ is:\n\n\\[\n-\\mathcal{L}(\\theta) = -\\sum_{i = 1}^{N} y_i \\log(p_i) + (1 - y_i) \\log(1 - p_i)\n\\]\n\nWe can treat all models as embedded inside of the $\\epsilon$-noise formulation\nsince we can always set $\\epsilon = 0$ when the additional noise is not\nappropriate. In this formulation, the probability that $y_i = 1$ is $p_i$,\nwhich is derived from an inner probability without $\\epsilon$-noise. We'll call\nthe inner probability $\\tilde{p_i}$. The two probabilities are related as\nfollows:\n\n\\[\np_i = (1 - \\epsilon) \\tilde{p}_i + \\epsilon (\\frac{1}{2})\n\\]\n\nBecause we always generate $\\tilde{p_i}$ using an inverse logit link function\nof a predictor, we can write $\\tilde{p_i}$ as a function of the (potentially\nnon-linear) predictor value, $z_i$:\n\n\\[\n\\tilde{p}_i = L(z_i) = (1 + \\exp(-z_i))^{-1}\n\\]\n\nThe linear relationship between $p_i$ and $\\tilde{p_i}$ implies that their\nderivatives with respect to model parameters are related as follows:\n\n\\[\n\\frac{\\partial}{\\partial \\theta_j} p_i\n  = (1 - \\epsilon) \\frac{\\partial}{\\partial \\theta_j} \\tilde{p}_i\n\\]\n\nA nice property of the inverse link function is that its derivative can be\nwritten in terms of a simple function of its value:\n\n\\[\n\\frac{\\partial}{\\partial z_i} L(z_i)\n  = L(z_i) (1 - L(z_i)) = \\tilde{p_i} (1 - \\tilde{p_i})\n\\]\n\nGiven all of this, we can compute gradients with regard to the $j$-th parameter\n$\\theta_j$ as follows using repeated applications of the chain rule to drill\ndown to the places where different models have different functional forms,\nwhich generates different gradients for different parameters:\n\n\\begin{equation*}\n\\begin{split}\n\\frac{\\partial}{\\partial \\theta_j} -\\mathcal{L}(\\theta)\n  &= -\\sum_{i = 1}^{N}\n    y_i \\frac{\\partial}{\\partial \\theta_j} \\log(p_i)\n    + (1 - y_i) \\frac{\\partial}{\\partial \\theta_j} \\log(1 - p_i) \\\\\n  &= -\\sum_{i = 1}^{N}\n    y_i \\frac{1}{p_i} \\frac{\\partial}{\\partial \\theta_j} p_i\n    + (1 - y_i) \\frac{1}{1 - p_i} \\frac{\\partial}{\\partial \\theta_j} (1 - p_i) \\\\\n  &= -\\sum_{i = 1}^{N}\n    y_i \\frac{1}{p_i} \\frac{\\partial}{\\partial \\theta_j} p_i\n    - (1 - y_i) \\frac{1}{1 - p_i} \\frac{\\partial}{\\partial \\theta_j} p_i \\\\\n  &= -\\sum_{i = 1}^{N}\n    y_i \\frac{1}{p_i} (1 - \\epsilon) \\frac{\\partial}{\\partial \\theta_j} \\tilde{p_i}\n    - (1 - y_i) \\frac{1}{1 - p_i} (1 - \\epsilon) \\frac{\\partial}{\\partial \\theta_j} \\tilde{p_i} \\\\\n  &= -\\sum_{i = 1}^{N}\n    y_i \\frac{1}{p_i} (1 - \\epsilon) \\tilde{p_i} (1 - \\tilde{p_i}) \\frac{\\partial}{\\partial \\theta_j} z_i\n    - (1 - y_i) \\frac{1}{1 - p_i} (1 - \\epsilon) \\tilde{p_i} (1 - \\tilde{p_i}) \\frac{\\partial}{\\partial \\theta_j} z_i \\\\\n\\end{split}\n\\end{equation*}\n\nIn the special case in which $\\epsilon = 0$, this last equation simplifies\nconsiderably because $p_i = \\tilde{p_i}$ when $\\epsilon = 0$:\n\n\\begin{equation*}\n\\begin{split}\n\\frac{\\partial}{\\partial \\theta_j} - \\mathcal{L}(\\theta)\n  &= -\\sum_{i = 1}^{N} y_i (1 - p_i) \\frac{\\partial}{\\partial \\theta_j} z_i\n    - (1 - y_i) p_i \\frac{\\partial}{\\partial \\theta_j} z_i \\\\\n  &= -\\sum_{i = 1}^{N} (y_i - p_i) \\frac{\\partial}{\\partial \\theta_j} z_i \\\\\n  &= \\sum_{i = 1}^{N} (p_i - y_i) \\frac{\\partial}{\\partial \\theta_j} z_i \\\\\n\\end{split}\n\\end{equation*}\n\n\\section{Gradient Calculations for Specific Models}\n\n\\subsection{Gradient Calculations for Baseline}\n\n\\begin{align*}\n\\theta &= (\\beta_0) \\\\\nz_i &= \\beta_0 \\\\\n\\frac{\\partial}{\\partial \\beta_0} z_i &= 1 \\\\\n\\end{align*}\n\n\\subsection{Gradient Calculations for ITCH}\n\n\\begin{align*}\n\\theta &= (\\beta_0, \\beta_1, \\beta_2, \\beta_3, \\beta_4) \\\\\nz_i &= \\beta_0\n  + \\beta_1 (x^2_i - x^1_i)\n  + \\beta_2 (\\frac{x^2_i - x^1_i}{\\frac{x^2_i + x^1_i}{2}})\n  + \\beta_3 (t^2_i - t^1_i)\n  + \\beta_4 (\\frac{t^2_i - t^1_i}{\\frac{t^2_i + t^1_i}{2}}) \\\\\n\\frac{\\partial}{\\partial \\beta_0} z_i &= 1 \\\\\n\\frac{\\partial}{\\partial \\beta_1} z_i &= x^2_i - x^1_i \\\\\n\\frac{\\partial}{\\partial \\beta_2} z_i &= \\frac{x^2_i - x^1_i}{\\frac{x^2_i + x^1_i}{2}} \\\\\n\\frac{\\partial}{\\partial \\beta_3} z_i &= t^2_i - t^1_i \\\\\n\\frac{\\partial}{\\partial \\beta_4} z_i &= \\frac{t^2_i - t^1_i}{\\frac{t^2_i + t^1_i}{2}} \\\\\n\\end{align*}\n\n\\subsection{Gradient Calculations for DRIFT}\n\n\\begin{align*}\n\\theta &= (\\beta_0, \\beta_1, \\beta_2, \\beta_3, \\beta_4) \\\\\nz_i &= \\beta_0\n  + \\beta_1 (x^2_i - x^1_i)\n  + \\beta_2 (\\frac{x^2_i - x^1_i}{x^1_i})\n  + \\beta_3 (\\frac{x^2_i}{x^1_i}^{\\frac{1}{t^2_i - t^1_i}} - 1)\n  + \\beta_4 (t^2_i - t^1_i) \\\\\n\\frac{\\partial}{\\partial \\beta_0} z_i &= 1 \\\\\n\\frac{\\partial}{\\partial \\beta_1} z_i &= x^2_i - x^1_i \\\\\n\\frac{\\partial}{\\partial \\beta_2} z_i &= \\frac{x^2_i - x^1_i}{x^1_i} \\\\\n\\frac{\\partial}{\\partial \\beta_3} z_i &= \\frac{x^2_i}{x^1_i}^{\\frac{1}{t^2_i - t^1_i}} - 1 \\\\\n\\frac{\\partial}{\\partial \\beta_4} z_i &= t^2_i - t^1_i \\\\\n\\end{align*}\n\n\\subsection{Gradient Calculations for Trade-Off}\n\n\\begin{align*}\n\\theta &= (a, k, \\gamma_x, \\gamma_t) \\\\\nz_i &= a(\n  \\phi(x^2_i, \\gamma_x) - \\phi(x^1_i, \\gamma_x)\n  - k * (\\phi(t^2_i, \\gamma_t) - \\phi(t^1_i, \\gamma_t))\n) \\\\\n\\phi(\\chi, \\gamma) &= \\frac{\\log(1 + \\gamma \\chi)}{\\gamma} \\\\\n\\phi^{\\prime}(\\chi, \\gamma)\n  &= \\frac{\\frac{\\gamma \\chi}{1 + \\gamma \\chi} - \\log(1 + \\gamma \\chi)}{\\gamma^2} \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= \\phi(x^2_i, \\gamma_x) - \\phi(x^1_i, \\gamma_x)\n    - k * (\\phi(t^2_i, \\gamma_t) - \\phi(t^1_i, \\gamma_t)) \\\\\n\\frac{\\partial}{\\partial k} z_i\n  &= -a (\\phi(t^2_i, \\gamma_t) - \\phi(t^1_i, \\gamma_t))) \\\\\n\\frac{\\partial}{\\partial \\gamma_x} z_i\n  &= a(\\phi^{\\prime}(x^2_i, \\gamma_x) - \\phi^{\\prime}(x^1_i, \\gamma_x)) \\\\\n\\frac{\\partial}{\\partial \\gamma_t} z_i\n  &= -a k (\\phi^{\\prime}(t^2_i, \\gamma_t) - \\phi^{\\prime}(t^1_i, \\gamma_t)) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < k < \\infty$}\n    \\item{$0 < \\gamma_x < \\infty$}\n    \\item{$0 < \\gamma_t < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Exponential}\n\n\\begin{align*}\n  \\theta &= (a, \\delta) \\\\\n  z_i &= a (x^2_i \\delta^{t^2_i} - x^1_i \\delta^{t^1_i}) \\\\\n  \\frac{\\partial}{\\partial a} z_i\n    &= x^2_i \\delta^{t^2_i} - x^1_i \\delta^{t^1_i} \\\\\n  \\frac{\\partial}{\\partial \\delta} z_i\n    &= a (x^2_i t^2_i \\delta^{t^2_i - 1} - x^1_i t^1_i \\delta^{t^1_i - 1}) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\delta < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Exponential with Intercept}\n\n\\begin{align*}\n  \\theta &= (a, \\delta, \\beta_0) \\\\\n  z_i &= \\beta_0 + a (x^2_i \\delta^{t^2_i} - x^1_i \\delta^{t^1_i}) \\\\\n  \\frac{\\partial}{\\partial a} z_i\n    &= x^2_i \\delta^{t^2_i} - x^1_i \\delta^{t^1_i} \\\\\n  \\frac{\\partial}{\\partial \\delta} z_i\n    &= a (x^2_i t^2_i \\delta^{t^2_i - 1} - x^1_i t^1_i \\delta^{t^1_i - 1}) \\\\\n  \\frac{\\partial}{\\partial \\beta_0} z_i\n    &= 1\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\delta < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Homothetic Exponential}\n\n\\begin{align*}\n\\theta &= (a, \\delta) \\\\\nz_i &= a (\\log(x^2_i \\delta^{t^2_i}) - \\log(x^1_i \\delta^{t^1_i})) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= (\\log(x^2_i \\delta^{t^2_i}) - \\log(x^1_i \\delta^{t^1_i})) \\\\\n\\frac{\\partial}{\\partial \\delta} z_i\n  &= a (\n      \\frac{1}{x^2_i \\delta^{t^2_i}} x^2_i t^2_i  \\delta^{t^2_i - 1} -\n      \\frac{1}{x^1_i \\delta^{t^1_i}} x^1_i t^1_i \\delta^{t^1_i - 1}\n    ) \\\\\n  &= a (t^2_i \\delta^{-1} - t^1_i \\delta^{-1}) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\delta < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Hyperbolic}\n\n\\begin{align*}\n\\theta &= (a, \\alpha) \\\\\nz_i &= a (x^2_i (1 + \\alpha t^2_i)^{-1} - x^1_i (1 + \\alpha t^1_i)^{-1}) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= (x^2_i (1 + \\alpha t^2_i)^{-1} - x^1_i (1 + \\alpha t^1_i)^{-1}) \\\\\n\\frac{\\partial}{\\partial \\alpha} z_i\n  &= a (\n    x^2_i (-1) (1 + \\alpha t^2_i)^{-2} t^2_i\n    - x^1_i (-1) (1 + \\alpha t^1_i)^{-2} t^1_i\n  ) \\\\\n  &= a (\n    x^1_i (1 + \\alpha t^1_i)^{-2} t^1_i\n    - x^2_i (1 + \\alpha t^2_i)^{-2} t^2_i\n  ) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\alpha < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Homothetic Hyperbolic}\n\n\\begin{align*}\n  z_i &= a (\n    \\log(x^2_i (1 + \\alpha t^2_i)^{-1})\n    - \\log(x^1_i (1 + \\alpha t^1_i)^{-1})\n  ) \\\\\n  \\theta &= (a, \\alpha) \\\\\n  \\frac{\\partial}{\\partial a} z_i\n    &= (\\log(x^2_i (1 + \\alpha t^2_i)^{-1}) - \\log(x^1_i (1 + \\alpha t^1_i)^{-1})) \\\\\n  \\frac{\\partial}{\\partial \\alpha} z_i\n    &= a (\\frac{x^2_i (-1) (1 + \\alpha t^2_i)^{-2} t^2_i}{x^2_i (1 + \\alpha t^2_i)^{-1}}\n      - \\frac{x^1_i (-1) (1 + \\alpha t^1_i)^{-2} t^1_i}{x^1_i (1 + \\alpha t^1_i)^{-1}}) \\\\\n    &= a (t^1_i (1 + \\alpha t^1_i)^{-1} - t^2_i (1 + \\alpha t^2_i)^{-1}) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\alpha < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Hyperbolic with Intercept}\n\n\\begin{align*}\n\\theta &= (a, \\alpha, \\beta_0) \\\\\nz_i &= \\beta_0 + a (x^2_i (1 + \\alpha t^2_i)^{-1} - x^1_i (1 + \\alpha t^1_i)^{-1}) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= (x^2_i (1 + \\alpha t^2_i)^{-1} - x^1_i (1 + \\alpha t^1_i)^{-1}) \\\\\n\\frac{\\partial}{\\partial \\alpha} z_i\n  &= a (\n    x^2_i (-1) (1 + \\alpha t^2_i)^{-2} t^2_i\n    - x^1_i (-1) (1 + \\alpha t^1_i)^{-2} t^1_i\n  ) \\\\\n\\frac{\\partial}{\\partial \\beta_0} z_i &= 1 \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\alpha < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Hyperboloid}\n\n\\begin{align*}\n\\theta &= (a, \\alpha, \\mu) \\\\\nz_i &= a (x^2_i (1 + \\alpha t^2_i)^{-\\mu} - x^1_i (1 + \\alpha t^1_i)^{-\\mu}) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= (x^2_i (1 + \\alpha t^2_i)^{-\\mu} - x^1_i (1 + \\alpha t^1_i)^{-\\mu}) \\\\\n\\frac{\\partial}{\\partial \\alpha} z_i\n  &= a (\n    x^2_i (-\\mu) (1 + \\alpha t^2_i)^{-\\mu - 1} t^2_i\n    - x^1_i (-\\mu) (1 + \\alpha t^1_i)^{-\\mu - 1} t^1_i\n  ) \\\\\n\\frac{\\partial}{\\partial \\mu} z_i\n  &= a (\n    -x^2_i (1 + \\alpha t^2_i)^{-\\mu} \\log(1 + \\alpha t^2_i)\n    - (-x^1_i) (1 + \\alpha t^1_i)^{-\\mu} \\log(1 + \\alpha t^1_i)\n  ) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\alpha < \\infty$}\n    \\item{$0 < \\mu < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Homothetic Hyperboloid}\n\n\\begin{align*}\n\\theta &= (a, \\alpha, \\mu) \\\\\nz_i &= a (\n  \\log(x^2_i (1 + \\alpha t^2_i)^{-\\mu})\n  - \\log(x^1_i (1 + \\alpha t^1_i)^{-\\mu})\n) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= \\log(x^2_i (1 + \\alpha t^2_i)^{-\\mu})\n  - \\log(x^1_i (1 + \\alpha t^1_i)^{-\\mu}) \\\\\n\\frac{\\partial}{\\partial \\alpha} z_i\n  &= a (\n    \\frac{1}{x^2_i (1 + \\alpha t^2_i)^{-\\mu}} x^2_i (-\\mu) (1 + \\alpha t^2_i)^{-\\mu - 1} t^2_i\n    - \\frac{1}{x^1_i (1 + \\alpha t^1_i)^{-\\mu}} x^1_i (-\\mu) (1 + \\alpha t^1_i)^{-\\mu - 1} t^1_i\n  ) \\\\\n  &= a (\n    (-\\mu) (1 + \\alpha t^2_i)^{-1} t^2_i\n    - (-\\mu) (1 + \\alpha t^1_i)^{-1} t^1_i\n  ) \\\\\n  &= a \\mu ((1 + \\alpha t^1_i)^{-1} t^1_i - (1 + \\alpha t^2_i)^{-1} t^2_i) \\\\\n\\frac{\\partial}{\\partial \\mu} z_i\n  &= a (\n    \\frac{1}{x^2_i (1 + \\alpha t^2_i)^{-\\mu}} (-x^2_i) (1 + \\alpha t^2_i)^{-\\mu} \\log(1 + \\alpha t^2_i)\n    - \\frac{1}{x^1_i (1 + \\alpha t^1_i)^{-\\mu}} (-x^1_i) (1 + \\alpha t^1_i)^{-\\mu} \\log(1 + \\alpha t^1_i)\n  ) \\\\\n  &= a (\n    -\\log(1 + \\alpha t^2_i) - (-\\log(1 + \\alpha t^1_i))\n  ) \\\\\n  &= a (\\log(1 + \\alpha t^1_i) - \\log(1 + \\alpha t^2_i)) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\alpha < \\infty$}\n    \\item{$0 < \\mu < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Hyperboloid with Intercept}\n\n\\begin{align*}\n\\theta &= (a, \\alpha, \\mu, \\beta_0) \\\\\nz_i &= a (x^2_i (1 + \\alpha t^2_i)^{-\\mu} - x^1_i (1 + \\alpha t^1_i)^{-\\mu}) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= (x^2_i (1 + \\alpha t^2_i)^{-\\mu} - x^1_i (1 + \\alpha t^1_i)^{-\\mu}) \\\\\n\\frac{\\partial}{\\partial \\alpha} z_i\n  &= a (\n    x^2_i (-\\mu) (1 + \\alpha t^2_i)^{-\\mu - 1} t^2_i\n    - x^1_i (-\\mu) (1 + \\alpha t^1_i)^{-\\mu - 1} t^1_i\n  ) \\\\\n\\frac{\\partial}{\\partial \\mu} z_i\n  &= a (\n    -x^2_i (1 + \\alpha t^2_i)^{-\\mu} \\log(1 + \\alpha t^2_i)\n    - (-x^1_i) (1 + \\alpha t^1_i)^{-\\mu} \\log(1 + \\alpha t^1_i)\n  ) \\\\\n\\frac{\\partial}{\\partial \\beta_0} z_i\n  &= 1\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\alpha < \\infty$}\n    \\item{$0 < \\mu < \\infty$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Quasi-Hyperbolic}\n\n\\begin{align*}\n\\theta &= (a, \\beta, \\delta) \\\\\nz_i &= a (\n  x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i}\n  - x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i}\n) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i}\n  - x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i} \\\\\n\\frac{\\partial}{\\partial \\beta} z_i\n  &= a (x^2_i I(t_2 > 0) \\delta^{t^2_i} - x^1_i I(t_1 > 0) \\delta^{t^1_i}) \\\\\n\\frac{\\partial}{\\partial \\delta} z_i\n  &= a (\n    x^2_i \\beta^{I(t_2 > 0)} t^2_i \\delta^{t^2_i - 1}\n    - x^1_i \\beta^{I(t_1 > 0)} t^1_i \\delta^{t^1_i - 1}\n  ) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\beta < 1$}\n    \\item{$0 < \\delta < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Homothetic Quasi-Hyperboloid}\n\n\\begin{align*}\n\\theta &= (a, \\beta, \\delta) \\\\\nz_i &= a (\n  \\log(x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i})\n  - \\log(x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i})\n) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= \\log(x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i})\n  - \\log(x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i}) \\\\\n\\frac{\\partial}{\\partial \\beta} z_i\n  &= a (\n    \\frac{1}{x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i}} x^2_i I(t_2 > 0) \\delta^{t^2_i}\n    - \\frac{1}{x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i}} x^1_i I(t_1 > 0) \\delta^{t^1_i}\n  ) \\\\\n  &= a (\n    \\frac{I(t_2 > 0)}{\\beta^{I(t_2 > 0)}}\n    - \\frac{I(t_1 > 0)}{\\beta^{I(t_1 > 0)}}\n  ) \\\\\n\\frac{\\partial}{\\partial \\delta} z_i\n  &= a (\n    \\frac{1}{x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i}} x^2_i \\beta^{I(t_2 > 0)} t^2_i \\delta^{t^2_i - 1}\n    - \\frac{1}{x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i}} x^1_i \\beta^{I(t_1 > 0)} t^1_i \\delta^{t^1_i - 1}\n  ) \\\\\n  &= a (\n    t^2_i \\delta^{-1}\n    - t^1_i \\delta^{-1}\n  ) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\beta < 1$}\n    \\item{$0 < \\delta < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard Quasi-Hyperboloid with Intercept}\n\n\\begin{align*}\n\\theta &= (a, \\beta, \\delta, \\beta_0) \\\\\nz_i &= \\beta_0 + a (\n  x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i}\n  - x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i}\n) \\\\\n\\frac{\\partial}{\\partial a} z_i\n  &= x^2_i \\beta^{I(t_2 > 0)} \\delta^{t^2_i}\n  - x^1_i \\beta^{I(t_1 > 0)} \\delta^{t^1_i} \\\\\n\\frac{\\partial}{\\partial \\beta} z_i\n  &= a (x^2_i I(t_2 > 0) \\delta^{t^2_i} - x^1_i I(t_1 > 0) \\delta^{t^1_i}) \\\\\n\\frac{\\partial}{\\partial \\delta} z_i\n  &= a (\n    x^2_i \\beta^{I(t_2 > 0)} t^2_i \\delta^{t^2_i - 1}\n    - x^1_i \\beta^{I(t_1 > 0)} t^1_i \\delta^{t^1_i - 1}\n  ) \\\\\n\\frac{\\partial}{\\partial \\beta_0} z_i &= 1 \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\beta < 1$}\n    \\item{$0 < \\delta < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard System-2}\n\n\\begin{align*}\n  \\theta &= (a, \\omega, \\delta_1, \\delta_2) \\\\\n  z_i &= a (\n    x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})\n    - x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})\n  ) \\\\\n  \\frac{\\partial}{\\partial a} z_i\n    &= (\n      x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})\n      - x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})\n    ) \\\\\n  \\frac{\\partial}{\\partial \\omega} z_i\n    &= a (\n      x^2_i (\\delta_1^{t^2_i} - \\delta_2^{t^2_i})\n      - x^1_i (\\delta_1^{t^1_i} - \\delta_2^{t^1_i})\n    ) \\\\\n  \\frac{\\partial}{\\partial \\delta_1} z_i\n    &= a (\n      x^2_i \\omega t^2_i \\delta_1^{t^2_i - 1}\n      - x^1_i \\omega t^1_i \\delta_1^{t^1_i - 1}\n    ) \\\\\n  \\frac{\\partial}{\\partial \\delta_2} z_i\n    &= a (\n      x^2_i (1 - \\omega) t^2_i \\delta_2^{t^2_i - 1}\n      - x^1_i (1 - \\omega) t^1_i \\delta_2^{t^1_i - 1}\n    ) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\delta_1 < 1$}\n    \\item{$0 < \\delta_2 < 1$}\n    \\item{$0 < \\omega < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Homothetic System-2}\n\n\\begin{align*}\n  \\theta &= (a, \\omega, \\delta_1, \\delta_2) \\\\\n  z_i &= a (\n    \\log(x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i}))\n    - \\log(x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i}))\n  ) \\\\\n  \\frac{\\partial}{\\partial a} z_i\n    &= (\n      \\log(x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i}))\n      - \\log(x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i}))\n    ) \\\\\n  \\frac{\\partial}{\\partial \\omega} z_i\n    &= a (\n      \\frac{x^2_i (\\delta_1^{t^2_i} - \\delta_2^{t^2_i})}{x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})}\n      - \\frac{x^1_i (\\delta_1^{t^1_i} - \\delta_2^{t^1_i})}{x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})}\n    ) \\\\\n    &= a (\n      \\frac{\\delta_1^{t^2_i} - \\delta_2^{t^2_i}}{\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i}}\n      - \\frac{\\delta_1^{t^1_i} - \\delta_2^{t^1_i}}{\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i}}\n    ) \\\\\n  \\frac{\\partial}{\\partial \\delta_1} z_i\n    &= a (\n      \\frac{x^2_i \\omega t^2_i \\delta_1^{t^2_i - 1}}{x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})}\n      - \\frac{x^1_i \\omega t^1_i \\delta_1^{t^1_i - 1}}{x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})}\n    ) \\\\\n    &= a (\n      \\frac{\\omega t^2_i \\delta_1^{t^2_i - 1}}{\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i}}\n      - \\frac{\\omega t^1_i \\delta_1^{t^1_i - 1}}{\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i}}\n    ) \\\\\n  \\frac{\\partial}{\\partial \\delta_2} z_i\n    &= a (\n      \\frac{x^2_i (1 - \\omega) t^2_i \\delta_2^{t^2_i - 1}}{x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})}\n      - \\frac{x^1_i (1 - \\omega) t^1_i \\delta_2^{t^1_i - 1}}{x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})}\n    ) \\\\\n    &= a (\n      \\frac{(1 - \\omega) t^2_i \\delta_2^{t^2_i - 1}}{\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i}}\n      - \\frac{(1 - \\omega) t^1_i \\delta_2^{t^1_i - 1}}{\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i}}\n    ) \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\delta_1 < 1$}\n    \\item{$0 < \\delta_2 < 1$}\n    \\item{$0 < \\omega < 1$}\n\\end{itemize}\n\n\\subsection{Gradient Calculations for Standard System-2 with Intercept}\n\n\\begin{align*}\n  \\theta &= (a, \\omega, \\delta_1, \\delta_2, \\beta_0) \\\\\n  z_i &= \\beta_0 + a (\n    x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})\n    - x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})\n  ) \\\\\n  \\frac{\\partial}{\\partial a} z_i\n    &= (\n      x^2_i (\\omega \\delta_1^{t^2_i} + (1 - \\omega) \\delta_2^{t^2_i})\n      - x^1_i (\\omega \\delta_1^{t^1_i} + (1 - \\omega) \\delta_2^{t^1_i})\n    ) \\\\\n  \\frac{\\partial}{\\partial \\omega} z_i\n    &= a (\n      x^2_i (\\delta_1^{t^2_i} - \\delta_2^{t^2_i})\n      - x^1_i (\\delta_1^{t^1_i} - \\delta_2^{t^1_i})\n    ) \\\\\n  \\frac{\\partial}{\\partial \\delta_1} z_i\n    &= a (\n      x^2_i \\omega t^2_i \\delta_1^{t^2_i - 1}\n      - x^1_i \\omega t^1_i \\delta_1^{t^1_i - 1}\n    ) \\\\\n  \\frac{\\partial}{\\partial \\delta_2} z_i\n    &= a (\n      x^2_i (1 - \\omega) t^2_i \\delta_2^{t^2_i - 1}\n      - x^1_i (1 - \\omega) t^1_i \\delta_2^{t^1_i - 1}\n    ) \\\\\n  \\frac{\\partial}{\\partial \\beta_0} z_i &= 1 \\\\\n\\end{align*}\n\nNote constraints:\n\n\\begin{itemize}\n    \\item{$0 < a < \\infty$}\n    \\item{$0 < \\delta_1 < 1$}\n    \\item{$0 < \\delta_2 < 1$}\n    \\item{$0 < \\omega < 1$}\n\\end{itemize}\n\n\\section{Handling Constraints}\nNote that the results shown above all apply to the raw model specification,\nwhich involves constraints that will necessitate the use of a constrained\noptimization routine. It is often convenient to be able to use an unconstrained\noptimization routine instead by assuming that optima never occur near the\nboundaries of the open sets used to constrain the model parameters.\n\nThe notes above show that only two types of constraints are needed for the\nmodels under consideration: constraints to $(0, \\infty)$ and to $(0, 1)$. We\ncan map unconstrained parameters to these constrained spaces using\n$\\exp(\\theta_j)$ to map $(-\\infty, \\infty)$ to $(0, \\infty)$ and by using\n$L(\\theta) = (1 + \\exp(-\\theta_j))^{-1}$ to map $(-\\infty, \\infty)$ to\n$(0, 1)$. When calculating the gradients of the negative log likelihood under\nthese unconstrained reparameterizations of the models, we need to introduce an\nadditional term of $\\exp(\\theta_j)$ to handle the first mapping and an\nadditional term of $L(\\theta_j) (1 - L(\\theta_j))$ to handle the second\nmapping.\n\n\\end{document}\n", "meta": {"hexsha": "447b6d190fca4b07dc236c38afa82e58c034086c", "size": 21221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/gradients.tex", "max_stars_repo_name": "johnmyleswhite/IntertemporalChoiceHeuristics.jl", "max_stars_repo_head_hexsha": "6562fb1740a5e7af67b3a427a32acfd473a7e53f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-02T21:33:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-02T21:33:51.000Z", "max_issues_repo_path": "doc/gradients.tex", "max_issues_repo_name": "johnmyleswhite/IntertemporalChoiceHeuristics.jl", "max_issues_repo_head_hexsha": "6562fb1740a5e7af67b3a427a32acfd473a7e53f", "max_issues_repo_licenses": ["MIT"], "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/gradients.tex", "max_forks_repo_name": "johnmyleswhite/IntertemporalChoiceHeuristics.jl", "max_forks_repo_head_hexsha": "6562fb1740a5e7af67b3a427a32acfd473a7e53f", "max_forks_repo_licenses": ["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.4188976378, "max_line_length": 125, "alphanum_fraction": 0.5669855332, "num_tokens": 9043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6952675981270163}}
{"text": "\\section{Fourier}\n\nSome signal processing tests make use of Fourier-based signals for analytic tests.\n\nIn constructing a Fourier signal, we use the formulation\n\n\\begin{equation}\n  f(t) = \\sum_{k} \\sin\\frac{2\\pi}{k\\in\\Lambda}t + \\cos\\frac{2\\pi}{k}t,\\hspace{20pt}\\Lambda\\in\\Bbb R^N,\n\\end{equation}\nwhere the choice of periods $\\Lambda$ is any arbitrary set of real numbers and can have any dimensionality.\n\nIf the resulting signal is treated by a fast fourier transform, it should show peaks at the frequencies\ncorresponding to the selected periods, where frequencies are simply the inverse of the periods.\n", "meta": {"hexsha": "008c4468ee51f5f2bd68cb2576b974003f7c2401", "size": 605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/fourier.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/tests/fourier.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/tests/fourier.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": 43.2142857143, "max_line_length": 107, "alphanum_fraction": 0.7719008264, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6952675885242897}}
{"text": "\\section{Introduction}\n\\textbf{support vector machine} (SVM, also support vector networks) is a kind of binary classification models of supervised learning. Given a set of training examples, each marked as belonging to one or the other of two categories, an SVM training algorithm builds a model that assigns new examples to one category or the other, making it a non-probabilistic binary classifier.\n\\par From simple to complex,there are 3 levels of SVM,which are linear SVM in linearly separable case,linear SVM and non-linear SVM.\n\\begin{itemize}\n  \\item linear SVM in linearly separable case: while training data is linearly separable,we can use hard margin maximization algorithms to learn a binary linear classification.\n  \\item linear SVM: while training data is approximately linearly separable,we can use soft margin maximization algorithms to learn a binary linear classification.\n  \\item non-linear SVM: while training data isn't linearly separable,we can use kernel methods with soft margin maximization algorithms to learn a binary non-linear classifier.\n\\end{itemize}\n\n\n\\section{Linear SVM in linearly separable case}\n\\paragraph{Linearly separable} Let $\\displaystyle X_{0}$ and $\\displaystyle X_{1}$  be two sets of points in an n-dimensional Euclidean space.Then $\\displaystyle X_{0}$ and $\\displaystyle X_{1}$ are linearly separable if there exists an $n$-dimensional real vector $\\omega$ and a real value b, such that every point $\\displaystyle x\\in X_{0}$ satisfies $\\displaystyle\\omega\\cdot x+b>0$ and every point $\\displaystyle x\\in X_{1}$ satisfies $\\displaystyle \\omega\\cdot x+b<0$.\n\\\\\n\\\\We are given a training dataset of $\\displaystyle N$ points of the form\n$$(x_{1},y_{1}),\\cdots,(x_{N},y_{N})$$\nwhere $\\displaystyle x_{i}\\in \\mathbf{R}^n,y_{i}\\in \\{-1,1\\}$.$\\displaystyle y_{i}$ is a label that indicates which category $\\displaystyle x_{i}$ belongs  to.And we suppose that our training data is linearly separable.\n\\par We want to find the \"maximum-margin hyperplane\" that divides the group of points $x_{i}$ for which $\\displaystyle y_{i}=1$ from the group of points for which $\\displaystyle y_{i}=-1$, which is defined so that the distance between the hyperplane and the nearest point $\\displaystyle x_{i}$ from either group is maximized.\n\\par Any hyperplane can be written as the set of points $\\displaystyle x$ satisfying $\\displaystyle \\omega\\cdot x+b=0$,where $\\displaystyle \\omega$ is the (not necessarily normalized) normal vector to the hyperplane.The parameter $\\displaystyle\\ \\frac{b}{\\|\\omega\\|}\\ $ determines the offset of the hyperplane from the origin along the normal vector $\\displaystyle\\omega$.\n\n\\subsection{Hard margin}\n\nIf the training data are linearly separable, we can select two parallel hyperplanes that separate the two classes of data, so that the distance between them is as large as possible. The region bounded by these two hyperplanes is called the \"margin\", and the maximum-margin hyperplane is the hyperplane that lies halfway between them.\n\\noindent\n\n\\includegraphics[height=5cm]{margin}\n\n\\paragraph{Functional margin} Given a training dataset $T$ and hyperplane $\\displaystyle(\\omega,b)$,we define the functional margin of hyperplane $\\displaystyle(\\omega,b)$ $w.r.t.$ data $\\displaystyle(x_{i},y_{i})$ as\n\\begin{equation}\n\\widehat{\\gamma_{i}}=y_{i}(\\omega\\cdot x_{i}+b)\n\\end{equation}\nand can define the functional margin of hyperplane $\\displaystyle(\\omega,b)$ $w.r.t.$ dataset $T$ as\n\\begin{equation}\n\\widehat{\\gamma}=\\min_{i=1,\\cdots,N}\\widehat{\\gamma_{i}}\n\\end{equation}\n\n\\paragraph{Geometric margin} Given a training dataset $T$ and hyperplane $(\\omega,b)$,we define the geometric margin of hyperplane $(\\omega,b)$ $w.r.t.$ data $(x_{i},y_{i})$ as\n\\begin{equation}\n\\displaystyle\\gamma_{i}=\\frac{\\widehat{\\gamma_{i}}}{\\|\\omega\\|}\n\\end{equation}\nand can define the functional margin of hyperplane $(\\omega,b)$ $w.r.t.$ dataset $T$ as\n\\begin{equation}\n\\displaystyle\\gamma=\\min_{i=1,\\cdots,N}\\gamma_{i}=\\frac{\\widehat{\\gamma}}{\\|\\omega\\|}\n\\end{equation}\n\\\\Notice that if we change $(\\omega,b)$ into $(\\lambda\\omega,\\lambda b)$,the hyperplane and geometric margin remain unchanged,but functional margin $\\displaystyle\\widehat{\\gamma}$ changes into $\\displaystyle\\lambda\\widehat{\\gamma}$.In fact,what we want to maximize is geometric margin,but we can use the freedom of functional margin to simplify the optimization problem.\n\n\\subsection{Hard margin maximization method}\n\nThe basic idea of linear SVM is to maximize the geometric margin,and to find maximum margin classifier.The problem can be described as follows\n\\begin{equation}\n \\begin{split}\n  &\\max_{\\bm\\omega,b}\\ \\ \\gamma\\\\\n  &s.t.\\ \\min\\limits_{i=1,2,\\cdots,N}\\ y_{i}(\\bm\\omega\\bm\\cdot\\bm x_{i}+b)>0\\\\\n \\end{split}\n\\end{equation}\nNotice two things below:\n\\begin{enumerate}\n \\item $\\gamma(\\lambda\\bm\\omega,\\lambda b)=\\gamma(\\bm\\omega,b)$\n \\item Given $(\\bm\\omega,b)$, there always exists a $\\lambda$ such that $\\widehat{\\gamma}(\\lambda\\bm\\omega,\\lambda b)=1$\n\\end{enumerate}\nSo if we add an extra restraint $\\ \\widehat{\\gamma}(\\bm\\omega,b)=1$, it won't affect the result of (5). Then problem (5) turns out to be\n\\begin{equation}\n \\begin{split}\n  &\\max_{\\omega,b}\\ \\ \\frac{1}{\\|\\bm\\omega\\|}\\\\\n  &s.t.\\ \\min\\limits_{i=1,2,\\cdots,N}\\ y_{i}(\\bm\\omega\\bm\\cdot\\bm x_{i}+b)=1\\\\\n \\end{split}\n\\end{equation}\nIn order to change (6) into a convex problem, we expand constraint domain to a convex domain by adding points $(\\bm\\omega,b)$ which satisfies $\\widehat{\\gamma}(\\bm\\omega,b)>1$.\n\\\\Suppose $\\widehat{\\gamma}(\\bm\\omega_{0},b_{0})>1$, take $\\displaystyle\\bm\\omega_{1}=\\frac{\\bm\\omega_{0}}{\\widehat{\\gamma_{0}}},\\ b_{1}=\\frac{b_{0}}{\\widehat{\\gamma_{0}}}$, we have $$\\displaystyle\\gamma(\\bm\\omega_{1},b_{1})=1,\\ \\ \\frac{1}{\\|\\bm\\omega_{1}\\|}=\\frac{\\widehat{\\gamma_{0}}}{\\|\\bm\\omega_{0}\\|}>\\frac{1}{\\|\\bm\\omega_{0}\\|}$$.\nSo we can see that this operation won't affect the result of (6). Meanwhile, to maximize $\\displaystyle\\frac{1}{\\|\\bm\\omega\\|}$ is equally to minimize $\\displaystyle\\frac{1}{2}\\|\\bm\\omega\\|^2$, our problem can be finally written as following\n\\begin{equation}\n \\begin{split}\n  &\\min_{\\bm\\omega,b}\\ \\frac{1}{2}\\|\\bm\\omega\\|^{2}\\\\\n  &s.t.\\ \\ y_{i}(\\bm\\omega\\bm\\cdot\\bm x_{i}+b)\\geq 1,\\ i=1,2,\\cdots ,N\n \\end{split}\n\\end{equation}\n\n\\begin{algorithm}\n\\caption{Hard margin maximization method}\n\\textbf{Input:} linearly separable dataset $T=\\{(x_{1},y_{1}),\\cdots,(x_{N},y_{N})\\},x_{i}\\in\\chi=\\textbf{R}^n ,y_{i}\\in\\Upsilon=\\{-1,1\\},i=1,2,\\cdots,N\\\\$\n\\textbf{Output:} maximum margin hyperplane $(\\omega,b)$ and classification decision function $f(x)=sign(\\omega\\cdot x+b)$\n\\begin{algorithmic}[1]\n\\State Solve problem (7),get optimal solution $(\\omega^*,b^*)$\n\\State get maximum margin hyperplane $\\omega^*\\cdot x+b^*=0$ and classification decision function $f(x)=sign(\\omega^*\\cdot x+b)$\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{theorem}\n If training dataset$T$ is linearly separable,the solution of problem (1) exists uniquely, in other words,the maximum margin hyperplane exists uniquely.\n\\end{theorem}\n\n\\paragraph{Support vector} If training dataset $T$ is linearly separable,then $x$ is a support vector precisely when $\\ y(\\omega\\cdot x+b)=1$.\n\n\\subsection{Dual method}\n\nIn order to solve problem (7), we can consider it as a primal problem,use Lagrange duality theory to get its dual problem. And we can solve the dual problem to get the solution of the primal problem.\n\n\\paragraph{Remark} Here we'll introduce several conclusions in convex optimization programming before going further in dual method.\n\\\\Consider a convex optimal problem:\n\\begin{equation}\n\\begin{split}\n&\\min_{x\\in\\textbf{R}^n} f(x)\\\\\n&s.t.\\ c_{i}(x)\\leq 0,\\ i=1,2,\\cdots,k;\\ h_{j}(x)=0,\\ j=1,2,\\cdots,l\n\\end{split}\n\\end{equation}\n\\\\We call this problem a primal problem.Its generalized Lagrange function is\n\\begin{equation}\nL(x,\\alpha,\\beta)=f(x)+\\sum\\limits_{i=1}^{k}\\alpha_{i}c_{i}(x)+\\sum\\limits_{i=1}^{l}\\beta_{j}h_{j}(x)\n\\end{equation}\nHere,$x=(x^{(1)},x^{(2)},\\cdots,x^{(n)})\\in\\ \\mathbf{R}^n$,$\\alpha,\\beta$ is Lagrange multiplier,$\\alpha_{i}\\geq 0$.\n\\\\Consider problem\n\\begin{equation}\nd^*=\\min\\limits_{x}\\max\\limits_{\\alpha,\\beta;\\alpha\\geq 0}\\ \\ L(x,\\alpha,\\beta)\n\\end{equation}\nWe can easily prove that problem $(10)$ is equal to problem $(8)$.\nMeanwhile,the dual problem of $(10)$ is defined as\n\\begin{equation}\np^*=\\max\\limits_{\\alpha,\\beta;\\alpha\\geq 0}\\min\\limits_{x}\\ \\ L(x,\\alpha,\\beta)\n\\end{equation}\n\nwe have following theorem.\n\n\\begin{theorem}[KKT]\n Suppose that $f(x)$ and $c_{i}(x)$ are convex functions, $h_{j}(x)$ is an affine function,meanwhile, inequality constraint $c_{i}(x)$ is strictly feasible, which means $\\exists x,\\ \\forall i,\\ c_{i}(x)<0$.\n \\begin{itemize}\n   \\item $\\exists\\ x^*,\\bm\\alpha^*,\\bm\\beta^*$, such that $x^*$ is the solution of the primal problem $(7)$, $\\bm\\alpha^*,\\bm\\beta^*$ is the solution of the dual problem $(8)$,and $d^*=p^*=L(x^*,\\bm\\alpha^*,\\bm\\beta^*)$.\n   \\item $x^*$ is the solution of the primal problem $(7)$, $\\bm\\alpha^*,\\bm\\beta^*$ is the solution of the dual problem $(8)$ $iff$ $x^*,\\bm\\alpha^*,\\bm\\beta^*$ satisfy:\n         \\begin{equation}\n\t     \\left\\{\n\t     \\begin{split}\n\t     &\\nabla_{x} L(x^*,\\bm \\alpha^*, \\bm \\beta^*)&=0\\\\\n         &\\nabla_{\\bm\\alpha} L(x^*,\\bm \\alpha^*, \\bm \\beta^*)&=0\\\\\n         &\\nabla_{\\bm\\beta} L(x^*,\\bm \\alpha^*, \\bm \\beta^*)&=0\\\\\n\t     &\\alpha_i^* c_i(x^*)&=0\\\\\n\t     & c_i(x^*)&\\leq 0\\\\\n\t     &\\alpha_i^* &\\geq 0\\\\\n\t     &h_j(x^*) &= 0\\\\\n\t     \\end{split}\n\t     \\right.\n\t     \\end{equation}\n \\end{itemize}\n\\end{theorem}\n\\noindent\n\\\\\n\\\\Now we can go back to the SVM problem.\n\\\\In SVM, we have$$x=(\\omega,b),\\ f(x)=\\frac{1}{2}\\|\\omega\\|^{2},\\ k=N,\\ c_{i}(x)=1-y_{i}(\\omega\\cdot x_{i}+b),h_{j}(x)=0$$\nFirst,we can construct $generalized\\ Lagrange\\ function$ according to the constraints in problem (7).Introduce $Lagarange\\ multiplier $ $\\alpha_{i}\\geq 0,\\ i=1,2,\\cdot,N$ and define $Lagrange\\ function$:\n\\begin{equation}\nL(\\omega,b,\\alpha)=\\frac{1}{2}\\|\\omega\\|^2-\\sum\\limits_{i=1}^{N}\\alpha_{i}y_{i}(\\omega\\cdot x_{i}+b)+\\sum\\limits_{i=1}^{N}\\alpha_{i}\n\\end{equation}\nWe can easily prove that the primal problem $\\min\\limits_{\\omega,b}\\max\\limits_{\\alpha;\\alpha_{i}\\geq 0}L(\\omega,b,\\alpha)$ is equal to problem $(7)$.\nAnd its dual problem is $\\max\\limits_{\\alpha;\\alpha_{i}\\geq 0}\\min\\limits_{\\omega,b}L(\\omega,b,\\alpha)$.\nNext,we will rewrite the form of dual problem.\n\\\\Consider $\\min\\limits_{\\omega,b}L(\\omega,b,\\alpha)$,make\n\\begin{equation}\n\\begin{split}\n&\\nabla_{\\omega} L(\\omega, b, \\bm \\alpha)=\\omega-\\sum\\limits_{i=1}^{N}\\alpha_{i}y_{i}x_{i}=0\\\\\n&\\nabla_{b} L(\\omega, b, \\bm \\alpha)=\\sum\\limits_{i=1}^{N}\\alpha_{i}y_{i}=0\n\\end{split}\n\\end{equation}\nApply the result to equation (16), we can compute to obtain that\n\\begin{equation}\nL(\\omega,b,\\bm\\alpha)=-\\frac{1}{2}\\sum\\limits_{i=1}^{N}\\sum\\limits_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}(x_{i}\\cdot x_{j})+\\sum\\limits_{i=1}^{N}\\alpha_{i}\n\\end{equation}\nSo\n\\begin{equation}\n\\min\\limits_{\\omega,b}L(\\omega,b,\\bm\\alpha)=-\\frac{1}{2}\\sum\\limits_{i=1}^{N}\\sum\\limits_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}(x_{i}\\cdot x_{j})+\\sum\\limits_{i=1}^{N}\\alpha_{i}\n\\end{equation}\nThen we have\n\\begin{equation}\n\\max\\limits_{\\alpha;\\alpha_{i}\\geq 0}\\min\\limits_{\\omega,b}L(\\omega,b,\\bm\\alpha)=\\max\\limits_{\\bm\\alpha;\\alpha_{i}\\geq 0}-\\frac{1}{2}\\sum\\limits_{i=1}^{N}\\sum\\limits_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}(x_{i}\\cdot x_{j})+\\sum\\limits_{i=1}^{N}\\alpha_{i}\n\\end{equation}\nFinally,we can obtain a optimization problem of $\\bm\\alpha$\n\\begin{equation}\n\\begin{split}\n&\\max_{\\alpha}\\  -\\frac{1}{2}\\sum\\limits_{i=1}^{N}\\sum\\limits_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}(x_{i}\\cdot x_{j})+\\sum\\limits_{i=1}^{N}\\alpha_{i}\\\\\n&s.t.\\  \\sum\\limits_{i=1}^{N}\\alpha_{i}y_{i}=0,\\ \\alpha_{i}\\geq 0,\\ i=1,2,\\cdots,N\n\\end{split}\n\\end{equation}\nConsider problem $(7)$,problem (7) satisfies the condition of $Theorem\\ R2$,so $\\exists$ $(\\omega^*,\\alpha^*,\\beta^*)\\ S.t\\ \\omega^*$ is the solution of the primal problem (10),$\\alpha^*,\\beta^*$ is the solution of the dual problem (11).\nFor linearly separable training dataset,suppose that $\\alpha^*$ is the solution of problem $(21)$,we can obtain the solution $(\\omega^*,b^*)$ of problem $(7)$ from $\\alpha^*$.\n\n\\begin{theorem}\nSuppose that $\\alpha^*$ is the solution of problem (21),then $\\exists$ subscript $j$ ,$S.t\\ \\alpha_{j}^*>0$, and we can obtain the solution $(\\omega^*,b^*)$ of problem $(7)$ from the following equations:\n\\begin{equation}\n\\begin{split}\n&\\omega^*=\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}x_{i}\n\\\\&b^*=y_{j}-\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}(x_{i}\\cdot x_{j})\n\\end{split}\n\\end{equation}\n\\end{theorem}\n\n$proof$ Acordding to \\textbf{Theorem 2}, KKT condition is satisfied,\n\\\\so we have\n\\begin{equation}\n\\begin{split}\n&\\nabla_{\\omega} L(\\omega^*, b^*, \\bm \\alpha^*)=\\omega^*-\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}x_{i}=0\\\\\n&\\nabla_{b} L(\\omega^*, b^*, \\bm \\alpha^*)=-\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}=0\\\\\n&\\alpha_{i}^*(y_{i}(\\omega^*\\cdot x_{i}+b^*)-1)= 0,\\ i=1,2,\\cdots,N\\\\\n&y_{i}(\\omega^*\\cdot x_{i}+b^*)-1\\geqslant 0,\\ i=1,2,\\cdots,N\\\\\n&\\alpha_{i}^*\\geqslant 0,\\ i=1,2,\\cdots,N\\\\\n\\end{split}\n\\end{equation}\nSo\n\\begin{equation}\n\\omega^*=\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}x_{i}\n\\end{equation}\nSuppose that $\\alpha^*=0$,we have $\\omega^*=0$,obviously it's not the solution of the primal problem.It's contradictory to $Theorem\\ R2$.\n\\\\So $\\exists$ subscript $j,\\ S.t\\ \\alpha_{j}^*>0$.\n\\\\For this $j$, we have\n\\begin{equation}\ny_{j}(\\omega^*\\cdot x_{j}+b^*)-1=0\n\\end{equation}\n\\\\By the way,it means that $x_{j}$ must be a support vector.\n\\\\Take $(24)$ into $(25)$,and notice that $y_{j}^2=1$,we have\n\\begin{equation}\nb^*=y_{j}-\\sum\\limits_{i=1}^{N}\\alpha^*y_{i}(x_{i}\\cdot x_{j})\n\\end{equation}\nFrom this theorem we can see that maximum margin hyperplane can be described by\n\\begin{equation}\n\\sum\\limits_{i=1}^{N}\\alpha^*y_{i}(x_{i}\\cdot x)+b^*=0\n\\end{equation}\nAnd classification decision function can be described by\n\\begin{equation}\nf(x)=sign(\\sum\\limits_{i=1}^{N}\\alpha^*y_{i}(x_{i}\\cdot x)+b^*)\n\\end{equation}\n\n\n\n%\\begin{algorithm}\n%\\caption{dual method}\n%\\textbf{Input:} linearly separable dataset $T={(x_{1},y_{1}),\\cdots,(x_{N},y_{N})},x_{i}\\in\\chi=\\textbf{R}^n ,y_{i}\\in\\Upsilon=\\{-1,1\\},i=1,2,\\cdots,N\\\\$\n%\\textbf{Output:} maximum margin hyperplane $(\\omega,b)$ and classification decision function $f(x)=sign(\\omega^Tx+b)$\n%\\begin{algorithmic}[1]\n%\\State Solve problem (21),get optimal solution $\\alpha^*$\n%\\State Compute\n%$$\\omega^*=\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}x_{i}$$\n%Choose one of the positive component $\\alpha_{j}^*$ of $\\alpha^*$,compute\n%$$b^*=y_{j}-\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}(x_{i}\\cdot x_{j})$$\n%\\State get maximum margin hyperplane $\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}(x_{i}\\cdot x)+b^*=0$ and classification decision function %$f(x)=sign(\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}(x_{i}\\cdot x)+b^*)$\n%\\end{algorithmic}\n%\\end{algorithm}\n\n\n\n\n\\section{Soft margin maximization}\nGiven a training dataset of $\\displaystyle N$ points of the form\n$$(x_{1},y_{1}),\\cdots,(x_{N},y_{N})$$\nwhere $\\displaystyle x_{i}\\in \\mathbf{R}^n,y_{i}\\in \\{-1,1\\}$. $\\displaystyle y_{i}$ is a category label of $\\displaystyle x_{i}$ .We suppose that our training data is not linearly separable, but we can get a linearly separable set by removing few outliers. In this situation, we still want to get a linear classifier. The difference is we need to find a balance between maximizing \"margin\" and minimizing the classifier model bias.\\\\\nWe use hinge loss function to describe the classifier model bias.\n\\begin{equation}\nL(y(\\omega\\cdot x+b))=[1-y(\\omega\\cdot x+b)]_{+}=\\max(0,1-y(\\omega\\cdot x+b))\n\\end{equation}\nIt is to say that while $(x_{i},y_{i})$ is correctly classified by $(\\omega,b)$ and functional margin $y_{i}(\\omega\\cdot x_{i}+b)\\ge 1$, the loss is 0; otherwise, the loss is $1-y_{i}(\\omega\\cdot x_{i}+b)$.\nNow we can describe the problem as follows:\n\\begin{equation}\n  \\min_{\\bm\\omega,b}\\ \\ \\sum_{i=1}^{N}[1-y_{i}(\\bm\\omega\\cdot\\bm x_{i}+b)]_{+}+\\lambda\\|\\bm\\omega\\|^2\n\\end{equation}\n$\\lambda$ is a parameter up to the real problem which balances the \"margin\" maximization and bias minimization.\n\n\\begin{theorem}\n  problem (27) is equivalent to following problem:\n  \\begin{equation}\n    \\begin{split}\n      &\\min_{\\bm\\omega,b,\\bm\\xi}\\ \\ \\frac{1}{2}\\|\\bm\\omega\\|^2+C\\sum_{i=1}^{N}\\xi_{i}\\\\\n      &s.t.\\ \\ y_{i}(\\bm\\omega\\cdot\\bm x_{i}+b)+\\xi_{i}\\geqslant 1,\\ \\xi_{i}\\geqslant 0,\\ i=1,2,\\cdots,N\n    \\end{split}\n  \\end{equation}\n\\end{theorem}\n\n\\noindent\nTake $\\displaystyle C=\\frac{1}{2\\lambda}$, the equivalence property is obvious. Notice that problem (28) is the same kind of question as problem (8). So we can use Lagrange dualty as we do in hard margin maximization.\\\\\n\\\\\nThe generalized Lagrange function of (28) is:\n\\begin{equation}\n  L(\\bm\\omega,b,\\bm\\xi,\\bm\\alpha,\\bm\\mu)\\equiv \\frac{1}{2}\\|\\omega\\|^2+C\\sum_{i=1}^{N}\\xi_{i}-\\sum_{i=1}^{N}\\alpha_{i}(y_{i}(\\bm\\omega\\cdot \\bm x_{i}+b)+\\xi_{i}-1)-\\sum_{i=1}^{N}\\mu_{i}\\xi_{i}\n\\end{equation}\nThe primal problem of (28) is:\n\\begin{equation}\n  d^*=\\min_{\\bm\\omega,b,\\bm\\xi}\\ \\ \\max_{\\bm\\alpha,\\bm\\mu;\\bm\\alpha\\geqslant 0,\\bm\\mu\\geqslant 0}\\ \\ L(\\bm\\omega,b,\\bm\\xi,\\bm\\alpha,\\bm\\mu)\n\\end{equation}\nThe dual problem of (28) is:\n\\begin{equation}\n  p^*=\\max_{\\bm\\alpha,\\bm\\mu;\\bm\\alpha\\geqslant 0,\\bm\\mu\\geqslant 0}\\ \\ \\min_{\\bm\\omega,b,\\bm\\xi}\\ \\ L(\\bm\\omega,b,\\bm\\xi,\\bm\\alpha,\\bm\\mu)\n\\end{equation}\nSimilar to hard maximization, our goal is to find $(\\bm\\omega^*,b^*,\\bm\\xi^*,\\bm\\alpha^*,\\bm\\mu^*)$ such that $\\bm\\omega^*,b^*,\\bm\\xi^*$ is the solution of the primal problem $(30)$, $\\bm\\alpha^*,\\bm\\mu^*$ is the solution of the dual problem $(31)$,and $d^*=p^*=L(\\bm\\omega^*,b^*,\\bm\\xi^*,\\bm\\alpha^*,\\bm\\mu^*)$.\\\\\n\\\\\nAccording to \\textbf{Theorem 2(KKT)}, we can add following extra restraints to the problem without losing optimal points $(\\bm\\omega^*,b^*,\\bm\\xi^*,\\bm\\alpha^*,\\bm\\mu^*)$:\n\\begin{equation}\n  \\begin{split}\n    &\\nabla_{\\bm\\omega} L(\\bm\\omega,b,\\bm\\xi,\\bm\\alpha,\\bm\\mu)=\\bm\\omega-\\sum\\limits_{i=1}^{N}\\alpha_{i}y_{i}\\bm{x_{i}}=0\\\\\n    &\\nabla_{b} L(\\bm\\omega,b,\\bm\\xi,\\bm\\alpha,\\bm\\mu)=-\\sum\\limits_{i=1}^{N}\\alpha_{i}y_{i}=0\\\\\n    &\\nabla_{\\xi_{i}} L(\\bm\\omega,b,\\bm\\xi,\\bm\\alpha,\\bm\\mu)=C-\\alpha_{i}-\\mu_{i}\n  \\end{split}\n\\end{equation}\nApply (32) to problem (31), we can simplify (31) as:\n\\begin{equation}\n  \\begin{split}\n    &\\min_{\\bm\\alpha}\\ \\ \\frac{1}{2}\\sum_{i=1}^{N}\\sum_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}(\\bm{x_{i}}\\cdot\\bm{x_{j}})-\\sum_{i=1}^{N}\\alpha_{i}\\\\\n    &s.t.\\ \\ \\sum_{i=1}^{N}\\alpha_{i}y_{i}=0,\\ 0 \\leqslant \\alpha_{i} \\leqslant C,\\ i=1,2,\\cdots,N\n  \\end{split}\n\\end{equation}\n\n\\begin{theorem}\n  Suppose $(\\bm\\alpha^*=(\\alpha_{1}^*,\\alpha_{2}^*,\\cdots,\\alpha_{N}^*)^{T})$ is one of the solution of dual problem (33). If there is a component of $\\bm\\alpha$ satisfies $0<\\alpha_{j}^*<C$, then we can get a solution $\\bm\\omega^*,b^*$ of primal problem (28) as:\n  \\begin{equation}\n    \\bm\\omega^{*}=\\sum_{i=1}^{N}\\alpha_{i}^*y_{i}\\bm x_{i}\n  \\end{equation}\n  \\begin{equation}\n    b^*=y_{j}-\\sum_{i=1}^{N}y_{i}\\alpha_{i}^*(\\bm x_{i}\\bm\\cdot\\bm x_{j})\n  \\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n  According to \\textbf{Theorem 2(KKT)}, we have\n  \\begin{equation}\n    \\nabla_{\\bm\\omega} L(\\bm\\omega^*,b^*,\\bm\\xi^*,\\bm\\alpha^*,\\bm\\mu^*)=\\bm\\omega^*-\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}\\bm{x_{i}}=0\n  \\end{equation}\n  \\begin{equation}\n    \\nabla_{b} L(\\bm\\omega^*,b^*,\\bm\\xi^*,\\bm\\alpha^*,\\bm\\mu^*)=-\\sum\\limits_{i=1}^{N}\\alpha_{i}^*y_{i}=0\n  \\end{equation}\n  \\begin{equation}\n    \\nabla_{\\xi_{i}} L(\\bm\\omega^*,b^*,\\bm\\xi^*,\\bm\\alpha^*,\\bm\\mu^*)=C-\\alpha_{i}^*-\\mu_{i}^*\n  \\end{equation}\n  \\begin{equation}\n    \\alpha_{i}^*(y_{i}(\\bm\\omega^*\\bm\\cdot \\bm x_{i}+b^*)-1+\\xi_{i}^*)= 0\n  \\end{equation}\n  \\begin{equation}\n    \\mu_{i}^*\\xi_{i}^*=0\n  \\end{equation}\n  \\begin{equation}\n    y_{i}(\\bm\\omega^*\\bm\\cdot \\bm x_{i}+b^*)-1+\\xi_{i}^*\\geqslant 0\n  \\end{equation}\n  \\begin{equation}\n    \\xi_{i}^*\\geqslant 0\n  \\end{equation}\n  \\begin{equation}\n    \\alpha^*\\geqslant 0\n  \\end{equation}\n  \\begin{equation}\n    \\mu^*\\geqslant 0\n  \\end{equation}\n  From equation (36), we can directly get result (34).\n  From (39)(40) we know that if there exists an $\\alpha_{j}^*$ such that $0<\\alpha_{j}^*<C$, then we have\n  $$y_{j}(\\bm\\omega^*\\bm\\cdot \\bm x_{j}+b^*)-1=0$$\n  This is equivalent to result (35).\n\\end{proof}\n\n\\paragraph{support vectors of soft margin} In soft margin maximization method, we say a data point $(x_{i},y_{i})$ is a support vector if the solution $\\bm\\alpha^*=(\\alpha_{1}^*,\\alpha_{2}^*,\\cdots,\\alpha_{N}^*)^T$ of dual problem (33) satisfies $\\alpha_{i}^*>0$\\\\\n\\includegraphics[height=5cm]{support}\n\\begin{itemize}\n  \\item If $\\alpha_{i}^*<C$, we have $\\xi=0$, support vectors $x_{i}$ is right on the margin boundary.\n  \\item If $\\alpha_{i}^*=C$\n        \\begin{itemize}\n          \\item $0<\\xi_{i}<1$, $x_{i}$ is correctly classified and between the separating hyperplane and margin boundary hyperplane.\n          \\item $\\xi_{i}=1$, $x_{i}$ is right on the separating hyperplane.\n          \\item $\\xi_{i}>1$, $x_{i}$ is wrongly classified.\n        \\end{itemize}\n\\end{itemize}\n\n\\section{Kernel methods}\n\n\\subsection{Nonlinearly separable case}\nGenerally speaking, we can't find a good linear classifier most of the time because dataset usually seems not to have a linear structure in real situation. In this section, we are trying to deal with nonlinearly separable case, which means that our dataset can be correctly classified by an $(N-1)$-dimensional hypersurface.\\\\\n\\\\\nOur main idea is to use a nonlinear mapping from input space to a feature space such that image set is approximately linearly separable in feature space. Here we give a simple example as the picture below.\\\\\n\\\\\nSuppose that input space (left picture) $\\bm\\chi\\subset \\mathbf{R^2},\\ x=(x^{(1)},x^{(2)})^T\\in \\bm\\chi$, image space $\\bm Z\\subset \\mathbf{R^2},\\ z=(z^{(1)},z^{(2)})^T\\in \\bm Z$.\\\\\nDefine a mapping $\\bm\\phi:\\bm\\chi\\rightarrow\\bm Z$ as:$$z=\\bm\\phi(x)=((x^{(1)})^2,(x^{(2)})^2)$$\n\\includegraphics[width=10cm]{feature}\\\\\nWe can see that input space (left) can be separated by an ellipse $w_{1}(x^{(1)})^2+w_{2}(x^{(2)})^2+b=0$ which becomes a straight line $w_{1}z^{(1)}+w_{2}z^{(2)}+b=0$ after mapping to feature space (right). In this way, we transfer nonlinearly separable case in input space to linearly separable case in feature space.\n\n\\subsection{Kernel function}\nWe can see from the dual problem of linear SVM that either objective function or classifier decision function is only involved with inner product between input data points. When we use linear SVM in feature space, $x_{i}\\cdot x_{j}$ is replaced by $\\bm\\phi(x_{i})\\cdot \\bm\\phi(x_{j})$, which means we only need to concern the inner products between image points in feature space.\\\\\n\n\\paragraph{\\textbf{Kernel function}} Suppose $\\bm\\chi$ is input space (subset of $\\mathbf{R^n}$ or discrete set), $\\mathscr{F}$ is feature space (Hilbert space), if there exists a mapping\n$$\\bm\\phi:\\bm\\chi\\rightarrow\\mathscr{F}$$\nsuch that for all $x,z\\in \\bm\\chi$, function $k:\\bm\\chi\\times\\bm\\chi\\rightarrow\\mathbf{R}$ satisfy:\n$$k(x,z)=\\bm\\phi(x)\\cdot\\bm\\phi(z)$$\nThen we say $k(x,z)$ is a kernel function, $\\bm\\phi$ is a feature mapping.\\\\\n\\\\\nIt's obvious that one feature mapping can only introduce one kernel function,but one kernel function may be able to be introduced by many different feature mappings. In real learning process, we only need to find proper kernel function instead of feature mapping. That's because on the one hand, the kernel function itself is enough to decide the final classifier; on the other hand, it's much easier and quicker to compute $k(x,z)$ than inner product $\\bm\\phi(x)\\cdot\\bm\\phi(z)$ in $\\mathscr{F}$ which is usually high-dimensional.\\\\\n\n\\paragraph{Gram matrix} Given a function $k:\\bm\\chi\\times\\bm\\chi\\rightarrow\\mathbf{R}$ and inputs $x_{1},\\cdots,x_{n}\\in \\bm\\chi$, the $n\\times n$ matrix\n$$K:=(k(x_{i},x_{j}))_{ij}$$ is called the Gram matrix of k with respect to $x_{1},\\cdots,x_{n}$.\n\n\\paragraph{Positive definite kernel} Let $\\bm\\chi$ be a nonempty set. A function $k:\\bm\\chi\\times\\bm\\chi\\rightarrow\\mathbf{R}$ which for all $n\\in \\mathbf{N},\\ x_{i}\\in \\bm\\chi, i=1,\\cdots,n$ gives rise to a positive definite Gram matrix is called a $positive\\ definite\\ kernel$.\n\n\\begin{theorem}\n  A function $$k:\\bm\\chi\\times\\bm\\chi\\rightarrow\\mathbf{R}$$ which is either continuous or has a finite domain, can be decomposed $$k(x,z)=\\bm\\phi(x)\\cdot\\bm\\phi(z)$$\n  into a feature map $\\bm\\phi$ into a Hilbert space $\\mathscr{F}$ applied to both its arguments followed by the evaluation of the inner product in $\\mathscr{F}$ if and only if it is a positive definite kernel.\n\\end{theorem}\n\n\\begin{proof}\n The 'only if' implication is trivial. We will mainly show the reverse implication.\\\\\n Assuming $k$ is a positive definite kernel, we'll proceed to construct a feature mapping $\\bm\\phi$ into a Hilbert space for which $k$ is the kernel.\n \\begin{enumerate}\n   \\item Define the feature mapping $\\bm\\phi$ and construct a vector space $\\bm F$.\\\\\n      We define\n      $$\\bm\\phi:x\\longmapsto k(\\bm x,\\cdot)$$\n      According to this mapping, we span the image set to a vector space\n      $$\\bm{F}=\\{\\sum_{i=1}^{l}\\alpha_{i}k(\\bm x_{i},\\cdot):l\\in\\mathbf{N},\\ \\bm x_{i}\\in\\bm\\chi,\\ \\alpha_{i}\\in\\mathbf{R},\\ i=1,\\cdots,N \\}$$\n   \\item Make $\\bm{F}$ an inner product space by defining inner product on $\\bm F$.\\\\\n      We define a binary function \"$\\bm{\\cdot}$\" on $\\bm{F}$: for any $f,g\\in \\bm F$\n      $$ f(\\cdot)=\\sum_{i=1}^{m}\\alpha_{i}k(x_{i},\\cdot) $$\n      $$ g(\\cdot)=\\sum_{j=1}^{n}\\beta_{i}k(x_{j},\\cdot) $$\n      $$ f\\bm{\\cdot} g=\\sum_{i=1}^{m}\\sum_{j=1}^{n}\\alpha_{i}\\beta_{j}k(x_{i},x_{j}) $$\n      The bilinearity and symmetry are easy to prove. Now we show that this function is positive definite.\n      $$ f\\bm\\cdot f=\\sum_{i,j=1}^{m}\\alpha_{i}\\alpha_{j}k(x_{i},x_{j})=\\alpha^T k\\alpha $$\n      Because the matrix K is positive semi-definite, we have $$f\\bm\\cdot f\\geqslant 0,\\ \\forall\\ f\\in \\bm{F}$$\\\\\n      Utilizing this result, we can prove the Cauchy-Schwarz inequality\n      \\begin{equation}\n        (f\\bm\\cdot g)^2\\leqslant(f\\bm\\cdot f)(g\\bm\\cdot g)\n      \\end{equation}\n      Notice that\n      \\begin{equation}\n        f\\bm\\cdot k(x,\\cdot)=\\sum_{i=1}^{m}\\alpha_{i}k(x_{i},x)=f(x)\n      \\end{equation}\n      Take $g(\\cdot)=K(x,\\cdot)$ into (45), we have\n      $$ (f\\bm\\cdot k(x,\\cdot))^2=|f(x)|^2\\leqslant(f\\bm\\cdot f)k(x,x) $$\n      So while $f\\bm\\cdot f=0$, we have $f(x)\\equiv 0$.\n      Above all, binary function \"$\\bm\\cdot$\" satisfies bilinearity, symmetry and positive definiteness which means \"$\\bm\\cdot$\" is an inner product on $\\bm{F}$. Now vector space $\\bm{F}$ with inner product \"$\\bm\\cdot$\" is an inner product space.\n   \\item Complete the inner product space $\\bm{F}$, we can get a Hilbert space $\\mathscr{F}$.\\\\\n      This Hilbert space is called $\\textbf{reproducing\\ kernel\\ Hilbert\\ space\\ (RKHS)}$ because it satisfies equation (46) which is called $reproducing\\ property$.\n \\end{enumerate}\n\\end{proof}\n\\noindent\\\\\nBack to SVM problem. When we choose a kernel function $K$, the objective function of dual problem turns out to be:\n$$ W(\\bm\\alpha)=\\frac{1}{2}\\sum_{i=1}^{N}\\sum_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}-\\sum_{i=1}^{N}\\alpha_{i} $$\nThe decision function changes into:\n$$ f(x)=sign(\\ \\sum_{i=1}^{N}\\alpha_{i}^*y_{i}K(x_{i},x)+b^*\\ ) $$\n\n\\subsection{Common kernel functions}\n\\begin{itemize}\n  \\item \\textbf{Polynomial kernel function}:\n        \\begin{equation}\n          K(\\bm x,\\bm z)=(\\bm x\\cdot \\bm z+1)^{p}\n        \\end{equation}\n  \\item \\textbf{Gaussian kernel function}\n        \\begin{equation}\n          K(\\bm x,\\bm z)=exp(-\\frac{\\|\\bm x-\\bm z\\|^2}{2\\sigma^2})\n        \\end{equation}\n  \\item \\textbf{sigmoid kernel function}\n        \\begin{equation}\n          K(\\bm x,\\bm z)=tanh(\\bm x\\cdot \\bm z+r)\n        \\end{equation}\n\\end{itemize}\n\n\n\n%\\end{document}\n", "meta": {"hexsha": "e89c803d5009a84fd788a24012cd903d7ee0df87", "size": 27934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/SVM.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/SVM.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/SVM.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.8008849558, "max_line_length": 533, "alphanum_fraction": 0.6727285745, "num_tokens": 9879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.695243125479671}}
{"text": "\\section{Complex Tori; the Open Mapping Theorem}\r\n\\subsection{Complex Tori}\r\nSo far, we only know one compact Riemann surface, namely the Riemann sphere $\\mathbb C_\\infty$.\r\nOne can also picture a torus being compact and can admit a conformal structure.\r\nWe shall formalise such constructions.\\\\\r\nLet $\\tau_1,\\tau_2\\in\\mathbb C_\\star$ such that they are linearly independent over $\\mathbb R$.\r\nLet $\\Lambda$ be the additive subgroup generated by $\\tau_1,\\tau_2$ which is a lattice.\r\nWe then define the torus as the quotient group $T=\\mathbb C/\\Lambda$ that inherits the quotient topology.\r\nWe can study this topology via the fundamental parallelogram $P$ with vertices $0,\\tau_1,\\tau_2,\\tau_1+\\tau_2$.\r\nWith a little geometrical intuition we are hinted that $T\\cong S^1\\times S^1$ since we are just gluing the sides of the fundamental parallelogram as topological spaces which is easy enough to check.\r\nConsequently it is compact.\\\\\r\nNow the quotient map $\\pi:\\mathbb C\\to T=\\mathbb C/\\Lambda$ is a regular covering map.\r\nTo prove this, take $0<\\epsilon<\\min\\{|\\lambda|:\\lambda\\in\\Lambda\\setminus\\{0\\}\\}/2$ which one can verify is well-defined.\r\nThen\r\n$$\\pi^{-1}(\\pi(D(z_0,\\epsilon)))=\\bigcup_{\\lambda\\in\\Lambda}(D(z_0,\\epsilon)+\\lambda)=\\coprod_{\\lambda\\in\\Lambda}(D(z_0,\\epsilon)+\\lambda)\\cong D(z_0,\\epsilon)\\times\\Lambda$$\r\nby our definition of $\\epsilon$.\r\nHere $\\Lambda$ has the discrete topology it inherited as a subspace of $\\mathbb C$.\r\nSo $\\pi$ is indeed a regular covering map.\r\nNow, we use $\\pi$ to construct an atlas on $T$.\r\nFor $p=z_0+\\Lambda\\in T$, let $U=\\pi(D(z_0,\\epsilon))$ for $\\epsilon>0$ as before and $(\\phi,U)$ is a chart where $\\phi=(\\pi|_{D(z_0,\\epsilon)})^{-1}$.\r\nThis works since $\\pi$ is a regular covering map.\r\nNow for any other chart constructed in this way, i.e. $(\\psi,V)=((\\pi|_{D(z_1,\\epsilon)})^{-1},\\pi(D(z_1,\\epsilon)))$, then $U\\cap V$ is nonempty iff there is some $\\lambda\\in\\Lambda$ (necessarily unique because of the bound on $\\epsilon$) such that $|z_0-(z_1+\\lambda)|<2\\epsilon$.\r\nIn this case, the transition function is just $z\\mapsto z+\\lambda$ which is analytic.\r\nSo this is indeed an atlas.\r\nThis extends to a conformal structure on $T$ that makes it a Riemann surface.\r\nIt is easy to see that all of these tori are homeomorphic as they are all homeomorphic to $S^1\\times S^1$.\r\nBut (as will be proven in example sheets) there are infinitely many conformal equivalence classes among these tori.", "meta": {"hexsha": "8a557063bbc871b4b56693fcdccf7a7b1fb04398", "size": 2446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/tori.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/tori.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/tori.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": 90.5925925926, "max_line_length": 283, "alphanum_fraction": 0.7293540474, "num_tokens": 720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.6952431066999492}}
{"text": "\\hypertarget{linear-regression}{%\n\\chapter{Linear Regression}\\label{linear-regression}}\n\n\\section{Introduction}\nLinear regression is a linear approach for modelling the relationship\nbetween a dependent and independent variable. Linear regression uses\nrepresentation in a linear equation that combines a specific set of\ninput values (x) the solution to which is the predicted output for that\nset of input values (y). As such, both the input values (x) and the\noutput value are numeric. The linear equation assigns one scale factor\nto each input value or column, called a coefficient and one additional\ncoefficient is also added, giving the line an additional degree of\nfreedom for moving up and down on a two-dimensional plot and is often\ncalled the intercept or the bias coefficient. \\[\n\\Large\\hat{y} = \\beta_0 + \\beta_1 x\n\\]\n\n\\hypertarget{linear-regression-calculation}{%\n\\section{Steps for Calculation}\\label{linear-regression-calculation}}\n\nStep 1: Calculate mean of \\(x\\) and \\(y\\) represented as \\(x’\\) and\n\\(y’\\).\n\nStep 2: Calculate deviation from mean for \\(x\\) and \\(y\\) with\n\\((x-x’)\\) and \\((y-y’)\\).\n\nStep 3: Square the deviation as \\((x-x’)^2\\).\n\nStep 4: Calculate \\((x-x’)(y-y’)\\).\n\nStep 5: $\\beta_0 = \\displaystyle \\frac{\\sum ((x-x’)(y-y’))}{\\sum (x-x’)^2}$\n\nStep 6: $\\beta_1 = y' - c * x'$\n\nStep 7: \\(\\hat{y} = \\beta_0 + \\beta_1 x\\)\n\nwhere, \\(\\hat{y}\\) = dependent, \\(\\beta_0\\) = intersection, \\(\\beta_1\\)\ntangent, \\(x\\) = independent\n\\section{Implementation from scratch}\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}{from} \\PY{n+nn}{matplotlib} \\PY{k+kn}{import} \\PY{n}{pyplot} \\PY{k}{as} \\PY{n}{plt}\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{k}{def} \\PY{n+nf}{coeff}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y}\\PY{p}{)}\\PY{p}{:}\n    \\PY{n}{n} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{size}\\PY{p}{(}\\PY{n}{x}\\PY{p}{)}\n    \n    \\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Number of datapoints:}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{n}\\PY{p}{)}\n    \n    \\PY{n}{mean\\PYZus{}x} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{mean}\\PY{p}{(}\\PY{n}{x}\\PY{p}{)}\n    \\PY{n}{mean\\PYZus{}y} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{mean}\\PY{p}{(}\\PY{n}{y}\\PY{p}{)}\n    \n    \\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Means (x, y): }\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{p}{(}\\PY{n}{mean\\PYZus{}x}\\PY{p}{,} \\PY{n}{mean\\PYZus{}y}\\PY{p}{)}\\PY{p}{)}\n    \n    \\PY{c+c1}{\\PYZsh{} cross deviation calculation}\n    \\PY{n}{s\\PYZus{}xy} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{sum}\\PY{p}{(}\\PY{n}{y} \\PY{o}{*} \\PY{n}{x}\\PY{p}{)} \\PY{o}{\\PYZhy{}} \\PY{n}{n} \\PY{o}{*} \\PY{n}{mean\\PYZus{}y} \\PY{o}{*} \\PY{n}{mean\\PYZus{}x}\\PY{p}{;}\n    \\PY{n}{s\\PYZus{}xx} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{sum}\\PY{p}{(}\\PY{n}{x} \\PY{o}{*} \\PY{n}{x}\\PY{p}{)} \\PY{o}{\\PYZhy{}} \\PY{n}{n} \\PY{o}{*} \\PY{n}{mean\\PYZus{}x} \\PY{o}{*} \\PY{n}{mean\\PYZus{}x}\\PY{p}{;}\n    \n    \\PY{n}{b1} \\PY{o}{=} \\PY{n}{s\\PYZus{}xy}\\PY{o}{/}\\PY{n}{s\\PYZus{}xx}\n    \\PY{n}{b0} \\PY{o}{=} \\PY{n}{mean\\PYZus{}y} \\PY{o}{\\PYZhy{}} \\PY{n}{b1} \\PY{o}{*} \\PY{n}{mean\\PYZus{}x}\n    \n    \\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Found b0 and b1: }\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{b0}\\PY{p}{,} \\PY{n}{b1}\\PY{p}{)}\n    \\PY{k}{return} \\PY{p}{(}\\PY{n}{b0}\\PY{p}{,} \\PY{n}{b1}\\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} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{array}\\PY{p}{(}\\PY{p}{[}\\PY{l+m+mi}{1}\\PY{p}{,} \\PY{l+m+mi}{3}\\PY{p}{,} \\PY{l+m+mi}{4}\\PY{p}{,} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{6}\\PY{p}{,} \\PY{l+m+mi}{8}\\PY{p}{,} \\PY{l+m+mi}{9}\\PY{p}{]}\\PY{p}{)}\n\\PY{n}{y} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{array}\\PY{p}{(}\\PY{p}{[}\\PY{l+m+mi}{2}\\PY{p}{,} \\PY{l+m+mi}{4}\\PY{p}{,} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{6}\\PY{p}{,} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{7}\\PY{p}{,} \\PY{l+m+mi}{8}\\PY{p}{]}\\PY{p}{)}\n\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{figure}\\PY{p}{(}\\PY{n}{dpi}\\PY{o}{=}\\PY{l+m+mi}{80}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Datapoints}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{xlabel}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\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}{y}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{legend}\\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}{3}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n<matplotlib.legend.Legend at 0x1b7faf83bb0>\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{center}\n    \\adjustimage{max size={0.9\\linewidth}{0.9\\paperheight}}{./figures/LR1.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}{4}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{b} \\PY{o}{=} \\PY{n}{coeff}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\nNumber of datapoints: 7\nMeans (x, y):  (5.142857142857143, 5.285714285714286)\nFound b0 and b1:  1.8048780487804876 0.6768292682926829\n    \\end{Verbatim}\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}{y\\PYZus{}pred} \\PY{o}{=} \\PY{n}{b}\\PY{p}{[}\\PY{l+m+mi}{0}\\PY{p}{]} \\PY{o}{+} \\PY{n}{b}\\PY{p}{[}\\PY{l+m+mi}{1}\\PY{p}{]} \\PY{o}{*} \\PY{n}{x}\n\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{figure}\\PY{p}{(}\\PY{n}{dpi}\\PY{o}{=}\\PY{l+m+mi}{80}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y}\\PY{p}{,} \\PY{n}{marker}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{X}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Datapoints}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{plot}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y\\PYZus{}pred}\\PY{p}{,} \\PY{n}{color}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{red}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Regression Line}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{xlabel}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\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}{y}\\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/LR2.png}\n    \\end{center}\n    { \\hspace*{\\fill} \\\\}\n    \n    \\hypertarget{linear-regression-using-scikit-learn}{%\n\\section{Implementation using scikit-learn}\\label{linear-regression-using-scikit-learn}}\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{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}{import} \\PY{n+nn}{seaborn} \\PY{k}{as} \\PY{n+nn}{sns}\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}{sklearn} \\PY{k+kn}{import} \\PY{n}{preprocessing}\\PY{p}{,} \\PY{n}{svm}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{linear\\PYZus{}model} \\PY{k+kn}{import} \\PY{n}{LinearRegression}\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}{x} \\PY{o}{=} \\PY{n}{pd}\\PY{o}{.}\\PY{n}{DataFrame}\\PY{p}{(}\\PY{p}{[}\\PY{l+m+mi}{1}\\PY{p}{,} \\PY{l+m+mi}{3}\\PY{p}{,} \\PY{l+m+mi}{4}\\PY{p}{,} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{6}\\PY{p}{,} \\PY{l+m+mi}{8}\\PY{p}{,} \\PY{l+m+mi}{9}\\PY{p}{]}\\PY{p}{)}\n\\PY{n}{y} \\PY{o}{=} \\PY{n}{pd}\\PY{o}{.}\\PY{n}{DataFrame}\\PY{p}{(}\\PY{p}{[}\\PY{l+m+mi}{2}\\PY{p}{,} \\PY{l+m+mi}{4}\\PY{p}{,} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{6}\\PY{p}{,} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{7}\\PY{p}{,} \\PY{l+m+mi}{8}\\PY{p}{]}\\PY{p}{)}\n\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{figure}\\PY{p}{(}\\PY{n}{dpi}\\PY{o}{=}\\PY{l+m+mi}{80}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Datapoints}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{xlabel}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\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}{y}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{legend}\\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=\\\\\\{\\}]\n<matplotlib.legend.Legend at 0x1b7817b93d0>\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{center}\n    \\adjustimage{max size={0.9\\linewidth}{0.9\\paperheight}}{./figures/LR3.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}{8}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{regr} \\PY{o}{=} \\PY{n}{LinearRegression}\\PY{p}{(}\\PY{p}{)}\n\\PY{n}{regr}\\PY{o}{.}\\PY{n}{fit}\\PY{p}{(}\\PY{n}{x}\\PY{p}{,} \\PY{n}{y}\\PY{p}{)}\n\\PY{n}{y\\PYZus{}pred} \\PY{o}{=} \\PY{n}{regr}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{n}{x}\\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}{9}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{figure}\\PY{p}{(}\\PY{n}{dpi}\\PY{o}{=}\\PY{l+m+mi}{80}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n}{x}\\PY{o}{.}\\PY{n}{values}\\PY{p}{,} \\PY{n}{y}\\PY{o}{.}\\PY{n}{values}\\PY{p}{,} \\PY{n}{marker}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{X}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Datapoints}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{plot}\\PY{p}{(}\\PY{n}{x}\\PY{o}{.}\\PY{n}{values}\\PY{p}{,} \\PY{n}{y\\PYZus{}pred}\\PY{p}{,} \\PY{n}{color}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{red}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Regression Line}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{xlabel}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\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}{y}\\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/LR4.png}\n    \\end{center}", "meta": {"hexsha": "d5ee7bdf8469f1eeae1718ff0953a13fdae13749", "size": 11714, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MCA/Machine Learning/Project file/Tex source/Linear Regression.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/Linear Regression.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/Linear Regression.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": 59.461928934, "max_line_length": 313, "alphanum_fraction": 0.573074953, "num_tokens": 5274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.6952029576245898}}
{"text": "\\documentclass[a4paper]{article}\n\n%% Language and font encodings\n\\usepackage{fontspec}\n\n%% Sets page size and margins\n\\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}\n\n%% Useful packages\n\\usepackage{amsmath,amsthm,amssymb,amsfonts}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\n\\usepackage{listings}\n\n\\usepackage{xcolor}\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\n\\lstdefinestyle{mystyle}{\n    backgroundcolor=\\color{backcolour},   \n    commentstyle=\\color{codegreen},\n    keywordstyle=\\color{magenta},\n    numberstyle=\\tiny\\color{codegray},\n    stringstyle=\\color{codepurple},\n    basicstyle=\\ttfamily\\footnotesize,\n    breakatwhitespace=false,         \n    breaklines=true,                 \n    captionpos=b,                    \n    keepspaces=true,                 \n    numbers=left,                    \n    numbersep=5pt,                  \n    showspaces=false,                \n    showstringspaces=false,\n    showtabs=false,                  \n    tabsize=2\n}\n\n\\lstset{style=mystyle}\n\n\\title{Convolutional Neural Networks Assignment}\n\n\\author{Ahmad Salimi \\\\ AI-Med}\n\n\\usepackage{mathtools}\n\\DeclarePairedDelimiter\\ceil{\\lceil}{\\rceil}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\n\\begin{document}\n\\maketitle\n\n%\\begin{abstract}\n%Your abstract.\n%\\end{abstract}\n\n\\section{A convolutional layer with $W \\times H$ inputs, $K_1 \\times K_2$ kernels, $C_{in}$ input channels, $C_{out}$ output channels, padding $P$ and stride $S$}\n\n\\begin{enumerate}\n    \\item Number of input elements: \n        $$W \\times H \\times C_{in}$$\n    \\item Output width:\n        $$W_{out} = \\floor{\\frac{W + 2P - K_1}{S}} + 1$$\n        Output Height:\n        $$H_{out} = \\floor{\\frac{H + 2P - K_2}{S}} + 1$$\n        Number of output channels:\n        $$C_{out}$$\n    \\item Number of parameters:\n        $$|\\theta| = (K_1 \\times K_2 \\times C_{in} + 1) \\times C_{out}$$\n    \\item Number of multiplication:\n        $$K_1 \\times K_2 \\times W_{out} \\times H_{out} \\times C_{out}$$\n\\end{enumerate}\n\n\n\\section{A pooling layer with $K \\times K$ kernels, stride $S_2$ and padding $P_2$}\n\n\\begin{enumerate}\n    \\item Number of input elements: \n        $$W \\times H \\times C_{in}$$\n    \\item Output width:\n        $$W_{out} = \\floor{\\frac{W + 2P_2 - K}{S_2}} + 1$$\n        Output Height:\n        $$H_{out} = \\floor{\\frac{H + 2P_2 - K}{S_2}} + 1$$\n        Number of output channels:\n        $$C_{in}$$\n    \\item Number of parameters:\n        $$0$$\n    \\item Number of multiplication:\n        $$0$$\n\\end{enumerate}\n\n\n\\section{A fully connected layer with $N$ neurons}\n\n\\begin{enumerate}\n    \\item Number of input elements: \n        $$W \\times H \\times C_{in}$$\n    \\item Output size:\n        $$N$$\n    \\item Number of parameters:\n        $$|\\theta| = (W \\times H \\times C_{in} + 1) \\times N$$\n    \\item Number of multiplication:\n        $$W \\times H \\times C_{in} \\times N$$\n\\end{enumerate}\n\n\\section{Parameters placement}\n$W = H = 256$ \\\\\n$K_1 = K_2 = 3$ \\\\\n$P = 1$ \\\\\n$S = 1$ \\\\\n$C_{in} = 64$ \\\\\n$C_{out} = 128$ \\\\\n$K = 2$ \\\\\n$S_2 = 2$ \\\\\n$P_2 = 0$ \\\\\n$N = 1000$ \\\\\n\n\\begin{enumerate}\n    \\item Convolutional layer:\n        \\begin{enumerate}\n            \\item Number of parameters:\n            $$|\\theta| = (K_1 \\times K_2 \\times C_{in} + 1) \\times C_{out} = (3 \\times 3 \\times 64 + 1) \\times 128 = 73,856$$\n            \\item Number of multiplications:\n            $$K_1 \\times K_2 \\times W_{out} \\times H_{out} \\times C_{out} = 3 \\times 3 \\times (\\frac{256 + 2 - 3}{1} + 1) \\times (\\frac{256 + 2 - 3}{1} + 1) \\times 128 = 74,908,800$$\n            \\item Output size:\n            $$\\floor{\\frac{W + 2P - K_1}{S}} + 1 = \\floor{\\frac{H + 2P - K_2}{S}} + 1 = \\frac{256 + 2 - 3}{1} + 1 = 256$$\n        \\end{enumerate}\n    \\item Pooling layer:\n        \\begin{enumerate}\n            \\item Number of parameters:\n            $$0$$\n            \\item Number of multiplications:\n            $$0$$\n            \\item Output size:\n            $$\\floor{\\frac{W + 2P_2 - K}{S_2}} + 1 = \\floor{\\frac{H + 2P_2 - K}{S_2}} + 1 = \\frac{256 + 0 - 2}{2} + 1 = 128$$\n        \\end{enumerate}\n    \\item Fully connected layer:\n        \\begin{enumerate}\n            \\item Number of parameters:\n            $$|\\theta| = (W \\times H \\times C_{in} + 1) \\times N = (256 \\times 256 \\times 64 + 1) \\times 1000 = 4,194,305,000$$\n            \\item Number of multiplications:\n            $$W \\times H \\times C_{in} \\times N = 256 \\times 256 \\times 64 \\times 1000 = 4,194,304,000$$\n            \\item Output size:\n            $$N = 1000$$\n        \\end{enumerate}\n\\end{enumerate}\n\n\\section{Network bottleneck}\n\n\\begin{lstlisting}[language=Python]\n            Layers              |     Shape     |     Size\n---------------------------------------------------------------\nInput: 256 x 256                # B 1   256 256 = B * 65536\n[64] Conv 3 x 3, s=1, p=1       # B 64  256 256 = B * 4194304\n[64] Conv 3 x 3, s=1, p=1       # B 64  256 256 = B * 4194304\nPool 2 x 2, s=2, p=0            # B 64  128 128 = B * 1048576\n[128] Conv 3 x 3, s=1, p=1      # B 128 128 128 = B * 2097152\n[128] Conv 3 x 3, s=1, p=1      # B 128 128 128 = B * 2097152\nPool 2 x 2, s=2, p=0            # B 128 64  64  = B * 524288\n[256] Conv 3 x 3, s=1, p=1      # B 256 64  64  = B * 1048576\n[256] Conv 3 x 3, s=1, p=1      # B 256 64  64  = B * 1048576\nPool 2 x 2, s=2, p=0            # B 256 32  32  = B * 262144\n[512] Conv 3 x 3, s=1, p=1      # B 512 32  32  = B * 524288\n[512] Conv 3 x 3, s=1, p=1      # B 512 32  32  = B * 524288\nPool 2 x 2, s=2, p=0            # B 512 16  16  = B * 131072\n[512] Conv 3 x 3, s=1, p=1      # B 512 16  16  = B * 131072\n[512] Conv 3 x 3, s=1, p=1      # B 512 16  16  = B * 131072\nPool 2 x 2, s=2, p=0            # B 512 8   8   = B * 32768\nFlatten                         # B 32768       = B * 32768\nFC (4096)                       # B 4096        = B * 4096\nFC (4096)                       # B 4096        = B * 4096\nFC (2)                          # B 2           = B * 2\n\\end{lstlisting}\n\nIt turns out that the largest size is $B \\times 4194304$. So, if we assume each number to be \\lstinline{float32}, the size of the largest possible batch will be as follows:\n$$\nB =  \\floor{\\frac{12 GB}{4194304 \\times 4B}} = \\floor{\\frac{12 \\times 2^{30}}{2^{24}}} = 12 \\times 2^6 = 768\n$$\n\n\n\\section{Receptive Field}\n\nFor each convolutional and pooling layer with kernel size $K$, stride $S$ and padding $P$, the $(i, j)$ neuron of $n^{th}$ layer, represents the following range of $n-1^{th}$ layer:\n$$(Si - P:Si - P + K - 1, \\space Sj - P:Sj - P + K - 1)$$\n\n\\begin{lstlisting}[language=Python]\n    [  i   :   i   ,   j   :   j   ]\nConv[  i-1 :   i+1 ,   j-1 :   j+1 ]\nConv[  i-2 :   i+2 ,   j-2 :   j+2 ]\nPool[ 2i-4 :  2i+5 ,  2j-4 :  2j+5 ]\nConv[ 2i-5 :  2i+6 ,  2j-5 :  2j+6 ]\nConv[ 2i-4 :  2i+7 ,  2j-4 :  2j+7 ]\nPool[ 4i-8 :  4i+15,  4j-8 :  4j+15]\nConv[ 4i-9 :  4i+16,  4j-9 :  4j+16]\nConv[ 4i-10:  4i+17,  4j-10:  4j+17]\nPool[ 8i-20:  8i+35,  8j-20:  8j+35]\nConv[ 8i-21:  8i+36,  8j-21:  8j+36]\nConv[ 8i-22:  8i+37,  8j-22:  8j+37]\nPool[16i-44: 16i+75, 16j-44: 16j+75]\nConv[16i-45: 16i+76, 16j-45: 16j+76]\nConv[16i-46: 16i+77, 16j-46: 16j+77]\n\\end{lstlisting}\n\nSo, the $(i, j)$ neuron of last convolutional layer, represents the following range of the input image:\n\n$$(16i - 44:16i + 75, \\space 16j - 44:16j + 75)$$\n\n\n\\end{document}", "meta": {"hexsha": "2e4e87a0e061849583bb4928ee0dadcd05b2507f", "size": 7510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CNN/Assignment/Assignment.tex", "max_stars_repo_name": "ahmadsalimi/DataAnalysisInternship", "max_stars_repo_head_hexsha": "4527af83b3db51b27a52293246373f242af90fc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CNN/Assignment/Assignment.tex", "max_issues_repo_name": "ahmadsalimi/DataAnalysisInternship", "max_issues_repo_head_hexsha": "4527af83b3db51b27a52293246373f242af90fc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CNN/Assignment/Assignment.tex", "max_forks_repo_name": "ahmadsalimi/DataAnalysisInternship", "max_forks_repo_head_hexsha": "4527af83b3db51b27a52293246373f242af90fc9", "max_forks_repo_licenses": ["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.5924170616, "max_line_length": 182, "alphanum_fraction": 0.5495339547, "num_tokens": 2898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6952029536979663}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Improper Integrals}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to improper integrals.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}%[APEX0607IMPRP07]\nEvaluate the improper integral: \\(\\displaystyle \\int_0^\\infty e^{5-2x}\\ dx = \\answer{(e^5)/2}.\\)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0607IMPRP10]\nEvaluate the given improper integral: \\(\\displaystyle \\int_{-\\infty}^\\infty \\frac{1}{x^2+9}\\ dx = \\answer{\\pi/3}.\\)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}\nEvaluate the integral: \\[ \\int_0^1 \\frac{e^{\\sqrt{x}}}{\\sqrt{x}} \\ dx = \\answer{2(e-1)}. \\]\nThis integral is \\wordChoice{\\choice{not improper}\\choice[correct]{improper}} because of the behavior of the integrand near $x = 0$.\n\\end{exercise}\n\n\\begin{exercise}%[APEX0607IMPRP14]\nEvaluate the given improper integral. \\(\\displaystyle \\int_{3}^\\infty\\frac{1}{x^2-4}\\ dx = \\answer{\\frac{\\ln 5}{4}}.\\)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0607IMPRP35]\nUse the Direct Comparison Test or the Limit Comparison Test to determine whether the integral converges or diverges:\n \\(\\displaystyle \\int_{10}^\\infty \\frac{3}{\\sqrt{3x^2+2x-5}} \\ dx.\\)\n Answer: the integral \n \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} by \\wordChoice{\\choice{direct}\\choice[correct]{limit}} comparison with the function $\\displaystyle \\frac{1}{x^{\\answer{1}}}.$\n%\n%\n\\end{exercise}\n\n\\begin{exercise}\nUse the Direct Comparison Test or the Limit Comparison Test to determine whether the integral converges or diverges:\n \\(\\displaystyle \\int_{2}^\\infty \\frac{2}{\\sqrt{7x^3-x}} \\ dx.\\)\n Answer: the integral \n \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} by \\wordChoice{\\choice{direct}\\choice[correct]{limit}} comparison with the function $\\displaystyle \\frac{1}{x^{\\answer{3/2}}}$ (select the largest exponent for the denominator which makes the statement true).\n\\end{exercise}\n\n\n\\begin{exercise}\nUse the Direct Comparison Test or the Limit Comparison Test to determine whether the integral converges or diverges:\n \\(\\displaystyle \\int_{1}^\\infty e^{-x} \\ln x \\ dx.\\)\n Answer: the integral \n \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} by direct comparison with the function \n \\begin{multipleChoice}\n \\choice{$e^{-x}$}\n \\choice[correct]{$x e^{-x}$}\n \\choice{$e^{-x}/x$}\n \\end{multipleChoice}\n\\end{exercise}\n\n\\begin{exercise}\nUse the Direct Comparison Test or the Limit Comparison Test to determine whether the integral converges or diverges:\n \\(\\displaystyle \\int_{1}^\\infty e^{-x^2 + 3x + 1} \\ dx.\\)\n Answer: the integral \n \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} by direct comparison with the function \n \\begin{multipleChoice}\n \\choice{$e^{-x^2}$}\n \\choice[correct]{$e^{-x}$}\n \\choice{$e^{3x+1}$}\n \\end{multipleChoice}\n\\end{exercise}\n\n\\begin{exercise}\nUse the Direct Comparison Test or the Limit Comparison Test to determine whether the integral converges or diverges:\n \\(\\displaystyle \\int_{1}^\\infty \\frac{x}{x^2+\\cos x} \\ dx.\\)\n Answer: the integral \n \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} by \\wordChoice{\\choice{direct}\\choice[correct]{limit}} comparison with the function \n \\begin{multipleChoice}\n \\choice[correct]{$1/x$}\n \\choice{$x/\\cos x$}\n \\choice{$1/(x^2+\\cos x)$}\n \\end{multipleChoice}\n\\end{exercise}\n\n\n\\begin{exercise}\nUse the Direct or Limit Comparison Test to determine whether the integral converges or diverges:\n\\[ \\int_0^{1/e} \\frac{(\\ln x)^2-1}{x^3 + x^2 + x} dx \\]\nAnswer: The integral \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} by \\wordChoice{\\choice{direct}\\choice[correct]{limit}} comparison with the function \n\\begin{multipleChoice}\n\\choice{$\\displaystyle \\frac{(\\ln x)^2}{x^3}$}\n\\choice{$\\displaystyle \\frac{(\\ln x)^2}{x^2}$}\n\\choice[correct]{$\\displaystyle \\frac{(\\ln x)^2}{x}$}\n\\choice{$\\displaystyle \\frac{1}{x^3}$}\n\\choice{$\\displaystyle \\frac{1}{x^2}$}\n\\end{multipleChoice}\n\\end{exercise}\n\n\\begin{exercise}\nUse the Direct or Limit Comparison Test to determine whether the integral converges or diverges:\n\\[ \\int_0^{1/e} \\frac{(\\ln x)^2-1}{x + \\sqrt{x} + e^{-1/x}} dx \\]\nAnswer: The integral \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} by direct comparison with the function \n\\begin{multipleChoice}\n\\choice{$\\displaystyle \\frac{(\\ln x)^2}{x}$}\n\\choice[correct]{$\\displaystyle \\frac{(\\ln x)^2}{\\sqrt{x}}$}\n\\choice{$\\displaystyle \\frac{(\\ln x)^2}{e^{-1/x}}$}\n\\choice{$\\displaystyle \\frac{1}{x}$}\n\\choice{$\\displaystyle \\frac{1}{\\sqrt{x}}$}\n\\choice{$\\displaystyle \\frac{1}{e^{-1/x}}$}\n\\end{multipleChoice}\n\\end{exercise}\n\n\n\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[ImpropCD01]\n\nWhich of the following improper integrals is convergent? \\offline{Show how you used comparison tests to justify your answer.}\n\\[ \\mathrm{I}: \\ \\int_0^1\\frac{\\sqrt{{1}+{x^2}{e^{-x}}}}{{(\\cos x)}{x^2}}~dx \\qquad   \\mathrm{II}: \\ \\int_{2}^\\infty\\frac{{e^{x}}}{{x}{e^{x}}+{x^2}}~dx \\qquad  \\mathrm{III}: \\ \\int_{2}^\\infty\\frac{{x^2}}{{x^4}+{1}}~dx\\]\n\\begin{multiplechoice}\n\\choice{only \\(\\mathrm{I}\\) converges}\n\\choice{only \\(\\mathrm{II}\\) converges}\n\\choice[correct]{only \\(\\mathrm{III}\\) converges} \n\\choice{\\(\\mathrm{I}\\) and \\(\\mathrm{II}\\) converge}\n\\choice{\\(\\mathrm{II}\\) and \\(\\mathrm{III}\\) converge}\n\\choice{\\(\\mathrm{I}\\) and \\(\\mathrm{III}\\) converge}\n\\end{multiplechoice}\n\\begin{feedback}\nIntegral \\(\\mathrm{I}\\) is divergent by direct comparison to the function \\(\\displaystyle \\frac{{1}}{{x^2}}\\). \nIntegral \\(\\mathrm{II}\\) is divergent by limit comparison to the function \\(\\displaystyle \\frac{{1}}{{x}}\\). \nIntegral \\(\\mathrm{III}\\) is convergent by direct comparison to the function \\(\\displaystyle \\frac{{1}}{{x^2}}\\).\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[ImpropCD08]\n\nWhich of the following improper integrals is convergent? \\offline{Show how you used comparison tests to justify your answer.}\n\\[ \\mathrm{I}: \\ \\int_0^1\\frac{\\sqrt{{e^{2x}}+{x^3}}}{{x}}~dx \\qquad   \\mathrm{II}: \\ \\int_0^1\\frac{{x^2}}{{x^2}{\\sqrt{x}}+{x^3}}~dx \\qquad  \\mathrm{III}: \\ \\int_{2}^\\infty\\frac{{x^2}{\\ln x}}{-{x}+{x^4}}~dx\\]\n\\begin{multiplechoice}\n\\choice{only \\(\\mathrm{I}\\) converges}\n\\choice{only \\(\\mathrm{II}\\) converges}\n\\choice{only \\(\\mathrm{III}\\) converges} \n\\choice{\\(\\mathrm{I}\\) and \\(\\mathrm{II}\\) converge}\n\\choice[correct]{\\(\\mathrm{II}\\) and \\(\\mathrm{III}\\) converge}\n\\choice{\\(\\mathrm{I}\\) and \\(\\mathrm{III}\\) converge}\n\\end{multiplechoice}\n\\begin{feedback}\nIntegral \\(\\mathrm{I}\\) is divergent by direct comparison to the function \\(\\displaystyle \\frac{{1}}{{x}}\\). \nIntegral \\(\\mathrm{II}\\) is convergent by direct comparison to the function \\(\\displaystyle \\frac{{1}}{{\\sqrt{x}}}\\). \nIntegral \\(\\mathrm{III}\\) is convergent by limit comparison to the function \\(\\displaystyle \\frac{{\\ln x}}{{x^2}}\\).\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2016C.06]\n\nOnly one of the following four improper integrals diverges. Choose that improper integral\\offline{ and justify why it diverges}. \\offline{(You need NOT justify why the other integrals converge.)}\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\int^{\\infty}_{2} \\frac{\\arctan x}{1+x^3} dx\\)}\n\\choice{\\(\\displaystyle \\int^{\\infty}_{2} \\frac{1}{\\sqrt{x^4+x^2}} dx\\)}\n\\choice{\\(\\displaystyle \\int^{\\infty}_{2} \\frac{1+\\sin x}{x^2} dx\\)}\n\\choice[correct]{\\(\\displaystyle \\int_{2}^{\\infty} \\frac{1}{\\sqrt[3]{x^2-1}} dx\\)}\n\\end{multiplechoice}\n\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "c9c6f2bbb79981b321d38e7ea3396e1125c96cc9", "size": 7465, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "applications/16improperpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/16improperpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/16improperpractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.9382022472, "max_line_length": 267, "alphanum_fraction": 0.6931011386, "num_tokens": 2427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6952029517346543}}
{"text": "\n\n\n\\section{Far-Field Green's Function and Plane Wave Expansion}\n\nThe core for the fast multipole method lies in the plane wave expansion of the kernel of the scalar Green's function.  This is derived and explained in excellent detail in \\cite{yucel2008helmholtz}. We summarized the main points here.\n\n\\paragraph{Far-Field Green's Function}\n\nRecall that the electric field dyadic Green's function is given by\n\\begin{equation}\n \\overline{\\bb{G}}(\\br,\\br') = \\left[\\overline{\\bb{I}} + \\dfrac{1}{k^2} \\nabla\\nabla \\right] g(\\br,\\br') \n \\end{equation}\n \n\\noindent where the scalar Green's function is \n \\eq{ g(\\br,\\br') =  \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi \\vert \\br - \\br' \\vert} \\label{fmmscagreen}}\n\n\\noindent and that the far-field dyadic Green's function is\n\\begin{equation}\n \\overline{\\bb{G}}_f(\\br,\\br') \\approx \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] g(\\br,\\br') \n \\end{equation}\n \n \\noindent where in using \\eqref{fmmscagreen} we have not approximated the phase term. \n\n\n\\paragraph{Plane Wave Expansion}\n\nThe derivation is based on two expansions. The first an expansion of the kernel of the scalar Green's function, \\cite{yucel2008helmholtz}, \n\\ea{\\dfrac{e^{ik\\vert \\bb{X} + \\bb{d} \\vert}}{\\vert \\bb{X} + \\bb{d} \\vert}  &=& i k h_0^{(1)}\\left( k \\left\\vert \\bb{X} + \\bb{d} \\right\\vert \\right) \\\\\n\\ &=& i k \\sum_{l=0}^{\\infty} (-1)^l (2l+1) j_l(kd) h_l^{(1)}(k X) P_l\\left(\\hat{\\bb{d}} \\cdot \\hat{\\bb{X}}\\right) \\label{fmmexp1} }\n\n\\noindent where $k$ is the free-space wavenumber, $j_l$ is the spherical Bessel function, $h_l^{(1)}$ is the spherical Hankel function, and $P_l$ is the Legendre polynomial. The expansion is valid for $d < X$ where $d = \\vert \\bb{d} \\vert$ and $X = \\vert \\bb{X} \\vert$. The second expansion is \n\\eq{j_l(kd) P_l\\left(\\hat{\\bb{d}} \\cdot \\hat{\\bb{X}}\\right) = \\dfrac{i^{-l}}{4\\pi} \\int e^{i \\bb{k}\\cdot\\bb{d}} P_l(\\hat{\\bb{k}} \\cdot\\hat{\\bb{X}}) d\\Omega_k \\label{fmmexp2} }\n\n\\noindent where the integral is over the sphere of plane wave directions, $\\hat{\\bb{k}} = \\bb{k}/k = (\\sin\\theta_k\\cos\\phi_k, \\sin\\theta_k\\sin\\phi_k, \\cos\\theta_k)$ and differential $d\\Omega_k = d^2\\hat{\\bb{k}} = \\sin\\theta_k d\\theta_k d\\phi_k$.  Substituting \\eqref{fmmexp2} into \\eqref{fmmexp1}\n\n\\ea{\\dfrac{e^{ik\\vert \\bb{X} + \\bb{d} \\vert}}{\\vert \\bb{X} + \\bb{d} \\vert}  &=& \\dfrac{i k}{4\\pi} \\int e^{i \\bb{k}\\cdot\\bb{d}}  \\sum_{l=0}^{\\infty} i^l (2l+1) h_l^{(1)}(k X) P_l(\\hat{\\bb{k}} \\cdot\\hat{\\bb{X}}) d\\Omega_k  \\label{fmmexp3}}\n\nNext, let source and observation points be $\\br'$ and $\\br$ with associated local centers, $\\br_s$ and $\\br_o$, respectively.  With these, the vectors $\\bb{X}$ and $\\bb{d}$ are defined \n\\ea{\\bb{X} &=& \\br_o - \\br_s \\label{fmmX} \\\\\n\\bb{d} &=& \\br - \\br_o - (\\br' - \\br_s) \\label{fmmd} }\n\nThe vector $\\bb{X}$ points from the local center of the source points to the local center of the observation points. The vector $\\bb{d}$ is a vector that would point from the source point to the observation point if the two local regions were translated so that they overlapped.  Under the validity condition for the sum, the two local regions must be non-overlapping spheres, in other words $\\vert \\br - \\br_o \\vert < X/2$ and $\\vert \\br' - \\br_s \\vert < X/2$.\n\n\n \\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{FastMultipoleMethod/Figures/fmmgreens} \n   \\caption{Geometry for the plane wave expansion of the scalar and dyadic Green's functions.}\n   \\label{}\n\\end{figure}\n\n\nSubstituting \\eqref{fmmX} and \\eqref{fmmd} into \\eqref{fmmexp3}, and after truncating the sum at degree $L$, the kernel can be approximated  \n\\eq{ \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{\\vert \\br - \\br' \\vert}  \\approx \\dfrac{ik}{4\\pi} \\int e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) e^{-i\\bb{k}\\cdot(\\br' - \\br_s) }d\\Omega_k \\label{kernelexp}}\n\n\\noindent where $T_L$ is the translation operator given by\n\\eq{T_L(\\bb{k},\\bb{X}) = \\sum_{l=0}^L i^l (2l+1) h_l^{(1)} (kX) P_l(\\hat{\\bb{k}}\\cdot\\hat{\\bb{X}}) }\n\n\\paragraph{Green's Functions}\n\nUsing \\eqref{kernelexp}, the scalar Green's function can be written  \n\\eq{ g(\\br,\\br') \\approx \\dfrac{ik}{16\\pi^2} \\int e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) e^{-i\\bb{k}\\cdot(\\br' - \\br_s) }d\\Omega_k }\n\nFrom which the far-field dyadic Green's function is approximated \n\\begin{equation}\n \\overline{\\bb{G}}_f(\\br,\\br') \\approx \\dfrac{ik}{16\\pi^2}  \\int \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right]  e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) e^{-i\\bb{k}\\cdot(\\br' - \\br_s) }d\\Omega_k  \\label{fmmdyadicg}\n \\end{equation}\n\nTreating $\\hat{\\bb{k}}$ as the radial unit vector, the vector dyad can be written $\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} = \\hat{\\boldsymbol{\\theta}}\\hat{\\boldsymbol{\\theta}} + \\hat{\\boldsymbol{\\phi}}\\hat{\\boldsymbol{\\phi}}$, which shows that the far pattern has only $\\hat{\\boldsymbol{\\theta}}$ and $\\hat{\\boldsymbol{\\phi}}$ vector components.  Note, the polarization vectors in the dyadic Green's function are relative to the local center of the source and are not integrated because the integral only expands the scalar part of the kernel.  \n\nTo illustrate how the dyadic Green's function expansion is used with a source, consider the electric field given by the volume integral \n\\eq{ \\bb{E}(\\br) = i \\omega \\mu \\int \\overline{\\bb{G}}(\\br,\\br') \\cdot \\bb{J}(\\br') dV }\n\n\\noindent where $\\bb{J}$ is the current density. Substituting \\eqref{fmmdyadicg}, we can write this as\n\\eq{ \\bb{E}(\\br) \\approx  \\dfrac{i k}{4 \\pi}  \\int \\bb{F}(\\hat{\\bb{k}})  e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) d\\Omega_k  \\label{fmmeint}}\n\n\\noindent where $\\bb{F}(\\hat{\\bb{k}})$ is the far-field radiation pattern of the source\n\\eq{\\bb{F}(\\hat{\\bb{k}}) =  \\dfrac{1}{4 \\pi}  (i \\omega \\mu) \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot \\int  e^{-i\\bb{k}\\cdot(\\br' - \\br_s) }\\bb{J}(\\br') dV }\n\nA similar form can be found in \\cite{hansen2014exact}.  In other words, given a far-field vector radiation pattern, which could equally be that of a scatterer, the electric field at observation point $\\bb{r}$ is computed by \\eqref{fmmeint}, which integrates the product of the pattern, plane wave phases, and translation matrix over all plane wave directions. %In the most general case, the far-field pattern can be any spherical vector field decomposed into $\\hat{\\theta}$ and $\\hat{\\phi}$ components \n%\\eq{\\bb{F}(\\theta,\\phi) = F_{\\theta}(\\theta,\\phi) \\hat{\\theta} + F_{\\phi}(\\theta,\\phi) \\hat{\\phi}}\n\n\n\\section{Selection of L}\n\nIn general, the maximum degree $L$ that is required to accurately compute the translation operation is proportional to the dimension of the source/observation spheres.  There are various formulas for $L$. From \\cite{song1997multilevel,yucel2008helmholtz}, one formula is\n\\eq{L \\approx kd + \\beta \\ln (\\pi + kd)}\n\n\\noindent where $\\beta$ is the number of digits of precision. From \\cite{song2001error,yucel2008helmholtz}, the excess bandwidth formula is \n\\eq{L \\approx kd + 1.8 \\alpha^{2/3} (kd)^{1/3}}\n\n\\noindent where $\\alpha = \\log_{10}(1/\\epsilon)$, and $\\epsilon$ is the number of digits of precision.  In both case, $L$ should be rounded up.\n\nIt needs to be noted that the sum of the translation operator does not become more accurate with more harmonics. In fact, it will break down if the number of harmonics is excessively large. This is due to unstable summation of the Hankel functions when $L$ is too large relative to the argument. Therefore, there is a balance between enough harmonics for accurate translation and too many of them that render the sum inaccurate. This is explained in detail in \\cite{yucel2008helmholtz}.\n\n\n\\section{Integration over the Unit Sphere}\n\nHere we explain rules for sampling and integrating spherical harmonics over the sphere. This is needed for understanding how to compute the plane wave expansions of the FMM, as well as spherical harmonic interpolation and filtering. This is based on a hybrid of Gauss-Legendre quadrature integration in $\\theta$ and trapezoidal integration in $\\phi$. It is exact for band-limited spherical functions assuming a minimum number of sampling points is used, which we derive next. While the method is exact and relatively simple, more efficient spherical integration schemes do exist and that use fewer integration points. \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Gauss-Legendre quadrature}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nIn general, quadrature is used to compute an integral of a continuous function as a weighted sum of its samples. Gauss-Legendre quadrature (Gaussian quadrature) is exact for polynomials of degree $2n-1$ with $n$ nodes and weights, $x_j$ and $w_j$, respectively.  This is normally presented on the domain $x = [-1, 1]$ as \n\\begin{equation}\n\\int_{-1}^{1} f(x) dx = \\sum_j^n w_j f(x_j)\n\\end{equation}\n\nThe nodes are given by the $j$th zero of the Legendre polynomials $P_n(x_j)$ normalized such that $P_n(1) = 1$, with weights \n\\begin{equation}\nw_j = \\dfrac{2}{(1-x_j^2)\\left[P_n'(x_j) \\right]^2}\n\\end{equation}\n\nRoutines exist for computing the nodes and weights of Gauss-Legendre quadrature. We recommend the routine \\texttt{legpts} from the \\texttt{http://www.chebfun.org/} library, which we use throughout and do not repeat here.\n\n \\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{FastMultipoleMethod/Figures/gaussquad} \n   \\caption{Notes and weights of Gaussian quadrature}\n   \\label{}\n\\end{figure}\n\n\\clearpage\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Numerical Integration of Spherical Harmonics}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nHere we derive the number of sampling points needed to numerically integrate spherical harmonics, which follows the results in \\cite{darve2000fast}.  Let $f(\\theta,\\phi)$ be a spherical scalar function composed of a finite number of spherical harmonics\n\\eq{f(\\theta,\\phi) = \\sum_{l=0}^{L}\\sum_{m=-l}^l f_{lm} Y_{lm}(\\theta,\\phi) \\label{fexpansion}}\n\nIntegrating this over the unit sphere and separating variables\n\\ea{\\int_0^{2\\pi} \\int_0^{\\pi} f(\\theta,\\phi) \\sin\\theta d\\theta d\\phi  %&=& \\sum_{l=0}^{L}\\sum_{m=-l}^l f_{lm}  \\int_0^{2\\pi} \\int_0^{\\pi} Y_{lm}(\\theta,\\phi)\\sin\\theta d\\theta d\\phi \\\\\n\\ & = &  \\dfrac{1}{\\sqrt{2\\pi}}  \\sum_{l=0}^{L}\\sum_{m=-l}^l  f_{lm}\\int_0^{2\\pi} e^{im\\phi} d\\phi \\int_0^{\\pi}\\widetilde P_l^m(\\cos\\theta) \\sin\\theta d\\theta d\\phi \\\\ }\n\nThe integral over $\\phi$ can be computed analytically as\n\\eq{ \\int_0^{2\\pi} e^{im\\phi} d\\phi = \\begin{cases}\n2\\pi, \\quad \\quad m = 0 \\\\\n\\dfrac{i (1- e^{2 i \\pi m})}{m} = 0, \\quad \\quad m \\ne 0\n\\end{cases} \\label{intphiana} }\n\nIt is clear that when $m\\ne0$, the double integral will be zero regardless of the value of the $\\theta$ integral. We still want to know the number of discrete integration points in $\\phi$ required to make this true.  Using trapezoidal integration with periodicity, \\eqref{intphiana} is written as a discrete sum over $N$ evenly spaced points\n\\ea{\\int_0^{2\\pi} e^{im\\phi} d\\phi  &=& \\Delta \\phi \\sum_{k=0}^{N-1} e^{im\\phi_k}  \\\\\n\\ &= & \\dfrac{2\\pi}{N}  \\sum_{k=1}^{N} e^{im k 2\\pi/N} \\\\\n\\ &= & \\dfrac{2\\pi}{N}  e^{i(N-1) m \\pi/N } \\dfrac{\\sin(m\\pi)}{\\sin(m\\pi/N)} \\label{trapintphi}}\n\n\\noindent where $\\phi_k = (k-1) \\Delta\\phi$, $k = 1,...,N$, and $\\Delta \\phi = 2\\pi/N$, The last equation comes from the Dirichlet kernel\n\\eq{\\sum_{k=0}^{N-1} e^{ikx} = e^{i(N-1)x/2} \\dfrac{\\sin(Nx/2)}{\\sin(x/2)}}\n\n\\eqref{trapintphi} will be zero when $\\vert m \\vert < N$, because the numerator sine is zero. When $m = N$, applying L'Hopital's rule, the ratio of sine functions is equal to $N$ while the complex exponent is non-zero. Therefore, the number of samples that correctly integrates all harmonics up to $m = L$ is $N = L + 1$. This can be confirmed numerically and is the same as given in \\cite{darve2000fast, beentjes2015quadrature}. We can then write the $\\phi$ integral as \n\\eq{ \\int_0^{2\\pi} e^{im\\phi} d\\phi = \\dfrac{2\\pi}{L+1} \\sum_{i=1}^{L+1} e^{im\\phi_i}, \\quad 0 \\le \\vert m \\vert \\le L }\n\nWhen $m=0$, the $\\theta$ integral becomes \n\\ea{ \\int_0^{\\pi}  P_l(\\cos\\theta) \\sin\\theta d\\theta &=& - \\int_0^{\\pi}  P_l(\\cos\\theta) d\\cos\\theta \\\\\n\\ &=& \\int_{-1}^{1}  P_l(\\mu) d \\mu \\\\\n\\ &=& \\sum_{j=1}^{N} w_j  P_l(\\mu_j) }\n\nwith the change of variables $\\mu = \\cos\\theta$ and where the integral has been replaced with Gaussian quadrature. Because $P_l(\\mu)$ are polynomials of degree $l$, and because the quadrature is exact for polynomial degrees less than $2n-1$, the number of points that will correctly integrate this is $ l  < 2 n - 1$. For maximum harmonic degree $L$, the number of quadrature nodes is $N = (L+1)/2$, which should be rounded up.  \n\t\nAs an aside, when $m$ is even, the associated Legendre polynomials can be integrated with quadrature, because they are simple polynomials. When $m$ is odd, they contain a factor of $\\sqrt{1-\\mu^2}$, which means they are not simple polynomials, and so cannot be integrated exactly via quadrature. This can be verified numerically. However, analytical integration of $P_l^m(\\mu)$ can be done for any $m$, \\cite{beentjes2015quadrature,atkinson2012spherical}.\n\n\nUsing these results, numerical integration of a spherical function composed of spherical harmonics with maximum degree $L$ can be computed exactly (to machine precision) as \n\\eq{\\int_0^{2\\pi} \\int_0^{\\pi} f(\\theta,\\phi) \\sin\\theta d\\theta d\\phi  =   \\dfrac{2\\pi}{L+1} \\sum_{i=1}^{L+1} \\sum_{j=1}^{\\lceil (L+1)/2 \\rceil} w_j f(\\theta_j,\\phi_i) \\label{intsphereharm} }\n\n\\noindent where $\\phi_i = (i-1)2\\pi/(L+1)$, $i = 1,...,L+1$, and $\\theta_j = \\arccos\\mu_j$, where $\\mu_j$ and $w_j$ are the nodes and weights of Gaussian quadrature for $\\lceil (L+1)/2 \\rceil$ points.  \n\nWe know that the spherical harmonics are zero-mean over the sphere except the monopole, therefore, if the expansion coefficients are known, one can simply use $f_{00}$ for the mean. If the coefficients are not known, but the function is sampled on the points of quadrature, \\eqref{intsphereharm} will compute the mean of $f(\\theta,\\phi)$ exactly.  \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Numerical Integration of Products of Spherical Harmonics}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nHere we derive the number of sampling points needed to numerically integrate a product of spherical harmonics over the unit sphere. This can be done using spherical harmonic synthesis. The expansion coefficients of a scalar spherical function are given by \n\\eq{f_{lm} = \\int_0^{2\\pi} \\int_0^{\\pi} f(\\theta,\\phi) Y^*_{lm}(\\theta,\\phi)\\sin\\theta d\\theta d\\phi  }\n\nSubstituting \\eqref{fexpansion} (ignore for the moment equivalency and orthogonality)\n\\ea{f_{lm} %&=& \\sum_{l'=0}^{L}\\sum_{m'=-l'}^{l'} f_{l'm'} \\int_0^{2\\pi} \\int_0^{\\pi}  Y_{l'm'}(\\theta,\\phi)Y^*_{lm}(\\theta,\\phi)\\sin\\theta d\\theta d\\phi \\\\\n&=& \\sum_{l'=0}^{L}\\sum_{m'=-l'}^{l'} f_{l'm'} \\dfrac{1}{2\\pi}\\int_0^{2\\pi} e^{i(m'-m)\\phi} d \\phi \\int_0^{\\pi}  \\widetilde P_{l'}^{m'}(\\cos\\theta)  \\widetilde P_l^m(\\cos\\theta)  \\sin\\theta d\\theta \\\\\n }\n\nUsing the reasoning in the previous section, the maximum harmonic in the $\\phi$ integration is $2L$. Therefore the number of equally spaced sampling points that are required for trapezoidal integration in $\\phi$ is $2L + 1$. The product of two associated Legendre polynomials is a pure polynomial of degree $2L$ for any $m$. Therefore, the number of required samples for Gaussian quadrature in $\\theta$ is $\\lceil L + 1/2 \\rceil$, which can be immediately rounded up to $L + 1$. \n\nUsing these, numerical integration of the product of two spherical \nfunctions, $f(\\theta,\\phi)$ and $g(\\theta,\\phi)$, each with maximum harmonic degree $L$ can be computed exactly as \n\\eq{\\int_0^{2\\pi} \\int_0^{\\pi} f(\\theta,\\phi) g(\\theta,\\phi)  \\sin\\theta d\\theta d\\phi =  \\dfrac{2\\pi}{2L+1} \\sum_{i=1}^{2L+1} \\sum_{j=1}^{L+1} w_j f(\\theta_j,\\phi_i)g(\\theta_j,\\phi_i) \\label{intharmprod}}\n\n\\noindent where $\\phi_i = (i-1)2\\pi/(2L+1)$, $i = 1,...,2L+1$, and $\\theta_j = \\arccos\\mu_j$, where $\\mu_j$ and $w_j$ are the nodes and weights of Gaussian quadrature for $L + 1$ points.  It is common to find \\eqref{intharmprod} in the literature applied to spherical functions without stipulating whether the underlying function is composed of pure harmonics of a product of spherical harmonics.\n\n\n \\begin{figure}[H] \n   \\centering\n   \\subfigure{\\includegraphics[width=3in]{FastMultipoleMethod/Figures/quadsphere5}}\n       \\subfigure{\\includegraphics[width=3in]{FastMultipoleMethod/Figures/quadsphere6}}\n   \\caption{Nodes of trapezoidal integration ($\\phi_i$) and Gaussian quadrature ($\\theta_j$) for integrating products of spherical functions.}\n   \\label{}\n\\end{figure}\n\n\n\nThe nodes $\\theta_j$ are almost uniformly spaced, and they never sample the poles because of the nodes of Gaussian quadrature do not sample the end points. This is especially convenient for vector spherical harmonics where the polarization is ambiguous at the poles. When $L+1$ is odd, the nodes will sample the equator. This scheme does crowd the poles somewhat.\n\nFinally, \\eqref{intharmprod} can be viewed as computing the power of a field over the sphere when the second function is conjugated (or computing the cross-correlation of two fields). If the spherical harmonic expansion coefficients are known, the analogous form of Parseval's theorem can be used to simply sum the magnitude squared of the coefficients. If the coefficients are not known, \\eqref{intharmprod} will compute a power-like quantity exactly from samples of the field(s). \n\n\n\n%\n%Integration of a spherical function $f(\\hat{\\bb{k}})$ over the unit sphere can be written generally as \n%\\eq{\\int f(\\hat{\\bb{k}}) d\\hat{\\bb{k}} = \\int_0^{2\\pi} \\int_0^{\\pi} f(\\theta,\\phi) \\sin\\theta d\\theta d\\phi }\n%\n%\\noindent where $\\hat{\\bb{k}} = (\\sin\\theta\\cos\\phi, \\sin\\theta\\sin\\phi, \\cos\\theta)$.  \n%\n%This integral can be computed exactly from the samples of $f(\\hat{\\bb{k}})$, if $f$ is band-limited, using a hybrid of Gauss-Legendre quadrature in $\\theta$ and trapezoidal integration in $\\phi$.  After a change of variables, the integral is \n%\\begin{eqnarray}\n%\\int f(\\hat{\\bb{k}}) d\\hat{\\bb{k}} & =& \\int_0^{2\\pi} \\int_0^{\\pi} f(\\theta,\\phi) \\sin\\theta d\\theta d\\phi \\\\\n%\\ & =& \\int_0^{2\\pi} \\int_{-1}^1 f(\\mu,\\phi) d\\mu d\\phi \\\\\n%\\ & = & \\dfrac{2\\pi}{2L+1} \\sum_{i=1}^{2L+1} \\sum_{j=1}^{L+1} w_j f(\\theta_j,\\phi_i) \\label{sphereint}\n%\\end{eqnarray}\n%\n%\n%\n%\n%\\noindent where $w_j$ are the weights corresponding to Gaussian nodes $\\mu_j$ on $[-1,1]$. The angular sampling points are $\\theta_j = \\arccos\\mu_j$ and $\\phi_i = (i-1)2\\pi/(2L+1)$. $L$ is the maximum degree required to expand the function $f(\\theta,\\phi)$ in spherical harmonics.  Interestingly, the nodes $\\theta_j$ are almost uniformly spaced, and they never sample the poles because of the nodes of Gaussian quadrature do not sample the end points. When $L+1$ is odd, the nodes will sample the equator.\n%\n%Address the no-quite polynomials for straight spherical harmonics.   Spherical transforms and green's function contain products of these harmonics. \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Green's Function Integration}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nFollowing \\cite{yucel2008helmholtz}, we give the number of sample points required to correctly integrate the plane wave expansions in the FMM. Using the addition theorem for plane waves \n\\eq{e^{i \\bb{k}\\cdot \\bb{d}} = \\sum_{l=0}^{\\infty} i^l (2l+1) j_l(kd) P_l(\\hat{\\bb{k}}\\cdot\\hat{\\bb{d}})}\n\n\\eqref{fmmexp3} can be written \n\\ea{\\dfrac{e^{ik\\vert \\bb{X} + \\bb{d} \\vert}}{\\vert \\bb{X} + \\bb{d} \\vert}  &=& \\dfrac{i k}{4\\pi}  \\sum_{l=0}^{\\infty} \\sum_{l'=0}^{\\infty} i^l (2l+1) i^{l'} (2l'+1) h_l^{(1)}(k X)   j_l'(kd)   \\int   P_l(\\hat{\\bb{k}} \\cdot\\hat{\\bb{X}}) P_l'(\\hat{\\bb{k}}\\cdot\\hat{\\bb{d}})   d\\Omega_k }\n\nUsing the addition theorem for Legendre polynomials, \n\\eq{P_l(\\hat{\\br} \\cdot \\hat{\\br}') = \\dfrac{4\\pi}{2l + 1} \\sum_{m=-l}^l Y_{lm}(\\theta,\\phi) Y_{lm}^*(\\theta',\\phi')}\n\nthe integral can be expanded as \n\\eq{\\int  P_l(\\hat{\\bb{k}} \\cdot\\hat{\\bb{X}}) P_l'(\\hat{\\bb{k}}\\cdot\\hat{\\bb{d}})   d\\Omega_k   = \\dfrac{4\\pi}{2l + 1} \\dfrac{4\\pi}{2l' + 1}  \\sum_{m=-l}^l  \\sum_{m=-l'}^{l'} Y_{lm}^*(\\theta_X',\\phi_X') Y_{lm}^*(\\theta_d',\\phi_d')    \\int  \\left(Y_{lm}(\\theta_k,\\phi_k)\\right)^2 d\\Omega_k }\n\nWhich shows that the spherical integral in \\eqref{fmmexp3} is really integrating a product of spherical harmonics. Therefore, using the results from the previous section, the integral over planes waves in the Green's function kernel \\eqref{kernelexp} can be computed exactly over discrete values of the wave vector $\\hat{\\bb{k}}_{ij}$ as \n\\eq{ \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{\\vert \\br - \\br' \\vert}  \\approx \\dfrac{ik}{4\\pi} \\dfrac{2\\pi}{2L+1} \\sum_{i=1}^{2L+1} \\sum_{j=1}^{L+1} w_j  e^{ik \\hat{\\bb{k}}_{ij}\\cdot(\\br - \\br_o)} T_L(k \\hat{\\bb{k}}_{ij},\\bb{X}) e^{-ik \\hat{\\bb{k}}_{ij} \\cdot(\\br' - \\br_s) } }\n\nwhich is the result in \\cite{yucel2008helmholtz}. The approximation comes from truncating the sum in \\eqref{kernelexp}, not the spherical integration.  \n\n\n\n\n\\section{Aggregation/Disaggregation}\n\nHere we give a basic idea of how to aggregate, translate, and disaggregate fields in the context of the FMM operations following the explanation in \\cite{yucel2008helmholtz}. The routines for computing the translation operator are given in Section \\ref{transoperator}, while routines for interpolating and filtering scalar and vector fields are given in Sections \\ref{sec:scasphfilter} and \\ref{sec:vecsphfilter}.\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Octree}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nTypically the scatterers in an FMM problem are organized on a hierarchical octree. An octree is a data structure in which each node has eight children. This is combined with the geometric process of subdividing a cubic volume into eight equal octants. The eight subcubes are called the children of the larger parent cube and visa versa. A cube at every level has an outgoing and incoming far-field pattern associated with it, say $\\bb{F}(\\hat {\\bb{k}})$, which is sampled on the sphere according to the rules of quadrature. This field expansion is centered on the cube and has harmonic bandwidth (i.e., maximum degree vector spherical harmonic, $L$) at least as large as that required for the diameter of the enclosing sphere, and further set by the desired accuracy of the translation operations. This means that fields are coarsely sampled in $(\\theta,\\phi)$ at higher levels (smaller cubes), and more finely sampled at lower (larger cubes) levels.\n\nFields are aggregated up the hierarchy, translated at the highest level possible, then disaggregated down the hierarchy. There is a constraint that fields cannot be translated to neighboring boxes at the same level (due to the separation requirement of the translation). This creates a complication when disaggregating. For more details see \\cite{yucel2008helmholtz}. In general, aggregation and disaggregation do not have to be restricted to octree structures as long as the bandwidth and separation between the groups of scatterers is obeyed. \n\n\n \\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=6in]{FastMultipoleMethod/Figures/aggdiss} \n   \\caption{Aggregation, translation, and disaggregation. }\n   \\label{}\n\\end{figure}\n\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Aggregation}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nTo reiterate, the far pattern of each child cube has lower harmonic content than the parent (due to its smaller size), and therefore coarser spatial sampling in $(\\theta,\\phi)$. The process of aggregating fields consists of 1) interpolating each far pattern of the children cubes up to the finer sampling of the parent, 2) shifting the phase centers of the children's patterns to that of the parent, then 3) summing the fields of the all the children. The shift is done by multiplication by a complex exponential of plane wave phases, which is equivalent to a diagonal matrix-vector multiply and is trivial to compute. \n\nLet $\\bb{F}_{n,l}(\\hat {\\bb{k}})$ be the vector field for the $n$th group (cube) at level $l$.  Let $P_{l+1}^{l}$ be the interpolation operator that interpolates a field from level $l+1$ to level $l$. The aggregated field for the $n$th group at the level of the parents is the sum over all interpolated and shifted fields of the children belonging to each parent, \\cite{yucel2008helmholtz}:\n\\begin{equation}\n\\bb{F}_{n,l}(\\hat {\\bb{k}}_{l}) = \\sum_{m \\in G_c} e^{i\\bb{k}_{l+1} \\cdot (\\bb{x}_{n} - \\bb{x}_{m}) } P_{l+1}^{l}\\left[\\bb{F}_{m,l+1}(\\hat{ \\bb{k}}_{l+1})\\right]\n\\end{equation}\n\n\\noindent where $G_c$ are the list of children that belong to parent group $n$, and $\\hat {\\bb{k}}_{l}$ are the spherical directions sampled for level $l$.\n\nThe process of interpolation does not change the harmonic content of the patterns of the children. However, multiplying the pattern by the phase exponential of the plane wave shift is equivalent to convolving the spherical harmonic spectra. This is why the fields are first interpolated, then translated. Another way to think about this is, even though the patterns of the children may contain lower harmonic content when centered on the cubes of the children, the same pattern that is offset from a different center, now belongs to a larger enclosing sphere, and therefore has more harmonic content requiring finer spherical sampling.\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Disaggregation}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nDisaggregation sweeps from the lowest level of the octree (largest cubes) to the highest level (smallest cubes) and consists of three steps: 1) shift the field of a parent to the phase center of the child then filter the parent's field to the child's level (i.e., anterpolate), 2) translate the outgoing patterns between groups at the same level that are not near-neighbors but whose parents are near-neighbors (i.e., called the neighborhood of the child), 3) sum the filtered and translated fields. This is done recursively from the bottom level to the top level for all groups and can be written. \n\\begin{equation}\n\\bb{G}_{m,l}(\\hat {\\bb{k}}_{l}) = P_{l-1}^{l}\\left[e^{i\\bb{k}_{l-1} \\cdot (\\bb{x}_{m} - \\bb{x}_{n}) }  \\bb{G}_{n,l-1}(\\hat{ \\bb{k}}_{l-1})\\right] + \\sum_{p \\in G_w} T_L({\\bb{k}}_{l}, \\bb{x}_{m} - \\bb{x}_{p}) \\bb{F}_{p,l}(\\hat {\\bb{k}})\n\\end{equation}\n\n\\noindent where $P_{l-1}^{l}$ is the filtering operator that filters the parent's field at level $l-1$ to the child sampling, $m$ is index of the child at level $l$, $n$ is the index of the parent at the parent's level, and $G_w$ is the list children at level $l$ that are well-separated from $m$ (i.e., children that are not near-neighbors, but whose parents are near-neighbors). The purpose of filtering the field of the parent is to reduce its total harmonic content to be of the same degree as that of the child. \n\n\n\\section{Translation Operator}\n\\label{transoperator}\n\n\\subsection{Basic Translation Operator}\nThe FMM translation operator is \n\\begin{equation}\nT_L(\\bb{k},\\bb{X}) = \\sum_{l=0}^L i^l (2l+1) h_l^{(1)} (kX) P_l(\\hat{\\bb{k}}\\cdot\\hat{\\bb{X}}) \n\\end{equation}\n\n\\noindent where $\\bb{X}$ is the Cartesian vector that points from the origin of the source frame to the origin of the observation frame, $k$ is the complex background wavenumber, $\\hat{\\bb{k}}$ is the Cartesian wave vector direction, $P_l(x)$ is the Legendre polynomial, and $L$ is the maximum degree of the sum. When computing this, it can be written terms of the dot product $\\cos\\theta = \\hat{\\bb{k}}\\cdot\\hat{\\bb{X}}$ in order to externalize the vector computations.\n\\begin{equation}\nT_L(kX,\\theta) = \\sum_{l=0}^L i^l (2l+1) h_l^{(1)} (kX) P_l(\\cos\\theta) \\label{tltheta}\n\\end{equation}\n\n\n \\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=3.5in]{FastMultipoleMethod/Figures/TLtheta} \n   \\caption{Real part of the translation operator, \\eqref{tltheta}, for $\\hat{\\bb{X}} = [1, 0, 0]$, $L = 12$, and $kX = 50$. The grid is highly oversampled compared to the sampling required for quadrature integration over the sphere. Note, the operator is peaked in the direction of propagation and contains a 'back lobe'-like feature.}\n   \\label{}\n\\end{figure}\n\n\n\nThe routine \\texttt{TLth} returns the translation operator \\eqref{tltheta} given scalars $kX$, $L$, and array of $\\cos\\theta$, which can be any size. To save memory, the Legendre polynomials are computed inline with the recursion \\eqref{plrec}.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/TL/TLth.m}\n}\n\n\n\n%\n%\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/FastMultipoleMethod/TLth.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/FastMultipoleMethod/TLmem.m}\n%}\n\n\\subsection{Translation Operator Interpolation}\n\nComputing the translation operator as a straight sum is a computational bottleneck for large problems.  Much work has gone into finding an optimal computation scheme, and the result is a fast interpolator.  The translation operator is precomputed directly at a coarse sampling, after which any value is found by interpolation to a selectable level of error.  Because the translation operator is band limited, it can be computed exactly from the samples using the approximate prolate spheroid (APS) method.  In practice, only a small subset of samples in the vicinity of the interpolation point needs to be used.  \n\nThe interpolation formula using APS is given by \\cite{bucci1991optimal,yucel2008helmholtz}\n\\begin{equation}\n\\widetilde{T}_L(\\theta) = \\sum_{m = m_o - p + 1}^{m_o + p} T_L(m\\Delta\\theta)S_N(\\theta-m\\Delta\\theta,\\theta_o)D_M(\\theta - m \\Delta\\theta)\n\\end{equation}\n\n\\noindent where $\\widetilde{T}_L(\\theta)$ is the interpolated translation operator, $D_M(\\theta)$ is the periodic sinc function (or Dirichlet kernel), $S_N(\\theta,\\theta_o)$ is a windowing function, and $T_L(m\\Delta\\theta)$ are precomputed samples of the translation operator.  The windowing function is given by \n\\begin{equation}\nS_N(\\theta,\\theta_o) = \\dfrac{R_N(\\theta,\\theta_o)}{R_N(0,\\theta_o)} \n\\end{equation}\n\\begin{equation}\nR_N(\\theta,\\theta_o) = \\dfrac{\\sinh\\left[ (2N+1) \\sinh^{-1} \\sqrt{\\sin^2(\\theta_o/2) - \\sin^2(\\theta/2)}\\right]}{\\sqrt{\\sin^2(\\theta_o/2) - \\sin^2(\\theta/2)}}\n\\end{equation}\n\nThe Dirichlet kernel is given by \n\\begin{equation}\nD_M(\\theta) = \\dfrac{\\sin\\left[(2M+1)\\theta/2 \\right]}{(2M+1)\\sin(\\theta/2)}\n\\end{equation}\n\nIn these expressions, $L$ is the truncation degree of the sum and $M=sL$ is the total number of precomputed sampling points where $s$ is the over-sampling ratio and is an integer.  The required sample spacing is $\\Delta \\theta = 2\\pi/(2M+1)$.  This spacing is over a $2\\pi$ circumference, even though we only need $\\theta = [0, \\pi]$.  This comes from the original papers on optimal interpolation over a sphere, but the formulation persists in the literature.  $N = M-L = (s-1)L$ is the number of over-sampling points.  $m_o = \\textrm{Int}[\\theta/\\Delta\\theta]$ is the integer index to the left of the interpolation point, where $\\textrm{Int}[\\cdot]$ is the integer part or floor function.   $\\theta_o = p\\Delta\\theta$ is the width of the interpolation window, where $p$ is the number of samples on each side of the interpolation point.  The choice of $s$ and $p$ is important for maintaining accuracy while minimizing computation.  Good empirical values are $s = 5$, $p= 3$.  \n\n \\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=3in]{FastMultipoleMethod/Figures/indexing} \n   \\caption{Sampling and indexing of the interpolation.  Example for $M = 8$, $p = 3$.  $m=0$ corresponds to $\\theta = 0$. Note no sample at $\\theta=\\pi$.}\n   \\label{fig4}\n\\end{figure}\n\nEven though we will only interpolate $\\theta = [0, \\pi]$, we require precomputed samples outside this range when interpolating near the ends.  The translation operator is an even function of $\\theta$, therefore, there are two options to obtain the out of bounds points: 1) Only compute sampling points in the range $\\theta = [0, \\pi]$ and loop the summation index $m$ back on itself if we go beyond the ends, or 2) precompute the necessary values outside of the range, and let the index roam free. We choose the first for simplicity.  \n\nFigure \\ref{fig4} illustrates the sample spacing as it relates to the number of sample points as well as the indexing scheme for precomputing points outside the range $\\theta = [0, \\pi]$.  There are $p-1$ samples to the left of 0, $p$ samples after $\\pi$, $M + 2p$ total sample points, and the array index is $I = m + p$, where $m = [0,M]$.  Figure \\ref{fig5} shows the interpolator.  \n\n \\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{FastMultipoleMethod/Figures/TLthetainterp} \n   \\caption{Translation operator interpolator.  $L = 4$, $s = 5$, $p = 3$, $M = 20$ and there are $M + 2p$ total sampling points.  $k = 2\\pi$, $r = 10$. Note there is no sampling point at $\\theta = \\pi$.}\n   \\label{fig5}\n\\end{figure}\n\nThe routine \\texttt{interpTL} takes as inputs the outputs from the preparatory function \\texttt{interpTLprep} as well as the interpolation point(s).  The helper functions are the windowing and Dirichlet kernel, \\texttt{SN} and \\texttt{DM}.  \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/TL/interpTL.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/TL/interpTLprep.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/TL/SN.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/TL/DM.m}\n}\n\n\n\n\n\\section{Scalar Spherical Filter}\n\\label{sec:scasphfilter}\n\nIn this section, we give routines for interpolating and filtering scalar spherical harmonics following \\cite{yucel2008helmholtz}. These routines can stand on their own, because they are excellent for general applications of spherical harmonic expansions. The scalar filters can be used in the scalar form of the FMM for interpolating and filtering fields up and down the multi-level hierarchy structure. These lay the ground work for the vector spherical filters derived later.\n\n\\subsection{Spherical Harmonic Transforms}\n\nThe spherical harmonics form a complete basis, so any band-limited spherical signal can be represented as a finite sum of harmonics\n\\begin{equation}\nf(\\theta,\\phi) = \\sum_{l=0}^{L} \\sum_{m = -l}^{l} f_{lm} Y_{lm}(\\theta,\\phi)\n\\label{c6eq1}\n\\end{equation}\n\nSpherical harmonics can be written in terms of the normalized Legendre polynomials as \n\\begin{equation}\nY_{lm}(\\theta,\\phi) = \\dfrac{1}{\\sqrt{2\\pi}}\\widetilde{P}_l^m(\\cos \\theta)e^{im\\phi}\n\\end{equation}\n\nUsing orthogonality of the spherical harmonics, the expansion coefficients are\n\n%\\begin{equation}\n%\\int_{0}^{2\\pi} \\int_{0}^{\\pi} Y_{lm}(\\theta,\\phi) Y^*_{l'm'}(\\theta,\\phi) \\sin\\theta d\\theta d\\phi = \\delta_{ll'}\\delta_{mm'}\n%\\end{equation}\n\n%from which is follows that\n\n\\begin{equation}\nf_{lm} = \\int_{0}^{2\\pi} \\int_{0}^{\\pi}  f(\\theta,\\phi) Y^*_{l'm'}(\\theta,\\phi) \\sin\\theta d\\theta d\\phi   \n\\label{c6eq3}\n\\end{equation}\n\nEquation \\eqref{c6eq3} is the forward transform, or spherical harmonic analysis, while equation \\eqref{c6eq1} is the inverse transform, or spherical harmonic synthesis.  \n\n\n\n\n\\subsection{Forward Scalar Spherical Transform}\n\nComputing \\eqref{c6eq3} consists of two steps: 1) forward Fourier transform in $\\phi$, 2) forward Legendre transform in $\\theta$.  Writing out \\eqref{c6eq3}\n\\begin{equation}\nf_{lm} = \\int_{0}^{\\pi} \\widetilde{P}_l^m(\\cos \\theta) \\sin \\theta d \\theta \\dfrac{1}{\\sqrt{2\\pi}} \\int_{0}^{2\\pi}   f(\\theta,\\phi) e^{-im\\phi} d\\phi   \n\\end{equation}\n\n\\noindent where $\\widetilde{P}_l^m(\\cos \\theta)$ are the fully normalized Legendre polynomials.  The $\\phi$ integral is computed first in order to create a set of 1D functions of $\\theta$ for each $m$\n\\begin{equation}\nf_m(\\theta) = \\dfrac{1}{\\sqrt{2\\pi}} \\int_{0}^{2\\pi}   f(\\theta,\\phi) e^{-im\\phi} d\\phi   \n\\end{equation}\n\nEvaluating this with trapezoidal integration\n\\begin{equation}\nf_m(\\theta) = \\dfrac{\\sqrt{2\\pi}}{I} \\sum_{i=1}^{I} f(\\theta,\\phi_i) e^{-im\\phi_i} \n\\end{equation}\n\n\\noindent where $I$ is the number of grid points in longitude and $\\phi_i = 2\\pi i/ I $ for $ i = 0,...,I-1$.  This can be computed via FFT. The $\\theta$ integral is next computed for each $f_m(\\theta)$ by using the forward Legendre transform with a change of variables \n\\ea{f_{lm} &=& \\int_{0}^{\\pi} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) \\sin \\theta d \\theta \\\\\n\\ & = & -\\int_{0}^{\\pi} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) d\\cos\\theta \\\\\n\\ & = & \\int_{-1}^{1} f_m(\\theta( \\mu)) \\widetilde{P}_l^m(\\mu) d\\mu, \\quad \\mu = \\cos\\theta }\n\n%\n%\\begin{equation}\n%f_{lm} = \\int_{0}^{\\pi} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) \\sin \\theta d \\theta \n%\\end{equation}\n%\n%Making a change of variables\n%\\begin{eqnarray}\n%%f_{lm} &=& \\int_{0}^{\\pi} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) \\sin \\theta d \\theta \\\\\n%f_{lm} & = & -\\int_{0}^{\\pi} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) d\\cos\\theta \\\\\n%%\\ & = & \\int_{\\pi}^{0} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) d\\cos\\theta \\\\\n%\\ & = & \\int_{-1}^{1} f_m(\\theta( \\mu)) \\widetilde{P}_l^m(\\mu) d\\mu, \\quad \\mu = \\cos\\theta \n%\\end{eqnarray}\n\nThis can now be evaluated with Gaussian quadrature on the interval $\\mu = [-1, 1]$ as\n\\begin{equation}\nf_{lm} = \\sum_{j=1}^J f_m(\\theta_j) \\widetilde{P}_l^m(\\mu_j) w_j \\label{forwardlegendre}\n\\end{equation}\n\n\\noindent where $J$ is the number of points in latitude and the weights, $w_j$, correspond to the nodes $\\theta_j = \\arccos\\mu_j$.  One first selects the number of grid points in latitude, retrieves the Gaussian nodes for that number of integration points, then evaluates the points $\\theta_j$.  Because this operation is integrating products of spherical harmonics, the integral is exact if the number of grid points in latitude and longitude are $J = L+1$ and $I = 2L+1$ for coefficients through $L$. By virtue of the Gaussian quadrature node spacing, the field is never evaluated at the poles.\n\nThe routine \\texttt{sst} performs the forward scalar spherical transform and returns the spectral coefficients $f_{lm}$.  The coefficients are returned on a 1D array of size $L^2 + 2L + 1$, linearly indexed.  It takes as inputs the maximum degree $L$ for which harmonics are desired. The spherical function $f(\\theta_j,\\phi_i)$ is sampled on an $I \\times J$ meshgrid, where $I = 2L'+1$ and $J = L'+1$ are such that $L' \\ge L$.  The sample points need to be $\\phi_i = 2\\pi i/ I $ for $ i = 0,...,I-1$, and $\\theta_j = \\arccos \\mu_j $, where $\\mu_j$ are the $J$ quadrature nodes on $\\mu = [-1, 1]$, which are also inputs. In other words, the grid can be sampled more finely than the maximum degree of the harmonics desired for the coefficients. $f_m(\\theta_j)$ is computed in place with an FFT along the first dimension of the array.  Matlab's \\texttt{fft} produces a two-sided DFT, and $2L+1$ is always odd, so the rows of the matrix $f_m(\\theta_j)$ correspond to the spectral components $m = 0, 1, ..., (I-1)/2, -(I-1)/2, ..., -1$.  The rows of the 1D FFT are indexed \n\\begin{equation}\n\\textrm{idx}(I,m) = \\left\\{ \\begin{array}{cc} m + 1, & m \\ge 0 \\\\ I - m + 1, & m < 0 \\\\ \\end{array} \\right.\n\\end{equation}\n\n%Finally, this uses our routine \\texttt{Plm} for associated Legendre polynomials, which ensures that one factor of $(-1)^m$ in included in the definition of the spherical harmonics.\n\n\n%uses onThe Legendre polynomials are computed normalized with Matlab's \\texttt{legendre} function and \\texttt{'norm'} option.  An extra factor of $(-1)^m$ is included in that definition. Therefore, we need to cancel this to be content with our use of the Condon-Shortly phase that we include in our definition of spherical harmonics.\n\n%\n%Note: the definition of Legendre polynomials has a factor of $(-1)^m$.  Our definition of spherical harmonics includes the Condon-Shortly phase, which means there are really two factors of $(-1)^m$ in the entire definition.  Our spherical harmonics are consistent with the wave function translation matrices.  This derivation of the filter does not include the extra $(-1)^m$ on the spherical harmonics, only the one in the definition of the Legendre polynomials, which is also included with the \\texttt{'norm'} option.  The filter works was shown to work with just the one factor.  Therefore, we take out the second factor of $(-1)^m$ by multiplying by $(-1)^m$.  If the definition of the the spherical harmonics does not include that phase, then that part of the code should be removed.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/sst.m}\n}\n\n\n\n\\subsection{Inverse Scalar Spherical Transform}\n\nThe inverse transform consists of taking the expansion coefficients $f_{lm}$ and applying 1) the inverse Legendre transform in $\\theta$, 2) the inverse Fourier transform in $\\phi$.  The inverse Legendre transform is \n\n\\begin{equation}\nf_m(\\theta_j) = \\sum_{l = \\vert m \\vert}^{L} f_{lm} \\widetilde{P}_l^m(\\mu_j)\n\\label{eqist1}\n\\end{equation}\n\n\\noindent where again $\\mu_j = \\cos\\theta_j$.  The inverse Fourier transform in $\\phi$ is\n\n\\begin{equation}\nf(\\theta_j,\\phi_i) = \\dfrac{1}{\\sqrt{2\\pi}}\\sum_{m = -L}^{L} f_m(\\theta_j) e^{im\\phi_i}\n\\label{eqist2}\n\\end{equation}\n\nThe routine \\texttt{isst} computes the inverse scalar spherical transform.  The inputs are the array of harmonics $f_{lm}$ of size $L^2 + 2L + 1$ linearly indexed, and the maximum degree $L$. It then returns the $I \\times J$ spherical function $f(\\theta_j,\\phi_i)$ as a meshgrid such that $I = 2L'+1$ and $J = L' + 1$, where $\\phi_i = 2\\pi i/ I $ for $ i = 0,...,I-1$, and $\\mu_j = \\cos\\theta_j$.  $J$ is determined by the length of the input $\\mu_j$, which can be larger than the corresponding sampling of the $L$ harmonics in $f_{lm}$ (this allows the routine to preform interpolation automatically). An additional factor of $I$ is needed because Matlab's \\texttt{ifft} divides by the number of samples in $\\phi$.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/isst.m}\n}\n\n\\clearpage\n\n\\subsection{Scalar Spherical Filter}\n\nThe forward and inverse scalar spherical transforms can be used together to accomplish interpolation or filtering (anterpolation) of a spherical function.  \n\nInterpolation takes a function $f(\\theta,\\phi)$ with coarse sampling and $L$ harmonics, and upsamples it to a function $f(\\theta',\\phi')$ with finer sampling and $K$ harmonics, where $K > L$.  Because the original signal is band limited with maximum harmonic $L$, the interpolated signal contains the same harmonic content, and is interpolated exactly. This is the spherical harmonic analog of upsampling a Nyquist-sampled exactly to an arbitrarily fine sampling with sinc interpolation.  Interpolation is accomplished by first computing the spectral components $f_{lm}$ of $f(\\theta,\\phi)$ using the scalar spherical transform to degree $L$, zero-padding the coefficients to degree $K$ to form $f_{lm}'$, then applying the inverse scalar spherical transform to create $f(\\theta',\\phi')$.\n\nFiltering takes $f(\\theta',\\phi')$ with fine sampling and $K$ harmonics to a function $f(\\theta,\\phi)$ with coarse sampling and $L$ harmonics, where $L < K$.  This is analogous to filtering a signal and resampling it at lower rate.  Filtering necessarily eliminates higher frequency harmonics.  Filtering is accomplished by computing the spectral components $f_{lm}'$ of $f(\\theta',\\phi')$ via the SST to degree $K$, truncating down to degree $L$ to form $f_{lm}$, then applying the ISST to create $f(\\theta,\\phi)$.\n\n\\begin{equation}\n\\begin{array}{cccccccccc}\n\\textrm{Interpolation:} & f(\\theta,\\phi) & \\stackrel{\\textrm{sst}}{\\rightarrow} & f_{lm}, L & \\rightarrow & \\textrm{zero pad} &\\rightarrow & f_{lm}', K & \\stackrel{\\textrm{isst}}{\\rightarrow} & f(\\theta',\\phi') \\nonumber \\\\\n\\textrm{Filter:} & f(\\theta',\\phi') & \\stackrel{\\textrm{sst}}{\\rightarrow} & f_{lm}', K & \\rightarrow & \\textrm{trunctate} &\\rightarrow & f_{lm}, L &\\stackrel{\\textrm{isst}}{\\rightarrow} & f(\\theta,\\phi) \\nonumber \\\\\n\\end{array}\n\\end{equation}\n\n%\n% \\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=3.5in]{FastMultipoleMethod/Figures/samples} \n%   \\caption{Sample spacing for $L = 4$.}\n%   \\label{}\n%\\end{figure}\n%\n\n\n \\begin{figure}[H] \n \\centering\n\\subfigure{\n\\includegraphics[width=3in]{FastMultipoleMethod/Figures/filt1} } \n\\subfigure{\n\\includegraphics[width=3in]{FastMultipoleMethod/Figures/filt2} } \n\\caption{Interpolation of a complex scalar field (real part). Left: coarsely sampled field. Right: finely sampled interpolated field. }\n\\end{figure}\n\n \\begin{figure}[H] \n \\centering\n\\subfigure{\n\\includegraphics[width=3in]{FastMultipoleMethod/Figures/filt3} } \n\\subfigure{\n\\includegraphics[width=3in]{FastMultipoleMethod/Figures/filt4} } \n\\caption{Filtering of a complex scalar field (real part). Left: finely sampled field. Right: coarsely sampled filtered field. }\n\\end{figure}\n\n\nThe routine \\texttt{ssfilt} computes the scalar spherical interpolation or filtering operation.  It takes the maximum harmonic degrees $L$ and $K$, where $L \\le K$.  The harmonic content is either interpolated from $L$ to $K$ or filtered from $K$ to $L$.  For interpolation, the input function is $f(\\theta,\\phi)$, sized $2L'+1 \\times L' + 1$ on a meshgrid, and the routine returns $f(\\theta',\\phi')$, sized $2K'+1 \\times K'+1$, where $L'$ and $K'$ are set by the length of $\\mu_j$ and $\\mu_k$, respectively.  The sampling of the grid can have more harmonics than the interpolation/filter harmonics. As always, it assumes $\\phi$ is uniformly spaced and $\\theta$ is spaced according to the Gaussian quadrature nodes.  This routine calls \\texttt{sst} and \\texttt{isst} that recompute the underlying Legendre polynomials at each run and is not built for speed.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/ssfilt.m}\n}\n\n\\clearpage\n\n\\subsection{Fast Scalar Spherical Filter}\n\\label{sec:fastscasphfilt}\nThe bottle neck of the scalar spherical filter lies in the sums of the forward and inverse Legendre transforms, especially when $L$ is large.  The fix is to combine the two transforms, after which the sums can be simplified and further accelerated with the 1D FMM, which is described in Section \\ref{sec:1dfmm}. For a discussion of the computational complexity, see \\cite{yucel2008helmholtz}.\n\nAssume that interpolation is being done and $L < K$.  The quantities $\\theta_j$, $\\mu_j$, and $w_j$ are associated with $L$ harmonics of field $f(\\theta_j,\\phi_i)$, and the quantities $\\theta_k$, $\\mu_k$, and $w_k$ are associated with $K$ harmonics of field $f'(\\theta_k,\\phi_k)$ and the routine is interpolating $f(\\theta_j,\\phi_i)$ to $f'(\\theta_k,\\phi_k)$. Start by substituting the forward Legendre transform, \\eqref{forwardlegendre}, into the inverse Legendre transform, \\eqref{eqist1}, \n\\begin{equation}\nf_m'(\\theta_k) = \\sum_{l = \\vert m \\vert}^{K} \\left(\\sum_{j=1}^J f_m(\\theta_j)\\widetilde{P}_l^m(\\mu_j)w_j\\right) \\widetilde{P}_l^m(\\mu_k)\n\\end{equation}\n\nWhen $L<K$, the sum over $K$ can be restricted to $L$ because $f_m(\\theta_j)$ does not have harmonics when $\\vert m\\vert> L$.  This is equivalent to zero-padding the harmonics $f_{lm}$ in the standard spherical filter. Changing the limit of the sum and exchanging the order of the sums\n\\begin{equation}\nf_m'(\\theta_k) = \\sum_{j=1}^J f_m(\\theta_j)w_j \\sum_{l = \\vert m \\vert}^{L} \\widetilde{P}_l^m(\\mu_j) \\widetilde{P}_l^m(\\mu_k) \\label{combineLtrans}\n\\end{equation}\n\n%\\begin{equation}\n%f_m'(\\theta_k) = \\sum_{l = \\vert m \\vert}^{L} \\left(\\sum_{j=1}^J f_m(\\theta_j)\\widetilde{P}_l^m(\\mu_j)w_j\\right) \\widetilde{P}_l^m(\\mu_k)\n%\\end{equation}\n\n\nThe sum over $L$ can be simplified with the Christoffel-Darboux formula \n\\begin{equation}\n\\sum_{l = \\vert m \\vert}^{L} \\widetilde{P}_l^m(\\mu_j) \\widetilde{P}_l^m(\\mu_k) = \\epsilon_{L+1}^m \\dfrac{ \\widetilde{P}_{L+1}^m(\\mu_k)  \\widetilde{P}_L^m(\\mu_j) - \\widetilde{P}_{L}^m(\\mu_k)  \\widetilde{P}_{L+1}^m(\\mu_j)}{\\mu_k - \\mu_j} \\label{cdform}\n\\end{equation}\n\nwhere\n\\begin{equation}\n\\epsilon_{l}^m  = \\sqrt{\\dfrac{l^2 - m^2}{4l^2 - 1}}\n\\end{equation}\n\nSubstituting \\eqref{cdform} into \\eqref{combineLtrans} and separating terms\n%\\begin{equation}\n%f_m'(\\theta_k) = \\sum_{j=1}^J f_m(\\theta_j)w_j\\epsilon_{L+1}^m \\dfrac{\\widetilde{P}_{L+1}^m(\\mu_k) \\widetilde{P}_{L}^m(\\mu_j) - \\widetilde{P}_{L}^m(\\mu_k) \\widetilde{P}_{L+1}^m(\\mu_j)}{\\mu_k - \\mu_j}\n%\\end{equation}\n%\n%Separating the terms\n\\begin{equation}\n\\dfrac{f_m'(\\theta_k)}{\\epsilon_{L+1}^m} = \\widetilde{P}_{L+1}^m(\\mu_k)\\sum_{j=1}^J \\dfrac{f_m(\\theta_j)w_j\\widetilde{P}_L^m(\\mu_j)}{\\mu_k - \\mu_j}   - \\widetilde{P}_{L}^m(\\mu_k)\\sum_{j=1}^J \\dfrac{f_m(\\theta_j)w_j\\widetilde{P}_{L+1}^m(\\mu_j)}{\\mu_k - \\mu_j}  \\label{cdform2}\n\\end{equation}\n\nThis has the form of a matrix-vector multiply over the kernel of type $1/(x-x')$, therefore it is possible to use the 1D FMM to accelerate this computation. \n\nWhen the sum rolls over the case $\\mu_k = \\mu_j$, L'Hopital's rule can be applied to either $\\mu_k$ or $\\mu_j$ to resolve the singularity. The condition $\\mu_k = \\mu_j$ only ever occurs at $\\mu = 0$, because the nodes of quadrature for different degrees of harmonics never overlap expect at $\\mu = 0$, and only when the number of quadrature points in $\\theta$ of both functions is odd. Assuming the number of quadrature points is equal to $L+1$ and $K+1$, this means that the rule needs to be applied when both $L$ and $K$ are even and different (when $L=K$ there is nothing to interpolate or filter). It is possible to avoid the singularity entirely by requiring that $L$ and $K$ always be odd, then $\\mu_j \\ne \\mu_k$ and the Legendre derivative are not needed, but this is too restrictive.  Applying L'Hopital's rule to $\\mu_j$ we get a version of \\eqref{cdform2} that handles the singularity\n\\ea{\n\\dfrac{f_m'(\\theta_k)}{\\epsilon_{L+1}^m}  &=&\n\\widetilde{P}_{L+1}^m(\\mu_k)\\sum_{j=1}^J f_m(\\theta_j)w_j\n\\left\\{\n\\begin{array}{cc}\n\\dfrac{\\widetilde{P}_L^m(\\mu_j)}{\\mu_k - \\mu_j} & \\mu_j \\ne \\mu_k \\\\\n-\\dfrac{d\\widetilde{P}_{L}^m(\\mu_j)}{d\\mu_j}  & \\mu_j = \\mu_k \\\\\n\\end{array} \\right. \n\\nonumber \\\\\n\\ & \\ & - \\widetilde{P}_{L}^m(\\mu_k)\\sum_{j=1}^J f_m(\\theta_j)w_j\n\\left\\{  \n\\begin{array}{cc}\n\\dfrac{\\widetilde{P}_{L+1}^m(\\mu_j)}{\\mu_k - \\mu_j} & \\mu_j \\ne \\mu_k \\\\\n-\\dfrac{d\\widetilde{P}_{L+1}^m(\\mu_j)}{d\\mu_j}  & \\mu_j = \\mu_k \\\\\n\\end{array} \\right. }\n\n\n%\n%\\begin{eqnarray}\n%\\dfrac{f_m'(\\theta_k)}{\\epsilon_{K+1}^m}  &=& \\widetilde{P}_{K+1}^m(\\mu_k)\\sum_{\\substack{j=1 \\\\ \\mu_k \\ne \\mu_j}}^J \\dfrac{f_m(\\theta_j)w_j\\widetilde{P}_K^m(\\mu_j)}{\\mu_k - \\mu_j}   - \\widetilde{P}_{K}^m(\\mu_k)\\sum_{\\substack{j=1 \\\\ \\mu_k \\ne \\mu_j}}^J \\dfrac{f_m(\\theta_j)w_j\\widetilde{P}_{K+1}^m(\\mu_j)}{\\mu_k - \\mu_j} \\nonumber \\\\\n%\\ & \\ & + \\left[\\dfrac{d\\widetilde{P}_{K+1}^m(\\mu_k)}{d\\mu_k} f_m(\\theta_j)w_j\\widetilde{P}_K^m(\\mu_k)   - \\dfrac{d\\widetilde{P}_{K}^m(\\mu_k)}{d\\mu_k}f_m(\\theta_j)w_j\\widetilde{P}_{K+1}^m(\\mu_k)\\right]_{\\mu_k = \\mu_j}\n%\\end{eqnarray}\n\n\n%\n%\\begin{equation}\n%\\begin{array}{c}\n%\\dfrac{f_m'(\\theta_k)}{\\epsilon_{L+1}^m}  =  \n%\\dfrac{d\\widetilde{P}_{L+1}^m(\\mu_k)}{d\\mu_k}\\sum_{j=1}^J f_m(\\theta_j)w_j\n%\\widetilde{P}_L^m(\\mu_j) \\left\\{  \n%\\begin{array}{cc}\n%\\dfrac{1}{\\mu_k - \\mu_j} & \\mu_j \\ne \\mu_k \\\\\n%1  & \\mu_j = \\mu_k \\\\\n%\\end{array} \\right.  \\\\\n%-\n%\\dfrac{d\\widetilde{P}_{L}^m(\\mu_k)}{d\\mu_k}\\sum_{j=1}^J f_m(\\theta_j)w_j\n%\\widetilde{P}_{L+1}^m(\\mu_j) \\left\\{  \n%\\begin{array}{cc}\n%\\dfrac{1}{\\mu_k - \\mu_j} & \\mu_j \\ne \\mu_k \\\\\n%1  & \\mu_j = \\mu_k \\\\\n%\\end{array} \\right. \\\\\n%\\end{array}\n%\\end{equation}\n%\n%%\\dfrac{f_m(\\theta_j)w_j\\widetilde{P}_K^m(\\mu_j)}{\\mu_k - \\mu_j}   - \\widetilde{P}_{K}^m(\\mu_k)\\sum_{\\substack{j=1 \\\\ \\mu_k \\ne \\mu_j}}^J \\dfrac{f_m(\\theta_j)w_j\\widetilde{P}_{K+1}^m(\\mu_j)}{\\mu_k - \\mu_j} \\nonumber \\\\\n%%\\ & \\ & + \\left[\\dfrac{d\\widetilde{P}_{K+1}^m(\\mu_k)}{d\\mu_k} f_m(\\theta_j)w_j\\widetilde{P}_K^m(\\mu_k)   - \\dfrac{d\\widetilde{P}_{K}^m(\\mu_k)}{d\\mu_k}f_m(\\theta_j)w_j\\widetilde{P}_{K+1}^m(\\mu_k)\\right]_{\\mu_k = \\mu_j}\n%%\\end{eqnarray}\n%\n%\n%%\\noindent where\n%%\n%%\\begin{equation}\n%%\\dfrac{d}{dx}\\widetilde{P}_{l}^m(x)  = -m \\dfrac{x}{1-x^2} \\widetilde{P}_{l}^m(x) + \\dfrac{\\sqrt{(l+m+1)(l-m)}}{\\sqrt{1-x^2}} \\widetilde{P}_{l}^{m+1}(x)\n%%\\end{equation}\n%%\n%%or \n%\n%%\\begin{equation}\n%%\\dfrac{d}{dx}\\widetilde P_l^m(x) = \\dfrac{1}{x^2-1}\\left( lx \\widetilde P_l^m(x) - \\sqrt{\\dfrac{(l+1/2)}{(l-1/2)}}\\sqrt{(l+m)(l-m)} \\widetilde P_{l-1}^m(x)\\right)\n%%\\end{equation}\n%\n%\n%\\begin{equation}\n%\\dfrac{f_m'(\\theta_k)}{\\epsilon_{L+1}^m}  =  \n%\\dfrac{d\\widetilde{P}_{L+1}^m(\\mu_k)}{d\\mu_k} \\sum_{j=1}^J f_m(\\theta_j)w_j \\widetilde{P}_L^m(\\mu_j) -\n%\\dfrac{d\\widetilde{P}_{L}^m(\\mu_k)}{d\\mu_k} \\sum_{j=1}^J f_m(\\theta_j)w_j\\widetilde{P}_{L+1}^m(\\mu_j), \\qquad \\mu_k = \\mu_j\n%\\end{equation}\n\nAnother way to think about the singular point, when it occurs, is to consider $1/(\\mu_k - \\mu_j)$ as a matrix that is multiplied on the right by a vector that indexes $\\mu_j$ (e.g., $f_m(\\theta_j) w_j\\widetilde P_L^m(\\mu_j)$) and multiplied element-wise on the left by a vector that indexes $\\mu_k$ (e.g., $\\widetilde P_L^m(\\mu_k)$).  Only the central matrix element needs to be adjusted, but the adjustment applies to both the matrix element and the element in the right hand vector. This makes what should be a simple matrix-vector multiply awkward to compute. We handle this by recomputing the row-vector multiplication that contains the singular point separately, but better solutions exist.  Finally, the application of L'Hopital's rule in \\cite{yucel2008helmholtz} does not appear to handle the sum over $j$ correctly, and \\cite{jakob1997fast} mentions this procedure but does not give the equations.\n\nThe above equations are for interpolation. For filtering, simply exchange the nodes and weights between $L$ and $K$. The intermediate sum will be restricted again to a maximum degree $L$, because the filtered field only has harmonics up to order $m = L$. Truncating the intermediate sum is equivalent to truncating the coefficients $f_{lm}'$ in the standard spherical filter.   \n\n\\subsubsection{Basic implementation}\n\nThe routine \\texttt{fssfilt} implements a basic version of the fast scalar spherical filter and works the same as \\texttt{ssfilt}. It expects $L \\le K$ and that the input field be sampled at the nodes of quadrature with either $I = 2L' + 1$ and $J = L' +1$ points for interpolation, or $P = 2K' +1$ and $Q = K' + 1$ points for filtering. $L'$ and $K'$ are set by the length of $\\mu_j$ and $\\mu_k$, respectively, such that $L' \\ge L$ or $K' \\ge K$.  Provisions are included for the singular point based on the values of $L'$ and $K'$. It computes the matrix-vector multiplication directly and does not implement the 1D FMM acceleration. It also computes the Legendre polynomials anew at each call, so it can be made much faster with appropriate precomputation, because only the $L$ and $L+1$ harmonics are needed. The routine returns the same result as \\texttt{ssfilt} to machine precision, and is several times faster for low number of harmonics.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/fssfilt.m}\n}\n\n%\\subsubsection{Fast implementation}\n%\n%The real speed of the fast scalar filter comes from using the 1D FMM to accelerate the matrix vector multiplication as well as precomputing the Legendre polynomials and auxiliaries of the 1D FMM.  \n\n\\clearpage\n\\section{Vector Spherical Filter}\n\\label{sec:vecsphfilter}\n\n\nIn this section, we give routines for interpolating and filtering vector spherical harmonics. Like the scalar routines, they could also stand on their own apart from the FMM. Fast versions of the vector spherical filter are also possible, either based on similar concepts of the fast scalar filter in which the forward and inverse Legendre transforms are compressed, or by using the fast scalar filter with modifications.\n \n\\subsection{Vector Spherical Harmonic Transforms}\n\nThe vector spherical harmonics form a complete basis, so any band limited vector field can be represented as sum of harmonics\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 where $F_{\\theta}(\\theta,\\phi)$ and $F_{\\phi}(\\theta,\\phi)$ are scalar spherical functions representing each vector component. In general, the vector spherical harmonics, $\\bb{B}_{lm}$ and $\\bb{C}_{lm}$, could be fully normalized or partially normalized. Eventually, the fast vector spherical filter will use the fast scalar filter and, to accommodate this, it is best to use the partially normalized vector spherical harmonics in the derivations that follow (as opposed to the fully normalized versions that include a factor of $1/\\sqrt{l(l+1)}$). The scalar functions are expanded as\n\\begin{eqnarray}\n F_{\\theta}(\\theta,\\phi) &=&  \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm}  \\dfrac{d}{d\\theta} Y_{lm}(\\theta,\\phi)   + c_{lm} \\dfrac{im}{\\sin\\theta} Y_{lm}(\\theta,\\phi) \\label{fmmFtheta} \\\\\nF_{\\phi}(\\theta,\\phi) &=&\\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm} \\dfrac{im}{\\sin\\theta} Y_{lm}(\\theta,\\phi) -c_{lm} \\dfrac{d}{d\\theta} Y_{lm}(\\theta,\\phi)    \\label{fmmFphi}\n\\end{eqnarray}\n\nwhich show the mixing of harmonics between vector components.\n\n%\\begin{eqnarray}\n% F_{\\theta}(\\theta,\\phi) &=&  \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm} \\dfrac{1}{\\sqrt{l(l+1)}} \\dfrac{d}{d\\theta} Y_{lm}(\\theta,\\phi)   + c_{lm} \\dfrac{1}{\\sqrt{l(l+1)}} \\dfrac{im}{\\sin\\theta} Y_{lm}(\\theta,\\phi)   \\nonumber \\\\\n% \\ & \\ & \\ \\\\\n%F_{\\phi}(\\theta,\\phi) &=&\\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm}  \\dfrac{1}{\\sqrt{l(l+1)}} \\dfrac{im}{\\sin\\theta} Y_{lm}(\\theta,\\phi) -c_{lm} \\dfrac{1}{\\sqrt{l(l+1)}} \\dfrac{d}{d\\theta} Y_{lm}(\\theta,\\phi)     \\nonumber \\\\\n% \\ & \\ & \\ \n%\\end{eqnarray}\n\n\nThe orthogonality relations for these partially normalized vector spherical harmonics are \n\\ea{\n\\int_0^{2\\pi} \\int_0^{\\pi}\n\\left\\{\n\\begin{array}{c}\n\\bb{B}_{lm}(\\theta,\\phi) \\cdot \\bb{B}^*_{lm}(\\theta,\\phi) \\\\\n\\bb{C}_{lm}(\\theta,\\phi) \\cdot \\bb{C}^*_{lm}(\\theta,\\phi) \n\\end{array}\n\\right\\}\n\\sin\\theta d\\theta d\\phi &=& l(l+1)\\delta_{ll'}\\delta_{mm'} \\\\\n\\int_0^{2\\pi} \\int_0^{\\pi}\n\\left\\{\n\\begin{array}{c}\n\\bb{B}_{lm}(\\theta,\\phi) \\cdot \\bb{C}^*_{lm}(\\theta,\\phi) \\end{array}\n\\right\\}\n\\sin\\theta d\\theta d\\phi &=& 0\n}\n\nGiven a vector field $\\bb{F}(\\theta,\\phi)$, the coefficients are found with\n\\begin{equation}\n\\left\\{\n\\begin{array}{c}\nb_{lm} \\\\\nc_{lm} \\\\\n\\end{array}\n\\right\\}\n=\n\\dfrac{1}{l(l+1)}\\int_0^{2\\pi} \\int_0^{\\pi}\n\\bb{F}(\\theta,\\phi) \\cdot \n\\left\\{\\begin{array}{c}\n\\bb{B}^*_{lm}(\\theta,\\phi) \\\\\n\\bb{C}^*_{lm}(\\theta,\\phi) \n\\end{array}\\right\\}\n\\sin\\theta d\\theta d\\phi \\label{vecanalysis}\n\\end{equation}\n\n\n\\subsection{Forward Vector Spherical Transform}\n\nThe forward vector spherical transform, as in the scalar case, is composed of a forward Fourier transform and forward Legendre transform.  Writing out \\eqref{vecanalysis}\n\n\\begin{eqnarray}\nb_{lm} &=& \\dfrac{1}{l(l+1)}\\int_0^{2\\pi} \\int_0^{\\pi} \\dfrac{1}{\\sqrt{2\\pi}} \\left( F_{\\theta}(\\theta,\\phi) \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta} e^{-im\\phi} \\right) \\sin\\theta d\\theta d\\phi \\nonumber \\\\\n\\ & \\ & + \\dfrac{1}{l(l+1)}\\int_0^{2\\pi} \\int_0^{\\pi} \\dfrac{1}{\\sqrt{2\\pi}} \\left( F_{\\phi}(\\theta,\\phi) \\dfrac{(-im)}{\\sin\\theta} \\widetilde{P}_l^m(\\cos\\theta) e^{-im\\phi} \\right) \\sin\\theta d\\theta d\\phi \n\\end{eqnarray}\n\n\\begin{eqnarray}\nc_{lm} &=& \\dfrac{1}{l(l+1)}\\int_0^{2\\pi} \\int_0^{\\pi} \\dfrac{1}{\\sqrt{2\\pi}} \\left( F_{\\theta}(\\theta,\\phi) \\dfrac{(-im)}{\\sin\\theta} \\widetilde{P}_l^m(\\cos\\theta) e^{-im\\phi} \\right) \\sin\\theta d\\theta d\\phi \\nonumber \\\\\n\\ & \\ & - \\dfrac{1}{l(l+1)}\\int_0^{2\\pi} \\int_0^{\\pi} \\dfrac{1}{\\sqrt{2\\pi}} \\left( F_{\\phi}(\\theta,\\phi)\\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta}  e^{-im\\phi} \\right) \\sin\\theta d\\theta d\\phi \n\\end{eqnarray}\n\nThe integrals over latitude and longitude can be separated.  Performing the $\\phi$ integral first we have \n\n\\begin{eqnarray}\n\\left\\{\n\\begin{array}{c}\nf_{\\theta,m}(\\theta) \\\\\nf_{\\phi,m}(\\theta) \\\\\n\\end{array}\n\\right\\}\n&=&\n\\dfrac{1}{\\sqrt{2\\pi}} \n\\int_0^{\\pi}\n\\left\\{\n\\begin{array}{c}\nF_{\\theta}(\\theta,\\phi) \\\\\nF_{\\phi}(\\theta,\\phi) \n\\end{array}\\right\\}\ne^{-im\\phi} d\\phi  \\\\\n\\ &=&\n\\dfrac{\\sqrt{2\\pi}}{I}\n\\sum_{i=1}^I\n\\left\\{\n\\begin{array}{c}\nF_{\\theta}(\\theta,\\phi_i) \\\\\nF_{\\phi}(\\theta,\\phi_i) \n\\end{array}\\right\\}\ne^{-im\\phi_i} \n\\end{eqnarray}\n\n\\noindent where the grid points are $\\phi_i = 2\\pi i/I$ for $i = 0,...,I-1$.  These are evaluated with a fast Fourier transform.  The coefficients are then written in terms of $f_{\\theta,m}(\\theta)$ and $f_{\\phi,m}(\\theta)$ as\n\n\\begin{eqnarray}\nb_{lm} &=& \\dfrac{1}{l(l+1)}\\int_0^{\\pi} \\left( \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta}f_{\\theta,m}(\\theta)   + \\dfrac{(-im)}{\\sin\\theta} \\widetilde{P}_l^m(\\cos\\theta) f_{\\phi,m}(\\theta)  \\right) \\sin\\theta d\\theta   \\label{blmftheta}\n\\end{eqnarray}\n\\begin{eqnarray}\nc_{lm} &=& \\dfrac{1}{l(l+1)}\\int_0^{\\pi} \\left(\\dfrac{(-im)}{\\sin\\theta} \\widetilde{P}_l^m(\\cos\\theta) f_{\\theta,m}(\\theta)   -  \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta}f_{\\phi,m}(\\theta)  \\right) \\sin\\theta d\\theta \\label{clmftheta}\n\\end{eqnarray}\n\nThe integrations are performed exactly with Gaussian quadrature after a change of variables.  The first change of variables is of the type\n\n\\begin{eqnarray}\n\\int_{0}^{\\pi} \\dfrac{1}{\\sin\\theta}f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) \\sin \\theta d \\theta & = & -\\int_{0}^{\\pi} \\dfrac{1}{\\sin\\theta} f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) d\\cos\\theta \\\\\n\\ &= & \\int_{\\pi}^{0} \\dfrac{1}{\\sqrt{1-\\cos^2\\theta}}f_m(\\theta) \\widetilde{P}_l^m(\\cos \\theta) d\\cos\\theta \\\\\n\\ & = & \\int_{-1}^{1} \\dfrac{1}{\\sqrt{1-\\mu^2}}f_m(\\theta( \\mu)) \\widetilde{P}_l^m(\\mu) d\\mu, \\quad \\mu = \\cos\\theta \n\\end{eqnarray}\n\nThe second change of variables is of the type\n\n\\begin{eqnarray}\n \\int_{0}^{\\pi} f_m(\\theta) \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta} \\sin \\theta d \\theta & = & -\\int_{0}^{\\pi} f_m(\\theta) \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta} d\\cos\\theta \\\\\n\\ &= & \\int_{\\pi}^{0} f_m(\\theta) \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta} d\\cos\\theta \\\\\n\\ &= & -\\int_{-1}^{1} \\sqrt{1-\\mu^2}f_m(\\theta(\\mu)) \\dfrac{\\partial \\widetilde{P}_l^m(\\mu)}{\\partial\\mu}d\\mu, \\quad \\mu = \\cos\\theta \n\\end{eqnarray}\n\nwhere we have used the chain rule \n\n\\[\n\\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\theta} = \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\mu}\\dfrac{\\partial\\mu}{\\partial\\theta} = \\dfrac{\\partial \\widetilde{P}_l^m(\\cos\\theta)}{\\partial\\mu} (-\\sin\\theta) = -\\sqrt{1-\\mu^2}\\dfrac{\\partial \\widetilde{P}_l^m(\\mu)}{\\partial\\mu} \\]\n\nNote, in \\cite{yucel2008helmholtz}, the equations are given in terms of $\\partial \\widetilde{P}_l^m(\\mu_j)/\\partial\\theta$ and the chain rule is not applied. The chain rule is required for the derivatives to be compatible with our computations of the Legendre derivatives.  \n\n\n%\\ & = & \\int_{-1}^{1} \\dfrac{1}{\\sqrt{1-\\mu^2}}f_m(\\theta( \\mu)) \\widetilde{P}_l^m(\\mu) d\\mu, \\quad \\mu = \\cos\\theta \n%\\end{eqnarray}\n\n\nEquations \\eqref{blmftheta} and \\eqref{clmftheta} can now be evaluated via Gaussian quadrature on the interval $\\mu = [-1, 1]$ as \n\\begin{eqnarray}\nb_{lm} &=& \\dfrac{1}{l(l+1)}\\sum_{j=1}^J \\left( \\left(-\\sqrt{1-\\mu_j^2}\\right)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu}f_{\\theta,m}(\\theta_j)   + \\dfrac{(-im)}{\\sqrt{1-\\mu_j^2}} \\widetilde{P}_l^m(\\mu_j) f_{\\phi,m}(\\theta_j)  \\right) w_j  \\nonumber \\\\\n\\ & \\ & \\label{eqblm1}\n\\end{eqnarray}\n\\begin{eqnarray}\nc_{lm} &=& \\dfrac{1}{l(l+1)}\\sum_{j=1}^J \\left( \\dfrac{(-im)}{\\sqrt{1-\\mu_j^2}} \\widetilde{P}_l^m(\\mu_j) f_{\\theta,m}(\\theta_j)   -  \\left(-\\sqrt{1-\\mu_j^2}\\right)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu} f_{\\phi,m}(\\theta_j)  \\right) w_j \\nonumber \\\\\n\\ & \\ & \\label{eqclm1}\n\\end{eqnarray}\n\n\\noindent where $J$ is the number of integration points in longitude with weights $w_j$ and Gaussian nodes $\\mu_j = \\cos\\theta_j$.  \n\n%In the computation, we need an extra factor of $(-1)^m$ to be consistent with our definitions of $ \\bb{B}_{lm}(\\theta,\\phi)$ and $\\bb{C}_{lm}(\\theta,\\phi)$, which we didn't show in the derivations above.\n\nThe routine \\texttt{vst} takes as input the scalar functions $F_{\\theta}(\\theta,\\phi)$ and $F_{\\phi}(\\theta,\\phi)$ sampled such that the number of rows is $I = 2L+1$ and number of columns is $J = L+1$ sampled at the points of quadrature.  It returns the expansion coefficients $b_{lm}$ and $c_{lm}$ linearly indexed. It is otherwise similar in form to the routine for the scalar spherical transform, \\texttt{sst}, except that there is no monopole component.  The routine defaults to the partially normalized vector spherical harmonics as derived above. For fully normalized harmonics, use optional string switch \\texttt{norm} that will use a factor of $1/\\sqrt{l (l+1)}$, and \\texttt{none} for no factors of $l$.  The Legendre polynomials can be optionally precomputed for repeated application over fields of the same sampling.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/vst.m}\n}\n\n\n\n\\subsection{Inverse Vector Spherical Transform}\n\nGiven coefficients $b_{lm}$ and $c_{lm}$ the inverse vector spherical transform is computed by first applying the inverse Legendre transform then an inverse Fourier transform.  Note, the factor of $l(l+1)$ is not needed for partially normalized vector spherical wave functions.\n\n\\begin{eqnarray}\nf_{\\theta,m}(\\theta_j) &=& \\sum_{l=\\vert m \\vert }^L b_{lm} \\left(-\\sqrt{1-\\mu_j^2}\\right)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu} + c_{lm}  \\dfrac{im}{\\sqrt{1-\\mu_j^2}} \\widetilde{P}_l^m(\\mu_j) \\label{eqfthj}\\\\\nf_{\\phi,m}(\\theta_j) &=& \\sum_{l=\\vert m \\vert }^L b_{lm}  \\dfrac{im}{\\sqrt{1-\\mu_j^2}} \\widetilde{P}_l^m(\\mu_j) - c_{lm} \\left(-\\sqrt{1-\\mu_j^2}\\right)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu} \n\\label{eqphij}\n\\end{eqnarray}\n\nAgain, the Gaussian nodes are $\\mu_j = \\cos\\theta_j$.  The inverse Fourier transform of $f_{\\theta,m}(\\theta_j)$ and $f_{\\phi,m}(\\theta_j)$ in $\\phi$ then gives\n\n\\begin{equation}\n\\left\\{\n\\begin{array}{c}\nF_{\\theta}(\\theta_j,\\phi_i)\\\\\nF_{\\phi}(\\theta_j,\\phi_i) \\\\\n\\end{array}\n\\right\\}\n=\n\\dfrac{1}{\\sqrt{2\\pi}}\n\\sum_{m=-L}^L\n\\left\\{\\begin{array}{c}\nf_{\\theta,m}(\\theta_j) \\\\\nf_{\\phi,m}(\\theta_j) \n\\end{array}\\right\\}\ne^{im\\phi_i}\n\\end{equation}\n\nThe routine \\texttt{ivst} computes the inverse vector spherical transform given coefficients $b_{lm}$ and $c_{lm}$.  It returns the vector field components $F_{\\theta}(\\theta,\\phi)$ and $F_{\\phi}(\\theta,\\phi)$. The coefficients matrices contain all harmonics up through $L$ all $m$ and must be length $L^2 + 2L$. There has to be at least $I = 2L+1$ sampling points in $\\phi$ and at least $J = L+1$ nodes of quadrature in $\\theta$, which is determined from the length of the input $\\mu_j$. Like \\texttt{isst}, this allows the routine to performs interpolation automatically onto a grid that is sampled for a harmonic degree larger than $L$. The routine defaults to the partially normalized vector spherical harmonics. For fully normalized harmonics, use optional string switch \\texttt{norm} to include a factor of $1/\\sqrt{l (l+1)}$. The Legendre polynomials can be optionally precomputed for repeated application over fields of the same sampling.\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/ivst.m}\n}\n\n\n\\subsection{Vector Spherical Filter}\n\nThe routine \\texttt{vsfilt} is a straight forward implementation of the vector spherical filter.  It works like the scalar spherical filter, \\texttt{ssfilt}, to accomplish vector spherical interpolation or filtering  by zero padding or truncating the expansion coefficients. It takes as input the maximum degrees of the harmonic content $L$ and $K$, where $L \\le K$ on either side of the transforms. However, the sampling can be greater than the requested degree of harmonic when interpolating or filtering as long as $L\\le L'$ and $K\\le K'$.  For interpolation, the input functions are $F_{\\theta}(\\theta,\\phi)$ and $F_{\\phi}(\\theta,\\phi)$, which are both sized $I \\times J = 2L'+1 \\times L' + 1$ on a meshgrid. It returns $F_{\\theta}(\\theta',\\phi')$ and $F_{\\phi}(\\theta',\\phi')$, which are both sized $P \\times Q = 2K'+1 \\times K'+1$. Visa-versa for filtering. The routine decides to interpolate or filter based on the size of the input functions and lengths of $\\mu_j$ and $\\mu_k$. This routine calls \\texttt{vst} and \\texttt{ivst} sequentially, which means that the spherical harmonics normalization does not matter, so the default is to use partially normalized vector spherical harmonics. \n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/vsfilt.m}\n}\n\n\n\\subsection{Fast Vector Spherical Filter}\n\nLike in the scalar spherical filter, the vector spherical transforms above are bogged down by the Legendre transforms.  There are two methods for accelerating the computation.  \n\nThe first method is similar to the fast scalar spherical filter where the forward vector transform is substituted into the inverse vector transform. This results in sums of mixed products of Legendre polynomial and Legendre polynomial derivatives that look like they should be simplified with Christoffel-Darboux formulas, but expressions for simplifying the mixed terms have not been found to the best of our knowledge. This means that the 1D FMM speed up is not available. However, the sums can be precomputed, then the computation carried out with matrix-vector multiplication will be easy to implement and pretty fast. \n\nThe second method is the one that is recommended throughout the literature. Interpolation/filtering is accomplished by applying the fast scalar filter to each scalar field component of the vector field. The complication comes from the fact that the vector spherical harmonics contain derivatives of the Legendre polynomial. As a result, correction terms are needed for the harmonics at the edge of the spectrum of the field that is being interpolated or filtered. Finally, we find that method 1 and method 2 agree to machine precision with the previous routines. \n\n\\subsubsection{Method 1 - Precomputed Matrix-Vector Multiply}\nSimilar to the fast scalar spherical filter, we can derive a fast vector interpolation and filter procedure by substituting the forward vector transform into inverse vector transform.  Defining the following terms \\begin{eqnarray}\na_j &=& -\\sqrt{1-\\mu_j^2} \\\\\nb_j &=& \\dfrac{-i}{\\sqrt{1-\\mu_j^2}} = \\dfrac{i}{a_j} \n\\end{eqnarray}\n\nthen \\eqref{eqblm1} and \\eqref{eqclm1} can be written\n\\begin{eqnarray}\nb_{lm} &=& \\dfrac{1}{l(l+1)}\\sum_{j=1}^J \\left( a_j\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu}f_{\\theta,m}(\\theta_j)   + m b_j \\widetilde{P}_l^m(\\mu_j) f_{\\phi,m}(\\theta_j)  \\right) w_j  \\label{meth11} \\\\\nc_{lm} &=& \\dfrac{1}{l(l+1)}\\sum_{j=1}^J \\left( m b_j\\widetilde{P}_l^m(\\mu_j) f_{\\theta,m}(\\theta_j)   +  (-a_j)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu} f_{\\phi,m}(\\theta_j)  \\right) w_j \\label{meth12}\n\\end{eqnarray}\n\nSimilar to the fast scalar operation, the sum over $l$ in the inversion transform only goes up to a maximum harmonic $L$.  If we are interpolating, this is the maximum degree harmonic of the coarsely sampled field (all coefficients $b_{lm}$ and $c_{lm}$ greater than $L$ are zero).  When filtering, the harmonic coefficients are truncated to harmonics $L$. In both cases, the limit of the sum is the same, all that changes is the coarse/fine sampling of either field. Letting the $\\theta$ samples of the resultant field be indexed by $k$, equations \\eqref{eqfthj} and \\eqref{eqphij} are first written more compactly as \n\\begin{eqnarray}\nf_{\\theta,m}(\\theta_k) &=& \\sum_{l=\\vert m \\vert }^L b_{lm} a_k \\dfrac{\\partial \\widetilde{P}_l^m(\\mu_k)}{\\partial\\mu} + c_{lm}  m(-b_k) \\widetilde{P}_l^m(\\mu_k) \\label{fvsfiltf1} \\\\\nf_{\\phi,m}(\\theta_k) &=& \\sum_{l=\\vert m \\vert }^L b_{lm}  m(-b_k) \\widetilde{P}_l^m(\\mu_k) + c_{lm}(-a_k)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_k)}{\\partial\\mu} \\label{fvsfiltf2}\n\\end{eqnarray}\n\nAfter substituting \\eqref{meth11} and \\eqref{meth12} into \\eqref{fvsfiltf1} and \\eqref{fvsfiltf2}, exchanging the order of summation, and collecting terms we can write the combined Legendre transforms as \n\\begin{eqnarray}\nf_{\\theta,m}(\\theta_k) &=& \\sum_{j=1}^J f_{\\theta,m}(\\theta_j) A_m(\\mu_j,\\mu_k)  + f_{\\phi,m}(\\theta_j)  B_m(\\mu_j,\\mu_k) \\label{ftmkmat} \\\\\nf_{\\phi,m}(\\theta_k) &=& \\sum_{j=1}^J - f_{\\theta,m}(\\theta_j) B_m(\\mu_j,\\mu_k)  + f_{\\phi,m}(\\theta_j)A_m(\\mu_j,\\mu_k) \\label{fpmkmat}\n\\end{eqnarray}\n\nwhere \n\\begin{eqnarray}\nA_m(\\mu_j,\\mu_k)  &=& w_j a_j a_k M_{1,m}(\\mu_j,\\mu_k) - w_j b_jb_k m^2 M_{2,m}(\\mu_j,\\mu_k)   \\\\\nB_m(\\mu_j,\\mu_k)  &=& w_j b_j a_k m M_{3,m}(\\mu_j,\\mu_k) + w_j a_jb_k m M_{4,m}(\\mu_j,\\mu_k) \n%C_m(\\mu_j,\\mu_k)  &=& w_j a_j (-b_k)m M_{4,m}(\\mu_j,\\mu_k) + w_j b_j(-a_k) m M_{3,m}(\\mu_j,\\mu_k)\\nonumber \n%D_m(\\mu_j,\\mu_k)  &=& w_j b_j (-b_k) m^2 M_{2,m}(\\mu_j,\\mu_k) + w_j (-a_j)(-a_k) M_{1,m}(\\mu_j,\\mu_k)\\nonumber\n\\end{eqnarray}\n\nand\n\n\\begin{eqnarray}\nM_{1,m}(\\mu_j,\\mu_k) &=& \\sum_{l=\\vert m \\vert }^L \\dfrac{1}{l(l+1)} \\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu}\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_k)}{\\partial\\mu}  \\\\\nM_{2,m}(\\mu_j,\\mu_k)  &=& \\sum_{l=\\vert m \\vert }^L \\dfrac{1}{l(l+1)} \\widetilde{P}_l^m(\\mu_j)\\widetilde{P}_l^m(\\mu_k)  \\\\\nM_{3,m}(\\mu_j,\\mu_k)  &=& \\sum_{l=\\vert m \\vert }^L \\dfrac{1}{l(l+1)} \\widetilde{P}_l^m(\\mu_j)\\dfrac{\\partial \\widetilde{P}_l^m(\\mu_k)}{\\partial\\mu}  \\\\\nM_{4,m}(\\mu_j,\\mu_k)  &=& \\sum_{l=\\vert m \\vert }^L \\dfrac{1}{l(l+1)} \\dfrac{\\partial \\widetilde{P}_l^m(\\mu_j)}{\\partial\\mu} \\widetilde{P}_l^m(\\mu_k) \n\\end{eqnarray}\n\nIn the fast scalar operator, the Christoffel-Darboux formula was used to simplify the sums over $l$ and yield an expression that can be accelerated with the 1D FMM.  Similar formulas for the above expressions have not been found.  Regardless, the matrices $A_m(\\mu_j,\\mu_k) $, $B_m(\\mu_j,\\mu_k) $ can be precomputed and \\eqref{ftmkmat} and \\eqref{fpmkmat} can be computed as matrix-vector multiplication. After which, $f_{\\theta,m}(\\theta_k)$ and $f_{\\phi,m}(\\theta_k)$ are computed and then the inverse Fourier transform over $m$ completes the filter.\n\nThe routine \\texttt{fvsfilt1} implements the fast vector spherical filter using the matrix-multiplication method above. It detects whether to interpolate or filter based on the size of the input fields, which need to be sampled at the nodes of quadrature consistent with $L$ and $K$.  It uses \\texttt{fvsfilt1AmBm} to precompute the matrices $A_m(\\mu_j,\\mu_k) $, $B_m(\\mu_j,\\mu_k)$, which take as input just $L$ and $K$, where one is either interpolating from $L$ harmonics to $K$, of filtering from $K$ harmonics down to $L$. Use string switch \\texttt{'interp'} or \\texttt{'filter'} for interpolation or filter. A handy trick is that the same basic computation of the matrices applies no matter if one is interpolating or filtering, one simply swaps the sample points and nodes and weights of quadrature. The indexing then also needs to swap. The intermediate sums always only go to $L$, which is again the equivalent of zero padding the spherical harmonic expansion coefficients when interpolating or truncating when filtering. The routine returns the same result as \\texttt{vsfilt} to machine precision. With precomputation, it is faster than \\texttt{vsfilt} and becomes progressively faster as the number of harmonics increases.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/fvsfilt1.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/fvsfilt1AmBm.m}\n}\n\n\n\n\\subsubsection{Method 2 - Fast Scalar Filter with Correction Terms}\n\n\nThe fast scalar filter cannot simply be applied to each scalar component of the vector fields. This is because the vector spherical harmonics contain derivatives of the Legendre polynomials, which are themselves composed of Legendre polynomials at harmonic degrees one above and one below the harmonic degree of the derivative. The fast scalar filter meanwhile a) only operates on spherical harmonics that contain non-differentiated Legendre polynomials, and b) only operates up to the highest degree in the spectrum and no more. If we want to filter the scalar components of the vector field to degree $L$, the fast scalar filter will only be accurate for harmonic degrees less than or equal to $L-1$. There is still a way to use the fast scalar filter up to degree $L$, but correction terms are needed to account for the Legendre derivatives that straddle the harmonic cutoff.\n\nThe approach is to rewrite the expressions for the vector spherical harmonic expansions in terms of purely scalar spherical harmonics. This results in a handful of leftover terms which are collected to create the needed correction terms. The correction terms in \\cite{yucel2008helmholtz} appear to have errors, and those given in \\cite{shanker2003fast} are not for normalized Legendre polynomials, so we rederive the correction terms here.  \n\nIn a few places in the literature it is stated that the correction terms are only needed when filtering. The reasoning goes that when a field is interpolated there is no harmonic content above degree $L$, so the correction terms are not needed. However, when the Legendre derivatives are split into pure Legendre polynomials, the harmonics straddle the band edge regardless of whether a field is interpolated or filtered. We found that the correction terms are still required when interpolating in order to give the same results as our previous vector spherical filter routines.\n\n\n\\paragraph{Legendre Derivative Relations:}\n\nThe first step is to express the derivative of the Legendre polynomial (the $d/d\\theta$ version) as a linear combination of Legendre polynomials.  Start with the following two identities for unnormalized Legendre polynomials:\n\\begin{eqnarray}\n(2l+1)\\cos\\theta P_l^m(\\cos\\theta) &=& (l+m)P_{l-1}^m(\\cos\\theta) + (l-m+1)P_{l+1}^m(\\cos\\theta) \\label{legrelfmm1} \\\\\n\\sin\\theta \\dfrac{dP_l^m(\\cos\\theta)}{d\\theta} &=& l\\cos\\theta P_l^m(\\cos\\theta) - (l+m)P_{l-1}^m(\\cos\\theta) \\label{legrelfmm2} \n\\end{eqnarray}\n\nSubstituting \\eqref{legrelfmm1} into \\eqref{legrelfmm2} it can be shown that\n\\begin{equation}\n\\sin\\theta \\dfrac{dP_l^m(\\cos\\theta)}{d\\theta}  = \\dfrac{l(l-m+1)}{2l+1}P_{l+1}^m(\\cos\\theta) - \\dfrac{(l+m)(l+1)}{2l+1}P_{l-1}^m(\\cos\\theta)\n\\end{equation}\n\nMultiply both sides by the normalization factor of the normalized Legendre polynomials\n\\begin{eqnarray}\n\\sqrt{(l + 1/2)\\dfrac{(l-m)!}{(l+m)!}}\\sin\\theta \\dfrac{dP_l^m(\\cos\\theta)}{d\\theta} & =& \\sqrt{(l + 1/2)\\dfrac{(l-m)!}{(l+m)!}}\\dfrac{l(l-m+1)}{2l+1}P_{l+1}^m(\\cos\\theta) \\nonumber \\\\ \n\\ & \\  & - \\sqrt{(l + 1/2)\\dfrac{(l-m)!}{(l+m)!}}\\dfrac{(l+m)(l+1)}{2l+1}P_{l-1}^m(\\cos\\theta) \\nonumber \\\\\n\\end{eqnarray}\n\nFinally, multiply the $l+1$ and $l-1$ polynomials by appropriate factors in order to apply the definition of the normalized Legendre polynomials, then simplify to get\n\\begin{eqnarray}\n\\sin\\theta \\dfrac{d \\widetilde P_l^m(\\cos\\theta)}{d\\theta} & =& \\sqrt{\\dfrac{(l + 1/2)(l+1+m)}{(l+3/2)(l+1-m)}}\\dfrac{l(l-m+1)}{2l+1}\\widetilde P_{l+1}^m(\\cos\\theta) \\nonumber \\\\ \n\\ & \\  & - \\sqrt{\\dfrac{(l + 1/2)(l-m)}{(l-1/2)(l+m)}}\\dfrac{(l+m)(l+1)}{2l+1}\\widetilde P_{l-1}^m(\\cos\\theta) \\label{sinthetadPlmtheta}\n\\end{eqnarray}\n\n\\paragraph{$F_{\\theta}(\\theta,\\phi)$ Component:}\n\nConsider the $\\theta$ component, \\eqref{fmmFtheta}, after multiplication by $\\sin\\theta$.  \n\\begin{equation}\n\\sin\\theta F_{\\theta}(\\theta,\\phi) =  \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm}  \\sin\\theta\\dfrac{d}{d\\theta} Y_{lm}(\\theta,\\phi)   + c_{lm} (im)  Y_{lm}(\\theta,\\phi)  \n\\end{equation}\n\nSubstituting \\eqref{sinthetadPlmtheta}, this can be written in terms of pure spherical harmonics as\n\\begin{eqnarray}\n\\sin\\theta F_{\\theta}(\\theta,\\phi) &=& \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm} h_1(l,m) Y_{l+1,m}(\\theta,\\phi) \\nonumber \\\\\n\\ & \\ & - \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm} h_2(l,m) Y_{l-1,m} (\\theta,\\phi) \\nonumber \\\\\n\\ & \\  & + \\sum_{l=1}^{L} \\sum_{m = -l}^{l} c_{lm}  h_3(l,m)Y_{l,m}(\\theta,\\phi)\n\\end{eqnarray}\n\n\\noindent where\n\\begin{eqnarray}\nh_1(l,m) &=&  \\sqrt{\\dfrac{(l + 1/2)(l+1+m)}{(l+3/2)(l+1-m)}}\\dfrac{l(l-m+1)}{2l+1} \\\\\nh_2(l,m) &=& \\sqrt{\\dfrac{(l + 1/2)(l-m)}{(l-1/2)(l+m)}}\\dfrac{(l+m)(l+1)}{2l+1} \\\\ \nh_3(l,m) &=& im\n\\end{eqnarray}\n\nNext, let $L$ be the highest harmonic we are interpolating from (up to $K$) or the highest harmonic we are filtering to (down from $K$) to create the scalar function $\\widetilde F_{\\theta}(\\theta',\\phi')$ at the new sampling.  Then for each sum in turn, make the following substitutions respectively: $l+1 \\rightarrow l $, $l-1 \\rightarrow l $, and $l \\rightarrow l$ so that the spherical harmonics have the same indices\n\\begin{eqnarray}\n\\sin\\theta' \\widetilde F_{\\theta}(\\theta',\\phi') &=& \\sum_{l=2}^{L+1} \\sum_{m = -(l-1)}^{(l-1)} \\widetilde b_{l-1,m} h_1(l-1,m) Y_{lm}(\\theta',\\phi') \\nonumber \\\\\n\\ & \\ & - \\sum_{l=0}^{L-1} \\sum_{m = -(l+1)}^{(l+1)} \\widetilde b_{l+1,m} h_2(l+1,m) Y_{lm} (\\theta',\\phi') \\nonumber \\\\\n\\ & \\  & + \\sum_{l=1}^{L} \\sum_{m = -l}^{l} \\widetilde c_{lm} h_3(l,m) Y_{lm}(\\theta',\\phi')\n\\end{eqnarray}\n\n%\\begin{eqnarray}\n%\\sin\\theta' \\widetilde F_{\\theta}(\\theta',\\phi') &=& \\sum_{k=2}^{K+1} \\sum_{m = -(k-1)}^{(k-1)} \\widetilde b_{k-1,m} h_1(k-1,m) Y_{km}(\\theta',\\phi') \\nonumber \\\\\n%\\ & \\ & - \\sum_{k=0}^{K-1} \\sum_{m = -(k+1)}^{(k+1)} \\widetilde b_{k+1,m} h_2(k+1,m) Y_{km} (\\theta',\\phi') \\nonumber \\\\\n%\\ & \\  & + \\sum_{k=1}^{K} \\sum_{m = -k}^{k} \\widetilde c_{km} h_3(k,m) Y_{km}(\\theta',\\phi')\n%\\end{eqnarray}\n\nSpin out the terms $L$ and $L+1$ and collect the sums over $l$ (the same expression in \\cite{yucel2008helmholtz} does not appear to be correct, while the one in \\cite{shanker2003fast} does)\n\\begin{eqnarray}\n\\sin\\theta' \\widetilde F_{\\theta}(\\theta',\\phi') &=& \\sum_{l=0}^{L-1} \\sum_{m = -l}^l \\widetilde d_{l,m} Y_{lm}(\\theta',\\phi') \\nonumber \\\\\n\\ & \\ &  + \\sum_{m = -L}^{L} \\widetilde e_{L,m} Y_{Lm} (\\theta',\\phi') \\nonumber \\\\\n\\ & \\  & + \\sum_{m = -L}^{L} \\widetilde e_{L+1,m} Y_{L+1,m}(\\theta',\\phi')\n\\end{eqnarray}\n\n%\\begin{eqnarray}\n%\\sin\\theta' \\widetilde F_{\\theta}(\\theta',\\phi') &=& \\sum_{k=0}^{K-1} \\sum_{m = -k}^k \\widetilde d_{k,m} Y_{km}(\\theta',\\phi') \\nonumber \\\\\n%\\ & \\ &  + \\sum_{m = -K}^{K} \\widetilde e_{K,m} Y_{Km} (\\theta',\\phi') \\nonumber \\\\\n%\\ & \\  & + \\sum_{m = -K}^{K} \\widetilde e_{K+1,m} Y_{K+1,m}(\\theta',\\phi')\n%\\end{eqnarray}\n\nwhere\n\\begin{eqnarray}\n\\widetilde d_{l,m} & = & \\widetilde b_{l-1,m}h_1(l-1,m) - \\widetilde b_{l+1,m}h_2(l+1,m) + \\widetilde c_{l,m}h_3(l,m)  \\\\\n\\widetilde e_{L,m} & = & \\widetilde b_{L-1,m}h_1(L-1,m) + \\widetilde c_{L,m} h_3(L,m)  \\label{correct1} \\\\\n\\widetilde e_{L+1,m} & = & \\widetilde b_{L,m}h_1(L,m) \\label{correct2}\n\\end{eqnarray}\n\n%\\begin{eqnarray}\n%\\widetilde d_{k,m} & = & \\widetilde b_{k-1,m}h_1(k-1,m) - \\widetilde b_{k+1,m}h_2(k+1,m) + \\widetilde c_{k,m}h_3(k,m)  \\\\\n%\\widetilde e_{K,m} & = & \\widetilde b_{K-1,m}h_1(K-1,m) + \\widetilde c_{K,m} h_3(K,m)  \\label{correct1} \\\\\n%\\widetilde e_{K+1,m} & = & \\widetilde b_{K,m}h_1(K,m) \\label{correct2}\n%\\end{eqnarray}\n\n\\paragraph{$F_{\\phi}(\\theta,\\phi)$ Component:}\n\nThe $\\phi$ component, \\eqref{fmmFphi}, after multiplication by $\\sin\\theta$, is\n\\begin{equation}\n\\sin\\theta F_{\\phi}(\\theta,\\phi) = \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm}   im Y_{lm}(\\theta,\\phi) -c_{lm} \\sin\\theta\\dfrac{d}{d\\theta} Y_{lm}(\\theta,\\phi)   \n\\end{equation}\n\nThis is structurally similar to the $\\theta$ component.  Making the change $b_{lm} \\rightarrow -c_{lm}$ and $c_{lm} \\rightarrow b_{lm}$ in the above derivation we can immediately write \n\\begin{eqnarray}\n\\sin\\theta' \\widetilde F_{\\phi}(\\theta',\\phi') &=& \\sum_{l=0}^{L-1} \\sum_{m = -l}^l \\widetilde f_{l,m} Y_{lm}(\\theta',\\phi') \\nonumber \\\\\n\\ & \\ &  + \\sum_{m = -L}^{L} \\widetilde g_{L,m} Y_{Lm} (\\theta',\\phi') \\nonumber \\\\\n\\ & \\  & + \\sum_{m = -L}^{L} \\widetilde g_{L+1,m} Y_{L+1,m}(\\theta',\\phi')\n\\end{eqnarray}\n\n%\\begin{eqnarray}\n%\\sin\\theta' \\widetilde F_{\\phi}(\\theta',\\phi') &=& \\sum_{k=0}^{K-1} \\sum_{m = -k}^k \\widetilde f_{k,m} Y_{km}(\\theta',\\phi') \\nonumber \\\\\n%\\ & \\ &  + \\sum_{m = -K}^{K} \\widetilde g_{K,m} Y_{Km} (\\theta',\\phi') \\nonumber \\\\\n%\\ & \\  & + \\sum_{m = -K}^{K} \\widetilde g_{K+1,m} Y_{K+1,m}(\\theta',\\phi')\n%\\end{eqnarray}\n\n\nwhere\n\\begin{eqnarray}\n\\widetilde f_{l,m} & = & -\\widetilde c_{l-1,m}h_1(l-1,m) + \\widetilde c_{l+1,m}h_2(l+1,m) + \\widetilde b_{l,m}h_3(l,m)   \\\\\n\\widetilde g_{L,m} & = & -\\widetilde c_{L-1,m}h_1(L-1,m) + \\widetilde b_{L,m} h_3(L,m)  \\label{correct3} \\\\\n\\widetilde g_{L+1,m} & = & -\\widetilde c_{L,m}h_1(L,m) \\label{correct4}\n\\end{eqnarray}\n\n%\\begin{eqnarray}\n%\\widetilde f_{k,m} & = & -\\widetilde c_{k-1,m}h_1(k-1,m) + \\widetilde c_{k+1,m}h_2(k+1,m) + \\widetilde b_{k,m}h_3(k,m)   \\\\\n%\\widetilde g_{K,m} & = & -\\widetilde c_{K-1,m}h_1(K-1,m) + \\widetilde b_{K,m} h_3(K,m)  \\label{correct3} \\\\\n%\\widetilde g_{K+1,m} & = & -\\widetilde c_{K,m}h_1(K,m) \\label{correct4}\n%\\end{eqnarray}\n\n(a minus sign is missing in \\cite{yucel2008helmholtz})\n\n\\paragraph{Summary:}\n\nDespite the complications, the manipulations have so far been exact.  This implies that the first summation is the result obtained by applying the scalar filter directly to the vector field component up to degree $L-1$.  The second and third sums correct the effects of the Legendre polynomials derivatives at the highest harmonic of the truncation.  Thus the fast scalar filter can be applied to obtain the field contribution from harmonics $l = 1,..,L-1$, while the correction terms at $L$ and $L+1$ are summed directly.  The coefficients $\\widetilde d_{l,m}$ and $\\widetilde f_{l,m}$ are never actually computed, and neither is $h_2(l,m)$. \n\nIn \\cite{yucel2008helmholtz} it is stated that the signal being filtered must be sampled on a grid one degree higher, because the field actually contains information at $L+1$, so that the number of $(\\theta,\\phi)$ evaluation points needs to correspond to degree $L+1$.  However, we found this sampling requirement not be the case. Rather, the scalar filter can be applied up to degree $L-1$ on a grid sampled for $L$.  The scalar filter could also be applied up to degree $L$, then the correction terms need to occur at $L+1$ and $L+2$.  \n\nNote that the scalar field components are first multiplied by $\\sin\\theta$ before applying the fast scalar filter, then the filtered result is divided by $\\sin\\theta'$. The correction terms are simply divided by $\\sin\\theta'$ before being summed. We never divide by zero, because the Gaussian nodes never sample the poles.    \n\n\\paragraph{Routine:} \nThe routine \\texttt{fvsfilt2} is a non-optimized implementation of the algorithm above, and written only to show that these equations work. The inputs and outputs are the same as \\texttt{vsfilt}. The routine calls the fast scalar filter routine \\texttt{fssfilt} to interpolate from, or filter to, harmonics at $L-1$ (at the time of this writing, that routine was not optimized). Next, the routine \\texttt{vst} is used to compute all the vector spherical harmonic expansion coefficients up to $L$ of the input fields, even though only degrees $L-1$ and $L$ are needed. It then computes and applies the correction terms, and sums the spherical harmonics at $L$ and $L+1$ directly which are computed from \\texttt{sphericalY}. The results match \\texttt{vsfilt} and \\texttt{fvsfilt1} with an accuracy slightly less than machine precision.\n\nThis implementation is inefficient because each of the subroutines compute all of the Legendre polynomials anew at each call. However, the fast scalar filter and the correction terms only need Legendre polynomials at degrees $L-2$, $L-1$, $L$, and $L+1$. The proper way to implement this is to precompute the Legendre polynomials and derivatives for these harmonics, which are then used for in-line implementations of the fast scalar filter and the combined forward and inverse Legendre transforms.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/SphericalFilters/fvsfilt2.m}\n}\n\n\n\n\n%A slow version of these equations are implemented in \\texttt{vstfilterbasic}.  \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/vstfilterbasic.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/vecfiltcorr.m}\n%}\n%\n%\\subsection{Local Field Interpolation}\n%\n%In general, there are two approaches to the interpolation/filter step: global methods, and local methods.  We have so far used a global method for interpolation and filtering.  Global methods are exact to machine precession and can be computed at best with $O(L^2 \\log L)$ speed.  Local methods, on the other hand, interpolate the field locally to accomplish both the interpolation and filtering step and cost $O(L)$.  \n%\n%In \\cite{}, Legrange interpolation is used to interpolate and filter the far field pattern in two dimensions.  Legrange interpolation is exact for polynomials less than a certain degree.  On a 2D grid with $2p \\times 2p$ stencil, this is given by \n%\n%\\begin{equation}\n%f(\\theta,\\phi) \\approx \\sum_{j=s+1-p}^{s+p} w_j(\\phi) \\sum_{i=t+1-p}^{t+p} v_i(\\theta)f(\\theta_i,\\phi_j)\n%\\end{equation}\n%\n%\\noindent where $w_j(\\phi)$ and $v_i(\\theta)$ are the interpolation weights given by\n%\n%\\begin{equation}\n%w_j(\\phi) = \\prod_{\\substack{m=s+1-p \\\\ m \\neq j}}^{s+p} \\dfrac{\\phi-\\phi_m}{\\phi_j - \\phi_m} \n%\\end{equation}\n%\n%\\begin{equation}\n%v_i(\\theta) = \\prod_{\\substack{n=t+1-p \\\\ n \\neq i}}^{t+p} \\dfrac{\\theta-\\theta_n}{\\theta_i - \\theta_n} \n%\\end{equation}\n%\n%It was reported in \\cite{} that the local interpolation method was accurate to three digits.  We tried this, and found that Legrange interpolation is exact for scalar field harmonics when $m$ is even, while harmonics when $m$ is odd could only be interpolated to three digits.  The reason for this is because the associated Legendre polynomials with $m$ even are simple polynomials, while $m$ odd contain a factor of $\\sqrt{1-x^2}$, which is not a polynomial (or is with an infinite number of terms).  Therefore the error when interpolating fields composed of spherical harmonics comes not from the Legrange interpolation but the fact that $m$ odd have a non-polynomial factor.  This cannot be changed or improved.  Thus, we stick with the global interpolation methods.\n%\n%\n%\\newpage \n%\\section{Storage}\n%\n%The extended bandwidth formula of the minimum degree $L$ given the translation operator precision and group dimension is \n%\n%\\begin{eqnarray}\n%L &\\approx& kd + 1.8 \\alpha^{2/3}\\left(kd\\right)^{1/3} \\\\\n%\\alpha &=& \\log_{10}(1/\\epsilon) \n%\\end{eqnarray}\n%\n%The number of elements required to store a scalar field is \n%\n%\\begin{equation}\n%N = (2L+1)(L+1) = 2L^2 + 3L + 1\n%\\end{equation}\n%\n%Assuming the field is composed of 16 byte complex values the number bytes required to store a scalar field is $B = 16N$.  The following figures show $L$ and $B$ versus group dimension and translation precision.\n%\n% \\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=3.5in]{FastMultipoleMethod/digvsL} \n%   \\caption{}\n%   \\label{fig7}\n%\\end{figure}\n%\n% \\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=3.5in]{FastMultipoleMethod/storgvsL} \n%   \\caption{}\n%   \\label{fig8}\n%\\end{figure}\n%\n%\\newpage\n% \n%\\section{FMM Structure}\n%\n%The box hierarchy is structured as regular octree with $N_{levs}$ levels.  The top is level 1, the lowest is $N_{levs}$.  The number of harmonics at each level, and thus the sampling, are determine by the dimension of the boxes at that level, the bandwidth formula, and the precision of translation between boxes at that level.  Interpolation and filtering operations do not depend on the location of the boxes, so the Legendre polynomials only have to be computed and stored per level transition and are good for the entire domain.  However, each unique translation matrix must be precomputed. \n%We require $L$ to be odd to have an even number of latitude points.  This ensures that latitudes points between levels do not coincide, which avoids the singularity in the core filter operation.  \n%\n%\n%\n%\n%\\subsection{Level Properties}\n%\n%The properties at each level are \n%\n%\\begin{table}[H]\n%\\caption{Properties of each level}\n%\\begin{center}\n%\\begin{tabular}{|c|c|}\n%\\hline\n%Box edge dimension & $d$ \\\\\n%\\hline\n%Maximum degree harmonic & $L$\\\\\n%\\hline\n%Number of $\\phi$ samples & $I = 2L + 1$ \\\\\n%\\hline\n%Number $\\theta$ samples & $J = L + 1$ \\\\\n%\\hline\n%$\\phi$ samples & $\\phi_i = 2\\pi i/I$, $i = 0,...,I-1$ \\\\\n%\\hline\n%$\\theta$ samples & $\\theta_j = \\arccos(\\mu_j)$ \\\\\n%\\hline\n%$J$ Gaussian quadrature nodes on $[-1,1]$ & $\\mu_j$ \\\\\n%\\hline\n%$J$ Gaussian quadrature weights & $w_j$ \\\\\n%\\hline\n%\\end{tabular}\n%\\end{center}\n%\\label{tab4}\n%\\end{table}%\n%\n%\n%The routine \\texttt{fmmL} computes the maximum degree harmonics and box dimensions at each level.  It takes the side length of the box at the top most level, the number of levels, and the precision of the translation and uses the extended bandwidth formula.  It  forces $L$ to be odd. \n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmL.m}\n%}\n%\n%The routine \\texttt{fmmLevel} takes the harmonic degrees at each level computed in \\texttt{fmmL} and computes the properties in Table \\ref{tab4} for each level, stored in a structure array.  The nodes and weights of Gaussian quadrature are precomputed quickly and accurately to any degree $L$ using \\texttt{legpts} from the package Chebfun.  \n%\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmLevel.m}\n%}\n%\n%\n%\\subsection{Interpolation/Filter}\n%\n%There are $N_{levs}-1$ transitions that exist between $N_{levs}$ levels.  The sums in the interpolator or filter are limited by the maximum harmonic degree of the \\textit{smaller} of the two levels.  Therefore, we index the transitions relative to the level that is being interpolated from, or filtered to.  Let the small of the two levels have maximum degree $L$, sampled in latitude at $\\mu_j$, while the larger of the two levels has maximum degree $K$ sampled in latitude at $\\mu_k$.  The only quantities that must be precomputed to compute a filter or interpolation between levels $l$ to $l+1$ are given in Table \\ref{tab5}.  Once computed, the quantities in the table are good for any transition in the entire computational domain assuming the hierarchy of boxes is a regular octree.  \n%\n%\n%\\begin{table}[htbp]\n%\\caption{Precomputed quantities required to interpolate up from, or filter down to, level $l+1$.}\n%\\begin{center}\n%\\begin{tabular}{|c|c|c|}\n%\\hline\n%Quantity & Interpolation & Filter \\\\\n%\\hline\n%$\\widetilde P_{L-1}^m (\\mu_j)$ & \\ & x \\\\\n%\\hline\n%$\\widetilde P_{L}^m (\\mu_j)$ & x & x \\\\\n%\\hline\n%$\\widetilde P_{L+1}^m (\\mu_j)$ & x & x  \\\\\n%\\hline\n%$\\widetilde P_{L-1}^m (\\mu_k)$ & \\ & x \\\\\n%\\hline\n%$\\widetilde P_{L}^m (\\mu_k)$ & x & x \\\\\n%\\hline\n%$\\widetilde P_{L+1}^m (\\mu_k)$ & x & \\ \\\\\n%\\hline\n%$\\dfrac{d}{d\\mu}\\widetilde P_{L-1}^m (\\mu_k)$, $\\dfrac{d}{d\\mu}\\widetilde P_{L}^m (\\mu_k)$& \\ & x \\\\\n%\\hline\n%1D FMM, $\\mu_j$ source, $\\mu_k$ observation & x & \\ \\\\\n%\\hline\n%1D FMM, $\\mu_k$ source, $\\mu_j$ observation & \\ & x \\\\\n%\\hline\n%\\end{tabular}\n%\\end{center}\n%\\label{tab5}\n%\\end{table}\n%\n%Due to the nature of the sums in the filter or interpolation, all required Legendre polynomials only need to be computed for $m=-L,...,L$ on grids size $(2L+1)\\times(L+1)$ or $(2L+1)\\times(K+1)$.  For polynomials of degree $L-1$, values at $m=L$ are set to zero.  For polynomials of degree $L+1$, the sums that use these polynomials only reach $L$.  \n%\n%\\subsubsection{Precomputed Structure Array}\n%\n%The routine \\texttt{fmmIntFilt} returns a structure array containing the quantities in Table \\ref{tab5} precomputed to interpolate or filter the far-field patterns between levels.  In Matlab, \\texttt{fft} returns one-sided frequencies that correspond to harmonics $[0:M, -M:-1]$.  Our computation of Legendre polynomials returns the order $[-M:M]$.  We rearrange the polynomial harmonics to correspond to the FFT harmonics to avoid additional indexing. \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmIntFilt.m}\n%}\n%\n%\\subsubsection{Fast Interpolation/Filter for FMM}\n%\n%We provide two working versions of the fast vector interpolation and filter operations based on the two methods described above.  To summarize, method 1 relies on precomputed matrices for the core operation, is easier to implement, but is limited to $O(L^3)$ operations.  Method 2 uses the fast scalar filter at its core, requires correction terms, is more complicated, but can be accelerated with the 1D FMM to $O(L^2 log L)$ operations.  \n%\n%\\subsubsection{Method 1}\n%\n%The routine \\texttt{fmmvecinterp1} interpolates a vector field from level $l+1$ to $l$, while the routine and \\texttt{fmmvecfilter1} filters a vector field from level $l$ to $l+1$.  They are designed to work with the precomputed matrices $A$ and $B$ stored in the structure array that is the output of \\texttt{fmmIntFilt}.  The matrices are precomputed using the routine \\texttt{fmmComputeInterpFilter}.\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmvecinterp1.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmvecfilter1.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmComputeInterpFilter.m}\n%}\n%\n%\n%\\subsubsection{Method 2}\n%\n%The routine \\texttt{fmmvecinterp2} interpolates a vector field from level $l+1$ to $l$, while the routine and \\texttt{fmmvecfilter2} filters a vector field from level $l$ to $l+1$.  They are designed to work with the precomputed quantities stored in the structure array that is the output of \\texttt{fmmIntFilt}.  Each are implemented similarly as follows:\n%\n%\\begin{enumerate}\n%\\item Application of the fast scalar interpolation from harmonic $L-1$ or fast scalar filter to harmonic $L-1$.  These are provided by the routines \\texttt{fmminterpLm1} and \\texttt{fmmfilterLm1}.  The field components are multiplied by $\\sin\\theta_j$ (interpolation) or $\\sin\\theta_k$ (filter) on input.   The routines assume that there is no singularity in the core operation (I.e., even number of latitude samples).  \n%Two implementations of the core computation are available: straight matrix-vector multiplication of precomputed $1/(x_j-x-k)$ matrix, or 1D FMM.  At the moment, Matlab's matrix-vector multiplication is faster than our implementation of the 1D FMM.  This may change in a different language.  The 1D FMM version is commented but fully functional\n%\n%\\item Direct computation of vector harmonic coefficients at $L$ and $L+1$.  This is done with \\eqref{eqblm1} and \\eqref{eqclm1}.  All multiplying factors in those equations are included during pre-computation in \\texttt{fmmIntFilt}.\n%\n%\\item Computation of the correction terms in equations \\eqref{correct1}, \\eqref{correct2}, \\eqref{correct3}, \\eqref{correct4} by the function \\texttt{fmmCorrectionTerms}. \n%\n%\\item Computation of the scalar field corrections via \\eqref{eqist1} and \\eqref{eqist2}.  Factors of $2\\pi$ that appear in the original filters have again been cancelled.  \n%\n%\\item Sum the fields from the fast filter and corrected field to give the final filtered vector field components.  Divide the sum by $\\sin\\theta_j$.\n%\\end{enumerate}\n%\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmvecinterp2.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmminterpLm1.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmvecfilter2.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmfilterLm1.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmCorrectionTerms.m}\n%}\n%\n%\\subsection{Octree}\n%\n%An octree is a recursive division of a cube into octants.  Each cube at a given level is called a group, which has at most 8 occupied children.  We use the publicly available Matlab routine \\texttt{BuildOctree} to construct the octree.  It takes the $(x,y,z)$ coordinates of scatterer points and minimum group size.  It returns a structure array of group relations.  It prunes unoccupied groups and determines the near-neighbors.  We modify it in order to specific the edges of the bounding box (We will later replace the \\texttt{neargrouptouch} array with the interlayer near neighbor list and add the interlayer interaction list.)  The routine \\texttt{fmmInitializeTree} adds structure elements for $F_{\\theta}$ and $F_{\\phi}$ at each group.  \n%\n%%\\begin{table}[htbp]\n%%\\caption{Properties of tree structure array}\n%%\\begin{center}\n%%\\begin{tabular}{|c|c|}\n%%\\hline\n%%Level & $l$\\\\\n%%\\hline\n%%Box index at this level & $i$ \\\\\n%%\\hline\n%%Level of parent & $l+1$ \\\\\n%%\\hline\n%%Global index of parent at level $l+1$  & $p$ \\\\\n%%\\hline\n%%Octant in parent's box &  $1,...,8$ \\\\\n%%\\hline\n%%Level of children & $l-1$ \\\\\n%%\\hline\n%%Global indexes of children at level $l-1$ & $c_1$, $c_2$, ..., $c_n$ \\\\\n%%\\hline\n%%Coordinates of box center & \\bb{x} \\\\\n%%\\hline\n%%Field components size $(2L+1)\\times(L+1)$ & $F_{\\theta}(\\theta,\\phi)$, $F_{\\phi}(\\theta,\\phi)$  \\\\\n%%\\hline\n%%\\end{tabular}\n%%\\end{center}\n%%\\label{default}\n%%\\end{table}%\n%\n%\n%\\begin{table}[htbp]\n%\\caption{Properties of Tree structure array.}\n%\\begin{center}\n%\\begin{tabular}{|c|c|}\n%\\hline\n%List of children per group per level & \\texttt{Tree(l).group(g).child(c)} \\\\\n%\\hline\n%Coordinates of group center & \\texttt{Tree(l).group(g).groupcenter}  \\\\\n%\\hline\n%Length of box edge & \\texttt{Tree(l).group(g).cubelength}  \\\\\n%\\hline\n%List of near-neighbors  & \\texttt{Tree(l).group(g).neargrouptouch(nn)}  \\\\\n%\\hline\n%$F_{\\theta}(\\theta,\\phi)$, size $(2L+1)\\times(L+1)$ & \\texttt{Tree(l).group(g).Fth} \\\\\n%\\hline\n%$F_{\\phi}(\\theta,\\phi)$, size $(2L+1)\\times(L+1)$  & \\texttt{Tree(l).group(g).Fphi} \\\\\n%\\hline\n%\\end{tabular}\n%\\end{center}\n%\\label{default}\n%\\end{table}%\n%\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmInitializeTree.m}\n%}\n%\n%\n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/octree} \n%   \\caption{Octree structure of random points.  $N_{levs}$ = 5, maximum group size 10$\\lambda$, minimum group size 0.625$\\lambda$.}\n%   \\label{fig9}\n%\\end{figure}\n%\n\n\n%\n%\\subsection{Traditional Interaction List}\n%\n%The tradition FMM interaction list is constructed recursively starting at the top most level and sweeping the entire octree in order to build a near-neighbor list and interaction list for each group at each level.  The interaction list for a group consists of  groups that are in its so-called neighborhood, i.e., children of the near neighbors of its parent, that are not near neighbors to the group itself.  Neighborhood boxes are well removed, but the outgoing fields are not accounted for one level up because the parents are near neighbors.  [Adapted from Darve 2000]\n%\n%\\begin{figure}[htbp]\n%\\begin{algorithmic}[1]\n%\\footnotesize\n%\\Function{Main}{}\n%\\State CurrentGroup = TopGroup\n%\\State Store CurrentGroup in NearNeighbor list of CurrentGroup\n%\\State \\Call{BuildInteractionList}{CurrentGroup,Nlevs,level = 1}\n%\\EndFunction\n%\\\\\n%\\Function{BuildInteractionList}{Parent,Nlevs,level}\n%\\If {level == Nlevs} \\State {\\Return} \n%\\Else{  \n%\\For {Parent's NearNeighbors}\n%\\For{Neighborhood = Children of Parent's NearNeighbors}\n%\\For{Child = Children of Parent}\n%\\If {Neighborhood == Child's NearNeighbor}\n%\\State{Add Neighborhood to Child's NearNeighbor list}\n%\\Else\n%\\State{Add Neighborhood to Child's Interaction list}\n%\\EndIf\n%\\EndFor\n%\\EndFor\n%\\EndFor\n%\\For {Child = Children of Parent}\n%\\State \\Call{BuildInteractionList}{Parent,Nlevs,level+1}\n%\\EndFor\n%}\n%\\EndIf\n%\\EndFunction\n%\\end{algorithmic}\n%\\caption{Pseudocode for building a traditional FMM near-neighbor and interaction lists}\\label{}\n%\\end{figure}\n%\n%\n%\\newpage\n%\n%\\section{Multi-layer FMM Algorithm}\n%\n%The aim of the multi-layer FMM algorithm is to capture first-order scattering through dielectric layer interfaces in 3D domains that are many thousands of wavelengths.  The goal of the implementation is to capture enough of the relevant scattering physics while making the problem computationally tractable.  The scattering physics we need to capture are\n%\n%\\begin{enumerate}\n%\\item Reflection, refraction, specularity, and rough surface effects at an interface.   \n%\\item First-order interactions between many facets between layers over Fresnel-zone sized regions.  \n%\\item Two-way propagation and reflection at each interface.\n%\\end{enumerate}\n%\n%Item 1 is accomplished with scattering matrices that capture scattering from facets that are used to discitize the interfaces.  Item 2 is accomplished via a user defined interaction rule in combination with FMM acceleration through aggregation/dissaggregation.  Item 3 is accomplished by sweeping the fields from the top interface to the bottom interface and back again.  On the return pass, upward transmission fields are combined with reflected fields from the same interface.  \n%\n%This algorithm drives two key elements: 1) a method of computation for scattering matrices of facets, 2) the construction of an different type of interaction list from the traditional one.  Scattering matrices transform all incoming plane waves into all outgoing plane waves, and, while large, fit naturally into the plane wave formulation of the FMM.  \n%\n%Diagrams\n%\n%\n%\n%\n%\\subsection{Multi-layer Interaction List}\n%\n%For a large multi-layer problem, we construct the interaction action list as follows: \n%\n%\\begin{enumerate}\n%\\item For scattering between layers, we only need a near-neighbor list and interaction list between layers, not within a layers.\n%\\item We only need to bookkeep near-neighbors and interactions from the interface of layer $n$ to $n+1$ (downward).  Reverse interactions are necessity captured in this list.  \n%\\item If there are $N$ interfaces, there are $N-1$ interaction lists.  \n%\\item For extremely large problems, we will likely not aggregate to the top most FMM level.  This is because the number of harmonics required is too large, or the storage for the groups will not be parallelizable.  We defined a maximum FMM level for translations.  When groups in two adjacent layers at the maximum level are well separated, the interaction list will be constructed with a rule we define (e.g., radiation cones).  When groups in two adjacent layers are neighbors (at the max level or below) the traditional interaction rules apply.  \n%\\item We will enforce the rule that the minimum spacing between two interfaces must greater than one box at the lowest FMM level, so that there are no near-neighbors at the lowest level.\n%\\end{enumerate}\n%\n%First define the points for each layer.  An FMM octree is constructed for the points of each layer.  Each layer octree is a subset of a global octree, such that boxes between layers are on the same global grid.  Next, create a layer structure array that contains the octree for all layers (in large problems, for example, this might be a link across files, one file per layer) and their dielectric properties.  Then, we identify groups at the max level in layer $n$ that have near neighbors in layer $n+1$ (including self terms) and construct the tradition interaction lists for them between the two layers.  \n%\n%\n%\\begin{figure}[hbtp]\n%\\begin{algorithmic}[1]\n%\\footnotesize\n%\\Function{Main}{}\n%\\For {layer = 1 to Nlayers}\n%\\State tree = \\Call{BuildOctree}{layer}\n%\\State Add tree to Layer structure array\n%\\EndFor\n%\\State Initialize the trees in the Layer structure array with empty near neighbor and interaction lists that will point to groups indices in layer+1 (up to layer N-1)\n%\\For {layer = 1 to Nlayers-1}\n%\\For {CurrentGroup = Groups at max level}\n%\\State Find CurrentGroup near neighbors in layer+1 and if a self group.\n%\\EndFor\n%\\EndFor\n%\\For {layer =1 to Nlayers-1}\n%\\For {CurrentGroup = Groups at max level }\n%\\If {CurrentGroup has near neighbors in layer+1}\n%\\State \\Call{BuildNNInteractionList}{CurrentGroup,layer,Nlevs,level = maxlevel}\n%\\EndIf\n%\\If {CurrentGroup has non-near neighbors in layer+1}\n%\\State \\Call{BuildMaxLevelInteractionList}{CurrentGroup,layer,level = maxlevel}\n%\\EndIf\n%\\EndFor\n%\\EndFor\n%\\EndFunction\n%\\\\\n%\\Function{BuildNNInteractionList}{Parent,layer,Nlevs,level}\n%\\If {level == Nlevs} \\State {\\Return} \n%\\Else{  \n%\\For {Parent's NearNeighbors in layer+1}\n%\\For{Neighborhood = Children of Parent's NearNeighbors in layer+1}\n%\\For{Child = Children of Parent}\n%\\If {Neighborhood == Child's NearNeighbor in layer+1}\n%\\State{Add Neighborhood to Child's NearNeighbor list in layer+1}\n%\\Else\n%\\State{Add Neighborhood to Child's Interaction list in layer+1}\n%\\EndIf\n%\\EndFor\n%\\EndFor\n%\\EndFor\n%\\For {Child = Children of Parent}\n%\\State \\Call{BuildNNInteractionList}{Child,layer,Nlevs,level+1}\n%\\EndFor\n%}\n%\\EndIf\n%\\EndFunction\n%\\end{algorithmic}\n%\\caption{Pseudocode for building a multi-layer near-neighbor and interaction lists}\\label{}\n%\\end{figure}\n%\n%% we have a maximum upper limit on level, due to size\n%% the interactions at the max lev is decided by a different rule, (cone\n%% size, interaction angle, parallelizable maximum level L < 600)\n%% upper layer to lower, will capture all lower to upper as well\n%% includes a self term\n%% minimum spacing between layers determined so they are well separated at\n%% the lowest level, because we have no direct/self terms.\n%\n%\\newpage \n%\n%The function \\texttt{fmmLayerInteractionList} takes the layer structure array, maximum FMM level and returns the same structure array with near neighbor and interactions for $N-1$ layers.  It initializes the lists and finds the near neighbors at the maximum level.  It then calls \\texttt{fmmInteractionList} which recursively down-traverses a group with any near-neighbors in the next level to form the lower level interaction lists.   The routine \\texttt{fmmMaxLevelInteractionList} creates the interactions list between layers at the maximum level.  The rule here finds the groups at the maximum level in the next layer who's centers fall within a downward scattering cone.  \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmLayerInteractionList.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmNNInteractionList.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmMaxLevelInteractionList.m}\n%}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/layerNN} \n%   \\caption{Near neighbors between a group in layer 1 and groups in layer 2.}\n%   \\label{fig10}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/layerInt} \n%   \\caption{Interactions between a group in layer 1 groups in layer 2, who's parents are near neighbors but are themselves well separated.}\n%   \\label{fig1}\n%\\end{figure}\n%\n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/cone} \n%   \\caption{Interactions between a group in layer 1 those in layer 2 at the maximum level defined by a downward scattering cone.  Here the cone is has 30 degree half angle and pitch in the $-y$ direction of 12 degrees.}\n%   \\label{fig1}\n%\\end{figure}\n%\n%\n%\\newpage\n%\n%\n%\\subsection{Translation}\n%\n%The translation operators can be computed two ways: 1) precompute all unique translation operators for all interaction groups in their entirety and store them: 2) precompute the sampled translation operators and use the fast interpolated scheme before.  \n%\n%On a regular grid, the number of unique translations is greatly reduced.  At levels less than the maximum interaction level (not including the lowest level), a group has at most $3^3-1 = 26$ nearest neighbors, and at most $7^3-3^3-1 = 315$ possible interaction directions.  Given a maximum group level, when we transfer between layers, we may have many fewer or many more than 315 unique interactions.\n%\n%\\begin{table}[htbp]\n%\\caption{Precomputed translation operators}\n%\\begin{center}\n%\\begin{tabular}{|c|c|}\n%\\hline\n%Precomputed translation operators, for unique $kr$ & $T_L(\\bb{k},\\bb{X})$ \\\\\n%\\hline\n%\\end{tabular}\n%\\end{center}\n%\\label{default}\n%\\end{table}\n%\n%For this  Matlab implementation, we choose option 1) to precompute the unique translation operators in the forward and reverse directions and adds them to the layer structure.  We do this because the interpolation scheme is, at the moment, fairly slow.  This is done with the routine \\texttt{fmmTranslationOperators}.  It finds the unique translations between interacting groups between each layer for each level and computed them.  It adds a list of interaction indices that index the translation operator for that group and the group in the next layer at the same position in the next-layer interaction list.  It then computes reverse interaction lists that point from a lower level to the next higher level.\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmTranslationOperators.m}\n%}\n%\n%\n%\\subsection{Layers Field Storage}\n%\n%Only outgoing fields from interacting groups must be stored. Incoming radiation patterns are computed during disaggregation on the fly.  An interface has one set of downward fields after transmission, and one set of upward fields after reflection and transmission from the lower layer on the return pass.  The fields are sampled on the usual $2L+1$ x $L+1$ phi/theta.  There are two exceptions: 1) at the top interface only transmitted fields are stored, 2) at the bottom interface only reflected fields are stored.  Reflection from the upper surface is computed separately between the source and the each facet directly, this will have benefits later.\n%\n%The routine \\texttt{fmmInitializeLayerTree} creates this storage based on the interaction lists. \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmInitializeLayerTree.m}\n%}\n%\n%\\newpage \n%\\subsection{Multi-layer Scattering Algorithm Psuedo-Code}\n%\n%\\begin{figure}[htbp]\n%\\begin{algorithmic}[1]\n%\\footnotesize\n%\\State Create the layer interfaces (facet centers, facet normals, dielectric properties)\n%\\State Call \\Call{BuildOctreeMod}{} to create FMM trees for each layer interface\n%\\State Create an $N\\times1$ Layers struct array\n%\\State Add FMM layer interface trees to Layers struct\n%\\State Call \\Call{fmmLayerInteractionList}{} to create the interaction lists and add them to Layers struct\n%\\State Call \\Call{fmmLevel}{} to create level properties struct\n%\\State Call \\Call{fmmIntFilt}{} to create interpolation and filter struct\n%\\State Call \\Call{fmmTranslationOperators}{} to compute the unique translation operations in the interaction list and add them to the Layers struct\n%\\State Call \\Call{fmmInitializeLayerTree}{} to create storage for all outgoing fields in Layers struct\n%\\State Compute $S_{11}$ for each facet directly to source \\Comment{\\textit{Surface return}}\n%\\For{Layer = top to bottom}\\Comment{\\textit{Downward pass}}\n%\\For{CurrentGroup = Groups at max level}\n%%\\State Copy tree struct for CurrentGroup, create temporary storage at each level.\n%\\If {Layer = top}\n%\\State Compute $S_{21}$ for each facet directly from source field\n%\\State Aggregate $S_{21}$ to max level and store as transmitted field\n%\\Else\n%\\State Translate and disaggregate incoming fields from layer above to facet level\n%\\State Compute $S_{11}$ for each facet\n%\\State Aggregate $S_{11}$ to max level and store as reflected field\n%\\If {Layer != bottom}\n%\\State Compute $S_{21}$ for each facet\n%\\State Aggregate $S_{21}$ to max level and store as transmitted field\n%\\EndIf\n%\\EndIf\n%\\EndFor{}\n%\\EndFor{}\n%\n%\\For{Layer = next-to-last to top}\\Comment{\\textit{Upward pass}}\n%\\For{CurrentGroup = Groups at max level}\n%\\State Translate and disaggregate reflected fields from lower layer to facet level\n%\\If {Layer = top}\n%\\State Compute $S_{12}$ for each facet directly to source\n%\\State Compute $S_{11}$ for each facet directly to source \n%\\State Sum $S_{12}$ and $S_{11}$ contributions to source received field\n%\\Else\n%\\State Compute $S_{12}$ for each facet\n%\\State Aggregate $S_{12}$ transmission to max level\n%\\State Add aggregated transmission to previously stored reflected fields\n%\\EndIf\n%\\EndFor{}\n%\\EndFor{}\n%\n%%\\\\\n%%\\\\\n%% \\Function{Main}{}\n%%\\State CurrentGroup = TopGroup\n%%\\State Store CurrentGroup in NearNeighbor list of CurrentGroup\n%%\\State \\Call{BuildInteractionList}{CurrentGroup,Nlevs,level = 1}\n%%\\EndFunction\n%%\\\\\n%%\\Function{BuildInteractionList}{Parent,Nlevs,level}\n%%\\If {level == Nlevs} \\State {\\Return} \n%%\\Else{  \n%%\\For {Parent's NearNeighbors}\n%%\\For{Neighborhood = Children of Parent's NearNeighbors}\n%%\\For{Child = Children of Parent}\n%%\\If {Neighborhood == Child's NearNeighbor}\n%%\\State{Add Neighborhood to Child's NearNeighbor list}\n%%\\Else\n%%\\State{Add Neighborhood to Child's Interaction list}\n%%\\EndIf\n%%\\EndFor\n%%\\EndFor\n%%\\EndFor\n%%\\For {Child = Children of Parent}\n%%\\State \\Call{BuildInteractionList}{Parent,Nlevs,level+1}\n%%\\EndFor\n%%}\n%%\\EndIf\n%%\\EndFunction\n%\\end{algorithmic}\n%\\caption{Pseudocode for the multi-layer FMM algorithm}\\label{}\n%\\end{figure}\n%\n%\\newpage \n%\n%\\subsection{Subtree Recursion Template}\n%\n%The routine \\texttt{treeTraverse} is a template for recursing through a subtree given the starting level and group index.\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/treeTraverse.m}\n%}\n%\n%\\subsection{Create Subtree}\n%\n%Subtrees will be used to provide scratch space for aggregation and disaggregation of max level groups.  All max level groups that are well separated between layers only need to store the outgoing fields at the max level, not the underlying fields at each level of aggregation or disaggregation.  Therefore, we create scratch space in a subtree that contains field storage at every group.  We will transfer only the fields required for interacting groups to the global tree, then destroy the subtree.  This also makes aggregation/disaggregation easy, because we simply loop over all existing elements of the tree.  \n%\n%The routine \\texttt{fmmMakeSubTree} will extract a subtree from the global tree for a given layer with a local parent/child indexing.   The subtree structure is initialized, then the routine calls \\texttt{fmmTraverseNewTree} to determine the local parent/child indexing and group index in the global tree, and calls \\texttt{fmmInitializeTree} to create field storage for every group in the subtree.  We give it another structure called \\texttt{Pts}, which is a structure array containing the locations of the scatterers.  It will return a tree with storage down to the level of the scatterers.  \n%\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmMakeSubTree.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmTraverseNewTree.m}\n%}\n%\n%\\subsection{Aggregate Subtree}\n%\n%The routine \\texttt{fmmAggregateSubTree} will aggregate the fields up a subtree produced by \\texttt{fmmMakeSubTree} starting at the scatterer level up to the max level.  The outgoing fields from the scatterers must first be loaded at the lowest level.  The wave number is a variable because will we aggregate the same tree in two different media (one for up going waves, one for down going waves).\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmAggregateSubTree.m}\n%}\n%\n%\\subsection{Layer-to-layer Translation}\n%\n%Translations will be computed per group at the maximum level and loaded into the current subtree.  The direction of the translation, and therefore the operator and medium it was computed in will depend on the whether we are in the downward or upward pass of the layers.  \n%\n%The routine \\texttt{fmmTranslateToSubTree} computes the translated fields to all level of the subtree that need it (i.e., nonzero interaction list).  It includes a flag (called 'add') to the subtree to indicate whether the disaggregation routine should add the the filtered field with the stored field or not.  \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmTranslateToSubTree.m}\n%}\n%\n%\n%\\subsection{Disaggregate Subtree}\n%\n%The routine \\texttt{fmmDisaggregateSubTree} will disaggregate the fields in a subtree produced by \\texttt{fmmMakeSubTree} starting at the maximum level down to the scatter level.  The incoming fields at all levels must be loaded.  Filtered fields are added to whatever existing fields already exist at that level based on the \\texttt{add} switch.  The wave number is again a variable. \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmDisaggregateSubTree.m}\n%}\n%\n%\n%\\subsection{Store Subtree}\n%\n%After a subtree as been aggregated to the max level, only the outgoing fields for groups with non-zero interaction lists need to be stored in the Layers structure.  \n%\n%The routine \\texttt{fmmStoreSubTree} takes an aggregated subtree and identifies from the global indices which fields must be stored.  The string switch \\texttt{TRstr} indicates if the fields are stored as reflected or transmitted fields.  The string switch \\texttt{writestr} indicates whether to overwrite or add to existing fields.  \n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/fmmStoreSubTree.m}\n%}\n\n\\clearpage\n\\newpage\n\n\\section{Scattering Matrices for the FMM}\n\n\\subsection{S-matrix and Field Multiplication using Quadrature}\n\nThe scattering matrix (S-matrix) (or scattering function matrix, \\cite{tsang2000scattering}) embeds the scattering behavior of an object as a mapping between incident and scattered plane waves of different incident and scattered directions and polarizations. In the FMM, fields are treated as expansions of plane waves where many plane waves are incident on a local region at once. The outgoing scattered field in any particular direction is the sum of scattering contributions from all incident waves. In the limit, this sum can be computed as an integral of incident directions over the unit sphere. Casting the  S-matrix this way allows it to be used in the structures of the FMM.  \n\nFor the FMM, we choose the orthonormal basis for the S-matrix formed by $\\hat{k}$, $\\hat{\\theta}$, and $\\hat{\\phi}$, such that the incident and scattered fields are defined over two far-field patterns $\\bb{F}(\\theta_s,\\phi_s)$ and $\\bb{G}(\\theta_i,\\phi_i)$. \\begin{equation}\n\\bb{E}_i(\\hat{k}_i) = \\left(G_{\\theta}(\\hat{k}_i)\\hat{\\theta}  +G_{\\phi}(\\hat{k}_i) \\hat{\\phi} \\right) e^{i\\bb{k}_i \\cdot \\br}\n\\end{equation}\n\n\\begin{equation}\n\\bb{E}_s(\\hat{k}_s) = \\left( F_{\\theta}(\\hat{k}_s)\\hat{\\theta} +  F_{\\phi}(\\hat{k}_s)\\hat{\\phi}\\right) \\dfrac{ e^{i k r}}{r}\n\\end{equation}\n \n\\begin{equation}\n\\twobyone{F_{\\theta}(\\hat{k}_s)}{F_{\\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{G_{\\theta}(\\hat{k}_i)}{G_{\\phi}(\\hat{k}_i)} \n\\end{equation}\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}. %In addition, $\\hat{\\theta}$, and $\\hat{\\phi}$ are really the same polarization components relative to the frame of the scatterer, where $\\hat{k}_i$ and $\\hat{k}_s$ are just radial vectors in the direction of propagation. \n \nThe matrix above maps any pair of direction/polarization to any other pair.  Define the operation that transforms an incoming field pattern, $\\bb{G}(\\hat{\\bb{k}})$, to an outgoing field pattern, $\\bb{F}(\\hat{\\bb{k}})$, as the integral of the S-matrix over the unit sphere of incident directions \n\\begin{equation}\n\\bb{F}(\\hat{\\bb{k}}_s) = \\int \\overline{\\bb{S}}(\\hat{\\bb{k}}_s,\\hat{\\bb{k}}_i)\\cdot \\bb{G}(\\hat{\\bb{k}}_i) d\\Omega_{k_i}\n\\end{equation}\n\nor\n\\begin{equation}\n\\twobyone{F_{\\theta}(\\hat{\\bb{k}}_s)}{F_{\\phi}(\\hat{\\bb{k}}_s)} = \n\\int \\twobytwo\n{S_{\\theta\\theta}(\\hat{\\bb{k}}_s,\\hat{\\bb{k}}_i)}\n{S_{\\theta\\phi}(\\hat{\\bb{k}}_s,\\hat{\\bb{k}}_i)}\n{S_{\\phi\\theta}(\\hat{\\bb{k}}_s,\\hat{\\bb{k}}_i)}\n{S_{\\phi\\phi}(\\hat{\\bb{k}}_s,\\hat{\\bb{k}}_i)}\n\\cdot \\twobyone{G_{\\theta}(\\hat{\\bb{k}}_i)}{G_{\\phi}(\\hat{\\bb{k}}_i)} d\\Omega_{k_i} \\label{smatintegral}\n\\end{equation}\n\nTo compute this exactly, the field pattern and the S-matrix are sampled at the nodes of Gaussian quadrature on a grid that is $(2L+1) \\times (L+1)$ for maximum harmonic degree $L$. Then \\eqref{smatintegral} can be discretized as\n \\begin{equation}\n\\twobyone{F_{\\theta}(\\theta_{\\mu},\\phi_{\\nu})}{F_{\\phi}(\\theta_{\\mu},\\phi_{\\nu})} = \n\\dfrac{2\\pi}{2L+1}  \\sum_{i=1}^{2L+1} \\sum_{j=1}^{L+1} w_j \\twobytwo\n{S_{\\theta\\theta}(\\theta_{\\mu},\\phi_{\\nu};\\theta_j,\\phi_i)}\n{S_{\\theta\\phi}(\\theta_{\\mu},\\phi_{\\nu};\\theta_j,\\phi_i)}\n{S_{\\phi\\theta}(\\theta_{\\mu},\\phi_{\\nu};\\theta_j,\\phi_i)}\n{S_{\\phi\\phi}(\\theta_{\\mu},\\phi_{\\nu};\\theta_j,\\phi_i)} \\cdot \\twobyone{G_{\\theta}(\\theta_j,\\phi_i)}{G_{\\phi}(\\theta_j,\\phi_i)} \n\\end{equation}\n\n\\noindent where the spherical angles $(\\theta_j,\\phi_i)$ and $(\\theta_{\\mu},\\phi_{\\nu})$ are the samples of quadrature.  Technically, only the incident directions needed to be sampled by quadrature. As always with quadrature, the poles are never sampled, so the polarization ambiguity at the poles never occurs. Writing this in matrix form, where the 2D spherical sum is over columns of the matrix, and the weights and multiplying constants are put in a diagonal matrix,\\begin{equation}\n\\twobyone{\\bb{F}_{\\theta}}{\\bb{F}_{\\phi}} = \n\\twobytwo{\\overline{\\bb{S}}_{\\theta\\theta}}{\\overline{\\bb{S}}_{\\theta\\phi}}{\\overline{\\bb{S}}_{\\phi\\theta}}{\\overline{\\bb{S}}_{\\phi\\phi}} \\twobytwo{\\bb{W}}{0}{0}{\\bb{W}}\\twobyone{\\bb{G}_{\\theta}}{\\bb{G}_{\\phi}}  \\label{FSWG}\n\\end{equation}\n\n\\noindent where the elements of $\\bb{W}$ contains copies of the weights $w_j$ as they apply to $\\theta_j$.  \n\nThe routine \\texttt{compute\\char`_Smatrix\\char`_quad} applies the S-matrix to an incoming field pattern when both are sampled on the points of Gaussian quadrature.  It returns the scattered field sampled the same way.  The fields are sized $I \\times J$ where $I = 2L + 1$ and $J = L+1$ for maximum harmonic degree $L$ (as written the routine can take any sampling $I$ and $J$). The S-matrix block components are $I \\times J \\times I \\times J$ with scattered directions in the first two dimensions and incident directions in the last two dimensions. The results match the same computation when its performed by starting with a S-matrix, converting it to a T-matrix, computing the scattering via harmonic expansions, and then converting it back to an S-matrix. \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/Smatrix/compute_Smatrix_quad.m}\n}\n\n\n\n\n\n\n%\n%\n%At a layer interface (e.g., surface facet), we can further define the scattering matrix with four components that account for two-way reflection and transmission at the interface such that\n%\n%\n%\\begin{equation}\n%\\twobyone{\\bb{F}_1(\\hat{\\bb{k}}) }{\\bb{F}_2(\\hat{\\bb{k}}) } = \\twobytwo{\\overline{\\bb{S}}_{11} }{\\overline{\\bb{S}}_{12} }{\\overline{\\bb{S}}_{21} }{\\overline{\\bb{S}}_{22} }\\twobyone{\\bb{G}_1(\\hat{\\bb{k}}) }{\\bb{G}_2(\\hat{\\bb{k}}) } \n%\\end{equation}\n%\n%\\noindent where $\\bb{G}_1$ and $\\bb{F}_1$ are incoming/outgoing fields in the upper region and $\\bb{G}_2$ and $\\bb{F}_2$ are in the lower region.  For facets, we can automatically enforce 'shadowing' by zeroing non-physical propagation combinations.  For example, $\\overline{\\bb{S}}_{11} $ should only transform downward incident plane waves into upward plane waves, relative to the facet normal, all other combinations are zero.  Likewise for the other components.  \n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=3.5in]{FastMultipoleMethod/diagramsSmatrix} \n%   \\caption{Components of a two-layer scattering matrix.}\n%   \\label{figxx}\n%\\end{figure}\n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=5in]{FastMultipoleMethod/diagramsSmatrixk} \n%   \\caption{Sampling scheme of plane wave directions or, equivalently, spherical angles. Incident directions are along columns, scattered directions are along rows.  Quadrants represent paris of $\\pm k_{i,z}$ and $\\pm k_{s,z}$.}\n%   \\label{figyy}\n%\\end{figure}\n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/diagramsSmatrix2} \n%   \\caption{Coordinate and vector conventions for $S_{11}$ and $S_{21}$ in the FMM.}\n%   \\label{figyy}\n%\\end{figure}\n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/diagramsSmatrix3} \n%   \\caption{Coordinate and vector conventions for $S_{12}$ and $S_{22}$ in the FMM.}\n%   \\label{figyy}\n%\\end{figure}\n%\n\n\n%\n%\\subsection{Scattering Matrix of a Kirchhoff Facet}\n%\n%We use the results of the Kirchhoff approximation to derive a scattering matrix for Kirchhoff facets in the context of the FMM.  Given an incident field \n%\n%\\[\\bb{E}_i = \\bb{e}_i E_o e^{i\\bb{k}_i \\cdot \\bb{r}} \\]\n%\n%the equations for the reflected and transmitted field from an entire facetized interface under the Kirchhoff approximation are\n%\n%\\begin{eqnarray}\n%\\bb{E}_r(\\br) & \\approx & \\dfrac{ik_1e^{ik_1r}}{4\\pi r} E_o \\left( \\overline{\\bb{I}} - \\hat{k}_r \\hat{k}_r \\right)  \\cdot \\sum_n \\bb{F}(\\br_n) \\int_{S_n} dS e^{i (\\bb{k}_i - \\bb{k}_r) \\cdot \\br}  \\nonumber \\\\\n%\\bb{E}_t(\\br) & \\approx & -\\dfrac{ik_2 e^{ik_2r}}{4\\pi r} E_o \\left( \\overline{\\bb{I}} - \\hat{k}_t \\hat{k}_t \\right)  \\cdot \\sum_n \\bb{N}(\\br_n) \\int_{S_n} dS  e^{i (\\bb{k}_i - \\bb{k}_t) \\cdot \\br}  \\nonumber \n%\\end{eqnarray}\n%\n%where\n%\n%\\begin{eqnarray}\n%\\bb{F}(\\br_n) &=&  - (\\hat{e}_i \\cdot \\hat{q} )(\\hat{n} \\cdot \\hat{k}_i) \\hat{q} (1 - R^{\\textrm{TE}}) \\nonumber \\\\\n%\\ & \\ & + (\\hat{e}_i \\cdot \\hat{p} )(\\hat{n} \\times \\hat{q}) (1 + R^{\\textrm{TM}}) \\nonumber \\\\\n%\\ & \\ &+ (\\hat{e}_i \\cdot \\hat{q} )(\\hat{k}_r \\times (\\hat{n} \\times \\hat{q})) (1 + R^{\\textrm{TE}}) \\nonumber \\\\\n%\\ & \\ & + (\\hat{e}_i \\cdot \\hat{p} )(\\hat{n} \\cdot \\hat{k}_i) (\\hat{k}_r \\times \\hat{q}) (1 - R^{\\textrm{TM}}) \\\\\n%\\bb{N}(\\br_n) &=&  - \\dfrac{\\eta_2}{\\eta_1}(\\hat{e}_i \\cdot \\hat{q} )(\\hat{n} \\cdot \\hat{k}_i) \\hat{q} (1 - R^{\\textrm{TE}})\\nonumber \\\\\n%\\ & \\ & + \\dfrac{\\eta_2}{\\eta_1}(\\hat{e}_i \\cdot \\hat{p} )(\\hat{n} \\times \\hat{q}) (1 + R^{\\textrm{TM}}) \\nonumber \\\\\n%\\ & \\ &+ (\\hat{e}_i \\cdot \\hat{q} )(\\hat{k}_t \\times (\\hat{n} \\times \\hat{q})) (1 + R^{\\textrm{TE}}) \\nonumber \\\\\n%\\ & \\ & + (\\hat{e}_i \\cdot \\hat{p} )(\\hat{n} \\cdot \\hat{k}_i) (\\hat{k}_t \\times \\hat{q}) (1 - R^{\\textrm{TM}}) \n%\\end{eqnarray}\n%\n%\\noindent and $\\bb{F}(\\br')$ and $\\bb{N}(\\br')$ are treated constant over the surface of facets.  By definition, reflected directions $\\hat{k}_r$ are in the upward direction above the facet in the first medium, while transmitted directions $\\hat{k}_t$ are downward in the second medium.  \n%\n%To derive the scattering matrix of a single facet, we take one facet centered at the origin.  The surface sum reduces to  \n%\n%\\begin{eqnarray}\n%\\bb{E}_r(\\br) & \\approx & \\dfrac{ik_1 e^{ik_1 r}}{4\\pi r} E_o \\left( \\overline{\\bb{I}} - \\hat{k}_r \\hat{k}_r \\right)  \\cdot  \\bb{F}(\\hat{k}_i,\\hat{k}_r) I(\\bb{k}_i,\\bb{k}_r)   \\\\\n%\\bb{E}_t(\\br) & \\approx & -\\dfrac{ik_2e^{ik_2 r}}{4\\pi r} E_o \\left( \\overline{\\bb{I}} - \\hat{k}_t \\hat{k}_t \\right)  \\cdot  \\bb{N}(\\hat{k}_i,\\hat{k}_t) I(\\bb{k}_i,\\bb{k}_t) \n%\\end{eqnarray}\n%\n%\\noindent where $\\bb{F}(\\hat{k}_i,\\hat{k}_r)$ and $\\bb{N}(\\hat{k}_i,\\hat{k}_t)$ depend on incident and scattered directions, surface normal, and material type.  The phase integral is one of\n%\n%\\begin{eqnarray}\n%I(\\bb{k}_i,\\bb{k}_r) &=&  \\int_{S} dS  e^{i (\\bb{k}_i - \\bb{k}_r) \\cdot \\br}  \\\\\n%I(\\bb{k}_i,\\bb{k}_t) &=&  \\int_{S} dS  e^{i (\\bb{k}_i - \\bb{k}_t)\\cdot \\br }\n%\\end{eqnarray}\n%\n%Using they identity $ \\overline{\\bb{I}} - \\hat{k} \\hat{k} = \\hat{\\theta} \\hat{\\theta} + \\hat{\\phi} \\hat{\\phi}$ and separating the far-field phase and decay\n%\n%\\begin{eqnarray}\n%\\bb{E}_r(\\br) & \\approx & \\left( E_{\\theta,s} \\hat{\\theta} + E_{\\phi,s} \\hat{\\phi} \\right)  \\dfrac{e^{ik_1 r}}{r} \\\\\n%\\bb{E}_t(\\br) & \\approx & \\left( E_{\\theta,t} \\hat{\\theta} + E_{\\phi,t} \\hat{\\phi} \\right)  \\dfrac{e^{ik_2 r}}{r} \n%\\end{eqnarray}\n%\n%\\begin{eqnarray}\n%E_{\\theta,s} &=& E_o\\dfrac{ik_1 }{4\\pi}\\left(\\hat{\\theta}  \\cdot  \\bb{F}(\\hat{k}_i,\\hat{k}_r) \\right)I(\\bb{k}_i,\\bb{k}_r) \\\\\n%E_{\\phi,s} &=& E_o\\dfrac{ik_1 }{4\\pi}\\left(\\hat{\\phi}  \\cdot  \\bb{F}(\\hat{k}_i,\\hat{k}_r) \\right)I(\\bb{k}_i,\\bb{k}_r) \\\\\n%E_{\\theta,t} &=& E_o\\dfrac{ik_2 }{4\\pi}\\left(\\hat{\\theta}  \\cdot  \\bb{N}(\\hat{k}_i,\\hat{k}_t) \\right)I(\\bb{k}_i,\\bb{k}_t) \\\\\n%E_{\\phi,t} &=& E_o\\dfrac{ik_2 }{4\\pi}\\left(\\hat{\\phi}  \\cdot  \\bb{N}(\\hat{k}_i,\\hat{k}_t) \\right)I(\\bb{k}_i,\\bb{k}_t) \n%\\end{eqnarray}\n%\n%Noticing that $E_o$ is common with the incident field defined above, the vector components of the scattering matrix can be constructed by taking $\\bb{e}_i = [\\hat{\\theta}, \\hat{\\phi}]$ in turn.\n%\n%For $S_{11}$ and $S_{21}$, the equations above are unchanged.  The incident directions come from above the facet, reflected waves propagate above the facet, and transmitted directions propagate below the facet.  For $S_{12}$ and $S_{22}$, we reverse the equations.  In both cases, the field components are projected onto the same local $\\hat{q}$, $\\hat{p}$ basis, so that the polarization transforms consistently between all four scattering matrices.  The reflection coefficients are determined by the local normal of the incident direction.  We zero incident/scattering angle combinations that are inconsistent with the definition each scattering matrix. \n%\n%For the FMM, we can either derive a scattering matrix in the frame of the facet, requiring FMM fields to be rotated to the frame and back during computation, or we can create scattering matrices with the facet rotated in the global FMM frame. The later also fits more naturally into the structure of the FMM where plane wave directions are sampled and locked in the global frame, but ultimately it is a trade between computation and storage.  In either case, the FMM plane wave directions become reflected or transmitted depending on which side of the facet they originate. \n%\n%\n%\n%\n%\\subsubsection{Kirchhoff Disk}\n%\n%The routine \\texttt{sMatrixDisk} returns one of the four S-matrices for a Kirchhoff disk.  It takes as input the enumerated type ($S_{11}$, $S_{21}$, $S_{12}$, $S_{22}$), incident and scattering field directions, dielectrics and wave numbers of the upper and lower media, disk area and surface normal in the global FMM frame.  The reflection coefficients can be computed with complex $\\epsilon_r$, but the phase integral will use the real part of the wave numbers for \\texttt{intKirchhoffDisk}.  The incident and scattered directions are forced to 1D arrays, and using the $\\theta$, $\\phi$ grids defined in the FMM Level structure, will return wave vector directions consistent with the ordering in the figure above.  \n\n%\n%\n%{\\footnotesize\n%\\VerbatimInput{/Users/mshaynes/Desktop/Work/Database/sMatrixDisk.m}\n%}\n%\n%\n%\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{11}Disk} \n%   \\caption{$S_{11}$ for disk $\\hat{n} = [0,0,1]$, $a = 1/4 \\lambda$, $\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$}\n%   \\label{figyy}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{21}Disk} \n%   \\caption{$S_{21}$ for disk $\\hat{n} = [0,0,1]$, $a = 1/4 \\lambda$,$\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$.  The fading stripe in the amplitude is due to the Brewster angle.  }\n%   \\label{figyy}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{12}Disk} \n%   \\caption{$S_{12}$ for disk $\\hat{n} = [0,0,1]$, $a = 1/4 \\lambda$,$\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$}\n%   \\label{figyy}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{22}Disk} \n%   \\caption{$S_{22}$ for disk $\\hat{n} = [0,0,1]$, $a = 1/4 \\lambda$,$\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$.  The fading patterns are due to the partial effects of total internal reflection (not complete total internal reflection because the disk the finite)}\n%   \\label{figyy}\n%\\end{figure}\n%\n%%% \n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{11}Disk2} \n%   \\caption{$S_{11}$ for disk $\\hat{n} = [0,1/\\sqrt{2},1/\\sqrt{2}]$, $a = 1/4 \\lambda$, $\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$}\n%   \\label{figyy}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{21}Disk2} \n%   \\caption{$S_{21}$ for disk $\\hat{n} = [0,1/\\sqrt{2},1/\\sqrt{2}]$, $a = 1/4 \\lambda$, $\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$}\n%   \\label{figyy}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{12}Disk2} \n%   \\caption{$S_{12}$ for disk $\\hat{n} = [0,1/\\sqrt{2},1/\\sqrt{2}]$, $a = 1/4 \\lambda$, $\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$}\n%   \\label{figyy}\n%\\end{figure}\n%\n% \\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=4in]{FastMultipoleMethod/S_{22}Disk2} \n%   \\caption{$S_{22}$ for disk $\\hat{n} = [0,1/\\sqrt{2},1/\\sqrt{2}]$, $a = 1/4 \\lambda$, $\\epsilon_{r1} = 1$, $\\epsilon_{r2} = 3$}\n%   \\label{figyy}\n%\\end{figure}\n\n\n\n\\subsection{S-matrix to T-matrix Transformation using Quadrature}\n\\label{fastStoT}\n\nWhile the S-matrix is a useful 4D structure for storing the scattering properties of a target, it 1) can be difficult and inaccurate to interpolate if the propagation directions are not highly oversampled, and 2) it can be difficult to rotate between two reference frames because the wave directions and the vector components need to be transformed. On the other hand, the transition matrix (T-matrix), which relates coefficients of the incident and scattered spherical harmonic expansions, is very easy to rotate, and enables exact interpolation at arbitrary propagation directions through field expansions.  \n\nRecall the S-matrix to T-matrix transformation \\eqref{StoTBC}\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{\\bb{W}}{0}{0}{\\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{\\bb{W}}{0}{0}{\\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{StoTvst}}\n\nOur routine \\texttt{vst} will compute exactly the discretized integral of the vector spherical harmonics over the unit sphere when applied from the left to the columns of $\\bb{S}$, when the scattered directions $\\bb{S}$ are sampled at the nodes of Gaussian quadrature. It can also be used again to compute the integral over incident directions as a left operation on $\\bb{S}^*$.\n\nThe routine \\texttt{convert\\char`_S\\char`_to\\char`_T} computes the S-matrix to T-matrix transformation \\eqref{StoTvst}. It takes as input the four S-matrix components and returns the four components of the T-matrix. Each S-matrix component is stored on a 4D grid that is $I \\times J \\times I \\times J$, where $I = 2L+1$ and $J = L+1$ are sampled according to quadrature for $L$ harmonics. The scattered directions are dimensions 1 and 2 and the incident directions are dimensions 3 and 4. The routine returns the four components of the T-matrix up to harmonic degree $L$ all $m$ linearly indexed, each an $N \\times N$ matrix where $N = L^2 + 2L$. The routine calls \\texttt{vst} with precomputed Legendre polynomials and carries out the block matrix multiplication as a sequence of operations on the columns of the S-matrix or its transpose. The columns of the S-matrix are in fact the $I \\times J$ subfields that are converted to columns of the T-matrix that are pairs of coefficients length $N$. This uses the fully normalized vector spherical harmonics.\n\\clearpage\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/Smatrix/convert_S_to_T.m}\n}\n\n\n\n\\subsection{T-matrix to S-matrix Transformation using Quadrature}\n\\label{fastTtoS}\n\nRecall the T-matrix to S-matrix transformation \\eqref{TtoSBC}\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{Sivst}} \n\nOur routine \\texttt{ivst} will compute exactly the matrix multiplication over the block vector spherical harmonics when applied as a left operation to the columns of the T-matrix. We can use it again to compute the right multiplication of the conjugate operation as a left multiplication of the conjugate T-matrix, $\\bb{T}^*$.\n\nThe routine \\texttt{convert\\char`_T\\char`_to\\char`_S}, computes the four components of the S-matrix given the four components of the T-matrix that contain harmonics up to degree $L$ all $m$ linearly indexed. It calls \\texttt{ivst} to compute \\eqref{Sivst} as a sequence of operations over the columns of the T-matrix or its transpose. The columns of the T-matrix are treated as pairs of expansion coefficients having $N = L^2 + 2L$ harmonics each when input to \\texttt{ivst} that return field quantities sized $I \\times J$ that are the new columns. When done, the S-matrix is $I \\times J \\times I \\times J$ with scattered directions in the first two dimensions and incident directions in the last two dimensions.  Applied in sequence with \\texttt{convert\\char`_S\\char`_to\\char`_T} the routines will return identical results. Note, these two transformations do not require physically realistic T- or S-matrices, but an unrealistic S-matrix will be filtered into a band-limited T-matrix.   %Use string switch \\texttt{'norm'} to transform from the normalized T-matrix.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/Smatrix/convert_T_to_S.m}\n}\n\n\n\n%\n%\\newpage \n%\n%\\section{FMM Formulation}\n%\n%The dyadic Green's function is give by\n%\n%\\begin{equation}\n% \\overline{\\bb{G}}(\\br,\\br') = \\left[\\overline{\\bb{I}} + \\dfrac{1}{k^2} \\nabla\\nabla \\right] g(\\br,\\br') \n% \\end{equation}\n% \n% where \n% \n% \\[ g(\\br,\\br') =  \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi \\vert \\br - \\br' \\vert} \\]\n%\n%The far-field dyadic Green's function is \n%\n%\\begin{equation}\n% \\overline{\\bb{G}}_f(\\br,\\br') \\approx \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] g(\\br,\\br') \n% \\end{equation}\n%\n%\n%The curl of the far expression can be derived as\n%\n%\\[ \\nabla \\times \\overline{\\bb{G}}_f(\\br,\\br')  = \\nabla \\times \\left( \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] g(\\br,\\br')\\right) \\]\n%\n%This has the form\n%\n%\\[ \\nabla \\times ( \\phi \\overline{\\bb{F}} ) = \\nabla \\phi \\times \\overline{\\bb{F}} + \\phi \\nabla \\times \\overline{\\bb{F}} \\]\n%\n%where $ \\overline{\\bb{F}}  = \\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}}  $. This reduces to \n%\n%\\[ \\nabla \\times \\overline{\\bb{G}}_f(\\br,\\br')  = \\nabla g(\\br,\\br') \\times \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right]  \\]\n%\n%Applied to a vector $\\bb{v}$, \n%\n%\\begin{eqnarray}\n%\\left( \\nabla \\times \\overline{\\bb{G}}_f(\\br,\\br')\\right)  \\cdot \\bb{v} & = &  -\\bb{v} \\cdot \\left( \\nabla \\times \\overline{\\bb{G}}_f(\\br,\\br')\\right) \\\\\n%\\ & = &  - \\bb{v} \\cdot  \\left(\\nabla g(\\br,\\br') \\times \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\right) \\\\\n% \\ & = & - \\left( \\bb{v} \\times \\nabla g(\\br,\\br') \\right) \\cdot \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\\\\n% \\ & = & -\\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot \\left( \\bb{v} \\times \\nabla g(\\br,\\br') \\right) \\\\\n% \\ & = &  \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot \\left( \\nabla g(\\br,\\br') \\times \\bb{v}  \\right) \\\\\n%  \\ & \\approx &  \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot \\left( i k g(\\br,\\br')\\right) \\left( \\hat{\\bb{k}} \\times \\bb{v} \\right) \n% \\end{eqnarray}\n%\n%The first equation because the curl of the dyadic Green's function is anti-symmetric.  The third equation uses the relation $\\bb{a}\\cdot(\\bb{b} \\times \\overline{\\bb{c}}) = (\\bb{a} \\times \\bb{b})\\cdot  \\overline{\\bb{c}} $.  The fourth  because $ \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] $ is a symmetric dyad.  The fifth equation is cross product commutation.  Finally the gradient is applied and the far-field taken since \n%\n%\\[\\nabla g(\\br,\\br')  = \\left(ik - \\dfrac{1}{r}\\right) g(\\br,\\br') \\hat{\\bb{k}} \\]\n%\n%\\subsection{Spectral Representation}\n%\n%The spectral representation of the exponent is \n%\n%\\[ \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{\\vert \\br - \\br' \\vert}  \\approx \\dfrac{ik}{4\\pi} \\int e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) e^{i\\bb{k}\\cdot(\\br' - \\br_s) }d\\Omega \\]\n%\n%The far field scalar Green's function is then\n%\n% \\[ g(\\br,\\br') \\approx \\dfrac{ik}{16\\pi^2} \\int e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) e^{i\\bb{k}\\cdot(\\br' - \\br_s) }d\\Omega \\]\n%\n%And the dyadic Green's function is\n%\n%\n%\\begin{equation}\n% \\overline{\\bb{G}}_f(\\br,\\br') \\approx \\dfrac{ik}{16\\pi^2} \\int  \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right]  e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) e^{i\\bb{k}\\cdot(\\br' - \\br_s) }d\\Omega \n% \\end{equation}\n%\n%\\subsubsection{Source Volume Integral}\n%\n%The electric field due to a source is \n%\n%\\[ \\bb{E}(\\br) = i \\omega \\mu \\int \\overline{\\bb{G}}_f(\\br,\\br') \\cdot \\bb{J}(\\br') dV \\]\n%\n%Substituting the dyadic Green's function we can write this\n%\n%\\[ \\bb{E}(\\br) =  \\dfrac{i k}{4 \\pi}  \\int \\bb{F}(\\hat{\\bb{k}})  e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) d\\Omega  \\]\n%\n%where\n%\n%\\[\\bb{F}(\\hat{\\bb{k}}) =  \\dfrac{1}{4 \\pi}  (i \\omega \\mu) \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot \\int  e^{i\\bb{k}\\cdot(\\br' - \\br_s) }\\bb{J}(\\br') dV \\]\n%\n%where $\\bb{F}(\\hat{\\bb{k}}) $ is the far pattern of the source.\n%\n%\\subsubsection{Surface Integrals}\n%\n%The reflected and transmitted fields above and below the boundary, respectively, are given by\n%\n%\\begin{eqnarray}\n%\\bb{E}_r(\\br) & = & \\int_S dS' \\left\\{ i\\omega \\mu \\G{1} \\cdot \\hat{n}' \\times \\bb{H}(\\br') + \\left[\\nabla \\times \\G{1} \\right] \\cdot \\hat{n}' \\times \\bb{E}(\\br')\\right\\} \\nonumber \\\\\n%\\bb{E}_t(\\br) & = & \\int_S dS' \\left\\{ i\\omega \\mu \\G{2} \\cdot \\hat{n}_d' \\times \\bb{H}(\\br') + \\left[\\nabla \\times \\G{2} \\right] \\cdot \\hat{n}_d' \\times \\bb{E}(\\br')\\right\\}  \\nonumber\n%\\end{eqnarray}\n%\n%where $\\hat{n}$ and $\\hat{n}_d$ are the outward and inward pointing surface normals, and $\\bb{E}$ and $\\bb{H}$ are the fields on the boundary.\n%\n%Generically, these are \n%\n%\\begin{eqnarray}\n%\\bb{E}(\\br) & = & \\int_S dS' \\left\\{ i\\omega \\mu \\G{} \\cdot \\hat{n}' \\times \\bb{H}(\\br') + \\left[\\nabla \\times \\G{} \\right] \\cdot \\hat{n}' \\times \\bb{E}(\\br')\\right\\} \\nonumber \\\\\n%\\end{eqnarray}\n%\n%Substituting the far field dyadic Green's function \n%\n%\\begin{eqnarray}\n%\\bb{E}(\\br) & = & \\int_S dS' \\left\\{ i\\omega \\mu \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] g(\\br,\\br')  \\cdot \\hat{n}' \\times \\bb{H}(\\br') \\right. \\nonumber \\\\\n%\\ & \\ & \\left. + \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot \\left( i k g(\\br,\\br')\\right) \\left(  \\hat{\\bb{k}} \\times \\left( \\hat{n}' \\times \\bb{E}(\\br')\\right)\\right) \\right\\} \\nonumber \n%\\end{eqnarray}\n%\n%which is\n%\n%\\begin{eqnarray}\n%\\bb{E}(\\br) & = & \\int_S dS' \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot  \\left( i\\omega \\mu \\left(\\hat{n}' \\times \\bb{H}(\\br')\\right) +  i k  \\hat{\\bb{k}} \\times \\left( \\hat{n}' \\times \\bb{E}(\\br')\\right)   \\right) g(\\br,\\br')  \\nonumber \n%\\end{eqnarray}\n%\n%As before, substitute the spectral representation of the scalar Green's function, we can write fields as\n%\n%\\[ \\bb{E}(\\br) =  \\dfrac{i k}{4 \\pi} \\int \\bb{F}(\\hat{\\bb{k}})  e^{i\\bb{k}\\cdot(\\br - \\br_o)} T_L(\\bb{k},\\bb{X}) d\\Omega  \\]\n%\n%\\[\\bb{F}(\\hat{\\bb{k}}) =  \\dfrac{1}{4 \\pi} \\int \\left[\\overline{\\bb{I}} - \\hat{\\bb{k}} \\hat{\\bb{k}} \\right] \\cdot   \\left( i\\omega \\mu \\left(\\hat{n}' \\times \\bb{H}(\\br')\\right) +  i k  \\hat{\\bb{k}} \\times \\left( \\hat{n}' \\times \\bb{E}(\\br')\\right)   \\right)  e^{i\\bb{k}\\cdot(\\br' - \\br_s) } dS' \\]\n%\n%Next assume the incident field has the form \n%\n%\\[ \\bb{E}_{inc}(\\br) =  \\dfrac{i k}{4 \\pi} \\int \\bb{F}_{inc} (\\hat{\\bb{k}}')  e^{i\\bb{k}'\\cdot(\\br - \\br_o)} T_L(\\bb{k}',\\bb{X}) d\\Omega'  \\]\n%\n%For plane waves, the magnetic field is\n%\n%\\[ \\bb{H}_{inc}(\\br) = \\dfrac{1}{\\eta} \\hat{\\bb{k}} \\times \\bb{E}_{inc}(\\br) \\]\n%\n%The goal is the write $\\bb{F}(\\hat{\\bb{k}})$ as \n%\n%\\[ \\bb{F}(\\hat{\\bb{k}}) = \\int \\overline{\\bb{S}}(\\hat{\\bb{k}},\\hat{\\bb{k}}') \\cdot  \\bb{F}_{inc} (\\hat{\\bb{k}}') T_L(\\bb{k}',\\bb{X}) d\\Omega' \\]\n%\n%where $\\overline{\\bb{S}}(\\hat{\\bb{k}},\\hat{\\bb{k}}')$ is the scattering matrix.  \n%\n%\n%%\n%%\\section{Dyadic Green's Function Representations}\n%%\n%%\\subsection{Forms of the Dyadic Green's Function}\n%%\n%%\\subsubsection{Form 1}\n%%\n%%The explicit expression for the dyadic Green's function is given by\n%%\n%%\\begin{equation}\n%% \\overline{\\bb{G}}(\\br,\\br') = \\left[\\overline{\\bb{I}} + \\dfrac{1}{k^2} \\nabla\\nabla \\right] \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi \\vert \\br - \\br' \\vert}\n%% \\end{equation}\n%%\n%%See Chapter 1 for details.\n%%\n%%\\subsubsection{Form 2}\n%%\n%%The dyadic Green's function written as an expansion of vector wave functions is\n%%\n%%\\begin{equation}\n%%\\overline{\\mathbf{G}}(\\br,\\br') = \n%%ik\\displaystyle\\sum\\limits_{lm} \\dfrac{1}{l(l+1)}\\left[\\M{\\br}\\Re\\Mhat{\\br'}  +  \\N{\\br}\\Re\\Nhat{\\br'}\\right] \n%%\\end{equation}\n%%\n%%for $\\vert \\br' \\vert < \\vert \\br \\vert $.\n%%\n%%\n%%\n%%\\subsubsection{Form 3}\n%%\n%%The far-field approximation of the dyadic Green's function used in the FMM is given by\n%%\n%%\\begin{equation}\n%%\\overline{\\mathbf{G}}(\\br,\\br') \\approx \\dfrac{ik}{4\\pi} \\int_S \\left(\\overline{\\bb{I}} - \\hat{\\bb{k}}\\hat{\\bb{k}}'\\right) \n%%e^{i \\bb{k}\\cdot(\\bb{r}-\\bb{r}_o) } T_L(\\bb{k},\\bb{X}) e^{-i \\bb{k}\\cdot(\\bb{r}'-\\bb{r}_s) } d^2\\hat{\\bb{k}}\n%%\\end{equation}\n%%\n%%where \n%%\n%%\\begin{eqnarray}\n%%\\bb{r} &=& \\textrm{Observation point} \\nonumber \\\\\n%%\\bb{r}_o &=& \\textrm{Observation frame origin} \\nonumber \\\\\n%%\\bb{r}' &=& \\textrm{Source point} \\nonumber \\\\\n%%\\bb{r}_s &=& \\textrm{Source frame origin} \\nonumber \\\\\n%%\\bb{X} = \\bb{r}_o - \\bb{r}_s &=& \\textrm{Vector between origins} \\nonumber \\\\\n%%\\bb{k} = k \\hat{\\bb{k}}  &=& \\textrm{Wave vectors of the expansion} \\nonumber \\\\\n%%\\hat{\\bb{k}} &=& \\textrm{Plane wave directions on the unit sphere}\\nonumber\n%%\\end{eqnarray}\n%%\n%%\n%%\\subsection{Equivalency}\n%%\n%%We want to show the equivalent between all three forms of the dyadic Green's function.  This is to validate the computation of $T_L(\\bb{k},\\bb{X})$.  The electric field radiated from a current density $\\bb{J}(\\bb{r})$ is given by\n%%\n%%\\begin{equation}\n%%\\bb{E}(\\br) = i\\omega\\mu\\int \\overline{\\bb{G}}(\\br,\\br')\\cdot \\bb{J}(\\bb{r}) dV'\n%%\\end{equation}\n%%\n%%Let the current density be a Hertzian dipole at the origin\n%%\n%%\\[ \\bb{J}(\\bb{r})  = I \\hat{z} \\delta(\\br) \\]\n%%\n%%\\subsubsection{Form 1}\n%%\n%%Substituting the current density above into the integral above and using the Cartesian form of the dyadic Green's function the electric field everywhere is\n%%\n%%\\begin{eqnarray}\n%%\\bb{E}(\\br) &=& i\\omega\\mu\\int \\overline{\\bb{G}}(\\br,\\br')\\cdot I \\hat{z} \\delta(\\br') dV' \\\\\n%%\\ &=& i\\omega\\mu I \\thrcol{G_{xz}(\\br,0) }{G_{yz}(\\br,0) }{G_{zz}(\\br,0)}\n%%\\end{eqnarray}\n%%\n%%\\subsubsection{Form 2}\n%%\n%%\\begin{eqnarray}\n%%\\bb{E}(\\br) &=& i\\omega\\mu\\int \\overline{\\bb{G}}(\\br,\\br')\\cdot I \\hat{z} \\delta(\\br') dV' \\\\\n%%\\ &=& i\\omega\\mu \\int ik\\displaystyle\\sum\\limits_{lm} \\dfrac{1}{l(l+1)}\\left[\\M{\\br}\\Re\\Mhat{\\br'}  +  \\N{\\br}\\Re\\Nhat{\\br'}\\right] \\cdot I \\hat{z} \\delta(\\br') dV' \\\\\n%%\\ &=& \\displaystyle\\sum\\limits_{lm} a_{lm} \\M{\\br}  + b_{lm} \\N{\\br}\n%%\\end{eqnarray}\n%%\n%%where\n%%\n%%\\begin{eqnarray}\n%%a_{lm} &=& \\dfrac{1}{l(l+1)}i\\omega\\mu (ik) I \\Re\\Mhat{0}  \\cdot \\hat{z} \\\\\n%%b_{lm} &=& \\dfrac{1}{l(l+1)}i\\omega\\mu (ik) I \\Re\\Nhat{0}  \\cdot \\hat{z}\n%%\\end{eqnarray}\n%%\n%%The $z$ unit vector can be written $\\hat{z} = \\cos\\theta \\hat{r} - \\sin\\theta \\hat{\\theta}$.  \n%%\n%%The Bessel function expressions in the regular wave functions have the following limits at the origin\n%%\n%%\\begin{eqnarray}\n%%j_l(kr) &=& 0, \\quad l \\ge 1 \\\\ \n%%j_l(kr)/kr  &=& 1/3, \\quad l = 1 , \\quad 0, \\quad \\textrm{o.w.}\\\\\n%%\\dfrac{[krj_l(kr)]'}{kr} &=& 2/3, \\quad l = 1, \\quad 0, \\quad \\textrm{o.w.}\n%%\\end{eqnarray}\n%%\n%%\n%%\n%%\n%%\\begin{eqnarray}\n%%a_{lm} &=& 0 \\\\\n%%b_{lm} &=& i\\omega\\mu (ik) I \\Re\\Nhat{0}  \\cdot \\hat{z}\n%%\\end{eqnarray}\n%%\n%%\n%%\\subsubsection{Form 3}\n%%\n%%\n%\n%\n", "meta": {"hexsha": "6e6fafd676a5a43864ec70c58f8f6dc991a6ccc3", "size": 153336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/FastMultipoleMethod/FMM.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/FastMultipoleMethod/FMM.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/FastMultipoleMethod/FMM.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": 65.4722459436, "max_line_length": 1232, "alphanum_fraction": 0.7046094851, "num_tokens": 50096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6950680626911987}}
{"text": "\n\\subsection{The Harrod-Domar model}\n\n\\subsubsection{Introduction to growth models}\n\nWe have output as a function of capital.\n\n\\(Y=f(K)\\)\n\nWe also have capital dynamics.\n\n\\(\\dot K=I-\\delta K\\)\n\n\\(I=S=sY\\)\n\nThis gives us:\n\n\\(\\dot K = sY-\\delta K\\)\n\n\\subsubsection{Introduction}\n\nThe production function is:\n\n\\(Y=cK\\)\n\nThis gives us:\n\n\\(\\dot K=(sc-\\delta )K\\)\n\n\\subsubsection{Growth}\n\n\\(\\dot Y=c\\dot K \\)\n\n\\(\\dfrac{\\dot Y}{Y}=c\\dfrac{\\dot K}{Y}\\)\n\n\\(\\dfrac{\\dot Y}{Y}=c\\dfrac{(sc-\\delta )K}{cK}\\)\n\n\\(\\dfrac{\\dot Y}{Y}=sc-\\delta \\)\n\n\\subsubsection{Per-capita growth}\n\nPer capita income is:\n\n\\(y=\\dfrac{Y}{L}\\)\n\n\\(k=\\dfrac{K}{L}\\)\n\n", "meta": {"hexsha": "f7b768f924b983c0928701585f6e78a01d948ebe", "size": 628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/neoClassical/03-01-harrodDomar.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/neoClassical/03-01-harrodDomar.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/neoClassical/03-01-harrodDomar.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.0833333333, "max_line_length": 48, "alphanum_fraction": 0.6257961783, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.695000495575418}}
{"text": "\\chapter{Summary of Babu, Krishnan and Paleri}\n\\label{chap:chapter5}\n\nOne of the problems with other former approaches to Herbrand \nequivalence is that most of the alogrithms were based on fix point \ncomputations. But the classical definition of Herbrand equivalence is \nnot a fix point based definition making it difficult to prove their \nprecision or completeness. Babu, Krishnan and Paleri \\cite{Babu} gave \na new lattice theoretic formulation of Herbrand equivalences and \nproved its equivalence to the classical version.\n\nThe paper defines a congruence relation on the set of all possible \nexpressions and shows that the set of all congruences for a complete \nlattice. Then for a given dataflow framework with $n$ program points, \na continuous composite transfer function is defined over the n-fold \nproduct of the above lattice such that the maximum fix point of the \nfunction yields the set of Herbrand equivalence classes at various \nprogram points. Finally, equivalence of this approach to the \nclassical meet over all path definition of Herbrand Equivalence is \nestablished.\n\nBelow is a brief summary of the developments in the paper, for more \ndetailed approach and proofs and for equivalence to MOP  \ncharacterization refer to \\cite{Babu}.\n\n\\section{Program Expressions}\n\nLet $C$ and $X$ be the set of constants and variables occurring in \nthe program respectively. The program expressions (terms) can be \ndescribed as \n$$t\\; ::=\\; c\\; |\\; x\\; |\\; t_1 + t_2$$\nwhere $c \\in C$ and $x \\in X$.\n\n\\section{Congruence Relation}\nLet $T$ be the set of all program terms. A partition $P$ of terms in $T$ is said to be a congruence (of terms) if \n\\begin{itemize}\n    \\item For $t$, $t'$, $s$, $s'$ $\\in$ $T$, $t' \\cong t$ and $s' \\cong s$ iff $t' + s' \\cong t + s$. \n    \\item For $c \\in C$, $t \\in T$, if $t \\cong c$ then either $t = c$ or $t \\in X$.\n\\end{itemize}\nLet $G(T)$ be the set of all congruences over $T$. We say $P_1 \n\\preceq P_2$ for $P_1, P_2 \\in G(T)$, if \n$\\forall A_1 \\in P_1, \\exists A_2 \\in P_2$ such that \n$A_1 \\subseteq A_2$. We define \\textit{confluence} operation as \n$$P_1 \\land P_2\\; =\\; \\{A_i \\cap B_j\\: |\\: A_i \\in P_1 \\text{ and } B_j \\in P_2\\}$$\nNow, we extend $G(T)$ to $\\overline{G(T)}$ by introducing abstract \ncongruence $\\top$ satisfying \n$P \\land \\top = \\top, \\forall P \\in \\overline{G(T)}$.\nAlso, we denote the congruence in which every element is in a \nseparate class as $\\bot$. \n\n$(\\overline{G(T)}, \\preceq, \\bot, \\top)$ \nforms a complete lattice, with $\\land$ as meet operator.\n\n\\section{Transfer function}\nAn assignment $y := \\beta$ transforms a congruence $P$ to another \ncongruence $P'$. This can be described in the form of transfer \nfunction $f_{y = \\beta}:G(T) \\to G(T)$, given by\n\\begin{itemize}\n    \\item $B_i = \\{t \\in T\\ |\\ t[y \\leftarrow \\beta] \\in A_i\\}, \\text{ for each } A_i \\in P$\n    \\item $f_{y = \\beta}(P) = \\{B_i\\ | \\ B_i \\neq \\phi\\}$\n\\end{itemize}\nWe extend this definition to form extended transfer function, \n$\\overline{f}_{y=\\beta} : \\overline{G(T)} \\to \\overline{G(T)}$ \nby defining $\\overline{f}_{y=\\beta}(\\top)\\ =\\ \\top$, otherwise $\\overline{f}_{y=\\beta}(P) = f_{y=\\beta}(P)$.\nThe extended transfer function is distributive, monotonic and continuous.\n\n\\section{Non deterministic assignment}\nAn assignment $y := *$ transforms a congruence $P$ to another \ncongruence $P'$. This can be described in the form of another \ntransfer function $f_{y = *}:G(T) \\to G(T)$, given by: \nfor every $t$, $t' \\in T$, $t \\cong_{f(P)} t'$, (here $f(P) = f_{y = *}(P)$ for simplicity) iff\n\\begin{itemize}\n    \\item $t \\cong_P t'$\n    \\item $\\forall \\beta \\in (T \\setminus T(y)),\\ t[y \\leftarrow \\beta] \\cong_p t'[y \\leftarrow \\beta]$\n\\end{itemize}\nAs before we extend this transfer function to \n$\\overline{f}_{y=*} : \\overline{G(T)} \\to \\overline{G(T)}$ by defining\n$\\overline{f}_{y=*}(\\top)\\ =\\ \\top$, otherwise \n$\\overline{f}_{y=*}(P) = f_{y=*}(P)$. \nThe function $\\overline{f}_{y=*}$ is also continuous.\n\n\\section{Dataflow analysis Framework}\nA dataflow framework over $T$ is $D = (G, F)$ where $G(V, E)$ is the \ncontrol flow graph associated with the program and $F$ is a \ncollection of transfer function associated with program points.\n\n\\section{Herbrand Equivalence}\nThe Herbrand Congruence function $H_D : V(G) \\to \\overline{G(T)}$ \ngives the Herbrand Congruence associated with each program point and \nis defined to be the maximum fix point of the \\textit{continuous\ncomposite transfer function} \n$f_D : \\overline{G(T)}^n \\to \\overline{G(T)}^n$, where \n$\\overline{G(T)}^n$ is the product lattice, $f_D$ is a function satisfying $\\pi_k \\circ f_D = f_k$. Here $\\pi_k$ is the projection map\nand $f_k : \\overline{G(T)}^n \\to \\overline{G(T)}$ is defined as follows \n\\begin{itemize}\n    \\item   If k = 1, the entry point of the program $f_k = \\bot$.\n    \\item   If k is a function point with $Pred(k) = \\{j\\}, \\text{ then } f_k = h_k \\circ \\pi_j$ where \n    $h_k$ is the extended transfer function corresponding to function point k.\n    \\item   If k is a confluence point with $Pred(k) = {i, j}, \\text{ then } f_k = \\pi_{i, j}, \\text{ where }\n    \\pi_{i, j}:\\overline{G(T)}^n \\to \\overline{G(T)}$ is given by $\\pi_{i,j}(P_1,\\ \\dots,\\ P_n) = P_i \\land P_j$.\n\\end{itemize}.", "meta": {"hexsha": "93e78a8b9074f86e9f3c2bbfcfd868baeb794c8a", "size": 5221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Rep_End_7/chapter5.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_End_7/chapter5.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_End_7/chapter5.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": 51.6930693069, "max_line_length": 134, "alphanum_fraction": 0.6877992722, "num_tokens": 1689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6949921792830389}}
{"text": "\\begin{solution}\nIn this problem we interpolate the different functions using polynomial interpolation on Chebishev nodes. The rate of convergence is given in the next figure. Observe that the rate of convergence is the highest for the function of part d,since it is infinitely smooth, followed by the function of part c,a and b. The order of this convergence is because of the smoothness of the different functions. In real numbers the function of part c is infinitely smooth as well, whereas the other two functions arent.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[$f(x)=|x|^3$.]{\\includegraphics[scale=0.5]{IMAGES/problem4a.eps}}\n\\hfill\n\\subfigure[$f(x)=exp\\left(\\frac{-1}{\\sin{(2x^2)}}\\right)$.]{\\includegraphics[scale=0.5]{IMAGES/problem4b.eps}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[$f(x)=\\frac{1}{\\sin{(1+x^2)}}$.]{\\includegraphics[scale=0.5]{IMAGES/problem4c.eps}}\n\\hfill\n\\subfigure[$f(x)=\\sinh{x}$.]{\\includegraphics[scale=0.5]{IMAGES/problem4d.eps}}\n\\hspace*{\\fill}\n\\caption{Error of the polynomial interpolation on Chebyshev nodes for the different functions.}\n\\end{figure}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n% Part a\nN = 1:100;\nerr = 0*N;\nff = @(x) abs(x).^3;\nf = chebfun(ff,'splitting','on');\nfor k = 1:length(N)\n    n = N(k);\n    g = chebfun(ff,n);\n    err(k) = norm(f-g,inf);\nend\nfigure\nloglog(N,err,'*',N,N.^-1,'--',N,N.^-3,'--')\nset(gca,'fontsize',14)\ngrid on\nxlabel('$N$ (log scale)','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem4a','epsc')\n% Part b\nff = @(x) exp(-1/sin(2*x^2));\nf = chebfun(ff,'splitting','on');\nfor k = 1:length(N)\n    n = N(k);\n    g = chebfun(ff,n);\n    err(k) = norm(f-g,inf);\nend\nfigure\nsemilogy(N,err,'*',N,N.^-1,'--',N,N.^-3,'--')\nset(gca,'fontsize',14)\ngrid on\nxlabel('$N$','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem4b','epsc')\n\n% Part c\nff = @(x) 1/sin(1+x^2);\nf = chebfun(ff,'splitting','on');\nfor k = 1:length(N)\n    n = N(k);\n    g = chebfun(ff,n);\n    err(k) = norm(f-g,inf);\nend\nfigure\nsemilogy(N,err,'*',N,N.^-1,'--',N,N.^-3,'--')\nset(gca,'fontsize',14)\ngrid on\nxlabel('$N$ ','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem4c','epsc')\n\n% Part d\nff = @(x) sinh(x)^2;\nf = chebfun(ff,'splitting','on');\nfor k = 1:length(N)\n    n = N(k);\n    g = chebfun(ff,n);\n    err(k) = norm(f-g,inf);\nend\nfigure\nsemilogy(N,err,'*',N,N.^-1,'--',N,N.^-3,'--')\nset(gca,'fontsize',14)\ngrid on\nxlabel('$N$ (log scale)','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem4d','epsc')\n\\end{verbatim}\n\n\n\\end{solution}\n", "meta": {"hexsha": "078a1aa2bbf698950e3c96310c7f51ee6b6959bb", "size": 2832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 1/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 1/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 1/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": 32.1818181818, "max_line_length": 507, "alphanum_fraction": 0.6546610169, "num_tokens": 932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.6949921667672478}}
{"text": "\\chapter{Generalized Linear Models \\label{chapter:glms}}\n\nLinear and logistic regression, which we have seen already in Chapters~\\ref{chapter:classification}, \\ref{chapter:regression}, \\ref{chapter:linreg}, and \\ref{chapter:logreg}, are members of a broader class of supervised learning models called \\textbf{generalized linear models (GLMs)}. In GLMs, the outcome variable, $y$, is assumed to follow a probability distribution of a particular type. For example, in linear regression, $y$ follows a normal distribution. In logistic regression, $y$ is binary $\\left( y \\in \\{0, 1\\} \\right)$ and follows a Bernoulli distribution\\footnote{In \\textbf{grouped} logistic regression, it follows a binomial distribution.}. The expected value, or mean, of the outcome distribution is related to a \\textbf{linear combination} of the predictors, $\\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p$, via a model-specific \\textbf{link function}.\n\nGLMs, like maximum likelihood (Chapter~\\ref{chapter:mlebasics}), are normally considered an advanced topic. However, they provide a nice example of how the same formalism -- modeling the response variable using a probability distribution, assuming a certain form for the predictors, optimizing the whole thing using maximum likelihood -- can be applied to solve different-looking problems. They are also a good entryway into the sorts of optimization tasks performed by graphical models and deep learning algorithms. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Model Assumptions}\n\nGLMs require us to make several assumptions which affect both our choice of model and our interpretation of model output:\n\n\\begin{enumerate}\n\\item We assume that the outcome follows a certain type of distribution (e.g. Bernoulli distribution for a logistic regression model, normal for linear, etc.) conditional on the predictors. This assumption is baked into the model structure. It is, therefore, important to consider whether the outcome distribution you chose actually makes sense for your particular problem. It is generally not advisable to use a linear regression model, for example, when your outcome is a count. \n\\item We assume that the predictors are fixed and known, and thus have no error associated with their measurements\\footnote{Bayesian versions of these models relax this assumption.}.\n\\item We assume that the predictors enter the model as a linear combination, $\\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p$. This is why GLMs are referred to as ``linear models''. \n\\item We assume that the $n$ samples in our dataset are collected independently, so that the errors of the $n$ sample outcomes are uncorrelated\\footnote{Think back to our formulation of the likelihood in Chapter~\\ref{chapter:mlebasics} and how it depended on the samples' being independent and identically distributed, or iid.}.\n\\end{enumerate}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Notation for the Predictors}\n\nAs mentioned above, GLMs assume that the predictors enter the model as a linear combination. A linear combination is an expression constructed from a set of terms by multiplying each term by a constant and adding the results. We denote the number of predictors in the model by $p$ and the vector of predictors by $x$, where\n$$ x = \\begin{bmatrix}\n1 \\\\\n           x_{1} \\\\\n           x_{2} \\\\\n           \\vdots \\\\\n           x_{p}\n         \\end{bmatrix} $$\nand we have included a ``1'' as the first element to allow for an \\textbf{intercept}. We write $x^{(i)}$ to denote the vector of predictors associated with the $i$th training example. The coefficients of the linear combination (i.e. the model parameters we are hoping to learn) are denoted by:\n$$ \\beta = \\begin{bmatrix}\n\\beta_0 \\\\\n           \\beta_{1} \\\\\n           \\beta_{2} \\\\\n           \\vdots \\\\\n           \\beta_{p}\n         \\end{bmatrix} $$\nand we often express the linear combination as an \\textbf{inner product}, or \\textbf{dot product}, of the two vectors, written as\n$$ \\beta^T x = \\beta_0 + \\sum_{j=1}^p \\beta_j x_j. $$\nThis is just notational shorthand. \n\\vspace{3mm}\n\n\\begin{question}{}\nWe saw the details of linear and logistic regression models in Chapters~\\ref{chapter:linreg} and \\ref{chapter:logreg} and discussed the limitations of predictors' entering as a linear combination. What are some of those limitations?\n\\end{question}\n\n\\begin{question}{}\nJust to confirm that you understand this notation, write out the form of $\\beta^Tx$ for a model with (a) one predictor, (b) three predictors. Write both the general form and the form for one training example, $x^{(i)}$. \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Modeling the Outcome}\n\nGeneralized linear models model the expected value of the outcome, $E[y]$, as a function of this linear combination of predictors.\n\n\\subsection{Linear Regression}\n\nIn linear regression, we assume that the outcome, $y$, follows a normal distribution (see Section~\\ref{sect:normal}), whose mean is controlled by the values of the predictors. Recall that the normal distribution is a continuous probability distribution with the following properties:\n$$ p(y) = \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} e^{-\\frac{(y-\\mu)^2}{2 \\sigma^2}} \\qquad  E[y] = \\mu \\qquad \\text{var}(y) = \\sigma^2 $$\nwhere $y \\in \\mathbb{R}$. Its mean, $\\mu$, can be any real number. To link $\\mu$ to the predictors, therefore, we simply set it equal to $\\beta^Tx$, like so:\n\\begin{equation} E[y] = \\mu = \\beta^T x \\label{eqn:meanlinear} \\end{equation}\nThis is called using the \\textbf{identity link}. The relationship between $E[y] = \\mu$ and $\\beta^T x$ is shown below.\n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/l02-figure1-linreg.png}\n\\end{center}\n\n\\vspace{3mm}\n\n\\begin{question}{}\nIn this model, how much does the mean of the outcome distribution, $\\mu$, change as you vary each predictor? For example, if you have $p=3$ predictors, by how much does $\\mu$ change as the value of $x_2$ changes by one unit (for example, from $1$ to $2$)? How much does $\\mu$ change as the value of $x_2$ changes from $3$ to $4$? What about $x_1$ and $x_3$?\n\\end{question}\n\n\\subsection{Logistic Regression}\n\nIn logistic regression the outcome, $y$, is either $0$ or $1$. We model it using the Bernoulli distribution (see Section~\\ref{sect:bernoulli}), which is a discrete probability distribution with the following properties:\n$$ p(y) = \\mu^y (1 - \\mu) ^ {1-y} \\qquad E[y] = \\mu \\qquad \\text{var}(y) = \\mu (1 - \\mu) $$\nwhere $y \\in \\{0, 1\\}$. Because $\\mu$ is a probability, it must be a real number between 0 and 1. No matter how large or small $\\beta^T x$ gets, the value of $E[y] = \\mu$ cannot be outside this range. We therefore apply the \\textbf{logistic function}, $f(x) = 1/(1 + \\exp(-x))$, which has the range $(0, 1)$, to $\\beta^T x$ to squash it:\n\\begin{equation} E[y] = \\mu = \\frac{1}{1 + \\exp{(-\\beta^Tx)}} \\label{eqn:meanlogistic} \\end{equation}\nThe relationship between $E[y]$ and $\\beta^T x$ is shown below. We typically invert the model to write\n$$ \\log{\\frac{\\mu}{1-\\mu}} = \\beta^T x. $$\nThe function $\\log \\left( \\mu/(1-\\mu) \\right)$ is called the logit, and we say we use the \\textbf{logit link}.\n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/l02-figure2-logistic.png}\n\\end{center}\n\n\\vspace{3mm}\n\n\\begin{question}{}\nLet's revisit Question~\\ref{question:logreglink}. Now that we've described logistic regression in the framework of GLMs, what more can you say about why the model is not of the form\n$$ \\mu = \\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p \\text{?}$$\n\\end{question}\n\n\\subsection{Poisson Regression}\n\nIn Poisson regression, the outcome is a count. We model the outcome using a Poisson distribution, which is a discrete probability distribution with the following properties (Section~\\ref{sect:poisson}):\n$$ p(y) = \\frac{e^{-\\lambda} \\lambda^y}{y!} \\qquad E[y] = \\lambda \\qquad \\text{var}(y) = \\lambda $$\nwhere $y \\in 0, 1, 2, \\dots$. Because $\\lambda$, the mean of the outcome distribution, is the expected value of a count, it must be a real number greater than or equal to zero. In particular, no matter how small $\\beta^T x$ gets, the value of $E[y] = \\lambda$ cannot be negative. We therefore exponentiate $\\beta^T x$ to ensure that $\\lambda$ is greater than zero:\n\\begin{equation} E[y] = \\lambda = \\exp(\\beta^T x) \\label{eqn:meanpoisson} \\end{equation}\nThe relationship between $E[y]$ and $\\beta^T x$ is shown below. We typically invert the model to write\n$$ \\log(\\lambda) = \\beta^T x $$\nwhich is the standard form of the Poisson regression model. We say these models use the \\textbf{log link}.\n\n\\vspace{3mm}\n\n\\begin{question}{}\nThere are many other generalized linear models. In each case, the mean (expected value) of a probability distribution is related, via a link function, to a linear combination of the predictors. \n\nKnowing this, how would you create a GLM where the outcome follows an exponential distribution (Section~\\ref{sect:exponential})? Which link would you use?\n\\end{question}\n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/l02-figure3-poisson.png}\n\\end{center}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Maximum Likelihood for GLMs \\label{section:mleglms}}\n\nGLMs are fit using maximum likelihood estimation (see Chapter~\\ref{chapter:mlebasics}). A full treatment of MLE for GLMs is outside the scope of these notes, but I've put the start of the calculations for each type of model below. The only difference between these calculations and those in Chapter~\\ref{chapter:mlebasics} is that now our parameters of interest, the means of our outcome distributions, are functions of our predictors $x_1, \\dots, x_p$. Our job is to find the coefficients on those predictors, $\\beta_0, \\dots, \\beta_p$, that provide the best fit between our model and our training data.\n\n\\subsection{Linear Regression} \n\nThe likelihood for the linear regression model is:\n$$ \\mathcal{L}(\\mu^{(1)}, \\dots, \\mu^{(n)}, \\sigma) = \\prod_{i=1}^n \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} \\exp \\left[ - \\frac{(y^{(i)} - \\mu^{(i)})^2}{2 \\sigma^2} \\right] $$\nwhere we use $\\mu^{(i)}$ to represent the model's estimate of the mean of the outcome at the position of training example $i$. We can use Equation~\\ref{eqn:meanlinear} to rewrite this as a function of the predictors:\n$$ \\mathcal{L}(\\beta, \\sigma) = \\prod_{i=1}^n \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} \\exp \\left[ - \\frac{(y^{(i)} - \\beta^T x^{(i)})^2}{2 \\sigma^2} \\right] $$\nTaking the log, we obtain the log-likelihood:\n$$ \\log \\mathcal{L}(\\beta, \\sigma) = -\\frac{n}{2} \\log (2 \\pi) - \\frac{n}{2} \\log(\\sigma^2) - \\frac{1}{2 \\sigma^2} \\sum_{i=1}^n \\left( y^{(i)} - \\beta^T x^{(i)} \\right)^2 $$\nTaking derivatives of the log-likelihood with respect to the $\\beta$s, we find that we can maximize the likelihood by minimizing the sum-squares: $\\sum_{i=1}^n \\left( y^{(i)} - \\beta^T x^{(i)} \\right)^2$.\n\n\\vspace{3mm}\n\n\\begin{question}{}\nTake a minute to stare at this result. When most people learn linear regression, they learn that these models are fitted by minimizing the sum of squared residuals (see Chapter~\\ref{chapter:linreg}). Indeed, linear regression models predate GLMs and are typically fit using ordinary least squares, not maximum likelihood. If you fit a linear regression model in R using the \\texttt{lm} package, you're using OLS. If you use the \\texttt{glm} package with the argument \\texttt{family = \"gaussian\"}, you're using maximum likelihood. However, both methods will produce the same fitted models. Do you see why this is?\n\\end{question}\n\n\\subsection{Logistic Regression}\n\nThe likelihood for the logistic regression model is:\n$$ \\mathcal{L}(\\mu^{(1)}, \\dots, \\mu^{(n)}) = \\prod_{i=1}^n {\\mu^{(i)}}^{y^{(i)}} (1-\\mu^{(i)})^{1 - y^{(i)}} $$\nRewriting this as a function of the predictors, we get:\n$$ \\mathcal{L}(\\beta) = \\prod_{i=1}^n \\left( \\frac{1}{1 + \\exp(-\\beta^T x^{(i)})} \\right)^{y^{(i)}} \\left( \\frac{\\exp(-\\beta^T x^{(i)})}{1 + \\exp(-\\beta^T x^{(i)})} \\right)^{1 - y^{(i)}} $$\nTaking the log, we obtain the log-likelihood:\n$$ \\log \\mathcal{L}(\\beta) = \\sum_{i=1}^n \\left[ y^{(i)} \\beta^T x^{(i)} - \\log \\left(1 + \\exp(\\beta^T x^{(i)}) \\right) \\right] $$\nAgain, we will take derivatives of the log-likelihood with respect to the $\\beta$s to maximize it. However, we cannot solve for the optimal $\\beta$s analytically in this case. Numerical optimization methods are used to find the maximum likelihood estimates, $\\hat{\\beta}_0, \\hat{\\beta}_1,$ etc.\n\n\\subsection{Loglinear (Poisson) Regression}\n\nThe likelihood for the Poisson regression model is:\n$$ \\mathcal{L}(\\lambda^{(1)}, \\dots, \\lambda^{(n)}) = \\prod_{i=1}^n \\frac{{\\lambda^{(i)}}^{y^{(i)}} e^{-\\lambda^{(i)}}}{y^{(i)}!} $$\nRewriting this as a function of the predictors, we get:\n$$ \\mathcal{L}(\\beta) = \\prod_{i=1}^n \\frac{\\exp{(y^{(i)} \\beta^T x^{(i)})} e^{-\\exp{(\\beta^T x^{(i)})}}}{y^{(i)}!} $$\nTaking the log, we obtain the log-likelihood:\n$$ \\log \\mathcal{L}(\\beta) = \\sum_{i=1}^n \\left[ y^{(i)} \\beta^T x^{(i)} - \\exp(\\beta^T x^{(i)}) - \\log (y^{(i)}!) \\right] $$\nAs with logistic regression, we cannot solve for the optimal $\\beta$s analytically; numerical optimization methods are used. \n\\vspace{1mm}\n\n\\begin{question}{}\nThink of the log-likelihood as measuring the height of a hill. Your data, \n$$\\left\\{x^{(1)},\\dots,x^{(n)}\\right\\}$$ \ndon't change, so we don't care about their effect on the height. What we care about are the parameters, $\\beta_0, \\dots, \\beta_p$. For each combination of those $p+1$ parameters, the height changes. We want to find the combination of parameters that puts us at the top of the hill. \n\nThe first derivative of the log-likelihood with respect to one of the parameters, $\\beta_j$, is\n$$ \\frac{\\partial \\log \\mathcal{L}}{\\partial \\beta_j} $$\nand the vector of all of these first derivatives for $\\beta_0, \\dots, \\beta_j$ is called the \\textbf{gradient}. Evaluated at a particular set of parameters, the gradient tells you how steep your hill is in the direction of each of your $p+1$ parameters. How could you use this information to maximize the likelihood? You don't need to do any math. Just say how you would do it.\n\\end{question}\n\n\\begin{question}{}\nThere are many different numerical optimization algorithms that one can use to maximize the likelihood (i.e., find the top of the hill). One of them is called \\textbf{Fisher scoring}. Examine the output of the logistic regression models in Chapter~\\ref{chapter:logreg} and the Poisson regression model shown below in Section~\\ref{sect:poisreg}. Where do you see the term ``Fisher scoring''? What do you think the term ``Fisher scoring iterations'' refers to?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Standard Errors and Hypothesis Tests \\label{section:sehyp}}\n\nHere, once again, is the summary output from a logistic regression model of the ER readmissions example from Chapter~\\ref{chapter:classification}, reprinted again in Section~\\ref{sect:eragain}:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/glm-binomial-example.png}\n\\end{center}\nAs we discussed in Chapter~\\ref{chapter:logreg}, the magnitudes of the coefficients in these models matter, but they are only important in relation to:\n\\begin{enumerate}\n\\item The scale on which the predictors are measured. \n\\item The amount of uncertainty the model has about their values.\n\\end{enumerate}\nFor example, if a predictor varies only across a tiny range of values, its model coefficient may be large, since it quantifies the change in the link-function-transformed outcome when the predictor changes by 1.0. However, that doesn't mean that the predictor itself is important to the outcome\\footnote{This is one reason many advocate \\textbf{scaling} and \\textbf{centering} predictors before fitting a model. Centering means subtracting the mean value of a predictor from all of its individual measurements so that the mean of each centered predictor is zero. Scaling means dividing the values of each predictor by their standard deviation, so that the standard deviation of each predictor is 1.0. This enables the relative magnitudes of the model coefficients to be compared directly.}.\n\nSimilarly, the model may be highly uncertain about a coefficient's value, owing to factors like a small dataset (small $n$) or collinearity (correlations) among the predictors. Mathematically, high uncertainty means that the value of the likelihood doesn't change very rapidly as you move away from the maximum likelihood estimate of a coefficient. For example, here is how the log-likelihood for the logistic regression example above changes when we vary $\\beta_1$ (the coefficient of $x_1$), keeping $\\beta_0$ (the intercept) and $\\beta_2$ (the coefficient of $x_2$) fixed at their MLEs: \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-logistic-beta1.png}\n\\end{center}\nThe gray vertical lines are related to the \\textbf{standard error} of the model coefficient, which is in turn related to the ``flatness'' of the likelihood surface around the MLE. The gray lines are situated at 1 and 2 standard errors away from the MLE in either direction. You can see that in the case of $\\beta_1$, the gray lines overlap zero. The value zero (no effect) is a plausible estimate of the impact of $x_1$ on the outcome. \n\nContrast this with how the log-likelihood varies around the MLE for $\\beta_2$:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-logistic-beta2.png}\n\\end{center}\nHere the standard error is larger, but the magnitude of the coefficient is also larger, so the range of the gray lines does not overlap zero.\n\n\\begin{question}{}\nThese findings are reflected in the relative values of the Z-statistic (\\texttt{z value}) and P-value (\\verb|Pr(>|z|)|) in the model output for the two coefficients. With that in mind, let's reconsider Question~\\ref{question:nulllogregexample}. How do these likelihood plots and the null distributions shown in Question~\\ref{question:nulllogregexample} convey the same information?\n\\end{question} \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Example: Nesting Horseshoe Crabs Dataset \\label{sect:poisreg}}\n\nLet's examine some output from a Poisson regression model, which is a type of GLM with which you may not already be familiar. \n\nThese data come from a study of nesting horseshoe crabs. Each of the 173 observed female horseshoe crabs had a male crab resident in her nest. The study investigated factors affecting whether the female crab had any other males, called \\emph{satellites}, residing nearby. (Source: Agresti, \\emph{Categorical Data Analysis}, Table 4.3. Data courtesy of Jane Brockmann, Zoology Department, University of Florida; study described in \\emph{Ethology} \\textbf{102}: 1-21, 1996.)\n\n\\begin{center}\n\\texttt{\\small\n\\begin{tabular}{ll}\n\\toprule\nSATELL & Number of satellites \\\\\nCOLOR & Color of the female crab \\\\\n& (1 = light medium, 2 = medium, 3 = dark medium, \\\\\n& 4 = dark) \\\\\nSPINE & Spine condition \\\\\n& (1 = both good, 2 = one work or broken, \\\\\n& 3 = both worn or broken) \\\\\nWIDTH & Carapace width of the female crab (cm) \\\\\nWEIGHT & Weight of the female crab (g) \\\\\n\\bottomrule\n\\end{tabular}\n}\n\\end{center}\n\n\\noindent The GLM output of this model is:\n\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{img/poisson-horseshoe-model.png}\n\\end{center}\n\n\\begin{question}{}\nComment on how the variables \\texttt{color} and \\texttt{spine} are coded here. Does this make sense in light of what those variables mean?\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 the number of male satellites around a nesting female horseshoe crab? \n\\end{question}\n\n\\begin{question}{}\nHow could you use a decision tree to model the horseshoe crabs data? What are its advantages and disadvantages relative to Poisson regression (a type of GLM)?\n\\end{question}\n\n", "meta": {"hexsha": "512e189f83d6406f1d1303d15df2903fb9e5f65c", "size": 20115, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-generalized-linear-models.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-generalized-linear-models.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-generalized-linear-models.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": 79.8214285714, "max_line_length": 868, "alphanum_fraction": 0.7164305245, "num_tokens": 5422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6949662689840713}}
{"text": "\\lab{Python}{The Standard Library}{Standard Library}\n\\objective{Become familiar with the Python standard library}\n\nOne of the reasons Python is so useful as a scientific computing platform is because\nit is not limited to only scientific computing.  Python has a very large and comprehensive standard library that is available with almost every Python environment.\nIn this lab, we will look at some of the useful parts of Python's standard library.  The standard library is comprised of over a hundred different modules that provide extra functionality to Python.\nModules can be imported via the \\li{import} statement.\n\n\\section*{\\texttt{math} Module}\nThe \\li{math} module and its companion, \\li{cmath} (for complex numbers), are very useful modules.\nCommon mathematical functions are defined in this module such as: \\li{cos}, \\li{sin}, \\li{log}, \\li{sqrt}, etc.  These functions wrap around the functionality of the C math library.\n\n\\begin{problem}\nNumPy also implements these special mathematical functions.  However, there is a difference.\nThe NumPy variants are designed to work with NumPy arrays.  For scalar inputs, the functions\nin Python's \\li{math} or \\li{numpy.math} are much faster.\n\nImport NumPy with \\li{import numpy as np}.  Time how long it takes to execute the following statements.\n\\begin{lstlisting}\nnp.sin(.5)\nmath.sin(.5)\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{\\texttt{random} Module}\nPython includes an implementation of the Mersenne Twister pseudorandom number generator.\nThe \\li{random} module contains many helpful functions for obtaining random numbers.  It also contains functions that operate on sequences.\nThe \\li{randint()} function will return a random integer in a desired interval.  \n\\li{randrange()} will randomly select a random number from a range of numbers (similar to a range generated by \\li{range()}, except it doesn't actually construct the range object).\n\nFor sequences, we can randomly choose elements using the \\li{choice()} function.  If wish to randomly sample a sequence we can use \\li{sample()}, which will return a random sampling of unique elements of desired length from the given sequence.  A sequence can be randomly shuffled in place by the \\li{shuffle()} function.\n\nThe \\li{random} module can sample from several distributions such as the uniform, normal, beta, gamma, exponential, and many others.  NumPy's \\li{random} module is even more fully featured than the standard Python \\li{random} module.\n\n\\section*{\\texttt{csv} Module}\nCSV files are common for exchanging data from databases and tables. \nPython has a very useful module for reading and writing data as comma separated values.\nThe \\li{csv} module provides \\li{reader} and \\li{writer} objects.  There are also analogous \\li{DictReader} and \\li{DictWriter} objects that use dictionaries for handling data.\n\\begin{lstlisting}\nimport csv\n\n#print the contents of a csv_file\nwith open('test.csv', 'r') as csv_file:\n    csv_reader = csv.reader(csv_file)\n    for line in csv_reader:\n        print line\n\\end{lstlisting}\n\nWriting with a CSV \\li{writer} object is very similar to writing with a regular file object.\n\\begin{lstlisting}\ncontents = [[\"Column 1\", \"Column 2\", \"Column 3\"],\n            [0,1,2], [3, 2, 1], [4,5,2], [68, 38, 99]]\nwith open('test_out.csv', 'w') as csv_file:\n    csv_writer = csv.writer(csv_file):\n    for record in contents:\n        csv_writer.writerow(record)\n\\end{lstlisting}\n\n\\begin{problem}\nPractice reading and writing a CSV file.  Read \\texttt{test.csv} and write it to \\texttt{test\\_out.csv}.\nWhen writing the CSV file, you must use a delimiter other than a comma.  Read the Python documentation for\ninstructions of how to do this.\n\\end{problem}\n\n\\section*{\\texttt{sys} Module}\nThe \\li{sys} module allow you to access information specific to the system running Python.\nOne of the most commonly used functions is \\li{sys.argv}.  This returns a list of arguments passed to the current environment.  Accessing these arguments is important.  Many programs are written to execute differently based on the various arguments and options specified at execution.  For example, if we execute our script from the command line as follows\n\\begin{verbatim}\npython myscript.py 5 no yes yes\n\\end{verbatim}\n\\li{sys.argv} would return the list\n\\begin{verbatim}\n[`myscript.py', `5', `no', `yes', `yes']\n\\end{verbatim}\nWe can use \\li{sys.argv} in combination with \\li{argparse} to obtain a full featured argument processing system.\n\n\\section*{\\texttt{pickle} Module}\nThe pickle module turns a Python object into a bytestream and saves it to a file.\nIt can also take a bytestream and turn it back into a Python object.\nPickle can be used to store any builtin Python data type such as lists, tuple, integers, etc.\nNot all Python objects can be pickled.\nDumping a bytestream to a file is easy\n\\begin{lstlisting}\nimport pickle\na = range(10)\npickle.dump(a, open(`out.pkl', `w'))\n\\end{lstlisting}\nWhat pickle does is write a small program that will rebuild your data structures when you read it.\nWhen unpickling a file, pickle executes this file in the interpreter.  Because of this,\npickle is meant to be used as a temporary storage and data persistence mechanism.  It is not designed\nto be used for long term storage of data.  The pickle documentation includes this warning\n\\begin{quote}\n\\textbf{The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.}\n\\end{quote}\nTo unpickle an object on simple use \\li{pickle.load()}.  It accepts a file handle and returns the Python object it creates.\n\n\\begin{problem}\nCreate a list of numbers and strings.  Pickle the object to a file.  Inspect the contents of the file you created when pickling.  Unpickle the object.\n\\end{problem}\n\nThe \\li{pickle} module only allows you to store one object per file.\nIf storing many objects is desired, you may want to use the \\li{shelve} module.\nThis stores objects in a dictionary-like data structure with keys and values.\nThe values are pickled objects.  Since \\li{shelve} relies on \\li{pickle}, the\nsame warning against untrusted sources applies to \\li{shelve} as well.\n\n\\section*{\\texttt{timeit} Module}\nThis module is used to time the execution of small bits of Python code.\nIt is recommended to time lines of Python using this module because it avoids a number of common pitfalls in measuring execution time.  IPython's \\li{\\%timeit} magic function is a wrapper around this module.  \n\n\\begin{problem}\nFor most timing situations, we rely on IPython's \\li{\\%timeit} magic function.\nOne major drawback is it only works in IPython.\nThe solution to this problem will be useful in other labs where you will be\nasked to time the performance of your coded solutions.\nWrite a function that will \ntime the execution of another function.  You will need to use the \\li{timeit} module.\nYour function, should accept as arguments, a function, $f$, and any arguments that\nshould be passed to $f$.  Your function should return the minimum runtime.\n\nBecause of the way that Python's \\li{timeit} module functions, we must use a \\emph{callable}\nfunction.  This essentially means we have to wrap the function we are timing and all of\nits arguments into a function object that can be called by \\li{timeit}.\nThis can be done by declaring a Python \\li{lambda} function which takes no arguments.\n\\begin{lstlisting}\npfunc = lambda: f(*args, **kargs)\n\\end{lstlisting}\nwhere \\li{args} is a tuple and \\li{kargs} is a dictionary.  \nThis syntax is explained in chapter 4 of the Official Python Tutorial).\n\\end{problem}\n\n\n\\section*{\\texttt{os.path} Module}\nThe \\li{os.path} module contains several methods for interfacing with the local file system in a cross-platform manner.\n\\begin{table}[h]\n\\begin{tabular}{|l|p{9cm}|}\n\\hline\n\\li{os.path.abspath} & Return a normalized absolute version given path. \\\\\n\\li{os.path.exists} & Return \\li{True} if given path exists on the file system. \\\\\n\\li{os.path.isfile} & Return \\li{True} if given path refers to an existing file. \\\\\n\\li{os.path.isdir} & Return \\li{True} if given path refers to an existing directory. \\\\\n\\li{os.path.join} & Join one or more elements of a path intelligently, depending on the current platform. \\\\\n\\li{os.realpath} & Return the system's canonical form of a given path. \\\\\n\\li{os.split} & Split a given path into a tuple where the second entry is the final path element and the first element is all elements up to the final element. \\\\\n\\li{os.splitext} & Split a given path into a tuple of two elements where the second entry is the extension of the file referred to by the path.  The first entry contains everything up to the extension separator. \\\\\n\\hline\n\\end{tabular}\n\\caption{Some useful functions provided by \\li{os.path}}\n\\end{table}\n\n\\section*{\\texttt{collections} Module}\nThis module defines several specialized data structures to use in addition to the builtin\nPython data structures.  Some of these useful data structures are named tuples, deques, and a Counter object.\n\nNamed tuples are designed to help improve code readability in some cases.\nStandard tuples in Python are accessed by index.\nNamed tuples allow access via index or by a field name.\nCompare the following\n\\begin{lstlisting}\nfrom collections import namedtuple\npt = (32.1, 63.2)\n\nPt = namedtuple(`Point', `y x')\nnpt = Pt(32.1, 63.2)\n\\end{lstlisting}\nThe tuple \\li{pt} is a standard tuple, which we can surmise represents the coordinates\nof a pt in 2D space.  We must assume that \\li{pt[0]} is the x-coordinate and \\li{pt[1]}\nis the y-coordinate.  When declaring a named tuple, we clearly defined what each index\nrepresents.  We know for certain that \\li{npt.x} is the x-coordinate and that \\li{npt.y}\nis the y-coordinate.\n\nOrdered dictionaries are exactly like standard dictionaries except for one important\ndifference.  Ordered dictionaries remember the order in which key-value pairs were added\nto the data structure.  This data structure is useful if we want to iterate over key-value pairs\nof a dictionary in a specific order.\n\nDefault dictionaries are a very convenient way to set a default value for all new keys in a dictionary.  While this can be done with standard dictionaries using the \\li{setdefault()} method,\nusing a default dictionary is simpler and faster.\n\n\\begin{problem}\nA double-ended queue, or deque, can be thought of as a deck of cards.\nInserting and removing elements from either end is very efficient.\nPython's deque implementation does not allow inserting into any other place\nin the data structure except for the left and right ends.\nA list, however, is very inefficient when adding elements to the front.\nWrite two functions that will rotate the elements of a deque and a list respectively.\nTo rotate, remove elements from the right end one by one and insert them on the left end.\nCompare the timings you obtain from a deque and a list of 10000 elements.\n\\end{problem}\n", "meta": {"hexsha": "bd8606908f29312d0c0f3ea349ef1260806b54c1", "size": 10924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/StandardLibrary/stdlib.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/StandardLibrary/stdlib.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/StandardLibrary/stdlib.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": 57.4947368421, "max_line_length": 356, "alphanum_fraction": 0.7702306847, "num_tokens": 2617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.6949253083115594}}
{"text": "Lists are intrinsically monodimensional, without any additional information besides sequentialisation. The implication of this is that any operation on lists will require to potentially go through the whole list, and we will be sure that we can stop only after having processed all elements. For this reason lists are expensive as containers: as the number of elements of the list grows, so grows the number of steps needed for processing operations.\n\nA solution to this issue is to build data structures where the position of elements within the data structures has some correlation with the value of the elements themselves, and stronger yet with the relationship between the value of each element and the values of other elements. One of the most used such data structures is the binary search tree. A binary search tree is a tree where each node contains an element and two subtrees, which are usually called \\texttt{left} and \\texttt{right}. The \\textit{fundamental search property} of binary trees states that, for any node within the tree, each element is bigger than all elements within the left tree and smaller than all elements within the right tree. Thanks to this fundamental property, when searching a tree for an element we will always be able to determine with a single comparison whether all elements of the left or right subtree may be immediately discarded.\n\nOf course a tree may also be empty. We encode such a tree as follows, with the \\texttt{nil} keyword:\n\n\\begin{lstlisting}\nData [] \"nil\" [] Priority 0 Type BinTreeInt\n\\end{lstlisting}\n\nA node of a tree, encoded with the \\texttt{node} keyword, takes three parameters as input: the left sub-tree, the element of the node, and the right sub-tree:\n\n\\begin{lstlisting}\nData [] \"node\" [BinTreeInt <<int>> BinTreeInt] Priority 1010 Type BinTreeInt\n\\end{lstlisting}\n\nAccording to the definitions above, a tree such as:\n\n\\begin{lstlisting}\n    5\n   / \\\n  2   7\n / \\\n1   3\n\\end{lstlisting}\n\nwould be encoded as: \\texttt{node (node (node nil 1 nil) 2 (node nil 3 nil)) 5 (node nil 7 nil)}.\n\n\\subsection{Insertion}\nAdding an element to a binary tree is not trivial as it is for lists. Whereas in a list we simply use \\texttt{;} to push yet an element on top of the list, for binary trees we must make sure to return a tree which still satisfies the fundamental search property. The \\texttt{add} keyword, which takes a left parameter which is the initial tree, and a right parameter which is the integer value to add, will return a new tree which contains the elements of the initial tree, plus the new element to add, all the while respecting the fundamental search property:\n\n\\begin{lstlisting}\nFunc [BinTreeInt] \"add\" [<<int>>] Priority 100 Class Expr => BinTreeInt\n\\end{lstlisting}\n\nLet us begin with the simplest case of adding an element \\texttt{k} to an empty tree. There is not much to do in this case, since we can simply create a new node with element \\texttt{k} and empty left and right subtrees:\n\n\\begin{lstlisting}\n----------------------------\nnil add k => node nil k nil\n\\end{lstlisting}\n\nIf the current node of the binary tree contains an element which is identical to the one we are inserting, then there is not much to do. In this case we simply return the original tree, as it already satisfied our requirement that the returned tree contains the desired element:\n\n\\begin{lstlisting}\nx == k\n---------------------------------\n(node l x r) add k => node l k r\n\\end{lstlisting}\n\nIf the current node of the binary tree contains an element which is bigger than the element we are adding, then we add the element to the left subtree and we use the resulting left subtree (which contains the elements of \\texttt{l} plus \\texttt{k}) as the left subtree of the final result:\n\n\\begin{lstlisting}\nk < x\nl add k => l'\n----------------------------------\n(node l x r) add k => node l' x r\n\\end{lstlisting}\n\nIf the current node of the binary tree contains an element which is smaller than the element we are adding, then we add the element to the right subtree and we use the resulting right subtree (which contains the elements of \\texttt{r} plus \\texttt{k}) as the right subtree of the final result:\n\n\\begin{lstlisting}\nk > x\nr add k => r'\n------------------------------------\n(node l x r) add k => (node l x r')\n\\end{lstlisting}\n\n\nFor example, consider adding element \\texttt{3} to tree \\texttt{node nil 5 (node nil 7 nil)}:\n\n\\begin{lstlisting}\n5\n \\\n  7\n\\end{lstlisting}\n\nWe start with the following program:\n\n\\begin{lstlisting}\n-----------------------------------------\n(node nil 5 (node nil 7 nil)) add 3 => ?\n\\end{lstlisting}\n\nThe first rule which is applied is the rule for recursion in the left subtree, thus:\n\n\\begin{lstlisting}\n3 < 5\nnil add 3 => l'\n-----------------------------------------------------------------\n(node nil 5 (node nil 7 nil)) add 3 => node l' 5 (node nil 7 nil)\n\\end{lstlisting}\n\nAddition within an empty sub-tree is trivially resolved, thus we obtain:\n\n\\begin{lstlisting}\nl' := node nil 3 nil\n---------------------\nnil add 3 => l'\n-----------------------------------------------------------------\n(node nil 5 (node nil 7 nil)) add 3 => node l' 5 (node nil 7 nil)\n\\end{lstlisting}\n\nWe can now unwind the stack, which after just one unwinding step yields the final result:\n\n\\begin{lstlisting}\n-------------------------------------------------------------------------------\n(node nil 5 (node nil 7 nil)) add 3 => node (node nil 3 nil) 5 (node nil 7 nil)\n\\end{lstlisting}\n\nwhich (as expected) is the tree:\n\n\\begin{lstlisting}\n  5\n / \\\n3   7\n\\end{lstlisting}\n\n\n\\subsection{Search}\nJust like we did for lists, we can perform a search within a binary search tree. Search determines whether or not a given element is contained within the tree, and we encode it with the operator \\texttt{contains} which has a tree as its left parameter and an integer element as right parameter:\n\n\\begin{lstlisting}\nFunc [BinTreeInt] \"contains\" [<<int>>] Priority 100 Type Expr => YesNo\n\\end{lstlisting}\n\nAn empty tree never contains an element:\n\n\\begin{lstlisting}\n---------------------\nnil contains k => no\n\\end{lstlisting}\n\nOn the other hand, a tree that begins with the element we are looking for trivially contains the element:\n\n\\begin{lstlisting}\nx == k\n-------------------------------\n(node l k r) contains x => yes\n\\end{lstlisting}\n\nIf the tree begins with an element \\texttt{x} that is bigger than the element \\texttt{k} we are looking for, than we know that only the left subtree is of interest: all elements of the right subtree are bigger than \\texttt{x}, and thus also of \\texttt{k}:\n\n\\begin{lstlisting}\nk < x\nl contains k  => res\n-------------------------------\n(node l x r) contains k => res\n\\end{lstlisting}\n\nSymmetrically for a tree that begins with an element \\texttt{x} that is bigger than the element \\texttt{k} we are looking for, than we know that only the right subtree is of interest: all elements of the left subtree are smaller than \\texttt{x}, and thus also of \\texttt{k}:\n\n\\begin{lstlisting}\nk > x\nr contains k  => res\n-------------------------------\n(node l x r) contains k => res\n\\end{lstlisting}\n\n\nConsider now searching element \\texttt{10} within tree:\n\n\\begin{lstlisting}\n  5\n / \\\n3   7\n\\end{lstlisting}\n\nThis means resolving:\n\n\\begin{lstlisting}\n-----------------------------------------------\n(node nil 5 (node nil 7 nil)) contains 10 => ?\n\\end{lstlisting}\n\nSince \\texttt{10} is bigger than \\texttt{5}, we proceed recursively into the right sub-tree:\n\n\\begin{lstlisting}\n5 < 10\n(node nil 7 nil) contains 10 => res\n-------------------------------------------------\n(node nil 5 (node nil 7 nil)) contains 10 => res\n\\end{lstlisting}\n\nAgain, since \\texttt{10} is bigger than \\texttt{7}, we proceed recursively into the right-subtree:\n\n\\begin{lstlisting}\n10 < 7\nnil contains 10 => res'\nres := res'\n------------------------------------\n(node nil 7 nil) contains 10 => res\n-------------------------------------------------\n(node nil 5 (node nil 7 nil)) contains 10 => res\n\\end{lstlisting}\n\nSearching within the empty tree always fails, therefore:\n\n\\begin{lstlisting}\nres' := no\n------------------------\nnil contains 10 => res'\nres := res'\n------------------------------------\n(node nil 7 nil) contains 10 => res\n-------------------------------------------------\n(node nil 5 (node nil 7 nil)) contains 10 => res\n\\end{lstlisting}\n\nAt this point we can begin unwinding. The first unwinding step yields:\n\n\\begin{lstlisting}\nnil contains 10 => no\nres := no\n------------------------------------\n(node nil 7 nil) contains 10 => res\n-------------------------------------------------\n(node nil 5 (node nil 7 nil)) contains 10 => res\n\\end{lstlisting}\n\nafter just another unwinding step we end up with the final result:\n\n\\begin{lstlisting}\n(node nil 5 (node nil 7 nil)) contains 10 => no\n\\end{lstlisting}\n\n\n\\subsection{Performance}\nThe more the tree is balanced, the more effective search and insertion into a binary search tree will be. Let us intuitively analyse the number of steps we will need to perform during a binary search. Assume that we have a perfectly balanced tree with \\texttt{n+1} elements; since the tree is balanced, then both the left and the right sub-trees contain exactly \\texttt{n/2} elements each.\n\nIn the beginning we are searching among the whole \\texttt{n+1} elements, that is our tree is:\n\n\\begin{lstlisting}\n  x    = 1 element\n / \\\nl   r  = n/2 + n/2 elements\n\\end{lstlisting}\n\n\nAfter comparing the searched value and the current element of the tree, we choose one between the two sub-trees and fully discard the other. This means that after one step we focus on a smaller sub-tree:\n\n\\begin{lstlisting}[mathescape=true]\n  x'    = 1 element\n / \\\nl'  r'  $\\approx$ n/4 + n/4 elements\n\\end{lstlisting}\n\nAfter yet another step we get:\n\n\\begin{lstlisting}[mathescape=true]\n  x''    = 1 element\n / \\\nl'' r''  $\\approx$ n/8 + n/8 elements\n\\end{lstlisting}\n\nIt should be clear that every step roughly divides the number of active elements (the set within which we are searching) by two, therefore after \\texttt{k} steps we have only \n\n$$\\frac{n}{2^k}$$\n\nelements left to consider. We are sure that at worst we will stop when this set of elements left has at most one element, thus we stop when:\n\n$$\\frac{n}{2^k} = 1$$\n\nBy multiplying both sides by $2^k$, we get:\n\n$$n = 2^k$$\n\nAnd by taking the logarithm of both sides, we obtain the final result that:\n\n$$\\log_2 n = k$$\n\nthat is we will stop searching after (at most) \\texttt{k} steps, which is the logarithm in base $2$ of \\texttt{n}.\\footnote{One might go back to the definition of logarithm for a moment to clarify this last step: \\textit{the logarithm is the exponent to which a fixed value, the base, must be raised to produce the desired number}. This means literally that if $\\log_b(x)=y$ then $b^y=x$.}\n\nLogarithms grow quite slowly. This means that we will take roughly:\n\\begin{itemize}\n\\item $10$ search steps if the tree has $10^3$ elements\n\\item $20$ search steps if the tree has $10^6$ elements\n\\item $40$ search steps if the tree has $10^{12}$ elements\n\\end{itemize}\n\nThis makes binary search trees one of the most efficient data structures for handling large data sets, but one word of warning is necessary. The original assumption that binary search trees need to be balanced for such good performance properties to be verified is quite a strong hypothesis, which needs further exploration.\n", "meta": {"hexsha": "c2b82f27debfca032b8238fbec59c1fc20942770", "size": 11368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/binary_search_trees.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/Examples/binary_search_trees.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/Examples/binary_search_trees.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 40.3120567376, "max_line_length": 924, "alphanum_fraction": 0.6844651654, "num_tokens": 2805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6949147511463684}}
{"text": "\\section{Presentation and Discussion of Results}\n\nAs we briefly explained in section \\ref{data-visualization}, the number of initial face examples is slightly greater than the number of non-face examples, so, we decided not to use accuracy as performance metric, because it becomes misleading. Instead, we used the combination of \\textbf{F1 Score}, \\textbf{Accuracy}, \\textbf{Precision} and \\textbf{Recall} to compare both models.\n\nTo clarify these concepts:\n\n\\begin{itemize} \n\\item \\textbf{Precision} - the fraction of correctly classified positive examples from all classified as positive.\n\\item \\textbf{Recall} - actual positive rate of all positive examples, that is, the fraction of correctly classified examples.\n\\item \\textbf{F1 Score} - weighted average of Precision and Recall.\n\\end{itemize}\n\nFurthermore, these concepts have mathematical representations, as follows:\n\n\\begin{itemize} \n\\item  \\(Precision = \\frac{TP}{TP+FP}\\)  \\\\\n\\item  \\(Recall = \\frac{TP}{TP+FN}\\) \\\\\n\\item  \\(F1 Score = 2*\\frac{Recall * Precision}{Recall + Precision}\\) \\\\\n\\end{itemize}\n\n\\subsection{SVM}\n\nAfter optimizing our SVM classifier, we tested it with our testing dataset. As we can see in figure \\ref{fig:svm-cross-validation} previously showed, the results of both train and cross-validation phases were good, as we could find a combination of parameters where the accuracy of the model in both phases had the value of 1.\n\nHence, in the table \\ref{table:svm-results} we can clearly see what values of \\textbf{F1 Score}, \\textbf{Accuracy}, \\textbf{Precision} and \\textbf{Recall} our model was able to achieve.\n\n\\begin{table}[H]\n\\centering\n\\caption{SVM Results}\n\\begin{tabular}{ccccc}\n\\cline{2-3}\n\\multicolumn{1}{l|}{}                & \\multicolumn{1}{l|}{\\textbf{Train \\& Cross-Validation}} & \\multicolumn{1}{l|}{\\textbf{Test}} &  &  \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{F1 Score}} & \\multicolumn{1}{c|}{1}                     & \\multicolumn{1}{c|}{0.985}                              &  &  \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{Accuracy}} & \\multicolumn{1}{c|}{1}                     & \\multicolumn{1}{c|}{0.985}                              &  &  \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{Precision}} & \\multicolumn{1}{c|}{1} & \\multicolumn{1}{c|}{0.985} & & \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{Recall}} & \\multicolumn{1}{c|}{1} & \\multicolumn{1}{c|}{0.986} & & \\\\\\cline{1-3} & & & & \n\\end{tabular}\n\\label{table:svm-results}\n\\end{table}\n\nAs we can see, and reiterating the behaviour of our SVM classifier on both testing and cross-validation phases, we can see that all four metrics have the value of \\(1\\). In the testing phase, the results were not perfect, that is, the values are a little bit lower than \\(1\\), however, were quite good, as we were able to achieve a success rate approximately close to \\(0.985\\). It is necessary to remember that these results are not related to just one execution, but to \\(50\\) executions of the entire flow. This means that the values presented in table \\ref{table:svm-results}, represent the average of each metric for the \\(50\\) repetitions of the entire flow (dataset splitting, training, cross-validation and testing).\n\nFurthermore, to help us understand if the classifier was systematically incorrectly classifying one of the classes, we decided to produce the confusion matrix that can be seen in figure \\ref{fig:svm-confusion-matrix}.\n\n\\begin{figure}[htbp]\n\\centerline{\\includegraphics[width=0.65\\linewidth]{images/svm_conf_matrix.png}}\n\\caption{SVM - Confusion Matrix}\n\\label{fig:svm-confusion-matrix}\n\\end{figure}\n\nAs we analyse the confusion matrix related to the results on the testing dataset, in figure \\ref{fig:svm-confusion-matrix}, we can see that the model it's not systematically miss-classifying some of the classes, which means that our data augmentation of the dataset was able to regularize the learning process of our model. We can also see that in each class we have less than 5 examples miss-classified, which we see as positive outcome.\n\n\\subsection{NN}\n\nTo the Neural Network classifier, the adopted flow was similar to the one detailed above, that is, we optimized our NN model and then tested it on the testing dataset.\n\nThe table \\ref{table:nn-results} summarizes the result values the NN model was able to achieve.\n\n\\clearpage\n\n\\begin{table}[htbp]\n\\centering\n\\caption{NN Results}\n\\begin{tabular}{ccccc}\n\\cline{2-3}\n\\multicolumn{1}{l|}{}                & \\multicolumn{1}{l|}{\\textbf{Train \\& Cross-Validation}} & \\multicolumn{1}{l|}{\\textbf{Test}} &  &  \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{F1 Score}} & \\multicolumn{1}{c|}{1}                     & \\multicolumn{1}{c|}{0.973}                              &  &  \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{Accuracy}} & \\multicolumn{1}{c|}{1}                     & \\multicolumn{1}{c|}{0.973}                              &  &  \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{Precision}} & \\multicolumn{1}{c|}{1} & \\multicolumn{1}{c|}{0.974} & & \\\\ \\cline{1-3}\n\\multicolumn{1}{|l|}{\\textbf{Recall}} & \\multicolumn{1}{c|}{1} & \\multicolumn{1}{c|}{0.974} & & \\\\\\cline{1-3} & & & & \n\\end{tabular}\n\\label{table:nn-results}\n\\end{table}\n\nAs can be seen in table \\ref{table:nn-results}, as in our SVM model, for training and cross-validation phases, the model achieve the value of \\(1\\) to every metric, but for the testing phase, our NN model performed worse than our SVM model, achieving the average values of \\(0.97\\) to each evaluation metric. \n\nMoreover, we also produced the confusion matrix to this model, as can be seen in figure \\ref{fig:nn-confusion-matrix}. As in the SVM model, our NN classifier it's not systematically miss-classifying the examples, which confirms the conclusion we stated above about the data augmentation process. As in our SVM model, we can see that the miss-classified examples were also on a reduced number, although a little higher than in the SVM model. With this, we were able to conclude that neither of the models had systematic miss-classification problems and that our NN model was not able to generalize its predictions as much as the SVM classifier.\n\n\\begin{figure}[htbp]\n\\centerline{\\includegraphics[width=0.65\\linewidth]{images/nn_conf_matrix.png}}\n\\caption{NN - Confusion Matrix}\n\\label{fig:nn-confusion-matrix}\n\\end{figure}\n\nThe purpose of this paper was always to compare the two models against each other. However, we always thought the NN model would be better than the SVM model, even if by a little range. After these results, we came to the conclusion that this could be related with a number of causes:\n\n\\begin{itemize} \n\\item The dataset size that was not that big, and can harm the learning process of the NN model, that ends up needing more data than the SVM model.\n\\item The feature extractor function: both models used the same feature extraction function (HOG) as a mean to achieve common ground and a true state of comparison, and that could indeed be one of the reasons, since other feature extractors, such as \\textit{Fast Gabor Filtering}, produce better results on Neural Network models.\n\\end{itemize}\n\nThese possibilities will be further detailed in section \\ref{novelty}.\n\n\\subsection{External Test Examples}\n\nFinally, after testing our two models with the testing dataset, we decided to test both models with external images that weren't part of the original dataset. Thus, we slightly modified how we processed the images and its predictions so we could test an example with multiple faces and a more complex context to assert how our models would handle that test case.\n\nAs we can see in figures \\ref{fig:svm-family-result} and \\ref{fig:nn-family-result}, both models successfully identified all the existent faces in the images and both models produced instances of false positive results. We can also see that the NN model produced more false positives (it produced three false positives in the testing image) than the SVM model, that only produced one. This does not come as a surprise, because we already saw that our SVM model produces better results than our NN model.\n\n\\begin{figure}[htbp]\n\\centerline{\\includegraphics[width=1\\linewidth]{images/svm_persons.png}}\n\\caption{SVM - Family External Image Test Result}\n\\label{fig:svm-family-result}\n\\end{figure}\n\n\\begin{figure}[htbp]\n\\centerline{\\includegraphics[width=1\\linewidth]{images/nn_persons.png}}\n\\caption{NN - Family External Image Test Result}\n\\label{fig:nn-family-result}\n\\end{figure}\n\nWith this external test image, we were asserted that both models were able to correctly detect all existent faces, and that both had problems with false positives, which was expected as none of our models produced result scores of approximately \\(1\\) in the testing phase.", "meta": {"hexsha": "2a1726e140b4fc39e4a01bd61b1c23f11113e266", "size": 8719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/results.tex", "max_stars_repo_name": "vascoalramos/image-face-detection", "max_stars_repo_head_hexsha": "c6aced3864343481dea27882a164134890fb001a", "max_stars_repo_licenses": ["MIT"], "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/results.tex", "max_issues_repo_name": "vascoalramos/image-face-detection", "max_issues_repo_head_hexsha": "c6aced3864343481dea27882a164134890fb001a", "max_issues_repo_licenses": ["MIT"], "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/results.tex", "max_forks_repo_name": "vascoalramos/image-face-detection", "max_forks_repo_head_hexsha": "c6aced3864343481dea27882a164134890fb001a", "max_forks_repo_licenses": ["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.8482142857, "max_line_length": 724, "alphanum_fraction": 0.7325381351, "num_tokens": 2302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.694914744932153}}
{"text": "\\mychapter{4}{Lesson 4} %181005\n\n\\section{Negligible function}\n\nWhat is exactly a negligible function? Below here there is a possible interpretation of this notion, taken from an answer to a question in the Cryptography Stack Exchange website:\n\\begin{quotation}\n    ``[...] in modern cryptographic schemes, we generally do not try to achieve perfect secrecy [...]. Instead, we define security against a specific set of adversaries whose computational power is bounded. Generally, we assume an adversary that is bounded to run in time polynomial to $n$, where $n$ is the security parameter given to the key generation algorithm [...].\n\n    So consider a scheme $\\Pi$ where the only attack against it is the brute-force attack. We consider $\\Pi$ to be secure if it cannot be broken by a brute-force attack in polynomial time.\n\n    The idea of \\emph{negligible probability} encompasses this exact notion. In $\\Pi$, let's say that we have a polynomial-bounded adversary. Brute force attack is not an option. But instead of brute force, the adversary can try (a polynomial number of) random values and hope to guess the right one. In this case, we define security using negligible functions: The probability of success has to be smaller than the reciprocal of any polynomial function.\n\n    And this makes a lot of sense: if the success probability for an individual guess is a reciprocal of a polynomial function, then the adversary can try a polynomial amount of guesses and succeed with high probability. If the overall success rate is $\\oneover{\\poly(n)}$ then we consider this attempt a feasible attack to the scheme, which makes the latter insecure.\n\n    So, we require that the success probability must be less than the reciprocal of every polynomial function. This way, even if the adversary tries $\\poly(n)$ guesses, it will not be significant since it will only have tried:\n    \\[\n        \\frac{\\poly(n)}{superpoly(n)}\n    \\]\n    As $n$ grows, the denominator grows far faster than the numerator and the success probability will not be significant.''\\footnote{\\linkicon \\href\n        {https://crypto.stackexchange.com/questions/5832/what-exactly-is-a-negligible-and-non-negligible-function}\n        {\\textsf{``What exactly is a negligible (and non-negligible) function?'' --- Cryptography Stack Exchange}}}\n\\end{quotation}\n\n\n\\begin{definition}\n    Let $f : \\nonneg \\to \\nonneg$ be a function. Then it is deemed \\emph{polynomial}, and denoted as $f \\in \\poly(\\lambda)$, iff:\n    \\[\n        \\exists c \\in \\nonneg : f(\\lambda) \\in O(\\lambda^c) \\qedhere\n    \\]\n\\end{definition}\n\n% AP190904: Big O or small O?!?\n% ^^^^^^^^: Big O, as specified here: https://en.wikipedia.org/wiki/Randomness_extractor#Randomness_extractors_in_cryptography\n\\begin{definition}\n    Let $\\nu : \\nonneg \\to \\real$ be a function. Then it is deemed \\emph{negligible}, and denoted as $\\nu \\in \\negl(\\lambda)$, iff:\n    \\[\n        \\forall f \\in \\poly(\\lambda)  \\implies \\nu(\\lambda) \\in O\\left(\\oneover{f(\\lambda)}\\right) \\qedhere\n    \\]\n\\end{definition}\n\nNote that these actually represent upper bounds for functions: a negligible function adheres to the polynomial function definition, whereas the opposite isn't true. To sum it up: $\\negl \\subset \\poly$.\n\n\\begin{exercise}\n    Let $p(\\lambda), p'(\\lambda) \\in \\poly(\\lambda)$ and $\\nu(\\lambda), \\nu'(\\lambda) \\in \\negl(\\lambda)$. Then prove the following:\n\n    \\begin{enumerate}\n        \\item $p(\\lambda) \\cdot p'( \\lambda) \\in  \\poly(\\lambda)$\n        \\item \\label{ex:negl} $\\nu(\\lambda) + \\nu'(\\lambda) \\in \\negl(\\lambda)$\n    \\end{enumerate} \n\\end{exercise}\n\n\\begin{solution}[\\ref{ex:negl}]\n\n    \\todo{Questa soluzione usa disuguaglianze deboli; per essere negligibile una funzione dev'essere strettamente minore di un polinomiale inverso. Da approfondire}\n    \n    We need to show that for any $c \\in \\nonneg $, then there is $n_0$ such that $\\forall n > n_{0} \\implies \\nu(n) + \\nu'(n) < \\oneover{n^c}$.\n    \n    Consider an arbitrary $c \\in \\nonneg$. Then, since $c + 1 \\in \\nonneg$, and both $\\nu$ and $\\nu'$ are negligible, there exist $n_\\nu$ and $n_{\\nu'}$ such that:\n    \n    \\begin{align*}\n        \\forall n \\geq n_{\\nu} \\implies& \\nu(n) \\leq n^{-(c+1)} \\\\\n        \\forall n \\geq n_{\\nu'} \\implies& \\nu'(n) \\leq n^{-(c+1)}\n    \\end{align*}\n\n    Fix $n_{0} = \\max(n_{\\nu}, n_{\\nu'})$. Then, since $n_0 \\geq 2$, $\\forall n \\geq n_0$ we have:\n    \\begin{align*}\n        & \\nu(n) + \\nu'(n) \\\\\n        \\leq& n^{-(c+1)} + n^{-(c+1)} \\\\\n        =& 2n^{-(c+1)} \\\\\n        \\leq& n^{-c}\n    \\end{align*}\n    Therefore, we conclude that $\\nu(n) + \\nu'(n) \\in \\negl(\\lambda)$.\n\\end{solution}\n\n\n\\section{One-way functions}\n\nFrom here, we start defining an object that is fundamental to everyday cryptography: the \\emph{one-way} function, or \\owf{} in short. Colloquially, a one-way function is a function that is ``easy to compute'', while being ``hard to invert'' at the same time, the concept of hardness being borrowed by complexity theory.\n\n\\begin{definition}    \n    Let $f : \\binary^{n(\\lambda)} \\to \\binary^{n(\\lambda)}$ be a function. Then it is a \\owf{} iff:\n    \\[\n        \\forall \\adversary \\in \\ppt\\, \\exists \\nu(\\lambda) \\in \\negl(\\lambda) : \\Pr\\left[\\cryptog{owf}[f](\\lambda) = 1 \\right] \\leq \\nu(\\lambda) \\qedhere\n    \\]\n\\end{definition}\n\n\n\\begin{cryptogame}\n    {owfdef}\n    {One-Way Function hardness}\n    {owf}\n\n    \\receive{\\shortstack[l]{\n        $x \\pickUAR \\binary^n$ \\\\\n        $y = f(x)$\n    }}{$y$}{}\n\n    \\cseqdelay\n\n    \\send{}{$x'$}{\\textsc{Output 1 iff} $f(x') = y$}\n\n\\end{cryptogame}\n\nThe structure of the ``game'' appearing in the definition is depicted in figure \\ref{cryptogame:owfdef}. Do note that the game does not check for $x = x'$, but rather for $f(x) = f(x')$; in a sense, the adversary is not trying to guess what the original $x$ was: its goal is to find any value such that its image is $y$ according to $f$, and such value may very well not be unique.\n\n\\begin{exercise} \\label{ex:owf}\n    Prove the following claims:\n    \\begin{enumerate}\n        \\item There exists an inefficient adversary that wins $\\cryptog{owf}[f]$ with probability $1$\n        \\item There exists an efficient adversary that wins $\\cryptog{owf}[f]$ with probability $2^{-n}$\n    \\end{enumerate}\n\\end{exercise}\n\n\\begin{solution}[\\ref{ex:owf}]\\\n    \\begin{enumerate}\n        \\item Adversary uses a brute-force attack.\n        \\item Adversary makes a random guess.\n    \\end{enumerate}\n\\end{solution}\n\nA one-way function can be thought as a function which is very efficient in generating ``puzzles'' that are very hard to solve from scratch. Furthermore, given a candidate solution, one can efficiently verify its validity. In a twist of perspective, for a given couple $(\\mathcal{P}_\\textsc{gen},\\mathcal{P}_\\textsc{ver})$ of a puzzle generator and a puzzle verifier, another ``game'' can be drawn as in figure \\ref{cryptogame:owpuzzle}.\n\n\\begin{cryptogame}\n    {owpuzzle}\n    {The puzzle game}\n    {puzzle}\n\n    \\receive{$(x, y) \\pickUAR \\mathcal{P}_\\textsc{gen}$}{$y$}{}\n\n    \\cseqdelay\n\n    \\send{}{$x'$}{\\textsc{Output} $\\mathcal{P}_\\textsc{ver}(x', y)$}\n\n\\end{cryptogame}\n\nIt can also be said that the one-way puzzle problem is in \\textsc{np}, because witness checking is easy, but not in \\textsc{p} because finding a solution to begin with is hard.\n\n\\subsubsection{Impagliazzo's Worlds}\n\nSuppose to have Gauss, a genius child, and his professor. The professor gives to Gauss some mathematical problems, and Gauss wants to solve them all.\n\nImagine now that, if using one-way functions, the problem is $f(x)$, and its solution is $x$. According to Impagliazzo, we live in one of these possible worlds:\n\\begin{itemize}\n    \\item \\textit{Algorithmica}: $\\textsc{P} = \\textsc{NP}$, meaning all efficiently verifiable problems are also efficiently solvable. \n    \n    The professor can try as hard as possible to create a hard scheme, but he won't succeed because Gauss will always be able to efficiently break it using the verification procedure to compute the solution\n\n    \\item \\textit{Heuristica}: \\textsc{NP} problems are hard to solve in the worst case but easy on average. \n    \n    The professor, with some effort, can create a game difficult enough, but Gauss will solve it anyway; here there are some problems that the professor cannot find a solution to\n\n    \\item \\textit{Pessiland}: \\textsc{NP} problems are hard on average but no one-way functions exist\n    \n    \\item \\textit{Minicrypt}: One-way functions exist but public-key cryptography is impractical\n    \n    \\item \\textit{Cryptomania}: Public-key cryptography is possible: two parties can exchange secret messages over open channels\n\\end{itemize}\n    \n\\section{Computational Indistinguishability}\n\nDistribution ensembles $X = \\{X_{\\lambda \\in \\mathbb{N}}\\}$ and $Y = \\{Y_{\\lambda \\in \\mathbb{N}}\\}$ are distribution sequences.\n\n\\begin{definition}[\\emph{Comp. indist.}]\n    Let $X$ and $Y$ be two distribution sequences; they are deemed \\emph{computationally indistinguishable}, written as ``$X \\compindist Y$'' iff:\n    \\[\n        \\forall \\adversary \\in \\ppt \\exists \\nu(\\lambda) \\in \\negl(\\lambda) : \\left|\\Pr[\\adversary(X_\\lambda) = 1] - \\Pr[\\adversary(Y_\\lambda) = 1]\\right| \\leq \\nu(\\lambda) \\qedhere\n    \\]\n\\end{definition}\n\nIn words: any \\emph{efficient} adversary attempting to distinguish outputs between the two ensembles will succeed with a probability that is negligibly different than randomly guessing. Note the emphasis on ``efficient'', which makes this relationship between ensembles weaker than what would be a purely statistical one.\n\nWith the purpose of making these new concepts clearer, it is presented this mental game.\n\n\\todo{AP181129-2344: There may be room for improvement, but I like how it's worded: it puts some unusual perspective into the cryptographic game, and it could be a good thing since it closely precedes our first reduction, and the whole hybrid argument mish-mash.}\n\nA \\emph{challenger} \\challenger{} chooses a value $z$ among $X_\\lambda$ and $Y_\\lambda$, and gives it to a \\emph{distinguisher} \\distinguisher{}. In turn, \\distinguisher{} has to correctly guess which was the source of $z$: either $X_\\lambda$ or $Y_\\lambda$. \n\nIf we let $X_\\lambda$ and $Y_\\lambda$ to be \\emph{computationally indistinguishable}, then, fixed 1 as one of the sources, the probability that \\distinguisher{} says ``1!'' when \\challenger{} picks $z$ from $X_\\lambda$ is \\emph{not so far} from the probability that \\distinguisher{} says ``1!'' when \\challenger{} picks $z$ from $Y_\\lambda$.\n\nSo, this means that, when this property is verified by two random variables, there isn't too much \\textit{difference} between the two variables in terms of information available to \\distinguisher{}, otherwise the distance between the two probabilities should be much more than a negligible quantity.\n\n\\begin{lemma} \\label{lem:compmall}\n    Let $f$ be a function that has polynomial time-complexity. Then, for any two ensembles $X$ and $Y$:\n    \\[\n        X \\compindist Y \\implies f(x) \\compindist f(y) \\qedhere\n    \\]\n\\end{lemma}\n\n\\begin{proof}\n    This proof is by contradiction and uses a reduction. Let $X \\compindist Y$ be two indistinguishable ensembles, and $f \\in \\ppt$ an arbitrary poly-time complex function. Assume there exists an adversary \\adversary{} to the challenge of distinguishing the ensembles' images $f(X)$ from $f(Y)$ that does efficiently succeed, as shown in figure \\ref{cryptogame:fdistin}. \n    \n    \\begin{cryptogame}\n        {fdistin}\n        {A distinguisher for $f$}\n        {$f$-\\textsc{dist}}\n\n        % Adversary asks for the challenge. Challenger chooses evenly between X and Y, and samples a value; then it sends that value's image by f to the adversary\n        \\receive{\\shortstack[l]{\n            $z_0 \\pickUAR X$ \\\\\n            $z_1 \\pickUAR Y$ \\\\\n            $b \\pickUAR \\binary$\n        }}{$f(z_b)$}{}\n\n        \\cseqdelay\n\n        % Adversary attempts to guess from which distribution the value's image came from\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n    \\end{cryptogame}\n    \n    Fix this adversary to be the distinguisher $\\distinguisher_f$. From here, another adversary $\\adversary \\in \\ppt$ can use $\\distinguisher_f$ to effectively distinguish the original ensembles, as depicted in figure \\ref{cryptoredux:fdistin}:\n    \\begin{enumerate}\n        \\item \\adversary{} asks for the original sample from the challenger\n        \\item \\adversary{} applies $f$ on the sample\n        \\item \\adversary{} relays the resulting image to $\\distinguisher_f$\n        \\item $\\distinguisher_f$ replies with his outcome\n        \\item \\adversary{} relays the outcome to the challenger\n    \\end{enumerate}\n    All of this is done in polynomial time, since all functions and machines involved in the process operate in \\ppt. This contradicts the computational indistinguishability of $X$ and $Y$.\n\n    \\begin{cryptoredux}\n        {fdistin}\n        {Distinguisher reduction}\n        {dist}\n        {f-\\textsc{dist}}\n        \n        % The distinguisher asks for the challenge\n        \\receive{\\shortstack[l]{\n            $z_0 \\pickUAR X$ \\\\\n            $z_1 \\pickUAR Y$ \\\\\n            $b \\pickUAR \\binary$\n        }}{$z_b$}{}\n      \n        % The distinguisher applies f to z and relays the image to A\n        \\invoke{}{$f(z_b)$}{}\n        \n        % Adversary distinguishes between the two distributions\n        \\return{}{$b'$}{}\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n        \n    \\end{cryptoredux}\n\n\\end{proof}\n\n\n\\section{Pseudo-random generators}\n\nA deterministic function $G \\in \\binary^\\lambda \\to \\binary^{\\lambda + l(\\lambda)}$ is called a \\emph{pseudo-random generator}, or \\prg{} in short, iff:\n\n\\begin{itemize}\n    \\item $G \\in \\ppt(\\lambda)$\n    \\item $|G(s)| = \\lambda + l(\\lambda)$ % Well duh, we can see it by def...\n    \\item Given $U_n$ to be a distribution ensemble of $n$ uniform random variables:\n    \\[\n        G(U_{\\lambda}) \\compindist U_{\\lambda + l(\\lambda)}\n    \\]\n\\end{itemize}\n\n\\begin{cryptogame}\n    {prg}\n    {The pseudorandom game}\n    {prg}\n    \n    \\receive{\\shortstack[l]{\n        $x_0 \\pickUAR G(U_\\lambda)$ \\\\\n        $x_1 \\pickUAR U_{\\lambda+l(\\lambda)}$ \\\\\n        $b \\pickUAR \\binary$\n    }}{$x_b$}{}\n\n    \\cseqdelay\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b = b'$}\n    \n\\end{cryptogame}\n\nSo, if we take $s \\pickUAR U_\\lambda$, the output of $G$ will be indistinguishable from a random pick from $U_{\\lambda + l(\\lambda)}$.\n", "meta": {"hexsha": "6e34bbc2791a509613901961f501d80b4d480906", "size": 14443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_4.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_4.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_4.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": 51.9532374101, "max_line_length": 454, "alphanum_fraction": 0.6843453576, "num_tokens": 4055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936438, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.6949147402714914}}
{"text": "\\chapter{Week 0: The function and the field}\n\n% ================================================================\n\n\\section{The function and other preliminaries}\n\n\\subsection{Set terminology and notation}\n\\begin{definition}[Set]\n  A set is an unordered collection of objects.\n\\end{definition}\n\\begin{itemize}\n\\item $\\in$: indicates that an object belongs to a set. (e.g. $a\\in\\{a,b,\\ldots\\}$)\n\\item $\\sA \\subseteq \\sB$: ``$\\sA$ is a \\textbf{subset} of $\\sB$''. Every element of $\\sA$ is also an element of $\\sB$\n\\item $\\sA = \\sB$: two sets are equal if they contain exactly the same elements.\n\\end{itemize}\n\n\\subsubsection{Set expressions}\n$\\{ x\\in\\R : x \\ge 0 \\}$ is the set of nonnegative numbers. First part specifies where the elements of the set comes from and introduces variables. The second part gives a rule that restricts which elements specified in the first part actually get to make it into the set.\n\n\\begin{definition}[Cardinality]\n  If a set $\\sS$ is not infinite, we use $|\\sS|$ to denote the number of elements or \\emph{cardinality} of the set.\n\\end{definition}\n\n\\begin{definition}\n  $\\sA \\times \\sB$ is the set of all pairs $(a, b)$ where $a\\in\\sA$ and $b\\in\\sB$\n\\end{definition}\n\n\\subsection{The function}\nInformally, for each input element in a set $\\sA$, a function assigns a single output element from another set $\\sB$\n\\begin{itemize}\n\\item $\\sA$ is called the \\textbf{domain} of the function\n\\item $\\sB$ is called the \\textbf{co-domain}\n\\end{itemize}\n\n\\begin{definition}[Function]\n  A function is a set of pairs $(a, b)$ no two of which have the same first element.\n\\end{definition}\n\n\\begin{definition}[Image]\n  The output of a given input is called the \\emph{image} of that input. The image of $q$ under a function $f$ is denoted $f(q)$\n\\end{definition}\n\nIf $f(q) = r$, we say $q$ maps to $r$ under $f$. In Mathese, we write this as $q \\mapsto r$.\n\nThe set from which all the outputs are chosen is called the co-domain.\nWe write:\n\\begin{equation*}\n  f : \\sD \\rightarrow \\sF\n\\end{equation*}\nwhen we want to say that $f$ is a function with domain $\\sD$ and co-domain $\\sF$.\n\n\\begin{definition}[Image of a function]\n  The image of a function is the set of all images of inputs. Mathese: $\\Ima f$\n\\end{definition}\n\n\\begin{example}\n  $\\cos : \\R \\rightarrow \\R$, which means the domain is $\\R$, and the co-domain is $\\R$. The image of $\\cos(x)$, $\\Ima \\cos$ is $\\{ x\\in\\R : -1 \\le x \\le 1 \\}$.\n\\end{example}\n\n\\begin{definition}\n  For sets $\\sF$ and $\\sD$, $\\sF^{\\sD}$ denotes all functions from $\\sD$ to $\\sF$.\n\\end{definition}\n\n\\begin{proposition}\n  For finite sets, $|\\sF^{\\sD}| = |\\sF|^{|\\sD|}$.\n\\end{proposition}\n\n\\begin{definition}[Identity function]\n  For any domain $\\sD$. $\\mathrm{id}_{\\sD} : \\sD \\rightarrow \\sD$ maps each domain element $d$ to itself.\n\\end{definition}\n\n\\begin{definition}[Functional composition]\n  For functions $f : \\sA \\rightarrow \\sB$ and $g : \\sB \\rightarrow \\sC$, the functional composition of $f$ and $g$ is the function $(g \\circ f) : \\sA \\rightarrow \\sC$ defined by $(g \\circ f)(x) = g(f(x))$.\n\\end{definition}\n\n\\begin{proposition}\n  $h \\circ (g \\circ f) = (h \\circ g) \\circ f$\n\\end{proposition}\n\n\\begin{definition}[Functional inverses]\n  Functions $f$ and $g$ are functional inverses if $f \\circ g$ and $g \\circ f$ are defined and are identity functions. A function that has an inverse is invertible.\n\\end{definition}\n\n\\begin{definition}\n  $f : \\sD \\rightarrow \\sF$ is \\textbf{one-to-one} if $f(x) = f(y)$ implies $x = y$.\n\\end{definition}\n\n\\begin{definition}\n  $f : \\sD \\rightarrow \\sF$ is \\textbf{ontox} if for every $z \\in \\sF$ there exists an $a$ such that $f(a) = z$.\n\\end{definition}\n\n\\begin{proposition}\n  Invertible functions are one-to-one.\n\\end{proposition}\n\n\\begin{theorem}[Function Invertibility Theorem]\n  A function $f$ is invertible if and only if it is one-to-one and onto.\n\\end{theorem}\n\n% ================================================================\n\n\\section{The Field: Introduction to complex numbers}\n\n$i = \\sqrt{-1}$ is an imaginary number, this is a solution to an equation such as $x^2 = -1$. For $(x-1)^2 = 9$, the solution is $x = 1 + 3i$.\n\nA \\textbf{complex number} has a real part and an imaginary part.\n\n\\subsection{Field notation}\nWhen we want to refer to a field without specifying which field we will use the notation $\\fF$.\n\nWe study three fields;\n\\begin{itemize}\n\\item The field $\\R$ of real numbers.\n\\item The field $\\sC$ of complex numbers.\n\\item The finite field $GF(2)$, which consists of $0$ and $1$ under $\\mod 2$ arithmetic.\n\\end{itemize}\n\n\\section{The Field of playing with $\\sC$}\nWe can interpret real and imaginary parts of a complex number as $x$ and $y$ coordinates. Assume that $z\\in\\sC$.\n\n\\begin{itemize}\n\\item \\textbf{Translation} $f(z) = z + z_0, z_0 \\in \\sC$. A translation can ``move'' a picture anywhere in the complex plane.\n\\item \\textbf{Scaling} $f(z) = mz, m \\in \\R$.\n\\item \\textbf{Invert} $f(z) = (-1)z$.\n\\item \\textbf{Rotate counterclockwise by 90 degreesx} $f(z) = iz$.\n\\item \\textbf{Rotating by an angle} $f(z) = z \\cdot e^{\\tau i}$, does rotation by angle $\\tau$.\n\\end{itemize}\n\n\\section{The Field of playing with $GF(2)$}\n$GF(2) = \\text{Galois Field 2}$, has just two elements: $0$ and $1$.\n\\begin{itemize}\n\\item Addition is like exclusive-or. (e.g. $\\mathrm{XOR}(a, b) = a \\not\\equiv b ; a, b \\in GF(2)$)\n\\item Multiplication is just like normal multiplication.\n\\end{itemize}\n\n", "meta": {"hexsha": "d082443ad5755661da5f7b20eaeeae3fbbd52b3e", "size": 5399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/week0.tex", "max_stars_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_stars_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/week0.tex", "max_issues_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_issues_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/week0.tex", "max_forks_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_forks_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.6985294118, "max_line_length": 272, "alphanum_fraction": 0.6727171698, "num_tokens": 1687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.694914740059813}}
{"text": "\\lab{Gibbs Sampling and LDA}{Gibbs Sampling and LDA}\n\\objective{Understand the basic principles of implementing a Gibbs sampler. Apply this to Latent Dirichlet Allocation.}\n\n\\section*{Gibbs Sampling}\nGibbs sampling is an MCMC sampling method in which we construct a Markov chain which is used to sample from a desired joint (conditional) distribution\n\\begin{equation*}\n\\mathbb{P}(x_{1},\\cdots,x_{n} | \\mathbf{y}).\n\\end{equation*}\nOften it is difficult to sample from this high-dimensional joint distribution, while it may be easy to sample from the one-dimensional\nconditional distributions\n\\begin{equation*}\n\\mathbb{P}(x_{i} | \\mathbf{x}_{-i}, \\mathbf{y})\n\\end{equation*}\nwhere $\\mathbf{x}_{-i} = x_{1},\\cdots,x_{i-1},x_{i+1},\\cdots,x_{n}.$\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Gibbs Sampler}{}\n    \\State \\textrm{Randomly initialize } $x_1,x_2,\\ldots,x_n$.\n    \\For{$k = 1, 2, 3, \\ldots$}\n        \\For{$i = 1, 2, \\ldots,n$}\n            \\State \\textrm{Draw } $x \\sim \\mathbb{P}(x_{i} | \\mathbf{x}_{-i}, \\mathbf{y})$\n            \\State \\textrm{Fix } $x_i = x$\n        \\EndFor\n        \\State $\\mathbf{x}^{(k)}= (x_1,x_2,\\ldots,x_n)$\n    \\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Basic Gibbs Sampling Process.}\n\\label{alg:gibbs}\n\\end{algorithm}\nA Gibbs sampler proceeds according to Algorithm \\ref{alg:gibbs}.\nEach iteration of the outer for loop is a \\emph{sweep} of the Gibbs sampler, and the value of $\\mathbf{x}^{(k)}$ after a sweep is a \\emph{sample}.\nThis creates an irreducible, non-null recurrent, aperiodic Markov chain over the state space consisting of all possible $\\mathbf{x}$.\nThe unique invariant distribution for the chain is the desired joint distribution\n\\begin{equation*}\n\\mathbb{P}(x_{1},\\cdots,x_{n} | \\mathbf{y}).\n\\end{equation*}\nThus, after a burn-in period, our samples $\\mathbf{x}^{(k)}$ are effectively samples from the desired distribution.\n\nConsider the dataset of $N$ scores from a calculus exam in the file \\texttt{examscores.npy}.\nWe believe that the spread of these exam scores can be modeled with a normal distribution of mean $\\mu$ and variance $\\sigma^{2}$.\nBecause we are unsure of the true value of $\\mu$ and $\\sigma^2$, we take a Bayesian approach and place priors on each parameter to quantify this uncertainty:\n\\begin{align*}\n\\mu & \\sim N(\\nu, \\tau^{2})\\quad &&\\text{(a normal distribution)} \\\\\n\\sigma^{2} & \\sim IG(\\alpha, \\beta) &&\\text{(an inverse gamma distribution)}\n\\end{align*}\nLetting $\\mathbf{y} = (y_1,\\ldots,y_N)$ be the set of exam scores, we would like to update our beliefs of $\\mu$ and $\\sigma^2$ by sampling from the posterior\ndistribution\n\\begin{equation*}\n\\mathbb{P}(\\mu, \\sigma^{2} | \\mathbf{y}, \\nu, \\tau^{2}, \\alpha, \\beta).\n\\end{equation*}\nSampling directly can be difficult. However, we \\emph{can} easily sample from the following conditional distributions:\n\\begin{align*}\n\\mathbb{P}(\\mu | \\sigma^{2}, \\mathbf{y}, \\nu, \\tau^{2}, \\alpha, \\beta) & = \\mathbb{P}(\\mu | \\sigma^{2}, \\mathbf{y}, \\nu, \\tau^{2})\\\\\n\\mathbb{P}(\\sigma^{2} | \\mu, \\mathbf{y}, \\nu, \\tau^{2}, \\alpha, \\beta) & = \\mathbb{P}(\\sigma^{2} | \\mu, \\mathbf{y}, \\alpha, \\beta)\n\\end{align*}\nThe reason for this is that these conditional distributions are \\emph{conjugate} to the prior distributions, and hence are part of the same distributional\nfamilies as the priors. In particular, we have\n\\begin{align*}\n\\mathbb{P}(\\mu | \\sigma^{2}, \\mathbf{y}, \\nu, \\tau^{2}) &= N(\\mu^*, (\\sigma^*)^2)\\\\\n\\mathbb{P}(\\sigma^{2} | \\mu, \\mathbf{y}, \\alpha, \\beta) &= IG(\\alpha^*, \\beta^*),\n\\end{align*}\nwhere\n\\begin{align*}\n(\\sigma^*)^2 &= \\left(\\frac{1}{\\tau^2}+\\frac{N}{\\sigma^2}\\right)^{-1}\\\\\n\\mu^* &= (\\sigma^*)^2\\left(\\frac{\\nu}{\\tau^2} + \\frac{1}{\\sigma^2}\\sum_{i=1}^N y_i \\right)\\\\\n\\alpha^* &= \\alpha + \\frac{N}{2}\\\\\n\\beta^* &= \\beta + \\frac{1}{2}\\sum_{i=1}^N (y_i-\\mu)^2\n\\end{align*}\nWe have thus set this up as a Gibbs sampling problem, where we have only to alternate between sampling $\\mu$ and sampling $\\sigma^{2}$.\nWe can sample from a normal distribution and an inverse gamma distribution as follows:\n\\begin{lstlisting}\n>>> from math import sqrt\n>>> from scipy.stats import norm\n>>> from scipy.stats import invgamma\n>>> mu = 0. # the mean\n>>> sigma2 = 9. # the variance\n>>> normal_sample = norm.rvs(mu, scale=sqrt(sigma))\n>>> alpha = 2.\n>>> beta = 15.\n>>> invgamma_sample = invgamma.rvs(alpha, scale=beta)\n\\end{lstlisting}\nNote that when sampling from the normal distribution, we need to set the \\li{scale} parameter to the standard deviation, \\emph{not} the variance.\n\n\\begin{problem}\nWrite a function that accepts data $\\y$, prior parameters $\\nu$, $\\tau^2$, $\\alpha$, and $\\beta$, and an integer $n$.\nUse Gibbs sampling to generate $n$ samples of $\\mu$ and $\\sigma^2$ for the exam scores problem.\n\nTest your sampler with priors $\\nu=80$, $\\tau^{2} = 16$, $\\alpha = 3$, and $\\beta = 50$, collecting $1000$ samples.\nPlot your samples of $\\mu$ and your samples of $\\sigma^{2}$.\nThey should each to converge quickly.\n\\end{problem}\n\nWe'd like to look at the posterior marginal distributions for $\\mu$ and $\\sigma^2$.\nTo plot these from the samples, use a kernel density estimator from \\li{scipy.stats}.\nIf our samples of $\\mu$ are called \\li{mu_samples}, then we can do this with the following code.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n>>> from scipy.stats import gaussian_kde\n\n>>> mu_kernel = gaussian_kde(mu_samples)\n>>> x = np.linspace(min(mu_samples) - 1, max(mu_samples) + 1, 200)\n>>> plt.plot(x, mu_kernel(x))\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n    \\begin{subfigure}[b]{.49\\textwidth}\n        \\includegraphics[width=\\textwidth]{figures/mu_posterior.pdf}\n        \\caption{Posterior distribution of $\\mu$.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{.49\\textwidth}\n        \\includegraphics[width=\\textwidth]{figures/sigma2_posterior.pdf}\n        \\caption{Posterior distribution of $\\sigma^2$.}\n    \\end{subfigure}\n\\caption{Posterior marginal probability densities for $\\mu$ and $\\sigma^2$.}\n\\label{fig:post}\n\\end{figure}\n\nKeep in mind that the plots above are of the posterior distributions of the \\emph{parameters}, not of the scores. If we would like to compute the posterior distribution of a new exam score $\\tilde{y}$ given our data $\\mathbf{y}$ and prior parameters, we compute what is known as the \\emph{posterior predictive distribution}:\n\\begin{equation*}\n\\mathbb{P}(\\tilde{y} | \\mathbf{y}, \\lambda) = \\int_{\\Theta} \\mathbb{P}(\\tilde{y} | \\Theta)\\mathbb{P}(\\Theta | \\mathbf{y}, \\lambda) d\\Theta\n\\end{equation*}\nwhere $\\Theta$ denotes our parameters (in our case $\\mu$ and $\\sigma^{2}$) and $\\lambda$ denotes our prior parameters (in our case $\\nu, \\tau^{2}, \\alpha,$ and $\\beta$).\n\nRather than actually computing this integral for each possible $\\tilde{y}$, we can do this by sampling scores from our parameter samples. In other words, sample\n\\begin{equation*}\n\\tilde{y}_{(t)} \\sim N(\\mu_{(t)}, \\sigma_{(t)}^{2})\n\\end{equation*}\nfor each sample pair $\\mu_{(t)}, \\sigma_{(t)}^{2}$. Now we have essentially drawn samples from our posterior predictive distribution, and we can use a kernel density estimator to plot this distribution from the samples.\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/predictiveposterior.pdf}\n    \\caption{Predictive posterior distribution of exam scores.}\n    \\label{fig:predictive}\n\\end{figure}\n\n\\begin{problem} % Visualize Gibbs sampler results.\nPlot the kernel density estimators for the posterior distributions of $\\mu$ and $\\sigma^{2}$.\nYou should get plots similar to those in Figure \\ref{fig:post}.\n\nNext, use your samples of $\\mu$ and $\\sigma^{2}$ to draw samples from the posterior predictive distribution.\nPlot the kernel density estimator of your sampled scores.\nCompare your plot to Figure \\ref{fig:predictive}.\n\\end{problem}\n\n\\section*{Latent Dirichlet Allocation}\n\nGibbs sampling can be applied to an interesting problem in natural language processing (NLP): determining which topics are prevalent in a document.\n\\emph{Latent Dirichlet Allocation} (LDA) is a generative model for a collection of text documents.\nIt supposes that there is some fixed vocabulary (composed of $V$ distinct terms) and $K$ different topics, each represented as a probability distribution $\\phi_{k}$ over the vocabulary, each with a Dirichlet prior $\\beta$.\nThis means $\\phi_{k,v}$ is the probability that topic $k$ is represented by vocabulary term $v$.\n\nWith the vocabulary and topics chosen, the LDA model assumes that we have a set of $M$ documents (each ``document'' may be a paragraph or other section of the text, rather than a ``full'' document).\nThe $m$-th document consists of $N_m$ words, and a probability distribution $\\theta_{m}$ over the topics is drawn from a Dirichlet distribution with parameter $\\alpha$.\nThus $\\theta_{m,k}$ is the probability that document $m$ is assigned the label $k$.\nIf $\\phi_{k,v}$ and $\\theta_{m,k}$ are viewed as matrices, their rows sum to one.\n\nWe will now iterate through each document in the same manner.\nAssume we are working on document $m$, which you will recall contains $N_{m}$ words.\nFor word $n$, we first draw a topic assignment $z_{m,n}$ from the categorical distribution $\\theta_{m}$, and then we draw a word $w_{m,n}$ from the categorical distribution $\\phi_{z_{m,n}}$. Throughout this implementation, we assume $\\alpha$ and $\\beta$ are scalars. In summary, we have\n\\begin{enumerate}\n    \\item Draw $\\phi_{k} \\sim \\text{Dir}(\\beta)$ for $1 \\leq k \\leq K$.\n    \\item For $1 \\leq m \\leq M$:\n    \\begin{enumerate}\n        \\item Draw $\\theta_{m} \\sim \\text{Dir}(\\alpha)$.\n        \\item Draw $z_{m,n} \\sim \\text{Cat}(\\theta_{m})$ for $1 \\leq n \\leq N_{m}$.\n        \\item Draw $w_{m,n} \\sim \\text{Cat}(\\phi_{z_{m,n}})$ for $1 \\leq n \\leq N_{m}$.\n    \\end{enumerate}\n\\end{enumerate}\n\nWe end up with $n$ words which represent document $m$.\nNote that these words are \\emph{not} necessarily distinct from one another; indeed, we are most interested in the words that have been repeated the most.\n\nThis is typically depicted with graphical plate notation as in Figure \\ref{fig:ldaplates}.\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[>=stealth', dot/.style=\n    {circle,fill=black,minimum size=3pt,inner sep=0pt, outer sep=-1pt} ]\n\n\\node[draw,minimum height=3.2cm, minimum width=2.1cm](r1)[]{};\n\\node[draw,minimum height=5cm, minimum width=2.4cm, node distance=\n    .4cm](r2)[above of=r1]{};\n\n\\node[node distance=1.3cm](Nm)[below of=r1]{$1 \\le n \\le N_m$};\n\\node[node distance=2.28cm](M)[below of=r2]{$1 \\le m \\le M$};\n\n\\node[node distance = 2.7cm](dummy3)[left of=r1]{};\n\\node[draw,minimum height=2cm, minimum width=2.1cm, node distance=\n    .55cm](r3)[ below of =dummy3]{};\n\\node[node distance=.7cm](K)[below of=r3]{$1 \\le k \\le K$};\n\n\\node[node distance=.6cm](dummy)[above right of =Nm]{};\n\\node[circle, draw,  inner sep=1pt, fill=black!25!,node distance=.4cm]\n    (w)[above of=dummy]{$w_{m,n}$};\n\\node[circle, draw,  inner sep=1pt, node distance=1.3cm](z)[above\n    of=w]{$z_{m,n}$};\n\\node[circle, draw,  inner sep=1pt, node distance=1.3cm]\n    (theta)[above of=z]{$\\vec{\\theta}_{m}$};\n\n\\node[node distance=1.2cm, inner sep=0pt](alpha)[above of=\n    theta]{$\\vec{\\alpha}$};\n\n\\node[node distance=.6cm](dummy2)[above right of=K]{};\n\\node[node distance=.35cm, circle, inner sep=1pt, draw](phi)[above\n    of=dummy2]{$\\vec{\\phi_k}$};\n\\node[node distance=1.4cm, inner sep=0pt](beta)[above of = phi]{$\\vec{\\beta}$};\n\n\\foreach \\x/\\y in {alpha/theta, theta/z, z/w, beta/phi, phi/w} \\draw[->](\\x)--(\\y);\n\n\\end{tikzpicture}\n\\caption{Graphical plate notation for LDA text generation.}\n\\label{fig:ldaplates}\n\\end{figure}\n\nIn the plate model, only the variables $w_{m,n}$ are shaded, signifying that these are the only observations visible to us; the rest are latent variables. Our goal is to estimate each $\\phi_{k}$ and each $\\theta_{m}$. This will allow us to understand what each topic is, as well as understand how each document is distributed over the $K$ topics. In other words, we want to predict the topic of each document, and also which words best represent this topic.\nWe can estimate these well if we know $z_{m,n}$ for each $m, n$, collectively referred to as $\\mathbf{z}$. Thus, we need to sample\n$\\mathbf{z}$ from the posterior distribution $\\mathbb{P}(\\mathbf{z} | \\mathbf{w}, \\alpha, \\beta),$ where $\\mathbf{w}$ is the collection words in the text corpus. Unsurprisingly, it is intractable to sample directly from the joint posterior distribution. However, letting $\\mathbf{z}_{-(m,n)} = \\mathbf{z}\\setminus \\{z_{m,n}\\}$, the conditional posterior distributions\n\\[\\mathbb{P}(z_{m,n} = k | \\mathbf{z}_{-(m,n)}, \\mathbf{w}, \\alpha, \\beta)\\]\nhave nice, closed form solutions, making them easy to sample from.\n\nThese conditional distributions have the following form:\n\\begin{equation*}\n\\mathbb{P}(z_{m,n} = k | \\mathbf{z}_{-(m,n)}, \\mathbf{w}, \\alpha, \\beta) \\propto \\frac{(n_{(k,m,\\cdot)}^{-(m,n)} + \\alpha)(n_{(k, \\cdot, w_{m,n})}^{-(m,n)} + \\beta)}{n_{(k,\\cdot,\\cdot)}^{-(m,n)} + V \\beta}\n\\end{equation*}\nwhere\n\\begin{align*}\nn_{(k,m,\\cdot)} & = \\mbox{ the number of words in document $m$ assigned to topic $k$} \\\\\nn_{(k,\\cdot,v)} & = \\mbox{ the number of times term $v = w_{m,n}$ is assigned to topic $k$} \\\\\nn_{(k,\\cdot,\\cdot)} & = \\mbox{ the number of times topic $k$ is assigned in the corpus} \\\\\nn_{(k,m,\\cdot)}^{-(m,n)} & = n_{(k,m,\\cdot)} - \\indicator_{z_{m,n} = k} \\\\\nn_{(k,\\cdot,v)}^{-(m,n)} & = n_{(k,\\cdot,v)} - \\indicator_{z_{m,n} = k} \\\\\nn_{(k,\\cdot,\\cdot)}^{-(m,n)} & = n_{(k,\\cdot,\\cdot)} - \\indicator_{z_{m,n} = k}\n\\end{align*}\n\nThus, if we simply keep track of these count matrices, then we can easily create a Gibbs sampler over the topic assignments. This is actually a particular class of samplers known as \\emph{collapsed Gibbs samplers}, because we have collapsed the sampler by integrating out $\\theta$ and $\\phi$.\n\n\nWe have provided for you the structure of a Python object \\li{LDACGS} with several methods, listed at the end of the lab.\nThe object is already defined to have attributes \\li{n\\_topics}, \\li{documents}, \\li{vocab}, \\li{alpha}, and \\li{beta}, where \\li{vocab} is a list of strings (terms), and documents is a list of dictionaries (a dictionary for each document). Each entry in dictionary $m$ is of the form $n : w$, where $w$ is the index in \\li{vocab} of the $n^{th}$ word in document $m$.\n\nThroughout this lab we will guide you through writing several more methods in order to implement the Gibbs sampler. The first step is to initialize our assignments, and create the count matrices $n_{(k,m,\\cdot)}, n_{(k,\\cdot,v)}$ and vector $n_{(k,\\cdot,\\cdot)}$.\n\n\\begin{problem}\nComplete the method \\li{initialize()}.\nBy randomly assigning initial topics, fill in the count matrices and topic assignment dictionary. In this method, you will initialize the count matrices (among other things). Note that the notation\nprovided in the code is slightly different than that used above. Be sure to understand how the formulae above\nconnect with the code.\n\nTo be explicit, you will need to initialize $nmz$, $nzw$, and $nz$ to be zero arrays of the correct size.\nThen, in the second for loop, you will assign z to be a random integer in the correct range of topics.\nIn the increment step, you need to figure out the correct indices to increment by one for each of the three arrays.\nFinally, assign $topics$ as given.\n\\end{problem}\n\nThe next method we need to write fully outlines a sweep of the Gibbs sampler.\n\n\\begin{problem}\nComplete the method \\li{_sweep()}, which needs to iterate through each word of each document. It should call on the method \\li{_conditional()} to get the conditional distribution at each iteration.\n\nNote that the first part of this method will undo what \\li{initialize()} did.\nThen we will use the conditional distribution (instead of the uniform distribution we used previously) to pick a more accurate topic assignment.\nFinally, the latter part repeats what we did in \\li{initialize()}, but does so using this more accurate topic assignment.\n\\end{problem}\n\n\\begin{comment}\nTake out this problem to make the lab easier.\nWe need to write the method to create the appropriate conditional distribution.\n\n\\begin{problem}\nComplete the method \\li{_conditional()}.\nIt accepts arguments $m,w$ where $m$ is the document and $w$ is an index of \\li{vocab}.\nDon't forget to normalize to ensure you are actually returning a distribution!\n\\end{problem}\n\\end{comment}\nWe are now prepared to write the full Gibbs sampler.\n\n\\begin{problem}\nComplete the method \\li{sample()}.\nThe argument \\emph{filename} is the name and location of a .txt file, where each line is considered a document.\nThe corpus is built by method \\li{buildCorpus}, and stopwords are removed (if argument \\emph{stopwords} is provided).\nBurn in the Gibbs sampler, computing and saving the log-likelihood with the method \\li{\\_loglikelihood}.\nAfter the burn in, iterate further, accumulating your count matrices, by adding \\li{nzw} and \\li{nmz} to \\li{total\\_nzw} and \\li{total\\_nmz} respectively, where you only add every \\emph{sample\\_rate}$^{th}$ iteration.\nAlso save each log-likelihood.\n\\end{problem}\n\nYou should now have a working Gibbs sampler to perform LDA inference on a corpus.\nLet's test it out on one of Ronald Reagan's State of the Union addresses, found in \\texttt{reagan.txt}.\n\n\\begin{problem}\n\nCreate an \\li{LDACGS} object with $20$ topics, letting $\\alpha$ and $\\beta$ be the default values.\nRun the Gibbs sampler, with a burn in of $100$ iterations, accumulating $10$ samples, only keeping the results of every $10$th sweep.\nUse \\texttt{stopwords.txt} as the stopwords file.\n\\end{problem}\n\nPlot the log-likelihoods. How long did it take to burn in?\n\nWe can estimate the values of each $\\phi_{k}$ and each $\\theta_{m}$ as follows:\n\n\\begin{align*}\n\\widehat{\\theta}_{m,k} & = \\frac{n_{(k,m,\\cdot)} + \\alpha}{K \\cdot \\alpha + \\sum_{k=1}^{K} n_{(k,m,\\cdot)}} \\\\\n\\widehat{\\phi}_{k,v} & = \\frac{n_{(k,\\cdot,v)} + \\beta}{V \\cdot \\beta + \\sum_{v=1}^{V} n_{(k,\\cdot,v)}}\n\\end{align*}\n\nWe have provided methods \\li{phi} and \\li{theta} that do this for you. We often examine the topic-term distributions $\\phi_{k}$ by looking at the $n$ terms with the highest probability, where $n$ is small (say $10$ or $20$).\nWe have provided a method \\li{topterms} which does this for you.\n\n\\begin{problem}\nUsing the methods described above, examine the topics for Reagan's addresses. As best as you can, come up with labels for each topic.\nIf $ntopics=20$ and $n=10$, we will get the top $10$ words that represent each of the $20$ topics; for each topic, decide what these ten words jointly represent.\n\\end{problem}\n\nWe can use $\\widehat{\\theta}$ to find the paragraphs in Reagan's addresses that focus the most on each topic. The documents with the highest values of $\\widehat{\\theta}_{k}$ are those most heavily focused on topic $k$.\nFor example, if you chose the topic label for topic $p$ to be \\emph{the Cold War}, you can find the five highest values in $\\widehat{\\theta_{p}}$, which will tell you which five paragraphs are most centered on the Cold War.\n\\begin{comment}\nThis problem was difficult for the first cohort, and since it does not add much to the lab it has been removed.\n\n\\begin{problem}\nIn your above topic analysis, you should have found a topic about the Cold War and one about education. Find the five paragraphs in Reagan's addresses that most closely focus on each of these topics, according to the above method.\n\\end{problem}\n\\end{comment}\n\nLet's take a moment to see what our Gibbs sampler has accomplished.\nBy simply feeding in a group of documents, and with no human input, we have found the most common topics discussed, which are represented by the words most frequently used in relation to that particular topic.\nThe only work that the user has done is to assign topic labels, saying what the words in each group have in common.\nAs you may have noticed, however, these topics may or may not be \\emph{relevant} topics.\nYou might have noticed that some of the most common topics were simply English particles (words such as \\emph{a}, \\emph{the}, \\emph{an}) and conjunctions (\\emph{and}, \\emph{so}, \\emph{but}).\nIndustrial grade packages can effectively remove such topics so that they are not included in the results.\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{LDACGS Source Code} % --------------------------------------------\n\n\\begin{lstlisting}\nclass LDACGS:\n    \"\"\"Do LDA with Gibbs Sampling.\"\"\"\n\n    def __init__(self, n_topics, alpha=0.1, beta=0.1):\n        \"\"\"Initialize system parameters.\"\"\"\n        self.n_topics = n_topics\n        self.alpha = alpha\n        self.beta = beta\n\n    def buildCorpus(self, filename, stopwords_file=None):\n        \"\"\"Read the given filename and build the vocabulary.\"\"\"\n        with open(filename, 'r') as infile:\n            doclines = [line.rstrip().lower().split(' ') for line in infile]\n        n_docs = len(doclines)\n        self.vocab = list({v for doc in doclines for v in doc})\n        if stopwords_file:\n            with open(stopwords_file, 'r') as stopfile:\n                stops = stopfile.read().split()\n            self.vocab = [x for x in self.vocab if x not in stops]\n            self.vocab.sort()\n        self.documents = []\n        for i in range(n_docs):\n            self.documents.append({})\n            for j in range(len(doclines[i])):\n                if doclines[i][j] in self.vocab:\n                    self.documents[i][j] = self.vocab.index(doclines[i][j])\n\n    def initialize(self):\n        \"\"\"Initialize the three count matrices.\"\"\"\n        self.n_words = len(self.vocab)\n        self.n_docs = len(self.documents)\n\n        # Initialize the three count matrices.\n        # The (i,j) entry of self.nmz is the number of words in document i assigned to topic j.\n        self.nmz = np.zeros((self.n_docs, self.n_topics))\n        # The (i,j) entry of self.nzw is the number of times term j is assigned to topic i.\n        self.nzw = np.zeros((self.n_topics, self.n_words))\n        # The (i)-th entry is the number of times topic i is assigned in the corpus.\n        self.nz = np.zeros(self.n_topics)\n\n        # Initialize the topic assignment dictionary.\n        self.topics = {} # key-value pairs of form (m,i):z\n\n        for m in range(self.n_docs):\n            for i in self.documents[m]:\n                # Get random topic assignment, i.e. z = ...\n                # Increment count matrices\n                # Store topic assignment, i.e. self.topics[(m,i)]=z\n                raise NotImplementedError(\"Problem 3 Incomplete\")\n\n    def sample(self,filename, burnin=100, sample_rate=10, n_samples=10, stopwords=None):\n        self.buildCorpus(filename, stopwords)\n        self.initialize()\n        self.total_nzw = np.zeros((self.n_topics, self.n_words))\n        self.total_nmz = np.zeros((self.n_docs, self.n_topics))\n        self.logprobs = np.zeros(burnin + sample_rate*n_samples)\n        for i in range(burnin):\n            # Sweep and store log likelihood.\n            raise NotImplementedError(\"Problem 5 Incomplete\")\n        for i in range(n_samples*sample_rate):\n            # Sweep and store log likelihood\n            raise NotImplementedError(\"Problem 5 Incomplete\")\n            if not i % sample_rate:\n                # accumulate counts\n                raise NotImplementedError(\"Problem 5 Incomplete\")\n\n    def phi(self):\n        phi = self.total_nzw + self.beta\n        self._phi = phi / np.sum(phi, axis=1)[:,np.newaxis]\n\n    def theta(self):\n        theta = self.total_nmz + self.alpha\n        self._theta = theta / np.sum(theta, axis=1)[:,np.newaxis]\n\n    def topterms(self,n_terms=10):\n        self.phi()\n        self.theta()\n        vec = np.atleast_2d(np.arange(0,self.n_words))\n        topics = []\n        for k in range(self.n_topics):\n            probs = np.atleast_2d(self._phi[k,:])\n            mat = np.append(probs,vec,0)\n            sind = np.array([mat[:,i] for i in np.argsort(mat[0])]).T\n            topics.append([self.vocab[int(sind[1,self.n_words - 1 - i])] for i in range(n_terms)])\n        return topics\n\n    def toplines(self,n_lines=5):\n        lines = np.zeros((self.n_topics,n_lines))\n        for i in range(self.n_topics):\n            args = np.argsort(self._theta[:,i]).tolist()\n            args.reverse()\n            lines[i,:] = np.array(args)[0:n_lines] + 1\n        return lines\n\n    def _removeStopwords(self, stopwords):\n        return [x for x in self.vocab if x not in stopwords]\n\n    def _conditional(self, m, w):\n        dist = (self.nmz[m,:] + self.alpha) * (self.nzw[:,w] + self.beta) / (self.nz + self.beta*self.n_words)\n        return dist / np.sum(dist)\n\n    def _sweep(self):\n        for m in range(self.n_docs):\n            for i in self.documents[m]:\n                # Retrieve vocab index for i-th word in document m.\n                # Retrieve topic assignment for i-th word in document m.\n                # Decrement count matrices.\n                # Get conditional distribution.\n                # Sample new topic assignment.\n                # Increment count matrices.\n                # Store new topic assignment.\n                raise NotImplementedError(\"Problem 4 Incomplete\")\n\n    def _loglikelihood(self):\n        lik = 0\n\n        for z in range(self.n_topics):\n            lik += np.sum(gammaln(self.nzw[z,:] + self.beta)) - gammaln(np.sum(self.nzw[z,:] + self.beta))\n            lik -= self.n_words * gammaln(self.beta) - gammaln(self.n_words*self.beta)\n\n        for m in range(self.n_docs):\n            lik += np.sum(gammaln(self.nmz[m,:] + self.alpha)) - gammaln(np.sum(self.nmz[m,:] + self.alpha))\n            lik -= self.n_topics * gammaln(self.alpha) - gammaln(self.n_topics*self.alpha)\n\n        return lik\n\\end{lstlisting}\n", "meta": {"hexsha": "734b400ad3baaa7ce0b2efce01e7291805684e06", "size": 25771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume3/LDA/LDA.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": "Volume3/LDA/LDA.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": "Volume3/LDA/LDA.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": 55.3025751073, "max_line_length": 457, "alphanum_fraction": 0.6833650227, "num_tokens": 7182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6949147342689532}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  What is an element of $\\R^1$?\n\\end{ex}\n\n\\begin{ex} Given the points $P=(2,0,-4)$ and $Q=(5,-2,1)$, find $\\longvect{PQ}$ and $\\longvect{QP}$.\n\n  \\begin{sol}\n\n    \\begin{equation*}\n      \\longvect{PQ}  = \\longvect{0Q} - \\longvect{0P}= \\begin{mymatrix}{c}\n        5-2 \\\\\n        -2-0 \\\\\n        1-(-4)\n      \\end{mymatrix} = \\begin{mymatrix}{c}\n        3 \\\\\n        -2 \\\\\n        5\n      \\end{mymatrix}\n    \\end{equation*}\n\n    \\begin{equation*}\n      \\longvect{QP}  = \\longvect{0P} - \\longvect{0Q}= \\begin{mymatrix}{c}\n        2-5 \\\\\n        0-(-2) \\\\\n        (-4)-1\n      \\end{mymatrix} = \\begin{mymatrix}{c}\n        -3 \\\\\n        2 \\\\\n        -5\n      \\end{mymatrix}\n    \\end{equation*}\n\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Find $x$ and $y$ so that $\\vect{u}= \\mat{5x-3y, 4}^T$ and\n  $\\vect{v}=\\mat{2x-2y, 2y}^T$ are equal in $\\R^2$.\n\n  \\begin{sol}\n    We need $5x-3y=2x-2y$ and $4=2y$. The unique solution is\n    $x=\\frac{2}{3}$ and $y=2$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "38070b8dba5e0cb2bb36669a4444591378bf9114", "size": 995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Vectors-PointsAndVectors.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-PointsAndVectors.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-PointsAndVectors.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": 21.170212766, "max_line_length": 100, "alphanum_fraction": 0.4894472362, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6948992304695224}}
{"text": "I am only considering subdivision surfaces based on triangles\n\\cite{hoppe-et-al-94,hoppe-thesis-94}.\n\n\\subsection{Approximating meshes}\n\\label{sec:Approximating-meshes}\n\nA common approach to the use of subdivision surfaces is\nto approximate the limit surface by the {\\it subdivided mesh,} $\\M^s$,\na $k$ times subdivided version of the {\\it control mesh,} $\\M^c$\n(a typical value for $k$ is 2).\nThe positions of the $n^c$ vertices of the control mesh,\n$\\p^c = (\\p^c_0 \\ldots \\p^c_{n-1}) \\\\in \\Reals^{3n^c},$\nand the $n^s$ vertices of the subdivided mesh,\n$\\p^s = (\\p^s_0 \\ldots \\p^s_{n-1}) \\in \\Reals^{3n^s},$\nare related by the {\\it subdivision transform}\n$\\S : \\Reals^{n^c} \\mapsto \\Reals^{n^s}$.\nIf\n$\\x^c = (x^c_0 \\ldots x^c_{n-1}) \\in \\Reals^{n^c}$,\n$\\y^c = (y^c_0 \\ldots y^c_{n-1}) \\in \\Reals^{n^c}$,\nand\n$\\z^c = (z^c_0 \\ldots z^c_{n-1}) \\in \\Reals^{n^c}$,\nare the $x, y,$ and $z,$ coordinates of $\\p^c$,\nand $\\x^s, \\y^s, \\z^s$ are the same coordinates\nof $\\p^s$, then\n\\begin{eqnarray}\n\\x^s & = & \\S \\x^c\n\\\\\n\\y^s & = & \\S \\y^c\n\\nonumber\n\\\\\n\\z^s & = & \\S \\z^c\n\\nonumber\n\\end{eqnarray}\nWe can use the above to define $\\S_3 : \\Reals^{3n^c} \\mapsto \\Reals^{3n^s}$,\nso that\n\\begin{equation}\n\\p^s = \\S_3 \\p^c.\n\\end{equation}\n\n\nIf $f(\\p^s) = f(\\S_3 \\p^c)$ is a penalty function applied to the subdivided mesh,\nthen the gradient with respect to the positions of\nthe vertices of the control mesh is simply:\n\\begin{equation}\n\\Gc{\\p^c}{f(\\S_3 \\p^c)}{\\q^c} = \\S_3^{\\dagger} \\Gc{\\p^s}{f(\\p^s)}{\\q^s = \\S_3 \\q^c}\n\\end{equation}\n", "meta": {"hexsha": "d4f3d5da844909e51f330f97dfb6e2ad1faf7f03", "size": 1518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/subdivision.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/subdivision.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/subdivision.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": 32.2978723404, "max_line_length": 83, "alphanum_fraction": 0.6343873518, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6948992292892349}}
{"text": "\\section{Optimization}\n\\label{sec:RNN-optim}\n\nAs described previously, we make use of a reference offline labelling of the training data, marking the segments where an SWR is present. This reference labelling can be used to create a training signal $y_t$, that we want the RNN output $n_t$ to approach. As $n_t \\in (0, 1)$ (see \\cref{eq:out}), we can define for example $y_t = 1$ during SWR events, and $y_t = 0$ outside them. Alternatively, we can construct $y_t$ to be $1$ only around the start of each reference SWR segment.\n\nGiven a target signal $y_t$, and the actual RNN output $n_t$, we can compare them to quantify how close the RNN output matches the target signal. We choose cross-entropy for this comparison. The so called \\emph{loss function} $\\ell_t$ is then defined as:\n%\n\\begin{equation}\n\\label{eq:loss}\n\\ell(n_t, y_t) = - y_t \\log(n_t) - (1 - y_t) \\log(1 - n_t)\n\\end{equation}\n%\nThe loss $\\ell_t$ is lower whenever the RNN output is more similar to the target signal. The mean loss $\\expval{\\ell_t}$ over some dataset can thus be used as a proxy for how useful the RNN output $n_t$ is for SWR detection. Just as in \\cref{ch:GEVec}, we want to find the weights $w_i$ (the elements of the matrices $\\W_\\_$ and the vectors $\\bias_\\_$ from \\cref{eq:out,eq:hnew}) that minimize this expected loss $\\expval{\\ell_t}$. Unlike in \\cref{ch:GEVec}, there is no known way to find the global minimum of this function.\n\nInstead, a form of gradient descent is used to iteratively and stochastically approach a local minimum of $\\expval{\\ell_t}$. We divided the training data into 300 ms long chunks. For each such chunk, the total loss $L = \\sum_{300 \\text{ms}} \\ell_t$ is calculated. Then, the partial derivatives $\\pdv*{L}{w_{i,t}}$ of this loss are calculated, for each parameter $w_i$ in the RNN, and for each timestep $t$ in the chunk. This calculation of the gradient of $L$ is done through the so called \\emph{backpropagation} algorithm \\cite{Rumelhart1986}, which is an application of the chain rule from calculus. In this case we apply so called ``backpropagation through time'' (BPTT) -- a common way to train RNN's \\cite{Goodfellow2016}. Such derivative calculations are often done through an automatic differentiation program. In our case, we used the \\texttt{PyTorch} library \\cite{Paszke2017}.\n\nFor each parameter $w_i$ in the RNN, the BPTT algorithm yields a set of partial derivatives $\\{ \\pdv*{L}{w_{i,t_1}}, \\pdv*{L}{w_{i,t_2}}, \\tdots \\}$ that each tell how much and in which direction the chunk loss $L$ changes when the parameter $w_i$ is increased at timestep $t$. Taking the mean of this set of partial derivatives over all timesteps in the chunk yields a value $\\pdv*{L}{w_i}$ that can be used to tell how the parameter $w_i$ should be adapted to decrease the loss $L$:\n%\n\\begin{equation}\n\\label{eq:SGD}\nw_i \\leftarrow w_i - \\eta \\pdv{L}{w_i}\n\\end{equation}\n%\n(i.e. if $\\pdv*{L}{w_i} > 0$ then the loss would increase by increasing $w_i$; so decrease $w_i$). Doing this for all parameters $w_i$ of the RNN results in a complete so called gradient step. $\\eta$ determines the step size, and is called the \\emph{learning rate}. Having a separate and adaptive learning rate $\\eta_{i,t}$ for each parameter has been shown to greatly increase convergence speed of stochastic gradient descent. We used the AdaMax optimization algorithm \\cite{Kingma2014} to update our RNN parameters with such adaptive learning rates, using the default hyperparameters as suggested in the paper.\n\n\n\n\\section{Regularization}\n\\label{sec:RNN-regularization}\n\nRepeating this procedure for all chunks, and for multiple passes over the training data, yields a trained RNN. The danger then exists that the network is \\emph{overfit} to the training data; i.e. it achieves a low loss on the training data, but it performs badly on unseen data. We avoided this with so called \\emph{early stopping} on a validation set.\n\nAs described in \\cref{sec:recording}, the first 20 minutes of the 34 minutes-long recording were used as training data for data-driven online algorithms. For the RNN, these 20 minutes were further split into a part for training proper (the first 15.6 minutes), and a part for validation (the final 4.4 minutes). The RNN was trained for 50 passes over the proper training part. After each training pass (or \\emph{epoch}), the loss on the validation set was calculated, as an estimate of how the RNN would perform on unseen data. The RNN where the validation loss was lowest was then chosen for the final evaluation of online SWR detection performance on the held-out test data. See \\cref{fig:validloss} for an example validation loss curve over training time.\n\n\\begin{figure}\n\\img[0.62]{validloss_fullrect}\n\\captionn{Regularization by early stopping}{Evolution of total loss on the validation data during training of the RNN of \\cref{fig:RNN-envelopes}.}\n\\label{fig:validloss}\n\\end{figure}\n\n% todo: dropout \n", "meta": {"hexsha": "5c3aed885135385c232d8e2dd8b5e75c18094286", "size": 4919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/RNN/Optimize.tex", "max_stars_repo_name": "tfiers/master-thesis", "max_stars_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-23T01:39:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-23T01:39:24.000Z", "max_issues_repo_path": "modules/RNN/Optimize.tex", "max_issues_repo_name": "tfiers/master-thesis", "max_issues_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-10T22:37:35.000Z", "max_forks_repo_path": "modules/RNN/Optimize.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": 117.119047619, "max_line_length": 886, "alphanum_fraction": 0.7601138443, "num_tokens": 1323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.694899227470336}}
{"text": "\n\\subsection{Homomorphisms form a vector space}\n\nIf we can can show that scalars can act on morphisms, then we can shwn that morphisms on a vector space are themselves a vector space.\n\nScalars can act on morphisms, and so morphisms of vector spaces are themselves vector spaces.\n\n\\subsubsection{Dimensions of homomorphisms}\n\nWe can identify the dimensionality of this new vector space from the dimensions of the original vector spaces.\n\n\\(\\dim (\\hom(V, W))=\\dim V \\dim W\\)\n\n", "meta": {"hexsha": "1f01ec5dd41f721c78446f9292c3634326a4f634", "size": 474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/maps/01-02-morphismsVector.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/maps/01-02-morphismsVector.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/maps/01-02-morphismsVector.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.8571428571, "max_line_length": 134, "alphanum_fraction": 0.7784810127, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6946992284858428}}
{"text": "%---------------------------Shape and Size-----------------------------\n\\section{Shape and Size\\label{s:tet-shape-and-size}}\n\nLet $S$ be the shape as defined in \\S\\ref{s:tet-shape}\nand $R$ be the relative size squared as defined in \\S\\ref{s:tet-rel-size-squared}.\nThen the shape and size metric is\n\\begin{displaymath}\nq = S R\n\\end{displaymath}\n\n\\tetmetrictable{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{V}$}%                Equilateral tet\n{\\cite{knu:03}}%                              Citation\n{v\\_tet\\_shape\\_and\\_size}%                            Verdict function name\n\n", "meta": {"hexsha": "6639ded2ffbe48c892b1318a3f6d27c1cff7d744", "size": 808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetShapeAndSize.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/TetShapeAndSize.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/TetShapeAndSize.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.4, "max_line_length": 82, "alphanum_fraction": 0.4690594059, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6946759925587768}}
{"text": "\\section{Pinhole camera}\n\\label{sec:pinhole_camera}\nPinhole camera is the simplest camera model, where light passes through a tiny hole (from which the name \\textit{pinhole camera}) of a box: an inverted image of the scene is projected on the opposite side of the box itself. This effect, known as \\textit{camera obscura effect}, was studied since 500 BC (the first writings are back to the chinese Mozi) and it is the underlying principle of the $19^{th}$ century cameras. An example of the geometry of this camera is shown in Figure \\ref{fig::pinhole}: as it can be seen, for each 3D point there is only one ray of light that passes through the pinhole. This is an ideal condition which allows to neglect distortions, such as blurring. Furthermore it is free of lenses, a condition that accords you to neglect distortions such as vignetting or radial and tangential distortions.\n\\begin{figure}[t!]\n  \\centering\n  \\begin{minipage}[c]{.48\\textwidth}\n  \t\\centering\n    \\includegraphics[width=\\textwidth]{./images/tech/pinhole.png}\n    \\caption{The geometry of a \\\\ pinhole camera}\n    \\label{fig::pinhole}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[c]{.48\\textwidth}\n  \t\\centering\n    \\includegraphics[width=\\textwidth]{./images/tech/image_plane.png}\n    \\caption{Mathematical model}\n    \\label{fig:math_model}\n  \\end{minipage}\n  %\\caption{Examples of different types of occlusions}\n  %\\label{fig:occlusions}\n\\end{figure}\n\nThanks to these simplifications, the mathematical model that describes the relations between the 3D world points and their projections in the image, is very simple. Let's look at the Figure \\ref{fig:math_model}. \n% Let us define the \\textit{camera coordinate system} $\\left(e_x', e_y', e_z' \\right)$: the origin $c = \\left(0,0,0 \\right)$ will represent the so called camera center (i.e. the pinhole).\n% We form the line between $X = \\left( X_1^w, X_2^w, X_3^w \\right)$ and $c$ and intersect it with the plane $z = k$ called \\textit{image plane}, to generate a projection $x = (x_1, x_2, k)$ of a scene point $X$. We will refer to $e_Z$ as the \\textit{viewing direction}.\n% Note that if $k > 0$, the image plane is placed in front of the camera center and the image will not appear upside down. In this case we talk about \\textit{virtual image}, but in real models we put $k < 0$. \\\\\n% Since $Xc$ is a direction vector of the viewing ray we can parametrize it by the expression\n%  \\begin{equation*}\n%    c + s(X - c) = sX \\qquad s \\in \\mathds{R}\n%  \\end{equation*}\n% where $sX_3^w = k$ (intersection with the plane $z = k$). Note that this model does not take into account the scene projection from the image plane to the sensor plane. \\\\\nLet $\\left(e_x', e_y', e_z' \\right)$ be the \\textit{camera coordinate system}, centered in $C = \\left(0,0,0 \\right)$, and let $C$ be the camera center (i.e. the pinhole). Then, let us define the \\textit{image plane} as the 2D plane in the world in which the sensor lies. The point 2D $x = (x_1, x_2)$ in the image plane, is related to the 3D world point $X' = (X'_1, X'_2, X'_3)$ through a linear pathway for point $C$. We can parametrize this transformation with the expression:\n  \\begin{equation}\n    \\begin{pmatrix} x_1 \\\\ x_2 \\end{pmatrix} = - \\frac{f}{X'_3} \\begin{pmatrix} X'_1 \\\\ X'_2 \\end{pmatrix}\n    \\label{eq:image-plane}\n  \\end{equation}\nwhere $f$ is the \\textit{focal length} (the distance from the pinhole to which the rays are focused) of the ideal camera. This is a very simple model, but a point in the image plane does not correspond to a unique point in the world as there are three unknowns on the right hand side. Thanks to the collinearity condition from the points $X'$, $x$ and $C$, the \\acs{DLT} (Direct Linear Transformation, an algorithm used to determine a set of variables from a set of similarity relations) is used: it is simple to solve this intersection and to determine this last projection. \\\\\n\nHowever, this case is unrealistically simple, because the object and image plane are parallel. In real applications, the point $X$ can lie on a plane that have an arbitrary position and rotation, with respect to the image plane. Let us put this new plane into a \\textit{global coordinate reference system} $\\left( e_x, e_y, e_z \\right)$; all points in the 3D world and all the camera movements will be related to this system.\n% In Figure \\ref{fig:math_model} we can see how point $X$ is projected in the image plane, but a questions arise: how we can locate $X$ in the world and where image plane is located respecting to the world? To answer to these questions we have to introduce a new \\textit{global coordinate reference system} $\\left( e_x, e_y, e_z \\right)$; all points in the 3D world and all the camera movements will be related to this system.\nIn this way the projection of the point $X$ in the camera reference system $\\left( e_x', e_y', e_z' \\right)$ is a simple rotation and translation, that in \\textit{homogeneous coordinates} is:\n  \\begin{equation}\n    \\label{eq:extrinsic}\n    \\begin{pmatrix}\n      X'_1 \\\\ X'_2 \\\\ X'_3\n    \\end{pmatrix}\n    =\n    \\begin{bmatrix}\n      R & t\n    \\end{bmatrix}\n    \\begin{pmatrix}\n      X_1 \\\\ X_2 \\\\ X_3 \\\\ 1\n    \\end{pmatrix}\n    =\n    H\n    \\begin{pmatrix}\n      X_1 \\\\ X_2 \\\\ X_3 \\\\ 1\n    \\end{pmatrix}\n  \\end{equation}\nwhere $R$ is a $3 \\times 3$ rotation matrix and $t$ a $3 \\times 1$ translation vector, and they are referred to as \\textit{extrinsic parameters}, while the matrix $H$ is called \\textit{homography matrix}. This is the first projection shown in Figure \\ref{fig:perspective_projection}.\n\\begin{figure}[t!]\n  \\centering\n  \\includegraphics[width=\\textwidth]{./images/tech/perspective_projection.PNG}\n  \\caption{Projection chain from the point $X$ in the world reference system, to $x'$ in the sensor reference system.}\n  \\label{fig:perspective_projection}\n\\end{figure} \\\\\n\nThe Equation \\ref{eq:image-plane} shown us that the image plane is embedded in $\\mathds{R}^3$, so we need to project the point $x'$ in the $\\mathds{N}^2$ sensor coordinate system (in pixel unit). This is possible using a $3 \\times 3$ matrix $K$ of the \\textit{intrinsic parameters}\n  \\begin{equation*}\n    \\label{eq:intrinsic_matrix}\n    K =\n    \\begin{pmatrix}\n      \\gamma_1\t& s\t\t\t& c_x \\\\\n      0\t\t\t& \\gamma_2\t& c_y \\\\\n      0\t\t\t& 0\t\t\t\t& 1\n    \\end{pmatrix}\n  \\end{equation*}\nwhere $\\left( c_x, c_y \\right)$ are the coordinates of the point $C$ in the sensor reference system. The pair $\\left( \\gamma_1, \\gamma_2 \\right)$ are scale factors that translate the image plane unit ($mm$) into sensor unit ($pixel$). Finally, $s$ is called skew factors, and it forces sensor rows and columns to be perpendicular. These are properties of the used camera and are related to non-ideality of camera construction. The projection (the second in Figure \\ref{fig:perspective_projection}) is performed as follow:\n  \\begin{equation}\n    \\label{eq:intrinsic}\n    \\begin{pmatrix}\n      x'_1 \\\\ x'_2 \\\\ 1\n    \\end{pmatrix}\n    = K \n    \\begin{pmatrix}\n      x_1 \\\\ x_2 \\\\ 1\n    \\end{pmatrix}\n  \\end{equation} \\\\\n\nThe chain of all these projections, shown in Figure \\ref{fig:perspective_projection}, is called \\textit{perspective projection}. A common way to indicate Equations \\ref{eq:extrinsic} and \\ref{eq:intrinsic} in a single formula through the \\textit{homogeneous coordinates} is\n  \\begin{equation}\n    \\label{eq:perspective_projection}\n    \\lambda\n    \\begin{pmatrix}\n      x_1 \\\\ x_2 \\\\ 1\n    \\end{pmatrix}\n    = KH\n    \\begin{pmatrix}\n      X_1 \\\\ X_2 \\\\ X_3 \\\\ 1\n    \\end{pmatrix}\n  \\end{equation}\nwhere the parameter $\\lambda$ takes into account the projection in Equation \\ref{eq:image-plane}.\n\n%--------------------------------------------------%\n\\subsection{Lenses}\n\\label{subsec:lenses}\nAs mentioned above, Equation \\ref{eq:perspective_projection} does not consider many non-ideality that affect the quality of images acquisitions. \n\nIn Section \\ref{sec:pinhole_camera} we introduced the fact that, ideally, only one ray per point passes through the pinhole. If on the one hand this guarantees focus, on the other the impression of the scene in the sensor requires too much time. The increasing of the size of the pinhole allows the passage of light, reducing sensor exposure time. However, in this case the projection of the point on the sensor is the result of the mixing of many light rays, condition that reduces the image sharpness until becomes a continuous smear. Lenses are used to solve this problem.\n\nThe role of the lenses is the same as the pinhole: in fact, it allows the passage of light. Their advantage compared to the pinhole is the ability to converge many light rays on a specific point, allowing much more light, and reducing film exposure times. Lens models can be quite complex, so a common practice is considered: the \\textit{thin lens approximation}. A thin lens is a lens with a negligible thickness compared to the radii of curvature of its surface. In this way Equation \\ref{eq:perspective_projection} remains the same. Despite this, the use of lenses introduces some other issues. \\\\\n\nThe amount of light that impresses the sensors is proportional to the lens diameter. The bigger the diameter is, the more light enters in the camera, but we have to consider also the \\textit{magnification}. Magnification is the process of enlarging (factor greater than one) or decreasing (factor less than one, this situation is also called ``minification'') appearance of something. In this case magnification refers to the ability to see more details of the world in a single image. That said, the brightness of the image depends inversely on magnification. A simple way to indicate \\textit{aperture} of a lens (the opening through which light travels), is using the \\textit{f-number} $K$, defined as\n  \\begin{equation}\n    K = \\frac{f}{d}\n    \\label{eq:fnumber}\n  \\end{equation}\nwhere $f$ is the lens focal length and $d$ the aperture diameter. As we can see in Equation \\ref{eq:fnumber}, $K$ decreasing at increasing of $d$. Thanks to $K$, it is possible to compare lenses, considering image luminosity, focal length and magnification. Note that this is a simple rule with no effects on the Equation \\ref{eq:perspective_projection}. \\\\\n  \nAnother problem is the focus of the lens. While a pinhole camera is permanently on-focus (ideal condition), this is not always valid for a lens. In reality a lens is on focus only at a specific distance: this means that only the point at that distance will be perfectly sharp. All the other points that are out-of-focus are projected on film as circles, called \\textit{circles of confusion}. The blur spot shape is due by the aperture shape (that typical is a circle from which the name) and its size increases with the distance from the focus plane. Differently from chemical film, digital sensor are made as a matrix of photosensitive elements (pixels) that convert light in electrical signals; this means that sensors resolution is not infinite. If the circle of confusion is smaller than pixels sizes, we can consider that point on focus. The space range, around the focus plane in which the scene looks reasonably sharp, is called \\textit{depth of field} (\\acs{DOF}). An example of these effects, common in literature, is shown in Figure \\ref{fig:dof}.\n%  \\begin{wrapfigure}{L}{0.5\\textwidth}\n%    \\centering\n%    \\includegraphics[width=0.5\\textwidth]{./images/dof_txt.jpg}\n%    \\caption{Example of a very shallow \\acs{DOF}.}\n%    \\label{fig:dof}\n%  \\end{wrapfigure} \\\\\n  \\begin{figure}[t!]\n    \\centering\n    \\begin{minipage}[c]{.48\\textwidth}\n      \\centering\n \\includegraphics[width=\\textwidth]{./images/tech/dof_txt.jpg}\n      \\caption{Example of a very shallow \\acs{DOF}.}\n      \\label{fig:dof}\n    \\end{minipage}\n    \\hfill\n    \\begin{minipage}[c]{.48\\textwidth}\n      \\centering\n \\includegraphics[width=0.74\\textwidth]{./images/tech/airydisk.jpg}\n      \\caption{Example of an \\textit{airy disk}.\\\\ ~}\n      \\label{fig:airy-disk}\n    \\end{minipage}\n  \\end{figure} \\\\\n\nThe second big advantage of lenses against the pinhole, is the reduction of the diffraction. Diffraction is an effect generated by the interferences of light waves, when the light finds an obstacle or a hole, similar to the size of its wavelength. As the divergent rays now travel to different distances, some of them move out of phase and begin to interfere with each other, adding in some places and partially or completely canceling out in others. This effect, well known in many fields of interest, from electromagnetic to sound, in photography is known as \\textit{airy disk} (by his discoverer, George Airy) and it is shown in Figure \\ref{fig:airy-disk}. As for \\acs{DOF}, even diffraction is negligible if it is smaller than the size of pixels. Diffraction could be present also in the \\acs{DOF} of the camera, and depends only by the $f$-number, not by focal length. Lenses reduce this noise on the image, setting their aperture up appropriately. \\\\\n\nRegardless of the lens model chosen (i.e. thin or thick lenses), their use introduces distortions due to the nature of the lens itself. In geometric optics, a distortion is a deviation from rectilinear projection, caused by small blemishes in the lenses and their alignment. The main optical aberration are two: \\textit{radial distortion} and \\textit{tangential distortion}. \\\\\nAlmost all of the deformation is radial in nature, this is the reason why distortion are more apparent from the center toward the edges of the image. This particular type of distortion is able to change the direction of straight lines, and it is evident during 3D calibration phases, when straight reference objects are seen from the camera as curve. Furthermore, it is often due to the need to expand the field of vision using a camera with short focal distance. Some example of its effects can be seen in Figure \\ref{fig:teo-distorsions}. \\\\\nVice versa, tangential distortion is typically negligible than radial one, then it is ignored in most mathematical models.\n  \\begin{figure}[h!]\n    \\centering\n \\includegraphics[width=0.9\\textwidth]{./images/tech/distorsions.png}\n    \\caption{Example of radial distortions: on the left distortions free image is shown; in center a \\textit{pincushion} aberration; on the right a \\textit{barrel} aberration.}\n    \\label{fig:teo-distorsions}\n  \\end{figure}\n\n%--------------------------------------------------%\n\\subsection{Scheimpflug principle}\nIn the previous subsection we talked about \\acs{DOF} and the problem to maintain focus on the whole scene. Furthermore, we dealt with the Figure \\ref{fig:dof} to show the result. Anyway, in the figure we can see that the subject lies on a plane not parallel with the sensor plane. Typical cameras and lenses are designed so that sensor plane, lens plane and subject plane are parallel to each other. This makes the focus of the camera very simple but, as said in Subsection \\ref{subsec:lenses} talking about the rectilinear projection, the effective focal length depends by the position of the target with respect to the sensor itself. \\\\\n\nSince the early $20^{th}$ century, the study of rotating the lens with respect to the sensor, and its effects on image acquisition, has been a widespread practice. In $1901$, Carpenter (one of the fathers of cinema) patented the first prototype of the so called ``view camera'' \\cite{pat:carpentier}. From these studies, the Captain T. Scheimpflug patented \\cite{pat:scheimpflug} in 1904. With his patent, Scheimpflug was the first to formulate the mathematical problem. The \\textit{Scheimpflug principle} is a geometric rule that describes the relations between the sensor plane, then lens plane and the plane of focus when the lens plane is not parallel to the image plane. To achieve this situation, some cameras, such as view cameras, allow to tilt either the lens and the film, relative to the other. \\\\\n  \\begin{figure}[b!]\n    \\centering\n    \\begin{minipage}[c]{0.49\\textwidth}\n      \\centering\n      \\includegraphics[width=\\textwidth]{./images/tech/sch_par.png}\n    \\end{minipage}\n    \\hfill\\\n    \\begin{minipage}[c]{0.49\\textwidth}\n      \\centering\n      \\includegraphics[width=\\textwidth]{./images/tech/sch_tilt.png}\n    \\end{minipage}\n    \\caption{(On the left) For standard cameras, the sensor, lens and focus planes are parallel to one another. (On the right) For a view camera, tilting lens causes the plane of sharp focus to tilt as well.}\n    \\label{fig:scheimpflug}\n  \\end{figure}\n\nThis principle asserts that when the lens is tilted, lens plane, image plane and the plane of focus all intersects in a line, called \\textit{Scheimpflug line}, as illustrated in Figure \\ref{fig:scheimpflug}. In this way, a subject that is not parallel to the sensor can be completely in focus. Nevertheless, this first relation does not give any information about how to tilt the lens to achieve the intended position for the plane of focus. This information arises from the laws of optics, thanks to the \\textit{hinge rule}, similar to Scheimpflug one. The required amount of lens tilt is given by the expression:\n  \\begin{equation*}\n    \\alpha = \\arcsin \\left( \\frac{f}{J} \\right)\n  \\end{equation*}\nwhere $f$ is the focal length of the lens, and $J$ is the distance from the lens and the \\textit{hinge line}. The hinge line is the intersection between a plane parallel with the sensor and passing through the lens one, and the plane of focus. \\\\\nFrom this principle we can also determine the \\acs{DOF} of the camera. It can be demonstrated that the limits of the \\acs{DOF} are also planes, that passes through the hinge line, and symmetrical compared to the plane of focus. To be precise, these planes lies at a distance $J$ from the plane of focus, distance measured at the \\textit{hyperfocal distance} $H$ from the hinge line \\cite{book:ftvc}. The scenario is illustrated in Figure \\ref{fig:sch_dof}.\n  \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{./images/tech/sch_dof.png}\n    \\caption{Depth of field in view cameras, with tilted lenses.}\n    \\label{fig:sch_dof}\n  \\end{figure}\n\n%--------------------------------------------------%\n\\subsection{Overview on digital cameras}\n\\label{subsec:overview-cameras}\nTo complete the introduction on digital camera we think that it could be useful to linger over some practical aspects, in particular about what concerns manufacturing of the sensor and image acquisitions. \\\\\n\nIn Subsection \\ref{subsec:lenses} we introduced the quantization effect due by pixels. If it relaxes the problem of the lens focus, on the other hand it introduces noise in light to image conversion. We briefly analyse the two most popular sensor types on the market: \\acs{CMOS} and \\acs{CCD} (Charge-Coupled Device).\n\nIn \\acs{CMOS} sensors, each element has its own signal amplifier: this allows to improve the camera frame rate and to isolate regions of interests via hardware. On the contrary, pixels haven't the same sizes neither the same doping, which reduces the quality of the sensor itself. The latest CMOS sensors on the market are good enough to be used in computer vision, achieving excellent results.\n\n\\acs{CCD} are high-scale integration sensors that use only one signal amplifier, ensuring the same amplification constant for each element. However, this requires that sensor rows are converted one by one, by lowering the camera frame rate. Furthermore these sensors give a very small, but non-zero response to a zero input and they saturate for very bright stimuli. In spite of that, they are much less noisy than the CMOS.\n\nThese differences are very delicate, specially considering the fields of application of the camera. For example, in laser triangulation systems, the acquired images are dark to highlight the laser light. In situation like this, when the brightness of the image is very low\\footnote{In this case we consider source of light with brightness near to the base noise level of the sensor.}, signals amplification offsets are meaningful. The mono-pixel amplifiers in \\acs{CMOS} are more noisy and generate less uniform values than \\acs{CCD}, resulting in a more homogeneous output. This source of noise is known as \\textit{thermal noise}. High quality systems provide different solutions to reduce this effect as much as possible. In Figure \\ref{fig:thermal-noise} an example of the noise is shown.\n  \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{./images/tech/dark-example.jpg}\n    \\caption{Example of uncontrolled dark noise in astronomical photography.}\n    \\label{fig:thermal-noise}\n  \\end{figure} \\\\\n\nAnother problem due to sensor quantization, is colours acquisition. Each pixel is able to acquire only light signals, resulting in grey scale acquisitions. For this reason sensors needed filters to encode colours. The most widespread is \\textit{Bayer's color filter array} (Bayer's \\acs{CFA}). A \\acs{CFA} is an array in which passband filters are placed, according to a known pattern. In this way each pixel is able to encode only a specific colour. Many algorithms are used to reconstruct the scene; they interpolate signals collected by near pixels and extract the correct colour for each pixel. To perform measures, this is a waste of pixels: the presence of the filter reduces the sensor surface useful to collect world details. For these reasons, grey scale cameras are often used.\n", "meta": {"hexsha": "8cfe1463265ac69e04d017b6e2fdc297521d2e38", "size": 21339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch2-Technology/1_camera_model.tex", "max_stars_repo_name": "extoxesses/LaserMat", "max_stars_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-05-12T08:53:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T06:36:55.000Z", "max_issues_repo_path": "report/thesis/src/chapters/ch2-Technology/1_camera_model.tex", "max_issues_repo_name": "extoxesses/LaserMat", "max_issues_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/thesis/src/chapters/ch2-Technology/1_camera_model.tex", "max_forks_repo_name": "extoxesses/LaserMat", "max_forks_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 102.1004784689, "max_line_length": 1057, "alphanum_fraction": 0.7483012325, "num_tokens": 5465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.6946660929195333}}
{"text": "\\chapter{Kalman Filtering}\n\\label{ch:kalman_filter}\n%\nThe Kalman filter is over 50 years old but is still one of the most important and common data fusion algorithms in use today. \nNamed after Rudolf E.Kálmán, the great success of the Kalman filter is due to its small computational requirement, elegant recursive properties, and its status as the optimal estimator for one-dimensional linear systems with Gaussian error statistics. \nTypical uses of the Kalman filter include smoothing noisy data and providing estimates of parameters of interest. \nKalman filtering is used in a wide range of applications include global positioning system receivers, in control systems, through to the smoothing the output from laptop trackpads, and many more.\n\n\\section{Overview of Kalman Filtering}\n\nKalman filter are typically used to estimate parameters which change with time. \nParameters with no process noise are called deterministic.\nA Kalman filter has measurements $y_t$, with noise $y_t$, and a state vector $\\hat x_t$ (or a parameter list) which have specified statistical properties.\n\nThe observation equation at time t:\n\\begin{equation}\n    y_t = H_t x_t + \\epsilon_t\t \\label{eq:kfObs}\n\\end{equation}\n\nThe state transition equation:\n\\begin{equation}\n    x_{t+} = F_t x_t + w_t\t\n\\end{equation}\n\nThe kalman filter processing is broken up into three main steps.\n\n\\textit{Prediction} {uses a process noise model} to 'predict' the parameters at the next data epoch, subscript is time quantity refers to, where as the superscript refers to the time of the data:\n\\begin{equation}\n    \\hat{x}_{t+1}^t = F_t \\hat{x}_t^t\n\\end{equation}\nwhere, $F_t$ is the state transition matrix\n\\begin{equation}\n    P_{t+1}^t = F_t P_t^t F_t^\\intercal + Q_t\n\\end{equation}\nwhere, $Q_t$ is the process noise covariance matrix.\nThe state transition matrix $F$ projects the state vector (parameters) forward to the next epoch.\n\\begin{itemize}\n    \\item For random walk $F$ = 1\n    \\item For rate terms: $F$ is matrix \n    $\\begin{bmatrix}\n    1 & \\delta t\\\\\n    0 & 1\n  \\end{bmatrix}$\n    \\item for FOGM: $F$ = $e^{-\\delta t \\beta}$\n    \\item For white noise $F$ = 0\n\\end{itemize}\nThe second equation projects the covariance matrix of the state vector, $P$, forward in time. Contributions from the state transition and process noise ($Q$ matrix). \n$Q$ elements are 0 for deterministic parameters.\n%\n\\textit{The Kalman gain} {is the matrix} that allocates the differences between the observation at time t+1 and their predicted value at this time based on the current values of the state vector according to the noise in the measurements and the state vector noise.\n\n\\section{Comparison between Weighted Least Squares and Kalman Filtering}\n\n\\begin{itemize}\n    \\item In kalman filtering apriori constraints must be give for all parameters. This is not needed in weighted least squares, but can also be done.\n    \\item Kalman filters can allow for 0 variance parameters, this cannot be done in WLS, as this requires the inversion of the constraint matrix.\n    \\item Kalman filter can allow for a method of applying absolute constraints, WLS can only tightly constrain parameters.\n    \\item Kalman filters are more prone to numerical stability problems, and take longer to run (they have more parameters).\n    \\item Process noise models can be implemented in WLS, but they are computationally slow.\n\\end{itemize}\n\n\\section{Implementation in the PEA}\n\n\\subsection{Robust Kalman Filter Philosophy}\n\nIt is well known that the Kalman filter is the optimal technique for estimating parameters of interest from sets of noisy data - provided the model is appropriate.\n\nIn addition, statistical techniques may be used to detect defects in models or the parameters used to characterise the data, providing opportunities to intervene and make corrections to the model according to the nature of the anomaly.\n\nBy incorporating these features into a single generic module, the robustness that was previously available only under certain circumstances may now be automatically applied to all systems to which it is applied. These benefits extend automatically to all related modules (such as RTS), and often perform better than modules designed specifically to address isolated issues.\n\n\\subsection{Initialisation}\n\nWhen parameters' initial values are not known a-priori, it is often possible to determine them using a least-squares approach.\n\nTo minimise processing times, the minimal subset of existing states, measurements, and covariances are used in least-squares estimation whenever the initial value and variance of a parameter is unspecified.\n\nFor rate parameters, multiple epoch’s worth of data are required for an ab-initio initialisation. This logic is incorporated into the filter and is applied automatically as required.\n\n\\subsection{Outlier detection, Iteration, and Hypothesis Testing}\n\nAs a statistical machine, the Kalman filter is capable of detecting measurements that do not fit within the system as modelled.\n\nIn these cases, the model may be adjusted on-the-fly, to allow all measurements to be continued to be used without contaminating the results in the filter.\n\nA typical example of a modelling error in GNSS processing is a cycle-slip, in which the ambiguity term (which usually modelled with no change over time) has a discontinuity. Other examples may include clock-jumps or satellite burns.\n\nHypotheses are to be generated for any measurements that are statistical outliers, and the model iterated as required.\n\n\\subsection{Performance Optimisation}\n\nThe inversion of large matrices as required by the Kalman filter easily dominates the processing time required during operation. Techniques are available to reduce, and distribute this processing burden across multiple processors.\n\nThe Eigen library is used for algebraic manipulation which allows for automatic parallelisation of vector algebra, and improves code robustness by checking matrix dimensions while in use.\n\n\\subsubsection{Chunking}\n\nBy dividing measurements into multiple smaller sub-matrices, the long inversion times may be reduced, as the inversion order is of $O(n^3)$\n\n\\subsubsection{Blocking}\nBy separating the filter covariance matrix into a block-diagonal form, individual blocks of the filter may be processed individually, without degredation in accuracy. This may improve performance, and may also enable blocks that are relatively independent to be processed separately, albeit with some degredation in accuracy.\n\n\\section{Configuration} \\label{KFConfig}\n\nAll elements within the kalman filter are configured using the yaml configuration file, and use a consistant format.\n\n\\subsection{default\\_filter\\_parameters}\n\n\\begin{lstlisting}[language=yaml,caption=Filter Parameters:]\n\ndefault_filter_parameters:\n\n    stations:\n\n        error_model:        elevation_dependent         #uniform elevation_dependent\n        code_sigmas:        [0.15]\n        phase_sigmas:       [0.0015]\n\n        pos:\n            estimated:          true\n            sigma:              [0.1]\n            proc_noise:         [0] #0.57 mm/sqrt(s), Gipsy default value from slow-moving\n            proc_noise_dt:      second\n            #apriori:                                   # taken from other source, rinex file etc.\n            #frame:              xyz #ned\n            #proc_noise_model:   Gaussian\n\n        clk:\n            estimated:          true\n            sigma:              [0]\n            proc_noise:         [10]\n            proc_noise_dt:      second\n            #proc_noise_model:   Gaussian\n\n        clk_rate:\n            estimated:          false\n            sigma:              [500]\n            proc_noise:         [1e-4]\n            proc_noise_dt:      second\n            clamp_max:          [+500]\n            clamp_min:          [-500]\n            \n    satellites:\n\n        clk:\n            estimated:          true\n            sigma:              [1000]\n            proc_noise:         [1]\n            #proc_noise_dt:      min\n            #proc_noise_model:   RandomWalk\n\n        # clk_rate:\n        #     estimated:          true\n        #     sigma:              [10]\n        #     proc_noise:         [1e-5]\n        #     # clamp_max:          [+500]\n        #     # clamp_min:          [-500]\n\n        orb:\n            estimated:          false\n\n    eop:\n        estimated:  true\n        sigma:      [40]\n\n\noverride_filter_parameters:\n\n    stations:\n        #ALIC:\n            pos:\n                sigma:              [0.001]\n                proc_noise:         [0]\n\\end{lstlisting}\n\n\nThe majority of estimated states are configured in this section. These configurations are applied to all estimates unless another configuration overrides these parameters in the override\\_filter\\_parameter section.\n\nThe parameters that are available for estimation include:\n\\begin{itemize}\n\\item stations:\n\\begin{itemize}\n\\item pos\n\\item pos\\_rate\n\\item clk\n\\item clk\\_rate\n\\item amb\n\\item trop\n\\item trop\\_grads\n\\end{itemize}\n\\item satellites:\n\\begin{itemize}\n\\item pos (coming soon)\n\\item pos\\_rate (coming soon)\n\\item clk\n\\item clk\\_rate\n\\item orb\n\\end{itemize}\n\\end{itemize}\n\n\n\\subsection*{estimated:}\n\nBoolean to add the state(s) to the kalman filter for estimation.\n\n\\subsection*{sigma:}\n\nList of a-priori sigma values for each of the components of the state.\n\nIf the sigma value is left as zero (or not initialised), then the initial variance and value of the state will be estimated by using a least-squares approach.\nIn this case, the user must ensure that the solution is likely rank-sufficient, else the least-squares initialisation will fail.\n\nFor states with multiple elements (eg, X,Y,Z positions), multiple sigma values may be added to the list. However, if insufficient values are added to the list, the intialiser will use the last value in the list for any extra elements.\nie. Setting \\lstinline{sigma: [10]} is sufficient to set all x,y,z components of the apriori standard deviation to 10.\n\n\\subsection*{proc\\_noise:}\n\nList of process noises to be added to the state during state transitions. These are typically in m/sqrt(s), but different times may be assigned separately.\nAs for the sigma list, the last value will be used for any elements exceeding the list length.\n\n\\subsection*{proc\\_noise\\_dt:}\n\nUnit of measure for process noise. \nMay be left undefined for seconds, or using sqrt\\_second, sqrt\\_seconds, sqrt\\_minutes, sqrt\\_hours, sqrt\\_days, sqrt\\_weeks, sqrt\\_years.\n\n\\subsection{override\\_filter\\_parameters:}\n\nIn the case that a specific station or satellite requires an alternate configuration, or to exclude estimates entirely, the override\\_filter\\_parameters section may be used to overwrite selected components of the configuration.\n\n\n\\subsection{user\\_filter\\_parameters, network\\_filter\\_parameters:}\n\nThe internal operation of the kalman filter is specified in this section. It has a large impact on the robustness, and associated processing time that the filter will achieve.\n\n\\begin{lstlisting}[language=yaml,caption=Filter Operating Parameters:]\n\nuser_filter_parameters:\n\n    max_filter_iterations:      5 #5\n    max_prefit_removals:        3 #5\n\n    rts_lag:                    -1      #-ve for full reverse, +ve for limited epochs\n    rts_directory:              ./\n    rts_filename:               PPP-<CONFIG>-<STATION>.rts\n\n    inverter:                   LLT         #LLT LDLT INV\n\n\\end{lstlisting}\n\n\n\\subsection*{max\\_prefit\\_removals:}\n\nMaximum number of pre-fit residuals to reject from the filter.\n\nAfter the vector of residuals has been generated and before the filter update stage is computed, the residuals are compared with the expected values given the existing states and design matrix.\nIf the values are deemed to be unreasonable - because the variances of the transformed states and measurements do not overlap to with a 4-sigma level of confidence - then these measurements are deweighted by deweight\\_factor, to prevent the bad values from contaminating the filter.\n\nThese measurements are recorded as being rejected, and may have additional consequences according to other configurations such as phase\\_reject\\_limit.\n\n\\subsection*{max\\_filter\\_iterations:}\n\nMaximum number of times to compute the full update stage due to rejections.\n\nThis is similar to the max\\_filter\\_rejections parameter, but the 4-sigma check is performed with post-fit residuals, which are much more precise.\n\nRejections that occur in this stage require the entire filter inversion to be repeated, and has an associated performance hit when used excessively.\n\n\n\\subsection*{inverter:}\n\nThere are multiple inverters that may be used within the kalman filter update stage, which may provide different performance outcomes in terms of processing time and accuracty and stability.\n\nThe inverter may be selected from:\n\\begin{itemize}\n\\item llt\n\\item ldlt\n\\item inv\n\\end {itemize}\n\n\n\n\\subsection{outage\\_reset\\_limit:}\nMaximum number of epochs with missed phase measurements before the ambiguity associated with the measurement is reset.\n\n\\subsection{phase\\_reject\\_limit:}\nMaximum number of phase measurements to reject before the ambiguity associated with the measurement is reset.\n\n\n\\subsection*{rts\\_X:}\n\nFor details about rts configuration, see section \\ref{ch:RTS}\n\n\n\n\n\n\n\n\\subsection{Process Noise Guidelines}\n\nCurrently in the PEA we have random walk process noise models implemented.\n\nThe units are typically in meters, and they are given as $\\sigma$ = $\\sqrt{variance}$\n\nFor a random walk process noise, the process noise is incremented at each epoch as $\\sigma^2\\times dt$ where dt is the time step between filter updates.\n\nIf you want to allow kinematic processing, then you can increase the process noise e.g.\\\\\nproc\\_noise [0.003]\\\\\nproc\\_noise\\_dt: second\\\\ \n\nequates to $0.003\\frac{1}{\\sqrt{s}}$\n\\\\ \nOr if you wanted highway sppeds 100km/hr = 28 m/s\\\\\nproc\\_noise [28]\\\\\nproc\\_noise\\_dt: second\n\nA nice value for using VMF as an apriori value is 0.1mm /sqrt(s)\n%\n\\begin{lstlisting}\ntrop:\n    estimated:          true\n    sigma:              [0.1]\n    proc_noise:         [0.01]\n    proc_noise_dt:      hour\n\\end{lstlisting}\n\n\n\n\\section{Recommended Reading}\n\n\\begin{enumerate}\n    \\item https://ocw.mit.edu/courses/earth-atmospheric-and-planetary-sciences/12-540-principles-of-the-global-positioning-system-spring-2012/lecture-notes/MIT12\\_540S12\\_lec13.pdf\n\\end{enumerate}\n\n\n\n\n\n\n", "meta": {"hexsha": "abde6a9f4f2590282c9be5bc3440d40bdf148753", "size": 14378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manual/kalman_filter.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/kalman_filter.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/kalman_filter.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": 42.2882352941, "max_line_length": 373, "alphanum_fraction": 0.7320211434, "num_tokens": 3228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.8080672112416736, "lm_q1q2_score": 0.6946660865747722}}
{"text": "\\section{Background}\n\\label{background}\n\n\\subsection{Resilience analysis using Graph Theory}\n\\label{resilience}\n\nThe seminal works in \\cite{2000Natur.406..378A,DaqingAl14} address contingency analysis for the power grid using simulation of complex networks. Typically, the power grid is modeled using generator, transmission, and distribution nodes. In such scale-free networks, a large fraction of the nodes have low degrees and a substantially smaller fraction exhibit high degrees. Those networks are established to be resilient against random failures upon nodes, and the overall loss to be contingent upon the targeting of the high-degree hubs \\cite{AlbertAl00, CohenAl00, CohenAl01, CallawayAl00}. \n\\edited{\nIn addition to topological analysis of the power grid, other metrics can be used to assess its vulnerability. These are based on the physical properties of the network such as line resistance and sensitivity, which encapsulate the impedance matrix and consequently, the  ``electrical centrality'',  the equivalent of topological centrality, is computed and node removal strategies can be tested accordingly~\\cite{Hines:2007bt,WangST10}. \n\nEquivalently, vertex vulnerability or network robustness can be evaluated through percolation measures such as the average inverse geodesic and the giant component, which emerges subsequent to attacks and exhibits a dependence on the node removal strategy and on the topology of the network under scrutiny~\\cite{Bianconi:2016ka,Callaway:vd,Karrer:2014ep,Radicchi:2015gp}. \nWe will thus focus our effort on a graph-based approach to vulnerability since the physical properties of the power grid were not made available to us.}\n\nIn our Spark implementation we aim to distribute the random and cascading failure scenarios explored by \\cite{2000Natur.406..378A}, which in turn models the North American power grid using its transmission lines, and examines its connectivity in relation to a small set of high impact nodes. \n\nThe notion of connectivity is based on the notion of betweenness centrality. A node's betweenness centrality is a focal measure of connectedness in a graph, built around the notion of shortest paths. Given any two vertices in a graph, there exists at least one shortest path between the vertices. When the length of the path is infinity, it is understood to say that there is no path to connect the given two vertices. If the graph is weighted, the shortest path is obtained by minimising the number of edges that the path passes through. Else, the path is obtained by minimising the sum of the weights of the edges that the path passes through. Given an arbitrary vertex in a graph, its betweenness centrality is defined to be the number of shortest paths that pass through the given vertex. Exploiting betweenness centrality has been widespread in a number of works addressing power grid vulnerability analysis. The work in \\cite{2000Natur.406..378A} employs this notion using four scenarios each of which simulates a unique temporal mode of removal of vertices. For example, the overall connectivity of the graph is re-examined upon removal of transmission nodes according to the following orders: (1) totally random order (2) decreasing order of node degrees (load) (3) decreasing order of node betweennees centrality and (4) decreasing order of node betweenness centrality in cascading order resulting from the nodes' dynamical removal. \\edited{\nThe cascading scenario is based on recalculated information or more precisely after the identification of the most central node of the initial graph and subsequent to its removal a new graph ensues. The central node of the latter should then be computed and then the process is iterated over.}\n\nThe approach taken in \\cite{JinAl10} considers the intensity of the power flowing on a transmission branch, as opposed to the degree of nodes. The resulting graph is weighted (but still undirected), and the contingency analysis method there is based on applying edge betweenness centrality \\cite{GirvanAl02} to the power grid topology. High-impact components in the power grid are defined using the most traversed edges. We believe this approach is less exhaustive than the one adopted by \\cite{2000Natur.406..378A}, and we do not pursue it here.\n\nOur spatial understanding of the propagation of faults in the Lebanese power grid makes classical use of the concept of spatial correlation \\cite{CavagnaAl10, MakseAl95}. As a leading example that we follow, this measure is used in \\cite{DaqingAl14} to measure the relation between failures separated at some distance $r$. More details follow in Sec. \\ref{methods}.\n\n\n\\subsection{Distributed Computation frameworks}\n\\label{distcomp}\nIn the following, we discuss two distributed computation frameworks: (1) MapReduce and Pregel; (2) Spark and GraphX.\n\n\\subsubsection{MapReduce and Pregel}\nThe last few years have witnessed an uptake in distributed data processing research. Among the leading frameworks to exploit distributed computation on commodity hardware is the MapReduce paradigm \\cite{mapreduce}. A typical MapReduce program consists of the ``Map'' operator that parcels out work to various nodes within the cluster or map, and the ``Reduce'' phase that applies a reduction operator on the results from each node into a global query. The key contributions of the MapReduce framework are the scalability and fault-tolerance achieved for a variety of applications by optimizing the execution engine, for example, by reassigning tasks when a given execution fails. As with all other parallel and distributed paradigms, the performance of an efficient MapReduce algorithm is contingent upon a reduced communication cost. Of particular challenge is how to efficiently process large graphs. Graph algorithms often exhibit poor locality of reference, and a low compute-to-memory access ratio, which affects the scalability of their parallel adaptations. It is also difficult to maintain a steady degree of parallelism over the course of execution of graph algorithms. Additionally, expressing a graph algorithm in MapReduce requires passing the entire state of the graph from one stage to the next, thus imposing significant communication as well as serialisation in the parallel code. \n\nThe first serious development for supporting graph algorithms using the MapReduce framework is found in Google's Pregel \\cite{Pregel}. Instead of coordinating the steps of a chained MapReduce program, Pregel is able to process iteration over supersteps under the Bulk Synchronous Parallel model \\cite{Biss04, McColl2, Valiant}. In a BSP algorithm, a computation proceeds in a series of global supersteps. Each superstep consists of three phases:\n\\begin{enumerate}\n\\item{A concurrent computation superstep: each processor performs local computations using values stored in the local, fast memory of the processor.}\n\\item{A communication superstep: the processes exchange data between themselves if needed for the aggregation of the results computed in (1) above.}\n\\item{A barrier synchronisation superstep: each processor halts until all other processes have reached the same barrier.}\n\\end{enumerate}\nAccording to this model, a graph algorithm in Pregel is organised as a sequence of iterations, and can be described from the point of view of a vertex, that manages its state and sends messages only to its neighbours. Pregel keeps vertices and edges on the machine that performs computation, and uses network transfers only for messages.\n\n\\subsubsection{Spark and GraphX}\n\nSpark, a distributed computation framework built around the MapReduce paradigm, is a recent Apache foundation software project supported by an execution engine for big data processing. Spark provides for in-memory computation, which refers to the storage of information in the main random access memory (RAM) of dedicated servers rather than in relational databases running on relatively slower disk drives. Using over $80$ high-level operators, Spark makes it possible to write code more succinctly, and till this point in time, is considered one of the fastest frameworks for big data processing. Spark's most notable properties are also thanks to its core, which, in addition for serving as the base engine for large-scale parallel and distributed data processing, is able to handle memory management and fault recovery, scheduling, distributing and monitoring jobs on a cluster, as well as interacting with storage systems.\n\nSpark hinges on parallel abstract data collections called RDDs (resilient distributed datasets), which can be distributed across a cluster. These RDDs are immutable, partitioned data structures that can be manipulated through multiple operators like Map, Reduce, and Join. For example, RDDs are created through parallel transformations (e.g., map, group by, filter, join, create from file systems). RDDs can be cached (in-memory) by allowing to keep data sets of interest locally across operations, thus contributing to a substantial speedup. At the same time, Spark uses lineage to support fault tolerance, i.e., record all the operations/transformations that yield RDDs from a source data. In case of failure, an RDD can be reconstructed given the transformation functions contributing to that RDD. Additionally, after creating RDDs, it is possible to analyse them using actions such as count, reduce, collect and save. Note that all operations/transformations are lazy until one runs an action. At that point, the Spark execution engine pipelines operations and determines an execution plan.\n\nBorrowing from Pregel, GraphX~\\cite{graphx} is a platform built on top of Spark that provides APIs for parallel and distributed processing on large graphs. In GraphX, each graph is mapped into different RDDs, where in each RDD one applies the computation on the graph using the ``think like a vertex'' model. \n\n", "meta": {"hexsha": "2a3558426f56e0c2c8594e03e8413b9c1720ebec", "size": 9865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/journal-tcss/Background.tex", "max_stars_repo_name": "okm02/Power-grid-analysis", "max_stars_repo_head_hexsha": "1c24a2c8bcdedd04d3e63f2db7abfa6ab135a107", "max_stars_repo_licenses": ["MIT"], "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/journal-tcss/Background.tex", "max_issues_repo_name": "okm02/Power-grid-analysis", "max_issues_repo_head_hexsha": "1c24a2c8bcdedd04d3e63f2db7abfa6ab135a107", "max_issues_repo_licenses": ["MIT"], "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/journal-tcss/Background.tex", "max_forks_repo_name": "okm02/Power-grid-analysis", "max_forks_repo_head_hexsha": "1c24a2c8bcdedd04d3e63f2db7abfa6ab135a107", "max_forks_repo_licenses": ["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.8936170213, "max_line_length": 1450, "alphanum_fraction": 0.8165230613, "num_tokens": 2002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.6946660796959183}}
{"text": "\\section{Periodic Orbits as Solutions of System of Equations, the Galerkin Operator}\n\n%stationary? ordinary?\nGiven a system of $n \\in \\N$ possibly non-linear, autonomous, ordinary, first-order differential equations $\\mathbf{x}$\n\t\\begin{equation} \\label{eq:SDE}\n\t\t\\frac{d\\mathbf{x}}{dt} = \\mathbf{f}(t, \\mathbf{x}) \\text,\n\t\\end{equation}\nwe are interested in numerically computed, periodic solutions.\nThat is, solutions $\\mathbf{y}: \\R \\to \\C^n$ which obey $\\mathbf{y}(t) = \\mathbf{y}(t+T)$ for all $t \\in \\R$ and some period $T \\in \\R$.\nThis is the general case, as differential equations of any degree can be converted to a system of first-order differential equations.\n\n\\paragraph{Model} Solution candidates need to be modeled in a certain way.\nThe periodicity constraint suggests using a multidimensional trigonometric polynomial of degree $m \\in \\N$\n\t\\[\n\t\t\\mathbf{y} \\coloneqq \\sum_{k = -m}^m \\mathbf{y}_k \\exp\\left(i \\omega k t\\right) \\text{,}\n\t\\]\nwhere $\\mathbf{y}_k \\in \\C^n$, $\\omega = \\frac{2\\pi}T$. %$\\mathbf{y}_{-k} = \\Re(\\mathbf{y}_k) - i \\Im(\\mathbf{y}_k)$ for $k \\in \\N$, $-m \\le k \\le m$,\nSolution candidates of this form satisfy $\\mathbf{y}(t) = \\mathbf{y}(t+T)$ by definition.\n%A function of this form is defined solely by its $m+1$ unique coefficients $\\mathbf{y}_k$ for $0 \\le k \\le m$.\n\n\\paragraph{Optimality Criterion} Finding good solutions, that is, functions $\\mathbf{y}$ which at least approximate $\\mathbf{y}^\\prime = \\mathbf{f}(t, \\mathbf{y})$, requires a way of judging whether a solution candidate is indeed a correct solution.\nIn this case, Galerkin's method takes this role.\nA useful property of the trigonometric polynomial is, that it can be trivially differentiated\n\t\\begin{equation}\n\t\t\t\\frac{d\\mathbf{y}}{dt} = \\sum_{k = -m}^m i \\omega k \\mathbf{y}_k \\exp\\left(i \\omega k t\\right) \\text.\n\t\\label{eq:trigondiff}\n\t\\end{equation}\nEmploying this property in the definition of the differential equation system yields\n\t\\begin{align*}\n\t\t\t& \\frac{d\\mathbf{y}}{dt} = \\mathbf{f}(t,\\mathbf{y})\\\\\n\t\t\\Leftrightarrow\\ & \\mathbf{f}(t,\\mathbf{y}) - \\frac{d\\mathbf{y}}{dt} = 0\\\\\n\t\t\\Leftrightarrow\\ & \\mathbf{f}(t,\\mathbf{y}) - \\sum_{k = -m}^m i \\omega k \\mathbf{y}_k \\exp\\left(i \\omega k t\\right) = 0 \\text.\n\t\\end{align*}\nThe difference between these two functions is called the \\emph{residual} $\\mathbf{r}(t) \\coloneqq \\mathbf{f}(t,\\mathbf{y}) - \\frac{d\\mathbf{y}}{dt}$.\nA candidate $\\mathbf y$ is a solution if and only if $\\mathbf r = 0$.\n%Checking for $\\mathbf{r}(t) = 0$ would require comparing the two functions at infinitely many points. %TODO fix... not changed by galerkin\nThe solution of the system of differential equations will generally not be representable by a trigonometric polynomial.\nThe residual can thus not genuinely equal zero.\n\n\\paragraph{Galerkin's Method} Galerkin's method relaxes the equality requirement such that only projections onto a set of so called \\emph{trial vectors}, need to vanish.\nThis is equivalent to requiring a projection of $\\mathbf{r}$ onto the subspace spanned by the trial vectors to be zero.\nChoosing the complex oscillations as a basis for this subspace as well is a solid choice.\nBasically the residual is approximated by a trigonometric polynomial and a solution is required to only minimize this representation.\nThere are other factors supporting this choice: The residual is periodic as well, because of orthogonality many terms can cancel each other out, it allows us to employ the FFT for many operations, and the resulting system of equations is almost balanced.\n\n\\paragraph{System of Equations} This yields $N = 2m+1$ equations, one for each trial vector $\\mathbf{v}_k = \\exp\\left( i \\omega k t \\right)$ for $-m \\le k \\le m$\n\t\\begin{align}\n\t\t0 &= \\langle \\mathbf{r} , \\mathbf{v}_k \\rangle \\nonumber \\\\\n\t\t&= \\langle \\mathbf{f}(t,\\mathbf{y}), \\mathbf{v}_k \\rangle - \\left\\langle \\frac{d\\mathbf{y}}{dt}, \\mathbf{v}_k \\right\\rangle \\nonumber \\\\\n\t\t&= \\langle \\mathbf{f}(t,\\mathbf{y}), \\mathbf{v}_k \\rangle - i \\omega k \\mathbf{y}_k\\label{eq:innerprod} \\text.\n\t\\end{align}\nThe last step exploits that the complex exponential functions are orthonormal.\n%The last step exploits that there is always exactly one component in the candidate function' derivative which is not orthogonal to the trial vectors.\nFor these $N$ equations, there are $N+1$ variables: $N$ unique coefficients and $\\omega$.\nThis represents the situation, that at this point there is still one degree of freedom: Each phase shifted version of a solution is still a solution.\nWe thus introduce another generic equation called the \\emph{anchor} equation, which basically chooses one of these solutions.\nIn this case $\\langle \\mathbf{y}(0), (\\delta_{1i})_{i \\in \\N_n} \\rangle = 0$ is used:\nFor $t = 0$, the solution needs to intersect the hyperplane defined by being zero in the first component.\nThis can be formulated by requiring the corresponding coefficients to sum up to zero.\nThe anchor equation needs to be adapted to the system considered: If there are no intersections with this plane, another equation needs to be chosen.\n\n%motivation tedious, error prone\n\\paragraph{Discretization} When transferring these theoretical constructs to a practical setting, the main change is that solutions $\\mathbf{y}$ are not considered to be functions of continuous time, but vectors representing discrete time.\nConsequently, solution candidates are represented by linear combinations of discrete vectors as well\n\t\\[\n\t\t\\mathbf{\\mathbf{y}} = \\left( \\sum_{k=0}^{N-1} \\mathbf{y}_k \\exp\\left(i \\frac{2\\pi}{N} j k\\right) \\right)_{0 \\le j \\le N-1} \\text.\n\t\\]\nThis is no real limitation at that point, as solution candidates are band limited by construction.\nDefine the \\emph{DFT matrix} $\\mathbf F \\in \\R^{N \\times N}$, the coefficient vector $\\mathbf Y \\in \\left(\\C^n\\right)^N$ and a diagonal matrix $\\mathbf K \\in \\R^{N\\times N}$\n\t\\begin{align*}\n\t\t\\mathbf{F} &\\coloneqq N^{-1} \\left( \\exp\\left(-i \\frac{2\\pi}{N} j k \\right) \\right)_{0 \\le j,k \\le N-1} \\\\\n\t\t\\mathbf{Y} &\\coloneqq \\left(\\mathbf{y}_k\\right)_{0 \\le k \\le N-1} \\\\\n\t\t\\mathbf K &\\coloneqq \\diag\\left( [0:m]\\, ||\\, [-m:-1] \\right) \\text.\n\t\\end{align*}\n$\\mathbf Y$ is a vector of vectors, while somewhat unusual, this allows for more concise notation later on, than notation as a matrix.\nUsing these constructs allows us to reformulate\n\t\\[\n\t\t\t\\mathbf{y} = \\mathbf{F^{-1}} \\mathbf{Y} \\text.\n\t\\]\nConsidering only the equations from projections onto trial vectors, and considering $\\omega$ to be known the system of equations becomes %TODO define\n\t\\[\n\t\t\\mathbf{F} \\mathbf{f}\\{\\mathbf F^{-1} \\mathbf{Y}\\} - i \\omega \\mathbf K \\mathbf Y = 0\\text,\n\t\\]\n%where $\\mathbf{\\tilde f}(\\mathbf Y) = \\mathbf f\\{\\mathbf Y\\}$ simply row wise applies $\\mathbf{f}$, the function defining the system of differential equations (see \\autoref{eq:SDE}).\nwhere $\\mathbf{f}$ defines the system of differential equations (see \\autoref{eq:SDE}).\n\nCompare this to \\autoref{eq:innerprod}.\nEssentially, $\\mathbf{f}\\{\\mathbf F^{-1} \\mathbf{Y}\\}$ is a sampled version of $\\mathbf f(t,\\mathbf y)$.\nMultiplication by $\\mathbf F$ corresponds to calculating the inner products with the trial vectors, which are the rows of $\\mathbf F$.\nThe term $i \\omega \\mathbf K \\mathbf Y$ corresponds to \\autoref{eq:trigondiff}, focusing on the coefficients only.\n\nIntroducing these new constructs might at first glance appear unnecessarily complicated, because the system of equations was already known, and could be used in the state it was in.\nHowever, an implementation in the basic form would have required different treatment for each dynamic system, while in this form, it is only trivially dependent of $\\mathbf f$ and the degree of the trigonometric polynomial.\n%That is, the auxiliary vectors and matrices are trivially constructed, as is $\\mathbf{\\tilde f}$ from $\\mathbf f$.\nWhile knowing the system of equations is important, the core task of finding a good solution requires the Jacobian of the system.\nThe great advantage is, that from this form the system can be derived in a general way.\n\n\\paragraph{Deriving the System} %Let $D$ denote a differential operator.\nThe only variable in the system is $\\mathbf Y$, thus\n\t\\begin{align}\n\t\t& \\frac{d}{d\\mathbf Y} \\left( \\mathbf{F} \\mathbf{f}\\{\\mathbf{F}^{-1} \\mathbf{Y}\\} - i \\omega \\mathbf K \\mathbf Y \\right) \\nonumber \\\\\n\t\t=\\ & \\mathbf{F} \\frac{d \\mathbf{f}\\{\\mathbf Y\\}}{d\\mathbf Y} \\left( \\mathbf{F}^{-1} \\mathbf{Y} \\right) \\mathbf{F}^{-1} - i \\omega \\mathbf K (\\delta_{ij} \\mathbf I_n)_{i,j \\in \\N_N} \\label{eq:vecsys} \\text,\n\t\\end{align}\n%TODO careful: dY/dY != I\n% where $\\mathbf J_{\\mathbf{\\tilde f}} \\coloneqq \\frac{d \\mathbf{f}\\{\\mathbf Y\\}}{d\\mathbf Y}$ is the Jacobian of $\\mathbf{\\tilde f}$, a vector-by-vector derivative, which yields a matrix.\nwhere $\\frac{d \\mathbf{f} \\{ \\mathbf Y \\}}{d \\mathbf Y}$ is a vector-by-vector derivative, which yields a matrix.\nHowever, because both vector's elements are vectors themselves, the entries of the matrix are again vector-by-vector derivatives.\nThis results in an $N \\times N$ matrix of matrices with\n\t\\[\n\t\t\t\\left( \\frac{d \\mathbf{f}\\{\\mathbf Y\\}}{d\\mathbf Y} \\right)_i^j = \\frac{d}{d\\mathbf Y_j} \\mathbf f (\\mathbf Y_i) = \\delta_{ij} \\frac{d \\mathbf f(\\mathbf x)}{d \\mathbf x}(\\mathbf Y_i) \\text, %TODO fix x\n\t\\]\nwhere $\\frac{d \\mathbf f(\\mathbf x)}{d\\mathbf x}$ is the Jacobian of $\\mathbf f$.\n% The matrix $\\mathbf J_{\\mathbf{\\tilde f}}$ is diagonal, thus\n% \t\\[\n% \t\t\\mathbf J _ \\mathbf{\\tilde f} (\\mathbf Y) = \\diag\\left( \\left(\\mathbf J _ \\mathbf f \\left(\\mathbf Y_i\\right) \\right)_{i \\in \\N_N} \\right)\n% \t\\]\nAt no point different cells of $\\frac{d \\mathbf f(\\mathbf x)}{d\\mathbf x}$ interact.\nHence, the expression for the Jacobian of the whole system can be considered separately for each partial derivative in the Jacobian of $\\mathbf f$.\nFor $k,l \\in \\N_n$ define the $N \\times N$ diagonal matrix which extracts a single partial derivative\n\t\\[\n\t\t\\mathbf A_{kl}(\\mathbf Y) = \\diag\\left( \\frac{\\partial f_k}{\\partial x_l} \\left\\{\\mathbf Y_i\\right\\} \\right) \\text.\n\t\\]\nFor each $k$ and $l$ \\autoref{eq:vecsys} then becomes\n\t\\begin{equation}\n\t\t\\mathbf{F} \\mathbf A_{kl}(\\mathbf{F}^{-1} \\mathbf{Y}) \\mathbf{F}^{-1} - i \\delta_{kl} \\omega \\mathbf K\n\t\\label{eq:syssingle}\n\t\\end{equation}\nThis expression is again free of nested vectors.\n\n%Because of the diagonal structure of the matrix, the term $\\frac{d\\mathbf{\\tilde f}}{d\\mathbf x}(\\mathbf{F}^{-1} \\mathbf{Y}) \\mathbf{F}^{-1}$ is essentially a multiplication of each row of $\\mathbf F^{-1}$ with a constant.\nBecause $\\mathbf A_{kl}(\\mathbf{F}^{-1} \\mathbf{Y})$ is diagonal, $\\mathbf A_{kl}(\\mathbf{F}^{-1} \\mathbf{Y}) \\mathbf{F}^{-1}$ is the rows of $\\mathbf F^{-1}$ each multiplied by a scalar.\nThis can also be seen as an element wise multiplication of the columns $\\mathbf c_k$ of $\\mathbf F^{-1}$ by a column vector $\\mathbf d$ defined by the diagonal of $\\mathbf A_{kl}(\\mathbf{F}^{-1} \\mathbf{Y})$\n\t\\begin{align*}\n\t\t&\\mathbf c_k \\coloneqq \\left(\\exp\\left(i\\frac{2\\pi}{N} j k\\right)\\right)_{0 \\le j \\le N-1}\\\\\n\t\t&\\mathbf d \\coloneqq \\frac{\\partial f_k}{\\partial x_l} \\{\\mathbf Y\\} \\text.\n\t\\end{align*}\nA column of $\\mathbf{F} \\mathbf A_{kl}(\\mathbf{F}^{-1} \\mathbf{Y}) \\mathbf{F}^{-1}$ is then the DFT of the product of two signals $\\mathcal F(\\mathbf d \\cdot \\mathbf c_k)$.\nBecause of the structure of $\\mathbf c_k$, this corresponds to a simple periodic shift of the Fourier coefficients of the discrete signal $\\mathbf d$ by $k$ steps.\nUsing this for every column of the complete term yields\n\t\\[\n\t\t\t\\mathbf{F} \\mathbf A_{kl}(\\mathbf{F}^{-1} \\mathbf{Y}) \\mathbf{F}^{-1} = \\left( \\mathbf \\F(\\mathbf d)_{((i-j))_N} \\right)_{0 \\le i,j \\le N} \\text,\n\t\\]\nthat is, a simple circulant matrix.\n\nRebuilding the complete derivative from these matrices is a matter of subtracting the remaining diagonal term and merging the results.\n% The general form of \\autoref{eq:syssingle} is $\\mathbf G = \\mathbf M \\cdot D \\mathbf Y$.\n%The differential operator $D$ has been left undefined and \\autoref{eq:syssingle} most of the term is independent of the choice of $D$.\n%This is important, because in an optimization setting real and imaginary parts of the Fourier coefficients need to be treated separately.\n% That is, derivatives of $\\frac{d \\Re \\mathbf G}{d\\Re \\mathbf Y}$, $\\frac{d \\Im \\mathbf G}{d\\Re \\mathbf Y}$, $\\frac{d \\Re \\mathbf G}{d\\Im \\mathbf Y}$, $\\frac{d \\Im \\mathbf G}{d\\Im \\mathbf Y}$ will be required.\nSince a central part of this project requires numerical optimization of the coefficients, their real and imaginary parts need to be treated separately.\nThis especially means separately deriving the real and imaginary parts of system of equations by their real and imaginary parts.\nHowever, all these cases can be reduced to $\\frac{d}{d \\mathbf Y}$\n\\begin{align*}\n\t\\frac{d \\Re}{d\\Re \\mathbf Y} = \\Re \\frac{d}{d \\mathbf Y} &&& \\frac{d \\Re}{d\\Im \\mathbf Y} = -\\Im \\frac{d}{d \\mathbf Y}\\\\\n\t\\frac{d \\Im}{d\\Re \\mathbf Y} = \\Im \\frac{d}{d \\mathbf Y} &&& \\frac{d \\Im}{d\\Im \\mathbf Y} = \\Re \\frac{d}{d \\mathbf Y} \\text.\n\\end{align*}\n", "meta": {"hexsha": "b5dd25fea28056bef051e52788b67d370b262244", "size": 13037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doctheory/galerkin.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/galerkin.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/galerkin.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": 83.0382165605, "max_line_length": 254, "alphanum_fraction": 0.7126639564, "num_tokens": 4142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.7931059560743423, "lm_q1q2_score": 0.6945918818996821}}
{"text": "\\documentclass[../main.tex]{subfiles}\n \\begin{document}\n \\chapter{Positive Borel Measure}\n \\begin{exercise}\n   Let $ \\{f_n\\} $ be a sequence of real non-negative functions on $ \\mathbb R^{1} $, and consider the following\n   four statements:\n   \\begin{enumerate}\n     \\item If $ f_1 $, $ f_2 $ are upper semicontinuous so is $ f_1 + f_2 $.\n     \\item If $ f_1, f_2 $ are lower semicontinuous, so is $ f_1 + f_2 $.\n     \\item If each $ f_n $ is upper semicontinuous, so is $ \\sum^{\\infty} f_n $.\n     \\item If each $ f_n $ is lower semicontinuous, so is $ \\sum^{\\infty} f_n $.\n   \\end{enumerate}\n   \\paragraph{Solution. }  Observe\n   \\begin{align*}\n   \\{f_1 + f_2 < a\\} = \\bigcup_{x \\in \\mathbb R} \\{f_1 < x\\} \\cap \\{f_2 < a - x\\}\n   \\end{align*}\n   is open. To see the left is included in the right, for any $ f_1(y) + f_2(y) < a $, take $ f_1(y) < x < a - f_2(y) $ and the\n   inclusion holds. Therefore 1 is verified. Similar argument goes with 2 if the above $ < $ are replaced with $ > $.\n\n   Notice 4 holds, fix any $ x $ such that $ \\sum f(x) > a $. Since $ f_n $'s are non-negative, there is $ N $ such that\n   $ \\sum^{N} f_n(x) > a $. Therefore there exists $\\delta$, $ \\sum^N f_n(y) > a $ for any $ y \\in B_\\delta(x) $ since\n   finite sums of lower semicontinuous functions are lower semicontinuous. The proof is complete by observing\n   \\begin{align*}\n   \\sum f_n(y) \\ge \\sum^N f_n(y) > a\n   \\end{align*}\n\n   To give 3 a counterexample, consider $ \\sum f_n = \\sum \\mathcal X_{[-n, -1/n] \\cup [1/n, n]} $.\n   Obviously, every point but $ 0 $ is greater than or equal to $ 1 $. Hence\n   \\begin{align*}\n   \\{\\sum f_n < 1 \\} = \\{0\\}\n   \\end{align*}\n   is closed.\n \\end{exercise}\n\n \\begin{exercise}\n   Let $ f $ be an arbitrary complex function on $ \\mathbb R^1 $, and define\n   \\begin{align*}\n   \\phi(x, \\delta) = \\sup \\{|f(s) - f(t)|: s, t \\in (x - \\delta, x + \\delta)\\}, \\\\\n   \\phi(x) = \\inf \\{\\phi(x, \\delta): \\delta > 0\\}.\n   \\end{align*}\n   Prove that $ \\phi $ is upper semicontinuous, that $ f $ is continuous at a point $ x $ iff $ \\phi(x) = 0 $, and\n   hence that the set of points of continuity of an arbitrary complex function is a $ G_{\\delta} $.\n\n   Formulate and prove an analogous statement for general topological spaces in place of $ \\R^1 $.\n\n   \\paragraph{Solution. }\n   Only give solution in the general case. Redefine\n   \\begin{align*}\n   \\phi(x) = \\inf_{B \\ni x} \\mathrm{diam} f(B)\n   \\end{align*}\n   where the diameter is defined as $ \\mathrm{diam} A = \\sup_{x, y \\in A} |x - y| $. Take any $ x \\in \\{\\phi(x) < a\\}$,\n   there is $ B \\ni x $, $ \\mathrm{diam} f(B) < a $. Take any $ y \\in B $, then $ \\phi(y) \\le \\mathrm{diam}f(B) < a $.\n   This says $  \\{\\phi(x) < a\\} $ is open and $ \\phi $ is upper semicontinuous.\n\n   The relation between $ \\phi $ and continuity of $ f $ is trivial. Since\n   \\begin{align*}\n   \\{\\phi = 0\\} = \\bigcap_{q\\in \\mathbb Q^+} \\{\\phi < q\\}\n   \\end{align*}\n   the set is a $ G_\\delta $.\n \\end{exercise}\n\n \\begin{exercise}\n   Let $ X $ be a metric space, with metric $ \\rho $. For any nonempty $ E \\subset X $, define\n   \\begin{align*}\n   \\rho_E(x) = \\inf_{y \\in E} \\rho(x, y)\n   \\end{align*}\n   Show that $ \\rho_E $ is uniformly continuous function on $ X $. If $ A $ and $ B $ are disjoint nonempty closed\n   subsets of $ X $, examine the relevance of the function\n   \\begin{align*}\n   f(x) = \\frac{\\rho_A(x)}{\\rho_A(x) + \\rho_B(x)}\n   \\end{align*}\n   to Urysohn's lemma.\n\n   \\paragraph{Solution. }\n   Notice\n   \\begin{align*}\n   \\rho(a, x) + \\rho(a, b) \\ge \\rho(x, b).\n   \\end{align*}\n   Taking infimum on $ E $ on both sides gives\n   \\begin{align*}\n   \\rho_E(b) - \\rho_E(a) \\le \\rho(a, b)\n   \\end{align*}\n   By symmetry,\n   \\begin{align*}\n   |\\rho_E(b) - \\rho_E(a)| \\le \\rho(a, b)\n   \\end{align*}\n   showing the uniform continuity. Notice $ 0 \\le f \\le 1 $ and $ f = 1 $ on $ B $. Its support lies in $ A^{c} $.\n   Therefore if $ B $ is compact, $ B \\prec f \\prec A^c $.\n\n \\end{exercise}\n\n \\begin{exercise}\n   Examine the proof of Riesz theorem and prove the following two statments:\n   \\begin{enumerate}\n     \\item If $ E_1 \\subset V_1 $ and $ E_2 \\subset V_2 $, where $ V_1 $ and $ V_2 $ are disjoint open sets, then $ \\mu(E_1 \\cup E_2) = \\mu(E_1) + \\mu(E_2) $, even if $ E_1, E_2 $ are not in $ \\mathcal{M} $.\n     \\item If $ E \\in \\mathcal{M}_F $, then $ E = N \\cup K_1 \\cup K_2 \\dots $, where $ \\{K_i\\} $ is a disjoint countable collection of compact sets and $ \\mu(N) = 0 $.\n   \\end{enumerate}\n\n   \\paragraph{Solution. }\n   \\begin{enumerate}\n     \\item Take any open set $ U $ that covers $ E_1 \\cup E_2 $. Observe\n     \\begin{align*}\n       \\mu(U) \\ge \\mu(U \\cap V_1) + \\mu(U \\cap V_2) \\ge \\mu(E_1) + \\mu(E_2).\n     \\end{align*}\n     Taking infimum on both sides together with the subadditivity of $ \\mu $ gives the result.\n\n     \\item Since $ E \\in \\mathcal{M}_F, \\mu(E) < \\infty $. Take $ K_1 $\n     \\begin{align*}\n       \\mu(E) < \\mu(K_1) + 1.\n     \\end{align*}\n     Having chosen $ K_1, ..., K_n $, denote $ G = E - \\cup ^{n-1} K_i \\in \\mathcal{M}_F$. Pick $ K_n $ such that\n     \\begin{align*}\n        \\mu(G) < \\mu(K_n) + 1/n .\n     \\end{align*}\n     Obviously $ \\mu(E - \\bigcup K_n) = 0 $ and this completes the proof.\n\n\n   \\end{enumerate}\n \\end{exercise}\n\n In Exercise 5 to 8, $ m $ stands for Lebesgue measure on $ \\mathbb{R}^1 $.\n\n \\begin{exercise}\n   Let $ E $ be Cantor's familiar ``middle thirds'' set. Show that $ m(E) = 0 $, even through $ E $ and $ \\R ^{1}  $ have the same cardinality.\n   \\paragraph{Solution. }\n   Denote $ R $ as the set removed from $ [0, 1] $ in construction of the Cantor set. Notice it is comprised of the union of $ 2 ^{n-1} $ open intervals of length $ 3 ^{-n} $ where $ n $ ranges in $ \\mathbb{N} $. Therefore\n   \\begin{align*}\n     \\mu(R) = \\sum_{n=1}^{\\infty} \\frac {2 ^{n-1}}{3^n} = 1\n   \\end{align*}\n   and $ \\mu(E) = \\mu(I - R) = 0 $.\n\n   To see $ E $ has the same cardinality as $ \\R $. Notice each element in $ E $ is a decimal of base 3 that has exactly one 1 at the end or no 1 at all. Therefore there is a surjection from $ \\R $ to $ E $, and one from $ E $ to decimals of base 2. This completes the proof.\n\n \\end{exercise}\n\n \\begin{exercise}\n   Construct a totally disconnected compact set $ K \\subset \\R^1 $ such that $ m(K) > 0 $. If $ v $ is lower semicontinuous and $ v \\le \\mathcal{X}_K $, show that actually $ v \\le 0 $. Hence $ \\mathcal{X}_K $ cannot be approximated from below by lower semicontinuous functions, in the sense of the Vitali-Carath\\'eodory theorem.\n   \\paragraph{Solution. }\n   Construct $ K $ similarly as the Cantor set in the previous exercise only we remove the middle fourths in place of thirds. Let $ R $ be the union of removed intervals. $ K $ is compact since each removal left a closed and bounded thus compact subset of $ [0, 1] $ and $ K $ is the intersection of all these compact sets. Similarly as above,\n   \\begin{align*}\n     \\mu(R) = \\sum_{n-1}^{\\infty} \\frac {2 ^{n-1} }{2 ^{2n} } = \\sum \\frac {1}{2 ^{n+1} } = \\frac {1}{2} .\n   \\end{align*}\n   Therefore $ \\mu(K) = 1/2 $. Notice $ \\{v > 0\\} $ is open by definition. But it cannot be a subset of $ K $ except for the empty set since $ K $ is totally disconnected.\n\n \\end{exercise}\n\n \\begin{exercise}\n   If $ 0 < \\epsilon < 1 $, construct an open set $ E \\subset [0, 1] $ which is dense in $ [0, 1] $, such that $ m(E) = \\epsilon $. (To say that $ A $ is dense in $ B $ means that the closure of $ A $ contains $ B $.)\n\n   \\paragraph{Solution. }\n   The construction is similar as before. Notice if one takes out one middle $ x $-th every time with $ x > 2 $, the removed set $ R $ has measure\n   \\begin{align*}\n     m(R) = \\sum_{n=1}^{\\infty} \\frac {2 ^{n-1} }{x^n}  = \\frac {1}{x - 2}\n   \\end{align*}\n   Take $ x = 1/\\epsilon + 2 $ and $ m(R) = \\epsilon $. $ R $ is open since its complement in $ [0, 1] $ is compact (as proven before), therefore closed. To see $ R $ is dense, notice every removal divides each remaining interval into its halves. Therefore to each point $ x $ in $ [0, 1] $, there must be a point that has been removed after the $ n $-th removal and lies in $ B _{1/2^n} (x) $.\n\n \\end{exercise}\n\n \\begin{exercise}\n   Construct a Borel set $ E \\subset \\mathbb{R}^1 $ such that\n   \\begin{align*}\n     0 < m(E \\cap I) < m(I)\n   \\end{align*}\n   for every nonempty segment $ I $. Is it possible to have $ m(E) < \\infty $ for such a set?\n   \\paragraph{Solution. }\n   Take $ E = \\mathbb{Q} $. Obviously $ 0 = m(E \\cap I) $. Since $ I $ is an nonempty segment, there is an open interval in it, i.e., $ m(I) > 0 $. Notice $ \\mathbb{Q} $ is Borel because it is the countable union of singaltons, and singaltons are Borel.\n \\end{exercise}\n\n \\begin{exercise}\n   Construct a sequence of continuous function $ f_n $ on $ [0, 1] $ such that $ 0 \\le f_n \\le 1 $, such that\n   \\begin{align*}\n     \\lim _{n \\to \\infty} \\int_0^1 f_n(x) dx = 0\n   \\end{align*}\n   but such that the sequence $ \\{f_n(x)\\} $ converges for no $ x \\in [0, 1] $.\n\n   \\paragraph{Solution. }\n   Define\n   \\begin{align*}\n     K_1 &= [0, 1], \\\\\n     K_2 &= [0, 1/2], K_3 = [1/2, 1], \\\\\n     K_4 &= [0, 1/4], K_5 = [1/4, 1/2], K_6 = [1/2, 3/4], K_7 = [3/4, 1]\n   \\end{align*}\n   Obviously $ m(K_n) \\to 0 $. To each $ K_n = [a, b] $, pick $ V_n = (a - 1/2n, b + 1/2n) $ and $ f_n $ that $ K_n \\prec f_n \\prec V_n $. Finally,\n   \\begin{align*}\n     \\int f_n dm \\le m(V_n) = m(K_n) + 1/n \\to 0\n   \\end{align*}\n   But $ f_n $ does not converge for any $ x \\in [0, 1] $, since $ f_n(x) = 1 $ and $ f_n(x) = 0 $ both infinitely often.\n\n   Notice the construction of $ f_n $ need not follow that of Urysohn's. Define\n   \\begin{align*}\n     l((x_1, y_1), (x_2, y_2))(x) = \\frac {y_1 - y_2}{x_1 - x_2} (x - x_1) + y_1.\n   \\end{align*}\n   If $ V_n = (a, b) $, $ K_n = [c, d] $, and $ a < c < d < b $. Pick $ s, t $ that, $ a < s < c < d < t < b $. Take\n   \\begin{align*}\n     f_n = \\begin{cases}\n       0, x \\le s\\\\\n       l((s, 0), (c, 1)), s \\le x \\le c\\\\\n       1, c \\le x \\le d\\\\\n       l((d, 1), (t, 0)), d \\le x \\le t\\\\\n       0, x \\ge t\n   \\end{cases}\n   \\end{align*}\n\n \\end{exercise}\n \\end{document}\n", "meta": {"hexsha": "a740c50f7de91c9aa805df3f4b99fd5311dd52dc", "size": 10072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_2/chapter_2.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_2/chapter_2.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_2/chapter_2.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": 48.8932038835, "max_line_length": 394, "alphanum_fraction": 0.589853058, "num_tokens": 3686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.6945918776168818}}
{"text": "\\section{Second Order Linear Equations - Variation of Parameters}{}{}\\label{sec:2nd order differential equations two} \nThe method of the last section works only when the function $f(t)$ in\n$\\ds ay''+by'+cy=f(t)$ has a particularly nice form, namely,\nwhen the derivatives of $f$ look much like $f$ itself. In other cases\nwe can try variation of parameters as we did in the first order case.\n\nSince as before\n$a\\not=0$, we can always divide by $a$ to make the coefficient of\n$\\ds y''$ equal to 1. Thus, to simplify the discussion, we assume $a=1$. \nWe know that the differential equation $\\ds y''+by'+cy=0$\nhas a general solution $\\ds y=Ay_1+By_2$. As before, we guess a\nparticular solution to $\\ds y''+by'+cy=f(t)$; this time we use\nthe guess $\\ds y=u(t)y_1+v(t)y_2$. Compute the derivatives:\n\\begin{eqnarray*}\ny'&=&u'y_1+uy'_1+v'y_2+vy'_2\\cr\ny''&=&u''y_1+u'y'_1+u'y'_1+uy''_1+v''y_2+v'y'_2+v'y'_2+vy''_2.\n\\end{eqnarray*}\nNow substituting:\n\\begin{eqnarray*}\ny''+by'+cy&=&\nu''y_1+u'y'_1+u'y'_1+uy''_1+v''y_2+v'y'_2+v'y'_2+vy''_2\\cr\n&&\\qquad + bu'y_1+buy'_1+bv'y_2+bvy'_2+cuy_1+cvy_2\\cr\n&=&(uy''_1+buy'_1+cuy_1)+(vy''_2+bvy'_2+cvy_2)\\cr\n&&\\qquad + b(u'y_1+v'y_2) + (u''y_1+u'y'_1+v''y_2+v'y'_2)+\n(u'y'_1+v'y'_2)\\cr\n&=&0+0+ b(u'y_1+v'y_2) + (u''y_1+u'y'_1+v''y_2+v'y'_2)+\n(u'y'_1+v'y'_2).\n\\end{eqnarray*}\nThe first two terms in parentheses are zero because $y_1$ and $y_2$\nare solutions to the associated homogeneous equation. Now we engage in\nsome wishful thinking. If $\\ds u'y_1+v'y_2=0$, then we also have\n$\\ds u''y_1+u'y'_1+v''y_2+v'y'_2=0$ by taking derivatives of both sides. This reduces the\nentire expression to $\\ds u'y'_1+v'y'_2=0$. We want this\nto be $f(t)$, that is, we need \n$\\ds u'y'_1+v'y'_2=f(t)$.\nSo we would very much like these equations to be true:\n\\begin{eqnarray*}\nu'y_1+v'y_2&=&0\\cr\nu'y'_1+v'y'_2&=&f(t).\n\\end{eqnarray*}\nThis is a system of two equations in the two unknowns $\\ds u'$ and\n$\\ds v'$, so we can solve as usual to get $\\ds u'=g(t)$ and\n$\\ds v'=h(t)$. Then we can find $u$ and $v$ by computing\nantiderivatives. This is of course the sticking point in the whole\nplan, since the antiderivatives may be impossible to\nfind. Nevertheless, this sometimes works out and is worth a try.\n\n\\begin{example}{Variation of Parameters}{Variation of Parameters}\\label{Variation of Parameters}\nConsider the equation $\\ds y''-5y'+6y=\\sin t$. \nSolve using variation of parameters. \n\\end{example}\n\n\\begin{solution}\nThe solution to the homogeneous equation is\n$\\ds Ae^{2t}+Be^{3t}$, so the \nsimultaneous equations to be solved are\n\\begin{eqnarray*}\nu'e^{2t}+v'e^{3t}&=&0\\cr\n2u'e^{2t}+3v'e^{3t}&=&\\sin t.\n\\end{eqnarray*}\nIf we multiply the first equation by 2 and subtract it from the second\nequation we get\n\\begin{eqnarray*}\nv'e^{3t}&=&\\sin t\\cr\nv'&=&e^{-3t}\\sin t\\cr\nv&=&-{1\\over 10}(3\\sin t+\\cos t)e^{-3t},\n\\end{eqnarray*}\nusing integration by parts. Then from the first equation:\n\\begin{eqnarray*}\nu'&=&-e^{-2t}v'e^{3t}=-e^{-2t}e^{-3t}\\sin(t)e^{3t}=-e^{-2t}\\sin\nt\\cr\nu&=&{1\\over 5}(2\\sin t+\\cos t)e^{-2t}.\n\\end{eqnarray*}\nNow the particular solution we seek is\n\\begin{eqnarray*}\nue^{2t}+ve^{3t}&=&{1\\over 5}(2\\sin t+\\cos t)e^{-2t}e^{2t}\n-{1\\over 10}(3\\sin t+\\cos t)e^{-3t}e^{3t}\\cr\n&=&{1\\over 5}(2\\sin t+\\cos t)-{1\\over 10}(3\\sin t+\\cos t)\\cr\n&=&{1\\over 10}(\\sin t+\\cos t),\n\\end{eqnarray*}\nand the solution to the differential equation is\n$\\ds Ae^{2t}+Be^{3t}+(\\sin t+\\cos t)/10$. For comparison (and\npractice) you might want to solve this using the method of\nundetermined coefficients---both techniques should yield the same result.\n\\end{solution}\n\n\\begin{example}{Variation of Parameters}{Variation of Parameters 2}\\label{Variation of Parameters 2}\n The differential equation $\\ds y''-5y'+6y=e^t\\sin t$\ncan be solved using the method of undetermined coefficients, though we\nhave not seen any examples of such a solution. Again, we will solve it\nby variation of parameters.\n\\end{example}\n\n\\begin{solution}\nThe equations to be solved are \n\\begin{eqnarray*}\nu'e^{2t}+v'e^{3t}&=&0\\cr\n2u'e^{2t}+3v'e^{3t}&=&e^t\\sin t.\n\\end{eqnarray*}\nIf we multiply the first equation by 2 and subtract it from the second\nequation we get\n\\begin{eqnarray*}\nv'e^{3t}&=&e^t\\sin t\\cr\nv'&=&e^{-3t}e^t\\sin t=e^{-2t}\\sin t\\cr\nv&=&-{1\\over 5}(2\\sin t+\\cos t)e^{-2t}.\n\\end{eqnarray*}\nThen substituting we get\n\\begin{eqnarray*}\nu'&=&-e^{-2t}v'e^{3t}=-e^{-2t}e^{-2t}\\sin(t)e^{3t}=-e^{-t}\\sin\nt\\cr\nu&=&{1\\over 2}(\\sin t+\\cos t)e^{-t}.\n\\end{eqnarray*}\nThe particular solution is\n\\begin{eqnarray*}\nue^{2t}+ve^{3t}&=&{1\\over 2}(\\sin t+\\cos t)e^{-t}e^{2t}\n-{1\\over 5}(2\\sin t+\\cos t)e^{-2t}e^{3t}\\cr\n&=&{1\\over 2}(\\sin t+\\cos t)e^t-{1\\over 5}(2\\sin t+\\cos t)e^t\\cr\n&=&{1\\over 10}(\\sin t+3\\cos t)e^t,\n\\end{eqnarray*}\nand the solution to the differential equation is\n$\\ds Ae^{2t}+Be^{3t}+e^t(\\sin t+3\\cos t)/10$.\n\\end{solution}\n\n\\begin{example}{Solving a DE}{Solving a DE}\\label{Solving a DE}\n The differential equation $\\ds y'' -2y'+y=e^t/t^2$ is\nnot of the form amenable to the method of undetermined\ncoefficients. Solve it using variation of parameters.\n\\end{example}\n\n\\begin{solution}\nThe solution to the homogeneous equation is\n$\\ds Ae^t+Bte^t$ and so the simultaneous equations are\n\\begin{eqnarray*}\nu'e^{t}+v'te^{t}&=&0\\cr\nu'e^{t}+v'te^{t}+v'e^t&=&{e^t\\over t^2}.\n\\end{eqnarray*}\nSubtracting the equations gives\n\\begin{eqnarray*}\nv'e^{t}&=&{e^t\\over t^2}\\cr\nv'&=&{1\\over t^2}\\cr\nv&=&-{1\\over t}.\n\\end{eqnarray*}\nThen substituting we get\n\\begin{eqnarray*}\nu'e^t&=&-v'te^t=-{1\\over t^2}te^t\\cr\nu'&=&-{1\\over t}\\cr\nu&=&-\\ln t.\n\\end{eqnarray*}\nThe solution is $\\ds Ae^t+Bte^t-e^t\\ln t-e^t$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:2nd order differential equations two}}\n\n\\begin{enumialphparenastyle}\n\nFind the general solution to the differential equation using variation\nof parameters.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+y=\\tan x$\n\\begin{sol}\n $\\ds A\\sin(t)+B\\cos(t)-\\hfill\\break\\cos t\\ln|\\sec t+\\tan t|$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+y=e^{2t}$\n\\begin{sol}\n $\\ds A\\sin(t)+B\\cos(t)+{1\\over5}e^{2t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+4y=\\sec x$\n\\begin{sol}\n $\\ds A\\sin(2t)+B\\cos(2t)+\\cos t-\\sin t\\cos t\\ln|\\sec t+\\tan t|$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+4y=\\tan x$\n\\begin{sol}\n $\\ds A\\sin(2t)+B\\cos(2t)+{1\\over2}\\sin(2t)\\sin^2(t)+\n{1\\over2}\\sin(2t)\\ln|\\cos t|-{t\\over2}\\cos(2t)+{1\\over4}\\sin(2t)\\cos(2t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+y'-6y=t^2e^{2t}$\n\\begin{sol}\n $\\ds Ae^{2t}+Be^{-3t}+{t^3\\over15}e^{2t}-\\left({t^2\\over5}\n-{2t\\over25}+{2\\over125}\\right){e^{2t}\\over5}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-2y'+2y=e^{t}\\tan(t)$\n\\begin{sol}\n $\\ds Ae^{t}\\sin t+Be^{t}\\cos t-e^t\\cos t\\ln|\\sec t+\\tan t|$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-2y'+2y=\\sin(t)\\cos(t)$ (This is rather messy\nwhen done by variation of parameters; compare to undetermined coefficients.)\n\\begin{sol}\n $\\ds Ae^{t}\\sin t+Be^{t}\\cos t-\n{1\\over10}\\cos t(\\cos^3 t+3\\sin^3 t-2\\cos t-\\sin t)+\n{1\\over10}\\sin t(\\sin^3 t-3\\cos^3 t-2\\sin t+\\cos t)=\n{1\\over10}\\cos(2t)-{1\\over20}\\sin(2t)$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "fc4007d769b13ec39fa3f87f41e1cc58204e40f6", "size": 7177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-7-second-order-linear-variation-parameters.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-7-second-order-linear-variation-parameters.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-7-second-order-linear-variation-parameters.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.2043478261, "max_line_length": 118, "alphanum_fraction": 0.6494356974, "num_tokens": 2910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8757869884059267, "lm_q1q2_score": 0.6945918639087509}}
{"text": "% !TEX root = lectures.tex\n%!TEX encoding = UTF-8 Unicode\n%\\input{lectureheader.tex}\n\n\\section{Lagrangians and the Calculus of Variations}\n\\label{sec:lagrangians}\n\\bigskip\n\n\\subsection{Calculus of Variations and the Euler-Lagrange Equation}\n\nThe usual minimization problem one faces involves taking a function\n$J(y)$, then finding the single value $y$ for which $J$ is either a\nmaximum or minimum. In multivariate calculus one also learns to solve\nproblems where you minimize for multiple variables, $J(y_1,y_2,\\cdots\ny_n)$, and finding the point $(y_1\\cdots y_n)$ in $n-$dimensional\nspace that maximizes or minimizes the function. Here, we consider what\nseems to be a much more ambitious problem. Imagine you have a function\n$J(y(x),y'(x);x)$, and you wish to find the extrema for an infinite\nnumber of values of $y$, i.e. $y$ at each point $x$. The function $J$\nwill not only depend on $y$ at each point $x$, but also on the slope\nat each point, plus an additional dependence on $x$. Note we are NOT\nfinding an optimum value of $x$, we are finding the set of optimum\nvalues of $y$ at each point $x$, or equivalently, finding the function\n$y(x)$.\n\nOne treats the function $y(x)$ as being unknown while minimizing\n\\[\nJ=\\int_{x_1}^{x_2}dx~f\\{y(x),y'(x);x\\}.\n\\]\nThus, we are minimizing $J$ with respect to an infinite number of\nvalues of $y(x_i)$ at points $x_i$. As an additional criteria, we will\nassume that $y(x_1)$ and $y(x_2)$ are fixed, and that that we will\nonly consider variations of $y$ between the boundaries. The dependence\non the derivative, $y'=dy/dx$, is crucial because otherwise the\nsolution would involve simply finding the one value of $y$ that\nminimized $f$, and $y(x)$ would equal a constant if there were no\nexplicit $x$ dependence. Furthermore, $y$ wouldn't need to be\ncontinuous at the boundary.\n\nThe Euler equation is a differential equation for $y(x)$, that when\nsolved, provides the required solution. For an extrema\n\\begin{eqnarray}\n\\delta J&=&\\int_{x_1}^{x_2}dx~\\left\\{ \\frac{\\partial f}{\\partial\n  y}\\delta y(x)+\\frac{\\partial f}{\\partial y'}\\delta y'(x)\\right\\}=0.\n\\end{eqnarray}\nFor ANY small $\\delta y(x)$ at any point $x$, the change should be\nzero if one is at an optimum function $y(x)$. Integrating the second\nterm by parts,\n\\begin{eqnarray}\n\\delta J&=&\\int_{x_1}^{x_2}dx~\\left\\{ \\frac{\\partial f}{\\partial\n  y}-\\frac{d}{dx}\\left(\\frac{\\partial f}{\\partial\n  y'}\\right)\\right\\}\\delta y(x)\\\\ \\nonumber &&+\\left.\\frac{\\partial\n  f}{\\partial y'}\\delta y\\right|_{x_2}-\\left.\\frac{\\partial\n  f}{\\partial y'}\\delta y\\right|_{x_1}\\\\ \\nonumber &=&0.\n\\end{eqnarray}\nBecause $y$ is not allowed to vary at the endpoints, $\\delta\ny(x_1)=\\delta y(x_2)=0$, so the middle line can be ignored.  Also,\nthis relation must hold for ANY $\\delta y$, so one can write the Euler\nequations (or sometimes called the Euler Lagrange equations)\n\\begin{equation}\n\\label{eq:el}\n\\frac{\\partial f}{\\partial y}=\\frac{d}{dx}\\frac{\\partial f}{\\partial\n  y'}.\n\\end{equation}\nThis will yield a differential equations for $y$. Combined with the\nboundary conditions,\n\\begin{equation}\ny(x_1)=y_1, ~~~y(x_2)=y_2,\n\\end{equation}\none can now solve the differential equations for $y$. Because $f$ is\nonly a function of $f'$, not $f''$ or $f'''$, the $d/dx$ in Euler\nLagrange equation can lead to terms involving $f''$, but not\n$f'''$. Thus, the equation will be a second-order differential\nequation (not a linear equation usually), and the two boundary\nconditions are sufficient to determine the entire equation.\n\n\\example\\label{ex:brachiostone}\\noindent Consider a particle\nconstrained to move along a path (like a bead moving without friction\non a wire) and you need to design a path from $x=y=0$ to some final\npoint $x_f,y_f$. Assume there is a constant force in the $x$\ndirection, $F_x=mg$. Design the path so that the time the bead travels\nis a minimum.\n\n{\\bf Solution:} The net time is\n\\[\nT=\\int \\frac{d\\ell}{v}=\\int_0^{x_f}\ndx~\\frac{\\sqrt{1+y'^2}}{\\sqrt{2gx}}={\\rm minimum}.\n\\]\nHere we made use of the fact that $d\\ell=\\sqrt{dx^2+dy^2}$ and that\nthe velocity is determined by $KE=mv^2/2=mgx$. The Euler equations can\nbe applied if you first define the function as\n\\begin{eqnarray*}\nf(y,y';x)&=&\\frac{\\sqrt{1+y'^2}}{\\sqrt{x}}.\n\\end{eqnarray*}\nThe equations are then\n\\begin{eqnarray*}\n\\frac{d}{dx}\\frac{\\partial f}{\\partial y'}&=&0.\n\\end{eqnarray*}\nThe simplification ensued from $f$ not having any dependence on\n$y$. This yields the differential equation\n\\begin{eqnarray}\n\\frac{y'}{x^{1/2}(1+y'^2)^{1/2}}&=&(2a)^{-1/2},\n\\end{eqnarray}\nbecause $\\partial f/\\partial y'$ must be a constant, which with some\nforesight we label $(2a)^{-1/2}$. One can now solve for $y'$,\n\\begin{eqnarray*}\n(y')^2&=&2ax(1+y'^2)\\\\ \\nonumber\n  y'&=&\\sqrt{\\frac{x}{2a-x}},\\\\ \\nonumber y(x)&=&\\int_0^x\n  dx'~\\frac{\\sqrt{x'}dx'}{\\sqrt{2a-x'}}=\\int_0^x\n  dx'~\\frac{x'dx'}{\\sqrt{2ax'-x'^2}}\\\\ \\nonumber\n  &=&\\frac{1}{2}\\int_0^x\\frac{(2x'-2a)dx'}{(2ax'-x'^2)^{1/2}}+a\\int_0^x\\frac{dx'}{\\sqrt{2ax'-x'^2}}\\\\ \\nonumber\n  &=&\\frac{-1}{2}\\int_0^{2ax-x^2}\\frac{du}{\\sqrt{u}}+a\\int_0^x\\frac{dx'}{\\sqrt{a^2-(x'-a)^2}}\\\\ &=&-\\sqrt{2ax-x^2}+a\\cos^{-1}(1-x/a).\n\\end{eqnarray*}\nThis turns out to be the equation for a {\\it cycloid} or a {\\it\n  brachiostone}. If you rolled a wheel of radius $a$ down the $y$ axis\nand followed a point on the rim, it would trace out a cycloid. Here,\nthe constant $a$ must be chosen to match the boundary condition,\n$y_2=y(x_2)$. You can see the textbook for more details, plus you get\na chance to work with cycloids in the exercises at the end of this\nchapter.\n\n\\exampleend\n\n\\subsection{Auxiliary Constraints}\n\nSometimes an auxiliary constraint is added to the problem (beyond\nfixing the end poits $y_1$ and $y_2$). Just ahead, we will work on the\nexample of a hanging chain. The shape of the curve minimizes the\npotential energy, under the constraint of a fixed length of\nchain. Before presenting such an example we first review the method of\nLagrange multipliers as a method for finding minima or maxima under\nconstraints.\n\nImagine a function $f(x_1,x_2\\cdots x_n)$ for which you wish to find\nthe minima. Additionally, you are given a constraint\n\\begin{eqnarray}\nC(x_1\\cdots x_n)=0\n\\end{eqnarray}\nThe usual condition for a a minimum is\n\\begin{eqnarray}\n\\frac{\\partial f}{\\partial x_i}=0{\\rm ,~~or~}\\nabla f=0.\n\\end{eqnarray}\nwhich would be $n$ equations for the $n$ variables. The gradient of a\nscalar is a vector, so you should think of $\\nabla$ as\n$\\vec{\\nabla}$. However, the solution will likely not satisfy the\nconstraint, i.e. the point at which $f(x_1\\cdots x_n)$ has an extrema,\nmay not be a point where $C(x_1\\cdots x_n)=0$.\n\nA necessary condition for the solution is that\n\\begin{equation}\n\\nabla f\\cdot\\vec{\\epsilon}=0,\n\\end{equation}\nfor any infinitesimal vector $\\vec{\\epsilon}$ if $\\vec{\\epsilon}$\nsatisfies the condition\n\\begin{equation}\n\\delta C=\\nabla C\\cdot\\vec{\\epsilon}=0.\n\\end{equation}\nThat is to say if I take a small step in a direction that doesn't\nchange the constraint, then $f$ must not change if it is an\nextrema. Not changing the constraint implies the step is orthogonal to\n$\\nabla C$. As there are $n$ dimensions of $x$, the vector $\\nabla C$\ndefines one direction, and $\\vec{\\epsilon}$ can be in any of the $n-1$\ndirections orthogonal to $\\nabla C$. If $\\nabla\nf\\cdot\\vec{\\epsilon}=0$ for ANY of the $n-1$ directions of\n$\\vec{\\epsilon}$ orthogonal to $\\nabla C$, then\n\\begin{equation}\n\\nabla f ~||~ \\nabla C.\n\\end{equation}\nBecause the two vectors are parallel you can say there must exist some\nconstant $\\lambda$ such that\n\\begin{equation}\n\\label{eq:lagrangemultiplier}\n\\nabla(f-\\lambda C)=0.\n\\end{equation}\nHere, $\\lambda$ is known as a Lagrange multiplier. Satisfying\nEq. (\\ref{eq:lagrangemultiplier}) is a necessary, but not a sufficient\ncondition. One could add a constant to the constraint and the gradient\nwould not change. One must find the correct value of $\\lambda$ that\nsatisfies the constraint $C=0$, rather than $C=$ some other\nconstant. The strategy is then to solve\nEq. (\\ref{eq:lagrangemultiplier}) then adjust $\\lambda$ until one\nfinds the $x_1\\cdots x_n$ that gives $C(x_1\\cdots x_n)=0$.\n\nThe method of Lagrange multipliers is counter-intuitive to one's\nintuition to use the constraint to reduce the dimensionality of the\nproblem. Normally, minimizing a function of $n$ variables, leads to\n$n$ equations and $n$ unknowns. A constraint could be used, by\nsubstitution, to replace the $n$ variables with $n-1$\nvariables. Instead, we add an unknown parameter, $\\lambda$, and change\nthe equation to $n+1$ equations with $n+1$ unknowns, with the extra\nunknown being the Lagrange multiplier $\\lambda$. Often, it is rather\neasy to solve for $x_1\\cdots x_n$. Then one is left with the usually\ndifficult problem of finding $\\lambda$, often requiring the solution\nof a transcendental equation.\n\n\\example As an example of using Lagrange multipliers for a standard\noptimization formula we attempt to maximize the following function,\n\\[\nF(x_1\\cdots x_n)=-\\sum_{i=1}^n x_i\\ln(x_i),\n\\]\nwith respect to the $n$ variables $x_i$. With no constraints, each\n$x_i$ would maximize the function for\n\\begin{eqnarray*}\n\\frac{d}{dx_j}~\\left[-\\sum_i\n  x_i\\ln(x_i)\\right]&=&0\\\\ -\\ln(x_j)-1&=&0,~~~~x_j=e^{-1}.\n\\end{eqnarray*}\nNow, we repeat the problem but with two constraints,\n\\[\n\\sum_ix_i=1~,~~~~\\sum_ix_i\\epsilon_i=E.\n\\]\nHere, $\\epsilon_i$ and $E$ are fixed constants. We go forward by\nfinding the extrema for\n\\begin{eqnarray*}\nG(x_1\\cdots x_n)&=&F-\\alpha\\sum_i x_i-\\beta\\sum_i\\epsilon_ix_i =\\sum_i\n\\left\\{-x_i\\ln(x_i)-\\alpha x_i-\\beta\\epsilon_ix_i\\right\\}.\n\\end{eqnarray*}\nThere are two Lagrange multipliers, $\\alpha$ and $\\beta$,\ncorresponding to the two constraints. One then solves for the extrema\n\\begin{eqnarray*}\n\\frac{d}{dx_j}G&=&0\\\\ &=&-\\ln(x_j)-1-\\alpha-\\beta\\epsilon_j,\\\\ x_j&=&\\exp\\left\\{-1-\\alpha-\\beta\\epsilon_j\\right\\}.\n\\end{eqnarray*}\nFor any given $\\alpha$ and $\\beta$ this provides a solution for\nconstraining $\\sum_i x_i$ and $\\sum_i\\epsilon_ix_i$ to some values,\njust not the values of unity and $E$ that you wish. One would then\nhave to search for the correct values by adjusting $\\alpha$ and\n$\\beta$ until the constraint are actually matched by solving a\ntranscendental equation. Although this can be complicated, it is\ncertainly less expensive than searching over all $N$ values of\n$x_i$. This particular example corresponds to maximizing the entropy\nfor a system, $S=-\\sum_i x_i\\ln(x_i)$, where $x_i$ is the probability\nof the system being in a particular discrete level $i$ that has energy\n$\\epsilon_i$. One wishes to maximize the entropy subject to the\nconstraints that the probabilities sum to unity and the average energy\nhas some given value. The result that $x_i\\sim e^{-\\beta\\epsilon_i}$\ndemonstrates the origin of the Boltzmann factor, with the inverse\ntemperature $\\beta=1/T$.\n\n\\exampleend\n\nLagrange multipliers also assist with the Euler-Lagrange equation. If\none breaks an interval $x_1<x<x_2$ into a large number\n$n\\rightarrow\\infty$ points separated by $dx$, the Euler-Lagrange\nequation involves finding the $n$ values $y_i$ at each point so that\n$\\sum_i dx f\\left\\{y_i,y'_i=(y_{i+1}-y_{i-1})/(2dx)\\right\\}$ is\nmaximized for some given function $f$. If an additional auxiliary\nconstraint is added, also some function of the $n$ values $y_i$, one\ncan use the method of Lagrange multipliers. In the constraint can also\nbe written as some function of $C(y_i,y'_i)$, then one simply adds a\nterm $\\lambda C(y,y')$ to the function $f$ and uses the Euler-Lagrange\nequation to find the extrema of.\n\\begin{eqnarray}\nJ&=&\\int_{x_1}^{x_2}dx~f\\left\\{y(x),y'(x),x\\right\\}-\\lambda\nC\\left\\{y(x),y'(x),x\\right\\},\n\\end{eqnarray}\nthe one difference being that\n\\begin{equation}\nf\\left\\{y(x),y'(x),x\\right\\}\\rightarrow\nf\\left\\{y(x),y'(x),x\\right\\}-\\lambda C\\left\\{y(x),y'(x),x\\right\\}\n\\end{equation}\nin Eq. (\\ref{eq:el}).\n\n\\example Consider a chain of length $L$ and mass per unit length\n$\\kappa$ that hangs from point $x=0,y=0$ to point $x_f,y_f$. The shape\nmust minimize the potential energy. Find general expressions for the\nshape in terms of three constants which must be chosen to match\n$y(0)=0, y(x_f)=y_f$ and the fixed length. Equivalently, one finds the\nfunction $y(x)$ that provides an extrema for the integral,\n\n{\\bf Solution:} One must minimize\n\\[\n\\int d\\ell~\\kappa gy-\\lambda\\int d\\ell= \\int_0^{x_f}\ndx~\\sqrt{1+y'^2}\\kappa gy-\\lambda \\int_0^{x_f} dx\\sqrt{1+y'^2}.\n\\]\nHere $\\lambda$ is the Lagrange multiplier associated with constraining\nthe length of the chain. The constrained length $L$ appears nowhere in\nthe expression. Instead, one solves for form of the answer, then\nadjusts $\\lambda$ to give the correct length. For the purposes of the\nEuler-Lagrange minimization one considers the function\n\\begin{eqnarray}\nf(y,y';x)&=&\\kappa gy\\sqrt{1+y'^2}-\\lambda\\sqrt{1+y'^2}.\n\\end{eqnarray}\nBecause $\\lambda$ is an unknown constant and because minimizing a\nfunction multiplied by a constant is the same as minimizing the\nfunction, we can equivlently minimize the integral using the function\n\\begin{eqnarray}\n\\tilde{f}(y,y';x)&=&y\\sqrt{1+y'^2}-\\tilde{\\lambda}\\sqrt{1+y'^2},\\\\ \\nonumber\n\\tilde{\\lambda}&\\equiv&\\frac{\\lambda}{\\kappa g}.\n\\end{eqnarray}\nThe Euler-Lagrange equations then become\n\\begin{eqnarray*}\n\\frac{d}{dx}\\left\\{\n\\frac{y'}{\\sqrt{1+y'^2}}y-\\tilde{\\lambda}\\frac{y'}{\\sqrt{1+y'^2}}\n\\right\\}&=&\\sqrt{1+y'^2}.\n\\end{eqnarray*}\nHere, we will guess at the form of the solution,\n\\begin{eqnarray*}\ny'&=&\\sinh[(x-x_0)/a],~~y=a\\cosh[(x-x_0)/a]+y_0.\n\\end{eqnarray*}\nPlugging into the Euler-Lagange equations,\n\\begin{eqnarray*}\n\\frac{d}{dx}\\left\\{(a\\cosh[(x-x_0)/a]+y_0)\\frac{\\sinh[(x-x_0)/a]}{\\cosh[(x-x_0)/a]}-\\tilde{\\lambda}\\frac{\\sinh[(x-x_0)/a]}{\\cosh[(x-x_0)/a]}\\right\\}&=&\\cosh[(x-x_0)/a],\\\\ \\nonumber\n\\frac{d}{dx}\\left\\{(y_0-\\tilde{\\lambda})\\tanh[(x-x_0)/a]\\right\\}=0.\n\\end{eqnarray*}\nThis solution works if $y_0=\\tilde{\\lambda}$. So the general form of\nthe solution is\n\\[\ny=\\tilde{\\lambda}+a\\cosh[(x-x_0)/a].\n\\]\nOne must find $\\tilde{\\lambda}$, $x_0$ and $a$ to satisfy three\nconditions, $y(x=0)=0$, $y(x=x_f)=y_f$ and that the length is $L$. For\na hanging chain $a$ is positive. A solution with negative $a$ would\nrepresent a maximum of the potential energy. A remarkable property of\nthe solution is that once you define the length and the end-point\npositions $y_1$ and $y_2$, the solution does not depend on $\\kappa$ or\n$g$. Thus, the shape of the chain would be the same if you took it to\nthe moon. These solutions are known as {\\it\n  catenaries},\\\\ \\href{http://en.wikipedia.org/wiki/Catenary}{http://en.wikipedia.org/wiki/Catenary}.\n\n\\exampleend\n\n\\subsection{Lagrangians}\n\nLagrangians represent a powerful method for solving problems that\nwould be nearly impossible by direct application of Newton's third\nlaw, $\\vec{F}=m\\vec{a}$. The method works well for problems where a\nsystem is well described by a few \\textit{generalized coordinates}. A\ngeneralized coordinate might be the angle describing the position of a\npendulum. This one angle takes the place of using $x$ and $y$ to\ndescribe the position of the pendulum, then applying a clumsy\nconstraint.\n\nThe Lagrangian equations of motion can be derived from a principle of\nleast action, where the action $S$ is defined as\n\\begin{equation}\nS=\\int dt~ L(q,\\dot{q},t),\n\\end{equation}\nwhere $q$ is some coordinate that describes the orientation of a\nsystem and the Lagrangian $L$ is defined as\n\\begin{equation}\nL=T-U,\n\\end{equation}\nthe difference of the kinetic and potential energies. Minimizing the\naction through the Euler-Lagrange equations gives the Lagrangian\nequations of motion,\n\\begin{equation}\n\\frac{d}{dt}\\frac{\\partial L}{\\partial \\dot{q}}=\\frac{\\partial\n  L}{\\partial q}.\n\\end{equation}\nWe begin with two simple examples, neither of which gains from the\nLagrangian approach.\n\n\\example Consider a particle of mass $m$ connected to a spring with\nstiffness $k$. Derive the Lagrangian equations of motion.\\\\ {\\bf\n  Solution:}\n\\begin{eqnarray*}\nL&=&\\frac{1}{2}m\\dot{x}^2-\\frac{1}{2}kx^2,\\\\ \\frac{d}{dt}\\frac{\\partial\n  L}{\\partial \\dot{x}}&=&\\frac{\\partial L}{\\partial\n  x},\\\\ m\\ddot{x}&=&-kx.\n\\end{eqnarray*}\n\n\\example Derive the Lagrangian equations of motion for a pendulum of\nmass $m$ and length $\\ell$.\n\\begin{eqnarray*}\nL&=&\\frac{m}{2}\\ell^2\\dot{\\theta}^2-mg\\ell(1-\\cos\\theta),\\\\ \\frac{d}{dt}\\frac{\\partial\n  L}{\\partial \\dot{\\theta}}&=&\\frac{\\partial L}{\\partial\n  \\theta},\\\\ m\\ell^2\\ddot{\\theta}&=&-mg\\ell\\sin\\theta,\\\\ \\ddot{\\theta}&=&-\\frac{g}{\\ell}\\sin\\theta,\\\\ \\ddot{\\theta}&\\approx&-\\frac{g}{\\ell}\\theta.\n\\end{eqnarray*}\n\\exampleend\n\n\\subsection{Proving Lagrange's Equations of Motion from Newton's Laws}\n\nLagrange's equations of motion can only be applied for the following\nconditions:\n\\begin{enumerate}\n\\item The potential energy is a function of the generalized\n  coordinates $q_i$, but not of $\\dot{q}_i$.\n\\item The relation between the original coordinates $x,y,z\\cdots$ and\n  the generalized coordinates does not depend on $\\dot{q}_i$,\n  e.g. $x(q,t)$ not $x(q,\\dot{q},t)$.\n\\item Any constraints used to reduce the number of degrees of freedom\n  are functions of $\\vec{q}$, but not of $\\dot{\\vec{q}}$.\n\\item The motion is not dissipative (no damping or friction).\n\\end{enumerate}\nGoing forward with the proof, consider $x_i(q_1,q_2\\cdots,t)$ and look\nat the l.h.s. of Lagrange's equations of motion.\n\\begin{eqnarray}\n\\label{eq:lagrangederivation1}\n\\frac{\\partial T}{\\partial\\dot{q}_j}&=&\\sum_i\\frac{\\partial\n  T}{\\partial\\dot{x}_i}\\frac{\\partial\\dot{x}_i}{\\partial\\dot{q_j}}\n+\\sum_i\\frac{\\partial T}{\\partial x_i}\\frac{\\partial\n  x_i}{\\partial\\dot{q_j}}\\\\ \\nonumber &=&\\sum_i\nm\\dot{x}_i\\frac{\\partial \\dot{x}_i}{\\partial\\dot{q_j}}\\\\ \\nonumber\n&=&\\sum_i m\\dot{x}_i\\frac{(\\delta x_i/\\delta t)|_{{\\rm fixed~}q_{j'\\ne\n      j}}}{\\delta q_j/\\delta t}\\\\ \\nonumber\n&=&\\sum_im\\dot{x}_i\\frac{\\delta{x}_i|_{{\\rm fixed~}q_{j'\\ne\n      j}}}{\\delta q_j}\\\\ \\nonumber &=&\\sum_i m\\dot{x}_i\\frac{\\partial\n  x_i}{\\partial q_j}.\n\\end{eqnarray}\nIn the first line we used the fact that $T$ does not depend on\n$x$. Continuing with taking the derivative of $U$,\n\\begin{eqnarray}\n-\\frac{\\partial U}{\\partial\\dot{q}_j}&=&-\\sum_i\\frac{\\partial\n  U}{\\partial x_i}\\frac{\\partial x_i}{\\partial\\dot{q}_j}=0.\n\\end{eqnarray}\nIn the first line above we used the fact that $U$ does not depend on\n$\\dot{x}$ then we used the second condition that $x$ does not depend\non $\\dot{q}$. Adding the two pieces together, then taking the\nderivative w.r.t. time,\n\\begin{eqnarray}\n\\nonumber\n\\frac{d}{dt}\\frac{\\partial}{\\partial\\dot{q}}(T-U)&=&\\sum_im\\ddot{x}_i\\frac{\\partial\n  x_i}{\\partial q_j} +\\sum_i\nm\\dot{x}_i\\frac{\\partial\\dot{x}_i}{\\partial q_j}.\n\\end{eqnarray}\n\nNow, we consider the r.h.s. of Lagrange's equations. Because the\nkinetic energy depends only on $\\dot{x}$ and not $x$, and because the\npotential depends on $x$ but not $\\dot{x}$,\n\\begin{eqnarray}\n\\label{eq:lagrangederivation2}\n\\frac{\\partial}{\\partial q_j}(T-U)&=&\\sum_i\\frac{\\partial\n  T}{\\partial\\dot{x}_i}\\frac{\\partial\\dot{x_i}}{\\partial q_j}\n-\\sum_i\\frac{\\partial U}{\\partial x_i}\\frac{\\partial x_i}{\\partial\n  q_j}\\\\ \\nonumber &=&\\sum_i\nm\\dot{x}_i\\frac{\\partial\\dot{x_i}}{\\partial q_j} -\\sum_i\\frac{\\partial\n  U}{\\partial x_i}\\frac{\\partial x_i}{\\partial q_j}\n\\end{eqnarray}\nUsing the fact that $m\\ddot{x}_i=-(\\partial/\\partial x_i)U$, one can\nsee that the bottom expressions in Eq.s (\\ref{eq:lagrangederivation1})\nand (\\ref{eq:lagrangederivation2}) are identical,\n\\begin{equation}\n\\frac{d}{dt}\\frac{\\partial}{\\partial\\dot{q}_i}(T-U)=\\frac{\\partial}{\\partial\n  q_i}(T-U).\n\\end{equation}\n\n\\subsection{Lagrangian Examples}\n\nTwo examples are presented here. In the first, there are two\ngeneralized coordinates, but the two equations of motion can be\nreduced to one through conservation laws (angular momentum in this\ncase). In the second, there is a time-dependent constraint.\n\n\\example Consider a cone of half angle $\\alpha$ standing on its tip at\nthe origin. The surface of the cone is defined as\n\\[\nr=\\sqrt{x^2+y^2}=z\\tan \\alpha.\n\\]\nFind the equations of motion for a particle of mass $m$ moving along\nthe surface under the influence of a constant gravitational force,\n$-mg\\hat{z}$. For generalized coordinates use the azimuthal angle\n$\\phi$ and $r$.\n\n{\\bf Solution:}\\\\ The kinetic energy is\n\\begin{eqnarray*}\nT&=&\\frac{1}{2}mr^2\\dot{\\theta}^2+\\frac{1}{2}m(\\dot{r}^2+\\dot{z}^2)\\\\ &=&\\frac{1}{2}mr^2\\dot{\\theta}^2+\\frac{1}{2}m\\dot{r}^2\\left(1+\\cot^2\\alpha\\right)\\\\ &=&\\frac{1}{2}mr^2\\dot{\\theta}^2+\\frac{1}{2}m\\dot{r}^2\\csc^2\\alpha.\n\\end{eqnarray*}\nThe potential energy is\n\\[\nU=mgr\\cot\\alpha,\n\\]\nso Lagrange's equations give\n\\begin{eqnarray*}\n\\frac{d}{dt}\\left(mr^2\\dot{\\theta}\\right)&=&0,\\\\ \\frac{d}{dt}\\left(m\\csc^2\\alpha\n\\dot{r}\\right)&=&mr\\dot{\\theta}^2-mg\\cot\\alpha,\\\\ \\ddot{r}&=&r\\dot{\\theta}^2\\sin^2\\alpha-g\\cos\\alpha\\sin\\alpha\n\\end{eqnarray*}\nThe first equation is a statement of the conservation of angular\nmomentum with $L=mr^2\\dot{\\theta}$, so the second equation can also be\nexpressed as\n\\[\n\\ddot{r}=\\frac{L^2\\sin^2\\alpha}{m^2r^3}-g\\sin\\alpha\\cos\\alpha.\n\\]\n\n\\example A bead slides along a wire bent in the shape of a parabola,\n\\[\nz=\\frac{1}{2}kr^2,~~r^2=x^2+y^2.\n\\]\nAlso, the parabolic wire is rotating about the $z$ axis with angular\nvelocity $\\omega$. Derive the equations of motion. Are there any\nstable configurations?\n\n{\\bf Solution:}\\\\ Using the fact that\n\\[\n\\dot{z}=\\dot{r}\\frac{\\partial z}{\\partial r}=kr\\dot{r},\n\\]\nthe kinetic and potential energies are\n\\begin{eqnarray*}\nT&=&\\frac{1}{2}m\\left(\\dot{r}^2+\\dot{z}^2+r^2\\omega^2\\right)\\\\ &=&\\frac{1}{2}m\\left(\\dot{r}^2+(kr\\dot{r})^2+r^2\\omega^2\\right),\\\\ U&=&mgkr^2/2.\n\\end{eqnarray*}\nThe equations of motion are then\n\\begin{eqnarray*}\n\\frac{d}{dt}\\left\\{m\\dot{r}(1+k^2r^2)\\right\\}&=&-mgkr+mk^2\\dot{r}^2r+m\\omega^2r,\\\\ \\ddot{r}&=&\\frac{-gkr+\\omega^2r-k^2\\dot{r}^2r}{1+k^2r^2}\n\\end{eqnarray*}\nFor a stable configuration, there needs to be a solution with\n$\\dot{r}=0$ and $\\ddot{r}=0$. This can only happen at $r=0$, and then\nfor the acceleration to be inward for small deviations of $r$ one\nneeds to have $gk>\\omega^2$. If $\\omega^2>gk$ the bead will move\noutward indefinitely.\n\n\\subsection{Small Vibrations and Normal Modes}\n\nTwo examples are provided for solving for normal modes. These are\nsolutions with multiple generalized coordinates, where the motion is\nthat of simple harmonic motion. However, the motion is only simple for\na particular set of coordinates $q_1$ and $q_2$,\n\\begin{eqnarray}\nq_1&=&A\\cos(\\omega_1 t),\\\\ \\nonumber q_2&=&B\\cos(\\omega_2 t),\n\\end{eqnarray}\nwhile it is not necessarily simple in other coordinates. For example\nif $x=q_1+q_2$, and $y=q_1-q_2$, the $x$ and $y$ motions will contain\nmixtures of multiple frequencies. For many problems, or in the limit\nof small vibrations about a minimum, there is some coordinate system\nwhere the motion is simple. These are normal modes. Characterizing the\nnormal modes involves finding the frequencies, $\\omega_i$, and the\ncoordinate system where the motion is simple for each coordinate. This\ninvolves finding the direction, or the linear combination of $x_i$\nthat form the coordinates $q_i$ in which the motion is that of a\nsingle oscillator in each coordinate.\n\nFor a first example, we consider a system of springs, where we write\nthe Lagrangian, then find the normal modes. For the second example, a\ndouble pendulum is considered. In this case, one must first make a\nsmall angle expansion before finding the modes. In principle, problems\ncould have the same number of normal modes a degrees of freedom. For\nexample, a system of 7 particles moving in three dimensions has 21\ndegrees of freedom. However, some of the degrees of freedom do not\nhave oscillatory behavior. For example, for a rigid body in free\nspace, the angles describing the orientation evolve, but do not\noscillate. Also, the center-of-mass coordinates of a system of\nparticles isolated from outside particles moves at constant\nvelocity. One can also describe these as normal modes, but acknowledge\nthat their characteristic frequency is zero, as there are no restoring\nforces.\n\n\\example\n\\begin{figure}\n\\centerline{\\includegraphics[width=0.5\\textwidth]{figs/springs}}\n\\caption{\\label{fig:springs} For Example\n  \\ref{sec:lagrangians}.\\arabic{examplecounter}, three masses\n  connected by two springs. The center-of-mass motion is unaffected by\n  the springs.}\n\\end{figure}\nConsider two springs, whose relaxed lengths are $\\ell$, connected to\nthree masses as depicted in Fig. \\ref{fig:springs}. Describe the two\nnormal modes of the motion. We can write the Lagrangian as\n\\begin{eqnarray*}\n\\mathcal{L}&=&\\frac{m}{2}\\dot{x}_1^2+m\\dot{x}_2^2+\\frac{m}{2}\\dot{x}_3^2\n-\\frac{k}{2}(x_2-x_1-\\ell)^2-\\frac{k}{2}(x_3-x_2-\\ell)^2.\n\\end{eqnarray*}\nThere are three coordinates, thus there are three equations of motion,\n\\begin{eqnarray*}\nm\\ddot{x}_1&=&-k(x_1-x_2+\\ell)\\\\ 2m\\ddot{x}_2&=&-k(x_2-x_1-\\ell)-k(x_2-x_3+\\ell)\\\\ &=&-k(2x_2-x_1-x_3)\\\\ m\\ddot{x}_3&=&-k(x_3-x_2+\\ell).\n\\end{eqnarray*}\nThis is a bit complicated because the center-of-mass motion does not\neasily separate from the three equations. Instead, choose the\nfollowing coordinates,\n\\begin{eqnarray*}\nX&=&\\frac{x_1+2x_2+x_3}{4},\\\\ q_1&=&x_1-x_2+\\ell,\\\\ q_3&=&x_3-x_2-\\ell.\n\\end{eqnarray*}\nIn these coordinates the potential energy only involves two\ncoordinates,\n\\begin{eqnarray*}\nU&=&\\frac{k}{2}(q_1^2+q_3^2).\n\\end{eqnarray*}\nTo express the kinetic energy express $x_1, x_2$ and $x_3$ in terms of\n$X$, $q_1$ and $q_3$,\n\\begin{eqnarray*}\nx_1&=&(3q_1-q_3-4\\ell+4X)/4,\\\\ x_2&=&(4X-q_1-q_3)/4,\\\\ x_3&=&(3q_3-q_1+4\\ell+4X)/4.\n\\end{eqnarray*}\nThe kinetic energy and Lagrangian are them\n\\begin{eqnarray*}\nT&=&\\frac{m}{2}\\frac{1}{16}(3\\dot{q}_1-\\dot{q}_3+4\\dot{X})^2\n+m\\frac{1}{16}(4\\dot{X}-\\dot{q}_1-\\dot{q}_3)^2\n+\\frac{m}{2}\\frac{1}{16}(3\\dot{q}_3-\\dot{q}_1+4\\dot{X})^2\\\\ &=&\\frac{3m}{8}(\\dot{q}_1^2+\\dot{q}_3^2)-\\frac{m}{4}\\dot{q}_1\\dot{q}_3\n+2m\\dot{X}^2,\\\\ \\mathcal{L}&=&\\frac{3m}{8}(\\dot{q}_1^2+\\dot{q}_3^2)-\\frac{m}{4}\\dot{q}_1\\dot{q}_3\n+2m\\dot{X}^2-\\frac{k}{2}q_1^2-\\frac{k}{2}q_3^2.\n\\end{eqnarray*}\nThe three equations of motion are then,\n\\begin{eqnarray*}\n\\frac{3}{4}m\\ddot{q}_1-\\frac{1}{4}m\\ddot{q}_3&=&-kq_1,\\\\ \\frac{3}{4}m\\ddot{q}_3-\\frac{1}{4}m\\ddot{q}_1&=&-kq_3,\\\\ 4M\\ddot{X}&=&0.\n\\end{eqnarray*}\nThe last equation simply states that the center-of-mass velocity is\nfixed. One could obtain the same result by summing the equations of\nmotion for $x_1$, $2x_2$ and $x_3$ above. The second two equations are\nmore complicated. To solve them, we assume a form\n\\begin{eqnarray*}\nq_1&=&Ae^{i\\omega t},\\\\ q_3&=&Be^{i\\omega t},\n\\end{eqnarray*}\nBecause this is a linear equation, we can multiply the solution by a\nconstant and it will still be a solution. Thus, we can set $B=1$, then\nsolve for $A$, effectively solving for $A/B$. Putting this guess into\nthe equations of motion,\n\\begin{eqnarray*}\n-\\frac{3}{4}\\frac{A}{B}\\omega^2+\\frac{1}{4}\\omega^2&=&-\\omega_0^2\\frac{A}{B},\\\\ \\frac{3}{4}\\omega^2+\\frac{1}{4}\\frac{A}{B}\\omega^2&=&-\\omega_0^2.\n\\end{eqnarray*}\nThis is two equations and two unknowns, $\\omega^2$ and\n$A/B$. Substituting for $A/B$ gives a quadratic equation,\n\\begin{eqnarray*}\n\\omega^4-3\\omega_0^2\\omega^2+2\\omega_0^4&=&0,\\\\ \\omega_0^2&\\equiv&k/m.\n\\end{eqnarray*}\nThe two solutions are\n\\begin{eqnarray*}\n(1)~~\\omega&=&\\omega_0,~~~A=-B,\\\\ (2)~~\\omega&=&\\omega_0\\sqrt{2},~~~A=B.\n\\end{eqnarray*}\nThe first solution corresponds to the two outer masses moving in\nopposite directions, in sync, with the middle mass fixed. The second\nsolution has both outer masses moving in the same direction, but with\nthe center mass moving opposite. These two solutions are referred to\nas normal modes, and are characterized by their frequency and by the\nlinear combinations of coordinates that oscillate together. In\ngeneral, the solution is a linear combination of normal modes, which\nusually results in a chaotic looking motion. However, once the\nsolution is expressed in terms of the normal modes, each of which\noscillates independently in a simple manner, one can better understand\nthe motion. Further, the frequencies of these modes represent the\nnatural resonant frequencies of the system. This is important in the\nconstruction of many structures, such as bridges or vehicles.\n\n\\example Consider a double pendulum confined to the $x-y$ plane, where\n$y$ is vertical. A mass $m$ is connected to the ceiling with a\nmassless string of length $\\ell$. A second mass $m$ hangs from the\nfirst mass with an identical massless string of the same length. Using\n$\\theta_1$ and $\\theta_2$ to describe the orientations of the strings\nrelative to the vertical axis, find the Lagrangian and derive the\nequations of motion, both for arbitrary angles and in the small-angle\napproximation. Finally, express the equations of motion in the limit\nof small oscillations.\n\n{\\bf Solution:}\\\\ The kinetic and potential energies are:\n\\begin{eqnarray*}\nT&=&\\frac{1}{2}m\\ell^2\\dot{\\theta}_1^2\n+\\frac{1}{2}m\\left\\{(\\ell\\dot{\\theta}_1\\cos\\theta_1+\\ell\\dot{\\theta}_2\\cos\\theta_2)^2\n+(\\ell\\dot{\\theta}_1\\sin\\theta_1+\\ell\\dot{\\theta}_2\\sin\\theta_2)^2\\right\\}\\\\ &=&\\frac{1}{2}m\\ell^2\\left\\{2\\dot{\\theta}_1^2+\\dot{\\theta}_2^2+2\\dot{\\theta}_1\\dot{\\theta}_2\\cos(\\theta_1-\\theta_2)\n\\right\\},\\\\ U&=&mg\\ell(1-\\cos\\theta_1)+mg\\left[\\ell(1-\\cos\\theta_1)+\\ell(1-\\cos\\theta_2)\\right]\\\\ &=&mg\\ell(3-2\\cos\\theta_1-\\cos\\theta_2)\n\\end{eqnarray*}\nLagrange's equations for $\\theta_1$ lead to\n\\begin{eqnarray*}\nm\\ell^2\\frac{d}{dt}\\left\\{2\\dot{\\theta}_1+\\dot{\\theta}_2\\cos(\\theta_1-\\theta_2)\\right\\}&=&\n-m\\ell^2\\dot{\\theta}_1\\dot{\\theta}_2\\sin(\\theta_1-\\theta_2)\n-2mg\\ell\\sin\\theta_1,\\\\ 2\\ddot{\\theta}_1+\\ddot{\\theta}_2\\cos(\\theta_1-\\theta_2)+\\dot{\\theta}_2^2\\sin(\\theta_1-\\theta_2)\n&=&-2\\omega_0^2\\sin\\theta_1,\\\\ \\omega_0^2&\\equiv& g/\\ell,\n\\end{eqnarray*}\nand the equations for $\\theta_2$ are\n\\begin{eqnarray*}\nm\\ell^2\\frac{d}{dt}\\left\\{\\dot{\\theta}_2+\\dot{\\theta}_1\\cos(\\theta_1-\\theta_2)\\right\\}&=&\nm\\ell^2\\dot{\\theta}_1\\dot{\\theta}_2\\sin(\\theta_1-\\theta_2)-mg\\ell\\sin\\theta_2,\\\\ \\ddot{\\theta}_2+\\ddot{\\theta_1}\\cos(\\theta_1-\\theta_2)&=&\n-\\omega_0^2\\sin\\theta_2.\n\\end{eqnarray*}\nFor small oscillations, one can only consider terms linear in\n$\\theta_1$ and $\\theta_2$ or their derivatives,\n\\begin{eqnarray}\n\\label{eq:doublependulum}\n2\\ddot{\\theta}_1+\\ddot{\\theta}_2&=&-2\\omega_0^2\\theta_1,\\\\ \\nonumber\n\\ddot{\\theta}_1+\\ddot{\\theta}_2&=&-\\omega_0^2\\theta_2.\n\\end{eqnarray}\nTo find the solutions, assume they are of the form\n$\\theta_1=Ae^{i\\omega t}, \\theta_2=Be^{i\\omega t}$. Solve for $\\omega$\nand $A/B$, noting that $B$ is arbitrary.\n\nPlug in the desired form and find\n\\begin{eqnarray*}\ne^{i\\omega t}(-2\\omega^2A-\\omega^2B)&=&e^{i\\omega\n  t}(-2\\omega_0^2A),\\\\ e^{i\\omega\n  t}(-\\omega^2A-\\omega^2B)&=&e^{i\\omega t}(-\\omega_0^2B).\n\\end{eqnarray*}\nWe can treat $B$ as arbitrary and set it to unity. When we find $A$,\nit is the same as $A/B$ for arbitrary $B$. This gives the equations\n\\begin{eqnarray*}\n2\\omega^2A+\\omega^2&=&2\\omega_0^2A,\\\\ \\omega^2A+\\omega^2&=&\\omega_0^2.\n\\end{eqnarray*}\nThis is two equations and two unknowns. Solving them leads to a\nquadratic equation with solutions\n\\begin{eqnarray*}\nA/B&=&\\pm\\frac{1}{\\sqrt{2}},\\\\ \\omega^2&=&\\frac{\\omega_0^2}{1\\pm\n  1/\\sqrt{2}}.\n\\end{eqnarray*}\nAgain, these two solutions are the normal modes, and the general\nsolution is a sum of the two solutions, with two arbitrary\nconstants. For the angles $\\theta_1$ and $\\theta_2$ are:\n\\begin{eqnarray*}\n\\theta_1&=&\\frac{A_+}{\\sqrt{2}}e^{i\\omega_+t},\n~\\theta_2=A_+e^{i\\omega_+t},\\\\ \\theta_1&=&\\frac{-A_-}{\\sqrt{2}}e^{i\\omega_-t},\n~\\theta_2=A_-e^{i\\omega_-t},\\\\ \\omega_{\\pm}&=&\\omega_0\\sqrt{\\frac{1}{1\\pm\n    1/\\sqrt{2}}}.\n\\end{eqnarray*}\nOne can also express the solution in vector notation, with the vectors\nhaving arbitrary amplitudes $A_+$ and $A_-$,\n\\begin{eqnarray*}\n\\theta_+&=&\\left(\\begin{array}{c}\n  \\frac{1}{\\sqrt{2}}\\\\ 1\\end{array}\\right)A_+e^{i\\omega_+t},\\\\ \\theta_-&=&\\left(\\begin{array}{c}\n    \\frac{-1}{\\sqrt{2}}\\\\ 1\\end{array}\\right)A_-e^{i\\omega_-t}.\n\\end{eqnarray*}\nHere, the upper/lower components of the vector describe\n$\\theta_1/\\theta_2$ respectively.\n\n\\exampleend\n\n{\\bf Aside:} (not applied in this course)\\\\ These problems can be\ntreated as linear algebra exercises. Linear algebra is not used in\nthis course, but nonetheless we describe how this works for the\ncurious student. In the limit of small vibrations, the equations of\nmotion can be expressed in the form,\n\\begin{eqnarray*}\nM\\ddot{q}&=&-Kq,\n\\end{eqnarray*}\na form that looks like the spring equation. However, $q$ is an\n$n-$dimensional vector and $M$ and $k$ are $n\\times n$ matrices. In\nthe double pendulum example, the dimensionality is 2 and the $q$\nrefers to the $\\theta_1$ and $\\theta_2$, and the matrices for $M$ and\n$K$ can be read off Eq. (\\ref{eq:doublependulum}),\n\\begin{eqnarray*}\nM&=&\\left(\\begin{array}{cc}\n  2&1\\\\ 1&1\\end{array}\\right)~,\\hspace*{40pt}\n  K=\\left(\\begin{array}{cc}\n    2\\omega_0^2&0\\\\ 0&\\omega_0^2\\end{array}\\right).\n\\end{eqnarray*}\nMultiplying both sides of the equation by the inverse matrix $M^{-1}$,\n\\begin{eqnarray*}\n\\ddot{q}&=&-\\left(M^{-1}K\\right)q.\n\\end{eqnarray*}\nHere,\n\\begin{eqnarray*}\nM^{-1}&=&\\left(\\begin{array}{cc}\n  1&-1\\\\ -1&2\\end{array}\\right),\\\\ M^{-1}K&=&\\left(\\begin{array}{cc}\n    2&-1\\\\ -2&2\\end{array}\\right)\\omega_0^2.\n\\end{eqnarray*}\nOne can find a transformation, basically a rotation, that transforms\nto a frame where $M^{-1}K$ is diagonal. In this coordinate system the\ndiagonal components of $M^{-1}K$ represent the squared frequencies of\nthe normal modes,\n\\[\nM^{-1}K\\rightarrow -\\left(\\begin{array}{cc}\n  \\omega_+^2&0\\\\ 0&\\omega_-^2\\end{array}\\right)~,\n\\]\nand are known as ``eigen'' frequencies. The corresponding unit\nvectors,\n\\[\n\\left(\\begin{array}{c} 1\\\\0\\end{array}\\right)~{\\rm\n    and}~\\left(\\begin{array}{c} 0\\\\1\\end{array}\\right)~{\\rm\n      in~the~new~coordinate~system},\n\\]\ncan be rotated back into the original frame, and become the solutions\nfor the normal modes. These are then called ``eigenvectors'', which\nare the same as the normal modes. Finding the eigenfrequencies is\nperformed by realizing that the determinant of a matrix is unchanged\nby the rotation between coordinate systems. Writing the equations of\nmotion as an eigenvalue problem,\n\\begin{eqnarray}\n\\left[A-\\lambda_i\\mathbb{1}\\right]u_i&=&0,~~~A\\equiv\nM^{-1}K,~\\lambda_i\\equiv \\omega^2_i.\n\\end{eqnarray}\nIn the coordinate system where $M^{-1}K$ is diagonal, and the forms\nfor $u_i$ are simple this requires that in that system, the diagonal\nelements of $M^{-1}K$ are the eigenvalues, $\\omega_i^2$. For each\n$\\omega^2_i$, the determinant $|A-\\lambda_i\\mathbb{1}|$ must\nvanish. This is then true in any coordinate system,\n\\begin{eqnarray}\n{\\rm det}\\left[A-\\lambda\\mathbb{1}\\right]&=&0,\n\\end{eqnarray}\nwhich for a $2\\times 2$ matrix becomes\n\\begin{eqnarray}\n\\label{eq:eigen}\n\\left|\n\\begin{array}{cc}\nA_{11}-\\lambda&A_{12}\\\\ A_{21}&A_{22}-\\lambda\n\\end{array}\n\\right|&=&0,\\\\ A_{11}A_{22}-\\lambda A_{11}-\\lambda\nA_{22}+\\lambda^2-A_{21}A_{12}&=&0.\n\\end{eqnarray}\nOne can solve a quadratic equation for $\\lambda$, which gives two\neigenvalues corresponding to $\\omega_+^2$ and $\\omega_-^2$ found\nabove. Choosing one of the eigenvalues, one can insert one of the\neigenvalues $\\lambda_i$ into Eq. (\\ref{eq:eigen}) and solve for $u_i$,\nthen choose the other eigenvalue and solve for the other corresponding\nvector.\n\nIf this were a 3-dimensional set of equations, the determinant would\ninclude terms like $\\lambda^3$ and would become a cubic equation with\nthree eigenvalues. One would then solve for three eigenvectors. If one\nhas a system with dimensionality $n>2$, one usually resorts to solving\nthe problem numerically due to the messiness of the algebra. The main\nprogramming languages all have packages which readily diagonalize\nmatrices and find eigenvectors and eigenvalues.\n\\subsection{Conservation Laws}\n\nEnergy is conserved only when the Lagrangian has no explicit\ndependence on time, i.e. $L(q,\\dot{q})$, not $L(q,\\dot{q},t)$. To show\nthis, we first define the Hamiltonian,\n\\begin{eqnarray}\n\\label{eq:Hdef}\nH&=&\\sum_i\\left(\\dot{q}_i\\frac{\\partial\n  L}{\\partial\\dot{q}_i}\\right)-L.\n\\end{eqnarray}\nAfter showing that $H$ is conserved, i.e. $(d/dt)H=0$, we then show\nthat $H$ can be identified with the total energy, $H=T+V$.\n\nOne can see that $H$ is conserved by applying first using the chain\nrule for $(d/dt)H$ in Eq. (\\ref{eq:Hdef}), then applying Lagrange's\nequations,\n\\begin{eqnarray}\n\\frac{d}{dt}H&=&\\sum_i\\left\\{\\ddot{q}_i\\frac{\\partial\n  L}{\\partial\\dot{q}_i}+\\dot{q}_i\\frac{d}{dt}\\left(\\frac{\\partial\n  L}{\\partial\\dot{q}_i}\\right)-\\frac{\\partial\n  L}{\\partial\\dot{q}_i}\\ddot{q}_i-\\frac{\\partial L}{\\partial\n  q_i}\\dot{q}_i\\right\\}\\\\ \\nonumber\n&=&\\sum_i\\left\\{\\ddot{q}_i\\frac{\\partial\n  L}{\\partial\\dot{q}_i}+\\dot{q}_i\\frac{\\partial L}{\\partial\n  q_i}-\\frac{\\partial L}{\\partial\\dot{q}_i}\\ddot{q}_i-\\frac{\\partial\n  L}{\\partial q_i}\\dot{q}_i\\right\\}\\\\ \\nonumber &=&0.\n\\end{eqnarray}\nThese steps assumed that $L$ had no explicit time dependence, i.e. $L$\nis a function of $q$ and $\\dot{q}$, but not of $t$.\n\nNext, we show that $L$ can be identified with the energy. Because $V$\ndoes not depend on $\\dot{q}$,\n\\begin{equation}\nH=\\sum_i\\frac{\\partial T}{\\partial\\dot{q}_i}\\dot{q}_i-T+V.\n\\end{equation}\nIf the kinetic energy has a purely quadratic form in terms of\n$\\dot{q}$,\n\\begin{equation}\n\\label{eq:Hquadq}\nT=\\sum_{ij}A_{ij}(q)\\dot{q}_i\\dot{q}_j,\n\\end{equation}\nthe Hamiltonian becomes\n\\begin{eqnarray}\nH&=&\\sum_{ij}2A_{ij}(q)\\dot{q}_i\\dot{q}_j-\\sum_{ij}A_{ij}(q)\\dot{q}_i\\dot{q}_j+V\\\\ \\nonumber\n&=&T+V.\n\\end{eqnarray}\nThe proof that $H$ equals the energy hinged on the fact that the\nkinetic energy was quadratic in $\\dot{q}$. This can be attributed to\ntime-reversal symmetry. Because the Cartesian coordinates $x_i$ do not\ndepend on $\\dot{q}_i$ or on time, $\\dot{x}_i=(\\partial x_i/\\partial\nq_j)\\dot{q}_j$. Thus, the kinetic energy, $T=m\\dot{x}_i^2/2$, should\nbe proportional to two powers of $\\dot{q}$, which validates the\nassumption in Eq. (\\ref{eq:Hquadq}).\n\nHere, energy conservation is predicated on the Lagrangian not having\nan explicit time dependence. Without an explicit time dependence the\nequations of motion are unchanged if one translates a fixed amount in\ntime because the physics does not depend on when the clock starts. In\ncontrast, the absolute time becomes relevant if there is an explicit\ntime dependence. In fact, conservation laws can usually be associated\nwith symmetries. In this case the translation symmetry in time leads\nto energy conservation.\n\nFor another example of how symmetry leads to conservation laws,\nconsider a Lagrangian for a particle of mass $m$ moving in a\ntwo-dimensional plane where the generalized coordinates are the radius\n$r$ and the angle $\\theta$. The kinetic energy would be\n\\begin{equation}\nT=\\frac{1}{2}m\\left\\{\\dot{r}^2+r^2\\dot{\\theta}^2\\right\\},\n\\end{equation}\nand if the potential energy $V(r)$ depends only on the radius $r$ and\nnot on the angle, Lagrange's equations become\n\\begin{eqnarray}\n\\frac{d}{dt}(m\\dot{r})&=&-\\frac{\\partial V}{\\partial\n  r}+m\\dot{\\theta}^2r,\\\\ \\nonumber \\frac{d}{dt}(mr^2\\dot{\\theta})&=&0.\n\\end{eqnarray}\nThe second equation implies that $mr^2\\dot{\\theta}$ is a\nconstant. Indeed, it is the angular momentum which is conserved for a\nradial force. Here, the conservation of angular momentum is associated\nwith the independence of the physics to changes in $\\theta$, or in\nother words, rotational invariance. Once one knows the fact that\n$L=mr^2\\dot{\\theta}$ is conserved, it can be inserted into the\nequations of motion for $\\dot{r}$,\n\\begin{equation}\nm\\ddot{r}=-\\frac{\\partial V}{\\partial r}+\\frac{L^2}{mr^3}.\n\\end{equation}\nThis is related to Noether's theorem\n\\href{http://en.wikipedia.org/wiki/Noether's_theorem}{http://en.wikipedia.org/wiki/Noether's\\_theorem},\nnamed after Emmy Noether,\n\\href{http://en.wikipedia.org/wiki/Emmy_Noether}{http://en.wikipedia.org/wiki/Emmy\\_Noether}. Simply\nstated, if the Lagrangian $L$ is independent of $q_i$, one can see\nthat the quantity $\\partial L/\\partial\\dot{q}_i$ is conserved,\n\\begin{equation}\n\\label{eq:noether}\n\\frac{d}{dt}\\frac{\\partial L}{\\partial\\dot{q}_i}=0.\n\\end{equation}\n\nAnother easy example is in Cartesian coordinates where the potential\ndepends only on $x$ and $y$ but not on $z$. In that case, there is a\ntranslational symmetry. From Eq. (\\ref{eq:noether}), this translates\ninto conservation of the momentum in the $z$ direction.\n\n\\example Consider a pair of particles of mass $m_1$ and $m_2$ where\nthe potential is of the form\n\\[\nU(\\vec{r}_1,\\vec{r}_2)=V_a(|m_1\\vec{r}_1+m_2\\vec{r}_2|/(m_1+m_2))+V_b(|\\vec{r}_1-\\vec{r}_2|).\n\\]\nUsing symmetry arguments alone, are there any conserved components of\nthe momentum? or the angular momentum??\\\\\n\nThere is no translational invariance, hence there are no conserved\ncomponents of the momentum. However, there is rotational invariance\nabout any axis that goes through the origin. Hence, there is angular\nmomentum conservation in all three directions. Symmetry arguments are\ngreat ways to recognize the existence of conserved quantities, but\nactually expressing them in terms of coordinates can be tricky. For\ninstance, you may need to write the Lagrangian in terms of angles.\n\n\\exampleend\n\n\\subsection{Numerically Solving Differential Equations}\n\nLagrangians lead to equations of motion for the generalized\ncoordinates. Often, these equations are not analytically solvable, but\nare readily addressed computationally. Here, we demonstrate how one\nwould solve such an equation numerically. So, we first imagine we have\na differential equation for $y(t)$, and for this example we assume the\nequation has no derivatives higher than second order. If the boundary\nconditions fix $y(0)$ and $y'(0)$, this should be sufficient to\ndetermine $y(t)$ for all future times. Of course, computers need to\ndiscretize the time steps. So assume there are time steps separated by\n$\\Delta t$ and values,\n\\begin{eqnarray}\nt_n&=&n\\Delta t,~=0,\\Delta t, 2\\Delta t, 3\\Delta t\\cdots\\\\ \\nonumber\ny_n&=&y(t_n).\n\\end{eqnarray}\nOur first step is to solve for $y_{-1}$ and $y_1$ given $y_0$ and\n$y'_0$. Approximating the derivatives over the finite intervals,\n\\begin{eqnarray}\ny(0)&=&y_0,\\\\ \\nonumber y'(0)&=&\\frac{y_1-y_{-1}}{2\\Delta\n  t},\\\\ \\nonumber y''(0)&=&\\frac{1}{\\Delta\n  t}\\left\\{\\frac{y_1-y_0}{\\Delta t}-\\frac{y_0-y_{-1}}{\\Delta\n  t}\\right\\} =\\frac{y_1-2y_0+y_{-1}}{\\Delta t^2}.\n\\end{eqnarray}\nOne needs to solve for the three unknowns $y_{-1},y_0$ and\n$y_1$. Here, $y(0)$ and $y'(0)$ are given, but $y''(0)$ is not, so a\nthird equation is needed to solve for the three unknowns. This is\nprovided by the equations of motion from the Lagrangian. Solving 3\nequations and 3 unknowns is thus a fair fight, and one can determine\n$y_{-1}\\rightarrow y_1$. Once knows these three values, one can use\nthe differential equation to solve for $y_2$ using $y_0$ and\n$y_1$. One can then iteratively find $y_n$ for any $n$ given $y_{n-1}$\nand $y_{n-2}$.\n\n\\example\n\nWrite an algorithm for solving the driven harmonic oscillator,\n\\[\ny''(t)+2\\beta y'(t)+\\omega_0^2 y(t)=(F_0/m)\\cos\\omega t.\n\\]\ngiven $y'(0)=6$ m/s, $y(0)=0.3$ m, and given $m=0.5$ kg, $F_0=400$ N,\nand a spring constant $k=2000$ N/m. Let the driving force have a\nperiod of 2.5 s, and the damping rate be $\\beta=0.15$ s$^{-1}$.\n\nLet's first solve for $y$ with indices $a,b,c=-1,0,1$, using the\ndifferential equation and the boundary conditions. The BC state that\n$y_b=0.3$ m and $(y_c-y_a)=2\\Delta t y'_b$, where $y'_b=6$\nm/s. Writing the differential equation,\n\\begin{eqnarray*}\n\\frac{y_c-2y_b+y_a}{\\Delta t^2}+\\beta\\frac{y_c-y_a}{\\Delta\n  t}+\\omega_0^2 y_b&=&(F_0/m)\\cos\\omega t_b,\n\\end{eqnarray*}\none can substitute for $y_a$ because the boundary condition for\n$y'_b=y'_0$ gives $y_a=y_{-1}$,\n\\begin{eqnarray*}\ny_a&=&y_c-2\\Delta ty'_b,\n\\end{eqnarray*}\nwhich gives an equation for $y_c$, where everything else in known,\n\\begin{eqnarray*}\n\\frac{2y_c-2y_b-2y'_b\\Delta t}{\\Delta t^2}+2\\beta\ny'_b+\\omega_0^2y_b&=&f_b,\\\\ \\nonumber y_c&=&y_b+y'_b\\Delta\nt+\\left[(f_b/2)-(\\omega_0^2y_b/2)-\\beta y'_b\\right](\\Delta t)^2.\n\\end{eqnarray*}\nHere, $f_b\\equiv (F_0/m)\\cos\\omega t$.\n\nNow, that one knows $y_0$ and $y_1$, lets write the differential\nequation for three consecutive points $y_a$, $y_b$ and $y_c$, and\nsolve for $y_c$ in terms of the other two (rather than using the BC as\nwas done above). Again, beginning with the differential equation,\n\\begin{eqnarray*}\n\\frac{y_c-2y_b+y_a}{\\Delta t^2}+\\beta\\frac{y_c-y_a}{\\Delta\n  t}+\\omega_0^2 y_b&=&(F_0/m)\\cos\\omega\nt_b,\\\\ y_c\\left(\\frac{1}{\\Delta t^2}+\\frac{\\beta}{\\Delta t}\\right)\n&=&f_b-\\omega_0^2y_b+\\frac{2y_b-y_a}{\\Delta t^2}+\\frac{\\beta\n  y_b}{\\Delta\n  t},\\\\ y_c&=&\\frac{f_b-\\omega_0^2y_b+\\frac{2y_b-y_a}{\\Delta\n    t^2}+\\frac{\\beta y_b}{\\Delta t}}{\\frac{1}{\\Delta\n    t^2}+\\frac{\\beta}{\\Delta t}},\\\\ &=&\\frac{f_b\\Delta\n  t^2-\\omega_0^2y_b\\Delta t^2+2y_b-y_a+\\beta y_b\\Delta\n  t}{1+\\beta\\Delta t}.\n\\end{eqnarray*}\nUsing $a=0, b=1, c=2$, this gives $y_2$. Then one can repeat with\n$a=1, b=2$ and $c=3$ to find $y_3$, and iterate to find all $n$.\n\n{\\bf Solution}:\\\\ The code might look something like this:\n{\\tt \\begin{verbatim} void main(){ const double PI=4.0*atan(1.0);\n    double m=0.5,k=2000.0; double omega0=sqrt(k/m), omega=2.0*PI/2.5,\n    beta=0.15; double ya,yb,yc,Dt=0.0025; // Dt = Delta t double\n    F0=400,yprime0; // Solve for a,b,c=-1,0,1, solve for yc yb=0.3;\n    yprime0=6.0; fb=(F0/m); // Use BC to solve for y_1=yc, from\n    lecture notes yc=yb+yprime0*Dt\n    +(0.5*fb-0.5*omega0*omega0*yb-beta*yprime0)*Dt*Dt; printf(\"t=0,\n    y=%g\\n\",yb);\n   \n   // Now interatively solve for yc, beginning with yc=y_2\n   for(n=0;n<1000;n++){ ya=yb; yb=yc; t=(n+1)*Dt;\n     fb=(F0/m)*cos(omega*t);\n     yc=(fb*Dt^2-omega0^2*yb*Dt*Dt+2*yb-ya+beta*yb*Dt)/(1+beta*Dt);\n     printf(\"t=%g, y=%g\\n\",Dt*n,yb); } }\n\\end{verbatim}}\n\\hrulefill\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n\n\\item Consider a hill whose height $y$ is given as a function of the\n  horizontal coordinate $x$. Consider a segment of the hill from $x=0$\n  to $x=L$ with initial height $y(x=0)=0$ and whose final height is\n  $y(x=L)=-h$. Transforming the last equation in Example\n  \\ref{ex:brachiostone} for a downward vertical force rather than a\n  horizontal force,\n\\[\nx=-\\sqrt{-2ay-y^2}+a\\arccos(1+y/a).\n\\]\nConsider a wheel of radius $a$ rolling along the bottom of the $x$\naxis. Mark a point on the top of the wheel, which is originally at the\norigin, $x=y=0$, when the top of the wheel touches the origin. As the\nwheel rolls by an angle $\\theta$ the marked point moves due to both\nthe translation and the rotation of the wheel. The $y$ coordinate of\nthe marked point is\n\\[\ny=-a(1-\\cos\\theta),\n\\]\nwhereas the $x$ coordinate is\n\\[\nx=a\\theta-a\\sin\\theta.\n\\]\nThe first term is due to the horizontal translation of the axis, while\nthe second term arises from the rotation of the wheel. Re-express\nthese two equations to find $x(y)$.\n\n\\item Consider a chain of length $L$ that hangs from two supports of\n  equal height stretched from $x=-X$ to $x=+X$. The general solution\n  for a catenary is\n\\[\ny=\\lambda+a\\cosh[(x-x_0)/a],\n\\]\n\\begin{enumerate}\n\\item Using symmetry arguments, what is $x_0$?\n\\item Express the length $L$ in terms of $X$ and $a$.\n\\item Numerically solve the transcendental equation above to find $a$\n  in terms of $L=10$ m and $X=4$ m.\n\\end{enumerate}\n\n\\item Consider a mass $m$ connected to a spring with spring constant\n  $k$. Rather than being fixed, the other end of the spring oscillates\n  with frequency $\\omega$ and amplitude $A$. For a generalized\n  coordinate, use the displacement of the mass from its relaxed\n  position and call it $y=x-\\ell-A\\cos\\omega t$. In this system the\n  potential energy of the spring is $ky^2/2$.\n\\begin{enumerate}\n\\item Write the kinetic energy in terms of the generalized coordinate.\n\\item Write down the Lagrangian.\n\\item Find the equations of motion for $y$.\n\\end{enumerate}\n\n\\item Consider a bead of mass $m$ on a circular wire of radius\n  $R$. Assume a force $kx$ acts on the bead, where $x$ and $y$ axes\n  run through the center of the circle. Using $\\theta$ as the\n  generalized coordinate (measured relative to the $x$ axis),\n\\begin{enumerate}\n\\item Write the Lagrangian in terms of $\\theta$.\n\\item Find the equations of motion.\n\\end{enumerate}\n\n\\item Consider a pendulum of length $\\ell$ with all the mass $m$ at\n  its end. The pendulum is allowed to swing freely in both\n  directions. Using $\\phi$ to describe the azimuthal angle about the\n  $z$ axis and $\\theta$ to measure the angular deviation of the\n  pendulum from the downward direction, address the following\n  questions:\n\\begin{enumerate}\n\\item If the pendulum is initially moving horizontally with velocity\n  $v_0$ and angle $\\theta_0=90^\\circ$ (horizontal), use energy and\n  angular momentum conservation to find the minimum angles of\n  $\\theta_{\\rm min}$ subtended by the pendulum. (Note that the angle\n  will oscillate between $90^\\circ$ and the minimum angle.\n\\item Write the Lagrangian using $\\theta$ and $\\phi$ as generalized\n  coordinates.\n\\item Write the equations of motion for $\\theta$ and $\\phi$.\n\\item Rewrite the equations of motion for $\\theta$ using angular\n  momentum conservation to eliminate and reference to $\\phi$.\n\\item Find the value of $L$ required for the stable orbit to be at\n  $\\theta=45^\\circ$.\n\\item For the steady orbit found in (e) consider small perturbations\n  of the orbit. Find the frequency with which the pendulum oscillates\n  around $\\theta=45^\\circ$.\n\\end{enumerate}\n\n\\item Consider a mass $m$ that is connected to a wall by a spring with\n  spring constant $k$. A second identical mass $m$ is connected to the\n  first mass by an identical spring. Motion is confined to the $x$\n  direction.\n\\begin{enumerate}\n\\item Write the Lagrangian in terms of the positions of the two masses\n  $x_1$ and $x_2$.\n\\item Solve for the equations of motion.\n\\item Find two solutions of the type\n\\begin{eqnarray*}\nx_1&=&Ae^{i\\omega t},~~~x_2=Be^{i\\omega t}.\n\\end{eqnarray*}\nSolve for $A/B$ and $\\omega$. Express your answers in terms of\n$\\omega_0^2=k/m$.\n\\end{enumerate}\n\n\\item Consider two masses $m_1$ and $m_2$ interacting according to a\n  potential $V(\\vec{r}_1-\\vec{r}_2)$.\n\\begin{enumerate}\n\\item Write the Lagrangian in terms of the generalized coordinates\n  $\\vec{R}_{\\rm cm}=(m_1\\vec{r}_1+m_2\\vec{r}_2)/(m_1+m_2)$ and\n  $\\vec{r}=\\vec{r}_1-\\vec{r}_2$, and their derivatives.\n\\item Using the independence of the Lagrangian with respect to\n  $\\vec{R}_{\\rm cm}$, find expressions for the conserved total\n  momentum.\n\\end{enumerate}\n\n\\end{enumerate}\n%\\end{document}\n", "meta": {"hexsha": "da7e37e666ad8dbb55d1fb7b5232e6bb5923113f", "size": 50504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/AdminBackground/lectures/chapter6.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/chapter6.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/chapter6.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": 45.0124777184, "max_line_length": 221, "alphanum_fraction": 0.7174085221, "num_tokens": 17000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.6945395943778646}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\usepackage{amsmath}\t\n\\usepackage{graphicx}\t\t\t\n\\begin{document}\n\\title{Optimal state observer for linear systems Lecture Notes} \n\\author {Fadi Younes}\n\\maketitle\n\\newpage\n\\section*{Overview}\nA state observer provides internal state estimation by measuring the Input and output of real given system. The system states are compulsory to solve control engineering problems like state feedback stabilization of system. It is used to reconstruct the system state from output measurement only if system is observable. \n\\section*{Linear time invariant (LTI) system}\nIt is assumed that the state of linear time invariant (LTI) physical discrete-time system satisfies, \\cite{khalil2002nonlinear}\\\\\n\\begin{equation}\nx(k+1) = Ax(k) + Bu(k)\n\\end{equation}\n\\begin{equation}\ny(k) = Cx(k) + Du(k)\n\\end{equation}\\\\\nWhere plant state is represented by x (k) at time ‘k’, u (k) is an input and y (k) is the output of the system. Merely such equations defines that current inputs and current states is solely responsible to determine the future states and current output of plant. However same equations can be used to analyze the continuous time linear invariant system with continuous time step. System observation can be determined by observable matrix and if it is observable then y (k) can be utilized to get states of the system.\n\\section*{Observer design}\nThe state observer model of given system is derived from equation 1 and 2. The successive calculated values of input and output of plant is ensured by adding additional term in above equations, so that state converges to plant. The state observer called Luenberger observer, constructed by adding the following term in above equation no 1 \\cite{bernat2015multi}.\\\\\n\\begin{align*}\nL[y(k)-\\hat{y(k)}]\n\\end{align*}\nWhere observer output is subtracted from plant output and then multiplied by ‘L’ matrix. Then it summarized as,\n\\begin{equation}\n\\hat{x(k+1)} = A\\hat{x(k)} + L[y(k)-\\hat{y(k)}]+ Bu(k)\n\\end{equation}\n\\begin{equation}\n\\hat{y(k)} = C\\hat{x(k)} + Du(k)\n\\end{equation}\nThe designed observer is stable if and only if error e (k) approaches to zero when discrete time step ‘k’ leads to infinity.\n\\begin{equation}\ne(k)= \\hat{x(k)}-x(k)\n\\end{equation}\n\\section*{Asymptotic stability}\nThe Luenberger observer satisfies if and only if error e (k+1) approaches to zero when discrete time step ‘k’ leads to infinity  \\cite{pasand2019luenberger}.\\\\\n\\begin{equation}\ne(k+1)= (A-LC)e(k)\n\\end{equation}\nThe asymptotic stability of Luenberger observer is associated with Eigenvalue values of (A-LC) matrix. If eigenvalues lies in inside the unit circle then it is asymptotic stable.\n\\section*{Optimal minimal order state observer}\nThe reduced order or minimal order state observer are called optimal observer that gives us least mean square estimation error in all 'n-m' dimensional filter. where n represent the system state dimension to be estimated and 'm' shows that no of available independent outputs of system. Meanwhile kalman filter has dynamic order greater than reduced order observer \\cite{pasand2019luenberger}\\cite{gautheir1992simple}.\nThe design of optimum minimum order observer is considered with noise inputs at correlated time steps. Correlated noise is a system noise which included in the estimation problem\n\\cite{ciccarella199310}.\n\\section*{Luenberger State Observer}\nThe control input is added to the system equations for control purpose of whole system. In which, the observer output is supplied back to input of the plant and observer as well by ‘K’ gain matrix \\cite{pasand2019luenberger} \\cite{hadj2001estimation}.\n\\begin{equation}\nu(k)= -K\\hat{x(k)}\n\\end{equation}\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=4.5 in]{s.PNG}\n  \\caption{Schematic block diagram}\\label{1}\n\\end{figure}\nFinally we achieved Observer equation\\\\\n\\begin{equation}\n\\hat{x(k+1)} = A\\hat{x(k)} + L[y(k)-\\hat{y(k)}]- BK\\hat{x(k)}\n\\end{equation}\n\\begin{equation}\n\\hat{y(k)} = C\\hat{x(k)} - DK\\hat{x(k)}\n\\end{equation}\nAs shown in Figure \\ref{1} \\cite{vinodh2013comparison}, compact form of the equations summarized as\n\\begin{equation}\n\\hat{x(k+1)} = (A- BK)\\hat{x(k)} + L[y(k)-\\hat{y(k)}]\n\\end{equation}\n\\begin{equation}\n\\hat{y(k)} = (C- DK)\\hat{x(k)}\n\\end{equation}\nHere, K and L can be selected independently to avoid any stability loss to the system.  Usually observer poles from (A-LC) are selected for rapid convergence than the state feedback poles from (A-BK).\n\n\\section*{Inference}\nLecture notes has discussed the state estimation problem in linear time invariant discrete-time-system using minimal order Luenberger State Observer. \n\\bibliographystyle{ieeetran}\n\\bibliography{ref_observer}\n\\end{document}", "meta": {"hexsha": "08562553b44b8e89805a5c02635f81ac728fdb5f", "size": 4699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "student_lecture_notes/state observer (Fadi Younes)/observer_notes.tex", "max_stars_repo_name": "SergeiSa/Linear-Control-Slides-Spring-2020", "max_stars_repo_head_hexsha": "b2604ce29f6dcad0c764d0ed6569a27b72d25f03", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-03-11T09:44:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-31T16:34:13.000Z", "max_issues_repo_path": "student_lecture_notes/state observer (Fadi Younes)/observer_notes.tex", "max_issues_repo_name": "SergeiSa/Linear-Control-Slides-Spring-2020", "max_issues_repo_head_hexsha": "b2604ce29f6dcad0c764d0ed6569a27b72d25f03", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-03-11T10:43:42.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-22T13:14:06.000Z", "max_forks_repo_path": "student_lecture_notes/state observer (Fadi Younes)/observer_notes.tex", "max_forks_repo_name": "SergeiSa/Linear-Control-Slides-Spring-2020", "max_forks_repo_head_hexsha": "b2604ce29f6dcad0c764d0ed6569a27b72d25f03", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2020-03-11T10:16:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-20T21:30:40.000Z", "avg_line_length": 61.8289473684, "max_line_length": 517, "alphanum_fraction": 0.7680357523, "num_tokens": 1248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.6944298828766728}}
{"text": "\\section{Genetic Algorithm}\n\tGenetic algorithms are a population based heuristic method that simulates nature's evolutionary system to evolve a starting population of random solutions to obtain very good (possibly optimal) solutions at the end of the process. To do this a random starting population is generated, then each solution is evaluated with a fitness function. After that some solutions, usually the best ones, are chosen to create offsprings that will replace worst solutions. This way the algorithm performs a sort of natural selection keeping the best solutions and improving them over generations.\n\t\n\tAs the problem is a variation of the popular Traveling Salesman Problem (TSP), it will be traded as such, so operators and solution representation are often the one used in literature for that problem. Also the important thing in the solution is the order of visited nodes, so crossover and mutations are order preserving, this means that they don't generate many new connections but try te keep connected the nodes that were already connected before.\n\t\t\n\t\\subsection{Encoding}\n\t\tTo represent a TSP solution the path representation has been used, it consists in a sequence of $N$ nodes, where $N$ is the total number of nodes, sorted from the starting one to the last visited on encoded path.\n\t\t\n\t\tFor example the path $0 \\rightarrow 3 \\rightarrow 1 \\rightarrow 4 \\rightarrow 2 \\rightarrow 0$ is encoded as:\n\t\t\\[[0, 3, 1, 4, 2]\\]\n\t\tNote that there are some symmetries using this representation:\n\t\t\\begin{enumerate}\n\t\t\t\\item \\textit{Rotation symmetries}: By rotating the path we obtain a solution that is equivalent but simply starts from a different node, e. g. [0,3,1,4,2] and [3,1,4,2,0]. These have been removed by fixing starting node to 0.\n\t\t\t\\item \\textit{Direction symmetry}: By reversing all the elements but the first of a path we get a representation of the inverse path, e.g. [0,3,1,4,2] and [0,2,4,1,3]. Dealing with this symmetry is however not efficient and so it's not been removed.\n\t\t\\end{enumerate}\n\t\n\t\\subsection{Fitness}\n\t\tAs fitness concerns I took a different approach from usual genetic algorithms and considered the sum of costs in path as the fitness and I will try to minimize it.\n\t\tThis choice was taken because other considered fitness functions had drawbacks, mainly because most of them were in the form $upperBound - costs$ but upper bounds are not so strict and then a proportional choice based on fitness would yield a very similar probability for each individual (because $maxFitness - minFitness$ is much lower than $upperBound - anyFitness$).\n\t\t\n\t\tBy setting the fitness function equal to the sum of path costs it it directly proportional to objective function resulting in a more correct reward based on fitness.\n\t\t\n\t\\subsection{Select}\n\t\tThe select operator is a little tricky because of the fact that solutions with lower fitness should have higher probabilities, so both Montecarlo and Linear ranking methods can't be used. N-Tournament is a valid alternative, but it was discarded because if a subset of $k$ solutions is chosen, the $k-1$ worst solutions are never used for crossover and this reduces (slightly) diversification.\n\t\t\n\t\tThe final choice is a probability calculated based on position in an array of solutions sorted by fitness. The selected solution is the one with index\n\t\t\\[index = \\left \\lfloor{N * r^{2}}\\right \\rfloor\\]\n\t\twhere N is the total number of nodes and r is a random number $\\in [0, 1)$\n\t\t\n\t\tThis way the solutions with lower cost are more likely to be chosen than the others, but each solution might be selected.\n\t\t\n\t\\subsection{Crossover}\n\t\tThe crossover operator takes a certain number of parents and creates an offspring that inherits parents properties. In the project was used the Order Crossover (OX), that from 2 parents creates one child, and works like this:\n\t\t\n\t\t\\begin{figure}[h]\n\t\t\\includegraphics[width=0.6\\textwidth]{ox_crossover}\n\t\t\\centering\n\t\t\\caption{Example of Order Crossover (OX)}\n\t\t\\end{figure}\n\t\t\n\t\t\\begin{enumerate}\n\t\t\t\\item Select a random subsequence of consecutive alleles from parent 1. (underlined)\n\t\t\t\\item Drop the subsequence down to Child and mark out these alleles in Parent 2.\n\t\t\t\\item Starting on the right side of the subsequence, grab alleles from parent 2 and insert them in Child at the right edge of the subsequence. Since 8 is in that position in Parent 2, it is inserted into Child first at the right edge of the subsequence.\\\\\n\t\t\t\tNotice that alleles 1, 2 and 3 are skipped because they are marked out and 4 is inserted into the 2nd spot in Child.\n\t\t\\end{enumerate}\n\t\t\n\t\\subsection{Mutation}\n\t\tOnly one type of mutation is used and it is the 2-opt, an algorithm that takes a substring of the path representation and reverse it. The idea is to take a route that crosses over itself and reorder it so that it does not.\n\t\tThis is good for the main purpose of mutations (prevent genetic drift) as well as for improving solutions.\n\t\t\n\t\t\\begin{figure}[h]\n\t\t\\includegraphics[width=0.5\\textwidth]{2-opt}\n\t\t\\centering\n\t\t\\caption{Example of 2-opt mutation}\n\t\t\\end{figure}\n\t\t\n\t\tTo control the mutation there is a parameter MUTATION\\_CHANCE that sets the probability that this mutation happens.\n\t\t\n\t\\subsection{Generational Replacement}\n\t\tWhen a population advance to next generation we need to replace the old bad solutions with newly created offsprings. This is done by elitist, so only the best solutions are kept and all the others are replaced by new solutions. The percentage of survivors (and replaced solutions) is set by the parameter SURVIVAL\\_RATIO.\n\t\t\n\t\\subsection{Improvements}\n\t\tAfter implementing all the elements of the algorithm and doing some basic tests I found out that the convergence was fast and after a few generations the solution was already quite good and it was rarely improved after. This means that algorithm was iterating through a lot of generation with very few improving solutions, so I decided to introduce random restarts reducing generations count and considering the best solution from all evaluated populations. This approach worked out well to find more reliably good solutions but slowed computation down. To make up for the loss in performance multithread has been used running genetic algorithm on many random starting populations in parallel. It is possible to control the amount of populations evaluated by setting the parameter POPULATIONS.\n\t\t\n\t\tAnother thing that has been tested is to modify the mutation chance at runtime based on the number of non-improving generations, but this didn't lead to significative improvement of solutions.\n\t\t\n\t\t", "meta": {"hexsha": "cd5d492e21210b4e502b879e546737dd349c793b", "size": 6606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/meta_heuristic.tex", "max_stars_repo_name": "abeccaro/MeMOC-project", "max_stars_repo_head_hexsha": "74d6b79ac72ed573c280478820a221424fc138f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-02-07T13:28:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-07T13:28:49.000Z", "max_issues_repo_path": "report/sections/meta_heuristic.tex", "max_issues_repo_name": "abeccaro/MeMOC-project", "max_issues_repo_head_hexsha": "74d6b79ac72ed573c280478820a221424fc138f5", "max_issues_repo_licenses": ["MIT"], "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/meta_heuristic.tex", "max_forks_repo_name": "abeccaro/MeMOC-project", "max_forks_repo_head_hexsha": "74d6b79ac72ed573c280478820a221424fc138f5", "max_forks_repo_licenses": ["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.1470588235, "max_line_length": 795, "alphanum_fraction": 0.782924614, "num_tokens": 1507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6944231777951396}}
{"text": "\\subsection{Algebras over semirings}\\label{subsec:algebras_over_semirings}\n\nAlgebras are usually defined for fields or at least commutative rings. We extend this to semirings for the purposes of polynomial semirings.\n\n\\begin{definition}\\label{def:multilinear_function}\\mimprovised\n  Generalizing \\hyperref[def:semimodule/homomorphism]{linear maps}, if \\( M_1, \\ldots, M_n \\) and \\( N \\) are \\( R \\)-modules, we say that the function\n  \\begin{equation*}\n    f: M_1 \\times \\ldots \\times M_n \\to N\n  \\end{equation*}\n  is \\term{multilinear} (\\term{bilinear} for \\( n = 2 \\)) if it is linear in each component. That is, for every tuple\n  \\begin{equation*}\n    (x_1, \\ldots, x_n) \\in M_1 \\times \\cdots \\times M_n,\n  \\end{equation*}\n  and for every index \\( k = 1, \\ldots, n \\), the following function is linear:\n  \\begin{equation*}\n    y \\mapsto f(x_1, \\ldots, x_{k-1}, y, x_{k+1}, \\ldots, x_n)\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:algebra_over_semiring}\\mimprovised\n  An \\term{algebra} over a \\hyperref[def:semiring/commutative]{commutative semiring} \\( R \\) is an \\( R \\)-\\hyperref[def:semimodule]{semimodule} \\( M \\) with an \\hyperref[def:magma/associative]{associative} \\hyperref[def:multilinear_function]{bilinear} vector multiplication operation. This makes \\( M \\) a nonunital ring. By default, we will also assume that \\( M \\) has a multiplicative unit, although nonunital algebras as just as valid as nonunital rings.\n\n  As in the case of general rings, by \\enquote{\\( M \\) is commutative}, we will mean that vector multiplication is commutative. Furthermore, although we assume it by default, if needed, we will distinguish between associative and non-associative algebra.\n\n  We identify every element \\( t \\) of \\( R \\) with its canonical embedding \\( t \\cdot 1_M \\) in \\( M \\), and thus we can also regard \\( R \\) as a sub-semiring of \\( M \\).\n\n  Algebras have the following metamathematical properties:\n  \\begin{thmenum}\n    \\thmitem{def:algebra_over_semiring/theory} The \\hyperref[def:first_order_theory]{first-order theory} for algebras extends the \\hyperref[def:semimodule/theory]{theory of commutative semimodules}. We add a new \\hyperref[rem:first_order_formula_conventions/infix]{infix} binary function symbol \\( \\odot \\) to the language, and add to the theory all semiring axioms from \\fullref{def:semiring/theory} for \\( + \\) and \\( \\odot \\). We must also add axioms ensuring that \\( \\odot \\) is bilinear. Additivity follows from distributivity, hence it remains to account for homogeneity. Using the notation of \\fullref{def:semimodule/theory}, this amounts to the following axiom schemas:\n    \\begin{align*}\n      m_r(x) \\odot y &= m_r(x \\odot y), \\\\\n      x \\odot m_r(y) &= m_r(x \\odot y).\n    \\end{align*}\n\n    \\thmitem{def:algebra_over_semiring/homomorphism} A \\hyperref[def:first_order_homomorphism]{first-order homomorphism} between two \\( R \\)-algebras \\( M \\) and \\( N \\) is a linear map that also preserves vector multiplication.\n\n    \\thmitem{def:algebra_over_semiring/submodel} The set \\( A \\subseteq M \\) is a \\hyperref[thm:substructure_is_model]{submodel} of \\( M \\) if it is a \\hyperref[def:monoid/submodel]{submodule} of \\( M \\) that is closed under algebra multiplication. We say that \\( A \\) is a \\term{subalgebra}.\n\n    As for general submodules, \\fullref{rem:span_over_different_semirings} shows how it is important to be unambiguous about over which semiring we consider the subalgebra.\n\n    As a consequence of \\fullref{thm:positive_formulas_preserved_under_homomorphism}, the image of an \\( R \\)-algebra homomorphism is a subalgebra of its range.\n\n    \\thmitem{def:algebra_over_semiring/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:algebra_over_semiring/category} We denote the category of algebras over \\( R \\) by \\( \\cat{Alg}_R \\) and the subcategory of commutative algebras by \\( \\cat{CAlg}_R \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:semiring_is_algebra}\n  Every \\hyperref[def:semiring]{semiring} \\( R \\) is an \\( R \\)-\\hyperref[def:algebra_over_semiring]{algebra} with both scalar and vector multiplication given by the multiplication in \\( R \\).\n\n  This extends \\fullref{thm:semiring_is_semimodule}.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:semiring_is_semimodule} by noting that bilinearity follows from left distributivity in \\( R \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:semiring_is_natural_number_algebra}\n  The categories \\( \\hyperref[def:semiring/category]{\\cat{SRing}} \\) of semirings and \\( \\hyperref[def:algebra_over_semiring/category]{\\cat{Alg}_\\BbbN} \\) of natural number algebras are \\hyperref[rem:category_similarity/isomorphism]{isomorphic}.\n\n  Compare this result to \\fullref{thm:commutative_monoid_is_semimodule} and \\fullref{thm:ring_is_integer_algebra}.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:commutative_monoid_is_semimodule} by noting that, as in the proof of \\fullref{thm:semiring_is_algebra}, distributivity implies bilinearity.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:functions_over_algebra}\n  For a set \\( A \\) and an \\( R \\)-\\hyperref[def:algebra_over_semiring]{algebra} \\( N \\), the set of all functions from \\( A \\) to \\( N \\) is itself an \\( R \\)-algebra with the following operations:\n  \\begin{thmenum}\n    \\thmitem{thm:functions_over_algebra/addition} Pointwise addition\n    \\begin{equation*}\n      [f + g](x) \\coloneqq f(x) + g(x)\n    \\end{equation*}\n\n    \\thmitem{thm:functions_over_algebra/scalar_multiplication} Pointwise scalar multiplication\n    \\begin{equation*}\n      [t \\cdot f](x) \\coloneqq t \\cdot f(x)\n    \\end{equation*}\n\n    \\thmitem{thm:functions_over_algebra/vector_multiplication} Pointwise vector multiplication\n    \\begin{equation*}\n      [f \\odot g](x) \\coloneqq f(x) \\cdot g(x)\n    \\end{equation*}\n\n    In practice, we use juxtaposition \\( fg \\) or \\( f \\cdot g \\) instead of \\( f \\odot g \\).\n  \\end{thmenum}\n\n  If \\( A \\) is also an \\( R \\)-algebra, we denote the set of all \\( R \\)-\\hyperref[def:algebra_over_semiring/homomorphism]{algebra homomorphisms} by \\( \\hom(A, N) \\).\n\n  This result extends \\fullref{thm:functions_over_semimodule}.\n\\end{proposition}\n\\begin{proof}\n  By \\fullref{thm:functions_over_model_form_model}, \\( N \\) is both an \\( R \\)-semiring and an \\( R \\)-semimodule. Compatibility comes from left distributivity in \\( N \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:multi_index}\\mimprovised\n  A \\term{multi-index} over the \\hyperref[def:set]{plain set} \\( \\mscrK \\) is a member of the \\hyperref[def:free_semimodule]{free \\( \\BbbN \\)-semimodule} \\( \\mscrK^{\\oplus \\BbbN} \\) over \\( \\mscrK \\). We endow \\( \\mscrK^{\\oplus \\BbbN} \\) with the \\hyperref[def:norm]{norm}\n  \\begin{equation*}\n    \\norm{ \\alpha } \\coloneqq \\sum_{k \\in \\mscrK} \\alpha_k\n  \\end{equation*}\n  and the \\hyperref[def:partially_ordered_set]{partial order}\n  \\begin{equation*}\n    \\alpha \\leq \\beta \\T{if and only if} \\qforall {k \\in \\mscrK} \\alpha_k \\leq \\beta_k.\n  \\end{equation*}\n\n  Multi-indices are \\hyperref[def:weighted_set/multiset]{multisets} with extra structure.\n\\end{definition}\n\n\\begin{definition}\\label{def:polynomial_algebra}\n  Fix a \\hyperref[def:semiring/commutative]{commutative semiring} \\( R \\) and a set \\( \\mscrX \\) of \\hyperref[def:formal_language/symbol]{symbols}, which we will call \\term{indeterminates}.\n\n  Let \\( \\mscrM \\) be the \\hyperref[def:free_semimodule]{free \\( R \\)-semimodule} over \\( \\mscrX \\), written \\hyperref[rem:additive_magma]{multiplicatively}. We will call the members of \\( \\mscrM \\) \\term{monomials}. Using a \\hyperref[def:multi_index]{multi-index} \\( \\gamma \\) over \\( \\mscrX \\), every monomial can be written as\n  \\begin{equation*}\n    \\prod_{X \\in \\mscrX} X^{\\gamma_X},\n  \\end{equation*}\n  where \\( \\gamma_X \\) are the coefficients in \\( R^{\\oplus \\mscrX} \\) of the monomial.\n\n  The \\term{polynomial algebra} or \\term{polynomial semiring} \\( R[\\mscrX] \\) for the given indeterminates is the \\hyperref[def:free_semimodule]{free \\( R \\)-semimodule} over \\( \\mscrM \\). That is, a polynomial \\( p \\in R[\\mscrX] \\) is an \\( R \\)-linear combination of monomials, and we denote polynomials by\n  \\begin{equation}\\label{eq:def:polynomial_algebra/p}\n    p(\\mscrX) = \\sum_\\gamma a_\\gamma \\prod_{X \\in \\mscrX} X^{\\gamma_X}.\n  \\end{equation}\n\n  We call \\( a_\\gamma \\) the \\term{coefficients} of the polynomial. We use the components of the multi-index as powers in the monomials, but we use \\( \\gamma \\) itself as an index for the coefficient \\( a_\\gamma \\). Unfortunately, multi-indices are sometimes confusing, but often their brevity outweighs the possible confusion.\n\n  We do not ignore the structure of \\( \\mscrM \\). We conflate exponentiation in \\( \\mscrM \\) in the sense of \\fullref{def:monoid/exponentiation} with exponentiation in \\( R[\\mscrX] \\) in the sense of \\fullref{def:semiring/exponentiation}. Multiplication in \\( \\mscrM \\) motivates us to define multiplication in \\( R[\\mscrX] \\) via a convolution of the coefficients. We define the product of \\( p(X) \\) from \\eqref{eq:def:polynomial_algebra/p} with\n  \\begin{equation}\\label{eq:def:polynomial_algebra/q}\n    q(\\mscrX) = \\sum_\\gamma b_\\gamma \\prod_{X \\in \\mscrX} X^{\\gamma_X}\n  \\end{equation}\n  as\n  \\begin{equation}\\label{eq:def:polynomial_algebra/pq}\n    [pq](\\mscrX) \\coloneqq \\sum_\\gamma \\parens*{ \\sum_{\\delta + \\eta = \\gamma} a_\\delta b_\\eta } \\prod_{X \\in \\mscrX} X^{\\gamma_X}.\n  \\end{equation}\n\n  We simultaneously use multi-indices as vectors with pointwise summation (i.e. \\( \\delta + \\eta = \\gamma \\)) and as indices of coefficients (i.e. \\( a_\\delta \\) and \\( b_\\eta \\)).\n\n  We avoid writing the embedding \\( \\iota: \\mscrX \\to R[\\mscrX] \\), but it is sometimes beneficial to denote it explicitly, for example in \\fullref{thm:polynomial_algebra_universal_property}.\n\\end{definition}\n\n\\begin{theorem}[Polynomial algebra universal property]\\label{thm:polynomial_algebra_universal_property}\n  Fix a \\hyperref[def:semiring/commutative]{commutative semiring} \\( R \\) and a set \\( \\mscrX \\) of indeterminates. The \\hyperref[def:polynomial_algebra]{polynomial algebra} \\( R[\\mscrX] \\) is the unique up to a unique isomorphism commutative \\hyperref[def:algebra_over_semiring]{algebra} that satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every commutative \\( R \\)-algebra \\( M \\) and every function \\( e: \\mscrX \\to M \\), there exists a unique \\( R \\)-algebra homomorphism \\( \\Phi_e: R[\\mscrX] \\to M \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:polynomial_algebra_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__polynomial_semiring_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  The function \\( e \\) evaluates each indeterminate in \\( M \\), while \\( \\Phi_e \\) substitutes this value in every polynomial. We call \\( \\Phi_e \\) the \\term{substitution homomorphism} corresponding to the \\term{variable assignment} \\( e \\). We can parameterize this by the evaluation functions to obtain the functional evaluation homomorphism\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Phi: R[\\mscrX] \\to \\fun(M^\\mscrX, M) \\\\\n      &\\Phi(p) \\coloneqq (e \\mapsto \\Phi_e(p))\n    \\end{aligned}\n  \\end{equation*}\n\n  We call the values of \\( \\Phi \\) \\term{polynomial functions}. Given elements \\( x_1, \\ldots, x_n \\) of \\( M \\), we write\n  \\begin{equation*}\n    p(x_1, \\ldots, x_n)\n  \\end{equation*}\n  rather than\n  \\begin{equation*}\n    \\Phi(p)(x_1, \\ldots, x_n).\n  \\end{equation*}\n\n  Via \\fullref{rem:universal_mapping_property}, \\( R[\\anon*] \\) becomes \\hyperref[def:category_adjunction]{left adjoint} to the \\hyperref[def:concrete_category]{forgetful functor}\n  \\begin{equation*}\n    U: \\cat{CAlg}_R \\to \\cat{Set}.\n  \\end{equation*}\n\n  The action of \\( R[\\anon*] \\) on morphisms is given by \\( \\Phi \\).\n\\end{theorem}\n\\begin{proof}\n  For every indeterminate \\( X \\), we want\n  \\begin{equation*}\n    \\Phi_e(\\iota(X)) = f(X).\n  \\end{equation*}\n\n  This suggests defining \\( \\Phi_e \\) for the polynomial\n  \\begin{equation*}\n    p(\\mscrX) = \\sum_\\gamma a_\\gamma \\prod_{X \\in \\mscrX} \\iota(X)^{\\gamma_X}\n  \\end{equation*}\n  as the evaluation\n  \\begin{equation*}\n    \\Phi_e(p) \\coloneqq \\sum_\\gamma a_\\gamma \\prod_{X \\in \\mscrX} f(X)^{\\gamma_X}.\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:polynomials_over_infinitely_many_indeterminates}\n  As we saw in \\fullref{def:polynomial_algebra} and \\fullref{thm:polynomial_algebra_universal_property}, there is no formal problem in defining polynomial algebras over infinitely many indeterminates.\n\n  There is a problem, however. Polynomials in one indeterminate, which we will call univariate in accordance to \\fullref{def:multi_valued_function/arguments}, have a \\hyperref[def:well_ordered_set]{well-ordering} on their monomials, induced by the degree of their monomials. This is defined and discussed in \\fullref{subsec:univariate_polynomials}.\n\n  Polynomials in more than one variable do not have a well-ordering by default. If the indeterminates themselves are well-ordered, as is the case for finitely many indeterminates, we may introduce, for example, a \\hyperref[def:lexicographic_order]{reverse lexicographic order} on the monomials. Furthermore, for finitely many variables, \\fullref{thm:def:polynomial_algebra/iterated} allows us to use \\hyperref[rem:induction/peano_arithmetic]{natural number induction} on the number of variables in order to prove statements about multivariate polynomial rings.\n\n  For infinitely many, especially uncountably many variables, however, the theory is seriously crippled by the lack of the tools described above. For this reason, only polynomials in finitely many variables are often considered.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:def:polynomial_algebra}\n  The following are basic properties of \\hyperref[def:polynomial_algebra]{polynomial semirings}:\n  \\begin{thmenum}\n    \\thmitem{thm:def:polynomial_algebra/empty} If \\( \\mscrX \\) is empty, \\( R[\\mscrX] \\cong R \\).\n\n    \\thmitem{thm:def:polynomial_algebra/iterated} The polynomial algebras \\( R[\\mscrX] \\) and \\( R[\\mscrX \\setminus \\set{ X_0 }][X_0] \\) are isomorphic for any \\( X_0 \\in \\mscrX \\) (in case \\( \\mscrX \\) has more than one member).\n\n    In particular,\n    \\begin{equation*}\n      R[X_1, \\ldots, X_{n-1}][X_n] \\cong R[X_1, \\ldots, X_n].\n    \\end{equation*}\n\n    \\thmitem{thm:def:polynomial_algebra/entire} The univariate \\hyperref[def:polynomial_algebra]{polynomial semiring} \\( R[X] \\) is \\hyperref[def:divisibility/zero]{entire} if and only if \\( R \\) is entire.\n\n    \\thmitem{thm:def:polynomial_algebra/units} If \\( R \\) is entire, the \\hyperref[def:divisibility/unit]{units} in \\( R[X_1, \\ldots, X_n] \\) are precisely the (embeddings of) the units of \\( R \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:polynomial_algebra/empty} Trivial.\n\n  \\SubProofOf{thm:def:polynomial_algebra/iterated} Polynomials in \\( R[\\mscrX] \\) have the form\n  \\begin{equation*}\n    p(\\mscrX) = \\sum_{k=0}^\\infty \\sum_\\gamma \\parens*{ a_{(k,\\gamma)} \\prod_{\\mathclap{X \\in \\mscrX \\setminus \\set{ X_0 }}} X^{\\gamma_X} } X_0^k,\n  \\end{equation*}\n  where \\( \\gamma \\) is a \\hyperref[def:multi_index]{multi-index} on \\( \\mscrX \\).\n\n  Due to associativity, commutativity and distributivity, this can be rewritten as\n  \\begin{equation*}\n    p(\\mscrX) = \\sum_{k=0}^\\infty \\parens*{ \\sum_\\gamma a_{(k,\\gamma)} \\prod_{\\mathclap{X \\in \\mscrX \\setminus \\set{ X_0 }}} X^{\\gamma_X} } X_0^k.\n  \\end{equation*}\n\n  This shows how \\( R[\\mscrX] \\) can be embedded into \\( R[\\mscrX \\setminus \\set{ X_0 }][X_0] \\). This embedding is surjective because the coefficients \\( a_\\gamma \\) range through \\( R \\). Therefore, the embedding is an isomorphism.\n\n  \\SubProofOf{thm:def:polynomial_algebra/entire}\n\n  \\SufficiencySubProof Since \\( R \\) is an \\( R \\)-subalgebra of \\( R[X] \\), if the latter is entire, so is the former.\n\n  \\NecessitySubProof Suppose that \\( R \\) is entire and that \\( R[X] \\) isn't. Then there exist nonzero polynomials \\( p(X) \\) and \\( q(X) \\) such that \\( p(X) q(X) = 0 \\). If \\( a_n \\) is the leading coefficient of \\( p(X) \\) and \\( b_m \\) --- of \\( q(X) \\), the leading coefficient of \\( p(X) q(X) \\) is \\( a_n b_m \\). Since \\( p(X) q(X) \\) is the zero polynomial, \\( a_n b_m = 0 \\), which contradicts the assumption that \\( R \\) is entire.\n\n  Therefore, \\( R[X] \\) is entire.\n\n  \\SubProofOf{thm:def:polynomial_algebra/units} As in \\fullref{thm:def:polynomial_algebra/entire}, it is sufficient to prove the statement for one indeterminate.\n\n  Clearly every constant is invertible as a constant polynomial.\n\n  Now suppose that \\( p(X) q(X) = 1 \\). By definition of multiplication, the product has only one nonzero coefficient. Since \\( R \\) is entire, it follows that both \\( p(X) \\) and \\( q(X) \\) have only one nonzero coefficient, and are hence constants.\n\\end{proof}\n\n\\begin{example}\\label{ex:def:polynomial_algebra}\n  We list several examples of \\hyperref[def:polynomial_algebra]{polynomials} over semirings.\n  \\begin{thmenum}\n    \\thmitem{ex:def:polynomial_algebra/natural_numbers} Consider the polynomial \\( p(X) \\coloneqq aX^2 + bX + c \\) in \\( \\BbbN[X] \\). A function from the set \\( \\set{ X } \\) to \\( \\BbbN \\) corresponds to an element of \\( \\BbbN \\), and hence evaluating the polynomial is done by simply replacing \\( X \\) symbolically in \\( p \\) and then evaluating the obtained \\hyperref[rem:binary_operation_syntax_trees]{syntax tree}.\n\n    We seek the roots of \\( p(X) \\). We will only formally define roots in \\fullref{def:polynomial_root}; for the purposes of the example, a root is a natural number \\( n \\) such that \\( \\Phi_n(p) = 0_R \\).\n\n    By \\fullref{thm:fundamental_theorem_of_algebra} and \\fullref{def:algebraically_closed_field/exactly_n_roots}, \\( p \\) has two roots in the \\hyperref[def:set_of_complex_numbers]{complex plane}. That is, we regard \\( \\BbbC \\) as an algebra over \\( \\BbbN \\) and use \\fullref{thm:polynomial_algebra_universal_property} to obtain a polynomial function on \\( \\BbbC \\). Furthermore, over the complex numbers the roots can be explicitly found using\n    \\begin{equation*}\n      \\frac {-b \\pm \\sqrt{b^2 - 4ac}} {2a}.\n    \\end{equation*}\n\n    Finding a root of \\( p \\) over the natural numbers cannot be done in general, however. If \\( p(n) = 0 \\), by the ordering of the natural numbers we have\n    \\begin{equation*}\n      p(n) = an^2 + bn + c \\geq c,\n    \\end{equation*}\n    and hence \\( c \\) must necessarily be \\( 0 \\). If \\( c = 0 \\), then zero is a root of the polynomial \\( p(X) = aX^2 + bX \\).\n\n    Now let \\( n \\) be any root of \\( p \\). We have\n    \\begin{equation*}\n      an^2 + bn \\geq bn,\n    \\end{equation*}\n    and hence \\( bn \\) must also be \\( 0 \\). Thus, either \\( b = 0 \\) or \\( n = 0 \\). If we want a root other than \\( n \\), both \\( a \\) and \\( b \\) must be \\( 0 \\).\n\n    Therefore, the only natural number solution to the quadratic equation is \\( 0 \\), and it is only a solution if \\( c = 0 \\).\n\n    \\thmitem{ex:def:polynomial_algebra/tropical} Consider again the polynomial \\( p(X) \\coloneqq aX^2 + bX + c \\) over \\( \\BbbN \\), but this time evaluated over the \\hyperref[def:tropical_semiring]{\\( \\min \\)-plus semiring} \\( (\\BbbN \\cup \\set{ \\infty }, \\min, +) \\).\n\n    Expressed via the standard natural number operations, this polynomial becomes\n    \\begin{equation*}\n      \\min\\set{ 2X + a, X + b, c }.\n    \\end{equation*}\n\n    This allows us to express certain optimization problems via polynomials.\n\n    This polynomial has a root if and only if \\( a = b = c \\). Roots in the tropical semiring are not very interesting, however.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:generators_via_polynomials}\n  For a set \\( A \\) in an \\( R \\)-\\hyperref[def:algebra_over_semiring]{algebra} \\( M \\), the \\hyperref[def:algebra_over_semiring/submodel]{generated subalgebra} of \\( A \\), defined as the \\( R \\)-subalgebra generated by \\( A \\) in the sense of \\fullref{def:first_order_generated_substructure}, equals the set\n  \\begin{equation*}\n    \\bigcup \\set[\\Big]{ R[a_1, \\ldots, a_n] \\given* a_1, \\ldots, a_n \\in A }\n  \\end{equation*}\n  obtained by evaluating all multivariate polynomials over \\( R \\) with elements of \\( A \\).\n\n  The \\( \\BbbN \\)-subalgebras of \\( M \\) correspond to \\hyperref[def:semiring/submodel]{sub-semirings} and the \\( M \\)-subalgebras correspond to \\hyperref[def:semiring_ideal/generated]{ideals}.\n\n  Compare this result to \\fullref{thm:span_via_linear_combinations} for modules.\n\\end{proposition}\n\\begin{proof}\n  Similar to \\fullref{thm:span_via_linear_combinations}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:adjoining_elements_to_semiring}\n  Let \\( R \\subseteq S \\) be \\hyperref[def:semiring/commutative]{commutative semirings} and let \\( A \\subseteq S \\) be an arbitrary subset.\n\n  Fix a set \\( \\mscrX \\) of indeterminates and a bijective function \\( e: \\mscrX \\to A \\) and consider the \\hyperref[thm:polynomial_algebra_universal_property]{evaluation homomorphism}\n  \\begin{equation*}\n    \\Phi_e: R[\\mscrX] \\to S.\n  \\end{equation*}\n\n  The image \\( R[A] \\) of \\( \\Phi_e \\) is the smallest super-semiring of \\( R \\) that contains \\( A \\).\n\n  We say that \\( R[A] \\) is obtained by \\term{adjoining} the elements of \\( A \\) to \\( R \\).\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:generators_via_polynomials}.\n\\end{proof}\n\n\\begin{example}\\label{ex:adjoining_root}\n  Continuing \\fullref{ex:def:polynomial_algebra/natural_numbers}, consider the polynomial equation\n  \\begin{equation*}\n    X + 1 = 0.\n  \\end{equation*}\n\n  It has no natural number root as a consequence of \\eqref{eq:def:peano_arithmetic/PA2}.\n\n  It does have an integer root, however, \\( -1 \\). We can \\hyperref[thm:adjoining_elements_to_semiring]{adjoin} \\( -1 \\) to the semiring \\( \\BbbN \\) to obtain the semiring \\( \\BbbN[-1] \\). But this latter semiring is (isomorphic to) \\( \\BbbZ \\).\n\n  Therefore, \\( \\BbbZ \\) is the smallest extension of \\( \\BbbN \\) that contains a root to the polynomial \\( X + 1 \\).\n\n  This example extends to the theory of \\hyperref[def:transcendetal_element]{transcendental and algebraic} elements of fields.\n\\end{example}\n\n\\begin{definition}\\label{def:formal_power_series}\\mimprovised\n  If we extend the concept of \\hyperref[def:polynomial_algebra]{polynomials} to allow countably many nonzero terms, we obtain a set \\( R\\Bracks{\\mscrX} \\) which we call the \\term{formal power series} over \\( R \\) with indeterminates from the set \\( \\mscrX \\).\n\n  The evaluation homomorphism defined in \\fullref{thm:polynomial_algebra_universal_property} is problematic, however, since algebraic operations are finitary by nature. This is discussed in \\fullref{rem:binary_operation_syntax_trees/infinite}, along with how sometimes we can make sense of infinitary algebraic operations.\n\\end{definition}\n", "meta": {"hexsha": "224e0b86053bcd875c1f0887a1795ce020ee4edf", "size": 23140, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/algebras_over_semirings.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/algebras_over_semirings.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/algebras_over_semirings.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.0588235294, "max_line_length": 677, "alphanum_fraction": 0.71326707, "num_tokens": 7243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6944063370479049}}
{"text": "\\chapter{Vectors}\n\\label{chp:vector}\n\\label{sec:vector}\n\nPick two points \\(A\\) and \\(B\\).\n\nThe vector \\(AB\\) tells us how to go from \\(A\\) to \\(B\\).\n\nThe vector \\(AB\\) is the subtraction \\( B - A \\).\n\nWe draw the vector \\(AB\\) as a straight arrow from \\(A\\) to \\(B\\).\n\nIf we know \\(A\\) and \\(B\\), then we can find \\(AB\\).\n\nIf we are at \\(A\\), then following \\(AB\\) leads us to \\(B\\).\nWe notate this fact as \\( A + AB = B \\).\nWe write the point on the left and the vector on the right:\nwrite \\( A + AB \\), and don't write \\( AB + A \\).\n\nThe zero vector \\(0\\) tells us how to get to the same point:\n\\(A + 0 = A\\).\n\nThe length of a vector \\(v\\) is written \\(\\norm{v}\\).\n\nA unit vector is a vector whose length is one.\n\n\\section*{Adding two vectors}\n\nIf \\(AB\\) tells us how to go from \\(A\\) to \\(B\\)\nand \\(BC\\) tells us how to go from \\(B\\) to \\(C\\),\nthen \\(AC = AB + BC\\)\ntells us how to go from \\(A\\) to \\(C\\).\n\nWe can see that \\( a + b = b + a \\) by drawing a parallelogram.\nWe say that vector addition is commutative\nbecause commuting (swapping) the arguments doesn't change the result.\n\n\\section*{Negating a vector}\n\nThe negation of a vector \\(v\\) is \\(-v\\).\nIt is the vector such that the sum \\(v + (-v)\\) is the zero vector \\(0\\).\n\nIf we know the vector \\(AB\\), then we know \\(BA\\).\nWe write \\(BA = -AB\\).\nIf \\(AB\\) tells us how to go from \\(A\\) to \\(B\\),\nthen \\(BA\\) tells us how to go from \\(B\\) to \\(A\\).\n\\(BA\\) is the reverse of \\(AB\\).\n\n\\(BA\\) is also called the negation of \\(AB\\) because \\(AB + BA = 0\\) is the zero vector.\n\\(A + 0 = A\\).\n\nNegating a vector preserves its length:\n\\(\\norm{-AB} = \\norm{BA} = \\norm{AB}\\).\n\n\\section{Vector spaces}\n\nA vector space is a set of vectors.\n\nAn example vector space is the set of all two-dimensional Euclidean vectors.\nWe can imagine this vector space as the set of all arrows that we can draw on an unbounded flat sheet of paper.\nWe don't care about where the arrow is.\nWe only care about its length and direction.\nIf two arrows have the same length and direction,\nthen they represent the same vector.\n\nAn example vector space is the space of all two-dimensional Euclidean vectors.\n\n\\section{Collinearity and linear combination}\n\nTwo vectors \\(a\\) and \\(b\\) are collinear\niff they have the same direction or the opposite direction.\nIf we place them so that their origins coincide, they form a straight line segment.\n\nThe zero vector is collinear with every vector.\n% This simplifies the definition of basis later.\n% Now we can write \\enquote{non-collinear} instead of \\enquote{non-zero non-collinear}.\n\nSee also Wikipedia\\footnote{\\url{https://en.wikipedia.org/wiki/Collinearity}}.\n\n\\paragraph{Linear combination of two vectors}\n\nLet \\(p\\) and \\(q\\) be vectors.\nA linear combination of \\(p\\) and \\(q\\) is a vector \\( ap+bq \\)\nwhere \\(a\\) and \\(b\\) are real numbers.\nIn other words, we say that \\(r\\) is a linear combination of \\(p\\) and \\(q\\)\niff there exists \\(a,b\\in \\Real\\) such that \\(r = ap+bq\\).\n\n\\section{External resources}\n\nSee Wikipedia%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Euclidean_vector}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Vector_(mathematics_and_physics)}}%\n.\n\n\\section{What?}\n\n\\paragraph{Finding the angle between two vectors}\n\nFor every pair of vectors,\nwe can always find a plane such that both of them lie on that plane.\nThe plane defines the angle.\n\n\\paragraph{Deciding orthogonality by dot product}\n\nLet \\(a\\) be a vector.\n\nLet \\(b\\) be vector.\n\nLet the angle from \\(a\\) to \\(b\\) is \\(\\theta\\). Positive means counterclockwise.\n\nThe dot product is \\(a \\cdot b = \\norm{a} \\cdot \\norm{b} \\cdot \\cos \\theta\\).\n\nNote that the dot symbol \\(\\cdot\\) is overloaded.\nIt may mean real multiplication,\nvector scaling,\nvector dot product,\nor something else.\nIts meaning depends on the things around it.\n\nIf \\(\\norm{a} \\cdot \\norm{b} \\neq 0\\) and \\(a \\cdot b = 0\\),\nthen \\(a\\) and \\(b\\) are orthogonal.\nTwo orthogonal vectors form a right angle.\n", "meta": {"hexsha": "8fb40978017eae42b29469828964b9255984e6cb", "size": 3927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/vector.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/vector.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/vector.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 31.9268292683, "max_line_length": 111, "alphanum_fraction": 0.6806722689, "num_tokens": 1102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6943692706885841}}
{"text": "\\section{Backpropagation} \\label{sec:backpropagation}\nLast section showed how learning in a neural network is a minimization problem on the loss function and that it is solved by repeatedly updating the network's parameters using the gradient of the loss. But how exactly is the gradient calculated? The loss function is a surface in very high dimensions, calculated by averaging some distance function between the network's output and the true output for all inputs on the dataset; and the output of the network is a mapping calculated by passing the input through possible thousands, millions, or more units, where each one can apply a nonlinearity to its output. In summary, the loss surface is extremely complex and the same should be expected for its gradient.\n\nTo make it simpler to understand how the gradient is calculated, the procedure will be shown only for the weights and biases parameters, since those are present in practically all neural networks (although sometimes the bias is omitted in some units). This section will suppose a neural network with $L+1$ layers, where layer $0$ is the input, layer $L$ is the output and values in between are hidden layers.\n\nEssentially, calculating the gradients consists of a smart application of the chain rule of calculus. Recall that the chain rule is a way of calculating the derivative of composite functions, this means that for a function $y$ that depends on $t$, and $t$ that depends on $x$, then the chain rule allows for calculating the derivative of $y$ with respect to $x$ by compounding how $x$ changes $t$ and how $t$ changes $y$. For the case of single variable functions the chain rule is given by \\autoref{eq:chain_rule} \\cite[p. 406]{calculusIII2016}.\n\\begin{equation} \\label{eq:chain_rule}\n    \\frac{dy}{dx} = \\frac{dy}{dt} \\frac{dt}{dx}\n\\end{equation}\n\nBut for the case of neural networks, the loss function is dependent on all the activations of the output layer, and those are dependent on their weights, biases, and possibly other parameters, besides being dependent on activations of the previous layer. So it is necessary to use the multi-variable generalization of the chain rule shown in \\autoref{eq:chain_rule_general} \\cite[p. 412]{calculusIII2016}, here it is necessary to compound the effect of $x$ for all the variables $(t_0, t_1, \\dots t_n)$ that $y$ is dependent on.\n\\begin{equation} \\label{eq:chain_rule_general}\n    \\frac{\\partial y}{\\partial x} = \\sum_{i}^{n}{\\frac{\\partial y}{\\partial t_i} \\frac{\\partial t_i}{\\partial x}}\n\\end{equation}\n\nHaving the chain rule in mind, it is also useful to define an additional term $\\delta$ that represents the partial derivative of the loss with respect to the weighted input of a unit. For unit $i$ on layer $l$ this term is given by \\autoref{eq:neuron_delta}.\n\\begin{equation} \\label{eq:neuron_delta}\n    \\delta_{i}^{(l)} = \\frac{\\partial J}{\\partial z_i^{(l)}}\n\\end{equation}\n\nAnd lastly, note that by differentiating Equations \\ref{eq:activation_again} and \\ref{eq:dense_weighted_input}, the following relations are obtained.\n\\begin{equation*}\n    \\frac{\\partial z_i^{(l+1)}}{\\partial a_i^{(l)}} = w_{ij}^{(l+1)}\n    \\qquad\n    \\qquad\n    \\frac{\\partial z_i^{(l)}}{\\partial b_i^{(l)}} = 1\n    \\qquad \\qquad\n    \\frac{\\partial z_i^{(l)}}{\\partial w_{ij}^{(l)}} = a_j^{(l-1)}\n    \\\\[2pt]\n\\end{equation*}\n\nThe main idea of this algorithm is to derive $\\delta$ for all layers, then use these values to calculate the gradient terms for all parameters, the first step is to calculate $\\delta$ in the last layer. For the following derivation, consider $\\hat{\\bm{y}}$ as the network output, and notice that it is the same as the activations of the output layer $\\bm{a}^{(L)}$. By using this knowledge, \\autoref{eq:delta_last_layer} is derived as follows.\n\\begin{align}\n    \\frac{\\partial J}{\\partial z_i^{(L)}} = \\delta_{i}^{(L)} &=\n    \\frac{\\partial J}{\\partial \\hat{y_i}} \\frac{\\partial \\hat{y_i}}{\\partial z_i^{(L)}} \\nonumber \\\\[10pt]\n    %\n    &= \\frac{\\partial J}{\\partial \\hat{y_i}} \\frac{\\partial a_i^{(L)}}{\\partial z_i^{(L)}} \\nonumber \\\\[10pt]\n    %\n    &= \\frac{\\partial J}{\\partial \\hat{y_i}} \\frac{\\partial}{\\partial z_i^{(L)}} {f\\left(z_i^{(L)}\\right)} \\nonumber \\\\[10pt]\n    %\n    \\delta_{i}^{(L)} &= \\frac{\\partial J}{\\partial \\hat{y_i}} f'\\left(z_i^{(L)}\\right) \\label{eq:delta_last_layer}\n\\end{align}\n\nRecall that the loss function $J$ and activation function $f$ should both be continuous and differentiable, and since they are chosen when building the network their derivatives are known. The values $\\hat{y_i}$ and $z_i^{(L)}$ are also known since they are calculated by the network and can be easily stored during training. This means that \\autoref{eq:delta_last_layer} can be used to calculate all $\\delta$ values in the last layer.\n\nBy using \\autoref{eq:delta_last_layer} it is also possible to find an expression to calculate all the other $\\delta$ values, the following derivation shows how this can be done by writing $\\delta^{(l)}$ in terms of $\\delta^{(l+1)}$ as shown in \\autoref{eq:delta_hidden_layer}.\n\\begin{align}\n    \\frac{\\partial J}{\\partial z_j^{(l)}} = \\delta_j^{(l)} &= \\sum_{i}{\n        \\frac{\\partial J}{\\partial z_i^{(l+1)}}\n        \\frac{\\partial z_i^{(l+1)}}{\\partial a_j^{(l)}}\n        \\frac{\\partial a_j^{(l)}}{\\partial z_j^{(l)}}\n    } \\nonumber \\\\[10pt]\n    %\n    &= \\sum_{i}{\n        \\delta_i^{(l+1)}\n        \\frac{\\partial z_i^{(l+1)}}{\\partial a_j^{(l)}}\n        \\frac{\\partial a_j^{(l)}}{\\partial z_j^{(l)}}\n    } \\nonumber \\\\[10pt]\n    %\n    &= \\sum_{i}{\n        \\delta_i^{(l+1)}\n        w_{ij}^{(l+1)}\n        \\frac{\\partial a_j^{(l)}}{\\partial z_j^{(l)}}\n    } \\nonumber \\\\[10pt]\n    %\n    \\delta_j^{(l)} &= \\sum_{i}{\n        \\delta_i^{(l+1)}\n        w_{ij}^{(l+1)}\n        f'\\left( z_j^{(l)} \\right)\n    } \\label{eq:delta_hidden_layer}\n    %\n\\end{align}\n\nNotice how the algorithm works, first the input is feedforwarded through the network to obtain the output $\\hat{\\bm{y}}$, this value is used to calculate $\\delta^{(L)}$, that is then \\textit{backpropagated} through the network in order to calculate $\\delta^{(l)}$ for all previous layers. This process gives the name \\textit{Backpropagation} to the algorithm.\n\nNow for calculating the gradients using $\\delta$. Notice that for this case, where only the weights and biases are being considered, the gradient depends on the change $\\partial J$ with respect to $\\partial b_i^{(l)}$ and $\\partial w_{ij}^{(l)}$ for all units and layers.\n\nThe following derivation applies the chain rule to obtain the relation in \\autoref{eq:gradient_bias} for the partial derivatives of the loss with respect to all the biases parameters.\n\\begin{align}\n    \\frac{\\partial J}{\\partial b_i^{(l)}} &= \\sum_{k}{\n        \\frac{\\partial J}{\\partial z_k^{(l)}}\n        \\frac{\\partial z_k^{(l)}}{\\partial b_i^{(l)}}\n    } \\nonumber \\\\\n    %\n    &= \\frac{\\partial J}{\\partial z_i^{(l)}} \\frac{\\partial z_i^{(l)}}{\\partial b_i^{(l)}} + \n    \\sum_{k \\neq i}{\n        \\frac{\\partial J}{\\partial z_k^{(l)}}\n        \\cancelto{0}{\\frac{\\partial z_k^{(l)}}{\\partial b_i^{(l)}}}\n    } \\nonumber \\\\[10pt]\n    %\n    &= \\frac{\\partial J}{\\partial z_i^{(l)}} \\nonumber \\\\[10pt]\n    %\n    \\frac{\\partial J}{\\partial b_i^{(l)}} &= \\delta_{i}^{(l)} \\label{eq:gradient_bias}\n\\end{align}\n\nThe derivation for \\autoref{eq:gradient_bias} first breaks the partial derivative of the cost in terms of the weighted inputs $\\bm{z}^{(l)}$ in the layer where the bias is present. This is enough since the bias can not influence any previous layers and all influences in the next layers are already captured in the change $\\partial J$ with respect to the weighted inputs $\\partial z_k^{(l)}$. Since it is also known that the bias does not influence any other unit in the layer, the derivation could have been made directly without breaking the derivative into a sum of all the terms in the layer, but the whole process was shown here for completion sake.\n\nA similar rationale can be used for the weight parameters, obtaining the relation seen in \\autoref{eq:gradient_weight}.\n\\begin{align}\n    \\frac{\\partial J}{\\partial w_{ij}^{(l)}} &= \\sum_{k}{\n        \\frac{\\partial J}{\\partial z_k^{(l)}}\n        \\frac{\\partial z_k^{(l)}}{\\partial w_{ij}^{(l)}}\n    } \\nonumber \\\\\n    %\n    &= \\frac{\\partial J}{\\partial z_i^{(l)}} \\frac{\\partial z_i^{(l)}}{\\partial w_{ij}^{(l)}} + \n    \\sum_{k \\neq i}{\n        \\frac{\\partial J}{\\partial z_k^{(l)}}\n        \\cancelto{0}{\\frac{\\partial z_k^{(l)}}{\\partial w_{ij}^{(l)}}}\n    } \\nonumber \\\\[10pt]\n    %\n    &= \\frac{\\partial J}{\\partial z_i^{(l)}} a_{j}^{(l-1)} \\nonumber \\\\[10pt]\n    %\n    \\frac{\\partial J}{\\partial w_{ij}^{(l)}} &= \\delta_{i}^{(l)} a_{j}^{(l-1)} \\label{eq:gradient_weight}\n\\end{align}\n\n\n\\autoref{eq:gradient_weight} was the last piece of the puzzle, together with Equations \\ref{eq:delta_last_layer}, \\ref{eq:delta_hidden_layer}, and \\ref{eq:gradient_bias}, it can be applied to calculate the gradient for all parameters in the network, and this allows for gradient descent to update the parameters and minimize the loss function. From data to model, a complete procedure for a machine to learn by itself.\n\nThere are still some more concepts that will be briefly explored in the next section. One further detail to mention about backpropagation is the fact that the derivations in this section were only made for the weights and biases parameters, what about possible others? There are many different types of additional parameters, but the idea with backpropagation is that the $\\delta$ values are already calculated for all the units in the network, any new parameter $\\theta$ must simply have a correlation with some of these values in order to obtain $\\partial J$ in terms of $\\partial\\theta$ and apply gradient descent for updates. Modern libraries and frameworks already abstract most of these calculations for the programmer via underlying procedures of automatic differentiation, for example, Tensorflow \\cite{tensorflow2015} provides a \\texttt{GradientTape} object to automatically watch and calculate the gradients for any desired parameter.\n", "meta": {"hexsha": "bd60e395a3875d80b11b83e7ad5dfd49a39ddeec", "size": 10093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Overleaf/chapters/NeuralNets/backprop.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/backprop.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/backprop.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": 84.1083333333, "max_line_length": 944, "alphanum_fraction": 0.7007827207, "num_tokens": 2797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6943692682879039}}
{"text": "\\subsection{Homology theory}\n\nLet's remind ourselves of the First Isomorphism Theorem\n\\begin{thm}\n(First Isomorphism Theorem) Let $G$, $H$ be groups, and let $\\phi:G\\to H$\nbe a homomorphism, then\\end{thm}\n\\begin{enumerate}\n\\item $\\text{Img}(\\phi)\\cong G/\\ker(\\phi)$,\n\\item $\\ker(\\psi)$ is a normal subgroup of $G$,\n\\item $\\text{Img}(\\psi)$ is a subgroup of $H$,\n\\end{enumerate}\nIn particular if $\\phi$ is onto (surjective) then $H\\cong G/\\ker(\\psi)$.\n\\begin{defn}\nThe standard $p$-simplex is \n\n\\begin{align*}\n\\Delta^{p} & =\\{(t_{0},\\dots,t_{p})\\in\\mathbb{R}^{p+1}\\mid t_{i}\\geqslant0,\\sum_{i}t_{i}=1\\}.\n\\end{align*}\n\n\\end{defn}\n\n\\begin{defn}\nLet $X$ be a topological space. A singular $p$-simplex is a continuous\nmap $\\sigma:\\Delta^{p}\\to X$.\n\\end{defn}\n\n\\begin{defn}\nA $p$-chain is denoted $C_{p}(X)=\\{\\text{singular \\ensuremath{p}-simplesx in \\ensuremath{X}}\\}=\\text{free Abelian group generated by all singular \\ensuremath{p}-simplexes in \\ensuremath{X}.}$\nSo a $p$-chain is a formal sum\n\n\\begin{align*}\nC_{p}(X)=\\sum_{i}n_{i}\\sigma_{i}\n\\end{align*}\n\n\nwhere each $\\sigma_{i}$ is a signular $p$-simplex in $X$ (and all\nbut finitely-many $n_{i}$ are $0$.)\n\\end{defn}\n\n\\begin{defn}\n(Boundaries)\n\nThe $i$th face map for the standard $p$-simplex is the affine map\n\n\\begin{align*}\n[e_{0},\\dots,\\hat{e}_{i},\\dots,e_{p}] & :\\Delta^{p-1}\\to\\Delta^{p}\n\\end{align*}\n\n\n(where the hat means we \\emph{omit} this vertex.) Let $\\sigma^{(i)}:\\Delta^{p-1}\\to X$\nbe given by\n\n\\begin{align*}\n\\sigma^{(i)} & =\\sigma\\circ[e_{0},\\dots,\\hat{e}_{i},\\dots,e_{p}]\n\\end{align*}\n\n\nthen defined the boundary of $\\sigma$, $\\partial\\sigma$ as\n\n\\begin{align*}\n\\partial\\sigma & =\\sum_{i=0}^{p}(-1)^{i}\\sigma^{(i)}\n\\end{align*}\n\n\nand we have $\\partial\\sigma\\in C_{p-1}(X)$. So extend by linearity\nto get a homeomorphism $\\partial=\\partial_{p}:C_{p}(X)\\to C_{p-1}(X)$.\nSay $C_{p}(X)=0$ for $p<0$, and that $\\partial\\sigma=0$ for an\nsingular $0$-chain.\\end{defn}\n\\begin{lem}\n$\\partial\\circ\\partial=0$. (Proof by linearity, doing the sums, separating\nand noting that they cancel.)\\end{lem}\n\\begin{defn}\nCycles and boundaries\\end{defn}\n\\begin{itemize}\n\\item $\\alpha\\in C_{p}(X)$ is a $p$-cycle if $\\partial\\alpha=0$.\n\\item $\\alpha$ is a $p$-boundary if $\\alpha=\\partial\\beta$ for $\\beta\\in C_{p+1}(X)$\n\\item Let $Z_{p}=\\{\\text{\\ensuremath{p}-cycles in \\ensuremath{X}}\\}=\\ker(\\partial_{p})$\n\\item $B_{p}(X)=\\{\\text{\\ensuremath{p}-boundaries in \\ensuremath{X}}\\}=\\text{Img}(\\partial_{p+1})$.\n\\end{itemize}\nThen $B_{p}(X)\\leq Z_{p}(X)$ (subgroup) since $\\partial\\circ\\partial=0$.\n\\begin{defn}\nThe $p$th singular homology group of $X$ is\n\n\\begin{align*}\nH_{P}(X) & =\\frac{Z_{p}(X)}{B_{p}(X)}\\\\\n & =\\frac{\\ker(\\partial_{p})}{\\text{Img}(\\partial_{p+1})}.\n\\end{align*}\n\n\nGeometrically, the elements of $H_{p}(X)$ are equivalence classes\nof $p$-cycles where $\\alpha\\sim\\alpha'$ if $\\alpha'=\\alpha+\\partial\\beta$,\n$\\beta\\in C_{p+1}(X)$. We write $[\\alpha]$ for the homology class\nof a $p$-cycle $\\alpha\\in C_{p}(X)$.\\end{defn}\n\\begin{lem}\nIf $\\{X_{\\alpha}\\}$ are the path connected components of $X$, then\n$C_{p}(X)=\\bigoplus_{\\alpha}C_{p}(X_{\\alpha})$ and $\\partial:C_{p}(X_{\\alpha})\\to C_{p-1}(X_{\\alpha})$,\nhence $H_{p}(X)=\\bigoplus_{\\alpha}H_{p}(X_{\\alpha})$.\\end{lem}\n\\begin{defn}\nThe singular chain complex of $X$\n\n\\begin{align*}\nC_{p}\\to C_{p-1}\\to\\dots\\to C_{0}\\to0\n\\end{align*}\n\n\nis a sequence of Abelian groups and homomorphisms such that $\\partial_{p-1}\\circ\\partial_{p}=0$.\\end{defn}\n\\begin{thm}\n(Interpretation of $H_{0}$)\n\nIf $X$ is non-empty and path connected, then $H_{0}(X)\\cong\\mathbb{Z}$.\\end{thm}\n\\begin{cor}\nIf $X$ has $k$ path components, then $H_{0}(X)\\cong\\mathbb{Z}^{k}$.\\end{cor}\n\\begin{thm}\n(Interpretation of $H_{1}$) If $X$ is path connected, $x_{0}\\in H$,\nthen $H_{1}(X)$ is the Abelianisation of $\\pi_{1}(X,x_{0})$.\n\\end{thm}\n\n\\subsubsection{Effects of continuous maps}\n\nIf $f:X\\to Y$ is continuous and $\\sigma:\\Delta^{p}\\to X$ is a singular\n$p$-simplex in $X$ then $f\\circ\\sigma:\\Delta^{p}\\to Y$ is a singular\n$p$-simplex in $Y$. Then there exists an induced homomorphism $f_{\\#}:C_{p}(X)\\to C_{p}(Y)$\nwith $f_{\\#}\\left(\\sum n_{i}\\sigma_{i}\\right)=\\sum n_{i}(f\\circ\\sigma_{i})$.\n\\begin{lem}\n$\\partial\\circ f_{\\#}=f_{\\#}\\circ\\partial$.\\end{lem}\n\\begin{thm}\nThere are induced homomorphisms $f_{*}=H_{p}(f):H_{p}(X)\\to H_{p}(Y)$,\nwhere $f_{*}([c])=[f_{\\#}c]$.\\end{thm}\n\\begin{cor}\nIf $f:X\\to Y$ is a homeomorphism, then $f_{*}:H_{p}(X)\\to H_{p}(Y)$\nis an isomorphism. Therefore $H_{p}$ are topological invariants.\n\\end{cor}\n\n\\subsubsection{Homotopy invariance of homology}\n\\begin{thm}\nIf $f,g$ are two homotopic maps $f,g:X\\to Y$, then $f_{*}=g_{*}:H_{p}(X)\\to H_{p}(Y),$\n$p\\geqslant0$.\\end{thm}\n\\begin{cor}\nIf $f:X\\to Y$ is a homotopy equivalence, then $f_{*}:H_{p}(X)\\to H_{p}(Y)$\nis an isomorphism.\\end{cor}\n\\begin{defn}\n(Simplicial homology)\n\nA $\\Delta$-complex is a topological space $X$ obtained from the\ndisjoint uninion of simplies, with ordered vertices glued together\nby affine homeomorphisms.\n\\end{defn}\nDefine $C_{n}=C_{n}^{\\Delta}(X)=\\left\\{ \\sum n_{i}\\sigma_{i}\\mid n_{i}\\in\\mathbb{Z},\\,\\sigma_{i}\\,\\text{geometric \\ensuremath{n}-simplices in \\ensuremath{X}}\\right\\} $.\nThen define $\\partial:C_{n}\\to C_{n-1}$ as before. Then we define\nsimplicial homology\n\n\\begin{align*}\nH_{n}^{\\Delta}(X) & =\\frac{\\ker(\\partial_{n})}{\\text{Img}(\\partial_{n+1})}\n\\end{align*}\n\n\\begin{thm}\nIf $X$ is a $\\Delta$-complex then $H_{n}^{\\Delta}(X)\\cong H_{n}(X)$.\n(I.e. ``simplicial homology'' = ``singular homology'').\\end{thm}\n\\begin{defn}\n(Reduced homology) If $X=\\emptyset$ then we can define an augmented\nsingular chain complex\n\n\\begin{align*}\n\\cdots\\to C_{n}\\to^{\\partial_{n}}\\partial_{n-1}\\to^{\\partial_{n-1}}\\cdots\\partial_{1}\\to^{\\partial_{1}}C_{0}\\to^{\\epsilon}\\mathbb{Z}\\to0\n\\end{align*}\n\n\nwhere we let $\\epsilon\\left(\\sum n_{x}x\\right)=\\sum n_{x}$. Now $\\tilde{H}_{n}(X)=0$\nif $X$ is contractible.\n\\end{defn}\n\n\\subsubsection{Exact sequences}\n\\begin{defn}\nA sequence (finite or infinite) of Abelian groups and homomorphisms\n\n\\begin{align*}\n\\xymatrix{\\cdots\\ar[r] & A_{n}\\ar[r]^{\\alpha_{n}} & A_{n-1}\\ar[r]^{\\alpha_{n-1}} & \\cdots}\n\\end{align*}\n\n\nis called \\emph{exact} if the image of each homomorphism is the kernal\nof the next. I.e. $\\text{Img}(\\alpha_{n})=\\ker(\\alpha_{n-1})$ $\\forall n$.\n\\end{defn}\n\n\\paragraph{Examples}\n\\begin{enumerate}\n\\item $0\\to A\\to^{f}B$ exact $\\Leftrightarrow\\ker(f)=\\{0\\}\\Leftrightarrow f$\nis 1-1 (injective)\n\\item $A\\to^{f}B\\to^{0}0$ exact $\\Leftrightarrow\\text{Img}(f)=\\ker(B)=0$\n$\\Leftrightarrow f$ is onto (surjective).\n\\item $0\\to^{0}A\\to^{f}B\\to^{0}0$ exact $\\Leftrightarrow$ $f$ is an isomorphism.\n\\item $0\\to^{0}A\\to^{f}B\\to^{g}C\\to^{0}0$ exact $\\Leftrightarrow$ $f$\nis 1-1, $g$ is onto, $C=\\text{Img}(g)\\cong B/\\ker(g)=B/\\text{Img}(f)$\\end{enumerate}\n\\begin{defn}\nA short exact sequence $0\\to A\\to^{f}B\\to^{g}C\\to0$ splits if there\nexists a homomorphism such that $g\\circ h=1_{C}$ ($h:C\\to B$). Then\n$B=f(A)\\oplus h(C)\\cong A\\oplus B$. The sequence splits if, for example,\n$C$ is a free Abelian group.\n\\end{defn}\n\n\n\n\\paragraph{Mayer-Vietoris sequence}\n\nAn analogue to SvK. Let $X=X_{1}\\cup X_{2}$ be a topological space,\nwhere $X_{1},X_{2},X_{0}=X_{1}\\cap X_{2}$ are open sets in $X$,\nthen we have inclusion maps\n\n\\begin{align*}\n\\xymatrix{ & X_{1}\\ar[dr]_{j_{1}}\\\\\nX_{0}\\ar[ur]^{i_{1}}\\ar[dr]_{i_{2}} &  & X\\\\\n & X_{2}\\ar[ur]_{j_{2}}\n}\n\\end{align*}\n\n\nthen we have\n\n\\begin{align*}\n\\xymatrix{ & H_{p}(X_{1})\\ar[dr]_{j_{1*}}\\\\\nH_{P}(X_{0})\\ar[ur]^{i_{1*}}\\ar[dr]_{i_{2*}} &  & H_{p}(X)\\\\\n & H_{p}(X_{2})\\ar[ur]_{j_{2*}}\n}\n\\end{align*}\n\n\\begin{thm}\n(Mayer-Vietoris theorem) There is a long exact sequence in Homology\n\n\\begin{align*}\n\\xymatrix{\\cdots\\ar[r] & H_{p}(X_{0})\\ar[r]^{i_{1*}\\oplus i_{2*}} & H_{p}(X_{1})\\oplus H_{p}(X_{2})\\ar[r]^{j_{1*}-j_{2*}} & H_{p}(X)\\ar[r]^{\\partial_{*}} & H_{p-1}(X_{0})}\n\\end{align*}\n\n\\end{thm}\n\n\nFrom this we can calculate the homotopy of the $n$-sphere as \n\n\\begin{align*}\n\\tilde{H}_{p}(S^{n}) & =\\begin{cases}\n\\mathbb{Z} & p=n\\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{align*}\n\n\\begin{thm}\n(Topological invariance of dimension) If $\\mathbb{R}^{n}\\approx\\mathbb{R}^{m}$,\nthen $n=m$. \\end{thm}\n\\begin{proof}\nIf $f:\\mathbb{R}^{n}\\to\\mathbb{R}^{m}$ is a homeomorphism then we\nalso have an induced homeomorphism $\\mathbb{R}^{n}-\\{pt\\}\\to\\mathbb{R}^{m}-\\{pt\\}$\nso we have a homotopy $S^{n-1}\\simeq S^{m-1}$ so $\\tilde{H}_{*}(S^{n-1})\\cong\\tilde{H}_{*}(S^{m-1})$\nso $n=m$.\\end{proof}\n\\begin{defn}\nA continous map $f:S^{n}\\to S^{n}$ has degree $d$ if $f_{*}=H_{n}(f):\\tilde{H}_{n}(S^{n})\\to\\tilde{H}_{n}(S^{n})$\nis multiplication be the integer $d$.\\end{defn}\n\\begin{rem}\n$f\\simeq g\\implies\\deg(f)=\\deg(g)$. $\\deg(f\\circ g)=\\deg(f)\\times\\deg(g)$.\\end{rem}\n\\begin{thm}\n(Subdivision theorem) Let $U=\\{U_{j}\\}$ be an open cover of $X$\n(or a collection of subsets of $X$ whose inteiors cover $X$.). Then\nlet $C_{p}^{U}(X)$ be the subgroup of $C_{p}(X)$ consisting of singular\n$p$-chains $\\sum n_{i}\\sigma_{i}$ such that the image $\\sigma_{i}(\\Delta^{p})$\nof each $\\sigma_{i}$ lies in one of the sets in $U$.\n\nThen $\\partial:C_{p}^{U}(X)\\to C_{p-1}^{U}(X)$, so we get a chain\ncomplex $C_{*}^{U}(X)$ with homology $H_{*}^{U}(X)$.\n\nThe inclusion $C_{*}^{U}(X)\\to C_{*}(U)$ induces an isomorphism $H_{p}^{U}(X)\\to H_{p}(X)$\nfor all $p$.\\end{thm}\n\\begin{defn}\n(Relative homotopy) Let $(X,A)$ be a pair of topological spaces with\n$A\\leq X$ ($A$ is a subspace.) The inclusion $A\\hookrightarrow X$\ninduces the inclusions $C_{p}(A)\\to C_{p}(X)$ for all $p$ and we\ncan define\n\n\\begin{align*}\nC_{p}(X,A) & =\\frac{C_{p}(X)}{C_{p}(A)}.\n\\end{align*}\n\n\\end{defn}\nThen $\\partial:C_{p}(X)\\to C_{p-1}(X)$ takes $C_{p}(A)\\to C_{p-1}(A)$\nso induces a homomorphism $\\bar{\\partial}:C_{p}(X,A)\\to C_{p-1}(X,A)$\nand $\\bar{\\partial}\\circ\\bar{\\partial}=0$. This gives a chain complex\nwith homology $H_{p}(X,A)=\\frac{\\ker(\\bar{\\partial}_{p})}{\\text{Img}(\\bar{\\partial}_{p+1})}$\ncalled the ``relative homology of $X$ mod $A$.''\n\n", "meta": {"hexsha": "8bed3cb3106b94d947f56bb37bb0ced5183c1e5b", "size": 9947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homology.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": "homology.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": "homology.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": 34.6585365854, "max_line_length": 191, "alphanum_fraction": 0.6422036795, "num_tokens": 4082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6943356942317246}}
{"text": "\\section{Multigrid methods for numerical PDEs}\\label{sec:mg}\n\n\nWith the restriction $R_{\\ell}^{\\ell+1}$ and prolongation $P_{\\ell+1}^\\ell$\nobtained in Lemma \\ref{ris:plon},\n%as defined in \\eqref{mg-prolong} and restriction $R_{\\ell}^{\\ell+1} = (P_{\\ell+1}^{\\ell})^T$. \nwe have the following relationship to define coarse operation\n\\begin{equation}\\label{eq:def_coarse}\nA^{\\ell+1}=R_{\\ell}^{\\ell+1} A^{\\ell}P_{\\ell+1}^{\\ell} \\quad (\\ell = 1:J-1),\n\\end{equation}\nwith $A^1 = A$. \nSimilarly, with the smoother obtained by \\eqref{eq:convS}, we can define \n$S^{\\ell}: \\mathbb{R}^{m_\\ell \\times n_\\ell} \\mapsto \\mathbb{R}^{m_\\ell \\times n_\\ell}$.\n\nNow using the smoother $S^\\ell$, prolongation $P^{\\ell}_{\\ell+1}$, restriction $R_{\\ell}^{\\ell+1}$ and mapping\n$A^\\ell$ as given in \\eqref{eq:def_coarse}, we can formulate the following algorithm\n as a major component of a multigrid algorithm.\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$(u^{\\ell,\\nu_\\ell}: ~\\ell = 1:J) = {\\text{MG0}}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-Slash0}\n\t\\begin{algorithmic}\n\t\t\\State Set up\n\t\t$$\n\t\tf^1 = f, \\quad u^{1,0}=0.\n\t\t$$\n\t\t\\State Smoothing and restriction from fine to coarse level (nested)\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\State Pre-smoothing:\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\tu^{\\ell,i} = u^{\\ell,i-1} + K_S \\ast (f^\\ell - K_A \\ast u^{\\ell,i-1}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Form restricted residual and set initial guess:\n\t\t$$\n\t\tu^{\\ell+1,0} = 0, \\quad f^{\\ell+1} = K_R \\ast_2 (f^\\ell -  K_A \\ast u^{\\ell,\\nu_\\ell}).\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nHere $K_S$ can be chosen as $K_{S_0}$ or $K_{S_1}$ as definition in \\eqref{eq:kernel-S} and \\eqref{eq:kernel-S2}.\n\nUsing the above algorithm, there are different multigrid algorithms such as: $\\backslash$-cycle, V-cycle and W-cycle.\nLet us now only give one special form of multigrid algorithm for solving \\eqref{laplace} or \\eqref{laplace-h} as follows.\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$u = {\\backslash\\text{-MG}}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-Slash1}\n\t\\begin{algorithmic}\n\t\t\\State Call Algorithm \\ref{alg:L-Slash0},\n\t\t$$\n\t\t(u^{\\ell,\\nu_\\ell}: ~\\ell = 1:J) = {\\text{MG0}}(f; J,\\nu_1, \\cdots, \\nu_J).\n\t\t$$\n\t\t\\State Prolongation and restriction from coarse to fine level\n\t\t\\For{$\\ell = J-1:1$}\n\t\t\\State\n\t\t$$\n\t\tu^{\\ell,\\nu_\\ell} \\leftarrow u^{\\ell,\\nu_\\ell} + K_R  \\ast_2^{\\top} u^{\\ell+1, \\nu_{\\ell+1}}.\n\t\t$$\n%\t\t%\t\t\\IF{V-cycle}\n%\t\t\\For{$i = 1:\\nu_\\ell$}\n%\t\t\\State\n%\t\t$$\n%\t\tu^{\\ell,i} \\leftarrow u^{\\ell,i-1} + [B^{\\ell,i}]^T (f^\\ell - A^{\\ell} u^{\\ell,i-1})\n%\t\t$$\n%\t\t\\EndFor\n%\t\t%\t\t\\ENDIF\n\t\t\\EndFor\n\t\t\\State Output\n\t\t$$\n\t\tu = u^{1,\\nu_\\ell}.\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n", "meta": {"hexsha": "7f01efb3e182ff2737d5af66842f20a05bccb63e", "size": 2719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MgNet_MGintro.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/MgNet_MGintro.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/MgNet_MGintro.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7763157895, "max_line_length": 121, "alphanum_fraction": 0.6325855094, "num_tokens": 1133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.6943356928211304}}
{"text": "%&LaTeX\n\n\\section{Signals in the Computer}\n\nIn this lab, you will use JDSP to explore how a physical signal can\nbe considered to be composed of a sum of sinusoids --- its\n\\emph{Fourier series}. You will then investigate how capturing this\nsignal for computer use --- sampling and quantization --- modifies the\nsignal. Finally, you will see how the choices you make in the\nparameters for sampling and quantization affect the quality of the\ndigitized, computer signal. \n\n\n\n\\subsection{Fourier series representation of a physical signal}\n\tIn this section, you will use the  \\block{Cont Sig} block in J-DSP to simulate a analog signal \n\tgenerator. The \\block{Cont \n\tSig} block is capable of simulating analog signals of varying frequency content. \n\t\n\t% Block diagram, step 1\n\t\\begin{figure}[b]\n\t  \\begin{center}\n\t    \\includegraphics[height=1.5in]{lab3/block_diagram_step1}\n\t  \\end{center}\n\t\\caption{ A J-DSP diagram for summing and plotting analog sine waves (left) and a single \n\ttriangle wave (right). \n\t\\label{fg:step1}}\n\t\\end{figure}\n\n\\paragraph{Step 1.1} Create a J-DSP diagram that sums together four continuous time sinusoids \n\tand plots their sum. Use the ``Analog Blocks'' function set and the \\block{Adder} block only (See \n\tFigure \\ref{fg:step1}). Also create a separate set of blocks that plots a continuous time triangle \n\twave at a \\option{frequency} of 200 Hz and \\option{amplitude} of 1. In the next section you will \n\tsimulate this triangle wave using the sum of sinusoids.\n\n\\paragraph{Step 1.2} Recall that any periodic signal can be represented as a sum of harmonic \n\tsinusoids. The amplitude of each harmonic is known as the Fourier Series. It may at first seem\n\tlike sums of sinusoids would be poor approximations of real periodic signals, but this is not \n\tthe case. We\n \tcan illustrate this using a triangle wave. The formula for synthesis of a triangle wave with \n\tfrequency $\\omega_0$ is a sum of harmonically related sine waves (its Fourier series):\n\t\\[\n\tx(t) = \\sum_{k=0}^{\\infty}\n\t\\left( \n\t\\underbrace{ \\frac{8}{\\pi^2} \\frac{(-1)^k}{(2k+ 1)^2} }_{ \\text{amplitude} } \n\t\\underbrace{ \\sin((2k+1)\\omega_0 t) }_{ (2k+1)^{th}\\text{ harmonic} } \n\t\\right)\n\t\\]\n\tIn this case, in the analog domain, we are dealing with frequencies in\n\tHz, and so $\\omega_0 = 2\\pi f_0$. Notice that the Fourier Series of the triangle wave only uses \n\todd harmonics (i.e., the only non-zero frequencies are $(2k+1)\\omega_0=\\omega_0, 3\\omega_0, \n\t5\\omega_0 \\cdots$). Also notice that resulting wave will be zero mean because there is no ``DC'' \n\tterm (i.e., $2k+1 \\neq 0$ for any integer k). \n\tUse your diagram from Step 1.1 to generate and sum the\n\tfirst 7 harmonics of the Fourier Series of a triangle wave and plot the resultant signal (i.e., use \n\t$f_0$, $2f_0$, $3f_0$, $\\cdots 7f_0$, where $f_0=$200 Hz). How does this signal compare to \n\tthe triangle wave computed directly in \\block{Cont. Sig}?\n\t\n\n\\paragraph{Step 1.3} Another way to view a signal is in the \\emph{frequency domain}. For a \n\tsignal expressed in terms of its Fourier Series, the \\emph{frequency domain} representation\n\tis merely the coefficients of the harmonics. Use your favorite spreadsheet or plotting tool to \n\tcompute and plot \n\tthe spectrum of a triangle wave.  Note that you are \\emph{not} being asked to plot the triangle \n\twave as a function of time; you should plot the amplitudes of the Fourier Series as a \n\tfunction of the harmonics' frequencies (like the vertical lines in textbook figure~1.12).  \n\t\n\n\n\\subsection{Sampling}\n\nThe first step in digitization is \\emph{sample and hold}, in which the\ncontinuous analog signal is converted to a \\textit{discrete-time}\nanalog signal (an analog signal that only changes its value at\nparticular points in time). You will use the \\block{Sample-Hold} block\nin J-DSP to simulate this.\n\n% Block diagram, step 2\n\\begin{figure}[h]\n  \\begin{center}\n    \\includegraphics[height=1.5in]{lab3/block_diagram_step2}\n  \\end{center}\n  \\caption{ A J-DSP diagram for investigating sampling rate. \\label{fg:step2}}\n\\end{figure}\n\n\\paragraph{Step 2.1} Create an \\block{Cont Sig} sine waveform ranging\nfrom -5 to 5V with a frequency of 200Hz (Figure \\ref{fg:step2},\nleftmost block).\n\n\\paragraph{Step 2.2} Use four \\block{Sample-Hold} blocks to sample\nthis signal at 300Hz, 500Hz, 1000Hz and 2000Hz. Plot the original and\nall four sampled signals separately (Figure \\ref{fg:step2}). Clearly,\nthe results are not the same, and none look identical to the original\nsine wave. What are the two essential pieces of information about a\nsine wave that need to be preserved when sampling it?  Does it appear\nthat all sampled versions are equally useful in achieving this? Why or\nwhy not (in other words, your answer to this question should not be\njust ``yes'' or ``no'')?\n\n\n\\subsection{Analog to Digital Conversion}\n\n\tThe last step of digitization is called ``analog to digital conversion,'' or \\emph{quantization}. In \n\tthis step, the sampled analog signal is converted to a discrete signal, with values represented \n\tby $b$ bit integers. We will use the \\block{Quantizer} block under the ``Statistical DSP'' function \n\tset to perform this conversion.\n\t\n\t% Block diagram, step 3\n\t\\begin{figure}[h]\n\t  \\begin{center}\n\t    \\includegraphics[width=5.0in]{lab3/block_diagram_step3}\n\t  \\end{center}\n\t\\caption{ A J-DSP diagram for investigating quantization error and calculating SNR. \n\t\\label{fg:step3}}\n\t\\end{figure}\n\n\\paragraph{Step 3.1} Next we will be using the \\block{SNR} block under the ``Basic Blocks'' \n\tfunction set to compute signal-to-noise ratio (SNR) as a result of quantization. Place the \n\t\\block{SNR} block and open the dialog associated with it. You will see the equations used to \n\tcalculate the numerator and denominator. In your own words, what quantity is calculated in the \n\tnumerator and what quantity is calculated in the denominator of this ratio (Hint: can you \n\tdescribe the values in terms of \\emph{root mean square} (RMS) values)? Note that this SNR is \n\tdifferent than what we did in the textbook, because we are now doing the computation for a \n\t\\textit{specific} signal, not just figuring SNR for a possible \\textit{range} of signal values.\n\t\n\n\\paragraph{Step 3.2} Use the J-DSP diagram in Figure \\ref{fg:step3} to compute the SNR for a \n\tquantized sinusoid. Use the \\block{SigGen} block with a ``amplitude'' of 5, ``frequency'' of 0.05$\n\t\\pi$, and ``Pulsewidth'' of 256. Use 2, 4, 8, 12, and 16 bits quantization. Use your favorite \n\tspreadsheet or plotting software to plot SNR versus number of quantization bits (i.e., a scatter \n\tplot). Use the output of \\block{SigGen} as reference for the \\block{SNR} block. \n\n\\paragraph{Step 3.3} Plot the quantization error by using the \\block{Adder} block (bottom right \n\tblocks of Figure \\ref{fg:step3}). Set the \\block{Adder} block to ``subtract'' by opening the dialog \n\tand switching the ``$+$'' sign to ``$-$.'' You only need to include the quantization error plot for \n\t``4 bits'' in your report (but be sure to view the error plots for all quantization levels).\n\n\\paragraph{Step 3.4} Repeat Step 3.2 using a triangle waveform with ``Gain'' of 5 and \n\t``Pulsewidth'' of 256. \n\n\\paragraph{Step 3.5} As you double the number of bits used in quantization, how does the SNR \n\tchange? Refer to specific features of your plots from Steps~3.2--3.4 to justify your answer. \n\t\n\n% LocalWords:  WebQ MATLAB\n", "meta": {"hexsha": "d758d132a868552c117176c9c761f3c2fc3521ad", "size": 7367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "J-DSP Labs/lab3/lab3.tex", "max_stars_repo_name": "stiber/Signal-Computing", "max_stars_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-09-10T16:54:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T15:48:26.000Z", "max_issues_repo_path": "J-DSP Labs/lab3/lab3.tex", "max_issues_repo_name": "stiber/Signal-Computing", "max_issues_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2015-08-18T18:16:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-29T17:19:16.000Z", "max_forks_repo_path": "J-DSP Labs/lab3/lab3.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": 50.4589041096, "max_line_length": 102, "alphanum_fraction": 0.7453508891, "num_tokens": 2048, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085859124002, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.694243640638227}}
{"text": " \\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n\\setlength{\\parindent}{0in}\n\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{latexsym,amsfonts,amssymb,amsthm,amsmath}\n\\usepackage {tikz}\n\\usetikzlibrary {positioning}\n\\usetikzlibrary{quantikz}\n\n\\usepackage{braket}\n\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\title{Quantum Computing - Assignment 1}\n\\author{Kishlaya Jaiswal}\n\n\\begin{document}\n\n\\maketitle\n\n\n\\subsection*{Exercise 1}\n\\begin{proof}\nObserve that\n$$\\norm{ \\ket{\\psi} }^2 = \\braket{\\psi|\\psi} = \\big(\\ket{\\psi}\\big)^{\\dag} \\big(\\ket{\\psi}\\big)$$\n$U$ is unitary that is $U^{\\dag} U = I$, and hence\n$$\\norm{ U\\ket{\\psi} }^2 = \\big(U\\ket{\\psi}\\big)^{\\dag} \\big(U\\ket{\\psi}\\big) = \\bra{\\psi} U^\\dag U \\ket{\\psi} = \\bra{\\psi} I \\ket{\\psi} = \\braket{\\psi|\\psi} = \\norm{ \\ket{\\psi} }^2$$\n\nSince $\\norm{.} \\geq 0 \\implies \\norm{ U\\ket{\\psi} } = \\norm{ \\ket{\\psi} }$\n\\end{proof}\n\n\n\\subsection*{Exercise 2}\n\\begin{proof}\n\\begin{align*}\n    [X,Z] \\ket{0} &= (XZ-ZX) \\ket{0} = X\\ket{0} - Z\\ket{1} = \\ket{1} + \\ket{1} = 2 \\ket{1} \\\\\n    [X,Z] \\ket{1} &= (XZ-ZX) \\ket{1} = -X\\ket{1} - Z\\ket{0} = -\\ket{0} - \\ket{0} = -2 \\ket{0}\n\\end{align*}\n\nHence $[X,Z] = \\begin{pmatrix} 0 & -2 \\\\ 2 & 0\\end{pmatrix}$\n\\end{proof}\n\n\n\\subsection*{Exercise 3}\n\\begin{proof}\n$$X = \\begin{pmatrix}0 & 1 \\\\ 1 & 0\\end{pmatrix} \\implies X^\\dag = \\begin{pmatrix}0 & 1 \\\\ 1 & 0\\end{pmatrix} = X \\text{ and } X^\\dag X = \\begin{pmatrix}0 & 1 \\\\ 1 & 0\\end{pmatrix}\\begin{pmatrix}0 & 1 \\\\ 1 & 0\\end{pmatrix} = \\begin{pmatrix}1 & 0 \\\\ 0 & 1\\end{pmatrix} = I$$\n$$Y = \\begin{pmatrix}0 & -i \\\\ i & 0\\end{pmatrix} \\implies Y^\\dag = \\begin{pmatrix}0 & -i \\\\ i & 0\\end{pmatrix} = Y \\text{ and } Y^\\dag Y = \\begin{pmatrix}0 & -i \\\\ i & 0\\end{pmatrix}\\begin{pmatrix}0 & -i \\\\ i & 0\\end{pmatrix} = \\begin{pmatrix}1 & 0 \\\\ 0 & 1\\end{pmatrix} = I$$\n$$Z = \\begin{pmatrix}1 & 0 \\\\ 0 & -1\\end{pmatrix} \\implies Z^\\dag = \\begin{pmatrix}1 & 0 \\\\ 0 & -1\\end{pmatrix} = Z \\text{ and } Z^\\dag Z = \\begin{pmatrix}1 & 0 \\\\ 0 & -1\\end{pmatrix}\\begin{pmatrix}1 & 0 \\\\ 0 & -1\\end{pmatrix} = \\begin{pmatrix}1 & 0 \\\\ 0 & 1\\end{pmatrix} = I$$\n\nThus Pauli matrices are Hermitian and Unitary. And,\n\n% Suppose $A$ is any Hermitian matrix, then for any non-zero eigenvector $v$ with eigenvalue $\\lambda$: \n% $$\\bar\\lambda \\braket{v, v} = \\braket{\\lambda v, v} = \\braket{Av, v} = \\braket{v, A^\\dag v} = \\braket{v, Av} = \\braket{v, \\lambda v} = \\lambda \\braket{v, v}$$\n% So, eigenvalues of Hermitian matrices are real. \n\n% Suppose $A$ is any Unitary matrix, then for any non-zero eigenvector $v$ with eigenvalue $\\lambda$: \n% $$\\bar \\lambda \\braket{v, Av} = \\braket{\\lambda v, Av} = \\braket{Av, Av} = \\braket{v, A^\\dag A v} = \\braket{v, v}$$\n\n% But $\\bar \\lambda \\braket{v, Av} = \\lambda\\bar \\lambda \\braket{v, v}$ and hence $|\\lambda|^2 = 1$. So eigenvalues of Unitary matrices lie on the unit circle.\n\n% Since the only real numbers satisfying $|\\lambda|^2 = 1$ are $\\pm 1$, so only possible eigenvalues of Pauli matrices are $\\pm 1$ and in particular\n\n$$X\\begin{pmatrix}1/\\sqrt{2} \\\\ 1/\\sqrt{2}\\end{pmatrix} = \\begin{pmatrix}1/\\sqrt{2} \\\\ 1/\\sqrt{2}\\end{pmatrix}, X\\begin{pmatrix}1/\\sqrt{2} \\\\ -1/\\sqrt{2}\\end{pmatrix} = - \\begin{pmatrix}1/\\sqrt{2} \\\\ -1/\\sqrt{2}\\end{pmatrix}$$\n\n$$Y\\begin{pmatrix}1/\\sqrt{2} \\\\ i/\\sqrt{2}\\end{pmatrix} = \\begin{pmatrix}1/\\sqrt{2} \\\\ i/\\sqrt{2}\\end{pmatrix}, Y\\begin{pmatrix}1/\\sqrt{2} \\\\ -i/\\sqrt{2}\\end{pmatrix} = -\\begin{pmatrix}1/\\sqrt{2} \\\\ -i/\\sqrt{2}\\end{pmatrix}$$\n\n$$Z\\begin{pmatrix}1 \\\\ 0\\end{pmatrix} = \\begin{pmatrix}1 \\\\ 0\\end{pmatrix}, Z\\begin{pmatrix}0 \\\\ 1\\end{pmatrix} = -\\begin{pmatrix}0 \\\\ 1\\end{pmatrix}$$\n\\end{proof}\n\nThus the eigenvalues are of Pauli matrices are $\\pm 1$.\n\n\\subsection*{Exercise 4}\n\\begin{proof}\n\\begin{align*}\n  HXH \\ket{0} &= HX \\ket{+} = H \\ket{+} = \\ket{0}  \\\\\n  HXH \\ket{1} &= HX \\ket{-} = H (-\\ket{-}) = -\\ket{1}\n\\end{align*}\nAnd hence $HXH = Z$\n\n\\begin{align*}\n  HZH \\ket{0} &= HZ \\ket{+} = H \\ket{-} = \\ket{1} \\\\  \n  HZH \\ket{1} &= HZ \\ket{-} = H \\ket{+} = \\ket{0}\n\\end{align*}\nAnd hence $HZH = X$\n\\end{proof}\n\n\n\\subsection*{Exercise 5}\n\\begin{proof}\nFrom the above exercise $3$, we know that $\\ket{+}$ is an eigenvector of $X$ with eigenvalue $1$ and $\\ket{-}$ is an eigenvector of $X$ with eigenvalue $-1$, that is $X = \\ket{+}\\bra{+} - \\ket{-}\\bra{-}$\n\nHence $\\{\\ket+ \\bra+, \\ket- \\bra-\\}$ is an eigenbasis for $X$ and so $\\ket+ \\bra+$ and $\\ket- \\bra-$ are the measurement operators corresponding to a measurement of $X$ observable.\n\\end{proof}\n\n\n\\subsection*{Exercise 6}\n\\begin{proof}\nFirst we check that $\\frac{1}{\\sqrt{2}}\\big(\\ket{00} + \\ket{11}\\big) = \\frac{1}{\\sqrt{2}}\\big(\\ket{++} + \\ket{--}\\big)$ indeed.\n\n\\begin{align*}\n    \\ket{++} + \\ket{--} &= \\frac{1}{2}(\\ket0 + \\ket1)(\\ket0 + \\ket 1) + \\frac{1}{2}(\\ket0 - \\ket1)(\\ket0 - \\ket 1) \\\\ \n    &= \\frac12 (\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} + \\ket{00} - \\ket{01} - \\ket{10} + \\ket{11}) = \\ket{00} + \\ket{11}\n\\end{align*}\n\nSo it suffices to show that $\\frac{1}{\\sqrt{2}}\\big( \\ket{00} + \\ket{11}\\big)$ is an entangled state. \\\\\n\nSuppose not and so it can be written as $\\ket{\\psi} \\otimes \\ket{\\phi}$ where $\\ket{\\psi} = \\alpha \\ket0 + \\beta \\ket1$ and $\\ket\\phi = \\gamma \\ket0 + \\delta \\ket1$.\n\nThen $\\ket{\\psi} \\otimes \\ket{\\phi} = \\alpha \\gamma \\ket{00} + \\alpha \\delta \\ket{01} + \\beta \\gamma \\ket{10} + \\beta \\delta \\ket{11} = \\frac{1}{\\sqrt{2}}\\big(\\ket{00} + \\ket{11}\\big)$ \\\\\n\nSince $\\{\\ket{00}, \\ket{01}, \\ket{10}, \\ket{11}\\}$ is a linearly independent set in $\\mathbb{C}^4$, we get $\\alpha \\delta = \\beta \\gamma = 0$ and $\\alpha \\gamma = \\beta \\delta \\neq 0$ whose solution doesn't exist. Hence $\\frac{1}{\\sqrt{2}}\\big(\\ket{00} + \\ket{11}\\big)$ is an entangled state.\n\\end{proof}\n\n\n\\subsection*{Exercise 7}\n\\begin{center}\n\\begin{quantikz}\n\\lstick{$\\ket{0}$} & \\gate{H} & \\ctrl{1} & \\qw \\rstick[wires=2]{$\\ket\\phi$} \\\\\n\\lstick{$\\ket{0}$} & \\qw & \\targ{} & \\qw \n\\end{quantikz}\n\\end{center}\n\n\\begin{proof}\nWe start with $\\ket\\psi = \\ket{00}$ state.\\\\\n\n\nApplying $H \\otimes I$ to $\\ket\\psi$, we get $\\frac{1}{\\sqrt2}\\big(\\ket0 + \\ket1\\big)\\ket0 = \\frac{1}{\\sqrt2}\\big(\\ket{00} + \\ket{10}\\big)$\\\\\n\n\nApplying controlled-NOT gate (where first qubit is the control and second qubit is target) to this, we finally get $\\ket\\phi = \\frac{1}{\\sqrt2}\\big(\\ket{00} + \\ket{11}\\big)$ as required.\n\\end{proof}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "85ba5cb928d70fe4febadb269063d4e19140ba8a", "size": 6316, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "quantum_computing/assign1_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/assign1_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/assign1_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": 45.768115942, "max_line_length": 292, "alphanum_fraction": 0.6041798607, "num_tokens": 2652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959545, "lm_q2_score": 0.8670357666736773, "lm_q1q2_score": 0.6942286039067476}}
{"text": "\\section{Dual Averaging}\nIn this section, we introduce Nesterov's method of dual averaging. In order to best explain where this method comes from,\nwe first start with a different perspective on subgradient descent. We note that the subgradient descent iteration\n(\\ref{subgradient_descent_variable}) (with $x_1 = 0$) can also be written as\n\\begin{equation}\\label{minimizing_subgradient_descent}\n x_{n+1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x\\rangle + \\frac{1}{2}\\|x\\|_2^2\\right)\n\\end{equation}\n\nThis can easily be proven by induction on $n$ and we leave this as an exercise. The above minimization problem\ncan be rewritten as\n\\begin{equation}\n x_{n+1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^ns_i(f(x_i) + \\langle g_i, x - x_i\\rangle) + \\frac{1}{2}\\|x\\|_2^2\\right)\n\\end{equation}\nand we note that the terms $f(x_i) + \\langle g_i, x - x_i\\rangle$ are lower bounds on the objective $f$. Thus, the next iterate\ncan be obtained by optimizing an average of these lower bounds (with weights $s_i$) plus a regularization term which is a multiple\nof $\\|x\\|_2^2$.\n\nIn the previous section we set $s_i = \\frac{1}{\\sqrt{i}}$. This means that we are giving more weight to the bounds coming from\nearlier iterates, which is odd. The starting point for Nesterov's dual averaging method is to ask whether we can change the\nweights $s_i$. It turns out that we can, but in order to do this we must weight the regularization term differently as well.\n\nWe thus modify (\\ref{minimizing_subgradient_descent}) and consider methods of the form\n\\begin{equation}\\label{generalized_dual_averaging}\n x_{n+1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x\\|_2^2\\right)\n\\end{equation}\nwhere the sequences $s_i,\\alpha_i > 0$ are parameters (and $g_i\\in \\partial f(x_i)$ as before).\n\nWe obtain the following convergence result for the dual averaging method as a consequence of the definition (\\ref{generalized_dual_averaging}).\n\\begin{theorem}\\label{dual_averaging_theorem}\n Assume that $f$ is convex and Lipschitz with constant $M$, i.e. $\\|g\\|_2\\leq M$ for $g\\in \\partial f(x)$. Let \n $x^*\\in \\arg\\min_x f(x)$.\n \n Then if the sequence $x_i$ is given by (\\ref{generalized_dual_averaging}) (note in particular that this means that\n $x_1 = 0$) with $\\alpha_i \\leq \\alpha_{i+1}$, we have\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{2}\\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1} \\left(\\alpha_n\\|x^*\\|_2^2 + M\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\\right)\n \\end{equation}\n where $\\bar{x}_n = (\\sum_{i = 1}^n s_i)^{-1}\\sum_{i = 1}^n s_ix_i$ is a weighted average of the iterates with weights $s_i$.\n We also have\n \\begin{equation}\n  \\min_{i = 1,...,n} f(x_i) - f(x^*) \\leq \\frac{1}{2}\\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1} \\left(\\alpha_n\\|x^*\\|_2^2 + M\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\\right)\n \\end{equation}\n\n\\end{theorem}\n\\begin{proof}\n We begin by noting that by convexity we have\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1}\\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*))\n \\end{equation}\n and since the minimum is smaller than the average we have\n \\begin{equation}\n  \\min_{i = 1,...,n} f(x_i) - f(x^*) \\leq \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1}\\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*))\n \\end{equation}\n Thus it suffices to prove that\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) \\leq \\frac{1}{2}\\left(\\alpha_n\\|x^*\\|_2^2 + M\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\\right)\n \\end{equation}\n For this we first use the subgradient property to get\n \\begin{equation}\\label{eq_dual_averaging_59}\n  \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) \\leq \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x_i - x^*\\rangle\n \\end{equation}\n and rewrite this sum as follows\n \\begin{equation}\\label{eq_dual_averaging_63}\n  \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x_i - x^*\\rangle = \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x_n - x^*\\rangle\n  + \\displaystyle\\sum_{i = 1}^{n-1} \\displaystyle\\sum_{j = 1}^i\\langle s_jg_j, x_i - x_{i+1}\\rangle \n \\end{equation}\n We proceed by bounding the term\n \\begin{equation}\n  \\sum_{j = 1}^i\\langle s_jg_j, x_i - z\\rangle\n \\end{equation}\n Recall from (\\ref{generalized_dual_averaging}) that $x_i = \\arg\\min_x f_i(x)$ where\n \\begin{equation}\n  f_i(x) = \\displaystyle\\sum_{j = 1}^{i-1} \\langle s_jg_j, x\\rangle + \\frac{\\alpha_{i}}{2}\\|x\\|_2^2\n \\end{equation}\n This means that $0\\in\\partial f_i(x_i)$ and thus, defining \n $$f_i^\\prime(x) = f_i(x) + \\langle s_ig_i, x\\rangle$$ \n we see that $s_ig_i\\in \\partial f_i^\\prime(x_i)$. Moreover, $f_i^\\prime$ is strongly convex with convexity parameter\n $\\alpha_i$, which implies that\n $$f_i^\\prime(x_i) \\leq f_i^\\prime(z) + \\frac{1}{2\\alpha_i}\\|s_ig_i\\|_2^2\n $$\n Using the definition of $f_i^\\prime$ and rearranging, this gives\n \\begin{equation}\n  \\sum_{j = 1}^i\\langle s_jg_j, x_i - z\\rangle \\leq \\frac{\\alpha_i}{2}(\\|z\\|_2^2 - \\|x_i\\|_2^2) + \\frac{s_i^2}{2\\alpha_i}\\|g_i\\|_2^2\n \\end{equation}\n Pluggin this into (\\ref{eq_dual_averaging_63}) with $z = x_{i+1}$ and $z = x^*$, we obtain (recalling that $x_1 = 0$ and\n $\\|g_i\\|_2 \\leq M$)\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x_i - x^*\\rangle \\leq \\frac{\\alpha_n}{2}\\|x^*\\|_2^2 \n  + \\frac{1}{2}\\displaystyle\\sum_{i = 2}^n (\\alpha_{i-1} - \\alpha_i)\\|x_i\\|_2^2 + \\frac{M}{2}\\displaystyle\\sum_{i = 2}^n \\frac{s_i^2}{\\alpha_i}\n \\end{equation}\n Now we use the assumption that $\\alpha_i$ is an non-decreasing sequence, i.e. $$\\alpha_{i-1} - \\alpha_i \\leq 0$$ to see that\n the middle sum above is negative. Combining this with (\\ref{eq_dual_averaging_59}) we see that\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) \\leq \\frac{1}{2}\\left(\\alpha_n\\|x^*\\|_2^2 + M\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\\right)\n \\end{equation}\n which completes the proof.\n\n\\end{proof}\n\nWe conclude this section by noting several consequences of this theorem. First, the choice $s_i = \\frac{1}{\\sqrt{i}}$\nand $\\alpha_i = 1$ recovers subgradient descent. For this choice of $s_i$ and $\\alpha_i$\n$$\\displaystyle\\sum_{i = 1}^n s_i = O(\\sqrt{n})\n$$\nand\n$$\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i} = O(\\log(n))\n$$\nand we obtain the bound from Theorem \\ref{variable_subgradient_descent_thm}. \n\nWe can remove the logarithmic factor by\nshifting the weights $s_i$ to the more recent iterates. For example, if we set $s_i = 1$ and $\\alpha_i = \\sqrt{i}$,\nwe recover the dual averaging method originally proposed by Nesterov, for which we have\n$$\\displaystyle\\sum_{i = 1}^n s_i = n\n$$\nand\n$$\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i} = O(\\sqrt{n})\n$$\nwhich removes the logarithmic factor we had for subgradient descent. \n\nOther choices are also reasonable, for example we could\nset $s_n = n^c$ and $\\alpha_n = n^{c + (1/2)}$ for any $c \\geq -(1/2)$. As long as $c > -(1/2)$ we obtain the same convergence\nrate up to a constant, if $c = (1/2)$, then we recover subgradient descent which introduces a logarithmic factor.\n\nNext, we address the issue of scaling. If we scale the sequences $s_i$ and $\\alpha_i$ by the same (positive) factor,\nthen both the bound in Theorem \\ref{dual_averaging_theorem} and the method (\\ref{generalized_dual_averaging}) don't change.\nHowever, scaling one sequence and not the other has the effect of changing the `step size' of the method, and \nchanges the relative importance of the initial distance to the optimum $\\|x^*\\|_2^2$ and the Lipschitz constant $M$ in the\nour bound.\n\nFinally, we address the issue of setting the initial iterate to $0$. This is done solely out of notational convenience. In particular,\nif we change the regularization term $\\|x\\|_2^2$ to $\\|x - x_1\\|_2^2$, our analysis is unchanged. In fact, we can replace the \n$2$-norm regularizer by any strongly convex function, as the reader can easily verify. This is an important point which we\nwill use in a later section to extend these methods to the Banach space setting.\n", "meta": {"hexsha": "51a8a52c218ff56cbc513e10736a3b515a9d0b75", "size": 8032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DualAveraging.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/DualAveraging.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/DualAveraging.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.3909774436, "max_line_length": 189, "alphanum_fraction": 0.6998256972, "num_tokens": 2852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6942286018449435}}
{"text": "\n\\input{SingleAssignmentSetup.tex}\n\\input{../WeekTitles.tex}\n\\begin{document}\n\n\\begin{center}\n\\subsection*{MNTC P01 - Week \\#8 - \\WeekTitleEight}\n\\end{center}\n\n\\newcommand{\\Fext}{  F_{\\mbox{ext}} }\n\\newcommand{\\Fspring}{  F_{\\mbox{spring}} }\n\\newcommand{\\Fdamping}{  F_{\\mbox{damp}} }\n\n\\begin{enumerate}\n\n% ******************************\n\\item \n  \\begin{Question}\n    Use \\verb@ode45@ to generate a graph of the solution to the\n    following DEs, over the specified interval, given the initial\n    condition.\n\n\\begin{enumerate}\n\\item $\\ds \\frac{dy}{dt} = t^2 + y^2$, $y(0) = 0$, and $0 \\le t \\le 1$.\n\\item $\\ds \\frac{dy}{dt} = \\sin(t) + \\cos(y)$, $y(0) = 0$, and $0 \\le t \\le 10$.\n\\item $\\ds \\frac{dy}{dt} = (1-y^2) + 0.2 \\sin(t)$, $y(0) = 0$, and $0 \\le t \\le 20$.\n\\end{enumerate}\n\\end{Question}\n\n\\begin{Solution}\nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08DE01.m}{W08DE01.m}\n\nHere are the graphs of the solutions.\n\n\\includegraphics[width = 0.3\\linewidth]{graphics/Week08_DESolutions/W08DE01_a} \n\\includegraphics[width = 0.3\\linewidth]{graphics/Week08_DESolutions/W08DE01_b} \n\\includegraphics[width = 0.3\\linewidth]{graphics/Week08_DESolutions/W08DE01_c} \n\n\\end{Solution} \n\n% ******************** Newton's Cooling  ********************************\n\\item \n\\begin{Question}\nNewton's law of heating and cooling states that an object with\n  temperature $T$ in an environment at temperature $T_{ext}$ will heat\n  up or cool down according to the differential equation\n\n $$\\frac{dT}{dt} = -k (T - T_{ext})$$\n\n Consider a garage used as a workshop.  Its insulation and surface\n area give $k$ a value of 0.1, if time $t$ is measured in hours and\n the temperatures, $T$ and $T_{ext}$, are in degrees Celsius.\n\nThe temperature outside changes during the day, as described by\nthe formula \n$$T_{ext} =  10 + 7 \\cos\\left(\\frac{\\pi}{12} t\\right)$$\n\nWe now imagine that the power goes out, with the garage at 23$^o$ C at\n$t=0$.\n\n\\begin{enumerate}\n\\item Use ode45 and the DE to generate a numerical prediction of the\n  garage's temperature $T$ over time.  Graph the solution over a time\n  interval that shows both the initial and long-term behaviour of the\n  temperature.\n\n  In your script, try to use the functions \\verb#title#,\n  \\verb#xlabel#, \\verb#ylabel#, and \\verb#legend# to annotate the\n  graph to make it easier for a reader to understand.\n\n  For the following questions, just use the graph or the numerical\n  prediction of the temperature. You are {\\em not} expected to solve\n  the DE analytically.\n\n\\item How many days does it take for the garage to get into a\n  consistent temperature cycle?  (You will need to estimate this by\n  eye.)\n\n\\item How many degrees does the temperature in the building fluctuate\n  by, once the temperature gets into a steady cycle?\n\n\\item Suppose the building were better insulated, so that the rate of\n  heat loss were cut in half.  Should $k$ be half as large, or twice\n  as large?  \n\n\\item Generate a numerical prediction for the temperature over time in\n  the better-insulated scenario, and produce a graph of the\n  temperature vs time for both scenarios on the same axes.\n  \n\\item How large are the temperature fluctuations in the building, now\n  that the extra insulation has been added?  Does halving the net heat\n  flow also halve the net temperature fluctuations?\n\\end{enumerate}\n  \n\\end{Question}\n\n\\begin{Solution}\n\\begin{enumerate}\n\\item  A graph of the temperature over time is shown below: \n  \n  \\includegraphics[width=3in]{graphics/Week08_Spring/W08GarageTemp_1}\n\nThe file \n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08GarageTemp.m}{W08GarageTemp.m} \nhas the MATLAB code that generated the graph above.\n\n\\item From the graph, it takes the building roughly 2 days (48 hours)\n  to get into a repeating cycle of temperature variation.\n\n\\item Careful zooming of the graph (or a look at the $y$ values in the\n  ode45 output) give a highest temperature of 12.5 (high) and 7.5\n  (low), for a net fluctuation of approximately 2.6 degrees per day.\n\n\\item $k$ represents the coefficient of heat flow between the building\n  and the environment. The bigger $k$ is, the {\\em larger} the\n  headflow between the two.  Since we're adding insulation, this\n  should {\\em reduce} the heat flow, and so {\\em lower} the value of\n  $k$.\n\n\\item A graph of the heat change over time, given better insulation,\n  is shown below.\n\n  \\includegraphics[width=3in]{graphics/Week08_Spring/W08GarageTemp_2}\n\n\\item Zooming in on the peaks of the {\\bf red line} graph (new\n  insulation model), the temperature now fluctuates between\n  approximately 11.3 and 8.8 degrees Celsius, for a range of 2.5\n  degrees.  This {\\em is} roughly half the magnitude of the\n  fluctuations we saw earlier.\n\n\\end{enumerate}\n\\end{Solution}\n\n\n\\hrulefill\n\n\\subsection*{Modelling Spring Systems}\n% ******************************\n\\item  \\label{SpringNoDampingNoFext}\n  \\begin{Question}\n    \\begin{minipage}[t]{0.6\\linewidth}\n\\vspace{0pt}\nConsider the single spring/mass system shown to the right, with no damper.\n\nNewton's second law gives us the relationship:\n\\begin{align*}\nma & = \\sum F = \\Fspring \\\\\nm x'' & = -k x \n\\end{align*}\nwhere $k$ is the spring constant.\n    \\end{minipage}\n    \\begin{minipage}[t]{0.3\\linewidth}\n\\vspace{0pt}\n\\begin{center}\n\\includegraphics[width=1.0in]{graphics/Week08_Spring/SpringNoDamping}\n\\end{center}\n    \\end{minipage}\n\n\n\\begin{enumerate}\n\\item By hand, write this second order DE as a system of 1st order\n  DEs, using the new variables $w_1 = x$ and $w_2 = x'$\n\n\\item Write a MATLAB function file called \\verb#springDE1.m# starting\n  with the first line \\\\\n  \\verb#function dw_dt = springDE1(t, w, m, k)# \\\\\n  that implements the system of differential equations from part (a).\n\\item Write a MATLAB script that simulates the motion of the mass\n  using $m = 0.5$ kg and $k = 10$ N/m.  Choose the time interval for\n  the simulation so that 4-5 cycles of oscillation are shown.\n\\end{enumerate}\n\\end{Question}\n\n\\begin{Solution}\n \\begin{enumerate}\n \\item  The first-order system would be:\n \\begin{align*}\n \\frac{d}{dt} w_1 & = x' = w_2 \\\\\n \\frac{d}{dt} w_2 & = x'' = \\frac{1}{m} \\left(-kx \\right) = \\frac{1}{m} \\left(-k w_1  \\right)\n \\end{align*}\n\n\\item The function file  \n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/springDE1.m}{springDE1.m} \n  implements the differential equation system, with the $\\Fext $ term\n  left out.\n\n\\item The main script\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08SpringSimulation01.m}{W08SpringSimulation01.m} \nhas the code that will run this simulation.\n\nIn the resulting plot, we see a very nice example of simple harmonic\nmotion.\n\n\\begin{center}\n\\includegraphics[width=3in]{graphics/Week08_Spring/W08SpringSimulation01}\n\\end{center}\n\n\\end{enumerate}\n\\end{Solution}\n\n\n\n% ******************************\n\\item  \\label{SpringNoDampingWithFext}\n  \\begin{Question}\n    \\begin{minipage}[t]{0.6\\linewidth}\n\\vspace{0pt}\nConsider the single spring/mass system shown to the right, with no damper.\n\nThis is the same as in Question \\ref{SpringNoDampingNoFext}, except\nwith the addition of the $\\Fext$ shown as an external applied force.\n\nNewton's second law gives us the relationship:\n\\begin{align*}\nma & = \\sum F = \\Fspring + \\Fext \\\\\nm x'' & = -k x + \\Fext \n\\end{align*}\nwhere $k$ is the spring constant.\n    \\end{minipage}\n    \\begin{minipage}[t]{0.3\\linewidth}\n\\vspace{0pt}\n\\begin{center}\n\\includegraphics[width=1.0in]{graphics/Week08_Spring/SpringNoDampingWithFext}\n\\end{center}\n    \\end{minipage}\n\n\n\\begin{enumerate}\n\\item By hand, write this second order DE as a system of 1st order\n  DEs, using the new variables $w_1 = x$ and $w_2 = x'$\n\n\n\\item We will now incorporate an external force of the form\n  $F_{\\mbox{ext}} = a \\sin(b t)$. Write a MATLAB function file called\n  \\verb#springDE2.m# starting with the first line \\\\\n  \\verb#function dw_dt = springDE2(t, w, m, k, a, b)# \\\\\n  that implements the system of differential equations from part (a).\n\n\\item Create a new MATLAB script.  In the script, set $m =0.5$ kg,\n  $k = 10$ N/m, and use $a = 5$ and $b = 1$ in\n  $F_{\\mbox{ext}} = a \\sin(bt)$.  Use \\verb#ode45# to simulate the\n  motion of the spring for 30 seconds (\\verb#tspan = [0, 30]#), given\n  an initial displacement of $x(0) = 0.2$ m, and initial velocity of\n  zero: $x'(0) = 0$. \\label{forced}\n\n\\item Explain why the motion looks so disorganized.\n\n\\item Repeat Question (\\ref{forced}), but with an external force of\n  $\\Fext = \\sin(4 t)$. Explain why the motion in this case has cyclic\n  waves in its amplitude.\n\n\n\\end{enumerate}\n  \\end{Question}\n\n\\begin{Solution}\n \\begin{enumerate}\n \\item  The first-order system would be:\n \\begin{align*}\n \\frac{d}{dt} w_1 & = x' = w_2 \\\\\n \\frac{d}{dt} w_2 & = x'' = \\frac{1}{m} \\left(-kx + \\Fext\\right) = \\frac{1}{m} \\left(-k w_1  + \\Fext \\right)\n \\end{align*}\n\n\\item The file  \n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/springDE2.m}{springDE2.m} \n  implements the differential equation system, with new external force\n  $\\Fext = a \\sin(bt)$.\n\\item The file \n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08SpringSimulation02.m}{W08SpringSimulation02.m} \nhas the code that will run this simulation.\n\nIn the resulting plot, see some wildly varying and irregular\noscillations.\n\n\\begin{center}\n\\includegraphics[width=3in]{graphics/Week08_Spring/W08SpringSimulation02}\n\\end{center}\n\n\\item The motion of the mass looks very disorganized because the\n  natural frequency (the frequency at which the mass would oscillate\n  if you just let swing on its own) is different from the frequency\n  that we are pushing and pulling on it with through $\\Fext$.\n\n  Recall: the natural frequency of a spring/mass system is given by\n  $\\omega = \\sqrt{k/m}$, which for this scenario gives $\\omega = \\sqrt{ \\frac{25}{4}}$ \n\n\n\\item \nThe file \n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08SpringSimulation02.m}{W08SpringSimulation02.m} \n  has the code that will run this simulation.  Here is a graph of the\n  resulting mass motion.\n\n\\begin{center}\n\\includegraphics[width=3in]{graphics/Week08_Spring/W08SpringSimulation03}\n\\end{center}\n\nIn the plot, we see\n  that the natural frequency and the regular stimulation by the\n  outside force are close to each other: the natural frequency is\n  $\\omega = \\sqrt{\\frac{10}{0.5}} \\approx 4.5$, rad/s, and the\n  stimulating frequency is at $\\omega = 4$ rad/s.  This close match of\n  the frequencies leads to the phenonenon called {\\em beats}, or {\\em\n    near resonance}.\n\\end{enumerate}\n\\end{Solution}\n\n% ******************************\n\\item \n  \\begin{Question}\n    \\begin{minipage}[t]{0.6\\linewidth}\n      \\vspace{0pt} We return to the same single spring/mass system\n      from Question \\ref{SpringNoDampingWithFext}, shown to the right,\n      with no damper.\n      \nThe $\\Fext$ shown is an external applied force.\n    \\end{minipage}\n    \\begin{minipage}[t]{0.3\\linewidth}\n\\vspace{0pt}\n\\begin{center}\n\\includegraphics[width=1.0in]{graphics/Week08_Spring/SpringNoDampingWithFext}\n\\end{center}\n    \\end{minipage}\n\n\n\\begin{enumerate}\n\\item For a mass of $m = 5$ kg , and a spring constant of $k = 2$ N/m,\n  what is the natural frequency of the system?\n\\item Define an external force of the form $\\Fext = \\sin(b t)$ that will\nproduce {\\bf resonance} in the system.\n\\item Use MATLAB to simulate the motion of the spring, with your\n  selected external force, using an initial condition where the mass\n  starts at its equilibrium and at rest.\n\\item The system will break if the oscillations become too large,\n  specifically if $x(t)$ exceeds 2 m (in the positive or negative\n  directions).  Does the system break, and if so, how long does it\n  take for the system to break?\n\\end{enumerate}\n\\end{Question}\n\n\\begin{Solution}\n  \\begin{enumerate}[(a)]\n  \\item The natural frequency of a spring/mass system is given by\n    $\\omega = \\sqrt{\\frac{k}{m}} = \\sqrt{\\frac{2}{5}} \\approx 0.6325$\n    rad/s.\n  \\item If we want to produce resonance in the oscillations, our\n    applied force's frequency must be exactly at the same frequency as\n    the natural frequency. That way, the natural oscillations and the\n    applied force are perfectly synchronized, leading to a build-up of\n    the energy in the system.  \n\n    This means we should select $\\Fext = sin( 0.6325 t)$.\n\n  \\item For this problem, we can recycle the differential equation\n    code in\n    \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/springDE2.m}{springDE2.m}\n    from Question \\ref{SpringNoDampingWithFext}, because the forces\n    (spring and $\\Fext$) are in the same form as in that problem.\n\n    In our new main script,\n    \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08Resonance1.m}{W08Resonance1.m}\n    we will set up all the constants needed for the simulation:\n    \\begin{itemize}\n    \\item $m = 5$, $k = 2$, \n    \\item $a = 1$ and $b= 0.6325$ to define\n      $\\Fext = a \\sin(bt) = 1 \\cdot \\sin(0.6325 t)$.\n    \\end{itemize}\n\n    Below is a graph of the simulated motion of the mass over 30\n    seconds:\n\\begin{center}\n\\includegraphics[width=0.4\\linewidth]{graphics/Week08_Spring/W08SpringResonance1}\n\\end{center}\n\n\\item From the graph, we see that the amplitude of the oscillations\n  are growing with every cycle, as expected when we induce resonance.  This means that the system {\\em will } break at some point. \n\n  The specific limit we were given was that breakage will occur if\n  $x(t)$ exceeds 2 m. Zooming in, we can see that the system will\n  reach $x(t) \\approx 2$ m around $t = 14$ seconds.\n\n\\begin{center}\n\\includegraphics[width=0.4\\linewidth]{graphics/Week08_Spring/W08Resonance1_BreakPoint}\n\\end{center}\n\n  \\end{enumerate}\n\\end{Solution}\n\n\n% ******************************\n\\item \n  \\begin{Question}\n    \\begin{minipage}[t]{0.6\\linewidth}\n      \\vspace{0pt} Consider the damped system shown at right.\n\n      The damping force exerted by the dashpot/damper is proportional\n      to the velocity of the mass.\n\nNewton's second law gives us the relationship:\n\\begin{align*}\nma & = \\sum F = \\Fspring + \\Fdamping \\\\\nm x'' & = -k x  - c x' \n\\end{align*}\nwhere $k$ is the spring constant in N/m, and $c$ is the damping\ncoefficient in N/(m/s).\n\n    \\end{minipage}\n    \\begin{minipage}[t]{0.3\\linewidth}\n\\vspace{0pt}\n\\begin{center}\n\\includegraphics[width=0.9\\linewidth]{graphics/Week08_Spring/W08DampedSpringNoFext}\n\\end{center}\n    \\end{minipage}\n\n\\begin{enumerate}[(a)]\n\\item By hand, write this second order DE as a system of 1st order\n  DEs, using the new variables $w_1 = x$ and $w_2 = x'$\n\n\\item We define a system with a mass of $m = 10$ kg, spring constant\n  $k = 2$ N/m, and a damping coefficient of $c = 0.4$ N/(m/s).  If the\n  system is displaced by 0.5 m and then let go with zero initial\n  velocity, use MATLAB to find out how long (in both seconds and\n  cycles) it takes for the oscillations to reach approximately 10\\% of\n  their original amplitude.  Note: you will need to write both a\n  MATLAB function for the differential equation, and a main script to\n  run the simulation.\n\\item What damping coefficient would be needed for the oscillations to\n  be reduced to 10\\% of their original amplitude within 3 cycles?  You\n  will need to estimate your answer based on guessing and checking\n  against the graph.  Hint: add horizontal lines to the solution plot\n  at $x = 0.05$ and $x = -0.05$ to see easily whether the oscillations\n  are reduced to that level.\n\\end{enumerate}\n\\end{Question}\n\n\\begin{Solution}\n  \\begin{enumerate}[(a)]\n \\item  The first-order system would be:\n \\begin{align*}\n \\frac{d}{dt} w_1 & = x' = w_2 \\\\\n \\frac{d}{dt} w_2 & = x'' = \\frac{1}{m} \\left(-kx -c x'\\right) = \\frac{1}{m} \\left(-k w_1  - c w_2\\right)\n \\end{align*}\n\n\\item To simulate the motion of the spring/mass system, we need a\n  function file with the differential equation, which we called\n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/springDEDamped.m}{springDEDamped.m},\n  and a main script, which we called\n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08DampedSpringSystem.m}{W08DampedSpringSystem.m}.\n\n  Here is the graph of the resulting motion, showing a nice\n  oscillatory pattern, but the amplitude diminishing over time due to\n  the damping.\n\n\\begin{center}\n\\includegraphics[width=3in]{graphics/Week08_Spring/W08DampedSpring1A}\n\\end{center}\n\n\nseconds, or between 8 and 9 cycles.\n\n\\begin{center}\n\\includegraphics[width=3in]{graphics/Week08_Spring/W08DampedSpring1B}\n\\end{center}\n\n\\item Using $c = 1.1$ N/(m/s) gives the required damping, putting the amplitude\nof the oscillations below 10\\% of their original magnitude after 3 cycles.\n\n\\begin{center}\n\\includegraphics[width=3in]{graphics/Week08_Spring/W08DampedSpring1C}\n\\end{center}\n\n \n\n  \\end{enumerate}\n\\end{Solution}\n\n\n% %****************\n\\item \n\\begin{Question}\n  For a spring/mass system with $m=1$ kg, $c=0.5$ N/(m/s), and $k=45$,\n  approximately what frequency of external forcing would produce the\n  largest amplitude steady-state vibration?  Give your answer to the\n  nearest 0.5 rad/s.\n\n  You will need to estimate the answer based on guessing and checking\n  against the graph.\n \\end{Question}\n\n \\begin{Solution}\n   The natural frequency is going to be near\n   $\\omega = \\sqrt{k/m} \\approx 6.7$ rad/s.\n\n   To run the simulation in MATLAB, we know we need to build the\n   differential equation based on the sum of the forces in MATLAB.  $ma = \\sum F$ gives us\n$$ m x'' = -kx - c x' + \\sin(bt)$$\nwhere $b$ is the frequency we can experiment with to maximize the\nsteady-state oscillations.\n\nThe first-order system version of this is: \n \\begin{align*}\n \\frac{d}{dt} w_1 & = x' = w_2 \\\\\n \\frac{d}{dt} w_2 & = x'' =  \\frac{1}{m} \\left(-kx -c x'+ \\sin(bt) \\right) \\\\\n& = \\frac{1}{m} \\left(-k w_1  - c w_2 + \\sin(bt) \\right)\n \\end{align*}\n\n We built this system of differential equations into the file\n \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/springDEDampedAndForced.m}{springDEDampedAndForced.m} \nand the main script\n \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W08DampedSpringSystem3.m}{W08DampedSpringSystem3.m} \n\n If we are only interested in the steady-state behaviour, then the\n initial conditions won't matter (their influence fades in the long\n run). We make the easiest choice, which is the mass starting at\n equilibrium at rest, $x(0) = 0$ and $x'(0) = 0$.\n\n Below is a graph showing the response of the system to\n $b = 5, 5.5, 6, 6.5$ and 7 rad/s, and then the graph for $b = 6.5$\n rad/s only.\n\n\\begin{center}\n\\includegraphics[height=2.6in]{graphics/Week08_Spring/W08DampedAndForced1}\n\\includegraphics[height=2.6in]{graphics/Week08_Spring/W08DampedAndForced2}\n\\end{center}\n\nLooking for the steady-state oscillations means looking at the\namplitudes once the graph steadies into a regular repeating pattern.\nThe graph corresponding to $\\Fext = \\sin(6.5~t)$ is the graph with the\nhighest amplitude once that steady-state oscillation pattern is\nreached.\n\n\n \\end{Solution}\n\n\\end{enumerate}\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "f9f43cafba2152a4ae99ca9f8588ab0092c3dcd6", "size": 19189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PracticeProblems/Week08.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/Week08.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/Week08.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.3388581952, "max_line_length": 131, "alphanum_fraction": 0.7130126635, "num_tokens": 5819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919830720204, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.694228583285846}}
{"text": "%#########################################################\n\\chapter{Compressed Sensing Velocity Encoded Phase-Contrast Imaging}\n%#########################################################\nThis chapter includes a brief introduction into theory of compressed sensing and provides the details of compressed sensing application to Velocity Encoded Phase-Contrast imaging (VEPC).\n%=========================================================\n\\section{Compressed Sensing}\n%=========================================================\nOne of the greatest challenge in MR imaging is long scan time, which is directly proportional to the number of samples collected in the Fourier domain (\\textit{k-}space).\nIn recent years the theory of compressed sensing as well as the sampling and reconstruction framework was developed \\cite{Donoho:2006cia, 2008ISPM...25...21C, Lustig:2007cua}.\n%-new paragraph-%\n\n%-new paragraph-%\nLet $k(\\omega)$ be the \\mbox{\\textit{k-}space} data collected and the inverse Fourier transform of $k(\\omega)$ is a reconstructed image $a(t)$, $t = (t_1, ... t_d) \\in \\mathbb{Z}^d_N$\n%.........................................................\n\\begin{equation}\n\tk(\\omega) = \\sum_t{a(t)e^{-2\\pi i (\\omega_1 t_1 + ... + \\omega_d t_d)/N}}\n\\end{equation}\n%.........................................................\nIs it possible to recover the same image $a$ from $k(\\omega)$, where $\\omega = (\\omega_1, ..., \\omega_d) \\in \\Omega$ and $\\#\\Omega < N^d$~? The answer emerges from the fact that MR images meet two important conditions: ($i$) MR images are sparse in a certain domain and ($ii$) Fourier encoding is not coherent with these sparse transformations. \n%Therefore image can be recovered for the undersampled dataset by solving constrained optimization problem.\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Data Sparsity and Undersampling}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nMR data in the image domain in general are not sparse, yet in another domains the sparsity can still be achieved. \nConsider the signal $\\mathbf{a}(t)$ expanded in the orthonormal basis $\\mathcal{W}=\\left[\\mathbf{w}_1 \\dots \\mathbf{w}_n\\right]$, where $\\mathbf{w_i}$ are row vectors:\n%.........................................................\n\\begin{equation}\\label{signal of interest}\n\\mathbf{a}(t) = \\sum_{i=1}^n\tx_i \\mathbf{w}_i(t)\n\\end{equation}\n%.........................................................\nwith $x_i$ being an inner product of $\\mathbf{a}$ and $\\mathbf{w}_i$. \nIf signal $\\mathbf{a}(t)$ is sparse it's possible to discard a certain number of coefficients in the expansion without significant loss of information. \nThus sparsity can be quantified by the percentage of largest transformation coefficients preserved for the sufficiently good reconstruction. \nA more rigorous quantification would be to call the the signal $\\mathbf{a}(t)$ $S$-sparse if it has at most $S$ nonzero elements. \nUndersampled acquisition thus will collect only a subset of $m \\in M$ coefficients, where $M \\subset N$:\n%.........................................................\n\\begin{equation}\n\tk_j = \\left< \\mathbf{a}, \\mathbf{s}_j \\right>\n\\end{equation}\n%.........................................................\nhere $\\mathbf{s}_j$ is one of the $m$ rows of the sensing basis $\\mathcal{S} = [\\mathbf{s}_1 \\dots \\mathbf{s}_m]$. \n%-new paragraph-%\n\n%-new paragraph-%\nMany different sparsifying transformations can be applied, some of the most widely used are wavelet transform, discrete cosine transformation (DCT), finite difference and Gabor transform \\cite{Baker:2016vs}. \nExample in Figure~\\ref{WaveletCSExample} shows: magnitude MR image obtained using FGRE (Fast gradient echo) (a), its wavelet transform (b) and image obtained from top 2.5\\% of the wavelet coefficients (c).\nImage in Figure~\\ref{WaveletCSExample}c is visually indistinguishable from image in Figure~\\ref{WaveletCSExample}a thus by preserving only limited number of largest wavelet coefficients it's still possible to get a sufficiently good reconstructed image.\nThis approach works well when fully-sampled image is known beforehand (e.g. image compression).\r\nIn MRI experiment the image data are \\textit{a priori} unknown, therefore an acquisition strategy must be adopted.\r\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{Figures/CS2.pdf}\n    \\caption[MRI image reconstructed from top 2.5\\% of its wavelet coefficients]{Magnitude FGRE image (a); wavelet transformation (b) and image reconstructed from 2.5\\% of the largest wavelet coefficients (c).}\n    \\label{WaveletCSExample}\n\\end{figure}\n%*********************************************************\n\\FloatBarrier\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Incoherent Measurements and Random Sampling}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUndersampled data can be represented as following:\n%.........................................................\n\\begin{equation} \\label{kspace_multicoil}\n\\mathbf{k} = \\mathcal{A} \\mathbf{x} + \\sigma,\n\\end{equation}\n%.........................................................\nwhere $\\mathcal{A} = \\mathcal{S}\\mathcal{W}$ is sensing matrix of size $m \\times n$, $\\mathbf{x}$ is a vector represented by the set of coefficients $x_i$ defined in Equation~\\ref{signal of interest} and $\\sigma$ is noise. \nThe recovered signal $\\mathbf{a}^\\star$ is given by $\\mathbf{a}^\\star = \\mathcal{W} \\mathbf{x}^\\star$, where  $\\mathbf{x}^\\star$ is the solution to the following convex minimization problem:\n%.........................................................\n\\begin{equation} \\label{COP}\n\\begin{aligned}\n\t\\min_{\\mathbf{z} \\in \\mathbb{R}^n} \\quad &\\norm{\\mathbf{z}}_1 \\\\\n\t\\text{subject to} \\quad  &\\norm{\\mathcal{A} \\mathbf{z}-\\mathbf{k}}_2 < \\epsilon,\n\\end{aligned}\n\\end{equation}\n%.........................................................\nhere $\\epsilon$ is a threshold parameter to control the fidelity of reconstructed data and is set to be below expected noise level $\\sigma$, $\\ell_1$ and $\\ell_2$ -norms are defined for a vector $\\mathbf{z}$ according to the Equation~\\ref{L12Norm}:\n%.........................................................\n\\begin{equation} \\label{L12Norm}\n\\begin{aligned}\n\t\\norm{\\mathbf{z}}_1 & = \\sum_{n=1}^{N}{|z_n|} \\\\\n\t\\norm{\\mathbf{z}}_2 & = \\sqrt{\\sum_{n=1}^{N}{|z_n|}^2}\n\\end{aligned}\n\\end{equation}\n%.........................................................\nBefore discussing reconstruction procedure it's important to address the properties of the sensing matrix. \nSensing matrix should maintain two important properties: $(i)$ incoherence and ($ii$) restricted isometry property (RIP) \\cite{Candes:2005fx}.\n%---------------------------------------------------------\n\\subsubsection{Incoherence}\n%---------------------------------------------------------\nFor compressed sensing framework the incoherence of a sensing basis $\\mathcal{S}$ and the sparsifying basis $\\mathcal{W}$ is of a great importance. \nCoherence $\\mu$ measures the maximum correlation between elements of $\\mathcal{S}$ and $\\mathcal{W}$ and is defined as:\n%.........................................................\n\\begin{equation}\n\t\\mu (\\mathcal{S}\\mathcal{W}) = \\sqrt{n} \\max_{1\\leq p, q\\leq n}{\\left|\\left<{s_p , w_q}\\right>\\right|}\n\\end{equation}\n%.........................................................\nsince $\\mathcal{S}$ and $\\mathcal{W}$ are orthonormal lower and upper boundary for $\\mu \\in \\left[1,\\sqrt{n}\\right]$. \nSuppose that $\\mathbf{a}$ in basis $\\mathcal{W}$ is $S$-sparse then if:\n%.........................................................\n \\begin{equation}\n \tm\\geq C \\cdot \\mu^2(\\mathcal{S}\\mathcal{W}) \\cdot S \\cdot \\log{n}\n \\end{equation}\n%.........................................................\nthe reconstruction of the signal of interest is exact with overwhelming probability \\cite{2007InvPr..23..969C}. \nClearly this result implies that the smaller coherence leads to less number of samples required for reconstruction.\n%---------------------------------------------------------\n\\subsubsection{Restricted isometry property}\n%---------------------------------------------------------\nApplication of compressed sensing framework to experiment requires to consider two important issues. \nFirst sparsity of signal of interest is always approximate rather than exact and second is noise. \nThese two issues are crucial for robustness of the reconstruction algorithm. As shown in~\\cite{Candes:2006fb}, when sensing matrix $\\mathcal{A}$ satisfies Restricted Isometry Property (RIP):\n%.........................................................\n\\begin{equation}\n\t\\left(1-\\delta_S\\right)\\norm{\\mathbf{x}}^2_2\\leq\\norm{\\mathcal{A}\\mathbf{x}}^2_2\\leq\\left(1+\\delta_S\\right)\\norm{\\mathbf{x}}^2_2, \\quad 0 < \\delta_S < 1\n\\end{equation}\n%.........................................................\nthe reconstruction is accurate. In other words all subsets of S columns of sensing matrix $\\mathcal{A}$ are nearly orthogonal, so $S$-sparse vectors $\\mathbf{x}$ cannot be in the nullspace of $\\mathcal{S}$. \nSuppose that sensing matrix $\\mathcal{A}$ satisfies the RIP of order $2S$ with isometry constant $\\delta_{2s} < \\sqrt{2} -1$ then the solution $\\mathbf{x}^\\star$ of \\ref{COP} obeys:\n%.........................................................\n\\begin{equation}\\label{Reconstruction error}\n\t\\norm{\\mathbf{x}-\\mathbf{x}^\\star}_2 \\leq C_1 \\frac{\\norm{\\mathbf{x}-\\mathbf{x}_S}_1}{\\sqrt{S}} + C_2 \\epsilon\n\\end{equation}\n%.........................................................\nwhere $C_1$ and $C_2$ are constants, which are typically small, $\\mathbf{x_S}$ is $\\mathbf{x}$ with all $x_i$ except largest $S$ set to zero. \nHence reconstruction error is limited by sum of noise-less term $C_1$ and term $C_2$ proportional to noise threshold parameter $\\epsilon$.\nSince obeying RIP guarantees robust reconstruction \\cite{Candes:2006fb} it's important for sensing matrix $\\mathcal{A}$ to satisfy RIP. \nIt was demonstrated by Cand{\\`e}~et~al.~\\cite{2008ISPM...25...21C} that possible sampling schemes for sensing matrix are: sampling $m$ columns uniformly at random from $n$, i.i.d from normal distribution with mean 0 and variance $1/m$ and many other random sampling schemes satisfy RIP with high probability~if:\n%.........................................................\n\\begin{equation}\n\tm\\geq C \\cdot S \\log{\\frac{n}{S}}\n\\end{equation}\n%.........................................................\n%-new paragraph-%\n\n%-new paragraph-%\nFigure~\\ref{CS1} illustrates incoherence between wavelet and Fourier transformations for point spread function, here random \\textit{k-}space undersampling results in incoherent interference in the wavelet domain. \nThe interference spreads mostly within the wavelet coefficients of the same scale and orientation. \r\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n    \\centering\n    \\includegraphics[width=\\textwidth]{Figures/CS1.pdf}\n    \\caption[Incoherence between wavelet and Fourier domains]{Incoherence between wavelet and Fourier domains.}\n    \\label{CS1}\n\\end{figure}\n%*********************************************************\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Solution to the Constrained Optimization Problem}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nReconstruction process requires to solve the constrained optimization problem~(Equation~\\ref{COP}). \nFor the velocity encoded MR signal this problem can be restated as following:\n%.........................................................\n\\begin{equation} \\label{CS COP}\n\\begin{aligned}\n\t\\min_{\\mathbf{I}}  \\quad &\\norm{\\mathcal{F}_t \\, \\mathbf{I}}_1 \\\\\n\t\\text{subject to} \\quad  &\\norm{\\mathcal{F}_s \\, \\mathbf{I}-\\mathbf{k}}_2 < \\epsilon,\n\\end{aligned}\n\\end{equation}\n%.........................................................\nwhere vector $\\mathbf{I}$ is an image of interest, sparsifying transform $\\mathcal{F}_t$ is temporal Fourier operator, $\\mathcal{F}_s$ is spatial Fourier operator, and vector $\\mathbf{k}$ is undersampled MR \\mbox{\\textit{k-}space} data. \nDevelopment of efficient solution algorithms to problem stated in Equation~\\ref{CS COP} has been a subject of the research for many years by now. \nMultiple computational approaches exist and some of the most known and widely used are: Convex Relaxation, Iterative Thresholding, Gradient Pursuit and other~\\cite{Qaisar:2013ff}. Nonlinear conjugate gradient method is one of the possible choices.\n%---------------------------------------------------------\n\\subsubsection{Nonlinear conjugate gradient method}\n%---------------------------------------------------------\nDue to presence of noise in vector $\\mathbf{k}$ constrained optimization problem~\\ref{CS COP} should be relaxed to the least squares problem \\cite{Yin:2011ts}:\n%.........................................................\n\\begin{equation} \\label{CS UOP}\n\t\\min_{\\mathbf{I}} \\quad \\norm{\\mathcal{F}_s \\mathbf{I} - \\mathbf{k}}_{2}^{2} + \\lambda_1 \\, {\\norm{\\mathcal{F}_t \\mathbf{I}}}_1\n\\end{equation}\n%.........................................................\nwhere $\\lambda_1$ is the Lagrangian multiplier of the constraint from the Equation~\\ref{CS COP}, which controls the tradeoff between sparsity term ($\\ell_1$-norm term) and image consistency ($\\ell_2$-norm term). \nNonlinear conjugate gradient method (NCG) allows to solve minimization problem (Equation~\\ref{CS UOP}) numerically if gradient  of the cost function $f(\\mathbf{I})$ defined by Equation~\\ref{CS UOP} can be computed \\cite{Lustig:2007cua}. \nThe second term of the cost function is an $\\ell_1$-norm defined as a sum of absolute values, its derivative is not defined at $I_i = 0$, therefore an approximation by a smooth function is necessary. \nThe most computationally efficient choice is $\\left| x \\right| \\approx \\sqrt{x^2 + \\mu}$ \\cite{Ramirez:2014up}. \nThe gradient of $f(\\mathbf{I})$ is then approximated:\n%.........................................................\n\\begin{equation}\n\t\\nabla f(\\mathbf{I}) =  2 \\mathcal{F}_s^* \\left(\\mathcal{F}_s \\, \\mathbf{I}-\\mathbf{k} \\right) + \\lambda \\mathcal{F}_t^*\\mathcal{U}^{-1}\\mathcal{F}_t\\mathbf{I}\n\\end{equation} where $\\mathcal{U}$ is a diagonal matrix defined as following:\n\\begin{equation}\n\t\\mathcal{U}=\\DiagMat{\\sqrt{(\\mathcal{F}_t\\mathbf{I})^*_i \\, (\\mathcal{F}_t\\mathbf{I})_i + \\mu }}\n\\end{equation}\n%.........................................................\nwith smoothing parameter $\\mu \\in \\left[ 10^{-15} , 10^{-6} \\right]$ \\cite{Lustig:2007cua}.\nNCG method is summarized in the following outline:\n%-new paragraph-%\n\n%-new paragraph-%\n\\noindent \\begin{samepage} \\textbf{NCG outline} \\\\\n\\noindent\\rule{15cm}{0.4pt} \\\\\n%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\\indent \\qquad \\qquad \\textit{input:} \\, $f(\\mathbf{I})$ - cost function, $\\alpha$, $\\beta$ - line search parameters\\\\ \n\\indent \\qquad \\qquad \\textit{output:} $\\mathbf{I}$ - reconstructed image\\\\\n\\noindent\\rule{15cm}{1pt} \\\\\n$n=0$ \\quad $I_0 = 0$ \n\\begin{itemize}\n\t%\\renewcommand{\\labelitemi}{\\scriptsize$-$}\n\t\\item Initial search direction: $g_0 = \\nabla f(I_0)$; $\\Delta I_0 = -g_0$\n\t\\item Backtracking-Armijo line search: $\\tau = 1$\n\t\t\\begin{itemize}\n\t\t\t\\item \\textbf{while} \\quad $f(I_0 + \\tau \\Delta I_0) \\leq f(I_0) + \\alpha \\tau \\cdot \\Re(g^*_0 \\Delta I_0)$ \\, \\textbf{do} \\, $\\tau = \\beta \\tau$ \\quad ($\\star$)\n\t\t\\end{itemize}\n\t\\item Update search direction:\n\t\t\\begin{itemize}\n\t\t\t\\item $I_1 = I_0 + \\tau \\Delta I_0$, $g_1 = \\nabla f(I_1)$, $\\gamma = \\cfrac{\\norm{g_1}^2_2}{\\norm{g_0}^2_2}$\n\t\t\t\\item $\\Delta I_1 = -g_1 + \\gamma \\Delta I_0$\n\t\t\\end{itemize}\n\t\\item $n=1$ \n\\end{itemize} \\vspace{-3mm} \\noindent\\rule{15cm}{0.4pt} \\\\\n%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\\textbf{for} \\quad $0<n<N$, where $n \\in \\mathbb{N}$, $N$ - maximum number of iterations \\quad \\textbf{do}\n\\begin{itemize}\n\t%\\renewcommand{\\labelitemi}{\\scriptsize$-$}\n\t\\item Backtracking-Armijo line search: \t$\\tau = 1$\n\t\t\\begin{itemize}\n\t\t\t\\item \\textbf{while} \\quad $f(I_{n} + \\tau \\Delta I_{n}) \\leq f(I_{n}) + \\alpha \\tau \\cdot \\Re(g^*_{n} \\Delta I_{n})$  \\, \\textbf{do} \\, $\\tau = \\beta \\tau$ \\quad ($\\star\\star$)\n\t\t\\end{itemize}\n\t\\item Update search direction:\n\t\t\\begin{itemize}\n\t\t\t\\item $I_n = I_{n-1} + \\tau \\Delta I_{n-1}$, $g_n = \\nabla f(I_n)$, $\\gamma = \\cfrac{\\norm{g_n}^2_2}{\\norm{g_{n-1}}^2_2}$\n\t\t\t\\item $\\Delta I_n = -g_n + \\gamma \\Delta I_{n-1}$\n\t\t\\end{itemize}\n\t\\item $n=n+1$ \n\\end{itemize}\n\\textbf{end} \\\\\n\\noindent\\rule{15cm}{1pt}\n\\end{samepage}\\\\\n\\newpage\n\n%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nAt each iteration Backtracking-Armijo line-search is used since general backtracking line search fails to prevent the step $\\tau$ from getting too large relative to the decrease~in~$f$. \nThe Armijo-Goldstein condition ($\\star$  and $\\star \\star$ in NCG outline) has a second term on the right-hand side requiring the achieved reduction in $f$ to be at least a fixed fraction $\\alpha$ of the reduction promised by the first term of the Taylor series of $f(I_n)$~\\cite{Armijo:1966di}. \nBoth parameters $\\alpha$ and $\\beta \\in (0,1)$. \nCompared to conjugate gradient (CG) method where $f$ is quadratic NCG has a number of choices for $\\gamma$ parameter~\\cite{Hager:2006wp}. \nTwo most popular  are Fletcher-Reevs (given above in the NCG outline) and Polak-Ribi\\`ere. \nThe Fletcher-Reeves method converges if the starting point is sufficiently close to the desired minimum, whereas the Polak-Ribi\\`ere method can, in rare cases, cycle infinitely without converging~\\cite{Shewchuk:1994uc}.\n%=========================================================\n\\section{Application of Compressed Sensing Methods for Monitoring Skeletal Muscle Kinematics}\n\\label{sec: CS_paper}\n%=========================================================\nMagnetic Resonance imaging has been established as a viable technique to study muscle kinematics (including strain mapping)~\\cite{RNS31, RNSS4, RNCS3, RNCS4, RNCS5}. \nSeveral studies have established the feasibility of the VEPC based MRI technique for monitoring muscle velocity and strain rate mapping during passive muscle motion and for different contraction modes (e.g., for isometric, concentric and eccentric contraction patterns)~\\cite{RNCS3, RNCS4, RNCS5} as well applied it to study differences in aging and young muscle as well as pre- and post- unloading~\\cite{RNS16, Malis:2018fr}. \nHowever, the limitation of the VEPC is the long scan time that requires execution of $\\sim 75$ consistent contractions for dynamic imaging ($\\sim \\SI{2}{\\minute}~\\SI{40}{\\second}$).\nSeveral methods have been developed to maintain the consistency of contraction; e.g., by providing a visual feedback of the measured force superposed on the target force curve~\\cite{RNS16, Malis:2018fr}. \nHowever, this still limits the force that can be maintained for the duration of the scan; this is usually set at 30-35\\% Maximum Voluntary Isometric Contraction (MVIC) to enable $\\sim 75$ consistent contractions. \nStudying muscle kinematics for several \\%MVICs including higher \\%MVICs may provide better insights into differences in muscle kinematics between normal and diseased (e.g., sarcopenia, disuse atrophy, dystrophy) conditions~\\cite{RNS16, Malis:2018fr}. \nThe long scan times also prevent acquisition of multiple slices to extract the full 3D strain or strain rate tensor. \nFurther, in order to decrease scan times, views per segment (VPS) up to 4 are employed, but this limits the acquired temporal resolution of the scans. \nA faster VEPC sequence with improved temporal resolution could possibly expand the domain of exploration of muscle kinematics. \n%-new paragraph-%\n\n%-new paragraph-%\nCompressed sensing (CS) has been applied successfully and extensively in MRI to accelerate scan times~\\cite{Lustig:2007cua}. \nCS allows for reconstruction of undersampled MRI data based on the concept that an image with a sparse representation in a known transform domain can be recovered (without artifacts) from randomly undersampled \\mbox{\\textit{k-}space} data using a non-linear reconstruction. \nThe maximum acceleration (CS undersampling factor) will be determined by the image sparsity in the transform domain; the experimental observation is that the number of required samples is approximately $\\sim 4$ times the number of non-zero coefficients in the transform domain. \nVarious sparsifying transforms have been introduced such as wavelet, Principal Component Analysis (PCA) and Fourier Transform (FT)~\\cite{Lustig:2007cua}. \nFor 2D imaging, practical considerations limit the randomness to the phase encode direction ($k_y$) while for 3D acquisitions, random undersampling can be performed in the two phase-encode directions ($k_y$ and $k_z$) allowing for higher acceleration factors. \nFurther, in 2D dynamic imaging as in 2D VEPC, researchers have exploited the fact that each temporal frame can have a different random phase encode pattern and a joint reconstruction of all temporal frames exploits the randomness in two axes ($k_y$\\textit{-t}) allowing for higher acceleration factors compared to independent reconstructions of each temporal frame. \n$k_y$\\textit{-t} CS reconstruction has also been integrated with multiple coil sensitivity profiles to perform a joint reconstruction of raw data from all the coils: this allows higher acceleration factors than CS without multiple coils that still yields images without significant artifacts. \nThis latter technique, termed $k_y$\\textit{-t} SPARSE SENSE to reflect the combination of multi-coil (parallel) imaging and CS techniques, has been applied to first-pass cardiac perfusion imaging as well as to studying cardiovascular and hepatoportal vascular dynamics~\\cite{RNCS9, RNCS10}. \nHowever, the $k_y$\\textit{-t} SPARSE SENSE technique has not been applied to imaging muscle kinematics. \nIt should be noted that muscle velocities are much lower than that encountered in cardiac or portal and hepatic veins blood flow imaging ($venc = \\SI{80}{\\centi\\meter/\\second}$), so the velocity encoding gradients are much larger for the VEPC sequence to map muscle motion ($venc = \\SI{10}{\\centi\\meter/\\second}$). \nThe larger velocity encoding gradients result in noisier images, so that integrating compressed sensing with VEPC sequences mapping lower velocities may pose additional challenges. \nOne recent paper reported 4D VEPC integrated with compressed sensing applied to muscle dynamics~\\cite{RNCS11}.\nThe latter paper performed 3D volume acquisition with undersampling in the $k_y$ and $k_z$ axes with 3-directional velocity encoding. \nIn order to leverage the undersampling in the slice direction, a fairly high number of partitions is required (e.g. $\\Rightarrow 32$) that results, for the best acceleration factor reported in the latter paper ($\\sim \\times 6.4$), in scan times of $\\sim \\SI{2}{\\minute}~\\SI{46}{\\second}$. \nAdmittedly, the optimum approach for 3D strain rate tensor computation is to acquire in 3D with 3 directional velocity encoding to cover the entire muscle. \nHowever, the long acquisition time of the 3D sequence even with ($\\sim \\times 6.4$) undersampling~\\cite{RNCS11} limits its application with regards to the goal of the current work to reduce the acquisitions to less than a minute. \nFurther, earlier experimental observation was~\\cite{Malis:2018fr}, that with appropriate orientation of the acquisition slice in the plane of the muscle fibers (e.g., oblique sagittal for the medial gastrocnemius), 5 contiguous slices of $\\SI{5}{\\milli\\meter}$ thickness allows the extraction of the 3D strain~/~strain rate (SR) tensor in 3 slices and this is sufficient to capture the spatial variation of the 3D strain tensor along the length of the muscle. \n%-new paragraph-%\n\n%-new paragraph-%\nThe advantages of a faster VEPC sequence for muscle imaging is that it will allow scans to be completed with a shorter number of contraction cycles; this will expand the applicability to cohorts that are limited in their ability to sustain consistent contraction levels for a large number of repetitions. \nThese cohorts include older subjects (normal and sarcopenic) and subjects with skeletal muscle disorders such as disuse atrophy dystrophy. \nFurther, a short VEPC sequence will also enable acquisitions at higher \\%MVIC (and at several \\%MVIC) in contrast to current MRI based muscle kinematics studies limited to a single \\%MVIC ($\\sim 35$\\%MVIC) achievable using traditional longer VEPC sequences~\\cite{RNS16, Malis:2018fr}. \nDifferences in muscle performance between normal and abnormal (sarcopenic, dystrophy, disuse atrophy) muscle function may be characterized better by investigating over a range of \\%MVICs to explore force-strain patterns~\\cite{RNCS12}. \n%-new paragraph-%\n\n%-new paragraph-%\nThe objective of this study was to integrate compressed sensing and multi-coil methods with 2D VEPC imaging to decrease total scan time to less than a minute and implement this to study muscle kinematics. \nThe new sequence was first validated with a constant flow phantom and velocity from the fully sampled and undersampled acquisitions (at different accelerations) were compared to reference flowmeter values. \nCalf muscle tissue motion (velocity and strain rate) under isometric contraction was monitored by the reference VEPC sequence and compared to the undersampled VEPC sequences for different acceleration factors (obtained by combinations of \\mbox{CS\\textit{-factor}} and views per segment).\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Methods}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%---------------------------------------------------------\n\\subsubsection{Velocity encoded phase-contrast pulse sequence}\n%---------------------------------------------------------\nThe VEPC pulse sequence with 3 directional velocity encoding and the reference (without any velocity encoding) shown in Figure~\\ref{fig: VEPC} was modified for random undersampling with a different random pattern along the $k_y$ direction at each temporal frame. \nThe reference VEPC sequence was implemented with 4 views per segment that resulted in an acquired temporal resolution of $\\SI{285}{\\milli\\second}$  ($\\sim 8$ acquired frames for the contraction cycle duration of $\\SI{2.3}{\\second}$); this acquired data was then interpolated using view sharing to reconstruct 17 temporal frames. \nAs part of this study, both CS acceleration factors and views per segment were modified to reduce scan time while maintaining~/~increasing the acquired temporal resolution.\n%---------------------------------------------------------\n\\subsubsection{Compressed sensing}\n%---------------------------------------------------------\n\n%`````````````````````````````````````````````````````````\n\\textit{k-space undersampling:}\n%`````````````````````````````````````````````````````````\nUndersampling was performed along the $k_y$ direction with a different random pattern at each temporal frame. \nThe undersampling along the $k_y$ was a random variable density pattern that yielded a dense sampling at the center of \\mbox{\\textit{k-}space}. \nThe pattern was drawn from a probability density function (PDF) (Figure~\\ref{fig: CS2}a) given by 10th order polynomial:\n%.........................................................\n\\begin{equation}\\label{eq: CS1}\n\\mathrm{PDF} = (1-|k|)^{10} + m\n\\end{equation}\n%.........................................................\nHere $k$ is the magnitude of $k_y$ with the maximum and minimum values of $k_y$ normalized to $+1$ and $-1$ respectively and $m$ is the sampling density computed by using an iterative bisection method, where the value in each iteration is divided successively by 2. \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_1.pdf}\n\\caption[The probability density function, two times undersampled pattern for selected temporal frames and combined phase encode~/~temporal frame undersampling pattern]{The PDF from which the random undersampled phase encode (PE) pattern is drawn (a); CS\\textit{-factor} $\\times 2$ undersampling pattern for selected temporal frames with different patterns for each: black indicates not acquired, white indicates the acquired PE line (b); combined phase encode~/~temporal frame undersampling pattern (c).}\n\\label{fig: CS2}\n\\end{figure}\n%*********************************************************\nThis method ensured dense sampling at the center of $k_y$ with decreasing $k_y$ density toward the edges of $k_y$ space~\\cite{RNCS10}. \nDense sampling at the center has been established as providing better CS reconstructed images than uniform random undersampling~\\cite{Lustig:2007cua, RNCS9}.\n%-new paragraph-%\n\n%-new paragraph-%\nThe undersampling pattern for each temporal frame of the dynamic series was an independent random pattern (Figures~\\ref{fig: CS2}b~and~\\ref{fig: CS2}c) selected as recommended by Lustig~\\cite{Lustig:2007cua}. \nIn brief, an impulse at the origin in a 1D image is Fourier transformed to give a constant image. \nThis constant 1D image is undersampled by the chosen random pattern and then a 1D iFFT is performed to obtain the 1D image of the impulse. \nIf no undersampling is performed, then the impulse is completely recovered while the undersampling results in side lobes which are quantified as the sum of the coefficients not including the origin (denoted as interference) in the 1D image reconstructed by undersampling. \nThe undersampling pattern with the lowest value for the interference (from 100 iterations) was chosen in separate iterations for a temporal frame. \nDifferent combinations of compressed sensing acceleration factors (\\mbox{CS\\textit{-factor}}) and views per segment (VPS) were tested for both \\textit{in-vitro} phantom as well as for \\textit{in-vivo} calf muscle studies (Figure~\\ref{fig: CS3}).\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_2.pdf}\n\\caption[The $k_y$\\textit{-t} SPARSE SENSE acquisition and reconstruction pipeline]{The $k_y$\\textit{-t} SPARSE SENSE acquisition and reconstruction pipeline. Different sampling patterns and views per segment were tested to identify the highest acceleration factors that would still produce artifact free images after CS reconstruction. \\mbox{\\textit{k-}space} data was the input, the zero filled iFFT was the start point for the Temporal FFT.}\n\\label{fig: CS3}\n\\end{figure}\n%*********************************************************\nThe undersampled patterns generated as detailed above were integrated into the velocity encoded FGRE sequence by modifying the proprietary pulse sequence (GE Medical Systems, version 15M4, WI, USA) using the EPIC programming environment. \nThe undersampled mask for each temporal frame was read from an external file. \nThe entire sequence was tested on the simulation platform as well as during run-time to verify that the undersampled patterns were correctly reproduced.\n\n%`````````````````````````````````````````````````````````\n\\textit{Compressed sensing iterative reconstruction:}\n%`````````````````````````````````````````````````````````\nThe flowchart for the iterative non-linear reconstruction algorithm is shown in Figure~\\ref{fig: CS3} and follows the $k_y$\\textit{-t} SPARSE SENSE method reported earlier~\\cite{RNCS9, RNCS10, RNCS14}. \nData was downloaded from the scanner as the complex \\mbox{\\textit{k-}space} data for each coil for each temporal frame. \nData from the multiple channels was combined to form a self-calibrated coil sensitivity map $\\mathbb{C}$. \nThe coil sensitivity map is obtained by a temporal average over all the phases followed by an adaptive array combination~\\cite{RNCS15}.\n%-new paragraph-%\n\n%-new paragraph-%\nA two-stage process is used to reconstruct the image; the first stage uses the temporal Fourier transform as the sparsifying transform while the second stage uses the temporal PCA as the sparsifying transform (Figure~\\ref{fig: CS3}). \nThe starting point of the first stage (temporal FT as the sparsifying transform) is the sensitivity-weighted multicoil image combination of the zero-filled Fourier reconstruction of the undersampled data. \nA joint reconstruction is performed over all coils and all temporal frames. \nCS reconstruction minimizes the functional shown in Equation~\\ref{eq: CS2}:\n%.........................................................\n\\begin{equation}\\label{eq: CS2}\nf\\left(\\mathbf{I}\\right) = \\min_{\\mathbf{I}} |{\\mathcal{F}_{\\mathrm{su}} \\mathbb{C} \\cdot \\mathbf{I} - \\mathbb{K}| _{2}^{2}} + \\lambda_{\\mathcal{F}/\\mathcal{PCA}} |{\\mathcal{W}_{\\mathcal{F}/\\mathcal{PCA}} \\cdot \\mathbf{I}}|_1\n\\end{equation}\n%.........................................................\nwhere $\\mathbf{I}$ (current reconstructed image) and $\\mathbb{K}$ (acquired undersampled \\mbox{\\textit{k-}space} data) are defined according to Equations~\\ref{eq: CS3}~and~\\ref{eq: CS4} respectively:\n%.........................................................\n\\begin{equation}\\label{eq: CS3}\n\\mathbf{I} = \\begin{bmatrix} \n    \\mathbf{i}_{11} & \\dots & \\mathbf{i}_{t1} \\\\\n    \\vdots & \\ddots & \\\\\n    \\mathbf{i}_{1N} &        & \\mathbf{i}_{tN} \n    \\end{bmatrix}\n\\end{equation}\n%.........................................................\n%.........................................................\n\\begin{equation}\\label{eq: CS4}\n    \\mathbb{K} =\\mathcal{F}_{\\mathrm{su}} \\mathbb{C} \\cdot \\mathbf{I} = \\begin{bmatrix} \n    \\mathbf{k}_{11} & \\dots & \\mathbf{k}_{t1} \\\\\n    \\vdots & \\ddots & \\\\\n    \\mathbf{k}_{1N} &        & \\mathbf{k}_{tN} \n    \\end{bmatrix}\n\\end{equation}\n%.........................................................\nwith $N$ being the number of coils and $t$, the number of temporal frames and $\\mathcal{F}_{\\mathrm{su}}$ and $\\mathbb{C}$ are the spatially undersampled Fourier operator and coil sensitivity vector respectively defined by Equations~\\ref{eq: CS5}:\n%.........................................................\n\\begin{equation}\\label{eq: CS5}\n    \\mathcal{F}_{\\mathrm{su}} = \\begin{bmatrix} \n    \\mathrm{F_{su}}^{1} \\\\\n    \\vdots \\\\\n    \\mathrm{F_{su}}^{t}\n    \\end{bmatrix} , \\quad \\mathbb{C} = \\left[ \\mathrm{C}_1 \\dots \\mathrm{C}_N \\right]\n\\end{equation}\n%.........................................................\nThe functional in Equation~\\ref{eq: CS1} was minimized using a nonlinear conjugate gradient method~\\cite{Lustig:2007cua}. \nThe $\\ell_1$ norm term (second term on LHS) maximizes the sparsity in the transform domain, $\\mathcal{W}_{\\mathcal{F}/\\mathcal{PCA}}$ is the sparsifying transform (temporal FT in the first stage and PCA in the second stage of CS reconstruction), the $\\ell_2$ norm (first term on LHS) ensures data fidelity between the estimated image and the acquired data, and $\\lambda_{\\mathcal{F}/\\mathcal{PCA}}$ is the regularization parameter whose value controls the balance between image sparsity and image fidelity.\n%-new paragraph-%\n\n%-new paragraph-%\nThe CS reconstruction was performed offline using in-house built software developed in MATLAB (version R2018b. The MathWorks Inc. MA, USA) running on macOS (version 10.14.5 Apple Inc. CA, USA). \nUsing a computer with Intel Core i5 CPU at $\\SI{3.5}{\\giga\\hertz}$ with $\\SI{16}{\\gibi\\byte}$ global memory, the total computational time was $\\sim \\SI{30}{\\minute}$ for each series.\n%-new paragraph-%\n\n%-new paragraph-%\n%`````````````````````````````````````````````````````````\n\\textit{Optimization:}\n%`````````````````````````````````````````````````````````\r\n The regularization parameters $\\lambda$ and the number of iterations for the temporal FT and for the temporal PCA of the CS reconstruction were optimized independently for the flow phantom data and for the muscle data. \n The acquired undersampled images were used for phantom optimization while simulated undersampled images were used in the muscle data optimization. \n The latter choice was based on the fact that comparing the reference to the acquired undersampled images may be biased by small differences in the contraction patterns in two separate acquisitions. \n Optimization was performed to minimize the Root Mean Square Error (RMSE) in velocity estimated from the difference between the velocity from the full \\mbox{\\textit{k-}space} and from the undersampled \\mbox{\\textit{k-}space} data. \n For the phantom, the velocity was estimated in the three flow tubes while for the muscle data, the velocity was estimated in a region of interest (ROI) [20 pixels $\\times$ 7 pixels $= \\SI{23}{\\milli\\meter} \\times \\SI{8}{\\milli\\meter}$] placed in the medial gastrocnemius. \n The optimization was performed for each CS acceleration factor stepping through a grid of values for $\\lambda$ and the number of iterations in the following range: \n%.........................................................\n\\begin{align}\\label{eq: CS6}\n\\lambda_{\\mathcal{F}} = \\left[ 0.01, 0.10\\right], \\Delta_{\\lambda} = 5\\times10^{-3} \\qquad & \\mathcal{F}_\\text{ite} = [10;30], \\Delta_{\\text{ite}}=5 \\\\\n\\lambda_{\\mathcal{PCA}} = \\left[ 0, 0.10\\right], \\Delta_{\\lambda} = 5\\times10^{-3} \\qquad & \\mathcal{PCA}_\\text{ite} = [10;30], \\Delta_{\\text{ite}}=5 \n\\end{align}\n%.........................................................\n%---------------------------------------------------------\n\\subsubsection{Static and flow phantom}\n%---------------------------------------------------------\nThree tubes (diameter of 1cm) with constant flow were wound around a static water phantom such that the flow in the tubes was perpendicular to the image plane and opposite to each other (Figure~\\ref{fig: CSS1}a-d).\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=1\\textwidth]{Figures/CS1_3.pdf}\n\\caption[Rendering of the constant flow phantom and optimization plots]{Rendering of the constant flow phantom used to validate velocities calculated from the CS reconstructed images (a - d). Water flow directions are denoted by arrows. Velocity measurements were performed in the axial orientation (d). Optimization plots (e) for flow in the anterior and (f) posterior tubes for few best combinations.}\n\\label{fig: CSS1}\n\\end{figure}\n%*********************************************************\nAxial slices were acquired ensuring that the flow through the tubes was orthogonal to the plane of the image. \nThe static~/~flow phantom was imaged with the full \\mbox{\\textit{k-}space} acquisition and with the undersampled acquisitions (eight different combinations of CS acceleration factors and views per segment). \nThree different in-flow velocities were set for the phantom: 2.5, 5 and $\\SI{7.5}{\\centi\\meter/\\second}$ and verified using the flowmeter~1G08~R3 (Cole-Parmer, IL, USA) resulting in 6 different (3 velocity magnitudes $\\times$ 2 opposite directions $= 6$) flow velocities available for measurements using VEPC images.\n%---------------------------------------------------------\n\\subsubsection{\\textit{In-vivo} human subject imaging: }\n%---------------------------------------------------------\nEleven subjects (5 male and 6 female) were included in this study after written informed consent had been obtained. \nThe criterion for inclusion was that subjects should be moderately active and those with any surgical procedures performed on the lower leg were excluded. \nAll subjects were normal, healthy volunteers. \nThe study was carried out under the approval of the Medical Research Ethics Board of UC San Diego, and conformed to all standards for the use of human subjects in research as outlined in the Declaration of Helsinki on the use of human subjects in research.\n%-new paragraph-%\n\n%-new paragraph-%\nMagnetic resonance imaging was performed on a $\\SI{1.5}{\\tesla}$ Signa HD16 MR scanner (GE Medical Systems, WI, USA), with the subject lying supine, feet first, with the right leg (i.e., the dominant leg to be imaged) resting against foot pedal~\\cite{RNSS10}. \nAn optical fiber pressure transducer was glued to the foot pedal placed inside 8-channel radiofrequency coil. \nPressure exerted against the foot pedal during isometric contraction was detected by the transducer, converted to a voltage by a spectrometer (Luna Innovations, VA, USA), and used to trigger the MR image acquisition using in-house built software developed in LabVIEW (National Instruments Inc, TX, USA). \nFor data analysis, the voltage output from the pressure transducer was later converted into units of force [$\\SI{}{\\newton}$] based on a calibration of the system using disc weights. \nImages were acquired during sub-maximal, isometric contraction at 35\\% of the individual maximum voluntary isometric contraction (MVIC). \nThe MR image acquisition was completed in approximately 53 cycles for the full \\mbox{\\textit{k-}space} acquisition and the number of cycles ranged from 44 to 13 cycles for the accelerated scans; thus, it was important to ensure consistency of motion. \nThis was ensured by providing the subject with real-time visual feedback of the actual force generated by the subject superposed on the target force curve to facilitate consistent contractions~\\cite{Malis:2018fr}.\n%---------------------------------------------------------\n\\subsubsection{Magnetic resonance imaging}\n%---------------------------------------------------------\nThe MR images used in this report included a localizer scan to identify the oblique sagittal orientation that best depicted the fascicles in the medial gastrocnemius. \nThe acquisition parameters for the reference full \\mbox{\\textit{k-}space} VEPC acquisition was: echo time (TE):~$\\SI{7.7}{\\milli\\second}$, repetition time (TR):~$\\SI{17.8}{\\milli\\second}$, signal averages (NEX):~2, flip angle (FA):~$\\SI{20}{\\degree}$, slice thickness:~$\\SI{5}{\\milli\\meter}$, field of view (FOV):~$\\SI{30}{\\centi\\meter} \\times \\SI{22.5}{\\centi\\meter}$ (partial phase FOV: 0.55), matrix:~$256 \\times 192$ (lower resolution in the phase direction), 4 views per segment (VPS), 3~slices, 17~temporal frames (with view sharing factor = 2), $\\SI{10}{\\centi\\meter/\\second}$ 3D velocity encoding. \nThis resulted in 53 repetitions [192 (phase encode) $\\times$ 2 (averages) $\\times$ 0.55 (phase FOV)) / 4 (views per segment) = $53$] for each slice acquisition. \nThe temporal resolution is calculated as: 17.8(TR) $\\times$ 4 (VPS) $\\times$ 4 (3 velocity encoding directions + 1 flow compensated) / 2 (view sharing) $ = \\SI{142}{\\milli\\second}$. \nSeventeen temporal frames were collected within each isometric contraction-relaxation cycle of $\\sim \\SI{2.4}{\\second}$ $(17 \\times \\SI{142}{\\milli\\second}  = \\SI{2.4}{\\milli\\second})$. \nIt should be noted that, in the reference sequence, the actual acquired number of temporal frames is only 8 with an acquired temporal resolution of $\\SI{285}{\\milli\\second}$. \nFor all the undersampled sequences, the geometry parameters were the same as in the original sequence while the number of phase-encode steps was decreased by the CS acceleration factors between 2 to 4 while varying views per segment between 2 and 4 as well. \nIt should be noted that views per segment of 2 in the CS acquisitions increased the acquired temporal resolution by a factor of 2 compared to full \\mbox{\\textit{k-}space} acquisition (4 views per segment). \nThe maximum \\mbox{CS\\textit{-factor}} achievable was determined from a simulation of a full \\mbox{\\textit{k-}space} data of muscle contraction. \n%-new paragraph-%\n\n%-new paragraph-%\nFlow phantom acquisition parameters were same as for the human scans with the only difference being that the cycle length was $\\SI{2}{\\second}$ resulting in 14 temporal frames.\n%---------------------------------------------------------\n\\subsubsection{Image and Statistical Analysis}\n%---------------------------------------------------------\nPhase images were corrected for phase shading (mean background phase error) and denoised with a 2D anisotropic diffusion filter~\\cite{RNCS17} to yield the velocity images. \nPhase shading was estimated by averaging all of the dynamic images in the cine sequence. \nThis was based on the assumption that the net change in position (and therefore net velocity) over the isometric contraction-relaxation cycle was zero. \nThe average image was subtracted from the phase image at each temporal frame. \n%-new paragraph-%\n\n%-new paragraph-%\nThe ($2 \\times 2$) SR tensor was calculated from the spatial gradient of the velocity images and then diagonalized to obtain the eigenvalues and eigenvectors~\\cite{RNS16, Malis:2018fr}. \nEigenvalues ($SR_{\\mathrm{fiber}}$, $SR_{\\mathrm{in-plane}}$) were sorted on a voxel basis. \n$SR_{\\mathrm{fiber}}$ denotes deformation approximately along the muscle fiber long axis and is negative during muscle fiber shortening (contraction during phases 1-8 of reference VEPC sequence) and positive during relaxation (phases 9-17 of reference VEPC sequence). \n$SR_{\\mathrm{in-plane}}$ denotes deformation in the muscle fiber cross-section and is positive during muscle fiber shortening and negative during relaxation.\n%-new paragraph-%\n\n%-new paragraph-%\nRegions of interest were placed in the anterior and posterior tubes of the flow phantom were used to measure the velocity in the tubes for a range of flow in the phantom. \nBland-Altman plots were used to analyze the velocities from the acquisitions with different VPS/CS combinations using the flowmeter velocity values as the reference. \n\\textit{In-vivo} velocity and strain rate data were extracted and analyzed for the ROI [20px $\\times$ 7px = $\\SI{23}{\\milli\\meter}$ $\\times$ $\\SI{8}{\\milli\\meter}$] placed in the medial gastrocnemius. \nIn order to ensure that the same anatomic region was sampled, each pixel in the ROI placed in the first temporal frame was tracked (with respect to the first frame) to locate the new pixel positions in successive frames, creating a frame-based ROI. \nTracking was performed in 2D using the in-plane velocity information. \nThe position in a subsequent frame was calculated based on the velocity information in the current frame. \nThis allowed automated placement of an ROI in each frame that moved synchronously with the underlying anatomy. \nROIs changed both location and shape (5 to 20\\% in successive frames) but the number of points was kept constant to ensure average values were based on the same number of points~/~frame. \nBland-Altman analysis was performed on strain rate data comparing that derived from reference full \\mbox{\\textit{k-}space} values to that obtained from undersampled sequences.\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Results}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nFigure~\\ref{fig: CSS2} shows, for one example subject, the average of the force measured in a full reference acquisition and for the undersampled acquisition (VPS/\\mbox{CS\\textit{-factor}}: $4/4$) over the contraction cycle. \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_4.pdf}\n\\caption[Averaged force curve for the fully sampled acquisition and undersampled acquisition]{Averaged force curve with lower and upper boundary given as mean $\\pm$ standard deviation for the fully sampled acquisition with 52 contractions cycles (left) and undersampled acquisition with 13 contractions cycles (right).}\n\\label{fig: CSS2}\n\\end{figure}\n%*********************************************************\nThe upper and lower bound curves were generated by plotting points at mean $\\pm$ standard deviation (SD) at each sampled point of the force output. \nWhile the range of upper and lower bound of the force during the contractions was not significantly different between the undersampled and full \\mbox{\\textit{k-}space}, the FWHM of the mean force is lower for the undersampled acquisition. \nFigure~\\ref{fig: CSS3} shows an example velocity (phase) image from an undersampled acquisition (VPS/\\mbox{CS\\textit{-factor}}: $2/4$) and the denoised image after application of the 2D anisotropic diffusion filter. \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[scale=0.15]{Figures/CS1_5.pdf}\n\\caption[Velocity maps before and after 2D anisotropic diffusion filter]{Velocity maps before (a) and after (b) 2D anisotropic diffusion filter was applied for the frame corresponding to the peak of contraction cycle. Image shown on the left was acquired with a VPS/\\mbox{CS\\textit{-factor}} of 2/4. Parameters of anisotropic diffusion filter: $\\kappa = 2$ , $\\Delta = 1/7$  and 10 iterations.}\n\\label{fig: CSS3}\n\\end{figure}\n%*********************************************************\nThe reduction in velocity (phase) noise is visually evident in the denoised image. \nFigure~\\ref{fig: CSS4} shows the efficacy of the phase correction using the temporally averaged phase map on select frames of the dynamic cycle: the corrected frames show that the first and last frames are close to zero velocity (small discrepancies in the first and last frame arise from the fact the first frame is shifted compared to the start of the acquisition). \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_6.pdf}\n\\caption[Selected frames of phase images for the direction of maximum velocity before and after correction for phase shading artifacts]{Selected frames of phase images for the direction of maximum velocity before (top row) and after (bottom row) correction for phase shading artifacts. The phase averaged image shown on the right is subtracted from each frame of the acquired images to generate the corrected images.}\n\\label{fig: CSS4}\n\\end{figure}\n%*********************************************************\r\nTwo sparsifying transforms were used in the current study to improve image quality in the reconstructed images. \nThe fully sampled dynamic magnitude data was undersampled in the $k_y$\\textit{-t} plane to compare the sparsity provided by the temporal FT and temporal PCA transforms. \nFigure~\\ref{fig: CS4} shows the images after the temporal FT and after the temporal PCA transform respectively and these images illustrate the higher sparsity of the PCA transform.\n%*********************************************************\n\\begin{sidewaysfigure}\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=8.5in]{Figures/CS1_7.pdf}\n\\captionsetup{width=8.5in}\n\\caption[Magnitude images and images after performing a temporal FFT and a temporal PCA transformations]{Magnitude images from a dynamic muscle scan based on the VEPC sequence: top row. Images after performing a temporal FFT (middle row) and a temporal PCA (bottom row) on the magnitude images. Middle (temporal FFT) and bottom (temporal PCA) have same intensity windowing.}\n\\label{fig: CS4}\n\\end{sidewaysfigure}\n%*********************************************************\nThis is seen by the smaller number of images with non-zero coefficients in the PCA transform compared to the images in the FT transform. \r\n%-new paragraph-%\n\n%-new paragraph-%\nThe results of the optimization of the regularization, $\\lambda_{\\mathcal{F}}$ and $\\lambda_{\\mathcal{PCA}}$ and iteration parameters for each stage using the phantom image data are shown in Figure~\\ref{fig: CSS1}e,~f. \nFigure~\\ref{fig: CSS1}e shows the optimization results for velocity estimated in the anterior tubes while Figure~\\ref{fig: CSS1}f is the corresponding result for the tubes placed posteriorly. \nThe root mean square of the difference (RMSE) in velocities (as a function of time in the dynamic cycle) measured in the constant flow phantom between reference full \\mbox{\\textit{k-}space} and undersampled \\mbox{\\textit{k-}space} was used as the metric for optimizing weights. \nThe optimization was performed using undersampled data acquired with \\mbox{CS\\textit{-factor}} of 4, and VPS of 2. \nThe plots are shown close to the minimum RMSE values since the total number of combinations of the parameters was large (503 combinations). \nAt the optimal setting, the lowest values of 0.4\\% was seen for the anterior tubes and $\\sim 0.1\\%$ for the posterior tubes confirming that the CS reconstruction was able to accurately reproduce velocities. \nThe combination of values that minimized the RMSE was chosen as optimal and used for the rest of the phantom CS reconstructions. \nFigure~\\ref{fig: CSS5} is the Bland-Altman plot of the velocities from the full \\mbox{\\textit{k-}space} acquisition and from undersampled acquisitions using 8 combinations of CS accelerations and VPS factors with the flowmeter values as the reference velocities. \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=\\textwidth]{Figures/CS1_8.pdf}\n\\caption[Bland-Altman plots for velocity measurements for the constant flow phantom]{Bland-Altman plots for velocity measurements averaged in three regions of interest for the constant flow phantom for six different velocities. Measurements were performed for nine different combinations of views-per-segment (VPS) and undersampling factors (\\mbox{CS\\textit{-factor}}), flowmeter measurements are used as reference.}\n\\label{fig: CSS5}\n\\end{figure}\n%*********************************************************\nThe agreement is high with the mean of the differences close to zero or with a small underestimation of $\\SI{0.1}{\\centi\\meter/\\second}$ for the different undersampled acquisitions compared to the flowmeter values. \nThe 95\\% confidence intervals across the different VPS/CS combinations range from $\\pm \\SI{0.25}{\\centi\\meter/\\second}$ to $\\pm \\SI{0.4}{\\centi\\meter/\\second}$. \nNotably, the mean difference of the velocities is dependent on the mean velocity; this dependency was attributed to the errors in the reference flowmeter velocity that increased with velocity. \nHowever, the \\% difference between reference flowmeter and undersampled velocities was less than 2\\% for any of the VPS/CS combinations. \n%-new paragraph-%\n\n%-new paragraph-%\nThe optimization for the muscle data for the \\mbox{CS\\textit{-factor}} of 4 is shown in Figure~\\ref{fig: CS5}. \n%*********************************************************\n\\begin{figure}[!hb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_9.pdf}\n\\caption[Optimization of the compressed sensing parameters in human subject]{Optimization of the CS parameters in human subject. Each column represents each of the three orthogonal directions: $x$, $y$ (in-plane) and $z$ (out of plane). The plots of the velocities (top row), bottom row is the root-mean-squared error (RMSE) for each of the velocities. Plots with few best combinations only are shown here.}\n\\label{fig: CS5}\n\\end{figure}\n%*********************************************************\nThe root-mean-square velocity at the peak of the contraction (in the large ROI placed in the MG) was used in calculating the RMSE for the optimization. \nTable~\\ref{tab: CSS1} lists the regularization/iteration parameters for both steps of the reconstruction algorithm. \n%=========================================================\n\\begin{table}[!htb]\n\\vspace{+0.2cm}\n\\caption[Reconstruction parameters obtained for imaging sequences with different undersampling factors]{Reconstruction parameters obtained for imaging sequences with different undersampling factors.}\n\\label{tab: CSS1}\n\\begin{center}\n\\begin{tabular}{@{}ccccc@{}}\n\\toprule[1pt]\\midrule[0.3pt]\n\\mbox{CS\\textit{-factor}} & $\\lambda_{\\mathcal{F}}$ & $\\mathcal{F}_{\\mathrm{ite}}$ & $\\lambda_\\mathcal{PCA}$ & $\\mathcal{PCA}_{\\mathrm{ite}}$ \\\\ \\midrule\n4         & 0.025  & 20   & 0.025      & 30      \\\\\n3         & 0.015  & 10   & 0.015      & 30      \\\\\n2.4       & 0.010  & 10   & 0.010      & 20      \\\\\n2         & 0.010  & 10   & 0          & 0       \\\\ \\midrule[0.3pt]\\bottomrule[1pt]\n\\end{tabular}\n\\end{center}\n\\vspace{-0.2cm}\n\\end{table}\n%=========================================================\nThe value of ($\\lambda_{\\mathcal{F}/\\mathcal{PCA}}$) and number of iterations decreased with the decrease in acceleration factors. \nOnce the optimization was performed on one subject's muscle data, these parameters are used for the CS reconstruction of all \\textit{in-vivo} data; the optimal parameters corresponding to each CS acceleration was chosen from Table~\\ref{tab: CSS1}. \n%-new paragraph-%\n\n%-new paragraph-%\nFigure~\\ref{fig: CS6} compares the phantom (static and flow) images acquired with the full \\mbox{\\textit{k-}space}, simulated and actual undersampled data acquired with \\mbox{CS\\textit{-factor}} of 4 at select temporal frames. \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_10.pdf}\n\\caption[Velocity colormaps of the constant flow phantom at five temporal frames]{Velocity colormaps of the constant flow phantom at five temporal frames. The first row (fully sampled) velocity data, simulated undersapmpled (second row) and the acquired undersampled (third row) velocity data. RMSE maps of the difference in velocities of images in the first and third rows (last row).}\n\\label{fig: CS6}\n\\end{figure}\n%*********************************************************\nIn the undersampled images, the static phantom is mapped correctly to values close to zero velocity (green shade in the color map) while flow out of the imaging plane is in red shade and into the imaging plane is in blue shade. \nThe visual similarity of the fully sampled and undersampled velocity images is clearly evident. \nThis is also confirmed by the root mean square error map of the fully sampled and acquired undersampled images shown in the last row. \nThe flow phantoms are not visible on the RMSE maps (showing very close agreement between the velocities from full \\mbox{\\textit{k-}space} and undersampled \\mbox{\\textit{k-}space}) and there is only the background static phantom with very small RMSE errors. \n%-new paragraph-%\n\n%-new paragraph-%\nFigure~\\ref{fig: CSS6} shows simulated muscle data from random undersampling (CS factors of 4 and 6) and the resultant magnitude images after CS reconstruction.\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_11.pdf}\n\\caption[Selected frames of magnitude images reconstructed from the fully-sampled, undersampled \\mbox{\\textit{k-}space} with factors 4 and 6]{Selected frames of magnitude images reconstructed from the fully-sampled \\mbox{\\textit{k-}space} (top row), undersampled \\mbox{\\textit{k-}space} with factors 4 (middle row) and 6 (bottom row).}\n\\label{fig: CSS6}\n\\end{figure}\n%********************************************************* \nThe presence of artifacts at CS factor of 6 is visually evident. \nColor coded muscle velocity images of the fully sampled and the acquired undersampled images are shown in Figure~\\ref{fig: CS7} as a function of the isometric contraction cycle for 17 temporal frames.\nThese are oblique sagittal images positioned to obtain the fibers of the medial gastrocnemius (MG) in the plane of the image. \nThe two stage CS reconstruction using the optimized parameters based on muscle velocity images resulted in undersampled images that were visually close to the images reconstructed from fully sampled \\mbox{\\textit{k-}space} data. \nThe spatial and temporal patterns of velocity are very similar for the full \\mbox{\\textit{k-}space} and the undersampled acquisitions.\n%*********************************************************\n\\begin{sidewaysfigure}\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=8.5in]{Figures/CS1_12.pdf}\n\\captionsetup{width=8.5in}\n\\caption[Velocity colormaps for all three orthogonal directions in the oblique sagittal section through the calf muscles]{Velocity colormaps for all three orthogonal directions in the oblique sagittal section through the calf muscles; The fully sampled (top section) followed by undersampled (by a factor of $\\times 4$) reconstructed using the parameters obtained through the optimization process.}\n\\label{fig: CS7}\n\\end{sidewaysfigure}\n%*********************************************************  \nThe velocity in the image $y$-axis is the highest as this corresponds to the superior to inferior (SI) direction and the lowest velocity is in the $z$-direction which maps the out-of-plane motion. \nThe blue shades are negative velocities around the peak of the isometric contraction (temporal frames 4 to 8) and the red shades are positive velocities at the peak of the relaxation (temporal frames 12 to 16).\nFigure~\\ref{fig: CS8} is a plot of the $v_y$ velocity component (averaged over the eleven subjects) as a function of the dynamic cycle measured in ROIs placed in the MG extracted from the full \\mbox{\\textit{k-}space} as well as from the undersampled \\mbox{\\textit{k-}space} with the different CS and VPS factors.\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=\\textwidth]{Figures/CS1_13.pdf}\n\\caption[Velocity $v_y$ plots as a function of the isometric contraction for scans acquired with 8 different VPS/\\mbox{CS\\textit{-factor}}]{Velocity $v_y$ plots as a function of the isometric contraction for scans acquired with 8 different VPS/\\mbox{CS\\textit{-factor}}. The values are the mean over the eleven subjects, the green shaded region reflects mean $\\pm$ standard deviation. The red line is the mean (average of subjects) for the full \\mbox{\\textit{k-}space} acquisition.}\n\\label{fig: CS8}\n\\end{figure}\n%********************************************************* \nThe good agreement between the $v_y$ values from the reference and undersampled acquisitions is confirmed by the overlay of the mean $v_y$ from full \\mbox{\\textit{k-}space} on the $v_y \\pm \\sigma$ (average over 11 subjects) from the undersampled acquisitions. \n%-new paragraph-%\n\n%-new paragraph-%\nOne of the goals of velocity mapping is to derive the strain or strain rate tensor to study muscle kinematics. \nIt is important to note that both strain and strain rate are sensitive to noise as spatial gradients are calculated from the velocity or displacement maps to extract strain~/~strain rate; the use of the anisotropic diffusion filter to denoise was critical to the calculation of the strain rate maps (Figure~\\ref{fig: CSS3}). \nFigure~\\ref{fig: CS9} shows strain rate images (absolute values at the peak value in the contraction phase) calculated from the velocity maps acquired with different combinations of CS and VPS factors; SR image quality is maintained at the highest acceleration factors. \n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{Figures/CS1_14.pdf}\n\\caption[Absolute value strain rate tensor eigenvalue colormaps derived from velocity images for 4 different combinations of VPS/\\mbox{CS\\textit{-factor}}]{Absolute value strain rate tensor eigenvalue colormaps derived from velocity images for 4 different combinations of VPS/\\mbox{CS\\textit{-factor}}. The $SR_\\mathrm{fiber}$ and $SR_\\mathrm{in-plane}$ correspond to the strain rate maps along and perpendicular to the fiber direction respectively; shown here is one temporal frame at the peak of the contraction phase.}\n\\label{fig: CS9}\n\\end{figure}\n%********************************************************* \nBland-Altman plots (Figure~\\ref{fig: CS10}) and the indices extracted from these plots (Table~\\ref{tab: CS2}) show good agreement between the full \\mbox{\\textit{k-}space} acquisition and the subsampled acquisitions (average of mean differences ranges from 0.5\\% to 6.7\\% across the VPS/\\mbox{CS\\textit{-factor}} combinations).\n%*********************************************************\n\\begin{figure}[!htb]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=\\textwidth]{Figures/CS1_15.pdf}\n\\caption[Bland-Altman plots for the peak $SR_\\mathrm{fiber}$ values during the contraction part of the cycle for 6 different combinations of VPS/\\mbox{CS\\textit{-factor}}]{Bland-Altman plots for the peak $SR_\\mathrm{fiber}$ values during the contraction part of the cycle for 6 different combinations of VPS/\\mbox{CS\\textit{-factor}}. Mean value between fully sampled and undersampled data is shown in blue, the 95\\% confidence interval is shown in dotted red lines.}\n\\label{fig: CS10}\n\\end{figure}\n%********************************************************* \n%=========================================================\n\\begin{table}[!htb]\n\\vspace{+0.2cm}\n\\caption[Parameters obtained from the Bland-Altman plots of peak strain rates for seven different combinations of views per segment and undersampling factors]{Parameters obtained from the Bland-Altman plots (Figure~\\ref{fig: CS10}) of peak strain rates for seven different combinations of views per segment (VPS) and undersampling factors (\\mbox{CS\\textit{-factor}}).}\n\\label{tab: CS2}\n\\begin{center}\n\\begin{tabular}{@{}ccccccc@{}}\n\\toprule[1pt]\\midrule[0.3pt]\n$\\mathbf{<SR>}$     & $\\mathbf{\\Delta_{SR}}$ & $\\mathbf{<\\hat{SR}> \\%}$ & ${CR}$    & ${\\hat{CR}} \\%$ & VPS & \\mbox{CS\\textit{-factor}} \\\\ \\midrule\n$-712.4$ & $-13.7$    \t& 1.9   \t& 249.3 & 35.0   \t& 4   & 2                  \\\\\n$-730.0$ & 4.0        \t& $-0.5$  \t& 187.5 & 25.7  \t\t& 4   & 4                  \\\\\n$-778.2$ & 52.1     \t& $-6.7$  \t& 176.1 & 22.6  \t\t& 2   & 4                  \\\\\n$-768.4$ & 42.3     \t& $-5.5$  \t& 271.9 & 35.4  \t\t& 4   & 3                  \\\\\n$-708.5$ & $-17.6$    \t& 2.5   \t& 269.2 & 38.0    \t& 2   & 2.4                \\\\\n$-681.4$ & $-44.7$    \t& 6.6   \t& 275.5 & 40.4  \t\t& 2   & 3         \\\\ \\midrule[0.3pt]\\bottomrule[1pt]\n\\end{tabular}\n\\end{center}\n\\vspace{-0.2cm}\n\\end{table}\n%=========================================================\nTable~\\ref{tab: CS2} lists the following values: mean strain rate (mean of reference and undersampled SR values) $\\mathbf{<SR>}$, mean of the paired $\\mathrm{differences}\\colon$ $\\mathbf{<\\Delta_{{SR}}}>$ , \\% normalized mean of the paired differences: $\\mathbf{<\\hat{SR}> \\%} = 100 \\times \\mathbf{<SR>}/\\mathbf{\\Delta}_{\\mathbf{SR}}$, Coefficient of Repeatability: $CR = 1/2 \\times \\left( \\mathrm{upper \\; 95\\%} CI - \\mathrm{lower \\; 95\\%} CI \\right)$, \\% normalized : $=\\hat{CR} \\% = 100 \\times CR / \\mathbf{<SR>}$. \\textit{CI}: Confidence Interval. Units of $\\mathbf{<SR>}, \\mathbf{<\\Delta_{{SR}}>}$, and ${CR}$ are in $\\left[ \\mathrm{s}^{-1} \\right]$ while the normalized quantities are unitless.\nThe small mean differences confirm that the bias in the subsampled data compared to the full \\mbox{\\textit{k-}space} data is small. \nThe normalized coefficient of repeatability was $\\sim 24\\%$ for the $\\mathrm{CS}=4$ undersampling.\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Discussion}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nCompressed sensing has been integrated in VEPC sequences~\\cite{RNCS9, RNCS10} and applied to measuring flow in the cardiovascular system and offers a range of acceleration factors. \nOne of the first report in combining compressed sensing with multicoil acquisition in a VEPC sequence was the $k_y$\\textit{-t} SPARSE SENSE approach~\\cite{RNCS9, RNCS10}. \nThey used a two-stage compressed sensing scheme with a temporal FT as the sparsifying transform for the first stage and a temporal PCA for the sparsifying transform for the second stage. \nA recent study reported a compressed sensing accelerated 4D (3D spatial with 3 directional velocity encoding) phase contrast MRI using random undersampling patterns in the $k_y$-$k_z$ plane~\\cite{RNCS11}.\nThe latter work reported acceleration factors of $\\sim \\times 6.4$ without loss of accuracy in velocity or in the derived strain rate maps. \n3D acquisition enables higher acceleration factors but in order to realize the higher accelerations, it is important to have a large number of slices and this offsets the time gain from the higher acceleration factors. \nFor example, the undersampled 3D VEPC sequence discussed above reached an acceleration factor of $\\sim \\times 6.4$ for a 32-slice acquisition (scan time: $\\SI{2}{\\minute}$ $\\SI{46}{\\second}$)~\\cite{RNCS11}. \nThe undersampled 2D VEPC sequence presented in the current study has an acceleration factor of 4 and is completed~in~$\\SI{40}{\\second}$.\n%-new paragraph-%\n\n%-new paragraph-%\nThe current work extends the $k_y$\\textit{-t} SPARSE SENSE method to 3 directional velocity encoded acquisition applied to the study of muscle kinematics (velocity and strain rate mapping) during isometric contraction to achieve scan times less than a minute. \nIt should be noted, that for the current study, the imaging plane was chosen such that the medial gastrocnemius fibers were in the imaging plane. \nThis ensured that the velocity perpendicular to the slice was close to zero and it should thus be possible to obtain the velocity information with 2 directional velocity encoding. \nHowever, a 3 directional velocity encoding was implemented as it is not always possible to choose the slice orientation to be in the plane of the muscle fibers.\nThe goal of the undersampled VEPC reported here is to enable the sequential acquisition of 3-5 slices to extract the full $3 \\times 3$ strain~/~strain rate tensor. \nThe reduction in scan time per slice will translate in the ability to image several slices. \n%-new paragraph-%\n\n%-new paragraph-%\nThe original papers that proposed PCA as the single sparsifying transform required training data~\\cite{RNCS18, RNCS19, RNCS20}. \nSubsequently, a bootstrapping method was proposed that self-calibrated the PCA without the use of training data. \nThis two-step bootstrap reconstruction method using temporal FFT followed by temporal PCA was initially proposed by Jung and Ye~\\cite{RNCS14} and then applied for reconstructing undersampled cardiac $\\mathrm{T_2}$ mapping~\\cite{RNCS21} and for cine phase contrast imaging~\\cite{RNCS10}. \nComparison of the temporal FT and the temporal PCA in single step sparsifying transforms showed that temporal PCA was superior ~\\cite{RNCS10, RNCS21}. \nFurther, Feng et~al.~\\cite{RNCS21} reported that their preliminary results showed that the two-step method was better than the direct PCA approach. \nThis was attributed to the fact that an accurate PCA basis cannot be directly estimated because a set of low frequency \\mbox{\\textit{k-}space} frequencies was not fully sampled~\\cite{RNCS10, RNCS21}. \nBased on the results of these earlier studies, the current study implemented the two-step reconstruction using the temporal FFT as the first step sparsifying transform and the temporal PCA as the second sparsifying transform. \r\nOptimization of the regularization parameter and number of iterations for each step was performed using acquired undersampled data for the phantom whereas the optimization for the human subject data was performed on simulated undersampled data from a full \\mbox{\\textit{k-}space} acquisition. \nThe approach for the human data was based on the fact that physiological variations in repeat dynamic studies of muscle contraction would influence the repeatability and this would have biased the optimization. \nIn the phantom, the minimum RMSE in velocity with the full \\mbox{\\textit{k-}space} as the reference for the optimum values of the regularization parameters was less than 0.5\\%, whereas the corresponding minimum RMSE (averaged over the cycle) for $v_y$ (velocity along the longitudinal muscle axis) from muscle data was around 5\\%. \nA comprehensive search of a matrix of combinations of $\\lambda_{\\mathcal{F}}$, $\\lambda_{\\mathcal{PCA}}$ and the corresponding number of iterations in each step was performed. \nThe value of $\\lambda_{\\mathcal{PCA}}$ for optimizing the flow in the femoral artery~\\cite{RNCS9, RNCS10} was 0.01 for a \\mbox{CS\\textit{-factor}} of 6.3 while in the current study, for the flow phantom, it is 0.075 and for the \\textit{in-vivo} muscle velocities, 0.025 for a \\mbox{CS\\textit{-factor}} of 4. \nFurther, the regularization parameters changed with the acceleration factor. \nThe optimization results emphasize the need for optimization for datasets with different velocities, background signals, and \\mbox{CS\\textit{-factor}}. \r\n%-new paragraph-%\n\n%-new paragraph-%\nThe velocities derived from the VEPC images of the flow phantom for the reference acquisition and for the different combinations of CS and VPS were very well correlated with velocities measured by the flowmeter. \nThis is also confirmed in the phantom images where the RMSE images obtained from the reference (full \\mbox{\\textit{k-}space}) and undersampled acquired data (\\mbox{CS\\textit{-factor} = 4}) show that the velocities in the undersampled images are accurately reconstructed (no difference in the velocities estimated by the two methods). \n%-new paragraph-%\n\n%-new paragraph-%\nThe average force curves at the MVIC used in the current study (35\\% MVIC) showed that the standard deviation of the force (measure of the consistency of contractions) is comparable for the fully sampled \\mbox{\\textit{k-}space} and the undersampled acquisition. \nIt is highly likely though that differences in the standard deviation of the force will be more pronounced at higher \\%MVICs, for the elderly and for subjects with compromise in muscle function; in all these cases it will be harder to maintain consistency for larger repetitions. \nVisually good agreement of the muscle velocity images acquired with the full \\mbox{\\textit{k-}space} and the undersampled \\mbox{\\textit{k-}space} data (\\mbox{CS\\textit{-factor} = 4}) confirm that the proposed two stage CS reconstruction accurately reproduces velocities without visual artifacts for \\textit{in-vivo} undersampled data acquired in 40 seconds (compared to $\\SI{2}{\\minute}$ $\\SI{40}{\\second}$ for the full \\mbox{\\textit{k-}space} acquisition). \nA plot of the velocities, averaged over the eleven subjects shows good agreement with the reference velocities. \nHowever, a slightly larger variance in velocity is seen at the higher \\mbox{CS\\textit{-factor}} (e.g., \\mbox{CS\\textit{-factor} = 4}, $\\mathrm{VPS} = 4$) presumably from the lower SNR of the phase maps of the undersampled images. \nThe effect of temporal sampling and CS reconstruction on smoothing peak velocities merits discussion. \nIn the reference scan with a $\\mathrm{VPS} = 4$, smoothing occurs due to the lower number of temporal frames that are collected (8 frames). \nOn the other hand, the undersampled data with $\\mathrm{VPS} = 2$ has twice the temporal resolution but the joint CS reconstruction along the temporal frames introduces smoothing of peak velocities~\\cite{RNCS10}; the amount of smoothing will depend on the acceleration factor. \nHowever, the undersampled data with $\\mathrm{VPS} = 4$ will have smoothing artifacts from both low temporal resolution as well as from the CS reconstruction. \nSo, when comparing undersampled $\\mathrm{VPS} = 2$ acquisitions with that of the reference scan ($\\mathrm{VPS} = 4$), comparable extent of smoothing in the peak velocities is anticipated. \nHowever, it should be noted though that the velocity peaks during the isometric contraction are not that sharp and have FWHM of $\\sim \\SI{700}{\\milli\\second}$  ($\\mathrm{VPS} = 4/2$ have a temporal resolution of $\\SI{285}{\\milli\\second}$/$\\SI{142}{\\milli\\second}$) which may not result in significant smoothing of velocity peaks for any of the \\mbox{CS\\textit{-factor}}/VPS combinations tested here. \nFurther, in an earlier study, the reference full \\mbox{\\textit{k-}space} data has been validated using a flow phantom with pulsatile flow profile similar to \\textit{in-vivo} muscle motion~\\cite{RNSS10}. \r\nStrain rate maps are particularly sensitive to noise in the original phase maps (i.e., the velocity maps). \nA good test of the quality (SNR) of the undersampled VEPC data is to assess the image quality of the strain rate maps generated from the undersampled velocity images. \nThe quality of the strain rate maps generated from data acquired with different CS/VPS factors confirms that image quality is good (in terms of SNR as well as absence of artifacts) as the \\mbox{CS\\textit{-factor}} changes from low to high acceleration factors. \nThe Bland-Altman plots of reference SR values and undersampled SR values had good agreement and no bias for all combinations but the lowest confidence intervals (CI) were seen for the VPS/\\mbox{CS\\textit{-factor}} of 2/4 followed by the combination of 4/4. \nThe 2/4 combination offers an increase in temporal resolution by a factor of 2 over the reference sequence and time savings factor of 2 while the 4/4 results in a time savings of 4. \nThe normalized coefficient of repeatability is around 24\\% for the $\\mathrm{CS} = 4$ undersampled data which is high and may arise from two other sources besides the differences between the full \\mbox{\\textit{k-}space} and the undersampled acquisitions: higher noise in computed SR maps compared to velocity maps as well as the physiological variability in two separate acquisitions. \r\n%-new paragraph-%\n\n%-new paragraph-%\nThe choice of either sequence (VPS/\\mbox{CS\\textit{-factor}} of 2/4 or 4/4) will depend on the application. \nIncreased temporal resolution VEPC sequences will find application in monitoring blood flow and cardiac motion where rapid changes are anticipated at the systolic phase~\\cite{RNCS9, RNCS10}. \nIn studying skeletal muscle dynamics, a high temporal resolution VEPC sequence may be useful to monitor muscle motion under nerve simulation where the initial rise of muscle strain is steep~\\cite{RNCS12}. \nHigh temporal resolution may also be employed to track the correlation of the force curve in sub-maximal voluntary contractions to the strain curve; strain appears to diminish more slowly than the force and the force-strain temporal correlation patterns may be used to explore myotonic disorders that are associated with delayed relaxation~\\cite{RNCS12}.\nConsidering a decrease in total scan time, applications can extend to study cohorts (e.g. in muscular dystrophies~\\cite{RNCS12}) who cannot perform a large of repeated contractions as well as increase the range of \\%MVICs.\n%-new paragraph-%\n\n%-new paragraph-%\nIn order compare the maximum \\mbox{CS\\textit{-factor}} achieved in the current study versus in earlier studies using the $k_y$\\textit{-t} SPARSE SENSE approach~\\cite{RNCS9, RNCS10}, it is important to note the number of phase encode lines in the reference full \\mbox{\\textit{k-}space} as well as the number of multicoils; both of these have an impact on the maximum CS achievable. \nKim~et~al.~\\cite{RNCS10} reported on undersampled VEPC studies for flow imaging that achieved a \\mbox{CS\\textit{-factor}} of 6.3 starting with the full \\mbox{\\textit{k-}space} PE lines of 192 ($\\sim 30$ undersampled lines) and a 32-channel coil. Otazo~et~al.~\\cite{RNCS9} achieved a \\mbox{CS\\textit{-factor}} of 8 starting with the full \\mbox{\\textit{k-}space} PE lines of 192 ($\\sim 24$ undersampled lines) and a 12-channel coil. \nIn the current study, a 8-channel coil starting with a full \\mbox{\\textit{k-}space} lines of 106 was used resulting in $\\sim 26$ undersampled lines. \nThe number of undersampled lines between the current and earlier studies is comparable while the number of channels in the multicoil was the lowest in the current study. \r\nThere are several limitations to the study. \nThe validation with the phantom experiments occurred with constant flow, in contrast to the \\textit{in-vivo} situation in which a dynamically changing velocity profile in skeletal muscle was imaged. \nA 2D VEPC sequence as proposed here is appropriate for certain muscles in which the imaging plane can be selected such that muscle fibers run in the imaging plane; this is possible for the medial gastrocnemius which is the focus of this study. \nIf it is possible to select this orientation, a single slice at an orientation of the muscle fibers is sufficient since the deformation and strain in the direction orthogonal to the muscle fibers has been shown to be very small to zero from 3D strain measurements~\\cite{RNS31, RNCS11}. \nHowever, it is important to be able to extend the technique to monitor other muscles that have complex fiber trajectories. \nFuture studies will explore compressed sensing methods for 4D VEPC imaging to achieve under a minute scan time for 3D imaging as well. \nRecent innovations such as including random undersampling in the velocity encoding directions termed Multi-Dimensional Flow-Preserving Compressed Sensing (MuFloCoS)~\\cite{RNCS22} may help achieve the high acceleration factors required to obtain 3D imaging with 3 directional velocity encoding in acquisitions times of under a minute. \nAnother limitation is that validation (for muscle data) using the velocities from the undersampled data compared to the reference data is difficult using acquired data since the reproducibility of velocities acquired in separate dynamic scans will be limited by the subject's ability to reproduce the same force patterns in the reference and in the undersampled patterns. \nInclusion of a deformable phantom mimicking tissue deformation may help to accurately validate the undersampled acquisitions using the fully sampled acquisition as a reference.\n%-new paragraph-%\n\n%-new paragraph-%\r\nIn conclusion, this is a report of implementing a compressed sensing method for 2D VEPC for monitoring muscle motion during contraction paradigms. \nCS reconstructions provided artifact free images as well as accurate velocity values in phantoms and in \\textit{in-vivo} human muscle during isometric contractions for acceleration factors up to 4 resulting in scan times of 40 seconds. \nThis decrease in scan time extends the applicability of the technique to study muscle kinematics at higher \\%MVIC and in cohorts such as aging, sarcopenic or dystrophic subjects.\n%=========================================================\n\\section{Study of Age Related Difference in Strain Indices}\n\\label{sec: CS_SRYO}\n%=========================================================\nThe variation of the deformation indices with sub-maximal force output (\\% Maximum Voluntary Isometric Contraction, MVIC) can provide information on stress-strain like relationships. \nHowever, such studies have been limited by the long sequence time precluding its use at high MVICs~\\cite{Malis:2018fr}. \nThe technique developed and described in the previous section enables acquisitions in senior population across a range of MVICs to extract 3D Strain and SR tensors. \nThe CS technique combines multiple coils and a $k_y$\\textit{-t} SENSE SPARSE reconstruction to obtain artifact free images in 75 seconds. \nThe objective was to study the differences in 3D strain and SR tensor components (in the principal and fiber aligned frames of reference) with age and with \\%MVIC.\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Methods}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n11 young (28 $\\pm$ 7 years old) and 8 senior (74 $\\pm$ 6 years old) subjects were recruited after IRB approval and scanned on a $\\SI{1.5}{\\tesla}$ Signa HD16 MR scanner (GE Medical Systems, WI, USA).\nData acquisition and image processing pipeline are summarized in Figure~\\ref{fig: CSYO1}. The set of codes implementing the processing pipeline was developed in MATLAB (The MathWorks Inc. MA, USA) and is available~\\cite{3DSR}.\n%*********************************************************\n\\begin{sidewaysfigure}\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[scale=0.85]{Figures/CS2_1.pdf}\n\\caption[Pipeline of data acquisition and image processing for 3D strain~/~strain rate using undersampled VEPC sequence]{Pipeline of data acquisition and image processing for 3D strain~/~strain rate using undersampled VEPC sequence.}\n\\label{fig: CSYO1}\n\\end{sidewaysfigure}\n%*********************************************************\nGated VEPC images were obtained during 3 sub-maximal isometric contraction levels.\nVEPC acquisition was: echo time (TE): $\\SI{7.7}{\\milli\\second}$, repetition time (TR): $\\SI{17.8}{\\milli\\second}$, signal averages (NEX): 2, flip angle (FA): $\\SI{20}{\\degree}$, slice thickness: $\\SI{5}{\\milli\\meter}$, field of view (FOV): $\\SI{30}{\\centi\\meter} \\times \\SI{22.5}{\\centi\\meter}$ (partial phase FOV: 0.55), matrix $256 \\times 192$ (lower resolution in the phase direction), 17 temporal frames (with view sharing factor = 2), $\\SI{10}{\\centi\\meter/\\second}$ three directional velocity encoding, 24 repetitions, cycle length $\\SI{2.9}{\\second}$.\nThree contiguous slices were acquired at each \\%MVIC for a total of nine dynamic acquisitions; each dynamic scan was 75 seconds resulting in $\\times 8.6$ times accelerated acquisition (\\mbox{CS\\textit{-factor}} of 4.3, views per segment (VPS) = 2). \nThe protocol also included a geometrically matched spin echo DTI EPI sequence.\nThe multi-coil CS scheme used a variable density random undersampling with maximum density at the center of \\mbox{\\textit{k-}space}. \nA two-step $k_y$\\textit{-t} SENSE SPARSE CS joint reconstruction (of reference and velocity encoded images) was performed~\\cite{RNCS10} using the coil sensitivities with a temporal FFT followed by a temporal PCA as the sparsifying transforms. \nThe lower leg was resting against foot-pedal device~\\cite{RNSS10} with strain sensor and anchored in an 8-channel RF coil; real-time visual feedback was provided to the subject. \nData sets were obtained for sub-maximal forces (30, 40 and 60\\% MVIC) for all subjects. \n3D strain and SR tensors were calculated for the central slice of the three acquired slices. \nPrior to the analysis, phase-contrast images were corrected for phase shading artifacts and denoised using a 3D anisotropic diffusion filter~\\cite{RNCS17}.\nVoxels in the entire volume were tracked to obtain displacements and locations in subsequent temporal frames. \nThe 3D strain and SR images were generated from the spatial gradients of the velocity and displacement images; both Eulerian and Lagrangian strains and SR were evaluated. \nTwo invariants were calculated from the rank 2 strain and SR tensors (volumetric and maximum shear strain rate $SR_{fc\\_\\,\\mathrm{max}}$). \nThe strain and strain tensors in principal axis were rotated to the DTI eigenvector frame of reference. \nThe rotation matrix, R was generated from the DTI eigenvectors to reorient the strain and SR tensors from:\n%.........................................................\n\\begin{equation}\\label{eq: SRDTI}\nSR_{\\mathrm{fb}}=\\mathrm{R_{DTI}}\\cdot SR_{\\mathrm{pb}} \\cdot \\mathrm{R_{DTI}}^\\intercal\n\\end{equation}\n%.........................................................\nand components of the 3D strain rate tensor are:\n%.........................................................\n\\begin{equation}\nSR_{\\mathrm{fb}} =\\left[\r\\begin{array}{ccc}\rSR_{ff} & SR_{fs} & SR_{ft} \\\\[4pt]\rSR_{sf} & SR_{ss} & SR_{st} \\\\[4pt]\rSR_{tf} & SR_{ts} & SR_{tt} \\\\\r\\end{array}\\right]\n\\end{equation}\n%.........................................................\nQuantitative analysis was performed for a region of interest (ROI) placed in medial gastrocnemius and soleus muscles (7 $\\times$ 7).\nIndices were extracted at the frame corresponding to maximum $SR_\\mathrm{fiber}$ during the contraction part of the cycle.\r\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Results}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nFigure~\\ref{fig: CSYO2} shows the $SR_\\mathrm{fiber}$, $SR_\\mathrm{in-plane}$ and $SR_{fc\\_\\,\\mathrm{max}}$ maps respectively at 30 and 60 \\%MVIC effort for one young and one senior subject; the maps correspond to the temporal frame at max $SR_\\mathrm{fiber}$ in the contraction cycle.\n%*********************************************************\n\\begin{sidewaysfigure}\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=8.5in]{Figures/CS2_2.pdf}\n\\captionsetup{width=8.5in}\n\\caption[Colormaps of the two strain rate eigenvalues $SR_\\mathrm{fiber}$, $SR_\\mathrm{in-plane}$ and invariant $SR_{fc\\_\\,\\mathrm{max}}$ at 30\\% and 60\\% MVIC effort for one young and one senior subject]{Colormaps of the two strain rate eigenvalues $SR_\\mathrm{fiber}$, $SR_\\mathrm{in-plane}$ and invariant $SR_{fc\\_\\,\\mathrm{max}}$ at 30\\% and 60\\% MVIC effort for one young subject and one senior; the maps correspond to the temporal frame at max $SR_\\mathrm{fiber}$ in the contraction cycle.}\n\\label{fig: CSYO2}\n\\end{sidewaysfigure}\n%*********************************************************\nThe quality of the SR eigenvalue colormaps underlines the efficiency of the CS reconstruction. \nIncrease in eigenvalues with the increase in level of MVIC can be visually appreciated for subjects in both age groups. \nFigure~\\ref{fig: CSYO4} shows colormaps of the diagonal components of SR in the fiber frame of reference for young and senior subject at the peak of the contraction.\n%*********************************************************\n\\begin{sidewaysfigure}\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=8.5in]{Figures/CS2_4.pdf}\n\\captionsetup{width=8.5in}\n\\caption[Colormaps of the diagonal components of strain rate tensor in the fiber reference frame for one young and one senior subjects at two different levels of MVIC]{Colormaps of the diagonal components of strain rate tensor in the fiber reference frame for one young (left) and one senior (right) at two different levels of MVIC: 30\\% (top row), 60\\% (bottom row); the maps correspond to the temporal frame at max $SR_\\mathrm{fiber}$ in the contraction cycle.}\n\\label{fig: CSYO4}\n\\end{sidewaysfigure}\n%*********************************************************\nMuch smaller values of SR are seen in the fiber frame of reference and differences between young and senior are less than for components in principle frame. \nTable~\\ref{tab: CSYO1} lists only the strain and strain rate indices (ROIs placed in the MG and Soleus) that were either significantly different between age groups and~/~or \\%MVIC; no significant age*MVIC effect was seen.\n%=========================================================\n\\begin{table}[!htb]\n\\vspace{+0.2cm}\n\\caption[Strain rate indices for two regions of interest in MG and SOL extracted at the the peak of the contraction]{Strain rate indices for two regions of interest in MG and SOL extracted at the temporal frame corresponding to $\\max$ $SR_{\\mathrm{fiber}}$ during the contraction phase.}\n\\label{tab: CSYO1}\n\\begin{center}\n\\begin{threeparttable}\n\\begin{tabular}{@{}lclrrrr@{}}\n\\toprule[1pt]\\midrule[0.3pt]\n\\multicolumn{2}{l}{\\multirow{2}{*}{}} & \\multicolumn{1}{c}{\\multirow{2}{*}{age}} & \\multicolumn{2}{c}{MG}                                      &  \\multicolumn{2}{c}{SOL}                                     \\\\ \\cmidrule(lr){4-5} \\cmidrule(lr){6-7} \n\\multicolumn{2}{l}{}                  & \\multicolumn{1}{c}{}                           & \\multicolumn{1}{c}{30 \\%MVIC} & \\multicolumn{1}{c}{60\\% MVIC} &  \\multicolumn{1}{c}{30 \\%MVIC} & \\multicolumn{1}{c}{60\\% MVIC} \\\\ \\midrule[0.3pt]\n\\multirow{2}{*}{$\\Delta_x$}\\tnote{$1$, $2$, $4$}\t\t\t\t& \\multirow{2}{*}{$\\left[\\SI{}{\\milli\\meter}\\right]$}   \t\t \t& young     & $3.45 \\pm 1.93$   & $6.78 \\pm 3.53$  &  $2.54 \\pm 1.03$  & $5.27 \\pm 2.99$   \\\\\n\t  \t  \t\t\t\t\t\t\t\t\t\t\t\t\t&                  \t\t\t\t\t\t\t     \t\t\t\t& senior    & $2.54 \\pm 2.23$   & $4.02 \\pm 2.77$  &  $2.78 \\pm 2.56$  & $3.84 \\pm 2.90$   \\\\[4pt]\n\\multirow{2}{*}{$\\Delta_y$}\\tnote{$1$, $4$}\t\t\t\t\t& \\multirow{2}{*}{$\\left[\\SI{}{\\milli\\meter}\\right]$}\t   \t\t& young     & $8.10 \\pm 5.22$   & $10.14 \\pm 4.74$ &  $5.89 \\pm 1.98$  & $9.61 \\pm 4.12$   \\\\\n\t\t\t\t\t\t    \t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t  \t& senior    & $5.05 \\pm 3.40$   & $6.93 \\pm 4.29$  &  $5.46 \\pm 3.48$  & $7.65 \\pm 4.67$   \\\\[4pt]\n\\multirow{2}{*}{$v_x$}\\tnote{$1$, $2$, $4$}\t\t\t\t\t& \\multirow{2}{*}{$\\left[\\SI{}{\\milli\\meter/\\second}\\right]$} \t& young     & $9.22 \\pm 4.91$   & $15.12 \\pm 5.89$ &  $7.01 \\pm 2.41$  & $13.05 \\pm 5.56$  \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $7.15 \\pm 5.32$   & $9.89 \\pm 6.16$  &  $7.51 \\pm 7.25$  & $11.30 \\pm 7.68$  \\\\[4pt]\n\\multirow{2}{*}{$v_y$}\\tnote{$1$, $4$}\t\t\t\t\t\t& \\multirow{2}{*}{$\\left[\\SI{}{\\milli\\meter/\\second}\\right]$} \t& young     & $18.72 \\pm 10.21$ & $23.37 \\pm 7.49$ &  $14.50 \\pm 3.82$ & $23.95 \\pm 10.86$ \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $12.49 \\pm 8.05$  & $17.89 \\pm 11.55$&  $12.86 \\pm 9.34$ & $20.31 \\pm 11.86$ \\\\[4pt]\n\\multirow{2}{*}{$E_{\\mathrm{max}}$}\\tnote{$1$}\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& young     & $-0.92 \\pm 0.49$   & $-1.60 \\pm 0.57$  &  $-1.14 \\pm 0.64$  & $-1.60 \\pm 1.02$   \\\\\n \t\t\t\t                    \t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $-0.95 \\pm 0.54$   & $-1.46 \\pm 0.81$  &  $-1.01 \\pm 0.65$  & $-1.21 \\pm 0.93$   \\\\[4pt]\n\\multirow{2}{*}{$L_{\\mathrm{max}}$}\\tnote{$1$}\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& young     & $-1.01 \\pm 0.53$   & $-1.68 \\pm 0.59$  &  $-1.16 \\pm 0.59$  & $-1.65 \\pm 1.02$   \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $-1.02 \\pm 0.56$   & $-1.57 \\pm 0.85$  &  $-1.05 \\pm 0.69$  & $-1.30 \\pm 1.02$   \\\\[4pt]\n\\multirow{2}{*}{$SR_{fc\\_\\,\\mathrm{max}}$}\\tnote{$2$, $3$}\t& \\multirow{2}{*}{$\\left[\\SI{}{\\per\\milli\\second}\\right]$} \t\t& young     & $-197 \\pm 83$   \t& $-442 \\pm 306$    &  $-283 \\pm 227$    & $-400 \\pm 263$     \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $-244 \\pm 165$  \t& $-377 \\pm 272$    &  $-209 \\pm 157$    & $-261 \\pm 155$     \\\\[4pt]\n\\multirow{2}{*}{$E_{\\mathrm{fiber}}$}\\tnote{$2$}\t        \t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& young     & $-0.62 \\pm 0.27$   & $-1.07 \\pm 0.42$  &  $-0.60 \\pm 0.31$  & $-0.92 \\pm 0.56$   \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $-0.59 \\pm 0.33$   & $-0.94 \\pm 0.51$  &  $-0.57 \\pm 0.39$  & $-0.68 \\pm 0.54$   \\\\[4pt]\n\\multirow{2}{*}{$L_{\\mathrm{fiber}}$}\\tnote{$2$}\t        \t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& young     & $-0.66 \\pm 0.27$   & $-1.12 \\pm 0.43$  &  $-0.61 \\pm 0.27$  & $-0.94 \\pm 0.55$   \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $-0.64 \\pm 0.35$   & $-1.01 \\pm 0.55$  &  $-0.59 \\pm 0.41$  & $-0.74 \\pm 0.61$   \\\\[4pt]\n\\multirow{2}{*}{$SR_{\\mathrm{fiber}}$}\\tnote{$2$, $3$}\t\t& \\multirow{2}{*}{$\\left[\\SI{}{\\per\\milli\\second}\\right]$} \t\t& young     & $-115 \\pm 49$  \t& $-263 \\pm 170$   &  $-183 \\pm 161$   & $-230 \\pm 142$  \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $-153 \\pm 104$  \t& $-234 \\pm 176$   &  $-131 \\pm 87$    & $-164 \\pm 85$  \\\\[4pt]\n\\multirow{2}{*}{$SR_{\\mathrm{in-plane}}$}\\tnote{$2$, $3$}\t& \\multirow{2}{*}{$\\left[\\SI{}{\\per\\milli\\second}\\right]$} \t\t& young     & $120 \\pm 52$   \t& $258 \\pm 194$    &  $154 \\pm 110$    & $243 \\pm 166$   \\\\\n                  \t\t\t\t\t\t\t\t\t\t\t&                   \t\t\t\t\t\t\t     \t\t\t\t& senior    & $137 \\pm 91$   \t& $211 \\pm 140$    &  $118 \\pm 103$    & $146 \\pm 102$   \\\\ \\midrule[0.3pt]\\bottomrule[1pt]\n\\end{tabular}\n\\begin{tablenotes}[flushleft]\\footnotesize\n\\item[$1$] Significant difference between age groups for MG.\n\\item[$2$] Significant difference between 30\\% and 60\\% MVIC for MG.\n\\item[$3$] Significant difference between age groups for SOL.\n\\item[$4$] Significant difference between 30\\% and 60\\% MVIC for SOL.\n\\end{tablenotes}\n\\end{threeparttable}\n\\end{center}\n\\vspace{-0.2cm}\n\\end{table}\n%=========================================================\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Discussion}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nMaximum shear strain rate $SR_{fc\\_\\,\\mathrm{max}}$ (and shear strains), $SR_\\mathrm{fiber}$ and $SR_\\mathrm{in-plane}$ (and strains in-plane) were significantly lower with age and with \\%MVIC (30 and 60\\%MVIC). \nThe source of the shear strain is hypothesized (based on computational models) to be the shear in the extracellular matrix; these models have also shown that shear strain is the mechanism of lateral transmission of force. \nThe in-plane strain and $SR_\\mathrm{in-plane}$ reflect the deformation in the fiber cross-section and will change with the mechanical properties of the extracellular matrix (stiffer ECM will restrict the in-plane deformation). \n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Conclusions}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nCompressed sensing VE-PC enables dynamic acquisition of multi-slice~/~multiple levels of sub-maximal contraction in young and senior subjects. \nSignificant differences with age seen in shear strains and in shear strain rates imply that the significant remodeling with age may occur in the extracellular matrix which could be a contributor to force loss. \n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\section{Acknowledgments}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nSection~\\ref{sec: CS_paper} is a reprint of material, with minor edits as it appears in: V.~Malis, U.~Sinha, and S.~Sinha, ``Compressed sensing velocity encoded phase contrast imaging: Monitoring skeletal muscle kinematics,'' \\emph{Magn. Reson. Med.}, Dec. 2019.\nThe author of the dissertation was the primary author of this paper.\n%-new paragraph-%\n\n%-new paragraph-%\nSection~\\ref{sec: CS_SRYO} is a reprint of material, with minor edits as it appears in: V.~Malis, U.~Sinha, and S.~Sinha, ``Principal Axis and Fiber Aligned 3D Strain~/~Strain Rate Mapping with Compressed Sensing Velocity Encoded Phase Contrast MRI to study Aging Muscle,'' \\emph{Proceedings of the International Society of Magnetic Resonance in Medicine}, Sydney, 2020.\nThe author of the dissertation was the primary author of this abstract.", "meta": {"hexsha": "15e722082c1c1267a12b6e7612afb01a217bd1a2", "size": 98080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter4.tex", "max_stars_repo_name": "vmalis/PhDissertation", "max_stars_repo_head_hexsha": "7c6a343f902eb7a76d3f0ceca9aeb54def160c59", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter4.tex", "max_issues_repo_name": "vmalis/PhDissertation", "max_issues_repo_head_hexsha": "7c6a343f902eb7a76d3f0ceca9aeb54def160c59", "max_issues_repo_licenses": ["MIT"], "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": "vmalis/PhDissertation", "max_forks_repo_head_hexsha": "7c6a343f902eb7a76d3f0ceca9aeb54def160c59", "max_forks_repo_licenses": ["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.6786469345, "max_line_length": 700, "alphanum_fraction": 0.6821166395, "num_tokens": 24944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6942214352847685}}
{"text": "It has been highlighted that the complete solution of a hyperbolic system in elastic-plastic solids requires to know \\textit{a priori} the wave structure.\nThe object of this section is to study the mathematical properties of the loading functions \\eqref{eq:loading_func} in order to get some clues about the stress paths.\nIt is believed that the information thus earned could be used to accurately approximate the integration of equations \\eqref{eq:integral_example}.\nFirst, general properties holding regardless of the loading conditions are highlighted.\nNext, the equations are specialized to plane stress and plane strain cases.\n\n\\subsection{The general case}\nTo begin with, let us look at the product of the two loading functions in a direction of space.\nGiven the left eigenvectors of the acoustic tensor in equation \\eqref{eq:eigenvectAcc}, one has for instance:\n%Indeed, considering the left eigenvectors of the acoustic tensor given in equation \\eqref{eq:eigenvectAcc}, the product $\\psi^s_1\\psi^f_1$ reads:\n\\begin{equation*}\n  \\psi^s_1\\psi^f_1 = \\frac{l^1_2}{l^1_1}\\: \\frac{l_2^2}{l^2_1}  \n\\end{equation*}\nSince the eigenvectors of symmetric second-order tensors all satisfy $\\vect{l}^1 \\cdot \\vect{l}^2=0$, it comes out that the above product is equal to $-1$.\nHence, the loading paths resulting from the integration of the ODEs involving $\\psi^s_1$ and $\\psi^f_1$ are perpendicular in the stress space.\nThe same goes for $\\psi^s_2 $ and $\\psi^f_2 $.\nAlthough this orthogonality has already been noticed for particular plane strain and plane stress cases \\cite{Clifton,Ting68}, \\emph{the generic formulation proposed here shows that this is valid for all problems in two space dimensions}. \nAs a result, the study can be restricted to one function in each direction, say $\\psi_1^s$ and $\\psi_2^s$.\n\n\nSecond, if the function $\\psi_1^s$ vanishes at some point of the stress space, the projection in the $(\\sigma_{11},\\sigma_{12})$ plane of the loading path followed within a slow wave is vertical according to the ODE \\eqref{eq:sigSlow_n=e1} (\\textit{i.e} $d\\sigma_{11}=0$).\nConversely, if $\\psi_1^s\\rightarrow \\infty$, the loading path is horizontal in the $(\\sigma_{11},\\sigma_{12})$ plane (\\textit{i.e} $d\\sigma_{12}=0$).\n%Looking for vanishing $\\psi^f_1$ or $1/\\psi^f_1$ amounts to finding roots of the components of $\\vect{l}^2$:\nThese situations respectively correspond to:\n\\begin{align}\n  \\label{eq:first_root}\n  \\psi_1^s = 0  & \\Leftrightarrow A_{12} =0  \\\\\n  \\label{eq:second_root}\n  \\psi_1^s \\rightarrow \\infty & \\Leftrightarrow A_{22} -\\omega_1 =0\n\\end{align}\nIn particular, if $A_{12}=0$ the denominator of $\\psi_1^s$ reads:\n\\begin{equation}\n  A_{22} -\\omega_1 = \\frac{1}{2}\\(A_{22} -A_{11} -\\sqrt{(A_{11} -A_{22} )^2 + 4A_{12}^2 }\\) = \\frac{1}{2}\\(A_{22} -A_{11} -\\abs{A_{11} -A_{22}}\\vphantom{\\sqrt{(A_{11} -A_{22} )^2 + 4A_{12}^2 }}\\) = -\\left\\langle A _{11}-A _{22}  \\right\\rangle\n\\end{equation}\nwhere $\\left\\langle \\bullet \\right\\rangle=\\frac{1}{2}\\(\\bullet + \\abs{\\bullet}\\)$ denotes the positive part operator.\nTherefore, if $A_{12} =0$ and $A_{11} \\neq A_{22} $, one has $\\psi^s_1 =0$ and hence $\\psi^f_1 \\rightarrow -\\infty $ by orthogonality.\nIf moreover $A_{11}  = A_{22} $, both components of the eigenvectors vanish and the functions $\\psi^s_1$ and $\\psi^f_1$ are undetermined.\nNote also that in this case, the characteristic speeds of simple waves are identical according to  equations \\eqref{eq:eigenAcc1} and \\eqref{eq:eigenAcc2}.\n  % \\begin{equation}\n  %   \\label{eq:diff_celerities}\n  %   \\rho c_f^2 - \\rho c_s^2 = \\sqrt{(A_{11}-A_{22})^2+{4A_{12}}^2} \n  % \\end{equation}\n  % Then, it follows that the simultaneous satisfaction of conditions \\eqref{eq:first_root} and \\eqref{eq:second_root} leads to\nAs a result, the situation $c_f=c_s$ corresponds to a loss of hyperbolicity of the system.\n\nAnalogously, the function $\\psi_2^s$ is such that:\n\\begin{align}\n    \\label{eq:first_root_psi2cp}\n    \\psi_2^s \\rightarrow \\infty  & \\Leftrightarrow A_{12} =0  \\\\\n    \\label{eq:second_root_psi2cp}\n    \\psi_2^s =0 &  \\Leftrightarrow A_{22} -\\omega_1 =0\n\\end{align}\nTherefore, if both conditions $A_{12}=0$ and $A_{11} =A_{22}$ are satisfied, the system is no longer hyperbolic with characteristic speeds of fast and slow waves that are identical.\n\nAccording to the ODEs of table \\ref{tab:simpleWavesEquations}, the particular values of the loading functions $\\psi_i^{s,f}$ through the simple waves propagating in direction $\\vect{e}_i$ for $i=\\{1,2\\}$, provide information about the loading paths in the stress space.\nFirst, $\\psi^{s,f}_i =0$ leads to $d\\sigma_{ii}=0$ (no sum on $i$) so that the longitudinal stress is constant within the simple wave.\nConversely, with the loading functions tending to infinity, the stress $\\sigma_{12}$ does not vary.\nNotice that the coefficients $\\alpha_{ij}$ of the left eigenvector of the Jacobian matrix associated with the zero eigenvalue \\eqref{eq:null_left_eigen} also have to be regarded.\nNevertheless, those terms resulting from products of the components of the elastoplastic tangent modulus have complex expressions and are assumed to have non-zero values in the remainder of the paper.\n\nThe above discussions are now specified to the plane strain and plane stress cases, for which loading conditions leading to $A_{12} =0$ and $A _{11}-A _{22}=0$ are identified.\n\n\n\n\\subsection{The plane strain case}\nThe case of plane strain is first considered by using the elastoplastic tangent modulus so that the components of the acoustic tensor for $\\vect{n}=\\vect{e}_1$ read:\n% The elastoplastic tangent modulus under consideration is now that given in equation \\eqref{eq:elastoplastic_tangent}, so that the components of the acoustic tensor for $\\vect{n}=\\vect{e}_1$ read: \n\\begin{align}\n  \\label{eq:DP_A11}\n  & A_{11}^{ep}= C_{1111}^{ep} = \\lambda + 2\\mu -\\beta s_{11}^2 \\\\\n  \\label{eq:DP_A22}\n  & A_{22}^{ep}= C_{2121}^{ep}= \\mu -\\beta s_{12}^2 \\\\\n  \\label{eq:DP_A12}\n  & A_{12}^{ep}= C_{1121}^{ep}=-\\beta s_{11}s_{12}\n\\end{align}\nThe associated eigenvalues are then:\n\\begin{align}\n  \\label{eq:eigen_acc_DP1}\n  & \\rho c_s^2 =  - \\frac{\\sqrt{\\[\\lambda + \\mu -\\beta (s_{11}^2-s_{12}^2) \\]^2 +4(\\beta s_{11}s_{12})^2}}{2}  \n   + \\frac{\\lambda +3\\mu -\\beta (s_{11}^2+ s_{12}^2)}{2}\n   \\\\\n  \\label{eq:eigen_acc_DP2}\n  & \n    \\rho c_f^2 =    \\frac{\\sqrt{\\[\\lambda + \\mu -\\beta (s_{11}^2-s_{12}^2) \\]^2 +4(\\beta s_{11}s_{12})^2}}{2}  \n     + \\frac{\\lambda +3\\mu -\\beta (s_{11}^2+ s_{12}^2)}{2}\n\\end{align}\nSubtracting equations \\eqref{eq:DP_A11} and \\eqref{eq:DP_A22}, one gets: $A_{11}^{ep}-A_{22}^{ep}= \\lambda + \\mu -\\beta \\(s_{11}^2-s_{12}^2\\)$.\nHence, the equation $A_{11}^{ep}-A_{22}^{ep}=0$ admits a set of solutions in the deviatoric stress space.\nOn the other hand, we see from equation \\eqref{eq:DP_A12} that $A_{12}^{ep}$ vanishes for $s_{12}=0$ or $s_{11}=0$.\n% Recall that $A^{ep}_{12}=0$ leads to vertical and horizontal loading paths across slow and fast waves respectively. \nEach solution is studied in more details below.\n\n%% Sign of one of the functions psi... but not used afterwards\n% We first study the sign of the functions $\\psi^f$ by noticing that $\\mu=\\rho c_2^2$ so that $A_{22}^{ep}$ may be rewritten to yield:\n% \\begin{equation*}\n%   \\psi^f = -\\frac{A_{12}^{ep}}{A_{22}-\\rho c_f^2}= -\\frac{\\beta s_{11}s_{12}}{\\rho c_f^2-\\rho c_2^2 +\\beta s_{12}^2 }\n% \\end{equation*}\n% Since the denominator is positive for $c_f \\geq c_2$, it comes out that $\\sign (\\psi^f) = - \\sign(s_{12}) \\sign(s_{11})$. Moreover, two roots of the loading function $\\psi^f$ can be identified.\n\n%\\textbf{Condition $s_{12}=0$}: \n\\subsubsection{Condition $s_{12}=0$}\n% \\review{According to \\textsc{Raniecki} \\cite[ch.3 p.173]{mandel_book}, this case leads to $c_s =c_2$.}\n\nAccording to equations \\eqref{eq:eigen_acc_DP1} and \\eqref{eq:eigen_acc_DP2}, the eigenvalues of the acoustic tensor become:\n\\begin{align*}\n  & \\rho c_s^2 = \\frac{1}{2}\\( \\lambda +3\\mu -\\beta s_{11}^2 - \\abs{\\lambda + \\mu -\\beta s_{11}^2 } \\) \\\\\n  & \\rho c_f^2 = \\frac{1}{2}\\( \\lambda +3\\mu -\\beta s_{11}^2 + \\abs{\\lambda + \\mu -\\beta s_{11}^2 } \\)\n\\end{align*}\nTwo cases are to be considered:\n\\begin{itemize}\n\\item[(i)] if $\\beta s_{11}^2 < \\lambda + \\mu$, the expression further reduces to:\n  \\begin{align*}\n    & \\rho c_s^2 = \\mu \\\\\n    & \\rho c_f^2 = \\lambda +2\\mu -\\beta s_{11}^2 \n  \\end{align*}\n  The characteristic speed of slow waves is therefore equivalent to that of elastic shear waves for plane strain $c_s=c_2=\\sqrt{\\mu/\\rho}$. \n\\item[(ii)] if $ \\lambda + \\mu - \\beta s_{11}^2 <0$, the characteristic speeds read: \n  \\begin{align*}\n    & \\rho c_s^2 = \\lambda +2\\mu -\\beta s_{11}^2  \\\\\n    & \\rho c_f^2 =  \\mu \n  \\end{align*}\n  Therefore, the celerity of fast waves reduces to that of elastic shear waves.\n  Note, however, that the characteristic speed of slow waves remains real if and only if $\\lambda +2\\mu >\\beta s_{11}^2$.\n  One then gets the following bounds: $\\lambda +2\\mu > \\beta s_{11}^2 > \\lambda +\\mu$.\n\\end{itemize}\nNote that the two above situations lead to the propagation of one neutral wave in the medium.\n  \nAt last, the equality $\\beta s_{11}^2 = \\lambda + \\mu$ leads to $A_{11}^{ep}-A_{22}^{ep}=0$ and hence, to undetermined loading functions. \n%% Set of admissible values for s11 (depends on s itself)\n% It then appears that the values of $s_{11}$ ensuring hyperbolicity of the system are:\n% \\begin{equation}\n%   s_{11} \\in ]-\\infty,-\\sqrt{\\frac{\\lambda + \\mu}{\\beta}}[\\: \\cup\\: ]-\\sqrt{\\frac{\\lambda + \\mu}{\\beta}},\\sqrt{\\frac{\\lambda + \\mu}{\\beta}}[\\: \\cup \\:]\\sqrt{\\frac{\\lambda + \\mu}{\\beta}} ,\\infty[\n% \\end{equation}\n\n%% Discussion about the loading path direction\n% Recall that $\\psi^f_1$ tending to infinity implies that the loading path are horizontal in $(\\sigma_{11},\\sigma_{12})$ plane and hence, the fast wave has no influence on the shear stress if, and only if, $\\sigma_{12}=0$ downstream.\n% Conversely, the stress paths through slow simple waves are vertical.\n% Moreover, with regard the last row of table \\ref{tab:simpleWavesEquations}, $\\sigma_{22}$ is also unchanged in that case.\n% As a consequence, if the initial state is shear-free the solution no longer contain combined waves, but longitudinal stress and shear stress simple waves.\n\n% \\textbf{Condition $s_{11}=0$}:\n\\subsubsection{Condition $s_{11}=0$}\nConsidering the relation \\eqref{eq:plane_strain_stress33} between the stress components for plane strain, one writes:\n\\begin{equation*}\n  s_{11}= \\frac{2}{3}\\sigma_{11}-\\frac{1}{3}(\\sigma_{22}+\\nu(\\sigma_{11}+\\sigma_{22})-E\\eps^p_{33})\n\\end{equation*}\nso that $s_{11}=0$ is equivalent to:\n\\begin{equation}\n  \\label{eq:plane_strain_s11=0}\n  \\sigma_{11}=\\frac{1+\\nu}{2-\\nu}\\sigma_{22}-E\\eps^p_{33}\n\\end{equation}\nIn contrast to what has been seen previously, the functions $\\psi^{s,f}$ cannot be undetermined in the case $s_{11}=0$ since the equation $A_{11}^{ep}-A_{22}^{ep}=\\lambda + \\mu + \\beta s_{12}^2=0$ does not admit real solutions.\nNevertheless, the stress state \\eqref{eq:plane_strain_s11=0} yields the following characteristic speeds:\n\\begin{align*}\n  & \\rho c_s^2 = \\mu -\\beta s_{12}^2 \\\\\n  & \\rho c_f^2 = \\lambda +2\\mu \n\\end{align*}\nso that the celerity of fast waves identifies with that of elastic pressure waves under plane strain $c_f=c_1=\\sqrt{(\\lambda + 2\\mu)/\\rho}$. %$\nOnce again, this case corresponds to the propagation of a neutral wave.\n\n\n%%%% n=e2\n$\\newline$\nThe same analysis can be carried out in the direction $\\vect{n}=\\vect{e}_2$ by considering the following acoustic tensor components:\n\\begin{align}\n  \\label{eq:DP_A11_n2}\n  & A_{11}^{ep}= C_{1212}^{ep} = \\mu -\\beta s_{12}^2 \\\\\n  \\label{eq:DP_A22_n2}\n  & A_{22}^{ep}= C_{2222}^{ep}= \\lambda + 2\\mu -\\beta s_{22}^2 \\\\\n  \\label{eq:DP_A12_n2}\n  & A_{12}^{ep}= C_{1222}^{ep}=-\\beta s_{22}s_{12}\n\\end{align}\nThe characteristic speeds are then:\n\\begin{align}\n  \\label{eq:eigen_acc_DP1_n2}\n  & \\rho c_s^2 = - \\frac{\\sqrt{\\[\\lambda +\\mu -\\beta (s_{22}^2-s_{12}^2) \\]^2 +4(\\beta s_{22}s_{12})^2}}{2} \n    + \\frac{\\lambda +3\\mu -\\beta (s_{22}^2+ s_{12}^2)}{2}   \n   \\\\\n  \\label{eq:eigen_acc_DP2_n2}\n  &\n      \\rho c_f^2 =   \\frac{\\sqrt{\\[\\lambda +\\mu -\\beta (s_{22}^2-s_{12}^2) \\]^2 +4(\\beta s_{22}s_{12})^2}}{2}\n      + \\frac{\\lambda +3\\mu -\\beta (s_{22}^2+ s_{12}^2)}{2}   \n\\end{align}\nWith these expressions, the same remarks as for $\\vect{n}=\\vect{e}_1$ can obviously be made by replacing $s_{11}$ with $s_{22}$.\n\nAmong the above results, the most significant arises from the condition $s_{12}=0$.\nIndeed, it has been seen that $A_{12}^{ep}=0$ leads to $\\psi_1^s=0$ and $\\psi^s_2\\rightarrow \\infty$ in such a way that the corresponding loading paths in the $(\\sigma_{11},\\sigma_{12})$ plane are respectively vertical and horizontal.\nUnder the orthogonality property of the loading functions, the stress path followed in a fast wave propagating in the direction $\\vect{e}_1$ is horizontal in the same plane.\nHence, if the path through a fast wave intersects the plane $\\sigma_{12}=0$, the shear stress component remains constant afterwards.\nThe same result holds for the slow wave propagating in the direction $\\vect{e}_2$.\nThe above conclusion are summarized in table \\ref{tab:stress_paths_properties}.\n\\begin{table*}[h!]\n  \\centering\n  \\input{tabular/stress_paths}\n  \\caption{Loading paths projected on the ($\\sigma_{11},\\sigma_{12}$) plane followed across slow and fast simple waves, under the condition $\\sigma_{12}=0$ assuming that $A_{11}^{ep}-A_{22}^{ep}\\neq 0$.}\n  \\label{tab:stress_paths_properties}\n\\end{table*}\n\\subsection{The plane stress case}\n% The elastoplastic tangent modulus under consideration is now that given in equation \\eqref{eq:CP_constitutive}.\nAs mentioned in section \\ref{sec:2dproblem}, a suitable elastoplastic tangent modulus $\\widetilde{\\Cbb}^{ep}$ is now under consideration.\nLet's first focus on $\\psi_1^s$ related to the vector $\\vect{n}=\\vect{e}_1$.\nThus:\n\\begin{align}\n  \\label{eq:CP_A11}\n  &\n      \\widetilde{A}_{11}^{ep}= \\: C^{ep}_{1111} - \\frac{(C^{ep}_{1133})^2}{C^{ep}_{3333}} =\\:\\lambda + 2\\mu -\\beta s_{11}^2 -\\frac{\\(\\lambda -\\beta s_{11}s_{33}\\)^2}{\\lambda + 2\\mu - \\beta s_{33}^2}  \\\\\n  \\label{eq:CP_A22}\n  &\n      \\widetilde{A}_{22}^{ep}=  \\: C^{ep}_{2121} - \\frac{(C^{ep}_{2133})^2}{C^{ep}_{3333}} =\\:\\mu - \\beta s_{12}^2 -\\frac{\\(\\beta s_{12}s_{33}\\)^2}{\\lambda + 2\\mu - \\beta s_{33}^2}   \n\\\\\n  \\label{eq:CP_A12}\n  &\n      \\widetilde{A}_{12}^{ep} = \\: C^{ep}_{1121} - \\frac{C^{ep}_{1133}C^{ep}_{1233}}{C^{ep}_{3333}} =\\:\\beta s_{12} \\frac{\\lambda s_{33} - (\\lambda + 2\\mu)s_{11} }{\\lambda + 2\\mu - \\beta s_{33}^2}\n\\end{align}\nIn order to ensure the hyperbolicity of the system, the components of the acoustic tensor also have to be defined, that is $C^{ep}_{3333}> 0$, which leads to:\n\\begin{equation*}\n  \\lambda + 2\\mu - \\beta s_{33}^2 > 0 \\quad \\Leftrightarrow \\quad s_{33}^2 < \\frac{\\lambda + 2\\mu}{\\beta}\n\\end{equation*}\nSecond, from equation \\eqref{eq:CP_A12}, $\\widetilde{A}_{12}^{ep}$ admits two roots in terms of the components of the deviatoric stress tensor, namely: \n\\begin{equation}\n  s_{12}=0 \\quad ; \\quad s_{11}= \\frac{\\lambda}{\\lambda+2\\mu}s_{33}\n\\end{equation}\nIn terms of the components of the Cauchy stress tensor, these conditions read:\n\\begin{equation}\n  \\label{eq:CP_roots}\n  \\sigma_{12}=0 \\quad ; \\quad \\sigma_{11}=\\frac{2\\mu}{3\\lambda+4\\mu}\\sigma_{22}\n\\end{equation}\n% Hence, the loading path through a slow simple wave is vertical, that is $\\psi^s_1 = 0$, for stress values satisfying \\eqref{eq:CP_roots}, providing that the $\\widetilde{A}_{11}^{ep}$ and $\\widetilde{A}_{22}^{ep}$ are not equal.\n% Conversely, such stress states yield horizontal path through a fast wave.\n\n\n% \\textbf{Case $s_{12}=0$ :}\n% \\begin{align}\n%   & \\rho c_s^2 =\\frac{1}{2}\\(\\widetilde{A}_{11}^{ep}+\\widetilde{A}_{22}^{ep} - \\abs{\\widetilde{A}_{11}^{ep}-\\widetilde{A}_{22}^{ep}}\\) \\\\\n%   & \\rho c_f^2 =\\frac{1}{2}\\(\\widetilde{A}_{11}^{ep}+\\widetilde{A}_{22}^{ep} + \\abs{\\widetilde{A}_{11}^{ep}-\\widetilde{A}_{22}^{ep}}\\)\n% \\end{align}\n\nIf on the other hand the vector $\\vect{n}=\\vect{e}_2$ is considered, the acoustic tensor components read:\n\\begin{align}\n    \\label{eq:CP_A11_n=e2}\n    & \\widetilde{A}_{11}^{ep}= C^{ep}_{1212} - \\frac{(C^{ep}_{1233})^2}{C^{ep}_{3333}} = \\mu -\\beta s_{12}^2 -\\frac{\\(\\lambda -\\beta s_{12}s_{33}\\)^2}{\\lambda + 2\\mu - \\beta s_{33}^2} \\\\\n    \\label{eq:CP_A22_n=e2}\n    & \\widetilde{A}_{22}^{ep}= C^{ep}_{2222} - \\frac{(C^{ep}_{2233})^2}{C^{ep}_{3333}}= \\lambda +2\\mu - \\beta s_{22}^2 -\\frac{\\(\\beta s_{22}s_{33}\\)^2}{\\lambda + 2\\mu - \\beta s_{33}^2} \\\\\n    \\label{eq:CP_A12_n=e2}\n    & \\widetilde{A}_{12}^{ep} = C^{ep}_{1222} - \\frac{C^{ep}_{1233}C^{ep}_{2233}}{C^{ep}_{3333}} =\\beta s_{12} \\frac{\\lambda s_{33} - (\\lambda + 2\\mu)s_{22} }{\\lambda + 2\\mu - \\beta s_{33}^2}\n    %     \\label{eq:CP_A11_n=e2}\n    % & \\widetilde{A}_{11}^{ep}=  \\mu -\\beta s_{12}^2 -\\frac{\\(\\lambda -\\beta s_{12}s_{33}\\)^2}{\\lambda + 2\\mu - \\beta s_{33}^2} \\\\\n    % \\label{eq:CP_A22_n=e2}\n    % & \\widetilde{A}_{22}^{ep}= \\lambda +2\\mu - \\beta s_{22}^2 -\\frac{\\(\\beta s_{22}s_{33}\\)^2}{\\lambda + 2\\mu - \\beta s_{33}^2} \\\\\n    % \\label{eq:CP_A12_n=e2}\n    % & \\widetilde{A}_{12}^{ep} = \\beta s_{12} \\frac{\\lambda s_{33} - (\\lambda + 2\\mu)s_{22} }{\\lambda + 2\\mu - \\beta s_{33}^2}\n\\end{align}\nThese expressions are similar to those obtained before with $s_{22}$ instead of $s_{11}$.\nIt comes out that $\\widetilde{A}_{12}^{ep}$ admits two roots in the case $\\vect{n}=\\vect{e}_2$:\n\\begin{equation}\n  \\label{eq:CP_roots_n=e2}\n  \\sigma_{12}=0 \\quad ; \\quad \\sigma_{22}=\\frac{2\\mu}{3\\lambda+4\\mu}\\sigma_{11}\n\\end{equation}\n\nThe complexity introduced by the plane stress tangent modulus prevents finding other singular configurations for the hyperbolic system. \nIn particular, it is difficult to deal with the equation $\\widetilde{A}^{ep}_{11}=\\widetilde{A}^{ep}_{22}$ due to the expressions given in equations \\eqref{eq:CP_A11} and \\eqref{eq:CP_A22}.\nNevertheless, since the stress state $s_{12}=0$ also constitutes a singular point for plane stress, the same remarks as those made for the plane strain loading path hold.\nNamely, $\\sigma_{12}$ becomes constant if it falls to zero along the loading path followed inside a fast (\\textit{resp. slow}) wave propagating in direction $\\vect{e}_1$ (\\textit{resp. $\\vect{e}_2$}), as summarized in table \\ref{tab:stress_paths_properties}.\n%Namely, if $\\sigma_{12}$ falls to zero along the loading path followed inside a fast (\\textit{resp. slow}) wave propagating in direction $\\vect{e}_1$ (\\textit{resp. $\\vect{e}_2$}), is restricted to that value.\n%As we shall see below, more singular behaviors can be identified for plane strain.\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"manuscript\"\n%%% End:\n", "meta": {"hexsha": "b1b3bb8b5411181824c668fc15f6116f6c5de622", "size": 18674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papJmPs/analytical_results.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/analytical_results.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/analytical_results.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": 68.4029304029, "max_line_length": 272, "alphanum_fraction": 0.6860876084, "num_tokens": 6382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733979704703, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6942179884889945}}
{"text": "\\documentclass[12pt]{mpllatex}\n\\usepackage{examples}\n\\usepackage{caption}\n\\usepackage{pgfplots}\n\n\\begin{document}\n\n\\section*{Plotting Bessel functions}\n\nThis simple example uses Maple to produce a plot of the first six Bessel functions. Two plots are shown, one created by Maple and a second created by LaTeX using the plotting package {\\tt\\small pgfplots} and the data exported from Maple.\n\n\\begin{maple}\n   with(plottools):\n\n   myPlot := plot([seq(BesselJ(i, z), i = 0 .. 5)], z = 0 .. 15):\n\n   exportplot(\"example-04-fig.jpeg\",myPlot,\"JPEG\"):   # Maple18\n\n   a,b,n := 0.0,15.0,150:           # domain and number of samples\n   dx := (b-a)/n:                   # uniform step\n\n   fd := fopen (\"example-04.txt\", WRITE):\n   for i from 0 to n by 1 do\n      x := a + dx*i:\n      fprintf(fd,\"% .10e % .10e % .10e % .10e % .10e % .10e % .10e\\n\",x,\n                 seq(evalf(BesselJ(k,x)),k=0..5)):\n   end do:\n   fclose(fd):\n\\end{maple}\n\n\\clearpage\n\n\\hrule height0pt\n\\vfill\n\\begin{minipage}{\\textwidth}\n   \\centering\n   \\IfFileExists{example-04-fig.jpeg}%\n   {\\includegraphics[width=6.4in]{example-04-fig.jpeg}}{Failed to create jpeg plot.}\n   \\captionof{figure}{The first six Bessel functions.}\n\\end{minipage}\n\\vfill\n\n\\clearpage\n\n\\pgfplotsset{compat=newest}\n\\pgfplotsset{width=0.45\\textwidth,height=0.34\\textwidth}\n\n\\subsection*{Using pgfplots}\n\n\\begin{minipage}[t]{\\textwidth}\n   \\centering\n   \\begin{tikzpicture}\n      \\begin{axis}\n         [xmin= 0.0,  xmax=15.0,\n          ymin=-0.45, ymax=1.05,\n          xlabel=$x$, ylabel=$J_n(x)$,\n          grid=major, grid style={dashed,gray!30},\n          legend entries = {$J_0$, $J_1$, $J_2$, $J_3$, $J_4$, $J_5$}]\n          \\addplot[blue]   table [x index=0, y index=1]{example-04.txt};\n          \\addplot[red]    table [x index=0, y index=2]{example-04.txt};\n          \\addplot[green]  table [x index=0, y index=3]{example-04.txt};\n          \\addplot[teal]   table [x index=0, y index=4]{example-04.txt};\n          \\addplot[orange] table [x index=0, y index=5]{example-04.txt};\n          \\addplot[purple] table [x index=0, y index=6]{example-04.txt};\n      \\end{axis}\n   \\end{tikzpicture}\n   \\captionof{figure}{The first six Bessel functions.}\n\\end{minipage}\n\n\\vfill\n\n\\begin{latex}\n   \\begin{tikzpicture} % requires \\usepackage{pgfplots}\n      \\begin{axis}\n         [xmin= 0.0,  xmax=15.0,\n          ymin=-0.45, ymax=1.05,\n          xlabel=$x$, ylabel=$J_n(x)$,\n          grid=major, grid style={dashed,gray!30},\n          legend entries = {$J_0$, $J_1$, $J_2$, $J_3$, $J_4$, $J_5$}]\n          \\addplot[blue]   table [x index=0, y index=1]{example-04.txt};\n          \\addplot[red]    table [x index=0, y index=2]{example-04.txt};\n          \\addplot[green]  table [x index=0, y index=3]{example-04.txt};\n          \\addplot[teal]   table [x index=0, y index=4]{example-04.txt};\n          \\addplot[orange] table [x index=0, y index=5]{example-04.txt};\n          \\addplot[purple] table [x index=0, y index=6]{example-04.txt};\n      \\end{axis}\n   \\end{tikzpicture}\n   \\captionof{figure}{The first six Bessel functions.} % requires \\usepackage{caption}\n\\end{latex}\n\n\\end{document}\n", "meta": {"hexsha": "ac1757112f6f185cf7ece6f8746a905b48a185dc", "size": 3119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maple/examples/example-04.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "maple/examples/example-04.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maple/examples/example-04.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 33.902173913, "max_line_length": 237, "alphanum_fraction": 0.6114139147, "num_tokens": 1067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.6942179727596655}}
{"text": "\\chapter{G\\\"odel Universal Functions}\nIt is known that there are algorithms that given a program in one programming\nlanguage can produce a program in another programming language.\n\\marginurl{%\n  You can read more about such translators on Wikipedia.\n}{en.wikipedia.org/wiki/Source-to-source_compiler}\nHowever, in this book we are talking about universal functions instead of\nprogramming languages. Hence, we may be interested to study the following\nproblem. Let $U$ and $V$ be (computable) universal functions for the set of all\nunivariate computable functions. Given $n \\in \\N$ find $m \\in M$ such that $U_m$\nand $V_m$ are equal. Unfortunately, not for every pair of universal sets such\n$m$ can be found efficiently (see \\Cref{theorem:universal-not-godel}). \nHowever, there is a special class of universal functions that allow to find such\n$m$'s efficiently for any computable $V$.\n\\begin{definition}\n  Let $U : \\N^2 \\to \\N$ be a computable universal function for the class of\n  univariate computable functions. We say that $U$ is \\emph{G\\\"odel univeral\n  function} if for any computable function $V : \\N^2 \\to \\N$, there is a\n  computable function $s : \\N \\to \\N$ such that \n  \\[\n    V(n, x) = U(s(n), x)\n  \\]\n  for all $n, x \\in \\N$.\n\\end{definition}\n\n\\begin{theorem}\n  There is a G\\\"odel univeral function.\n\\end{theorem}\n\n\\begin{proof}\n  We start the proof of the theorem from proving that there is a computable\n  function $T : \\N^3 \\to \\N$ that is universal for the set of bivariate\n  computable functions. Let us fix a computable bijection \n  $\\pair{\\cdot}{\\cdot} : \\N^2 \\to \\N$. Let $R$ be a universal function for the set of\n  univariate computable functions, and let $T(n, u, v) = R(n, \\pair{u}{v})$.\n  it is easy to see that $T$ is indeed a universal function for the set of\n  bivariate computable functions.\n\n  Let $U : \\N^2 \\to \\N$ be the function such that $U(\\pair{n}{u}, v) = \n  T(n, u, v)$. We need to show that $U$ is G\\\"odel univeral function.\n  Let us consider some computable function $V : \\N^2 \\to \\N$. There is $n \\in\n  \\N$ such that $V(u, v) = T(n, u, v)$ for all $u, v \\in \\N$ since $T$ is\n  universal. Therefore $U(\\pair{n}{u}, v) = V(u, v)$ for all $u, v \\in \\N$.\n  As a result, we can define $s(u)$ to be equal to $\\pair{n}{u}$.\n\\end{proof}\n\n\\begin{exercise}\n  Show that there is a computable bijection $\\pair{\\cdot}{\\cdot} : \\N^2 \\to \\N$.\n\\end{exercise}\n\nG\\\"odel universal funcitons allow us to efficiently operate with numbers of\ncomputable functions.\nFor example, \\Cref{theorem:composition-computable} proved that composition of\ntwo computable functions is computbale. Moreover, it is easy to see that given\nthe programs computing funcitons $f$ and $g$ we can automatically obtain the\nfunction $g \\circ f$.\n\nHowever, we would like to avoid specifics of programin languages in our study of\ncomputability theory. Our tool to do so is the notion of a universal function so\nwe need to prove that there is an algorithm that given numbers of any two\ncomputable functions a computes a number of their composition.\n\\begin{theorem}\n  Let $U$ be a G\\\"odel universal function for the set of univariate computable\n  functions. Then there is a total computble function $c : \\N^2 \\to \\N$ such\n  that $U(c(p, q), x) = U(p, U(q, x))$ for any $p, q, x \\in \\N$.\n\\end{theorem}\n\\begin{proof}\n  Let us consider a computable function $V : \\N^2 \\to \\N$ such that\n  $V(\\pair{p}{q}, x) = U(p, U(q, x))$.There is a total computable function $s :\n  \\N \\to \\N$ such that $U(s(\\pair{p}{q}), x) = V(\\pair{p}{q}, x)$ since $U$ is a\n  G\\\"odel universal function. Hence, if we define $c(p, q)$ to be equal to\n  $s(\\pair{p}{q})$, we get that $U(c(p, q), x) = U(p, U(q, x))$.\n\\end{proof}\n\nUsing the notion of G\\\"odel universal function we can also prove that\nconstructing the shortest program solving a given problem is not feasible. In\nother words let us consider the problem of producing the shortest algorithm\n$\\Algorithm{A}$ by a given $\\Algorithm{B}$ such that\n$\\Algorithm{A}(x) = \\Algorithm{B}(x)$ for any $x \\in \\N$. Apparently there is\nno algorithm that can find such $\\Algorithm{A}$.\n\nTo prove this we need to formalize what we mean by the shortest algorithm and\nhow we encode $\\Algorithm{A}$.\n\\begin{theorem}\n\\label{theorem:program-optimization}\n  Let $U$ be a G\\\"odel universal function, and let $\\Optimize : \\N \\to \\N$ be\n  the function such that $U_{\\Optimize(n)}$ is the same as $U_n$ and $U_m$ and\n  $U_n$ are different for any $m < \\Optimize(n)$. Then $O$ is not computable.\n\\end{theorem}\n\nTo prove this statement we need the following auxilary result.\n\\begin{theorem}\n\\label{theorem:undefined-functions}\n  Let $U$ be a G\\\"odel universal function. \n  Then the set \n  $S = \\set[U(n, x) \\text{ is not defined for all } x \\in \\N]{n \\in \\N}$ is\n  not decidable.\n\\end{theorem}\n\\begin{proof}\n  Let $K$ be a enumerable but undecidable set.\n  Consider the partial function $V : \\N^2 \\to \\N$ such that \n  \\[\n    V(n, x) = \n    \\begin{cases}\n      0 & \\text{if } n \\in K \\\\\n      \\text{undefined} & \\text{otherwise}\n    \\end{cases}.\n  \\]\n  Note that $V(n, x)$ terminates for some $x \\in \\N$ iff $n \\in K$. \n  Since $U$ is G\\\"odel universal function there is a computable function $s$\n  such that $V(n, x) = U(s(n), x)$. Hence, $s(n) \\in S$ iff $n \\in K$.\n  As a result, $S$ is undecidable.\n\\end{proof}\n\n\\begin{proof}[Proof of \\Cref{theorem:program-optimization}]\n  Let $S$ be the set from the previous theorem.\n  Assume, for the sake of contradiction, that $\\Optimize$ is computable. Let\n  $n_0$ be the smallest natural number $n$ such that $U(n, x)$ is not defined\n  for all $x \\in \\N$. It is clear that $n \\in S$ iff $\\Optimize(n) = n_0$.\n  Therefore $S$ is decidable, which is a contradiction.\n\\end{proof}\n\n\\Cref{theorem:undefined-functions,theorem:halting,theorem:program-optimization}\nproved that several properties of algorithms cannot be computed or verified.\nThe following theorem says that this is not a coincidence, and essentially any \nnontrivial property of algorithms cannot be verified efficiently.\n\\begin{theorem}[Rice -- Uspensky]\n  Let $\\Computable$ be the set of all computable functions, and let\n  $\\mathcal{P} \\subseteq \\Computable$ be some nontrivial set of computable\n  funcitons ($\\mathcal{P} \\neq \\emptyset$ and $\\mathcal{P} \\neq \\Computable$).\n  Let $U : \\N^2 \\to \\N$ be a universal G\\\"odel function. Then the set \n  $S = \\set[U_n \\in \\mathcal{P}]{n \\in \\N}$ is undecidable.\n\\end{theorem}\n\\begin{proof}\n  This theorem can be proved using almost the same method as\n  \\Cref{theorem:undefined-functions}.\n\n  Let $f : \\N \\to \\N$ be a partial function that is not defined at all $x \\in\n  \\N$. Without loss of generality we may assume that $f \\in \\mathcal{P}$.\n  Let $g : \\N \\to \\N$ be a function from $\\Computable \\setminus \\mathcal{P}$.\n\n  Let $K$ be a enumerable but undecidable set.\n  Consider the partial function $V : \\N^2 \\to \\N$ such that \n  \\[\n    V(n, x) = \n    \\begin{cases}\n      g(x) & \\text{if } n \\in K \\\\\n      \\text{undefined} & \\text{if } n \\not\\in K \n    \\end{cases}.\n  \\]\n  Note that $V_n \\not\\in \\mathcal{P}$ iff $n \\in K$. \n  Since $U$ is G\\\"odel universal function there is a computable function $s$\n  such that $V(n, x) = U(s(n), x)$. Hence, $s(n) \\not\\in S$ iff $n \\in K$.\n  As a result, $S$ is undecidable.\n\\end{proof}\n\nLet $U$ be a G\\\"odel universal funciton.\nA simple corollary of the \\Cref{theorem:undefined-functions} is that the set \n$\\set[U(n, x) \\text{ is not defined for all } x \\in \\N]{n \\in \\N}$ has\ninfinitely many elements but it is not equal to the set of natural numbers. This\nsimple observation allows us to prove that not all universal functions are\nG\\\"odel universal functions.\n\\begin{theorem}\n\\label{theorem:universal-not-godel}\n  There is a universal function $U : \\N^2 \\to \\N$ such that $U$ is not  G\\\"odel\n  universal function.\n\\end{theorem}\n\\begin{proof}\n  Let $U$ be a G\\\"odel universal function. Note that the set \n  $S = \\set[U(n, x) \\text{ is defined for some } x \\in \\N]{n \\in \\N}$ is\n  enumerable. Hence, there is a computable bijection $d : \\N \\to S$.\n\n  Let us consider $V : \\N^2 \\to \\N$ such that $V(i + 1, x) = U(d(i), x)$ for \n  $i, x \\in \\N$ and $V(1, x)$ undefined for all $x \\in \\N$. It is clear that $V$\n  is computable universal function. However, the set \n  \\[  \n    \\set[V(n, x) \\text{ is not defined for all } x \\in \\N]{n \\in \\N} = \\set{1}\n  \\]\n  cannot be undecidable. As a result, $V$ is not G\\\"odel universal\n  function.\\marginurl[3cm]{%\n    In fact, Friedberg (Journal of Symbolic Logic 23 (1958), 309-318)\n    constructed a universal function such that any computable function has only\n    one number; i.e., it is possible to create a programming language such that\n    each programming problem has a unique solution in it.\n  }{doi.org/10.2307/2964290}\n\\end{proof}\n\n\\begin{chapterendexercises}\n  \\exercise Let $U : \\N^2 \\to \\N$ be a computable universal function for the\n    class of univariate computable functions. Assume that for any universal\n    computable function $V : \\N^2 \\to \\N$, there is a computable function \n    $s : \\N \\to \\N$ such that\n    \\[\n      V(n, x) = U(s(n), x)\n    \\]\n    for all $n, x \\in \\N$.\n  \\exercise Let $U$ be a G\\\"odel universal function. Show that for any\n    computable function $V : \\N^3 \\to \\N$, there is a total computable function\n    $s : \\N^2 \\to \\N$ such that $U(s(m, n), x) = V(m, n, x)$ for all $m, n, x\n    \\in \\N$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "09157ed8e1daa66378ca628be0d9704414874cf8", "size": 9380, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_9/chapter_37_godel_numberings.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_9/chapter_37_godel_numberings.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_9/chapter_37_godel_numberings.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.4356435644, "max_line_length": 85, "alphanum_fraction": 0.6812366738, "num_tokens": 2967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673359709796, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.6941177816214893}}
{"text": "\n\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\n\nPattern matching is a fundamental string processing problem. Pattern matching algorithms are also called string searching algorithms, and it is defined a class of string algorithms that try to find a place where one or several strings (also called patterns) are found within a larger string or text. Based on if some mismathces are allowed or not, we have \\textbf{Exact or Approximate} Pattern Matching. In this section, we start from exact single-pattern matching algorithms where we only need to find one pattern in a given string or text. \nBased on how on how many patterns we might have, we have \\textbf{one-time or multiple-times} string pattern matching problems. For multiple-times matching, preprocessing the text using suffix array/trie/tree can improve the total efficiency.  This chapter is organized as:\n\\begin{enumerate}\n    \\item Exact Pattern Matching: includes one-pattern and multiple patterns. \n    \\item Approximate Pattern Matching:\n\\end{enumerate}\n\n\n\\section{Exact Single-Pattern Matching}\n\n\\paragraph{Exact Single-pattern Matching Problem}  Given two strings or two arrays, one is pattern \\textbf{P} which has size $m$, and the other is the target string or text \\textbf{T} which has size $n$, the exact single-pattern matching problem is defined as finding the first one or all occurrences of pattern P in the T as substring, and return the starting indexes of all the occurrences. \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.7\\columnwidth]{fig/brute_force_matching.png}\n    \\caption{The process of the brute force exact pattern matching}\n    \\label{fig:brute_force_string_matching}\n\\end{figure}\n\n\\paragraph{Brute Force Solution} The naive searching is straightforward, we slide the pattern P like sliding window algorithm through the text T one by one item. At each position $i$, we compare P with T[i:i+m]. In this process, we need to do $n-m$ times of comparison, and each comparison takes maximum of $m$ times of computation. This brute force solution gives $O(mn)$ time complexity.\n\\begin{lstlisting}[language=Python]\ndef bruteForcePatternMatching(p, s):\n    if len(p) > len(s):\n        return [-1]\n    m, n = len(p), len(s)\n    ans = []\n    for i in range(n-m+1):\n        if s[i:i+m] == p:\n            ans.append(i)\n    return ans\n    \np = \"AABA\"\ns = \"AABAACAADAABAABA\"\nprint(bruteForcePatternMatching(p,s))\n# output\n# [0, 9, 12]\n\\end{lstlisting}\nWe write it in another way that use less built-in python function:\n\\begin{lstlisting}[language=Python]\ndef bruteForcePatternMatchingAll(p, s):\n    if not s or not p:\n        return []\n    m, n = len(p), len(s)\n    i, j = 0, 0\n    ans = []\n    while i < n:\n        # do the pattern matching  \n        if s[i] == p[j]:\n            i += 1\n            j += 1\n            if j == m: #collect position\n                ans.append(i - j)\n                i = i-j+1\n                j = 0\n        else:\n            i = i -j + 1\n            j = 0\n    return ans\n\\end{lstlisting}\n\nFor LeetCode Problems, most times, brute force solution will not be accepted and receive LTE. In real applications, such as human genome matching, the text can have approximate size of $3*10^9$ and the pattern can be very long to, such as $10^8$. Therefore, other faster algorithms are needed to improve the efficiency. \n\nThe other algorithms requires us preprocess either/both the pattern and text. In this book, we mainly discuss three algorithms:\n\\begin{enumerate}\n    \\item Knuth Morris Pratt (KMP) Algorithm (Section~\\ref{pattern_matching_subsec_kmp}). KMP is  a linear algorithm, and it should mostly be enough to solve interview related string matching, and also once we understand the algorithm, the implementation is quite trivial, which makes it a very good algorithm during interviews. It has $O(m+n)$ and $O(m)$ in the case of the time and space complexity.\n    \\item Suffix Trie/Tree/Array Matching (Section~\\ref{pattern_matching_subsec_suffix_array}).\n\\end{enumerate}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%% Knuth Morris Pratt\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Prefix Function and Knuth Morris Pratt (KMP)}\n\\label{pattern_matching_subsec_kmp}\nIn the above brute force solution, we compare our pattern with each item as starting window in the text. Each matching result is independent of each other, which is a lot of information lose to improve the efficiency. \n\n\\paragraph{Skipping Positions} See Fig.~\\ref{fig:brute_force_string_matching}, we know a matching at step 1. Is it necessary for us to do step 2 and step 3? The pattern itself tells us it is impossible to get a match at step 2 and step 3 because 'b' will dismatch 'a' and 'r' will dismatch 'a' too. However, at the original step 4, by analyzing the pattern itself we know 'a' will match 'a', and any step further, we have not enough information to cover, therefore, step 4 is necessary to compare 'c' with 'b' in the pattern. In this example, step 4, 5, 6, 7 are all needed but step 4, 5, 6 will only end up do one or two comparison each step. \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.7\\columnwidth]{fig/skipping_rule_kmp.png}\n    \\caption{The Skipping Rule}\n    \\label{fig:skipping_rule_kmp}\n\\end{figure}\n\n The reason why step 2 and 3 can be skipped can be shown from Fig.~\\ref{fig:skipping_rule_kmp}. If we analyze our pattern at first, we will know at step 2 and step 3, ``bra'' not equals to ``abr'' and ``ra'' not equals to ``ab''. While at step 4, we do have ``a'' equals to ``a''. If we observe further of the relations of these pairs, we will know they are suffix and prefix of the same length of the pattern. Inspired by this, we define \\textbf{border} of string S as a prefix of S which is equals to a suffix of the same length of S, but not equals to the whole S. For example:\n \\begin{lstlisting}[numbers=none]\n ''a'' is a border of 'arba'\n 'ab' is a border of 'abcdab'\n 'ab' is not a border of 'ab'\n \\end{lstlisting}\n \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.7\\columnwidth]{fig/shifing_pattern.png}\n    \\caption{The Sliding Rule}\n    \\label{fig:sliding_rule_kmp}\n\\end{figure}\n\n%\\url{https://cp-algorithms.com/string/prefix-function.html}\n\\paragraph{Prefix Function} A Prefix function for a string P generates an array $l$ (lps is short for failure loopkp table) of the same length of string, where $lps[i]$ is the length of the longest border of for prefix substring P[0...i]. Mathematically the definition of prefix function can be written as follows:\n\\begin{equation}\n    l[i] = \\max_{k=0,...,i}\\{k: P[0...k-1] = P[i-(k-1)...i\\}\n\\end{equation}\nThe naive implementation of prefix-function takes $O(n^3)$:\n\\begin{lstlisting}[language=Python]\ndef naiveLps(p:str):\n  dp = [0] * len(p)\n  for i in range(1, len(p)):\n    for l in range(i, 0, -1): # from maxmim length to length 1\n      prefix = p[0: l]\n      suffix = p[i - l+1: i+1]\n      #print(prefix, suffix)\n      if prefix == suffix:\n        dp[i] = l\n        break\n  return dp\n\\end{lstlisting}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.7\\columnwidth]{fig/kmp_lemma_proof.png}\n    \\caption{Proof of Lemma}\n    \\label{fig:proof_border_property}\n\\end{figure}\n\nFor example, prefix function of string ``abcabcd'' is [0,0,0,1,2,3,0]. The trivial algorithm to implement this has $O(n^3)$ time complexity (one for loop for i, second nested for loop for k, and another n for comparing corresponding substring), which exactly follows the definition of the prefix function.  The efficient algorithm which is demonstrated to run in $O(n)$ was proposed by Knuth and Pratt and independently from them by Morris in 1977. It was used as the main function of a substring search algorithm. This is the core of Knuth Morris Pratt (KMP) algorithm. In order to implement the prefix function in linear time, we first need to utilize two properties ( facts) for the purpose of two further optimization:\n\\begin{enumerate}\n    \\item \\label{observation_1} Observation: $\\pi[i+1] \\leq \\pi[i] + 1$, which states that the value of the prefix function can either increase by one, stay the same, or decrease by some amount.\n    \\item \\label{Lemma_1} Lemma: \\textbf{If $l[i] > 0$, then all borders of P[0...i] but for the longest one are also borders of $P[0...l(i)-1]$.} The proof is: As shown in Fig.~\\ref{fig:proof_border_property}, $l(i)$ is the longest border for P[0...i]. We let $\\mu$ be another shorter border of P[0...i] such that $|\\mu| < l(i) $. Because the first l(i) and the second is the same, this means at the first l(i), the suffix of l(i) that of the same length of $\\mu$ is $\\mu$. This states that $\\mu$ is both a border of P[0...l(i)-1].  \n \n\\end{enumerate}\n\nNow, with such knowledge we can do the following two further optimization:\n\\begin{enumerate}\n    \\item With \\ref{observation_1}, the complexity can be reduced to $O(n^2)$ by getting rid of the for loop on $k$. Because each step the prefix function can grow at most one. And among all iterations of $i$, it can grow at most $n$ steps, and also only can decrease a total of $n$ steps. \n    \\item With \\ref{Lemma_1}, we can further get rid of the $O(n)$ string comparison each step. To accomplish this, we have to use all the information computed in the previous steps: all borders of P[0...i] (assuming it has k in total) can be enumerated from the longest to shortest as: $b_0 = \\pi(i)$, $b_1 = \\pi(b_0-1)$, ..., $b_{k-1} = \\pi(b_{k-2}-1)$ ($b_{k-1} = 0$). Therefore, at step posited at $i+1$, instead of comparing string $s[0...\\pi(i)]$ with $s[i-(\\pi(i)-1)...i]$, comparison of char $s[\\pi(i)]$ and $s[i]$ is needed.\n\\end{enumerate}\n\n\n\n\\paragraph{Implementation of Prefix Function for a Given String S} Let's recap the above optimization to get the final algorithm which computes prefix function in $O(n)$. This step is of key importance to the success of KMP algorithm. Let's understand this together with the algorithm statement and the code. \n\\begin{enumerate}\n    \\item Initialization: assign $n$ space to $l$ array and set $l_0 = 0$. \n    \\item A for loop in range of [1, m-1] to compute $l(i)$. Set a variable j = $l(i-1)$, and a while loop over j until j = 0: check if s[j] == s[i]; if true, $l(i)=j+1$, otherwise reassign j $j = l(j-1)$ in order to check smaller border.\n\\end{enumerate}\n\\begin{lstlisting}[language=Python]\ndef prefix_function(s):\n    n = len(s)\n    pi = [0] * n\n    for i in range(1, n):\n        # compute l(i)\n        j = pi[i-1]\n        while j > 0 and s[i] != s[j]: # try all borders of s[0...i-1], from the longest to the shortest\n            j = pi[j-1]\n        # check the character\n        if s[i] == s[j]:\n            pi[i] = j + 1\n\n    return pi\n\\end{lstlisting}\n\nRun an example:\n\\begin{lstlisting}[language=Python]\nS = 'abcabcd'\nprint('The prefix function of: ', S, \" is \", prefix_function(S))\n\nThe prefix function of:  abcabcd  is  [0, 0, 0, 1, 2, 3, 0]\n\\end{lstlisting}\n\n\\paragraph{Knuth Morris Pratt (KMP)} Back to the problem of eaxact pattern matching, we first build a new string as $s = P+'\\$'+T$,  which is a concatenation of pattern P, '\\$', and text T. Let us calculate the prefix function of string s. Now, let us think about the meaning of the prefix function, except for the first $m+1$ items (which belong to the string P and the separator '\\$'): \n\\begin{enumerate}\n    \\item For all $i$, $\\pi[i] \\leq m$ because of the separator '\\$' in the middle of the pattern and the text that acts as a separator. \n    \\item If $\\pi[i] = m$, i.e. $K[0:m] = K[i-m:i] = P$. This means that the pattern P appears completely in the new string s and ends at position $i$. Now, we convert $i$ to the starting position of pattern in T with $i-2m$.\n    \\item If $f[i] < m$, no full occurrence of pattern ends with position i. \n\\end{enumerate}\n\nThus the Knuth-Morris-Pratt algorithm solves the problem in $O(n+m)$ time and $O(n+m)$ memory. And can be simply implemented with prefix function as follows:\n\\begin{lstlisting}[language=Python]\ndef KMP_coarse(p, t):\n    m = len(p)\n    s = p + '$' + t\n    n = len(s)\n    pi = prefix_function(s)\n    ans = []\n    for i in range(2*m, n):\n        if pi[i] == m:\n            ans.append(i - 2*m)\n    return ans\n\\end{lstlisting}\n\nBecause for all $\\pi[i] \\leq m$: for i in [0, m-1], we save the border in $\\pi$; for i in [m, n+m-1], we set up a global variable $j$ to track the last border. We can decrease the space complexity in $O(m)$.\nThe Python implementation is given as: \n\\begin{lstlisting}[language=Python]\ndef KMP(p, t):\n    m = len(p)\n    s = p + '$' + t\n    n = len(s)\n    pi = [0] * m\n    j = pi[0]\n    ans = []\n    for i in range(1, n):\n        # compute l(i)\n        while j > 0 and s[i] != s[j]: # try all borders of s[0...i-1], from the longest to the shortest\n            j = pi[j-1]\n        # check the character\n        if s[i] == s[j]:\n            j += 1\n        # record the result\n        if j == m:\n            ans.append(i-2*m)\n        # save the result if i in [0, m-1]\n        if i < m:\n            pi[i] = j\n    return ans\n\\end{lstlisting}\n\nRun an example:\n\\begin{lstlisting}[language=Python]\nt = 'textbooktext'\np = 'text'\nprint(KMP(p, t))\n# output\n# [0, 8]\n\\end{lstlisting}\n\n\\paragraph{Sliding Rule with Border Information} Now, assuming we know how to compute the border information, how do we slide instead compared with the brute force solution? There are three steps, with Fig.~\\ref{fig:sliding_rule_kmp} as demonstration:\n\n\\begin{enumerate}\n    \\item Find longest common prefix $\\mu$.\n    \\item Find $w$ -- the longest border of $\\mu$. \n    \\item Move P such that prefix $w$ in P aligns with suffix $w$ of $\\mu$ in T. \n\\end{enumerate}\n% There exists redundant comparison between pattern and the text at different location. For example in the following case, we found a match at pos 0, if we know p[0:3]==p[1:4], then we know p[0:3]==s[1:4], in the next sliding window, s[1:5], we only need to compare if p[3]==s[4]. \n%  \\begin{lstlisting}[numbers=none]\n% txt = \"AAAAABAAABA\" \n% pat = \"AAAA\"  [Initial position]\n%  \\end{lstlisting}\n\n% Knuth Morris Pratt is an exact pattern matching algorithm, which preprocesses the pattern string at first to recognize those patterns having same sub-patterns appearing more than once to skip characters while matching.  \n\n% \\textbf{Pattern Lookup Table.} Therefore, for the pattern we preprocess it and construct an auxiliary lookup table of size $m$ which saves the longest length of prefix before current index i which is the same as suffix. We define the table as f, we have that f[0] = 0, if f[i] = t, it means $P[:t+1] = P[i-t:i]$. The following figure(Fig~\\ref{fig:lookup}) shows the example of a lookup table. \n% \\begin{figure}[h]\n    \n%     \\centering\n%     \\includegraphics[width = 0.98\\columnwidth]{fig/lookup.jpg}\n%     \\caption{The example of lookup table of KMP, which can be generated with dynamic programming.}\n%     \\label{fig:lookup}\n    \n%     \\includegraphics[width = 0.98\\columnwidth]{fig/lookup_table.jpg}\n%     \\caption{The example of lookup table of KMP}\n% \\end{figure}\n\n% \\textbf{Generate Lookup Table with Dynamic Programming.} Now, we have not learn dynamic programming yet, you can come to digest this section more later. We initiate f[0]=0. At the 6th row with 'ABCDAB', we know before at 'ABCDA', the prefix 'A' matches suffix 'A', now we compare current char 'B' with the one next to prefix 'A' at position f[i-1], if it matches, then f[i] = f[i-1]+1. If it does'nt match, at 7th row, 'D' != 'C', thus we cant have 3 as the answer, we retreat to  check position f[i-2], where we have 'D'!='B', we retreat to f[i-3], and where 'A'!='D', then we have i-4 < 0, we stop, and put 0 as the result. The Python code is given as follows:\n% \\begin{lstlisting}[language=Python]\n% def LPS(p):\n%     m = len(p)\n%     f = [0] * m\n%     for i in range(1, m):\n%         # chek the previous position\n%         check_pos = f[i-1]\n%         if p[i] == p[check_pos]:\n%             f[i] = check_pos + 1 \n%             break\n%     return f\n% print(LPS(\"ABAB\"))\n% print(LPS(\"AAABAAA\"))\n% # output\n% # [0, 0, 1, 2]\n% # [0, 1, 2, 0, 1, 2, 3]\n% \\end{lstlisting}\n\n% \\begin{lstlisting}[language = Python]\n% # Generating lookup table for string S using Python\n% f=[0]*n\n% for i in xrange(1,n):\n%     t = f[i-1]\n%     while t > 0 and S[i] != S[t]:\n%         t = f[t-1]\n%     if S[i] == S[t]:\n%         t +=1 \n%     f[i] = t\n% \\end{lstlisting}\n\\paragraph{Knuth Morris Pratt $O(m+n)$} Now, to complete the picture of KMP, when we have the lookup table at hand, when we failed to match i and j, we set j = lps[j-1], and i doest not need to backtrack.\n\\begin{lstlisting}[language = Python]\ndef KMP(p, ps):\n    f = LPS(p)\n    n =m, n = len(p), len(ts)\n\n    i = 0 # index in s\n    j = 0 # index in p\n    pos = []\n    while i < n:\n        if p[j] == s[i]:\n            i += 1 \n            posj += 1 \n            dp[i] = pos\n            if dp[i] == m:if j == m: # i at i+1, j at f[j-1]\n                print(\"Found pattern at index \", i-j) \n                ans.append(i-2*mj)\n            i += 1\n        else:\n            if pos > 0:    j = f[j-1] \n        else: # mismatch at i and j \n            if j != 0: # if j can retreat with lps, then i keep the same\n                pos = dp[posj = f[j-1]\n            else:\n                i += 1 #the value is 0\n    return ans # if j needs to start over, i moves too \n                i += 1\n    return ans\nprint(KMP(p,s))\n# [0, 9, 12]\n\\end{lstlisting}\n\n%%%%%%%%%%%%%%%%%%%%%%Application of Prefix Function\n\\subsection{More Applications of Prefix Functions}\n\n\n\\paragraph{Counting the number of occurrences of each prefix}\n\n\\paragraph{Counting the number of occurrences of different substring in a string}\n\n\\paragraph{Compressing a string}\n\n% \\paragraph{}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%Z-function%%%%%%%%%%%\n\\subsection{Z-function} \n\\subsubsection{Definition and Implementation}\nZ-function for a string $s$ of length $n$ is defined as an array $z[i] = k, i \\in [1, n-1]$. At item $z[i]=k$ stores the longest substring starting at index $i$ which is also a prefix of string $s$. To notice, the length of the substring has to be smaller than the whole length, therefore, $z[0]=0$.  In other words, it means the  the length of the longest common prefix between $s$ and substring $s[i:n]$. %Thus, $z[i]=k$  tells us that $s[0...k-1] = s[i...i+k−1]$. \nFor example:\n\\begin{lstlisting}[numbers=none]\n\"aaaaa\" - [0,4,3,2,1]\na\na substring 'aaaa' = prefix 'aaaa'\na substring 'aaa' = prefix 'aaa'\na substring 'aa' = prefix 'aa'\na substring 'a' = prefix 'a'\n\\end{lstlisting}\nAnother Example.\n\\begin{lstlisting}[numbers=none]\n\"aaabaab\" - [0,2,1,0,2,1,0]\na  0 \na  substring 'aa' = prefix 'aa'\na  substring 'a' = prefix 'a'\nb  0\na  substring 'aa' = prefix 'aa'\na  substring 'a' = prefix 'a'\nb  \n\\end{lstlisting}\nz-function can be represented with a formula:\n\\begin{equation}\n    l[i] = \\max_{k=0,...,i}\\{k+1: P[0...k] = P[i...i+k]\\}\n\\end{equation}\nThe naive implementation of  z-function takes $O(n^2)$ time complexity just as the prefix function. \n\\begin{lstlisting}[language=Python]\ndef naiveZF(s):\n  n = len(s)\n  z = [0] * n\n  for i in range(1, n): # starting point\n    k = 0\n    while i + k < n and s[i + k] == s[k]:\n      k += 1\n    z[i] = k\n  return z\n\\end{lstlisting}\n\\paragraph{Z-function Property}\nHere, we show how we can implement it in $O(n)$. To compute $z[i]$, do we have to start at $i$, then follows the order of $i+1$, $i+2$, ..., $i+k$? The answer is No.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.9\\columnwidth]{fig/z_function.png}\n    \\caption{Z function property}\n    \\label{fig:z_function_property}\n\\end{figure}\nFirst, As shown in Fig.~\\ref{fig:z_function_property}, for a given position $i$,  $[l, r]$ is one of its preceding non-zero $z[p], p< i$, which has the furthest right boundary $r$. We can think it as a rightmost window, wherein $s[l, r] = s[0, r-l+1]$.  $s[0, i-l]$ is marked as yellow. We divide the area in range $[0, r-l+1]$ into yellow $[0, l-i]$ and a green parts $[l-i+1, r-l+1]$. Therefore, to compare range $[i, r]$ with prefix is the same as of comparing range $[l-i+1, r-l+1]$ with the prefix, which already has a result $z[i-l]$. So instead, our $k$ can start from position $z[i-l]$. However, there are two more restrictions:\n\\begin{enumerate}\n    \\item Enable to utilize z-function property, $r \\geq i$ because the index $r$ can be seen as ``boundary'' to which our string $s$ has been scanned by the algorithm. \n    \\item The initial approximation for $z[i]$ is bounded by the length between $r$ and $i$, which is $r-i+1$. Therefore, we modify our initial approximation to $z[i]$ to $z[i] = \\min(r-i+1, z[i-l])$ instead.\n\\end{enumerate}\n\nNow, the $O(n)$ implementation is given as follows:\n\\begin{lstlisting}[language=Python]\ndef linearZF(s):\n  n = len(s)\n  z = [0] * n\n  l = r = 0\n  for i in range(1, n): \n    k = 0\n    if i <= r: # r is the right bound has been scanned\n      k = min(r-i+1, z[i - l])\n    while i + k < n and s[i+k] == s[k]:\n      k += 1\n    # update the boundary\n    if i + k - 1 > r:\n      l = i\n      r = i + k - 1 \n    z[i] = k \n  return z\n\\end{lstlisting}\n\n\\subsubsection{Applications}\nThe applications of Z-function are largely similar to those of prefix function. Therefore, the applications will be explained briefly compared with the applications of prefix functions. If you have problems to understand this section, please read the prefix function first.\n\n\\paragraph{Exact Single-Pattern Matching} In this problem set, we are asked to find all occurrences of the pattern $p$ inside the text $t$. We can do the same as of in the KMP, we create a new string $s=p+\\$+t$. Then, we compute the z-function for $s$. With the z array, for $z[i]=k$, if $k=|p|$, then we know there is one occurrence of p starting in the i-th position in $s$, which is $i-(|p|+1)$ in the t. \n\\begin{lstlisting}[language=Python]\ndef findPattern(p, t):\n  s = p + '$' + t\n  m = len(p)\n  z = (linearZF(s))\n  ans = []\n  for i, v in enumerate(z):\n    if v == m:\n      ans.append(i-m-1)\n  return ans\n\\end{lstlisting}\n\n\\paragraph{Number of distinct substrings in a string} Given a string s of length n, count the number of distinct substrings of s. \n\nTo solve this problem we need to use dynamic programming and the subproblems are $s[0...0]$, $s[0...1]$, ..., $s[1...i]$,...$s[0...n-1]$. For example, given ``abc'', \n\\begin{lstlisting}[numbers=none]\nsubproblem 1: 'a', dp[0] = 1\nsubproblem 2: 'ab', dp[1] = 2, with new substrings 'b', 'ab'\nsubproblem 3, 'abc', dp[2] = 3, new substrs 'c', 'bc', 'abc'\n\\end{lstlisting}\n\nWe know the maximum for dp[i] is $i+1$, however for cases like ``aaa''', the situation is different:\n\\begin{lstlisting}[numbers=none]\nsubproblem 1: 'a', dp[0] = 1\nsubproblem 2: 'aa', dp[1] = 1, 'aa', because 'a'_1 == 'a_0'\nsubproblem 3, 'aaa', dp[2] = 1, new substrs 'aaa', because 'a_0a_1'='a_1a_2', 'a_2' = 'a_0'. \n\\end{lstlisting}\n\nIf for each subproblem i, we take the string s[0...i] and reverse it $i...0$. If using z-function on this substring, we can find the number of prefixes of the reversed string are found somewhere else in it, which is the maximum value of its z-function.  This is because if we know z[j] = max(k), then s[i...i-max-1] = s[i-j...i-j+max], which is to say s[i-max-1...i] = s[i-j-max...i-j]\nWith the max value, all of the shorter prefixes also occur too. Therefore, $dp[i] = i+1 - max(z[i])$. The time complexity is $O(n^2)$\n\\begin{lstlisting}[language=Python]\ndef distinctSubstrs(s):\n  n = len(s)\n  if n < 1:\n    return 0\n  ans = 1 # for dp[0]\n  #last_str = s[0:1]\n  for i in range(1, n):\n    reverse_str = s[0:i+1][::-1]\n    z = linearZF(reverse_str)\n    ans += (i + 1 - max(z))\n  return ans\n\\end{lstlisting}\n\nRun an example:\n\\begin{lstlisting}[language=Python]\ns = 'abab'\nprint(distinctSubstrs(s))\n# output\n# 7\n\\end{lstlisting}\n\n\\section{Exact Multi-Patterns Matching}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%% Rabin-Karp algorithm\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Suffix Trie/Tree/Array Introduction}\n\\label{pattern_matching_subsec_suffix_trie}\nUp till now, prefix function and the KMP algorithms seems impeccable with its liner time and space complexity. However, there are two problems that KMP can not resolve:\n\\begin{enumerate}\n    \\item Approximate matching, which we will detail more in the next section.\n    \\item If frequent queries will be made on the same text with a given pattern, and if the $m<<n$, then KMP become impractical.\n\\end{enumerate}\n\nThe solution to the second problem of KMP is preprocess the text and store it in order to obtain an algorithm with time complexity only related to the length of the pattern for each query. Building a suffix trie of the text is such a solution. \n\n\\paragraph{Suffix Trie} A suffix trie of a given string is defined as: \n\n\\paragraph{Suffix Tree} If we compress the above suffix trie, we get suffix tree. \n\n\\paragraph{Suffix Array} Suffix Array is further applied with the benefits of saving space in storage. \n\n\\paragraph{Suffix Tree VS Suffix Array} Each data structure has its own pros and cons. In reality, conversion between these two can be implemented in $O(n)$ time. Therefore, we can first construct one and convert it to the other later. \n\n\\subsection{Suffix Array and Pattern Matching}\n\\label{pattern_matching_subsec_suffix_array}\n\\subsubsection{Definition and Implementation}\nSuffix Array of a given string s is defined as all suffixes of this string in lexicographical order. Because no any two suffixes can have the same length, thus the sorting will not have equal items. For example, given s = 'ababaa', the suffix array will be:\n\\begin{lstlisting}[numbers=none]\n'a'\n'aa'\n'abaa'\n'ababaa'\n'baa'\n'babaa'\n\\end{lstlisting}\n\nTo avoid the prefix rule defined in the lexicographical order, as shown with example 'ab' < 'abab', we append a special character '\\$' at the end of all suffixes. '\\$' is smaller than all other characters. With this operation, we have 'ab\\$' and 'abab\\$'. At position 2, '\\$' will be smaller than 'a' or any other character and 'ab\\$' is still smaller than 'abab\\$'. Therefore, adding this special character will not lead to different sorting result, and can avoid the prefix rule when comparing two different strings. \n\n\\paragraph{Naive Solution with $O(n^2\\log n)$ time complexity} With this knowledge, we get s = s + '\\$', and we can generate the suffix array and sort them. A stable sorting algorithm takes $O(n\\log n)$ comparison, and each comparison takes additional $O(n)$, which makes the total time complexity of $O(n^2\\log n)$. \n\\begin{lstlisting}[language=Python]\ndef generateSuffixArray(s):\n    s = s + '$'\n    n = len(s)\n    suffixArray = [None]*n\n    # generate\n    for i in range(n):\n        suffixArray[i] = s[i:]\n    #print(suffixArray)\n    suffixArray.sort()\n    print(suffixArray)\n    # save space by storing the order of the suffixes, which is the starting index\n    for idx, suffix in enumerate(suffixArray):\n         suffixArray[idx] = n - len(suffix)\n    print(suffixArray)\n    return suffixArray\n\\end{lstlisting}\n\nRun the above example, we will have the following output:\n\\begin{lstlisting}[numbers=none]\n['$', 'a$', 'aa$', 'abaa$', 'ababaa$', 'baa$', 'babaa$']\n[6, 5, 4, 2, 0, 3, 1]\n\\end{lstlisting}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.5\\columnwidth]{fig/cyclic_shift.png}\n    \\caption{Cyclic Shifts}\n    \\label{fig:clyclic_shifts}\n\\end{figure}\n\\paragraph{Cyclic Shifts} For our example, we start at position 0, we get the first cyclic shift of 'ababaa\\$', and then position 1, we have our second cyclic shift 'babaa\\$a', and so till the last position of the string. Now, let us see what happens if we sort all of the cyclic shifts:\n\\begin{lstlisting}[numbers=none]\n             Sorted    To Suffix Array\n0:ababaa$    $ababaa    $\n1:babaa$a    a$ababa    a$\n2:abaa$ab    aa$abab    aa$\n3:baa$aba    abaa$ab    abaa$\n4:aa$abab    ababaa$    ababaa$\n5:a$ababa    baa$aba    baa$\n6:$ababaa    babaa$a    babaa$\n\\end{lstlisting}\n\nWe know the number of cyclic shifts is the same as of the number of all suffixes of the same string. And by observing the above example, sorting the cyclic shifts will get us sorted suffixes if we remove all characters after '\\$' in each cyclic shift. This conclusion can be hold true for all strings because '\\$' is smaller than all other characters, and with '\\$' at different position in each cyclic shift, once we are at '\\$', the comparison of two strings end because the first one that has '\\$' is smaller than all others. Therefore, all the characters after the '\\$' will not affect the sorting at all. Now, we know that sorting cyclic shifts and suffixes of string s is equivalent with the addition of '\\$' at the end. \n\nIf we can sort the cyclic shifts of string in faster way, then we will find ourselves a more efficient suffix sorting algorithm. One obvious efficient sorting algorithm is using Radix Sort. Using radix sort, we first sort the cyclic shifts by the last character using counting sort, and then the second last character till finishing the first character. Sorting each character for the whole cyclic shifts array takes $O(n)$, and we are running $n$ rounds, this makes the whole sorting of $O(n^2)$ and with $O(n)$ space. However, we can improve these complexity further by using special properties of the Cyclic shifts. %Before we give out the eventual algorithm and implementation, let us learn more concepts to help out later.\n\n\\paragraph{Partial Cyclic Shifts} Different from the cyclic shifts, partial cyclic shifts are defined as $C^{L}_i$ which is the partial cyclic shift of length $L$ starting at index $i$. For the above example, the partial cyclic shift of length 1, 2, and 4 will be :\n\\begin{lstlisting}[numbers=none,mathescape=true, escapechar=\\%]\n  $C^7$      $C^1$   $C^2$    $C^4$\nababaa%\\$%    a    a%\\underline{b}%    ab%\\underline{ab}%\nbabaa%\\$%a    b    b%\\underline{a}%    ba%\\underline{ba}%\nabaa%\\$%ab    a    a%\\underline{b}%    ab%\\underline{aa}%\nbaa%\\$%aba    b    b%\\underline{a}%    ba%\\underline{a\\$}%\naa%\\$%abab    a    a%\\underline{a}%    aa%\\underline{\\$a}%\na%\\$%ababa    a    a%\\underline{\\$}%    a%\\$\\underline{ba}%\n%\\$%ababaa    %\\$%    %\\$\\underline{a}%    %\\$a\\underline{ba}%\n\\end{lstlisting}\nCarefully observing the relation of pair $(C_1, C_2)$ and $(C_2, C_4)$. We can find that $C_1$ and the second half of substring (denoted by underline) in $C_2$ has the same key set. Same rule applies to $C_2$ and the second half of substring in $C_4$.\n\n\\paragraph{Doubled Partial Cyclic Shifts} \\textit{Doubled Partial Cyclic Shifts} of $C^L_i$ is $C^{2L}_i$ and $C^{2L}_i = C^{L}_iC^{L}_{i+L}$ (with concatenation of these two strings). Apply the same methodology of Radix Sort, we can sort the doubled partial shifts by firstly sort the second half and then the first half. Therefore, instead of doing $n$ rounds of counting sort on each character, we do $\\log n$ rounds of sorting of the doubled partial cyclic shifts from the last round. If we can sort each round in $O(n)$, then we make the time complexity to $O(n \\log)$ ($T(n) = T(n/2)$) which is way better than the radix sort of $O(n^2)$.  The starting point of sorting doubled partial cyclic is sorting the partial cyclic shifts with length one. \n\n\\paragraph{Order and Class} \\textit{Order} is defined as the sorted cyclic shift with the starting index as their value. For example, for $C^1$, the sorted order will be $[6, 0, 2, 4, 5, 1, 3]$, which represents $[\\$, a, a, a, a, b, b]$. \\textit{Class} is an array that each item $Class_{i}$ corresponds to $C_i$ and denotes as the number of partial cyclic shifts of the same length that are strictly smaller than $C_i$. For 'ababaa\\$', the class of length 1 will be $[1, 2, 1, 2, 1, 1, 0]$. The reason to bring in the concept of class is because of the rule that the set of first and second half of the doubled partial cyclic shifts share the same key set, and \\textbf{the class is equivalent to the converted key of corresponding partial cyclic shift}. \n\n\\paragraph{Compute Order and Class of Partial Cyclic Shifts of Length 1} For $C^1$: , we can obtain with counting sort with the range of 256 for all common English characters.  For $C^1$,  we know for $[\\$, a, a, a, a, b, b]$, we assign order as $[0, 1, 1, 1, 1, 2, 2]$. Each one corresponds to $C_{order_i}$.  Because the class corresponds to the original string order, therefore, we just need to put these class back to $order_i$ position in the array. We recap this as: we first set $class[order[0]] = 0$, and looping over the order array from [1, n-1], the corresponding character will be $s[order[i]$ and the last order char will be $s[order[i-1]]$.  We just need to compare if it equals.\n\\begin{lstlisting}[numbers=none]\nif s[order[i]] != s[order[i-1]]:\n    # use order as index to put the result back\n    class[order[i]] = class[order[i-1]] + 1\nelse:\n    class[order[i]] = class[order[i-1]]\n\\end{lstlisting}\n\nThe Python implementation  of Computing Order for Partial Cyclic Shift of Length 1, the time complexity is $O(n+k)$, $k$ is the number of possible characters. \n\\begin{lstlisting}[language=Python]\ndef getCharOrder(s):\n  n = len(s)\n  numChars = 256\n  count = [0]*numChars # totally 256 chars, if you want, can print it out to see these chars\n  \n  order = [0]*(n)\n  \n  #count the occurrence of each char\n  for c in s:\n    count[ord(c)] += 1\n    \n  # prefix sum of each char\n  for i in range(1, numChars):\n    count[i] += count[i-1]\n    \n  # assign from count down to be stable\n  for i in range(n-1,-1,-1):\n    count[ord(s[i])] -=1\n    order[count[ord(s[i])]] = i # put the index into the order instead the suffix string\n    \n  return order\n\\end{lstlisting}\n\nThe Python implementation  of Computing Class for Partial Cyclic Shift of Length 1, this can be applied in $O(n)$ given the order. \n\\begin{lstlisting}[language=Python]\ndef getCharClass(s, order):\n  n = len(s)\n  cls = [0]*n\n  # if it all differs, then cls[i] = order[i]\n  cls[order[0]] = 0 #the 6th will be 0\n  for i in range(1, n):\n    # use order[i] as index, so the last index\n    if s[order[i]] != s[order[i-1]]:\n      print('diff',s[order[i]],s[order[i-1]])\n      cls[order[i]] = cls[order[i-1]] + 1\n    else:\n      cls[order[i]] = cls[order[i-1]]\n  return cls\n\\end{lstlisting}\n\nApplying the above two functions, we can get:\n\\begin{lstlisting}[numbers=none]\n   L=1 cls order    CL=2  order cls\ni=0, a:1    $:6     a$:5  $a:6  ab:3\ni=1, b:2    a:0     $a:6  a$:5  ba:4\ni=2, a:1    a:2     ba:1  aa:4  ab:3\ni=3, b:2    a:4     ba:3  ab:0  ba:4\ni=4, a:1    a:5     aa:4  ab:2  aa:2\ni=5, a:1    b:1     ab:0  ba:1  a$:1\ni=6, $:0    b:3     ab:2  ba:3  $a:0\n\\end{lstlisting}\n\n\\paragraph{Sort the Doubled Partial Cyclic shifts} To apply radix sorting, we double our previous sorted partial shifts of $C^L_i$ as $C^{L}_{i-L}C^{L}_{i}$. Given the fact that the second part $C^{L}_{i}$ is already sorted, we just need to sort the first half with counting sort using the class array of the last partial cyclic shifts. The time complexity of this step is $O(n)$ too. The Python implementation of computing the doubled partial cyclic shifts' order is:\n\\begin{lstlisting}[language=Python]\n'''It is a counting sort using the first part as class'''\ndef sortDoubled(s, L, order, cls):\n  n = len(s)\n  count = [0] * n\n  new_order = [0] * n\n  # their key is the class\n  for i in range(n):\n    count[cls[i]] += 1\n    \n  # prefix sum\n  for i in range(1, n):\n    count[i] += count[i-1]\n    \n  # assign from count down to be stable\n  # sort the first half\n  for i in range(n-1, -1, -1):\n    start = (order[i] - L + n) % n #get the start index of the first half, \n    count[cls[start]] -= 1\n    new_order[count[cls[start]]] = start\n    \n  return new_order\n\\end{lstlisting}\n\nNow, similarily, we compute the new class information. The comparison of the string is converted to compare its corresponding class info, as a pair $(P_1, P_2)$ which is the class of the first and second half. \n\\begin{lstlisting}[language=Python]\ndef updateClass(order, cls, L):\n  n = len(order)\n  new_cls = [0]*n\n  # if it all differs, then cls[i] = order[i]\n  new_cls[order[0]] = 0 #the 6th will be 0\n  for i in range(1, n):\n    cur_order, prev_order = order[i], order[i-1]\n    # use order[i] as index, so the last index\n    if cls[cur_order] != cls[prev_order] or cls[(cur_order+L) % n] != cls[(prev_order+L) % n]:\n      new_cls[cur_order] = new_cls[prev_order] + 1\n    else:\n      new_cls[cur_order] = new_cls[prev_order]\n  return new_cls\n\\end{lstlisting}\n\n\n\\paragraph{Sorting Cyclic Shifts in $O(n\\log n)$}  Now, we have derived ourselves a $O(n\\log n)$ suffix array construction algorithm. We start from sorting partial cyclic shifts of length 1 and each time to double the length untill the the sorted length is >= to the string's length.\n\n\\begin{lstlisting}[language=Python]\ndef cyclic_shifts_sort(s):\n  s = s + '$'\n  n = len(s)\n  order = getCharOrder(s)\n  cls = getCharClass(s, order)\n  print(order, cls)\n  L = 1\n  while L < n:\n    order = sortDoubled(s, 1, order, cls)\n    cls = updateClass(order, cls, L)\n    print(order, cls)\n    L *= 2\n  \n  return order\n\\end{lstlisting}\n\n\\subsubsection{Applications}\n\\paragraph{Number of Distinct Substrings of a string}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%% Rabin-Karp algorithm\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Rabin-Karp Algorithm (Exact or anagram Pattern Matching) }\nUsed to find the exact pattern, because different anagram of string would have different hash value.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%% Bonus\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bonus}\n\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.7\\columnwidth]{fig/trie_pattern.png}\n    \\caption{Building a Trie from Patterns}\n    \\label{fig:trie_pattern}\n\\end{figure}\n\\paragraph{Multiple-Patterns Matching} Previously, we mainly talked about exact/approximate one pattern matching. When there are multiple patterns the time complexity became to $O(\\sum_i{m_i*n})$ if brute force solution is used. We can construct a trie of all patterns as shown in Section~\\ref{concept_trie}. For example, in Fig.~\\ref{fig:trie_pattern} shows a trie built with all patterns. \n\nNow, let us do \\textbf{Trie Matching} exactly the same way as the brute force pattern matching algorithm by sliding the pattern trie along the text at each position of text. Each comparison: walk down the trie by spelling symbols of text and a pattern from the pattern list matches text each time we reach a leaf. Try text = ``panamabananas''. We will first walk down branch of p->a->n and stop at the leaf, thus we find pattern `pan`. With Trie Matching, the runtime is decreased to $O(\\max_i{m_i*n})$. Plus the trie construction time $O(\\sum_i{m_i})$. \n\nHowever, merging all patterns into a trie makes it impossible for using advanced single-pattern matching algorithms such as KMP. \n\n\\paragraph{More Pattern Matching Tasks} There are more types of matching, instead of finding the exact occurrence of one string in another.\n\\begin{enumerate}\n    \\item Longest Common Substring (LCS): LCS asks us to return the longest substring between these two strings.\n    \\item Anagram Matching: this asks us to find a substring in T that has all letters in P, and does not care about the order of these letters in P.\n    \\item Palindrome Matching.\n\\end{enumerate}\n\n%%%%%%%%%%%%%%%%%%%Trie%%%%%%%%%%%%%%%%%\n\\section{Trie for String}\n\\label{concept_trie}\n\\paragraph{Definition} Trie comes from the word re\\textbf{Trie}val. In computer science, a trie, also called digital tree, radix tree or prefix tree which like BST is also a kind of search tree for finding substring in a text. We can solve string matching in $O(|T|)$ time,  where |T| is the size of our text.  This purely algorithmic approach has been studied extensively in the algorithms:  Knuth-Morris-Pratt, Boyer-Moore, and Rabin-Karp. However, we entertain the possibility that multiple queries will be made to the same text.  This motivates the development of data structures that preprocess the text to allow for more efficient queries. Such efficient data structure is Trie, which can do each query in $O(P)$, where P is the length of the pattern string. Trie is an ordered tree structure, which is used mostly for storing strings (like words in dictionary) in a compact way. \n\\begin{enumerate}\n    \\item In a Trie, each child branch is labeled with letters in the alphabet $\\sum$. Actually, it is not necessary to store the letter as the key, because if we  order the child branches of every node alphabetically from left to right, the position in the tree defines the key which it is associated to. \n    \\item The root node in a Trie represents an empty string. \n\\end{enumerate}\n% An ordered tree data structure used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. \n\nNow, we define a trie Node: first it would have a bool variable to denote if it is the end of the word and a children which is a list of of 26 children TrieNodes. \n\\begin{lstlisting}[language= Python]\nclass TrieNode:\n    # Trie node class\n    def __init__(self):\n        self.children = [None]*26\n        # isEndOfWord is True if node represent the end of the word\n        self.isEndOfWord = False\n\\end{lstlisting}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]{fig/trie_compact_trie.jpg}\n    \\caption{Trie VS Compact Trie}\n    \\label{fig:trie_compact_trie}\n\\end{figure}\n\n\\paragraph{Compact Trie} If we assign only one letter per edge, we are not taking full advantage of the trie’s tree structure. It is more useful to consider compact or compressed tries, tries where we remove the one letter per edge constraint, and contract non-branching paths by concatenating the letters on these paths.\nIn this way, every node branches out, and every node traversed represents a choice between two different words.  The compressed trie that corresponds to our example trie is also shown in Figure\n~\\ref{fig:trie_compact_trie}. \n\n\\paragraph{Operations: INSERT, SEARCH}\n% Now, let us solve an LeetCode problem together which requires us to implement a complete Trie that with the operations INSERT, SEARCH, STARTWITH. All of these operations are actually quickly similar and they all require us to simultaneously iterate each character in the input string (or word) and each level of the Trie on the location of that character. So, it would not be hard to get the worst time complexity when we searched the whole tree or finished iterating the characters in the input. \nBoth for INSERT and SEARCH, it takes $O(m)$, where m is the length of the word/string we wand to insert or search in the trie. Here, we use an LeetCode problem as an example showing how to implement INSERT and SEARCH. Because constructing a trie is a series of INSERT operations which will take $O(n*m)$, n is the total numbers of words/strings, and m is the average length of each item. The space complexity fof the non-compact Trie would be $O(N*|\\sum|)$, where $|\\sum|$ is the alphlbetical size, and N is the total number of nodes in the trie structure. The upper bound of N is $n*m$. \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]{fig/Trie.png}\n    \\caption{Trie Structure}\n    \\label{fig:trie}\n\\end{figure}\n\\begin{examples}\n\\item \\textbf{208. Implement Trie (Prefix Tree) (medium).} Implement a trie with insert, search, and startsWith methods.\n\\begin{lstlisting}\nExample:\nTrie trie = new Trie();\ntrie.insert(\"apple\");\ntrie.search(\"apple\");   // returns true\ntrie.search(\"app\");     // returns false\ntrie.startsWith(\"app\"); // returns true\ntrie.insert(\"app\");   \ntrie.search(\"app\");     // returns true\n\\end{lstlisting}\n\\textit{Note: You may assume that all inputs are consist of lowercase letters a-z. All inputs are guaranteed to be non-empty strings.}\n\n\\paragraph{INSERT} with INSERT operation, we woould be able to insert a given word in the trie, when traversing the trie from the root node which is a TrieNode, with each letter in world, if its corresponding node is None, we need to put a node, and continue. At the end, we need to set that node's endofWord variable to True. thereafter, we would have a new branch starts from that node constructured. For example, when we first insert ``app`` as shown in Fig~\\ref{fig:trie_compact_trie}, we would end up building branch ``app``, and with ape, we would add nodes ``e`` as demonstrated with red arrows. \n\\begin{lstlisting}[language=Python]\ndef insert(self, word):\n    \"\"\"\n    Inserts a word into the trie.\n    :type word: str\n    :rtype: void\n    \"\"\"\n    node = self.root #start from the root node\n    for c in word:\n        loc = ord(c)-ord('a')\n        if node.children[loc] is  None: # char does not exist, new one\n            node.children[loc] = self.TrieNode()\n        # move to the next node\n        node = node.children[loc]\n    # set the flag to true\n    node.is_word = True \n\\end{lstlisting}\n\n\\paragraph{SEARCH} For SEARCH, like INSERT, we traverse the trie using the letters as pointers to the next branch. There are three cases: 1) for word P, if it doesnt exist, but its prefix does exist, then we return False. 2) If we found a matching for all the letters of P, at the last node, we need to check if it is a leaf node where is\\_word is True.  STARTWITH is just slightly different from SEARCH, it does not need to check that and return True after all letters matched. \n\\begin{lstlisting}[language=Python]\ndef search(self, word):\n    node = self.root\n    for c in word:\n        loc = ord(c)-ord('a')\n        # case 1: not all letters matched \n        if node.children[loc] is None: \n            return False          \n        node = node.children[loc]\n    # case 2\n    return True if node.is_word else False\n\\end{lstlisting}\n\\begin{lstlisting}[language=Python]\ndef startWith(self, word):\n    node = self.root\n    for c in word:\n        loc = ord(c)-ord('a')\n        # case 1: not all letters matched \n        if node.children[loc] is None: \n            return False          \n        node = node.children[loc]\n    # case 2\n    return True\n\\end{lstlisting}\nNow complete the given Trie class with TrieNode and \\_\\_init\\_\\_ function.\n\\begin{lstlisting}[language=Python]\nclass Trie:\n    class TrieNode:\n        def __init__(self):\n            self.is_word = False\n            self.children = [None] * 26 #the order of the node represents a char\n\n    def __init__(self):\n        \"\"\"\n        Initialize your data structure here.\n        \"\"\"\n        self.root = self.TrieNode() # root has value None       \n\\end{lstlisting}\n\\end{examples}\n\n\\begin{examples}\n\\item \\textbf{336. Palindrome Pairs (hard).} Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.\n\\begin{lstlisting}\nExample 1:\n\nInput: [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]\nOutput: [[0,1],[1,0],[3,2],[2,4]] \nExplanation: The palindromes are [\"dcbaabcd\",\"abcddcba\",\"slls\",\"llssssll\"]\n\nExample 2:\n\nInput: [\"bat\",\"tab\",\"cat\"]\nOutput: [[0,1],[1,0]] \nExplanation: The palindromes are [\"battab\",\"tabbat\"]\n\\end{lstlisting}\n\\textbf{Solution: One Forward Trie and Another Backward Trie.}  We start from the naive solution, which means for each element, we check if it is palindrome with all the other strings. And from the example 1, [3,3] can be a pair, but it is not one of the outputs, which means this is a combination problem, the time complexity is ${C_n}{C_{n-1}}$, and multiply it with the average length of all the strings, we make it $m$, which makes the complexity to be $O(mn^2)$. However, we can use Trie Structure, \n\\begin{lstlisting}[language = Python]\nfrom collections import defaultdict\n\n\nclass Trie:\n    def __init__(self):\n        self.links = defaultdict(self.__class__)\n        self.index = None\n        # holds indices which contain this prefix and whose remainder is a palindrome\n        self.pali_indices = set()\n\n    def insert(self, word, i):\n        trie = self\n        for j, ch in enumerate(word):\n            trie = trie.links[ch]\n            if word[j+1:] and is_palindrome(word[j+1:]):\n                trie.pali_indices.add(i)\n        trie.index = i\n\n\ndef is_palindrome(word):\n    i, j = 0, len(word) - 1\n    while i <= j:\n        if word[i] != word[j]:\n            return False\n        i += 1\n        j -= 1\n    return True\n\n\nclass Solution:\n    def palindromePairs(self, words):\n        '''Find pairs of palindromes in O(n*k^2) time and O(n*k) space.'''\n        root = Trie()\n        res = []\n        for i, word in enumerate(words):\n            if not word:\n                continue\n            root.insert(word[::-1], i)\n        for i, word in enumerate(words):\n            if not word:\n                continue\n            trie = root\n            for j, ch in enumerate(word):\n                if ch not in trie.links:\n                    break\n                trie = trie.links[ch]\n                if is_palindrome(word[j+1:]) and trie.index is not None and trie.index != i:\n                    # if this word completes to a palindrome and the prefix is a word, complete it\n                    res.append([i, trie.index])\n            else:\n                # this word is a reverse suffix of other words, combine with those that complete to a palindrome\n                for pali_index in trie.pali_indices:\n                    if i != pali_index:\n                        res.append([i, pali_index])\n        if '' in words:\n            j = words.index('')\n            for i, word in enumerate(words):\n                if i != j and is_palindrome(word):\n                    res.append([i, j])\n                    res.append([j, i])\n        return res\n\\end{lstlisting}\n\\textbf{Solution2: .}Moreover, there are always more clever ways to solve these problems. Let us look at a clever way:\n abcd, the prefix is ''. 'a', 'ab', 'abc', 'abcd', if the prefix is a palindrome, so the reverse[abcd], reverse[dc], to find them in the words, the words stored in the words with index is fastest to find. $O(n)$. Note that when considering suffixes, we explicitly leave out the empty string to avoid counting duplicates. That is, if a palindrome can be created by appending an entire other word to the current word, then we will already consider such a palindrome when considering the empty string as prefix for the other word.\n \\begin{lstlisting}[language = Python]\n class Solution(object):\n    def palindromePairs(self, words):\n        # 0 means the word is not reversed, 1 means the word is reversed\n        words, length, result = sorted([(w, 0, i, len(w)) for i, w in enumerate(words)] +\n                                   [(w[::-1], 1, i, len(w)) for i, w in enumerate(words)]), len(words) * 2, []\n\n        #after the sorting,the same string were nearby, one is 0 and one is 1\n        for i, (word1, rev1, ind1, len1) in enumerate(words):\n            for j in xrange(i + 1, length):\n                word2, rev2, ind2, _ = words[j]\n                #print word1, word2\n                if word2.startswith(word1): # word2 might be longer \n                    if ind1 != ind2 and rev1 ^ rev2: # one is reversed one is not\n                        rest = word2[len1:]\n                        if rest == rest[::-1]: result += ([ind1, ind2],) if rev2 else ([ind2, ind1],) # if rev2 is reversed, the from ind1 to ind2\n                else:\n                    break # from the point of view, break is powerful, this way, we only deal with possible reversed, \n        return result\n \\end{lstlisting}\n \\end{examples}\n \n %https://fizzbuzzed.com/top-interview-questions-5/\n% \\paragraph{Searching}\n% \\paragraph{Insertion}\n% \\paragraph{Deletion}\n\n% Let us see the complete code of a Trie Class:\n% \\begin{lstlisting}[language = Python]\n \n% class Trie:\n     \n%     # Trie data structure class\n%     def __init__(self):\n%         self.root = self.getNode()\n \n%     def getNode(self):\n     \n%         # Returns new trie node (initialized to NULLs)\n%         return TrieNode()\n \n%     def _charToIndex(self,ch):\n         \n%         # private helper function\n%         # Converts key current character into index\n%         # use only 'a' through 'z' and lower case\n         \n%         return ord(ch)-ord('a')\n \n \n%     def insert(self,key):\n         \n%         # If not present, inserts key into trie\n%         # If the key is prefix of trie node, \n%         # just marks leaf node\n%         pCrawl = self.root\n%         length = len(key)\n%         for level in range(length):\n%             index = self._charToIndex(key[level])\n \n%             # if current character is not present\n%             if not pCrawl.children[index]:\n%                 pCrawl.children[index] = self.getNode()\n%             pCrawl = pCrawl.children[index]\n \n%         # mark last node as leaf\n%         pCrawl.isEndOfWord = True\n \n%     def search(self, key):\n         \n%         # Search key in the trie\n%         # Returns true if key presents \n%         # in trie, else false\n%         pCrawl = self.root\n%         length = len(key)\n%         for level in range(length):\n%             index = self._charToIndex(key[level])\n%             if not pCrawl.children[index]:\n%                 return False\n%             pCrawl = pCrawl.children[index]\n \n%         return pCrawl != None and pCrawl.isEndOfWord\n \n% # driver function\n% def main():\n \n%     # Input keys (use only 'a' through 'z' and lower case)\n%     keys = [\"the\",\"a\",\"there\",\"anaswe\",\"any\",\n%             \"by\",\"their\"]\n%     output = [\"Not present in trie\",\n%               \"Present in tire\"]\n \n%     # Trie object\n%     t = Trie()\n \n%     # Construct trie\n%     for key in keys:\n%         t.insert(key)\n \n%     # Search for different keys\n%     print(\"{} ---- {}\".format(\"the\",output[t.search(\"the\")]))\n%     print(\"{} ---- {}\".format(\"these\",output[t.search(\"these\")]))\n%     print(\"{} ---- {}\".format(\"their\",output[t.search(\"their\")]))\n%     print(\"{} ---- {}\".format(\"thaw\",output[t.search(\"thaw\")]))\n \n% if __name__ == '__main__':\n%     main()\n% \\end{lstlisting}\nThere are several other data structures, like balanced trees and hash tables, which give us the possibility to search for a word in a dataset of strings. Then why do we need trie? Although hash table has $O(1)$ time complexity for looking for a key, it is not efficient in the following operations :\n\\begin{itemize}\n    \\item Finding all keys with a common prefix.\n    \\item Enumerating a dataset of strings in lexicographical order.\n\\end{itemize}\n\n\\paragraph{Sorting}\nLexicographic sorting of a set of keys can be accomplished by building a trie from them, and traversing it in pre-order, printing only the leaves' values. This algorithm is a form of radix sort. This is why it is also called radix tree. \n\\end{document}", "meta": {"hexsha": "9ca6c10a815e0c01b2bb284448e9c65609b4c91d", "size": 55146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/question_2_string_matching.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/question_2_string_matching.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/question_2_string_matching.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": 53.4360465116, "max_line_length": 886, "alphanum_fraction": 0.6665215972, "num_tokens": 15268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042765, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.6941177784123277}}
{"text": "\\subsubsection{Beats ($\\omega \\neq \\gamma$)}\r\n\\noindent\r\nIf $\\omega \\neq \\gamma$, then we can guess that $y_p$ has the form\r\n\\begin{equation*}\r\n\ty_p = A\\cos{(\\gamma t)} + B\\sin{(\\gamma t)}\r\n\\end{equation*}\r\nSince we don't have a term involving the 1st derivative, we can be sure that $B = 0$, since an odd number of derivatives is the only way to turn a $\\sin$ term into a $\\cos$ term. So,\r\n\\begin{equation*}\r\n\ty_p = A\\cos{(\\gamma t)}\r\n\\end{equation*}\r\nSolving for $A$,\r\n\\begin{equation*}\r\n\tm\\left(A\\cos{(\\gamma t)}\\right)'' + k\\left(A\\cos{(\\gamma t)}\\right) = F_0\\cos{(\\gamma t)}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t-mA\\gamma^2\\cos{(\\gamma t)} + kA\\cos{(\\gamma t)} = F_0\\cos{(\\gamma t)}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tA\\left(k - m\\gamma^2\\right) = F_0\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tA = \\frac{F_0}{k - m\\gamma^2} = \\frac{F_0}{m(\\omega^2 - \\gamma^2)}\r\n\\end{equation*}\r\nSo, our solution is\r\n\\begin{equation*}\r\n\ty = \\frac{F_0}{m(\\omega^2 - \\gamma^2)}\\cos{(\\gamma t)} + C_1\\cos{(\\omega t)} + C_2\\sin{(\\omega t)}\r\n\\end{equation*}\\\\\r\n\r\n\\noindent\r\nLet's look specifically at the IVP where $y(0) = 0$ and $y'(0) = 0$.\r\n\\begin{equation*}\r\n\tC_1 = \\frac{-F_0}{m(\\omega^2 - \\gamma^2)} \\text{ and } C_2 = 0\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\ty = \\frac{F_0}{m(\\omega^2 - \\gamma^2)}\\cos{(\\gamma t)} - \\frac{F_0}{m(\\omega^2 - \\gamma^2)}\\cos{(\\omega t)}\r\n\\end{equation*}\r\nUsing the fact that $\\cos{\\alpha}-\\cos{\\beta} = 2\\sin{\\left(\\frac{\\alpha - \\beta}{2}\\right)}\\sin{\\left(\\frac{\\alpha + \\beta}{2}\\right)}$,\r\n\\begin{equation*}\r\n\ty = \\frac{2F_0}{m(\\omega^2 - \\gamma^2)}\\sin{\\left(\\frac{\\gamma - \\omega}{2}t\\right)}\\sin{\\left(\\frac{\\gamma + \\omega}{2}t\\right)}\r\n\\end{equation*}\\\\\r\n\r\n\\noindent\r\nWhen $\\gamma \\approx \\omega$, the $\\gamma + \\omega$, with a small period, dominates the motion, and the amplitude is slowly guided by the $\\gamma - \\omega$ term which has a large period. This creates intervals guided by the $\\gamma - \\omega$ term of higher and lower amplitudes. These are beats.\r\n\r\n\\begin{center}\r\n\t\\includegraphics[width=0.75\\textwidth]{./higherOrder/forcedVibrs/beats.png}\r\n\\end{center}", "meta": {"hexsha": "c0279c8c3d9c538c14c017063c74ab0fa299c832", "size": 2107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/forcedVibrs/beats.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/beats.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/beats.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8958333333, "max_line_length": 296, "alphanum_fraction": 0.634551495, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8723473846343394, "lm_q1q2_score": 0.69409026265322}}
{"text": "%!TEX program = xelatex\n\n\\documentclass[12pt,a4paper]{article}\n\\usepackage{xeCJK}\n\\usepackage{amsmath}\n\\setmainfont{Times New Roman}\n\\usepackage{setspace}\n\\usepackage{caption}\n\\usepackage{graphicx, subfig}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage{booktabs}\n\\usepackage{setspace}%使用间距宏包\n\\usepackage{mathtools}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n    \\newcommand{\\dd}{\\mathrm{d}}\n\\usepackage{tcolorbox}\n    \\tcbuselibrary{xparse}\n        \\DeclareTotalTCBox{\\verbbox}{ O{green} v !O{} }\n            {fontupper=\\ttfamily,nobeforeafter,tcbox raise base,\n             arc=0pt,outer arc=0pt,top=0pt,bottom=0pt,left=0mm,\n             right=0mm,leftrule=0pt,rightrule=0pt,toprule=0.3mm,\n             bottomrule=0.3mm,boxsep=0.5mm,bottomrule=0.3mm,boxsep=0.5mm,\n             colback=#1!10!white,colframe=#1!50!black,#3}{#2}\n\\usepackage{color}\n\\usepackage{textcomp}\n\\definecolor{listinggray}{gray}{0.9}\n\\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}\n\\lstset{\n\tbackgroundcolor=\\color{lbcolor},\n\ttabsize=4,\n\trulecolor=,\n\tlanguage=matlab,\n        basicstyle=\\scriptsize,\n        upquote=true,\n        aboveskip={1.5\\baselineskip},\n        columns=fixed,\n        showstringspaces=false,\n        extendedchars=true,\n        breaklines=true,\n        prebreak = \\raisebox{0ex}[0ex][0ex]{\\ensuremath{\\hookleftarrow}},\n        frame=single,\n        showtabs=false,\n        showspaces=false,\n        showstringspaces=false,\n        identifierstyle=\\ttfamily,\n        keywordstyle=\\color[rgb]{0,0,1},\n        commentstyle=\\color[rgb]{0.133,0.545,0.133},\n        stringstyle=\\color[rgb]{0.627,0.126,0.941},\n}\n\\begin{document} \n\\title{homework11}\n\t\\author{11611118 郭思源}  \n\\begin{spacing}{1.5}%%行间距变为double-space\n\n\\section{Question 1}\n\nSolve the ODE system as follows\n\\[\n    \\frac{\\dd x}{\\dd t} = - x + y, \\quad\n    \\frac{\\dd y}{\\dd t} = - x - y\n\\]\n\n\n\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\tx &=  -\\frac{\\dd y}{\\dd t}-y \\\\\n\t\t\\frac{\\dd x}{\\dd t} &= -\\frac{\\dd y}{\\dd^2 t} -\\frac{\\dd y}{\\dd t} = \\frac{\\dd y}{\\dd t}+2y \\\\\\\\\n\t\t\\frac{\\dd y}{\\dd^2 t} &+ 2\\frac{\\dd y}{\\dd t} + 2y = 0 \\\\\n\t\tr^2 &+ 2r + 2 = 0 \\\\\n\t\tr_1 &= - 1 +  i, \\quad r_2 = - 1 -  i \\\\\n\t\t\\alpha &= -1, \\quad \\beta = 1 \\\\\n\t\ty &= e^{\\alpha t}(C_1\\cos(\\beta t)+C_2\\sin(\\beta t)) \\\\\n\t\ty &= e^{-t}(C_1\\cos(t)+C_2\\sin(t)) \\\\\\\\\n\t\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\t\\frac{\\dd y}{\\dd t} &= e^{-t}(C_1(-\\sin(t)-\\cos(t))+C_2(\\cos(t)-\\sin(t)))\\\\\n\t\tx &=  -\\frac{\\dd y}{\\dd t}-y =  e^{-t}(C_1\\sin(t)-C_2\\cos(t)) \\\\\n\t\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\tC_1 &= 1 \\\\\n\t\tC_2 &= 0 \\\\\n\t\tx(t) &= e^{-t}\\sin(t) \\\\\n\t\ty(t) &= e^{-t}\\cos(t) \\\\\n\t\\end{aligned}\n\\end{equation*}\n\n\n\\section{Question 2}\n\nTry the \\verbbox{MATLAB} ODE solver by implementing the three numerical examples in the lecture note.\n\n\\subsection{Example model 1}\n\\[\n    \\frac{\\dd x}{\\dd t} = - x + y, \\quad\n    \\frac{\\dd y}{\\dd t} = - x - y\n\\]\nLet $x_0=0, y_0=1, t_0=0, t_e=1000$ :\n\\begin{lstlisting}[language=matlab]\nfunction dydt = m1func(t,Y)\n    x = Y(1);y = Y(2);\n    dydt = [- x + y;\n            - x - y];\n\n[t xy]=ode45(@m1func,[0:0.01:1000],[0,1]);\nx=xy(:,1);y=xy(:,2);\nfigure(1); plot(x,y);xlabel(\"x\");ylabel(\"y\");\n\\end{lstlisting}\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[scale=0.25]{m1.png}\t\n\\end{figure}\n\n\\subsection{Example model 2}\n\\[\n    \\frac{\\dd x}{\\dd t} = ax - bxy, \\quad\n    \\frac{\\dd y}{\\dd t} = my - nxy\n\\]\nLet $a=1,b=100,m=1,n=100,\\\\ x_0=1, y_0=1, t_0=0, t_e=10000$ :\n\n\\begin{lstlisting}[language=matlab]\nfunction dydt = m2func(t,Y)\n    a = 1;b = 100;m = 1;n = 100;\n    x = Y(1);y = Y(2);\n    dydt = [a * x - b * x * y;\n            m * y - n * x * y];\n\n[t xy]=ode45(@m2func,[0:10000],[1,1]);\n\nx=xy(:,1);y=xy(:,2);\nfigure(1); plot(x,y);xlabel(\"x\");ylabel(\"y\");\n\\end{lstlisting}\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[scale=0.3]{m2.png}\t\n\\end{figure}\n\n\\subsection{Example model 3}\n\\[\n    \\frac{\\dd x}{\\dd t} = - ax + by + c, \\quad\n    \\frac{\\dd y}{\\dd t} = mx - ny + p\n\\]\nLet $a=1,b=1,c=1,m=1,n=1,p=1 \\\\ x_0=1, y_0=1, t_0=0, t_e=10000$ :\n\n\\begin{lstlisting}[language=matlab]\nfunction dydt = m3func(t,Y)\n    a = 1;b = 1;c = 1;m = 1;n = 1;p = 1;\n    x = Y(1);y = Y(2);\n    dydt = [- a * x + b * y + c;\n            m * x - n * y + p];\n\n[t xy]=ode45(@m3func,[0:10000],[1,1]);\n\nx=xy(:,1);y=xy(:,2);\nfigure(1); plot(x,y);xlabel(\"x\");ylabel(\"y\");\n\\end{lstlisting}\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[scale=0.3]{m3.png}\t\n\\end{figure}\n\n\n\\end{spacing}\n\n\\end{document}", "meta": {"hexsha": "306e89e8ac9e71cbe4c3c90121b0f20e61da8d85", "size": 4468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW11/HW11.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": "Homework/HW11/HW11.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": "Homework/HW11/HW11.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": 25.6781609195, "max_line_length": 101, "alphanum_fraction": 0.581915846, "num_tokens": 1829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6940902515638846}}
{"text": "% !TEX TS-program = pdflatexmk\n\\documentclass{article}\n\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage[a4paper, total={6in, 8in}]{geometry}\n\\usepackage{amsthm}\n\\usepackage{natbib}\n\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\title{Sparse Graph Prior for Knowledge Graph}\n\\date{\\today}\n\\author{Dongwoo Kim\\\\ANU}\n\n\\begin{document}\n\n\\maketitle\n\\section{Completely Random Measure}\nA completely random measure (CRM) $\\mu$ on $\\mathbb{R}_+$ is a random measure such that for any countable number of disjoint measurable sets $A_1, A_2, ...$ of $\\mathbb{R}_+$, the random variable $\\mu(A_1), \\mu(A_2), ...$ are independent and $\\mu(\\cup_i A_i) = \\sum_i \\mu(A_i)$. If one assumes that the distribution of $\\mu([t,s])$ only depends on the difference $t-s$ then the CRM takes the form of $\\mu = \\sum_{i=1}^{\\infty}w_i\\delta_{\\theta_i}$ where $(w_i, \\theta_i)$ are the points of a Poisson point process on $\\mathbb{R}_+^2$ with L\\'{e}vy intensity measure $\\nu(dw, d\\theta) = \\rho(dw)\\lambda(d\\theta)$\\footnote{Subordinator.}. The Laplace transform of $\\mu(A)$ on any measurable set $A$ has a following representation: $\\mathbb{E}[e^{-t\\mu(A)}] = \\exp(-\\int_{\\mathbb{R}_+ \\times A}(1-e^{-tw})\\rho(dw)\\lambda(d\\theta))$ for any $t>0$ and $\\rho$ such that $\\int_{\\mathbb{R}_+}(1-e^{-w})\\rho(dw) < \\infty$. Laplace exponent is $\\psi(t) = \\int_{\\mathbb{R}} (1 - e^{-t w}) \\rho(dw)$.\n\n\\section{Caron and Fox Model}\n\n\\cite{Caron2015} propose a simple point process on $\\mathbb{R}^2$ as a product measure of a complete random measure. They propose a hierarchical model for undirected graphs\n\\begin{align}\n\\mu &= \\sum_{i=1}^{\\infty} w_i \\delta_{\\theta_i} & &\\mu \\sim \\text{CRM}(\\rho, \\lambda)\\\\\nD &= \\sum_{i,j} n_{ij} \\delta_{(\\theta_i, \\theta_j)} & &D|\\mu \\sim \\text{PP}(\\mu \\times \\mu)\\\\\nZ &=\\sum_{i,j} \\min(n_{ij} + n_{ji}, 1)\\delta_{(\\theta_i, \\theta_j)}, \\label{eqn:cnf}&&\n\\end{align}\nwith intensity measure $\\nu$ factorising as $\\nu(dw, d\\theta) = \\rho(dw) \\lambda(d\\theta)$ for a jump part of the measure $\\rho$ and Lebesgue measure $\\lambda$. $D$ is simply generated from a Poisson process with a product measure as an intensity and can be interpreted as a directed multi-graph.\nGiven $\\mu$, we can directly specify the undirected graph $Z$ as\n\\[ Pr(z_{ij}=1|w) =\n  \\begin{cases}\n    1 - \\exp(-2w_iw_j)       & \\quad i \\neq j\\\\\n    1 - \\exp(-w_i^2) & \\quad i = j.\\\\\n  \\end{cases}\n\\]\n\nThey show that the resulting graph is sparse, i.e. \\# of edges = $o$(\\# of nodes$^2$)\\footnote{only counts the nodes which has at least one edge}, if the intensity measure\\footnote{This is the L\\'{e}vy intensity of the generalised gamma process} is\n\\begin{align}\n\\rho(dw) = \\frac{1}{\\Gamma(1-\\sigma)}w^{-1-\\sigma}e^{-\\tau w}dw,\n\\end{align}\nwhere the two parameters range\n\\begin{align}\n(\\sigma, \\tau) \\in (0,1) \\times [0, +\\infty)\n\\end{align}\nand dense if the intensity measure is finite activity, i.e. $\\int_{0}^{\\infty} \\rho(w)dw < \\infty$.\n\nThe general construction of the sparse graph in Equation \\ref{eqn:cnf} results an infinite number of edges due to $\\mu(\\mathbb{R}_+) = \\infty$. A restriction of Lebesgue measure $\\lambda$ on $[0, \\alpha]$ is used to obtain a finite graph ($\\lambda_\\alpha = \\lambda\\delta_{[0, \\alpha]}$). Therefore, restricted graph $Z_\\alpha$ is defined on the box $[0,\\alpha]^2$. We also denote the total mass on $[0, \\alpha]^2$ by $Z_\\alpha^* = Z_\\alpha([0, \\alpha]^2)$, and similarly for $D_\\alpha^*$ and $\\mu_\\alpha^*$.\n\n\\section{Sparse Prior for Knowledge Graph}\nA knowledge base consists of a set of triples (entity, entity, relation) such as (BarackObama, bornIn, Hawaii). The set of triples can be represented as a binary-valued three-way tensor where three dimensions represent entity, entity, and relation, respectively. Here, we directly extend the Caron and Fox's model for the three-way tensor based on two independent completely random measures.\n\\begin{align}\n\\mu &= \\sum_{i=1}^{\\infty} w_i \\delta_{\\theta_i} & &\\mu \\sim \\text{CRM}(\\rho, \\lambda)\\\\\n\\mu' &= \\sum_{k=1}^{\\infty} w_k \\delta_{\\theta_k'} & &\\mu' \\sim \\text{CRM}(\\rho', \\lambda)\\\\\nD &= \\sum_{i,j,k} n_{ijk} \\delta_{(\\theta_i, \\theta_j, \\theta_k')}& &D \\sim \\text{PP}(\\mu \\times \\mu \\times \\mu') && \\\\\nZ &=\\sum_{i,j,k} \\min(n_{ijk}, 1)\\delta_{(\\theta_i, \\theta_j, \\theta_k')}, &&\n\\end{align}\nwhere $Z$ is asymmetric in $i$ and $j$ since the knowledge graph is a directed multi-graph. As done in the original model, we can also specify $Z$ as\n\\[ Pr(z_{ijk}=1|w, w') =\n  \\begin{cases}\n    1 - \\exp(-w_iw_jw_k')       & \\quad i \\neq j\\\\\n    1 - \\exp(-w_i^2w_k') & \\quad i = j.\\\\\n  \\end{cases}\n\\]\nIf we consider $\\theta_i$, $\\theta_j$, and $\\theta_k'$ as nodes in the graph, the above construction will generate a hypergraph where each edge connects three nodes. In the notion of knowledge graphs, it is more intuitive to consider a relation as a type of edge between two entities. In this case, we define two random measures on $\\mathbb{R}_+^2$:\n\\begin{align}\n\\bar{D} &= \\sum_{i,j}\\sum_{k}z_{ijk}\\delta_{\\theta_i,\\theta_j}\\\\\n\\bar{Z} &= \\sum_{i,j}\\min(\\bar{D}(\\{\\theta_i, \\theta_j\\}), 1) \\delta_{(\\theta_i,\\theta_j)},\n\\end{align}\nwhere $\\bar{D}$ is a multigraph, and $\\bar{Z}$ is a binary graph of a knowledge base.\n\\[ Pr(\\bar{z}_{ij}=1|w, w') =\n  \\begin{cases}\n    1 - \\exp(-w_iw_j\\sum_{k}w_k')       & \\quad i \\neq j\\\\\n    1 - \\exp(-w_i^2\\sum_{k}w_k') & \\quad i = j.\\\\\n  \\end{cases}\n\\]\nTo obtain a finite hypergraph (the number of edges is finite), we consider restrictions ${D}_{\\alpha\\beta}$ and ${Z}_{\\alpha\\beta}$ to the box $[0,\\alpha]^2\\times[0,\\beta]$. We denote by $Z_{\\alpha\\beta}^* = Z_{\\alpha\\beta}([0,\\alpha]^2\\times[0,\\beta])$ the total mass on the restricted area, and similar for $D_{\\alpha\\beta}^*$ and $\\mu_{\\alpha}^*$.\n\n\\subsection{Generative Process through Urn approach}\nGiven restriction $\\alpha$ and $\\beta$, the generative process of $D_{\\alpha\\beta}$ can be specified as follows:\n\\begin{enumerate}\n\\item $\\mu_\\alpha \\sim \\text{CRM}(\\rho, \\lambda_\\alpha)$\n\\item $\\mu_\\beta' \\sim \\text{CRM}(\\rho', \\lambda_\\beta)$\n\\item $D_{\\alpha\\beta}^* | \\mu_\\alpha, \\mu_\\beta' \\sim \\text{Poisson}(\\mu_\\alpha^{*2}{\\mu'}_\\beta^{*})$\n\\item For $d=1,...,D_{\\alpha\\beta}^*$:\n\\begin{enumerate}\n\\item $\\theta_{di} \\sim \\frac{\\mu_\\alpha}{\\mu_\\alpha^*}$\n\\item $\\theta_{dj} \\sim \\frac{\\mu_\\alpha}{\\mu_\\alpha^*}$\n\\item $\\theta_{dk}' \\sim \\frac{\\mu_\\beta}{{\\mu'}_\\beta^{*}}$\n\\end{enumerate}\n\\item $D_{\\alpha\\beta} = \\sum_{d=1}^{D_{\\alpha\\beta}^*} \\delta_{(\\theta_{di}, \\theta_{dj}, \\theta_{dk})}$,\n\\end{enumerate}\nwhere we have used that the total mass of $D_{\\alpha\\beta}^*$ follows the Poisson distribution. Each node $\\theta_i$ is drawn from the normalised CRM (NRM), $\\frac{\\mu_\\alpha}{\\mu_\\alpha^*}$, which is discrete with probability 1. However, it is not possible to sample $\\mu_\\alpha$ and $\\mu'_\\beta$ since these measures have infinite number of atoms. Instead we can simulate finite-dimensional generative process through the urn formulation. Let $\\theta_1, ..., \\theta_n$ drawn from the normalised CRM $\\frac{\\mu_\\alpha}{\\mu_\\alpha^*}$. Since NRM is discrete, variables $\\theta_1, ..., \\theta_n$ takes $l \\leq n$ distinct values $\\phi_l$, and $m_l$ is the number of variables corresponding to $\\phi_l$.\nGiven total mass $\\mu_\\alpha^*$ and $\\theta_1, ..., \\theta_n$, the conditional distribution of $\\theta_{n+1}$ can be modelled in terms of exchangeable partition probability function (EPPF):\n\\begin{align}\n\\label{eqn:eppf}\n\\theta_{n+1} | \\mu_\\alpha^*, \\theta_1,...,\\theta_n \\sim \\frac{\\Pi_{n+1}^{l+1}(m_1, ..., m_l, 1 | \\mu_\\alpha^*)}{\\Pi_{n}^{l}(m_1, ..., m_l | \\mu_\\alpha^*)} \\frac{1}{\\alpha} \\lambda_\\alpha\n+ \\sum_{i=1}^{l}\\frac{\\Pi_{n+1}^{l}(m_1, ..., m_{i}+1, ..., m_l | \\mu_\\alpha^*)}{\\Pi_{n}^{l}(m_1, ..., m_l| \\mu_\\alpha^*)} \\delta_{\\phi_l}\n\\end{align}\nwhere\n\\begin{align}\n\\Pi_{n}^l(m_1, ..., m_l|\\mu_\\alpha^*) = \\frac{\\sigma^l \\mu_\\alpha^{*-n}}{\\Gamma(n-l\\sigma)g_{\\sigma}(\\mu_\\alpha^*)} \\int_{0}^{\\mu_\\alpha^*}s^{n-l\\sigma-1}g_{\\sigma}(\\mu_\\alpha^*-s)ds \\bigg(\\prod_{i=1}^{l} \\frac{\\Gamma(m_i-\\sigma)}{\\Gamma(1-\\sigma)} \\bigg),\n\\end{align}\nand $g_\\sigma$ is the pdf of the positive stable distribution.\nFinally, the total mass of $\\mu_\\alpha^*$ and ${\\mu'}_\\beta^{*}$ follows an exponentially tilted stable distribution where the exact sampler exists \\citep{devroye2009random,hofert2011sampling}.\n\nUsing this urn representation, we can rewrite the generative process as\n\\begin{enumerate}\n\\item $\\mu_\\alpha^* \\sim P_{\\mu_\\alpha^*}$\n\\item ${\\mu'}_\\beta^{*} \\sim P_{{\\mu'}_\\beta^{*}}$\n\\item $D_{\\alpha\\beta}^* | \\mu_\\alpha, \\mu_\\beta' \\sim \\text{Poisson}(\\mu_\\alpha^{*2}{\\mu'}_\\beta^{*})$\n\\item For $d=1,...,D_{\\alpha\\beta}^*$:\n\\begin{enumerate}\n\\item Sample $\\theta_{di}$, $\\theta_{dj}$, and $\\theta_{dk}'$ with Urn process in Eqn \\ref{eqn:eppf}\n\\end{enumerate}\n\\item $D_{\\alpha\\beta} = \\sum_{d=1}^{D_{\\alpha\\beta}^*} \\delta_{(\\theta_{di}, \\theta_{dj}, \\theta_{dk})}$,\n\\end{enumerate}\n\n\\subsection{Characteristics of Random Graph in Gamma process case ($\\sigma=0$)}\nIn case $\\sigma=0$, $\\rho(dw)$ is an intensity of the Gamma process where the sum of the weights $\\mu_\\alpha^*$ follows Gamma distribution with shape parameter $\\alpha$ and scale parameter $\\tau$.\n\n\\subsubsection{Expected number of triples}\nFrom the generative process of the random graph, the number of total edge follows the poisson distribution with mean intensity $\\mu^{*2}_\\alpha \\mu^*_\\beta$.\n\\begin{align}\n\\mathbb{E}[D^*_{\\alpha\\beta}] & = \\mathbb{E}[\\mu^{*2}_\\alpha]\\mathbb{E}[\\mu^*_\\beta] \\\\\n&= (\\text{Var}(\\mu^*_\\alpha) + \\mathbb{E}[\\mu^{*}_\\alpha]^2)\\mathbb{E}[\\mu^*_\\beta]\\\\\n& = \\frac{\\alpha(\\alpha+1)}{\\tau} \\frac{\\beta}{\\tau}\n\\end{align}\n\n\\subsubsection{Expected number of entities and relations}\nFrom the generative process of the random graph, we can compute the expected number of entities $N_\\alpha$ as\n\\begin{align}\n\\mathbb{E}[N_\\alpha|D^*_{\\alpha\\beta}] = \\mathbb{E}\\bigg[\\sum_{i=1}^{2D^*_{\\alpha\\beta}} Y_i\\bigg],\n\\end{align}\nwhere\n\\begin{align}\nY_i \\sim \\text{Ber}\\bigg(\\frac{\\alpha}{\\alpha+i-1}\\bigg).\n\\end{align}\nSo, the expected number of entities for the large number of $2D^*_{\\alpha\\beta}$ can be approximated as\n\\begin{align}\n\\mathbb{E}[N_\\alpha|D^*_{\\alpha\\beta}] = \\sum_{i=1}^{2D^*_{\\alpha\\beta}}\\frac{\\alpha}{\\alpha+i-1} = \\alpha(\\Psi(\\alpha + 2D^*_{\\alpha\\beta}) - \\Psi(\\alpha)) \\approx \\alpha \\log (\\alpha + 2D^*_{\\alpha\\beta})\n\\end{align}\nwhere $\\Psi$ is a digamma function \\citep{arratia2003logarithmic}. By using Theorem 8 in \\citep{Caron2015}, we can further show $\\mathbb{E}[N_\\alpha] = \\Theta(\\alpha \\log\\alpha)$ as $\\alpha \\rightarrow \\infty$.\nThe expected number of relations can be computed in a similar way:\n\\begin{align}\n\\mathbb{E}[N_\\beta|D^*_{\\alpha\\beta}] = \\sum_{j=1}^{D^*_{\\alpha\\beta}}\\frac{\\beta}{\\beta+j-1} = \\beta(\\Psi(\\beta + D^*_{\\alpha\\beta}) - \\Psi(\\beta)) \\approx \\beta \\log (\\beta + D^*_{\\alpha\\beta})\n\\end{align}\nSince $N_\\alpha$ and $N_\\beta$ is independent,\n\\begin{align}\n\\mathbb{E}[N_\\alpha N_\\beta|D^*_{\\alpha\\beta}] \\approx \\alpha \\log (\\alpha + 2D^*_{\\alpha\\beta}) \\times \\beta \\log (\\beta + D^*_{\\alpha\\beta})\n\\end{align}\n\n%Unlike the two-dimensional space case, graph prior on three dimensional space may have various definition of the sparsity of the graph. Since our focus here is the growth rate of various statistics as the graph restriction $\\alpha$ and $\\beta$ increase. We list some statistics to characterise the random graph.\n%\n%To compute the (expected) growth rate of the number of triples with respect to the number of entities and relations, we first identify the growth rate of the number of triples, entities, and relations with respect to the varying graph restriction $\\alpha$ and $\\beta$. Let $N^{e}_{\\alpha\\beta}$ be the number of triples given $\\alpha$ and $\\beta$, $N_{\\alpha}$ be the number of entities given $\\alpha$, and $N_{\\beta}$ be the number of relations given $\\beta$. Here are some statistics that might help to shape these characteristics.\n%\n%\\begin{align}\n%\\frac{E[N^e_{\\alpha\\beta}]}{E[N_\\alpha N_\\beta]} &\\text{ as }\\alpha \\rightarrow \\infty, \\beta \\rightarrow \\infty \\\\\n%\\frac{E[N_\\alpha|\\beta]}{\\alpha} &\\text{ as } \\alpha \\rightarrow \\infty \\\\\n%\\frac{E[N_\\alpha]}{\\alpha} &\\text{ as } \\alpha \\rightarrow \\infty \\\\\n%\\frac{E[N_\\beta|\\alpha]}{\\beta} &\\text{ as } \\beta \\rightarrow \\infty \\\\\n%\\frac{E[N_\\beta]}{\\beta} &\\text{ as } \\beta \\rightarrow \\infty \\\\\n%\\frac{E[N^e_{\\alpha\\beta}]}{\\alpha\\beta} &\\text{ as }\\alpha \\rightarrow \\infty, \\beta \\rightarrow \\infty \\\\\n%\\frac{E[N^e_{\\alpha}|\\beta]}{\\alpha} &\\text{ as }\\alpha \\rightarrow \\infty\n%\\end{align}\n%\n%\n%\\begin{theorem} \\label{thm:edge} Consider the point process $\\bar{Z}$ with infinite-activity intensity measures $\\rho(dw)$ and $\\rho'(dw')$. Given $\\mu'$ from $\\rho'(dw')$, the number of edges in $\\bar{Z}_{\\alpha}$ grows quadratically as $\\alpha \\rightarrow \\infty$ almost surely.\n%\\end{theorem}\n%\\begin{proof}\n%$\\sum_{k=1}^{\\infty} w_k' < \\infty$ a.s. When $\\mu'$ is given and the sum of $w_k'$ is finite a.s., we can use the same proof technique used in \\cite{Caron2015}.\n%\\end{proof}\n%What if $\\mu'$ is not given? Let $(X_i)$ and $(Y_k)$ be i.i.d. real-valued random variable from $p$ and $q$, respectively, and let $h(x_1, x_2, y_1)$ be a measurable function symmetric in the first two arugments.\n%\\begin{align}\n%\\frac{2 \\sum_{i<j}\\sum_{k} h(X_i, X_j, Y_k)}{n_x(n_x -1) n_y} \\xrightarrow[]{?} \\mathbb{E}[h(X_i, X_j, Y_k)]\\quad a.s.\\quad as \\quad n\\rightarrow \\infty\n%\\end{align}\n%If this strong law of the large numbers for two samples is correct, we may proof Theorem 3.1 in more general case ($\\mu'$ is not given).\n%\n%\\begin{theorem} Consider the point process $\\bar{Z}$ with infinite-activity intensity measures $\\rho(dw)$ and $\\rho'(dw')$. Let $N_\\alpha$ be a number of nodes having at least one connection. Given $\\mu'$ from $\\rho'(dw')$, the number of nodes $N_\\alpha$ in $\\bar{Z}_{\\alpha}$ grows superlinearly as $\\alpha \\rightarrow \\infty$ almost surely.\n%\\end{theorem}\n%\\begin{proof}\n%As \\ref{thm:edge}.\n%\\end{proof}\n\n\\subsection{Posterior inference}\nWe first characterise the posterior of $\\mu_\\alpha$ given $\\mu'_\\beta$ and $D_{\\alpha\\beta}$. The conditional Laplace functional of $\\mu_\\alpha$ given $D_{\\alpha\\beta}$ is $\\mathbb{E}[e^{-\\mu_\\alpha(f)}|\\mu'_\\beta, D_{\\alpha\\beta}]$, for any non-negative measurable function $f$ such that $\\mu_\\alpha(f) = \\sum_{i=1}^{\\infty}w_i f(\\theta_i)$. We have $\\mu_\\alpha(f) = \\Pi(\\tilde{f})$ where $\\Pi = \\sum_{i=1}^{\\infty} \\delta_{w_i, \\theta_i}$ is a Poisson random measure on $\\mathcal{S} = (0, \\infty) \\times [0, \\alpha]$ with mean measure $\\rho \\times \\lambda$ and $\\tilde{f}(w, \\theta) = wf(\\theta)$. Let $n_{i**} = \\sum_{j=1}^{N_\\alpha}\\sum_{k=1}^{N_\\beta}n_{ijk}$, $m_i = \\sum_{j=1}^{N_\\alpha}\\sum_{k=1}^{N_\\beta} n_{ijk} + n_{jik}$, and $m'_k = \\sum_{i=1}^{N_\\alpha} \\sum_{j=1}^{N_\\alpha} n_{ijk}$.\n\n\\begin{align}\n\\label{eqn:lpl_d}\n\\mathbb{E}_{\\mu_\\alpha}[e^{-\\mu_\\alpha(f)}|D_{\\alpha\\beta}, \\mu'_\\beta]\n&= \\mathbb{E}_{\\Pi}[e^{-\\int \\tilde{f}(w, \\theta)\\Pi(dw, d\\theta)}|D_{\\alpha\\beta}, \\mu'_\\beta] \\\\\n&= \\frac{\\mathbb{E}_{\\Pi}[ e^{-\\Pi(\\tilde{f})} P(D_{\\alpha\\beta}|\\Pi, \\mu'_\\beta)]}{\\mathbb{E}_{\\Pi}[P(D_{\\alpha\\beta}|\\Pi, \\mu'_\\beta)]}\\\\\n%&= \\frac{\\mathbb{E}_{\\Pi}[e^{-\\Pi(\\tilde{f})} e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} \\prod_{i=1}^{N_\\alpha} w_i^{m_i} \\prod_{k=1}^{N_\\beta} {w'_k}^{m_k} ]}{\\mathbb{E}_{\\Pi}[e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} \\prod_{i=1}^{N_\\alpha} w_i^{m_i} \\prod_{k=1}^{N_\\beta} {w'_k}^{m_k} ]]}\n&= \\frac{\\mathbb{E}_{\\Pi}[e^{-\\Pi(\\tilde{f})} e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} \\prod_{i=1}^{N_\\alpha} w_i^{m_i}]}{\\mathbb{E}_{\\Pi}[e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} \\prod_{i=1}^{N_\\alpha} w_i^{m_i}]]}\n\\end{align}\nwhere $h(w, \\theta) = w$ and\n\\begin{align}\nP(D_{\\alpha\\beta}|\\Pi, \\mu'_\\beta) & = P(D_{\\alpha\\beta}|\\mu_\\alpha, \\mu'_\\beta)\\\\\n& = \\text{Poisson}(D^*_{\\alpha\\beta}|\\mu_\\alpha^{*2}{\\mu'}_\\beta^{*})\n\\prod_{i=1}^{N_\\alpha} P(n_{i**}|\\mu_\\alpha) \\prod_{j=1}^{N_\\alpha} P(n_{*j*}|\\mu_\\alpha)\n\\prod_{k=1}^{N_\\beta} P(n_{**k}|\\mu_\\beta) \\\\\n& = \\frac{ (\\mu_\\alpha^{*2}{\\mu'}_\\beta^{*})^{D^*_{\\alpha\\beta}} e^{-\\mu_\\alpha^{*2}{\\mu'}_\\beta^{*}} }{D^*_{\\alpha\\beta}!}\n\\prod_{i=1}^{N_\\alpha} \\Big( \\frac{w_i}{\\mu_\\alpha^*} \\Big)^{n_{i**}}\n\\prod_{j=1}^{N_\\alpha} \\Big( \\frac{w_j}{\\mu_\\alpha^*} \\Big)^{n_{*j*}}\n\\prod_{k=1}^{N_\\beta} \\Big( \\frac{w'_k}{{\\mu'}_\\beta^{*}} \\Big)^{n_{**k}}\\\\\n& =\\frac{e^{-\\mu_\\alpha^{*2}{\\mu'}_\\beta^{*}} }{D^*_{\\alpha\\beta}!}\n\\prod_{i=1}^{N_\\alpha} w_i^{m_i}\n\\prod_{k=1}^{N_\\beta} {w'_k}^{m_k}\n =\\frac{e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} }{D^*_{\\alpha\\beta}!}\n\\prod_{i=1}^{N_\\alpha} w_i^{m_i}\n\\prod_{k=1}^{N_\\beta} {w'_k}^{m_k}\\\\\n\\\\\n\\mu_\\alpha^* & = \\sum_{i=1}^{\\infty} w_i, \\qquad {\\mu'}_\\beta^{*} = \\sum_{k=1}^{\\infty} w'_k = \\sum_{k=1}^{N_\\beta} w'_k + {w'}^*\n\\end{align}\nApplying the generalised Palm formula to the numerator yields\n\\begin{align}\n&\\mathbb{E}_{\\Pi}\\Big[e^{-\\Pi(\\tilde{f})} e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} \\prod_{i=1}^{N_\\alpha} w_i^{m_i} \\Big] &\\\\\n&= \\mathbb{E}_{\\Pi}\\Big[e^{-\\Pi(\\tilde{f})} e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}} \\prod_{i=1}^{N_\\alpha} \\sum_{w_j, \\vartheta_j \\in \\Pi} w_j^{m_i} \\mathbf{1}_{\\theta_i}(\\vartheta_j)\\Big]& \\\\\n&= \\mathbb{E}_{\\Pi}\\Big[\\int_{\\mathcal{S}^{N_\\alpha}} e^{-\\Pi(\\tilde{f})} e^{-\\Pi(h)^2{\\mu'}_\\beta^{*}}  \\prod_{i=1}^{N_\\alpha} w_j^{m_i} \\mathbf{1}_{\\theta_i}(\\vartheta_j) \\Pi(dw_j, d\\vartheta_j)\\Big]& \\\\\n&=  \\int_{\\mathcal{S}^{N_\\alpha}} \\mathbb{E}_{\\Pi}\\Big[ e^{-(\\Pi+\\sum_i^{N_\\alpha}\\delta_{(w_i, \\theta_i)})(\\tilde{f})} e^{-(\\Pi+\\sum_i^{N_\\alpha}\\delta_{(w_i, \\theta_i)})(h)^2{\\mu'}_\\beta^{*}}\\Big] \\prod_{i=1}^{N_\\alpha} w_j^{m_i} \\mathbf{1}_{\\theta_i}(\\vartheta_j) \\rho(dw_j)\\lambda(d\\vartheta_j) & \\\\\n&=  \\int_{\\mathcal{S}^{N_\\alpha}} \\mathbb{E}_{\\mu_\\alpha}\\Big[ e^{-\\mu_\\alpha(f) - \\sum_{i=1}^{N_\\alpha}w_if(\\vartheta_j)} e^{-(\\mu_\\alpha(1) + \\sum_{i=1}^{N_\\alpha} w_i)^2{\\mu'}_\\beta^{*}}\\Big] \\prod_{i=1}^{N_\\alpha} w_j^{m_i} \\mathbf{1}_{\\theta_i}(\\vartheta_j) \\rho(dw_j)\\lambda(d\\vartheta_j) &\\\\\n&=  \\int_{\\mathcal{S}^{N_\\alpha}} \\mathbb{E}_{\\mu_\\alpha^*}\\bigg[ \\mathbb{E}_{\\mu_\\alpha} \\Big[e^{-\\mu_\\alpha(f)}|\\mu_\\alpha^* \\Big] e^{- \\sum_{i=1}^{N_\\alpha}w_if(\\vartheta_j)} e^{-(\\mu_\\alpha^* + \\sum_{i=1}^{N_\\alpha} w_i)^2{\\mu'}_\\beta^{*}}\\bigg] \\prod_{i=1}^{N_\\alpha} w_j^{m_i} \\mathbf{1}_{\\theta_i}(\\vartheta_j) \\rho(dw_j)\\lambda(d\\vartheta_j) &\n\\end{align}\nThe denominator is obtained by taking $f=0$.\n\\begin{align}\n\\mathbb{E}_{\\mu_\\alpha}[e^{-\\mu_\\alpha(f)}|D_{\\alpha\\beta}, \\mu'_\\beta] &= \\int_{\\mathbb{R}^{N_\\alpha + 1}} E_{\\mu_\\alpha}[e^{-\\mu_\\alpha(f)}|\\mu_\\alpha^* = w^*]\\\\\n&\\quad \\times e^{\\sum_{i=1}^{N_\\alpha}w_i f(\\theta_i)} p(w_1, ..., w_{N_\\alpha}, w^*|D_{\\alpha\\beta}, \\mu_\\beta) dw_{1:N_\\alpha}dw^*\n\\end{align}\nwhere\n\\begin{align}\np(w_1, ..., w_{N_\\alpha}, w^*|D_{\\alpha\\beta}, \\mu_\\beta)&\n= \\frac{\\prod_{i=1}^{N_\\alpha} w_j^{m_i} \\rho(w_i) e^{-(w^* + \\sum_{i=1}^{N_\\alpha} w_i)^2{\\mu'}_\\beta^{*}} g^*_\\alpha(w^*)}\n{\\int_{\\mathbb{R}^{N_\\alpha + 1}}\\prod_{i=1}^{N_\\alpha} \\tilde{w}_j^{m_i} \\rho(\\tilde{w}_i) e^{-(\\tilde{w}^* + \\sum_{i=1}^{N_\\alpha} \\tilde{w}_i)^2{\\mu'}_\\beta^{*}} g^*_\\alpha(\\tilde{w}^*) d\\tilde{w}_{1:N_\\alpha}d\\tilde{w}^*}\\\\\n\\end{align}\n$g^*_\\alpha(w^*)$ is a density function of random variable $w^*$ of which Laplace transform is $\\mathbb{E}[e^{tw^*}] = e^{\\alpha\\psi(t)}$. Therefore, the conditional of $\\mu_\\alpha$ given $D_{\\alpha\\beta}, \\mu'_\\beta$ is\n\\begin{align}\nw^* \\sum_{i=1}^{\\infty}\\tilde{P}_i\\delta_{\\tilde\\theta_i} + \\sum_{i=1}^{N_\\alpha} w_i \\delta_{\\theta_i}\n\\end{align}\nwhere $(\\tilde{P})$ are distributed from a Poisson-Kingman distribution conditional on $w^*$, and the weights $w_1, ..., w_{N_\\alpha}, w^*$ are jointly dependent conditional on $D_{\\alpha\\beta}$ and $\\mu'_\\beta$:\n\\begin{align}\np(w_1, ..., w_{N_\\alpha}, w^* | D_{\\alpha\\beta}, \\mu'_\\beta) \\propto \\prod_{i=1}^{N_\\alpha}{w_i}^{m_i} e^{(-w_* + \\sum_{i=1}^{N_\\alpha}w_i)^2 {\\mu'}_\\beta^*} \\prod_{i=1}^{N_\\alpha} \\rho(w_i) g^*_\\alpha(w^*)\n\\end{align}\n\nThe conditional Laplace functional of $\\mu'_\\beta$ given $\\mu_\\alpha$ and $D_{\\alpha\\beta}$ can be carried out in the same way as we've done in $\\mu_\\alpha$.\n\n\\bibliographystyle{apalike}\n\\bibliography{ref}\n\n\\end{document}\n", "meta": {"hexsha": "5bac8c5e9554acdbc510c38c5d192f54fbc60026", "size": 20169, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/sparse_tensor/sparse_tensor.tex", "max_stars_repo_name": "arongdari/sparse-graph-prior", "max_stars_repo_head_hexsha": "01bbe59d356b24e9967851d3ab5d7195c3bcd790", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-12-08T19:04:31.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-08T19:04:31.000Z", "max_issues_repo_path": "notes/sparse_tensor/sparse_tensor.tex", "max_issues_repo_name": "dongwookim-ml/sparse-graph-prior", "max_issues_repo_head_hexsha": "01bbe59d356b24e9967851d3ab5d7195c3bcd790", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-07-10T05:20:44.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-10T05:20:44.000Z", "max_forks_repo_path": "notes/sparse_tensor/sparse_tensor.tex", "max_forks_repo_name": "dongwookim-ml/sparse-graph-prior", "max_forks_repo_head_hexsha": "01bbe59d356b24e9967851d3ab5d7195c3bcd790", "max_forks_repo_licenses": ["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.0941176471, "max_line_length": 988, "alphanum_fraction": 0.6501561803, "num_tokens": 7607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.694090246277715}}
{"text": "\\subsection{Real numbers}\\label{subsec:real_numbers}\n\n\\begin{definition}\\label{def:set_of_rational_numbers}\n  The \\term{rational numbers} \\( \\BbbQ \\) are the field of \\hyperref[def:field_of_fractions]{fractions} of the \\hyperref[def:set_of_integers]{integers}. Both operations from \\( \\BbbZ \\) are inherited in \\( \\BbbQ \\) and all nonzero elements in \\( \\BbbQ \\) are now invertible, which makes \\( \\BbbQ \\) a field.\n\\end{definition}\n\n\\begin{definition}\\label{def:set_of_real_numbers}\n  The \\term{real numbers} \\( \\BbbR \\) are the metric space \\hyperref[def:complete_metric_space]{completion} of \\( \\BbbQ \\) with respect to the absolute value. Unfortunately, real numbers are used for defining metric spaces, so we cannot rely on the theory of metric spaces. This can be circumvented by\n  \\begin{enumerate}\n    \\item Regarding \\( \\BbbQ \\) as a \\hyperref[def:uniform_space]{uniform space}.\n    \\item Using uniform space \\hyperref[thm:uniform_space_completion]{completion} to obtain \\( \\BbbR \\).\n    \\item Defining metric spaces.\n    \\item Showing that \\( \\BbbR \\) is a metric space.\n    \\item Using \\fullref{def:complete_metric_space/uniform} to automatically verify that \\( \\BbbR \\) is complete as a metric space.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\\label{def:extended_real_numbers}\n  We are sometimes interested in \\term{extended real numbers}. These can be any of the three sets\n  \\begin{itemize}\n    \\item \\( \\BbbR \\cup \\{ +\\infty \\} \\),\n    \\item \\( \\BbbR \\cup \\{ -\\infty \\} \\),\n    \\item \\( \\BbbR \\cup \\{ -\\infty, +\\infty \\} \\),\n  \\end{itemize}\n  where \\( -\\infty \\) and \\( +\\infty \\) are both sentinel values that act as the \\hyperref[def:partially_ordered_set_extremal_points/maximum_and_minimum]{greatest} and/or least real number.\n\n  We generally avoid performing arithmetic operations on \\( \\pm \\infty \\), however it is sometimes convenient to define\n  \\begin{balign*}\n    x + (+\\infty)     & \\coloneqq +\\infty, x \\in \\BbbR\n                      &                              &\n    x \\cdot (+\\infty) & \\coloneqq +\\infty, x \\in \\BbbR\n  \\end{balign*}\n\n  We leave the operations\n  \\begin{balign*}\n     & (-\\infty) + (+\\infty)\n     & (-\\infty) \\cdot (+\\infty)\n  \\end{balign*}\n  undefined.\n\n  With these operations, the extended real numbers are no longer a \\hyperref[def:field]{field}.\n\\end{definition}\n\n\\begin{definition}\\label{def:floor_ceiling_functions}\n  Let \\( x \\in \\BbbR \\) be a real number. In analogy with \\fullref{def:commutative_ring_division}, we define its \\term{floor}\n  \\begin{equation*}\n    \\floor(x) \\coloneqq \\max \\{ n \\in \\BbbZ : n \\leq x \\},\n  \\end{equation*}\n  its \\term{ceiling}\n  \\begin{equation*}\n    \\ceil(x) \\coloneqq \\min \\{ n \\in \\BbbZ : n \\geq x \\}\n  \\end{equation*}\n  and its \\term{fractional part}\n  \\begin{equation*}\n    \\op{frac}(x) \\coloneqq x - \\floor(x).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:reals_not_algebraically_closed}\n  The field \\( \\BbbR \\) is not algebraically \\hyperref[def:algebraically_closed_field]{closed}.\n\n  In particular, the polynomial \\( x^2 + 1 \\) has no root.\n\\end{proposition}\n\\begin{proof}\n  Assume that \\( \\BbbR \\) is algebraically closed and that the polynomial \\( x^2 + 1 \\) has at least one root. Denote one of them by \\( u \\).\n\n  By the \\hyperref[def:binary_relation/trichotomic]{trichotomy} of the order \\( < \\) of \\( \\BbbR \\), we have either \\( u < 1 \\) or \\( u > 1 \\) since \\( u \\neq 1 \\).\n\n  If \\( u < 0 \\), then \\( u^2 = -1 < 0 \\), which is impossible because the image of \\( x \\mapsto x^2 \\) is the interval \\( [0, \\infty) \\).\n\n  If \\( u > 0 \\), then \\( u^2 = -1 < 0 = 0 \\), which is also impossible because \\( x \\mapsto x^2 \\) is monotone on \\( [0, \\infty) \\).\n\n  Thus, \\( u \\) is not a root of \\( x^2 + 1 \\) and \\( \\BbbR \\) is not algebraically closed.\n\\end{proof}\n\n\\begin{definition}\\label{def:signum}\n  We define the \\term{signum} function \\( \\sgn: \\BbbR \\to \\{ -1, 0, 1 \\} \\) as\n  \\begin{equation*}\n    \\sgn(x) \\coloneqq \\begin{cases}\n      1,  & x > 0, \\\\\n      0,  & x = 0, \\\\\n      -1, & x < 0.\n    \\end{cases}\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "977467ec4631d7be0c8ffa0f5b4e5231484ab832", "size": 4078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/real_numbers.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/real_numbers.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/real_numbers.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.4186046512, "max_line_length": 307, "alphanum_fraction": 0.6525257479, "num_tokens": 1350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6940829261678332}}
{"text": "\\section{Mathematical Preliminaries}\n\\label{sec:prelim}\nIn this paper, vector- and tensor-valued quantities\nare denoted by bold letters (e.g. $\\bh$ and $\\mathbf{T}$). \nSubscript indices of non-bold characters (e.g. $h_j$ or $T_{ij\\ell}$)\nare used to denote the entries within a vector or tensor.\nWe use the standard Einstein summation convention; i.e., \nthere is an implied sum taken over the repeated indices of \nany term (e.g. the symbol $a_{j} b_{j}$ is used to represent the sum\n$\\sum_{j} a_{j} b_{j}$).\nIf $\\xx = (x_1,x_2)^\\intercal$, then $\\xx^\\bot = (-x_2,x_1)^\\intercal$.\nSimilarly, $\\nabla^\\bot = (-\\partial_{x_2},\\partial_{x_1})^\\intercal$.\nUpper-case script characters (e.g. $\\mathcal{K}$) are reserved for\noperators on Banach spaces, with $\\mathcal{I}$ denoting the\nidentity. Given a set $X$, we denote the closure of $X$\nby $\\overline{X}$.\n\nFor a velocity field $\\bu$ and pressure $p$, let $\\bsigma(\\bu,p)$\ndenote the Cauchy stress tensor is given by\n\\begin{equation}\n\\bsigma(\\uu,p) = -p \\II + 2 \\be(\\bu) \\, ,\n\\end{equation}\nwhere $\\be(\\bu)$ is the strain tensor given by\n\\begin{equation}\ne_{ij}(\\bu) = \\frac{1}{2} \\left( \\partial_{x_j} u_i + \\partial_{x_i} u_j \\right) \\; .\n\\end{equation}\nWhen it is clear from context, we will drop the dependence of\n$\\bsigma$ on $\\bu$ and $p$.\nIf $\\Gamma$ is the boundary of a region $\\Omega$ and $\\bnu$ is the outward\nnormal to $\\Gamma$, the surface traction $\\bt$ on $\\Gamma$ \nis the Neumann data, i.e. \n\\begin{equation}\n\\bt = \\bsigma \\cdot \\bnu \\, .\n\\end{equation}\n\nWe seek solutions of \\cref{eq:ostokes} in the space\n\\begin{equation}\n  A(\\Omega) = \\{ (\\bu,p) \\textrm{ s.t. } \\bu \\in\n  \\left ( C^2(\\Omega)\\times C^2(\\Omega) \\right ) \\cap\n  \\left ( C(\\bar{\\Omega}) \\times C(\\bar{\\Omega}) \\right ) \\, , \\,\n  p \\in C^1(\\Omega) \\cap C(\\bar{\\Omega})\\} \\; ,\n\\end{equation}\nwhere $\\Omega$ is an open domain.\n\n\\subsection{Green's functions}\n\nLet $\\mathcal{L}_x$ denote a linear differential operator. A fundamental\nsolution $G(\\xx,\\yy)$ of $\\mathcal{L}_x$ satisfies the equation\n$\\mathcal{L}_x G(\\xx,\\yy) = \\delta_y(\\xx)$ in the distributional sense, i.e.\nfor sufficiently smooth $f$\n\\begin{equation}\n  \\mathcal{L}_x \\int_{\\R^2} G(\\xx,\\yy) f(\\yy) \\, d \\by = f(\\xx) \\; .\n  \\nonumber\n\\end{equation}\nWe consider here\nfree-space Green's functions, i.e. fundamental solutions which satisfy appropriate\nradiation conditions as $|\\xx-\\yy| \\to \\infty$.\nThe Green's function of the oscillatory biharmonic equation,\n\\begin{equation}\n  \\Delta ( \\Delta + k^2 ) u = 0 \\; , \\label{eq:obiharm} \\nonumber\n\\end{equation}\nis given by \n\\begin{equation}\n  \\Gbh(\\xx,\\yy) = \\frac{1}{k^2}\n  \\left (\\frac{1}{2\\pi} \\log |\\xx-\\yy| +\n  \\frac{i}{4} H_0^{(1)}(k|\\xx-\\yy|) \\right ) \\, ,\n  \\label{eq:Gbh}\n\\end{equation}\nwhere $k$ is the Helmholtz parameter in the oscillatory biharmonic equation,\nand $H_{0}^{1}(r)$ is the Hankel function of the first kind of order zero.\nNote that this is a scaled difference of the Green's function for\nLaplace, i.e.\n\n\\begin{equation}\n  \\Glap(\\xx,\\yy) = \\frac{1}{2\\pi} \\log |\\xx-\\yy| \\; , \\nonumber\n\\end{equation}\nand the Green's function for the Helmholtz equation\n\n\\begin{equation}\n  \\Ghelm(\\xx,\\yy) = -\\frac{i}{4} H_0^{(1)}(k|\\xx-\\yy|) \\; . \\nonumber\n\\end{equation}\n\n\\subsection{The Fredholm Alternative}\n\nWe require some standard results from the theory of\nFredholm integral equations. Interested readers may\nconsult \\cite{reed1972methods,colton1983integral,kress1989linear},\namong others, for the relevant background.\n\nWe first recall some definitions.\nLet $X$ and $Y$ be Banach spaces with a non-degenerate\nbilinear form $\\langle \\cdot ,\\cdot \\rangle: X\\times Y \\to \\C$.\n\\begin{itemize}\n\\item Two operators $\\cA:X\\to X$ and $\\cB:Y\\to Y$ are\nadjoint operators if\n$\\langle A \\phi,\\psi \\rangle = \\langle \\phi, B\\psi \\rangle$\nfor every $\\phi \\in X$ and $\\psi \\in Y$.\n\\item For an operator $\\cM:X\\to X$, we can define the range\n  $R(\\cM)$ as the set $\\{\\phi \\in X: \\exists \\phi_0 \\textrm{ with }\n  \\cM\\phi_0 = \\phi\\}$ and the null space $N(\\cM)$ as the\n  set $\\{\\phi \\in X: \\cM \\phi = 0 \\}$.\n\\item An operator $\\cA$ is said to be compact if\n  $\\overline{\\cA V}$ is a compact set for any\n  bounded subset $V\\subset X$.\n\\item Given a subspace $V\\subset X$,\n  we can define the subspace $V^\\perp\\subset Y$ as the\n  set $V^\\perp = \\{ \\psi \\in Y: \\langle \\phi,\\psi \\rangle = 0\n  \\textrm{ for each } \\phi \\in V \\}$, with the analogous\n  definition for subspaces of $Y$.\n\\end{itemize}\n\nOperators of the form $\\cI-\\cA$\nhave existence and uniqueness properties analogous to\nmatrices. This is known as the Fredholm Alternative;\nwe present the version provided in \\cite{colton1983integral}.\n\n\\begin{thrm}[Fredholm Alternative \\cite{colton1983integral}]\n  Let $X$ and $Y$ be Banach spaces and\n  $\\langle \\cdot,\\cdot \\rangle: X\\times Y \\to \\C$ be\n  a bilinear form. Suppose that $\\cA: X\\to X$ and\n  $\\cB:Y \\to Y$ are compact adjoint operators. Then\n  $\\dim N(\\cI-\\cA) = \\dim N(\\cI-\\cB) \\in \\N$,\n  $R(\\cI-\\cA) = N(\\cI-\\cB)^{\\perp}$, and\n  $R(\\cI-\\cB) = N(\\cI-\\cA)^\\perp$.\n\\end{thrm}\n\n\\subsection{Properties of the oscillatory Stokes layer\n  potentials}\n\nRecall that, in the case $k=i\\alpha$ for some real-valued $\\alpha$,\nthe oscillatory Stokes equations \\cref{eq:ostokes}\nare known as the modified Stokes equations and are of particular\ninterest for their application to the analysis and numerical\nsimulation of unsteady flow\n\\cite{Pozrikidis1992,biros2002embedded,\n  jiang2013second,ladyzhenskaya1969mathematical}.\nThe equations are well-studied in that setting and\nintegral representations which lead to second kind\nintegral equations have been developed. We review\nsome of the relevant results here, translating to\nthe oscillatory setting.\n\n\\subsubsection{Oscillatory Stokeslets and stresslets}\nConsider the solution of\n\\cref{eq:ostokes} where a $\\delta$-mass\ncentered at $\\yy$ with strength $\\ff$\nhas been added to the right-hand side of \\cref{eq:ostokes}, i.e.\n\n\\begin{align}\n  \\nabla p - \\Delta \\uu - k^2 \\uu &= \\delta_\\yy \\ff \\; ,\n  \\label{eq:ostokes_charge}  \\\\\n  \\nabla \\cdot \\uu &= 0 \\; . \\nonumber\n\\end{align}\nRecall that\n\n\\begin{equation}\n \\Delta \\Glap(\\xx,\\yy) = \\delta_\\yy(\\xx) \\; . \\label{eq:lapdelta}\n\\end{equation}\nIf we substitute \\eqref{eq:lapdelta} into\n\\eqref{eq:ostokes_charge} and take the divergence,\nwe obtain\n\n\\begin{equation}\n  p = \\nabla \\Glap(\\xx,\\yy) \\cdot \\ff \\; . \\nonumber\n\\end{equation}\nWe then have, formally,\n\n\\begin{align}\n  \\uu &= - (\\Delta + k^2)^{-1} ( \\Delta \\Glap \\ff\n  - \\nabla (\\nabla \\Glap \\cdot \\ff ) ) \\nonumber \\\\\n  &= \\left ( -\\Delta + \\nabla \\otimes \\nabla \\right )\n  \\Gbh \\ff \\; . \\nonumber\n\\end{align}\nThe tensor\n\n\\begin{equation} \\label{eq:ostokeslet}\n  \\GG = - \\II \\Delta \\Gbh + \\nabla \\otimes \\nabla \\Gbh\n\\end{equation}\nis then the analog of a Stokeslet\n\\cite{Pozrikidis1992} for \\eqref{eq:ostokes}.\n\nA related object is the stresslet, which is defined\nin terms of the stress tensor of the velocity, pressure\npair induced by a Stokeslet. For these tensors, we find\nthat it is more convenient to express them in index notation\nwith the Einstein index summing convention.\nRecall that the stress tensor $\\bsigma$ is defined as \n\n\\begin{equation}\n  \\sigma_{ij} = -p \\delta_{ij} + \\left ( \\partial_{x_j}u_i\n  +\\partial_{x_i} u_j \\right ) \\; , \\nonumber\n\\end{equation}\nwhere $\\delta_{ij}$ is the standard Kronecker delta notation.\nThe stresslet $\\TT$ is defined to be\n\n\\begin{align}\n  T_{ij\\ell} &= - \\partial_{x_j} \\Glap \\delta_{i\\ell}\n  + \\partial_{x_\\ell} \\left ( -\\Delta \\Gbh \\delta_{ij} +\n  \\partial_{x_i} \\left(\\partial_{x_j} \\Gbh \\right) \\right)\n  \\nonumber \\\\\n  & \\qquad+ \\partial_{x_i} \\left ( -\\Delta \\Gbh \\delta_{\\ell j} +\n  \\partial_{x_\\ell} \\left(\\partial_{x_j} \\Gbh \\right) \\right)\n  \\; . \\label{eq:ostress} \n\\end{align}\nLet $u_i = G_{ij} f_j$ and $p = \\partial_{x_i} \\Glap f_i$ be a\nsolution of the Stokes equations induced by a Stokeslet.\nThen the corresponding stress tensor is given by\n$\\sigma_{i\\ell} = T_{ij\\ell} f_j$.\n\n%For the layer potentials of the next section, the following\n%formulas are useful. Let $\\bnu$ be a given vector. When\n%summing over the third index, we obtain\n%\n%\\begin{equation}\n%  \\TT_{\\cdot,\\cdot,\\ell} \\nu_\\ell = -\\bnu \\otimes \\nabla \\Glap\n%  + \\partial_\\nu \\left ( -\\Delta \\Gbh \\II\n%  + \\nabla \\otimes \\nabla \\Gbh \\right)\n%  + \\nabla \\otimes \\left ( -\\Delta \\Gbh \\bnu\n%  + \\partial_{\\nu} \\nabla \\Gbh \\right) \\; . \\nonumber\n%\\end{equation}\n%Let $\\btau = \\bnu^\\bot$. Then\n%\n%\\begin{equation}\n%  \\TT_{\\cdot,\\cdot,k} \\nu_k = -\\bnu \\otimes \\nabla \\Glap\n%  - \\nabla^\\bot \\otimes \\nabla^\\bot \\partial_\\nu \\Gbh\n%  +\\nabla \\otimes \\nabla^\\bot \\partial_\\tau \\Gbh \\; .\n%  \\nonumber\n%\\end{equation}\n\n\\subsubsection{Layer potentials}\n\nWe now use the Stokeslet and stresslet \nto define the single\nand double layer potentials for the oscillatory Stokes problem.\nFor $\\xx \\in \\R^2$, the single layer potential with density $\\bmu$\nis defined to be\n\n\\begin{equation} \\label{eq:singlelayer}\n  \\bS [\\bmu] (\\xx) = \\int_\\Gamma \\GG (\\xx,\\yy) \\bmu(\\yy)\n  \\, dS(\\yy) \\; .\n\\end{equation}\nWe use the notation $\\bsigma_\\bS[\\bmu]$ to denote the\nstress tensor of the single layer at any given point\n$\\xx \\in \\R^2 \\setminus \\Gamma$.\n\nFor $\\xx \\in \\R^2 \\setminus \\Gamma$, the double layer\npotential with density $\\bmu$ is defined to be\n\n\\begin{equation} \\label{eq:doublelayer}\n  \\bD [\\bmu] (\\xx) = \\int_\\Gamma \\left ( \\TT_{\\cdot,\\cdot,\\ell}(\\xx,\\yy)\n  \\nu_\\ell(\\yy)\\right )^\\intercal \\bmu(\\yy) \\, dS(\\yy) \\; ,\n\\end{equation}\nwhere $\\bnu$ denotes the outward unit normal to the boundary.\nIf we write $\\bmu = \\bnu \\mu_\\nu + \\btau \\mu_\\tau$,\nwhere $\\btau = \\bnu^\\bot$ is the positively oriented unit\ntangent to the curve, then we have\n\n\\begin{align} \\label{eq:stokesdlkernel}\n  \\left ( \\TT_{\\cdot,\\cdot,\\ell}(\\xx,\\yy)\\nu_\\ell(\\yy) \\right )^\\intercal\n  \\bmu(\\yy) &= \\left ( - \\nabla \\Glap(\\xx,\\yy) + 2 \\nabla^\\bot\n  \\partial_{\\nu\\tau} \\Gbh(\\xx,\\yy) \\right ) \\mu_\\nu(\\yy) \\nonumber \\\\\n  & \\qquad+\n  \\nabla^\\bot \\left (\\partial_{\\tau\\tau}-\\partial_{\\nu\\nu} \\right )\n  \\Gbh(\\xx,\\yy) \\mu_\\tau(\\yy) \\; .\n\\end{align}\n\nLet $\\cS[\\bmu]: C(\\Gamma) \\to C(\\Gamma)$, and\n$\\cD[\\bmu]: C(\\Gamma) \\to C(\\Gamma)$ \ndenote the restrictions of the layer potentials \n$\\bS[\\bmu]$ and $\\bD[\\bmu]$ on the boundary $\\Gamma$, i.e.\nfor $\\bx \\in \\Gamma$, \n\n\\begin{equation}\n  \\cS [\\bmu] (\\xx) = \\int_\\Gamma \\GG (\\xx,\\yy) \\bmu(\\yy)\n  \\, dS(\\yy)\n\\end{equation}\nand\n\\begin{equation}\n\\label{eq:dlformula}\n  \\cD [\\bmu] (\\xx) = \\pv \\int_\\Gamma \\left ( \\TT_{\\cdot,\\cdot,\\ell}(\\bx,\\by)\n  \\nu_\\ell(\\yy)\n  \\right )^\\intercal \\bmu(\\yy) \\, dS(\\yy) \\; ,\n\\end{equation}\nwhere the \\pv indicates that the integral is to be\nevaluated in the principal value sense. \n\nFor two vector valued\nfunctions $\\ff$ and $\\bg$ defined on $\\Gamma$, consider the bilinear\nform\n\\begin{equation} \\label{eq:bi_form}\n  \\langle \\ff , \\bg \\rangle = \\int_\\Gamma \\ff \\cdot \\bg dS \\; .\n\\end{equation}\nThe definition of the adjoint used throughout the paper will be\nthe one induced by this form.\n\n\nThe adjoint of $\\cD$ with respect to the above bilinear form\nis of particular interest; and is given by\n\\begin{equation}\n  \\cD^{\\intercal} [\\bmu](\\bx) = \n  \\pv \\int_\\Gamma \\left ( \\TT_{\\cdot,\\cdot,\\ell}(\\bx,\\by)\\nu_\\ell(\\xx)\n  \\right ) \\bmu(\\yy) \\, dS(\\yy) \\; .\n\\end{equation}\n\n\nIn the following lemma, we review the limiting values of\nthe layer potentials $\\bS$ and $\\bD$ on the boundary $\\Gamma$.\n\n\\begin{lem}[Jump conditions] \\label{lem:jump-conds}\n  Suppose that $\\Omega$ is a bounded region with a $C^{2}$ boundary\n  $\\Gamma$.\n  Let $\\bnu(\\bx)$ denote the outward pointing normal at $\\bx \\in \\Gamma$.\n  Suppose that $\\bmu \\in C(\\Gamma)$.\n  Then $\\bS[\\bmu]$\n  is continuous across $\\Gamma$, and the exterior and interior\n  limits of the surface traction of $\\bD[\\bmu]$ are equal.\n  Furthermore, for $\\bx_{0} \\in \\Gamma$,\n\n  \\begin{align}\n    \\lim_{h \\downarrow 0^{+}} \\bsigma_\\bS[\\bmu](\\xx_0 \\pm h\\bnu(\\xx_0)) \\cdot \\bnu(\\xx_0)\n    &= \\mp \\frac{1}{2} \\bmu(\\xx_0) + \\cDt[\\bmu](\\xx_0) \\\\\n    \\lim_{h \\downarrow 0^{+}} \\bD[\\bmu](\\xx_0 \\pm h\\bnu(\\xx_0)) \n    &= \\pm \\frac{1}{2} \\bmu(\\xx_0) + \\cD[\\bmu](\\xx_0)    \\; .\n  \\end{align}\n\\end{lem}\n\nThe above expressions are derived by noting that the\nleading order singularity of these integral kernels\nis the same as for the original Stokes case, so that\nthe standard jump conditions for Stokes\n\\cite{KimSangtae1991,Pozrikidis1992}\napply. \n\n\\begin{lem} \\label{lem:compact-sd}\n  Suppose that $\\Omega$ is a bounded region with a $C^{2}$ boundary\n  $\\Gamma$. Then the operators $\\cS$ and $\\cD$ defined\n  above are compact operators on $C(\\Gamma)\\times C(\\Gamma)$\n  and $\\mathbb{L}^2(\\Gamma)\\times \\mathbb{L}^2(\\Gamma)$.\n\\end{lem}\n\nCompactness is proved by considering the\nasymptotic expansion of each kernel about\n$\\xx=\\yy$ and noting that each is at most\nweakly singular.\n\n\\subsubsection{Representation Theorem}\n\nIn the following theorem, we sketch the proof of the equivalent of the\nGreen's identity for oscillatory Stokes setting, which is well-known\nin the Stokes and modified Stokes settings\n\\cite{Pozrikidis1992,biros2002embedded,ladyzhenskaya1969mathematical}.\n\n\\begin{thrm} \\label{thrm:rep-theorem}\n  Let $\\Omega$ be a bounded domain with $C^2$ boundary and let\n  the pair $(\\bu,p)$ satisfy the oscillatory Stokes equations\n  \\cref{eq:ostokes} in $\\Omega$. Let $\\bt$ denote the surface\n  traction associated with $(\\bu,p)$. Then\n\n  \\begin{equation} \\label{eq:rep-theorem}\n    \\bS [\\bt](\\xx) - \\bD[\\bu](\\xx) = \\begin{cases} \n    \\bu(\\xx) &\\quad \\xx \\in \\Omega \\,  \\\\\n    0 &\\quad \\xx \\in E \n    \\end{cases} \\; ,\n  \\end{equation}\n  where $E=\\R^2\\setminus\\bar\\Omega$ is the\n  exterior of the domain.\n\\end{thrm}\n\n\\begin{proof}\n  Suppose that $\\xx \\in \\Omega$.\n  By the definitions of $\\GG$ and $\\Glap$, we have\n  \\begin{equation*}\n    \\bu(\\xx) = \\int_\\Omega -(\\Delta + k^2) \\GG(\\xx,\\yy) \\bu(\\yy)\n    + \\nabla \\otimes \\nabla \\Glap(\\xx,\\yy) \\bu(\\yy) \\, dV(\\yy) \\; .\n  \\end{equation*}\n  Applying Green's identity and the divergence theorem, we\n  obtain\n  \\begin{equation}\n    \\bu(\\xx) = \\int_\\Gamma \\GG(\\xx,\\yy) \\partial_\\nu \\bu\n    - \\partial_\\nu \\GG(\\xx,\\yy) \\bu\n    - \\nabla \\Glap(\\xx,\\yy) (\\bnu \\cdot \\bu) \\, dS \n    - \\int_\\Omega \\GG(\\xx,\\yy) (\\Delta + k^2) u \\, dV \\; .\n    \\nonumber\n  \\end{equation}\n  Substituting the definition of the PDE and applying the divergence\n  theorem again, we obtain\n  \\begin{equation}\n    \\bu(\\xx) = \\int_\\Gamma \\GG \\partial_\\nu \\bu - p \\GG \\bnu - \\partial_\\nu \\GG \\bu\n    - \\nabla \\Glap (\\bnu \\cdot \\bu) \\, dS  \\; . \\label{eq:rep_proof_1}\n  \\end{equation}\n  From the divergence theorem and the divergence-free properties of\n  $\\uu$ and $\\GG$, we then get\n\n  \\begin{equation}\n    \\int_\\Gamma \\GG \\nabla (\\bu \\cdot \\bnu)\n    - (\\nabla \\GG \\bnu)^\\intercal \\bu \\, dS = 0 \\; .  \\label{eq:rep_proof_2}\n  \\end{equation}\n  Adding \\cref{eq:rep_proof_1,eq:rep_proof_2}, we get the desired\n  result. The argument for the case $\\xx \\in E$ is similar.\n\\end{proof}\n\nA consequence of \\cref{thrm:rep-theorem} and the analyticity\nof $\\Gbh$ is \n\\begin{cor}\n\\label{cor:analytic}  \n  Let $(\\uu,p) \\in A(\\Omega)$ be a solution of \\cref{eq:ostokes}.\n  Then each component of $\\uu(\\xx)$ is an analytic function\n  of the coordinates $\\xx$ in $\\Omega$.\n\\end{cor}\n\nThe proof of \\cref{cor:analytic} follows the same reasoning as\nthat for the Helmholtz case; see \\cite[Theorem 3.5]{colton1983integral}.\n\n\n\\subsubsection{Null-space correction \\label{subsubsec:nullspacecorr}}\n\nWithout modification, the standard layer potentials\ncan result in rank-deficient representations for\nthe boundary value problems. The nature of this deficiency\nis treated in~\\cref{sec:analysis} but for now we introduce a standard\noperator used to correct this. For any integrable density\n$\\bmu$, let $\\cW[\\bmu]$ be defined by\n\n\\begin{equation} \\label{eq:ones_operator}\n  \\cW[\\bmu](\\xx) = \\frac{1}{|\\Gamma|} \\int_\\Gamma \\bnu(\\xx)\n  \\left ( \\bnu(\\yy) \\cdot \\bmu(\\yy) \\right )\n  \\, dS(\\yy) \\; ,\n\\end{equation}\nfor any $\\xx \\in \\Gamma$. We have\n\n\\begin{lem}\n  \\label{lem:propnullspacecorr}\n\n  Let $\\Omega$ be a domain with $C^2$ boundary and $\\bmu$ be\n  an integrable function defined on $\\Gamma$. Then\n  \\begin{itemize}\n  \\item $\\cW[\\cW[\\bmu]] = \\cW[\\bmu]$,\n  \\item $\\cW^\\intercal = \\cW$,\n  \\item $\\cW[\\bmu - 2 \\cD[\\bmu]] = 0$,\n  \\item $\\cW[\\cS[\\bmu]] = 0$,\n  \\end{itemize}\n  where the transpose is induced by the bilinear\n  form \\cref{eq:bi_form}.\n\\end{lem}\n\n\\begin{proof}\n  The first two results follow from the definitions of $\\cW$ and\n  the normal vector. The other two follow from the fact that\n  $\\bS[\\bmu]$ and $\\bD[\\bmu]$ are divergence-free and\n  an application of \\cref{lem:jump-conds}.\n\\end{proof}\n\n\\begin{remark}\nThe operators $\\bS,\\bD,\\cD$ and $\\cD^{\\intercal}$\ndepend on the Helmholtz parameter $k$ of the oscillatory Stokes equation.\nIn places where it is essential to highlight this dependence, in a slight\nabuse of notation, we will use the symbols $\\bS_{k}, \\bD_{k},\\cD_{k}$ and $\\cDt_{k}$ to \ndenote this dependence.\nSimilarly, we will use $A^{\\Gamma}$ instead of the operator $A$ to highlight \nthe dependence of the operator $A$ on the boundary of the region $\\Gamma$.\n\\end{remark}\n", "meta": {"hexsha": "13bfeed0d700b01c0d056bd6169a0bdae1e9cb17", "size": 17048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01-stokes/02prelim.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/02prelim.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/02prelim.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": 36.9004329004, "max_line_length": 89, "alphanum_fraction": 0.6747419052, "num_tokens": 5994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6940829204395909}}
{"text": "% !TeX document-id = {d3b263d9-4ae8-4edf-a203-72d775f66a9e}\n\\documentclass[]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{dsfont} % /mathds{}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{hyperref} % Hyperlinks\n\\usepackage{xcolor} % \\colorbox{} & \\textcolor{}\n\n%% \\usepackage{minted} % Syntax Highlighting (Requires Python)\n%% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]\n\n% See https://tex.stackexchange.com/a/78393/1661\n\\usepackage[framed, numbered, autolinebreaks, useliterate]{mcode} % Syntax Highlighting MATLAB\n\n% Math Symbols\n% http://www.cs.put.poznan.pl/ksiek/latexmath.html\n\n%\\newtheorem{theorem}{Theorem}[section]\n%\\newtheorem{corollary}{Corollary}[theorem]\n%\\newtheorem*{lemma*}[theorem]{Lemma}\n\\newtheorem*{lemma}{Lemma}\n\\newtheorem*{remark}{Remark}\n\n\\DeclareMathOperator{\\sign}{sign}\n\\DeclareMathOperator{\\prox}{prox}\n\\DeclareMathOperator{\\diag}{diag}\n\\DeclareMathOperator{\\Tr}{Tr}\n\\DeclareMathOperator{\\cond}{cond}\n\\DeclareMathOperator{\\chol}{chol}\n\n% Math Commands\n\\newcommand{\\MyParen}[1]{\\left( #1 \\right)}\n\\newcommand{\\MyBrack}[1]{\\left\\lbrack #1 \\right\\rbrack}\n\\newcommand{\\MyBrace}[1]{\\left\\lbrace #1 \\right\\rbrace}\n\\newcommand{\\MyNorm}[2]{{\\left\\| #1 \\right\\|}_{#2}}\n\\newcommand{\\MyNormSqr}[2]{{\\left\\| #1 \\right\\|}_{#2}^{2}}\n\\newcommand{\\MyAbs}[1]{\\left| #1 \\right|}\n\\newcommand{\\MyNormTwo}[1]{\\MyNorm{#1}{2}}\n\\newcommand{\\MyNormTwoSqr}[1]{\\MyNormSqr{#1}{2}}\n\\newcommand{\\MyCeil}[1]{\\lceil #1 \\rceil}\n\\newcommand{\\MyProd}[2]{\\langle #1, #2 \\rangle}\n\\newcommand{\\MyUndBrace}[2]{\\underset{#2}{\\underbrace{#1}}}\n% \\newcommand{\\RR}[1]{\\mathds{R}^{#1}} % Asaf's Style\n\\newcommand{\\RR}[1]{\\mathbb{R}^{#1}}\n\\newcommand{\\EE}[1]{\\mathbb{E} \\MyBrack{#1}}\n\n% Text Commands\n\\newcommand{\\inlinecode}[1]{\\colorbox{lightgray}{\\texttt{#1}}}\n\n\\begin{document}\n\t\n\t\\section*{Question - Calculate the Optimal Weights which Minimizes Variance}\n\t\n\tGiven $ \\MyBrace{ \\boldsymbol{{x}_{1}}, \\boldsymbol{{x}_{2}}, \\ldots, \\boldsymbol{{x}_{m}} } $ where $ {x}_{i} \\in \\RR{n} $ find $ w \\in \\RR{m} $ which minimized the Variance of $ y $ given by $ y = {w}_{1} \\boldsymbol{{x}_{1}} + {w}_{2} \\boldsymbol{{x}_{2}} + \\cdots + {w}_{m} \\boldsymbol{{x}_{m}} $ where $ \\forall i \\: {w}_{i} \\geq 0 $ and $ \\sum_{i = 1}^{m} {w}_{i} = 1 $.\n\t\n\t\\begin{remark}\n\t\tThe question is given at \\href{https://stackoverflow.com/questions/44984132}{Question 44984132 on StackOverflow}.\n\t\\end{remark}\n\t\n\t\\section*{Answer - Calculate the Optimal Weights which Minimizes Variance}\n\t\n\tThe above can be written as following:\n\t\n\t\\begin{alignat*}{3}\n\t\\arg \\min_{w} \t\t& \\quad && \\frac{1}{2} \\MyNormTwoSqr{ X w - \\frac{1}{m} {e}^{T} X w e } \\\\\n\t\\text{subject to} \t& \\quad && w \\succeq 0 \\\\\n\t\t\t\t\t\t& \\quad && {e}^{T} w = 1 \\\\\n\t\\end{alignat*}\n\t\n\tWhere $ X $ is composed by $ \\MyBrace{ \\boldsymbol{{x}_{1}}, \\boldsymbol{{x}_{2}}, \\ldots, \\boldsymbol{{x}_{m}} } $ as its columns, $ w = \\MyBrack{{w}_{1}, {w}_{2}, \\ldots, {w}_{m}}^{T} $ and $ e = \\MyBrack{1, 1, \\ldots, 1}^{T}, \\, e \\in \\RR{m} $.\n\t\n\tThe above is a Convex Problem where the solution is limited to the Unit Simplex.\n\t\n\tA method to solve is using \\href{https://en.wikipedia.org/wiki/Subgradient_method}{Projected Sub Gradient Method}. The idea is to apply a Sub Gradient step and project the result onto the Unit Simplex.\n\t\n\tIn order to so one have to calculate the following:\n\t\\begin{itemize}\n\t\t\\item The Sub Gradient (Gradient in the case above as the function is smooth) of the Objective Function.\n\t\t\\item The Projection onto the unit simplex.\n\t\\end{itemize}\n\t\n\t\\subsubsection*{The Gradient of the Objective Function}\n\t% See https://en.wikipedia.org/wiki/Matrix_calculus for \"Denominator Layout\"\n\t\\begin{align*}\n\t\\frac{\\partial }{\\partial w} f \\MyParen{w} & = \\frac{\\partial }{\\partial w} \\MyParen{\\frac{1}{2} \\MyNormTwoSqr{ X w - \\frac{1}{m} {e}^{T} X w e }} && \\text{} \\\\\n\t& = \\frac{\\partial }{\\partial w} \\MyParen{ X w - \\frac{1}{m} {e}^{T} X w e } \\frac{\\partial }{\\partial \\MyParen{X w - \\frac{1}{m} {e}^{T} X w e}} f \\MyParen{w} && \\text{} \\\\\n\t& = \\MyParen{ {X}^{T} - \\frac{1}{m} \\frac{\\partial }{\\partial w} \\MyParen{{e}^{T} X w e} } \\MyParen{X w - \\frac{1}{m} {e}^{T} X w e} && \\text{} \\\\\n\t& = \\MyParen{ {X}^{T} - \\frac{1}{m} {X}^{T} e {e}^{T} } \\MyParen{X w - \\frac{1}{m} {e}^{T} X w e} && \\text{} \\\\\n\t\\end{align*}\n\t\n\t\\subsubsection*{The Projection onto the Unit Simplex}\n\tThere are 2 options to apply this:\n\t\\begin{itemize}\n\t\t\\item Solving the Projection Minimization as done in \\href{https://math.stackexchange.com/a/2338491}{MathExchange Answer 2338491}.\n\t\t\\item Iteratively projecting onto the Non Negative Half Space and the set of vectors which their sum is $ 1 $.\n\t\\end{itemize}\n\t\n\t\\begin{remark}\n\t\tThe answer (With MATLAB code) is given at \\href{https://stackoverflow.com/a/44986301/195787}{Answer 195787 on StackOverflow}.\n\t\\end{remark}\n\t\n\t\n\\end{document}\n", "meta": {"hexsha": "0dc34f063cbba9e1bf78f46b4d9049a5f92ef6ff", "size": 4882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "StackOverflow/Q44984132/Q44984132.tex", "max_stars_repo_name": "skn123/StackExchangeCodes", "max_stars_repo_head_hexsha": "c5193a52567eb23a2d0479e489cd7910a8df7e9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "StackOverflow/Q44984132/Q44984132.tex", "max_issues_repo_name": "skn123/StackExchangeCodes", "max_issues_repo_head_hexsha": "c5193a52567eb23a2d0479e489cd7910a8df7e9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "StackOverflow/Q44984132/Q44984132.tex", "max_forks_repo_name": "skn123/StackExchangeCodes", "max_forks_repo_head_hexsha": "c5193a52567eb23a2d0479e489cd7910a8df7e9e", "max_forks_repo_licenses": ["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.2037037037, "max_line_length": 377, "alphanum_fraction": 0.6665301106, "num_tokens": 1767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.6940829192831589}}
{"text": "\\section{Top Level}\n\nIn top level, the system maintains the interaction with user and\nadds the user input, namely, \\textit{Axiom}, \\textit{Definition}, \\textit{Fixpoint}, and \\textit{Inductive Definition}, \ninto the context.\\par\nIt is also in this part, the inductive rule forms.\n\n\\subsection{Acceptance of Command}\n\\subsubsection{Axiom}\nAfter parsing and checking, the command will be like\n$$\n\\tt Ax\\ \\ \\it name\\ term,\n$$ \nwhere {\\it term} denotes the type of this axiom.\nSince it is an axiom, we do not have to (sometimes can not) build the corresponding term.\\par\nJust build the corresponding term as {\\it Nothing} then put it into the context.\n\n\\subsubsection{Definition}\nAfter parsing and checking, the command will be like\n$$\n\\tt Def\\ \\ {\\it name\\ term2\\ term1},\n$$\nwhere {\\it term2} is the type of {\\it term1}.\\par\nSimply bind the name, term, type together and put it into the context.\n\n\\subsubsection{Fixpoint}\nAfter parsing and checking, the command will be like\n$$\n\\tt Fix\\ {\\it name }\\ \\left(\\lambda {\\it f}:{\\it term1},\\ {\\it term2}\\right),\n$$\nwhere {\\it term1} is the type of {\\it term2} and it is a recursive function of {\\it f}.\\par \nSince this recursive function has passed all the type check and safety check, we can safely use it without worrying termination\nproblem.\nOn the other hand, whether it is a {\\it Fixpoint} definition will not influence any reduction, because the reduction\nalways finds the term in context according to its index.\\par\nSo simply remove the {\\it Fixpoint} mark and put it into the context.\n\n\\subsubsection{Inductive Definition}\nAfter parsing and checking, the command will be like\n$$\n\\tt Ind\\ \\ {\\it name\\ p\\ term2\\ term1\\ constructors},\n$$\nwhere {\\it p} is the number of parameters of the inductive type, {\\it term1} is the type of the inductive definition,\nand {\\it term2} is the corresponding term.\\par\nApart from the ordinary operation, we also need to add inductive rule, which is actually a type theory view of mathematical\ninduction. Since the proof of a claim becomes a term of certain type, the induction rule is a term offering inductive scheme.\\par\nFor example,\n\\begin{center}\n\\begin{minted}{coq}\nInductive nat : Type := \n| O : nat\n| S : nat -> nat.\n\n(* build inductive rule*)\n\nfun (P:nat -> Type)(f:P O)(f0:forall (n:nat), P n -> P (S n))\n    fix F (n:nat) : P n :=\n        match n as n0 in nat return (P n0) with\n        | O => f\n        | S n0 => f0 n0 (F n0)\n        end\n:\nforall (P:nat -> Type), P O -> \n    (forall (n:nat), P n -> P (S n)) ->\n        forall (n:nat), P n\n\\end{minted}\n\\end{center}\nThe intuition here is that for a proposition \\mintinline{coq}|P|,\n\\begin{itemize}\n\\item it is true on \\mintinline{coq}|O|;\n\\item if it is true on \\mintinline{coq}|n|, then it is true on \\mintinline{coq}|S n|.\n\\end{itemize}\nThen it is true on all term of \\mintinline{coq}|nat| type, which is reasonable according \nmathematical induction.\\par\nBasically, to build such term, we should build weakened assumptions for all constructors first, \nlike the \\mintinline{coq}|f|,\n\\mintinline{coq}|f0| above. After that, the final proposition which applies to all the terms of such inductive type\nshall come out, like the \\mintinline{coq}|F| above.\\par\nEvery occurrence of the inductive type on the constructors demands a verification of the proposition,\nwhich explains why for constructor \\mintinline{coq}|S : nat -> nat|, which depends on a \\mintinline{coq}|nat| term, \nthe weakened assumption is \\mintinline{coq}|f0 : forall (n:nat), P n -> P (S n)|.\\par\nThe reason why the inductive rule of \\mintinline{coq}|nat| requires {\\it Fixpoint} is that some constructors of it\nrely on the term of type \\mintinline{coq}|nat|. Here is a case which do not need recursive function.\n\\begin{center}\n\\begin{minted}{coq}\nInductive eq (T : Type) (x : T) : T -> Type :=\n| eq_refl : eq T x x.\n\n(* build inductive rule*)\n\nfun (T:Type) (x:T) (P:forall (t:T) (_:eq T x t), Type) \n    (f:P x (eq_refl T x)) (t:T) (e:eq T x t) => \n        match e as e0 in eq _ _ a0 return (P a0 e0) with \n        | eq_refl _ _ => f\n        end\n: \nforall (T:Type) (x:T) (P:forall (t:T) (_:eq T x t), Type) \n    (f:P x (eq_refl T x)) (t:T) (e:eq T x t),\n        P t e\n\\end{minted}\n\\end{center}\nSadly, we have to admit that because of the lack of references, time, and energy,\nthe induction rule in our system is not complete.\nThe inductive definition acceptable to our system must satisfy:\\par\nAssume the inductive type is $\\tt A_1\\to A_2\\to \\cdots A_n$, then $\\tt A_k$ must be\nany one of the following\n\\begin{itemize}\n\\item A ordinary term, like \\mintinline{coq}|Type|, \\mintinline{coq}|T|.\n\\item An application, like \\mintinline{coq}|P n|.\n\\item An inductive type, like \\mintinline{coq}|nat|, \\mintinline{coq}|eq T x y|.\n\\end{itemize}\nOthers like product type \\mintinline{coq}|U -> V| is not supported.\n\n\\subsection{Requests to Environment}\n\\subsubsection{\\tt Print \\sl ident}\nThis command displays on the screen information about the declared or defined object referred by {\\sl ident}.\n\\subsubsection{\\tt Check \\sl term}\nThis command displays the type of {\\sl term}.\n\n\\subsection{Top Loop}\nThe main work flow of our top level loop:\n\\subsubsection*{Reading raw input}\nThe MiniProver will read the user's input until a dot (\\textquotesingle .\\textquotesingle), and any further input in the same line will be abandoned.\n\\subsubsection*{Parsing}\nThe raw input will be parsed without nameless representation.\n\nHere is an example, the raw input\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\n(* raw input *)\nFixpoint plus (n:nat) (m:nat) : nat :=\nmatch n as n0 in nat return nat with\n| O => m\n| S n0 => S (plus n0 m)\nend.\n\\end{minted}\n\\end{minipage}\n\\end{center}\nwill be parsed as the AST\n\\begin{center}\n\\begin{minipage}{0.9\\textwidth}\n\\begin{minted}{haskell}\nFix \"plus\"\n  ( TmFix (-1)\n    ( TmLambda \"plus\"\n      ( TmProd \"n\" ( TmVar \"nat\" )\n        ( TmProd \"m\" ( TmVar \"nat\" ) ( TmVar \"nat\" )))\n      ( TmLambda \"n\" ( TmVar \"nat\" )\n        ( TmLambda \"m\" ( TmVar \"nat\" )\n          ( TmMatch (-1) ( TmVar \"n\" ) \"n0\" [ \"nat\" ]\n            ( TmVar \"nat\" )\n            [ Equation [ \"O\" ] ( TmVar \"m\" )\n            , Equation [ \"S\", \"n0\" ]\n              ( TmAppl\n                [ TmLambda \"n\" ( TmVar \"nat\" )\n                  ( TmAppl [ TmVar \"S\", TmVar \"n\" ])\n                , TmAppl [ TmVar \"plus\", TmVar \"n0\", TmVar \"m\" ]])])))))\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\\subsubsection*{Duplicate global name checking}\nAfter parsing, we can get the name of the input command, and the name should not be the same with\nany defined or declared object in the environment.\n\\subsubsection*{Name checking}\nBefore building the nameless representation, there should be no unbounded name in the AST.\n\\subsubsection*{Nameless representation building}\nIf all names are bounded, we can build the nameless representation. The variable pointed to\na type constructor or a term constructor will be unfolded to its functional representation.\n\nHere is an example, the nameless AST will be built for the previous AST:\n\\begin{center}\n\\begin{minipage}{0.9\\textwidth}\n\\begin{minted}{haskell}\nFix \"plus\"\n( TmFix (-1)\n  ( TmLambda \"plus\"\n    ( TmProd \"n\" ( TmIndType \"nat\" [])\n      ( TmProd \"m\" ( TmIndType \"nat\" []) ( TmIndType \"nat\" [])))\n    ( TmLambda \"n\" ( TmIndType \"nat\" [])\n      ( TmLambda \"m\" ( TmIndType \"nat\" [])\n        ( TmMatch 0 ( TmRel \"n\" 1 ) \"n0\" [ \"nat\" ] ( TmIndType \"nat\" [])\n          [ Equation [ \"O\" ] ( TmRel \"m\" 0 )\n          , Equation [ \"S\", \"n0\" ]\n            ( TmAppl \n              [ TmLambda \"n\" ( TmIndType \"nat\" [])\n                ( TmConstr \"S\" [ TmRel \"n\" 0 ])\n              , TmAppl\n                [ TmRel \"plus\" 3\n                , TmRel \"n0\" 0\n                , TmRel \"m\" 1 ]])])))))\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\\subsubsection*{Positivity Checking (Inductive Definition Only)}\nFor an inductive definition, after building it's nameless representation, the positivity\ncould be checked.\n\\subsubsection*{Termination Checking}\nAll subterms with fixpoint definitions will be checked if they are terminating. After checking,\nannotations for the indices of decreasing variables will be added to the AST.\n\\subsubsection*{Type checking}\nBefore actually dealing with the command, the top level will check if it's a well-typed command.\n\\subsubsection*{Processing the command}\nThe definitions and declarations will be processed as described before. And an assertion will lead to the proof editing mode.\n\n", "meta": {"hexsha": "bf1feacf4cd97feb92059eb99680119150274b09", "size": 8450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/toplevel.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/toplevel.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/toplevel.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": 41.0194174757, "max_line_length": 149, "alphanum_fraction": 0.6820118343, "num_tokens": 2505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6940829147113482}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage[round]{natbib}\n\\usepackage{hyperref}\n\\usepackage{cleveref}\n\\usepackage{amsmath}\n\\usepackage{mathrsfs}\n\\usepackage{listings}\n\n\\usepackage{algorithm}\n\\usepackage[noend]{algpseudocode}\n\n\\makeatletter\n\\def\\BState{\\State\\hskip-\\ALG@thistlm}\n\\makeatother\n\n\\title{FAS Multigrid in Chombo}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nThis is an application with illustrates the use of the AMR Full Approximation Scheme (FAS) multigrid solver for nonlinear problems within Chombo \\citep{Chombo}. \n\nHere, we first describe the nonlinear problem that the code solves (\\cref{sec:problem}). In \\cref{sec:options} we describe some of options available in the application, and in \\cref{sec:tests} we demonstrate the accuracy of the code. Finally, in \\cref{sec:algorithm}, we describe how we implement the algorithm on an AMR hierarchy.\n\n\\section{Example problem}\n\\label{sec:problem}\nWe follow \\cite{Henson2002} and consider the nonlinear problem\n\\begin{align}\n- \\nabla^2 u + \\gamma \\, u e^u = f,\n\\end{align}\nwhere $\\gamma$ is a constant, $f$ is some forcing term and $u$ is the solution we wish to obtain. The domain is a 2D unit square ($0<x<1, 0<y<1$), and boundary conditions are given by $u=0$ on all sides. \n\nThe size of $\\gamma$ determines the strength of the nonlinearity; when $\\gamma=0$ the problem reduces to solving a Poisson equation. We choose the forcing $f$ such that the problem has an analytic solution, allowing us to determine the accuracy of our numerical scheme.\n\nThe example code contains two difference problems. The problem which will be solver is determined by the \\texttt{main.problem} parameter in the inputs file, which should be set to either $0$ for the `exact' problem (\\cref{sec:exact})or $1$ for the `inexact' problem' (\\cref{sec:inexact}).\n\n\\subsection{Exact}\n\\label{sec:exact}\nTaking \n\\begin{align}\nu=(x-x^2)(y-y^2),\n\\end{align}\nthe forcing term becomes\n\\begin{align}\nf = 2 \\left[ (x-x^2) + (y-y^2) \\right] + \\gamma (x-x^2)(y-y^2) e^{(x-x^2)(y-y^2)}.\n\\end{align}\nAs \\cite{Henson2002} note, the solution here is a second order polynomial so there is no discretization error with our second order scheme. Hence, we refer to this test case as `exact'.\n\n\n\\subsection{Inexact}\n\\label{sec:inexact}\nChoosing \n\\begin{align}\nu=(x^2-x^3) \\sin (3 \\pi y),\n\\end{align}\nthe forcing term becomes\n\\begin{align}\nf = \\left\\{ \\left[9 \\pi^2 + \\gamma e^{(x^2-x^3) \\sin (3 \\pi y)} \\right] (x^2 - x^3) +6x -2 \\right\\} \\sin (3 \\pi y),\n\\end{align}\nwhich will now have a notable discretization error.\n\n\\section{Options}\n\\label{sec:options}\nThe \\texttt{inputs} file controls various aspects of the application.\n\n\\subsection{Grids}\nWhen \\texttt{grids}.\\texttt{max\\char`_level} is greater than $0$, the grid hierarchy is determined by refining all cells where\n\\begin{align}\n\\text{max}(\\nabla f) \\Delta x > \\texttt{grids}.\\texttt{refine}\\char`_\\texttt{threshold}.\n\\end{align}\nAlternatively, you can specify the desired grids by setting \\texttt{grids.read\\char`_in\\char`_grids=true} and using the format introduced at the end of the inputs file.\n\n\n\\section{Tests}\n\\label{sec:tests}\nThe python script \\texttt{runTests.py} executes a convergence test on a fixed AMR hierarchy of grids and prints the results. A typical output for $\\gamma=100$ and the `exact' test problem looks like\n\\begin{verbatim}\n==================================\nConvergence test\n----------------------------------\nNx   | Max err  | L1       | L2       | Rate  || Runtime (s)  | Rate \n16   | 1.67e-04 | 5.60e-05 | 7.28e-05 | 0.000 ||   0.103      | 0.000\n32   | 5.11e-05 | 1.45e-05 | 1.92e-05 | 1.634 ||   0.066      | 0.159\n64   | 1.40e-05 | 3.66e-06 | 4.88e-06 | 1.825 ||   0.086      | 0.330\n128  | 3.66e-06 | 9.18e-07 | 1.23e-06 | 1.913 ||   0.219      | 0.633\n256  | 9.34e-07 | 2.30e-07 | 3.07e-07 | 1.959 ||   0.656      | 0.748\n512  | 2.36e-07 | 5.74e-08 | 7.67e-08 | 1.979 ||   2.555      | 0.974\n1024 | 5.93e-08 | 1.44e-08 | 1.92e-08 | 1.990 ||  11.466      | 1.122\n==================================\n\\end{verbatim}\nThe convergence of the error $\\epsilon$ between successive computations, $i$, is calculated as\n\\begin{align}\nr_N = \\frac{\\epsilon(N_x^i)/ \\epsilon(N_x^{i-1})}{N_x^i / N_x^{i-1}}.\n\\end{align}\nThe ratio between successive runtimes $\\tau$ is scaled with the number of grid cells\n\\begin{align}\nr_t = \\frac{\\tau(N_x^i) / \\tau(N_x^{i-1})}{N_x^i / (N_x^{i-1})^2}.\n\\end{align}\n\n\n\n\\section{FAS Multigrid algorithm}\n\\label{sec:algorithm}\nThe FAS approach to geometric multigrid is a well established method for dealing with nonlinear problems - see e.g. \\cite{Briggs2000, Henson2002} for a detailed introduction. The application of this method to an AMR hierarchy requires some care, as noted by \\cite{Martin1996, Martin1998} for linear multigrid problems. Here we describe the AMR FAS algorithm used in Chombo, as originally written by Mark Adams, following the format introduced in the Chombo Design document.\n\nWe wish to solve the equation\n\\begin{align}\nN^{comp} \\psi^{comp} = \\rho^{comp},\n\\end{align}\non an AMR hierarchy $\\{ \\Omega \\}_{l=0}^{l_max}$. The algorithm (\\cref{alg:AMRFAS}) proceeds in two stages. First we solve down to the coarsest AMR level, then the problem on this level is solved by standard FAS multigrid \\texttt{FASVCycle}, before completing the AMR portion of the algorithm. In the psuedocode descriptions, the restriction $R$ and interpolation $I$ operators are as described in \\cite{Chombo}. $N^{nf}(\\psi^\\ell, \\psi^{\\ell-1})$ is a two-level discretization of the nonlinear operator, whilst $N^\\ell(\\psi^\\ell)$ is a single-level discretization. The crucial difference is that the two-level version includes a reflux correction.\n\nNote that the \\texttt{relax} procedure in both \\texttt{AMRFASVCycle} and \\texttt{FASVCycle} requires a coarse-fine boundary condition. During FAS multigrid it is the actual solution, not the error, which is smoothed, so boundary conditions are not simply $\\psi=0$. A box on an initially refined level $\\ell+1$ with a coarse-fine interface will retain its coarse-fine interface throughout the algorithm, so a boundary condition must be specified for smoothing steps. This boundary condition comes from level $\\ell$, which must be appropriately coarsened. The ability to coarsen this boundary condition places a limit on the maximum depth of \\texttt{FASVCycle}.\n\n\\begin{algorithm}\n\\caption{AMR FAS algorithm. In \\texttt{relax}, $\\lambda$ is the relaxation parameter for a Gauss-Seidel scheme. Note that bottom solver in FASVCycle is simply relaxation.}\\label{alg:AMRFAS}\n\\begin{algorithmic}[1]\n\\State Residual $ = \\rho - N(\\psi)$\n\\While {$||\\text{Residual}|| > \\epsilon ||\\rho||$}\n\\State AMRFASVCycle($\\ell^{max}$)\n\\State Residual $ = \\rho - N(\\psi)$\n\\EndWhile\n\n\\Procedure{AMRFASVCycle}{level $\\ell$}\n\\If {$\\ell = \\ell^{max}$} $r^\\ell= \\rho^\\ell$ \\EndIf\n\\If {$\\ell > 0$}\n\\State relax($\\psi^\\ell$, $\\psi^{\\ell-1}$, $r^l$)\n\\State $r^{\\ell-1} = R(r^\\ell) - N^{nf}(\\psi^\\ell, \\psi^{\\ell-1})$ on $\\Omega^{\\ell-1}$\n\n\\State $r^{\\ell-1} = R(r^\\ell - N^{nf}(\\psi^\\ell, \\psi^{\\ell-1}))$ on $\\mathcal{C}(\\Omega^{\\ell})$\n\n\\State $r^{\\ell-1} = r^{\\ell-1} + N^{\\ell-1}(R(\\psi^{\\ell}))$ on $\\mathcal{C}(\\Omega^{\\ell})$\n\n\\State $\\psi^{\\ell, save} = \\psi^\\ell$ on $\\Omega^ell$\n\n\\State AMRFASVCycle($\\ell-1$)\n\n\\State $\\psi^{\\ell, corr} = I(\\psi^{\\ell-1}) - \\psi^{\\ell, save}$ on $\\Omega^ell$\n\n\\State $\\psi^{\\ell} = \\psi^\\ell + \\psi^{\\ell, corr}$ on $\\Omega^ell$\n\n\\State relax($\\psi^\\ell$, $\\psi^{\\ell-1}$, $r^l$)\n \n\\Else\n\\State FASVCycle($\\psi^0, r^0$)\n\\EndIf\n\\EndProcedure\n\n\\Procedure{FASVCycle}{$\\psi^\\ell$, $r^l$}\n\\State $\\psi^{\\ell, save} = \\psi^\\ell$\n\\If {$\\ell = \\ell^\\text{max depth}$}\n\\State relax($\\psi^\\ell$, $\\psi^{\\ell-1}$, $r^\\ell$)\n\\Else\n%\\State $\\psi^{\\ell, save} = \\psi^\\ell$\n\\State relax($\\psi^\\ell$, $\\psi_{valid}^{\\ell-1}$, $r^\\ell$)\n\\State $r^{\\ell-1} = R(r^\\ell - N^\\ell(\\psi^\\ell) + N^{\\ell-1}(R(\\psi^\\ell))$\n\\State FASVCycle($R(\\psi^{\\ell})$, $r^{\\ell-1}$)\n\\State $\\psi^\\ell = \\psi^\\ell + I(e^{\\ell-1})$\n\\State relax($\\psi^\\ell$, $\\psi_{valid}^{\\ell-1}$, $r^\\ell$)\n%\\State $e^\\ell = \\psi^\\ell - \\psi^{\\ell, save}$\n\\EndIf\n\\State $e^\\ell = \\psi^\\ell - \\psi^{\\ell, save}$\n\\EndProcedure\n\n\n\\Procedure{relax}{$\\psi^\\ell$, $\\psi^{\\ell-1}$, $r^l$}\n\\State Fill $\\psi^\\ell$ BCs using quadratic interpolation with $\\psi^{\\ell-1}$\n\\State $\\psi^\\ell = \\psi^\\ell + \\lambda (N^{nf}(\\psi^\\ell, \\psi^{\\ell-1}) - r^\\ell)$ on $\\Omega^\\ell$\n\\EndProcedure\n\n\n\n\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\\bibliographystyle{plainnat}\n\\bibliography{references}\n\n\\end{document}", "meta": {"hexsha": "f5b81bb2b73b99602fb94c81d925448d23961930", "size": 8529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "releasedExamples/AMRPoisson/execAMRFAS/doc/AMRFAS.tex", "max_stars_repo_name": "rmrsk/Chombo-3.3", "max_stars_repo_head_hexsha": "f2119e396460c1bb19638effd55eb71c2b35119e", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-02-01T20:57:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T02:57:49.000Z", "max_issues_repo_path": "releasedExamples/AMRPoisson/execAMRFAS/doc/AMRFAS.tex", "max_issues_repo_name": "rmrsk/Chombo-3.3", "max_issues_repo_head_hexsha": "f2119e396460c1bb19638effd55eb71c2b35119e", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-10-04T21:37:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T16:20:11.000Z", "max_forks_repo_path": "releasedExamples/AMRPoisson/execAMRFAS/doc/AMRFAS.tex", "max_forks_repo_name": "rmrsk/Chombo-3.3", "max_forks_repo_head_hexsha": "f2119e396460c1bb19638effd55eb71c2b35119e", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2019-01-12T23:33:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T15:19:50.000Z", "avg_line_length": 46.8626373626, "max_line_length": 659, "alphanum_fraction": 0.6806190644, "num_tokens": 2881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6940829069458706}}
{"text": "%% ---------------------------------------------------\n%% Notice that we use the \"report\" class instead of \"article\"\n%% ---------------------------------------------------\n\\documentclass{report}\n\n\\title{Project 7}\n\\author{\\textbf{Jinhao Wei}}\n\\date{\\textbf{5 March 2019}}\n\n%% ---------------------------------------------------\n%% CSBDformat specifies the format of our reports\n%% ---------------------------------------------------\n\\usepackage{634format}\n\n%% ---------------------------------------------------\n%% enumerate \n%% ---------------------------------------------------\n\\usepackage{enumerate}\n\n%% ---------------------------------------------------\n%% listings is used for including our source code in reports\n%% ---------------------------------------------------\n\\usepackage{listings}\n\\usepackage{textcomp}\n\n%% ---------------------------------------------------\n%% Packages for math environments\n%% ---------------------------------------------------\n\\usepackage{amsmath}\n\n%% ---------------------------------------------------\n%% Packages for URLs and hotlinks in the table of contents\n%% and symbolic cross references using \\ref\n%% ---------------------------------------------------\n\\usepackage{hyperref}\n\n%% ---------------------------------------------------\n%% Packages for using HOL-generated macros and displays\n%% ---------------------------------------------------\n\\usepackage{holtex}\n\\usepackage{holtexbasic}\n\\input{commands}\n\n\\begin{document}\n\n\n\\input{../HOL/HOLReports/HOLexType}\n\\input{../HOL/HOLReports/HOLnexp}\n\n%% --------------------------------------------------- the listings\n%% parameter \"language\" is set to \"ML\"\n%% ---------------------------------------------------\n\\lstset{language=ML,breaklines}\n\n\n\\maketitle{}\n\n\\begin{abstract}\n  This report is basically a summary on my attempts on Project 7, which includes proof by induction, function definition and datatype definiton. This report provides my solution on \\emph{exercise 11.6.1}, \\emph{11.6.2} and \\emph{11.6.3}. In addition, I had fine printed the corresponding datatypes and proofs and put the reports in \\emph{../HOL/HOLReports/exTypeReport.pdf} and \\emph{../HOL/HOLReports/nexpReport.pdf}.\n\\end{abstract}\n\n\\begin{acknowledgments}\n  This project follows the format and structure of \\emph{sampleTheory} provided by Professor Shiu-Kai Chin. To make it more accurate, this project mostly followed the format of one of my previous projects, which is project 5, and project 5 followed the sturcture of Professor Shiu-Kai Chin's \\emph{sampleTheory} project.\n\\end{acknowledgments}\n\n\\tableofcontents{}\n\n\\chapter{Executive Summary}\n\\label{cha:executive-summary}\n\n\\textbf{All requirements for this project are satisfied}.  In\nparticular, we defined all the datatypes and proved all the theorems in this project, pretty printed the HOL theories,\nand made use of the \\emph{EmitTeX} structure to typeset HOL theorems\nin this report.\n\n\nWe gave definitions for the following functions or datatypes\n\\begin{quote}\n  \\HOLexTypeDefinitions\n  \\HOLnexpDatatypes\n  \\HOLnexpDefinitions\n\\end{quote}\n\nand the following theorems are proved\n\\begin{quote}\n  \\HOLexTypeTheorems\n  \\HOLnexpTheorems\n\\end{quote}\n\n\\begin{description}\n\\item [Reproducibility in ML and \\LaTeX]\\ \\\\\nAll ML and \\LaTeX{} source files compile well on the environment provided by this course.\n\\end{description}\n\n\\chapter{Exercise 11.6.1}\n\\label{cha:e1161}\n\n\\section{Problem Statement}\n\\label{sec:e1161ps}\nIn this exercise, we will define a function named \\emph{APP}, according to the following formula \\HOLexTypeDefinitionsAPPXXdef and prove the theorem \n\\HOLexTypeTheoremsLENGTHXXAPP\n\nBefore we go through the following sections, we will need to print \n\\begin{lstlisting}[frame=trBL]\nopen HolKernel Parse boolLib bossLib;\nopen arithmeticTheory listTheory;\n\\end{lstlisting}\nin HOL session.\n\\section{Definition of \\emph{APP}}\n\\label{sec:e1161definition}\n\\subsection{Code for defining \\emph{APP}}\n\\label{subsec:e1161code}\nWe used the following code to define \\emph{APP}\n\\begin{lstlisting}[frame=trBL]\nval APP_def =\nDefine\n`(APP [] (l:'a list) = l) /\\\n(APP (h::(l1:'a list)) (l2:'a list) = h::(APP l1 l2))`;\n\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{subsec:e1161st}\nIf we send the above code to HOL, we will see the transcript as below:\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n \n> # # # Definition has been stored under \"APP_def\"\nval APP_def =\n   |- (!(l :'a list). APP ([] :'a list) l = l) /\\\n   !(h :'a) (l1 :'a list) (l2 :'a list). APP (h::l1) l2 = h::APP l1 l2:\n   thm\n\\end{verbatim}\n\\end{scriptsize}\n\\end{session}\n\n\\section{Proof for \\emph{LENGTH_APP}}\n\\label{sec:e1161proof}\n\\subsection{Code for Proving \\emph{LENGTH_APP}}\n\\label{subsec:e1161codeforproof}\n\\begin{lstlisting}[frame = trBL] \nval LENGTH_APP =\nTAC_PROOF(\n([], ``!(l1:'a list)(l2:'a list). LENGTH (APP l1 l2) = LENGTH l1 + LENGTH l2``),\n(Induct_on `l1` THEN\nASM_REWRITE_TAC [APP_def, LENGTH, ADD_CLAUSES] THEN\nASM_REWRITE_TAC [APP_def, LENGTH, ADD_CLAUSES]\n)\n)\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\nThe above code will give us transcript as below:\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n \n> # # # # # # # val LENGTH_APP =\n   |- !(l1 :'a list) (l2 :'a list).\n     LENGTH (APP l1 l2) = LENGTH l1 + LENGTH l2:\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\n\\chapter{Exercise 11.6.2}\n\n\\section{Problem Statement}\nIn this exercise, we defined a function \\emph{Map}, using the following formula\n\n\\HOLexTypeDefinitionsMapXXdef\n\n and proved the theorem \\emph{Map_APP}:\n\n\\HOLexTypeTheoremsMapXXAPP \n\nBefore we go through the following sections, we will need to print \n\\begin{lstlisting}[frame=trBL]\nopen HolKernel Parse boolLib bossLib;\nopen arithmeticTheory listTheory;\n\\end{lstlisting}\nin HOL session.\n\n\\section{Definition of \\emph{Map}}\n\n\\subsection{Code for Defining \\emph{Map}}\nWe use the following code to define \\emph{Map}\n\\begin{lstlisting}[frame=trBL]\nval Map_def =\nDefine\n`(Map f [] = []) /\\\n (Map f ((h:'a)::(l:'a list)) = (f h)::(Map f l))`;\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{sec:session-transcript}\nThe above code will give us transcript as below:\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # <<HOL message: inventing new type variable names: 'b>>\nDefinition has been stored under \"Map_def\"\nval Map_def =\n   |- (!(f :'a -> 'b). Map f ([] :'a list) = ([] :'b list)) /\\\n   !(f :'a -> 'b) (h :'a) (l :'a list). Map f (h::l) = f h::Map f l:\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\\section{Proof of  \\emph{Map_APP}}\n\n\\subsection{Code for Proving \\emph{Map_APP}}\nWe will use the following code to prove \\emph{Map_APP}.\n\\begin{lstlisting}[frame=trBL]\nval Map_APP =\nTAC_PROOF(\n([], ``Map f (APP (l1:'a list)(l2:'a list)) = APP (Map f l1) (Map f l2)``),\n(Induct_on`l1` THEN\n ASM_REWRITE_TAC [Map_def, APP_def] THEN\n ASM_REWRITE_TAC [APP_def, Map_def]\n));\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\nThe above code will give us transcript as below:\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # # # # <<HOL message: inventing new type variable names: 'b>>\nval Map_APP =\n   |- Map (f :'a -> 'b) (APP (l1 :'a list) (l2 :'a list)) =\n   APP (Map f l1) (Map f l2):\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\n\\chapter{Exercise 11.6.3}\n\n\n\\section{Problem Statement}\nIn this exercise, we will define our datatype \\emph{nexp}:\n\\begin{quote}\n\\HOLnexpDatatypesnexp\n\\end{quote}\n and its semantic \\emph{nexpVal}\n\n\\begin{quote}\n\\HOLnexpDefinitions\n\\end{quote}\n then we will prove several theorems concerning the datatype, including\n\\begin{quote}\n\\HOLnexpTheorems\n\\end{quote}\n\nBefore we go through the following sections, we will need to enter the code below in HOL window.\n\\begin{lstlisting}[frame=trBL]\nopen HolKernel Parse boolLib bossLib;\nopen TypeBase boolTheory arithmeticTheory\n\\end{lstlisting}\n\n\\section{Definition of \\emph{nexp}}\n\n\\subsection{Code for Defining \\emph{nexp}}\n\n\\begin{lstlisting}[frame=trBL]\nval _ = Datatype\n`nexp = Num num | Add nexp nexp | Sub nexp nexp | Mult nexp nexp`;\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{sec:session-transcript}\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n \n> # <<HOL message: Defined type: \"nexp\">>\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\\section{Definition of \\emph{nexpVal}}\n\n\\subsection{Code for Defining \\emph{nexpVal}}\n\\begin{lstlisting}[frame=trBL]\nval nexpVal_def =\nDefine\n`\n(nexpVal (Num num) = num)/\\\n(nexpVal (Add f1 f2) = (nexpVal f1) + (nexpVal  f2))/\\\n(nexpVal (Sub f1 f2) = (nexpVal f1) - (nexpVal  f2))/\\\n(nexpVal (Mult f1 f2) = (nexpVal f1) * (nexpVal  f2))\n`\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # # # # # Definition has been stored under \"nexpVal_def\"\nval nexpVal_def =\n   |- (!(num :num). nexpVal (Num num) = num) /\\\n   (!(f1 :nexp) (f2 :nexp).\n      nexpVal (Add f1 f2) = nexpVal f1 + nexpVal f2) /\\\n   (!(f1 :nexp) (f2 :nexp).\n      nexpVal (Sub f1 f2) = nexpVal f1 - nexpVal f2) /\\\n   !(f1 :nexp) (f2 :nexp).\n     nexpVal (Mult f1 f2) = nexpVal f1 * nexpVal f2:\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\n\n\\section{Proof of \\emph{Add_0}}\n\n\n\\subsection{Code for Proving \\emph{Add_0}}\n\\begin{lstlisting}[frame=trBL]\nval Add_0 =\nTAC_PROOF(\n([], ``!f.nexpVal (Add (Num 0) f) = nexpVal f``),\nInduct_on `f` THEN\nASM_REWRITE_TAC [ADD] THEN\nREWRITE_TAC [nexpVal_def] THEN\nREWRITE_TAC [ADD] THEN\nREPEAT (PROVE_TAC [ADD, SUB, MULT, nexpVal_def])\n);\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{sec:session-transcript-1}\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # # # # # # val Add_0 =\n   |- !(f :nexp). nexpVal (Add (Num (0 :num)) f) = nexpVal f:\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\\section{Proof of \\emph{Add_SYM}}\n\n\n\\subsection{Code for Proving \\emph{Add_SYM}}\n\\begin{lstlisting}[frame=trBL]\nval Add_SYM =\nTAC_PROOF(\n([], ``!f1 f2. nexpVal (Add f1 f2) = nexpVal (Add f2 f1)``),\nREWRITE_TAC [ADD, nexpVal_def] THEN\nREWRITE_TAC [Once ADD_COMM]\n);\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{sec:session-transcript-1}\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # # # val Add_SYM =\n   |- !(f1 :nexp) (f2 :nexp). nexpVal (Add f1 f2) = nexpVal (Add f2 f1):\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\\section{Proof of \\emph{Sub_0}}\n\n\n\\subsection{Code for Proving \\emph{Sub_0}}\n\\begin{lstlisting}[frame=trBL]\nval Sub_0 =\nTAC_PROOF(\n([], ``!f. (nexpVal (Sub (Num 0) f ) = 0)/\\(nexpVal (Sub f (Num 0)) = nexpVal f)``),\nREWRITE_TAC [SUB, nexpVal_def] THEN\nREWRITE_TAC [SUB_0]\n);\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{sec:session-transcript-1}\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # # # val Sub_0 =\n   |- !(f :nexp).\n     (nexpVal (Sub (Num (0 :num)) f) = (0 :num)) /\\\n     (nexpVal (Sub f (Num (0 :num))) = nexpVal f):\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\\section{Proof of \\emph{Mult_ASSOC}}\n\n\n\\subsection{Code for Proving \\emph{Mult_ASSOC}}\n\\begin{lstlisting}[frame=trBL]\nval Mult_ASSOC =\nTAC_PROOF(\n([], ``!f1 f2 f3. nexpVal (Mult f1 (Mult f2 f3)) = nexpVal (Mult (Mult f1 f2) f3)``),\nREWRITE_TAC [nexpVal_def, MULT, MULT_ASSOC]\n);\n\\end{lstlisting}\n\n\\subsection{Session Transcript}\n\\label{sec:session-transcript-1}\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n  \\begin{scriptsize}\n\\begin{verbatim}\n\n> # # # # val Mult_ASSOC =\n   |- !(f1 :nexp) (f2 :nexp) (f3 :nexp).\n     nexpVal (Mult f1 (Mult f2 f3)) = nexpVal (Mult (Mult f1 f2) f3):\n   thm\n\\end{verbatim}\n  \\end{scriptsize}\n\\end{session}\n\n\n\n\n%% ------------------------------------------\n%% Change to letters for appendix\n%% ------------------------------------------\n\n%% ------------------------------------------\n%% this restarts the section numbering\n%% ------------------------------------------\n\\appendix{} \n\n\n%% ------------------------------------------\n% label using capital letters\n%% ------------------------------------------\n\\renewcommand{\\thechapter}{\\Alph{chapter}} \n\n\\chapter{Source Code for exTypeScript.sml}\n\\label{cha:source-code-sample}\n\nThe following code is from \\emph{exTypeScript.sml}, which is located\nin directory \"../HOL/\" \n\\lstinputlisting{../HOL/exTypeScript.sml}\n\n\\chapter{Source Code for nexpScript.sml}\n\\label{cha:source-code-sample}\n\nThe following code is from \\emph{nexpScript.sml}, which is located\nin directory \"../HOL/\"\n\\lstinputlisting{../HOL/nexpScript.sml}\n\n\\end{document}\n", "meta": {"hexsha": "9131bda7a4b6cad7792fba4265f36c17e3b42e5d", "size": 12634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW7/LaTeX/HW7.tex", "max_stars_repo_name": "jwei15/CIS-634", "max_stars_repo_head_hexsha": "4c6d063b40719371e20fac49671a5af177c3750d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW7/LaTeX/HW7.tex", "max_issues_repo_name": "jwei15/CIS-634", "max_issues_repo_head_hexsha": "4c6d063b40719371e20fac49671a5af177c3750d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW7/LaTeX/HW7.tex", "max_forks_repo_name": "jwei15/CIS-634", "max_forks_repo_head_hexsha": "4c6d063b40719371e20fac49671a5af177c3750d", "max_forks_repo_licenses": ["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.4863731656, "max_line_length": 418, "alphanum_fraction": 0.6455596011, "num_tokens": 3813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6940532024468464}}
{"text": "\\subsection{2n Points}\t\n\t\n\t\\prob{https://artofproblemsolving.com/community/c5h1434584p8117190}{USAMO 2017 P4}{M}{Let $ P_1 $ , $ P_2 $ , $ \\dots $ , $ P_{2n} $ be $ 2n $ distinct points on the unit circle $ x^2+y^2=1 $ , other than $ (1,0) $. Each point is colored either red or blue, with exactly $ n $ red points and $ n $ blue points. Let $ R_1 $ , $ R_2 $ , $ \\dots $ , $ R_n $ be any ordering of the red points. Let $ B_1 $ be the nearest blue point to $ R_1 $ traveling counterclockwise around the circle starting from $ R_1 $. Then let $ B_2 $ be the nearest of the remaining blue points to $ R_2 $ travelling counterclockwise around the circle from $ R_2 $, and so on, until we have labeled all of the blue points $ B_1, \\dots, B_n $. Show that the number of counterclockwise arcs of the form $ R_i \\to B_i $ that contain the point $ (1,0) $ is independent of the way we chose the ordering $ R_1, \\dots, R_n $ of the red points.}\\label{problem:induction_type1_15}\n\t\n\t\t\\solu{As the statement is saying that the condition is true for every positive integer $ n $, can we try induction? Which part of the condition makes the problem challenging? Obviously the circle condition and the $ (1, 0) $ point. So Lets remove a ``problematic'' pair $ R_t, B_t $. We encounter some problems, but we can pull it out of there.}\n\t\n\t\n\t\n\t\n\t\\prob{}{SMMC}{}{Let $ 2n $ points be uniformly distributed on a circle. Paint $ n $ of them red, and $ n $ of them blue. Let $ B $ be the list of distances between each pair of blue points. Let $ R $ be the list of distances between each pair of blue points. Prove that $ A=B $}\n\t\n\t\n\t\\prob{www.hehe.com}{Putnam 1979}{E}{Let $ A $ be a set of $ 2n $ points in the plane, no three of which are collinear, $ n $ of them are colored red and the other blue. Prove that there are $ n $ line segments, no two with a point in common, such that the endpoints of each segment are points of $ A $ having different colors.}\\label{problem:convex_hull_1}\\label{Putnam_1979}\n\t\n\t\t\\solu{Strong induction, and a way to divide the points into two sets with the same number of red and blue points. Travel through the points around a certain point and keep track of the number of red and blue points.}\n\t\t\n\t\t\n\t\t\n\t\\prob{https://artofproblemsolving.com/community/c6h34319p213018}{USAMO 2005 P5}{E}{Let $n$ be an integer greater than 1. Suppose $2n$ points are given in the plane, no three of which are collinear. Suppose $n$ of the given $2n$ points are colored blue and the other $n$ colored red. A line in the plane is called a balancing line if it passes through one blue and one red point and, for each side of the line, the number of blue points on that side is equal to the number of red points on the same side. Prove that there exist at least two balancing lines.}\\label{problem:convex_hull_3}\n\t\t\n\t\t\\solu{Using the same idea as in \\hrf{Putnam_1979}{this} problem. }\n\t\t", "meta": {"hexsha": "117ece249af6a84afc3ede95a376c220a04bbbb2", "size": 2883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/subsec_1_2n_points.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/subsec_1_2n_points.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/subsec_1_2n_points.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": 131.0454545455, "max_line_length": 945, "alphanum_fraction": 0.7197363857, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619263765706, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6940531915344902}}
{"text": "\\chapter{Structured Matrix Types}\n\n\\NOTE{Structured matrix types are experimental in {\\ViennaCLversion}. Interface changes as well as considerable performance improvements may be included in\nfuture releases!}\n\nThere are a number of structured dense matrices for which some algorithms such as matrix-vector products can be computed with much lower computational effort\nthan for the general dense matrix case. In the following, four structured dense matrix types included in {\\ViennaCL} are discussed. \nExample code can be found in \\lstinline|examples/tutorial/structured-matrices.cpp|.\n\n\\section{Circulant Matrix}\nA circulant matrix is a matrix of the form\n\\begin{align*}\n \\left( \\begin{array}{ccccc}\n         c_0 & c_{n-1} & \\ldots & c_2 & c_1 \\\\\n         c_1 & c_0 & c_{n-1} & & c_2 \\\\\n         \\vdots & c_1 & c_0 & \\ddots & \\vdots \\\\\n         c_{n-2} & & \\ddots & \\ddots & c_{n-1} \\\\\n         c_{n-1} & c_{n-2} & \\hdots & c_1 & c_0 \\\\\n        \\end{array} \\right)\n\\end{align*}\nand available in {\\ViennaCL} via\n\\begin{lstlisting}\n #include \"viennacl/circulant_matrix.hpp\"\n\n std::size_t s = 42;\n viennacl::circulant_matrix circ_mat(s, s);\n\\end{lstlisting}\nThe \\lstinline|circulant_matrix| type can be manipulated in the same way as the dense matrix type \\lstinline|matrix|. Note that writing to a single element of\nthe matrix is structure-preserving, e.g.~changing \\lstinline|circ_mat(1,2)| will automatically update \\lstinline|circ_mat(0,1)|, \\lstinline|circ_mat(2,3)| and\nso on.\n\n\n\\section{Hankel Matrix}\nA Hankel matrix is a matrix of the form\n\\begin{align*}\n \\left( \\begin{array}{cccc}\n         a & b & c & d \\\\\n         b & c & d & e \\\\\n         c & d & e & f \\\\\n         d & e & f & g \\\\\n        \\end{array} \\right)\n\\end{align*}\nand available in {\\ViennaCL} via\n\\begin{lstlisting}\n #include \"viennacl/hankel_matrix.hpp\"\n\n std::size_t s = 42;\n viennacl::hankel_matrix hank_mat(s, s);\n\\end{lstlisting}\nThe \\lstinline|hankel_matrix| type can be manipulated in the same way as the dense matrix type \\lstinline|matrix|. Note that writing to a single element of\nthe matrix is structure-preserving, e.g.~changing \\lstinline|hank_mat(1,2)| in the example above will also update \\lstinline|hank_mat(0,3)|,\n\\lstinline|hank_mat(2,1)| and\n\\lstinline|hank_mat(3,0)|.\n\n\\section{Toeplitz Matrix}\nA Toeplitz matrix is a matrix of the form\n\\begin{align*}\n \\left( \\begin{array}{cccc}\n         a & b & c & d \\\\\n         e & a & b & c \\\\\n         f & e & a & b \\\\\n         g & f & e & a \\\\\n        \\end{array} \\right)\n\\end{align*}\nand available in {\\ViennaCL} via\n\\begin{lstlisting}\n #include \"viennacl/toeplitz_matrix.hpp\"\n\n std::size_t s = 42;\n viennacl::toeplitz_matrix toep_mat(s, s);\n\\end{lstlisting}\nThe \\lstinline|toeplitz_matrix| type can be manipulated in the same way as the dense matrix type \\lstinline|matrix|. Note that writing to a single element of\nthe matrix is structure-preserving, e.g.~changing \\lstinline|toep_mat(1,2)| in the example above will also update \\lstinline|toep_mat(0,1)| and\n\\lstinline|toep_mat(2,3)|.\n\n\n\\section{Vandermonde Matrix}\nA Vandermonde matrix is a matrix of the form\n\\begin{align*}\n \\left( \\begin{array}{ccccc}\n         1 & \\alpha_1 & \\alpha_1^2 & \\ldots & \\alpha_1^{n-1} \\\\\n         1 & \\alpha_2 & \\alpha_2^2 & \\ldots & \\alpha_2^{n-1} \\\\\n         1 & \\vdots & \\vdots & \\vdots \\\\\n         1 & \\alpha_m & \\alpha_m^2 & \\ldots & \\alpha_m^{n-1} \\\\\n        \\end{array} \\right)\n\\end{align*}\nand available in {\\ViennaCL} via\n\\begin{lstlisting}\n #include \"viennacl/vandermonde_matrix.hpp\"\n\n std::size_t s = 42;\n viennacl::vandermonde_matrix vand_mat(s, s);\n\\end{lstlisting}\nThe \\lstinline|vandermonde_matrix| type can be manipulated in the same way as the dense matrix type \\lstinline|matrix|, but restrictions apply. For\nexample, the addition or subtraction of two Vandermonde matrices does not yield another Vandermonde matrix. Note that writing to a single element of\nthe matrix is structure-preserving, e.g.~changing \\lstinline|vand_mat(1,2)| in the example above will automatically update \\lstinline|vand_mat(1,3)|,\n\\lstinline|vand_mat(1,4)|, etc.\n\n", "meta": {"hexsha": "39bc3bc2e5e2a26dfd8cbb2a412dd5a0a2adbc8f", "size": 4075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/manual/structured-matrices.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/structured-matrices.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/structured-matrices.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": 41.1616161616, "max_line_length": 158, "alphanum_fraction": 0.6934969325, "num_tokens": 1262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6940075065525418}}
{"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{amsfonts}\n\\usepackage{enumerate}\n\\usepackage{tikz}\n\\usetikzlibrary{calc}\n% Node styles\n\\tikzset{\n    % Two node styles for game trees: solid and hollow\n    solid node/.style={circle,draw,inner sep=1.5,fill=black}, hollow node/.style={circle,draw,inner sep=1.5}\n    }\n\n\\title{\\textbf{Week 8.} Games with incomplete information}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\n\\subsection*{Bonus 1: Volunteer's dilemma with correlated costs}\n\nConsider the volunteer's dilemma with payoffs\n\n\\begin{equation*}\n    \\begin{blockarray}{ccc}\n        & C & D \\\\\n        \\begin{block}{c(cc)}\n            C & (1 - c_1, 1 - c_2) & (1 - c_1, 1) \\\\\n            D & (1, 1 - c_2) & (0, 0) \\\\\n        \\end{block}\n    \\end{blockarray}\n\\end{equation*}\n\nSuppose \\(c_1\\) is randomly drawn from \\([0, 2]\\) uniformly. For \\(c_2\\) assume\nthat it is (anti-) correlated, such that \\(c_1 + c_2 = 2\\) is always satisfied\n(whenever player 1 has a comparably high cost they know player 2 has a\ncomparable low cost). \\textbf{Show that the following strategies are a Bayesian Nash\nequilibrium.}\n\n\\begin{equation*}\n    s^{(1)}(c_1) = \n    \\begin{cases}\n        C,& \\text{if } c_1 \\leq 1\\\\\n        D,              & \\text{if } c_1 > 1\n    \\end{cases} \\qquad\n    s^{(2)}(c_2) = \n    \\begin{cases}\n        C,& \\text{if } c_2 < 1\\\\\n        D,              & \\text{if } c_2 \\geq 1\n    \\end{cases}\n\\end{equation*}\n\n\\underline{\\textbf{Bonus question:}} Are there any other Bayesian Nash equilibria?\n\n[Hint: To show that (\\(s^{(1)}\\), \\(s^{(2)}\\)) is a Bayesian Nash equilibrium,\nconsider player 1. Show that for the three cases $c_1 < 1$, $c_1 > 1$ and $c_1 =\n1$, the player has no reason to deviate from \\(s^{(1)}\\). Do the same for player\n2.]\n\n\\subsection*{Bonus 2: Second-price sealed bid auction}\n\nAn item is sold to the highest bid among \\(n\\) players. The players' values for\nthe item, \\(\\mathbf{v}^{(i)}\\), are uniformly and independently drawn from \\([0, 1]\\).\nThe players' strategy is to choose a bid, depending on how much the item would be\nworth to them, \\(s^{(i)}: \\mathbf{v}^{(i)} \\rightarrow b^{(i)}\\).\n\nThe player with the highest bid wins the auction. However, they only have to\npay the second-highest bid.\n\n\\begin{equation*}\n\\text{Payoff: }    \\pi^{(i)} (b^{(i)}, b^{(-i)}) = \n    \\begin{cases}\n        \\mathbf{v}^{(i)} - \\max\\limits_{j \\neq i}(b^{(j)}), & \\text{if } b^{(i)} > b^{(j)} \\ \\forall \\ j \\neq i \\\\\n        (\\mathbf{v}^{(i)} - \\max\\limits_{j \\neq i}(b^{(j)})) / K, & \\text{if } b^{(i)} = \\max\\limits_{j \\neq i} (b^{(j)}) \\ \\& \\ K \\text{number of highest biddings}\\\\\n        0,              & \\text{otherwise}.\n    \\end{cases}\n\\end{equation*}\n\n\\textbf{Show that the strategy \\(b^{(i)} = v^{(i)}\\) weakly dominates any other\nstrategy.}\n\n[Hint: Consider 3 cases. The first case is that \\(\\textbf{v}^{(i)} > \\max\\limits_{j \\neq i} (b^{(j)})\\).\nShow that bidding \\(b^{(i)} \\neq \\textbf{v}^{(i)}\\) never yields a higher payoff than bidding\n\\(b^{(i)} = \\textbf{v}^{(i)}\\), but sometimes the payoff is worse. Similar for the cases\n\\(\\textbf{v}^{(i)} = \\max\\limits_{j \\neq i} (b^{(j)})\\) and \\(\\textbf{v}^{(i)} < \\max\\limits_{j \\neq i} (b^{(j)})\\).]\n\n\n\\subsection*{Exercise 1: Revenue equivalence theorem}\n\nConsider an auction between two players with valuations for an item again uniformly\ndrawn from \\([0, 1]\\). We already know the equilibria of the\n\n\n\\begin{itemize}\n    \\item first-price sealed bid auction: \\(b ^ {(i)} =  \\frac{1}{2} \\textbf{v}^{(i)}\\) (Example 4.5), and the\n    \\item second-price sealed bid auction: \\(b ^ {(i)} =  \\textbf{v}^{(i)}\\) (Bonus 2).\n\\end{itemize}\n\n\\textbf{Show that the expected revenue for the seller (the price the winning bidder\nhas to pay) is the same for both auctions.}\n\n[Hint: Suppose without loss of generality that the player with the highest valuation assigns a value\n\\(\\textbf{v}\\) to the item. Show that the expected revenue of the seller is\n\\(\\frac{\\textbf{v}}{2}\\), in both cases.]\n\n\n\\subsection*{Exercise 2: Pooling equilibrium of the IMPRS game}\n\nRevisit the IMPRS game from Example 4.8.\n\n\\begin{figure*}[!htbp]\n    \\begin{center}\n    \\begin{tikzpicture}[scale=1.5,font=\\footnotesize] % Specify spacing for each level of the tree\n        \\tikzstyle{level 1}=[level distance=15mm,sibling distance=45mm] \\tikzstyle{level 2}=[level distance=15mm,sibling distance=15mm]\n        \\tikzstyle{level 3}=[level distance=16mm]\n        % The Tree\n        \\node(0)[solid node,label=above:{Nature}]{}\n        child{node(1)[solid node]{}\n        child{node[hollow node,label=below:{$(0, 0)$}]{} edge from parent node[above, rotate=65]{Not Apply}} \n        child{node[solid node]{} child{node(3)[hollow node, label=below:{$(-1, 0)$}]{} edge from parent node[above, rotate=65, xshift=-0.2cm]{Don't accept}} \n        child{node[hollow node, label=below:{$(-1, -3)$}]{} edge from parent node[above, rotate=-60]{Accept}} \n        edge from parent node[above, rotate=-60]{Apply}} \n        edge from parent node[left,xshift=-3]{bad $(\\frac{1}{2})$}\n            }\n        child{node(2)[solid node]{}\n        child{node[solid node]{}  child{node(4)[hollow node, label=below:{$(-1, 0)$}]{} edge from parent node[above, rotate=65, xshift=-0.2cm]{Don't accept}} \n        child{node[hollow node, label=below:{$(3, 2)$}]{} edge from parent node[above, rotate=-60]{Accept}} \n        edge from parent node[above, rotate=65]{Apply}} \n        child{node[hollow node,label=below:{$(0, 0)$}]{} edge\n        from parent node[above, rotate=-60]{Not apply}} edge from parent node[right,xshift=3]{good$(\\frac{1}{2})$}\n        };\n        % information set\n    \\node at ($(1)!.5!(2)$) {Student};\n    \\node at (0, -3) {MPI};\n    \\draw[dashed,rounded corners=10]($(2) + (-.4,-1.33)$)rectangle($(3) +(.4, 1.4)$); % specify mover at 2nd information set\n    \\end{tikzpicture}\n\\end{center}\n\\end{figure*}\n\n\\textbf{Show that if the players use the following strategies, players have no incentive to\ndeviate.}\n\n\\begin{align*}\n    s^{(1)}(\\theta) & = \\text{Not apply } \\ \\forall \\ \\theta \\in \\{\\text{good, bad}\\}, \\\\\n    s^{(2)} & = \\text{Don't accept}.\n\\end{align*}\n\n[Hint: For this, note that in this equilibrium, no student ever applies. So if MPI\nobserves an application, it does not know from the student's strategies which\nof the student applied. Assume that MPI thinks\n\\(\\mathbb{P}(\\text{good} \\mid \\text{Apply}) = \\frac{1}{2}\\).]\n\\end{document}\n\n", "meta": {"hexsha": "6c591440c5bfb91475fdffe5c39e34775e0c7dd9", "size": 6626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w8.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/w8.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/w8.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": 40.4024390244, "max_line_length": 166, "alphanum_fraction": 0.6320555388, "num_tokens": 2235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435030872968, "lm_q2_score": 0.8991213759183765, "lm_q1q2_score": 0.69398099248951}}
{"text": "\n\\section{Equality of stacks}\n\\Label{sec:stack-equality}\n\nDefining equality of instances of non-trivial data types, in\nparticular in object-oriented languages, is not an easy task.\n%\nThe book \\emph{Programming in Scala}\\cite[Chapter~28]{OderskyEtAl2008} \ndevotes to this topic a whole chapter of more than twenty pages.\n%\nIn the following two sections we give a few hints how \\acsl\nand \\framac can help to\ncorrectly define equality for a simple data type.\n\nWe consider two stacks as equal if they have the same size and if they contain the same objects.\n%\nTo be more precise, let~\\inl{s} and~\\inl{t} two pointers of type \\stacktype,\nthen we define the predicate \\StackEqual as in the following listing.\n\n\\input{Listings/Stack.acsl.tex}\n\nOur use of labels in this listing makes\nthe specification somewhat hard to read (in particular in the last line\nwhere we reuse the predicate \\logicref{Equal}.\n%\nHowever, this definition of \\StackEqual will allow us later to compare \nthe same stack object at different points of a program.\n%\nThe logical expression \\inl{StackEqual\\{A,B\\}(s,t)}\nreads informally as: \n{The stack object \\inl{*s} at program point \\inl{A}\nequals the stack object \\inl{*t} at program point \\inl{B}}.\n\nThe reader might wonder why we exclude the capacity of a stack\ninto the definition of stack equality.\nThis approach can be motivated with the behavior of the method\n\\inl{capacity} of the class \\inl{std::vector<T>}.\nThere, equal instances of type \\inl{std::vector<T>} may very well \nhave different capacities.\\footnote{\nSee \\url{http://www.cplusplus.com/reference/vector/vector/capacity}\n}\n\nIf equal stacks can have different capacities then, according to our\ndefinition of the predicate \\logicref{StackFull}, \nwe can have to equal stacks where one is full and the other one is not.\n\nA finer, but very important point in our specification of equality\nof stacks is that the elements of the arrays \\inl{s->obj} and \\inl{t->obj}\nare compared only up to \\inl{s->size} and \\emph{not} up  to\n\\inl{s->capacity}.\nThus the two stacks \\inl{s} and \\inl{t} in Figure~\\ref{fig:equal-stacks}\nare considered\nequal although there is are obvious differences in their internal arrays.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.75\\linewidth]{Figures/stack12.pdf}\n\\caption{\\Label{fig:equal-stacks} Example of two equal stacks}\n\\end{figure}\n\n\\FloatBarrier\n\nIf we define an equality relation $(=)$ of objects for a data\ntype such as \\stacktype,\nwe have to make sure that the following rules hold.\n\n\\begin{subequations}\n\\Label{eq:equivalence-relation}\n\\begin{align}\n   \\text{reflexivity}\\qquad && \\forall s \\in S&: s = s,\\\\\n   \\text{symmetry}\\qquad &&    \\forall s,t \\in S&: s = t \\implies t = s,\\\\\n   \\text{transitivity}\\qquad &&    \\forall s,t,u \\in S&: s = t \\land t = u \\implies s = u.\n\\end{align}\n\\end{subequations}\n\n\nAny relation that satisfies the conditions~\\eqref{eq:equivalence-relation}\nis referred to as an \\emph{equivalence relation}.\n%\nThe mathematical set of all instances that are considered equal to\nsome given instance \\inl{s} is called the equivalence class of \\inl{s}\nwith respect to that relation.\n\nOur formalization of \\logicref{StackEquality} shows \nthese three rules for the relation \\StackEqual;\nit can be automatically verified that they are a consequence of the\ndefinition of \\StackEqual.\n\nThe two stacks in Figure~\\ref{fig:equal-stacks} show that\nan equivalence class of \\StackEqual\ncan contain more than one element.\\footnote{\n    This is a common situation in mathematics. For example,\n    the equivalence class of\n    the rational number $\\frac{1}{2}$ contains infinitely many elements,\n    viz.\\ $\\frac{1}{2},\n    \\frac{2}{4}, \\frac{7}{14}, \\ldots$.\n}\nThe stacks \\inl{s} and \\inl{t} in Figure~\\ref{fig:equal-stacks}\nare also referred to as two \\emph{representatives} of the\nsame equivalence class.\nIn such a situation, the question arises whether a function\nthat is defined on\na set with an equivalence relation can be defined in such a\nway that its definition\nis \\emph{independent of the chosen representatives}.\\footnote{\n    This is why mathematicians know that\n    $\\frac{1}{2} + \\frac{3}{5}$\n    equals $\\frac{7}{14} + \\frac{3}{5}$.\n}\nWe ask, in other words, whether the function is \\emph{well-defined}\non the set of all equivalence classes of the relation \\StackEqual.\\footnote{\n  See \\url{http://en.wikipedia.org/wiki/Well-definition}.\n}\nThe question of well-definition\nwill play an important role when verifying the functions of\nthe \\stacktype (see \\S\\ref{sec:stack-functions}).\n\n", "meta": {"hexsha": "1028949e73b50802db76c5750ba5cdd7765010dd", "size": 4526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/stack/stack-equality.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/stack/stack-equality.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/stack/stack-equality.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 38.3559322034, "max_line_length": 96, "alphanum_fraction": 0.7520989837, "num_tokens": 1221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434925908525, "lm_q2_score": 0.8991213867309121, "lm_q1q2_score": 0.6939809913975178}}
{"text": "\\subsection{Density Estimation}\n\\label{sec:density}\n\nWe use a histogram to estimate the merger rate as a function of $\\mathcal{M}_c$, using Knuth's rule to determine the bin size (See Figure \\ref{fig:chirp}). Since we are interested in the intrinsic rate, not just that of detected events, we weigh each point by the inverse of the spacetime volume in which we are sensitive to it, $w = 1 / VT$. Binaries with a higher chirp mass are easier to detect, so we do not want to count them as heavily. For a given chirp mass, we are sensitive out to a distance\n%\n\\begin{equation}\n  D(\\mathcal{M}_c) =\n  \\SI{200}{\\mega\\parsec} \\qty( \\mathcal{M}_c / \\SI{1.2}{\\Msun} )^{5/6}\n\\end{equation}\n%\nwhich corresponds to a volume\n%\n\\begin{equation}\n  V(\\mathcal{M}_c) = \\frac{4}{3} \\pi D^3(\\mathcal{M}_c).\n\\end{equation}\n%\nMultiplying this by the time spent observing, $T = \\SI{0.6}{yr}$, gives us the spacetime volume $V(\\mathcal{M}_c) T$.\n\nTo obtain uncertainties in our histogram, we take the square root of the sum-of-squares of the weights within that bin, i.e.\n%\n\\begin{equation}\n  \\sigma_k = \\sqrt{\\sum_i w_i^2},\n\\end{equation}\n%\nwhich was taken from \\textcite{weighted-hist}. This reduces to $\\sqrt{N}$ in the case of an unweighted histogram, as $w_i = 1$, so $\\sum_i w_i^2 = N$.\n\nWe also over-plot a pure power law. To do this, we employ Bayesian linear regression, fitting a straight line to $\\log r$ versus $\\log \\mathcal{M}_c$, and transforming back to linear space. This is also shown in Figure \\ref{fig:chirp}.\n\n\\begin{figure*}[ht]\n  \\centering\n  \\begin{subfigure}[c]{\\textwidth}\n    \\centering\n    \\includegraphics[height=0.4\\textheight]{img/chirp-mass-distribution}\n    \\caption{}\n    \\label{fig:chirp-linear}\n  \\end{subfigure}\n\n  \\begin{subfigure}[c]{\\textwidth}\n    \\centering\n    \\includegraphics[height=0.4\\textheight]{img/chirp-mass-log-distribution}\n    \\caption{}\n    \\label{fig:chirp-log}\n  \\end{subfigure}\n\n  \\caption{Estimated rate of compact binary mergers, based on 5000 synthetic observations. Rate is shown in (\\subref{fig:chirp-linear}) linear and (\\subref{fig:chirp-log}) log scale. Blue line is weighted histogram fit. Red curve is power law fit. Shaded regions are 1-$\\sigma$ error bars. Vertical dashed line is boundary between events with counterparts and without.}\n  \\label{fig:chirp}\n\\end{figure*}", "meta": {"hexsha": "8eb02ec3dc59e2e1de8028ecb89bd21d30ceb75b", "size": 2318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "subsec_density_estimation.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": "subsec_density_estimation.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": "subsec_density_estimation.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": 49.3191489362, "max_line_length": 501, "alphanum_fraction": 0.7226056946, "num_tokens": 715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.7718434925908524, "lm_q1q2_score": 0.6939809820087343}}
{"text": "The properties desired of CBC Casper broadly fall into two categories: 1) safety and 2) non-triviality. Definition of what these two things are. Some intuition on why these two things are important. We show below our incremental approach to proving these properties, starting from a definition of CBC Casper in terms of a state transition system with a reflexive and transitive reachability relation, also known in rewrite logic literature as a partial order and in modal logic literature as a KT4 Kripke model.\n\\subsection{Partial order}\n\\begin{lstlisting}\nClass PartialOrder :=\n{ A : Type;\n\tA_eq_dec : forall (a1 a2 : A), {a1 = a2} + {a1 <> a2};\n\tA_inhabited : exists (a0 : A), True;\n\tA_rel : A -> A -> Prop;\n\tA_rel_refl :> Reflexive A_rel;\n\tA_rel_trans :> Transitive A_rel;\n}.\n\\end{lstlisting}\nAt this level, we are able to derive all of the safety properties desired of CBC Casper, namely:\n\\begin{lstlisting}\nTheorem pair_common_futures '{CBC_protocol_eq}:\nforall s1 s2 : pstate,\n(equivocation_weight (state_union s1 s2) <= proj1_sig t)%R ->\nexists s : pstate, pstate_rel s1 s /\\ pstate_rel s2 s.\n\nTheorem n_common_futures '{CBC_protocol_eq} :\nforall ls : list pstate,\n(equivocation_weight (fold_right state_union state0 (map (fun ps => proj1_sig ps) ls)) <= proj1_sig t)%R ->\nexists ps : pstate, Forall (fun ps' => pstate_rel ps' ps) ls.\n\nTheorem pair_consistency_prot '{CBC_protocol_eq} :\nforall s1 s2 : pstate,\n(equivocation_weight (state_union s1 s2) <= proj1_sig t)%R ->\nforall P,\n~ (decided P s1 /\\ decided (not P) s2).\n\nTheorem n_consistency_prot '{CBC_protocol_eq} :\nforall ls : list pstate,\n(equivocation_weight (fold_right state_union state0 (map (fun ps => proj1_sig ps) ls)) <= proj1_sig t)%R ->\nstate_consistency ls.\n\nTheorem n_consistency_consensus '{CBC_protocol_eq} :\nforall ls : list pstate,\n(equivocation_weight (fold_right state_union state0 (map (fun ps => proj1_sig ps) ls)) <= proj1_sig t)%R ->\nconsensus_value_consistency ls.\n\\end{lstlisting}\nThese results correspond to Theorems X - Y in \\cite{CBCfull}.\n\\newline\n\n\n\\subsection{Partial order with non-local confluence}\nIn order to prove non-triviality properties, we additionally require  that our partial order possess certain confluence properties. In fact, we find that non-triviality as defined in \\cite{CBCfull} directly captures the notion of non-local confluence in state transition systems, defined abstractly as follows:\n\n\\begin{lstlisting}\nClass PartialOrderNonLCish '{PartialOrder} :=\n{ no_local_confluence_ish : exists (a a1 a2 : A),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tA_rel a a1 /\\ A_rel a a2 /\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t~ exists (a' : A), A_rel a1 a' /\\ A_rel a2 a';\n}.\n\\end{lstlisting}\n\n\\subsection{Abstract protocol}\nTo provide a richer, protocol-specific language to describe our desired properties, we give an abstract type class from which we can generalize a partial order, but which contains information specific to consensus protocols, including types for validators, consensus values, states, and an abstract, total estimator function.\n\\begin{lstlisting}\nClass CBC_protocol_eq :=\n{\nconsensus_values : Type;\nabout_consensus_values : StrictlyComparable consensus_values;\nvalidators : Type;\nabout_validators : StrictlyComparable validators;\nweight : validators -> {r | (r > 0)%R};\nt : {r | (r >= 0)%R};\nsuff_val : exists vs, NoDup vs /\\ ((fold_right (fun v r => (proj1_sig (weight v) + r)%R) 0%R) vs > (proj1_sig t))%R;\nstate : Type;\nabout_state : StrictlyComparable state;\nstate0 : state;\nstate_eq : state -> state -> Prop;\nstate_union : state -> state -> state;\nstate_union_comm : forall s1 s2, state_eq (state_union s1 s2) (state_union s2 s1);\nreach : state -> state -> Prop;\nreach_refl : forall s, reach s s;\nreach_trans : forall s1 s2 s3, reach s1 s2 -> reach s2 s3 -> reach s1 s3;\nreach_union : forall s1 s2, reach s1 (state_union s1 s2);\nreach_morphism : forall s1 s2 s3, reach s1 s2 -> state_eq s2 s3 -> reach s1 s3;\nE : state -> consensus_values -> Prop;\nestimator_total : forall s, exists c, E s c;\nprot_state : state -> Prop;\nabout_state0 : prot_state state0;\nequivocation_weight : state -> R;\nequivocation_weight_compat : forall s1 s2, (equivocation_weight s1 <= equivocation_weight (state_union s2 s1))%R;\nabout_prot_state : forall s1 s2, prot_state s1 -> prot_state s2 ->\n(equivocation_weight (state_union s1 s2) <= proj1_sig t)%R -> prot_state (state_union s1 s2);\n}.\n\\end{lstlisting}\n\nThe plan here is to 1) say that our t\n\nWe prove that \\verb|CBC_protocol_eq| can derive \\verb|PartialOrder|.", "meta": {"hexsha": "ef1c06b355c57094915b9bcbd0188b10b56e21a7", "size": 4473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/typeclass.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/typeclass.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/typeclass.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": 48.6195652174, "max_line_length": 511, "alphanum_fraction": 0.7451374916, "num_tokens": 1228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.693882288677088}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage[margin=1in]{geometry}\n\n\\title{An inner product space of sampled fission sources}\n\\author{James Holloway and Jeremy Conlin}\n\n\\newtheorem{definition}{Definition}\n\\newtheorem{theorem}{Theorem}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Source vectors}\n\nWe need a vector space that can contain all possible sampled fission sources.  The purpose of this document is to define such a vector space.  A vector space provides a notion of scalar multiplication and a notion of vector addition, with certain properties.  The key properties are that addition is commutative and distributive, there is a zero vector, for every vector there is an additive inverse that when summed with that vector will yield zero, and the scalar multiplication is associative and distributive over vector addition.\n\n\\subsection{Source vectors}\n\nFirst, we define a source point as a location in space combined with a weight, which can be positive, negative or zero.\n\\begin{definition} A \\emph{source point} $s$ is a pair $s = (w, \\mathbf{x})$ where $w \\in \\mathbf{R}\\backslash0$ is a non-zero real number called the \\emph{weight}, and $\\mathbf{x} \\in \\Gamma$ is a point in a subset of 3-space, $\\Gamma \\subset \\mathbf{R}^3$.  Note that the weight cannot be zero, but can be positive or negative.   We denote by $w(s)$ the weight of a source point, $s$, and by $\\mathbf{x}(s)$ the location of the source point. \n\\end{definition}\nWe will need a notion of equality for source points; two source points are equal if they are at the same location and have equal weight.\n\\begin{definition}\nTwo source points, $s_1, s_2$, are equal, written as $s_1 = s_2$ if and only if $w(s_1) = w(s_2)$ as real numbers and $\\mathbf{x}(s_1) = \\mathbf{x}(s_2)$ as points in $\\Gamma$.  \n\\end{definition}\nFor convenience of notation it will be useful to define multiplication of a source point $s$ by a non-zero real number $\\alpha$ as\n\\begin{definition}\nFor $\\alpha \\in \\mathbf{R}\\backslash 0$ and source point $s$, multiplication $\\alpha s$ is defined as producing the new source point $\\alpha s = (\\alpha w(s), \\mathbf{x}(s))$ at the same location, but with weight scaled by $\\alpha$.\n\\end{definition}\nNote that there is no meaning to adding source points together.  A notion of this sort will be the heart of defining a vector space whose elements are lists of source points. In addition, we will need a sense of scalar multiplication that includes multiplication by zero.\n\nNow we define a collection,  $S$, of source points that can represent a fission source as a finite collection of source points.\n\\begin{definition}\nLet $N$ be a non-negative integer.  A \\emph{source} $S$ is a set of $N$ non-zero-weight source points, $S = \\{s_1, s_2, \\ldots, s_N\\}$, $w(s_i) \\ne 0$ $i = 1, 2, \\ldots N$, with distinct locations $\\mathbf{x}(s_i) \\ne \\mathbf{x}(s_j)$, $i \\ne j$.  $N$ is called the number of source points, and will also be written as $N(S)$.\n\\end{definition}\nIt is very important that $S$ is a set, and so we do not allow repeated source point locations $\\mathbf{x}(s_i) \\ne \\mathbf{x}(s_j)$. Note that sets are un-ordered (by definition), so the order of the source points does not matter; $\\{s_1, s_2\\}$ is the same source as $\\{s_2, s_1\\}$.  Note also that a source does not just have distinct source points, but rather has source points with distinct locations.\n\nThere is a very interesting source, namely the source with $0$ source points.  There is only one such source, since it is simply the empty set.  This special source is very important to defining a vector space of sources, and it is physically important too.\n\\begin{definition}\nThe unique source with no source points is called the \\emph{zero source, and will be denoted $0$}.\n\\end{definition}\n\nLet's discuss equality of any two source $S_1, S_2$.  This is simply the set equality imposed by our previous definition of equality of source points.   For $S_1$ and $S_2$ to be equal they must:\n\\begin{enumerate}\n\\item Have the same number of source points, $N = N(S_1) = N(S_2)$\n\\item If $N > 0$, then for each source point $s_1 \\in S_1$ there must exist a source point $s_2 \\in S_2$ (and there can be only one because $S_1$ and $S_2$ are sets) such that $s_1 = s_2$. \n\\end{enumerate}\n\nWe are finally ready to define a vector space of sources.\nLet $\\mathcal{S}$ be the set of all sources (including sources of any number of source points from zero on up).  \nWe can give $\\mathcal{S}$ a vector space structure by defining scalar multiplication (over the real numbers) and by defining the addition of sources, with the appropriate properties.  Let's define scalar multiplication first, basically as scaling the source weights by a scalar.\n\\begin{definition}\nLet $S \\in \\mathcal{S}$, and $\\alpha \\in \\mathbf{R}$ be a real number.  If $S$ has no source points, or if $\\alpha = 0$, then $\\alpha S = 0$.   Otherwise, with $M = N(S)$ the number of source points, there exist source points $s_i$, $i = 1, \\ldots, M$ such that $S = \\{s_1, \\ldots, s_M\\}$, and $\\alpha S$ is defined to be the source $\\alpha S = \\{\\alpha s_1, \\ldots, \\alpha s_M\\}$.\n\\end{definition}\nNote that $\\alpha S$ is still a good source.  It's either a zero source, or else a set of non-zero-weight source points all at distinct locations.  Scalar multiplication is properly associative $(\\alpha \\beta) S = \\alpha (\\beta S)$, and that $\\alpha = 1$ is the identity.  Note also that multiplication by a non-zero scalar does not change the number of source points, but multiplication by zero does.\n\nNext we must define vector addition, and in doing so we wish to capture the physical notion of adding together two sources.\n\\begin{definition}\nGiven any two sources $S_1, S_2 \\in \\mathcal{S}$, the sum $S_1 + S_2 \\in \\mathcal{S}$ is defined as the source consisting of all source points from $S_1$ and $S_2$ that are at distinct locations, and for every pair of source points $s_1 \\in S_1$ and $s_2 \\in S_2$ that share a common location, $\\mathbf{x}(s_1) = \\mathbf{x}(s_2)$, the sum $S_1 + S_2$ will contain only the single source point $(w(s_1) + w(s_2), \\mathbf{x}(s_1))$ at the same location but with weight equal to the sum total weight of the two originals.  If this combined weight is zero, there is no source point at that location, and that location is not included in the source points of the final sum vector.\n\\end{definition}\nThis definition is well posed; by construction $S_1 + S_2$ will contain a finite number of source points all of which are at distinct locations and none of which has zero weight.  Note that the number of source points in $S_1 + S_2$ will be between 0 and $N(S_1) + N(S_2)$, inclusive; the sum will have fewer source points if there were points in $S_1$ and $S_2$ at common locations, and will have no source points if every point in $S_1$ has a partner of opposite weight in $S_2$.\n\nWe want now to show that this definition of addition makes $\\mathcal{S}$ into a vector space.  \n\\begin{theorem}\nWith the scalar multiplication and addition just defined, $\\mathcal{S}$ is a vector space.\n\\end{theorem}\n\n\\begin{proof}\nNote first that the zero source is the additive identity element, $S + 0 = S$ because $0$ contains no source points.  Further, note that $-1 S$ is an additive inverse because every source point from $-1 S$ is at the same location as a source point in $S$, but the sum of the weights of these paired points will be zero.  Hence $-1 S + S = 0$.\n\nNext, we must check the distributive property $\\alpha (S_1 + S_2) = \\alpha S_1 + \\alpha S_2$.  If $\\alpha$ is zero this is trivially true, and if either $S_1$ or $S_2$ is zero, it's also trivially true.  Otherwise, we must show that that $\\alpha(S_1 + S_2)$ and $\\alpha S_1 + \\alpha S_2$ contain the same source points.  Scalar multiplication does not alter any source points locations, it just changes the source point weights; therefore for points in $S_1$ and $S_2$ at distinct points  $\\alpha S_1 + \\alpha S_2$ contains the same source points as $\\alpha (S_1 + S_2)$.  For points in $S_1$ and $S_2$ at the same source locations there are two cases to consider: 1) either they sum to zero weight and are removed, or 2) they do not.  In the first case, corresponding points in $\\alpha S_1 + \\alpha S_2$ will also sum to zero (if $w(s_1) + w(s_2) = 0$ then $\\alpha w(s_1) + \\alpha w(s_2) = 0$), and in both  $\\alpha (S_1 + S_2)$ and $\\alpha S_1 + \\alpha S_2$ the point in the sum will be eliminated.  In the second case, $\\alpha(S_1 + S_2)$ will contain a point at the common location with weight $\\alpha(w(s_1) + w(s_2)) = \\alpha w(s_1) + \\alpha w(s_2)$ and this is the same weight and location as a particle in $\\alpha S_1 + \\alpha S_2$.\n\nNow we must show that $(\\alpha + \\beta) S = \\alpha S + \\beta S$.  If $\\alpha + \\beta = 0$ then both sides are the zero source, and the statement is true. Similarly if either $\\alpha$ or $\\beta$ is zero.  So we assume now that $\\alpha \\ne0$, $\\beta \\ne 0$, and $\\alpha + \\beta \\ne 0$ and note that $(\\alpha + \\beta)S$ will contain the same source locations as $S$, and that $S$, $\\alpha S$, $\\beta S$ and hence $\\alpha S + \\beta S$ will also all contain the same source locations.  The weight for the source point $s$ in $S$ becomes $(\\alpha + \\beta) w(s)$ in $(\\alpha + \\beta) S$, and this same source point generates a point with weight $\\alpha w(s) + \\beta w(s) = (\\alpha + \\beta) w(s)$ in the sum $\\alpha S + \\beta S$.  This establishes that $(\\alpha + \\beta) S = \\alpha S + \\beta S$ in all cases.\n\nNext we must show the commutative property $S_1 + S_2 = S_2 + S_1$.   The commutative property is obvious if either source is zero, so we now focus on the non-zero case.  If $s \\in S_1 + S_2$ then there exists a point $s'$ in either $S_1$ or $S_2$ or both, such that $\\mathbf{x}(s) = \\mathbf{x}{s'}$.  Suppose this point $s'$ appears only in $S_1$; then $s = s'$ and this point is also in $S_2 + S_1$.  Similarly if the point $s'$ appears only in $S_2$.  Finally if there is an $s' \\in S_1$ and $s'' \\in S_3$ such that $\\mathbf{x}(s) = \\mathbf{x}(s') = \\mathbf{x}(s'')$ then $w(s) = w(s') + w(s'') = w(s'') + w(s')$ and this point also appears in $S_2 + S_1$.  Thus, addition is commutative.\n\nFinally, we must show that addition is associative, $(S_1 + S_2) + S_3 = S_1 + (S_2 + S+3)$.  The thinking that leads to this is identical to that showing that addition is commutative.  It does not matter in what order we collect source points into the sum, and if multiple source points share a common location it does not matter in what order we add up their weights. \n\\end{proof}\n\n\\subsection{Mapping sources to functions}\n\nLet $S \\in \\mathcal{S}$ be a source vector.  We can, in a non-unique way, map this vector to a function $q(x)$ over $\\Gamma$.  Let $h(\\mathbf{x}, \\mathbf{y})$ be any non-negative function (a kernel) from $\\Gamma \\times \\Gamma \\to \\mathcal{R}$ with the property \n\\begin{equation}\n1 = \\int_{\\Gamma} h(\\mathbf{x}, \\mathbf{y}) \\, d\\mathbf{x} \\,.\n\\end{equation} \nLet $\\{s_1, \\ldots, s_M\\}$ be the source points in $S$.  Then \n\\begin{equation}\nQ(S, \\mathbf{x}) = \\sum_{i=1}^M w(s_i) h(x, \\mathbf{x}(s_i))\n\\end{equation}\nis a physical representation of the source as a function of space.   Normally we would also want the function $h$ to be zero outside of $\\Gamma$ (so for example, there is no source outside $\\Gamma$).  Obviously we define $Q(0, \\mathbf{x})$ as the zero function.  Most importantly,\n\\begin{equation}\nQ(\\alpha S, \\mathbf{x}) = \\sum_{i=1}^M \\alpha w(s_i) h(x, \\mathbf{x}(s_i)) = \\alpha Q(s, \\mathbf{x})\n\\end{equation}\nso the mapping from $\\mathcal{S}$ to the space of functions is linear over scalar multiplication, and indeed, scalar multiplication in $\\mathcal{S}$ maps to scalar multiplication of functions.  (Exercise for the reader: show that the mapping is a vector space isomorphism, that is, the vector addition of vectors in $\\mathcal{S}$ maps to the vector addition of functions.  This is needed in order to have a well defined inner product below.)\n\nThis construction is fairly general.  Note for example that if we want a histogram (in 1-D) then we can define a set of bins and\n\\begin{equation}\nh(x,y) = \\begin{cases}\n1/\\Delta & \\text{if $x$ and $y$ are in the same bin}\\\\\n0 & \\text{otherwise} \n\\end{cases}\n\\end{equation}\nwhere $\\Delta$ is the width of the bin in which $x$ and $y$ lie.\n\nNote: It might have been easier to start here and work out the properties needed to add vectors in $\\mathcal{S}$ in order to create this vector space isomorphism.\n\n\\subsection{An inner product space}\n\nFinally, we want to discuss equipping $\\mathcal{S}$ with an inner product; with this in hand $\\mathcal{S}$ becomes an inner product space and we can define a norm and orthogonality.  We can also carry out the Arnoldi process, although we should note that $\\mathcal{S}$ will be an infinite dimensional inner product space (a Hilbert space), and we don't know much about Arnoldi for infinite dimensional problems.\n\nThere is no unique way to attach an inner product to $\\mathcal{S}$, but a general approach is to map $\\mathcal{S}$ to a space of functions, and use the natural $L^2$ inner product.  So we pick kernel functions $h$ as the the previous section and define\n\\begin{equation}\n\\langle S_1, S_2 \\rangle = \\int_{\\Gamma} Q(S_1, \\mathbf{x}) Q(S_2, \\mathbf{x}) \\, d\\mathbf{x}\n\\end{equation}\nThis inner product is symmetric, and linear in each argument because mapping $\\mathcal{S}$ to the space of finite expansions in kernels is a vector space isomorphism.\n\nThe inner product is positive-definite \n\\begin{equation}\n\\langle S, S \\rangle = \\int_{\\Gamma} Q(S, \\mathbf{x}) Q(S, \\mathbf{x}) \\, d\\mathbf{x} \\geq 0\n\\end{equation}\nwith equality if and only if $S = 0$.\n\n\\section{Practical issues}\n\nBecause $\\mathbf{S}$ is an inner product space, all the steps in Arnoldi can be done by working on source vectors $S \\in \\mathcal{S}$.   Doing this in practice is problematic because the vectors will contain more and more source points as we orthogonalize.  However, maybe we do not need to explicitly construct vectors of the form $S_1 + \\beta S_2$.  Rather we simply need to track of $S_1$, $\\beta$, and $S_2$.   A simple data structure can keep this formation.   Then we need a way to sample from the vector $S_1 + \\beta S_2$ without explicitly constructing it.  Is there a way to do this?\n\nThis is important, because explicitly adding two vectors $S_1$ and $S_2$ could be a very expensive process: to accomplish it we must find any points in the two vectors that share a single source location (of course the probability of this is so small we might neglect it).\n\n\\end{document}", "meta": {"hexsha": "b7ee6b8265a9c6cbbc08c7f10e382ca75d18906b", "size": 14599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/fissionSource/fissionSource.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/fissionSource/fissionSource.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/fissionSource/fissionSource.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": 110.5984848485, "max_line_length": 1240, "alphanum_fraction": 0.7243646825, "num_tokens": 4213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6938413866281137}}
{"text": "\\documentclass[letterpaper,12pt]{article}\n\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath,amsthm,amsfonts,amssymb}\n\\usepackage{mathtools}\n\\usepackage{algorithm,algpseudocode}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\n% \\newcommand{\\Mod}[1]{\\ (\\mathrm{mod}\\ #1)}\n\n\\theoremstyle{remark}\n\\newtheorem{claim}{Claim}\n\n\\DeclarePairedDelimiter\\abs{\\lvert}{\\rvert}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\\DeclarePairedDelimiter\\ceiling{\\lceil}{\\rceil}\n\n\\begin{document}\n\n\\title{Brief description of the algorithms}\n\\date{\\today}\n\\author{Vaibhav Sinha}\n\\maketitle\n\n\\section{Discrete Log Problem}\n\nIn this problem we are given $g, y$ and $n$ and we have to find an $x$ such that $g^x \\equiv y \\pmod n$. We use this $\\equiv$ and = alterchangebaly in the report and the meaning is clear from the context.\n\nFirst notice a few things:\n\\begin{enumerate}\n    \\item If $g = 0$ or $1$ then all powers $x$ would only produce $0$ and $1$ respectively. We can always output $1$ in this case. Also observe that without loss of generality, $g < n$. So in the rest of the report we will only consider $g \\in \\{2 \\dots n-1\\}$. \n    \\item When $n$ is prime, then $y \\neq 0$, as $y = 0$ can not have any solution. So in such cases, $y \\in [n-1]$ and $x \\in [n-1]$. Notice that one can equivalently take the $x \\in \\{0, \\dots n-2\\}$ as $g^0 \\equiv g^{n-1} \\equiv 1 \\pmod g$.\n\\end{enumerate}\n\nWe now describe a few algorithms to solve the discrete log problem. Observe that none of these algorithms are truly polynomial time. No efficient algorithm are known for solving Discrete Log Problem in general setting. We implement these algorithms (and some of these only work) modulo a prime as Diffie-Hellman uses a prime modulus.\n\n\\subsection{Brute Force Algorithm}\nIn this algorithm we simply try all possible $x$'s. This takes $O(n)$ time.\n\n\\subsection{Baby-Step Giant-Step Algorithm}\n\nThis algorithm trades off space to improve the running time over brute force. The idea is to write $x = i\\lceil n \\rceil + j$ for $0 \\le i,j \\le \\lceil n \\rceil$. For simplicity let $m = \\lceil n \\rceil$. First compute $g^j$ for all $0 \\le j \\le m$. Then we compute $y\\cdot g^{-im}$ for each $0 \\le i \\le m$. Notice that both can be done in $O(\\sqrt n )$ time. If we could find a collision $y\\cdot g^{-im} = g^j$, then $x = im + j$. To find this collision efficiently we store all $g^j$ (for all $0 \\le j \\le m$) by hash-sets and when we compute $y\\cdot g^{-im}$ we simply check if that value is already present in the set. This finds the collision in $O(\\sqrt{n})$ time (as we need to check if the value is present in the set only $O(\\sqrt{n})$ times). Overall this algorithm uses $O(\\sqrt{n})$ space and time.\n\n\\subsection{Pollard's $\\rho$ algorithm}\n\nThis is a randomized algorithm that works in $O(\\sqrt{n})$ expected time and with $O(1)$ space requirement. We descirbe the algorithm for prime modulus. All the operations described in this section work mod $p$.\n\nThe idea is to divide $\\{1, \\dots n-1\\}$, which are the possible $x$s into three sets, say, $S_0, S_1$ and $S_2$ of roughly equal size. In practice we do it by taking $x \\pmod 3$ ie. $x \\in S_i$, where $i = x \\pmod 3$. We do a random walk starting at $x_0 = g^{a_0} y^{b_0}$ where $a_0 = b_0 = 0$. To generate $x_{i+1}$ from $x_i$ we follow the following rule:\n\n\\begin{equation*}\n    x_{i+1} = \n    \\begin{dcases}\n        x_i^2 \\text{ if } x_i \\in S_0 \\\\\n        yx_i \\text{ if } x_i \\in S_1 \\\\\n        gx_i \\text{ if } x_i \\in S_2\n    \\end{dcases}\n\\end{equation*}\n\nCorresponding to these $x_i$'s we also maintain the $a_i, b_i$ such that $x_i = g^{a_i} y^{b_i}$. Now suppose we find $i$ and $j$, $i \\neq j$, such that $x_i = x_j$, or $g^{a_i} y^{b_i} = g^{a_j} y^{b_j}$. Then $g^{a_i - a_j} = y^{b_j - b_i} \\pmod n$. Substituing $y = g^x$, we get the equation $a_i - a_j = x (b_j - b_i)$. We then solve this using a linear congrence solver to obtain $x$.\n\nSo all we need to so now is to find $i$ and $j$, $i \\neq j$, such that $x_i = x_j$. This is done using the classic Floyd's Hare and Tortoise algorithm (by which the algorithm gets the $\\rho$ in its name). Essentially there are two pointers, one that jumps two steps and another that jumps only one. If there are $i$ and $j$, such that $x_i = x_j$, then these pointers would meet at the same point, giving us $i$ and $j$.\n\n\n\\subsection{Pohlig Hellman algorithm}\n\nLet $g^x = y \\pmod n$. Given $g$, $y$ and $n$ where $g$ is the generator $\\mathbb{Z}^*_{n}$ we need to find $x$. We are also given the factorization of $n-1$ as,\n\\begin{equation*}\n    n-1 = p_1^{e_1} p_2^{e_2} \\cdots p_k^{e_k}\n\\end{equation*}\nwhere $p$'s are distinct primes. Notice that $1 \\le y \\le n-1$ and $0 \\le x \\le n-2$ (as $g^0 = g^{n-1} = 1$).\n\nThe idea of Pohlig Hellman is to first compute $x \\pmod {p_i^{e_i}}$ for each $i \\in [k]$. As all $p_i^{e_i}$ are mututally coprime we can recover $x \\pmod {n-1}$ by Chinese Remainder Theorem. We show how to compute $x \\pmod {p_i^{e_i}}$. We now drop the indices from $p_i$ and $e_i$ for simplicity (and refer to them as $p$ and $e$).\n\nConsider the expansion of $x$,\n\\begin{equation*}\n    x = \\sum_{0 \\le i \\le e-1} x_i p^i + sp^e\n\\end{equation*}\n\nObserve,\n\\begin{equation*}\n    y^{\\frac{n-1}{p}} \\equiv g^{\\left(x_0 \\frac{n-1}{p} + k(n-1)\\right)} \\equiv g^{x_0 \\frac{n-1}{p}} \\pmod n \n\\end{equation*}\nwhere $k$ is some integer.\nThis follows because of $g$ is a generator and so $g^{n-1} \\pmod n = 1$. So now we can recover $x_0$ by using Baby-Step Giant-Step algorithm (as $y^{\\frac{n-1}{p}}$ is the $x_0$th power of $g^{\\frac{n-1}{p}} \\pmod n$). \n\nThis idea extends to find $x_i$. Assume that we have computed $x_0 \\dots x_{i-1}$. Now we compute, \n\\begin{equation*}\n    y\\cdot g^{-(\\sum_{0\\le j \\le i-1} x_j p^j)} = g^{(\\sum_{i \\le j \\le e-1} x_j p^j) + sp^e}\n\\end{equation*}\nCall this $y'$. Then notice that (using similar simplification as above),\n\\begin{equation*}\n    (y')^{\\frac{n-1}{p^{(i+1)}}} \\equiv g^{x_i \\frac{n-1}{p}} \\pmod n \n\\end{equation*}\nAgain we use Baby-Step Giant-Step algorithm to compute $x_j$. We continue this to extract each $x_i$ until $x_{e-1}$ using which we create $x \\pmod {p^e}$. This algorithm is exactly implemented in the code.\n\n\\section{Man in the middle attack on the Diffie-Hellman Protocol}\n\nAssume that there is an attacker Eve who wants to evesdrop on Alice and Bob's conversation or worse even to modify their messages. Here's how Eve attacks using the `Man In The Middle' attack if Alice and Bob use Diffie-Hellman Protocol.\n\nEve obtains the public $g$ and $p$, the generator and modulus, that Alice and Bob have decided to use. Now according to protocol Alice chooses $a$ and sends $g^a$ and Bob chooses $b$ and sends $g^b$. Eve herself chooses an $e$ and generates $g^e$. She sends $g^e$ to Alice and Bob claiming that she is Bob and Alice respectively. She receives both Alice and Bob's $g^a$ and $g^b$ which they had sent. \n\nNow Alice receives $g^e$ and believes that this message is from Bob. So she creates the key $g^{ae}$. Similarly, Bob receives $g^e$ and believes that this message is from Alice. So he creates the key $g^{be}$. Eve computes both $g^{ae}$ and $g^{be}$. Notice now that Eve has both the keys and has Alice and Bob convinced that they are talking to each other. \n\nNow when Alice sends a message encrypted by the key $g^{ae}$, Eve decrypts it, reads (and possibly modifies) it, reencrypts the message using $g^{be}$ and sends it to Bob who successfully decrypts it. The message recieved is what Eve sent him and not Alice but Bob believes that the message is from Alice. Eve similarly intercepts messages from Bob to Alice. Thus Alice and Bob think that they are communicating with each other without realizing that there is a `man' in the middle, Eve, who is evesdropping and possibly modifing their messages.\n\nThis attack happens because there is no way for Alice and Bob to authenticate that they are talking to the persons they think they are. This vulenrability is fixed by using digital signatures (a mechanism for authentication) and other such protocols. \n\n\\end{document}\n", "meta": {"hexsha": "2ade6b9bcb8b1c3926a4178d4e368bc3eff62908", "size": 8063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithms.tex", "max_stars_repo_name": "vbsinha/Diffie-Hellman-Attacks", "max_stars_repo_head_hexsha": "d1b67cc3d5e30a9db1246ce52e45b6eb93017ce3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-24T17:16:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-24T17:16:35.000Z", "max_issues_repo_path": "algorithms.tex", "max_issues_repo_name": "vbsinha/Diffie-Hellman-Attacks", "max_issues_repo_head_hexsha": "d1b67cc3d5e30a9db1246ce52e45b6eb93017ce3", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "vbsinha/Diffie-Hellman-Attacks", "max_forks_repo_head_hexsha": "d1b67cc3d5e30a9db1246ce52e45b6eb93017ce3", "max_forks_repo_licenses": ["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.3, "max_line_length": 811, "alphanum_fraction": 0.6984993179, "num_tokens": 2579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6938413826838645}}
{"text": "\\section{Autoregressive Models}\n\nWe begin our study with the autoregressive generative models. As before, we assume we are given access to a dataset $\\mathcal{D}$  of $n$-dimensional datapoints $\\mathbf{x}$. For simplicity, we assume the datapoints are binary, i.e.,  $\\mathbf{x} \\in \\{0,1\\}^n$.\n\n\\section{Representation}\n\nBy the chain rule of probability, we can factorize the joint distribution over the $n$-dimensions as:\n\\[\n\\begin{equation}\np(\\mathbf{x}) = \\prod\\limits_{i=1}^{n}p(x_i \\vert x_1, x_2, \\ldots, x_{i-1}) = \\prod\\limits_{i=1}^{n} p(x_i \\vert \\mathbf{x}_{<i})\n\\end{equation}\n\\label{eq:chain_rule}\n\\]\nwhere $\\mathbf{x}_{<i}=[x_1, x_2, \\ldots, x_{i-1}]$ denotes the vector of random variables with index less than $i$. If we allow for every conditional $p(x_i \\vert \\mathbf{x}_{<i})$ to be specified in a tabular form, then such a representation is fully general and can represent any possible distribution over $n$ random variables. However, the space complexity for such a representation grows exponentially with $n$. \n\nTo see why, let us consider the conditional for the last dimension, given by $p(x_n \\vert \\mathbf{x}_{<n})$. In order to fully specify this conditional, we need to specify a probability for $2^{n-1}$ configurations of the variables $x_1, x_2, \\ldots, x_{n-1}$.  Since the probabilities should sum to 1, the total number of parameters for specifying this conditional is given by $2^{n-1} -1$. Hence, a tabular representation for the conditionals is impractical for learning the joint distribution in (\\ref{eq:chain_rule}) . \n\nIn an \\textit{autoregressive generative model}, the conditionals are specified as parameterized functions with a fixed number of parameters. That is, we assume the conditional distributions $p(x_i \\vert \\mathbf{x}_{<i})$ to correspond to a Bernoulli random variable and learn a function that maps the preceeding random variables $x_1, x_2, \\ldots, x_{i-1}$ to the mean of this distribution. Hence, we have:\n\\[\np_{\\theta_i}(x_i \\vert \\mathbf{x}_{<i}) = \\mathrm{Bern}(f_i(x_1, x_2, \\ldots, x_{i-1}))\n\\]\nwhere $\\theta_i$ denotes the set of parameters used to specify the mean function $f_i: \\{0,1\\}^{i-1}\\rightarrow [0,1]$.  The term \\textit{autoregressive} originates from the literature on time-series models where observations from the previous time-steps are used to predict the value at the current time step. Here, we are predicting the distribution for the $i$-th random variable using the values of the preceeding random variables in the sequence $x_1, x_2, \\ldots, x_n$.\n\nThe number of parameters of an autoregressive generative model are given by $\\sum_{i=1}^n \\vert \\theta_i \\vert$. As we shall see in the examples below, the number of parameters are much fewer than the tabular setting considered previously. Unlike the tabular setting however, an autoregressive generative model cannot represent all possible distributions. Its expressiveness is limited by the fact that we are limiting the conditional distributions to correspond to a Bernoulli random variable with a restricted class of parameterized functions specifying the mean.\n\nIn the simplest case, we can specify the function as a linear combination of the input elements followed by a sigmoid non-linearity (to restrict the output to lie between 0 and 1). This gives us the formulation of a \\textit{fully-visible sigmoid belief network} (FVSBN):\n\\[\nf_i(x_1, x_2, \\ldots, x_{i-1}) =\\sigma(\\alpha^{(i)}_0 + \\alpha^{(i)}_1 x_1 + \\ldots + \\alpha^{(i)}_{i-1} x_{i-1})  \n\\]\nwhere $\\sigma$ denotes the sigmoid function and $\\theta_i=\\{\\alpha^{(i)}_0,\\alpha^{(i)}_1, \\ldots, \\alpha^{(i)}_{i-1}\\}$ denote the parameters of the mean function. The conditional for variable $i$ requires $i$\n parameters, and hence the total number of parameters in the model is given by $\\sum_{i=1}^ni= O(n^2)$.  Note that the number of parameters are much fewer than the exponential parameters required in the tabular case.\n\nA natural way to increase the expressiveness of an autoregressive generative model is to use more flexible parameterizations for the mean function e.g., multi-layer perceptrons (MLP). In the case of 1-hidden layer neural networks, the mean function for variable $i$ can be expressed as:\n\\[\n\\mathbf{h}_i = \\sigma(A_i \\mathbf{x_{<i}} + \\mathbf{c}_i)\\\\\nf_i(x_1, x_2, \\ldots, x_{i-1}) =\\sigma(\\boldsymbol{\\alpha}^{(i)}\\mathbf{h}_i +b_i )  \n\\]\nwhere $\\mathbf{h}_i \\in \\mathbb{R}^d$ denotes the hidden layer activations for the MLP and$\\theta_i = \\{A_i \\in \\mathbb{R}^{d\\times (i-1)},  \\mathbf{c}_i \\in \\mathbb{R}^d, \\boldsymbol{\\alpha}^{(i)}\\in \\mathbb{R}^d, b_i \\in \\mathbb{R}\\}$ are the set of parameters for the mean function $\\mu_i(\\cdot)$.  The total number of parameters in this model is dominated by the matrices $A_i$ and given by $O(n^2 d)$. \n\nThe Neural Autoregressive Density Estimation (NADE) provides an efficient MLP parameterization that shares parameters used for evaluating the hidden layer activations.\n\\[\n\\mathbf{h}_i = \\sigma(W_{., <i} \\mathbf{x_{<i}} + \\mathbf{c})\\\\\nf_i(x_1, x_2, \\ldots, x_{i-1}) =\\sigma(\\boldsymbol{\\alpha}^{(i)}\\mathbf{h}_i +b_i )  \n\\]\nwhere $\\theta=\\{W\\in \\mathbb{R}^{d\\times n}, \\mathbf{c} \\in \\mathbb{R}^d, \\{\\boldsymbol{\\alpha}^{(i)}\\in \\mathbb{R}^d\\}^n_{i=1}, \\{b_i \\in \\mathbb{R}\\}^n_{i=1}\\}$is the full set of parameters for the mean functions $f_1(\\cdot), f_2(\\cdot), \\ldots, f_n(\\cdot)$. The weight matrix $W$ and the bias vector $\\mathbf{c}$ are shared across the conditionals. Sharing parameters offers two benefits:\n\\begin{enumerate}\n\\item The total number of parameters from $O(n^2 d)$ to $O(nd)$ [readers are encouraged to check!].\n\\item The hidden unit activations can be evaluated in $O(nd)$ time via the following recursive strategy:\n\\[\n\\mathbf{h}_i = \\sigma(\\mathbf{a}_i)\\\\\n\\mathbf{a}_{i+1} = \\mathbf{a}_{i} + W[., i]x_i\n\\]\nwith the base case given by $\\mathbf{a}_1=\\mathbf{c}$.\n\\end{enumerate}\n\n\n\\section{Learning and inference}\n\nRecall that learning a generative model involves optimizing the closeness between the data and model distributions. One commonly used notion of closeness in the KL divergence between the data and the model distributions.\n\n$$\n\\begin{align*}\n\\min_{\\theta\\in \\mathcal{M}}d_{KL}(p_{\\mathrm{data}}, p_{\\theta}) &= \\mathbb{E}_{\\mathbf{x} \\sim p_{\\mathrm{data}} }\\left[\\log p_{\\mathrm{data}}(\\mathbf{x}) - \\log p_{\\theta}(\\mathbf{x})\\right].\n\\end{align*}\n$$\nBefore moving any further, we make two comments about the KL divergence. First, we note that the KL divergence between any two distributions is asymmetric. As we navigate through this chapter, the reader is encouraged to think what could go wrong if we decided to optimize the reverse KL divergence instead. Secondly, the KL divergences heavily penalizes model distribution $p_\\theta$ which place little mass on any datapoint that has a non-zero probability under $p_{\\mathrm{data}}$. In the extreme case, if the density $p_\\theta(\\mathbf{x})$ evaluates to zero for a datapoint sampled from $p_{\\mathrm{data}}$, the objective evaluates to $+\\infty$. \n\nSince $p_{\\mathrm{data}}$ does not depend on $\\theta$, we can equivalently recover the optimal parameters via maximizing likelihood estimation:\n\n$$\n\\begin{align*}\n\\max_{\\theta\\in \\mathcal{M}}\\mathbb{E}_{\\mathbf{x} \\sim p_{\\mathrm{data}} }\\left[\\log p_{\\theta}(\\mathbf{x})\\right].\n\\end{align*}\n$$\nHere, $\\log p_{\\theta}(\\mathbf{x})$ is referred to as the log-likelihood of the datapoint $\\mathbf{x}$ with respect to the model distribution $p_\\theta$. \n\nTo approximate the expectation over the unknown $p_{\\mathrm{data}}$, we make an assumption: points in the dataset $\\mathcal{D}$ are sampled i.i.d. from $p_{\\mathrm{data}}$. This allows us to obtain an unbiased Monte Carlo estimate of the objective:\n\n$$\n\\begin{align}\n\\max_{\\theta\\in \\mathcal{M}}\\frac{1}{\\vert D \\vert} \\sum_{\\mathbf{x} \\in\\mathcal{D} }\\log p_{\\theta}(\\mathbf{x}) = \\mathcal{L}(\\theta \\vert \\mathcal{D}).\n\\end{align}\n\\label{eq:mle}\n\\tag{2}\n$$\n\nThe maximum likelihood estimation (MLE) objective has an intuitive interpretation: pick the model parameters $\\theta \\in \\mathcal{M}$ that maximize the log-probability of the observed datapoints in $\\mathcal{D}$. \n\nIn practice, we optimize the MLE objective using mini-batch gradient ascent. The algorithm operates in iterations. At every iteration $t$, we sample a mini-batch $\\mathcal{B}_t$  of datapoints sampled randomly from the dataset ($\\vert \\mathcal{B}_t\\vert < \\vert \\mathcal{D} \\vert$) and compute gradients of the objective evaluated for the mini-batch. These parameters at iteration $t+1$ are then given via the following update rule:\n\\[\n\\theta^{(t+1)} = \\theta^{(t)} + r_t \\nabla_\\theta\\mathcal{L}(\\theta^{(t)} \\vert \\mathcal{B}_t)\n\\]\nwhere $\\theta^{(t+1)}$ and $\\theta^{(t)}$ are the parameters at iterations $t+1$ and $t$ respectively, and $r_t$ is the learning rate at iteration $t$.  Typically, we only specify the initial learning rate $r_1$ and update the rate based on a schedule.  [Variants](http://cs231n.github.io/optimization-1/) of stochastic gradient ascent, such as RMS prop and Adam, employ modified update rules that work slightly better in practice. \n\nFrom a practical standpoint, we must think about how to choose hyperaparameters (such as the initial learning rate) and a stopping criteria for the gradient descent. For both these questions, we follow the standard practice in machine learning of monitoring the objective on a validation dataset. Consequently, we choose the hyperparameters with the best performance on the validation dataset and stop updating the parameters when the validation log-likelihoods stop improving.\n\nNow that we have a well-defined objective and optimization procedure, the only remaining task is to evaluate the objective in the context of an autoregressive generative model. To this end, we substitute the factorization of the joint distribution in Eq.$~\\ref{eq:chain_rule}$\nin the MLE objective in Eq.$~\\ref{eq:mle}$ to get:\n\\[\n\\max_{\\theta \\in \\mathcal{M}}\\frac{1}{\\vert D \\vert} \\sum_{\\mathbf{x} \\in\\mathcal{D} }\\sum_{i=1}^n\\log p_{\\theta_i}(x_i \\vert \\mathbf{x}_{<i})\n\\]where $\\theta = \\{\\theta_1, \\theta_2, \\ldots, \\theta_n\\}$ now denotes the collective set of parameters for the conditionals.\n\nInference in an autoregressive model is straightforward. For density estimation of an arbitrary point $\\mathbf{x}$, we simply evaluate the log-conditionals $\\log p_{\\theta_i}(x_i \\vert \\mathbf{x}_{<i})$ for each $i$ and add these up to obtain the log-likelihood assigned by the model to $\\mathbf{x}$. Since we know conditioning vector $\\mathbf{x}$, each of the conditionals can be evaluated in parallel. Hence, density estimation is efficient on modern hardware.\n\nSampling from an autoregressive model is a sequential procedure. Here, we first sample $x_1$, then we sample $x_2$ conditioned on the sampled $x_1$, followed by $x_3$ conditioned on both $x_1$ and $x_2$ and so on until we sample $x_n$ conditioned on the previously sampled $\\mathbf{x}_{<n}$. For applications requiring real-time generation of high-dimensional data such as audio synthesis, the sequential sampling can be an expensive process.\n\n\nTODO: add NADE samples figure\n\nFinally, an autoregressive model does not directly learn unsupervised representations of the data. In the next few set of lectures, we will look at latent variable models (e.g., variational autoencoders) which explicitly learn latent representations of the data.\n\n\nTODO: Autoregressive generative models based on Autoencoders, RNNs, and CNNs.\nMADE, Char-RNN, Pixel-CNN, Wavenet", "meta": {"hexsha": "bc157b265897ba90a22e08dd2a97ef78b47309fd", "size": 11509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/autoregressive/index.tex", "max_stars_repo_name": "kitliu5/notes", "max_stars_repo_head_hexsha": "69766ca15a8fe7bd969508ba36242a916777c97a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 371, "max_stars_repo_stars_event_min_datetime": "2018-10-09T21:36:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T07:29:01.000Z", "max_issues_repo_path": "docs/autoregressive/index.tex", "max_issues_repo_name": "kitliu5/notes", "max_issues_repo_head_hexsha": "69766ca15a8fe7bd969508ba36242a916777c97a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2018-11-29T07:40:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T17:12:32.000Z", "max_forks_repo_path": "docs/autoregressive/index.tex", "max_forks_repo_name": "kitliu5/notes", "max_forks_repo_head_hexsha": "69766ca15a8fe7bd969508ba36242a916777c97a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 97, "max_forks_repo_forks_event_min_datetime": "2018-10-27T21:18:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T03:54:48.000Z", "avg_line_length": 100.9561403509, "max_line_length": 650, "alphanum_fraction": 0.7430706404, "num_tokens": 3267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895106480586, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.6938413820106076}}
{"text": "\\chapter{Background}\\label{chap:background}\n\nThe explanations of the fundamental elements of reinforcement learning are based on the book Reinforcement Learning:\nAn Introduction\\cite{Sutton1998} from Richard S. Sutton and Andrew G. Barto.\n\n\\section{Markov Decision Processes}\nThe Markov Decision Process (MPD)  is the mathematical framework of Reinforcement Learning and\nis defined as a tuple < $\\mathcal{S, A, R, T}$ >\n\\begin{itemize}\n\\item $\\mathcal{S}$ is a set of states, s $\\in \\mathcal{R}^{n}$\n\\item $\\mathcal{A}$ is a set of actions, a $ \\in \\mathcal{R}^{n}$\n\\item $\\mathcal{R}$ is the reward\n\\item $\\mathcal{T}$ is the transition probability function\n\\end{itemize}\nEvery state in a Markov Decision Process needs to satisfy the Markov Property,\nwhich means that \"The future is independent of the past given the present\".\nThe definition is given by a state reward pair \n\\begin{equation}\n\\mathcal{P}(S_{t+1}, R_{t+1} | S_{t}, R_{t}) =  \\mathcal{P}(S_{t+1}, R_{t+1} | S_{t}, R_{t}, ..., S_{0}, R_{0})\n\\end{equation}\nUnfortunately for most real-world problems this assumption is violated. This is also the case for the\nstate transition function, which is defined as\n\\begin{equation}\n  \\mathcal{P}(s_{t+1}| s_{t}, a_{t}) =  \\mathcal{P}(S_{t+1} = s^{'}| S_{t} = s ,  A_{t} = a)\n\\end{equation}\n The goal of the agent is to find the policy that maximizes the total reward $(R_{t})$.\nIn the discounted case is given as \n\\begin{equation}\n  R_t = \\sum^{\\infty}_{k = 0} \\gamma^k r_{t+k+1}\n\\end{equation}\nwith $\\gamma$ as the discount factor to exponentially discounts future rewards. \nThe policy is a function, which in the deterministic case maps states to actions.\nWhile a stochastic policy $\\pi(a|s)$ has a certain probability of selecting an action \\textit{a} in state \\textit{s}.\nFor every MDP there is always at least one optimal policy $\\pi$. \nIn case the transition probability is given, the \\textit{dynamic programming} based \\textit{value iteration} Algorithm is one way to compute policy $\\pi$.\nThis Algorithm is build upon the concept of a value function.\n\\subsection{Value Function}\nThe value function $V^{\\pi}$ : $\\mathcal{S}$ $\\rightarrow$ $\\mathcal{R}$, represents the expeceted total reward in a given state when following the policy $\\pi$.\nIt is defined as\n \\begin{equation}\n  \\begin{aligned}\n    V^{\\pi}(s) &= \\mathbb{E}_{\\pi} [R_t | s_t = s] \\\\\n    &= \\mathbb{E}_{\\pi} [\\sum^{\\infty}_{k=0} \\gamma^{k} r_{t+k+1} | s_t = s] \\label{MDP:eq1} \\\\\n    &= \\sum_{a \\in \\mathcal{A}} \\pi(s, a) \\sum_{s' \\in \\mathcal{S}} \\mathcal{T}^{a}_{ss'}[\\mathcal{R}^{a}_{ss'} + \\gamma V^\\pi(s')]\n  \\end{aligned}\n\\end{equation}\nIn each Iteration \\textit{i} of the \\textit{value iteration} Algorithm the value function is updated by the following equation\n\\begin{equation}\n  V_{i+1}(s) := \\max_a \\Big\\{ \\sum_{s', r} P(s',r| s,a) (r + \\gamma V_i(s')) \\Big\\}\n\\end{equation}\nThis update is repeated until both sides of the equation are equal.\n\\subsection{Q-value Function}\nIn many real-world problems the transition function is unknown and computing the value function is not feasible, because\nit would require evaluating all possible actions in a single state at every time step.\nTo evaluate every action in a state the Q-value function $ \\mathcal{Q}: \\mathcal{S} \\times \\mathcal{A} \\rightarrow \\mathcal{R} $\n\\begin{align}\n  Q^{\\pi}(s, a) &= \\textsc{E}_\\pi[R_t | s_t = s, a_t = a] \\\\\n  &= \\textsc{E}_\\pi [\\sum^\\infty_{k=0} \\gamma^k r_{t+k+1} | s_t = s, a_t = a]\n\\end{align}\nIt represents the expected reward of the agent if the action a is chosen in state s at time step t when following the current policy $\\pi$.\nThe Bellman Optimality Equation is one way to update the Q-value Function \n\\begin{equation}\n  Q(s_t, a_t) \\leftarrow Q(s_t, a_t) + \\alpha[r_{t+1} + \\gamma \\max_a Q(s_{t+1}, a) - Q(s_t, a_t)]\n\\end{equation}\nwhere $ \\alpha$ is the \\textit{learning rate} and $\\gamma$ weights between short and longterm reward.\n\n\\subsection{Q Learning}\nThis update equation is used to find an optimal policy in the Q-Learning Algorithm repesened in Algorithm \\ref{alg:q-learning}\n\\input{figures/background/Q-learning.tex}\nThe Algorithm is based on the concept of Temporal Difference Learning.\nIt uses the combined ideas of Dynamic Programming (DP) and Monte Carlo (MC) methods.\nLike in Dynamic Programming the old estimate to update the new estimate. Unlike MC it uses a bootstraped estimate.\n\nQ-Learning is an off-policy Algorithm, it uses different policies for interacting with the environment and updating the Q-value Function.\n\n\\section{Neural Network}\nIn complex environments, the state space is continuous, which makes it infeasible to store all state-action pairs in a table.\nAdvances in machine learning especially in deep learning make it possible to approximate the Q function.  \nBasic elements of Deep learning are artificial neural networks which are inspired by the human brain.\nNeural network have a structure of input layer connected to hidden layers followed by the output layer. \nA fully connected network has many hidden layers represented as nodes. The nodes between different layers are connected by weights. \nThe values of the weights can be trained iteratively by using an optimization technique like stochastic gradient descent and backpropagation.\nThis simple architecture could be seen as matrix multiplications which makes it a linear function.\nBy adding nonlinear activation functions it is able to approximate more complex nonlinear functions.\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{figures/background/nn.png}\n  \\caption{Deep Neural Network with several hidden layers}\n  \\label{fig:tab-training}\n\\end{figure}\n\n\n\n\\section{Soft Q Learning}\n\nSoft Q learning uses the maximum entropy to augment the standard RL objective \nby maximizing also the entropy of the policy. \n\n\\begin{equation}\n  \\pi^* = \\underset{\\pi}{\\mathrm{argmax}} \\sum_{t=0}^{T} E_{(s_t, a_t) \\sim \\tau_{\\pi}}[\\gamma^t (r(s_t, a_t) + \\alpha \\mathcal{H}(\\pi(.|s_t))]\n\\end{equation}\n\nThe entropy of the polciy $\\pi$ is represented by $\\mathcal{H}(\\pi(.|s_t))]$ and is computed with $-log\\pi(.|s_t)$.\nThis new objectiv leads to a stochasic policy and an implicit exploration.\nIn most cases it is difficult to find a good $\\alpha$, for this nt. Haarnoja et al. (2018) proposed to adjust $\\alpha$  dynamically by taking a\ngradient step with respect to the loss \n\n\\begin{equation}\\label{eq:entropy_temp}\nJ(\\alpha)= \\mathbb{E}_{\\mathcal{D}, \\pi}\n\\left[\n    \\log \\alpha \\cdot  (\n        -\\log \\pi( a_{t} | s_{t} )\n        -\n        \\mathcal{H}_T\n    )\n\\right],\n\\end{equation}\n\n\n\\section{Actor-Critic Concept}\n\nThe Algoritem used in this work is based on Soft Q Learning approch and the Actor-Critic Concept.\n\nThe Actor is a Neural Network to approximate our policy function p(s) in continuous action spaces.  \nThis is necessary because with infinite actions the max operation for updating the Q-value function is not feasible. The probably simplest way to update the \nactor weights to force the actor to select actions that have a higher Q-value is by using the critic to evaluate the actions.\n\nA simple way is to minimize the policy gradient loss:\n\n\\begin{equation}\n  \\nabla_{\\theta} \\mathcal{L}_{\\theta}(\\mathcal{D}) = - \\mathbb{E}_{s \\sim \\mathcal{D}} [\\nabla_{\\theta} log \\pi_{\\theta}(a|s) \\cdot Q_{\\phi}(s,a)]\n\\end{equation}\n\n\nThe Critic is used to evaluate the action of the actor. It is a neural network that approximates the Q-value function and it can be trained by minimixing the mean squard error loss\nof the training data-set $\\mathcal{D}$ represented by the replay buffer. \n\n\\begin{equation}\n  \\mathcal{L}_{\\phi}(\\mathcal{D}) =  \\mathbb{E}_{s,a, r, s^{\\prime} \\sim \\mathcal{D}} [Q_{\\phi}(s,a) - \\underbrace{( r + \\gamma \\: \\underset{a^{\\prime}}{max} \\:  Q_{\\phi^{\\prime}}(s^{\\prime},a^{\\prime})}_{TD - target}]^{2}\n\\end{equation}\n\n\n\n", "meta": {"hexsha": "004aeff479e1c0f19690d25cb5960dc21041d1b0", "size": 7842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-background.tex", "max_stars_repo_name": "ChrisProgramming2018/bachelorThesisLatex", "max_stars_repo_head_hexsha": "46ca9c643797dea09c11d72cc95fbe85e35b169b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-background.tex", "max_issues_repo_name": "ChrisProgramming2018/bachelorThesisLatex", "max_issues_repo_head_hexsha": "46ca9c643797dea09c11d72cc95fbe85e35b169b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-background.tex", "max_forks_repo_name": "ChrisProgramming2018/bachelorThesisLatex", "max_forks_repo_head_hexsha": "46ca9c643797dea09c11d72cc95fbe85e35b169b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.4583333333, "max_line_length": 222, "alphanum_fraction": 0.727110431, "num_tokens": 2246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895106480586, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6938413801722134}}
{"text": "\\section{Physics}\r\n\\subsection{Position, Velocity, \\& Acceleration}\r\nSince we know by the FTC that integration is the opposite of differentiation, we can also interpret integrals in a similar physical sense as derivatives.\r\n\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{ l l }\r\n\t\t\t$\\begin{aligned}\\int{v(t)\\d{t}}=x(t) + C\\end{aligned}$ & $\\begin{aligned}\\int{a(t)\\d{t}}=v(t)\\end{aligned}$\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\\end{table}\r\n\r\n\\begin{example}\r\n\tA particle starts at $t=0$ with an initial velocity of 5m/s and accelerates for 8 seconds.\r\n\tIt's acceleration is given by $a(t)=2.4t$ m/s$^2$.\r\n\tWhat is the particle's velocity after the 8 seconds pass?\r\n\tWhat is the particle's displacement after the 8 seconds pass?\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can integrate acceleration to get velocity.\r\n\t\\begin{equation*}\r\n\t\tv(t) = \\int{2.4t\\d{t}} = 1.2t^2 + C.\r\n\t\\end{equation*}\r\n\t\r\n\tWe know that $v(0)=5$m/s so we can solve\\footnote{When we solve for $C$ like this, we're solving what's called an \"inital value problem,\" which we'll do more of when talking about differential equations.} for $C$.\r\n\t\\begin{align*}\r\n\t\t1.2(0) + C &= 5 \\\\\r\n\t\tC &= 5 \\\\\r\n\t\tv(t) = 1.2t^2 + 5.\r\n\t\\end{align*}\r\n\t\r\n\tSo, at $t=8$, $v(8) = 1.2(8)^2 + 5 = 81.8$m/s.\r\n\tWe can now integrate velocity to get displacement\r\n\t\\begin{equation*}\r\n\t\tx(t) = \\int{1.2t^2 + 5 \\d{t}} = 0.4t^3 + 5t + C.\r\n\t\\end{equation*}\r\n\t\r\n\tWe know that $x(0)=0$m, so $C=0$.\r\n\t\\begin{equation*}\r\n\t\tx(t) = 0.4t^3 + 5t.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, at $t=8$, $x(t) = 0.4(8)^3 + 5(8) = 244.8$m.\r\n\tWe could have also tackled this problem with definite integrals.\r\n\t\\begin{align*}\r\n\t\t\\Delta x = \\int_{0}^{8}{v(t)\\d{t}} &= 244.8\\text{m} \\implies \\text{Net Displacement} = x_0 + \\Delta x = 244.8\\text{m} \\\\\r\n\t\t\\Delta v = \\int_{0}^{8}{a(t)\\d{t}} &= 76.8\\text{m/s} \\implies \\text{Net Velocity} = v_0 + \\Delta v = 81.8\\text{m/s}\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Work}\r\nWork is defined as\r\n\\begin{equation*}\r\n\tW = Fd\r\n\\end{equation*}\r\nwhere $F$ is force and $d$ is displacement.\r\nThe force applied by stretching or compressing a spring beyond its natural length is given by Hooke's Law\r\n\\begin{equation*}\r\n\tF = kx\r\n\\end{equation*}\r\nwhere $k$ is some spring constant and $x$ is the displacement beyond the spring's natural length.\r\nWe can apply ideas as integrals representing net change to find the work needed to compress or stretch a spring.\r\n\r\n\\begin{example}\r\n\tIt takes 10N of force to stretch a spring 2m beyond its natural length.\r\n\tHow much work is done stretching the spring 4m beyond its natural length?\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can use the first bit of information to get the spring constant.\r\n\t\\begin{align*}\r\n\t\tF &= kx \\\\\r\n\t\t10\\text{N} &= k(2\\text{m}) \\\\\r\n\t\tk &= 5\\text{N/m}.\r\n\t\\end{align*}\r\n\t\r\n\tSo, $F(x)=5x\\text{N}$.\r\n\tIf we stretch the spring by $\\Delta x$, the work done over this interval is approximately $\\Delta W = F(x)\\Delta x= 5x\\Delta x$.\r\n\tIn the limit, $\\d{W} = 5x\\d{x}$.\r\n\tIntegrating both sides from $x=0$ to $x=4$,\r\n\t\\begin{equation*}\r\n\t\tW = \\int_{0}^{4}{\\d{W}} = \\int_{0}^{4}{5x\\d{x}} = 40\\text{Nm}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\r\nWe can even bring in other concepts to these problems, like related rates.\r\n\\begin{example}\r\n\tAn inverted conical tank with a height of 10ft and a base radius of 5ft is filled to within 2ft of the top with a liquid with a density of 57lbs/ft$^3$.\r\n\tHow much work does it take to fill the remaining 2ft of the tank with liquid, assuming you only have to pump the liquid to the current liquid level in the tank?\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $V$ be the volume of the tank and $x$ the height of the liquid.\r\n\tImagine we pump in some liquid that changes the height of the liquid in the tank by $\\Delta x$.\r\n\tThen\r\n\t\\begin{align*}\r\n\t\t\\Delta V &= \\pi r^2 \\Delta x \\\\\r\n\t\t\\d{V} &= \\pi r^2 \\d{x}.\r\n\t\\end{align*}\r\n\t\r\n\tSince the height of the tank is 10ft and the base radius 5ft, the radius of the liquid level will always be half the liquid depth.\r\n\t\\begin{align*}\r\n\t\tr &= x/2 \\\\\r\n\t\t\\d{V} &= \\pi (x/2)^2 \\d{x}.\r\n\t\\end{align*}\r\n\t\r\n\tSince weight in pounds is already a unit of force, we can multiply $\\d{V}$ by the density of the liquid to get $F$.\r\n\t\\begin{equation*}\r\n\t\tF = 57\\pi(x/2)^2 \\d{x}.\r\n\t\\end{equation*}\r\n\t\r\n\tThe displacement of the liquid is the current height of the liquid $x$, getting us $\\d{W}$.\r\n\t\\begin{align*}\r\n\t\t\\d{W} &= 57\\pi x(x/2)^2 \\d{x} \\\\\r\n\t\tW &= \\int_{8}^{10}{57\\pi x(x/2)^2 \\d{x}} \\\\\r\n\t\t&= 21033\\pi \\text{ft lbs}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n", "meta": {"hexsha": "2b382348f856772591924ade08eec73411d3a641", "size": 4498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_integrals/basic_physics.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/applications_integrals/basic_physics.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/applications_integrals/basic_physics.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1186440678, "max_line_length": 215, "alphanum_fraction": 0.6471765229, "num_tokens": 1584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6938413700395247}}
{"text": "\\section*{Annex A: Wavelet transform  using the Fourier Transform}\n\\addcontentsline{toc}{section}{Appendix A: Wavelet transform  using the Fourier Transform}\n\nWe start with the set of scalar products $c_0(k)=<f(x),\\phi(x-k)>$. If\n$\\phi(x)$ has a cut-off frequency $\\nu_c\\le {1\\over 2}$\n(\\cite{starck:sta94_3,starck:sta94_4,starck:book98}), \nthe data are\ncorrectly sampled. The data at resolution $j=1$ are:\n\\begin{eqnarray}\nc_1(k)=<f(x),\\frac{1}{2}\\phi(\\frac{x}{2}-k)>\n\\end{eqnarray}\nand we can  compute the set $c_{1}(k)$ from $c_0(k)$ with a discrete \nfilter $\\hat h(\\nu)$:\n\\begin{eqnarray}\n\\hat h(\\nu)= \\left\\{\n  \\begin{array}{ll}\n  {\\hat{\\phi}(2\\nu)\\over \\hat{\\phi}(\\nu)} & \\mbox{if } \\mid \\nu \\mid < \\nu_c \\\\\n0 & \\mbox{if } \\nu_c  \\leq \\mid \\nu \\mid < {1\\over 2} \n  \\end{array}\n  \\right.\n\\end{eqnarray}\nand\n\\begin{eqnarray}\n\\forall \\nu, \\forall n \\mbox{    } & \\hat h(\\nu + n) = \\hat h(\\nu)\n\\end{eqnarray}\nwhere $n$ is an integer.\nSo:\n\\begin{eqnarray}\n\\hat{c}_{j+1}(\\nu)=\\hat{c}_{j}(\\nu)\\hat{h}(2^{j}\\nu)\n\\end{eqnarray}\nThe cut-off frequency is reduced by a factor $2$ at each step, allowing  a\nreduction of the number of samples by this factor.\n\nThe wavelet coefficients at scale $j+1$ are:\n\\begin{eqnarray}\nw_{j+1}(k)=<f(x),2^{-(j+1)}\\psi(2^{-(j+1)}x-k)>\n\\end{eqnarray}\nand they can be computed directly from $c_j(k)$ by:\n\\begin{eqnarray}\n\\hat{w}_{j+1}(\\nu)=\\hat{c}_{j}(\\nu)\\hat g(2^{j}\\nu)\n\\end{eqnarray}\nwhere $g$ is the following  discrete filter:\n\\begin{eqnarray}\n\\hat g(\\nu)= \\left\\{\n  \\begin{array}{ll}\n  {\\hat{\\psi}(2\\nu)\\over \\hat{\\phi}(\\nu)} & \\mbox{if } \\mid \\nu \\mid < \\nu_c \\\\\n1 & \\mbox{if } \\nu_c  \\leq \\mid \\nu \\mid < {1\\over 2} \n  \\end{array}\n  \\right.\n\\end{eqnarray}\nand\n\\begin{eqnarray}\n\\forall \\nu, \\forall n \\mbox{    } & \\hat g(\\nu + n) = \\hat g(\\nu)\n\\end{eqnarray}\n\nThe frequency band is also reduced by a factor $2$ at each step.\nApplying the sampling theorem, we can build a pyramid  of\n\\index{pyramid}\n $N+{N\\over 2}+\\ldots+1=2N$ elements.\nFor an image analysis the number of elements is ${4\\over 3}N^2$. The\noverdetermination is not very high.\n\nThe B-spline functions are compact in direct space. They\ncorrespond to the autoconvolution of a square function. In\nFourier space we have:\n\\index{Fourier transform}\n\\begin{eqnarray}\n\\hat B_l(\\nu)=({\\sin\\pi\\nu\\over\\pi\\nu})^{l+1}\n\\end{eqnarray}\n$B_3(x)$ is a set of $4$ polynomials of degree $3$.\nWe choose the scaling function $\\phi(\\nu)$ which has a\n$B_3(x)$ profile in Fourier space:\n\\begin{eqnarray}\n\\hat{\\phi}(\\nu)={3\\over 2}B_3(4\\nu)\n\\end{eqnarray}\nIn direct space we get:\n\\begin{eqnarray}\n\\phi(x)={3\\over 8}[{\\sin{\\pi x\\over 4}\\over {\\pi x\\over\n4}}]^4\n\\end{eqnarray}\nThis function is quite similar to a Gaussian and converges\nrapidly to $0$. For 2-dimensions the scaling function is defined by\n$\\hat \\phi(u,v) = {3\\over 2}B_3(4r)$, with $r = \\sqrt(u^2+v^2)$.\nThis is an isotropic function.\n\nThe wavelet transform algorithm with $n_p$ scales is the following:\n\\index{wavelet transform}\n\\begin{enumerate}\n\\item Start with a $B_3$-spline scaling function and derive $\\psi$, $h$ and\n$g$ numerically.\n\\item Compute the corresponding FFT image. \nName the resulting complex array $T_0$.\n\\item Set $j$ to $0$. Iterate:\n\\item Multiply  $T_j$ by $\\hat g(2^ju,2^jv)$. We get the complex array\n$W_{j+1}$. The inverse FFT\ngives the wavelet coefficients at scale $2^j$;\n\\item Multiply  $T_j$ by $\\hat h(2^ju,2^jv)$. We get the array\n$T_{j+1}$. Its inverse FFT gives the image at scale $2^{j+1}$.\nThe frequency band is reduced by a factor $2$.\n\\item Increment $j$.\n\\item If $j \\leq  n_p$, go back to 4.\n\\item The set $\\{w_1, w_2, \\dots, w_{n_p}, c_{n_p}\\}$ describes the\nwavelet transform.\n\\end{enumerate}\nIf the wavelet is the difference between two resolutions, i.e.\n\\begin{eqnarray}\n\\hat \\psi(2\\nu) = \\hat \\phi(\\nu) - \\hat \\phi(2\\nu)\n\\end{eqnarray}\nand:\n\\begin{eqnarray}\n\\hat g(\\nu) = 1 - \\hat h(\\nu)\n\\end{eqnarray}\nthen the wavelet coefficients $\\hat w_j(\\nu)$ can be computed by \n$\\hat c_{j-1}(\\nu) - \\hat c_j(\\nu)$.\n\n\\subsubsection*{Reconstruction.}\nIf the wavelet is the difference between two resolutions,\nan evident reconstruction for a wavelet transform \n${\\cal W} = \\{w_1,\\dots, w_{n_p}, c_{n_p}\\}$ is:\n\\begin{eqnarray}\n\\hat c_0(\\nu) = \\hat c_{n_p}(\\nu) + \\sum_j \\hat w_j(\\nu)\n\\end{eqnarray}\nBut this is a particular case, and other alternative wavelet functions can be\nchosen. The reconstruction can be made step-by-step, starting from\nthe lowest resolution. At each scale, we have the relations:\n\\begin{eqnarray}\n\\hat c_{j+1} = \\hat h(2^j \\nu) \\hat c_j(\\nu) \\\\\n\\hat w_{j+1} = \\hat g(2^j \\nu) \\hat c_j(\\nu) \n\\end{eqnarray}\nWe look for $c_j$ knowing $c_{j+1}$, $w_{j+1}$, $h$ and $g$.\nWe restore $\\hat c_j(\\nu)$ based on a least mean square estimator:\n\\begin{eqnarray}\n\\hat p_h(2^j\\nu) \\mid \\hat c_{j+1}(\\nu)-\\hat h(2^j\\nu)\\hat c_j(\\nu) \\mid^2 + \n\\nonumber \\\\\n\\hat p_g(2^j\\nu) \\mid \\hat w_{j+1}(\\nu)-\\hat g(2^j\\nu)\\hat c_j(\\nu) \\mid^2\n\\end{eqnarray}\nis to be minimum. $\\hat p_h(\\nu)$ and $\\hat p_g(\\nu)$ are weight\nfunctions which permit a general solution to the\nrestoration of $\\hat c_j(\\nu)$. From the derivation of $\\hat c_j(\\nu)$  we get:\n\\begin{eqnarray}\n\\hat{c}_{j}(\\nu)=\\hat{c}_{j+1}(\\nu) \\hat{\\tilde h}(2^{j}\\nu)\n                +\\hat{w}_{j+1}(\\nu) \\hat{\\tilde g}(2^{j}\\nu)\n\\label{restauration}\n\\end{eqnarray} \nwhere the conjugate filters have the expression:\n\\begin{eqnarray}\n\\hat{\\tilde h}(\\nu) & = {\\hat{p}_h(\\nu) \\hat{h}^*(\\nu)\\over \\hat{p}_h(\\nu)\n\\mid \\hat{h}(\\nu)\\mid^2 + \\hat{p}_g(\\nu)\\mid \\hat{g}(\\nu)\\mid^2} \\label{eqnht} \\\\ \n\\hat{\\tilde g}(\\nu) & = {\\hat{p}_g(\\nu) \\hat{g}^*(\\nu)\\over \\hat p_h(\\nu)\n\\mid \\hat{h}(\\nu)\\mid^2 + \\hat{p}_g(\\nu)\\mid \\hat{g}(\\nu)\\mid^2}\n\\label{eqngt}\n\\end{eqnarray}\n\nIn this analysis, the\nShannon sampling condition is always respected and no aliasing\nexists.\n\nThe denominator is reduced if we choose:\n\\[\\hat{g}(\\nu) = \\sqrt{1 - \\mid\\hat{h}(\\nu)\\mid^2}\\]\nThis corresponds to the case where the wavelet is the difference between\nthe square of two resolutions:\n\\begin{eqnarray}\n\\mid \\hat \\psi(2\\nu)\\mid^2  \\ = \\ \\mid \\hat \\phi(\\nu)\\mid^2  - \\mid  \\hat\n\\phi(2\\nu)\\mid^2 \n\\end{eqnarray}\n\n% \\begin{figure}[htb]\n% \\centerline{\n% \\hbox{\n% \\psfig{figure=ch1_diff_uv_phi_psi.ps,bbllx=0.5cm,bblly=13.5cm,bburx=20.5cm,bbury=27cm,height=6cm,width=14.cm,clip=}\n% }}\n% \\caption{On the left, the interpolation function $\\hat{\\phi}$ and, on the \n% right, the wavelet  $\\hat{\\psi}$.}\n% \\label{fig_diff_uv_phi_psi}\n% \\end{figure}\n\n% \\begin{figure*}[htb]\n% \\centerline{\n% \\hbox{\n% \\psfig{figure=ch1_diff_uv_ht_gt.ps,bbllx=0.5cm,bblly=13.5cm,bburx=20.5cm,bbury=27cm,height=5cm,width=14.5cm,clip=}\n% }}\n% \\caption{On the left, the filter $\\hat{\\tilde{h}}$, and on the right the \n% filter $\\hat{\\tilde{g}}$.}\n% \\label{fig_diff_uv_ht_gt}\n% \\end{figure*}\n\n% In Fig.\\ \\ref{fig_diff_uv_phi_psi} the chosen scaling function \n% derived from a B-spline of degree \n% 3, and its resulting wavelet function, are plotted in frequency space.\n \nThe reconstruction algorithm is:\n\\begin{enumerate}\n\\item Compute  the FFT of the image at the low resolution.\n\\item Set $j$ to $n_p$. Iterate:\n\\item Compute the FFT of the wavelet coefficients at scale $j$.\n\\item Multiply  the wavelet coefficients $\\hat{w}_j$ by $\\hat{\\tilde{g}}$.\n\\item Multiply   the image at the lower resolution $\\hat{c}_j$ by \n$\\hat{\\tilde{h}}$.\n\\item The inverse Fourier transform of the addition of  \n$\\hat{w}_j\\hat{\\tilde{g}}$ and $\\hat{c}_j\\hat{\\tilde{h}}$ gives the \nimage $c_{j-1}$.\n\\item Set $j = j - 1$ and return to 3.\n\\end{enumerate}\n\\index{Fourier transform}\n\nThe use of a scaling function with a cut-off frequency\nallows a reduction of sampling at each scale, and limits the  \ncomputing time and the memory size. \n\n", "meta": {"hexsha": "c77910ccb13c03057bb8d6efecd94b03649d6e6a", "size": 7683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr4/Annex_FFT.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/Annex_FFT.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/Annex_FFT.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.5857142857, "max_line_length": 117, "alphanum_fraction": 0.6718729663, "num_tokens": 2887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6936720098668552}}
{"text": "\\begin{document}\n\t\\chapter{Integration}\n\t\\section{Reduction Formul\\ae}\n\tIntegrating using a reduction formula is in essence repeating integration by parts over and over again.\\\\\n\t\n\t\n\t We can think of the process of finding a reduction formula for a given integral as a \\emph{recursive approach} to integration by parts. By listing all the iterations of $\\textstyle\\int u\\od vx\\,dx= uv-\\int v\\od ux\\,dx$, more specifically the $\\textstyle\\int v\\od ux\\,dx$ part in terms of $I_n$ where $n$ is the \\emph{iterative index}, or the \\textit{step number}, if you will.\\\\\n\t\n\tAs expected, finding this recursively valid form is not as direct, and thus, the exponent has to be \\textit{split} in such a way that trigonometric identities can be used.\n\t\\begin{example}\n\t\tIf $I_n = \\int \\cos^n x \\, dx$ show that $I_n = \\frac{1}{n} \\sin\\cos^{n-1}x + \\frac{n-1}{n}\\cdot I_{n-2}$. Hence find $\\int \\cos^5x\\, dx$.\n\t\\end{example}\n\t\n\t\\begin{align*}\n\t\tI_n                  & = \\int \\cos^n x \\, dx                                                       \\\\\n\t\t& = \\int \\cos x \\cdot \\cos^{n-1}x\\, dx                                        \\\\\n\t\t%&\\quad \\text{Integrating by parts: }\\\\\t\t\t\t\t\t\t\t\n\t\t\\therefore \\quad I_n & = \\cos^{n-1}x\\sin x + (n-1)\\int\\cos^{n-2}x\\sin^2x\\,dx                       \\\\\n\t\t& = \\cos^{n-1}x\\sin x + (n-1)\\int\\cos^{n-2}x(1-\\cos^2x)\\,dx                   \\\\\n\t\t& = \\cos^{n-1}x\\sin x + (n-1)\\int\\cos^{n-2}x \\, dx \\,-\\, (n-1)\\int\\cos^nx\\,dx \\\\\n\t\t& = \\cos^{n-1}x\\sin x + (n-1)I_{n-2} - (n-1)I_n                               \\\\\n\t\tI_n + (n-1)I_n       & = \\cos^{n-1}x\\sin x + (n-1)I_{n-2}                                          \\\\\n\t\t\\implies  nI_n       & = \\cos^{n-1}x\\sin x + (n-1)I_{n-2}                                          \\\\\n\t\t\\implies I_n         & = \\frac1n\\cos^{n-1}x\\sin x + \\left(\\frac{n-1}n\\right)I_{n-2}                \\\\\n\t\\end{align*}\n\t\n\t\\begin{align*}\n\t\t\\int \\cos^5 x \\, dx   =\\,      & I_5                                                                                                                 \\\\\n\t\t& I_5 = \\frac{1}{5} \\cos^4x\\sin x + \\frac45I_3                                                                        \\\\\n\t\t& I_3 = \\frac{1}{5} \\cos^4x\\sin x + \\frac{4}{5}I_1                                                                    \\\\\n\t\t& I_1 = \\int \\cos x \\, dx = \\sin x + k                                                                                \\\\\n\t\t\\therefore \\quad \\int \\cos^5 x & = \\frac{1}{5}\\cos^4x \\sin x + \\frac{4}{5}\\left(\\frac{1}{3}\\cos^2x\\sin x + \\frac{2}{3}\\left(\\sin x + k\\right)\\right) \\\\\n\t\t& =\\frac{1}{5}\\cos^2x\\cdot\\sin x + \\frac4{15} \\cos^2 x \\cdot \\sin x + \\frac{8}{15}\\sin x + c   \\qed                   \n\t\\end{align*}\t  \t\t\t\t\t\t\n\t\t\\hrulefill\n\t\\begin{example}\n\t\tIf $I_n = \\int \\tan^n\\theta \\, d\\theta$, find a reduction formula for $I_n$ and use it to evaluate $\\int_0^{\\frac\\pi4} \\tan^6\\theta\\,d\\theta$.\n\t\\end{example}\n\t\n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\tI_n &= \\int \\tan^n\\theta \\, d\\theta\\\\\n\t\t\t&= \\int \\tan^2\\theta \\tan^{n-2}\\theta\\, d\\theta\\\\\n\t\t\t&= \\int (\\sec^2\\theta - 1) \\tan^{n-2}\\theta\\, d\\theta\\\\\n\t\t\t&= \\int \\sec^2\\theta\\tan^{n-2}\\theta\\,d\\theta - \\int \\underbrace{\\tan^{n-2}\\theta\\,d\\theta}\\\\\n\t\t\t&= \\frac{\\tan^{n-1}\\theta}{n-1} - \\underbrace{I_{n-2}}\n\t\t\\end{split}\n\t\t\\qquad\\qquad\\qquad\n\t\t\\begin{split}\n\t\t\t\\int_0^{\\frac\\pi4}\\tan^6\\theta\\,d\\theta &= I_6\\bigg|_0^{\\frac\\pi4}\\\\\n\t\t\tI_6 &= \\frac{tan^5\\theta}{5} - I_4\\\\\n\t\t\tI_4 &= \\frac{\\tan^3\\theta}{3} - I_2\\\\\t\t\n\t\t\tI_2 &= \\tan\\theta - I_0\\\\\n\t\t\tI_0 &= \\int 1 \\, d\\theta = \\theta + k\n\t\t\\end{split}\n\t\\end{equation*}\n\t\\begin{align*}\n\t\t\\therefore \\int_0^\\frac\\pi4  \\tan^6\\theta \\, d\\theta & =  \\frac{\\tan^6\\theta}5 - \\frac{\\tan^3\\theta}{3} + \\tan\\theta - \\theta\\bigg|_0^\\frac\\pi4 \\\\\n\t\t& = \\frac15 - \\frac13 + 1 - \\frac{\\pi}{4}                                                  \\\\\n\t\t& = \\frac{13}{15} - \\frac{\\pi}{4}   \\qed                                                   \n\t\\end{align*}\n\t\t\\hrulefill\\newpage\n\t\n\t\\begin{example}\n\t\tEstablish a reduction formula that could be used to find $\\int x^ne^x \\, dx$ and use it to find $\\int x^4e^4$.\n\t\\end{example}\n\t\n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\text{Let } I_n &= \\int x^ne^x \\, dx \\\\\n\t\t\t\\text{Let } u \t&= x^n    \\qquad   \\od{v}{x} = e^x \\\\\n\t\t\t\\od{u}{x}     \t&= nx^{n-1} \\qquad  v = e^x         \\\\\n\t\t\t\\therefore \\quad I_n\t&= x^ne^x - n \\int x^{n-1}e^x \\, dx\\qquad\\\\\n\t\t\t&= x^ne^x - n\\, I_{n-1}\n\t\t\\end{split}\n\t\t\\begin{split}\n\t\t\t&\\int x^4e^x = I_4\\\\\n\t\t\t&I_4 = x^4e^x - 4I_3\\\\\n\t\t\t&I_3 = x^3e^x - 3I_2\\\\\n\t\t\t&I_2 = x^2e^x - 2I_1\\\\\t\t\n\t\t\t&I_1 = xe^x - I_0\\\\\t\t\t\t \t\t \t\n\t\t\t&I_0 = e^x + k\n\t\t\\end{split}\n\t\\end{equation*}\n\t\\begin{align*}\n\t\t\\therefore \\quad I_4 & = x^4e^x -4(x^3e^x - 3(x^2e^x - 2(xe^x - e^x + k))) \\\\\n\t\t& = x^4e^x -4x^3e^x + 12x^2e^x - 24xe^x + 24e^x + c   \\qed\n\t\\end{align*}\n\t\t\\hrulefill\n\t\\begin{example}\n\t\tEstablish a reduction formula which can be used to evaluate $\\int x^n \\sin x \\, dx$.\n\t\\end{example}\n\t\n\t\\begin{align*}\n\t\t\\text{Let } I_n &= \\int x^n \\cdot \\sin x\\\\\n\t\t\t\t\t\t&= -x^n\\cos x + \\int nx^{n-1}\\cos x\\,dx\\\\\n\t\t\t\t\t\t&= -x^n\\cos x + n\\left(x^{n-1}\\sin x - \\int (n-1)x^{n-2}\\sin x\\,dx\\right)\\\\\n\t\t\t\t\t\t&= -x^n\\cos x + n\\left(x^{n-1}\\sin x - (n-1) \\int x^{-2} \\cdot x^n\\sin x\\,dx\\right)\\\\\n\t\t\t\t\t\t&= -x^n\\cos x + n\\left(x^{n-1}\\sin x - (n-1) \\underbrace{x^{n-2}\\sin x\\,dx}\\right)\\\\\n\t\t\t\t\t\t\\therefore \\quad I_n &= -x^n\\cos x + n\\left(x^{n-1}\\sin x - (n-1)I_{n-2}\\right)\\\\\n\t\t\t\t\t\t&= -x^n\\cos x + nx^{n-1}\\sin x - n(n-1)I_{n-2} \\qed\n\t\\end{align*}\n\t\\hrulefill\\newpage\n\t\n\t\\begin{example}\n\t\tEstablish a reduction formula to find $\\int \\csc^nx \\, dx$. Hence find $\\int csc^5x \\, dx$\n\t\\end{example}\n\n\n\t\\begin{align*}\n\t\t\\text{Let } I_n &= \\int \\csc^nx \\, dx\\\\\n\t\t&= \\int \\csc^2x \\cdot \\csc^{n-2}x \\, dx\\\\\n\t\t\\text{Let } u & = \\csc^{x-2} x              \\qquad \\od{v}{x} = \\csc^2x \\, dx \\\\\n\t\t\\od{u}{x}     & = -(n-2)\\csc^{n-2}\\cot x  v \\qquad = -\\cot x                 \\\\\n\t\t\\therefore \\int \\csc^nx \\, dx &= -\\cot x \\cdot \\csc^{n-2}x  - (n-2)\\int \\csc^{n-2}x\\cot^2x \\, dx\\\\\n\t\tI_n &= \t-\\cot x \\cdot \\csc^{n-2}x - (n-2)\\int \\csc^{n-2}x\\left(\\csc^2x - 1\\right) \\, dx\\\\\n\t\t&= \t\t-\\cot x \\cdot \\csc^{n-2}x - (n-2)\\int \\csc^{n}x\\,dx + (n-2)\\int\\csc^{n-2}xdx\\\\\n\t\t&=-\\cot x \\cdot \\csc^{n-2}x  - (n-2)\\, I_n + (n-2)I_{n-2}\\\\\n\t\tI_n + nI_n -2I_n &= -\\cot x\\cdot \\csc^{n-2}x  + (n-2)I_{n-2}\\\\\n\t\t(n-1)I_n &= -\\cot x\\cdot \\csc^{n-2}x  + (n-2)I_{n-2}\\\\\n\t\tI_n &= \\frac{-1}{n-1}-\\cot x\\cdot \\csc^{n-2}x + \\frac{n-2}{n-1}I_{n-2}\\\\\n\t\t&= \\left(1-\\frac{1}{n-1}\\right)I_{n-2}-\\frac{\\cot x\\csc^{n-2}x}{n-1}\\qed\n\t\\end{align*}\n\t\\begin{example}\n\t\tShow that if $I_n - \\int_0^\\pi x^n\\sin x\\,dx$, then $I_n = \\pi^n - n(n-1)\\,I_n-1$. Hence evaluate $\\int_0^\\pi\\sin x\\,dx$\n\t\\end{example}\n\t\\begin{align*}\n\t\tI_n &=\\left[-x^n\\cos x\\right]_0^\\pi + n\\int_0^\\pi x^{n-1} \\cos x \\, dx\\\\\n\t\t&=\\pi^n + n\\int_0^\\pi x^{n-1} \\cos x \\, dx\\\\\n\t\t&= \\pi^n \\int_0^\\pi \\\\\n\t\t\\text {Let } u &=\n\t\\end{align*}\n\t\\begin{example}\n\t\tShow that, if $I_n = \\int_0^1 x^n e^{x^3} \\, dx$, then $I_n =\\frac{e}{3} - \\frac{n-2}{3} \\cdot I_{n-3}$\n\t\\end{example}\n\t\n\t\\begin{align*}\n\t\tI_n &= \\int_0^1 x^n e^{x^3} \\, dx\\\\\n\t\t&= \\int_0^1 x^{n-2}x^2e^{x^3} \\, dx\\\\\n\t\t\\therefore \\quad I_n &= \\left[\\frac{x^{n-2}e^{x^3}}3\\right]_0^1 - \\frac{n-2}3 \\int_0^1 x^{n-3}{e^{x^3}} \\, dx\\\\\n\t\t&= \\frac{e}3 - \\frac{n-2}3 \\cdot I_{n-3}\n\t\\end{align*}\n\t\n\t\\begin{example}\n\t\tShow that, if $I_n= \\int_0^1 x^n(1+x^5)^4 \\, dx$, then $I_n = \\frac1{n+21} \\left[32-(n-4)\\cdot I_{n-5}\\right]$\n\t\\end{example}\n\t\n\t\\begin{align*}\n\t\tI_n                 & = \\int_0^1 x^n(1+x^5)^4 \\, dx                                                                           \\\\\n\t\t& = x^{n-4}x^4(1+x^5)^4\\,dx                                                                               \\\\\n\t\t& =\\left[x^{n-4} \\frac{(1+x^5)^5}{25}\\right]_0^1 - \\frac{n-4}{25} \\int x^{n-5}(1+x^5)^5\\,dx               \\\\\n\t\t& = \\frac{32}{25}  -\\frac{n-4}{25} \\int_0^1x^n-5(1+x^5)(1+x^5)^4\\,dx                                      \\\\\n\t\t& = \\frac{32}{25} - \\frac{n-5}{25}\\int_0^1x^{n-5}(1+x^5)^4\\, dx - \\frac{n-4}{25}\\int_0^1x^n(1+x^5)^4\\, dx \\\\\n\t\t& = \\frac{32}{25} - \\left(\\frac{n-4}{25}\\right)I_{n-5} - \\left(\\frac{n-4}{25}\\right)I_n                   \\\\\n\t\t25I_n               & = 32 - (n-4)I_{n-5} - \\left(\\frac{n-4}{25}\\right)\\,I_n                                                  \\\\\n\t\t25I_n + nI_n - 4I_n & = 32-(n-4)\\,I_{n-5}\\\\\n\t\t(n+21)I_n &= 32-(n-4)I_{n-5}\\\\\n\t\tI_n &= \\frac{1}{n+21}\\left(32-(n-4)I_{n-5}\\right)\n\t\\end{align*}\n\t\\hrulefill\n\t\\newpage\n\t\\begin{example}\n\t\tGiven $I_n = \\int_0^1 (1+x^2)^{-n}\\,dx$, show that $2n\\,I_{n+1} = 2^{-n} + (2n-1)\\,I_n$\n\t\\end{example}\n\t\\begin{align*}\n\t\tI_n                   & = \\int_0^1 (1+x^2)^{-n}\\,dx                                             \\\\\n\t\t& = \\int_0^1  (1+x^2)^{-n}\\cdot 1 \\,dx                                    \\\\\n\t\t\\therefore \\quad  I_n & = -2nx^2(1+x^2)^{-(n+1)}\\bigg|_0^1 + 2n \\int_0^1x^2(1+x^2)^{-n-1}\\,dx   \\\\\n\t\t\t\t\t\t   \t  & =2^{-n} + 2n\\int_0^1(x^2+1-1)(1+x^2)^{-(n+1)}\\,dx                       \\\\\n\t\t\t\t\t\t      & =2^{-n} + 2n \\int_0^1(1+x^2)^{-2}\\,dx - 2n\\int_0^1 (1+x^2)^{-(n+1)}\\,dx \\\\\n\t\t\t\t\t\t\t  & = 2^{-n} + 2n\\,I_n - 2n\\,I_{n+1}                                        \\\\\n           \t      2n\\,I_{n+1} & = 2^{-n} + (2n-1)\\,I_n                                                 \n\t\\end{align*}\n\\end{document}", "meta": {"hexsha": "138f61f8b7a99c2fe64a3f8b21b6744066ece516", "size": 9168, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/Integration.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/Integration.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/Integration.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": 52.6896551724, "max_line_length": 380, "alphanum_fraction": 0.4541884817, "num_tokens": 4075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.693672007497173}}
{"text": "\\documentclass{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\n\\setlength{\\bigskipamount}{8em}\n\\setlength{\\parindent}{3em}\n\\setlength{\\parskip}{1em}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{question}{Q.}\n\\newtheorem{answer}{A.}\n\n\\begin{document}\n\\author{Dave Neary}\n\\title{Introduction to Modular Arithmetic}\n\n\\maketitle\n\n\\section{Modular arithmetic}\n\nLet's start with a question: $3.141592653589793238462643383279$ is the value of \n$\\pi$ to 30 decimal places. Is the number 3141592653589793238462643383279 the\nsquare of an integer?\n\nRather than attempting to answer ths question directly, let's do some exploration\nof squares of integers, to see if we can find some common characteristics.\n\n\\begin{table}[htb]\n\\begin{tabular}{|c|c|c|}\n\\hline\n\t$n$ & $n^2$ & rem($\\frac{n^2}{4}$) \\\\   \n\\hline \n\t1 &  1 & 1 \\\\\n\t2 &  4 & 0 \\\\\n\t3 &  9 & 1 \\\\\n\t4 & 16 & 0 \\\\\n\t5 & 25 & 1 \\\\\n\t6 & 36 & 0 \\\\\n\t7 & 49 & 1 \\\\\n\\hline \n\\end{tabular}\n\\end{table}\n\nInterestingly, it seems like every even square has a remainder of 0 when we divide\nby 4, and every odd square has a remainder of 1 (and in fact, appears to be 1 more than a multiple of 8).\nWe can prove that this is the case in general quite easily:\n\n\\[ n = 2k \\implies n^2 = 4k^2 \\]\n\\[ n = 2k+1 \\implies n^2 = 4k^2 + 4k + 1 = 4(k^2+k) + 1 \\]\n\n\nWe can now return to our original question - a simple initial test for whether a\nnumber is a square of an integer is to check its remainder when divided by 4. And\nwe only need to look at the last two digits to check because $100n+m =4(25n)+m$ -\nso we can ignore everything before the last 2 digits. In our example, \n$79 = 4\\times 19 + 3$, so the number at the start of this section is \\textbf{not}\nthe square of an integer.\n\n\\subsection{Working with remainders}\n\nThis example gives a glimpse of something called modular arithmetic - sometimes,\nwe can draw conclusions related to a problem by looking only at the remainders\nwhen divided by a number. In terms of notation, we say that $a \\equiv b \\pmod{n}$\nwhen $a = m\\cdot n+b$ for some integer $m$. In the example above, we can write:\n$a^2 \\equiv 0 \\text{ or } 1 \\pmod{4} \\text{ for all } a\\in \\mathbb{Z}$.\n\nThere are a few operations that hold for all numbers $\\pmod{n}$:\n\nRemainders are additive and multiplicative:\n\\begin{eqnarray*}\n\t(a\\pmod{n}) + (b\\pmod{n}) & = & (a+b)\\pmod{n} \\\\\n\t(a\\pmod{n}) \\cdot (b\\pmod{n}) & = & (a\\cdot b) \\pmod{n}\n\\end{eqnarray*}\n\nSo we can tell that if $a=76$ and $b=42$, when we multiply them together, the\nremainder when we divide the result by 5 will be $76 \\pmod{5} \\times 42 \\pmod{5}\n= 1\\times 2 \\pmod{5}$. We say that $a \\equiv b \\pmod{n}$ ($a$ is congruent to $b$\nmod $n$) if $n|(a-b)$ - that is, if we subtract one number from another, and they\nhave the same remainder when divided by $n$, then their difference is a multiple\nof $n$.  \n\nJust the basics of modular arithmetic allow us to address a whole range of problems already.\n\n\\begin{question}Prove that $6\\cdot 4^n - 6$ is divsible by 9 for all $n$.\\end{question}\n\\begin{proof}\n\tLet's look at the values of $6 \\cdot 4^n \\pmod{9}$ for different\nvalues of $n$. \n\n\\begin{table}[htb]\n\\begin{tabular}{|c|c|c|}\n\\hline\n\t$n$ & $4^n \\pmod{9}$ & $6\\cdot 4^n \\pmod{n}$\\\\   \n\\hline \n\t0 & 1 & 6 \\\\\n\t1 & 4 & 6 \\\\\n\t2 & 7 & 6 \\\\\n\t3 & 1 & 6 \\\\\n\\hline \n\\end{tabular}\n\\end{table}\n\nClearly, $4^n$ cycles through the values 1, 4, 7 for all $n$, and each of these multiplied\nby $6$ gives a remainder of 6 when divided by 9. Another way of putting this is that\n$4^n \\equiv 1 +3k \\pmod{9}$ for $n\\equiv k \\pmod{3}$, and since $6\\cdot 3 = 18 \\equiv 0 \\pmod{9}$\n$6\\times (1+3k) \\equiv 6 \\pmod{9}$ for all $n$.\n\\end{proof}\n\n\\begin{question}What are the last two digits base 10 of $6^{19}$?\\end{question}\n\n\\begin{answer} This is an intimidating looking question, but modular arithmetic offers us a\npowerful tool to simplify things. $6^2 = 36 \\pmod{100}$, $6^3 = 216 \\equiv 16 \\pmod{100}$,\n$6^4 \\equiv 96 \\pmod{100} \\equiv -4 \\pmod{100}$, $(6^4)^2 = 6^8 \\equiv (-4^2) = 16 \\pmod{100}$\nSo we have $6^8 \\equiv 6^3 \\pmod{100}$ But now we have: \n\\begin{eqnarray*}\n\t6^{19} & =&  (6^8)^2\\cdot 6^3 \\\\\n               & \\equiv & (6^3)^3 \\pmod{100} \\\\\n\t       & \\equiv & 6^{9} \\pmod{100} \\\\\n\t       & \\equiv & 6^8\\cdot 6 \\pmod{100} \\\\\n\t       & \\equiv & 6^4 \\pmod{100} \\\\\n\t       & \\equiv & 96 \\pmod{100} \n\\end{eqnarray*}\n\\end{answer}\n\nYou can use modular arithmetic to prove common divisibility tricks.\n\n\\begin{question}Prove that 9 divides a number if and only if it divides the sum of its digits.\\end{question}\n\\vspace*{\\bigskipamount}\n\n\\begin{question}Prove that a number is divisible by 8 if its last 3 digits are divisible by 8.\\end{question}\n\\vspace*{\\bigskipamount}\n\n\\begin{question}Prove that a number is divisible by 11 if the sum of its even digits minus the\nsum of its odd digits is divisible by 11.\\end{question}\n\\vspace*{\\bigskipamount}\n\n\\subsection{Fermat's Little Theorem}\n\nFermat made an interesting observation when working with remainders modulo a prime number. If you\nrepeatedly multiplied any number not divisible by a prime number $p$, and took just the remainder\n$\\mod (p)$, that $p$ would eventually divide $a^k - 1$ for some number, and that $k$ always divided\nevenly into $p-1$. Equivalently, for any number not divisible by $p$, $a^{p-1} \\equiv 1 \\pmod{p}$.\nMore generally, $a^p \\equiv a \\pmod{p}$ for all $a\\in \\mathbb{Z}$\n\nLet's work through an example to see how it works with $p=7$:\n\n\\begin{table}[htb]\n\\begin{tabular}{|c|c|c|c|c|c|c| }\n\\hline\n\t$a$ & $a^2$ & $a^3$ & $a^4$ & $a^5$ & $a^6$ \\\\\n\\hline  \n\t1 & 1 & 1 & 1 & 1 & 1 \\\\\n\t2 & 4 & 1 & 2 & 4 & 1 \\\\\n\t3 & 2 & 6 & 4 & 5 & 1 \\\\\n\t4 & 2 & 1 & 4 & 2 & 1 \\\\\n\t5 & 4 & 6 & 2 & 3 & 1 \\\\\n\t6 & 1 & 6 & 1 & 6 & 1 \\\\\n\\hline  \n\\end{tabular}\n\\end{table}\n\nTo show how we get the table entries, let's look at row 5 for example:\n\\begin{eqnarray*}\n\t5^2 &=& 25 \\equiv 4 \\pmod{7}\\\\\n\t5^3 &=& 5 \\times 4 \\equiv 6 \\pmod{7} \\\\\n\t5^4 &=& 5 \\times 6 \\equiv 2 \\pmod{7} \\\\\n\t5^5 &=& 5 \\times 2 \\equiv 3 \\pmod{7} \\\\\n\t5^6 &=& 5 \\times 3 \\equiv 1 \\pmod{7}\n\\end{eqnarray*}\n\nIf you look at how many times you need to multiply a number by itself to get back to 1, you can\nsee that for 1, the cycle length is 1, for $6\\equiv-1 \\pmod{7}$ it is 2, for 2 and 4 it is 3,\nand for 3 and 5, it is 6. In all cases the cycle length divides $p-1$.\n\nIn many equations where we want to prove that solutions are or are not possible for equations\nincluding prime numbers, we can do so using Fermat's Little Theorem and modular arithmetic.\n\n\\begin{question} \nWhat is the value of $2001^{2002} \\pmod{2003}$?\n\\end{question}\n\n\\begin{answer}\n\tThere are often questions like this with year numbers in the question - it is a good idea to\n\tknow if the current year (or one more than the current year) has some interesting property.\n\tIn this case, let's check whether 2003 is a prime. To do so, we need to check whether it\n\tis divisible by any prime number less than $\\sqrt{2003} \\approx 44$.\n\n\tWe can quickly see with basic divisibility tricks that it is not divisible by 2 (last\n\tdigit is odd), 3 (sum of digits is not a multiple of 3), 5 (last digit is not 0 or 5), 11\n\t(summing the alternating digits does not give the same number mod 11). So we only have to\n\tcheck divisibility by 7, 13, 17, 19, 23, 29, 31, 37, 41, and 43 to verify if 2003 is prime.\n\tI will leave that as an excercise.\n\n\tIf 2003 is prime, then by Fermat's Little Theorem, $a^2002 \\equiv 1 \\pmod{2003}$.\n\\end{answer}\n\n\\begin{question}\n\tWhat is the remainder when you divide $4^{87}$ by 17?\n\\end{question}\n\\begin{answer}\n\tWe know by Fermat's Little Theorem that $4^{16} \\equiv 1 \\pmod{17}$.\n\tThen:\n\t\\begin{eqnarray*}\n\t\t4^{87} &=& (4^{16})^5 \\times 4^7 \\pmod{17} \\\\\n\t\t&=& (4^2)^3 \\times 4 \\pmod{17} \\\\\n\t\t&=& (-1)^3 \\times 4 \\pmod{17} \\\\\n\t\t&=& -4 \\pmod{17} = 13 \\pmod{17}\n\t\\end{eqnarray*}\n\\end{answer}\n\n\\begin{question}Find $6^{1000} \\pmod{23}$. (AOPS)\\end{question}\n\\vspace*{\\bigskipamount}\n\n\\begin{question}What are the last two digits of $7^{9999}$? (MATHCOUNTS 1986)\\end{question}\n\\vspace*{\\bigskipamount}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "4fa5735acb0f9a8dc879808d36ba4fa4530ad45a", "size": 8049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modular_arithmetic.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": "modular_arithmetic.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": "modular_arithmetic.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": 36.4208144796, "max_line_length": 108, "alphanum_fraction": 0.6700211206, "num_tokens": 2888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.9019206850975361, "lm_q1q2_score": 0.6936493743138067}}
{"text": "\\chapter{Assignment-Matrices}\n\\section{MCQ}\n\\begin{enumerate}\n\t\\item The eigen value of matrix $A=\\left(\\begin{array}{lll}1 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 1\\end{array}\\right)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\lambda=1,0,2$\n\t\t\\task[\\textbf{b.}]$\\lambda=-1,2,2$\n\t\t\\task[\\textbf{c.}] $\\lambda=0,0,3$\n\t\t\\task[\\textbf{d.}] $\\lambda=1,1,1$\n\t\\end{tasks}\n\t\\item The eigen value of matrix $A=\\left(\\begin{array}{ccc}1 & \\sqrt{8} & 0 \\\\ \\sqrt{8} & 1 & \\sqrt{8} \\\\ 0 & \\sqrt{8} & 1\\end{array}\\right)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\lambda=1,0,2$\n\t\t\\task[\\textbf{b.}]$\\lambda=-1,2,2$\n\t\t\\task[\\textbf{c.}]$\\lambda=-3,1,5$\n\t\t\\task[\\textbf{d.}]$\\lambda=1,1,1$\n\t\\end{tasks}\n\t\\item The eigen value of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\lambda=-1,0,1$\n\t\t\\task[\\textbf{b.}]$\\lambda=0,-2,2$\n\t\t\\task[\\textbf{c.}]$\\lambda=0,0,0$\n\t\t\\task[\\textbf{d.}]  $\\lambda=-\\sqrt{2}, 0, \\sqrt{2}$\n\t\\end{tasks}\n\t\\item The eigen value of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\lambda=-1,-1,2$\n\t\t\\task[\\textbf{b.}]$\\lambda=0,-2,2$\n\t\t\\task[\\textbf{c.}] $\\lambda=0,0,0$\n\t\t\\task[\\textbf{d.}] $\\lambda=-\\sqrt{2}, 0, \\sqrt{2}$\n\t\\end{tasks}\n\t\\item The degenerate eigen value of matrix $A=\\left(\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1\\end{array}\\right)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]1\n\t\t\\task[\\textbf{c.}]2\n\t\t\\task[\\textbf{d.}] 3\n\t\\end{tasks}\n\t\\item The eigen vector of matrix $A=\\left(\\begin{array}{lll}1 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 1\\end{array}\\right)$ corresponding to eigen value 0 is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 0\\end{array}\\right]$\n\t\t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right]$\n\t\t\\task[\\textbf{c.}] $\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{d.}]  $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n\t\\end{tasks}\n\t\\item The eigen vector of matrix $A=\\left(\\begin{array}{ccc}1 & \\sqrt{8} & 0 \\\\ \\sqrt{8} & 1 & \\sqrt{8} \\\\ 0 & \\sqrt{8} & 1\\end{array}\\right)$ corresponding to eigen value 5 is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{c.}] $\\left[\\begin{array}{c}\\sqrt{2} \\\\ 1 \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{d.}]  $\\left[\\begin{array}{c}-\\sqrt{2} \\\\ 1 \\\\ 1\\end{array}\\right]$\n\t\\end{tasks}\n\t\\item The eigen vectors of matrix $A=\\left(\\begin{array}{ccc}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ corresponding to eigen values $-\\sqrt{2}, 0, \\sqrt{2}$ are respectively\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{c.}]$\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right]$\n\t\t\\task[\\textbf{d.}]  $\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right]$\n\t\\end{tasks}\n\t\\item If one of the eigen vector of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$ corresponding to eigen value $-1$ is $\\left[\\begin{array}{c}-2 \\\\ 1 \\\\ 1\\end{array}\\right]$ then other orthogonal eigen vector for same eigen value is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\left[\\begin{array}{c}0 \\\\ 1 \\\\ -1\\end{array}\\right] \\quad$\n\t\t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}-4 \\\\ 2 \\\\ 2\\end{array}\\right]$\n\t\t\\task[\\textbf{c.}]$\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{d.}] $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n\t\\end{tasks}\n\t\\item If one of the eigen vector of matrix $A=\\left(\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1\\end{array}\\right)$ corresponding to eigen value 0 is $\\left[\\begin{array}{c}0 \\\\ 1 \\\\ -1\\end{array}\\right]$ then other orthogonal eigen vector for same eigen value is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\left[\\begin{array}{c}-2 \\\\ 1 \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}0 \\\\ 2 \\\\ -2\\end{array}\\right]$\n\t\t\\task[\\textbf{c.}]$\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 1\\end{array}\\right]$\n\t\t\\task[\\textbf{d.}]  $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n\t\\end{tasks}\n\t\\item A square matrix $3 \\times 3$ is given by $A=\\left[\\begin{array}{lll}2 & 0 & 0 \\\\ 0 & 1 & 1 \\\\ 0 & 1 & 1\\end{array}\\right]$ is diagonalized in eigenvector of\n\tmatrix $S=\\left[\\begin{array}{ccc}1 & 0 & 0 \\\\ 0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ 0 & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\end{array}\\right] .$ Which one of the following is matrix $A$ in the diagonal form in the\n\tbasis of $S$ ?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\left[\\begin{array}{lll}2 & 0 & 0 \\\\ 0 & 2 & 0 \\\\ 0 & 0 & 0\\end{array}\\right] \\quad$ \n\t\t\\task[\\textbf{b.}] $\\left[\\begin{array}{lll}0 & 0 & 0 \\\\ 0 & 2 & 0 \\\\ 0 & 0 & 2\\end{array}\\right] \\quad$ \n\t\t\\task[\\textbf{c.}]$\\left[\\begin{array}{lll}2 & 0 & 0 \\\\ 0 & 0 & 0 \\\\ 0 & 0 & 2\\end{array}\\right] \\quad$\n\t\t\\task[\\textbf{d.}] $\\left[\\begin{array}{lll}1 & 0 & 2 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 2\\end{array}\\right]$\n\t\\end{tasks}\n\t\\item Consider the matrix $M=\\left(\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1\\end{array}\\right) .$ The eigenvalues of $M$ are\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $0,1,2$\n\t\t\\task[\\textbf{b.}]$0,0,3$\n\t\t\\task[\\textbf{c.}]$1,1,1$\n\t\t\\task[\\textbf{d.}] $-1,1,3$\n\t\\end{tasks}\n\t\\item Consider the matrix $M=\\left(\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1\\end{array}\\right)$. The exponential of $M$ simplifies to $(I$ is the $3 \\times 3$ identity matrix)\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$e^{M}=I+\\left(\\frac{e^{3}-1}{3}\\right) M$\n\t\t\\task[\\textbf{b.}] $e^{M}=I+M+\\frac{M^{2}}{2 !}$\n\t\t\\task[\\textbf{c.}] $e^{M}=I+3^{3} M$\n\t\t\\task[\\textbf{d.}]  $e^{M}=(e-1) M$\n\t\\end{tasks}\n\t\\item The eigenvalues of the matrix $\\left(\\begin{array}{lll}2 & 3 & 0 \\\\ 3 & 2 & 0 \\\\ 0 & 0 & 1\\end{array}\\right)$ are\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$5,2,-2$\n\t\t\\task[\\textbf{b.}]$-5,-1,-1$\n\t\t\\task[\\textbf{c.}]$5,1,-1$\n\t\t\\task[\\textbf{d.}] $-5,1,1$\n\t\\end{tasks}\n\t\\item The eigen values of the matrix $A=\\left(\\begin{array}{ccc}1 & 2 & 3 \\\\ 2 & 4 & 6 \\\\ 3 & 6 & 9\\end{array}\\right)$ are\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$(1,4,9)$\n\t\t\\task[\\textbf{b.}] $(0,7,7)$\n\t\t\\task[\\textbf{c.}]$(0,1,13)$\n\t\t\\task[\\textbf{d.}] $(0,0,14)$\n\t\\end{tasks}\n\t\\item The eigenvalues of the antisymmetric matrix, $A=\\left(\\begin{array}{ccc}0 & -n_{3} & n_{2} \\\\ n_{3} & 0 & -n_{1} \\\\ -n_{2} & n_{1} & 0\\end{array}\\right)$ where $n_{1}, n_{2}$ and $n_{3}$ are the components of a unit vector, are\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$0, i,-i$\n\t\t\\task[\\textbf{b.}]$0,1,-1$\n\t\t\\task[\\textbf{c.}]$0,1+i,-1,-i$\n\t\t\\task[\\textbf{d.}] $0,0,0$\n\t\\end{tasks}\n\t\\item Consider the matrix $M=\\left(\\begin{array}{ccc}0 & 2 i & 3 i \\\\ -2 i & 0 & 6 i \\\\ -3 i & -6 i & 0\\end{array}\\right)$. The eigenvalues of $M$ are\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-5,-2,7$\n\t\t\\task[\\textbf{b.}]$-7,0,7$\n\t\t\\task[\\textbf{c.}]$-4 i, 2 i, 2 i$\n\t\t\\task[\\textbf{d.}] $2,3,6$\n\t\\end{tasks}\n\t\\item The column vector $\\left(\\begin{array}{l}a \\\\ b \\\\ a\\end{array}\\right)$ is a simultaneous eigenvector of\n\t$A=\\left(\\begin{array}{lll}0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right)$ and $B=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$, if\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $b=0$ or $a=0$\n\t\t\\task[\\textbf{b.}] $b=a$ or $b=-2 a$\n\t\t\\task[\\textbf{c.}] $b=2 a$ or $b=-a$\n\t\t\\task[\\textbf{d.}]  $b=a / 2$ or $b=-a / 2$\n\t\\end{tasks}\n\\item Let $\\alpha$ and $\\beta$ be complex numbers. Which of the following sets of matrices forms a group under matrix multiplication?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\left(\\begin{array}{ll}\\alpha & \\beta \\\\ 0 & 0\\end{array}\\right)$\n\t\t\\task[\\textbf{b.}] $\\left(\\begin{array}{lr}1 & \\alpha \\\\ \\beta & 1\\end{array}\\right)$, where $\\alpha \\beta \\neq 1$\n\t\t\\task[\\textbf{c.}] $\\left(\\begin{array}{cc}\\alpha & \\alpha^{*} \\\\ \\beta & \\beta^{*}\\end{array}\\right)$, where $\\alpha \\beta^{*}$ is real\n\t\t\\task[\\textbf{d.}]  $\\left(\\begin{array}{cc}\\alpha & \\beta \\\\ -\\beta^{*} & \\alpha^{*}\\end{array}\\right)$, where $|\\alpha|^{2}+|\\beta|^{2}=1$\n\t\\end{tasks}\n\t\\item A $3 \\times 3$ matrix $M$ has $\\operatorname{Tr}[M]=6, \\operatorname{Tr}\\left[M^{2}\\right]=26$ and $\\operatorname{Tr}\\left[M^{3}\\right]=90$. Which of the following can be a possible set of eigenvalues of $M$ ?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\{1,1,4\\}$\n\t\t\\task[\\textbf{b.}]$\\{-1,0,7\\}$\n\t\t\\task[\\textbf{c.}]$\\{-1,3,4\\}$\n\t\t\\task[\\textbf{d.}] $\\{2,2,2\\}$\n\t\\end{tasks}\n\t\\item The matrix $A=\\frac{1}{\\sqrt{3}}\\left[\\begin{array}{cc}1 & 1+i \\\\ 1-i & -1\\end{array}\\right]$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]Orthogonal\n\t\t\\task[\\textbf{b.}] Symmetric\n\t\t\\task[\\textbf{c.}]anti-symmetric\n\t\t\\task[\\textbf{d.}] Unitary\n\t\\end{tasks}\n\t\\item If $H$ is Hermitian matrix then matrix $A=\\exp (i H)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] Hermitian\n\t\t\\task[\\textbf{b.}]Unitary\n\t\t\\task[\\textbf{c.}]Skew Hermitian\n\t\t\\task[\\textbf{d.}] Identity\n\t\\end{tasks}\n\t\\item The matrix $A=\\left(\\begin{array}{ccc}0 & 1 & 0 \\\\ 1 & 0 & 0 \\\\ 0 & 0 & 2\\end{array}\\right)$ is diagonalize in the basis of unitary matrices $U$ and get the diagonalise matrix $\\left(\\begin{array}{ccc}2 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & -1\\end{array}\\right)$ then matrix $U$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\left(\\begin{array}{ccc}0 & 0 & 1 \\\\ \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} & 0\\end{array}\\right)$\n\t\t\\task[\\textbf{b.}]$\\left(\\begin{array}{ccc}0 & 0 & 1 \\\\ \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\ -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0\\end{array}\\right)$\n\t\t\\task[\\textbf{c.}] $\\left(\\begin{array}{ccc}0 & 0 & 0 \\\\ 0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ 1 & \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\\end{array}\\right)$\n\t\t\\task[\\textbf{d.}]  $\\left(\\begin{array}{ccc}0 & 1 & 0 \\\\ \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & 0 & -\\frac{1}{\\sqrt{2}}\\end{array}\\right)$\n\t\\end{tasks}\n\t\\item Given a $2 \\times 2$ unitary matrix $U$ satisfying $U^{\\dagger} U=U U^{\\dagger}=1$ with $\\operatorname{det} U=e^{i \\varphi}$, one can construct a unitary matrix $V\\left(V^{\\dagger} V=V V^{\\dagger}=1\\right)$ with det $V=1$ from it by\n\t \\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}] Multiplying $U$ by $e^{-i \\varphi / 2}$\n\t\t\\task[\\textbf{b.}] Multiplying any single element of $U$ by $e^{-i \\varphi}$\n\t\t\\task[\\textbf{c.}] Multiplying any row or column of $U$ by $e^{-i \\varphi / 2}$\n\t\t\\task[\\textbf{d.}]  Multiplying $U$ by $e^{-i \\varphi}$\n\t\\end{tasks}\n\t\\item Consider an $n \\times n(n>1)$ matrix $A$, in which $A_{i j}$ is the product of the indices $i$ and $j$ (namely $A_{i j}=i j$ ). The matrix $A$\n\t \\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}]Has one degenerate eigevalue with degeneracy $(n-1)$\n\t\t\\task[\\textbf{b.}]Has two degenerate eigenvalues with degeneracies 2 and $(n-2)$\n\t\t\\task[\\textbf{c.}]Has one degenerate eigenvalue with degeneracy $n$\n\t\t\\task[\\textbf{d.}] Does not have any degenerate eigenvalue\n\t\\end{tasks}\n\t\\item Two matrices $A$ and $B$ are said to be similar if $B=P^{1} A P$ for some invertible matrix $P$. Which of the following statements is NOT TRUE?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\operatorname{Det} A=\\operatorname{Det} B$\n\t\t\\task[\\textbf{b.}] Trace of $A=$ Trace of $B$\n\t\t\\task[\\textbf{c.}]$A$ and $B$ have the same eigenvectors\n\t\t\\task[\\textbf{d.}]  $A$ and $B$ have the same eigenvalues\n\t\\end{tasks}\n\t\\item A $3 \\times 3$ matrix has elements such that its trace is 11 and its determinant is 36 . The eigenvalues of the matrix are all known to be positive integers. The largest eigenvalues of the matrix is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]18\n\t\t\\task[\\textbf{b.}]12\n\t\t\\task[\\textbf{c.}]9\n\t\t\\task[\\textbf{d.}] 6\n\t\\end{tasks}\n\t\\item The inverse of matrix $M=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 0 & 0 & 1 \\\\ 1 & 0 & 0\\end{array}\\right)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$M-1$\n\t\t\\task[\\textbf{b.}]$M^{2}-1$\n\t\t\\task[\\textbf{c.}] $I-M^{2}$\n\t\t\\task[\\textbf{d.}] $I-M$\n\t\\end{tasks}\n       \\section{MSQ}  \n \\item For matrix $A=\\left(\\begin{array}{lll}5 & 0 & 2 \\\\ 0 & 1 & 0 \\\\ 2 & 0 & 2\\end{array}\\right)$, which of the following statements are true?\n                 \\begin{tasks}(1)\n                \t\\task[\\textbf{a.}]The degenerate eigen value is 1\n                \t\\task[\\textbf{b.}]One of the eigen vector corresponding to degenerate eigen value is $\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -2\\end{array}\\right]$\n                \t\\task[\\textbf{c.}]The eigen vector corresponding to nondegenerate eigen value is $\\left[\\begin{array}{l}2 \\\\ 0 \\\\ 1\\end{array}\\right]$\n                \t\\task[\\textbf{d.}] The eigen vector corresponding to nondegenerate eigen value is $\\left[\\begin{array}{l}0 \\\\ 2 \\\\ 1\\end{array}\\right]$   \n                \\end{tasks}\n \\item   For matrix $A=\\left(\\begin{array}{lll}1 & 1 & 0 \\\\ 1 & 1 & 0 \\\\ 0 & 0 & 0\\end{array}\\right)$, which of the following statements are true?    \n                 \\begin{tasks}(1)\n                \t\\task[\\textbf{a.}]The degenerate eigen value is 0\n                \t\\task[\\textbf{b.}]One of the eigen vector corresponding to degenerate eigen value is $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n                \t\\task[\\textbf{c.}]One of the eigen vector corresponding to degenerate eigen value is $\\left[\\begin{array}{l}0 \\\\ 0 \\\\ 1\\end{array}\\right]$\n                \t\\task[\\textbf{d.}] The eigen vector corresponding to nondegenerate eigen value is $\\left[\\begin{array}{l}1 \\\\ 1 \\\\ 0\\end{array}\\right]$\n                \\end{tasks}\n  \\item For matrix $A=\\left(\\begin{array}{ccc}5 & 0 & \\sqrt{3} \\\\ 0 & 3 & 0 \\\\ \\sqrt{3} & 0 & 3\\end{array}\\right)$, which of the following statements are true?\n  \\begin{tasks}(1)\n \t\\task[\\textbf{a.}]The eigen value are $2,3,6$\n \t\\task[\\textbf{b.}]The eigen value are 2, 4, 5\n \t\\task[\\textbf{c.}]Eigen vector corresponding eigen value2 is $\\left[\\begin{array}{c}1 \\\\ 0 \\\\ \\sqrt{3}\\end{array}\\right]$\n \t\\task[\\textbf{d.}] Eigen vector corresponding eigen value 2 is $\\left[\\begin{array}{c}\\sqrt{3} \\\\ 0 \\\\ 1\\end{array}\\right]$\n \\end{tasks}               \n \\item  Which one of following is correct \n   \\begin{tasks}(1)\n  \t\\task[\\textbf{a.}] If $A^{\\dagger}=A$ and $B^{\\dagger}=-B$ Then $A B+B A$ is skew Hermitian\n  \t\\task[\\textbf{b.}] If $A^{\\dagger}=A$ and $B^{\\dagger}=-B$ Then $A B+B A$ is Hermitian\n  \t\\task[\\textbf{c.}]If $A^{\\dagger}=A$ and $B^{\\dagger}=-B \\quad i(A B+B A)$ is skew Hermitian\n  \t\\task[\\textbf{d.}] $A^{\\dagger}=A$ and $B^{\\dagger}=-B i(A B+B A)$ is Hermitian    \n  \\end{tasks}              \n\\item  Which of the following is correct for matrix $A=\\left(\\begin{array}{lll}1 & 0 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$             \n   \\begin{tasks}(2)\n  \t\\task[\\textbf{a.}] It is its own inverse\n  \t\\task[\\textbf{b.}]It is its own transpose\n  \t\\task[\\textbf{c.}] It has eigen value $\\pm 1$\n  \t\\task[\\textbf{d.}]  It is orthogonal matrix.\n  \\end{tasks}              \n\\section{NAT}              \n  \\item The degenerate eigenvalue of the matrix $\\left[\\begin{array}{ccc}4 & -1 & -1 \\\\ -1 & 4 & -1 \\\\ -1 & -1 & 4\\end{array}\\right]$ is (your answer should be an integer)-------------      \n\\item  The minimum eigenvalues of the matrix $\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ is...........               \n  \\item The degenerate eigen value of matrix $A=\\left[\\begin{array}{lll}0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right]$ is given by\n\\item  The inverse of matrix $A=\\left[\\begin{array}{lll}0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right]$ is   \n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\left[\\begin{array}{ccc}0 & 0 & -1 \\\\ 0 & -1 & 0 \\\\ -1 & 0 & 0\\end{array}\\right]$\n\t\\task[\\textbf{b.}]$\\left[\\begin{array}{ccc}0 & 0 & -1 \\\\ 0 & -1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right]$\n\t\\task[\\textbf{c.}]$\\left[\\begin{array}{ccc}0 & 0 & -1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right]$\n\t\\task[\\textbf{d.}] $\\left[\\begin{array}{lll}0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right]$\n\\end{tasks}                \n \\item  The eigenvalue of matrix $A=\\left(\\begin{array}{lll}1 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 1\\end{array}\\right)$ is         \n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\lambda=1,0,2$\n \t\\task[\\textbf{b.}]$\\lambda=-1,2,2$\n \t\\task[\\textbf{c.}]$\\lambda=0,0,3$\n \t\\task[\\textbf{d.}]$\\lambda=1,1,1$ \n \\end{tasks}\n \\item The eigenvalue of matrix $A=\\left(\\begin{array}{ccc}1 & \\sqrt{8} & 0 \\\\ \\sqrt{8} & 1 & \\sqrt{8} \\\\ 0 & \\sqrt{8} & 1\\end{array}\\right)$ is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\lambda=1,0,2$\n \t\\task[\\textbf{b.}]$\\lambda=-1,2,2$\n \t\\task[\\textbf{c.}]$\\lambda=-3,1,5$\n \t\\task[\\textbf{d.}] $\\lambda=1,1,1$\n \\end{tasks}\n \\item The eigenvalue of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}] $\\lambda=-1,0,1$\n \t\\task[\\textbf{b.}] $\\lambda=0,-2,2$\n \t\\task[\\textbf{c.}]$\\lambda=0,0,0$\n \t\\task[\\textbf{d.}]  $\\lambda=-\\sqrt{2}, 0, \\sqrt{2}$\n \\end{tasks}\n\\item The eigenvalue of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$ is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\lambda=-1,-1,2$\n \t\\task[\\textbf{b.}]$\\lambda=0,-2, \\quad 2$\n \t\\task[\\textbf{c.}]$\\lambda=0,0,0$\n \t\\task[\\textbf{d.}]  $\\lambda=-\\sqrt{2}, 0, \\sqrt{2}$\n \\end{tasks}\n\\item The eigenvector of matrix $A=\\left(\\begin{array}{lll}1 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 1\\end{array}\\right)$ corresponding to eigenvalue 0 is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 0\\end{array}\\right]$\n \t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right]$\n \t\\task[\\textbf{c.}]$-\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 1\\end{array}\\right] .$\n \t\\task[\\textbf{d.}] $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n \\end{tasks}\n \\item 69 The eigenvector of matrix $A=\\left(\\begin{array}{ccc}1 & \\sqrt{8} & 0 \\\\ \\sqrt{8} & 1 & \\sqrt{8} \\\\ 0 & \\sqrt{8} & 1\\end{array}\\right)$ corresponding to eigenvalue 5 is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{c.}]$\\left[\\begin{array}{c}\\sqrt{2} \\\\ 1 \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{d.}] $\\left[\\begin{array}{c}-\\sqrt{2} \\\\ 1 \\\\ 1\\end{array}\\right]$\n \\end{tasks}\n \\item 70 The eigen vectors of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ corresponding to eigen values $-\\sqrt{2}, 0, \\sqrt{2}$ are respectively\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{c.}] $\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right]$\n \t\\task[\\textbf{d.}] $\\left[\\begin{array}{c}1 \\\\ 0 \\\\ -1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -\\sqrt{2} \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ \\sqrt{2} \\\\ 1\\end{array}\\right]$\n \\end{tasks}\n \\item 71 If one of the eigenvector of matrix $A=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$ corresponding to eigenvalue $-1$ is $\\left[\\begin{array}{c}-2 \\\\ 1 \\\\ 1\\end{array}\\right]$ then other orthogonal eigen vector for same eigen value is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\left[\\begin{array}{c}0 \\\\ 1 \\\\ -1\\end{array}\\right]$\n \t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}-4 \\\\ 2 \\\\ 2\\end{array}\\right]$\n \t\\task[\\textbf{c.}] $\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{d.}]  $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n \\end{tasks}\n \\item 72 If one of the eigen vector of matrix $A=\\left(\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1\\end{array}\\right)$ corresponding to eigen value 0 is $\\left[\\begin{array}{c}0 \\\\ 1 \\\\ -1\\end{array}\\right]$ then other orthogonal eigen vector for same eigen value is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]$\\left[\\begin{array}{c}-2 \\\\ 1 \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{b.}]$\\left[\\begin{array}{c}0 \\\\ 2 \\\\ -2\\end{array}\\right]$\n \t\\task[\\textbf{c.}]$\\left[\\begin{array}{l}1 \\\\ 0 \\\\ 1\\end{array}\\right]$\n \t\\task[\\textbf{d.}] $\\left[\\begin{array}{c}1 \\\\ -1 \\\\ 0\\end{array}\\right]$\n \\end{tasks}\n \\item 73  A $3 \\times 3$ matrix $M$ has $\\operatorname{Tr}[M]=6, \\operatorname{Tr}\\left[M^{2}\\right]=26$ and $\\operatorname{Tr}\\left[M^{3}\\right]=90$. Which of the following can be a possible set of eigenvalues of $M$ ?\n      \\begin{tasks}(2)\n     \t\\task[\\textbf{a.}]$\\{1,1,4\\}$\n     \t\\task[\\textbf{b.}]$\\{-1,0,7\\}$\n     \t\\task[\\textbf{c.}]$\\{-1,3,4\\}$\n     \t\\task[\\textbf{d.}] $\\{2,2,2\\}$\n     \\end{tasks}\n\\item     Q74. Consider an $n \\times n(n>1)$ matrix $A$, in which $A_{i j}$ is the product of the indices $i$ and $j$ (namely $\\left.A_{i j}=i j\\right)$. The matrix $A$\n      \\begin{tasks}(2)\n     \t\\task[\\textbf{a.}]has one degenerate eigevalue with degeneracy $(n-1)$\n     \t\\task[\\textbf{b.}]has two degenerate eigenvalues with degeneracies 2 and $(n-2)$\n     \t\\task[\\textbf{c.}]has one degenerate eigenvalue with degeneracy $n$\n     \t\\task[\\textbf{d.}] does not have any degenerate eigenvalue\n     \\end{tasks}\n \\item     Q75. A $3 \\times 3$ matrix has elements such that its trace is 11 and its determinant is 36 . The eigenvalues of the matrix are all known to be positive integers. The largest eigenvalues of the matrix is\n     \\begin{tasks}(2)\n    \t\\task[\\textbf{a.}]18\n    \t\\task[\\textbf{b.}]12\n    \t\\task[\\textbf{c.}]9\n    \t\\task[\\textbf{d.}] 6\n    \\end{tasks} \n\\item Q76. The inverse of matrix $M=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 0 & 0 & 1 \\\\ 1 & 0 & 0\\end{array}\\right)$ is\n  \\begin{tasks}(2)\n    \t\\task[\\textbf{a.}]$M-I$\n    \t\\task[\\textbf{b.}]$M^{2}-I$\n    \t\\task[\\textbf{c.}]$I-M^{2}$\n    \t\\task[\\textbf{d.}] $I-M$. \n    \\end{tasks}\n\\item Q77. Consider the matrix $M=\\left(\\begin{array}{ccc}0 & 2 i & 3 i \\\\ -2 i & 0 & 6 i \\\\ -3 i & -6 i & 0\\end{array}\\right)$. The eigenvalues of $M$ are\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$-5,-2,7$\n\t\\task[\\textbf{b.}]$-7,0,7$\n\t\\task[\\textbf{c.}]$-4 i, 2 i, 2 i$\n\t\\task[\\textbf{d.}] $2,3,6$ \n\\end{tasks}       \n \\item Q78. The matrix $A=\\frac{1}{\\sqrt{3}}\\left[\\begin{array}{cc}1 & 1+i \\\\ 1-i & -1\\end{array}\\right]$.\n is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}]Orthogonal\n \t\\task[\\textbf{b.}]symmetric\n \t\\task[\\textbf{c.}] anti-symmetric\n \t\\task[\\textbf{d.}]  Unitary    \n \\end{tasks}    \n\\item Q79. If $H$ is Hermitian matrix then matrix $A=\\exp (i H)$ is\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}] IIermitian\n \t\\task[\\textbf{b.}] Unitary\n \t\\task[\\textbf{c.}] Skew Hermitian\n \t\\task[\\textbf{d.}] Identity     \n \\end{tasks}    \n\\item Q80. Which one of following is correct?\n      \\begin{tasks}(2)\n     \t\\task[\\textbf{a.}] If $A^{\\dagger}=A$ and $B^{\\dagger}=-B$, then $A B+B A$ is skew Hermitian\n     \t\\task[\\textbf{b.}]If $A^{\\dagger}=A$ and $B^{\\dagger}=-B$, then $A B+B A$ is Hermitian\n     \t\\task[\\textbf{c.}] If $A^{\\dagger}=A$ and $B^{\\dagger}=-B$, then $-i(A B+B A)$ is skew Hermitian\n     \t\\task[\\textbf{d.}]  If $A^{\\dagger}=A$ and $B^{\\dagger}=-B$, then $i(A B+B A)$ is skew Hermitian\n     \\end{tasks}\n\\item Q81. A square matrix $3 \\times 3$ is given by $A=\\left[\\begin{array}{ccc}2 & 0 & 0 \\\\ 0 & 1 & 1 \\\\ 0 & 1 & 1\\end{array}\\right]$ is diagonalized in eigenvector of matrix $S=\\left[\\begin{array}{ccc}1 & 0 & 0 \\\\ 0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ 0 & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\end{array}\\right]$. Which one of the following is the diagonal matrix of $A$ in form in the basis of $S$ ?\n\\begin{tasks}(2)\n     \t\\task[\\textbf{a.}] $\\left[\\begin{array}{lll}2 & 0 & 0 \\\\ 0 & 2 & 0 \\\\ 0 & 0 & 0\\end{array}\\right]$\n     \t\\task[\\textbf{b.}]$\\left[\\begin{array}{lll}0 & 0 & 0 \\\\ 0 & 2 & 0 \\\\ 0 & 0 & 2\\end{array}\\right]$\n     \t\\task[\\textbf{c.}] $\\left[\\begin{array}{lll}2 & 0 & 0 \\\\ 0 & 0 & 0 \\\\ 0 & 0 & 2\\end{array}\\right]$\n     \t\\task[\\textbf{d.}] $\\left[\\begin{array}{lll}1 & 0 & 2 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 2\\end{array}\\right]$\n     \\end{tasks}\n\\item    Q82. The column vector $\\left(\\begin{array}{l}a \\\\ b \\\\ a\\end{array}\\right)$ is a simultaneous eigenvector of\n$A=\\left(\\begin{array}{lll}0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right)$ and $B=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$, if  \n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$b=0$ or $a=0$\n\t\\task[\\textbf{b.}]$b=a$ or $b=-2 a$\n\t\\task[\\textbf{c.}]$b=2 a$ or $b=-a$\n\t\\task[\\textbf{d.}] $b=a / 2$ or $b=-a / 2$\n\\end{tasks}\n\\item Q83. Two matrices $A$ and $B$ are said to be similar if $B=P^{-1} A P$ for some invertible matrix $P$. Which of the following statements is NOT TRUE?\n   \\begin{tasks}(2)\n  \t\\task[\\textbf{a.}] $\\operatorname{Det} A=\\operatorname{Det} B$\n  \t\\task[\\textbf{b.}] Trace of $A=$ Trace of $B$\n  \t\\task[\\textbf{c.}]$\\dot{A}$ and $B$ have the same eigenvectors\n  \t\\task[\\textbf{d.}] $A$ and $B$ have the same eigenvalues\n  \\end{tasks}   \n\\item Q84. The matrix $A=\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 0 \\\\ 0 & 0 & 2\\end{array}\\right)$ is diagonalize in the basis of unitary matrices $U$ and get the diagonalise matrix $\\left(\\begin{array}{ccc}2 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & -1\\end{array}\\right)$ then matrix $U$ is     \n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\left(\\begin{array}{ccc}0 & 0 & 1 \\\\ \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} & 0\\end{array}\\right)$\n\t\\task[\\textbf{b.}]$\\left(\\begin{array}{ccc}0 & 0 & 1 \\\\ \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\ -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0\\end{array}\\right)$\n\t\\task[\\textbf{c.}]$\\left(\\begin{array}{ccc}0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ 0 & \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} \\\\ 1 & 0 & 0\\end{array}\\right)$\n\t\\task[\\textbf{d.}] $\\left(\\begin{array}{ccc}0 & 1 & 0 \\\\ \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & 0 & -\\frac{1}{\\sqrt{2}}\\end{array}\\right)$\n\\end{tasks}     \n     \n     \n     \n     \n     \n     \n     \n     \n\\end{enumerate}\n", "meta": {"hexsha": "5586e1e53251ed0e77eca003c76b110a87b77e30", "size": 26832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Matrices.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-Matrices.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-Matrices.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": 65.7647058824, "max_line_length": 413, "alphanum_fraction": 0.5769603459, "num_tokens": 11673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.6936493065581651}}
{"text": "\\section{Playing Around With Our New Toy}\n    \n    \\frame{\\sectionpage}\n    \n    \\begin{frame}{Fourier Transforming}\n        \\only<-3>{\\uncover<+->{\\begin{equation*}\n            f(t) = \\cos(\\omega_0 t)e^{-\\pi t^2}\n        \\end{equation*}}\n        \\uncover<+->{\\begin{equation*}\n            \\widehat{f}(\\omega) = \\frac{e^{-\\frac{(\\omega - \\omega_0)^2}{4\\pi}} + e^{-\\frac{(\\omega + \\omega_0)^2}{4\\pi}}}{2\\sqrt{2\\pi}}\n        \\end{equation*}}\n        \\uncover<+->{\\begin{equation*}\n            \\omega = 2\\pi\\nu\n        \\end{equation*}}}\n        \\only<4>{\\begin{equation*}\n            f(t) = \\cos(2\\pi\\nu_0 t)e^{-\\pi t^2}\n        \\end{equation*}\n        \\begin{equation*}\n            \\widehat{f}(\\nu) = \\frac{e^{-\\pi(\\nu - \\nu_0)^2} + e^{-\\pi(\\nu + \\nu_0)^2}}{2\\sqrt{2\\pi}}\n        \\end{equation*}}\n    \\end{frame}\n    \n    \\begin{frame}{Fourier Transforming}\n        \\begin{equation*}\n            f(t) = \\cos(2\\pi\\nu_0 t)e^{-\\pi t^2}\n        \\end{equation*}\n        \\centering\n        \n        \\includegraphics[height = 0.7 \\textheight]{images/Pulse1.pdf}\n    \\end{frame}\n    \n    \\begin{frame}{Fourier Transforming}\n        \\begin{equation*}\n            \\widehat{f}(\\nu) = \\frac{e^{-\\pi(\\nu - \\nu_0)^2} + e^{-\\pi(\\nu + \\nu_0)^2}}{2\\sqrt{2\\pi}}\n        \\end{equation*}\n        \\centering\n        \n        \\includegraphics[height = 0.65 \\textheight]{images/Pulse1-Fourier.pdf}\n    \\end{frame}\n    \n    \\begin{frame}{A Harder Example}\n        \\uncover<+->{\\begin{equation*}\n            f(t) = e^{i\\omega_0 t} = \\cos(\\omega_0 t) + i \\sin(\\omega_0 t)\n        \\end{equation*}}\n        \\uncover<+->{\\begin{equation*}\n            \\widehat{f}(\\omega) = \\frac{1}{\\sqrt{2\\pi}} \\int_{-\\infty}^{+\\infty} e^{i\\omega_0 t} e^{-i \\omega t} \\dd{t}\n        \\end{equation*}}\n    \\end{frame}\n    \n    \\begin{frame}{The Mathematical Moonwalk}\n        \\uncover<+->{\\begin{equation*}\n            f(t) = e^{i\\omega_0 t}\n        \\end{equation*}}\n        \\uncover<+->{\\begin{equation*}\n            e^{i\\omega_0 t} = \\frac{1}{\\sqrt{2\\pi}} \\int_{-\\infty}^{+\\infty} \\widehat{f}(\\omega) e^{i \\omega t} \\dd{\\omega}\n        \\end{equation*}}\n        \\uncover<+->{\\begin{equation*}\n            \\widehat{f}(\\omega) = \\sqrt{2\\pi} \\dirac{\\omega - \\omega_0}\n        \\end{equation*}}\n    \\end{frame}\n    \n    \\begin{frame}{Cosines}\n        \\begin{equation*}\n            f(t) = \\cos(\\omega_0 t) = \\frac{e^{i\\omega_0t} + e^{-i\\omega_0t}}{2}\n        \\end{equation*}\n        \n        \\centering\n        \\includegraphics[height = 0.65 \\textheight]{images/Pulse2.pdf}\n    \\end{frame}\n    \n    \\begin{frame}{Cosines}\n        \\begin{equation*}\n            \\widehat{f}(\\omega) = \\sqrt{\\frac{\\pi}{2}}\\prnt{\\dirac{\\omega-\\omega_0} + \\dirac{\\omega+\\omega_0}}    \n        \\end{equation*}\n        \n        \\centering \n        \\includegraphics[height = 0.65 \\textheight]{images/Pulse2-Fourier.pdf}\n    \\end{frame}", "meta": {"hexsha": "2381ba924f4f32d68ed8b03cb812ea88b7f32b8a", "size": 2856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "200+ beamer 模板合集/DeadPhysicistsSocietyPresentationTemplate(DPS 研讨会)/chapters/playing-around.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 模板合集/DeadPhysicistsSocietyPresentationTemplate(DPS 研讨会)/chapters/playing-around.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 模板合集/DeadPhysicistsSocietyPresentationTemplate(DPS 研讨会)/chapters/playing-around.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": 36.6153846154, "max_line_length": 136, "alphanum_fraction": 0.5087535014, "num_tokens": 1056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.693649300515349}}
{"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 26, 2014}\n\\maketitle\n\\section*{section 6.2.4}\nlet $f:[a,b]\\to\\mathbb{R}$ be differentiable, then\n\\begin{enumerate}\n\\item\nif $f'$ is (strictly) positive, $f$ is (strictly) increasing\n\\item\nsame for negative\n\\item\nif $f'(x)=0$ then $\\forall x\\in[a,b]$, $f$ is constant\n\\end{enumerate}\n\\subsubsection*{proof}\nsuppose $f'$ is strictly positive, let $x,y\\in[a,b]$ such that $x<y$. then by mean value theorem $\\exists c\\in(x,y)$ such that $f'(c)=\\frac{f(y)-f(x)}{y-x}$ and so $(y-x)f'(c)=f(y)-f(x)$ and so $y-x>0$ and $f'(c)\\ge 0 (>0)$ so $f(y)-f(x)\\ge0$ an $f(y)\\ge f(x)$\n\n\\subsection*{exercise 6.2.L}\na function is convex (lies below that line segment (x,f(x) to (y,f(y))) if $f(tx+(1-t)y)\\le tf(x) +(1-t)f(y)$ for all $x,y$ in $[a,b]$ and all $t\\in[0,1]$\n\\subsection*{a)} if $f$ is differentiable and $f'$ is increasing then $f$ is convex.\n\ndefine $z=tx+(1-t)y$\n\nnote that $x\\le z\\le y$. and there exists $c_1\\in(x,z),c_2\\in(z,y)$ and $f'(c_1)=\\frac{f(z)-f(x)}{z-x}$ and $f'(c_2)=\\frac{f(y)-f(z)}{y-z}$ and $c_1< c_2$ and so $f'(c_1)\\le f'(c_2)$ and $\\frac{f(z)-f(x)}{z-x}\\le \\frac{f(y)-f(z)}{y-z}$ and on through until $f(z)(y-z)+f(z)(z-x)\\le f(y)(z-x)+f(x)(y-z)$ and sub t back in for\n\\begin{align*}\n  f(z)(y-x)&\\le f(y)[tx+(1-t)y-x]+f(x)[y-tx-(1-t)y]\\\\\n\\end{align*}\nand algebra to get definition\n\\end{document}\n", "meta": {"hexsha": "fffc5dacf83c2e87c8477a27dc79779b13191ad3", "size": 1581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "real analysis/analysis-notes-2014-11-26.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-26.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-26.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": 38.5609756098, "max_line_length": 323, "alphanum_fraction": 0.6325110689, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.6936492991084227}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 7}\n\\subsection{Lecture Notes - Symmetries and Conservation Laws}\n\\subsubsection{Noether's Theorem}\nIdea: Certain symmetries we observe in nature are associated with conservation laws. E.g. momentum with translational symmetry. Formally, we consider the following:\n\\newline Consider a Lagrangian $\\LL(q, \\dot{q}, t)$ is invariant under a coordinate transformation $(q_1, \\cdots, q_n) \\rightarrow (\\tilde{q}_1(\\alpha), \\cdots, \\tilde{q}_n(\\alpha))$ with $\\tilde{q}_i(\\alpha) = q_i + \\alpha h_i(q,t) + \\delta(\\alpha^2)$. Consider taking the derivative with respect to $\\alpha$ and set $\\alpha = 0$:\n\\[\\left.\\dod{}{\\alpha}\\LL(\\tilde{q}(\\alpha), \\dot{\\tilde{q}}(\\alpha), t)\\right|_{\\alpha = 0} = 0\\]\nWhere the expression is zero as $\\LL$ is invariant of $\\alpha$. Now, by the chain rule, we can say:\n\\[0 = \\left. \\sum_{j=1}^n\\left(\\dpd{\\LL}{\\tilde{q}_j}\\dpd{\\tilde{q}_j}{\\alpha} + \\dpd{\\LL}{\\dot{\\tilde{q}}_j}\\dpd{\\dot{\\tilde{q}}_j}{\\alpha}\\right)\\right|_{\\alpha=0}\\]\nNow, we can say that $\\dpd{\\dot{\\tilde{q}}_j}{\\alpha} = \\dod{}{t}\\dpd{\\tilde{q}_j}{\\alpha}$ my equality of mixed partials. Using the EL equations, we can also say that $\\dpd{\\LL}{\\tilde{q}_j} = \\dod{}{t}\\dpd{\\LL}{\\dot{\\tilde{q}}_j}$. We can then write the whole expression as:\n\\[0 = \\left.\\dod{}{t}\\sum_{j=1}^n\\left(\\dpd{\\LL}{\\dot{\\tilde{q}}_j}\\dpd{\\tilde{q}_j}{\\alpha}\\right)\\right|_{\\alpha=0}\\]\nBy the chain rule. We have just recollapsed the sum using the chain rule multiple times. Now, call this sum $I(q, \\dot{q}, t)$. This object is conserved as its time derivative is zero, i.e. $\\dod{}{t}I(q, \\dot{q}, t) = 0$. Let us apply this to make this more concrete. \n\\subsubsection{Translational and Rotational Symmetry}\nThe first symmetry we will consider is the homoegeneity of space. This can be mathematically represented as $\\v{r}_i \\mapsto \\tilde{\\v{r}}_i + \\alpha\\ehat$ (where $\\ehat$ is some unit vector) and where $\\dot{\\v{r}}_i = \\dot{\\tilde{\\v{r}}}_i$. \n\\newline The next symmetry we can consider is the isotropy of space. This is represented as $\\v{r}_i \\mapsto \\tilde{\\v{r}}_i = \\v{r}_i + \\hat{\\bm{\\alpha}}\\times \\v{r}_i$ (where $\\hat{\\bm{\\alpha}}$ is the axis of rotation). \n\\newline Now, what does Noether tell us about these symmetries? Assuming that the Lagrangians are invariant under the transformations, then $I$ is conserved, and hence:\n\\[I = \\left.\\sum_{j=1}^n\\left(\\dpd{\\LL}{\\dot{\\tilde{q}}_j}\\dpd{\\tilde{q}_j}{\\alpha}\\right)\\right|_{\\alpha=0} = \\begin{cases}\n\\text{(Translation) } \\sum_{j=1}^n m_j\\dot{\\v{r}}_j \\cdot \\ehat\n\\\\ \\text{(Rotation) } \\sum_{j=1}^nm_j\\dot{r}_j \\cdot\\left(\\hat{\\bm{\\alpha}} \\times \\v{r}_j\\right) = \\hat{\\bm{\\alpha}}\\sum_{j=1}^n \\v{r}_j \\times m_j \\dot{\\v{r}}_j\n= \\hat{\\bm{\\alpha}}\\cdot\\v{L}\\end{cases}\\]\nIn the first case (with translational symmetry) we have conservation of linear momentum along $\\ehat$. In the second case (with rotational symmetry) we have the conservation of angular momentum along $\\hat{\\bm{\\alpha}}$.\n\\subsubsection{Time symmetry and the Hamiltonian}\nWe next consider a scenario where we have homogeneity of time; In other words, where $\\LL$ is unchanged by $t$. $t \\mapsto t + \\e$, and $\\dpd{\\LL}{t} = 0$. Expanding out the total time derivative of the Lagrangian, we have:\n\\[\\dod{}{t}\\LL(q, \\dot{q}, t) = \\sum_{j=1}^n \\left(\\dpd{\\LL}{q_j}\\dpd{q_j}{t} + \\dpd{\\LL}{\\dot{q}_j}\\dpd{}{t}\\dpd{q_j}{t}\\right)\\]\nWe recall that $\\dpd{q_j}{t} = \\dot{q}_j$, $\\dpd{\\LL}{\\dot{q}_j} = p_j$ (generalized momentum) and $\\dpd{\\LL}{q_j} = \\dod{}{t}\\dpd{\\LL}{\\dot{q}_j}$ (generalized force/time derivative of generalized momentum). Again by taking out the time differential operator out of the sum, we have:\n\\[\\dod{}{t}\\LL(q, \\dot{q}, t) = \\dod{}{t}\\sum_jp_j\\dot{q}_j\\]\nwhere $p_j$ is the generalized momentum of the coordinate $q_j$. We can write this as:\n\\[\\dod{}{t}\\left(\\sum_jp_j\\dot{q}_j - \\LL\\right) = 0\\]\nAnd we call the term in the brakets to be the \\textbf{Hamiltonian}:\n\\[\\HH = \\sum_jp_j\\dot{q}_j - \\LL\\]\nwhich is a conserved quantity.\n\\end{document}", "meta": {"hexsha": "ea76235d1ba47fcf20a6940260b14f0df452cd05", "size": 4060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-7/Lecture-Notes-7.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-7/Lecture-Notes-7.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-7/Lecture-Notes-7.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 119.4117647059, "max_line_length": 331, "alphanum_fraction": 0.6810344828, "num_tokens": 1471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.6936492991084225}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{url}\n\\usepackage{fullpage}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{definition}{Definition}\n\n\\newcommand{\\N}{\\mathcal{N}}\n\\newcommand{\\I}{\\mathcal{I}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\renewcommand{\\v}[1]{\\mathbf{#1}}\n\n\\begin{document}\n\n\\title{Hierarchical Regression for SIG-VISA}\n\\author{Dave Moore}\n\\maketitle\n\n\\section{Fully Parametric}\n\nWe first consider the case where some parameter of interest $y$ (e.g. the amplitude transfer function) is modeled as linear-in-features for some feature representation $\\phi$, plus i.i.d. Gaussian noise:\n\\[\\v{y} = \\v{w}^T\\phi(X) + \\v{\\epsilon}, \\qquad \\v{\\epsilon} \\sim \\N(\\v{0}, \\sigma^2_n \\I).\\]\nWe allow weights to vary across stations. The weight $\\v{w}^{(s)}$ at station $s$ is modeled as the sum of a global weight vector and a station-specific correction:\n\\[\\v{w}^{(s)} = \\v{w} + \\v{c}^{(s)}, \\qquad \\v{w}\\sim\\N(\\v{\\mu_g}, \\Sigma_g \\I), \\qquad v{c}^{(s)} \\sim \\N(\\v{0}, \\Sigma_e).\\]\nWe observe data $X^{(s)}, \\v{y}^{(s)}$ at each station. We assume as a ``black box'' the ability to run a Bayesian linear regression to obtain the posterior distribution $p(\\v{w}^{(s)} | X^{(s)}, \\v{y}^{(s)})$ on the regression weights given the observed data. \n\n\n\n    %% LET:\n    %% prior(g) ~ N(\\mu_g, sigma_g)\n    %% s = g + eps, eps ~ N(0, \\sigma_e)\n\n\n    %% p(g | d) = int_s p(g|s)p(s|d) ds\n    %% where\n    %% p(s|d) ~ N(s; mu_s, sigma_s)\n\n    %% p(g|s) ~ N(g; mu, sigma)\n    %%          mu = sigma * (sigma_e^-1 * s + sigma_g^-1 * mu_g)\n    %%          sigma = (sigma_e^-1 + sigma_g^-1)^-1\n    %% (see ``observations'' section of my gaussian identity notes)\n\n\n    %% now let A = sigma * sigma_e^-1, b = sigma * sigma_g^-1 * mu_g, then\n    %% p(g|d) = int_s N(g; As+b, sigma) N(s; mu_s, sigma_s) ds\n    %% by the ``linear gaussian marginalization'' section of my notes, this gives\n\n    %% p(g|d) ~ N(g; A*mu_s +b, sigma + A * sigma_s * A^T )\n\n    %% so\n\n    %% mu_g <= A*mu_s + b\n    %%       = sigma * (sigma_e^-1 * mu_s + sigma_g^-1 * mu_g)\n    %%       = sigma * (p_e * mu_s + p_g * mu_g)\n\n    %% sigma_g <= sigma + A * sigma_s * A^T\n    %%          = sigma + sigma * sigma_e^-1 * sigma_s * sigma_e^-1 * sigma\n    %%          = sigma * (I + sigma_e^-1 * sigma_s * sigma_e^-1)\n\n\n    %% where sigma = (p_e + p_g)^-1: if we had a specific value of s to update with, we'd get a new precision for the global params by summing our current precision, with the precision on our observed value of s.\n\n\n    %% TODO: implement the equations above, hope for numerical stability\n\nmessage passing interpretation?\n\nwe have a big tree graph. lots of station params tied together by global params. below each station param in station data, which we observe. \n\nThe message passed by the station params to the global params is\n\nm_s->g = \\int_s p(s|g) * m_d->s p(d | s)\n       = \\int_s p(s|g) * p(d|s)\n\nso the marginal on global params is proportional to\n\np(g) * \\prod_s m_s->g\n\nand the marginal on params at any station should be prop to\n\nm_g->s * m_d->s\n= \\int p(s|g) dg * p(d|s)\nwhich is exactly p(s|d) if we marginalize out g, and just use p(g) + station_slack as our prior on s.\nso given a marginal on g, we should be able to get the appropriate marginals on s just by building the regression model.\n\n\n\nargh. if we have a single station, and we marginalize out g, we literally just have the standard regression model. so we should get the same results. \nbut somehow this is just totally incompatible with the idea that we compute p(g|d), then train under that prior.\nthe answer, somehow, is going to come from the fact that in message passing, we don't pass a node's own messages back down to it. we just pass messages from elsewhere in the tree. \n\nlet's take the simplest possible case. just a single scalar. we have\n\ng ~ N(0,1)\ns ~ N(g, 1)\nd ~ N(s, 1)\n\nwe observe d. now we have a ``regression'' procedure which computes p(s|d) \\propto p(d|s)p(s)\nwhere p(s) = int dg p(s|g)p(g) = N(0, 2). Then the ``regression'' is given by\np(s|d) = N( d/2, .5  )\nfollowing the ``observation'' section of my Gaussian notes.\n\nand the global posterior is now \np(g | d) \\propto p(d | g)p(g)\n               = p(g) int_s p(d|s) p(s|g) \n               = N(g, 0, 1) * \n         = N(.25, .75)\nfollowing the equations I figured out elsewhere, which seems plausible. \nbut it would NOT be okay to go back and update s by training with this prior. \nwhy not? shouldn't message passing reach a fixed point? yes, but the messages I pass to s are always going to be the messages from elsewhere. they'll never be exactly the same as the marginal. \n\nso I think it'd be okay to compute, for each station, the posterior on the global params from ALL OTHER stations, then use that as the prior to train. that takes n^2 work though. is there a more efficient way of getting these messages?\n\nrepeating from above, our messages are\n\nm_s->g (g) = \\int_s p(s|g) * p(d|s)\n           = p(d|g)\n\n\nI have p(g|d) ~ p(d|g)p(g)\n\n\nnow say I want to compute the message to station i\nformally speaking this is the product of messages from all the other stations, with the global prior\n\nso if I went through and updated to get the global marginal, can I get the message by ``dividing out'' the contribution from that one station?\n\ndividing by a Gaussian density is (up to constants) the same as multiplying by that density with a negative sign on the covariance matrix. \nso let's say I have a marginal on g. now I want the ``message'', i.e., the distribution with which to do regression in order to get s to work. \n\nif my previous ``update'' corresponded to multiplying g by the message from s, then renormalizing to get a posterior on g, I should be able to ``divide'' just by doing the exact same update, but with the negative of the covariance matrix from s.\n\noh shit.\nthe ``message'' that I send from s to g should *just* be from the data. it shouldn't have any component from g at all. \nin other words, my message should be\n\nM_s->g = \\int_s p(s|g) p(d|s)\n= N(Hg; d, noise_var*I H sigma_e H^T)\n\nsomehow this isn't satisfying though: I should still be able to do an ``update'' on p(g).\n\nso I could write code to do an ``update'' on p(g), by taking whatever the current p(g) mean and cov are, and incorporating the message from d. this doesn't let me use the existing regression code. but hopefully it would work, and would let me debug the current code approach.\n\nokay, so my message-passing approach is\n\np(g|d) \\propto p(d|g)p(g)\n             = N(Hg; d, noise_var*I H sigma_e H^T) * N(mu_g, sigma_g)\n       where we just update mu_g and sigma_g\n\nmy other approach is\np(g|d) = int_s p(g,s|d)\n       = int_s p(g|s)p(s|d)\nwhere p(s|d) comes from the bayesian regression. now formally, we have p(s|d) \\propto p(d|s)p(s),\nwhere p(s) is a prior on s. in our graph, this comes from pushing down the *prior* on g. \nso I should be running my p(s|d) regression using the prior on s, if I want this to work out.\n\nthen we have p(g|s). this is\np(s|g)p(g) = N(s; g, cov_e) N(g; mu_g, cov_g)\n           = N(c, C)\nC = (cov_g^-1 + cov_e^-1)^-1\nc = C (cov_g^-1 * mu_g + cov_e^-1 * s)\n\nwhich matches what I got before.\n\nthen p(g|d) = int_s p(g|s) p(s|d)\n            = int_s N(C * (cov_e^-1 * s) + C * (cov_g^-1)*mu_g, C) N(mu_s, cov_s) \n\nIT WORKS!\n\nnow to ``back out'' a station's contributions.\nwe have p(g|d) = p(d|g)p(g)\nand we want\np(g) = p(g|d)\n       ------\n       p(d|g)\nwhere p(d|g) = int_s p(d|s)p(s|g)\n             = int_s p(s|d)p(d)/p(s) * p(g|s)p(s)/p(g)\n             = int_s p(s|d)p(g|s) / p(g)\n             = p(g|d) / p(g)\n\nwell, we know explicitly that p(d|g) = N(Hg; d, noise_var*I H sigma_e H^T)\n\nwe have an expression for the posterior on the global params, given all of our stations\nwe also have, for station i, a posterior on the station params given the data\n(which we previously used to update the global posterior)\n\nmaybe I just need to use math.\n\nsg2 = (se^-1 + sg1^-1)^-1 + (se^-1 + sg1^-1)^-1 * se^-1 * sigma_s * se^-1 * (se^-1 + sg1^-1)^-1\n\nsg2 (se^-1 + sg1^-1) = I + (se^-1 + sg1^-1)^-1 * se^-1 * sigma_s * se^-1\n\n(se^-1 + sg1^-1) sg2 (se^-1 + sg1^-1) = se^-1 + sg1^-1 + se^-1 * sigma_s * se^-1\n\n(sei *sg2 * sei) + (sg1i * sg2 * se1) + (sei * sg2 * sg1i) + (sg1i * sg2 * sg1i) = \nsei + sg1i + sei * sigma_s * sei\n\n\n\n\\end{document}\n", "meta": {"hexsha": "16fab6d30c70d2ec3e26aadb9e422d80661833c6", "size": 8340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/hierarchical_global_regression.tex", "max_stars_repo_name": "davmre/sigvisa", "max_stars_repo_head_hexsha": "91a1f163b8f3a258dfb78d88a07f2a11da41bd04", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/hierarchical_global_regression.tex", "max_issues_repo_name": "davmre/sigvisa", "max_issues_repo_head_hexsha": "91a1f163b8f3a258dfb78d88a07f2a11da41bd04", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/hierarchical_global_regression.tex", "max_forks_repo_name": "davmre/sigvisa", "max_forks_repo_head_hexsha": "91a1f163b8f3a258dfb78d88a07f2a11da41bd04", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.4854368932, "max_line_length": 275, "alphanum_fraction": 0.6507194245, "num_tokens": 2631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.693649298639447}}
{"text": "\\subsection{One to one and onto transformations}\n\nRecall the following definitions, given here in terms of vector spaces.\n\n\\begin{definition}{One to one}{one-to-one-vector-space}\nLet $V, W$ be vector spaces with $\\vect{v}_1, \\vect{v}_2$ vectors in $V$. Then a linear transformation $T: V \\to W$ is called one to one if whenever $\\vect{v}_1 \\neq \\vect{v}_2$ it follows that\n\\[\nT(\\vect{v}_1) \\neq T (\\vect{v}_2)\n\\]\n\\end{definition}\n\n\\begin{definition}{Onto}{onto-vector-space}\nLet $V, W$ be vector spaces. Then a linear transformation $T: V \\to W$ is called onto if for all $\\vect{w} \\in \\vect{W}$ there exists $\\vect{v} \\in V$ such that $T(\\vect{v}) = \\vect{w}$.\n\\end{definition}\n\nRecall that every linear transformation $T$ has the property that $T(\\vect{0})=\\vect{0}$. This will be necessary to prove the following useful lemma.\n\n\\begin{lemma}{One to one}{one-to-one-abstract}\nThe assertion that a linear transformation $T$ is one to one is equivalent to\nsaying that if $T(\\vect{v})=\\vect{0}$, then $\\vect{v}=\\vect{0}$.\n\\end{lemma}\n\n\\begin{proof}\nSuppose first that $T$ is one to one.\n\\begin{equation*}\nT(\\vect{0})=T(\\vect{0}+\\vect{0}) =T(\\vect{0})+T(\\vect{0})\n\\end{equation*}\nand so, adding the additive inverse of $T(\\vect{0})$ to both sides, one sees\nthat $T(\\vect{0})=\\vect{0}$. Therefore, if $T(\\vect{v})=\\vect{0}$, it must be the\ncase that $\\vect{v}=\\vect{0}$ because it was just shown that $T(\\vect{0})=\\vect{0}$.\n\nNow suppose that if $T(\\vect{v})=\\vect{0}$, then $\\vect{v}=\\vect{0}$. If $T(\\vect{v})=T(\\vect{u})$, then $T(\\vect{v})-T(\\vect{u})=T(\\vect{v}-\\vect{u}) =\\vect{0}$ which\nshows that $\\vect{v}-\\vect{u}=\\vect{0}$ or in other words, $\\vect{v}=\\vect{u}$.\n\\end{proof}\n\nConsider the following example.\n\n\\begin{example}{One to one transformation}{one-to-one-general}\nLet $S:\\Poly_2\\to\\Mat_{2,2}$ be a linear transformation\ndefined by\n\\[ S(ax^2+bx+c)\n=\n\\begin{mymatrix}{cc}\na+b & a+c \\\\ b-c & b+c \\end{mymatrix}\n\\mbox{ for all }\n ax^2+bx+c\\in \\Poly_2.\\]\nProve that $S$ is one to one but not onto.\n\\end{example}\n\n\\begin{solution}\nBy definition,\n\\[ \\ker(S)=\\set{ax^2+bx+c\\in \\Poly_2 \\mid a+b=0, a+c=0, b-c=0, b+c=0}.\\]\n\nSuppose $p(x)=ax^2+bx+c\\in\\ker(S)$.\nThis leads to a homogeneous system of four equations in three\nvariables.\nPutting the augmented matrix in {\\rref}:\n\n\\[ \\begin{mymatrix}{rrr|c}\n1 & 1 & 0 & 0  \\\\\n1 & 0 & 1 & 0  \\\\\n0 & 1 & -1 & 0  \\\\\n0 & 1 & 1 & 0  \\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{ccc|c}\n1 & 0 & 0 & 0  \\\\\n0 & 1 & 0 & 0  \\\\\n0 & 0 & 1 & 0  \\\\\n0 & 0 & 0 & 0  \\end{mymatrix}. \\]\n\nThe solution is $a=b=c=0$. This tells us that if $S(p(x)) = 0$, then $p(x) = ax^2+bx+c = 0x^2 + 0x + 0 = 0$. Therefore it is one to one.\n\nTo show that $S$ is \\textbf{not} onto, find a matrix $A\\in\\Mat_{2,2}$\nsuch that for every $p(x)\\in \\Poly_2$,\n$S(p(x))\\neq A$.\nLet\n\\[ A=\\begin{mymatrix}{cc}\n0 & 1 \\\\ 0 & 2 \\end{mymatrix},\\]\nand suppose $p(x)=ax^2+bx+c\\in \\Poly_2$ is such that\n$S(p(x))=A$.\nThen\n\\[ \\begin{array}{ll}\na+b=0 & a+c=1 \\\\ b-c=0 & b+c=2 \\end{array}\\]\nSolving this system\n\\[ \\begin{mymatrix}{ccc|c}\n1 & 1 & 0 & 0  \\\\\n1 & 0 & 1 & 1  \\\\\n0 & 1 & -1 & 0  \\\\\n0 & 1 & 1 & 2  \\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr|r}\n1 & 1 & 0 & 0  \\\\\n0 & -1 & 1 & 1  \\\\\n0 & 1 & -1 & 0  \\\\\n0 & 1 & 1 & 2  \\end{mymatrix}. \\]\n\nSince the system is inconsistent, there is no $p(x)\\in \\Poly_2$ so\nthat $S(p(x))=A$, and therefore $S$ is not onto.\n\\end{solution}\n\n\\begin{example}{An onto transformation}{onto}\nLet $T:\\Mat_{2,2}\\to\\R^2$ be a linear transformation defined by\n\\[ T\\begin{mymatrix}{cc}\na & b \\\\ c & d \\end{mymatrix}\n=\n\\begin{mymatrix}{c}\na+d \\\\ b+c \\end{mymatrix}\n\\mbox{ for all }\n\\begin{mymatrix}{cc}\na & b \\\\ c & d \\end{mymatrix} \\in\\Mat_{2,2}.\\]\nProve that $T$ is onto but not one to one.\n\\end{example}\n\n\\begin{solution}\nLet $\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}$ be an arbitrary vector in $\\R^2$.\nSince\n$T\\begin{mymatrix}{cc} x & y \\\\ 0 & 0 \\end{mymatrix}\n=\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}$,\n$T$  is onto.\n\nBy Lemma~\\ref{lem:one-to-one-abstract} $T$ is one to one if and only if $T(A) = \\vect{0} $ implies that $A = 0$ the zero matrix.\nObserve that\n\\[\nT \\paren{\\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & -1 \\end{mymatrix}}\n=\n\\begin{mymatrix}{c}\n1 + -1 \\\\\n0 + 0\n\\end{mymatrix}\n=\n\\begin{mymatrix}{c}\n0 \\\\\n0\n\\end{mymatrix}\n\\]\nThere exists a non-zero matrix $A$ such that $T(A) = \\vect{0}$. It follows that $T$ is not one to one.\n\\end{solution}\n\nThe following example demonstrates that a one to one transformation preserves linear independence.\n\n\\begin{example}{One to one and independence}{preserves-independence}\nLet $V$ and $W$ be vector spaces and $T: V \\to W$ a linear\ntransformation.\nProve that if $T$ is one to one and\n$\\set{\\vect{v}_1, \\vect{v}_2, \\ldots, \\vect{v}_k}$ is an independent\nsubset of $V$, then\n$\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}$ is an independent\nsubset of $W$.\n\\end{example}\n\n\\begin{solution}\nLet $\\vect{0}_V$ and $\\vect{0}_W$ denote the zero vectors of $V$ and $W$,\nrespectively.\nSuppose that\n\n\\[ a_1T(\\vect{v}_1) + a_2T(\\vect{v}_2) +\\ldots +a_kT(\\vect{v}_k) =\\vect{0}_W \\]\n\nfor some $a_1, a_2, \\ldots, a_k\\in\\R$.\nSince linear transformations preserve linear combinations (addition\nand scalar multiplication),\n\n\\[ T(a_1\\vect{v}_1 + a_2\\vect{v}_2 +\\ldots +a_k\\vect{v}_k) =\\vect{0}_W. \\]\n\nNow, since $T$ is one to one, $\\ker(T)=\\set{\\vect{0}_V}$, and thus\n\n\\[ a_1\\vect{v}_1 + a_2\\vect{v}_2 +\\ldots +a_k\\vect{v}_k =\\vect{0}_V. \\]\n\n\\noindent However, $\\set{\\vect{v}_1, \\vect{v}_2, \\ldots, \\vect{v}_k}$ is independent so $a_1=a_2=\\ldots=a_k=0$.\nTherefore, $\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}$\nis independent.\n\\end{solution}\n\nA similar claim can be made regarding onto transformations. In this case, an onto transformation preserves a spanning set.\n\n\\begin{example}{Onto and spanning}{preserves-spanning}\nLet $V$ and $W$ be vector spaces and $T:V\\to W$ a linear\ntransformation.\nProve that if $T$ is onto and\n$V=\\sspan\\set{\\vect{v}_1, \\vect{v}_2, \\ldots, \\vect{v}_k}$,\nthen\n\\[ W=\\sspan\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}.\\]\n\\end{example}\n\n\\begin{solution}\nSuppose that $T$ is onto and let $\\vect{w}\\in W$.\nThen there exists $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{w}$.\nSince $V=\\sspan\\set{\\vect{v}_1, \\vect{v}_2, \\ldots, \\vect{v}_k}$, there\nexist $a_1, a_2, \\ldots a_k\\in\\R$ such that\n$\\vect{v} = a_1\\vect{v}_1 + a_2\\vect{v}_2 + \\ldots + a_k\\vect{v}_k$.\nUsing the fact that $T$ is a linear transformation,\n\n\\begin{eqnarray*}\n\\vect{w}=T(\\vect{v})\n& = & T(a_1\\vect{v}_1 + a_2\\vect{v}_2 + \\ldots + a_k\\vect{v}_k) \\\\\n& = & a_1T(\\vect{v}_1) + a_2T(\\vect{v}_2) + \\ldots + a_kT(\\vect{v}_k),\n\\end{eqnarray*}\n\ni.e., $\\vect{w}\\in\\sspan\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}$,\nand thus\n\n\\[ W\\subseteq \\sspan\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}.\\]\n\nSince $T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)\\in W$,\nit follows from\nthat\n$\\sspan\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}\\subseteq W$,\nand therefore\n$W=\\sspan\\set{T(\\vect{v}_1), T(\\vect{v}_2), \\ldots, T(\\vect{v}_k)}$.\n\\end{solution}\n", "meta": {"hexsha": "723dbac67d3c27cd0919c97227dd401c9978bdae", "size": 7065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/vectorspacesIsomorphismsOnetoOneOnto.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/vectorspacesIsomorphismsOnetoOneOnto.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/vectorspacesIsomorphismsOnetoOneOnto.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.6428571429, "max_line_length": 193, "alphanum_fraction": 0.6351026185, "num_tokens": 2869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933535169629, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.6935825818071912}}
{"text": "\\SecDef{intro}{Introduction}\n\nS-Boxes play important role in the design of symmetric cryptographic primitives. It is one of the two components of an SPN structure and often S-Boxes are used inside the Feistel functions in Feistel Networks. The main role of S-Boxes is to provide non-linearity and confusion. An S-Box at least should have low linearity, low differential uniformity and high algebraic degree. It is also desirable that the S-Box has good implementation properties: an efficient hardware/bit-slice implementation, small size in order to reduce the memory footprint. \n\nThe cryptographic community expects designers to explain all choices done during the design procedure. How the S-Boxes were generated? Do they have an algebraic structure, e.g. an inversion in the finite field? Or do they have a Feistel Network structure? Were they generated at random? If yes, what was the seed used? Which cryptographic properties were optimized and how?\n\nUnfortunately, often the designers describe the S-Box as a look-up table and do not provide any rationale behind its choice. A prominent example is the S-Box of the Skipjack block cipher designed by the American National Security Agency (NSA). Léo Perrin and Alex Biryukov~\\cite{LeoRE} attempted to \\emph{reverse-engineer} it, i.e. to find the hidden design criteria, an underlying structure or optimization procedure. They succeeded and described a simple optimization method which generates S-Boxes with very close cryptographic properties. The designers of the Russian cryptographic standards did not disclose any rationale behind the S-Box as well, except that it has reasonable cryptographic properties.\n\nThe 8-bit S-Box used in the Kuznyechik block cipher and in the Streebog hash function is denoted $\\pi$ in this chapter. The look-up table of $\\pi\\colon \\field{8} \\to \\field{8}$ is given in \\TabRef{sbox}. It has linearity equal to 56 and differential uniformity equal to 8. Using methods developed in~\\cite{LeoRE}, it can be shown that the probability to randomly sample an S-Box with as good differential properties is approximately $2^{-82.69}$. It follows that $\\pi$ has strong resistance against differential cryptanalysis, compared to random S-Boxes. The algebraic degree of all coordinates of $\\pi$ is maximal and equal to 7.\n\n\\FigTex{sbox.tex}\n\nIn this chapter I describe two decompositions of $\\pi$ and the way in which they were obtained. A simplified view of the discovered structures of $\\pi$ is given in  \\FigRef{simplified}. The first decomposition is based on finite field multiplications. It also contains four 4-bit S-Boxes and two whitening (external) linear layers. Interestingly, 16 inputs clearly stand out from the patterns and force the usage of a multiplexer (omitted in the simplified view). The second decomposition is based on a finite field logarithm. It contains only one extra 4-bit S-Box, one whitening linear layer and a simple arithmetic layer.\n\nMore recently, my former colleague Léo Perrin studied the logarithm-based decomposition further~\\cite{LeoKuz}. He shows that the S-Box maps a partition of $\\field{8}$ into multiplicative cosets of $\\fielde{4}^*$ into a partition of $\\field{8}$ into additive cosets of $\\field{4}$. Furthermore, he derives a structure called $\\mathsf{TKlog}$ that $\\pi$ follows.\n\n\\FigTex{simplified.tex}\n\n\\subsection{Outline}\n\\SecRef{multi} described the first decomposition, and \\SecRef{expo} explains the second decomposition. The results are summarized and discussed in \\SecRef{conclusions}.\n\n\\subsection{Differences with~\\cite{OurKuz1,OurKuz2}}\nThis chapter is a reworked version of the two papers~\\cite{OurKuz1,OurKuz2} that we wrote with my colleagues Alex Biryukov and Léo Perrin. In this chapter I kept only results directly related to decompositions of $\\pi$. The decompositions are kept the same, except that for the first decomposition I performed the analysis for $\\pi$ from the beginning, without decomposing $\\pi^{-1}$ first. In this way $T$ and $U$ are inverted and swapped, compared to~\\cite{OurKuz1}. The final decomposition is the same.\n", "meta": {"hexsha": "017005b96a7661808708e9b6fa75bce6306578dd", "size": 4081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strKuz/00intro.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/00intro.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/00intro.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": 170.0416666667, "max_line_length": 708, "alphanum_fraction": 0.794658172, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.6935825743614484}}
{"text": "\\chapter{Combinatorics}\n\n\\section*{1.1. Assigning seats}\n\\addcontentsline{toc}{section}{1.1. Assigning seats}\nSix girls and four boys are to be assigned to ten seats in a row, with the stipulations\nthat a girl sits in the third seat and a boy sits in the eighth seat. How many arrangements\nare possible?\n\n\\vspace{1em}\n\n\\begin{proof}\n    We compute the number of ways that the boy on the eighth seat and the girl on the third seat can be chosen:\n    \\[\n        \\binom{6}{1}\\binom{4}{1} = 24\n    \\]\n\n    Now, we see how many ways the other kids can be placed on the seats:\n    \\[\n        !8 = 40,320\n    \\]\n\n    Our final result is:\n    \\[\n        24 \\cdot 40,320 = 967,680\n\\]\n\\end{proof}\n\n\\section*{1.2. Number of outcomes}\n\\addcontentsline{toc}{section}{1.2. Number of outcomes}\nOne person rolls two six-sided dice, and another person flips six two-sided coins.\nWhich setup has the larger number of possible outcomes, assuming that the order matters?\n\n\\vspace{1em}\n\n\\begin{proof}\n    The two dice rolls have $6^2 = 36$ possible outcomes, while the coin flips have $2^6 = 64$ outcomes.\n\\end{proof}\n\n\\section*{1.3. Subtracting the repeats}\n\\addcontentsline{toc}{section}{1.3. Subtracting the repeats}\n\\begin{enumerate}[(a)]\n    \\item From Eq. (1.6) we know that the number of ordered sets of three people chosen from five people\n        is $5 \\cdot 4 \\cdot 3 = 60$. Reproduce this result by starting with the naive answer of $5^3 = 125$\n        ordered sets where repetitions are allowed, and then subtracting off the number of triplets that have\n        repeated people.\n    \\item It's actually not much more difficult to solve this problem in the general case where triplets\n        are chosen from N people, instead of five. Repeat part (a) for a general N.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item The number of triplets that have three repeating people is obviously $5$, while the number of \n            triplets with two repetitions is given by $5 \\cdot 4 \\cdot 2 + 5 \\cdot 1 \\cdot 4 = 60$. \n            Therefore, the number of ordered sets of three people chosen from five people is $125 - 60 = 65$.\n\n        \\item The number of triplets that have three repeating people will be $N$, while the number of triplets\n            that have two repeating people will be $N(N - 1) \\cdot 2 + N(N - 1) = 3N(N-1)$. As a result,\n            the number of ordered sets of three people chosen from five people is given by\n            $N^3 - 3N(N - 1) - N = N^3 - 3N^2 + 2N$.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{1.4. Subtracting the repeats, again}\n\\addcontentsline{toc}{section}{1.4. Subtracting the repeats, again}\nRepeat the task of Problem 1.3(a), but now in the case where you pick quadruplets (instead of triplets)\nfrom five people.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The number of ordered sets of 4 people chosen from five people is $5 \\cdot 4 \\cdot 3 \\cdot 2 = 120$.\n\n    To find the number of repeating quadruplets, we split them into 3 categories:\n    \\begin{enumerate}\n        \\item \\textbf{4 repeating people} The repeating person can be chosen in 5 ways and there is only one way\n            to order (AAAAA), so there are 5 such quadruples.\n\n        \\item \\textbf{3 repeating people} The repeating person can be chosen in 5 ways, and then the \n            non-repeating person in 4 ways, thus the number of unorderd quadruples is given \n            by $4 \\cdot 5 = 20$. Since there are 4 (AAAB, AABA, ABAA, BAAA) ways to choose the \n            order, we get $4 \\cdot 20 = 80$ ordered quadruples.\n\n        \\item \\textbf{2 repeating people} The repeating person can be chosen in 5 ways, and the other 2 people\n            can be chosen in $\\binom{4}{2} = 6$ ways. Therefore, we have $5 \\cdot 30 = 50$ unordered quadruples.\n            The sets can be ordered in 12 ways, so we have $30 \\cdot 12 = 360$ orderd quadruples with 2 \n            repeating people.\n\n        \\item \\textbf{2 groups of repeating people} The repeated persons can be chosen in $\\binom{5}{2} = 10$ \n            ways and can be ordered in 6 modes (AABB, ABAB, ABBA, BBAA, BABA, BAAB), therefore the number\n            of such sorted quadruples is 60.\n\n            Therefore, the number of ordered sets of four people from five people is \n            \\[\n                5^4 - 5 - 80 - 360 - 60 = 120\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\vspace{1em}\n\n\\section*{1.6. Many ways to count}\n\\addcontentsline{toc}{section}{1.6. Many ways to count}\nHow many different orderings are there of the six letters: A, A, A, B, B, C? \\\\\nHow many different ways can you think of to answer this question?\n\n\\vspace{1em}\n\n\\begin{proof}\n    We analyze the possible orderings of the letters. The positions of the 3 A letters can be chosen \n    in $\\binom{6}{3} = 20$ ways, and then the positions of the two B letters can be chosen in\n    $\\binom{3}{2} = 3$ modes. Since the C letter has the last position, we find that the number of possible\n    orderings is now $20 \\cdot 3 = 60$.\n\n    The same method can be applied for any ordering of letter-position assignments (e.g. we choose the \n    possible positions of B and then of A and C). We'll get different formulas, but the result will be the\n    same. There are $3 \\cdot 2 = 6$ such ways of computing the number of possible orderings.\n\\end{proof}\n\n\\section*{1.7. Committees with a president}\n\\addcontentsline{toc}{section}{1.7. Committees with a president}\nTwo students are given the following problem: From $N$ people, how many ways are there to choose a committee\nof $n$ people, with one person chosen as the president? One student gives an answer of $n\\binom{N}{n}$, while\nthe other student gives an answer of $N\\binom{N-1}{n-1}$.\n\n\\begin{enumerate}[(a)]\n    \\item By writing out the binomial coefficients, show that the two answers are equal.\n    \\item Explain the (valid) reasoning that lead to these two (correct) answers.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item We simply rewrite the expressions to obtain the equality:\n        \\[\n            n\\binom{N}{n} = n\\frac{N!}{n!(N-n)!} = \\frac{N!}{(n-1)!(N-n)!} = N\\frac{(N-1)!}{(n-1)!(N-n)!}\n                          = N\\binom{N-1}{n-1}\n        \\]\n        \\item The president can be chosen in $N$ ways and then the rest of the group can be chosen in \n            $\\binom{N-1}{n-1}$ modes, giving us $N\\binom{N-1}{n-1}$ ways to form the committee.\n\n            Without thinking about the president, the committee can be chosen in $\\binom{N}{n}$ ways. In \n            such a committee any of the $n$ persons can be chosen as the president. Therefore, we have \n            $n\\binom{N}{n}$ ways to form the committee.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{1.8. Multinomial coefficients}\n\\addcontentsline{toc}{section}{1.8. Multinomial coefficients}\n\\begin{enumerate}[(a)]\n    \\item A group of ten people are divided into three committees. Three people are on committee\n        A, two are on committee B, and five are on committee C. How many different ways are there \n        to divide up the people?\n\n    \\item\n        A group of N people are divided into k committees. $n_1$ people are on committee 1, $n_2$\n        people are on committee 2, \\dots, and $n_k$ people are on committee $k$, with \n        $n_1 + n_2 + \\dots + n_k = N$. How many different ways are there to divide up the people?\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item The people on committee A can be chosen in $\\binom{10}{3} = 120$ ways and then the people on\n            committee B can be chosen in $\\binom{7}{2} = 21$ ways. The remaining people will be on the C\n            committee. As a result, the group of ten people can be divided in $120 \\cdot 21 = 2,520$ ways.\n        \n        \\item We assign people to committees like in the previous example. The 1st committee's members\n            can be chosen in $\\binom{N}{n_1}$ modes, the 2nd committee's composition can be chosen in \n            $\\binom{N - n_1}{N_2}$ ways, and so on. We observe (and can prove using induction), that the\n            number of ways the i-th ($2 \\leq i < k$) committee can be assembled is given by the expression:\n            \\[\n                M_i = \\binom{N - n_1 - \\ldots - n_{i - 1}}{n_i}\n            \\]\n            Therefore, the number of ways the group of people can be divided is given by:\n            \\begin{align*}\n                M = \\binom{N}{n_1} \\prod_{i = 2}^{k}M_i \n                    =& \\binom{N}{n_1} \\binom{N - n_1}{n_2} \\ldots \\binom{N - n_1 - \\ldots - n_{k - 1}}{n_k} \\\\\n                    =& \\frac{N!}{n_1! (N - n_1)!} \\cdot \\frac{(N - n_1)!}{n_2! (N - n_1 - n_2)!} \\cdot \\ldots \n                    \\cdot \\frac{(N - n_1 - \\ldots - n_{k - 1})!}{n_3! (N - n_1 - \\ldots - n_{k - 1} - n_k)!} \\\\\n                    =& \\frac{N!}{n_1!n_2! \\ldots n_k!}\n            \\end{align*}\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{1.9. One heart and one 7}\n\\addcontentsline{toc}{section}{1.9. One heart and one 7}\nHow many different five-card poker hands contain exactly one heart and exactly one 7? (If the hand\ncontains the 7 of hearts, then this one card satisfies both requirements.)\n\n\\vspace{1em}\n\n\\begin{proof}\n    There are $52 - 13 - 4 + 1 = 36$ cards that are neither a heart nor a 7. We consider two cases:\n    \\begin{enumerate}[(i)]\n        \\item \\textbf{The 7 of hearts is in the hand}, so the other 4 cards in the hand\n            can be any that are neither a heart nor a 7. As a result, we have \n            $\\binom{36}{4}= 58,905$ such hands.\n\n        \\item \\textbf{The 7 of hearts is not in the hand.} There are 12 cards that are hearts and \n            not a 7 and 3 cards that are 7 but not a heart. We choose one of each and the rest of \n            the cards can be any that are neither a heart nor a 7. Hence, we get\n            $12 \\cdot 3 \\binom{36}{3} = 257,040$ such hands.\n    \\end{enumerate}\n    In conclusion, there are $286,110 + 257,040 = 315,945$ five-card hands that contain exactly\n    one heart and exactly one 7.\n\\end{proof}\n\n\n\\section*{1.14. Yahtzee}\n\\addcontentsline{toc}{section}{1.14. Yahtzee}\nIn the game of Yahtzee, five dice are rolled in a group, with the order not mattering.\n\n\\begin{enumerate}[(a)]\n    \\item Using Eq. (1.16), how many unordered rolls (sets) are possible?\n\n    \\item In the spirit of the examples at the beginning of Section 1.7. reproduce the\n        result in part (a) by determining how many unordered rolls there are\n        of each general type (for example, three of one number and two of another, etc.)\n\n    \\item In the spirit of the example at the end of Section 1.7., show that the total\n        number of \\emph{ordered} Yahtzee rolls is $6^5 = 7776$.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item The number of unordered rolls is given by \n            \\[\n                \\binom{5 + (6 - 1)}{6 - 1} = \\binom{10}{5} = 252\n            \\] \n\n        \\item We split the rolls in 7 types:\n            \\begin{enumerate}[(1)]\n                \\item All five rolls are the same (e.g. 66666). There are 6 sets of this type.\n\n                \\item Four rolls have the same value and the other roll has another value (e.g. 66665).\n                    There are $6 \\cdot 5 = 30$ sets of this type.\n                \n                \\item Three rolls have the same value and the other two rolls have other (different 2 by 2)\n                    values (e.g. 66654). There are  $6 \\binom{5}{2} = 6 \\cdot 10 = 60$ sets of this type.\n\n                \\item Three rolls have the same value and the other two rolls have both another (same) value \n                    (e.g. 66655). There are $6 \\cdot 5 = 30$ sets of this type.\n\n                \\item Two rolls have the same value and the other three rolls have different (2 by 2) values\n                    (e.g. 66654). There are $6 \\binom{5}{2} = 60$ such sets.\n\n                \\item Two rolls have the same value, two rolls have another (same value) and the \n                    remaining roll has another different value (e.g. 66554). \n                    There are $6 \\binom{5}{2} = 60$ such sets of rolls.\n\n                \\item Each roll has a different value. (e.g. 65432). There are $\\binom{6}{5} = 6$ such sets.\n            \\end{enumerate}\n\n        By summing all the types, we get that the number of unordered rolls is \n        \\[\n            6 + 30 + 60 + 30 + 60 + 60 + 6 = 252\n        \\] \n\n    \\item We want to see in how many ways can the 5 roll types be ordered:\n        \\begin{enumerate}[(1)]\n            \\item All rolls are the same, so the set can be ordered in one way. The number of \n                ordered sets with the same 5 rolls is 6.\n\n            \\item Four rolls have the same value and the other roll has another value.\n                The set can be ordered in 5 ways (we consider the different roll on each\n                possible position). Therefore, there are $5 \\cdot 30 = 150$ ordered sets of this type.\n\n            \\item Three rolls have the same value and the other two have other (different 2 by 2) values.\n                The positions of the repeated values can be chosen in $\\binom{5}{3} = 10$ and then there \n                are two ways to order the other values, so there are $10 \\cdot 2 = 20$ ways to order the set.\n                As a result, there are $20 \\cdot 60 = 1200$ ordered sets of this type.\n\n            \\item Three rolls have the same value and the other two rolls have both another (same) value.\n                There are $\\binom{5}{3} = 10$ ways the sets can be ordered, so we get $10 \\cdot 30 = 300$\n                such ordered sets.\n\n            \\item Two rolls have the same value and the other three have other (different 2 by 2) values.\n                As before, we find that the set of values can be ordered in \n                $\\binom{5}{2} \\cdot 3 \\cdot 2 = 60$ ways.\n                Hence, there are $60 \\cdot 60 = 3600$ such ordered sets.\n\n            \\item Two rolls have the same value, two rolls have another (same value) and the \n                remining roll has another differente value. There are \n                $\\binom{5}{2}\\binom{3}{2} = 10 \\cdot 3 = 30$ ways to order this set, so we get \n                $30 \\cdot 60 = 1800$ such ordered sets.\n\n            \\item All rolls have different values. The sets can be ordered in $5! = 120$ ways. As a result,\n                there are $120 \\cdot 6 = 720$ such ordered sets.\n        \\end{enumerate}\n\n        In conclusion, we get that the number of $\\emph{ordered}$ sets of Yahtzee rolls is:\n        \\[\n            6 + 150 + 1200 + 300 + 3600 + 1800 + 720 = 7776 = 6^5\n        \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{1.16. Pascal sum 2}\n\\addcontentsline{toc}{section}{1.16. Pascal sum 2}\nAt the end of Section 1.8.3, we demonstrated the relation \n$\\binom{n}{k} = \\binom{n - 1}{k - 1} + \\binom{n - 1}{k}$\nby using the argument involving committees. Repeat this reasoning,\nbut now in terms of:\n\\begin{enumerate}[(a)]\n    \\item coin flips,\n    \\item the $(a + b)^n$ binomial expansion.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item The number of ways we can get $k$ tails from $n$ coin flips is given by \n            $\\binom{n}{k}$. If we single out the first flip, we get two cases:\n            \\begin{enumerate}[(1)]\n                \\item The flip was heads, so the number of ways to get tails $k$ times\n                    from the rest $n - 1$ of the flips is $\\binom{n - 1}{k}$\n\n                \\item The flip was tails, so the number of ways to get the remaining \n                    $k - 1$ tails flips from the other $n - 1$ rolls is given by $\\binom{n - 1}{k - 1}$\n            \\end{enumerate}\n\n        Therefore, the number of ways we get $k$ tails from $n$ coin flips can be split into the above\n        two cases, so:\n        \\[\n            \\binom{n}{k} = \\binom{n - 1}{k} + \\binom{n - 1}{k - 1}\n        \\] \n\n    \\item The coefficient of the term $a^{n - k}b^k$ from the expansion of $(a + b)^n$ is given by \n        $\\binom{n}{k}$. If we single out the first $(a + b)$ factor, we have two possible situations:\n        \\begin{enumerate}\n            \\item The factor was used in getting a power of $b$ in $a^{n - k}b^k$, so there are \n                $\\binom{n - 1}{k - 1}$ factors to use for the other $k - 1$ powers of $b$ and the $n - k$ \n                powers of $a$, since \n                $\\binom{n - 1}{n - k} = \\binom{n - 1}{k - 1}$.\n\n            \\item The factor wasn't used in getting a power of $b$ in $a^{n - k}b^k$, so there are \n                $\\binom{n - 1}{k}$ factors to use for the other $k$ b powers and the other $n - k - 1$ \n                powers of a, since $\\binom{n - 1}{n - k - 1} = \\binom{n - 1}{k}$.\n        \\end{enumerate}\n\n    Therefore, the coefficient of $a^{n-k}b^k$ is given by:\n    \\[\n        \\binom{n}{k} = \\binom{n - 1}{k} + \\binom{n - 1}{k - 1}\n    \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{1.17. Pascal diagonal sum}\n\\addcontentsline{toc}{section}{1.17. Pascal diagonal sum}\n\\begin{enumerate}[(a)]\n    \\item If we pick an unordered committee of three people from five people (A, B, C, D, E),\n        we can list the $\\binom{5}{3} = 10$ possibilities as shown in Table 1.19.\n        We have grouped them according to which letter comes first. (The order of letters\n        doesn't matter, so we've written each triplet in increasing alphabetical order.)\n        The columns in the table tell us that we can think of $10$ as equaling $6 + 3+ 1$.\n        Explain why it makes sense to write this sum as  $\\binom{4}{2} + \\binom{3}{2} + \\binom{2}{2}$.\n\n        \\begin{table}[h]\n            \\centering\n            \\begin{tabular}{ccc}\n                A B C & & \\\\ \n                A B D & & \\\\\n                A B E & & \\\\\n                A C D & B C D & \\\\\n                A C E & B C E & \\\\\n                A D E & B D E & C D E \\\\\n            \\end{tabular}\n            \\caption*{\\textbf{Table 1.19:} Unordered triplets chosen from five people.}\n        \\end{table}\n\n    \\item You can also see from Table 1.15 and 1.16 that, for example \n        $\\binom{6}{3} = \\binom{5}{2} + \\binom{4}{2} + \\binom{3}{2} + \\binom{2}{2}$.\n    More generally,\n    \\begin{equation*}\\tag{1.29}\n        \\binom{n}{k} = \\binom{n - 1}{k - 1} + \\binom{n - 2}{k - 2} + \\binom{n - 3}{k - 3} + \\ldots + \n                        \\binom{k}{k - 1} + \\binom{k - 1}{k - 1}\n    \\end{equation*}\n\n    In words: A given number (for example, $\\binom{6}{3}$) in Pascal's triangle equals the sum\n    of the numbers in the diagonal string that starts with the number that is above and to the \n    left of the given number ($\\binom{5}{2}$ in this case) and then proceeds upward to the right.\n    So the string contains $\\binom{5}{2}, \\binom{4}{2}, \\binom{3}{2}$ and $\\binom{2}{2}$\n    in this case.\n\n    Prove Eq.(1.29) by making repeated use of Eq.(1.22), which says that each number in Pascal's\n    triangle is the sum of the two numbers abot it (or just the \"1\" above it, if it occurs at the end \n    of a line).\n\\end{enumerate}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item We split the committees into 4 categories:\n            \\begin{enumerate}[(1)]\n                \\item The set contains A, so there are $\\binom{4}{2} = 6$ such sets.\n                \\item The set contains B and doesn't contain A, so there are $\\binom{3}{2} = 3$ sets.\n                \\item The set contains C and doesn't contain A or B, so there is $\\binom{2}{2} = 1$\n                \\item The set doesn't contain A, B or C. There are obviously no such sets, as we\n                    need 3 elements.\n           \\end{enumerate}\n\n        Since the reunion of those sets contains all the possible unordered committees of 3 members,\n        we obtain that:\n        \\[\n            \\binom{4}{2} + \\binom{3}{2} + \\binom{2}{2} = 6 + 3 + 1 = 10 = \\binom{5}{3}\n        \\] \n        \n        \\item We prove using induction that:\n        \\begin{equation*}\\tag{1.29}\n            \\binom{n}{k} = \\binom{n - 1}{k - 1} + \\binom{n - 2}{k - 2} + \\ldots + \n                            \\binom{k}{k - 1} + \\binom{k - 1}{k - 1}\n                            = \\sum_{i = k}^{n} \\binom{i - 1}{k - 1}, \\forall k \\in \\mathbb{N^*}, k \\leq n\n        \\end{equation*}\n        for all $n \\in \\mathbb{N}, n \\geq 2$.\n\n        The base case is obviously valid, since\n        \\begin{align*}\n            \\binom{2}{1} &= \\binom{1}{0} + \\binom{0}{0} = 1 + 1 = 2 \\\\\n            \\binom{2}{2} &= \\binom{1}{1} + \\binom{0}{1} = 1 + 0 = 1\n        \\end{align*}\n\n        We assume that the relation holds for a fixed $m \\in \\mathbb{N}, m \\geq 2$, so we have:\n        \\[\n            \\binom{m}{k} = \\sum_{i = k}^{m}\\binom{i - 1}{k - 1}, \\forall k \\in \\mathbb{N^*}, k \\leq n\n        \\]\n\n        Using (1.22), we obtain that: \n        \\[\n            \\binom{m + 1}{k} = \\binom{m}{k} + \\binom{m}{k - 1} \n                             = \\sum_{i = k}^{m}\\binom{i - 1}{k - 1} + \\binom{m}{k - 1} \n                             = \\sum_{i = k}^{m + 1}\\binom{i - 1}{k - 1} \n        \\] \n\n        Since (1.22) holds true for the base case and the $m$ case implies the validity of the $m + 1$ case,\n        we proved using induction that (1.29) holds for all $n \\in \\mathbb{N}, n \\geq 2$.\n    \\end{enumerate}\n\\end{proof}\n", "meta": {"hexsha": "50aea3400309830f6818904f8f754de7d8c99f90", "size": 21310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1_combinatorics.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/chapter1_combinatorics.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/chapter1_combinatorics.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": 47.3555555556, "max_line_length": 112, "alphanum_fraction": 0.5969028625, "num_tokens": 6419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6935825706385769}}
{"text": "\\subsection{Application of Array in Image Analysis}\n\\subsubsection{Intensity Profile and Array Functions}\n\nTo learn the actual use of array in image analysis, we explore several example applications. In the first application, we use \\ilcom{getProfile} function. We already used \\ilcom{getProfile()} in the section \\ref{subsec:numericalarray} ``Numerical Array''. This time, we use it in combination with Array functions to get local minima along the intensity profile - just like finding downward peak positions. We use a sample image Tree\\textunderscore Rings.jpg (\\ijmenu{[File > Open Samples > Tree Rings]}). \n \nWe draw a straight line ROI crossing tree rings, and then the aim of the macro we will write is to detect ring positions along that line ROI and indicate those positions by point ROIs. The macro first reads the line-profile from the straight line ROI and then we use \\ilcom{Array.findMinima} function to detect local minima (dark rings). Since this function returns the position of minima only as indices of the line-profile array, we need to get \\ilcom{x} and \\ilcom{y} coordinates of minima from their indices in order to plot minima positions in the original image. For this purpose, we resample the straight line ROI to the same number of points as the length of line-profile array. Let's write the code and learn by doing. \n\nNote: Before running the macro code20\\_4.ijm, be sure to have a straight line ROI placed crossing tree rings (fig. \\ref{fig:treeRingsSelected}). \n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{fig/Tree_Rings_Selected.png}\n\\caption{A strainght Line ROI crossing rings.}\n\\label{fig:treeRingsSelected}\n\\end{center}\n\\end{figure}\n\n\n\\lstinputlisting[morekeywords={*, getProfile, Array, findMinima, resample, print, getStatistics}]{code/code20_4.ijm}\n\n\n\\begin{itemize}\n\\item line 3 - 4:  Check if the selection type is a straight line ROI using function \\ilcom{selectionType}. If not, macro terminates leaving a message.\n\\item Line 5: An intensity profile array \\ilcom{pA} is sampled by \\ilcom{getProfile}().\n\\item Line 6: Detect local minima using \\ilcom{Array.findMinima}. The first argument is the line-profile array, and the second argument is ``tolerance''. A larger tolerance value is less sensitive to intensity minimum - less detection. You could try changing this value later to see the effect. An array containing indices of minima positions is returned. \n\\item Line 7: \\ilcom{getSelectionCoordinates} with straight-line ROI stores two arrays, each for start/end x coordinates and start/end y coordinates. Two arrays, in this case \\ilcom{xpoints} and \\ilcom{ypoints}, have length of two. \n\\item Line 8 - 9: Resampling of straight-line ROI by number of points in the line-profile array \\ilcom{pA}.\n\\item Line 10-11: Prepare two new arrays to store x and y coordinates of minima positions. \n\\item Line 12: For-loop to go through minima indices array. \n\\item Line 13-14: \\ilcom{minsA[i]} is the index for a single minimum, and using that index, x and y coordinate of that minimum position is retrieved and stored into new arrays prepared in line 10-11. \n\\item Line 16: After the looping, x and y coordinates of minima are used in \\ilcom{makeSelection} function to create multiple point ROI. \n\\end{itemize}\n\nRun the code, then you should see multiple point ROIs indicating positions of rings (See fig. \\ref{fig:treeRingsSelected}). Similar macro can be used to measure striated pattens in tissues or cell edges. In case of fluorescence images, \\ilcom{Array.findMaxima} can be used to detect high-intensity maxima positions. \n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{fig/Tree_Rings_Minima.png}\n\\caption{Detected ring positions.}\n\\label{fig:treeRingsMinima}\n\\end{center}\n\\end{figure}\n\n\n\\subsubsection{Extending Stack Analysis by Direct Measurements}\n\nWe studied how to use for-loops to measure each frame/slice within a stack (\\ref{sec:forloopStack}). There we did measurements by firstly setting measurement parameters with \\ilcom{run(\"Set Measurements...\")} and then did measurement by \\ilcom{run(\"Measure\")}. Measured values were shown in the table in the ``Results'' window. To use those measured values to \\textit{e.g.} calculate statistics or plot the results, one should access the table in the ``Results'' window and parse all the values. This is possible with the macro language, but we will not try this method as it is indirect. Instead, we try to access directly to the measured values and compute. There are two ways. \n\n\\begin{enumerate}\n\\item \\ilcom{getRawStatistics(nPixels, mean, min, max, std, histogram)}\n\\item \\ilcom{List.setMeasurement}\n\\end{enumerate}\nThe function \\ilcom{getRawStatistics} measures statistical parameters from the image and returns those values in the variables declared as arguments. In other words, after this function is executed, variable \\ilcom{mean} will have the mean intensity of the image\n\\footnote{In this example we use a variable named \\ilcom{mean}, but the name could be anything such as \\ilcom{a} or \\ilcom{b}.}. \nIf a ROI is selected, mean intensity of that ROI will be the value of \\ilcom{mean}. We could loop each slice/frame within a stack and for each loop we could do \\ilcom{getRawStatistics} and store measured values in arrays. But there is a drawback of using this function: the available parameters to measure is limited. \n\nThe second method \\ilcom{List.setMeasurement} does not have this limitation. One could measure many more parameters because all the available parameters listed in \\ilcom{[Analyze > Set Measurements...]} are accessible with this function. The basic usage is shown in the code below, which measures the currently active image, extracts specific measurement value (in this example case ``Mean'' intensity) and then prints out that value in the log window. Try writing this code and test it with any image. \n\n\\begin{lstlisting}\nList.setMeasurements;\nmean = List.getValue(\"Mean\");\nprint(mean)\n\\end{lstlisting}\n\nWe could do the measurement using \\ilcom{List.setMeasurement} function for every loop for stack slices/frames and store the results in arrays. Here is the code, a modified version of code 10 (p~\\pageref{code:10}). \n\n\\lstinputlisting[morekeywords={*, List, setMeasurements, getValue, newArray}]{code/code10_1.ijm}\n\n\\begin{itemize}\n  \\item Line 2: Checks the ImageJ version, since \\ilcom{List.setMeasurements} function is only available after version 1.42i.\n  \\item Line 5, 6: Create new arrays with their length equal to the number of frames of the stack. These arrays will be used to store measurement results. \n  \\item Line7: for-loop going through each frames in the stack.\n  \\item Line 10: Measure. All the parameters will be stored in the List. \n  \\item Line 11, 12: Retrieve the results, mean intensity and its standard deviation. \n  \\item Line 15, 16: Print out results in the log window. \n\\end{itemize}\n\n\\subsubsection{Acquiring intensity profile from segmented line ROI}\n \nIn recent version of ImageJ, selection thickness controls the width of segmented\nline ROI when you do \\ijmenu{[Analyze > Plot Profile])}. We try to mimick this\nbehavior in macro, and instead of choosing the line ROI thickness using GUI, the\nmacro asks the user to input the thickness. \n\nIn the code below, there is only one macro. Two functions are added at the\nbottom. One is for profile plotting and the last one is for listing\nintensity profile data in the result table. Strategy of this macro is to use\nstraight line selection for each segment, measure that segment and then profiles\nare concatenated to the total profile array.\n\n%\\lstinputlisting[morekeywords={*, newArray, selectionType, getProfile, setResult, updateResults}]{code/code20_75.ijm}\n%\\lstinputlisting[morekeywords={*, getSelectionCoordinates, makeLine, Plot,\n% create, setLimits, setColor, add, show}]{code/code20_75.ijm}\n\\lstinputlisting[morekeywords={*, getSelectionCoordinates, makeLine, Plot,\ncreate, setLimits, setColor, add, show, Array, concat,\ngetStatistics}]{code/code20_76.ijm}\n\n\\begin{itemize}\n\\item Lines 2 - 16: Main part, macro for the segmented line ROI measurement.  \n\n\\item Line 3: Check if the selection type is a segmented line ROI. If not, macro\nterminates leaving a message.\n\n\\item Line 4: Reads the x and y coordinates of the segmented line\nand store them in two arrays \\ilcom{xCA} and \\ilcom{yCA}.\n\n\\begin{indentCom}\n\\textbf{getSelectionCoordinates(xCoordinates, yCoordinates)}\\\\\nReturns two arrays containing the X and Y coordinates of the points that define the current selection. \n\\end{indentCom}\n\n\\item Line 5 - 7: Asks the user to input width of the segmented ROI. The ROI\nline width is set to that value.\n\n\\item Line 8: A new array \\ilcom{totalprofile} is created, initialized without\nany element. This new array will store the profile data of full ROI.\n\n\\item Line 9 - 13: Profile measurement by placing straight line ROI,\nfor wach segment of the original ROI. \\ilcom{makeLine} function is used for this\npurpose, and \\ilcom{getProfile} returns intensity profile of the corresponding\nline ROI. Profile data in \\ilcom{thisprofile} array are concatenated to\n\\ilcom{totalprofile} array using \\ilcom{Array.concat}.\n\n\\begin{indentCom}\n\\textbf{makeLine(x1, y1, x2, y2)}\\\\\nCreates a new straight line selection. The origin (0,0) is assumed to be the upper left corner of the image. Coordinates are in pixels. With ImageJ 1.35b and letter, you can create segmented line selections by specifying more than two coordinate, for example makeLine(25,34,44,19,69,30,71,56).\n\\end{indentCom}\n\n\\item Line 14: Call graph plotting function (Line 20 - 27), passing\n\\ilcom{totalprofile} array as an argument.\n\n\\item Line 15: call function to printout the profile array in the results window\n(Lines 32 - 39).\n\n\\item Line 20 - 27: Function for plotting the intensity profile.\n\\item Line 21 : Use \\ilcom{Array.getStatistics} function to know the minimum and\nthe maximum value of the array that was given as argument.\n\\item Line 22: Creates the window and axes of the plot. \n\\item Line 23: Set the range for x and y axis using the results of line 21\n\\ilcom{min} and \\ilcom{max}. 5\\% of offset is added to both values for some\nmargins below and above.\n\\item Line 24: Sets the color of the plot. \n\\item Line 25: Plot the profile. \n\\item Line 26: Show the plot on the screen (lot is hidden until this show()\nfunction).\n\n\\item Line 30 - 37: Function for outputting the profile array in the result\ntable. This function is exactly the same function you already used in the\nprevious chapter (code 20.5).\n\n\\end{itemize}\n\n\\subsubsection{Build-in Macro Functions using Array}\n\nMany built-in macro functions return an array, to have multiple numerical values as a singular object. Below is a list of those array-returning functions. \n\n\\begin{indentCom}\n\\texttt{\n\\item Dialog.addChoice(\"Label\", items) \n\\item Dialog.addChoice(\"Label\", items, default)\n\\item Fit.doFit(equation, xpoints, ypoints)\n\\item Fit.doFit(equation, xpoints, ypoints, initialGuesses)\n\\item getFileList(directory)\n\\item getHistogram(values, counts, nBins[, histMin, histMax])\n\\item getList(\"window.titles\")\n\\item getList(\"java.properties\")\n\\item getLut(reds, greens, blues)\n\\item getProfile()\n\\item getRawStatistics(nPixels, mean, min, max, std, histogram)\n\\item getSelectionCoordinates(xCoordinates, yCoordinates)\n\\item getStatistics(area, mean, min, max, std, histogram)\n\\item makeSelection(type, xcoord, ycoord)\n\\item newArray(size)\n\\item newMenu(macroName, stringArray)\n\\item Plot.create(\"Title\", \"X-axis Label\", \"Y-axis Label\", xValues, yValues)\n\\item Plot.add(\"circles\", xValues, yValues)\n\\item Plot.getValues(xpoints, ypoints)\n\\item setLut(reds, greens, blues)\n\\item split(string, delimiters) \n}\n\\end{indentCom}\n\n\n", "meta": {"hexsha": "56175d14f85e4ba7346a762a8d276ee591bc080e", "size": 11726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/experimentalTools/ImageJ/reference/cmci-ij_textbook2-d852848/sections/adv/macroAdv_ArrayApplications.tex", "max_stars_repo_name": "mistltoe/mistltoe.github.io", "max_stars_repo_head_hexsha": "2e465787f2a06fd795460432297b90cf0fbf721b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/experimentalTools/ImageJ/reference/cmci-ij_textbook2-d852848/sections/adv/macroAdv_ArrayApplications.tex", "max_issues_repo_name": "mistltoe/mistltoe.github.io", "max_issues_repo_head_hexsha": "2e465787f2a06fd795460432297b90cf0fbf721b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/experimentalTools/ImageJ/reference/cmci-ij_textbook2-d852848/sections/adv/macroAdv_ArrayApplications.tex", "max_forks_repo_name": "mistltoe/mistltoe.github.io", "max_forks_repo_head_hexsha": "2e465787f2a06fd795460432297b90cf0fbf721b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.7282608696, "max_line_length": 728, "alphanum_fraction": 0.7771618625, "num_tokens": 2969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6935825695848078}}
{"text": "\\chapter{Survival Trees}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{The Log-Rank Test}\n\nThe \\textbf{log-rank test} (Mantel 1966; Peto and Peto 1972) is a test for statistical equivalence of two survival curves. It is obtained by constructing a $2x2$ contingency table at the time of each event and comparing the failure rates between the two groups, conditional on the number at risk in each group\\footnote{See https://bookdown.org/sestelo/sa\\_financial/comparing-survival-curves.html.}. In this way, the test compares the entire survival experience between groups. The null hypothesis is that the true underlying curves for the two groups are identical.\n\n``In the absence of censoring, these methods reduce to the Wilcoxon-Mann-Whitney rank-sum test (Mann and Whitney 1947) for two samples and to the Kruskal-Wallis test (Kruskal and Wallis 1952) for more than two groups of survival times.''\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Survival Example: Primary Biliary Cirrhosis}\n\nNow let's consider how the same tree-building machinery \n\nThis data is from the Mayo Clinic trial in primary biliary cirrhosis (PBC) of the liver conducted between 1974 and 1984. A total of 424 PBC patients, referred to Mayo Clinic during that ten-year interval, met eligibility criteria for the randomized placebo controlled trial of the drug D-penicillamine. The first 312 cases in the data set participated in the randomized trial and contain largely complete data. The additional 112 cases did not participate in the clinical trial, but consented to have basic measurements recorded and to be followed for survival. Six of those cases were lost to follow-up shortly after diagnosis, so the data here are on an additional 106 cases as well as the 312 randomized participants.\n\n\n\n\\begin{question}{}\nHere's a dataset of survival data... how would you build a survival forest?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Random Survival Forests}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Boosted Survival Trees}\n\n", "meta": {"hexsha": "62b9891b8e00c6049e0d30a785c10d75a1f2f102", "size": 2219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-survival-trees.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-survival-trees.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-survival-trees.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": 59.972972973, "max_line_length": 720, "alphanum_fraction": 0.6768814781, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933315126791, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.6935825695616875}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Most powerful tests}\\label{sec:most_powerful_tests}\n\n\\begin{definition}\nLet $C_1$ and $C_2$ be two critical regions of size $\\alpha$ for testing $H_0:\\theta\\in\\Theta_0$ against $H_1:\\theta\\in\\Theta_1$ and consider the power functions $\\gamma_1(\\theta)$ and $\\gamma_2(\\theta)$ of the associated tests, \n\\[\n\\gamma_1(\\theta) = \\prob_{\\theta}(X\\in C_1) \\quad\\text{and}\\quad \\gamma_2(\\theta) = \\prob_{\\theta}(X\\in C_2) \\quad\\text{for $\\theta\\in\\Theta_1$.}\n\\]\nIf $\\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$. \n\\end{definition}\n\n\\begin{definition}\nLet $C$ be a critical region of size $\\alpha$ for testing $H_0:\\theta\\in\\Theta_0$ against $H_1:\\theta\\in\\Theta_1$. Then the associated test is called a \\emph{most powerful test} of size $\\alpha$ if for every subset $A\\subset D$ of size $\\alpha$,\n\\[\n\\prob_{\\theta}(\\mathbf{X}\\in C) \\geq \\prob_{\\theta}(\\mathbf{X}\\in A) \\quad\\text{for all $\\theta\\in\\Theta_1$.}\n\\]\nThis means that the test is at least as powerful as any other test of size $\\alpha$.\n\\end{definition}\n\n%-----------------------------\n\\subsection{The Neyman-Pearson lemma}\n\n\\begin{theorem}[The Neyman-Pearson lemma]\nThe likelihood ratio test is a most powerful test of a simple null hypothesis against a simple alternative.\n\\end{theorem}\n\\begin{proof}\nLet $H_0:\\theta=\\theta_0$ and  $H_1:\\theta=\\theta_1$. The SLRT is given by the critical region\n\\[\nC = \\left\\{\\mathbf{x}:\\lambda(\\mathbf{x}) \\leq k\\right\\}\n\\quad\\text{where}\\quad\n\\lambda(\\mathbf{x}) = \\frac{L(\\theta_0;\\mathbf{x})}{L(\\theta_1;\\mathbf{x})}\n\\]\nLet $A$ be another critical region of size $\\alpha$. We need to show that $\\prob_{\\theta_1}(C) \\geq \\prob_{\\theta_1}(A)$.\n\n\\bit\n\\it If $\\mathbf{x}\\in C\\setminus A$, then $\\lambda(\\mathbf{x})\\leq k$, so $L(\\theta_1;\\mathbf{x}) \\geq \\displaystyle\\frac{1}{k}L(\\theta_0;\\mathbf{x})$, or equivalently  $f(\\mathbf{x};\\theta_1) \\geq \\displaystyle\\frac{1}{k}f(\\mathbf{x};\\theta_0)$\n\\it If $\\mathbf{x}\\in A\\setminus C$, then $\\lambda(\\mathbf{x})> k$, so $L(\\theta_1;\\mathbf{x}) \\leq \\displaystyle\\frac{1}{k}L(\\theta_0;\\mathbf{x})$, or equivalently $f(\\mathbf{x};\\theta_1) \\leq \\displaystyle\\frac{1}{k}f(\\mathbf{x};\\theta_0)$\n\\eit\n\nHence, for continuous distributions (the discrete case is similar),\n\\begin{align*}\n\\prob_{\\theta_1}(C) - \\prob_{\\theta_1}(A)\n\t& = \\int_{C} L(\\theta_1;\\mathbf{x})\\,d\\mathbf{x} - \\int_{A} L(\\theta_1;\\mathbf{x})\\,d\\mathbf{x} \\\\\n\t& = \\int_{C\\setminus A} L(\\theta_1;\\mathbf{x})\\,d\\mathbf{x} - \\int_{A\\setminus C} L(\\theta_1;\\mathbf{x})\\,d\\mathbf{x} \\\\\n\t& \\geq \\frac{1}{k}\\left(\\int_{C\\setminus A} L(\\theta_0;\\mathbf{x})\\,dx - \\int_{A\\setminus C} L(\\theta_0;\\mathbf{x})\\,dx\\right) \\\\\n\t& = \\frac{1}{k}\\left(\\int_{C} L(\\theta_0;\\mathbf{x})\\,dx - \\int_{A} L(\\theta_0;\\mathbf{x})\\,dx\\right) \\\\\n\t& = \\frac{1}{k}(\\alpha-\\alpha) \\\\\n\t& = 0.\n\\end{align*}\n\nThus $\\prob_{\\theta_1}(C) \\geq \\prob_{\\theta_1}(A)$ and because this holds for any critical region $A$ of size $\\alpha$, we conclude that the SLRT is a most powerful test of $H_0:\\theta=\\theta_0$ against $H_1:\\theta=\\theta_1$.\n\\end{proof}\n\n\n% example: SLRT for Poisson\n\\begin{example}%[SLRT for the mean of a Poisson distribution]\nLet $X_1,\\ldots,X_n$ be a random sample from the $\\text{Poisson}(\\theta)$ distribution. Find a most powerful test of the simple hypothesis $H_0:\\theta=2$ against the simple alternative $H_1:\\theta = 1/2$.\n\\end{example}\n\n\\begin{solution}\nThe PMF of a $\\text{Poisson}(\\theta)$ random variable is\n\\[\nf(x) = \\begin{cases}\n\\displaystyle\\frac{\\theta^{x} e^{-\\theta}}{x!}\t\t& x=0,1,2,\\ldots \\\\\n0\t\t\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\n\nThe likelihood function is\n\\[\nL(\\theta;\\mathbf{x}) = \\frac{\\theta^{\\sum_i x_i } e^{-n\\theta}}{\\prod_{i=1}^n x_i!}.\n\\]\n\nFor the null value $\\theta_0=2$ and the alternative value $\\theta_1=1/2$, \n\\[\nL(\\theta_0;\\mathbf{x}) = \\frac{2^{\\sum_i x_i} e^{-2n}}{\\prod_{i=1}^n x_i!} \n\\text{\\quad and\\quad}\nL(\\theta_1;\\mathbf{x}) = \\frac{(1/2)^{\\sum_i x_i} e^{-n/2}}{\\prod_{i=1}^n x_i!} \n\\]\nso the likelihood ratio is\n\\[\n\\lambda(\\mathbf{x})\n\t= \\frac{L(\\theta_0|\\mathbf{x})}{L(\\theta_1|\\mathbf{x})} \n\t= \\frac{2^{\\sum_i x_i} e^{-2n}}{(1/2)^{\\sum_i x_i} e^{-n/2}}\n\t= 4^{\\sum_i x_i} e^{-3n/2}.\n\\]\nBy the Neyman-Pearson lemma, a most powerful test is given by the critical region\n\\[\nC = \\{\\mathbf{x}:\\lambda(\\mathbf{x})\\leq k\\} = \\{\\mathbf{x}:4^{\\sum_i x_i} e^{-3n/2}\\leq k\\}\n\\]\nwhere $k$ is chosen according to the required size of the test.\n%\nTo clarify the decision rule, note that\n\\begin{align*}\nC \n\t& = \\left\\{\\mathbf{x}: \\sum_{i=1}^n x_i\\log 4 - \\frac{3n}{2} \\leq \\log k\\right\\} \n\t= \\left\\{\\mathbf{x}: \\sum_{i=1}^n x_i \\leq \\frac{3n/2 + \\log k}{\\log 4}\\right\\} \n\t= \\left\\{\\mathbf{x}: \\sum_{i=1}^n x_i \\leq k'\\right\\}\n\\end{align*}\nwhere $k'$ is chosen according to the required size of the test.\n\\end{solution}\n\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_{10}$ be a random sample from the $\\text{Bernoulli}(\\theta)$ distribution, where $\\theta$ is unknown. The null hypothesis $H_0:\\theta=1/2$ is rejected in favour of the alternative $H_1:\\theta < 1/2$ whenever the sum of the observations satisfies $\\sum_{i=1}^{10}X_i \\leq 2$. \n\\ben\n\\it Find the size of the test.\n\\it Find the power of the test at $\\theta=1/4$ and the power of the test at $\\theta=1/5$.\n\\it Show that this is a most powerful test of $H_0:\\theta=1/2$ against the simple alternative $H_1:\\theta=1/4$.\n\\een\n\\begin{solution}\n\\ben\n\\it % <<<<\nLet $S = \\sum_{i=1}^{10}X_i \\leq 2$. From tables,\n\\[\n\\alpha = \\prob\\big[S\\leq 2 \\text{ when } S\\sim\\text{Binomial}(10,1/2)\\big] = 0.0547.% \\text{\\quad (from tables).}\n\\]\n\\it % <<<<\nFrom tables,\n\\begin{align*}\n\\gamma(1/4) & = \\prob\\big[S\\leq 2 \\text{ when } S\\sim\\text{Binomial}(10,1/4)\\big] = 0.5256. \\\\\n\\gamma(1/5) & = \\prob\\big[S\\leq 2 \\text{ when } S\\sim\\text{Binomial}(10,1/5)\\big] = 0.6778.\n\\end{align*}\n\\it % <<<<\nLikelihood function:\n\\[\nL(\\theta;\\mathbf{x}) = \\prod_{i=1}^{10}f(x_i;\\theta) = \\prod_{i=1}^{10}\\theta^{x_i}(1-\\theta)^{1-x_i}\n\\]\nLikelihood ratio:\n\\[\n\\lambda(\\mathbf{x}) \n\t= \\frac{L(1/2;\\mathbf{x})}{L(1/4;\\mathbf{x})}\n\t= \\frac{\\prod_{i=1}^{10}(1/2)^{x_i}(1/2)^{1-x_i}}{\\prod_{i=1}^{10}(1/4)^{x_i}(3/4)^{1-x_i}}\n%\t= \\frac{(1/2)^{10}}{(1/3)^{\\sum_i x_i}(3/4)^{10}}\n\t= 3^{\\sum_i x_i}(2/3)^{10}.\n\\]\nSimple likelihood ratio test: \n\\begin{align*}\nC \n\t& = \\{\\mathbf{x}:\\lambda(\\mathbf{x})\\leq k\\} \\\\\n%\t& = \\{\\mathbf{x}:3^{\\sum_i x_i}(2/3)^{10}\\leq k\\} \\\\\n\t& = \\big\\{\\mathbf{x}:\\sum_i x_i \\leq (\\log k + 10\\log(3/2))/\\log 3 \\big\\} \\\\\n\t& = \\{\\mathbf{x}:\\sum_i x_i \\leq k' \\}\n\\end{align*}\t\nwhere $k'$ is chosen appropriately. By the Neyman-Pearson lemma, this is a most powerful test of $H_0:\\theta=1/2$ against $H_1:\\theta=1/4$.\n\\een\n\\end{solution}\n\\end{example}\n\n\n%==========================================================================\n\\begin{exercise}\n\\begin{questions}\n\\question  % 8.1.5\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from a distribution whose PDF is $f(x;\\theta) = \\theta x^{\\theta-1}$ for $0 < x < 1$, and zero otherwise.\n%\\[\n%f(x;\\theta) = \\begin{cases}\n%\\theta x^{\\theta-1}\t& 0 < x < 1, \\\\\n%0\t\t\t\t\t& \\text{otherwise.}\n%\\end{cases}\n%\\]\nShow that a most powerful test of $H_0:\\theta=1$ against $H_1:\\theta=2$ is given by the critical region\n\\[\nC = \\left\\{\\mathbf{x}: \\displaystyle\\prod_{i=1}^n x_i \\geq c\\right\\}.\n\\]\n%\\[\n%C = \\left\\{\\mathbf{x}: T(\\mathbf{x})\\geq c\\right\\}\\quad\\text{where } T(\\mathbf{x})=\\displaystyle\\prod_{i=1}^n x_i.\n%\\]\n%defines a most powerful test of $H_0:\\theta=1$ against $H_1:\\theta=2$.\n\\begin{answer}\nThe likelihood function is \n\\[\nL(\\theta|\\mathbf{x}) \n\t= \\prod_{i=1}^{n} f(x_i;\\theta)\n\t= \\prod_{i=1}^{n} \\theta x^{\\theta-1}\n\t= \\theta^n\\prod_{i=1}^{n} x_i^{\\theta-1}.\n\\]\nIn particular, $L(1|\\mathbf{x})=1$ and $L(2|\\mathbf{x})=2^n\\prod_{i=1}^{n} x_i$, so the likelihood ratio for testing $H_0$ against $H_1$ is given by\n\\[\n\\lambda(\\mathbf{x})\n\t= \\frac{L(1|\\mathbf{x})}{L(2|\\mathbf{x})}\n\t= \\frac{1}{2^n\\prod_{i=1}^{n} x_i}.\n\\]\nBy the Neymann-Pearson lemma, a most powerful test is given by\n\\[\nC \t= \\{\\mathbf{x}:\\lambda(\\mathbf{x})\\leq k\\}\n\t= \\left\\{\\mathbf{x}:\\frac{1}{2^n\\prod_{i=1}^{n} x_i} \\leq k\\right\\}\n\t= \\left\\{\\mathbf{x}:\\prod_{i=1}^{n} x_i \\geq \\frac{1}{k2^n}\\right\\}.\n\\]\nHence a most powerful test is given by a set of the form $C = \\big\\{\\mathbf{x}: \\prod_{i=1}^n x_i \\geq c\\big\\}$, where $c$ is chosen to fix the size of the test.\n\\end{answer}\n\n\n\n%==========================================================================\n\\question  % 8.1.7\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the $N(\\theta,100)$ distribution, and let\n\\[\nC = \\left\\{\\mathbf{x}:\\frac{1}{n}\\sum_{i=1}^n x_i \\geq k\\right\\}\n\\] \nwhere $k$ is a constant.\n\\ben\n\\it % (i)\nShow that $C$ defines a most powerful test of $H_0:\\theta=75$ against $H_1:\\theta=78$. \n\\item % (ii)\nFind values for $n$ and $k$ such that $\\prob_{H_0}\\left(\\frac{1}{n}\\sum_{i=1}^n X_i\\geq k\\right)=0.05$ and $\\prob_{H_1}\\left(\\frac{1}{n}\\sum_{i=1}^n X_i\\geq k\\right)=0.90$, approximately.\n\\een\n\n\\begin{answer}\n\\ben\n\\it % << (i)\nThe density function is $f(x;\\theta,\\sigma^2) = \\displaystyle\\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left(-\\frac{1}{2\\sigma^2}(x-\\theta)^2\\right)$. \n\nThe likelihood ratio for $H_0:\\theta=\\theta_0$ against $H_1:\\theta=\\theta_1$ is therefore\n\\begin{align*}\n\\lambda(\\mathbf{x})\n\t& = \\frac{L(\\theta_0;\\mathbf{x})}{L(\\theta_1;\\mathbf{x})} \\\\\n\t& = \\frac{\\exp\\left(-\\frac{1}{2\\sigma^2}\\sum_i (x_i-\\theta_0)^2\\right)}{\\exp\\left(-\\frac{1}{2\\sigma^2}\\sum_i(x_i-\\theta_1)^2\\right)} \\\\\n\t& = \\exp\\left(-\\frac{1}{2\\sigma^2}\\sum_i\\big[(x_i-\\theta_0)^2 -(x_i-\\theta_1)^2\\big]\\right) \\\\\n\t& = \\exp\\left(-\\frac{1}{2\\sigma^2}\\big[-2(\\theta_0-\\theta_1)\\sum_i x_i + n(\\theta_0^2-\\theta_1^2)\\big]\\right) \\\\\n%\t& = \\exp\\left(-\\frac{1}{2\\sigma^2}\\big[-2n(\\theta_0-\\theta_1)\\bar{x} + n(\\theta_0^2-\\theta_1^2)\\big]\\right) \\\\\n\\end{align*}\t\n\nBy the Neyman-Pearson lemma, a most powerful test is given by \n\\begin{align*}\n\\{\\mathbf{x}:\\lambda(\\mathbf{x})\\leq k\\}\n\t& = \\left\\{\\mathbf{x}:\\exp\\left(-\\frac{1}{2\\sigma^2}\\big[-2(\\theta_0-\\theta_1)\\sum_i x_i + n(\\theta_0^2-\\theta_1^2)\\big]\\right)\\leq k\\right\\} \\\\\n\t& = \\left\\{\\mathbf{x}\\,:\\,\\frac{1}{n}\\sum_i x_i \\geq \\frac{1}{2}(\\theta_0+\\theta_1) - \\frac{\\sigma^2\\log k}{n(\\theta_0-\\theta_1)}\\right\\}\n\\end{align*}\nwhere we have used the fact that $\\theta_0 < \\theta_1$.\n\n\\bigskip\nThus if $\\theta_0<\\theta_1$, the set $\\displaystyle C=\\left\\{\\mathbf{x}\\,:\\,\\frac{1}{n}\\sum_i x_i\\geq k\\right\\}$ defines a most powerful test of $H_0:\\theta=\\theta_0$ against $H_1:\\theta=\\theta_1$.\n\n\\it % << (i)\nUnder $H_0:\\theta=75$, each $X_i\\sim N(75,100)$ so the sample mean is $\\bar{X}\\sim N(75,100/n)$. For a test of size $\\alpha=0.05$, the critical value $c$ must be the $95$th percentile of the $N(75,100/n)$ distribution, so $c = 75 + 1.645(10/\\sqrt{n})$ where $1.645$ is the $95$th percentile of the standard normal distribution $N(0,1)$.\n\nUnder $H_1:\\theta=78$, each $X_i\\sim N(78,100)$ so the sample mean is $\\bar{X}\\sim N(78,100/n)$. For a test of $\\gamma = 0.9$, the critical value $c$ must be the $10$th percentile of the $N(78,100/n)$ distribution, so $c = 78 - 1.280(10/\\sqrt{n})$ where $-1.280$ is the $10$th percentile of the standard normal distribution $N(0,1)$.\n\nEquating these expressions for $c$, we obtain $\\sqrt{n} = 10(1.645+1.280)/(78-75) = 9.75$ and therefore $n=95.0625$, which means that we need a sample size $n=96$ to ensure that the significance level does not exceed 0.05. Substituting for $\\sqrt{n}$ in one of the above expression then yields the critical value $c = 76.6872$, which defines the critical region \n\\[\n\\displaystyle C=\\left\\{\\mathbf{x}\\,:\\,\\frac{1}{n}\\sum_i x_i\\geq 76.6872\\right\\}.\n\\]\nAs shown above, this defines a most powerful test of $H_0:\\theta=75$ against $H_1:\\theta=78$.\n\\een\n\\end{answer}\n\n%==========================================================================\n\\question  % 8.1.4\nLet $X_1,X_2,\\ldots,X_{10}$ be a random sample from the $N(0,\\sigma^2)$ distribution where $\\sigma^2$ is unknown. \n\\ben\n\\it Find a most powerful test of size $\\alpha=0.05$ for testing $H_0:\\sigma^2=1$ against $H_1:\\sigma^2=2$. \n\\it Is this also a most powerful test of $H_0:\\sigma^2=1$ against $H_1:\\sigma^2=4$?\n\\it Is this a most powerful test of $H_0:\\sigma^2=1$ against the composite alternative $H_1:\\sigma^2>1$?\n\\een\n\n\\begin{answer}\n\\ben\n\\it % << (i)\nThe density function is $f(x,\\sigma^2) = \\displaystyle\\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-x^2/2\\sigma^2}$, the likelihood function is \n\\[\nL(\\sigma^2;\\mathbf{x}) \n\t= \\prod_{i=1}^{10} f(x_i,\\sigma^2)\n\t= \\left(\\frac{1}{2\\pi\\sigma^2}\\right)^{5}\\exp\\left(-\\frac{1}{2\\sigma^2}\\sum_i x_i^2\\right)\n\\]\nand the likelihood ratio for $H_0:\\sigma^2=1$ against $H_1:\\sigma^2=2$ is therefore\n\\[\n\\lambda(\\mathbf{x})\n\t= \\frac{L(1;\\mathbf{x})}{L(2;\\mathbf{x})}\n\t= 2^{5} \\exp\\left(-\\frac{1}{4}\\sum_i x_i^2\\right).\n\\]\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_{10})$ denote the random sample. By the Neymann-Pearson lemma, a best critical region for the test is\n\\begin{align*}\nC \t= \\{\\mathbf{x}:\\lambda(\\mathbf{x})\\leq k\\} \n\t& = \\left\\{\\mathbf{x}:2^{5} \\exp\\left(-\\frac{1}{4}\\sum_{i=1}^{10} x_i^2\\right) \\leq k\\right\\} \\\\\n\t& = \\left\\{\\mathbf{x}:\\sum_{i=1}^{10} x_i^2 \\geq 4\\log\\left(\\frac{k}{2^{5}}\\right)\\right\\} \\\\\n\t& = \\left\\{\\mathbf{x}:\\sum_{i=1}^{10} x_i^2 \\geq k'\\right\\} \\\\\n\\end{align*}\nwhere $k'$ is chosen to ensure that $\\prob(\\mathbf{X}\\in C;H_0)=0.05$. \n\\it % << (ii)\nUnder the null hypothesis we have $X_i\\sim N(0,1)$, so the sum-of-squares $\\sum_{i=1}^{10} X_i^2$ has chi-squared distribution with $10$ degrees-of-freedom. From tables, the critical value at $\\alpha=0.05$ for this distribution is $18.307$, so the critical region is given by \n\\[\nC = \\left\\{\\mathbf{x}\\,:\\,\\sum_{i=1}^{10} x_i^2 \\geq 18.307\\right\\} \n\\]\nThis is also a most powerful test of $H_0:\\sigma^2=1$ against $H_1:\\sigma^2=4$. \n\\it\nThe argument of part (b) holds for any simple alternative hypthesis $H_1:\\sigma^2=\\sigma^2_1$ provided $\\sigma^2_1 > 1$. This is therefore a \\emph{uniformly most powerful test} of size $\\alpha$ for testing $H_0:\\sigma^2=1$ against every simple alternative in the composite hypothesis $H_1:\\sigma^2>1$.\n\\een\n\\end{answer}\n\n\n\\end{questions}\n\\end{exercise}\n", "meta": {"hexsha": "1c0c432f2fc4568e412e83e0c90fe70973bf7208", "size": 14194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/09D_most_powerful_tests.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/09D_most_powerful_tests.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/09D_most_powerful_tests.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 48.1152542373, "max_line_length": 362, "alphanum_fraction": 0.6317458081, "num_tokens": 5638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.6935825613313978}}
{"text": "\\section{Value Function Approximation}\n\nIn function approximation, the value function $v_\\pi$ becomes:\n\\begin{equation}\n\tv_\\pi (s) \\approx \\widehat{v}(s, \\mathbf{W}) \\text{  ,  } \\mathbf{W} \\in \\mathbb{R}^d\n\\end{equation}\n\nIt is a supervised learning with data pair:\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\langle S_1, R_1 &+ \\gamma \\widehat{v}(S_2, \\mathbf{W}) \\rangle \\\\\n\t\t\\langle S_2, R_2 &+ \\gamma \\widehat{v}(S_3, \\mathbf{W}) \\rangle \\\\\n\t\t&\\dots\n\t\\end{aligned}\n\\end{equation}\n\n\\subsection{On-policy Prediction}\n\n\\subsubsection{Requirement}\n\nThe approximate function $\\widehat{v}(s, \\mathbf{W})$ has these requirements:\n\\begin{itemize}\n\t\\item learning needs to be online\n\t\\item the learning target is non-stationary and can change over time\n\t\\item differentiable of $\\mathbf{W}$ for all $s \\in \\mathcal{S}$\n\\end{itemize}\n\n\\subsubsection{Prediction Objective}\n\nIn tabular case there is no estimation of value function quality because it will converge to the end goal. However in function approximation there is no exact value function and the quality need to be estimated. \n\nAssume the state is distributed under $\\mu(s)>0, \\sum\\limits_s \\mu(s) = 1$, the \\cindex{mean squared value error} $\\overline{\\text{VE}}$ is defined as:\n\\begin{equation}\n\t\\overline{\\text{VE}} = \\sum_{s \\in \\mathcal{S}} \\mu (s) \\Big ( v_\\pi (s) - \\widehat{v}(s,\\mathbf{W}) \\Big )^2\n\\end{equation}\n\n$\\mu(s)$ can be chosen as the fraction of time for episodes, and stationary distribution for continuous tasks.\n\n$\\widehat{v}$ is chosen to be differentiable function, which could be:\n\\begin{itemize}\n\t\\item linear combination of features\n\t\\item neural network\n\\end{itemize}\n\n\\subsubsection{Stochastic Gradient Descent}\n\nAssume $\\mu$ is uniform distribution, the $\\mathbf{W}$ is updated as:\n\\begin{equation}\\label{wstogradesc}\n\t\\begin{aligned}\n\t\t\\mathbf{W}_{t+1} &= \\mathbf{W}_t - \\frac{1}{2} \\alpha \\nabla_{\\mathbf{W}} \\Big ( v_\\pi(S_t) - \\widehat{v}(S_t, \\mathbf{W}_t) \\Big )^2 \\\\\n\t\t&= \\mathbf{W}_t+ \\alpha \\Big ( v_\\pi(S_t) - \\widehat{v}(S_t, \\mathbf{W}_t) \\Big ) \\nabla_{\\mathbf{W}}  \\widehat{v}(S_t, \\mathbf{W}_t) \n\t\\end{aligned}\n\\end{equation}\n\nwhere $\\nabla_{\\mathbf{W}} f(\\mathbf{W})$ is defined as:\n\\begin{equation}\n\t\\nabla_{\\mathbf{W}} f(\\mathbf{W}) = \\left( \\frac{\\partial f(\\mathbf{W})}{\\partial \\mathbf{W}_1}, \\frac{\\partial f(\\mathbf{W})}{\\partial \\mathbf{W}_2}, \\dots, \\frac{\\partial f(\\mathbf{W})}{\\partial \\mathbf{W}_d}  \\right)^{\\top}\n\\end{equation}\n\n Formula (\\ref{wstogradesc}) need to follow these in order to converge to a local minimum:\n\\begin{itemize}\n\t\\item $\\alpha$ follow equation (\\ref{convergenceofsequence}).\n\t\\item $v_\\pi(S_t) $ is an unbiased estimate of $v$.\n\\end{itemize}\n\n\n\n\nSee Algorithm (\\ref{algo:gradmcapprox}) for detail.\n\nIn practice, the $v_\\pi$ in formula (\\ref{wstogradesc}) is chosen as:\n\\begin{itemize}\n\t\\item for MC, the target is the return $G_t$:\n\t\\item for TD(0), the target is $R_{t+1} + \\gamma \\widehat{v}(S_{t+1}, \\mathbf{W} )$\n\t\\item for TD($\\lambda$), the target is $G_t^\\lambda$ which could be forward or backward view\n\\end{itemize}\n\n\n\\begin{algorithm}\n\t\\caption{gradient MC, estimate $\\widehat{v} \\approx v_\\pi$ }\\label{algo:gradmcapprox}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\mathbf{W} \\gets $ random\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State generate $S_0,A_0,R_1,\\dots,R_T,S_T$ using $\\pi$\n\t\t\t\\For{$t \\gets \\Big[0, 1, \\dots, T-1 \\Big]$}\n\t\t\t\t\\State $\\mathbf{W} \\gets \\mathbf{W} + \\alpha \\Big( G_t - \\widehat{v}(S_t, \\mathbf{W}) \\Big) \\nabla_{\\mathbf{W}} \\widehat{v}(S_t, \\mathbf{W})$\n\t\t\t\\EndFor\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n \n \\subsection{Semi-gradient methods}\n \n In formula (\\ref{wstogradesc}) if $v_\\pi(S_t)$ depends on $\\mathbf{W}$, the formula is biased and will not converge as the true gradient descent methods. It is called \\cindex{semi-gradient methods}.\n \n Bootstrapping estimate belongs to this category.\n \n \n\\subsection{Linear Methods}\n\nSuppose $\\widehat{v}$ is linear: $\\widehat{v}(s,\\mathbf{W})= \\mathbf{W}^\\top \\mathbf{X}(s) = \\sum\\limits_{i=1}^d w_i x_i(s)$. $\\mathbf{X}(s)$ is called feature vector represents state $s$.  Formula (\\ref{wstogradesc}) now becomes:\n\n\\begin{equation}\\label{lineargraddesc}\n\t\\mathbf{W}_{t+1} = \\mathbf{W}_t+ \\alpha \\Big ( v_\\pi(S_t) - \\widehat{v}(S_t, \\mathbf{W}_t) \\Big ) \\mathbf{X}(S_t)\n\\end{equation}\n\nIn linear case all local optimum is global optimum. \n\n\\subsubsection{Semi-gradient Linear Methods TD(0)}\n\nsemi-gradient TD(0) algorithms also converges under linear function. But it converges to a point near the local optimum, rather than global minimum.\n\n\\begin{equation}\\label{wstosemigradesc}\n\t\\begin{aligned}\n\t\t\\mathbf{W}_{t+1} &= \\mathbf{W}_t+ \\alpha \\Big ( R_{t+1} + \\gamma \\mathbf{W}_t^\\top \\mathbf{X}_{t+1} - \\mathbf{W}_t^\\top \\mathbf{X}_t \\Big ) \\mathbf{X} \\\\\n\t\t&= \\mathbf{W}_t+ \\alpha \\Big ( R_{t+1}\\mathbf{X}_t + \\mathbf{X}_t ( \\mathbf{X}_t - \\gamma \\mathbf{X}_{t+1})^\\top \\mathbf{W}_t  \\Big ) \n\t\\end{aligned}\n\\end{equation}\n\nThe expected next weight vector could be written as:\n\n\\begin{equation}\\label{convergesequence}\n\t\\mathbb{E}[\\mathbf{W}_{t+1} | \\mathbf{W}_t] = \\mathbf{W}_t + \\alpha (\\textbf{b} - \\mathbf{A} \\mathbf{W}_t)\n\\end{equation}\n\nwhere \n\n\\begin{equation}\n\t\\textbf{b} = \\mathbb{E}[R_{t+1} \\mathbf{X}_t] \\in \\mathcal{R}^d\n\\end{equation}\n\nand \n\n\\begin{equation}\n\t\\mathbf{A} =  \\mathbb{E}[\\mathbf{X}_t ( \\mathbf{X}_t - \\gamma \\mathbf{X}_{t+1})^\\top]\n\\end{equation}\n\n\nIf formula (\\ref{convergesequence}) converges and is unbiased, it will converge to $\\mathbf{W}_{TD}$ at which:\n\n\\begin{equation}\\label{solvesemilr}\n\t\\begin{aligned}\n\t\t\\textbf{b} - \\mathbf{A} \\mathbf{W}_{TD} &= 0\\\\\n\t\t\\textbf{b} &= \\mathbf{A} \\mathbf{W}_{TD} \\\\\n\t\t\\mathbf{W}_{TD} &= \\mathbf{A}^{-1} \\textbf{b}\n\t\\end{aligned}\n\\end{equation}\n\n\nThe solution of formula (\\ref{solvesemilr}) is around global minimum:\n\n\\begin{equation}\\label{semigradientlrerror}\n\t\\overline{\\text{VE}}(\\mathbf{W}_{TD}) \\leq \\frac{1}{1-\\gamma} \\underset{\\mathbf{W}}{\\min}\\ \\overline{\\text{VE}}(\\mathbf{W})\n\\end{equation}\n\nformula (\\ref{semigradientlrerror}) applies to other on-policy bootstrapping methods as well, such as semi-gradient DP, semi-gradient action value methods.\n\n\\subsubsection{Least-Squares TD}\n\nIn LSTD, the $A$ and $b$ in formula (\\ref{solvesemilr}) is defined as:\n\\begin{equation}\n\t\\widehat{A}_t = \\sum_{k=0}^{t-1} \\mathbf{X}_k (\\mathbf{X}_k - \\gamma \\mathbf{X}_{k+1} )^\\top + \\varepsilon \\mathbf{I}\n\\end{equation}\nand\n\\begin{equation}\n\t\\widehat{b}_t=\\sum_{k=0}^{t-1}R_{t+1}\\mathbf{X}_k\n\\end{equation}\n\nA small $\\varepsilon > 0$ is added to ensure $\\widehat{A}_t$ is always invertible. \n\n$w_t$ is now defined as $w_t=\\widehat{A}_t^{-1} \\widehat{b}_t$.\n\nThere is a \\cindex{Sherman-Morrison formula} that simplify the calculation of $\\widehat{A}$:\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\widehat{A}_t^{-1} &= \\Big (\\widehat{A}_{t-1} + \\mathbf{X}_t (\\mathbf{X}_t - \\gamma \\mathbf{X}_{t+1})^\\top \\Big)^{-1}\\\\\n\t\t&= \\widehat{A}_{t-1}^{-1} - \\frac{\\widehat{A}_{t-1}^{-1} \\mathbf{X}_t (\\mathbf{X}_t - \\gamma \\mathbf{X}_{t+1})^\\top \\widehat{A}_{t-1}^{-1} }{1 + (\\mathbf{X}_t - \\gamma \\mathbf{X}_{t+1})^\\top \\widehat{A}_{t-1}^{-1} \\mathbf{X}_t }\n\t\\end{aligned}\n\\end{equation}\n\nwith $\\widehat{A}_0 = \\varepsilon \\mathbf{I}$\n\nLSTD does not require $\\alpha$, but it needs $\\varepsilon$ which has these problems: \n\\begin{itemize}\n\t\\item small $\\varepsilon$: the inverse calculation will vary widly\n\t\\item big $\\varepsilon$: the learning is slow\n\t\\item no $\\alpha$: it never forgets\n\\end{itemize}\n\n\\subsection{On-policy Control}\n\nIn approximate control, the $v$ in formula (\\ref{wstogradesc}) is changed to $q$:\n\\begin{equation}\n\t\\mathbf{W}_{t+1} = \\mathbf{W}_t+ \\alpha \\Big ( U_t - \\widehat{q}(S_t, A_t, \\mathbf{W}_t) \\Big ) \\nabla_{\\mathbf{W}}  \\widehat{q}(S_t, A_t, \\mathbf{W}_t) \n\\end{equation}\n\nAs before, the $U_t$ could be : \n\\begin{itemize}\n\t\\item for MC, the target is the return $G_t$:\n\t\\item for TD(0), the target is $R_{t+1} + \\gamma \\widehat{q}(S_{t+1}, A_{t+1}, \\mathbf{W} )$\n\t\\item for TD($\\lambda$), the target is $G_t^\\lambda$ with forward and backward view\n\\end{itemize}\n", "meta": {"hexsha": "d553211a5fca54463d6fd8ed2a509299e5e9c7d3", "size": 8042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/reinforcement_learning/rl.7.onpolicy_pred_fun_approx.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.7.onpolicy_pred_fun_approx.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.7.onpolicy_pred_fun_approx.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": 38.8502415459, "max_line_length": 230, "alphanum_fraction": 0.679557324, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6935825555009881}}
{"text": "% !TEX root = main.tex\n\n%------------------------------------------------\n\\chapter{First Order Differentials}\n\nA first order (ordinary differential equations) is an equation of the form : $$\\frac{dy}{dt} = f(t,y).$$\n\nHere any solution $y$ is a real or complex valued function of a single real variable and $f$ is a function of 2 variables.\n\nIn Newtonian notation the same equation would be written as : $$y'(t) = f(t,y(t)).$$\n\\section{Separable Equations}\n\nA separable equation is an equation of the form : $$\\frac{dy}{dt} = g(t)h(y).$$\nSuppose that $h$ never takes the value 0. Then we can write the equation as : $$\\frac{1}{h(y)}\\frac{dy}{dt}  = g(t).$$\nWe can also (at least on principle) find a function $F$ whose derivative is $\\frac{1}{h}$ : $$F' = \\frac{1}{h},$$\nhence : $F'(y(t))\\frac{dy}{dt} = g(t) \\implies \\frac{d}{dt}[F(y(t))] = g(t).$\n\n\\bigskip\n\n\\begin{example}  Solve $$\\frac{dy}{dt} = (1+y^2)(1+\\alpha{y})$$ where $\\alpha \\geq 0$ is constant. \\newline\n\\begin{solution} Write the equation as $$\\frac{1}{1+y^2}\\frac{dy}{dt} = 1 + \\alpha{t}.$$\nHere we need $F'(y) = \\frac{1}{1+y^2}$ so we choose : $$F(y) = tan^{-1}(y)$$ and get : $$\\frac{d}{dt}(tan^{-1}(y(t))) = 1 + \\alpha{t},$$\nand so by integration $$tan^{-1}(y(t)) = t +\\alpha{\\frac{t^2}{2}} + \\beta$$ where $\\beta$ is constant.\nHence : $y(t) = tan( t +\\alpha\\frac{t^2}{2} + \\beta).$\nRemark : The solution of this equation always blows up in finite time even when $\\alpha = \\beta = 0 $. In this case the solution blows up at $t = \\frac{\\pi}{2}$.\n\\end{solution}\n\\end{example}\n\\bigskip\n\n\\begin{example}  Find the solution of $$\\frac{dy}{dt} = 2\\sqrt[]{y}.$$\n\\begin{solution} Divide by $2\\sqrt[]{y}$ to get $$ \\frac{1}{2\\sqrt[]{y}}\\frac{dy}{dt} = 1.$$\nFor this case : $$F'(y) = \\frac{1}{2\\sqrt[]{y}}$$ and so we choose $F(y) + \\sqrt[]{y}$ and get $$\\frac{d}{dt}(\\sqrt[]{y(t)} = 1.$$\nSo, on integration $$\\sqrt[]{y(t)} = t + c $$ where $c$ is a constant.\nThis gives $y(t) = (t + c)^2.$\nSuppose we want $y(0) = 0$ we get : $$0 = y(0) = (0 + c)^2 = c^2.$$\nGiving $c = 0$. Thus $y(t) = t^2.$\n\nWarning : This is not the only solution of $\\frac{dy}{dt} = 2\\sqrt[]{y}$ which satisfies $y(0) = 0$, as we said previously. We could also have $y(t) = 0$ for all $t$.\n\\end{solution}\n\\end{example}\n\n\\bigskip \n\n\\begin{example}  Solve the equation : $$\\frac{dy}{dt} = m(1 - m).$$\n\\begin{solution} Suppose $ m \\neq 0$, $ m \\neq 1$ Then $$\\frac{1}{m(1-m)}\\frac{dm}{dt} = 1.$$\nWe need to find a function $F$ such that :\n$$F'(m) = \\frac{1}{m(1-m)} = \\frac{1}{m} + \\frac{1}{1-m}.$$\nA suitable $F$ is: $$F(m) = \\log(m) - \\log(1-m) = \\log(\\frac{m}{1-m})$$ and so our equation is : $$\\frac{d}{dt}[\\log(\\frac{m}{1-m})] = 1 \\implies \\log(\\frac{m}{1-m}) = t + c$$ where $c$ is a constant, thus $$\\frac{m(t)}{1-m(t)} = \\exp(t + c) = \\alpha \\exp(t)$$ where $\\alpha = \\exp(c)$ is also a constant. Suppose that $m(0) = \\mu$ then : $$\\frac{\\mu}{1-\\mu} = \\alpha.$$\nThe equation for $m(t)$ can be rearranged as $$\\mu(t) = \\frac{\\alpha \\exp(t)}{1 + \\alpha \\exp(t)} = \\frac{1}{\\frac{1}{\\alpha} \\exp(-t) + 1} = \\frac{1}{(\\frac{1 - \\mu}{\\mu}) \\exp(-t) + 1} = \\frac{\\mu}{(1-\\mu) \\exp(-t) = \\mu}.$$\n\\end{solution}\n\\end{example}\n\n\\bigskip \n\n\\begin{remark}\n\\begin{itemize}\n\\item If we take $m(0) = \\mu = 0$ we get $m(t) = 0$ for all $t$ then : \\newline\nIf $0 < \\mu , 1$ then $(1 - \\mu)\\exp(-t) > 0$ and hence $$ 0 , m(t) < \\frac{\\mu}{0 + \\mu} = 1$$ Thus $$\\frac{dm}{dt} = m(1-m) > 0 \\mbox{ also } \\lim m(t) = 1.$$\n\n\\item If we take $m(0) = \\mu = 1$ we get $m(t) = 1$ for all $t$ then :\n\\newline\nIf $\\mu > 1$ then the expression $$m(t) = \\frac{\\mu}{\\mu(1-\\exp(-t))+ \\exp(-t)}$$ tells us that $m(t) > 0$ whilst the expression $$m(t) = \\frac{\\mu}{(1-m)\\exp(-t) + \\mu}$$ tells us that $m(t) > 1$ for all $t \\geq 0$. Also $\\frac{dm}{dt} = m(1-m) < 0$, so $m$ is strictly decreasing. Also $\\lim m(t) = 1$.\n\n\\end{itemize}\n\\end{remark}\n\\section{Homogeneous Equations }\n\nA homogeneous equation is an equation of the form : $$\\frac{dy}{dt} = f(\\frac{y}{t}).$$\nWe introduce a new function $z = \\frac{y}{t}$; more precisely $z(t) = \\frac{y(t)}{t}$. Hence $y(t) = tz(t)$ which gives $$f(z) = \\frac{dy}{dt} = z(t) + t\\frac{dz}{dt}.$$\nRearranging yields: $$\\frac{dz}{dt} = \\frac{f(z) - z}{t} = \\frac{1}{z}(f(z) - z)$$ which is now separable.\n\n\\bigskip\n\n\\begin{example} Solve the equation : $$t^2\\frac{dy}{dt} = ty + t^2 + y^2$$ and examine the behavior of the solution as $t$ tends to 0. \n\n\\begin{solution} Divide by $t^2$ to get $$\\frac{dy}{dt} = \\frac{y}{t} + 1 +(\\frac{y}{t})^2 = f(\\frac{y}{t})$$ where $f(z) = z + 1 + z^2$. We let $y = tz$ and get $$\\frac{dz}{dt} = \\frac{1}{t}(f(z)-z) = \\frac{1}{t}(1+z^2)\\implies \\frac{1}{1+z^2}\\frac{dz}{dt} = \\frac{1}{z},$$\nso $$\\frac{1}{1 +z^2}dz = \\frac{1}{t}dt.$$\nIntegrate both sides to obtain $tan^{-1} = \\log(t) + c$ where $c$ is a constant of integration. This yields $$z = tan(c + \\log(t)) \\implies y - t*tan(c+\\log(t)).$$\nPut $c = \\log\\alpha$ where $\\alpha = \\exp(c)$ so that $$y = t*tan(\\log\\alpha + \\log t) = t*tan(\\log(\\alpha t )).$$ This blows up whenever $\\log(\\alpha t) = (2k + 1)\\frac{\\pi}{2}$, $k\\in \\mathbb{Z}$ i.e $$\\alpha t = \\exp((2k + 1)\\frac{\\pi}{2}) \\mbox{,} \\mbox{ or } t = \\frac{1}{\\alpha}\\exp((2k + 1)\\frac{\\pi}{2}).$$\nLetting $k$ decrease to $-\\infty$ through the negative integers we see that these are infinitely many points at which $y$ blows up, in any neighborhood of zero. \n\\end{solution}\n\\end{example}\n\n\\bigskip\n\n\\begin{example}  Solve the homogeneous equation : $$\\frac{dy}{dt} = \\frac{y}{t}^{\\frac{1}{3}}.$$\n\\begin{solution} Put $y = tz, f(z) = z^{\\frac{1}{3}}$, and obtain $$\\frac{dz}{dt} = \\frac{1}{t}(f(z) - z) = \\frac{1}{t}(z^{\\frac{1}{3}} - z).$$ This yields $$\\frac{1}{z^\\frac{1}{3} - z}dz = \\frac{1}{t}dt.$$\nAlternatively, the original equation is already separable, as $y^{\\frac{-1}{3}}dy = t^\\frac{-1}{3}dt$. By integration : $$y^\\frac{2}{3} = t^\\frac{2}{3} + c$$ where $c$ is a constant of integration, thus $$ y = (c + t^\\frac{2}{3})^\\frac{3}{2}.$$\n\\end{solution}\n\\end{example}\n\n\\section{Linear Equations}\nA first-order differential linear equation is an equation of the form : $$\\frac{dy}{dt} = a(t)y+b(t)$$ where $a(t)$ and $b(t)$ are given functions of the dependant variable $t$. For linear equations we can always write the solution $y$ explicitly as a function.\n\n\\subsection*{Solution Procedure}\n\\begin{enumerate}\n\\item Choose a function $p(t)$ such that $$\\frac{dp}{dt} = a(t)$$\n\\item Observe that $$\\frac{d}{dt}(ye^{-p(t)}) = \\frac{dy}{dt}e^{-p(t)} + ye^{-p(t)} = (\\frac{dy}{dt} - a(t)y)e^{-p(t)} = b(t)e{-p(t)}$$\n\\item Integrate the equation $$\\frac{d}{dt}(ye^{-p(t)}) = b(t)e^{-p(t)}$$ This integrates to $$ye^{-p(t)} = \\int b(t)e{-p(s)}ds + c$$ where $c$ is a constant\nBy doing this we get : $$y = e^p(t)(c+ \\int b(s)e^{-p(s)}ds$$\n\\end{enumerate}\n\\begin{example} Solve the differential equation $$\\frac{dy}{dt} = ky +\\sin(t)$$ subject to the condition $y(0)=0$.\n\\begin{solution} Choose $p = \\int kdt = kt$ where $a(t) = k$ and $b(t) = \\sin(t)$.\nTherefore $$\\frac{d}{dt}(e^{-kt}y) = e^{-kt}\\sin(t).$$ There are at least two ways of integrating the right hand side of the equation. One is to integrate by parts and the other is to use complex exponentials, therefore : $$\\sin(t) = Im(e^{it}).$$ Hence : $$\\int e^{-kt}\\sin(t) dt \\implies \\int e^{-kt} Im(e^{-it}dt = Im(\\int e^{-kt + it}dt) \\implies Im(\\frac{e^{(i-k)t}}{(i-k)}$$ $$= Im(\\frac{(-i-k)(\\cos(t) + \\sin(t))*e^{-kt}}{1+k^2} = Im(\\frac{(-k\\cos(t) +\\sin(t) +i(-\\cos(t) - k\\sin(t)))e^{-kt}}{1+k^2})$$ $$= \\frac{-(\\cos(t) + k\\sin(t))e^{-kt}}{1+k^2}.$$\nTherefore :\n$$e^{-kt}y =   -(\\frac{-(\\cos(t) + k\\sin(t))e^{-kt}}{1+k^2})$$ where $c$ is a constant and when $t=0$ and $y=0$ so : $$c - \\frac{1}{1+k^2} = 0 \\implies c = \\frac{1}{1+k^2}$$\nThus the solution is $$y = \\frac{e^{kt} - (\\cos(t) + k\\sin(t))}{1+k^2}.$$\n\\end{solution}\n\\end{example}\n\\bigskip\n\n\\begin{example} Solve the linear differential equation $$t^2\\frac{dy}{dt} + 2ty = e^t$$ subject to $y(1) = 1.$ Is there a solution subject to the condition $y(0)=1$?\n\\begin{solution}\nWe can write the equation in the form $$\\frac{dy}{dt}= \\frac{-2}{t}y +\\frac{e^t}{t^2}.$$ Then we find the integrating factors as before however in this case we can simplify the equation by inspection : $$t^2\\frac{dy}{dt} + 2ty = \\frac{d}{dt}(t^2y) = e^t.$$\nThen by integration : $$t^2y = e^t + c \\implies y = \\frac{e^t + c}{t^2}$$ where $c$ is a constant.\nThe initial condition $y(1) = 1$ gives you $$ 1 = \\frac{e + c}{1} \\implies c = 1-e.$$ Thus $$y = \\frac{e^t + 1 - e}{t^2}.$$ There is no solution which takes the value 1 when $t=0$! This is because when we write the equation as $\\frac{dy}{dt}= f(t,y)$ we have $$\\frac{dy}{dt} = \\frac{-2y}{t} + \\frac{e^t}{t^2}$$ and this function is badly behaved as $t \\rightarrow 0$. The initial conditions can not be imposed at a point where the right hand side of the differential equation blows up.\n\\end{solution}\n\\end{example}\n\n\\bigskip\n\n\\begin{example}  Solve the equation $$(t\\log(t))\\frac{dy}{dt} + y = 3t^3.$$\n\\begin{solution}\nFirst we must find an integrating factor which is $$\\exp( \\int \\frac{1}{t\\log(t)} dt).$$ Then by integration by substitution where $u = \\log(t)$ and $\\frac{du}{dt} = \\frac{1}{t}$ we have that $$\\int \\frac{1}{t\\log(t)} dt \\implies \\int \\frac{1}{u}du = \\log(u) \\implies \\log(\\log(t)).$$\nNow the integrating factor is $\\exp(\\log(\\log(t))$ which is $\\log(t)$ and therefore : $$\\log(t)\\frac{dy}{dt} + \\frac{y}{t} = 3t^2 \\implies \\frac{d}{dt}[\\log(t)y] = 3t^2.$$ Then by integration you get $$\\log(t)y = \\int3t^2 dt = t^3 + c$$ where $c$ is a constant. Thus by rearranging $$y = \\frac{t^3 + c}{\\log(t)}.$$\n\\end{solution}\n\\end{example}\n\n\\bigskip\n\n\\section{Bernoulli Equations}\nA Bernoulli equation is an equation in the form $$\\frac{dy}{dt} + a(t)y = b(t)y^n.$$\nWhere when $n = 0$ we have a linear equation and when $n = 1$ we have  linear and separable equation. We choose an integration factor $p(t)$ such that $$\\frac{p'(t)}{p(t)} = a(t) \\mbox{ so that } \\frac{dy}{dt} + \\frac{p'(t)}{p(t)}y = b(t)y^n.$$\nNow we multiply both sides by $p(t)$ to get $$p(t)\\frac{dy}{dt} + \\frac{dp}{dt}y = p(t)b(t)y^n.$$ Then by differentiation $$\\frac{d}{dt}(p(t)y(t0 = \\frac{b(t)}{p(t)^{n-1}}(p(t)y(t))^n.$$ We introduce a new function $z$ by the formula $z(t) = p(t)y(t)$ which satisfies $$\\frac{dz}{dt} = q(t)z^n \\mbox{ where } q(t) = \\frac{b(t)}{p(t)^{n-1}}.$$\n\n\\begin{example}\nSolve the equation $$\\frac{dy}{dt} + \\frac{2}{t}y = \\exp(t)y^2.$$\n\\begin{solution}\nMultiply both sides by $t^2$ to obtain $$t^2\\frac{dy}{dt} + 2ty = t^2\\exp(t)y^2 \\implies \\frac{d}{dt}(t^2y) = \\frac{1}{t^2}\\exp(t)(t^2y)^2.$$ Let $z = t^2y$ such that $$\\frac{dz}{dt}=\\frac{1}{t^2}\\exp(t)z^2$$ which is now a separable equation. This separates as $$\\frac{1}{z^2}\\frac{dz}{dt} = \\frac{1}{t^2}\\exp(t) \\mbox{ or } \\frac{d}{dt}(\\frac{-1}{z}) = \\frac{1}{t^2}\\exp(t)$$ Any further progress depends on integrating the right hand side, probably with an incomplete gamma-function.\n\\end{solution}\n\\end{example}\n\\bigskip\n\n\\begin{example}\nSolve the equation $$\\frac{dy}{dt} = t\\exp(t^2-y).$$\n\\begin{solution}\nThanks to the property $\\exp(t^2-y) = \\frac{\\exp(t^2)}{\\exp(y)}$ this is a separable equation. We rearrange it as $$\\exp(y)\\frac{dy}{dt} = t\\exp(t^2) \\implies \\frac{d}{dt}\\exp(y)) = \\frac{d}{dt}(\\frac{1}{2} \\exp(t^2.)$$\nThus $$\\exp(y) = \\frac{1}{2} \\exp(t^2) + c$$ where $c$ is a constant. Finally $$y = \\log(c + \\frac{1}{2} \\exp(t^2)).$$ For the special case when $c = 0$ we get $$y = \\log(\\frac{1}{2} \\exp(t^2)) \\implies \\log(\\frac{1}{2}+t^2 = t^2 - \\log(2).$$\n\\end{solution}\n\\end{example}\n\n\n%------------------------------------------------\n\\endinput\n", "meta": {"hexsha": "e43ecd6ded67264120c9bee1fe7ba5a2ddf0a76a", "size": 11579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L4/MA1001/First_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/First_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/First_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": 74.7032258065, "max_line_length": 559, "alphanum_fraction": 0.5870109681, "num_tokens": 4524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.6934860490059921}}
{"text": "\\documentclass[letterpaper,options]{article}\n\\usepackage[]{amsmath,amssymb}\n\\usepackage[margin=1in]{geometry}\n%preamble\n\\title{Asteroid Data Hunter MM2: Description of Solution}\n\\author{Kushal Agarwal (TopCoder Handle: Kushal1)\\\\ Computer Science\\\\California Institute of Technology\\\\ \\texttt{kushal@caltech.edu}}\n\\date{\\today}\n\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Description of Algorithm}\n\\subsection{Source Extraction}\nThe first step in the algorithm is completed by the \\texttt{findSources()} function. For each pixel $i,j$ in the image, let $g_{i,j}$,  be a two dimensional Gaussian function centered on that pixel with standard deviation in each axis of 1.05 pixels. Then, linear regression can be used to find the values of $\\texttt{scaleFac}$ and $\\texttt{offset}$ for which the function $(g_{i,j}\\cdot\\texttt{scaleFac}+\\texttt{offset})$ best fits the values of the 5x5 grid of pixels centered on $i,j$.\n\nThis results in an $\\texttt{offset}$ value and a $\\texttt{scaleFac}$ value for each pixel. Noise in an image follows a Poisson Distribution, and the standard deviation of a Poisson process with mean $\\lambda$ is $\\sqrt{\\lambda}$. So the expected amount of noise for a specific pixel is proportional to $\\sqrt{\\texttt{offset}}$ (the proportionality constant depends on the gain of the image, but I have ignored this by assuming all image have the same gain). Therefore I can compute a signal to noise ratio as $\\texttt{SNR} =\\texttt{scaleFac}/\\sqrt{\\texttt{offset}}$ for each pixel.\n\nOn this new image where each pixel's value is based on its $\\texttt{SNR}$, I take two different thresholds and then apply a flood-fill to individually process each contiguous white region. (Contiguous means connected along the x or y directions; diagonally connected is not enough. Taking a threshold of an image means setting pixels above the threshold to white and those below it to black).\n\nThis is first done using a low threshold. Then any regions that are either very non square ($|length-width|>3$ pixels) or very large (area $ >16$ pixels), are kept white and the rest of the white pixels are made black. After this is complete, the pixels that are remaining white form a mask of points from which we will not make any detections.\n\nThen I repeat the process of thresholding and flood-filling, this time with a higher threshold. This time I keep sources which are close to square ($|length-width|\\le2$ pixels) and not too large (area $\\le16$ pixels). For each region that meets these criteria I create a detection centered at the pixel from the region that has the the largest $\\texttt{SNR}$ (as long as the mask at that pixel is black).\n\\subsection{Subpixel Source Centering}\nThe constructor for the \\texttt{Detection} class next fine tunes the the position of these sources to subpixel accuracy. For each of the detections found above, I use Gauss-Newton minimization to minimize the sum of square error between a Gaussian function  given by $(g_{y,x}\\cdot\\texttt{scaleFac}+\\texttt{offset})$ and the values of the 5x5 grid of pixels centered on the original detection. (Unlike the linear regression done to this same effect earlier, when using Gauss-Newton minimization I also allow $x$ and $y$ to vary and to do so continuously. Allowing $x$ and $y$ to vary break the linearity so non-linear tools must be used in place of linear regression). The result of Gauss-Newton minimization then yields four values describing the fit ($x$, $y$, $\\texttt{scaleFac}$, and $\\texttt{offset}$), two of which are the new more accurate center.\n\nFinally, this coordinate, $(x,y)$, (in pixel space) is transformed into an RA/Dec space, and then it is transformed into the pixel space of the fourth image. This way all detections from all four images are in the same coordinate space.\n\n\\subsection{Removal of Stars}\nFrom the set of aligned detections generated above, the function \\texttt{removeStars()} attempts to remove any detections that were created by stationary stars. This helps reduce the total number of detections, reducing the chance of false detections, especially in images with a high density of stars. A set of four detections are labeled as stars if a detection is found in each of the three latter images within 1 pixel of a detection in the first image.\n\nFinally, this process gives me a good opportunity to do a sanity check by checking to see that at least some of the sources were stars. If less than 15\\% of detections were labeled stars and removed, that is an indication something has gone terribly wrong (the image has really bad artifacts or the WCS data is inaccurate), and so I do not process it to avoid the risk of accidentally seeing thousands of false detections. However, once mid-contest changes were made, I never saw this check ever taking effect.\n\n\\subsection{Finding Asteroids}\nThis is done by the \\texttt{findAsteroids()} function. \tLet the images be taken at times $t_0,\\ldots,t_3$. For each detection in the first image (call this detection $d_0$), I look for all detections within  5 pixels of that one, and for each one of those (call it $d_1$) I do the following:\n\nThe current estimate for the velocity is now \n$$v=\\frac{\\text{position}(d_1 )-\\text{position}(d_0)}{t_1-t_0}$$\n\nSo I expect $d_2$ to be at $d_1+v(t_2-t_1)$. For each detection within 1 pixel of this expected center, I repeat the process. The new velocity is  \n$$v=\\frac{\\text{position}(d_2 )-\\text{position}(d_0 )}{t_2-t_0}$$\n\nAnd so the new expected location for $d_3$ will be $d_2+v(t_3-t_2)$. And again I do the following for each detection within 1 pixel of this expected center.\n\nFor each tuple of four detections $(d_0,d_1,d_2,d_3)$ found in this manner, I will next check how linear its path is. First, the velocity during each of the three legs can be computed as $$\\text{$v_i=\\frac{\\text{position}(d_{i+1} )-\\text{position}(d_i)}{t_{i+1}-t_i}$ for $i=1..3.$}$$\n\nLet $\\texttt{avgLen}=(|v_0 |+|v_1 |+|v_2 |)/3$. This tells us about how fast the object is moving. Then I compute the linearity of motion by first computing $\\texttt{error}=(|v_0-v_1 |+|v_0-v_2 |+|v_1-v_2 |)/\\texttt{avgLen}$. The numerator indicates how closely the three velocity vectors were pointing in the same direction, the denominator normalizes this for objects that are moving at different speeds. Finally, any tuple of detections with $\\texttt{error}<2.5$ and $\\texttt{avgLen}>70$ (meaning the path is fairly linear and the object is moving faster than 70 pixels per day), is called an asteroid.\n\n\\subsection{Output Results}\nThe function \\texttt{getAnswer()} returns all asteroids that were found. Each is output twice because most ground truths are also duplicated, and detections are sorted according to the $\\texttt{error}$ parameter (described in the previous section) so that the more linear the path, the more confident I am in the detection.\n\nFurther, asteroids whose velocity lies outside some very rough bounds (velocity in dec direction is between -0.6 and 0.25 degrees/day, and velocity in the RA direction is between -0.5 and 0.5 degrees/day) are skipped (this really is not recommended, as it leads to a very marginal score increase at the cost of potentially strongly biasing the sample of asteroids detected).\n\nFinally, sources with velocity in the RA direction less than -0.4 degrees/day are considered NEO. Obviously this categorization isn't great, but it's better than nothing.\n\n\\section{Overview of Implementation}\nThe implementation of such an algorithm is fairly straightforward because it is just a bunch of sequential steps, and most are fairly easy to code in a way that uses time and space efficiently. I have included an explanation of the job of each class I used in the next section (which would be helpful if you want to start reading through code). These are mostly helper classes because I feel the main part of the code has been documented above. Note that a good amount of code is obsolete, meaning it is included in my solution but is not being used because it was made to solve the alignment problems that were fixed mid-contest. So if you are puzzled by a particular function, first check to see that it is actually used.\n\nNext, Section 2.2 has some important assorted implementation details for less obvious parts of the code.\n\\subsection{Classes}\n\\paragraph{\\texttt{Vector} Class}\nRepresents a fixed size vector in $\\mathbb{R}^n$ (for doing math) or $\\mathbb{Z}^n$ (for indexing pixels in images) and allows you to add, subtract, multiply, and return these vectors. Be careful not to confuse my \\texttt{\\underline{V}ector} class (which is a vector in the mathematical sense) with the lowercase C++ STL \\texttt{\\underline{v}ector} class which I also use frequently, but which represents an expandable array.\n\\paragraph{\\texttt{Matrix} Class}\nRepresents a standard matrix.\n\\paragraph{\\texttt{Transformation} Class}\nThis was left over from older versions of the code and I never bothered to completely get rid of it, so it is unnecessary and rarely used. It represents a transformation (linear and translation) using homogeneous coordinates and is based on the \\texttt{Matrix} class. It can be applied to \\texttt{Vectors} using multiplication just like matrices.\n\\paragraph{\\texttt{Image} Class}\nStores an image as a \\texttt{vector<int>} and provides some 2D accessors into the 1D array. For debugging purposes it also includes a \\texttt{saveAs} feature to save images in a raw byte format readable by Photoshop.\n\\paragraph{\\texttt{Detection} Class}\nRepresents a detection in an image and the parameters associated with that detection. It is also responsible for doing the Gauss-Newton minimization described in the previous section to fine tune the position of detections\n\\paragraph{\\texttt{DetectionSet} Class}\nStores a set of 4 \\texttt{Detection} objects (one from each image) and stores the parameters related to the set of all 4 detections, such as the $\\texttt{error}$.\n\\paragraph{\\texttt{Header} Class}\nReads and parses the provided header format so that any field can be accessed by tag (used to read the \\texttt{\"MJD\"} of each image to determine the time it was taken)\n\\paragraph{\\texttt{WCSTransformation} Class} Stores the WCS data for a single image internally and provides functions to convert between pixel coordinates and RA/Dec coordinates using the code provided in the Java Tester.\n\\subsection{Assorted Implementation Details}\n\\paragraph{}\nThe linear regression fitting was done by setting the derivative of [the sum of square error between the function and the pixel values of the 5x5 grid] to equal 0 and solving the general case. The results in a system of two equations in two unknowns, which can be solved for a formula that was hardcoded into my code. However, a standard linear regression formula would yield the same result.\n\\paragraph{}\nIn many cases it was important to switch from \\texttt{Vector} based image indexing to raw \\texttt{int} based indexing because of performance issues. The point being that it is best to avoid using a wrapper class in inner loops as the compiler is unable to ``optimize the warper out.'' This change led to an approximately 10x speed up, which meant my entire solution runs in 20 sec per set of images, which makes debugging and trial and error much more practical.\n\\paragraph{}\nFinally, you may have seen that many times while describing my algorithm, I reference finding detections in a certain pixel window. Instead of searching through all the detections each time, I do this more efficiently by creating an \\texttt{Image} (ie. 2D array) of \\texttt{Detection}\\** variables. Then each “pixel” or “element of the array” (which is a \\texttt{Detection}\\**) is set to the address of a detection if one resides somewhere in that pixel, or otherwise it is set to \\texttt{null} to indicate no detection there. This makes searches for detections within certain rectangular bounds very fast by just searching through all pixels in that rectangle rather than every single detection. (While this technique limits me to  one detection per pixel, this is not any issue because I should not have multiple detections in a pixel because of the way detections are generated)\n\\section{Parameter Derivation}\nMost parameters were set by hand, using methods that are not worth discussing in detail (such as trial and error, and guessing and being close enough). The few exceptions to this include the following parameters\n\\paragraph{Asteroid Min and Max Movement} Were tuned by looking at images that had been aligned by eye and noticing that most asteroids moved at least 2 pixels over all 4 frames, and at most 5 pixels per frame. This lead to the 5 pixel search radius and the 70 pixels/day minimum motion limits\n\\paragraph{Gaussian Standard Deviation} The standard deviation 1.05 was found using the attached Mathematica file (\\texttt{PSF.nb}) by fitting a Gaussian to a small 9x9 cropped image of a handpicked sample star from one of the training image (\\texttt{PSF.png}). (However, I bet NASA knows the true point spread function function of their telescopes and can therefore use this function instead of a Gaussian)\n\\paragraph{Velocity Bounds}\nThese were computed by plotting the velocity (in RA/Dec space) of all the training objects using Mathematica (code: \\texttt{NEO.nb}) (data: \\texttt{detections.csv}). The plot allowed me to create the rough velocity bounds for both rejection and NEO classification by looking at the graphs by eye. (Again, I do not recommend this because it was a hack with positive---but very small---benefit)\n\\end{document}", "meta": {"hexsha": "3d683be8de60174f12a4c494b00605feda67d04a", "size": 13522, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Algorithm #5/Kushal1 - Algorithm.tex", "max_stars_repo_name": "JUJUME1960/Orbita", "max_stars_repo_head_hexsha": "74b80a1267566ab609d94ac776bf5585e626d64f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2015-03-10T15:35:01.000Z", "max_stars_repo_stars_event_max_datetime": "2015-04-19T15:26:39.000Z", "max_issues_repo_path": "Algorithms/Algorithm #5/Kushal1 - Algorithm.tex", "max_issues_repo_name": "nasa/NTL-Asteroid-Data-Hunter", "max_issues_repo_head_hexsha": "74b80a1267566ab609d94ac776bf5585e626d64f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-03-16T03:07:47.000Z", "max_issues_repo_issues_event_max_datetime": "2015-04-26T19:29:43.000Z", "max_forks_repo_path": "Algorithms/Algorithm #5/Kushal1 - Algorithm.tex", "max_forks_repo_name": "JUJUME1960/Orbita", "max_forks_repo_head_hexsha": "74b80a1267566ab609d94ac776bf5585e626d64f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-03-16T01:45:39.000Z", "max_forks_repo_forks_event_max_datetime": "2015-04-17T11:25:06.000Z", "avg_line_length": 150.2444444444, "max_line_length": 881, "alphanum_fraction": 0.7827984026, "num_tokens": 3186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6933745064101353}}
{"text": "\\chapter{Regularization}\n\\label{ch:regularization}\n\nThere has to be some cure for overfitting. Something that helps us control it. To find it, let's check what are the values of the parameters $\\theta$ under different degrees of polynomials.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.6]{workflow-overfitting.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nWith smaller degree polynomials values of $\\theta$ stay small, but then as the degree goes up, the numbers get really large.\n\n\\begin{figure*}[h]\n    \\centering\n    \\newcommand{\\third}{\\includegraphics[scale=0.55]{data-table-third.png}}\n    \\newcommand{\\eigth}{\\includegraphics[scale=0.55]{data-table-eigth.png}}\n    \\infinitewidthbox{\n    \\stackinset{r}{-0.32\\linewidth}{t}{+0.00\\linewidth}{\\eigth}{\\third}\\hspace{11cm}\n    }\n\\end{figure*}\n\n\\marginnote{Which inference of linear model would overfit more, the one with high $\\lambda$ or the one with low $\\lambda$? What should the value of $\\lambda$ be to cancel regularization? What if the value of $\\lambda$ is really high, say 1000?}\n\nMore complex models can fit the training data better. The fitted curve can wiggle sharply. The derivatives of such functions are high, and so need be the coefficients $\\theta$. If only we could force the linear regression to infer models with a small value of coefficients. Oh, but we can. Remember, we have started with the optimization function the linear regression minimizes — the sum of squared errors. We could simply add to this a sum of all $\\theta$ squared. And ask the linear regression to minimize both terms. Perhaps we should weigh the part with $\\theta$ squared, say, with some coefficient $\\lambda$, just to control the level of regularization.\n\nHere we go: we just reinvented regularization, a procedure that helps machine learning models not to overfit the training data. To observe the effects of regularization, we can give Polynomial Regression our own learner, which supports these kind of settings.\n\n\\newpage\n\nThe Linear Regression widget provides two types of regularization. \\marginnote{Internally, if no learner is present on its input, the Polynomial Regression widget would use just ordinary, non-regularized linear regression.}Ridge regression is the one we have talked about and minimizes the sum of squared coefficients $\\theta$. Lasso regression minimizes the sum of absolute value of coefficients. Although the difference may seem negligible, the consequences are that lasso regression may result in a large proportion of coefficients $\\theta$ being zero, in this way performing feature subset selection.\n\n% should it be so small?\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[scale=0.4]{lin-reg-ridge.png}\n    \\caption{$\\;$}\n\\end{marginfigure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.6]{workflow-ridge.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nNow for the test. Increase the degree of polynomial to the max. Use Ridge Regression. Does the inferred model overfit the data? How does the degree of overfitting depend on regularization strength?\n", "meta": {"hexsha": "9e2b36a84f8f076b908170bb79d92e67bf466b14", "size": 3059, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/041-regularization/regularization.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/041-regularization/regularization.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/041-regularization/regularization.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": 65.085106383, "max_line_length": 659, "alphanum_fraction": 0.7675711017, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.9149009549929799, "lm_q1q2_score": 0.6933067939674734}}
{"text": "\\section{Berry curvature}\n\nThe Berry curvature in the non-interacting crystal\nfor left and right circularly polarized\n($\\vc{ϵ}_±$) optical excitations for a given $\\vK$\nis $± 2 Ω_{+ ↑}^+ \\of{k}$, where\n\\begin{subequations}\n  \\begin{align}\n    Ω_{τ {\\s}}^n \\of{k}\n    & = \\vc{\\hat{z}} · \\vc{Ω}_{τ {\\s}}^n \\ofK, \\\\\n    & = - n τ\n        \\left[ \\frac{1}{2 k} \\pderiv{}{k} \\fnTheta{n} \\right]\n        \\sin{\\fnTheta{n}}, \\\\\n    & = - n τ\n        \\frac{2 {\\left( a t \\right)}^2 \\left( E_g - \\tau s E_{\\text{soc}} \\right)}\n        {{\\left[{\\left( 2 a t k \\right)}^2\n      + {\\left( E_g - \\tau s E_{\\text{soc}} \\right)}^2 \\right]}^{3/2}}.\n  \\end{align}\n\\end{subequations}\n\nThe BCS ground state %\n\\footnote{%\n  Note that the full ground state\n  also contains the two lower filled bands,\n  but those contribute zero net Berry curvature and may be ignored\n  in this section and the next.}\nis\n\\begin{subequations}\n  \\begin{align}\n    \\Ket{Ω}\n    & = ∏_{\\vK} \\csc{β_{\\vK}} γ_{\\vK ↑} γ_{-\\vK ↓} \\Ket{0}, \\\\\n    & = ∏_{\\vK} \\left( \\cos{β_{\\vK}} - \\sin{β_{\\vK}}\n        c_{\\vK ↑}^† c_{-\\vK ↓}^† \\right) \\Ket{0}.\n  \\end{align}\n\\end{subequations}\nThis superconducting state is built up\nfrom the quasiparticle eigenstates,\n$\\Ket{\\vK}\n= \\csc{β_{\\vK}} γ_{\\vK ↑} γ_{-\\vK ↓} \\Ket{0}$,\nof the $\\vK$-dependent Hamiltonian\n$λ_{\\vK} \\left( γ_{\\vK ↑}^† γ_{\\vK ↑}\n+ γ_{-\\vK ↓}^† γ_{-\\vK ↓} \\right)$.\nThe $z$-component of the Berry curvature of\nthe correlated state is zero,\n\\begin{equation}\n  \\vc{\\hat{z}} · i ∇_{\\vK} ⨯\n  \\Braket{\\vK | ∇_{\\vK} | \\vK}\n  = Ω_{+ ↑}^- \\of{k} + Ω_{- ↓}^- \\of{-k} = 0.\n\\end{equation}\nA single optically excited state in the left valley\nfor a given $\\vK$ is\n${c_{+ ↑}^+}^† \\ofK c_{+ ↑}^- \\Ket{\\vK}$,\nwhich has a Berry curvature\n$+2 \\sin^6 {β_{\\vK}} Ω_{+ ↑}^+ \\of{k}$.\nThe corresponding excitation in the right valley\nhas a Berry curvature of the same magnitude but opposite sign.\n", "meta": {"hexsha": "63e433bb1e8a703616e2189508a7a4966e2c5c6c", "size": 1878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/_topology.tex", "max_stars_repo_name": "razor-x/aps-dichalcogenides-superconductivity", "max_stars_repo_head_hexsha": "311fab11004ecf5efd79f0fbbe48a5f6f3b62da8", "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": "tex/_topology.tex", "max_issues_repo_name": "razor-x/aps-dichalcogenides-superconductivity", "max_issues_repo_head_hexsha": "311fab11004ecf5efd79f0fbbe48a5f6f3b62da8", "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/_topology.tex", "max_forks_repo_name": "razor-x/aps-dichalcogenides-superconductivity", "max_forks_repo_head_hexsha": "311fab11004ecf5efd79f0fbbe48a5f6f3b62da8", "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": 32.9473684211, "max_line_length": 82, "alphanum_fraction": 0.5820021299, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6932968172427412}}
{"text": "\\section{Implementation}\n\\label{sec:implementation}\n\n\\subsection{Training and Test Set}\nIn different experiments we use a different number of training examples.\nGiven the original dataset $\\mathbb{D} = \\{ \\varepsilon_\\mu, \\tau(\\varepsilon_\\mu)\\}_{\\mu=1}^M$ (with $M = 5000$), we create the training $\\mathbb{D}_{train}$ and test set $\\mathbb{D}_{test}$ as follows:\n\\begin{equation*}\n    \\begin{split}\n        \\mathbb{D}_{train} &= \\{ \\varepsilon_\\mu, \\tau(\\varepsilon_\\mu)\\}_{\\mu=1}^P, \\\\\n        \\mathbb{D}_{test} &= \\{ \\varepsilon_\\mu, \\tau(\\varepsilon_\\mu)\\}_{\\mu=Q}^M,\n    \\end{split}\n\\end{equation*}\nwith $Q > P$.\nSince we choose $P \\in [1, 2000]$ in different experiments, we fix $Q = 2001$ for all experiments, in order to always test on the same dataset. \n\n\\subsection{Stochastic Gradient Descent}\nThe first step of our implementation of Stochastic Gradient Descent is to initialize the weights' vectors with random values and then normalize them to have unit norm $||w_j|| = 1$.\nIt is important to initialize the weights randomly in order to avoid symmetry problems:\nsince the weights gradient and the update rule is the same for all hidden unit, the updates at each epoch are also the same, which causes all units to learn the same final weights and reduces the representation power of the network.\nThen, we perform a given number of updates:\nat each iteration, we randomly select an example $\\nu$ from the training dataset, compute the gradient with respect to the weights (see \\cref{sub:gradients}) and update them according to \\cref{eq:weights-update}.\n\nAt regular intervals (i.e. after a fixed number of iterations), we compute the error on both the entire training and the test sets, as shown in \\cref{eq:cost-total}.\n", "meta": {"hexsha": "7caa5622984d60e65adb1722ceccb86b08cc84ab", "size": 1733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_3/report/03_implementation.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/03_implementation.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/03_implementation.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": 72.2083333333, "max_line_length": 232, "alphanum_fraction": 0.7391806117, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.6932767990260265}}
{"text": "\\section{Limits, colimits, and adjunctions}\\label{906}\n% Some organizational stuff, unnecessary for the book:\n% Hi! This is 18.906. I'm glad to see familiar faces, and new faces. Let me introduce the course. It's a pset based course, with 6 psets. The first one is due Feb 22. It's due every two weeks, so I can't formulate all porblems right at the beginning of the two weeks. I'll try to have the psets done a week before the psets are due. So the first couple problems are up for this pset. You'll be glad to hear that there's no final. I don't think I'll do it again, not this term.\n\n% I'll have office hours every week, but I don't know when yet. Hood's the grader and he'll have office hours. There's a course website which can be easily found. What's the course about? Really homotopy theory. 905 was homology and cohomology. \n\n%Any questions? I try to correspond problems in the psets and lectures.\n\\subsection{Limits and colimits}\n%I'm interested in ``construction''. In 905, I began by talking about category theory. I just won't introduce basic concepts again.\nWe will freely use the theory developed in the first part of this book (see \\S \\ref{categories}).\nSuppose $\\cI$ is a small category (so that it has a \\emph{set} of objects),\nand let $\\cc$ be another category.\n\\begin{definition}\n    Let $X:\\cI\\to\\cc$ be a functor.\n    A \\emph{cone under $X$} is a natural transformation $\\eta$ from $X$ to a constant functor;\n    explicitly, this means that for every object $i$ of $\\cI$, we must have a map $\\eta_i: X_i\\to Y$,\n    such that for every $f:i\\to j$ in $\\cI$, the following diagram commutes:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    X_i\\ar[d]^{f_\\ast}\\ar[dr]^{\\eta_i} & \\\\\n\t    X_j\\ar[r]^{\\eta_j} & Y.\n\t    }\n    \\end{equation*}\n    A \\emph{colimit} of $X$ is an initial cone $(L,\\tau_i)$ under $X$;\n    explicitly, this means that for all cones $(Y,\\eta_i)$ under $X$,\n    there exists a unique natural transformation $h:L\\to Y$ such that $h\\circ \\tau_i = \\eta_i$.\n\\end{definition}\nAs always for category theoretic concepts, some examples are in order.\n\\begin{example}\\label{coproductsarecolimits}\n    If $\\cI$ is a discrete category (i.e., only a set, with identity maps), the colimit of any functor $\\cI\\to\\cc$\n    is the coproduct. This already illustrates an important point about colimits: they need not exist in general\n    (since, for example, coproducts need not exist in a general category).\n    Examples of categories $\\cc$ where the colimit of a functor $\\cI\\to\\cc$ exists:\n    if $\\cc$ is sets, or spaces, the colimit is the disjoint union.\n    If $\\cc=\\mathbf{Ab}$, a candidate for the colimit would be the product:\n    but this only works if $\\cI$ is finite; in general, the correct thing is to take the (possibly infinite) direct sum.\n\\end{example}\n\\begin{example}\n    Let $\\cI = \\mathbf{N}$, considered as a category via its natural poset structure;\n    then a functor $\\cI\\to \\cc$ is simply a linear system of objects and morphisms in $\\cc$.\n    As a specific example, suppose $\\cc = \\mathbf{Ab}$, and\n    consider the diagram $X:\\cI \\to \\cc$ defined by the system\n    $$\\Z\\xrightarrow{2}\\Z\\xrightarrow{3}\\Z\\to\\cdots$$\n    The colimit of this diagram is $\\QQ$, where the maps are:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\Z\\ar[r]^2\\ar[dr]^1 & \\Z\\ar[r]^3\\ar[d]^{1/2} & \\Z\\ar[r]^4\\ar[dl]^{1/3!} & \\cdots\\\\\n\t    & \\QQ & &\n\t    }\n    \\end{equation*}\n\\end{example}\n\\begin{example}\\label{colimitgroupaction}\n    Let $G$ be a group; we can view this as a category with one object, where the morphisms are the elements of the group\n    (composition is given by the group structure).\n    If $\\cc = \\Top$ is the category of topological spaces, a functor $G\\to \\cc$ is simply a\n    group action on a topological space $X$.\n    The colimit of this functor is the orbit space of the $G$-action on $X$.\n\\end{example}\n\\begin{example}\n    Let $\\cI$ be the category whose objects and morphisms are determined by the following graph:\n    \\begin{equation*}\n\t\\xymatrix{ & a\\ar[dl]\\ar[dr] & \\\\\n\tb & & c.}\n    \\end{equation*}\n    The colimit of a diagram $\\cI\\to \\cc$ is called a \\emph{pushout}.\n\n    If $\\cc=\\Top$, again, a functor $\\cI\\to \\cc$ is determined by a diagram of spaces:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    & A\\ar[dl]^f\\ar[dr]^g & \\\\\n\t    B & & C.\n\t    }\n    \\end{equation*}\n    The colimit of such a functor is just the pushout $B\\cup_A C:= B\\sqcup C/\\sim$, where $f(a)\\sim g(a)$ for all $a\\in A$.\n    We have already seen this in action before: the same construction appears in the process of attaching cells to CW-complexes.\n\n    If $\\cc$ is the category of groups, instead, the colimit of such a functor is the free product quotiented out\n    by a certain relation (the same as for topological spaces); this is called the \\emph{amalgamated free product}.\n\\end{example}\n\\begin{example}\n    Suppose $\\cI$ is the category defined by the following graph:\n\\begin{equation*}\n    \\begin{tikzcd}\n\ta\\ar[r,shift left=.75ex]\\ar[r,shift right=.75ex] & b.\n    \\end{tikzcd}\n\\end{equation*}\n    The colimit of a diagram $\\cI\\to\\cc$ is called the \\emph{coequalizer} of the diagram.\n\\end{example}\n\n    One can also consider cones \\emph{over} a diagram $X:\\cI\\to\\cc$: this is simply a cone in the opposite category.\n\\begin{definition}\n    With notation as above, the \\emph{limit} of a diagram $X:\\cI\\to\\cc$ is a terminal object in cones over $X$.\n\\end{definition}\nFor instance, products are limits, just like in Example \\ref{coproductsarecolimits}.\n(This example also shows that abelian groups satisfy an interesting property: finite products are the same as finite coproducts!)\n\\begin{exercise}\n    Revisit the examples provided above: what is the limit of each diagram?\n    For instance, the limit of the diagram described in Example \\ref{colimitgroupaction} is just the fixed points!\n\\end{exercise}\n\\subsection{Adjoint functors}\nAdjoint functors are very useful --- and very natural --- objects.\nWe already have an example: let $\\cc^\\cI$ be the functor category $\\Fun(\\cI,\\cc)$.\n(We've been working in this category this whole time!)\nLet's make an additional assumption on $\\cc$, namely that all $\\cI$-indexed colimits exist.\nAll examples considered above satisfy this assumption.\n\nThere is a functor $\\cc\\to \\cc^\\cI$, given by sending any object to the constant functor taking that value.\nThe process of taking the colimit of a diagram supplies us with a functor $\\cc^\\cI\\to \\cc$.\nWe can characterize this functor via a formula\\footnote{There is an analogous formula for the limit of a diagram:\n$$\\cc(W,\\lim_{i\\in \\cI} X_i) = \\cc^{\\cI}(\\mathrm{const}_W,X).$$}:\n$$\\cc(\\colim_{i\\in \\cI} X_i,Y) = \\cc^\\cI(X,\\mathrm{const}_Y),$$\nwhere $X$ is some functor from $\\cI$ to $\\cc$.\nThis formula is reminiscent of the adjunction operator in linear algebra,\nand is in fact our first example of an adjunction.\n\n\\begin{definition}\n    Let $\\cc,\\cd$ be categories,\n    with specified functors $F:\\cc\\to \\cd$ and $G:\\cd\\to\\cc$.\n    An \\emph{adjunction between $F$ and $G$} is an isomorphism:\n    $$\\cd(FX,Y) = \\cc(X,GY),$$\n    which is natural in $X$ and $Y$.\n    In this situation, we say that $F$ is a \\emph{left adjoint} of $G$ and $G$ is a \\emph{right adjoint} of $X$.\n    %People typically write left adjoints on the top.\n\\end{definition}\nThis notion was invented by Dan Kan, who worked in the MIT mathematics department until he passed away in 2013.\n\nWe've already seen an example above, but here is another one:\n\\begin{definition}[Free groups]\n    There is a forgetful functor $u:\\mathrm{Grp}\\to\\mathrm{Set}$.\n    Any set $X$ gives rise to a group $FX$, namely the free group on $X$ elements.\n    This is determined by a universal property:\n    set maps $X\\to u\\Gamma$ are the same as group maps $FX\\to \\Gamma$,\n    where $\\Gamma$ is any group.\n    This is exactly saying that the free group functor the left adjoint to the forgetful functor $u$.\n\\end{definition}\nIn general, ``free objects'' come from left adjoints to forgetful functors.\n\n\n\\begin{definition}\n    A category $\\cc$ is said to be \\emph{cocomplete} if all (small) colimits exist in $\\cc$.\n    Similarly, one says that $\\cc$ is \\emph{complete} if all (small) limits exist in $\\cc$.\n\\end{definition}\n\\subsection{The Yoneda lemma}%This belongs to the next lecture, but fits in better here.\nOne of the many important concepts in category theory is that an object is determined by\nthe collection of all maps out of it.\nThe Yoneda lemma is a way of making this precise.\nAn important reason to even bother thinking about objects in this fashion comes from our\ndiscussion of colimits.\nNamely, how do we even know that the notion is well-defined?\n\nThe colimit of an object is characterized by maps out of it; precisely:\n$$\\cc(\\colim_{j\\in\\cJ}X_j,Y) = \\cc^\\cJ(X_\\bullet,\\mathrm{const}_Y).$$\nThe two sides are naturally isomorphic, but if the colimit exists, how do we know that it\nis unique?\nThis is solved by Yoneda lemma\\footnote{Sometimes ``you-need-a-lemma''!}:\n\\begin{theorem}[Yoneda lemma]\n    Consider the functor $\\cc(X,-):\\cc\\to\\set$. Suppose $G:\\cc\\to\\set$ is another functor. It turns out that:\n    $$\\mathrm{nt}(\\cc(X,-),G)\\simeq G(X).$$\n\\end{theorem}\n\\begin{proof}\n    Let $x\\in G(X)$.\n    Define a natural transformation that sends a map $f:X\\to Y$ to $f_\\ast(x)\\in G(Y)$.\n    On the other hand, we can send a natural transformation $\\theta:C(X,-)\\to G$\n    to $\\theta_X(1_X)$. \n    Proving that these are inverses is left as an exercise --- largely in notation --- to the reader.\n\\end{proof}\nIn particular, if $G=\\cc(Y,-)$\n--- these are called \\emph{corepresentable} functors ---\nthen $\\mathrm{nt}(\\cc(X,-),\\cc(Y,-))\\simeq \\cc(Y,X)$.\nSimply put, natural isomorphisms $\\cc(X,-)\\to \\cc(Y,-)$ are the same as isomorphisms $Y\\to X$.\nAs a consequence, the object that a corepresentable functor corepresents is unique\n(at least up to isomorphism).\n\nFrom the Yoneda lemma, we can obtain some pretty miraculous conclusions.\nFor instance, functors with left and/or right adjoints are very well-behaved\n(the ``constant functor'' functor is an example where both adjoints exist),\nas the following theorem tells us.\n\\begin{theorem}\\label{adjointslimits}\n    Let $F:\\cc\\to\\cd$ be a functor.\n    If $F$ admits a right adjoint, it preserves colimits.\n    Dually, if $F$ admits a left adjoint, it preserves limits.\n\\end{theorem}\n\\begin{proof}\n    We'll prove the first statement, and leave the other as an (easy) exercise.\n    Let $F:\\cc\\to\\cd$ be a functor that admits a right adjoint $G$, and let $X:\\cI\\to\\cc$ be a\n    small $\\cI$-indexed diagram in $\\cc$.\n    For any object $Y$ of $\\cc$, there is an isomorphism\n    $$\\Hom(\\colim_{\\cI} X, Y) \\simeq \\lim_{\\cI}\\Hom(X, Y).$$\n    This follows easily from the definition of a colimit.\n    Let $Y$ be any object of $\\cd$; then, we have:\n    \\begin{align*}\n\t\\cd(F(\\colim_{\\cI} X), Y) & \\simeq \\cc(\\colim_{\\cI} X, G(Y))\\\\\n\t& \\simeq \\lim_{\\cI}\\cc(X, G(Y))\\\\\n\t& \\simeq \\lim_{\\cI}\\cd(F(X), Y)\\\\\n\t& \\simeq \\cd(\\colim_{\\cI}F(X), Y).\n    \\end{align*}\n    The Yoneda lemma now finishes the job.\n\\end{proof}\n", "meta": {"hexsha": "c4b06dfc6661004aabe28a76024ceee98cf09af2", "size": 11010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-39-limits-colimits-adjunctions.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-39-limits-colimits-adjunctions.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-39-limits-colimits-adjunctions.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": 55.3266331658, "max_line_length": 476, "alphanum_fraction": 0.6992733878, "num_tokens": 3298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038221, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.6932767820642121}}
{"text": "\\lab{Metropolis Algorithm}{Metropolis Algorithm}\n\\objective{Understand the basic principles of the Metropolis algorithm and apply these ideas to the\nIsing Model.}\n\n\\section*{The Metropolis Algorithm}\nSampling from a given probability distribution is an important task in many different applications found throughout the sciences.\nWhen these distributions are complicated, as is often the case when modeling real-world problems, direct sampling methods\ncan become difficult, as they might involve computing high-dimensional integrals.\nThe Metropolis algorithm is an effective method to sample from many distributions, requiring only that we\nbe able to evaluate the probability density function up to a constant of proportionality. In particular,\nthe Metropolis algorithm does not require us to compute difficult high-dimensional integrals, such as those that are found\nin the denominator of Bayesian posterior distributions.\n\nThe Metropolis algorithm is an MCMC sampling method which generates a sequence of random variables, similar to Gibbs sampling.\nThese random variables form a Markov Chain whose invariant distribution is equal to the distribution from which we wish\nto sample. Suppose that $h : \\mathbb{R}^n \\rightarrow \\mathbb{R}$ is the probability density function of distribution,\nand suppose that $f(\\boldsymbol{\\theta}) = c \\cdot h(\\boldsymbol{\\theta})$ for some nonzero constant $c$ (in practice, we assume that $f$ is an easy\nfunction to evaluate, while $h$ is difficult). Let $Q : \\mathbb{R}^n \\times \\mathbb{R}^n \\rightarrow \\mathbb{R}$ be\na symmetric \\emph{proposal function}\n(so that $Q(\\cdot, \\y)$ is a probability density function for all $\\y \\in \\mathbb{R}^n$,\n and $Q(\\x,\\y) = Q(\\y,\\x)$ for all $\\x,\\y \\in \\mathbb{R}^n$) and let\n $A : \\mathbb{R}^n \\times \\mathbb{R}^n \\rightarrow \\mathbb{R}$ be an \\emph{acceptance function} defined by\n\\[\nA(\\x,\\y) = \\min\\left(1, \\frac{f(\\x)}{f(\\y)}\\right).\n\\]\nWe can combine these functions in such a way so as to sample from the aforementioned Markov Chain by following Algorithm \\ref{alg:metropolis}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Metropolis Algorithm}{}\n    \\State \\textrm{Choose initial point } $\\y_0$.\n    \\For{$t=1,2,\\ldots$}\n        \\State \\textrm{Draw } $\\x \\sim Q(\\cdot, \\y_{t-1})$\n        \\State \\textrm{Draw } $a \\sim \\text{unif}(0,1)$\n        \\If{$a \\leq A(\\x,\\y_{t-1})$}\n            \\State $\\y_t = \\x$\n        \\Else\n            \\State $\\y_t = \\y_{t-1}$\n        \\EndIf\n    \\EndFor\n    \\State \\textrm{Return } $\\y_1,\\y_2,\\y_3,\\ldots$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Metropolis Algorithm}\n\\label{alg:metropolis}\n\\end{algorithm}\nThe Metropolis algorithm can be interpreted as follows:\ngiven our current state $\\y$, we propose a new state according to the distribution $Q(\\cdot, \\y)$. We then accept or reject it according to $A$.  We continue by repeating the process. So long as $Q$ defines an irreducible, aperiodic, and non-null recurrent Markov chain, we will have a Markov chain whose unique invariant distribution will have density $h$. Furthermore, given any initial state, the chain will converge to this invariant distribution.\nNote that for numerical reasons, it is often wise to make calculations of the acceptance functions in log space:\n\\[\n\\log A(\\x,\\y) = \\min(0, \\log f(\\x) - \\log f(\\y)).\n\\]\n\n\nLet's apply the Metropolis algorithm to a simple example of Bayesian analysis.\nConsider the problem of computing the posterior distribution over the mean $\\mu$ and variance $\\sigma^2$ of a normal distribution for which we have $n$ data points $y_1,\\ldots,y_n$.\nFor concreteness, we use the data in \\texttt{examscores.csv} and we assume\nthe prior distributions\n\\begin{align*}\n\\mu &\\sim \\mathcal{N}(m=80,\\ s^2=16)\\\\\n\\sigma^2 &\\sim IG(\\alpha=3,\\beta=50).\n\\end{align*}\nIn this situation, we wish to sample from the posterior distribution\n\\[\np(\\mu,\\sigma^2 \\,|\\,y_1,\\ldots,y_N) = \\frac{p(\\mu)p(\\sigma^2)\\prod_{i=1}^n \\mathcal{N}(y_i \\, | \\, \\mu, \\sigma^2)}\n{\\int_{-\\infty}^\\infty\\int_{0}^\\infty p(\\mu)p(\\sigma^2)\\prod_{i=1}^n \\mathcal{N}(y_i \\, | \\, \\mu, \\sigma^2)\\,d\\sigma^2d\\mu}.\n\\]\nHowever, we can conveniently calculate only the numerator of this expression.\nSince the denominator is simply a constant with respect to $\\mu$ and $\\sigma^2$, the numerator can serve as the function $f$ in the Metropolis algorithm, and the denominator can serve as the constant $c$.\n\nWe choose our proposal function to be based on a bivariate Normal distribution:\n\\[\nQ(x,y) = \\mathcal{N}(x\\, | \\, y, sI),\n\\]\nwhere $I$ is the $2\\times 2$ identity matrix and $s$ is some positive scalar.\n\\begin{lstlisting}\n>>> def proposal(y, s):\n...     \"\"\"The proposal function Q(x,y) = N(x|y,sI).\"\"\"\n...     return stats.multivariate_normal.rvs(mean=y, cov=s*np.eye(len(y)))\n...\n>>> def propLogDensity(x):\n...     \"\"\"Calculate the log of the proportional density.\"\"\"\n...     logprob = muprior.logpdf(x[0]) + sig2prior.logpdf(x[1])\n...     logprob += stats.norm.logpdf(scores, loc=x[0], scale=sqrt(x[1])).<<sum>>()\n...     return logprob    # ^this is where the scores are used.\n...\n>>> def acceptance(x, y):\n...     return min(0, propLogDensity(x) - propLogDensity(y))\n\\end{lstlisting}\n\nWe are now ready to code up the Metropolis algorithm using these functions.\nWe will keep track of the samples generated by the algorithm, along with the proportional log densities of the samples and the proportion of proposed samples that were accepted.\n\nWe can evaluate the quality of our results by plotting the log probabilities, the $\\mu$ samples, the $\\sigma^2$ samples, and kernel density estimators for the marginal posterior distributions of $\\mu$ and $\\sigma^2$. The kernel density estimator is the posterior distribution for a parameter. It measures the frequency of each draw. In this example, the kernel density estimator for $\\mu$ should be approximately normal, and the kernel density estimator for $\\sigma^2$ should be approximately an inverse gamma.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/logprobs.pdf}\n    \\caption{Log densities of the first 500 Metropolis samples.}\n    \\label{fig:logprobs}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\begin{subfigure}[b]{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/mu_traces.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/mu_kernel.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/sig_traces.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/sig_kernel.pdf}\n    \\end{subfigure}\n\\caption{Metropolis samples and KDEs for the marginal posterior distribution of $\\mu$ (top row) and $\\sigma^2$ (bottom row).}\n\\label{fig:metropolis_results}\n\\end{figure}\n\n\n\\begin{comment}\nWe will use the Metropolis algorithm to obtain samples from a multivariate normal distribution to demonstrate this process.\nSuppose also that we desire to obtain samples from a multivariate normal distribution with arbitrary covariance matrix $\\Sigma$, and that this is difficult (obviously we can do this directly in Python, but this is merely a tutorial to see how the Metropolis algorithm works). Suppose further that we are able to easily compute the ratio of the density of this distribution at two points $\\mathbf{x}$ and $\\mathbf{y}$ of length $K$, i.e.\n\\begin{align*}\n\\frac{N(\\mathbf{x} \\; ; \\; \\mu, \\Sigma)}{N(\\mathbf{y} \\; ; \\; \\mu, \\Sigma)} & = \\frac{\\frac{1}{(2\\pi)^{K/2}|\\Sigma|^{1/2}} e^{-\\frac{1}{2}(\\mathbf{x} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{x} - \\mu)}}{\\frac{1}{(2\\pi)^{K/2}|\\Sigma|^{1/2}} e^{-\\frac{1}{2}(\\mathbf{y} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{x} - \\mu)}} \\\\\n& = \\frac{e^{-\\frac{1}{2}(\\mathbf{x} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{x} - \\mu)}}{e^{-\\frac{1}{2}(\\mathbf{y} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{x} - \\mu)}} \\\\\n& = e^{-\\frac{1}{2}\\left((\\mathbf{x} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{x} - \\mu) - (\\mathbf{y} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{y} - \\mu)\\right)}\n\\end{align*}\n\n\\begin{problem}\n\\label{problem1}\nWrite an acceptance function that computes\n\\begin{equation*}\np = \\min \\{1, e^{-\\frac{1}{2}\\left((\\mathbf{x} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{x} - \\mu) - (\\mathbf{y} - \\mu)^{T} \\Sigma^{-1} (\\mathbf{y} - \\mu)\\right)}\\}\n\\end{equation*}\ngiven $\\mathbf{x}, \\mathbf{y}, \\mu,$ and $\\Sigma$, and then draws from a Bernoulli distribution with parameter $p$. It should return a $1$ if it accepts the new state, and a $0$ if it rejects it.\n\\end{problem}\n\nSpecifically, we will try to sample from the distribution centered at the origin, with covariance matrix\n\\begin{equation*}\n\\Sigma = \\left[ \\begin{array}{cc} 12 & 4 \\\\ 4 & 16 \\end{array} \\right]\n\\end{equation*}\n\n\\begin{lstlisting}\n>>> mu = np.zeros(2)\n>>> sigma = np.array([[12., 10.], [10., 16.]])\n\\end{lstlisting}\n\nWe will let $Q(\\mathbf{x} | \\mathbf{y}) = N(\\mathbf{x} \\; ; \\; \\mathbf{y}, I)$ be our proposal distribution, given that we are currently in state $\\mathbf{y}$, i.e. we propose a new state by drawing from the multivariate normal distribution centered at $\\mathbf{y}$ with identity covariance. We then accept according to our acceptance probability, computed in Problem \\ref{problem1}.\n\n\\begin{problem}\nWrite a function that accepts a current state, the mean and covariance from the distribution we desire to sample from, and returns the next state. We should propose according to $Q$ described above, and accept according to the function in Problem \\ref{problem1}.\n\\end{problem}\n\nWe now have a way to sample a new state from an old state.\nAs we've stated before, this method creates a Markov chain that \\emph{converges} to the desired distribution; at the beginning, however, if our initial guess is highly unlikely for the desired distribution, it may take a while before we get there.\nWe would like to measure our progress.\n\n\\begin{problem}\nWrite a function that computes the log of the multivariate normal density of a point $\\mathbf{x}$ given a mean $\\mu$ and covariance matrix $\\Sigma$. Be intelligent about how you implement this, that is, do not simply compute the multivariate normal density and then take the log of it, as this may lead to numerical issues. The whole purpose of looking at the multivariate log is to make this more stable.\n\\end{problem}\n\nWe will finally put everything together.\n\n\\begin{problem}\nWrite a function that accepts an initial point $\\mathbf{x}$, a mean $\\mu$ and covariance $\\Sigma$ for the desired sampling distribution, and which performs the Metropolis algorithm for a number of iterations, $n\\_samples$. Save each sample $\\mathbf{x}$ as produced by the algorithm. Also compute the log of the multivariate normal density of each point, and return both the samples and the logprobs.\n\\end{problem}\n\nWe would like to see how long it takes for our algorithm to converge to the right distribution. We can do this by plotting the log-probs returned by our function. Here we use an initial state $\\mathbf{x} = \\left[\\begin{array}{cc} 100 & 100 \\end{array}\\right]$.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/logprobs.pdf}\n\\caption{Log probabilities of our samples.}\n\\end{figure}\n\nFrom this we can see that after between $300$ and $500$ iterations, we had converged to the correct distribution. We can visualize the path of our sampler by plotting the samples themselves:\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/samples.pdf}\n\\caption{Samples from the Metropolis algorithm.}\n\\end{figure}\n\n\\begin{problem}\nUsing $\\mu$ and $\\Sigma$ as defined previously and using an initial state $\\mathbf{x} = \\left[ \\begin{array}{cc} 1000 & -1000 \\end{array} \\right]$ run your Metropolis sampler for $10000$ iterations. Plot the log probs as well as the samples. How long did it take to converge?\n\\end{problem}\n\\end{comment}\n\n\\begin{problem}\nWrite a function that uses the Metropolis Hastings algorithm to draw from the posterior distribution over the mean $\\mu$ and variance $\\sigma^2$. Use the given functions and algorithm \\ref{alg:metropolis} to complete the problem.\n\n\tYour function should return an array of draws, an array of the log probabilities, and an acceptance rate. Use the following code to check your work. Using the seaborn.kdeplot function, plot the first 500 log probabilities, the $\\mu$ samples and posterior distribution, and the $\\sigma^2$ samples and posterior distribution. The results should be \\textit{similar} to Figures \\ref{fig:logprobs} and \\ref{fig:metropolis_results}.\n\nWhen comparing \\texttt{a} to the acceptance, remember to use \\texttt{log(a)} as we are in log space.\n\n\n\\begin{lstlisting}\n# Load in the data and initialize hyperparameters.\n>>> scores = np.load(\"examscores.npy\")\n\n# Prior sigma^2 ~ IG(alpha, beta)\n>>> alpha = 3\n>>> beta = 50\n\n#Prior mu ~ N(m, s)\n>>> m = 80\n>>> s = 4\n\n# Initialize the prior distributions.\n>>> muprior = stats.norm(loc=m, scale=sqrt(s**2))\n>>> sig2prior = stats.invgamma(alpha, scale=beta)\n\\end{lstlisting}\n\n\\textit{Hint}: The seaborn package is very useful in plotting kernel densities, with the distplot method. See the \\href{https://seaborn.pydata.org/generated/seaborn.distplot.html}{documentation.}\n\\end{problem}\n\n\\section*{The Ising Model}\nIn statistical mechanics, the Ising model describes how atoms interact in ferromagnetic material. Assume we have some lattice $\\Lambda$ of sites. We say $i \\sim j$ if $i$ and $j$ are adjacent sites. Each site $i$ in our lattice is assigned an associated \\emph{spin} $\\sigma_{i} \\in \\{\\pm 1\\}$. A \\emph{state} in our Ising model is a particular spin configuration $\\sigma = (\\sigma_{k})_{k \\in \\Lambda}$. If $L = |\\Lambda|$, then there are $2^{L}$ possible states in our model. If $L$ is large, the state space becomes huge, which is why MCMC sampling methods (in particular the Metropolis algorithm) are so useful in calculating model estimations.\n\nWith any spin configuration $\\sigma$, there is an associated energy\n\\[\nH(\\sigma) = -J \\sum_{i \\sim j} \\sigma_{i} \\sigma_{j}\n\\]\n where $J > 0$ for ferromagnetic materials, and $J < 0$ for antiferromagnetic materials. Throughout this lab, we will assume $J = 1$, leaving the energy equation to be $H(\\sigma) = -\\sum_{i \\sim j} \\sigma_{i}\\sigma_{j}$ where the interaction from each pair is added only once.\n\nWe will consider a lattice that is a $100 \\times 100$ square grid.\nThe adjacent sites for a given site are those directly above, below, to the left, and to the right of the site, so to speak.\nFor sites on the edge of the grid, we assume it wraps around.\nIn other words, a site at the farthest left side of the grid is adjacent to the corresponding site on the farthest right side.\nThus, a single spin configuration can be represented as a $100 \\times 100$ array, with entries of $\\pm 1$.\n\nThe following code will construct a random spin configuration of size n:\n\n\\begin{lstlisting}\ndef random_lattice(n):\n    \"\"\"Constructs a random spin configuration for an nxn lattice.\"\"\"\n    random_spin = np.zeros((n,n))\n    for k in range(n):\n        random_spin[k,:] = 2*np.random.binomial(1,.5, n) -1\n    return random_spin\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.5\\textwidth]{figures/initial_config.pdf}\n\\caption{Spin configuration from random initialization.}\n\\label{fig:random_spin}\n\\end{figure}\n\n\\begin{problem} % Calculate the energy of the spin configuration.\n\\label{problem2}\nWrite a function that accepts a spin configuration $\\sigma$ for a lattice as a NumPy array.\nCompute the energy $H(\\sigma)$ of the spin configuration.\nBe careful to not double count site pair interactions!\n\\\\(Hint: \\li{np.roll()} may be helpful.)\n\\end{problem}\n\nDifferent spin configurations occur with different probabilities, depending on the energy of the spin configuration and $\\beta > 0$, a quantity inversely proportional to the temperature.\nMore specifically, for a given $\\beta$, we have\n\\begin{equation*}\n\\mathbb{P}_{\\beta}(\\sigma) = \\frac{e^{-\\beta H(\\sigma)}}{Z_{\\beta}}\n\\end{equation*}\nwhere $Z_{\\beta} = \\sum_{\\sigma} e^{-\\beta H(\\sigma)}$.\nBecause there are $2^{100 \\cdot 100} = 2^{10000}$ possible spin configurations for our particular lattice, computing this sum is infeasible.\nHowever, the numerator is quite simple, provided we can efficiently compute the energy $H(\\sigma)$ of a spin configuration.\nThus the ratio of the probability densities of two spin configurations is simple:\n\\begin{equation*}\n\\frac{\\mathbb{P}_{\\beta}(\\sigma^{*})}{\\mathbb{P}_{\\beta}(\\sigma)}\n= \\frac{e^{-\\beta H(\\sigma^{*})}}{e^{-\\beta H(\\sigma)}}\n= e^{\\beta (H(\\sigma) - H(\\sigma^{*}))}\n\\end{equation*}\n\nThe simplicity of this ratio should lead us to think that a Metropolis algorithm might be an appropriate way by which to sample from the spin configuration probability distribution, in which case the acceptance probability would be\n\\begin{equation}\nA(\\sigma^{*}, \\sigma) = \\begin{cases} 1 & \\mbox{if } H(\\sigma^{*}) < H(\\sigma) \\\\ e^{\\beta (H(\\sigma) - H(\\sigma^{*}))} & \\mbox{ otherwise.} \\end{cases}\n\\label{eq:ising-acceptance}\n\\end{equation}\n\nBy choosing our transition matrix $Q$ cleverly, we can also make it easy to compute the energy for any proposed spin configuration.\nWe restrict our possible proposals to only those spin configurations in which we have flipped the spin at exactly one lattice site, i.e. we choose a lattice site $i$ and flip its spin.\nThus, there are only $L$ possible proposal spin configurations $\\sigma^{*}$ given $\\sigma$, each being proposed with probability $\\frac{1}{L}$, and such that $\\sigma_{j}^{*} = \\sigma_{j}$ for all $j \\neq i$, and $\\sigma_{i}^{*} = - \\sigma_{i}$.\nNote that we would never actually write out this matrix (it would be $2^{10000} \\times 2^{10000}$).\nComputing the proposed site's energy is simple: if the spin flip site is $i$, then we have\n\\begin{equation}\nH(\\sigma^{*}) = H(\\sigma) + 2\\sum_{j: j \\sim i} \\sigma_{i}\\sigma_{j}.\n\\label{eq:ising-new-spin-energy}\n\\end{equation}\n\n\\begin{problem} % Choose somewhere to flip a bit.\nWrite a function that accepts an integer $n$ and chooses a pair of indices $(i,j)$ where $0 \\le i,j \\le n-1$.\nEach possible pair should have an equal probability $\\frac{1}{n^2}$ of being chosen.\n\\label{prob:ising-flip-site}\n\\end{problem}\n\n\\begin{problem} % Compute the energy of the proposed configuration.\nWrite a function that accepts a spin configuration $\\sigma$, its energy $H(\\sigma)$, and integer indices $i$ and $j$.\nUse \\eqref{eq:ising-new-spin-energy} to compute the energy of the new spin configuration $\\sigma^*$, which is $\\sigma$ but with the spin flipped at the $(i,j)$th entry of the corresponding lattice.\nDo not explicitly construct the new lattice for $\\sigma^*$.\n\\label{prob:ising-new-energy}\n\\end{problem}\n\n\\begin{problem} % Accept / reject the new configuration.\nWrite a function that accepts a float $\\beta$ and spin configuration energies $H(\\sigma)$ and $H(\\sigma^*)$.\nUsing \\eqref{eq:ising-acceptance}, calculate whether or not the new spin configuration $\\sigma^*$ should be accepted (return \\li{True} or \\li{False}).\nConsider doing the calculations in log space.\n(Hint: np.random.binomial() might be useful)\n\\label{prob:ising-acceptance}\n\\end{problem}\n\nTo track the convergence of the Markov chain, we would like to look at the probabilities of each sample at each time. However, this would require us to compute the denominator $Z_{\\beta}$, which is generally the reason we have to use a Metropolis algorithm to begin with.\nWe can get away with examining only $-\\beta H(\\sigma)$.\nWe should see this value increase as the algorithm proceeds, and it should converge once we are sampling from the correct distribution.\nNote that we don't expect these values to converge to a specific value, but rather to a restricted range of values.\n\n\\begin{problem}\nWrite a function that accepts a float $\\beta>0$ and integers $n$, \\li{n_samples}, and \\li{burn_in}.\nInitialize an $n\\times n$ lattice for a spin configuration $\\sigma$ using Problem \\ref{problem2}.\nUse the Metropolis algorithm to (potentially) update the lattice \\li{burn_in} times.\n\\begin{enumerate}\n    \\item Use Problem \\ref{prob:ising-flip-site} to choose a site for possibly flipping the spin, thus defining a potential new configuration $\\sigma^*$.\n    \\item Use Problem \\ref{prob:ising-new-energy} to calculate the energy $H(\\sigma^*)$ of the proposed configuration.\n    \\item Use Problem \\ref{prob:ising-acceptance} to accept or reject the proposed configuration.\n    If it is accepted, set $\\sigma = \\sigma^*$ by flipping the spin at the indicated site.\n    \\item Track $-\\beta H(\\sigma)$ at each iteration (independent of acceptance).\n\\end{enumerate}\nAfter the burn-in period, continue the iteration \\li{n_samples} times, also recording every $100$th sample (to prevent memory failure).\nThe acceptance rate is counted after the burn-in period.\nReturn the samples, the sequence of weighted energies $-\\beta H(\\sigma)$, and the acceptance rate.\n\nTest your sampler on a $100 \\times 100$ grid with $200000$ total iterations, with \\li{n_samples} large enough so that you will keep $50$ samples, for $\\beta = 0.2, 0.4, 1$.\nPlot the proportional log probabilities, as well as a late sample from each test.\nHow does the ferromagnetic material behave differently with differing temperatures?\nRecall that $\\beta$ is an inverse function of temperature.\nYou should see more structure with lower temperature, as illustrated in Figure \\ref{fig:ising-results}.\n\nTo show the spin configuration, use \\li{plt.imshow(L,cmap='gray')}.\n\\end{problem}\n\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/beta0_2_logprobs.pdf}\n    \\caption{Proportional log probs when $\\beta = 0.2$.}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=.62\\textwidth]{figures/beta0_2.pdf}\n    \\caption{Spin configuration sample when $\\beta = 0.2$.}\n\\end{subfigure}\n\\\\\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/beta0_4_logprobs.pdf}\n    \\caption{Proportional log probs when $\\beta = 0.4$.}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=.62\\textwidth]{figures/beta0_4.pdf}\n        \\caption{Spin configuration sample when $\\beta = 0.4$.}\n\\end{subfigure}\n\\\\\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/beta1_logprobs.pdf}\n    \\caption{Proportional log probs when $\\beta = 1$.}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=.62\\textwidth]{figures/beta1.pdf}\n    \\caption{Spin configuration sample when $\\beta = 1$.}\n\\end{subfigure}\n\\caption{}\n\\label{fig:ising-results}\n\\end{figure}\n", "meta": {"hexsha": "9eee71b408371b5c8f777a5657452ad65d15e19c", "size": 22748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume3/Metropolis/Metropolis.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/Metropolis/Metropolis.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/Metropolis/Metropolis.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": 59.8631578947, "max_line_length": 647, "alphanum_fraction": 0.7256901706, "num_tokens": 6260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6932358449246644}}
{"text": "% Appendix A\n\n\\chapter{Quaternions}\n\\label{ch:app:quaternions} \nQuaternions are a number systems that extends complex numbers introduced by William Rowan Hamilton in 1843. They are commonly represented in the form\n\\[ q = w + x\\mathbf{i} + y\\mathbf{j} + z\\mathbf{k} \\]\nwhere $ \\mathbf{i},\\ \\mathbf{j}\\ and\\ \\mathbf{k} $ are the fundamental quaternion units.\nMultiplications between quaternions are non-commutative, with\n\\begin{table}[]\n\t\\centering\n\t\\caption{My caption}\n\t\\label{my-label}\n\t\\begin{tabular}{|l|l|}\n\t\t\\hline\n\t\t\\[ \\mathbf{j} x \\mathbf{k} = \\mathbf{i} \\] & \\[ \\mathbf{j} x \\mathbf{k} = \\mathbf{i} \\] \\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\n\\[ \\mathbf{i} x \\mathbf{1} = \\mathbf{i} \\]\n\\[ \\mathbf{i} x \\mathbf{i} = \\mathbf{-1} \\]\n\\[ \\mathbf{i} x \\mathbf{j} = \\mathbf{k} \\]\n\\[ \\mathbf{i} x \\mathbf{k} = \\mathbf{-j} \\]\n\n\n\n\\[ \\mathbf{k} x \\mathbf{1} = \\mathbf{i} \\]\n\\[ \\mathbf{k} x \\mathbf{i} = \\mathbf{i} \\]\n\\[ \\mathbf{k} x \\mathbf{j} = \\mathbf{i} \\]\n\\[ \\mathbf{k} x \\mathbf{k} = \\mathbf{i} \\]\n\n\n\\section{Rotations}\nNormal quaternions are\n", "meta": {"hexsha": "f6900fecd88841d855d9b11ef6730b65969d80fc", "size": 1042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Chapter0A.tex", "max_stars_repo_name": "fmr42/MasterThesis", "max_stars_repo_head_hexsha": "0ff0d2100d6547afb67af40c0f355bec1a3c9150", "max_stars_repo_licenses": ["MIT"], "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/Chapter0A.tex", "max_issues_repo_name": "fmr42/MasterThesis", "max_issues_repo_head_hexsha": "0ff0d2100d6547afb67af40c0f355bec1a3c9150", "max_issues_repo_licenses": ["MIT"], "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/Chapter0A.tex", "max_forks_repo_name": "fmr42/MasterThesis", "max_forks_repo_head_hexsha": "0ff0d2100d6547afb67af40c0f355bec1a3c9150", "max_forks_repo_licenses": ["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.6470588235, "max_line_length": 149, "alphanum_fraction": 0.6333973129, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6932279658886799}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[usenames]{color} %used for font color\n\\usepackage{amssymb} %maths\n\\usepackage{amsmath} %maths\n\\usepackage[utf8]{inputenc} %useful to type directly diacritic characters\n\\usepackage{graphicx}\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\n\\author{Tianshuang (Ethan) Qiu}\n\\begin{document}\n\\title{Math 74, Week 3}\n\\maketitle\n\n\\section{Wed Lec, 1a}\nProve that $\\binom{n}{k} + \\binom{n}{k+1} = \\binom{n+1}{k+1}$\n\\subsection{algebraic}\nWe first expand the expression:\n$$LHS = \\frac{n!}{(n-k)!k!} + \\frac{n!}{(n-k-1)!(k+1)!}$$\nThen we simplify:\n$$LHS = \\frac{n!}{(n-k)(n-k-1)!k!} + \\frac{n!}{(k+1)(n-k-1)!k!}$$\n$$LHS = \\frac{(n!(k+1))+(n!(n-k))}{(n-k)(k+1)(n-k-1)!k!} $$\n$$LHS = \\frac{n!(n+1)}{(k+1)!(n-k)!} $$\n$$LHS = \\frac{(n+1)!}{(k+1)!(n-k)!}$$\nNow we expand the right side:\n$$RHS = \\frac{(n+1)!}{(k+1)!(n-k)!}$$\nWe see thatt RHS = LHS.\n\\newline\nQ.E.D.\n\n\\subsection{Combinatorial}\nThe right hand side calculates the number of bitstrings of length $n+1$ with $k+1$ 0's. Since each bit can either end in $0$ or $1$, we can split them into different cases.\n\\newline\nIf the the last is $0$, there are $k$ 0's left in the substring of length $n$. So to calculate this, we use $\\binom{n}{k}$.\n\\newline\nIf the last bit is $1$, there are still $k+1$ 0's left in the substring before it. Using the formula, we get $\\binom {n}{k+1}$\n\\newline\nAdding them together equals the right hand side. They are evaluating the same thing.\n\\newline\nQ.E.D.\n\n\\section{Wed Lec, 4b}\nLet people be the pigeons and each letter is a different hole.\n\\newline\nNumber of pigeons = number of names = 33\n\\newline\nNumber of holes = number of letters = 30\n\\newline\nSince the amount of pigeons is greater than the amount of holes, some hole must have at least 2 pigeons by PHP. Therefore some ending letter must be shared by at least 2 names.\n\n\\section{Wed Lec, 5}\n\n\\subsection{a}\nWe can form a segment from any two points. So the total amount of segments is $\\binom{50}{2} = \\frac{50!}{2!48!}=1225$\n\n\\subsection{b}\nSince no three points are co-linear, we can choose any 3 points to form a triangle. So the total amount is $\\binom{50}{3} = \\frac{50!}{3!47!} = 19600$\n\n\\subsection{c}\nSimilar to part (b), we choose any 4 points to form a quadrilateral. The total amount is $\\binom {50} {4} = \\frac{50!}{46!4!} = 230300$.\n\n\\newpage\n\n\\section{Wed Dis, 2}\nSince the three books needs to be next to each other in the specified order, we can think of it as if the three are \"glued together\" into one book. So essentially we are looking for the amount of ways to arrange 5 books.\n\\newline\nThere are 5 ways to choose the first one, 4 for the second, ..., for a total of $5! = 120$ ways to arrange it.\n\n\\section{Wed Dis, 4}\nWe are looking for the amount of ways to rearrange \"GAUSS\". Since there are 5 letters, we have $5!=120$. Then we remove the ways that we over count the repeat \"S\". $\\frac{5!}{2!} = 60$\n\\newline\nSimilarly, for \"RAMANUJAN\", we take all possible permutations and divide by repeating letters \"A\" and \"N\"$: \\frac{9!}{3!2!} = 30240$\n\n\\newpage\n\n\\section{Fri Lec, 1b}\n\\subsection{Combinatorial}\nRHS is the number of ways to choose a team and a captain out of $n$ people: choose the captain first, then choose the rest of the team (each member can either be chosen or not): $n \\times 2^{n-1}$\n\\newline\nLHS chooses the team first, then chooses the captain. There are $\\binom{n}{k}$ ways to choose $k$ people from $n$ to form a team. Then, from that team there are $k$ ways to pick a captain. Finally we sum up all possible number of team size (from 0 to n): $\\sum_{k=0}^{n}k\\binom{n}{k}$\n\\newline\nRHS = LHS, Q.E.D.\n\n\n\\section{Fri Lec, 4}\nLet the $n$ students be our pigeons, and the friends they have be $f$, so $f$ would be the holes. $0 \\leq f \\leq n-1$\n\\newline\nCase 1: if someone has $0$ friends, then there cannot be anyone with $n-1$ friends. If there is a person who is not friends with anyone, and since friendships are mutual, then there cannot be anyone who is friends with everyone. In this case $0 \\leq f < n-1$. There are $n-1$ holes, $n > n-1$. By PHP there must be 2 people with the same amount of friends.\n\\newline\nCase 2: otherwise, $0 < f \\leq n-1$. Once again there are $n-1$ holes, by PHP there must be 2 people with the same amount of friends.\n\\newline\nQ.E.D.\n\n\n\\end{document}\n", "meta": {"hexsha": "dbac07b2c343104757f710fbdb0b9949898e98d3", "size": 4524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week3/main.tex", "max_stars_repo_name": "TianshuangQiu/Math74-Homework", "max_stars_repo_head_hexsha": "89f1c999b9744af6062185ab91834887a81ca3d5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week3/main.tex", "max_issues_repo_name": "TianshuangQiu/Math74-Homework", "max_issues_repo_head_hexsha": "89f1c999b9744af6062185ab91834887a81ca3d5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week3/main.tex", "max_forks_repo_name": "TianshuangQiu/Math74-Homework", "max_forks_repo_head_hexsha": "89f1c999b9744af6062185ab91834887a81ca3d5", "max_forks_repo_licenses": ["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.9223300971, "max_line_length": 356, "alphanum_fraction": 0.6934129089, "num_tokens": 1520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925404, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.6932046177197922}}
{"text": "\n\\chapter{GPU programs for Fourier pseudospectral simulations of the Navier-Stokes, Cubic Nonlinear Schr\\\"{o}dinger and sine Gordon equations}\n\nThis section includes the programs taken from a conference paper by Cloutier, Muite and Rigge~\\cite{CloMuiRig12}. The main purpose is to give example programs which show how to use graphics processing units (GPUs) to solve partial differential equations using Fourier methods. For further background on GPUs and programming models for GPUs see Cloutier, Muite and Rigge~\\cite{CloMuiRig12}. It should be noted that the algorithms used for the sine Gordon equation are very similar to those for the Klein Gordon equation discussed elsewhere in this tutorial. For consistency with the rest of the tutorial, programs using CUDA Fortran and OpenACC extensions to Fortran are included. GPUs enable acceleration of Fourier pseudospectral codes by factors of 10 compared to OpenMP parallelizations on a single 8 core node.\n\n\\section{2D Navier Stokes Equations}\n\nThese programs use the Crank-Nicolson method.\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dNsCUF,caption={A CUDA Fortran program to solve the 2D Navier-Stokes equations.}]{./SingleGPU/Programs/NS/GPUcuf/navierstokes.cuf}\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dNsACC,caption={An OpenACC  Fortran program to solve the 2D Navier-Stokes equations.}]{./SingleGPU/Programs/NS/GPUacc/navierstokes.f90}\n\n\\section{2D Cubic Nonlinear Schr\\\"{o}dinger Equations}\n\nThese programs use splitting.\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dNlsCUF,caption={A CUDA Fortran program to solve the 2D Nonlinear Schr\\\"{o}dinger equation.}]{./SingleGPU/Programs/NLS/GPUcuf/cubicNLS.cuf}\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dNlsACC,caption={An OpenACC  Fortran program to solve the  2D Nonlinear Schr\\\"{o}dinger equation.}]{./SingleGPU/Programs/NLS/GPUacc/cubicNLS.f90}\n\n\n\\section{2D sine-Gordon Equations}\n\nThese programs use a semi-explicit method that is similar to that used for the Klein-Gordon equation. Only the main program is included here, and the auxiliary subroutines can be downloaded from Cloutier, Muite and Rigge~\\cite{CloMuiRig12}\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dSgCUF,caption={A CUDA Fortran program to solve the 2D sine-Gordon equation.}]{./SingleGPU/Programs/sineGordon/GPUcuf/sgsemiimp2d.cuf}\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dSgACC,caption={An OpenACC  Fortran program to solve the  2D sine-Gordon equation.}]{./SingleGPU/Programs/sineGordon/GPUacc/sgsemiimp2d.f90}\n\n", "meta": {"hexsha": "dc54717e7ece6d3051be7b02fe5a020a5b4ee03d", "size": 2653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SingleGPU/SingleGPU.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": "SingleGPU/SingleGPU.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": "SingleGPU/SingleGPU.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": 85.5806451613, "max_line_length": 814, "alphanum_fraction": 0.8179419525, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6931505363146367}}
{"text": "\\section{Sylvester's Law, Sesquilinear Forms}\r\nWe start by looking at some immediate corollaries of \\ref{bilinear_diag}.\r\n\\begin{corollary}\r\n    For a finite dimensional complex vector space $V$ and a symmetric bilinear form $\\phi$ on $V$, there is a basis $B$ of $V$ such that\r\n    $$[\\phi]_B=\\begin{pmatrix}\r\n        I_r&0\\\\\r\n        0&0\r\n    \\end{pmatrix}$$\r\n    where $r=r(\\phi)$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Square roots always exist as $F=\\mathbb C$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Every symmetric matrix in $\\mathbb C$ is congruent to a unique matrix of the form\r\n    $$\\begin{pmatrix}\r\n        I_r&0\\\\\r\n        0&0\r\n    \\end{pmatrix}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $F=\\mathbb R$, $\\dim V=n<\\infty$ and $\\phi$ a symmetric bilinear form of $V$, then there exists a basis $\\{v_1,\\ldots,v_n\\}$ of $V$ such that\r\n    $$\\begin{pmatrix}\r\n        I_p&&\\\\\r\n        &-I_q&\\\\\r\n        &&0\r\n    \\end{pmatrix}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Every positive number in $\\mathbb R$ has a square root.\r\n\\end{proof}\r\n\\begin{definition}\r\n    $s(\\phi)=p-q$ is called the signature of the real symmetric bilinear form $\\phi$.\r\n\\end{definition}\r\nTo see it is well-defined,\r\n\\begin{theorem}[Sylvester's Law of Inertia].\r\n    If a real symmetric bilinear form $\\phi$ has\r\n    $$[\\phi]_B=\\begin{pmatrix}\r\n        I_p&&\\\\\r\n        &-I_q&\\\\\r\n        &&0\r\n    \\end{pmatrix},[\\phi]_{B'}=\\begin{pmatrix}\r\n        I_{p'}&&\\\\\r\n        &-I_{q'}&\\\\\r\n        &&0\r\n    \\end{pmatrix}$$\r\n    then $p=p',q=q'$.\r\n\\end{theorem}\r\n\\begin{definition}\r\n    Let $\\phi$ be a real symmetric bilinear form.\r\n    We say that $\\phi$is positive semidefinite if $\\phi(u,u)\\ge 0$ for any $u\\in V$, and is positive definite if $\\phi(u,u)>0$ for any $u\\in V\\setminus\\{0\\}$.\r\n    Similarly, $\\phi$ is positive semidefinite if $\\forall u\\in V,\\phi(u,u)\\le 0$ for any $u\\in V$, and negative definite if $\\forall u\\in V\\setminus\\{0\\},\\phi(u,u)<0$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The matrix\r\n    $$\\begin{pmatrix}\r\n        I_p&0\\\\\r\n        0&0\r\n    \\end{pmatrix}\\in M_n(\\mathbb R)$$\r\n    is always positive semidefinite, and is positive definite iff $p=n$.\r\n\\end{example}\r\n\\begin{proof}\r\n    Indeed $p$ is the largest dimension of subspace of $V$ in which $\\phi$ is positive definite.\r\n    Similarly $q$ is the largest dimension of a subspace in which $q$ is negative definite.\r\n    These descriptions are independent of the choice of basis, so we are done\r\n\\end{proof}\r\n\\begin{definition}\r\n    The kernel of the bilinear form $\\phi:V\\times V\\to F$ is the set $K(\\phi)=\\{v\\in V:\\forall u\\in V,\\phi(u,v)=0\\}$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. $\\dim K+r(\\phi)=0$.\\\\\r\n    2. For $F=\\mathbb R$, we now know from the preceding theorem that there is a subspace $T$ of dimension $n-(p+q)+\\min{p,q}$ such that $\\phi|_T=0$.\r\n    More over, this can easily be shown to be the largest dimension such that such a subspace $T$ exists.\r\n\\end{remark}\r\nRecall that the standard inner product on $\\mathbb C^n$, that is\r\n$$\\langle x,y\\rangle=\\sum_{i=1}^nx_i\\bar{y}_i$$\r\nis not a bilinear form.\r\n\\begin{definition}\r\n    Let $V,W$ be vector spaces over $\\mathbb C$.\r\n    A map $\\phi:V\\times W\\to\\mathbb C$ is a sesquilinear form if for any $w\\in W$, $\\phi(\\cdot,w)$ is linear and for any $v\\in V,\\lambda_1,\\lambda_2\\in \\mathbb C,w_1,w_2\\in W$,\r\n    $$\\phi(v,\\lambda_1w_1+\\lambda_2w_2)=\\bar{\\lambda}_1\\phi(v,w_1)+\\bar\\lambda_2\\phi(v,w_2)$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    With notation as above, for bases $B=\\{v_1,\\ldots,v_m\\}$ of $V$ and $C=\\{w_1,\\ldots,w_n\\}$ of $W$, the matrix of $\\phi$ is $(\\phi]_{B,C})_{ij}=(\\phi(v_i,w_j))$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    $\\phi(v,w)=[u]_B^\\top [\\phi]_{B,C}\\overline{[v]}_C$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Expand.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    If $B,B'$ are bases of $V$ and $C,C'$ of $W$ and $P=[\\operatorname{id}_V]_{B',B},Q=[\\operatorname{id}_W]_{C',C}$, then $[\\phi]_{B',C'}=P^\\top[\\phi]_{B,C}\\bar{Q}$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Analogous to the bilinear case.\r\n\\end{proof}", "meta": {"hexsha": "e46827a19949d5960b5d14baf35880eb0e0c0d6e", "size": 4073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "19/sylvester.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": "19/sylvester.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": "19/sylvester.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.73, "max_line_length": 177, "alphanum_fraction": 0.619936165, "num_tokens": 1410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8856314753275019, "lm_q1q2_score": 0.69315052591857}}
{"text": "\n\\subsection{Remainders}\n\nDivision is defined between natural numbers. However there are many cases where this division does not map to a natural number. For example:\n\n\\(\\dfrac{7}{3}\\)\n\nWe can divide \\(6\\) of the \\(7\\) by \\(3\\), giving \\(2\\) with \\(1\\) remaining.\n\nAlternatively we can divide \\(3\\) of the \\(7\\) by \\(3\\), giving \\(1\\) with \\(4\\) remaining\n\nOr we could divide \\(0\\) of the \\(7\\) by \\(3\\) giving \\(0\\) with \\(7\\) remaining.\n\nThe remainder refers to the lowest possible number - in this case \\(1\\).\n\n", "meta": {"hexsha": "05cfc825e32f1ec6b999379cfc24ab41907a6d9b", "size": 514, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/modulus/01-01-remainder.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/modulus/01-01-remainder.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/modulus/01-01-remainder.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.125, "max_line_length": 140, "alphanum_fraction": 0.6595330739, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6931505200121516}}
{"text": "\\section{Divisibility}\n\n\\frame{\n{Part 1: Divisibility}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-5}]\n}\n\n\\subsection{Definitions}\n\n\\begin{frame}\n  \\frametitle{Talking about Division}\n\n  How should we define the \\emph{divide} operation on integers?\\bigskip\n\n  Consider $a/b$, for $a,b \\in \\mathbb{N}$ and $b > 0$. We have:\n  \\bigskip\n\n  \\begin{itemize}\n  \\item q = quotient(a,b)\n  \\item r = remainder(a,b)\n  \\end{itemize}\n\n  \\bigskip\n\n  The {\\bf Division Theorem} says that $\\exists$ {\\bf unique} $q$ and $r$ in $\\mathbb{N}$ such as\n  \\begin{equation*}\n    a = bq + r, 0 \\leq r < b\n  \\end{equation*}\\bigskip\n\n  {\\bf Example}: $16/3: a = 16, b = 3, q = 5, r = 1$;\\hspace{1cm} $16 = 3\\times 5 + 1$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Divisibility}\n\n  We say that $c$ {\\bf divides} $a (c|a)$ {\\bf iff}\n    \\begin{equation*}\n      \\exists k \\in \\mathbb{N}, a = k\\times c.\n    \\end{equation*}\n    \\begin{center}\n      $c$ divides $a$ if there is a number $k$ where $a$ equals $c$ times $k$.\n    \\end{center}\n\n  \\bigskip\n\n  \\begin{itemize}\n  \\item $5 | 15$ because $15 = 3 \\times 5$\n  \\item $n | 0$ because $0 = 0 \\times n$ \\hspace{1cm} every number divides 0\n  \\item $1 | n$ because $n = n \\times 1$ \\hspace{1cm} 1 divides every number\n  \\end{itemize}\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}{Implications of Divisibility (1/2)}\n\n  \\begin{block}{Lemma 1: $c|a \\implies c|(sa)$}\n    If $c$ divides $a$, then $c$ divides all multiples of $a$. {\\bf Miniproof}: Multiply both sides by $s$:\n    \\begin{itemize}\n      \\item $a = kc$\\hfill Definition of divisibility\n      \\item $sa = skc$\\hfill Multiplies both sides by $s$\n      \\item $(sa) = (sk)\\times c \\implies c|sa$\\qed\n    \\end{itemize}\n  \\end{block}\n\n  \\begin{block}{Lemma 2: $c|a \\land c|b \\implies c|(a+b)$}\n    If $c$ divides $a$ and $b$, then $c$ divides $a+b$. {\\bf Miniproof}: Distributive property of multiplication:\n    \\begin{itemize}\n      \\item $a = k_1c, b = k_2c$\\hfill Definition of divisibility\n      \\item $a+b = k_1c + k_2c$\\hfill Adding both equations together\n      \\item $(a+b) = (k_1+k_2)c \\implies c|(a+b)$\\qed\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n\n\\begin{frame}[t]{Implication of Divisibility (2/2)}\n\n  \\begin{block}{$c|a \\land c|b \\implies c | (sa+tb)$}\n    If $c$ divides $a$ and $b$, then $c$ divides all \\alert{linear combinations} of $a$ and $b$.\\\\\n    {\\bf This one is pretty important.}\n  \\end{block}\n  Try to solve it by yourself first:\\bigskip\n\n  \\begin{onlyenv}<2>\n  \\begin{itemize}\n    \\item Lemma 1: $c|a \\implies c|ka$ for any $k$.\\medskip\n    \\item Collorary: $c|a \\land c|b \\implies c|sa \\land c|tb$\\medskip\n    \\item Lemma 2: $c|a \\land c|b \\implies c|(a+b)$.\\medskip\n    \\item Collorary: $c|sa \\land c|tb \\implies c|(sa+tb)$\\qed\n  \\end{itemize}\n  \\end{onlyenv}\n\\end{frame}\n\n\\subsection{Common Divisors}\n\n\\begin{frame}\n  \\frametitle{Common Divisors}\n\n    If $c|a$ and $c|b$, we say that c is a \\structure{common divisor} of $a$ and $b$.\\bigskip\n\n    As we saw in the last slide, a common divisor of $a$ and $b$ will also divide the linear combinations of $a$ and $b$:\n    \\begin{equation*}\n      c|a \\land c|b \\implies \\forall s,t\\in\\mathbb{N}, c|(sa+tb)\n    \\end{equation*}\\bigskip\n\n    In the next section, let's talk in more details about $c$, $s$ and $t$.\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "55eebdbaa0a2bd2e3a9f7a3239b3220bd41abfc9", "size": 3379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week03/01_Divisibility.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/01_Divisibility.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/01_Divisibility.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": 30.1696428571, "max_line_length": 121, "alphanum_fraction": 0.6111275525, "num_tokens": 1239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624738835052, "lm_q2_score": 0.8856314723088733, "lm_q1q2_score": 0.6931505190663538}}
{"text": "\\subsection{Model fitting}\n\\label{subsec:fitting}\nWe employed a Markov Chain Monte Carlo (MCMC), using \\texttt{emcee} \\parencite{2013PASP..125..306F}, to fit the coefficients of a polynomial model for $r(\\mathcal{M}_c)$. The MCMC uses the smoothing prior as defined in \\S\\ref{subsec:likelihood}. We performed a least squares fit first in order to obtain the initial guess for the coefficients of the model.\n\nThe model we used is a polynomial of degree 9. Because of the smoothing function, using higher order does not change the shape of the fit in a significant way. The MCMC best fit can be seen in Figure \\ref{fig:line_MCMC}. The MCMC walkers and triangle plot are in Figures \\ref{fig:MCMC_time} and \\ref{fig:MCMC_triangle}.\n\nThe best fit model is\n%\n\\begin{equation}\n  r(\\mathcal{M}_c) = \\sum_{k = 0}^{9}\\alpha_k(\\log\\mathcal{M}_c)^k,\n%\n  \\label{MCMC_best_fit}\n\\end{equation}\n%\nwhere the coefficients, $\\alpha_k$, are listed in Table \\ref{table:coefficients}.\n\n\\begin{table}[ht]\n\\centering\n\\caption{Coefficients from the MCMC fit.}\n\\label{table:coefficients}\n\n\\begin{tabular}{l|r}\n  k & $\\alpha_k$ \\\\\n  \\hline\n  \\hline\n  0 & \\num{-1.903e-06} \\\\\n  1 & \\num{+1.842e-05} \\\\\n  2 & \\num{+9.999e-01} \\\\\n  3 & \\num{+1.748e-04} \\\\\n  4 & \\num{-2.441e-04} \\\\\n  5 & \\num{+2.122e-04} \\\\\n  6 & \\num{-1.130e-04} \\\\\n  7 & \\num{+3.470e-05} \\\\\n  8 & \\num{-5.416e-06} \\\\\n  9 & \\num{+3.470e-07} \\\\\n\\end{tabular}\n\\end{table}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/line-MCMC.pdf}\n  \\caption{The cyan line is an example of a fit from MCMC.}\n  \\label{fig:line_MCMC}\n\\end{figure*}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/line-mcmc_err.pdf}\n  \\caption{2000 randomly chosen fits from the MCMC.}\n  \\label{fig:line_MCMC_err}\n\\end{figure*}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/line-time-1.pdf}\n  \\caption{Visualization of MCMC worker locations over the large number of iterations performed for coefficients $\\lambda_0 $ to $\\lambda_4$. }\n  \\label{fig:MCMC_time}\n\\end{figure*}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/line-time-2.pdf}\n  \\caption{Visualization of MCMC worker locations over the large number of iterations performed for coefficients $\\lambda_5$ to $\\lambda_9$.}\n  \\label{fig:MCMC_time}\n\\end{figure*}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/line-triangle.pdf}\n  \\caption{Corner plot of MCMC fit coefficients.}\n  \\label{fig:MCMC_triangle}\n\\end{figure*}\n\n", "meta": {"hexsha": "99cc936f7dd847a584bea27fb3621ada77d73464", "size": 2453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "subsec_fitting.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": "subsec_fitting.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": "subsec_fitting.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": 35.5507246377, "max_line_length": 356, "alphanum_fraction": 0.7093355075, "num_tokens": 838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6931505155225028}}
{"text": "\\section{Deep Residual Networks - ResNet}\nDeep convolutional neural networks is today used to produce the best results on the ImageNet dataset, and this reveals that the depth of the networks is of high importance for the performance of the networks\\citep{RESNET}. Some of the leading results on the ImageNet dataset have models with a depth of 16 to 30 layers. The real question is, if learning better networks is as easy as having more layers in the network?\n\n\\myFigure{plain_network}{Results from two networks run on the CIFAR-10 dataset with 20 and 56 layers \\citep{RESNET}}{fig:plain}{1}\n\nOn figure \\ref{fig:plain} it is shown that a convolutional neural network with 20 layers achieves a better performance than a network with 56 layers. A reason why the 56-layer network is bad could be the vanishing / exploding gradients problem, which hamper convergence from the beginning of the training. This problem can be solved by normalized initialization and intermediate normalization layers, which will make the network start converging. After solving this problem the deeper networks will be able to converge, but here a degradation problem might occur, meaning that with the network depth increasing the accuracy gets saturated. the degradation problem is also shown on figure \\ref{fig:plain}. To solve this problem a deep residual network can be used.\n\n\\myFigure{res_block}{A residual building block. \\citep{RESNET}}{fig:resblock}{0.5}\n\nFigure \\ref{fig:resblock} shows a residual learning building block. In a residual neural network the underlying layers are fit a residual mapping. The underlying mapping is referred to as \\emph{H(x)}, where the nonlinear layers fit a mapping of \\emph{F(x) = H(x) - x}. The original mapping is represented as \\emph{F(x) + x}, where this mapping can be realized by feed forward neural networks with shortcut connections. Shortcut connections are connections which takes the input \\emph{x} and skips it forward to the output of the stacked layers, as seen in figure \\ref{fig:resblock}, this is also called identity mapping. The shortcut connections does not add extra complexity to the network. Each residual building block can be defined as:\n\n\\begin{equation} \\label{eq:res}\ny = F(x, {Wi}) + x\n\\end{equation} \n\nIn equation \\ref{eq:res}, x and y are the input and output vectors of the layers in the building block. The $F(x,{Wi})$ function represents the residual mapping to be learned throughout the layers. By using figure \\ref{fig:resblock} as a building block, the following function will be used for the two layers: \n\n\\begin{equation} \\label{eq:func_res}\nF = W2\\sigma(W1x)\n\\end{equation} \n\nIn equation \\ref{eq:func_res}, $\\sigma$ is the ReLU activation function, while W2 and W1 is the weights for each layer. The shortcut connections added in equation \\ref{eq:res} does not introduce any extra parameters or computation complexity. This is good for the comparison between plain and residual networks, as two networks can be compared easily as they have the same amount of parameters, depth, width and computational cost.\n\\newline\n\nOn figure \\ref{fig:plainvsres} the first layers of a plain and a residual network is shown. The plain network consist of convolutional layers with a 3x3 filter. When the output feature maps are the same size, the layers have the same amount of filters. If the size of the feature map is divided by two, the filters will be multiplied with two, and this will preserve the time complexity per layer. Downscaling is performed by convolutional layers that have a stride 2.\n\n\\myFigure{plain_vs_res}{The left shows the first layers of a plain 34-layer network. The right shows the same layers from a 34-layer residual network. \\citep{RESNET}}{fig:plainvsres}{0.5}\n\\FloatBarrier\n\nThe difference from the plain network to the residual network architecture is the shortcut connections. When the input and the output of the layers are of the same dimensions the identity shortcuts can be used directly, this is shown on figure \\ref{fig:plainvsres} by the solid lines going from input to output. When the dimensions between input and output increase the dotted line is used in figure \\ref{fig:plainvsres}. Two solutions exist to the shortcut connections between two different input and output dimensions. The first solution is to pad extra zeros to the input image, to achieve the same dimension as the output image. This solution does not add any extra paramters to equation \\ref{eq:res}. Another solution is to use a projection shortcut which is used to match the dimensions between input and ouput done by 1x1 convolutions. Adding the projection shortcut gives the equation shown in equation \\ref{eq:func_proj}, where Ws is added to the equation.\n\n\\begin{equation} \\label{eq:func_proj}\ny = F(x, {Wi}) + Wsx.\n\\end{equation} ", "meta": {"hexsha": "630e18a47ead739bcff3a5c1796002e75ae1500f", "size": 4793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/ResNet.tex", "max_stars_repo_name": "Rotvig/cs231n", "max_stars_repo_head_hexsha": "a25aef7f8675eca930fc5cf651409edbcc35c6e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-11T12:30:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-11T12:30:50.000Z", "max_issues_repo_path": "Report/chapter/ResNet.tex", "max_issues_repo_name": "Rotvig/cs231n", "max_issues_repo_head_hexsha": "a25aef7f8675eca930fc5cf651409edbcc35c6e2", "max_issues_repo_licenses": ["MIT"], "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/ResNet.tex", "max_forks_repo_name": "Rotvig/cs231n", "max_forks_repo_head_hexsha": "a25aef7f8675eca930fc5cf651409edbcc35c6e2", "max_forks_repo_licenses": ["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.9705882353, "max_line_length": 965, "alphanum_fraction": 0.7924055915, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6931342746152365}}
{"text": "\\section{Regularized Dual Averaging}\nIn this section, we generalize the dual averaging method (\\ref{generalized_dual_averaging}) to deal\nwith composite optimization problems, i.e. problems of the form\n\\begin{equation}\\label{composite_optimization}\n\\arg\\min_x \\left[f(x) = F(x) + G(x)\\right] \n\\end{equation}\nwhere $F$ is a convex, Lipschitz function and $G$ is a convex function for which we can efficiently solve the proximal,\nor backward step\n\\begin{equation}\\label{prox_regularlized_dual_averaging}\n P_{\\lambda G}(x) = \\arg\\min_{y} \\frac{1}{2}\\|y - x\\|_2^2 + \\lambda G(y)\n\\end{equation}\nTwo very common choices for $G$ are the indicator function of a convex set $A$\n\\begin{equation}\n G(x) = i_A(x) = \n \\begin{cases}\n                    0 &~ \\text{if $x\\in A$} \\\\\n\t\t    +\\infty &~ \\text{if $x\\notin A$}\n \\end{cases}\n\\end{equation}\nand the l$1$-norm $G(x) = \\|x\\|_1$. In the former case, the proximal map is just a projection onto the set $A$ and\nwe obtain methods for solving constrained optimization problems. In the latter case, the\nproximal map is called soft-thresholding and can be given in closed form.\n\nIt is important to note that the methods we will derive for the composite problem (\\ref{composite_optimization})\nhave convergence rates which only depend upon the Lipschitz constant of $F$. This is where the drastic improvement\nlies, since often $G$ will not be Lipschitz at all, for instance $G = i_A$, or the Lipschitz constant of $G$ \nwill be very large, for instance $G = \\|\\cdot\\|_1$.\n\nTo derive the regularized dual averaging methods, we begin by noting that if $g_i\\in \\partial F(x_i)$, then\n$$ F(x_i) + \\langle g_i, x - x_i\\rangle + G(x)\n$$\nis a lower bound for $f(x)$. Substituting this lower bound into the dual averaging iteration (\\ref{generalized_dual_averaging}),\nwe arrive at the following iteration\n\\begin{equation}\\label{naive_regularized_dual_averaging}\n x_{n+1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^n \\langle s_ig_i, x\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x\\|_2^2 + \\gamma_{n+1} G(x)\\right)\n\\end{equation}\nwhere $\\gamma_{n + 1} = \\sum_{i = 1}^n s_i$.\n\nBefore we proceed, it is useful to write out the iteration (\\ref{naive_regularized_dual_averaging}) in two steps by completing the\nsquare\n\\begin{equation}\n x_{n+\\frac{1}{2}} = -\\frac{1}{\\alpha_{n+1}}\\displaystyle\\sum_{i = 1}^n s_ig_i,~x_{n+1} = P_{(\\gamma_{n+1}/\\alpha_{n+1})G}(x_{n+\\frac{1}{2}})\n\\end{equation}\nWe note that the second, i.e. proximal, step above means that\n$$h_{n+1}:=\\frac{\\alpha_{n+1}}{\\gamma_{n+1}}(x_{n+\\frac{1}{2}} - x_{n+1})\\in \\partial G(x_{n+1})\n$$\nSo in the process of computing the minimizer in (\\ref{naive_regularized_dual_averaging}) we obtain an element\nof $\\partial G(x_{n+1})$ as a byproduct. We can use this element to lower bound $f$ in a different way, namely by\n$$ F(x_i) + \\langle g_i, x - x_i\\rangle + f_i(G(x_i) + \\langle h_i, x - x_i\\rangle) + (1 - f_i)G(x)\n$$\nwhere $0 \\leq f_i$. Here we have replaced a fraction $f_i$ of the bound $G(x)$ by its linear lower bound\nbased on $h_i\\in \\partial G(x_i)$. Writing $t_i = s_if_i$, this leads to the following method\n\\begin{equation}\\label{argmin_formulation_generalized_RDA}\n x_{n+1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^n \\langle s_ig_i + t_ih_i, x\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x\\|_2^2 + \\gamma_{n+1} G(x)\\right)\n\\end{equation}\ni.e.\n\\begin{align}\\label{first_attempt_iteration}\n x_{n+\\frac{1}{2}} = -\\frac{1}{\\alpha_{n+1}}\\displaystyle\\sum_{i = 1}^n &s_ig_i + t_ih_i = \\frac{\\alpha_n}{\\alpha_{n+1}}x_{n-\\frac{1}{2}} - \\frac{s_ng_n + t_nh_n}{\\alpha_{n+1}}\\\\\n x_{n+1} &= P_{(\\gamma_{n+1}/\\alpha_{n+1})G}(x_{n+\\frac{1}{2}})\n\\end{align}\nwhere $\\gamma_{n + 1} = \\sum_{i = 1}^n s_i-t_i$, $h_i = \\frac{\\alpha_{i}}{\\gamma_{i}}(x_{i-\\frac{1}{2}} - x_{i})$, and\n$g_i\\in \\partial f(x_i)$. Additionally, we must have $t_1 = 0$ since we don't have an element in the subdifferential\nof $G$ at $x_1$ (as $\\gamma_1 = 0$).\n\nBy utilizing the definition of $h_i$ in (\\ref{first_attempt_iteration}), we can rewrite this iteration in the following simpler way\n\\begin{align}\\label{generalized_RDA_iteration}\n &x_{n+\\frac{1}{2}} = \\frac{\\alpha_n}{\\alpha_{n+1}}\\left(\\frac{t_n}{\\gamma_n}x_n + \\left(1 - \\frac{t_n}{\\gamma_n}\\right)x_{n-\\frac{1}{2}}\\right) - \\frac{s_n}{\\alpha_{n+1}}g_n \\\\\n &x_{n+1} = \\arg\\min_x \\left(\\frac{1}{2}\\|x - x_{n+\\frac{1}{2}}\\|_2^2 + \\frac{\\gamma_{n+1}}{\\alpha_{n+1}}G(x)\\right)\n\\end{align}\n\nWe have the following convergence result for the generalized RDA method.\n\\begin{theorem}\n Assume that $F$ is convex and Lipschitz with parameter $M$ and let $x^*\\in \\arg\\min_x f(x)$. \n Then if $x_n$ is given by the iteration (\\ref{generalized_RDA_iteration})\n with $t_i\\leq \\gamma_i$, $\\alpha_i\\leq \\alpha_{i+1}$, and $s_{i+1}\\leq s_i$, then we have\n \\begin{align}\n  &f(\\bar{x}_n) - f(x^*) \\leq \\\\\n  &\\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1} \\left(\\alpha_n\\|x^*\\|_2^2 + M^2\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i} + s_1(G(x_1) - \\inf_x G(x))\\right)\n \\end{align}\n where $\\bar{x}_n = (\\sum_{i = 1}^n s_i)^{-1}\\sum_{i = 1}^n s_ix_i$ is a weighted average of the iterates with weights $s_i$.\n We also have\n \\begin{align}\n  &\\min_{i = 1,...,n} f(x_i) - f(x^*) \\leq \\\\\n  &\\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1}\\left(\\alpha_n\\|x^*\\|_2^2 + M^2\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i} + s_1(G(x_1) - \\inf_x G(x))\\right)\n \\end{align}\n\\end{theorem}\n\n\\begin{proof}\n  We begin by noting that by convexity we have\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1}\\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*))\n \\end{equation}\n and since the minimum is smaller than the average we have\n \\begin{equation}\n  \\min_{i = 1,...,n} f(x_i) - f(x^*) \\leq \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1}\\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*))\n \\end{equation}\n Thus it suffices to prove that\n \\begin{equation}\n \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) \\leq \n \\frac{1}{2}\\left(\\alpha_n\\|x^*\\|_2^2 + M^2\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\\right)+ s_1(G(x_1) - \\inf_x G(x))\n \\end{equation}\n For this we first use the subgradient property to get\n \\begin{align}\\label{eq_rda_100}\n  \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) &\\leq \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i + t_ih_i, x_i - x^*\\rangle \\\\\n  &+ \\displaystyle\\sum_{i = 1}^n (s_i - t_i)(G(x_i) - G(x^*))\n \\end{align}\n We now rewrite the first sum above as\n \\begin{align}\\label{eq_rda_105}\n  \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i + t_ih_i, x_i - x^*\\rangle &= \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i + t_ih_i, x_n - x^*\\rangle \\\\\n  &+ \\displaystyle\\sum_{i = 1}^{n-1} \\displaystyle\\sum_{j = 1}^i\\langle s_jg_j + t_jh_j, x_i - x_{i+1}\\rangle \n \\end{align}\n We proceed by bounding the term\n \\begin{equation}\n  \\sum_{j = 1}^i\\langle s_jg_j + t_jh_j, x_i - z\\rangle\n \\end{equation}\n Recall from (\\ref{argmin_formulation_generalized_RDA}) that $x_i = \\arg\\min_x f_i(x)$ where\n \\begin{equation}\n  f_i(x) = \\displaystyle\\sum_{j = 1}^{i-1} \\langle s_jg_j + t_jh_j, x\\rangle + \\frac{\\alpha_{i}}{2}\\|x\\|_2^2 + \\gamma_i G(x_i)\n \\end{equation}\n The definition of $h_i\\in \\partial G(x_i)$ means that\n \\begin{equation}\n  0 = \\alpha_i x_i + \\gamma_i h_i + \\displaystyle\\sum_{j = 1}^{i-1} s_jg_j + t_jh_j\n \\end{equation}\n This means that $0\\in \\partial f_i^\\prime(x_i)$ if we set \n $$f_i^\\prime(x) = f_i(x) + \\langle t_ih_i, x\\rangle - t_iG(x)\n $$\n Moreover, $f_i^\\prime$ is a strongly convex function with convexity parameter $\\alpha_i$ as long as $t_i\\leq \\gamma_i$.\n Now, define $f^{\\prime\\prime}_i(x) = f_i^\\prime(x) + \\langle s_ig_i, x\\rangle$. Then we have\n $s_ig_i\\in \\partial f^{\\prime\\prime}_i(x_i)$ and the strong convexity of $f^{\\prime\\prime}_i$ implies that\n \\begin{equation}\n  f^{\\prime\\prime}_i(x_i) \\leq f^{\\prime\\prime}_i(z) + \\frac{1}{2\\alpha_i}\\|s_ig_i\\|_2^2\n \\end{equation}\n Substituting in the definition of $f^{\\prime\\prime}_i$ and rearranging, we get\n \\begin{align}\n  \\sum_{j = 1}^i\\langle s_jg_j + t_jh_j, x_i - z\\rangle &\\leq \\frac{\\alpha_i}{2}(\\|z\\|_2^2 - \\|x_i\\|_2^2) + \\frac{s_i^2}{2\\alpha_i}\\|g_i\\|_2^2 \\\\\n  &+ (\\gamma_i - t_i)(G(z) - G(x_i))\n \\end{align}\n Plugging this bound into (\\ref{eq_rda_105}) with $z = x_{i+1}$ and $z = x^*$, recalling that \n $\\gamma_n = \\sum_{i = 1}^{n-1} s_i - t_i$, that $x_1 = 0$, $\\gamma_1 = t_1 = 0$, and that\n $\\|g_i\\|_2\\leq M$, and rearranging terms, we obtain\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n \\langle s_ig_i + t_ih_i, x_i - x^*\\rangle& \\leq \\frac{\\alpha_n}{2}\\|x^*\\|_2^2 \n  + \\frac{1}{2}\\displaystyle\\sum_{i = 2}^n (\\alpha_{i-1} - \\alpha_i)\\|x_i\\|_2^2 \\\\\n  &+ \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\n  + \\displaystyle\\sum_{i = 2}^n (t_i - s_{i-1})G(x_i)\n \\end{align}\n Plugging this bound into (\\ref{eq_rda_100}) we obtain\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) &\\leq \\frac{\\alpha_n}{2}\\|x^*\\|_2^2 \n  + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i} \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^n (\\alpha_{i-1} - \\alpha_i)\\|x_i\\|_2^2 \\\\\n  &+ s_1 G(x_1) - \\displaystyle\\sum_{i = 2}^n (s_{i-1} - s_i)G(x_i) - s_nG(x^*)\n \\end{align}\n Finally, we use the assumption that $\\alpha_{i-1} - \\alpha_i \\leq 0$ and that $s_{i-1} - s_i \\geq 0$ to conclude that\n $$\\frac{1}{2}\\displaystyle\\sum_{i = 2}^n (\\alpha_{i-1} - \\alpha_i)\\|x_i\\|_2^2 \\leq 0\n $$\n and\n $$s_1 G(x_1) - \\displaystyle\\sum_{i = 2}^n (s_{i-1} - s_i)G(x_i) - s_nG(x^*) \\leq s_1(G(x_1) - \\inf_x G(x))\n $$\n Finally, this yields\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n s_i(f(x_i) - f(x^*)) \\leq \\frac{\\alpha_n}{2}\\|x^*\\|_2^2 \n  + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{s_i^2}{\\alpha_i}\n  + s_1(G(x_1) - \\inf_x G(x))\n \\end{equation}\n which completes the proof.\n\n\\end{proof}\n\nWe begin by noting that the regularizer $\\|x\\|_2^2$ can be replaced by any strongly convex function. In particular,\nif we replace it by $\\|x - x_1\\|_2^2$, we are free to choose $x_1$ arbitrarily. This allows us to remove the\nannoying term $s_1(G(x_1) - \\inf_x G(x))$ from the bound in the above theorem, by simply choosing $x_1$ to be a minimizer\nof $G$.\n\nWe would also like to note two special cases of the above method. If we set $t_i = \\frac{1}{\\sqrt{i-1}}$ for $i > 1$,\n$s_i = \\frac{1}{\\sqrt{i}}$, and $\\alpha_i = 1$ (note that this means $\\gamma_i = t_i$), \nthen we recover forward-backward subgradient descent.\n\nAlso, if we set $t_i = 0$, $s_i = 1$, and $\\alpha_i = \\sqrt{n}$ (note that this means $\\gamma_i = i$), we recover the\noriginal version of RDA.\n", "meta": {"hexsha": "1c91e6e67ce62405c769678b18ec4490e94f9e22", "size": 10471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/RegularizedDualAveraging.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/RegularizedDualAveraging.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/RegularizedDualAveraging.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": 57.8508287293, "max_line_length": 178, "alphanum_fraction": 0.6584853405, "num_tokens": 4156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.6931342716061857}}
{"text": "\\chapter{Splines}\n\nThrough-out this section, the regression function $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{fdef}\nf(x) = \\E(Y|X=x), x \\in I \\subset \\mathbb{R}.\n\\end{equation}\nFor spline models, estimate definitions and their properties \nare more easily characterized in the context of linear spaces. \n\n\\input{section-04-01}\n\\input{section-04-02}\n\\input{section-04-03}\n\\input{section-04-04}\n\\input{references-04}\n", "meta": {"hexsha": "ba6f635dd29b1191d8b2e981540aa666de1d8618", "size": 598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-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-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-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": 31.4736842105, "max_line_length": 70, "alphanum_fraction": 0.7424749164, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6930894325135858}}
{"text": "\\section{Notes for myself}\n\nIt is possible to generate random numbers\nfor various distributions using unit rectangular\ngenerator, see e.g. \\cite[][p.196,197]{evans2000}:\n\n\\begin{quote}\nRandom numbers of the Weibull variate $W$: $\\gamma$,\n$\\eta$, $\\beta$ can be generated from the unit rectangular\nvariate $R$ using the relationship:\n\n\\begin{displaymath}\nW: \\gamma, \\eta, \\beta \\sim \\gamma + \n \\eta\n  \\left(\n   - \\log R\n  \\right)\n          ^ {1/\\beta}\n\\end{displaymath}\n\n\\end{quote}\n", "meta": {"hexsha": "dec5023d3f9dce991ea788b0a94ccce5810b7d18", "size": 482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/notes.tex", "max_stars_repo_name": "lcebaman/casup", "max_stars_repo_head_hexsha": "240f25f07d8ea713b9fbed9814d0ac56d0141f86", "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/notes.tex", "max_issues_repo_name": "lcebaman/casup", "max_issues_repo_head_hexsha": "240f25f07d8ea713b9fbed9814d0ac56d0141f86", "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/notes.tex", "max_forks_repo_name": "lcebaman/casup", "max_forks_repo_head_hexsha": "240f25f07d8ea713b9fbed9814d0ac56d0141f86", "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": 21.9090909091, "max_line_length": 58, "alphanum_fraction": 0.6887966805, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6930890509053815}}
{"text": "\\section{Homogeneous systems}\n\\label{sec:homogeneous-systems}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a homogeneous system of equations has\n    non-trivial solutions from its rank.\n  \\item Find the basic solutions of a homogeneous system of\n    equations.\n  \\item Understand the relationship between the general solution of a\n    system of equations and that of its associated homogeneous\n    system.\n  \\end{enumerate}\n\\end{outcome}\n\nThere is a special type of system of linear equations that requires\nadditional study. This type of system is called a {\\em\n  homogeneous}\\footnote{The word ``homogeneous'' has 5 syllables. In\n  scientific usage, it is not the same as the word\n  ``\\nospellcheck{\\homogenous}''.}  system of equations.  Our focus in\nthis section is to consider what types of solutions are possible for a\nhomogeneous system of equations, and how the solutions of\nnon-homogeneous systems are related to those of their homogeneous\ncounterparts.\n\n\\begin{definition}{Homogeneous system of equations}{homogeneous-system}\n  A system of equations is called\n  \\textbf{homogeneous}%\n  \\index{system of linear equations!homogeneous}%\n  \\index{homogeneous system}\n  if each of the constant terms is equal to $0$. A homogeneous system\n  therefore has the form\n  \\begin{equation*}\n    \\begin{array}{c}\n      a_{11}x_1 + a_{12}x_2 + \\ldots + a_{1n}x_n = 0 \\\\\n      a_{21}x_1 + a_{22}x_2 + \\ldots + a_{2n}x_n = 0  \\\\\n      \\vdots \\\\\n      a_{m1}x_1 + a_{m2}x_2 + \\ldots + a_{mn}x_n = 0,\n    \\end{array}\n  \\end{equation*}\n  where $a_{ij}$ are coefficients and $x_j$ are variables.\n\\end{definition}\n\nThe first thing we note is that a homogeneous system is always\nconsistent. Indeed, it always has the solution $x_1=0$, $x_2=0$,\n$\\ldots$, $x_n=0$. This solution is called the \\textbf{trivial\n  solution}%\n\\index{trivial solution}%\n\\index{solution!trivial}%\n\\index{system of linear equations!trivial solution}.\n\nIf the system has a solution in which not all of the $x_1,\\ldots, x_n$\nare equal to zero, then we call this solution \\textbf{non-trivial}%\n\\index{non-trivial solution}%\n\\index{solution!non-trivial}%\n\\index{system of linear equations!non-trivial solution}.  When working\nwith homogeneous systems of equations, since the trivial solution\nalways exists, we are usually interested in finding whether there are\nnon-trivial solutions.\n\nThe following theorem is a special case of\nTheorem~\\ref{thm:rank-consistent-solutions}. Recall that the {\\em\n  rank}%\n\\index{rank} of a system is the number of pivot variables in its\n{\\ef}.\n\n\\begin{theorem}{Rank and solutions of homogeneous system of equations}{rank-homogeneous-solutions}\n  Consider a homogeneous system of $m$ equations in $n$ variables, and\n  assume that the coefficient matrix has rank $r$. Then the system is\n  consistent, and\n  \\begin{enumerate}\n  \\item if $r=n$, then the system has only the trivial solution;\n  \\item if $r<n$, then the system has infinitely many solutions.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{example}{Homogeneous system with more variables than equations}{homo-more-variables}\n  True or false: Suppose a homogeneous system has more variables than\n  equations. Then the system has infinitely many solutions.\n\\end{example}\n\n\\begin{solution}\n  This is true. If the system has $m$ equations and $n$ variables,\n  then the rank can be at most $m$. Since $m<n$, the system has\n  infinitely many solutions. Note that it is not possible for a\n  homogeneous system to be inconsistent, since there is always the\n  trivial solution.\n\\end{solution}\n\n\\begin{example}{Homogeneous system with an equal number of variables and equations}{homo-less-variables}\n  True or false: Suppose a homogeneous system has the same number of\n  variables as equations. Then the system has a unique solution.\n\\end{example}\n\n\\begin{solution}\n  This is false in general. While it is possible for such a system to\n  have a unique solution, it is also possible for it to have\n  infinitely many. Let there be $n$ equations and $n$ variables.  Then\n  depending on the {\\ef}, the rank $r$ could be either equal to $n$,\n  in which case there is a unique solution, or less than $n$, in which\n  case there are infinitely many.\n\\end{solution}\n\nWe now consider an example of solving a homogeneous system of equations.\n\n\\begin{example}{Solutions to a homogeneous system of equations}{homogeneous-solution}\n  Find the general solution to the following homogeneous system of\n  equations. Does the system have non-trivial solutions?\n  \\begin{equation*}\n    \\begin{array}{c}\n      2x + y + z + 4w = 0 \\\\\n      x + 2y - z + 5w = 0\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Notice that this system has $m = 2$ equations and $n = 4$ variables,\n  so $n>m$.  Therefore by our previous discussion, we expect this\n  system to have infinitely many solutions. In particular, it will\n  have non-trivial solutions.\n\n  The process we use to find the solutions for a homogeneous system of\n  equations is the same process we used for non-homogeneous\n  equations. We construct the augmented matrix and reduce it to\n  {\\rref}.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      2 & 1 & 1 & 4 & 0 \\\\\n      1 & 2 & -1 & 5 & 0\n    \\end{mymatrix}\n    \\roweq\n    \\begin{mymatrix}{rrrr|r}\n      1 & 0 &  1 & 1 & 0 \\\\\n      0 & 1 & -1 & 2 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  The corresponding system of equations is\n  \\begin{equation*}\n    \\begin{array}{r}\n      x + z + w = 0 \\\\\n      y - z + 2w = 0. \\\\\n    \\end{array}\n  \\end{equation*}\n  The free variables are $z$ and $w$. We set them equal to parameters\n  $z=s$ and $w=t$. Then our general solution has the form\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = -s-t \\\\\n      y = s-2t \\\\\n      z = s \\\\\n      w = t.\n    \\end{array}\n  \\end{equation*}\n  Hence this system has infinitely many solutions, with two parameters\n  $s$ and $t$.\n\\end{solution}\n\nLet us write the solution of the last example in another form.\nSpecifically, it can be written as\n\\begin{equation}\\label{eqn:homogeneous-solution-1}\n  \\begin{mymatrix}{r}\n    x \\\\\n    y \\\\\n    z \\\\\n    w\n  \\end{mymatrix}\n  =\n  s\n  \\begin{mymatrix}{r}\n    -1 \\\\\n    1 \\\\\n    1 \\\\\n    0\n  \\end{mymatrix}\n  +\n  t\n  \\begin{mymatrix}{r}\n    -1 \\\\\n    -2 \\\\\n    0 \\\\\n    1\n  \\end{mymatrix}.\n\\end{equation}\nNotice that we have constructed a column from the coefficients of $s$\nin each equation, and another column from the coefficients of $t$.  We\nwill discuss this notation more in later chapters. For now, consider\nwhat happens when we choose the parameters to be $s=1$ and $t=0$. In\nthis case, we get the solution\n\\begin{equation}\\label{eqn:homogeneous-solution-2}\n  \\begin{mymatrix}{r}\n    -1 \\\\\n    1 \\\\\n    1 \\\\\n    0\n  \\end{mymatrix},\n\\end{equation}\nwhich is the same as the column of coefficients for $s$. This is\ncalled a \\textbf{basic solution}%\n\\index{basic solution}%\n\\index{solution!basic} of the\nhomogeneous system of equations. The other basic solution is obtained\nby setting $s=0$ and $t=1$. In this case,\n\\begin{equation}\\label{eqn:homogeneous-solution-3}\n  \\begin{mymatrix}{r}\n    -1 \\\\\n    -2 \\\\\n    0 \\\\\n    1\n  \\end{mymatrix}.\n\\end{equation}\nThe basic solutions of a system are columns constructed from the\ncoefficients on parameters in the solution. If $X_1$ and $X_2$ are the\nbasic solutions {\\eqref{eqn:homogeneous-solution-2}} and\n{\\eqref{eqn:homogeneous-solution-3}}, then the general solution\n{\\eqref{eqn:homogeneous-solution-1}} is of the form $sX_1+tX_2$.  We\nsay that the general solution of the homogeneous system is a\n\\textbf{linear combination}%\n\\index{linear combination!of basic solutions} of its basic solutions.\n\nWe explore this further in the following example.\n\n\\begin{example}{Basic solutions of a homogeneous system}{basic-solutions}\n  Consider the following homogeneous system of equations.\n  \\begin{equation}\\label{eqn:basic-solutions-1}\n    \\begin{array}{c}\n      x + 4y + 3z = 0 \\\\\n      3x + 12y + 9z = 0.\n    \\end{array}\n  \\end{equation}\n  Find the basic solutions to this system.\n\\end{example}\n\n\\begin{solution}\n  The augmented matrix of this system and the resulting {\\rref} are\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 4 & 3 & 0 \\\\\n      3 & 12 & 9 & 0\n    \\end{mymatrix}\n    \\roweq\n    \\begin{mymatrix}{rrr|r}\n      1 & 4 & 3 & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  When written in equations, this system is given by\n  \\begin{equation*}\n    x + 4y + 3z = 0.\n  \\end{equation*}\n  Notice that $x$ is the only pivot variable, and $y$ and $z$ are free\n  variables. Let $y = s$ and $z=t$ for parameters $s$ and $t$. Then the\n  general solution is\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = -4s - 3t \\\\\n      y = s \\\\\n      z = t,\n    \\end{array}\n  \\end{equation*}\n  which can be written as\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix}\n    =\n    s\n    \\begin{mymatrix}{r}\n      -4 \\\\\n      1 \\\\\n      0\n    \\end{mymatrix}\n    +\n    t\n    \\begin{mymatrix}{r}\n      -3 \\\\\n      0 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n  You can see here that we have two columns of coefficients\n  corresponding to parameters, specifically one for $s$ and one for $t$.\n  Therefore, this system has two basic solutions! They are\n  \\begin{equation*}\n    X_1=\n    \\begin{mymatrix}{r}\n      -4 \\\\\n      1 \\\\\n      0\n    \\end{mymatrix},\\quad X_2 = \\begin{mymatrix}{r}\n      -3 \\\\\n      0 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWe can take any non-homogeneous system of equations and get a new\nhomogeneous system by keeping the left-hand sides the same and setting\nall of the constant terms equal to $0$. This is called the\n\\textbf{associated homogeneous system}%\n\\index{homogeneous system!associated}%\n\\index{associated homogeneous system}\nof the system of equations. We end this section by investigating how\nthe solutions of a system of equations are related to the solutions of\nits associated homogeneous system.\n\n\\begin{example}{Non-homogeneous vs. homogeneous system}{non-homo-vs-homo}\n  Solve the system of equations\n  \\begin{equation}\\label{eqn:non-homo-vs-homo-1}\n    \\begin{array}{c}\n      x + 4y + 3z = 2 \\\\\n      3x + 12y + 9z = 6.\n    \\end{array}\n  \\end{equation}\n  How are the solutions related to those of the associated homogeneous\n  system in Example~\\ref{exa:basic-solutions}?\n\\end{example}\n\n\\begin{solution}\n  We note that the associated homogeneous system of\n  {\\eqref{eqn:non-homo-vs-homo-1}} is the system we saw in\n  Example~\\ref{exa:basic-solutions}. We solve the system\n  {\\eqref{eqn:non-homo-vs-homo-1}} in the usual way by reducing its\n  augmented matrix to {\\rref}\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 4 & 3 & 2 \\\\\n      3 & 12 & 9 & 6\n    \\end{mymatrix}\n    \\roweq\n    \\begin{mymatrix}{rrr|r}\n      1 & 4 & 3 & 2 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  and then assigning parameters $y=s$, $z=t$ to the free\n  variables. From the equation $x+4y+3z=2$, the general solution is\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = 2 -4s - 3t \\\\\n      y = s \\\\\n      z = t,\n    \\end{array}\n  \\end{equation*}\n  which can be written as\n  \\begin{equation}\\label{eqn:non-homo-vs-homo-2}\n    \\begin{mymatrix}{r}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r}\n      2 \\\\\n      0 \\\\\n      0\n    \\end{mymatrix}\n    +\n    s\n    \\begin{mymatrix}{r}\n      -4 \\\\\n      1 \\\\\n      0\n    \\end{mymatrix}\n    +\n    t\n    \\begin{mymatrix}{r}\n      -3 \\\\\n      0 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation}\n  We see that the general solution is almost exactly the same as that\n  of the homogeneous system in Example~\\ref{exa:basic-solutions}. The\n  only difference is the additional column\n  \\begin{equation}\\label{eqn:non-homo-vs-homo-3}\n    \\begin{mymatrix}{r}\n      2 \\\\\n      0 \\\\\n      0\n    \\end{mymatrix}\n  \\end{equation}\n\\end{solution}\n\nNote that the column {\\eqref{eqn:non-homo-vs-homo-3}}, by itself, is a\nsolution of the non-homogeneous system. It is not the most general\nsolution, but rather the particular solution resulting from the\nparameters $s=0$ and $t=0$. We can therefore interpret equation\n{\\eqref{eqn:non-homo-vs-homo-2}} as saying that the general solution%\n\\index{general solution} of the non-homogeneous system is equal to a\nparticular solution%\n\\index{particular solution} of the non-homogeneous system, plus the\ngeneral solution of the associated homogeneous system. The same is\ntrue in general, and we summarize it as a theorem.\n\n\\begin{theorem}{Non-homogeneous vs. homogeneous system}{non-homo-vs-homo}\n  Let $A$ be a system of equations, and let $B$ be the associated\n  homogeneous system. Then\n  \\begin{equation*}\n    \\mbox{the general solution of $A$}\n    = \\mbox{a particular solution of $A$}\n    + \\mbox{the general solution of $B$}.\n  \\end{equation*}\n\\end{theorem}\n", "meta": {"hexsha": "f0f3f5d6c51fa5000355d91efcf11f607ee49e1d", "size": 12811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-HomogeneousSystems.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-HomogeneousSystems.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-HomogeneousSystems.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.3995098039, "max_line_length": 104, "alphanum_fraction": 0.6779330263, "num_tokens": 3938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8947894541786198, "lm_q1q2_score": 0.6930890435327599}}
{"text": "\n\\subsection{Residue systems}\n\n\\subsubsection{Least residue system modulo \\(n\\)}\n\nThis is the set of numbers from \\(0\\) to \\(n-1\\).\n\n\\subsubsection{Complete residue system}\n\nThis a set of numbers none of which are congruent \\(\\mod n\\). That is, for no pair \\(\\{a,b\\}\\) does \\(a \\mod(n)=b mod(n)\\)\n\n\\subsubsection{Reduced residue system}\n\nThis is a complete residue system where all numbers are relatively prime to \\(n\\).\n\n", "meta": {"hexsha": "adcc3ce0c26d8da26c55f012c179d4aea159393b", "size": 422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/modulus/01-02-residue.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/modulus/01-02-residue.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/modulus/01-02-residue.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.375, "max_line_length": 122, "alphanum_fraction": 0.7061611374, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7745833737577159, "lm_q1q2_score": 0.6930890325906053}}
{"text": "\n\\subsection{Functionals}\n\nFunctionals map functions to scalars. They are the \\(1\\)-forms of infinite-dimensional vector spaces.\n\nIf we have a function \\(f\\), we can write functional \\(J[f]\\).\n\n\\subsubsection{More}\n\nWe can define neighbourhoods around a function \\(f\\). For example, taking \\(y\\) to be \\(f\\) with infintesimal changes. to each of the values.\n\nThe difference between the functional at both points is\n\n\\(\\delta J=J[y]-J[f]\\)\n\n\\subsubsection{Extrema}\n\nIf\n\n\\(\\delta J=J[y]-J[f]\\)\n\nis the same sign for all y around f, then J has an extremum at f.\n\n\\subsubsection{Functional derivatives}\n\n", "meta": {"hexsha": "ce1702de26003fc152d08a6dccc87a74772eae45", "size": 600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-02-functional.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-02-functional.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-02-functional.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0769230769, "max_line_length": 141, "alphanum_fraction": 0.7216666667, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6930779331371341}}
{"text": "\\begin{Definition}{facets}\n  Let $\\cell\\subset \\R^d$ be a polyhedron. We call the lower\n  dimensional polyhedra constituting its boundary \\define{facet}s. A\n  facet of dimension zero is called \\define{vertex}, of dimension one\n  \\define{edge}, and a facet of codimension one is called a\n  \\define{face}.\n\\end{Definition}\n\n\\begin{Definition}{mesh}\n  A \\define{mesh} $\\mesh$ is a nonoverlapping subdivision of the\n  domain $\\domain$ into polyhedral \\define{cell}s denoted by $\\cell$,\n  for instance simplices, quadrilaterals, or hexahedra. The\n  faces of a cell are denoted by $\\face$, the\n  vertices by $\\vertex$. Cells are typically considered open sets.\n\n  A mesh $\\mesh$ is called regular, if each face\n  $\\face \\subset \\d\\cell$ of the cell $\\cell\\in\\mesh$ is either a\n  face of another cell $\\cell\\prime$, that is,\n  $\\overline{\\face} = \\overline{\\cell} \\cap \\overline{\\cell\\prime}$,\n  or a subset of $\\d\\domain$.\n\\end{Definition}\n\n\\begin{remark}\n  For this introduction, we will assume that indeed $\\domain$ is the\n  union of mesh cells, which means, that its boundary consists of a\n  finite union of planar faces. The more general case of a mesh\n  approximating the domain will be deferred to later discussion.\n\\end{remark}\n\n\\begin{Definition}{finite-element}\n  With a mesh cell $\\cell$, we associate a finite dimensional\n  \\define{shape function} space $\\shapespace(\\cell)$ of dimension\n  $n_\\cell$. The term \\define{node functional} denotes linear\n  functionals on this space.\n\n  A set of node functionals $\\{\\nodal_\\cell^i\\}_{i=1,\\dots,n_\\cell}$ is called\n  \\define{unisolvent} on $\\shapespace(\\cell)$ if for any vector\n  $\\vu = (u_1,\\dots,u_{n_\\cell})^T$ there exists a unique\n  $u\\in \\shapespace(\\cell)$ such that\n  \\begin{gather}\n    \\nodal_\\cell^i(u) = \\vu_i,\\quad i=1,\\dots,n_\\cell.\n  \\end{gather}\n\n  A \\define{finite element} is a set of shape function spaces\n  $\\shapespace(\\cell)$ for all $\\cell\\in\\mesh$ together with\n  unisolvent set of node functionals.\n\\end{Definition}\n\n\\begin{Notation}{dofs}\n  If the node functionals $\\nodal^i$ are unisolvent on\n  $\\shapespace(\\cell)$, then, there is a basis $\\{p_k\\}$ of $\\shapespace(\\cell)$\n  such that\n  \\begin{gather}\n    \\nodal^i(p_k) = \\delta_{ik}.\n  \\end{gather}\n  We refer to $\\{p_k\\}$ as \\define{shape function basis} and use the\n  term \\define{degrees of freedom} for both the node functionals and\n  the basis functions.\n\\end{Notation}\n\n\\begin{Definition}{node-topology}\n  Node functionals can be associated with the cell $\\cell$ or with one\n  of its lower dimensional boundary facets. We call this association\n  the \\define{topology} of the finite element.\n\\end{Definition}\n\n\\begin{Definition}{fe-space}\n  The \\define{finite element space} on the mesh $\\mesh$, denoted by\n  $V_\\mesh$ is a subset of the concatenation of all shape function\n  spaces,\n  \\begin{gather}\n    V_\\mesh \\subset \\bigl\\{ f\\in L^2(\\domain) \\big|\n    f_{|\\cell} \\in \\shapespace(\\cell) \\bigr\\}.\n  \\end{gather}\n  The \\define{degrees of freedom} of $V_\\mesh$ are the union of all\n  node functionals, where we identify node functionals associated to\n  boundary facets among all cells sharing this facet. The resulting\n  dimension is\n  \\begin{gather}\n    n = \\dim V_\\mesh \\le \\sum n_\\cell.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{figure}[tp]\n  \\begin{center}\n    \\includegraphics[width=.5\\textwidth]{graph/concatenation.tikz}\n  \\end{center}\n  \\caption{Identification of node functionals. The node functionals on\n    shared edges (separated for presentation purposes) are\n    distinguished locally as belonging to their respective cells, but\n    identical global indices are assigned to all nodes in a single\n    circle. Thus, all associated shape functions obtain the same\n    coefficient in the global basis representation of a finite element\n    function $u$.}\n  \\label{fig:nodes-identification}\n\\end{figure}\n\n\\begin{Notation}{global-local}\n  When we enumerate the degrees of freedom of $V_\\mesh$, we obtain a\n  global numbering of degrees of freedom $\\nodal^i$ with\n  $i=1,\\dots,n$. For each mesh cell, we have a local numbering\n  $\\nodal_\\cell^j$ with $j=1,\\dots,n$. By construction of the finite\n  element space, there is a unique $i$, such that\n  $\\nodal_\\cell^j(f) = \\nodal^i(f)$ for all cells $\\cell$ and local\n  indices $j$. The converse is not true due to the identification\n  process.\n\\end{Notation}\n\n\\begin{Definition}{local-global}\n  We refer to the mapping between $\\nodal^i$ and $\\nodal_\\cell^j$ as\n  the mapping between global and local indices\n  \\begin{gather}\n    \\iota: (\\cell, j) \\mapsto i.\n  \\end{gather}\n  It induces a\n  ``natural'' basis $\\{v_i\\}$ of $V_\\mesh$ by\n  \\begin{gather}\n    v_{i|\\cell} = p_{\\cell,j},\n  \\end{gather}\n  where $\\{p_{\\cell,j}\\}$ is the shape function basis on $\\cell$. For\n  each $\\nodal^i$, we define $\\mesh(\\nodal^i)$ as the set of cells\n  $\\cell$ sharing the node functional $\\nodal^i$, and\n  \\begin{gather}\n    \\domain\\left(\\nodal^i\\right) = \\bigcup_{\\cell\\in \\mesh(\\nodal^i)} \\cell.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{fe-support}\n  The support of the basis function $v_i\\in V_\\mesh$ is\n  \\begin{gather*}\n    \\operatorname{supp}(v_i) \\subset \\domain\\left(\\nodal^i\\right).\n  \\end{gather*}\n\\end{Lemma}\n\n\\begin{Lemma}{mesh-continuity}\n  Let $\\mesh$ be a subdivision of $\\domain$, and let $u$ be a function\n  on $\\domain$, such that $u_{|\\cell} \\in C^1(\\overline{\\cell})$ for\n  each $\\cell\\in\\mesh$. Then,\n  \\begin{gather}\n    u\\in H^1(\\domain)\n    \\quad \\Longleftrightarrow\\quad\n    u\\in C(\\overline\\domain).\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Lemma}{nodal-continuity}\n  We have $V_\\mesh\\subset C(\\overline{\\domain})$ if and only if for\n  every facet $F$ of dimension $d_F < d$ there holds that\n  \\begin{enumerate}\n  \\item the traces of the spaces $\\shapespace(\\cell)$ on $F$ coincide\n    for all cells $\\cell$ having $F$ as a facet,\n  \\item The node functionals associated to the facet are unisolvent on\n    this trace space.\n  \\end{enumerate}\n\\end{Lemma}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Shape function spaces on simplices}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Definition}{barycentric-coordinates}\n  A simplex $\\cell\\in \\R^d$ with vertices $\\vertex_0,\\dots,\\vertex_d$\n  is described by a set of $d+1$ \\define{barycentric coordinates}\n  $\\vlambda = (\\lambda_0,\\dots,\\lambda_d)^T$ such that\n  \\begin{xalignat}2\n    0\\le\\lambda_i &\\le 1& i&=0,\\dots,d;\\\\\n    \\lambda_i(\\vertex_j) &= \\delta_{ij}& i,j&=0,\\dots,d\\\\\n    \\sum \\lambda_i(\\vx) &= 1,\n  \\end{xalignat}\n  and there holds\n  \\begin{gather}\n    T = \\Bigl\\{x\\in\\R^d \\Big| x = \\sum \\vertex_k\\lambda_k \\Bigr\\}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{todo}\n  Properties of simplicial coordinates, e.g. $\\{\\lambda_i=0\\}$ is the facet opposite to $\\vertex_i$.\n\\end{todo}\n\n\\begin{Lemma}{barycentric-affine}\n  There is a matrix $B_T\\in \\R^{d+1\\times d}$ and a vector\n  $b_T\\in\\R^{d+1}$, such that\n  \\begin{gather}\n    \\vlambda = B_T\\vx + b_T.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Corollary}{barycentric-interpolation}\n  The barycentric coordinates $\\lambda_0,\\dots,\\lambda_d$ are the\n  linear Lagrange interpolating functions for the points\n  $\\vertex_0,\\dots,\\vertex_d$. In particular, $\\lambda_k \\equiv 0$ on\n  the facet not containing $\\vertex_k$.\n\\end{Corollary}\n\n\\begin{example}\n  We can use barycentric coordinates to define interpolating polynomials on\n  simplicial meshes easily, as in\n  Table~\\ref{tab:barycentric-shapes}.\n  \\begin{table}[tp]\n    \\centering\n    \\begin{tabular}{|c|l|}\n      \\hline Degrees of freedom\n      & Shape functions \\\\\\hline\n      \\adjustbox{valign=center,margin=3pt}{\\includegraphics[width=2cm]{mixed/fig/p1-p.tikz}}\n      &\n        {\\begin{minipage}[b]{6cm}\n          \\begin{gather*}\n            \\phi_i = \\lambda_i,\n            \\quad i=0,1,2\n          \\end{gather*}\n        \\end{minipage}}\n      \\\\\\hline\n      \\adjustbox{valign=center,margin=3pt}{\\includegraphics[width=2cm]{mixed/fig/p2-p.tikz}}\n      &\n        {\\begin{minipage}[b]{6cm}\n          \\begin{xalignat*}2\n            \\phi_{ii} &= 2\\lambda_i^2 - \\lambda_i,\n            &i&=0,1,2\\\\\n            \\phi_{ij} &= 4\\lambda_i\\lambda_j\n            &j&\\neq i\n          \\end{xalignat*}\n        \\end{minipage}}\n        \\\\\\hline\n      \\adjustbox{valign=center,margin=3pt}{\\includegraphics[width=2cm]{mixed/fig/p3-p.tikz}}\n      &\n        {\\begin{minipage}[b]{6cm}\n          \\begin{xalignat*}2\n          \\phi_{iii} &= \\tfrac12 \\lambda_i(3\\lambda_i-1)(3\\lambda_i-2)\n          &i&=0,1,2\\\\\n          \\phi_{ij} &= \\tfrac92\\lambda_i\\lambda_j(3\\lambda_j-1)\n          &j&\\neq i\\\\\n          \\phi_0 &= 27\\lambda_0\\lambda_1\\lambda_2\n        \\end{xalignat*}\n        \\end{minipage}}\n        \\\\\\hline\n    \\end{tabular}\n    \\caption{Degrees of freedom and shape functions of simplicial elements\n      in terms of barycentric coordinates}\n    \\label{tab:barycentric-shapes}\n  \\end{table}\n\\end{example}\n\n\\begin{remark}\n  The functions $\\lambda_i(x)$ are the shape functions of the linear\n  $P_1$ element on $T$. They allow us to define basis functions on the\n  cell $T$ without use of a reference element $\\widehat T$.\n\n  Note that $\\lambda_i\\equiv 0$ on the face opposite to the\n  vertex $x_i$.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Shape functions on tensor product cells}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Definition}{tensor-product-polynomials}\n  The space of \\define{tensor product polynomials} of degree $k$ in\n  $d$ dimensions, denoted as $\\Q_k$ consists of polynomials of degree\n  up to $k$ in each variable. Given a basis for one-dimensional\n  polynomials $\\{p_i\\}_{i=0,\\dots,k}$, a natural basis for $\\Q_k$ is\n  the \\define{tensor product basis}\n  \\begin{gather}\n    \\label{eq:fem-intro:1}\n    p_{i_1,\\dots,i_d}(\\vx)\n    = p_{i_1}\\otimes \\dots\\otimes p_{i_d}(\\vx)\n    = \\prod_{k=1}^d p_{i_k}(x_k).\n  \\end{gather}\n\\end{Definition}\n\n\\begin{remark}\n  Note that the basis functions of $\\Q_k$ can be denoted as products\n  of univariate polynomials, but that general polynomials in this\n  space as linear combinations of these basis functions do not have\n  this structure.\n\\end{remark}\n\n\\begin{Lemma}{tensor-product-node-functionals}\n  Let $\\{\\nodal_j\\}$ be a set of one-dimensional node functionals dual\n  to the one-dimensional basis $\\{p_i\\}$ such that\n  \\begin{gather}\n    \\nodal_j(p_i) = \\delta_{ij}.\n  \\end{gather}\n  Then, a dual basis for $\\{p_{i_1,\\dots,i_d}\\}$ is obtained by\n  defining on the tensor product basis of $\\Q_k$\n  \\begin{gather}\n    \\label{eq:fem-intro:2}\n    \\nodal_{j_1,\\dots,j_d}(p_{i_1,\\dots,i_d})\n    = \\nodal_{j_1} \\otimes \\dots\\otimes \\nodal_{j_d}(p_{i_1}\\otimes\\dots\\otimes p_{i_d})\n    = \\prod_{k=1}^d \\nodal_{j_k}(p_{i_k}).\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  It is a theorem in linear algebra, that a linear functional on a\n  vector space is uniquely defined by its values on a basis of the\n  space. Thus,~\\eqref{eq:fem-intro:2} uniquely defines the node\n  functionals $\\nodal_{j_1,\\dots,j_d}$. The duality property follows\n  from the fact that\n  \\begin{gather*}\n    \\nodal_{j_1,\\dots,j_d}(p_{i_1,\\dots,i_d}) = \\prod_{k=1}^d \\delta_{i_k,j_k},\n  \\end{gather*}\n  which is one if and only if all index pairs match and zero in all\n  other cases.\n\\end{proof}\n\n\\begin{example}\n  Let a basis $\\{p_i\\}$ of the univariate space $\\P_k$ be defined by\n  Lagrange interpolation in $k+1$ points $t_j \\in [0,1]$. A basis of\n  the $d$-dimensional space $\\Q_k$ is then obtained by all possible\n  products\n  \\begin{gather*}\n    p_{i_1,\\dots,i_d}(\\vx) = \\prod_{k=1}^d p_{i_k}(x_k).\n  \\end{gather*}\n  The node functionals following the construction above are obtained by\n  \\begin{gather*}\n    \\nodal_{j_1,\\dots,j_d}(p_{i_1,\\dots,i_d}) = \\prod_{k=1}^d p_{i_k}(x_{j_k}).\n  \\end{gather*}\n  Finally, we have to convert the term on the right into an\n  expression, which can be applied to any polynomial in $\\Q_k$. To\n  this end, we observe that\n  \\begin{gather*}\n    \\prod_{k=1}^d p_{i_k}(x_{j_k}) = p_{i_1,\\dots,i_d}(x_{j_1},\\dots,x_{j_d}).\n  \\end{gather*}\n  Therefore, we conclude that the tensor product node functionals\n  resulting from this construction are\n  \\begin{gather*}\n    \\nodal_{j_1,\\dots,j_d}(p) = p(x_{j_1},\\dots,x_{j_d}).\n  \\end{gather*}\n\\end{example}\n\n\\begin{Example*}{q2}{The space $\\Q_2$}\n    \\begin{center}\n    \\includegraphics[width=.3\\textwidth]{graph/shape0}\n    \\includegraphics[width=.3\\textwidth]{graph/shape1}\n    \\includegraphics[width=.3\\textwidth]{graph/shape2}\n\n    \\includegraphics[width=.3\\textwidth]{graph/shape3}\n    \\includegraphics[width=.3\\textwidth]{graph/shape4}\n    \\includegraphics[width=.3\\textwidth]{graph/shape5}\n\n    \\includegraphics[width=.3\\textwidth]{graph/shape6}\n    \\includegraphics[width=.3\\textwidth]{graph/shape7}\n    \\includegraphics[width=.3\\textwidth]{graph/shape8}\n  \\end{center}\n\\end{Example*}\n\n\n\\begin{Lemma}{tensor-product-trace}\n  The trace of the $d$-dimensional tensor product polynomial space\n  $\\Q_k$ on the $\\delta$-dimensional facets of the reference cube\n  $\\refcell = (0,1)^d$ is the $\\delta$-dimensional space $\\Q_k$.\n\n  The traces from two cells sharing the same face coincide, if the\n  mapping is continuous. Therefore, continuity can be achieved by\n  unisolvent sets of node functionals on the face.\n\\end{Lemma}\n\n\\begin{proof}\n  By keeping $d-\\delta$ variables constant in the tensor product basis\n  in~\\eqref{eq:fem-intro:1}.\n\\end{proof}\n\n\\begin{Example*}{cg-q2}{Continuous basis functions}\n  \\begin{center}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-02}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-03}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-15}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-16}\n\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-07}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-13}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-18}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-22}\n\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-17}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-23}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-20}\n    \\includegraphics[height=.20\\textwidth]{graph/cgbasis1-24}\n  \\end{center}\n\\end{Example*}\n\n\\begin{Example*}{dg-q2}{Discontinuous basis functions}\n  \\begin{center}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-08}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-15}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-20}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-27}\n\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-07}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-19}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-23}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-30}\n\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-26}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-33}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-24}\n    \\includegraphics[height=.20\\textwidth]{graph/dgbasis1-22}\n  \\end{center}\n\\end{Example*}\n\n\\begin{example}\n  As a second example, we choose $d=2$ and the univariate space $\\P_2$ with node functionals\n  \\begin{gather}\n    \\nodal_0(p) = p(0),\n    \\quad \\nodal_1(p) = \\int_0^1 p(t) \\dt,\n    \\quad \\nodal_2(p) = p(1),\n  \\end{gather}\n  that is, a mixture of Lagrange interpolation and orthogonality on\n  the interval $[0,1]$. The matching basis polynomials are\n  \\begin{gather}\n    p_0(t) = 3(1-t)^2 - 2(1-t),\n    \\quad p_1(t) = 6 t(1-t),\n    \\quad p_2(t) = 3t^2-2t.\n  \\end{gather}\n  Follwoing the construction of the previous example, we obtain\n  \\begin{gather}\n    \\begin{aligned}\n    \\nodal_{00}(p) &= p(0,0),\n    &\\nodal_{02}(p) &= p(0,1),\\\\\n    \\nodal_{20}(p) &= p(1,0),\n    &\\nodal_{22}(p) &= p(1,1).\n    \\end{aligned}\n  \\end{gather}\n  Then,\n  \\begin{gather}\n    \\nodal_{01}(p_{01}) = \\nodal_{01}(p_0\\otimes p_1)\n    = p_0(0)\\int_0^1 p_1(y)\\dy\n    = \\int_0^1 p(0,y) \\dy.\n  \\end{gather}\n  Thus, the node functional $\\nodal_{01}$ is the integral over the\n  left edge of the reference square. By the same construction,\n  $\\nodal_{01}$ is the integral over the right edge. $\\nodal_{10}$ and\n  $\\nodal_{12}$ are the integrals over the bottom and top edge,\n  respectively. Finally,\n  \\begin{gather}\n    \\nodal_{11}(p_{11})\n    = \\int_0^1 p_1(x)\\dx \\int_0^1 p_1(y) \\dy\n    = \\int_0^1\\int_0^1 p_{11}(x,y) \\dx\\dy.\n  \\end{gather}\n  Thus, the tensor product of two line integrals becomes the integral\n  over the area.\n\\end{example}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{The Galerkin equations and Céa's lemma}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Definition*}{galerkin-approximation}{Galerkin approximation}\n  Let $u\\in V$ be determined by the weak formulation\n  \\begin{gather*}\n    a(u,v) = f(v) \\qquad\\forall v\\in V,\n  \\end{gather*}\n  where $V$ is a suitable function space including boundary\n  conditions. The \\define{Galerkin approximation}, also called\n  \\define{conforming approximation} of this problem reads as follows:\n  choose a subspace $V_n\\subset V$ of dimension $n$ and find\n  $u_n\\in V_n$, such that\n  \\begin{gather*}\n    a(u_n,v_n) = f(v_n) \\qquad\\forall v_n\\in V_n.\n  \\end{gather*}\n  We will refer to this equation as the \\define{discrete problem}.\n\\end{Definition*}\n\n\\begin{Corollary*}{galerkin-equations}{Galerkin equations}\n  After choosing a basis $\\{v_i\\}$ for $V_n$, the Galerkin equations are\n  equivalent to a linear system\n  \\begin{gather}\n    \\mata \\vu = \\vf,\n  \\end{gather}\n  with $\\mata\\in\\R^{n\\times n}$ and $\\vf\\in \\R^n$ defined by\n  \\begin{gather}\n    a_{ij} = a(v_j, v_i), \\qquad f_i = f(v_i).\n  \\end{gather}\n\\end{Corollary*}\n\n\\begin{Lemma}{discrete-lax-milgram}\n  If the lemma of Lax-Milgram holds for $a(.,.)$ on $V$, it holds on\n  $V_n\\subset V$. In particular, solvability of the Galerkin equations\n  is implied.\n\\end{Lemma}\n\n\\begin{Lemma*}{cea}{Céa}\n  Let $a(.,.)$ be a bounded and elliptic bilinear form on the Hilbert\n  space $V$.  Let $u \\in V$ and $u_n\\in V_n \\subset V$ be\n  the solution to the weak formulation and its Galerkin approximation\n  \\begin{gather*}\n    \\begin{aligned}\n      a(u,v) &= f(v) & \\qquad\\forall v&\\in V,\\\\\n      a(u_n,v_n) &= f(v_n) & \\qquad\\forall v_n&\\in V_n,\n    \\end{aligned}\n  \\end{gather*}\n  respectively. Then, there holds\n  \\begin{gather}\n    \\norm{u-u_h}_V \\le \\frac{M}{\\alpha}\n    \\inf_{v_n\\in V_n}\\norm{u-v_h}_V.\n  \\end{gather}\n\\end{Lemma*}\n\n\\begin{Lemma}{fe-matrix}\n  For a finite element discretization of Poisson's equation with the\n  space $V_\\mesh$, the Galerkin equations can be computed using the\n  following formulas:\n  \\begin{alignat*}3\n    a_{ij} &= \\int\\limits_\\domain \\nabla v_j \\cdot \\nabla v_i \\dx\n    &&= \\int\\limits_{\\domain(\\nodal^i)} \\nabla v_j \\cdot \\nabla v_i \\dx\n    &&= \\sum_{\\cell\\in\\mesh(\\nodal^i)}\\int\\limits_\\cell \\nabla v_j \\cdot \\nabla v_i \\dx\\\\\n    f_{i} &= \\int\\limits_\\domain f v_i \\dx\n    &&= \\int\\limits_{\\domain(\\nodal^i)} f v_i \\dx\n    &&= \\sum_{\\cell\\in\\mesh(\\nodal^i)}\\int\\limits_\\cell f v_i \\dx\n  \\end{alignat*}\n\\end{Lemma}\n\n\\begin{Algorithm*}{matrix-assembling}{Assembling the matrix}\n  \\begin{enumerate}\n  \\item Start with a matrix $\\mata = 0 \\in \\R^{n\\times n}$\n  \\item Loop over all cells $\\cell\\in\\mesh$\n  \\item On each cell $\\cell$, compute a cell matrix\n    $\\mata_\\cell \\in \\R^{n_\\cell\\times n_\\cell}$ by integrating\n    \\begin{gather}\n      a_{\\cell,ij} = \\int_\\cell \\nabla p_{\\cell,j}\\cdot\\nabla p_{\\cell,i}\\,dx,\n    \\end{gather}\n    where $\\{p_{\\cell,i}\\}$ is the shape function basis.\n  \\item Assemble the cell matrices into the global matrix by\n    \\begin{gather}\n      a_{\\iota(i),\\iota(j)} = a_{\\iota(i),\\iota(j)} + a_{\\cell,ij}\n      \\qquad i,j = 1,\\dots,n_\\cell.\n    \\end{gather}\n  \\end{enumerate}\n\\end{Algorithm*}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Mapped finite elements}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Definition}{mapped-mesh}\n  A mapped mesh $\\mesh$ is a set of cells $\\cell$, which are defined\n  by a single \\define{reference cell} $\\refcell$ and individual\n  smooth mappings\n  \\begin{gather}\n    \\begin{split}\n      \\Phi_\\cell \\colon \\refcell &\\to \\R^d\\\\\n      \\Phi_\\cell(\\refcell) &= \\cell.\n    \\end{split}\n  \\end{gather}\n  The definition extends to small sets of reference cells, for\n  instance for triangles and quadrilaterals.\n\\end{Definition}\n\n\\begin{Example}{mapping-linear}\n  Let the reference triangle $\\refcell$ be defined by\n  \\begin{gather}\n    \\refcell = \\left\\{\n      \\begin{pmatrix}\n        \\refx\\\\\\refy\n      \\end{pmatrix}\n      \\middle|\n      \\refx,\\refy >0, \\refx+\\refy < 1\n    \\right\\}.\n  \\end{gather}\n  Then, every cell $\\cell$ spanned by the vertices $\\vertex_0$,\n  $\\vertex_1$, and $\\vertex_2$ is obtained by mapping $\\refcell$ by\n  the \\putindex{affine mapping}\n  \\begin{gather}\n    \\Phi_\\cell(\\refvx) =\n    \\begin{pmatrix}\n      X_1-X_0 & X_2 - X_0 \\\\ Y_1-Y_0 & Y_2 - Y_0\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      \\refx \\\\ \\refy\n    \\end{pmatrix}\n    +\n    \\begin{pmatrix}\n      X_0 \\\\ Y_0\n    \\end{pmatrix} =: \\matb_\\cell \\refvx + \\vb_\\cell\n  \\end{gather}\n\\end{Example}\n\n\\begin{Example}{mapping-bilinear}\n  The reference cell for a quadrilateral is the reference square\n  $\\refcell = (0,1)^2$. Every quadrilateral $\\cell$ spanned by the\n  vertices $\\vertex_0$ to $\\vertex_3$ is then obtained by the\n  \\putindex{bilinear mapping}\n  \\begin{gather}\n    \\Phi_\\cell(\\refvx)\n    = \\vertex_0 (1-\\refx)(1-\\refy)\n    + \\vertex_1 \\refx(1-\\refy)\n    + \\vertex_2 (1-\\refx)\\refy\n    + \\vertex_3 \\refx\\refy\n  \\end{gather}\n\\end{Example}\n\n\\begin{Definition}{mapped-fe}\n  Mapped shape functions $\\{p_i\\}$ on a mesh cell $\\cell$ are defined by a\n  set of shape functions $\\{\\refp_i\\}$ on the reference cell\n  $\\refcell$ through \\define{pull-back}\n  \\begin{gather}\n    \\begin{split}\n      p_i(\\vx) &= \\refp_i\\left(\\Phi^{-1}(\\vx)\\right) = \\refp_i(\\refvx),\\\\\n      \\nabla p_i(\\vx) &= \\nabla\\Phi^{-T}(\\refvx)\\refgrad\\refp_i(\\refvx)\n    \\end{split}\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{mapped-norms-affine}\n  Let $\\refcell$ be the reference triangle and let $\\cell$ be a\n  triangular mesh cell with mapping\n  $\\vx = \\Phi_\\cell(\\refvx) = \\matb \\refvx + \\vb$. Let there hold\n  $u(\\vx) = \\refu(\\refvx)$. Then, $u\\in H^k(\\cell)$ if and only if\n  $\\refu\\in H^k(\\refcell)$ and we have with some constant $c$ the\n  estimates\n  \\begin{gather}\n    \\begin{split}\n      \\snorm{\\refu}_{k,\\refcell}\n      &\\le c \\norm{\\matb}^k (\\det \\matb)^{-\\nicefrac12}\n      \\snorm{u}_{k,\\cell},\\\\\n      \\snorm{u}_{k,\\cell}\n      &\\le c \\norm{\\matb^{-1}}^k (\\det \\matb)^{\\nicefrac12}\n      \\snorm{\\refu}_{k,\\refcell}.\n    \\end{split}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Lemma}{shape-regular-transformation}\n  For a cell $\\cell$, let $R$ be the radius of the circumscribed\n  circle and $\\rho$ the radius of the inscribed circle. Then,\n  \\begin{gather}\n    \\norm{\\matb} \\le c R, \\qquad \\norm{\\matb^{-1}} \\le c \\rho^{-1}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  \\begin{figure}\n    \\centering\n    \\begin{tikzpicture}\n    \\def\\scale{3}\n    \n    %% reference cell\n    \\def\\mid{\\scale*0.2928932188}\n    \\def\\outermid{\\scale*0.5}\n    \\def\\outerrad{\\scale*0.7071067811}\n    \n    \\node (mid) at (\\mid,\\mid) {$\\refvx_0$};\n    \\coordinate (x1) at (\\scale*1,0);\n    \\node[right = \\scale*0.01 of x1] (x1name) {$\\refvx_1$};\n    \\coordinate (x2) at (0,\\scale*1);\n    \\node[above = \\scale*0.01 of x2] (x2name) {$\\refvx_2$};\n    \\coordinate (x3) at (0,0);\n    \\node[left = \\scale*0.01 of x3] (x3name) {$\\refvx_3$};\n    \\coordinate (xc) at (\\outermid,\\outermid);\n    \\node[above = \\scale*0.01 of xc] (xcname) {$\\refvx_c$};\n    \n    \\draw (x1)--(x2)--(x3)--(x1);\n    \n    % incircle\n    \\draw (mid) circle (\\mid);\n    \\draw (mid) --  (\\mid,0);\n    \\node[below = \\scale*0.01 of mid,xshift=0.5em] (rho) {$\\refrho$};\n    \n    % circumcircle\n    \\draw (xc) circle (\\outerrad);\n    \\draw (xc) -- (\\outermid+\\outerrad,\\outermid);\n    \\node[above right = \\scale*0.01 and \\scale*0.25 of xc] (R) {$\\reference{R}$};\n    \\end{tikzpicture}\n    \\caption{Visualization of the inscribed and circumscribed circle of the reference cell $\\refcell$.}\n  \\end{figure}\n\n  Let us define $S_{\\refrho}\\coloneqq \\{\\refvy\\in\\R^d ~\\mid~ \\abs{\\refvy}=\\refrho \\}$.\n  For $\\refvy\\in S_{\\refrho}$ there holds\n  $\\refvx\\coloneqq \\refvxo + \\refvy\\in \\overline{\\refcell}$\n  and $\\vx=\\matb\\refvx + \\vb = \\matb(\\refvxo+\\refvy)+\\vb$.\n  Additionally, we have $\\vxo = \\matb \\refvxo + \\vb$\n  which yields\n  \\begin{align*}\n    \\abs{\\vx-\\vxo} = \\abs{\\matb\\refvy}\\leq 2R.\n  \\end{align*}\n  Now consider the operator norm of $\\matb$\n  \\begin{align*}\n    \\norm{\\matb} = \\sup_{\\refvy\\in\\R^d} \\frac{\\abs{\\matb\\refvy}}{\\abs{\\refvy}}\n    = \\sup_{\\abs{\\refvy}=1} \\abs{\\matb\\refvy}\n    = \\sup_{\\refvy\\in S_{\\refrho}} \\frac{\\abs{\\matb\\refvy}}{\\refrho}\n    \\leq \\frac{2R}{\\refrho}.\n  \\end{align*}\n  $\\refrho$ is a constant only depending on $\\refcell$ but\n  not on $\\cell$. Hence, we get $\\norm{\\matb}\\leq cR$ with $c$ depending\n  on $\\refrho$.\n\n  The same argument can be applied for the second estimate.\n  We now define $S_\\rho\\coloneqq \\{\\vy\\in\\R^d~\\mid~\\abs{\\vy}=\\rho \\}$.\n  For $\\vy\\in S_\\rho$ there holds $\\vx\\coloneqq\\vxo+\\vy\\in\\overline{\\cell}$\n  and let $\\refvx=\\matb^{-1}\\vx-\\vb,~\\refvxo=\\matb^{-1} \\vxo - \\vb$ which yields\n  \\begin{align*}\n    \\abs{\\refvx - \\refvxo} = \\abs{\\matb^{-1} \\vy}\\leq 2\\reference{R}.\n  \\end{align*}\n  Analogous to the first estimate we obtain\n  \\begin{align*}\n    \\norm{\\matb^{-1}} = \\sup_{\\vy\\in S_\\rho} \\frac{\\abs{\\matb^{-1} \\vy}}{\\rho}\n    \\leq \\frac{2\\reference{R}}{\\rho}.\n  \\end{align*}\n  Now $\\reference{R}$ is only depending on $\\refcell$ but not on $\\cell$.\n  Hence, we have $\\norm{\\matb^{-1}}\\leq c\\rho^{-1}$ where $c$ depends\n  on $\\reference{R}$.\n\\end{proof}\n\n\\begin{Assumption}{mapping-decomposition}\n  For more general mappings $\\Phi\\colon \\refcell\\to \\cell$, we\n  make the assumption, that they can be decomposed into three factors,\n  \\begin{gather}\n    \\Phi = \\Phi_O \\circ \\Phi_S \\circ \\Phi_W,\n  \\end{gather}\n  where $\\Phi_O$ is a combination of translation and rotation,\n  $\\Phi_S$ is a scaling with a characteristic length $h_T$, and\n  $\\Phi_W$ is a warping function not changing the characteristic length.\n\\end{Assumption}\n\n\\begin{example}\n  We construct the inverse of $\\Phi$ in two dimensions by the\n  following three steps, using as $h_\\cell$ the length of the longest\n  edge of $\\cell$.\n  \\begin{enumerate}\n  \\item Choose $\\Phi_O$ as the rigid body movement which maps the\n    longest edge to the interval $(0,h_\\cell)$ on the $x$-axis and the\n    cell itself to $\\cell_O$ in the positive half plane. This mapping\n    has the structure\n    \\begin{gather*}\n      \\Phi^{-1}_O (\\vx) = \\mats \\vx - \\mats \\vertex_0,\n    \\end{gather*}\n    where $\\mats$ is an orthogonal matrix and $\\vertex_0$ is the\n    vertex moved to the origin.\n  \\item Choose the scaling\n    \\begin{gather*}\n      \\Phi^{-1}_S (\\vx) = \\tfrac1{h_\\cell} \\vx,\n    \\end{gather*}\n    such that the longest edge of the resulting cell $\\cell_S$ has the\n    longest edge equal to the interval $(0,1)$ on the $x$-axis.\n  \\item Warp the cell $\\cell_S$ into the reference cell $\\refcell$ by\n    the mapping $\\Phi^{-1}_W$. This operation leaves the longest edge\n    untouched. For triangles, it is the uniquely defined linear\n    transformation mapping the vertex not on the longest edge to\n    $(0,1)$. For quadrilaterals, it is a bilinear transformation.\n  \\end{enumerate}\n\n  In the first step, we have assumed that the cell is convex, which is\n  always true for triangles. For nonconvex quadrilaterals, it can be\n  shown that the determinant of $\\nabla\\Phi$ changes sign inside the\n  cell, such that these cells are not useful for computations.\n\n  The idea of this decomposition is, that we separate mappings\n  changing the position, size, and shape of the cells.\n\\end{example}\n\n\\begin{Lemma*}{scaling-1}{Scaling lemma}\n  Let the typical length of a cell $\\cell$ be $h_\\cell$. Assume there\n  are constants $0 < M_\\cell, m_\\cell, d_\\cell, D_\\cell$, such that\n  \\begin{gather}\n    \\begin{split}\n      \\norm{\\nabla\\Phi_W(\\refvx)} \\le M_\\cell,\n      \\\\\n      \\norm{\\nabla\\Phi_W^{-1}(\\refvx)} \\le m_\\cell^{-1} ,\n      \\\\\n      d^2_\\cell \\le \\det \\nabla\\Phi_W(\\refx)) \\le D^2_\\cell.      \n    \\end{split}\n  \\end{gather}\n  for all $\\refvx\\in\\refcell$. Then, for $k=0,1$ and a constant $c$\n  \\begin{gather}\n    \\begin{split}\n      \\snorm{\\refu}_{k,\\refcell}\n      &\\le c \\frac{M_\\cell}{d_\\cell}  h_\\cell^{k-\\nicefrac d2}\n      \\snorm{u}_{k,\\cell},\\\\\n      \\snorm{u}_{k,\\cell}\n      &\\le c \\frac{D_\\cell}{m_\\cell} h_\\cell^{\\nicefrac d2-k}\n      \\snorm{\\refu}_{k,\\refcell}.\n    \\end{split}\n  \\end{gather}\n  This extends to higher derivatives under assumptions on higher\n  derivatives of $\\Phi_\\cell$.\n\\end{Lemma*}\n\n\\begin{proof}\n  By the chain rule,\n  $\\nabla \\Phi_T = \\nabla \\Phi_O \\nabla \\Phi_S \\nabla \\Phi_W$. By\n  construction, $\\nabla\\Phi_O$ is an orthogonal matrix, such that\n  \\begin{gather*}\n    \\norm{\\nabla\\Phi_O} = \\norm{\\nabla\\Phi_O^{-1}} = 1.\n  \\end{gather*}\n  Since it preserves angles and lengths, $\\det \\nabla\\Phi_O =\n  1$. Since $\\Phi_S$ is a multiple of the identity, we have\n  \\begin{gather*}\n    \\norm{\\nabla\\Phi_S} = h_\\cell,\n    \\quad\\norm{\\nabla\\Phi_S^{-1}} = \\frac1{h_\\cell},\n    \\quad\\det\\nabla\\Phi_S = h_\\cell^d.\n  \\end{gather*}\n  By change of variables, we have\n  \\begin{gather*}\n    \\int_\\cell u^2 \\dvx\n    = \\int_{\\refcell} \\refu^2 \\abs{\\det\\nabla\\Phi_\\cell} \\dvxref\n    = \\int_{\\refcell} \\refu^2 \\det\\nabla\\Phi_S\\det\\nabla\\Phi_O\\det\\nabla\\Phi_W \\dvxref\n    ,\n  \\end{gather*}\n  such that the case $k=0$ is proven immediately by\n  \\begin{gather*}\n    h_T^d d_\\cell^2 \\int_{\\refcell} \\refu^2 \\dvxref\n    \\le \\int_\\cell u^2 \\dvx\n    \\le h_T^d D_\\cell^2 \\int_{\\refcell} \\refu^2 \\dvxref\n  \\end{gather*}\n  By the chain rule, we have\n  \\begin{gather*}\n    \\refgrad\\refu(\\refvx) = \\nabla\\Phi^T \\nabla u(\\vx)\n    = \\nabla\\Phi_W^T \\nabla\\Phi_S^T \\nabla\\Phi_O^T \\nabla u(\\vx),\n  \\end{gather*}\n  such that there holds\n  \\begin{gather}\n    \\begin{split}\n      \\abs{\\refgrad\\refu(\\refvx)}\n      &\\le \\norm{\\nabla\\Phi_W} h_\\cell \\abs{\\nabla u},\\\\\n      \\abs{\\nabla u(\\vx)}\n      &\\le \\norm{\\nabla\\Phi_W^{-1}} h_\\cell^{-1} \\abs{\\refgrad \\refu}.\n    \\end{split}\n  \\end{gather}\n\\end{proof}\n\n\n\\begin{Remark}{simple-mappings}\n  We have $d_\\cell = D_\\cell$, if and only if the mapping is\n  affine. The quotient $M_\\cell/m_\\cell$ measures how much the shape\n  of the mesh cell deviates from the reference cell. For instance, it\n  is one for squares.\n\\end{Remark}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "cf7458b8c2ae7db552c595a613ad5ce1368c3e1e", "size": 31285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fem/fem-intro.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fem/fem-intro.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fem/fem-intro.tex", "max_forks_repo_name": "ahumanita/notes", "max_forks_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1115065243, "max_line_length": 103, "alphanum_fraction": 0.6414256033, "num_tokens": 10351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.6929241128758035}}
{"text": "\\section{Newtonian Dynamics: The Basics}\r\n\\subsection{Particles}\r\n\\begin{definition}\r\n    A particle is an object that has negligible size but have positive mass $m$ and electric charge $q$.\r\n\\end{definition}\r\nSince a particle will have small size, we can describe its position by a simple position vector $\\underline{r}(t)\\in\\mathbb R^3$ relative to the origin.\r\nWe often write the vector in terms of its Cartesian components $\\underline{r}=x\\underline{i}+y\\underline{j}+z\\underline{k}=(x,y,z)$ where $\\underline{i},\\underline{j},\\underline{k}$ are an orthonormal basis.\r\nThe choice of the coordinate system (the origin and the basis) defines a frame of reference.\\\\\r\nWhen the particle moves, its position is determined by a curve $\\underline{r}(t)$.\r\nThe velocity of the particle is naturally its derivative $\\underline{u}(t)=\\underline{\\dot{r}}(t)$.\r\nGeometrically, the velocity will be the tangent to the curve (or trajectory) at time $t$.\r\nThe momentum as we know would be $\\underline{p}=m\\underline{u}=m\\underline{\\dot{r}}$.\r\nThe acceleration is defined as $\\underline{a}=\\underline{\\dot{u}}=\\underline{\\ddot{r}}$.\r\n\\begin{note}\r\n    The time derivative of a vector valued function $\\underline{v}(t)$ is\r\n    $$\\underline{\\dot{v}}(t)=\\lim_{h\\to0}\\frac{\\underline{v}(t+h)-\\underline{v}(t)}{h}$$\r\n    provided its existence.\r\n    If anyone is worried, $\\underline{v}\\to\\underline{v_0}\\iff\\|\\underline{v}-\\underline{v_0}\\|\\to 0$.\\\\\r\n    In particular, if $\\underline{v}=x\\underline{i}+y\\underline{j}+z\\underline{k}$, then $\\underline{\\dot{v}}=\\dot{x}\\underline{i}+\\dot{y}\\underline{j}+\\dot{z}\\underline{k}$ (given that the frame of reference is invariance in time).\r\n\\end{note}\r\n\\begin{proposition}\r\n    For scalar functions $f(t)$ and vector functions $\\underline{g}(t),\\underline{h}(t)$, we have\\\\\r\n    1. $(f\\underline{g})^\\prime=f^\\prime \\underline{g}+f\\underline{g}^\\prime$.\\\\\r\n    2. $(\\underline{g}\\cdot\\underline{h})^\\prime=\\underline{g}^\\prime\\cdot\\underline{h}+\\underline{g}\\cdot\\underline{h}^\\prime$.\\\\\r\n    3. $(\\underline{g}\\times\\underline{h})^\\prime=\\underline{g}^\\prime\\times\\underline{h}+\\underline{g}\\times\\underline{h}^\\prime$.\\\\\r\n    Note that sometimes the order matters.\r\n\\end{proposition}\r\n\\subsection{Newton's Laws of Motion}\r\n\\begin{law}[Newton's First Law]\r\n    There exists inertial frames of reference (or inertial frames).\r\n    That is, a particle at rest or move in constant velocity continues to do so given that it is acted by no force.\r\n\\end{law}\r\n\\begin{law}[Newton's Second Law]\r\n    In an inertial frame, then the motion obeys the rule $\\underline{\\dot{p}}=\\underline{F}$.\r\n\\end{law}\r\n\\begin{law}[Newton's Third Law]\r\n    To every action there is an equal and opposite reaction.\r\n\\end{law}\r\nThe statements, albeit are made for particles, can be extended to finite bodies.\r\n\\footnote{Bounded bodies.}\r\n\\subsection{Inertial Frames and Galileo Transformation}\r\nIf we have an inertial frame, $\\ddot{r}=0$ if there is no force acting on it.\r\nThere is obviously not only one inertial frame.\r\nIn particular, if $S$ is an inertial frame, then a frame $S'$ moving with uniform velocity relative to $S$ is also an inertial frame.\r\nFor example, if the frame $S'$ is moving with velocity $v$ on the $x$ direction, then\r\n$$\\begin{cases}\r\n    x'=x-vt\\\\\r\n    y'=y\\\\\r\n    z'=z\\\\\r\n    t'=t\r\n\\end{cases}$$\r\nMore generally, if $S'$ is moving with vector velocity $\\underline{v}$ relative to $S$, we have\r\n$$\\begin{cases}\r\n    \\underline{r'}=\\underline{r}-\\underline{v}t\\\\\r\n    t'=t\r\n\\end{cases}$$\r\nThis transformation is called a \\textit{boost}.\r\nFor a partical having position vector $\\underline{r}(t)$ in $S$ and $\\underline{r'}(t')$ in $S'$.\r\nSo we have the velocity $\\underline{u'}=\\underline{u}-\\underline{v}$ (note that the primes are NOT used for derivatives here) and $\\underline{a'}=\\underline{a}$.\r\n\\begin{definition}\r\n    A general Galileo transformation is one which preserves inertial frames.\r\n    It combines a boost with any of the following:\\\\\r\n    1. Translation of space: $\\underline{r'}=\\underline{r}-\\underline{r_0}$.\\\\\r\n    2. Translation of time: $t'=t-t_0$.\\\\\r\n    3. Rotations and reflections: $\\underline{r'}=R\\underline{r},R\\in\\operatorname{O}(3)$.\\\\\r\n    This set generates the Galilean group of transformations.\r\n\\end{definition}\r\nNote that if the acceleration is zero in one frame, so it is in another.\r\n\\begin{definition}[Principle of Galilean Relativity]\r\n    The laws of (Newtonian) physics is unchanged in all inertial frames.\r\n\\end{definition}\r\nThat is, the laws of physics look the same in every inertial frame.\r\nHence the system of Newtonian physics has to be invariant under the Galilean transformations.\r\n\\subsection{Newton's Second Law}\r\nThe law postulates that $\\underline{F}=\\underline{\\dot{p}}$.\r\nAssume that $m$ is constant in time, then we have $\\underline{F}=m\\underline{\\ddot{r}}$.\r\nEasily $m$ is the measure of ``reluctance to accelerate'', that is inertia.\r\nIf we specify $\\underline{F}$ as a function of $\\underline{r},\\underline{\\dot{r}},t$, then we have a second order ODE in $\\underline{r}$:\r\n$$\\underline{F}(\\underline{r},\\underline{\\dot{r}},t)=m\\underline{\\ddot{r}}$$\r\nWe then need two initial conditions to solve the equation (or to determine the motion).\r\nFor example, we can specify the initial position and velocity.\r\nWith these information\r\n\\footnote{And perhaps Picard-Lindel\\\"of Theorem}\r\nwe can get an unique solution for the trajectory of our particle.\r\n\\subsection{Examples of Forces}\r\nConsider $2$ particles indexed by $1,2$, then Newton tells us\r\n\\begin{law}[Newton's Law of Gravitation]\r\n    There is an action-reaction pair on the two particles, namely\r\n    $$\\underline{F_1}=-\\frac{Gm_1m_2}{|\\underline{r_1}-\\underline{r_2}|^3}(\\underline{r_1}-\\underline{r_2})=-F_2$$\r\n\\end{law}\r\nIn particular, $|\\underline{F_1}|=|\\underline{F_2}|\\propto|\\underline{r_1}-\\underline{r_2}|^{-2}$.\r\nThis is known as the inverse square law.\r\nIt is quite obvious that $G$ has an unit.\r\nIt is called Newton's Gravitation Constant.\\\\\r\nAnother example is electromagnetic forces.\r\nLet there be a particle with electric charge $q$ and imagine that it is moving in an electric-magnetic field $\\underline{E}(\\underline{r},t)$ and $\\underline{B}(\\underline{r},t)$.\r\n\\begin{law}[Lorentz Force Law]\r\n    We have\r\n    $$\\underline{F}=q(\\underline{E}+\\underline{\\dot{r}}\\times\\underline{B})$$\r\n\\end{law}\r\n\\begin{example}\r\n    Take $\\underline{E}=\\underline{0},\\underline{B}=\\underline{B}(t)$, i.e. the electric field is constant and the magnetic field is constant in space.\r\n    Hence\r\n    $$m\\underline{\\ddot{r}}=q\\underline{\\dot{r}}\\times\\underline{B}(t)$$\r\n    Choose axes such that $\\underline{B}=B\\underline{\\hat{z}}$, then $m\\ddot{z}=0\\implies z=z_0+ut$.\r\n    As for the other directions, we have\r\n    $$\\begin{cases}\r\n        m\\ddot{x}=qB\\dot{y}\\\\\r\n        m\\ddot{y}=-qB\\dot{x}\r\n    \\end{cases}$$\r\n    which we can easily solve to get\r\n    $$\\begin{cases}\r\n        x=x_0-\\alpha\\cos(\\omega(t-t_0))\\\\\r\n        y=y_0+\\alpha\\sin(\\omega(t-t_0))\r\n    \\end{cases}$$\r\n    which shall produce a helical path which is clockwise when viewed from the direction of $\\underline{B}$.\r\n    And the axis of the helix is parallel to the magnetic field.\r\n\\end{example}", "meta": {"hexsha": "dbec11889d42138ba7711dcfe763354ba8597778", "size": 7212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/basics.tex", "max_stars_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_stars_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/basics.tex", "max_issues_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_issues_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/basics.tex", "max_forks_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_forks_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.1186440678, "max_line_length": 233, "alphanum_fraction": 0.6992512479, "num_tokens": 2133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.8499711737573763, "lm_q1q2_score": 0.6929241005973175}}
{"text": "% !TEX root = main.tex\n%=====================================================================\n\\chapter{General linear models}\\label{chap:bivariate_analysis}\n\\startcontents[chapters]\n\\chapcontents\n\n%-------------------------------------------------\n\\section{The chi-squared distribution}\\label{sec:chi-squared}\n\nIf $Z_1,Z_2,\\ldots,Z_n$ are independent standard normal %$N(0,1)$ \nvariables, the sum-of-squares\n$\\displaystyle\\sum_{i=1}^n Z_i^2$\nhas the \\emph{chi-squared distribution} with $n$ degrees of freedom, which plays a central role in statistics.\n\n%--------------------------------------------------\n\\subsection{The gamma distribution}\n%--------------------------------------------------\n\\begin{definition}\\label{def:gamma_distribution}\nThe \\emph{gamma distribution} with parameters $k>0$ and $\\theta>0$ is defined by the PDF\n\\[\nf(x) = \\begin{cases}\n\t\\displaystyle\\frac{1}{\\Gamma(k)\\theta^k}\\,x^{k-1} e^{-x/\\theta} & \\text{for $x>0$}, \\\\\n\t0\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nwhere $\\Gamma(k)$ is the so-called \\emph{gamma function},\n\\[\n\\Gamma(k) = \\int_0^{\\infty} t^{k-1}e^{-t}\\,dt.\n\\]\n%which is defined for all $k>0$.\n\\end{definition}\n\nNote that if $X\\sim\\text{Exponential}(\\theta)$ where $\\theta$ is a scale parameter, then $X\\sim\\text{Gamma}(1,\\theta)$.\n\n\\begin{lemma}\nThe MGF of the $\\text{Gamma}(k,\\theta)$ distribution is $M(t) = \\displaystyle\\frac{1}{(1-\\theta t)^k}$, defined for $t<\\displaystyle\\frac{1}{\\theta}$.\n%for $t<\\theta^{-1}$.\n\\end{lemma}\n\n\\begin{proof} % leave as exercise\nLet $X\\sim\\text{Gamma}(k,\\theta)$. Then\n\\begin{align*}\nM_X(t) = \\expe(e^{tX})\n\t& = \\int_0^\\infty e^{tx} \\frac{1}{\\Gamma(k)\\theta^k}\\,x^{k-1} e^{-x/\\theta}\\,dx \\\\\n\t& = \\int_0^\\infty \\frac{1}{\\Gamma(k)\\theta^k}\\,x^{k-1} e^{-x(1-\\theta t)/\\theta}\\,dx \n\\end{align*}\nChanging the variable of integration, let $y=x(1-\\theta t)/t$ where $t<1/\\theta$. Then $x=\\theta y/(1-\\theta t)$ so\n\\begin{align*}\nM_X(t)\n\t& = \\int_0^\\infty \\frac{\\theta/(1-\\theta t)}{\\Gamma(k)\\theta^k}\\left(\\frac{\\theta y}{1-\\theta t}\\right)^{k-1} e^{-y}\\,dy \\\\\n\t& = \\left(\\frac{1}{1-\\theta t}\\right)^{k} \\int_0^\\infty \\frac{1}{\\Gamma(k)}y^{k-1} e^{-y}\\,dy \\\\\n\t& = \\left(\\frac{1}{1-\\theta t}\\right)^{k} \\qquad\\text{for } t < \\frac{1}{\\theta}.\n\\end{align*}\n\\end{proof}\n\n% corollary: mean and variance\n\\begin{corollary}\nIf $X\\sim\\text{Gamma}(k,\\theta)$, then $\\expe(X) = k\\theta$ and $\\var(X) = k\\theta^2$.\n\\end{corollary}\n% proof\n\\begin{proof}\n\\begin{align*}\nM'(t)\t& = (-k)(1-\\theta t)^{-k-1}(-\\theta) \\\\\nM''(t)\t& = (-k)(-k-1)(1-\\theta t)^{-k-2}(-\\theta)^2\n\\end{align*}\nHence,\n\\begin{align*}\n\\expe(X)\t& = M'(0) = k\\theta, \\\\\n\\var(X)\t\t& = M''(0)- M'(0)^2 = k(k+1)\\theta^2 - k^2\\theta^2 = k\\theta^2.\n\\end{align*}\n\\end{proof}\n\nWe now derive two useful properties of the gamma disribution.\n% lemma: sum of two independent \n\\begin{lemma}\\label{lem:properties_of_gamma_distribution}\n\\ben\n\\it If $X\\sim\\text{Gamma}(k,\\theta)$ and $a\\in\\R$ is a constant, then $aX\\sim\\text{Gamma}(k,a\\theta)$.\n\\it If $X_1\\sim\\text{Gamma}(k_1,\\theta)$ and $X_2\\sim\\text{Gamma}(k_2,\\theta)$ are independent, then $X_1+X_2\\sim\\text{Gamma}(k_1+k_2,\\theta)$.\n\\een\n\\end{lemma}\n\\begin{proof}\n\\ben\n\\it\n\\[\nM_{aX}(t) = \\expe(e^{t(aX)}) = \\expe(e^{(at)X}) = M_X(at) = \\frac{1}{\\big(1-\\theta (at)\\big)^k} = \\frac{1}{\\big(1-(a\\theta)t\\big)^k} \n\\]\nwhidh is the MGF of the $\\text{Gamma}(k,a\\theta)$ distribution.\n\\it\nThe $MGFs$ of $X_1$ and $X_2$ are:\n\\[\nM_{X_1}(t) = \\frac{1}{(1-\\theta t)^{k_1}}\n\\quad\\text{and}\\quad\nM_{X_2}(t) = \\frac{1}{(1-\\theta t)^{k_2}},\n\\]\nand since $X_1$ and $X_2$ are independent, \n\\[\nM_{X_1+X_2}(t) \n=\tM_{X_1}(t)M_{X_2}(t) \n= \\frac{1}{(1-\\theta t)^{k_1+k_2}}\n\\]\nwhich is the MGF of the $\\text{Gamma}(k_1+k_2,\\theta)$ distribution.\n\\een\n\\end{proof}\n\n\n%-----------------------------\n\\subsection{The $\\chi^2$ distribution}\n\n% defn: chi-squared distribution\n\\begin{definition}\\label{defn:chisquared_dist}\nThe $\\chi^2_{n}$ distribution is defined by the PDF\n\\[\nf(x) = \\begin{cases}\n\t\\displaystyle\\frac{1}{\\Gamma(n/2)2^{n/2}}\\,x^{n/2-1} e^{-x/2} & \\text{for $x>0$}, \\\\\n\t0\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise,}\n\\end{cases}\n\\]\nwhere the parameter $n$ is called the \\emph{degrees of freedom}.\n\\end{definition}\n\nThe $\\chi^2_{n}$ distribution is a special case of the $\\Gamma(k,\\theta)$ distribution, with $k=n/2$ and $\\theta=2$. Thus if $X\\sim\\chi^2_{n}$, it follows that \n\\bit\n\\it $M_X(t) = (1-2t)^{-n/2}$ for $t<1/2$;\n\\it $\\expe(X) = n$ and $\\var(X)=2n$.\n\\eit\n\n% corollary\nWe also have the following corollary of Lemma~\\ref{lem:properties_of_gamma_distribution}.\n\\begin{corollary}\\label{cor:sum_of_two_independent_chisquared}\nIf $X_1\\sim\\chi^2_{m}$ and $X_2\\sim\\chi^2_{n}$ are independent, then $X_1+X_2\\sim\\chi^2_{m+n}$.\n\\end{corollary}\n\nNext we show that the square of a standard normal variable has $\\chi^2_1$ distribution.\n% lemma\n\\begin{lemma}\\label{lem:standard_normal_squared}\nIf $Z\\sim N(0,1)$ then $Z^2\\sim\\chi^2_{1}$.\n\\end{lemma}\n\\begin{proof}\nLet $U=Z^2$. Then the CDF of $U$ (for $u\\geq 0$) is\n\\[\nF(u) = \\prob(U\\leq u) = \\prob(-\\sqrt{u}\\leq Z \\leq \\sqrt{u})\n\\]\nwhich (by symmetry) we can write as\n\\[\nF(u) = \\int_{0}^{\\sqrt{u}}\\frac{1}{\\sqrt{2\\pi}} e^{-u^2/2}\\,du\t\n\\]\nfor $u\\geq 0$ (and zero otherwise). Now change the variable of integration by writing $y=u^2$:\n\\[\nF(u) = \\int_{0}^{\\sqrt{y}}\\frac{1}{\\sqrt{2\\pi}}\\frac{1}{\\sqrt{y}} e^{-y/2}\\,dy \\quad(v\\geq 0).\n\\]\nHence the PDF $f(u) = F'(u)$ is \n\\[\nf(u) = \\frac{1}{\\sqrt{2\\pi}} u^{1/2} e^{-u/2}\n\\]\nfor $u\\geq 0$ (and zero otherwise). Since $\\Gamma(1/2)=\\sqrt{\\pi}$, this is the PDF of the $\\chi^2_1$ distribution.\n\\end{proof}\n\n% corollary\nCorollary~\\ref{cor:sum_of_two_independent_chisquared} and Lemma~\\ref{lem:standard_normal_squared} combine to yield the following.\n\\begin{corollary}\nIf $Z_1,Z_2,\\ldots,Z_n$ are independent standard normal variables, then $\\displaystyle\\sum_{i=1}^n Z_i^2\\sim\\chi^2_n$.\n\\end{corollary}\n\n%--------------------------------------------------\n\\subsection{The non-central chi-squared distribution}\n%--------------------------------------------------\n\\begin{definition}\nLet $X_1,X_2,\\ldots,X_n$ be independent random variables with $X_i\\sim N(\\mu_i,1)$. The distribution of the sum-of-squares\n\\[\nW=\\sum_{i=1}^n X_i^2\n\\]\nis called the \\emph{non-central chi-squared distribution}, with $n$ degrees of freedom and non-centrality parameter \n\\[\n\\lambda = \\sum_{i=1}^n \\mu_i^2.\n\\]\n\\end{definition}\nWe write this as $W\\sim\\chi^2_n(\\lambda)$, in which case\n\\[\n\\expe(W)=n+\\lambda \\quad\\text{and}\\quad \\var(W)=2(n+2\\lambda).\n\\]\n\nWhen $\\lambda=0$, all $\\mu_i$ must be zero and the $\\chi^2_n(\\lambda)$ distribution reduces to the ordinary $\\chi^2_n$ distribution. Any non-zero mean $\\mu_i$ increases the value of $\\lambda$, and hence increases $\\expe(W)$ and $\\var(W)$ compared to those of the ordinary $\\chi^2_n$ distribution. \n\n%--------------------------------------------------\n\\subsubsection{One-sample test of variance}\n%--------------------------------------------------\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\mu,\\sigma^2)$ distribution, and consider the null hypothesis $H_0:\\sigma^2=\\sigma_0^2$ against a suitable alternative, where $\\sigma_0>0$ is fixed. If $\\mu$ is known, we use the test statistic\n\\[\nT = \\sum_{i=1}^n \\left(\\frac{X_i-\\mu}{\\sigma_0}\\right)^2 \\sim \\chi^2_n \\quad\\text{under $H_0$.}\n\\]\nIf $\\mu$ is unknown, we replace it by the sample mean $\\bar{X}$, in which case $T\\sim\\chi^2_{n-1}$.\n\n%Under the alternative hypothesis $H_1:\\sigma^2\\neq\\sigma^2_0$, \n%\\[\n%T(\\mathbf{X}) = \\left(\\frac{\\sigma}{\\sigma_0}\\right)^2\\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma}\\right)^2  \n%\\]\n%Because the $\\chi^2_n$ distribution is a special case of the $\\text{Gamma}(k,\\theta)$ distribution with $k=n/2$ and $\\theta=2$, it follows by Lemma\\ref{lem:properties_of_gamma_distribution} that $T\\sim\\text{Gamma}(n/2, 2(\\sigma/\\sigma_0)^2)$, for which $\\expe(T)=n(\\sigma/\\sigma_0)^2$ and $\\var(T)=2n(\\sigma/\\sigma_0)^4$. Thus,\n%\\bit\n%\\it for $H_1:\\sigma<\\sigma_0$, the probability mass shifts to the left, so we need a lower-tail test;\n%\\it for $H_1:\\sigma>\\sigma_0$, the probability mass shifts to the right, so we need an upper-tail test.\n%\\eit.\n\n\\begin{exercise} %[One-sample test of variance]\nA quality control supervisor at a paint factory knows that the exact amount each tin contains will vary due to certain uncontrollable factors that affect the amount of fill. The mean fill is important, but equally important is the variation of each fill. If the variance $\\sigma^2$ of the fill is large, some tins will contain too much and others too little. A regulatory agency specifies that the variance of the amount of fill in 250ml tins should be less than $3$. To determine whether or not the process is meeting this specification, the supervisor randomly selects 10 tins and measures the contents of each tin. The mean fill over the sample is found to be $250.78$, and the sample variance is $s^2 = 1.03$. Does the data indicate that the factory is operating within the regulatory limits?\n\\begin{answer}\nWe wish to test the null hypothesis $H_0:\\sigma^2 = 3$ against the alternative $H_1:\\sigma^2 < 3$. We assume that the distribution of the fill amounts is approximately normal, and consider the test statistic \n\\[\nT = \\sum_{i=1}^{n} \\left(\\frac{X_i-\\bar{X}}{\\sigma}\\right)^2 = \\frac{(n-1)s^2}{\\sigma^2},\n\\]\nwhere $s^2$ is the sample variance of the fill amounts. Taking $n=10$, the distribution of our test statistic under the null hypothesis $H_0:\\sigma^2 = 3$ is\n\\[\nT \\sim \\chi^2_9.\n\\]\n\\bit\n\\it From tables, the critical value for a lower-tailed test at $\\alpha=0.05$ is $T_{0.95} = 3.326$.\n\\it The observed value of the test statistic (under the null hypothesis) is\n\\[\nT = \\frac{(n-1)s^2}{\\sigma^2} = \\frac{9\\times 1.03}{3} = 3.09.\n\\]\n\\eit \nThe test statistic lies in the rejection region, so the supervisor can reject $H_0:\\sigma^2=3$ and conclude that the variance of the fill amounts is less than $3$. The supervisor can be confident that the factory is operating within the desired limits of variability. \n\\end{answer}\n\\end{exercise}\n%%--------------------------------------------------\n%\\subsubsection{One-sample tests}\n%%--------------------------------------------------\n%Let $X\\sim N(\\mu,\\sigma^2)$.\n%\n%\\ben\n%\\it % \\mu unknown, \\sigma^2 known\n%If $\\mu$ is unknown but $\\sigma^2$ is known, a test statistic for $H_0:\\mu=\\mu_0$ against a suitable alternative is the standardized sum\n%\\[\n%Z(\\mathbf{X}) = \\frac{1}{\\sqrt{n}}\\sum_{i=1}^n\\left(\\frac{X_i-\\mu_0}{\\sigma}\\right) \\quad\\sim N(0,1) \\text{ under $H_0:\\mu=\\mu_0$.}\n%\\]\n%\\bit\n%If $\\sigma^2$ also unknown, we replace it by the sample variance $s^2$, in which case $Z\\sim t_{n-1}$ under $H_0$.\n%\\eit\n%\n%If $\\mu\\neq\\mu_0$, then $X -\\mu_0\\sim N(\\mu-\\mu_0,\\sigma^2)$, so \n%\\[\n%Z(\\mathbf{X}) \n%%\t= \\frac{1}{\\sqrt{n}}\\sum_{i=1}^n\\left(\\frac{X_i-\\mu_0}{\\sigma}\\right)\n%\t= \\frac{1}{\\sqrt{n}}\\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma} + \\frac{\\mu-\\mu_0}{\\sigma}\\right)\n%\\]\n%in which case $Z\\sim N(\\mu-\\mu_0,1)$.\n%\n%Another test statistic for $H_0:\\mu=\\mu_0$ is the standardized \\emph{sum-of-squares},\n%\\[\n%T(\\mathbf{X}) = \\sum_{i=1}^n\\left(\\frac{X_i-\\mu_0}{\\sigma}\\right)^2  \\quad\\sim\\chi^2_n \\text{ under $H_0:\\mu=\\mu_0$.}\n%\\]\n%\n%\\bit\n%\\it If $\\mu\\neq\\mu_0$, $T\\sim\\chi^2_n(\\lambda)$ where $\\lambda= n(\\mu-\\mu_0)^2$.\n%\\eit\n%\n%\\it % \\mu known, \\sigma^2 unknown\n%If $\\mu$ is known but $\\sigma^2$ is unknown, the standardized sum-of-squares can also be used as a test statistic for $H_0:\\sigma^2=\\sigma^2_0$ against a suitable alternative,\n%\\[\n%T(\\mathbf{X}) = \\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma_0}\\right)^2  \\quad\\sim\\chi^2_n \\text{ under $H_0:\\sigma^2=\\sigma^2_0$.}\n%\\]\n%\\bit\n%\\it If $\\mu$ is also unknown we replace it by the sample mean $\\bar{X}$, in which case $T\\sim\\chi^2_{n-1}$ under $H_0$.\n%\\eit\n%\n%Under the alternative $H_1:\\sigma^2\\neq\\sigma^2_0$, \n%\\[\n%T(\\mathbf{X}) \n%%\t= \\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma_0}\\right)^2  \n%\t= \\left(\\frac{\\sigma}{\\sigma_0}\\right)^2\\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma}\\right)^2  \n%\\]\n%in which case $T\\sim\\text{Gamma}(n/2, 2(\\sigma/\\sigma_0)^2)$, for which $\\expe(T)=n(\\sigma/\\sigma_0)^2$ and $\\var(T)=2n(\\sigma/\\sigma_0)^4$.\n%\n%%\\begin{remark}\n%%If $\\sigma^2$ unknown, we replace it by the sample variance $s^2$, in which case $Z\\sim t_{n-1}$ under $H_0$.\n%%If $\\mu$ is unknown, we replace it by the sample mean $\\bar{X}$, in which case $T\\sim\\chi^2_{n-1}$ under $H_0$.\n%%\\end{remark}\n%\n%%--------------------------------------------------\n%\\subsubsection{Two-sample tests}\n%%--------------------------------------------------\n%Let $X\\sim N(\\mu_1,\\sigma^2)$ and $Y\\sim N(\\mu_2,\\sigma^2)$ \n%\n\n%====================================================================\n\\subsection{The $F$ distribution}\n%====================================================================\n\\begin{definition}\nLet $T_1$ and $T_2$ be independent random variables with $T_1\\sim\\chi^2_m$ and $T_2\\sim\\chi^2_n$. The distribution of the ratio\n\\[\nF = \\frac{T_1/m}{T_2/n}.\n\\]\nis called the \\emph{$F$-distribution with $m$ and $n$ degrees of freedom}, and denoted by $F\\sim F_{m,n}$.\n\\end{definition}\n\n%--------------------------------------------------\n\\subsubsection{Two-sample tests of variance}\n%--------------------------------------------------\nLet $X_1,X_2,\\ldots,X_m$ be a random sample from the $N(\\mu_1,\\sigma_1^2)$ distribution, let $Y_1,Y_2,\\ldots,Y_n$ be an independent random sample from the $N(\\mu_2,\\sigma_2^2)$ distribution, and consider the null hypothesis $H_0:\\sigma_1^2 = \\sigma_2^2$ against a suitable alternative. \n\n%If $\\mu_1$ and $\\mu_2$ are known, we use the ratio of the sample mean estimatorss of variance:\n\n\\ben\n\\it % known means\nIf $\\mu_1$ and $\\mu_2$ are known, we use the ratio of the sample mean estimators of variance as a test statistic,\n\\[\nF \t= \\frac{\\hat{\\sigma}_1^2}{\\hat{\\sigma}_2^2}\n\t= \\frac{\\displaystyle\\frac{1}{m}\\sum_{i=1}^m (X_i-\\mu_1)^2}{\\displaystyle\\frac{1}{n}\\sum_{j=1}^n (Y_i-\\mu_2)^2}\n\t= \\frac{\n\t\t\\displaystyle\\sigma_1^2\\left[\\frac{1}{m}\\sum_{i=1}^m \\left(\\frac{X_i-\\mu_1}{\\sigma_1}\\right)^2\\right]\n\t}{\n\t\t\\displaystyle\\sigma_2^2\\left[\\frac{1}{n}\\sum_{j=1}^n \\left(\\frac{Y_j-\\mu_2}{\\sigma_2}\\right)^2\\right]\n\t}.\n\\]\nUnder $H_0:\\sigma_1^2 = \\sigma_2^2$, this statistic has the $F_{m,n}$ distribution.\n\\it % unknown means\nIf $\\mu_1$ and $\\mu_2$ are unknown, we use the ratio of the sample variances as a test statistic,\n\\[\nF \t= \\frac{s_1^2}{s_2^2}\n\t= \\frac{\\displaystyle\\frac{1}{m-1}\\sum_{i=1}^m (X_i-\\bar{X})^2}{\\displaystyle\\frac{1}{n-1}\\sum_{j=1}^n (Y_i-\\bar{Y})^2}\n\t= \\frac{\n\t\t\\displaystyle\\sigma_1^2\\left[\\frac{1}{m-1}\\sum_{i=1}^m \\left(\\frac{X_i-\\bar{X}}{\\sigma_1}\\right)^2\\right]\n\t}{\n\t\t\\displaystyle\\sigma_2^2\\left[\\frac{1}{n-1}\\sum_{j=1}^n \\left(\\frac{Y_j-\\bar{Y}}{\\sigma_2}\\right)^2\\right]\n\t}.\n\\]\nUnder $H_0:\\sigma_1^2 = \\sigma_2^2$, this ratio has the $F_{m-1,n-1}$ distribution.\n\\een\n\n\\bit\n\\it For $H_1:\\sigma_1<\\sigma_2$, the probability mass shifts to the left so we need a lower-tail test;\n\\it for $H_1:\\sigma_1>\\sigma_2$, the probability mass shifts to the right so we need an upper-tail test.\n\\eit.\n\nNote that statistical tables usually only give upper-tail percentage points: if necessary, we can convert between the two using the fact that if $F\\sim F_{m,n}$, then $1/F\\sim F_{n,m}$.\n\n\\begin{exercise}%[two-sample test of variance]\nA researcher wants to compare the metabolic rates of white mice subjected to different drugs. The weights of the mice may affect their metabolic rates, so the researcher wishes to obtain mice that are relatively homogeneous with respect to weight. Five hundred mice will be needed to complete the study. Currently, 18 mice from supplier 1 and another 13 mice from supplier 2 are available for comparison. The researcher weighs these mice and finds that the sample standard deviations are $s_1=0.2021$ and $s_2=0.0982$ respectively. Is there sufficient evidence to indicate a significant difference in the variability of the weight of mice obtained from the two suppliers at the $\\alpha=0.1$ level?\n\\begin{answer}\nLet $\\sigma^2_1$ and $\\sigma^2_2$ be the population variances for mice from Supplier 1 and Supplier 2 respectively. The null hypothesis is $H_0:\\sigma^2_1=\\sigma^2_2$, and our test statistic is the ratio of the sample variances,\n\\[\nF = \\frac{s^2_1}{s^2_2}\n\\]\n\\bit\n\\it We reject $H_0$ if the observed $F$-ratio exceeds the tabulated value $F_{1-\\alpha/2}=F_{0.95} = 2.38$.\n\\it The observed value is $F=(0.2021)^2/(0.0982)^2=4.24$.\n\\eit\nThe observed value lies in the rejection region, so we reject the null hypothesis and conclude that the weights of mice from Supplier 2 tend to be more homogeneous that the weights of mice from Supplier 1.\n\\end{answer}\n\\end{exercise}\n\n%-------------------------------------------------\n\\section{Analysis of variance}\\label{sec:anova}\n\nAnalysis-of-variance (ANOVA) is a way of testing hypotheses about means by looking at sample variances. Consider a population consisting of $k$ groups. We assume that all observations are independent and normally distributed with the same variance, but whose means might be different depending on the group to which they belong. \n\n\\medskip\nLet $\\mu_i$ denote the mean of the $i$th group. We wish to test the null hypothesis that all group means are equal, against the alternative that they are not:\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\\medskip\nSuppose we obtain an independent random sample of observations 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\n%\\bit\n%\\it Groups are indexed by $i=1,2,\\ldots,k$.\n%\\it Observations within the $i$th group are indexed by $j=1,2,\\ldots,n_i$.\n%\\it We assume that all observations are independent and have equal variance.\n%\\eit\n\n%====================================================================\n\\subsection{The test statistic}\n%====================================================================\n\n\\bit\n\\it Let $N=\\sum_{i=1}^k n_i$ be the total number of observations. \n\\it Let $\\bar{Y}_i = \\frac{1}{n_i}\\sum_{j=1}^{n_i} Y_{ij}$ be the sample mean of the $i$th group.% (for $i=1,2,\\ldots k$).\n\\it Let $\\bar{Y} = \\frac{1}{N}\\sum_{i=1}^k\\sum_{j=1}^{n_i} Y_{ij}$ be the overall sample mean.\n\\eit\n\nThe total deviation of a single observation from the overall sample mean can be divided into two components:\n\\[\n\\begin{array}{ccccc}\n(Y_{ij}-\\bar{Y})\t\t& = & (Y_{ij}-\\bar{Y}_i)\t\t\t& + & (\\bar{Y}_i-\\bar{Y})  \\\\[1ex]\n\\text{Total deviation} \t& \t& \\text{Unexplained deviation}\t& \t& \\text{Explained deviation} \t\n\\end{array}\n\\]\n\nTo test the null hypothesis $H_0:\\mu_1=\\mu_2=\\ldots=\\mu_k$, we define the following sums-of-squares:\n\n%Under $H_0$, we have independent estimates of $\\sigma^2$:\n%\\bit\n%\\it Between groups: $\\frac{1}{k-1}\\sum_{i=1}^{k}(\\bar{Y}_{i\\cdot} - \\bar{Y}_{..})^2$\n%\\it Within groups: $\\frac{1}{n_i-1}\\sum_{j=1}^{n_i}(Y_{ij} - \\bar{Y}_{i\\cdot})^2$\n%\\eit\n%\n%\n%\n%\n\\[\n\\begin{array}{lll}\nSST\t& = \\displaystyle\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\bar{Y})^2.\n\\qquad\\qquad & \\text{The \\textbf{total} sum-of-squares.} \\\\\nSSG\t& = \\displaystyle\\sum_{i=1}^k n_i (\\bar{Y}_i-\\bar{Y})^2.\n\\qquad & \\text{The \\textbf{between-groups} sum-of-squares.} \\\\\nSSE\t& = \\displaystyle\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\bar{Y}_i)^2.\n\\qquad & \\text{The \\textbf{error} sum-of-squares.} \\\\\n\\end{array}\n\\]\n\nThe following lemma is easily proved.\n\\begin{lemma}\n$SST = SSG + SSE$.\n\\end{lemma}\n%\\begin{proof}\n%Exercise.\n%\\begin{align*}\n%S_T\n%\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\bar{Y}_{\\cdot\\cdot})^2 \\\\\n%\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\bar{Y}_{i\\cdot}+\\bar{Y}_{i\\cdot}-\\bar{Y}_{\\cdot\\cdot})^2 \\\\\n%\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} \\big[(Y_{ij}-\\bar{Y}_{i\\cdot})^2 + 2(Y_{ij}-\\bar{Y}_{i\\cdot})(\\bar{Y}_{i\\cdot}-\\bar{Y}_{\\cdot\\cdot})+ (\\bar{Y}_{i\\cdot}-\\bar{Y}_{\\cdot\\cdot})^2\\big] \\\\\n%\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\bar{Y}_{i\\cdot})^2 + \\sum_{i=1}^k n_i(\\bar{Y}_{i\\cdot}-\\bar{Y}_{\\cdot\\cdot})^2 \\\\\n%\t& = S_E + S_G.\n%\\end{align*}\n%\\end{proof}\n\n%\\bit\n%\\it $S_T$ is the total squared deviation,\n%\\it $S_G$ is the squared deviation explained by group membership,\n%\\it $S_E$ is the residual squared deviation.\n%\\it Note that $SST = SSG + SSE$.\n%\\it[]\n%\\it If the ratio $SS_G/SS_E$ is large, we might be inclined to reject the null hypothesis that all group means are equal.\n%\\eit\nIntuitively, if the ratio $SSG/SSE$ is large, we might be inclined to reject the null hypothesis that all group means are equal.\n\n% lemma: distribution of SS_E\n\\begin{lemma}[The distribution of $SSE$]\n\\[\n%\\frac{SS_E}{\\sigma^2} = \n\\frac{1}{\\sigma^2}\\sum_{i=1}^k\\sum_{j=1}^{n_i}(Y_{ij}-\\bar{Y}_i)^2 \\sim \\chi^2_{N-k}.\n\\]\n\\end{lemma}\n\n\\begin{proof}\nFor the $i$th group we have $Y_{ij}\\sim N(\\mu_i,\\sigma^2)$ so by independence,\n\\[\n\\frac{1}{\\sigma^2}\\sum_{j=1}^{n_i}(Y_{ij}-\\mu_i)^2 \\sim \\chi^2_{n_i}.\n\\]\nReplacing the unknown expectation $\\mu_i$ by the sample mean $\\bar{Y}_i$, we obtain\n\\[\n\\frac{1}{\\sigma^2}\\sum_{j=1}^{n_i}(Y_{ij}-\\bar{Y}_i)^2 \\sim \\chi^2_{n_i-1}.\n\\]\nBy Corollary~\\ref{cor:sum_of_two_independent_chisquared}, if $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}-\\bar{Y}_i)^2 \\sim \\chi^2_{N-k}.\n\\]\n%as required.\n\\end{proof}\n\n% lemma: distribution of SS_G\n\\begin{lemma}[The distribution of $SSG$]\\label{lem:ssg}\nLet $\\mu$ be the expected value of the $Y_{ij}$ across the entire population. Then\n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^k n_i (\\bar{Y}_i - \\bar{Y})^2 \\sim \\chi^2_{k-1}(\\lambda)\n\\quad\\text{where}\\quad\\lambda = \\sum_{i=1}^k n_i(\\mu_i-\\mu)^2.\n\\]\n\\end{lemma}\n\n% proof\n\\begin{proof}\nFor the $i$th group we have $\\bar{Y}_i \\sim N(\\mu_i,\\sigma^2/n_i)$, so\n\\[ \n\\sqrt{n_i}\\left(\\frac{\\bar{Y}_i - \\mu}{\\sigma}\\right) \\sim N(\\mu_i-\\mu,1)\n\\]\nBecause all observations are independent of each other the $\\bar{Y}_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 $\\bar{Y}$, we obtain \n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^k n_i (\\bar{Y}_i - \\bar{Y})^2 \\sim \\chi^2_{k-1}(\\lambda).\n\\]\n%as required.\n\\end{proof}\n\n% remark\n\\begin{remark}\nUnder the null hypothesis, each group mean $\\mu_i$ is equal to the population mean $\\mu$, in which case $\\lambda=0$ and hence $SS_G/\\sigma^2 \\sim \\chi^2_{k-1}$. Otherwise we must have $SS_G/\\sigma^2 \\sim \\chi^2_{k-1}(\\lambda)$ where $\\lambda>0$, in which case $SS_G/\\sigma^2$ is likely to be larger than it would be if $H_0$ is true.\n\\end{remark}\n\n\\begin{theorem}[Test Statistic for ANOVA]\nLet\n\\[\ns^2_G = \\frac{1}{k-1}\\sum_{i=1}^k n_i (\\bar{Y}_i-\\bar{Y})^2\n\\quad\\text{and}\\quad\ns^2_E = \\frac{1}{N-k}\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\bar{Y}_i)^2,\n\\]\nand define the test statistic $F = s^2_G/s^2_E$. Under the null hypothesis $H_0:\\mu_1=\\mu_2=\\ldots=\\mu_k$, %this has the $F_{k-1,N-k}$ distribution.\n\\[\n%F = \\displaystyle\\frac{s^2_G}{s^2_E} \\sim F_{k-1,N-k}.\n%F = s^2_G/s^2_E \\sim F_{k-1,N-k}.\nF \\sim F_{k-1,N-k}.\n\\]\n\\end{theorem}\n\n\\begin{remark}\n%By Lemma~\\ref{lem:ssg}, if $H_0$ does not hold then $SSG/\\sigma^2\\sim\\chi^2(\\lambda)$ where $\\lambda>0$, so $F$ is likely to be larger than it would be if $H_0$ is true. \nBy the previous remark, we see that an upper-tail test is required: $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\t\t& \\qquad df\\qquad\\mbox{}& \\qquad SS\\qquad\\mbox{}& \\qquad MS\\qquad\\mbox{}& \\qquad F\\qquad\\mbox{}\t\\\\ \\hline\nBetween Groups\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\t\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\t\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 an 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 yield the following sums-of-squares:\n\\[\nSST = 8762.9688,\\quad SSG = 3848.71875 \\text{\\quad and\\quad} SSE = 4914.2.\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\t\t& df\t& SS\t\t& MS\t\t& F \t\t\t\\\\ \\hline\nBetween-Groups\t& 7\t\t& 3848.72\t& 549.8170\t& 2.6852\t\t\\\\ \\hline\nError\t\t\t& 24\t& 4914.25\t& 204.7604 \t& \t\t\t\\\\ \\hline\nTotal\t\t\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\n\n%-------------------------------------------------\n\\section{Linear regression I}\\label{sec:slr1}\n\n%-----------------------------\n%\\subsection{}\nWe wish to investigates how one random variable $X$ influences the behaviour of another random variable $Y$.\n\n\\bit\n\\it $X$ is called the \\emph{explanatory variable}, or the \\emph{independent} variable.\n\\it $Y$ is called the \\emph{response variable}, or the \\emph{dependent} variable.\n\\eit\n\nSuppose we observe that $X$ takes the value $x$. Unless $Y$ is completely determined by $X$, we cannot predict its value with certainty, so we focus on the problem of estimating its conditional expectation $E(Y|X=x)$. This leads us to represent $Y$ as the sum of two random variables:\n\\[\nY = \\mu(X) + \\epsilon\n\\]\nwhere \n\\bit\n\\it $\\mu(x) = \\expe(Y|X=x)$ is called the \\emph{regression function}, and\n\\it $\\epsilon = Y - \\expe(Y|X)$ is called the \\emph{error variable} (whose distribution may depend on $X$).\n\\eit\n \n% lemma\n%By the law of total expectation, the expected value of the error variable is zero.\n\\begin{lemma}\nThe expected value of the error variable is zero.\n%$\\expe(\\epsilon) = 0$.\n\\end{lemma}\n\\begin{proof}\nBy the law of total expectation, \n\\[\n\\expe(\\epsilon) = \\expe\\big[Y - \\expe(Y|X)\\big] = \\expe(Y) - \\expe\\big[\\expe(Y|X)\\big] = \\expe(Y)-\\expe(Y) = 0.\n\\]\n\\end{proof}\n\n% lemma\n%The law of total variance divides the variance of $Y$ into a component attributed to the explanatory variable $X$, and a component attributed to the error variable $\\epsilon$.\nThe following lemma shows that the variance of $Y$ can be divided into a component attributed to the explanatory variable $X$, and a component attributed to the error variable $\\epsilon$.\n\\begin{lemma}\n%$\\var(Y) = \\var(\\mu) + \\expe\\big[\\var(\\epsilon|X)\\big]$.\nIf the error variable $\\epsilon$ is independent of the explanatory variable $X$,\n\\[\\var(Y) = \\var(\\mu) + \\var(\\epsilon).\n\\]\n\\end{lemma}\n\\begin{proof}\n$\\epsilon = Y - \\expe(Y|X)$, so (by the definition of conditional variance),\n\\[\n\\var(Y|X) = \\expe\\big(\\big[Y-\\expe(Y|X)\\big]^2|X\\big) = \\expe(\\epsilon^2|X) = \\var(\\epsilon|X) = \\var(\\epsilon).\n\\]\nBy the law of total variance,\n\\begin{align*}\n\\var(Y) \n\t& = \\var\\big[\\expe(Y|X)\\big] + \\expe\\big[\\var(Y|X)\\big] \\\\\n\t& = \\var\\big[\\mu(X)\\big] + \\expe\\big[\\var(\\epsilon)\\big]\n\t& = \\var\\big[\\mu(X)\\big] + \\var(\\epsilon).\n\\end{align*}\n\\end{proof}\n\n\\begin{remark}\n\\bit\n\\it $\\var(\\mu) = \\var\\big[\\expe(Y|X)\\big]$ is the \\emph{explained} variance.\n%\\it $\\expe\\big[\\var(\\epsilon|X)\\big] = \\expe\\big[\\var(Y|X)\\big]$ is the \\emph{unexplained} variance.\n\\it $\\var(\\epsilon) = \\var(Y|X)$ is the \\emph{unexplained} variance.\n\\eit\n\\end{remark}\n\n\n%-----------------------------\n\\subsection{Linear models}\n\n\\begin{definition}\nA regression function $\\mu(x)=\\expe(Y|X=x)$ is called a \\emph{linear model} if it is linear in its parameters:\n\\end{definition}\n%For example,\n\\bit\n\\it $\\mu(x) = \\alpha + \\beta x + \\gamma x^2$ is a linear model.\n\\it $\\mu(x) = \\alpha e^{\\beta x}$ is not a linear model.\n\\eit\n\n\\begin{definition}\nA \\emph{simple} linear model is a model of the form $\\mu(x) = \\alpha + \\beta x$.\n\\end{definition}\n\nThe simple linear model yields\n\\[\nY = \\alpha + \\beta X + \\epsilon \\quad\\text{where}\\quad \\epsilon\\sim N(0,\\sigma^2).\n\\]\n\\fbox{\\begin{minipage}{\\linewidth}\\centering We assume that the error variable $\\epsilon$ is \\emph{independent} of the explanatory variable $X$.\\end{minipage}}\n\n\\bigskip\nIf we observe that $X=x$, we see that $Y\\sim N(\\alpha+\\beta x, \\sigma^2)$ and in particular,\n\\[\n\\expe(Y|X=x) = \\alpha + \\beta x\n\\quad\\text{and}\\quad\n\\var(Y|X=x) = \\sigma^2.\n\\]\n\n%-----------------------------\n\\subsection{Parameter estimation}\nLet $(X_1,Y_1),(X_2,Y_2),\\ldots,(X_n,Y_n)$ be a random sample of observations from the joint distribution of $X$ and $Y$. \n% theorem: mle of alpha and beta\n\\begin{theorem}\nThe maximum likelihood estimators of $\\alpha$ and $\\beta$ are given by\n\\[\n\\hat{\\alpha} = \\bar{Y}-\\hat{\\beta}\\bar{X}\n\\text{\\qquad and\\qquad}\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2}\n\\text{\\qquad respectively.}\n\\]\n\\end{theorem}\n\n% proof\n\\begin{proof}\nLet $\\{(x_1,y_1),(x_2,y_2),\\ldots,(x_n,y_n)\\}$ be a realisation of the sample. The likelihood function is:\n\\begin{align*}\nL(\\alpha,\\beta,\\sigma^2)\n\t& = \\prod_{i=1}^n \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{y_i-(\\alpha+\\beta x_i)}{\\sigma}\\right)^2\\right] \\\\\n\t& = \\left(\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\right)^n \\exp\\left[-\\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2\\right].\n\\end{align*}\nThe log-likelihood function is:\n\\[\n\\ell(\\alpha,\\beta,\\sigma^2)\n\t= - \\frac{n}{2}\\log(2\\pi\\sigma^2) - \\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\n\nThe MLE estimates of $\\alpha$ and $\\beta$ are those values that minimise the sum of squared errors:\n\\[\nH(\\alpha,\\beta) = \\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2\n\\]\n\\bit\n\\it To minimize $H(\\alpha,\\beta)$ is known as the \\emph{method of least squares}.\n\\eit\n\n% partial derivatives\nThe partial derivatives of $H(\\alpha,\\beta)$ with respect to $\\alpha$ and $\\beta$ are\n\\begin{align*}\n\\frac{\\partial H}{\\partial\\alpha} \n\t& = 2\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big] (-1) \\\\\n\\frac{\\partial H}{\\partial\\beta} \n\t& = 2\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big] (-x_i) \\\\\n\\end{align*}\n\nTo find the MLEs of $\\alpha$ and $\\beta$, we set the partial derivatives to equal zero.\n% alpha\n\\begin{align*}\n\\frac{\\partial H}{\\partial\\alpha} = 0\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n y_i- n\\alpha -\\beta\\sum_{i=1}^n x_i = 0 \\\\\n\t& \\ \\Rightarrow\\  n\\alpha  = \\sum_{i=1}^n y_i- \\beta\\sum_{i=1}^n x_i \\\\\n\t& \\ \\Rightarrow\\  \\alpha = \\bar{y}-\\beta\\bar{x}.\n\\end{align*}\n\n% beta\n\\begin{align*}\n\\frac{\\partial H}{\\partial\\beta} =0\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n x_i y_i - \\alpha\\sum_{i=1}^n x_i -\\beta\\sum_{i=1}^n x_i^2 = 0 \\\\\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n x_i y_i - (\\bar{y}-\\beta\\bar{x})\\sum_{i=1}^n x_i -\\beta\\sum_{i=1}^n x_i^2 = 0 \\\\\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n x_i(y_i-\\bar{y}) - \\beta\\sum_{i=1}^n x_i(x_i-\\bar{x}) = 0 \\\\\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n (x_i-\\bar{x})(y_i-\\bar{y}) - \\beta\\sum_{i=1}^n (x_i-\\bar{x})^2 = 0 \\\\\n\t& \\ \\Rightarrow\\  \\beta = \\frac{\\sum_{i=1}^n (x_i-\\bar{x})(y_i-\\bar{y})}{\\sum_{i=1}^n (x_i-\\bar{x})^2}\n\\end{align*}\n\nThe maximum-likelihood estimators of $\\alpha$ and $\\beta$ are therefore\n\\[\n\\hat{\\alpha} = \\bar{Y}-\\hat{\\beta}\\bar{X}\n\\text{\\quad and\\quad}\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2}.\n\\]\n\\end{proof}\n\n%-----------------------------\n\\subsection{Residual variance}\n\n\\begin{definition}\n%Let $(x_1,x_2,\\ldots,x_n)$ be a realisation of the marginal sample $(X_1,X_2,\\ldots,X_n)$.\n%Given $X=x$,\n\n\\ben\n\\it $\\hat{y} = \\hat{\\alpha} + \\hat{\\beta}X$ is called the \\emph{predicted value of $Y$} at $X$.\n\\it $\\hat{\\epsilon} = Y - \\hat{y}$ is called the \\emph{residual variable} at $X$.\n\\een\n\\end{definition}\n\n% theorem: mle of alpha and beta\n\\begin{theorem}\nThe maximum likelihood estimator of the error variance $\\sigma^2$ is the sample mean of the squared residuals,\n\\[\n\\hat{\\sigma}^2 = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \n\\text{\\quad where\\quad} \n\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} X_i).\n\\]\n\\end{theorem}\n\n% proof\n\\begin{proof}\nRecall the log-likelihood function:\n\\[\n\\ell(\\alpha,\\beta,\\sigma^2)\n\t= \\frac{n}{2}\\log(2\\pi\\sigma^2) + \\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\nThe first partial derivative of $\\ell(\\alpha,\\beta,\\sigma^2)$ with respect to $\\sigma^2$ is\n\\[\n\\frac{\\partial\\ell}{\\partial(\\sigma^2)} \n\t= \\frac{n}{2\\sigma^2} - \\frac{1}{2(\\sigma^2)^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\nSetting this equal to zero,\n\\[\n\\sigma^2 = \\frac{1}{n}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\nSubstituting our estimates for $\\alpha$ and $\\beta$, we obtain the MLE\n\\[\n\\hat{\\sigma^2} = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \\text{\\quad where\\quad} \\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i)\n\\]\nas required.\n\n\\end{proof}\n\n\\begin{remark}[Residual Analysis]\nOur model assumes that $\\epsilon\\sim N(0,\\sigma^2)$ and that $\\epsilon$ is independent of $X$. To test whether these assumptions hold, we plot the points $(x_i,\\hat{\\epsilon}_i)$ on a scatter diagram. If the assumptions do indeed hold, the points should be evenly spread about the horizontal axis, and the extent of their spread should not depend on the $x$-coordinate. \nThis is an example of \\emph{residual analysis}. \n\\end{remark}\n\n% exercise\n\\begin{exercise}\nFollowing a class test, 10 students were asked about the number of hours they had revised for the test. The data is shown in the table below.\n\\begin{center}\n\\begin{tabular}{|l|cccccccccc|} \\hline\nHours studied ($x$)\t&  4\t &  9 & 10 & 14 &  4 &  7 & 12 & 22 &  1 & 17 \\\\ \nTest score ($y$)\t\t& 31 & 58 & 65 & 73 & 37 & 44 & 60 & 91 & 21 & 84 \\\\ \\hline\n\\end{tabular}\n\\end{center}\nPerform a simple linear regression to estimate the relationship between the number of hours studied and the score achieved in the test.\n\\begin{answer}\n%It is easy to show that \n%\\begin{align*}\n%\\sum_{i=1}^n (x_i - \\bar{x})(y_i - \\bar{y})\t\n%\t\t& = \\sum_{i=1}^n x_iy_i - \\frac{1}{n}\\left(\\sum_{i=1}^n x_i\\right)\\left(\\sum_{i=1}^n y_i\\right) \\text{ and} \\\\\n%\\sum_{i=1}^n (x_i - \\bar{x})^2\t\t\t\t\n%\t\t& = \\sum_{i=1}^n x_i^2 - \\frac{1}{n}\\left(\\sum_{i=1}^n x_i\\right)^2.\n%\\end{align*}\n%\n%From the table,\n%\\bit\n%\\it $n=10$,\n%\\it $\\sum_i x_i = 100$ and $\\sum_i y_i = 564$,\n%\\it $\\sum_i x_i^2 = 1376$ and $\\sum_i x_iy_i = 6945$.\n%\\eit\n%This yields\nTedious calculations yield\n\\[\n\\sum_{i=1}^n(x_i-\\bar{x})^2  = 376 \\text{\\quad and\\quad} \\sum_{i=1}^n (x_i - \\bar{x})(y_i - \\bar{y}) = 1305.\n\\]\nThus\n\\begin{align*}\n\\hat{\\beta}\t\n\t& = \\displaystyle\\frac{\\sum_{i=1}^n (x_i - \\bar{x})(y_i - \\bar{y})}{\\sum_{i=1}^n(x_i-\\bar{x})^2} \n\t= \\displaystyle\\frac{1305}{376}\t= 3.47,\\\\\t\n\\intertext{and}\n\\hat{\\alpha}\n\t& = \\displaystyle\\bar{y} - \\hat{\\beta}\\bar{x} \n\t= \\displaystyle\\frac{564}{10} - \\left(\\frac{1305}{376}\\right)\\left(\\frac{100}{10}\\right) = 21.69.\n\\end{align*}\nThe estimated relationship is therefore $\\hat{y} = 21.69 + 3.471 x$.\n\\end{answer}\n\\end{exercise}\n\n%-------------------------------------------------\n\\section{Linear regression II}\\label{sec:slr2}\n\n%-----------------------------\n%\\subsection{}\nFor a fixed realisation $(x_1,x_2,\\ldots,x_n)$ of the marginal sample $(X_1,X_2,\\ldots,X_n)$, the maximum likelihood estimators $\\hat{\\alpha}$, $\\hat{\\beta}$ and $\\hat{\\epsilon}_i$ are linear functions of $Y_1,Y_2,\\ldots,Y_n$. Because the $Y_i$ are independent normal variables, it thus follows that $\\hat{\\alpha}$, $\\hat{\\beta}$ and $\\hat{\\epsilon}_i$ are also normal variables.\n\n\n% lemma: intercept\n\\begin{lemma}\nThe MLE of the intercept $\\alpha$ satisfies\n$$\\hat{\\alpha} \\sim N(\\alpha,\\sigma^2/n)$$\n\\end{lemma}\n\\begin{proof}\nThe expected value of $\\hat{\\alpha}$ is \n\\begin{align*}\n\\expe(\\hat{\\alpha})\n\t= \\expe(\\bar{Y}-\\beta\\bar{x})\n\t& = \\expe\\left(\\frac{1}{n}\\sum_{i=1}^n Y_i - \\frac{\\beta}{n}\\sum_{i=1}^n x_i\\right) \\\\\n\t& = \\frac{1}{n}\\sum_{i=1}^n \\expe(Y_i) - \\frac{\\beta}{n}\\sum_{i=1}^n x_i \\\\\n\t& = \\frac{1}{n}\\sum_{i=1}^n (\\alpha+\\beta x_i) - \\frac{\\beta}{n}\\sum_{i=1}^n x_i \\\\\n\t& = \\alpha.\n\\end{align*}\n%This shows that $\\hat{\\alpha}$ is an \\emph{unbiased} estimator for $\\alpha$.\nBecause $\\var(Y_i)=\\sigma^2$, the variance of $\\hat{\\alpha}$ is \n\\begin{align*}\n\\var(\\hat{\\alpha})\n\t& = \\var\\left(\\frac{1}{n}\\sum_{i=1}^n Y_i - \\frac{\\beta}{n}\\sum_{i=1}^n x_i\\right) \\\\\n\t& = \\frac{1}{n^2}\\sum_{i=1}^n \\var(Y_i)\n\t= \\frac{\\sigma^2}{n}.\n\\end{align*}\nHence $\\hat{\\alpha} \\sim N(\\alpha,\\sigma^2/n)$, as required.\n\\end{proof}\n\n% lemma: gradient\n\\begin{lemma}%[Gradient]\nThe MLE of the gradient $\\beta$ satisfies\n$$\\hat{\\beta}\\sim N\\left(\\beta,\\frac{\\sigma^2}{\\sum_{i=1}^n(x_i-\\bar{x})^2}\\right)$$\n\\end{lemma}\n\\begin{proof}\nSince $\\expe(Y_i) = \\alpha + \\beta x_i$ and $\\expe(\\bar{Y}) = \\alpha + \\beta\\bar{x}$, the expected value of $\\hat{\\beta}$ is therefore\n\\begin{align*}\n\\expe(\\hat{\\beta})\n\t& = \\expe\\left[\\frac{\\sum_{i=1}^n (x_i-\\bar{x})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (x_i-\\bar{x})^2}\\right] \\\\\n\t& = \\frac{\\sum_{i=1}^n (x_i-\\bar{x})\\expe(Y_i-\\bar{Y})}{\\sum_{i=1}^n (x_i-\\bar{x})^2} \n`\t= \\frac{\\sum_{i=1}^n \\beta(x_i-\\bar{x})^2}{\\sum_{i=1}^n (x_i-\\bar{x})^2} = \\beta.\n\\end{align*}\nUsing the fact that $\\sum_{i=1}^n x_i = n\\bar{x}$, it is easy to see that $\\hat{\\beta}$ can be rewritten as\n\\[\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (x_i-\\bar{x})Y_i}{\\sum_{i=1}^n (x_i-\\bar{x})^2}.\n\\]\nBecause $\\var(Y_i)=\\sigma^2$, the variance of $\\hat{\\beta}$ is\n\\begin{align*}\n\\var(\\hat{\\beta})\n\t= \\var\\left[\\frac{\\sum_{i=1}^n (x_i-\\bar{x})Y_i}{\\sum_{i=1}^n (x_i-\\bar{x})^2}\\right]\n\t& = \\frac{1}{\\left[\\sum_{i=1}^n(x_i-\\bar{x})^2\\right]^2}\\sum_{i=1}^n(x_i-\\bar{x})^2\\var(Y_i) \\\\\n\t& = \\frac{\\sigma^2}{\\sum_{i=1}^n(x_i-\\bar{x})^2}.\n\\end{align*}\nHence $\\hat{\\beta}\\sim N\\left(\\beta,\\frac{\\sigma^2}{\\sum_{i=1}^n(x_i-\\bar{x})^2}\\right)$, as required.\n\\end{proof}\n\nThe residuals $\\hat{\\epsilon}_i$ are normal variables, and the estimated error variance $\\hat{\\sigma}^2$ is the sample mean of the \\emph{squared} residuals. It follows therefore that under a suitable scaling, $\\hat{\\sigma}^2$ has a chi-squared distribution.\n\n\\begin{lemma}%[Error variance]\nThe MLE of the error variance $\\sigma^2$ satisfies\n\\[\n\\frac{n\\hat{\\sigma}}{\\sigma} \\sim \\chi^2_{n-2}\n\\]\n\\end{lemma}\n\\begin{proof}\nRecall that\n\\[\n\\hat{\\sigma}^2 = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon_i}^2\n\\quad\\text{where}\\quad\n\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i).\n\\]\nConsider\n\\begin{align*}\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n\\big[Y_i-(\\alpha+\\beta x_i)\\big]^2 \n\t& = \\frac{1}{\\sigma^2}\\sum_{i=1}^n\\big[(\\hat{\\alpha}-\\alpha) + (\\hat{\\beta}-\\beta)x_i + (Y_i-(\\hat{\\alpha}+\\hat{\\beta}x_i))\\big]^2 \\\\\n\t& = \\frac{n(\\hat{\\alpha}-\\alpha)^2}{\\sigma^2} + \\frac{(\\hat{\\beta}-\\beta)^2}{\\sigma^2}\\sum_{i=1}^n x_i^2 + \\frac{n\\hat{\\sigma}^2}{\\sigma^2}.\n\\end{align*}\nThe first three terms in this expression all have chi-squared distribution.\n\\bit\n\\it\nBecause $Y_i\\sim N(\\alpha+\\beta x_i,\\sigma^2)$ it follows that $\\big[Y_i-(\\alpha+\\beta x_i)\\big]/\\sigma\\sim N(0,1)$, so\n\\[\n\\displaystyle\\frac{1}{\\sigma^2}\\sum_{i=1}^n\\big[Y_i-(\\alpha+\\beta x_i)\\big]^2\\sim\\chi^2_{n}.\n\\]\n\\it\nBecause $\\hat{\\alpha}\\sim N(\\alpha,\\sigma^2/n)$ it follows that $\\sqrt{n}(\\hat{\\alpha}-\\alpha)/\\sigma\\sim N(0,1)$, so\n\\[\n\\displaystyle\\frac{n(\\hat{\\alpha}-\\alpha)^2}{\\sigma^2} \\sim \\chi^2_1.\n\\]\n\\it \nBecause $\\hat{\\beta}\\sim N\\left(\\beta,\\sigma^2/\\sum_{i=1}^n(x_i-\\bar{x})^2\\right)$ it follows that $(\\hat{\\beta}-\\beta)\\sqrt{\\sum_{i=1}^n x_i^2}/\\sigma \\sim N(0,1)$, so\n\\[\n\\frac{(\\hat{\\beta}-\\beta)^2}{\\sigma^2}\\sum_{i=1}^n x_i^2 \\sim \\chi^2_1.\n\\]\n\\eit\nIt is easy to see that if $U\\sim\\chi^2_a$ and $V\\sim\\chi^2_b$ are independent, then $U+V\\sim\\chi^2_{a+b}$. It thus follows that $n\\hat{\\sigma}/\\sigma\\sim \\chi^2_{n-2}$ as required.\n\\end{proof}\n\n%-----------------------------\n\\subsection{Test statistics for $\\alpha$ and $\\beta$}\n\nWe have shown that $\\hat{\\alpha} \\sim N(\\alpha,\\sigma^2/n)$ and $\\hat{\\beta}\\sim N\\Big[\\beta,\\sigma^2 / \\sum_{i=1}^n(x_i-\\bar{x})^2\\Big]$. The error variance $\\sigma^2$ is usually unknown, and we use instead the following (unbiased) estimator for $\\sigma^2$, based on the squared residuals:\n\\[\n\\hat{\\sigma}^2 = \\frac{1}{n-2}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \n\\quad\\text{where}\\quad\n\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i).\n\\]\nThis estimator for $\\sigma^2$ yields the following test statistics:\n%\\begin{align*}\n%T_1 & = \\frac{\\hat{\\alpha}-\\alpha}{\\sqrt{\\hat{\\sigma}^2/(n-2)}} \\\\[2ex]\n%T_2 & = \\frac{\\hat{\\beta}-\\beta}{\\sqrt{n\\hat{\\sigma}^2/[(n-2)\\sum_{i=1}^n(x_i-\\bar{x})^2]}}\n%\\end{align*}\n\\[\nT_1 = \\frac{\\hat{\\alpha}-\\alpha}{\\sqrt{\\hat{\\sigma}^2/(n-2)}}\n\\quad\\text{and}\\quad\nT_2 = \\frac{\\hat{\\beta}-\\beta}{\\sqrt{n\\hat{\\sigma}^2/[(n-2)\\sum_{i=1}^n(x_i-\\bar{x})^2]}}.\n\\]\n\n\\bit\n\\it Under the null hypothesis $H_0:\\alpha=0$, \n\\[\nT_1 = \\frac{\\hat{\\alpha}-\\alpha}{\\sqrt{\\hat{\\sigma}^2/(n-2)}} \\sim t_{n-2}.\n\\]\n\\it Uhder the null hypothesis $H_0:\\beta=0$,\n\\[\nT_2 = \\frac{\\hat{\\beta}-\\beta}{\\sqrt{n\\hat{\\sigma}^2/[(n-2)\\sum_{i=1}^n(x_i-\\bar{x})^2]}} \\sim t_{n-2}.\n\\]\n\\eit\n\n$T_2$ can be used to test whether or not $Y$ depends (linearly) on $X$:\n\\begin{align*}\nH_0: \t&\\ Y = \\alpha+\\epsilon, \\\\\nH_1:\t&\\ Y = \\alpha+\\beta X + \\epsilon.\n\\end{align*}\n\n%-----------------------------\n\\subsection{ANOVA for regression}\n\n%For a fixed realisation $(x_1,x_2,\\ldots,x_n)$ of the marginal sample $(X_1,X_2,\\ldots,X_n)$, \nRecall that the \\emph{predicted value} of $Y_i$ is \n\\[\n\\hat{Y}_i = \\hat{\\alpha} + \\hat{\\beta}X_i.\n\\]\nThe total deviation of $Y_i$ from the overall mean $\\bar{Y}$ can be divided into two components:\n\\[\nY_i - \\bar{Y} = (Y_i-\\hat{Y}_i) + (\\hat{Y}_i - \\bar{Y}),\n\\]\nfrom which it follows that\n\\[\n\\sum_{i=1}^n(Y_i - \\bar{Y})^2 = \\sum_{i=1}^n(Y_i-\\hat{Y}_i)^2 + \\sum_{i=1}^n(\\hat{Y}_i - \\bar{Y})^2.\n\\]\nAs with ANOVA, we define the following sums-of-squares.\n\\[\n\\begin{array}{lll}\nSST\t& = \\displaystyle\\sum_{i=1}^n (Y_i-\\bar{Y})^2\n\\qquad & \\text{The \\emph{total} sum-of-squares.} \\\\\nSSR\t& = \\displaystyle\\sum_{i=1}^n (\\hat{Y}_i-\\bar{Y})^2\n\\qquad & \\text{The \\emph{regression} (or \\emph{model}) sum-of-squares.} \\\\\nSSE\t& = \\displaystyle\\sum_{i=1}^n (Y_i-\\hat{Y}_i)^2\n\\qquad & \\text{The \\emph{error} sum-of-squares.} \n\\end{array}\n\\]\n\nThe total sum-of-squares $SST$ is determined the marginal sample $(Y_1,Y_2,\\ldots,Y_n)$, and substituting for $\\hat{Y}_i = \\hat{\\alpha} + \\hat{\\beta}X_i$ we see that the regression sum-of-squares satisfies\n\\[\nSSR = \\frac{\\big[\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})\\big]^2}{\\sum_{i=1}^n (X_i-\\bar{X})^2}\n\\]\nThe error sum-of-squares is then given by $SSE = SST - SSR$.\n\n\\bigskip\nUnder $H_0:\\beta=0$,\n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n (\\hat{Y}_i-\\bar{Y})^2\t\\sim \\chi^2_1\n\\text{\\quad and\\quad}\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n (Y_i-\\hat{Y}_i)^2\t\t\\sim \\chi^2_{n-2}.\n\\]\nThus we have the test statistic\n\\[\nF \n%\t= \\frac{SSR}{\\frac{1}{n-2}SSE} \n\t= \\frac{\\sum_{i=1}^n (\\hat{Y}_i-\\bar{Y})^2}{(n-2)^{-1}\\sum_{i=1}^n (Y_i-\\hat{Y}_i)^2} \n\t\\sim F_{1,n-2} \\quad\\text{under $H_0:\\beta=0$.}\n\\]\nwhich provides an alternative meathod of testing whether or not $Y$ depends linearly on $X$.\n\n\\begin{exercise}\nThe table below shows the deaths due to bronchitis ($x$) and corresponding daily temperatures ($y$), averaged over a long period.\n\\begin{center}\n\\begin{tabular}{lcccccccccc}\\hline\n$x$ & 253 & 232 & 210 & 200 & 191 & 187 & 134 & 102 & 81 & 25 \\\\\n$y$ & 35 & 37 & 39 & 41 & 43 & 45 & 47 & 49 & 51 & 53 \\\\ \\hline\n\\end{tabular}\n\\end{center}\nUse the simple linear model $y = \\alpha + \\beta x + \\epsilon$ to perform a least-squares regression of $y$ on $x$. Test whether the slope of the regression line is significantly different from zero at the 5\\% significance level.\n\\begin{answer}\nThe various quantities of interest are computed here:\n\\bit\n\\it $n = 10$.\n\\it $\\sum x_{i} = 1615$.\n\\it $\\sum x_{i}^{2}\t= 308929$.\n\\it $\\sum (x_i-\\bar{x})^2\t= 308929 - (1615)^{2}/10 = 48106.5$.\n\\it $\\sum y_{i} =  440$.\n\\it $\\sum y_{i}^{2}  = 19690$.\n\\it $\\sum (y_i-\\bar{y})^2 = 19690 - (440)^{2}/10 = 330$.\n\\it $\\sum x_{i}y_{i}\t= 67209$.\n\\it $\\sum (x_i-\\bar{x})(y_i-\\bar{y})\t= 67209 - (1615){\\times}(440)/10 = -3851$.\n\\eit\n\nThe OLS estimates of the regression coefficients are\n\\begin{align*}\n\\hat{\\beta}\t\t&\\quad = \\frac{\\sum (x_i-\\bar{x})(y_i-\\bar{y})}{\\sum (x_i-\\bar{x})^2} = \\frac{-3851}{48106.5} = -0.080052 \\\\\n\\hat{\\alpha}\t&\\quad = \\bar{y}-\\hat{\\beta}\\bar{x} = 44 + 0.080052{\\times}161.5 = 56.928326\n\\end{align*}\n\nThe least squares regression line is \n\\[\ny = 56.928326 - 0.080052x.\n\\]\nTo test the null hypothesis $H_0:\\beta=0$, we compute the model sum-of-squares:\n\\[\nSSM \n\t= \\frac{\\big[\\sum (x_i-\\bar{x})(y_i-\\bar{y})\\big]^{2}}{\\sum (x_i-\\bar{x})^2} \n\t=\\frac{(-3851)^{2}}{48106.5} \n\t= 308.2785\n\\]\nand the error sum-of-squares,\n\\[\nSSE\n\t= \\sum (y_i-\\bar{y})^2 - S_R = 330.0 - 308.2785 =  21.7215.\n\\]\nThe test statistic is\n\\[\nF = \\frac{SSM}{\\frac{1}{n-2}SSE} = \\frac{308.2785}{21.7215/8} = 113.54.\n\\]\n\nCritical values of the $F_{1,8}$-distribution are\n\\bit\n\\it $5.318$ at sig. level $0.05$\n\\it $7.570$ at sig. level $0.025$\n\\it $11.25$ at sig. level $0.001$\n\\it $14.68$ at sig. level $0.005$\n\\eit\nThus the null hypothesis ${\\beta} = 0$ is strongly rejected at the $5\\%$ significance level.\n\\end{answer}\n\\end{exercise}\n\n\n%-----------------------------\n\\subsection{The coefficient of determination}\n\nRecall that, for any pair of random variables $X$ and $Y$, the \\emph{correlation coefficient} is defined by\n\\[\n\\rho(X,Y) \n\t= \\frac{\\cov(X,Y)}{\\sqrt{\\var(X)\\var(Y)}}\n\t= \\frac{\\expe\\big[(X-\\expe X)(Y-\\expe Y)\\big]}\n\t\t\t{\\sqrt{\\expe\\big[(X-\\expe X)^2\\big]\\expe\\big[(Y-\\expe Y)^2\\big]}}\n\\]\n\nFor a bivariate random sample $(X_1,Y_1),(X_2,Y_2),\\ldots,(X_n,Y_n)$, the \\emph{sample correlation coefficient} (also called the Pearson correlation) is defined by\n\\[\nR = \\frac{\\sum_{i=1}^n(X_i-\\bar{X})(Y_i - \\bar{Y})}{\\sqrt{\\sum_{i=1}^n(X_i-\\bar{X})^2\\sum_{i=1}^n(Y_i-\\bar{Y})^2}} \n\\]\n\nFor the simple linear regression model $Y=\\alpha+\\beta X + \\epsilon$, the MLE of $\\beta$ can be written as,\n\\begin{align*}\n\\hat{\\beta}\n\t& = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2} \n\t= R\\sqrt{\\frac{\\sum_{i=1}^n(Y_i-\\bar{Y})^2}{\\sum_{i=1}^n(X_i-\\bar{X})^2}}.\n\\end{align*}\n\n%The square of the empirical correlation coefficient is called the \\emph{coefficient of determination}, denoted by $R^2$:\nThe \\emph{coefficient of determination} is the square of the sample correlation, and denoted by $R^2$:\n\\[\nR^2 \n\t= \\frac{\\big[\\sum_{i=1}^n(X_i-\\bar{X})(Y_i - \\bar{Y})\\big]^2}{\\sum_{i=1}^n(X_i-\\bar{X})^2\\sum_{i=1}^n(Y_i-\\bar{Y})^2}\n\t= \\frac{SSR}{SST}.\n\\]\n\nwhere $SSR$ and $SST$ are the model sum-of-squares and total sum-of-squares respectively. Thus $R^2$ is the proportion of the total variation explained by the regression model: it quantifies how well the regression line fits the data points, and accordingly is often referred to as a \\emph{goodness-of-fit} statistic.\n\n\n\n%=====================================================================\n\\stopcontents[chapters]\n\\endinput\n", "meta": {"hexsha": "8ce66493db40004bb0c60e55a5990bd9f7a9af13", "size": 49337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/12_linear_models.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/12_linear_models.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/12_linear_models.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 42.2405821918, "max_line_length": 796, "alphanum_fraction": 0.6263858767, "num_tokens": 19015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.6927780015489298}}
{"text": "% Section 1: Introduction\n\n\\section{Introduction}\n\nOptimal transport is widely used in the field of computer science, especially in areas as computer graphics, computer vision, medical image processing and deep learning. As the product of the intersection of multiple disciplines, it contains problems from probability, analysis, and optimization. The main objective of the research is to establish a geometric tool for efficient comparison of probability distributions, that is, the modeling of probability distributions by geometric methods and the measurement of the distance between probability distributions is a bridge connecting geometry and probability.\n\nTake the problem given by the French mathematician Monge more than 200 years ago as an example: When two sand plates are given (each sand plate can represent a probability distribution), a sand plate can be transmitted in many ways (Transport or Reshape) to another sandbox. Based on the local cost of transmitting a single sand particle, each transport method corresponds to a global cost. The purpose of optimal transport is to find the transport solution with the lowest overall cost, so as to further establish the geometric toolset for probability distribution.\n\nThe optimal transport problem has a long and rich research history, which can be traced back to the eighteenth-century Monge mentioned above. The Russian mathematician Kantorovich gave a more practical form of relaxation in the 1940s and was further promoted in the 1990s because of a series of important mathematical theoretical achievements, including important work of French mathematician Brenier. It is particularly important that many Fields Prize winners have made important contributions in the study of optimal transport theory, such as the French mathematician Cédric Villani (The Fields Award 2010), Italian Mathematics Alessio Figalli (The Fields Award 2018), and has many important monographs \\cite{book1, book2, book3, book4}. In terms of application, optimal transport has been widely used in the field of computer science, especially in computer graphics, computer vision, medical image processing, and deep learning.\n\nIn order to introduce the optimal transmission problem more concisely, we only consider the optimal transmission problem for discrete probability vectors (histograms). First, a probability vector or histogram refers to a vector $a \\in \\Sigma_m$ belongs to a set of probability simplex, that is,\n\n\\begin{equation}\n  \\Sigma_{m}:=\\left\\{\\mathbf{a} \\in \\mathbb{R}_{+}^{m}: \\sum_{i=1}^{m} \\mathbf{a}_{i}=1\\right\\}\n\\end{equation}\n\nDue to the computational difficulty of the optimal transport problem proposed by Monge and the limitation of this model, the Kantorovich relaxed optimal transport model has drawn attention in academia. By removing the limitation of fully deterministic transport (the quantity of the same point cannot be decomposed), Kantorovich gives a concise and effective optimal transport model. Transport is achieved through the Couplings matrix $P_+^{n \\times m}$, where the set of coupling matrices is defined as\n\n\\begin{equation}\n  \\mathbf{U}(\\mathbf{a}, \\mathbf{b}) \\stackrel{\\text { def. }}{=}\\left\\{\\mathbf{P} \\in \\mathbb{R}_{+}^{m \\times n}: \\mathbf{P} \\mathbf{1}_{n}=\\mathbf{a} \\quad \\text { and } \\quad \\mathbf{P}^{\\mathrm{T}} \\mathbf{1}_{m}=\\mathbf{b}\\right\\}\n\\end{equation}\n\n$\\mathbf{a} \\in \\Sigma_m$ and $\\mathbf{b} \\in \\Sigma_n$ are both probability vectors or histograms. The coupling matrix set is bounded and consists of $m + n$ equality constraints, which can be regarded as a convex polyhedron. \n\nKantorovich optimal transmission problem can be defined as\n\n\\begin{equation}\n  \\mathcal{L}_{\\mathbf{C}}(\\mathbf{a}, \\mathbf{b}):=\\min _{\\mathbf{P} \\in \\mathbf{U}(\\mathbf{a}, \\mathbf{b})}\\langle\\mathbf{C}, \\mathbf{P}\\rangle:=\\sum_{i, j} \\mathbf{C}_{i j} \\mathbf{P}_{i j}\n\\end{equation}\n\nWhere $C \\in \\mathbb{R}^{n \\times m}$ represents the cost matrix and $C_{ij}$ represents the cost required to transfer from $i$ to $j$. The Kantorovich optimal transport problem is a linear programming problem, and the problem does not necessarily have a unique solution. The importance of the optimal transport problem is not only in itself, it provides a way to meaningfully characterize the distance between probability vectors or histograms.\n\n\\vspace{5ex}\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.8\\linewidth]{img/ot}\n  \\label{fig:ot}\n  \\caption{Illustration of Optimal Transport Interpolation}\n\\end{figure}", "meta": {"hexsha": "12807dc6ed2499fd26407d7d27af744d0dbabefc", "size": 4512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/content-1.tex", "max_stars_repo_name": "CrazyIvanPro/Optimal_Transport", "max_stars_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-09T10:37:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T09:24:30.000Z", "max_issues_repo_path": "doc/content-1.tex", "max_issues_repo_name": "CrazyIvanPro/Optimal_Transport", "max_issues_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/content-1.tex", "max_forks_repo_name": "CrazyIvanPro/Optimal_Transport", "max_forks_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-03T17:07:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T17:07:01.000Z", "avg_line_length": 115.6923076923, "max_line_length": 933, "alphanum_fraction": 0.7841312057, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6927780002755383}}
{"text": "\\section{The Isomorphism Theorems}\r\n\\begin{definition}\r\n    A subgroup $H\\le G$ is called normal if $\\forall h\\in H,\\forall g\\in G, ghg^{-1}\\in H$, in which occasion $H\\unlhd G$\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $\\{e\\}\\unlhd G,G\\unlhd G$.\\\\\r\n    2. The subgroup of the dihedral group $D_{2n}$ generated by the rotations is normal. but that generated by the reflection generator is not normal (given $n\\ge 3$).\\\\\r\n    3. If $G$ is abelian, then for every $H\\le G,H\\unlhd G$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    A subgroup $H\\le G$ is normal if and only if $\\forall a\\in G,aH=Ha$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial but let us write it down.\\\\\r\n    If $H$ is normal, then for any $ah\\in aH,\\exists h'\\in H,aha^{-1}=h'\\implies ah=h'a\\in Ha$, so $aH\\subset Ha$.\r\n    Similarly $Ha\\subset aH$, so $Ha=aH$.\\\\\r\n    Conversely, if $\\forall a\\in G,Ha=aH$, we can choose any $h\\in H,\\exists h'\\in H,ah=h'a\\implies aha^{-1}=h'\\in H$, so $H$ is normal.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $H\\le G$.\r\n    If $|G/H|=2$, then $H$ is normal.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    If $a\\in H$, then obviously $aH=Ha$, otherwise, since $H$ has index $2$, $aH=G\\setminus H=Ha$, thus $H\\unlhd G$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $\\phi:G\\to K$ be a homomorphism, then $\\ker\\phi\\unlhd G$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose $h\\in\\ker\\phi$, then $\\forall g\\in G$, then $\\phi(ghg^{-1})=\\phi(g)e_K\\phi(g)^{-1}=e_K\\implies ghg^{-1}\\in\\ker\\phi$.\r\n\\end{proof}\r\nSo we know that every kernel is a normal subgroup, but how about the converse?\r\nMust every normal subgroup the kernel of some homomorphism?\r\n\\begin{definition}\r\n    Let $G$ be a group and $H\\unlhd G$, then we can define the operation\r\n    $$(aH)\\cdot(bH)=(ab)H$$\r\n    And $G/H$ is a group under this operation.\r\n    This is called the quotient group.\r\n\\end{definition}\r\nGiven that it is well defined, which we will prove later, then we know that whenever $H$ is normal, then it is the kernel of the homomorphism $\\pi: G\\to G/H$ by $\\pi(a)=aH$.\r\nThis is called the caconical projection.\\\\\r\nIf we do not have $H$ being normal, then if we want to define the operation\r\n$$aH\\times bH=abH$$\r\nBut is it well defined?\r\nNote that to do so, if $aH=a'H,bH=b'H$, then $a^{-1}a',b^{-1}b'\\in H$, but to make the operation well-defined, we must have\r\n$$a'b'H=abH\\iff a^{-1}b^{-1}a'b'\\in H$$\r\nBut this is not always true.\r\nBut if $H$ is normal, then it is however true.\r\nIn fact, this is true if and only if $H$ is normal.\r\n\\begin{theorem}\r\n    Our operation on quotient group is well-defined and $G/H$ is a group under it.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    If $aH=a'H,bH=b'H$, then\r\n    $$a'b'H=a'bH=a'Hb=aHb=abH$$\r\n    Due to normality of H.\\\\\r\n    To see that $G/H$ is thus a group, we observe that $(aH\\cdot bH)\\cdot cH=abcH=aH\\cdot(bH\\cdot cH)$.\r\n    Also $H=eH$ is the identity and $gH\\cdot g^{-1}H=H$.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Note that $n\\mathbb Z\\le\\mathbb Z$, and it is normal since $\\mathbb Z$ is abelian.\r\n    Now $\\mathbb Z_n\\cong \\mathbb Z/n\\mathbb Z$ by the isomorphism $k\\mapsto k+n\\mathbb Z$.\\\\\r\n    2. Let $R=\\langle r|r^n\\rangle\\le D_{2n}$, then $|D_{2n}/R|=2$, so $D_{2n}/R\\cong C_2$.\\\\\r\n    3. Let $K$ be the group consisting of $\\{e,r^2\\}$ in $D_8$.\r\n    One can check that this is normal, and that $D_8/K\\cong K_4=C_2\\times C_2$ since (by inspection) every element in the quotient group has order $2$.\\\\\r\n    4. Let $K$ be the subgroup of $Q_8$ consisting of $\\{\\pm\\underline{1}\\}$, and $Q_8/K\\cong K_4$ since every element has order $2$ again.\r\n    From this example and the last one, we can see that if $H_1\\le G_1,H_2\\le G_2$ and $H_1\\cong H_2,G_1/H_1\\cong G_2/H_2$, we do not necessarily have $G_1\\cong G_2$.\r\n    Hence, when we dissolve a group into normal subgroup and quotient, there might not be an unique way to rebuild the group from them.\r\n\\end{example}\r\n\\begin{theorem}[First Isomorphism Theorem]\\label{1_isom_thm}\r\n    Suppose $\\phi:G\\to H$ is a homomorphism, then $G/\\ker\\phi\\cong\\operatorname{Im}\\phi$.\r\n    Indeed, the map $\\bar\\phi:G/\\ker\\phi\\to\\operatorname{Im}\\phi$ by $g\\ker\\phi\\mapsto\\phi(g)$ is well defined and is an isomorphism.\r\n\\end{theorem}\r\nThe theorem gives the following commutative diagram, where $\\pi$ is the caconical projection:\r\n$$\r\n\\begin{tikzcd}\r\n    G\\arrow{r}{\\phi} \\arrow[swap]{d}{\\pi} & \\operatorname{Im}\\phi\\\\\r\n    G/\\ker\\phi\\arrow[swap,dashed]{ur}{\\bar\\phi}&\r\n\\end{tikzcd}\r\n$$\r\n\\begin{proof}\r\n    We know that $\\ker\\phi$ is normal, thus we can form the quotient $G/\\ker\\phi$.\\\\\r\n    If $g\\ker\\phi=h\\ker\\phi$, then $h^{-1}g\\in\\ker\\phi$, hence\r\n    $$e_H=\\phi(h^{-1}g)=\\phi(h)^{-1}\\phi(g)\\implies \\phi(g)=\\phi(h)$$\r\n    thus $\\bar\\phi$ is well-defined.\r\n    Note also that\r\n    $$\\bar\\phi((g\\ker\\phi)(h\\ker\\phi))=\\bar\\phi(gh\\ker\\phi)=\\phi(gh)=\\phi(g)\\phi(h)=\\bar\\phi(g\\ker\\phi)\\bar\\phi(h\\ker\\phi)$$\r\n    so it is a homomorphism.\r\n    Furthermore, if $\\bar\\phi(g\\ker\\phi)=\\bar\\phi(h\\ker\\phi)$, then\r\n    $$\\phi(g)=\\phi(h)\\implies \\phi(h^{-1}g)=e_H\\implies h^{-1}g\\in\\ker\\phi\\implies h\\ker\\phi=g\\ker\\phi$$\r\n    So it is injective.\r\n    It is also surjective by definition, so it is bijective, hence it is an isomorphism.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Consider $\\mathbb Z_n\\cong\\mathbb Z/n\\mathbb Z$.\r\n    Now an easy proof of that is to recognize the homomorphism $\\mathbb Z\\to\\mathbb Z_n$ sending an integer to the remainder it left when divided by $n$.\r\n    And the result follows by Theorem \\ref{1_isom_thm}.\\\\\r\n    2. The function $\\phi:(\\mathbb R,+,0)\\to(\\mathbb C\\setminus\\{0\\},\\times,1)$ by $t\\mapsto e^{2\\pi it}$, so the image of $\\phi$ is $S^1=\\{z\\in\\mathbb C:|z|=1\\}$ and $\\ker\\phi=\\mathbb Z$, so $\\mathbb R/\\mathbb Z\\cong S^1$.\\\\\r\n    3. If $H$ and $G$ are groups, we have $G\\times H$ and $\\{e\\}\\times H\\unlhd G\\times H$, but $G\\times H/\\{e\\}\\times H\\cong G$.\\\\\r\n    4. Let $G$ be the group of all symmetries (isometries) of the tetrahedron, then consider the map $\\phi:G\\to\\operatorname{Sym} V$ where $V$ is the set of vertices by action.\r\n    But this is injective and $\\operatorname{Sym}V\\cong S_4$ has $24$ elements, and the rotational symmetries forms an order-$12$ proper subgroup of $G$, thus we must have $G\\cong G/\\{e\\}\\cong\\operatorname{Im}\\phi\\le S_4$, but $12<|\\operatorname{Im}\\phi||24=|S_4|$ by Theorem \\ref{1_isom_thm}, so by Corollary \\ref{lagrange}, $\\operatorname{Im}\\phi\\cong S_4$.\r\n    5. $G$ also acts on the opposite pairs of edges, which has order $3$, so it gives a homomorphism $\\phi:G\\to S_3$.\r\n    Since its image has an element of order $2$ and an element of order $3$, this homomorphism is surjective, therefore $S_4/\\ker\\phi=G/\\ker\\phi\\cong S_3$, so $|\\ker\\phi|=4$.\r\n    Interestingly, there is never again a surjective homomorphism from $S_n$ to $S_{n-1}$ for $n>4$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A group $G$ is simple if it has no proper normal subgroup.\r\n\\end{definition}\r\n\\begin{example}\r\n    $C_p$ is simple for $p$ prime, since it does not even have any proper subgroup by Corollary \\ref{lagrange}.\r\n\\end{example}\r\n", "meta": {"hexsha": "1f4dd6421cf2a6932a323904585bd915b5622ddb", "size": 7015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/isothm.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "8/isothm.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "8/isothm.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.6339285714, "max_line_length": 360, "alphanum_fraction": 0.6575908767, "num_tokens": 2527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959543, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.6927779945923379}}
{"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{Geometry}\n  \\subsection{Inscribed angles}\n    \\begin{enumerate}\n      \\item Inscribed angles subtending the same arc are equal to each other\n      \\item Inscribed angle is equal to half of the central angle subtending the same arc.\n      \\item \\textbf{Alternate segment theorem}: Angle between chord and tangent is equal to inscribed angle which subtends to that chord.\n    \\end{enumerate}\n  \\subsection{Power of point}\n    \\begin{enumerate}\n      \\item The \\textbf{power of point} $P$ with respect to circle with centre $O$ and radius $r$ is defined as\n      $$ p= PO^2-r^2 $$\n      \\item For any line through point $P$ which intersects the circle at points $A$ and $B$\n      $$p= PA \\times PB$$\n    \\end{enumerate}\n  \\subsection{Trigonometry}\n    \\begin{enumerate}\n      \\item Basic trigonometric identities\n      $$\\frac{\\sin x}{\\cos x} = \\tan x$$\n      $$\\sin^2 x + \\cos^2 x =1$$\n      \\item Double angle formulae\n      $$ \\cos 2x = \\cos^2 x - \\sin^2 x $$\n      $$ \\sin 2x = 2\\sin x \\cos x $$\n      \\item Sine law\n      $$\\frac{a}{\\sin\\alpha} = \\frac{b}{\\sin\\beta} = \\frac{c}{\\sin\\gamma} = 2R$$\n      \\item Cosine law\n      $$ a^2 + b^2 - c^2 -2ab\\cos\\gamma = 0$$\n    \\end{enumerate}\n\\newpage\n\\section{Algebra}\n  \\subsection{Polynomials}\n    \\begin{enumerate}\n      \\item \\textbf{Bezout's theorem}: A polynomial $P(x)$ is divisible by the binomial $(x-a)$ if and only if $P(a)=0$.\n\n      \\item \\textbf{The fundamental theorem of algebra}: Every non-constant polynomial has a complex root.\n\n      \\item \\textbf{The rational root theorem}: If $x = p/q$ is a rational zero\n      of a polynomial $P(x) = a_nx^n +\\hdots + a_0$ with integer coefficients and $p,q=1$,\n      then $p | a_0$ and $q | a_n$.\n\n      \\item \\textbf{Vieta's formulae}: If the solutions polynomial of degree $n$ are $x_1,x_2,\\dots,x_n$ and  $a_n=1$, then the following holds:\n      \\begin{eqnarray*}\n      x_1+x_2+\\ldots+x_n &=& -a_{n-1},\\\\\n      x_1x_2+x_1x_3+\\ldots+x_{n-1}x_{n} &=& \\hphantom{-} a_{n-2}, \\\\\n      x_1x_2x_3+x_1x_2x_4+\\ldots+x_{n-2}x_{n-1}x_n &=& -a_{n-3},\\\\\n      \\ldots \\\\\n      x_1x_2\\ldots x_n &=& (-1)^n a_0.\n      \\end{eqnarray*}\n    \\end{enumerate}\n  \\subsection{Inequalities}\n    \\begin{enumerate}\n    \t\\item \\textbf{General mean inequality}:\n    \tThe mean of order $p$ of positive real numbers $x_1,\\dots,x_n$ is defined as:\n    \t$$M_p=\n    \t\\begin{cases}\n    \t\\left(\\frac{x_1^p+ \\dots + x_n^p}{n}\\right)^{1/p} &\\text{for } p \\ne 0 \\\\\n    \t\\sqrt[n]{x_1 \\dots x_n}                           &\\text{for } p=0\n    \t\\end{cases}\n    \t$$\n    \tIn particular\n    \t\\begin{center}\n    \t\t\\begin{tabular}{lcl}\n    \t\t\tSmallest element & $\\min\\{x_i\\}$ & $M_{-\\infty}$ \\\\\n    \t\t\tHarmonic mean & HM & $M_{-1}$ \\\\\n    \t\t\tGeometric mean & GM & $M_0$ \\\\\n    \t\t\tArithmetic mean & AM & $M_1$ \\\\\n    \t\t\tQuadratic mean & QM & $M_2$ \\\\\n    \t\t\tLargest element & $\\max\\{x_i\\}$ & $M_{\\infty}$\n    \t\t\\end{tabular}\n    \t\\end{center}\n    \tThen for any real $p$ and $q$\n    \t$$M_p \\leq M_q \\iff p \\leq q $$\n\n    \t\\item \\textbf{Cauchy inequality}:\n    \tFor real numbers $x_1, \\dots , x_n, y_1, \\dots , y_n$\n\n    \t$$\\left(\\sum_{i=1}^{n} x_i y_i\\right)^2 \\leq \\sum_{i=1}^{n} x_i^2 \\sum_{i=1}^{n} y_i^2 $$\n\n    \t\\item \\textbf{Chebyshev inequality}:\n    \tFor real numbers $x_1 \\geq \\dots \\geq x_n$ and $y_1 \\geq \\dots \\geq y_n$\n    \t$$\\frac{1}{n} \\sum_{i=1}^{n} x_iy_i\n    \t\\geq\n    \t\\left(\\frac{1}{n}\\sum_{i=1}^{n}x_i\\right)\n    \t\\left(\\frac{1}{n}\\sum_{i=1}^{n}y_i\\right)\n    \t\\geq\n    \t\\frac{1}{n} \\sum_{i=1}^{n} x_iy_{n+1-i} $$\n\n    \t\\item \\textbf{Jensen inequality.}\n    \tGiven positive real numbers $\\lambda_1,\\hdots,\\lambda_n$ for which $\\lambda_1+\\hdots+\\lambda_n=1$  and a convex function $f(x)$ the following holds:\n    \t$$f(\\lambda_1 x_1 + \\hdots + \\lambda_n x_n) \\leq \\lambda_1 f(x_1) + \\hdots + \\lambda_n f(x_n)$$\n    \tSimilarly, when $f(x)$ is a concave function, then\n    \t$$f(\\lambda_1 x_1 + \\hdots + \\lambda_n x_n) \\geq \\lambda_1 f(x_1) + \\hdots + \\lambda_n f(x_n)$$\n  \t\\end{enumerate}\n  \\subsection{Functional equations}\n    \\begin{enumerate}\n      \\item\n      If $f(x)=f(y)$ implies $x=y$, then $f$ is \\textbf{injective}\n      \\item\n      If for each element $y$ in function codomain, there exists $x$ for which $f(x)=y$, then $f$ is \\textbf{surjective}.\n      \\item\n      If $f$ is both injective and surjective then $f$ is \\textbf{bijective} (one-to-one).\n      \\item \\textbf{Cauchy functions}: If any of the following is satisfied\n      \\begin{enumerate}\n        \\item The function is continuous at one point,\n        \\item The function is monotonic on any interval,\n        \\item The function is bounded on any interval.\n      \\end{enumerate}\n      then all of the following functional equations have the respective solutions.\n      \\begin{align}\n         f(x+y) &= f(x) + f(x) & \\Rightarrow && f(x) &= cx \\\\\n         f(xy)  &= f(x)f(y)    & \\Rightarrow && f(x) &= x^c \\\\\n         f(xy)  &= f(x) +f(y)  & \\Rightarrow && f(x) &= c \\log |x| \\\\\n         f(x+y) &= f(x)f(y)    & \\Rightarrow && f(x) &= e^{cx}\n      \\end{align}\n    \\end{enumerate}\n\\newpage\n\\section{Number Theory}\n  \\subsection{Divisibility}\n    \\begin{enumerate}\n      \\item\n      If $a \\mid b$ and $ c \\mid d$ then $ac \\mid bd$\n      \\item\n      If $a \\mid b$ and $a \\mid c$, then $a \\mid b+c$\n      \\item\n      \\textbf{Euclid's algorithm.} \\\\\n      $\\gcd (a,b) = \\gcd (a,b-a)$\n      \\item\n      \\textbf{Corollary of Euclid's algorithm.} \\\\\n      $ax+by=n$ has solution $(x,y)$ in integers if and only if $gcd(a,b) \\mid n$\n    \\end{enumerate}\n  \\subsection{Congruences}\n    For integers $a,b,c,d,m,n$ and prime $p$.\n    \\begin{enumerate}\n      \\item\n      $a \\equiv b \\mod m \\iff m \\mid a-b $\n      \\item\n      $a\\equiv b \\mod m$ and $ c\\equiv d \\mod m \\implies a+c\\equiv b+d \\mod m$\n      \\item\n      $a \\equiv b \\mod m \\iff an \\equiv bn \\mod mn$\n      \\item\n      $a \\equiv b \\mod m \\implies an \\equiv bn \\mod m$\n    \\end{enumerate}\n  \\subsection{Exponential congruences}\n    \\begin{enumerate}\n    \\item\n    \\textbf{Fermat's little theorem.} \\\\\n    For prime $p$ and integer $a$\n    $$a^p \\equiv a \\mod p$$\n\n    \\item\n    \\textbf{Wilson's theorem.} \\\\\n    $$(p-1)! \\equiv -1 \\mod p$$\n    if and only if when $p$ is prime number.\n\n    \\item\n    \\textbf{Number of factors} \\\\\n    The number of positive factors of $n=p_1^{\\alpha_1} \\dots p_k^{a_k}$\n    $$d(n)= (\\alpha_1+1)(\\alpha_2+1)\\dots (\\alpha_k+1)$$\n    \\item\n    \\textbf{Sum of factors} \\\\\n    The sum of positive factors of $n=p_1^{\\alpha_1} \\dots p_k^{a_k}$\n\n    $$\\sigma(n)= \\frac{p_1^{\\alpha_1+1}-1}{p_1-1} + \\dots \\frac{p_k^{\\alpha_k+1}-1}{p_k-1}$$\n\n    \\item\n    \\textbf{Euler's function} \\\\\n    Euler’s function or totient function $\\varphi(n)$ is defined for $n=p_1^{\\alpha_1} \\dots p_k^{a_k}$ as the number\n    of positive integers less than $n$ and coprime to $n$. Then\n    $$\\varphi(n) = n \\left(1-\\frac{1}{p_1}\\right) \\dots  \\left(1-\\frac{1}{p_k}\\right)$$\n\n    \\item\n    \\textbf{Euler's theorem}  (Generalisation of Fermat's theorem)\\\\\n    Let $n$ be a natural number and $a$ an integer such that $\\gcd(a,n)=1$. Then\n    $$a^{\\varphi(n)} \\equiv 1 \\mod n $$\n    \\end{enumerate}\n\\newpage\n\\section{Combinatorics}\n  \\subsection{Counting of objects}\n    \\begin{enumerate}\n      \\item \\textbf{Permutations}: $P_n=n!$\n      \\item \\textbf{Variations}: $V^k_n=\\frac{n!}{(n-k)!}$\n      \\item \\textbf{Combinations}: $C^k_n=\\frac{n!}{(n-k)!}$\n    \\end{enumerate}\n  \\subsection{Pigeonhole principle}\n    \\begin{enumerate}\n      \\item If a set of $nk + 1$ different elements is partitioned into $n$ mutually disjoint subsets, then at least one subset will contain at least $k + 1$ elements.\n    \\end{enumerate}\n  \\subsection{Graph Theory}\n    \\begin{enumerate}\n      \\item \\textbf{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      \\item \\textbf{Euler path} is a path in which every edge of the graph appears exactly once. Likewise \\textbf{Euler circuit} is a circuit in which every edge appears exactly once.\n      \\item If each vertex in a connected graph has even degree, then the graph contains an Euler circuit.\n      \\item If a connected graph has exactly two vertices with odd degree, it contains an Euler path.\n      \\item A \\textbf{Hamilton circuit} is a circuit in which each vertex appears exactly once.\n      \\item\n      A \\textbf{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      \\item \\textbf{Dirac's theorem}: A graph with $n$ vertices contains a Hamilton cycle if the degree of each vertex is at least $n/2$.\n      \\item \\textbf{Euler's formula}: $E+2=F+V$, where $E,F,V$ are the numbers of edges, faces and vertices of a polyhedron.\n\n  \\end{enumerate}\n\\end{document}s\n", "meta": {"hexsha": "b358b276eabbbcce9fecc390a7b5620517983b59", "size": 9083, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "00_theorems.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": "00_theorems.tex", "max_issues_repo_name": "kauraare/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": "00_theorems.tex", "max_forks_repo_name": "kauraare/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": "2019-05-26T15:18:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-26T15:18:18.000Z", "avg_line_length": 42.4439252336, "max_line_length": 194, "alphanum_fraction": 0.6146647583, "num_tokens": 3148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6927071708482299}}
{"text": "\\subsection{Complexity Estimate}\n\n\\begin{frame}{Complexity Estimate}\n    \\begin{itemize}\n        \\item Invented by Gustavo Enrique de Almeida Prado Alves Batista, Xiaoyue Wang and Eamonn Keogh in 2011\n            \\cite{batista2011complexity}\n        \n        \\item A possible approach to measure the complexity of a time series\n        \n        \\item Linear complexity\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Complexity Estimate}{Calculation}\n    \\begin{block}{Given}\n        \\begin{itemize}\n            \\item A domain set $\\mathbb{U}$\n            \n            \\item A distance measure function $d$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Input}\n        \\begin{itemize}\n            \\item A time series $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with length $l$ over the domain set\n                $\\mathbb{U}$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Complexity Estimate}{Calculation}\n    \\begin{block}{Calculation}\n        \\begin{itemize}\n            \\item $CE(Q) = \\sqrt[2]{\\sum \\limits_{i=1}^{l-1} d(q_i, q_{i + 1})^2}$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Length Normalized Complexity Estimate}{Calculation}\n    \\begin{block}{Calculation}\n        \\begin{itemize}\n            \\item $LNCE(Q) = \\frac{1}{l-1}CE(Q)$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n", "meta": {"hexsha": "cef98701c63b5a7fb4401d38d6ed9487bf6b8052", "size": 1404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/background/complexity_estimate.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "presentation/background/complexity_estimate.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "presentation/background/complexity_estimate.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": 30.5217391304, "max_line_length": 111, "alphanum_fraction": 0.5897435897, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6927071689651496}}
{"text": "\\documentclass{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{amsthm}\n\n\\newtheorem{theorem}{Theorem}[section]\n\n\\begin{document}\n\\title{Solving simultaneous modular arithmetic equations}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{The Chinese Remainder Theorem}\n\n\\begin{theorem}\n\tThe Chinese Remainder Theorem states that for $n_1,n_2,\\cdots,n_k$ pairwise\n\tcoprime integers greater than 1 (that is, $\\gcd(n_i,n_j) = 1, i \\neq j$)\n\twhose product is $N$, and integers $a_1,a_2,\\cdots,a_k$ with\n\t$0\\leq a_i < n_i$, there is a unique integer $x$ such that $0 \\leq x < N$\n\tand:\n\t\\begin{align*}\n\t\tx &\\equiv a_1 \\pmod{x_1} \\\\\n\t\tx &\\equiv a_2 \\pmod{x_2} \\\\\n\t\t& \\vdots  \\\\\n\t\tx &\\equiv a_k \\pmod{x_k}\n\t\\end{align*}\n\\end{theorem}\n\n\\section{Applying the theorem}\n\nWe will apply the theorem using a construction method which can also be used to\nprove the existence and uniqueness of the number $x$ with the following problem:\n\n\\textbf{Question:} What is the smallest positive integer that has remainders of 7, 4, and 3\nwhen divided by 8, 9, and 13 respectively?\n\nSince $\\gcd(8,9) = \\gcd(8,13) = \\gcd(9,13) = 1$ we are guaranteed by the Chinese\nRemainder Theorem that there will be an answer between 0 and $8\\times9\\times13 = 936$.\n\nWe can construct the solution with the following algorithm. We are given:\n\n\\[(m_1,m_2,m_3) = (8,9,13)\\]\n\\[(r_1,r_2,r_3) = (7,4,3)\\]\n\nDefine:\n\\[(M_1,M_2,M_3) = (m_2\\times m_3,m_1 \\times m_3, m_1 \\times m_2) = (117,104,72)\\]\n\nWe use the extended Euclidean algoritm to find $(N_1,N_2,N_3)$ such that:\n\n\\[ 1 = M_i N_i + m_i n_i, i\\in \\{1,2,3\\}\\]\n\nThen we can calculate:\n\\[x = r_1 N_1 M_1 + r_2 N_2 M_2 + r_3 N_3 M_3 \\pmod{m_1 \\times m_2 \\times m_3}\\]\n\nAnd since $M_i \\equiv 0 \\pmod{m_j}, i \\neq j$, we are guaranteed that $x$ will\nsatisfy each of the congruence relations we want.\n\nFor $M_1,m_1$:\n\\begin{align*}\n\t117 &= 14 \\times 8 + 5 & 5 &= 117 - 14 \\times 8 \\\\\n\t8   &= 1 \\times 5 + 3  & 3 &= 15 \\times 8 - 117 \\\\\n\t5   &= 1 \\times 3 + 2  & 2 &= 2 \\times 117 - 29 \\times 8 \\\\\n\t3   &= 1 \\times 2 + 1  & 1 &= 44 \\times 8 -3 \\times 117\n\\end{align*}\n\nWhich yields $N_1 = -3$.\n\nSimilarly, for $M_2, M_3$, we get:\n\\begin{align*}\n\t1 &= 2 \\times 104 - 23 \\times 9 & N_2 &= 2 \\\\\n\t1 &= 2 \\times 72 - 11 \\times 13 & N_3 &= 2 \\\\\n\\end{align*}\n\nThen we can calculate:\n\n\\begin{align*}\n\tx &= r_1 N_1 M_1 + r_2 N_2 M_2 + r_3 N_3 M_3 \\pmod{m_1 \\times m_2 \\times m_3} \\\\\n\tx &= 7(-3)(117)+4(2)(104)+3(2)(72) \\pmod{936} \\\\\n\tx &= -1193 \\pmod{936} = 679 \\pmod{936} \n\\end{align*}\n\nAnd we can find all solutions of these equations in integers by adding or\nsubtracting multiples of the product of the modulos:\n\n\\[ x = 679 + 936k, k \\in \\mathbb{Z} \\]\n\n\n\\end{document}\n", "meta": {"hexsha": "0561bec88a9ff3010e3b6c5ae99abb6655409f73", "size": 2714, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chinese_remainder_theorem.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": "chinese_remainder_theorem.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": "chinese_remainder_theorem.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": 29.5, "max_line_length": 91, "alphanum_fraction": 0.6617538688, "num_tokens": 1077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311856832191, "lm_q2_score": 0.8791467754256017, "lm_q1q2_score": 0.6927071611506731}}
{"text": "%        File: AnalyticalDuctModes.tex\n%     Created: Fri Feb 11 10:00 PM 2022 E\n% Last Change: Fri Feb 11 10:00 PM 2022 E\n%\n\\documentclass[a4paper]{report}\n\\usepackage{mathtools}\n\\begin{document}\n\n\n\nStarting with equation 2.28 (Wave Equation) in Kousen's paper,\n\n\n\n\\begin{equation}\n    \\frac{1}{A^2}\\frac{D^2\\tilde{p}}{Dt^2} -\n    \\nabla^2 \\tilde{p} =\n    2 \\bar{\\rho} \\frac{d V_x}{d x} \\frac{\\partial  \\tilde{v}_r}{ \\partial x} \n    \\label{eqn:KousensWaveEquation}\n\\end{equation}\n\n\nlets look at the no flow case. In the case of sheared flow, $dV_x/dx = 0$ the right hand side will be zero \n\n\n\n\\begin{align*}\n    \\frac{1}{A^2}\\left(\n        \\frac{\\partial^2 \\tilde{p}}{\\partial t^2} + \n        \\vec{V}\\cdot \\vec {\\nabla} (\\tilde{p}) \n    \\right) -\n    \\nabla^2\n    \\tilde{p} &=\n    0 \\\\\n\\end{align*}\n\nSubstituting the definitions for $\\nabla$ and $\\nabla^2$ in cylindrical \ncoordinates gives,\n\n\\begin{align*} \n    \\frac{1}{A^2}\\left(\n        \\frac{\\partial^2 \\tilde{p}}{\\partial t^2}\n    + \n        \\vec{V}\\cdot \\left(\n            \\frac{\\partial\\tilde{p}}{\\partial t} + \n            \\frac{1}{\\tilde{r}}\\frac{\\partial \\tilde{p} }{\\partial \\tilde{r}} +\n            \\frac{\\partial \\tilde{p}}{\\partial \\theta} +\n            \\frac{\\partial \\tilde{p}}{\\partial x}  \n        \\right)  \\right)-\n        \\left(\n            \\frac{\\partial^2 \\tilde{p}}{\\partial t^2} + \n            \\frac{1}{\\tilde{r}}\\frac{\\partial \\tilde{p}}{\\partial r} +\n            \\frac{1}{\\tilde{r}^2} \\frac{\\partial^2 \\tilde{p}}{\\partial \\theta^2} + \n            \\frac{\\partial^2 \\tilde{p}}{\\partial x^2} \n        \\right) &= 0  \n\\end{align*} \nSetting $\\vec{V} = 0$,\n\n\\begin{align*} \n    \\frac{1}{A^2}\\left(\n        \\frac{\\partial^2 \\tilde{p}}{\\partial t^2}\n    \\right) - \n        \\left(\n            \\frac{\\partial^2 \\tilde{p}}{\\partial t^2} + \n            \\frac{1}{\\tilde{r}}\\frac{\\partial \\tilde{p}}{\\partial  r}  +\n            \\frac{1}{\\tilde{r}^2} \\frac{\\partial^2 \\tilde{p}}{\\partial \\theta^2} + \n            \\frac{\\partial^2 \\tilde{p}}{\\partial x^2} \n        \\right) &= 0  \n\\end{align*} \nRecall, $\\tilde{p} = p/\\bar{\\rho} A^2$. To dimensionalize the equation, this is\nsubstituted and both sides are multiplied by $\\bar{\\rho}A^2$,\n\n\n\\begin{align*} \n    \\frac{1}{A^2}\\left(\n        \\frac{\\partial^2 {p}}{\\partial t^2}\n    \\right) - \n        \\left(\n            \\frac{\\partial^2 {p}}{\\partial t^2} + \n            \\frac{1}{\\tilde{r}}\\frac{\\partial p}{\\partial r} +\n            \\frac{1}{\\tilde{r}^2} \\frac{\\partial^2 p}{\\partial \\theta^2} + \n            \\frac{\\partial^2 p}{\\partial x^2} \n        \\right) &= 0  \n\\end{align*} \n\nThe process of separation of variables(seperation indeterminatarum)\nwas first written and formalized by John Bernoulli in a letter to Leibniz. The method\nof separation of variables requires an assumed solution as well as initial and boundary \nconditions. For a partial differential equation, the assumed solution can be a \nlinear combination of solutions to a system of ordinary differential equations that\ncomprises the partial differential equation. Since $p$ is a function of four\nvariables, the solution is assumed to be a linear combination of four solutions.\nEach solution is assumed to be Euler's identity, a common ansant for linear partial \ndifferential equations and boundary conditions.\n\nDefining,\n\n\\begin{equation}\n    p(x,r,\\theta,t) = X(x) R(r) \\Theta(\\theta) T(t)\n\\end{equation}\n\nwhere, \n\n\\begin{align*}\n    X(x) &=\n    A_1 e^{ik_x x} +\n    B_1 e^{-ik_x x }\\\\\n    \\Theta(\\theta) &=\n    A_2 e^{i k_{\\theta} \\theta } +\n    B_2 e^{-ik_{\\theta} \\theta }\\\\\n    T(t) &=\n    A_3 e^{i \\omega t } +\n    B_3 e^{-i\\omega t  }\n\\end{align*}\n\nThe next step is to rewrite the wave equation in terms of $X$, $R$, $\\Theta$,\nand $T$. To further simplify the result, each term is divided by $p$.\nBefore the substitution, the derivatives of the assumed solutions need to be\nevaluated.\n\n\n\\subsubsection{Temporal Derivatives}\n\n\\begin{align*}\n    \\frac{\\partial p}{\\partial t} \n    &=\n    \\frac{\\partial }{\\partial t}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    XR\\Theta\\frac{\\partial T}{\\partial t}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial p}{\\partial t} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( XR\\Theta\\frac{\\partial T}{\\partial t} \\right) \\\\\n    &=\\frac{ 1}{ T}\\frac{\\partial T}{\\partial t}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 p}{\\partial t^2} \n    &=\n    \\frac{\\partial^2 }{\\partial t^2}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    XR\\Theta\\frac{\\partial^2 T}{\\partial t^2}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial^2 p}{\\partial t^2} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( XR\\Theta\\frac{\\partial^2 T}{\\partial t^2} \\right) \\\\\n    &=\\frac{ 1}{ T}\\frac{\\partial^2 T}{\\partial t^2}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial T}{\\partial t} &=\n    \\frac{\\partial}{\\partial t}\n        \\left( \n        A_3 e^{i \\omega t} + B_3 e^{-i \\omega t}\n    \\right)  \\\\\n    &=\n    \\frac{\\partial}{\\partial t} \\left(A_3 e^{i \\omega t}  \\right) +\n    \\frac{\\partial}{\\partial t} \\left(B_3 e^{-i \\omega t}  \\right)\\\\ \n    &= i \\omega A_3 e^{i \\omega t} - i \\omega B_3 e^{i \\omega t} \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 T}{\\partial t^2} &=\n    \\frac{\\partial^2}{\\partial t^2}\n        \\left( \n        i \\omega A_3 e^{i \\omega t} + i \\omega B_3 e^{-i \\omega t}\n    \\right)  \\\\\n    &=\n    \\frac{\\partial^2}{\\partial t^2} \\left(i \\omega A_3 e^{i \\omega t}  \\right) +\n    \\frac{\\partial^2}{\\partial t^2} \\left(- i \\omega B_3 e^{-i \\omega t}  \\right)\\\\ \n    &= (i \\omega)^2 A_3 e^{i \\omega t} - (i \\omega)^2 B_3 e^{i \\omega t} \n\\end{align*}\n\n\\begin{align*}\n    \\frac{1}{T}\\frac{\\partial^2 T}{\\partial t^2} \n    &=\n    (i\\omega)^2 \\\\\n    &= -\\omega^2\n\\end{align*}\n\n\n\\subsubsection{Radial Derivatives}\n\\begin{align*}\n    \\frac{\\partial p}{\\partial r} \n    &=\n    \\frac{\\partial }{\\partial r}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    X\\Theta T\\frac{\\partial R}{\\partial r}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial p}{\\partial r} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( X\\Theta T\\frac{\\partial R}{\\partial r} \\right) \\\\\n    &=\\frac{ 1}{ R}\\frac{\\partial R}{\\partial r}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 p}{\\partial r^2} \n    &=\n    \\frac{\\partial^2 }{\\partial r^2}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    X\\Theta T\\frac{\\partial^2 R}{\\partial r^2}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial^2 p}{\\partial r^2} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( X\\Theta T \\frac{\\partial^2 R}{\\partial r^2} \\right) \\\\\n    &=\\frac{ 1}{ R}\\frac{\\partial^2 R}{\\partial r^2}  \n\\end{align*}\nThe radial derivatives will be revisited once the remaining derivatives are evaluated,\n\n\\subsubsection{Tangential Derivatives}\n\n\\begin{align*}\n    \\frac{\\partial p}{\\partial \\theta } \n    &=\n    \\frac{\\partial }{\\partial t}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    XRT\\frac{\\partial \\Theta}{\\partial \\theta}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial p}{\\partial \\theta} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( XR\\Theta\\frac{\\partial T}{\\partial \\theta} \\right) \\\\\n    &=\\frac{ 1}{ \\Theta}\\frac{\\partial \\Theta}{\\partial \\theta}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 p}{\\partial \\theta^2} \n    &=\n    \\frac{\\partial^2 }{\\partial \\theta^2}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    XRT\\frac{\\partial^2 \\Theta }{\\partial \\theta^2}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial^2 p}{\\partial \\theta^2} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( XRT\\frac{\\partial^2 \\Theta}{\\partial \\theta^2} \\right) \\\\\n    &=\\frac{ 1}{ \\Theta}\\frac{\\partial^2 \\Theta}{\\partial \\theta^2}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial \\Theta}{\\partial \\theta} &=\n    \\frac{\\partial}{\\partial \\theta}\n        \\left( \n            A_2 e^{i k_{\\theta} \\theta} + B_2 e^{-i k_{\\theta} \\theta}\n        \\right)  \\\\\n    &=\n    \\frac{\\partial}{\\partial \\theta} \\left(A_2 e^{i k_{\\theta} \\theta}  \\right) +\n    \\frac{\\partial}{\\partial \\theta} \\left(B_2 e^{-i k_{\\theta} \\theta}  \\right)\\\\ \n    &= i k_{\\theta} A_2 e^{i k_{\\theta} \\theta} - i k_{\\theta} B_2 e^{i k_{\\theta} \\theta} \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 \\Theta }{\\partial \\theta^2} &=\n    \\frac{\\partial^2}{\\partial \\theta^2}\n        \\left( \n        i k_{\\theta} A_2 e^{i k_{\\theta} \\theta} - i k_{\\theta} B_2 e^{i k_{\\theta} \\theta} \n    \\right)  \\\\\n    &=\n    \\frac{\\partial^2}{\\partial \\theta^2} \\left(i k_{\\theta} A_2 e^{i k_{\\theta} \\theta}  \\right) +\n    \\frac{\\partial^2}{\\partial \\theta^2} \\left(- i k_{\\theta} B_2 e^{-i k_{\\theta} \\theta}  \\right)\\\\ \n    &= (i k_{\\theta})^2 A_2 e^{i k_{\\theta} \\theta } - (i k_{\\theta})^2 B_2 e^{i k_{\\theta} \\theta} \n\\end{align*}\n\n\\begin{align*}\n    \\frac{1}{\\Theta}\\frac{\\partial^2 \\Theta}{\\partial \\theta^2} \n    &=\n    (ik_{\\theta})^2 \\\\\n    &= -k_{\\theta}^2\n\\end{align*}\n\n\\subsubsection{Axial Derivatives}\n\n\\begin{align*}\n    \\frac{\\partial p}{\\partial x} \n    &=\n    \\frac{\\partial }{\\partial x}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    R\\Theta T \\frac{\\partial X}{\\partial x}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial p}{\\partial x} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( R\\Theta\\frac{\\partial X}{\\partial x} \\right) \\\\\n    &=\\frac{ 1}{ X}\\frac{\\partial X}{\\partial x}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 p}{\\partial x^2} \n    &=\n    \\frac{\\partial^2 }{\\partial x^2}  \\left( XR\\Theta T \\right) \\\\\n    &=\n    R\\Theta T \\frac{\\partial^2 X}{\\partial x^2}  \n\\end{align*}\n\n\n\\begin{align*}\n    \\frac{1}{p}\\frac{\\partial^2 p}{\\partial x^2} \n    &=\n    \\frac{ 1}{X R \\Theta T}  \\left( R\\Theta T \\frac{\\partial^2 X}{\\partial x^2} \\right) \\\\\n    &=\\frac{ 1}{ X}\\frac{\\partial^2 X}{\\partial x^2}  \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial X}{\\partial x} &=\n    \\frac{\\partial}{\\partial t}\n        \\left( \n        A_3 e^{i k_x t} + B_3 e^{-i \\omega t}\n    \\right)  \\\\\n    &=\n    \\frac{\\partial}{\\partial t} \\left(A_1 e^{i k_x x}  \\right) +\n    \\frac{\\partial}{\\partial t} \\left(B_1 e^{-i k_x x }  \\right)\\\\ \n    &= i k_x A_1 e^{i k_x x } - i k_x B_1 e^{i k_x x} \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial^2 X}{\\partial x^2} &=\n    \\frac{\\partial^2}{\\partial x^2}\n        \\left( \n        i k_x A_1 e^{i k_x x} + i k_x B_1 e^{-i k_x x}\n    \\right)  \\\\\n    &=\n    \\frac{\\partial^2}{\\partial x^2} \\left(i k_x A_1 e^{i k_x x}  \\right) +\n    \\frac{\\partial^2}{\\partial x^2} \\left(- i k_x B_1 e^{-i k_x x}  \\right)\\\\ \n    &= (i k_x)^2 A_1 e^{i k_x x} - (i k_x)^2 B_1 e^{i k_x x} \n\\end{align*}\n\n\\begin{align*}\n    \\frac{1}{X}\\frac{\\partial^2 X}{\\partial x^2} \n    &=\n    (i k_x)^2 \\\\\n    &= -k_x^2\n\\end{align*}\n\nSubstituting this back into the wave equation yields ,\n\n\n\n\\begin{align*} \n    \\frac{1}{A^2}\\left(\n        \\frac{\\partial^2 {p}}{\\partial t^2}\n    \\right) &= \n        \\left(\n            \\frac{\\partial^2 {p}}{\\partial t^2} + \n            \\frac{1}{\\tilde{r}}\\frac{\\partial p}{\\partial r} +\n            \\frac{1}{\\tilde{r}^2} \\frac{\\partial^2 p}{\\partial \\theta^2} + \n            \\frac{\\partial^2 p}{\\partial x^2} \n        \\right) \n\\end{align*} \n\n\\begin{equation}\n    \\frac{1}{A^2} \\frac{1}{T}\\frac{\\partial^2 T}{\\partial t^2} = \n    \\frac{1}{R}\\frac{\\partial^2 R}{\\partial r^2 } +\n    \\frac{1}{r}\\frac{1}{R}\\frac{\\partial R}{\\partial r}  + \n    \\frac{1}{r^2}\\frac{1}{\\Theta}\\frac{\\partial \\Theta}{\\partial \\theta} + \n    \\frac{1}{X}\\frac{\\partial^2 X}{\\partial x^2}\n    \\label{eqn:waveode}\n\\end{equation}\n\nNotice that each term is only a function of its associated independent variable.\nSo, if we vary the time, only the term on the left-hand side can vary. However,\nsince none of the terms on the right-hand side depend on time, that means the\nright-hand side cannot vary, which means that the ratio of time with its second\nderivative is independent of time. The practical upshot is that each of these \nterms is constant, which has been shown. The wave numbers are the \\textit{separation constants} \nthat allow the PDE to be split into four separate ODE's. Substituting the separation constants \ninto Equation (\\ref{eqn:waveode}) gives, \n\n\n\\begin{equation}\n    -\\frac{\\omega^2}{A^2}  = \n    \\frac{1}{R}\n    \\left(      \n    \\frac{\\partial^2 R}{\\partial r^2 } +\n    \\frac{1}{r}\\frac{\\partial R}{\\partial r}  \n\\right) -\n    \\frac{k_{\\theta}^2}{r^2}-  \n    k_x^2\n    \\label{eqn:waveode2}\n\\end{equation}\nNote that the dispersion relation states $\\omega = k A$\n\n\\begin{equation}\n    \\frac{1}{R}\n    \\left(      \n    \\frac{\\partial^2 R}{\\partial r^2 } +\n    \\frac{1}{r}\\frac{\\partial R}{\\partial r}  \n\\right) -\n    \\frac{k_{\\theta}^2}{r^2}-  \n    k_x^2 + k^2 = 0\n    \\label{eqn:waveode3}\n\\end{equation}\nThe remaining terms are manipulated to follow the same form as \\textit{Bessel's Differntial \nEquation} ,\n\n\\begin{equation}\n    x^2 \\frac{d^2 y}{dx^2} + x \\frac{dy }{dx } + (x^2 - n^2) y = 0\n    \\label{eqn:besselODE}\n\\end{equation}\n\nThe general solution to Bessel's differential equation is a linear combination of\nthe Bessel functions of the first kind, $J_n(x)$ and of the second kind, $Y_n(x)$ \n\\cite{wolphram:bessel}. The subscript $n$ refers to the order of Bessel's equation.\n\n\\begin{equation}\n    y(x) = AJ_n(x) + BY_n(x)\n    \\label{eqn:besselsolution}\n\\end{equation}\n\nBy rearranging Equation (\\ref{eqn:waveode3}), a comparison can be made to Equation\n(\\ref{eqn:besselODE}) to show that the two equations are of the same form. \n\nThe first step is to revisit the radial derivatives that have not been addressed.\nAs was done for the other derivative terms, the radial derivatives will also \nbe set equal to a separation constant, $-k_r^2$. \n\n\\begin{align}\n    \\underbrace{\\frac{1}{R}\n    \\left(      \n    \\frac{\\partial^2 R}{\\partial r^2 } +\n    \\frac{1}{r}\\frac{\\partial R}{\\partial r}  \n\\right) -\n    \\frac{k_{\\theta}^2}{r^2}}_{-k_r^2}-  \n    k_x^2 + k^2 = 0\n    \\label{eqn:wavenumber_without_kr}\n\\end{align}\n\nThe reader may be curious as to why the tangential separation constant $k_{\\theta}$ is \nincluded within the definition of the radial separation constant. \n\nRecall the ODE for the tangential direction, \n\n\\begin{align*}\n    \\frac{\\partial \\Theta}{\\partial \\theta} \\frac{1}{\\Theta} = - k_{\\theta}^2\\\\\n    \\frac{\\partial \\Theta}{\\partial \\theta} \\frac{1}{\\Theta} + \\Theta k_{\\theta}^2 = 0 \n\\end{align*}\n\nwhere the solution is more or less,\n\n\\begin{align*}\n    \\Theta(\\theta) = e^{i k_{\\theta} \\theta}\n\\end{align*}\n\nIn order to have non trivial, sensible solutions, the value of $\\Theta(0)$ and\n$\\Theta(2\\pi)$ need to be the same, and this needs to be true for any multiple \nof $2\\pi$ for a fixed r. Taking $\\Theta$ to be one, a unit circle, it can be shown that the domain\nis only going to be an integer multiple. Therefore, there is an implied periodic\nazimuthal boundary condition, i.e. $0<\\theta\\leq 2 \\pi$ and $k_{\\theta}=m$. \n\nContinuing with the radial derivatives\\ldots\n\n\n\\begin{align*}\n    -k_r^2 =\\frac{1}{R}\n    \\left(      \n    \\frac{\\partial^2 R}{\\partial r^2 } +\n    \\frac{1}{r}\\frac{\\partial R}{\\partial r}  \n\\right) -\n    \\frac{m^2}{r^2} \n\\end{align*}\nTo further simplify, the chain rule is used to do a change of variables, $x = k_r r$\n\\begin{align*}\n    \\frac{\\partial R}{\\partial r} &= \\frac{dR}{dx}\\frac{dx}{dr}\\\\\n    &=\n    \\frac{dR}{dx}\\frac{d}{dr}\\left( k_r r \\right) \\\\\n    &=\n    \\frac{dR}{dx} k_r \n\\end{align*} \n\n\n\\begin{align*}\n    \\frac{\\partial^2 R}{\\partial r^2} &= \\frac{d^2R}{dx^2}\\left(\\frac{dx}{dr}\\right)^2 + \n    \\frac{dR}{dr}\\frac{d^2x}{dr^2}\\\\\n    &=\n    \\frac{d^2R}{dx^2}\\frac{d}{dr} k_r^2 + k_r \\frac{d^2r}{dr^2}\\\\\n    &=\n    \\frac{d^2R}{dx^2}\\frac{d}{dr} k_r^2\n\\end{align*} \n\nSubstituting this into Equation (\\ref{eqn:waveode3}),\n\\begin{equation}\n    \\left(\\frac{d^2R}{dx^2}k_r^2 +\n    \\frac{1}{r}\\frac{d^2R}{dx^2}k_r\\right) +\n    \\left(k_r^2 - \\frac{m^2}{r^2}\\right)R\n    \\label{eqn:waveode4}\n\\end{equation}\nDividing Equation \\ref{eqn:waveode4} by $k_r^2$,\n\n\\begin{equation}\n    \\left(\\frac{d^2R}{dx^2} +\n    \\frac{1}{k_r r}\\frac{d^2R}{dx^2}\\right) +\n    \\left(1  - \\frac{m^2}{k_r^2 r^2}\\right)R\n    \\label{eqn:waveode5}\n\\end{equation}\n\n\\begin{equation}\n    \\left(\\frac{d^2R}{dx^2} +\n    \\frac{1}{x^2}\\frac{d^2R}{dx^2}\\right) +\n    \\left(1  - \\frac{m^2}{x^2}\\right)R\n    \\label{eqn:waveode6}\n\\end{equation}\n\nMultiplying Equation (\\ref{eqn:waveode6}) by $x^2$ gives,\n\n\\begin{equation}\n    \\frac{d^2R}{dr^2}x^2 + \n    \\frac{dR}{dr}x + \n    \\left( x^2 - m^2 \\right)R\n    \\label{eqn:finalradialode}\n\\end{equation}\nwhich matches the form of Bessel's equation\n\nIn summary, the wave equation for no flow in a hollow duct with hard walls is obtained \nfrom Equation (\\ref{eqn:wavenumber_without_kr}).\n\\begin{equation}\n    k^2 = k_r^2 + k_x^2\n    \\label{eqn:wavenumber_equation}\n\\end{equation}\n\n\\subsubsection{Hard Wall boundary condition}\n\\begin{equation}\n    \\frac{\\partial P}{\\partial r} = \\frac{\\partial}{\\partial r} \\left( X\\Theta T R \\right)\n\\end{equation}\n\n\\section{}\n\nTo get the same equation but for uniform flow, the same procedure can be followed.\n\nStarting with Equation 2.27 redimensionalized, \n\n\\begin{align*}\n    \\frac{ d^2 \\tilde{p}}{d \\tilde{r}^2} +\n    \\frac{1}{\\tilde{r}} \n    \\frac{d \\tilde{p}}{d \\tilde{r}} + \n    \\frac{2 \\bar{\\gamma} \\left( \\frac{d m_x}{d \\tilde{r}} \\right)}\n    {\\left( k - \\bar{\\gamma} m_x \\right)}\\frac{d \\tilde{p}}{d \\tilde{r}}+\n    \\left[ \\left( k - \\bar{\\gamma} m_x \\right)^2 - \\frac{m^2}{\\tilde{r}^2}- \n    \\bar{\\gamma}^2 \\right] \\tilde{p}\n\\end{align*}\n\nLet's separate the new terms from the old ones, \n\n\\begin{align*}\n    \\frac{ d^2 \\tilde{p}}{d \\tilde{r}^2} +\n    \\frac{1}{\\tilde{r}} \n    \\frac{d \\tilde{p}}{d \\tilde{r}} + \n    \\frac{2 \\bar{\\gamma} \\left( \\frac{d m_x}{d \\tilde{r}} \\right)}\n    {\\left( k - \\bar{\\gamma} m_x \\right)}\\frac{d \\tilde{p}}{d \\tilde{r}}+\n    \\left[ \\left( k - \\bar{\\gamma} m_x \\right)^2 - \\frac{m^2}{\\tilde{r}^2}- \n    \\bar{\\gamma} \\right] \\tilde{p}\n\\end{align*}\n\n\nRecalling the non-dimensional definitions,\n\\begin{align*}\n    \\tilde{p} &= \\frac{p}{\\bar{\\rho} A^2} \\\\\n    \\tilde{r} &= \\frac{r}{r_T} \\\\\n    \\frac{\\partial \\tilde{p}}{\\partial \\tilde{r}} &= \n    \\frac{ \\partial \\tilde{p}}{\\partial r} \\frac{\\partial r}{ \\partial \\tilde{r}}  \\\\ \n    &= \\frac{ \\partial \\tilde{p}}{\\partial r} \\frac{\\partial }{ \\partial \\tilde{r}} \\left( \\tilde{r} r_T \\right) \\\\\n    &= \n    \\frac{ \\partial \\tilde{p}}{\\partial r}  r_T \\\\\n    \\frac{\\partial^2 \\tilde{p}}{\\partial \\tilde{r}^2} &= \n    \\frac{ \\partial^2 \\tilde{p}}{\\partial r^2}  (r_T)^2+ \n    \\frac{ \\partial \\tilde{p}}{\\partial r} \\frac{\\partial^2 r}{ \\partial \\tilde{r}^2} \\\\\n    &= \\frac{ \\partial^2 \\tilde{p}}{\\partial r^2}  (r_T)^2 \n\\end{align*}\n\n\\begin{align*}\n    \\frac{\\partial}{\\partial r} \\left( \\frac{p}{\\bar{\\rho} A^2} \\right) \n    &=\n    \\frac{\\left(\\frac{\\partial}{\\partial r} \\left(  p\\right) \\bar{\\rho} A^2 - \n    \\underbrace{\\frac{\\partial \\bar{\\rho}A^2}{\\partial r}}_0 p \\right)}{\\left( \\bar{\\rho} A^2 \\right)^2}\\\\ \n    &= \\frac{1}{\\bar{\\rho}A^2} \\frac{\\partial p}{\\partial r}\n\\end{align*}\n\n\\begin{align*}\n    \\frac{ d^2 \\tilde{p}}{d \\tilde{r}^2} +\n    \\frac{1}{\\tilde{r}} \n    \\frac{d \\tilde{p}}{d \\tilde{r}}- \n    \\frac{m^2}{\\tilde{r}^2}\\tilde{p}- \n    \\bar{\\gamma}^2  \\tilde{p}\n + \n    \\frac{2 \\bar{\\gamma} \\left( \\frac{d M_x}{d \\tilde{r}} \\right)}\n    {\\left( k - \\bar{\\gamma} M_x \\right)}\\frac{d \\tilde{p}}{d \\tilde{r}}+\n    \\left( k - \\bar{\\gamma} M_x \\right)^2\\tilde{p} \n\\end{align*}\n\nIf there is only uniform flow, then $dM_x/dr = 0$,\n\n\\begin{align*}\n    \\frac{ d^2 \\tilde{p}}{d \\tilde{r}^2} +\n    \\frac{1}{\\tilde{r}} \n    \\frac{d \\tilde{p}}{d \\tilde{r}}- \n    \\frac{m^2}{\\tilde{r}^2}\\tilde{p}- \n    \\bar{\\gamma}^2  \\tilde{p}\n + \n    \\left( k - \\bar{\\gamma} M_x \\right)^2\\tilde{p} \n\\end{align*}\n\nRe-dimensionalizing,\n\n\\begin{align*}\n    \\frac{1}{\\bar{\\rho} A^2}\\left[\n    \\frac{ d^2 p}{d r} r_T^2+\n    \\frac{r_T}{r} \n    \\frac{d p}{d r} r_T - \n    \\frac{m^2}{r^2}r_T^2 p - k_x^2r_T^2  p\\right]\n    + \\left( \\frac{\\omega }{A}r_T - k_x r_T M_x \\right)^2p \n\\end{align*}\n\nExpanding the last term and substituting $\\omega/A = k$\n\n\\begin{align*}\n    \\frac{1}{\\bar{\\rho} A^2}\\left[\n    \\frac{ d^2 p}{d r} r_T^2+\n    \\frac{r_T}{r} \n    \\frac{d p}{d r} r_T - \n    \\frac{m^2}{r^2}r_T^2 p - k_x^2r_T^2  p\\right]\n    +\\left( r_T^2\\left(\n        k^2 - 2 k k_x M_x - k_x^2 M_x^2 \\right)\n    \\right)p \n\\end{align*}\nCanceling out $r_T/\\bar{\\rho}A$ in every term\n\n\n\\begin{align*}\n    \\frac{ d^2 p}{d r} +\n    \\frac{1}{r} \n    \\frac{d p}{d r} + \\left[ \n    k^2 - 2 k k_x M_x - k_x^2 M_x^2- \\frac{m^2}{r^2}  - k_x^2\\right]p \n\\end{align*}\n\nDefining \n\n$$-N^2 = k_x^2 M_x^2 - 2 k k_x M_x - k_x^2 $$\n$$-N^2 = -(1 -  M_x^2)k_x^2 - 2 k k_x M_x  $$\n$$-N^2 = - \\beta^2 k_x^2 - 2 k k_x M_x  $$\n\n\n\\begin{align*}\n    \\frac{ d^2 p}{d r} +\n    \\frac{1}{r} \n    \\frac{d p}{d r} + \\left[ \n    k^2 - N^2 - \\frac{m^2}{r^2}  \\right]p \n\\end{align*}\n\nLet $k_r^2 = k^2 - N^2$\n\n\n\\begin{align*}\n    \\frac{ d^2 p}{d r} +\n    \\frac{1}{r} \n    \\frac{d p}{d r} + \\left[ \n    k_r^2  - \\frac{m^2}{r^2}  \\right]p \n\\end{align*}\n\nLooking at the radial wavenumber,\n\n\\begin{align*}\n    k_r^2 &= k^2 - N^2 \\\\\n          &= k^2-\\beta^2 k_x^2 - 2 k k_x M_x \\\\\n    0 &= - \\beta ^2 k_x ^2 - \\left( 2M_x k \\right)k_x +(k^2 - k_r^2)\n\\end{align*}\n\nWhere the roots to this equation are the axial wavenumber,\n\n\nApplying the quadratic formula and taking \n\n\\begin{align*}\n    <+content+>\n\\end{align*}<++>\n\\bibliographystyle{plain}\n\\bibliography{references}\n\\end{document}\n\n\n", "meta": {"hexsha": "e795dfad7f87b5cf2437f13b4495d1a137c5a985", "size": 21268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/AnalyticalDuctModeds.tex", "max_stars_repo_name": "jeffs2696/AnalyticalDuctModes", "max_stars_repo_head_hexsha": "67d8e1729fca8a6ad269583591f6a0a61a274f8d", "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/AnalyticalDuctModeds.tex", "max_issues_repo_name": "jeffs2696/AnalyticalDuctModes", "max_issues_repo_head_hexsha": "67d8e1729fca8a6ad269583591f6a0a61a274f8d", "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/AnalyticalDuctModeds.tex", "max_forks_repo_name": "jeffs2696/AnalyticalDuctModes", "max_forks_repo_head_hexsha": "67d8e1729fca8a6ad269583591f6a0a61a274f8d", "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.5574712644, "max_line_length": 115, "alphanum_fraction": 0.5817190145, "num_tokens": 8285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6926977738447488}}
{"text": "%---------------------------Average Aspect Frobenius-----------------------------\n\\section{Mean Aspect Frobenius\\label{s:hex-med-aspect-frobenius}}\n\nFor hexahedra, there is not a unique definition of the aspect Frobenius.\nInstead, we use the aspect Frobenius\ndefined for tetrahedra (see section~\\S\\ref{s:tet-aspect-Frobenius}),\nbut choose the reference $W$ element to be right isosceles at\nthe hexahedral corner. Consider the eight tetrahedra formed by edges\nincident to the corner of a hexahedron. \nGiven a corner vertex $i$ and its three adjacent vertices $j$, $k$, and $\\ell$ ordered\nin a clockwise manner (so that $ijk\\ell$ is a positively oriented tetrahedron),\ndenote the tetrahedral aspect frobenius of that corner as $F_{ijk\\ell}$.\nTo obtain a single value for the metric, we average the eight unique tetrahedral aspects\n\\[\n  q = \\frac{1}{8}\\left(F_{0134} + F_{1205} + F_{2316} + F_{3027} + F_{4750} + F_{5461} + F_{6572} + F_{7643} \\right).\n\\]\n\n\\hexmetrictable{mean aspect frobenius}%\n{$1$}%                                        Dimension\n{$[1,3]$}%                                    Acceptable range\n{$[1,DBL\\_MAX]$}%                             Normal range\n{$[1,DBL\\_MAX]$}%                             Full range\n{1}%                                          Cube\n{--}%                                         Citation\n{v\\_hex\\_med\\_aspect\\_frobenius}%             Verdict function name\n", "meta": {"hexsha": "101911a84e6b7577d3dc4564313223dfa6675ccc", "size": 1403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexMedAspectFrobenius.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/HexMedAspectFrobenius.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/HexMedAspectFrobenius.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": 53.9615384615, "max_line_length": 117, "alphanum_fraction": 0.5894511761, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6926977685019683}}
{"text": "\\chapter{Ranked Retrieval}\n\\begin{multicols*}{2}\n\n\\noindent Boolean queries are not suitable for most users and often results in either too few or too many results. In ranked retrieval, users can use natural language for query and we only show top 10 results. \\\\\n\n\\noindent In bag-of-words model, vector representation doesn’t consider the ordering of word in a document.\\\\\n\n\\noindent Term frequency is the number of times a term occurs in a document. \\\\\n\n$$w_{t,d} = \n\\begin{cases}\n    1 + log_{10} \\text{tf}_{t,d} & \\text{tf}_{t,d} > 0 \\\\\n    0 & \\text{otherwise}\n\\end{cases}\n$$\n\n\\noindent Document frequency is number of times a term occurs in a collection of documents. Rare term has low document frequency, and is more informative than frequent terms. Inverse document frequency has no effect on one-term queries.\n\n$$\\text{idf}_t = log_{10} \\frac{N}{\\text{df}_t}$$\n\n\\noindent TF-IDF weighting: \n\n$$w_{t,d} = (1+ log_{10} \\text{tf}_{t,d})\\times log_{10} \\frac{N}{\\text{df}_t}$$\n\n\\noindent SMART Notation: \\verb|ddd.qqq|\n\\begin{center}\n\\includegraphics[width=8cm]{smart-notion}\n\\end{center}\n\n\\noindent Example: \\verb|lnc.ltc|\n\\begin{center}\n\\includegraphics[width=8cm]{smart-notion-example}\n\\end{center}\n\n\\noindent We rank documents according to their proximity to the query in vector space. Proximity can be measured using Euclidean Distance or Cosine Similarity.\n\n$$\\text{dist}(A,B) = \\sqrt{(x_A - x_B)^2 + (y_A - y_B)^2}$$\n\n$$\\text{cosine} (\\vec{q},\\vec{d}) = \\frac{\\vec{q} \\cdot \\vec{d}}{|\\vec{q}||\\vec{d}|}$$\n\n\\end{multicols*}\n", "meta": {"hexsha": "7697c9948c1db6d4bd78d8e57325585daac990a7", "size": 1535, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ranked.tex", "max_stars_repo_name": "Andyccs/CZ4034-information-retrieval-summary", "max_stars_repo_head_hexsha": "1636bbebc0fd7864e3d6234a57e0e978fbf7d5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-04-23T05:00:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-05T07:10:54.000Z", "max_issues_repo_path": "ranked.tex", "max_issues_repo_name": "Andyccs/CZ4034-information-retrieval-summary", "max_issues_repo_head_hexsha": "1636bbebc0fd7864e3d6234a57e0e978fbf7d5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ranked.tex", "max_forks_repo_name": "Andyccs/CZ4034-information-retrieval-summary", "max_forks_repo_head_hexsha": "1636bbebc0fd7864e3d6234a57e0e978fbf7d5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5476190476, "max_line_length": 236, "alphanum_fraction": 0.7100977199, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6926977621743162}}
{"text": "\\lesson{6}{Sep 27 2021 Mon (07:30:12)}{Polynomial Operations}{Unit 1}\n\n\\subsubsection*{Adding Polynomials}\n\nThe most important part of adding or subtracting polynomials is identifying\nlike terms. Like terms are terms containing the exact same “variable part.”\nExponents for the variables must be exactly the same. Coefficients can, and\nprobably will, be different. Identify the like terms in the following matching\nexercise.\n\n\\begin{example}[Adding Polynomials]\n    Add: $(2x^3 + 4x^2 - x + 7) + (3x^2 + 6x + 10)$\n    \n    \\begin{enumerate}\n        \\item Again, there is an understood $1$ in front of each set of\n            parentheses. As you've seen, distributing this $1$ will not change\n            the expression. Therefore, the parentheses may simply be removed.\n        \\item Highlight each pair of terms containing the same variable part.\n            Combine the like terms.\n    \\end{enumerate}\n\n    Note: Since there is no other term with a variable part of $x^3$, the term\n    $2x^3$ stays the same in the final answer.\n    \n    \\begin{align}\n        (2x^3 + 4x^2 - x + 7) + (3x^2 + 6x + 10) &= 2x^3 + 4x^2 - x + 7 + 3x^2 + 6x + 10 \\\\\n                                                 &= 2x^3 + 7x^2 + 5x + 17\n    \\end{align}\n\\end{example}\n\n\\subsubsection*{Subtracting Polynomials}\n\nSubtracting polynomials is almost exactly like adding polynomials. The only\n“difference” is that now a negative one must be distributed.\n\n\\begin{example}[Subtracting Polynomials]\n    Subtract: $(4x^2 - 5) - (x^3 + 2x^2 + 7)$\n    \n    The understood $1$ in front of the first set of parentheses will not change\n    the binomial within. However, the trinomial in the second set of\n    parentheses will change because a negative one ($-1$) must be distributed!\n    In effect, it will change the signs of those three terms.\n\n    \\begin{enumerate}\n        \\item Highlight each pair of terms containing the same variable part.\n        \\item  Combine the like terms. Since $-x^3$ does not have a like term,\n            it is written down as is. Arrange terms in descending order, from\n            greatest exponent to least.\n    \\end{enumerate}\n\n    \\begin{align}\n        1(4x^2 - 5) - 1(x^3 + 2x^2 + 7) &= 4x^2 - 5 - x^3 - 2x^2 - 7 \\\\\n                                        &= 4x^2 - 5 - x^3 - 2x^2 - 7 \\\\\n                                        &= -x^3 + 2x^2 - 12\n    \\end{align}\n\\end{example}\n\n\\subsubsection*{Inverses of Functions}\n\nFinding the inverse of an integer means performing an operation that will\ncancel that number. For example, if you are given the number $7$, you could add\n$-7$ to it to cancel it.\n\nLet's look at an example:\n\n\\begin{example}[Inverse of Functions]\n    \\begin{align}\n        f(x) &= 3x - 5 \\\\\n             &= y = 3x - 5 \\\\\n             &= x + 5 = 3y \\\\\n             &= \\frac{x + 5}{3} = y \\\\\n             &= f^{-1}x = \\frac{x + 5}{3}\n    \\end{align}\n\\end{example}\n\n\\subsubsection*{Operations on Functions}\n\n\\paragraph*{Addition}\n\nThe addition of two functions $f(x)$ and $g(x)$ is represented using the\nnotation $f(x) + g(x)$.\n\nLet $f(x) = 4x - 7$ and $g(x) = 10x - 3$. To add $f(x)$ and $g(x)$, the\nexpressions $4x - 7$ and $10x - 3$ need to be added.\n\nTherefore, this could be written as $f(x) + g(x) - (4x - 7) + (10x - 3)$.\n\n\\begin{enumerate}\n    \\item Simplify the right side by first distributing any coefficients\n        outside the parentheses. If no number or variable appears before the\n        parentheses, an understood 1 exists.\n    \\item When 1 is distributed to each term within each set of parentheses,\n        the expression remains unchanged.\n    \\item Identify and combine like terms.\n\\end{enumerate}\n\n\\begin{align}\n    f(x) + g(x) &= (4x - 7) + (10x - 3) \\\\\n                &= 1(4x - 7) + 1(10x - 3) \\\\\n                &= 4x - 7 + 10x - 3 \\\\\n                &= 14x - 10 \\\\\n                &= f(x) + g(x) = 14x - 10\n\\end{align}\n\n\\paragraph*{Subtraction}\n\nSubtraction of functions is similar to addition. The only difference is that\nyou must be very careful of sign changes!\n\nLet $f(x) = 4x - 7$ and $g(x) = 10x - 3$. To subtract $f(x)$ and $g(x)$, the\nexpressions $4x - 7$ and $10x - 3$ need to be subtracted.\n\nTherefore, this could be written as $f(x) - g(x) = (4x - 7) - (10x - 3)$.\n\n\\begin{enumerate}\n    \\item Simplify the right side by first distributing any coefficients\n        outside the parentheses. If no number or variable appears before the\n        parentheses, an understood 1 exists.\n    \\item Be very careful not to forget to distribute the $-1$ to each term in\n        the second set of parentheses.\n    Identify and combine like terms.\n\\end{enumerate}\n\n\\begin{align}\n    f(x) - g(x) &= (4x - 7) - (10x - 3) \\\\\n                &= 1(4x - 7) - 1(10x - 3) \\\\\n                &= 4x - 7 - 10x - 3 \\\\\n                &= -6x - 4 \\\\\n                &= f(x) - g(x) = -6x - 4\n\\end{align}\n\n\\newpage\n", "meta": {"hexsha": "7ecb4717d7bb80566ef6d128cc409fb36b0ec97b", "size": 4845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-6.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-6.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-6.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4285714286, "max_line_length": 91, "alphanum_fraction": 0.6, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246077301781, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.6926119543241965}}
{"text": "%auto-ignore\n\\providecommand{\\MainFolder}{..}\n\\documentclass[\\MainFolder/Text.tex]{subfiles}\n\n\\newcommand{\\Soln}{\\mathcal{S}}\n\\newcommand{\\InvSoln}{\\Soln_{\\mathrm{rot}}}\n\\newcommand{\\InvDR}{\\DR_{\\mathrm{rot}}}\n\\newcommand{\\InvR}{\\R_{\\mathrm{rot}}}\n\\newcommand{\\SO}{\\mathrm{SO}}\n\\newcommand{\\ArtPrpg}{\\mathrm{P}_{\\mathrm{art}}}\n\n\\begin{document}\n\n\\section{Standard Hodge propagator for 1- and 2-sphere}\\label{Sec:GrSpgh}\n\\allowdisplaybreaks\n\nIn this section, we denote the Hodge propagator for $\\Sph{n}$ constructed in Part~I by $\\ArtPrpg$. We would like to use $\\ArtPrpg$ to study the standard Hodge propagator $\\StdPrpg$ for $\\Sph{n}$.\n\nFor $\\Sph{1}$, we can compute $\\KKer_t$ and hence $\\StdPrpg$ explicitly. \n\n\\begin{Example}[$\\StdPrpg$ for $\\Sph{1}$]\\label{Ex:SADQQ}\nWe write $\\Sph{1} = \\R/2\\pi\\Z$ and use the coordinate $x\\in [0,2\\pi)$. Because $\\Sph{1}$ is flat, we have\n$$ \\Laplace = - \\frac{\\partial^2}{\\partial x^2}. $$\nSolving the eigenvalue problem $\\Laplace \\omega = \\lambda \\omega$ for $\\omega\\in \\DR(\\Sph{1})$ and $\\lambda\\in \\R$, we get $\\lambda\\in \\{0, n^2 \\mid n\\in\\N\\}$ and the corresponding eigenvectors\n\\begin{align*}\n\\Bigl\\{\\frac{1}{\\sqrt{2 \\pi}}, \\frac{1}{\\sqrt{\\pi}} \\cos(nx), \\frac{1}{\\sqrt{\\pi}} \\cos(nx) \\Diff{x}, \\frac{1}{\\sqrt{\\pi}} \\sin(nx), \\frac{1}{\\sqrt{\\pi}} \\sin(nx) \\Diff{x} \\mid n\\in \\N\\Bigr\\},\n\\end{align*}\nwhich we normalized in the $L^2$-norm. Plugging in \\eqref{Eq:HK}, we get\n\\begin{align*}\n\\KKer_t(x_1,x_2) & = \\frac{1}{2\\pi} + \\frac{1}{\\pi}\\sum_{n=1}^\\infty e^{-n^2 t}\\bigl(\\cos(nx_1) \\cos(nx_2) + \\sin(nx_1)\\sin(nx_2) \\bigr) (\\Diff{x_1}-\\Diff{x_2}) \\\\\n& = \\frac{1}{2\\pi} + \\frac{1}{\\pi}\\sum_{n=1}^\\infty e^{-n^2 t}\\cos(nx_1 - nx_2)(\\Diff{x_1}-\\Diff{x_2}).\n\\end{align*}\nApplying the product codifferential, we get\n\\begin{align*}\n\\CoDd \\KKer_t(x_1,x_2) &= \\frac{1}{\\pi}\\sum_{n=1}^\\infty e^{-n^2 t}\\Bigl[- \\frac{\\partial}{\\partial x_1}\\cos(nx_1-nx_2)+\\frac{\\partial}{\\partial x_2}\\cos(nx_1-nx_2)\\Bigr] \\\\\n& = \\frac{2}{\\pi} \\sum_{n=1}^\\infty e^{-n^2 t} n \\sin(n x_1 - n x_2). \n\\end{align*}\nFinally, the integration gives\n\\begin{align*}\n\\StdPrpg(x_1,x_2) &= \\frac{1}{2}\\int_0^\\infty \\CoDd\\KKer_t(x_1,x_2) \\Diff{t} \\\\\n&=\\frac{1}{\\pi}\\sum_{n=1}^\\infty \\Bigl(\\int_0^\\infty e^{-n^2 t} \\Diff{t}\\Bigr)n\\sin(nx_1 - nx_2) \\\\\n&= \\frac{1}{\\pi}\\sum_{n=1}^\\infty\\frac{\\sin\\bigl(n(x_1-x_2)\\bigr)}{n} \\\\\n& = \\frac{1}{2\\pi} \\begin{cases}\n\\pi - (x_1 - x_2) & x_1 > x_2, \\\\\n-\\pi - (x_1-x_2) & x_1< x_2.\n\\end{cases} \\\\\n& = \\frac{1}{2\\pi}\\bigl(\\alpha(x_1,x_2) - \\pi\\bigr).\n\\end{align*}\nThis is precisely $\\ArtPrpg$ from Part~I.\n%In particular, the standard Hodge propagator extends smoothly to the blow-up.\n% See \\cite{https://math.stackexchange.com/questions/566856/is-sum-n-1-infty-frac-sinnxn-continuous} for the computation of the sum.\n\\end{Example}\n\nFor $n\\ge 2$, an explicit formula for any of $\\StdPrpg$, $\\LapGKer$ or $\\KKer_t$ seems to be unknown. For $\\Sph{2}$, the formula for $\\StdPrpg$ on functions was derived by Dr.~A.~Hermann.\n\n\nOur idea to study $\\StdPrpg$ via $\\ArtPrpg$ is to examine the uniqueness of Hodge propagators. Consider the Schwartz form $\\HKer(x,y) = \\frac{1}{V}(\\Vol(x) + (-1)^n\\Vol(y))$ of the harmonic projection for $\\Sph{n}$. Let $C_2(\\Sph{n})\\coloneqq\\Sph{n}\\times\\Sph{n}\\backslash\\Diag$ denote the configuration space, and let\n\\begin{equation}\\label{Eq:DifEq}\n\\Soln_n\\coloneqq\\{\\Prpg\\in\\DR^{n-1}(C_2(\\Sph{n}))\\mid\\Dd\\Prpg=(-1)^n\\HKer\\}\n\\end{equation}\nbe the space of primitives to $(-1)^n\\HKer$. We know that $\\StdPrpg\\in \\Soln_n$. The following holds.\n\n\\begin{Proposition}[The space of primitives to $\\HKer$ for $\\Sph{n}$]\\label{Prop:SpaceOfSolnSn}\nLet\n$$ V_n\\coloneqq \\begin{cases}\n\\DR^{n-2}(C_2(\\Sph{n}))/\\Dd \\DR^{n-3}(C_2(\\Sph{n})) & \\text{for } n\\ge 3, \\\\\n\\DR^{0}(C_2(\\Sph{n}))/\\R & \\text{for }n=2,\n\\end{cases}$$\nwhere $\\R\\subset\\DR^0(C_2(\\Sph{n}))$ denotes the constants. The action $\\rho: V_n \\times \\Soln_n \\rightarrow \\Soln_n$, $(\\lambda,\\Prpg)\\mapsto \\Prpg + \\Dd\\lambda$ of the additive group $V_n$ on $\\Soln_n$ defines the structure of an affine space on $\\Soln_n$ for $n\\ge 2$. If we require $SO(n+1)$ or $(-1)^n\\tau^*$-invariance, then the same holds with $\\DR$ replaced by the correspondingly invariant forms.\n\\end{Proposition}\n\\begin{proof}\nWe have to check that the action $\\rho$ is free and transitive. For $\\Prpg_1$, $\\Prpg_2\\in \\Soln_n$, the difference $\\eta \\coloneqq \\Prpg_1 - \\Prpg_2$ is a closed $(n-1)$-form; it is exact because $C_2(\\Sph{n})$ is homotopy equivalent to $\\Sph{n}$. A primitive $\\lambda_1$ is an $n-2$ form. If $\\lambda_2$ is another primitive, then $\\lambda_1 - \\lambda_2$ is closed, and hence it is a constant for $n=2$ and an exact form for $n \\ge 3$. Therefore,~$\\Soln_n$ is an affine space over $V_n$. As for the invariance, we can average a primitive of an invariant form over $SO(n+1)$ or take $\\frac{1}{2}(\\Id + (-1)^n \\tau^*)$.\n\\end{proof}\n\nNote that $\\Soln_1 \\simeq \\R$ by adding the constant and that all functions on $C_2(\\Sph{1})$ are coexact. Therefore, $\\StdPrpg$ for $\\Sph{1}$ can not be characterized as a unique coexact solution of the differential equation for the Hodge propagator.\n\n\\begin{Proposition}[Coexactness of artificial Hodge propagator]\\label{Prop:ArtProsCoexact}\nThe Hodge propagator $\\ArtPrpg\\in\\DR^{n-1}(\\Sph{n}\\times\\Sph{n}\\backslash\\Diag)$ constructed in Part~I is coexact for every $n\\in \\N$.\n\\end{Proposition}\n\\begin{proof}\nFirst of all, we rewrite\n\\begin{align*}\n\\omega_k(x,y) &= \\frac{1}{k!(n-1-k)!}\\sum_{\\sigma\\in \\Perm_{n+1}} x^{\\sigma_1} y^{\\sigma_1} \\Diff{x}^{\\sigma_3} \\dotsb\\Diff{x}^{\\sigma_{2+k}} \\Diff{y}^{\\sigma_{3+k}}\\dotsb \\Diff{y}^{\\sigma_{n+1}} \\\\\n& = (-1)^k \\sum_{\\substack{I\\subset \\{1,\\dotsc,n+1\\} \\\\ \\Abs{I} = k + 1}} \\iota_x(\\Diff{x}^I) \\wedge \\underbrace{\\iota_y \\Star^{\\R^{n+1}}}_{\\Star^{\\Sph{n}}}(\\Diff{y}^I).\n\\end{align*}\nRecall the formulas $\\CoDd \\alpha = (-1)^{d(k-1)+1}\\Star \\Dd \\Star \\alpha$ and $\\Star \\Star \\alpha= (-1)^{k(n-k)}\\alpha$ for $\\alpha\\in \\DR^k(M)$, where $d=\\dim(M)$. For all $(x,y)\\in \\Sph{n}\\times\\Sph{n}\\backslash\\Diag$, we compute \n\\begin{align*}\n \\CoDd_y \\ArtPrpg(x,y) &= \\CoDd_y\\Bigl(\\sum_{k=0}^{n-1} (-1)^k g_k(x\\cdot y) \\sum_{\\substack{I\\subset\\{1,\\dotsc,n+1\\}\\\\\\Abs{I}=k+1}} (\\iota_x \\Diff{x}^I)\\wedge \\Star^{\\Sph{n}}(\\Diff{y}^I) \\Bigr) \\\\\n & =\\sum_{k=0}^{n-1}\\sum_{\\substack{I\\subset\\{1,\\dotsc,n+1\\}\\\\\\Abs{I}=k+1}} (\\iota_x \\Diff{x}^I)\\wedge\\CoDd_y\\bigl(g_k(x\\cdot y) \\Star^{\\Sph{n}}(\\Diff{y}^I)\\bigr) \\\\\n & \\underset{\\mathclap{\\qquad\\ \\; \\qquad\\subalign{& \\Big\\uparrow\\rule{0pt}{5.5ex} \\\\ \\CoDd_y &= (-1)^{n(n-k)+1}\\Star^{\\Sph{n}}\\Dd \\Star^{\\Sph{n}}\\\\\n\\Star^{\\Sph{n}} \\Star^{\\Sph{n}} &= (-1)^{(k+1)(n-k-1)} \\Id\\\\\n\\text{tot.~sign} &= (-1)^k}}}{=} \\sum_{k=0}^{n-1} (-1)^k \\sum_{\\substack{I\\subset\\{1,\\dotsc,n+1\\}\\\\\\Abs{I}=k+1}} (\\iota_x \\Diff{x}^I) \\wedge \\Star^{\\Sph{n}} \\Dd_y\\bigl(g_k(x\\cdot y) \\Diff{y}^I\\bigr) \\\\\n& = \\sum_{k=0}^{n-1}(-1)^k g_k'(x\\cdot y) \\sum_{\\substack{I \\subset \\{1,\\dotsc,n+1\\}\\\\\\Abs{I}=k+1\\\\}}\\underbrace{\\begin{multlined}[t] \\sum_{i\\in I} \\sum_{j\\in \\{1,\\dotsc,n+1\\}\\backslash I} \\varepsilon(i,I)\\varepsilon(j,I) x^i x^j \\\\ \\Diff{x}^{I\\backslash\\{i\\}}\\wedge\\Star^{\\Sph{n}}(\\Diff{y}^{I\\cup \\{j\\}}) \\end{multlined}}_{=0} \\\\\n& = 0.\n\\end{align*}\nThe cancellation occurs because the summand $(I, i, j)$ contains the same terms as the summand $(I'=I\\backslash\\{i\\}\\cup j, j, i)$, and the signs satisfy\n$$ \\varepsilon(j,I')\\varepsilon(i,I') = - \\varepsilon(i,I)\\varepsilon(j,I). $$\nWe have\n$$ \\H_{n-1}(\\DR(\\Sph{n}\\times\\Sph{n}\\backslash\\Diag),\\CoDd) \\simeq \\HDR^{n+1}(\\Sph{n}\\times\\Sph{n}\\backslash\\Diag) = 0, $$\nand hence any coclosed $(n-1)$-form is coexact.\n\\end{proof}\n\n\\begin{Proposition}[Smooth extension to the blow-up for $\\Sph{2}$]\\label{Prop:StdS2}\nThe standard Hodge propagator for $\\Sph{2}$ extends smoothly to the blow-up.\n\\end{Proposition}\n\\begin{proof}\nLet $\\Prpg_1$, $\\Prpg_2 \\in \\Soln_2$ be two $\\SO(3)$-symmetric solutions. Proposition~\\ref{Prop:SpaceOfSolnSn} asserts that there is a smooth $\\SO(3)$-symmetric function $\\lambda: C_2(\\Sph{2})\\rightarrow \\R$ such that $\\Prpg_1 - \\Prpg_2 = \\Dd \\lambda$. Because $\\SO(3)$ acts on $\\Sph{2}$ transitively, there is a smooth function $f: [-1,1)\\rightarrow \\R$ such that\n$$ \\lambda(x,y) = f(x\\cdot y)\\quad\\text{for all }(x,y)\\in C_2(\\Sph{2}). $$\nNote that one can let $f$ explode at $1$ and obtain Hodge propagators which do not extend smoothly to the blow-up. Let us assume, in addition, that $\\Prpg_1 - \\Prpg_2$ is coexact. We obtain \n$$ 0 = \\CoDd(\\Prpg_1 - \\Prpg_2) = \\CoDd \\Dd\\lambda = \\Laplace \\lambda. $$\nTherefore, $\\lambda$ is a harmonic function on $C_2(\\Sph{2})$. Denoting \n\\[\nB(x,y) \\coloneqq x\\cdot y,\n\\]\nwe can write $\\lambda = f\\circ B$,  which implies\n$$ \\Laplace(f \\circ B) = f'' \\Norm{\\Grad B}^2 + f' \\Laplace B. $$\nThe computation of $\\Norm{\\Grad B}$ and $\\Laplace B$ is straightforward and we will do it for any $n\\in \\N$. If $\\tilde{f}: \\Sph{n} \\rightarrow \\R$ is a smooth function and $f: \\R^{n+1} \\rightarrow \\R$ is defined by \n$$ f(x)\\coloneqq \\tilde{f}\\Bigl(\\frac{x}{\\Abs{x}}\\Bigr)\\quad\\text{for all }x\\in \\R^{n+1}\\backslash\\{0\\}, $$\nthen\n$$ \\Laplace^{\\Sph{n}} \\tilde{f} = \\Restr{\\bigl(\\Laplace^{\\R^{n+1}}f\\bigr)}{\\Sph{n}}\\quad\\text{and}\\quad \\Grad^{\\Sph{n}} \\tilde{f} = \\Restr{\\bigl(\\Grad^{\\R^{n+1}}f\\bigr)}{\\Sph{n}}. $$\nHere $\\Laplace^{\\Sph{n}}$, resp.~$\\Grad^{\\Sph{n}}$ are the Laplacian, resp.~the gradient on $\\Sph{n}$ expressed in terms of the corresponding operators $\\Laplace^{\\R^{n+1}}$ and $\\Grad^{\\R^{n+1}}$ on $\\R^{n+1}$, where $\\Sph{n}$ is embedded into. \nWe compute\n\\begin{align*}\n\\Laplace_x^{\\R^{n+1}} \\Bigl( \\frac{x}{\\Abs{x}}\\cdot y \\Bigr) &= \\sum_{i=1}^{n+1} - \\frac{\\partial}{\\partial x^i}\\Bigl(\\frac{y^i}{\\Abs{x}} - \\frac{x^i}{\\Abs{x}^3}x\\cdot y\\Bigr) \\\\\n &= \\sum_{i=1}^{n+1} \\frac{x^i y^i}{\\Abs{x}^3} - 3 \\frac{x^i x^i}{\\Abs{x}^5} x \\cdot y + \\frac{x\\cdot y}{\\Abs{x}^3} + \\frac{x^i y^i}{\\Abs{x}^3} \\\\\n & = 0,\\\\\n\\Grad^{\\R^{n+1}}_x\\Bigl(\\frac{x}{\\Abs{x}}\\cdot y\\Bigr) & = \\sum_{i=1}^{n+1} \\Bigl(\\frac{y^i}{\\Abs{x}} - \\frac{x^i}{\\Abs{x}^3}x\\cdot y \\Bigr)\\frac{\\partial}{\\partial x^i}\\quad\\text{and}\\\\\n\\Norm{\\Grad (x\\cdot y)}^2 &= \\Bigl\\|\\sum_{i=1}^{n+1}(y^i - (x\\cdot y) x^i) \\frac{\\partial}{\\partial x^i} + \\sum_{i=1}^{n+1}(x^i - (x\\cdot y) y^i) \\frac{\\partial}{\\partial y^i}\\Bigr\\|^2 \\\\\n& = \\sum_{i=1}^{n+1} (y^i - (x\\cdot y) x^i)^2 + (x^i - (x\\cdot y)y^i)^2 \\\\\n& = 1 - 2(x\\cdot y)^2 + (x\\cdot y)^2 + 1 - 2(x\\cdot y)^2 + (x\\cdot y)^2 \\\\\n& = 2(1- (x\\cdot y)^2).\n\\end{align*}\nTherefore, $\\Laplace B = 0$, $\\Norm{\\Grad B(x_1,x_2)}^2=2(1-(x_1\\cdot x_2)^2)$, and we arrive to the equation\n$$ 2(1-u^2) f''(u) = 0\\quad \\text{for all }u\\in[-1,1) $$\nand a smooth function $f: [-1,1) \\rightarrow \\R$. The only solution is a linear function, and it must hold\n$$ \\lambda(x_1,x_2) = a B(x_1, x_2) + b \\quad\\text{for some }a, b\\in \\R. $$\nWe see that $\\lambda$ extends smoothly to the blow-up.\n\\end{proof}\n\nIf we determine the constant $a$ in the proof of Proposition~\\ref{Prop:StdS2}, then we get a formula relating $\\HtpStd$ to $\\ArtPrpg$ for $\\Sph{2}$.\n\\ToDo[caption={Do more here!}]{This needs to be computed.}\n\n%For higher spheres we will have $\\ArtPrpg - \\StdPrpg \\in \\Im \\CoDd \\cap \\Im\\Dd$ and the primitives will be symmetric on the actions.\n%\n%\\Add[caption={Add about Hodge propagator for $\\Sph{n}$}]{\n%\\begin{itemize}\n%\\item Is a coexact solution of $\\Dd \\Prpg = H$ which smoothly extends to the blow-up unique?\n%\\item Can I check for $\\Sph{2}$ that $\\Im\\GOp\\subset\\Im\\CoDd$ or can I prove otherwise for the artificial green kernel. Can I find constants $A$, $B$?\n%\\item Can I say something about uniqueness on $\\Sph{3}$?\n%\\item What additional condition should specify $\\StdPrpg$ as the unique solution.\n%\\item GARBAGE: But we know uniqueness of the coexact operator. But coexact operator is not implied by coexact kernel because we can not switch integral and codifferential!!\n%\n%It does not hold that every solution of the equation $\\Dd \\Prpg = \\HKer$ defines a Green operator!. But those who extend smoothly to the blow-up yes.\n%\\end{itemize}}\n\\end{document}\n", "meta": {"hexsha": "fae182bdf3d6f9ffdc8c44e40cf0a73798263702", "size": 11968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Subfiles/GrKer_Sn.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_Sn.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_Sn.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": 76.7179487179, "max_line_length": 619, "alphanum_fraction": 0.642881016, "num_tokens": 4892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.6926119491410498}}
{"text": "\\section{Multiple linear regression}\n\n\\subsection{Model}\n\\begin{equation}\n\\label{eq:multiple_linear_regression_model}\nY = \\theta_0 + \\theta_1 * X_1 + \\theta_2 * X_2\n\\end{equation}\n\n% Regression without scaling the predictor variables\n\\subsection{Regression without scaling predictor variables}\n\\subsubsection{Initial values of parameters}\n\\begin{equation}\n\\theta_0 = 0.6520699150884046\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 0.9861396174652116\n\\end{equation}\n\\begin{equation}\n\\theta_2 = 0.9915108605252747\n\\end{equation}\n\n\\subsubsection{Final values of parameters}\n\\begin{equation}\n\\theta_0 = 4.311257778431243e+152\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 1.4490623380861671e+153\n\\end{equation}\n\\begin{equation}\n\\theta_2 = 2.685595874504226e+154\n\\end{equation}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth, height=.4\\textheight]{output_2/cost_function_alpha_0_01_unscaled.png}\n    \\caption{Mean squared error when predictor variables are not scaled}\n    \\label{fig:mean_squared_without_scaling}\n\\end{figure}\n\n% Regression after scaling the predictor variables\n\\subsection{Regression after scaling predictor variables}\n\\subsubsection{Initial values of parameters}\n\\begin{equation}\n\\theta_0 = 0.4409653770961314\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 0.16376353557709156\n\\end{equation}\n\\begin{equation}\n\\theta_2 = 0.2407927690962538\n\\end{equation}\n\n\\subsubsection{Final values of parameters}\n\\begin{equation}\n\\theta_0 = 1.545463253882367\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 3.8202281258797064\n\\end{equation}\n\\begin{equation}\n\\theta_2 = 1.0008683090251478\n\\end{equation}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth, height=.4\\textheight]{output_2/cost_function_alpha_0_01_scaled.png}\n    \\caption{Mean squared error when predictor variables are scaled}\n    \\label{fig:mean_squared_with_scaling}\n\\end{figure}\n\n\\subsection{Observation}\nEquation \\ref{eq:multiple_linear_regression_model} was used to model the prediction variable Y as a linear model of predicting variables $X_1$ and $X_2$. At first, multiple linear regression without parameter scaling was used to obtain the prediction line. The cost function value kept increasing and it failed to converge as shown in the figure \\ref{fig:mean_squared_without_scaling}.\n\nWhen parameter scaling was used with multiple linear regression the gradient descent algorithm converged and was able to obtain the optimum values for the $\\theta$s. The corresponding graph for cost function when predicting parameters were scaled is shown in figure \\ref{fig:mean_squared_with_scaling}.\n\\subsection{Conclusion}\nThe data that was used with multiple linear regression shows that the predictor variable $X_2$ had higher magnitude than the values of predictor variable $X_1$. Due to the dissimilarity in magnitude of predictor variables the gradient descent algorithm when used without feature scaling diverges and fails to yield an optimum regression line.\n\n\\subsection{Source Code}\n\n\\lstinputlisting[language=python]{task_2.py}\n", "meta": {"hexsha": "efe0f5ee98de6f5b8d4c763b2b115dbc2cfc7737", "size": 3007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/multiple_linear_regression.tex", "max_stars_repo_name": "diwasblack/machine_learning", "max_stars_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/multiple_linear_regression.tex", "max_issues_repo_name": "diwasblack/machine_learning", "max_issues_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/multiple_linear_regression.tex", "max_forks_repo_name": "diwasblack/machine_learning", "max_forks_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0632911392, "max_line_length": 385, "alphanum_fraction": 0.803791154, "num_tokens": 829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583169, "lm_q2_score": 0.8333245994514082, "lm_q1q2_score": 0.6926119474433546}}
{"text": "\\chapter{Lecture 1 May 02nd 2018}\n  \\label{chapter:lecture_1_may_02nd_2018}\n\n\\section{Introduction} % (fold)\n\\label{sec:introduction}\n\n\\subsection{Numbers} % (fold)\n\\label{sub:numbers}\n\nThe following are some of the number sets that we are already familiar with:\n\\begin{gather*}\n  \\mathbb{N} = \\{1, 2, 3, ...\\} \\qquad \\mathbb{Z} = \\{.., -2, -1, 0, 1, 2, ...\\} \\\\\n  \\mathbb{Q} = \\left\\{\\frac{a}{b} : a \\in \\mathbb{Z}, b \\in \\mathbb{N} \\right\\} \\qquad \\mathbb{R} = \\text{ set of real numbers} \\\\\n  \\mathbb{C} = \\{a + bi : a, b \\in \\mathbb{R}, i = \\sqrt{-1} \\} = \\text{ set of complex numbers} \n\\end{gather*}\nFor $n \\in \\mathbb{Z}$, let $\\mathbb{Z}_n$ denote the set of integers modulo $n$, i.e.\n\\begin{equation*}\n  \\mathbb{Z}_n = \\{ [0], [1], ..., [n - 1] \\}\n\\end{equation*}\nwhere the $[r]$, $0 \\leq r \\leq n - 1$, are the congruence classes, i.e.\n\\begin{equation*}\n  [r] = \\{z \\in \\mathbb{Z} : z \\equiv r \\mod n\\}\n\\end{equation*}\n\nThese sets share some common properties, e.g. $+$ and $\\times$. Let's try to break that down to make further observation.\n\n\\newthought{Note that} for $R = \\mathbb{N}, \\, \\mathbb{Z}, \\, \\mathbb{Q}, \\, \\mathbb{R}, \\, \\mathbb{C},$ or $\\mathbb{Z}_n$, $R$ has 2 operations, i.e. addition and multiplication.\n\n\\paragraph{Addition} If $r_1, r_2, r_3 \\in R$, then\n\\begin{itemize}\n  \\item (\\hldefn{closure}) $r_1 + r_2 \\in R$\n  \\item (\\hldefn{associativity}) $r_1 + (r_2 + r_3) = (r_1 + r_2) + r_3$\n\\end{itemize}\nAlso, if $R \\neq \\mathbb{N}$, then $\\exists 0 \\in R$ (the \\hldefn{additive identity}) such that\n\\begin{equation*}\n  \\forall r \\in R \\quad r + 0 = r = 0 + r.\n\\end{equation*}\nAlso, $\\forall r \\in R$, $\\exists (-r) \\in R$ such that\n\\begin{equation*}\n  r + (-r) = 0 = (-r) + r.\n\\end{equation*}\n\n\\paragraph{Multiplication} For $r_1, r_2, r_3 \\in R$, we have\n\\begin{itemize}\n  \\item (\\hlnoteb{closure}) $r_1 r_2 \\in R$\n  \\item (\\hlnoteb{associativity}) $r_1 (r_2 r_3) = (r_1 r_2) r_3$\n\\end{itemize}\nAlso, $\\exists 1 \\in R$ (a.k.a the \\hldefn{mutiplicative identity}), such that\n\\begin{equation*}\n  \\forall r \\in R \\quad r \\cdot 1 = r = 1 \\cdot r.\n\\end{equation*}\nFinally, for $R = \\mathbb{Q}, \\, \\mathbb{R},$ or $\\mathbb{C}$, $\\forall r \\in R, \\, \\exists r^{-1} \\in R$ such that\n\\begin{equation*}\n  r \\cdot r^{-1} = 1 = r^{-1} \\cdot r.\n\\end{equation*}\nNote that for $R = \\mathbb{Z}_n$, where $n \\in \\mathbb{Z}$, not all $[r] \\in \\mathbb{Z}_n$ have a multiplicative inverse. For example, for $[2] \\in \\mathbb{Z}_4$, there is no $[x] \\in \\mathbb{Z}_4$ such that $[2][x] = [1]$.\\sidenote{This is best proven using techniques introduced in MATH135/145.}\n\n% subsection numbers (end)\n\n\\subsection{Matrices}\n  \\label{sub:matrices}\n\nFor $n \\in \\mathbb{N} \\setminus \\{1\\}$, an $n \\times n$ matrix over $\\mathbb{R}$ \\sidenote{$\\mathbb{R}$ can be replaced by $\\mathbb{Q}$ or $\\mathbb{C}$.} is an $n \\times n$ array that can be expressed as follows:\n\\begin{equation*}\n  A = [a_{ij}] = \\begin{bmatrix}\n    a_{11} & a_{12} & \\hdots & a_{1n} \\\\\n    a_{21} & a_{22} & \\hdots & a_{2n} \\\\\n    \\vdots & \\vdots &        & \\vdots \\\\\n    a_{n1} & a_{n2} & \\hdots & a_{nn}\n  \\end{bmatrix}\n\\end{equation*}\nwhere for $1 \\leq i, j \\leq n$, $a_{ij} \\in \\mathbb{R}$. We denote $M_n(\\mathbb{R})$ as the set of all $n \\times n$ matrices over $\\mathbb{R}$.\n\nAs in \\cref{sub:numbers}, we can perform \\hlnotea{addition and multiplication} on $M_n(\\mathbb{R})$.\n\n\\paragraph{Matrix Addition} Given $A = [a_{ij}], B = [b_{ij}], C = [c_{ij}] \\in M_n(\\mathbb{R})$, we define matrix addition as\n\\begin{equation*}\n  A + B = [a_{ij} + b_{ij}],\n\\end{equation*}\nwhich immediately gives the \\hlnoteb{closure property}, since $a_{ij} + b_{ij} \\in \\mathbb{R}$ and hence $A + B \\in M_n(\\mathbb{R})$. Also, by this definition, we also immediately obtain the \\hlnoteb{associativity property}, i.e.\n\\begin{equation*}\n  A + (B + C) = (A + B) + C.\n\\end{equation*}\nWe define the zero matrix as\n\\begin{equation*}\n  0 = \\begin{bmatrix}\n    0      &   0    & \\hdots &   0 \\\\\n    0      &   0    & \\hdots &   0 \\\\\n    \\vdots & \\vdots &        & \\vdots \\\\\n    0      &   0    & \\hdots &   0\n  \\end{bmatrix}.\n\\end{equation*}\nThen we have that $0$ is the \\hlnoteb{additive identity}, i.e.\n\\begin{equation*}\n  A + 0 = A = 0 + A.\n\\end{equation*}\nFinally, $\\forall A \\in M_n(\\mathbb{R})$, $\\exists (-A) \\in M_n(\\mathbb{R})$ (the \\hlnoteb{additive inverse}) such that\n\\begin{equation*}\n  A + (-A) = 0 - (-A) + A.\n\\end{equation*}\n\nNote that in this case, we also have that that the operation is \\hlnoteb{commutative}, i.e.\n\\begin{equation*}\n  A + B = B + A.\n\\end{equation*}\n\n\\paragraph{Matrix Multiplication} Given $A = [a_{ij}], B = [b_{ij}], C = [c_{ij}] \\in M_n(\\mathbb{R})$, we define the matrix multiplication as\n\\begin{equation*}\n  AB = [d_{ij}] \\text{ where } c_{ij} = \\sum_{k=1}^{n} a_{ik} b_{kj} \\in \\mathbb{R}.\n\\end{equation*}\nClearly, $AB \\in M_n(\\mathbb{R})$, i.e. it is \\hlnoteb{closed under matrix multiplication}. Also, we have that, under such a defintion, matrix multiplication is \\hlnoteb{associative}, i.e.\n\\begin{equation*}\n  A(BC) = (AB)C.\n\\end{equation*}\nDefine the identity matrix, $I \\in M_n(\\mathbb{R})$, as follows:\n\\begin{equation*}\n  I = \\begin{bmatrix}\n    1      &   0    & \\hdots & 0 \\\\\n    0      &   1    & \\hdots & 0 \\\\\n    \\vdots & \\vdots &        & \\vdots \\\\\n    0      &   0    & \\hdots & 1\n  \\end{bmatrix}.\n\\end{equation*}\nThen we have that $I$ is the \\hlnoteb{multiplicative identity}, since\n\\begin{equation*}\n  AI = A = IA.\n\\end{equation*}\nHowever, contrary to matrix addition, $\\forall A \\in M_n(\\mathbb{R})$, it is not always true that $\\exists A^{-1} \\in M_n(\\mathbb{R})$ such that\\marginnote{This is especially true if the \\hlnotea{determinant} of $A$ is $0$.}\n\\begin{equation*}\n  AA^{-1} = I = A^{-1} A.\n\\end{equation*}\n\nAlso, we can always find some $A, B \\in M_n(\\mathbb{R})$ such that\n\\begin{equation*}\n  AB \\neq BA,\n\\end{equation*}\ni.e. matrix multiplication is not always commutative.\n\n\\newthought{The common properties} of the operations from above: \\hlimpo{closure, associativity, and existence of an inverse}, are not unique to just addition and multiplication. We shall see in the next lecture that there are other operations where these properties will continue to hold, e.g. \\hlnoteb{permutations}.\n\n% subsection matrices (end)\n\n% section introduction (end)\n\n% chapter lecture_1_may_02nd_2018 (end)\n", "meta": {"hexsha": "e3cd877d90b0751db6661ba70ad5159c1ab1382d", "size": 6318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PMATH347S18/lectures/lec01.tex", "max_stars_repo_name": "japorized/TeX_notes", "max_stars_repo_head_hexsha": "5814c8682addc5dd6f9a323758f87e4c4ca57b8e", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-09-28T21:23:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-21T01:41:27.000Z", "max_issues_repo_path": "PMATH347S18/lectures/lec01.tex", "max_issues_repo_name": "japorized/TeX_notes", "max_issues_repo_head_hexsha": "5814c8682addc5dd6f9a323758f87e4c4ca57b8e", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-29T17:58:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-29T17:58:51.000Z", "max_forks_repo_path": "PMATH347S18/lectures/lec01.tex", "max_forks_repo_name": "japorized/TeX_notes", "max_forks_repo_head_hexsha": "5814c8682addc5dd6f9a323758f87e4c4ca57b8e", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-09-27T20:55:58.000Z", "max_forks_repo_forks_event_max_datetime": "2017-09-27T20:55:58.000Z", "avg_line_length": 43.2739726027, "max_line_length": 318, "alphanum_fraction": 0.6240899019, "num_tokens": 2464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.692611942327753}}
{"text": "\\input{templates/ex_template.tex}\n\n\n\\title{BPP Exercise 8 -- Standard Library}\n% {YYYY}{MM}{DD}\n\\setdate{2019}{06}{02}\n\n\n\\begin{document}\n\n\\section{Warm-Up (20 points)}\n\n\\noindent 1.1. Using \\texttt{time}, print the number of seconds that have passed since January 1st 1970 00:00:00.\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\nimport time\n\nprint(time.time())\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\noindent 1.2. Using \\texttt{os}, write a function \\texttt{make\\_absolute} that converts a relative path to an absolute one.\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\nimport os\n\ndef make_absolute(relative_path):\n    \"\"\"Makes a relative path absolute.\"\"\"\n    return os.getcwd() + \"/\" + relative_path\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\noindent 1.3. Using \\texttt{math}, write two functions \\texttt{calculate\\_x} and \\texttt{calculate\\_y} that take an \\texttt{int n} between 1 and 12 as an argument and return the respective value of the following formulas:\n\n\\vspace{1em}\n\n\\noindent $calculate\\_x(n) = 3 * \\sin{\\frac{n * \\pi}{6}}$\n\n\\vspace{1em}\n\n\\noindent $calculate\\_y(n) = 3 * \\cos{\\frac{n * \\pi}{6}}$\n\n\\vspace{1em}\n\n\\noindent \\textbf{Background information (not relevant for the implementation):} \n\n\\vspace{1em}\n\n\\noindent These functions calculate the x and y position of the label for hour \\texttt{n} on a clock of radius 3. The x position of the hour 12 would e.g. be $3 * \\sin{\\frac{12 * \\pi}{6}} = 3 * \\sin{2 * \\pi} = 0$ and the y position $3 * \\cos{\\frac{12 * \\pi}{6}} = 3 * \\cos{2 * \\pi} = 3$.\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\nfrom math import sin, cos, pi\n\ndef calculate_x(n):\n    \"\"\"Calculates the x position of hour n on the clock.\"\"\"\n    return 3 * sin((n * pi) / 6)\n\ndef calculate_y(n):\n    \"\"\"Calculates the y position of hour n on the clock.\"\"\"\n    return 3 * cos((n * pi) / 6)\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\section{os, sys (20 points)}\n\nIn the folder Homework Sheets/Resources on StudIP, you will find the file 08\\_comp\\_tree.zip. Download it and extract it. \n\n\\vspace{1em}\n\n\\noindent 2.1. Familiarize yourself with the folder structure. Can you find the system behind the comparison tree? Briefly explain the rules in a file \\texttt{comp\\_tree\\_explained.txt}.\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\noindent There are three layers of folders. The folders on the lowest layer are all named after numbers between 1 and 100, e.g. \"26\". The folders on the middle layer are either also named after numbers or after comparisons with one specific number, e.g. \"larger\\_than\\_25\". The folders on the top layer are all named after comparisons. There are three kinds of comparisons: \"larger\\_than\", \"smaller\\_than\" and \"equals\". \\newline The numbers are sorted according to the comparisons, e.g. the folder \"larger\\_than\\_50\" contains only numbers that are larger than 50.\n\n\\end{solution}\n\n\\vspace{1em}\n\n\\noindent 2.2. Write a script \\texttt{insert.py} that takes a number as a command-line argument and then creates a folder with this name in the correct position according to the existing folder structure. You should use \\texttt{os.listdir()} and \\texttt{os.mkdir()} for this, which both take a relative or absolute path as an argument.\n\n\\vspace{1em}\n\n\\noindent \\textbf{Hint 1:} \\texttt{sys.argv[0]} is the name of your own script, \\texttt{sys.argv[1]} is the first command-line argument.\n\n\\noindent \\textbf{Hint 2:} With the command \\texttt{tree} in the terminal you can get an overview of the folder structure. A screenshot of this can also be found on StudIP in the folder Homework Sheets/Resources.\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\nimport sys\nimport os\n\ndef get_path(n):\n    \"\"\"Returns the path of n in a comp_tree structure.\"\"\"\n\n    rel_path = \"comp_tree/\"\n        \n    if n > 50:\n        rel_path += \"larger_than_50/\"\n        if n > 75:\n            rel_path += \"larger_than_75/\"\n        elif n < 75:\n            rel_path += \"smaller_than_75/\"\n        else:\n            rel_path += \"equals_75/\"\n    elif n < 50:\n        rel_path += \"smaller_than_50/\"\n        if n > 25:\n            rel_path += \"larger_than_25/\"\n        elif n < 25:\n            rel_path += \"smaller_than_25/\"\n        else:\n            rel_path += \"equals_25/\"\n    else:\n        rel_path += \"equals_50/\"\n\n    rel_path += str(n)\n\n    return rel_path\n\n    \nn = int(sys.argv[1])\npath = get_path(n)\n\nos.mkdir(path)\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\section{copy, random, time (30 points)}\n\n\\noindent 3.1. Write a function \\texttt{rand\\_change} that takes a nested 3x3 2d list (meaning a list with three row lists in it which each have three elements in it) as an argument and returns a deep copy of it in which one randomly selected cell was assigned a random integer between 1 and 3. Cells are elements of row lists.\n\n\\vspace{1em}\n\n\\noindent \\textbf{Example}:\n\n\\begin{pythoncode}\n\nmy_list = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]\n\nmy_list = rand_change(my_list)\n\nprint(my_list)\n# Output: [[1, 1, 1], [2, 1, 1], [1, 1, 1]]\n\n\\end{pythoncode}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\nfrom copy import deepcopy\nimport random\n\ndef rand_change(array):\n    \"\"\"Returns a copy with one random cell changed.\"\"\"\n    array_copy = deepcopy(array)\n    x = random.randint(0, 2)\n    y = random.randint(0, 2)\n    array_copy[x][y] = random.randint(1, 3)\n    return array_copy\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\noindent 3.2. Write a function \\texttt{get\\_diff} that takes two nested 3x3 2d lists and returns the number of how many cells (in the same x, y position) have different values.\n\n\\vspace{1em}\n\n\\noindent \\textbf{Example}:\n\n\\begin{pythoncode}\n\nlist_1 = [[1, 1, 1], [1, 1, 1], [2, 3, 1]]\n\nlist_2 = [[3, 3, 3], [3, 3, 3], [1, 2, 3]]\n\nprint(get_diff(list_1, list_2))\n# Output: 3\n\n\\end{pythoncode}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\ndef get_diff(array_1, array_2):\n    \"\"\"Returns the number of cells that differ.\"\"\"\n    diff = 0\n    for x in range(3):\n        for y in range(3):\n            if array_1[x][y] != array_2[x][y]:\n                diff += 1\n    return diff\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\noindent 3.3. Create two nested 3x3 2d lists \\texttt{ones} and \\texttt{threes}. \\texttt{ones} should be filled with value 1, \\texttt{threes} should be filled with the value 3. Change both 2d lists with \\texttt{rand\\_change} until \\texttt{get\\_diff(ones, threes)} returns 0. Measure the time this took in seconds and print it.\n\n\\vspace{1em}\n\n\\noindent \\textbf{Hint 1:} In the beginning, \\texttt{get\\_diff(ones, threes)} should return 9.\n\n\\noindent \\textbf{Hint 2:} This should take at most 10 seconds. If it takes longer, you made a mistake somewhere.\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\n# record start time\nstart = time.time()\n\nones = []\nthrees = []\n\n# fill ones and threes\nfor x in range(3):\n    row_ones = []\n    row_threes = []\n    for y in range(3):\n        row_ones.append(1)\n        row_threes.append(3)\n    ones.append(row_ones)\n    threes.append(row_threes)\n\ndiff = 1\n\nwhile diff > 0:\n    diff = get_diff(ones, threes)\n    ones = rand_change(ones)\n    threes = rand_change(threes)\n\n# print time difference in seconds\nprint(\"It took {:.4f} seconds\".format(time.time() - start))\n\n\\end{pythoncode}\n\n\\end{solution}\n\n\\section{math, time (30 points)}\n\nTo test our skills, we will implement a simplified formula for the increase in global temperature levels due to the radiative forcing of CO2 level changes.\n\n\\vspace{1em}\n\n\\noindent \\textbf{Keep in mind that the following is an extremely simplified model which may be outdated and might not represent the current scientific consensus.}\n\n\\vspace{1em}\n\n\\noindent \\textbf{Radiative forcing due to change in CO2 level:}\\qquad \\qquad \\qquad $\\Delta F = \\alpha * ln(\\frac{c_1}{c_0})$\n\n\\vspace{1em}\n\n\\noindent \\textbf{Relation between radiative forcing and temperature:} \\qquad $\\lambda = \\frac{\\Delta T}{\\Delta F}$\n\n\\vspace{1em}\n\n\\noindent $\\alpha$ is fixed at 5.35 while $\\lambda$ differs from model to model - we will simply use 0.5.\n\n\\vspace{1em}\n\n\\noindent $c_1$ denotes the changed CO2 level, $c_0$ denotes the unchanged CO2 level.\n\n\\vspace{1em}\n\n\\noindent Let's take the CO2 level of January 1970 as the unchanged CO2 level, so $c_0 = 325.03$. \n\n\\vspace{1em}\n\n\\noindent Current levels of CO2 were at $c_1 = 411.97$ as of March 2019. We will just assume that the CO2 level has not changed significantly since then for the purposes of our calculations.\n\n\\vspace{1em}\n\n\\noindent This would result in a 0.63 K increase in global temperature since 1970, which is consistent with the actual change in global temperature, especially considering that there are also other influences on the global climate such as other greenhouse gases.\n\n\\vspace{1em}\n\n\\noindent \\textbf{Your task is to do the following:} \n\n    \\begin{enumerate}\n\n        \\item Calculate how many hours have passed since January 1st 1970 00:00:00\n        \\item Use this time difference to calculate the average CO2 increase per hour since 1970\n        \\item Use this CO2 increase per hour to calculate a projection of what the CO2 level could be in 2100 (assuming that the CO2 increase per hour stays constant)\n        \\item Calculate the increase in temperature in from 1970 to 2100 (use your projected CO2 level as $c_1$ and the value from 1970 as $c_0$)\n        \\item Now generalize steps 3. and 4. by writing a function \\texttt{predict\\_increase} that takes an \\texttt{int year} larger than 1970 as an input and returns the increase in temperature from 1970 to \\texttt{year}\n\n    \\end{enumerate}\n\n\\vspace{1em}\n\n\\noindent \\textit{Formulas taken from: } IPCC (2001) Radiative Forcing of Climate Change, in Climate Change 2001: The Scientific Basis. Contribution of Working Group 1 to the Third Assessment. Report of the Intergovernmental Panel on Climate Change, CUP, pp. 349-416\n\n\\vspace{1em}\n\n\\noindent \\textit{CO2 values taken from: } Dr. Pieter Tans, NOAA/ESRL (www.esrl.noaa.gov/gmd/ccgg/trends/) and Dr. Ralph Keeling, Scripps Institution of Oceanography. \\url{https://www.esrl.noaa.gov/gmd/ccgg/trends/data.html}\n\n\\vspace{1em}\n\n\\begin{solution}\n\n\\begin{pythoncode}\n\nfrom math import log\nimport time\n\nco2_1970 = 325.03\nco2_now = 411.97\n\nalph = 5.35\nlamb = 0.5\n\n# hours that have passed since 1970\nhours_passed_now = time.time() / 3600\n\n# co2 increase since 1970\nco2_increase_now = co2_now - co2_1970\n\n# average co2 increase per hour since 1970\navg_co2_increase = co2_increase_now / hours_passed_now\n\n# hours that have passed between 1970 and 2100\nhours_passed_2100 = (2100 - 1970) * 365.25 * 24\n\n# co2 level projection for 2100\nco2_2100 = co2_1970 + (hours_passed_2100 * avg_co2_increase)\n\nprint(\"Projected CO2 level in 2100: {:.4f}\".format(co2_2100))\n\n# calculate change in radiative forcing\ndelta_F_2100 = alph * log(co2_2100 / co2_1970)\n\n# calculate change in temperature\ndelta_T_2100 = lamb * delta_F_2100\n\nprint(\"Projected temperature increase from 1970 to 2100: {:.4f}\".format(delta_T_2100))\n\ndef predict_increase(year):\n    \"\"\"Predicts the increase in temperature between 1970 and a given year.\"\"\"\n\n    # calculate projected value of co2 in year\n    hours_passed = (year - 1970) * 365.25 * 24\n    co2 = co2_1970 + (hours_passed * avg_co2_increase)\n    \n    # calculate temperature increase from 1970 to year\n    delta_F = alph * log(co2 / co2_1970)\n    delta_T = lamb * delta_F\n\n    print(\"Projected temperature increase from 1970 to {}: {:.4f}\".format(year, delta_T))\n\n    \n\\end{pythoncode}\n\n\\end{solution}\n\n\\end{document}\n", "meta": {"hexsha": "daf4a6b249aaf2b1329d145871cedfaa465a1aa7", "size": 11393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2019/08_Standard_Library/08_Standard_Library_Ex.tex", "max_stars_repo_name": "lfrommelt/monty", "max_stars_repo_head_hexsha": "e8cabf0e4ac01ab3d97eecee5e699139076d6544", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2019/08_Standard_Library/08_Standard_Library_Ex.tex", "max_issues_repo_name": "lfrommelt/monty", "max_issues_repo_head_hexsha": "e8cabf0e4ac01ab3d97eecee5e699139076d6544", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2019/08_Standard_Library/08_Standard_Library_Ex.tex", "max_forks_repo_name": "lfrommelt/monty", "max_forks_repo_head_hexsha": "e8cabf0e4ac01ab3d97eecee5e699139076d6544", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-20T14:26:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-20T14:26:28.000Z", "avg_line_length": 29.1381074169, "max_line_length": 564, "alphanum_fraction": 0.7054331607, "num_tokens": 3367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.9005297774417915, "lm_q1q2_score": 0.692579654724183}}
{"text": "\\section{Divergence, Curl and Laplacian}\r\n\\subsection{Definitions}\r\n\\begin{definition}\r\n    For a vector field $\\underline{F}:\\mathbb R^3\\to\\mathbb R^3$, we define the divergence\r\n    $$\\operatorname{div}\\underline{F}=\\nabla\\cdot\\underline{F}=\\frac{\\partial F_i}{\\partial x_i}$$\r\n    where the summation convention applies.\r\n\\end{definition}\r\n\\begin{definition}\r\n    For a vector field $\\underline{F}:\\mathbb R^3\\to\\mathbb R^3$, we define the curl\r\n    $$\\operatorname{curl}\\underline{F}=\\nabla\\times\\underline{F}=\\epsilon_{ijk}\\frac{\\partial F_k}{\\partial x_j}\\underline{e_i}$$\r\n    where again the summation convention applies.\r\n\\end{definition}\r\n\\begin{definition}\r\n    For a function $f:\\mathbb R^3\\to\\mathbb R$, we define the Laplacian\r\n    $$\\Delta f=\\nabla^2f=\\nabla\\cdot(\\nabla f)=\\frac{\\partial^2 f}{\\partial x_i\\partial x_i}$$\r\n    where yet again we have the summation convention.\r\n\\end{definition}\r\n\\begin{note}\r\n    All these are in Cartesians.\r\n\\end{note}\r\n\\begin{example}\r\n    Consider the vector field $\\underline{F}(\\underline{x})=\\underline{x}$, then $\\nabla\\cdot\\underline{F}=3$.\r\n    Also $(\\nabla\\times\\underline{F})_i=\\epsilon_{ijk}\\frac{\\partial F_k}{\\partial x_j}=\\epsilon_{ijk}\\delta_{jk}=0$, hence $\\nabla\\times\\underline{F}=\\underline{0}$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    We have the following identities:\r\n    $$\\nabla(fg)=(\\nabla f)g+f(\\nabla g)$$\r\n    $$\\nabla\\cdot(f\\underline{F})=(\\nabla f)\\cdot\\underline{F}+f(\\nabla\\cdot\\underline{F})$$\r\n    $$\\nabla\\times (fF)=(\\nabla f)\\times\\underline{F}+f(\\nabla\\times\\underline{F})$$\r\n    $$\\nabla(\\underline{F}\\cdot\\underline{G})=\\underline{F}\\times(\\nabla\\times\\underline{G})+\\underline{G}\\times(\\nabla\\times\\underline{F})+(\\underline{F}\\cdot\\nabla)\\underline{G}+(\\underline{G}\\cdot\\nabla)\\underline{F}$$\r\n    $$\\nabla\\times(\\underline{F}\\times\\underline{G})=\\underline{F}(\\nabla\\cdot\\underline{G})-\\underline{G}(\\nabla\\cdot\\underline{F})+(\\underline{G}\\cdot\\nabla)\\underline{F}-(\\underline{F}\\cdot\\nabla)\\underline{G}$$\r\n    $$\\nabla\\cdot(\\underline{F}\\times\\underline{G})=(\\nabla\\times\\underline{F})\\cdot\\underline{G}-\\underline{F}\\cdot(\\nabla\\times\\underline{G})$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nOf course we want, can can compute these three quantities in curvilinear coordinates, but we cannot do it directly since the basis vectors are not constant.\r\nHowever we can expand everything and get\r\n\\begin{proposition}\r\n    For a vector field $\\underline{F}$ under a curvilinear coordinate $\\underline{F}=F_u\\underline{e_u}+F_v\\underline{e_v}+F_w\\underline{e_w}$,\r\n    $$\\nabla\\cdot\\underline{F}=\\frac{1}{h_uh_vh_w}\\sum_{u,v,w}^{\\rm cyc}\\frac{\\partial}{\\partial u}(h_vh_wF_u)$$\r\n    $$\\nabla\\times\\underline{F}=\\sum_{u,v,w}^{\\rm cyc}\\frac{1}{h_vh_w}\\left( \\frac{\\partial}{\\partial v}(h_wF_w)-\\frac{\\partial}{\\partial w}(h_vF_v) \\right)\\underline{e_u}$$\r\n    And for a scalar function $f$,\r\n    $$\\nabla^2f=\\frac{1}{h_uh_vh_w}\\sum_{u,v,w}^{\\rm cyc}\\frac{\\partial}{\\partial u}\\left(\\frac{h_uh_w}{h_u}\\frac{\\partial f}{\\partial u}\\right)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial calculations.\r\n\\end{proof}\r\nIf one is bored, one can try and find the formulas for cylindral and spherical coordinates:\r\n$$\\nabla^2f=\\frac{1}{\\rho}\\frac{\\partial}{\\partial\\rho}\\left( \\rho\\frac{\\partial f}{\\partial\\rho} \\right)+\\frac{1}{\\rho^2}\\frac{\\partial^2f}{\\partial \\phi^2}+\\frac{\\partial^2f}{\\partial z^2}$$\r\n$$\\nabla^2f=\\frac{1}{r^2}\\frac{\\partial}{\\partial r}\\left( r^2\\frac{\\partial f}{\\partial r} \\right)+\\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial f}{\\partial\\theta} \\right)+\\frac{1}{r^2\\sin\\theta}\\frac{\\partial^2f}{\\partial\\phi^2}$$\r\nThe reason why we need these notions is for the generalization of fundamental Theorem of Calculus to general integrals, where some of these operators will be used as a substituent of derivative.\\\\\r\nThe reason we need Laplacians is that the PDE $\\nabla^2f=0$, whose solutions are called harmonic functions, is pretty important.\r\nOne of their properties that once they are twice differentiable (so as to let the equation make sense), then they are infinitely differentiable.\r\nEven better, they are all analytic, i.e. can be expressed in terms of power series.\r\n\\subsection{Relationships between the Operators}\r\n\\begin{proposition}\r\n    Let $f:\\mathbb R^3\\to\\mathbb R$ and $\\underline{F}:\\mathbb R^3\\to\\mathbb R^3$, then $\\nabla\\times\\nabla f=0$ and $\\nabla \\cdot(\\nabla\\times\\underline{F})=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nHence if $\\underline{F}$ is conservative, then it has zero curl.\r\nThe reverse implication is true when the domain is simply connected.\r\nFor example, if we take $\\mathbb R^3\\setminus\\{(0,0,z):z\\in\\mathbb R\\}$ as our domain, then this is not simply connected, but $\\mathbb R^3\\setminus\\{(0,0,0)\\}$ is.\\\\\r\nIf there exists vector fields $\\underline{A}$ such that $\\underline{F}=\\nabla\\times\\underline{A}$, we say $\\underline{A}$ is a vector potential of $\\underline{F}$.\r\nSo if $\\nabla\\cdot\\underline{F}=0$, we say $\\underline{F}$ is solenoidal.\r\nThe existence of a vector potential for $\\underline{F}$ implies $\\underline{F}$ is solenoidal.\r\nThe reverse implication is true when the domain is $2$-connected, that is, it is simply connected and the second homotopy group is trivial.\r\nFor example, $\\mathbb R^3$ is $2$-connected but $\\mathbb R^3\\setminus\\{(0,0,0)\\}$ is not.", "meta": {"hexsha": "85c8c6b751c1ab9a9d95f383f2c4764758033e1e", "size": 5411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/dcl.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/dcl.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/dcl.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": 77.3, "max_line_length": 273, "alphanum_fraction": 0.705784513, "num_tokens": 1824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6925727911170427}}
{"text": "\\section{Eligibility Traces}\n\n\\subsection{$\\lambda$-return}\n\\cindex{eligibility trace} is a short term memory vector that has the same dimension as $\\mathbf{W}$. \n\nThe \\cindex{forward view of TD($\\lambda$)} is defined as:\n\\begin{equation}\n\t\\begin{cases}\n\t\tG_t^\\lambda = (1-\\lambda)\\sum\\limits_{n=1}^\\infty \\lambda^{n-1} G_{t:t+n} & \\text{, for continuous task}\\\\\n\t\t\\\\\n\t\tG_t^\\lambda = (1-\\lambda)\\sum\\limits_{n=1}^{T-t-1} \\lambda^{n-1} G_{t:t+n} + \\lambda^{T-t-1}G_t & \\text{, for episodes} \n\t\\end{cases}\n\\end{equation}\n\n\\subsection{TD($\\lambda$)}\n\nIn \\cindex{backward view of TD($\\lambda$)}, the \\cindex{eligibility trace} $z_t \\in \\mathbb{R}^d$ is defined as:\n\\begin{equation}\n\t\\begin{aligned}\n\t\tz_{-1} &= 0 \\\\\n\t\tz_t &= \\gamma \\lambda z_{t-1} + \\nabla \\widehat{v} (S_t, \\mathbf{W}_t)\n\t\\end{aligned}\n\\end{equation}\n\nOf which $\\gamma$ is the discount rate and $\\lambda$ is the $\\lambda$ in TD($\\lambda$).\n\nThe TD error is defined as:\n\\begin{equation}\n\t\\delta_t = R_{t+1} + \\gamma \\widehat{v}(S_{t+1}, \\mathbf{W}_t) -\\widehat{v}(S_t, \\mathbf{W}_t) \n\\end{equation}\n\nThe gradient is defined as:\n\\begin{equation}\n\t\\mathbf{W}_{t+1} = \\mathbf{W}_t + \\alpha \\delta_t z_t\n\\end{equation}\n\nHere the $\\alpha$ is the ratio used for mean value converge calculation. \n\nIf $\\lambda = 0$, TD($\\lambda$) becomes one-step semi-gradient TD. \n\nIf $\\lambda = 1$, TD($\\lambda$) becomes Monte Carlo calculation.\n\n\nLinear TD($\\lambda$) will converge in on-policy case if step size follows formula (\\ref{convergenceofsequence}):\n\n\n\\begin{equation}\\label{semigradientlrerror}\n\t\\overline{\\text{VE}}(\\mathbf{W}_{\\infty}) \\leq \\frac{1 - \\gamma \\lambda}{1-\\gamma} \\underset{\\mathbf{W}}{\\min}\\ \\overline{\\text{VE}}(\\mathbf{W})\n\\end{equation}\n\nIn practice, do not choose $\\lambda = 1$ which is the poorest choice.\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "9013f9e7384334922fba033c6fa8c0ddaef43aba", "size": 1792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/reinforcement_learning/rl.8.eligibility_traces.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.8.eligibility_traces.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.8.eligibility_traces.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": 28.4444444444, "max_line_length": 145, "alphanum_fraction": 0.6702008929, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.6925727735130175}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Passivity}\n\\begin{align}\n\t\\dot{x} &= f(x,u) \\label{eq:passive1} \\\\\n\ty       &= h(x,u) \\label{eq:passive2}\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Memoryless functions}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Definition 6.1}\nThe system $y = h(t,u)$ is\n\\begin{itemize}\n\t\\item passive if $u\\T y \\geq 0$,\n\t\\item lossless if $u\\T y = 0$,\n\t\\item input-feedforward passive if $u\\T y \\geq u\\T \\phi(u)$ for some $\\phi(u)$,\n\t\\item input strictly passive if it is IFP and $u\\T \\phi(u) > 0 \\: \\forall \\: y \\neq 0$,\n\t\\item output-feedback passive if $u\\T y \\geq y\\T \\rho(y)$ for some $\\rho(y)$,\n\t\\item output strictly passive if it is OFP and $y\\T \\rho(y) > 0 \\: \\forall \\: y \\neq 0$.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{State models}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Definition 6.3}\nThe system \\eqref{eq:passive1}--\\eqref{eq:passive2} with storage function $V(x) \\geq 0$ is\n\\begin{itemize}\n\t\\item passive if $u\\T y \\geq \\dot{V}$,\n\t\\item lossless if $u\\T y = \\dot{V}$,\n\t\\item input-feedforward passive if $u\\T y \\geq \\dot{V} + u\\T \\phi(u)$ for some function $\\phi$,\n\t\\item input strictly passive if it is IFP with $u\\T \\phi(u) > 0 \\: \\forall \\: u \\neq 0$,\n\t\\item output-feedback passive if $u\\T y \\geq \\dot{V} + y\\T \\rho(y)$ for some function $\\rho$,\n\t\\item output strictly passive if it is OFP with $y\\T \\rho(y) > 0 \\: \\forall \\: y \\neq 0$,\n\t\\item strictly passive if $u\\T y \\geq \\dot{V} + \\psi(x)$ for some pos. def $\\psi$.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection[\\texorpdfstring{$\\mathcal{L}_2$ and Lyapunov stability}\n\t{L2 and Lyapunov stability}]\n\t{$\\mathcal{L}_2$ and Lyapunov stability}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Lemma 6.5 (finite-gain $\\mathcal{L}_2$ stable)}\nIf a system is output strictly passive with $\\rho(y) = \\delta y$ with $\\delta > 0$ then it is finite-gain $\\mathcal{L}_2$ stable with gain $\\gamma \\leq \\delta^{-1}$.\n\n\\paragraph{Definition 6.5 (zero-state observability)}\nThe system \\eqref{eq:passive1}--\\eqref{eq:passive2} is zero-state observable if only the solution $x(t) \\equiv 0$ of $\\dot{x} = f(x,0)$ can stay in $S = \\{ x \\in \\mathbb{R}^n | h(x,0) = 0 \\}$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Feedback systems}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=8cm]{feedback-connection.png}\n\t\\caption{Feedback connection}\n\\end{figure}\n\n\\paragraph{Theorem 6.1}\nThe feedback connection of two passive systems is passive, with $V = V_1 + V_2$.\n\n\\paragraph{Theorem 6.2 ($\\mathcal{L}_2$-stability of feedback connection)}\nIf $H_1$ and $H_2$ satisfy\n\\begin{equation}\n\te_i\\T y_i \\geq \\dot{V}_i + \\epsilon_i e_i\\T e_i + \\delta_i y_i\\T y_i\n\\end{equation}\nand\n\\begin{equation}\n\t\\epsilon_1 + \\delta_2 > 0 \\mbox{ and } \\epsilon_2 + \\delta_1 > 0\n\\end{equation}\nthen the feedback connection is finite-gain $\\mathcal{L}_2$-stable.", "meta": {"hexsha": "384eee657efc7f87c9f8da9dd8900af694650482", "size": 2898, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-passivity.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-passivity.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-passivity.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": 42.0, "max_line_length": 192, "alphanum_fraction": 0.6169772257, "num_tokens": 1034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.6925647397735417}}
{"text": "\\newpage\t\t\r\n\t\\section*{}\r\n\t\\textbf{Task}\\\\\r\n\tProve the equality:\r\n\t\\begin{gather*}\r\n\t\t\\sum\\limits_{k=0}^{n} {{n}\\choose{k}}^2 = {{2n}\\choose{n}}\r\n\t\\end{gather*}\r\n\t\\textbf{Solution}\\\\\r\n\tWe know that\r\n\t\\begin{gather*}\r\n\t\t{{n}\\choose{k}} = {{n}\\choose{n-k}}\r\n\t\\end{gather*}\r\n\tThen\r\n\t\\begin{gather*}\r\n\t\t\\sum\\limits_{k=0}^{n} {{n}\\choose{k}}^2 = \r\n\t\t\\sum\\limits_{k=0}^{n} {{n}\\choose{k}}{{n}\\choose{n-k}}\r\n\t\\end{gather*}\r\n\tThen we can see that this is the same as choosing $n-k$ objectsfrom the set of power $n$ and $k$ from the other set with the same size. Then, considering the sum of ${{n}\\choose{k}}{{n}\\choose{n-k}}$ for all possible k, we get the number of ways to select $n$ objects from a set of size $2n$. ", "meta": {"hexsha": "ca24233db5c19f9d9e4c7b563bc00cea7ae7032c", "size": 711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/1st term/Discrete Math/Spr_Mid/Body/P3.tex", "max_stars_repo_name": "Vladm0z/github.io", "max_stars_repo_head_hexsha": "e4ca87ac40286659eeb9b75493e6e73398cf1dec", "max_stars_repo_licenses": ["MIT"], "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/1st term/Discrete Math/Spr_Mid/Body/P3.tex", "max_issues_repo_name": "Vladm0z/github.io", "max_issues_repo_head_hexsha": "e4ca87ac40286659eeb9b75493e6e73398cf1dec", "max_issues_repo_licenses": ["MIT"], "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/1st term/Discrete Math/Spr_Mid/Body/P3.tex", "max_forks_repo_name": "Vladm0z/github.io", "max_forks_repo_head_hexsha": "e4ca87ac40286659eeb9b75493e6e73398cf1dec", "max_forks_repo_licenses": ["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.5, "max_line_length": 294, "alphanum_fraction": 0.611814346, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6925647397735416}}
{"text": "\\mychapter{3}{Lesson 3} %181003\n\n\\newcommand{\\ext}{\\textup{\\textsf{Ext}}}\n\\newcommand{\\statdist}{\\ensuremath{\\Delta_\\textsc{s}}}\n\\newcommand{\\sdtu}{\\ensuremath{\\Delta_\\textsc{u}}}\n\n\\section{Randomness Extraction}\n\nIn most of our discourse, the subject of uniformly random variables is much recurrent; this chapter/lesson delves deeper into the topic. For starters, we devise some attempts to extract uniform randomness from ``non-uniform'' randomness sources.\n\nSuppose to have a biased coin $B \\sim \\berdist(p) : p \\neq \\half$. How to craft a fair coin out of it? In his time, Von Neumann devised a simple algorithm, which is now known as the \\emph{Von Neumann extractor}:\n\n\\begin{enumerate}\n    \\item Let $B \\sim \\berdist(p)$ be a random variable\n    \\item \\label{enum:VNEsample} Sample $b_1 \\pickUAR B$\n    \\item Sample $b_2 \\pickUAR B$\n    \\item If $b_1 = b_2$ go to step \\ref{enum:VNEsample}\n    \\item \\label{enum:VNEreturn} Else:\n    \\begin{itemize}\n        \\item If $b_1 = 0 \\wedge b_2 = 1$ output 1\n        \\item If $b_1 = 1 \\wedge b_2 = 0$ output 0\n    \\end{itemize}\n\\end{enumerate}\n\nSome considerations can be made: The probability of both single cases in step \\ref{enum:VNEreturn} is $p(1 - p)$, therefore the probability to reach it is $2p(1 - p)$. Also, it is apparent that the number of possible failures in reaching step \\ref{enum:VNEreturn} follow a geometric distribution in $p$, thus the probability of an increased number of failures decrease exponentially.\n\nWe now get back to our ultimate goal. Let $X$ be any random variable over a space $\\Omega$, we wish to design an ``extraction'' algorithm \\ext{} such that $U = \\ext(X)$ distributes uniformly over $\\Omega$. To help ourselves, we will deal with probability spaces of binary strings ($\\binary^n$), and define a measure of ``how much'' a distribution is uniform over its space:\n\n\\begin{definition} Let X be a random variable from a given probability distribution. Its \\emph{min-entropy} is defined as follows:\n\\[\n    H_{\\infty}(X) = -\\log_2(\\max(\\Pr[X = x]))\n\\]\n\\end{definition}\n\nUsing this measure, we can already see an interesting case, which involves ``constant'' random variables:\n\\begin{align*}\n    X \\sim \\mathcal{C}onst(\\overline{x}) \\implies & \\Pr[X = \\overline{x}] = 1                                       \\\\\n                                         \\implies & \\Pr[X \\neq \\overline{x}] = 0                                    \\\\\n                                         \\implies & H_{\\infty}(X) = -\\log_2(\\Pr[X = \\overline{x}]) = -\\log_2(1) = 0 \\\\\n\\end{align*}\n\nAnd in fact, a constant variable is useless in creating a uniform distribution: it always gives the same outcome, making everything deterministic. Therefore, such variables must be excluded in our search for a ``universal extractor''.\nOn the other hand, looking at a uniform distribution:\n\\begin{align*}\n    X \\sim \\unifdist(\\Omega) \\implies & \\forall x \\Pr[X = x] = \\oneover{|\\Omega|}   \\\\\n                             \\implies & H_{\\infty}(X) = -\\log_2(\\oneover{|\\Omega|})\n\\end{align*}\n\nKnowing that $\\Omega$ is be our usual domain choice of binary strings of a given length $\\binary^n$, the min-entropy becomes exactly $n$\\footnote{This also sheds some light in how the string length is a frequent topic in the cryptography realm, as it usually expresses a cryptosystem's strength: the greater its min-entropy, the harder it is to find the right key from scratch for a ciphertext.}.\nUsing this measure, we can actually seek how much min-entropy we require in the original distribution $X$ in order for the extractor to return a uniform distribution. Ideally, we would like a value as close to 0 as possible, because a min-entropy of zero leads to constant variables, which have been excluded beforehand. Alas, it turns out that:\n\\begin{claim}\n    There is no such universal \\ext{} algorithm that returns a uniform distribution from random variables $X$ with min-entropy $H_{\\infty}(X) \\leq n - 1$\n\\end{claim}\n\n\\begin{proof}\n    % Notes: In our domain, the extraction problem to a unifdist reduces to an extraction of a fair coin; from there, creating a unifdist consists in doing as many coin flips as the strings' length in the domain of choice (remember we're still in the domain of binary strings, each coin flip is essentially one bit).\n\n    % Furthermore, extraction of a fair coin reduces to the extraction of a generic bernoulli variable: from there we can simply use the Von Neumann extractor to get a fair coin\n\n    % WHAT'S HAPPENING DOWN HERE?!?!?!\n\n    %Let \\ext{} be a candidate extractor which outputs a fair coin from any given random variable $X$ in a fixed-length binary string space. The resulting coin effectively splits $X$'s domain in two parts $X_0$ and $X_1$, in an attempt to balance the probability that $X$ is in either part. Now, pick the biggest one $X_b$\n\n    %ILLUMINATION: fix ext , run with any X, ext bipartitions the domain, define Y to be unif over an arbitrary part b. Ext(Y) will be forced to output the constant RV on b. contradiction\n\n    %AP190904: Don't like this model, appears to not reflect exactly the matter at hand; algorithms =/= functions\n\n    % Let \\ext{} be a candidate extractor, assume that $X$ is any random variable for which $\\ext(X)$ is a fair coin. Going deeper into the model, we can figure the extraction result to fairly bipartition the \"language\" that is formed by repeated saplings from X, as in: \"\\Omega*\". For example, the Von Neumann extractor recognizes the language (00|11)*(01)(0|1)* and doesn't recognize (00|11)*(10)(0|1)*.\n    % \n\n    \\todo{Help with the proof, things don't look good}\n\n    %Let \\ext{} be a candidate extractor, assume that $X$ is any random variable for which $\\ext(X)$ is a fair coin. We are %in a situation where \n    %\n    %Let \\ext{} be a candidate extractor, Let b be any binary value s.t. $|Ext^-1(b)|$ is maximal ($Ext^-1: \\binary \\to \\binary^n$)\\\\\n    %$\\implies |Ext^-1(b)|\\geq 2^{n-1}=\\frac{2^2}{2}$\n    %\n    %\\begin{figure}[ht]\n    %    \\centering\n    %    \\begin{tikzpicture}[>=latex]\n    %        \n    %        \\node (a1) {};\n    %        \\node[below=0.3cm of a1] (a2) {};\n    %        \\node[below=0.3cm of a2] (a3) {};\n    %\n    %        \\node[below=0.6cm of a3] (a4) {};\n    %        \\node[below=0.3cm of a4] (a5) {};\n    %        \\node[below=0.3cm of a5] (a6) {};\n    %\n    %        \\node[below=0.3cm of a3] (l) {};\n    %        \\node[right=1.4cm of l] (l1) {};\n    %        \\node[left=1.4cm of l] (l2) {};\n    %        \\draw[-,black] (l2) -- (l1);\n    %\n    %        \\node[right=4cm of a2] (b1) {$x=0$};\n    %        \\node[right=4cm of a5] (b3) {$x=1$};\n    %\n    %        \\node[ellipse,line width = 1pt, draw=black,minimum size=3cm,fit={(a1) (a6)}] {};\n    %\n    %        \\node[below=1cm of a6,font=\\color{black}\\Large] {$\\binary^n$};\n    %\n    %        \\draw[-,black] (a3) to[out=-10,in=190] (b1.190);\n    %        \\draw[-,black] (a2) -- (b1.180);\n    %        \\draw[-,black] (a1) to[out=10,in=170] (b1.170);\n    %\n    %        \\draw[-,black] (a6) to[out=-10,in=190] (b3.190);\n    %        \\draw[-,black] (a5) -- (b3.180);\n    %        \\draw[-,black] (a4) to[out=10,in=170] (b3.170);\n    %    \\end{tikzpicture}\n    %\\end{figure}\n    %\n    %Define $X$ to be uniform over $Ext^-1(b)$ so $H_{\\infty}(x)=n-1$ but $Ext(X)=b$ CONSTANT.\n    %\n    %\\dots\n\n\\end{proof}\n\nSo this approach is doomed unless we factor in a preemptive small amount of true randomness in the algorithm. This is what a \\emph{seeded extractor} does:\n\\[\n    \\ext: \\underbrace{\\binary^d}_{seed(public)}\\times \\underbrace{\\binary^n}_{input} \\to \\underbrace{\\binary^l}_{output}\n\\]\n\nBefore giving a formal definition of such an extractor, we require another notion of measure related to probability distributions:\n\n\\begin{definition} \\emph{Statistical Distance}:\n    Let $X$ and $Y$ be two random variables on the same probability space. Their \\emph{statistical distance} is defined as follows:\n    \\[\n        \\statdist(X, Y) = \\half\\sum_{x \\in \\Omega}|\\Pr[X = x] - \\Pr[Y = x]|\n    \\]\n\n\\end{definition}\n\nFrom a more visual perspective, this distance amounts to half the area delimited by the two distributions, if drawn one over another on the outcome space.\n\n\\todo{Image of the statistical distance}\n\nIn most scenarios, given a random variable $X$, it is valuable to know how much it is distant to a uniform random variable $U$ over the same space $\\Omega$. To this purpose, the notation $\\statdist(X, U)$ will be shortened to $\\sdtu(X)$, making any definition of uniform variables implicit.\n\n\\begin{definition}\n    Let $\\ext \\in \\binary^d \\times \\binary^n \\to \\binary^l$ be a seeded extractor, and $S \\sim \\unifdist(\\binary^d)$. Then it is a ($k$, $\\varepsilon$)-extractor iff:\n    \\[\n        \\forall X : H_{\\infty}(X) \\geq k \\implies \\statdist((S, \\ext(S, X)), (S, \\unifdist(\\binary^l))) \\leq \\varepsilon\n    \\]\n\\end{definition}\n\nDo note that $S$ takes part in both sides of the statistical distance: this is to be interpreted that the seed is known at the time of extraction.\n\n\\todo{Need to rethink this definition further}\n\n\\subsection{Universal hash functions}\n\nGetting back to our hash function families, we see that they too use an argument as a random seed, and attempt to be as uniform as possible; thus they behave in most ways as seeded extractors. Let's further develop the idea:\n\n\\begin{definition}\n    Let $S$ be a uniform seed. A hash function family $H$ is deemed \\emph{universal} iff:\n    \\[\n        \\forall a \\neq b \\in \\Omega \\implies \\Pr[h_S(a) = h_S(b)] = \\oneover{\\binary^l}\n    \\]\n\\end{definition}\n\n\\begin{definition}\n    Let $X$ and $Y$ be two \\iid{} random variables; a \\emph{collision} is the event of both variables evaluating to the same outcome. Such event probabilities are denoted as:\n    \\[\n        Col(X) = Col(Y) = \\Pr[X = Y]\n    \\]\n\\end{definition}\n\nA different formulation of collision probability can be reached by simple manipulations, with the added benefit that it refers to only one of the two \\iid{} random variables:\n\\begin{align*}\n    \\Pr(X = Y) =& \\sum_{x \\in \\Omega} \\Pr[X = x \\wedge Y = x] & \\text{(Total probability)} \\\\\n               =& \\sum_{x \\in \\Omega} \\Pr[X = x] \\Pr[Y = x]   & \\text{(Independency)}      \\\\\n               =& \\sum_{x \\in \\Omega} \\Pr[X = x]^2                                         \\\\\n\\end{align*}\n\n\\begin{lemma}[Collision bound] \\label{lem:colbound}\n    Let $X$ be a random variable such that its collision probability is upper bounded by the following function of some positive value $\\varepsilon$ arbitrarily close to $0$:\n    \\[\n        Col(X) \\leq \\frac{1 + 4\\varepsilon^2}{|\\Omega|}\n    \\]\n    Then $\\sdtu(X) \\leq \\varepsilon$, meaning that $X$ is almost uniform over $\\Omega$.\n\\end{lemma}\n\n\n\\begin{proof}\n    By definition of statistical distance:\n    \\[\n        \\sdtu(X) = \\half \\sum_{x \\in \\Omega} \\left| \\Pr[X = x] - \\oneover{|\\Omega|} \\right|\n    \\]\n\n    Decompose each of the above addends into the couple $q_x$ and $s_x$:\n    \\[\n        q_x = \\Pr[X = x] - \\oneover{|\\Omega|} \\qquad s_x =\n        \\begin{cases}\n            1  & \\text{if $q_x \\geq 0$} \\\\\n            -1 & \\text{otherwise}\n        \\end{cases}\n    \\]\n    \n    Then, by the Euclidean variant of the Cauchy-Schwarz inequality:\n    \\begin{align*}\n        \\sdtu(X) =&\\ \\half \\sum_{x \\in \\Omega} q_x s_x                                                                & \\text{(Decomposition)}     \\\\\n              \\leq&\\ \\half \\sqrt{ \\left( \\sum_{x \\in \\Omega} q_x^2 \\right) \\left( \\sum_{x \\in \\Omega} s_x^2 \\right) } & \\text{(Cauchy-Schwarz)}    \\\\\n                 =&\\ \\half \\sqrt{|\\Omega| \\sum_{x \\in \\Omega} q_x^2}                                                  & (\\forall x \\; (s_x^2 = 1)) \\\\\n    \\end{align*}\n\n    Focusing on the sum $\\sum_{x \\in \\Omega} q_x^2$:\n    \\begin{align*}\n        \\sum_{y \\in \\Omega} q_x^2 =&\\ \\sum_{x \\in \\Omega} \\left( \\Pr[X = x] - \\oneover{|\\Omega|} \\right)^2                                   &                        \\\\\n                                  =&\\ \\sum_{x \\in \\Omega} \\left( \\Pr[X = x]^2 - \\frac{2}{|\\Omega|} \\Pr[X = x] + \\oneover{|\\Omega|^2} \\right) &                        \\\\\n                                  =&\\ Col(X) - \\frac{2}{|\\Omega|} + \\frac{1}{|\\Omega|}                                                       &                        \\\\\n                               \\leq&\\ \\frac{1 + 4 \\varepsilon^2}{|\\Omega|} - \\frac{2}{|\\Omega|} + \\oneover{|\\Omega|}                         & \\text{(By hypothesis)} \\\\\n                                  =&\\ \\frac{4 \\varepsilon^2}{|\\Omega|}                                                                       &                        \\\\\n    \\end{align*}\n\n    Thus, getting back to the statistical distance evaluation:\n    \\begin{align*}\n        \\sdtu(X) \\leq&\\ \\half \\sqrt{|\\Omega| \\sum_{x \\in \\Omega} q_x^2}        \\\\\n                 \\leq&\\ \\half \\sqrt{|\\Omega| \\frac{4 \\varepsilon^2}{|\\Omega|}} \\\\\n                    =&\\ \\half 2 \\varepsilon = \\varepsilon                      \\\\\n    \\end{align*}\n\n    and by stating that $\\varepsilon$ is arbitrarily close to zero, $X$ is statistically close to the uniform distribution over $\\Omega$.\n\\end{proof}\n\n\\subsubsection{Leftover hash lemma}\n\nThis lemma has been proven by Russell Impagliazzo, Leonid Levin and Michael Luby:\n\n\\begin{lemma}[Leftover hash]\n    Let $h_s$ be a pairwise-independent hash function with uniform seed $S$, and $\\ext \\in \\binary^d \\times \\binary^n \\to \\binary^l$ be a seeded randomness extractor. Then if $\\ext(S, x) = h_S(x)$, and $x$ is governed by a random variable $X$ with min-entropy $H_{\\infty}(X) \\geq k$, where:\n    \\[\n       k = l - 2 \\log_2 \\varepsilon - 2\n    \\]\n    then $\\ext$ is a ($k$, $\\varepsilon$)-seeded randomness extractor.\n\\end{lemma}\n\n\\begin{proof}\n    The extractor definition requires that:\n    \\[\n        \\statdist(Y, (S, U_l)) \\leq \\varepsilon\n    \\]\n    where $U_l$ distributes uniformly over $\\binary^l$. Although the appearance of $S$ in both operands may seem to complicate things, the distance formulation can be changed to remove such constraint, and become simpler:\n    \\begin{align*}\n         &\\ \\statdist((S, h_S(X))), (S, U_l))                                                                                               &                \\\\\n        =&\\ \\half \\sum_{(s, t) \\in \\binary^{d + l}} \\left| \\Pr[(S, h_S(X))) = (s, t)] - \\Pr[(S, U_l) = (s, t)] \\right|                      &                \\\\\n        =&\\ \\half \\sum_{(s, t) \\in \\binary^{d + l}} \\left| \\Pr[(S, h_S(X))) = (s, t)] - \\oneover{|\\binary|^d} \\oneover{|\\binary^l|} \\right| & (S \\indep U_l) \\\\\n        =&\\ \\half \\sum_{(s, t) \\in \\binary^{d + l}} \\left| \\Pr[(S, h_S(X))) = (s, t)] - \\Pr[U_{d + l} = (s, t)] \\right|                     &                \\\\\n         &                                                                                          & \\mathllap{(U_{d + l} \\sim \\unifdist(\\binary^{d + l}))} \\\\\n        =&\\ \\statdist((S, h_S(X)), U_{d + l})                                                                                               &                \\\\\n        =&\\ \\sdtu((S, h_S(X)))                                                                                                              &                \\\\\n    \\end{align*}\n    \n    At this point the \\hyperref[lem:colbound]{collision bound} can be used to put an upper bound on this statistical distance. To this end, let $Y = (S, h_S(X))$ and $Y = (S, h_S(X))$ be two \\iid{} random variables; the collision probability of $Y$ equates to:\n    \\begin{align*}\n         &\\ Col(Y)                                               &                                               \\\\\n        =&\\ \\Pr[Y = Y']                                          &                                               \\\\\n        =&\\ \\Pr[S = S' \\wedge h_S(X) = h_{S'}(X')]               & \\mathllap{\\text{(By definition)}}             \\\\\n        =&\\ \\Pr[S = S'] \\Pr[h_S(X) = h_{S'}(X') \\knowing S = S'] & \\mathllap{\\text{(Conditional prob.)}}         \\\\\n        =&\\ \\Pr[S = S'] \\Pr[h_S(X) = h_S(X')]                    & \\mathllap{\\text{(Condition collapse)}}        \\\\\n        =&\\ 2^{-d} \\Pr[h_S(X) = h_S(X')]                         & \\mathllap{\\text{(Uniform collision prob.)}}   \\\\\n        =&\\ 2^{-d} \\left( \\Pr[h_S(X) = h_S(X') \\wedge X = X'] + \\Pr[h_S(X) = h_S(X') \\wedge X \\neq X'] \\right) & \\\\\n         &                                                       & \\mathllap{\\text{(Total probability)}}         \\\\\n    \\end{align*}\n\n    The two addends are tackled separately. For the first one: \n\n    \\begin{align*}\n         &\\ \\Pr[h_S(X) = h_S(X') \\wedge X = X']               &                               \\\\\n        =&\\ \\Pr[X = X'] \\Pr[h_S(X) = h_S(X') \\knowing X = X'] & \\text{(Conditional prob.)}    \\\\\n        =&\\ Col(X) \\Pr[h_S(X) = h_S(X') \\knowing X = X']      & \\text{(Collision def.)}       \\\\\n        =&\\ Col(X) \\Pr[h_S(X) = h_S(X)]                       & \\text{(Condition collapse)}   \\\\\n        =&\\ Col(X)                                            & \\text{(Prob. of a tautology)} \\\\\n    \\end{align*}\n\n    \\begin{proposition}\n        Given any random variable $X$:\n        \\[\n            H_\\infty(X) \\geq k \\implies Col(X) \\leq 2^{-k} \\qedhere\n        \\]\n    \\end{proposition}\n\n    \\begin{proof}\n        By definition of min-entropy\\footnote{The definition specifies explicitly a base-2 logarithm, but can actually be any base; in case, the statement to be proved shall correct the collision probability bound accordingly by changing its exponential basis}:\n        \\begin{align*}\n            -\\log \\max_{x \\in \\Omega}(\\Pr [X = x]) &\\geq k      \\\\\n            \\log \\max_{x \\in \\Omega}(\\Pr [X = x])  &\\leq -k     \\\\\n            \\max_{x \\in \\Omega}(\\Pr [X = x])       &\\leq 2^{-k} \\\\\n        \\end{align*}\n\n        On the other hand:\n        \\begin{align*}\n            Col(X) =&\\ \\sum_{x \\in \\Omega} \\Pr[X = x]^2                               \\\\\n                \\leq&\\ \\sum_{x \\in \\Omega} \\Pr[X = x] \\max_{y \\in \\Omega}(\\Pr[X = y]) \\\\\n                   =&\\ \\max_{y \\in \\Omega}(\\Pr[X = y]) \\sum_{x \\in \\Omega} \\Pr[X = x] \\\\\n                   =&\\ \\max_{y \\in \\Omega}(\\Pr[X = y])                                \\\\\n        \\end{align*}\n\n        Therefore:\n        \\[\n            Col(X) \\leq \\max_{x \\in \\Omega}(\\Pr[X = x]) \\leq 2^{-k}\n        \\]\n    \\end{proof}\n\n    Shifting the focus to the second addend:\n\n    \\begin{align*}\n            &\\ \\Pr[h_S(X) = h_S(X') \\wedge X \\neq X']                  &                                                  \\\\\n           =&\\ \\Pr[X \\neq X'] \\Pr[h_S(X) = h_S(X') \\knowing X \\neq X'] & \\text{(Conditional prob.)}                       \\\\\n        \\leq&\\ \\Pr[h_S(X) = h_S(X') \\knowing X \\neq X']                & \\mathllap{\\text{(Prob. is not greater than 1)}}  \\\\\n    \\end{align*}\n\n    \\begin{proposition}\n        If $h_S$ is a pairwise independent hash function, then:\n        \\[\n            \\Pr[h_S(X) = h_S(X') \\knowing X \\neq X'] \\leq 2^{-l}\n        \\]\n    \\end{proposition}\n    \n    \\begin{proof}\n        \\todo{Left as an exercise.}\n    \\end{proof}\n\n    Going back to the collision probability of $Y$, and using the two propositions above:\n    \\begin{align*}\n        Col(Y) \\leq&\\ 2^{-d} \\left( Col(X) + \\Pr[h_S(X) = h_S(X') \\knowing X \\neq X'] \\right) & \\\\\n               \\leq&\\ 2^{-d} (2^{-k} + 2^{-l}) & \\\\\n                  =&\\ 2^{-d - l} (2^{-k + l} + 2^{-l + l}) & \\\\\n                  =&\\ 2^{-d - l} (2^{-(l - 2 \\log_2(\\varepsilon) - 2) + l} + 1)  & \\\\\n                  =&\\ 2^{-d - l} (2^{2 \\log_2(\\varepsilon) + 2} + 1)  & \\\\\n                  =&\\ 2^{-d - l} (4\\varepsilon^2 + 1) & \\\\\n    \\end{align*}\n\n    Applying the collision bound entails that $\\sdtu(Y) \\leq \\varepsilon$, therefore $h_S$ is a $(k, \\varepsilon)$-seeded randomness extractor.\n\\end{proof}\n\nNote that for smaller values of $\\varepsilon$ we have greater values of min-entropy. A problem that is still open is to find an extractor with $k \\approx l$.\n", "meta": {"hexsha": "c051cccef4446081e7a2c50f380bed0bcdfafc2b", "size": 19870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_3.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_3.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_3.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": 58.9614243323, "max_line_length": 405, "alphanum_fraction": 0.5502767992, "num_tokens": 5812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924954, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.6925647395709164}}
{"text": "%!TEX root = da2020-07.tex\n\n\\Chapter{7}{Covering Maps}\n\n\\noindent\nChapters \\chapterref{3}--\\chapterref{6} have focused on positive results; now we will turn our attention to techniques that can be used to prove negative results. We will start with so-called covering maps\\mydash we will use covering maps to prove that many problems cannot be solved at all with deterministic $\\PN$-algorithms.\n\n\\section{Definition}\n\nA covering map is a topological concept that finds applications in many areas of mathematics, including graph theory. We will focus on one special case: covering maps between port-numbered networks.\n\nLet $N = (V,P,p)$ and $N' = (V'\\!,P'\\!,p')$ be port-numbered networks, and let $\\phi \\colon V \\to V'$. We say that $\\phi$ is a \\emph{covering map from $N$ to $N'$} if the following holds:\n\\begin{enumerate}\\raggedright\n    \\item $\\phi$ is a surjection: $\\phi(V) = V'$.\n    \\item $\\phi$ preserves degrees: $\\deg_{N}(v) = \\deg_{N'}(\\phi(v))$ for~all~$v \\in V$.\n    \\item $\\phi$ preserves connections and port numbers: $p(u,i) = (v,j)$ implies $p'(\\phi(u),i) = (\\phi(v),j)$.\n\\end{enumerate}\nSee Figures \\ref{fig:covering-map}--\\ref{fig:covering-map3} for examples.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PCoveringMap]{figs.pdf}\n    \\caption{There is a covering map $\\phi$ from $N$ to $N'$ that maps $a_i \\mapsto a$, $b_i \\mapsto b$, $c_i \\mapsto c$, and $d_i \\mapsto d$ for each $i \\in \\{1, 2\\}$.}\\label{fig:covering-map}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PCoveringMapB]{figs.pdf}\n    \\caption{There is a covering map $\\phi$ from $N$ to $N'$ that maps $v_i \\mapsto v$ for each $i \\in \\{1, 2, 3\\}$. Here $N$ is a simple port-numbered network but $N'$ is not.}\\label{fig:covering-map2}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PCoveringMapC]{figs.pdf}\n    \\caption{There is a covering map $\\phi$ from $N$ to $N'$ that maps $v_i \\mapsto v$ for each $i \\in \\{1, 2\\}$. Again, $N$ is a simple port-numbered network but $N'$ is not.}\\label{fig:covering-map3}\n\\end{figure}\n\nWe can also consider labeled networks, for example, networks with local inputs. Let $f\\colon V \\to X$ and $f'\\colon V' \\to X$. We say that $\\phi$ is a covering map from $(N,f)$ to $(N'\\!,f')$ if $\\phi$ is a covering map from $N$ to $N'$ and the following holds:\n\\begin{enumerate}[resume*]\n    \\item $\\phi$ preserves labels: $f(v) = f'(\\phi(v))$ for all $v \\in V$.\n\\end{enumerate}\n\n\\section{Covers and Executions}\n\nNow we will study covering maps from the perspective of deterministic $\\PN$-algorithms. The basic idea is that a covering map $\\phi$ from $N$ to $N'$ fools any $\\PN$-algorithm $A$: a node $v$ in $N$ is indistinguishable from the node $\\phi(v)$ in $N'$.\n\nWithout further ado, we state the main result and prove it\\mydash many applications and examples will follow.\n\n\\begin{theorem}\\label{thm:cover}\n    Assume that\n    \\begin{enumerate}[itemsep=0ex]\\raggedright\n        \\item $A$ is a deterministic $\\PN$-algorithm with $X = \\Input_A$,\n        \\item $N = (V,P,p)$ and $N' = (V'\\!,P'\\!,p')$ are port-numbered networks,\n        \\item $f\\colon V \\to X$ and $f'\\colon V' \\to X$ are arbitrary functions, and\n        \\item $\\phi\\colon V \\to V'$ is a covering map from $(N,f)$ to $(N'\\!,f')$.\n    \\end{enumerate}\n    Let\n    \\begin{enumerate}[resume*]\n        \\item $x_0, x_1, \\dotsc$ be the execution of $A$ on $(N,f)$, and\n        \\item $x'_0, x'_1, \\dotsc$ be the execution of $A$ on $(N'\\!,f')$.\n    \\end{enumerate}\n    Then for each $t = 0, 1, \\dotsc$ and each $v \\in V$ we have $x_t(v) = x'_t(\\phi(v))$.\n\\end{theorem}\n\n\\begin{proof}\n    We will use the notation of Section~\\longref{3.3.2}{ssec:execution}; the symbols with a prime refer to the execution of $A$ on $(N'\\!,f')$. In particular, $m'_t(u',i)$ is the message received by $u' \\in V'$ from port $i$ in round $t$ in the execution of $A$ on $(N'\\!,f')$, and $m'_t(u')$ is the vector of messages received by $u'$.\n    \n    The proof is by induction on $t$. To prove the base case $t = 0$, let $v \\in V$, $d = \\deg_N(v)$, and $v' = \\phi(v)$; we have\n    \\[\n        x'_0(v') = \\Init_{A,d}(f'(v')) = \\Init_{A,d}(f(v)) = x_0(v).\n    \\]\n    \n    For the inductive step, let $(u,i) \\in P$, $(v,j) = p(u,i)$, $d = \\deg_N(u)$, $\\ell = \\deg_N(v)$, $u' = \\phi(u)$, and $v' = \\phi(v)$. Let us first consider the messages sent by $v$ and $v'$; by the inductive assumption, these are equal:\n    \\[\n        \\Send_{A,\\ell}(x'_{t-1}(v')) = \\Send_{A,\\ell}(x_{t-1}(v)).\n    \\]\n    \n    A covering map $\\phi$ preserves connections and port numbers: $(u,i) = p(v,j)$ implies $(u',i) = p'(v',j)$. Hence $m_t(u,i)$ is component $j$ of $\\Send_{A,\\ell}(x_{t-1}(v))$, and $m'_t(u',i)$ is component $j$ of $\\Send_{A,\\ell}(x'_{t-1}(v'))$. It follows that $m_t(u,i) = m'_t(u',i)$ and $m_t(u) = m'_t(u')$. Therefore\n    \\begin{align*}\n        x'_t(u')\n        &= \\Receive_{A,d}\\bigl(x'_{t-1}(u'), m'_t(u') \\bigr) \\\\\n        &= \\Receive_{A,d}\\bigl(x_{t-1}(u), m_t(u) \\bigr)\n        = x_t(u). \\qedhere\n    \\end{align*}\n\\end{proof}\n\nIn particular, if the execution of $A$ on $(N,f)$ stops in time $T$, the execution of $A$ on $(N'\\!,f')$ stops in time $T$ as well, and vice versa. Moreover, $\\phi$ preserves the local outputs: $x_T(v) = x'_T(\\phi(v))$ for all $v \\in V$.\n\n\\section{Examples}\n\nWe will give representative examples of negative results that we can easily derive from Theorem~\\ref{thm:cover}. First, we will observe that a deterministic $\\PN$-algorithm cannot break symmetry in a cycle\\mydash unless we provide some symmetry-breaking information in local inputs.\n\n\\begin{lemma}\\label{lem:cycle-symmetric}\n    Let $G = (V,E)$ be a cycle graph, let $A$ be a deterministic $\\PN$-algorithm, and let $f$ be a constant function $f\\colon V \\to \\{0\\}$. Then there is a simple port-numbered network $N = (V,P,p)$ such that\n    \\begin{enumerate}\n        \\item the underlying graph of $N$ is $G$, and\n        \\item if $A$ stops on $(N,f)$, the output is a constant function $g\\colon V \\to \\{c\\}$ for some $c$.\n    \\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n    Label the nodes $V = \\Set{ v_1, v_2, \\dotsc, v_n }$ along the cycle so that the edges are\n    \\[\n        E = \\bigSet{ \\{v_1, v_2\\},\\ \\{v_2, v_3\\},\\ \\dotsc,\\ \\{v_{n-1}, v_n\\},\\ \\{v_n, v_1\\} }.\n    \\]\n    Choose the port numbering $p$ as follows:\n    \\begin{align*}\n        p\\colon &(v_1, 1) \\mapsto (v_2, 2),\\ (v_2, 1) \\mapsto (v_3, 2),\\ \\dotsc, \\\\\n                &(v_{n-1}, 1) \\mapsto (v_n, 2),\\ (v_n, 1) \\mapsto (v_1, 2).\n    \\end{align*}\n    See Figure~\\ref{fig:covering-map2} for an illustration in the case $n = 3$.\n    \n    Define another port-numbered network $N' = (V'\\!,P'\\!,p')$ with $V' = \\{v\\}$, $P' = \\{ (v,1), (v,2) \\}$, and $p(v,1) = (v,2)$. Let $f'\\colon V' \\to \\{0\\}$. Define a function $\\phi\\colon V \\to V'$ by setting $\\phi(v_i) = v$ for each $i$.\n    \n    Now we can verify that $\\phi$ is a covering map from $(N,f)$ to $(N'\\!,f')$. Assume that $A$ stops on $(N,f)$ and produces an output~$g$. By Theorem~\\ref{thm:cover}, $A$ also stops on $(N'\\!,f')$ and produces an output~$g'$. Let $c = g'(v)$. Now\n    \\[\n        g(v_i) = g'(\\phi(v_i)) = g'(v) = c\n    \\]\n    for all~$i$.\n\\end{proof}\n\nIn the above proof, we never assumed that the execution of $A$ on $N'$ makes any sense\\mydash after all, $N'$ is not even a simple port-numbered network, and there is no underlying graph. Algorithm $A$ was never designed to be applied to such a strange network with only one node. Nevertheless, the execution of $A$ on $N'$ is formally well-defined, and Theorem~\\ref{thm:cover} holds. We do not really care what $A$ outputs on $N'$, but the existence of a covering map can be used to prove that the output of $A$ on $N$ has certain properties. It may be best to interpret the execution of $A$ on $N'$ as a thought experiment, not as something that we would actually try to do in practice.\n\nLemma~\\ref{lem:cycle-symmetric} has many immediate corollaries.\n\n\\begin{corollary}\\label{cor:cycle-symmetric}\n    Let $\\calF$ be the family of cycle graphs. Then there is no deterministic $\\PN$-algorithm that solves any of the following problems on~$\\calF$:\n    \\begin{enumerate}[noitemsep]\n        \\item maximal independent set,\n        \\item \\Apx{1.999} of a minimum vertex cover,\n        \\item \\Apx{2.999} of a minimum dominating set,\n        \\item maximal matching,\n        \\item vertex coloring,\n        \\item weak coloring,\n        \\item edge coloring.\n    \\end{enumerate}\n\\end{corollary}\n\\begin{proof}\n    In each of these cases, there is a graph $G \\in \\calF$ such that a constant function is not a feasible solution in the network $N$ that we constructed in Lemma~\\ref{lem:cycle-symmetric}.\n    \n    For example, consider the case of dominating sets; other cases are similar. Assume that $G = (V,E)$ is a cycle with $3k$ nodes. Then a minimum dominating set consists of $k$ nodes\\mydash it is sufficient to take every third node. Hence a \\Apx{2.999} of a minimum dominating set consists of at most $2.999k < 3k$ nodes. A solution $D = V$ violates the approximation guarantee, as $D$ has too many nodes, while $D = \\emptyset$ is not a dominating set. Hence if $A$ outputs a constant function, it cannot produce a \\Apx{2.999} of a minimum dominating set.\n\\end{proof}\n\n\\begin{lemma}\n    There is no deterministic $\\PN$-algorithm that finds a weak coloring for every \\Reg{3} graph.\n\\end{lemma}\n\\begin{proof}\n    Again, we are going to apply the standard technique: pick a suitable \\Reg{3} graph $G$, find a port-numbered network $N$ that has $G$ as its underlying graph, find a smaller network $N'$ such that we have a covering map $\\phi$ from $N$ to $N'$, and apply Theorem~\\ref{thm:cover}.\n    \n    However, it is not immediately obvious which \\Reg{3} graph would be appropriate; hence we try the simplest possible case first. Let $G = (V,E)$ be the \\emph{complete graph} on four nodes: $V = \\Set{s,t,u,v}$, and we have an edge between any pair of nodes; see Figure~\\ref{fig:three-reg}. The graph is certainly \\Reg{3}: each node is adjacent to the other three nodes.\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[page=\\PThreeReg]{figs.pdf}\n        \\caption{Graph $G$ is the complete graph on four nodes. The edges of $G$ can be partitioned into a $2$-factor $X$ and a $1$-factor $Y$. Network $N$ has $G$ as its underlying graph, and there is a covering map $\\phi$ from $N$ to $N'$}\\label{fig:three-reg}\n    \\end{figure}\n        \n    Now it is easy to verify that the edges of $G$ can be partitioned into a $2$-factor $X$ and a $1$-factor $Y$. The $2$-factor consists of a cycle and a $1$-factor consists of disjoint edges. We can use the factors to guide the selection of port numbers in~$N$.\n    \n    In the cycle induced by $X$, we can choose symmetric port numbers using the same idea as what we had in the proof of Lemma~\\ref{lem:cycle-symmetric}; one end of each edge is connected to port $1$ while the other end is connected to port $2$. For the edges of the $1$-factor $Y$, we can assign port number $3$ at each end. We have constructed the port-numbered network $N$ that is illustrated in Figure~\\ref{fig:three-reg}.\n    \n    Now we can verify that there is a covering map $\\phi$ from $N$ to $N'$, where $N'$ is the network with one node illustrated in Figure~\\ref{fig:three-reg}. Therefore in any algorithm $A$, if we do not have any local inputs, all nodes of $N$ will produce the same output. However, a constant output is not a weak coloring of $G$.\n\\end{proof}\n\nIn the above proof, we could have also partitioned the edges of $G$ into three $1$-factors, and we could have used the $1$-factorization to guide the selection of port numbers. However, the above technique is more general: there are \\Reg{3} graphs that do not admit a $1$-factorization but that can be partitioned into a $1$-factor and a $2$-factor.\n\nSo far we have used only one covering map in our proofs; the following lemma gives an example of the use of more than one covering map.\n\n\\begin{lemma}\\label{lem:cycles-and-covers}\n    Let $\\calF = \\Set{G_3, G_4}$, where $G_3$ is the cycle graph with $3$ nodes, and $G_4$ is the cycle graph with $4$ nodes. There is no deterministic $\\PN$-algorithm that solves the following problem $\\Pi$ on $\\calF$: in $\\Pi(G_3)$ all nodes output $3$ and in $\\Pi(G_4)$ all nodes output $4$.\n\\end{lemma}\n\\begin{proof}\n    We again apply the construction of Lemma~\\ref{lem:cycle-symmetric}; for each $i \\in \\{3,4\\}$, let $N_i$ be the symmetric port-numbered network that has $G_i$ as the underlying graph.\n    \n    Now it would be convenient if we could construct a covering map from $N_4$ to $N_3$; however, this is not possible (see the exercises). Therefore we proceed as follows. Construct a one-node network $N'$ as in the proof of Lemma~\\ref{lem:cycle-symmetric}, construct the covering map $\\phi_3$ from $N_3$ to $N'$, and construct the covering map $\\phi_4$ from $N_4$ to $N'$; see Figure~\\ref{fig:cycles-and-covers}. The local inputs are assumed to be all zeros.\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[page=\\PCyclesAndCovers]{figs.pdf}\n        \\caption{The structure of the proof of Lemma~\\ref{lem:cycles-and-covers}.}\\label{fig:cycles-and-covers}\n    \\end{figure}\n    \n    Let $A$ be a $\\PN$-algorithm, and let $c$ be the output of the only node of $N'$. If we apply Theorem~\\ref{thm:cover} to $\\phi_3$, we conclude that all nodes of $N_3$ output $c$; if $A$ solves $\\Pi$ on $G_3$, we must have $c = 3$. However, if we apply Theorem~\\ref{thm:cover} to $\\phi_4$, we learn that all nodes of $N_4$ also output $c = 3$, and hence $A$ cannot solve $\\Pi$ on $\\calF$.\n\\end{proof}\n\nWe have learned that a deterministic $\\PN$-algorithm cannot determine the length of a cycle. In particular, a deterministic $\\PN$-algorithm cannot determine if the underlying graph is bipartite.\n\n\n\\section{Quiz}\n\nLet $G = (V, E)$ be a graph. A set $X \\subseteq V$ is a \\emph{$k$-tuple dominating set} if for every $v \\in V$ we have $|\\ball_G(v,1) \\cap X| \\ge k$. Consider the problem of finding a minimum 2-tuple dominating set in \\emph{cycles}. What is the best (i.e.\\ smallest) approximation ratio we can achieve in the $\\PN$ model?\n\n\n\\section{Exercises}\n\nWe use the following definition in the exercises. A graph $G$ is \\emph{homogeneous} if there are port-numbered networks $N$ and $N'$ and a covering map $\\phi$ from $N$ to $N'$ such that $N$ is simple, the underlying graph of $N$ is $G$, and $N'$ has only one node. For example, Lemma~\\ref{lem:cycle-symmetric} shows that all cycle graphs are homogeneous.\n\n\\begin{ex}[finding port numbers]\\label{ex:cover-three-reg1}\n    Consider the graph $G$ and network $N'$ illustrated in Figure~\\ref{fig:cover-ex-three-reg}. Find a simple port-numbered network $N$ such that $N$ has $G$ as the underlying graph and there is a covering map from $N$ to $N'$.\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[page=\\PCoverExThreeReg]{figs.pdf}\n        \\caption{Graph $G$ and network $N'$ for Exercises \\ref{ex:cover-three-reg1} and \\ref{ex:cover-reg}b.}\\label{fig:cover-ex-three-reg}\n    \\end{figure}\n\\end{ex}\n\n\\begin{ex}[homogeneity]\n    Assume that $G$ is homogeneous and it contains a node of degree at least two. Give several examples of graph problems that cannot be solved with any deterministic $\\PN$-algorithm in any family of graphs that contains $G$.\n\\end{ex}\n\n\\begin{ex}[regular and homogeneous]\\label{ex:cover-reg}\n    Show that the following graphs are homogeneous:\n    \\begin{subex}\n        \\item graph $G$ illustrated in Figure~\\ref{fig:cover-ex-four-reg},\n        \\item graph $G$ illustrated in Figure~\\ref{fig:cover-ex-three-reg}.\n    \\end{subex}\n\n    \\hint{(a)~Apply the result of Exercise~\\longref{2.8}{ex:2fact}. (b)~Find a $1$-factor.}\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[page=\\PCoverExFourReg]{figs.pdf}\n        \\caption{Graph $G$ for Exercise~\\ref{ex:cover-reg}a.}\\label{fig:cover-ex-four-reg}\n    \\end{figure}\n\\end{ex}\n\n\\begin{ex}[complete graphs]\\label{ex:cover-complete}\n    Recall that we say that a graph $G = (V,E)$ is \\emph{complete} if for all nodes $u, v \\in V$, $u \\ne v$, there is an edge $\\{u,v\\} \\in E$. Show that\n    \\begin{subex}\n        \\item any $2k$-regular graph is homogeneous,\n        \\item any complete graph with $2k$ nodes has a $1$-factorization,\n        \\item any complete graph is homogeneous.\n    \\end{subex}\n\\end{ex}\n\n\\begin{ex}[dominating sets]\\label{ex:domset}\n    Let $\\Delta \\in \\{2,3,\\dotsc\\}$, let $\\epsilon > 0$, and let $\\calF$ consist of all graphs of maximum degree at most $\\Delta$. Show that it is possible to find a \\Apx{(\\Delta+1)} of a minimum dominating set in constant time in family~$\\calF$ with a deterministic $\\PN$-algorithm. Show that it is not possible to find a \\Apx{(\\Delta+1-\\epsilon)} with a deterministic $\\PN$-algorithm.\n    \n    \\hint{For the lower bound, use the result of Exercise~\\ref{ex:cover-complete}c.}\n\\end{ex}\n\n\\begin{ex}[covers with covers]\\label{ex:cover-cover}\n    What is the connection between covering maps and the vertex cover 3-approximation algorithm in Section~\\longref{3.6}{sec:vc3}?\n\\end{ex}\n\n\\begin{exs}[\\Reg{3} and not homogeneous]\\label{ex:cover-three-reg-b}\n    Consider the graph $G$ illustrated in Figure~\\ref{fig:cover-ex-three-reg-b}.\n    \\begin{subex}\n        \\item Show that $G$ is not homogeneous.\n        \\item Present a deterministic $\\PN$-algorithm $A$ with the following property: if $N$ is a simple port-numbered network that has $G$ as the underlying graph, and we execute $A$ on $N$, then $A$ stops and produces an output where at least one node outputs $0$ and at least one node outputs $1$.\n        \\item Find a simple port-numbered network $N$ that has $G$ as the underlying graph, a port-numbered network $N'$, and a covering map $\\phi$ from $N$ to $N'$ such that $N'$ has the smallest possible number of nodes.\n    \\end{subex}\n    \\hint{Show that if a \\Reg{3} graph is homogeneous, then it has a $1$-factor. Show that $G$ does not have any $1$-factor.}\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[page=\\PCoverExThreeRegB]{figs.pdf}\n        \\caption{Graph $G$ for Exercise~\\ref{ex:cover-three-reg-b}.}\\label{fig:cover-ex-three-reg-b}\n    \\end{figure}\n\\end{exs}\n\n\\begin{exs}[covers and connectivity]\n    Assume that $N = (V,P,p)$ and $N' = (V'\\!,P'\\!,p')$ are simple port-numbered networks such that there is a covering map $\\phi$ from $N$ to $N'$. Let $G$ be the underlying graph of network $N$, and let $G'$ be the underlying graph of network~$N'$.\n    \\begin{subex}\n        \\item Is it possible that $G$ is connected and $G'$ is not connected?\n        \\item Is it possible that $G$ is not connected and $G'$ is connected?\n    \\end{subex}\n\\end{exs}\n\n\\begin{exs}[$k$-fold covers]\n    Let $N = (V,P,p)$ and $N' = (V'\\!,P'\\!,p')$ be simple port-numbered networks\n    such that the underlying graphs of $N$ and $N'$ are connected, and\n    assume that $\\phi\\colon V \\to V'$ is a covering map from $N$ to $N'$.\n    Prove that there exists a positive integer $k$ such that the following holds:\n    $|V| = k |V'|$ and for each node $v' \\in V'$ we have $|\\phi^{-1}(v')| = k$.\n    Show that the claim does not necessarily hold if the underlying graphs are not connected.\n\\end{exs}\n\n\n\\section{Bibliographic Notes}\n\nThe use of covering maps in the context of distributed algorithm was introduced by Angluin~\\cite{angluin80local}. The general idea of Exercise~\\ref{ex:cover-three-reg-b} can be traced back to Yamashita and Kameda~\\cite{yamashita96computing}, while the specific construction in Figure~\\ref{fig:cover-ex-three-reg-b} is from Bondy and Murty's textbook~\\cite[Figure~5.10]{bondy76graph-theory}. Parts of exercises \\ref{ex:cover-three-reg1}, \\ref{ex:cover-reg}, \\ref{ex:cover-complete}, and \\ref{ex:domset} are inspired by our work \\cite{suomela10eds,astrand10weakly-coloured}.\n", "meta": {"hexsha": "05d91945ef586a4b347d25203c06df1bd4b58404", "size": 19810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/ch07.tex", "max_stars_repo_name": "suomela/da2020", "max_stars_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-12-11T00:47:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T15:46:43.000Z", "max_issues_repo_path": "book/ch07.tex", "max_issues_repo_name": "suomela/da2020", "max_issues_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-17T18:31:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-17T18:42:16.000Z", "max_forks_repo_path": "book/ch07.tex", "max_forks_repo_name": "suomela/da2020", "max_forks_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-22T03:53:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:33:40.000Z", "avg_line_length": 70.0, "max_line_length": 688, "alphanum_fraction": 0.6695103483, "num_tokens": 6176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070838, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6925647206923488}}
{"text": "\\section{Graph and network optimization}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/graphsIntroduction.png}\n\\caption{Introduction to Graphs}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{figures/weightedAdjecency.png}\n\\caption{Example Graph with weight and Adjecency Matrix }\n\\end{figure}\n\n\\subsection{Depth-First Search (DFS)}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/dfs.png}\n\\caption{Depth-First Search}\n\\end{figure}\n\n\\subsection{Breadth-First Search (BFS)}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/bfs.png}\n\\caption{Depth-First Search}\n\\end{figure}\n\n\\subsection{Spanning trees}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/spanningtree.png}\n\\caption{Spanning trees}\n\\end{figure}\n\n\\subsubsection{Minimal weight Optimistic approach (And Kruskal’s algorithm)}\n\n\\textbf{The Kruskal algorithm is exactly the same approach like the optimistic approach.} \\\\\n\\textit{The Prim algorithm just differ a little bit since you have a starting node and then search within the connected edges.}\n\n\\begin{enumerate}\n    \\item Find the next edge with the lowest weight in the whole graph\n    \\item Check if the edge is redundant or not\n    \\item If the edge is not redundant, mark it as usable. If it is redundant, mark it as unusable\n    \\item Repeat until you have all edges checked\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/optimisticGraphAlg.png}\n\\caption{Minimal weight - Optimistic Approach}\n\\end{figure}\n\n\\subsubsection{Minimal weight Pessimistic approach}\n\n\n\\begin{enumerate}\n    \\item Find the next edge with the highest weight in the whole graph\n    \\item Check if you can remove the edge without splitting the graph into two graphs\n    \\item If you can remove the edge, mark it as unusable. If you can't remove the edge, mark it as usable\n    \\item Repeat until you have all edges checked\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/pessimisticGraphAlg.png}\n\\caption{Minimal weight - Pessimistic Approach}\n\\end{figure}\n\n\\clearpage\n\\subsubsection{Minimal weight Prim's algorithm}\nChoose an arbitrary start vertex $v_0$ and set $M = \\{v_0\\}$.\nIteratively add to $M$ a vertex in $V \\setminus M$ that can be reached the\ncheapest from the current set $M$. Select the corresponding\nedge. Continue until $M = V$ .\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/primsGraphAlg.png}\n\\caption{Minimal weight - Prim's Algorithm}\n\\end{figure}\n\n\\subsection{Shortes path problem}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/shortestPathProblem.png}\n\\caption{Spanning trees}\n\\end{figure}\n\n\\clearpage\n\\subsubsection{Dijkstra's algorithm}\nComputes shortest paths from one vertex $v_0$ to all other vertices (i.e., a shortest-paths tree from $v_0$).\nWe iteratively compute the shortest distance $l(v)$ for the vertex\n$v$ closest to $v_0$ that has not been reached yet, as follows:\n\n\\begin{enumerate}\n    \\item Set $V_0 = \\{v_0\\}, E_0 = \\{\\}$ and $I(v_0) = 0$\n    \\item Do the following $n-1$ times: \\\\\n    $V_i = \\{v_0, ..., v_i\\}$ and $E_i = \\{e_1, ..., e_i\\}$ are the sets of vertices and edges already visited. For each edge $e = (u, v)$ with $u \\in V_i$ and $v \\in V \\setminus V_i$, compute $l(u) + weight(e)$. Choose the edge minimizing this as $e_{i+1} = (u_{i+1}, v_{i+1})$. \\\\\n    Set $V_{i+1} = V_i  \\cup \\{v_{i+1}\\}, E_{i+1} = E_i \\cup \\{e_{i+1}\\}$ and $l(v_{i+1}) = l(u_{i+1}) + weight(e_{i+1})$\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/dijkstra.png}\n\\caption{Shortest Path - Dijkstra's Algorithm}\n\\end{figure}\n\n\\clearpage\n\\subsubsection{Floyd-Warshall algorithm}\n\nThe Floyd-Warshall algorithm solves the all-pairs shortest paths\nproblem. Unlike Dijkstra’s algorithm, it can also handle the case of\nnegative edge-weights.\n\n\\begin{enumerate}\n    \\item Initialization: \\\\\n    $minPath(i, j, 0) =\n  \\begin{cases}\n    w(v_i, v_j)       & \\quad \\text{if } (v_i, v_j) \\in E\\\\\n     \\infty   & \\quad \\text{else}\n  \\end{cases}$\n  \\item For $k = 1,2,..., n$ compute: \\\\\n  $minPath (i, j, k )$ for all $i$ und $j$ according iteration formula\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/floyd1.png}\n\\caption{Shortest Path - Floyd-Warshall Matrix 1}\n\\end{figure}\n\n\\begin{itemize}\n    \\item Now I start with the first node $a$ and compare every other node if I can find a shorter path over $a$\n    \\item Starting this iteration with $b$, I check if I can find e.g. a shorter path from $b$ to $d$ over $a$.\n    \\item In this example, I see from $b$ to $d$ the weight is $5$. From $a$ to $b$ it is $3$, from $a$ to $d$ it is $9$, which would make a total of $12$. Since $12 \\geq 5$, we leave $5$ and check the next node.\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/floyd2.png}\n\\caption{Shortest Path - Floyd-Warshall Matrix 2}\n\\end{figure}\n\n\\begin{itemize}\n    \\item After we have done this for every entry in the matrix compared to $a$, we start the next iteration step and comparing it with $b$\n    \\item In the next example, we found a improvement for the connection from $a$ to $d$. $a$ to $d$ has a weight of $9$, but if you go first from $a$ to $b$ with $3$, and then from $b$ to $d$ with $5$, you have a weight of $8$.\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/floyd3.png}\n\\caption{Shortest Path - Floyd-Warshall Matrix 3}\n\\end{figure}\n\n\\begin{itemize}\n    \\item After every iteration step, write the improvements directly into the matrix\n    \\item After comparing the entries in the matrix to every node, you should not have any $\\infty$ anymore.\n\\end{itemize}\n\n\\clearpage\n\\subsection{Network flow}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/networkFlow.png}\n\\caption{Network Flow}\n\\end{figure}\n\n\\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]\nAn \\textbf{st-network} $(G, w, s, t)$ is a weighted graph $G(V,E)$ with weight function $w$ and two distinguished vertices $s,t, \\in V$, where $s$ is the source and $t$ is the target.\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]\nA graph $G(V,E)$ is \\textbf{bipartite} if its vertex set can be split in two parts $A$ and $B$ such that all edges have one vertex in $A$ and one in $B$.\n\\end{tcolorbox}\n\n\\subsubsection{Maximum Flow}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/maximumFlow.png}\n\\caption{Maximum Network Flow Example}\n\\end{figure}\n\nFinding the first best maximum network flow is not the best solution all the time. Sometimes, there are multiple paths and therefore you need to check more than one path. The Ford-Fulkerson algorithm checks already used paths for this.\n\n\\subsubsection{Ford-Fulkerson algorithm}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/ford-fulkerson.png}\n\\caption{Ford Fulkerson algorithm}\n\\end{figure}\n\n\\subsubsection{Edmonds-Karp algorithm}\nThe Edmonds-Karp algorithm finds the path from $s$ to $t$ with the fewest number of edges. The algorithm is using Breadth-First Search for finding this.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/Edmonds-Karp.png}\n\\caption{Edmonds-Karp algorithm}\n\\end{figure}\n\n\\subsubsection{Distribution Problem}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/distributionProblem.png}\n\\caption{Network Flow - Distribution Problem}\n\\end{figure}\n\n\\subsubsection{Vertices with restrictions}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/restrictionModelling.png}\n\\caption{Network Flow - Vertices with restrictions}\n\\end{figure}\n\n\\subsubsection{Bipartite Matching}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/bipartiteMatching.png}\n\\caption{Network Flow - Bipartite Matching}\n\\end{figure}\n\n\\subsubsection{ST-Cut}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/stCut.png}\n\\caption{Network Flow - ST-Cut}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/st-cut.png}\n\\caption{Network Flow - ST-Cut Example}\n\\end{figure}\n\n\\subsubsection{Min-Cost Max-Flow}\n\nWith the Ford-Fulkerson, there can be multiple solutions. You can now add costs to the edges and use this to find the best solution with the Ford-Fulkerson algorithm respecting the costs.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/min-cost-max-flow.png}\n\\caption{Network Flow - Min-Cost Max-Flow}\n\\end{figure}\n\n\\clearpage", "meta": {"hexsha": "2cc16d5f2afcc24973e9237d57898974bd9b8bae", "size": 8730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FTP_Optimiz/06_GraphAndNetworkOptimization.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": "FTP_Optimiz/06_GraphAndNetworkOptimization.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": "FTP_Optimiz/06_GraphAndNetworkOptimization.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": 34.2352941176, "max_line_length": 282, "alphanum_fraction": 0.7396334479, "num_tokens": 2611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387956435734, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6925647119331169}}
{"text": "%----------------------------------------------------------------------\n% ml-tools documentation\n% Polynomial fit derivation\n% Author: Daniel Clark\n%\n% References:\n% Pattern Recognition and Machine Learning - Christopher Bishop\n%----------------------------------------------------------------------\n\n%----------------------------------------------------------------------\n% Document class, packages, and formatting\n%----------------------------------------------------------------------\n\\documentclass{article}\n\n%% Packages\n\\usepackage{fancyhdr}    % Required for custom headers\n\\usepackage{lastpage}    % Required to determine the last page for the footer\n\\usepackage{extramarks}  % Required for headers and footers\n\\usepackage{graphicx}    % Allow figures to be scaled and inserted\n\\usepackage{float}       % Allow figures to be inserted immediately\n%\\usepackage{indentfirst} % Allow indentation of all paragraphs, including first, by default\n\\usepackage{amsmath}     % Allow for extended math symbols library\n\\usepackage{amssymb}     % allow for special math binary operator characters\n\\usepackage{hyper ref}   % Hyperlinks\n\\usepackage[all]{hypcap} % Go to top of the image in link\n\\usepackage{amsfonts}    % Allow for extended fonts library\n\\usepackage{dsfont}      % Allow for digit formatting for pulse equation\n\\usepackage{upgreek}     % allow for variants on greek letters (e.g. tau)\n\\usepackage{bm}          % allow for bold math symbols via \\bm\n\\usepackage{url}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{listings}    % code format listing\n\\usepackage{xcolor}\n\n%% Margins\n\\topmargin=-0.45in\n\\evensidemargin=0in\n\\oddsidemargin=0in\n\\textwidth=6.5in\n\\textheight=9.0in\n\\headsep=0.1in\n\n%% Set up the header and footer\n\\pagestyle{fancy}\n\\rhead{Daniel Clark} % Top right header\n\\chead{} % Top center header\n\\lhead{}\n\\cfoot{} % Bottom center footer\n\\rfoot{Page\\ \\thepage\\ of \\pageref{LastPage}} % Bottom right footer\n\\renewcommand\\headrulewidth{0.4pt} % Size of the header rule\n\\renewcommand\\footrulewidth{0.4pt} % Size of the footer rule\n\n%% Other formatting\n\n%% Inputs\n\n%----------------------------------------------------------------------\n% Title Block\n%----------------------------------------------------------------------\n\n% Title\n\\title{Polynomial fit derivation notes\\\\\nUsed in \\emph{polyfit.py}}\n\n% Author name\n\\author{Daniel Clark}\n\n\n\\begin{document}\n\n% Make the title, author name, date\n\\maketitle\n\n%\\newpage\n%\\tableofcontents\n%\\newpage\n%-----\n\\section*{Polynomial curve-fitting}\n%-----\nGiven a real-valued input variable $x$, we wish to predict a real-valued target variable $t$.\n\\\\\\\\\nWe can fit a polynomial to an existing set of $N$ data points, with row vector inputs $\\bm{x} \\equiv (x_1, ..., x_n)$ and target variables $\\bm{t} \\equiv (t_1, ..., t_n) $. For a given input $x_n$\n% Polynomial fit y(x,w)\n\\begin{align}\n    t_n \\approx y(x_n, \\mathbf{w}) = \\sum_{j=0}^M w_j x_n^j,\n\\end{align}\nwhere $\\mathbf{w} \\equiv (w_0, ..., w_M)^\\top$ and $y(x_n, \\mathbf{w})$ predicts the target $t_n$ using an $M+1$-dimensional vector of weights, corresponding to each term of the $M$-order polynomial (plus the line offset $w_0$). *Note that $y(x_n, \\mathbf{w})$ is a nonlinear function of $x_n$, but a linear function of the coefficients $\\{w_j\\}$; these type of models are known as \\emph{linear models}.\n\\\\\\\\\nThese weights can be determined by minimizing an \\emph{error function}, which measures the misfit between the approximation $y(x_n, \\mathbf{w})$ and the training set for any given value of $\\mathbf{w}$. A widely used error function is the sum-of-squares, measuring the sum of the distance-squared between the predicted point $y(x_n, \\mathbf{w})$ and the actual target $t_n$, from $n=1, ..., N$.\n\n% Sum-of-squares error function E(w)\n\\begin{align}\n    E(\\mathbf{w}) = \\frac{1}{2}\\sum_{n=1}^N \\hspace{1pt}\\big[y(x_n, \\mathbf{w}) - t_n\\big]^2\n\\end{align}\n\nThe error function can be solved in closed form to find the optimal solution, $\\mathbf{w}^*$, where $E(\\mathbf{w}^*)$ is minimized.\n%-----\n\\subsubsection*{Derivation}\n%-----\nSetting $y_n \\equiv y(x_n, \\mathbf{w})$, we have\n\n% Derive w*\n\\begin{align*}\n    E(\\mathbf{w}) &= \\frac{1}{2}\\sum_{n=1}^N \\hspace{1pt} \\big[y(x_n, \\mathbf{w}) - t_n \\big]^2 \\\\\n                  &= \\frac{1}{2}\\sum_{n=1}^N \\hspace{1pt} \\big[y_n - t_n \\big]^2 \\\\\n                  &= \\frac{1}{2}\\sum_{n=1}^N \\hspace{1pt} \\big[y_n^2 - 2y_nt_n + t_n^2 \\big] \\\\\n                  &= \\frac{1}{2}\\sum_{n=1}^N y_n^2 - \\sum_{n=1}^Ny_nt_n + \\frac{1}{2}\\sum_{n=1}^Nt_n^2 \\\\\n                  &= \\frac{1}{2}\\sum_{n=1}^N y(x_n, \\mathbf{w})y(x_n, \\mathbf{w}) - \\sum_{n=1}^Ny(x_n, \\mathbf{w})t_n + \\frac{1}{2}\\sum_{n=1}^Nt_n^2\n\\end{align*}\n\nSince $E(\\mathbf{w})$ is a quadratic function of $\\mathbf{w}$, its global minimum is found by setting its derivative with respect to $\\mathbf{w}$ to 0. First, let`s take the partial derivative of $y(x_n, \\mathbf{w})$ with respect to any component of $\\mathbf{w}$, $w_i$\n\n% Deriv of y(x_n, w)\n\\begin{align*}\n    \\frac{\\partial}{\\partial w_i}y(x_n, \\mathbf{w}) &= \\frac{\\partial}{\\partial w_i} \\sum_{j=0}^Mw_jx^j \\\\\n                                                    &= \\frac{\\partial}{\\partial w_i} \\bigg(... + w_{i-1}x^{i-1} + w_ix^i + w_{i+1}x^{i+1} + ... \\bigg) \\\\\n                                                    &= ... + \\frac{\\partial}{\\partial w_i}w_{i-1}x^{i-1} + \\frac{\\partial}{\\partial w_i}w_ix^i + \\frac{\\partial}{\\partial w_i}w_{i+1}x^{i+1} + ... \\\\\n                                                    &= ... + 0 + x^i + 0 + ... \\\\\n    \\frac{\\partial}{\\partial w_i}y_n = \\frac{\\partial}{\\partial w_i}y(x_n, \\mathbf{w}) &= x^i\n\\end{align*}\n\nAnd we can take the derivative of $y(x_n, \\mathbf{w})y(x_n, \\mathbf{w})$ using the product rule, where\n\n% Deriv of y(x_n, w) y(x_n, w)\n\\begin{align*}\n    \\frac{\\partial}{\\partial w_i} \\big[y(x_n, \\mathbf{w}) y(x_n, \\mathbf{w}) \\big] &= \\frac{\\partial}{\\partial w_i}y(x_n, \\mathbf{w}) \\cdot y(x_n, \\mathbf{w}) + y(x_n, \\mathbf{w}) \\cdot \\frac{\\partial}{\\partial w_i}y(x_n, \\mathbf{w}) \\\\\n                                                                                   &= 2 \\frac{\\partial}{\\partial w_i} y(x_n, \\mathbf{w}) \\cdot y(x_n, \\mathbf{w}) \\\\\n                                                                                   &= 2 x^i y(x_n, \\mathbf{w})\n\\end{align*}\n\nFinally, taking $\\frac{\\partial}{\\partial w_i} E(\\mathbf{w})$ and setting it equal to 0 (where we are using the sum rule, $(f + g)' = f' + g'$, to take the derivatives on the inside of the summations),\n\n% Deriv of E(w)\n\\begin{align*}\n    \\frac{\\partial}{\\partial w_i}E(x_n, \\mathbf{w}^*) = 0 &= \\frac{1}{2}\\sum_{n=1}^N \\frac{\\partial}{\\partial w_i} \\big[y(x_n, \\mathbf{w}^*)y(x_n, \\mathbf{w}^*) \\big] - \\sum_{n=1}^N\\frac{\\partial}{\\partial w_i}y(x_n, \\mathbf{w}^*)t_n + \\frac{1}{2}\\sum_{n=1}^N\\frac{\\partial}{\\partial w_i}t_n^2 \\\\\n                                                  0       &= \\frac{1}{2}\\sum_{n=1}^N 2x_n^i y(x_n, \\mathbf{w}^*) - \\sum_{n=1}^Nx_n^it_n + 0 \\\\\n                                                          &= \\sum_{n=1}^N x_n^i y(x_n, \\mathbf{w}^*) - \\sum_{n=1}^Nx_n^it_n \\\\\n                                     \\sum_{n=1}^Nx_n^it_n &= \\sum_{n=1}^N x_n^i \\sum_{j=0}^Mw_j^*x_n^j \\\\\n                                     \\sum_{n=1}^Nx_n^it_n &= \\sum_{n=1}^N \\sum_{j=0}^Mw_j^*(x_n)^{i+j} \\\\\n                                     \\sum_{n=1}^Nx_n^it_n &= \\sum_{j=0}^Mw_j^*\\sum_{n=1}^N(x_n)^{i+j}\n\\end{align*}\n\nWe can re-arrange the above and represent the equations with vectors and matrices in the form of $\\mathbf{A}\\mathbf{w} = \\mathbf{b}$, where\n\n% Aw = b\n\\begin{align*}\n    \\sum_{j=0}^Mw_j^* \\underbrace{\\sum_{n=1}^N(x_n)^{i+j}}_{a_{ij}} &= \\underbrace{\\sum_{n=1}^Nx_n^it_n}_{b_i} \\\\\n    \\sum_{j=0}^Ma_{ij} w_j^* &= b_i \\\\\n    \\text{where $i$ are the vectors' index, from $0..M$}\\rightarrow \\mathbf{A} \\mathbf{w}^* &= \\mathbf{b} \\\\\n    \\rightarrow \\mathbf{w}^* &= \\mathbf{A}^{-1}\\mathbf{b}\n\\end{align*}\n\nTo solve this efficiently, we can use matrix algebra to create $\\mathbf{A}$ and $\\mathbf{b}$ using a $N\\times M+1$ matrix $\\mathbf{X}$, where\n\n% X => Aw = b\n\\begin{align*}\n    \\mathbf{X} =\n    \\begin{bmatrix}\n        x_1^0 & x_1^1 & ... & x_1^M \\\\\n        x_2^0 & x_2^1 & ... & x_2^M \\\\\n        \\vdots & \\vdots & ... & \\vdots \\\\\n        x_N^0 & x_N^1 & ... & x_N^M\n    \\end{bmatrix}, &~\\bm{t} =\n        \\begin{bmatrix}\n            t_1 & ... & t_N\n        \\end{bmatrix} \\\\\n        \\text{and}~\\mathbf{A} = \\mathbf{X}^\\top\\mathbf{X}, &~\\mathbf{b} = \\bm{t}\\mathbf{X}\n\\end{align*}.\n\n\nThere's also a problem when choosing the degree of the polynomial, $M$. A high $M$ can lead to over-fitting; we want to achieve a good \\emph{generalization}.\n\\\\\\\\\nOne way of testing the model is by comparison of $E(\\mathbf{w}^*)$ across model parameters (e.g. size of $M$). A good way to incorparte different-sized datasets is via root-mean-squared error (RMS). With $E(\\mathbf{w}^*) \\equiv \\frac{1}{2}\\sum_{n=1}^N [y(x_n, \\mathbf{w}^*) - t_n]^2$,\n\n% RMS\n\\begin{align}\n    E_{RMS} &= \\sqrt{2E(\\mathbf{w}^*)/N}\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "ea2b8f1eb9cd616f398b008f2b0b7d82fe1732fb", "size": 9063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/polyfit_deriv.tex", "max_stars_repo_name": "dclark87/pytools", "max_stars_repo_head_hexsha": "f395f3cdedc3e2f3debcaab510343f5a0b52d604", "max_stars_repo_licenses": ["MIT"], "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/polyfit_deriv.tex", "max_issues_repo_name": "dclark87/pytools", "max_issues_repo_head_hexsha": "f395f3cdedc3e2f3debcaab510343f5a0b52d604", "max_issues_repo_licenses": ["MIT"], "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/polyfit_deriv.tex", "max_forks_repo_name": "dclark87/pytools", "max_forks_repo_head_hexsha": "f395f3cdedc3e2f3debcaab510343f5a0b52d604", "max_forks_repo_licenses": ["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.7967032967, "max_line_length": 403, "alphanum_fraction": 0.5735407702, "num_tokens": 3050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387914176258, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.6925647067045942}}
{"text": "\\subsection{Defining Work on a Gas}\nAs you may remember from the previous unit, work is generally defined as\n\\begin{equation}\n    W = \\int_{x_1}^{x_2} Fdx\n\\end{equation}\nHowever, in thermodynamics we don't have position or force as variables to work with. Instead, we have pressure and volume. So, we need to find a way to define force and position in terms of pressure and volume. Starting with force, I can say that $F = PA$, so substituting that into the equation we get\n\\begin{equation*}\n    W = \\int_{x_1}^{x_2} PAdx\n\\end{equation*}\nThe product of area and distance is volume (Think of a cube. What's the area of on of the cube's faces times the length of its side?). So, since dx is a tiny displacement, which ultimately is a length, Adx is a tiny change in volume! Therefore:\n\\begin{equation*}\n    W = \\int_{V_1}^{V_2} PdV\n\\end{equation*}\nHowever, there's one more issue with this. The way I've defined work so far was based on the definition of the amount of work done \\textbf{by} a system on another system. We want the amount of work done \\textbf{on} the system. Due to conservation of energy, I can just throw a negative sign in front to get\n\\begin{equation}\n    W = -\\int_{V_1}^{V_2} PdV\n\\end{equation}\nThis is the proper definition of the work done on a gas. One thing to be careful of here; It looks like the pressure $P$ is just a constant I can take out of the integral. This is only the case if the pressure is \\textit{actually a constant over the entire process}. Otherwise, the pressure really is a function of volume, and so we keep it inside the integral; to be extra clear that the pressure is changing as a function of volume, we should write the equation as:\n\\begin{equation}\n    \\label{eqn:(16)}\n    W = -\\int_{V_1}^{V_2} P(V)dV\n\\end{equation}\nThe below diagram illustrates gas in a box with a piston, and shows the work done by the gas (because it's easier to draw):\n\\begin{center}\n    \\begin{tikzpicture}[scale=4]\n    \\filldraw[fill=pink, draw = black] (0,0) rectangle (1,1);\n    \\draw[black] (0,1) rectangle (1,1.2);\n    \\draw (0,1.2) -- (0,1.5);\n    \\draw (1,1.2) -- (1,1.5);\n    \\draw[->] (0.5,0.8) -- (0.5,1);\n    \\node[right] at (0.5,0.9) {Force $F$};\n    \\node[left] at (0,1) {$x_1$};\n    \\draw (0.5,0.5) node {Gas of volume $V_1$};\n    \\draw (0.5, 1.1) node {Piston of area $A$};\n    \\draw[->, blue, thick] (1.2,0.75) -- (1.8, 0.75);\n    \\node[above] at (1.5,0.75) {Gas does work $W$};\n    \\node[below] at (1.5,0.75) {$\\displaystyle W = \\int_{x_1}^{x_2} Fdx$};\n    \\node[below] at (1.5,0.4) {$\\displaystyle \\phantom{W }=  \\int_{V_1}^{V_2} PdV$};\n    \\filldraw[fill=pink, draw = black] (2,0) rectangle (3,1.1);\n    \\draw[black] (2,1.1) rectangle (3,1.3);\n    \\draw[dashed] (2,1) -- (3,1);\n    \\draw (2,1.2) -- (2,1.5);\n    \\draw (3,1.2) -- (3,1.5);\n    \\node[left] at (2,1.1) {$x_2$};\n    \\draw (2.5,0.5) node {Gas of volume $V_2$};\n    \\draw (2.5, 1.2) node {Piston of area $A$};\n    \\end{tikzpicture}\n\\end{center}\n", "meta": {"hexsha": "70bd8dcec89f50002c5d65e55f5269846e6f3ea7", "size": 2949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OneLaw/definingwork.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/definingwork.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/definingwork.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": 60.1836734694, "max_line_length": 467, "alphanum_fraction": 0.6605629027, "num_tokens": 1049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6925246070755784}}
{"text": "\\chapter{Bases}\n\nThe plural of \\enquote{basis} is \\enquote{bases}.\nDon't confuse it with the plural of \\enquote{base}.\n\n\\Table{\n    \\Columns{ll}\n    \\Caption{Basis-related notations}\n    \\Head{object & type}\n    \\Body{\n        vector & \\(V\\)\n        \\\\ tuple & \\( \\Real^n \\)\n        \\\\ parametric curve & \\(\\Real \\to V\\)\n        \\\\ basis & \\( \\Real^n \\to V \\)\n        \\\\ covector, scalar field & \\(V \\to \\Real\\)\n        \\\\ cobasis & \\( V \\to \\Real^n \\)\n        \\\\ vector change, vector field & \\(V \\to V\\)\n        \\\\ basis change & \\( \\Real^n \\to \\Real^n \\)\n    }\n}\n\nA basis invertibly maps a tuple to a vector.\n\nLet \\(V\\) be a vector space.\n\nA basis of \\(V\\) is an invertible function with type \\( \\Real^n \\to V \\).\n\nWith a basis, we can describe a vector by writing a tuple of numbers instead of drawing an arrow.\n\n\\section*{Example basis}\n\nLet \\(V\\) be the space of all two-dimensional Euclidean vectors.\n\nThus the basis we describe here will have the type \\( \\Real^2 \\to V \\).\n\nLet \\(i\\) be the unit vector pointing east (right).\n\nLet \\(j\\) be the unit vector pointing north (up).\n\nNote that \\(i\\) and \\(j\\) are orthogonal.\n\nThen we can choose a basis \\(e\\) such that \\(e(x,y) = xi+yj\\).\n\nIn this basis, the tuple \\((1,1)\\) describes the vector\nthat has length \\(\\sqrt{2}\\) and points northeast.\n\n\\section*{Example basis change}\n\nSuppose that we rotate the basis \\(e\\)\n(we rotate the coordinate axes) by 90 degrees counterclockwise.\nLet the new basis be \\(f\\).\nThen \\(f(x,y) = -yi + xj\\).\n\n\\section*{Don't confuse vectors and tuples}\n\nThe tuple is not the vector itself.\nThe tuple describes the vector.\nThe tuple and the vector are two different things.\nThey are related by the basis.\n\nBut we can indeed form an abstract-algebraic vector space \\(\\Real^n\\) over the abstract-algebraic field \\(\\Real\\),\nso a real tuple is a vector.\n\n\\section{Linear basis}\n\nA basis \\(e : \\Real^n \\to V\\) is linear iff \\(e(a+b) = e(a) + e(b)\\).\nNote that we overload the plus sign.\nThe left plus sign is tuple addition.\nThe right plus sign is vector addition.\n\nWe can explode a linear basis \\(e : \\Real^n \\to V\\) to \\(n\\) vectors \\(e_1,\\ldots,e_n\\),\neach of the type \\(V\\), in this way:\n\\begin{align*}\n    e(x_1,\\ldots,x_n) &= e_1 x_1 + \\ldots + e_n x_n\n    \\\\ &= \\Matrix{e_1 & \\ldots & e_n}\\Matrix{x_1 \\\\ \\vdots \\\\ x_n}\n    \\\\ &= EX\n\\end{align*}\nand thus the linear basis \\(e\\) can be represented by the matrix \\(E\\) where\n\\[\n    E = \\Matrix{e_1 & \\ldots & e_n}\n\\]\n\n\\section{Describing every vector as a linear combination of basis vectors}\n\nWe are talking about the two-dimensional Euclidean space here.\nWe can imagine it as an unbounded flat sheet of paper.\n\nLet \\(V^2\\) be the set of all two-dimensional Euclidean vectors.\n\nFrom \\(V^2\\), pick any two non-collinear vectors \\(e_1\\) and \\(e_2\\).\n\nLet \\(x_1,x_2\\in\\Real\\).\n\nThe linear combination \\(x_1 e_1 + x_2 e_2\\) describes a vector in \\(V^2\\).\n\nIf we pick a basis,\nwe can represent every vector in \\(V^2\\) using two real numbers.\nWe can describe the entire \\(V^2\\) using \\(\\Real^2\\)\nas \\( V^2 = \\{ x_1 e_1 + x_2 e_2 ~|~ (x_1,x_2) \\in \\Real^2 \\} \\).\n\nWe say that \\(E = \\{e_1,e_2\\}\\) is a basis of the two-dimensional Euclidean space.\n\nWe say that \\((x_1,x_2)\\) is the coordinate tuple of vector \\(v\\) according to basis \\(E\\).\nWe can also say that \\((x_1,x_2)\\) is the \\(E\\)-coordinates of \\(v\\).\n\nA basis of \\(V^n\\) is a set of \\(n\\) basis vectors\nin which every pair of basis vectors are non-collinear.\nWith such basis, we can describe every vector in \\(V^n\\)\nas a linear combination of those basis vectors.\n\n\\section{Representing a coordinate tuple by a column matrix}\n\nWe can write \\((x,y,z)\\) or we can write\n\\[\n    \\Matrix{x \\\\ y \\\\ z}\n\\]\n\n\\section{Scaling a vector}\n\nIf \\(k\\) is a number and \\(v\\) is a vector,\nthen \\(kv\\) is a vector that has the same direction as \\(v\\),\nbut the length of \\(kv\\) is \\(k\\) times the length of \\(v\\),\nthat is, \\( \\norm{k v} = k \\norm{v} \\).\n\nWe can think of \\(-v\\) (the negation of \\(v\\)) as scaling \\(v\\) by \\(-1\\).\n\nIf \\(v = \\sum_k x_k e_k\\) then \\(cv = \\sum_k (c x_k) e_k \\).\n\n\\section{The relationship between vectors and coordinates}\n\nWe have two choices\n\n\\(V \\to \\Real^n\\)\n\n\\(\\Real^n \\to V\\)\n\n\\section{Exploding a cobasis to covectors}\n\nWe can explode a cobasis \\( e : V \\to \\Real^n \\) to \\(n\\) covectors \\( e_1, \\ldots, e_n \\),\neach having type \\( V \\to \\Real \\), in this way:\n\\[\n    e(v) = (e_1(v), \\ldots, e_n(v))\n\\]\n\n\\section{Why are the basis and cobasis not the other way around?}\n\n\\enquote{A choice of an ordered basis for \\(V\\) is equivalent to a choice of a linear isomorphism \\(\\varphi\\)\nfrom the coordinate space \\(F^n\\) to \\(V\\).}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Basis_(linear_algebra)\\#Ordered_bases_and_coordinates}}\n\n\\section{Radial basis? Polar coordinates?}\n\nLet \\(e\\) be the radial basis. Then \\(e(v+w) \\neq e(v) + e(w)\\) in general.\n\n\\section{The cross product? The Levi-Civita symbol?}\n\nThe vector \\( a \\times b \\) is the vector that is orthogonal to \\(a\\), orthogonal to \\(b\\).\nFollow the right hand rule.\nIf \\(a\\) is represented by the thumb pointing right,\nand \\(b\\) is represented by the index finger pointing forward,\nthen \\(a \\times b\\) is represented by the middle finger pointing up.\n\n\\( a \\times b = \\sum_i\\sum_j\\sum_k \\epsilon_{ijk} e_i a^j b^k \\) ?\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Levi-Civita_symbol\\#Cross_product_(two_vectors)}}\n\n\\section{The Pythagorean theorem}\n\nLet there be a right triangle.\nLet \\(c\\) be its hypothenuse.\nLet \\(a\\) and \\(b\\) be the other two sides.\nThen, \\( a^2 + b^2 = c^2 \\).\n\nMany proofs of this theorem are on the Internet.\n\n\\section{Closing}\n\nWith a basis, we can define vectors with numbers without drawing.\nAfter we have a basis, we can use the calculus of infinitesimals on vectors.\n", "meta": {"hexsha": "8b341f7849dc331d3af4bbe42ebb59004c5d4494", "size": 5759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/basis.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/basis.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/basis.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 31.9944444444, "max_line_length": 114, "alphanum_fraction": 0.659663136, "num_tokens": 1740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6925245863224059}}
{"text": "\\chapter{The Stiff String}\\label{ch:stiffString}\nIn earlier chapters, the case of the ideal string was presented, modelled using the 1D wave equation. This system, if the CFL condition is satisfied with equality, generates an output with harmonic partials that are integer multiples of the fundamental frequency. In the real world, however, strings exhibit a phenomenon called \\textit{frequency dispersion} due to stiffness in the material, hence the name \\textit{stiff string}. This phenomenon causes another effect known as \\textit{inharmonicity}: the ``harmonic'' partials get exponentially further apart the higher their frequency is. The stiffness in a string is dependent on its material properties and geometry and will be elaborated on in this chapter. The stiff string played a prominent part in the following papers: \\citeP[A], \\citeP[B], \\citeP[C], \\citeP[D] and \\citeP[E].\n\nThis chapter presents the PDE of the stiff string in continuous time, and goes through the discretisation process. The analysis techniques presented in Chapter \\ref{ch:analysis} will then be applied to the resulting (explicit) FD scheme and derived in detail. Finally, an example of an implicit scheme will be given and comparison to the earlier FD scheme will be made. Unless denoted otherwise, this chapter follows \\cite{theBible}.\n\n\\section{Continuous time}\nConsider a lossless stiff string of length $L$ and with a circular cross-section. Its transverse displacement is described by $u=u(x,t)$ (in m) defined for $x\\in \\D$ with domain $\\D = [0, L]$ and time $t\\geq 0$. The PDE describing its motion is \n\\begin{equation}\\label{eq:stiffStringPDENoLosses}\n    \\rho A \\ptt u = T \\pxx u - EI \\pxxxx u\n\\end{equation}\nparametrised by material density $\\rho$ (in kg/m$^3$), cross-sectional area $A = \\pi r^2$ (in m$^2$), radius $r$ (in m), tension $T$ (in N), Young's modulus $E$ (in Pa) and area moment of inertia $I = \\pi r^4/4$ (in m$^4$). If $E = 0$, Eq \\eqref{eq:stiffStringPDENoLosses} reduces to the 1D wave equation in Eq. \\eqref{eq:1DwavePDE} where $c = \\sqrt{T/\\rho A}$, i.e., the ideal string. If instead $T = 0$, Eq. \\eqref{eq:stiffStringPDENoLosses} reduces to the \\textit{ideal bar} equation. A more compact way to write Eq. \\eqref{eq:stiffStringPDENoLosses} is \n\\begin{equation}\n    \\ptt u = c^2 \\pxx u - \\kappa^2 \\pxxxx u\n\\end{equation}\nwith wave speed $c = \\sqrt{T/\\rho A}$ (in m/s) and stiffness coefficient $\\kappa = \\sqrt{EI / \\rho A}$. \n\nThe difference between the ideal string and the stiff string is the term containing a 4\\thOrder spatial derivative. This term adds \\textit{stiffness} to the system and causes frequency dispersion. As opposed to unwanted numerical dispersion due to numerical error (see Section \\ref{sec:quality1DWave}) this type of dispersion is physical and thus something desired in the model. This phenomenon causes higher frequencies to travel faster through a medium than lower frequencies. See Figure \\ref{fig:dispersion}. Furthermore, frequency dispersion is closely tied to \\textit{inharmonicity}, an effect where `harmonic' partials get exponentially further apart as frequency increases. For low values of $\\kappa$, the frequency of these partials can be expressed in terms of the fundamental frequency $f_0 = c/2L$ (as in Eq. \\eqref{eq:fundamentalFreq}) and frequency of partial $p$ (in Hz) is defined as \\cite{theBible}\n\\begin{equation}\\label{eq:inharmonicityEquation}\n    f_p = f_0 p \\sqrt{1 + B p^2},\n\\end{equation}\nwith inharmonicity coefficient \n\\begin{equation*}\n    B = \\frac{\\kappa^2 \\pi^2}{c^2}.\n\\end{equation*}\nFrequency dispersion and inharmonicity will be further discussed in Section \\ref{sec:paramsAndOutput}.\n\n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$t = 0$ ms.\\label{fig:dispersion1}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/dispersion1.eps}}\\hfill\n    \\subfloat[$t = 1$ ms.\\label{fig:dispersion2}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/dispersion2.eps}}\\hfill\n    \\subfloat[$t = 2$ ms.\\label{fig:dispersion3}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/dispersion3.eps}}\n    \\caption{Frequency dispersion in a stiff string due to stiffness.\\label{fig:dispersion}}\n\\end{figure}\n\n\\subsubsection{Dispersion Analysis}\nThe 4th-order spatial derivative models \\textit{frequency dispersion}, a phenomenon that causes different frequencies to travel at different speeds. As opposed to the undesired numerical dispersion \n\n\\subsection{Adding losses}\nBefore moving on to the discretisation of the PDE in Eq. \\eqref{eq:stiffStringPDENoLosses}, losses can be added to the system. In the physical world, strings lose energy through fx. air viscosity and thermoelastic effects. All frequencies lose energy and die out (damp) over time, but higher frequencies do so at a much faster rate. This phenomenon is called \\textit{frequency-dependent damping} and can be modelled using a mixed derivative $\\pt \\pxx$. This way of frequency-dependent damping first appeared in \\cite{Bensa2003} and has been used extensively in the literature since \\cite{Valimaki2006,theBible}. A damped stiff string can be modelled as\n\\begin{equation}\\label{eq:stiffStringPDE}\n    \\rho A \\ptt u = T \\pxx u - EI \\pxxxx u - 2 \\sz \\rho A \\pt u + 2 \\so \\rho A\\pt \\pxx u\n\\end{equation}\nwhere the non-negative loss coefficients $\\sz$ (in s$^{-1}$) and $\\so$ (in m$^2$/s) determine the frequency-independent and frequency-dependent losses respectively. Appendix \\ref{app:intuitionSigma1} attempts to provide some intuition on workings of these damping terms.\n\nA more compact way to write Eq. \\eqref{eq:stiffStringPDE}, and is also found often in the literature \\cite{theBible}\\todo{etc.}, is to divide all terms by $\\rho A$ to get\n\\begin{equation}\\label{eq:stiffStringPDECompact}\n    \\ptt u = c^2 \\pxx u - \\kappa^2 \\pxxxx u - 2 \\sz \\pt u + 2 \\so \\pt \\pxx u,\n\\end{equation}\nwhere $c=\\sqrt{T/\\rho A}$ is the wave speed \\todo{FULL DOC SWEEP: check wavespeed or wave speed (entire document)} (in m/s) as in the 1D wave equation in \\eqref{eq:1DwavePDE} and $\\kappa = \\sqrt{EI / \\rho A}$ is referred to as the stiffness coefficient (in m$^2$/s). \n\n\\subsubsection{Intuition}\nAlthough Eq. \\eqref{eq:stiffStringPDE} might look daunting at first, the principle of Newton's second law remains the same. \n\nSomething about the 4th spatial derivative and the loss terms here...\n\n\\subsubsection{Boundary conditions}\nSection \\ref{sec:1DWave} presents two types of boundary conditions for the 1D wave equation in Eq. \\eqref{eq:boundaryCond1DWave}. In the case of the stiff string, these can be extended to\n\\begin{subequations}\\label{eq:stiffStringBoundConds}\n    \\begin{align}\n        u = \\px u &= 0 \\quad \\text{(clamped)}\\label{eq:BCclamped}\\\\\n        u = \\pxx u &= 0 \\quad \\text{(simply supported)}\\label{eq:BCsimplySupported}\\\\\n        \\pxx u = \\pxxx u &= 0 \\quad \\text{(free)}\\label{eq:BCfree}\n    \\end{align}\n\\end{subequations}\nat $x = 0, L$. See Figure \\ref{fig:boundaryCondsStiffString} for plots of the first modal shape for each respective boundary condition. \n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[Clamped.\\label{fig:clamped}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/clamped.eps}}\\hfill\n    \\subfloat[Simply supported.\\label{fig:simplySupported}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/simplySupported.eps}}\\hfill\n    \\subfloat[Free.\\label{fig:free}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/free.eps}}\n    \\caption{Plots of the first (normalised) modal shape for the three boundary conditions in Eqs. \\eqref{eq:stiffStringBoundConds}. The extremes are indicated with solid black and dashed grey lines respectively. \\label{fig:boundaryCondsStiffString}}\n\\end{figure}\n\n\\section{Discrete time}\\label{sec:stiffStringDiscrete}\nFor the sake of compactness, Eq. \\eqref{eq:stiffStringPDECompact} will be used in the following, rather than Eq. \\eqref{eq:stiffStringPDE}. Naturally, the same process can be followed for the latter, the only difference being a multiplication by $\\rho A$ of all terms.\n\nFollowing Section \\ref{sec:gridFunctions} and using the FD operators presented in Section \\ref{sec:FDoperators}, Eq. \\eqref{eq:stiffStringPDECompact} can be discretised as \n\\begin{equation}\\label{eq:stiffStringFDS}\n    \\dtt \\uln = c^2 \\dxx \\uln - \\kappa^2 \\dxxxx \\uln - 2 \\sz \\dtd \\uln + 2 \\so\\dtm\\dxx \\uln,\n\\end{equation}\nfor domain $l\\in\\{0, \\hdots, N\\}$ and number of grid points $N+1$. \n\nThe $\\dxxxx$ operator is the second-order spatial difference in Eq. \\eqref{eq:discSecondSpace} applied to itself\n\\begin{equation}\\label{eq:dxxxx}\n    \\dxxxx = \\dxx\\dxx = \\frac{1}{h^4}\\left(e_{x+}^2 - 4e_{x+}+6 - 4e_{x-}+e_{x-}^2\\right).\n\\end{equation} \nA multiplication of two shift operators applied to a grid function simply means to apply each shift individually. The $\\dxxxx$ operator applied to $\\uln$ thus becomes\n\\begin{equation}\n    \\dxxxx\\uln = \\frac{1}{h^4}\\left(u_{l+2}^n - 4u_{l+1}^n+6\\uln - 4u_{l-1}^n+u_{l-2}^n\\right).\n\\end{equation}\n\nA definition for the mixed-derivative operator can similarly be found.\nRecalling the definitions for $\\dtm$ in Eq. \\eqref{eq:backwardTimeOperator} and $\\dxx$ Eq. \\eqref{eq:discSecondSpace}, their combination results in\n\\begin{align}\n    \\dtm\\dxx &= \\frac{1}{k}\\left(1-e_{t-}\\right)\\frac{1}{h^2}\\left(e_{x+}-2+e_{x-}\\right),\\nonumber \\\\\n    &= \\frac{1}{kh^2}\\left(e_{x+}-2+e_{x-} - e_{t-}(e_{x+}-2+e_{x-})\\right).\n\\end{align}\nTo have two different shift operators multiplied together still simply means to apply each of them to the grid function individually. The $\\dtm\\dxx$ operator applied to $\\uln$ thus yields\n\\begin{equation}\n    \\dtm \\dxx \\uln = \\frac{1}{hk^2}\\left(u_{l+1}^n - 2 \\uln + u_{l-1}^n - u_{l+1}^{n-1} + 2 u_l^{n-1} - u_{l-1}^{n-1}\\right).\n\\end{equation}\nThe reason a backwards difference is used here is to keep the system \\textit{explicit}. A scheme is explicit if the values of $u_l^{n+1}$ can be calculated from known values at times $n$ and $n-1$. If this is not the case and values of fx. $u_{l+1}^{n+1}$ and $u_{l-1}^{n+1}$ are required to calculate $u_l^{n+1}$, the scheme is called \\textit{implicit}. An example of an implicit scheme using the centred operator for the temporal derivative in the frequency-dependent damping term instead can be found in Section \\ref{sec:implicitStiffString}.\n\nUsing the definitions above, \nthe operators in scheme \\eqref{eq:stiffStringFDS} can be expanded to get\n\\begin{equation}\n    \\begin{aligned}\\label{eq:expandedStringFDS}\n        \\frac{1}{k^2}\\big(u_l^{n+1} - 2\\uln & + u_l^{n-1} \\big) =\\frac{c^2}{h^2}\\left(u_{l+1}^n - 2\\uln + u_{l-1}^n\\right) \\\\\n        &- \\frac{\\kappa^2}{h^4}\\left(u_{l+2}^n - 4u_{l+1}^n+6\\uln - 4u_{l-1}^n+u_{l-2}^n\\right) \\\\ \n        &- \\frac{\\sz}{k} \\left(u_l^{n+1} - u_l^{n-1}\\right)\\\\\n        & + \\frac{2\\so}{kh^2}\\left(u_{l+1}^n - 2\\uln + u_{l-1}^n - u_{l+1}^{n-1} + 2u_l^{n-1} + u_{l-1}^{n-1}\\right),\n    \\end{aligned}\n\\end{equation}\nand after multiplication by $k^2$ and collecting the terms yields\n\\begin{equation}\\label{eq:stiffStringUpdate}\n    \\begin{aligned}\n        (1+\\sz k) u_l^{n+1} =&\\ \\left(2 - 2\\lambda^2 - 6\\mu^2 - \\frac{4\\so k}{h^2}\\right) \\uln\\\\\n        & + \\left(\\lambda^2 + 4\\mu^2 + \\frac{2\\so k}{h^2}\\right) (u_{l+1}^n + u_{l-1}^n) \\\\\n        &- \\mu^2 (u_{l+2}^n + u_{l-2}^n) + \\left(-1+\\sz k + \\frac{4\\so k}{h^2}\\right)u_l^{n-1}\\\\\n        & - \\frac{2\\so k}{h^2}(u_{l+1}^{n-1} + u_{l-1}^{n-1}),\n    \\end{aligned}\n\\end{equation}\nwith \n\\begin{equation}\\label{eq:stiffStringCourant}\n    \\lambda = \\frac{ck}{h} \\qaq \\mu = \\frac{\\kappa k}{h^2}.\n\\end{equation}\nThe update equation follows by dividing both sides by $(1+\\sz k)$. \n\nThe stability condition for the FD scheme in \\eqref{eq:stiffStringFDS} is defined as \n\\begin{equation}\\label{eq:stiffStringStability}\n    h \\geq \\sqrt{\\frac{c^2k^2+4\\so k + \\sqrt{(c^2k^2 + 4\\so k)^2+16\\kappa^2k^2}}{2}},\n\\end{equation}\nand will be derived in Section \\ref{sec:stiffStringStability} using von Neumann analysis. \nThis condition can then be used to calculate the number of intervals $N$ in a similar fashion as for the 1D wave equation shown in Eq. \\eqref{eq:orderOfCalc}. First, Eq. \\eqref{eq:stiffStringStability} should be satisfied with equality, after which\n\\begin{equation*}\n    N := \\floor[\\frac{L}{h}], \\qaq h := \\frac{L}{N}\n\\end{equation*}\nwhich can then be used to calculate $\\lambda$ and $\\mu$ in \\eqref{eq:stiffStringCourant}.\n\n\\subsubsection{Stencil}\nAs done in Section \\ref{sec:1DWaveDisc}, a stencil for the FD scheme in Eq. \n\\eqref{eq:stiffStringFDS} can be created. This is shown in Figure \\ref{fig:stencilStiffString}. In order to calculate $u_l^{n+1}$, $5$ points at the current time step are needed due to the 4\\thOrder spatial derivative. Due to the mixed derivative in the frequency-dependent damping term, neighbouring points at the previous time step are also required. \n%, the coefficient multiplied onto $u_l^{n+1}$.\n\n% and the terms collected to obtain the following update equation\n% \\begin{equation}\n%     \\begin{aligned}\n%     % (1+\\sz k) u_l^{n+1} =&\\ \\left(2 - 2\\lambda^2 - 6\\mu^2 - \\frac{4\\so k}{h^2}\\right) \\uln\\\\\n%     % & + \\left(\\lambda^2 + 4\\mu^2 + \\frac{2\\so k}{h^2}\\right) (u_{l+1}^n + u_{l-1}^n) \\\\\n%     % &- \\mu^2 (u_{l+2}^n + u_{l-2}^n) + \\left(-1+\\sz k + \\frac{4\\sz k}{h^2}\\right)u_l^{n-1}\\\\\n%     % & - \\frac{2\\so k}{h^2}(u_{l+1}^{n-1} + u_{l-1}^{n-1})\n%     % \\end{aligned}\n%     Au_l^{n+1} = &\\ B_0 \\uln + B_1 (u_{l+1}^n + u_{l-1}^n) + B_2 (u_{l+2}^n + u_{l-2}^n) \\\\\n%     &+ C_0 u_l^{n-1} + C_1(u_{l+1}^{n-1} + u_{l-1}^{n-1}) \n%     \\end{aligned}\n% \\end{equation}\n% with coefficients\n% \\begin{gather*}\n%     B_0 = 2 - 2\\lambda^2 - 6\\mu^2 - \\frac{4\\so k}{h^2}, \\quad B_1 = \\lambda^2 + 4\\mu^2 + \\frac{2\\so k}{h^2}, \\quad B_2 =- \\mu^2, \\\\[1em]\n%     C_0 =  -1+\\sz k + \\frac{4\\so k}{h^2},\\quad C_1 = - \\frac{2\\so k}{h^2}, \\qaq A = 1+\\sz k.\n% \\end{gather*}\n% Note that for clarity the division by $A$ has been left for implementation. \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{figures/resonators/stencilDampedStiffString.eps}\n    \\caption{The stencil for the damped stiff string scheme in Eq. \\eqref{eq:stiffStringFDS} (adapted from \\citeP[A]).\\label{fig:stencilStiffString}}\n\\end{figure}\n\n\\subsection{Boundary conditions}\\label{sec:stiffStringBoundaryConditions}\nDue to the 4\\thOrder spatial derivative, two virtual grid points need to be accounted for at the boundaries of the system. Discretising the boundary conditions in \\eqref{eq:stiffStringBoundConds} yields\n\\begin{subequations}\\label{eq:stiffStringBoundCondsDisc}\n    \\begin{align}\n        \\uln = \\delta_{x\\pm} \\uln &= 0 \\quad \\text{(clamped)}\\label{eq:BCclampedDisc}\\\\\n        \\uln = \\dxx \\uln &= 0 \\quad \\text{(simply supported)}\\label{eq:BCsimplySupportedDisc}\\\\\n        \\dxx \\uln = \\dxd\\dxx \\uln &= 0 \\quad \\text{(free)}\\label{eq:BCfreeDisc}\n    \\end{align}\n\\end{subequations}\nat $l = 0, N$. The operator in the clamped condition uses the $\\dxp$ operator at the left boundary ($l = 0$) and $\\dxm$ at the right ($l = N$). Note that to discretise $\\px^3$ in the free boundary condition in Eq. \\eqref{eq:BCfree}, the more accurate $\\dxd\\dxx$ operator has been chosen over the less accurate $\\dxm \\dxx$ and $\\dxp \\dxx$ operators for the left and right boundary respectively.\n\nBelow, the boundary conditions are expanded to get definitions for the virtual grid points. \n\n\\todo{insert figure showing virtual grid points somewhere in this section}\n\n\\subsubsection{Clamped}\nExpanding the operators for the clamped condition yields \n\\begin{equation}\n    u_0^n = u_1^n = 0 \\qaq u_{N-1}^n = u_N^n = 0.\n\\end{equation}\nThis can be simplified by reducing the range of calculation to $l\\in \\{ 2, \\hdots, N-2\\}$.\n\n\\subsubsection{Simply supported}\nAs the states of the end points of a system with simply supported boundary conditions are $0$ at all times, the range of calculation can be reduced to $l\\in \\{ 1, \\hdots, N-1\\}$. Evaluating the update equation in Eq. \\eqref{eq:stiffStringUpdate} at $l=1$ and $l=N-1$ shows that definitions for the virtual grid points $u_{-1}^n$ and $u_{N+1}^n$ are required. A definition for $u_{-1}^n$ can be found by expanding Eq. \\eqref{eq:BCsimplySupportedDisc} at $l = 0$:\n\\begin{align}\n    &\\frac{1}{h^2}\\left(u_1^n - 2 u_0^n + u_{-1}^n\\right) = 0,\\nonumber\\\\[-1em]\n    \\xLeftrightarrow{\\mystrut\\ u^n_0 = 0\\ } \\quad & u_1^n + u_{-1}^n = 0,\\nonumber\\\\[0.25em]\n    &u_{-1}^n = -u_1^n,\\label{eq:simplySupportedResult}\n\\end{align}\nand similarly for $u_{N+1}^n$ by expanding the condition at $l=N$:\n\\begin{equation*}\n    u_{N+1}^n = -u_{N-1}^n.\n\\end{equation*}\nSubstituting the first definition into the expanded scheme in Eq. \\eqref{eq:expandedStringFDS} at $l=1$ and collecting the terms thereafter yields\n\\begin{equation}\n    \\begin{aligned}\n        \\!\\!\\!\\!\\!(1+\\sz k) u_1^{n+1} =&\\ \\left(2 - 2\\lambda^2 - 5\\mu^2 - \\frac{4\\so k}{h^2}\\right) u_1^n + \\left(\\lambda^2 + 4\\mu^2 + \\frac{2\\so k}{h^2}\\right) u_{2}^n \\\\\n        &+ \\left(-1+\\sz k + \\frac{4\\sz k}{h^2}\\right)u_1^{n-1} - \\frac{2\\so k}{h^2}u_{2}^{n-1}.\n    \\end{aligned}\n\\end{equation}\nDoing the same for $l=N-1$ yields\n\\begin{equation}\n    \\begin{aligned}\n        \\!\\!(1+\\sz k) u_{N-1}^{n+1} =&\\ \\left(2 - 2\\lambda^2 - 5\\mu^2 - \\frac{4\\so k}{h^2}\\right) u_{N-1}^n + \\left(\\lambda^2 + 4\\mu^2 + \\frac{2\\so k}{h^2}\\right) u_{N-2}^n \\\\\n        &-\\mu^2u_{N-3}^n+ \\left(-1+\\sz k + \\frac{4\\sz k}{h^2}\\right)u_{N-1}^{n-1} - \\frac{2\\so k}{h^2}u_{N-2}^{n-1}.\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Free}\nFinally, the free boundary condition requires all points to be calculated and the range of calculation remains $l\\in\\{0, \\hdots, N\\}$. At each respective boundary, two virtual grid points are needed: $u_{-1}^n$ and $u_{-2}^n$ at the left and $u_{N+1}^n$ and $u_{N+2}^n$ at the right boundary respectively.\nThe third-order spatial FD operator in Eq. \\eqref{eq:BCfreeDisc} is defined as:\n\\begin{align}\n    \\dxd\\dxx &= \\frac{1}{2h^3}\\left(e_{x+}-e_{x-}\\right)\\left(e_{x+}-2+e_{x-}\\right),\\nonumber\\\\\n    &=\\frac{1}{2h^3}\\left(e_{x+}^2 - 2e_{x+} + 1 - (1 - 2e_{x-} + e_{x-}^2\\right),\\nonumber\\\\\n    &=\\frac{1}{2h^3}\\left(e_{x+}^2 - 2e_{x+} + 2e_{x-} -e_{x-}^2\\right).\n\\end{align}\nand can be used to solve for $u_{-2}^n$ at $l=0$:\n\\begin{align*}\n    \\frac{1}{2h^3} &\\left(u_2^n - 2 u_1^n + 2u_{-1}^n - u_{-2}^n\\right) = 0,\\\\%[0.25em]\n    u_{-2}^n &= u_2^n - 2 u_1^n + 2u_{-1}^n.\n    % \\\\[-1em]\n    % \\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\xLeftrightarrow{\\mystrut\\ \\dxx \\uln = 0\\ \\Rightarrow\\ \\text{ Eq. \\eqref{eq:simplySupportedResult}}\\ }\n    % \\quad u_{-2}^n &= u_2^n - 4 u_1^n \n\\end{align*}\nAs $u_0^n$ is not necessarily $0$ at all times, solving the first part of the boundary condition (i.e., $\\dxx u_0^n = 0$) yields a different result than in the simply supported case:\n\\begin{align*}\n    \\frac{1}{2h^3} &\\left(u_2^n - 2 u_1^n + u_{-1}^n - u_{-2}^n\\right) = 0\\\\[0.25em]\n    u_{-2}^n &= u_2^n - 2 u_1^n + u_{-1}^n\\\\[-1em]\n    \\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\xLeftrightarrow{\\mystrut\\ \\dxx \\uln = 0\\ \\Rightarrow\\ \\text{ Eq. \\eqref{eq:simplySupportedResult}}\\ }\n    \\quad u_{-2}^n &= u_2^n - 3 u_1^n \n\\end{align*}\nThe same can be done at $l=N$ to get the following definitions for the virtual grid points\n\\begin{equation*}\n    u_{N+2}^n = u_{N-2}^n - 2 u_{N-1}^n + 2u_{N+1}^n\n    \\qaq u_{N+1}^n = 2u_N^n - u_{N-1}^n.\n\\end{equation*}\nThe update equations for the boundary points will not be given here. Instead the matrix form of the FD scheme with free boundaries will be provided below. \n% The update equation at $l=0$ then becomes\n% \\begin{equation}\n%     \\begin{aligned}\n%         \\!\\!\\!\\!\\!(1+\\sz k) u_0^{n+1} =&\\ \\left(2 - 2\\lambda^2 - 2 \\mu^2 - \\frac{4\\so k}{h^2}\\right) u_0^n + \\left(\\lambda^2 +4\\mu^2 + \\frac{4\\so k}{h^2}\\right) u_1^n \\\\\n%         &-2\\mu^2u_2^n+ \\left(-1+\\sz k + \\frac{4\\sz k}{h^2}\\right)u_0^{n-1} - \\frac{4\\so k}{h^2}u_1^{n-1}.\n%     \\end{aligned}\n% \\end{equation}\n% at $l=1$\n% \\begin{equation}\n%     \\begin{aligned}\n%         \\!\\!\\!\\!\\!(1+\\sz k) u_1^{n+1} =&\\ \\left(2 - 2\\lambda^2 - 5\\mu^2 - \\frac{4\\so k}{h^2}\\right) u_1^n + \\left(\\lambda^2 + 4\\mu^2 + \\frac{2\\so k}{h^2}\\right) u_{2}^n \\\\\n%         &-2\\mu^2u_3^n+ \\left(-1+\\sz k + \\frac{4\\sz k}{h^2}\\right)u_1^{n-1} - \\frac{2\\so k}{h^2}u_{2}^{n-1}.\n%     \\end{aligned}\n% \\end{equation}\n\\\\\n\nIn practice, the simply supported boundary condition is mostly chosen as this most realistically reflects string terminations in the real world. The clamped condition could be chosen for simplicity as this does not require an alternative update at the boundaries. The free boundary condition is more often used to model a (damped) ideal bar, (Eq. \\eqref{eq:stiffStringPDE} with $T = 0$).\n\n\\subsection{Implementation and matrix form}\\label{sec:implementationStiffString}\nWhen using \\texttt{MATLAB}, for a more compact implementation, it is useful to write the scheme in matrix form (see Section \\ref{sec:matrixForm}). The FD scheme of the stiff string in \\eqref{eq:stiffStringFDS} can be written as \n\\begin{equation}\\label{eq:matrixFormStiffString}\n    A\\u^{n+1} = \\B\\u^n + \\C \\u^{n-1}\n\\end{equation}\nwhere \n\\begin{equation}\n    \\begin{gathered}\n    A = (1+\\sz k), \\quad \\B = 2\\I + c^2 k^2 \\Dxx - \\kappa^2 k^2 \\Dxxxx + 2 \\so k \\Dxx, \\\\\n    \\text{and} \\quad \\C = -(1-\\sz k)\\I - 2\\so k \\Dxx.\n    \\end{gathered}\n\\end{equation}\nNotice that $A$ is a scalar rather than a matrix.\n\nThe size of the state vectors and the matrix-form operators depend on the boundary conditions. For clamped conditions, the state vectors ($\\u^{n+1}$, $\\u^n$ and $\\u^{n-1}$) and matrices will be of size $(N-3) \\times 1$ and $(N-3) \\times (N-3)$ respectively. The $\\Dxx$ matrix will be of the form given in Eq. \\eqref{eq:DxxDef} and the matrix form of the $\\dxxxx$ operator is\n\\begin{equation}\n    \\mathbf{D}_{xxxx} = \\frac{1}{h^4}\\begin{bmatrix}\n        6& -4 & 1 & & \\mathbf{0} \\\\\n        -4 & 6 &\\ddots &\\ddots & \\\\\n        1& \\ddots & \\ddots & \\ddots&1 \\\\\n        &\\ddots & \\ddots & 6 & -4 \\\\\n        \\mathbf{0} & & 1& -4 & 6 \\\\\n    \\end{bmatrix}.\n\\end{equation}\n\nFor simply supported conditions, the state vectors and matrices will be of size $(N-1) \\times 1$ and $(N-1) \\times (N-1)$ respectively. Again, $\\Dxx$ is as defined in Eq. \\eqref{eq:DxxDef} and $\\Dxxxx$ can be obtained by multiplying two $\\Dxx$ matrices according to \n\\begin{equation}\n    \\Dxx\\Dxx = \\mathbf{D}_{xxxx} = \\frac{1}{h^4}\\begin{bmatrix}\n        5& -4 & 1 & & & \\mathbf{0}& \\\\\n        -4 & 6 &\\ddots &\\ddots & & & \\\\\n        1& \\ddots & \\ddots & -4 & 1 & & \\\\\n        & \\ddots& -4 & 6 & -4 & \\ddots& \\\\\n        & & 1 & -4 & \\ddots & \\ddots &1 \\\\\n        & & & \\ddots & \\ddots & 6 & -4 \\\\\n        & \\mathbf{0} & & & 1& -4 & 5 \\\\\n    \\end{bmatrix}.\n\\end{equation}\n\nFinally for free boundary conditions given in Eq. \\eqref{eq:BCfreeDisc}, the state vectors and matrices are $(N+1)\\times 1$ and $(N+1)\\times (N+1)$ respectively. Now, the $\\Dxx$ matrix is of the form in Eq. \\eqref{eq:DxxDefNeumann} instead, and\n\n\\setstackgap{L}{16pt}\n\\setstacktabbedgap{8pt}\n\\def\\lrgap{\\kern3pt}\n\\fixTABwidth{T}\n\\begin{equation}\n    \\mathbf{D}_{xxxx} = \\frac{1}{h^4}\\xbracketMatrixstack{\n        2& -4 & 2 & & & \\mathbf{0}& \\\\\n        -2 & 5 & -4 & 1 & & & \\\\\n        1& -4 & 6 & -4 & 1 & & \\\\\n        & \\ddots & \\ddots & \\ddots & \\ddots &\\ddots & \\\\\n        & & 1 & -4 & 6 & -4 &1 \\\\\n        & & & 1 & -4 & 5 & -2 \\\\\n        & \\mathbf{0} & & & 2& -4 & 2}.\n\\end{equation}\n\n\\subsection{Parameters and output}\\label{sec:paramsAndOutput}\nThe values of the parameters naturally determine the properties of the output sound. Where in the 1D wave equation, only the fundamental frequency $f_0$ could be affected (through $c$ and $L$ in Eq. \\eqref{eq:fundamentalFreq}), the stiff string has many more aspects that can be changed. See Table \\ref{tab:stiffStringParams} for parameters most commonly used in this project. \n\\begin{table}[h]\n    \\begin{center}\n    \\begin{tabular}{|l|c|c|}\n        \\hline\n        Name & Symbol (unit) & Value\\\\ \\hline\n        Length & $L$ (m) & $1$\\\\\n        Material density & $\\rho$ (kg/m$^3$) & $7850$\\\\\n        Radius & $r$ (m) & $5\\cdot10^{-4}$\\\\\n        Tension & $T$ (N) &$100 \\leq T \\leq 1.5\\cdot 10^4$\\\\\n        Young's modulus & $E$ (Pa) & $2\\cdot10^{11}$\\\\\n        Freq.-independent damping & $\\sz$ (s$^{-1}$) & $1$\\\\\n        Freq.-dependent damping & $\\so$ (m$^2$/s) & $0.005$\\\\\\hline\n    \\end{tabular}\n    \\caption{Parameters and their values most commonly used over the course of this project.\\label{tab:stiffStringParams}}\n    \\end{center}\n\\end{table}\n{\\renewcommand{\\arraystretch}{1}\n\nA formula exists to calculate the loss coefficients $\\sz$ and $\\so$ from $T_{60}$ values at different frequencies (see \\cite[Eq (7.29)]{theBible}). During this project, however, these values have been tuned by ear and are usually set to be approximately those found in Table \\ref{tab:stiffStringParams}. \n\n\n\\subsubsection{Output}\nFigure \\ref{fig:stiffStringOutput} shows the time domain and frequency domain output (retrieved at $l = 3$) of an implementation of the stiff string excited using a raised-cosine. The parameters used can be found in Table \\ref{tab:stiffStringParams} \nwith $T = 1129$ N. Furthermore, $E = 7\\cdot 10^{11}$ Pa to highlight dispersive effects. Finally, simply supported boundary conditions are chosen. From the left panel, one can observe that over time, dispersive effects show where higher-frequency components in the excitation travel faster through the medium than lower-frequency components. In the frequency domain (the right panel in Figure \\ref{fig:stiffStringOutput}) this shows in the fact that the partials are not perfect integer multiples of the fundamental. Notice that the partials are closer to each other for lower frequencies and further apart as their frequency increases. Finally, the frequency-dependent damping term causes higher frequencies to have a lower amplitude than lower frequencies. \n\nApart from the obvious material properties such as density, stiffness and geometry, perceptual qualities of the sound are surprisingly much determined by $\\so$, and for lower values the output can become extremely metallic.\n\n\\begin{figure}[h]\n    \\includegraphics[width=\\textwidth]{figures/resonators/outputFFT.eps}\n    \\caption{The time-domain and frequency domain output of the stiff string. The parameters are set as in Table \\ref{tab:stiffStringParams} with $E = 7\\cdot 10^{11}$ Pa to highlight dispersive effects and $T = 1129$ N. %From the left panel, one can observe that over time, dispersive effects show due to the stiffness in the string. In frequency domain (right panel) this shows through the partials not being perfect integer multiples of the fundamental. Lastly, higher frequency components have a lower amplitude due to the frequency-dependent damping.\n    \\label{fig:stiffStringOutput}}\n\\end{figure}\n\n\n\\section{von Neumann analysis and stability condition}\\label{sec:stiffStringStability}\nIn order to obtain the stability condition for the damped stiff string, one can perform von Neumann analysis as presented in Section \\ref{sec:stabilityAnalysis} on the FD scheme in Eq. \\eqref{eq:stiffStringFDS}.\n\nUsing the definitions found in Eq. \\eqref{eq:temporalAnsatz} for the temporal operators and Eqs. \\eqref{eq:dxxAnsatz} and \\eqref{eq:dxxxxAnsatz} for the spatial operators, the frequency domain representation of Eq. \\eqref{eq:stiffStringFDS} can be obtained:\n\\begin{align*}\n    \\!\\!\\!\\!\\frac{1}{k^2}\\left(z - 2 + z^{-1}\\right) =&-\\frac{4c^2}{h^2}\\sin^2(\\beta h/2) - \\frac{16\\kappa^2}{h^4}\\sin^4(\\beta h/2) - \\frac{\\sz}{k}z + \\frac{\\sz}{k}z^{-1}\\\\\n    & - \\frac{8 \\so}{kh^2}\\sin^2(\\beta h/2) + \\frac{8 \\so}{kh^2} \\sin^2(\\beta h/2)z^{-1}\n\\end{align*}\nand after collecting the terms, the characteristic equation is as follows\n\\begin{gather}\n    (1+\\sz k)z + \\left(16\\mu^2\\sin^4(\\beta h/2)+\\left(4\\lambda^2+\\frac{8\\so k}{h^2}\\right)\\sin^2(\\beta h/2) - 2\\right)\\nonumber\\\\\n    +\\left(1-\\sz k-\\frac{8\\so k}{h^2}\\sin^2(\\beta h/2)\\right)z^{-1}=0.\\label{eq:charDampedString}\n\\end{gather}\nRewriting this to the form \\eqref{eq:polynomialForm}, and using $\\S = \\sin^2(\\beta h /2)$ for brevity, yields\n\\begin{equation*}\n    z^2 + \\left(\\frac{16\\mu^2\\S^2+\\left(4\\lambda^2+\\frac{8\\so k}{h^2}\\right)\\S - 2}{1 + \\sz k}\\right)z+\\frac{1-\\sz k-\\frac{8\\so k}{h^2}\\S}{1 + \\sz k}=0.\n\\end{equation*}\nStability of the system can then be proven using condition \\eqref{eq:condition214}, and substituting the coefficients into this condition yields\n\\begin{equation}\\nonumber\n    \\begin{aligned}\n        \\left|\\frac{16\\mu^2\\S^2+\\left(4\\lambda^2+\\frac{8\\so k}{h^2}\\right)\\S - 2}{1+\\sz k}\\right|-1 &\\leq \\frac{1-\\sz k-\\frac{8\\so k}{h^2}\\S}{1+\\sz k}\\leq 1,\\\\\n        \\left|16\\mu^2\\S^2+\\left(4\\lambda^2+\\frac{8\\so k}{h^2}\\right)\\S - 2\\right|-(1+\\sz k) &\\leq 1-\\sz k-\\frac{8\\so k}{h^2}\\S\\leq 1+\\sz k,\\\\\n        \\left|16\\mu^2\\S^2+\\left(4\\lambda^2+\\frac{8\\so k}{h^2}\\right)\\S - 2\\right|&\\leq2-\\frac{8\\so k}{h^2}\\S\\leq2+2\\sz k.\n    \\end{aligned}\n\\end{equation}\nThe second condition is always true due to the fact that $\\sigma_0,\\sigma_1 \\geq 0$. Continuing with the first condition: \n\\begin{align*}\n    -2+\\frac{8\\so k}{h^2}\\S&\\leq 16\\mu^2\\S^2+\\left(4\\lambda^2+\\frac{8\\so k}{h^2}\\right)\\S - 2\\leq 2-\\frac{8\\so k}{h^2}\\S,\\\\\n    0&\\leq 16\\mu^2\\S^2+4\\lambda^2\\S\\leq 4-\\frac{16\\so k}{h^2}\\S.\n\\end{align*}\nAs $16\\mu^2\\S^2+4\\lambda^2\\S$ is positive definite, the first condition is always satisfied. Continuing with the second condition:\n\\begin{align*}\n    16\\mu^2\\S^2+\\left(4\\lambda^2+ \\frac{16\\so k}{h^2}\\right)\\S &\\leq 4,\\\\\n    4\\mu^2\\S^2+\\left(\\lambda^2+ \\frac{4\\so k}{h^2}\\right)\\S&\\leq 1.\n\\end{align*}\nAs $\\S$ is bounded by $1$ for all values of $\\beta$, one can set $\\S = 1$ \\SWcomment[check with Stefan]. Continuing with the substituted definitions for $\\lambda$ and $\\mu$ from Eq. \\eqref{eq:stiffStringCourant} yields\n\\begin{align*}\n    \\frac{4\\kappa^2k^2}{h^4}+\\frac{c^2k^2 + 4\\so k}{h^2}&\\leq 1, \\\\\n    4\\kappa^2k^2+(c^2k^2+ 4\\so k)h^2&\\leq h^4,\\\\\n    h^4- (c^2k^2+ 4\\so k)h^2 - 4\\kappa^2k^2 &\\geq 0 ,\n\\end{align*}\nwhich is a quadratic equation in $h^2$ with $h$ bounded by\n\\begin{equation}\n    h \\geq \\sqrt{\\frac{c^2k^2+4\\so k + \\sqrt{(c^2k^2 + 4\\so k)^2+16\\kappa^2k^2}}{2}}.\n\\end{equation}\nThis is the stability condition for the damped stiff string also shown in Eq. \\eqref{eq:stiffStringStability}.\n\n\\section{Energy analysis}\\label{sec:energyAnalysisString}\nAs mentioned in Section \\ref{sec:energyAnalysis}, it is useful to perform the energy analysis on the scheme with all physical parameters written out. Discretising the PDE in Eq. \\eqref{eq:stiffStringPDE} yields\n\\begin{equation}\n    \\rho A \\dtt \\uln = T \\dxx \\uln - EI \\dxxxx \\uln - 2\\sz \\rho A \\dtd \\uln + 2 \\so \\rho A \\dtm \\dxx \\uln,\n\\end{equation}\ndefined for $l\\in d$ with discrete domain $d = \\{0, \\hdots, N\\}$. This section will follow the 4 steps described in Section \\ref{sec:energyAnalysis}.\n\nThis section will be divided into $5$ steps, as done in Section \\ref{sec:energyAnalysis}.\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\nAs there is damping present in the system, and the system is distributed, the energy balance will be of the form \n\\begin{equation}\n    \\dtp \\h = \\mathfrak{b}-\\mathfrak{q}.\n\\end{equation}\nwith boundary term $\\b$ and damping term $\\q$. The latter is defined as \\todo{virtual grid points needed for freq-dep damping term..}\n\\begin{equation}\\label{eq:dampingTermStiffString}\n    \\mathfrak{q} = 2\\sz \\rho A \\lVert\\dtd\\uln\\rVert_d^2 - 2 \\so \\rho A \\langle \\dtd \\uln, \\dtm \\dxx \\uln \\rangle_d,\n\\end{equation}\nand $\\mathfrak{b}$ appears after rewriting Eq. \\eqref{eq:rOCStiffString} using summation by parts (see Section \\ref{sec:summationByParts}). Specifically, using Eq. \\eqref{eq:summationByPartsMinusBar} for the second term and Eq. \\eqref{eq:summationByPartsTwiceReduced} for the third, yields\n\\begin{align*}\n    \\dtp \\h &= \\rho A \\langle \\dtd \\uln, \\dtt \\uln \\rangle_d + T \\langle \\dtd \\dxp \\uln, \\dxp \\uln\\rangle_{\\underline{d}} + EI \\langle \\dtd \\dxx \\uln, \\dxx \\uln \\rangle_{\\overline{\\underline{d}}} \\\\\n    &= \\mathfrak{b} - \\mathfrak{q}\n\\end{align*}\nwhere the boundary term becomes\n\\begin{align*}\n    \\mathfrak{b} =&\\ T\\Big((\\dtd u_N^n)(\\dxp u_N^n) - (\\dtd u_0^n) (\\dxp u_{-1}^n)\\Big) \\\\\n    &+ EI \\Big((\\dtd u_N^n)(\\dxp \\dxx u_N^n) - (\\dxx u_N^n)(\\dxm \\dtd u_N^n) \\Big)\\\\\n    &- EI \\Big((\\dtd u_0^n)(\\dxm \\dxx u_0^n) - (\\dxx u_0^n)(\\dxp \\dtd u_0^n)\\Big).\n\\end{align*}\nFor the clamped and simply supported boundary conditions in \\eqref{eq:BCclampedDisc} and \\eqref{eq:BCsimplySupportedDisc} it can easily be shown that $\\mathfrak{b} = 0$. If free conditions as in Eq. \\eqref{eq:BCfreeDisc} are used, the boundary conditions will vanish when the primed inner product in Eq. \\eqref{eq:primedInnerProd} is used in Step 1 and identity \\eqref{eq:summationByPartsTwicePrimed} is used when performing summation by parts. Here, only the clamped / simply supported case will be considered. \n\n\n\\subsubsection{Step 3: Check units}\nComparing the acquired energy balance in Eq. \\eqref{eq:energyBalanceStiffString} to the energy balance for the 1D wave equation in Eq. \\eqref{eq:energyBalance1DWave}, one can observe that the balances are nearly identical, the only difference being the second term in the definition for $\\v$ in Eq. \\eqref{eq:energyBalanceStiffString}. \nWriting this term out in units, and recalling that Pa (the unit for $E$) in SI units is kg$\\cdot$m$^{-1}\\cdot$s$^{-2}$, yields\n\\begin{align*}\n    \\frac{EI}{2}\\langle\\dxx\\uln, e_{t-}\\dxx\\uln\\rangle_{\\overline{\\underline{d}}}\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}& \\quad \\text{Pa}\\cdot \\text{m}^4 \\cdot \\text{m} \\cdot (\\text{m}^{-2} \\cdot \\text{m} \\cdot \\text{m}^{-2} \\cdot \\text{m}) \\\\\n    & = \\text{kg} \\cdot \\text{m}^2 \\cdot \\text{s}^{-2},\n\\end{align*}\nand indeed has the correct units. \n\nAs described in Section \\ref{sec:energyAnalysis}, the damping terms in $\\mathfrak{q}$ need to have units of Joules per second, or kg $\\cdot$ m$^2 \\cdot$ s$^{-3}$. Writing the terms in Eq. \\eqref{eq:dampingTermStiffString} out in their units yields\n\\begin{align*}\n    2\\sz \\rho A \\lVert\\dtd\\uln\\rVert_d^2\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}&\\quad \\text{s}^{-1}\\cdot\\text{kg}\\cdot\\text{m}^{-3}\\cdot\\text{m}^2\\cdot \\text{m}\\cdot(\\text{s}^{-1}\\cdot\\text{m})^2 \\\\\n    &= \\text{kg} \\cdot \\text{m}^2 \\cdot \\text{s}^{-3},\\\\\n    - 2 \\so \\rho A \\langle \\dtd \\uln, \\dtm \\dxx \\uln \\rangle_d\\  \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}&\\quad \\text{m}^2\\cdot\\text{s}^{-1}\\cdot\\text{kg}\\cdot\\text{m}^{-3}\\cdot\\text{m}^2\\\\\n    &\\qquad\\cdot\\text{m}\\cdot(\\text{s}^{-1}\\cdot\\text{m})(\\text{s}^{-1}\\cdot\\text{m}^{-2}\\cdot \\text{m}),\\\\\n    &= \\text{kg} \\cdot \\text{m}^2 \\cdot \\text{s}^{-3},\n\\end{align*}\nand also have the correct units.\n\\subsubsection{Step 4: Implementation}\nAn implementation of the energy calculation for the simply supported boundary condition is given in Algorithm \\ref{alg:stiffStringEnergy}. The damping is ignored but can be found in Appendix \\ref{app:stiffstring}. \\todo{Add to appendix or refer to a gist} Figure \\ref{fig:energyStiffString} shows that the damping present in the system causes $\\h$ to decrease in the left panel. The right panel shows that the deviation of the total energy calculated using Eq. \\eqref{eq:normalisedEnergyDamping} is within machine precision.\n\n\\setlstMAT\n\\begin{lstlisting}[caption=Calculating $\\h$ for the simply supported boundary condition., label=alg:stiffStringEnergy]\n%%%% Before the main loop: %%%%\n\n% Initialise Dx+ operator to calculate potential energy due to tension\n% As the domain is reduced by one, the matrix needs to be of size N x N\nDxp = sparse(1:N, 1:N, -ones(1, N), N, N) + ...\n        sparse(1:N-1, 2:N, ones(1, N-1), N, N);\n\n%%%% In the main loop: %%%%\n\n% energy in the system\nkinEnergy(n) = rho * A * h / 2 * sum((1/k * (u - uPrev)).^2);\npotEnergy(n) = T / 2 * h * sum((Dxp * [0; u]) .* (Dxp * [0; uPrev])) ... + E * I * h / 2 * sum((Dxx * u) .* (Dxx * uPrev));\n\\end{lstlisting}\n\n\n\\section{Modal analysis}\n% To find an expression for the modal frequencies one can ignore the damping terms for now and follow the process in Section \\ref{sec:modalAnalysis} to obtain\n% \\begin{equation}\n%     f_p = \\frac{1}{\\pi k}\\sin^{-1}\\left(\\frac{1}{2}\\sqrt{-\\eig_p(c^2k^2\\Dxx - \\kappa^2k^2\\Dxxxx)}\\right).\n% \\end{equation}\n\nTo be able to perform a modal analysis on the FD scheme in \\eqref{eq:stiffStringFDS}, it must be written in one-step form -- introduced in Section \\ref{sec:oneStepForm} -- due to the damping present in the system. Using the matrix form of the damped stiff string in Eq. \\eqref{eq:matrixFormStiffString}, the one-step form can be written as\n%needs be used. As there are damping terms present in the system, it is useful to write the update in one-step form as explained in Section \\ref{sec:oneStepForm}.\n\\begin{equation}\\label{eq:oneStepFormStiffSTring}\n    \\underbrace{\\begin{bmatrix}\n        \\u^{n+1}\\\\\n        \\u^n\n    \\end{bmatrix}}_{\\w^{n+1}} = \n    \\underbrace{\\begin{bmatrix}\n        \\B/A & \\C/A\\\\\n        \\I & \\mathbf{0}\n    \\end{bmatrix}}_{\\Q}\n    \\underbrace{\\begin{bmatrix}\n        \\u^n\\\\\n        \\u^{n-1}\n    \\end{bmatrix}}_{\\w^n},\n\\end{equation}\nwhere the definitions for $\\B$, $\\C$ and $A$ can be found in Section \\ref{sec:implementationStiffString}. In this analysis, the definitions for $\\Dxx$ and $\\Dxxxx$ for simply supported boundary conditions will be used.\n\nAssuming test solutions of the form $\\w^n = z^n\\boldPhi$, and recalling that $z=e^{sk}$ and complex frequency $s = j\\omega + \\sigma$, yields the following eigenvalue problem (see Section \\ref{sec:eigenValueProblems})\n\\begin{equation}\n    z\\boldPhi = \\Q \\boldPhi,\n\\end{equation}\nwhich can be solved for the $p$\\th complex modal frequency\n\\begin{equation}\n    s_p = \\frac{1}{k}\\ln \\left(\\eig_p(\\Q)\\right).\n\\end{equation}\nThe (angular) frequency of the $p$\\th mode can then be obtained using $\\mathfrak{I}(s_p)$ and the damping per mode as $\\mathfrak{R}(s_p)$. Only selecting the non-negative frequencies obtained from $\\mathfrak{I}(s_p)$, these can be plotted and are shown in Figure \\ref{fig:modesStiffString}. The parameters used are the ones found in Table \\ref{tab:stiffStringParams} with $T = 1885$ N, and $E = 2\\cdot 10^{14}$ Pa to highlight inharmonic behaviour. The left panel shows that the system is indeed inharmonic, i.e., modal frequencies increase more as the modal number increases. The right panel shows that higher modes exhibit a higher amount of damping. This is due to the frequency-dependent damping term. If $\\sigma_1 = 0$ in \\eqref{eq:stiffStringFDS}, it can be shown that $\\sigma_p = \\sigma_0$ for every mode $p$ (in this case $\\sigma_0 = -1$).\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/modesStiffString.eps}\n    \\caption{The modal frequencies and damping per mode for the stiff string using the values in Table \\ref{tab:stiffStringParams} and $T = 1885$ N and $E = 2\\cdot 10^{14}$ Pa to highlight effects of stiffness. % Notice form the left panel that the frequency increases exponentially with the mode number. The right panel shows that higher modes exhibit a greater amount of damping due to the frequency-dependent damping term.\n    \\label{fig:modesStiffString}}\n\\end{figure}\n\n\\section{Implicit scheme}\\label{sec:implicitStiffString}\nAlthough not used in the published work of this project, it is useful to touch upon an example of an implicit scheme. Consider a discretisation of Eq. \\eqref{eq:stiffStringPDECompact} where the (more accurate) centred operator is used for the frequency-dependent damping term:\n\\begin{equation}\\label{eq:stiffStringFDSImplicit}\n    \\dtt \\uln = c^2 \\dxx \\uln - \\kappa^2 \\dxxxx \\uln - 2 \\sz \\dtd \\uln + 2 \\so\\dtd\\dxx \\uln.\n\\end{equation}\nUsing the centred operator in the mixed-spatio-temporal operator renders the system \\textit{implicit}, meaning that a definition for $u_l^{n+1}$ can not explicitly be found from known values. The stencil in Figure \\ref{fig:stencilStiffStringImplicit} also shows this: in order to calculate $u_l^{n+1}$, neighbouring points at the next time step $u_{l+1}^{n+1}$ and $u_{l-1}^{n+1}$ are needed. The issue is that these values are unknown at the time of calculation.\n\nLuckily, as the scheme is linear, it can be treated as a system of linear equations and solved following the technique described in Section \\ref{sec:linearEquations}. The drawback is that this requires one matrix inversion per iteration which can be extremely costly (see Section \\ref{sec:RTmatrixInversion}). However, both von Neumann and modal analysis (below) show that using the centred instead of the backwards operator has a positive effect on the stability and the modal behaviour of the scheme. \n\nConsidering simply supported boundary conditions such that $l \\in \\{1, \\hdots, N-1\\}$, the system will have $N-1$ unknowns ($u_l^{n+1}$ for $l \\in \\{1, \\hdots, N-1\\}$) that can be calculated using $N-1$ (update) equations. Writing this in matrix form using column vector $\\u^n = [u_1^n, u_2^n, \\hdots, u_{N-1}^n]$ yields \n\n\\begin{equation}\\label{eq:matrixFormStiffStringImplicit}\n    \\A\\u^{n+1} = \\B\\u^n + \\C \\u^{n-1}\n\\end{equation}\nwhere \n\\begin{equation*}\n    \\begin{gathered}\n    \\A = (1+\\sz k)\\I - \\so k\\Dxx, \\quad \\B = c^2 k^2 \\Dxx - \\kappa^2 k^2 \\Dxxxx \\\\\n    \\text{and} \\quad \\C = -(1-\\sz k)\\I - \\so k \\Dxx.\n    \\end{gathered}\n\\end{equation*}\nEquation \\eqref{eq:matrixFormStiffStringImplicit} can be considered a system of linear equations (see Section \\ref{sec:linearEquations}) and the state at the next time step $\\u^{n+1}$ can then be retrieved using a matrix inversion (see \\ref{sec:inverse})\n\\begin{equation}\n    \\u^{n+1} = \\A^{-1}\\left(\\B\\u^n + \\C \\u^{n-1}\\right).\n\\end{equation}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{figures/resonators/stencilImplicitStiffString.eps}\n    \\caption{The stencil for the damped stiff string scheme in \\eqref{eq:stiffStringFDSImplicit}.\\label{fig:stencilStiffStringImplicit}}\n\\end{figure}\n\n\\subsection{von Neumann analysis}\nUsing the same process as in Section \\ref{sec:stiffStringStability}, the definitions in Section \\ref{sec:stabilityAnalysis} can be used to obtain a frequency domain representation of the FD scheme in Eq. \\eqref{eq:stiffStringFDSImplicit}:\n\\begin{align}\n    \\!\\!\\!\\!\\frac{1}{k^2}\\left(z - 2 + z^{-1}\\right) =&-\\frac{4c^2}{h^2}\\sin^2(\\beta h/2) - \\frac{16\\kappa^2}{h^4}\\sin^4(\\beta h/2) - \\sz kz + \\sz k z^{-1}\\nonumber\\\\\n    & - \\frac{4 \\so  k}{h^2}\\sin^2(\\beta h/2)z + \\frac{4 \\so  k}{h^2} \\sin^2(\\beta h/2)z^{-1}\n\\end{align}\nand after collecting the terms, the characteristic equation follows\n\\begin{gather}\n\\left(1+\\sz k + \\frac{4\\so k}{h^2}\\sin^2(\\beta h/2)\\right)z + \\left(16\\mu^2\\sin^4(\\beta h/2)+4\\lambda^2\\sin^2(\\beta h/2) - 2\\right)\\nonumber\\\\\n+ \\left(1-\\sz k - \\frac{4\\so k}{h^2}\\sin^2(\\beta h/2)\\right)z^{-1} = 0.\\label{eq:charDampedStiffSTring}\n\\end{gather}\nRewriting this to the form \\eqref{eq:polynomialForm} and, again, using $\\S = \\sin^2(\\beta h / 2)$ yields:\n\\begin{equation*}\nz^2 + \\frac{16\\mu^2\\S^2+4\\lambda^2\\S - 2}{1+\\sz k + \\frac{4\\so k}{h^2}\\S}z+\\frac{1-\\sz k - \\frac{4\\so k}{h^2}\\S}{1+\\sz k + \\frac{4\\so k}{h^2}\\S} = 0.\n\\end{equation*}\nstability of the system can be proven using condition \\eqref{eq:condition214}. Continuing with $\\S = \\sin^2(\\beta h/2)$ and substituting the coefficients into this condition yields\n\\begin{align*}\n\\left|\\frac{16\\mu^2\\S^2+4\\lambda^2\\S - 2}{1+\\sz k + \\frac{4\\so k}{h^2}\\S} \\right|-1 &\\leq \\frac{1-\\sz k - \\frac{4\\so k}{h^2}\\S}{1+\\sz k + \\frac{4\\so k}{h^2}\\S}\\leq 1,\\\\[1em]\n\\left|16\\mu^2\\S^2+4\\lambda^2\\S - 2 \\right| - \\left(1+\\sz k + \\frac{4\\so k}{h^2}\\S\\right) &\\leq 1-\\sz k - \\frac{4\\so k}{h^2}\\S\\\\\n&\\qquad\\leq 1+\\sz k + \\frac{4\\so k}{h^2}\\S,\\\\[1em]\n\\left|16\\mu^2\\S^2+4\\lambda^2\\S - 2 \\right|&\\leq 2 \\leq 2+2\\sz k + \\frac{8\\so k}{h^2}\\S.\n\\end{align*} \nBecause $\\sz, \\so, k, \\S$ and $h$ are all non-negative, the last condition is always satisfied. Continuing with the first condition:\n\\begin{align*}\n    -2\\leq 16\\mu^2\\S^2+4\\lambda^2\\S - 2 &\\leq 2,\\\\\n    0\\leq 16\\mu^2\\S^2+4\\lambda^2\\S &\\leq 4.\n\\end{align*}\nAgain, the first condition is always satisfied due to the non-negativity of all coefficients. Continuing with the second condition yields\n\\begin{equation*}\n    4\\mu^2\\S^2+\\lambda^2\\S \\leq 1,\n\\end{equation*} \nand knowing that $\\S$ is bounded by $1$ for all $\\beta$, the process can be finalised:\n\\begin{align*}\n    4\\mu^2+\\lambda^2 &\\leq 1,\\\\\n    \\frac{4\\kappa^2k^2}{h^4}+\\frac{c^2k^2}{h^2} &\\leq 1,\\\\\n    h^4 - c^2k^2h^2 - 4\\kappa^2k^2 &\\geq 0,\n\\end{align*}\nand yields the following stability condition:\n\\begin{equation}\\label{eq:implicitStability}\n    h \\geq \\sqrt{\\frac{c^2k^2 + \\sqrt{c^4k^4 + 16\\kappa^2k^2}}{2}}.\n\\end{equation}\nComparing this to the stability condition for the explicit scheme in Eq. \\eqref{eq:stiffStringStability}, one can observe that the terms containing $\\so$ have vanished. It can thus be concluded that if the centred (rather than the backwards) difference is used to discretise the temporal derivative in the frequency-dependent damping term, $\\so$ no longer influences the stability of the scheme and the condition is more relaxed. What this means in terms of behaviour of the scheme will be elaborated on in the following section.\n\n\\subsection{Modal analysis}\nAs the matrix form of the implicit FD scheme in Eq. \\eqref{eq:matrixFormStiffStringImplicit} matches the form in Eq. \\eqref{eq:modalForm}, one can perform a modal analysis by writing the scheme in one-step form as explained in Section \\ref{sec:oneStepForm}. The results of the analysis are shown in Figure \\ref{fig:implicitModes}. To highlight the difference between using the backwards and centred difference for the frequency-dependent damping term, $\\so $ has been set to $1$, which is much higher than one would normally use.\n\nOne can observe from Figure \\ref{fig:implicitModes} that especially higher-frequency modes in the explicit scheme are affected by $\\so$.  \nIn the continuous case, the modal frequencies should only be affected by values for $c$ and $\\kappa$ as per Eq. \\eqref{eq:inharmonicityEquation} and the damping should not influence the frequencies of the partials, as one could expect. However, as $\\so$ increases, $h$ increases due to Eq. \\eqref{eq:stiffStringStability}, causing $\\lambda$ and $\\mu$ to decrease. This introduces numerical dispersion as explained in Section \\ref{sec:quality1DWave}, and the higher the value of $\\so$, the more numerical dispersion is introduced.\n\nAs the stability condition for the implicit scheme in Eq. \\eqref{eq:implicitStability} does not contain $\\so$, this value will not affect $\\lambda$ and $\\mu$ and will thus not affect the modal frequencies. As can be observed from the figure, it even allows for one more grid point to be included in the simulation. It can be concluded that because the frequency-dependent damping term no longer affects the stability condition for the implicit scheme, a more accurate simulation can be obtained with fewer numerically dispersive effects.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/implicitModes.eps}\n    \\caption{A comparison between the modal frequencies and damping per mode of the explicit (blue) and implicit (red) scheme. Here, $T = 1885$ N, $E = 2\\cdot10^{14}$ Pa and $\\so = 1$ m$^2$/s to highlight differences between the two schemes. %One can observe that the modes of the implicit scheme follow the expected exponential pattern for the stiff string, where the explicit scheme shows numerically dispersive effects. Furthermore, due to the absence of $\\so$ in the stability condition in Eq. \\eqref{eq:implicitStability} and allows for one more grid point  \n    \\label{fig:implicitModes}}\n\\end{figure}\n\n\\subsection{Conclusion}\nThis section presented an implicit discretisation of the stiff string where the centred operator has been used to discretise the temporal derivative in the frequency-dependent damping term. By means of stability analysis and modal analysis several advantages that the implicit scheme has over its explicit counterpart (presented in Section \\ref{sec:stiffStringDiscrete}) have been shown.\n\nAs these advantages only show for higher values of $\\so$, much higher than the ones used in this project, it has been chosen to use the explicit scheme for all further implementation. The decrease in accuracy is negligible for lower values of $\\so$ and the calculation of the scheme becomes orders of magnitude more computationally expensive if the implicit scheme is used. \n", "meta": {"hexsha": "66af5d8ca68cd652ae29c4037e539cf6e98333ac", "size": 48429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/resonators/stiffString.tex", "max_stars_repo_name": "SilvinWillemsen/phdThesis", "max_stars_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aauPhdCollectionThesis/resonators/stiffString.tex", "max_issues_repo_name": "SilvinWillemsen/phdThesis", "max_issues_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aauPhdCollectionThesis/resonators/stiffString.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": 79.6529605263, "max_line_length": 914, "alphanum_fraction": 0.693406843, "num_tokens": 16485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.6924703148156593}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\section{Least-squares fitting}\n\n\\subsection{Model}\n\n\\begin{equation}\ny=\\alpha_{0}+\\alpha_{1}x\n\\end{equation}\n\n\\subsection{Data}\n\n\\begin{table}[ht]\n\\begin{centering}\n\\begin{tabular}{ccc}\ni & $x_{i}$ & $y_{i}$\\\\\n1 & 0 & 0 \\\\\n2 & 2 & 3 \\\\\n3 & 4 & 5 \\\\\n\\end{tabular}\n\\par\\end{centering}\n\\caption{Data.}\n\\end{table}\n\n\\begin{figure}[ht]\n\\begin{centering}\n\\includegraphics[width=\\columnwidth]{data.png}\n\\end{centering}\n\\caption{Data.}\n\\end{figure}\n\n\\section{Solution}\n\n\\begin{align*}\n\\alpha_{0}+\\alpha_{1}0 & =0\\\\\n\\alpha_{0}+\\alpha_{1}2 & =3\\\\\n\\alpha_{0}+\\alpha_{1}4 & =5\n\\end{align*}\n\n\n\\[\n\\left[\\begin{array}{cc}\n1 & 0\\\\\n1 & 2\\\\\n1 & 4\n\\end{array}\\right]\\left[\\begin{array}{c}\n\\alpha_{0}\\\\\n\\alpha_{1}\n\\end{array}\\right]=\\left[\\begin{array}{c}\n0\\\\\n3\\\\\n5\n\\end{array}\\right]\n\\]\n\n\\begin{align*}\n\\boldsymbol{X}\\boldsymbol{\\alpha} & =\\boldsymbol{y}\\qquad|\\boldsymbol{X}^{\\mathrm{T}}\\cdot\\left(\\cdot\\right)\\\\\n\\boldsymbol{X}^{\\mathrm{T}}\\boldsymbol{X}\\boldsymbol{\\alpha} & =\\boldsymbol{X}^{\\mathrm{T}}\\boldsymbol{y}\\qquad|\\left(\\boldsymbol{X}^{\\mathrm{T}}\\boldsymbol{X}\\right)^{-1}\\cdot\\left(\\cdot\\right)\\\\\n\\boldsymbol{\\alpha} & =\\left(\\boldsymbol{X}^{\\mathrm{T}}\\boldsymbol{X}\\right)^{-1}\\boldsymbol{X}^{\\mathrm{T}}\\boldsymbol{y}\n\\end{align*}\n\n\\begin{figure}[ht]\n\\begin{centering}\n\\includegraphics[width=\\columnwidth]{solution.png}\n\\end{centering}\n\\caption{Solution.}\n\\end{figure}\n\n\\end{document}", "meta": {"hexsha": "f556f09c82b3fdb60603066b465140720918bc58", "size": 1476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/report.tex", "max_stars_repo_name": "JuliaTraining/MyTestRepo.jl", "max_stars_repo_head_hexsha": "3ab863dfa7c87a780b62f86a5039a787f3f0761e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/report.tex", "max_issues_repo_name": "JuliaTraining/MyTestRepo.jl", "max_issues_repo_head_hexsha": "3ab863dfa7c87a780b62f86a5039a787f3f0761e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-11-01T13:54:24.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-01T13:57:20.000Z", "max_forks_repo_path": "docs/report.tex", "max_forks_repo_name": "JuliaTraining/MyTestRepo.jl", "max_forks_repo_head_hexsha": "3ab863dfa7c87a780b62f86a5039a787f3f0761e", "max_forks_repo_licenses": ["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.9459459459, "max_line_length": 196, "alphanum_fraction": 0.6653116531, "num_tokens": 577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.6924703081135132}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage[colorinlistoftodos]{todonotes}\n\n\\title{Playing with function iteration}\n\\author{Slavomir Kaslev}\n\n\\begin{document}\n\\maketitle\n\n\\section{General problem}\n\nThe equations $f(x) = x + f(x^2 + x^3)$ and $f(x) = x + f(\\frac{1}{1-x})$ are instances of the more general equation\n\\begin{equation}\nf(x) = x + f(g(x))\\label{eq:eq1}\n\\end{equation}\nWe want to find a function $f(x)$ such that \\eqref{eq:eq1} holds for all $x$, where the function $g(x)$ is known. Telescoping the equation gives\n$$f(x) = x + g(x) + g(g(x)) + g(g(g(x))) + \\dots$$\nLet's use the following notation for iterating a function\n\\begin{align*}\ng^{[0]}(x) &= x\\\\\ng^{[1]}(x) &= g(x)\\\\\ng^{[n]}(x) &= g(g^{[n-1]}(x))\n\\end{align*}\nto rewrite equation \\eqref{eq:eq1} as\n\\begin{equation}\nf(x) = \\sum_{n=0}^{\\infty}{g^{[n]}(x)}\\label{eq:eq2}\n\\end{equation}\nWe've reduced the problem from solving equation \\eqref{eq:eq1} to calculating the infinite sum \\eqref{eq:eq2}.\n\n\\section{Power series sleight of hand}\n\nThe next step is instead of solving equation \\eqref{eq:eq1} we'll change the problem by inserting a small parameter $\\epsilon$\n\\begin{equation}\nf(x) = x + \\epsilon f(g(x))\\label{eq:eq3}\n\\end{equation}\nRepeating the steps above, we telescope \\eqref{eq:eq3}\n$$f(x) = x + \\epsilon g(x) + \\epsilon^2 g(g(x)) + \\epsilon^3 g(g(g(x))) + \\dots$$\nand finally we get $f(x)$ as power series of $\\epsilon$\n\\begin{equation}\\label{eq4}\nf(x) = \\sum_{n=0}^{\\infty}{g^{[n]}(x)} \\epsilon^n\n\\end{equation}\n\nNow we have two procedures for computing $f(x)$ defined by equations \\eqref{eq:eq2} and \\eqref{eq4}. Of course, the two procedures will agree only if we finally set $\\epsilon$ to $1$.\n\n\\section{Special case $g(x) = \\frac{1}{1-x}$}\n\nEquation \\eqref{eq:eq3} takes the form\n\\begin{equation}\\label{eq5}\nf(x) = x + \\epsilon f(\\frac{1}{1-x})\n\\end{equation}\nNote that the function $g^{[n]}(x)$ is periodic in $n$ with period 3. That is\n\\begin{align*}\ng^{[0]}(x) &= x\\\\\ng^{[1]}(x) &= \\frac{1}{1-x}\\\\\ng^{[2]}(x) &= 1 - \\frac{1}{x}\\\\\ng^{[3]}(x) &= x\n\\end{align*}\nSo the series in \\eqref{eq4} have the form\n\\begin{equation}\\label{eq6}\nf(x) = x + \\epsilon \\frac{1}{1-x} + \\epsilon^2 (1 - \\frac{1}{x}) + \\epsilon^3 x + \\epsilon^4 \\frac{1}{1-x} + \\dots\n\\end{equation}\nWe'll sum this series using a generic summation procedure $S$ with the properties\n\\begin{subequations}\n\\begin{align}\n  S(a_0 + a_1 + a_2 + \\dots) &= a_0 + S(a_1 + a_2 + a_3 + \\dots)\\label{eq:sum1}\\\\\n  S(\\sum{\\alpha a_n} + \\sum{\\beta b_n}) &= \\alpha S(\\sum{a_n}) + \\beta S(\\sum{b_n})\\label{eq:sum2}\n\\end{align}\n\\end{subequations}\nTo simplify the calculation we'll substitute\n\\begin{equation*}\ns = f(x)\n\\qquad\na = x\n\\qquad\nb = \\frac{1}{1-x}\n\\qquad\nc = 1 - \\frac{1}{x}\n\\end{equation*}\nin \\eqref{eq6} to obtain\n$$s = S(a + b \\epsilon + c \\epsilon^2 + a \\epsilon^3 + b \\epsilon^4 + c \\epsilon^5 + \\dots)$$\nNext we'll pull the first term out of the sum two times by \\eqref{eq:sum1} and bring $\\epsilon$ outside the sum by \\eqref{eq:sum2}\n\\begin{align*}\ns = S&(a + b \\epsilon + c \\epsilon^2 + a \\epsilon^3 + b \\epsilon^4 + c \\epsilon^5 + \\dots)\\\\\ns = a + \\epsilon S&(b + c \\epsilon + a \\epsilon^2 + b\\epsilon^3 + c\\epsilon^4 + a \\epsilon^5 + \\dots)\\\\\ns = a + b \\epsilon + \\epsilon^2 S&(c + a \\epsilon + b\\epsilon^2 + c\\epsilon^3 + a \\epsilon^4 + b \\epsilon^5+ \\dots)\\\\\n\\end{align*}\nIf we multiply the first equation by $\\epsilon^2$, the second by $\\epsilon$ then add them all up, the result is\n$$(1 + \\epsilon + \\epsilon^2)s = (1+\\epsilon)a + \\epsilon b + \\epsilon^2 (a+b+c) S(1 + \\epsilon + \\epsilon^2 + \\epsilon^3 + \\dots)$$\nNotice that $S(1 + \\epsilon + \\epsilon^2 + \\epsilon^3 + \\dots) = \\frac{1}{1-\\epsilon}$ and now we have an explicit formula for $s$\n$$s=\\frac{(1+\\epsilon) a + \\epsilon b}{1+\\epsilon+\\epsilon^2} + \\frac{\\epsilon^2}{1-\\epsilon^3}(a+b+c)$$\nTherefore the solution of \\eqref{eq5} is\n\\begin{equation}\nf(x) = \\frac{(1+\\epsilon)x + \\epsilon\\frac{1}{1-x}}{1+\\epsilon+\\epsilon^2} + \\frac{\\epsilon^2}{1-\\epsilon^3}\\frac{x^3-3x+1}{x(x-1)}\\label{eq:soleps}\n\\end{equation}\nWe're interested in the solution of this equation\n\\begin{equation}\nf(x) = x + f(\\frac{1}{1-x})\\label{eq9}\n\\end{equation}\nwhich can be derived from \\eqref{eq:soleps} by seting $\\epsilon$ to $1$.\nNotice that when $\\epsilon=1$, the second term in the equation becomes infinite unless $x^3-3x+1=0$.\n\nWe conclude that the solution $f(x)$ of equation \\eqref{eq9} is infinite everywhere except for a finite set of points given by the roots of the equation\n$$x^3-3x+1=0$$\nnamely\n\\begin{equation*}\nx_1 \\approx -1.87938524\n\\qquad\nx_2 \\approx 0.34729636\n\\qquad\nx_3 \\approx 1.53208889\n\\end{equation*}\nwhere $f(x)$ has an explicit formula\n$$f(x)=\\frac{1}{3}\\;\\frac{1 + 2x - 2x^2}{1-x}$$\nand can be evalutated directly\n\\begin{equation*}\nf(x_1) \\approx -1.13715804\n\\qquad\nf(x_2) \\approx 0.7422272\n\\qquad\nf(x_3) \\approx 0.39493084\n\\end{equation*}\nNotice that iterating $g(x)$ over the numbers $x_1,x_2,x_3$ forms a cycle\n\\begin{equation*}\ng(x_1) = x_2\n\\qquad\ng(x_2) = x_3\n\\qquad\ng(x_3) = x_1\n\\end{equation*}\nand\n\\begin{equation*}\n\\sum_{k=1}^{3}{x_k} = 0\n\\qquad\n\\sum_{k=1}^{3}{f(x_k)} = 0\n\\qquad\n\\sum_{k=1}^{3}{g(x_k)} = 0\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "83019d20c7b54f355c46e4cad43de139d118fea3", "size": 5288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "iterating.tex", "max_stars_repo_name": "skaslev/papers", "max_stars_repo_head_hexsha": "592ef26e52ec6a4b61f9c0c198e9c459cef5b00a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iterating.tex", "max_issues_repo_name": "skaslev/papers", "max_issues_repo_head_hexsha": "592ef26e52ec6a4b61f9c0c198e9c459cef5b00a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "iterating.tex", "max_forks_repo_name": "skaslev/papers", "max_forks_repo_head_hexsha": "592ef26e52ec6a4b61f9c0c198e9c459cef5b00a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-09T17:16:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-09T17:16:43.000Z", "avg_line_length": 36.2191780822, "max_line_length": 183, "alphanum_fraction": 0.6562027231, "num_tokens": 2054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.6924703021864462}}
{"text": "\\documentclass{beamer}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{subfigure}\n\\usepackage{bbm}\n\n\\usetheme{Madrid}\n\\usecolortheme{beaver}\n\n\\title{Spectral clustering}\n\\author{%\n  Davide Riva\n  (\\texttt{driva95@protonmail.com})\n}\n\n\\begin{document}\n\n\\frame{\\titlepage}\n\n\\begin{frame}\n  \\frametitle{Table of Contents}\n  \\tableofcontents\n\\end{frame}\n\n\\section{Graphs with 1 connected component}\n\\begin{frame}\n  \\frametitle{Graphs with 1 connected component}\n  \\centering\n  \\includegraphics[width=0.5\\linewidth]{figures/one-component.eps}\n\\end{frame}\n\\begin{frame}\n  \\begin{block}{Laplacian matrix}\n    \\[ L = D - W \\]\n    \\[ D_{ij} = \\begin{cases} \\sum_{j=1}^n W_{ij} \\; \\text{if} \\; i = j \\\\ 0 \\; \\text{if} \\; i \\neq j \\end{cases} \\]\n  \\end{block}\n\n  \\begin{alertblock}{One eigenvalue equals to zero, its eigenvector equals to $a [1, 1, \\dots, 1]$}\n    \\[ f^T L f = \\frac{1}{2} \\sum_{i=1}^n \\sum_{j=1}^n W_{ij} (f_i - f_j)^2, \\; f \\in \\mathit{R}^n\n      \\implies f^T L f \\geq 0 \\; \\forall f \\]\n  \\end{alertblock}\n\\end{frame}\n\n\\section{Graphs with multiple connected components}\n\\begin{frame}\n  \\frametitle{Graphs with multiple connected components}\n  \\centering\n  \\includegraphics[width=0.5\\linewidth]{figures/multiple-component.eps}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Number of eigenvalues equal to zero}\n  \\begin{figure}\n    \\hfill\n    \\subfigure[Graphs with two connected components]{\\includegraphics[width=0.3\\linewidth]{figures/2-components.eps}}\n    \\hfill\n    \\subfigure[Graphs with four connected components]{\\includegraphics[width=0.3\\linewidth]{figures/4-components.eps}}\n    \\hfill\n    \\subfigure[Graphs with eight connected components]{\\includegraphics[width=0.3\\linewidth]{figures/8-components.eps}}\n    \\hfill\n    \\label{figure:mcomp}\n    \\caption{Box plot of the first 10 eigenvalues of 100 graphs with 64 nodes and different connected components, sorted in ascending order for each graph.}\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Eigenvectors as indicator vectors}\n  \\begin{figure}\n    \\hfill\n    \\subfigure{\\includegraphics[width=0.3\\linewidth]{figures/0-eigenvectors.eps}}%\n    \\hfill\n    \\subfigure{\\includegraphics[width=0.3\\linewidth]{figures/1-eigenvectors.eps}}%\n    \\hfill\n    \\subfigure{\\includegraphics[width=0.3\\linewidth]{figures/2-eigenvectors.eps}}%\n    \\hfill\n    \\label{figure:eivects}%\n  \\end{figure}\n\\end{frame}\n\n\\section{Considerations about noise}\n\\begin{frame}\n  \\frametitle{Considerations about noise}\n  \\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{figures/adding-noise.eps}\n    \\caption{Example of the effect of noise in the eigenvalues intensities in a graph with 3 connected components}\n    \\label{figure:addingnoise}\n  \\end{figure}\n\\end{frame}\n\n\\section{Spectral clustering when data is not a graph}\n\\begin{frame}\n  \\frametitle{Spectral clustering when data is not a graph}\n  Similarity function $s(x_i, x_j) \\geq 0$:\n  \\begin{itemize}\n    \\item $s(x_i, x_j) = e^{ - \\frac{||x_i - x_j||^2}{2\\sigma^2}}$ (Gaussian similarity function)\n    \\item $s(x_i, x_j) = ||x_i - x_j||_2 < \\epsilon$\n    \\item $s(x_i, x_j) = \\frac{1}{\\sqrt{2}} \\sqrt{\\sum_k (\\sqrt{x_i(k)} - \\sqrt{x_j(k)})^2}$ (Hellinger distance)\n    \\item \\dots\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Why not K-means?}\n  \\begin{figure}[ht]\n    \\hfill\n    \\subfigure[Ground truth]{\\includegraphics[width=0.3\\linewidth]{figures/ground-truth.eps}}%\n    \\hfill\n    \\subfigure[Clustering using K-means]{\\includegraphics[width=0.3\\linewidth]{figures/kmeans.eps}}%\n    \\hfill\n    \\subfigure[Clustering using spectral clustering]{\\includegraphics[width=0.3\\linewidth]{figures/spectral-on-comparison.eps}}%\n\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Is it possible to avoid hyperparameters tuning?}\n  \\begin{block}{Modularity}\n    \\[ Q = \\frac{1}{2m} \\sum_{i=1}^n \\sum_{j=1}^n (A_{ij} - \\frac{k_i k_j}{2m}) \\mathbbm{1}_{[C_i == C_j]} \\]\n  \\end{block}\n\n  \\begin{figure}\n    \\subfigure[Raw data]{\\includegraphics[width=0.2\\linewidth]{figures/mall-raw.png}}%\n    \\hfill\n    \\subfigure[Spectral clustering with modularity]{\\includegraphics[width=0.2\\linewidth]{figures/mall-spectral.png}}%\n    \\hfill\n    \\subfigure[Spectral clustering]{\\includegraphics[width=0.2\\linewidth]{figures/mall-manual.png}}%\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Conclusions}\n  Spectral clustering outperforms K-means, but you need hyperparameter tuning\n\\end{frame}\n\n\\end{document}", "meta": {"hexsha": "7457f57609fd0d087e5baa934ab2fed22286338c", "size": 4434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation.tex", "max_stars_repo_name": "Davide95/practical_spectral_clustering", "max_stars_repo_head_hexsha": "498797f26d3a6ef8d02e2d9b1734c18f5ab7e7ef", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-19T15:50:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-19T15:50:24.000Z", "max_issues_repo_path": "presentation.tex", "max_issues_repo_name": "Davide95/practical_spectral_clustering", "max_issues_repo_head_hexsha": "498797f26d3a6ef8d02e2d9b1734c18f5ab7e7ef", "max_issues_repo_licenses": ["CC0-1.0"], "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": "Davide95/practical_spectral_clustering", "max_forks_repo_head_hexsha": "498797f26d3a6ef8d02e2d9b1734c18f5ab7e7ef", "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.8444444444, "max_line_length": 156, "alphanum_fraction": 0.7036535859, "num_tokens": 1479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6924702959345289}}
{"text": "\\vsssub\n\\subsubsection{~$S_{ice}$: Damping by sea ice (Mosig et al.)} \\label{sec:ICE5}\n\\vsssub\n\n\\opthead{IC5}{U. of Otago MATLAB code}{Q. Liu, E. Rogers, A. Babanin}\n\n\\noindent\nThe fifth method for representing ice-induced wave decay is based on another viscoelastic-type model, i.e., the EFS ice layer model described in \\citet{art:MMS15}. The authors introduced viscosity into the thin elastic plate model of \\citet{art:FS1994} and restricted it to one horizontal dimension (replacing a plate by a beam). The dispersion relation given by the EFS model can be written in the form\n\\begin{equation}\nQ g k \\tanh(k d)-\\sigma^2 = 0,\n\\label{eq:ic5a}\n\\end{equation}\n%\n\\begin{equation}\nQ = \\frac{G_{\\eta} h_i^3}{6 \\rho_w g} (1+\\nu) k^4 - \\frac{\\rho_i h_i \\sigma^2}{\\rho_w g} + 1.\n\\label{eq:ic5b}\n\\end{equation}\n%\nIn Eq.~(\\ref{eq:ic5a})$-$(\\ref{eq:ic5b}), $G_{\\eta} = G - i \\sigma \\rho_i \\eta$ is the complex shear modulus, where $G$ is the \\emph{effective} elastic shear modulus and $\\eta$ is the \\emph{effective} viscosity; $\\rho_w$ ($\\rho_i$) is the density of water (ice), $d$ is water depth, $h_i$ is the ice cover thickness, $\\sigma$ is the radian frequency, $k=k_r + i k_i$ is the complex wavenumber, $g$ is the gravitational acceleration and $\\nu=0.3$ refers to the Poisson ratio of sea ice.\n\nSame as {\\code IC3}, {\\code IC5} requires four ice parameters as input: $C_{ice, 1}$ for ice thickness $h_i$ (m), $C_{ice, 2}$ for the \\emph{effective} viscosity $\\eta$ (m$^2$ s$^{-1}$), $C_{ice, 3}$ for ice density $\\rho_i$ (kg m$^{-3}$) and $C_{ice, 4}$ for the \\emph{effective} shear modulus $G$ (Pa). For example, as shown in \\citet[][see their Fig. 8]{art:MMS15}, a setting of $C_{ice, 1,...,4}=[1.0\\ \\mathrm{m},\\ 5.0\\times10^7\\ \\mathrm{m^2\\ s^{-1}},\\ 917.0\\ \\mathrm{kg\\ m^{-3}},\\ 4.9\\times10^{12}\\ \\mathrm{Pa}]$ (with a water depth $d$ of 4300 m) can be used to fit the observed wave attenuation rates reported in \\citet{art:MBK14}. The application of the EFS model to two realistic case studies is presented in \\citet{Liu2018ic5}.\n\nThe dispersion relation shown above is solved iteratively using the Newton-Raphson method. The numerical solver, however, may fail for small wave periods in some rare cases (particularly for shallow water depth $d$ and low $G$). In such cases, the estimated wavelength $k_r$ is unreasonably low. Several namelist variables (limiters) are introduced to improve the code stability:\n\\begin{clist}\n\\cit{IC5MINIG} {the minimum allowed shear modulus $G$; Default= 1 Pa (i.e., zero $G$ is not allowed).}\n%\n\\cit{IC5MINWT} {the minimum allowed wave periods $T$; Default=0 s (i.e., by default, this option is not used).}\n%\n\\cit{IC5MAXKRATIO} {the maximum allowed $k_{ow}/k_r$, where $k_{ow}$ is the open-water wavenumber; Default=1E9 (i.e., by default, this option is not used).}\n%\n\\cit{IC5MAXKI} {the maximum allowed $k_i$; Default=100 m$^{-1}$ (i.e., by default, this option is not used).}\n%\n\\cit{IC5MINHW} {the minimum allowed water depth $d$; Default=300 m (this basically limits {\\code IC5} to the deep-water case).}\n%\n\\cit{IC5MAXITER} {the maximum allowed \\# of iteration; Default=100.}\n\\end{clist}\n\nNote that the EFS model used here regards the ice cover as a continuous homogeneous medium and characterizes various ice types with two \\emph{totally empirical} rheological parameters, namely the elastic shear modulus $G$ and the viscosity $\\eta$. As argued in \\citet{art:MMS15}, these two parameters \\emph{``cannot be measured directly as they do not represent observable physical processes''}. Therefore, ``no restrictions on the acceptable values of the rheological parameters, \\emph{except positiveness}, can be imposed.'' So strictly speaking, the EFS model is better termed as an \\emph{effective medium} model rather than a \\emph{viscoelastic} model.\n", "meta": {"hexsha": "cfbb8457316fa21120aa28df1ad5c7a0f6407542", "size": 3785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WW3/manual/eqs/ICE5.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/ICE5.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/ICE5.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": 97.0512820513, "max_line_length": 737, "alphanum_fraction": 0.7207397622, "num_tokens": 1187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6924454070922907}}
{"text": "%---------------------------Scaled Jacobian---------------------------\n\\section{Scaled Jacobian}\n\nThis metric is the minimum determinant of the Jacobian matrix\nevaluated at each corner and the center of the element,\ndivided by the corresponding edge lengths.\n\\[\nq = \\min_{i\\in\\{0,1,\\ldots,8\\}}\\left\\{\\hat\\alpha_i\\right\\}.\n\\]\n\nNote that if ${L_{\\min}}^2 \\leq DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{scaled Jacobian}%\n{$1$}%                                        Dimension\n{$[0.5,1]$}%                                  Acceptable range\n{$[-1,1]$}%                                   Normal range\n{$[-1,DBL\\_MAX]$}%                            Full range\n{$1$}%                                        Cube\n{\\cite{knu:00}}%                              Citation\n{v\\_hex\\_scaled\\_jacobian}%                   Verdict function name\n", "meta": {"hexsha": "602dff50a586eca89f8505bcfdc5fc9571cda9d0", "size": 836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexScaledJacobian.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/HexScaledJacobian.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/HexScaledJacobian.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.8095238095, "max_line_length": 70, "alphanum_fraction": 0.466507177, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.692378929825257}}
{"text": "\\section{Points and vectors}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Understand the geometric and algebraic meaning of points and\n    vectors in $\\R^n$.\n  \\item Find the position vector of a point in $\\R^n$.\n  \\item Determine whether two vectors are equal.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we define points and vectors in $n$-dimensional\nspace, and discuss some of their interpretations. We start with a\nbrief review of Cartesian coordinate systems.\n\\bigskip\n\n\\noindent\\textbf{Points in $n$-dimensional space.}\nYou are probably already familiar with Cartesian coordinates%\n\\index{Cartesian coordinates}%\n\\index{coordinate system!Cartesian}, which let you describe points%\n\\index{point} in $2$- or $3$-dimensional space. Consider the familiar\ncoordinate plane, with an $x$-axis and a $y$-axis. Any point within\nthis coordinate plane is identified by its $x$- and $y$-coordinates%\n\\index{coordinate!of a point}. For example, the point $P$ in the\nfollowing diagram has $x$-coordinate~$2$ and $y$-coordinate~$1$.  We\nwrite these coordinates as an ordered pair $P=(2,1)$. Here,\n``ordered'' means that the $x$-coordinate comes first, and then the\n$y$-coordinate, i.e., $(1,2)$ is not the same point as\n$(2,1)$. Coordinates can be positive, negative, or zero. The special\npoint with coordinates $(0,0)$ is called the \\textbf{origin}%\n\\index{origin of a coordinate system} of the coordinate system, and\nalso written as $0$.\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.6]\n    \\draw[thick,->](-4,0)--(4,0);\n    \\draw[thick,->](0,-1)--(0,5);\n    \\draw(2,0.2)--(2,-0.2);\n    \\draw(-3,0.2)--(-3,-0.2);\n    \\draw(-0.2,1)--(0.2,1);\n    \\draw(-0.2,4)--(0.2,4);\n    \\draw[help lines] (-3,0)--(-3,4)--(0,4);\n    \\draw[help lines](0,1)--(2,1)--(2,0);\n    \\draw[fill](-3,4) circle [radius=3pt];\n    \\draw[fill](2,1) circle [radius=3pt];\n    \\node[below right] at (4,0){$x$};\n    \\node[left] at(0,5){$y$};\n    \\node[below] at (-3,-0.5){$-3$};\n    \\node[below] at (2,-0.5){$2$};\n    \\node[left] at (-0.5, 1){$1$};\n    \\node[left] at (-0.5, 4){$4$};\n    \\node[above] at (-3,4){$Q = (-3,4)$};\n    \\node[above] at (2,1){$P = (2,1)$};\n  \\end{tikzpicture}\n\\end{center}\nThe situation in $3$ dimensions is analogous. Here, the coordinate\nsystem has three axes, and each point is described by a triple of\ncoordinates, which we can write as $(x,y,z)$.  We can extend these\nideas beyond $n=3$. A coordinate system for $n$-dimensional space has\n$n$ axes, which we may call $x_1,\\ldots,x_n$ (as there are not enough\nletters in the alphabet to continue after $z$). A point of\n$n$-dimensional space is described by an ordered $n$-tuple\n$(x_1,\\ldots,x_n)$ of coordinates. For example, $P=(2,1,0,-1)$ is a\npoint in $4$-dimensional space which has $x_1$-coordinate $2$,\n$x_2$-coordinate $1$, and so on. While most people cannot really\npicture space beyond $3$ dimensions, it is easy to imagine tuples of\n$n$ real numbers. Thus, although we may not be able to ``see'' the\npoints in higher dimensions, we can still talk about their coordinates.\n\\bigskip\n\n\\noindent\\textbf{Vectors in $n$-dimensional space.}\nUnlike a point, which describes a location in a coordinate system, a\nvector%\n\\index{vector!geometric meaning} describes an {\\em offset}%\n\\index{offset} or a {\\em distance and direction}. We usually picture a\nvector as an arrow, starting at one point (called the \\textbf{tail}%\n\\index{tail of a vector}%\n\\index{vector!tail} of the arrow) and ending at another point (called\nthe \\textbf{tip}%\n\\index{tip of a vector}%\n\\index{vector!tip} of the arrow).\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.8]\n    \\draw[->, thick, blue](1,0)--+(1.5,1.125);\n    \\draw[->, thick, blue](2,1.2)--+(1.5,1.125);\n    \\draw[->, thick, blue](2,0)--+(1.5,1.125);\n    \\draw[->, thick, blue](0.7,0.7)--+(1.5,1.125);\n  \\end{tikzpicture}\n\\end{center}\nTwo vectors are considered equal if they have the same direction and\nlength. Thus, all four blue arrows in the above image describe exactly\nthe same vector. Mathematically, a vector in $2$-dimensional space is\ndescribed as an offset in the $x$-direction and an offset in the\n$y$-direction.  For example, a certain vector $\\vect{v}$ may be\ndescribed by the instruction: ``move $4$ units in the direction\nparallel to the $x$-axis, and move $3$ units in the direction parallel\nto the $y$-axis''. This situation is pictured here:\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.5]\n    \\draw[->, thick, blue](0,0) -- node[above]{$\\vect{v}$} +(4,3);\n    \\draw(0,0) -- node[below]{4 units} (4,0) -- node[right]{3 units} (4,3);\n  \\end{tikzpicture}\n\\end{center}\nThe numbers $4$ and $3$ are also called the $x$-component%\n\\index{component!of a vector} and the $y$-component of the\nvector. Notice that a point has ``coordinates'', but a vector has\n``components''. We write the components of a vector as an ordered\ncolumn within square brackets:\n$\\vect{v}=\\begin{mysmallmatrix}{c}\\scriptstyle4\\\\\\scriptstyle3\\end{mysmallmatrix}$. Note\nthat components can also be negative; for example, a negative\n$x$-component indicates to move left instead of right, and a negative\n$y$-component indicates to move down instead of up. The vector with\nall components equal to $0$ is called the \\textbf{zero vector}%\n\\index{zero vector}, and is written $\\vect{0}$.\n\nThe situation in $3$ dimensions is similar. Here, a vector is\ndescribed by three components, namely, its $x$-component,\n$y$-component, and $z$-component. The three components are written as\n$\\begin{mysmallmatrix}{c}\\scriptstyle x\\\\\\scriptstyle y\\\\\\scriptstyle\n  z\\end{mysmallmatrix}$. The same idea generalizes to $n$-dimensional\nvectors when $n$ is greater than $3$.\n\n\\begin{definition}{Column vectors and $\\R^n$}{column-vector}\n  A $n$-dimensional%\n  \\index{dimension!of a vector}%\n  \\index{vector!dimension} \\textbf{column vector}%\n  \\index{column vector}%\n  \\index{vector!column vector}, often simply called a \\textbf{vector}%\n  \\index{vector}, is an ordered list of $n$ real numbers, written as a\n  column within square brackets:\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x_1 \\\\\n      x_2 \\\\\n      \\vdots \\\\\n      x_n\n    \\end{mymatrix}.\n  \\end{equation*}\n  We write $\\R^n$%\n  \\index{Rn@$\\R^n$} for the set of all $n$-dimensional column\n  vectors. It is also known as \\textbf{$n$-dimensional Euclidean\n    space}%\n  \\index{Euclidean space}.\n\\end{definition}\nVectors are usually denoted by boldface lower-case letters such as\n$\\vect{v}$, $\\vect{w}$, $\\vect{a}$, $\\vect{b}$. Some people write a\nsmall arrow above the vector, but we do not do this here.\n\\bigskip\n\n\\noindent\\textbf{Points vs. vectors.}\nWhat is the relationship between points and vectors? Algebraically,\nthey seem to be almost the same thing, because a point $(x,y)$ and a\nvector\n$\\begin{mysmallmatrix}{c}\\scriptstyle x\\\\\\scriptstyle\n  y\\end{mysmallmatrix}$ are both an ordered pair of real numbers,\nwritten in a slightly different way. On the other hand, geometrically,\na point is a location in space, and has neither a length nor\ndirection, whereas a vector has length and direction, but is not fixed\nat any particular location. Indeed, to convince yourself that despite\nthe similarity in their notation, points and vectors are different\nkinds of objects, imagine that we moved the origin of the coordinate\nsystem to a different location. Then the coordinates of all the points\nwould change, whereas the components of all the vectors would remain\nthe same. To describe the components of a vector, we require axes and\na scale, but no origin. To describe the coordinates of a point, we\nrequire axes, a scale, and an origin.  \\bigskip\n\n\\noindent\\textbf{Vectors from points.}\nIf $Q$ and $P$ are two points in $n$-dimensional space, we can define\na \\textbf{vector from $Q$ to $P$}%\n\\index{vector!from a point to a point}. This vector is written\n$\\longvect{QP}$, and is described by the arrow whose tail is at $Q$\nand whose tip is at $P$, as in the following picture:\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.55]\n    \\draw[fill] (0,0) circle [radius=1.8pt] node[below]{$Q$};\n    \\draw[fill] (4,0.5) circle [radius=1.8pt] node[below]{$P$};\n    \\draw[thick, blue, ->](0,0) -- node[above, pos=0.45]{$\\longvect{QP}$} (4,0.5);\n  \\end{tikzpicture}\n\\end{center}\nIf the point $Q$ has coordinates $(q_1,\\ldots,q_n)$ and the point $P$\nhas coordinates $(p_1,\\ldots,p_n)$, then the components of\n$\\longvect{QP}$ are\n\\begin{equation*}\n  \\longvect{QP} =\n  \\begin{mymatrix}{c}\n    p_1 - q_1 \\\\\n    \\vdots    \\\\\n    p_n - q_n\n  \\end{mymatrix}.\n\\end{equation*}\nAn important special case of this is the case when the point $Q$ is\nthe origin. The following definition is concerned with that situation.\n\n\\begin{definition}{The position vector of a point}{position-vector}\n  Let $P$ be a point in $n$-dimensional space. The \\textbf{position\n    vector}%\n  \\index{position vector} of $P$ is the vector\n  $\\vect{p} = \\longvect{0P}$ whose tail is at the origin and whose tip\n  is at $P$.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.6]\n      \\draw[<->](2,0,0)--(0,0,0)--(0,2,0);\n      \\draw[fill] (0,0) circle [radius=1.8pt] node[below]{$0$};\n      \\draw[fill] (3,2) circle [radius=1.8pt] node[below]{$P$};\n      \\draw[thick, blue, ->](0,0) -- node[above left]{$\\vect{p}$} (3,2);\n    \\end{tikzpicture}\n  \\end{center}\n  If the point $P$ has coordinates $(p_1,\\ldots,p_n)$, then the\n  components of the position vector are\n  \\begin{equation*}\n    \\vect{p} =\n    \\begin{mymatrix}{c}\n      p_1    \\\\\n      \\vdots \\\\\n      p_n\n    \\end{mymatrix}.\n  \\end{equation*}\n  Thus, the coordinates of a point are the same as the components of\n  its position vector. For this reason, the position vector is also\n  sometimes called the \\textbf{coordinate vector}%\n  \\index{coordinate vector} of $P$.\n\\end{definition}\n\n\\noindent\\textbf{Points from vectors.} Conversely, given any vector\n$\\vect{p}$, we may find a point $P$ that has $\\vect{p}$ as its\nposition vector. To do so geometrically, we first have the move the\nvector $\\vect{p}$ around until its tail is at the origin. The point\n$P$ will then be located at its tip.\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.8]\n    \\draw[<->](2,0,0)--(0,0,0)--(0,2,0);\n    \\draw[fill] (0,0) circle [radius=1.8pt] node[below]{$0$};\n    \\draw[fill] (3,2) circle [radius=1.8pt] node[below]{$P$};\n    \\draw[thick, blue, ->](-2,1) -- node[above left]{$\\vect{p}$} +(3,2);\n    \\draw[thick, blue, ->](2.5,0.5) -- node[below right]{$\\vect{p}$} +(3,2);\n    \\draw[thick, blue, ->](0,0) -- node[above left]{$\\vect{p}$} +(3,2);\n  \\end{tikzpicture}\n\\end{center}\nAlgebraically, if the vector $\\vect{p}$ has components\n\\begin{equation*}\n  \\vect{p} =\n  \\begin{mymatrix}{c}\n    p_1    \\\\\n    \\vdots \\\\\n    p_n\n  \\end{mymatrix},\n\\end{equation*}\nthen the point $P$ will have coordinates $(p_1,\\ldots,p_n)$. This is\njust the opposite process of Definition~\\ref{def:position-vector}.\n\nSo although we went to some lengths to point out that vectors and\npoints are different geometric objects, as soon as an origin of a\ncoordinate system has been fixed, we can always talk about a point by\ntalking about its coordinate vector. We will systematically do so, and\neventually the distinction between a point and its coordinate vector\nwill become blurred, so that we will be able to talk about $\\R^n$ as\n``a set of points'' or ``a set of vectors'' interchangeably.  \\bigskip\n\n\\noindent\\textbf{Equality of vectors.}\nTwo vectors are equal%\n\\index{equality!of vectors}%\n\\index{vector!equality} precisely when all corresponding components\nare equal. In symbols, if\n\\begin{equation*}\n  \\vect{u} =\n  \\begin{mymatrix}{c}\n    u_1 \\\\\n    \\vdots \\\\\n    u_n\n  \\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\vect{v} =\n  \\begin{mymatrix}{c}\n    v_1 \\\\\n    \\vdots \\\\\n    v_n\n  \\end{mymatrix},\n\\end{equation*}\nthen $\\vect{u}=\\vect{v}$ if and only if $u_1=v_1$ and $u_2=v_2$ and\n\\ldots and $u_n=v_n$.\n\\bigskip\n\n\\noindent\\textbf{Notation.}\nIn the text, it is often awkward to write column vectors, because they\ntake up so much space. To save space, we sometimes use a superscript\n``$T$'' to denote a column vector. For example, we write\n$\\begin{mymatrix}{rrr}1&2&3\\end{mymatrix}^T$, or sometimes\n$\\mat{1, 2, 3}^T$, to denote the vector\n\\begin{equation*}\n  \\begin{mymatrix}{c}\n    1 \\\\\n    2 \\\\\n    3 \\\\\n  \\end{mymatrix}.\n\\end{equation*}\nThe letter ``$T$'' stands for ``transpose''. To transpose a vector\nmeans to turn a row into a column or vice versa.\n\n% ----------------------------------------------------------------------\n\n", "meta": {"hexsha": "08947ac2a97d2ef3c8e5ff692957b0a11041782d", "size": 12404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-PointsAndVectors.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-PointsAndVectors.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-PointsAndVectors.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 41.2093023256, "max_line_length": 88, "alphanum_fraction": 0.683972912, "num_tokens": 4011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290698, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6923286958116353}}
{"text": "\\subsection{Dynamic Time Warping} \\label{dynamic_time_warping}\nDynamic Time Warping (DTW) is a widely used and robust distance measure for time series, \\textit{allowing similar shapes\nto match even if they are out of phase in the time axis} \\cite{keogh2002exact}. The following explanation to calculate\nthe DTW distance is based on \\cite{sart2010accelerating}.\n\nGiven are two time series $Q = (q_1,\\allowbreak q_2,\\allowbreak \\dots,\\allowbreak q_i,\\allowbreak \\dots,\\allowbreak q_l)$\nwith length $l$, $C = (c_1,\\allowbreak c_2,\\allowbreak \\dots,\\allowbreak c_j,\\allowbreak \\dots,\\allowbreak c_k)$ with\nlength $k$ over the domain set $\\mathbb{U}$ and a distance measure function $d$ with\n$d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$. Calculating the DTW distance between the two time series $Q$ and $C$\ncan be achieved by calculating a matrix $M$ of size $l \\times k$ with the following rule.\n\\begin{equation} \\label{eq:dtw}\n    M_{i, j} = \\begin{cases}\n        d(q_i,c_j) & \\text{if } i = 1 \\wedge j = 1\\\\\n        M_{i,j-1} + d(q_i,c_j) & \\text{if } i = 1 \\wedge j \\neq 1\\\\\n        M_{i-1,j} + d(q_i,c_j) & \\text{if } i \\neq 1 \\wedge j = 1\\\\\n        min(M_{i-1,j}, M_{i-1,j-1}, M_{i,j-1}) + d(q_i,c_j) & \\text{if } i \\neq 1 \\wedge j \\neq 1\n    \\end{cases}\n\\end{equation}\nThe DTW distance between the two time series $Q$ and $C$ is the entry $M_{l,k}$ of the resulting matrix.\n\\begin{equation}\n    DTW(Q, C) = M_{l,k}\n\\end{equation}\nThe detection of the warping path as a result of the backtracking is irrelevant for the aim of this bachelor thesis.\nFigure \\ref{fig:dynamictimewarping} illustrates DTW for two time series $Q$ and $C$ that contain recorded data from one\nacceleration sensor. DTW, shown as above, has time and space complexity of $\\mathcal{O}(lk)$. When ignoring the\nwarping path as a result the algorithm can easily reduce the space complexity to $\\mathcal{O}(min(l, k))$. This can be\nachieved by keeping only the last important entries in space that are necessary to calculate the final entry $M_{l,k}$\nof the matrix.\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/dynamictimewarping/path.dat};\n                            \\addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-100,\n                                    ymax=0,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};\n                                \\addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/dynamictimewarping/matrix_path.dat};\n                            \\end{axis}\n                        \\end{tikzpicture} \\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-100,\n                                ymax=0,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n    \\caption{Two time series $Q$ and $C$ containing recorded and compressed data from one acceleration sensor. 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:dynamictimewarping}\n\\end{figure}\n\n\\input{background_and_notation/dynamic_time_warping/sakoe-chiba_band.tex}\n\\input{background_and_notation/dynamic_time_warping/time_series_normalization.tex}\n", "meta": {"hexsha": "4b9c0de1ed045565b35798ee570a047ca38dcc97", "size": 6554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/background_and_notation/dynamic_time_warping.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "bachelor-thesis/background_and_notation/dynamic_time_warping.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bachelor-thesis/background_and_notation/dynamic_time_warping.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 56.0170940171, "max_line_length": 137, "alphanum_fraction": 0.4967958499, "num_tokens": 1525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6923286834501724}}
{"text": "\n\\subsection{Regression}\n\nWe can simply regress outcomes on variables, including treatment.\n\nThis assumes treatment effects are constant.\n\nThis also assumes that outcomes \\(y_{1i}\\) and \\(y_{0i}\\) are independent of \\(D_i\\), conditional on \\(X\\).\n\nIf we are missing variables in \\(X\\) then we will have biased estimates.\n\nThis also assumes the effects of \\(X\\) are linear.\n\nWe assume: \\(E[y_{0i}|\\mathbf x_{i}, D_i]=\\mathbf x_i \\theta\\).\n\n", "meta": {"hexsha": "8b9cba7feab25ea7649891e95df280aa903524f0", "size": 439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treatmentHomo/03-01-regression.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treatmentHomo/03-01-regression.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treatmentHomo/03-01-regression.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4375, "max_line_length": 107, "alphanum_fraction": 0.7175398633, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6922331364006051}}
{"text": "\\section{The Model | Methodology} \\label{sec:03}\nDefine the model, give some equations and explain them:\n\\begin{equation}\nTSO(\\tau_1, \\tau_2) = \\int_{\\tau_1}^{\\tau_2} \\frac{WPL(s)}{C(s)}ds = \\int_{\\tau_1}^{\\tau_2} U(s)ds.\n\\end{equation}\n\n\\subsection{Subsection}\nAdd aligned equations:\n\\begin{align}\nU_t &= \\Lambda_t + Y_t\\\\\nd\\Lambda_t &= \\Lambda_t dt\\\\\nY_t &= {\\bf b}^\\top {\\bf X}_t\\\\\nd{\\bf X}_t &= ({\\bf A}{\\bf X}_t +  {\\bf e}_p\\sigma_t\\theta_t)dt +  {\\bf e}_p \\sigma_t dB_t^{\\theta},\n\\end{align}\nwith matrices and vectors\n\\[{\\bf A} = \\left( \\begin{array}{ccccc}\n0 & 1 & 0 & \\ldots& 0\\\\\n0 & 0 & 1 & \\ddots& \\vdots\\\\\n\\vdots &  & \\ddots & \\ddots &0\\\\\n0 & \\ldots & \\ldots & 0 & 1\\\\\n-\\alpha_p & -\\alpha_{p-1} & \\ldots & & -\\alpha_1 \\end{array} \\right)\\quad {\\bf e}_p =  \\left( \\begin{array}{c} \n0\\\\\n0\\\\\n\\vdots\\\\\n0\\\\\n1\n\\end{array} \\right) \\]\nIntegrals:\n\\begin{align*}\nU_s &=  \\int_t^{s}\\tilde{U_u}^{\\eta_1}\\exp({\\bf A}(s-u)){\\bf x}du +  \\int_t^{s}\\tilde{U_u}^{\\eta_1}\\exp({\\bf A}(s-u))\\Lambda_u du   \\\\\n&+  \\int_t^{s}\\tilde{U_u}^{\\eta_1}\\exp({\\bf A}(s-u)) {\\bf e}_p \\sigma_u dB_u^\\theta\n\\end{align*}\n\n\n", "meta": {"hexsha": "2143c537ebdaab67ef4367c76480b4e8bcb1a323", "size": 1098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Template/ch03.tex", "max_stars_repo_name": "awdesch/Topics_in_Finance", "max_stars_repo_head_hexsha": "aa3e353f2ac506f8122fbce6a4c001c63fd0c46f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Template/ch03.tex", "max_issues_repo_name": "awdesch/Topics_in_Finance", "max_issues_repo_head_hexsha": "aa3e353f2ac506f8122fbce6a4c001c63fd0c46f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Template/ch03.tex", "max_forks_repo_name": "awdesch/Topics_in_Finance", "max_forks_repo_head_hexsha": "aa3e353f2ac506f8122fbce6a4c001c63fd0c46f", "max_forks_repo_licenses": ["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.3714285714, "max_line_length": 134, "alphanum_fraction": 0.5919854281, "num_tokens": 499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6922331314593935}}
{"text": "\\section{Segment coordinate transform}\n\nFor the following calculations we define the following points of the wing segment: $\\vec p_1$ is the innermost point of the leading edge, $\\vec p_2$ the outermost point of the leading edge, $\\vec p_3$ the innermost point of the trailing edge, and $\\vec p_4$ the outermost point of the trailing edge.\n\n\\begin{figure}[htb]\n  \\centering\n  \\includegraphics[width = 10cm]{gfx/bilinearSurface}\n\t\\caption{Mathematically, a the chord face of a wing segment is a bilinear surface}\n\t\\label{fig:bilin_surf}\n\\end{figure}\n\n\\subsection{Parametrization of the chord surface}\n\nFor simplicity, lets rename $\\alpha := \\eta$, $\\beta := \\xi$. Each point $\\vec p$ on the surface then be expressed by\n\n\\begin{align}\n\\vec p(\\alpha, \\beta) &= \\left( \\vec {p_1} (1-\\alpha) + \\vec {p_2} \\alpha \\right) (1-\\beta) \\\\\n                  &+ \\left( \\vec {p_3} (1-\\alpha) + \\vec {p_4} \\alpha \\right) \\beta \\\\\n                  &= \\alpha \\underbrace{(-\\vec p_1 + \\vec p_2)}_{\\vec a} + \\beta\\underbrace{(-\\vec p_1 + \\vec p_3)}_{\\vec b} + \\alpha \\beta \\underbrace{(\\vec p_1 - \\vec p_2 - \\vec p_3 + \\vec p_4)}_{\\vec c} + \\underbrace{\\vec p_1}_{\\vec d}\n\\label{eq:param}\n\\end{align}\n\nThis formula defines the transformation between the segments coordinates $(\\alpha, \\beta)$ to cartesian coordinates $(x, y, z)$. Mathematically, this form is called called bilinear surface. To sum up:\n\n\\begin{align}\n\\vec p (\\alpha, \\beta) &= \\alpha   \\vec a + \\beta \\vec b + \\alpha \\beta \\vec c + \\vec d \\, , \\quad\n\\textrm{with}\\\\\n\\vec a &= -\\vec p_1 + \\vec p_2 \\nonumber \\\\\n\\vec b &= -\\vec p_1 + \\vec p_3 \\nonumber \\\\\n\\vec c &= \\vec p_1 - \\vec p_2 - \\vec p_3 + \\vec p_4 \\nonumber \\\\\n\\vec d &= \\vec p_1 \\nonumber\n\\end{align}\n\n\\subsection{Projecting a point onto the chord surface}\nThe projection of a point $\\vec x$ onto the surface is defined as the point $\\vec p(\\alpha, \\beta)$ so that $\\vec p (\\alpha, \\beta) - \\vec x$ is orthogonal to the surface. Mathematically it can be shown, that the orthogonality requirement is equivalent to finding the point $\\vec p(\\alpha, \\beta)$ that has a smallest distance to $\\vec x$. \\par\nThis is of course an optimization problem which can be defined as:\n\\begin{equation}\n\\min_{\\alpha, \\beta} f(\\alpha, \\beta) := \\min_{\\alpha, \\beta} \\Vert \\vec p(\\alpha, \\beta) - \\vec x \\Vert^2\n\\end{equation}\nThis is an almost quadratic problem (it is only quadratic, if $\\vec c = 0$) and can be thus solved with Newton's optimization method. Newtons method is an iterative procedure. In our case, we can adapt it as follows:\n\n\\begin{algorithm}[htb]\n %\\SetAlgoLined\n $(\\alpha; \\beta)_0 \\leftarrow (0; 0)$ \\\\\n $k \\leftarrow 0$\\\\\n \\While{not converged}{\n  $(\\alpha, \\beta)_{k+1} \\leftarrow (\\alpha, \\beta)_{k} - s [\\nabla^2 f(\\alpha, \\beta) ]^{-1} \\cdot \\vec \\nabla f(\\alpha, \\beta),\\quad \\textrm{with}\\, s \\leq 1$\\\\\n  $k \\leftarrow k + 1$ \\\\\n }\n \\caption{Newton's optimization algorithm}\n\\end{algorithm}\n\n \nIn order to perform this projection, we need the gradient $\\vec \\nabla f(\\alpha, \\beta)$ and the hessian matrix $\\nabla^2 f(\\alpha, \\beta)$, which are defined as the first and second order derivative of $f(\\alpha, \\beta)$. \\\\\n\n\\paragraph{Gradient}\nUsing the chain rule, we get for the gradient:\n\\begin{equation}\n\\vec \\nabla f(\\alpha, \\beta) = 2 J_p (\\alpha, \\beta)^T \\cdot (\\vec p(\\alpha, \\beta) - \\vec x),\n\\end{equation}\nwhere $J_p (\\alpha, \\beta)$ is the Jacobian of $\\vec p(\\alpha, \\beta)$. In components this is:\n\\begin{align}\n\\frac {\\partial f} {\\partial \\alpha}(\\alpha, \\beta) &= 2 \\left(\\frac{\\partial \\vec p}{\\partial \\alpha}(\\alpha, \\beta)\\right)^T (\\vec p(\\alpha, \\beta) - \\vec x) \\nonumber\\\\\n&= 2\\left( \\vec a + \\beta \\vec c \\right)^T (\\vec p(\\alpha, \\beta) - \\vec x) \n\\end{align}\nand\n\\begin{align}\n\\frac {\\partial f} {\\partial \\beta}(\\alpha, \\beta) &= 2 \\left(\\frac{\\partial \\vec p}{\\partial \\beta}(\\alpha, \\beta)\\right)^T (\\vec p(\\alpha, \\beta) - \\vec x) \\nonumber\\\\\n&= 2\\left( \\vec b + \\alpha \\vec c \\right)^T (\\vec p(\\alpha, \\beta) - \\vec x) \n\\end{align}\n\n\\paragraph{Hessian}\nA derivative of the gradient gives as the Hessian matrix:\n\\begin{align}\n\\nabla^2 f(\\alpha, \\beta) = 2 J_p (\\alpha, \\beta)^T J_p (\\alpha, \\beta) + 2 (\\nabla^2 \\vec p (\\alpha, \\beta))^T \\cdot (\\vec p(\\alpha, \\beta) - \\vec x)\n\\end{align}\nThus for the diagonal elements of the Hessian, we get\n\\begin{align}\n\\frac {\\partial^2 f} {\\partial \\alpha^2}(\\alpha, \\beta) &= 2(\\vec a + \\beta \\vec c)^T(\\vec a + \\beta \\vec c) = 2 \\Vert \\vec a + \\beta \\vec c \\Vert^2 \\\\\n\\frac {\\partial^2 f} {\\partial \\beta^2}(\\alpha, \\beta) &= 2(\\vec b + \\alpha \\vec c)^T(\\vec b + \\alpha \\vec c) = 2 \\Vert \\vec b + \\alpha \\vec c \\Vert^2 \n\\end{align}\nand for the off-diagonals\n\\begin{align}\n\\frac {\\partial^2 f} {\\partial \\alpha \\partial  \\beta}(\\alpha, \\beta) \n&= 2(\\vec a + \\beta \\vec c)^T(\\vec b + \\alpha \\vec c) + 2(\\vec p (\\alpha, \\beta) - \\vec x)^T \\vec c.\n\\end{align}\nDue to the symmetry of the Hessian, we get the same result for the other off-diagonal element $\\frac {\\partial^2 f} {\\partial \\beta \\partial  \\alpha}(\\alpha, \\beta)$.", "meta": {"hexsha": "b5194297fdc75d4f345f8366830d1845e8618056", "size": 5014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tiglGuide/segmentMath.tex", "max_stars_repo_name": "cfsengineering/tigl", "max_stars_repo_head_hexsha": "abfbb57b82dc6beac7cde212a4cd5e0aed866db8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 171, "max_stars_repo_stars_event_min_datetime": "2015-04-13T11:24:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T00:56:38.000Z", "max_issues_repo_path": "doc/tiglGuide/segmentMath.tex", "max_issues_repo_name": "cfsengineering/tigl", "max_issues_repo_head_hexsha": "abfbb57b82dc6beac7cde212a4cd5e0aed866db8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 620, "max_issues_repo_issues_event_min_datetime": "2015-01-20T08:34:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:05:33.000Z", "max_forks_repo_path": "doc/tiglGuide/segmentMath.tex", "max_forks_repo_name": "cfsengineering/tigl", "max_forks_repo_head_hexsha": "abfbb57b82dc6beac7cde212a4cd5e0aed866db8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2015-02-09T13:33:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T04:52:51.000Z", "avg_line_length": 57.632183908, "max_line_length": 344, "alphanum_fraction": 0.6559633028, "num_tokens": 1717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6921886120909514}}
{"text": "  The basic examples relevant to us are:\n  \\begin{description}\n    \\item[0-dim: ]\n      A 0-dimensional topological space is a collection of points.\n    \\item[1-dim: ]\n      A 1-dimensional topological space is a graph - a collection of edges glued together at vertices.\n    \\item[2-dim: ]\n      A 2-dimensional topological is a graph with faces.\n  \\end{description}\n  All the maps between topological spaces that we'll consider will be continuous.\n  A map $f:X \\rightarrow Y$ between topological spaces is a \\emph{homeomorphism} if it has a continuous inverse.\n\n  \\begin{ex}\n    Examples of covering spaces.\n    \\todo{examples of covering spaces.}\n  \\end{ex}\n\n  \\begin{mdframed}\n    Assume from now on that all our spaces are \\emph{path-connected}.\n  \\end{mdframed}\n\n\n\n\n\n\n\n\n\n\n  \\subsection{Covering spaces}\n\n  $X$ is called a \\emph{cover} of $Y$.\n  The set $\\pi^{-1}(y)$ is called the fiber over $y$\n  If $\\cali$ is finite then $\\pi$ is called a \\emph{finite cover}.\n\n  \\begin{qbox}\n    Show that every cover of a graph (resp. 2-graph) is a graph (resp. 2-graph).\n  \\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n  \\subsection{Group action}\n  A left group action of $G$ on a space $X$, denoted $G \\groupaction X$, is a collection of continuous maps\n  \\begin{align*}\n    g \\cdot - : X &\\longrightarrow X\\\\\n    x &\\longmapsto gx\n  \\end{align*}\n  satisfying $ex = x$, where $e$ is the identity element in $G$ and $g(hx) = (gh)x$ for all $g,h \\in G$.\n  \\begin{definition}\n    We say that $G \\groupaction X$ is \\emph{properly discontinous} if every point $x \\in X$ has an open neighborhood $U$ such that\n    \\begin{equation*}\n      g U \\cap U = \\varnothing\n    \\end{equation*}\n    for all $g \\in G$.\n  \\end{definition}\n  \\begin{qbox}\n    Show that if $g U \\cap U = \\varnothing$ for all $g \\in G$ then $g U \\cap hU = \\varnothing$ for all $g,h \\in G$.\n  \\end{qbox}\n  \\begin{ex}\n    add example of maps between $S^1$: rotation and reflection.\n    \\todo{add example of maps between $S^1$: rotation and reflection.}\n  \\end{ex}\n  \\begin{qbox}\n    Show that if $G \\groupaction X$ is free then $X \\rightarrow G \\backslash X$ is a cover.\n  \\end{qbox}\n", "meta": {"hexsha": "0d03af0671eadb5a52d0b5e2b531c1294f24348c", "size": 2114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.2.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": "01.2.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": "01.2.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": 27.8157894737, "max_line_length": 130, "alphanum_fraction": 0.6579943236, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825659156573, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.6921399049191247}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\subsection{Exercise 8}\n\nFor clarity, we denote with Greek indices those ranging from 1 to \\(N\\), the size of the vector of data; and with Latin indices those ranging from 1 to \\(M\\), the number of templates.\n\nWe are assuming that the data have a Gaussian distribution with a covariance matrix \\(C\\), and we are modelling their mean \\(\\mu_\\alpha  \\) as a sum of templates \\(t_{i \\alpha}\\) with coefficients \\(A_i\\):\n%\n\\begin{align}\n\\mu _\\alpha = t_{i \\alpha } A_i\n\\,,\n\\end{align}\n%\nwhere the Einstein summation convention has been used. \nTherefore, the likelihood is proportional to \n%\n\\begin{align}\n\\mathscr{L}(d_\\alpha | A_i) \\propto \\exp(- \\frac{1}{2} \\qty(d_\\alpha - A_{i} t_{i \\alpha }) C^{-1}_{\\alpha \\beta } \n\\qty(d_\\beta - A_j t_{j \\beta }))\n\\,.\n\\end{align}\n\nThe normalization only depends on the covariance matrix \\(C_{\\alpha \\beta }\\), which we assume is fixed.\nTherefore, maximizing the likelihood\\footnote{Which is equivalent to maximizing the posterior if we are using a flat prior.} is equivalent to minimizing the \\(\\chi^2\\), which reads \n%\n\\begin{align}\n\\chi^2 = \\qty(d_\\alpha - A_{i} t_{i \\alpha }) C^{-1}_{\\alpha \\beta } \n\\qty(d_\\beta - A_j t_{j \\beta })\n\\,.\n\\end{align}\n\nWe want to minimize this as the amplitudes vary: therefore, we set the derivative with respect to \\(A_k\\) to zero,\\footnote{The fact that the stationary point we will find is indeed a minimum can be checked by looking at the second derivative of \\(\\chi^2\\): \n%\n\\begin{align}\n\\pdv[2]{\\chi ^2}{A_k}{A_m} = 2 t_{k \\alpha } C_{\\alpha \\beta }^{-1} t_{m \\beta } \n\\,,\n\\end{align}\n%\nand recalling that the inverse of the covariance matrix is positive definite.\n}\n%\n\\begin{align}\n\\pdv{\\chi^2}{A_k} = -2 t_{k \\alpha } C^{-1}_{\\alpha \\beta } \\qty(d_\\beta - A_j t_{j \\beta }) = 0\n\\,,\n\\end{align}\n%\nwhich means that \n%\n\\begin{align}\nt_{k \\alpha } C^{-1}_{\\alpha \\beta } d_\\beta = (t_{k \\alpha } C^{-1}_{\\alpha \\beta }  t_{j \\beta }) A_j\n\\,,\n\\end{align}\n%\na linear system of \\(M\\) equations (indexed by \\(k\\)) in the \\(M\\) variables \\(A_j\\). \nIf we denote the evaluations of bilinear forms in the data (\\(N\\)-dimensional) space with brackets, as \\(a_\\alpha C_{\\alpha \\beta } b_\\beta \\overset{\\text{def}}{=} (a | C |b)\\), this reads \n%\n\\begin{align}\n(t | C^{-1} | d)_k &= (t | C^{-1} | t)_{kj} A_j  \\\\\n\\qty[(t | C^{-1} | t)^{-1}]_{mk} (t | C^{-1} | d)_k  &=\n\\underbrace{ \\qty[(t | C^{-1} | t)^{-1}]_{mk}\n(t | C^{-1} | t)_{kj}}_{= \\delta_{mj}} A_j = A_m  \\\\\nA_m &= \\qty[(t | C^{-1} | t)^{-1}]_{mk} (t | C^{-1} | d)_k\n\\,, \\label{eq:template-fitting}\n\\end{align}\n%\nwhere the inverse of \\((t | C^{-1} | t)\\) is to be computed in the \\(M\\)-dimensional vector space. \n\n\\subsection{Exercise 9}\n\nOur model for the mean value is in the form \\(\\mu (\\Theta , A) = A \\overline{x}(\\Theta )\\), where \\(\\overline{x}\\) is a generic function of \\(\\Theta \\), while \\(A\\) is our scale parameter.\\footnote{This is not specified in the problem, but it seems natural to think that \\(\\abs{\\overline{x}(\\Theta )}\\) is a constant for varying \\(\\Theta \\). } \nOur likelihood then reads \n%\n\\begin{align}\n\\mathscr{L}(x | \\Theta , A) = \\underbrace{\\frac{1}{(2\\pi )^{N/2} \\sqrt{\\det C}}}_{B_1 }\n\\exp(- \\frac{1}{2} (x - A \\overline{x}(\\Theta ))^{\\top} C^{-1} (x- A \\overline{x}(\\Theta )))\n\\,.\n\\end{align}\n\nIf the priors for both \\(A\\) and \\(\\Theta \\) are flat, this corresponds to the joint posterior \\(P (\\Theta , A | x)\\). \nWe want to marginalize over \\(A\\), which amounts to integrating over it: dropping the dependence on \\(\\Theta \\) of \\(\\overline{x}\\) and defining \\(V = C^{-1}\\) we find\n%\n\\begin{align}\nP(\\Theta | x) \n&= B_1  \\int \\exp(- \\frac{1}{2} (x - A \\overline{x})^{\\top} V (x- A \\overline{x})) \\dd{A}  \\\\\n&= B_1  \\int \\exp(- \\frac{1}{2} \\qty(x^{\\top} V x -2 A \\overline{x}^{\\top} V x + A^2 \\overline{x}^{\\top} V \\overline{x})) \\dd{A} \n\\marginnote{Used the symmetry of \\(V\\).}\n\\,.\n\\end{align}\n\nThe amplitude being negative makes little sense in a typical physical context, however the Gaussian integral can be done analytically only over the whole of \\(\\mathbb{R}\\).\n\nIn order to get analytical results, here we will marginalize by integrating over negative amplitudes as well (\\(A \\in \\mathbb{R}\\)); the last figure (\\ref{fig:marginalization}) will show how only integrating over positive amplitudes only would have looked (by numerical calculation) in a simple case.\nIn general if one wishes to perform the integral over \\(A \\in (0, + \\infty )\\) the tabulated values of the error function may be used.\n\nApplying the formula for the single-variable Gaussian integral \\eqref{eq:single-variable-gaussian-integral} (the bilinear forms are all evaluated to yield scalars, we are only integrating over the scalar \\(A\\)!) we then get \n%\n\\begin{align}\nP(\\Theta | x) &= \\underbrace{B_1  \\exp(- \\frac{1}{2} x^{\\top} V x )}_{B_2 } \n\\exp( \\frac{1}{2} \\frac{(\\overline{x}^{\\top} V x)^2}{(\\overline{x}^{\\top} V \\overline{x})}) \n\\sqrt{ \\frac{2 \\pi }{\\overline{x}^{\\top} V \\overline{x}}}  \\\\\n&= B_2 \\sqrt{\\frac{2 \\pi}{\\overline{x}^{\\top}V \\overline{x}}}\n\\exp( \\frac{1}{2} \\frac{\\overline{x}^{\\top} \\Omega \\overline{x}}{\\overline{x}^{\\top}V \\overline{x}})\n\\,,\n\\end{align}\n%\nwhere we defined the bilinear form \\(\\Omega = V x x^{\\top} V^{\\top}\\).\\footnote{With explicit indices, \\(\\Omega_{im} = V_{ij} x_j x_k V_{km}\\).}\n\n% We can observe that all information about the scale of \\(\\overline{x}\\) has been lost: if we map \\(\\overline{x} \\to A \\overline{x}\\) the argument of the exponential does not change, therefore the only change comes from the factor in front, and the posterior \\(P\\) is mapped to \\(P / A\\). \n\n\\subsubsection{An application of posterior marginalization in this fashion}\n\nLet us consider a simple example of this as a sanity check: suppose that \\(x\\) is two-dimensional, and \\(\\overline{x}(\\Theta ) = (\\cos \\Theta , \\sin \\Theta )^{\\top}\\); further, suppose that \\(V\\) is diagonal, so that \n%\n\\begin{align}\nV = \\left[\\begin{array}{cc}\n\\sigma_x^{-2} & 0 \\\\ \n0 & \\sigma _y^{-2}\n\\end{array}\\right]\n\\,.\n\\end{align}\n\nAlso, suppose that the observed data parameter is \n%\n\\begin{align}\nx = A_x \\left[\\begin{array}{c}\n\\cos \\varphi  \\\\ \n\\sin \\varphi \n\\end{array}\\right]\n\\,.\n\\end{align}\n\nThen, the multiplicative constant in front of the marginalized posterior reads \n%\n\\begin{align}\nB_2 = B_1 \\exp(- \\frac{1}{2} A_x^2 \\qty( \\frac{\\cos^2\\varphi}{\\sigma^2_x} + \\frac{\\sin^2\\varphi}{\\sigma^2_y}))\n\\,;\n\\end{align}\n%\nwhile the bilinear form \\(\\Omega \\) is \n%\n\\begin{align}\n\\Omega &= A_x^2\n\\left[\\begin{array}{cc}\n\\sigma_x^{-2} & 0 \\\\ \n0 & \\sigma _y^{-2}\n\\end{array}\\right]\n\\left[\\begin{array}{cc}\n\\cos^2 \\varphi  & \\cos \\varphi \\sin \\varphi  \\\\ \n\\cos \\varphi \\sin \\varphi  & \\sin^2 \\varphi \n\\end{array}\\right]\n\\left[\\begin{array}{cc}\n\\sigma_x^{-2} & 0 \\\\ \n0 & \\sigma _y^{-2}\n\\end{array}\\right]  \\\\\n&= A_x^2\\left[\\begin{array}{cc}\n\\cos^2 \\varphi / \\sigma_x^{4} & \\cos \\varphi \\sin \\varphi / \\sigma_x^2 \\sigma _y^2 \\\\ \n\\cos \\varphi \\sin \\varphi / \\sigma_x^2 \\sigma _y^2 & \\sin^2 \\varphi / \\sigma_y^{4}\n\\end{array}\\right]\n\\,.\n\\end{align}\n\nThen, when we  evaluate the marginalized posterior we will find something in the form\n%\n\\begin{align}\nP(\\Theta | x) &= B_1 \\sqrt{2 \\pi } \\qty( \\frac{\\cos^2\\Theta }{\\sigma_x^2} + \\frac{\\sin^2 \\Theta }{\\sigma _y^2})^{-1/2}\n\\exp( A_x^2 F(\\Theta , \\varphi ))\n\\,,\n\\end{align}\n%\nwhere \\(F (\\Theta , \\varphi )\\) is some function whose specific form does not really matter.\\footnote{For completeness, here is the full expression: \n%\n\\begin{align}\n\\begin{split}\nF(\\Theta , \\varphi ) &=\n- \\frac{1}{2} \\qty( \\frac{\\cos^2\\varphi}{\\sigma^2_x} + \\frac{\\sin^2\\varphi}{\\sigma^2_y})+  \\\\\n&\\phantom{=}\\ \n+ \n\\qty( \\frac{\\cos^2 \\Theta}{\\sigma _x^2} + \\frac{\\sin^2 \\Theta }{\\sigma _y^2})^{-1}\n\\qty[ \n    \\frac{\\cos^2 \\Theta \\cos^2 \\varphi }{\\sigma _x^{4}}\n    +2\\frac{\\cos \\Theta \\sin \\Theta \\cos \\varphi \\sin \\varphi  }{\\sigma _x^{2} \\sigma _y^{2}}\n    +\\frac{\\sin^2 \\Theta \\sin^2 \\varphi }{\\sigma _y^{4}}\n]\n\\,.\n\\end{split}\n\\end{align}\n%\n}\n\nThe amplitude of the observed data vector, \\(A_x\\), appears in a rather simple way, as a multiplicative prefactor in the exponent: it can affect the shape of the distribution, but not its mean.\nSpecifically, we can see that scaling \\(A_x\\) is equivalent to scaling \\(\\sigma _x\\) and \\(\\sigma _y\\) simultaneously in the opposite direction --- this is rather intuitive, since the angular size of the distribution as seen from the origin is smaller if it is further away. \n\n% Therefore, we see that by marginalizing over \\(A\\) we have ``forgotten'' any scaling information about \\(x\\). \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/marginalization.pdf}\n\\caption{Marginalization: the left plot shows the full likelihood in terms of \\(A\\) and \\(\\Theta \\); the middle plot shows the result of marginalization as shown in the previous calculation (the posterior as a function of \\(\\Theta \\)); the right plot shows the result of the more physically meaningful marginalization over \\(A \\in (0, + \\infty )\\) only.\nHere the likelihood is a diagonal Gaussian with \\(\\sigma _x = \\num{1.2}\\) and \\(\\sigma _y = \\num{1.8}\\), centered in \\(A_x = \\num{2.5}\\) and \\(\\varphi = \\SI{1}{rad}\\).}\n\\label{fig:marginalization}\n\\end{figure}\n\n\\subsubsection{Likelihood marginalization}\n\nSo far we have considered the posterior \\(P(\\Theta | x)\\), the marginalized posterior, a function of the parameter(s) \\(\\Theta \\); however we may also be interested in the marginalized likelihood \\(\\mathscr{L}(x | \\Theta )\\), whose expression is the same as the one we found for \\(P(\\Theta | x)\\).\nLet us write it in a way which makes the dependence on \\(x\\) more explicit: \n%\n\\begin{align} \\label{eq:marginalized-likelihood}\n\\mathscr{L}(x | \\Theta ) = \\underbrace{B_1 \\sqrt{\\frac{2 \\pi }{\\overline{x}^{\\top} V \\overline{x}}}}_{B_3 } \\exp(- \\frac{1}{2} x^{\\top} V x + \n\\frac{1}{2}\n\\frac{(\\overline{x}^{\\top} V x)^2}{\\overline{x}^{\\top} V \\overline{x}})\n\\,,\n\\end{align}\n%\nwhich can be simplified by making use of the fact that the best-fit template amplitude we found in the last exercise (equation \\eqref{eq:template-fitting}) can be applied here, with the single template \\(t = \\overline{x}\\), the single amplitude \\(A\\), the data \\(d = x\\), and the inverse covariance matrix \\(C^{-1}= V\\): the fitting value for \\(A \\) is \n%\n\\begin{align}\n\\hat{A} = \\frac{\\overline{x}^{\\top} V x}{\\overline{x}^{\\top} V \\overline{x}}\n\\,;\n\\end{align}\n%\ntherefore the likelihood is \n%\n\\begin{align}\n\\mathscr{L}(x | \\Theta ) = B_3 \\exp(- \\frac{1}{2} x^{\\top} V x +\n\\frac{1}{2}\n \\hat{A} \\overline{x}^{\\top} V x)\n\\,.\n\\end{align}\n\nThis can be rewritten in the canonical MVN form by making use of the matrix square completion formula \\eqref{eq:square-completion}, with \\(A = -V\\) and \\(\\vec{b}^{\\top} = \\hat{A} \\overline{x}^{\\top} V\\): \n%\n\\begin{align}\n\\begin{split}\n- \\frac{1}{2} x^{\\top} V x + \\frac{1}{2} \\hat{A} \\overline{x}^{\\top} V x\n&= - \\frac{1}{2} \n\\qty(x - \\frac{1}{2} V^{-1} \\hat{A} (\\overline{x}^{\\top} V)^{\\top})^{\\top} V\n\\qty(x - \\frac{1}{2} V^{-1} \\hat{A} (\\overline{x}^{\\top} V)^{\\top}) \\\\\n&\\phantom{=}\\ \n+ \\frac{1}{8} \\hat{A}^2 (\\overline{x}^{\\top} V) V^{-1} (\\overline{x}^{\\top} V)^{\\top}  \n\\end{split}\\\\\n&= - \\frac{1}{2} \n\\qty(x - \\frac{1}{2} \\hat{A} \\overline{x})^{\\top}\nV \n\\qty(x - \\frac{1}{2} \\hat{A} \\overline{x})\n+ \n\\frac{1}{8} \\hat{A}^2 \\overline{x}^{\\top} V \\overline{x}\n\\,.\n\\end{align}\n\nTherefore, the marginalized likelihood reads \n%\n\\begin{align}\n\\mathscr{L}(x | \\Theta ) = B_3 \\exp( \\frac{1}{8} \\hat{A}^2 \\overline{x}^{\\top} V \\overline{x}) \\exp(- \\frac{1}{2} \\qty(x - \\frac{1}{2} \\hat{A} \\overline{x})^{\\top} V \\qty( \\frac{1}{2} x - \\hat{A} \\overline{x}))\n\\,.\n\\end{align}\n\nWe must be careful with this expression: it looks like a multivariate normal in \\(\\overline{x}\\), however \\(\\hat{A}\\) is not in general independent of it.\nIf neither the estimate for \\(\\hat{A}\\) nor the expression \\(\\overline{x}^{\\top} V \\overline{x}\\) vary significantly in the range of \\(\\overline{x}\\) we are interested in, then we can consider this expression for the likelihood as Gaussian in \\(x\\), or as a marginalized posterior which is Gaussian in \\(\\overline{x}\\).\n\n% A clearer way to see that this is indeed still a MVN is to come back to the original expression \\eqref{eq:marginalized-likelihood}, and to write it as \n% %\n% \\begin{align}\n% \\mathscr{L} (x | \\Theta ) = B_3 \\exp(- \\frac{1}{2} x^{\\top} \\qty(V - \\frac{V \\overline{x} \\overline{x}^{\\top} V}{\\overline{x}^{\\top} V \\overline{x}}) x )\n% \\,,\n% \\end{align}\n% %\n% thus showing that the likelihood is a \\emph{zero-mean} MVN with covariance given by \n% %\n% \\begin{align}\n% \\qty[V - \\frac{V \\overline{x} \\overline{x}^{\\top} V}{\\overline{x}^{\\top} V \\overline{x}}]^{-1}\n% \\,.\n% \\end{align}\n\n\n\\end{document}\n", "meta": {"hexsha": "aae5a63c9982dd2da1f874058cc70d7f6d151ebd", "size": 12693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostat_homework/exercises_89.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_89.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_89.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.6582733813, "max_line_length": 353, "alphanum_fraction": 0.6487827937, "num_tokens": 4376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.6921399045140744}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\nWe set $c=1$.\n\nHere we will often use (anti)symmetrization of indices, which makes some calculations much easier. The idea of symmetrization is to sum over all permutation of the selected indices, with a minus sign for the odd permutation if the case of anti symmetrization. So, for instance, \\(F_{\\mu \\nu }\\) can be antisymmetrized into \\(F_{[\\mu \\nu ]} = \\frac[i]{1}{2} \\qty(F_{\\mu \\nu }- F_{\\nu \\mu })\\) and symmetrized into \\(F_{(\\mu \\nu )}= \\frac[i]{1}{2} \\qty(F_{\\mu \\nu } + F_{\\nu \\mu })\\).\n\nThe factor \\(\\frac[i]{1}{2} \\) is in general \\(1/n!\\), where \\(n\\) is the number of antisymmetrized indices. This is included because in general we will be summing \\(n!\\) terms, and we want to write things like: ``\\(F_{\\mu \\nu }\\) is antisymmetric means \\(F_{\\mu \\nu} = F_{[\\mu \\nu ]}\\)'', so we need to rescale the sum to make it into an average.\n\nThe general formulas are then: \n%\n\\begin{subequations}\n\\begin{align}\n  F_{[\\mu_{1} \\dots \\mu_{n}]} &= \\frac{1}{n!} \\sum _{\\sigma  \\in \\mathfrak{S}_n} \\sign{\\sigma} F_{\\sigma (\\mu_1)\\dots \\sigma(\\mu_n)} \\\\\n  F_{(\\mu_{1} \\dots \\mu_{n})} &= \\frac{1}{n!} \\sum _{\\sigma  \\in \\mathfrak{S}_n}F_{\\sigma (\\mu_1)\\dots \\sigma(\\mu_n)}\n\\,,  \n\\end{align}\n\\end{subequations}\n%\nwhere \\(\\mathfrak{S}_n\\) is the \\emph{symmetric group} of permutations of \\(n\\) elements, and the sign of a permutation \\(\\sigma \\in \\mathfrak S_n\\) is \\(\\pm 1\\), depending on the parity of pair swaps that are needed to get that configuration (we fix (\\(\\sign(\\mathbb{1}) = 1\\))). \n\nIf we want to symmetrize indices which are not next to each other, we will denote the end of the (anti)symmetrized indices by a vertical bar.\n\nA useful mnemonic for the Riemann tensor: we'd like to write the formula \\(R = \\partial \\Gamma  + \\Gamma \\Gamma \\) keeping the indices in the same order on either side: the way to do it is this: \n%\n\\begin{align}\n  R^{\\mu }_{\\alpha \\beta \\gamma } = -2 \\qty(\n    \\Gamma^{\\mu }_{\\alpha [\\beta , \\gamma ]}\n    + \\Gamma^{\\sigma }_{\\alpha [\\beta } \\Gamma^{\\mu }_{\\gamma ] \\sigma }\n  )\n\\,,\n\\end{align}\n%\nwhich is much easier to remember: one writes down the indices in the same order, adds a dummy index in the second Christoffel symbol on the last term, which must be contracted with the upper index on the other symbol. \n\nThen, since the Riemann tensor is antisymmetric in the last two indices, we antisymmetrize in those. \n\nAnother useful relation is given by \n%\n\\begin{align}\n  R_{\\mu \\nu } = \\partial_{\\gamma } \\Gamma^{\\gamma }_{\\mu \\nu } - \\Gamma^{\\alpha }_{\\mu \\beta } \\Gamma^{\\beta }_{\\nu \\alpha } - \\nabla_{\\mu } \\qty(\\partial_{\\nu } \\log \\sqrt{ \\abs{g}})\n\\,,\n\\end{align}\n%\nwhere \\(g\\) is the determinant of the metric. \n\n\\section{Sheet 1}\n\n\\subsection{Lorentz transformations }\n\n\\subsubsection{Inverses}\n\nWe can consider a Lorentz boost with velocity $v$ in the $x$ direction, and we look at its representation in the $(t, x)$ plane (since the $y$ and $z$ directions are unchanged). Its matrix expression looks like:\n%\n\\begin{equation}\\label{LorBoost}\n    \\Lambda = \\begin{bmatrix}\n        \\gamma & -v \\gamma \\\\\n        -v \\gamma & \\gamma\n    \\end{bmatrix}\\,,\n\\end{equation}\n%\nwhere $\\gamma = 1 / \\sqrt{1 - v^2}$. The inverse of this matrix can be computed using the general formula for a 2x2 matrix:\n\n\\begin{equation}\n    A^{-1}=\n    \\begin{bmatrix}\n        a & b \\\\\n        c & d\n    \\end{bmatrix}^{-1}\n    =\n    \\frac{1}{\\det(A)}\n        \\begin{bmatrix}\n        d & -b \\\\\n        -c & a\n    \\end{bmatrix}\\,.\n\\end{equation}\n\nThe determinant of $\\Lambda $ is equal to $\\gamma^2 (1-v^2) = 1$, therefore the inverse matrix is:\n%\n\\begin{equation}\n    \\Lambda = \\begin{bmatrix}\n        \\gamma & v \\gamma \\\\\n        v \\gamma & \\gamma\n    \\end{bmatrix}\\,.\n\\end{equation}\n\n\\subsubsection{Invariance of the spacetime interval}\n\nOur Lorentz transformation is\n\n\\begin{subequations}\n\\begin{align}\n    \\dd{t}' &= \\gamma (\\dd{t} - v \\dd{x}) \\\\\n    \\dd{x}' &= \\gamma (-v\\dd{t} + \\dd{x}) \\\\\n    \\dd{y}' &= \\dd{y} \\\\\n    \\dd{z}' &= \\dd{z}\n\\end{align}\n\\end{subequations}\n%\nand we wish to prove that the spacetime interval, defined by $\\dd{s^2} = \\eta_{\\mu\\nu} \\dd{x^\\mu}\\dd{x^\\nu}$ is preserved: $\\dd{s'\\,^2} = \\dd{s^2}$.\nLet us write the claimed equality explicitly:\n%\n\\begin{subequations}\n\\begin{align}\n    -\\dd{t^2} + \\dd{x^2}+ \\dd{y^2}+ \\dd{z^2}\n    &= \\gamma (\\dd{t} - v \\dd{x})\n\\end{align}\n\\end{subequations}\n\n\n\\subsubsection{Tensor notation pseudo-orthogonality}\n\nThe invariance of the spacetime interval $\\dd{s'\\,^2} = \\dd{s^2}$ can be also written as \\(\\eta_{\\mu\\nu} \\dd{x^\\mu} \\dd{x^\\nu} = \\eta_{\\mu\\nu} \\dd{x'\\,^\\mu} \\dd{x'\\,^\\nu}\\). By making the primed differentials explicit we have:\n%\n\\begin{equation}\n  \\eta_{\\mu\\nu} \\dd{x^\\mu} \\dd{x^\\nu}\n  =\n  \\eta_{\\mu\\nu} \\tensor{\\Lambda}{^\\mu_\\rho} \\dd{x^\\rho} \\tensor{\\Lambda}{^\\nu_\\sigma} \\dd{x^\\sigma} \\,,\n\\end{equation}\n%\nbut the dummy indices on the LHS can be changed to \\(\\rho\\) and \\(\\sigma\\), so that both sides are proportional to  \\(\\dd{x^\\rho}\\dd{x^\\sigma}\\). Doing this we get:\n%\n\\begin{equation}\n  \\eta_{\\rho\\sigma}\n  =\n  \\eta_{\\mu\\nu} \\tensor{\\Lambda}{^\\mu_\\rho} \\tensor{\\Lambda}{^\\nu_\\sigma}\n  =\\tensor{(\\Lambda^\\top)}{_\\rho^\\mu} \\eta_{\\mu\\nu} \\tensor{\\Lambda}{^\\nu_\\sigma} \\,,\n\\end{equation}\n%\nor, in matrix form, \\(\\eta = \\Lambda^\\top \\eta \\Lambda\\).\n\n% \\subsubsection{Pseudo orthogonality}\n% Defining $dx^\\mu=(cdt,dx,dy,dz)^T$, and $dx_\\mu=(cdt,dx,dy,dz)=\\eta_{\\mu\\nu}dx^\\nu$, we will have\n\\begin{subequations}\n% \\begin{align}\n% &ds^2=dx^\\mu dx_\\mu=dx^\\mu\\eta_{\\mu\\nu}dx^\\nu\\nonumber\\\\\n% &\\dd{s,^{2\\prime}}=dx^{\\mu\\prime} dx_\\mu'=dx^{\\mu\\prime}\\eta_{\\mu\\nu}dx^{\\nu\\prime}=dx^\\rho\\Lambda_\\rho^\\mu\\eta_{\\mu\\nu}dx^\\sigma\\Lambda_\\sigma^\\nu\n% \\end{align} and $\\dd{s'\\,^2} = \\dd{s^2}$ is equivalent to our thesis.\n\\end{subequations}\n\n% \\subsubsection{Pseudo orthogonality by matrix product}\n\n% Let $\\Lambda$ be the Lorentz transformation in \\eqref{LorBoost}.bIn this case we have\n\\begin{subequations}\n% \\begin{align}\n%     \\Lambda ^T\\eta\\Lambda=& \\begin{bmatrix}\n%         \\gamma & -v \\gamma & 0 & 0\\\\\n%         -v \\gamma & \\gamma & 0 & 0\\\\\n%         0 & 0 & 1 & 0\\\\\n%         0 & 0 & 0 & 1\\\\\n%     \\end{bmatrix}\\cdot \\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}\\cdot \\begin{bmatrix}\n%         \\gamma & -v \\gamma & 0 & 0\\\\\n%         -v \\gamma & \\gamma & 0 & 0\\\\\n%         0 & 0 & 1 & 0\\\\\n%         0 & 0 & 0 & 1\\\\\n%     \\end{bmatrix}=\\nonumber\\\\\n%      =&\\begin{bmatrix}\n%         -\\gamma & -v \\gamma & 0 & 0\\\\\n%         v \\gamma & \\gamma & 0 & 0\\\\\n%         0 & 0 & 1 & 0\\\\\n%         0 & 0 & 0 & 1\\\\\n%     \\end{bmatrix}\\cdot\n%     \\begin{bmatrix}\n%         \\gamma & -v \\gamma & 0 & 0\\\\\n%         -v \\gamma & \\gamma & 0 & 0\\\\\n%         0 & 0 & 1 & 0\\\\\n%         0 & 0 & 0 & 1\\\\\n%     \\end{bmatrix}=\\nonumber\\\\\n%     =& \\begin{bmatrix}\n%         -\\gamma^2+v^2\\gamma^2 & 0 & 0 & 0\\\\\n%         0 & -v^2\\gamma^2+\\gamma^2 & 0 & 0\\\\\n%         0 & 0 & 1 & 0\\\\\n%         0 & 0 & 0 & 1\\\\\n%     \\end{bmatrix}=\\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}=\\eta\n% \\end{align}\n\\end{subequations}\n% Where we used the fact that $\\gamma^2(1-v^2)=\\frac{\\gamma^2}{\\gamma^2}=1$.\n\n\\subsubsection{Explicit pseudo-orthogonality}\n\nFor simplicity but WLOG we consider a boost in the \\(x\\) direction with velocity \\(v\\) and Lorentz factor \\(\\gamma\\). The matrix expression to verify is:\n%\n\\begin{subequations}\n\\begin{align}\n  \\begin{bmatrix}\n  \\gamma    & - v \\gamma  \\\\\n    -v \\gamma & \\gamma\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    -1 & 0 \\\\\n    0 & 1\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\gamma & -v \\gamma \\\\\n     -v \\gamma&  \\gamma\n  \\end{bmatrix}\n  &\\overset{?}{=}\n  \\begin{bmatrix}\n  -1   & 0 \\\\\n  0   & 1\n\\end{bmatrix} \\\\\n  \\begin{bmatrix}\n  \\gamma    & - v \\gamma  \\\\\n    -v \\gamma & \\gamma\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    -\\gamma & v \\gamma \\\\\n    -v \\gamma&  \\gamma\n  \\end{bmatrix}\n  &\\overset{?}{=}\n  \\begin{bmatrix}\n  -1   & 0 \\\\\n  0   & 1\n\\end{bmatrix} \\\\\n  \\begin{bmatrix}\n  -\\gamma^2 + \\gamma^2 v^2    & v \\gamma^2 - v \\gamma^2  \\\\\n    v \\gamma^2 -v \\gamma^2 & -v\\gamma^2 +\\gamma^2\n  \\end{bmatrix}\n  &=\n  \\begin{bmatrix}\n  -1   & 0 \\\\\n  0   & 1\n\\end{bmatrix}\\,,\n\\end{align}\n\\end{subequations}\n%\nwhich by \\(\\gamma^2 = 1/ (1-v^2)\\) confirms the validity of the expression.\n\n\\subsection{Muons}\n\n\\subsubsection{Nonrelativistic approximation}\n\nThe survival probability is given by \\(\\mathbb{P} (t) = \\exp(-t/ \\SI{2.2e-6}{s})\\). If the ground is \\( h =\\SI{15}{km} \\) away, then the muon will reach it in \\(t = h/v = \\SI{15}{km} / (0.995c) \\approx \\SI{5.03e-05}{s}\\), therefore \\(\\mathbb{P}(t) \\approx \\num{1.2e-10} \\).\n\n\\subsubsection{Relativistic effects: ground perspective}\n\nThe observer on the ground will see the muon having to traverse the whole \\(h = \\SI{15}{km} \\), but the muon's time will be dilated for them by a factor \\(\\gamma_v \\approx 10\\): therefore the survival probability\nwill be \\(\\mathbb{P}(t) = \\exp(- t / (\\gamma_v \\times \\SI{2.2e-6}{s})) \\approx 0.1\\).\n\n\n\\subsubsection{Relativistic effects: muons perspective}\n\nThe muons in their system will observe length contraction, which can be calculated by applying a Lorentz boost, by a factor \\(\\gamma_v \\approx 10\\): therefore the survival probability\nwill be \\(\\mathbb{P}(t) = \\exp(- t / (\\gamma_v \\times \\SI{2.2e-6}{s})) \\approx 0.1\\).\nThis result is the same of the one predicted by the ground observer: the relativity principle is respected.\n\n\n\\subsection{Radiation}\n\n\\subsubsection{New angle}\nIn the source frame the radiation velocity components are \\( u_x' = \\cos\\theta', u_y' = \\sin\\theta' \\). From the composition of velocities we obtain:\n\n\\begin{subequations}\n\\begin{align}\n    u_y = \\sin\\theta &= \\frac{\\dd{y}}{\\dd{t}} = \\frac{\\dd{y'}}{\\gamma_v(\\dd{t'} + v\\dd{x'})} = \\frac{\\sin\\theta'}{\\gamma_v(1+v\\cos\\theta')} \\\\\n    u_x = \\cos\\theta &= \\frac{\\dd{x}}{\\dd{t}} = \\frac{\\gamma_v(\\dd{x'} + v\\dd{t'})}{\\gamma_v(\\dd{t'} + v\\dd{x'})} = \\frac{\\cos\\theta' + v}{1+v\\cos\\theta'}\\,,\n\\end{align}\n\\end{subequations}\n%\nhence:\n%\n\\begin{equation}\n\\frac{1}{\\tan\\theta} = \\frac{\\gamma_v}{\\tan\\theta'} + \\frac{\\gamma_vv}{\\sin\\theta'} \\,.\n\\end{equation}\n\n\\subsubsection{Angle plot and relevant limits}\nSee the jupyter notebook in the \\texttt{python} folder for plots.\nFor $v=0$ we have $\\theta=\\theta'$ as we expected, while for $v=1$, $\\theta = 0$.\n\n\\subsubsection{Radiation speed invariance}\n\nAre the components of the velocity, which we called \\(\\sin \\theta\\) and \\(\\cos \\theta \\), actually normalized? Let us check:\n\n\\begin{subequations}\n\\begin{align}\n    \\sin^2\\theta + \\cos^2\\theta &= \\frac{(\\frac{\\sin\\theta'}{\\gamma_v})^2 + (\\cos\\theta' + v)^2}{(1 + v\\cos\\theta')^2} \\\\ \n    &= \\frac{(1-v^2)\\sin^2\\theta' + \\cos^2\\theta' + v^2 + 2v\\cos\\theta'}{(1 + v\\cos\\theta')^2} \\\\\n    &= \\frac{1+v^2(1-\\sin\\theta')+2v\\cos\\theta'}{(1 + v\\cos\\theta')^2} = 1 \\,,\n\\end{align}\n\\end{subequations}\n%\ntherefore the square modulus of the speed of the radiation is still \\(c\\), as we could have assumed earlier.\n\n\\subsubsection{Isotropic emission}\n\nSince the angular distribution of emission varies when changing inertial reference, we might suppose that every system in relative motion respect to $O$ with $v\\neq 0$ observes nonisotropic emission.\n\nThis can be seen by noticing that for $v\\simeq 1$ we have that in the observer system there is almost only emission at an angle $\\theta = 0$.\nIn general, since there is a Lorentz \\(\\gamma\\) factor multiplying a function of the angle in the radiation emission frame \\(O'\\), the cotangent of the angle in the observation frame \\(O\\) must get larger and larger as the relative velocity \\(v\\) increases, therefore the radiation gets compressed towards angles with large cotangents: \\(\\theta\\sim 0\\).\n\nSee the jupyter notebook in the \\texttt{python} folder for interactive plots :)\n\n\\end{document}\n\n", "meta": {"hexsha": "84d653059cc7931ce17d7ee03fb4aca9a7b441fb", "size": 11915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/gr_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": "ap_first_semester/gr_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": "ap_first_semester/gr_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": 39.0655737705, "max_line_length": 482, "alphanum_fraction": 0.6161141418, "num_tokens": 4280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.6921399022639777}}
{"text": "\\chapter{Position, Speed, and Acceleration}\n\nLet's say that you get in a car and drive 45 km/hour for two hours in\none direction. Your position will be $2 \\times 45 = 90$ km from where\nyou started. We could plot your velocity and your position during those two hours:\n\n\\includegraphics[width=0.7\\textwidth]{speed_simple.pdf}\n\n\\includegraphics[width=0.7\\textwidth]{position_simple.pdf}\n\nNotice that the area under the velocity line is $2 \\times 45$, the total\ndistance traveled. In fact, at any point in your drive, your distance\nfrom the starting point is equal to the area under the velocity line.\n% Diagram needed, explain why it is the area under the curve\n% KA: https://www.khanacademy.org/math/ap-calculus-ab/ab-diff-contextual-applications-new/ab-4-2/e/interpret-motion-graphs\n\nWhat if you:\n\\begin{itemize}\n\\item drive 50 km/hour for 45 minutes\n\\item rest for 15 minutes\n\\item continue driving 90 km/hour for 45 minutes\n\\item turn around and head back at 120 km/hour for 15 minutes\n\\end{itemize}\n% KA: https://www.khanacademy.org/math/ap-calculus-ab/ab-diff-contextual-applications-new/ab-4-2/v/one-dimensional-motion-with-calculus\n\nNow the graphs look a little more complex:\n\n\\includegraphics[width=0.7\\textwidth]{speed_stops.pdf}\n\n\\includegraphics[width=0.7\\textwidth]{position_stops.pdf}\n\nIt is still true that at any time, the position is equal to the\narea under the graph up to that time. Notice that when the velocity goes\nnegative, it is subtracting from the position( negative velocity means going backwards).\n\nNotice that when you are going faster, the slope of the position line\nis steeper. When the slope of the position is negative, the velocity is\nnegative( the velocity is decreasing).\n\nSo we end up with two important ideas:\n\\begin{itemize}\n\\item If we plot the velocity, the position is equal to the area under the speed line.\n\\item If we plot the position, the velocity is equal to the slope of the position line.\n\\end{itemize}\n\n\\section{Acceleration}\n\nJust as velocity represents the change in position over time,\nacceleration represents the change in velocity over time.\n\nWhat if, from a standstill, you accelerate smoothly 45 km/hour each\nhour for one hour and 30 minutes. Then you stop accelerating for 15\nminutes. Then you decelerate (or accelerate toward home) at a rate of\n80 km/hour each hour for 15 minutes. Now we have three graphs: the\nacceleration, the velocity, and the position\n\n\\includegraphics[width=0.7\\textwidth]{acceleration_asp.pdf}\n\n\\includegraphics[width=0.7\\textwidth]{speed_asp.pdf}\n\n\\includegraphics[width=0.7\\textwidth]{position_asp.pdf}\n\n\nSo we end up with two important ideas:\n\\begin{itemize}\n\\item If we plot the acceleration, the velocity is equal to the area under the acceleration line.\n\\item If we plot the velocity, the acceleration is equal to the slope of the velocity line.\n\\end{itemize}\n\n\\section{Differentiation and Integration}\n\nIn calculus, we talk a lot about differentiation and integration.\n\n\\textit{Differentiation} is just finding the slope of a curve. If you give me\nthe position of an object over time, I will differentiate that to find\nits velocity at any time. Once I have the velocity, I can differentiate\nagain to find its acceleration.\n\n\\textit{Integration} is just finding the area under a curve. If you give me\nthe initial speed of an object and its acceleration over time, I will\nintegrate that to find its velocity at any time. Then, if I know the\nstarting point of the object, I can integrate the velocity to find its\nposition at any time.\n\n\\section{Speed vs. Velocity, Distance vs. Position}\n\nIn casual conversation, we tend to use the words ``speed'' and\n``velocity'' interchangeably. When we are solving problems, velocity\nrepresents the change in position, and that can be pretty specific,\nlike ``It's velocity is 12 m/s due west.'' Velocity, then, can\nhave a direction and can be negative.\n\nSpeed, is just the magnitude of the velocity, like ``12 m/s''.  It is\na number that is never negative.\n% ADD: Scalar vs Vector\n% KA: https://www.khanacademy.org/math/ap-calculus-ab/ab-diff-contextual-applications-new/ab-4-2/v/one-dimensional-motion-with-calculus\n\nSimilarly, a position can be quite complex like ``12 km east of\nLexington.'' Distance is just a number, like ``12 km from Lexington.''\nDistance is never negative.\n\n% ADD: Distance vs Displacement\n% KA: https://www.khanacademy.org/science/high-school-physics/one-dimensional-motion-2/distance-displacement-and-coordinate-systems-2/a/relative-motion-review-article\n\n% ADD: Example interpreting all three graphs\n% Video: https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DnUb7xfkc0Ac&psig=AOvVaw2cfsXUgDpoYlIRVKcfIMJP&ust=1653186487204000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCPCdxtzF7_cCFQAAAAAdAAAAABAD\n", "meta": {"hexsha": "0ee0149b42295507d7c6dcb0b1a727a367e8388e", "size": 4773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/position-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/position-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/position-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": 44.6074766355, "max_line_length": 222, "alphanum_fraction": 0.7852503666, "num_tokens": 1245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.6921398884029905}}
{"text": "% -----------------------------------------------------------------------------------\n% Section   : \n% -----------------------------------------------------------------------------------\n\n\\def\\H{\\mathcal{H}}              \n\\def\\Z{\\pmb{Z}}       \n\\def\\X{\\pmb{X}}       \n\\def\\ci{c_{i,\\H_i(x)}}       \n\n\n\n\\section*{Proof}\n\n\nIntuitively, the the use of different hash functions ensures that \nactually the chance of getting an estimate that is far from some average is small. Now we make this precise. Since for every $x$ the value $\\ci \\ge f_x$ we have:\n\t\\[\n\t\tf_x \\le \\widetilde{f_x} = min(c_{1,\\H_1(x),...c_{d,\\H_d(x)}})\n\t\\]\n\n\n We show that if $w = \\frac{2}{\\eps}$ and $d = \\log_2 \\frac{1}{\\delta}$ then:\n\t\\[\n\t\t\\Pr { f_x \\le \\widetilde{f_x} \\le f_x + \\eps m } \\ge 1 - \\delta\n\t\\]\n\nLet's define random variables $\\Z_1,\\ldots,\\Z_d$ so that $\\ci = f_x + \\Z_i$, where\n\t\\[\n\t\t\\Z_i = \\sum_{y \\ne x, \\H_i(y) = \\H_i(x)} f_y,\n\t\\]\n\ndefine $\\pmb{X}_{i,h} = 1$ if $\\H_i(y) = \\H_i(x)$ and $0$ otherwise:\n\n\t\\[\n\t\t\\Z_i = \\sum_{y \\ne x} f_y \\pmb{X}_{i,y},\n\t\\]\n\nSince the $\\H$'s are pairwise independent, we have:\n\t\\[\n\t\t\\E{\\Z_i} = \\sum_{y\\ne x} f_y \\E{ X_{i,y}} = \\sum_{y\\ne x} Pr{ \\H_i(x) = \\H_i(x)} \\le \\frac{m}{w},\n\t\\]\n\nby Markov we have:\n\t\\[\n\t\t\\Pr{ \\Z_i \\ge \\eps m} \\le \\frac{1}{w \\eps} = \\frac{1}{2}..\n\t\\]\t\n\n\nSince all $Z_i$ are independent, we know:\n\n\t\\[\n\t\t\\Pr{Z_i \\ge \\eps m \\quad \\forall \\quad 1 \\le i \\le d} \\le \\bigg(\\frac{1}{d}\\bigg)^d = \\delta.\n\t\\]\n\nNow with probability $1-\\delta$ there is some $j$ so that $Z_j \\le \\eps m$:\n\t\n\t\\[\n\t\t\\widetilde{f_x} = min (f_x + \\Z_1, ..., f_x + Z_d) \\le f_x + \\eps m.\n\t\\]\n\nHence CountMin esitmates $x$ up to $+/- \\eps m$ with space $O \\bigg(  \\frac{log m log \\frac{1}{\\delta}}{\\eps} \\bigg)$.\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "e0f21ca001ecb86e931641c4f22cc07c47f84127", "size": 1725, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sec/proof.tex", "max_stars_repo_name": "lingxiao/CIS700", "max_stars_repo_head_hexsha": "0aebe925c4b413a37d75b8c782a3dffd53851f8a", "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/sec/proof.tex", "max_issues_repo_name": "lingxiao/CIS700", "max_issues_repo_head_hexsha": "0aebe925c4b413a37d75b8c782a3dffd53851f8a", "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/sec/proof.tex", "max_forks_repo_name": "lingxiao/CIS700", "max_forks_repo_head_hexsha": "0aebe925c4b413a37d75b8c782a3dffd53851f8a", "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": 23.9583333333, "max_line_length": 161, "alphanum_fraction": 0.4962318841, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6921213648138278}}
{"text": "\\chapter{Diffusion}\n\\emph{Stochastic everything.}\n\\newpage\n\n\\section{Describing a Diffusion}\n    \\subsection{An Aside on Calculus}\n        Let's forget all the stochastic process stuff for a moment. Consider a smooth function $F(x):\\mathbb{R} \\mapsto \\mathbb{R}$. Let $f(x) = F'(x)$.\n\n        \\[ F(x) = F(0) + \\int_0^x f(t) \\mathrm{d}t \\]\n\n        So any smooth function $F$ can be uniquely determined by an initial condition and its derivative $f$.\n\n        \\[ f(x) = \\lim_{h \\to 0} \\frac{F(x+h)-F(x)}{h} \\]\n\n        That is, we assume the function can be approximated by a linear function near $x$. This gives us some food for thought.\n\n    \\subsection{Diffusion}\n        Similar to the derivative in calculus, we assume an arbitrary stochastic process can be approximated by a Brownian motion near $x+h$ as $h \\to 0$.\n        \\[ x_h = x_0 + \\mu(x_0)h + \\sigma(x_0)\\sqrt{h}z_1 \\quad z_1 \\sim \\mathcal{N}(0,1) \\]\n\n        As is in calculus, we define two functions $\\mu(t,x)$ and $\\sigma^2(t,x)$,\n        \\[ \\mu(t,x) = \\lim_{h \\to 0}\\frac{1}{h}\\mathbb{E}[X(t+h)-X(t)|X(t)=x] \\]\n        \\[ \\sigma^2(t,x) = \\lim_{h \\to 0}\\frac{1}{h}\\var[X(t+h)-X(t)|X(t)=x] \\]\n\n        A diffusion is \\textbf{Time-homogeneous} if $\\mu(t,x) = \\mu(x)$, $\\sigma(t,x) = \\sigma(x)$. From now on we only consider time-homogeneous diffusions.\n\n        Once $\\mu$ and $\\sigma$ are specified,\n        \\begin{equation}\\label{eq:DiffusionDE} \\mathrm{d}X_t = \\mu(t,X_t)\\mathrm{d}t + \\sigma(t,X_t)\\mathrm{d}W_t \\end{equation}\n        where intuitively $W_t$ is the ``movement of a Brownian motion in a very small interval of time''. But since a Brownian motion is not differentiable, defining $W_t$ is non-trivial. However, if we take the integral of Equation \\ref{eq:DiffusionDE}.\n        \\[ X_t - X_0 = \\int_0^t \\mu(X_s)\\mathrm{d}s + \\int_0^t \\sigma(X_s)\\mathrm{d}W_s \\]\n        where\n        \\[ \\int_0^t \\sigma(X_s)\\mathrm{d}s \\]\n        is called the \\textbf{Ito's Integral}. Due to its complexity we will not give any further details on Ito's Integral, and we will not operate on it in the following parts.\n\n\n\\section{Langevin Dynamics}\n    \\emph{“大家听说过Langevin吗？肯定听说过。郎之万。--Chihao.”}\n    \\subsection{Recap: Gradient Descent}\n        Recall the update rule of Gradient Descent\n        \\[ X_t = X_{t-1} - \\eta\\nabla f(X_{t-1}) \\Longrightarrow X_t - X_{t-1} = -\\nabla f(X_{t-1})\\]\n\n        In the continuous case,\n        \\[ \\mathrm{d}X_t = -\\nabla f(X_t)\\mathrm{d}t \\]\n\n    \\subsection{Langevin Dynamics}\n        A \\textbf{Langevin Dynamics} is a continuous version of gradient descent, with an additional Gaussian noise\\footnote{“下降完了它还要抖一下--Chihao”}\n        \\[ \\mathrm{d}X_t = -\\nabla f(X_t)\\mathrm{d}t + \\sqrt{2}\\mathrm{d}W_t \\]\n\n        \\begin{theorem}[Convergence of Langevin Dynamics]\\label{thm:ConvergenceOfLangevinDynamics}\n            For any function $f$, $X_t \\sim p(X)$, where $p(X)$ is given by\n            \\[ p(x) = \\frac{e^{-f(x)}}{\\sum_x e^{-f(x)}} \\]\n        \\end{theorem}\n\n        The following sections will be devoted to the convergence analysis. The proofs will be given in 1D cases $X_t \\in \\mathbb{R}$, but the results apply to $\\mathbb{R}^n$. And we further asuume $\\sigma(X_t) \\in \\mathbb{R}$.\n\n    \\subsection{Fokker-Planck Equation}\n        Fokker-Planck Equation is the continuous version of Kolmogorov Forward Equation \\ref{eq:KolmogorovForwardEquation}.\n\n        Let $p(t,y)$ denote the density of $X_t = y$.\n\n        \\begin{equation}\\label{eq:Fokker-PlanckEquation}\n            \\frac{\\partial p(t,y)}{\\partial t} = - \\sum_{i=1}^n \\frac{\\partial \\mu_i(y)p(t,y)}{\\partial y_i} + \\frac{1}{2}\\sigma^2(y)\\sum_{i=1}^n\\frac{\\partial^2 p(t,y)}{\\partial y_i^2}\n        \\end{equation}\n        Where $y_i$ and $\\mu_i(y)$ denote the $i$-th element of vectory $y$ and $\\mu(y)$ respectively.\n\n        To prove \\ref{eq:Fokker-PlanckEquation}, we first introduce the backward probability. Fix $y \\in \\mathbb{R}^n$, let\n        \\[ q(t,x) \\triangleq p_{X_t}(y|X_0=x) \\]\n        Then\n        \\begin{equation}\\label{eq:Fokker-PlanckBackwardEq}\n            \\frac{\\partial q(t,x)}{\\partial t} = \\mu(x)\\sum_{i=1}^n \\frac{\\partial q(t,x)}{\\partial x_i} + \\frac{1}{2}\\sum_{i=1}^n\\frac{\\partial^2 \\sigma^2(x)q(t,x)}{\\partial x_i^2}\n        \\end{equation}\n\n        \\subsubsection{Proof of Backward Equation in 1D}\n            \\begin{align*}\n                \\partial_t q(t,x) &= \\mu(x)\\partial_xq(t,x) + \\frac{1}{2}\\sigma^2(x)\\partial_{xx}q(t,x)\n            \\end{align*}\n            We prove a more general case. Let $\\rho()$ be some function defined on the state space, then we define $g(t,x)$ by\n            \\[ g(t,x) = \\mathbb{E}_x[\\rho(X_t)] \\quad \\mathbb{E}_x[\\cdot]=\\mathbb{E}[\\cdot|X_0=x] \\]\n            Therefore\n            \\[ g(t+h,x) = \\mathbb{E}_x[\\rho(X_{t+h})] = \\mathbb{E}_x[\\mathbb{E}_x[\\rho(X_{t+h})|X_h]] = \\mathbb{E}_x[g(t, X_h)] \\]\n\n            \\begin{align*}\n                LHS &= \\lim_{h \\to 0}\\frac{1}{h}\\mathbb{E}_x[g(t,X_h) - g(t,x)]\\\\\n                &= \\lim_{h \\to 0}\\frac{1}{h}\\mathbb{E}_x[g'(t,x)(X_h - x) + \\frac{1}{2}g''(t,x)(X_h-x)^2 + o(h)]\\\\\n                &= \\mu(x)g'(t,x) + \\frac{1}{2}\\sigma^2(x)g''(t,x)\n            \\end{align*}\n\n            And our desired backward equation can be proved by letting $\\rho(z) = \\mathbb{I}[z \\le y]$ and take derivative w.r.t. $y$.\n            \\[ g(t,x) = \\mathbb{E}_x[\\rho(X_t)] = \\mathbb{P}_x[X_t \\le y] \\triangleq F(t,x,y) \\]\n\n            So $F(t,x,y)$ satisfies the backward equation, and notice that $\\partial_y F(t,x,y) = q(t,x)$, so simply take partial derivative of $F$ w.r.t. $y$ yields the desired result.\n\n        \\subsubsection{Proof of Forward Equation in 1D}\n            By Markov property,\n            \\[ g(s,y) = \\mathbb{E}[\\rho(X_{t+s})|X_t=y] \\]\n\n    \\subsection{Proof of Convergence}\n        Let the stationary distribution be $\\pi(x)$. Plug $\\pi(x)$ into Equation \\ref{eq:Fokker-PlanckEquation}.\n        \\[ 0 = -\\frac{\\partial}{\\partial x}\\left( f'(x) \\cdot \\pi(x) \\right) + \\frac{1}{2}\\frac{\\partial}{\\partial x}\\pi'(x)\\]\n\n        Therefore\n        \\[ \\pi'(x) = -f'(x)\\pi(x) \\]\n\n        This is an ordinary differential equation, with solution\n        \\[ \\pi(x) \\sim e^{-f} \\]\n\n    \\subsection{Convergence Analysis}\n        Suppose the function $f$ is $m$-strongly convex. Recall that an $m$-strongly convex function has a quadratic lower bound\n        \\[ f(y) \\ge f(x) + \\nabla f(x)^T(y-x) + \\frac{m}{2}(y-x)^T\\nabla^2f(x)(y-x) \\]\n\n        \\begin{theorem}\n            For an $m$-strongly convex $f$, the Langevin dynamics converges to its stationary distribution exponentially fast.\n\n            Let $x_t$, $y_t$ be two Langevin Dynamics,\n            \\[ \\mathbb{E}[\\|x_t-y_t\\|] \\le e^{-mt}\\|x_0-y_0\\| \\]\n        \\end{theorem}\n        \\begin{proof}\n            We construct a coupling. Let $X_t$ and $Y_t$ be two Langevin Dynamics, with the same Gaussian noise. Since they have the same noise, the remaining analysis is very similar to that of an ordinary gradient descent.\n\n            Consider $\\|x_t-y_t\\|^2$ . To show that it converges very fast, we only need to show that its derivative drops very fast. Thank you, continuity!\\footnote{``Everybody should be able to take the gradient of a quadratic function. -- Bo Jiang''}\n            \\begin{align*}\n                \\mathrm{d}\\|x_t-y_t\\|^2 &= 2\\left(\\frac{\\mathrm{d}}{\\mathrm{d}t}(x_t-y_t)^T(x_t-y_t)\\right)\\\\\n                &= 2(\\nabla f(y_t) - \\nabla f(x_t))^T(x_t-y_t)\n            \\end{align*}\n\n            By strong convexity\n            \\[ f(y_t) - f(x_t) \\ge \\nabla f(x_t)^T(y_t-x_t) + \\frac{m}{2}\\|x_t-y_t\\|^2 \\]\n            and\n            \\[ f(x_t) - f(y_t) \\ge \\nabla f(y_t)^T(x_t-y_t) + \\frac{m}{2}\\|x_t-y_t\\|^2 \\]\n\n            Add the two equations up\n            \\[ 0 \\ge (\\nabla f(y_t) - \\nabla f(x_t))^T(x_t-y_t) + m\\|x_t-y_t\\|^2 \\]\n\n            Therefore\n            \\[ \\mathrm{d}\\|x_t-y_t\\|^2 \\le -2m\\|x_t-y_t\\|^2 \\]\n\n            Integrate on both sides yields our desired result\n            \\[ \\|x_t-y_t\\|^2 \\le e^{-2m}\\|x_0-y_0\\|^2 \\]\n        \\end{proof}\n\n    \\subsection{Discrete Implementation of Langevin Dynamics}\n        \\[ Z_{t+1} = Z_t - \\eta\\nabla f(Z_t) + \\sqrt{2\\eta}\\xi_t \\]\n        where\n        \\[ \\xi_t \\sim \\mathcal{N}(0,1) \\]\n        \\begin{remark}\n            The choice of $\\eta$ matters.\n        \\end{remark}\n\n        The convergence analysis in the discrete case is beyond the scope.\n", "meta": {"hexsha": "9024a3b949c623ef2062b7856549bb39a21e318e", "size": 8349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/Diffusion.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/Diffusion.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/Diffusion.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": 55.66, "max_line_length": 255, "alphanum_fraction": 0.5892921308, "num_tokens": 2853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6921213573804982}}
{"text": "\\chapter{Simple Machines}\n\nAs mentioned earlier, physicists define work to be the force applied\ntimes the distance it is applied over. So, if you pushed your car 100\nmeters with 17 newtons of force, you have done 1700 joules of work.\n\nHumans have always had to move really heavy things, so many centuries\nago we developed simple machines to decrease the amount of force\nnecessary to execute those tasks. These include things like:\n\\begin{itemize}\n\\item Levers\n\\item Pulleys\n\\item Ramps\n\\item Gears\n\\item Hydraulics\n\\item Screws\n\\end{itemize}\n\n\\includegraphics[width=0.8\\textwidth]{Simple_Machines.png}\n\nWhile these machines can decrease the force needed, they don't change\nthe amount of work that must be done. So if the force is decreased to\na third, the distance that you must apply the force is increased by a\nfactor of three.\n\n``Mechanical gain'' is what we call the increase in force.\n\n\\section{Levers}\n\nA lever rotates on a fulcrum. To decrease the necessary force, the load\nis placed nearer to the fulcrum than where the force is applied.\n\nIn particular, physicists talk about the \\newterm{torque} created by a\nforce. When you push on a lever, the torque is the product of the\nforce you exert and the distance from the point of rotation.\n\nTorque is typically measured in newton-meters.\n\nTo balance two torques, the products must be the same. So, assuming\nthat the forces are applied in the proper direction,\n\n$$R_L F_L = R_A F_A$$\n\nwhere $R_L$ and $R_A$ are the distance from the fulcrum to the where\nthe load's force and the applied force (respectively) are applied, and\n$F_L$ and $F_A$ are the amounts of the forces.\n\n\\begin{Exercise}[title={Lever}, label=lever]\n  \nPaul, who weighs 70 kilograms, sits on a see-saw 4 meters from the\nfulcrum.  Jan, who weighs 50 kilograms, wants to balance. How far\nshould Jan sit from the fulcrum?\n\n\\end{Exercise}\n\\begin{Answer}[ref=lever]\n  Paul is exerting $(70)(9.8)$ newtons of force at 4 meters from the\n  fulcrum, so he is creating a torque of 2,744 newton-meters of torque\n  on the see-saw.  Jan is creating $(50)(9.5) = 490$ newtons of\n  force.\n\n  If $r$ is the distance from the fulcrum to Jan's seat, to balance\n  $490 r = 2744$, so $r = 5.6$ meters.\n\\end{Answer}\n% KA: https://www.khanacademy.org/science/physics/discoveries/simple-machines-explorations/a/lever\n\n\\includegraphics[width=0.8\\textwidth]{WD=WD.png}\n\n\\section{Ramps}\n\nRamps, or include planes, let you roll or slide objects up to a higher\nlevel. Steeper ramps give you less mechanical gain. For example, it is much easier \nto roll a ball up a wheelchair ramp than on a skateboard ramp.\n% diagram neeeded\n\nAssuming the ramp has a constant steepness, the mechanical gain is\nequal to the ratio of the length of the ramp divided by the amount\nthat it rises.\n\nIf you assume there is no friction, the force that you push a weight up the ramp will be:\n\n$$F_A = \\frac{V}{L} F_G$$\n\nWhere $F_A$ is the force you need to push. $L$ is the length of the\nramp, $V$ is the amount of vertical gain and $F_G$ is the force of\ngravity on the mass.\n\n(We haven't talked about the sine function yet, but in case you already know about it: Note that\n\n$$\\frac{V}{L} = \\sin{\\theta}$$\n\nwhere $\\theta$ is the angle between the ramp and level.)\n\n\\begin{Exercise}[title={Ramp}, label=ramp]\nA barrel of oil weighs 136 kilograms. You can push with a force of\nup to 300 newtons. You have to get the barrel onto a platform that is 2\nmeters. What is the shortest board that you can use as a ramp?\n\\end{Exercise}\n\\begin{Answer}[ref=ramp]\n  To lift the barrel would require $136 \\times 9.8 = 1,332.8$ newtons of force.\n\n  Letting $L$ be the length of the ramp:\n\n  $$300= \\frac{2}{L} 1332.8$$\n\n  So $L = 8.885$ meters.\n\\end{Answer}\n\n\\section{Gears}\n\nGears (which might have a chain connecting them like on a bicycle)\nhave teeth and come in pairs. You apply torque to one gear, and it\napplies torque to another. The torque is increased or decreased based\non the ratio between the teeth on the gears.\n% ADD: Driver, Driven, Idler\n\n\\includegraphics[width=0.8\\textwidth]{Gears.png}\n\n\nIf $N_A$ is the number of teeth on the gear you are turning with a\ntorque of $T_A$, and $N_L$ is the number of teeth on the gear it is\nturning, the resulting torque is:\n\n$$T_L = \\frac{N_A}{N_L} T_A$$\n\n\n\\begin{Exercise}[title={Gears}, label=gear]\n\nThe bicycle is an interesting case because we are not trying to get\nmechanical gain. We want to spin the pedals slower with more force.\n  \nYou like to pedal your bike at 70 revolutions per minute. The\nchainring that is connected to your pedals has 53 teeth. The\ncircumference of your tire is 2.2 meters. You wish to ride a 583 meters\nper minute.\n\nHow many teeth should the rear sprocket have?\n  \n\\end{Exercise}\n\\begin{Answer}[ref=ramp]\n  \n  $$583 = (70)(2.2)\\frac{53}{n}$$\n  \nThus $n = 14$ teeth.\n\\end{Answer}\n% KA: https://www.khanacademy.org/science/physics/discoveries/simple-machines-explorations/a/simple-machines-and-how-to-use-this-tutorial\n\n\\section{Hydraulics}\n\nIn a hydraulic system, like the braking system of a car, you exert\nforce on a piston filled with fluid. The fluid carries that pressure\ninto another cylinder. The pressure of the fluid pushes the piston in\nthat cylinder out.\n\n\\includegraphics[width=0.8\\textwidth]{Hydraulics.png}\n\n\nThe pressure in the hose can be measured in pounds per square inch\n(PSI) or newtons per square meter (Pascals or Pa). We will use Pascals.\n% ADD: Create a page in the back of the book with units\n\nTo figure out how much pressure you create, you divide the force by\nthe area of the piston head you are pushing.\n\nTo figure out how much force that creates on the other end, you\nmultiply the pressure times the area of the piston head that is\npushing the load.\n\n\\begin{Exercise}[title={Hydraulics}, label=hydraulics]\n\nYour car has disc brakes. When you put 2,500,000 pascals of pressure on the\nbrake fluid, the car stops quickly. As the car designer, you would like\nthat to require 12 newtons of force from the driver's foot.\n\nWhat should the radius of the master cylinder (the one the driver is pushing on) be?\n\\end{Exercise}\n\\begin{Answer}[ref=hydraulics]\n  We are looking for $r$, the radius of the piston head in meters. The area of the piston head is $\\pi r^2$.\n\n  The pressure in pascals of the brake fluid is given by $12 / (\\pi r^2)$.\n\n  $$2,500,000 = \\frac{12}{\\pi r^2}$$\n\n  So $r = \\sqrt{\\frac{12}{\\pi \\times 2.5 \\times 10^6}} = 0.001236077446474$ meters.\n\n\\end{Answer}\n% KA: https://youtu.be/Pn5YEMwQb4Y\n\n\n", "meta": {"hexsha": "f70e82f999eaee38380c54070cfe4ffe5addb426", "size": 6471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/simple_machines-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/simple_machines-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/simple_machines-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": 34.2380952381, "max_line_length": 137, "alphanum_fraction": 0.7467161181, "num_tokens": 1835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6920782728137106}}
{"text": "\\problemname{Quality-Adjusted Life-Year}\n\n%% Image URL: https://www.pexels.com/photo/sunset-sunshine-travel-wings-103127/  \n%% Image License: https://www.pexels.com/photo-license/\n\n\\illustration{0.33}{balcony.jpg}{~}\n\nThe Quality-Adjusted Life-Year (QALY) is a way to measure a person's\nquality of life that includes both the quality and the quantity of\nlife lived.\n\nThe quality of life lived can be quantified as a number between $0$ and\n$1$.  If someone is living with perfect health, the quality of life is\n$1$.  If someone is dead, then the quality of life is $0$.  The quality of\nlife may increase or decrease due to medical treatements, sickness, \netc.\n\nThe QALY for each period in which the quality of life is constant is\nsimply the product of the quality of life and the length of the period\n(in years).  We wish to know the amount of QALY accumulated by a\nperson at the time of death, given the complete history of this\nperson.\n\n\\section*{Input}\n\nThe first line of input contains a single integer $N$~($1 \\leq N \\leq 100$), which is the number of periods of constant quality of life during the person's lifetime.\n\nThe next $N$ lines describe the periods of life. Each of these lines contains two real numbers $q$~($0 < q \\leq 1$), which is the quality of life in this period, and $y$~($0 < y \\leq 100$), which is the number of years in this period. All real numbers will be specified to exactly one decimal place.\n\n\\section*{Output}\n\nDisplay the QALY accumulated by the person. Your answer will be considered correct if its absolute error does not exceed $10^{-3}$.\n", "meta": {"hexsha": "8dad911101b0b18649e3d6ab591fca59933d30fb", "size": 1575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/qaly/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/qaly/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/qaly/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": 47.7272727273, "max_line_length": 299, "alphanum_fraction": 0.7517460317, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.6920782682940182}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{amssymb}\n\\usepackage{showkeys}\n\\usepackage{amsmath}\n\\usepackage{float}\n\\usepackage{subcaption}\n\\usepackage{graphicx}\n\\usepackage{stix}\n\n\\newtheorem{thm}{Theorem}[section]\n\\newtheorem{prop}[thm]{Proposition}\n\\newtheorem{lem}[thm]{Lemma}\n\\newtheorem{cor}[thm]{Corollary}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}[thm]{Definition}\n\\newtheorem{example}[thm]{Example}\n\n\\theoremstyle{remark}\n\n\\newtheorem{remark}[thm]{Remark}\n\n\\newcommand{\\R}{\\mathbf{R}}  % The real numbers.\n\\DeclareMathOperator{\\dist}{dist} % The distance.\n\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\begin{document}\n\\title{Signal Denoising and Error Bounding using Analytic Methods}\n\\author{Noah Stockwell}\n\n\\begin{abstract}\nIt is shown that with normalized convolution kernels, one can find smooth derivatives that interpret any continuous system sampled at discrete points.\n\\end{abstract}\n\n\n\\maketitle\n\\tableofcontents\n\n\\section{Introduction}\nThis paper provides a specific formulation of a method to find smooth trends in discrete data for both the Riemann integral and then the Lebesgue integral with bound consideration. The motivation is the existence of the engineering question: \\textit{what do real-world processes look like when they are sampled and how do we remove sampling error without destroying the signal?} This paper considers the result of applying a convolution to a set of 2-dimensional discrete points, and how accurate we can expect the convolution to be compared to the process that is being sampled.\n\\newpage\n\\section{Formulation for $S\\in C_0(\\mathbb{R})$ using the Riemann Integral}\n\\begin{thm}Given a set $T=(T_x, T_y)$ of points separated by an identical $T_x$ distance $\\lambda$, the generating function $S\\in C_0(\\mathbb{R})$ can be approximated by a smooth function.\n\\end{thm}\n\\begin{proof}\nFirst, define the piecewise function made up of constant functions that passes through all points in $T$:\n$$\nf(x)\\mid (x,f(x))\\in T\n$$\nWith\n$$\nf(t)\\equiv T_{y_m} \\qquad\\forall\\,\\, t\\in [T_{x_m}, T_{x_{m+1}})\n$$\nNext, define the function with consideration width $w$:\n\\begin{equation}\n\\delta_n(x, w):=\n\\begin{cases}\n\\left(1-\\left(\\frac{x}{w}\\right)^n\\right)^2 & x\\in (-w, w)\\\\\n0&x\\not\\in (-w, w)\\\\\n\\end{cases}\n\\end{equation}\nNormalization is trivial:\n$$\nN(w):=\\int_{-w}^w\\delta_n(t, w)\\,dt =C(w)\n$$where $C$ is a constant. Define and note that \n\\begin{equation}\n\\phi(x,w) := \\frac{\\delta_n(x,w)}{N(w)}\n\\end{equation}\nIs now a probability function: the total area under $\\phi$ is now 1 across $\\mathbb{R}$. Define the convolution:\n$$\nf\\approx(f\\circledast\\phi)(x, w) = \\int_{-\\infty}^\\infty f(\\tau)*\\phi(x-\\tau, w)\\,d\\tau\n$$\nWhich is exactly equivalent to\n\\begin{equation}\n(f\\circledast\\phi)(x, w) =\n\\begin{cases}\n\\displaystyle \\int_I f(\\tau)*\\phi(x-\\tau, w)\\,d\\tau &x\\in I\\\\\n0 &x\\not\\in I\\\\\n\\end{cases}\n\\end{equation}\nFor $I=(\\min(T_x)-w,\\max(T_x)+w)$. Because $f$ is constant and piecewise, we can redefine the integral part as such:\n\\begin{equation}\n\\displaystyle \\int_I f(\\tau)*\\phi(x-\\tau)\\,d\\tau = \\displaystyle\\sum_{a\\in T_x} f(a) \\int_a^{a+\\lambda} \\phi(x-\\tau, w)\\,d\\tau\n\\end{equation}\nWe do not care about extrapolation which means we can throw out the extra convolution width $w$ and tails rewriting the convolution as:\n$$\nf(x)\\approx(f\\circledast\\phi)(x, w) =\\displaystyle\\sum_{a\\in T_x} f(a)\\displaystyle\\int_a^{a+\\lambda} \\phi(x-\\tau, w)\\,d\\tau\n$$\nFor $x\\in [\\min(T_x),\\max(T_x)]$. By construction, $\\phi$ is smooth and thus a linear combination of $\\phi$'s is smooth.\n\\end{proof}\n\\begin{cor}Given a set $T=(T_x, T_y)$ of points separated by an identical $T_x$ distance $\\lambda$, the generating derivative can be approximated by a smooth function.\n\\end{cor}\n\\begin{proof}\nFrom our last result,\n\\begin{align}\nf(x)&\\approx \\displaystyle\\sum_{a\\in T_x} f(a)\\displaystyle\\int_a^{a+\\lambda} \\phi(x-\\tau, w)\\,d\\tau\\\\\n\\implies \\frac{d}{dx}\\,f(x)&\\approx \\displaystyle\\sum_{a\\in T_x} f(a)\\,\\,* \\frac{d}{dx}\\int_a^{a+\\lambda} \\phi(x-\\tau, w)\\,d\\tau\\\\\n\\implies f'(x) &\\approx \\displaystyle\\sum_{a\\in T_x} f(a) * \\left( \\phi(x-a-\\lambda, w)-\\phi(x-a, w) \\right)\n\\end{align}\nThe approximation for $f'$ can be convolved with an arbitrary probability kernel $h$, as well, to find a smoother interpretation of the derivative:\n\\begin{equation}\nf'(x)\\approx \\left(\\frac{d}{dx} (f\\circledast\\phi)(x,w)\\,\\circledast\\, h\\right)(x)\n\\end{equation}\n\\end{proof}\nIt is clear that if we choose not only normalized functions $\\phi_n$ and $h$ to be approximations to the identity, we have that our representation will approach the function itself at every point \\cite{stein_real_2006}.\n\\newpage\n\n\\section{Motivation for $S\\in C_0(\\mathbb{R})$ using the Lebesgue Integral}\nOf the many properties of the Lebesgue integral that we do not have with the Riemann integral is the ability to ignore points on a set of measure zero. It is clear that a process of engineering interest is happening continuously in the real world but can be only sampled at finitely many points. Furthermore, it is possible to have significant noise or sensor malfunctions at some points that drive $S$ incredibly far away from the generating signal.\\\\\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}[t]{0.5\\textwidth}\n\t\\centering\n\t\\includegraphics[height=2.0in]{/Users/noahstockwell/Documents/TeX/Proj544/Images/NoisyThermocouple.png}\n\t\\caption{The signal over multiple samples}\n\\end{subfigure}%\n~ \n\\begin{subfigure}[t]{0.5\\textwidth}\n\t\\centering\n\t\\includegraphics[height=2.0in]{/Users/noahstockwell/Documents/TeX/Proj544/Images/SmoothThermocouple.png}\n\t\\caption{The signal over few samples}\n\\end{subfigure}\n\\caption{A sample thermocouple response at different sampling levels}\n\\end{figure}\n\nAbove in Figure 1(A), it is clear to us as humans the general shape of the generating signal. However, the true data points being collected look more like Figure 2(B) and it is often a trade-off between maintaining a close relationship to the original generating signal's value and maintaining a close relationship to the original generating signal's behavior. For example, as seen in section (2), the convolution with $\\delta_n$ will either produce a function that has very few quick changes in its derivative, or a function that approximates the original function closely by value. It is in the Engineer's interest to ask the question: \\textit{how much data can I reasonably destroy without jeopardizing the conclusion?}\\\\\n\nWith this in mind, we will construct a method and identify how `bad' it can be: how far can it be away from the generating signal?\n\n\\section{Formulation for $S\\in C_0(\\mathbb{R})$ using the Lebesgue Integral}\n\\subsection{Construction of problem}\nLet $S$ be our observed signal. We can visualize $S$ as $S(t) = f(t) + \\eta(t) + \\rho(t)$ where $f$ is the exact representation of the real process, $\\eta$ is white noise upon the signal, and $\\rho$ is extreme instantaneous variation induced by the signal. To replicate the real world, let $\\rho$ vanish everywhere except on a set of Lebesgue measure 0. The motivation for this representation is that it is possible to have extreme variation when recording a signal that has no physical meaning and does not repeat. As white noise on a signal is zero in the time domain, for all $E$ of sufficient measure, we would like $\\displaystyle\\int_E\\eta=0$. We only need to consider $S$ supported on a set of finite measure as the time values sampled are discrete and thus extrapolation beyond local areas is not desired. As such, we only require $S$ to belong to $L^1_{\\text{loc}}$.\n\\subsection{Requirements}\nWithout loss of generality, we can split $\\eta$ into $\\eta^+$ and $\\eta^-$ such that:\n\\begin{align*}\n\\int S&=\\int f+\\int \\eta\\\\\\\\\n\\int S&=\\int f+\\int \\eta^+-\\int \\eta^-\n\\end{align*}\nWhere $\\eta^+$ and $\\eta^-$ are both strictly nonnegative functions on the signal interval I, and since we know $\\eta$ should be zero in the time domain \\cite{saito_naoki_simultaneous_1994}, we want to create a process such that:$$\\int_I\\eta^+=\\int_I\\eta^-$$\nSince the $\\eta^\\pm$ are zero when the other is positive, we can let $$I=E^+\\bigcup E^-$$ with $E^+$ and $E^-$ disjoint and thus we have:\n$$\\int_I\\eta^i =\\int_I\\chi_{E^i}\\cdot\\eta^i= \\int_{E^i}\\eta^i$$\nSince $E^i\\subset I$. We can begin constructing the function by defining:\n\\begin{align*}\nE_a^+ &= \\{x: S(x)-f(x)>a\\}\\\\\nE_a^- &= \\{x: f(x)-S(x)>a\\}\n\\end{align*}\n\\vfill\nClearly, $E_a^+\\nearrow E^+$ and $E_a^- \\nearrow E^-$ as $a\\to 0$. For almost everywhere compactly supported functions, we have $$m(E^\\pm_a)\\le m(E^\\pm)\\quad \\forall\\,\\, a>0$$Similarly, for finitely supported functions, we have $$|E^\\pm_a|\\le |E^\\pm|\\quad \\forall\\,\\, a>0$$\n\\vfill\nWith these, we want to optimize $f$ such that:\n\\begin{enumerate}\n\t\\item The quantity of noise is largely time independent: \n\t$$\\lim_{a\\to 0} \\left\\lvert m(E_a^+) - m(E_a^-) \\right\\rvert < \\epsilon_a$$\n\t\\item The amount of noise is largely time independent:\n\t$$\\lim_{a\\to 0}\\left\\lvert \\int_{E_a^+} \\eta - \\int_{E_a^-} \\eta\\right\\rvert<\\epsilon_a$$\n\\end{enumerate}\nWe can rewrite (2) as:\n$$\\lim_{a\\to 0}\\left\\lvert \\int_{E_a^+} S(x)-f(x)\\,dx - \\int_{E_a^-} f(x)-S(x)\\,dx\\right\\rvert<\\epsilon_a$$\nWith these in hand, we now want to see how we can bound this difference. It is clear that we desire some type of average over value and time so that we can balance both requirement (1) and (2). This paper makes the choice to consider a convolution $\\phi$ that is normalized and can be considered part of a sequence approaching an approximation to the identity. In fact, we will chose the exact $\\phi_n$ that was selected earlier:\n\n\\begin{align*}\n\t\\delta_n(x, w)&:=\n\t\\begin{cases}\n\t\\left(1-\\left(\\frac{x}{w}\\right)^n\\right)^2 & x\\in (-w, w)\\\\\n\t0&x\\not\\in (-w, w)\\\\\n\t\\end{cases}\\\\\\\\\n\tN(w)&:=\\int_{-w}^w\\delta_n(t, w)\\,dt = C(w)\\\\\\\\\n\t\\phi(x,w)&:= \\frac{\\delta_n(x,w)}{N(w)}\n\\end{align*}\n\nThe question is how far away from $f$ is $S \\circledast \\phi$? Two bounding options are considered.\n\n\\subsection{Error Bounding using a Naive Approach}\nBecause we require our convolution kernels to be normalized, we have:\n\\begin{align*}\n\t(S\\circledast \\phi_n) &= \\int_E S(\\tau)*\\phi(x-\\tau, w)\\,d\\tau\\\\\n\t &\\le \\sup_{x\\in E} S(x)\\quad\\\\\n\\end{align*}\nHowever, this bound is really not helpful. A smarter approach to bounding should be considered. One possible method would be to restrict ourselves to $A \\subset E$:\n\\begin{align*}\n(S\\circledast \\phi_n) &= \\int_A S(\\tau)*\\phi(x-\\tau, w)\\,d\\tau\\\\\n&\\le \\sup_{x\\in A_w} S(x)\\quad\\\\\n\\end{align*}\nWhere $A_w$ is a $w$-dilation of $A$. This is a little more helpful but again $A$ has to be large enough to absorb $\\eta$.\n\n\\subsection{Error Bounding using the Maximal Function}\nThe Hardy-Littlewood maximal function $S^*$ is defined to be:\n\\[\nS^*(t) := \\sup_{B_r(t)\\,\\, \\forall t\\in \\mathbb{R}} \\,\\,\\intbar_B S(t)\\,dt \n\\]\nIt is possible to put a bound on the maximal function, especially because we only consider a single-dimensional independent variable on $E$ with m$(E) < \\infty$ \\cite{stein_real_2006}:\n\\[\n\\text{m}({x\\in E: S^*(x) > \\alpha}) \\le \\frac{3}{\\alpha} \\norm{S}_{L^1(E)}\n\\]\nIt is apparent that we can consider the maximal function as the upper bound for the convolution if we require that the convolution kernel has most density around the origin and is only a small value away from vanishing outside of a small ball centered at the origin. In fact, with our choice of $\\phi_n$ have:\n\\[\n(S \\circledast \\phi_n)(t) \\le (1+c) \\,S^*(t)\n\\]\nWith $c>0$ small. In fact, because our convolution vanishes outside of a ball of radius $w$ around the origin and our convolution kernel is less than the box kernel $K$ of width $\\le w$ outside of a smaller ball, we have:\n\\begin{align*}\n(S\\circledast \\phi_n) &= \\int_E S(\\tau)*\\phi(x-\\tau, w)\\,d\\tau\\\\\n& \\le (1+c) \\sup_{\\tilde{w} \\in (0,w]} \\int_E S(\\tau)*K(x-\\tau, \\tilde{w})\\,d\\tau\\\\\n&=  (1+c) \\sup_{B_r(t)\\,\\, \\forall t\\in (0, w]} \\,\\,\\intbar_B S(t)\\,dt\\\\\n&= (1+c)\\,S^*_{w}(x)\n\\end{align*}\nWhere $S^*_{w}(x)$ is the maximal function taken over balls of size up to $w$ around $x$ and $c>0$ small. This provides us a much nicer bound on the convolution.\\\\\nIt was claimed earlier that $S$ could be represented as the sum of three functions and $\\rho$ vanishes everywhere except a set of Lebesgue measure 0. There are multiple methods to remove outliers for data: apply one or multiple and now we have:\n\\[\n\\int_E S = \\int_E f + \\eta\n\\]\nas the Lebesgue integral ignores values on a set of measure zero. We can now assume that we can simply sum the convolution as we did in the beginning:\n\\begin{align*}\nS(x)\\approx(S\\circledast\\phi)(x, w) &\\le \\epsilon_0(x) + \\sum_{a_n\\in T_x} S\\left(a_n\\right)\\int_{a_n}^{a_{n+1}} \\phi(x-\\tau, w)\\,d\\tau\\\\\n&= \\epsilon_0(x) + \\sum_{a_n\\in T_x} \\left(f\\left(a_n\\right) + \\eta\\left(a_n\\right)\\right)\\int_{a_n}^{a_{n+1}} \\phi(x-\\tau, w)\\,d\\tau\\\\\n\\end{align*}\nIf we set \n\\[\nb_{{a_n}(x), w} = \\int_{a_n}^{a_{n+1}} \\phi(x-\\tau, w)\\,d\\tau\n\\]\nwe have\n\\begin{align*}\n(S\\circledast\\phi)(x, w) &\\le \\epsilon_0(x) +  \\sum_{a_n\\in T_x} \\left(f\\left(a_n\\right) + \\eta\\left(a_n\\right)\\right)\\ * b_{{a_n}, w}(x)\\\\\n&= \\epsilon_0(x) +  \\left(\\sum_{a_n\\in T_x} f\\left(a_n\\right) * b_{{a_n}, w}(x)\\right) + \\left(\\sum_{a_n\\in T_x} \\eta\\left(a_n\\right) * b_{{a_n}, w}(x)\\right)\\\\\n\\end{align*}\nSince $\\eta$ sums to zero in the time domain, we get:\n\\[\n\\sum_{a_n\\in T_x} \\eta\\left(a_n\\right) * b_{{a_n}, w}(x) \\equiv 0\n\\]\nLeaving us with only\n\\[\n(S\\circledast\\phi)(x, w) \\le \\epsilon_0(x) +  \\sum_{a_n\\in T_x} f\\left(a_n\\right) * b_{{a_n}, w}(x)\n\\]\nWhich leads us back to the Riemann conclusion. At this point, the question is can we recover $f(t)$ exactly? Clearly we want equality, so the process would have to start with identifying $\\epsilon_0$:\n\\[\n\\epsilon_0(x) = \\min\\left(\\left|(1+c)*S^*_{w}(x) - S(x)\\right|, \\left|\\sup_{\\tilde{x}\\in B_w(x)}S(\\tilde{x}) - S(x)\\right|\\right)\n\\]\nIt should be clear at least with this choice of bounding, $f(t)$ cannot be recovered exactly. However, for certain classes of functions, we can approximate $f$ very closely. A further question of importance is given a certain type of function, is it possible to significantly improve the bound, i.e. given a first-order ODE, is it possible to be within only an epsilon range of $f$? \n\\newpage\n\\section{Conclusion}\nWe do not have the ability to recreate $f$ with this formulation, however we may be able to get close for certain functions, especially simple functions. This process was implemented in MATLAB(\\texttrademark) on an experiment involving temperature measurements of a thermocouple being moved from one environment to another \\cite{engr_132}:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=2.0in]{/Users/noahstockwell/Documents/TeX/Proj544/Images/Comparison.png}\n\t\\caption{Thermocouple response: Noisy and Convolved}\n\\end{figure}\nFigure 2 demonstrates the potential of a well-tuned convolution in denoising signals for Engineering analysis. It is clear that a correct choice of parameters allows for a close interpretation of the signal. For the mathematical question of how far away is the convolution, more work should be done to better identify the constant $c$ and if superior bounding methods exist. Furthermore, it may be of interest to study only certain classes of functions, as we are modeling real-world processes and we should expect a process to be near a simple PDE, for example. \\\\\nA potential method to attempt to analyze $S$ in the future could be trying to interpret $f+\\eta^+$ and $f-\\eta^-$ because these functions would appear to be a sawtooth-wave style upon a smooth function. It could then be possible to use the property that the sawtooth frequency and amplitude should be equal in the time domain to reduce the error in the approximation to $f$.\n\\newpage\n\\bibliography{bibFile}\n\\bibliographystyle{plain}\n\\end{document}\n\n\n\n\n\n\n", "meta": {"hexsha": "75434a19f77fa3c1f05bbba8b22de67133496273", "size": 15792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "noahess/Project544", "max_stars_repo_head_hexsha": "0c49ab1cb3b7a7559b9789709dc7350c1ace9007", "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": "noahess/Project544", "max_issues_repo_head_hexsha": "0c49ab1cb3b7a7559b9789709dc7350c1ace9007", "max_issues_repo_licenses": ["CC0-1.0"], "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": "noahess/Project544", "max_forks_repo_head_hexsha": "0c49ab1cb3b7a7559b9789709dc7350c1ace9007", "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.7384615385, "max_line_length": 874, "alphanum_fraction": 0.7216945289, "num_tokens": 4897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.6920564827050766}}
{"text": "%================================================\r\n\\section{Introduction to TDA}\r\n%================================================\r\n\t%----------------------------------------------\r\n\t\\subsection{Mathematics of Machine Learning}\r\n\t%----------------------------------------------\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Mathematics of Machine Learning: Problem Statement}\r\n\t\t\r\n\t\t\\begin{definition}\r\n\t\t\tGiven an ideal function $f: X\\rightarrow Y$, which associates \\textbf{data} in $X\\neq\\phi$ with \\textbf{measurements} in $Y\\neq\\phi$,\r\n\t\t\tthe problem of \\textbf{supervised learning} is to \\textbf{learn} a \\textbf{target function} $\\hat{f}:X\\rightarrow Y$, which approximates $f$,\r\n\t\t\tusing a finite sample $S=\\{(x_i,f(x_i))\\}_{i=1}^n$, a \\textbf{training set}.\r\n\t\t\\end{definition}\r\n\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item When $Y$ is finite, we say that this is a \\textbf{supervised classification problem},\r\n\t\t\totherwise, we say this is a \\textbf{supervised regression problem}.\r\n\t\t\t\\medskip\r\n\t\t\t\\item In practice we often encode $Y$ to be isomorphic to $\\rr^n$ or $\\zz_n$ for some $n\\in\\nn$.\r\n\t\t\t(e.g., if the possible measurements are ``red'' and ``not red'', we encode this as $Y=\\{0,1\\}$).\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Mathematics of Machine Learning: Generalization}\r\n\t\t\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item There are infinitely many $\\hat{f}$ for which $\\hat{f}(x_i) = f(x_i)$ for all $x_i\\in S$. \r\n\t\t\t\\medskip\r\n\t\t\t\\item For the purpose of machine learning, we are more interested not in\r\n\t\t\tfitting $\\hat{f}$ to $S$, but in generalizing $\\hat{f}$ to $X$; i.e., approximating $f$ on $X$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item For this reason, we often partition $S$ into two sets $S_{\\text{train}}$ and $S_{\\text{test}}$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item We first find $\\hat{f}$ which performs well on $S_{\\text{train}}$, then we validate this on $S_{\\text{test}}$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item This does not guarantee accuracy on $X$. It is an open problem of research to establish useful conditions under\r\n\t\t\twhich training and test set performance will generalize to the entire set $X$.\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Mathematics of Machine Learning: Hypothesis Space}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item The \\textbf{hypothesis space} for the supervised learning problem is $\\cH = \\{f:X\\rightarrow Y\\}$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item It is not computationally feasible to search over the space\r\n\t\t\tof all such functions for $f$, especially when the $X$ is infinite or extremely large. Instead we choose a class of target functions $\\hat{H}$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item Once a class of target functions has been selected, a \\textbf{loss function} $J:\\hat{\\cH}\\times \\cH\\rightarrow \\rr$ is selected.\r\n\t\t\t\\medskip\r\n\t\t\t\\item A popular example of this is the mean squared error:\r\n\t\t\t\t$$J(\\hat{f},f) = \\frac{1}{n} \\sum_{i=1}^n (f(x_i)-\\hat{f}(x_i))^2.$$\r\n\t\t\t\\item In the case where $Y=\\{0,1\\}$, a popular loss function is \\textbf{logarithmic loss}:\r\n\t\t\t\t$$J(f,\\hat{f}) = -f(x_i)\\log(\\hat{f}(x_i))+(1-f(x_i))\\log(1-\\hat{f}(x_i)).$$\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Mathematics of Machine Learning: Optimization}\r\n\t\t\r\n\t\t\t\\begin{itemize}\r\n\t\t\t\\item The task of learning $\\hat{f}$ is to minimize $J$.\r\n\t\t\t\\item There is copious literature on the subject of optimization and loss functions in a machine learning context.\r\n\t\t\t\\item One of the most popular methods of optimization for machine learning is Adam, or adaptive moment estimation.\r\n\t\t\t\\item It is beyond the scope of this talk to delve into the details of Adam.\r\n\t\t\t\\item The selection of an optimization algorithm can impact the performance of machine learning significantly. \r\n\t\t\t\\item See details of Adam here: \\url{https://arxiv.org/pdf/1412.6980.pdf}\r\n\t\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Mathematics of Machine Learning: Pipeline}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Define the problem in terms of an ideal function $f$ and a dataset $S$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item Select a target function class; i.e., $\\hat{H}$.\r\n\t\t\t\\medskip\r\n\t\t\t\\item Select a loss function $J$; e.g., mean squared error.\r\n\t\t\t\\medskip\r\n\t\t\t\\item Select an optimization method; e.g., Adam.\r\n\t\t\t\\medskip\r\n\t\t\t\\item Learn $\\hat{f}$ by optimizing $J$ over $S$ (i.e., implement the machine learning architecture design).\r\n\t\t\t\\medskip\r\n\t\t\t\\item Analyze the results usually with statistics-based methods such as area under curve (AUC) and iterate on the design.\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\tNote: if enough computational resources are available, hyperparameter search can be used to automate some of the iteration.\r\n\t\t\r\n\t\t\\end{frame}\r\n\t%----------------------------------------------\r\n\t\\subsection{Topological Data Analysis Motivations}\r\n\t%----------------------------------------------\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Traditional Assumptions of Data Analytics}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Qualitative information is required - we wish to classify data/datasets by describing global properties (i.e., features).\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item Loss/error functions are quantitative in nature.\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\\item Metrics usually have no basis in physics (counterexample to this would be Physics-informed Neural Networks).\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item Optimization of machine learning algorithms is sensitive to metric choice (e.g., mean squared error).\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\\item Coordinates are not usually natural (unlike state vector coordinates from physics).\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item The representation of data matters significantly, especially in terms of coordinates (normalized data vs. raw data).\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\\item Preference of summaries over individual parameter selection.\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item Parameter selection and hyperparameter search look for optimal parameters, but this is computationally expensive.\r\n\t\t\t\t\\end{itemize}\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Topological Data Analysis}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Qualitative information is required - we wish to classify data/datasets by describing global properties.\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item Topology captures global qualitative information via connectivity information about\r\n\t\t\t\t\tthe underlying surface (e.g., manifold) that data resides within.\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\\item Metrics usually have no basis in physics.\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item Less sensitivity to metric choice in topology since spatial information is not dependent on true distance, but relative placement.\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\\item Coordinates are not usually natural.\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item Topology is coordinate free by definition. We place topological structure on a coordinate space, but that structure is not the significant factor.\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\\item Preference of summaries over individual parameter selection.\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item The powerhouse of topological data analysis is persistent homology, which looks at all possible parameter choices\r\n\t\t\t\t\tas a summary versus endlessly searching a large hyperparameter space.\r\n\t\t\t\t\\end{itemize}\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t%----------------------------------------------\r\n\t\\subsection{Basic Topological Structures}\r\n\t%----------------------------------------------\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Spaces Under Study}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tLet $X\\neq\\phi$ and $d:X\\times X\\rightarrow [0,\\infty)$. Then $d$ is said to be a \\textbf{metric} on $X$, and the pair\r\n\t\t$(X,d)$ a \\textbf{metric space} if for all $x,y,z\\in X$:\r\n\t\t\t\\begin{enumerate}\r\n\t\t\t\t\\item $d(x,y) = 0$ iff $x=y$\r\n\t\t\t\t\\item $d(x,y) = d(y,x)$\r\n\t\t\t\t\\item $d(x,z) \\leq d(x,y) + d(y,z)$\r\n\t\t\t\\end{enumerate}\r\n\t\t\\end{defn}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tLet $X\\neq\\phi$ and $\\cT\\subseteq X$. Then $\\cT$ is a \\textbf{topology} on $X$, and the pair $(X,\\cT)$ is said to be a \\textbf{topological space}, if\r\n\t\t\t\\begin{enumerate}\r\n\t\t\t\t\\item $X,\\phi\\in\\cT$\r\n\t\t\t\t\\item $\\cT$ is closed under arbitrary unions\r\n\t\t\t\t\\item $\\cT$ is closed under finite intersections.\r\n\t\t\t\\end{enumerate}\r\n\t\tThe members of $\\cT$ are said to be \\textbf{open}.\r\n\t\t\\end{defn}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Continuity}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tLet $(X,\\cT_X)$ and $(Y,\\cT_Y)$ be topological spaces and $f:X\\rightarrow Y$. Then $f$ is \\textbf{continuous} at $x_0$ if for every $V(f(x))\\in\\cT_Y$, there exists $U(x)\\in \\cT_X$ such that $f(U)\\subseteq V$.\r\n\t\t\\end{defn}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tLet $(X,d)$ be a metric space and $\\epsilon>0$, then the open ball $B(x;\\epsilon)=\\{y: d(x,y)<\\epsilon\\}$\r\n\t\t\\end{defn}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tLet $(X,d)$ and $(Y,d_Y)$ be metric spaces. Then $f:X\\rightarrow Y$ is continuous at $x_0\\in X$ if for every\r\n\t\t$\\epsilon>0$, there exists $\\delta>0$ such that $f(B(x_0;\\delta))\\subseteq B(y;\\epsilon)$.\r\n\t\t\\end{defn}\t\t\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Point Clouds and Homeomorphism}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tA \\textbf{point cloud} is a finite metric space (i.e., $(X,d)$ such that $X=\\{x_1,\\ldots,x_n\\}$). As such all datasets encoded in computers can be seen as mathematical point clouds.\r\n\t\t\\end{defn}\r\n\t\t\r\n\t\t\\begin{defn}\r\n\t\tLet $f:X\\rightarrow Y$ be bicontinuous (continuous $f$ and $f^{-1}$). Then $f$ is a \\textbf{homeomorphism} and we say $X$ is homeomorphic to $Y$; $X\\cong Y$. If a property holds for $X$ and for any homeomorphism $f(X)$, then we say that property is a \\textbf{topological invariant}.\r\n\t\t\\end{defn}\r\n\t\t\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Since every dataset is a point cloud (i.e., a metric space), every dataset has a topology, dependent on the choice of metric.\r\n\t\t\t\\item E.g., $32\\times 32$ black and white images can be seen as lying in $\\cM^{32\\times 32}([0,1])$. We can endow this space\r\n\t\t\twith a metric (e.g., Euclidean distance), which makes it a point cloud. Since it is also a point cloud, it has an underlying topology.\r\n\t\t\t\\item $\\cM^{32\\times 32}([0,1]) \\cong [0,1]^{1024}$.\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t%----------------------------------------------\r\n\t\\subsection{Algebraic Topology: Connectivity Information}\r\n\t%----------------------------------------------\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Homotopy}\r\n\t\t\r\n\t\t\\begin{definition}\r\n\t\t\tIf $f,g:X\\rightarrow Y$ are continuous, we say that they are \\textbf{homotopic} if $H:X\\times[0,1]\\rightarrow Y$ is such that $H(x,0)=f(x)$\r\n\t\t\tand $H(x,1)=g(x)$. Furthermore, we say that $f:X\\rightarrow Y$ is a \\textbf{homotopy equivalence} if there exists $G:Y\\rightarrow X$ such \r\n\t\t\tthat $f\\circ g$ is homotopic to $\\mathrm{id}_X$ and $g\\circ f$ is homotopic to $\\mathrm{id}_Y$. If $X$ is homotopy equivalent to $Y$ then \r\n\t\t\twe say they are \\textbf{homotopic} spaces.\r\n\t\t\\end{definition}\r\n\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item See \\textit{Algebraic Topology} by Hatcher for a more thorough treatment of this topic.\r\n\t\t\t\\item It is enough for us to note with some hand-waving that there is a group $H_k(X,A)$ for any commutative group $A$ and non-negative \r\n\t\t\tinteger $k$, such that when $X$ and $Y$ are homotopic, $H_k(X,A)$ is \\textbf{isomorphic} (i.e., operation-preserving) to $H_k(Y,A)$. \r\n\t\t\t\\item We call $H_k(X,A)$ the \\textbf{homotopy group} of $X$.\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Homotopy}\r\n\t\tWith respect to $H_k(X,A)$:\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item If we require $A$ to be a field, then $H_k(X,A)$ is a vector space.\r\n\t\t\t\\item We denote the dimension of this vector space as $\\beta_k(X,A)$, which will be referred to as the $k-$th Betti number.\r\n\t\t\t\\item Informally, the $k-$th Betti number corresponds to the number of independent $k-$dimensional surfaces.\r\n\t\t\t\\item If two spaces are homotopy equivalent, then all their Betti numbers are equal.\r\n\t\t\t\\item The profound observation of TDA, is that data may be studied by studying the inherent independent $k-$dimensional surfaces.\r\n\t\t\t\\item This structure is not one that has been engineered, but one that is inherent in the data's topological structure.\r\n\t\t\t\\item Computationally, it is not feasible/efficient to compute $H_k(X,A)$.\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Homology}\r\n\t\t\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Homology is a computationally feasible analog for homotopy equivalences.\r\n\t\t\t\\item The rigorous definition of homology for general topology relies on infinitely generate modules over $\\zz$.\r\n\t\t\t\\item This definition is not useful from a data analytics perspective because it is computationally impossible to guarantee\r\n\t\t\twe could feasibly compute an approximation in general.\r\n\t\t\t\\item However, using a simple combinatorial structure called \\textbf{simplicial complexes}, we can determine the homology of a given point cloud efficiently.\r\n\t\t\t\\item We will see that we can actually extract Betti numbers from simplicial complexes.\r\n\t\t\\end{itemize}\r\n\t\t\\end{frame}\r\n\t\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Complexes}\r\n\t\t\\begin{defn}\r\n\t\tAn \\textbf{abstract simplicial complex} is a pair $(V,\\Sigma)$ where $V$ is finite and $\\Sigma$ is a family of non-empty subsets of $V$ such that:\r\n\t\t$$\\sigma\\in\\Sigma \\;\\;\\;\\text{and}\\;\\;\\; \\tau\\subseteq\\sigma \\;\\;\\;\\text{implies}\\;\\;\\; \\tau\\in\\Sigma$$\r\n\t\t\\end{defn}\r\n\t\t\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Intuitively, simplicial complexes express a space of points, segments, triangles, tetrahedrons, and their higher dimensional analogues.\r\n\t\t\t\\item These provide a particularly simple way to approximate topological spaces (in terms of homotopy/homology).\r\n\t\t\t\\item Simplicial complexes admit a topology as well as an associated vector space (beyond the scope for this talk).\r\n\t\t\t\\item It is computationally efficient to determine the homology of simplicial complexes compared to the original topological space.\r\n\t\t\t\\item Rigorously, this is done by computing $H_k^{\\text{simp}}(X,\\zz)$, associated with the simplicial complex $X=(V,\\Sigma)$.\r\n\t\t\t\\item $H_k^{\\text{simp}}(X,\\zz)$ is isomorphic to the homology of $X$, which can be generate for a given point cloud.\r\n\t\t\t\\item See Gunnar Carlsson's ``Topology and Data.''\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\t\\end{frame}\r\n\t\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Persistent Homology}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item In order to guarantee that the homology of the point cloud $X$ corresponds with the homology of a simplicial complex $(V,\\Sigma)$\r\n\t\t\tis to build this complex in such a way that there is a homotopy equivalence between $X$ and $(V,\\Sigma)$.\r\n\t\t\t\\item One such complex is the Vietoris-Rips simplicial complex.\r\n\t\t\t\\end{itemize}\r\n\t\t\t\r\n\t\t\t\\begin{defn}\t\t\t\r\n\t\t\tFor a metric space $(X,d)$, the Vietoris-Rips simplicial complex associated with $\\epsilon>0$, whose vertex set is $X$ and where $\\{x_0,\\ldots,x_k\\}$ spans a $k-$dimensional subset iff $d(x_i,x_j)\\leq\\epsilon$ for all $i,j\\leq k$.\r\n\t\t\t\\end{defn}\r\n\t\t\t\r\n\t\t\tBy varying $\\epsilon$, we can study the homology of a point cloud at varying scales. We thus do not tie ourselves to one homology, but study the \\textbf{persistent homologies} across sufficient choices of $\\epsilon$ to summarize the topological information within the data.\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\t\t\\begin{frame}\r\n\t\t\\frametitle{VR Complexes}\r\n\t\t\r\n\t\t\t\t\\begin{figure}\r\n\t\t\t\t\\centering\r\n\t\t\t\t\\includegraphics[scale=0.5]{images/complex.png}\r\n\t\t\t\t\\caption{Sample simplicial complex structure using the Vietoris-Rips construction. As $\\epsilon$ varies, the homology groups of the complex change.}\r\n\t\t\\end{figure}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t%----------------------------------------------\r\n\t\\subsection{Persistent Homology Representations}\r\n\t%----------------------------------------------\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Persistence Diagrams}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item This is a representation of the persistent homology information.\r\n\t\t\t\\item Persistence Diagrams (PDs) can be encoded in terms of two-dimensional vectors $(b_i,d_i)$, where $b_i$ is the birth and $d_i$ is the death of the $i^{\\text{th}}$ homology feature.\r\n\t\t\t\\item PDs have a natural metric associated with them called the \\textbf{bottleneck distance}, which is numerically stable and computationally efficient to compute.\r\n\t\t\t\\item We often design algorithms for TDA on PDs under the bottleneck distance.\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Persistence Diagram Example}\r\n\t\t\r\n\t\t\t\t\t\t\\begin{figure}\r\n\t\t\t\t\\centering\r\n\t\t\t\t\\includegraphics[scale=0.5]{images/pd.png}\r\n\t\t\t\t\\caption{Sample persistence diagram visualized in $\\rr^n$ as a set of (birth,death) pairs.}\r\n\t\t\\end{figure}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Persistence Barcodes}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Persistent Barcodes are an alternative representation to PDs, mostly used for visualization.\r\n\t\t\t\\item Instead of considering $(b_i,d_i)$ pairs as points, we look at them as segments/intervals and organize them with respect to the $k^{\\text{th}}$ Betti number ($y$-axis).\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\t\t\t\t\t\\begin{figure}\r\n\t\t\t\t\\centering\r\n\t\t\t\t\\includegraphics[scale=0.5]{images/barcode.png}\r\n\t\t\t\t\\caption{Sample barcode. As $\\epsilon$ varies, the homology groups of the complex change and this is captured by line segments representing $[$birth, death$]$ intervals.}\r\n\t\t\\end{figure}\r\n\t\t\r\n\t\t\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Persistence Images}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item Persistence Images (PIs) provide a vector representation of PDs stable with respect to input noise, which are efficient to compute, and whose resolution can be adjusted.\r\n\t\t\t\\item The user makes three choices for this representation:\r\n\t\t\t\\begin{itemize}\r\n\t\t\t\t\\item Resolution of the output PI.\r\n\t\t\t\t\\item Probability distribution which affects noise stability (e.g., Gaussian, Rayleigh).\r\n\t\t\t\t\\item Weighting function, which controls the relative importance of persistence coordinates (e.g., sigmoidal functions).\r\n\t\t\t\\end{itemize}\r\n\t\t\t\\item PIs lend themselves to being studied under traditional image processing techniques as well as convolutional neural networks.\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Persistence Image Example}\r\n\t\t\r\n\t\t\t\t\t\t\\begin{figure}\r\n\t\t\t\t\\centering\r\n\t\t\t\t\\includegraphics[scale=0.35]{images/persimg.png}\r\n\t\t\t\t\\caption{Sample persistence image pipeline from PD to Persistence Surface to PI at varying resolutions.}\r\n\t\t\\end{figure}\r\n\t\t\\end{frame}\r\n\t\t\r\n\t\t\\begin{frame}\r\n\t\t\\frametitle{Open Source Tools for Computing Persistent Homology}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item There have been a number of open source software packages developed for the efficient computation of persistent homology of data.\r\n\t\t\t\\item These have been developed mostly by academic mathematicians in Python, C++, R, and Julia.\r\n\t\t\t\\item Most popular ones include dionysus, scikit-tda, gudhi, ripser, and mapper.\r\n\t\t\t\\item A full list of these tools has been compiled by \\href{https://www.math.colostate.edu/~adams/advising/appliedTopologySoftware/}{Henry Adams}.\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\t\\end{frame}", "meta": {"hexsha": "49492d971925493f563769e31d2673dd13858f1c", "size": 18753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/Intro_TDA.tex", "max_stars_repo_name": "river-reger/topological-data-analysis-demo", "max_stars_repo_head_hexsha": "e72547d2f093ca221c83993adb6a85424ff7f515", "max_stars_repo_licenses": ["MIT"], "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/Intro_TDA.tex", "max_issues_repo_name": "river-reger/topological-data-analysis-demo", "max_issues_repo_head_hexsha": "e72547d2f093ca221c83993adb6a85424ff7f515", "max_issues_repo_licenses": ["MIT"], "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/Intro_TDA.tex", "max_forks_repo_name": "river-reger/topological-data-analysis-demo", "max_forks_repo_head_hexsha": "e72547d2f093ca221c83993adb6a85424ff7f515", "max_forks_repo_licenses": ["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.9592391304, "max_line_length": 285, "alphanum_fraction": 0.6766384045, "num_tokens": 5431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6920564813827066}}
{"text": "% !TEX root = ../main.tex\n\nIn this chapter, we sketch some adaptations of the set reconciliation algorithm to related problems. \\Cref{general-partitions} considers more general partitioning strategies than one-dimensional ranges. \\Cref{maps} presents how to reconcile key-value mappings. \\Cref{set-mirror} shows an asymmetric variant of the protocol, mirroring the contents of a set or map held at a primary node to a replica node. \\Cref{authenticated} demonstrates how our data structures for fingerprint computations can also serve as simple authenticated data structures.\n\n\\section{Higher-Dimensional Ranges}\n\\label{general-partitions}\n\nThe set reconciliation algorithm recursively partitions the item sets of both nodes by splitting the sets into successive ranges. But for the correctness of the algorithm, the exact mechanism by which partitions are chosen is irrelevant. All that is necessary is that in each communication round, when receiving a mismatching fingerprint for some non-empty $S \\subseteq U$, the node chooses a partition $\\disjointunion{S_0}{\\disjointunion{S_1}{\\disjointunion{\\ldots}{S_k}}} = S$ of $S$, and then communicates to the other node the choice of the partition and how its items are distributed among the individual sets.\n\nPartitioning into successive ranges over a linearly ordered set has some nice properties: It can be applied to virtually any set since one can always arbitrarily define a linear order. The choice of the partition and the way the items are distributed among the sets can be encoded and transmitted efficiently. And finally, when receiving an arbitrarily chosen partition into successive ranges, a node can always efficiently compute the items it holds within that partition as well as the fingerprint over these items.\n\nAs long as nodes always want to synchronize the complete sets they hold, this is completely sufficient. But more elaborate partitioning strategies can become attractive if nodes might wish to only synchronize certain subsets. The partitioning mechanism effectively dictates which such subsets can be described, taking on the role of a query language. A natural next step is to look for more powerful partitioning mechanisms that still admit efficient fingerprint computation.\n\nWe now give one such partitioning scheme by generalizing the one-dimensional ranges of the original presentation of the algorithm to $k$-dimensional ranges. Let $U$ be a finite set of items, and let $\\preceq_0, \\preceq_1, \\ldots, \\preceq_{k-1}$ be linear orders over $U$. A \\defined{$k$-dimensional range} is a $k$-tuple $((x_0, y_0), (x_1, y_1), \\ldots, (x_{k-1}, y_{k-1}))$ with $x_i \\preceq_i y_i$. Given some $S \\subseteq U$, the items from $S$ in this range are all items $v \\in S$ such that $x_i \\preceq_i v \\preceq_i y_i$ for all $0 \\leq i < k$. Note that for $k = 1$ this is equivalent to the ranges used in previous chapters. The reconciliation protocol needs to be adapted so that messages include the $k$-dimensional range boundaries, but otherwise no changes are required.\n\nFingerprints can be computed efficiently by storing the set as a (balanced) $k$-d tree~\\cite{bentley1975multidimensional}. As $k$-d trees are binary trees, the labels from \\cref{fingerprints} can be used without any modification. Fingerprint computation still works by traversing the tree, alternating between the dimensions just as in e.g. a $k$-d tree item lookup. For $k = 1$, this yields exactly the algorithms of \\cref{fingerprints}.\n\nGeneralized partitioning schemes, including $k$-dimensional ranges, can not only be applied to the regular set reconciliation protocol, but also to all modifications discussed in the further sections.\n\n\\section{Map Reconciliation}\n\\label{maps}\n\nA key-value mapping, i.e. a partial function $\\partialfun{\\m}{K}{V}$ with a finite domain from some set of keys $K$ to a set of values $V$, can be reconciled by reconciling the set $\\set{(k, v) \\mid \\text{$k \\in \\domain(\\m)$ and $v = \\m(k)$}}$. After this reconciliation, a node may have obtained two pairs $(k, v), (k, v')$ if the two nodes mapped the same key $k$ to distinct values $v, v'$, so the resulting set would not correspond to an updated map. In those cases, both nodes compute the single new image of $k$ as $\\f(v, v')$, where $\\fun{\\f}{V \\times V}{V}$ is some function known to all participating nodes.\n\nParticularly interesting are cases where $\\f$ can be computed via another interactive protocol. If for example $V$ consists of the fingerprints of finite subsets of some universe $U$, and $\\f(v, v')$ is defined to be the fingerprint of the union of the two sets whose fingerprints are $v$ and $v'$, then the two nodes can run a set reconciliation session to efficiently obtain the union. Viewed more abstractly, when reconciling a map, the values can be reconciled via arbitrary nested protocol invocations.\n\n\\section{Set and Map Mirroring}\n\\label{set-mirror}\n\nWe based the presentation of our synchronization approach on set reconciliation because it is a symmetric problem where both nodes use identical algorithms to compute identical types of messages. A related, asymmetric problem is that of a \\defined{replica} node setting its locally stored set to that of a \\defined{primary} node, utilizing similarity between the two initial sets to minimize the communication complexity. The approach of recursively exchanging fingerprints for subsets of decreasing size can be modified to solve this \\defined{set mirroring} problem.\n\nThe primary node can run exactly the same protocol as that for such reconciliation. The replica node uses a slightly modified version. Whenever it receives a range item set, it adds the received items to its local set as usual, but then it deletes all item it holds within that range which were not part of the received range item set. Whenever the replica node sends a range item set, it sends an empty one.\n\nThe complexity analysis is identical to that of the set reconciliation protocol, the correctness argument is analogous: ranges with equal fingerprints are already correctly mirrored if no fingerprint collisions occurred, exchanging range item sets correctly mirrors all items within that range, and large ranges with non-equal fingerprints can be handled recursively because mirroring the partitions of a set results in mirroring the whole set.\n\nJust as for reconciliation, maps can be mirrored by interpreting them as sets of key-value pairs. Mirroring maps has some interesting use cases, for example filesystems can be regarded as maps from paths to strings. The efficient creation of backups then becomes the problem of mirroring such a map onto a backup server that may already hold a similar, older backup. An equivalent problem is that of efficiently distributing source code updates from a server to clients which may hold old versions of the source code.\n\n\\section{Authenticated Data Structures}\n\\label{authenticated}\n\nAuthenticated data structures solve the problem of outsourcing data structure membership queries processing to untrusted replicas rather than processing all queries at the original trusted data source. The trusted source publishes a short digest to a client. The client can then send a query to a replica, which answers with the result and a small certificate which together with the digest proves that the answer is indeed correct. For more details on this three-party model and pointers to the rich literature on the topic, we refer to~\\cite{martel2004general}.\n\nMerkle trees form a simple authenticated set. The root label is the digest, and the certificate for an affirmative membership query consists of the labels of the children of the vertices on the path from the root to the item in question. These labels can be used to recompute the root label, proving that the item is part of the original tree. Fabricating a sequence of labels to fake inclusion of an item amounts to breaking the hash function. Non-membership queries can be authenticated by providing certificates for tree membership of items stored in adjacent leaves such that one is less than and one is greater than the item in question.\n\nOur examination of randomized data structures was driven by the need for Merkle-like properties, so it is not very surprising that they can also be used as authenticated data structures. Indeed~\\cite{naor2000certificate} mentions treaps as an alternative to regular Merkle trees. Monoidal labels based on Cayley hash functions remove the need for a specific tree shape to be maintained. Skip lists as authenticated data structures have been studied in~\\cite{goodrich2000efficient}, but they require the hash function to be commutative. Our construction removes this assumption.\n", "meta": {"hexsha": "9a35dccecbd86f46ad8f7ba22986878e3893e8e3", "size": 8697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/other_data_structures.tex", "max_stars_repo_name": "AljoschaMeyer/master_thesis", "max_stars_repo_head_hexsha": "01bd42dd4cc51078e1526ac7197c5294551beafb", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-30T11:02:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-30T11:02:56.000Z", "max_issues_repo_path": "chapters/other_data_structures.tex", "max_issues_repo_name": "AljoschaMeyer/master_thesis", "max_issues_repo_head_hexsha": "01bd42dd4cc51078e1526ac7197c5294551beafb", "max_issues_repo_licenses": ["CC0-1.0"], "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/other_data_structures.tex", "max_forks_repo_name": "AljoschaMeyer/master_thesis", "max_forks_repo_head_hexsha": "01bd42dd4cc51078e1526ac7197c5294551beafb", "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": 189.0652173913, "max_line_length": 784, "alphanum_fraction": 0.7978613315, "num_tokens": 1862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.7981867729389245, "lm_q1q2_score": 0.6920564806238888}}
{"text": "\\chapter{Expectation values}\n\n\\section*{3.1. Flip until heads}\n\\addcontentsline{toc}{section}{3.1. Flip until heads}\nIn Example 2 on page 136, we found that if you flip a coin until you get a Heads, the\nexpectation value of the total number of coins is\n\\begin{equation*}\\tag{3.89}\n    \\frac{1}{2} \\cdot 1 + \\frac{1}{4} \\cdot 2 + \n    \\frac{1}{8} \\cdot 3 + \\frac{1}{16} \\cdot 4 + \\frac{1}{32} \\cdot 5 \\ldots \n\\end{equation*}\n\nWe claimed that this sum equals 2. Demonstrate this by writing the sum as a\ngeometric series starting with 1/2, plus another geometric series starting\nwith 1/4, and so on. You can use the fact that the sum of a geometric series\nwith first term $a$ and ratio $r$ is $a/(1-r)$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    It can be easily seen that the general term of the sum is $\\frac{n}{2^n}$, so\n    \\[\n        S_n = \\frac{1}{2} \\cdot 1 + \\frac{1}{4} \\cdot 2 + \\frac{1}{8} \\cdot 3 + \\frac{1}{16} \\cdot 4 + \n        \\frac{1}{32} \\cdot 5 + \\ldots + \\frac{1}{2^n} \\cdot n\n        = \\sum_{k = 1}^{n} \\frac{n}{2^n}\n    \\] \n\n\n    We rewrite the sum and observe the suggested pattern:\n    \\begin{align*}\n        \\frac{1}{2} + \\frac{2}{4} + \\frac{3}{8} + \\ldots + \\frac{n}{2^n} \n        &= \\bigg(\\frac{1}{2} + \\frac{1}{4} + \\frac{1}{8} + \\ldots + \\frac{1}{2^n}\\bigg)\n            + \\bigg(\\frac{1}{4} + \\frac{1}{8} + \\ldots + \\frac{1}{2^n}\\bigg) + \\ldots\n            + \\bigg(\\frac{1}{2^{n - 1}} + \\frac{1}{2^n}\\bigg) + \\frac{1}{2^n} \\\\\n        &= \\sum_{k = 1}^{n}\\bigg(\\frac{1}{2}\\bigg)^k + \\sum_{k = 2}^{n}\\bigg(\\frac{1}{2}\\bigg)^k + \\ldots\n            + \\sum_{k = n - 1}^{n}\\bigg(\\frac{1}{2}\\bigg)^k + \\sum_{k = n}^{n}\\bigg(\\frac{1}{2}\\bigg)^k \n    \\end{align*}\n\n    By observing the fact that the sums are actually geometric series with the ratio $r = \\frac{1}{2}$\n    and the first term $a = \\frac{1}{2^k}$, we obtain:\n    \\[\n        \\sum_{k = p}^{n} \\bigg(\\frac{1}{2}\\bigg)^k = \\frac{\\big(\\frac{1}{2}\\big)^p}{1 - \\frac{1}{2}} \n        = \\bigg(\\frac{1}{2}\\bigg)^{p - 1}\n    \\] \n\n    Therefore, by rewriting the sum using the last expression and then applying the geometric\n    series result again, we get our desired result:\n    \\[\n        S = \\bigg(\\frac{1}{2}\\bigg)^0 + \\bigg(\\frac{1}{2}\\bigg)^1 + \\ldots + \\bigg(\\frac{1}{2}\\bigg)^{n - 1}\n        = \\sum_{k = 0}^{n - 1} \\bigg(\\frac{1}{2}\\bigg)^k \n        = \\frac{1}{1 - \\frac{1}{2}} = 2\n    \\] \n\\end{proof}\n\n\\section*{3.2. HT waiting time}\n\\addcontentsline{toc}{section}{3.2. HT waiting time}\nWe know from Example 2 on page 136 that the expected number of flips required to obtain a Heads is 2. \nWhat is the expected number of flips required to obtain a Heads and a Tails in succession (in that order)?\n\n\\vspace{1em}\n\n\\begin{proof}\n    Since the first flip in the succession has to be Heads, we flip the coin until we obtain a Heads. \n    It is known that the expected number of flips for that to happen is 2. Now, we need to obtain a \n    Tails. Since Heads and Tails are equally likely in a fair coin flip, the expected number of flips\n    needed to obtain Tails is also 2. Therefore, the expected number of flips needed to obtain a \n    Heads and Tails succession (in this order) is $2 + 2 = 4$.\n\\end{proof}\n\n\\section*{3.3. Sum of dependent variables}\n\\addcontentsline{toc}{section}{3.3. Sum of dependent variables}\nConsider the example on page 137, but now let $X$ and $Y$ be dependent in the following\nmanner: If $Y = 1$, then it is always the case that $X = 1$. If  $Y = 2$, then it is always the\ncase that $X = 2$. If $Y = 3$, then there are equal chances of $X$ being 1 or 2. If we assume that \n$Y$ takes on the values 1, 2, and 3 with equal probabilities of 1/3, then you can quickly show\nthat $X$ takes on the values 1 and 2 with equal probabilities of 1/2. So we have reproduced\nthe probabilities in the original example. Show (by explicitly calculating the probabilities of\nthe various outcomes) that in the present scenario where $X$ and $Y$ are dependent, the relation\n$E(X + Y) = E(X) + E(Y)$ still holds.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Since we know that the $X$ takes on the values 1, 2 with equal probabiliy, we can easily find that:\n     \\[\n         E(X) = p(X = 1) \\cdot 1 + p(X = 2) \\cdot 2 = \\frac{1}{2} + \\frac{1}{2} \\cdot 2 =\\frac{3}{2}\n    \\] \n\n    We do the same for $Y$ to obtain:\n    \\[\n        E(Y) = p(Y = 1) \\cdot 1 + p(Y = 2) \\cdot 2 + p(Y = 3) \\cdot 3 \n        = \\frac{1}{3} + \\frac{2}{3} + \\frac{3}{3} = 2\n    \\] \n\n    Therefore, it is straightforward that:\n    \\[\n        E(X) + E(Y) = \\frac{3}{2} + 2 = \\frac{7}{4}\n    \\] \n\n    We continue by computing $E(X + Y)$. We'll do that by analyzing the obtained cases from the perspective\n    of  $Y$. \n    \\begin{enumerate}[(1)]\n        \\item We know that there is a  $\\frac{1}{3}$ probability that $Y = 1$ and that if $Y = 1$, then $X = 1$.\n            As a result, there is a $\\frac{1}{3}$ probability that $Y = 1 \\text{ and } X = 1$.\n\n        \\item Analogously, we find that there is a $\\frac{1}{3}$ probability that $Y = 2$ and $X = 2$.\n\n        \\item For $Y = 3$, $X$ takes on the values $1, 2$ with equal probabilities of $\\frac{1}{2}$. Hence,\n            ($Y = 3$ and $X = 1$) and ($Y = 3$ and $X = 2$) are equally likely with a probability \n            of $\\frac{1}{6}$.  \n    \\end{enumerate}\n\n    By looking at the described cases, we obtain the outcomes of $X + Y$ and their probabilities:\n    \\begin{enumerate}[(i)]\n        \\item $\\frac{1}{3}$ probability that $X + Y = 2$, for ($X = 1$ and $Y = 1$)\n\n        \\item $\\frac{1}{3} + \\frac{1}{6} = \\frac{1}{2}$ probability that $X + Y = 4$, for ($Y = 2$ and $X = 2$)\n    and ($Y = 3$ and  $X = 1$)\n\n    \\item $\\frac{1}{6}$ probability that $X + Y = 5$, for ($Y = 3$ a and $X = 2$)\n    \\end{enumerate}\n\n    Finally, we compute the expectation of the sum and prove the linearity of expectation:\n    \\begin{align*}\n        E(X + Y) =& P(X + Y = 2) \\cdot 2 + P(X + Y = 4) \\cdot 4 + P(X + Y = 5) \\cdot 5 \\\\\n        =& \\frac{1}{3} \\cdot 2 + \\frac{1}{2} \\cdot 4 + \\frac{1}{6} \\cdot 5 = \\frac{7}{4} = E(X) + E(Y) \n    \\end{align*}\n\\end{proof}\n\n\\section*{3.4. Playing \"unfair\" games}\n\\addcontentsline{toc}{section}{3.4. Playing \"unfair\" games}\n\\begin{enumerate}[(a)]\n    \\item Assume that later on in life, things work out so that you have more than enough money\n        in your retirement savings to take care of your needs and beyond, and that you truly\n        don't have a need for any more money. Someone offers you the chance to play a one-time\n        game where you have a 3/4 chance of doubling your money, and a 1/4 chance of losing \n        it all. If you initially have $N$ dollars, what is the expectation value of your\n        resulting amount of money if you play the game? Would you want to play it?\n\n    \\item Assume that you are stranded somewhere, and that you have only \\$10 for a \\$20 bus\n        ticket. Someone offers you the chance to play a one-time game where you have a 1/4\n        chance of doubling your money, and a 3/4 change of losing it all. What is the expectation\n        value of your resulting amount of money if you play the game? Would you want to play it?\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item Since there is a 3/4 chance of doubling the money and a 1/4 chance of losing it all,\n            the expectation value of the resulting money if playing the game is:\n            \\[\n                E(X) = \\frac{3}{4} \\cdot 2N + \\frac{1}{4} \\cdot 0 = \\frac{3N}{2}\n            \\] \n\n            Even if the expected return looks favorable, I would not play the game in the given context.\n            If I don't have a need for more money, a potential of doubling the money is dwarfed by the \n            devastating result of losing it all, so the 1/4 probability of losing the money doesn't \n            make the game appealing enough.\n\n        \\item The expected value of the resulting amount of money if playing the second game is given\n            by:\n            \\[\n                E(Y) = \\frac{3}{4} \\cdot \\$0 + \\frac{1}{4} \\cdot \\$20 = \\$5\n            \\] \n\n            Here, even if the expected return doesn't look favorable, I would play the game. The price\n            is small enough that it would be worth losing the money for a $\\frac{1}{4}$ chance of being \n            able to get the bus ticket and get home.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{3.5. Simpson's paradox}\n\\addcontentsline{toc}{section}{3.5. Simpson's paradox}\nDuring the baseball season in a particular year, player A has a higher batting average than player B.\nIn the following year, A again has a higher average than B. But to your great surprise when you \ncalculate the batting averages over the combined span of the two years, you find that A's average is\n$\\emph{lower}$ than B's! Explain, by giving a concrete example, how this is possible.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Simpson's paradox is a phenomenon in which a trend appears in several different groups of data\n    but disappears when these groups are combined. Let's consider the same setup as in the description of \n    the problem. Suppose that the batting averages in the first year are 5/10 for player A and 15/35 for\n    player B, respectively 10/20 for player A and 20/30 for player B in the second year. We can easily\n    see that if we take years individually, the averages of player A are higher than averages of player B. \n    However, if we combine the data of the two years, we get that the overall batting average \n    of player A will be lower than the overall average of player B:\n    \\[\n        \\frac{5 + 10}{10 + 20} = \\frac{1}{2} < \\frac{7}{13} = \\frac{15 + 20}{35 + 30}\n    \\] \n\\end{proof}\n\n\\section*{3.6. Variance of a product}\n\\addcontentsline{toc}{section}{3.6. Variance of a product}\nLet $X$ and $Y$ each be the result of independent (and fair) coin flips where we assign the value\n1 to Heads and 0 to Tails. Show that Var($XY$) is not equal to Var($X$)Var($Y$). \n\n\\vspace{1em}\n\n\\begin{proof}\n    Since we know that $X$ takes on the values $1, 2$ with equal probability, we easily compute the \n    variance of $X$: \n    \\[\n        \\text{Var}(X) = E[(X - \\mu_x)^2] = E\\bigg[\\bigg(X - \\frac{1}{2}\\bigg)^2\\bigg] \n        = \\frac{1}{2}\\bigg(0 - \\frac{1}{2}\\bigg)^2  + \\frac{1}{2}\\bigg(1 - \\frac{1}{2}\\bigg)^2 \n        = \\frac{1}{2} + \\frac{1}{2}\n        = \\frac{1}{4}\n    \\] \n\n    Analogously, we get the same result for Var($X$), so:\n    \\[\n        \\text{Var}(X)\\text{Var}(Y) = \\frac{1}{4} \\cdot \\frac{1}{4} = \\frac{1}{16}\n    \\] \n    \n    X and Y can be chosen in 4 ways, 3 give $XY = 0$ and one gives $XY = 1$, so $\\mu_{XY} = \\frac{1}{4}$.\n    Since all pairings are equally likely, we have that $P(XY = 0) = \\frac{3}{4}$ and\n    $P(XY = 1) = \\frac{1}{4}$. Now, the variance of the product is given by:\n    \\[\n        \\text{Var}(XY) = E[(XY - \\mu_{XY})^2] = E\\bigg[\\bigg(XY - \\frac{1}{4}\\bigg)^2\\bigg]\n        = \\frac{3}{4} \\bigg(0 - \\frac{1}{4}\\bigg)^2 + \\frac{1}{4} \\bigg(1 - \\frac{1}{4}\\bigg)^2\n        = \\frac{3}{64} + \\frac{9}{64}\n        = \\frac{3}{16}\n    \\] \n\n    In conclusion, we proved that in this setup Var($XY$) $\\neq$ Var($X$)Var($Y$).\n\\end{proof}\n\n\\section*{3.7. Variances}\n\\addcontentsline{toc}{section}{3.7. Variances}\nFor each of the three examples near the beginning of Section 3.2., show that the alternative\n$E(X^2) - \\mu^2$ form of the variance given in Eq. (3.34) leads to the same results we obtained\nin the examples.\n\n\\begin{proof}\n    \\hfill\n    \\begin{itemize}\n        \\item \\textbf{Example 1 (Die roll):} The expectation value of the six equally likely outcomes\n            of a dire roll is $\\mu = \\frac{21}{6}$, therefore $\\mu^2 = \\frac{441}{36}$. The expected value\n            of $X^2$ is:\n            \\[\n                E(X^2) = \\frac{1}{6}(1 + 4 + 9 + 16 + 25 + 36) = \\frac{91}{6}\n            \\] \n\n            Hence, the variance result is the same as using the standard formula in (3.20): \n            \\[\n                \\text{Var}(X) = E(X^2) - \\mu_X^2 = \\frac{91}{6} - \\frac{441}{36} = \\frac{105}{36} \\approx 2.92\n            \\] \n\n        \\item \\textbf{Example 2 (Coin flip):} Consider a coin flip where we assign the value 1 to Heads\n            and 0 to Tails. The expectation value of these two equally likely outcomes is $\\mu = \\frac{1}{2}$,\n            so $\\mu^2 = \\frac{1}{4}$. The expected value of $X^2$ is:\n            \\[\n                E(X^2) = \\frac{1}{2} (0 + 1) = \\frac{1}{2}\n            \\] \n\n            As a result, the variance is the same as using the standard variance form in (3.21):\n            \\[\n                \\text{Var}(X) = E(X^2) - \\mu^2 = \\frac{1}{4}\n            \\] \n\n        \\item \\textbf{Example 3 (Biased coin):} Consider a biased coins, where the probability of getting\n            Heads is $p$ and the probability of getting Tails is $1 - p \\equiv q$. If we again\n            assign the value 1 to Heads and 0 to Tails, then the expectation value is \n            $\\mu = p \\cdot 1 + (1 - p) \\cdot 0 = p$, so $\\mu^2 = p^2$. The expected value\n            of $X^2$ is:\n             \\[\n                 E(X^2) = p \\cdot 1 + q \\cdot 0 = p\n            \\] \n\n            Once again, the variance is the same as in (3.22):\n            \\[\n                \\text{Var}(X) = E(X^2) - \\mu^2 = p - p^2 = p(1 - p) = pq\n            \\] \n    \\end{itemize}\n\\end{proof}\n\n\\section*{3.8. Random walk}\n\\addcontentsline{toc}{section}{3.8. Random walk}\nConsider the following one-dimensional random walk. A person starts at the origin and\nthen takes $n$ successive steps. Each step is equally likely to be to the right or to the\nleft. All steps have the same length.\n\\begin{enumerate}[(a)]\n    \\item What is the probability that the person is located back at the \n        origin after the $n$th step?\n\n    \\item After $n$ steps, what is the standard deviation of the person's position\n        relative to the origin? (Assume that the length of each step is, say, one \n        foot).\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item We see from the beginning that a person can end up in the origin only\n            if he made the same number of steps in both directions. Therefore, it's\n            impossible to end up in the origin if $n$ is odd, so: \n            \\[\n                P(O | n = \\text{odd}) = 0\n            \\] \n\n            If $n$ is even, we\n            count the favorable cases by considering the sequence of performed steps\n            and seeing in how many ways can the left steps be placed in the sequence,\n            the right steps taking the remaining positions. So, the number\n            of ways in which the person ends up in the origin for an even $n$ is:\n             \\[\n                 \\binom{n}{\\frac{n}{2}} = \\frac{n!}{\\big(\\frac{n}{2}\\big)!\\big(\\frac{n}{2}\\big)!}\n            \\] \n\n            The number of possible step sequences is obviously $2^n$, giving us the \n            probability that is located back at the origin after the $n$th step:\n            \\[\n                P(O | n = \\text{even}) = \\frac{n!}{2^n\\big(\\frac{n}{2}\\big)!\\big(\\frac{n}{2}\\big)!}\n            \\] \n\n            By using the Law of Total Probability:\n            \\[\n                P(O) = P(O | n = \\text{even})P(n = \\text{even}) + P(O | n = \\text{odd})P(n = \\text{odd}) \n                = \\frac{n!}{2^{n+1}\\big(\\frac{n}{2}\\big)!\\big(\\frac{n}{2}\\big)!}\n            \\] \n\n        \\item Let $X$ be the distance from the origin after n steps, where steps are represented\n            by the random variables $X_i$ which take on the values $-1$ and $1$ and 2 equally likely. Then,\n            \\[\n                X = \\sum_{i = 1}^{n} X_i\n            \\] \n\n            We compute the expectation of $X^2$:\n            \\[\n                E[X^2] = E\\bigg[\\bigg(\\sum_{i = 1}^n X_i\\bigg)^2\\bigg] \n                = E\\bigg[\\bigg(\\sum_{i = 1}^n {X_i}^2 + \\sum_{j = 1}^n\\sum_{k = j+1}^n X_jX_k\\bigg)\\bigg]\n            \\] \n\n            Since $X_i$ takes on -1 and 1, then $X_i^2 = 1$, so $\\displaystyle \\sum_{i = 1}^n {X_i}^2 = n$.\n            Using this and the linearity of expectation, our expression becomes:\n            \\[\n                E[X^2] = E[n] + E\\bigg[\\sum_{j = 1}^n\\sum_{k = j+1}^n X_jX_k\\bigg]\n                = n + \\sum_{j = 1}^n\\sum_{k = j+1}^n E[X_jX_k]\n            \\] \n\n            The events $X_i$ and $X_j$ of choosing a step are independent for $i \\neq j$. From\n            this and the fact that the expected value of $X_i$ is 0, we get:\n             \\[\n                 E[x^2]= n + \\sum_{j = 1}^n\\sum_{k = j+1}^n E[X_j]E[X_k] = n\n            \\] \n\n            The mean is now given by:\n            \\[\n            \\mu = \\frac{1}{n}\\sum_{i = -n}^n i = 0\n            \\] \n\n            Finally, the standard deviation is:\n            \\[\n                \\sigma = \\sqrt{E(X^2) - \\mu^2} = \\sqrt{n}\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{3.9. Expected product, without replacement}\n\\addcontentsline{toc}{section}{3.9. Expected product, without replacement}\nConsider a set of $N$ given numbers, $a_1, a_2, \\ldots a_N$. Let the mean of these $N$ numbers\nbe $\\mu$, and let the standard deviation be $\\sigma$. Draw two numbers $X_1$ and $X_2$ \nrandomly $\\emph{without replacement}$. Show that the expectation value of their\nproduct is \n\\begin{equation*}\\tag{3.90}\n    E[X_1X_2] = \\mu^2 - \\frac{\\sigma^2}{N - 1}\n\\end{equation*}\n\n$\\emph{Hint}$: All of the $a_ia_j$ possibilities (with $i \\neq j$) are equally likely.\n\n\\vspace{1em}\n\n\\begin{proof}\n    There are $\\binom{N}{2} = \\frac{N(N - 1)}{2}$ ways of choosing $X_1$ and $X_2$, all of\n    them being equally likely, so:\n    \\[\n        E[X_1X_2] = \\frac{2}{N(N - 1)} \\sum_{i = 1}^n \\sum_{j = i + 1}^n a_ia_j\n    \\] \n\n    Seeing that\n    \\[\n        \\bigg(\\sum_{i = 1}^n a_i\\bigg)^2 = \\sum_{i = 1}^n {a_i}^2 + 2\\sum_{i = 1}^n \\sum_{j = i + 1}^n a_ia_j\n    \\] \n\n    , the expression of the expectation becomes:\n    \\[\n        E[X_1X_2] = \\frac{1}{N(N - 1)} \\bigg[\\bigg(\\sum_{i = 1}^n a_i\\bigg)^2 - \\sum_{i = 1}^n {a_i}^2\\bigg]\n    \\] \n    \n    From the formula of the mean we notice that\n    \\begin{equation*}\\tag{3.9.1}\n        N\\mu = \\sum_{i = 1}^n a_i\n    \\end{equation*}\n\n    , so then\n    \\begin{align*}\n        E[X_1X_2] = \\frac{1}{N(N - 1)} \\bigg(N^2\\mu^2 - \\sum_{i = 1}^n {a_i}^2\\bigg) \n        =& \\frac{N\\mu^2}{N - 1} - \\frac{1}{N(N - 1)}\\sum_{i = 1}^n {a_i}^2 \\\\\n        =& \\mu^2 - \\frac{1}{N(N - 1)}\\bigg(\\sum_{i = 1}^n {a_i}^2 - N\\mu^2\\bigg) \\\\\n    \\end{align*}\n\n    By rewriting the expression of the variance and using (3.9.1), we obtain:\n    \\begin{align*}\n        \\frac{\\sigma^2}{N - 1} = \\frac{1}{N(N - 1)}\\sum_{i = 1}^n (a_i - \\mu)^2\n        =& \\frac{1}{N(N - 1)} \\bigg(\\sum_{i = 1}^n {a_i}^2 - 2\\mu \\sum_{i = 1}^n a_i + N\\mu^2\\bigg) \\\\\n        =& \\frac{1}{N(N - 1)} \\bigg(\\sum_{i = 1}^n {a_i}^2 - 2N\\mu^2 + N\\mu^2\\bigg) \\\\\n        =& \\frac{1}{N(N - 1)} \\bigg(\\sum_{i = 1}^n {a_i}^2 - N\\mu^2\\bigg) \\\\\n    \\end{align*}\n\n    In conclusion, by substituting the last expression in the expectation's form, we see\n    that\n    \\begin{equation*}\\tag{3.90}\n        E[X_1X_2] = \\mu^2 - \\frac{\\sigma^2}{N - 1}\n    \\end{equation*}\n\\end{proof}\n\n\\section*{3.10. Standard deviation of the mean, without replacement}\n\\addcontentsline{toc}{section}{3.10. Standard deviation of the mean, without replacement}\nConsider a set of $N$ given numbers, $a_1, a_2, \\ldots, a_N$. Let the mean of these\n$N$ numbers be $\\mu$ and let the standard deviation be $\\sigma$. Draw a sample\nof $n$ numbers $X_i$, randomly $\\emph{without replacement}$, and calculate \ntheir sample mean. Show that the variance of the sample mean is given by\n\\begin{equation*}\\tag{3.91}\n    E\\bigg[\\bigg(\\frac{1}{n}\\sum_{i = 1}^n X_i - \\mu\\bigg)^2\\bigg] \n    = \\frac{\\sigma^2}{n}\\bigg(1 - \\frac{n-1}{N-1}\\bigg)\n\\end{equation*}\n\n\\vspace{1em}\n\n\\begin{proof}\n    We start by expanding the square in the expression:\n\n    \\begin{align*}\n        E\\bigg[\\bigg(\\frac{1}{n}\\sum_{i = 1}^n X_i - \\mu\\bigg)^2\\bigg]\n        =& E\\bigg[\\frac{1}{n^2}\\bigg(\\sum_{i = 1}^n X_i\\bigg)^2 \n                              - \\frac{2\\mu}{n}\\sum_{i = 1}^n X_i + \\mu^2\\bigg] \\\\\n        =& E\\bigg[\\frac{1}{n^2}\\sum_{i = 1}^{n} {X_i}^2 + \\frac{2}{n^2}\\sum_{i = 1}^n\\sum_{j = i + 1}^n X_iX_j\n                              - \\frac{2\\mu}{n}\\sum_{i = 1}^n X_i + \\mu^2\\bigg] \\\\\n    \\end{align*}\n\n    By using the linearity of expectation, the expression becomes:\n    \\[\n        E\\bigg[\\bigg(\\frac{1}{n}\\sum_{i = 1}^n X_i - \\mu\\bigg)^2\\bigg] =\n        \\frac{1}{n^2}\\sum_{i = 1}^nE[{X_i}^2] + \\frac{2}{n^2}\\sum_{i = 1}^n\\sum_{j = i + 1}^n E[X_iX_j]\n        - \\frac{2\\mu}{n} \\sum_{i = 1}^n E[X_i] + \\mu^2\n    \\] \n\n    We assume that the $n$ numbers $X_i$ are equally likely to be extracted, so\n    we denote $X$ such that for all $1 \\leq i \\leq n$,\n    \\begin{align*}\n        E[X_i] &= E[X] = \\mu \\\\\n        E[{X_i}^2] &= E[X^2] = \\mu^2 + \\sigma^2\n    \\end{align*}\n    $X_iX_j$ are also distributed the same. Using (3.90), we denote $X_aX_b$ so that \n    for all $1 \\leq i \\leq j \\leq n$,\n    \\[\n        E[X_iX_j] = E[X_aX_b] = \\mu^2 - \\frac{\\sigma^2}{N - 1}\n    \\] \n\n    By using the proposed substitutions, our expression becomes:\n    \\begin{align*}\n        E\\bigg[\\bigg(\\frac{1}{n}\\sum_{i = 1}^n X_i - \\mu\\bigg)^2\\bigg]\n        =& \\frac{1}{n^2}\\sum_{i = 1}^nE[{X}^2] + \\frac{2}{n^2}\\sum_{i = 1}^n\\sum_{j = i + 1}^n E[X_aX_b]\n            - \\frac{2\\mu}{n} \\sum_{i = 1}^n E[X] + \\mu^2 \\\\\n        =& \\frac{1}{n}\\bigg[\\mu^2 + \\sigma^2 + (n - 1) \n            \\bigg(\\mu^2 - \\frac{\\sigma^2}{N - 1}\\bigg)\\bigg] - \\mu^2 \\\\\n        =& \\mu^2 \\bigg(\\frac{1}{n} + \\frac{n-1}{n} - 1\\bigg) + \n            \\sigma^2\\bigg(\\frac{1}{n} - \\frac{n-1}{n(N - 1)}\\bigg) \n    \\end{align*}\n\n    The coefficient of $\\mu^2$ is 0, so we obtain the desired result:\n    \\begin{equation*}\\tag{3.91}\n        E\\bigg[\\bigg(\\frac{1}{n}\\sum_{i = 1}^n X_i - \\mu\\bigg)^2\\bigg] \n        = \\frac{\\sigma^2}{n}\\bigg(1 - \\frac{n-1}{N-1}\\bigg)\n    \\end{equation*}\n\\end{proof}\n\n\n\\section*{3.11. Biased sample standard deviation}\n\\addcontentsline{toc}{section}{3.11. Biased sample standard deviation}\nWe mentioned on page 163 that the sample standard deviation $s$ is a $\\emph{biased}$\nestimator of the distribution standard deviation $\\sigma$. The basic reason for this\nis that  the square root operation is nonlinear, which means that the square\nroot of the average of a set of numbers isn't equal to the average of their\nsquare roots. For example, the average of 1.1 and 0.9 is 1, but the average of \n$\\sqrt{1.1}$ and  $\\sqrt{0.9}$ isn't 1. It is smaller than 1. Let's give a general\nproof that  $E[s] \\leq \\sigma$ (unlike  $E[s^2] = \\sigma$).\n\nIf we calculate the sample variances for a large number $N$ of sets of $n$ numbers,\nthen the $E[s^2] = \\sigma^2$ equality in Eq. (3.74) tells us that in the $N \\to \\infty$ \nlimit, we have\n\\begin{equation*}\\tag{3.92}\n    \\frac{s_1^2 + s_2^2 + \\ldots + s_N^2}{N} = \\sigma^2\n\\end{equation*}\n\nOur goal is to show that\n\\begin{equation*}\\tag{3.93}\n    \\frac{s_1 + s_2 + \\ldots + s_N}{N} \\leq \\sigma\n\\end{equation*}\nin the $N \\to \\infty$ limit. To demonstrate this, square both sides of Eq. (3.93)\nand make copious use of the arithmetic-geometric-mean inequality, $\\sqrt{ab} \\leq (a+b)/2$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let us define the series $(a_N)_{N \\geq 1}, (b_N)_{N \\geq 1} \\subset \\mathbb{N}$, with\n\n    \\vspace{1em}\n    \\begin{minipage}{0.5\\textwidth}\n        \\[\n            a_N = \\frac{s_1 + s_2 + \\ldots + s_N}{N}\n        \\]\n    \\end{minipage}\n    \\begin{minipage}{0.5\\textwidth}\n        \\[\n            b_N = \\sqrt{\\frac{s_1^2 + s_2^2 + \\ldots + s_N^2}{N}} \n        \\] \n    \\end{minipage}\n    \\vspace{1em}\n\n    We'll prove that $a_N \\leq b_N$, for all $N \\in \\mathbb{N}$. The starting point is \n    the inequality\n    \\[\n        \\sum_{i = 1}^N \\sum_{j = i + 1}^N (s_i - s_j)^2 \\geq 0\n    \\] \n    which is true, since a sum of squares is always nonnegative. By expanding\n    the sum, we get that\n    \\[\n        (N - 1)\\sum_{i = 1}^{N}s_i^2 - \\sum_{i = 1}^N \\sum_{j = i + 1}^N 2s_is_j \\geq 0\n    \\] \n    After moving the second term in the right-hand side of the inequality and then\n    adding $\\displaystyle \\sum_{i = 1}^{N} s_i^2$ to both sides, the expression becomes:\n    \\[\n        N\\sum_{i = 1}^N s_i^2 \\geq \\sum_{i = 1}^N s_i^2 + \\sum_{i = 1}^N \\sum_{j = i + 1}^N 2s_is_j\n    \\] \n\n    The member on the right is the expansion of the squared sum of $s_i$'s, so\n    \\[\n        N\\sum_{i = 1}^N s_i^2 \\geq \\bigg(\\sum_{i = 1}^{N} s_i\\bigg)^2\n    \\] \n\n    We divide both sides by $N^2 > 0$ and. Then,\n    \\[\n        \\frac{1}{N}\\sum_{i = 1}^N s_i^2 \\geq \\bigg(\\frac{1}{N}\\sum_{i = 1}^{N} s_i\\bigg)^2\n    \\] \n\n    The next step is applying the squared root operation on both sides of the expression.\n    Since the squared root function is increasing, the inequality is preserved:\n    \\[\n        \\bigg(\\frac{1}{N}\\sum_{i = 1}^N s_i^2\\bigg)^{\\frac{1}{2}} \\geq \\frac{1}{N}\\sum_{i = 1}^{N} s_i\n    \\] \n\n    We expand the sum and see that we find $a_N$ and $b_N$ :\n    \\[\n        \\sqrt{\\frac{s_1^2 + s_2^2 + \\ldots s_N^2}{N}} = b_N \\geq a_N = \\frac{s_1 + s_2 + \\ldots + s_N}{N}\n    \\] \n\n    Therefore, we proved that $a_N \\leq b_N$, for all $N \\in \\mathbb{N}$.\n\n    \\vspace{1em}\n\n    Now, we know that:\n    \\[\n        a_N \\leq b_N, \\forall N \\in \\mathbb{N} \\implies \\lim_{N \\to \\infty} a_N \\leq \\lim_{N \\to \\infty} b_N\n    \\] \n\n    By substituting the actual values of $a_N$ and $b_N$, we get:\n    \\[\n        \\lim_{N \\to \\infty} \\frac{s_1 + s_2 + \\ldots + s_N}{N}\n        \\leq \\lim_{N \\to \\infty} \\sqrt{\\frac{s_1^2 + s_2^2 + \\ldots + s_N^2}{N}} \n    \\] \n\n    By using the continuity of the square root and then substituting with (3.92) in the\n    right-hand side member, we obtain the desired result:\n    \\begin{equation*}\\tag{3.93}\n        \\lim_{N \\to \\infty} \\frac{s_1 + s_2 + \\ldots + s_N}{N} \\leq \\sigma\n    \\end{equation*}\n\\end{proof}\n\n\\section*{3.13. Sample variance for two dice rolls}\n\\addcontentsline{toc}{section}{3.13. Sample variance for two dice rolls}\n\\begin{enumerate}[(a)]\n    \\item We know from the first example in Section 3.2 that the variance of a\n        single die roll is $\\sigma^2 = 2.92$. If you use Eq. (3.73) to\n        calculate the sample variance  $s^2$ for $n = 2$ dice rolls,\n        the expected value of $s^2$ should be $\\sigma^2 = 2.92$,\n        according to Eq. (3.74). By considering the 36 equally\n        likely pairs of dice in Table 1.5, verify that this is indeed the case.\n\n    \\item Using the information you generated from Table 1.5, calculate Var($s^2$).\n        Then show that the result agrees with the expression of Var($s^2$) in\n        Eq. (3.94), with $n = 2$.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n\n    \\begin{enumerate}[(a)]\n        \\item By using (3.74) for $n = 2$, our sample variance is:\n             \\[\n                 s^2 = \\frac{1}{n - 1}\\sum_{i = 1}^n (x_i - \\overline{x})^2\n                 = (x_1 - \\overline{x})^2 + (x_2 - \\overline{x})^2\n            \\] \n\n        Using the fact that $\\overline{x} = \\frac{1}{2}(x_1 + x_2)$, we\n        can easily prove that \n        \\[\n            s^2 = \\frac{(x_1 - x_2)^2}{2}\n        \\] \n\n        Now, we analyze each one of the 36 possible dice roll pairs and analyze their sample variances.\n        We have 6 cases: \n        \\begin{enumerate}[(1)]\n            \\item $x_1$ and $x_2$ are equal. There are 6 such cases, with $s^2 = 0$.\n\n            \\item The difference between $x_1$ and $x_2$ is 1. There are $5 \\cdot 2 = 10$ \n                such roll pairs, with $s^2 = \\frac{1}{2}$\n\n            \\item The difference between $x_1$ and $x_2$ is 2. There are $4 \\cdot 2 = 8$ \n                such roll pairs, with $s^2 = 2$\n\n            \\item The difference between $x_1$ and $x_2$ is 3. There are $3 \\cdot 2 = 6$ \n                such roll pairs, with $s^2 = \\frac{9}{2}$.\n\n            \\item The difference between $x_1$ and $x_2$ is 4. There are $2 \\cdot 2 = 4$ \n                such roll pairs, with $s^2 = 8$.\n\n            \\item The difference between $x_1$ and $x_2$ is 5. There are $1 \\cdot 2 = 2$ \n                such roll pairs, with $s^2 = \\frac{25}{2}$.\n        \\end{enumerate}\n\n        Therefore, the expected value of the sample variance $s^2$ for $n = 2$ is:\n        \\[\n            E[s^2] = \\bigg(\\frac{6}{36} \\cdot 0\\bigg) + \\bigg(\\frac{10}{36} \\cdot \\frac{1}{2}\\bigg)\n                  + \\bigg(\\frac{8}{36} \\cdot 2\\bigg) + \\bigg(\\frac{6}{36} \\cdot \\frac{9}{2}\\bigg) \n                  + \\bigg(\\frac{4}{36} \\cdot 8\\bigg) + \\bigg(\\frac{2}{36} \\cdot \\frac{25}{2}\\bigg) \n                  = \\frac{88}{36} \\approx 2.92\n        \\]\n        which matches the expected result.\n\n    \\vspace{1em}\n\n    \\item The variance of the sample variance is given by:\n        \\begin{align*}\n            \\text{Var}(s^2) = E[(s^2 - 2.92)^2]\n               &= \\bigg[\\frac{6}{36} \\cdot (0 - 2.92)^2\\bigg] \n                + \\bigg[\\frac{10}{36} \\cdot (0.5 - 2.92)^2\\bigg]\n                + \\bigg[\\frac{8}{36} \\cdot (2 - 2.92)^2\\bigg] \\\\ \n               &+ \\bigg[\\frac{6}{36} \\cdot (4.5 - 2.92)^2\\bigg]\n                + \\bigg[\\frac{4}{36} \\cdot (8 - 2.92)^2\\bigg]\n                + \\bigg[\\frac{2}{36} \\cdot (12.5 - 2.92)^2\\bigg] \\\\\n               &\\approx 11.62\n        \\end{align*}\n\n        The fourth-order mean $\\mu_4$ is\n        \\begin{align*}\n            \\mu_4 = E[(X - \\mu)^4] \n            &= \\frac{1}{6}\\big[(1 - 3.5)^4 + (2 - 3.5)^4 + (3 - 3.5)^4 \n                + (4 - 3.5)^4 + (5 - 3.5)^4 + (6 - 3.5)^4] \\\\\n            &\\approx 14.73\n        \\end{align*}\n\n        Eq. (3.94) is given by\n        \\begin{equation*}\\tag{3.94}\n            \\text{Var}(s^2) = \\frac{1}{n}\\bigg[\\mu_4 - \\sigma^2\\bigg(\\frac{n-3}{n-1}\\bigg)\\bigg]\n        \\end{equation*}\n        so by plugging the numbers, we see that: \n        \\[\n            \\text{Var}(s^2) = \\frac{1}{2}(14.73 + {2.92}^2) = 11.62\n        \\] \n        which matches the expected result.\n    \\end{enumerate}\n\\end{proof}t\n", "meta": {"hexsha": "7e4dfc992a3ea58062b7b42e629f5cb8530a370e", "size": 29834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter3_expectation_values.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/chapter3_expectation_values.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/chapter3_expectation_values.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": 43.8735294118, "max_line_length": 112, "alphanum_fraction": 0.5669705705, "num_tokens": 10628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8670357512127873, "lm_q1q2_score": 0.6920564724455864}}
{"text": "\\section{Edge homomorphisms, transgression}\nRecall the Serre spectral sequence for a fibration $F\\to E\\to B$ has $E^2$-page\ngiven by\n$$\nE^2_{s,t} = H_s(B;H_t(F)) \\Rightarrow H_{s+t}(E).\n$$\nIf $B$ is path-connected, $\\widetilde{H}_t(F) = 0$ for $t<q$,\n$\\widetilde{H}_s(B) = 0$ for $s<p$, and $\\pi_1(B)$ acts trivially on\n$H_\\ast(F)$, we showed that there is a long exact sequence (the Serre exact\nsequence)\n\\begin{equation}\\label{serre-exact}\n    H_{p+q-1}(F)\\xrightarrow{\\bullet} H_{p+q-1}(E)\\to H_{p+q-1}(B)\\to\n    H_{p+q-2}(F)\\to\\cdots\n\\end{equation}\nLet us attempt to describe the arrow marked by $\\bullet$. %If $t>q$, we know\n\nLet $(E^r_{p,q},d^r)$ be any spectral sequence such that $E^r_{p,q} = 0$ if\n$p<0$ or $q<0$; such a spectral sequence is called a \\emph{first quadrant}\nspectral sequence. The Serre spectral sequence is a first quadrant spectral\nsequence. In a first quadrant spectral sequence, the $d^2$-differential\n$d^2:E^2_{0,t}\\to E^2_{-2,t+1}$ is zero, since $E^2_{s,t}$ vanishes for $s<0$.\nThis means that $H_t(F) = H_0(B;H_t(F)) = E^2_{0,t}$ surjects onto $E^3_{0,t}$.\nArguing similarly, this surjects onto $E^4_{0,t}$. Eventually, we find that\n$E^{r}_{0,t} \\simeq E^{t+2}_{0,t}$ for $r\\geq t+2$.\nIn particular,\n$$E^{t+2}_{0,t} \\simeq E^\\infty_{0,t} \\simeq \\gr_0 H_t(E) \\simeq F_0 H_t(E),$$\nwhich sits inside $H_t(E)$. The composite\n$$E^2_{0,t} = H_t(F) \\to E^3_{0,t}\\to \\cdots\\to E^{t+2}_{0,t} \\subseteq F_0\nH_t(E)\\to H_t(E)$$\nis precisely the map $\\bullet$! Such a map is known as an \\emph{edge\nhomomorphism}.\n\nThe map $F\\to E$ is the inclusion of the fiber; it induces a map $H_t(F)\\to\nH_t(E)$ on homology. We claim that this agrees with $\\bullet$.\n%We almost saw this in the construction of a sseq for a filtered complex.\nRecall that $F_0H_t(E)$ is defined to be $\\img(H_t(F_0 E) \\to H_t(E))$. In the\nconstruction of the Serre spectral sequence, we declared that $F_0 E$ is\nexactly the preimage of the zero skeleton. Since $B$ is simply connected, we\nfind that $F_0 E$ is exactly the fiber $F$.\n\nTo conclude the proof of the claim, consider the following diagram:\n\\begin{equation*}\n    \\xymatrix{\n\tF\\ar[r]\\ar[d] & F\\ar[d]\\\\\n\tF\\ar[r]\\ar[d] & E\\ar[d]\\\\\n\t\\ast\\ar@{^(->}[r] & B\n    }\n\\end{equation*}\nThe naturality of the Serre spectral sequence implies that there is an induced\nmap of spectral sequences. Tracing through the symbols, we find that this\nobservation proves our claim.\n\nThe long exact sequence \\eqref{serre-exact} also contains a map $H_s(E)\\to\nH_s(B)$. The group $F_s H_s(E) = H_s(E)$ maps onto $\\gr_s H_s(E) \\simeq\nE^\\infty_{s,0}$. If $F$ is connected, then $H_s(B) = H_s(B;H_0(F)) =\nE^2_{s,0}$. Again, the $d^2$-differential $d^2:E^2_{s+2,-1}\\to E^2_{s,0}$ is\ntrivial (since the source is zero). Since $E^3 = \\ker d^2$, we have an\ninjection $E^3_{s,0} \\to E^2_{s,0}$. Repeating the same argument, we get\ninjections\n$$E^\\infty_{s,0} = E^{s+1}_{s,0}\\to \\cdots\\to E^2_{s,0}\\to E^2_{s,0} =\nH_s(B).$$\nComposing with the map $H_s(E)\\to E^\\infty_{s,0}$ gives the desired map $H_s(E)\n\\to H_s(B)$ in the Serre exact sequence. This composite is also known as an\nedge homomorphism.\n\nAs above, this edge homomorphism is the map induced by $E\\to B$. This can be\nproved by looking at the induced map of spectral sequences coming from the\nfollowing map of fiber sequences:\n\\begin{equation*}\n    \\xymatrix{\n\tF\\ar[r]\\ar[d] & \\ast\\ar[d]\\\\\n\tE\\ar[r]\\ar[d] & B\\ar[d]\\\\\n\tB\\ar[r] & B\n    }\n\\end{equation*}\n\nThe topologically mysterious map is the boundary map $\\partial:H_{p+q-1}(B)\\to\nH_{p+q-2}(F)$. Such a map is called a \\emph{transgression}. Again, let\n$(E^r_{s,t},d^r)$ be a first quadrant spectral sequence. In our case,\n$E^2_{n,0} = H_n(B)$, at least $F$ is connected. As above, we have injections\n$$i:E^n_{n,0} \\to \\cdots\\to E^3_{n,0} \\to E^2_{n,0} = H_n(B).$$\nSimilarly, we have surjections\n$$s:E^2_{0,n-1}\\to E^3_{0,n-1}\\to \\cdots\\to E^n_{0,n-1}.$$\nThere is a differential $d^n:E^n_{n,0}\\to E^n_{0,n-1}$. The transgression is\ndefined as the \\emph{linear relation} (not a function!) $E^2_{n,0}\\to\nE^2_{0,n-1}$ given by\n$$x\\mapsto i^{-1} d^n s^{-1}(x).$$\nHowever, the reader should check that in our case, the transgression is indeed\na well-defined function.\n\nTopologically, what is the origin of the transgression? There is a map\n$H_n(E,F)\\xrightarrow{\\pi_\\ast} H_n(B,\\ast)$, as well as a boundary map\n$\\partial : H_n(E,F) \\to H_{n-1}(F)$. We claim that:\n$$\\img \\pi_\\ast = \\img(E^n_{n,0}\\to H_n(B) = E^2_{n,0}),\\quad\n\\partial\\ker\\pi_\\ast = \\ker(H_{n-1}(F) = E^2_{0,n-1} \\to E^n_{0,n-1}).$$\n\\begin{proof}[Proof sketch]\n    Let $x\\in H_n(B)$. Represent it by a cycle $c\\in Z_n(B)$. Lift it to a\n    chain in the total space $E$. In general, this chain will not be a cycle\n    (consider the Hopf fibration). The differentials record this boundary; let\n    us recall the geometric construction of the differential. Saying that the\n    class $x$ survives to the $E^n$-page is the same as saying that we can find\n    a lift to a chain $\\sigma$ in $E$, with $d\\sigma\\in S_{n-1}(F)$. Then\n    $d^n(x)$ is represented by the class $[dc]\\in H_{n-1}(F)$. This is\n    precisely the trangression.\n\n    Informally, we lift something from $H_n(B)$ to $S_n(E)$; this is\n    well-defined up to something in $F$. In particular, we get an element in\n    $H_n(E,F)$. We send it, via $\\partial$, to an element of $H_{n-1}(F)$ ---\n    and this is precisely the transgression.\n\\end{proof}\n\\subsection{An example}\nWe would like to compare the Serre exact sequence \\eqref{serre-exact} with the\nhomotopy exact sequence:\n$$\\ast\\to \\pi_{p+q-1}(F)\\to \\pi_{p+q-1}(E)\\to \\pi_{p+q-1}(B)\\xar{\\partial}\n\\pi_{p+q-2}(F)\\to \\cdots$$\nThere are Hurewicz maps $\\pi_{p+q-1}(X)\\to H_{p+q-1}(X)$. We claim that there\nis a map of exact sequences between these two long exact sequences.\n\\begin{equation*}\n    \\xymatrix{\n\tH_{p+q-1}(E) \\ar[r]^{\\pi_\\ast} & H_{p+q-1}(B)\\ar[r]_\\partial &\n\tH_{p+q-2}(F)\\ar[r] & \\cdots\\\\\n\t\\pi_{p+q-1}(E)\\ar[r]_{\\pi_\\ast}\\ar[u]_{h} &\n\t\\pi_{p+q-1}(B)\\ar[u]^h\\ar[r] & \\pi_{p+q-2}(F)\\ar[r]\\ar[u]^h &\n\t\\cdots\\\\\n    }\n\\end{equation*}\nThe leftmost square commutes by naturality of Hurewicz. The commutativity of\nthe righmost square is not immediately obvious. For this, let us draw in the\nexplicit maps in the above diagram:\n\\begin{equation*}\n    \\xymatrix{\n\t& & H_{p+q-1}(E,F)\\ar[dl]\\ar[dr] & &\\\\\n\tH_{p+q-1}(E) \\ar[r]^{\\pi_\\ast} & H_{p+q-1}(B)\\ar[rr]_\\partial & &\n\tH_{p+q-2}(F)\\ar[r] & \\cdots\\\\\n\t\\pi_{p+q-1}(E)\\ar[r]_{\\pi_\\ast}\\ar[dr]\\ar[u]_{h} &\n\t\\pi_{p+q-1}(B)\\ar[u]^h\\ar[rr] & & \\pi_{p+q-2}(F)\\ar[r]\\ar[u]^h &\n\t\\cdots\\\\\n\t& \\pi_{p+q-1}(E,F)\\ar[uuur]\\ar[urr]\\ar[u]^\\cong_{s} & &\n    }\n\\end{equation*}\nThe map marked $s$ is an isomorphism (and provides the long arrow in the above\ndiagram, which makes the square commute), since\n$$\n\\pi_n(E,F) = \\pi_{n-1}(\\mathrm{hofib}(F\\to E)) = \\pi_{n-1}(\\Omega B) =\n\\pi_n(B).\n$$\nLet us now specialize to the case of the fibration\n$$\\Omega X\\to PX\\to X.$$\nAssume that $X$ is connected, and $\\ast \\in X$ is a chosen basepoint. Let\n$p\\geq 2$, and suppose that $\\widetilde{H}_s(X) = 0$ for $s<p$. Arguing as in\n\\S \\ref{loops-sn}, we learn that the Serre spectral sequence we know that the\nhomology of $\\Omega X$ begins in dimension $p-1$ since $PX\\simeq \\ast$, so $q =\np-1$. Likewise, if we knew $\\widetilde{H}_n(\\Omega X) = 0$ for $n<p-1$, then\nthe same argument shows that $\\widetilde{H}_n(X) = 0$ for $n<p$.\n\\subsection*{A surprise gust: the Hurewicz theorem}\nThe discussion above gives a proof of the Hurewicz theorem; this argument is\ndue to Serre.\n\\begin{theorem}[Hurewicz, Serre's proof]\n    Let $p\\geq 1$. Suppose $X$ is a pointed space with $\\pi_i(X) = 0$ for\n    $i<p$. Then $\\widetilde{H}_i(X) = 0$ for $i<p$ and $\\pi_p(X)^{ab}\\to\n    H_p(X)$ is an isomorphism.\n\\end{theorem}\n\\begin{proof}\n    Let us assume the case $p=1$. This is classical: it is Poincar\\'{e}'s\n    theorem. We will only use this result when $X$ is a loop space, in which\n    case the fundamental group is already abelian.\n\n    Let us prove this by induction, using the loop space fibration. By\n    assumption, $\\pi_i(\\Omega X) = 0$ for $i<p-1$. By our inductive hypothesis,\n    $\\widetilde{H}_i(\\Omega X) = 0$ for $i<p-1$, and $\\pi_{p-1}(\\Omega X)\n    \\xrightarrow{\\simeq} H_{p-1}(\\Omega X)$. By our discussion above, we learn\n    that $\\widetilde{H}_i(X) = 0$ for $i<p$. The Hurewicz map\n    $\\pi_p(X)\\xrightarrow{h}H_p(X)$ fits into a commutative diagram:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\pi_{p-1}(\\Omega X)\\ar[r]^\\simeq & H_{p-1}(\\Omega X)\\\\\n\t    \\pi_p(X)\\ar[u]^\\simeq \\ar[r]_h &\n\t    H_p(X)\\ar[u]^{\\simeq}_{\\text{transgression}}\n\t    }\n    \\end{equation*}\n    It follows from the Serre exact sequence that the transgression is an\n    isomorphism.\n\\end{proof}\n%This proof has an enormous advantage, since you can make modifications that modify all primes except for a single prime, or get rational information.\n%In other words, it's amenable to localizations.\n%On Monday we'll talk about Serre classes and get information about homotopy groups way beyond conductivity of the space, if you do it right.\n", "meta": {"hexsha": "740cee10860501b545c621af077b04356089111f", "size": 9025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-64-edge-homomorphisms.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-64-edge-homomorphisms.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-64-edge-homomorphisms.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": 48.2620320856, "max_line_length": 150, "alphanum_fraction": 0.6631578947, "num_tokens": 3377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6919649100921801}}
{"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\nLet $f : \\mathbb{R}^2 \\rightarrow \\mathbb{R}$ be the function given in Equation \\ref{eq21}.\n\n\\begin{equation}\nf(x) = x_1^2 + 4x_2^2\n\\label{eq21}\n\\end{equation}\n\nLet $S$ be the set of feasible solutions defined by the restrictions\n\n\\begin{equation}\n\\begin{aligned}\n5x_1 + 8x_2 - 41 &\\leqslant 0,\\\\\nx_1 &\\geqslant 0,\\\\\nx_2 &\\geqslant 0.\\\\\n\\end{aligned}\n\\label{eq22}\n\\end{equation}\n\nUsing Fritz John theorem determine the point of minimum for $f$.\n\n\\subsection*{Solution}\n\nFigure \\ref{fig21} depicts the feasible region $S$ for function $f: \\mathbb{R}^2 \\rightarrow \\mathbb{R}$.\n\n\\begin{figure}[H]\\centering\n\\begin{tikzpicture}\n    \\draw [thick] (1.708,0) coordinate (a_1) -- (0,2.733) coordinate (a_2);\n    \\path [fill=gray!20] (0,0) -- (a_2) to\n        (a_1) -- (0,0);\n    \\draw [<->,thick] (0,3) node (yaxis) [above] {$y$} |- (3,0) node (xaxis) [right] {$x$};\n    \\fill[black] (a_1) circle (2pt) node[above right] {$(0, 5.125)$};\n    \\fill[black] (a_2) circle (2pt) node[right] {$(8.2, 0)$};\n    \\node at (0.5,1) {$S$};\n\\end{tikzpicture}\n\\caption{Feasible region $S$ defined by restrictions given in Eq. \\ref{eq22}}\\label{fig21}\n\\end{figure}\n\nWe define $g_i$ for $i \\in \\{1,2,3\\}$ as follows.\n\n\\begin{equation}\n\\begin{aligned}\ng_1(\\mathbf{x}) &= 5x_1 + 8x_2 - 41\\\\\ng_2(\\mathbf{x}) &= x_1\\\\\ng_3(\\mathbf{x}) &= x_2\\\\\n\\end{aligned}\n\\label{eq23}\n\\end{equation}\n\nUsing Eq. \\ref{eq21} and \\ref{eq23}, $(\\nabla f)_x$ and $(\\nabla g_i)$ can be obtained as follows.\n\n\\begin{equation}\n\\begin{aligned}\n(\\nabla f)'_\\mathbf{x} &= \\begin{pmatrix} 2x_1 & 8x_2\\end{pmatrix} \\\\\n(\\nabla g_1)'_\\mathbf{x} &= \\begin{pmatrix} 5 & 8\\end{pmatrix} \\\\\n(\\nabla g_2)'_\\mathbf{x} &= \\begin{pmatrix} 1 & 0\\end{pmatrix} \\\\\n(\\nabla g_3)'_\\mathbf{x} &= \\begin{pmatrix} 0 & 1\\end{pmatrix} \\\\\n\\end{aligned}\n\\label{eq24}\n\\end{equation}\n\nWe claim $\\mathbf{x} = (0,0)$ is an optimal point for function $f$.\nTo prove this claim, we first need to show Fritz John necessary condition is satisfied; i.e. $F(f,\\mathbf{x})$ and $FD(S,\\mathbf{x_0})$ are disjoint.\n\nFor $\\mathbf{x} = (0,0)$, constraints $g_2$ and $g_3$ are binding.\nWe have $\\mathbf{d} \\in F(f,\\mathbf{x}) \\cap G(\\mathbf{g}, \\mathbf{x})$ if following conditions are satisfied, simultaneously.\n\n\\begin{equation}\n\\begin{aligned}\n2x_1 d_1 + 8x_2 d_2 &< 0\\\\\nx_1 d_1 &< 0\\\\\nx_2 d_2 &< 0\\\\\n\\end{aligned}\n\\label{eq25}\n\\end{equation}\n\nHowever, since $x_1 = x_2 = 0$, none of the conditions in Eq. \\ref{eq25} are satisfied and therefore, $F(f,\\mathbf{x}) \\cap G(\\mathbf{g}, \\mathbf{x}) = \\emptyset$ for $x = (0,0)$.\nTherefore we can continue with finding scalars $u_0$ and $u_i$ such that $u_0(\\nabla f)_\\mathbf{x} + \\Sigma_{i=1}^{3} u_i (\\nabla g_i)_\\mathbf{x} = \\mathbf{0}$.\nUsing Eq. \\ref{eq24}, this condition can be rewritten as follows.\n\n\\begin{equation}\nu_0 \\begin{pmatrix} 2x_1\\\\ 8x_2\\\\ \\end{pmatrix} + u_2 \\begin{pmatrix} 1\\\\ 0\\end{pmatrix} + u_3 \\begin{pmatrix} 0\\\\ 1\\end{pmatrix} = \\begin{pmatrix}\n0 \\\\ 0 \\end{pmatrix}\n\\label{eq26}\n\\end{equation}\n\nFor Eq. \\ref{eq26} to hold for $x = (0, 0)$, we should have $u_i = 0$ for all $i\\in \\{1,2,3\\}$ and $u_0$ can be chosen as any positive number.\nSince there is at least one positive scalar, all necessary conditions are satisfied for $\\mathbf{x} = (0, 0)$ and $\\mathbf{x}$ is proven to be the point of minimum for $f$.\n\n\\subsection*{Side Note}\n\nIn case the restrictions given in \\ref{eq22} are changed to the following, the point of minimum of $f$ would be $\\mathbf{x} = (5,2)$.\n\n\\begin{equation}\n\\begin{aligned}\n5x_1 + 8x_2 - 41 &\\geqslant 0,\\\\\nx_1 &\\geqslant 0,\\\\\nx_2 &\\geqslant 0.\\\\\n\\end{aligned}\n\\label{eq27}\n\\end{equation}\n\nChoosing $\\mathbf{x} = (5,2)$ will change the set of binding constraints to $\\{g_1\\}$.\nTherefore, \\ref{eq25} will change to Eq. \\ref{eq28}.\nIn this case, $F(f,\\mathbf{x}) \\cap G(\\mathbf{g}, \\mathbf{x}) = \\emptyset$ again, since no $d_1$ and $d_2$ exist to satisfy the following conditions simultaneously.\n\n\\begin{equation}\n\\begin{aligned}\n10d_1 + 16d_2 &< 0,\\\\\n5d_1 + 8d_2 &> 0\\\\\n\\end{aligned}\n\\label{eq28}\n\\end{equation}\n\nTherefore, by showing there are $u_0$ and $u_i$ such that $u_0(\\nabla f)_\\mathbf{x} + \\Sigma_{i=1}^{3} u_i (\\nabla g_i)_\\mathbf{x} = \\mathbf{0}$, we can prove $\\mathbf{x}(5,2)$ is really an optimal point.\nThe former is easy to show, using Eq. \\ref{eq29}.\n\n\\begin{equation}\nu_0 \\begin{pmatrix} 2x_1\\\\ 8x_2\\\\ \\end{pmatrix} + u_1 \\begin{pmatrix} 5\\\\ 8\\end{pmatrix} = \\begin{pmatrix}\n0 \\\\ 0 \\end{pmatrix}\n\\label{eq29}\n\\end{equation}\n\nAnd replacing $x_1 = 5$, $x_2 = 2$, Eq. \\ref{eq29} holds by having $u_0 = u_1 = 0$ and choosing $u_2$ and $u_3$ as any arbitrary positive number.\n", "meta": {"hexsha": "c05c76c73959a7bc7b8c0778433a21d42dbb82db", "size": 4969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q02.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/hw03/hw03q02.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/hw03/hw03q02.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": 37.3609022556, "max_line_length": 204, "alphanum_fraction": 0.645602737, "num_tokens": 1959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6919649100921801}}
{"text": "\\section{Conditional Expectation}\r\n\\begin{definition}\r\n    Let $B$ be an event such that $\\mathbb P(B)>0$ and let $X$ be a random variable, then we define\r\n    $$\\mathbb E[X|B]=\\frac{\\mathbb E[X\\cdot 1_B]}{\\mathbb P(B)}$$\r\n\\end{definition}\r\n\\begin{proposition}[Law of Total Expectation]\r\n    Let $\\Omega_n$ be a sequence of events that partitions $\\Omega$, then\r\n    $$\\mathbb E[X]=\\sum_n\\mathbb E[X|\\Omega_n]\\mathbb P(\\Omega_n)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Write $X=\\sum_nX\\cdot1_{\\Omega_n}$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $X_1,\\ldots,X_n$ be random variables, then the joint distribution is $\\mathbb P(X_1=x_1,\\ldots,X_n=x_n),x_i\\in\\omega_{X_i}$.\r\n    Given such a joint distribution, the marginal distribution of $X_i$ is defined as\r\n    $$\\mathbb P(X_i=x_i)=\\sum_{j\\neq i,x_j\\in\\Omega_{X_j}}\\mathbb P(X_1=x_1,\\ldots,X_n=x_n)$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $X,Y$ be random variables, then the conditional probability given $Y=y,y\\in\\Omega_Y$ is defined by\r\n    $$\\mathbb P(X=x|Y=y)=\\mathbb P(X=x,Y=y)/\\mathbb P(Y=y)$$\r\n\\end{definition}\r\nImmediately\r\n$$\\mathbb P(X=x)=\\sum_{y\\in\\Omega_Y}\\mathbb P(X=x,Y=y)=\\sum_{y\\in\\Omega_Y}\\mathbb P(X=x|Y=y)\\mathbb P(Y=y)$$\r\nNote that if $X,Y$ are independent, then\r\n\\begin{align*}\r\n    \\mathbb P(X+Y=z)&=\\sum_{y\\in\\Omega_Y}\\mathbb P(X+Y=z|Y=y)\\mathbb P(Y=y)\\\\\r\n    &=\\sum_{y\\in\\Omega_Y}\\mathbb P(X=z-y|Y=y)\\mathbb P(Y=y)\\\\\r\n    &=\\sum_{y\\in\\Omega_Y}\\mathbb P(X=z-y)\\mathbb P(Y=y)\r\n\\end{align*}\r\nSimilarly\r\n$$\\mathbb P(X+Y=z)=\\sum_{x\\in\\Omega_X}\\mathbb P(X=x)\\mathbb P(Y=z-x)$$\r\n\\begin{example}\r\n    Let $X\\sim\\operatorname{Pois}(\\lambda),Y\\sim\\operatorname{Pois}(\\mu)$, and $X,Y$ are independent, then\r\n    $$\\mathbb P(X+Y=n)=\\sum_{r=0}^\\infty \\mathbb P(X=r)\\mathbb P(X=n-r)=e^{-(\\lambda+\\mu)}\\frac{(\\lambda+\\mu)^n}{n!}$$\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $X,Y$ be random variables,\r\n    The conditional expectation of $X$ given $Y=y$ is defined to be the expectation of the conditional distribution of $X$ given $Y=y$, so\r\n    $$\\mathbb E[X|Y=y]=\\frac{\\mathbb E[X\\cdot 1_{Y=y}]}{\\mathbb P(Y=y)}=\\sum_{x\\in\\Omega_X}x\\mathbb P(X=x|Y=y)$$\r\n\\end{definition}\r\nNote that $g(y)=\\mathbb E[X|Y=y]$ is a function in $\\Omega_Y\\to\\mathbb R$.\r\n\\begin{definition}\r\n    The conditional expectation of $X$ given $Y$ is defined to be $\\mathbb E[X|Y]=g(Y)$ which is a random variable as a function of $Y$.\r\n\\end{definition}\r\nSo obviously,\r\n\\begin{align*}\r\n    \\mathbb E[X|Y]&=g(Y)\\\\\r\n    &=\\sum_{y\\in\\Omega_Y}g(Y)\\mathbb P(1_{Y=y})\\\\\r\n    &=\\sum_{y\\in\\Omega_Y}1_{Y=y}g(y)\\\\\r\n    &=\\sum_{y\\in\\Omega_Y}1_{Y=y}\\mathbb E[X|Y=y]\r\n\\end{align*}\r\n\\begin{example}\r\n    Toss a $p$-coin several times independently, so they produce a sequence of random variables $(X_i)_{i\\in\\mathbb N}\\sim\\operatorname{Bern}(p)$ and the number of heads are distributed in $Y_m=X_1+X_2+\\cdots+X_m\\sim\\operatorname{Bin}(m,p)$\r\n    We want to calculate $\\mathbb E[X_i|Y_m]$.\r\n    Note that $\\mathbb E[X_i|Y_m=r]=\\mathbb P(X_i=1|Y_m=r)=r/m$, which means\r\n    $$\\mathbb E[X_i|Y_m]=\\frac{Y_m}{m}$$\r\n\\end{example}\r\n\\begin{proposition}\r\n    1. $\\forall c\\in\\mathbb R,\\mathbb E[cX|Y]=c\\mathbb E[X|Y],\\mathbb E[c|Y]=c$.\\\\\r\n    2.\r\n    $$\\mathbb E\\left[\\sum_{i=1}^nX_i\\middle|Y\\right]=\\sum_{i=1}^n\\mathbb E[X_i|Y]$$\r\n    3. $\\mathbb E[\\mathbb E[X|Y]]=\\mathbb E[X]$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1 and 2 are obvious.\r\n    For 3,\r\n    \\begin{align*}\r\n        \\mathbb E[\\mathbb E[X|Y]]&=\\sum_{y\\in\\Omega_Y}\\mathbb P(Y=y)\\mathbb E[X|Y=y]\\\\\r\n        &=\\sum_{y\\in\\Omega_Y}\\sum_{x\\in\\Omega_X}x\\mathbb P(X=x|Y=y)\\mathbb P(Y=y)\\\\\r\n        &=\\sum_{x\\in\\Omega_X}x\\mathbb P(X=x)\\\\\r\n        &=\\mathbb E[X]\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nIntuitively we also have the following:\r\n\\begin{proposition}\\label{conditional_exp}\r\n    1. If $X,Y$ are independent, then $\\mathbb E[X|Y]=\\mathbb E[X]$ which is constant.\\\\\r\n    2. Suppose $Y,Z$ are independent, then $\\mathbb E[\\mathbb E[X|Y]|Z]=\\mathbb E[X]$.\\\\\r\n    3. Let $h:\\mathbb R\\to\\mathbb R$, then $\\mathbb E[h(Y)X|Y]=h(Y)\\mathbb E[X|Y]$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1 is trivial.\\\\\r\n    For 2, we have $\\mathbb E[X|Y]$ is independent of $Z$, so $\\mathbb E[\\mathbb E[X|Y]|Z]=\\mathbb E[\\mathbb E[X|Y]]=\\mathbb E[X]$ by 1.\\\\\r\n    As for 3, we have $\\mathbb E[h(Y)X|Y=y]=h(y)\\mathbb E[X|Y=y]$, the identity follows.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $\\mathbb E[\\mathbb E[X|Y]|Y]=\\mathbb E[X|Y]$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Take $h(y)=\\mathbb E[X|Y=y]$ in Proposition \\ref{conditional_exp}.3.\r\n\\end{proof}", "meta": {"hexsha": "9277bd666cdd8e910810c558d0752d15104d9e5c", "size": 4522, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/conexp.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": "6/conexp.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": "6/conexp.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": 49.6923076923, "max_line_length": 241, "alphanum_fraction": 0.6318000885, "num_tokens": 1743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6919649076849792}}
{"text": "\\section*{Integration schemes}\r\nEuler first order explicit\r\n\\begin{align}\\label{eqn:euler}\r\n    \\begin{split}\r\n        &v(t+\\Delta{t}) = v(t) + a(t) * \\Delta{t}\\\\\r\n        &x(t+\\Delta{t}) = x(t) + v(t) * \\Delta{t}\r\n    \\end{split}\r\n\\end{align}\r\n\\par\r\nThe central difference scheme, also known as velocity Verlet is a very widely\r\nused integration method of second order. This was initially proposed by Cundall\r\nand Strack (1979) and adopted by several other authors. Velocities in the\r\nupcoming time step $t + \\Delta{t}/2 $ and positions at $t + \\Delta{t}$ are\r\ncalculated as\r\n\\begin{align}\\label{eqn:verlet}\r\n    \\begin{split}\r\n        &v(t + \\Delta{t}/2) = v(t + \\Delta{t}/2) +a(t - \\Delta{t}/2) * \\Delta{t}\\\\\r\n        &x(t + \\Delta{t}) = x(t) +v(t + \\Delta{t}/2) * \\Delta{t}\\\\\r\n    \\end{split}\r\n\\end{align}\r\n\\par\r\npredictor–corrector schemes very commonly used for molecular dynamics and\r\ndiscrete element applications are Gear’s schemes. They are based on three\r\nstages, whereas in addition to the predictor and corrector step known from the\r\nAdams-method an evaluation step is added. Schemes considered here are the third\r\norder Gear’s method (GPC3) and the fourth order Gear’s method (GPC4). In the\r\nprediction step positions and their higher derivatives are calculated based on\r\nTaylor series expansions as\r\n\\begin{equation}\\label{eqn:gearP}\r\n    \\begin{split}\r\n        c(t+\\Delta{t}, p) =& c(t)\\\\\r\n        b(t+\\Delta{t}, p) =& b(t) + c(t) *\\Delta{t}\\\\\r\n        a(t+\\Delta{t}, p) =& a(t) + b(t) *\\Delta{t}^2 + \\frac{1}{6} * c(t) *\\Delta{t}^2\\\\\r\n        v(t+\\Delta{t}, p) =& v(t) + a(t) *\\Delta{t} + \\frac{1}{2} * b(t) *\\Delta{t}^2 +\\\\\r\n        &\\frac{1}{6} * c(t) *\\Delta{t}^3\\\\\r\n        x(t+\\Delta{t}, p) =& x(t) + v(t) * \\Delta{t} + \\frac{1}{2} * a(t) *\\Delta{t}^2 +\\\\\r\n        &\\frac{1}{6} * b(t) *\\Delta{t}^3 + \\frac{1}{24} * c(t) *\\Delta{t}^4\\\\\r\n    \\end{split}\r\n\\end{equation}\r\nwith the first and second derivative of the accelerations calculated as\\par\r\nfor GPC3:\r\n\\begin{align}\\label{eqn:gearJerk3}\r\n    \\begin{split}\r\n        &b(t) = \\frac{\\Delta{a(t)}}{\\Delta{t}}\\\\\r\n        \\\\\r\n        &c(t) = 0\\\\\r\n    \\end{split}\r\n\\end{align}\\par\r\nfor GPC4:\r\n\\begin{align}\\label{eqn:gearJerk4}\r\n    \\begin{split}\r\n        &b(t) = \\frac{\\Delta{a(t)}}{\\Delta{t}}\\\\\r\n        \\\\\r\n        &c(t) = \\frac{\\Delta{b(t)}}{\\Delta{t}}\\\\\r\n    \\end{split}\r\n\\end{align}\r\n\\par\r\nIn the evaluation step the difference in the accelerations calculated based on\r\nthe acceleration $a(t+ \\Delta{t}, p)$ and the acceleration $a(t+\\Delta{t})$\r\ncalculated from positions $x(t+\\Delta{t}, p)$ and velocities $v(t+\\Delta{t}, p)$\r\nis obtained by\r\n\\begin{align}\\label{eqn:gearDa}\r\n    \\Delta{a} = a(t + \\Delta{t}) - a(t + \\Delta{t}, p)\r\n\\end{align}\r\n\\par\r\nIn the following, correction step positions and their higher derivatives are\r\ncalculated based on their values from the previous time step and the obtained\r\ndifference in acceleration as\r\n\\begin{align}\\label{eqn:gearCorrector}\r\n    \\begin{split}\r\n        &x(t+\\Delta{t}) = x(t+\\Delta{t}, p) + k1 * \\Delta{a} * \\Delta{t}^2\\\\\r\n        &v(t+\\Delta{t}) = v(t+\\Delta{t}, p) + k2 * \\Delta{a} * \\Delta{t}\\\\\r\n        &a(t+\\Delta{t}) = a(t+\\Delta{t}, p) + k3 * \\Delta{a}\\\\\r\n        &b(t+\\Delta{t}) = b(t+\\Delta{t}, p) + k4 * \\frac{\\Delta{a}}{\\Delta{t}}\\\\\r\n        &c(t+\\Delta{t}) = c(t+\\Delta{t}, p) + k5 * \\frac{\\Delta{a}}{\\Delta{t}^2}\\\\\r\n    \\end{split}\r\n\\end{align}\r\n\\par\r\nGear’s scheme parameters k1-k5\\par\r\nfor GPC3:\r\n$k_1 = 1/12, k_2 = 5/12, k_3 = 1, k_4 = 1, k_5 = 0$\\par\r\nfor GPC4:\r\n$k_1 = 19/240, k_2 = 3/8, k_3 = 1, k_4 = 3/2, k_5 = 1$\r\n\\par\r\n\\newpage", "meta": {"hexsha": "dfe940cab115ee763c3b63cb77ca06dc34efcfe5", "size": 3580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "big_article_2021q1/integrSchemes.tex", "max_stars_repo_name": "alexgubanow/phd_articles", "max_stars_repo_head_hexsha": "755fa2c17de7db928f536cb8b4d0789813ac4b6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "big_article_2021q1/integrSchemes.tex", "max_issues_repo_name": "alexgubanow/phd_articles", "max_issues_repo_head_hexsha": "755fa2c17de7db928f536cb8b4d0789813ac4b6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "big_article_2021q1/integrSchemes.tex", "max_forks_repo_name": "alexgubanow/phd_articles", "max_forks_repo_head_hexsha": "755fa2c17de7db928f536cb8b4d0789813ac4b6f", "max_forks_repo_licenses": ["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.1176470588, "max_line_length": 91, "alphanum_fraction": 0.588547486, "num_tokens": 1298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6919426208960036}}
{"text": "\\section{Merge Classification}\n\nAfter generating the list of potential merge locations we extract a cubic region of interest around each.\nWe experimented with three different cube side lengths: $800 \\textrm{nm}$, $1200 \\textrm{nm}$, and $1600 \\textrm{nm}$. \nSide lengths of $1200 \\textrm{nm}$ performed better on the training and validation data on our network. \n\n\\vspace{1cm}\n\n\\noindent\n\\textbf{Network Architecture}\nWe tested various architectures before deciding on the one we present in the paper. \nEach architecture uses VGG-style blocks (i.e. two convolutions of size $3\\times3\\times3$ followed by a max-pooling layer)~\\cite{chatfield2014return}.\nFor the first two layers the max-pooling is anisotropic with reduction only in the $x$ and $y$ dimensions. \nThe number of filters starts at 16 for the first block and doubles in each subsequent block.\nOur architectures vary in the input size and number of layers. \nIn all instances we extract a \\SI{1200}{\\nano\\meter^3} region of interest and map the extracted voxels to the given input size. \nThese input sizes correspond to specific output sizes from the last VGG block.\nFor training we use the mean squared error loss function and optimize with SGD with Nesterov momentum.\n\n\\begin{table}\n\t\\scriptsize\n\t\\centering\n\t\\begin{tabular}{c c c c c c c}\n\t\t\\hline\n\t\t\\textbf{Depth} & \\textbf{Input Size} & \\textbf{No. Parameters} & \\textbf{Output Size} & \\textbf{Accuracy} & \\textbf{Precision} & \\textbf{Recall} \\\\ \\hline\n\t\t      3        & (3, 18, 52, 52)     & 1,101,553               & (64, 3, 3, 3)        & 91.30             & 58.06              & 92.81 \\\\\n\t\t      3        & (3, 20, 60, 60)     & 2,313,969               & (64, 4, 4, 4)        & 92.41             & 61.70              & 92.41 \\\\\n\t\t      3        & (3, 22, 68, 68)     & 4,312,817               & (64, 5, 5, 5)        & 92.33             & 61.49              & 92.34 \\\\\n\t\t      3        & (3, 24, 76, 76)     & 7,294,705               & (64, 6, 6, 6)        & 93.51             & 65.78              & 93.13 \\\\\n\t\t      \\textbf{3}        & \\textbf{(3, 26, 84, 84)}     & \\textbf{11,456,241}              & \\textbf{(64, 7, 7, 7)}        & \\textbf{95.38}             & \\textbf{74.43}              & \\textbf{92.34} \\\\\n\t\t      3        & (3, 28, 92, 92)     & 16,994,033              & (64, 8, 8, 8)        & 91.87             & 59.70              & 94.22 \\\\\n\t\t      3        & (3, 30, 100, 100)   & 24,104,689              & (64, 9, 9, 9)        & 92.01             & 60.24              & 93.75 \\\\\n\t\t      4        & (3, 28, 92, 92)     & 1,404,913               & (128, 2, 2, 2)       & 91.70             & 60.24             & 85.94 \\\\\n\t\t      4        & (3, 32, 108, 108)   & 2,650,097               & (128, 3, 3, 3)       & 92.80             & 64.28              & 86.88 \\\\\\hline\n\t\\end{tabular}\n\t\\caption{The results of various network architectures trained on the Kasthuri data.}\n\t\\label{table:input-size}\n\\end{table}\n\n\\noindent\n\\textbf{Inference Augmentation}\nAugmenting the data for inference increases the precision by 3.79\\% and the accuracy by 0.64\\%. \nFigure~\\ref{fig:test-augmentation} shows the changes in the number of true positives, false positives, and false negatives as a function of the number of augmentations on the Kasthuri dataset.\nThe number of false positives decreases at first, falling below 200 after a second augmentation.\nThe gains become more gradual with the number of augmentations, leveling out around 175 false positives after 5 augmentations.\n\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=0.45\\linewidth]{./figures/Kasthuri-test-augmentation.png}\n\t\\caption{The number of false positives decreases with our data augmentation scheme. The benefit of augmentation gradually decreases with the number of random examples.}\n\t\\label{fig:test-augmentation}\n\\end{figure}\n", "meta": {"hexsha": "3f56c02aba2d14121670a7b57d9b4a3204d4e7be", "size": 3818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/eccv2018/supplemental/classifier.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/eccv2018/supplemental/classifier.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/eccv2018/supplemental/classifier.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": 72.0377358491, "max_line_length": 202, "alphanum_fraction": 0.6003143007, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6919426159993872}}
{"text": "We include some examples to demonstrate some of the uses of this package.\n\n\\section{Distinguishing groups}~\n\n\\begin{example}[Payne\\_Grps]\n\nWe can use these functions to build groups from bilinear maps and distinguish\nseemingly indistinguishable groups. In 2004, S. E. Payne asked if two elation\ngroups were isomorphic but suspected they were not \\cite{Payne:elation-grps}.\n\nThe first group, $G_f$, is the elation group of the generalized quadrangle\n$H(3,q^2)$, the Hermitian geometry. This group is defined as a Heisenberg group\nwhose bilinear map is the usual dot product.\n\n\\begin{code}\n> p := 3;\n> e := 4;\n> q := p^e; // q = 3^e >= 27\n> F := [KSpace(GF(q),2), KSpace(GF(q),2), KSpace(GF(q),1)];\n> \n> DotProd := function(x)\nfunction>   return KSpace(GF(q),1)!(x[1]*Matrix(2,1,x[2]));\nfunction> end function;\n> \n> DoubleForm := function(T)\nfunction>   F := SystemOfForms(T)[1];\nfunction>   K := BaseRing(F);\nfunction>   n := Nrows(F);\nfunction>   m := Ncols(F);\nfunction>   MS := KMatrixSpace(K,n,m);\nfunction>   Z := MS!0;\nfunction>   M1 := HorizontalJoin(Z,-Transpose(F));\nfunction>   M2 := HorizontalJoin(F,Z);\nfunction>   D := VerticalJoin( M1, M2 );\nfunction>   return Tensor( D, 2, 1 );\nfunction> end function;\n> \n> f := DoubleForm( Tensor( F, DotProd ) );\n> f;\nTensor of valence 2, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over GF(3^4)\nU1 : Full Vector space of degree 4 over GF(3^4)\nU0 : Full Vector space of degree 1 over GF(3^4)\n> \n> IsAlternating(f);\ntrue\n> Gf := HeisenbergGroup(f);\n\\end{code}\n\nNow we define Payne's second group, $G_{\\bar{f}}$, which is the elation group of\nthe Roman quadrangle with parameters $(q^2,q)$. In this example, $\\bar{f}$ is a\nbiadditive map, but is bilinear over the prime field $\\mathbb{F}_3$. Therefore,\nwe construct a vector space isomorphism from $\\mathbb{F}_3^e$ to\n$\\mathbb{F}_{3^e}$ and the bilinear commutator map, induced by $\\bar{f}$. Hence,\n$G_{\\bar{f}}$ is the Heisenberg group of this bilinear commutator map.\n\n\\begin{code}\n> n := PrimitiveElement(GF(q)); // non-square\n> MS := KMatrixSpace(GF(q),2,2);\n> A := MS![-1,0,0,n];\n> B := MS![0,1,1,0];\n> C := MS![0,0,0,n^-1];\n> F1 := Frame(f);\n> F2 := [KSpace(GF(p),4*e), KSpace(GF(p),4*e),\\\n>   KSpace(GF(p),e)];\n> \n> // take 1/3^r root\n> Root := function(v,r) \nfunction>   k := Eltseq(v)[1];\nfunction>   K := Parent(k);\nfunction>   if k eq K!0 then return k; end if;\nfunction>   R<x> := PolynomialRing(K);\nfunction>   f := Factorization(x^(3^r)-k)[1][1];\nfunction>   return K!(x-f);\nfunction> end function;\n> \n> // biadditive map defining elation grp\n> RomanGQ := function(x) \nfunction>   u := Matrix(1,2,x[1]);\nfunction>   v := Matrix(2,1,x[2]);\nfunction>   M := [A,B,C];\nfunction>   f := &+[Root(u*M[i]*v,i-1) : i in [1..3]];\nfunction>   return KSpace(GF(q),1)![f];\nfunction> end function;\n> \n> // vector space isomorphisms\n> phi := map< F2[1] -> F1[1] | \\\n>   x :-> F1[1]![ GF(q)![ s : s in Eltseq(x)[i+1..e+i] ] : \\\n>     i in [0,e,2*e,3*e] ] >;\n> gamma := map< F1[3] -> F2[3] | \\\n>   x :-> F2[3]!&cat[ Eltseq(s) : s in Eltseq(x) ] >;\n> \n> // bilinear commutator from RomanGQ\n> RomanGQComm := function(x)\nfunction>   x1 := Eltseq(x[1]@phi)[1..2];\nfunction>   x2 := Eltseq(x[1]@phi)[3..4];\nfunction>   y1 := Eltseq(x[2]@phi)[1..2];\nfunction>   y2 := Eltseq(x[2]@phi)[3..4];\nfunction>   comm := RomanGQ( <x2,y1> ) - RomanGQ( <y2,x1> );\nfunction>   return comm @ gamma;\nfunction> end function;\n> \n> f_bar := Tensor( F2, RomanGQComm );\n> f_bar;\nTensor of valence 2, U2 x U1 >-> U0\nU2 : Full Vector space of degree 16 over GF(3)\nU1 : Full Vector space of degree 16 over GF(3)\nU0 : Full Vector space of degree 4 over GF(3)\n> \n> IsAlternating(f_bar);\ntrue\n> Gfb := HeisenbergGroup(f_bar);\n\\end{code}\n\nThe groups $G_f$ and $G_{\\bar{f}}$ have order $3^{20}$ and are class 2, exponent\n3, and minimally generated by 16 elements. In other words, the groups $G_f$ and\n$G_{\\bar{f}}$ are central extensions of $\\mathbb{Z}_3^{16}$ by\n$\\mathbb{Z}_3^{4}$ and have exponent $3$. Using standard heuristics, these\ngroups are indistinguishable. However, the invariants associated to their\nexponent-$p$ central tensor are vastly different, and thus, they determine that\nthese groups are non-isomorphic. We show that the centroids of the tensors are\nnot isomorphic.\n\n\\begin{code}\n> Tf := pCentralTensor(Gf,1,1);\n> Tf;\nTensor of valence 2, U2 x U1 >-> U0\nU2 : Full Vector space of degree 16 over GF(3)\nU1 : Full Vector space of degree 16 over GF(3)\nU0 : Full Vector space of degree 4 over GF(3)\n> \n> Tfb := pCentralTensor(Gfb,1,1);\n> Tfb;\nTensor of valence 2, U2 x U1 >-> U0\nU2 : Full Vector space of degree 16 over GF(3)\nU1 : Full Vector space of degree 16 over GF(3)\nU0 : Full Vector space of degree 4 over GF(3)\n> \n> Cf := Centroid(Tf);\n> Cfb := Centroid(Tfb);\n> Dimension(Cf) eq Dimension(Cfb);\nfalse\n\\end{code}\n\\end{example}\n\n\\section{Simplifying automorphism group computations}~\n\n\\begin{example}[Ext\\_Over\\_Adj] We demonstrate how to to simplify the\nautomorphism group computation as discussed in \\cite{BW:grps-tensor}. We\nconstruct a class 2, exponent $p$, $p$-group $G$ which is a quotient of a\nmaximal unipotent subgroup of $\\text{GL}(3,317^4)$.\n\n\\begin{code}\n> p := 317;\n> e := 4;\n> H := ClassicalSylow( GL(3,p^e), p );\n> U := UnipotentMatrixGroup(H);\n> P := PCPresentation(U);\n> Z := Center(P);\n> \n> N := sub< P | >;\n> while #N lt p^2 do\nwhile>   N := sub< P | Random(Z), N >;\nwhile> end while;\n> \n> G := P/N;\n> G;\nGrpPC : G of order 10246902931634286779441449 = 317^10\nPC-Relations:\n    G.5^G.1 = G.5 * G.9^62 * G.10^133, \n    G.5^G.2 = G.5 * G.9^312 * G.10^295, \n    G.5^G.3 = G.5 * G.9^316, \n    G.5^G.4 = G.5 * G.10^316, \n    G.6^G.1 = G.6 * G.9^312 * G.10^295, \n    G.6^G.2 = G.6 * G.9^316, \n    G.6^G.3 = G.6 * G.10^316, \n    G.6^G.4 = G.6 * G.9^138 * G.10^163, \n    G.7^G.1 = G.7 * G.9^316, \n    G.7^G.2 = G.7 * G.10^316, \n    G.7^G.3 = G.7 * G.9^138 * G.10^163, \n    G.7^G.4 = G.7 * G.9^188 * G.10^50, \n    G.8^G.1 = G.8 * G.10^316, \n    G.8^G.2 = G.8 * G.9^138 * G.10^163, \n    G.8^G.3 = G.8 * G.9^188 * G.10^50, \n    G.8^G.4 = G.8 * G.9^125 * G.10^151\n\\end{code}\n\nWe construct the exponent-$p$ central tensor of $G$ and compute its adjoint $*$-algebra $A$.\n\n\\begin{code}\n> T := pCentralTensor(G,1,1);\n> T;\nTensor of valence 2, U2 x U1 >-> U0\nU2 : Full Vector space of degree 8 over GF(317)\nU1 : Full Vector space of degree 8 over GF(317)\nU0 : Full Vector space of degree 2 over GF(317)\n> \n> A := AdjointAlgebra(T);\n> Dimension(A);\n16\n> star := Star(A);\n\\end{code}\n\nIf $V=G/\\Phi(G)$ is the Frattini quotient of $G$, then our goal is to get the\ncotensor space $V\\wedge_A V$. Note that $\\dim V\\wedge V=28$, so standard methods\nwill compute a stabilizer of $\\text{GL}(8,317)$ inside $V\\wedge V$. We will\ndecrease the size of the ambient space resulting in an easier stabilizer\ncomputation.\n\n\\begin{code}\n> V := Domain(T)[1];\n> E := ExteriorCotensorSpace(V,2);\n> E;\nCotensor space of dimension 28 over GF(317) with valence 1\nU2 : Full Vector space of degree 8 over GF(317)\nU1 : Full Vector space of degree 8 over GF(317)\n\\end{code}\n\nNow we create a sub cotensor space $S$ generated by all $(e_iX)\\wedge e_j - e_i\\wedge (e_jX)$ for $X\\in A$, \nand then quotient $V\\wedge V$ by $S$. The result is a 4 dimensional space.\n\n\\begin{code}\n> L := [];\n> for E_gen in Generators(E) do\nfor>   F := SystemOfForms(E_gen)[1];\nfor>   for X in Basis(A) do\nfor|for>     L cat:= [E!Eltseq(X*F - F*Transpose(X@star))];\nfor|for>   end for;\nfor> end for;\n> \n> S := SubTensorSpace(E,L);\n> S;\nCotensor space of dimension 24 over GF(317) with valence 1\nU2 : Full Vector space of degree 8 over GF(317)\nU1 : Full Vector space of degree 8 over GF(317)\n> \n> Q := E/S;\n> Q;\nCotensor space of dimension 4 over GF(317) with valence 1\nU2 : Full Vector space of degree 8 over GF(317)\nU1 : Full Vector space of degree 8 over GF(317)\n\\end{code}\n\\end{example}\n\n", "meta": {"hexsha": "13518792b13099b070679735e02cfc0de4e5e919", "size": 7830, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/longer-exs.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/longer-exs.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/longer-exs.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.9591836735, "max_line_length": 108, "alphanum_fraction": 0.640357599, "num_tokens": 2904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6919419036196657}}
{"text": "\\chapter{Proofs by Contradiction}\n\\label{chapter:indirect-proofs}\n\\marginurl{%\n  Proofs by Contradiction:\\\\\\noindent\n  Introduction to Mathematical Reasoning \\#3\n}{youtu.be/bWP0VYx75DI}\n\\section{Proving Negative Statements}\nThe direct method is not very convenient when we need to prove the negation of\na statement.\n\nFor example, we may try to prove that $78 n + 102 m = 11$ does not have integer\nsolutions. It is not clear how to prove it directly since we can not consider\nall possible $n$ and $m$. Hence, we need another approach. Let us assume that\nsuch a solution $n$, $m$ exists. Note that $78 n + 102 m$ is even, but $11$ is\nodd. In other words, an odd number is equal to an even number, which is\nimpossible. Thus, the assumption was false.\n\nConsider another example, let us prove that if $p^2$ is even, then\n$p$ is also even ($p$ is an integer). Assume the opposite; i.e. that $p^2$ is\neven but $p$ is not.\\footnote{%\n  Note that we use here the statement that an integer $n$ is not even iff it is\n  odd, which, formally speaking, should be proven.\n}\nLet $p = 2b + 1$. Note that $p^2 = (2b + 1)^2 = 2(2b^2 + 2b) + 1$.\nHence, $p^2$ is odd which contradicts to the assumption that $p^2$ is even.\n\nUsing this idea we may prove much more complicated results e.g. one may show\nthat $\\sqrt{2}$ is irrational. For the sake of contradiction, let us assume\nthat it is not true. In other words there are $p$ and $q$ such that\n$\\sqrt{2} = \\frac{p}{q}$ and $\\frac{p}{q}$ is an irreducible fraction.\n\nNote that $\\sqrt{2} q = p$, so $2q^2 = p^2$. Which implies that $p$ is even\nand $4$ divides $p^2$. Therefore $4$ divides $2q^2$ and $q$ is also even. As\na result, we get a contradiction with the assumption that $\\frac{p}{q}$ is an\nirreducible fraction.\n\n\\begin{template}\n  \\textbf{Template for proving a statement by contradiction.} \\\\\n\n  Assume, for the sake of contradiction, that \\emph{the statement} is false.\n  Then \\emph{present some argument that leads to a contradiction}. Hence, the\n  assumption is false and \\emph{the statement} is true.\n\\end{template}\n\n\\begin{exercise}\n  Show that $\\sqrt{3}$ is irrational.\n\\end{exercise}\n\n\\begin{exercise}\n  Let $a$ and $b$ be some integers. Show that $a^2 - 4b - 2 \\neq 0$.\n\\end{exercise}\n\\begin{solution}\n  Assume, for the sake of contradiction, that such $a$ and $b$ exist. Note that\n  $a^2 = 4b + 2$, hence, $a$ is even but $a^2$ is not divisible for $4$ which is a\n  contradiction.\n\\end{solution}\n\n\\section{Proving Implications by Contradiction}\nThis method works especially well when we need to prove an implication.\nSince the implication $A \\implies B$ is false only when $A$ is true but $B$ is\nfalse, it is enough to derive a contradiction from the fact that $A$ is true\nand $B$ is false.\n\nWe have already seen such examples in the previous section, we proved that\n$p^2$ is even implies $p$ is even, for any integer $p$. Let us consider another\nexample. Let $a$ and $b$ be real numbers such that $a > b$. We need to show that\n$(ac < bc) \\implies c < 0$. So we may assume that $ac < bc$ but $c \\ge 0$. By\nthe multiplicativity of the inequalities we know that if $(a > b)$ and $c > 0$,\nthen $ac > bc$ which contradicts to $ac < bc$.\n\nA special case of such a proof is when we need to prove the implication\n$A \\implies B$, assume that $B$ is false and derive that $A$ is false which\ncontradicts to  $A$ (such proofs are called proofs by contraposition); note\nthat the previous proof is a proof in this form.\n\n\\section{Proof of ``OR'' Statements}\nAnother important case is when we need to prove that at least one of two\nstatements is true. For example, let us prove that $ab = 0$ iff $a = 0$ or\n$b = 0$. We start from the implication from the right to the left. Since if\n$a = 0$, then $ab = 0$ and the same is true for $b = 0$ this implication is\nobvious.\n\nThe second part of the proof is the proof by contradiction. Assume $ab = 0$,\n$a \\neq 0$, and $b \\neq 0$. Note that $b = \\frac{ab}{a} = 0$,\nhence $b = 0$ which is a contradiction to the assumption.\n\n\n\\begin{chapterendexercises}\n    \\exercise[recommended] Prove that if $n^2$ is odd, then $n$ is odd.\n    \\exercise  In Euclidean (standard) geometry, prove: If two lines share a\n        common perpendicular, then the lines are parallel.\n        \\begin{solution}\n          Let us denote by $AB$ the common perpendicular. Assume that the lines\n          are not parallel (note that these lines are different) i.e. that there\n          is an intersection $C$ of these lines.\n\n          Note that the angles $CAB$ and $CBA$ are right, hence, the angle $ACB$\n          is equal to $0$ degrees. So the lines are the same, which is a\n          contradiction. \n\n          Hence, the assumption was incorrect i.e. the lines are parallel.\n        \\end{solution}\n    \\exercise[recommended] Let us consider four-lines geometry, it is a theory with\n        undefined terms: point, line, is on, and axioms:\n        \\begin{enumerate}\n            \\item there exist exactly four lines,\n            \\item any two distinct lines have exactly one point on both of them, and\n            \\item each point is on exactly two lines.\n        \\end{enumerate}\n\n        Show that every line has exactly three points on it.\n        \\begin{solution}\n          Let us assume the opposite; i.e. there is a line $\\ell$ with four\n          points $p_1, \\dots, p_4$ on it. By axiom~3, for each of these points\n          $p_i$ there is a line $\\ell_i \\neq \\ell$ such that $p_i$ is on $\\ell$.\n          Since we have only $4$ lines and $\\ell_i \\neq \\ell$, then there are $i\n          \\neq j$ such that $\\ell_i = \\ell_j$. As a result, $p_i$ and $p_j$ are\n          on $\\ell$ and $\\ell_i$, it is contradicting to axiom~2.\n        \\end{solution}\n    \\exercise Let us consider group theory, it is a theory with undefined\n        terms: group-element and times (if $a$ and $b$ are group elements,\n        we denote $a$ times $b$ by $a \\cdot b$), and axioms:\n        \\begin{enumerate}\n          \\item $(a \\cdot b) \\cdot c = a \\cdot (b \\cdot c)$\n            for every group-elements $a$, $b$, and $c$;\n          \\item there is a unique group-element $e$ such that\n            $e \\cdot a = a = a \\cdot e$ for every group-element $a$\n            (we say that such an element is the identity element);\n          \\item for every group-element $a$ there is a group-element $b$\n            such that $a \\cdot b = e$, where $e$ is the identity element;\n          \\item for every group-element $a$ there is a group-element $b$\n            such that $b \\cdot a = e$, where $e$ is the identity element.\n        \\end{enumerate}\n\n        Let $e$ be the identity element. Show the following statements\n        \\begin{itemize}\n          \\item if $b_0 \\cdot a = b_1 \\cdot a = e$, then $b_0 = b_1$, for every\n            group-elements $a$, $b_0$, and $b_1$.\n          \\item if $a \\cdot b_0 = a \\cdot b_1 = e$, then $b_0 = b_1$, for every\n            group-elements $a$, $b_0$, and $b_1$.\n          \\item if $a \\cdot b_0 = b_1 \\cdot a = e$, then $b_0 = b_1$, for every\n            group-elements $a$, $b_0$, and $b_1$.\n        \\end{itemize}\n    \\exercise Let us consider three-points geometry, it is a theory with\n        undefined terms: point, line, is on, and axioms:\n        \\begin{enumerate}\n            \\item There exist exactly three points.\n            \\item Two distinct points are on exactly one line.\n            \\item Not all the three points are collinear i.e. they do not lay on the\n                same line.\n            \\item Two distinct lines are on at least one point i.e. there is at\n              least one point such that it is on both lines.\n        \\end{enumerate}\n\n        Show that there are exactly three lines.\n\n        \\begin{solution}\n            Let us denote the points by $p_1$, $p_2$, and $p_3$ (they exist by\n            Axiom~1). By Axiom~2, there are lines $l_{1, 2}$,\n            $l_{1, 3}$, and $l_{2, 3}$ such that $p_i$ and $p_j$ are on\n            $l_{i, j}$ ($i \\neq j$).\n\n            Note that the lines $l_{1, 2}$, $l_{1, 3}$, and $l_{2, 3}$ are different.\n            Indeed, assume the opposite, i.e., without loss of generality that\n            $l_{1, 2} = l_{1, 3}$. Note that $p_1$, $p_2$, and $p_3$ are on $l_{1, 2}$\n            which contradicts Axiom~3.\n\n            Let us now prove that there are no other lines. Assume the\n            opposite i.e. that there is another line $l$. There is a\n            point that is on $l$ and $l_{1, 2}$. Without loss of generality,\n            this point is $p_1$. Additionally there is a point $p_i$\n            ($i \\neq 1$) that is on $l$ and  $l_{2, 3}$. However, it means that\n            $p_1$ and $p_i$ are on $l$ which contradicts Axiom~2.\n        \\end{solution}\n    \\exercise Show that there are irrational numbers $a$ and $b$ such that\n        $a^b$ is rational.\n        \\begin{solution}\n          Assume that $a^b$ is irrational for all irrationals $a$ and $b$. Since\n          $\\sqrt{2}$ is irrational $\\sqrt{2}^{\\sqrt{2}}$ is also irrational.\n          However, $(\\sqrt{2}^{\\sqrt{2}})^{\\sqrt{2}} = \\sqrt{2}^2 = 2$, which\n          contradicts to the assumption.\n\n          As a result, there are irrational $a$ and $b$ such that $a^b$ is\n          rational.\n        \\end{solution}\n    \\exercise[recommended] Show that there does not exist the largest integer.\n\n    \\exercise Let us consider Young's geometry, it is a theory with undefined\n        terms: point, line, is on, and axioms:\n        \\begin{enumerate}\n            \\item there exists at least one line,\n            \\item every line has exactly three points on it,\n            \\item not all points are on the same line,\n            \\item for two distinct points, there exists exactly one line on both of\n              them,\n            \\item if a point does not lie on a given line, then there exists exactly\n              one line on that point that does not intersect the given line.\n        \\end{enumerate}\n\n        Show that for every point, there are exactly four lines on that point.\n        \\begin{solution}\n          First, we prove that for every point, there is a line not on that\n          point. Let $p$ be some point. By the first axiom, there is a line\n          $\\ell$. Assume that $p$ is on $\\ell$ (otherwise we proved the\n          statement). By axiom 2, there are two other points $p_1$ and $p_2$ on\n          this line. By axiom 3, there is a point $q$ not on $\\ell$. Finally, by\n          axiom 4, there is a line $\\ell'$ on $p_1$ and $q$. Note that $\\ell'\n          \\neq \\ell$, thus $p$ is not on $\\ell'$.\n          \n          Now we are ready to prove that there are at least four lines. Let $p$\n          be a point and $\\ell$ be a line such that $p$ is not on $\\ell$. By\n          axiom 2, there are three points $p_1$, $p_2$, and $p_3$ on $\\ell$. By\n          axiom 4, there are lines $\\ell_1$, $\\ell_2$, and $\\ell_3$ such that\n          $p$ is on all of them and $p_i$ is on $\\ell_i$ for $i \\in \\range{3}$.\n          By axiom 5, there is a line $\\ell_4$ contain $p$ but $p_1$, $p_2$,\n          and $p_3$  are not on $\\ell_4$. Thus, there are at least four lines\n          through $p$.\n\n\n          Let us now prove that there is no other line $\\ell_5$ such that $p$ is\n          on $\\ell_5$. By axiom 5, there is a point $p_i$ such that $p_i$ is on\n          both $\\ell_5$ and $\\ell$. But this contradicts to axiom 4, since $p_i$\n          is also on $\\ell_i$.\n        \\end{solution}\n    \\exercise Let us consider five-point geometry, it is a theory with undefined\n      terms: point, line, is on, and axioms:\n      \\begin{enumerate}\n        \\item there exist exactly five points,\n        \\item each two distinct points have exactly one line on both of them, and\n        \\item each line has exactly two points.\n      \\end{enumerate}\n\n      Show that each point has exactly four lines on it.\n      \\begin{solution}\n        Let us consider some point $p$ and let $p_1$, \\dots, $p_4$ be all other\n        points (they exist by axiom~1). Note that there are lines $l_1$, \\dots,\n        $l_4$ such that $l_i$ goes throw $p$ and $p_i$. Note that $l_i \\neq l_j$\n        for $i \\neq j$ by axiom~3 since $p_i$ is not on $l_j$ and there are\n        already two points on $l_i$. Thus we proved that any point is on at\n        least $4$ lines.\n\n        Let us now prove that there are no other lines. Assume that $p$ is on a\n        line $l$ and $l$ is not equal to $l_i$ for all $i$. However, by axiom 2,\n        there is a point $p_j$ on $\\ell$. Thus $l = l_j$ which is a contradiction.\n      \\end{solution}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "77cc6d4b555033d1a65a0cc46cba64165a22bea6", "size": 12553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_2_proofs_by_contradiction.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_2_proofs_by_contradiction.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_2_proofs_by_contradiction.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": 50.8218623482, "max_line_length": 86, "alphanum_fraction": 0.6299689317, "num_tokens": 3660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.6919043769387005}}
{"text": "\\section{Homotopy, star-shaped regions}\nAs homology is a functor $H_\\ast:\\mathbf{Top}\\to\\mathbf{Ab}$, it preserves isomorphisms: homeomorphic spaces have isomorphic homology. However, homology is not always able to distinguish between non-homeomorphic spaces. We introduce the looser notion of homotopy, which is a central concept of algebraic topology, and later we will show that homology is a homotopy invariant.\n\\begin{definition}\nLet $f_0,f_1:X\\to Y$ be two maps. A \\emph{homotopy} from $f_0$ to $f_1$ is a map $h:X\\times I\\to Y$ such that $h(x,0)=f_0(x)$ and $f(x,1)=f_1(x)$. We say that $f_0$ and $f_1$ are \\emph{homotopic} and write $f_0\\sim f_1$.  This notation is justified because it is indeed an equivalence relation (transitivity follows from the gluing lemma).\n\\end{definition}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{assets/L05/05-homotopy}\n\t\\caption{A homotopy $h$ between $f_0,f_1:X\\to Y$.}\n\t\\label{fig:05-homotopy}\n\\end{figure}\n\nWe denote by $[X,Y]$ the set $\\mathbf{Top}(X,Y)/\\sim$.\n\nSuppose we have a map $g: Y\\to Z$ and homotopic maps $f_0,f_1:X\\to Y$, with a homotopy $h:f_0\\sim f_1$. Then $g\\circ h$ gives a homotopy $g\\circ f_0 \\sim g\\circ f_1$. Similarly, if $g:W\\to X$ is a map and $f_0,f_1:X\\to Y$ are homotopic, then $f_0\\circ g\\sim f_1\\circ g$.\n\nIf $g_0\\sim g_1:Y\\to Z$ and $f_0\\sim f_1: X\\to Y$, then $g_0\\circ f_0\\sim g_0 \\circ f_1\\sim g_1 \\circ f_1$. Hence we are able to compose homotopy classes, giving the dotted arrow below.\n\\begin{equation*}\n\\xymatrix{\\mathbf{Top}(Y,Z)\\times\\mathbf{Top}(X,Y)\\ar[d]\\ar[r] & \\mathbf{Top}(X,Z)\\ar[d]\\\\\n[Y,Z]\\times[X,Y]\\ar@{-->}[r] & [X,Z]}\n\\end{equation*}\n\n\\begin{definition}\nThe \\emph{homotopy category of topological spaces} is $\\mathrm{Ho}(\\mathbf{Top})$ whose objects are topological spaces and $\\mathrm{Ho}(\\mathbf{Top})(X,Y)=[X,Y]=\\mathbf{Top}(X,Y)/\\sim$.\n\\end{definition}\n\\begin{definition}\n\tA map $f:X\\to Y$ is a \\emph{homotopy equivalence} if $[f]\\in[X,Y]$ is an isomorphism in $\\htop$. In other words, there is $g:Y\\to X$ such that $fg\\sim 1_Y$ and $gf\\sim 1_X$.\n\\end{definition}\n%This is an interesting category because it has \\textit{terrible} categorical properties\\todo{This sentence seems a bit random atm; give examples of why it's terrible? or just remove?}.\n\nIn Section \\ref{lec:6-homotopy-invariance-of-homology} we will prove:\n\\begin{theorem}[Homotopy invariance of homology]\n\tIf $f_0\\sim f_1$, then $ H_\\ast(f_0)= H_\\ast(f_1)$.\n\\end{theorem}\nThis theorem states that the homology functor $H_\\ast:\\mathbf{Top}\\to\\mathbf{Ab}$ factors as $\\mathbf{Top}\\to\\mathrm{Ho}(\\mathbf{Top})\\to\\mathbf{Ab}$. In particular, it cannot distinguish between homotopy equivalent spaces. (Caution: spaces with isomorphic homology need not be homotopy equivalent.)\n\\begin{example}\\label{exa:homotopy-equivalence-sphere}\nThe inclusion $S^{n-1}\\subseteq \\mathbf{R}^n-\\{0\\}$ is a homotopy equivalence. The homotopy inverse $p:\\mathbf{R}^n-\\{0\\}\\to S^{n-1}$ can be obtained by dividing a (always nonzero!) vector by its length. Clearly $p\\circ i=1_{S^{n-1}}$. A homotopy $i\\circ p\\sim 1_{\\mathbf{R}^n-\\{0\\}}$ is given by $(v,t)\\mapsto tv+(1-t)\\frac{v}{||v||}$. This example shows that homotopy equivalence does not preserve compactness.\n\\end{example}\n\\begin{definition}\nA space $X$ is \\emph{contractible} if the map $X\\to\\ast$ is a homotopy equivalence.\n\\end{definition}\n\n\\begin{definition}\n\tA \\emph{star-shaped region} is a subspace $X$ of Euclidean space containing $\\{0\\}$, such that for all $x\\in X$ and $t\\in[0,1]$, $tx\\in X$. \n\\end{definition}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.4\\linewidth]{assets/L05/05-star-shaped-region}\n\t\\caption{A star-shaped region.}\n\t\\label{fig:05-star-shaped-region}\n\\end{figure}\n\nFor example, any convex region containing the origin is star-shaped. An argument similar to the one in Example \\ref{exa:homotopy-equivalence-sphere} shows that the inclusion of $\\{0\\}$ into a star-shaped region is a homotopy equivalence. Thus star-shaped regions are contractible. Our goal now is to prove the following.\n\\begin{theorem}\\label{thm:star-shaped-homology}\n\tLet $X$ be a star-shaped region. The augmentation map $\\epsilon: H_\\ast(X)\\to \\mathbf{Z}$ is an isomorphism, i.e., $ H_0(X)\\cong\\mathbf{Z}$ and $ H_i(X)\\cong 0$ for $i>0$.\n\\end{theorem}\n%The strategy of proof is that $\\epsilon$ is induced by sending $X\\to \\ast$. We'll look at the chain map $S_\\ast(x)\\to\\mathbf{Z}\\to S_\\ast(X)$. We'll show that this composite induces the same map in homology as the identity map, which means that the identity map factors through $\\mathbf{Z}$, so we're done. (probably not necessary to include this now that it's been moved to this section, given that the proof follows shortly)\nBefore proving this, we will give a notion of homotopy in the category of chain complexes.\n\\begin{definition}\nLet $C_\\bullet,D_\\bullet$ be chain complexes, and $f_0,f_1:C_\\bullet\\to D_\\bullet$ be chain maps. A \\emph{chain homotopy} $h:f_0\\sim f_1$ is a collection of homomorphisms $h:C_n\\to D_{n+1}$ such that $\\partial h+h\\partial=f_1-f_0$.\n\\end{definition}\n\t\t\t\\begin{equation*}\n\t\t\t\\xymatrix{C_{n+2}\\ar[r]^{f_1-f_0}\\ar[d]^\\partial & D_{n+2}\\ar[d]^\\partial\\\\\n\t\t\tC_{n+1}\\ar@{-->}[ur]^h\\ar[r]^{f_1-f_0}\\ar[d]^\\partial & D_{n+2}\\ar[d]^\\partial\\\\\n\t\t\tC_n\\ar@{-->}[ur]^h\\ar[r]_{f_1-f_0} & D_n}\n\t\t\t\\end{equation*}\nThe following lemma shows the significance of this condition.\n\\begin{lemma}\n\tIf $f_0,f_1:C_\\bullet\\to D_\\bullet$ are chain homotopic, then $f_{0,\\ast}=f_{1,\\ast}: H(C)\\to H(D)$.\n\\end{lemma}\n\\begin{proof}\n\tWe show that $(f_1-f_0)_\\ast=0$. Let $c\\in Z_n(C_\\bullet)(C)$, so that $\\partial c=0$. Then $(f_1-f_0)_\\ast c=(\\partial h+h\\partial)c=\\partial hc+h\\partial c=\\partial hc$ is a boundary, which is zero in homology.\n\\end{proof}\n\\begin{proof}[Proof of Theorem \\ref{thm:star-shaped-homology}]\n\tThe maps $\\{0\\}\\to X$ and $X\\to \\{0\\}$ induce $\\mathbf{Z}\\xrightarrow{\\eta}S_\\ast(X)$ and $S_\\ast(X)\\xrightarrow{\\epsilon}\\mathbf{Z}$ respectively. It is clear that $\\epsilon\\eta = 1:\\mathbf{Z}\\to\\mathbf{Z}$. We now proceed to show that $\\eta\\epsilon\\sim 1:S_\\ast(X)\\to S_\\ast(X)$. Note that the composite $\\eta \\epsilon$ kills all chains in dimensions greater than zero, and on zero-chains we have $\\eta\\epsilon(\\sum a_ix_i)=(\\sum a_i)c_0$ where $c_0$ is the zero-simplex at the origin.\n\t\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{assets/L05/05-star-shaped-line-homotopy-pf}\n\t\\caption{The map $h$ illustrated on a 1-simplex.}\n\t\\label{fig:05-star-shaped-line-homotopy-pf}\n\\end{figure}\n\t\n\tFor $\\sigma\\in\\Sin_q(X)$, define $h:\\Sin_q(X)\\to\\Sin_{q+1}(X)$ as follows:\n\t$$h\\sigma(t_0,\\cdots,t_{q+1})=(1-t_0)\\sigma\\left(\\frac{(t_0,\\cdots,t_{q+1})}{1-t_0}\\right).$$\n\tThis extends by linearity to a map $h:S_q(X)\\to S_{q+1}(X)$.\n\tObserve that $d_0 h \\sigma = \\sigma$, and if $q \\geq 1$, $d_i h \\sigma = h d_{i-1} \\sigma$. Then, if $\\sigma \\in \\Sin_q(X)$ with $q \\geq 1$,\n\t\\begin{align*}\n\t\t\\partial h \\sigma &= \\sum_{i=0}^{q+1} (-1)^{i} d_i h\\sigma\\\\\n\t\t&= \\sigma - h \\sum_{i=0}^q (-1)^i d_i \\sigma\\\\\n\t\t&= \\sigma - h\\partial \\sigma\\\\\n\t\t\\partial h \\sigma + h \\partial \\sigma &= \\sigma.\n\t\\end{align*}\n\tIf $\\sigma \\in \\Sin_0(X)$, then $d_1 h \\sigma = c_0$ and we instead get $\\partial h \\sigma + h \\partial \\sigma = \\sigma - c_0$. Thus $h:S_q(X)\\to S_{q+1}(X)$ is a chain homotopy $\\eta \\epsilon \\sim 1$ as desired.\n\\end{proof}\n% Continue indenting like this.\n", "meta": {"hexsha": "b2d13dc2c757b7eafdc286f2e5585191aa4a1935", "size": 7378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-5-homotopy.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-5-homotopy.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-5-homotopy.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": 76.0618556701, "max_line_length": 488, "alphanum_fraction": 0.7026294389, "num_tokens": 2647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8840392817460332, "lm_q1q2_score": 0.6919043757431247}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage{amsmath,amsthm}\n\\usepackage{listings}\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\\usepackage{color}\n\\usepackage{graphicx}\n\n\\lstset{basicstyle=\\footnotesize\\ttfamily,language=Matlab}\n\n\\pagestyle{myheadings}\n\\markboth{Volume}{Volume}\n\n\\input{../fncextra}\n\n\\begin{document}\n\n\n\\begin{center}\n  \\bf Depths of despair\n\\end{center}\n\nNumerical integration of a function of one variable is called quadrature. The analogous situation of integrating a function of two variables is sometimes called \\emph{cubature}. In this project you will explore the extension of the trapezoid formula to this situation, and apply it to find the volume of water in a patch of the ocean.\n\nConsider the problem $\\iint_R f(x,y)\\,dx\\,dy$, where $R$ is the rectangle $[x_0,x_m] \\times [y_0,y_n]$. We discretize each variable using the space steps $h$ and $k$, respectively, so that $x_i = x_0 + ih$ for $i=0,\\ldots,n$, and $y_j=y_0+jk$ for $j=0,\\ldots,m$. (This requires that $h=(x_m-x_0)/m$ and $k=(y_n-y_0)/n$.) The result is a decomposition of $R$ into rectangles with the nodes at the corners. The strategy is to compute a volume over each little rectangle and sum them over the whole domain. Here's an example of how the discretization process works in MATLAB:\n\n\\input{CubatureSetup}\n\nAt the corners of each rectangle we have values of $z$ according to $Z_{ij}=f(x_i,y_j)$. We can model the surface $z=f(x,y)$ over one of these rectangles using the function $L_{ij}(x,y)=a + b (x-x_i) + c(y-y_j) + d(x-x_i)(y-y_j)$, where $a,b,c,d$ are determined by interpolation conditions at the four corners of the rectangle. (These coefficients depend on $i$ and $j$, but that is left out to make the notation clearer.) We get a solid defined over the rectangle looking like this:\n\n\\input{CubatureSolid}\n\n\n\\subsection*{Objectives}\n\\label{sec:objectives}\n\nMathematical content:\n\\begin{enumerate}\n\\item Using a symbolic math package if you want, derive exact expressions for the interpolant $L_{ij}$ over the rectangle whose lower left corner is $(x_i,y_j)$, in terms of $h$, $k$, and four values $Z_{ij}$, $Z_{i+1,j}$, $Z_{i,j+1}$, $Z_{i+1,j+1}$. (Show the steps involved, whether you use a computer or not.)  \n\\item Integrate the interpolant over the rectangle to get another expression in terms of the same quantities. This is $V_{ij}$, the volume used to approximate the integral of $f$ over the rectangle. \n\\item Show that if the $V_{ij}$ are added up over all $i$ and $j$, the result is identical to applying the trapezoid formula in each dimension sequentially over the domain (i.e., as an iterated integral). \n\\end{enumerate}\n\nComputational content:\n\\begin{enumerate}\n\\item Download and install the GeoMapApp at \\texttt{www.geomappapp.org}. \n\\item Start the app and agree to the license. You should get a window with a projected map of the world, in latitude-longitude corrdinates as measured in degrees of arc, and some GUI widgets. Use the magnifying glass tool to select a small rectangle over the ocean. You should try to get it to include about 1-2 degrees of latitiude (the $y$ axis). \n\\item Click on the icon that looks like a grid. After a few seconds another window should open with a histogram in it. Make sure the dropdown menu at the top of this window says ``GMRT Grid'' with some version number. Click on the floppy disk icon, select ``Grid: .XYZ (ascii format)'', and save the file to your computer. At this point you can close GeoMapApp. \n\\item You can import this data into MATLAB by double-clicking on it in the ``Current Folder'' tab of the MATLAB Desktop, and using the resulting dialog. What you will get is three columns of $x$, $y$, and $z$ data on a regular rectangular grid, where $x$ and $y$ are reported in degrees of arc, and $z$ will be negative to represent depths below sea level.\n\\item \\textbf{After converting all the data into km units}, use it and the formula you derived above to estimate the amount of water in your patch of ocean.\n\\end{enumerate}\n\n\n\\subsection*{Submission}\n\nSubmit a function \n\\begin{verbatim}\nfunction volume = ocean(x,y,z)\n\\end{verbatim}\nthat will compute an approximation to the volume using three vectors of depth data as described in the previous section.\n\nPrepare a report that includes the following.\n\\begin{enumerate}\n\\item The required mathematical content. \n\\item Details needed to acquire the same raw data from the app and compute your volume result.\n\\item Some form of quantitative check on whether your answer is reasonable, in the sense of being at least the right order of magnitude. \n\\item A brief statement of the contributions of each team member to the project. \\textbf{Be as specific as possible.}\n\\end{enumerate}\nYour report should read like a document understandable to anyone else in the class. All of the mathematical expressions in your document should be typeset properly as mathematical notation. You have several options: Word, OpenOffice, \\LaTeX, \\texttt{texmacs.org}, Mathematica. Submit your report as a single PDF document, along with your M-file. \n\n\\end{document}\n\n", "meta": {"hexsha": "249e3141f076295146da0db3564a4a57dff1c52d", "size": 5094, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/oceanvolume/oceanvolume.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/oceanvolume/oceanvolume.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/oceanvolume/oceanvolume.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": 68.8378378378, "max_line_length": 572, "alphanum_fraction": 0.7618767177, "num_tokens": 1314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.6919039756229448}}
{"text": "\\section{Code}\n\n\\begin{minted}{python}\n# -*- coding: utf-8 -*-\n\"\"\"\nTRABAJO 1. \nAutor Blanca Cano Camarero   \nGrupo 2\n\"\"\"\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D # to display 3d function \n\nnp.random.seed(1)\ndef STOP_EXECUTION_TO_SEE_RESULT():\n        input('\\n--- End of a section, press any enter to continue ---\\n')\n        \n\n\nprint('GRADIENT DESCENDENT\\n')\nprint('Exercise 1\\n')\n\n## 1\n\ndef gradient_descent(initial_point, loss_function, gradient_function,  eta, max_iter, target_error):\n    '''\n    initicial point: w_0 \n    E: error function \n    gradient_function\n    eta:  step size \n\n    ### stop conditions ###\n    max_iter\n    target_error\n\n    #### return ####\n    (w,iterations)\n    w: the coordenates that minimize E\n    it: the numbers of iterations needed to obtain w\n    \n    '''\n\n    iterations = 0\n    error = E( initial_point[0], initial_point[1])\n    w = initial_point\n  \n    while ( (iterations < max_iter) and(error > target_error)): \n\n        w = w - eta * gradient_function(w[0], w[1])\n        \n        iterations += 1\n        error = loss_function(w[0], w[1])\n \n    \n    return w, iterations\n\n############  2 ###################################\ndef E(u,v):\n    '''\n    Function to minimize\n    '''\n    return np.float64(\n        ( u**3 * np.e**(v-2) - 2*v**2 * np.e**(-u) )**2\n    )\n\n\ndef dEu(u,v):\n    '''\n    Partial derivate of E with respect to the variable u\n    '''\n    return np.float64(\n        2\n        *( u**3 * np.e**(v-2) - 2*v**2 * np.e**(-u))\n        *( 3* u**2 * np.e**(v-2) + 2*v**2 * np.e**(-u))      \n    )\n    \ndef dEv(u,v):\n    '''\n    Partial derivate of E with respect to the variable v\n    '''\n    return np.float64(\n        2\n        *( u**3 * np.e**(v-2) - 2*v**2 * np.e**(-u) )\n        *( u**3 * np.e**(v-2) - 4*v * np.e**(-u))\n    )\n\n\ndef gradE(u,v):\n    ''' \n        gradient of E\n    '''\n    return np.array([dEu(u,v), dEv(u,v)])\n\n\n\n######  conditions  \neta = 0.1 \nmax_iter = 10000000000\ntarget_error = 1e-14\ninitial_point = np.array([1.0,1.0])\nw, it = gradient_descent( initial_point,E, gradE, eta, max_iter, target_error )\n\n\n# DISPLAY FIGURE\n\nx = np.linspace(-30, 30, 50)\ny = np.linspace(-30, 30, 50)\nX, Y = np.meshgrid(x, y)\nZ = E(X, Y) #E_w([X, Y])\nfig = plt.figure()\nax = Axes3D(fig)\nsurf = ax.plot_surface(X, Y, Z, edgecolor='none', rstride=1,\n                        cstride=1, cmap='jet')\nmin_point = np.array([w[0],w[1]])\nmin_point_ = min_point[:, np.newaxis]\nax.plot(min_point_[0], min_point_[1], E(min_point_[0], min_point_[1]), 'r*', markersize=10)\nax.set(title='Ejercicio 1.2. Función sobre la que se calcula el descenso de gradiente')\nax.set_xlabel('u')\nax.set_ylabel('v')\nax.set_zlabel('E(u,v)')\nplt.show()\n\n######### Exercise 1, part 2 answers  ######\nprint('2 a) Function:  E(u,v) = (u^3 e^{(v-s)} - 2* v^2 e^{-u})^2')\n\nprint('dE_u = 2(u^3 e^{(v-s)} - 2* v^2 e^{-u})(3u^2e^{(v-2)} + 2 v^2 e^{-u} ), ')\n\nprint( 'dE_v =  2(u^3 e^{(v-s)} - 2* v^2 e^{-u})(u^3 e^{(v-2)} - 4 v e^{-u}')\n\nprint ('So de gradient is: \\n nabla E(u,v) =(2(u^3 e^{(v-s)} - 2* v^2 e^{-u})(3u^2e^{(v-2)} + 2 v^2 e^{-u} ), 2(u^3 e^{(v-s)} - 2* v^2 e^{-u})(u^3 e^{(v-2)} - 4 v e^{-u}) )')\n\nprint ('2b) Numbers of iterations : ', it)\nprint ('2c) Final coodinates: (', w[0], ', ', w[1],')')\n\n\n\n############################### EXERCISE 1 PART 3 #########\n\ndef f(x,y):\n    '''\n    Function to minimize\n    '''\n    return np.float64(\n        (x+2)**2 + 2*(y-2)**2 + 2* np.sin( 2* np.pi * x)* np.sin( 2* np.pi * y)\n    )\n\ndef dfx(x,y):\n    '''\n    Partial derivate of f with respect to the variable x\n    '''\n    return np.float64(\n        2*( x+2 ) + 4* np.pi* np.cos(  2* np.pi * x )* np.sin(2* np.pi * y)\n    )\n\n\ndef dfy(x,y):\n    '''\n    Partial derivate of f with respect to the variable y\n    '''\n    return np.float64(\n        4*( y-2 ) + 4* np.pi* np.cos(  2* np.pi * y )* np.sin(2* np.pi * x)\n\n    )\n\n\ndef gradF(x,y):\n    ''' \n        gradient of E\n    '''\n    return np.array([dfx(x,y), dfy(x,y)])\n\n######################## gradien descendent with trace  ############\n\ndef gradient_descent_trace(initial_point, loss_function, gradient_function,  eta, max_iter):\n    '''\n    initicial point: w_0 \n    loss_function: error function \n    gradient_function\n    eta:  step size \n\n    ### stop conditions ###\n    max_iter\n\n    #### return ####\n    (w,iterations)\n    w: the coordenates that minimize loss_function\n    it: the numbers of iterations needed to obtain w\n    \n    '''\n\n    iterations = 0\n    error = loss_function( initial_point[0], initial_point[1])\n    w = [initial_point]\n  \n    while iterations < max_iter: \n\n        new_w = w[-1] - eta * gradient_function(w[-1][0], w[-1][1])\n        \n        \n        iterations += 1\n        error = loss_function(new_w[0], new_w[1])\n        w.append( new_w ) \n    \n    return w, iterations\n\n\n\n######  conditions  \nsmaller_eta = 0.01\nbigger_eta = 0.1 \nmax_iter = 50\ninitial_point = np.array([-1.0,1.0])\n\n#### run \nsmaller_w, smaller_it = gradient_descent_trace( initial_point,f, gradF, smaller_eta, max_iter)\nbigger_w, bigger_it = gradient_descent_trace( initial_point,f, gradF, bigger_eta, max_iter)\n\nimages_smaller_eta = [ f(x[0],x[1]) for x in smaller_w ]\nimages_bigger_eta = [ f(x[0],x[1]) for x in bigger_w]\n\nprint(f'With eta = {smaller_eta}, coordenates (x,y)= {(smaller_w[-1][0],smaller_w[-1][1])}, the number of iterations: {smaller_it} and the image is f(x,y) = {images_smaller_eta[-1]}')\n\nprint(f'With eta = {bigger_eta}, coordenates (x,y)={(bigger_w[-1][0],bigger_w[-1][1])}, the number of iterations: {bigger_it} and the image is f(x,y) = {images_bigger_eta[-1]}')\n\n\n########### PLOTTING\nx_label = 'Number of iterations'\ny_label = 'f(x,y)'\nbigger_eta_label = '$\\eta$ = '+str(bigger_eta)\nsmaller_eta_label = '$\\eta$ = '+str(smaller_eta)\n\n## bigger eta ####\nplt.clf()\nplt.plot(images_bigger_eta, label=bigger_eta_label)\nplt.xlabel(x_label)\nplt.ylabel(y_label)\nplt.title(f'Gradient descent of f with $\\eta =$ {bigger_eta}')\n\n\nplt.legend()\nplt.show()\nSTOP_EXECUTION_TO_SEE_RESULT()\n## smaller eta ###\n\nplt.clf()\nplt.plot(images_smaller_eta, label=smaller_eta_label)\nplt.xlabel(x_label)\nplt.ylabel(y_label)\nplt.title(f'Gradient descent of f with $\\eta =$ {smaller_eta}')\n\n\nplt.legend()\nplt.show()\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n## comparation ###\nplt.clf()\nplt.plot(images_bigger_eta, label=r\"$\\eta$ = 0.1\")\nplt.plot( images_smaller_eta, label=r\"$\\eta$ = 0.01\")\n\nplt.xlabel('Iterations')\nplt.ylabel('f(x,y)')\n\nplt.title(\"Comparation of the gradient descendent for $f$ changing eta value  \")\n\n\nplt.legend()\nplt.show()\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\n\n### exta experimental ####\n\nepsilon_eta = 1e-14\nmax_iter = 50\ninitial_point = np.array([-1.0,1.0])\n\n\nepsilon_eta_label = '$\\eta$ = '+str(epsilon_eta)\n#### run \nepsilon_w, epsilon_it = gradient_descent_trace( initial_point,f, gradF, epsilon_eta, max_iter)\nimages_epsilon_eta = [ f(x[0],x[1]) for x in epsilon_w ]\n\n\nprint(f'With eta = {epsilon_eta}, coordenates (x,y)={(epsilon_w[-1][0],epsilon_w[-1][1])}, the number of iterations: {epsilon_it} and the image is f(x,y) = {images_epsilon_eta[-1]}')\nSTOP_EXECUTION_TO_SEE_RESULT()\n\nplt.clf()\nplt.plot(images_epsilon_eta, label=epsilon_eta_label)\nplt.xlabel(x_label)\nplt.ylabel(y_label)\nplt.title(f'Gradient descent of f with $\\eta =$ {epsilon_eta}')\n\n\nplt.legend()\nplt.show()\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n## smaller eta and tiny one ###\n\nplt.clf()\n\nplt.plot(images_epsilon_eta, label=epsilon_eta_label)\nplt.plot( images_smaller_eta, label=r\"$\\eta$ = 0.01\")\n\nplt.xlabel('Iterations')\nplt.ylabel('f(x,y)')\n\nplt.title(\"Comparation of the gradient descendent for $f$ changing eta value  \")\n\n\nplt.legend()\nplt.show()\nSTOP_EXECUTION_TO_SEE_RESULT()\n######################################################################\n\n#### exercise 3.b\n\ninitial_points = map(np.array, [[-.5, -.5],[1, 1], [2.1, -2.1], [-3,3],  [-2, 2]])\nminimum_value = np.Infinity\n\nprint('{:^17}  {:^17}  {:^9}'.format('Initial', 'Final', 'Value'))\n\nfor initial in initial_points:\n \n  w, _ = gradient_descent_trace(initial, f, gradF, 0.01, 50)\n  local_minimum = w[-1]\n  local_value = f(local_minimum[0], local_minimum[1])\n\n  print('{}  {}  {: 1.5f}'.format(initial, local_minimum, local_value))\n\n  \nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\n\"\"\"\nExercise 2 \nAuthor: Blanca Cano Camarero\n\"\"\"\n\ndef STOP_EXECUTION_TO_SEE_RESULT():\n        input('\\n--- End of a section, press any enter to continue ---\\n')\n        \n\nprint('_______LINEAR REGRESSION EXERCISE _______\\n')\nprint('Exercise 1')\ninput('\\n Enter to start\\n') \n\nlabel5 = 1\nlabel1 = -1\n\n\ndef readData(file_x, file_y):\n        '''\n        function for read data\n        '''\n\t# reads files\n        datax = np.load(file_x)\n        datay = np.load(file_y)\n        y = []\n        x = []\t\n        # Solo guardamos los datos cuya clase sea la 1 o la 5\n        for i in range(0,datay.size):\n                if datay[i] == 5 or datay[i] == 1:\n                        if datay[i] == 5:\n                                y.append(label5)\n                        else:\n                                y.append(label1)\n                        x.append(np.array([1, datax[i][0], datax[i][1]]))\n\n        x = np.array(x, np.float64)\n        y = np.array(y, np.float64)\n\t\n        return x, y\n\n\ndef Error(x,y,w):\n    '''quadratic error \n    INPUT\n    x: input data matrix\n    y: target vector\n    w:  vector to \n\n    OUTPUT\n    quadratic error >= 0\n    '''\n    error_times_n = np.float64(np.linalg.norm(x.dot(w) - y.reshape(-1,1))**2)\n  \n    return np.float64(error_times_n/len(x))\n\n\ndef dError(x,y,w):\n    ''' gradient\n    OUTPUT\n    column vector\n    '''\n    return  2/len(x)*(x.T.dot(x.dot(w) - y.reshape(-1,1)))\n    \n\n\ndef sgd(x,y, eta = 0.01, max_iter = 1000, batch_size = 32, error=10**(-10)):\n        '''\n        Stochastic gradient descent\n        INPUT \n        x: data set\n        y: target vector\n        eta: learning rate\n        max_iter \n\n        OUTPUT \n        w: weight vector\n        '''\n  \n        #initialize data\n        w = np.zeros((x.shape[1], 1), np.float64)\n        n_iterations = 0\n\n        len_x = len(x)\n        x_index = np.arange( len_x )\n        batch_start = 0\n        w_error = Error(x,y,w)\n\n        while n_iterations < max_iter and w_error > error :\n  \n                #shuffle and split the same into a sequence of mini-batches\n                np.random.shuffle(x_index)\n                for batch_start in range(0,  len_x, batch_size):\n                        iter_index = x_index[ batch_start : batch_start + batch_size]\n\n        \n                        w = w - eta* dError(x[iter_index, :], y[iter_index], w)\n        \n                n_iterations += 1\n                w_error = Error(x,y,w)\n\n   \n        return w\n\n\ndef sgd_exact_number_iter(x,y, eta = 0.01, max_iter = 1000, batch_size = 32, error = 10**(-10)):\n        '''\n        Stochastic gradient descent\n        INPUT \n        x: data set\n        y: target vector\n        eta: learning rate\n        max_iter \n        OUTPUT \n        w: weight vector\n        '''\n        #initialize data\n        w = np.zeros((x.shape[1], 1), np.float64)\n    \n        n_iterations = 0\n        batch_start = 0\n        len_x = len(x)\n    \n        x_index = np.arange( len_x )\n        w_error = Error(x,y,w)\n \n        while n_iterations < max_iter and w_error > error:\n                #shuffle and split the same into a sequence of mini-batches\n                if batch_start == 0:\n                        x_index = np.random.permutation(x_index)\n                iter_index = x_index[ batch_start : batch_start + batch_size]\n\n                w = w - eta* dError(x[iter_index, :], y[iter_index], w)\n                \n                n_iterations += 1\n\n                batch_start += batch_size\n                if batch_start >= len_x: # if end, restart\n                        batch_start = 0\n                \n                w_error = Error(x,y,w)\n\n\n        return w\n\ndef pseudoInverseMatrix ( X ):\n    '''\n    INPUT \n    X: is a matrix (must be a np.array) to use transpose and dot method\n    OUTPUT\n    hat matrix \n    '''\n\n    '''\n    #S =( X^TX ) ^{-1}\n    simetric_inverse = np.linalg.inv( X.T.dot(X) )\n\n    # S X^T = ( X^TX ) ^{-1} X^T\n    return simetric_inverse.dot(X.T)\n    '''\n    return np.linalg.pinv(X)\n\n\n# Pseudoinverse\t\ndef pseudoInverse(X, Y):\n    ''' \n    INPUT\n    X is the feature matrix \n    Y is the target vector (y_1, ..., y_m)\n    \n    OUTPUT: \n    w: weight vector\n    '''\n    X_pseudo_inverse = pseudoInverseMatrix ( X )\n    Y_transposed = Y.reshape(-1, 1)\n    \n    w = X_pseudo_inverse.dot( Y_transposed)\n    \n    return w\n\n\n# Evaluating the autput\n\ndef performanceMeasurement(x,y,w):\n    '''Evaluating the output binary case\n\n    INPUT\n    X is the feature matrix \n    Y is the target vector (y_1, ..., y_m)\n    \n    OUTPUT: \n    w: weight vector\n    OUTPUT: \n    bad_negative, bad_positives, input_size\n    '''\n\n    # defference between the sign of the regression and the target vector\n    sign_column = np.sign(x.dot(w)) - y.reshape(-1,1)\n\n    bad_positives = 0\n    bad_negatives = 0\n    \n    for sign in sign_column[:,0]:\n        if sign > 0 :\n                bad_positives += 1\n        elif sign < 0 :\n                bad_negatives += 1\n\n    input_size = len(y)\n\n    return bad_negatives, bad_positives, input_size\n\ndef evaluationMetrics (x,y,w, label = None):\n    '''PRINT THE PERFORMANCE MEASUREMENT\n    '''\n    bad_negatives, bad_positives, input_size = performanceMeasurement(x,y,w)\n\n    accuracy = ( input_size-(bad_negatives +bad_positives))*100 / input_size\n\n    if label :\n        print(label)\n    print (f'For w^T = {w.reshape(1,-1)}')\n    print ( 'Input size: ', input_size )    \n    print( 'Bad negatives :', bad_negatives)\n    print( 'Bad positives :', bad_positives)\n    print( 'Accuracy rate :', accuracy, '%')\n\n\n\n\n\n    \n## Draw de result\n\n### scatter plot\ndef plotResults (x,y,w, title = None):\n        label_5 = 1\n        label_1 = -1\n\n        labels = (label_5, label_1)\n        colors = {label_5: 'b', label_1: 'r'}\n        values = {label_5: 'Number 5', label_1: 'Number 1'}\n\n        plt.clf()\n\n        # data set plot \n        for number_label in labels:\n                index = np.where(y == number_label)\n                plt.scatter(x[index, 1], x[index, 2], c=colors[number_label], label=values[number_label])\n\n        # regression line\n        # x = 0\n        symmetry_for_cero_intensity = -w[0]/w[2]\n\n        #  x = 1, 0 = w0 + w1 * w2 * x2\n        # then y = (-w0 - w1) /w2\n        symmetry_for_one_intensity= (-w[0] - w[1])/w[2]\n\n        #plotting order\n        plt.plot([0, 1], [symmetry_for_cero_intensity, symmetry_for_one_intensity], 'k-', label=(title+ ' regression'))\n\n                \n\n        if title :\n                plt.title(title)\n        plt.xlabel('Average intensity')\n        plt.ylabel('Simmetry')\n        plt.legend()\n        plt.show()\n        \n\ndef plotResultMultiplesLines(x,y,multiple_w, main_title = None, multiples_title = None):\n        '''\n        INPUT \n        x featue matrx\n        y labels vector \n        multiple_w vector of different weight vector\n        multiple_titles\n        '''\n        label_5 = 1\n        label_1 = -1\n\n        labels = (label_5, label_1)\n        colors = {label_5: 'b', label_1: 'r'}\n        values = {label_5: 'Number 5', label_1: 'Number 1'}\n\n        plt.clf()\n\n        # data set plot \n        for number_label in labels:\n                index = np.where(y == number_label)\n                plt.scatter(x[index, 1], x[index, 2], c=colors[number_label], label=values[number_label])\n\n        for i in range(len(multiple_w)):\n                w = multiple_w[i]\n                title = multiple_title[i]\n                # regression line\n                # x = 0\n                symmetry_for_cero_intensity = -w[0]/w[2]\n\n                #  x = 1, 0 = w0 + w1 * w2 * x2\n                # then y = (-w0 - w1) /w2\n                symmetry_for_one_intensity= (-w[0] - w[1])/w[2]\n\n                #plotting order\n                plt.plot([0, 1],\n                         [symmetry_for_cero_intensity, symmetry_for_one_intensity],\n                         #'k-',\n                         label=(title+ ' regression'))\n\n                \n\n        if main_title :\n                plt.title(main_title)\n        plt.xlabel('Average intensity')\n        plt.ylabel('Simmetry')\n        plt.legend()\n        plt.show()\n        \n\n### _____________ DATA ____________________\n\n# Reading training data set \nx, y = readData('datos/X_train.npy', 'datos/y_train.npy')\n# Reading test data set \nx_test, y_test = readData('datos/X_test.npy', 'datos/y_test.npy')\n\nw_pseudoinverse = pseudoInverse(x, y) \nprint(\"\\n___ Goodness of the Pseudo-inverse fit ___\\n\")\nprint(\"  Ein:  \", Error(x, y, w_pseudoinverse))\nprint(\"  Eout: \", Error(x_test, y_test, w_pseudoinverse))\n\nevaluationMetrics (x,y,w_pseudoinverse, '\\nEvaluating output training data set')\nevaluationMetrics (x_test, y_test, w_pseudoinverse, '\\nEvaluating output test data set')\nplotResults(x,y,w_pseudoinverse, title = 'Pseudo-inverse') \n\nprint(f'\\nThe weight vector is {w_pseudoinverse}')\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\nprint(\"\\n___ Goodness of the Stochastic Gradient Descendt (SGD) fit ___\\n\")\n\nbatch_sizes =[1,32,200,len(y)] #batch sizes compared in the experiment\n\nn_iterations = [50,300] \nfor iteration in n_iterations:\n        multiple_w = [w_pseudoinverse]\n        multiple_title = ['pseudo-inverse']\n\n        for _batch_size in batch_sizes:\n                w = sgd(x,y, eta = 0.01, max_iter = iteration, batch_size = _batch_size)\n\n                _title = f'SGD, batch size {_batch_size}'\n                print( '\\n\\t'+_title)\n                print (\"Ein: \", Error(x,y,w))\n                print (\"Eout: \", Error(x_test, y_test, w))\n                evaluationMetrics (x,y,w, '\\nEvaluating output training data set')\n                evaluationMetrics (x_test, y_test, w, '\\nEvaluating output test data set')\n                #plotResults(x,y,w, title = _title)\n                multiple_w.append(w)\n                multiple_title.append(_title)\n        \n                STOP_EXECUTION_TO_SEE_RESULT()\n\n        plotResultMultiplesLines(x,y,multiple_w,f'Comparative batch sizes, {iteration} iterations',multiple_title)        \n\nSTOP_EXECUTION_TO_SEE_RESULT()\n \n\n\n\n\n\nprint ('Exercise 2\\n')\n\n\n\n\n#### EXPERIMIENTS ###########\n\n## a)\nprint('\\nEXPERIMENT (a) \\n')\ndef simula_unif(N, d, size):\n        ''' generate a trining sample of N  points\nin the square [-size,size]x[-size,size]\n'''\n        return np.random.uniform(-size,size,(N,d))\n\n\n### data\n\nsize_training_example = 1000\ndimension = 2\nsquare_half_size = 1\n\ntraining_sample = simula_unif( size_training_example,\n                               dimension,\n                               square_half_size)\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\nplt.clf()\nplt.scatter(training_sample[:, 0], training_sample[:, 1], c='b')\nplt.title('Muestra de entrenamiento generada por una distribución uniforme')\nplt.title('Training sample generated by a uniform distribution')\nplt.xlabel('$x_1$ value')\nplt.ylabel('$x_2$ value')\n\nplt.show()\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n## b)\n\nprint('\\nEXPERIMENT (b) \\n')\ndef f(x1, x2):\n\treturn np.sign(\n            (x1 -0.2)**2\n            +\n            x2**2 -0.6\n        ) \n\n\ndef noisyVector(y, percent_noisy_data):\n        '''\n        y target vector to introduce noise\n        size_training_example: number of point generated in each experiment,\n        percent_noisy_data\n        '''\n        len_y = len(y)\n        \n        index = list(range(len_y))\n        np.random.shuffle(index)\n        \n        size_noisy_data = int((len_y*percent_noisy_data)/ 100 )\n\n        noisy_y = np.copy(y)\n        for i in index[:size_noisy_data]:\n                noisy_y[i] *= -1\n        return noisy_y\n\n#labels \ny = np.array( [f(x[0],x[1]) for x in training_sample ])\n\n\npercent_noisy_data = 10.0\n\ny = noisyVector(y,  percent_noisy_data)\n\n    \n## draw\nlabels = (1, -1)\ncolors = {1: 'blue', -1: 'red'}\n\nplt.clf()\n\nfor l in labels:\n\t\n\tindex = np.where(y == l)\n\tplt.scatter(training_sample[index, 0],\n                    training_sample[index,1],\n                    c=colors[l],\n                    label=str(l))\n\nplt.title('Labelled training sample before noise')\nplt.xlabel('$x_1$ value')\nplt.ylabel('$x_2$ value')\nplt.legend()\nplt.show()\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\nplt.clf()\n\nfor l in labels:\n\t\n\tindex = np.where(y == l)\n\tplt.scatter(training_sample[index, 0],\n                    training_sample[index,1],\n                    c=colors[l],\n                    label=str(l))\n\nplt.title('Labelled training sample after noise')\nplt.xlabel('$x_1$ value')\nplt.ylabel('$x_2$ value')\nplt.legend()\nplt.show()\n\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\n#### C\nprint('\\nEXPERIMENT (c) \\n')\neta = 0.01\nbatch_size = 5\nmaximum_number_iterations = 1000\n\n\nx = np.array( [\n        np.array([ 1, x_n[0], x_n[1] ])\n        for x_n in training_sample\n])\n\ny = np.array( [f(x_n[0],x_n[1]) for x_n in training_sample ])\ny = noisyVector(y,  percent_noisy_data)\nw = sgd_exact_number_iter(x, y, eta, maximum_number_iterations, batch_size )\n\n\n_title = f'SGD, batch size {batch_size}'\nprint( '\\n\\t'+_title)\nprint (\"Ein: \", Error(x,y,w))\nevaluationMetrics (x,y,w, '\\nEvaluating output training data set')\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\nplt.clf()\n\nfor l in labels:\n\t\n\tindex = np.where(y == l)\n\tplt.scatter(training_sample[index, 0],\n                    training_sample[index,1],\n                    c=colors[l],\n                    label=str(l))\n\nplt.title('Linear regression fit')\nplt.xlabel('$x_1$ value')\nplt.ylabel('$x_2$ value')\n\n# regression line\n# x_0 = -1\ny_0 = (w[1] - w[0]) /w[2]\n#x_1 = 1\ny_1 = -( w[1]+w[0]) /w[2]\n\nplt.plot([-1, 1], [y_0, y_1], 'k-', label=('SGD regression'))\nplt.xlim([-1,1])\nplt.ylim([-1,1])\nplt.show()\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n## d\nprint('\\n EXPERIMENT (d), lineal regression\\n')\n\n        \ndef experiment(featureVector,\n               number_of_repetitions = 1000,\n               size_training_example = 1000,\n               percent_noisy_data = 10.0\n               ):\n        '''\n        INPUT\n        featureVector: function that return  np.array \n        number_of_repetitions: experiment repetitions ,\n        size_training_example: number of point generated in each experiment,\n        percent_noisy_data: \n\n        OUTPUT\n        (error_in, error_out)\n        ''' \n        total_in_error = 0\n        total_out_error = 0\n\n        for _ in range( number_of_repetitions):\n        ## data generation \n                training_sample = simula_unif( size_training_example,\n                                               dimension,\n                                               square_half_size)\n\n                test_sample = simula_unif( size_training_example,\n                                           dimension,\n                                           square_half_size)\n                test_y = np.array( [f(x[0],x[1]) for x in test_sample ])\n                test_y = noisyVector(test_y, percent_noisy_data)\n        \n                y = np.array( [f(x[0],x[1]) for x in training_sample ])\n                y = noisyVector(y,  percent_noisy_data)\n \n                # fit\n                x = np.array( [\n                        featureVector(x_n)\n                        for x_n in training_sample\n                ])\n\n                x_test = np.array( [\n                        featureVector(x_n)\n                        for x_n in test_sample\n                ])\n                \n                w = sgd_exact_number_iter(x, y, eta, maximum_number_iterations, batch_size = 32)\n\n                total_in_error += Error(x,y,w)\n                total_out_error += Error(x_test, test_y, w)\n                \n                \n        error_in = float(total_in_error / number_of_repetitions)\n        error_out = float(total_out_error / number_of_repetitions)\n\n        return error_in, error_out\n\n\n\ndef linearFeatureVector(x_n):\n        return np.array( [\n                1,\n                x_n[0],\n                x_n[1]\n               ] )\n\n_number_of_repetitions = 1000 \nerror_in, error_out = experiment( linearFeatureVector,\n                                  number_of_repetitions = _number_of_repetitions,\n                                  size_training_example = 1000,\n                                  percent_noisy_data = 10.0\n               )\nprint(f'The mean value of E_in in all {_number_of_repetitions} experiments is: {error_in}')\nprint(f'The mean value of E_out in all {_number_of_repetitions} experiments is: {error_out}')\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n# e)\n\nprint('\\nEXPERIMENT (e)\\n' )\neta = 0.01\nbatch_size = 5\nmaximum_number_iterations = 1000\n\ndef quadraticFeatureVector(x_n):\n        '''\n        INPUT \n         xn = (x1,x2) vector of coordinates \n        \n        '''\n        return np.array([ 1,\n                   x_n[0],\n                   x_n[1],\n                   x_n[0]*x_n[1],\n                   x_n[0]* x_n[0],\n                   x_n[1]* x_n[1]  ])\n\nx = np.array( [\n        quadraticFeatureVector(x_n)\n        for x_n in training_sample\n])\ny = np.array( [f(x[0],x[1]) for x in training_sample ])\ny = noisyVector(y,  percent_noisy_data)\n\n\nfor i in [10, 50, 100, 200, 500, 700, 1000]:\n        maximum_number_iterations = i\n        w = sgd_exact_number_iter(x, y, eta, maximum_number_iterations , batch_size = 17)\n\n        print('\\nFor one experiment:')\n        _title = f'SGD, batch size {batch_size}, number iterations {maximum_number_iterations}'\n        print( '\\n',_title)\n        print (\"Ein: \", Error(x,y,w))\n        evaluationMetrics (x,y,w, '\\nEvaluating output training data set')\nprint('')\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\n## plotting\n\ndef equation (x,y,w):\n        '''\n        INPUT \n        x coordinate\n        y coodinate \n        w weights vector\n        \n        OUTPUT\n        Real number, the scalar product of features vector dot weights vector\n        '''\n        return ( w[0,0]\n                 + w[1,0] * x\n                 + w[2,0] * y\n                 + w[3,0] * x * y\n                 + w[4,0] * x**2\n                 + w[5,0] * y**2\n                )\n'''\nPLOTING LINEAR REGRESSION \n\nWe are going to plot the (x,y) \\in [-1,-1]^2 that their value after \nthe linear regression for classification  is near to 0. \n\nThat means that they are in the limit area.  \n'''\nerror = 10**(-2.1)\nspace = np.linspace(-1,1,100)\n\nz = [[ equation(i,j,w) for i in space] for j in space ]\n\nplt.contour(space,space, z, 0, colors=['black'],linewidths=2 )\n\nfor l in labels:\n\t\n\tindex = np.where(y == l)\n\tplt.scatter(training_sample[index, 0],\n                    training_sample[index,1],\n                    c=colors[l],\n                    label=str(l))\n\nplt.title('Quadratic regression fit')\nplt.xlabel('$x_1$ value')\nplt.ylabel('$x_2$ value')\nplt.legend( loc = 'lower left')\nplt.show()\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n## EXPERIMENT\nerror_in, error_out = experiment( quadraticFeatureVector,\n                                  number_of_repetitions = _number_of_repetitions,\n                                  size_training_example = 1000,\n                                  percent_noisy_data = 10.0\n                                 )\nprint(f'The mean value of E_in in all {_number_of_repetitions} experiments is: {error_in}')\nprint(f'The mean value of E_out in all {_number_of_repetitions} experiments is: {error_out}')\nprint('==========================================')\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\n\n\n\"\"\"\nExercise 3 \nAuthor: Blanca Cano Camarero\n\"\"\"\n\ndef f(x,y):\n    '''\n    Function to minimize\n    '''\n    return np.float64(\n        (x+2)**2 + 2*(y-2)**2 + 2* np.sin( 2* np.pi * x)* np.sin( 2* np.pi * y)\n    )\n\ndef dfx(x,y):\n    '''\n    Partial derivate of f with respect to the variable x\n    '''\n    return np.float64(\n        2*( x+2 ) + 4* np.pi* np.cos(  2* np.pi * x )* np.sin(2* np.pi * y)\n    )\n\n\ndef dfy(x,y):\n    '''\n    Partial derivate of f with respect to the variable y\n    '''\n    return np.float64(\n        4*( y-2 ) + 4* np.pi* np.cos(  2* np.pi * y )* np.sin(2* np.pi * x)\n\n    )\n\n\ndef gradf(x,y):\n    ''' \n        gradient of E\n    '''\n    return np.array([dfx(x,y), dfy(x,y)])\n\ndef ddfxx(x,y):\n    return 2 - 8*np.pi**2*np.sin(2*np.pi*x)*np.sin(2*np.pi*y)\n\ndef ddfyy(x,y):\n   \n    return 4 - 8*np.pi**2*np.sin(2*np.pi*x)*np.sin(2*np.pi*y)\n\ndef ddfxy(x,y):\n    return 8*np.pi**2*np.cos(2*np.pi*x)*np.cos(2*np.pi*y)\n\ndef hessianf(x, y):\n    return np.array([\n        ddfxx(x,y),\n        ddfxy(x,y),\n        ddfxy(x,y),\n        ddfyy(x,y),\n    ]).reshape((2, 2))\n\n\ndef newton_trace(initial_point, fun, grad_fun, hessian, eta, max_iter):\n    \"\"\" Newton method\n    INPUT \n    - initial_point: \n    - f: differential function\n    - grad_fun: Gradient\n    - hessian: hessian\n    - eta: learning rate\n    - max_iter: number of iterations\n\n    OUTPUT \n    w trace\n    \"\"\"\n\n    w = initial_point\n    w_list = [initial_point]\n    iterations = 0\n\n    while iterations < max_iter:\n        w = w - eta *np.linalg.inv(hessian(w[0],w[1])).dot(grad_fun(w[0], w[1]))\n        w_list.append(w)\n        iterations += 1\n\n    return np.array(w_list)\n\n\n# Dicrease with the x-axis\n\n## Exercise 1\n \n\n######  conditions  \nsmaller_eta = 0.01\nbigger_eta = 0.1 \nmax_iter = 50\ninitial_point = np.array([-1.0,1.0])\n\n#### run \nsmaller_w = newton_trace( initial_point,f, gradf, hessianf, smaller_eta, max_iter)\nbigger_w = newton_trace( initial_point,f, gradf, hessianf, bigger_eta, max_iter)\n\nimages_smaller_eta = [ f(x[0],x[1]) for x in smaller_w ]\nimages_bigger_eta = [ f(x[0],x[1]) for x in bigger_w]\n\nprint(f'With eta = {smaller_eta}, coordenates (x,y)= {(smaller_w[-1][0],smaller_w[-1][1])}, the number of iterations: {max_iter} and the image is f(x,y) = {images_smaller_eta[-1]}')\n\nprint(f'With eta = {bigger_eta}, coordenates (x,y)={(bigger_w[-1][0],bigger_w[-1][1])}, the number of iterations: {max_iter} and the image is f(x,y) = {images_bigger_eta[-1]}')\n\n\n\n########### PLOTTING\nx_label = 'Number of iterations'\ny_label = 'f(x,y)'\nbigger_eta_label = '$\\eta$ = '+str(bigger_eta)\nsmaller_eta_label = '$\\eta$ = '+str(smaller_eta)\n\n## bigger eta ####\nplt.clf()\nplt.plot(images_bigger_eta, label=bigger_eta_label)\nplt.xlabel(x_label)\nplt.ylabel(y_label)\nplt.title(f\"Newton's adjust of f with $\\eta =$ {bigger_eta}\")\n\n\nplt.legend()\nplt.show()\n\n## smaller eta ###\n\nplt.clf()\nplt.plot(images_smaller_eta, label=smaller_eta_label)\nplt.xlabel(x_label)\nplt.ylabel(y_label)\nplt.title(f\"Newton's adjust of f with $\\eta =$ {smaller_eta}\")\n\n\nplt.legend()\nplt.show()\n\n\n## comparation ###\nplt.clf()\nplt.plot(images_bigger_eta, label=r\"$\\eta$ = 0.1\")\nplt.plot( images_smaller_eta, label=r\"$\\eta$ = 0.01\")\n\nplt.xlabel('Iterations')\nplt.ylabel('f(x,y)')\n\nplt.title(\"Comparation of the newton's method for $f$ changing eta value  \")\n\n\n\nplt.legend()\nplt.show()\n\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n#### exercise 3.b\neta = 0.1\nmax_iter = 50\ninitial_points = map(np.array, [[-.5, -.5],[1, 1], [2.1, -2.1], [-3,3],  [-2, 2]])\nminimum_value = np.Infinity\n\nplt.clf()\nprint('{:^17}  {:^17}  {:^9}'.format('Initial', 'Final', 'Value'))\n\nfor initial in initial_points:\n \n  w = newton_trace( initial,f, gradf, hessianf, eta, max_iter)\n  local_minimum = w[-1]\n  local_value = f(local_minimum[0], local_minimum[1])\n  #plot\n  images = [ f(x[0],x[1]) for x in w ]\n  plt.plot(images, label=f'Initial point {initial}')\n  \n\n  print('{}  {}  {: 1.5f}'.format(initial, local_minimum, local_value))\n\nplt.xlabel('Iterations')\nplt.ylabel('f(x,y)')\n\nplt.title(\"Comparation of the newton's method for $f$ changing initial point \")\n\n\n\nplt.legend()\nplt.show()\n\n\n## without the biggest\n\ninitial_points = map(np.array, [[-.5, -.5],[1, 1], [-3,3],  [-2, 2]])\nminimum_value = np.Infinity\n\nplt.clf()\nprint('{:^17}  {:^17}  {:^9}'.format('Initial', 'Final', 'Value'))\n\nfor initial in initial_points:\n \n  w = newton_trace( initial,f, gradf, hessianf, eta, max_iter)\n  local_minimum = w[-1]\n  local_value = f(local_minimum[0], local_minimum[1])\n  #plot\n  images = [ f(x[0],x[1]) for x in w ]\n  plt.plot(images, label=f'Initial point {initial}')\n  \n\n  print('{}  {}  {: 1.5f}'.format(initial, local_minimum, local_value))\n\nplt.xlabel('Iterations')\nplt.ylabel('f(x,y)')\n\nplt.title(\"Comparation of the newton's method for $f$ changing initial point  \")\n\n\n\nplt.legend()\nplt.show()\n  \n  \nSTOP_EXECUTION_TO_SEE_RESULT()\n\n# let see gradient values \npoints =  [[-0.38067878, -0.52778221],\n           [1.06677195, 0.91078249],\n           [ 3.26077803, -3.11750721] ,\n           [-2.,  2.]]\n             \n\nfor x,y in points :\n    \n    print(f'For {(x,y)}')\n    print(f'\\tThe gradient value is {gradf(x,y)}')\n    print(f'\\tThe inverse hessian is {np.linalg.inv(hessianf(x,y))}\\n')\n\nSTOP_EXECUTION_TO_SEE_RESULT()\n\n\\end{minted}", "meta": {"hexsha": "dc6e03ec2090cbe411b464e7a963620dc8de2bae", "size": 32621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "practica1/memory/code.tex", "max_stars_repo_name": "BlancaCC/aprendizaje-automatico", "max_stars_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "practica1/memory/code.tex", "max_issues_repo_name": "BlancaCC/aprendizaje-automatico", "max_issues_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-04T14:03:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:03:37.000Z", "max_forks_repo_path": "practica1/memory/code.tex", "max_forks_repo_name": "BlancaCC/aprendizaje-automatico", "max_forks_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0737893928, "max_line_length": 183, "alphanum_fraction": 0.5729131541, "num_tokens": 9198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.6919039745084011}}
{"text": "\\section{Linear Algebra}\n\n\\begin{definition}[Basis]\n    Given a set of vectors in $\\mathbf{R}^{n}, V$, which is linearly\n    independent, the set $V$ is a \\textit{basis} if you can span \n    $\\mathbf{R}^{n}$ using $V$.\n\\end{definition}\n\n\\begin{definition}[Backward substituion]\\label{backwardsubstituion}\n    Opposite of~\\nameref{forwardsubstituion}.\n\\end{definition}\n\n\\begin{definition}[Condition number]\\label{conditionnumber}\n    A measure of how the output value for a function changes respective to \n    input variables.\n\\end{definition}\n\n\\begin{definition}[Column space]\n    All linear combinations of the columns of a matrix $A$.\n\\end{definition}\n\n\\begin{definition}[Consistent]\n    $\\iff$ the rightmost column of an augmented matrix is not a pivot column.\n    I.e.\\ in a 3x4 matrix, if the last row is zero and 2nd column has pivot\n    column, then the system is still consistent.\n\\end{definition}\n\n\\begin{definition}[Diagonal Dominance]\n    $\\forall{i}, \\exists{i} A_{i, i}, \\forall i, \\iff A_{i,i} \n    \\geq \\sum\\limits_{j = 0, j\\neq i}^{m}$,\n    then matrix $A$ is DD.\n\\end{definition}\n\n\\begin{definition}[Diagonlizable matrix]\n    Given a matrix $A$, we can express it as $A = PDP^{-1}$.\n    Then, we can compute:\n    \\begin{align}\n        A^{2} = (PDP^{-1})(PDP^{-1}) = PD(P^{-1}P)DP^{-1} = PDDP^{-1} \\\\\n        \\text{Because} P \\cdot P{-1} = I \\\\\n        \\dots A^{k} = PD^{k}P^{-1}\n    \\end{align}\n\n    So, we use diagonal matrices to easily raise matrices to power $k$.\n    \n    To diagonalize a matrix $A^{n\\times{n}}$, it is required that it has $n$ linearly \n    independent eigenvectors.\n\\end{definition}\n\n\\begin{definition}[Divergence]\n    In vector calculus, divergence measures the magnitude to the\n    gradient of~\\nameref{vectorfield}s at a given point.\n\n\\end{definition}\n\n\\begin{definition}[Dotting matrices]\n    \\includegraphics[scale=0.3]{mm.png}\n\\end{definition}\n\n\\begin{definition}[Echelon form]\n    A matrix where:\n    \\begin{enumerate}\n        \\item All nonzero rows are above zero-rows\n        \\item Each pivot column is placed from left to right\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Eigenvector]\\label{eigen}\n    Given a square matrix A, when A is multiplied with an eigenvector $v$,\n    the resulting matrix A${^\\prime}$ is a multiple of $v$.\n    The multipe is denoted by $\\lambda$ and is called an eigenvalue.\n    So, $Av = \\lambda v$\n\n\\end{definition}\n\n\\begin{definition}[Forward substituion]\\label{forwardsubstituion}\n    In an iterative method, if we first solve an element $A_{i,j}$,\n    then when we caluclate some $A_{i+a, j+b}$ in the same iteration, then we\n    use the updated value of $A_{i,j}$. Opposite\n    of~\\nameref{backwardsubstituion}\n\n\\end{definition}\n\n\\begin{definition}[Gaussian Elimination]\n    AKA ``Row reduction''. Add row $x$ to row $y, y \\neq x$, to reduce $y$ to \n    zeroes.\n\n\\end{definition}\n\n\\begin{definition}[Ill-conditioned matrix]\n    A matrix is ill-conditioned if the~\\nameref{conditionnumber} is large.\n    If you make a small change in an ill conditioned matrix, there are usually\n    large differences in results from calculations with this maxtrix.\n\n\\end{definition}\n\n\\begin{definition}[Inner product]\\label{innerprod}\n    The product $u^{T}v$. Given that $u, v \\in R^{i\\times{j}}$, then we need to transpose\n    to perform normal dot products.\n\n    Inner products are commutative: $u \\dot v \\equiv v \\dot u$.\n\\end{definition}\n\n\\begin{definition}[Inverse]\n    For a matrix $A \\in \\mathbf{R}^{2x2}$:\n    $$\n    A^{-1} = \\frac{1}{|A|}\n    \\begin{bmatrix}\n    d & -b \\\\\n    -c & a\n    \\end{bmatrix}\n    = \\frac{1}{ad - bc}\n    \\begin{bmatrix}\n    d & -b \\\\\n    -c & a\n    \\end{bmatrix}\n    $$\n    For a matrix $A \\in \\mathbf{R}^{3x3}$: bcacab\n\n    Properties:\n    \\begin{itemize}\n    \\item $(A^{-1})^{-1} = A$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Kernel]\n    For a vector space given by a~\\nameref{lintrans}, a kernel is the set\n    of vectors $v \\in V$, s.t. $T(u) = 0$.\n\\end{definition}\n\n\\begin{definition}[Length of Vector]\\label{vectorlength}\n    For a vector \n    \\begin{align*}\n        v = [a_{1}, a_{2}, \\dots , a_{n}] \\\\\n        |v| = \\sqrt{a^{2}_{1} + a^{2}_{2} + \\dots + a^{2}_{n}}{}\n    \\end{align*}\n\\end{definition}\n\n\\begin{definition}[Linear dependence]\n    For $V = {v_{1}, \\dots, v_{n}}$, and $\\forall v, v is vector$,\n    if none of the vectors in V can be written as a linear combination\n    from the other vectors in V, the set is linearly independent.\n\\end{definition}\n\n\\begin{definition}[Linear transformation]\\label{lintrans}\n    Take a vector space into another, s.t.\\\n    \\begin{align}\n        T(u + v) = T(u) + T(v) &\\forall u,v \\in v \\\\\n        T(cu) = cT(u) &\\forall u \\in V\n    \\end{align}\n\\end{definition}\n\n\\begin{definition}[Matrix of observations]\n    Collect a sample, subject it to tests, and for each test, you give a value.\n    For $n$ tests and $m$ samples, you will result in $\\Re^{n\\times{m}}$ \n    \\textit{matrix of observations}.\n\\end{definition}\n\n\\begin{definition}[Norm]\n    The ``length'' of a vector, just remember to sum up over all dimensions.\n    Each number is raised to $n$, and the total sum is then raised to\n\n    \\begin{description}\n        \\item[L1]\n        \\item[L2] Can be defined as:\n            \\begin{align}\n                \\phi^{2} = \\phi \\times \\phi =\n                \\dots = \\int{\\phi (x)^{2}  dx} \\\\\n                |x| = \\sqrt{ \\sum\\limits_{k = 1}^{n}{x_{k}|^{2}}}\n            \\end{align}\n    \\end{description}\n\n    $\\frac{1}{p}$.  \n\\end{definition}\n\n\\begin{definition}[Normalization of vectors]\n    $ \\hat{X} \\equiv \\frac{X}{|X|} $, where $|x|$ is the~\\nameref{vectorlength}\n    $X$ is, in this case, evaluated as the additive sum of it's entries.\n\\end{definition}\n\n\\begin{definition}[Null space]\n    Given a matrix $A$, if you solve for that each row = 0,\n    all possible values for each $x$ makes out the Null space.\n\n    Note that here it is apossible to get free variables for \n    some x, and bound to others.\n\n\\end{definition}\n\n\\begin{definition}[Numerical stability]\n    This concept describes how changes in the input should not affect the result.\n    An example could be that sorting a list should not change the outcome from\n    applying a function to the input.\n\\end{definition}\n\n\n\n\\begin{definition}[Orthogonal]\\label{orthogonal}\n    Two lines that intersect each other at 90 degrees.\\\\\n    \\begin{itemize}\n        \\item Orthogonal matrices preserve dot products:\n        given two vectors $u$, and $v$, and an orthogonal matrix Q,\n        the following is true:\n        $u \\times v = Qu \\times Qv$\n        \\item The determinant of an orthogonal matrix is always 1 or -1\n        \\item The transpose of $Q$ is equal to it's inverse, hence:\n            $Q \\times Q^{T} = I$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Orthonormal]\n    In~\\nameref{innerprod} space are orthonormal if they are\n    orthogonal and unit vectors.\n\\end{definition}\n\n\n\\begin{definition}[Perpendicular]\n    Similar to~\\nameref{orthogonal}, but with lines.\n\\end{definition}\n\n\\begin{definition}[Pivoting]\n    Finding the first non-zero element in an algorithm on linear systems.\n    To do so, you can do things like gaussian elimination, etc.\n    \\begin{description}\n        \\item[Complete pivoting] find the largest absolute value of a pivot,\n            considering all elements.\n        \\item[Partial pivoting] finds the largest absolute value in the pivot\n            column.\n        \\item[Scaled pivoting] finds the largest absolute value of a pivot\n            column relative to it's entries in the same row.\n    \\end{description}\n\\end{definition}\n\n\\begin{definition}[Plane]\n    A flat, two-dimensional surface\n\\end{definition}\n\n\\begin{definition}[Positive semidefninite matrix]\n    Properties:\n    \\begin{itemize}\n        \\item Nonnegative~\\nameref{eigen}s\n        \\item $X = V^{T}V$ for some $V \\in \\mathbf{R}^{mxn}$\n        \\item $X = \\sum\\limits_{i=1}^{m}\\lambda_{i}w_{i}w^{t}_{i}$ \n            for some $\\lambda_{i} \\geq 0$ and vectors $w_{i} \\in \\mathbf{R}^{n}$\n            such that $w^{T}_{i}w = 1$ and $w^{T}_{i}w_{j} = 0$\n\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Preconditoner]\n    A matrix $P$ such that $P^{-1}A$ has a smaller~\\nameref{conditionnumber}\n    than $A$.\n\n\\end{definition}\n\n\\begin{definition}[Projection]\n    define a vector $v$ and $u$.\n    \\begin{align*}\n        L &= \\left\\{cv | c \\in \\mathbf{R} \\right\\}  \\\\\n        proj(v) &= l \\in L \\text{\\ such that\\ } u - proj(v) \n        \\text{\\ is~\\nameref{orthogonal} to l}  \\\\\n        \\textit{I.e., } proj(v) &= cv, c \\in \\mathbf{R}\n    \\end{align*}\n\n    Properties:\n    \\begin{itemize}\n        \\item $proj(v) = proj(v)^{2}$\n        \\item Linear independence on $u, v$ also relates for $v - proj(v), u$\n        \\item adding $proj(v)$ to $v$ gives you $u$\n    \\end{itemize}\n\n\\end{definition}\n\n\\begin{definition}[Relaxation methods]\n     relaxation methods are iterative methods for solving systems of equations,\n     including nonlinear systems. Examples are Gauss-Seidel, Jacboi, etc.\n\n\\end{definition}\n\n\\begin{definition}[Singular matrix]\n    Any square matrix without an inverse.\n    A matrix is singular $\\iff$ its determinant is 0.\n\n\\end{definition}\n\n\\begin{definition}[Span of vectors]\\label{vectorspan}\n    All linear combinations of a set of vectors.\n    \\begin{align*}\n        V &= \\left\\{v_{1}, \\dots, v_n\\right\\} \\\\\n        C &= \\left\\{c \\in C | \\mathbf{R}\\right\\} \\\\\n        span &= c_{1}v_{1} + \\dots + c_{n}v_{n}\n    \\end{align*}\n\\end{definition}\n\n\\begin{definition}[Spectrum of a matrix]\n    The multiset of its eigenvalues\n\\end{definition}\n\n\\begin{definition}[Spectral Radius]\n    The largest absolute eigenvalue of a matrix.\n\\end{definition}\n\n\\begin{definition}[Successive Over Relaxation]\n    Gauss-Seidel is the same as SOR (successive over-relaxation) with $\\omega=1$\n\\end{definition}\n\n\\begin{definition}[Symmetric]\n    \\begin{itemize}\n        \\item Length of rows is equal\n        \\item The transpose is equal to the originl\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Tensor]\n    Geometric objects that describe linear relations between vectors or scalars.\n\\end{definition}\n\n\\begin{definition}[Toeplitz matrix]\n    $$\n    \\begin{bmatrix}\n    a & b & c & d \\\\\n    b & a & b & c \\\\\n    c & b & a & b \\\\\n    d & c & b & a\n    \\end{bmatrix}\n    $$\n\n    Noteworthingly, this kind of matrix can be inverted in $O(n \\times \\log{n})$\n\\end{definition}\n\n\\begin{definition}[Trace]\n    Sum of all diagonal entries in a matrix.\n    $A_{11} + A_{22} + A_{nn}$\n\\end{definition}\n\n\\begin{definition}[Transpose]\n    Take column $i$ and make it into a column. Repeat.\n\\end{definition}\n\n\\begin{definition}[Unit vector]\n    A vector who's length is 1.\n\\end{definition}\n\n\n\\begin{definition}[vector length]\n    number of \"steps\" in a vector\n\\end{definition}\n\n", "meta": {"hexsha": "f2848aa410649667a908d88fa06d817aaa4df155", "size": 10829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/lin_alg.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/lin_alg.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/lin_alg.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": 31.117816092, "max_line_length": 89, "alphanum_fraction": 0.6482593037, "num_tokens": 3221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.6919039716616207}}
{"text": "\\documentclass{article}\n\n\n\\include{stddefs}\n\\include{imodefs}\n\n\\begin{document}\n\n\n\n\\chapterno{8}\n\\chapter{The Hessian}\n\nIn Chapter \\ref{chapter:convexfunctions} we exploited the second derivative\n$f''(x)$ of a one variable real function $f:(a, b) \\rightarrow \\RR$ to analyze\nconvexity along with local minima and maxima.\n\nIn this chapter we introduce an analogue of the second derivative for real functions $f:\\RR^n\\rightarrow \\RR$ of\nseveral variables. This will be an $n\\times n$ matrix. The important notion of a matrix\nbeing positive (semi-) definite introduced in Section \\ref{Sectionsymmat} will now\nmake its appearance.\n\n\\section{Introduction}\n\nIn Section \\ref{section:Taylor} the Taylor expansion for a one variable differentiable\nfunction $f:\\RR\\rightarrow \\RR$ centered a $x_0$ with step size\n$h  = x - x_0$ was introduced as\n\\begin{equation}\\label{taylor}\nf(x_0 + h) = f(x_0) + f'(x_0) h + \\frac{1}{2} f''(x_0) h^2 + \\cdots\n\\end{equation}\n\nRecall that the second derivative $f''(x_0)$ contains a\nwealth of information about the function. Especially if $f'(x_0) = 0$,\nthen we might glean from $f''(x_0)$ if $x_0$ is a local maximum or\nminimum or none of these (see Theorem \\ref{derconv} and review Exercise \\ref{exderconv}).\n\nWe also noticed that gradient descent did not work so well only\ndescending along the gradient. We need to take the second\nderivative into account to get a more detailed picture of the\nfunction.\n\n\\section{Several variables}\n\nOur main character is a differentiable function $F:\\RR^n\\rightarrow \\RR$ in\nseveral variables. We already know that\n$$\nF(x_0 + h) = F(x_0) + \\nabla F(x_0) h + \\epsilon(h) \\abs{h},\n$$\nwhere $x_0$ and $h$ are vectors in $\\RR^n$ (as opposed to the good old\nnumbers in \\eqref{taylor}). Take a look back at Definition \\ref{diffdef} for\nthe general definition of differentiability.\n\nWe wish to have an analogue of the Taylor expansion in \\eqref{taylor} for\nsuch a function of several variables. To this end we introduce the function\n$g:\\RR\\rightarrow \\RR$ given by\n\\begin{equation}\\label{onedimg}\ng(t) = F(x_0 + t h).\n\\end{equation}\nNotice that\n$$\ng(t) = (F\\circ A)(t),\n$$\nwhere $A: \\RR\\rightarrow \\RR^n$ is the function given by $A(t) = x_0 + t h$. In particular\nwe get\n\\begin{equation}\\label{chrule1}\ng'(t) = F'(x_0 + t h) h = \\nabla F(x_0 + t h) h\n\\end{equation}\nby using the chain rule (see Theorem \\ref{chainrule}).\n\n\\beginshex\nExplain how the chain rule is applied to get \\eqref{chrule1}.\n\\endshex\n\nThe derivative $g'(t)$ is also composed of several functions and again we may\ncompute $g''(t)$ by using the chain rule:\n\\begin{align}\n  g''(t) &= (C\\circ B \\circ A)'(t)\\\\\n        &= (C\\circ B)'(A(t)) A'(t) \\\\\n        &= C'(B(A(t))) B'(A(t)) A'(t),\n\\end{align}\nwhere $B: \\RR^n\\rightarrow \\RR^n$ is defined by\n$$\nB(v) = \\nabla F(v)^T\n$$\nand $C:\\RR^n \\rightarrow \\RR$ by\n$$\nC(v) = v^T h.\n$$\n\n\\begin{definition}[emph]\n\nThe \\emph{Hessian matrix} of $F$ at the point\n$x\\in \\RR^n$ is defined by\n\n\\begin{equation*}\n  \\nabla^2 F(x) :=\n  \\begin{pmatrix}\n    \\dfrac{ \\partial^2 F}{ \\partial x_1 \\partial x_1}(x) &\n    \\cdots & \\dfrac{ \\partial^2 F}{ \\partial x_1 \\partial\n      x_n}(x)\n    \\\\\n    \\vdots & \\ddots & \\vdots\n    \\\\\n    \\dfrac{ \\partial^2 F}{ \\partial x_n \\partial x_1}(x) &\n    \\cdots & \\dfrac{\\partial^2 F}{ \\partial x_n\\partial\n      x_n}(x)\n  \\end{pmatrix}\n  .\n\n\\end{equation*}\n\\end{definition}\n\n\n\nA very important observation is that $\\nabla^2 F(x)$ above is a\nsymmetric matrix. Again, you should review what this means by clicking\nback to Section \\ref{Sectionsymmat}.\n\n\\beginshex\nWhy is the Hessian matrix symmetric?\n\\endshex\n\n\\begin{example}\\label{sagegradhess}\n  Suppose that $f: \\RR^2\\rightarrow \\RR$ is given by\n  $$\n  f(x, y) = \\sin(x y) + x^2 y^2 + y.\n  $$\n  Then the gradient\n  $$\n  \\nabla f = \\left(\\frac{\\partial f}{\\partial x}, \\frac{\\partial f}{\\partial y} \\right)\n  $$\n  and the Hessian\n\n  $$\n  \\nabla^2 f =\n  \\begin{pmatrix}\n    \\dfrac{\\partial^2 f}{\\partial x^2} & \\dfrac{\\partial^2 f}{\\partial x \\partial y} \\\\\n    \\\\\n    \\dfrac{\\partial^2 f}{\\partial y \\partial x} & \\dfrac{\\partial^2 f}{\\partial y^2}\n  \\end{pmatrix}\n  $$\n  of $f$ are computed in the Sage window below.\n\n  \\begin{sage}\nx, y = var('x, y')\nf = sin(x*y) + x^2*y^2 + y\nprint(\"gradient = \", f.gradient())\nprint(\"Hessian = \", f.hessian())\n  \\end{sage}\n\nSee the \\url{further documentation}{http://doc.sagemath.org/html/en/reference/calculus/sage/calculus/functions.html} for Calculus functions in Sage.\n\\end{example}\n\n\n  \n\\beginshex\nVerify (just this once) by hand the computations done by Sage in Example \\ref{sagegradhess}.\n\nAlso, experiment with a few other functions in the Sage window and compute their\nHessians.\n\\endshex\n\n\n\nBy applying Proposition \\ref{proppd} it is not too hard to see that the Hessian\nmatrix fits nicely into the framework above, since\n\\begin{equation}\\label{exhess}\nB'(v) = \\nabla^2 F(v).\n\\end{equation}\n\nThe full application of the chain rule then gives\n\\begin{equation}\\label{chrule2}\ng''(t) = h^T \\nabla^2 F(x_0 + t h) h.\n\\end{equation}\n\n\n\\beginshex\nGive a detailed explanation as to why \\eqref{exhess} holds.\n\\endshex\n\n\n\\section{Newton's method for finding critical points}\n\nWe may use Newton's method for computing critical points for a function\n$F:\\RR^n\\rightarrow \\RR$ of several variables. Recall that a\ncritical point is a point $x_0\\in \\RR^n$ with $\\nabla F(x_0) = 0$.\nBy \\eqref{onestepmultnewt} and \\eqref{exhess} the computation in Newton's method becomes\n\\begin{equation}\\label{newthess}\nx_1 = x_0 - \\left(\\nabla^2 F(x_0)\\right)^{-1} \\nabla F(x_0).\n\\end{equation}\nIn practice \nthe (inverse) Hessian appearing in \\eqref{newthess} is often a heavy\ncomputational burden. This leads to the socalled\n\\url{quasi-Newton methods}{https://en.wikipedia.org/wiki/Quasi-Newton_method}, where\nthe inverse Hessian in \\eqref{newthess} is replaced by other matrices. \n\n\n\\begin{example}\\label{Exbadlogist}\nWe will return to the logistic regression in Example \\ref{challengerexample} about the\nChallenger disaster. Here we sought to maximize the function\n  \\begin{equation}\\label{logtwo}\n  \\ell(\\alpha, \\beta) = \\sum_{i=1}^m E_i (\\alpha + \\beta x_i) - \\log(1 + e^{\\alpha + \\beta x_i}).\n  \\end{equation}\n\nIn order to employ Newton's method we compute the gradient and the Hessian of \\eqref{logtwo}\n\\begin{align}\\label{hesslogist}\n  \\frac{\\partial \\ell}{\\partial \\alpha} &= \\sum_{i=1}^m E_i - \\sigma(\\alpha + \\beta x_i)\\\\\n  \\frac{\\partial \\ell}{\\partial \\beta} &= \\sum_{i=1}^m E_i x_i - x_ i\\sigma(\\alpha + \\beta x_i)\\\\\n  \\frac{\\partial^2 \\ell}{\\partial \\alpha^2} &= \\sum_{i=1}^m - \\sigma'(\\alpha + \\beta x_i)\\\\\n  \\frac{\\partial^2 \\ell}{\\partial \\beta \\partial \\alpha} &= \\sum_{i=1}^m -\\sigma'(\\alpha + \\beta x_i) x_i\\\\\n  \\frac{\\partial^2 \\ell}{\\partial \\beta^2} &= \\sum_{i=1}^m - \\sigma'(\\alpha + \\beta x_i) x_i^2,\n\\end{align}\nwhere\n$$\n\\sigma(t) = \\frac{1}{1 + e^{-t}}\n$$\nis the sigmoid function.\n\nNotice the potential problem in using Newton's method here: the formula for\nthe second order derivatives in \\eqref{hesslogist} show that if the $\\alpha +\\beta x_i$ are just mildly big, say $\\geq 50$, then\nthe Hessian is extremely close to the zero matrix and therefore Sage considers it non-invertible and\n\\eqref{newthess} fails.\n\nIn the code below we have nudged the initial vector so that it works, but you\ncan easily set other values and see its failure. Optimization is not just mathematics, it also calls\nfor some good (engineering) implementation skills (see for example details on the\n\\url{quasi Newton algorithms}{https://en.wikipedia.org/wiki/Quasi-Newton_method}).\n\nIn the instance below we do, however, get a gradient that is pratically $(0, 0)$.\n  \n\\begin{hideinbutton}{Code for Newton's method}\n\\begin{sage}\nx0 = [11,-0.2] \nnoofits = 10\n  \n\nx = [53.0, 56.0, 57.0, 63.0, 66.0, 67.0, 67.0, 67.0, 68.0, 69.0, 70.0, 70.0, 70.0, 70.0, 72.0, 73.0, 75.0, 75.0, 76.0, 76.0, 78.0, 79.0, 80.0, 81.0]\nE = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n\nEs = sum(E)\nExs = sum(u*v for (u, v) in zip(x, E))\n    \ndef sigmoid(a, b, x):\n  s = 1/(1 + exp(-a - b*x))\n  return s.n()\n\ndef sigmoidm(a, b, x):\n  s = sigmoid(a, b, x)\n  return s*(1-s)\n      \ndef gradient(v):\n  a = v[0]\n  b = v[1]\n  return vector((Es - sum(sigmoid(a, b, t) for t in x), Exs - sum(t*sigmoid(a, b, t) for t in x)))\n    \ndef hessian(v):\n  a = v[0]\n  b = v[1]\n  h11 = - sum(sigmoidm(a, b, t) for t in x)\n  h12 = - sum(sigmoidm(a, b, t)*t for t in x)\n  h22 = - sum(sigmoidm(a, b, t)*t*t for t in x)\n  return matrix([[h11, h12], [h12, h22]])\n\ndef newtonstep(v0):\n  d = gradient(v0)\n  h = hessian(v0)\n  return v0 - h.inverse()*d\n\nv = vector(x0)  \nfor k in range(noofits):\n  print(v)\n  v = newtonstep(v)\n\nprint(\"x0 = \", x0)\nprint(\"Number of Newton iterations =  \", noofits)\nprint(\"Predicted maximal point =  \", v)\n\nalpha = v[0]\nbeta = v[1]\n\nprint(\"Gradient at predicted maximal point = \", gradient(v))\nprint(\"Predicted probability of failure at 31F = \", sigmoid(alpha, beta, 31))\n\\end{sage} \n\\end{hideinbutton}\n\\end{example}\n\n\n\\subsection{Transforming data for better numerical performance}\n\nThe numerical problems with Newton's method in Example \\ref{Exbadlogist} can be prevented by transforming the input data.\nIt makes sense to transform data from large numbers to\nsmaller numbers around $0$. There is a rather standard way of doing this.\n\nSuppose in logistic regression we have a set of data\n\\begin{equation}\\label{datapts}\nx_1, x_2, \\dots, x_n\n\\end{equation}\nassociated with outcomes $E_1, \\dots, E_n$. Then the function\n  $$\n  \\ell(\\alpha, \\beta) = \\sum_{i=1}^m E_i (\\alpha + \\beta x_i) - \\log(1 + e^{\\alpha + \\beta x_i}).\n  $$\n  from Example \\ref{exlogist} becomes much more manageable if we first\n  transform the data according to\n  $$\n  x'_i = \\frac{x_i - \\overline{x}}{\\sigma} \n  $$\n  and instead optimize the function\n  $$\n  \\ell'(\\alpha, \\beta) = \\sum_{i=1}^m E_i (\\alpha + \\beta x'_i) - \\log(1 + e^{\\alpha + \\beta x'_i}).\n  $$\n  Here\n  $$\n  \\overline{x} = \\frac{x_1 + x_2 + \\cdots + x_n}{n}\n  $$\n  is the mean value and\n  $$\n  \\sigma^2 = \\frac{(x_1 - \\overline{x})^2 + (x_2 - \\overline{x})^2 + \\cdots + (x_n - \\overline{x})^2}{n}\n  $$\n  the variance of the data in \\eqref{datapts}.\n\n  \n  Now if $\\alpha'$ and $\\beta'$ is an optimum for $\\ell'$, then\n  \\begin{align}\\label{transformtrick}\n    \\alpha &= \\alpha' - \\frac{\\overline{x}}{\\sigma} \\beta'\\\\\n    \\beta &= \\frac{\\beta'}{\\sigma}\n  \\end{align}\n  is an optimum for $\\ell$, since\n  $$\n  \\ell'(\\alpha, \\beta) = \\ell\\left(\\alpha - \\beta \\frac{\\overline{x}}{\\sigma}, \\frac{\\beta}{\\sigma}\\right).\n  $$\n\n\\beginshex\nWhy is the claim/trick alluded to in \\eqref{transformtrick} true?\n\nBelow is a snippet of Sage code implementing the trick in \\eqref{transformtrick}.\nThe function \\texttt{test} takes as input \\texttt{x0} (an initial vector like \\texttt{[0,0]}) and\n\\texttt{noofits} (the number of iterations of Newton's method). You execute this in the Sage\nwindow by adding for example\n\\begin{code}\n  test([0,0], 10)\n\\end{code}\nand then pressing \\texttt{Compute}.\n\nExperiment and compare with the official output from Example \\ref{challengerexample}. Also, compute\nthe gradient of the output below for the original non-transformed problem.\n\n\\begin{hideinbutton}{Transformed code}\n\\begin{sage}\nx = [53.0, 56.0, 57.0, 63.0, 66.0, 67.0, 67.0, 67.0, 68.0, 69.0, 70.0, 70.0, 70.0, 70.0, 72.0, 73.0, 75.0, 75.0, 76.0, 76.0, 78.0, 79.0, 80.0, 81.0]\nE = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\nmean = sum(x)/len(x)\nstd = sqrt(sum(map(lambda t: (t-mean)^2, x))/len(x))\n\nx = list(map(lambda t: (t-mean)/std, x))\n\n\nEs = sum(E)\nExs = sum(u*v for (u, v) in zip(x, E))\n    \ndef sigmoid(a, b, x):\n  s = 1/(1 + exp(-a - b*x))\n  return s.n()\n\ndef sigmoidm(a, b, x):\n  s = sigmoid(a, b, x)\n  return s*(1-s)\n      \ndef gradient(v):\n  a = v[0]\n  b = v[1]\n  return vector((Es - sum(sigmoid(a, b, t) for t in x), Exs - sum(t*sigmoid(a, b, t) for t in x)))\n    \ndef hessian(v):\n  a = v[0]\n  b = v[1]\n  h11 = - sum(sigmoidm(a, b, t) for t in x)\n  h12 = - sum(sigmoidm(a, b, t)*t for t in x)\n  h22 = - sum(sigmoidm(a, b, t)*t*t for t in x)\n  return matrix([[h11, h12], [h12, h22]])\n\ndef newtonstep(v0):\n  d = gradient(v0)\n  h = hessian(v0)\n  return v0 - h.inverse()*d\n\n\ndef test(x0, noofits):\n  v = vector(x0)  \n  for k in range(noofits):\n    print(v)\n    v = newtonstep(v)\n  print(\"Number of Newton iterations =  \", noofits)\n  print(\"Predicted maximal point in transformed problem =  \", v)\n  tv =   matrix([[1, -mean/std], [0, 1/std]])*v\n  print(\"Predicted maximal point in original problem =  \", tv)\n\n\n  \n\\end{sage}\n\\end{hideinbutton}\n\\endshex\n\n\\section{The Taylor series in several variables}\n\nNow we are in a position to state at least the first terms in the\nTaylor expansion for a differentiable function $F:\\RR^n\\rightarrow \\RR$.\nThe angle of the proof is to reduce to the one-dimensional case through\nthe function $g(t)$ defined in \\eqref{onedimg}. Here\none may prove that\n\n\\begin{equation}\\label{taylorg}\ng(t) = g(0) + g'(0) t + \\frac{1}{2} g''(0) t^2 + \\epsilon(t)t^2,\n\\end{equation}\nwhere $\\epsilon(0) = 0$ with $\\epsilon$ continuous at $0$, much like\nin the definition of differentiability except that we also include\nthe second derivative.\n\nNow \\eqref{taylorg} translates into\n\n\\begin{equation}\\label{critminmax}\n  F(x_0 + t h) = F(x_0) + \\left(\\nabla F(x_0) h \\right) t + \\frac{1}{2} \\left( h^T \\nabla^2 F(x_0) h \\right) t^2 + \\epsilon(t) t^2 \n\\end{equation}\nby using \\eqref{chrule1} and \\eqref{chrule2}.\n\nFrom \\eqref{critminmax} one reads the following nice criterion, which may be viewed as a several variable generalization of Theorem \\ref{derconv}.\n\n\\begin{theorem}[emph]\\label{thmcritminmax}\n  Let $x_0$ be a critical point for $F:\\RR^n\\rightarrow \\RR$. Then\n  \\begin{enumerate}[(i)]\n  \\item\n    $x_0$ is a local minimum if $\\nabla^2 F(x_0)$ is positive definite.\n  \\item\n    $x_0$ is a local maximum if $-\\nabla^2 F(x_0)$ is positive definite (here we call\n    $\\nabla^2 F(x_0)$ negative definite).\n  \\item\\label{thmcritminsaddle}\n    $x_0$ is a \\url{saddle point}{https://en.wikipedia.org/wiki/Saddle_point} if $\\nabla^2 F(x_0)$ is indefinite.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{remark}\n  We need to clarify two things concerning the above theorem. \n\n  \\begin{enumerate}[(i)]\n  \\item\n    An $n\\times n$ indefinite matrix is a symmetric matrix $A$ with the property that there exists\n    $u, v\\in \\RR^n$ with\n    \\begin{align*}\n      u^T A u &>0\\quad\\text{and}\\\\\n      v^T A v &<0\n    \\end{align*}\n  \\item\n    A saddle point $x_0$ for $F$ is defined by the existence of two vectors $u, v\\in \\RR^n$, such that\n    \\begin{align*}\n      &t=0\\quad \\text{is a local minimum for the function}\\quad f(t) = F(x_0 + t u)\\\\\n      &t=0\\quad \\text{is a local maximum for the function}\\quad  g(t) = F(x_0 + t v)\n    \\end{align*}\n    as illustrated in the graphics below.\n\n    \\includegraphics{saddle.png}\n    \\end{enumerate}\n\\end{remark}\n\n\\begin{example}\\label{examplehesscrit}\nConsider, with our new technology in Theorem \\ref{thmcritminmax}, Exercise \\ref{exsaddlept} once again.\nHere we analyzed the point $v_0 = (0, 0)$ for the function\n$$\nf(x, y) = x^3 + x y + y^3\n$$\nand showed (by a trick) that $v_0$ is neither a local maximum nor a local minimum for $f$. The Hessian\nmatrix for $f(x, y)$ at $v_0$ is\n$$\nH = \\begin{pmatrix} 0 & 1 \\\\ 1 & 0 \\end{pmatrix}.\n$$\n\nNow\nTheorem \\ref{thmcritminmax}\\ref{thmcritminsaddle} shows that $v_0$ is a saddle point, since\n$$\n\\begin{pmatrix} x & y \\end{pmatrix} H \\begin{pmatrix} x \\\\ y \\end{pmatrix} = 2 x y\n$$ \nand\n\\begin{align*}\nu^T H u &> 0\\qquad\\text{for } u = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}\\\\\nv H v &< 0\\qquad\\text{for } v =  \\begin{pmatrix} 1 \\\\ -1 \\end{pmatrix}.\n\\end{align*}\n\n\\begin{sage}\nx, y = var('x, y')\na = 1\nplot3d(x^3 + a*x*y+ y^3, (x, -0.4, 0.4), (y, -0.4, 0.4), \nadaptive=True, color=rainbow(60, 'rgbtuple'))\n\\end{sage}\n\\end{example}\n\n\\beginshex\nTry plotting the graph for \\footnote{different values of \\texttt{a}}{\\texttt{a=4} shows the saddle point clearly.} in the Sage window in \nExample \\ref{examplehesscrit}. What do you observe for the point $v_0$ with\nrespect to the function? Does \\texttt{a} have to be a number? Could it be a symbolic\nexpression in the variables \\texttt{x} and \\texttt{y} like \\texttt{a = -10*cos(x)*sin(y)}?\n\\endshex\n\n\\beginshex\nCheck the computation of the Hessian matrix $H$ in Example \\ref{examplehesscrit} by showing\nthat the Hessian matrix for $f$  at the point $(x, y)$ is\n$$\n\\begin{pmatrix}\n6 x & 1\\\\\n1 & 6 y\n\\end{pmatrix}. \n$$\n\\endshex\n\n\\beginshex\nWhat about $u$ and $v$ in Example \\ref{examplehesscrit}? How do they relate to the hint\ngiven in Exercise \\ref{exsaddlept}?\n\\endshex\n\n\n\\beginshex\n  Give an example of a function $F:\\RR^2\\rightarrow \\RR$ having a local minimum at\n  $x_0$, where $\\nabla^2 F(x_0)$ is not positive definite.\n\\endshex\n\n\\beginshex\n\nThe following exercise is a \\texttt{sci2u} exercise from the Calculus book.\n\n\\begin{enumerate}[(i)]\n\\item\n  The point $\\left(0, \\frac{\\sqrt{3}}{3}\\right)$ is a critical point for\n  $$\n  f(x, y) = x^3 + y^3 - y.\n  $$\n  What does Theorem \\ref{thmcritminmax} say about this point?\n\\item\n  The point $\\left(\\frac{1}{3}, \\frac{1}{3}\\right)$ is a critical point for\n  $$\n  f(x, y) = -x^3 -x^2 + x - y^3 + 2 y^2 - y.\n  $$\n  What does Theorem \\ref{thmcritminmax} say about this point?\n\\item\n  The point $(0, 1)$ is a critical point for\n  $$\n  f(x, y) = x^3 - x^2 + y^3 - y^2 - y.\n  $$\n  What does Theorem \\ref{thmcritminmax} say about this point?\n\\end{enumerate}\n\\endshex\n  \n\n\\beginshex\nConsider the function\n$$\nf(x, y) = x^4 y^2 + x^2 y^4 - 3 x^2 y^2.\n$$\nCompute its critical points and decide on their types according to Theorem \\ref{thmcritminmax}. \nTry to convince yourself that\n$$\nf(x, y) \\geq -1\n$$\nfor every $x, y\\in \\RR$.\n\\endshex\n\n\\beginshex\nGive an example of a function $f:\\RR\\rightarrow \\RR$ that has a local maximum, but where\nthere exists $x\\in \\RR$ with $f(x) > M$ for any given (large) number $M$.\n\\endshex\n\n\\section{Convex functions of several variables}\n\nBelow is the generalization of Theorem \\ref{fp} to several\nvariables. You have already seen this in an exercise in the\nprevious chapter, right?\n\n\n\\begin{theorem}[emph]\\label{thmdiffsubdif}\n  Let $f: U\\rightarrow \\RR$ be a differentiable function, where\n  $U\\subseteq \\RR^n$ is an open convex subset. Then $f$ is convex if\n  and only if\n  \\begin{equation}\n    f(x) \\geq f(x_0) + \\nabla f(x_0) (x-x_0)\\label{subgr}\n  \\end{equation}\n  for every $x, x_0\\in U$.\n\\end{theorem}\n\\begin{hideinbutton}{Proof}\n  Suppose that \\eqref{subgr} holds and let $x_t = (1-t)x_0 + t x$ with\n  $0 \\leq t \\leq 1$, where $x_0, x\\in U$.  To prove that $f$ is convex\n  we must verify the inequality\n  \\begin{equation}\n    f(x_t) \\leq (1-t) f(x_0) + t f(x).\\label{subdineq}\n  \\end{equation}\n  Let $\\xi = \\nabla f(x_t)$. Then\n  \\begin{align*}\n    f(x) &\\geq f(x_t) + \\xi (1-t) (x-x_0)\\\\\n    f(x_0) &\\geq f(x_t) - \\xi t (x-x_0)\n  \\end{align*}\n  by \\eqref{subgr}.  If you multiply the first inequality by $t$, the\n  second by $1-t$ and then add the two, you get \\eqref{subdineq}.\n\n  Suppose on the other hand that $f$ is a convex function. Let $x_0,\n  x\\in U$. Since $U$ is an open subset, it follows that $(1-t)x_0 + t\n  x\\in U$ for $t\\in I=(-\\delta, 1 + \\delta)$, where $\\delta>0$ is\n  sufficiently small. Now define the function $g:I\\rightarrow \\RR$ by\n  \\begin{equation*}\n    g(t) = f((1-t) x_0 + t x) = f(x_0 + t (x-x_0)).\n  \\end{equation*}\n  Being the composition of two differentiable functions, $g$ is\n  differentiable.  Suppose that $0\\leq \\alpha \\leq 1$ and $t_1, t_2\\in\n  I$. Then\n  \\begin{align*}\n   g((1- \\alpha) t_1 + \\alpha t_2) &= f(x_0 + ((1-\\alpha)\n    t_1 + \\alpha t_2)(x-x_0))\n    \\\\\n    &=f((1-\\alpha)(x_0 + t_1(x-x_0)) + \\alpha (x_0+t_2(x-x_0)))\n    \\\\\n    &\\leq(1-\\alpha) f(x_0 + t_1 (x-x_0)) + \\alpha f(x_0 + t_2(x-x_0))\n    \\\\\n    &=(1-\\alpha) g(t_1) + \\alpha g(t_2)\n  \\end{align*}\n  showing that $g$ is a convex function.  By Theorem \\ref{fp},\n  \\begin{equation*}\n    g(1) \\geq g(0) + g'(0),\n  \\end{equation*}\n  which translates into\n  \\begin{equation*}\n    f(x) \\geq f(x_0) + \\nabla f(x_0) (x-x_0)\n  \\end{equation*}\n  by using the chain rule in computing $g'(0)$.\n\\end{hideinbutton}\n\n\n\\beginshex\n  Prove that a bounded convex differentiable function $f:\\RR^n\\rightarrow \\RR$ is\n  constant.\n\\endshex\n\n\nThe following is the generalization of  Corollary \\ref{corfdp}.\n\n\\newcommand{\\Hess}[1]{\\nabla^2 #1}\n\n\\begin{theorem}[emph]\\label{thmhessconv}\n  Let $f: U\\rightarrow \\RR$ be a differentiable function with continuous\n  second order partial derivatives, where $U\\subseteq \\RR^n$ is a\n  convex open subset. Then $f$ is convex if and only if the Hessian\n  $\\Hess{f}(x)$ is positive semidefinite for every $x\\in U$. If\n  $\\Hess{f}(x)$ is positive definite for every $x\\in U$, then $f$ is\n  strictly convex.\n\\end{theorem}\n\\begin{hideinbutton}{Proof}\n  We have done all the work for a convenient reduction to the one\n  variable case. Suppose that $f$ is convex. Then the same reasoning\n  as in the proof of Theorem \\ref{thmdiffsubdif} shows that\n  \\begin{equation*}\n    g(t) = f(x + t v)\n  \\end{equation*}\n  is a convex function for every $x\\in U$ and every $v\\in \\RR^n$ from\n  an open interval $(-\\delta, \\delta)$ to $\\RR$ for suitable\n  $\\delta>0$. Therefore $g''(0) = v^t \\Hess{f}(x) v \\geq 0$ by\n  Theorem \\ref{fdp}. This proves that the matrix $\\Hess{f}(x)$ is\n  positive semidefinite for every $x\\in U$.  Suppose on the other hand\n  that $\\Hess{f}(x)$ is positive semidefinite for every $x\\in U$.\n  Then Theorem \\ref{fdp} shows that $g(t) = f(x + t(y-x))$ is a convex\n  function from $(-\\delta, 1+\\delta)$ to $\\RR$ for $\\delta>0$ small\n  and $x, y\\in U$, since\n  \\begin{equation*}\n    g''(\\alpha) = (y-x)^t \\Hess{f}(x + \\alpha(y-x)) (y-x) \\geq 0\n  \\end{equation*}\n  for $0\\leq \\alpha \\leq 1$. Therefore $f$ is a convex function, since\n  \\begin{align*}\n    f((1-t) x + t y) = &g((1-t)\\cdot 0 + t\\cdot 1) \\\\\n    &\\leq(1-t) g(0) + t g(1) = (1-t) f(x) + t f(y).\n  \\end{align*}\n  The same argument (using the last part of Theorem \\ref{fdp} on\n  strict convexity), shows that $g$ is strictly convex if\n  $\\Hess{f}(x)$ is positive definite. It follows that $f$ is strictly\n  convex if $\\Hess{f}(x)$ is positive definite for every $x\\in U$.\n\\end{hideinbutton}\n\n\\beginshex\n  Prove that\n  \\begin{equation*}\n    f(x, y) = x^2 + y^2\n  \\end{equation*}\n  is a strictly convex function from $\\RR^2$ to $\\RR$. Also, prove that\n  $$\n  \\{(x, y)\\in \\RR^2 \\mid x^2 + y^2 \\leq 1\\}\n  $$\n  is a convex subset of $\\RR^2$.\n  \\endshex\n\n\\beginshex\n  Is $f(x, y) = \\cos(x) + \\sin(y)$ strictly convex on some non-empty\n  open convex subset of the plane?\n\\endshex\n\n\n\\beginshex\n Show that $f:\\RR^2 \\rightarrow \\RR$ given by\n  \\begin{equation*}\n    f(x, y) = \\log(e^x + e^y)\n  \\end{equation*}\n  is a convex function. Is $f$ strictly convex?\n\\endshex\n\n\\beginshex\nLet $f:\\RR^2\\rightarrow \\RR$ be given by\n  \\begin{equation*}\n    f(x, y) = a x^2 + b y^2 + c x y,\n  \\end{equation*}\n  where $a, b, c\\in \\RR$.\n\n  \\begin{enumerate}[(i)]\n  \\item Show that $f$ is a strictly convex function if and only if $a > 0$\n    and $4 a b - c^2 > 0$.\n  \\item Suppose now that $a > 0$ and $4 a b - c^2>0$.  Show that $g(x,\n    y) = f(x, y) + x + y$ has a unique global minimum and give a\n    formula for this minimum in terms of $a, b$ and $c$.\n\\end{enumerate}\n\\endshex\n\n\n\n\\section{How to decide the definiteness of a matrix}\n\nIn this section we will outline a straightforward method for\ndeciding if a matrix is positive definite, positive semidefinite,\nnegative definite or indefinite.\n\nBefore proceeding it is a must that you do the following exercise.\n\n\\beginshex\nShow that a diagonal matrix\n$$\n\\begin{pmatrix}\n  \\lambda_1 & 0 & \\dots & 0\\\\\n  0 &\\lambda_2 & \\dots &0\\\\\n  \\vdots & \\vdots & \\ddots & \\vdots\\\\\n  0 & 0 &\\dots & \\lambda_n\n\\end{pmatrix}\n$$\nis positive definite if and only if $\\lambda_1 > 0, \\dots, \\lambda_n > 0$\nand positive semidefinite\nif and only if $\\lambda_1 \\geq  0, \\dots, \\lambda_n \\geq 0$.\n\nAlso, show that if $A$ is a symmetric matrix, then $A$ is\npositive definite if and only if\n$$\nB^t A B\n$$\nis positive definite, where $B$ is an invertible matrix.\n\\endshex\n\nThe crucial ingredient is the following result.\n\n\\begin{theorem}[emph]\\label{thmsymred}\n  Let $A$ be a real symmetric $n\\times n$ matrix. Then there exists an\n  invertible matrix $B$, such that $B^T A B$ is a diagonal matrix.\n\\end{theorem}\n\nThe proof contains an algorithm for building $B$ by different steps.\nWe will supply examples afterwards illustrating these. Incidentally,\nhow does this help you in deciding for example that a given matrix\nis positive definite? If you cannot answer this question, please\ndo the exercise above.\n\n\\begin{hideinbutton}{Proof}\n   Suppose that $A=(a_{ij})$. If $A$ has a non-zero entry in the upper\n  left hand corner i.e., $a_{11}\\neq 0$, then\n  \\begin{equation*}\n    B_1^T A B_1 =\n    \\begin{pmatrix}\n      a_{11} & 0 & \\cdots & 0\\\\\n      0 & c_{11} & \\cdots & c_{1, n-1}\\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      0 & c_{n-1, 1} & \\cdots & c_{n-1, n-1},\n    \\end{pmatrix}\n  \\end{equation*}\n  where $C = (c_{ij})$ is a real symmetric matrix and $B_1$ is the\n  invertible $n\\times n$ matrix\n  \\begin{equation*}\n    % \\def\\frac#1#2{{#1\\strut \\over #2}\\,}\n    \\begin{pmatrix}\n      1 & -\\frac{ a_{12}}{a_{11}} & \\cdots & -\\frac{\n        a_{1n}}{a_{11}}\\\\\n      0 & 1 & \\cdots & 0\\\\\n      \\vdots & \\vdots & \\ddots & \\vdots\\\\\n      0 & 0 & \\cdots & 1\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n  By induction on $n$ we may find an invertible matrix $(n-1)\\times\n  (n-1)$ matrix $B_2$ such that\n  \\begin{equation*}\n    B_2^t C B_2 =\n    \\begin{pmatrix}\n      a_1 & 0 &\\cdots & 0\\\\\n      0 & a_2 & \\cdots & 0\\\\\n      \\vdots & \\vdots & \\ddots &\\vdots\\\\\n      0 & 0 & \\cdots & a_{n-1}\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n  \n  Putting\n  \\begin{equation*}\nB = B_1\n    \\begin{pmatrix}\n      1 & 0\\\\\n      0 & B_2\n    \\end{pmatrix},\n    \\end{equation*}\n    it follows that\n\\begin{equation*}\n    B^t A B =                           \n    \\begin{pmatrix}\n      a_{11} & 0 &\\cdots & 0\\\\\n      0 & a_1 & \\cdots & 0\\\\\n      \\vdots & \\vdots & \\ddots &\\vdots\\\\\n      0 & 0 & \\cdots & a_{n-1}\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n  \nWe now treat the case of a zero entry in the upper left hand corner\n  i.e., $a_{11}=\\nobreak 0$.  Suppose first that $a_{jj} \\neq 0$ for\n  some $j > 1$. Let $P$ denote the identity matrix with the first and\n  $j$-th rows interchanged.  The operation $A\\mapsto A P$ amounts to\n  interchanging the first and $j$-th columns in $A$.  Similarly\n  $A\\mapsto P^t A$ is interchanging that first and $j$-th rows in $A$.\n  The matrix $P$ is invertible and $P^t A P$ is a symmetric matrix\n  with $(P^t A P)_{11} = a_{jj}\\neq 0$ and we have reduced to the case\n  of a non-zero entry in the upper left hand corner.\n\n  If $a_{ii} = 0$ for every $i = 1, \\dots, n$ we may assume that $a_{1\n    j}\\neq 0$ for some $j>1$. Let $B$ denote the identity matrix where\n  the entry in the first column and $j$-th row is $1$. The operation\n  $A\\mapsto A B$ amounts to adding the $j$-th column to the first\n  column in $A$. Similarly $A\\mapsto B^t A$ is adding the $j$-th row\n  to the first row in $A$. All in all we get $(B^t A B)_{11} = 2 a_{1\n    j} \\neq 0$, where we have used that $a_{ii} = 0$ for $i=1, \\dots,\n  n$. Again we have reduced to the case of a non-zero entry in the\n  upper left hand corner.\n\\end{hideinbutton}\n\n\n\n\\begin{example}\\label{eksempel1}\n  Consider the $3\\times 3$ real symmetric matrix.\n  \\begin{equation*}\n    A = (a_{ij}) = \n    \\begin{pmatrix}\n      1 & 5 & 2\\\\\n      5 & 3 & 0\\\\\n      2 & 0 & 5\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n  Here $a_{11} = 1 \\neq 0$. Therefore the fundamental step in the\n  proof of Theorem \\ref{thmsymred} applies and\n  \\begin{equation*}\n    \\begin{pmatrix}\n      1 & 0 & 0 \\\\\n      -5 & 1 & 0\\\\\n      -2 & 0 & 1\n    \\end{pmatrix}\n    A\n    \\begin{pmatrix}\n      1 & -5 & -2\\\\\n      0 & 1 & 0\\\\\n      0 & 0 & 1\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      1 & 0 & 0\\\\\n      0 & -22 & -10\\\\\n      0 & -10 & 1\n    \\end{pmatrix}\n  \\end{equation*}\n  and again\n  \\begin{equation*}\n    \\begin{pmatrix}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0\\\\\n      0 & -\\frac{5}{11} & 1\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      1 & 0 & 0\\\\\n      0 & -22 & -10\\\\\n      0 & -10 & 1\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      1 & 0 & 0\\\\\n      0 & 1 & -\\frac{5}{11}\\\\\n      0 & 0 & 1\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      1 & 0 & 0\\\\\n      0 & -22 & 0\\\\\n      0 & 0 & \\frac{61}{11}\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n\n\nSumming up we get\n  \\begin{equation*}\n    B = \n    \\begin{pmatrix}\n      1 & -5 & -2\\\\\n      0 & 1 & 0\\\\\n      0 & 0 & 1\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      1 & 0 & 0\\\\\n      0 & 1 & -\\frac{5}{11}\\\\\n      0 & 0 & 1\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      1 & -5 & \\frac{3}{11}\\\\\n      0 & 1 & -\\frac{5}{11}\\\\\n      0 & 0 & 1\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n  You are invited to check that\n  \\begin{equation*}\n    B^t A B =\n    \\begin{pmatrix}\n      1 & 0 & 0\\\\\n      0 & -22 & 0\\\\\n      0 & 0 & \\frac{61}{11}\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n\\end{example}\n\n\\begin{example}\\label{eksempel2}\n  Let\n  \\begin{equation*}\n    A =\n    \\begin{pmatrix}\n      0 & 0 & 1 & 1\\\\\n      0 & 0 & 2 & 3\\\\\n      1 & 2 & 1 & 4\\\\\n      1 & 3 & 4 & 0\n    \\end{pmatrix}.\n  \\end{equation*}\n  Here $a_{11} = a_{22} = 0$, but the diagonal element $a_{33}\\neq\n  0$. So we are in the second step of the proof of\n  Theorem \\ref{thmsymred}.  Using the matrix\n  \\begin{equation*}\n    P =\n    \\begin{pmatrix}\n      0 & 0 & 1 & 0\\\\\n      0 & 1 & 0 & 0\\\\\n      1 & 0 & 0 & 0\\\\\n      0 & 0 & 0 & 1\n    \\end{pmatrix}\n  \\end{equation*}\n  we get\n\\begin{equation*}\n  P^t A P =\n    \\begin{pmatrix}\n      1 & 2 & 1 & 4\\\\\n      2 & 0 & 0 & 3\\\\\n      1 & 0 & 0 & 1\\\\\n      4 & 3 & 1 & 0\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n\n\n  As argued in the proof, this corresponds to interchanging the first\n  and third columns and then interchanging the first and third\n  rows. In total you move the non-zero $a_{33}$ to the upper left\n  corner in the matrix.\n\\end{example}\n\n\n\\begin{example}\\label{eksempel3}\n  Consider the symmetric matrix\n  \\begin{equation*}\n    A =\n    \\begin{pmatrix}\n      0 & 1 & 1 & 1\\\\\n      1 & 0 & 1 & 1\\\\\n      1 & 1 & 0 & 1\\\\\n      1 & 1 & 1 & 0\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n  We have zero entries in the diagonal. As in the third step in the\n  proof of Theorem \\ref{thmsymred} we must find an invertible matrix\n  $B_1$, such that the upper left corner in $B_1^t A B_1$ is\n  non-zero. In the proof it is used that every diagonal element is\n  zero: if we locate a non-zero element in the $j$-th column in the\n  first row, we can add the $j$-th column to the first column and then\n  the $j$-th row to the first row obtaining a non-zero element in the\n  upper left corner. For $A$ above we choose $j=2$ and the matrix\n  $B_1$ becomes\n  \\begin{equation*}\n    B_1 =\n    \\begin{pmatrix}\n      1 & 0 & 0 & 0\\\\\n      1 & 1 & 0 & 0\\\\\n      0 & 0 & 1 & 0\\\\\n      0 & 0 & 0 & 1\n    \\end{pmatrix}\n  \\end{equation*}\n  so that\n\\begin{equation*}\n  B_1^t A B_1 =\n    \\begin{pmatrix}\n      2 & 1 & 2 & 2\\\\\n      1 & 0 & 1 & 1\\\\\n      2 & 1 & 0 & 1\\\\\n      2 & 1 & 1 & 0\n    \\end{pmatrix}\n    .\n  \\end{equation*}\n\n\\end{example}\n\n\n\\beginshex\nLet $A$ be any matrix. Show that\n$$\nA^T A\n$$\nis positive semidefinite.\n\\endshex\n\n\\beginshex\n Find inequalities defining the set\n  \\begin{equation*}\n    \\left\\{(a, b)\\in \\RR^2 \\middle\\vert\n      \\begin{pmatrix}\n        2 & 1 & a\\\\ 1 & 1 & 1 \\\\ a & 1 & b\n      \\end{pmatrix}\n      \\,\\,\\text{is positive definite}\n    \\right\\}.\n  \\end{equation*}\n  Same question with positive semidefinite. Sketch and compare the two\n  subsets of the plane $\\{(a, b) \\mid a, b\\in \\RR\\}$.\n\\endshex\n\n\n\\beginshex\nLet $f:\\RR^3\\rightarrow \\RR$ denote the function given by\n$$\nf(x, y, z) = x^2 + y^2 + z^2 +  a x y +  x z +  y z,\n$$\nwhere $a\\in \\RR$. Let $H$ denote the Hessian of\n$f$ in a point $(x, y, z)\\in \\RR^3$.\n\n\\begin{enumerate}[(i)]\n\\item\n  Compute $H$.\n\\item\n  Show that $f(v) = v^T A v$ for $v=(x, y, z)\\in \\RR^3$ and $A = \\frac{1}{2} H$.\n\\item\n  Compute a non-zero vector $v\\in \\RR^3$, such that $H v = 0$ in\n  the case, where $a=2$. Is $H$ invertible in this case?\n\\item\n  Show that $f$ is strictly convex if $-1 < a < 2$.\n\\item\n  Is $f$ strictly convex if $a=2$?\n\n  \\begin{hideinbutton}{Hint}\n    Consider the line segment between $0$ and a suitable vector\n    $u\\neq 0$, where $f(u) = 0$.\n\n    \n  \\end{hideinbutton}\n\\end{enumerate}\n\\endshex\n\n\\beginshex\nWhy is the subset given by the inequalities\n  \\begin{align*}\n    x &\\geq 0\\\\\n    y &\\geq 0\\\\\n    x y - z^2 &\\geq 0\n  \\end{align*}\n  a convex subset of $\\RR^3$?\n\\endshex\n\n\n\\end{document}", "meta": {"hexsha": "250e325c7bf26bb179ab842623102c33490c1da4", "size": 32781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/IMO21/hessian.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/hessian.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/hessian.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": 30.0467461045, "max_line_length": 148, "alphanum_fraction": 0.6314938531, "num_tokens": 12322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118222, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.6919039681952215}}
{"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 1, 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\\end{document}\n\n", "meta": {"hexsha": "c357b442da2d2a0b557f7b93928097525fcb9322", "size": 5007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-10-01.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-01.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-01.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": 45.9357798165, "max_line_length": 360, "alphanum_fraction": 0.6676652686, "num_tokens": 1995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.6919039569289424}}
{"text": "\\chapter{Supplemental Algorithms}\\label{chap:appendix-algo}\n\nFind here concrete implementation details on the EFTs described\nin Theorem~\\ref{thm:eft}. They do not use branches, nor access to the\nmantissa that can be time-consuming.\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{EFT of the sum of two floating point numbers.}}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\left[S, \\sigma\\right] = \\mathtt{TwoSum}\\)}{$a, b$}\n      \\State \\(S = a \\oplus b\\)\n      \\State \\(z = S \\ominus a\\)\n      \\State \\(\\sigma = (a \\ominus (S \\ominus z)) \\oplus (b \\ominus z)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent In order to avoid branching to check which among\n\\(\\left|a\\right|, \\left|b\\right|\\) is largest, \\texttt{TwoSum} uses 6 flops\nrather than 3.\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Splitting of a floating point number into two parts.}}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\left[h, \\ell\\right] = \\mathtt{Split}\\)}{$a$}\n      \\State \\(z = a \\otimes (2^r + 1)\\)\n      \\State \\(h = z \\ominus (z \\ominus a)\\)\n      \\State \\(\\ell = a \\ominus h\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent For IEEE-754 double precision floating point number, \\(r = 27\\)\nso \\(2^r + 1\\) will be known before \\texttt{Split} is called. In all,\n\\texttt{Split} uses 4 flops.\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{EFT of the product of two floating point numbers.}}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\left[P, \\pi\\right] = \\mathtt{TwoProd}\\)}{$a, b$}\n      \\State \\(P = a \\otimes b\\)\n      \\State \\(\\left[a_h, a_{\\ell}\\right] = \\mathtt{Split}(a)\\)\n      \\State \\(\\left[b_h, b_{\\ell}\\right] = \\mathtt{Split}(b)\\)\n      \\State \\(\\pi = a_{\\ell} \\otimes b_{\\ell} \\ominus (((P \\ominus\n          a_h \\otimes b_h)\n          \\ominus a_{\\ell} \\otimes b_h) \\ominus a_h \\otimes b_{\\ell})\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent This implementation of \\texttt{TwoProd} requires 17 flops.\nFor processors that provide a fused-multipy-add operator (\\texttt{FMA}),\n\\texttt{TwoProd} can be rewritten to use only 2 flops:\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{EFT of the sum of two floating point numbers with a FMA.}}\n  \\label{alg:two-prod-fma}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\left[P, \\pi\\right] = \\mathtt{TwoProdFMA}\\)}{$a, b$}\n      \\State \\(P = a \\otimes b\\)\n      \\State \\(\\pi = \\mathtt{FMA}(a, b, -P)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent The following algorithms from \\cite{Ogita2005} can be used as a\ncompensated method for computing a sum of numbers. The first is a vector\ntransformation that is used as a helper:\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Error-free vector transformation for summation.}}\n  \\label{alg:vec-sum}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\mathtt{VecSum}\\)}{$p$}\n      \\State \\(n = \\texttt{length}(p)\\)\n      \\For{\\(j = 2, \\ldots, n\\)}\n        \\State \\(\\left[p_j, p_{j - 1}\\right] = \\mathtt{TwoSum}\\left(\n            p_j, p_{j - 1}\\right)\\)\n      \\EndFor\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent The second (\\texttt{SumK}) computes a sum with results that are as\naccurate as if computed in \\(K\\) times the working precision. It requires\n\\((6K - 5)(n - 1)\\) floating point operations.\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Summation as in K-fold precision\n      by \\((K - 1)\\)-fold error-free vector transformation.}}\n  \\label{alg:sum-k}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\mathtt{result} = \\mathtt{SumK}\\)}{$p, K$}\n      \\For{\\(j = 1, \\ldots, K - 1\\)}\n        \\State \\(p = \\mathtt{VecSum}(p)\\)\n      \\EndFor\n      \\State \\(\\mathtt{result} = p_1 \\oplus p_2 \\oplus \\cdots \\oplus p_n\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent Since the final error \\(\\cdb{K - 1}\\) will not track the errors\nduring computation, we have a non-EFT version of\nAlgorithm~\\ref{alg:local-error-eft}:\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Compute the local error (non-EFT).}}\n  \\label{alg:local-error}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\widehat{\\ell} =\n        \\mathtt{LocalError}\\)}{$e, \\rho, \\delta b$}\n      \\State \\(L = \\texttt{length}(e)\\)\n      \\\\\n      \\State \\(\\widehat{\\ell} = e_1 \\oplus e_2\\)\n      \\For{\\(j = 3, \\ldots, L\\)}\n        \\State \\(\\widehat{\\ell} = \\widehat{\\ell} \\oplus e_j\\)\n      \\EndFor\n      \\\\\n      \\State \\(\\widehat{\\ell} = \\widehat{\\ell} \\oplus \\left(\n          \\rho \\otimes \\delta b\\right)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\nIn order to discuss varied implementations of Newton's method in\nChapter~\\ref{chap:compensated-newton}, we define a generic algorithm\nthat takes an ``update function'' (\\(\\mathtt{update\\_fn}\\)), i.e.\na callable that will produce the next Newton update \\(p(s) / p'(s)\\)\ncomputed in a problem-specific way.\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Generic Newton's method for scalar functions.}}\n  \\label{alg:generic-newton}\n\n  \\begin{algorithmic}\n    \\Function{\\(x_{\\ast} = \\mathtt{NewtonGeneric}\\)}\n             {$\\mathtt{update\\_fn}, x_0, \\mathtt{tol}, \\mathtt{max\\_iter}$}\n      \\State \\(x = x_0\\)\n      \\\\\n      \\For{\\(j = 1, \\ldots, \\mathtt{max\\_iter}\\)}\n        \\State \\(\\mathtt{update} = \\mathtt{update\\_fn}(x)\\)\n        \\State \\(x = x \\ominus \\mathtt{update}\\)\n        \\If{\\(\\left|\\mathtt{update}\\right| < \\mathtt{tol}\\)}\n          \\State \\textbf{break}\n        \\EndIf\n      \\EndFor\n      \\\\\n      \\State \\(x_{\\ast} = x\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\nIn \\cite[Algorithm~3]{Jiang2010}, the \\texttt{CompDeCasteljau} (\nAlgorithm~\\ref{alg:comp-de-casteljau}) is modified for the computation\nof the derivative \\(p'(s)\\). Since \\(p'(s)\\) has coefficients\n\\(n \\Delta b_j\\) where \\(c_j = \\Delta b_j = b_{j + 1} - b_j\\),\nwe can begin the computation with nonzero\n\\(\\widehat{\\partial c}_j\\) (as opposed to\n\\(\\cdb{1}_j^{(n)} = 0\\) in \\texttt{CompDeCasteljau}).\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Compensated de Casteljau\n      algorithm for polynomial first derivative evaluation.}}\n  \\label{alg:comp-de-casteljau-derivative}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\mathtt{result} = \\mathtt{CompDeCasteljauDer}\\)}{$b, s$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\State \\(\\left[\\widehat{r}, \\rho\\right] = \\mathtt{TwoSum}(1, -s)\\)\n      \\\\\n      \\For{\\(j = 0, \\ldots, n - 1\\)}\n        \\State \\(\\left[\\widehat{c}_j^{(n - 1)},\n          \\widehat{\\partial c}_j^{(n - 1)}\\right] =\n          \\mathtt{TwoSum}(b_{j + 1}, -b_j)\\)\n      \\EndFor\n      \\\\\n      \\For{\\(k = n - 2, \\ldots, 0\\)}\n        \\For{\\(j = 0, \\ldots, k\\)}\n          \\State \\(\\left[P_1, \\pi_1\\right] = \\mathtt{TwoProd}\\left(\n              \\widehat{r}, \\widehat{c}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\left[P_2, \\pi_2\\right] = \\mathtt{TwoProd}\\left(\n              s, \\widehat{c}_{j + 1}^{(k + 1)}\\right)\\)\n          \\State \\(\\left[\\widehat{c}_j^{(k)}, \\sigma_3\\right] =\n              \\mathtt{TwoSum}(P_1, P_2)\\)\n          \\State \\(\\widehat{\\ell}_{1, j}^{(k)} = \\pi_1 \\oplus \\pi_2 \\oplus\n              \\sigma_3 \\oplus \\left(\\rho \\otimes\n              \\widehat{c}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\widehat{\\partial c}_j^{(k)} =\n              \\widehat{\\ell}_{1, j}^{(k)} \\oplus\n              \\left(s \\otimes \\widehat{\\partial c}_{j + 1}^{(k + 1)}\n              \\right) \\oplus\n              \\left(\\widehat{r} \\otimes\n              \\widehat{\\partial c}_j^{(k + 1)}\\right)\\)\n        \\EndFor\n      \\EndFor\n      \\\\\n      \\State \\(\\mathtt{result} = n \\otimes \\left[\\widehat{c}_0^{(0)} \\oplus\n          \\widehat{\\partial c}_0^{(0)}\\right]\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\nFor an applied usage of \\texttt{CompDeCasteljau}\n(Algorithm~\\ref{alg:comp-de-casteljau}) in\nChapter~\\ref{chap:compensated-newton}, both the non-compensated\nvalue \\(\\widehat{b}\\) and the compensation term \\(\\widehat{\\partial b}\\) are\nneeded. So we define a partial EFT. We say \\emph{partial} because\nthe compensation term is rounded.\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{EFT for de Casteljau algorithm for polynomial evaluation.}}\n  \\label{alg:eft-de-casteljau}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\left[\\widehat{b}, \\widehat{\\partial b}\\right] =\n      \\mathtt{DeCasteljauEFT}\\)}{$b, s$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\State \\(\\left[\\widehat{r}, \\rho\\right] = \\mathtt{TwoSum}(1, -s)\\)\n      \\\\\n      \\For{\\(j = 0, \\ldots, n\\)}\n        \\State \\(\\widehat{b}_j^{(n)} = b_j\\)\n        \\State \\(\\cdb{1}_j^{(n)} = 0\\)\n      \\EndFor\n      \\\\\n      \\For{\\(k = n - 1, \\ldots, 0\\)}\n        \\For{\\(j = 0, \\ldots, k\\)}\n          \\State \\(\\left[P_1, \\pi_1\\right] = \\mathtt{TwoProd}\\left(\n              \\widehat{r}, \\widehat{b}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\left[P_2, \\pi_2\\right] = \\mathtt{TwoProd}\\left(\n              s, \\widehat{b}_{j + 1}^{(k + 1)}\\right)\\)\n          \\State \\(\\left[\\widehat{b}_j^{(k)}, \\sigma_3\\right] =\n              \\mathtt{TwoSum}(P_1, P_2)\\)\n          \\State \\(\\widehat{\\ell}_{1, j}^{(k)} = \\pi_1 \\oplus \\pi_2 \\oplus\n              \\sigma_3 \\oplus \\left(\\rho \\otimes\n              \\widehat{b}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\cdb{1}_j^{(k)} =\n              \\widehat{\\ell}_{1, j}^{(k)} \\oplus\n              \\left(s \\otimes \\cdb{1}_{j + 1}^{(k + 1)}\n              \\right) \\oplus\n              \\left(\\widehat{r} \\otimes\n              \\cdb{1}_j^{(k + 1)}\\right)\\)\n        \\EndFor\n      \\EndFor\n      \\\\\n      \\State \\(\\widehat{b} = \\widehat{b}_0^{(0)}\\)\n      \\State \\(\\widehat{\\partial b} = \\cdb{1}_0^{(0)}\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n", "meta": {"hexsha": "8fc6f24eade107f871be85dc6a50250de86c46bb", "size": 9564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algorithms.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/algorithms.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/algorithms.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": 37.2140077821, "max_line_length": 78, "alphanum_fraction": 0.5941028858, "num_tokens": 3384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6918638900911445}}
{"text": "%\\chapter{An Introduction of Machine Learning}\n\\section{What is a learning algorithm?} \n\n        A \\textbf{machine learning algorithm} is an algorithm that is able to learn from data. But what does \"learning\" mean? Mitchell (1997) provides a definition \"A computer program is said to learn from experience $E$ with 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\n        The 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    \\subsection{Types of learning algorithm}\n\n         Machine learning algorithms can be broadly categorized as \\textbf{unsupervised} or \\textbf{supervised} or \\textbf{Reinforcement learning algorithms\n         }\tby what kind of experience they are allowed to have during the learning process. \n    \\begin{itemize}\t\t\n        \\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        \\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        \\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    \\end{itemize}\t\n    Here we offer a simple example to illustrate the difference between the supervised and unsupervised learning algorithm.\n\n     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     \\begin{itemize}\n         \\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         \\item The points are painted red,green or blue. We want to learn from the data about the reason why the point is red,green or blue. If given a new point, we can label its color according the points before. That's an example of classification, which is one kind of supervised learning algorithm.\n     \\end{itemize}\n     \\begin{figure}[htbp]\n         \\centering\n         \\includegraphics[width = 1.0 \\textwidth]{Cluster.png}\n         \\caption{An example of clustering}\n     \\end{figure}\n    \\subsection{Maximum Likelihood Estimation}\n    As the process of machine learning is to estimate a set of parameters �� based on observations of examples X, \\textbf{maximum likelihood} is often considered the preferred estimator to use for machine learning.\t\n\n    \\begin{itemize}\n        \\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        \\item Let $p_{model}(\\bm x;\\bm \\theta)$ be a parametric family of probability distributions over the same space indexed by $\\bm \\theta$.\n        \\item The maximum likelihood estimator for $\\bm \\theta$ is then defined as \n            \\begin{equation*}\n                \\begin{split}\n                    \\bm \\theta_{ML} &= \\arg \\max_{\\bm \\theta}p_{model}(\\mathbb X;\\bm \\theta) \\\\\n                    &=\\arg \\max_{\\bm \\theta}\\prod_{\\bm x \\in \\mathbb X} p_{model}(\\bm x;\\bm \\theta)\\\\\n                    &=\\arg \\max_{\\bm \\theta}\\sum_{\\bm x \\in \\mathbb X} \\log p_{model}(\\bm x;\\bm \\theta)\\\\\n                \\end{split}\n            \\end{equation*}\n    \\end{itemize}\n\n    \\subsection{Input data}\n    Previously observed data in the experience can be split to three categories:\n    \\begin{itemize}\n        \\item Training data: used to train the model\n        \\item Validation data: used to adjust the model\n        \\item Test data: used to evaluate the generalization of the model\n    \\end{itemize}\n    Training data and validation data are usually splitted from a large observed data set. The ratio between training data and validation data is commenly 4:1 or 9:1.\n    \\subsection{Capacity and Performance}\t\n\n    The capacity of the learning algorithms can be under fitting, 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\n    \\begin{figure}[htbp]\n        \\centering\n        \\includegraphics[width = 1.0 \\textwidth]{fitCap.png}\n        \\caption{We fit three models to this example training set. The training data was\n        generated synthetically, by randomly sampling $x$ values and choosing $y$ deterministically\n        by evaluating a quadratic function. (Left)A linear function fit to the data suffers from underfitting-it cannot capture the curvature that is present in the data. (Center) A quadratic function fit to the data generalizes well to unseen points. It does not suffer from a significant amount of overfitting or underfitting. (Right)A polynomial of degree 9 fit to the data suffers from overfitting. Here we used the Moore-Penrose pseudoinverse to solve the underdetermined normal equations. The solution passes through all of the training points exactly, but we have not been lucky enough for it to extract the correct structure. It now has a deep valley in between two training points that does not appear in the true underlying function. It also increases sharply on the left side of the data, while the true function decreases in this area.}\n    \\end{figure}\n    The factors determining the performance of the machine learning algorithms are:\n    \\begin{itemize}\n        \\item Test error (final error of the generated model) The error is calculated by a cost function based on the test data set\n        \\item The gap between training and validation error\n    \\end{itemize}\n    The 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    \\begin{figure}[htbp]\n        \\centering\n        \\includegraphics[width = 1.0 \\textwidth]{ErrorwithCap.png}\n        \\caption{Typical relationship between capacity and error. Training and test error behave differently. At the left end of the graph, training error and generalization error are both high. This is the underfitting regime. As we increase capacity, training error decreases, but the gap between training and generalization error increases. Eventually, the size of this gap outweighs the decrease in training error, and we enter the overfitting regime, where capacity is too large, above the optimal capacity.}\n    \\end{figure}\n    \\section{Regularization and generalization}\n    \\subsection{Regularization}\n    Regularization is a process of introducing additional information in order to prevent \\textbf{overfitting}. Empirical learning of models (learning from a finite data set) is always an underdetermined problem, because in general we are trying to infer a function of any $x$ given only some examples $ x_{1},x_{2},...x_{n}$.\n\n    A \\textbf{regularization term} (or \\textbf{regularizer}) $R(f)$ is added to a loss function:\n\n    \\begin{equation}\n        \\min _{f}\\sum _{i=1}^{n}L(f({\\hat {x}}_{i}),{\\hat {y}}_{i})+\\lambda R(f)\n    \\end{equation}\n\n    where $L$ is an underlying loss function that describes the cost of predicting $ f(x)$ when the label is $y$ (for classification problem); and $\\lambda$  is a parameter which controls the importance of the regularization term. $ R(f)$ is typically chosen to impose a penalty on the complexity of $f$. Concrete notions of complexity used include restrictions for smoothness and bounds on the vector space norm.\n\n    \\subsection{Generalization error}\n    In supervised learning applications in machine learning and statistical learning theory, \\textbf{generalization error} (also known as the \\textbf{out-of-sample error}) is a measure of how accurately an algorithm is able to predict outcome values for previously unseen data. Because learning algorithms are evaluated on finite samples, the evaluation of a learning algorithm may be sensitive to sampling error. As a result, measurements of prediction error on the current data may not provide much information about predictive ability on new data. Generalization error can be minimized by \\textbf{avoiding overfitting} in the learning algorithm.\n\n    The generalization error, $I[f_{n}]$ of a particular function $f_{n}$ over all possible values of $x$ and $y$ is:\n\n    \\begin{equation}\n        I[f_{n}]=\\int _{X\\times Y}V(f_{n}(x),y)\\rho (x,y)dxdy\n    \\end{equation}\n    Since $I[f_{n}]$ cannot be computed for an unknown probability distribution, the generalization error cannot be computed explicitly. Instead, the aim of many problems in statistical learning theory is to bound or characterize the generalization error in probability:\n    \\begin{equation}\n        P_{G}=P(I[f_{n}]-I_{S}[f_{n}]\\leq \\epsilon )\\geq 1-\\delta _{n}\n    \\end{equation}\n    while \n    \\begin{equation}\n        I_{S}[f_{n}]={\\frac {1}{n}}\\sum _{i=1}^{n}V(f_{n}(x_{i}),y_{i})\n    \\end{equation}\n    is the empirical error computed from the sample points. \n\n    \\section{Types of problems}\n    \\subsection{Classification problem}\n    In machine learning and statistics, classification is the problem of identifying to which of a set of categories (sub-populations) a new observation belongs, on the basis of a training set of data containing observations (or instances) whose category membership is known. An example would be assigning a given email into \"spam\" or \"non-spam\" classes or assigning a diagnosis to a given patient as described by observed characteristics of the patient (gender, blood pressure, presence or absence of certain symptoms, etc.). \n     \\begin{figure}[htbp]\n         \\centering\n         \\includegraphics[width = 1.0 \\textwidth]{Classification.png}\n         \\caption{An example of classification}\n     \\end{figure}\n    \\subsection{Regression problem}\n    In statistical modeling, regression is a statistical process for estimating the relationships among variables. It includes many techniques for modeling and analyzing several variables, when the focus is on the relationship between a dependent variable and one or more independent variables (or 'predictors'). More specifically, regression analysis helps one understand how the typical value of the dependent variable (or 'criterion variable') changes when any one of the independent variables is varied, while the other independent variables are held fixed.  In all cases, the estimation target is a function of the independent variables called the \\textbf{regression function}.\n    \\begin{figure}[htbp]\n        \\centering\n        \\includegraphics[width = 1.0 \\textwidth]{Regression.png}\n        \\caption{An example of multivariate regression}\n    \\end{figure}\n\n\n\\input{6DL/PageRank.tex}\n", "meta": {"hexsha": "27ccc5bace531a6c11729a53d4bfbf1173fb1998", "size": 11411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/IntroML.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/IntroML.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/IntroML.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": 92.7723577236, "max_line_length": 848, "alphanum_fraction": 0.7399877311, "num_tokens": 2631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6918638885938474}}
{"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 4}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\section*{1a. Problem 1}\n\n\\begin{align*}\nE[(X-a)(X-a)']&= E[(X-a)(X'-a')]\\\\\n&= E[XX'-Xa'-aX'+aa']\\\\\n&= E[XX']-E[Xa']-E[aX']+E[aa']\\\\\n&= E[XX']-E[X]a'-aE[X']+E[aa']\\\\\n&= (Var[X]+E[X]E[X]')-E[X]a'-aE[X']+aa'\\\\\n&= Var[X]+ E[X]E[X]'-E[X]a'-aE[X]'+aa'\\ \\text{ since } E[X']=E[X]'\\\\\n&= Var[X] + (E[X]-a)(E[X]'-a')\\\\\n&= Var[X] + (E[X]-a)(E[X]-a)'\n\\end{align*}\n\n$$Var[X] = \\sum = (\\sigma_{ij})$$\n\n$$||X-a||_{1\\times 1}^2 = (X-a)'_{1 \\times r}(X-a)_{1 \\times r}$$\n\nAnd hence(replace $X$ with $X'$ and $a$ with $a'$):\n\n\\begin{align*}\nE[||X-a||^2] &= E[(X-a)'(X-a)]\\\\\n&= E[X'X]-E[X']a-a'E[X]+a'a\\\\\n&= \\sum_i E[X_i^2]-E[X']a-a'E[X]+a'a\\\\\n&= \\sum_i (Var[X_i]+E[X_i]^2)-E[X']a-a'E[X]+a'a\\\\\n&= \\sum_i Var[X_i]+ E[X']E[X]-E[X']a-a'E[X]+a'a\\ \\text{since } \\sum_i E[X_i]^2 = E[X'X]\\\\\n&=\\sum_i Var[X_i]+ E[X]'E[X]-E[X]'a-a'E[X]+a'a\\ \\text{since } \\sum_i E[X_i]^2 = E[X'X]\\\\\n&= \\sum_i Var[X_i] + (E[X]-a)'(E[X]-a)\\\\\n&= \\sum_i \\sigma_i + ||E[X]-a||^2\n\\end{align*}\n\n\\section*{1a. Problem 2}\nFact: $X-a-E[X-a]=X-E[X]$\n\\begin{align*}\nCov[X-a,Y-b] &= E[(X-a-E[X-a])(Y-b-E[Y-b])'])\\\\\n&= E[(X-E[X])(Y-E[Y])']\\\\\n&= Cov[X,Y]\n\\end{align*}\n\n\\section*{1a. Problem 3}\n$Y_i = X_i-X_{i-1}$\n\n$Cov[Y_i,Y_j]=0$ for $i \\neq j$\n\nConsider the vector $(Y_1, Y_2, Y_3, \\dots, Y_n)' = (X_1,X_2-X_1,X_3-X_2, \\dots, X_n-X_{n-1})'$ \n\nWe make use of $Var(AX) = AVar(X)A'$.\n\nTo find $A$, consider the vectors $(Y_1, Y_2, Y_3, \\dots, Y_n)' = (X_1,X_2-X_1,X_3-X_2, \\dots, X_n-X_{n-1})'$ \n\n\\begin{align*}\n\\begin{pmatrix}\nY_1\\\\\nY_2\\\\\nY_3\\\\\n\\vdots\\\\\nY_n\n\\end{pmatrix} &= \\begin{pmatrix}\nX_1\\\\\nX_2-X_1\\\\\nX_3-X_2\\\\\n\\vdots\\\\\nX_n-X_{n-1}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}1 & 0 & 0 & \\dots & 0 & 0\\\\\n-1 & 1 & 0 & \\dots & 0 & 0\\\\\n0 & -1 & 1 & \\dots & 0 & 0\\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots\\\\\n0 & 0 & 0 & \\dots & -1 & 1\n\\end{pmatrix} \\times \\begin{pmatrix}\nX_1\\\\\nX_2\\\\\nX_3\\\\\n\\vdots\\\\\nX_n\n\\end{pmatrix}\n\\end{align*}\n\nHence $A=\\begin{pmatrix}1 & 0 & 0 & \\dots & 0 & 0\\\\\n-1 & 1 & 0 & \\dots & 0 & 0\\\\\n0 & -1 & 1 & \\dots & 0 & 0\\\\\n\\vdots \\\\\n0 & 0 & 0 & \\dots & -1 & 1\n\\end{pmatrix}$\n\n\nNow using $Var(Y) = AVar(X)A'$ we get \n\n$$Var(X) = A^{-1}Var(Y)A'^{-1}$$\n\n$Var(Y) = I_{n\\times n}$\nand hence $Var(X) = A^{-1}A'^{-1} = BB^T$ where $B=A^{-1}$\n\n\\newpage \n\\section*{Problem 4}\n\n$X_{i+1} = \\rho X_i$\n\nConsider:\n\n\\begin{align*}\n\\begin{pmatrix}\nX_1\\\\\nX_2\\\\\nX_3\\\\\n\\vdots\\\\\nX_n\n\\end{pmatrix} &= \\begin{pmatrix}\nX_1\\\\\n\\rho X_1\\\\\n\\rho X_2\\\\\n\\vdots\\\\\n\\rho X_{n-1}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n1\\\\\n\\rho\\\\\n\\rho^2\\\\\n\\vdots\\\\\n\\rho^{n-1}\n\\end{pmatrix}X_1\n\\end{align*}\n\nLet $A=\\begin{pmatrix}1 & \\rho & \\rho^2 & \\dots & \\rho^{n-1}\\end{pmatrix}'$\nand hence variance $Var[X] = AVar(X_1)A' = \\sigma^2AA'$\n\n$Var[X] = \\begin{pmatrix}\n1 & \\rho & \\rho^2 & \\dots & \\rho^{n-1}\\\\\n\\rho & \\rho^2 & \\rho^3 & \\dots & \\rho^n\\\\\n\\rho^2 & \\rho^3 & \\rho^4 & \\dots & \\rho^{n+1}\\\\\n\\vdots & \\vdots & \\vdots & & \\vdots\\\\\n\\rho^n & \\rho^{n+1} & \\rho^{n+2} & \\dots & \\rho^{2n-2}\\\\\n\\end{pmatrix}$\n\n\\section*{1b. Problem 1}\n\n\\begin{align*}\nX_1^2+2X_1X_2-4X_2X_3+X_3^2 &= (X_1+X_2)X_1 + (X_1-2X_3)X_2 + (-2X_2+X_3)X_3\\\\\n&= \\begin{pmatrix}\nX_1 & X_2 & X_2\n\\end{pmatrix}\\begin{pmatrix}\n1 & 1 & 0\\\\\n1 & 0 & -2\\\\\n0 & -2 & 1\\\\\n\\end{pmatrix}\\begin{pmatrix}\nX_1\\\\\nX_2\\\\\nX_3\n\\end{pmatrix}\n\\end{align*}\n\n$$X=\\begin{pmatrix}X_1 & X_2 & X_3\\end{pmatrix}'$$\n\n$$A = \\begin{pmatrix}\n1 & 1 & 0\\\\\n1 & 0 & -2\\\\\n0 & -2 & 1\\\\\n\\end{pmatrix}$$\n\n\n$$A\\sum = AVar[X] = \\sigma^2\\begin{pmatrix}\n1 & 1 & \\frac{1}{4}\\\\\n1 & -\\frac{1}{2} & -2\\\\\n0 & -\\frac{7}{4} & \\frac{1}{2}\\\\\n\\end{pmatrix}$$\n\n\nThus, $$E[X'AX] = tr(A\\sum) + \\mu'A\\mu = \\sigma^2 + \\mu'A\\mu$$\n\n\\section*{1b. Problem 2}\n\n\\begin{align*}\n\\sum_i(X_i-\\bar{X})^2 &= \\sum_i (X_i^2-2X_i\\bar{X}+\\bar{X}^2)\\\\ \n&= \\sum_i X_i^2 -2\\sum_i X_i \\bar{X} + \\bar{X}^2\\\\  \n&= \\sum_i X_i^2 -n\\bar{X}^2\n\\end{align*}\n\nNow $\\sum_iX_i^2 = X'X$ and $\\bar{X} = \\frac{1}{n}\\sum_i X_i = \\frac{1}{n} \\mathbf{1'}X = \\frac{1}{n}X'\\mathbf{1} $\n\nHence,\n\n\\begin{align*}\n\\sum_i(X_i-\\bar{X})^2 &= \\sum_i X_i^2-n\\bar{X}^2\\\\\n&= X'X - n\\frac{1}{n^2}(X'\\mathbf{11'}X)\\\\\n&= X'X-\\frac{1}{n}(X'\\mathbf{11'}X)\\\\\n&= X'(\\mathbf{I}-\\frac{1}{n}\\mathbf{11'})X\n\\end{align*}\n\nLet $A=(\\mathbf{I}-\\frac{1}{n}\\mathbf{11'})$\n\nNow using $E[X'AX]= tr(A\\sum) + \\mu'A\\mu$ we have:\n\n\\begin{align*}A\\sum &= \\begin{pmatrix}1-1/n & -1/n & -1/n & \\dots & -1/n\\\\\n-1/n & 1-1/n & -1/n & \\dots & -1/n\\\\\n\\vdots\\\\\n-1/n & -1/n & -1/n & \\dots & 1-1/n\n\\end{pmatrix}\\times diag(\\sigma_1^2, \\sigma_2^2, \\dots, \\sigma_n^2)\\\\ \n&= (1-\\frac{1}{n})\\sum_i \\sigma_i^2\n\\end{align*}\n\nAlso, $$\\mu'A = \\begin{pmatrix} \\mu & \\mu & \\dots & \\mu \\end{pmatrix} \\times \\begin{pmatrix}1-1/n & -1/n & -1/n & \\dots & -1/n\\\\\n-1/n & 1-1/n & -1/n & \\dots & -1/n\\\\\n\\vdots\\\\\n-1/n & -1/n & -1/n & \\dots & 1-1/n\n\\end{pmatrix} = 0$$ \n\nand hence $\\mu'A\\mu=0$\n\n\\begin{align*}\nE[\\sum_i(X_i-\\bar{X})^2] &= (1-\\frac{1}{n})\\sum_i \\sigma_i^2  \\\\\nE[\\frac{1}{n(n-1)}\\sum_i(X_i-\\bar{X})^2]  &= \\frac{1}{n^2} \\sum_i \\sigma_i^2\n\\end{align*}\n\nFinally,\n\n\\begin{align*}\nvar(\\bar{X}) &= Var(\\frac{1}{n}\\sum_i X_i)\\\\\n&= \\frac{1}{n^2} \\sum_i Var(X_i)\\\\ \\text{ since $X_i$ are mutually independent}\\\\\n&= \\frac{1}{n^2}\\sum_i \\sigma_i^2\\\\\n&= E[\\frac{1}{n(n-1)}\\sum_i(X_i-\\bar{X})^2]\n\\end{align*}\n\n\\section*{1b. Problem 3}\n\nGiven: $\\bar{X_w} = \\sum_i w_i X_i $ and $\\sum w_i =1 $\n\n\\begin{align*}\nVar(\\bar{X_w}) &= Var(\\sum w_i X_i)\\\\\n&= \\sum w_i^2Var(X_i)\\ \\text{ since $X_i$ are mutually independent}\\\\\n&= \\sum w_i^2 \\sigma_i^2\n\\end{align*}\n\nNow consider,\n\n$$\n\\text{minimize} \\sum w_i^2\\sigma_i^2 \\text{ subject to } \\sum_i w_i =1\n$$\n\nWe consider the following lagrange formulation:\n\n$$min_w f(\\mathbf{w}) = \\sum_i w_i^2\\sigma_i^2 +\\lambda(\\sum_iw_i-1)$$\n\nNow to find optimal $\\lambda$, we solve $\\frac{\\partial f(\\mathbf{w})}{\\partial w_i} = 0$\n\n\\begin{align*}\n\\frac{\\partial f(\\mathbf)}{\\partial w_i} &= 2w_i\\sigma_i^2+\\lambda =0\\\\\n\\implies w_i &= -\\frac{\\lambda}{2\\sigma_i^2}\n\\end{align*}\n\nThus, $w_i = -\\frac{\\lambda}{2\\sigma_i^2}$ or $w_i \\propto \\frac{1}{\\sigma_i^2}$\n\nUsing $\\sum_i w_i=1$  we get:\n\\begin{eqnarray*}\n\\sum_i w_i = 1\\\\\n\\sum_i \\frac{\\lambda}{-2\\sigma_i^2} =1\\\\\n\\implies \\lambda = \\frac{-2}{\\sum_i 1/\\sigma_i^2 }\\\\\n\\implies w_i = \\frac{1}{\\sigma_i^2 \\sum_i(1/\\sigma_i^2)}\\\\\n\\implies f_{min}(w) = \\sum_i (\\frac{1}{\\sigma_i^2 \\sum_i(1/\\sigma_i^2)}) \\sigma_i^2\\\\\nv_{min} = \\frac{1}{\\sum_i(1/\\sigma_i^2)}\n\\end{eqnarray*}\n\n\n\\subsection*{Part b}\n\n\\begin{align*}\n\\sum_i w_i (X_i-\\bar{X_w})^2 &= \\sum_i w_i(X_i^2-2X_i\\bar{X_w}+\\bar{X_w}^2)\\\\\n&= \\sum_i w_iX_i^2-2\\bar{X_w}\\sum_iw_iX_i+\\bar{X_w^2}\\\\\n&= \\sum_i w_iX_i^2 -2\\bar{X_w}^2+\\bar{X_w}^2\\\\\n&= \\sum_i w_iX_i^2 -\\bar{X_w}^2\n\\end{align*}\n\nNow, we rewrite $\\sum_i w_iX_i^2 = X'\\Lambda X$ where $\\Lambda = diag(w_1, w_2, \\dots, w_n)$\n\nand $\\bar{X_w} = \\sum_i w_iX_i = X'w = w'X$\n\n\\begin{align*}\n\\bar{X_w}^2 &= (\\sum_i w_iX_i)^2\\\\\n&=X'ww'X\n\\end{align*}\n\nand hence $\\sum_i w_i (X_i-\\bar{X_w})^2=X'(\\Lambda-ww')X$ \n\nDefine $A=\\Lambda-ww' = \\begin{pmatrix}\nw_1-w_1^2 & w_1w_2 & w_1w_3 & \\dots & w_1w_n\\\\\nw_2w_1 & w_2-w_2^2 & w_2w_3 & \\dots & w_2w_n\\\\\n\\vdots & \\vdots & \\vdots & \\vdots \\\\\nw_nw_1 & w_nw_2 & w_nw_3 & \\dots w_n-w_n^2\\\\\n\\end{pmatrix}$\n\nso that \n$$E[\\sum_i w_i (X_i-\\bar{X_w})^2] = E[X'AX]= tr(A\\sum) + \\mu'A\\mu$$\n\n\n$$tr(A\\sum) = \\sum_i(w_i-w_i^2)\\sigma_i^2 = \\sum_i w_i\\sigma_i^2-w_i(w_i\\sigma_i^2) = \\sum_i (a-aw_i) = na-a$$\n\nand the $(1,1)$ element of the matrix $\\mu'A$ is given by: \n\n\\begin{align*}\n\\mu'A_1 &= \\mu (w_1-w_1^2 - w_1\\sum_{i=2}w_i)\\\\ &= w_1-w_1^2-w_1(1-w_1)\\\\ \n&= 0\\end{align*}\n\nand hence it's essentially a zero matrix(other elements are zero similarly)\n\nAlso, $$v_{min} = \\frac{1}{\\sum_i 1/\\sigma_i^2} = \\frac{1}{\\sum_i \\frac{w_i}{a}} = a$$\n\nThus,\n\n\\begin{align*}\nE[S_w^2] &= \\frac{1}{n-1} tr(A\\sum) + \\mu'A\\mu\\\\\n&= \\frac{1}{n-1} (na-a) + 0\\\\\n&=a\\\\\n&= v_{min}\n\\end{align*}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "886c1d70605bda017b48f18066d9a437b58c5ece", "size": 7944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW04/hw04.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/HW04/hw04.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/HW04/hw04.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": 24.1458966565, "max_line_length": 128, "alphanum_fraction": 0.556143001, "num_tokens": 4025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6916975126971286}}
{"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 3: Matrices}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Matrices}\n\nA motivation for bringing in matrices is better expressing linear relations\nbetween variables.\n\n\\begin{example}\n  The coordinates of a point in two different Cartesian coordinate systems have\n  linear relations. Suppose in the first coordinate system, the point\n  $P = (x_1, x_2, x_3)$, and in the second one, the point $P = (u_1, u_2, u_3)$.\n  The relations between them can be described by linear equations, such as\n  \\[\n    \\left\\{ \\begin{array}{ll}\n    u_1 = 2x_1 + x_2 + 5x_3 \\\\\n    u_2 = x_1 + 3x_2 + 2x_3 \\\\\n    u_3 = x_1 + 2x_2 + x_3\n    \\end{array} \\right.\n  \\]\n  The reason why their relation is linear is that each unit vector in the\n  second coordinate system can be decomposed into three vectors along the\n  directions of the unit vectors in the first coordinate system, i.e. each unit\n  vector in the second coordinate system has a unique coordinate in the first\n  system. Since $x_1$, $x_2$, $x_3$ are just scalars in three directions of the\n  first coordinate system, the coordinates of the unit vectors of the second\n  system can also be expressed with $x_1$, $x_2$, $x_3$, a linear combination\n  of these three scalars. Then the coordinate of the point in the second\n  coordinate system is also a linear combination of the unit vectors in the\n  system, so the coordinate of the point in the second coordinate system is a\n  linear combination of the coordinate of the point in the first one.\n\n  Then we can actually use matrix product to express the linear system:\n  \\[\n    \\begin{bmatrix}\n      u_1 \\\\\n      u_2 \\\\\n      u_3 \\\\\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n      2 & 1 & 5 \\\\\n      1 & 3 & 2 \\\\\n      1 & 2 & 1 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      x_1 \\\\\n      x_2 \\\\\n      x_3 \\\\\n    \\end{bmatrix}\n  \\]\n  \\[\n    U = AX\n  \\]\n  Such a matrix $A = \\begin{bmatrix}\n                       2 & 1 & 5 \\\\\n                       1 & 3 & 2 \\\\\n                       1 & 2 & 1 \\\\\n                     \\end{bmatrix}$ is called a tranformation matrix, and such \n  operation $AX$ is called matrix product.\n\\end{example}\n\n\\subsection{Definition of matrix product}\n\nEntries in a matrix product $AB$ are the dot products of the corresponding rows \nin the matrix $A$ and the corresponding columns in the matrix $B$ respectively.\n\nTherefore, in order to apply the matrix product to the matrices $A$ and $B$ in \nthis way $AB$,\n\\[\n  \\textnormal{the number of columns in A} = \\textnormal{the number of rows in B}\n\\]\nIn other words, the width of $A$ must equal the height of $B$.\n\n\\subsection{Property of matrix product}\n\n\\subsubsection{Associative property}\n\nThe matrix product satisfies the associative property.\n\n\\[\n  (AB)X = A(BX)\n\\]\n\nTherefore, when there are multiple tranformation matrices applied on a vector \nsuch as $ABX$, it means the tranformation matrix $B$ is applied to $X$ first, \nthen the tranformation matrix $A$ is applied to their result.\n\n\\subsubsection{Commutative property}\n\nThe matrix product doesn't satisfy the commutative property.\n\n\\[\n  AB \\neq BA\n\\]\n\nNot only in some cases $AB$ is valid while $BA$ doesn't make sense, but also \nwhen both $AB$ and $BA$ are valid, their results can be different.\n\n\\subsection{Identity Matrix}\n\nThe identity matrix $I$ is defined as the matrix where\n\\[\n  X = IX\n\\]\n\nDeriving from the definition, we know that all identity matrices are square \nmatrices, and identity matrices always have the elements of the main diagonal \n(the list of entries $A_{i,j}$ where $i = j$) as 1, and other elements outside \nof the main diagonal as 0.\n\n\\[\n  I_{4 \\times 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\n\\begin{example}\n  Find the transformation matrix to make a plane rotated by $90^{\\circ}$ \n  counterclockwise.\n\n  Since the transformation matrix represents a rotation of a plane, i.e. \n  transforming each 2D point on the plane into another 2D point, the size of \n  the transformation matrix is $2 \\times 2$:\n  \\[\n    R = \n    \\begin{bmatrix}\n      r_1 & r_2 \\\\\n      r_3 & r_4 \\\\\n    \\end{bmatrix}\n  \\]\n  Then we can use some points and their transformed results to figure out the \n  elements:\n  \\[\n    A = \n    \\begin{bmatrix}\n      1 \\\\\n      0 \\\\\n    \\end{bmatrix}\n    A' = \n    \\begin{bmatrix}\n      0 \\\\\n      1 \\\\\n    \\end{bmatrix}\n  \\]\n  \\[\n    B =\n    \\begin{bmatrix}\n      0 \\\\\n      1 \\\\\n    \\end{bmatrix}\n    B' = \n    \\begin{bmatrix}\n      -1 \\\\\n      0 \\\\\n    \\end{bmatrix}\n  \\]\n  After calculation,\n  \\[\n    R = \n    \\begin{bmatrix}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{bmatrix}\n  \\]\n  We can verify the result by multiply itself by 4 times, which in effect \n  doesn't rotate the plane at all, hence the result should be the identity \n  matrix.\n  \\[\n    RRRR = \n    \\begin{bmatrix}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{bmatrix} = \n    \\begin{bmatrix}\n      1 & 0 \\\\\n      0 & 1 \\\\\n    \\end{bmatrix}\n  \\]\n\\end{example}\n\n\\section{Inverse Matrix}\n\n\\subsection{Definition of inverse matrix}\n\nThe inverse matrix of $A$, usually denoted as $A^{-1}$, is defined as\n\\begin{gather*}\n  A^{-1}A = I \\\\\n  AA^{-1} = I \\\\\n\\end{gather*}\n\nDeriving from the definition, only square matrices have inverse matrix. The \nmatrices which have its corresponding inverse matrix are said to be invertible.\n\nInvert matrices can help solve matrix equations:\n\\begin{gather*}\n  AX = B \\\\\n  A^{-1}AX = A^{-1}B \\\\\n  X = A^{-1}B \\\\\n\\end{gather*}\n\n\\subsection{How to invert a matrix}\n\nThe formula of inverse matrices is:\n\\[\n  A^{-1} = \\frac{1}{det(A)}adj(A)\n\\]\n$adj(A)$ is the adjugate matrix of $A$, or the classical adjoint matrix of $A$.\n\n\\bigskip\n\nSteps to invert a matrix:\n\n1. Calculate the minor $M$ of $A$. The entry on the position $(i,j)$ of the \nminor, called the $(i,j)$-minor of $A$ and denoted $M_{i,j}$, is the determinant \nof the matrices that results from deleting the row $i$ and column $j$ of $A$.\n\n2. Calculate the cofactor matrix $C$ of $A$. The entry on the position $(i,j)$ \nof the cofactor matrix is the result of multiplying $M_{i,j}$ by $(-1)^{i+j}$.\n\n3. Calculate the adjugate matrix $adj(A)$ of $A$ by transposing the cofactor \nmatrix of $A$. Transposing means switching rows and columns correspondingly.\n\n4. Calculate the inverse matrix of $A$ by dividing the adjugate matrix of $A$ by the determinant of $A$.\n\n\\end{document}", "meta": {"hexsha": "4445bfcb4ba4145c9cd62ac17765fb1c29900b43", "size": 6987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture3.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": "lecture3.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": "lecture3.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": 26.566539924, "max_line_length": 104, "alphanum_fraction": 0.6477744382, "num_tokens": 2120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6916975082714386}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\nIn this section, we will give a proper and accurate definition of geometric progression, from which we will derive the summation formula for the geometric progression in both finite and infinite cases.\n\n\\subsection{Definition}\n\\begin{defnbox}{Geometric Progression\\cite{Weisstein2019gp}}{gp}\n    A geometric sequence is a sequence $\\{a_k\\}, k=0, 1, \\ldots$, such that each term is given by a multiple $r$ of the previous one. Another equivalent definition is that a sequence is geometric iff\\footnote{if and only if} it has a zero series bias. If the multiplier is $r$, then the $k$th term is given by\n    \\[\n        a_k = ra_{k-1} = r^2a_{k-2} = \\cdots = a_0r^k.\n    \\]\n\n    Taking $a_0=1$ gives the simple special case\n    \\[\n        a_k = r^k.\n    \\]\n\\end{defnbox}\n\nAccordingly, we can define the arithmetic progression in advance to facilitate future introductions.\n\\begin{defnbox}{Arithmetic Progression\\cite{Weisstein2019ap}}{ap}\n    An arithmetic progression, also known as an arithmetic sequence, is a sequence of $n$ numbers $\\{a_0+kd\\}^{n-1}_{k=0}$ such that the differences between successive terms is a constant $d$. That is,\n    \\[\n        a_k = a_{k-1}+d = a_{k-2}+d = \\cdots = a_0+kd.\n    \\]\n\n    Taking $a_0=0$ gives the simple special case\n    \\[\n        a_k = kd.\n    \\]\n\\end{defnbox}\n\n\n\\subsection{Derivation}\n\\subsubsection{Summation Formula For the Geometric Progression}\nAccording to the definition of the geometric progression, we have,\n\\begin{equation}\\label{E:gp-1}\n    S_n = \\sum_{k=1}^{n} a_k = \\sum_{k=1}^{n} a_1 r^{k-1}.\n\\end{equation}\n\nMultiply both sides of the equation by $r$, then we have,\n\\begin{equation}\\label{E:gp-2}\n    rS_n = \\sum_{k=1}^{n} a_1 r^{k} = \\sum_{k=1}^{n} a_{k+1} = \\sum_{k=2}^{n+1} a_k.\n\\end{equation}\n\nSubtract equation~\\eqref{E:gp-2} from equation~\\eqref{E:gp-1}, we have,\n\\begin{equation}\\label{E:gp-3}\n    (1-r) S_n = a_1 - a_{n+1} = a_1(1-r^n).\n\\end{equation}\n\nTherefore, we need a classification discussion, if the $r$ equals to 1, both sides of the equation cannot divide $1-r$ simultaneously, but we can derivate the formula from equation~\\eqref{E:gp-1}, $S_n=na_1$.\n\nAbove all, we derivate the summation formula for the geometric progression,\n\\begin{equation}\\label{E:gp-4}\n    S_n = \\begin{cases}\n              na_1 & \\text{if } r=1, \\\\\n              \\frac{a_1(1-r^n)}{1-r} & \\text{if } r\\neq 1.\n          \\end{cases}\n\\end{equation}\n\nMoreover, if we use the form of the limit, we can simplify the formula,\n\\begin{equation}\\label{E:gp-5}\n    S_n = \\lim_{q\\to r} \\frac{a_1(1-q^n)}{1-q}.\n\\end{equation}\n\nNext we consider what happens when $n\\to\\infty$. $1-q$ is finite, the convergence of $S_n$ is equivalent to convergence of $\\lim_{q\\to r}1-q^n$. Therefore,  $S$ convergence if and only if $|r|<1$.\n\\begin{equation}\\label{E:gp-6}\n    S = \\lim_{n\\to\\infty} S_n = \\lim_{\\substack{n\\to\\infty \\\\ q\\to r}} \\frac{a_1(1-q^n)}{1-q} = \\lim_{n\\to\\infty}\\frac{a_1(1-r^n)}{1-r} = \\frac{a_1}{1-r}.\n\\end{equation}\n\nIn summary, we get the summation formula for the geometric progression,\n\\[\n    S_n = \\begin{cases}\n              na_1 & \\text{if } r=1, \\\\\n              \\frac{a_1(1-r^n)}{1-r} & \\text{if } r\\neq 1.\n          \\end{cases}\n\\]\nand $S$ convergence if and only if $|r|<1$,\n\\[\n    S = \\lim_{n\\to\\infty} = \\frac{a_1}{1-r}.\n\\]\n\n\n\\subsubsection{Summation Formula For the Arithmetic progression}\nThe summation formula for the arithmetic progression is slightly different from the geometric progression, and it relates back to a famous mathematician, Gauss. The main idea of the formula comes from\n\\[\n    1+2+\\cdots+n = \\frac{n(n+1)}{2}.\n\\]\n\nThe proof part is left to readers as a practice question, we just provide clues below,\n\\begin{equation}\\label{E:ap-1}\n    \\begin{aligned}\n        S_{n+1} &= \\sum_{k=0}^n a_k \\\\\n            &= \\sum_{k=0}^n (a_0+kd) \\\\\n            &= \\sum_{k=0}^n a_0 + d\\sum_{k=0}^n k.\n    \\end{aligned}\n\\end{equation}\n", "meta": {"hexsha": "44951b57ce3fc8fd46169d02b8662ed8f95ff621", "size": 3942, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA320/sections/2/2.tex", "max_stars_repo_name": "iydon/homework", "max_stars_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-20T08:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T12:14:56.000Z", "max_issues_repo_path": "MA320/sections/2/2.tex", "max_issues_repo_name": "AllenYZB/homework", "max_issues_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-01-13T03:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:49:10.000Z", "max_forks_repo_path": "MA320/sections/2/2.tex", "max_forks_repo_name": "AllenYZB/homework", "max_forks_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-02T05:46:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T23:11:28.000Z", "avg_line_length": 41.0625, "max_line_length": 309, "alphanum_fraction": 0.6560121766, "num_tokens": 1367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8807970795424088, "lm_q1q2_score": 0.6916975045855309}}
{"text": "\\documentclass[12pt]{mmalatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Displaying long expressions}\n\nThis example uses a simple (though contrived) example of a Taylor series expansion of $1/(1+x)$ to demonstrate the problems that can arise when displaying very long expressions.\n\n\\begin{minipage}[t]{0.47\\textwidth}\n\\begin{mathematica}\n   f[x_] = 1/(1+x)\n   ans = f[x]                       (* mma (ans.511,ans) *)\n   ans = Series[f[x],{x, 0, 10}]    (* mma (ans.512,ans) *)\n   ans = Series[f[x],{x, 0, 20}]    (* mma (ans.513,ans) *)\n   ans = Series[f[x],{x, 0, 23}]    (* mma (ans.514,ans) *)\n\\end{mathematica}\n\\end{minipage}\n\\hskip 0.5cm\n\\begin{minipage}[t]{0.53\\textwidth}\n\\begin{latex}\n   \\begin{dgroup*}[spread={5pt}]\n      \\begin{dmath*} f(x) = \\Mma*{ans.511} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Mma*{ans.512} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Mma*{ans.513} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Mma*{ans.514} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Mma*[\\hskip 2cm]{ans.514} \\end{dmath*}\n   \\end{dgroup*}\n\\end{latex}\n\\end{minipage}\n\n\\vspace{18pt}\n\nThe first four lines of the following output were set using {\\tt\\small\\verb|\\Mma*|}\nwhile the final line used {\\tt\\small\\verb|\\Mma*[\\hskip=2cm]|}. The last pair of lines displays\nthe output for the same tag {\\tt\\small ans.514} and clearly the formatting of the second\nlast line is not ideal as the text has overlapped the tag. This was corrected in the final\nline by using the option argument {\\tt\\small\\verb|[\\hskip=2cm]|} in the call to {\\tt\\small\\verb|\\Mma*|}.\n\n\\begin{dgroup*}[spread={5pt}]\n   \\begin{dmath*} f(x) = \\Mma*{ans.511} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Mma*{ans.512} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Mma*{ans.513} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Mma*{ans.514} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Mma*[\\hskip 2cm]{ans.514} \\end{dmath*}% LCB: do we need extra space for the tag?\n\\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "bd36b1dfba257e86e14a83ac73763c1cc514e494", "size": 1931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematica/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": "mathematica/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": "mathematica/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": 39.4081632653, "max_line_length": 177, "alphanum_fraction": 0.6261004661, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6916209538881114}}
{"text": "\n\\subsubsection{The Definition of Entropy}\nNow that we know what micro and macro states are, we can define entropy using statistics! In this case, entropy is defined as\n\\begin{equation}\n    \\label{eqn:(41)}\n    S=k_{b}\\ln{\\Omega}\n\\end{equation}\n\nwhere $\\Omega$ is the number of possible microstates within the current macrostate of the system. \\\\\nWith a closed system of constant volume, we can characterize macrostates using the temperature of the system, and microstates as the exact distribution of kinetic energies amongst the particles in the system. Using this we can start to see all the parallels between the two different ways of defining entropy.\n\\begin{enumerate}\n    \\item At $T=0\\textrm{K}$ every particle must have no kinetic energy. So, there's only one possible microstate, and by equation \\ref{eqn:(41)} above $S=0$. This is exactly what we'd expect from the third law of thermodynamics, at absolute zero temperature, we obtain that entropy has a constant value\\footnote{Note that the third law of thermodynamics does not say a system reaches zero entropy as it approaches zero temperature, as there do exist certain systems where the minimum energy (i.e. low temperature) states are not unique. Therefore, there still can be more than one microstate, and hence nonzero (but still constant) entropy. You don't need to know about these in any kind of detail.}.\n    \\item If you have two systems (a and b), the amount of microstates in a system including both of them is $\\Omega_{a}\\Omega_{b}$. Therefore, the total entropy is...\n    \\begin{align*}\n        S_{total}&=k_{b}\\ln{\\Omega_{a}\\Omega_{b}} \\\\\n        &=k_{b}\\ln{\\Omega_{a}}+k_{b}\\ln{\\Omega_{b}} \\\\\n        &=S_{1}+S_{2}\n    \\end{align*}\n    Since the total entropy is the sum of the entropy of both systems, entropy is an extensive quantity!\n    \\item In our example for microstates/macrostates above, the macrostate with the highest number of microstates was the one where each side had three particles (if you don't believe me count them). This analogy applies to two systems that can exchange energy, they have the maximum number of microstates (and therefore entropy) when they share the energy equally (i.e. have the same temperature). \n\\end{enumerate}\nTo close off our discussion of macrostates, microstates, and the statistical definition of entropy, let us consider another concrete example, in the form of the entropy of rolling two dice. Therein, we can consider the macrostate as the sum of the two dice rolls, and the microstates as the particular values we got on each dice (here, we imagine that the dice are unique, in that I can tell them apart from each other). For example, if I rolled the first dice to be 6, and the second dice to be 1, then the microstate could be described with $(6,1)$ and this microstate belongs to the macrostate of $7$. A complete description of all of the macrostates and microstates (as well as the entropy of the macrostate, as defined in this section) is given in the table below, though you may want to work this out for yourself first for practice.\n\n\\begin{center}\n \\begin{tabular}{|c c c|} \n \\hline\n \\textbf{Macrostates} & \\textbf{Microstates} & \\textbf{Entropy}\\\\ \n \\hline\\hline\n 2 & (1,1) & $k_b\\ln(1) = 0$\\\\ \n \\hline\n 3 & (1,2),(2,1) & $k_b\\ln(2)$ \\\\\n \\hline\n 4 & (1,3),(2,2),(3,1) & $k_b\\ln(3)$ \\\\\n \\hline\n 5 & (1,4),(2,3),(3,2),(4,1) & $k_b\\ln(4)$ \\\\\n \\hline\n 6 & (1,5),(2,4),(3,3),(4,2),(5,1) & $k_b\\ln(5)$ \\\\\n \\hline\n 7 & (1,6),(2,5),(3,4),(4,3),(5,2),(6,1) & $k_b\\ln(6)$\\\\\n \\hline\n 8 & (2,6),(3,5),(4,4),(5,3),(6,2) & $k_b\\ln(5)$\\\\\n \\hline\n 9 & (3,6),(4,5),(5,4),(6,3) & $k_b\\ln(4)$\\\\\n \\hline\n 10 & (4,6),(5,5),(6,4) & $k_b\\ln(3)$\\\\\n \\hline\n 11 & (5,6),(6,5) & $k_b\\ln(2)$\\\\\n \\hline\n 12 & (6,6) & $k_b\\ln(1) = 0$\\\\\n \\hline\n\\end{tabular}\n\\end{center}\nThis example also demonstrates an assumption I implicitly made up until this point: all possible microstates are equally likely to appear (in the last example, unless you had loaded dice, every dice roll would have been equally likely!). This is a very fundamental assumption, so much so that it is called the \\textbf{Fundamental Assumption of Statistical Mechanics}. Just to restate it for a more general case (as not every system in the universe is a bunch of dice), it states that every microstate of a system is equally likely and the system on average spends the same amount of time in each of them. We will use this in the next section to conclude our discussion of entropy. ", "meta": {"hexsha": "e446616fea05ac8ef0ac57834dddadd77e44f1e5", "size": 4463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Entropy/statdefinition.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": "Entropy/statdefinition.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": "Entropy/statdefinition.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": 84.2075471698, "max_line_length": 839, "alphanum_fraction": 0.717902756, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6916209514233242}}
{"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 9}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\subsection*{Problem 1}\nSince $\\mathbf{X}$ is full rank, the least sqare estimate of $\\beta$ for the linear model $\\mathbf{Y}=\\mathbf{y}\\beta+\\epsilon$ then $\\hat{\\beta} = \\mathbf{(X'X)^{-1}X'y}$ also this is an unbiased estimator of $\\beta$ that is $E[\\hat{\\beta}]=\\beta$\n\\begin{align*}\na'\\beta &= a'E[\\hat{\\beta}]\\\\\n&= a'E[\\mathbf{(X'X)^{-1}X'y}]\\\\\n&= E[a'\\mathbf{(X'X)^{-1}X'y}]\\\\\n&= E[b'\\mathbf{y}]\n\\end{align*}\nHence when $\\mathbf{X}$ is full rank, we have can take $b'=a'\\mathbf{(X'X)^{-1}X'}$ making every $a'\\beta$ estimable\n\nFor each individual $\\beta_i$ to be estimable, we set $a'=\\begin{pmatrix}0 & 0 & \\dots & 0 & 1 & 0 \\dots 0 \\end{pmatrix}$\nsetting $a_i=1$ remaining zero.\n\n\\subsection*{Problem 2}\nSince each $a_i'\\beta$ is estimable: $a_i'\\beta = E[b_i'Y]$\nConsider $\\lambda_i \\in \\mathcal{R}$\n\\begin{align*}\n\\lambda_1a_1'\\beta + \\lambda_2a_2'\\beta + \\dots + \\lambda_na_n'\\beta &= \\lambda_1 E[b_1'Y] +  \\lambda_2 E[b_2'Y] + \\dots \\lambda_n E[b_n'Y]\\\\\n&= \\sum_i E[\\lambda_ib_i'Y]\\\\\n&= \\sum E[c'Y] \\text{ where }c'= \\mathbf{\\lambda I b'}\n\\end{align*}\nwhere $\\lambda =  \\begin{pmatrix}\\lambda_1 & \\lambda_2 &  \\dots & \\lambda_n \\end{pmatrix}$ and $b' = \\begin{pmatrix} b_1 & b_2 & \\dots b_n \\end{pmatrix}$\n\nHence linear combination of $a_i'\\beta$ is also estimable.\n\n\\subsection*{Problem 3}\n\\begin{align*}\nX &= \\begin{pmatrix}\n1 & 1 & 3\\\\\n1 & 1 & -2\\\\\n1 & 1 & 0\\\\\n1 & 0 & 0\\\\\n\\end{pmatrix}\n\\beta & = \\begin{pmatrix}\n\\beta_1\\\\\n\\beta_2\\\\\n\\beta_3\n\\end{pmatrix}\\\\\n\\beta_1 & = \\begin{pmatrix}1 & 1 & 0\\end{pmatrix}\\mathbf{\\beta}\\\\\n\\beta_1-\\beta_2 &= \\begin{pmatrix}1 &-1 & 0\\end{pmatrix}\\mathbf{\\beta}\\\\\n5\\beta_1+3\\beta_2+9\\beta_3 &= \\begin{pmatrix}5 & 3& 9\\end{pmatrix}\\mathbf{\\beta}\\\\\n\\end{align*}\n\nX has full column rank and hence we can make use of the theorem we proved in Problem 1 to say that all three cases $(a,b,c)$ are indeed estimable, that is since $X$ is full rank, every $a'\\beta$ is estimable (One particular case of the corollary proved in Problem 1 here is the case $a$ where $a'=\\begin{pmatrix}1 & 0 & 0\\end{pmatrix}$\n\\subsection*{Problem 4}\n\\subsubsection*{Problem 4.a}\nDefine $\\mathbf{y}=\\begin{pmatrix}Y_1 & Y_2 &  Y_3\\end{pmatrix}'$, $\\mathbf{\\tau} = \\begin{pmatrix} \\tau_1 & \\tau_2 & \\tau_3 \\end{pmatrix}$, $\\mathbf{\\epsilon} = \\begin{pmatrix}\\epsilon_1 & \\epsilon_2 & \\epsilon_3\\end{pmatrix}$\n\nThus, $\\mathbf{y} = \\begin{pmatrix}1 & 1& 1\\\\\n1 & 0 & 1\\\\\n0 & 1 & 0\n\\end{pmatrix}\\mathbf{\\tau} + \\mathbf{\\epsilon}$\n\nRank of design matrix is 2\n\n\\subsubsection*{Problem 4.b}\n\n$E[b'Y] = a'\\beta = b'X\\beta$ iff $a'=b'X$ or $a=Xb'$\n%which is equivalent to saying that $a$ belongs to row space of $X$\n$\\tau_2$ is estimable:\n\\begin{align*}\n\\tau_2  &= a'\\mathbf{\\beta}= \\begin{pmatrix}0 & 1 & 0\\end{pmatrix}\\mathbf{\\tau}\\\\\n&= EY_3\\\\\n&= E[\\begin{pmatrix}0 & 0 & 1\\end{pmatrix}]\n\\end{align*}\n\n\n$\\tau_1 = \\begin{pmatrix}1 & 0 & 0 \\end{pmatrix}\\mathbf{\\tau}$ so we need to find $b$ such that $\\begin{pmatrix}1 & 0 & 0 \\end{pmatrix}' = X'b$ It is clear to see no b does not exist.\n\n$\\tau_2 =  \\begin{pmatrix}0 & 1 & 0\\end{pmatrix}\\mathbf{\\tau}$ is estimable because $b=\\begin{pmatrix}0 & 1 & 0 \\end{pmatrix}$\n\n$\\tau_3$ is not estimable because of symmetry with $\\tau_1$\n\n\\subsubsection*{Problem 4.c}\n\n$\\tau_1-2\\tau_2+\\tau_3 = \\begin{pmatrix}1 &-2 &1 \\end{pmatrix}\\mathbf{\\tau} = \\begin{pmatrix}1 &1 &0\\\\ 1 &0 &1\\\\ 0 & 1 & 0\\end{pmatrix} \\begin{pmatrix}0\\\\1\\\\-2\\end{pmatrix}$ and hence it is estimable\n\n\\subsubsection*{Problem 4.d}\n\nA possible unbiasd estimator of $\\tau_1-2\\tau_2+\\tau_3 = E[Y_2-2Y_3]$ i.e $Y_2-2Y_3$ whihc is not necessarily BLUE.\n\nFor BLUE, we simply take the OLS estimate of $\\beta$ as $\\hat{\\beta} = \\mathbf{X'X}^{-1}\\mathbf{X'y}$ and from Gauss-Markov model BLUE follows.\n\nGeneralized inverse(using $R$) $\\mathbf{X'X}^{-1} = \\begin{pmatrix} \\frac{1}{6} & \\frac{-1}{6} & \\frac{1}{6}\\\\ \n\\frac{-1}{6} & \\frac{2}{3} & \\frac{-1}{6}\\\\\n\\frac{1}{6} & \\frac{-1}{6} & \\frac{1}{6} \\\\\n\\end{pmatrix}$\n\nso $\\hat{\\beta} =\\mathbf{X'X}^{-1}\\mathbf{X'y} = \\begin{pmatrix} \\frac{1}{6} & \\frac{1}{3} & \\frac{-1}{6}\\\\ \n\\frac{1}{3} & \\frac{-1}{3} & \\frac{2}{3}\\\\\n\\frac{1}{6} & \\frac{1}{3} & \\frac{-1}{6}\\\\\n\\end{pmatrix}\\mathbf{y}$\n\nand hence $\\tau_1-2\\tau_2+\\tau_3 = \\begin{pmatrix} 1 &-2 &1\\end{pmatrix}\\begin{pmatrix} \\frac{1}{6} & \\frac{1}{3} & \\frac{-1}{6}\\\\ \n\\frac{1}{3} & \\frac{-1}{3} & \\frac{2}{3}\\\\\n\\frac{1}{6} & \\frac{1}{3} & \\frac{-1}{6}\\\\\n\\end{pmatrix}\\mathbf{y} = \\frac{-Y_1+4Y_2-5Y_3}{3}  $\n\nThus BLUE of  $\\tau_1-2\\tau_2+\\tau_3$ : $ \\frac{-Y_1+4Y_2-5Y_3}{3}$\n\\end{document}\n\n\n\n", "meta": {"hexsha": "b31be55bad646271595d257f67ebe23cbb43852d", "size": 4742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW09/hw09.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/HW09/hw09.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/HW09/hw09.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": 40.8793103448, "max_line_length": 335, "alphanum_fraction": 0.6353859131, "num_tokens": 2018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.6916209494173392}}
{"text": "\\section{Numpy} % (fold)\n\\label{sec:numpy}\nGenerate matrices $A$, with random Gaussian entries, $B$, a Toeplitz matrix, where\n$A \\in \\R^{n\\times m}$ and $B \\in \\R^{m \\times m}$, for n = 200, m = 500.\n\n\\begin{questions}\n\n\\titledquestion{Matrix operations}\n\\label{sub:mat_ops}\n\nCalculate $A + A$, $A A^\\top, A^\\top A$ and $AB$.\nWrite a function that computes $A(B - \\lambda I)$ for any $\\lambda$.\n\n\\titledquestion{Solving a linear system}\n\\label{sub:linear_system}\n\nGenerate a vector $b$ with $m$ entries and solve $Bx = b$.\n\n\\titledquestion{Norms} % (fold)\n\\label{sub:norms}\n\nCompute the Frobenius norm of $A$: $\\|A\\|_F$ and the infinity norm of $B$:\n$\\|B\\|_{\\infty}$. Also find the largest and smallest singular values of $B$.\n\n% titledquestion norms (end)\n\n\\titledquestion{Power iteration}\n\\label{sub:power}\n\nGenerate a matrix $Z$, $n \\times n$, with Gaussian entries, and use the power iteration to\nfind the largest eigenvalue and corresponding eigenvector of $Z$.\nHow many iterations are needed till convergence?\n\nOptional: use the \\texttt{time.clock()} method to compare computation time when varying $n$.\n\n\\titledquestion{Singular values} % (fold)\n\\label{sub:svd}\n\nGenerate an $n \\times n$ matrix, denoted by $C$, where each entry is $1$ with probability $p$ and\n$0$ otherwise.\nUse the linear algebra library of Scipy to compute the singular values of $C$.\nWhat can you say about the relationship between $n$, $p$ and the largest singular value?\n\n% titledquestion svd (end)\n\n\\titledquestion{Nearest neighbor} % (fold)\n\\label{sub:nearest_neighbor}\n\nWrite a function that takes a value $z$ and an array $A$ and finds\nthe element in $A$ that is closest to $z$. The function should\nreturn the closest value, not index.\n\nHint: Use the built-in functionality of Numpy rather than writing code to find this\nvalue manually. In particular, use brackets and \\texttt{argmin}.\n\n% titledquestion nearest_neighbor (end)\n\n\n\\end{questions}\n% section numpy (end)\n", "meta": {"hexsha": "055bb80e572155c891ee2e545d2271da2a493087", "size": 1951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/tex/numpy.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/numpy.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/numpy.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": 31.9836065574, "max_line_length": 97, "alphanum_fraction": 0.7283444387, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.8080672204860317, "lm_q1q2_score": 0.6915852574796156}}
{"text": "\\chapter{eq}\n\n\\begin{equation}\nT_{motes}\\ = N_{slots}*N_{motes} \n\\end{equation}\n\n\n\\begin{tabular}{lllp{10cm}}\nwhere, &   &   &   \\\\ \n%\\hline \n  & $T_{motes}$  & = & the maximum number of motes that can be accommodated in the network \\\\ \n%\\hline \n  & $N_{slots}$ & = & the maximum number of transmission slots in a transmission period \\\\ \n%\\hline \n  & $N_{motes}$ & = & the maximum number of motes in each transmission slot of the \\textit{\\textbf{root}} mote \\\\ \n\\end{tabular} \n\n\\begin{center}\n$N_{motes}\\ =\\ \\dfrac{internal\\ message\\ buffer\\ size}{message\\ length}$\n\\end{center}\n\n\n$N_{slots}\\ =\\ \\dfrac{transmission\\ interval}{transmission\\ slot\\ duration}$\n\n\n$B_{charged}\\ =\\ T_{sunlight}*I$\n\n\n\n\\begin{tabular}{lllp{10cm}}\nwhere, &   &   &   \\\\ \n%\\hline \n  & $B_{charged}$  & = & the amount of battery charged $(milliamps)$ \\\\ \n%\\hline \n  & $T_{sunlight}$ & = &  the time for which sunlight is present $(hours)$\\\\ \n%\\hline \n  & $I$ & = & the amount of current used to charge the battery $(milliamps)$\\\\ \n\\end{tabular} ", "meta": {"hexsha": "a025e01c3023fa1ce8507d4f96052fa37bb7dca2", "size": 1019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "eq.tex", "max_stars_repo_name": "aravindhsampath/virtualizing-Intelligent-River", "max_stars_repo_head_hexsha": "7203cebdeb54a555e10722d2b7b4ec9e1c58e219", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "eq.tex", "max_issues_repo_name": "aravindhsampath/virtualizing-Intelligent-River", "max_issues_repo_head_hexsha": "7203cebdeb54a555e10722d2b7b4ec9e1c58e219", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "eq.tex", "max_forks_repo_name": "aravindhsampath/virtualizing-Intelligent-River", "max_forks_repo_head_hexsha": "7203cebdeb54a555e10722d2b7b4ec9e1c58e219", "max_forks_repo_licenses": ["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.8157894737, "max_line_length": 114, "alphanum_fraction": 0.6310107949, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6915848836926228}}
{"text": "\\input ../6001mac\n\n\\begin{document}\n\n\\psetheader{Sample Problem Set}{Streams And Series}\n\\begin{center}\n{\\bf Streams}\n\\end{center}\n\n\\section{Part 1: Tutorial exercises}\n\nPrepare the following exercises for oral presentation in tutorial:\n\n\\paragraph{Tutorial exercise 1:} \nDescribe the streams produced by the following definitions.  Assume\nthat {\\tt integers} is the stream of non-negative integers (starting\nfrom 1):\n\n\\beginlisp \n(define A (cons-stream 1 (scale-stream 2 A)))\n\\null\n(define (mul-streams a b)\n  (cons-stream\n   (* (stream-car a) (stream-car b))\n   (mul-streams (stream-cdr a)\n                (stream-cdr b))))\n\\null\n(define B (cons-stream 1 (mul-stream B integers)))\n\\endlisp\n\n\\paragraph{Tutorial exercise 2} \n\nGiven a stream {\\tt s} the following procedure returns the stream of\nall pairs of elements from {\\tt s}:\n\n\\beginlisp\n(define (stream-pairs s)\n  (if (stream-null? s)\n      the-empty-stream\n      (stream-append\n       (stream-map\n        (lambda (sn) (list (stream-car s) sn))\n        (stream-cdr s))\n       (stream-pairs (stream-cdr s)))))\n\\null\n(define (stream-append s1 s2)\n  (if (stream-null? s1)\n      s2\n      (cons-stream (stream-car s1)\n                   (stream-append (stream-cdr s1) s2))))\n\\endlisp\n\n\\noindent\n(a) Suppose that {\\tt integers} is the (finite) stream 1, 2, 3, 4, 5.\nWhat is {\\tt (stream-pairs s)}?  (b) Give the clearest explanation\nthat you can of how {\\tt stream-pairs} works.  (c) Suppose that {\\tt\ns} is the stream of positive integers.  What are the first few\nelements of {\\tt (stream-pairs s)}?  Can you suggest a modification of\n{\\tt stream-pairs} that would be more appropriate in dealing with\ninfinite streams?\n\n\n\\section{Part 2: Laboratory---Using streams to represent power series}\n\nWe described in lecture a few weeks ago how to represent polynomials\nas lists of terms.  In a similar way, we can work with {\\it power\nseries}, such as\n\\begin{eqnarray*}\ne^{x} &=&\n1+x+\\frac{x^{2}}{2}+\\frac{x^{3}}{3\\cdot2}+\\frac{x^{4}}{4\\cdot 3\\cdot\n2}+\\cdots \\cr\n\\cos x &=& 1-\\frac{x^{2}}{2}+\\frac{x^{4}}{4\\cdot 3\\cdot 2}-\\cdots \\cr\n\\sin x &=& x-\\frac{x^{3}}{3\\cdot 2}+\\frac{x^{5}}{5\\cdot 4\\cdot 3\\cdot 2}- \\cdots\n\\end{eqnarray*}\nrepresented as streams of infinitely many terms.  That is, the power\nseries\n\n\\[ a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \\cdots \\]\n\n\\noindent\nwill be represented as the infinite stream whose elements are $a_0,\na_1, a_2, a_3, \\ldots$.\\footnote{In this representation, all streams are\ninfinite: a finite polynomial will be represented as a stream with an\ninfinite number of trailing zeroes.}\n\nWhy would we want such a method?  Well, let's separate the idea of a\nseries representation from the idea of evaluating a function.  For\nexample, suppose we let $f(x) = \\sin x$.  We can separate the idea of\nevaluating $f$, e.g., $f(0) = 0, f(.1) = 0.0998334$, from the means we\nuse to compute the value of $f$.  This is where the series\nrepresentation is used, as a way of storing information sufficient to\ndetermine values of the function.  In particular, by substituting a\nvalue for $x$ into the series, and computing more and more terms in\nthe sum, we get better and better estimates of the value of the\nfunction for that argument.  This is shown in the table, where $\\sin\n{1 \\over 10}$ is considered.\n\n\\begin{tabular}{lllll}\nCoefficient&$x^n$&term&sum&value\\\\\n\\hline\n0& 1& 0 & 0& 0\\\\\n\\\\\n1& ${1 \\over 10}$& ${1 \\over 10}$ & ${1 \\over 10}$& .1\\\\\n\\\\\n0&${  1 \\over 100}$& 0 &  ${1 \\over 10}$& .1\\\\\n\\\\\n- ${1 \\over 6}$& ${1 \\over 1000}$& - ${1 \\over 6000}$ & ${599 \\over 6000}$& .099833333333\\\\\n\\\\\n0& ${1 \\over 10000}$& 0 & ${599 \\over 6000}$& .099833333333\\\\\n\\\\\n${1 \\over 120}$& ${1 \\over 100000}$& ${1 \\over 12000000}$ & ${1198001 \\over\n12000000}$& .09983341666\\\\\n\\\\\n\\end{tabular}\n\nThe first column shows the terms from the series representation for\nsine.  This is the infinite series with which we will be dealing.  The\nsecond column shows values for the associated powers of ${1 \\over 10}$.\nThe third column is the product of the first two, and represents the\nnext term in the series evaluation.  The fourth column represents the\nsum of the terms to that point, and the last column is the decimal\napproximation to the sum.\n\nWith this representation of functions as streams of coefficients,\nseries operations such as addition and scaling (multiplying by a\nconstant) are identical to the basic stream operations.  We provide\nseries operations, though, in order to implement a complete power\nseries data abstraction:\n\n\\beginlisp\n(define (add-streams s1 s2)\n  (cond ((stream-null? s1) s2)\n        ((stream-null? s2) s1)\n        (else\n         (cons-stream (+ (stream-car s1) (stream-car s2))\n                      (add-streams (stream-cdr s1)\n                                   (stream-cdr s2))))))\n\\null\n(define (scale-stream c stream)\n  (stream-map (lambda (x) (* x c)) stream))\n\\null\n(define add-series add-streams)\n\\null\n(define scale-series scale-stream)\n\\null\n(define (negate-series s)\n  (scale-series -1 s))\n\\null\n(define (subtract-series s1 s2)\n  (add-series s1 (negate-series s2)))\n\\endlisp\n\n\\noindent You can use the following procedure to examine the series you will\ngenerate in this problem set:\n\n\\beginlisp\n(define (show-series s nterms)\n  (if (= nterms 0)\n      'done\n      (begin (write-line (stream-car s))\n             (show-series (stream-cdr s) (- nterms 1)))))\n\\endlisp\n\n\\noindent\nYou can also examine an individual coefficient (of $x^n$) in a series\nusing {\\tt series-coeff}:\n\n\\beginlisp\n(define (series-coeff s n)\n  (stream-ref s n))\n\\endlisp        \n\nWe also provide two ways to construct series.  {\\tt Coeffs->series}\ntakes an list of initial coefficients and pads it with zeroes to\nproduce a power series.  For example, {\\tt (coeff->series '(1 3 4))}\nproduces the power series $1+3x+4x^2+0x^3+0x^4+\\ldots{}$.\n\n\\beginlisp\n(define (coeffs->series list-of-coeffs)\n  (define zeros (cons-stream 0 zeros))\n  (define (iter list)\n    (if (null? list)\n        zeros\n        (cons-stream (car list)\n                     (iter (cdr list)))))\n  (iter list-of-coeffs))\n\\endlisp\n\n{\\tt Proc->series} takes as argument a procedure $p$ of one numeric\nargument and returns the series\n\\[  p(0) + p(1)x + p(2)x^2 + p(3)x^3 + \\cdots  \\]\nThe definition requires the stream {\\tt non-neg-integers} to be the stream of\nnon-negative integers: $0,1,2,3,\\ldots{}$\\,.\n\n\\beginlisp\n(define (proc->series proc)\n  (stream-map proc non-neg-integers))\n\\endlisp\n\n\\medskip\n\n\\noindent\n{\\bf Note:} Loading the code for this problem set will change\nScheme's basic arithmetic operations {\\tt +}, {\\tt -}, {\\tt *}, and\n{\\tt /} so that they will work with rational numbers.  For instance,\n{\\tt (/ 3 4)} will produce 3/4 rather than .75.  You'll find this\nuseful in doing the exercises below.\n\n\n\\paragraph{Lab exercise 1:}\nLoad the code for problem set 9.  To get some initial practice with\nstreams, write and turn in definitions for each of the following:\n\n\\begin{itemize}\n\n\\item {\\tt ones}: the infinite stream of 1's.\n\n\\item {\\tt non-neg-integers}:  the stream of integers, $1, 2, 3, 4,\n\\ldots$\n\n\\item {\\tt alt-ones}:  the stream $1, -1, 1, -1, \\ldots$\n\n\\item {\\it zeros}:  the infinite stream of 0's.  Do this using {\\tt alt-ones}.\n\n\\end{itemize}\n\n\nNow, show how to define the series:\n\\begin{eqnarray*}\nS_1 &=& 1 + x + x^2 + x^3 + \\cdots \\cr\nS_2 &=& 1 + 2x + 3x^2 + 4x^3 + \\cdots\n\\end{eqnarray*}\nTurn in your definitions and a couple of coefficient printouts to\ndemonstrate that they work.\n\n\n\\paragraph{Lab exercise 2:}\n\nMultiplying two series is a lot like multiplying two multi-digit numbers,\nbut starting with the left-most digit, instead of the right-most.\n\nFor example:\n\n\\begin{verbatim}\n\n                11111\n             x  12321\n            _________\n\n            11111\n             22222\n              33333\n               22222\n                11111\n            ---------\n            136898631\n\n\\end{verbatim}\n\nNow imagine that there can be an infinite number of digits, i.e., each of \nthese is a (possibly infinite) series.  (Remember that because each \"digit\" \nis in fact a term in the series, it can become arbitrarily large, without\ncarrying, as in ordinary multiplication.)\n\nUsing this idea, complete the definition of the following procedure,\nwhich multiplies two series:\n\\beginlisp\n(define (mul-series s1 s2)\n  (cons-stream $\\langle E_1 \\rangle$\n               (add-series $\\langle E_2 \\rangle$\n                           $\\langle E_3 \\rangle$)))\n\\endlisp\nTo test your procedure, demonstrate that the product of $S_1$ (from\nexercise 1) and $S_1$ is $S_2$.  What is the coefficient of\n$x^{10}$ in the product of $S_2$ and $S_2$?  Turn in your definition of\n{\\tt mul-series}.  (Optional: Give a general formula for the\ncoefficient of $x^n$ in the product of $S_2$ and $S_2$.)\n\n\\subsection*{Inverting a power series}\n\nLet $S$ be a power series whose constant term is 1.  We'll call such a\npower series a ``unit power series.''  Suppose we want to find the {\\em\ninverse} of $S$, namely, the power series $X$ such that $S\\cdot X= 1$.\nTo see how to do this, \nwrite $S=1+S_R$ where $S_R$ is the rest of $S$ after the constant\nterm.  Then we want to solve the equation $S \\cdot X = 1$ for $S$ and\nwe can do this as follows: \n\n\\begin{eqnarray*}\nS \\cdot X &=& 1 \\cr\n(1+S_R)\\cdot X &=& 1 \\cr\nX + S_R \\cdot X &=& 1 \\cr\nX &=& 1 - S_R \\cdot X\n\\end{eqnarray*}\n\nIn other words, $X$ is the power series whose constant term is 1 and\nwhose rest is given by the negative of $S_R$ times $X$.\n\n\\paragraph{Lab exercise 3:} Use this idea to write a procedure {\\tt\ninvert-unit-series} that computes $1/S$ for a unit power series $S$.\nTo test your procedure, invert the series $S_1$ (from exercise 1) and\nshow that you get the series $1-x$.  (Convince yourself that this is\nthe correct answer.)  Turn in a listing of your procedure.  This is a\nvery short procedure, but it is very clever.  In fact, to someone\nlooking at it for the first time, it may seem that it can't\nwork---that it must go into an infinite loop.  Write a few sentences\nof explanation explaining why the procedure does in fact work, and\ndoes not go into a loop.\n\n\\paragraph{Lab exercise 4:} Use your answer from exercise 3 to produce\na procedure {\\tt div-series} that divides two power series.  {\\tt\nDiv-series} should work for any two series, provided that the\ndenominator series begins with a non-zero constant term.  (If the\ndenominator has a zero constant term, then {\\tt div-series} should\nsignal an error.)  Turn in a listing of your procedure along with\nthree or four well-chosen test cases (and demonstrate why the answers\ngiven by your division are indeed the correct answers).\n\n\\paragraph{Lab exercise 5:}  Now suppose that we want to integrate a\nseries representation.  By this, we mean that we want to perform\nsymbolic integration, thus, for example, \ngiven a series\n\\[ a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \\cdots \\]\nwe want to return the integral of the series (except for the constant term) \n\\[ a_0 x + \\frac{1}{2}a_1 x^2 + \\frac{1}{3}a_2 x^3 + \\frac{1}{4}a_3 x^4 + \\cdots \\]\n\nDefine a procedure {\\tt\nintegrate-series-tail} that will do this.   Note that all you need to\ndo is transform the series\n\n\\[ a_0 \\ \\ \\ \\ \\  a_1 \\ \\ \\ \\ \\  a_2  \\ \\ \\ \\ \\  a_3  \\ \\ \\ \\ \\   a_4  \\ \\ \\ \\ \\   a_5  \\ \\ \\ \\ \\  \\cdots \\]\n\ninto the series \n\n\\[ a_0 \\ \\ \\ \\ \\  {a_1 \\over 2} \\ \\ \\ \\ \\  {a_2 \\over 3}  \\ \\ \\ \\ \\\n{a_3 \\over 4}  \\ \\ \\ \\ \\  \n{a_4 \\over 5}  \\ \\ \\ \\ \\  \n{a_5 \\over 6}  \\ \\ \\ \\ \\  \\cdots \\]\n\nNote that this means that the procedure generates the coefficients of\na series starting with the first order coefficient, not that the\nzeroth order coefficient is 0.\n\nTurn in a listing of your procedure and demonstrate that it works by\ncomputing {\\tt integrate-series-tail} of the series $S_2$ from\nexercise 1.\n\n\\paragraph{Lab exercise 6:} Demonstrate that you can generate the\nseries for $e^x$ as\n\n\\beginlisp\n(define exp-series\n  (cons-stream 1 (integrate-series-tail exp-series)))\n\\endlisp\n\n\\noindent Explain the reasoning behind this definition.  Show how to generate\nthe series for sine and cosine, in a similar way, as a pair of mutually\nrecursive definitions.  It may help to recall that the integral \n\\[\\int \\sin x =  - \\cos x\\]\nand that the integral\n\\[\\int \\cos x = \\sin x\\]\n\n\n\\paragraph{Lab exercise 7:} Louis Reasoner is unhappy with the idea\nof using {\\tt integrate-series-tail} separately.  ``After all,'' he\nsays, ``if we know what the constant term of the integral is supposed\nto be, we should just be able to incorporate that into a procedure.''\nLouis consequently writes the following procedure, using {\\tt\nintegrate-series-tail}:\n\n\\beginlisp\n(define (integrate-series series constant-term)\n  (cons-stream constant-term (integrate-series-tail series)))\n\\endlisp\n\n\\noindent\nHe would prefer to define the exponential series as\n\n\\beginlisp \n(define exp-series\n  (integrate-series exp-series 1))\n\\endlisp \n\n\\noindent\nWrite a two or three sentence clear explanation of why this won't\nwork, while the definition in exercise 6 does work.\n\n\\paragraph{Lab exercise 8:} Write a procedure that produces the\nderivative of a power series.  Turn in a definition of your procedure\nand some examples demonstrating that it works.\n\n\\paragraph{Lab exercise 9:} Generate the power series for tangent,\nand secant.  List the first ten or so coefficients of each\nseries.  Demonstrate that the derivative of the tangent is the square\nof the secant.\n\n\\paragraph{Lab exercise 10:}  We can also generate power series for\ninverse trigonometric functions.  For example:\n\\[\\tan^{-1}(x) = \\int_0^x {dz \\over {1 + z^2}}\\]\nUse this equation, plus methods that you have already created, to\ngenerate a power series for arctan. \nNote that $1+z^2$ can be viewed as a finite series.\nTurn in your definition, and a\nprintout of the first few coefficients of the series.\n\n\\paragraph{Lab exercise 11:}  One very useful feature of a power\nseries representation for a function is that one can use the initial\nterms in the series to get approximations to the function.  For\nexample, suppose we have\n\n\\[f(x) = a_0 + a_1x + a_2 x^2 + a_3 x^3 + \\ldots\\]\n\nWe have represented this by the series of coefficients:\n\n\\[\\left\\{a_0\\ \\ a_1\\ \\ a_2 \\ \\ a_3 \\ \\ \\ldots\\right\\}\\]\n\nNow suppose that we want to approximate the value of the function $f$\nat some point $x_0$.  We could successively improve this\napproximation\\footnote{actually there are some technical issues\nabout whether the argument is in the radius of convergence of the\nseries, but we'll ignore that issue here} by considering the following\n\n\\begin{eqnarray} f(x_0) \\approx a_0\\\\ f(x_0) \\approx a_0 + a_1 x_0\\\\\nf(x_0) \\approx a_0 + a_1 x_0 + a_2 x_0^2\\\\\n\\end{eqnarray}\n\nNotice that each of these expressions (1), (2), (3) could also be captured in a\nstream representation, with first term $a_0$, second term $a_0 + a_1\nx_0$ and so on.\n\nImplement this idea by defining a procedure {\\tt approximate} which\ntakes as arguments a value $x_0$ and a series representation of a\nfunction $f$, and which returns a stream of successive approximations\nto the value of the function at that point $f(x_0)$.  Turn in a\nlisting\nof your code, as well as examples of using it to approximate some\nfunctions.\nNote that to be very careful, this is not a series representation but\na stream one, so you may want to think carefully about which\nrepresentations to use.\n\n{\\bf Optional additional exercises}\n\nhe {\\em Bernoulli numbers} $B_n$ are\ndefined by the coefficients in the following power series:%\n%\n\\footnote{The Bernoulli numbers arise in a wide variety of\napplications involving power series and approximations.  They were\nintroduced by Jacob Bernoulli in 1713.}%\n%\n\\[\n\\frac{x}{e^x-1} = B_0 + B_1 x + \\frac{B_2 x^2}{2!} + \\frac{B_3\nx^3}{3!} + \\cdots = \\sum_{k \\geq 0} \\frac{B_k x^k}{k!}\n\\]\nWrite a procedure that takes $n$ as an argument and produces the $n$th\nBernoulli number.  (Check: All the odd Bernoulli numbers are zero\nexcept for $B_1=-1/2$.)  Generate a table of the first 10 (non-zero)\nBernoulli numbers.  Note: Since $e^x-1$ has a zero constant term, you\ncan't just use {\\tt div-series} to divide $x$ by this directly.\n\nIt turns out that the coefficient of\n$x^{2n-1}$ in the series expansion of $\\tan x$ is given by\n\\[\n\\frac{(-1)^{n-1} 2^{2n} (2^{2n} - 1) B_{2n}}{(2n)!}\n\\]\nUse your series expansion of tangent to verify this for a few of\nvalues of $n$.\n\n\n\\end{document}\n", "meta": {"hexsha": "7e03a0b1bd075f4afc91665cb78c2fd43e7255da", "size": 16289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "additional-assignments/ps9/ps9.tex", "max_stars_repo_name": "Buxus/sicp", "max_stars_repo_head_hexsha": "8fbea7e0def60eda5f8b4be7a9d20635de95b4af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "additional-assignments/ps9/ps9.tex", "max_issues_repo_name": "Buxus/sicp", "max_issues_repo_head_hexsha": "8fbea7e0def60eda5f8b4be7a9d20635de95b4af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "additional-assignments/ps9/ps9.tex", "max_forks_repo_name": "Buxus/sicp", "max_forks_repo_head_hexsha": "8fbea7e0def60eda5f8b4be7a9d20635de95b4af", "max_forks_repo_licenses": ["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.5838641189, "max_line_length": 108, "alphanum_fraction": 0.6952544662, "num_tokens": 4896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.9161096216057903, "lm_q1q2_score": 0.6915848829638431}}
{"text": "\\chapter{Cryptography and Computer Security}\r\n\\section{Classical Systems}\r\n{\\bf Shannon Theory: } Shannon \\emph{entropy} of random variable $X$ is \r\n$H(X)= - \\sum_{i=1}^n P(X=x_i) lg(P(X=x_i))$.\r\nWhat is the amount of information in a number $n: 0 \\le n <2^m$?  \r\nInformation learned about \r\n$Y$ by observing $X$ is $I(Y; X)= H(Y) - H(Y|X)$.  Note $H(Y|X)= -\\sum p_X(x) H(Y|X=x)$ which\r\nis generally not equal to $\\sum_{X, Y} p_Y(y|x) lg(p_Y(y|x))$.\r\n$H_E= lim_{N \\rightarrow \\infty} {\\frac {H(P^n)} {n}}$.  $H(K|C)= H(M|C)+ H(K|M,C)$.\r\n\\\\\r\n\\\\\r\n{\\bf Application to cryptography: }\r\n\\emph{Perfect secrecy: } $Pr(M|C)=P(M)$.  \r\n\\emph{Unicity Theorem: }  Let $H$ be the entropy of the \r\nsource (say English) and let $\\Sigma$ be the alphabet.  \r\nLet $K$ be the set of (equiprobable) keys, then $u= {\\frac {lg(|K|)} {(lg(|\\Sigma|)-H)}}$.\r\nThe ``Index of Coincidence,''\r\n$IC(f)= {\\frac {\\sum {f_i(f_i-1)}} {n(n-1)}}$.\r\n$MC(f, f')= {\\frac {\\sum {f_i f_{i}'}} {n n'}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Vigeniere alphabet chaining: }  If $\\alpha$ is the mixed plaintext alphabet and\r\n$\\beta$ is the mixed cipher alphabet underneath, rearranging with the plain alphabet into\r\nits normal form we get the tableaux:\r\n\\begin{center}\r\n\\begin{tabular} {|c|c|c|c|}\r\n\\hline\r\n1 & 2 & $\\ldots$ & n\\\\\r\n\\hline\r\n$\\beta(\\alpha^{-1}(1))$ & $\\beta(\\alpha^{-1}(2))$ & $\\ldots$ & $\\beta(\\alpha^{-1}(n))$\\\\\r\n$\\beta(\\alpha^{-1}(1)+1)$ & $\\beta(\\alpha^{-1}(2)+1)$ & $\\ldots$ & $\\beta(\\alpha^{-1}(n)+1)$\\\\\r\n$\\ldots$ & $\\ldots$ & $\\ldots$ & $\\ldots$\\\\\r\n$\\beta(\\alpha^{-1}(1)+n-1)$ & $\\beta(\\alpha^{-1}(2))$ & $\\ldots$ & $\\beta(\\alpha^{-1}(n)+n-2)$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nNote that the columns have the same sequence of characters as the original rows ---\r\nif plain A corresponds to cipher F and\r\nif plain F corresponds to cipher W then the distance between plain A and plain F is the\r\nsame as cipher F and cipher W in the original sequence.\r\n\\\\\r\n\\\\\r\n{\\bf Heburn: } Five rotors, \r\ntwo ratchet controls.  Key: $[i,j,k,m,n]$ and 2 ratchet stepping \r\ncontrols at right and left $(l, r)$.  Rightmost ($R_5$) rotor moved after\r\nevery enciphered \r\nletter.  Leftmost ($R_1$) moved when fast rotor reached position specified by $r$.  \r\n$a(m)$ character in line to $R_5$.\r\nWhen the leftmost rotor hit $l$ the middle ($R_3$) rotor moved one position.  Equation:\r\n$(p)K C^iR_1C^{-i} C^j R_2 C^{-j} C^k R_3 C^{-k} C^m R_4 C^{-m} C^n R_5 C^{-n} L=c$,\r\n$C$ is the cyclic in alphabetical order.  Solution: $c(m)= a(m) C^{(m+p)} R_5 C^{-(m+p)}L$,\r\n$d(m,p)= c(m)L^{-1} C^{(m+p)} R_5^{-1} C^{-(m+p)}$ then \r\n$d(m,p) R_5^{-1} C^{n-m} R_5=d(n,p)$.  Practical application relies on the IC for the\r\nmonoalphabetic substitution (imagine all the input letters are the same).  If \r\n$i=d(m,p)$, $j=d(n,p)$ and $k=n-m$.  To remove noise, tally\r\n$s'[i,j,k]= \\sum_m \\sum_n s[i, m, k-m] s[m,j,n]$, this can be iterated.\r\n\\\\\r\n\\\\\r\n{\\bf Enigma: }\r\n$K$: Keyboard.\r\n$P=(ABCDEFGHIJKLMNOPQRSTUVWXYZ)$.\r\n$N$: First Rotor.\r\n$M$: Second Rotor.\r\n$L$: Third Rotor.\r\n$U$: Reflector.  Note: $U=U^{-1}$.\r\n$i,j,k$: Number of rotations of first, second and third rotors respectively.\r\n$c= (p) P^i N P^{-i} P^j M P^{-j} P^k L P^{-k} U P^k L^{-1} P^{-k} P^j M^{-1} P^{-j} P^i N^{-1} P^{-i}$.\r\nLater military models added plug-board or ``Stecker''($S$):\r\n$$c=(p) S P^i N P^{-i} P^jMP^{-j} P^kLP^{-k} U P^kL^{-1}P^{-k} P^jM^{-1}P^{-j} P^iN^{-1}P^{-i}\r\nS^{-1}.$$\r\nTotal key including rotor wiring (in bits):\r\n$67.1 + 3 \\times 88.4 = 312.3$.\r\n\\\\\r\n\\emph{Method of Batons (no Stecker):} \r\nLet $N$ be the fast rotor and $Z$ the combined \r\neffect of the other apparatus, then,\r\n$N^{-1}ZN(p)=c$ \r\nat first letter; assuming other rotor doesn't turn,\r\n$P^{-i}N^{-1}P^iZP^{-i}NP^i(p)=c$ or\r\n$ZP^{-i}N(p(i))P^i= P^{-i}NP^i c(i)$.  \\emph{Rejewski:}\r\nLet $Q= MLUL^{-1}M^{-1}=Q^{-1}$,\r\nthe first 6 permutations (used to encrypt settings twice) are:\r\n$$A=A^{-1}= SP^1NP^{-1}QP^1N^{-1}P^{-1}S^{-1}, B=B^{-1}= SP^2NP^{-2}QP^2N^{-1}P^{-2}S^{-1}$$\r\n$$C=C^{-1}= SP^3NP^{-3}QP^3N^{-1}P^{-3}S^{-1}, D=D^{-1}= SP^4NP^{-4}QP^4N^{-1}P^{-4}S^{-1}$$\r\n$$E=E^{-1}= SP^5NP^{-5}QP^5N^{-1}P^{-5}S^{-1}, F=F^{-1}= SP^6NP^{-6}QP^6N^{-1}P^{-6}S^{-1}$$\r\nTheir products and ciphertext ($c_1c_2c_3c_4c_5c_6$) satisfy:\r\n$$AD= SP^1NP^{-1}QP^1N^{-1}P^3NP^{-4} QP^4N^{-1}P^{-4} S^{-1}, (c_1)AD= c_4$$\r\n$$BE= SP^2NP^{-2}QP^2N^{-1}P^3NP^{-5}QP^5N^{-1}P^{-5}S^{-1}, (c_2)BE= c_5$$\r\n$$CF= SP^3NP^{-3}QP^3N^{-1}P^3NP^{-6}QP^6N^{-1}P^{-6}S^{-1}, (c_3)CF= c_6$$\r\nSo we can find $AD$, $BE$ and $CF$ after about 80 messages.  To solve for rotors if\r\n$S$ is known.  First note the following theorem.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } If two permutations of the same \r\ndegree consist of disjoint transpositions then their product contains an even number of cycles\r\nof the same length (and conversely). ``Cillies'' (guessed simple indicators like aaa)\r\nalign cycles. Let $U=P^{-1}S^{-1}ASP= PNP^{-1}QPN^{-1}P^{-1}$,\r\n$V= P^{-2}S^{-1}BSP^2$, etc, then \r\n$VW= NP^{-1}N^{-1} (UV)  N P N^{-1}$,\r\n$WX= NP^{-1}N^{-1} (VW)  N P N^{-1}$, etc.\r\nwhich can be solved for $N$.\r\n\\\\\r\n\\\\\r\nAssume we know all rotor wirings and the plaintext for some received ciphertext. \r\nWe do not know plugboard, rotor order, ring and indicator.\r\n\\begin{verbatim}\r\nPosition   123456789012345678901234\r\nPlain Text OBERKOMMANDODERWEHRMACHT\r\nCipherText ZMGERFEWMLKMTAWXTSWVUINZ\r\n\\end{verbatim}\r\nObserve the loop $A[9] \\rightarrow M[7] \\rightarrow E[14] \\rightarrow  A$.\r\n$(E)M_7M_9M_{14}=E$, where $M_i$ is the effect of the machine at position $i$.\r\nBritish Bombe searched probable text for these loop isomorphisms.  False alarms have probability\r\n${\\frac 1 {26}}$ for each independent loop tested.\r\n\\section{Public Key Systems}\r\n{\\bf RSA: } $n=pq$, choose e, $ed=1 \\jmod{\\phi(pq)}$, $e$ is often $2^{16}+1$ for efficiency.\r\n\\\\\r\n\\\\\r\n{\\bf DLP: } Given $g, h$ and $h=g^x$, find $x$.  \r\n{\\bf DHP: }  Given $g, a=g^x, b=g^y$, find $z= g^{xy}$.\r\n{\\bf DDH: } Given $g \\in G, a=g^x, b=g^y, c=g^z$, determine if $z=xy$.  $DDH \\le DHP \\le DLP$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } $FACTOR \\le SQRT \\le FACTOR$.  \r\nIf the RSA problem is hard, then RSA is secure under a chosen plaintext attack.  If DHP\r\nis hard, El Gamal is secure under a chosen plaintext attack.\r\n\\\\\r\n\\\\\r\n{\\bf Finding square roots (mod p): } \r\nSuppose $({\\frac a p})=1$, so that $a$ is a square and let $n$ be a quadratic\r\nnon-residue  $\\jmod{p}$.  Want to find $x$:\r\n$x^2= a \\jmod{p}$.  Set $p-1= 2^{e}q$ and put $b=n^q \\jmod{p}$\r\nIf $p= 3 \\jmod{4}$, $x= a^{\\frac {(p+1)} {4 }} \\jmod{p}$.\r\nIf $p= 5 \\jmod{8}$, let\r\n$b=a^{\\frac {(p-1)}{4}} = \\pm 1\\jmod {p}$, then\r\nif $b=1, x= a^{\\frac {(p+3)} {8}} \\jmod {p}$, otherwise,\r\nif $b= -1, x= (2a)(4a)^{\\frac {(p-5)} {8}} \\jmod{p}$.\r\nThis leaves the hard case, $p=1 \\jmod{8)}$.  The algorithm of \\emph {Tonelli\r\nand Shanks} solves this case (and the others).\r\nWe want $x: x^2= a \\jmod {p}$.  Put\r\n$p-1=2^e  q$, $q$, odd.\r\nChoose $n$: $({\\frac n p})= -1$; note $n$ is a generator\r\nfor the multiplicative group. Set $z= n^q \\jmod {p}$ and $b= a^q$.  Since $b^{2^{e-1}}= 1$,\r\n$b$ is a quadratic residue and $b= z^{2k}$ or $bz^{k'}=1$.  Put $x= a^{\\frac {q+1} 2} z^{{\\frac {k'} 2}}$\r\nthen $x^2 = a \\jmod{p}$.\r\n\\\\\r\nThe algorithm:\\\\\r\n\r\n$Q= {\\frac {(q-1)} 2}$, $z = n^q$,\r\n$y=z$, $r=e$,  $x=a^Q \\jmod{p}$, $b=ax^2 \\jmod{p}$ and  $x= ax \\jmod{p}$.\r\n$x= a^{\\frac {q+1} 2} z^{\\frac {k'} 2}$ will satisfy $a= x^2$ where $z^k=1$.\r\nNow set $R=2^{r-1}, ab=x^2, y^R= -1, b^R=1$.  Do the following:\r\n\\\\\r\n\\jt loop: \\\\\r\n\\jt\\jt  if($b=1$) \\\\\r\n\\jt\\jt\\jt   return($x$); \\\\\r\n\\jt\\jt  Let $M=2^m$. For smallest $m>0: b^M= 1 \\jmod{p}$\\\\\r\n\\jt\\jt  if($m=r$) \\\\\r\n\\jt \\jt \\jt return(non-residue);\\\\\r\n\\jt \\jt $t= y^{2^{r-m-1}} \\jmod{p}$;\\\\\r\n\\jt \\jt $y= t^2 \\jmod{p}$; \\\\\r\n\\jt \\jt $r=m;$ \\\\\r\n\\jt \\jt $x=xt;$ \\\\\r\n\\jt \\jt $b=by;$ \\\\\r\n\\jt \\jt goto loop;\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } Factoring $n$ may be equivalent to computing $\\phi(n)$ which is equivalent to\r\nfinding $d$.\\\\\r\n\\\\\r\n{\\bf Definitions: }\r\n\\emph{Strong primes: }\r\n$p-1$ has a large prime factor $r$,\r\n$p+1$ has a large prime factor $a$,\r\n$r-1$ has a large prime factor $t$.\r\n\\emph{Miller-Rabin} has error probability $p= {\\frac 1 4}$ as the following shows.\r\n\\\\\r\n\\\\\r\n{\\bf Definition: } A composite number $n$ is a Carmichael number if $\\forall a <n: (a,n) = 1$\r\nwe have $a^{n-1} = 1 \\jmod{n}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } $n \\ge 3$ is a Carmichael number iff $n$ is square-free and $(p-1) \\mid (n-1), \\forall p | n$.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nLet $(a, n) = 1$.\\\\\r\n$\\rightarrow$: Suppose $n$ is a Carmichael number. $a^{p-1} = 1 \\jmod{p}$ so $a^{p-1} = 1 \\jmod{n}$\r\nand $(p-1) \\mid (n-1)$.  If $n$ is not square free, $p^k (p-1) \\mid \\phi(n)$ so,\r\nfor some $a$, $a^p = 1 \\jmod{n}$ but $a^{p-1} = 1 \\jmod{n}$.  Contradiction.\r\n\\\\\r\n$\\leftarrow$: \r\nSuppose $n$ is square-free and $(p-1) \\mid (n-1), \\forall p \\mid n$. $a^{p-1} = 1 \\jmod{p}$.\r\nSo $a^{n-1} = 1 \\jmod{n}$.\r\n\\end{quote}\r\n{\\bf Theorem: } If $n \\ge 3$ is a Carmichael number, $n$ is divisible by three or more primes.\r\n\\begin{quote}\r\n\\emph{Proof: } Suppose $n = pq$.  \r\n$(p-1) \\mid (pq - 1)$ and\r\n$(q-1) \\mid (pq - 1)$. $(p-1)a = pq -1 = pq - q + q-1 = q(p-1) + q-1$ so $(p-1) \\mid (q-1)$.\r\nThus $2(p-1) \\geq (q-1)$.  Similarly\r\n$2(q-1) \\geq (p-1)$.  This is a contradiction.\r\n\\end{quote}\r\n{\\bf Theorem: } If $n$ is prime, $n-1 = 2^sd$ $\\forall a < n$, then either\r\n$a^d =1 \\jmod{n}$ or $a^{2^rd}$ for some $r < s$.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nFor any $a: (a,n) = 1$, $a^{2^sd} = 1 \\jmod{n}$ and the result follows.\r\n\\end{quote}\r\n{\\bf Theorem: } If $n \\ge 3$ is composite then $S= \\{x: 1 \\leq x < n \\}$ has at most\r\n${\\frac {n-1} 4}$ non-witnesses.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nIf there are no non-witnesses, the result holds.  Let $a$ be a non-witness,\r\n$a^{d} = 1 \\jmod{n}$ or $a^{2^rd} = -1 \\jmod{n}$ for some $r < s$.  In fact,\r\nwe can assume $a^{2^rd} = -1 \\jmod{n}$ because $a^{d} = 1 \\jmod{n}$ implies\r\n$(-a)^{d} = -1 \\jmod{n}$.  Let $k$ be the largest $k: a^{2^kd} = -1 \\jmod{n}$.\r\nPut $n = \\prod_{p \\mid n} p^{e_p}$ and $m = 2^kd$.  Define\r\n$J= \\{a, a < n, (a,n)=1, a^{n-1} = 1 \\jmod{n} \\}$,\r\n$K= \\{a, a < n, (a,n)=1, a^{n-1} = \\pm 1 \\jmod{p^{e_p}} \\}$,\r\n$L= \\{a, a < n, (a,n)=1, a^{m} = \\pm 1 \\jmod{n} \\}$, and\r\n$M= \\{a, a < n, (a,n)=1, a^{m} = 1 \\jmod{n} \\}$.\r\nThus $ M \\subseteq L \\subseteq K \\subseteq J\\subseteq ({\\mathbb Z} / (n{\\mathbb Z}))^*$.\r\nIf $a$ is a non-witness, $a \\in L$.  $[K:M] = 2^{\\alpha}$ since $x \\in K \\rightarrow x^2 \\in M$.\r\nSo $[K:L] = 2^j$.  If $j \\geq 2$, we're done.\r\nIf $j=1$, $n=pq$ and $n$ is not a Carmichael number, so $[({\\mathbb Z} / (n{\\mathbb Z}))^* : K] \\geq 1$.\r\n$[K:L] =2$ so $[({\\mathbb Z} / (n{\\mathbb Z}))^* : L] \\geq 4$ and we're done.\r\nIf $j=1$, $n=p^e, e>1$ so $p(p-1) \\mid \\phi(n)$ and $[({\\mathbb Z} / (n{\\mathbb Z}))^* : J] \\geq p$.\r\nIf $p^e \\geq 4$, were done.  The only remaining case is $n = 9$.  The theorem holds for this case as well.\r\n\\end{quote}\r\n{\\bf El Gamal Crypto: }\r\nFor the \\emph{El Gamal encryption system}, let $g$ be a generator of $F_{q}^*$.  \r\nA picks $a$ at random,\r\nthis is A's secret.  User picks $k$ at random and sends $(g^{k}, Pg^{ka})$.\r\nAn \\emph{El Gamal Signature} is generated as follows: $g$ is a primitive element\r\n${\\mathbb Z}_{p}^{*}$. $(p, g , y=g^x )$ are public, $x$ is secret.  To sign\r\n$m$, pick $k$: $1 \\leq k \\leq p-2$ with $(k, p-1)= 1$.\r\n$sig_K (m, k) =(r, s)$, $r=g^k$, $s= k^{-1}(m-xr)$.\r\n$ver_k (m, r, s)$ is true iff $y^{r}r^{s}==g^m$.\r\nNote: $k$ must be different for each signature and $m$ must be a hash.\r\n\\emph{Recommended parameters:} $>768$ bits.\r\nThere is an existential forgery if hash isn't used in El Gamal.\r\nFor key elements, $(\\langle {\\mathbb Z}_p \\rangle, g, a)$, pick \r\n$(u, v)$, $r= g^u g^v = g^{u+av}$.\r\n$s= -rv^{-1} \\jmod{p-1}$, $M=su$.  Note that $t=r^s y^r=g^{su}$.\r\n\\\\\r\n\\\\\r\n{\\bf Diffie Hellman Key Exchange: }\r\nThe \\emph{Diffie Hellman} key exchange scheme works as follows: Let $g$ be a generator of $F_{q}^*$.\r\nA generates $a \\in F_{q}^*$ at random and transmits $g^{a}$,\r\nB generates $b \\in F_{q}^*$ at random\r\nand transmits $g^{a}$,  they use $g^{ab}$ as key.\r\n\\\\\r\n\\\\\r\n{\\bf Blinding and E-cash: } Let $M$ be a note or check.  To blind, generate random\r\n$k$.  Let $(e, d, n)$ be the bank's key and $H$, a hash.  Send bank $r=H(M)k^e$.\r\nBank sends back $r^d$, now multiply by $k^{-1}$.  For fraud resistant\r\nprotocol,\r\ndo this for a bunch of $k_s$'s.  Bank signs one of them.  \r\n\\\\\r\n\\\\\r\n{\\bf DSA: } Pick $p, q$, $2^{159}<q<2^{160}$, $2^{511+64t} < p < 2^{512+64t}$, $0 \\le t \\le 8$ with\r\n$q|(p-1)$.  \r\nLet $x$ be a primitive root $\\jmod{p}$.  Set $g= x^{{\\frac {p-1} q}}>1 \\jmod{q}$. \r\nFinally,\r\npick $a$ at random and set  $A= g^a \\jmod{p}$.\r\n$p, q, g, A$ are public, $a$ is secret.  To sign $M$:\r\ngenerate random $k: k<q$.  Set $r= g^k \\jmod{q}$ and compute\r\n$s= k^{-1} (h(M) + xr) \\jmod{q}$, where $h$ is a cryptographic hash.  \r\n\\emph{Signature} is $(r, s)$.\r\n\\emph{To verify:}\r\n$u_1= s^{-1} h(M) \\jmod{q}$,\r\n$u_2= s^{-1} r \\jmod{q}$,\r\n$v= g^{u_1} g^{u_2} \\jmod{p} \\jmod{q}$.  If $v=r$, it\r\nverifies.  Unlike El Gamal signature, $s$ does not carry full information about\r\n$p$ (only $\\jmod{q}$) and since $q$ is large, the Pohlig-Hellman attack is harder.\r\n\\\\\r\n\\\\\r\n{\\bf Montgomery Arithmetic: }\r\nSuppose $(R, n)=1$; think of $R= 2^r$, $n < 2^r$.\r\n$R R' - n n' = 1$ (i.e.- $n'= -n^{-1} \\jmod{R}$). \\\\\r\n\\emph{Theorem: }  If $0 \\leq t < nR$ and $u=tn' \\jmod{R}$ then\r\n$R \\mid (t+un)$ and for $x= {\\frac {(t+un)} R}$, $x= t R^{-1} \\jmod{n}$ and\r\n$0 \\leq x < 2n$.\\\\\r\n\\\\\r\n${\\overline a}= a r \\jmod{n}$.\r\n$r r' - n n' = 1$. \\\\\r\n\\jt MontPro(${\\overline a}, {\\overline b}$) \\\\\r\n\\jt \\jt $t= {\\overline a} {\\overline b}$; \\\\\r\n\\jt \\jt $u= tn' \\jmod{R}$; \\\\\r\n\\jt \\jt $x= {\\frac {un+t} R}$; \\\\\r\n\\jt \\jt if($x>n$)  \\\\\r\n\\jt \\jt \\jt $x-=n$; \\\\\r\n\\jt \\jt return($x$); \\\\\r\n\\\\\r\n\\jt MontMult($a,b,n$): Compute $n'$ ;\\\\\r\n\\jt \\jt ${\\overline a}= a r \\jmod{n}$;\\\\\r\n\\jt \\jt ${\\overline b}= b r \\jmod{n}$;\\\\\r\n\\jt \\jt ${\\overline x}= MontPro({\\overline a}, {\\overline b})$;\\\\\r\n\\jt \\jt $x= MontPro({\\overline x}, 1)$;\\\\\r\n\\jt \\jt return($x$).\r\n\\\\\r\n\\\\\r\n{\\bf NAF: } Let $k= \\sum_{j=0}^l s_j 2^j, s_j \\in \\{0, 1\\}$. NAF form is\r\n$k= \\sum_{j=0}^{l+1} c_j 2^j, c_j \\in \\{-1, 0, 1\\}$, conversion is achieved\r\nby following algorithm:\\\\\r\n\\jt $c_0 =0;$\\\\\r\n\\jt $for(j=0; j \\le l; j++) \\{$\\\\\r\n\\jt \\jt $c_{j+1}= \\lfloor (k_j + k_{j+1} +c_j) /2 \\rfloor;$ \\\\\r\n\\jt \\jt $s_{j}= k_j + c_j -2 c_{j+1}; \\\\\r\n\\jt \\}$\r\n\\\\\r\n\\\\\r\n{\\bf AMD-64 3Ghz dual core timings: }\r\n\\begin{center}\r\n\\begin{tabular} {|l|rrr||l|rrr|}\r\n\\hline\r\n{\\bf Algorithm} & {\\bf KSize} & {\\bf T($\\mu$-sec)} & {\\bf Cycles} &\r\n{\\bf Algorithm} & {\\bf KSize} & {\\bf T($\\mu$-sec)} & {\\bf Cycles} \\\\\r\n\\hline\r\nECDSA-SIGN & 256 & 4942 & 14,827,000 &\r\nECDSA-VERIFY & 256 & 9,848 & 29,546,000 \\\\\r\nECDSA-SIGN & 384 & 13,000 & 38,860,000 &\r\nECDSA-VERIFY & 384 & 25,900 & 77,639,000 \\\\\r\nECDSA-SIGN & 521 & 29,500 & 88,287,000 &\r\nECDSA-VERIFY & 521 & 58,900 & 176,524,000 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|l|rrr||l|rrr|}\r\n\\hline\r\n{\\bf Algorithm} & {\\bf KeySize} & {\\bf T($\\mu$-sec)} & {\\bf Cycles} &\r\n{\\bf Algorithm} & {\\bf KeySize} & {\\bf T($\\mu$-sec)} & {\\bf Cycles} \\\\\r\n\\hline\r\nDSA-SIG & 512 & 1,077 & 3,233,000 &\r\nDSA-VERIFY & 512 & 2,142 & 6,427,000 \\\\\r\nDSA-SIG\t& 768 & 2,332 & 6,999,000 &\r\nDSA-VERIFY & 768 & 4,641 & 13,924,000 \\\\\r\nDSA-SIG\t& 1024\t& 4,027 & 12,083,000 &\r\nDSA-VERIFY\t& 1024 & 8,015 & 24,047,000 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|l|rrr|l|rrr|}\r\n\\hline\r\n{\\bf Algorithm} & {\\bf KeySize} & {\\bf T($\\mu$-sec)} & {\\bf Cycles} &\r\n{\\bf Algorithm} & {\\bf KeySize} & {\\bf T($\\mu$-sec)} & {\\bf Cycles} \\\\\r\n\\hline\r\nRSA-SIGN & 1024 & 3,488 & 10,465,000 &\r\nRSA-VERIFY\t& 1024 & 168 & 505,000 \\\\\r\nRSA-SIGN & 2048 & 22,905 & 68,717,000 &\r\nRSA-VERIFY\t& 2048 & 608 & 1,825,000 \\\\\r\nRSA-SIGN & 3072 & 72,494 & 217,491,000 &\r\nRSA-VERIFY & 3072 & 1,340 & 4,021,000 \\\\\r\nRSA-SIGN & 4096 & 168,548 & 505,664,000 &\r\nRSA-VERIFY & 4096 & 2,363 & 7,091,000 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|rrr||rrr|}\r\n\\hline\r\n{\\bf Algorithm} & {\\bf KeySize} & {\\bf T(sec)} & {\\bf Algorithm} & {\\bf KeySize} & {\\bf T(sec)} \\\\\r\n\\hline\r\nRSA KeyGen & 1024 & .37 & ECC KeyGen & 160 & .0053 \\\\\r\nRSA KeyGen & 2048 & 3.5 & ECC KeyGen & 224 & .0056 \\\\\r\nRSA KeyGen & 3072 & 11.2 & ECC KeyGen & 256 & .0067 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf McEliece Cryptosystem: }  Bob chooses $G$, an $[n,k,d]$ linear code,\r\n$G_1= SGP$ where $P$ is an $n \\times n$ permutation matrix and $S$ is a $k \\times k$\r\ninvertible matrix.  To send a message to Bob, Alice adds an error, $e$, of weight $t$,\r\n$y=xG_1+e$.  To decrypt, (1) compute $y_1= yP^{-1}= xSG+e_1$; (2) apply error\r\ndecode to $y_1$ to get $x_1$; (3) compute $x_0: x_0G= x_1$; (4) compute $x=x_0S^{-1}$.\r\nWant $d$ to be large.  For example, use Goppa code ($n=2^m, d= 2t+1, k= n=mt$): \r\n$m=10, t=50$ to get $[1024, 524, 101]$.\r\n\\\\\r\n\\\\\r\n\\section{Symmetric Key Systems}\r\n{\\bf Modes: }\r\n\\emph{CBC: } $y_0 = IV$, $y_i = E_K (x_i + y_{i-1})$.\r\n\\\\\r\n\\emph{OFB: } $z_0 = IV$, $z_{i+1} = E_K (z_i )$, $y_i = x_i + z_{i}$.\r\n\\\\\r\n\\emph{CFB: } $y_0 = IV$, $z_i = E_K (y_{i-1})$, $y_i = x_i + z_i $.\r\n\\\\\r\n\\emph{CTR: } $z_i = E_K (Nounce||ctr)$, $y_i = x_i \\oplus z_i $.\r\n\\\\\r\n\\emph{HMAC: } $(K,m) \\mapsto h( (K \\oplus a) || h(K \\oplus b) || m)$.\r\n\\\\\r\n\\emph{GCM: } $F=GF(2^{128}), p(x)= 2^{128}+x^7+x^2+x+1$, $(z_0 , y_0)= (IV,0^{128})$,\r\n$(z_1, y_i) \\mapsto (z_{i+1}, y_{i+1})$ by $z_{i+1}= \\pi_i(z_i)$, if $\\pi_i(x)=0$,\r\n$z_i \\oplus y_i$ otherwise and $y_{i+1} = y_i >> 1$ if $LSB(y_i)=0$ otherwise\r\n$y_{i+1}= (y_i>>1) \\oplus R$, $R= [11100001 || 0^{120}$.  \r\nDefine $X \\cdot Y= (z_{128}, y_{128})$.\r\n$inc_s(X)=MSB_{len(X)-s}(X) || [int(LSBs(X))+1 \\jmod {2^s}]_s$.\r\n$GHASH_H(X), len(X)=128m$:\r\n$H = E_K(0^{128})$. $Y_0 = 0^{128}$, $Y_{i+1}= (Y_{i} \\oplus X_{i+1}) \\cdot H$.\r\nreturn $Y_m$.\r\n\\\\\r\n\\emph{GCTR: }\r\n$GCTR_K (ICB, X)$: If $X$ is the empty string, then return the empty string as $Y$.\r\n$n= \\lceil (len(X)/128 \\rceil$.  Let $CB_1 = ICB$, $CB_i= inc_{32}(CB_{i-1}, i= 1 \\ldots n$.\r\n$Y_i= X_i \\oplus E_K(CB_i)$.  ${Y_n}^*= {X_i}^* E_K(CB_i)$.  return $Y$.\r\n\\\\\r\n\\emph{GCM-AES: }\r\n$GCM-AE_K (IV, P, A)$: $H = E_K(0^{128})$.  If $len(IV)=96$, $J_0 = IV || 0^{31} ||1$.\r\nIf $len(IV) \\ne 96$, let $s = 128 \\lceil len(IV)/128 \\rceil-len(IV)$, and let\r\n$J_0=GHASH_H(IV||0^{s+64}||len(IV)^{64})$.\r\n$C=GCTR_K(inc_{32}(J0), P)$.  Let $ n $ Define \r\n$S = GHASH_H (A || 0^v || C || 0^u || len(A)^{64} || len(C)^{64}$).  $T=MSB_t(GCTR_K(J_0,S))$.\r\nreturn $(C, T)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n\\emph{Recurrence for LFSR of length $k$:} $s_j= c_1 s_{j-1} + \\ldots c_k s_{j-k}$.\r\n\\emph{Hamming weight:} $w_H(x)= \\# \\{n: x_n \\ne 0 \\}$.  \r\n\\emph{Modular weight:} $w_M(x)= |x'|$ where \r\n$x'=x \\jmod{2^n}$ and $-2^{n-1} < x' \\le 2^{n-1}$.\r\n\\emph{NAF weight:} $w_{NAF}(x) = \\# \\{ i<n: \\alpha_i \\ne 0 \\}$. \r\n$\\Delta^{\\oplus}(x,y)$, $\\Delta^{+}(x,y)$, $\\Delta^{\\pm}(x,y)$ are the xor, modular and\r\nsigned differences respectively.  \\emph{Distortion for map $\\varphi$:} \r\n$D(\\varphi, d_1, d_2)=\r\nsup_{x\\ne y} {\\frac {d_2(\\varphi(x), \\varphi(y))} {d_1(x,y)}}\r\nsup_{x\\ne y} {\\frac {d_1(x,y)} {d_2(\\varphi(x), \\varphi(y))}}$.\r\n$f(x_1, \\ldots, x_n)$ is \\emph{$m$-correlation immune} if\r\n$I(f(x_1, \\ldots, x_n); x_{i_1}, \\ldots , x_{i_m})=0$ for any choice of the\r\n$i_k$.  This happens when the boolean spectrum of $F(w)$ is $0$ when\r\n$w$ has weight $\\le m$.  \r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nThe \\emph{connection polynomial} for $L_n({\\vec s})$ is\r\n$c(x)= 1 + c_1 x + \\ldots + c_l x^l$ with $c(x)=0$ if $L_n({\\vec s})=0$.  \r\nDefine $d_n$ as\r\n$n$th discrepancy, suppose $m$ is the position of change of length in minimal generating\r\nLFSR. $L_m({\\vec s}) \\le L_n({\\vec s})$ and $L_{m+1}({\\vec s})= L_n({\\vec s})$.  \r\nThe recurrence is\r\n$c^{(n+1)}(x)= c^{(n)}(x) -d_n {d_m}^{-1} x^{n-m} c^{(m)}(x)$.  \r\nThe synthesis algorithm is $O(n^2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} A LFSR of length $k$ has maximal period ($K=2^k-1$) iff its connection \r\npolynomial is \\emph{primitive}.\r\n\\begin{quote}\r\n\\emph{ Proof: }\r\nLet $G(x)= a_0 + a_1 x + a_2 x^2 + \\ldots + a_{m-1} x^{m-1} + \\ldots$,\r\n$a_m= c_1 a_{m-1} + \\ldots + c_m a_1$, etc.  We get a recurrence yielding\r\n${\\frac {K} {1-c(x)}}$, $f(x)= 1-c(x)$.  If sequence is $p$,\r\n$G(x)= \r\n(a_0 + a_1 x + \\ldots + a_{m-1} x^{m-1}) +\r\n(a_0 + a_1 x + \\ldots + a_{m-1} x^{m-1}) x^p + \\ldots =\r\n{\\frac {(a_0 + a_1 x + \\ldots + a_{m-1} x^{m-1})} {1-x^p}} = {\\frac {K} {(f(x))}}$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $M_{j,k}(x)=\r\n\\left(\r\n\\begin{array}{ccccc}\r\nx_{j} & x_{j+1} & x_{j+2} & ... & x_{j+k-1}\\\\\r\nx_{j+1} & x_{j+2} &x_{j+3} & ... & x_{j+k}\\\\\r\n... & ... & ... & ... & ... \\\\\r\nx_{j+k-1} & x_{j+k} &x_{j+k+1} & ... & x_{j+2k-2}\\\\\r\n\\end{array}\r\n\\right)$. \r\nIf $\\langle x_i \\rangle$ is generated by an LFSR of length $N$ but not one shorter then\r\n$det(M_{j,N}(x))=1$ and\r\n$det(M_{j,n}(x))=0, n>N$.  If $x_{n+m}= c_0 x_n + \\ldots + c_{m-1} x_{n+m-1}$ and\r\n$c(x)= x^m +c_{m-1} x^{m-1} + \\ldots + c_0$, the associated connection\r\npolynomial, is irreducible,\r\nthen the sequence repeats at an interval of $k= 2^m -1$.\r\n\\\\\r\n\\\\\r\n{\\bf Massey's Lemma:} If $L_n({\\vec s})$ generates \r\n$\\langle s_0, \\ldots , s_{n-1} \\rangle$ but not\r\n$\\langle s_0, \\ldots , s_{n} \\rangle$ then \r\n$L_{n+1}({\\vec s}) \\ge max(L_n({\\vec s}), n+1-L_n({\\vec s}))$.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose $L$ generates $\\langle s_0 , s_1 , \\ldots , s_{n-1} \\rangle$ but not\r\n$\\langle s_0 , s_1 , \\ldots , s_{n} \\rangle$ and let $L'$ with\r\n$L_{n+1}'({\\vec s})= l'$ then $l' \\ge n+1-l$.  Proof.  If $l \\ge n$,\r\n$l' \\ge 1$ so it's true.  If $l<n$, let $c_i$ be the coefficients of $L$ and\r\n$c_i'$, the coefficients of $L'$.  \r\n$s_j + \\sum_{i=1}^l c_i s_{j-i}=0$ for $j= l, l+1, \\ldots , n-1$ but not for $j=n$ and\r\n$s_j + \\sum_{i=1}^{l'} c_i' s_{j-i}=0$ for $j= l', l'+1, \\ldots , n$  so\r\n$-\\sum_{i=1}^l c_i s_{j-i}= \\sum_{i=1}^l c_i \\sum_{k=1}^{l'} c_k' s_{n-i-k}$\r\nSwitching the\r\norder of summation, the second sum is $s_n$  which is a contradiction.\r\n\\end{quote}\r\n{\\bf Berlekamp-Massey:} Given $s_1 , s_2 , \\ldots , s_{n-1}$\r\noutput linear complexity $L$.\r\n\\begin{enumerate}\r\n\\item $C(x)= 1, L= 0, m=-1, b(x)= 1, n= 0$.\r\n\\item $d= S_n + \\sum_{i=1}^L c_i s_{n-i}$.\r\n\\item If ($d==1$) $t(x)= c(x), c(x)+= b(x)x^{n-m}$)\r\nif($L \\leq {\\frac n 2}$)\r\n$L= n+1-L, m=n, b(x)= t(x)$\r\n\\item $n= n+1$;\r\n\\end{enumerate}\r\n\\begin {multicols} {2} {\r\n\\begin {verbatim}\r\nRC4Init() {\r\n    for (i=0; i<256; i++)\r\n        s[i]= i;\r\n    fill k[] with key repeating \r\n         as necessary;\r\n    j= 0;\r\n    for(i = 0; i<256; i++) {\r\n        j= (k[i]+s[i]+j) (mod 256); \r\n        swap(s[i], s[j]);\r\n        }\r\n    i= 0;\r\n    j= 0;\r\n    }\r\n\r\nbyte Next() {\r\n    i= (i+1) (mod 256);\r\n    j= (j+s[i]) (mod 256);\r\n    swap(s[i], s[j]);\r\n    return(s[(s[i]+s[j]) (mod 256)]);\r\n    }\r\n\\end{verbatim}\r\n}\r\n\\end {multicols}\r\nLet $\\Lambda(s^n)$ be the associated \\emph{linear complexity}\r\nof the sequence $\\langle s_i \\rangle$ of\r\nlength $n$ and $N_n(L)$ be the number of sequences of length $n$ with linear complexity $L$,\r\nthen $N_n(L) = 2 N_{n-1}(L) + N_{n-1}(n-L)$, if $n \\ge L > {\\frac n 2}$;\r\n$N_n(L) = 2 N_{n-1}(L)$, if $L = {\\frac n 2}$; and,\r\n$N_n(L) = N_{n-1}(L)$, if ${\\frac n 2} \\ge L \\ge 0$. So\r\n$N_n(L)= 2^{min(2n-2L, 2L-1)}$, if $n \\ge L >0$,\r\n$N_n(L)= 1$, if $n \\ge L = 0$.  \r\n$E(\\lambda(s^n))= {\\frac n 2} + {\\frac {4+R_2(n)} {18}}- 2^{-n}({\\frac n 3} + {\\frac 2 9})$,\r\n$Var(\\Lambda(s^n))= {\\frac {86} {81}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Shrinking Generator:}  Take two LFSR: $LFSR_1$ and $LFSR_2$\r\nsynchronously clocked.  Use $LFSR_2(t)$ in stream when $LFSR_1(t)=1$.\r\nTake $LFSR_i(t)= x_i(t)$ for $i=1,2, \\ldots , n$\r\nuse $f(x_1(t), x_2(t) , \\ldots , x_n(t))$ where $f$ is non linear.  For $k$ stage\r\nshift register design, where stage $i$ has $n_i$ bits of state, keysearch takes\r\n$2^{n_0 + n+1 + \\ldots + n_{k-1}}$ while correlation attack takes\r\n$2^{n_0} + 2^{n+1} + \\ldots + 2^{n_{k-1}}$.\r\n\\emph{Example:}\r\nThe Geffe combiner is\r\n$f(x,y,z)= xy \\oplus yz \\oplus z$, $f(x,y,z)=x$ with $p={\\frac 3 4}$. \r\n\\\\\r\n\\\\\r\n{\\bf ANSI 9.17 random stream generator:}\r\n$I=E_k(D)$.\r\n$x_i= E_k(I \\otimes s)$ and\r\n$s= E_k(x_i \\otimes s)$.\r\n\\\\\r\n\\\\\r\n{\\bf FIPS 186 One Way Function (OWF):} $t$, $c$ 160 bits.  Output $G(t,c)$ where\r\n$t= H_1 || H_2 \\ldots || H_5$.  Pad $c$ with $0$s to get 512 bit\r\nblock $X$.  Break $X$ into 16 32 bits words $x_0, \\ldots, x_{15}$ and\r\nset $m= 1$, apply iterative step of SHA-1.\r\n\r\n\\begin{multicols} {2} {\r\n\r\n\\begin{verbatim}\r\nDual Elliptic Curve RNG\r\n  s[0] in [0,1, ..., #E-1]\r\n  output 240 bits\r\n  for(i=1 to k {\r\n    s[i]= x(s[i-1]P);\r\n    r[i]= lsb[240] x(s[i]Q);\r\n    }\r\n  return(r[1] ... r[k]);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{verbatim}\r\n// State for Hash_DRBG\r\n  V\t// seedlen bits\r\n  C\t// seedlen bits\r\n  reseedCtr \r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nHash_DRBG_Instantiate(entBitsIn, nonce, \r\n                      extraEnt)\r\n  seedBits= entBitsIn||nonce||extraEnt;\r\n  seed= Hash_df(seedBits, seedlen);\r\n  V= seed;\r\n  C= Hash_df((0x00||V), seedlen);\r\n  reseedCtr= 1;\r\n  return;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nHash_DRBG_Reseed(entBitsIn, addInBits)\r\n  seedBits= 0x01||V||entBitsIn||addInBits;\r\n  seed= Hash_df(seedBits, seedlen);\r\n  V= seed;\r\n  C= Hash_df((0x00||V), seedlen);\r\n  reseedCtr= 1;\r\n  return;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nHash_DRBG_Generate(numReqBits, addInBits)\r\n  if(reseedCtr>reseedInterval) then \r\n       Reseed;\r\n  if(addInBits!=NULL)\r\n     w= Hash(0x02||V||addInBits);\r\n     V=(V+w) mod 2**seedlen;\r\n  returnedBits= Hashgen(numReqBits, V);\r\n  H= Hash(0x03||V);\r\n  V=(V+H+C+reseedCtr) mod 2**seedlen;\r\n  reseedCtr= reseedCtr+1;\r\n  return returnedBits;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nHashgen(numReqBits, V)\r\n  m= reqNumBits/outlen;\r\n  data= V;\r\n  W= NULL;\r\n  for i= 1 to m\r\n    w= Hash(data);\r\n    W= W||w;\r\n    data= (data+1) mod 2**seedlen;\r\n  returnedBits= Leftmost numReqBits\r\n                  bits of W;\r\n  return returnedBits;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nHash_df(inBits, numRetBits):\r\n  temp= NULL;\r\n  m= numRetBits/outlen;\r\n  counter= 8-bit representation of 1;\r\n  for i= 1 to len do\r\n    temp= temp|| Hash(counter||\r\n            numRetBits||inBits);\r\n    counter= counter+1;\r\n  reqBits= Leftmost numRetBits of temp;\r\n  return reqBits;\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{verbatim}\r\n// State for CTR_DRBG\r\n    V\t// outlen bits\r\n    C\t// keylen bits\r\n    reseedCtr \r\n    nStrength\r\n    fPrediction\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nCTR_DRBG_Update(provided_data, Key, V):\r\n  temp= NULL;\r\n  while(len(temp)<seedlen) do\r\n    V=(V+1) mod 2**outlen;\r\n    outBits= blockEncrypt(Key, V);\r\n    temp= temp||ouput_block;\r\n  temp= Leftmost seedlen bits of temp;\r\n  temp= temp^provided_data;\r\n  Key= Leftmost keylen bits of temp;\r\n  V= Rightmost outlen bits of temp;\r\n  return Key and V;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\n// Full Entropy\r\nCTR_DRBG_Instantiate(entBitsIn, extraEnt):\r\n  // Ensure that the length of \r\n  // extraEnt is seedlen bits. \r\n  temp= len(extraEnt);\r\n  if(temp<seedlen))\r\n    extraEnt= extraEnt||\r\n                [seedlen-temp] bits of 0;\r\n  seedBits= entBitsIn^extraEnt;\r\n  Key= [keylen] bits of 0;\r\n  V= [outlen] bits of 0;\r\n  (Key, V)= Update (seedBits, Key, V);\r\n  reseedCtr= 1;\r\n  return;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\n// Derivation function required\r\nCTR_DRBG_Instantiate(entBitsIn, extraEnt):\r\n  seedBits= entBitsIn||nonce||extraEnt;\r\n  seedBits= Block_Cipher_df(seedBits, seedlen);\r\n  Key= 0 of[keylen];\r\n  V= 0 of[outlen];\r\n  (Key, V)= Update (seedBits, Key, V);\r\n  reseedCtr= 1;\r\n  return;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\n// Full entropy\r\nCTR_DRBG_Reseed(entBitsIn, addInBits):\r\n  temp= len(addInBits);\r\n  if(temp<seedlen), then \r\n      addInBits= addInBits||\r\n           [seedlen-temp] bits of 0;\r\n  seedBits= entBitsIn^addInBits.;\r\n  (Key, V)= Update (seedBits, Key, V);\r\n  reseedCtr= 1;\r\n  return;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\n// Derivation Function Required\r\nCTR_DRBG_Reseed(entBitsIn, addInBits):\r\n  seedBits= entBitsIn||addInBits;\r\n  seedBits= Block_Cipher_df(seedBits,\r\n                            seedlen);\r\n  (Key, V)= Update (seedBits, Key, V);\r\n  reseedCtr= 1;\r\n  return;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nCTR_DRBG_Generate(numReqBits, addInBits):\r\n    if reseedCtr>reseedInterval, then \r\n            reseed;\r\n    if(addInBits!=NULL)\r\n        temp= len(addInBits);\r\n    if(temp<seedlen))\r\n        addInBits= addInBits||\r\n                 [seedlen-temp] bits of 0;\r\n        (Key, V)= Update (addInBits, Key, V);\r\n    else \r\n      addInBits= [seedlen] bits of 0;\r\n   temp= NULL;\r\n   while(len(temp)<numReqBits) do:\r\n     V=(V+1) mod 2**outlen;\r\n     outBits= blockEncrypt(Key, V);\r\n     temp= temp||outBits;\r\n   returnedBits= Leftmost numReqBits of temp;\r\n   // Update for backtracking resistance.\r\n   (Key, V)= Update(addInBits, Key, V);\r\n   reseedCtr= reseedCtr+1;\r\n   return returnedBits; \r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nBCC(Key, data):\r\n  CV= [outlen] bits of 0;\r\n  n= len(data)/outlen;\r\n  Split the data into n blocks of outlen bits \r\n       forming block[1] to block[n];\r\n  for i= 1 to n do\r\n    inBlock= CV^block[i];\r\n    CV= blockEncrypt(Key,inBlock);\r\n  outBits= CV;\r\n  Return outBits;\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nBlock_Cipher_df(numRetBits, inBits)\r\n  if(numRetBits>maxNumBits), then \r\n    return ERROR;\r\n  L= len(inBits)/8;\r\n  N= numRetBits/8;\r\n  S= L||N||inBits||0x80;\r\n  // Pad S with zeros, if necessary.\r\n  while(len(S) mod outlen) != 0\r\n       S= S||0x00;\r\n  temp= NULL;\r\n  i= 0;\r\n  K= Leftmost keylen bits \r\n         of 0x00010203...1D1E1F.\r\n  while len(temp)<keylen+outlen)\r\n    IV= i||[outlen-len(i)] bits of 0;\r\n    temp= temp||BCC(K,(IV||S));\r\n    i= i+1;\r\n  K= Leftmost keylen bits of temp;\r\n  X= Next outlen bits of temp;\r\n  temp= NULL;\r\n  while len(temp)<numRetBits\r\n    X= blockEncrypt(K, X);\r\n    temp= temp||X;\r\n  reqBits= Leftmost numRetBits of temp;\r\n  return reqBits;\r\n\\end{verbatim}\r\nMGF property:  Given no input and partial output, remaining output is unpredictable.\r\n\\begin{verbatim}\r\nmgf1(mSeed, nLen)\r\n1. if (mLen>2^32), return error\r\n2. T= ||;\r\n3. uL= ceiling(mLen/hLen), \r\n   // hLen is length of hash used\r\n4. for(c=0; c<uL;c++)\r\n       T= t|| h(mSeed || c);\r\n5. output leading bits\r\n\\end{verbatim}\r\n\\begin{verbatim}\r\nPSS-Encode(M, emBits, salt, sLen)\r\n// M- message\r\n// emBits- bits of EM >= 8 hLen + 8 sLen + 9\r\n1. emLen= ceil(enBits/8);\r\n2. if (l(M)> largest message), return error;\r\n3. mH= h(M)\r\n4. if( emLen < hLen+sLen+2 ), return error;\r\n5. M'= (0x00)^8 || mH || salt\r\n6. H= h(M');\r\n7. DB= (0x00)^(emLen-hLen-sLen-2) \r\n       || 0x01 || salt\r\n8. dbMask= mgf(H, emLen-hLen-1);\r\n9. maskedDB= DB^dbMask;\r\n10. Clear leftmost 8*emLen-emBits in maskedDB\r\n11. EM= maskedDB || H || 0xbc\r\n12. return EM;\r\n\\end{verbatim}\r\n\\begin{verbatim}\r\nemsa-pkcs(M, emLen)\r\n// emLen= l(EM)>= tLen+11\r\n1. H= h(M)\r\n2. T= hash-prefix || H ;  // tLen= l(T)\r\n3. EM= 0x00 || 0x01 || (0xff)^(emLen-tLen-3) || T;\r\n4. return EM;\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\r\n{\\bf Blum-Blum-Shub:}\r\nSelect $p, q$ each $= 3 \\jmod{4}$,\r\n$n=pq$, $s \\in [1, n-1]$-seed, $(s,n)=1$ \r\n$x_0 = s^2 \\jmod{n}$ for(i=1 to l) { $x_i = x_{i-1}^2 \\jmod{n}$ $z_i = LSB(x_i)$ }.\r\nNext bit test: Given $l$ bits, no polynomial time algorithm can predict\r\nthe $l+1$st with probability $> {\\frac 1 2}+\\epsilon$.\r\n\\begin{verbatim}\r\nRC6 input: A,B,C,D, r rounds, w-bit round keys in S[0...2r+3].\r\n\\end{verbatim}\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nRC6() {\r\n    B= B+S[0];\r\n    D= D+S[1];\r\n    for(i=1;i<=r;i++) {\r\n        t= (B*(2B+1)) <<< lg(w);\r\n        u= (D*(2D+1)) <<< lg(w);\r\n        A= ((A^t)<<<u)+S[2i];\r\n        C= ((C^u)<<t)+S[2i+1];\r\n        (A, B, C, D) = (B,C,D,A);\r\n        }\r\n    A= A+S[2r+2];\r\n    C= C+S[2r+3];\r\n    }\r\n\r\n\r\n// Key L[0 to k-1];\r\nRoundKeys(L,S,k) {\r\n    S[0]= 0xB7E15163al Elliptic Curve RNG\r\n    s[0] in [0,1, ..., #E-1]\r\n    output 240 bits\r\n    for(i=1 to k {\r\n        s[i]= x(s[i-1]P);\r\n        r[i]= lsb[240] x(s[i]Q);\r\n        }\r\n    return(r[1] ... r[k]);\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n{\\bf OAEP:} Want to send $m$.  Let $\\rho(r)$ be a pseudo random number\r\ngenerator initialized\r\nwith seed $r$.  Calculate $a= \\rho(r) \\oplus m$, $b= r \\oplus H(a)$.\r\nSend $E(a || b)$.\r\n\\\\\r\n\\\\\r\n{\\bf Traitor tracing:}\r\n$y= \\Pi_{i=1}^{2k}  {h_i}^{\\delta_i}$.  $\\delta$ is the representation\r\nvector\r\nwith respect to the base $h$.  Convex combinations of representations are\r\nalso solutions.  Generate $l \\geq 2k+2$ private keys with security parameter\r\n$s$\r\nto defend against coalition of size $k$.  Choose $g$, a generator of $G_q$,\r\n$r_i$, $i= 1,2, \\ldots, 2k$ at random with $h_i = g^{r_i}$.  Public key is\r\n$\\langle y, h_1, h_2 , \\ldots , h_{2k} \\rangle$ where\r\n$y= \\Pi_{i=1}^{2k}  {h_i}^{\\alpha_i}$.  Private key is $\\theta_i$ with\r\n$\\theta_i \\gamma^{(i)}$ a representation of $y$. $\\Gamma = \\{ \\gamma^{(1)} ,\r\n\\gamma^{(2)} ,\\ldots, \\gamma^{(l)} \\}$ are public. Each\r\n${\\gamma}^{(i)}= \\sum_{j} \\gamma_{j}$ is a  codeword.\r\n$\\theta_i ={\\frac\r\n{\\sum_{j=1}^{2k} r_j \\alpha_j }  {\\sum_{j=1}^{2k} r_j \\gamma_j}} $.\r\n\\emph{Encrypt:} pick $a$ randomly $C= \\langle My^a , {h_1}^a , \\ldots , (h_{2k})^a \\rangle$.\r\nTo decrypt\r\n$C= \\langle C, {H_1}, \\ldots , {H_{2k}} \\rangle$, compute $M= {\\frac {S} {U^{\\theta_i}}}$\r\nwhere $U= \\Pi_{i=1}^{2k}  {H_i}^{\\gamma_i}$.   \r\n\\emph{Tracing:} Assume $q> max(l,\r\n2k)$\r\nexamine $l-2k-1 \\times 2k$ matrix $A$\r\n$$\r\nA=\r\n\\left(\r\n\\begin{array}{ccccc}\r\n1 & 1 &  1 &  ... &  1\\\\\r\n1 &  2 &  3 &  ... &  l\\\\\r\n1^2 &  2^2 &  3^2 &  ... &  l^2\\\\\r\n... &  ... &  ... &  ... & ...\\\\\r\n1^{l-2k-1} & 2^{l-2k-1} & 3^{l-2k-1} & ...   &l^{l-2k-1}\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nRowspace $\\leftrightarrow$ polynomials of degree $\\leq l-2k-1$.  Let $B$\r\nbe formed by the column vectors $b_1 , b_2 , \\ldots , b_{2k}$,\r\nthe basis of vectors satisfying $AX=0 (q)$.\r\n$\\exists w$ of Hamming wt $\\leq k$ with $vB=d$, null space of B\r\n$\\leftrightarrow f$ with $deg(f)\\leq l-2k-1$ and $v-w= \\langle f(1), f(2), \\ldots\r\nf(l) \\rangle$ in all but (at most) $k$ places.  Use Berlekamp to find $f$ from $v$.\r\n\\section{Public Key Analysis}\r\n\\emph{Define} $L_n[u,v]= e^{vln(n)^u ln(ln(n))^{1-u}}$.  $L_n[0,v]$ is polynomial and\r\n$L_n[1,v]$ is exponential.  \r\nECM is $L_n[{\\frac 1 2}, 1+o(1)]$.\r\nQS is $L_n[{\\frac 1 2}, 1]$.\r\nNFS is $L_n[{\\frac 1 3}, {\\frac {64} 9}^{1/3}]$.\r\nProbabilistic primality testing is polynomial.\r\n\\\\\r\n\\\\\r\n{\\bf Solovay-Strassen:} Choose $1 \\leq a \\leq (n-1)$.  If\r\n$({\\frac a n}) = a^{\\frac {n-1} 2} \\jmod{n}$ then $n$ is prime\r\nwith probability ${\\frac 1 2}$.  Use the following to compute\r\n$({\\frac a n})$:\r\n(1) $({\\frac {m_1 m_2} n})= ({\\frac {m_1} n}) ({\\frac {m_2} n})$,\r\n(2) $({\\frac {m} n})= -({\\frac n m})$, if $m=n=1, 3\r\n\\jmod{4}$, $({\\frac {m} n})= ({\\frac n m})$, otherwise,\r\n(3) $({\\frac {2} n})= -1$, if $n= 1,7 \\jmod{8}$, $1$, if\r\n$n= 3,5 \\jmod{8}$,\r\n(4) $({\\frac {2^k t} n})= ({\\frac 2 n})^k ({\\frac {t} n})$.\r\n\\\\\r\n\\\\\r\n{\\bf Pockington:}\r\nLet $n>1$ and $s \\mid (n-1)$.  Suppose for some $a$, (1)\r\n$a^{\\frac {n-1} 2}=1 \\jmod{n}$, and (2)\r\n$\\forall q, q|s$, $(\r\na^{\\frac {n-1} q}-1, n)= 1$.  Then $p \\mid n$.  So if\r\n$s> {\\sqrt n}$, $n$ is prime.\r\n\\\\\r\n\\\\\r\n{\\bf Pollard $p-1$:}  Extract prime factor $p$ of $n$ where $p-1$ is $B$ smooth. \r\n$Q= \\prod_{q|B} q^{ \\lfloor \\frac {ln(n)} {ln(q)} \\rfloor}$, where $q$ is prime. \r\nNote $Q \\mid p-1$.  Now pick $a$, compute $gcd( a^Q - 1 , n) = d$.\r\n\\\\\r\n\\\\\r\n{\\bf Pollard-$\\rho$ and Floyd:}\r\nLet $x_{i+1}= f( x_i )$ with $\\lambda$ the length of the tail and $\\mu$ the length of cycle.  \r\nThe \\emph{expected tail length} is $\\sqrt {\\frac {\\pi n} {8}}$ and\r\nthe \\emph{expected cycle length} is $\\sqrt {\\frac {\\pi n} {2}}$.\r\nFloyd started at $(x_0, x_0)$ and computes $(x_i, x_{2i})$ recursively from\r\n$(x_{i-1}, x_{2i-2})$.  $x_m= x_{2m}$ for $\\lambda < m < \\lambda + \\mu$.\r\n\\\\\r\n\\\\\r\n{\\bf Integer factoring with Pollard:} \r\n$n=pq$.  $f(x)= x^2+1 \\jmod{n}$. Let $d= (x_{2m}-x_m,n)$.  This should\r\nfind $p$ or $q$.\r\n\\\\\r\n\\\\\r\n{\\bf Solving discrete log problems:}\r\nFor the discrete log problem, $h= g^x \\jmod{n}$.\r\nLet $S_1, S_2 , S_3$ partition the multiplicative set ${\\mathbb Z}_n^*$, $1 \\notin S_2$\r\nDefine \r\n$x_{i+1}= f(x_i)= h x_i, x_i \\in S_1$,\r\n$x_{i+1}= f(x_i)= x_i^2, x_i \\in S_2$, and\r\n$x_{i+1}= f(x_i)= g x_i, x_i \\in S_3$.  Further, for a triple,\r\n$(x_i , a_i, b_i)$, put\r\n$a_{i+1}=  a_i \\jmod{n}, x_i \\in S_1$,\r\n$a_{i+1}= 2 a_i \\jmod{n}, x_i \\in S_2$, and\r\n$a_{i+1}=  a_i +1 \\jmod{n}, x_i \\in S_3$;\r\n$b_{i+1}=  b_i +1\\jmod{n}, x_i \\in S_1$,\r\n$b_{i+1}= 2 b_i \\jmod{n}, x_i \\in S_2$, and\r\n$b_{i+1}=  b_i \\jmod{n}, x_i \\in S_3$ and consider $3$-tuples $(x_i , a_i , b_i)$ with\r\n$(x_0, a_0, b_0) = (1,0,0)$.  Then $log_g(x_i)= a_i + b_i log_g(h)$ \r\nis an invariant of the sequence.  When \r\n$x_m= x_{2m}$, $a_m + x b_m= a_{2m} + x b_{2m}$ and \r\n$x= -{\\frac {a_{2m}-a_m} {b_{2m}-b_m}} \\jmod{n}$.\r\n\\\\\r\n\\\\\r\n{\\bf Quadratic Sieve:} Want to find $x^2=y^2 \\jmod{n}$, then $(x-y,n)$ or\r\n$(x+y,n)$ is a factor of $n$.  Factor base is \r\n${\\cal B}_B= \\{ -1, 2, 3, \\ldots p_l \\} , p_l \\le B$.\r\nDefine a sequence $b_i= (\\lfloor {\\sqrt {n} \\rfloor +i})$, \r\n$a_i = b_i^2 - n= b_i^2 \\jmod{n}$, $b_i^2 - {a_i}  = n$. \r\nFor the $a_i$'s that factor over the base, find a bunch \r\nusing linear algebra after taking the log.  Then for these $a_{i_l}$'s,\r\n$\\prod a_{i_l} = y^2 \\jmod{n}$, where $y$ is a product of the\r\ncorresponding $b_i$'s.  Sieving finds $B-$smooth elements of sequence.\r\n\\emph{Sieving:}  Fix sieving interval $-C \\le s \\le C$, compute \r\n$f(s)= (s+ \\lfloor {\\sqrt n \\rfloor})^2-n$, find $s: p \\mid f(s)$ - i.e.-\r\nfind roots of $f(x)=0 \\jmod{p}$.  For each $p$ in the base, walk through\r\nsieving interval by steps of $p$ for others.  Divide each $f(s)$ in sieving\r\ninterval by the highest possible dividing power of each $p$, ones with $1$ or $-1$ \r\nremaining are smooth.\r\nWiedemann algorithm for solving sparse linear\r\nequations is $L_n[{\\frac 1 2}, 2v+o(1)]$.  \r\nSieving is $O(L_n[{\\frac 1 2}, v+{\\frac 1 {4v}}+o(1)]/p)$.  \r\n\\emph{Reason:}  Let $\\psi(X,Y)$ be\r\nthe number of $Y-$smooth numbers in $[1,X]$.  $Pr(a \\in [1,X] \\; is \\; Y-smooth)=\r\n{\\frac {\\psi(X,Y)} X}$; expected trials to find one: ${\\frac X {\\psi(X,Y)}}$ need about\r\n$\\pi(Y)$ to get enough for a square and each takes $\\pi(Y)$ work to test, so the total work\r\nis $W(X,Y)= {\\frac {\\pi(Y)^2 X} {{\\psi(X,Y)}}}$.  Minimum occurs when $Y=e^{{\\frac 1 2}\r\n{\\sqrt {ln(X) ln(ln(X))}}}$ and $X \\approx n^{{\\frac 1 2} + \\epsilon}$.\r\nTry $n= 24961, 157$, for example.\r\n\\\\\r\n\\\\\r\n{\\bf Number Field Sieve:} $F= \\{ p: p \\le B \\}$ want to find $a, \\lambda: b= a+ N \\lambda$ and\r\n$b$ is $B$-smooth so $\\prod{p \\in F} p^{a_p} = \\prod_{p \\in F} p^{b_p} \\jmod{N}$.  \r\n\\emph{Procedure:}\r\n(1) Fix $\\lambda$, (2) let the array $A$ have $A+1$ $0$'s, (3) $\\forall p \\in F$,  add\r\n$lg(p)$ to all positions congruent to $- \\lambda N \\jmod{p}$ and \r\n(4) choose $a$ larger than some threshold.\r\nConstruct two monics of degree $d_1, d_2$: $f_1(m) = f_2(m)= 0 \\jmod{N}$ using the\r\nnumber fields \r\n$K_1= {\\mathbb Q}(\\theta_1)$ and\r\n$K_2= {\\mathbb Q}(\\theta_2)$.  \r\nWe have two homomorphisms \r\n$\\phi_i: {\\mathbb Z}[\\theta_i] \\rightarrow {\\mathbb Z}/N{\\mathbb Z}$, \r\nwith $\\theta_1 \\mapsto m$.  Set $S= \\{ (a,b) \\in {\\mathbb Z}^2: (a,b)=1\\}$ satisfying\r\n$\\prod_S (a-b \\theta_1) = \\beta^2$ and $\\prod_S (a-b \\theta_2) = \\gamma^2$.  Then\r\n$\\phi_1(\\beta)^2= \\phi_2(\\gamma)^2 \\jmod{N}$ and $(\\phi_1(\\beta)-\\phi_2(\\gamma)) \\mid N$.\r\nWhat's left is to find $S$, $\\beta^2$, $f_1$ and $f_2$.  An algebraic integer is smooth if the\r\nthe ideal it generates is divisible only by small primes.  \r\nDefine $F_i(X,Y)= Y^{d_i}f_i(X/Y)$ then \r\n$N_{{\\mathbb Q}[\\theta_i]/{\\mathbb Q}}(a-bi)= F_i(a,b)$.\r\nUse two factor bases ${\\cal F}_i= \\{ (p,\\theta_i-r), f_i(r)= 0 \\jmod{p} \\}$.\r\n$F_i(a,b)= \\prod_{(p_j,r) \\in {\\cal F}_i} {p_j}^{s_j^{(i)}}$.  \r\n\\emph{Sieving:}\r\n(1) fix $a$, (2) init sieve array $-B \\le b \\le B$, $S[b]= lg(F_1(a,b) \\cdot F_2(a,b))$,\r\n(3) $\\forall (p,r) \\in {\\cal F}_i$ subtract $lg(p)$ from every element:\r\n$a-rb=0 \\jmod{p}$, (4) the desired $b$'s are the ones: $S[b] \\le Threshhold$.\r\n$\\prod_{(a,b) \\in S} (a-b \\theta_i)= {\\cal I}^2, {\\cal I} \\subseteq {\\mathbb Z}[\\theta_i]$.  \r\nNow find enough relations such that $\\prod_S (a-b \\theta_1)= \\beta^2$, etc.\r\n\\\\\r\n\\\\\r\n\\emph{Example:} $N=290^2+1$, $f_1(x)= x^2+1, f_2(x)=x-m, m=290$.  $f_1(m)=f_2(m)=0 \\jmod{N}$.\r\n\\begin{center}\r\n\\begin{tabular} {|c|c|c|c|c|c|}\r\n\\hline\r\n$x$ & $y$ & $N(x-iy)$ & Factors & $x-my$ & Factors\\\\\r\n\\hline\r\n$-38$ & $-1$ & $1445$ & $5 \\cdot 17^2$ & $252$ & $2^2 \\cdot 3^3 \\cdot 7$\\\\\r\n$-22$ & $-19$ & $845$ & $5 \\cdot 13^2$ & $5488$ & $2^4 \\cdot 7^3$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n$(-31+i)= -(2+i)(4-i)^2$,\r\n$-22 + 19i)= -(2+i) (3-2i)^2$,\r\n$(-38+m)(-22+19m)=2^6 3^2 7^4= 1176^2=(31-12i)^2$.\r\n$\\phi_1(31-12i)=31-12m= -3449$, $(-3449)^2=(1176)^2$.\r\n$(N, -3449+1176)= 2273$, $(N, -3449-1176)=37$.\r\n\\\\\r\n\\\\\r\n{\\bf Sieving analysis:}\r\nLet $\\psi(x,B)$ be the $B-$smooth\r\nnumbers $\\le x$.  Let $\\epsilon >0$; if $x \\ge 10$ and $w \\le (ln(x))^{1-\\epsilon}$,\r\nthen $\\psi(x, x^{\\frac 1 w}) = x w^{-w+f(x,w)}$ and ${\\frac {f(x,w)} w} \\rightarrow 0$\r\nfor $w \\rightarrow \\infty$.  Result: As $n \\rightarrow \\infty$,\r\n$\\psi(n^a , L_n[u,v]) = n^a L_n[1-u, -({\\frac a v})(1-u)]+o(1)$. \r\nFor \\emph{QS} $a \\approx {\\frac 1 2}$.\r\n\\emph{NFS} discrete log is $L_n[{\\frac 1 3}, {\\frac {64} 9}^{\\frac 1 3}]$.\r\n\\emph{MPQF:} $O(e^{({\\sqrt ln(N) ln(ln(N))})})$.  QS and NFS cross at\r\n350 bits.  Results below.  Note: $1 MIP-yr= 3.1 \\times 10^{13}$ instructions.  \r\n$120000 Mip-years= 55 Opteron-2.2GHz-years$.\r\n\\begin{center}\r\n\\begin{tabular} {|c|ccc|}\r\n\\hline\r\n & RSA-129 & RSA-130 & RSA-200 \\\\\r\n\\hline\r\nDate &  4/1996 & 8/1999 & 5/2005 \\\\\r\nTime (MIP-years) & 500 & 8,000 & 120,000 \\\\\r\nRows & $3.5 \\times 10^6$ & $6.7 \\times 10^6$ & $6.4 \\times 10^7$\\\\\r\nNon Zero Members & $1.4 \\times 10^8$ & $4.2 \\times 10^8$ & $1.1 \\times 10^{10}$\\\\\r\nNZ/R & 39 & 62 & 171 \\\\\r\nLinear Algebra (hrs) & 68 & 224 & 2160\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|cccccc|}\r\n\\hline\r\nRSA key & ECC key & Symmetric Key & ArithOps & SieveMem & LAMem\\\\\r\n\\hline\r\n428 & 110 & 51 & $5.5 \\times 10^{17}$ & 2GB & 128MB\\\\\r\n512 & 119 & 56  & $1.7 \\times 10^{19}$ & 64MB & 10GB \\\\\r\n768 & 144 & 69 & $1.1 \\times 10^{23}$ & - & - \\\\\r\n1024 & 163 & 79 & $1.3 \\times 10^{26}$ & 256MB & 100GB\\\\\r\n2048 & 222 & 109 & $1.5 \\times 10^{35}$ & - & -\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Finding discrete logs using\r\nPohlig-Silver:}  Let $g$ be a generator for $F_q^*$.\r\nFind $x$ such that $g^x = y \\jmod{q}$.\r\n$q-1 = {p_1}^{\\alpha_1} \\ldots {p_k}^{\\alpha_k}$.\r\nFirst, precompute:\r\n$r_{i,j}= g^{\\frac {j(q-1)} {p_i}}$, for $j= 1,2, \\ldots , p-1$.\r\nWant to find $x \\jmod{p_i^{\\alpha_i}}$, for each $p_i$ then use Chinese Remainder\r\nTheorem (CRT).\r\n$x= x_0 + x_1 p + x_2 p^2 + \\ldots + x_{\\alpha - 1} p^{\\alpha - 1}$.\r\n$y^{(q-1)/p}=g^{x(q-1)/p}=r_{p,x_{0}}$.  This yields $x_0$. Next\r\nput $y_{1}= {\\frac {y} {g^{x_{0}}}}$.  This reduces the discrete log over any group\r\norder to discrete log over $p$.  This takes $O(\\sum_{p \\mid |G|} (e(p)(lg(|G|)+{\\sqrt p}))$\r\nif we use Pollard.\r\n\\\\\r\n\\\\\r\n{\\bf Finding discrete logs using\r\nindex calculus:}  Let $g$ be a generator for $F_q^*$ with $q=p^n$.\r\nFind $x$ such that $g^x = y \\jmod{q}$.\r\n\\emph{Precomputation phase:}  Let $f(x)$ be an irreducible polynomial \r\nof degree $n$ over $F_p$. Let\r\n$B_m$ be the set of irreducible polynomials of degree $\\leq m$.  Pick random $t$ and compute\r\n$c(x)=g(x)^t= c_0 \\prod_{a(x) \\in B_m} a(x)^{\\alpha_{c,a}}$.\r\n$ind(c(x))= ind(c_0) + \\sum_{a(x) \\in B_m} \\alpha_{c,a} ind(a(x))=t \\jmod{q-1}$.\r\nNow solve for the $ind(a(x))$.\r\n\\emph{Solution phase:} To compute $ind(y(x))$, pick random $t$ and compute\r\n$y(x) g(x)^t= \\prod_{B_m} a(x)^{\\alpha_{c,a}} \\jmod{f(x)}$.  This runs in\r\n$L_p[{\\frac 1 2}, c+o(1)]$. In $E_F$, there is no good basis corresponding to primes.\r\n{\\bf Example:} Let $q=p=83$ and $g=2$.\r\n$2^{1}= 2 \\jmod{83}$, so $ind_2(2)= 1$;\r\n$2^{2}= 4 \\jmod{83}$, so $ind_2(4)= 2$;\r\n$2^{7}= 128= 45= 3^2 \\cdot 5 \\jmod{83}$, so $ind_2(45)= 7$;\r\n$2^{17}= 15= 3 \\cdot 5 \\jmod{83}$, so $ind_2(15)= 7$.  Rewrite\r\nthe last two equations in log form as:\r\n$2 ind_2(3) + ind_2(5)= 7 \\jmod{82}$\r\nand\r\n$ind_2(3) + ind_2(5)= 17 \\jmod{82}$.  Subtracting, we get\r\n$ind_2(3)= -10= 72 \\jmod{82}$.  This is a simple example of solving the \r\nequations.  Now suppose we want $ind_2(31)$.\r\n$31^2= 48 = 2^4 3 \\jmod{83}$, so\r\n$2ind_2(31) = 4 ind_2(2) + ind_2(3)= 4+72 =76 \\jmod{82}$ and\r\nso $ind_2(31)= 38$.  Sure enough, $(2^{17})^2)\\cdot 2^4= 59 \\cdot 16= 31 \\jmod{83}$.\r\n\\\\\r\n\\\\\r\n{\\bf Shanks Baby/Giant:}  $\\langle g \\rangle = G$.  Given $y=g^x$,\r\nfind $x= log_{g}(y)$.\r\nPut $m= {\\sqrt n}$, Compute $(j,g^{j})$ for $j= 1, \\ldots , m$ sorted\r\nby second coordinate.  Set $t \\leftarrow g^{-m}$,\r\n$s \\leftarrow y$.\r\n\\\\\r\nFor(i=0 to m-1) \\{ /* is $s$ second component?*/ if($s= g^j$)\r\nreturn($x=im+j$); $s \\leftarrow st$\\}.  Alternative:  Solve $g^x = a \\jmod{p}$.  Pick\r\n$n: n^2 \\ge (p-1)$ and compute $g^j \\jmod{p}$ and $ag^{-nk} \\jmod{p}$ for\r\n$0 \\le j, k \\le n$; match two lists giving $g^j= a g^{-nk} \\jmod{p}$ or\r\n$g^{j+nk}= a \\jmod{p}$.\r\n\\\\\r\n\\\\\r\n{\\bf Boneh-Joux attack} on El Gamal/RSA with small messages and no preprocessing.\r\nSuppose we encrypt an $m$ bit message $M$ which is small then \r\n$M$ is often smooth --- i.e. $M=M_1M_2$.  \r\nIf the El Gamal system is $\\langle p, g, y=g^a \\rangle$\r\nand either the order of $g$ is small (less than ${\\frac p {2^m}}$)\r\nor $p-1=qs$ and the DL problem is tractable for subgroups of order $s$,\r\nmuch of the time ($\\approx .18$) which solves the problem using about $2^{m/2}$\r\nexponentiations.  Here is the general problem:\r\nLet $z \\in G_q \\rightarrow {\\mathbb Z}_p^*$, where\r\n$G_q$ is a subgroup of order $q$; if $\\Delta < 2^m$ and $u = z \\Delta \\jmod{p}$ then\r\ngiven $u$, find $z$.  Here is a meet in the middle shortcut.  Suppose \r\n$\\Delta= \\Delta_1 \\Delta_2$, $\\Delta_1 \\le 2^{m_1}, \\Delta_2 \\le 2^{m_2}$, by tablizing\r\n$\\Delta_1^q$ for possible $\\Delta_1$'s and trying every possible\r\n$\\Delta_2$ in $({\\frac u {\\Delta_2}})^q= \\Delta_1^q (\\bmod{p})$, we\r\ncan find $\\Delta= \\Delta_1 \\Delta_2$ in $O(2^{m_1}+2^{m_2})$ time and\r\n$2^{m_1}$ space.  With $m_1=m_2=32$ this can solve for a $64$ bit session\r\nkey with probability about $.18$.\r\n\\\\\r\n\\\\\r\n{\\bf Defense for Boneh-Joux (OAEP or IND-CCA):}\r\n$c= E(m) = f(a= M \\oplus G(r) || b=r \\oplus H(a)$ \\\\\r\nREACT:\r\n$E(m, r||s): (a= f(x,r), b= k \\oplus m, c= H(m,x,a,b)$, $k= G(x)$.\r\nFor El Gamal:\r\n$a= Rand(1 .. q)$, $R= Rand(\\langle g \\rangle)$,\r\n$A= g^a$, $A'= Rg^a$,\r\n$k=G(R)$, $B=E_k(m)$, $C= H(R,m,A,a',B)$.\r\n\\begin{center}\r\n\\begin{tabular} {|rrr|rrr|}\r\n\\hline\r\n$n$ & $p$ & $H(B_n(p))$ & $n$ & $p$ & $H(B_n(p))$\\\\\r\n\\hline\r\n$2$ & $.5$ & $2$ & $3$ & $.5$ & $3$\\\\\r\n$2$ & $.60$ & $1.94$ & $3$ & $.60$ & $2.91$\\\\\r\n$2$ & $.75$ & $1.62$ & $3$ & $.75$ & $2.43$\\\\\r\n$2$ & $.80$ & $1.44$ & $3$ & $.80$ & $2.16$\\\\\r\n$2$ & $.90  $ & $.93$ & $3$ & $.90  $ & $1.4$\\\\\r\n$2$ & $.95$ & $.57$ & $3$ & $.95$ & $.85$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|rr|rr|}\r\n\\hline\r\n$\\lambda$ & $H(P(\\lambda))$ & $\\lambda$ & $H(P(\\lambda))$\\\\\r\n\\hline\r\n$.5$ & $.91$ & $.60$ & $1.00$\\\\\r\n$.75$ & $1.14$& $.80$ & $1.18$\\\\\r\n$.90  $ & $1.27$ & $.95$ & $1.31$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Shamir's attack on RSA with multiplication bug:}\r\nAssume the RSA implementation uses the CRT (which yields a speedup of $4$) and let\r\nthe public key be $n=pq$ with $p<q$.  Suppose that $a \\times b$ (two\r\n$32$ bit quantities) is computed\r\nincorrectly on a computer with a word size of $w$ bits.  We can pick\r\n$c= \\lfloor {\\sqrt n} \\rfloor$ so $p<c<q$.  Put\r\n$c= c_{k}2^{wk} + c_{k-1}2^{w(k-1)} + \\ldots + c_{1}2^{w} + c_0$ and select $m$ such that\r\n$m= c_{k}2^{wk} + c_{k-1}2^{w(k-1)} + \\ldots + a2^{w} + b$.  Assume we can have the\r\nflawed machine compute $m^d \\jmod{n}$.  Put\r\n$m_1 = m \\jmod{p}$ and $m_2 = m \\jmod{q}$.\r\nSince $p<m<q$ is likely, $a$ and $b$ are not likely\r\nto appear in the representation of $m_1$ but will appear in $m_2$. Thus\r\n$x_1= {m_1}^d \\jmod{p}$ will be computed correctly but $x_2= {m_2}^d \\jmod{q}$ will be computed incorrectly. \r\nSuppose $1= up+vq$, the combined result will be computed as $y= m^d \\jmod{n}= x_2 up + x_1 vq$.\r\n$y$ will likely be correct\r\n$\\jmod {p}$ but incorrect $\\jmod {q}$.  Thus $p \\mid y^e-m$ but\r\n$q \\nmid y^e-m$ and $p= (y^e-m,n)$.  Padding interferes with this attack.\r\n\\\\\r\n\\\\\r\n{\\bf Weiner's attack:} \r\n$|\\alpha - {\\frac p q}| \\le {\\frac 1 {2q^2}}$ with $d< {\\frac 1 3} N^{\\frac 1 4}$.\r\nPut $N=pq$, $q<p<2q, ed=1 \\jmod {\\phi}$.  $|{\\frac e {\\phi}} - {\\frac k d}| < {\\frac 1 {d \\phi}}$\r\nwith $ed-k \\phi=1$, $|N- \\phi|=|p+q+1|< 3 {\\sqrt N}$ so \r\n$|{\\frac e N}-{\\frac k d}| \\le {\\frac {3k} {d {\\sqrt N}}}< {\\frac 1 {2d^2}}$ and \r\n${\\frac k d}$ arises as a convergent, $\\alpha={\\frac e N}$.\r\n\\\\\r\n\\\\\r\n{\\bf Coppersmith:}  Let $f(x) \\in {\\mathbb Z}[x]$ be a monic polynomial\r\nof $deg(f)=d$, $N \\in {\\mathbb Z}$.  If \r\n$\\exists x_0 : f(x_0) = 0 \\jmod{N}$\r\nwith $|x_0| \\le X= N^{{\\frac 1 d} - \\epsilon}$, one can find $x_0$ in time polynomial in\r\n$lg(N)$ and ${\\frac 1 {\\epsilon}}$ for fixed $d$.  This can be used to extend the \r\n\\emph {Franklin-Reiter} attack.\r\n\\\\\r\n\\\\\r\n{\\bf Observation:}\r\nIf $f(x)=f_0 + f_1 x + \\ldots + f_d x^d$ and $\\exists x_0: f(x_0)= 0 \\jmod{n}$ with\r\n$|x_0| < N^{\\frac 1 d}$, find $x_0$ efficiently.  The idea is to \r\nfind $h(x) \\in {\\mathbb Z}[x]$ which\r\nshares a root with $f \\jmod{n}$ with $||h||^2= \\sum_{i=0}^{deg(h)} |h_i |^2$ with\r\n$||h||$ small.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma:} Let $h(x) \\in {\\mathbb Z}[x]$, $deg(h)\\le n, X,N \\in {\\mathbb Z}^{>0}$;  suppose\r\n$||h(XN)|| < {\\frac N {\\sqrt n}}$; if $|x_0 |<X$ satisfies $h(x_0 ) = 0 \\jmod{N}$ then\r\n$h(x_0)=0$.\r\n\\\\\r\n\\\\\r\nSuppose $f(x_0)=0 \\jmod{n}$ then $f(x_0)^k= 0 \\jmod{N^k}$.  For some $m$,\r\nset $g_{u,v}(x)= N^{m-v} x^u f(x)^v$, $0 \\le u < d, 0 \\le v \\le m$\r\nthen $g_{u,v} (x_0)= 0 \\jmod{N^m}$.  \r\nFix $m$, try to find\r\n$a_{u,v} \\in {\\mathbb Z}: \r\nh(x)= \\sum_{u \\ge 0} \\sum_{v=0}^m a_{u, v} g_{u,v}(x)$ that\r\nsatisfies the lemma; that is $||h(xX)|| \\le {\\frac {N^m} {\\sqrt {d(m+1}}}$\r\nwith $h(xX)= \\sum_{u \\ge 0} \\sum_{v=0}^m a_{u, v} g_{u,v}(xX)$ that.  Use LLL for\r\nthis minimization problem.\r\nLLL conditions on $\\langle b_1 , b_2 , \\ldots , b_n \\rangle$ are \r\n$\\mu_{ij} = {\\frac {\\langle b_i, b_i^* \\rangle} {\\langle b_i^*, b_i^*} \\rangle}$,\r\n$b_i^*= b_i - \\sum_{j<i} \\mu_{ij} b_j^*$,\r\n$||b_i^*||^2 \\ge ({\\frac 3 4} - \\mu_{i,i-1}^2) ||b_{i-1}||^2$, if \r\n$x \\in L, ||b_1|| \\le 2^{\\frac {m-1} 2} ||x||$, $||b_1|| \\le 2^{\\frac m 4} \\Delta^{\\frac 1 m}$.\r\n\\\\\r\n\\\\\r\n\\emph{Example:} $f(x)= x^2 + ax + b$.  Want to find $x_0: f(x_0)=0 \\jmod{N}$.  Set $m=2$.\r\n$g_{00}(xX)= N^2$,\r\n$g_{10}(xX)= XN^2 x$,\r\n$g_{01}(xX)= bN + aXxN+ XN^2 x$,\r\n$g_{11}(xX)= bNXx + aX^2x^2N+ N^2 X^3x^3$,\r\n$g_{02}(xX)= b^2 + 2ab Xx+ (a^2 + 2b) X^2 x^2 + 2a X^3 x^3 + X^4 x^4$,\r\n$g_{12}(xX)= b^2Xx + 2ab X^2x^2+ (a^2 + 2b) X^3 x^3 + 2a X^4 x^4 + X^5 x^45$.\r\n$A=\r\n\\left(\r\n\\begin {array} {cccccc}\r\nN^2 & 0 & bN & 0 & b^2 & 0 \\\\\r\n0 & XN^2 & aXN & bNX & 2abX & Xb^2 \\\\\r\n0 & 0 & NX^2 & aNX^2 & (a^2+2b)X^2 & 2ab X^2 \\\\\r\n0 & 0 & 0 & NX^3 & 2aNX^3 & (a^2+2b)X^3\\\\\r\n0 & 0 & 0 & 0 & X^4 & 2aX^4\\\\\r\n0 & 0 & 0 & 0 & 0 & X^5\\\\\r\n\\end {array}\r\n\\right)$.\r\n$det(A) = N^6 X^{15}$, $||b_1|| < 2^{\\frac 3 2} N X^{\\frac 5 2}$.  \r\n$b_1 = Au$, $Bu= (u_1 , u_2, \\ldots , u_6)$, $||h(xX)|| \\le {\\frac {N^2} {\\sqrt 6}}$,\r\n$|x_0| \\le X = {\\frac {N^{\\frac 2 5}} {48^{\\frac 1 8}}}$ and $|x_0| < N^{.39}$.\r\n\\\\\r\n\\\\\r\n{\\bf Common Modulus attack:} Suppose $(e_1, e_2)=1$ and $m$ is encrypted both with an\r\n$\\langle n,e_1 \\rangle$ scheme and a $\\langle n, e_2 \\rangle$ scheme; let \r\n$c_1= m^{e_1} \\jmod{n}$ and\r\n$c_2= m^{e_2} \\jmod{n}$ with $d_1 e_1 + d_2 e_2=1$ then $m= {c_1}^{d_1} {c_2}^{d_2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Small exponent attacks:}  Suppose $e=3$ and \r\n$c_1= {m_1}^{e}$, $c_2= {m_2}^{e}$ with $m_2= m_1 + \\delta$, where $\\delta$ is known.\r\nPut $F(x)= x^e-c_1 \\jmod{n}$ and\r\n$G(x)= (x+\\delta)^e-c_2 \\jmod{n}$ then $(x-m) \\mid (F(x), G(x))$ and we can recover $m$.\r\nNow if $\\delta$ is unknown but $| \\delta | < n^{\\frac 1 9}$ and there is an algorithm, $A$\r\n(e.g.- Coppersmith's algorithm),\r\nthat can find the roots, $\\alpha$ of $f(x)=0 \\jmod {n}$ when $| \\alpha|< n^{\\frac 1 9}$, the\r\nforegoing attack can be extended.  To do this, consider $F(x)= x^e - c_1 \\jmod{n}$ and\r\n$G(x,y)= (x+y)^e -c_2 \\jmod{n}$ and compute the resultant $h(y)= Res(F,G)$ in the ring\r\n${\\mathbb Z}_n[y]$; note $h$ has a root, $\\delta$.\r\n\\section {Lattice Methods}\r\n{\\bf Lattices:} \r\n$\\Lambda = {\\mathbb Z} {\\vec {b_1}} + {\\mathbb Z} {\\vec {b_2}} + \\ldots + {\\mathbb Z} {\\vec {b_n}}$\r\nis the lattice generated by $\\langle b_1 , \\ldots , b_n \\rangle$.  The volume of\r\nthe fundamental region is $vol(\\Lambda) = det({\\vec {b_1}}, {\\vec {b_2}}, \\ldots, {\\vec {b_n}})$.\r\nIf the basis vectors, $\\langle b_1 , \\ldots , b_n \\rangle$ are orthogonal,\r\n$vol(\\Lambda) = ||b_1|| \\cdot ||b_2|| \\cdot \\ldots \\cdot ||b_n||$.  The \\emph{orthogonal defect}\r\nof the basis $\\langle b_1 , \\ldots , b_n \\rangle$ is ${\\frac {||b_1|| \\cdot ||b_2|| \\cdot \\ldots \\cdot ||b_n||}\r\n{vol(\\Lambda)}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Minkowski's Theorem: } Let $\\Lambda$ be a lattice in ${\\mathbb R}^n$ and $S \\subseteq {\\mathbb R}^n$\r\na convex, centrally symmetric region in ${\\mathbb R}^n$.  If $vol(S) > 2^n det(\\lambda)$ then $S$ has\r\nat least one non-zero lattice point of $\\Lambda$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nNote that if $S_1 \\cap S_2 = \\emptyset$, $vol(S_1 \\cup S_2) = vol(S_1) + vol(S_2)$.\r\nLet $\\lambda'$ be the lattice generated by $\\langle e_1, e_2, \\ldots, e_n$ and suppose $vol(S') > 2^n$.\r\nFor ${\\vec r} \\in S'$, ${\\vec r} = (\\alpha_1 + x_1, \\alpha_2 + x_2, \\ldots, \\alpha_n + x_n)$,\r\nwhere $\\alpha_i \\in {\\mathbb Z}$ and\r\n$x_i \\leq 1$, put ${\\vec \\alpha} = (\\alpha_1, \\alpha_2, \\ldots , \\alpha_n)$ then\r\ndefine $T_{\\vec \\alpha}(r) = (x_1, x_2, \\ldots, x_n)$.\r\nIf $s \\ne t \\in S$ implies $T(r) \\ne T(s)$ then\r\n$vol(S) = vol(T(S))$. $S = \\bigcap_{{\\vec alpha} \\in {\\mathbb Z}^n} {\\vec alpha} + T(S)$.\r\n$vol(T_{\\vec 0}(S)) \\leq 1$.   So if $vol(\\bigcap_{\\alpha}T_{\\vec alpha}(S)) > 1$,\r\n$S$ has two distinct non-zero\r\npoints, $r_1, r_2$ such that $0 \\ne r_1 - r_2 \\in {\\mathbb Z}^n$. Since $S$ is centrally symmetric, $-r_1, -r_2 \\in S$\r\nalso.  \r\nIf $vol(S') > 2^n$, there are at least $2^n +1$ distinct points, $r_k \\in S'$ with $r_i - r_j \\in {\\mathbb Z}^n$.\r\nSo at least two of these points, say, $r_j, r_k$ have the property that $r_j = r_k \\jmod{2}$.\r\n$0 \\ne {\\frac {r_j - r_k} {2}} \\in {\\mathbb Z}^n$ and ${\\frac {r_j - r_k} {2}} \\in S'$, by convexity.\r\nNow returning to $S$, let $\\langle b_1, b_2, \\ldots, b_n \\rangle$ generate $\\Lambda$ and let\r\n$b_i = A e_i$. $vol(\\Lambda) = det(A) vol(e_1, e_2, \\ldots, e_n)$, so if $vol(S) > 2^n vol(\\Lambda)$,\r\n${\\frac {vol(S)} {det(A)}} > 2^n$.  $S' = A^{-1}S$ is centrally symmetric, convex and\r\ngenerated by $\\langle e_1, e_2, \\ldots, e_n \\rangle$; so, by the case above, there is a vector\r\n$0 \\ne \\alpha_1 e_1 +\\alpha_2 e_2 + \\ldots  +\\alpha_n e_n \\in S'$.  But then,\r\n$\\alpha_1 b_1 +\\alpha_2 b_2 + \\ldots  +\\alpha_n b_n \\in S$.\r\n\\end{quote}\r\n{\\bf Shortest vector problems :}  The shortest vector problem, $SVP$, is :\r\nGiven a lattice $\\Lambda$, generated by $\\langle b_1 , \\ldots , b_n \\rangle$,\r\nfind the vector ${\\vec x} \\in \\Lambda$ with smallest length.\r\n$SVP_{\\gamma}$ is :\r\nGiven a lattice $\\Lambda$, generated by $\\langle b_1 , \\ldots , b_n \\rangle$,\r\nfind a vector ${\\vec x} \\in \\Lambda$ with $||v|| \\leq \\gamma \\lambda$, where $\\lambda$ is the length of the\r\nshortest vector in $\\Lambda$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } If $\\Lambda$ is lattice generated by $b_1, b_2, \\ldots, b_n$ and $\\lambda$ is the shortest vector\r\nin $\\Lambda$, then $\\lambda \\leq \\sqrt{n} det(\\Lambda)^{\\frac 1 n}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $B_r$ be a ball centered at ${\\vec 0}$ with $r = \\sqrt{n}det(\\Lambda)^{\\frac 1 n}$.\r\n$vol(B_r) > 2^n vol(\\Lambda)$, so there is at least one non-zero vector, say $x$, in $\\Lambda$ inside $B_r$\r\nby Minkowski. Hence $\\lambda \\leq ||x|| \\leq r$.\r\n\\end{quote}\r\n{\\bf Hermite Normal Form: } If $A$ is an $m \\times n$ dimensional matrix, there is a matrix $HNF(A)$ of the form\r\n$$\r\n\\left(\r\n\\begin{array}{ccccccc}\r\n>0 & 0 & 0 & 0 & 0 & \\ldots & 0\\\\\r\n\\geq 0 & >0 & 0 & 0  & 0 &  \\ldots & 0\\\\\r\n\\geq 0 &\\geq 0 & >0 & 0  & 0 &  \\ldots & 0\\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\n\\ldots &\\geq 0 &\\geq 0 & >0 &  0 & &  0\\\\\r\n0 & 0 & 0 & 0 & 0 & \\ldots & 0\\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\n0 & 0 & 0 & 0 & 0 & \\ldots & 0\\\\\r\n\\end{array}\r\n\\right) \r\n$$. $HNF(A)$ is in normal form if (1) rightmost $m-n$ colums are $0$, (2) $HNF(A)$ is lower triangular and,\r\n(3) all the elements in $HNF(A)$ are non-negative.\r\nFurther, $HNF(A) = U A$, where $U$ is unimodular.\r\n\\\\\r\n\\\\\r\n{\\bf Gram Schmidt orthogonalization algorithm (GSO): } Given $\\langle b_1 , \\ldots , b_n \\rangle$,\r\ncompute an orthogonal basis $\\langle b_1^* , \\ldots , b_n^* \\rangle$ and $\\mu_{ij}$ as follows:\r\n\\begin{enumerate}\r\n\\item $b_1^* = b_1$\r\n\\item for $i = 2$, $i \\leq n$\r\n\\begin{enumerate}[label*=\\arabic*.]\r\n\\item $b_i^* \\leftarrow b_i - \\sum_{j=1}^{i-1} \\mu_{ij} b_j^* , \\mu_{ij} = {\\frac {(b_i, b_j^*)} {(b_j^*, b_j^*)}}$\r\n\\end{enumerate}\r\n\\item return $\\langle b_1^* , \\ldots , b_n^* \\rangle$ and $\\mu_{ij}$ \r\n\\end{enumerate}\r\nGenerally, $\\langle b_1^* , \\ldots , b_n^* \\rangle \\notin \\Lambda$.  The basis reduction\r\nalgorithm finds a new reduced basis $\\langle b_1 , \\ldots , b_n \\rangle$ from the original\r\nbasis and the output of the Gram-Schmidt orthogonalization algorithm.\r\n\\\\\r\n\\\\\r\n{\\bf Size reduction algorithm (SRA): } Given $\\langle b_1 , \\ldots , b_n \\rangle$,\r\nproduce reduced basis $\\langle b_1 , \\ldots , b_n \\rangle$ GSO vectors\r\n$\\langle b_1^* , \\ldots , b_n^* \\rangle$ and GSO coefficients $\\mu_{ij}$.\r\n\\begin{enumerate}\r\n\\item Run GSO to get $\\langle b_1^* , \\ldots , b_n^* \\rangle$ and $\\mu_{ij}$.\r\n\\item for $i=2$ up to $n$\r\n\\begin{enumerate}[label*=\\arabic*.]\r\n\\item for $j=(i-1)$ downto $1$\r\n\\begin{enumerate}[label*=\\arabic*.]\r\n\\item $b_i \\leftarrow b_i - \\lfloor \\mu_{ij} \\rceil b_j$\r\n\\item for $k=1$ to j\r\n\\begin{enumerate}[label*=\\arabic*.]\r\n\\item $\\mu_{ik} \\leftarrow \\mu_{ik} - \\lfloor \\mu_{ij} \\rceil \\mu_{jk}$\r\n\\end{enumerate}\r\n\\end{enumerate}\r\n\\end{enumerate}\r\n\\item return $\\langle b_1 , \\ldots , b_n \\rangle$, $\\langle b_1^* , \\ldots , b_n^* \\rangle$, $\\mu_{ij}$\r\n\\end{enumerate}\r\n{\\bf LLL motivation:}  $AU=B$ has a solution iff\r\n$M=\r\n\\left (\r\n\\begin{array}{cc}\r\nI & 0\\\\\r\nA & -B\\\\\r\n\\end{array}\r\n\\right)$ and $M [U,1]^T = [U,0]^T$ has a solution with $U$ a $0,1$ vector.  Since\r\n$||[U, 0]^T || \\leq n$, a short vector in the lattice generated by the column\r\nspace of $M$ is likely to be close to a solution of $AU=B$.  Let $L$ be a\r\nlattice generated by $M$, $vol(L)= |det(M)|$   Not all lattices are generated\r\nby linearly independent vectors; for example $\\langle (1,2), (1,1), (2,1) \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Lattices in 2 dimensions} (vectors are columns)  $[a, b]$ is reduced iff\r\n$||a|| \\leq ||b||$ and $||a||, ||b|| \\leq ||a+b||, ||a-b||$.\r\nLemma: If $||x|| \\leq ||x+y||$ then $||x+y|| \\leq ||x+ \\alpha y||$, $\\alpha > 1$.\r\nLet $\\lambda_k = min_{x} |\\{ v \\in {\\cal L}(B)-\\{0\\} : ||v|| \\leq x\\}| \\geq k$\r\n(so $\\lambda_1$ is the shortest\r\nvector in the lattice.)\r\nTheorem: If $a, b$ is a basis, $||a|| = \\lambda_1$, $||b||= \\lambda_2$ iff $[a, b]$\r\nis a reduced basis.\r\nGauss algorithm: (1) Find $\\mu$: $||b-\\mu a||$ is minimal.  \r\n(2) if $||a-b||>||a+b||$ replace\r\n$b$ with $-b$. (3) if $[a, b]$ is not reduced, swap $a$ and $b$ and go to 1.\r\nNote: LLL Gives an approximation to reduced basis $n>2$.  \\\\\r\n\\\\\r\n{\\bf Definitions: }  $\\langle b_1, b_2, \\ldots b_n \\rangle$ is \\emph{size reduced} if $|\\mu_{ij}| \\leq {\\frac 1 2}$.\r\n$\\langle b_1 , b_2 , \\ldots , b_n \\rangle$ is \\emph{LLL reduced}\r\nwith respect to $\\delta$ if\r\n\\begin{enumerate}\r\n\\item  $\\langle b_1 , b_2 , \\ldots , b_n \\rangle$ is size reduced.\r\n\\item $\\delta ||b_i^*||^2 \\leq ||b_{i+1}^*||^2 + \\mu_{i+1,i}^2 ||b_i^*||^2$.\r\n\\end{enumerate}\r\n{\\bf LLL algorithm:} Input is basis $\\langle b_1 , \\ldots , b_n \\rangle$.  Output is\r\nLLL reduced basis.\r\n\\begin{enumerate}\r\n\\item Run SRA to get reduced $\\langle b_1 , \\ldots , b_n \\rangle$,\r\n$\\langle b_1^* , \\ldots , b_n^* \\rangle$, $\\mu_{ij}$\r\n\\item Compute $B_i = ||b_i^*||^2$\r\n\\item for $i=2$ to $n-1$\r\n\\begin{enumerate}[label*=\\arabic*.]\r\n\\item if $(\\delta - \\mu_{i+1,i}^2)B_i > B_{i+1}$\r\n\\begin{enumerate}[label*=\\arabic*.]\r\n\\item swap $b_i$ and $b_{i+1}$\r\n\\item start again at step 1\r\n\\end{enumerate}\r\n\\end{enumerate}\r\n\\item return $\\langle b_1 , \\ldots , b_n \\rangle$\r\n\\end{enumerate}\r\n{\\bf LLL Theorem: } Let $\\Lambda \\subseteq {\\mathbb R}^n$ be a lattice with an LLL reduced basis\r\n$\\langle b_1 , b_2 , \\ldots , b_n \\rangle$ and let $\\lambda$ be the length of the shortest vector in $\\Lambda$.  Then\r\n\\begin{enumerate}\r\n\\item $||b_1|| \\leq 2^{\\frac {n-1} {2}} vol(\\Lambda)^{\\frac 1 n}$\r\n\\item $||b_1|| \\leq 2^{\\frac {n-1} 2} \\lambda$\r\n\\item $||b_1|| \\cdot ||b_2|| \\cdot \\ldots \\cdot ||b_n|| \\leq 2^{\\frac {n(n-1)} {4}}$\r\n\\end{enumerate}\r\n{\\bf Theorem: } Let $\\Lambda$ be a lattice with basis $\\langle b_1 , \\ldots , b_n \\rangle$ with\r\n$||b_i|| < X$ for all $i$.  Let ${\\frac 1 4} < \\delta < 1$.  Then LLL's running time is\r\n$O(n^6 lg(X)^3)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } Let $\\langle b_1 , b_2 , \\ldots , b_n \\rangle$ be a LLL-reduced basis for $\\Lambda$\r\nwith $\\delta = {\\frac 3 4}$ and $\\langle b_1^* , \\ldots , b_n^* \\rangle$ as above and $B_i = ||b_i^*||^2$.\r\nThen\r\n\\begin{enumerate}\r\n\\item $B_i \\leq 2 B_{i+1}$\r\n\\item $B_i \\leq ||b_i||^2 \\leq ({\\frac 1 2} + 2^{i-2})B_i$\r\n\\item $||b_j|| \\leq 2^{\\frac {i-1} 2} ||b_i^*||$\r\n\\item $\\lambda(\\Lambda) \\geq min_i ||b_i^*||$\r\n\\end{enumerate}\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nSince the basis is reduced, $\\mu_{i+1,i}^2 \\leq {\\frac 1 4}$. The LLL condition with $\\delta = {\\frac 3 4}$\r\ngives 1.  GSO insures $b_i = b_i^* + \\sum_{j=1}^{i-1} \\mu_{ij}b_j^*$ and by orthogonality,\r\n$||b_i^*|| \\leq ||b_i||$ and $||b_i||^2 = B_i + \\sum_{j=1}^{i-1} \\mu_{ij}^2 B_j$.\r\n$\\mu_{ij}^2 B_j \\leq {\\frac 1 4} B_j \\leq {\\frac 1 4} 2^{i-j} B_i$ giving 2, since\r\n$||b_i||^2 \\leq B_i(1 + {\\frac 1 4} \\sum_{j=1}^{i-1} 2^{i-j}) = $\r\n$B_i (1+ {\\frac 1 4} (2^i - 2))= B_i ({\\frac 1 2} + 2^{i-2})$.  For $j \\geq 1$, ${\\frac 1 2} + 2^{j-2} \\leq 2^{j-1}$,\r\nso 2 implies $||b_j||^2 \\leq 2^{j-1} B_j$.\r\nSince $B_j \\leq 2^{i-j} B_i$, by 1, we get $||b_j||^2 \\leq 2^{j-1} 2^{i-j} B_i= 2^{i-1}B_i$.\r\nWe get 3 by taking square roots.\r\nIf ${\\vec v}$ is the shortest vector, ${\\vec v} = \\sum_{i=1}^n x_i b_i, x_i \\in {\\mathbb Z}$, we get\r\n${\\vec v} = \\sum_{i=1}^n (x_i b_i^* + \\sum_{j=1}^{i-1} (x_i \\mu_{ij} b_j^*))= $\r\n$\\sum_{i=1}^n (x_i + \\mu_{i+1,i} x_{i+1} + \\ldots + \\mu_{ni} x_n)b_i^*$.  Let $i$ be the \r\nlargest index with $x_i \\ne 0$.  The last equation and orthogonality give $||{\\vec v}|| \\geq |x_i| ||b_i^*||$ which gives 4.\r\n\\end{quote}\r\n{\\bf Theorem: } Let $\\langle b_1 , b_2 , \\ldots , b_n \\rangle$ be a LLL-reduced basis for $\\Lambda$\r\nwith $\\delta = {\\frac 3 4}$ then\r\n\\begin{enumerate}\r\n\\item $||b_1|| \\leq 2^{\\frac {n-1} 2} \\lambda$\r\n\\item $vol(\\Lambda) \\leq \\prod_{i=1}^n ||b_i|| \\leq 2^{\\frac {n(n-1)} {4}} vol(\\Lambda)$\r\n\\item $||b_1|| \\leq 2^{\\frac {n-1} {4}} vol(\\Lambda)^{\\frac 1 n}$\r\n\\end{enumerate}\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nBy the previous proposition $||b_i^*||^2\\geq2^{\\frac {1-i} 2} ||b_1^*||$,  But $b_1 = b_1^*$,\r\nso $\\lambda \\geq min_i ||b_i^*|| = 2^{\\frac {1-n} 2} ||b_1||$.  $vol(\\Lambda) = \\prod_{i=1}^n ||b_i^*||$\r\nand inequality 2 follows from $||b_i^*|| \\leq ||b_i||$ and part 3 of the proposition.\r\n$||b_1|| \\leq 2^{\\frac {i-1} 2} ||b_1^*||$ now gives\r\n$||b_1||^n \\leq \\prod_{i=1}^n 2^{\\frac {i-1} 2} ||b_i^*|| = 2^{\\frac {n(n-1)} 4} vol(\\Lambda)$.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\n$K$ is \\emph{convex} and \\emph{symmetric} iff $x, y \\in K$\r\nimplies\r\n$ax+by \\in K$ provided $|a| + |b| \\leq 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Minkowski: } Let $L$ be a lattice of rank $r$.  Let $v_1$ be the shortest\r\nvector,\r\n$v_i$ the shortest vector independent of $\\langle v_1, \\ldots , v_{i-1} \\rangle$, then\r\n$|v_1 | |v_2 | \\ldots |v_r | \\leq {\\frac {2^r} {vol(B_r)}} d(L)$ where\r\n$vol(B_r)= {\\frac {\\pi^{\\frac r 2}} {\\Gamma(1+{\\frac r 2)})}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Minkowski's theorem on linear forms: }  Let $\\Lambda \\in\r\n{\\mathbb R}^N$ and $L_1, \\ldots , L_N$ be linear forms with associated\r\nmatrix $C$;\r\nif $det(C)d(\\lambda) \\leq \\epsilon_1 \\epsilon_2 \\ldots \\epsilon_N$,\r\nthere is a lattice point $\\lambda \\ne 0$ such that\r\n$|L_m (\\lambda)| \\leq \\epsilon_m$.   Corollary: $\\exists l: L_m(l)\r\n\\leq (det(C))^{\\frac 1 N}$.  \\\\\r\n\\\\\r\nLow density subset sum. $\\sum a_i s_i = s$ look at matrix\r\nformed by $I_n$\r\nwith bottom row $(\\frac {1} {2} , \\ldots , \\frac {1} {2} , ms)$ and\r\nfirst n entries in rightmost columns $(m a_1 , m a_2 , \\ldots , m a_n )$.\r\nNow round.\r\n\\\\\r\n\\\\\r\n{\\bf Weakness due to partial knowledge: }\r\nIf $n=pq$ has $m$ bits and we know the first or last ${\\frac m 4}$ bits of $p$, then\r\n$n$ is easy to factor.  If plaintext is short, match $c x^{-e} = y^e$ to get\r\n$c=(xy)^e \\jmod{n}$.  If $q<p<2q$ and $1 \\le d, e < \\psi(n)$ with $de=1 \\jmod{\\psi(n)}$ and\r\n$d<{\\frac 1 3} n^{\\frac 1 4}$ then $d$ can be found easily.\r\n\\\\\r\n\\\\\r\n{\\bf Attack on RSA using LLL: }\r\n Suppose message is of the form ``M xxx'' where only `xxx' varies\r\n(e.g.- ``The key is xxx'').  Thus the message is of the form $B+x$ where $B$ is fixed and\r\n$|x|<Y$.  $c= (B+x)^3 \\jmod{n}$ and \r\n$f(T)= (B+T)^3-c= T^3+ a_2 T^2 + a_1 T + a_0 \\jmod{n}$. We \r\nwant to find $x: f(x)=0 \\jmod{n}$.  Let\r\n$v_1= (n, 0, 0, 0)$, $v_2= (0, Yn, 0, 0)$, $v_3= (0, 0, Y^2n, 0)$,\r\n$v_4= (a_0 , a_1 Y, a_2Y^2, Y^3)$.  Then \r\n$||b_1|| \\le \r\n2^{\\frac 3 4} |det(v_1, v_2, v_3, v_4)| = 2^{\\frac 3 4}n^{\\frac 3 4} Y^{\\frac 3 2}$.\r\n$b_1= c_1 v_1 + \\ldots + c_4 v_4= (e_0 , Y e_1 , Y^2 e_2, Y^3 e_3)$;\r\n$e_0 = c_1 n + c_4 a_0$, $e_1 = c_2 n + c_4 a_1$,\r\n$e_2 = c_3 n + c_4 a_2$,\r\n$e_3 =  c_4$, and $g(T)= e_3 T^3 + e_2 T^2  + e_1 T +e_0$.  Since $f(x)= 0 \\jmod{n}$\r\nand $c_4 f(T)= g(T) \\jmod{n}$, $0=c_4 f(x) = g(x) \\jmod{n}$.  If\r\n$Y < 2^{\\frac 7 6} n^{\\frac 1 6}$, $|g(x)| \\le 2 || b_1 ||$ (use C-S) but\r\n$||b_1|| \\le 2^{-1} n$ so $|g(x)| < n$ and $g(x)=0$ yielding 3 candidates for $x$.\r\n\\emph{Coppersmith} extended this to small solutions of polynomials of degree $d$ using\r\na $d+1$ dimensional lattice by examining the monic polynomial $f(T)= 0 \\jmod{n}$ of\r\ndegree $d$ when $|x| \\le n^{\\frac 1 d}$.\r\n\\\\\r\n\\\\\r\n{\\bf GGH public key scheme: }\r\nLet $n \\in {\\mathbb N}$ be the security parameter. $M \\in {\\mathbb Z}$ and $\\sigma = 3$.\r\n\\begin{enumerate}\r\n\\item ${\\cal M} = \\{ -M, \\ldots , 0, 1, \\ldots M\\}$ is the message space ${\\cal C} = {\\mathbb Z}^n$ is the cipherspace.\r\n\\item For key generation, choose $B \\in {\\mathbb Z}^{n \\times n}$ uniformly over small integers (say between $-4$ and\r\n$4$).  Check that $B$ is invertible.  $B$ is the private key.  Let $H$ be the HNF of $B$.  $H$ is the public key.\r\n\\item To encrypt, ${\\vec m} \\in \\{ -M \\ldots 0, 1, \\ldots M\\}$,\r\nchoose random noise vector, ${\\vec r} \\in \\{ -\\sigma, \\sigma \\}^n$.  ${\\vec c} = H{\\vec m} + r$.\r\n\\item To decrypt, ${\\vec m} = H^{-1} B \\lfloor B^{-1} {\\vec c}\\rceil$ ( $ \\lfloor B^{-1} {\\vec c} \\rceil$ is\r\ncalled the Babai rounding of ${\\vec c}$ with respect to  $B$).\r\n\\end{enumerate}\r\n{\\bf NTRU public key scheme: }\r\n$R = {\\mathbb Z}[x]/(x^N-1)$.  Define ${\\cal T}(d_1, d_2)$ are ternary polynomials n $R$\r\nwith $d_1$ coefficients $1$, $d_2$ coefficients\r\nequal to $-1$ and the rest $0$.  Let $p$ be prime and make sure $(N,p)=(N,q)=1$ and $q > (6d+1)p$.\r\n$R_p = {\\mathbb Z}_p[x]/(x^N-1)$, $R_q = {\\mathbb Z}_q[x]/(x^N-1)$.\r\n\\begin{enumerate}\r\n\\item ${\\cal M} = R_p$ and ${\\cal C} = R_q$.\r\n\\item For key generation, pick two polynomials $f, g \\in R$ with $f \\in {\\cal T}(d+1, d)$ and\r\n$g \\in {\\cal T}(d,d)$.  Check that $f$ is invertible $\\jmod{q}$ and $\\jmod{p}$, so\r\n$f_p \\cdot f = 1 \\jmod{p}$ and\r\n$f_q \\cdot f = 1 \\jmod{q}$.  Put $h = f_q \\cdot g \\jmod{q}$.\r\nPublic key is $(N, p, q,h)$, the private key is $f$.\r\n\\item To encrypt, encode the message in a polynomial, of degree $<N$, with coefficients,\r\n$-{\\frac {p-1} 2} \\leq m_i \\leq {\\frac {p-1} 2}$.  Choose $r \\in {\\cal T}(d,d)$.\r\n$c = prh+m \\jmod{q}$.\r\n\\item To decrypt, compute $a = fc \\jmod{q}$ and represent $a$ with integer coefficients between\r\n$-{\\frac {p-1} 2}$ and ${\\frac {p-1} 2}$.  $m = f_p a \\jmod{p}$.  To verify, check\r\n$a=fc=f(prh+m) \\jmod{q} = prg + fm \\jmod{q}$.  The largest coefficient of this is at most\r\n$p\\cdot 2d + (2d+1){\\frac p 2}$ and since $q > (6d+1)p$ the coefficients have magnitude less than ${\\frac q 2}$.\r\n\\end{enumerate}\r\nFor a polynomial, $f(x) = a_0 + a_1 x + a_2 x^2 + \\ldots + a_{n-1} x^{n-1}$, we can define the circulant matrix,\r\n$C_f$, whose top roq consists of the coefficients, in order.  On each successive row, the entries shift on place left.\r\nIf $g(x) = b_0 + b_ 1 x + \\ldots + b_{N-1} x^{N-1}$, $(b_0, b_1, \\ldots , b_{N-1}) C_f = \\tilde{f} \\tilde{g}$ is the convolution.\r\nNTRU in the lattice context is as follows. $\\tilde{f}C_h = \\tilde{g} \\jmod{q}$.  The matrix\r\n$$\r\nA=\r\n\\left(\r\n\\begin{array}{cc}\r\nI_N & C_h \\\\\r\n0 & q I_N \\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\ngenerates a lattice.\r\nA short vector in this lattice is $(\\tilde{f}, \\tilde{g})$.\r\n\\\\\r\n\\\\\r\n{\\bf Learning with Errors (LWE): }  If $a_i \\in {\\mathbb Z}_q^n$ are chosen uniformly at random.\r\n$s \\in {\\mathbb Z}_q^n$ is secret and we are given $m \\geq n$ approximate equations\r\n$a_1 \\cdot s = b_1$,\r\n$a_2 \\cdot s = b_2$,\r\n\\ldots\r\n$a_m \\cdot s = b_m$.  The errors, $e_1, e_2, \\ldots, e_m$ are small and chosed from $\\chi$.\r\nWe often use the discrete Gaussian for $\\chi$: $p(x) = {\\frac 1 c} e^{\\frac {x^2}{2 \\sigma^2}}, x \\in {\\mathbb Z}$,\r\nwhere $c = \\sum_{k \\in {\\mathbb Z}} e^{\\frac {k^2}{2 \\sigma^2}} \\approx \\sigma \\sqrt{2 \\pi}$.  Parameter width is\r\n$s = {\\frac {s} {\\sqrt{2 \\pi}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition: } Let $n, m, q \\in {\\mathbb N}, m \\geq n, q \\geq 2$ with \r\n$s \\in {\\mathbb Z}_q^n$.  Let $A \\in {\\mathbb Z}_q^{m \\times n}$ with entries choosen uniformly at random.\r\nLet $e \\in {\\mathbb Z}_q^m$ be drawn from $\\chi^m$.\r\nThe \\emph{search LWE} problem is to find $s$, given $A$ and $b =As+e$.\r\nThe \\emph{decision LWE} problem is to distinguish between (1) $b = As +e$ and (2) a uniform distribution.\r\n\\\\\r\n\\\\\r\nPiekert showed with the right parameters, breaking the cipher is equivalent to worst case LWE.\\\\\r\n\\\\\r\n{\\bf Regev:} Let $n \\in {\\cal N}$ and $m, q \\in {\\cal N}$ are polynomial in $n$.  $\\chi = D_{{\\cal Z}, s}$,\r\n$s > \\alpha q > 2 \\sqrt{n}$ and $0 < \\alpha < 1$.  LWE is as hard as worst case $SIVP_{\\gamma}$, $\\gamma = O({\\frac n {\\alpha}})$.\r\n\\\\\r\n\\\\\r\n{\\bf LWE Public scheme: }\r\n$m,n,q \\in {\\mathbb N}$, $m \\geq n, q \\geq 2$, $\\chi$ and error distribution on ${\\mathbb Z}$.  $l$ is plaintext\r\nlength.  ${\\cal M} = \\{0, 1\\}^l$, ${\\cal C} = {\\mathbb Z}_q^n \\times {\\mathbb Z}_q^l$.\r\n\\begin{enumerate}\r\n\\item Keys: Choose \r\n$S \\in {\\mathbb Z}^{n \\times l}$ and \r\n$A \\in {\\mathbb Z}^{m \\times n}$ uniformly at random and choose\r\n$E \\in {\\mathbb Z}^{m \\times l}$  according to $\\chi$.  Public key is $(A, P=AS+e)$.  Secret key is $S$.\r\n\\item to encrypt $v \\in \\{ 0, 1\\}^l$, choose $a \\in \\{0, 1 \\}^m$ uniformly at random.  Cipher is\r\n$(u,c) = (A^Ta, P^Ta + \\lfloor {\\frac q 2} \\rceil v)$.\r\n\\item To decrypt, $D = \\lfloor \\lfloor {\\frac q 2}\\rceil^{-1} (c - S^Tu)\\rceil \\jmod{2}$.\r\n\\end{enumerate}\r\nA decryption error occurs if the magnitude of a coordinate of $E^Ta$ is greater than or equal to ${\\frac q 4}$.\r\nIf $\\chi$ is the discrete gaussian, the coordinates of $E^Ta \\leq \\sqrt{ms}$ with high probability.\r\nAgain, considering a lattice generated by $AS+e$, if we can fins a short vector, we can identify $S$.\r\n\\\\\r\n\\\\\r\nTo convert LWE to a lattice problem, let ${\\vec s}$ is a column of $S$ and ${\\vec e}, {\\vec b}$ be\r\nthe corresponding vectors of $E$ and $P$, respectively in $\\Lambda_q(A^T)$.  This is a closest vector problem.\r\nTo embed it in the shortest vevctor problem, Let $H \\in {\\cal Z}_1^{m \\times m}$ where the columns of $H$ form a\r\nbasis for ${\\cal Z}_q^m$.  Pick $M > 0$.  Consider \r\n$$\r\nB = \r\n\\left(\r\n\\begin{array}{cc}\r\nH &  b \\\\\r\n0 &  M \\\\\r\n\\end{array}\r\n\\right).\r\n$$\r\nLinear combinations of columns of $H$ give a short vector $e' = (e, M)^T$.  Choosing $M$ properly gives $e$ with high probability.\r\n\\\\\r\n\\\\\r\n{\\bf Ring learning with errors (RLWE): }\r\nLWE keys are large.  For ring LWE, use $R = {\\mathbb Z}_q[x]/(x^n + 1)$, where $n$ is a power of  $2$.\r\n$A, s, e$ are replaced by elements of $R$.  The ring-LWE problem is\r\nto find $s  \\in R$ given $a \\in R$ and $b = as+e \\in R$, again $e$ is small according to the error distribution.\r\nThere is a reduction from worst case $SVP_{\\gamma}$ to R-LWE.\r\n\\\\\r\n\\\\\r\n{\\bf LLL example: }  $\\delta = {\\frac 3 4}$, \r\n$b_1 = (2, 3, 14)^T$,\r\n$b_2 = (0, 7, 11)^T$,\r\n$b_3 = (0, 0, 23)^T$.\r\nLLL-reduced basis is \r\n$b_1 = (-2, 4, -3)^T$,\r\n$b_2 = (-4, 2, 6)^T$,\r\n$b_3 = (4, 6, 5)^T$.\r\n\\\\\r\n\\\\\r\n{\\bf GGH example: } \r\n$m= (4, -4, 1,3)^T$.\r\n$r = (-1, 1,1,-1)^T$.\r\n$ B = \\left(\r\n\\begin{array}{cccc}\r\n2 & -3 & 1 & -4 \\\\\r\n-1 & 1 & 0 &4\\\\\r\n-1 & 3 & 2 & 1\\\\\r\n-1 & -4 & 3 & -3\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$ H = \\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0\\\\\r\n0 & 1 & 0 & 0\\\\\r\n0 & 0 & 1 &0\\\\\r\n44 & 18 & 4 &45 \\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$c = Hm+r = (2, 03,2,210)^T$.\r\n$ B^{-1} = {\\frac 1 {49}} \\left(\r\n\\begin{array}{cccc}\r\n61 & 45 & 10 & -27\\\\\r\n-10 & -13 & 8 & -2\\\\\r\n29 & 23 & 16 & -4 \\\\\r\n33 & 38 & 3 & -13 \\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$ H^{-1} = {\\frac 1 {49}} \\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0 \\\\\r\n0 & 1 & 0 & 0 \\\\\r\n\\end{array}\r\n\\right)$.\r\n\\\\\r\n\\\\\r\n{\\bf GGH example: }\r\n$m= (4, -4, 1,3)^T$.\r\n$r = (-1, 1,1,-1)^T$.\r\n$ B = \\left(\r\n\\begin{array}{cccc}\r\n2 & -3 & 1 & -4 \\\\\r\n-1 & 1 & 0 &4\\\\\r\n-1 & 3 & 2 & 1\\\\\r\n-1 & -4 & 3 & -3\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$ H = \\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0\\\\\r\n0 & 1 & 0 & 0\\\\\r\n0 & 0 & 1 &0\\\\\r\n44 & 18 & 4 &45 \\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$c = Hm+r = (2, 03,2,210)^T$.\r\n$ B^{-1} = {\\frac 1 {49}} \\left(\r\n\\begin{array}{cccc}\r\n61 & 45 & 10 & -27\\\\\r\n-10 & -13 & 8 & -2\\\\\r\n29 & 23 & 16 & -4 \\\\\r\n33 & 38 & 3 & -13 \\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$ H^{-1} = {\\frac 1 {49}} \\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0 \\\\\r\n0 & 1 & 0 & 0 \\\\\r\n0 & 0 & 1 & 0 \\\\\r\n{\\frac {-44} {15}} & {\\frac {-18} {49}} & {\\frac {-4} {49}} & {\\frac {1} {49}} \\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n\\\\\r\n\\\\\r\n{\\bf LWE example: } \r\n$n = 4$, $q = 23$, $m = 8$, $\\alpha = {\\frac 5 {23}}$, $\\sigma = {\\frac s {\\sqrt{2 \\pi}}}$, $s = 5$.\r\n$A= \\left(\r\n\\begin{array}{cccc}\r\n9 & 5 & 11 & 13\\\\\r\n0 & 22 & 22 & 22\\\\\r\n6 & 21 & 17 & 18\\\\\r\n22 & 22 & 22 & 0\\\\\r\n0 & 0 & 0 & 0\\\\\r\n0 & 0 & 1 & 2\\\\\r\n1 & 22 & 1 & 22 \\\\\r\n22 & 0 & 0 & 1\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$S= \\left(\r\n\\begin{array}{cccc}\r\n5 & 2 & 9 & 1\\\\\r\n6 & 8 & 19 & 1\\\\\r\n19 & 18 & 9 & 18\\\\\r\n9 & 2 & 14 & 18\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$E= \\left(\r\n\\begin{array}{cccc}\r\n0 & 22 & 1 & 21\\\\\r\n0 & 22 & 22 & 22 \\\\\r\n6 & 21 & 17 & 18\\\\\r\n22 & 22 & 22 & 0\\\\\r\n0 & 0 & 0 & 0\\\\\r\n0 & 0 & 1 & 2\\\\\r\n1 & 22 & 1 & 22\\\\\r\n22 & 0 & 0 & 1\\\\\r\n\\end{array}\r\n\\right)$.\r\n$P= \\left(\r\n\\begin{array}{cccc}\r\n10 & 5 & 21 & 7\\\\\r\n3 & 1 & 13 & 1\\\\\r\n19 & 15 & 6 & 13\\\\\r\n22 & 22 & 22 & 0\\\\\r\n9 & 20 & 20 & 17\\\\\r\n15 & 21 & 1 & 2\\\\\r\n0 & 12 & 3 & 19\\\\\r\n16 & 2 & 7 & 15\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$v = (1,0,1,1)^T$, $a = (1,1,0,1,0,0,1)^T$. $\\lfloor {\\frac {23} 2} v \\rceil = (12,0,12,12)^T$,\r\n$(u, c) = ( (3,14,2,7)^T, (14, 5, 7,5)^T)$.\r\n$m' = c= S^Tu \\jmod{23} = (11,21,12,10)^T$.  $\\lfloor {\\frac {23} 2} v = (12,0,12,12)^T$.\r\nRecover $(1,0,1,1)^T$.\r\n\\\\\r\n\\\\\r\n{\\bf NTRU example: } \r\n$N=5$, $p=3$, $q=29$, $d=1$, $f = x^4 + x^3 - 1$, $g = x^3 - x$.\r\n$m = x^3 + x$.\r\n$f_p = x^3 - x^2 + x - 1$,\r\n$f_q = -5x^4 +8x^3 -3x^2 + 11x + 15$.\r\n$h = f_q g = 8 x^4 + 21 x^3 + 25 x^2 + 20 x + 15 \\jmod{29}$ .\r\n$c = prh + fm \\jmod{29} = 8 x^4 + 21 x^3 + 25 x^2 + 20 x + 15$.\r\n$a = fc \\jmod{29} = -2 x^4 + 2 x^3 + 4 x^2 -3 x + 1$.\r\n$m = x^3 + x$.\r\n\\\\\r\n\\\\\r\n{\\bf NIST contestants: } The contestants use the following security parameters:\r\n\\begin{enumerate}\r\n\\item New hope uses ring LWE with parameters $q=12289$, $n=1024$.\r\n\\item Frodo uses LWE onunstructures lattices with $m=n=1344$, $q= 2^{16}$, $\\sigma = 1.4$,\r\n$-6 \\leq x \\leq 6$, for AES-256 parity.  Cipher text size is $21644$-bytes.  Decoding\r\nerror rate is $2^{-252}$.  The public key size is about 1 Mb.\r\n\\item The NTRU parameters are $n=1024$ $N=743$, $q=2048$, $d_1=11$, $d_2=11$ giving\r\n$256$-bit security.  Public key size about 2 KB.\r\n\\item McElice uses $n=6960$, $k=5413$, $t=119$ with a Goppa code.  The key size\r\nis $8$MB.\r\n\\end{enumerate}\r\n\\section{Symmetric Key Analysis}\r\n{\\bf DES S Box Criteria:} (1) $S$ is not linear or affine in the inputs,\r\n(2) changing 1 bit of input changes at least 2 bits of output, (3)\r\nminimize differences between 1s and 0s if one input bit is held constant,\r\n(4)$Ham(S(x) \\oplus S(x \\oplus 001100))>1$, and\r\n(5) $S(x) \\ne S(x \\oplus 11ab00)$.\r\n\\\\\r\n\\\\\r\n{\\bf Differential cryptanalysis: }  Notation: $ x \\rightarrow y, p$ means\r\ninput difference $x$ produces output $y$ with probability $p$.\r\nIf $x' \\rightarrow y'$ and $D_j(x',y')= \\{u: S_j(u) \\oplus S_j(u \\oplus x')= y'\\}$\r\nthen\r\n$x \\oplus k \\in D_j(x', y')$, and $k \\in D_j(x', y') \\oplus x$.  Set\r\n$\\tau_j (x, x', y')= \\{ k: k \\in D_j(x',y') \\oplus x \\}$ and\r\n$test_j (E_j , {E_j}^*, C_j ' ) = \\tau_j(E_j, E_j \\oplus E_j^{*}, C_j')$.\r\nNote: some candidate keys will scritch.\r\nTo convert from chosen to known attack, select $2^{32} {\\sqrt {2m}}$ pairs,\r\nabout $m$ of these will have the right difference \r\n$x$ produces output $y$ with probability $p$.\r\nIf $x' \\rightarrow y'$ and $D_j(x',y')= \\{u: S_j(u) \\oplus S_j(u \\oplus x')= y'\\}$\r\nthen\r\n$x \\oplus k \\in D_j(x', y')$, and $k \\in D_j(x', y') \\oplus x$.  Set\r\n$\\tau_j (x, x', y')= \\{ k: k \\in D_j(x',y') \\oplus x \\}$ and\r\n$test_j (E_j , {E_j}^*, C_j ' ) = \\tau_j(E_j, E_j \\oplus E_j^{*}, C_j')$.\r\n\\\\\r\n\\\\\r\n{\\bf 3-round attack: } $(L_0 , R_0 )$, $R_3 = L_2 \\oplus\r\nf(R_2 , k_3 )= L_0 \\oplus   f(R_0 , k_1 ) \\oplus f(R_2 , k_3 )$.\r\nChoose ${R_0}' = 000000$, so that\r\n$f(R_0 , k_1 ) \\oplus   f(R_0^* , k_1 ) = 0$, get\r\n$R_3 '  = L_0 ' \\oplus   f(R_2 , k_3 ) \\oplus f(R_2^* , k_3 )$.\r\nSet $C'= P^{-1} (R_3 ' \\oplus L_0 ')$ which is the output xor for round 3.\r\nCompute\r\n$E=E(L_3 )$, $E^*=E(L_3^* )$.  Calculate\r\n$test_j (E_j , {E_j}^*, C_j ' )$, for $j= 1,2,...,8$ after choosing\r\nplaintexts.\r\nCan do this since $R_2= L_3$ is known.\r\nNote that key bits overlap on initial and final rounds and must satisfy both conditions.\r\n\\\\\r\n\\\\\r\n{\\bf Cost of differential cryptanalysis: }  The \\emph{signal to noise ratio},\r\n$S/N$ ratio,\r\nis the ratio of the count in the correct key bin to the average count in a key bin.\r\nFor the differential attack to succeed, $S/N>1$.  Assume there are $m$ pairs of chosen text,\r\n$p$ is probability of characteristic, $k$ is the number of key bins (number\r\nof possible keys),\r\n$\\gamma$ is number of suggested keys per pair.  There are about $mp$ right pairs (and\r\nthe right key is always counted).  If\r\n$\\lambda$ is the ratio of non-discarded pairs to the number pairs, then the average\r\ncount is ${\\frac {\\gamma \\lambda m} {k}}$ and so $S/N= {\\frac {pk} {\\gamma \\lambda}}$.\r\nNote that differential differs from the product of round differential characteristics (which\r\nis what we used); the differential probability considers\r\nall valid pairs with correct first and final round differentials combine (add) to provide\r\nthe differential probability estimate.  \r\nUsually, however, the product of probabilities of the round characteristics\r\nis a good estimate for the differential, if not, other attacks, like related\r\nkey attacks, often work.\r\n\\\\\r\n\\\\\r\n{\\bf 6-round attack:}  Use\r\n$(L_0 ' , R_0 ')= (0x40080000, 0x04000000)$,\r\n$(L_1 ' , R_1 ')= (0x04000000, 0x00000000)$, $p= .25$;\r\n$(L_2 ' , R_2 ')= ( 0x00000000, 0x04000000)$, $p= 1$;\r\n$(L_3 ' , R_3 ') = (0x04000000, 0x40080000)$, $p= .25$.\r\n$L_6 = L_5 \\oplus f(R_5, K_6 )$, $R_4 = L_3 \\oplus f(R_3, K_4 )$, and $L_5= R_4$ so\r\n$L_3 ' \\oplus L_6 ' = f(R_3, K_4 ) \\oplus f(R_5, K_6 ) \\oplus f(R_3^*, K_4 ) \\oplus f(R_5^*, K_6 )$.  \r\nEstimate $L_3 ' = 0x04000000$ and $R_3 ' = 0x40080000$ with $p= {\\frac 1 {16}}$.  \r\nUse this to estimate input xor for S-boxes of round 4.  \r\nGet $C_1 ' C_2 ' ... C_8 ' = P^{-1} (L_6 ' \\oplus 0x04000000)$ and\r\n$E_1 ' E_2 ' ... E_8 ' = E(R_5 )$.  \r\n$f(K_6, R_5) \\oplus f(K_6, R_5^*) = 0$ since xors to $S2, S5, S6, S7, S8 $ are $0$\r\nso $f(K_4, R_3) \\oplus f(K_4,R_3^*)= P^{-1} (L_6 ' \\oplus 0x04000000)$.\r\nRight pairs bump count for correct key bits, wrong pairs are random.  \r\n\\emph{Filter:}   If $|test_j (E_j , {E_j}^*, C_j ' )| = 0 $, for all  $j= 2,5,6,7,8$, this is a\r\nwrong pair; the probability that a wrong pair satisfies this at random is \r\n$({\\frac {4}{5}})^5 = {\\frac 1 3}$ since only ${\\frac 4 5}$ of the differentials are possible\r\nin each S-box.  \r\n${\\frac 2 3}$ of the wrong pairs are detected this way, so\r\nratio of right pairs (``RP'') remaining is ${\\frac {\\frac 1 {16}} {{\\frac 1 {16}} +\r\n{\\frac {15} {16}} \\times {\\frac 1 3}}}= {\\frac 1 6}$.\r\nNumber of suggested pairs is\r\n$\\Pi |test_j (E_j , {E_j}^*, C_j ' )| $, for $j= 2,5,6,7,8$, correct values\r\nwill be suggested ${\\frac {3n} {16}}$ times; incorrect strings at random\r\namong approximately $2^{30}$ values.  Let $T_j$ be the counter vector of length 64.\r\nFor each pair compute $T^i_j$, $j= 2,5,6,7,8$, $1 \\leq i \\leq n$.  For\r\n$I \\subseteq \\{ 1, 2, \\ldots n \\}$, $\\sum_{i \\in I} T^i_j$.  There\r\nshould be some $I$ of size about ${\\frac {3n} {16}}$, this is the\r\nsuggested key.  Here $n$ is the number of pairs and\r\nall of the remaining indexes have $1$ in the vector.\r\n\\\\\r\n\\\\\r\n{\\bf Another 3-round Characteristic:}\r\n$L_0 ' , R_0 '$: 0x00200008, 0x00000400,\r\n$L_1 ' , R_1 '$: 0x00000400, 0x00000000, $p= .25$;\r\n$L_2 ' , R_2 '$: 0x00000000, 0x00000400, $p= 1$;\r\n$L_3 ' , R_3 '$: 0x00000400, 0x00200008, $p= .25$.\r\n{\\bf Iterative Characteristic:} $\\Omega_P= (19 60 00 00 | 00 00 00 00), p= {\\frac 1 {234}}$.\r\nThese can be concatinated.\r\n\\\\\r\n\\\\\r\n{\\bf $5$-round differential and $0$R, $1$R, $2$R attacks:}\r\nThe differential is\r\n$\\Omega_P= (40 00 46 D0 || 02 00 00 00)= \\Omega_T$ consisting of\r\n$02 00 00 00 \\rightarrow 40 00 40 10, p_1= {\\frac {14} {64}}$,\r\n$00 00 06 c0 \\rightarrow 02 00 00 00, p_2= {\\frac {12 \\cdot 16} {64^2}}$,\r\n$00 00 00 00 \\rightarrow 00 00 00 00, p_3= 1$,\r\n$00 00 06 c0 \\rightarrow 02 00 00 00, p_2= {\\frac {12 \\cdot 16} {64^2}}$,\r\n$02 00 00 00 \\rightarrow 40 00 40 10, p_1= {\\frac {14} {64}}$, with total\r\nprobability $p= {\\frac 1 {9511}}$.  \r\nIn the \\emph{$0$-R attack}, \r\nrequest ${\\frac m p}$ pairs with $\\Delta P= \\Omega_P$.\r\nApproximately $m$ pairs survive.  Given ``right pairs,'' $(P_1, P_2), (C_1, C_2)$,\r\nwe obtain $5$-bits of key from subkey $K_5$, using the active S-box, $S_2$, as follows.\r\nTry all $2^5$ key candidates as a guess and calculate $S_2'$, if this is not\r\n$7$ discard.  $14$ pairs survive.  Another right pair reduces this to $2$ after\r\n$3-5$ right pairs, we're done.  A wrong pair satisfying $\\Omega_P \\rightarrow \\Omega_T$\r\noccurs with probability $2^{-64}$.  We can actually do the \r\nfirst and last rounds simultaneously to get $10$ key-bits.  To calculate $m$,\r\nnotice that we get about $2^{-64} {\\frac m p}$ ``wrong pairs'' (``WP'') and the\r\ntotal number of suggested wrong keys suggested is $2^{-54} {\\frac m p}$ which is\r\nnegligible for $m < 2^{36}$.  Since there are $196$ subkeys suggested\r\n$14^2$ values, ``right pair'' must agree on the $2$ shared bits, so\r\n${\\frac 1 4}$ of these survive this filter leaving $49$ subkeys on average.  The right\r\nkey is always among then.  A wrong key is suggested ${\\frac {48} {1023}}m = .05m$ times.\r\nIf $t$ is the threshold for picking the key, \r\n$m= 2, t=2$ succeeds $.276$ of the time,\r\n$m= 4, t=3$ succeeds $.53$ of the time and\r\n$m= 5, t=3$ succeeds $.64$ of the time and\r\n$m= 10, t=5$ succeeds $.91$ of the time.\r\nIn the \\emph{$1$-R attack}, $f'= (40 00 46 D0)$ enters $F$ in sixth round and the pattern\r\n$?0 00 ?? ??$ must emerge this gives a $32+12=44$ bit filter so given $40000$ pairs,\r\nwe expect $40000 \\cdot 2^{-44} < 2^{-28}$ WP's to survive the filter.  Now examine the\r\ninput difference.\r\nIn the \\emph{$2$-R attack}, request $100000$ pairs.  Output of $F$ in seventh round is\r\n$C_L' \\oplus (40 00 46 D0)$ and only $7$ bits after round $7$ are known.  All right pairs\r\nsuggest the correct key in round $7$.  We expect $33$ to suggest keys and $4^8$ subkeys\r\nto be suggested per pair.  $33 \\cdot 2^{16} \\approx 2^{21}$ suggestions and wrong\r\nkeys are suggested ${\\frac {2^{21}} {2^{48}}}= 2^{-27}$ times.\r\nFor linear \\emph{$1$R}, guess subkey on last round and use distinguisher to confirm.\r\nAsk for $N=c q^{-2}$ encryptions.\r\n\\\\\r\n\\\\\r\n{\\bf Linear cryptanalysis:} $\\alpha \\cdot P \\oplus \\beta \\cdot C= \\gamma \\cdot C$ with\r\n$p= {\\frac {1} {2}} + \\delta$ requires about $c \\delta^{-2}$ plaintexts.\r\nLast round estimation:\r\n$L(P) \\oplus M(C) \\oplus N(P_{n-1} , K_n )= P(K)$ then use MLE: $T$= \\# plain\r\ncipher pairs $=0$ if \r\n$|T_{max} - {\\frac {N} {2}}|>|{\\frac {N} {2}} - T_{min}|$\r\nand $p>.5$, guess $P(K)= 0$.\r\n\\\\\r\n\\\\\r\n{\\bf Basic Linear constraints in DES: }\r\n\\begin{center}\r\n\\begin{tabular} {|c|c|c|c|c|}\r\n\\hline\r\n- & SBx & SBox Equation & Round Equation & Prob\\\\\r\n\\hline\r\nA & $5$ & $X[2] \\oplus Y[1,2,3,4]= K[2]\\oplus1$ & $X[17] \\oplus Y[3,8,14,25]= K[26] \\oplus 1$ & ${\\frac {52}{64}}$\\\\\r\nB & $1$ & $X[1,4,5,6] \\oplus Y[1,2,3]= K[1,4,5,6]\\oplus1$ & $X[1,2,4,5] \\oplus Y[3,8,14,25]= K[2,3,5,6] \\oplus 1$ & ${\\frac {42}{64}}$\\\\\r\nC & $1$ & $X[2] \\oplus Y[1,2,3,4]= K[2]\\oplus1$ & $X[3] \\oplus Y[17]= K[4] \\oplus 1$ & ${\\frac {34}{64}}$\\\\\r\nD & $5$ & $X[2] \\oplus Y[1,2,3]= K[2]\\oplus1$ & $X[17] \\oplus Y[8,14,25]= K[26]$ & ${\\frac {42}{64}}$\\\\\r\nE & $5$ & $X[1,5] \\oplus Y[1,2,3]= K[1,5]\\oplus1$ & $X[16,20] \\oplus Y[8,14,25]= K[25,29] \\oplus 1$ & ${\\frac {48}{64}}$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nUsing round bit-numbering (and taking into account expansion and permutation),\r\nthe relation $S_5(x_1+k_1, x_2+k_2, x_3+k_3, x_4+k_4, x_5+k_5, x_6+k_6)+x_2= k_2$\r\nbecomes $X[17] \\oplus Y[3,8,14,25]= K[26] \\oplus 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Best Differential attack on full DES: }\r\nUse $0 \\rightarrow 0$ together with $6$ concatenated $2$-round iterative differential \r\ncharacteristic with $p= {\\frac 1 {234}}$ to obtain a $13$ round with $p= 2^{-47.2}$.\r\nUse $2$R attack on last two rounds.  For first round, we want $19 60 00 00 || 00 00 00 00$\r\nentering round $2$.  If we get $19 60 00 00$ to enter the $F$-function, the output\r\nhas $20$ $0$ bits and $12$ unknown bits. Chose plaintexts so that all possible\r\n$2^{12}$-bit combinations occur in the $12$ bits on corresponding input plaintext.\r\nNow choose $2^{35.2}$ such $12$ bit structures to insure $2^{47.2}$ pairs.  Analyze \r\n$2^{24}$ with difference $19 60 00 00$ in the right hand word yielding\r\n$19 60 00 00 || 00 00 00 00$ after round $14$.  Candidate round $16$ pairs will have\r\n$20$ ciphertext bits with $0$ difference.  Consider $2^{24} \\cdot 2^{-20}$ of these.\r\nAn additional filter is used noting that $S_1$ with an input difference of $3$ can\r\nonly produce $15$ outputs and do the same for round $16$ leaving a survival ratio\r\nof $0.0745$ or $1.19$ pairs from each of the $2^{35.2}$ structures.  Of the survivors,\r\nanalyze the output obtaining the key values for which it can be a ``right'' pair.\r\nThere are $52$ involved bits and $2^{52}$ key values.  Ratio of values that are not\r\ndiscarded in round $16$ analysis is ${\\frac {2^{-32}} {(.8)^8}}$.  \r\nProbability that it\r\nis not discarded in round $1$ or round $15$ analysis is ${\\frac {2^{-12}} {\r\n{\\frac {13} {16}} \\cdot\r\n{\\frac {14} {16}} \\cdot\r\n{\\frac {15} {16}}}}$.  So a key has probability of $.84 \\times 2^{-52}$ of being\r\nsuggested, yielding $1.19 \\times .84 \\approx 1$ key suggestion.  Now try\r\n$2^4$ possible values for the remaining key to confirm.  There are actually two\r\nsuch iterative differential characteristics reducing the complexity by a factor of\r\n$2$.\r\n\\\\\r\n\\\\\r\n{\\bf Best Linear attack on full DES: }\r\nUse the $14$ round approximation with bias $2^{-21.75}$ twice (once in reverse order).\r\nThe basic attack is:\r\n(1) Ask for the encryption of $m$ random texts. (2) for each of the $24$ guessed bits\r\nentering active S-Boxes in first and last round, partially encrypt and decrypt and\r\nstore values of pairs satisfying the approximation.  (3) Guess suggested key with maximal\r\ndeviation from ${\\frac m 2}$.  This would normally involve a work factor of\r\n$2^{43} \\times 2^{24} \\textnormal{ trial encryptions } \\times 4 \\textnormal{ S-boxes}\r\n/ 128= 2^{62}$ but this is reduced to $2 \\cdot (2^{43} \\times 2^{12} \\times 2 / 128= 2^{47}$\r\nby doing each approximation seperately and doing the trial encryption once for each\r\nof the $2^{12}$ possible S-box inputs.  \r\nThis gives $26$ bits $24 + 2 \\textnormal{ from the approximation}$ \r\nwith probability $.85$ and the other $30$ bits\r\nare tried at random.\r\n\\\\\r\n\\\\\r\n{\\bf Note: } Suppose ${\\vec f}: GF(2)^k \\times GF(2)^n \\rightarrow GF(2)^n$.\r\nIf ${\\vec f}({\\vec k}, {\\vec x}_0)= (1,1, \\ldots, 1)$ then\r\n$g({\\vec k}, {\\vec x})= \\prod_{i=1}^n f_i({\\vec k}, {\\vec x})$ is $0$ everywhere except\r\n${\\vec x}= {\\vec x}_0$.\r\n\\\\\r\n\\\\\r\n{\\bf Basic Correlation matrix definitions: }\r\nLet $f,g: GF(2)^n \\rightarrow GF(2)$, define\r\n$C(f,g)= 2 Prob[f(x)=g(x)] -1$, $\\hat{f}(x) = (-1)^{f(x)}$,\r\n$\\langle \\hat{f}, \\hat{g} \\rangle = \\sum_x \\hat{f}(x) \\hat{g}(x) $,\r\n$|| \\hat{f}||= \\sqrt{\\langle \\hat{f}, \\hat{f} \\rangle}$.  Note that\r\n$C(f,g)= {\\frac {\\langle \\hat{f}, \\hat{g} \\rangle} {||\\hat{f}|| \\cdot ||\\hat{g}||}}$.\r\nFor $u \\in GF(2)^n$ define $L_u(x)= u^T \\cdot x$ then \r\n$\\langle \\hat{L}_u , \\hat{L}_v \\rangle= 2^n \\delta (u \\oplus v)$.\r\nWith this notation, the (normalized) \\emph{Walsh transform} is\r\n$F(w)= 2^{-n} \\sum_x (-1)^{f(x) \\oplus L_w(x)} = \r\n2^{-n} \\langle \\hat{f}, \\hat{L}_w \\rangle$.\r\nNote that \r\n$\\hat{f}(x)= \\sum_w {\\frac {\\langle \\hat{f}, \\hat{L}_w \\rangle} \r\n{||\\hat{L}_w|| \\cdot ||\\hat{f}||}} \\hat{L}_w(x)$ or\r\n$\\hat{f}(x)= \\sum_w F(w) \\hat{L}_w(x)$.  Denote ${\\cal W}(f)= F$ and note that\r\n$\\sum_w F(w)^2 =1$.  If ${\\cal BF}_n$ denotes the boolean functions from\r\n$GF(2)^n$ to $GF(2)$,  we can define a map \r\n${\\cal L}: {\\cal BF}_n \\rightarrow {\\mathbb R}^{2^n}$ by $f \\mapsto \r\n( (-1)^{f(0,\\ldots, 0)},\r\n(-1)^{f(0,\\ldots, 1)}, \\ldots,\r\n(-1)^{f(1,\\ldots, 1)})$.\r\nIf \r\n$f(x_1, \\ldots, x_n) = (f_1(x_1, \\ldots, x_n), f_2(x_1, \\ldots, x_n), \\ldots, \r\nf_m(x_1, \\ldots, x_n)) $\r\nthen define the $m \\times n$ \\emph{correlation matrix} as $C^{(f)}= (c_{u,w}), \r\nc_{u,w}= C(u \\cdot f(x), L_w)$.\r\n\\\\\r\n\\\\\r\n{\\bf Fast Hadamard Transform: }\r\n$H_{2^m} = H_2 \\otimes H_{2^{m-1}}$.\r\n$H_{2^m}= M^{(1)}_{2^m} M^{(2)}_{2^m} \\ldots M^{(m)}_{2^m}$,\r\n$M^{(i)}_{2^m}= I_{2^{m-1}} \\otimes H_2 \\otimes I_{2^{i-1}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Observation: }\r\nA \\emph{balanced boolean function} is uncorrelated with either constant function.\r\n\\emph{Question: } What is the best affine approximation of a balanced function?\r\nThe question is important because if $E(k,x)$ is a block cipher on blocks of $n$ bits, \r\neach $E_i(k,x)$ is a balanced boolean function.\r\nHow many inputs satisfy all approximations?  \r\nFor the correct input, what are the expected number of equations\r\nthat agree with it?  Variance, etc.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: }  $\\sum_w F(w) = \\pm 1$.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\n$\\sum_w F(w)= \\sum_w 2^{-n} \\sum_x (-1)^{f(x)+ w \\cdot x}\r\n= 2^{-n} \\sum_x (-1)^{f(x)} (\\sum_w (-1)^{w \\cdot x})=\r\n2^{-n} \\sum_x (-1)^{f(x)} 2^n \\delta_{w,x}$, so\r\n$\\sum_x (-1)^{w \\cdot x+c} =  (-1)^c , w =0, 0, w \\ne 0$.\r\nLet $F(w,c)= \\sum_x (-1)^{f(x +  w \\cdot x + c)}$\r\nthen $\\sum_{w,c} F(w,c)= 0$.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\nIf $h(x)= f(x) \\oplus g(x)$ then $H(w)= \\sum_v F(v \\oplus w) G(v)$.\r\nIf $h(x)= f(x) \\cdot g(x)$ then $\\hat{h}(x)= {\\frac 1 2} (1 + \\hat{f}(x) + \\hat{g}(x) -\r\n\\hat{f}(x) \\cdot \\hat{g}(x)\r\n)$ and hence $H(w) = {\\frac 1 2} (\\delta(w) + \r\n{\\cal W}(f) +\r\n{\\cal W}(g) -\r\n{\\cal W}(f \\oplus g))$.  \r\n\\begin{quote}\r\n\\emph{Proof: }\r\nLet $N= 2^n$.\r\n$\r\n\\sum_u F(u)G(w+u)=\r\n\\sum_u\r\n({\\frac 1 N} \\sum_s (-1)^{f(s)+s \\cdot u})\r\n({\\frac 1 N} \\sum_t (-1)^{g(t)+t \\cdot (w+u)})=\r\n\\sum_u\r\n({\\frac 1 {N^2}} \\sum_t (-1)^{f(s)} (-1)^{g(t)} (-1)^{t\\cdot w} (-1)^{(s+t)\\cdot u}) =\r\n({\\frac 1 {N^2}}) \\sum_t (-1)^{f(s)} (-1)^{g(t)} (-1)^{t\\cdot w} (\\sum_u (-1)^{(s+t)\\cdot u})$. \r\nThe last sum is $0$ unless $s=t$ in which case it's $N$ so\r\n$\\sum_u F(u)G(w+u)= {\\frac 1 N} \\sum_t (-1)^{f(t)+g(t)+w \\cdot t}$.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\nIf $V= V_1 \\oplus V_2$,\r\n$f(u_1 + u_2)= f(u_1)$ and\r\n$g(u_1 + u_2)= g(u_2)$ for $u_1 \\in V_1, u_2 \\in V_2$ and $h(x)= f(x) \\oplus g(x)$ then\r\n$H^{(V)}(u_1 + u_2)= F^{(V_1)}(u_1) G^{(V_2)}(u_2)$.  For example, $h(x, y)= (f(x), g(y))$,\r\n$C^{(h)}=\r\n\\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0 \\\\\r\nF(0) & F(1) & 0 & 0 \\\\\r\nG(0) & 0 & G(1) & 0 \\\\\r\nF(0)G(0) & F(1)G(0) & F(0)G(1) & F(1)G(1)\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: } If \r\n$C^{(f)}$ is invertible, $(C^{(f)})^{-1}= (C^{(f)})^{T}$.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nIf $h$ is invertible, $(C^{(h)})^{-1}= (C^{(h)})^T$.  For a bijection,\r\n$C(u^T h^{-1}(a), w^Ta)= C(u^T b, w^T h(b))= C(w^T h(b), u^T b)^T$,\r\nso, $C^{(h^{-1})}= (C^{(h)})^{-1}$.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\n$f$ is invertible iff $C^{(f)}$ is invertible.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\nThe $\\rightarrow$ direction follows from the inverse formula above.\r\nThe proof of $\\leftarrow$: $(-1)^{u^T h(a)} = \\sum_w C^{(h)}_{u,w} (-1)^{w^T a}$. \r\nIf $C^{(h)}$ is invertible,\r\n$(-1)^{w^T a} = \\sum_u (C^{(h)})^{-1}_{w,u} (-1)^{u^T h(a)}$.  \r\nIf $\\exists x \\ne y: h(x) = h(y)$, substituting into\r\nthe equation above, $(-1)^{w^Tx}=(-1)^{w^Ty}$ and that is just wrong.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\nIf $h(x)= f(g(x))$ then  $ C^{(h)}= C^{(f)} C^{(g)} $.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\n$(-1)^{u^T \\cdot h(a)} =\r\n\\sum_v C^{(f)}_{u,v} (-1)^{v^T \\cdot g(a)}=\r\n\\sum_v C^{(f)}_{u,v} ( \\sum_w C^{(g)}_{v,w} (-1)^{w^T \\cdot a})$.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\nIf $h(x)= x \\oplus a$ then $C^{(f)}_{u,u} = (-1)^{u^T \\cdot a}$.\r\n\\begin{quote}\r\n\\emph{Proof: }\r\n$u^T \\cdot h(a)= u^T \\cdot x \\oplus u^T \\cdot a$.\r\n\\end{quote}\r\n{\\bf Theorem: }\r\nIf $h(x)= Mx$ then $C^{(f)}_{u,w} = \\delta(M^Tu \\oplus w)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$u^T \\cdot h(a)= (M^T u)^T a$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$C_{u \\oplus v, x} = \\sum_w \r\nC_{u , w \\oplus x} \r\nC_{v , w} $.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n${\\cal W}((u \\oplus v)^T h(a)) = {\\cal W}(u^T h(a)) \\otimes {\\cal W}(v^T h(a))$;\r\nnote that first transform on right is \r\n$C^{(h)}_{u,w}$ and second is\r\n$C^{(h)}_{v,w}$.  One consequence is: $C_{u \\oplus v, 0} = \\sum_w C_{u,w} C_{v,w}$.\r\n\\end{quote}\r\n{\\bf Theorem:}  A Boolean transformation is invertible iff every output parity is\r\na balanced binary boolean function of the input bits. \r\n\\begin{quote}\r\n\\emph{Proof:}  Let $C=C^{(h)}$.\r\n$\\rightarrow$: If $h$ is invertible, $C C^T = I$, $C_{00}=1$ and the norm of every\r\nrow and column is $1$.  $C(u^T h(a),0) = \\delta(u)$; all rows except row $0$ are\r\ncorrelated to $0$ hence the function is balanced for $u \\ne 0$.\r\nFor $\\leftarrow$: The condition on\r\noutput parities being balanced is $C_{u,0}=0, u \\ne 0$. i.e.- $C$ is orthogonal.\r\n$C C^T =I \\leftrightarrow \\sum_w C_{u,w} C_{v,w}= \\delta(u \\oplus v)$ (``*'') also\r\n$\\sum_w C_{u,w} C_{v,w} = C_{u \\oplus v,0}$ but $C_{u,0}=0, u \\ne 0$ and $C_{00}=1$\r\nso ``*'' holds $\\forall u,v$ hence $C$ is orthogonal and invertible so by the previous\r\nresult $h$ is invertible.  \r\n\\end{quote}\r\n{\\bf Theorem:} Let $u$ and $w$ are parities then and \r\n$F^u$ denotes the normalized Walsh transform of $u^T {\\vec f}({\\vec x})$ while\r\n$G^w$ denotes the normalized Walsh transform of $w^T {\\vec g}({\\vec x})$ then\r\n$(C({\\vec f},{\\vec g}))_{u,w}= \\sum_v F^u(v) G^w(v)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} A \\emph{linear trail} is \r\n$U= ( u_0, u_1, \\ldots, u_r)$ associated with a composite function\r\n$\\beta= \\rho_r \\rho_{r-1} \\ldots \\rho_1$ with correlation contribution\r\nat each step of $C((u_i^T \\rho_i (a), u_{i-1}a)$ and overall \r\ncorrelation of $C_p(U)= \\prod_i C^{\\rho_i}_{u_{i}, u_{i-1}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$C(u^T \\beta(a), w^T a)= \\sum_{U, u^{(0)}=u, u^{(r)}=w} C_p(U)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Follows from definition.\r\n\\end{quote}\r\n{\\bf Theorem:} The correlation coefficients and spectrum values for a boolean function\r\nover $GF(2)$ are integer multiples of $2^{1-n}$.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe values are of the form\r\n$k+(2^n-k)(-1)=2k-2^n$ which is even.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThe correlation $\\hat{c}_{fg}(b)= C(f(x), g(x \\oplus b))= {\\cal W}^{-1}(FG)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$\\hat{c}_{fg}(b)= 2^{-n} \\sum_a (-1)^{f(a) \\oplus g(a \\oplus b)} = C(f(x), g(x \\oplus b))$.\r\n\\end{quote}\r\n{\\bf ``Bricklayer'' functions:} If \r\n$$h(a(1), \\ldots,a(n))=\r\n(h(1)(a(1), a(2), \\ldots , a(n)), h(2)(a(1), a(2), \\ldots , a(n)), \\ldots,\r\nh(n)(a(1), a(2), \\ldots , a(n))),$$ then\r\n$C^{(h)}_{uv}= \\prod_{i=1}^n C^{h(i)}_{u_i,v_i}$.\r\n\\\\\r\n\\\\\r\n{\\bf Truncating Function:} Let $a'= \\varphi^{v,\\epsilon, s}(a)$ \r\ntaking $\\varphi: GF(2)^{n-1} \\rightarrow GF(2)^{n}$ be\r\ndefined by  $a_i'=a_i$ for $i \\ne s$ and $a_s'= \\epsilon \\oplus v^t a \\oplus a_s$ \r\nwhere $v^Ta= \\epsilon$ defined the restriction.  Then \r\n$C^{\\varphi}_{w,w} =1$, \r\n$C^{\\varphi}_{v \\oplus w,w} = (-1)^{\\epsilon}$, $\\forall w: w_s= 0$; \r\nnote there are two non-zero\r\nentries both of amplitude 1.  \r\nIf $C'= C C^{\\varphi}$,\r\n$C'_{u,w}= C_{u,w} \\oplus (-1)^{\\epsilon} C_{u,v \\oplus w}$ if $w_s=1$ and $0$ if\r\n$w_s=0$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nFor \\emph{key alternating ciphers}, $C_p(U)= \\prod_i (-1)^{u_i^T k_i} C_{u_i, u_{i-1}}\r\n= (-1)^{d_U \\oplus \\bigoplus_i u_{i}^T k_i }\r\n|C_p(U)|$ where $d_U= 1$ if\r\n$\\prod_i (-1)^{u_i^T k_i} C_{u_i, u_{i-1}}<0$\r\nand $0$ otherwise.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$C(v^T \\cdot \\beta(a), w^Ta)=\r\n\\sum_{U, u_0=u, u_r=w} (-1)^{d_U \\oplus U^TK} |C_p(U)|$.\r\n\\\\\r\n\\\\\r\nPut $s_i= U^TK \\oplus d_U$ and $C_i= C_p(U_i) (-1)^{s_i}$, then\r\naveraging over the round keys, for all \r\ntrail, we get:\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$E(C_t^2)= 2^{-n_K} \\sum_k ( \\sum_i (-1)^{s_i} C_i)^2$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$E(C_t^2)\r\n= 2^{-n_K} \\sum_k (\\sum_i (-1)^{U_i^Tk \\oplus d_{U_i} }C_i)^2\r\n= 2^{-n_K} \r\n\\sum_i \\sum_j (\\sum_k (-1)^{(U_i \\oplus U_j)^Tk \\oplus d_{U_i} \\oplus d_{U_j}}C_i C_j)$.\r\nBut $C_i C_j = 2^{n_K} \\delta(i \\oplus j)$.\r\n\\end{quote}\r\nFor key schedule $K=M_{\\kappa}(k)$, $E(C_t^2)= 2^{-n_K} \\sum_i \\sum_j ( \\sum_k\r\n(-1)^{(d_{U_i} \\oplus d_{U_j})^T M_{\\kappa}k \\oplus d_{U_i} \\oplus d_{U_j}})C_i C_j$.\r\nThe inner sum simplifies to \r\n$(-1)^{d_{U_i} \\oplus d_{U_j}}2^{n_K} \\delta(M_{\\kappa}^T(U_i \\oplus U_j))$.\r\nIf key schedule is not linear $K=f_{\\kappa}(k)$, the coefficient of the mixed\r\nterm is $(-1)^{(U_i \\oplus U_j)^T f_{\\kappa}(k) \\oplus d_{U_i} \\oplus d_{U_j}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Observation:}\r\nMultiround linear expressions correspond to\r\nlinear trails.\r\nGenerally, $|C_p(U)|$ is independent of round key but this is not the case in DES because\r\nof the shared bits between S-boxes.  $32$ bit input parities before $E$ give rise to $\\alpha$\r\n$2^{2l}$-$48$ bit patterns.  If $l$ is the number of pairwise neighboring S-boxes,\r\nwe can do this in $16l$ multiplications and additions.\r\nThe probability that a multiround expression holds \r\nis ${\\frac 1 2}(1+C_p(U))$ for the associated\r\ntrail.\r\n\\\\\r\n\\\\\r\n{\\bf Observation:}\r\nAll Hadamard transform values of\r\n\\emph{bent functions} are equal to\r\n$\\pm 2^{\\frac m 2}$ and hence the distance to any affine function is\r\n$2^m \\pm 2^{{\\frac m 2} -1}$.  If $f(x_1, x_2,\\ldots,x_m)$ is bent and $m \\ge 6$ then\r\n$f$ is indecomposable.  \r\n$f(u_1, \\ldots, u_m, v_1, \\ldots, v_m) = \r\ng(v_1, \\ldots , v_m) + \\sum_i u_i v_i$ is bent.\r\nIf $f(u_1, \\ldots, u_m, v_1, \\ldots, v_m) = \\sum_i u_i v_i$, then\r\n$f+u_1 u_2, u_3$, $f+u_1 u_2, u_3 u_4$, \\ldots,\r\n$f+u_1 u_2, u_3 \\ldots u_m$ are all inequivalent bent functions.\\\\\r\n\\\\\r\n{\\bf Correlation Immunity:}\r\nIn this paragraph, $F$ denotes the unnormalized Walsh transform of $f$.  A function\r\n$z=f(x_1 , \\ldots , x_n)$ on $n$ variables \r\n$x_1, \\ldots, x_n$ is $m$-th order \\emph{correlation immune} if for every subset of these\r\nvariables or size $m$, $I(z; x_{i_1}, \\ldots, x_{i_m})=0$.  If\r\n$f$ has correlation immunity $m$ and non-linear order $k$, $m+k \\le n$.  Let \r\n$N_{ab}(\\omega)= | \\{ x: z=f(x)=a, \\omega \\cdot x = b \\} |$ then\r\n$F(\\omega)= N_{10}(\\omega) - N_{11}(\\omega)$.  Denote $p_a = P(z=a)$ then\r\n$P(\\omega \\cdot x = b | z=a)=\r\n{\\frac {P(\\omega \\cdot x=b, z=a)} {P(z=a)}}=p_a^{-1}2^{-n} N_{ab}(\\omega)$.  We obtain the\r\nfollowing:\r\n$P(\\omega \\cdot x=0 | z=1)= {\\frac 1 2} + p_1^{-1} 2^{-n-1} F(\\omega)$,\r\n$P(\\omega \\cdot x=1 | z=1)= {\\frac 1 2} - p_1^{-1} 2^{-n-1} F(\\omega)$,\r\n$P(\\omega \\cdot x=0 | z=0)= {\\frac 1 2} + p_0^{-1} 2^{-n-1} F(\\omega)$,\r\n$P(\\omega \\cdot x=1 | z=0)= {\\frac 1 2} - p_0^{-1} 2^{-n-1} F(\\omega)$.\r\nLet $h(t)= - t lg(t) - (1-t) lg(1-t)$.  \r\n\\\\\r\n{\\bf Theorem 1:}  Let $x_0, \\ldots, x_{n-1}$ be\r\nindependent and uniformly distributed arguments of the boolean function $f$ whose output\r\nis the random variable $z$; then $\\forall \\omega \\ne 0,\r\nI(z; \\omega \\cdot x)= 1 - p_0 h({\\frac 1 2} - {\\frac {F(\\omega)} {2^{n+1} p_0}})\r\n- p_1 h({\\frac 1 2} - {\\frac {F(\\omega)} {2^{n+1} p_1}})$.  \r\nMoreover, when $z$ is uniformly distributed then\r\n$I(z; \\omega \\cdot x)= 1 - h({\\frac 1 2} - 2^{-n} F(\\omega))$.\r\n$F$ thus describes\r\nthe best affine approximation of $f$ (pick $\\omega$ with largest coefficient, the\r\ncoefficients of the best affine approximation has coefficients of 1 for the corresponding\r\nvariables).  This generalizes to\r\n\\\\\r\n{\\bf Theorem 2:}  Let $x_0, \\ldots, x_{n-1}$ be\r\nindependent and uniformly distributed arguments of the boolean function $f_i \\in {\\cal F}$ \r\nwhere ${\\cal F} = \\{ f_1 , \\ldots , f_m \\}$, $p_f= {\\frac 1 m}$ and the \r\noutputs of the randomly selected $f_i$ is the random variable $z$; then $\\forall \\omega \\ne 0,\r\nI(z; \\omega \\cdot x)= 1 - p_0 h({\\frac 1 2} - {\\frac {\\sum_{i=1}^m F_i(\\omega)} {2^{n+1} m p_0}})\r\n- p_1 h({\\frac 1 2} - {\\frac {\\sum_{i=1}^m F(\\omega)} {2^{n+1} m p_1}})$.  \r\nMoreover, when $z$ is uniformly distributed then\r\n$I(z; \\omega \\cdot x)= 1 - h({\\frac 1 2} - 2^{-n+1} m^{-1} \\sum_{i=1}^m F_i(\\omega))$.\r\nAgain, this provides the best affine approximation for the set of functions.  Finally,\r\nthis implies {\\bf Theorem 3:} A boolean function $f$ is correlation immune of order $m$\r\nif $F(\\omega)=0, \\forall \\omega: 1 \\le wt(\\omega) \\le m$. \\\\\r\n\\\\\r\n{\\bf Counting Results:} Let $N=2^n$ and $BF(n)$ denotes the set of boolean functions on $n$-bit\r\nvalues then $|BF(n)|= 2^N$. Let $BBF(n)$ be the balanced functions on $n$ bits then\r\n$|BBF(n)|= {N \\choose {\\frac N 2}}$, $|GA(n)| \\approx 2^{m^2+m}$.\\\\\r\n\\\\\r\n{\\bf The natural isomorphism:}\r\n${\\cal L}: GF(2)^n \\rightarrow {\\mathbb R}^{2^n}$ by $a \\mapsto (-1)^{a^T \\cdot x}$.\r\n${\\cal L}(a+b)= {\\cal L}(a) {\\cal L}(b)$ by pointwise multiplication.  \r\nAlmost directly from the definitions, we get {\\bf Theorem:}\r\n$C^{(h)}({\\cal L}(a))= {\\cal L}(h(a))$.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} The elements of a correlation matrix corresponds to an invertible\r\ntransform of $n$-bit vectors are integer multiples of $2^{2-n}$.  The proof uses\r\nthe restriction map and the fact that $\\sum (F(w) + F(w+v))^2 = 2$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nLet $F_q, q=2^n$, $Tr_{F_q/F_2}(x)=Tr(x)= \\sum_{i=0}^{n-1} x^{2^i}$.\r\n$Tr(x) \\ne 0$ for some $x$.\r\n$Tr(x+y)= Tr(x)+Tr(y)$.\r\n$Tr(x^2)= Tr(x)$.\r\n$Tr(x) \\in F_2$.\r\n$Tr(\\omega x)$ is linear in $x$.\r\n$Tr(\\omega_1 x)= Tr(\\omega_2 x) \\rightarrow \\omega_1 = \\omega_2$.\r\n$Tr(\\omega x)$ are exactly the linear functions.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\n$F: F_{2^n} \\rightarrow F_{2^m}$ is \\emph{differentially $\\delta$ uniform} if\r\n$\\forall \\alpha, \\beta, \\alpha \\ne 0$: $|\\{ x: F(x+\\alpha)+F(x)= \\beta \\}| \\leq \\delta$.\r\n{\\bf Theorem:} $F(x)= x^{2^k + 1}$, $s=(k,n)$ then $F$ is differentially $2^s$-uniform.\r\n$N(F)= 2^{n-1} - 2^{{\\frac {n+s} 2} -1}$.\r\n{\\bf Theorem:}  Let $G(x)= x^{-1}, x \\ne 0; 0, x=0$.  $F$ is differentially 4 uniform.\r\n$N(G) \\geq 2^{n-1}-2^{{\\frac n 2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Boolean functions:}\r\n$a \\vee b = a \\oplus b \\oplus ab$ as a boolean function.  Let ${\\vec x}= (x_4 , x_3, x_2, x_1)$\r\nwith $x_1$ the least significant bit.\r\n${\\vec F} ({\\vec x})=\r\n(F_4 ({\\vec x}), F_3 ({\\vec x}), F_2 ({\\vec x}), F_1 ({\\vec x}))$.\r\nIf $\\rho= (0000, 0001)$ then \r\n${\\vec {F_i^{\\rho}}}({\\vec x})= x_i, i>1$ and \r\n${\\vec {F_1^{\\rho}}}({\\vec x})= \r\n({\\overline {x_2 \\vee  x_3 \\vee x_4}}) (x_1 \\oplus 1) \\oplus\r\n(x_2 \\vee x_3 \\vee x_4) x_1= 1 \\oplus x_1 \\oplus x_2 \\oplus x_3 \\oplus x_4\r\n\\oplus x_2 x_3 \\oplus x_2 x_4 \\oplus x_3 x_4 \\oplus x_2 x_3 x_4$.  If\r\n$\\sigma = (0000, 0001, \\ldots , 1111)$, then\r\n${\\vec {F_1^{\\sigma}}} ({\\vec x})= x_1 \\oplus 1$,\r\n${\\vec {F_2^{\\sigma}}} ({\\vec x})= x_1 (x_2 \\oplus 1) \\oplus {\\overline {x_1}}x_2\r\n= x_1 \\oplus x_2$,\r\n${\\vec {F_3^{\\sigma}}} ({\\vec x})= (x_1 x_2) (x_3 \\oplus 1) \\oplus ({\\overline {x_1 x_2}})x_3\r\n= x_1 x_2 \\oplus x_3$,\r\n${\\vec {F_4^{\\sigma}}} ({\\vec x})= (x_1 x_2 x_3 ) (x_4 \\oplus 1) \\oplus \r\n({\\overline {x_1 x_2 x_3}}) x_4= x_1 x_2 x_3 \\oplus x_4$.\\\\\r\n\\\\\r\n{\\bf Theorem:} $RM(r,m)$ has minimum distance $2^{m-r}$.\r\n$R(1,5)$ has $48$ inequivalent affine classes.\r\n\\\\\r\n\\\\\r\n{\\bf Balence:}\r\nEach possible Boolean transformation on $n$ bits is a permutaion on the $2^n, n$-bit values\r\nand so listing them in order, the columns are the possible ${\\vec f}$ vectors representing the \r\ncomponent functions.  If we label these as points in $GF(2)^{2^n}$ and draw an edge between\r\nallowable co-components with the edges labeled by the correlation between these vectors,\r\nany allowable $n$ boolean functions form a complete graph with the label $0$ on each edge.\r\n$C(f,g)= 1-{\\frac {wt(f+g)} {2^{n-1}}}$.  \r\n{\\bf Generalized Balence Theorem:} For each $n \\le 128$ and each\r\n$1 \\le b_1 < b_2 < \\ldots < b_n \\le 128$ and fixed ${\\vec k}$,\r\n$(E_{b_1} ({\\vec k}, {\\vec x}), E_{b_2} ({\\vec k}, {\\vec x}), \r\n\\ldots , E_{b_n} ({\\vec k}, {\\vec x}))$\r\ntakes each value in ${\\mathbb Z}_2^n$ as ${\\vec x}$ varies over\r\n${\\mathbb Z}_2^n$.  So does any non-trivial sum of any of these functions.\r\n{\\bf Theorem:}  If $f:GF(2)^{n-1} \\rightarrow GF(2)$ is any boolean function,\r\n$g(x_1, \\ldots, x_n)= f(x_1, \\ldots, x_{n-1})+x_n$ is balanced.\r\n\\\\\r\n\\\\\r\n{\\bf Advantage:}\r\nWrite $\\epsilon= E_K$ and $\\epsilon'= E_{K'}$.  What does $[\\epsilon^i, {\\epsilon'}^j]$ reveal\r\nabout $K$ for known $K'$.  Let ${\\cal P}= \\{ p_1 , p_2 , \\ldots , p_m \\}$ and let $l$ be given\r\nput $N= p_1^l \\ldots p_m^l$ and denote the set of $n$-bit elements of the block by\r\n$S$;  what is ${\\mathbb C}_S(\\epsilon^N)$?  \r\nHow do you characterize the $x: g(x)=x$ where, say, $g$ represents $N$ applications of\r\n$\\epsilon$.  \r\nIn general, $\\epsilon$ is complicated but\r\n$\\epsilon^m=1$ for some $m$ and\r\n$\\epsilon^t$ many be much simpler for some $m<t$.\r\nLet $ g^{(0)}_{(i)}(x_1 , x_2 , \\ldots , x_{i-1},x_{i+1}, \\ldots, x_n)=\r\nf(x_1 , x_2 , \\ldots , x_{i-1},0,x_{i+1}, \\ldots, x_n)$.  \r\n{\\bf Idea:} Suppose \r\n$\\epsilon^i$ and $\\epsilon^j$ are relatively easy to determine \r\n(low degree, good approximation whatever)\r\nand $(i,j)=1$ then we can find $a, b: ai+bj=1$ and calculate\r\n$\\epsilon= (\\epsilon^i)^a (\\epsilon^j)^b= \\epsilon$.  Let $B_n(r,{\\vec v})=\r\n\\{ {\\vec x} :  wt({\\vec v} \\oplus {\\vec x}) =r \\}$. $|B_n({\\vec v}, r)|= 2^{n-r}$.  \r\nMotivation for idea is while\r\nthere are lots of ``far away'' approximations of $\\epsilon$ there aren't many near ones.  \r\nHowever,\r\nthere may be close approximations of $\\epsilon^i$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nLet $f$ be the Boolean function defined by\r\n$S^0_f= \\{x: f(x)=0 \\}$ and\r\n$S^1_f= \\{x: f(x)=1 \\}$.  \r\nIf $e_i(x)= E_i(k,x)$ then \r\n$| S^{b}_{e_1} \\cap S^{b}_{e_2} \\cap \\ldots \\cap S^{b}_{e_k} |=2^{n-k}$.  What\r\nare the permutations that fix such a set?\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nLet $f,g: GF(2)^n \\rightarrow GF(2)$ and $N= 2^n$.\r\nLet $a$ be the number of positions where $f$ and $g$ agree and\r\n$d$ be the number of positions where $f$ and $g$ disagree, then\r\n$Pr[(f(x)=g(x)] = {\\frac a {2^n}}$.\r\nNote that\r\n$wt(f \\oplus g)=d= dist(f,g)$.  \r\nNow suppose $g(x)= w \\cdot x$,\r\nthe linear function.  $F(w)= {\\frac 1 {2^n}} \\sum_x (-1)^{f(x)=g(x)}= {\\frac 1 {2^n}} (a-d)$\r\nSince $a+d=2^n$, $F(w)= 2 {\\frac a {2^n}} -1$ and thus $C(f,w)= F(w)$.  These yield\r\n$dist(f(x),w \\cdot x)= 2^n(1-F(w))$.  Thus the best affine approximation is the one which\r\nmaximizes $|F(w)|$ for some $w$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nNow let $f: GF(2)^n \\rightarrow GF(2)$ be a bijective boolean transformation with component\r\nfunctions $f_1 , f_2 , \\ldots , f_n$.  All such transformations represent\r\npermutations in $S_{2^N}$ and the correlation matrices of these transformations is orthogonal\r\n($C C^T = I$).  A block cipher gives rise to such transformations by setting $f(x)= E_K(x)$ for\r\nfixed $K$.  Note that all balanced boolean functions can be obtained by applying a\r\npermutation in $S_{2^N}$ to a sequence of ${\\frac N 2}$, $1$'s and ${\\frac N 2}$, $0$'s.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 1:} \r\nWith the foregoing notation,\r\n$C(f_i,1)= C(f_i,0)=0$, $C(f_i, f_j)=0, i \\ne j$,\r\n$wt(f_i)= 2^{n-1}, \\forall i$, $wt(f_i f_j) = 2^{n-2}, i \\ne j$ and in general,\r\n$wt( f_{i_1} f_{i_2} \\ldots f_{i_k})= 2^{n-k}$.  Further, $C(f_i f_j, f_k)= {\\frac 1 2}$ ,\r\n$C(f_i, f_j, f_k f_l) = C(f_i f_j f_k, f_l)$ and\r\nin general\r\n$C( f_{i_1} f_{i_2} \\ldots f_{i_k}, f_l)= 2^{n-k-1}$. Let $f$ be a boolean function.\r\n{\\bf Theorem 2:}  Let $f$ be a boolean function.  The $N$ functions\r\n$f_{i_1} f_{i_2} \\ldots f_{i_k}$ form a basis for the space of boolean functions; that is,\r\nfor any boolean function $g$,\r\n$\\exists a^{(g)}_{i_1, i_2, \\ldots, i_k}$ such that $g(x)= \\sum_{1\\le i_1 < i_2< \\ldots < i_k = n}\r\na^{(g)}_{i_1, i_2, \\ldots, i_k}\r\nf_{i_1} f_{i_2} \\ldots f_{i_k}$.  In particular, there are such coefficients such that\r\n$x_i= \\sum_{1\\le i_1 < i_2< \\ldots < i_k = n}\r\na^{(x_i)}_{i_1, i_2, \\ldots, i_k} f_{i_1} f_{i_2} \\ldots f_{i_k}$.  Define\r\n$Appx_i(f)= \\{ g: dist(f,g) \\le i \\}$, then $|Appx_i(f)|= \\sum_{j=0}^i{N \\choose i}$.\r\n\\\\\r\n\\\\\r\n$NL(f) \\le 2^{n-1}- 2^{{\\frac n 2} -1}$,  $NL(f) \\le 2^{n-1} +\r\n{\\sqrt {2^n + max_{e \\ne 0} (F(D_e(f)))}}$, where $D_e f = f(x) \\oplus f(x \\oplus e)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem (Rothaus):} Let $n \\ge 4$ of even algebraic degree then any bent function\r\non $GF(2)^n$ has degree $\\le {\\frac n 2}$. An $n$-Boolean function, $f$, is $m$-resilient\r\niff $f$ is balanced and $F(u)=0, \\forall u: wt(u) \\le m$.  \r\nMaiorana-MacFarland class ${\\cal M}= \\{f: f(x,y)=x \\pi(y) \\oplus g(y) \\}$ where $\\pi$ is\r\na permutation on $GF(2)^{\\frac n 2}$ and $g$ is affine.  \r\n$|{\\cal M}|= (2^{\\frac n 2})! 2^{\\frac n 2}$.   \r\nFor \\emph{bent quadratics}, $\\bigoplus_{1 \\le i,j \\le n}\r\na_{ij} x_i x_j \\oplus h(x)$, $h$, affine.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nFor this section, $f:GF(2)^m \\rightarrow GF(2)$.  The \\emph{sensitivity} of $v$\r\nis defined by $S(v) = | \\{ v': f(v) \\ne f(v'), dist(v,v') = 1 \\}|$.  The average sensitivity\r\n$aS(f)= {\\frac 1 {2^m}} \\sum_v S(v)$.  The \\emph{influence} of $x_i$\r\nis defined by\r\n$I(x_i)= Prob(f(x_1,\\ldots,x_{i-1},y,x_{i+1},\\ldots, x_m)$, the probability\r\nthat the function is determined no matter what $y$ is.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Let $f$ be a boolean function of $n$ variables with average\r\nsensitivity $aS(f)=k$.  Let $\\epsilon > 0$ and $M={\\frac k {\\epsilon}}$ then\r\n(1) $\\exists h$ depending on \r\n$exp((2+{\\sqrt {\\frac {2 log(4M)} M}})M)$ variables\r\nsuch that $Prob(f \\ne h) \\le \\epsilon$; and,\r\n(2) $\\exists g$ of degree at most\r\n$exp((2+{\\sqrt {\\frac {2 log(4M)} M}})M)$ such that $Prob(f \\ne g) \\le {\\frac {\\epsilon} 2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Basic Question:}\r\nLet $F$ be a family of $m$ binary $n$-vectors.  How densely packed is $F$?\r\nGiven $b \\le n$, $|F|$, what is the largest possible number of pairs of vectors\r\nin $F$ whose Hamming distance is less than $b$?\r\n\\\\\r\n\\\\\r\n{\\bf Trace and correlation in $GF(2^n)$:}\r\n$C^f_{u,w}= 2^{-n} \\sum_a  (-1)^{Tr(wa)} (-1)^{Tr(u f(a))}$ so the terms are\r\ndetermined by the condition $Tr(wa+uf(a))=0$, if this is satisfied by $r$ values\r\nthe entry is $r 2^{1-n}$.  If a function is linear over $GF(2^n)$, it is linear\r\nover $GF(2)$ but not vice versa.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nLet $r_n$ be the ratio of the number of invertible $n \\times n$ matrices over\r\n$GF(2)$ to the number of $n \\times n$ matrices over $GF(2)$, then\r\n$lim_{n \\rightarrow \\infty} (r_n) \\approx 0.288$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe number of invertible $n \\times n$ boolean matrices is\r\n$t_n= (2^n-1) (2^n-2) \\ldots (2^n-2^{n-1})$.  \r\nThe number of $n \\times n$ boolean matrices is $2^{n^2}$.\r\n$t_n= 2^{\\frac {n(n-1)} 2} (2^n-1)(2^{n-1}-1) \\ldots (2-1)$. \r\nDefine $s_n= (2^n-1)(2^{n-1}-1) \\ldots (2-1)$.\r\nNow \r\n$t_{n+1}= \r\n2^{\\frac {n(n+1)} 2} s_{n+1}= \r\n2^{\\frac {n(n+1)} 2} 2^{-{\\frac {n(n-1)} 2}} (2^{\\frac {n(n-1)} 2} s_{n}) (2^{n+1}-1)= \r\n2^n (2^{n+1}-1) t_{n}$.  \r\nDividing both sides of this by $2^{(n+1)^2}$, we get\r\n$r_{n+1}= {\\frac {t_{n+1}} {2^{(n+1)^2}}}= \r\n{\\frac {2^n} {2^{2n+1}}} \r\n{\\frac {t_{n} } {2^{n^2}}} (2^{n+1}-1) = r_n (1- 2^{-(n+1}))$.  \r\nUsing this recurrence, we get $r_n= \\prod_{i=1}^n (1-2^{-n})$.\r\nThe product approaches $\\approx 0.288$ as $n \\rightarrow \\infty$.\r\n\\end{quote}\r\n{\\bf Question:}  Is there an easy to compute function, $T_K$, obviously non-linear,\r\nso that $T_K E_K T_K^{-1}$ has good linear approximations?\r\nHow do you find such $T_K$?\r\nFinding the best approximation reduces to finding an orthogonal transformation that\r\nmaximizes the largest entry.  Suppose $T$ is such a matrix; if $T$ has all bad affine approximations\r\nis it possible that there is another orthogonal transformation, $R$ with\r\n$T^R= R^{-1} T R$\r\nsuch that $max_{ij}(|(T^R)_{ij}|)> max_{ij}(|(T)_{ij}|)$? If \r\n$\\rho_1 , \\rho_2 , \\ldots , \\rho_n$ is a series of such transformations (like the iterated\r\ncomponents of a block cipher), note that $R^{-1} E_K(x) R= \r\nR^{-1} \\rho_1 R\r\nR^{-1} \\rho_2 R \\ldots\r\nR^{-1} \\rho_n R$ thus raising the possibility of better ``per round'' approximations on a\r\nrelated cipher.\r\n\\\\\r\n\\\\\r\nHere is a motivating example\r\nin ${\\mathbb R}^3$:\r\n$R=\r\n\\left(\r\n\\begin{array}{ccc}\r\ncos(\\varphi) & sin(\\varphi) & 0\\\\\r\n-sin(\\varphi) & cos(\\varphi) & 0\\\\\r\n0 & 0 & 1\\\\\r\n\\end{array}\r\n\\right)$,\r\n$T=\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & cos(\\theta) & sin(\\theta)\\\\\r\n0 & -sin(\\theta) & cos(\\theta)\\\\\r\n\\end{array}\r\n\\right)$ and\r\n$$R^{-1}TR=\r\n\\left(\r\n\\begin{array}{ccc}\r\ncos^2(\\varphi)+cos(\\theta)sin^2(\\varphi) & \r\ncos(\\varphi) sin(\\varphi) - cos(\\theta)cos(\\varphi) sin(\\varphi) & \r\n-sin(\\varphi)sin(\\theta)\\\\\r\n-cos(\\varphi) sin(\\varphi) + cos(\\theta)cos(\\varphi) sin(\\varphi) & \r\nsin^2(\\varphi)+cos(\\theta)cos^2(\\varphi) & \r\nsin(\\varphi)sin(\\theta)\\\\\r\nsin(\\varphi)sin(\\theta) &\r\n-cos(\\varphi)sin(\\theta) &\r\ncos(\\theta) \\\\\r\n\\end{array}\r\n\\right)$$\r\n\\\\\r\n\\\\\r\n$NL(f) \\le 2^{n-1}- 2^{{\\frac n 2} -1}$,  $NL(f) \\le 2^{n-1} +\r\n{\\sqrt {2^n + max_{e \\ne 0} (F(D_e(f)))}}$, where $D_e f = f(x) \\oplus f(x \\oplus e)$.\r\n\\\\\r\n\\\\\r\n{\\bf Prolog to computing DES correlation matrix:}  Let\r\n$f(x_1, x_2, x_3, x_4)= ( x_1 + f_1(x_3 , x_4) , x_2 + f_2(x_3 , x_4) , x_3, x_4)$ (first\r\nposition most significant) then, with least significant positions indexing rows and columns, and\r\n$F_i(w)$ as the Walsh transform for\r\n$f_i(x_3 , x_4)$ and $H(w)$ the Walsh transform of $h(x)= f_1(x)+f_2(x)$.  Bit positions\r\nin this example are $(x_1, x_2 , x_3 , x_4 )$.\r\n$$C^{(f)}=\r\n\\left(\r\n\\begin{array}{cccc|cccc|cccc|cccc}\r\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n\\hline\r\n0 & 0 & 0 & 0 &  F_2(0) &  F_2(1) &  F_2(2) &  F_2(3) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 &  F_2(1) &  F_2(0) &  F_2(3) &  F_2(2) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 &  F_2(2) &  F_2(3) &  F_2(0) &  F_2(1) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 &  F_2(3) &  F_2(2) &  F_2(1) &  F_2(0) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n\\hline\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  F_1(0) &  F_1(1) &  F_1(2) &  F_1(3) & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  F_1(1) &  F_1(0) &  F_1(3) &  F_1(2) & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  F_1(2) &  F_1(3) &  F_1(0) &  F_1(1) & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  F_1(3) &  F_1(2) &  F_1(1) &  F_1(0) & 0 & 0 & 0 & 0 \\\\\r\n\\hline\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  H(0) &  H(1) &  H(2) &  H(3) \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  H(1) &  H(0) &  H(3) &  H(2) \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  H(2) &  H(3) &  H(0) &  H(1) \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  H(3) &  H(2) &  H(1) &  H(0) \\\\\r\n\\end{array}\r\n\\right)$$\r\n{\\bf Feistel:}\r\nA typical round of DES consists of two involutions: $\\tau$ and $\\sigma_k$.\r\n$\\sigma_k (L,R)= (L \\oplus f(R,k), R)$, $f(x,k)= P S_1 S_2 \\ldots S_8 (E(x)+k))$.\r\n$\\tau(L,R)= (R,L)$.\r\nFirst ``line'' of $\\sigma_k$ is \r\n$y_9= x_9 \\oplus S_1^1(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2, x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$,\r\n$y_{17}= \r\nx_{17} \\oplus S_1^2(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2,x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$,\r\n$y_{23}= \r\nx_{23} \\oplus S_1^3(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2,x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$,\r\n$y_{31}=\r\nx_{31} \\oplus S_1^4(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2, x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$.\r\n\\\\\r\n\\\\\r\nSuppose $\\tau (x_1, x_2, x_3, x_4)= (x_3, x_4, x_1, x_2)$, with position $(0001)$ representing\r\n$x_4$, then\r\n$$C^{(\\tau)}=\r\n\\left(\r\n\\begin{array}{cccccccc|cccccccc}\r\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\\\\r\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\\\\r\n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\\\\r\n0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\\\\r\n\\end{array}\r\n\\right).$$\r\nThe column order from left to right in the forgoing is:\r\n$1$, $(x_4)$, $(x_3)$, $(x_4, x_3)$, $(x_2)$, $(x_4, x_2)$, $(x_3, x_2)$, $(x_4, x_3, x_2)$,\r\n$(x_1)$, $(x_4, x_1)$, $(x_3, x_1)$, $(x_4, x_3, x_1)$,\r\n$(x_2, x_1)$, $(x_4, x_2, x_1)$, $(x_3, x_2, x_1)$, $(x_4, x_3, x_2, x_1)$\r\ncorresponding to the ordered sequence $0000, 0001, 0010, \\ldots$.\r\nThe row order from top to bottom is\r\n$1$, $(x_2)$, $(x_1)$, $(x_2, x_1)$, $(x_4)$, $(x_4, x_2)$, $(x_4, x_1)$, $(x_4, x_2, x_1)$, \r\n$(x_3)$, $(x_3, x_1)$, $(x_3, x_2)$, $(x_3, x_2, x_1)$, \r\n$(x_3, x_4)$, $(x_3, x_4, x_2)$, $(x_3, x_4, x_2)$, \r\n$(x_3, x_4, x_1)$, $(x_3, x_4, x_2, x_1)$.\r\n\\\\\r\n\\\\\r\nCorrelation of decomposed function ($g(x_1 , x_2 , \\ldots , x_{k}, h(x_{k+1}, \\ldots, x_{n}))$).\r\nMinimum distance.  \\\\\r\n\\\\\r\n{\\bf Standard Functions:} For $h(x)= x \\oplus k$, $C^{(h)}_{u,u}= (-1)^{u^T \\cdot k}$.  For\r\n$h(x)= Mx \\oplus w$, $C^{(h)}_{u,w}= \\delta(M^Tu \\oplus w)$.\r\n${\\hat {c}}_{fg}= 2^{-n} \\sum_a (-1)^{{\\hat f}(a) {\\hat g}(a+b)}$,\r\n${\\hat {r}}_f= {\\hat {c}}_{ff}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nAll correlation matrices are doubly stochastic and orthogonal.  Correlation matrices for\r\ninvolutions are symmetric.\r\n\\\\\r\n\\\\\r\n{\\bf Round correlation for DES:}\r\nTo calculate the \\emph{round correlation for DES}, \r\ndecompose it into three involutions.  The first,\r\nadds output from odd numbered S-boxes but is otherwise the identity.  The second,\r\nadds output from even numbered S-boxes but is otherwise the identity.  The third transposes $L$\r\nand $R$.  The first and second involutions don't overlap on input variables to the SBoxes so\r\nthe Walsh transforms of components of the S-Boxes are all that is needed.  In both the first\r\nand second transformations, each position affected by an S-box is multiplied by\r\n$(-1)^{w^T \\cdot k}$ (i.e. - $\\pm 1$) for the relevant round keys.\r\nThus, if $\\sigma_k (L,R)= (L \\oplus f(R,k), R)$, $f(x,k)= P S_1 S_2 \\ldots S_8 (E(x)+k))$,\r\nthe first ``line'' is\r\n$y_9= x_9 \\oplus S_1^1(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2, x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$,\r\n$y_{17}= x_{17} \\oplus S_1^2(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2,x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$,\r\n$y_{23}= x_{23} \\oplus S_1^3(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2,x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$,\r\n$y_{31}= x_{31} \\oplus S_1^4(x_{64}+k_1,x_{33}+k_2,x_{34}+k_2, x_{35}+k_2, x_{36}+k_2, x_{37}+k_2)$.\r\n$Tr(C^{(AES)})$ is the number of fixed points of AES. Since $Tr(AB)=Tr(BA)$,\r\n$Tr(C^{(AES)})= Tr( C^{(k_{14})} C^{(k_{13})} \\ldots C^{(k_{1})} C^{(RS)} (C^{(MRS)})^{13})$.\r\n\\\\\r\n\\\\\r\n{\\bf Differentials:} \r\n$b= h(a)$,\r\n$b^*= h(a^*)$, \r\n$b'= b \\oplus b^*$\r\n$a'= a \\oplus a^*$. \r\n$Prob(a', b')= 2^{-n} \\sum_a \\delta(b' \\oplus h(a\\oplus a')+h(a))$.\r\nThis is also called the \r\n\\emph{difference propagation probability} denoted by $R_p(a' \\rightarrow_h b')$ is\r\n$Prob^h(a',b')= 2^{-n} \\sum_a \\delta( b' + h(a+a')+h(a))$; we have \r\n$0 \\le R_p(a' \\rightarrow_h b') \\le 1$.  \r\nThe\r\n\\emph{restriction weight} is defined as $w_r(a' \\rightarrow_h b')= -lg(R_p(a' \\rightarrow_h b'))$\r\n(restriction weight reflect loss of entropy).  $w_c(U)= -lg(|C_p(U)|)$ (correlation weight).\r\nFor bricklayer function, $Prob^{h}(a', b')= \\prod_i Prob^{h_{(i)}}(a'_{(i)}, b'_{(i)})$ and\r\n$w_r (a', b')= \\sum_i w_r(a'_{(i)},b'_{(i)})$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} For the composite function\r\n$\\beta= \\rho_r \\circ \\ldots \\circ \\rho_1$,\r\na \\emph{differential trail} of length $r$, is a sequence\r\n$Q= (q^{(0)}, q^{(1)}, \\ldots, q^{(r)})$ with steps\r\n$(q^{(i-1)}, q^{(i)})$ having difference propagation probability\r\n$Prob^{\\rho_i} (q^{(i-1)}, q^{(i)})$.\r\nEach ``step'' has weight \r\n$w_r^{\\rho^{(i)}} (q^{(i-1)}, q^{(i)})$.  The trail weight is\r\n$w_r(Q)= \\sum_i w_r^{\\rho^{(i)}} (q^{(i-1)}, q^{(i)})$.  \r\n$Prob(a',b')= \\sum_{q^{(0)}=a', q^{(r)}=b'} Prob(Q)$.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$\\sum_{b'} R_p(a' \\rightarrow_h b') =1$.\r\n$Prob(a', b')= 2^{-n} \\sum_{u,w} (-1)^{w^Ta' \\oplus u^T b'} C^2_{u,w}$ and \\\\\r\n$C^2_{u,w}= 2^{-n} \\sum_{u,w} (-1)^{w^Ta' \\oplus u^Tb'} Prob(a', b')$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$Prob(a', b')= 2^{-n} \\sum_{a} \\delta(h(a) \\oplus h(a \\oplus a') \\oplus b')$\\\\\r\n\\jt \r\n$= 2^{-n} \\sum_{a} \\prod_i {\\frac 1 2} (-1)^{h_i(a) \\oplus h_i(a \\oplus a') \\oplus b')}+1$\\\\\r\n\\jt \r\n$= 2^{-n} \\sum_{a} \r\n2^{-m} \\sum_{u} \r\n\\prod_i {\\frac 1 2} (-1)^{u^T \\cdot h(a) \\oplus h(a \\oplus a') \\oplus b')}$\\\\\r\n\\jt \r\n$= 2^{-m} \\sum_{u} (-1)^{u^Tb'}\r\n2^{-n} \\sum_{a} \r\n(-1)^{u^T \\cdot h(a) \\oplus u^T \\cdot h(a \\oplus a'))}$\\\\\r\n\\jt \r\n$= 2^{-m} \\sum_{u} (-1)^{u^Tb'} \\hat{r}_u(a')$\\\\\r\n\\jt \r\n$= 2^{-m} \\sum_{u} (-1)^{u^Tb'}\r\n2^{-m} \\sum_{u} \r\n2^{-n} \\sum_{w} (-1)^{w^Ta'} C^2_{u,w}$\\\\\r\n\\jt \r\n$= 2^{-m} \\sum_{u} (-1)^{u^Tb'}\r\n2^{-m} \\sum_{u,w} \r\n(-1)^{w^Ta' \\oplus u^Tb'} C^2_{u,w}$\\\\\r\n\\end{quote}\r\nFor a differential trail, $Q$,\r\nwith weight $<(n-1)$, $Prob(Q) \\approx 2^{-w_r(Q)}$ (ignore restriction correlations).\r\nFor differential trails with $w_r(Q) \\ge n-1$, the right pair will exist \r\nonly for $2^{n-1-w_r(Q)}$ of the keys.\r\n\\\\\r\n\\\\\r\n{\\bf Block cipher design:} To eliminate low weight trails,\r\nthere are two strategies: (1) Choose S-boxes with difference propagations that have high\r\nrestriction weight and input-output correlations with high correlation weights; or,\r\n(2) Design round transformations so that only trails with many S-boxes occur.\r\nLinear\r\ncryptanalysis requires correlation $> 2^{- {\\frac {n_b} 2}}$ over most rounds.\r\nThis can't happen if we choose the number of rounds so that there are no such linear\r\ntrails with correlation contribution $>n_k^{-1} 2^{- {\\frac {n_b} 2}}$\r\nEach output\r\nparity is correlated to an input parity since $\\sum_w F(w)^2=1$ but if it occurs by\r\nconstructive interference over many trails that share input/output selection then any such \r\nmust be the result of at least $n_k$ linear trails which are unlikely to be key dependent.\r\nDifferential cryptanalysis requires input to output difference propagation with\r\nprobability $>2^{1-n_b}$.  If there are no differential trails with low weight,\r\ndifference propagation results from multiple trails which again will not \r\nlikely be key dependent.\r\n\\\\\r\n\\\\\r\n{\\bf Design strategy for Rijndael:}\r\nChoose number of rounds so that there is no correlation\r\nover all but a few rounds with amplitude significantly \r\nlarger than $2^{- {\\frac {n_b} 2}}$ by insuring there are no \r\nlinear trails with correlation contribution above ${n_k}^{-1} 2^{- {\\frac {n_b} 2}}$\r\nand no differential trails with weight below $n_b$.\r\n\\\\\r\n\\\\\r\n{\\bf Observation:}\r\nExamine round transformations $\\rho= \\lambda \\circ \\gamma$, where\r\n$\\lambda$ is the mixing function and $\\gamma$ is a bricklayer function that\r\nacts on bundles of $n_t$ bits.  Block size is $n_b=m n_t$.  The correlation over\r\n$\\gamma$ is the product of correlations over different S-box positions for\r\ngiven input and output patterns.  Define weight of correlation as $-lg(Amplitude)$.\r\nIf output selection pattern is $\\ne 0$, the S-box is active.  Looking for maximum\r\namplitude of correlations and maximum difference propagation probability.\r\nThe weight of a trail is the sum of the weights of the selection patterns or the\r\nsum of the active S-box positions it is greater than the number of active S-boxes times\r\nthe minimum correlation weight per S-box.  \\emph{Wide trail strategy:} design round transformations\r\nso there are no trails with low bundle weight.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nDefine $w_b(a)$ as the \\emph{bundle weight} of $a$.  \r\n${\\cal B}_d(\\phi)= min_{a, b \\ne a} (w_b(a \\oplus b) + w_b(\\phi(a) \\oplus \\phi(b)))$.\r\n${\\cal B}_l(\\phi, \\alpha)= min_{\\alpha, \\beta, C(\\alpha^Tx, \\beta^T \\phi(x)) \\ne 0} (w_b(\\alpha) + w_b(\\beta))$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} In an alternating key block cipher with $\\gamma \\lambda$ round functions,\r\nthe number of active bundles in a two round trail is $\\ge$ the bundle branch number of\r\n$\\lambda$. If $\\psi= \\gamma \\Theta \\gamma \\lambda$ is a four round function, \r\n${\\cal B}(\\psi) \\ge {\\cal B}(\\lambda) \\times {\\cal B}^c(\\Theta)$ where ${\\cal B}$ can\r\nbe either the linear or differential branch number.  The linear and differential branch\r\nnumbers for an AES round is $5$.\r\n\\\\\r\n\\\\\r\n{\\bf Linearized polynomial:} $L(x) = \\sum_{i=0}^t \\beta_i x^{2^i}, \\beta \\in GF(2^n)$.\r\n\\\\\r\n\\\\\r\n{\\bf Discrete Fourier Transform:} $A_k= \\sum [f(x) + f(0)]x^{-k}$, \r\n$f(x)= \\sum A_k x^k$.  $A_{2^i k} = A_k^{2^i}$.  Coset leaders:\r\n$C_s = \\{s, 2s, 2^2 s , \\ldots , 2^{n_s-1}s \\}$, coset leader $s$ is\r\nsmallest: $s=s 2^{n_s-1} \\jmod{2^n -1}$.  For any non-zero function\r\n$f: GF(2^n) \\rightarrow GF(2)$ can be represented as\r\n$f(x) = \\sum_{k \\in \\Gamma(n)} Tr_1^{n_k} (A_k x^k) + A_{2^n-1} x^{2^n-1}$ where\r\n$\\Gamma(n)$ are the coset leaders $\\jmod{2^n-1}$, $n_k \\mid n$ and\r\n$Tr_1^{n_k}(x)$ is the trace function from \r\n$GF(2^{n_k}) \\rightarrow GF(2)$.\r\nLet $\\alpha$ be a primitive element of $GF(2^n)$ and $f(0)=0$ with\r\n$a_t = f(\\alpha^t), t= 0, 1, 2, \\ldots, 2^n-1$,\r\n$x= x_0 + x_1 \\alpha + x_2 \\alpha^2 + \\ldots + x_{n-1} \\alpha^{n-1}$.\r\n\\\\\r\n\\\\\r\nAny function \r\n$f: GF(2^{n_k}) \\rightarrow GF(2)$ corresponds to a binary sequence with period\r\n$N \\mid 2^n-1$; TBD--- what is $k$.\r\n{\\bf Hadamard-Walsh:} \r\n${\\hat f}(\\lambda)= \\sum_{x \\in GF(2^n)} (-1)^{Tr(\\lambda \\cdot x)+f(x)}$.\r\nPolynomials $\\rightarrow_{eval}$ Periodic sequences $\\leftrightarrow_{trace}$\r\nBoolean Functions.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nBy \\emph{low degree approximations} we mean\r\n$\\exists g \\ne 0: fg= 0$ and $fg$ has low degree\r\n$deg(fg) \\ge deg(f)$.  $| S_d |= \\sum_{i=0}^d {n \\choose i}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nLet $f$ be a boolean function of $n$ variables.  The \\emph{annihilator ideal} of $f$,\r\n$AN(f) = \\{ g: g(x) f(x)=0 \\}, \\forall x \\in GF(2^n)$,\r\n$AN_d(f) = \\{ g \\in AN(f): deg(g(x)) \\le d \\}$.  The \\emph{algebraic immunity},\r\n$AI(f)$, is the smallest degree non-zero polynomial in\r\n$AN(f) \\cup AN(1+f)$.  $AI(f) \\le \\lceil {\\frac n 2} \\rceil$.\r\n\\\\\r\n\\\\\r\n{\\bf NLFSRs:}\r\nSuppose ${\\cal L}$ is an $n$-bit NLFSR based filter generator with filter function\r\n$f$ and that $L$ takes the current $n$-bit state to the next $n$-bit\r\nstate. Suppose the initial state is ${\\vec {x_0}}$. Then\r\nthe generated keystream is $s_t = f \\circ L^t({\\vec {x_0}})$.\r\n$s_t=1$ if $\\exists g \\in AN_d(f): g \\circ L^t({\\vec {x_0}})=0$,\r\n$s_t=0$ if $\\exists h \\in AN_d(1+f): h \\circ L^t({\\vec {x_0}})=0$.\r\nCollect all functions of degree $\\le d$ for $N$ known keystream bits; then,\r\n(1) $g \\circ L^t(x_1, x_2, \\ldots, x_n): \\forall g \\in AN_d(f), \\forall 0 \\le t < N:\r\ns_t=1$; and,\r\n(2) $h \\circ L^t(x_1, x_2, \\ldots, x_n): \\forall g \\in AN_d(1+f), \\forall 0 \\le t < N:\r\ns_t=0$.  Using linearization to solve these equations, requires identifying \r\nthe subset of monomials forming a linear\r\nsystem of up to $\\sum_{i=1}^d {n \\choose i}$ variables.  Gaussian reduction on this\r\nsystem takes time\r\n$O((\\sum_{i=1}^d {n \\choose i})^{\\omega}) \\approx n^{\\omega d}$\r\nwhere $\\omega \\approx 2.37$ and the\r\nthe number of monomials is \r\n$\\approx {\\frac {2 n^d} {d!(dim(AN_d(f))+ dim(AN_d(1+f)))}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Akelarre:}\r\nRounds $0 \\le R <R$.  \r\n$(B_0, B_1, B_2, B_3)= (A_0, A_1, A_2, A_3)<<< K_{13r+4}[25, 26, \\ldots, 31]$. Initial\r\nPrep: $I_j= X_j = K_j$.  Round $r$:\r\n$(I_0', I_1', I_2', I_3')= (I_0, I_1, I_2, I_3)<<< K_{13r+4}[25, 26, \\ldots, 31]$. \r\n$A_R(I_0' \\oplus I_2', I_1' \\oplus I_3')= a_L||a_R$.\r\n$O_0= I_0' \\oplus a_R$,\r\n$O_1= I_1' \\oplus a_L$,\r\n$O_2= I_2' \\oplus a_R$,\r\n$O_3= I_3' \\oplus a_L$.\r\nFinal Out: $Y_j=I_j' + K_{13R+5+j}$.\r\nDescribe $A_R$.\r\n\\\\\r\n\\\\\r\n{\\bf FEAL-4:}  $32$ bit blocks, $64$ bit keys.  \r\nFour round Feistel with input/output whitening.  Key, $K$, is used to generate $12$\r\n$16$-bit keys $K_0 , K_1 , \\ldots , K_{11}$.\r\nTo define the key schedule and the round function $F$ put\r\n$G_0(a,b)= (a+b \\jmod{256}) <<<2$,\r\n$G_1(a,b)= (a+b+1 \\jmod{256}) <<<2$.  \r\nKey Schedule: Define \r\n$f_K: {\\mathbb Z}_2^{32} \\times {\\mathbb Z}_2^{32} \\rightarrow {\\mathbb Z}_2^{32} $ as follows:\r\n$f_K(a,b)= c$, \r\n$a= a_0 || a_1 ||a_2 ||a_3$,\r\n$b= b_0 || b_1 ||b_2 ||b_3$,\r\n$c= c_0 || c_1 ||c_2 ||c_3$, then \r\n$d_1= a_0 \\oplus a_1$,\r\n$d_2= a_2 \\oplus a_3$,\r\n$c_1= G_1(d_1, a_2 \\oplus b_0)$,\r\n$c_2= G_0(d_2, c_1 \\oplus b_1)$,\r\n$c_0= G_0(a_0, c_1 \\oplus b_2)$,\r\n$c_3= G_1(a_3, c_2 \\oplus b_3)$.  Then put \r\n$B_{-2}=0$,\r\n$B_{-1}= K_L$,\r\n$B_{0}= K_R$, and\r\n$B_{i}= f_K(B_{i-2}, B_{i-1} \\oplus B_{i-3})$, \r\n$K_{2(i-1)}= (B_i)_L$,\r\n$K_{2i-1}= (B_i)_R$.\r\nEncryption:\r\nIf $P_L, P_R$ is the cipher input and\r\n$C_L, C_R$ is the cipher output, $L_0= P_L \\oplus (K_4 || K_5)$ and\r\n$R_0= L_0 \\oplus P_R \\oplus (K_6 || K_7)$.  Each round is defined as:\r\n$R_{i+1}= L_i \\oplus F((K_{2(i-1)} || K_{2i-1}) \\oplus R_i)$ and\r\n$L_{i+1}= R_i$.  $F$ is defined by:\r\n$F(x_0, x_1, x_2, x_3) = (y_0, y_1, y_2, y_3)$ where\r\n$y_1=G_1(x_0 \\oplus x_1 , x_2 \\oplus x_3)$,\r\n$y_0=G_0(x_0, y_1)$,\r\n$y_2=G_0(y_1, x_2 \\oplus x_3)$, and\r\n$y_3=G_1(y_2, x_3)$.  Finally, \r\n$C_L= L_4 \\oplus (K_8 || K_9), C_R= R_4 \\oplus L_4 \\oplus (K_{10} || K_{11})$.  Note that\r\n$A_0 \\oplus A_1 = 0x80800000 \\rightarrow F(A_0 ) \\oplus F(A_1 ) = 0x02000000$.\r\nFor differential attack, pick $P_L$ at random and $P_1= 0x8080000080800000$.\r\nSuppose $X'$ is the output differential of $F$ in round 3, $Y'$ is the input differential\r\nto $F$ in round 4 and $Z'$ is the output differential in Round 4, then\r\n$C_L'= 0x02000000 \\oplus Z'$ and $C_R'= C_L' \\oplus Y'$ and $Y=C_L \\oplus C_R$.  Guess $K_3$\r\ncompute $Y, Y^*$ and $Z, Z^*$ and see if differential hold for each guess.\r\nanalysis, denote $S_{i,j}(X)= x_i \\oplus x_j$, $S_i(X)= x_i$.  Then,\r\n$S_5(G_0(a,b))= S_7(a \\oplus b)$ and\r\n$S_5(G_1(a,b))= S_7(a \\oplus b) \\oplus 1$.  The following hold:\r\n$S_{13}(Y)= S_{7,15,23,31}(X) \\oplus 1$,\r\n$S_{5}(Y)= S_{15}(Y) \\oplus S_{7}(X)$,\r\n$S_{15}(Y)= S_{21}(Y) \\oplus  S_{23, 31}(X)$,\r\n$S_{23}(Y)= S_{29}(Y) \\oplus S_{31}(X) \\oplus 1$ and\r\n$a= S_{23, 29}(P_L \\oplus P_R  \\oplus C_L) \\oplus S_{31}(P_L \\oplus C_L \\oplus C_R)\r\n\\oplus S_{31}F(P_L \\oplus C_L \\oplus K_0)$.\r\n\\\\\r\n\\\\\r\n{\\bf RC4 Weakness:}  Let $S_i$ be the state at time $i$, $N= 2^n$ ($n=8$,\r\nusually).\r\nLet $\\langle z_i \\rangle$ be the output sequence.  $P(z_2=0)= {\\frac 2 N}$.\r\n[\\emph{Proof:} Suppose $S_0[2]=0$, $S_0[1] \\ne 2$, $S_0[1]= X$, $S_0[X]= Y$.]\r\nRound 1:\r\n$i=1$, $X=S_0[1]+0$.  Exchange $S_0[1]$ and $S_0[Y]$.  Round 2: $i=2$,\r\n$j= X+S_1[2]=X$,  Output $S_1[S_1[2]+S_1[X]]= S_1[X]= 0$.  So\r\n$P(z_2 = 0) \\approx {\\frac 1 N} + {\\frac 1 N} (1- {\\frac 1 N}) \\approx\r\n{\\frac 2 N}$.  So by Bayes, if $z_2= 0$, we can extract byte of state with\r\nprobability ${\\frac 1 2}$.\r\n\\\\\r\n\\\\\r\n{\\bf WEP Attack:}\r\nWEP is data level encryption using a long term secret $K$ and per message initial vector,\r\n$IV$ which is $3$ bytes which we call $K_0, K_1, K_3$.  The IV and the key bytes $K_3, ...$\r\nform a single RC4 key $K_0, K_1, K_2, K_3, \\ldots$.  Attack involves selecting $IV= 3|255|V$.\r\nThe RC4 initialization at $i=0$ step is\r\n$j= j+S_0+255 = 3 \\jmod {256}$ then swap $S[0], S[3]$; this leaves $S$:\r\n\\begin{center}\r\n\\begin{tabular} {|l|r|r|r|r|r|r|r|r|r|}\r\n\\hline\r\ni & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & ... \\\\\r\n\\hline\r\nS[i] & 3 & 1 & 2 & 0 & 4 & 5 & 6 & 7 & ... \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThe $i=1$ step is\r\n$j= j+S_1+K_1 = 3+1+255 \\jmod {256}= 3$; this leaves $S$:\r\n\\begin{center}\r\n\\begin{tabular} {|l|r|r|r|r|r|r|r|r|r|}\r\n\\hline\r\ni & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & ... \\\\\r\n\\hline\r\nS[i] & 3 & 0 & 2 & 1 & 4 & 5 & 6 & 7 & ... \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThe $i=2$ step is\r\n$j= j+S_2+K_2 = 5+V \\jmod {256}= 3$; this leaves $S$:\r\n\\begin{center}\r\n\\begin{tabular} {|l|r|r|r|r|r|r|r|r|r|}\r\n\\hline\r\ni & 0 & 1 & 2 & 3 & 4 & ... & 5+V & ... & ... \\\\\r\n\\hline\r\nS[i] & 3 & 0 & 5+V & 1 & 4 & ... & 2 & ... & ... \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nFinally, at $i=3$ step is\r\n$j= j+S_3+K_3 = 5+V+S_3+k+3 \\jmod {256}= 6+V+K_3$; this leaves $S$:\r\n\\begin{center}\r\n\\begin{tabular} {|l|r|r|r|r|r|r|r|r|r|r|}\r\n\\hline\r\ni & 0 & 1 & 2 & 3 & 4 & ... & 5+V & ... & 6+V+K[3] & ... \\\\\r\n\\hline\r\nS[i] & 3 & 0 & 5+V & 6+V+K[3] & 4 & ... & 2 & ... & 1 & ... \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n$Stream[0]= S[3]=6+V+K_3$ if initialization stops here.  Attack works if\r\n$S[0], S[1], S[2]$\r\ndon't change.  The probability of this is ${\\frac {253} {256}}^{255} \\approx .0513$.\r\n\\\\\r\n\\\\\r\n$\\Delta^{\\otimes}X =  X \\otimes X^{-1}$.  $r-$round characteristic:  sequence of differences\r\n$\\langle \\alpha_0, \\alpha_1 , \\ldots , \\alpha_r \\rangle$.\r\n{\\bf Definition (Lai):} An iterated cipher is called a Markov cipher if \r\n$Pr( \\Delta C_1= \\beta | \\Delta C_0= \\alpha, C_0= \\gamma)$ is independent of \r\n$\\gamma, \\forall \\alpha , \\beta \\ne e$.  \\emph{Homogeneous Markov Chain:}\r\n$Pr(v_{i+1} | v_i= \\alpha)$ is independent of $i, \\forall \\alpha, \\beta$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf an $r-$round iterated cipher is a Markov and the $r$ round keys are independent and\r\nuniformly distributed then $\\Delta P= \\Delta C_0, \\Delta C_1 , \\ldots, \\Delta C_r$\r\nis a homogeneous Markov chain and\r\n$Pr(\\Delta C_s = \\alpha_s | \\ldots | \\Delta C_1= \\alpha_1 | \\Delta P= \\alpha_0)\r\n= \\prod Pr(\\Delta C_i | \\Delta C_{i-1})$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nLet $P= (p_{ij})$ be the transition probabilities of a homogeneous Markov chain and\r\n${p_{ij}}^s$ is the probability that state $j$ can be reached from state $i$ in\r\n$s$ steps.  A Markov chain is \\emph{ergodic} if it is aperiodic and irreducible.\r\nIf a random cipher is selected from $\\Sigma_{2^n}$, $Pr( P$ is ergodic $) \\rightarrow 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem (OConner):} Most Feistel ciphers are resistant to differential attack.  Let\r\n$p_g$ be the probability of the best linear approximation of $g$.\r\n$|p_g - {\\frac 1 2}| = max_k (max_{\\alpha \\ne 0 \\ne \\beta} | Pr_x(g(x,h) \\cdot \\beta \r\n= x \\cdot \\alpha)- {\\frac 1 2}|)$ and the best $s$ round linear approximation\r\nsatisfies $|p_L -{\\frac 1 2}|^2 \\le |p_g - {\\frac 1 2}|^2$.  For DES, $s \\ge 4$,\r\n$|p_L - {\\frac 1 2}|^2 \\le 8|p_f -{\\frac 1 2}|^4$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nAn $r-$round iterated $2m$ bit block cipher with $r$-round keys each has\r\n$n$ bits.  A \\emph{strong key schedule} is one in which\r\n(1) For any $s$ bits of the $r$ round keys derived from $k$ where $s<rn$, it is ``hard''\r\nto find any of the remaining $rn-s$ bits from the $s$ bits, (2) given a relation between\r\ntwo different master keys, is it ``hard'' to predict the relationship between any of the \r\nround keys.  $\\langle RK_l \\rangle= n MSB(E_{k_i}(IV \\oplus l))$.\r\n\\\\\r\n\\\\\r\n\\section{New Ciphers}\r\n\\subsection{AES-Rijndael}\r\nArithmetic in $GF(2^8 )$ with minimum polynomial $m(x)= x^8 + x^4 +x^3 +x\r\n+1$.  If $m(\\theta)=0$, matrix for multiplication by $\\theta$ over $GF(2)$ is denoted\r\nby $T$ and squaring by $S$, then\r\n$$\r\nT=\r\n\\left(\r\n\\begin{array}{cccccccc}\r\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\r\n1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\r\n1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\r\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\r\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 0  \r\n\\end{array}\r\n\\right), \r\nS=\r\n\\left(\r\n\\begin{array}{cccccccc}\r\n1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 \\\\\r\n0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\r\n1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\r\n1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 \\\\\r\n0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 \\\\\r\n1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\r\n0 & 1 & 0 & 1 & 0 & 0 & 0 & 1  \r\n\\end{array}\r\n\\right)\r\n$$  \r\n$Tr(a)= a + a^p + a^{p^2} + \\ldots + a^{p^{d-1}}$ and\r\n$N(a)= a  a^p  a^{p^2}  \\ldots  a^{p^{d-1}}$.\r\nLinearized polynomial: $L(x)= a_0 x + a_1 x^p + a_2 x^{p^2} + \\ldots + a_{d-1} x^{p^{d-1}}$;\r\nlinear functions can be expressed as linearized polynomials.\r\n\\\\\r\n\\\\\r\n{\\bf Rijndael} input: $p$ consisting of $Nb$ words, $k$ with $Nk$ words.\r\nState: 4 rows, $Nb$ columns.\r\nKey: 4 rows, $Nk$ columns.\r\nBoth key rows are filled in the following order:\r\nFill leftmost column $s_{i,0}, i= 0, 1, 2, 3$,\r\nthen next column, etc.\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\n    Nb/Nk  4   6   8\r\n       4  10  12  14 \r\n       6  12  12  14 \r\n       8  14  14  14 \r\n\r\nRijndael(p, k, Nb, Nk)  {\r\n    ComputeRoundKeys(K, W[i])\r\n    state= p \r\n    AddRoundKey(state)\r\n    for (i=0, i<Nr, i++) {\r\n         for each byte, b in state, ByteSub(b)\r\n         ShiftRow(state)\r\n         if(i<Nr-1) \r\n             MixCol(state)\r\n         AddRoundKey(state)\r\n         }\r\n}\r\n\r\nByteSub(b) {\r\n    t= 0 \r\n    if b!=0 {\r\n        t= 1/b;\r\n    // M= circ(1,0,0,0,1,1,1,1) \r\n    // [Shift right going down].\r\n    // a= (1,1,0,0,0,1,1,0)^T.\r\n    return(Mt + a);\r\n    }\r\n\r\nShiftRow(state) {\r\n    shift right row 1 by 0. \r\n    shift right row 2 by 1. \r\n    shift right row 3 by 2 if Nb<8, \r\n                      3 otherwise. \r\n    shift right row 4 by 3 if Nb<8, \r\n                      4 otherwise. \r\n    }\r\n\r\nMixCol(state) {\r\n    multiply each col of state by \r\n             c(x) (mod  x**4+1);\r\n    // c(x)= 0x03x**3+0x01x**2+0x01x+0x02\r\n    // d(x)= 0x0bx**3+0x0dx**2+0x09x+0x0e\r\n    }\r\n\r\nAddRoundKey(state) {\r\n    state= state + W[i];\r\n    }\r\n\r\nComputeRoundKeys(K[4*Nk], W[Nb*(Nr+1)]) {\r\n    for(i=0; i<Nk; i++) \r\n           W[i]= (K[4i], K[4i+1], \r\n                  K[4i+2], K[4i+3])\r\n    for(i=Nk; i<Nb*(Nr+1)); i++) {\r\n        t= W[i-1];\r\n        if((i mod Nk)==0)\r\n           t= SubByte(RotByte(t))^RCon(i/Nk);\r\n        if((i mod Nk)==4 and Nk>6)\r\n           t=SubByte(t);\r\n        W[i]= W[i-Nk] ^ t;\r\n        }\r\n    }\r\n\r\nSubByte(w) {\r\n    w= ByteSub(w);\r\n    }\r\n\r\nRotByte(w= (a,b,c,d)) {\r\n    w= (b,c,d,a);\r\n    }\r\n\r\nRCon[i]= (RC[i], 0x00, 0x00, 0x00);\r\nRC[1]= 0x01;\r\nRC[i+1]=  RC[i]*x (x in poly over GF(2));\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\nNote $[ShiftRow, MixCol]=1$.  Rounds Key: $ K_{r,0}, K_{r,1}, \\ldots , K_{r,15}$.\r\nFirst Round is input key.  For $s= r+1$, \r\n$T_0 = S[K_{r,13}] + \\theta^r$,\r\n$T_1 = S[K_{r,14}]$,\r\n$T_2 = S[K_{r,15}]$,\r\n$T_3 = S[K_{r,12}]$ and \r\n$K_{s,i}= K_{r,i}+T_i, 0 \\le i \\le 3$, \r\n$K_{s,i}= K_{r,i}+K_{s, i-4}, 4 \\le i \\le 15$.  Note that key expansion is\r\nequivalent to: \r\n$W[i]= W[i-1] \\oplus W[i-4]$, if $i \\ne 0 \\jmod{4}$\r\n$W[i]= T(W[i-1]) \\oplus W[i-4]$, if $i = 0 \\jmod{4}$ where\r\n$T(a,b,c,d)= \r\n(SB(b) \\oplus r(i), SB(c), SB(d), SB(a)), r(i)= 0x02^{\\frac {i-4} 4}$\r\nin $GF(2^8)$.\r\nInverse provides linear/differential immunity,\r\nlinear diffusion provides algebraic complexity.\r\n\\\\\r\n\\\\\r\n$$\r\nL=\r\n\\left(\r\n\\begin{array}{cccccccc}\r\n1 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\\\\r\n1 & 1 & 0 & 0 & 0 & 1 & 1 & 1 \\\\\r\n1 & 1 & 1 & 0 & 0 & 0 & 1 & 1 \\\\\r\n1 & 1 & 1 & 1 & 0 & 0 & 0 & 1 \\\\\r\n1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\\\\r\n0 & 1 & 1 & 1 & 1 & 1 & 0 & 0 \\\\\r\n0 & 0 & 1 & 1 & 1 & 1 & 1 & 0 \\\\\r\n0 & 0 & 0 & 1 & 1 & 1 & 1 & 1  \r\n\\end{array}\r\n\\right), \r\n\\left(\r\n\\begin{array}{c}\r\ny_7 \\\\\r\ny_6 \\\\\r\ny_5 \\\\\r\ny_4 \\\\\r\ny_3 \\\\\r\ny_2 \\\\\r\ny_1 \\\\\r\ny_0\r\n\\end{array}\r\n\\right)\r\n= L\r\n\\left(\r\n\\begin{array}{c}\r\nx_7 \\\\\r\nx_6 \\\\\r\nx_5 \\\\\r\nx_4 \\\\\r\nx_3 \\\\\r\nx_2 \\\\\r\nx_1 \\\\\r\nx_0\r\n\\end{array}\r\n\\right)\r\n$$\r\n$S[w]= L[w^{(-1)}] + 0x63$.   Combined RowShift, ColumnMix and Diffusion and AddRound is\r\n$x \\mapsto Mx + 0x63 + k_i$ where $M$ is a $16 \\times 16$ matrix and\r\n$min_M (x)= (x+1)^{15}) | (x^{16} +1)$ which can be transformed into\r\n$P^{-1} M P= V_1 \\oplus \\ldots \\oplus V_{15}$ with $dim(V_i)= (16, 14^3, 10^3, 8^2,6,4,4^4,2)$.\r\n\\\\\r\n\\\\\r\n{\\bf AES Design Overview:}\r\n\\emph{Linear cryptanalysis resistance for AES design} is provided if no linear trail has a\r\ncorrelation coefficient $>2^{\\frac n 2}$.  \\emph{Differential cryptanalysis resistance} is\r\nprovided if there is no differential trail with prop ratio $>2^{1-n}$.  \r\nThe \\emph{prop ratio} of differential trail is \r\napproximately the product of the prop ratios of its active S-boxes.\r\nThe \\emph{correlation} of a linear trail is approximately the \r\nproduct of the I/O correlations of its active S-boxes.  \r\nThe \\emph{wide trail} strategy is: (1) choose an S-box with maximum\r\nprop ratio and correlation $\\approx 2^{-6}, 2^{-3}$, respectively; \r\n(b) construct diffusion layer\r\nin such a way that there are no multiple round trails with few active S-boxes.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe weight of a two round trail with $Q$ active columns at the input \r\nand output is $\\ge 5Q$; The minimum number of active \r\nS-boxes in a four round differential or linear trail is $25.$\r\n\\subsection{Tea, TwoFish}\r\n\\begin{verbatim}\r\nTea(unsigned K[4], ref unsigned L, ref unsigned R) {\r\n    unsigned d= 0x9e3779b9;\r\n    unsigned s= 0;\r\n    for(int i=0; i<32;i++) {\r\n        s+= d;\r\n        L+= ((R<<4)+K[0])^(R+s)^((R>>5)+K[1]);\r\n        R+= ((L<<4)+K[2])^(L+s)^((L>>5)+K[3]);\r\n        }\r\n    }\r\n\\end{verbatim}\r\n(1) 4 different $8 \\times 8$ bijective, key dependent S boxes.\r\n(2) MDS code.\r\n(3) PHT: $a'= a+b \\jmod{2^{32}}$,\r\n$b'= a+2b \\jmod{2^{32}}$.\r\nBasic algorithm: whiten, 16 rounds, whiten. \\\\\r\n$$\r\nMDS= \r\n\\left(\r\n\\begin{array}{cccc}\r\n0x01 & 0xef & 0x5b & 0x5b\\\\\r\n0x5b & 0xef & 0x5b & 0x01\\\\\r\n0xef & 0x5b & 0x01 & 0xef\\\\\r\n0xef & 0x01 & 0xef & 0x5b\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\n$Round(w_1 , w_2 , w_3 , w_4 , k_1 , k_2 )= (w_1 ', w_2 ', w_1 , w_2 )$:\r\n$w_1 '= w_3 + F_1 (w_1 , w_2 , r) >>> 1$;\r\n$w_2 '= (w_4 <<< 1)+ F_1 (w_1 , w_2 , r)$;\r\n$F_r (w, v) = PHT(g(w), g(v<<<8)) + k_r \\jmod{2^{32}}$;\r\n$g(x, y, z,w) = MDS \r\n\\left(\r\n\\begin{array}{c}\r\nS_1 (x) \\\\\r\nS_2 (y) \\\\\r\nS_3 (z) \\\\\r\nS_4 (w) \\\\\r\n\\end{array}\r\n\\right)$.  All calculations over $GF(2^8 )$.\r\n\\subsection{Miscellaneous}\r\n{\\bf Cramer-Shoup:} $G= {\\mathbb Z}_p$, $G= \\langle g \\rangle= \\langle g' \\rangle$, $H$, \r\na collision resistant hash whose\r\nimage is ${{\\mathbb Z}_p}^*$.  $PK= (G, g, g', h, k, k')$, $s, t, t', u, u'$ randomly\r\nselected.  $h=sg$, $k=tg+t'g'$, $k'=ug+u'g'$.  Encrypt (m): Choose $r$,\r\nrandom,\r\nset $n= H(rg | rg' | m+rnk')$.\r\n$E(m)= (x, y, z, w)= (rg, rg', m+rh, rk+rnk')$. Decryption: $D(x, y, z, w)$,\r\ncheck that $(nu+t)x + (nu'+t'))y=w$.  If so, compute $z-sx$.\r\n\\\\\r\n\\\\\r\n{\\bf Bit Commitment and coin flips:} $b, b' \\in \\{0,1\\}$. Alice sends Bob\r\n$c=commit(b)$, Bob sends Alice $b'$, Alice sends Bob $reveal(c)$.  Result is\r\n$b \\oplus b'$.\r\n\\\\\r\n\\\\\r\n{\\bf Zero Knowledge} using 3 color:  For each round, Prover randomly permutes colors\r\nand $commits$ color at each vertex.  For each round, Verifier asks to\r\n$reveal$ color at the vertices of an edge.\r\nblob: commit with equality.\r\n\\\\\r\n\\\\\r\n{\\bf Shalevi-Micali Commit:} $h$ is a one way function like $SHA1$.\r\n$commit(m)= h(r||m)$, $r$, random.  $p$ a 161 bit prime.  Pick\r\n$a, b$: $ax+b=z \\jmod{p}, y=h(x), c=(y,a,b)$.  $reveal(c)= x,m$.\r\n\\\\\r\n\\\\\r\n{\\bf Time memory tradeoff:}\r\nFix a plaintext block, $P$ and pick $SP_{i}, i= 1,2, \\ldots, m$.\r\nFor each $i$, set $K_0^i = SP_i$ and $K_{j+1}^i= F(E(K_j^i, P)), j= 0, 1, \\ldots , t-1$\r\nwhere $F$ is a randomizing function to avoid short cycles and put $EP_i=K_t^i$.  \r\nFor each $i$, store $(SP_i, EP_i)$. Phase 2: Get $C=E(P, K)$ from oracle\r\nwhere $K$ is unknown.  Compute\r\n$X_0= C$, $X_{i+1}= E(P, X_i)$ until $X_i= EP_j$ for some $i, j$.\r\nThen compute $Y_0= EP_j$ and $Y_{j+1}= E(P, Y_j)$ until $Y_k = C$ then\r\n$K= Y_{k-1}$.  If $m$ is the number of starting points for each $F$, $t$ is the number of\r\nencryptions per chain and $r$ is the number of tables.  Attack requires $mr$ memory\r\nand $tr$ time with the probability of success $1- e^{-{\\frac {trm} k}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Nostradamus (``herding'') attack:}  Let $h$ be a\r\nMerkle-Damgard hash with compression function $f$ and initial value $IV$.\r\nGoal is to hash a prefix value (P) quickly by appending random suffixes (S).\r\nProcedure Phase 1:  Pick $k$ and generate $2^k$ random values $d_{0i}$ from each pair of\r\nthe values $f(IV||d_{i, i+1})$ find two messages \r\n$M_{0,j}, M_{1,j}$ \r\nwhich collide under $f$ and call this value $d_{1,j}$\r\nthis takes effort $2^{n/2}$ for each pair.  Keep doing this (colliding\r\n$d_{i,j}, d_{i+1,j}$ under $M_{i,j}, M_{i+1,j}$ to produce $d_{i, j+1}$\r\nuntil you reach $d_{2^k , 0}$.  This is the diamond.  Publish $y= w(d_{2^k , 0})$\r\nwhere $w$ is the final transformation in the hash as the hash (i.e. - claim $y=h(P||S)$.\r\nThe cost of phase 1 is $(2^k-1) 2^{n/2}$.  In phase 2, guess $S'$ and compute\r\n$T= f(IV||P||S')$; keep guessing until $T$ is one of the $d_{ij}$.  Once you get a \r\ncollision, follow a path through the $M_{ij}$ to $d_{2^k, 0}$, append these $M_{ij}$ to\r\n$P||S'$ and apply $w$ to get right hash.\r\n\\section{Cryptographic Hashes}\r\n{\\bf Weak collision resistance:} Given $x$, it is computationally infeasible to\r\nfind $x' \\ne x$ with $h(x)=h(x')$.\r\n{\\bf Strong collision resistance:} It is computationally infeasible to\r\nfind $x' \\ne x$ with $h(x)=h(x')$ for any $x$, $x'$.  \r\n{\\bf One-way:} Given a\r\ndigest $z$, it is computationally infeasible to find $x$ with $h(x)=z$.\r\nStrongly collision resistant implies one-way. \\\\\r\n\\\\\r\n{\\bf Merkle Damgard construction:}  $z_0= IV, z_{i+1}= f(z_i, m_i), h(m)= g(z_r)$,\r\nwhere $f$ is a compression function, $r$ is the number of rounds and\r\n$m= m_1 || m_2 || \\ldots || m_r$.  If $f$ is\r\ncollision resistant then so is $h$.\r\n{\\bf Hash from Block Cipher:} $m= m_1 || m_2 || \\ldots || m_r$,  $H_0 = IV$, $H_i = E_{m_i}(H_{i-1}) \\oplus H_{i-1}$,\r\n$H(m)= f(H_i)$.  is the Meyer-Davis construction.\\\\\r\n$g_i = e_{g_{i-1}} (x_i ) + x_i $,\r\n$g_i = e_{g_{i-1}} (x_i ) + x_i + g_{i-1}$,\r\n$g_i = e_{g_{i-1}} (g_{i-1} + x_i ) + x_i $,\r\n$g_i = e_{g_{i-1}} (g_{i-1} + x_i ) + g_{i-1} + x_i $.\r\n\\\\\r\n\\\\\r\n{\\bf Chaum Hash:} $\\alpha$,\r\n$\\beta$ two primitive elements of ${\\mathbb Z}_p$,\r\n$h(x,y)= \\alpha^{x} \\beta^{y} \\jmod{p}$.  If there's a collision,\r\n$log_{\\alpha} (\\beta )$ can be computed efficiently. $h(0^{t+1} || y_1)$,\r\n$g_{i+1} = h(g_i || 1 || y_{i+1})$. Do reduction proof.\r\n\\\\\r\n\\\\\r\n{\\bf Iterative construction is vulnerable to multi-collision (Joux):}  Suppose\r\n$M_1,M_1'; M_2,M_2'; \\ldots ; M_t,M_t'$ all collide.  From these we get  $2^t$ collisions.  \r\nIf $r$ people each have one of $N$ possible birthdays, there is a greater than $.5$ chance\r\nof $k$ collisions if\r\n$r > N^{\\frac {k-1} k}$.  Prove this fact.\r\n\\\\\r\n\\\\\r\n{\\bf Random Oracle Model:} \r\nLet $f$ be a OWF with trapdoor, $(y_1, y_2)= (f(r) , h(r) + m)$ is used as encryption.\r\nAn oracle with $l$ requests $L$, $Pr(guess \\; right)= P( r \\in L) + {\\frac 1 2} P( \\neg r \\in L)$.  \r\nSet $p= {\\frac 1 2}+e$,\r\n$e \\le Pr(r \\in L)$.  \r\nCanetti, Goldreich, Halevi constructed a cryptosystem that is secure in Random Oracle Model but \r\ninsecure for any concrete hash.\r\n\\\\\r\n\\\\\r\n{\\bf MD-4:}  In description below, K[0]= 0, K[1]= 0x5a827999, K[2]= 0x6ed9eba1.\r\n$F(A,B,C) = (A \\wedge B) \\vee (\\neg A \\wedge C)$,\r\n$G(A,B,C) = (A \\wedge B) \\vee (A \\wedge C) \\vee (B \\wedge C)$,\r\n$H(A,B,C) = (A \\oplus B) \\oplus C$.  $W_i= X_{\\sigma(i)}, i= 0, 1, \\ldots, 47$.\r\n$Q_{-4}= A$,\r\n$Q_{-3}= D$,\r\n$Q_{-2}= C$,\r\n$Q_{-1}= B$.\r\n$Q_i(A,B,C)= (Q_{i-4} + F(Q_{i-1}, Q_{i-2}, Q_{i-3}) + W_i + K_0)<<<s_i, 0 \\le i \\le 15$,\r\n$Q_i(A,B,C)= (Q_{i-4} + G(Q_{i-1}, Q_{i-2}, Q_{i-3}) + W_i + K_1)<<<s_i, 16 \\le i \\le 31$,\r\n$Q_i(A,B,C)= (Q_{i-4} + H(Q_{i-1}, Q_{i-2}, Q_{i-3}) + W_i + K_2)<<<s_i, 32 \\le i \\le 47$.\r\n\\begin{verbatim}\r\nMD-4(Y[0] , ..., Y[N-1])\r\n    K[0]= 0; K[1]= 0x5a827999; K[2]= 0x6ed9eba1; \r\n    (A, B, C, D)= (0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476);\r\n    for(i=0; i<(N/16); i++) {\r\n        X[j]= Y[16i+j], j= 0, 1, ..., 15;\r\n        W[j]= X[SIGMA(j)], j= 0, 1, ..., 47;\r\n        Q[-4]= A;\r\n        Q[-3]= D;\r\n        Q[-2]= C;\r\n        Q[-1]= B;\r\n        // Calculate Q[i] recursively according to formula above\r\n        (A, B, C, D)+= (Q[44], Q[45], Q[46], Q[47]);\r\n        (A, B, C, D)= (A, D, C, B);\r\n        }\r\n    return (A, B, C, D);\r\n\\end{verbatim}\r\n{\\bf Dobbertin attack on MD4, steps 20-35}  \r\nLet $M$ and $M'$ be $512$ bit messages consisting\r\nof $16$, $32$-bit works $X_0 , X_1 , \\ldots, X_{15}$ with $X_i=X_i'$ for all $i$ except\r\n$i=12$ and let $X_{12}' = X_{12}+1 \\jmod {2^{32}}$.  We want to find a collision.\r\n$\\Delta_i= (Q_j'- Q_j, Q_{j-1}'-Q_{j-1}, Q_{j-2}'-Q_{j-2}, Q_{j-3}' - Q_{j-3})$ after\r\nstep $i$.  Dobbertin attack consists of three steps: (1) Show that if\r\n$\\Delta_{19}= (0, 2^{25}, -2^5,0)$ then $\\Delta_{35}= (0, 0, 0, 0)$ with probability\r\n$p> 2^{-30}$ (actually,\r\n$p> 2^{-22}$); (2) get conditions on $M$ (i.e. on the $X_i$) based on\r\nround $12$, that guarantee $\\Delta_{19}= (0, 2^{25}, -2^5,0)$; (3)\r\nfind $X_0, X_1, \\ldots , X_{11}$ that produce candidates that present the desired\r\nconditions at step $12$, after about $2^{22}$ of these, you'll get a collision.\r\nThe work factor is about $2^{20}$. \\\\\r\n{\\bf 1.}  Steps 19-35.  Suppose \r\n$\\Delta_{19}= (0, 2^{25}, -2^5,0)$ and \r\n$G(Q_{19}, Q_{18}, Q_{17})= G(Q_{19}', Q_{18}', Q_{17}')$, then the following table\r\nholds:\r\n\\begin{center}\r\n\\begin{tabular} {|r|rrrr|rrcc|}\r\n\\hline\r\n$j$&$\\Delta(Q_{j})$&$\\Delta(Q_{j-1})$&$\\Delta(Q_{j-2})$&$\\Delta(Q_{j-3})$&$i$&$s_j$&$p$&In\\\\\r\n\\hline\r\n$19$& $2^{25}$&$-2^5$&$0$&$0$&$*$&$*$&$*$&$*$\\\\\r\n$20$& $0$&$2^{25}$&$-2^5$&$0$&$1$&$3$&$1$&$X_{1}$\\\\\r\n$21$& $0$&$0$&$2^{25}$&$-2^5$& $1$&$5$&${\\frac 1 9}$&$X_{5}$\\\\\r\n$22$& $-2^{14}$&$0$&$0$&$2^{25}$& $1$&$9$&${\\frac 1 3}$&$X_{9}$\\\\\r\n$23$& $2^6$&$-2^{14}$&$0$&$0$& $1$&$13$&${\\frac 1 3}$&$X_{13}$\\\\\r\n$24$& $0$&$2^6$&$-2^{14}$&$0$& $1$&$3$&${\\frac 1 9}$&$X_{2}$\\\\\r\n$25$& $0$&$0$&$2^6$&$-2^{14}$& $1$&$5$&${\\frac 1 9}$&$X_{6}$\\\\\r\n$26$& $-2^{23}$&$0$&$0$&$2^6$& $1$&$9$&${\\frac 1 3}$&$X_{10}$\\\\\r\n$27$& $2^{19}$&$-2^{23}$&$0$&$0$& $1$&$13$&${\\frac 1 3}$&$X_{14}$\\\\\r\n$28$& $0$&$2^{19}$&$-2^{23}$&$0$& $1$&$3$&${\\frac 1 9}$&$X_{3}$\\\\\r\n$29$& $0$&$0$&$2^{19}$&$-2^{23}$& $1$&$5$&${\\frac 1 9}$&$X_{7}$\\\\\r\n$30$& $-1$&$0$&$0$&$2^{19}$& $1$&$9$&${\\frac 1 3}$&$X_{11}$\\\\\r\n$31$& $1$&$-1$&$0$&$0$& $1$&$13$&${\\frac 1 3}$&$X_{15}$\\\\\r\n$32$& $0$&$1$&$-1$&$0$& $2$&$3$&${\\frac 1 3}$&$X_{0}$\\\\\r\n$33$& $0$&$0$&$1$&$-1$& $2$&$9$&${\\frac 1 3}$&$X_{8}$\\\\\r\n$34$& $0$&$0$&$0$&$1$& $2$&$11$&${\\frac 1 3}$&$X_{4}$\\\\\r\n$35$& $0$&$0$&$0$&$0$& $2$&$15$&$1$&$X_{12}, X_{12}+1$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Steps 12 to 19}.\r\nTo get $\\Delta_{19}= (0, 2^{25}, -2^5,0)$,\r\n$Q_{16}=Q_{16}'$,\r\n$Q_{19}=Q_{19}' + 2^{25}$,\r\n$Q_{18} + 2^5 =Q_{18}'$,\r\n$Q_{17}=Q_{17}'$  and\r\n$Q_{i}=Q_{i}', 8 \\le i \\le 11$.\r\n\\begin{center}\r\n\\begin{tabular} {|r|ccc|}\r\n\\hline\r\n$j$&$i$&M In & M' In\\\\\r\n\\hline\r\n12 &0&$X_{12}$&$X_{12}+1$\\\\\r\n13 &0&$X_{13}$&$X_{13}$\\\\\r\n14 &0&$X_{14}$&$X_{14}$\\\\\r\n15 &0&$X_{15}$&$X_{15}$\\\\\r\n16 &1&$X_{0}$&$X_{0}$\\\\\r\n17 &1&$X_{4}$&$X_{4}$\\\\\r\n18 &1&$X_{1}$&$X_{8}$\\\\\r\n19 &1&$X_{12}$&$X_{12}+1$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThese yield the following conditions:\r\n$(Q_{12}' <<< 29) - (Q_{12} <<< 29) =1$,\r\n$F(Q_{12}', Q_{11}, Q_{10}) - F(Q_{12}, Q_{11}, Q_{10})= (Q_{13}'<<<25) - (Q_{13}<<<25)$,\r\n$F(Q_{13}', Q_{12}, Q_{11}) - F(Q_{13}, Q_{12}, Q_{11})= (Q_{14}'<<<21) - (Q_{14}<<<21)$,\r\n$F(Q_{14}', Q_{13}, Q_{12}) - F(Q_{14}, Q_{13}, Q_{12})= (Q_{15}'<<<13) - (Q_{15}<<<13)$,\r\n$G(Q_{15}', Q_{14}', Q_{13}) - G(Q_{15}, Q_{14}, Q_{13})= Q_{12} - (Q_{12}'$,\r\n$G(Q_{16}', Q_{15}', Q_{14}) - G(Q_{16}, Q_{15}, Q_{13})= Q_{13} - (Q_{13}'$,\r\n$G(Q_{17}', Q_{16}', Q_{15}) - G(Q_{17}, Q_{16}, Q_{14})= \r\nQ_{12} - Q_{12}' + (Q_{18} <<< 23) - (Q_{18} <<< 23)'$,\r\n$G(Q_{18}', Q_{17}', Q_{16}) - G(Q_{18}, Q_{17}, Q_{15})= \r\nQ_{15} - Q_{15}' + (Q_{19} <<< 19) - (Q_{19} <<< 19)')$.  \r\nChoose $Q_{14}, Q_{15}, \\ldots , Q_{19}$ arbitrarily and solve for\r\n$\r\nQ_{10}, Q_{13},\r\nQ_{13}', Q_{14}',\r\nQ_{15}'$, use the $Q$'s to solve for $X_j , j= 0, 4, 8, 12, 13, 14, 15$.\r\nFor the solutions,\r\n$$(Q_{10}, Q_{11}, Q_{12}, Q_{13}, Q_{14}, Q_{15}, Q_{16}, \r\nQ_{17}, Q_{18}, Q_{19}, Q_{12}', Q_{13}', Q_{14}', Q_{15}'),$$ $\\Delta_{19}$ will hold\r\nif\r\n$X_{13}= \\; anything$,\r\n$X_{14}= (Q_{14} <<< 21) - Q_{10} -F(Q_{13}, Q_{12}, Q_{11}) $,\r\n$X_{15}= (Q_{15} <<< 13) - Q_{11} -F(Q_{14}, Q_{13}, Q_{12}) $,\r\n$X_{ 0}= (Q_{16} <<< 29) - Q_{12} -G(Q_{15}, Q_{14}, Q_{13}) - K_1 $,\r\n$X_{ 4}= (Q_{17} <<< 27) - Q_{13} -G(Q_{16}, Q_{15}, Q_{14})  - K_1$,\r\n$X_{ 8}= (Q_{18} <<< 23) - Q_{14} -G(Q_{17}, Q_{16}, Q_{15})  - K_1$,\r\n$X_{12}= (Q_{19} <<< 19) - Q_{15} -G(Q_{18}, Q_{17}, Q_{16})  - K_1$,\r\n$Q_{ 9}= (Q_{13} <<< 25) -F(Q_{12}, Q_{11}, Q_{10}) - X_{13}$,\r\n$Q_{ 8}= (Q_{12} <<< 19) -F(Q_{11}, Q_{10}, Q_{09}) - X_{12}$.  Can choose\r\n$Q_{12}= -1$, $Q_{12}'=0$, $Q_{11}=0$ to simplify.\r\nThis means we can pick\r\n$Q_{14}, Q_{15}, Q_{16}, Q_{17}, Q_{18}, Q_{19}$ \r\narbitrarily and determine\r\n$Q_{10}, Q_{13}, Q_{13}', Q_{14}', Q_{15}'$ subject to the checks\r\n$ G(Q_{15}, Q_{14}, Q_{13}) - G(Q_{15}', Q_{14}', Q_{13}') = 1$ and\r\n$ F(Q_{14}', Q_{13}', 0) - F(Q_{14}, Q_{13}, -1) -\r\n(Q_{15}' <<< 13) + (Q_{15} <<< 13) = 0$.  Finally, we must insure the solutions is\r\nadmissible by checking that\r\n$G(Q_{19}', Q_{18}', Q_{17}) = G(Q_{19}, Q_{18}, Q_{17})$.  Under these circumstances\r\nthe solution is a candidate for the differential.  Once one candidate is found\r\nuse the ``continuity'' of $F$ and $G$ by modifying one bit of the candidate at a time,\r\nthe continuity makes it likely this will work. \\\\\r\n{\\bf Steps 0 to 11}.  Having found $Q_{8 }, Q_{9 }, Q_{10}, Q_{11}$ such that\r\n$$MD4_{12, \\ldots, 47}(Q_{8 }, Q_{9 }, Q_{10}, Q_{11}, X)=\r\nMD4_{12, \\ldots, 47}(Q_{8 }, Q_{9 }, Q_{10}, Q_{11}, X')$$\r\nwe need to find\r\n$MD4_{0, \\ldots, 11}(IV,X) = (Q_{11}, Q_{10}, Q_{ 9}, Q_{ 8})$.  We are free\r\nto choose\r\n$X_j, j= 1,2,5,6,7,9,10,11$.  We pick\r\n$ X_{ 1}, X_{ 2}, X_{ 3}, X_{ 5} $ at random and compute\r\n$ X_{ 6}, X_{ 7}, X_{ 9}, X_{10} , X_{11} $ such that\r\n$MD4_{6, \\ldots, 11}(Q_{2 }, Q_{3 }, Q_{ 4}, Q_{ 5}, X)=\r\n(Q_{11}, Q_{10}, Q_{ 9}, Q_{ 8})$.  Since\r\n$Q_{11}= (Q_{7} +F(Q_{10}, Q_{ 9}, Q_{ 8}) + X_{11}) <<<19$,\r\nif can do this by making\r\n$X_{11}= (Q_{11} <<< 13) - Q_{7} - F(Q_{10}, Q_{ 9}, Q_{ 8})$ and\r\nsimilarly for $X_{10}, X_{9}$.  We can't do this for $X_9$ but since\r\n$Q_{ 8}= (Q_{4} +F(Q_{ 7}, Q_{ 6}, Q_{ 5}) + X_{8}) <<< 3$, if\r\n$Q_7= -1, Q_6= (Q_8 <<< 29) -Q_4 -X_8$ the desired equation holds for\r\nall such $X_8$; in particular, by picking\r\n$X_{6}= (Q_{6} <<< 21) - Q_{2} - F(Q_{5}, Q_{4}, Q_{3})$ and\r\n$X_{7}= (Q_{7} <<< 13) - Q_{3} - F(Q_{6}, Q_{5}, Q_{4})$.  These\r\nguarantee $\\Delta_{35}= 0$.\r\n\\begin{tabbing}\r\n\\= \\kill\r\n{\\bf SHA1}\\= ($M$,\\= $n$)  \\=\\\\\r\n// $M$ is message, $n$ is number of 512 bit blocks \\\\\r\n    \\> M= SHA1Pad(M)  \\\\\r\n    \\> $f_i(B,C,D)= (B \\wedge C) \\vee ({\\overline B} \\wedge D), 0 \\leq i \\leq 19$ \\\\\r\n    \\> $f_i(B,C,D)= (B \\oplus C \\oplus D), 20 \\leq i \\leq 39$\\\\\r\n    \\> $f_i(B,C,D)= (B \\wedge C) \\vee (B \\wedge D) \\vee (C \\wedge D), 40 \\leq i \\leq 59$ \\\\\r\n    \\> $f_i(B,C,D)= (B \\oplus C \\oplus D), 60 \\leq i \\leq 79$\\\\\r\n    \\>\\\\\r\n    \\> $K_i= 0x5a827999, 0 \\leq i \\leq 19; K_i= 0x6ed9eba1, 20 \\leq i \\leq 39$\\\\\r\n    \\> $K_i= 0x8f1bbcdc, 40 \\leq i \\leq 59; K_i= 0x6a62c1d6, 60 \\leq i \\leq 79$\\\\\r\n    \\>\\\\\r\n    \\> $H_0= 0x67452301, H_1= 0xefcdab89 , H_2= 0x98badcfe , H_3= 0x10324576 ,\r\n\tH_4= 0xc3d2e1f0 $\\\\\r\n    \\>\\\\\r\n    \\>for (\\=i=0, $i<n$, i++) \\{\\\\\r\n    \\>     \\> $M_i= W_0 || W_1 || \\ldots || W_{15}$\\\\\r\n    \\>     \\> for($j=16, j<80, j++$) \\{\\\\\r\n    \\>     \\>\t\\> // $ROTL^1$ below is difference between SHA-0 and SHA-1 \\\\\r\n    \\>     \\>\t\\> $W_j= ROTL^1(W_{j-3} \\oplus W_{j-8} \\oplus W_{j-14} \\oplus W_{j-16})$\\\\\r\n    \\>     \\>\t\\> \\}\\\\\r\n    \\>     \\> $A= H_0, B=H_1, C=H_2, D=H_3, E=H_4$\\\\\r\n    \\>     \\> for($j=0, j<80$; j++) \\{\\\\\r\n    \\>     \\>\t\\> $ROTL^5$ below is correlated to lowest wt differential \\\\\r\n    \\>     \\>\t\\> $t= ROTL^5(A) + f_j(B,C,D) + E + W_j + K_j$\\\\\r\n    \\>     \\>\t\\> $E= D, D=C, C=ROTL^{30}(B), B=A, A=t$\\\\\r\n    \\>     \\>\t\\> \\}\\\\\r\n    \\>\t   \\> $ H_0+= A, H_1+= B, H_2+= C, H_3+= D, H_4+= E $\\\\\r\n    \\>     \\>\\}\r\n\\end{tabbing}\r\n\\begin{verbatim}\r\nSHA-1Pad(x)   // with MD strengthening\r\n    Append 1 and enough 0's until there are 64 bits remaining \r\n    Append size hashed in 64 bit format \r\n    return(x)\r\n\\end{verbatim}\r\n{\\bf Shamir's non-linear functions with maximal period:} $x \\rightarrow x^2 \\wedge c$,\r\n$x \\rightarrow x + 4 h(x) +1$. \\emph{Example:} $x \\rightarrow (x+1)(2x+1)$.\r\n\\\\\r\n\\\\\r\n{\\bf SHA-3 (Keccak):}\r\nBasic mixing function is $Keccak-f[b]$.  $b= r+c$.\r\n$b= 25, 50, 100, 200, 400, 800, 1600$.  For SHA-3, $r=1024$, $c=576$, $b=1600$.\r\n$w= {\\frac b {25}}= 2^l$, $n_r= 12+2l$.  So for SHA-3, $n_r= 24$. State $s[b]$\r\nis addressed by $a(x,y,z)= w(5y+x)+z$, little endian. Terminology:\r\nrow, constant $(y, z)$, column, constant $(x, z)$, lane, constant $(x, y)$.\r\nPad: $10^*1$.\r\n\\begin {multicols} {2} {\r\n\\begin{verbatim}\r\nKeccak-f[r,c](A, RC)\r\n    for(i=0;i<nr;i++)\r\n        A= Round[b](A,RC);\r\n\r\nrot(W,r)\r\n    W[(i+r)(mod laneSize)]= W[i];\r\n\r\nRound[b](A, RC)\r\n    C[x]= A[x,0]^A[x,1]^A[x,2]^A[x,3]^A[x,4];\r\n    D[x]= C[x-1]^rot(C[x+1], 1);\r\n    A[x,y]= A[x,y]^D[x];\r\n    B[y,2x+3y]= rot(A[x,y], r(x,y));\r\n    A[x,y]= B[x,y]^(NOT(A[x,y]) AND B[x+2,y]); \r\n    A[0,0]= A[0,0]^RC;\r\n\r\n    r(x,y)  x=3  x=4  x=0  x=1  x=2\r\n    y=2      25   39    3   10   43\r\n    y=1      55   20   36   44    6\r\n    y=0      28   27    0    1   62\r\n    y=4      56   14   18    2   61\r\n    y=3      21    8   41   45   15\r\n\r\nKeccak-f[r,c](M)\r\n    P=M||(0x01 0x00 ... 0x00;\r\n    P^=   0x80;\r\n    s[i,j]= 0;\r\n\r\nAbsorb(P[i])\r\n    s[x,y]^= P[i][x+5y];\r\n    s= Keccak-f[r,c]\r\n\r\nSqueeze(k)\r\n    first k bits of s\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\r\n$\r\n\\left(\r\n\\begin{array}{c}\r\n1 \\\\\r\n0\r\n\\end{array}\r\n\\right)=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & 2 \\\\\r\n1 & 3 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{c}\r\nx \\\\\r\ny\r\n\\end{array}\r\n\\right)\r\n$.  $rc[t]= x^t \\jmod{x^8+x^6+x^5+x^4+1}$, $RC[i_r][0,0][2^j-1]= rc[j+7i_r], 0 \\leq j <l$.\r\nDistinguisher: $2^{\\frac b 2}$.\r\nInner collision: $n^2 2^{-(c+1)}$.\r\nState recovery: $n m 2^{-c}$.\r\n\\\\\r\n\\\\\r\n{\\bf Changes from MD4 to MD5:} (1) 64 steps, function for final 16 rounds is\r\n$I(A,B,C)= B \\oplus (A \\vee \\neg C)$, (2) $G(A,B,C)= (A \\wedge C) \\vee (B \\wedge \\neg C)$,\r\n(3) each round uses different constant, (4) each step adds result of previous step,\r\n(5) the order of input words to the steps is different,(6) shift values are different.\r\nChinese attack uses ``precise'' differential (signed difference) where $0$ indicates no difference,\r\n$+$ indicates $1 \\rightarrow 0$ difference and\r\n$-$ indicates $0 \\rightarrow 1$ difference.\r\nThis is different from both xor and modular difference; for example,\r\nif $z'= 10100101, z= 10010101$, $\\nabla(z', z)= 00+-0000$.\r\n\\\\\r\n\\\\\r\n{\\bf Chinese attack on MD5.}  Attack proceeds in four\r\nphases: (1) specify input differential patters via modular difference (hard and\r\n``done by hand'' according to Wang), (2) specify output differential pattern (only 1 known)\r\nthat is easily satisfied in earlier rounds, (3) derive sufficient conditions propagation;\r\n(4) generate pairs of $1024$ bit numbers that satisfy 3 (deterministically when possible).\r\nTo do step 4: (a) generate $M_0$ at random; (b) use single step modification to\r\n$M_0$ to satisfy sufficient conditions; (c) use multi-step modifications to insure\r\nconditions hold in middle rounds; (d) check conditions for all remaining steps; (e-f)\r\ndo the same for $M_1$; compute $M_0'= M_0 + \\Delta M_0$ and\r\n$M_1'= M_1 + \\Delta M_1$ according to the input differential.  \r\n{\\bf Conditions:}  $T_j= F( Q_{j-1}, Q_{j-2}, Q_{j-3}) + Q_{j-4} + K_j + W_j$, \r\n$R_j= T_j <<< s_j$, $Q_j= Q_{j-1} + R_j$, now apply modular difference and\r\nderive conditions on $\\Delta T_j$ and $\\Delta Q_j$ for differential (below) to\r\nhold.\r\n\\\\\r\n\\\\\r\n$\\Delta X = X' - X$.\r\n$\\Delta H_0 \\rightarrow_{(M_0, M_0')} \\Delta H_1 \\rightarrow_{(M_1, M_1')} \r\n\\Delta H_2 \\ldots \\rightarrow_{(M_{i-1}, M_{i-1}')} \r\n\\Delta H_i = H$ with each composed of\r\n$\\Delta H_i \\rightarrow_{P_2} \\Delta R_{i+1,1} \r\n\\rightarrow_{P_2} \\Delta R_{i+1,2} \\rightarrow_{P_3} \\Delta R_{i+1,3} \r\n\\rightarrow_{P_4} \\Delta R_{i+1,4} = \\Delta H_{i+1}$.\r\nLet $\\Delta{i,j}= x_{i,j}' - x_{i,j} = \\pm 1$ and\r\n$\\Delta x_{i}[ j_1 , j_2 , \\ldots , j_l ]= x_{i}[ j_1 , j_2 , \\ldots , j_l] - x_{i}$.\r\nCollision is caused by 1024 bit input: $(M_0, M_1)$ with\r\n$\\Delta M_0= (0,0,0,0,2^{31}, 0,0,0,0,0,0,2^{15},0,0,2^{31},0)$ and\r\n$\\Delta M_1= (0,0,0,0,2^{31}, 0,0,0,0,0,0,-2^{15},0,0,2^{31},0)$.  \r\nSufficient conditions\r\ninsure that differential holds with high probability.  At 8th iteration, \r\n$b_2= c_2+(b_1+F(c_2,d_2,a_2)+m_7+t_7)<<<22$,\r\nwe try to control \r\n$(\\Delta c_2 , \\Delta d_2, \\Delta a_2, \\Delta b_1) \\rightarrow \\Delta b_2$ with the\r\nfollowing (A) non-zero bits of $\\Delta b_2$:\r\n$d_{2,11}=1, b_{2,1}=0$,\r\n$d_{2,26}= {\\overline {a_{2,26}}}=1, b_{2,16}=0$,\r\n$d_{2,28}= {\\overline {a_{2,28}}}=0, b_{2,i}=0$,\r\n$d_{2,11}=1, b_{2,24}=0$;\r\n(B) zero bits of $\\Delta b_2$:\r\n$c_{2,i}=0$,\r\n$d_{2,i}= a_{2,i}$,\r\n$c_{2,1}=1$,\r\n$d_{2,6}={\\overline {a_{2,6}}}=0$,\r\n$d_{2,i}= 0$,\r\n$d_{2,12}= 1$,\r\n$a_{2,24}= 0$, \r\n7th bit of $c_2, d_2, a_2$ result in no change in $b_2$.\r\nAlgorithm 1: Repeat until first block is found (a) Select random $M_0$, \r\n(b) Modify $M_0$,\r\n(c) $M_0, M_0'= M_0 + \\Delta M_0$ produce $\\Delta M_0 \\rightarrow (\\Delta H_1, \\Delta M_1)$\r\nwith probability $2^{-37}$, (d) Test characteristics.\r\n2: Repeat until first block is found (a) Select random $M_1$, \r\n(b) Modify $M_1$,\r\n(c) $M_1, M_1'= M_1 + \\Delta M_1$ produce $\\Delta M_1 \\rightarrow 0$\r\nwith probability $2^{-30}$, (d) Test characteristics.\r\n\\\\\r\n\\\\\r\n{\\bf Comments from NIST:} Randomization (prevent offline computation for herding):\r\n$RMX(r, M_1 | \\ldots | M_L)= (r| m_1 \\oplus r | \\ldots | m_L \\oplus r)$.\r\n$H_r(M_1 | \\ldots | M_L)= H(r| m_1 \\oplus r | \\ldots | m_L \\oplus r)$.  Transmit $r$.\r\nHerding attack: first committing to an output $h$, \r\nthen mapping messages with arbitrary starting values to $h$.  Joux:  If\r\n$H_1, H_2$ are n bit hashes;  $H_1(M) || H_2(M)$ can be broken in\r\n$O(n2^{\\frac n 2})$.  \\emph{Haifa:} $h_{i+1} = CF(h_i , M_i , bitlength, salt)$.\r\n\\\\\r\n\\\\\r\n{\\bf Joux attack on SHA-0: }\r\nIdea is to linearize by replacing $+$ with $\\oplus$, as well as replacing $MAJ$ and $IF$\r\nwith $\\oplus$.  This is ``SHI-1.''\r\nNow select the collision in two steps.  \r\nFirst, ignoring message expansion a $5$-round correction for a\r\nlocal collision is: \r\n$\\delta= W_1^{(i)} \\oplus W_2^{(i)}$,\r\n$\\delta= ROL^{5}(W_1^{(i+1)} \\oplus W_2^{(i+1)})$,\r\n$\\delta= W_1^{(i+2)} \\oplus W_2^{(i+2)}$,\r\n$\\delta= ROL^{30}(W_1^{(i+3)} \\oplus W_2^{(i+3)})$,\r\n$\\delta= ROL^{30}(W_1^{(i+4)} \\oplus W_2^{(i+4)})$,\r\n$\\delta= ROL^{30}(W_1^{(i+5)} \\oplus W_2^{(i+5)})$.\r\nSince message expansion reduces the freedom of choice,\r\nno changes can be introduced in the last $5$ rounds because there is\r\nno way to correct them.  We focus on expansion patterns in bits $j, j+5, j+30$.\r\nFor a $5$-round correction, about ${\\frac 1 {32}}$ possible ones will work beacuse they\r\nfollow the message\r\nexpansion.  Now we look at candidate collisions $(W, \\Delta)$.  Taking into account\r\nthe non-linearized version, we focus on patterns in the high order bit (which has no carries) and\r\ncan calculate the probability of successful propagations of $1 \\rightarrow 1$ and $1 \\rightarrow 0$\r\ntransitions through $MAJ$ and $IF$.  The strategy is to choose $\\Delta$ and then find $W$.\r\n\\\\\r\n\\\\\r\nAttack expands by studying ``SHI-2'' which leaves $\\oplus$ in SHI-1 but reintroduces\r\n$MAJ$ and $IF$.  Effects of $MAJ$ and $IF$ are separated into four cases:\r\n(1) No change in $b,c,d$ (the only bits affecting the $f_i$;\r\n(2) Change in one bit of $b$;\r\n(3) Change in one bit of $c$ or $d$;\r\n(4) Change in one bit of each of $c$ and $d$.\r\n``SHI-3'' takes SHI-1 and reintroduces the (non-linear) add used in calculating $a$ but leaves\r\n$IF$ and $MAJ$'s linear replacements.  Attack gives a collision in $2^{61}$.  This was improved\r\nby Biham and Chen by introducing ``neutral bit'' estimates and starting the perturbation later\r\nin the rounds.\r\n\\\\\r\n\\\\\r\nFor SHA-0, change bit 1 (because the $+$ operation is linear in bit $1$)\r\nwhich shifts to bit 31 and\r\nis linear in $\\oplus$.  Disturbance bit vector: \r\n$( m_{0}^{(0)}, m_{0}^{(1)}, \\ldots , m_{0}^{(79)})$.  Perturbation mask:\r\n$-5 \\le i \\le -1, M_{0}^{(i)}=0$,\r\n$0 \\le i \\le 79, M_{0,k}^{(i)}=0$, if $k \\ne 1$\r\n$0 \\le i \\le 79, M_{0,1}^{(i)}= M_0^{(i)}$.  Corrective masks:\r\n$-4 \\le i \\le 79, M_{1}^{(i)}= ROL_{5}(M_{1}^{(i-1)})$,\r\n$-3 \\le i \\le 79, M_{2}^{(i)}= M_{1}^{(i-2)}$,\r\n$-2 \\le i \\le 79, M_{3}^{(i)}= ROL_{30}(M_{1}^{(i-3)})$,\r\n$-1 \\le i \\le 79, M_{3}^{(i)}= ROL_{30}(M_{1}^{(i-4)})$,\r\n$0 \\le i \\le 79, M_{3}^{(i)}= ROL_{30}(M_{1}^{(i-5)})$.  \r\n\\\\\r\n\\\\\r\nEarly round differentials are\r\nprescribed and later round differentials hold with non-negligible probability ($2^{-61}$,\r\n$2^{-56}$ using \\emph{neutral bits} --- A bit is neutral if flipping it doesn't change \r\ndifferential pattern).  \r\nIn Wang's multi-block attack:  patch final round errors in next block.\r\nEarly rounds are non-linear and prescribed.  Late rounds linear and probabilistic. \r\n\\emph{Procedure:}  Fix linear characteristic, fix non-linear\r\ncharacteristic, modify message (keeping differential) if conflict in mid round.\r\n\\\\\r\n\\\\\r\n{\\bf SHA-256 definitions:}\r\n$Ch(x,y,z)= (x \\wedge y) \\oplus (\\neg x \\wedge z)$,  \r\n$\\psi_{256}^{i, j, k}(x)= ROTR^i (x) \\oplus ROTR^j (x) \\oplus ROTR^k (x)$,\r\n$\\Sigma_0^{256}(x)= \\psi_{256}^{2, 13, 22} (x)$,\r\n$\\sigma_0^{256}(x)= \\phi_{256}^{7, 18, 3} (x)$,\r\n\\\\\r\n{\\bf SHA-512 definitions:}\r\n$Ch(x,y,z)= (x \\wedge y) \\oplus (\\neg x \\wedge z)$,  \r\n$\\psi_{512}^{i, j, k}(x)= ROTR^i (x)  \\oplus ROTR^j (x)  \\oplus ROTR^k (x)$,\r\n$\\Sigma_0^{512}(x)= \\psi_{512}^{28, 34, 39} (x)$,\r\n$\\Sigma_1^{512}(x)= \\psi_{512}^{14, 18, 41} (x)$. \\\\\r\n$\\sigma_0^{512}(x)= \\phi_{512}^{1,8,7} (x)$,\r\n\\begin{tabbing}\r\n1111 \\= 2222 \\= 3333 \\= 4444 \\= 5555 \\kill\r\n{\\bf SHA-256($M_1 || M_2 || \\ldots || M_N$):}\\\\\r\nfor($i=1; i \\le N; i++$)  \\{\\\\\r\n    \\> $W_t= M_t^{(i)}, 0 \\le t \\le 15$,\\\\\r\n    \\> $W_t= \\sigma_1^{256}(W_{t-2}) \\oplus W_{t-7} \\oplus \\sigma_0^{256}(W_{t-15}) \\oplus W_{t-16}, 16 \\le t \\le 63$;\\\\\r\n    \\> $a= H_0^{(i-1)}$; $b= H_1^{(i-1)}$; $c= H_2^{(i-1)}$; $d= H_3^{(i-1)}$; \\\\\r\n    \\> $e= H_4^{(i-1)}$; $f= H_5^{(i-1)}$; $g= H_6^{(i-1)}$; $e= H_7^{(i-1)}$; \\\\\r\n    \\> for($t=0; t<64;t++$) \\{ \\\\\r\n    \\>   \\> $T_1=h + \\Sigma_1^{256}(e)+Ch(e,f,g)+K_t^{256}+W_t$; $T_2= \\Sigma_0^{256}(a)+Maj(e,f,g)$; \\\\\r\n    \\>   \\> $h= g$; $g= f$; $f=e$; $e= d+T_1$; $d=c$;\\\\\r\n    \\>   \\> $c=b$; $b=a$; $a= T_1+T_2$; \\\\\r\n    \\>   \\> \\} \\\\\r\n    \\> $H_0^{(i)}= a+ H_0^{(i-1)}$; $H_1^{(i)}= b+ H_1^{(i-1)}$; $H_2^{(i)}= c+ H_2^{(i-1)}$; $H_3^{(i)}= d+ H_3^{(i-1)}$;\\\\\r\n    \\> $H_4^{(i)}= e+ H_4^{(i-1)}$; $H_5^{(i)}= f+ H_5^{(i-1)}$; $H_6^{(i)}= g+ H_6^{(i-1)}$; $H_7^{(i)}= h+ H_7^{(i-1)}$;\\\\\r\n    \\> \\} \r\n\\end{tabbing}\r\nSHA-512 is the same except there are 79 rounds and the words are 64 bits long.\r\n\\\\\r\n\\\\\r\n{\\bf Cayley Hashes:} Let $S= \\{s_0, \\ldots, s_{k-1} \\} \\subseteq G$ and\r\n$M=m_1 || m_2 || \\ldots || m_n, m_i \\in [0, k-1]$.  \r\nDefine $H_M)= s_{m_1} s_{m_2} \\ldots s_{m_n}$.\r\n\\emph{Representation Problem:}  Given $G, S$, find short $\\prod s_i =1$.\r\n\\emph{Balence Problem:}  Given $G, S$, find short $\\prod s_i = \\prod s_i'$.\r\n\\emph{Factoring Problem:}  Given $G, S, g \\in G$, find short $\\prod s_i = g$.\r\n\\\\\r\n\\\\\r\n\\emph{Example:} $p(x) \\in {\\mathbb Z}_2[x]$, irreducible, $deg(p)=n$,\r\n$G=SL_2(F_{2^n})$,  $S= \\langle\r\n\\left(\r\n\\begin{array}{cc}\r\nx & 1 \\\\\r\n1 & 0 \\\\\r\n\\end{array}\r\n\\right),\r\n\\left(\r\n\\begin{array}{cc}\r\nx & x+1 \\\\\r\n1 & 1 \\\\\r\n\\end{array}\r\n\\right)\r\n\\rangle$ is the Tillich-Zemor scheme.\r\n$G=SL_2(p)$,  $S= \\langle\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 1 \\\\\r\n0 & 1 \\\\\r\n\\end{array}\r\n\\right),\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0 \\\\\r\n1 & 1 \\\\\r\n\\end{array}\r\n\\right)\r\n\\rangle$ is the LPS scheme.\r\n\\section{Elliptic Curve Crypto}\r\n{\\bf Definition:}\r\n$E_F(a,b): y^2= x^3 + ax +b$ where $a,b \\in F$ and $char(F) \\ne 2,3$;  we sometimes\r\nwrite $E_q(a,b)$ if $F=GF(q)$.  For ECC, also\r\nrequire smooth; namely, $4a^3 + 27b^2 \\ne 0 \\jmod{p}$, $p= char(F)$.  For\r\n$P=(x_1, y_1)$ and $Q=(x_2, y_2)$ define $P+Q=(x_3, y_3)$ with\r\n$x_3 = \\lambda^2 - x_1 - x_2, y_3= \\lambda(x_1-x_3)-y_1$ where\r\n$\\lambda= {\\frac {(y_1-y_2)} {(x_1-x_2)}}$ if $P \\ne Q$ and\r\n$\\lambda= {\\frac {(3 x_1^2 + a)} {(2 y_1)}}$ if $P = Q$.  For $char(F)=2$,\r\n$E_F(a,b): y^2 + xy = x^3 + ax +b$ and $x_3= \\lambda^2+\\lambda+a+x_1+x_2, \r\ny_3= \\lambda(x_1+x_3)+x_3+y_1$ where \r\n$\\lambda= {\\frac {(y_1 - y_2)} {(x_1-x_2)}}, P \\ne Q$ and\r\n$\\lambda= x_1 + {\\frac {y_1} {x_1}}, P = Q$.\r\n\\\\\r\n\\\\\r\n{\\bf ECDSA:}\r\nFor an ECC system,\r\nthe public key parameters are $q, a, b, P$ ($P$ is called the base point);\r\npick $1 <x < p$, $x$ is the private key.  Public key is $Q=xP$.  \r\n\\emph{ECDLP:} Find $x$ knowing $Q$.\r\n\\emph{ECC Encrypt:}  To encrypt $m$ (already an integer in the right range), map it\r\nto a point on the curve $P_M$, pick $1<k<p$,\r\nsend $(kP, kQ+P_M)$.  \r\n\\emph{ECC Decrypt:} Receive $(L,M)$ calculate $M-xL=P_M$ and map it\r\nback to the integer message.  Here is a way to embed\r\nintegers in curves: For $q=p^r$, odd, select parameter $\\kappa$ so that the\r\nprobability of failure is $2^{- \\kappa}$; $m$ is message and $0 \\le m <M, q>\\kappa M$ and\r\n$x=m \\kappa +j \\in F_q$ now for the first $j$ for which $x^3+ax+b$ is a square, use \r\nthe corresponding point $P=(x,{\\sqrt x})$.\r\n\\emph{ECDSA sign:}  Select $k$ at random, compute $kP, r=f_E(kP), s= k^{-1} (H(M)+xr)$.\r\nSignature\r\nis $(r,s)$.  \\emph{ECDSA verify:} $u_1=s^{-1}H(M), u_2= s^{-1}r$, accept if $f_E(u_1P+u_2Q)=r$.\r\n\\\\\r\n\\\\\r\n{\\bf Curve selection:}  Avoid \\emph{anomalous curves}\r\n(Definition: $char(F) \\mid \\#E_F(a,b)$), and\r\n\\emph{supersingular curves} (Definition: $\\#E_q(a,b)= q+1-t, q \\mid t$ ---\r\n$t$ is Frobenius trace satisfying $(\\phi_q)^2-t \\phi_q +q=0$; also\r\n$t$ is $Tr(\\phi_q)$),\r\nCM 3 ($a=0, p=3 \\jmod{4}$, MOV-vulnerable (Frey-Ruck)\r\nFor comparison, attacks on DLP: \r\n$L(v,c,n)=exp(c(ln(p)^v (ln(ln(p))^{1-v})$, \r\nNFS discrete log is $L_n[{\\frac 1 3}, ({\\frac {64} 9})^{\\frac 1 3}]$.\r\nBest known ECDLP is\r\n$EC(n)= {\\sqrt n}$. In comparisons, usually put \r\n$n= lg(\\lceil q \\rceil), N= lg(\\lceil p \\rceil)$\r\nand put \r\n${\\frac {E_{EC}} {E_{CONV}}}= \r\n{\\frac {2^{\\frac n 2}} {exp (c N^{\\frac 1 3}(log(N (log(2))^{\\frac 2 3}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf NIST Curves:} Use prime fields ${\\mathbb F}_p$ with $p=\r\n2^{192}-2^{ 64}-1,\r\n2^{224}-2^{ 96}+1,\r\n2^{256}-2^{224}+ 2^{192}+2^{96}-1,\r\n2^{384}-2^{128}- 2^{96}+2^{32}-1,\r\n2^{521}-1$ or  binary fields ${\\mathbb F}_{q}$ with $q=\r\n2^{163}, 2^{233}, 2^{283}, 2^{409}, 2^{571}$.  $\\#E_p(a,b)=q+1-t, |t| \\le 2 {\\sqrt q}$ and\r\n$t$ is called the trace of $E$.  $E_q(a,b)$ has rank 1 or 2, that is:\r\n$E_q(a,b) \\cong {\\mathbb Z}_{n_1} \\times {\\mathbb Z}_{n_2}$ and $n_2 \\mid n_1, n_2 \\mid (q-1)$.\r\nIf $n_2=1, E_q(a,b) \\cong {\\mathbb Z}_{n_1}= \\{kP: 0<k<n_1 \\}$ and $P$ is a generator.\r\n$E_q(a_1, b_1) \\cong E_q(a_2, b_2)$ if \r\n$a_1= u^4 a_2$ and $b_1= u^4 b_2$.  $E_q, q= p^n$ is supersingular if $p \\mid t$.  Field\r\nrepresented as polynomial or normal basis.  Hyperelliptic: higher genus.\r\n\\\\\r\n\\\\\r\n{\\bf Weil-Deligne:}\r\nSet $\\zeta(t,E/F_q)= exp(\\sum_r {\\frac {N_r t^r} r})$, where $N_r$ is the\r\nnumber of solutions of $E/F_{q^r}$.  $\\zeta(t,E)= {\\frac {a-at+qt^2} {(1-t)(1-qt)}},\r\nN_1=q+1-a, N_r= q^r +1 - \\alpha^r - \\beta^r$ where $\\alpha, \\beta$ are reciprocal roots\r\nof the numerator.  Random selection of $(E,B)$:  Generate $x,y,a$ at random and compute\r\n$b= y^2-(x^3+ax)$, check there are not multiple roots.  To compute $|E|$,\r\nuse Schoof.\r\n\\\\\r\n\\\\\r\n{\\bf MOV Attack:} $E_q(a,b) \\mapsto F^*_{q^k}$ if $n$, the curve order, satisfies\r\n$n \\mid (q^k-1)$ then use index calculus, small probability of supersingular or\r\n$k \\le log^2(q)$.  Attack fails if $k>log^2(q)$ (Frey and Ruck extended the attack).\r\n\\\\\r\n\\\\\r\n{\\bf IBE:} Suppose $p=6q-1$, $E_p: y^2 = x^3 + 1 \\jmod{p}$ and suppose $\\#E= 6q$.\r\n$\\exists P_0 \\ne \\infty$ and\r\n$qP_0 = \\infty$.  Finally, suppose there is a bilinear map,\r\n${\\tilde {e}}(P,Q)$, from points into $q$-th\r\nroots of unity that is easy to compute with\r\n$\\tilde {e}(aP_0,bP_0)= \\tilde {e}(P_0, P_0)^{ab}$.\r\n$\\tilde{e}(P_0 , P_0) \\ne 0$ and two hash functions: \r\n$H_1: \\langle 2^{\\infty} \\rangle \\rightarrow kP_0$\r\nand $H_2: \\{\\omega^i\\} \\rightarrow \\langle 2^n \\rangle$.  \r\nPick a secret $s: P_1=sP_0$.  To encrypt\r\nto $ID$: set $D_U= sH_1(ID)$, $g= \\tilde {e}(H_1(ID), P_1)$,\r\nchoose $r \\ne 0 \\jmod{q}$ and compute $t= m \\oplus H_2(g^r)$, $A \\rightarrow B:\r\nc=(r P_0 , t)$.  To decrypt:  Get $(u,v)$, compute $h= \\tilde {e} (H_1(D_u, u)$,\r\n$m= v \\oplus H_2(h)$.  Note $h= g^r$.\r\n\\\\\r\n\\\\\r\n{\\bf ECC Point Operation Costs:}\r\n$I= $ inverse cost $/GF(p)$.\r\n$S= $ square cost $/GF(p)$.\r\n$M= $ multiply cost $/GF(p)$.\r\n\\begin{center}\r\n\\begin{tabular} {|l|l||l|l|}\r\n\\hline\r\n{\\bf Operation} & {\\bf Cost} & {\\bf Modular Op} & {\\bf Cost}\\\\\r\n\\hline\r\n$2P$ & $I+2S+2M$ & Add, Sub & $O(lg(n))$ \\\\\r\n$P+Q$ & $I + S+ 2M$ & Multiply & $O(lg(n)^2)$ \\\\\r\n$2P+Q$ & $2I + 2S + 2M$ & Invert & $O(lg(n)^2)$ \\\\\r\n$P+Q$, $P-Q$ & $I+2S+4M$ & Exp & $O(lg(n)^3)$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nIf $X= \\langle X_1, X_2, \\ldots, X_n \\rangle$ and\r\n$Y= \\langle Y_1, Y_2, \\ldots, Y_n \\rangle$ then \r\n$Pr(\\Delta X, \\Delta Y)= {\\frac 1 {2^n}}$ for\r\nperfect differential resistance.\r\n$(\\Delta X, \\Delta Y)$ is a differential characteristic.  $N_D= {\\frac c {p_D}}$ and\r\n$p_D= \\prod_i^{\\gamma} \\beta_i$ where $\\gamma$ is the number of active boxes.  \r\n\\\\\r\n\\\\\r\n{\\bf  Definitions:}\r\n$Tr(x)= x+ x^p + \\ldots + x^{p^{n-1}}$.  \r\n$e, d$ is a dual basis if $Tr(d^{(i)} e^{(j)})= \\delta(i \\oplus j)$.\r\n\\section {Algebraic and other attacks}\r\n{\\bf Hadamard-Walsh:} $W_f(w)$, measures distance to affine and\r\ncompletely determines $f$.\r\nThe\r\n\\emph{autocorrelation} is $r_f(w)$ measures differential and\r\ndoes not determine $f$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n\\emph{Balanced:} weight is $2^{n-1}$.\r\n$CI_f(t)$: output is statistically independent on any $t$ input bits.\r\n\\emph{Resilient:} $R_f(t)$ is $CI_f(t)$ and balanced.\r\n\\emph{Non-linearity:} $N_f$ is distance to affine.  \r\n$N_f= min_{g \\in RM(1,n)} d(f,g)= 2^{n-1} - {\\frac 1 2} max_{w} |W_f(w)|$.\r\n$\\epsilon= {\\frac {N_f} {2^n}} - {\\frac 1 2}$\r\n\\emph{Linearity:} $L_f= max_w |W_f(w)|$.\r\n$D_w(f(x))= f(x) \\oplus f(w+x)$\\\\\r\n\\\\\r\n{\\bf Theorem:} $r_f(w)= 2^{-n} \\sum_u W_f(u)^2 (-1)^{u \\cdot w}$.\r\nFor iterated ciphers, once the number of rounds is high enough to generate\r\n$G$ (usually $A_n$), more rounds don't help.\r\n\\\\\r\n\\\\\r\n{\\bf AES:} $8j+m$ component is $v_{(j,m)}$.\r\n$0=w_{0,(j,m)}+p_{(j,m)}+k_{0,(j,m)}$,\r\n$0=x_{i,(j,m)} w_{i,(j,m)}+1, i=1,2,\\ldots, 9$.\r\n$0=w_{i,(j,m)}+(M x_{i-1})_{(j,m)}+k_{i,(j,m)}, i= 1,2, \\ldots, 9$,\r\n$0=c_{(j,m)}+(M^* x_{9})_{(j,m)}+k_{10,(j,m)}$.\r\n$M$ is the combined effect of ShiftRow, MixColumn and the Linear diffusion.\r\n5248 equations, 3840 sparse quadratic, 1408 linear diffusion, 7808 terms, 2560 state\r\nvariables, 1408 key variables. $1280+1408=2588$ state/key variables eliminated, \r\n$4288-2688=1600$ unknown.\r\n2688 equations, 1280 sparse quadratic, 5248 terms, 2560 state, 1408 linear diffusion,\r\n1408 key variables.\r\n\\\\\r\n\\\\\r\nFor AES: $M: x \\mapsto CRLx+63$ (Everything but subByte).  Minimal polynomials: \r\n$C: (x^4+1)$,\r\n$R: (x^4+1)$,\r\n$L: (x+1)^3$,\r\n$C: (x+1)^{15}$.  \r\n{\\bf BES:} $b \\rightarrow M_B b^{-1} + k_B$.\r\n$w_0=p+k_0$,\r\n$x_i=w_i^{-1}$,\r\n$w_i=M_B x_{i-1} + k_i$,\r\n$c=M_B^* x_{9} + k_{10}$.\r\n$AES_{k}(P)=C \\leftrightarrow BES_{ \\phi(k) } ( \\phi (P) )=\\phi(C)$, \r\n$\\phi(a)= ( a^{2^0}, a^{2^1}, a^{2^2}, a^{2^3}, a^{2^4}, a^{2^5}, a^{2^6}, a^{2^7})$.\r\n\\\\\r\n\\\\\r\n{\\bf Circulant as linearized polynomial:} $x \\mapsto 0x05x^{2^0}+ 0x09x^{2^1}+ 0xf9x^{2^2}+ \r\n0x25x^{2^3}+ 0xf4x^{2^4}+ 0x01x^{2^5}+ 0xb5x^{2^6}+ 0x8fx^{2^7}$, \r\n$S: w \\mapsto \\sum_{i=0}^7 \\lambda_i w^{255-2^i} +0x63$, modified: \r\n$S: w \\mapsto \\sum_{i=0}^7 \\lambda_i w^{-2^i}$.\r\n{\\bf Rank of system} is ${\\frac {equations} {monomials}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Equation Solving:} If $n=$number of equations, $M=$ number of variables.  \r\nSolution takes $2^n$, if $n=m$, $n$, if $n=m+1$ and ${\\sqrt n}$ if $m>>n$.\r\n\\begin{tabbing}\r\n1111 \\= 2222 \\= 3333 \\= 4444 \\= 5555 \\kill\r\n{\\bf Buchberger:} \\\\\r\nInput: $F= \\{ f_1, f_2, \\ldots , f_m \\}$.\r\nOutput: Grobner $G= \\{ g_1 , g_2 , \\ldots , g_s \\}$.\r\n\\\\\r\n$G \\leftarrow F;$\\\\\r\nDo \\{ \\\\\r\n    \\> $G' \\leftarrow G;$\\\\\r\n    \\> for($p,q\\in G', p \\ne q$) \\{ \\\\\r\n    \\>   \\> Compute $S(p,q)$; \\\\\r\n    \\>   \\> $r \\leftarrow REM(S(p,q), G')$; \\\\\r\n    \\>   \\> if($r \\ne 0$) \\{ \\\\\r\n    \\>   \\>     \\> $G' \\leftarrow G' \\cup \\{r\\}$; \\\\\r\n    \\>   \\>     \\> \\} \\\\\r\n    \\>   \\> \\} \\\\\r\n    \\> \\} while($G!=G'$) \\\\\r\n\\end{tabbing}\r\nTheorem:  Foregoing algorithm yields Grobner Basis.\r\n\\\\\r\n\\\\\r\n{\\bf F4/F5:}  Grobner by matrix reduction.  \\emph{Example:} \r\n$f_1 = 3 x^3 y z -5xy$, $f_2 = 5x^2z^2+3xy+1$,\r\n$g_1= xy-2z$, $g_2=x^2z-3yz$.\r\n\\begin{center}\r\n\\begin{tabular} {|c|cccccc|}\r\n\\hline\r\n& $x^3yz$ & $x^2z^2$ & $yz^2$ & $xy$ & $z$ & $1$\\\\\r\n\\hline\r\n$f_1$ & $3$ & $0$ & $0$ & $-5$ & $0$ & $0$ \\\\\r\n$f_2$ & $0$ & $5$ & $0$ & $3$ & $0$ & $1$ \\\\\r\n$x^2 z g_1$ & $1$ & $-2$ & $0$ & $0$ & $0$ & $0$ \\\\\r\n$1 g_1$ & $0$ & $0$ & $0$ & $1$ & $-2$ & $0$ \\\\\r\n$zg_2$ & $0$ & $1$ & $-3$ & $0$ & $0$ & $0$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nComplexity of F5 is ${N_D}^{\\omega}$ where $N_D$ is the size of the largest matrix\r\ncontaining polynomials of degree $D$.  If $m=n, D \\approx .09n$.\r\n\\begin{center}\r\n\\begin{tabular} {|cc|}\r\n\\hline\r\nCondition & Complexity \\\\\r\n\\hline\r\n$m=an$ & exponential in $n$ \\\\\r\n$n << m << n^2$ & subexponential in $n$ \\\\\r\n$m=an^2$ & polynomial in $n$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf AES Design Criteria:}\r\nInvertibility,\r\nminimize largest non-trivial correlation between input and output,\r\nminimize largest non-trivial xor,\r\ncomplexity of algebraic expressions,\r\nSimplicity of expression.\r\nEstimation of linearly independent equations for XSL on AES-128. \r\n\\begin{tabbing}\r\n1111 \\= 2222 \\= 3333 \\= 4444 \\= 5555 \\kill\r\n{\\bf XL (extended linearization):}  \\\\\r\nInput: $F= \\{ f_1 , f_2 , \\ldots , f_m \\}$.\\\\\r\nOutput: univariates.\\\\\r\n$S \\leftarrow \\emptyset;$\\\\\r\nPick $D=d+1$; \\\\\r\n$G \\leftarrow F;$\\\\\r\nfor($i=1; i \\le n+1; i++)$ \\{ \\\\\r\n    \\> Generate $p_{\\beta j}= x^{\\beta} f_j, f_j \\in F;$ \\\\\r\n    \\> Do Gaussian reduction. \\\\\r\n    \\> If there is a univariate $f(x)$ \\{ \\\\\r\n    \\>     \\> Solve; \\\\\r\n    \\>     \\> $S \\leftarrow S \\cup \\{(x- a_i)\\};$ \\\\\r\n    \\>     \\> Substitute. \\\\\r\n    \\>     \\> \\} \\\\\r\n    \\> else \\\\\r\n    \\>     \\> $D \\leftarrow D + 1;$\\\\\r\n    \\> \\} \r\n\\end{tabbing}\r\nFor each round \r\n($0 \\leq i \\leq 9$)\r\nand each\r\nS-box ($0 \\leq j \\leq 15$), we get $r= 8 \\times 3 =24$ quadratics. $S$: Total S-boxes,\r\n$P-1$: passive S-Boxes, Highest degree: $2P$.  $R$: Equations.  $B$: S-boxes/round.\r\n$|R|= {S \\choose P} (t^P - (t-r)^P)$,\r\n$|R'|= {S \\choose {P-1}} SB (N_r +1) (t-r)^{P-1}$,\r\n$|R''|= {S \\choose {P-1}} (S_k -L_k) (N_r +1) (t-r)^{P-1}$, \r\n$L_k$: independent key variables, $S_k$: key variables.\r\nTotal terms: $T= {S \\choose P} t^P$.  \r\nFor $P=2$, $(R+R'+R'')= 33,665,888, T= 33,788,100$.\r\nFor $P=3$, $(R+R'+R'')= 95.18 \\times 10^9, T= 91.9 \\times 10^9$.\r\n\\\\\r\n\\\\\r\n{\\bf Boomerang:} $E=E_1 E_0$.\r\n$E_0: \\alpha \\rightarrow \\beta, p$,\r\n$E_1^{-1}: \\gamma \\rightarrow \\delta, q$.  (1) Pick $P_1 \\oplus P_2= \\alpha$;\r\n(2) Ask for $C_1= E(P_1), C_2= E(P_2)$;\r\n(3) Compute $C_3= C_1 \\oplus \\gamma$, $C_4= C_2 \\oplus \\gamma$;\r\n(4) Request $P_4= E^{-1}(C_4)$, $P_3= E^{-1}(C_3)$.\r\n$E_0(P_1)=I_1$, $E_0(P_2)=I_2$, $E_0(P_3)=I_3$, $E_0(P_4)=I_4$.  $E_1^{-1}(I_1)= C_1$,\r\n$E_1^{-1}(I_2)=C_2$, $E_1^{-1}(I_3)=C_3$, $E_1^{-1}(I_4)=C_4$.\r\nWhat is probability that $P_3 \\oplus P_4 = \\alpha$?\r\n$e_1: Pr[I_1 \\oplus I_3 = \\delta]= q$, $e_2: Pr[I_2 \\oplus I_4= \\delta]= q$.  \r\n$Pr[ e_1 \\wedge e_2 ]= q^2$.\r\n$Pr[I_3 \\oplus I_4 = \\beta]= q^2$,\r\n$Pr[P_3 \\oplus P_4 = \\alpha]= p^2q^2$.  If $(pq)^2>2^{-n}$, $pq>2^{\\frac {-n} 2}$\r\nand this is better than a simple differential attack if the differential probability\r\nis less than $2^{-n/2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Amplified Boomerang:}\r\nUse two short differentials instead of one differential.  Start with quartet\r\n$P_1 \\oplus P_2 = P_3 \\oplus P_4= \\alpha$, \r\neach has $\\alpha \\rightarrow \\beta$\r\nwith probability $p$.\r\n$E_0(P_1) \\oplus E_0(P_2) = E_0(P_3) \\oplus E_0(P_4)= \\beta$. \r\n$E_0(P_1) \\oplus E_0(P_3) = E_0(P_2) \\oplus E_0(P_4)= \\gamma$. \r\n$C_2 \\oplus C_4 = C_1 \\oplus C_3= \\delta$ and we want to use\r\n$\\gamma \\rightarrow \\delta$.  Probability that quartet becomes\r\nright is ${{Np} \\choose 2} 2^{-n} q^2$.  Distinguishers count quartets\r\n$((P_1, P_2), (P_3, P_4))$ satisfying \r\n$C_1 \\oplus C_3 = C_2 \\oplus C_4 = \\delta$.\r\n\\\\\r\n\\\\\r\n{\\bf Bilinear Attack:}\r\nNotation: $L_r[0, 1, 2, \\ldots, n-1]$, $R_r[0, 1, 2, \\ldots, n-1]$ are the input\r\nto round $r$ and \r\n$I_r[0, 1, 2, \\ldots, n-1]$, $O_r[0, 1, 2, \\ldots, n-1]$ are the input (without key)\r\nand output to the round functions.  If $\\alpha \\subseteq \\{0, 1, 2, \\ldots, n-1\\}$,\r\ndefine $L_r[\\alpha]= \\bigoplus_{s \\in \\alpha} L_r[s]$.  Consider the bilinear\r\n$L_{r+1}[\\beta] \\cdot R_{r+1}[\\alpha] \\oplus\r\nR_{r}[\\beta] \\cdot L_{r}[\\alpha] = I_{r}[\\beta] \\cdot O_{r}[\\alpha]$.\r\nTODO: More from Nick.\r\n\\\\\r\n\\\\\r\n{\\bf Square/Integral/Saturation Attack:} \r\n$\\Lambda$-set has $256$ states which are either all the same in a byte position or\r\nall different.  In either case $\\bigoplus_{x \\in \\Lambda} x_{i,j} = 0$.  \r\n\\emph{Structural:} Prior to MixCol\r\n$(x_0^i, x_1^i, x_2^i, x_3^i)^T$ and after\r\n$(y_0^i, y_1^i, y_2^i, y_3^i)^T$ then $y_0^0 \\oplus y_1^0 \\oplus \\ldots \\oplus y_{255}^0 =00$.\r\nguess key byte.   If condition holds, it's right; otherwise it isn't.  Mixcolumn\r\nis the only operation that changes this condition and only if there is more than one active\r\nbyte in the column.  To capitalize on this at final round (where mixing disrupts condition),\r\nGives one linear combination of 4 key bits in round 4.  Properties of\r\nsets of texts preserved by encryption.  \\emph{Example:}\r\n256 plaintexts that agree on 15 input bytes.\r\n$\\theta$ - linear map, $\\gamma$ - non-linear transform,\r\n$\\pi$ - byte transposition,  $\\sigma$ - key addition,\r\n$\\Lambda$ - 256 active states, $\\lambda$ - set of indices of active bytes.\r\nThen $\\bigoplus_{b= \\theta(a), a \\in \\Lambda} b_{i,j} = 0$.\r\n$\\forall x, y \\in \\Lambda$, \r\n$x_{i,j} \\ne b_{i,j}$ if $(i,j) \\in \\lambda$,\r\n$x_{i,j} = b_{i,j}$ if $(i,j) \\notin \\lambda$.\r\n$a_{i,j}= b_{i,j} \\oplus S_{\\lambda}[b_{i,j}] \\oplus_{i,j} k^4_{i,j}$; if the result is\r\nnot balanced (over $\\Lambda$), the key is wrong.\r\n\\emph{Example with block cipher Square:}  Square round is \r\n$\\rho_r(x)= \\sigma_r(\\pi(\\gamma(\\theta(x))))$,\r\n$\\gamma$ is the non-linear substitution, $\\theta$ is linear diffusion ($c_i$ are\r\npolynomials), $\\pi$ flips rows and columns, $\\sigma_r$ is key addition. \r\n$ \\bigoplus_{b=\\theta(a), a \\in \\Lambda} b_{i,j}=\r\n\\bigoplus_{a \\in \\Lambda} \\bigoplus_{k} c_{j-k} a_{i, k} =\r\n\\bigoplus_{l} c_{l} (\\bigoplus_{a \\in \\Lambda} a_{i,l+j})$.\r\nAfter three rounds, all bytes are active.  For ciphertext\r\n$d_{i,j}$, guess $k^4_{i,j}$ and compute\r\n$ b_{j,i}= \\gamma^{-1}( d_{i,j}\\oplus k^{4}_{i,j} )$.\r\n\\\\\r\n\\\\\r\n{\\bf Truncated differentials:}\r\nSuppose \r\n$g: GF(2)^n \\times GF(2)^n \\times GF(2)^m \\rightarrow GF(2)^n \\times GF(2)^n \\times$\r\nimplements a Feistel cipher round that is $g(X,Y,Z)=(Y, f(Y,Z) \\oplus X)$.  The\r\nS/N ratio is ${\\frac {|K| p} {\\gamma \\lambda}}$ where $p$ is the differential\r\nprobability, $\\gamma$ is the number of suggested keys and $\\lambda$ is the ratio\r\nof non-discarded keys to all keys.  A full differential $a' \\rightarrow b'$\r\nspecifies all $n$ bits, a truncated differential specifies a subset of bits.\r\nHere is an example of its usefulness.  Let $f(x)= x^{-1}$.  It has non-linear\r\norder $n-1$.\r\nIf $n$ is odd the map is differentially 2-uniform $p= 2^{1-n}$;\r\nif $n$ is even the map is differentially 4-uniform $p= 2^{2-n}$.  For\r\n$3$ rounds, the differential probability is $2^{3-2n}$ and the S/N is\r\n$2^{3-n}$.  For $r>3$ the attack can't succeed.  For $2$ rounds,\r\n$p=2^{1-n}$ and the S/N is $2^{n+1}$ so the attack requires $2^{n}$ texts\r\nand is $O(2^{3n})$ but for $a' \\ne 0$, there are only\r\n$2^{n-1}$ possible $b'$ and we get one bit of information --- the S/N is \r\n${\\frac {2^{2n}} {2^{2n-1}}}=2$.  Let $f(x,k)$ be the non-linear function\r\nin a $5$ round Feistel cipher with block size $2n$.  Let  $\\alpha \\ne 0$\r\nbe an input differential for which only a fraction, $W$, of all output\r\ndifferences are possible.  Then a truncated differential attack requires\r\n$2L$ chosen plain-cipher pairs and is $O(L 2^{2n})$ where $L$ is the smallest\r\ninteger: $W^L < 2^{-2n}$.\r\nNote that truncated differentials cannot propagate backwards.\r\n\\\\\r\n\\\\\r\n{\\bf Higher order differentials:}  Define \r\n$$\\Delta_a^{(1)}(f(x))= f(x+a)-f(x),\r\n\\Delta_{a_1, a_2, \\ldots, a_i}^{(i)}(f(x))= \r\n\\Delta_{a_i}^{(1)}( \\Delta_{a_1, a_2, \\ldots, a_{i-1}}^{(i-1)}(f(x))).$$\r\nLet $L[a_1 , a_2, \\ldots, a_i]$ is the set of all linear combinations\r\nof $\\langle a_1 , a_2, \\ldots, a_i \\rangle$.  Then\r\n$\\Delta_{a_1, a_2, \\ldots, a_i}^{(i)}(f(x))= \\sum_{\\gamma \\in L[ a_1, a_2, \\ldots , a_i]}\r\nf(P+ \\gamma)$ and\r\n$ord(\\Delta_a^{(1)}(f(x))) \\le ord(f(x))-1$.\r\nHere is an example application.  Let $f(x,k)= (x+k)^2 \\jmod{p}$ be the Feistel round\r\nfunction with size is $lg(p)$. $f$ is differentially 1-uniform and the round\r\ndifferential has probability ${\\frac 1 p}$,  $f''(x)$ is constant.  The first order\r\ndifferential attack on a 5 round cipher requires $2p$ texts and is $O(p^3)$;\r\na second order differential attack requires $8$ texts and is $O(p^2)$. [Use\r\n$\\Delta_{\\alpha , \\beta}(f(x)), \\alpha= a || 0, b= b ||0, S/N=r^2$].  For a\r\n5 round Feistel with $f$ non-linear of degree $r$ using an $r$th order differential\r\nrequires $2^{r+1}$ texts and is $O(2^{2n+r})$.\r\n\\\\\r\n\\\\\r\n{\\bf SFLASH attack:} The idea of SFLASH is to hide an easy-to-invert quadratic map,\r\n$F(x)$ with two ``secret'' invertible linear transformations $U, T$.  If\r\n$e=q^i+q^j$, $F(x)= x^e$ is quadratic; in particular, if\r\n$e= q^{\\theta}+1$ (and from now on, it is)\r\nand $P= T \\circ F \\circ U$, $F$ is (easily) invertible if $(q^{\\theta}+1, q^n-1)=1$ (so\r\n$q=2^k$) but without knowledge of $U, T$, $P$ isn't.  This is the $C^*$ scheme\r\nPatarin broke.  If we remove $r$ of $n$ quadratic equations in the base field\r\nthat represent $P$, Patarin's attack\r\ndoesn't work and the new scheme $C^{*-}$ can be used for signatures.\r\nLet $\\Pi: (x_1 , x_2 , \\ldots , x_n) \\mapsto (x_1 , x_2 , \\ldots ,x_{n-r})$.\r\n$P$ is public key; to sign $m$, choose $r$ coordinates at random.  Signer\r\nrecovers $s$: $P_{\\Pi}(s)= {\\vec r}$.  Signature is $(m,s)$.  The \r\nidea of Shamir's attack is to use a multiplicative property of the linear transformation\r\ninduced by a field element, $\\xi$, on the differential to obtain a different set of\r\nlinear combinations of the $F$ quadratics and then apply Patarin's attack.\r\nDefine the differential $DF(a,x)= F(x+a) -F(x) -F(a) -F(0)$.  For $F(x)= x^e$,\r\n$e= q^{\\theta}+1$ in field of characteristic $q$,\r\n$DF(\\xi \\cdot a , x) + DF(a, \\xi \\cdot x) = (\\xi + \\xi^{q^{\\theta}}) DF(a , x)$.\r\nDenote $M_{\\xi}$ as the matrix for the linear transformation induced by multiplying\r\nby $\\xi$, $L(\\xi)$ as the matrix induced by $\\xi+ \\xi^{q^{\\theta}}$ and\r\n$\\Lambda(L(\\xi))= T_{\\Pi} M_{L(\\xi)}T^{-1}$.  Let $Q$ be the space of\r\nquadratic forms, $V$ the subspace generated by $TFU$ and $V_{\\Pi}$ the space generated\r\nby $T_{\\Pi}FU$.  $V_{\\Pi} \\subseteq V \\subseteq Q$.  There is a corresponding set\r\nof bilinear forms $B$, and sets $W$ and $W_{\\Pi}$ and setting\r\n$N_{\\xi}= U^{-1}M_{\\xi}U$, the relation\r\n$DP(N_{\\xi}(a),x))+DP(N_{a, \\xi}(x))= \\Lambda(L(\\xi)) DP(a,x)$ holds.\r\nThis equation relates unknown coefficients of $N_{\\xi}$ on the left with unknown coefficients\r\nof $\\Lambda(L(\\xi))$ on the right.  Setting $S_M(a,x)=\r\nDP_{\\Pi}(N_{\\xi}(a),x))+DP_{\\Pi}(N_{a, \\xi}(x))$ we note the LHS is in $W_{\\Pi}$ with probability\r\n$q^{-r}$ if $M$ represents a matrix for some $\\xi$ induced value and probability\r\n$q^{n^2/2}$ if not.  These identify transforms that can produce other $P$ equations to fill\r\nout the $r$ unknown quadratics to apply Patarin.\r\nSFLASH-1 parameters: $q=2^7, n=37, \\theta=11, r=11$;\r\nSFLASH-2 parameters: $q=2^7, n=67, \\theta=33, r=11$.\r\n\\\\\r\n\\\\\r\n{\\bf Impossible differentials:} Suppose $\\alpha \\rightarrow \\beta$ for \r\n$E_1$ is impossible and $E= E_2 \\circ E_1 \\circ E_0$.  Encrypt many plaintexts\r\nwith possible output $\\alpha$ after $E_0$ and decrypt pairs with all possible\r\nsubkeys through $E_2$.  If these suggest $\\alpha \\rightarrow \\beta$ the keys are\r\nimpossible.\r\n\\\\\r\n\\\\\r\n{\\bf Related Key Attacks:} If\r\n$K \\rightarrow (K_1, K_2, \\ldots, K_r)$ and\r\n$K^* \\rightarrow (K_2, \\ldots, K_r, K_1)$ and $F(X, K_i)$ is the round function then\r\n$n-1$ of the rounds are identical.  If $P^*=F(P,K_1)$ and we know\r\n$2^{n/2}$ P/C pairs $(P, C)_{K}$ and\r\n$2^{n/2}$ P/C pairs $(P^*, C^*)_{K^*}$ try to solve \r\n$F(P, K')=P^*$ and $F(C, K')=C^*$; this gives\r\n$K_1$.  Related key differential: $\\alpha \\rightarrow \\beta$ for $E^0$ with \r\n$p > 2^{-n}$ then \r\n$Pr_{X,K}[E^0_K(X) \\oplus E^0_{K \\oplus \\Delta K}(X \\oplus \\alpha)= \\beta] = p > 2^{-n}$.\r\n\\\\\r\n\\\\\r\n{\\bf Slide Attack:} Let $F$ be a per-round function.\r\nIf $C=E_K(P)= F_K^m(P), P,C \\in GF(2)^n$ \r\nand $P'= F(P)$ then $C'= E(P')=F(C)$.  To find slide pairs,\r\nlet $\\alpha_F(P,C)= K$ which is easy to calculate.  Store $2^{n/2}$ (and possibly\r\nless as in DES) pairs $(P,C)$ if $\\alpha_F(P, C)= \\alpha_F(P', C')$, $P'= F_K(P)$ and\r\n$C'= F(C)$.  By birthday collision, this will happen.\r\nEffective against rounds which implement weak permutations.\r\n\\\\\r\n\\\\\r\n{\\bf Wiedemann:}  Solve $A{\\vec x}= {\\vec b}$ in $O(n \\omega)$ time over $F=GF(q)$\r\nwhere $\\omega$ is the number of non-zero elements of $A$.  Let\r\n$S= \\langle A^i b \\rangle, det(A) \\ne 0$ and suppose \r\n$f(z)= \\sum_{j=0}^d$ is the minimal polynomial\r\nnormalized so the trailing coefficient ($f_0$) is $1$.  Let $x= - \\sum_{i=1}^d f_i A^{i-1}b$.\r\nThen $Ax= (1-f(A)) b= b$ so $x$ is a solution, this requires $2n(\\omega+1)$ field operations.\r\nTo find $f$, look at the \\emph{linear recurrent sequence}\r\n$s_i = (u, A^ib)$, the associated polynomial\r\n$f_u | f$ can be computed from the first $2n$ terms is $O(n^2)$.\r\n\\\\\r\n\\\\\r\nLet $F=GF(q)$.  Every $k$th order linear recurrent sequence is ultimately periodic\r\nwith period $r$ satisfying \r\n$r \\le q^k$ \r\n($r \\le q^k-1$ if homogeneous). If $s_{n+k}= a_{k-1} s_{n+k-1} + \\ldots + a_0 s_n$ the\r\nassociated matrix is\r\n$A=\r\n\\left(\r\n\\begin{array}{ccccccc}\r\n0 & 0 & 0 & \\ldots & 0 & 0 & a_0 \\\\\r\n1 & 0 & 0 & \\ldots & 0 & 0 & a_1 \\\\\r\n0 & 1 & 0 & \\ldots & 0 & 0 & a_2 \\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\n0 & 0 & 0 & \\ldots & 0 & 1 & a_{n-1}\r\n\\end{array}\r\n\\right)\r\n$ and the least period divides $A^k-1$. If\r\n$D^{(r)}_n= \r\n\\left(\r\n\\begin{array}{ccccc}\r\ns_n & s_{n+1} & s_{n+2} & \\ldots & s_{n+r-1} \\\\\r\ns_{n+1} & s_{n+2} & s_{n+3} & \\ldots & s_{n+r-1} \\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\ns_{n+r-1} & s_{n+r} & s_{n+r+1} & \\ldots & s_{n+2r-1}\r\n\\end{array}\r\n\\right)\r\n$ then $s_0, s_1, \\ldots$ is a linear recurrent sequence iff $D^{(r)}_n=0$ \r\nfor all but finitely many $n \\ge 0$.\r\nIf a linear recurrent sequence has minimal polynomial $m(x)$ of degree $\\le k$ and\r\n$r= \\lfloor k + {\\frac 1 2} - {\\frac 1 2} m_{2k} \\rfloor$ then\r\n$m(x)= x^r g_{2k}({\\frac 1 x})$ and $m(x)$ depends only on the first $2k$ terms.\r\n\\begin{verbatim}\r\nWiedemann's Algorithm\r\n1. Set b[0]= b, k=0, y[0]= 0, d[0]= 0\r\n2. If b[k]=0, x= -y[k].  Terminate.\r\n3. Select u[k+1] at random\r\n4. Compute first 2(n-d[k]) terms of (u[k+1], A**i b[k])= s[0,..]\r\n5. Set f[k+1](z)= minimum poly in 4\r\n6. Set y[k+1]= y[k]+f[k+1](z) b[k], b[k+1]= b[0]+A[y[k+1]), d[k+1]= d[k]+deg(f[k])\r\n7. k= k+1, go to 2\r\n\\end{verbatim}\r\n\\begin{verbatim}\r\nBerlekamp's Algorithm\r\nGiven s[0], s[1], ... with generating function G(x)= s[0] + s[1]x + ... + s[i] x**i + ... in\r\nF=GF(q)\r\n\r\n1. g[0](x) = 1, h[0](x)=x, m[0]= 0\r\n2. b[j]= coefficient of x**j in G(x) g[j](x)\r\n   g[j+1]= g[j](x)- b[j] g[j](x),\r\n   h[j+1] = 1/b[j] x g[j(x), if b[j] !=0 and m[j] >=0; x h[j](x), otherwise\r\n   m[j+1]= -m[j], if b[j] !=0 and m[j] >=0; m[j+1]+1, otherwise\r\n\r\nVersion 2\r\nInput: F=GF(q), 2n coefficients of a Linear recurrence <a[0], a[1], ..., a[2n-1]>\r\nOutput:  Minimal polynomial P\r\n\r\n   R0=x**(2n); R1= a[0]+a[1]x+ ... + a[2n-1] x**(2n-1); V0=0; V1=1;\r\n   while(n<=deg(R1) {\r\n        R0= QR1+R;  // Division Algorithm\r\n        V= V0-Q V1;\r\n        V0= V1; V1= V; R0= R1; R1= R;\r\n        }\r\n   d= max(deg(V1), 1+deg(R1));\r\n   P= x**d V1(1/x);\r\n   return(P/leading-coeff(P));\r\n\\end{verbatim}\r\n\\begin{figure}\r\n\\begin{center}\r\n\\begin{tabular} {|ccccc|}\r\n\\hline\r\n$j$ & $g_j(x)$ & $h_j(x)$ & $m_j$ & $b_j$ \\\\\r\n\\hline\r\n$0$ &  $1$  &  $x$   &  $0$  & $0$ \\\\\r\n$1$ &  $1$  &  $x^2$   &  $1$  & $2$ \\\\\r\n$2$ &  $1+x^2$  &  $2x$   &  $-1$  & $1$ \\\\\r\n$3$ &  $1+x+x^2$  &  $2x^2$   &  $0$  & $0$ \\\\\r\n$4$ &  $1+x+x^2$  &  $2x^3$   &  $1$  & $2$ \\\\\r\n$5$ &  $1+x+x^2+2x^3$  &  $2x+2x^2+2x^3$   &  $-1$  & $2$ \\\\\r\n$6$ &  $1+x^3$  &  $2x^2+2x^3+2x^4$   &  $0$  & $1$ \\\\\r\n$7$ &  $1+x^2+2x^3+x^4$  &  $x+x^4$   &  $0$  & $1$ \\\\\r\n$8$ &  $1+2x+x^2+2x^3$  &  -   &  $0$  &  - \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\caption{Berlekamp-Massey for $G(x)= 1+x+x^4+x^6+x^7 \\in F_2[x]$}\r\n\\end{figure}\r\n\\section{Quantum Crypto}\r\n{\\bf Key Distribution:} Choose two basis: \r\n$B_1= ( |0 \\rangle, |1 \\rangle)$ and\r\n$B_2= ( |{\\frac 1 2} \\rangle, |-{\\frac 1 2} \\rangle)$.  \r\nAlice chooses a random sequence \r\nof basis $\\beta_i$ from\r\n$\\{B_1 , B_2 \\}$ and a random sequence of bits $b_i$ and encodes $b_i with \\beta_i$.\r\nBob chooses a random sequence \r\nof basis $\\beta_i$ from\r\n$\\{B_1 , B_2 \\}$ and obtains sequence $c_i= \\beta_i b_i$.  Bob reveals his sequence of\r\nbasis choices and then Alice reveals hers.  Each confirms subset of bits for which the\r\nsequences agree using some classical system.\r\n\\\\\r\n\\\\\r\nConsider three polarizers $A, B, C$ which have phases $0, 45, 90$.  If\r\n$A$ and $C$ are placed in series, no light comes through but if\r\n$A$, $B$ and $C$ are placed in series, some light gets through.\r\nLet $|0 \\rangle, |1 \\rangle$ be two orthogonal vectors in a complex $2-$dimensional space.\r\nA \\emph{qubit} is a unit vector in this space.  It can have many basis.\r\n\\emph{Shor:}  Choose $m: n^2 \\le 2^m <2 n^2$ and let \r\n$v= {\\frac {1} {\\sqrt {2^m}}} (|0 \\rangle + |1 \\rangle + \\ldots + |2^m-1 \\rangle$.  \r\nLet $f$ be a function\r\nand $x= {\\frac 1 C} \\sum |x \\rangle$.   System computes\r\n$t= {\\frac 1 C} \\sum |x, f(x) \\rangle$.  If $f(x)= a^x \\jmod{n}$, measurement of\r\nlast ${\\frac m 2}$ bits fixes sequence\r\n$t= {\\frac 1 C} \\sum |x, u=f(x) \\rangle$ for fixed $u$ measuring the Fourier transform\r\nidentifies period, that is $m: a^{i} = a^{i+r}$ so that $a^r= 1\\jmod{n}$ but\r\nthat means $r$ is a universal exponent and we can (probably) factor $n$.\r\n\\\\\r\n\\\\\r\n{\\bf Universal exponent method:}  Suppose $a^r=1 \\jmod{n}, \\forall a: (a,n)=1$.  Put\r\n$r=2^km$, $m$ odd.  Choose $a$ at random if $(a,n) \\ne 1$, we have a factor;\r\notherwise, put $b_0=a^m \\jmod{n}$ and $b_{n+1}= b_n^2 \\jmod{n}$.  If $b_0= 1$\r\nor $b_j= -1 \\jmod{n}, 0 \\le j < k$ or\r\n$b_{j+1}=1 \\jmod{n}$ and $b_{j}=-1 \\jmod{n}$, stop and\r\npick a new $a$.  If \r\n$b_{j+1}=1 \\jmod{n}$ but $b_{j} \\ne \\pm 1 \\jmod{n}$ then $(b_j-1,n)$ is a factor.\r\n\\section{Protocols, Models}\r\n{\\bf Bell-Lapadula (BLP):}  Subjects and Objects labeled.  Simple Security property:\r\nS can read O iff $L(O) \\leq L(S)$.  *-Property: S can write O iff $L(S) \\geq L(O)$.\r\n\\emph{Tranquility:} Labels never change.  \\emph{Biba:} S can write O iff $I(O) \\leq I(S)$.  S can\r\nread O iff $I(S) \\leq I(O)$.\r\n\\\\\r\n\\\\\r\n{\\bf Perfect Forward Security and ephemeral Diffie-Hellman with authentication:}\r\nBoth Alice and Bob agree on modulus $p$ and base $g$.  Alice picks secret\r\n$a$ and Bob $b$ for signing; signing public keys have been previously exchanged.\r\nSo for the session key, Alice picks random $x$ and Bob picks random $y$.\r\nIn the protocol below, $r_A= g^x \\jmod{p}$,\r\n$r_B= g^y \\jmod{p}$ and $K= g^{xy} \\jmod{p}$.  \r\n(1) $A \\rightarrow B:$ ``Alice'', $r_A$.\r\n(2) $B \\rightarrow A:$ ``Bob'', $r_B$, $E_K(sig_B(r_A, r_B))$\r\n(3) $A \\rightarrow B:$ $E_K(sig_A(r_A, r_B))$.  Throwing away $r_A, r_B, x, y$ \r\nyields perfect forward secrecy.\r\n\\\\\r\n\\\\\r\n{\\bf Kerberos (v4):} $L$ is lifetime. $T_X$ is the timestamp from $X$. Most features (like lifetime)\r\nprompted by workstation/server model (no longer valid), network masquarading replay.  Kerberos AS\r\nis sole root of trust for realm.\r\n\\begin{enumerate}\r\n\\item $A \\rightarrow S$: $A,B$\r\n\\item $S \\rightarrow A$: $\\{T_S , L, K_{AB}, B, \\{T_A, L, K_{AB},A\\}_{K_{BS}}\\}_{K_{AS}}$.\r\n\\item $A \\rightarrow B$: $\\{T_S , L, K_{AB}, A\\}_{K_{BS}}, \\{A, T_A\\}_{K_{AB}}$.\r\n\\item $B \\rightarrow A$: $\\{T_A +1\\}$.\r\n\\end{enumerate}\r\n{\\bf Protocol layers:} Application (DNS, TLS, HTTP, SSH), Transport (TCP), Network (IPv4),\r\nLink (ethernet, Wi-Fi).\r\n\\\\\r\n\\\\\r\n{\\bf X.509 certificate format:} Version number (There are three), CA serial number,\r\nSignature algorithm (useless, appears later), Issuer name (x.509 name), validity period,\r\nsubject name (x.509), subject public key information, \r\nIssuer unique identifier (x.509, optional),\r\nsubject unique id (x.509, optional), extensions (version 3), signature.  \r\nExtenstions required because \r\n(1) Subject/issuer identifiers inadequate, (2) no way to tie policy\r\nto cert, (3) cannot constrain use, (4) cannot easily cross reference entities for better\r\nkey management.  Extensions include: Authority key ID, Subject key  ID, Key usage, Private\r\nkey validity period, certificate evaluation policies, policy map between CAs, \r\nalternate subject and issuer names, basic, name and policy constraints.\r\n\\\\\r\n\\\\\r\n{\\bf TLS:} Three phases: (1) Peer negotiation, (2) PK based key exchange \r\n(including certificate exchange), (3) encrypted traffic.  TLS exchanges records \r\neach record has a content-type and MAC; all records are numbered.\r\nContent type 22 is handshake.  Results in 2 encryption keys, 2 integrity keys and 2 IV's.\r\n\\begin{description}\r\n\\item M1: ($C \\rightarrow S$) ClientHello(Client-random[28], cipher-suites, compression methods, highest protocol version),\r\n\\item M2: ($S \\rightarrow C)$ ServerHello(ServerRandom[28], cipher-suite, certificates),\r\n\\item M3: ($C \\rightarrow S$) ClientKeyExchange(E(PkS, Pre-Master Secret), \r\nMD5-SHA1(M1 || M2|| M3A)), [Master Secret is PRF(Pre-master secret, ``master secret'', \r\nClientRandom || ServerRandom)],\r\n\\item M4: ($S \\rightarrow C$) Finish MD5-SHA1(M1 || M2 || M3A || M3C).\r\n\\end{description}\r\n{\\bf IPSEC:} Two protocols: securing packets and key negotiation.  Two modes: \r\ntransport and tunnel.  In transport mode only payload is encrypted.  Packets can be \r\nsecured for authentication and integrity only (AH) or authentication, confidentiality and\r\nintegrity.  IKE Phase1: CP (crypto proposed), CS (crypto selected), \r\nIC (initiation cookie),\r\nRL (response cookie), $K= h(IC,RC,g^{ab} \\jmod{p}, R_A, R_B)$.  \r\n$SKEYID= h(R_A, R_B, g^{ab} \\jmod{p})$.  $Proof_A: \r\n[h(SKEYID, g^a \\jmod{p}, g^b \\jmod{p}, IC, RC, CP, ``Alice'']_{Alice}$. Public Key:\r\n(1) $A \\rightarrow B:$ IC, CP.\r\n(2) $B \\rightarrow A:$ IC, RC, CS.\r\n(3) $A \\rightarrow B:$ IC, CP $g^a \\jmod{p}, \\{R_A\\}_{Bob}, \\{``Alice''\\}_{Bob}$.\r\n(4) $B \\rightarrow A:$ IC, CP $g^b \\jmod{p}, \\{R_B\\}_{Alice}, \\{``Bob''\\}_{Alice}$.\r\n(5) $A \\rightarrow B:$ IC, CP $E(Proof_A;K)$.\r\n(6) $B \\rightarrow A:$ IC, CP $E(Proof_B;K)$.\r\n\\\\\r\n\\\\\r\n{\\bf Fiat-Shamir:}\r\nProve knowledge of a secret, $s$, where $v= s^2 \\jmod{n}$, $n=pq$; $v, n$, public.\r\n$A$ proves she knows $s$: (1) $A$ picks $r$ at random and computes $x=r^2 \\jmod{n}$ ---\r\ncommitment, (2) $B$ chooses $e \\in \\{ 0, 1 \\}$ at random and sends $e$ to $A$ --- challenge, (3)\r\n$A$ computes $y= rs^e \\jmod{n}$ and sends it to Bob --- response, (4) finally, $B$ verifies\r\n$y^2= r^2 s^{2e} = xv^e \\jmod{n}$ --- verify this.\r\n\\\\\r\n\\\\\r\n{\\bf S/Mime:} \r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nDSig:\r\n<Signature>\r\n  <SignedInfo>\r\n    <CanonicalizationMethod/>\r\n    <Reference URI=?>\r\n      <Transforms/>\r\n      <DigestMethod/>\r\n      <DigestValue/>\r\n  </SignedInfo>\r\n  <SignatureValue/>\r\n  <KeyInfo/>\r\n  <Object>\r\n</Signature>\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nXML Encryption:\r\n<EncryptedData>\r\n  <EncryptionMethod/>\r\n  <KeyInfo>\r\n    <AgreementMethod/>\r\n    <KeyName/>\r\n    <RetrievalMethod/>\r\n  </KeyInfo>\r\n  <CipherData/>\r\n</EncryptedData>\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nSAML: Authn/AuthZ Request/Response over SOAP.  \r\n      Assertion, conditions, advice.\r\nXACML: Authorization Rules: \r\n      Subjects, Resources, Actions.\r\nREL: Grant, Principal, Right, Resource, Condition.\r\nWS-Policy: security policy\r\nWS Trust: Trust\r\nWS-Privacy including WS-Secure \r\n   Conversation, Federation.\r\nWS-Authorization: Principal, Claim, Token.\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\nMore Timings: P4, 2.1 GHz.  AES: 44 operations/round.\r\n\\begin{center}\r\n\\begin{tabular} {|rrr|rrr|}\r\n\\hline\r\n{\\bf Algorithm} & {\\bf Key Size} & {\\bf Speed(MB/sec)} & {\\bf Algorithm} & {\\bf Key Size} & {\\bf Speed(MB/sec)} \\\\\r\n\\hline\r\nDES & 56 & 21 & 3DES & 168 & 9.8 \\\\\r\nSHA-1 & NA & 68 & SHA-256 & NA & 44 \\\\\r\nTEA & 64 & 23 & AES & 128 & 61 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Reestimation:} Rotor modeled by $S(r_j , R)= C^r R C^{-r}$ and represented by a\r\n$q \\times q$ permutation matrix.  Key space is $D_1 \\times D_2 \\times \\ldots \\times D_k$,\r\n$D_i$ is all $q!$ permutation matrices.\r\n$\\chi^{cs} = {\\chi_1}^{cs} \\times {\\chi_2}^{cs} \\times \\ldots \\times {\\chi_k}^{cs}$,\r\n${\\chi_i}^{cs}$ is all possible $q \\times q$ stochastic matrices.  Suppose\r\n${\\vec p}$ is plaintext distribution.\r\n$d(r, x)= S(r,x) {\\vec p}$.  Likelihood $L(X | \\{c, r \\}) =\r\nPr(ciphertext= \\{c_1\\}^N | \\{r_1\\}^N; X)= \\prod_{n=1}^N {e_{c(n)}}' d(r(n); X)$.  \r\nWant to maximize $L$ by adjusting $X$.  The MLE of $X$ exists and is strongly consistent.\r\nUse the following result:  Let $P(z)$ be a polynomial with non-negative coefficients\r\nhomogeneous of degree $d$ in $z_{ij}$, ${\\cal Z}= \\{ z_{ij}: z_{ij} \\ge 0,\r\n\\sum_i^{q_j} z_{ij} =1 \\}$.  ${\\cal T}(z)_{ij}= z_{ij} \r\n{\\frac {\\frac {\\partial P} {\\partial {z_{ij}}}}\r\n{\\sum_i^{q_j} z_{ij} ({\\frac {\\partial P} {\\partial {z_{ij}}}})_z}}$.  Computations\r\nrequires is\r\n$\\approx k q^2 N$ and a $2$ rotor machine with $N=1024$ ciphertext letters requires about\r\n$60$ iterations.\r\n\\section{Random Number Quality}\r\n{\\bf Motivation:}\r\nTraditional approach for getting $n$ bit value:\r\n(1) Get large sample. (2)\r\nCalculate the relative frequency, $r_w$, of each word $w$ in $b$-bit block.\r\n(3) Estimate $H= - \\sum_{w=0}^{2^r-1} r_w lg(r_w)$.\r\nRepeat ${\\frac n H}$ times.  Total bits checked: $\\lceil {\\frac {nb} H} \\rceil$\r\nConcern: small set of possible values and deterministic mixing reduces entropy.\r\nEntropy is not the best measure of security.  Consider the following:\r\n\\\\\r\n\\\\\r\n{\\bf Theorem.}  The entropy of a source $P= \\langle <p_1 ,p_2 , \\ldots , p_N \\rangle$ \r\nwhich is mixed\r\nby $F: [1..N] \\rightarrow [1..m]$ is greater than the entropy of the mixed sequence.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $Prob(O=j)= q_j$ and $Q=  \\langle q_1, q_2, \\ldots, q_m \\rangle$.\r\n$H_{out}=H_Q\r\n= - \\sum_{j=1}^m q_j lg(q_j)\r\n= - \\sum_{j=1}^m [\\sum_{f(i)=j} p_i] lg([\\sum_{f(i)=j} p_i])\r\n= - \\sum_{i=1}^N p_i lg(p_i + S_i)<H_p=H_{in}$, where $S_i= \\sum_{j \\ne i, F(i)=F(j)} p_j$ \r\nfor the standard Shannon entropy $H_Q= - \\sum_{i=1}^N p_i lg(p_i)$.\r\n\\end{quote}\r\n{\\bf Observation:}\r\nSuppose $T$ values are required in cryptoperiod;\r\nif $Q= \\langle q_1 , q_2 , \\ldots , q_m \\rangle$ is the distribution and\r\n$q_{i_1} \\ge q_{i_2} \\ge \\ldots \\ge q_{i_m}$, adversary's best strategy\r\nis to guess $\\langle i_1, i_2, \\ldots \\rangle$ until success.  \r\nThis motivates a different entropy measure.\r\nDefine $H_{\\alpha}(Q)= {\\frac 1 {1- \\alpha}} \\sum_{j=1}^M {q_j}^2$.  \r\n$H_2(Q)$ is a good measure for collision resistance (not secrecy) since\r\n$\\sum_{j=1}^m {q_j}^2=2^{- H_2(Q)}$;\r\nthe waiting time for repeats is ${\\sqrt {\\pi 2^{H_2(Q)-1}}}$.\r\n$H_{\\infty}(Q)$ is a good measure for the quality of resulting key generation,\r\nsince the expected cost of the guessing attack is ${\\frac 1 {2 q_{max}}}=2^{H_{\\infty}(Q)-1}$.\r\nAs an example, consider the distribution, \r\n$Q$ over $128$ bit quantities consisting of one value that\r\noccurs with probability $2^{-80}$ and is otherwise flat.  \r\n$H_2(Q) \\approx 128$, $H_{\\infty}(Q) \\approx 80$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nIf $X$ is a event with\r\n$n$ possible outcomes having respective probabilities $p_1 , p_2 , \\ldots , p_n$\r\nthe \\emph{min-entropy} of $X$ is \r\n$H_{\\infty}(X)= min_{1 \\le i \\le n} -lg(p_i)= - lg(max_i(p_i))$.\r\nTo get an estimate of the min-entropy or $W(Q)$, we need $S(Q)$.\r\nSuppose randomizer produces $m= 2^n$ outputs with probability distribution\r\n$Q= \\langle q_1, q_2 , \\ldots , q_m \\rangle$.  Quality of $Q$ is\r\n$S(Q)= \\sum_{j=1}^m q_j^2 \\ge {\\frac 1 m}$ which is the probability of repeated output.\r\n$W(Q)= \\sum_{j=1}^m j q_j \\le {\\frac {m+1} 2}$ which is the adversary's work factor.\r\nEstimating either $H_2(Q)$ or $H_{\\infty}(Q)$ consists of four steps.\r\n(1) Form Markov model of input source data (over $L$ consecutive samples),\r\n(2) Compute source data repeat probability,\r\n(3) Estimate $S(Q)$,\r\n(4) Use $S(Q)$ to estimate lower bound on $W(Q)$ and/or $H_{\\infty}(Q)$.\r\n\\\\\r\n\\\\\r\n{\\bf Entropy Order Paradox:} Consider \r\n$Q_1=\\langle 0.258, 0.116, 0.146, 0.032, 0.140, 0.266, 0.038, 0.004 \\rangle$ and\r\n$Q_2=\\langle 0.256, 0.232, 0.076, 0.130, 0.006, 0.157, 0.005, 0.129 \\rangle$.\r\n$H(Q_1)= 2.54542$ and\r\n$H(Q_2)= 2.54495$ but\r\n$S(Q_1)= 0.194176$ and\r\n$S(Q_2)= 0.188076$ while\r\n$W(Q_1)= 2.844$ and\r\n$W(Q_2)= 2.903$.\r\n\\\\\r\n\\\\\r\n{\\bf Step 1 -  Markov Model:}\r\nThe model consists of $\\Theta= \\langle  \\theta_1 , \\theta_2 , \\ldots , \\theta_L \\rangle$ \r\nstates where where $\\rho$ is the initial probability distribution, and\r\n$T=\r\n\\left(\r\n\\begin{array}{cccc}\r\n\\tau_{1,1} & \\tau_{1,2} & ...  & \\tau_{1,s}\\\\\r\n\\tau_{2,1} & \\tau_{2,2} & ...  & \\tau_{2,s}\\\\\r\n... & ... & ... & ...\\\\\r\n\\tau_{s,1} & \\tau_{s,2} & ...  & \\tau_{s,s}\\\\\r\n\\end{array}\r\n\\right)$ is the transition matrix.  The procedure is to\r\n(1) Model source as sequence of states $\\langle s_1 , s_2 , \\ldots , s_s \\rangle$,\r\n(2) Get $\\rho$ (use steady state estimate),\r\n(3) Determine state defining bits.  For multiple sources,\r\n$\\Theta^{(k)}= \\langle \\theta_1 , \\theta_2 , \\ldots , \\theta_{i_k} \\rangle$ and\r\n$\\sum_{i=1}^N {p_i}^2=\r\n\\sum_{i_1=1}^{N_1} \r\n(p_{i_1}^{(1)} p_{i_2}^{(2)} \\ldots p_{i_k}^{(k)})^2$.\r\n{\\bf Step 2 -  Compute source data repeat probability:}  \r\n$\\sum_{j=1}^N {p_j}^2\r\n= [\\rho_1, \\rho_2, \\ldots \\rho_s] T [1,1, \\ldots, 1]^T$.\r\n{\\bf Step 3 -  Estimate $S(Q)$:} $S(Q) = \\sum_{j=1}^m q_j^2={\\frac 1 m}\r\n(1+ \\epsilon_s)$ where\r\n$(1+ \\epsilon_s)= (m-1) \\sum_{i=1}^N p_i^2$.\r\n{\\bf Step 4 (for $H_2$) -  Estimate $W(Q)$ using $S(Q)$ for $L$ source inputs:}\r\nTo get the best possible bound on $W(Q)$\r\ngiven $S(Q)$ ($q_j$ unknown):  Let\r\n$m'= min(m, {\\frac {3S(Q)+4+{\\sqrt {9 S(Q)^2+16}}} {6S(Q)}}) \\approx min(m, {\\frac 4 {3S(Q)}})$\r\nthen $W(Q) \\ge B$ where\r\n$B= {\\frac 1 6}  (3m'+3-{\\sqrt {3 (m'^2-1) (m'S(Q)-1)}})$.  To obtain this result use Lagrange\r\nmultipliers to minimize $W(Q)$ subject to $\\sum_{j=1}^m {q_j}^2 =S(Q)$ and\r\n$\\sum_{j=1}^m q_j=1$.\r\n{\\bf Step 4 (for $H_{\\infty}$):}  Use Dynamic Programming compute $p_{max}$ or proceed as\r\nfollows: Set \r\n$y_1=F(x_1)$, $q_1= Pr[y_1]= p_{max}+\\sum_{i=2}^N p_i I_{i,1}$ and\r\n$q_j= \\sum_{i=2}^N p_i I_{i,j}$.  \r\n$\\mu_1 = E[q_1]={\\frac 1 M} [1+(M-1)p_{max}]$,\r\n$\\mu_2 = E[q_j]={\\frac 1 M} [1-p_{max}]$,\r\n$\\sigma_1^2= \\sum_{i=2}^N {p_i}^2 Var(I_{i,1})= (\r\n{\\frac 1 M} -\r\n{\\frac 1 {M^2}}) \\sum_{i=2}^N{p_i}^2$ and for $j \\ge 2$,\r\n$\\sigma_j^2= {\\frac {M-1} M} \\sum_{i=2}^N {p_i}^2$. $-lg(\\mu_1)$ is a good estimate for\r\n$H_{\\infty}(Q)$.\r\nWant $|-lg( \\mu_1) - H_{\\infty}(Q)| \\le {\\frac 1 2} 10^{s-d+1}$, \r\nwhereas $s$ is largest integer:\r\n$10^s \\le H_{\\infty}(Q)$.  If $Y$ is the number of $q_j$ exceeding $B$, $Pr[q_{max} \\le B]\r\n= 1- Pr[Y>0] \\ge 1-E[Y]>1- \\epsilon$.  \r\n$Pr[E_j]= Pr[z> {\\frac {\\mu_1^{1-{\\frac 1 2} 10^{-d}}} {\\sigma}}, j>1$.\r\nPut $B= max(\\mu_1+T_1 \\sigma, \\mu_2 + T_2 \\sigma)$, where $z$ is normally\r\ndistributed and \r\n$Pr(z>T_1)= {\\frac {\\epsilon} 3}$ while\r\n$Pr(z>T_2)= {\\frac {\\epsilon} {3(M-1)}}$ then \r\n$Pr(\\mu_1^{1+{\\frac 1 2} 10^{-d}} \\le p_{max} \\le \\mu_1^{1-{\\frac 1 2} 10^{-d}}) \\ge (1- \\epsilon)$.\r\n\\\\\r\n\\\\\r\n\\emph{Example ($L=3$):} Let $b_t , b_{t+1}, b_{t+2}$ be three successive states and\r\n$Prob(b_{t+2}=b_{t+1} \\oplus b_t)= .8$ with $s=4$ states then\r\n$T=\r\n\\left(\r\n\\begin{array}{cccc}\r\n.8 & .2 & 0 & 0\\\\\r\n0 & 0 & .2 & .8\\\\\r\n.2 & .8 & 0 & 0\\\\\r\n0 & 0 & .8 & .2\\\\\r\n\\end{array}\r\n\\right)$ and the initial distribution\r\n$\\rho= (.25, .25, .25, .25)$.\r\nThe state distribution is $\\Theta= \\langle  \\theta_1 , \\theta_2 , \\theta_3 \\rangle$.\r\nIn SHA-1 mixing example, $\\sum_{i=1}^N p_i^2 = 4.87 \\times 10^{-44}$, $L= 256$ and\r\nwe compute $S(Q)= \\sum_{i=1}^m q_j^2 \\approx\r\n{\\frac 1 m} [ 1+ (m-1) \\sum_{i=1}^N p_i^2]$. $m= 2^{160}$.\r\n$m=2^{160}$, $m'= 2.74 \\times 10^{43}$, $W(Q) \\ge 9.1 \\times 10^{42}$.\r\n\\\\\r\n\\\\\r\n{\\bf Parameter Estimate:}\r\n$N= \\alpha \\Gamma^{L-1} U$, $\\alpha$ is initial $\\rho$, $\\Gamma$ is initial $T$.\r\n$U=[1,1, \\ldots, 1]^T$.\r\n$I_{i,j}$ is $1$ if $F(i)=j$ and $0$ if $F(i) \\ne j$.\r\n$q_j= \\sum_{i=1}^N I_{i,j} p_i$,\r\n$E(q_j)= \\sum_{i=1}^N p_i E(I_{i,j})= {\\frac 1 m}$.\r\n$Var(q_j)= \\sum_{i=1}^N p_i^2 Var(I_{i,j})$.\r\n$Var(I_{i,j})= {\\frac 1 m} - {\\frac 1 {m^2}}$.\r\n$Var(q_{j})=  \\sum_{i=1}^N p_i^2 Var(I_{i,j})= {\\frac {m-1} {m^2}} \\sum p_i^2$.\r\n$E(\\sum_{j=1}^m) q_j^2)=  \\sum_{i=1}^N E(q_j^2)= \\sum_{j=1}^N E(q_j^2) + Var(q_j) =\r\n{\\frac 1 m} (1 +(m-1) \\sum_{i=1}^N p_i^2$.\r\n\\\\\r\n\\\\\r\n{\\bf Extension to HMM:}\r\nTransition matrix $T= \\tau_{i,j}$, $s$ states, ${\\vec \\rho}$ initial\r\ndistribution, $\\theta_t \\in \\{1,2, \\ldots, r\\}$ is the output at time $t$,\r\n$C^{(n)}= (c_{i,j}^{(n)})$, \r\n$c_{i,j}^{(n)}= \\sum_{\\theta_1 , \\ldots , \\theta_n} \r\nPr(\\theta_1, \\ldots , \\theta_n, \\sigma_n=i) Pr(\\theta_1, \\ldots , \\theta_n, \\sigma_n=j)$. \r\n$\\sum_{i,j} c_{i,j}^{(n)} = \\sum_{i=1}^N p_i^2= \\sum_{\\theta_1 , \\ldots , \\theta_n} \r\nPr(\\theta_1, \\ldots , \\theta_n)^2$ and\r\n$C^{(n)} = (B B^T) \\cdot (T^T C^{(n-1)} T)$ where $\\cdot$ means \r\nelementwise multiplication.  Recursion step requires $2s^3$ multiplications.\r\n$\\approx 7$ minuses for $400$ outputs without eigenvalue.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n$f: G \\rightarrow {\\mathbb C}$,\r\n$g: G \\rightarrow {\\mathbb C}$, $E(f)=E(g)=0$, $E(|f|^2)= E(|g|^2)= =1$.\r\n$S_{fg}= f(x) \\cdot {\\overline {g(y)}}$, $L_{ab}(X,Y)= \\chi^a(x) \\chi^{-b}(y)$.  Imbalance\r\nof $S$: $I(S)= |E(S)|^2$, ${\\overline I}(S)= {\\frac 1 K} \\sum_{k \\in K} I(S|K=k)$.\r\n$C= (c_{ab}), c_{ab}= {\\overline I}(L_{ab}(X,Y))$, $a, b \\in G \\setminus \\{0\\}$.\r\nLet $y=e_k(x)=x+k$, $c_{ab}= \\delta(a \\oplus b)$.  \r\n$c_{ab}= {\\frac 1 {|K|}} \\sum_k |{\\cal F}(\\chi^b \\cdot e_k)(a)|^2$,\r\n${\\overline I}(S)= {\\hat f}^T C {\\hat g}$. \r\n${\\hat f}_a= | {\\cal F}(f)(a)|^2$,\r\n${\\hat g}_b= | {\\cal F}(g)(b)|^2$.  The \\emph{likelihood estimate of correlation} is\r\n${\\tilde I}(S)= | {\\frac 1 N} \\sum_{x,y} f(x) {\\overline {g({\\tilde y})}}|^2$.\r\n$\\xi(x,J,N)$ is the \\emph{imbalance distribution} with imbalance parameter $J$.\r\n$\\xi(x,J,N) {\\frac {2N} {1-J}} h({\\frac {2N} {1-J}}x, {\\frac {2N} {1-J}}J) $  where\r\n$h(\\cdot, s)$ is the probability density of $\\chi^2$ with $2$ degrees of freedom\r\nand skewness parameter $s$.  \r\n$\\xi(x,J,N)= {\\frac N {(1-J) {\\sqrt \\pi}}} e^{-{\\frac {N(x+J)} {1-J}}}\r\n\\sum_{r=0}^{\\infty} \\sigma_r$ where $\\sigma_r= {\\frac 1 {(2r)!}} (({\\frac {2N} {1-J}})^2 Jx)^r\r\n{\\frac {\\Gamma(r+{\\frac 1 2})} {\\Gamma(r+1)}}$.  If $J << ({\\frac 1 {2N}})^2$, $\\xi(x,J,N) \\approx\r\nh(x,J,N)$, $h(x,J,N)= {\\frac N {1-J}} e^{-{\\frac {N(x+J)} {-1J}}}$ with accumulated\r\nerror $\\epsilon= 1- e^{-{\\frac {JN} {1-J}}}$.\r\n\\\\\r\n\\\\\r\nLet $S$ be an I/O product and $S_1, \\ldots , S_N$ samples,\r\n${\\tilde I}(S) = |{\\frac 1 N} \\sum_{j=1}^N S_j |^2$.  Let $E$ be an ${n-1 \\times n-1}$\r\nmatrix with $E_{ij}= {\\frac 1 {n-1}}$ and $C$ the truncated correlation matrix.\r\n$C^r-E= (C-E)^r$ and $\\sigma_2(C)= \\sigma_1(C-E)$ where $\\sigma_k(M)$ is the $k$-th largest\r\nsingular value of $M$.  Let $D= C^T C= V^{-1} \\Lambda V$, $\\Lambda= diag(1, \\sigma_2(C) , \\ldots)$.\r\n{\\bf Theorem:} Let each of the $r$ rounds of an interactive cipher have correlation matrix\r\n$C$ then ${\\overline I}(S) \\le {\\frac 1 {n-1}} + ||C-E||^r$; also,\r\n${\\overline I}(S) \\le {\\frac 1 {n-1}} + \\sigma_2(C)^r$,\r\n$\\sigma_2(C) \\le min \\langle \r\n(1-\\sum_b min_a (C^TC)_{ab})^{\\frac 1 2}, (1-\\sum_a min_b (C^TC)_{ab})^{\\frac 1 2} \\rangle$.\r\n\\\\\r\n\\\\\r\nLet $\\otimes$ be the Kroneker product.  \r\n$\\Phi(M,N)= \\sum_{a,b} g_{ab} M^a \\otimes N^b$,\r\n$\\phi(x,y)= \\sum_{a,b} g_{ab} x^a y^b$.  The eigenvalues of $\\Phi(M,N)$ are\r\n$\\phi(\\lambda_r(M), \\lambda_s(N))$.  if $C= A \\otimes B$, the singular values of\r\n$C$ are products of the singular values of $A$ and $B$.\r\nThe correlation of a non-keyed permutation $R= G \\rightarrow G$ is $C= (F^*PF) ({\\overline\r\n{F^*PF}})$ where $F=(f_{ab}))$, $f_{ab}= {\\frac 1 {\\sqrt n}} \\chi^{-a}(b)$, $P= (p_{ab})$,\r\n$p_{ab} = \\delta (a \\oplus \\phi(b))$.  $C=U \\cdot {\\overline U}$ where $U$ is unitary.\r\n{\\bf Theorem:} The correlation matrix of a keyed permutation $e_k: G \\rightarrow G$ is\r\n$C= {\\frac 1 {|K|}} \\sum_k C^{(k)}$, $C^{(k)}= U^{(k)} {\\overline U}^{(k)}, U^(k)= F P^{(k)} F^*$,\r\n$P^{(k)}= \\delta(a \\oplus e_k(b))$.\r\n\\\\\r\n\\\\\r\n{\\bf Dan's attack on RNGs:}\r\n\\begin{verbatim}\r\n    s= IV;\r\n\r\n    NewRN() {\r\n        t= s;\r\n        s= b**t (mod p);\r\n        r= q**t (mod p);\r\n        output(r);\r\n    }\r\n\\end{verbatim}\r\nSuppose we know $e: q=b^e \\jmod{p}$ then $r= b^{et}= (b^t)^e = s^e \\jmod{p}$.\r\n\\section{Related key attack on AES-256}\r\n{\\bf Reminder:} AES-128 has 10 rounds, AES-192 has 12 rounds and AES-256 had 14 rounds.\r\n\\\\\r\n\\\\\r\n{\\bf Birykov et al $9$-Round attack on AES-256:}\r\nGiven\r\ntwo keys $K_1, K_2$ related by $K_2= K_1 \\oplus (b,b,b,b,a,0^{32},a,0^{32})$ ($a, b$) specified\r\nbelow and $2^{38}$ related plaintexts ($P_2= P_1 \\oplus (b,b,b,b)$), with each plaintext\r\nencrypted by each of the two related keys, we can find $K_1, K_2$ with work factor about $2^{39}$.\r\n\\\\\r\n\\\\\r\n{\\bf Notation and key schedule:}  $SB$, $SR$, $MC$, and $ARK$ are respectively the SubByte,\r\nshift-row, mix-column and add round-key transformations.  Byte order for $32$-bit input words is:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|r|r|}\r\n\\hline\r\n$0$ & $4$ & $8$ & $12$ \\\\\r\n\\hline\r\n$1$ & $5$ & $9$ & $13$ \\\\\r\n\\hline\r\n$2$ & $6$ & $10$ & $14$ \\\\\r\n\\hline\r\n$3$ & $7$ & $11$ & $15$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nSuppose the $256$ key is written as $8$ $32$ bit words $W[0], \\ldots, W[7]$, the first\r\ntwo round keys are \r\n$W[0], \\ldots, W[3]$ and\r\n$W[4], \\ldots, W[7]$.  The remaining round keys are determined by:\r\n\\begin{verbatim}\r\n    for(i=8; i<60; i++) {\r\n        if((i%8)==0)\r\n            W[i]=W[i-8]^(SB,SB,SB,SB)W[i-1]+RCon(i/8);\r\n        else if((i%8)==0)\r\n            W[i]=W[i-8]^(SB,SB,SB,SB)W[i-1];\r\n        else\r\n            W[i]=W[i-8]^W[i-1];\r\n    }\r\n\\end{verbatim}\r\n{\\bf 8 round key trail for attack:} Let $\\alpha \\rightarrow \\beta$ be a differential\r\nthat occurs through $SB$ with probability $2^{-6}$.  Put \r\n$a=(\\alpha,0,0,0)^T$ and\r\n$b=MC((\\beta,0,0,0)^T)$.  Rounds are numbered $0, 1, \\ldots ,7$.\r\n$\\delta= (b,b,b,b,a,0,a,0)$, $c= b \\oplus SB(RotByte(a))$, $d= a \\oplus SB(c)$, $e= d \\oplus a$,\r\n$f=b \\oplus c$.  $\\Delta(K^i)$ is the (xor) differenece of the subkey for round $i$ and\r\n$\\Delta(I^k)_{i,j}$ means the difference in the input to round $k$ of bytes $i$ and $j$.\r\n\\\\\r\n\\\\\r\n{\\bf Basic $8$ round differential:} $(b,b,b,b) \\rightarrow (f,f,f,f), p= 2^{-54}$ can\r\nbe constructed as follows: $P_1= P_2 \\oplus (b,b,b,b)$ and $\\Delta(K^0)= (b,b,b,b)$.\r\n$\\Delta(I^0)= 0^{128}$.  At the end of round 0, the difference is $0^{128}$ and $ARK$\r\nat the end of round $0$ adds a difference of $(a,0,a,0)$ which introduces two non-zero\r\nbytes with value $\\alpha$.  Because of the differential, with $p=2^{-12}=2^{-6} \\times 2^{-6}$,\r\nthe difference becomes $(b,0,b,0)$ which is xored with the key differential $(b,0,b,0)$ yielding\r\n$\\Delta(I^2)=0$ with $p=2^{-12}$.  Similarly, given this difference, application of\r\nrounds $2,3$ yield $\\Delta(I^4)=0$ with probability $2^{-12}$.  The combined probabililty\r\nthat \r\n$\\Delta(I^4)=0$ is $p= 2^{-12} \\times 2^{-12}= 2^{-24}$.  The transition probability that\r\n$\\Delta(I^4)=0 \\rightarrow \\Delta(I^6)=(b,b,b,b)$ is $2^{-6}$ and\r\n$\\Delta(I^6)=(b,b,b,b) \\rightarrow \\Delta(I^8)=(f,f,f,f)$ is $2^{-24}$.  Thus\r\nthe plaintext differential \r\n$(b,b,b,b) \\rightarrow (f,f,f,f)$ occurs with $p=2^{-54}$.\r\n\\\\\r\n\\\\\r\n{\\bf Actual differentials used:}  By modifying the $8$ round differentials, we get three\r\ntruncated differentials: \r\n(1) By relaxing the conditions in round $7$ and insisting that\r\nonly byte $0$ have difference $0$, we get $\\Delta(I^8_{0,1,2})=0, p=2^{-36}$.\r\n(2) (the ``Shifted Differential'') By relaxing the conditions in round $7$ and insisting that\r\nonly byte $12$ have difference $0$, we get $\\Delta(I^8_{13,14})=0, p=2^{-36}$.\r\n(3) (the ``Complemented Differential'') By relaxing the conditions in round $5$ in a $6$\r\nround differential and not imposing a condition on byte $5$ (the others are $0$), we obtain\r\n$16$ possible differential outputs at the input to round $7$.\r\nonly byte $12$ have difference $0$, we get $\\Delta(I^8_{13,14})=0, p=2^{-36}$.\r\n\\\\\r\n\\\\\r\n{\\bf Full $9$ Round attack:}\r\n\\\\\r\n\\\\\r\n\\jt 1. Generate $2^{37}$ pairs $P'=P \\oplus (b,b,b,b)$ and encrypt each $P$ and $P'$ with\r\n$K$ and $K \\oplus (b,b,b,b,a,0,a,0)$.  Insert the cipher pairs $(C, C')$ in a hash\r\ntable indexed on $\\Delta(C)_{0, 10, 13}= {d_0, d_1, d_2}$.  Right pair has\r\n$\\Delta(I^{8}_{0,1,2})= 0$.\r\n\\\\\r\n\\\\\r\n\\jt 2. Guess $K_{12}^8$ and partially decrypt to get $\\Delta(I^8_{12})$.  \r\n$\\Delta(K^8_{12})= d_0 \\oplus \\alpha$ is known.\r\n\\\\\r\n\\\\\r\n\\jt 3. Do same as $2$ to $d_0, d_1, d_2, K_{12}^8$ to get $6$ bytes of $K^8$ ($2,5,6,8,9,12)$).\r\n\\\\\r\n\\\\\r\n\\jt 4. For each remaining pair, guess $c_3, d_3$ and use $SB$ on ($3,7,11,15$) of round $8$\r\nto suggest $K^8_{3,7,11,15}$.\r\n\\\\\r\n\\\\\r\n\\jt 5. Repeat with shifted differential.\r\n\\\\\r\n\\\\\r\n\\jt 6. By now, $K^8$ is known decrypt through round $7$ then find $K^7$ as follows:\r\n\\\\\r\n\\jt \\jt (a) For right pairs, under main $8$ round differential, guess $K^7_{0,4,8,12}$ and\r\npartially decrypt to get \r\n$\\Delta(I^7_{0,4,8,12})$ discard when\r\n$\\Delta(I^7_{0,4,8,12}) \\ne ( \\alpha, \\alpha , \\alpha, \\alpha)$.  Right differences suggest\r\nright key values.\r\n\\\\\r\n\\jt \\jt (b) Use key schedule to get possible $K^7_{13,14,15}$.\r\n\\\\\r\n\\jt \\jt (c) Now $K^7_{0,4,8,13,14,15}$ is known.\r\nFor $2^{26}$ to of the $2{38}$ pairs: Partially decrypt to get \r\n$\\Delta(I^7_{0,1,4,6,8,11})$.  Consider colums $0,1,2$ of $\\Delta(I^7)$ separately and\r\nsee if the differences of the two ``known'' bytes agree with the complementary differential.\r\nThis filters $8$ bits.  Finally, for each of the remaining pairs, use\r\n$\\Delta(I^7_{0,4,8,12})$ to retrieve full difference $\\Delta(I^7)$.  Then use the I/O differences\r\nthough SB to suggest byte values for each byte of $K^7$ and discard bytes suggested less than\r\n$3$ times.  This should get the right key most times.\r\n\\\\\r\n\\\\\r\n\\jt 7. Now, $K^7$ and $K^8$ are known and we can run the key schedule backwards to get the key.\r\n\\section{Trivium and Cube}\r\n{\\bf Cube Attack:}\r\nFor any polynomial $P$ and term $t$, write $P= tP_t+Q$, where\r\nthe variables in $P_t$ are disjoint from those in $t$\r\nand each term in Q misses at least one variable from $t$.\r\n$P_t$ is called the \\emph{superpoly} of $t$ in $P$.  \r\nA \\emph{maxterm} of $P$ is any product $t$ of variables whose superpoly has degree $1$ \r\n(i.e., is a linear or affine function which is not a constant).\r\n\\emph{Example:}\r\n$P(x_1,x_2,x_3,x_4,x_5) =x_1x_2x_3+x_1x_2x_4+x_2x_4x_5+x_1x_2+x_2+x_3x_5+x_5+1 $.\r\nLet $t=x_1x_2$, $P(x_1,x_2,x_3,x_4,x_5)= x_1x_2(x_3+x_4+1)+(x_2x_4x_5+x_3x_5+x_2+x_5+1)$,\r\nthe superpoly of $x_1x_2$ in $P$ is $(x_3+x_4+1)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\n$\\sum_t (tP_t+Q) = P_t$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$\\sum_t Q = 0$ since every numerical value appears an even number of times.\r\n$\\sum_t (tP_t+Q) = \r\n(\\sum_t t) P_t$ since the only term in the sum that is non-zero is the one where all the variables are $1$.\r\n\\end{quote}\r\n{\\bf To apply in attack:}\r\nFor each candidate maxterm $t$, choose pairs of values for all the other variables \r\n$X'$ and $X''$. Verify that the numerical values of the subcube sums satisfy the linearity test:  \r\n$P_t(X')+P_t(X'')= P_t(X'+X'')+P_t(0)$.\r\nIf the test succeeds multiple times, obtain the linear superpoly by checking the \r\nnumeric effect of flipping each key bit $x_i$.\r\n\\begin {multicols} {2} {\r\n\\begin {verbatim}\r\n\r\n//  Trivium\r\n\r\n//     Key size: 80 bits\r\n//     IV size: 80 bits\r\n//     State size: 288 bits\r\n//     Up to 2^64 keystream bits\r\n\r\n//     Step takes 15 bits and produces 3 new \r\n//          state bits and 1 output bit.\r\n\r\nInit() \r\n{\r\n    (s[1],..., s[93]):= (k[1],..., k[80], \r\n                         0,...,0);\r\n    (s[94], ..., s[177]):= (IV[1], ...,IV[80], \r\n                            0, ...,0);\r\n    (s[178], ..., s[288]):= (IV[1], ...,IV[80], \r\n                             0, ...,0,1,1,1);\r\n    for(i=1; i<= 4*288) {\r\n        t1= s[66]+s[91]*s[92]+s[93]+s[171];\r\n        t2= s[162]+s[175]*s[176]+s[177]+s[264];\r\n        t3= s[162]+s[175]*s[176]+s[177]+s[264];\r\n        (s[1],..., s[93]):= (t3,s[1],...,s[92]);\r\n        (s[94],..., s[177]):= (t1,s[94],...,s[176]);\r\n        (s[178],..., s[288]):= (t2,s[178],...,s[288]);\r\n    }\r\n}\r\n\r\n\r\nStep() \r\n{\r\n    t1= s[66]+s[93];\r\n    t2= s[162]+s[177];\r\n    t3= s[243]+s[288];\r\n    z= t1+t2+t3;\r\n    t1+= s[91]*s[92]+ s[171];\r\n    t2+= s[175]*s[176]+ s[264];\r\n    t3+= s[286]*s[287]+ s[69];\r\n    (s[1],..., s[93]):= (t3,s[1],...,s[92]);\r\n    (s[94],..., s[177]):= (t1,s[94],...,s[176]);\r\n    (s[178],..., s[288]):= (t2,s[178],...,s[288]);\r\n    return (z);\r\n}\r\n\r\n\\end{verbatim}\r\n}\r\n\\end {multicols}\r\nShamir and Dinur found $35$ maxterms in the $767$ round initialization.\r\n\\\\\r\n\\\\\r\n{\\bf Stream Cipher Notation:} \r\nInput is $x(D)= x_0 + x_1 D + x_2 D^2 + \\ldots $.\r\nOurput is $y(D)= y_0 + y_1 D + y_2 D^2 + \\ldots $.\r\n$f(x)$ is feedforward polynomial and $g(x)$ is feedback polynomial.\r\n$y(D)= {\\frac {f(D)}{g(D)}} [x(D) + x^0(D)] + y^0(D)$ where\r\n$x^0= D^{-m} (s \\cdot g \\jmod{D^m}$,\r\n$y^0= D^{-m} (s \\cdot f \\jmod{D^m}$.\r\n$B= min_{\\Gamma \\ne 0} [w_h(\\Gamma_Y) + w_h(M^T \\Gamma_Y)]$.\r\n\\emph{Example:} The setup (left to right) at init is:\r\n$ S_{box} \\rightarrow  \\oplus \\rightarrow\r\n0 \\rightarrow 0 \\rightarrow \\textnormal{feedforward tap} \\rightarrow\r\n1 \\rightarrow \\textnormal{feedback tap} \\rightarrow 0 \\rightarrow\r\n\\textnormal{feedback tap} \\rightarrow \\oplus \\rightarrow S_{box}$.\r\n$f(D)= D^4(D^{-2} + 1)$,\r\n$g(D)= D^4(D^{-4}+ D^{-1} + 1)$, $s^0= D$, $x^0(D)= D^{-3}$,\r\n$y^0(D)= D^{-1}$ then\r\n$y(D)= {\\frac {D^{-1}+D+D^2+D^4} {1+D^3+D^4}} + D^{-1}$.\r\n$\\gamma_x(D)$ is the input selection polynomial;\r\n$\\gamma_x = q {\\frac {f^*} {(f^*, g^*)}}$,\r\n$\\gamma_y = q {\\frac {g^*} {(f^*, g^*)}}$.\r\n$\\gamma_y(D)$ is the output selection polynomial. $f^*(D)= f(D^{-1})$.\r\n$\\gamma_x^*= \\gamma_y^* {\\frac {f} {g}}$;\r\n$\\gamma_y= \\gamma_x {\\frac {g^*} {f^*}}$.  In example, \r\n$\\gamma_x(D)= 1 + D + D^2 + D^3$ and\r\n$\\gamma_y(D)= 1 + D^2 + D^4 + D^5$; $x_0 + x_1 + x_2 + x_3 = y_0 + y_2 + y_4 + y_5$.\r\nLet $d= (f_1^* f_2^*, g_1^*f_2^*, g_1^* g_2^*)$,\r\n$\\gamma_u= q {\\frac {f_1^* f_2^*} {d}} $,\r\n$\\gamma_v= q {\\frac {g_1^* f_2^*} {d}} $,\r\n$\\gamma_w= q {\\frac {g_1^* g_2^*} {d}} $, ${\\cal W} = w_h(\\gamma_u) + w_h(\\gamma_v)$.\r\n\\\\\r\n\\\\\r\n{\\bf KeyLoq:} $32$-bit NLFSR, $64$-bit rotating key,\r\n$NLF(a,b,c,d,e)= d+e+ac+ae+bc+be+cd+de+ade+ace+abd+abc$.  $(e+b+a+y) \\cdot (c+d+y)=0$.\r\nEquations are: \r\n$L_i= P_i, 0 \\le i \\le 31$,\r\n$L_i= k_{(i-32) \\jmod{64}} + L_{i-32} + L_{i-16} +\r\nNLF(L_{i-1}, L_{i-6}, L_{i-12}, L_{i-23}, L_{i-30}), 32 \\le i \\le 521$,\r\n$C_{i-528}= l_i, 528 \\le i \\le 559$. \r\nDegree reduction: $\\alpha \\leftarrow ab, \\beta \\leftarrow ae$.  Define\r\n$f^{(i)}(x)= f^{(i-1)}(f(x))$.\r\nKeyloq equation is $E_k(P)= g_k(f_k^{(8)}(P))= c$ where $f(x)$ is $64$ rounds.\r\nAssume $f(x)=x, f(y)= y$ then we know $64$ bits of input and output.  Guess $16$ bits\r\nof $g_k(x)$ key.  Solve for $64$ key bits plus $64$ intermediate values.  $.26$ of the keys\r\nhave two fixed points.\r\n\\\\\r\n\\\\\r\n{\\bf Disk Encryption with ESSIV(cbc):} \r\n$IV(\\textnormal{sector})= Enc_{\\textnormal{salt}}(\\textnormal{sector})$, $\\textnormal{salt}= H(K)$.\r\n\\\\\r\n\\\\\r\n{\\bf CBC Padding attack:}\r\n$b$ bytes in a block.  Number of values in a byte is $W$.\r\nPadding appends $n>0$ bytes.  For any block, $y$, want to compute\r\nlast byte of $C^{-1}(y)$, where $y$ is the block we're interested\r\nin decoding.\r\nConstruct fake two block message $r||y$, $r= r_1, r_2, \\ldots, r_b$,\r\nwith $r_i$, random.  If $r||y$ is valid, \r\n$C^{-1}(y) \\oplus r$ ends with a valid pad.\r\nSo last byte of $C^{-1}(y)= r_b \\oplus 1$, most likely.  \r\nNow replace $r_b$ with $r_b \\oplus 1$ and do next byte.\r\nAssume $a= a_1, a_2, \\ldots, a_b= C^{-1}(y)$.  Requires $O(NbW/2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Permutation generating functions:} Let \r\n$P(\\pi, c_1 , c_2)$ is the probability\r\nthat $\\pi$ has $c_1$ one cycles and $c_2$ cycles of length $2, 4, 8$ then\r\n$P(\\pi, c_1 , c_2)= {\\frac 1 {c_1! c_2!}} {\\frac 7 8}^{c_2} e^{-15/8}$.\r\n$EGF= {\\frac {z^{c_1}} {(1-z)c_1! c_2!}} [ {\\frac {z^2} {2}} +\r\n{\\frac {z^4} {4}} + {\\frac {z^8} {8}} ]^{c_2} exp(\\sum_{i \\mid 8} z^i/i)$.\r\n$\\pi \\in S_n, P(\\pi \\textnormal{ has } c_1 \\textnormal{ fixed points})= {\\frac 1 {e(c_1)!}} =\r\n{\\frac {e^{-15/8}} {c_1!}} e^{7/8}$.\r\nOGF: $C(z)= \\sum_i z^i$, EGF: $C_e(z)= \\sum_i {\\frac {c_i} {i!}} z^i$.\r\nIf ${\\cal P}$ is the permutatation population generating function,\r\n${\\cal P}(x)= z + 2 z^2 + 6 z^3 + \\ldots $ and\r\n${\\cal P}_e(x)= z + z^2 + z^3 + \\ldots $.  $1, 2, 3, 4$-selection generating function is\r\n$B(z)= 0 + z + z^2 + z^4$.  For cycles,\r\n${\\cal C}_e(x)= z + {\\frac {z^2}{2}} + {\\frac {z^3}{3}} + \\ldots = log({\\frac 1 {1-z}})$. \r\nProbability $\\pi \\in S_n$ does not have cycles of length $k$ is\r\n$e^{-{\\frac 1 k}}$.\r\n\\section{Zero Knowledge Protocols}\r\nSome preliminaries first.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $n=pq$, and we know $p, q$, where $p$ and $q$ are primes\r\nthen we can efficiently compute all four $x$: $y = x^2 \\jmod{n}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe can find $x_p, x_q$ such that $y= {x_p}^2 \\jmod{p}$ and\r\n$y= {x_q}^2 \\jmod{q}$ using Tonelli-Shanks.  Using the Chinese remainder theorem, we can compute $t$ such that\r\n$t = x_p \\jmod{p}$ and \r\n$t = x_q \\jmod{q}$.  Then $y-t^2 = 0 \\jmod{p}$\r\nand $y-t^2 = 0 \\jmod{q}$ so $y= t^2 \\jmod{n}$.\r\n\\end{quote}\r\n{\\bf Theorem:} Suppose $n=pq$, and we know $n$ and the fact that $p, q$ are primes.\r\nIf we know $n$, $y$  and all for $x: y= x^2 \\jmod{n}$ then we can find $p$ and $q$.\r\nthen we can efficiently compute all $x$; $y = x^2 \\jmod{n}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose the square roots of $y$ are $\\pm a$ and $\\pm b$. $y^2 = (ab)^2 \\jmod{n}$, so\r\n$(y-ab) (y+ab) \\mid n$.  We can find, say $p$ by computing $(y-ab, n)$.\r\n\\end{quote}\r\n{\\bf Coin flipping protocol:} Alice picks $p, q$ and computes $n= pq$.  Protocol is:\r\n\\begin{enumerate}\r\n\\item Alice $\\rightarrow$ Bob: $n$.\r\n\\item Bob calculates $y= x^2 \\jmod{n}$ using a random $x$. Bob $\\rightarrow$ Alice: $y$.\r\n\\item Alice calculates all four square roots, $\\pm a$, $\\pm b$.  She picks one, say $b$,\r\nand sends it to Bob.  Alice $\\rightarrow$ Bob: $b$.\r\n\\item Alice wins if $x = \\pm b$ and loses if $x \\ne \\pm b$.  Bob sends her a message telling her whether she won or\r\nlost.\r\n\\end{enumerate}\r\nAlice can check Bob isn't cheating because if $x = \\pm a$, Bob knows all four square roots $\\jmod{n}$ and can\r\ntell Alice $p, q$.\r\n\\\\\r\n\\\\\r\n{\\bf Zero knowledge secret proof:} Peggy knows a secret, $s$, and want to prove she know is to Victor without\r\nrevealing it.  Peggy finds a $p, q$ and computes $n=pq$ and $y= s^2 \\jmod{n}$ and checks that\r\n$(y, n) = 1$.  She chooses $r_1$ at random and\r\ncomputes $r_2 = s {r_1}^{-1} \\jmod{n}$  Note that $s = r_1 r_2 \\jmod{n}$.  Finally, Alice computes\r\n$x_1 = (r_1)^2 \\jmod{n}$ and $x_2 = (r_2)^2 \\jmod{n}$.  Protocol is:\r\n\\begin{enumerate}\r\n\\item Peggy $\\rightarrow$ Victor: $n, y, x_1, x_2$.\r\n\\item Victor checks that $y= (x_1 x_2)^2 \\jmod{n}$, and choses one, say $x_1$. Victor $\\rightarrow$ Peggy: $x_1$.\r\n\\item Peggy $\\rightarrow$ Victor: $r_1$.\r\n\\item Victor confirms that  $(r_1)^2 = x_1 \\jmod{m}$.\r\n\\end{enumerate}\r\nWithout knowing $s$, Peggy succeeds with probability ${\\frac 1 2}$ but always succeeds if she knows $s$.  Repeating this\r\n$m$ times, Victor knows that Peggy knows $s$ with probability $1-({\\frac 1 2})^2$.\r\n\\\\\r\n\\\\\r\n{\\bf More efficient proof of secret knowledge protocol (FFS):} \r\nAgain, Peggy finds a $p, q$ and computes $n=pq$.  There are $k$ secrets $s_1, s_2, \\ldots s_k$. Peggy picks $r$ at\r\nrandom and computes $x = r^2 \\jmod{n}$.  She also computes $v_i = s_i^2 \\jmod{n}$ for $i=1,2, \\ldots, k$.\r\n\\begin{enumerate}\r\n\\item Peggy $\\rightarrow$ Victor: $n, x, v_1, v_2 , \\ldots, v_k$.\r\n\\item Victor picks $k$ values $b_i \\in \\{0, 1\\}$.  Victor $\\rightarrow$ Peggy: $b_1, b_2, \\ldots, b_k$.\r\n\\item Peggy computes $y = r s_1^{b_1} s_2^{b_2} \\ldots s_k^{b_k} \\jmod{n}$.\r\n\\item Victor checks that $x = y^2 v_1^{b_1} v_2^{b_2} \\ldots v_k^{b_k} \\jmod{n}$.\r\n\\end{enumerate}\r\nAs before, repeat this as often as you like.\r\n\\\\\r\n\\\\\r\n{\\bf Secret splitting:} Suppose we want to share a secret, $s$, among $n$ people, so that and $t$ of them could assemble\r\nthe secret. Pick $p >s$ and choose $s_1, s_2, \\ldots, s_{t-1}$ at random $0 \\leq s_i < p$.  Put $s_0 = s$ and form\r\n$f(x)= s_0 + s_1x + \\ldots + s_{t-1}x^{t-1}$. Now chose $x_1, x_2, \\ldots, x_{n}$ at random $0 \\leq x_i < p$ and put\r\n$y_i = f(x_i ) \\jmod{p}$.  Give $(x_i , y_i )$ to participant $i$.  Any $t$ participants can find $s=s_0$.\r\n", "meta": {"hexsha": "39153db2729fdac996e072da0141b27ec4110bd6", "size": 230855, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/crypto.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/crypto.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/crypto.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.9556359482, "max_line_length": 137, "alphanum_fraction": 0.5708648286, "num_tokens": 98035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.691582741841298}}
{"text": "% !TEX root = Main.tex\n\\section{Non-Negative Matrix Factorization}\n\\subsection*{pLSA}\n\\textbullet co-occurence matrix $X=x_{ij}$ \\#occurences of word $w_j$ in doc $d_i$. \n\\textbullet $p(w|d) = \\sum_z p(w,z|d) = \\sum_z p(w|d,z)p(z|d) = \\sum_z p(w|z)p(z|d)$.\\\\\n\\textbullet log-likelihood: $\\sum_{i,j} x_{i,j}\\log p(w_j|d_i)$ \\\\\nE-Step (optimal q):\\\\\n$q_{zij} = p(z|w_j,d_i)=\\frac{p(w_j|z)p(z|d_i)}{\\sum_{k=1}^K p(w_j|k)p(k|d_i)}$ \\\\\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*{NMF Algorithm for quadratic cost function}\n$\\mathbf{X} \\in \\mathbb{Z}^{N \\times M}_{\\geq 0}$, NMF: $\\mathbf{X} \\approx \\mathbf{U^\\top V}, x_{ij}$\n\n$\\min_{\\mathbf{U}, \\mathbf{V}} J(\\mathbf{U}, \\mathbf{V}) = \\frac{1}{2} \\|\\mathbf{X} - \\mathbf{U}^\\top\\mathbf{V}\\|_F^2 = \\\\ \n\\frac{1}{2}\\sum(x_{ij}-u_i^\\top v_j)^2$\\\\\ns.t. $\\forall i,j,z:u_{zi},v_{zj} \\geq 0 $\n\n\n1. init: $\\mathbf{U}, \\mathbf{V} = rand()$ 2. repeat for $\\mathit{maxIters}$:\\\\\n3. upd. $(\\mathbf{VV}^\\top)\\mathbf{U} = \\mathbf{VX}^\\top$, proj. $u_{zi} = \\max \\{ 0, u_{zi} \\}$\\\\\n4. upd. $(\\mathbf{UU}^\\top)\\mathbf{V} = \\mathbf{UX}$, proj. $v_{zj} = \\max \\{ 0, v_{zj} \\}$ \\\\\n\\textbullet vector form: \\\\ \n$(\\sum_i u_iu_i^\\top)v_j=\\sum_i x_{ij}u_i$, $(\\sum_j v_jv_j^\\top)u_i=\\sum_j x_{ij}v_j$ \\\\\nnote for derivation: If want matrix form, use trace def. If want vector only form, use sum representation of objective.\n", "meta": {"hexsha": "113f617d6ada5f5b844124d57d5467ba3a70d639", "size": 1450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NMF.tex", "max_stars_repo_name": "florianmorath/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T15:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T15:10:37.000Z", "max_issues_repo_path": "NMF.tex", "max_issues_repo_name": "florianmorath/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NMF.tex", "max_forks_repo_name": "florianmorath/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.7692307692, "max_line_length": 123, "alphanum_fraction": 0.6048275862, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6915827383863153}}
{"text": "\\subsubsection{Implicit Mass Transfer}\n\nOn its inner boundary, the Lumped Parameter model uses the fixed concentration\nDirichlet boundary condition directly in its solution such that,\n\\begin{align}\nC_{k,in}(t_n) &= C(z, t_n)|_{z=r_j}.\n\\end{align}\n\nThe resulting mass transfer into the external component $k$ containing the Lumped\nParameter model is calculated by taking the integral of that concentration\nprofile over the volume,\n\n\\begin{align}\nm_{jk}(t_n) &=\\int C(z,t_n)dV_k - \\int C(z, t_{n-1})dV_k.\n\\end{align}\n\n\nIn the similar case of the One Dimensional Permeable Porous Medium Model,\nthe Dirichlet boundary condition at the boundary is also used directly in\nthe solution as $C_0$ such that,\n\n\\begin{align}\n  C_{k,0}(t_n) &= C(z, t_n)|_{z=r_j}.\n\\end{align}\n\nThe mass transfer on the inner boundary is again calculated by taking an\nintegral of that profile over the volume,\n\n\\begin{align}\nm_{jk}(t_n) &=\\int C(z,t_n)dV_k - \\int C(z, t_{n-1})dV_k.\n\\end{align}\n", "meta": {"hexsha": "d1ff666ce1e2d7f6c8761576d86e04514619de17", "size": 964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nuclide_models/mass_transfer/implicit.tex", "max_stars_repo_name": "katyhuff/2017-huff-rapid", "max_stars_repo_head_hexsha": "cfb06a9a2e744914e7f3d088014db7a71a68c39d", "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": "nuclide_models/mass_transfer/implicit.tex", "max_issues_repo_name": "katyhuff/2017-huff-rapid", "max_issues_repo_head_hexsha": "cfb06a9a2e744914e7f3d088014db7a71a68c39d", "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": "nuclide_models/mass_transfer/implicit.tex", "max_forks_repo_name": "katyhuff/2017-huff-rapid", "max_forks_repo_head_hexsha": "cfb06a9a2e744914e7f3d088014db7a71a68c39d", "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.125, "max_line_length": 81, "alphanum_fraction": 0.744813278, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6914964909028225}}
{"text": "\\chapter{Linear Regression}\n\\label{ch:linear-regression}\n\nFor a start,\\marginnote{In the \\widget{Paint Data} widget, remove the C2 label from the list. If you have accidentally left it while painting, don't despair. The class variable will appear in the \\widget{Select Columns} widget, but you can \"remove\" it by dragging it into the Available Variables list.} let us construct a very simple data set. It will contain just one continuous input feature (let's call it x) and a continuous class (let's call it y). We will use Paint Data, and then reassign one of the features to be a class using \\widget{Select Columns} and moving the feature y from \"Features\" to \"Target Variable\". It is always good to check the results, so we are including \\widget{Data Table} and \\widget{Scatter Plot} in the workflow at this stage. We will be modest this time and only paint 10 points and will use Put instead of the Brush tool.\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[width=\\linewidth]{lin-reg-workflow1.png}\n    \\caption{$\\;$}\n\\end{marginfigure}\n\nWe would like to build a model that predicts the value of target variable y from the feature x. Say that we would like our model to be linear, to mathematically express it as $h(x)=\\theta0+\\theta1x$. Oh, this is the equation of a line. So we would like to draw a line through our data points. The $\\theta$0 is then an intercept and $\\theta$1 is a slope. But there are many different lines we could draw. Which one is the best one? Which one is the one that fits our data the most? Are they the same?\n\n\\begin{figure*}[h]\n    \\centering\n    \\newcommand{\\paint}{\\includegraphics[scale=0.45]{paint-data.png}}\n    \\newcommand{\\selcol}{\\includegraphics[scale=0.45]{select-columns.png}}\n    \\infinitewidthbox{\n    \\stackinset{r}{-0.35\\linewidth}{t}{+0.1\\linewidth}{\\selcol}{\\paint}\\hspace{6cm}\n    }\n\\end{figure*}\n\nThe question above requires us to define what a good fit is. Say, this could be the error the fitted model (the line) makes when it predicts the value of y for a given data point (value of x). The prediction is h(x), so the error is $h(x) - y$. We should treat the negative and positive errors equally, plus, let us agree, we would prefer punishing larger errors more severely than smaller ones. Therefore, we should square the errors for each data \\marginnote{Do not worry about the strange name of the \\widget{Polynomial Regression}, we will get there in a moment.} point and sum them up. We got our objective function! Turns out that there is only one line that minimizes this function. The procedure that finds it is called linear regression. For cases where we have only one input feature, Orange has a special widget in the Educational add-on called \\widget{Polynomial Regression}.\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[width=\\linewidth]{lin-reg-workflow2.png}\n    \\caption{$\\;$}\n\\end{marginfigure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{pol-regression-first.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nLooks ok. Except that these data points do not appear exactly on the line. We could say that the linear model is perhaps too simple for our data set. Here is a trick: besides the column x, the widget Polynomial Regression can add columns x2, x3… xn to our data set. The number n is a degree of polynomial expansion the widget performs. Try setting this number to higher values, say to 2, and then 3, and then, say, to 8. With the degree of 3, we are then fitting the data to a linear function $h(x) = \\theta0 + \\theta1x + \\theta1x2 + \\theta1x3$.\n\n\\newpage\n\nThe trick we have just performed (adding higher order features to the data table and then performing linear regression) is called polynomial regression. Hence the name of the widget. We get something reasonable with polynomials of degree 2 or 3, but then the results get really wild. With higher degree polynomials, we totally overfit our data.\n\n\\begin{figure*}[h!]\n    \\centering\n    \\newcommand{\\second}{\\includegraphics[scale=0.35]{pol-regression-second.png}}\n    \\newcommand{\\eigth}{\\includegraphics[scale=0.35]{pol-regression-eigth.png}}\n    \\infinitewidthbox{\n    \\stackinset{r}{-0.35\\linewidth}{t}{+0.2\\linewidth}{\\eigth}{\\second}\\hspace{6cm}\n    }\n\\end{figure*}\n\n\\marginnote{It is quite surprising to see that linear regression model can result in fitting non-linear (univariate) functions. That is, the functions with curves, such as those on the figures. How is this possible? Notice though that the model is actually a hyperplane (a flat surface) in the space of many features (columns) that are the powers of x. So for the degree 2, $h(x)=\\theta0+\\theta1x+\\theta1x2$ is a (flat) hyperplane. The visualization gets curvy only once we plot $h(x)$ as a function of x.}\n\nOverfitting is related to the complexity of the model. In polynomial regression, the models are defined through parameters $\\theta$. The more parameters, the more complex the model. Obviously, the simplest model has just one parameter (an intercept), ordinary linear regression has two (an intercept and a slope), and polynomial regression models have as many parameters as is the degree of the polynomial. It is easier to overfit with a more complex model, as this can adjust to the data better. But is the overfitted model really discovering the true data patterns? Which of the two models depicted in the figures above would you trust more?\n", "meta": {"hexsha": "63ef16b9effa1c522a6869af75bc3d882ff4a2f7", "size": 5398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/040-linear-regression/linear-regression.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/040-linear-regression/linear-regression.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/040-linear-regression/linear-regression.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": 98.1454545455, "max_line_length": 887, "alphanum_fraction": 0.7593553168, "num_tokens": 1349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8991213874066956, "lm_q1q2_score": 0.6914964802644215}}
{"text": "% !TeX root = ./main.tex\n% chktex-file 46\n% !TeX spellcheck = en-GB\n% !TeX encoding = utf8\n\n\\subsection{Graphs and graph convolutions}\n\nGraphs are sets of nodes connected by edges, as shown in Fig.~\\ref{fig:graph_example}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.4\\columnwidth]{img/graph_example.pdf}\n\t\\caption{Example graph where nodes are individuals and edges are their contacts at time step $t$.}%\n\t\\label{fig:graph_example}\n\\end{figure}\n\nWe model partially infected populations as a graph, where each individual (interchangeably called agent) is a node. Edges of this graph model contacts between two agents. The dynamics of infections throughout the population is described by graph convolutions. The 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 $h_{v_i}^{(l)}$ denoting the feature vector of node $i$ of iteration $(l)$ and $A(i)$ as all neighbours of node $i$ as described by the adjacency matrix $A$. This formulation is equivalent to the matrix formulation $h^{(l+1)} = A h^{(l)}$ with $A$ as adjacency matrix as shown in~\\ref{sec:consistency}. We consider here adjacency matrices without diagonal elements.\n\nEach 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 in this work, $D=3$, modeling three possible health states. The unit vectors of this space are interpreted as following:\n\\begin{itemize}\n\t\\item $\\vec{e}_0$: susceptible state\n\t\\item $\\vec{e}_1$: infected state\n\t\\item $\\vec{e}_2$: recovered state\n\\end{itemize}\nA uniform distribution over these possible states expresses complete uncertainty of the health state of an agent.\n\n\\subsection{SIR Model}\nOur basic stochastic SIR model relies on the assumptions that every person in an environment can be modeled as a point value on a grid, which has a location (i.e.\\ GPS coordinates) and an infection state. These states can be either \\textit{susceptible} (S), \\textit{infected} (I), \\textit{recovered} (R) or in advanced models also \\textit{under quarantine} (Q) or \\textit{dead} (D). All individuals, here called agents, have a probability (here called diffusion rate $d$) to make a step on the grid per time step on a predefined grid. The movement is a random walk pattern. In the case that some agents meet at the same location, disease spreading can occur. An infected agent spreads the disease with the probability $\\beta$ to all the agents in its close vicinity (same location on the grid). Furthermore, recovery is covered by taking a recovery rate into account, i.e.\\ a probability $\\gamma$ to recover from the disease per time step. If an infected agent recovers from the disease, the state of the agent changes from \\textit{infected} to \\textit{recovered}, which is definite (no double infections). The process ends, when no infected agents are left. For more background the reader is referred to~\\cite{weiss2013sir} and~\\cite{epstein2009modelling}.\n\n", "meta": {"hexsha": "923032035963a729f3bac4640bf8b27200f9618b", "size": 3276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sections/basics.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/sections/basics.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/sections/basics.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": 88.5405405405, "max_line_length": 1257, "alphanum_fraction": 0.7603785104, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6914389865568707}}
{"text": "\\subsection{Hilbert spaces}\\label{subsec:hilbert_spaces}\n\n\\begin{definition}\\label{def:hilbert_space}\n  A \\term{Hilbert space} is an \\hyperref[def:inner_product_space]{inner product space} which is also a \\hyperref[def:complete_metric_space]{complete metric space} with the metric induced by the inner product.\n\\end{definition}\n\n\\begin{definition}\\label{def:orthonormal_system}\n  A set of vectors \\( A \\) in a Hilbert space \\( X \\) is called an \\term{orthonormal system} if \\( A \\)\n  \\begin{equation*}\n    \\inprod x y \\coloneqq \\begin{cases}\n      1, & x = y,    \\\\\n      0, & x \\neq y.\n    \\end{cases}\n  \\end{equation*}\n\n  It is a special case of an \\hyperref[def:orthogonality]{orthogonal system}. We are usually interested in \\term{orthogonal bases}.\n\\end{definition}\n", "meta": {"hexsha": "087e8049a87c9e7c66cd26afbc8ad69c40a4d042", "size": 771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/hilbert_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/hilbert_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/hilbert_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": 42.8333333333, "max_line_length": 208, "alphanum_fraction": 0.7172503243, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.691438981143721}}
{"text": "\\documentclass[en,12pt]{elegantpaper}\n\n\\begin{document}\n    \\section*{6}\n    \\noindent  For Poisson distribution, \n    \\[\n        f(x=k|\\lambda)=\\frac{\\lambda^k}{k!}e^{-\\lambda}=1/k!\\exp\\left(k\\log\\lambda-\\lambda\\right), \n    \\]\n    \\[\n        f(X=K|\\lambda)=1\\Big/\\prod k_i!\\exp\\left(\\log\\lambda\\sum_{i=1}^n(k_i)-n\\lambda\\right). \n    \\]\n    So, \\(T(X)=\\sum_{i=1}^{n} X_{i}\\) is sufficient and complete for \\(\\lambda\\). Let $\\log\\lambda=\\theta$, \n    \\[\n        \\mathbb{E}(T)=\\left(ne^\\theta\\right)'=n\\lambda. \n    \\]\n    Hence, UMVU for $\\lambda$ is $T/n$. Let $h(t)$ be UMVU for $\\lambda^r$, then\n    \\[\n        \\mathbb{E}(h(T))=\\sum_{i=0}^\\infty\\frac{h(i)n^i}{i!}\\lambda^i=e^{n\\lambda}\\lambda^r=\\sum_{i=0}^\\infty\\frac{(n\\lambda)^i}{i!}\\lambda^r. \n    \\]\n    Then, compare the coefficients for both sides, when $t<r$, \n    \\[\n        h(t)=0. \n    \\]\n    But when $t\\geqslant r$, \n    \\[\n        h(t)=\\frac{t!}{n^r(t-r)!}. \n    \\]\n\\end{document}", "meta": {"hexsha": "0f9a3fe190aebaa5612c902c0fbf43b875cea282", "size": 947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/midterm1/6.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/6.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/6.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": 33.8214285714, "max_line_length": 143, "alphanum_fraction": 0.535374868, "num_tokens": 379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.6914389711617066}}
{"text": "\\documentclass[12pt, letterpaper]{article}\n\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{anysize}\n\n\\marginsize{.5in}{.5in}{.5in}{.5in}\n\n% I found that pdflatex, my favorite weapon-of-choice, was goofing my \n% margins.  This will fix it:\n% Force pdflatex to use correct paper size.\n\\special{papersize=8.5in,11in}\n\\setlength{\\pdfpageheight}{\\paperheight}\n\\setlength{\\pdfpagewidth}{\\paperwidth}\n\n\\begin{document}\n\n\\noindent\n{\\LARGE \\textbf{The Crank-Nicholson Scheme}}\n\nEarlier versions of our heat equation code used an explicit scheme, i.e. one\nwhere  $U(t+\\Delta t, x)$ is only a function of $U(t, x\\pm\\Delta x)$.  This\ngave us a somewhat reliable scheme but easily became unstable if our selection\nof $\\Delta t$ and $\\Delta x$ was poor.  \\emph{Implicit schemes} are ones where\n$U(t+\\Delta t, x)$ is a function of $U(t, x\\pm\\Delta x)$ \\emph{and} a function\nof $U(t+\\Delta t, x\\pm\\Delta x)$, i.e. we need to know information about the\nfuture state to get to the future state.  This sounds self-contradictory, but\nit is both possible and yields a scheme that is unconditionally stable.\nLet's start with our heat equation:\n\n\\begin{equation}\n  \\label{heat}\n  \\frac{\\partial U}{\\partial t} = c^{2} \\nabla U\n\\end{equation}\n\n\\noindent\nAgain, note that in my examples, the diffusion coefficient is defined as\n$c^{2}$, in other places it is simply $c$.\n\nPreviously, we discretized this equation by using the forward difference\napproximation for the time derivative and a central difference approximation\nfor the spatial second derivative. This gave us one term that was a function\nof $t+\\Delta t$; it was trivial to solve for this term.  However, something\ninteresting happens when we use central difference approximations to yield\nthe time and space derivative not at time $t$ but at time \n$t+\\frac{\\Delta t}{2}$:\n\n\\begin{equation}\n  \\label{disct}\n  \\frac{\\partial U(x,t+\\frac{\\Delta t}{2})}{\\partial t} = \n  \\frac{U(x, t+\\Delta t) - U(x, t)}{\\Delta t} + \\mathcal{O}(\\Delta t^{2})\n\\end{equation}\n\n\\noindent\nFor the space discretization at $t+\\frac{\\Delta t}{2}$, we'll average the\ncentral difference approximation for $U(x,t+\\Delta t)$ and \n$U(x,t)$:\n\n\\begin{align}\n  \\label{discx}\n  \\frac{\\partial^{2} U(x,t+\\frac{\\Delta t}{2})}{\\partial x^{2}} = \n  \\frac{1}{2\\Delta x}\\\\\n  \\nonumber & \\left(U(x-\\Delta x,t+\\Delta t) - \n  2U(x,t+\\Delta t) + U(x+\\Delta x,t+\\Delta t) + \\right.\\\\\n  \\nonumber & \\left. U(x-\\Delta x,t) - \n  2U(x,t) + U(x+\\Delta x,t)\\right) \\\\\n  \\nonumber & + \\mathcal{O}(\\Delta x^{2})\n\\end{align}\n\n\\noindent\nSubstituting Equation \\ref{disct} and \\ref{discx} into Equation \\ref{heat}\nyields\n\n\\begin{equation}\n  \\label{heat_disc}\n  \\frac{U_{i,j+1}-U_{i,j}}{k} = c^{2}\\frac{U_{i-1,j+1}-2U_{i,j+1}+U_{i+1,j+1}+\n    U_{i-1,j}-2U_{i,j}+U_{i+1,j}}{2h^{2}}\n\\end{equation}\n\n\\noindent\n...where the following definitions were made:\n\n\\begin{equation}\n  \\label{subs}\n  \\begin{array}{c}\n  k=\\Delta t \\\\\n  h=\\Delta x \\\\\n  U_{i+n, j+m} = U(x+n\\Delta x, t+m\\Delta t)\n  \\end{array}\n\\end{equation}\n\nWe have a mix of forward terms ($j+1$) and current terms ($j$).  Let's first\nmake the following definition:\n\n\\begin{equation}\n  \\label{r}\n  r \\equiv \\frac{c^{2}k}{h^{2}}\n\\end{equation}\n\n\\noindent\n...and now place all of the forward terms on the left and the current terms\non the right:\n\n\\begin{equation}\n  \\label{cn}\n  -rU_{i-1,j+1} + (2+2r)U_{i,j+1} - rU_{i+1,j+1} = \n  rU_{i-1,j} + (2-2r)U_{i,j} +rU{i+1,j}\n\\end{equation}\n\n\\noindent\nThis is the \\textbf{Crank-Nicholson} method for solving the diffusion equation.\nIt is implicit and unconditionally stable.\n\nIn the domain $x=[x_{0}:x_{0}+n\\Delta x]$ (or, rather more simply, $i=[1:n]$),\nwhen we have enforced boundary conditions at $i=1$ and $i=n$, \\emph{we have\n$n$ equations and $n$ unknowns}.  Any $j+1$ term that is not on the boundary\nis an unknown.  Casting this into matrix notation makes the situation far\nmore clear:\n\n\\begin{equation}\n  \\label{matrix}\n  \\begin{array}{c}\n  \\begin{bmatrix}\n    2+2r & -r   & & & & &\\\\\n    -r   & 2+2r & -r & & &\\mathbf{0} &\\\\\n         &   -r & 2+2r & -r & & &\\\\\n         & & & \\ddots & & &\\\\     \n     & \\mathbf{0}& & & -r   & 2+2r & -r \\\\\n     & & & & &   -r & 2+2r\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    U_{1,j+1} \\\\ U_{2,j+1}\\\\U_{3,j+1}\\\\ \\vdots \\\\U_{n-1,j+1} \\\\ U_{n,j+1}\n  \\end{bmatrix}\n  =\\\\\n  \\\\\n  \\begin{bmatrix}\n    2-2r & r   & & & & &\\\\\n    r   & 2-2r & r & & &\\mathbf{0} &\\\\\n    &   r & 2-2r & r & & &\\\\\n    & & & \\ddots & & &\\\\     \n    & \\mathbf{0}& & & r   & 2-2r & r \\\\\n    & & & & &   r & 2-2r\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    U_{1,j} \\\\ U_{2,j}\\\\U_{3,j}\\\\ \\vdots \\\\U_{n-1,j} \\\\ U_{n,j}\n  \\end{bmatrix}\n  \\end{array}\n\\end{equation}\n\nThe $\\mathbf{A}\\overline{U_{j+1}} = \\mathbf{B}\\overline{U_{j}}$ form of Equation \n\\ref{matrix} makes the final task clear.  Matrices $\\mathbf{A}$ and $\\mathbf{B}$\nmust be constructed appropriately.  Then, the only unknown at any given \niteration is vector $\\overline{U_{j+1}}$.  We simply solve for it: \n$\\overline{U_{j+1}} =\\mathbf{A}^{-1}\\mathbf{B}\\overline{U_{j}}$, where \n$\\mathbf{A}^{-1}$ is the inverse of $\\mathbf{A}$.\n  Note that the matrices are sparse and \\textbf{tri-diagonal}.  They only have\nnon-zero elements along $i=j$, $i-1=j$, and $i+1=j$ diagonals.\n\n%\\section{Implementation in FORTRAN}\n%%%%%%%%%%%%%%\n\\end{document}\n", "meta": {"hexsha": "3d76745a5aaf6d19fe081acb0436e5164799e59f", "size": 5278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Fortran90/CrankNicholson.tex", "max_stars_repo_name": "spacecataz/sciprog_teaching", "max_stars_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran90/CrankNicholson.tex", "max_issues_repo_name": "spacecataz/sciprog_teaching", "max_issues_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/CrankNicholson.tex", "max_forks_repo_name": "spacecataz/sciprog_teaching", "max_forks_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T02:31:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T02:31:54.000Z", "avg_line_length": 32.5802469136, "max_line_length": 81, "alphanum_fraction": 0.6398256915, "num_tokens": 1923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190226, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6913107693325228}}
{"text": "\\chapter{Project Description}\n\n\\section{Basics}\n\n\n%Can put  this into the introduction\nWe use the following notation:\n\\begin{itemize}\n\\item Matrices are written in uppercase bold e.g. $\\mathbf{X}$.\n\\item Vectors are written in lowercase bold e..g $\\mathbf{x}$.\n\\item scalars are written in lowercase or uppercase. Lowercase indicates that it is a counting variable and uppercase that it is one of the limits in an finite set.\n\\item For all functions , e.g. $f(x)$, where $x = \\mathbf{X}$ , we apply the function element wise.\n\\item Dot product is indicated by simple concatenation of two matrices/vectors e.g. $\\mathbf{X} \\mathbf{y}$.\n\\item Element wise multiplication is indicated as $\\mathbf{X} \\otimes \\mathbf{Z}$.\n\\end{itemize}\n\nNeural networks are a statistical model for regression or classification. Even though naturally they do not produce any classification output, we can model the regressed output to be used as a classifier. \n\nOverall we have two different modes: Training and evaluation. In the training phase we use the back propagation algorithm to train the network and adjust it so that it produces output, which is close to our target output.\n\nFurthermore a neural network contains $L$ hidden layers, which are called hidden since their output is not directly observable.\n\nThe weights are in our simple case randomly initialized and then updated using the back propagation rule.\n\nA basic neural network has therefore the following parameters:\n\\begin{itemize}\n\\item The weights from an neuron $k$ in layer $a$ to a neuron $j$ in layer $b$\n\\item The input to the network, usually a vector $\\mathbf{x}$ with $k$ values\n\\item The target which should be estimated, usually a vector $\\mathbf{t}$ with $q$ values.\n\\item The learning rate $\\eta$, which is the indicator how fast the network learns.\n\\end{itemize}\n\nMoreover we can add some advanced techniques as the momentum to speed up the training the momentum \n\n\n\\subsection{Gradient Descent}\nGradient descent is a first-order optimization algorithm. To find a local minimum of a function using gradient descent, it takes steps proportional to the negative of the gradient (or of the approximate gradient) of the function at the current point. If instead one takes steps proportional to the positive of the gradient, one approaches a local maximum of that function; the procedure is then known as gradient ascent \\cite{Kiwiel2001,Qian1999}.\n\nGradient descent is based on the observation that if the multivariable function $F(\\mathbf{x})$ is defined and differentiable in a neighborhood of a point $\\mathbf{a}$, then $F(\\mathbf{x})$ decreases fastest if one goes from $\\mathbf{a}$ in the direction of the negative gradient of F at $\\mathbf{a}, -\\nabla F(\\mathbf{a})$ \\cite{Yuan1999}. It follows that, if\n\\begin{equation}\n\\mathbf{b} = \\mathbf{a}-\\gamma\\nabla F(\\mathbf{a})\n\\end{equation}\nfor $\\gamma$ small enough, then $F(\\mathbf{a})\\geq F(\\mathbf{b})$. With this observation in mind, one starts with a guess $\\mathbf{x}_0$ for a local minimum of F, and considers the sequence $\\mathbf{x}_0, \\mathbf{x}_1, \\mathbf{x}_2, \\dots$ such that\n\\begin{equation}\n\\mathbf{x}_{n+1}=\\mathbf{x}_n-\\gamma_n \\nabla F(\\mathbf{x}_n),\\ n \\ge 0.\n\\end{equation}\n\nFinally we have \\cite{Cauchy1847}:\n\\begin{equation}\nF(\\mathbf{x}_0)\\ge F(\\mathbf{x}_1)\\ge F(\\mathbf{x}_2)\\ge \\cdots,\n\\end{equation}\n\n\n\\subsection{Minibatch Stochastic Gradient Descent}\n\nBoth statistical estimation and machine learning consider the problem of minimizing an objective function that has the form of a sum:\n\\begin{equation}\nQ(w) = \\sum_{i=1}^n Q_i(w)\n\\end{equation}\n\nwhere the parameter $w^*$ which minimizes Q(w) is to be estimated. Each summand function $Q_i$ is typically associated with the $i$-th observation in the data set (used for training).\n\nWhen used to minimize the above function, a standard (or \"batch\") gradient descent method would perform the following iterations :\n\\begin{equation}\nw := w - \\eta \\nabla Q(w) = w - \\alpha \\sum_{i=1}^n \\nabla Q_i(w)\n\\end{equation}\nwhere $\\eta$ is the learning rate.\n\nBut since in many cases, the update of one gradient would take to estimate the gradient over the whole dataset, the computation would take too much time. Often times we only need a rough estimate of the gradient, not a precise one.\n\nWhat stochastic gradient descent does is to remove the sum and only uses one sample to estimate the gradient. \n\\begin{equation}\nw := w - \\eta \\nabla Q(w) = w - \\alpha \\nabla Q(w)\n\\end{equation}\nIn practice this turns out to be less effective than batch gradient descent, since we only get a very rough estimate of the gradient.\nTherefore the minibatch gradient descent technique is used. The difference here is that while batch gradient descent uses $n$ samples and stochastic gradient descent uses only $1$, minibatch gradient uses $b$ training samples, where $b << n$. Typical sizes for $b$ are in the range if $b \\in {2,\\ldots,100}$.\n\nTherefore in minibatch stochastic Gradient descent we randomly subset the training set and only take some samples out of it and estimate the gradient out of the seen sample set.\n\nThe important thing to do is to randomize the training set, since otherwise only a small portion of the training set will be seen and leads to wrong gradients.\n\n\\subsection{The Forward Backward procedure in detail}\n\nTo train the network we use the standard back-propagation algorithm, which essentially does a forward and a backward pass of the network in a row.\nFirstly we initialize the weights in a matrix. \n\\begin{align}\n\\mathbf{W}_{j \\times k } = \\begin{bmatrix}\nw_{11} & w_{12} & \\ldots & w_{1k}\\\\\nw_{21} & \\ddots & & \\vdots\\\\\n\\vdots & & \\ddots  & \\vdots\\\\\nw_{j1} & \\ldots & \\ldots  & w_{jk}\\\\\n\\end{bmatrix},\n\\mathbf{x}_{1 \\times k} = \\begin{bmatrix}\na_{1} \\\\\n\\vdots\\\\\n\\vdots \\\\\na_{k}\n\\end{bmatrix}\n\\end{align}\n\n\n\\paragraph{Forward propagation} is one of the two passes the network needs to do ( hence it's name ).\nIn forward propagation the network calculates the predicted output of the network.\n\nThe output of the hidden layer $j$ of the network can be calculated as the weighted sum of the inputs\n\\begin{align}\n\\mathbf{nnet}_j = \\sum_{k=1}^{n}w_{kj}x_k = \\mathbf{W} \\mathbf{x}\n\\end{align}\n\nEven though this method should already work, we add a bias to every node to increase the learning speed and void that the network stops learning.\n\n\\begin{align}\n\\mathbf{nnet}_j = \\sum_{k=1}^{n}w_{kj}x_k + b_k = \\mathbf{W} \\mathbf{x} + \\mathbf{b}\n\\end{align}r\n\n\nLater we see that back-propagation needs some variables, which can be already precomputed during the forward step. These two variables are the output $\\mathbf{o}_j$ of layer $j$ and the derivative of the output w.r.t to the weighted sum $\\mathbf{nnet}_j$. We represent the derivatives in a matrix $\\mathbf{D}$ and the output of the current layer \n\\begin{align}\n\\mathbf{D}_j = \\frac{\\mathbf{o}_j}{\\mathbf{nnet}_j}\n\\end{align}\nIn case of sigmoid activation function, we obtain:\n\\begin{align}\n\\mathbf{D}_j = \\varphi \\left( \\mathbf{nnet}_j \\right) \\left( 1 - \\varphi \\left(\\mathbf{nnet}_j \\right) \\right)\n\\end{align}\nFor the outputs, we simply feed forward the network and store the output $\\mathbf{o}_j$ in out buffered lists.\n\\begin{align}\n\\mathbf{o}_j = \\varphi \\left( \\mathbf{Wx+b} \\right)\n\\end{align}\n\nAs soon as the feed forward is done, we produced an output of the network, which we can denote as $\\mathbf{o}_L$. Now we need to decide how close our output is to the targeted output $\\mathbf{t}$. For this we use a cost function in usual cases it is sufficient to use $MSE$ as such, which is defined as:\n\\begin{equation}\n\\label{eq:mse}\n\\mathbf{MSE} = \\frac{1}{2} \\left( \\mathbf{o}_L - \\mathbf{t} \\right) ^2\n\\end{equation}\n\nHere (\\ref{eq:mse}) we need to make sure that the last output layer has the same dimensions as the target output.\n\n\n\\paragraph{Backpropagation} starts when all layers are trained. The idea behind back propagation is that the hidden layers do not produce any output. So we cannot modify their weights directly, since we don’t know how large the error was. With back propagation we calculate the error at the output layer $L$ and then propagate this error to the hidden layers back. Therefore we update all $L-1$ weight matrices and biases.\n\nAt first we calculate the differences between the target output and the estimated output.\n\n\\begin{align}\n\\boldsymbol{err} = \\mathbf{o}_L - y\\\\\n\\boldsymbol{\\delta}_L &= \\mathbf{err} \\otimes \\mathbf{D}_L\\\\\n\\nabla \\mathbf{W}_L &= \\mathbf{o}_L \\boldsymbol{\\delta}_L^T\n\\end{align}\n\nWe store both, the deltas and the nablas to later update the weights ( with the $\\nabla$s) and the biases (using the $\\mathbf{\\delta}$).\nFrom here on we then calculate the other layers backwards, we do:\n\\begin{align}\n\\boldsymbol{\\delta}_i &= \\mathbf{D}_i \\otimes \\left( \\mathbf{W}_{i+1}^T \\boldsymbol{\\delta}_{i+1} \\right)\\\\\n\\nabla \\mathbf{W}_i &= \\mathbf{o}_i \\boldsymbol{\\delta}_i^T\n\\end{align}\nWhereas we again store the deltas and the nablas to later update the weights.\n\nTo update the weights, we use the usual gradient descent update rule:\n\\begin{align}\n\\mathbf{W}^{*} = \\mathbf{W} - \\alpha \\nabla \\mathbf{W}_i^T\\\\\n\\end{align}\n\nTo update the biases, we use essentially the same update rule, but only consider the given $\\boldsymbol{\\delta}_{i}$s.\n\\begin{equation}\n\\mathbf{b}^{*} = \\mathbf{b} - \\alpha \\boldsymbol{\\delta}_i^T\\\\\n\\end{equation}\n\nFinally, if we would like to improve the converging speed we can apply momentum. Momentum adds extra \"velocity\" towards the gradient curve, by using the last estimated value of the gradient $\\mathbf{W}^{*}_{i-1}$ ($i$ denotes the current iteration) and applying on that the momentum ($ \\alpha$) as:\n\n\\begin{equation}\n\\mathbf{W}_{i+1} = \\mathbf{W}_i - \\eta \\nabla \\mathbf{W}_i + \\alpha \\mathbf{W}_i\n\\end{equation}\n\nThe momentum is initialized with 0 and takes effect after one iteration of gradient descent.\n\n\\section{Implementation details}\n\nOpenCL offers multiple implementation types. It is natively written in C, but has also a C++ wrapper onboard. We used in our project the C++ wrapper since it is more naturally to use that in a C++ project.\nFirst one needs to include the necessary header into any class.\n\n\\begin{lstlisting}[caption=OpenCL C++ header]\n#include <CL/cl.hpp>\n\\end{lstlisting}\n\n\n\\paragraph{The interface to OpenCL} was written in C++11 and makes heavily use of the current variadic args feature. For this small scale task, the interface is definitely too complex, but it can be used for any other OpenCL task.\n\n\\label{lst:mult}\n\\begin{lstlisting}[caption=Example Kernel function]\n__kernel void mult(const int wSrc, __global const float* A,__global const float* B,__global float* output)\n{\n   const int idx = get_global_id(0);\n   const int idy = get_global_id(1);\n\n   output[idy*wSrc+idx] = A[idy*wSrc+idx] * B[idy*wSrc+idx];\n}\n\\end{lstlisting}\nOpenCL uses externally defined functions ( coined as kernels ) to compile the code and run it, during the runtime. Therefore one needs to write a kernel for its needs. An example kernel can be seen at \\ref{lst:mult}. In our case we defined various kernels, for dot products and other matrix operations.\n\nSince OpenCL is a multi device and platform GPU/CPU interface, one needs to first figure out which kind of platform (e.g. NVIDIA,AMD,Intel) the current machine is using and then decide which accelerator will be used \\ref{lst:plat}.\n\n\\label{lst:plat}\n\\begin{lstlisting}[caption=Get Platforms and devices]\nvoid exampleplatform(const char * programpath){\nstd::vector<cl::Platform> all_platforms;\ncl::Platform::get(&all_platforms);\n//Assume having only one platform\ncl::Platform defaultplatform = all_platforms[0];\nstd::vector<cl::Device> all_gpu_devices;\n//CL_DEVICE_TYPE_GPU can also be CL_DEVICE_TYPE_CPU for CPU\ndefaultplatform.getDevices(CL_DEVICE_TYPE_GPU, &all_gpu_devices);\n//Assume having only one device / take the first\ncl::Device device = all_gpu_devices.front();\n//Init the current context with the device\ncl::Context(device);\n//We wrote a helper function here to get the string data out of the kernel file\nconst char* content = util::file_contents(programpath);\n}\n\\end{lstlisting}\n\n\nMoreover since OpenCL is compiled during runtime, one needs to extract the code from the kernel file (e.g. kernel.cl) and give this content to the OpenCL.\n\nAs soon as the context is initialized we can run our kernels on the device. The problem here is that the kernel is defined with it's own parameters and types, but we dont know these during the compile time.\nTo have a universal interface we used the variadicargs feature to allow the programmer a very straight forward way to use any kernel function.\n\\label{lst:kernel}\n\\begin{lstlisting}[caption=Kernel usage]\nvoid runKernel(const char *kernelname){\ncl::Program::Sources sources;\n//contents is the already read out content of the kernels file (e.g. kernels.cl)\nsources.push_back(std::make_pair(contents,strlen(contents)+1));\n//Init the program with the context and the source\ncl::Program program(context,sources);\n//Build the program on the device\nprogram.build({device});\ncl::CommandQueue queue(context,device);\n//The operator allows us to set args to the kernel \ncl::Kernel kernel_operator(program,kernelname);\n//kernel_operator allows us to send arguments to the kernel by calling\n//kernel_operator.setArgs(ARGNUMBER,ARGUMENT);\n\n//Init space on the device using cl::Buffers\n//Send Arguments to the device ....\n// quene.enqueueWriteBuffer() .....\n//Wait until the arguments did arrive on the device\nqueue.finish();\n\n//Execute!\ncl::Event event;\nqueue.enqueueNDRangeKernel(kernel_operator,cl::NullRange,cl::NDRange(10),cl::NullRange,NULL,&event);\n//Wait until the execution has finished\nevent.wait();\n// Read out the results by calling \n// quene.enqueueReadBuffer()\n}\n\\end{lstlisting}\n\nThe usual Kernel execution can be seen in \\ref{lst:kernel}. Even though it is recommended to use OpenCL in this fashion, we cannot cope with different arguments for the kernel. Therefore we would need to init a device and context every time ( or at least as a singleton ) and then rewrite the argument passing for every parameter independently. This would take a lot of time, if the GPU is used extensively.\n\nOur solution to that problem is as follows:\n\n\\begin{lstlisting}[caption=Add arguments to kernel dynamic way]\nclass OpenCL{\n\n//Constructor ..... etc\n//\tHook for the iteration\ntemplate<std::size_t P=0,typename... Tp>\n\ttypename std::enable_if<P == sizeof...(Tp), void>::type addkernelargs(std::tuple<Tp ...>&& t,cl::Kernel &k,cl::CommandQueue &,std::vector<cl::Buffer> &outputbuffers) const{\n\t// Do nothing\n\t}\n\t\n//  Start of the iteration\ntemplate<std::size_t P = 0, typename... Tp>\n\ttypename std::enable_if< P < sizeof...(Tp), void>::type addkernelargs(std::tuple<Tp...> && t,cl::Kernel &kernel,cl::CommandQueue &,std::vector<cl::Buffer> &outputbuffers) const{\n\t\t // Type\n        typedef typename std::tuple_element<P, std::tuple<Tp...>>::type type;\n\n        // Add the value of the current item from std::get<P> to the args in kernel\n        // This function decides which type the kernel arg is\n        addkernelarg(P, std::get<P>(t), kernel,queue,outputbuffers);\n\n        // Recurse to get the remaining args\n        addkernelargs<P + 1, Tp...>(std::forward<std::tuple<Tp...>>(t), kernel,queue,outputbuffers);\n\t}\n\t\n//\tAdding Std::vector as type to the kernel args list\n\ttemplate<typename T>\n\tvoid addkernelarg(std::size_t i, std::vector<T> const & arg, cl::Kernel & kernel,cl::CommandQueue &) const{\n\t\tcl::Buffer buffer(this->context,CL_MEM_READ_WRITE,arg.size()*sizeof(T));\n\t\tqueue.enqueueWriteBuffer(buffer,CL_FALSE,0,sizeof(T)*arg.size(),&(arg[0]));\n\t\tkernel.setArg(i,buffer);\n\t\n\t}\n\n\n//\tAdding any array into the kernel args\n\ttemplate<typename T,std::size_t N>\n\tvoid addkernelarg(std::size_t i, T const (& arg)[N], cl::Kernel & kernel,cl::CommandQueue &) const{\n\t\tcl::Buffer buffer(this->context,CL_MEM_READ_WRITE,N*sizeof(T));\n\t\tqueue.enqueueWriteBuffer(buffer,CL_FALSE,0,sizeof(T)*N,&arg);\n\t\tkernel.setArg(i,buffer);\n\t}\n\t\n\t// Adding any constant to the kernel\n\ttemplate<typename T>\n\tvoid addkernelarg(std::size_t i, T const & arg, cl::Kernel & kernel,cl::CommandQueue &) const{\n\t\tcl::Buffer buffer(this->context,CL_MEM_READ_WRITE,arg.size()*sizeof(T));\n\t\tqueue.enqueueWriteBuffer(buffer,CL_FALSE,0,sizeof(T)*arg.size(),&(arg[0]));\n\t\tkernel.setArg(i,buffer);\n\t}\n\n}\n\\end{lstlisting}\n\nThis recipe can be used to do the same actions for the reading buffers out after the transfer has finished.\nTherefore we can create a highly dynamic wrapper class for OpenCL.\n\n\\subsection{Using the Interface}\n\n", "meta": {"hexsha": "dc604738761d8eda27f29f38af38047d48a92b8f", "size": 16549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/content/project.tex", "max_stars_repo_name": "crysxd/Parallel-Computing-and-Algorithms-X033537-Project", "max_stars_repo_head_hexsha": "93edc82bd9cbaf6cc80d138be0d276712954ef13", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-21T13:41:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-21T13:41:51.000Z", "max_issues_repo_path": "documentation/content/project.tex", "max_issues_repo_name": "crysxd/Parallel-Computing-and-Algorithms-X033537-Project", "max_issues_repo_head_hexsha": "93edc82bd9cbaf6cc80d138be0d276712954ef13", "max_issues_repo_licenses": ["MIT"], "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/content/project.tex", "max_forks_repo_name": "crysxd/Parallel-Computing-and-Algorithms-X033537-Project", "max_forks_repo_head_hexsha": "93edc82bd9cbaf6cc80d138be0d276712954ef13", "max_forks_repo_licenses": ["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.8777429467, "max_line_length": 447, "alphanum_fraction": 0.7475980422, "num_tokens": 4389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6913107442329883}}
{"text": "\\section{Mathematical Preliminaries}\n\\label{sec:prelim}\nIn this paper, vector- and tensor-valued quantities\nare denoted by bold letters (e.g. $\\bh$ and $\\mathbf{T}$). \nSubscript indices of non-bold characters (e.g. $h_j$ or $T_{ij\\ell}$)\nare used to denote the entries within a vector or tensor.\nWe use the standard Einstein summation convention; i.e., \nthere is an implied sum taken over the repeated indices of \nany term (e.g. the symbol $a_{j} b_{j}$ is used to represent the sum\n$\\sum_{j} a_{j} b_{j}$).\nIf $\\xx = (x_1,x_2)^\\intercal$, then $\\xx^\\bot = (-x_2,x_1)^\\intercal$.\nSimilarly, $\\nabla^\\bot = (-\\partial_{x_2},\\partial_{x_1})^\\intercal$.\nUpper-case script characters (e.g. $\\mathcal{K}$) are reserved for\noperators on Banach spaces, with $\\mathcal{I}$ denoting the\nidentity. Given a set $X$, we denote the closure of $X$\nby $\\overline{X}$.\n\nIn the rest of the paper, \nsuppose that $\\Omega$ is a multiply connected region defined by\nthe intersection of a simply connected domain $\\Omega_{0}$ \nand the exteriors of a finite collection of bounded\nsimply connected domains $\\{ \\Omega_{i} \\}_{i=1}^{m}$. \nLet $\\Gamma_{i}$, denote the boundary of $\\Omega_{i}$, and \nlet $\\Gamma = \\cup_{i=0}^{m} \\Gamma_{i}$ denote the boundary of $\\Omega$.\nLet $\\bnu(\\bx)$ denote the outward normal at $\\bx \\in \\Gamma$.\n\n\\section{Stokes eigenvalue problem}\nThe Stokes Dirichlet eigenvalue problem is to find values $k^2$ such that\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  \\bu &=0 \\quad \\textrm{on} \\quad \\Gamma \\, ,\n\\end{aligned}\n\\end{equation}\nhas a non-trivial solution $(\\bu,p)$.\nSince the Stokes eigenfunction $\\bu$ is divergence free, \nand satisfies \n$\\int_{\\Gamma_{i}} \\bu \\cdot \\bnu \\, ds = 0$ \nfor all $i=0,1,2\\ldots m$, there exists a single valued\nstream function $\\psi$ associated with $\\bu$, i.e., \n$\\bu = \\nabla^{\\perp} \\psi$ for all $\\bx \\in \\Omega$.  \n\nThe Stokes eigenvalue problem can be reformulated as a buckling\neigenvalue problem with gradient boundary conditions for\nthe stream function $\\psi$.\nPlugging in $\\bu = \\nabla^{\\perp} \\psi$ and applying $\\nabla^{\\perp} \\cdot$\nto~\\cref{eq:ostokes}, we observe that $\\psi$ satisfies the following \ndifferential equation.\n\n\\begin{equation}\n\\begin{aligned}\n\\Delta (\\Delta + k^2) \\psi &= 0 \\, \\quad \\textrm{in} \\quad \\Omega \\, , \\\\\n\\nabla \\psi &=0 \\, ,\\quad \\textrm{in} \\quad \\Gamma \\, .\n\\end{aligned}\n\\end{equation}\n\n\\section{Connection to buckling eigenvalues}\nIt is clear that if $w$ is a buckling eigenfunction with\neigenvalue $k^2$, then $\\bu = \\nabla^{\\perp} w$ is a Stokes eigenfunction\nwith the same eigenvalue. \nThus, for a given region $\\Omega$,\nthe buckling eigenvalues are a subset of the Stokes eigenvalue. \n\nHowever, the converse is not necessarily true. \nThe reason is the following.\nAs before, suppose that $\\bu$ is a Stokes eigenfunction\nwith eigenvalue $k^2$.\nNote that a single valued stream function $\\psi$ associated with\n$\\bu$ always exists. \nMoreover, on each component $\\Gamma_{i}$, \n$\\psi$ satisfies $\\partial_{\\tau} \\psi = 0$, which implies that\n$\\psi$ is a constant on $\\Gamma_{i}$, for each $i=0,1,2\\ldots m$.\nIf the domain is simply connected, then since $\\psi$ is only\nwell-defined upto a constant, we can adjust to constant term \nto ensure that $\\psi$ also satisfies $\\psi = 0$ on $\\Gamma_{0}$.\nHowever, on multiply connected domains, this is not always \nthe case since $\\psi$ might be different constants on different\nboundary components. \nIn the following lemma, we identify necessary and sufficient \nconditions on the stream function $\\psi$ to guarantee that\n$\\psi$ (upto a constant) is also a buckling eigenfunction.\n\n\\begin{lem}\n\\label{lem:mainlem}\nSuppose that $k^2$ is a Stokes eigenvalue for the region $\\Omega$ and \nlet $\\bu$ be the corresponding eigenfunction. \nThen, the stream function associated with the velocity $\\bu$ defined by\n$\\psi = \\left(\\nabla^{\\perp} \\right)^{-1} \\bu$ exists and is single valued. \nFurthermore, $k^2$ is also a buckling eigenvalue if and only if\nthere exists a constant $c$ such that\n\\begin{equation}\n\\frac{1}{\\Gamma_{j}}\\int_{\\Gamma_{j}} \\psi\\, ds = c \\quad \\forall j=0,1,\\ldots m \\, .\n\\end{equation}\n\\end{lem}\n\n\\begin{proof}\nSince $\\bu$ is a Stokes eigenfunction, it satisfies\n\\begin{equation}\n\\int_{\\Gamma_{j}} \\bu \\cdot \\bn ds = 0 \\quad j=1,2\\ldots n \\, .\n\\end{equation}\nThus, there exists a single valued stream function associated with the\nvelocity field $\\bu$ such that \n\\begin{equation}\n\\nabla^{\\perp} w = \\bu \\, .\n\\end{equation}\nFurthermore, since $\\bu$ satisfies the oscillatory Stokes equations, \n$w$ satisfies\n\\begin{align}\n\\Delta (\\Delta + k^{2} ) w &= 0 \\, , \\quad \\bx \\in \\Omega \\\\\n\\nabla^{\\perp} w = \\bu &=0 \\, ,\\quad \\bx \\in \\Gamma \\, ,\n\\end{align}\nIn particular $\\psi= c_{j}$ for $\\bx \\in \\Gamma_{j}$ for\nsome constant $c_{j}$.\nThus $k$ is also a buckling eigenvalue if and only if \n\\begin{equation}\nc_{j} = \\frac{1}{|\\Gamma_{j}|}\\int_{\\Gamma_{j}} w ds =  c \\, .\n\\end{equation}\nThe buckling eigenfunction is then given by $\\psi -c$. \n\\end{proof}\n\n\n\\section{Computing the stream function}\nGiven $k^2$ to be a Stokes eigenvalue, in this section, we describe\nan integral formulation for computing the eigenfunction $\\bu$\nand the corresponding stream function $\\psi$. \n\nFollowing the approach in~\\cite{askhameig2019}, we\nfirst reformulate the oscillatory Stokes equation\nas an integral equation on the boundary using the combined\nfield representation.\n\nLet $\\GG(\\bx,\\by)$ denote the Stokeslet for the oscillatory\nStokes equation and $T_{ij\\ell}(\\bx,\\by)$ denote the corresponding\nStresslet. \nThese are given by the formulae\n\\begin{align} \n  \\GG &= - \\II \\Delta \\Gbh + \\nabla \\otimes \\nabla \\Gbh \n\\label{eq:ostokeslet} \\\\\n  T_{ij\\ell} &= - \\partial_{x_j} \\Glap \\delta_{i\\ell}\n  + \\partial_{x_\\ell} \\left ( -\\Delta \\Gbh \\delta_{ij} +\n  \\partial_{x_i} \\left(\\partial_{x_j} \\Gbh \\right) \\right)\n  \\nonumber \\\\\n  & \\qquad+ \\partial_{x_i} \\left ( -\\Delta \\Gbh \\delta_{\\ell j} +\n  \\partial_{x_\\ell} \\left(\\partial_{x_j} \\Gbh \\right) \\right)\n  \\; . \\label{eq:ostress} \n\\end{align}\n$\\Gbh$ is the Green's function for the oscillatory\nbiharmonic equation given by\n\\begin{equation}\n  \\Gbh(\\xx,\\yy) = \\frac{1}{k^2}\n  \\left (\\frac{1}{2\\pi} \\log |\\xx-\\yy| +\n  \\frac{i}{4} H_0^{(1)}(k|\\xx-\\yy|) \\right ) \\, ,\n  \\label{eq:Gbh}\n\\end{equation}\nwhere $k$ is the Helmholtz parameter in the oscillatory biharmonic equation,\nand $H_{0}^{1}(r)$ is the Hankel function of the first kind of order zero,\nand $\\Glap(\\xx,\\yy)$ is the Laplace Green's function given by\n\\begin{equation}\n  \\Glap(\\xx,\\yy) = \\frac{1}{2\\pi} \\log |\\xx-\\yy| \\; . \\nonumber\n\\end{equation}\n\nGiven a density $\\bmu$, the oscillatory Stokes single and double layer\npotentials denoted by $\\bS[\\bmu](\\bx)$ and $\\bD[\\bmu](\\bx)$ respectively,\nare given by\n\\begin{align} \\label{eq:singlelayer}\n  \\bS [\\bmu] (\\xx) &= \\int_\\Gamma \\GG (\\xx,\\yy) \\bmu(\\yy)\n  \\, dS(\\yy) \\; , \\\\\n  \\bD [\\bmu] (\\xx) &= \\int_\\Gamma \\left ( \\TT_{\\cdot,\\cdot,\\ell}(\\xx,\\yy)\n  \\nu_\\ell(\\yy)\\right )^\\intercal \\bmu(\\yy) \\, dS(\\yy) \\; .\n\\end{align}\nWhen solving the velocity boundary value problem for the oscillatory\nStokes equation on multiply connected domains, the velocity\nis represented as a bomcinbed field layer potential, i.e.\nsetting $\\bu = (i\\eta \\bS_{k} + \\bD_{k})[\\bmu]$, where\n$\\eta>0$ is a constant and $\\bmu$ now is an unknown density.\nBy construction, this velocity field satisfies the oscillatory\nStokes equation.\nOn imposing the velocity boundary condition, and using the jump\nconditions for the layer potentials (see~\\cref{askhameig2019}, \nfor example)\nwe obtain the following integral equation for the unknown density\n$\\bmu$,\n\\begin{equation}\n\\label{eq:inteq0}\n(\\cI - 2\\cD_{k} -2i \\eta \\cS_{k})\\bmu = 0 \\, \\quad \\textrm{on} \\quad \\Gamma \\,,\n\\end{equation}\nwhere $\\cS_{k}$ and $\\cD_{k}$ are the restrictions of the layer potentials\n$\\bS_{k}$ and $\\bD_{k}$ on the boundary $\\Gamma$ respectively, and are given\nby\n\\begin{align}\n  \\cS [\\bmu] (\\xx) &= \\int_\\Gamma \\GG (\\xx,\\yy) \\bmu(\\yy)\n  \\, dS(\\yy) \\\\\n  \\cD [\\bmu] (\\xx) &= \\pv \\int_\\Gamma \\left ( \\TT_{\\cdot,\\cdot,\\ell}(\\bx,\\by)\n  \\nu_\\ell(\\yy)\n  \\right )^\\intercal \\bmu(\\yy) \\, dS(\\yy) \\; .\n\\end{align}\nHere \\pv indicates that the integral is to be\nevaluated in the principal value sense.\nThe integral equation~\\cref{eq:inteq0} is known to be rank-deficient\nfor all values of $k$ due to the divergence-free condition\non $\\bu$, and a standard approach is to use the following integral \nequation instead\n\n\\begin{equation}\n\\label{eq:inteq}\n(\\cI - 2\\cD_{k} -2i \\eta \\cS_{k}-2\\cW)\\bmu = 0 \\, \\quad \\textrm{on} \\quad \\Gamma \\,,\n\\end{equation}\nwhere $\\cW$ is the operator given by\n\\begin{equation}\n\\cW[\\bmu](\\bx) = \\frac{\\bnu(x)}{|\\Gamma|}\\int_{\\Gamma} \\bmu(\\by) \\cdot \\bnu(\\by) \\, ds \\, .\n\\end{equation}\n\nIn~\\cite{askhameig2019}, the authors show that the operator \n$\\cI -2\\cD_{k} -2i \\cS_{k} -2\\cW$ is not invertible if and only\nif $k^2$ is a Stokes eigenvalue.\nFurthermore if $\\bmu$ is a non-zero null-vector of $\\cI - 2\\cD_{k} -2i \\cS_{k} \n-2 \\cW$, then \n$\\bu = (i \\eta \\bS_{k} + \\bD_{k})[\\bmu]$ is the Stokes eigenfunction.\n\nIn order to verify the conditions in~\\cref{lem:mainlem}, we\nneed to be able to compute the stream function associated with\nthe velocity $\\bmu$ defined above.\nIf $\\bmu = \\mu_{\\tau} \\btau + \\mu_{\\nu} \\bnu$, where $\\btau=\\bnu^{\\perp}$\nis the positively oriented tangential vector then the\nlayer potentials $\\bS_{k}[\\bmu]$ and $\\bD_{k}[\\bmu]$ can be rewritten as\n\\begin{align}\n\\bS_{k}[\\bmu] &=  \n\\nabla^{\\perp} \n\\int_{\\Gamma} (\\partial_{\\tau} \\Gbh(\\xx,\\yy) \\mu_{\\tau}(\\yy) -\n\\partial_{\\nu} \\Gbh(\\xx,\\yy) \\mu_{\\nu}(\\yy)) \\, ds \\\\\n\\bD_{k}[\\bmu] &= \n-\\nabla \n\\int_{\\Gamma} \\Glap(\\xx,\\yy) \\mu_{\\nu}(\\yy) \\, ds \n+ \\nabla^{\\perp} \n\\int_{\\Gamma} \\big( 2 \\partial_{\\nu\\tau} \\Gbh(\\xx,\\yy) \\mu_{\\nu}(\\yy) \n+ \\\\\n& \\hspace*{35ex}(\\partial_{\\tau\\tau} -\\partial_{\\nu\\nu})\\Gbh(\\xx,\\yy) \\mu_{\\tau}(\\yy) \n\\big) \\, ds \\, .\n\\end{align}\n\nFrom the expressions above, it is clear that the stream function \n$\\psi_{S}[\\bmu]$ associated with the single layer potential is given\nby\n\\begin{equation}\n\\psi_{S}[\\bmu] = \n\\int_{\\Gamma} (\\partial_{\\tau} \\Gbh(\\xx,\\yy) \\mu_{\\tau}(\\yy) -\n\\partial_{\\nu} \\Gbh(\\xx,\\yy) \\mu_{\\nu}(\\yy)) \\, ds \\, . \n\\end{equation}\n\nThe situation with the double layer potential is a little trickier. \nWe write the double layer potential as $\\bD_{k}[\\bmu] = \\nabla \\phi_{D}[\\bmu]\n+ \\nabla^{\\perp} \\xi_{D}[\\bmu]$, \nwhere \n\\begin{align}\n\\label{eq:phiddef}\n\\phi_{D}[\\bmu] &= \n-\\int_{\\Gamma} \\Glap(\\xx,\\yy) \\mu_{\\nu}(\\yy) \\, ds  \\, , \\\\\n\\xi_{D}[\\bmu] &= \n\\int_{\\Gamma} \\big( 2 \\partial_{\\nu\\tau} \\Gbh(\\xx,\\yy) \\mu_{\\nu}(\\yy) \n+ (\\partial_{\\tau\\tau} -\\partial_{\\nu\\nu})\\Gbh(\\xx,\\yy) \\mu_{\\tau}(\\yy) ) \\,\nds \\, . \n\\end{align}\n\nIf we can find a function $\\tilde{\\psi}_{D}[\\bmu]$ such\nthat \n\\begin{equation}\n\\label{eq:perptogradperp}\n\\nabla^{\\perp} \\tilde{\\psi}_{D}[\\bmu] = \\nabla \\phi_{D} [\\bmu] \\, ,\n\\end{equation}\nthen the stream function $\\psi_{D}[\\bmu]$ \nassociated with the double layer potential would\nbe given by $\\psi_{D}[\\bmu] = \\tilde{\\psi}_{D}[\\bmu] + \\xi_{D}[\\bmu]$.\nHowever, on multiply connected domains, it is not necessarily true, \nthat given a function $\\phi_{D}[\\bmu]$ of the form~\\cref{eq:phiddef} \nthere exists a single valued function $\\tilde{\\psi}_{D}[\\bmu]$ \nwhich satisfies the condition~\\cref{eq:perptogradperp} for\nevery $\\bmu$.\nTurns out, in the case where $\\bmu$ satisfies the conditions\n\\begin{equation}\n\\label{eq:inteqconst}\n\\int_{\\Gamma_{i}} \\mu_{\\nu} \\, ds = 0 \\, ,\\quad i=0,1,2\\ldots m \\, ,\n\\end{equation}\nthen there exists a single valued function $\\tilde{\\psi}_{D}[\\bmu]$\nwhich satisfies~\\cref{eq:perptogradperp} (see~\\cite{rachh2015integral}, \nfor example).\nIn the following lemma, we show that every null-vector of \n$\\cI - 2\\cD_{k} -2i \\eta \\cS_{k} - 2\\cW$ satisfies the above integral\nconstraints.\n\n\\begin{lem}\nSuppose $\\bmu$ is a null-vector of \n$\\cI - 2\\cD_{k} - 2i \\eta \\cS_{k} -2\\cW$, then\n$\\bmu$ satisfies~\\cref{eq:inteqconst}.\n\\end{lem}\n\\begin{proof}\nInsert proof here\n\\end{proof}\n", "meta": {"hexsha": "2d5d7f02a28e99fc88d902b31cf74de72214f421", "size": 12066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01/02prelim.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/02prelim.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/02prelim.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": 40.22, "max_line_length": 91, "alphanum_fraction": 0.6773578651, "num_tokens": 4248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6912908847911978}}
{"text": "\\subsection{Preordered sets}\\label{subsec:preordered_sets}\n\n\\begin{definition}\\label{def:preordered_set}\\mcite[def. 2.14]{OpenLogicFull}\n  A \\term{preordered set} is a set \\( \\mscrP \\) endowed with a \\hyperref[def:binary_relation/reflexive]{reflexive} and \\hyperref[def:binary_relation/transitive]{transitive} \\hyperref[def:binary_relation]{binary relation} \\( \\leq \\). The relation itself is called a \\term{preorder}.\n\n  It is conventional to use the same symbol \\( \\leq \\) as for \\hyperref[def:partially_ordered_set]{partial orders}, however the lack of \\hyperref[def:binary_relation/antisymmetric]{antisymmetry} may be confusing --- see \\fullref{ex:preorder_nonuniqueness}.\n\n  We define \\( \\geq \\) as the \\hyperref[def:binary_relation/converse]{inverse relation} of \\( \\leq \\).\n\n  Preordered sets have the following metamathematical properties:\n  \\begin{thmenum}\n    \\thmitem{def:preordered_set/theory} Consider a \\hyperref[def:first_order_language]{first-order language} \\( \\mscrL \\) with two \\hyperref[rem:first_order_formula_conventions/infix]{infix} binary predicate symbols --- \\( \\leq \\) and \\( \\geq \\).\n\n    The theory of preordered sets is a \\hyperref[def:first_order_theory]{first-order theory} in \\( \\mscrL \\) consisting of the axioms \\eqref{eq:def:binary_relation/reflexive} and \\eqref{eq:def:binary_relation/transitive} for \\( \\leq \\) and the compatibility axiom\n    \\begin{equation}\\label{eq:def:preordered_set/theory}\n      (\\xi \\leq \\eta) \\leftrightarrow (\\eta \\geq \\xi).\n    \\end{equation}\n\n    \\thmitem{def:preordered_set/homomorphism} A \\hyperref[def:first_order_homomorphism]{homomorphism} from \\( (\\mscrP, \\leq_\\mscrP) \\) to \\( (\\mscrQ, \\leq_\\mscrQ) \\) is, explicitly, a function \\( f: \\mscrP \\to \\mscrQ \\) such that\n    \\begin{equation}\\label{eq:def:preordered_set/homomorphism}\n      x \\leq_\\mscrP y \\T{implies} f(x) \\leq_\\mscrQ f(y).\n    \\end{equation}\n\n    These are precisely the \\hyperref[eq:def:partially_ordered_set/homomorphism/nonstrict]{nonstrict monotone maps}.\n\n    \\thmitem{def:preordered_set/submodel} Since the theory contains only positive formulas over a language with no functional symbols, any subset \\( A \\) of the domain of a preordered set \\( \\mscrP \\) becomes a preordered set with the induced preorder \\( \\leq_A \\) defined as the \\hyperref[def:binary_relation/restriction]{restriction} of \\( \\leq_\\mscrP \\) to only elements of \\( A \\).\n\n    \\thmitem{def:preordered_set/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial preordered set} is the empty set (see \\fullref{rem:empty_models} regarding allowing empty sets as first-order structures).\n\n    \\thmitem{def:preordered_set/category}  We denote the \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} for the theory of preordered sets by \\( \\ucat{PreOrd} \\).\n\n    This category is equivalent to that of \\( \\mscrU \\)-small thin categories --- see \\fullref{thm:order_category_isomorphism/preordered}.\n\n    \\thmitem{def:preordered_set/duality} We define the \\term{dual preordered set} of \\( (\\mscrP, \\leq) \\) as \\( (\\mscrP, \\geq) \\).\n\n    The \\term{principle of duality} states that the formula \\( \\varphi \\) is derivable in the \\hyperref[def:preordered_set/theory]{theory of preordered sets} if and only if the dual formula \\( \\varphi^{-1} \\), in which we swap all instances of \\( \\leq \\) and \\( \\geq \\), is also derivable. Observe that \\( \\varphi \\) is satisfied in a preordered set if and only if \\( \\varphi^{-1} \\) is satisfied in the dual preordered set.\n\n    There is a actually a very simple proof. If \\( \\varphi \\) is derivable in the theory, it is satisfied by every preordered set. Let \\( \\mscrP \\) be a preordered set. Then \\( \\varphi \\) is satisfied in both \\( (\\mscrP, \\leq) \\) and its dual \\( (\\mscrP, \\geq) \\). But if \\( \\varphi \\) is valid for the dual preordered set \\( (\\mscrP, \\geq) \\), its dual formula \\( \\varphi^{-1} \\) is valid for the the double dual preordered set, which is \\( (\\mscrP, \\leq) \\). Since \\( (\\mscrP, \\leq) \\) was chosen arbitrarily, the dual formula \\( \\varphi^{-1} \\) is valid for every preordered set and, so it belongs to the theory of preordered sets.\n\n    The dual of the dual formula of \\( \\varphi \\) is obviously \\( \\varphi \\). The actual replacement can be formalized by performing the \\hyperref[def:first_order_substitution/term_in_formula]{simultaneous substitution}\n    \\begin{equation*}\n      \\begin{aligned}\n        \\varphi^{-1} \\coloneqq \\varphi[\n          &\\xi_1 \\leq \\eta_1 \\mapsto \\xi_1 \\geq \\eta_1, &&\\xi_1 \\geq \\eta_1 \\mapsto \\xi_1 \\leq \\eta_1, \\\\\n          &\\vdots                                       &&\\vdots \\\\\n          &\\xi_n \\leq \\eta_n \\mapsto \\xi_n \\geq \\eta_n, &&\\xi_n \\geq \\eta_n \\mapsto \\xi_n \\leq \\eta_n]\n      \\end{aligned}\n    \\end{equation*}\n    for all pairs \\( (\\xi_k, \\eta_k) \\) of free variables in \\( \\varphi \\).\n\n    Another form of this duality is formalized in \\fullref{thm:order_category_isomorphism}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:directed_set}\\mcite[8]{Engelking1989}\n  A \\hyperref[def:preordered_set]{preordered set} \\( \\mscrP \\) is called a \\term{directed set} if every finite subset of \\( \\mscrP \\) has an \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{upper bound}, i.e. for all \\( x, y \\in \\mscrP \\) there must exist \\( z \\in \\mscrP \\) such that \\( x \\leq z \\) and \\( y \\leq z \\). We do not care how many upper bounds exist and how they are related, we simply need one upper bound to exist for every pair of elements of \\( \\mscrP \\).\n\n  There is no established name for the relation itself.\n\n  Directed sets are used to define nets in topological spaces, see \\fullref{def:topological_net}.\n\\end{definition}\n\n\\begin{definition}\\label{def:cofinal_set}\n  A subset \\( A \\) of a preordered set \\( (\\mscrP, \\leq) \\) is called \\term{cofinal} if for every \\( x \\in \\mscrP \\) there exists some \\( y \\in A \\) such that \\( x \\leq y \\).\n\\end{definition}\n\n\\begin{example}\\label{ex:def:cofinal_set}\n  We list several examples of \\hyperref[def:cofinal_set]{cofinal} and non-cofinal sets.\n\n  \\begin{itemize}\n    \\item In a finite set like \\( \\set{ 0, 1, 2 } \\), the set \\( \\set{ 2 } \\) containing the maximum is cofinal. This is generalized by \\fullref{thm:partially_ordered_cofinal_equivalences}.\n\n    \\item Consider the set \\( \\BbbZ \\) of integers. Clearly the set \\( 2\\BbbZ \\) of even integers is cofinal. This is generalized by \\fullref{thm:totally_ordered_cofinal_equivalences}.\n\n    \\item Cofinal sets are important in topology because it is used to define \\hyperref[def:net_convergence]{convergence of nets}.\n\n    \\item \\hyperref[def:regular_cardinal]{Regular cardinals} are equal to their own \\hyperref[def:cofinality]{cofinality}.\n  \\end{itemize}\n\\end{example}\n", "meta": {"hexsha": "78695ad5bdd7798bc86d24a35abc9ee4cec84286", "size": 6772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/preordered_sets.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/preordered_sets.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/preordered_sets.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.65, "max_line_length": 634, "alphanum_fraction": 0.7129356172, "num_tokens": 2066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6912908684558869}}
{"text": "\\documentclass{article}\n\n\\usepackage{style/preamble}\n\\usepackage{style/mytikz}\n\\usepackage{parskip}\n\n\\begin{document}\n  \\title{Problem Set 1 - The Riemann Sphere}\n  \\date{}\n  \\maketitle\n\n    \\begin{mdframed}\n      Corrected open mapping theorem statement:\n      \\begin{theorem}[Open mapping theorem]\n        \\label{th:OpenMappingTheorem}\n        If $f:U \\rightarrow \\bbc$ is a \\emph{non-constant} complex differentiable then for any open set $V \\subseteq U$, the set $f(V)$ is an open subset of $\\bbc$.\n      \\end{theorem}\n    \\end{mdframed}\n\n    \\section*{Holomorphic functions on $\\bbp^1$}\n    A complex differentiable function $f: X \\rightarrow \\bbc$ is called a \\emph{holomorphic} function on $X$.\n\n    The Riemann sphere $\\bbp^1$ is the set $\\bbc \\cup \\set{\\infty}$.\n    We write $\\bbp^1$ as the union of two sets\n    \\begin{align*}\n      U_1 = \\bbc && U_2 = \\bbc \\setminus \\set{0} \\cup \\set{\\infty}\n    \\end{align*}\n    The set $U_1$ is the standard complex plane, but the set $U_2$ is not.\n    We can turn $U_2$ into the complex plane by using the following function\n    \\begin{align*}\n      \\varphi_2 : U_2 &\\longrightarrow \\bbc \\\\\n      z &\\mapsto z^{-1} \\mbox{ if } z \\neq \\infty \\\\\n      \\infty &\\mapsto 0\n    \\end{align*}\n    Thus we can think of $\\bbp^1$ as two copies of the complex plane ($U_1$ and $\\varphi_2(U_2)$) glued together.\n\n    A function $f: \\bbp^1 \\rightarrow \\bbc$ is defined as a pair of functions\n    \\begin{align*}\n      f_1 : U_1 \\rightarrow \\bbc && f_2 : U_2 \\rightarrow \\bbc\n    \\end{align*}\n    such that $f_1$ and $f_2$ agree on $U_1 \\cap U_2$.\n\n    We can only make sense of the complex differentiable functions when both the source and target are open subsets of $\\bbc$. For this reason, we define holomorphic functions on $\\bbp^1$ as follows.\n\n    A function $f: \\bbp^1 \\rightarrow \\bbc$ is holomorphic if\n    \\begin{enumerate}\n      \\item $f|_{U_1}$ is holomorphic,\n      \\item $f \\circ \\varphi_2^{-1}|_{\\varphi(U_2)}$ is holomorphic.\n    \\end{enumerate}\n    \\begin{equation*}\n      \\begin{tikzcd}\n        U_1 \\ar[r,\"f|_{U_1}\"] &  \\bbc\\\\\n        U_2 \\ar[d, \"\\varphi_2\"] \\ar[r, \"f\"] & \\bbc \\\\\n        \\bbc \\ar[u, \"\\varphi_2^{-1}\", bend left] \\ar[ur, \"f \\circ \\varphi_2^{-1}\", swap, dashed]\n      \\end{tikzcd}\n    \\end{equation*}\n\n    \\begin{qbox}\n      Check that defining a function $f: \\bbp^1 \\rightarrow \\bbc$ is equivalent to defining a pair of functions\n      \\begin{align*}\n        f_1: U_1 &\\longrightarrow \\bbc \\\\\n        f_2 \\circ \\varphi_2^{-1}: \\varphi(U_2) &\\longrightarrow \\bbc \\\\\n      \\end{align*}\n      such that\n      \\begin{align*}\n        f_1(z) = f_2 \\circ \\varphi_2^{-1}(z^{-1}) \\mbox{ whenever } z \\neq 0.\n      \\end{align*}\n      Note that the source of both $f_1$ and $f_2 \\circ \\varphi_2^{-1}$ is $\\bbc$.\n    \\end{qbox}\n\n    It is kinda hard to come up with examples because of the following theorem.\n\n    \\begin{theorem}\n      The only holomorphic functions on $\\bbp^1$ are the constant functions.\n    \\end{theorem}\n    The proof is in the following exercises.\n\n    A subset $V$ of a topological space $X$ is compact if it has the following property.\n    \\begin{quote}\n      Every infinite sequence has a convergent subsequence i.e. for every infinite sequence of points $a_1, a_2, \\dots $ in $V$ there exists a subsequence $a_{n_1}, a_{n_2}, a_{n_3}, \\dots$ which converges to a point in $V$.\n    \\end{quote}\n    % For subsets of $\\bbr^n$ or $\\bbc^n$ this is equivalent to saying that $X$ is closed and bounded.\n\n    \\begin{qbox}\n      Prove that compact subsets $V$ of a (nice) topological space $X$ are closed i.e. if a sequence of points $a_1, a_2, \\dots $ in $V$ converges to point $a \\in X$ then $a$ is in $V$.\n    \\end{qbox}\n\n    \\begin{qbox}\n      Prove that every compact subset $V$ of $\\bbc$ is bounded i.e. there exists a real number $M$ such that $z < M$ for all $z \\in V$.\n    \\end{qbox}\n\n    \\begin{qbox}\n      \\label{q:imageOfCompact}\n      Use the fact that every infinite sequence has a convergent subsequence to argue that for any continuous function $g: X \\rightarrow Y $ the image of a compact set is compact.\n    \\end{qbox}\n\n    Assume the following fact:\n    \\begin{quote}\n      The Riemann sphere is a compact topological space.\n    \\end{quote}\n    One way to see this is that the Riemann sphere is topologically isomorphic to the sphere $S^2$ in $\\bbr^3$ (hence the name) which is a closed and bounded subset of $\\bbr^3$. It is not hard to show that such subsets are compact.\n\n    \\begin{qbox}\n      Argue that the image of any continuous function $f: \\bbp^1 \\rightarrow \\bbc $ is bounded.\n    \\end{qbox}\n\n    \\begin{qbox}\n      Using Liouville's theorem, argue that if $f$ is a holomorphic function on $\\bbp^1$ then $f|_{U_1}$ is a constant function.\n    \\end{qbox}\n    \\begin{qbox}\n      Using continuity, argue that if $f$ is a holomorphic function on $\\bbp^1$ then $f$ is a constant function.\n    \\end{qbox}\n\n\n\n\n\n\n\n\n\n    \\section*{Meromorphic functions on $\\bbc$}\n    A complex differentiable function $f: X \\rightarrow \\bbp^1$ is called a \\emph{meromorphic} function on $X$.\n\n    We can only make sense of the complex differentiable functions when both the source and target are open subsets of $\\bbc$. For this reason, we define meromorphic functions on $X$ as follows.\n\n    A function $f: X \\rightarrow \\bbp^1$ is meromorphic if\n    \\begin{enumerate}\n      \\item $f$ is holomorphic when restricted to $f^{-1}(U_1)$,\n      \\item $\\varphi_2 \\circ f$ is holomorphic when restricted to ${f^{-1}(U_2)}$.\n    \\end{enumerate}\n    \\begin{equation*}\n      \\begin{tikzcd}\n        f^{-1}(U_1) \\ar[rr,\"f\"] & &  U_1 = \\bbc\\\\\n        f^{-1}(U_2) \\ar[rr, \"f\"] \\ar[rrrr, \"\\varphi_2 \\circ f\", swap, bend right] & & U_2 \\ar[rr, \"\\varphi_2\"] & & \\bbc\n      \\end{tikzcd}\n    \\end{equation*}\n\n    It gets tedious to keep track of all the inverses and the sources and targets.\n    We use the following shorthand notation to simplify the clutter.\n    Let $\\varphi_1: U_1 \\rightarrow \\bbc$ be the identity function, $\\varphi_1(z) = z$.\n    Then a function $f: X \\rightarrow \\bbp^1$ is meromorphic if the two functions\n    \\begin{enumerate}\n      \\item $\\varphi_1 \\circ f$,\n      \\item $\\varphi_2 \\circ f$,\n    \\end{enumerate}\n    are holomorphic wherever they make sense.\n    \\begin{equation*}\n      \\begin{tikzcd}\n        f^{-1}(U_1) \\ar[rrrr, \"\\varphi_1 \\circ f\", swap, bend right] \\ar[rr,\"f|_{f^{-1}(U_1)}\"] &  &  U_1 \\ar[rr, \"\\varphi_1\"] & & \\bbc\\\\\\\\\n        f^{-1}(U_2) \\ar[rr, \"f|_{f^{-1}(U_2)}\"] \\ar[rrrr, \"\\varphi_2 \\circ f\", swap, bend right] &  & U_2 \\ar[rr, \"\\varphi_2\"] & & \\bbc\n      \\end{tikzcd}\n    \\end{equation*}\n\n    \\begin{qbox}\n      Which of the following functions are meromorphic functions on $\\bbc$?\n      \\begin{enumerate}\n        \\item $f(z) = z$\n        \\item \\begin{align*}\n            f(z) = \\begin{cases}\n                    z^{-1} & \\mbox{ if } z \\neq 0\\\\\n                    \\infty & \\mbox{ if } z = 0\n                  \\end{cases}\n          \\end{align*}\n        \\item \\begin{align*}\n            f(z) = \\begin{cases}\n                    e^{1/z} & \\mbox{ if } z \\neq 0\\\\\n                    \\infty & \\mbox{ if } z = 0\n                  \\end{cases}\n          \\end{align*}\n      \\end{enumerate}\n    \\end{qbox}\n\n\n\n\n\n\n\n\n\n\n    \\section*{Meromorphic functions on $\\bbp^1$}\n    \\begin{qbox}\n      Show that a function $f: \\bbp^1 \\rightarrow \\bbp^1$ is meromorphic if the four functions\n      \\begin{enumerate}\n        \\item $\\varphi_1 \\circ f \\circ \\varphi_1^{-1}$,\n        \\item $\\varphi_1 \\circ f \\circ \\varphi_2^{-1}$,\n        \\item $\\varphi_2 \\circ f \\circ \\varphi_1^{-1}$,\n        \\item $\\varphi_2 \\circ f \\circ \\varphi_2^{-1}$,\n      \\end{enumerate}\n      are holomorphic wherever they make sense.\n    \\end{qbox}\n\n    \\begin{qbox}\n      Let $p(z)$ and $q(z)$ be polynomials with no common roots. Assume that $q(z)$ is not the 0 polynomial.\n\n      Show that the following function is a meromorphic function on $\\bbp^1$.\n      \\begin{align*}\n        f(z) = \\begin{cases}\n          \\dfrac{p(z)}{q(z)} & \\mbox{ if } z \\neq \\infty, q(z) \\neq 0, \\\\\n          \\infty & \\mbox{ if } z \\neq \\infty, q(z) = 0, \\\\\n          \\lim \\limits_{z \\rightarrow \\infty} \\dfrac{p(z)}{q(z)} & \\mbox{ if } z = \\infty.\n      \\end{cases}\n      \\end{align*}\n      Such a function is called a \\emph{rational function}. It is common to simply write $f(z) = \\dfrac{p(z)}{q(z)}$.\n    \\end{qbox}\n\n    Turns out these are all the meromorphic functions on $\\bbp^1$.\n    \\begin{theorem}\n      Every meromorphic function on $\\bbp^1$ is a rational function.\n    \\end{theorem}\n    The following exercises provide the proof of this theorem.\n\n    Let $f: \\bbp^1 \\rightarrow \\bbp^1$ be a meromorphic function.\n    Let $\\calz = f^{-1}(0) \\cap \\bbc$ and $\\calp = f^{-1}(\\infty) \\cap \\bbc$. $\\calz$ is called the set of zeroes and $\\calp$ is called the set of poles.\n    \\begin{qbox}\n      Using the isolated zeroes property of complex differentiable functions argue that both the sets $\\calz$ and $\\calp$ are isolated i.e. for every point $x \\in \\calz$ there exists a neighborhood  $U$ of $x$ such that $U \\cap \\calz = \\set{x}$. Similarly, for $\\calp$.\n    \\end{qbox}\n    \\begin{qbox}\n      Using the fact that every infinite sequence in a compact set has a convergent subsequence, and that $\\bbp^1$ is compact, argue that both $\\calz$ and $\\calp$ are finite sets.\n    \\end{qbox}\n    Let $\\calz = \\set{z_1, \\dots, z_m}$ and $\\calp = \\set{p_1, \\dots, p_n}$.\n    Assume the following fact for now. We'll prove it in class tomorrow.\n    \\begin{quote}\n      The function\n      \\begin{align*}\n        g(z) = f(z) \\cdot \\dfrac{(z-p_1)^{k_1} \\dots (z-p_n)^{k_n}}{(z-z_1)^{\\ell_1} \\dots (z-z_m)^{\\ell_m}}\n      \\end{align*}\n      is meromorphic and has no zeroes or poles, for some positive integers $k_1, \\dots, k_n$ and $\\ell_1, \\dots, \\ell_m$.\n    \\end{quote}\n    \\begin{qbox}\n      Check that the open mapping theorem \\ref{th:OpenMappingTheorem} extends verbatim to meromorphic functions on $\\bbp^1$.\n    \\end{qbox}\n    \\begin{qbox}\n      Using the open mapping theorem and Q.\\ref{q:imageOfCompact} argue that $g$ is either a constant function or the image of $g$ is all of $\\bbp^1$.\\hint{You will need to use the fact that the only open and closed subsets of $\\bbp^1$ are the empty set and $\\bbp^1$ itself.}\n    \\end{qbox}\n    Because the only zero or pole of $g$ is at $\\infty$ (which can be one or the other) the image of $g$ cannot be all of $\\bbp^1$. Hence, $g$ is a constant function i.e. $g(z) = c$ for some $c \\in \\bbc$. Hence,\n    \\begin{align*}\n      &&\n      f(z) \\cdot \\dfrac{(z-p_1)^{k_1} \\dots (z-p_n)^{k_n}}{(z-z_1)^{\\ell_1} \\dots (z-z_m)^{\\ell_m}}\n      = c \\\\\n      \\implies\n      &&\n      f(z) = c\\dfrac{(z-z_1)^{\\ell_1} \\dots (z-z_m)^{\\ell_m}}{(z-p_1)^{k_1} \\dots (z-p_n)^{k_n}}.\n    \\end{align*}\n\\end{document}\n", "meta": {"hexsha": "dda7d8cd83a30b0aba526661675c48dda0f933c1", "size": 10785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PSet01.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": "PSet01.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": "PSet01.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": 43.4879032258, "max_line_length": 275, "alphanum_fraction": 0.6157626333, "num_tokens": 3590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629215, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.6912908658781757}}
{"text": "\\input{PreambleCommon}\r\n\\input{../WeekTitles}\r\n\r\n\\begin{document}\r\n\\setfont\r\n\\pagestyle{fancy}\r\n\\renewcommand{\\Week}{5 }\r\n\\renewcommand{\\WeekTitle}{\\WeekTitleFive }\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\r\n\\vspace{5mm}\r\n\\goals\r\n\\begin{itemize}\r\n\\item Recognize the family of functions that can be solved with the technique of\r\nintegration by substitution.\r\n\\item Solve integration problems using the technique of substitution. \r\n\\item Recognize the family of functions that can be solved with the technique of\r\nintegration by parts. \r\n\\item Solve integration problems using the technique of integration by parts. \r\n\\end{itemize}\r\n\\vspace{5mm}\r\n\r\n\r\n\r\n\\topic{Integration Method - Guess and Check}\r\n\r\nWe now return to the challenge of finding a {\\em formula} for an\r\nanti-derivative function.  We saw simple cases last week, and now we\r\nwill extend our methods to handle more complex integrals.\r\n\r\n\\section*{Anti-differentiation by Inspection:\\\\ The Guess-and-Check Method}\r\n\r\n\r\n\\vsc\r\n\r\nOften, even if we do not see an anti-derivative immediately, we can\r\nmake an educated guess and eventually arrive at the correct answer.\r\n\r\n\\vsc \r\n\r\n\\newpage\r\n\\problem Based on your knowledge of derivatives, what should the\r\n  anti-derivative of $\\cos(3x)$, $\\ds \\int \\cos(3x) ~dx$, look like?\r\n\r\n\\vfill\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\problem Find $\\ds \\int e^{3x-2} ~dx$.\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\nBoth of our previous examples had {\\em linear} `inside'\r\n  functions.  Here is an integral with a {\\em quadratic} `inside' function:\r\n$$\\ds{\\int x e^{-x^2} ~dx}$$\r\n\\problem Evaluate the integral.  \\vfill \\vfill\r\n\r\nWhy was it important that there be a factor $x$ in front\r\n  of $e^{-x^2}$ in this integral?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\\topic{Integration Method - Substitution}\r\n\\section*{Integration by Substitution}\r\n\r\nWe can formalize the guess-and-check method by defining an {\\em\r\n  intermediate variable} the represents the ``inside'' function.\r\n\r\n\\problem Show that $\\ds \\int x^3 \\sqrt{x^4 + 5} ~dx = {1 \\over 6} (x^4\r\n  + 5)^{3/2} + C$.\r\n\r\n\\vfill\r\n\\vfill\r\n\r\n\\newpage\r\n$$\\ds \\int x^3 \\sqrt{x^4 + 5} ~dx = {1 \\over 6} (x^4\r\n  + 5)^{3/2} + C$$\r\n\r\n\\problem Relate this result to the {\\bf chain rule}.\r\n\r\n\\vfill\r\n\r\n\\vsc\r\n\r\n\\newpage\r\n\r\n\\problem Now use the {\\bf method of substitution} to evaluate $\\ds\r\n  \\int x^3 \\sqrt{x^4 + 5}~dx$\r\n\r\n\\vfill\r\n\\vfill\r\n\\vfill\r\n\\vfill\r\n\r\n\r\n\\newpage\r\n\r\n\\topic{Substitution Integrals - Example 1}\r\n\r\n{\\bf Steps in the Method Of Substitution}\r\n\r\n\\begin{enumerate}[1.]\r\n\\item Select a simple function $w(x)$ that appears in the integral.\r\n  \\begin{itemize}\r\n  \\item Typically, you will also see $w'$ as a {\\bf factor} or {\\bf\r\n      multiplier} in the integrand as well.\r\n  \\end{itemize}\r\n\\item Find $\\ds \\frac{dw}{dx}$ by differentiating.  Re-write it in the\r\n  form $\\ldots dw = ~dx$\r\n  \\item Rewrite the integral using only $w$ and $dw$ (no $x$ nor\r\n    $dx$).\r\n  \\begin{itemize}\r\n  \\item If you can now evaluate the integral, the substitution\r\nwas effective. \r\n\\item If you cannot remove all the $x$'s, or the integral became\r\n  harder instead of easier, then either try a different substitution,\r\n  or a different integration method.\r\n  \\end{itemize}\r\n\\end{enumerate}\r\n\r\n\\newpage\r\n\r\n\r\n\\problem Find $\\ds{ \\int \\tan(x) ~dx}$.\r\n\r\n\\vsc \r\n\r\n\\vfill\r\n\\vfill\r\n\\vfill\r\n\\vfill\r\n\r\n\\newpage\r\n\r\nThough it is not required unless specifically requested, it can be reassuring to check the answer.\r\n\r\n\\problem Verify that the anti-derivative you found is correct.\r\n\r\n\\vfill\r\n\\newpage\r\n\r\n\\topic{Substitution Integrals - Example 2}\r\n\\problem Find $\\ds{\\int x^3 e^{x^4 - 3} dx}$.\r\n\r\n\\newpage \r\n\\topic{Substitution Integrals - Example 3}\r\n\r\n\\problem For the integral, $$ \\int{\\frac{e^x - e^{-x}}{(e^x + e^{-x})^2}}\r\n  dx \\ \\ $$ both $w = e^{x} - e^{-x}$ and $w = e^{x} + e^{-x}$ are\r\n  seemingly reasonable substitutions.  \r\n\r\n\\Question{Which substitution will change\r\n  the integral into the simpler form?}\r\n\r\n  \\begin{enumerate}[1.]\r\n  \\item  $ w = e^x - e^{-x}$ \r\n  \\item  $ w = e^x + e^{-x}$ \r\n  \\end{enumerate}\r\n\r\n\\newpage\r\n\r\n\\problem Compare both substitutions in practice.\r\n$$ \\int{\\frac{e^x - e^{-x}}{(e^x + e^{-x})^2}}~dx$$\r\n\\begin{center}\r\n\\begin{tabular}{l|r}\r\n   with $ w = e^x - e^{-x}$ ~~~~~ &~~~~~\r\n   with $ w = e^x + e^{-x}$  \\\\\r\n~& \\\\\r\n~& \\\\\r\n~& \\\\\r\n~& \\\\\r\n~& \\\\\r\n~& \\\\\r\n~& \\\\\r\n~& \\\\\r\n\\end{tabular}\r\n\\end{center}\r\n\r\n\\newpage\r\n\\topic{Substitution Integrals - Example 4}\r\n\\problem Find $\\ds \\int \\frac{\\sin(x)}{1 + \\cos^2(x)} dx$.\r\n\r\n\\newpage\r\n\r\n\\topic{Substitutions and Definite Integrals}\r\n\r\n\r\n\\section*{Using the Method of Substitution for Definite Integrals}\r\n\r\nIf we are asked to evaluate a {\\bf definite} integral such as\r\n$$\r\n\\int_0^{\\pi/2} \\frac{\\cos x}{1+\\sin x} dx \\ \\ ,\r\n$$\r\n\r\nwhere a substitution will ease the integration, we have two methods\r\nfor handling the limits of integration ($x=0$ and $x=\\pi/2$).\r\n\\begin{enumerate}[a)]\r\n\\item When we make our substitution, convert both the {\\em variables}\r\n  $x$ and the {\\em limits} (in $x$) to the new variable; or\r\n\\item do the integration while keeping the limits explicitly in terms\r\n  of $x$, writing the final integral back in terms of the original $x$\r\n  variable as well, and {\\em then} evaluating.\r\n\\end{enumerate}\r\n\r\n\\newpage\r\n\r\n\\problem Use method (a) (converting both the integral and the limits\r\nto the new variable) to evaluate the integral\r\n$$\\int_0^{\\pi/2} \\frac{\\cos x}{1+\\sin x} dx$$\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\\problem Use method (b) (converting back to $x$'s to evaluate at the\r\nend points) to evaluate\r\n$$ \\int_9^{64} \\frac{\\sqrt{1 + \\sqrt{x}}}{\\sqrt{x}} dx \\ \\ .\r\n$$\r\n\r\n\\newpage\r\n\r\n\\topic{Integration Method - By Parts}\r\n\r\n\\section*{Integration by Parts}\r\n\r\nSo far in studying integrals we have used \r\n\\begin{itemize}\r\n\\item direct anti-differentiation, for relatively simple functions,\r\n  and\r\n\\item integration by substitution, for some more complex integrals.\r\n\\end{itemize}\r\n\r\nHowever, there are many integrals that can't be evaluated with these\r\ntechniques.\r\n\r\n\\problem Try to find $\\ds \\int x e^{4x} ~dx$.\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\nThis particular integral can be evaluated with a different integration\r\ntechnique, {\\bf integration by parts.}  This rule is related to the\r\n{\\bf product rule} for derivatives.  \r\n\r\n\\problem Expand\r\n\\begin{align*}\r\n\\frac{d}{dx} \\left(u v\\right) = \r\n\\end{align*}\r\n\r\nIntegrate both sides with respect to $x$ and simplify.\r\n\r\n\\vfill\r\n\r\nExpress $\\ds \\int u \\frac{dv}{dx} ~dx$ relative to the other terms.\r\n\r\n\\vfill\r\n\r\n\r\n\\newpage\r\n\\begin{boxnote}\r\n  {\\bf Integration by Parts} \\\\\r\n  For short, we can remember this formula as\r\n\\begin{align*}\r\n\\ds \\int udv = uv - \\int vdu\r\n\\end{align*}\r\n\\end{boxnote}\r\n\r\n\\vspace{3mm} Integration by parts: \r\n\\begin{itemize}\r\n\\item Choose a part of the integral to be $u$, and the remaining part\r\n  to be $dv$.\r\n\\item {\\bf Differentiate} $u$ to get $du$.\r\n\\item {\\bf Integrate} $dv$ to get $v$.\r\n\\item Replace $\\ds \\int u ~dv$ with $\\ds uv - \\int v du$.\r\n\\item Hope/check that the new integral is easier to evaluate.\r\n\\end{itemize}\r\n\r\n\r\n\\newpage\r\n\r\n\\problem Use integration by parts to evaluate $\\ds \\int x e^{4x} ~dx$.\r\n\r\n\\vfill\r\n\\vfill\r\n\\vfill\r\n\r\n\\newpage\r\n\\problem Verify that your anti-derivative is correct.\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\\topic{Integration By Parts - Examples}\r\n\\subsection*{Integration By Parts - Examples}\r\n\r\n\\begin{boxnote}\r\n{\\bf Guidelines for selecting $u$ and $dv$}\r\n\r\n\\begin{itemize}\r\n\\item Ensure you can actually integrate the $dv$ part by itself, then\r\n\\item Try to select $u$ and $dv$ so that either \r\n\\begin{itemize}\r\n\\item $u'$ is simpler than $u$ or\r\n\\item $\\int dv$ is simpler than $dv$ \r\n\\end{itemize}\r\n\\end{itemize}\r\n\\end{boxnote}\r\n\r\n\\newpage\r\n\\problem Find $\\ds \\int x  \\cos x ~ dx$.\r\n\r\n\\vfill\r\n\r\n\r\n\\newpage\r\n\\problem Now evaluate the slightly more challenging integral $$\\ds \\int x^2\\cos x ~ dx$$\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\hfill $\\ds \\int x^2\\cos x ~ dx$\r\n\r\n\\newpage \r\n\r\n\\topic{Integration By Parts - Definite Integrals}\r\n\\subsection*{Integration By Parts - Definite Integrals}\r\nWhen using integration by parts to evaluate {\\em definite} integrals,\r\nyou need to apply the limits of integration to the {\\bf entire}\r\nanti-derivative that you find.\r\n\r\n\\problem Evaluate $\\ds \\int_{0}^{\\pi} x  \\sin 4x ~ dx$\r\n\r\n\\newpage \r\n\r\nDon't forget that $dv$ does not require any other factors besides\r\n$dx$.  That can help when there is only a single factor in the\r\nintegrand.\r\n\r\n\\problem Find the area under the graph of $\\ln x$ between $x=1$ and\r\n$x=2$.\r\n\r\n\\newpage\r\n\r\nGeneral integration advice:\r\n\\begin{itemize}\r\n\\item Look for a substitution in your integral first - they are the simplest method to use,\r\nand usually the most obvious.\r\n\\item Only try integration by parts if substitution fails. \r\n\\item With all methods, you may need to {\\bf experiment} with your\r\n  choice of $u, dv$, or your substitution.\r\n\\end{itemize}\r\n\r\n\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "2d918694d152ac70b2ade91b31f9d73ffe132029", "size": 8902, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/notes05.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/notes05.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/notes05.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": 24.3224043716, "max_line_length": 99, "alphanum_fraction": 0.6688384633, "num_tokens": 2605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.691290861854321}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 4}\n\nConstruct deterministic finite automata that accept the following languages over the alphabet $A = \\{a,b,c\\}$:\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item The set of all words that begin with $ab$ and end with $ba$.\n\t\\item The set $\\{bab\\}$.\n\t\\item The set $A^* - \\{bab\\}$.\n\t\\item The set of all words $x \\in A^*$ that contain at least three $a$s.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\t\\item\n\tThe \\textit{dfa} that recognizes the language of the set of words that begin with $ab$ and end with $ba$ represented by $abA^*ba \\cup \\{aba\\}$ is shown in Figure \\ref{fig:DR5}.\n\n\t\\begin{figure}[H]\\centering\n\t\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\t\\node[state] (2) {$q_2$};\n\t\t\t\\node[state,initial] (0) [above left of =2] {$q_0$};\n\t\t\t\\node[state] (1) [below left of=2] {$q_1$};\n\t\t\t\\node[state] (3) [right of=2] {$q_3$};\n\t\t\t\\node[state] (4) [above right of=3] {$q_4$};\n\t\t\t\\node[state, final] (5) [below right of=3] {$q_5$};\n\t\t\t\\path\n\t\t\t\t(0) edge [bend left] node {a} (2)\n\t\t\t\t\tedge [bend right] node {b,c} (1)\n\t\t\t\t(1) edge [loop left] node {a,b,c} (1)\n\t\t\t\t(2) edge [bend left]  node {a,c} (1)\n\t\t\t\t\tedge [bend left]  node {b} (3)\n\t\t\t\t(3) edge [loop left] node {b} (3)\n\t\t\t\t\tedge [bend right] node {c} (4)\n\t\t\t\t\tedge [bend left]  node {a} (5)\n\t\t\t\t(4) edge [loop right] node {a,c} (4)\n\t\t\t\t\tedge [bend right]  node {b} (3)\n\t\t\t\t(5) edge [bend right]  node {a,c} (4)\n\t\t\t\t\tedge [bend left]  node {b} (3);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Graph of a \\textit{dfa} accepting the set of words that begin with $ab$ and end with $ba$}\n\t\t\\label{fig:DR5}\n\t\\end{figure}\n\n\t\\item\n\tThe \\textit{dfa} that recognizes the language of the set $\\{bab\\}$ is shown in Figure \\ref{fig:DR6}.\n\n\t\\begin{figure}[H]\\centering\n\t\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\t\\node[state,initial] (0) {$q_0$};\n\t\t\t\\node[state] (1) [above right of=0] {$q_1$};\n\t\t\t\\node[state] (2) [below right of=1] {$q_2$};\n\t\t\t\\node[state] (3) [above right of=2] {$q_3$};\n\t\t\t\\node[state, final] (4) [below right of=3] {$q_4$};\n\t\t\t\\path\n\t\t\t\t(0) edge [bend left] node {b} (1)\n\t\t\t\t\tedge [bend right] node {a,c} (2)\n\t\t\t\t(1) edge [bend left=15] node {a} (3)\n\t\t\t\t\tedge [bend right] node {b,c} (2)\n\t\t\t\t(2) edge [loop below] node {a,b,c} (2)\n\t\t\t\t(3) edge [bend left] node {b} (4)\n\t\t\t\t\tedge [bend left] node {a,c} (2)\n\t\t\t\t(4) edge [bend left] node {a,b,c} (2);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Graph of a \\textit{dfa} accepting the set $\\{bab\\}$}\n\t\t\\label{fig:DR6}\n\t\\end{figure}\n\n\t\\item\n\tthe \\textit{dfa} that recognizes the language of the set $A^* - \\{bab\\}$ is shown in Figure \\ref{fig:DR7}.\n\n\t\\begin{figure}[H]\\centering\n\t\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\t\\node[state,initial,final] (0) {$q_0$};\n\t\t\t\\node[state,final] (1) [above right of=0] {$q_1$};\n\t\t\t\\node[state,final] (2) [below right of=1] {$q_2$};\n\t\t\t\\node[state,final] (3) [above right of=2] {$q_3$};\n\t\t\t\\node[state] (4) [below right of=3] {$q_4$};\n\t\t\t\\path\n\t\t\t\t(0) edge [bend left] node {b} (1)\n\t\t\t\t\tedge [bend right] node {a,c} (2)\n\t\t\t\t(1) edge [bend left] node {a} (3)\n\t\t\t\t\tedge [bend right] node {b,c} (2)\n\t\t\t\t(2) edge [loop below] node {a,b,c} (2)\n\t\t\t\t(3) edge [bend left] node {b} (4)\n\t\t\t\t\tedge [bend left] node {a,c} (2)\n\t\t\t\t(4) edge [bend left] node {a,b,c} (2);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Graph of a \\textit{dfa} accepting the set $A^* -\\{bab\\}$}\n\t\t\\label{fig:DR7}\n\t\\end{figure}\n\n\t\\item\n\tThe set of all words that contain at least three $a$s can be described as set of all words of the form $A^*aA^*aA^*aA^*$.\n\t\\textit{dfa} that recognizes such language would have a final state $q_3$ to be reached from $q_0$ by three symbols $a$.\n\tProposed \\textit{dfa} is shown in Figure \\ref{fig:DR8} where state $q_i$ is reached by the words with at least $i$ symbol $a$.\n\n\t\\begin{figure}[H]\\centering\n\t\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\t\\node[state,initial] (0) {$q_0$};\n\t\t\t\\node[state] (1) [right of=0] {$q_1$};\n\t\t\t\\node[state] (2) [right of=1] {$q_2$};\n\t\t\t\\node[state,final] (3) [right of=2] {$q_3$};\n\t\t\t\\path\n\t\t\t\t(0) edge [loop below] node {b,c} (0)\n\t\t\t\t\tedge [bend left] node {a} (1)\n\t\t\t\t(1) edge [loop below] node {b,c} (1)\n\t\t\t\t\tedge [bend left] node {a} (2)\n\t\t\t\t(2) edge [loop below] node {b,c} (2)\n\t\t\t\t\tedge [bend left] node {a} (3)\n\t\t\t\t(3) edge [loop below] node {a,b,c} (3);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Graph of a \\textit{dfa} accepting the set $A^*aA^*aA^*aA^*$}\n\t\t\\label{fig:DR8}\n\t\\end{figure}\n\n\\end{enumerate}\n", "meta": {"hexsha": "d9582677c9eb0ff6b3434517a498c716cf2d319c", "size": 5201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q04.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q04.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q04.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.6328125, "max_line_length": 177, "alphanum_fraction": 0.6041145933, "num_tokens": 2045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956856, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6912908466279454}}
{"text": "\\subsection{Taylor Polynomials}\\label{sec:Taylor}\nWe can go beyond first order derivatives to create polynomials approximating a function as closely as we wish, these are called $Taylor$ $Polynomials$.\n\nWhile our linear approximation $L(x)=f'(a)(x-a)+f(a)$ at a point $a$ was a polynomial of degree 1 such that both $L(a)=f(a)$ and $L'(a)=f'(a)$, we can now form a polynomial\n\\[ T_n(x)=a_0+a_1(x-a)+a_2(x-a)^2+a_3(x-a)^3+\\dots +a_n(x-a)^n \\]\nwhich has the same first $n$ derivatives at $x=a$ as the function $f$.\n\nBy successively computing the derivatives of $T_n$, we obtain:\n\\[ \\begin{array}{l}\na_0 = f(a)=\\frac{f(a)}{0!}\\\\\na_1 = \\frac{f'(a)}{1!}\\\\\na_2 = \\frac{f''(a)}{2!}\\\\\n\\cdots \\\\\na_k = \\frac{f^{(k)}(a)}{k!}\\\\\n\\cdots a_n =\\frac{f^{(n)}(a)}{n!}\n\\end{array} \\]\nwhere $f^{(k)}(x)$ is the $k^{th}$ derivative of $f(x)$, and\n$n!=n(n-1)(n-2)\\ldots (2)(1) $, referred to as \\ifont{factorial} notation.\n\nHere is an example.\n\n\\begin{example}{Approximate e using Taylor Polynomials}{approximate e using taylor polynomials}\nApproximate $e^x$ using Taylor polynomials at $a=0$, and use this to approximate $e$.\n\\end{example}\n\n\\begin{solution}\nIn this case we use the function $f(x)=e^x$ at $a=0$, and therefore\n\\[ T_n(x)=a_0+a_1x+a_xx^2+a_3x^3+\\ldots +a_nx^n \\]\n\nSince all derivatives $f^{(k)}(x)=e^x$, we get:\n\\[ \\begin{array}{l}\na_0=f(0)=1 \\\\\na_1=\\frac{f'(0)}{1!}=1 \\\\\na_2=\\frac{f''(0)}{2!}=\\frac{1}{2!} \\\\\na_3=\\frac{f'''(0)}{3!}=\\frac{1}{3!} \\\\\n\\cdots \\\\\na_k=\\frac{f^{(k)}(0)}{k!}=\\frac{1}{k!} \\\\\n\\cdots \\\\\na_n=\\frac{f^{(n)}(0)}{n!}=\\frac{1}{n!} \n\\end{array} \\]\nThus\n\\[ \\begin{array}{l}\nT_1(x)=1+x=L(x) \\\\\nT_2(x)=1+x+\\frac{x^2}{2!} \\\\\nT_3(x)=1+x+\\frac{x^2}{2!}+\\frac{x^3}{3!}\n\\end{array} \\]\nand in general\n\\[ T_n(x)=1+x+\\frac{x^2}{2!}+\\frac{x^3}{3!}+\\cdots +\\frac{x^n}{n!}. \\]\n\nFinally we can approximate $e=f(1)$ by simply calculating $T_n(1)$. A few values are:\n\\[ \\begin{array}{l}\nT_1(1)=1+1=2 \\\\\nT_2(1)=1+1+\\frac{1^2}{2!}=2.5 \\\\\nT_4(1)=1+1+\\frac{1^2}{2!}+\\frac{1^3}{3!}=2.\\overline{6} \\\\\nT_8(1)=2.71825396825 \\\\\nT_{20}(1)=2.71828182845\n\\end{array} \\]\n\nWe can continue this way for larger values of $n$, but $T_{20}(1)$ is already a pretty good approximation of $e$, and we took only 20 terms!\n\\end{solution}\n%\n%\\subsubsection{Taylor's Theorem}\\label{subsubsec:TaylorsTheoremsubsubsec}\n%We have now seen how a polynomial is used to approximate a function $f$ near $a$. But how close is our approximation to the actual function? That is to say, can we measure the error in our approximation?\n%\n%\\begin{theorem}{Taylor's Theorem}{TaylorTheorem}\n%Suppose $f$ is defined and has $n+1$ continuous derivatives on an open interval $I$ containing $a$. Then for each $x$ in the interval,\n%\\[\\ds f(x)=\\left[\\sum_{k=0}^n\\frac{f^{(k)}(a)}{k!}(x-a)^k\\right]+R_{n+1}(x)\\]\n%where the error term is \n%\\[R_{n+1}(x)=\\frac{f^{(n+1)}(z)}{(n+1)!}(x-a)^{n+1}\\]\n%for some $z$ between $a$ and $x$.\n%\\end{theorem}\n%\n%The form for the error $R_{n+1}(x)$ is called the \\dfont{Lagrange Formula} for the remainder. Notice that this error term looks quite similar to how we would expect the next term in the Taylor Polynomial of $f(x)$ to look. The main difference is that $f^{(n+1)}$ is evaluated at a point $z$ and not necessarily at the center $a$, and we do not know what $z$ might be.\n%\n%Notice as well that when $n=0$, Taylor's Theorem is precisely the Mean Value Theorem, which is mainly how we would prove Taylor's Theorem (but will not prove here). The following corollary is useful when applying the theorem.\n%\n%\\begin{corollary}{Corollary to Taylor's Theorem}{TaylorTheoremCorollary}\n%Let $\\mu_{n+1}$ be the maximum of $|f^{(n+1)}(x)|$ on some interval containing the center $a$. Then for any $x$ in this interval, the error of the Taylor Polynomial is bounded as follows.\n%\\[\\ds |f(x)-T_n(x)|\\leq \\frac{\\mu_{n+1}}{(n+1)!}|x-a|^{n+1}.\\]\n%\\end{corollary}\n%\n%Observe that if $f^{(n+1)}(x)=0$, then the Taylor Polynomial of degree $n$ is an exact approximation of the function $f$. Why? If the $(n+1)$\\textsuperscript{th} derivative of a function is 0, then $f$ is simply a polynomial of degree at most $n$.\n%\n%Let's look at an example:\n%\n%\\begin{example}{Approximate Square Root}{ApproxSquareRootTaylorTheorem}\n%Approximate $\\sqrt{11}$ to accuracy of at least 0.01.\n%\\end{example}\n%\\begin{solution}\n%The 2nd degree Taylor Polynomial of $f(x)=\\sqrt{x}$ centered at $x=9$ is given by:\n%\\[\\ds T_2(x)=3+\\frac{1}{6}(x-9)-\\frac{1}{216}(x-9)^2.\\]\n%For our purposes a 2nd degree polynomial should be sufficient to produce our desired level of accuracy, which we will see shortly. If we require greater accuracy, we can simply increase the degree of the Taylor Polynomial. At $x=11$ this polynomial approximation gives $T_2(10)=3.3\\overline{148}$.\n%\n%Now we must determine the accuracy of our approximation. We first find that the third derivative of $\\sqrt{x}$ if $f'''(x)=\\frac{3}{8}x^{-5/2}$, and that this function's maximum in the interval $[9,11]$ occurs at $x=9$ (since it is a positive decreasing function). Thus, the maximum value is $\\mu_3=f'''(9)=\\frac{3}{8}\\cdot\\frac{1}{243}=\\frac{3}{1944}=\\frac{1}{648}$. Applying the corollary we get\n%\\begin{align*}\n%\\left|\\sqrt{11}-3.3\\overline{148}\\right|&\\leq\\frac{1}{648}\\frac{1}{3!}(11-9)^3\t\\\\\n%&\\leq\\frac{1}{486}\\approx 0.0020576\n%\\end{align*}\n%Therefore, the approximation $3.3\\overline{148}$ is guaranteed to be accurate to at least $\\frac{1}{486}$, which is less than 0.01.\n%\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Taylor}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex} \nFind the 5\\textsuperscript{th} degree Taylor polynomial for $f(x)=\\sin x$ around $a=0$.\n\\begin{enumerate}\n\t\\item\tUse this Taylor polynomial to approximate $\\sin (0.1)$.\n\t\\item\tUse a calculator to find $\\sin (0.1)$. How does this compare to our approximation in part (a)?\n\\end{enumerate}\n\\begin{sol}\n$T_5(x)=x-\\frac{x^3}{3!}+\\frac{x^5}{5!}$\n\\begin{enumerate}\n\t\\item\t$\\sin (0.1)\\approx T_5(0.1)\\approx 0.10016675$\n\t\\item\t$\\sin (0.1)=0.0998334\\ldots$ using a calculator. Our approximation is accurate to $0.10016675-0.0998334\\ldots =0.000\\bar{3}$.\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nSuppose that $f^{\\prime\\prime}$ exists and is continuous on $[1,2]$.\nSuppose also that $\\left\\vert f^{\\prime\\prime}(x)\\right\\vert \\leq \\frac{1}{4}$\nfor all $x$ in $(1,2)$. Prove that if we use the linearization $y=L(x)$\nof $y=f(x)$ at $x=1$ as an approximation of $y=f(x)$ near $x=1$,\nthen our estimated value of $f(1.2)$ is\nguaranteed to have an accuracy of at least 0.01, i.e., our estimate will lie\nwithin 0.01 units of the true value.\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex} \nFind the 3\\textsuperscript{rd} degree Taylor polynomial for $f(x)=\\frac{1}{1-x}-1$ around $a=0$. Explain why this approximation would not be useful for calculating $f(5)$.\n\\begin{sol}\n\t$T_3(x)=x+x^2+x^3$. The point $x=5$ is not close to $x=0$, and $f$ is not continuous at $x=1$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nConsider $f(x)=\\ln x$ around $a=1$.\n\\begin{enumerate}\n\t\\item\tFind a general formula for $f^{(n)}(x)$ for $n\\geq 1$.\n\t\\item\tFind a general formula for the Taylor Polynomial, $T_n(x)$.\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$f^{(n)}(x)=\\frac{(-1)^{(n-1)}(n-1)!}{x^n}$\n\t\\item\t$T_n(x)=\\ln (1)+\\displaystyle\\sum_{i=1}^{n} \\frac{\\big(\\frac{(-1)^{(i-1)}(i-1)!}{1^n}\\big)}{i!}(x-1)^i=\\displaystyle\\sum_{i=1}^{n} \\bigg(\\frac{(-1)^{(i-1)}(i-1)!}{i!}\\bigg)(x-1)^i$ since $\\ln (1)=0$ and $1^n=1$.\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n%% % % % % % % % % %\n%% Exercises for Taylor's Theorem\n%% % % % % % % % % %\n%\\begin{ex}\n%Approximate $\\ln(1.3)$ to accuracy of at least 0.0001.\n%\\end{ex}\n%\n%\\begin{ex}\n%Determine a general inequality describing the error of Taylor Polynomial approximations of $f(x)=\\sin(x)$ and $g(x)=\\cos(x)$. \\ifont{(Hint: Build the inequality in Corollary~\\ref{cor:TaylorTheoremCorollary})}\n%\\begin{sol}\n%\t\\begin{align*}\n%\t|\\sin(x)-T_n(x)|&\\leq\\frac{1}{(n+1)!}x^{n+1}\t\\\\\n%\t|\\cos(x)-T_n(x)|&\\leq\\frac{1}{(n+1)!}x^{n+1}\n%\t\\end{align*}\n%\\end{sol}\n%\\end{ex}\n%\n%% % % % % % % % % %\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "7f09d20fc5d7c52f99b95eb6c5db342f62f5e006", "size": 8124, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-4-3-taylor-polynomials.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-3-taylor-polynomials.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-3-taylor-polynomials.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1333333333, "max_line_length": 398, "alphanum_fraction": 0.6509108813, "num_tokens": 3021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.9086178987887253, "lm_q1q2_score": 0.6911407977479103}}
{"text": "\\chapter{Trignometric Functions}\n\nAs mentioned earlier, in a right triangle where one angle is $\\theta$,\nthe sine of $\\theta$ is the length of the side opposite $\\theta$\ndivided by the length of the hypotenuse.\n\nThe sine function is defined for any real number. We treat that real number\n$\\theta$ as an angle, we draw a ray from the origin out to the unit\ncircle.  The $y$ value of that point is the sine. So, for example,\nthe $\\sin(\\frac{4\\pi}{3})$ is $-\\sqrt{3}/2$\n\n\\begin{tikzpicture}[declare function={angle=240;},bullet/.style={inner\n    sep=1pt,fill,draw,circle,solid}, scale=3]\n    % Axis\n    \\draw[thick,-stealth,black] (-1.2,0)--(1.2,0) node[right] {$x$}; % x axis\n    \\draw[thick,-stealth,black] (0,-1.2)--(0,1.2) node[left] {$y$}; % y axis\n    % Rest\n    \\draw (0,0) circle (1);\n    \\draw[thick] (0,0) -- (angle:1.0) node [midway, right] {1};\n    \\draw[sdkblue] (-0.1, 0.32) node[above] {$\\theta = \\frac{4\\pi}{3}\\text{ radians} = 240^\\circ$};\n    \\draw[-stealth,sdkblue] (0.3,0) arc (0:angle:0.3);\n    \\draw[dashed, black] (-0.7, -0.866) -- (0.05, -0.866) node[right] {$\\sin(\\theta) = -\\sqrt{3}/2$}; % horizontal\n    \\filldraw[black] (angle:1.0) circle(1pt);\n\\end{tikzpicture}\n\n(Note that in this section, we will be using radians instead of\ndegrees unless otherwise noted. While degrees is more familiar to most\npeople, engineers and mathematicians nearly always use radians when\nsolving problems. Your calculator should have a radians mode and a\ndegrees mode. You want to be in radians mode.)\n\nSimilarly, we define cosine using the unit circle: to find the cosine\nof $\\theta$, we draw a ray from the origin at the angle $\\theta$. The\n$x$ component of the point where the ray intersects the unit circle is\nthe cosine of $\\theta$.\n\n\\begin{tikzpicture}[declare function={angle=240;},bullet/.style={inner\n    sep=1pt,fill,draw,circle,solid}, scale=3]\n    % Axis\n    \\draw[thick,-stealth,black] (-1.2,0)--(1.2,0) node[right] {$x$}; % x axis\n    \\draw[thick,-stealth,black] (0,-1.2)--(0,1.2) node[left] {$y$}; % y axis\n    % Rest\n    \\draw (0,0) circle (1);\n    \\draw[thick] (0,0) -- (angle:1.0) node [midway, right] {1};\n    \\draw[sdkblue] (0.1, 0.32) node[above] {$\\theta = \\frac{4\\pi}{3}\\text{ radians} = 240^\\circ$};\n    \\draw[-stealth,sdkblue] (0.3,0) arc (0:angle:0.3);\n    \\draw[dashed, black]  (-0.5, -0.95) -- (-0.5, 0.05) node[left, above] {$\\cos(\\theta) = -0.5$}; % horizontal\n    \\filldraw[black] (angle:1.0) circle(1pt);\n\\end{tikzpicture}\n\nFrom this description, it is easy to see why $\\sin(\\theta)^2 +\n\\cos(\\theta)^2 = 1$.  They are the legs of a right triangle with a\nhypotenuse of length 1.\n\nIt should also be easy to see why $\\sin(\\theta) = \\sin(\\theta +\n2\\pi)$: Each time you go around the circle, you come back to where\nyou started.\n\nCan you see why $\\cos(\\theta) = \\sin(\\theta + \\pi/2)$? Turn the picture sideways.\n\n\\section{Graphs of sine and cosine}\n\nHere is a graph of $y = \\sin(x)$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.5] (-6.6,-1.2) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\end{tikzpicture}\n\nIt looks like waves, right? It goes forever to the left and\nright. Remembering that $\\cos(\\theta) = \\sin(\\theta + \\pi/2)$, we can\nguess what the graph of $y = \\cos(x)$ looks like:\n    \n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.5] (-6.6,-1.2) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] plot (\\x,{cos(deg{\\x})});\n\\end{tikzpicture}\n\n\\section{Plot cosine in Python}\n\nCreate a file called \\filename{cos.py}:\n\n\\begin{Verbatim}\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nuntil = 8.0\n\n# Make a plot of cosine\nthetas = np.linspace(0, until, 32)\ncosines = []\nfor theta in thetas:\n    cosines.append(np.cos(theta))\n\n# Plot the data\nfig, ax = plt.subplots()\nax.plot(thetas, cosines, 'r.', label=\"Cosine\")\nax.set_title(\"Cosine\")\nplt.show()\n\\end{Verbatim}\n\nThis will plot 32 points on the cosine wave between 0 and 8.  When you\nrun it, you should see something like this:\n\n\\includegraphics[width=0.8\\textwidth]{cospy.png}\n\n\\section{Derivatives of sine and cos}\n\nHere is a wonderful property of sine and cosine functions: At any point $\\theta$, the slope of the sine graph at $\\theta$ equals $cos(\\theta)$.\n\nFor example, we know that $\\sin(4\\pi/3) = -(1/2)\\sqrt{3}$ and\n$\\cos(4\\pi/3) = -1/2$. If we drew a line tangent to the sine curve at\nthis point, it would have a slope of -1/2:\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] (-1.25,-1.7) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-3/2, -1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -1] in \n       {-\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-1.25,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.5) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,thick,draw=black,\n      domain=-1.75:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\filldraw[black] (4.188790204786391,-0.866025403784439) circle(2pt);\n\\draw[->, thick, draw=red] (4.188790204786391,-0.866025403784439) -- (5.188790204786391,-1.366025403784439) node [right] {slope = -1/2} ;\n\\end{tikzpicture}\n\nWe say ``The derivative of the sine function is the cosine function.''\n\nCan you guess the derivative of the cosine function? For any $\\theta$, the slope of the graph of the $\\cos(\\theta)$ is $-\\sin(\\theta)$.\n\n\n\n\\section{A weight on a spring}\n\nLet's say you fill a rollerskate with heavy rocks and attach it to the\nwall with a stiff spring.  If you push the skate toward the wall a\nrelease it, it will roll back and forth. Engineers would say ``The skate will oscillate.''\n\nIntuitively, you can probably guess:\n\\begin{itemize}\n\\item If the spring is stronger, the skate will oscillate more times per minute.\n\\item If the rocks are lighter, the skate will oscillate more times per minute.\n\\end{itemize}\n\nThe force that the spring exerts on the skate is proportional to how\nfar its length is from its relaxed length.. When you buy a spring, the\nmanufacturer advertises its ``spring rate'', which is in pounds per\ninch or newtons per meter.  If a spring has a rate of 5 newtons per\nmeter, that means that if stretch or compress it 10 cm, it will push\nback with a force of 0.5 newtons. If you stretch or compress it 20 cm,\nit will push back with a force of 1 newton.\n\nLet's write a simulation of the skate-on-a-spring.  Duplicate \\filename{cos.py}, and name the new copy \\filename{spring.py}.  Add code to implement the simulation:\n\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nuntil = 8.0\n\n\\textbf{# Constants}\n\\textbf{mass = 100 # kg}\n\\textbf{spring_constant = -1 # newtons per meter displacement}\n\\textbf{time_step = 0.01 # s}\n\n\\textbf{# Initial state}\n\\textbf{displacement = 1.0 # height above equilibrium in meters}\n\\textbf{velocity = 0.0}\n\\textbf{time = 0.0 # seconds}\n\n\\textbf{# Lists to gather data}\n\\textbf{displacements = []}\n\\textbf{times = []}\n\n\\textbf{# Run it for a little while}\n\\textbf{while time <= until:}\n\\textbf{    # Record data}\n\\textbf{    displacements.append(displacement)}\n\\textbf{    times.append(time)}\n\n\\textbf{    # Calculate the next state}\n\\textbf{    time += time_step}\n\\textbf{    displacement += time_step * velocity}\n\\textbf{    force = spring_constant * displacement }\n\\textbf{    acceleration = force / mass}\n\\textbf{    velocity += acceleration}\n\n# Make a plot of cosine\nthetas = np.linspace(0, until, 32)\ncosines = []\nfor theta in thetas:\n    cosines.append(np.cos(theta))\n\n# Plot the data\nfig, ax = plt.subplots()\n\\textbf{ax.plot(times, displacements, 'b', label=\"Displacement\")}\nax.plot(thetas, cosines, 'r.', label=\"Cosine\")\n\n\\textbf{ax.set_title(\"Weight on Spring vs. Cosine\")}\n\\textbf{ax.set_xlabel(\"Time (s)\")}\n\\textbf{ax.set_ylabel(\"Displacement (m)\")}\n\\textbf{ax.legend()}\nplt.show()\n\\end{Verbatim}\nWhen you run it, you should get a plot of your spring and the cosine graph on the same plot.\n\n\\includegraphics[width=0.8\\textwidth]{springpy.png}\n\nThe position of the skate is following a cosine curve. Why?\n\nBecause for a sine or cosine waves happen whenever the acceleration of \nan object is proportional to -1 times its displacement. Or in symbols:\n\n$$a \\propto - p$$\n\nwhere $a$ is acceleration and $p$ is the displacement from equilibrum.\n\nRemember that if you take the derivative of the displacement, you get\nthe velocity.  And if you take the derivative of that, you get\nacceleration.  So, the weight on the spring must follow a function $f$ such that\n\n$$f(t) \\propto - f''(t)$$\n\nRemember that the derivative of the $\\sin(\\theta)$ is $\\cos(\\theta)$.\n\nAnd the derivative of the $\\cos(\\theta)$ is $- \\sin(\\theta)$\n\nThus these sorts of waves have an almost-magical power: their\nacceleration is proportional to -1 times their displacement.\n\nThus sine waves of various magnitudes and frequencies are ubiquitous\nin nature and technology.\n\n\\section{Integral of sine and cosine}\n\nIf we take the area between the graph and the $x$ axis of the cosine\nfunction (and if the function is below the $x$ axis, it counts as\nnegative area), from 0 to $4\\pi/3$, we find that it is equal to\n$-(1/2)\\sqrt{3}$\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels                                                                                               \n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n\n% y tick label                                                                                                           \n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label                                                                                                           \n\\foreach \\x [count=\\xx from -1] in\n       {-\\frac{\\pi}{2},\n        { },\n         \\frac{\\pi}{2},\n         \\pi,\n         \\frac{3\\pi}{2},\n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n       % axes\n       \\draw[->,thick] (-1.25,0) -- (6.5,0) node[right] {$x$};\n       \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n       % curve\n       \\draw[<->,thick,draw=black, domain=-1.75:6.5,samples=300,variable=\\x] plot (\\x,{cos(deg{\\x})});\n       \\fill[sdkblue, domain=0:1.57,samples=100, variable=\\b]\n       (0, 1)\n       -- plot (\\b,{cos(deg(\\b))})\n       -- (0, 0)\n       -- cycle;\n       \\fill[red, domain=1.57:4.188790204786391,samples=100, variable=\\b]\n       (1.57, 0)\n       -- plot (\\b,{cos(deg(\\b))})\n       -- (4.188790204786391, 0)\n       -- cycle;\n       \\draw[thick, draw=black] (4.188790204786391, 1) -- (4.188790204786391,-1) node [right]{area=$-(1/2)\\sqrt{3}$};\n\\end{tikzpicture}\n\nWe say ``The integral of the cosine function is the sine function.'' \n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "8dfdc32f995ab6b5aeee4711d3866a88664fec32", "size": 12325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Oscillations/trig_functions-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Oscillations/trig_functions-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Oscillations/trig_functions-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 35.0142045455, "max_line_length": 163, "alphanum_fraction": 0.6123326572, "num_tokens": 4092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.9086178994073576, "lm_q1q2_score": 0.6911407883584285}}
{"text": "\n\\subsection{Power series}\n\nof the form:\n\n\\(\\sum_{n=0}a_n(x-c)^n\\)\n\n\\subsubsection{Smoothness of power series}\n\nPower series are all smooth. That is, they are infinitely differentiable.\n\n", "meta": {"hexsha": "a34399da38cc32ae12e61ffcdb8b4587f863798f", "size": 187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/01-01-powerSeries.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/01-01-powerSeries.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/01-01-powerSeries.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.5833333333, "max_line_length": 73, "alphanum_fraction": 0.7379679144, "num_tokens": 52, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6911360850327445}}
{"text": "\\par These notes are entirely based on the material of the course Computational Mathematics for Learning and Data Analysis held by Professor Antonio Frangioni and Professor Federico Poloni at University of Pisa. The course is part of the M.Sc. degree in Computer Science.\n\n\\section{Mathematical Background}\n\\subsection{Notations and Nomenclatures}\n\\par Let's start with introducing some notations and nomenclatures that we are going to use throughout this book. Given a set $\\mathcal{X}$, that we call \\textbf{feasible region}, and a function $f : \\mathcal{X} \\rightarrow \\mathbb{R}$, that we call \\textbf{objective function}, we want to find the solution to the following problem:\n\\begin{equation}\n    f_{*} = \\min_{x \\in \\mathcal{X}}\\ \\{f(x)\\}\n    \\label{eq:opt_problem_def}\n\\end{equation}\nwhere $f_{*}$ is called \\textbf{optimal value}. The argument $x$ that \\textit{minimises} the objective function $f$ is called \\textbf{optimal solution}. It is generally denoted with $x_{*}$.\\\\[5px]\n%\n\\underline{Note that}: $f_{*}$ lives in the output space while $x$ lives in the input space. This is going to be very important where we speak about convergence of the various algorithms that we will see during this brief journey.\\\\[5px]\n%\nObviously, from the moment that we are minimising the function $f$, we have the following property:\n\\[\n    \\forall\\ x \\in \\mathcal{X}\\ f(x) \\geq f(x_{*})\n\\]\nHere again, note that we do not state any ordering relation in the input space; $x$ may be larger, equal or even smaller than $x_{*}$.\n\\par As we will see in the next chapters, we often employ \\textit{iterative methods} for finding the optimal value/optimal solution. Applying an iterative method implies producing a certain sequence of the form $x_1, x_2, ...$ that will bring us to the optimum solution; and thus to the optimal value. Typically we cannot hope to get exactly to $f_{*}$, what we hope instead is to get \\textit{as close as possible} to it. Accordingly, limits are very important to us.\nWe say that:\n\\begin{equation}\n    \\lim_{i \\rightarrow \\infty} x_i = x \\iff \\forall \\epsilon > 0\\ \\exists h : |x_i - x| \\leq \\epsilon\\ \\forall i \\geq h\n    \\label{eq:limit_def}\n\\end{equation}\nIn other words, the sequence $\\{x_i\\}$ converges to $x$, written as $\\{x_i\\} \\rightarrow x$, if and only if... the rest of the formula :). Just kidding. So we were saying, the sequence $\\{x_i\\}$ converges to $x$ if and only if for \\textit{any} tiny number $\\epsilon$ that we can choose (as long as it is greater than 0), at some point in our sequence, starting from the number $x_h$, all the numbers in it will be at distance at most $\\epsilon$ from $x$.\n\\par Not all sequences have the limit. For instance think of $(-1)^i$. This sequence does not converge to neither of -1, 0 or 1. This is the reason why we introduce the concept of \\textbf{infima} and \\textbf{suprema}, or respectively $\\liminf$ and $\\limsup$. We define the following two quantities:\n\\[\n    \\{x_i\\} \\rightarrow \\underbar{$x$}_i = \\inf\\{x_h : h \\geq i\\}\n\\]\nand\n\\[\n    \\{x_i\\} \\rightarrow \\bar{x}_i = \\sup\\{x_h : h \\geq i\\}\n\\]\nNow if we take the sequence of $\\{\\underbar{x}_i\\}$ we are sure that $\\underbar{x}_1 \\leq \\underbar{x}_2 \\leq \\underbar{x}_3 \\leq ...$ and the sequence of $\\{\\bar{x}_i\\}$ we are sure that $\\bar{x}_1 \\geq \\bar{x}_2 \\geq \\bar{x}_3 \\geq ...$. Accordingly, they have a limit! So we can speak about inferior and superior limit of a certain sequence $\\{x_i\\}$. We have the following equality:\n\\begin{align}\n    &\\liminf_{i \\rightarrow \\infty} x_i = \\lim_{i \\rightarrow \\infty}\\inf\\{x_h : h \\geq i\\} = \\lim_{i \\rightarrow \\infty} \\underbar{x}_i\\\\\n    &\\limsup_{i \\rightarrow \\infty} x_i = \\lim_{i \\rightarrow \\infty}\\sup\\{x_h : h \\geq i\\} = \\lim_{i \\rightarrow \\infty} \\bar{x}_i\n    \\label{eq:liminf_limsup_def}\n\\end{align}\nNow obviously $\\bar{x}_i \\geq \\underbar{x}_i$. But if these two quantities are equal, then we are sure that the limit of the sequence exists:\n\\[\n    \\lim_{i \\rightarrow \\infty} x_i = v \\iff \\liminf_{i \\rightarrow \\infty} x_i = v = \\limsup_{i \\rightarrow \\infty} x_i\n\\]\n%\n\\par Now the life would be pretty straightforward and we would not need to study optimisation if we worked just with single numbers, i.e. in $\\mathbb{R}$. We need to scale.\n%\n\\subsection{Euclidean Space \\texorpdfstring{$\\mathbb{R}^n$}{Rn}}\n\\par We will mostly use function that operate on vectors not numbers. We need to define the space in which these vectors have some meaning. We thus define the \\textbf{Euclidean Space} as the Cartesian product of $n$ one dimensional spaces $\\mathbb{R}$:\n\\begin{equation}\n    \\mathbb{R}^n = \\underbrace{\\mathbb{R} \\times ... \\times \\mathbb{R}}_{n\\ \\text{times}}\n    \\label{eq:euclidean_space}\n\\end{equation}\nThe elements of this space are vectors of $n$ components, i.e. $x \\in \\mathbb{R}^n = [x_1, ..., x_n]$.\\\\[5px]\n\\underline{\\textbf{Note}}: during this book we will always assume to work with \\textbf{column vectors}. When we use \\textbf{row vectors} we will use the transposition sign.\\\\[5px]\n\\par The Euclidean space is \\textbf{closed} under summation and scalar multiplication. This means that whenever we take two vectors and we sum them, or we take a constant $\\alpha$ and we multiply all the components of a vector with $\\alpha$, we will always get a new vector that is for sure still in our Euclidean space.\n\\par The Euclidean space is a \\textbf{finite} vector space: this means that each $x \\in \\mathbb{R}^n$ can be obtained from a \\textbf{finite basis}. A basis is a set of vectors such that for whatever vector $x$ in the space, we can somehow linearly combine the vectors from the basis to obtain $x$. Linearly combine means summations and scalar multiplications.\n\\par The Euclidean space is \\textit{not a totally ordered set}. We do not have a natural concept of which one comes first.\n\\par Since we will work a lot with distances we also need to define the concept of distance in this space. Before talking about the distance we need to introduce a very important concept that we will use constantly. \\textbf{The norm}. We define Euclidean norm as:\n\\begin{equation}\n    \\lVert x \\rVert = \\sqrt{\\sum_{i=1}^n x_i^2}\n    \\label{eq:2norm_def}\n\\end{equation}\nSome of the properties of the Euclidean norm are:\n\\begin{itemize}\n    \\item $\\lVert x \\rVert \\geq 0$ $\\forall x \\in \\mathbb{R}^n$ with 0 only in case that $x$ is the zero vector\n    \\item $\\lVert \\alpha x \\rVert = |\\alpha| \\lVert x \\rVert$ $\\forall x \\in \\mathbb{R}^n$ $\\forall \\alpha \\in \\mathbb{R}$\n    \\item $\\lVert x+y \\rVert \\leq \\lVert x \\rVert + \\lVert y \\rVert$ $\\forall x,y \\in \\mathbb{R}^n$. This property is called \\textbf{triangular inequality}.\n\\end{itemize}\nThe norm function is nothing more than a simple function that maps vectors to numbers (also matrices to numbers). Apart from the norm we have defined in the equation \\ref{eq:2norm_def}, we have also:\n\\begin{itemize}\n    \\item 0-norm $\\lVert . \\rVert_0 = |i : |x_i| > 0|$, i.e. the cardinality of the set of all non zero components in the vector $x$\n    \\item 1-norm $\\lVert . \\rVert_1 = \\sum_{i=1}^n |x_i|$\n    \\item $\\infty$-norm $\\lVert . \\rVert_\\infty = \\max_{i \\in I}\\{|x_i|\\}$\n\\end{itemize}\nAll these norms (including 2-norm) are the special cases of the unique definition of the p-norm:\n\\begin{equation}\n    \\lVert x \\rVert_p = \\Big(\\sum_{i=1}^n |x_i|^p\\Big)^{\\frac{1}{p}}\n    \\label{eq:p_norm}\n\\end{equation}\nIn figure \\ref{fig:norms} we show how the function of the norm changes as we augment $p$. Note that for $p \\geq 1$ we have a convex function while for $p < 1$ we have a concave function.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/1/1-norms.png}\n    \\caption{The various types of norms}\n    \\label{fig:norms}\n\\end{figure}\n\\par It is not very important which norm we are using since all of them are topologically equivalent. This means that whatever two norms we choose, there is a simple linear relation between them:\n\\begin{equation}\n    \\forall\\ \\lVert . \\rVert_x, \\lVert . \\rVert_y\\ \\exists\\ 0 < \\alpha < \\beta : \\alpha \\lVert . \\rVert_y \\leq \\lVert . \\rVert_x \\leq \\beta \\lVert . \\rVert_y\n    \\label{eq:norm_equivalence}\n\\end{equation}\nAccordingly, we are free to work with whatever norm. We will generally use the two norm, unless stated otherwise.\n\\par Another concept we have to introduce before defining the distance in the Euclidean space is the \\textbf{scalar product} between two vectors. We define the scalar product as:\n\\begin{equation}\n    \\langle x,y \\rangle = y^{T}x = \\sum_{i=1}^n = x_i y_i\n    \\label{eq:scalar_product}\n\\end{equation}\nLike the norm function, the scalar product is a simple function that takes two vectors and returns the value, i.e. $\\langle.\\rangle : \\mathbb{R}^n \\times \\mathbb{R}^n \\rightarrow \\mathbb{R}$. It satisfies the following properties ($\\forall\\ x,y,z \\in \\mathbb{R}^n, \\forall\\ \\alpha \\in \\mathbb{R}$):\n\\begin{itemize}\n    \\item $\\langle x, y \\rangle = \\langle y, x \\rangle$ (symmetry)\n    \\item $\\langle x, y \\rangle \\geq 0$\n    \\item $\\langle x, x \\rangle = 0 \\iff x = 0$\n    \\item $\\langle \\alpha x, y \\rangle = \\alpha \\langle x, y \\rangle$\n    \\item $\\langle x + y, z \\rangle = \\langle x, z \\rangle + \\langle y, z \\rangle$\n    \\item $\\langle x, x \\rangle = \\lVert x \\rVert^2$ (only for $\\lVert . \\rVert_2$)\n    \\item $\\langle x, y \\rangle^2 \\leq \\langle x, x \\rangle \\langle y, y \\rangle = \\lVert x \\rVert^2 \\lVert y \\rVert^2$. This is a very important property and it is called \\textbf{Cauchy-Schwarz inequality}\n\\end{itemize}\nThe scalar product have another definition, the one that uses the cosine function:\n\\begin{equation}\n    \\langle x,y \\rangle = \\lVert x \\rVert \\lVert y \\rVert \\cos \\theta\n    \\label{eq:scalar_product_cos}\n\\end{equation}\nFrom this definition it is clear that when two vectors are perpendicular to each other then the scalar product is 0 (figure \\ref{fig:scalar}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/1/2-scalar.png}\n    \\caption{Angle $\\theta$ between $x$ and $y$}\n    \\label{fig:scalar}\n\\end{figure}\nWhen the two vectors point to the same direction then the scalar product is $> 0$. Cosine of an angle that is between 0 and $\\frac{\\pi}{2}$ is positive, thus the scalar product is positive (the norms are always $\\geq 0$). This will be very useful when we will speak about various descent methods for unconstrained optimisation.\n\\par We are now ready to introduce the \\textbf{Euclidean distance}. The Euclidean distance between $x \\in \\mathbb{R}^n$ and $y \\in \\mathbb{R}^n$ is defined as:\n\\begin{equation}\n    d(x,y) = \\lVert x - y \\rVert = \\sqrt{\\sum_{i=1}^n(x_i - y_i)^2}\n    \\label{eq:euclidean_distance}\n\\end{equation}\nThe euclidean distance satisfies the following properties ($\\forall\\ x,y,z \\in \\mathbb{R}^n$ and $\\forall\\ \\alpha \\in \\mathbb{R}$):\n\\begin{itemize}\n    \\item The distance between two vectors is always $\\geq 0$: $d(x,y) \\geq 0$\n    \\item $d(\\alpha x, y) = |\\alpha|d(x,y)$\n    \\item $d(x,y) \\leq d(x,z) + d(z,y)$ (triangular inequality)\n\\end{itemize}\nSo the distance between two vectors is given by the norm of the vector difference between them.\n\\par We concept of Euclidean distance is useful for defining a very important mathematical object in optimisation.\n%\n\\subsection{Ball, Interior, Boundary and Bounded sets}\n\\begin{definition}\n    Given a centre $x \\in \\mathbb{R}^n$ and a radius $r > 0 \\in \\mathbb{R}$, we call \\textbf{Ball}:\n    \\[\n        \\mathcal{B}(x,r) = \\{y \\in \\mathbb{R}^n : d(x,y) \\leq r\\}\n    \\]\n    \\label{def:ball}\n\\end{definition}\nHaving these new mathematical objects, we can restate the concepts of converging sequences as:\n\\[\n    \\{x_i\\}_{i \\rightarrow \\infty} \\rightarrow x \\iff \\forall\\epsilon > 0\\ \\exists h : d(x_i,x) \\leq \\epsilon\\ \\forall i \\geq h\n\\]\nor\n\\[\n    \\{x_i\\}_{i \\rightarrow \\infty} \\rightarrow x \\iff \\forall\\epsilon > 0\\ \\exists h : x_i \\in \\mathcal{B}(x,\\epsilon)\\ \\forall i \\geq h\n\\]\nor even\n\\[\n    \\lim_{i \\rightarrow \\infty} d(x_i,x) = 0\n\\]\nWhy we are so interested in these sequences of points? Because if we consider the optimisation problem again:\n\\[\n    f_{*} = \\min_{x \\in \\mathcal{X}}\\ \\{f(x)\\}\n\\]\nwe want to construct the so called \\textit{minimising sequence} $\\{x_i\\}_{i \\rightarrow \\infty}$ such that $\\{f(x_i)_{i \\rightarrow \\infty}\\} \\rightarrow f_{*}$.\\\\\nNote again (again, yes) that $\\{f(x_i)_{i \\rightarrow \\infty}\\} \\rightarrow f_{*} \\centernot\\Rightarrow \\{x_i\\}_{i \\rightarrow \\infty} \\rightarrow x_{*}$. These are two different problems.\n\\par It is not sufficient to just solve analytically a problem. Consider for instance the following problem:\n\\[\n    \\min \\{x : x \\in \\mathbb{R}^n \\wedge x > 0\\}\n\\]\nThe optimal solution $f_{*}$ is infinitely close to 0 but cannot be reached by the sequence $\\{x_i = \\frac{1}{i}\\}_{i \\rightarrow \\infty}$ ($\\{f(x_i)_{i \\rightarrow \\infty}\\} \\rightarrow 0$). What can we do in order to avoid this situation. Generally we cannot. What we can do, as we will see during this book, is to require certain properties on the set or functions on which we optimise in order to guarantee that certain situations can never happen.\n\\begin{definition}\n    Given $\\mathcal{S} \\subseteq \\mathbb{R}^n$ we define:\n    \\begin{align}\n        &\\text{interior of $\\mathcal{S}$} \\equiv \\text{int}(\\mathcal{S}) = \\{x : x \\in \\mathcal{S} \\wedge \\exists r > 0 : \\mathcal{B}(x,r) \\subseteq \\mathcal{S}\\}\\\\\n        &\\text{boundary of $\\mathcal{S}$} \\equiv \\partial(\\mathcal{S}) = \\{x : \\forall r \\exists y,z \\in \\mathcal{B}(x,r) : y \\in \\mathcal{S} \\wedge z \\centernot \\in \\mathcal{S}\\}\n    \\end{align}\n\\end{definition}\n\\begin{definition}\n    The set $\\mathcal{S}$ is said to be open $\\iff \\mathcal{S} = \\textit{int}(\\mathcal{S})$.\n\\end{definition}\n\\begin{definition}\n    The set $\\mathcal{S}$ is said to be closed $\\iff \\mathcal{S} = \\textit{int}(\\mathcal{S}) \\cup \\partial \\mathcal{S}$. Or equivalently if $\\mathbb{R}^n \\setminus \\mathcal{S}$ is open set.\n\\end{definition}\nThe union of $\\textit{int}(\\mathcal{S}) \\cup \\partial \\mathcal{S}$ is called \\textit{closure} of the set $\\mathcal{S}$.\\\\[5px]\n\\textbf{Exercise}: Prove that both $\\mathbb{R}^n$ and $\\emptyset$ are both open and closed.\\\\\nLet us start from the easiest one: empty set. In order to be open its interior should be equal to itself. The interior of an empty set is empty, thus they are equal. In order to be a closed set, it should be equal to the union of its interior and its boundary. But both of these are empty sets, thus the union is an empty set again.\\\\\nNow consider the case of $\\mathbb{R}^n$. This set does not have a boundary, $\\partial(\\mathbb{R}^n) = \\emptyset$. Thus it is equal to its interior. Thus it is open. The union of its interior and an empty set is equal to its interior. Thus it is also closed.\\\\[3px]\n\\textbf{Exercise}: Exhibit a set that is neither closed nor open.\\\\\nTODO\n\\par The concept of the minimising sequences and closed sets can be connected by the following property:\n\\begin{theorem}\n    S is closed $\\iff \\forall \\{x_i\\} \\subset S \\rightarrow x \\Rightarrow x \\in S$\n\\end{theorem}\nThis basically means that $S$ is closed if and only if all accumulation points of sequences in $S$ are in $S$.\n\\par Suppose we have an infinite sequence of sets $\\{S_i\\}_{i \\rightarrow \\infty}$. If the sets are all open, then their union is also an open set.\n\\begin{equation}\n    \\cup_{i \\in I} S_i\\ \\text{is open}\n\\end{equation}\nOn the other hand, if the sets are all closed, then their intersection is also closed.\n\\begin{equation}\n    \\cap_{i \\in I} S_i\\ \\text{is closed}\n\\end{equation}\nNote that the union of an infinite family of closed sets is not necessarily a closed set and that the intersection of an infinite family of open sets is not necessarily an open set. As a counterexample, suppose we define a family of open sets in the following manner:\n\\begin{equation}\n    D_i = \\mathcal{B}(x_0, \\frac{1}{i})\\ i \\in \\mathbb{N}-\\{0\\}\n\\end{equation}\nThen the intersection of these sets tends to a set with only one point (0), which is obviously not an open set. The same reasoning can be applied to the union of a family of closed sets.\n\\par Another important concept when talking about balls and sets, is the concept of a \\textbf{Bounded set}.\n\\begin{definition}\n    $S \\subseteq \\mathbb{R}^n$ is called Bounded if $\\exists r > 0 : S \\subseteq \\mathcal{B}(0,r)$.\n\\end{definition}\nThis translates into: $S$ is a Bounded set if we can choose a radius $r$ strictly greater than 0 such that we can create a ball with centre in 0 so that it fully contains the whole $S$.\n\\begin{definition}\n    If a set $S$ is both closed and bounded, it is called \\textbf{Compact}.\n\\end{definition}\n%\n\\subsection{Bolzano-Weierstrass Theorem}\nTODO BETTER\n\\par Before announcing this important theorem, we need to introduce the concept of subsequence.\n\\begin{definition}\n    Given a sequence of points $\\{x_i\\} \\in \\mathbb{R}^n$ and a sequence of indexes $\\{n_i\\} \\in \\mathbb{N}$, the sequence $\\{x_{n_i}\\} \\subseteq \\{x_i\\}$ is called a subsequence.\n\\end{definition}\nThe \\textbf{Bolzano–Weierstrass theorem}, named after Bernard Bolzano and Karl Weierstrass, is a fundamental result about convergence in a finite-dimensional Euclidean space $\\mathbb{R}^n$. The theorem states that each bounded sequence in $\\mathbb{R}^n$ has a convergent subsequence. An equivalent formulation is that a subset of $\\mathbb{R}^n$ is sequentially compact if and only if it is closed and bounded. The theorem is sometimes called the sequential compactness theorem.\n%\n\\subsection{Functions}\n\\par Remember that our problem is to minimise functions (equation \\ref{eq:opt_problem_def}). As we can see, we have two mathematical objects in this equation: the set $\\mathcal{X}$ and the function $f$. Up until now we have discussed about sets and the properties we would like to have on them in order to make our life simpler. Now we need to do the same thing with the functions.\n\\par Note that the functions live in a different space ($\\mathbb{R}^{n+1}$) w.r.t. their inputs ($\\mathbb{R}^n$). Nevertheless, sometimes we'd like to see how sequences of the functional values behave in the input space. To this end there is a concept of \\textbf{level sets} and \\textbf{sublevel sets}.\n\\begin{definition}\n    The set $L(f,v) = \\{x \\in \\text{dom}(f) : f(x) = v\\}$ is called level set of the function $f$ and level $v$ (figure \\ref{fig:levelsets}).\n\\end{definition}\n\\begin{definition}\n    The set $S(f,v) = \\{x \\in \\text{dom}(f) : f(x) \\leq v\\}$ is called sublevel set of the function $f$ and level $v$ (figure \\ref{fig:sublevelsets}).\n\\end{definition}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/1/3-levelsets.png}\n    \\caption{Level set}\n    \\label{fig:levelsets}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/1/4-sublevelsets.png}\n    \\caption{Sublevel set}\n    \\label{fig:sublevelsets}\n\\end{figure}\n\\par In case that $f$ is unbounded below, we cannot actually talk about sublevel sets. We can reverse the concept and talk about superlevel sets.\n%\n\\par The first property that we'd like that our functions that we minimise have is continuity.\n\\begin{definition}\n    $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}$ is continuous in $x \\in \\mathbb{R}^n$ if\n    \\begin{itemize}\n        \\item $\\{x_i\\} \\rightarrow x \\Rightarrow \\{f(x_i) \\rightarrow f(x)\\}$\n        \\item $\\forall \\epsilon > 0\\ \\exists \\delta > 0 : |f(y) - f(x)| < \\epsilon\\ \\forall y \\in \\mathcal{B}(x,\\delta)$\n    \\end{itemize}\n\\end{definition}\nWe say that $f$ is continuous on a set $S \\subseteq \\mathbb{R}^n$ if it is continuous on each $x \\in S$.\n\\begin{theorem}[Intermediate Value Theorem]\n    Suppose we have function $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ continuous on a closed interval $[a,b]$. Then:\n    \\[\n        \\forall v : \\min \\{f(a),f(b)\\} \\leq v \\leq \\max \\{f(a),f(b)\\}\\ \\exists c \\in [a,b] : f(c) = v\n    \\]\n\\end{theorem}\nAll the considerations pointed out so far bring us to the Weistrass extreme value theorem. This theorem is one of the most important in optimisation.\n\\begin{theorem}[Weistrass Extreme Value Theorem]\nSuppose we have a set $X \\subseteq \\mathbb{R}^n$ compact and a function $f$ that is continuous, then the minimising problem has an optimal solution.\n\\end{theorem}\nFrom this statement, this theorem doesn't seem to be so meaningful. But, if we exploit a little bit some of the considerations explained so far, we can say that this statement is equivalent to say that: if our set is closed and our function continuous, then all the accumulation points of any minimising sequence are optimal solutions and there is at least one of them.\nUp until now, we have understand that having a continuous function is a really great thing and for this reason, in a lot of the methods we'll consider, the basic assumptions will be: a compact set and a continuous function.\nBut, if we are really lucky, we can ask for more. More we have, simpler it is to gain better results.\nTalking about continuity, a more strict version of it is Lipschitz continuity.\n\\begin{theorem}[Lipschitz continuity]\n\\[\n    \\exists L > 0 \\quad \\forall x,y \\in X : |f(x) - f(y)| \\leq L \\lVert x - y \\rVert \n\\]\n\\end{theorem}\nSince this is a stronger definition of continuity, all the considerations said so far for the continuity case are still true. Moreover, with L continuity, we know that our function doesn't jump wildly. This is a very good result, but unfortunately, a lot of functions are not L continuous. If this is the case, we could see if our function is lower semi continuous (or upper).\n%\n\\par Now, we have to remember our main task: find the minimum of an iterative sequence. For simplicity, we focus our attention on functions in two dimensions. We know that a derivative gives us a linear approximation of the function in that point. So, if I compute the derivative in $x$, in which way of the linear approximation ($f'(x)$) should I go? Of course, we have to go where the line decrease: if the slope of my line is greater than zero, I have to go left, otherwise right. I can stop to iterate when I find $f'(x)=0$ (since I know that in this case we are on a saddle point or a max or min).\n\\par The saddest part of it is that not all the function have a first derivative and that even if they have it, it may be the case that it isn't continuous. In order to understand when a function is differentiable or not, the definition of derivative is necessary: TODO\n\n\n\n\\subsection{Useful results about derivatives}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{figures/1/chapter1-mean_value_theorem1.png}\n    \\caption{A differentiable function $f(x)$ and two points $a$ and $b$.}\n    \\label{fig:chapter1-mean_value_theorem1}\n\\end{figure}\n\\par Suppose you have a differentiable function like in figure \\ref{fig:chapter1-mean_value_theorem1}, with two points and a line connecting those two points. Then according to the \\textbf{mean value theorem} we have the following:\n\\begin{theorem}\n    Given a function $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ continuous on $[a,b]$ and differentiable on $(a,b)$ then there exists a point $c \\in (a,b)$ such that the slope of the derivative in point $c$ is the same of the slope of the line connecting $a$ and $b$. In other words:\n    \\[\n        f'(c) = \\frac{f(b)-f(a)}{b-a} = m\n    \\]\n    where $m$ is the usual slope of a line.\n\\end{theorem}\nWhy do we care about this simple theorem? Because there is a special case of it, namely when $f(a) = f(b)$. This takes the name of \\textbf{Rolle's theorem} (see figure \\ref{fig:chapter1-rolles_theorem1}) and it says:\n\\begin{theorem}\n    Given a function $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ continuous on $[a,b]$ and differentiable on $(a,b)$, if $f(a) = f(b)$ then there exists a point $c \\in (a,b)$ such that the slope of the derivative in point $c$ equals 0.\n\\end{theorem}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{figures/1/chapter1-rolles_theorem1.png}\n    \\caption{Rolle's theorem.}\n    \\label{fig:chapter1-rolles_theorem1}\n\\end{figure}\nThis theorem assures us that if $f(a) = f(b)$ in the middle there must me at least one local minimum or maximum, or both.\n\\par Actually, we can even state that between two consecutive roots of $f$ there is an odd number of roots of the derivative $f'$ in the range of $(a,b)$. If $a$ and $b$ are two consecutive roots of $f$ then the sign of their derivatives are opposite to each other.\n\\par \\textit{Exercise}. Prove that between two consecutive roots of $f'$ there is at most one root of $f$.\n\\par Suppose $a$ and $b$ are two consecutive roots of $f'$. Suppose now by contradiction that there are two different points $c,d \\in (a,b)$ that are also the roots of $f$. According to Rolle's theorem, there must exist at least one point $e \\in (c,d)$ such that $f'(e)=0$. This contradicts the fact that $a$ and $b$ are two consecutive roots of $f'$.\n\n\\subsection{A different interpretation of the gradient}\n\\par Remember that the function is a mathematical object that lives in $\\mathbb{R}^{n+1}$. The gradient is the linear function approximating $f$ in a point. Thus, the gradient it self lives again in $\\mathbb{R}^{n+1}$. It is important also to look at it from the input space, i.e. in $\\mathbb{R}^n$. We can do that via level sets again.\n\\par The gradient turns out to be \\textit{normal} to the level sets. In other words, it is tangent to the level set.\n\\subsection{Vector valued function}", "meta": {"hexsha": "c3d12493bf74e40ce5236136e70f5af09a8a1faa", "size": 25321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/1-introduction.tex", "max_stars_repo_name": "ig92/CM4LDA", "max_stars_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/1-introduction.tex", "max_issues_repo_name": "ig92/CM4LDA", "max_issues_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/1-introduction.tex", "max_forks_repo_name": "ig92/CM4LDA", "max_forks_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.4180064309, "max_line_length": 602, "alphanum_fraction": 0.7147032108, "num_tokens": 7521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681086260461, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6910456049951514}}
{"text": "\\subsection{Tangent Planes}\r\n\\noindent\r\nAlthough the tangent lines at a point on a surface can all be different depending on the direction one approaches a point from, all of these tangent lines lie in the same plane, defining the tangent plane. This means that the tangent plane to $z = f(x_0, y_0)$ has the following properties:\r\n\\begin{itemize}\r\n\t\\item The z-value of the tangent plane at $(x_0, y_0)$ is the same as $f(x_0, y_0)$.\r\n\t\\item The value of the first-order partial derivatives of the tangent plane at $(x_0, y_0)$ should match those of $f(x_0, y_0)$.\r\n\\end{itemize}\r\n\r\n\\noindent\r\nThe general form of a plane at $(x_0, y_0, z_0)$ is $P(x,y) = A(x-x_0) + B(y-y_0) + z_0$.\\\\ \r\nWe want $P_x = f_x$ and $P_y = f_y$.\\\\\r\nThis means that $P_x = f_x = A$ and $P_y = f_y = B$.\\\\\r\nRewriting, $P(x,y) = f_x(x-x0) + f_y(y-y_0) + z_0$.\\\\\r\nThe normal vector is $\\langle \\pm f_x,\\pm f_y, \\mp 1\\rangle$.\\\\\r\nSo, the point normal form of the plane is \r\n\\begin{equation*}\r\n\t\\langle -f_x, -f_y, 1\\rangle \\cdot \\langle x-x_0, y-y_0, z-f(x_0,y_0) \\rangle = 0\r\n\\end{equation*}\r\n\r\n[INSERT IMAGE]\r\n", "meta": {"hexsha": "bc9f14eed498b79609f1dc550b3a47fbb9b0c9f8", "size": 1087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/tangentPlanes.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/tangentPlanes.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/tangentPlanes.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.7619047619, "max_line_length": 291, "alphanum_fraction": 0.6734130635, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.691045584344551}}
{"text": "\\section{Background}\n\n\\subsection{Theory}\n\nData collected via magnetic resonance (MR) imaging is inherently complex-valued, containing both real and imaginary (or equivalently, phase and magnitude) components (Figure~\\ref{fig:Complex_Plane}).  Phase data is useful in a variety of applications, such as harmonic phase (HARP) analysis of tagged MR \\cite{Osman1999}, susceptibility weighted imaging (SWI) \\cite{Li2011}, and phase contrast angiography/venography .  Although phase at a given pixel can generally take on any value, it is impossible to distinguish between true ($\\phi$) and principal ($\\hat{\\phi}$) phase values separated by an arbitrary multiple $k$ of $2\\pi$, such that the measured phase value is `wrapped' within the range $(-\\pi, \\pi]$.  In theory, true phase may be recovered from principle phase by adding an integer multiple $k$ of $2\\pi$, in a process known as `unwrapping' (Equation~\\ref{eqn:PrinciplePhase}).\n\n\\begin{equation}\n\\label{eqn:PrinciplePhase}\n\\phi = \\hat{ \\phi } + k2\\pi\n\\end{equation}\n\n\\begin{figure}[h] % h indicates inline\n\\center\n\\begin{tikzpicture}[scale=2.5]\n\\draw [very thin, lightgray] (0,0) circle [radius=1]; % circle\n\\draw [<->, black] (-1.2,0) -- (1.2,0); % imaginary\n\\draw [<->, black] (0,-1.2) -- (0,1.2); % real\n\\draw [->, thick, gray] (0.7071,0) -- (0.7071,0.7071); % b\n\\draw [->, thick, gray] (0,0) -- (0.7071, 0); % a\n\\draw [->, very thick, teal] (0,0) -- (0.7071,0.7071); % R\n\\node [above right] at (0.2,0) {$\\hat{\\phi}$};\n\\node [below] at (0.3535, 0) {$a$};\n\\node [right] at (0.7071, 0.3535) {$b$};\n\\node [above left] at (0.3535, 0.3535) {$R$};\n\\node [right] at (1.2, 0) {Real};\n\\node [above] at (0, 1.2) {Imaginary};\n\\end{tikzpicture}\n\\itkcaption[Complex_Plane]{The Complex Plane.  Here a complex number, $z$, is represented as a point on the complex plane.  $z$ can be represented equivalently in cartesian coordinates as the sum of a real and an imaginary number ($z = a+bi$) or in polar coordinates as a magnitude phase pair ($[R,\\phi]$).}\n\\label{fig:Complex_Plane}\n\\end{figure}\n\nThe reverse operation, by which principle phase is obtained from its true phase, is denoted by the wrapping operator $W{}$ (Equation~\\ref{eqn:Wrapping_Operator}), which can be practically implimented with the four-quadrant arctangent function (\\code{std::atan2(x,y)}).\n\n\\begin{equation}\n\\label{eqn:Wrapping_Operator}\n\\hat{\\phi} = \\arctan( \\sin( \\phi ), \\cos( \\phi )) \\equiv W \\left\\{ \\phi \\right\\}\n\\end{equation}\n\nItoh \\cite{Itoh1982} observed that the locally `corrected' phase gradient (i.e., the phase gradient after appropriate addition of $k2\\pi$ such that the difference between adjacent pixels is in the range $(-\\pi,\\pi]$) may be written in terms of the wrapping operator (Equation~\\ref{eqn:Wrapped_Phase_Gradient}).\\footnote{$i$ is used in this submission both to refer to the mathematical constant meaning $\\sqrt{-1}$, as previously, and, in this context, to pixel index along an arbitrary dimension ($0 < i < M-1$, where M is the number of pixels along that dimension).  The difference in usage should be clear from context.  Note also that the above definition only applies when both $i$ and $i-1$ are completely within the image; otherwise, $\\Delta \\phi_i \\equiv 0$.}\n\n\\begin{equation}\n\\label{eqn:Wrapped_Phase_Gradient}\n\\Delta \\phi_{i} \\equiv W \\left \\{ \\hat{\\phi_{i}} - \\phi_{i-1} \\right \\}\n\\end{equation}\n\nA target pixel ($\\phi_{i}$) may be `unwrapped' relative to an adjacent reference pixel ($\\phi_{i-1}$) such that their difference is in the range $(-\\pi, \\pi]$.  This operation can be written in terms of the wrapped phase gradient (Equation~\\ref{eqn:Binary_Unwrap}).\n\n\\begin{equation}\n\\label{eqn:Binary_Unwrap}\n\\phi_{i} = \\phi_{i-1} + \\Delta \\phi_{i}\n\\end{equation}\n\n\\subsection{Introduction to the ITKPhase Module}\n\nThe presented module provides the unary wrap operator as a functor, \\code{itk::Functor::WrapPhaseFunctor} (defined in \\code{itkWrapPhaseFunctor.h}).  The following snippet demonstrates the basic use of the class.\\footnote{The constant \\code{vnl\\_math::pi} is defined in the \\code{vnl/vnl\\_math.h} header file. \\code{std::cout} and \\code{std::endl} are defined in the \\code{<iostream>} header file.}\n\n\\small\n\\begin{verbatim}\n  itk::Functor::WrapPhaseFunctor< double > wrapFunc;\n\n  std::cout << wrapFunc( 3 ) << std::endl; // 3\n  std::cout << wrapFunc( 0 ) << std::endl; // 0\n  std::cout << wrapFunc( -3 ) << std::endl; // -3\n  std::cout << wrapFunc( 1 + vnl_math::pi ) << std::endl; // -2.14159\n  std::cout << wrapFunc( -vnl_math::pi - 1 ) << std::endl; // 2.14159\n\\end{verbatim}\n\\normalsize\n\n\\code{itk::PhaseImageToImageFilter} (defined in \\code{itkPhaseImageToImageFilter.h}) inherits from \\doxygen{ImageToImageFilter} and serves as the base class for most classes in this module.\n\nThis class provides two methods, \\code{Wrap(pixel)} and \\code{Unwrap(target,relativeToReference)}.  The first takes one argument and provides an interface to \\code{WrapPhaseFunctor} (see Equation~\\ref{eqn:Wrapping_Operator}).  The second makes use of the first to unwrap one pixel relative to another (see Equation~\\ref{eqn:Binary_Unwrap}).\n\n\\begin{figure}[h]\n\\center\n\n\\includegraphics[width=0.24\\textwidth]{images/2/00a_ramp_wrapped.png}\n\\includegraphics[width=0.24\\textwidth]{images/2/00b_ramp_unwrapped.png}\n\\includegraphics[width=0.24\\textwidth]{images/2/00c_noise_wrapped.png}\n\\includegraphics[width=0.24\\textwidth]{images/2/00d_noise_unwrapped.png}\n\n\\itkcaption[Simulated_Phase_Examples]{Simulated phase images, created by the \\code{itk::PhaseExamplesImageSource} class.  Wrapped phase ramp (far left); wrapped phase ramp with noise patch (center left); unwrapped phase ramp (center right); unwrapped phase ramp with noise patch (far right).}\n\\label{fig:Simulated_Phase_Examples}\n\\end{figure}\n\nFor convenience, the ITKPhase module also includes \\code{itk::PhaseExamplesImageSource} (defined in \\code{itkPhaseExamplesImageSource.h}), which provides simple simulated phase examples for demonstrating the functionality of the module's classes.\n\nBy default, the class outputs a simple, wrapped phase ramp (Figure~\\ref{fig:Simulated_Phase_Examples}, far left).\\footnote{For visualization purposes, all images have been rescaled prior to writing to png.}\n\n\\small\n\\begin{verbatim}\n  typedef itk::PhaseExamplesImageSource< WorkImageType > ExampleType;\n  ExampleType::Pointer phase = ExampleType::New();\n  phase->Update();\n\\end{verbatim}\n\\normalsize\n\nA patch of additive gaussian noise can be added by calling \\code{phase->SetNoise(true)} (Figure~\\ref{fig:Simulated_Phase_Examples}, center right), and unwrapped versions of these images can be obtained by calling \\code{phase->SetWrap(false)} (Figure~\\ref{fig:Simulated_Phase_Examples}, center left and far right, respectively).  Though not demonstrated in this submission, the mean, standard deviation, and seed of the noise can be manually set using the \\code{SetNoiseMean()}, \\code{SetNoiseSD()}, and \\code{SetNoiseSeed()} methods.\n", "meta": {"hexsha": "a30fe65e196f09d5f19c524576e9ef785d31b655", "size": 6941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Document/includes/Background.tex", "max_stars_repo_name": "DVigneault/ITKPhaseSubmission", "max_stars_repo_head_hexsha": "4f52c134102139544a63d454501983f00c3ade67", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-07T03:59:18.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-07T03:59:18.000Z", "max_issues_repo_path": "Document/includes/Background.tex", "max_issues_repo_name": "DVigneault/ITKPhaseSubmission", "max_issues_repo_head_hexsha": "4f52c134102139544a63d454501983f00c3ade67", "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": "Document/includes/Background.tex", "max_forks_repo_name": "DVigneault/ITKPhaseSubmission", "max_forks_repo_head_hexsha": "4f52c134102139544a63d454501983f00c3ade67", "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": 70.8265306122, "max_line_length": 888, "alphanum_fraction": 0.737213658, "num_tokens": 2074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.85776809953619, "lm_q1q2_score": 0.6910455836617138}}
{"text": "\\chapter{Gravity and Geometry}\nThe observable universe is stable. There are two obvious configurations in which this is possible:\n\\begin{enumerate}\n    \\item Static universe, masses are arranged in a grid, all nett forces cancel.\n    However small fluctuations cause the system to collapse therefore this is\n    no possible description for the universe. \n%TODO picture\n    \\item Expanding universe, all masses move away from each other, overcoming the gravitational attraction.\n    Theoretically such a system can be described by using Newtonian Physics introducing additional energy contributions.\n    This turns out to be inconsistent.\n\\end{enumerate}\nSince in the second description all particles are accelerated relative to each other, there are no inertial systems.\nA theory in which all observers are equal must therefore be local and thus be described by means of differential geometry.\nWe claim that the laws of physics are the same in every system.\nIf we assume that the \\name{Maxwell}'s equations are right, the\nNewtonian theory of gravity must be wrong.\nImplications:\nAll free falling systems are equivalent (i.e. indistinguishable by the observer).\nLight must bend, otherwise a beam could be used to deduce whether your system is inertial.\nThe following example illustrates that Euclidean geometry is no\nadequate description of space-time.\n\\begin{example}[Rotating Sphere]\nsee Introduction to tensor calculus\n%TODO copy or reference page\n\\end{example}\n\\section{Coordinate Systems}\nWe will start by studying coordinate systems in the flat space $\\Reals^2$, which\nshould be familiar.\n\\subsection*{Cartesian Coordinates}\nCartesian coordinates are described by two coordinates $x,y$ that are measured\nin two orthogonal directions from the origin. The distance $s$ between two\narbitrary points $(x_1,y_1)$ and $(x_2,y_2)$ can be calculated using\n\\name{Pythagoras}' theorem\n\\begin{equation}\n    s^2=(x_1-x_2)^2+(y_1-y_2)^2\\,.\n\\end{equation}\nAn infinitesimal distance is likewise given by\n\\begin{equation}\n    \\dif s^2=\\dif x^2+\\dif y^2\\,.  \\label{eq:cartline}\n\\end{equation}\n\\subsection*{Polar Coordinates}\nIf we describe a point in flat space by an angle $\\varphi$ and an distance $r$\nfrom the origin, we get polar coordinates. The conversion between the systems\nreads\n\\begin{equation}\n    x= r\\cos\\varphi\\quad y= r\\sin\\varphi\\,.\n\\end{equation}\nA infinitival change in the polar coordinates therefore results in \n\\begin{align}\n    \\dif x&= \\dpd{x}{r}\\dif r+\\dpd{x}{\\varphi}\\dif \\varphi = \\cos\\varphi\\dif\n    r-r\\sin\\varphi\\dif \\varphi\\,,\\\\\n    \\dif y&= \\dpd{x}{r}\\dif r+\\dpd{y}{\\varphi}\\dif \\varphi = \\sin\\varphi\\dif\n    r+r\\cos\\varphi\\dif \\varphi\\,.\n\\end{align}\nPlugging this into \\eqref{eq:cartline} gives the line element in polar coordinates\n\\begin{equation}\n    \\dif s^2=\\dif r^2+r^2\\dif \\varphi^2\n\\end{equation}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{cartcoord.pdf}\n \\includegraphics{polarcoord.pdf}\n\\caption{}\n%TODO Caption\n\\end{figure}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics[scale=0.75]{CoordinateGridCartesian.pdf}\\quad\n \\includegraphics[scale=0.75]{CoordinateGridPolar.pdf}\n\\caption{Coordinate grids.}\n%TODO Caption\n\\end{figure}\n\nIn matrix form\n\\begin{equation}\n\\dif s^2=\n\\begin{bmatrix}\n\\dif r& \\dif \\varphi\n\\end{bmatrix}\n\\begin{bmatrix}\n1& 0\\\\\n0& r^2\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n\\dif r\\\\ \\dif \\varphi\n\\end{bmatrix}\\, .\n\\end{equation}\nThe matrix\n\\begin{equation}\ng(\\vec{r})=\n\\begin{bmatrix}\n1& 0\\\\\n0& r^2\\\\\n\\end{bmatrix}\\, ,\n\\end{equation}\nis called the \\emph{metric}.\nIn general we have\n\\begin{equation}\n    \\dif s^2 = g_{ij}\\dif x^i\\dif x^j\\, .\n\\end{equation}\nThe idea is to keep the law of inertia, i.e. particles still move on straight\nline. However, we need to generalize the concept of a 'straight' line, in a\ncurved space.\n\\section{Variation Principle}\n\\label{sec:varprinc}\nWe know that straight lines are curves minimizing the distance between two\npoints. We generalize this concept to curved space by an variation principle.\nAgain we take a look at flat space, but with curved coordinates.\nThe length $S$ of a curve $\\gamma$ with $\\gamma^i(\\lambda) = x^i(\\lambda)$ is\ngiven by the integral\n\\begin{equation}\n    S=\\int_{\\gamma}\\sqrt{\\dif s^2} =\n    \\int_{\\gamma}\\sqrt{\\tensor{g}{_i_j}\\dif \\tensor{x}{^i}\\dif\n    \\tensor{x}{^j}}=\\int_{a}^{b}\\sqrt{\\tensor{g}{_i_j}\\dod{\\tensor{x}{^i}}{\\lambda}\n    \\dod{\\tensor{x}{^j}}{\\lambda}}\\dif \\lambda\\, .\n\\end{equation}\nAs stated above generalised straight lines satisfy $\\delta S = 0$. If we define\n$L:=\\left(\\tensor{g}{_i_j}\\od{\\tensor{x}{^i}}{\\lambda}\n\\od{\\tensor{x}{^j}}{\\lambda}\\right)^{\\nicefrac{1}{2}}$, $S$ takes a form\nfamiliar from classical mechanics:\n\\begin{equation}\n    S=\\int_a^b L\\dif \\lambda\\, .\n\\end{equation}\nThe extremal condition implies the Euler Lagrange equations\n\\begin{equation}\n    \\dod{}{\\lambda}\\pd{L}{\\left(\\pd{\\tensor{x}{^i}}{\\lambda}\\right)}\n    -\\pd{L}{\\tensor{x}{^i}}\n    =0\\, .\t\t\\end{equation}\nWe can calculate the relevant terms to \n\\begin{align}\n\\dpd{L}{\\tensor{x}{^i}}&=\\frac{1}{2\\sqrt{g_{ij}\\od{x^i}{\\lambda}\n\\od{x^j}{\\lambda}}}\\tensor{g}{_j_k_{,i}}\\dod{x^j}{\\lambda}\n\\dod{x^k}{\\lambda}\\,,\\\\\n\\dpd{L}{\\left(\\pd{\\tensor{x}{^i}}{\\lambda}\\right)}\n&=\\frac{1}{\\sqrt{g_{ij}\\od{x^i}{\\lambda}\n\\od{x^j}{\\lambda}}}\\tensor{g}{_j_i}\\dod{x^j}{\\lambda}\\, .\n\\end{align}\nIf we choose the parameter $\\lambda$ so that we are parametrised by the arc\nlength\\footnote{this is impossible for null i.e. lightlike geodesics, it can be\nshown however, that the resulting equation also holds true for null geodesics.}\ni.e.\n\\begin{equation}\n\\od{}{\\lambda}\\left(\\sqrt{g_{ij}\\od{x^i}{\\lambda}\\od{x^j}{\\lambda}}\\right)=0\\,,\n\\end{equation}\nthe Euler Lagrange equations simplify to\n\\begin{equation}\n0=\\frac{1}{\\sqrt{\\tensor{g}{_i_j}\\od{\\tensor{x}{^j}}{\\lambda}\n\\od{\\tensor{x}{^j}}{\\lambda}}}\\dod{}{\\lambda}\n\\left(\\tensor{g}{_j_i}\\dod{\\tensor{x}{^j}}{\\lambda}\\right)\n-\\frac{1}{2\\sqrt{\\tensor{g}{_i_j}\\od{x^i}{\\lambda}\n\\od{\\tensor{x}{^j}}{\\lambda}}}\\tensor{g}{_j_k_{,i}}\\dod{\\tensor{x}{^j}}{\\lambda}\n\\dod{\\tensor{x}{^k}}{\\lambda}\\,,\n\\end{equation}\nor equivalently\n\\begin{equation}\n\\begin{split}\n0\n&=\\dod{}{\\lambda}\\left(\\tensor{g}{_j_i}\\dod{\\tensor{x}{^j}}{\\lambda}\\right)\n-\\frac{1}{2}\\tensor{g}{_j_k_{,i}}\\dod{x^a}{\\lambda}\n\\dod{x^k}{\\lambda}\\\\\n&=\\tensor{g}{_j_i_{,k}}\\dod{\\tensor{x}{^j}}{\\lambda}\\dod{\\tensor{x}{^k}}{\\lambda}\n+\\tensor{g}{_j_i}\\dod[2]{\\tensor{x}{^j}}{\\lambda}\n-\\frac{1}{2}\\tensor{g}{_j_k_{,i}}\\dod{\\tensor{x}{^j}}{\\lambda}\\\\\n&=\\tensor{g}{_j_i}\\dod[2]{\\tensor{x}{^j}}{\\lambda}\n+\\frac{1}{2}\\left(\\tensor{g}{_j_i_{,k}}+\\tensor{g}{_i_j_{,k}}\n-\\tensor{g}{_j_k_{,i}}\\right)\\dod{\\tensor{x}{^j}}{\\lambda}\n\\dod{\\tensor{x}{^k}}{\\lambda}\\label{eq:PreGeo}\\,.\n\\end{split}\n\\end{equation}\nThe term invoking derivatives of the metric defines the \\emph{Christoffel\nsymbols of the first kind}\n\\begin{equation}\n    \\csym{j}{k}{i}:=\\frac{1}{2}\n    \\left(\\tensor{g}{_j_i_{,k}}+\\tensor{g}{_i_j_{,k}} -\\tensor{g}{_j_k_{,i}}\\right)\\, .\n\\end{equation}\nIt is convenient to multiply \\eqref{eq:PreGeo} by the inverse metric $g^{li}$ so\nthat we obtain the \\emph{geodesic equation}\n\\begin{equation}\n    0 =\n    \\od[2]{\\tensor{x}{^l}}{\\lambda}\n    +\\cSym{l}{j}{k}\\od{\\tensor{x}{^j}}{\\lambda}\\od{\\tensor{x}{^k}}{\\lambda}\\,\n    .\\label{eq:geodeq}\n\\end{equation}\nWhere $\\cSym{l}{j}{k}$ are the \\emph{Christoffel symbols of the second kind}\n\\begin{equation}\n    \\cSym{l}{j}{k}:=g^{li}\\csym{j}{k}{i}=\\frac{1}{2}g^{li}\n    \\left(\\tensor{g}{_j_i_{,k}}+\\tensor{g}{_i_j_{,k}} -\\tensor{g}{_j_k_{,i}}\\right)\\, .\n\\end{equation}\n% remark is obsolete as long as bracket notation for christoffel symbols is used\n%\\begin{remark}\n%Although the notation looks as the Christoffel symbols form a tensor, however\n% they do not.\n%\\end{remark}\nIn flat space we have $\\tensor{g}{_i_j}=\\tensor{\\eta}{_i_j}$ and can easily\ncheck that all Christoffel symbols vanish. We therefore recover the ordinary equation of motion for a free particle\n\\begin{equation}\n    0 = \\od[2]{\\tensor{x}{^i}}{\\lambda}\\, .\n\\end{equation}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{sphere_geodesics1.pdf}\n\\caption{Great circles are geodesics, i.e. shortest connections of points, on\na sphere.}\n%TODO Caption\n\\end{figure}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{WorldlineLightcones.pdf}\n\\caption{}\n%TODO Caption\n\\end{figure}\n\n\n% \\begin{example}\n% Suppose a observer follows a free falling body in a homogeneous field.\n% Therefore a transformation between the system of the earth and the one of the body are given by\n% (for simplicity we only consider the coordinate along it is falling)\n% \\begin{equation}\n%     (t,x)\\to\\left(t,x-\\frac{1}{2}gt^2\\right)\n% \\end{equation}\n% Analogous to the Riemannian case discussed before, the line element takes the form\n% \\begin{equation}\n%     \\begin{split}\n% \\dif s^2&=-\\dif t^2 +\\dif x^2\\\\\n% &=-\\dif t'^2+(\\dif x'- gt\\dif t')(\\dif x'- gt\\dif t')\\\\\n% &=(g^2t'^2-1)\\dif t'^2-2gt\\dif x'\\dif t'+\\dif x'^2\n% \\end{split}\n% \\end{equation}\n% \\end{example}\n% \\section{Newtonian Limit}\n", "meta": {"hexsha": "e53a857303e886e69fd01bd0b155045ecadfdf36", "size": 8964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/03-gravity-and-geometry.tex", "max_stars_repo_name": "Bigben37/GeneralRelativity", "max_stars_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-31T13:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T13:18:57.000Z", "max_issues_repo_path": "src/03-gravity-and-geometry.tex", "max_issues_repo_name": "QuantumDancer/GeneralRelativity", "max_issues_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/03-gravity-and-geometry.tex", "max_forks_repo_name": "QuantumDancer/GeneralRelativity", "max_forks_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8051948052, "max_line_length": 122, "alphanum_fraction": 0.7006916555, "num_tokens": 3001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6909845479137511}}
{"text": "\\section{Introduction}\nThis paper is a brief summary of differential algebra. We will discuss some introductory defintions and theorems and, later on, some examples. Basic knowledge of commutative algebra is required. We assume each ring $R$ to be commutative and unital. Furthermore, we omit subscripts where they can be inferred from context. The dual of an $R$ module $M$ is denoted by $M^*$.\n\\subsection{Basics}\nLet $R$ be a ring and $A$ an $R$ algebra, that is $A$ is an $R$ module with $R$ linear map\n$$\\mu : A \\otimes A \\longrightarrow A,\\ a \\otimes a' \\longmapsto a a'.$$\nWe denote an algebra $A$ with multiplication $m$ by $(A, \\mu)$. We call $A$ associative if\n$$\\xymatrix{\nA^{\\otimes 3} \\ar[r]^{\\mu \\otimes id_A} \\ar[d]_{id_A \\otimes \\mu} & A^{\\otimes 2}\\ar[d]^{\\mu}\\\\\nA^{\\otimes 2} \\ar[r]_{\\mu} &A\\\\\n}$$\ncommutes. We call a map $\\eta \\in \\mathrm{Hom}(R,A)$ unit map if\n$$\\xymatrix{\n&A^{\\otimes 2}\\ar[d]^\\mu&\\\\\nR \\otimes A \\ar[r]_{\\simeq}\\ar[ru]^{\\eta \\otimes id_A} &A&A \\otimes R \\ar[lu]_{id_A \\otimes \\eta}\\ar[l]^\\simeq\\\\\n}$$\ncommutes. In this case, we call $A$ a unital algebra over $R$ (denoted by $(A, \\mu, \\eta)$).\n\\subsubsection{Derivations}\n\\begin{defi}[Leibniz-rule]\nWe call a map $\\partial \\in \\mathrm{End}_R(A)$ an $R$ derivation if\n$$\\partial(a a') = \\partial(a) a' + a \\partial(a'),\\ \\forall a, a' \\in A.$$\nA unital (associative) algebra $(A, \\mu, \\eta)$ with derivation $\\partial$ is denoted by\n$$(A, \\mu, \\eta, \\partial).$$\nThe subset $B \\subset A$ with $\\partial(b) = 0$ for all $b \\in B$ is called the set of constants and is denoted by\n$$A^\\partial := \\{a \\in A : \\partial(a) = 0\\}.$$\n\\end{defi}\nFrom this definition we get\n\\begin{koro}\nLet $A$ and $A^\\partial$ be as above and let $A^\\times = \\{b \\in A : \\exists b' \\in A, b b' = 1_A\\} \\neq \\emptyset$.\n\\bn\n\\item The set of constants $A^\\partial$ is an $R$ subalgebra of $A$,\n\\item the unit $1_A \\in A$ is constant and\n\\item if $A$ is a division algebra (field) then $A^\\partial$ is a division algebra (field).\n\\en\n\\end{koro}\n\\bws is straight forward.\n\\bn\n\\item Clearly, $A^\\partial$ is an $R$ submodule. Thus, it suffice to show that $A^\\partial$ is an algebra over $R$. Let $a, a' \\in A^\\partial$ then\n$$\\partial(a a') = \\partial(a) a' + a \\partial(a') = 0 \\cdot a' + a \\cdot 0 = 0$$\nproving that products of constants are also constant.\n\\item Let $2 \\neq \\chr R$. By definition, we have\n$$\\partial(1_A) = \\partial(1_A \\cdot 1_A) = \\partial(1_A) 1_A + 1_A \\partial(1_A) = 2 \\partial(1_A) \\Leftrightarrow 0 = \\partial(1_A)$$\nshowing our claim, in parts. Let us assume that $\\chr R = 2$ and fix some $n \\in 2 \\nz$ (i.e. an even number). We have that\n$$1_A = \\underbrace{1_A \\cdot \\ldots \\cdot 1_A}_{n-\\mathrm{times}} \\Rightarrow \\partial(1_A) = \\sum_{i=1}^n \\underbrace{1_A \\cdot \\ldots \\cdot 1_A}_{n-1\\mathrm{-times}} \\partial(1_A) = 0 \\mod 2$$\nagain showing our assumption under given circumstances. Note, that an odd $n$ would yield\n$$\\partial(1_A) = \\partial(1_A) \\Leftrightarrow \\partial(0) = 0.$$\n\\item If $a \\in A^\\times \\cap A^\\partial := \\{b \\in A^\\partial : \\exists b' \\in A, b b' = 1_A\\}$ and $a^{-1} \\in A^\\times$ its inverse then:\n$$\\partial(a a^{-1}) = \\partial(1_A) \\stackrel{!}{=} 0 = \\partial(a) a^{-1} + a \\partial(a^{-1}) = a \\partial(a^{-1}) \\Leftrightarrow a^{-1} \\in A^\\partial.$$\n\\en\n\\bmk Obviously, the algebra of constants over any differential ring $(R, \\partial)$ is called the ring of constants. As we just saw, a differential division algebra has a division algebra as algebra of constants, therefore we get that the ring of constants of a differential field is a field.\n\\bsp Let $R$ be a ring.\n\\bn\n\\item With $\\chr R = 0$ then $\\left(R[X],\\mu_{R[X]}, \\eta, \\partial = \\left[X \\longmapsto 1_R\\right]\\right)$ has $R$ as its sole ring of constants.\n\\item With $\\chr R = p$, the ring of constants can be non-trivial - let $p \\in \\zz_{>0}$ be prime:\n$$\n\\bao{rrcl}\n\\partial : &R[X^p] &\\longrightarrow& R[X^p],\\\\\n&&&\\\\\n&\\sum r_k X^{p^k}& \\longmapsto& \\sum r_k \\partial\\left(X^{p^k}\\right)\\\\\n&&&\\\\\n&& = & \\sum r_k p^k X^{p^k-1}\\partial(X)\\\\\n&&&\\\\\n&&=& 0\\\\\n\\ea$$\nThus, in prime characterisic, the ring of constants is strictly larger than $R$: $R[X]^\\partial = R[X^p]$.\n\\en\n\n\\section{Generalisations}\nThere are two prominent ways to formalise and generalise the concept of derivations and their algebras.\n\\subsection{Lie Algebras}\nThe first way of formalisations are Lie algebras. \n\\begin{defi}\n\nAn $R$ algebra $(\\lieg,\\mu)$ is called a Lie algebra if $\\mu : \\lieg \\otimes \\lieg \\longrightarrow \\lieg$ fulfills:\n\\bn\n\\item Jacobian identity:\n$$\\sum_{i=0}^2 \\mu \\circ (\\mu \\otimes id_{\\lieg}) \\circ \\sigma_3^i(g_1 \\otimes g_2 \\otimes g_3) = 0,\\ \\mathrm{for~all}\\ g_1 \\otimes g_2 \\otimes g_3 \\in \\lieg^{\\otimes 3}.$$\nHere, $\\sigma_3 := (1,2,3) \\in \\mathrm{Gl}_R(\\lieg^{\\otimes3})$ is a $3$-cycle with $\\sigma_3^3 = id$.\n\\item Antissymmetry:\n$$\\mu \\circ \\tau = - \\mu,\\ \\mathrm{for}\\ \\tau = [g \\otimes h \\longmapsto h \\otimes g].$$\n\\en\n\\end{defi}\n\\begin{koro}\nGiven any associative algebra $(A,\\mu)$:\n\\bn\n\\item The commutator\n$$[,] = [a \\otimes b \\longmapsto \\mu(a \\otimes b) - \\mu(b \\otimes a)] = \\mu - \\mu \\tau,$$\ndefines a Lie algebra $(\\lieg(A),[,])$ on $A$. As $R$ modules, they are identical.\n\\item The module of $R$ derivations on $A$ forms a Lie algebra $\\mathrm{Der}_R(A)$ with commutator \n$$[,] : \\lieg(\\mathrm{End}_R(A)) \\otimes \\lieg(\\mathrm{End}_R(A)) \\longrightarrow \\lieg(\\mathrm{End}_R(A)),$$\nrestricted to the sub Lie algebra.\n\\en\n\\end{koro}\n\\bmk The proof is left to the reader. We shall extend our\n\\begin{defi}\nLet $(\\lieg,\\mu)$ be an $R$-Lie algebra. We call an $R$-submodule $\\lieh \\subset \\lieg$ an $R$-Lie subalgebra if\n$$(\\lieh,\\mu\\mid_{\\frk{h}}) \\subset (\\lieg,\\mu)$$\nis a Lie algebra in its own right. Given two Lie algebras $(\\lieg,\\mu_{\\lieg})$ and $(\\lieh,\\mu_{\\lieh})$ and a homomorphism $f \\in \\mathrm{Hom}_R(\\lieg,\\lieh)$. We call $f$ a homomorphism of Lie algebras if\n$$\\xymatrix{\n\\lieg^{\\otimes 2}\\ar[r]^{f\\otimes f}\\ar[d]_{\\mu_{\\lieg}}&\\lieh^{\\otimes 2}\\ar[d]^{\\mu_{\\lieh}}\\\\\n\\lieg \\ar[r]_f& \\lieh\\\\\n}$$\ncommutes. We call a Lie subalgebra $\\liea \\subset \\lieg$ a Lie ideal if\n$$\\mu(\\liea \\otimes_R \\lieg) \\subset \\liea.$$\nWe call a Lie algebra $\\lieg$ nilpotent if each sequence $(g_n) \\in \\lieg^{\\nz}$ with\n$$\\mu^{n-1}(g_1 \\otimes g_2 \\otimes \\ldots \\otimes g_n) = 0$$\nhas finite length. Here, $\\mu^n := \\mu^{n-1}(\\mu \\otimes id_{\\lieg^{\\otimes (n - 1)}})$, $\\mu^0 = id_\\lieg$ and $\\mu^1 = \\mu$. For each Lie algebra $\\lieg$ we get a chain of descending ideals: the so called $n$-th derived Lie algebra:\n$$\\mathcal{D}^n(\\lieg) := \\mu(\\mathcal{D}^{n-1}(\\lieg) \\otimes \\lieg),\\ \\mathrm{and}\\ \\mathcal{D}^0(\\lieg) = \\lieg.$$\nWe call $\\lieg$ solvable if $\\mathcal{D}(\\lieg) = \\mathcal{D}^1(\\lieg)$ is nilpotent. \n\\end{defi}\n\n\\bsp Let $R$ be a ring and $A = R[X]$ - its ring of polynomials. The endomorphism $\\partial_X = [X \\longmapsto 1] \\in \\mathrm{End}_R(A)$ is the classical example of a non-trivial $R$-derivation. Moreover, $\\mathrm{Der}_R(R[X])$ contains $R[X]$-left modules:\\\\\n\\indent Claim: for any derivation $\\partial : R[X] \\longrightarrow R[X]$, the $R$-submodule\n$$R[X].\\partial \\subset \\der{R[X]}$$\nis an $R[X]$-left module in $\\der{R[X]}$.\n\\paragraph{Proof} Given a derivation $\\partial \\in \\der{R[X]}$ and two polynomials $p, q \\in R[X]$:\n$$\\bao{rcl}\n[p \\partial,q \\partial] &=& p \\partial(q \\partial) - q \\partial(p \\partial)\\\\&&\\\\ &=& p \\partial(q) \\partial + p q \\partial^2 - q \\partial(p) \\partial - q p \\partial^2\\\\\n&&\\\\\n&=& (p \\partial(q) - q \\partial(p)) \\partial + (p q - p q) \\partial^2\\\\\n&&\\\\\n&=& (p \\partial(q) - q \\partial(p)) \\partial \\in R[X].\\partial\\\\\n\\ea$$\n\\bmk This proof actually applies to any differential algebra - given any derivation $\\partial \\in \\dera$, the $R$-submodule $R . \\partial$ generates an $A$-left submodule in $\\dera$.\n\\begin{defi}\n\n\\end{defi}\n\\subsection{Coalgbras}\nSpeaking in a categorical manner, for every ring $R$ algebras are the dual category of the category of $R$ coalgebras. We compare the diagrams defining algebras and coalgebras. Again, $(A, \\mu, \\eta)$ is an unital associative $R$ algebra - we call an $R$ module $C$ a coalgebra if there is an $R$ linear map $\\Delta : C \\longrightarrow C^{\\otimes2}$. In addition, we call a coalgebra $(C, \\Delta)$ coassociative or counital for a given $\\eps \\in \\mathrm{Hom}(C,R) = C^\\ast$ if \n$$(\\eps \\otimes id_C) \\Delta = (id_C \\otimes \\eps) \\Delta = id_C$$\nand the following diagrams commute:\n\\begin{longtable}{|c|cc|}\n\\hline\nCoalgebras: &$$\n\\xymatrix{\nC^{\\otimes 3}  & C^{\\otimes 2}\\ar[l]_{id_C \\otimes \\Delta}\\\\\nC^{\\otimes 2} \\ar[u]^{\\Delta \\otimes id_C}&C\\ar[l]^{\\Delta} \\ar[u]_{\\Delta}\\\\\n}$$\n&$$\n\\xymatrix{\n&C^{\\otimes 2}\\ar[ld]_{\\eps \\otimes id_C}\\ar[rd]^{id_C \\otimes \\eps}&\\\\\nR \\otimes C  &C\\ar[u]_\\Delta\\ar[r]_{\\simeq}\\ar[l]^\\simeq&C \\otimes R \\\\\n}$$\\\\\n&Coassociativity & Counitality\\\\\n\\hline\n&&\\\\\nAlgebras: &$$\n\\xymatrix{\nA^{\\otimes 3} \\ar[r]^{\\mu \\otimes id_A} \\ar[d]_{id_A \\otimes \\mu} & A^{\\otimes 2}\\ar[d]^{\\mu}\\\\\nA^{\\otimes 2} \\ar[r]_{\\mu} &A\\\\\n}$$\n&$$\n\\xymatrix{\n&A^{\\otimes 2}\\ar[d]^\\mu&\\\\\nR \\otimes A \\ar[r]_{\\simeq}\\ar[ru]^{\\eta \\otimes id_A} &A&A \\otimes R \\ar[lu]_{id_A \\otimes \\eta}\\ar[l]^\\simeq\\\\\n}$$\\\\\n&Associativity & Unitality\\\\\n\\hline\n\\end{longtable}\nClearly, each column is simply the inversion of arrows within the respective diagram. More interesting is the fact that the dual module $C^\\ast$ for each coalgebra $(C, \\Delta, \\eps)$ is an algebra with multiplication\n$$\\mu_{C^\\ast} := \\Delta^\\ast = \\left[\\alpha \\otimes \\beta \\longmapsto (\\alpha \\otimes \\beta) \\Delta = \\left[c \\longmapsto \\mu_R(\\alpha \\otimes \\beta)\\Delta(c) = \\sum_{(c)} \\alpha(c_{(1)}) \\beta(c_{(2)})\\right]\\right],$$\nwith Sweedler notation $\\Delta(c) = \\sum_{(c)} c_{(1)} \\otimes c_{(2)}$ and $\\mu_R$ denoting the multiplication on $R$. With the dual of the counit we get a unit: $\\eta_{C^\\ast} = \\eps^\\ast = [1_R \\longmapsto \\eps]$.\\\\\nWe call a coalgebra $C$ cocommutative if\n$$\\xymatrix{\n&C \\ar[rd]^\\Delta \\ar[dl]_\\Delta&\\\\\nC^{\\otimes2} \\ar[rr]_\\tau &&C^{\\otimes2}\\\\\n}$$\ncommutes for $\\tau : C^{\\otimes2} \\longrightarrow C^{\\otimes2}, c \\otimes c' \\longmapsto c' \\otimes c$ the flip isomorphism.\n\\subsubsection{Group-likes and skew primitives}\nUnless stated otherwise, we will always assume a coalgebra $C$ to be coassociative and counital.\n\\begin{defi}\nWe call an element $c \\in C$ group-like if\n$$\\Delta(c) = c \\otimes c.$$\nWe call an element $c$ $(g,h)$ skew primitive, for two group-like elements $g, h \\in C$, if\n$$\\Delta(c) = g \\otimes c + c \\otimes h.$$\n\\end{defi}\nFirstly, a group-like element $c \\in C$ has $\\eps(c) = 1$ as $(id_C \\otimes \\eps)\\Delta(c) = id(c) \\otimes \\eps(c) = \\eps(c) c \\stackrel{!}{=} 1 \\Leftrightarrow \\eps(c) = 1$. Secondly, for two group-like $g, h \\in C$ we have that a $(g,h)$ skew primitive element $c \\in C$:\n$$\\bao{rcl}\nc &\\stackrel{!}{=}& (id_C \\otimes \\eps)\\Delta(c) = id_C(g) \\otimes \\eps(c) + id_C(c) \\otimes \\eps(h)\\\\\n&&\\\\\n&\\stackrel{!}{=}& (\\eps \\otimes id_C)\\Delta(c) = \\eps(g) \\otimes id_C(c) + \\eps(c) \\otimes id_C(h)\\\\\n\\Leftrightarrow\\\\\n\\eps(c) &=& 0\\\\\n\\ea$$\n\\bmk Consider Skew primitive elements are, in essence, a generalisation of derivations - each derivation is simply a ", "meta": {"hexsha": "8a860acc077cfd7851be60c162a53cd9b7ae3b1b", "size": 11163, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "derivations/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": "derivations/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": "derivations/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": 60.6684782609, "max_line_length": 477, "alphanum_fraction": 0.6500940607, "num_tokens": 4190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6909845457569525}}
{"text": "\\documentclass[master.tex]{subfiles}\n\n%%%%%%%%%%%%%% BEGIN CONTENT: %%%%%%%%%%%%%%\n\n\\begin{document}\n\\section{Group Theory}\n\\subsection{Basic Facts}\n\\subsection*{Lecture 1: Normalizers and Centralizers}\n\\begin{defn*}[1.1.1]\n    For $A \\subset G$, we set $N_G(A) := \\{g \\in G | gAg^{-1} = A\\}$ and\n    $C_G(A) := \\{g \\in G | gag^{-1} = a, \\forall a \\in A\\}$.\n\\end{defn*}\nNote that $C_G(A) \\subset N_G(A)$ and $Z(G) = C_G(G)$. \n\\begin{rmk*}[1.1.2a]\n    If $A \\subgroup G$, then $A \\normsubgroup N_G(A)$. In fact, $N_G(A)$ is the\n    largest subgroup of $G$ in which $A$ is normal.\n\\end{rmk*}\n    The first part of this remark follows from the definition of $N_G(A)$. The\n    second part follows by assuming that $N_G(A)$ is not the largest and then\n    showing the ``largest'' is contained in $N_G(A)$.\n\\begin{rmk*}[1.1.2b]\n    If $A \\subgroup G$, then $A \\normsubgroup G$ if $N_G(A) = G$.\n\\end{rmk*}\n    This follows from the second part of the remark above.\n    Now for some remakrs about centralizers.\n    \\begin{rmk*}[1.1.3]\n      \\begin{enumerate}\n      \\item If $A \\subgroup G$, then $A$ is abelian if and only if $A \\subset\n        C_G(A)$.\n      \\item Furthermore, if $A \\subgroup Z(G)$, then $A \\normsubgroup G$.\n        This follows using basic commutativity arguments.\n      \\end{enumerate}\n        \n    \\end{rmk*}\n    \\begin{example}[1.1.4]\n        $Z(S_n) = \\{ id \\}$ if $n \\geq 3$. To prove this, prove $\\sigma \\in S_n, \\sigma \\neq id \\implies \\sigma \\notin Z(S_n)$.\n\n        $\\sigma \\neq id \\implies \\exists i,j \\in \\{1, \\ldots, n\\}$ where $i\n        \\neq j$ such that $\\sigma(i) = j$. Now, choose $k \\in \\{1, \\ldots, n\\}$\n        such that $k \\neq i,j$. Now, let $\\pi = \\sigma(i,k)\\sigma^{-1} =\n        (\\sigma(i), \\sigma(j)) = (j, \\sigma(k))$. So now, $\\pi(j) = \\sigma(k)\n        \\neq \\sigma(i) = j$. However, $(ik)(j)=j$ since $j \\neq i,k$. This\n        means $\\pi \\neq (ik)$, but if $\\sigma$ were in the center, then it\n        would have. So, we have that $\\sigma \\notin C_{S_n}( (ik) ) \\implies\n        \\sigma \\notin Z(S_n)$.\n    \\end{example}\n    \\begin{lem}[1.1.5]\n        Let $G$ be a group and $H \\subgroup Z(G)$. (Note this implies $H\n        \\normsubgroup G$.) If $G/H$ is cyclic, then $G$ is abelian.\n    \\end{lem}\n    \\begin{proof}\n        Since $G/H$ is cyclic, this means $\\exists g \\in G$ such that\n        $G/H=\\langle gH \\rangle$. Now, let $x,y \\in G$. Then, there are $n,m\n        \\in \\Z$ such that $xH = (gH)^n = g^nH$ and, similarly, $yH = (gH)^m =\n        g^mH$. This means $\\exists h,h' \\in H$ such that $x=g^nh$ and\n        $y=g^mh'$. Thus, we get $xy = g^nhg^mh' = g^ng^mhh' = g^{n+m}hh'$ and\n        $yx = g^mh'g^nh = g^mg^nh'h = g^{n+m}h'h = g^{n+m}hh'$. Thus, we have\n        our commutativity, thereby showing $G$ is abelian.\n    \\end{proof}\n    \\begin{rmk*}\n        Note, simply having $H \\subgroup Z(G)$ and $G/H$ abelian does not imply\n        $G$ is abelian. For a counter-example, look at $Q_8 = \\{\\pm 1, \\pm i,\n        \\pm j, \\pm k\\}$, the standard quaternion group. It is easy to compute\n        that $Z(Q_8) = \\{\\pm 1\\}$. Now, $Q_8/Z(Q_8) \\isom \\Z_2 \\times \\Z_2$,\n        the Klien-4 group, which is abelian. However, $Q_8$ is not abelian!\n    \\end{rmk*}\n    \\begin{defn}\n        Let $A,B \\subgroup G$, then \\begin{itemize}\n            \\item $A^{-1} = \\{a^{-1} | a \\in A\\}$.\n            \\item $AB = \\{ab | a \\in A, b \\in B\\}$.\n        \\end{itemize}\n    \\end{defn}\n    \\begin{lem}[1.1.6]\n        Let $G$ be a group with $A,B \\subgroup G$. Then,\n        \\begin{enumerate}\n            \\item $AB \\subgroup G$ if and only if $AB = BA$.\n            \\item If $A \\subgroup N_G(B)$ or $B \\subgroup N_G(A)$, then $AB =\n                BA$ and hence $AB \\subgroup G$ by 1.\n        \\end{enumerate}\n    \\end{lem}\n    \\begin{proof}\n        ($\\Rightarrow$) Let $AB \\subgroup G$. Then, $AB = (AB)^{-1} =\n        B^{-1}A^{-1} = BA$.\n\n        ($\\Leftarrow$) Let $AB = BA$. Then, we simply must show that $AB$ has\n        group properties.\\begin{enumerate}\n            \\item $e \\in A, e \\in B \\implies e = ee \\in AB$.\n            \\item This is the same as above. $(AB)^{-1} = B^{-1}A^{-1} = B! = AB$.\n            \\item $(AB)(AB) = A(BA)B = A(AB)B = (AA)(BB) = AB$.\n        \\end{enumerate} Thus, $AB \\subgroup G$.\n\n        Now, for the second part, let $A \\subgroup N_G(B)$. Then, let $a \\in A,\n        b \\in B$. We know $a,a^{-1} \\in A \\subset N_G(B)$. Then, we have $ab =\n        aba^{-1}a = (aba^{-1})a$. However, we know $aba^{-1} \\in B$ from the\n        definition of $N_G(B)$. So, $AB \\subset BA$. Similar logic shows $BA\n        \\subset AB$ and thus $AB = BA$.\n    \\end{proof}\n    \\subsection*{Lecture 2}\n    \\begin{rmk*}\n        \\begin{enumerate}\n            \\item If $A,B \\subgroup G$ and if $A \\normsubgroup G$ or\n              $B \\normsubgroup G$, then $AB \\subgroup G$. \n            \\item If $A,B \\normsubgroup G$, then $AB \\normsubgroup\n              G$.\n        \\end{enumerate}\n    \\end{rmk*}\n    \\begin{proof}\n        The first remark can be done by $(ab)(a'b') = aba'b^{-1}bb' =\n        aa'b' = (aba'b^{-1})b' \\in AB$ because $a$ and $ba'b^{-1}$ are\n        in $A$ and $b \\in B$. Also, $(ab)^{-1} = b^{-1}a^{-1} =\n        (b^{1}a^{-1}b)b^{-1} \\in AB$. The identity inclusion is\n        obvious.\n        \n        The second remark is proven by, for $g \\in G$, $gABg^{-1} =\n        gAg^{-1}gBg^{-1} = AB$. \n    \\end{proof}\n\n    \\subsubsection*{Index Computations}\n\n    \\begin{lem}\n        Let $A,B \\subgroup G$ and $|A|, |B| < \\infty$. Then, $|AB| = \\frac{|A| \\cdot |B|}{|A \\cap B|}$.\n    \\end{lem}\n    \\begin{proof}\n        Consider $A/(A \\cap B)$. Take a complete set of coset representatives $A' = \\{a_1, \\ldots, a_n\\}$. Then, $n = |A/(A \\cap B)| = [A : A \\cap B] = \\frac{|A|}{|A \\cap B|}$ by Lagrange's Theorem.\n\n        Now, consider $f: A' \\times B \\to AB$ defined by $(a_i,b) \\to a_ib$. If\n        we show that $f$ is bijective, then we will have that $|A'| \\cdot |B| =\n        |A' \\times B| = |AB|$, which will allow us to finish the proof.\n        To show $f$ is injective, let us take \\begin{align*}\n            a_ib = a_jb' (1 \\leq i,j \\leq n; b,b' \\in B) & \\ \\implies \\ a_j^{-1} a_i = b'b^{-1} \\in A\\cap B\\\\\n            \\ & \\ \\implies \\ a_i(A \\cap B) = a_j(A \\cap B) \\\\\n            \\ & \\ \\implies \\ a_i = a_j \\\\\n            a_ib = a_jb' & \\ \\implies b = b' \\\\\n            \\ & \\ \\implies (a_i, b) = (a_j, b')\n        \\end{align*}\n\n        To show $f$ is surjective, we let $a \\in A, b \\in B$. Then $\\exists i\n        (1 \\leq i \\leq n)$ such that $a=a_ix$ with $x \\in A \\cup B$. This\n        implies that $xb \\in B$ so $ab = a_ixb = f( (a_i,xb) )$.\n\n        Thus, we have that $f$ is bijective, and so we conclude that $n \\cdot\n        |B| = \\frac{|A|}{|A \\cap B|} \\cdot |B|$ giving us our result when we\n        divide by $|B|$.\n    \\end{proof}\n    \\begin{example}\n        (a) $G = \\Sym_3, A = \\langle (12) \\rangle, B = \\langle (13) \\rangle\n        \\subgroup G$. Then, $A \\cap B = \\{ id \\} \\implies |AB| = 2 \\cdot 2 = 4$\n        which does not divide $6 = |\\Sym_3|$. Thus, $AB$ is not a subgroup of\n        $\\Sym_3$.\n        (b) Let $G=\\Sym_4, A = \\Sym_3 \\to \\Sym_4, B = \\langle (1234) \\rangle$. Then, $A \\cap B = \\{id\\} \\implies |AB| = |A||B| = 6 \\cdot 4 = 24 = |\\Sym_4|$. This means that $AB = \\Sym_4$ but note that $A \\not\\subset N_G(B)$ and $B \\not\\subset N_G(A)$.\n    \\end{example}\n    \\begin{lem}\n        Let $G$ be a group and $A,B \\subgroup G$. Then\n        \\begin{enumerate}\n            \\item If $A \\subgroup B$, then $[G:A] = [G:B][B:A]$\n            \\item $[A: A \\cap B] \\leq [G:B]$\n            \\item $[G: A \\cap B] \\leq [G:A][G:B]$\n        \\end{enumerate}\n    \\end{lem}\n    \\begin{proof}\n       For the first part, fix a set of coset representatives (using the Axiom of Choice in the infinite case) for $G/A$. Then, given a coset $gA$, we can TODO\n\\end{proof}\n\\subsection*{The Isomorphism Theorems}\n\\begin{thm}[1.1.10 First Isomorphism Theorem]\n    If $\\phi: G \\to H$ is a group homomorphism, then $G/\\ker \\phi\n    \\isom \\phi(G) \\subgroup H$.\n\\end{thm}\n\\begin{proof}\n    Set $N = \\ker \\phi \\normsubgroup G$. Then, consider $\\widetilde{\\phi}: G/N\n    \\to \\phi(G)$ defined by $\\widetilde{\\phi}(gN) = \\phi(g)$. First, we check\n    that $\\widetilde{\\phi}$ is well-defined.\n\n    Assume $gN = g'N, g,g' \\in G$. Then, there exists $n \\in N$ such that $g'\n    = gn$. This tells us that $\\phi(g') = \\phi(gn) = \\phi(g)\\phi(n) = \\phi(g)e\n    = \\phi(g)$. Now, we show that $\\widetilde{\\phi}$ is a group homomorphism.\n\n    Check $\\widetilde{\\phi}( (gN)(g'N) ) = \\widetilde{\\phi}(gg'N) = \\phi(gg') =\n    \\phi(g)\\phi(g') = \\widetilde{\\phi}(gN) \\widetilde{\\phi}(g'N)$.\n\n    We know $\\widetilde{\\phi}$ is surjective by definition.\n\n    To show $\\widetilde{\\phi}$ is injective, it suffices to show that $\\ker\n    \\widetilde{\\phi} = \\{\\widetilde{e} = eN\\}$. If $\\widetilde{\\phi}(gN) =\n    \\phi(g) = e \\in H$, then $g \\in \\ker \\phi = N$ and therefore $gN = N =\n    \\widetilde{e}$\n\\end{proof}\n\\begin{cor}\n    (Second Isomorphism Theorem) If $A,B \\subgroup G$ and $A \\subgroup N_G(B)$,\n    then $AB/B \\isom A/A\\cap B$.\n\\end{cor}\n\\begin{proof}\n    First, we know since $A \\subgroup N_G(B)$ that $AB \\subgroup N_G(B)$. Then,\n    by definition of normalizer, $B \\normsubgroup AB$. Now, define a group\n    homomorphism $\\phi: A \\to AB/B$ by $\\phi(a) = aB$. Then, we can use the\n    first isomorphism theorem to get that $A/\\ker \\phi \\isom \\phi(A)$. Now,\n    $\\ker \\phi$ is the set of all $a \\in A$ that map to an element in $B$. This\n    clearly only happens when $a \\in B$. So, $\\ker \\phi = A \\cap B$.\n    Furthermore, it is clear $\\phi(A) = AB/B$ (as opposed to $A/B$) because $B$\n    need not be a subset of $A$. Thus, elements of the form $aB$ where $a \\in A$\n    are in $AB/B$. (This part is still unclear to me.) Thus, we get $A/A \\cap B\n    \\isom AB/B$.\n\\end{proof}\nThe second isomorphism theorem is sometimes referred to as the ``diamond\ntheorem'' because if you draw a diagram of what is happening, it is a diamond\nwith $A, B, AB$, and $A \\cap B$.\n\\begin{cor}\n    (Third Isomorphism Theorem) If $A,B \\normsubgroup G$ and $A \\subgroup B$, then $(G/A)/(B/A) \\isom G/B$.\n\\end{cor}\n\\begin{proof}\n    Let us define a group homomorphism $\\phi: G/A \\to G/B$ by $\\phi(gA) = gB$.\n    Then, let us examine $\\ker \\phi$. We note that if $t \\in B$,\n    then $\\phi(tA) = B$. Thus, $\\ker \\phi = \\{tA | t \\in B\\} = B/A$. Now, applying the first\n    isomorphism theorem with $\\phi$, we get that $(G/A)/(B/A) \\isom \\phi(G/A)$.\n    $\\phi$ is clearly surjective because $A \\subgroup B$, so we conclude that\n    $(G/A)/(B/A) \\isom G/B$.\n\\end{proof}\n\nThese isomorphism theorems are useful in many proof techniques and there are\nanalogues for many different algebraic structures. Next, we consider the\nCorrespondance Theorem which is sometimes referred to as the fourth isomorphism\ntheorem. The fundamental idea of the correspondance theorem is that the\nstructure of subgroups of $G/N$ for $N \\normsubgroup G$ is the same as the\nstructore of the subgroups of $G$ containing $N$ where $N$ is ``collapsed'' as\nthe identity element.\n\n\\begin{thm}[Lattice Isomorphism Theorem]\n    Let $G$ be a group, $N \\normsubgroup G$, and $\\overline{G} = G/N$. Next, let\n    $\\phi_N = \\{ A \\subgroup G | N \\subgroup A \\}$ and $\\overline{\\phi}$ be the\n    set of all subgroups of $\\overline{G}$. Then, all the following are true for $A,B \\in \\phi_N$.\n    \\begin{enumerate}[label=(\\alph*)]\n        \\item $A \\subgroup B$ if and only if $\\overline{A} \\subgroup \\overline{B}$..\n        \\item $A \\normsubgroup B$ if and only if $\\overline{A} \\normsubgroup\n            \\overline{B}$.\n        \\item If $A \\subgroup B$, then $[B:A] = [\\overline{B}:\\overline{A}]$.\n        \\item $\\overline{\\langle A, B \\rangle} = \\langle \\overline{A}, \\overline{B} \\rangle$\n        \\item $\\overline{A \\cap B} = \\overline{A} \\cap \\overline{B}$.\n        \\item The map $\\rho: \\phi_N \\to \\overline{\\phi}$ where $\\rho(A) =\n            \\overline{A}$ is bijective.\n        \\item A map from $\\{ A \\in \\phi_N | A \\normsubgroup G\\}$ to the set of\n            normal subgroups of $\\overline{G}$ defined by $A \\mapsto\n            \\overline{A}$ is bijective.\n    \\end{enumerate}\n\\end{thm}\n\\begin{proof}\n    Proofs for (a) -- (d) were left as an exercise (to be filled in later).\n    For (e), let $\\pi: G \\twoheadrightarrow \\overline{G}$ be the surjective\n    group homomorphism defined by $\\pi(g) = gN$. Now, consider $\\psi:\n    \\overline{\\phi} \\to \\phi_N$ defined by $\\psi(H) = \\pi^{-1}(H) \\subgroup G$.\n    Then, we want to show that $\\rho \\circ \\psi = id_{\\overline{\\phi}}$ and\n    $\\psi \\circ \\rho = id_{\\phi_N}$ because then we will know $\\rho$ is\n    invertible and thus bijective.\n\n    Examine $\\rho \\circ \\psi$. We know that $(\\rho \\circ \\psi)(H) =\n    \\rho(\\pi^{-1}(H))$. Now, note that $\\rho(A)$ is the image of $\\pi(A)$, so\n    we get $\\rho(\\pi^{-1}(H)) = \\pi(\\pi^{-1}(H)) = H$ because $\\pi$ is\n    surjective.\n\n    Next, examine $\\psi \\circ \\rho$. We then get that $(\\psi \\circ \\rho)(A) =\n    \\pi^{-1}(\\pi(A))$ for $A \\subgroup G$. We would like for this to be equal\n    $A$. It is clear that $A \\subset \\pi^{-1}(\\pi(A))$ because the pre-image of\n    $A/N$ under $\\pi$ must at least contain $A$. So, we still need to show that\n    $\\pi^{-1}(\\pi(A)) \\subset A$. To do this, take $x \\in \\pi^{-1}(A/N)$. Then,\n    $xN = \\pi(x) \\in A/B$, so $xN = aN$ for some $a \\in A$. This means that\n    there exists an $n \\in N$ such that $x = an$ since $N \\subgroup A$. So,\n    $\\pi^{-1}(A/N) \\subset A$.\n\n    Thus, we have shown that $\\rho$ and $\\psi$ are bijective maps that are\n    inverse to each other and we have proven (e). \\\\\n\n    (f) follows from the same proof technique as (e), I believe.\n\\end{proof}\n\n\\subsubsection*{Commutators}\n\n\\begin{defn}\n    The commutator of two elements $x,y \\in G$ is defined as \\[\n        [x,y] = xyx^{-1}y^{-1}\n    \\]\n\\end{defn}\n\nNote that mathematicians have not completely agreed on the definition and thus\nsome references will say $[x,y] = x^{-1}y^{-1}xy$. In essence, the commutator\nof two elements indicates how ``close'' elements are to commuting. This can be\nseen in the following lemma.\n\n\\begin{lem}\n    For $x,y,z \\in G$, we obtain\n    \\begin{enumerate}[label=(\\alph*)]\n        \\item $[x,y] = e$ if and only if $xy=yx$ if and only if $[x^{-1},y^{-1}] = e$.\n        \\item $[x,y]^{-1} = [y,x]$.\n        \\item $z[x,y]z^{-1} = [zxz^{-1},zyz^{-1}]$.\n        \\item If $\\phi: G \\to H$ is a group homoromorphism, then $[\\phi(g),\\phi(h)] = \\phi([g,h])$.\n        \\item $xy = [x,y]yx = yx[x^{-1},y^{-1}]$.\n        \\item $[xy,z] = x[y,z]x^{-1}[x,z]$\n        \\item $[x,yz] = [x,y]y[x,z]z^{-1}$.\n    \\end{enumerate}\n\\end{lem}\n\\begin{proof}\n    All proofs are straightforward computations.\n\\end{proof}\n\\subsection*{Lecture 3: Continuing with Commutators}\n\\begin{defn}\n    Let $A, B \\subgroup G$. Then, the \\emph{commutator} of $A$ and $B$ is the\n    subgroup of $G$ denoted $[A,B] = \\langle \\{[a,b] | a \\in A, b \\in B\\}\n    \\rangle$. Also note that $[G,G]$ is called the \\emph{commutator subgroup of\n    $G$}.\n\\end{defn}\n\\begin{rmk}\n    Let $A,B \\subgroup G$. Then\n    \\begin{enumerate}\n        \\item $[A,B] = \\{e\\}$ if and only if $ab = ba, \\forall a \\in A, b \\in B$\n            if and only if $A \\subgroup C_G(B)$ if and only if $B \\subgroup\n            C_G(A)$. In this case, we say that $A$ and $B$ commute.\n        \\item $[G,G] = \\{e\\}$ if and only if $G$ is abelian if and only if $Z(G) = G$.\n        \\item $[A,B] = [B,A]$ since $[a,b]^{-1} = [b,a]$.\n        \\item (matt) $[G,G]$ is characteristic in $G$.\n    \\end{enumerate}\n\\end{rmk}\n\\begin{example}\n    \\begin{enumerate}\n        \\item $[Q_8,Q_8] = \\{1,-1\\} = [\\langle i \\rangle, \\langle j \\rangle]$.\n            This can be seen because $[i,j] = iji^{-1}j^{-1} = ij(-i)(-j) =\n            ij(-i)(-j) = iij(-j) = -i^2j^2 = -1$.\n        \\item $[A_n, \\langle (12) \\rangle] = A_n$ for $n \\geq 2$. This follows\n            because, for $i \\geq 3$, we get $[(1i2),(12)] = (1i2)(12)(2i1)(12)\n            = (12i)$. This tells us that $A_n = \\langle \\{(12i) | 3 \\leq i \\leq\n            n\\} \\rangle \\subset [A_n, \\langle (12)\\rangle$.\n        \\item $[S_n,S_n] = A_n$ for $n \\geq 2$. To show this, for ($\\subset$)\n            we have \\begin{align*}\n                \\sgn( [\\sigma,\\tau] ) & = \\sgn(\\sigma \\tau \\sigma^{-1} \\tau^{-1}) \\\\\n                \\ & = \\sgn(\\sigma) \\sgn(\\tau) \\sgn(\\sigma)^{-1} \\sgn(\\tau)^{-1} \\\\\n                \\ & = 1, \\forall \\sigma, \\tau \\in S_n\n            \\end{align*}\n            For ($\\supset$), see the previous item.\n        \\item $[A_n,A_n] = A_n$ for $n \\geq 5$. This is because every 3 cycle\n            is a commutator. For instance $[(ijk),(klm)] = (ilk)$ for 5\n            distinct elements $i,j,k,l,m \\in \\{1, \\ldots, n\\}$. Also note that\n            $[A_3,A_3] = \\{e\\}$ and $[A_4,A_4] = \\Z_2 \\times \\Z_2$, the set of\n            all elements of the form $(ij)(kl)$.\n    \\end{enumerate}\n\\end{example}\n\\begin{lem}\n    Let $A,B \\subgroup G$. Then,\n    \\begin{enumerate}[label=(\\alph*)]\n        \\item $A \\subgroup N_G(B)$ if and only if $[A,B] \\subgroup B$.\n        \\item $B \\subgroup N_G(A)$ if and only if $[A,B] \\subgroup A$.\n        \\item If $A,B \\normsubgroup G$ then $[A,B] \\normsubgroup G$ and $[A,B]\n            \\subgroup A \\cap B$\n    \\end{enumerate}\n\\end{lem}\n\\begin{proof}\n    The forward direction of $(a)$ is given by the fact that $[a,b] =\n    aba^{-1}b^{-1}$ but $aba^{-1} \\in B$ since $A$ normalizes $B$. Thus, $[a,b]\n    \\in B, \\forall a \\in A, b \\in B$ so $[A,B] \\subgroup B$. To do the other\n    direction, we have that, we have that $aba^{-1}b^{-1} \\in B, \\forall a \\in A,\n    \\forall b \\in B$. Well, $(aba^{-1}b^{-1})b = aba^{-1} \\in B$, so $A$\n    normalizes $B$, so $A \\subgroup N_G(B)$. \\\\\n\n    (b) is similar to (a). \\\\\n\n    Now, given that $A,B \\normsubgroup G$, then $g[a,b]g^{-1} =\n    gaba^{-1}b^{-1}g^{-1} = gag^{-1}gbg^{-1}ga^{-1}g^{-1}gb^{-1}g^{-1}$. Now\n    note that $gag^{-1} \\in A$ since $A \\normsubgroup G$ and $(gag^{-1})^{-1} =\n    ga^{-1}g^{-1}$. Similarly for $b$. So, we have that $g[a,b]g^{-1} \\in [A,B]\n    \\implies [A,B] \\normsubgroup G$. Finally, an element of the form\n    $aba^{-1}b^{-1} \\in A$ because $ba^{-1}b^{-1} \\in A$ since $A$ is normal in\n    $G$ and similarly $aba^{-1} \\in B$. So, $[A,B] \\subgroup A \\cap B$. This\n    final fact also follows from the first two items in the lemma.\n\\end{proof}\n\nThis lemma also gives us the important fact that $[G,G] \\normsubgroup G$. This\nfollows easily from the third item.\n\n\\begin{prop}\n    If $H \\subgroup G$, then $[G,G] \\subgroup H$ if and only if $H\n    \\normsubgroup G$ and $G/H$ is abelian.\n\\end{prop}\n\\begin{proof}\n    Let $[G,G] \\subgroup H$. Then, if $a,b \\in G$, $aba^{-1}b^{-1} \\in H$. Now,\n    in particular, if $b \\in H$, then $aba^{-1}b^{-1} \\cdot b = aba^{-1} \\in H$\n    so $H \\normsubgroup G$. More concisely, we have that $[G,H] \\subgroup [G,G]\n    \\subgroup H \\implies G \\subgroup N_G(H)$ so $H \\normsubgroup G$. To show\n    $G/H$ is abelian, take a map $[a,b] \\mapsto [aH,bH] =\n    (aH)(bH)(aH)^{-1}(bH)^{-1} = aba^{-1}b^{-1}H = [x,y]H = H = e_{G/H}$. So,\n    then $[G/H,G/H] = \\{e\\}$.\n\n    To prove the other direction, let $G/H$ be abelian and $H \\normsubgroup G$.\n    Since $G/H$ is abelian, we have that $[aH,bH] = [a,b]H = H$. This means\n    that $[a,b] \\in H$ which implies that $[G,G] \\in H$. (Where is the normalcy\n    of $H$ used?!)\n\\end{proof}\n\n\\subsubsection*{Direct Products}\n\n\\begin{defn}\n    The (external) direct product of two groups $A$ and $B$ is defined\n    as the set (Cartesian product)  \\[\n        A \\times B = \\{(a,b) | a \\in A, b \\in B \\}\n    \\] with multiplication $(a_1,b_1) \\cdot (a_2,b_2) =\n    (a_1a_2,b_1b_2)$. With this multiplication, it is clear that $A\n    \\times B$ is a group by direct computation. \n\\end{defn}\n\nDirect products provide us with a way to build new groups from known groups.\n\n\\begin{lem}\n    Let $G_1, G_2$ be groups and let $H_1 \\subgroup G_1$ and $H_2 \\subgroup G_2$. Then\n    \\begin{enumerate}[label=(\\alph*)]\n        \\item $H_1 \\times H_2 = \\{(h_1,h_2) | h_1 \\in H_1, h_2 \\in H_2\\} \\subgroup G_1 \\times G_2$.\n        \\item $H_1 \\times H_2 \\normsubgroup G_1 \\times G_2$ if and only if $H_1 \\normsubgroup G_1$ and $H_2 \\normsubgroup G_2$. In this case, $(G_1 \\times G_2)/(H_1 \\times H_2) \\isom (G_1/H_1) \\times (G_2/H_2)$.\n    \\end{enumerate}\n\\end{lem}\n\\begin{proof}\n    For the first item, the proof is a clear from the definition of subgroup. \\\\\n\n    For the second item, examine the fact that\n    $(g_1,g_2)(h_1,h_2)(g_1,g_2)^{-1} = (g_1h_1g_1^{-1},g_2h_2g_2^{-1})$. Then,\n    if $H_1 \\normsubgroup G_1$ and $H_2 \\normsubgroup G_2$, we get\n    $(g_1,g_2)(h_1,h_2)(g_1,g_2)^{-1} = (h_1,h_2)$, so $H_1 \\times H_2\n    \\normsubgroup G_1 \\times G_2$. Going the other direction is similar, but\n    reducing the left hand side instead.\n\n    Finally, we can show the final equivalence using $\\phi: G_1 \\times G_2 \\to\n    G_1/H_1 \\times G_2/H_2$ where $\\phi( (g_1,g_2) ) = (g_1H_1, g_2H_2)$. It\n    is clear that $\\phi$ is surjective and a group homomorphism, and we note\n    that $\\ker \\phi = H_1 \\times H_2$. Thus, we apply the first isomorphism\n    theorem to get our equivalence.\n\\end{proof}\n\nA note of warning is that not every subgroup of a direct product needs to be\nof the form $H_1 \\times H_2$ where $H_1 \\subgroup G_1$ and $H_2 \\subgroup G_2$.\n\n\\begin{example*}\n    Examine $\\Z_2 = \\{0,1\\}$. Then, $\\Z_2 \\times \\Z_2 =\n    \\{(0,0),(0,1),(1,0),(1,1)\\}$.  However, $H = \\{(0,0),(1,1)\\} \\subgroup \\Z_2\n    \\times \\Z_2$ but is not of the form $H_1 \\times H_2$.\n\\end{example*}\n\n\\begin{rmk}\n    (Universal Property) Let $A \\times B$ be the direct product of two groups\n    $A$, $B$. Then, there are natural projections (surjective group\n    homomorphisms) defined by $\\pi_A: A \\times B \\to A$ by $\\pi( (a,b) ) = a$\n    and similarly for $\\pi_B$. They satisfy the following universal property. \\\\\n\n    For any group $G$, and any pairs of homomorphisms $\\phi_A: G \\to A$ and\n    $\\phi_B: G \\to B$, there exists a \\emph{unique} homomorphism $\\phi: G \\to A\n    \\times B$ such that $\\pi_A \\circ \\phi = \\phi_A$ and $\\pi_b \\circ \\phi =\n    \\phi_B$. Indeed, if $\\phi(g) = (a,b)$ for $g \\in G$, then $a = \\pi_A( (a,b)\n    ) = \\pi_A(\\phi(g)) = \\phi_A(g)$ and similarly for $b = \\phi_B(g)$. \\\\\n\n    The only possible map with these properties is given by $\\phi: G \\to A\n    \\times B$ where $\\phi(g) = (\\phi_A(g), \\phi_B(g))$.\n\n    We now check that $\\phi$ so defined is a homomorphism with the properties\n    $\\pi_A \\circ \\phi = \\phi_A$ and $\\pi_B \\circ \\phi = \\phi_B$.\n\\end{rmk}\n\\begin{proof}\n    Let $\\phi$ be defined as above. Then, $\\phi( (a_1,b_1)(a_2,b_2) ) =\n    (\\phi_A(a_1a_2), \\phi_B(b_1b_2)) =\n    (\\phi_A(a_1),\\phi_B(b_1))(\\phi_A(a_2),\\phi_B(b_2)) = \\phi( (a_1,b_1) )\\phi(\n    (a_2,b_2) )$. The other homomorphism properties clearly follow. \\\\\n\n    $\\pi_A \\circ \\phi( (a,b) ) = \\pi_A( (\\phi_A(a), \\phi_B(b)) ) = \\phi_A(a)$.\n    Similarly for $\\pi_B \\circ \\phi( (a,b))$. \\\\\n\\end{proof}\nIt is an exercise to generalize this for any $I$ index set with $(A_i)_{i \\in\nI}$ a family of groups to then generalize the unversal property to the direct\nproduct of these groups, say $\\times_{i \\in I} A_i = \\{(a_i) | a_i \\in A_i\n\\forall i \\in I\\}$. \\\\\n\nNow, let $A \\times B$ be the external direct product of groups $A$ and $B$.\nThen, we know $A \\isom A' = \\{(a,e_B) | a \\in A\\} \\subgroup A \\times B$ and\nsimilarly for $B \\isom B'$. Then, $A',B'$ have the following properties.\n\\begin{itemize}\n    \\item $A'B' = A \\times B$.\n    \\item $A' \\cap B' = \\{e\\}$.\n    \\item $A', B' \\normsubgroup A \\times B$.\n\\end{itemize}\n\nLet us next discuss internal direct products.\n\n\\begin{defn}\n    A group $G$ is the \\emph{internal direct product} of two subgroups $A,B\n    \\subgroup G$ if the following conditions are satisfied:\n    \\begin{enumerate}[label=\\roman*)]\n        \\item $AB = G$\n        \\item $A \\cap B = \\{e\\}$\n        \\item $A,B \\normsubgroup G$\n    \\end{enumerate}\n\\end{defn}\n\\begin{rmk*}\n    In which case, $AB \\isom A \\times B$.\n\\end{rmk*}\n\\begin{example}\n    \\begin{enumerate}[label=(\\alph*)]\n        \\item Let $G = \\Z_6, A = \\{\\overline{0}, \\overline{3}\\} \\subgroup G, B\n            = \\{\\overline{0}, \\overline{2}, \\overline{4}\\} \\subgroup G$. Then,\n            we have that $A \\cap B = \\{ \\overline{0} \\} \\implies |AB|=|A||B| =\n            6 = |G|$. Thus, $AB = G$. In abelian groups, all subgroups are\n            normal, so $G = A \\times B$. In fact, we can prove that $\\Z_{mn}\n            \\isom \\Z_m \\times \\Z_n$ when $\\gcd(m,n) = 1$ using the same\n            argument where we take $A = \\{\\overline{0}, \\overline{n},\n            \\overline{2n}, \\ldots, \\overline{(m-1)n}\\}$ and similarly $B =\n            \\{\\overline{0}, \\overline{m}, \\ldots, \\overline{(n-1)m}\\}$ and\n            showing that $A \\cap B = \\{\\overline{0}\\}$ since $\\gcd(m,n) = 1$.\n        \\item $V = \\{e, (12)(34), (13)(24), (14)(23)\\} \\normsubgroup S_4$. This\n            is clearly true since conjugating by a permutation is like applying\n            the permutation to the numbers of the cycle, which will not change\n            the cycle structure. Now, let $A = \\{e, (12)(34)\\}, B = \\{e, (13)(24)\\}$, then $A \\cap B = \\{e\\}$ and $A,B \\normsubgroup V$. So,\n            we get that $|AB| = 2\\cdot 2 = 4 = |V| \\implies V = AB$ so then $V\n            = A \\times B \\isom \\Z_2 \\times \\Z_2$.\n        \\item $S_4 = VS_3$. We know that $S_3$ can be embedded into $S_4$\n            easily and $V \\cap S_4 = \\{e\\}$. So, for this to happen $|VS_3| =\n            24 = |S_4|$. From above, we know $V \\normsubgroup S_3$, but it is\n            easy to see that $S_3 \\not\\normsubgroup S_4$. So, we have found an\n            example of a product of groups that is not a direct product but\n            still forms a group. This leads us into our discussion of\n            semi-direct products.\n    \\end{enumerate}\n\\end{example}\n\n\\begin{prop*}[1.1.26]\n  If $G$ is the internal direct product of two subgroups $A,B\n  \\subgroup G$, then $G$ and the external product $A \\times B$ are\n  isomorphic.\n\\end{prop*}\n\\begin{proof}\n  Proof was done in class but omitted here.\n\\end{proof}\n\\begin{cor*}[1.1.27]\n  If $G = A \\times B$, internal direct product, then\n  \\begin{enumerate}\n  \\item $A$ and $B$ commute.\n  \\item Any $g$ can be uniquely writen in the form $g = ab$ with $a\n    \\in A, b \\in B$.\n  \\end{enumerate}\n\\end{cor*}\n\\begin{proof}\n  Both of these statements follow easily from the proof of the\n  proposition above.\n\\end{proof}\n\n\\subsubsection*{Automorphisms}\n\\begin{defn*}[1.1.28]\n  An automorphism of a group $G$ is a bijective homomorphism from $G$\n  onto $G$. \\[\n    \\Aut(G) = \\{\\alpha: G \\to G : \\alpha \\text{ is an automorphism.}\\}\n  \\]\n  is a group with respect to composition as multiplication.\n\\end{defn*}\n\\begin{example*}[1.1.29]\n  \\begin{enumerate}\n  \\item $\\Aut(\\Z) \\isom \\{1,-1\\}$\n  \\item $\\Aut(\\Z_n) \\isom \\Z^\\times_n \\implies |\\Aut(\\Z_n)| = \\phi(n)$\n    where $\\phi(n)$ is Euler's phi function.\n  \\item If $A,B$ are groups, then $\\Aut(A) \\times \\Aut(B) \\subgroup\n    \\Aut(A \\times B)$.\n  \\item $\\Aut(\\Z_2 \\times \\Z_2) \\isom \\Sym_3$. Any permutations of\n    $a,b,c$ yields an automorphism of $\\Z_2 \\times \\Z_2$.\n  \\item For any group $G$ and any $g \\in G$, conjugation with $g$\n    defines an automorphism $\\kappa_g: G \\to G$ such that $x \\mapsto\n    gxg_{-1}$ called an inner automorphism. \n  \\end{enumerate} \n\\end{example*}\n\\begin{defn*}[1.1.30]\n  An automorphism is called an inner automorphism if there exists a $g\n  \\in G$ such that $\\alpha = \\kappa_g$. We set \\[\n    \\operatorname{Inn}(G) = \\{\\kappa_g : g \\in G\\} \\subgroup \\Aut(G).\n  \\]\n\\end{defn*}\n\\begin{lem*}\n  \\begin{enumerate}\n  \\item $\\operatorname{Inn}(G) \\isom G/Z(G)$\n  \\item $\\operatorname{Inn}(G) \\normsubgroup \\Aut(G)$\n  \\end{enumerate}\n\\end{lem*}\nAlso note that the quotient $\\Aut(G)/\\operatorname{Inn}(G)$ is called\nthe group of outer automorphisms of $G$.\n\\begin{proof}\n  Proved in class but ommitted here.\n\\end{proof}\n\\begin{example*}[1.1.32]\n  \\begin{enumerate}\n  \\item $G$ group, $\\operatorname{Inn}(G) = \\{id\\}$ if and only if $G\n    = Z(G)$ if and only if $G$ is abelian.\n  \\item $\\operatorname{Inn}(\\Sym_n) \\isom \\Sym_n$ if $n \\geq 3$ since\n    $Z(\\Sym_n) = id$ by 1.1.4.\n  \\item $\\Aut(\\Sym_3) = \\operatorname{Inn}(\\Sym_3)$.\n  \\item With some more work, one can show that\n    $\\operatorname{Inn}(\\Sym_n) = \\Aut(\\Sym_n)$ if $n \\geq 3$ and $n\n    \\neq 6$. Also, $\\Sym_6$ has 2 outer automorphisms.\n  \\end{enumerate}\n\\end{example*}\n\\begin{rmk*}[1.1.33]\n  \\begin{enumerate}\n  \\item If $\\alpha \\in \\Aut(G)$ and $g \\in G$, then $|\\alpha(g)| =\n    |g|$.\n  \\item $\\alpha \\in \\Aut(G) \\implies \\alpha(Z(G)) = Z(G)$.\n  \\item $\\alpha \\in \\Aut(G) \\implies \\alpha([G,G]) = [G,G]$.\n  \\end{enumerate}\n\\end{rmk*}\nProofs of these remarks were discussed in class but omitted here.\n\\begin{defn*}\n  A subgroup $H \\subgroup G$ is called a characteristic subgroup of\n  $G$ if $\\alpha(H) = H, \\forall \\alpha \\in \\Aut(G)$. We denote this $\n  H \\Char G$.\n\\end{defn*}\nSome examples are $\\{e\\}, G, Z(G), [G,G]$.\n\\begin{lem*}[1.1.35]\n  Let $G$ be a group and $A,B,H \\subgroup G$.\n  \\begin{enumerate}\n  \\item $H \\Char G \\implies H \\normsubgroup G$.\n  \\item $A \\subgroup H, A \\Char H \\Char G \\implies A \\Char G$.\n  \\item $A \\subgroup H, A \\Char H \\normsubgroup G \\implies A\n    \\normsubgroup G$.\n  \\item $A \\Char G, B \\Char G \\implies [A,B] \\Char G$.\n  \\end{enumerate}\n\\end{lem*}\n\\begin{example*}[1.1.36]\n  \\item $G = \\Z_2 \\times \\Z_2$. Then, any rder 2 subgroup of $G$ is\n    normal but not characteristic. \n  \\item $G = \\Sym_4, H = \\{id, (12)(34), (13)(24), (14)(23)\\}\n    \\normsubgroup \\Sym_4$. Then $H = [A_4,A_4] \\Char A_4 =\n    [\\Sym_4,\\Sym_4] \\Char \\Sym_4$ so we get that $H \\Char\n    \\Sym_4$. Take heed, though. Let $A = \\{id, (12)(34)\\}\n    \\normsubgroup H \\Char \\Sym_4$. This does not mean $A \\normsubgroup\n    \\Sym_4$. In fact, this is false. In particular, $\\normsubgroup$ is\n    not a transitive relationship. \n\\end{example*}\n\\subsection*{Lecture 5: Finite Cyclic Groups}\nWe start by recounting some basic facts about finite cyclic groups. If\n\\(G=\\langle x\\rangle\\) where \\(|x|=n\\) then \\(G \\isom \\Z_n\\) with the map\n\\[x^n \\longleftrightarrow \\bar{a}.\\] Then the order of \\(\\bar{a}\\) is given by\n\\[|\\bar{a}|=\\frac{n}{(n,a)}.\\] We now show that the generators of \\(\\Z_n\\) are\nthose elements relatively prime to \\(n\\).\n\\begin{align*}\n  \\Z_n = \\langle \\bar{a} \\rangle &\\iff |\\bar{a}|=n\\\\\n                                 &\\iff \\frac{n}{(n,a)}=n\\\\\n                                 &\\iff (n,a)=1.\n\\end{align*}\nAnother fact is that \\(\\Z_n\\) has a unique subgroup of order \\(d\\) for each\ndivisor \\(d\\) of \\(n\\).\n\\begin{lem*}[1.2.1] Let \\(R\\) be a ring with \\(1\\).\n  \\begin{enumerate}\n  \\item[(a)] For any \\(r \\in R\\) the map\n    \\begin{align*}\n      \\lambda_r \\colon R &\\to R\\\\\n      r &\\mapsto rx\n    \\end{align*}\n    defines a homomorphism of the abelian group \\((R,+)\\).\n  \\item[(b)] For any \\(r \\in R^\\times\\), \\(\\lambda_r \\in \\Aut(R,+)\\) and\n    \\begin{align*}\n      \\lambda \\colon R^\\times &\\to \\Aut(R,+)\\\\\n      r &\\mapsto \\lambda_r\n    \\end{align*}\n    is an injective group homomorphism.\n  \\end{enumerate}\n\n\\end{lem*}\n\\begin{prop*}[1.2.2]\n  \\[\\Aut(\\Z_n) \\isom \\Z_n^\\times\\]\n\\end{prop*}\n\\begin{proof}\n  By Lemma 1.2.1 we have \\(\\lambda \\colon \\bar{a} \\mapsto \\lambda_{\\bar{a}}\\) is\n  an injective group homomorphism. Thus we simply must show that it is\n  surjective, we will use an order argument. Take any \\(\\alpha \\in \\Aut(\\Z_n)\\)\n  since \\(|\\bar{1}|=n\\) this means that \\(|\\alpha(\\bar{1})|=n\\). Thus\n  \\(|\\Aut(\\Z_n)| \\le \\varphi(n)\\).\n\\end{proof}\n\n\\begin{prop*}[1.2.3]{Chinese Reminder Theorem}\n  Let \\(m,n \\in \\N\\).\n  \\begin{enumerate}\n  \\item[(a)] The map\n    \\begin{align*}\n      f \\colon \\Z_{mn} &\\to \\Z_n \\times \\Z_m\\\\\n      [a]_{mn}&\\mapsto [a]_m \\times [a]_n\n    \\end{align*}\n    is a ring homomorphism.\n  \\item[(b)] If \\((m,n)=1\\) then \\(f\\) is a ring isomorphism.\n  \\end{enumerate}\n\\end{prop*}\n\\begin{proof}[Proof of (a)]\n  Just a routine calculation.\n\\end{proof}\nNotice that this homomorphism sends \\(1\\) to \\(1\\), which needn't be the case in\ngeneral for a ring homomorphism.\n\\begin{proof}[Proof of (b)]\n  Notice that \\(f\\) is surjective through order considerations. Now check that\n  the kernel is trivial.\n\\end{proof}\nConsequences of b: If \\(n=\\primedecomposition{p}{e}{r}\\) where\n\\(p_1,\\ldots,p_r\\) are distinct primes and \\(e_i \\in \\N\\). Then\n\\[\\Z_n \\isom \\prod_{i-1}^r \\Z_{{p_i}^{e_i}}.\\]\nOne can prove this by using the Chinese Reminder Theorem and induction on r.\n\\begin{cor*}[1.2.4]\n  Let \\(m,n \\in \\N\\) with \\((m,n)=1\\).\n  \\begin{enumerate}\n  \\item[(a)] \\(Z_{mn}^\\times \\isom \\Z_m^\\times \\times \\Z_n^\\times\\). If\n    \\(n=\\primedecomposition{p}{e}{r}\\) then\n    \\[\\Z_n^\\times \\isom \\prod_{i-1}^r \\Z^\\times_{{p_i}^{e_i}}.\\]\n  \\item[(b)]\n    \\(\\varphi(mn)=|\\Z_{mn}^\\times|=|\\Z_{m}^\\times\\times\n    \\Z_{n}^\\times|=|\\Z_{m}^\\times||\\Z_{n}^\\times|=\\varphi(m)\\varphi(n)\\).\n  \\end{enumerate}\n\\end{cor*}\n\\begin{prop*}[1.2.5]\n  For \\(e \\in \\N\\)\n  \\begin{enumerate}\n    \\item[(a)] \\(\\Z_{2^e}^\\times \\isom \\Z_2 \\times \\Z_{2^{e-2}},\\ e \\ge 2\\)\n    \\item[(b)] \\(\\Z_p^\\times \\isom \\Z_{p-1}\\) for every prime \\(p\\)\n    \\item[(c)] \\(\\Z_{p^e}^\\times \\isom \\Z_{p^{e-1}(p-1)} \\isom \\Z_{p^{e-1}} \\times \\Z_{p-1} \\) for every prime p\n  \\end{enumerate}\n\\end{prop*}\n\n\\subsection*{Lecture 6: Fundamental\n  Theorem of Finitely Generated Abelian\n  Groups}\n\n\\begin{thm*}[1.2.6 (Cauchy's Theorem)]\n  Let \\(A\\) be an abelian group of\n  finite order. If a prime \\(p\\) divides\n  the order of \\(A\\), there exists an\n  element \\(a \\in A\\) of order \\(p\\).\n\\end{thm*}\n\n\\begin{proof}\n  We will proceed by induction on\n  \\(|A|\\). If \\(|A|=p\\), then\n  \\(A \\isom \\Z_p\\), which means every\n  nontrivial element has order\n  \\(p\\). If \\(|A| > p\\) we may choose an\n  \\(x \\in A/\\{e\\}\\). Notice that\n  \\(|x| > 1\\).\n\n  \\noindent Case 1:\\\\\n  \\(p \\mid n \\implies |a|=p\\) for\n  \\(a=x^{\\frac{n}{p}} \\in \\langle x\n  \\rangle \\subset A\\)\\\\\n\n  \\noindent Case 2:\\\\ \\(p\\) does not\n  divide \\(n\\). Let\n  \\(B=\\langle x \\rangle \\normsubgroup\n  A\\), and \\(\\bar{A}=A /B\\). Then\n  \\[|\\bar{A}|=\\frac{|A|}{|B|}=\\frac{|A|}{n}.\\]\n  Furthermore since \\(p \\mid |A|\\)\n  \\[p \\mid |A| \\implies p \\mid\n    \\frac{n|A|}{n}\\] but since \\(p\\)\n  does not divide \\(n\\) we have that\n  \\[p \\mid \\frac{|A|}{n}\\implies p \\mid\n    |\\bar{A}|.\\] Now \\(|\\bar{A}|\\) is a\n  small group than \\(A\\), hence we may\n  apply the inductive hypothesis, that\n  is there exists some \\(y \\in \\bar{A}\\)\n  of order \\(p\\). As the projection map\n  \\(\\pi\\) is surjective there must exist\n  some \\(z \\in A\\) such that\n  \\(\\pi(z)=y\\). Since \\(\\pi\\) is a\n  homomorphism \\(|y| \\mid |z|\\), which\n  means \\(p \\mid z\\), hence \\(z=pm\\) for\n  some \\(m \\in \\Z\\). Thus\n  \\(a=z^{\\frac{m}{p}}\\) is an element of\n  order \\(p\\) in \\(A\\).\n\\end{proof}\n\n\\begin{prop*}[1.2.7]\n  If \\(A\\) is a finite abelian group and\n  \\(m \\in \\N\\) with \\(m \\mid |A|\\), then\n  \\(A\\) has a subgroup of order \\(m\\).\n\\end{prop*}\n\\begin{proof}\n  We again proceed by induction. The\n  case in which \\(|A|=1\\) is\n  trivial. Assume \\(|A|>1\\) and\n  \\(m>1\\). Choose any prime divisor\n  \\(p\\) of \\(m\\). By Cauchy's Theorem\n  there exists an \\(a \\in A\\) of order\n  \\(p\\). Set\n  \\(B=\\langle a\\rangle \\unlhd A\\), then\n  \\[|\\bar{A}|=\\frac{|A|}{|B|}=\\frac{|A|}{p}.\\]\n  As \\(m \\mid |A|\\) we have that\n  \\[\\frac{m}{p} \\mid \\frac{|A|}{p}\n    \\implies \\frac{m}{p} \\mid\n    \\frac{|A|}{|\\bar{A}|}.\\] Now apply\n  the inductive hypothesis on\n  \\(\\bar{A}\\), that is, there exists a\n  subgroup \\(\\bar{H} \\le \\bar{A}\\) of\n  order \\(p\\). We now invoke the\n  Correspondence Theorem, thus there\n  exists \\(H \\le A\\) with\n  \\(\\bar{H}=H/B\\). Then\n  \\[|H|=\\frac{m}{p}=\\frac{|H|}{|B|}=\\frac{|H|}{p}\n    \\implies |H|=m.\\]\n\\end{proof}\n\n\\begin{cor*}[1.2.8]\n  Given a finite abelian group \\(A\\)\n  with\n  \\(|A|=\\primedecomposition{p}{e}{r}\\)\n  there exists subgroups \\(B_i \\le A\\)\n  for \\(1 \\le i \\le r\\) with\n  \\(|B_i|=p_i^{e_i}\\) and\n  \\[A = B_1 \\times \\ldots \\times B_r\\] moreover\n  \\(B_i = \\{a \\mid |a| \\text{ is a power\n    of } p_i\\}\\).\n\\end{cor*}\n\n\\begin{proof}\n  Subgroups \\(B_i\\) with\n  \\(|B_i|=p_i^{e_i}\\) exist due to\n  1.2.7.\n  \\[A \\text{ is abelian} \\implies B_i\n    \\normsubgroup A,\\ \\forall 1 \\le i\n    \\le r\\]\n  \\[\\prod|B_i| = |A| \\qquad \\bigcap B_i\n    = \\{e\\} \\implies A = B_1 \\times\n    \\ldots \\times B_r\\] Now we show\n  uniqueness:\n  \\(A \\isom B_1 \\times \\ldots \\times\n  B_r\\) as an external direct product\n  which means elemetns of \\(A\\) come as\n  tuples \\((b_1,\\ldots,b_r)\\), then\n  \\[|a|=|(b_1,\\ldots,b_r)|=\\text{lcm}(b_1,\\ldots,b_r),\\]\n  which means \\(|a|\\) is a power of\n  \\(p_i\\). (this needs clarification)\n\\end{proof}\n\n\\begin{rmk*}\n  \\(B_i\\) are Sylow \\(p_i\\)-subgroups of\n  \\(A\\)\n\\end{rmk*}\n\n\\begin{prop*}[1.2.9]\n  Let \\(A\\) be a finite abelian group of\n  order \\(n\\).\n  \\begin{enumerate}\n  \\item[(a)] If \\(A\\) is cyclic, and\n    \\(m \\in \\N\\), then\n    \\[|\\{a \\in A \\mid a^m = e\\ (|a| \\mid\n      m)\\}| =\n      \\begin{cases}\n        m   &  m \\mid n\\\\\n        <m & m \\text{ does not divide }\n        n\n      \\end{cases}\n    \\]\n  \\item[(b)] If ( for every $m$ s.t. \\(m \\mid n\\), we have\n    \\(|\\{a \\in A \\mid a^m = e\\}| \\le\n    m\\)), then \\(A\\) is cyclic.\n  \\end{enumerate}\n\\end{prop*}\n\\begin{proof}\n  Homework Three\n\\end{proof}\n\n\\begin{thm*}[1.2.10 (The Fundamental Theorem of Finitely Generated Abelian Groups)]\n  Let \\(A\\) be a finite abelian group\n  with\n  \\(|A|=\\primedecomposition{p}{e}{r}\\). Then\n  for each \\(i\\) there exists a uniquely\n  determined \\(l_i \\in \\N\\) such that\n  \\(m_{i1} < m_{i2} < \\ldots <\n  m_{il_i}\\) that partitions \\(e_i\\) by\n  \\(e_i=m_{1i}+\\ldots+m_{il_i}\\) and\n  \\[A \\isom (\\Z_{{p_1}^{m_{11}}} \\times\n    \\Z_{{p_1}^{m_{12}}} \\cdots \\times\n    \\Z_{{p_1}^{m_{1l_1}}}) \\times \\cdots\n    \\times (\\Z_{{p_r}^{m_{r1}}} \\times\n    \\Z_{{p_r}^{m_{r2}}} \\cdots \\times\n    \\Z_{{p_r}^{m_{rl_r}}}).\\]\n\\end{thm*}\n\n\\begin{rmk*}\n  Checkout Dummit and Foote 6.1 page\n  197. For a proof that every abelian\n  \\(p\\)-group is a direct product of\n  cyclic \\(p\\)-groups.\n\\end{rmk*}\n\n\\begin{example*}\n  Classification up to isomorphism of\n  all abelian groups of order\n  \\(75\\). First notice that\n  \\(72=2^3 \\cdot 3^2\\). The looking at\n  the partitions of the exponents\n  yields:\n  \\[\\Z_8,\\ \\Z_4 \\times \\Z_2,\\ \\Z_2\n    \\times \\Z_2 \\times \\Z_2\\] and,\n  \\[\\Z_9, \\Z_3 \\times \\Z_3.\\]\n  This yields six total possibilities,\n  furthermore by uniqueness these are\n  exactly the abelian groups of order\n  \\(75\\).\n\\end{example*}\n\n\\begin{rmk*}[1.2.11]\n  Every abelian group is also a\n  \\(\\Z\\)-module. (which is a\n  generalization of a vector space,\n  instead of working with a field, we\n  weaken the condition to working with a\n  ring).\n  \\begin{align*}\n    \\Z \\times A &\\longrightarrow A\\\\\n    (m,a)& \\mapsto ma\n  \\end{align*}\n  Where\n  \\[ma =\n    \\begin{cases}\n      \\underbrace{a+a+\\ldots+a}_{m \\text{ times}} & m > 0\\\\\n      0 & m=0\\\\\n      \\underbrace{(-a)+(-a)+\\ldots+(-a)}_{-m\n        \\text{ times}} & m < 0\n    \\end{cases}.\n  \\]\n\\end{rmk*}\nOne can check that this construction\nsatisfies the axioms of a\n\\(\\Z\\)-module. An abelian group is\nfinitely generated if and only if the\ncorresponding \\(\\Z\\)-module is finitely\ngenerated. That is to say the structure\nof finitely generated abelian groups is\ndetermined by finitely generated\n\\(Z\\)-modules.\n\n\\begin{defn*}[1.2.12]\n  An \\emph{elementary abelian $p$-group}, $A$, is an abelian $p$-group such that\n  \\(|a|=p\\) for all \\(a \\in A \\smallsetminus \\{e\\}\\).  (In OUR class, p-groups are *finite* by definition, but elementary abelian p-groups *can* be infinite.  In the REAL WORLD, p-groups can be infinite by definition.)\n\\end{defn*}\n\n\\begin{rmk*}[1.2.13]\n  $A$ is an elementary \\(p\\)-group iff it\n  is a vector space over\n  \\(\\Fp\\). This allows us to import\n  linear algebra. We define the scalar\n  multiplication by\n  \\begin{align*}\n    \\Fp \\times A &\\longrightarrow A\\\\\n    (\\bar{m},a) &\\longmapsto ma\n  \\end{align*}\n  This is well defined since if\n  \\(\\bar{m} = n \\in \\Fp\\) then there\n  exists \\(k\\) such that \\(n=m+kp\\)\n  which means\n  \\(na=(m+kp)a=ma+k(pa)=ma+k(0)=ma\\). Next\n  notice that any group homomorphism\n  \\(f \\colon A \\to A\\) is automatically\n  \\(\\Fp\\)-linear:\n  \\(f(\\bar{m}a)=\\bar{m}f(a)\\).\n\\end{rmk*}\n\n\\begin{cor}[1.2.14]\n  Let \\(A\\) be an elementary abelian\n  \\(p\\)-group.\n  \\begin{enumerate}\n  \\item[(a)] \\(A\\) is a direct sum of\n    copies of \\(\\Z_p\\)\n  \\item[(b)]\n    \\(\\Aut(A) \\isom \\GL(A)=\\{f \\colon A\n    \\to A \\mid f \\text{ is a\n      bijection}\\}\\) $<--$ this is not true.  not any permutation on the elements of A can be an automorphism of A.  Firstly, the identity must be fixed.  Secondly, if $f(a) = b$, then it is entirely necessary that $f(a+a) = b+b$.  So the choice of where one element gets sent will determine where other elements must be sent.  I think what was intended is this:  If A is written as the direct sum of copies of $Z_p$, then any permutation of the $Z_p$'s is an automorphism.\n  \\end{enumerate}\n\\end{cor}\n\nImplications for elementary abelian\n\\(p\\)-groups: \\(\\Aut(A) \\isom \\GL_n(\\Fp)\\), where $n$ is the number of copies of $\\Z_p$ in $A$.\n\\begin{enumerate}\n\\item[(a)] \\(A\\) has a basis\n  \\(\\{x_i \\mid i \\in I\\}\\)\n\\item[(b)] Any additive group is \\(\\Fp\\)\n  linear.\n  \\[\\GL(A) \\subseteq \\Aut(A),\\ \\Aut(A)\n    \\subseteq \\GL(A).\\]\n\\end{enumerate}\n\n\\begin{example*}\n  \\begin{gather*}\n    \\Aut(\\Z_2 \\times \\Z_2) \\isom S_3 \\isom \\GL_2(\\mathbb{F}_2)\\\\\n    \\Aut(\\Z_2 \\times \\Z_2 \\times \\Z_2)\n    \\isom \\GL_3(\\mathbb{F}_2)\n    \\rightsquigarrow \\text{order 168}\n  \\end{gather*}\n\\end{example*}\n\n\\subsection*{Lecture 7: Nilpotent and Solvable Groups}\n\n\\begin{defn*}[1.3.1]\n  \\begin{enumerate}\n  \\item[(a)] The \\emph{lower central series} is defined inductively as follows:\n    \\begin{align*}\n      G^{[0]} &:= G\\\\\n      G^{[1]} &:= [G,G]\\\\\n      &\\vdots\\\\\n      G^{[i+1]} &:= [G,G^{[i]}].\n    \\end{align*}\n    \\(G\\) is called \\emph{nilpotent} if there exists \\(n \\in \\N\\) such that \\(G^{[n]}=1\\). And \\(G\\) is \\emph{nilpotent}\n    of class \\(c\\), if \\(c\\) is the smallest natural number such that \\(G^{[c]}=1\\).\n  \\item[(b)] The \\emph{derived series} of \\(G\\) is defined inductively as follows:\n    \\begin{align*}\n      G^{{0}} &:= G\\\\\n      G^{(1)} &:= [G,G]\\\\\n      &\\vdots\\\\\n      G^{(i+1)} &:= [G^{(i)},G^{(i)}].\n    \\end{align*}\n    \\(G\\) is called \\emph{solvable} if there exists \\(n \\in \\N\\) such that \\(G^{(n)}=1\\).\n  \\end{enumerate}\n\\end{defn*}\n\\begin{rmk*}[1.3.2]\n  The next facts follow directly:\n  \\begin{enumerate}\n  \\item \\(G^{(i)} \\subset G^{[i]}\\). This means that nilpotent \\(\\implies\\) solvable.\n  \\item \\(G\\) abelian \\(\\implies [G,G]=e \\implies \\) G is nilpotent.\n  \\item \\(G\\) is nilpotent of class \\(2\\) \\(\\iff\\) \\([G,G] \\neq 1\\) and \\([G,G^{[1]}]=e\\) \\(\\implies G^{[1]} \\le Z(G)\\).\n  \\end{enumerate}\n\\end{rmk*}\n\n\\begin{lem*}[1.3.3]\n  Take \\(G \\neq 1\\).\n  \\begin{enumerate}\n  \\item[(a)] \\(G\\) is nilpotent \\(\\implies\\) \\(Z(G) \\neq 1\\)\n  \\item[(matt)] Every term in a derived series is characteristic in $G$.  This is true because $[G,G]$ is characteristic in $G$, and ``characteristic'' is a transitive property, so we can induct downwards.\n  \\item[(b)] \\(G\\) is solvable \\(\\implies\\) there exists an abelian subgroup \\(A \\neq 1\\) with A characteristic in \\(G\\).\n  \\end{enumerate}\n\\end{lem*}\n\n\\begin{example*}[1.3.4]\n  \\begin{enumerate}\n  \\item[] % make spacing nicer\n  \\item[(a)] \\(Z(Q)=\\{-1,1\\}=[Q,Q]\\), hence \\(Q\\) is nilpotent of class \\(2\\).\n  \\item[(b)] \\(S_n\\) is not nilpotent \\(n \\ge 3\\). Since \\(Z(S_n)=1\\). \\(S_3,S_4\\) are solvable. \\(S_3^{(1)}=A_3\\) and\n    \\(S_3^{(2)}=1\\). \\([S_n,S_n]=A_n,[A_n,A_n]=A_n\\).  The very last statement is false.  This is because \\([A_3,A_3]=1\\).  Maybe he meant to add the condition that $ n \\geq 5$.\n  \\item[(c)] \\(A_4\\) is solvable, non-nilpotent. \\(S_n,A_n\\) are not solvable \\(n \\ge 5\\).\n  \\item[(e)] If \\(|G| < 60\\), then \\(G\\) is solvable. If \\(|G|=60\\) and \\(G\\) is not solvable, then \\(G \\isom\n    A_5\\).\n  \\item[(matt)] Every solvable simple group is solvable of class 1. (And nilpotent of class 1)\n  \\item[(f)] Let \\(F\\) be a field, then define\n    \\[U_n(F) := \\left\\{\n       \\left.\\left( \\begin{array}{c c c}\n          1 & & \\star\\\\\n           & \\ddots \\\\\n          0& & 1\n        \\end{array}\\right)\\:\\right\\rvert \\ \\star \\in F \\right\\} \\le \\GL_n.\\]\n  \\(U_n(F)\\) is nilpotent.\n  \\item[(g)] Define \\(B_n(F)\\) as above, but instead of 1s on the diagonal allow any unit of \\(F\\). \\(B_n(F)\\) is\n    solvable, but potent for \\(n \\ge 2\\) and \\(F \\neq F_2\\).\n  \\end{enumerate}\n\\end{example*}\n\\begin{prop*}\n  If \\(G\\) is a finite \\(p\\)-group, then \\(G\\) is nilpotent.\n\\end{prop*}\n\\begin{thm}[Burnside's Theorem]\n  If \\(|G|=p^mq^n\\), then \\(G\\) is solvable.\n\\end{thm}\n\\begin{thm}[Feit–Thompson theorem]\n    Every finite group of odd order is solvable.  (this is an extension of the previous theorem)\n\\end{thm}\n\\begin{prop*}[1.3.5]\n  If \\(G\\) is nilpotent and \\(H < G\\), then \\(N_G(H)\\neq H\\).\n\\end{prop*}\n\\begin{defn*}[1.3.6]\nA sequence of homomorphisms\n\\[\\ldots \\to \\ldots  G_{i-1} \\xrightarrow{f_{i-1}}G_i \\xrightarrow{f_i} G_{i+1} \\to \\ldots \\to \\ldots\\]\nis called \\emph{exact} if \\(\\text{im}(f_{i-1})=\\ker(f_i)\\) for each \\(i\\). A sequence is a short exact sequence\n(SES) if it is exact and takes the form:\n\\[1 \\to N \\xrightarrow{f_1} G \\xrightarrow{f_2} Q \\to 1.\\]\n\\end{defn*}\nExactness means:\n\\begin{enumerate}\n\\item \\(f_1\\) is injective\n\\item \\(f_2\\) is surjective\n\\item \\(G/f_1(N) \\isom Q\\)\n\\end{enumerate}\n\n(still more to be said)\n\n\\subsection{I.5 Group Actions}\n\n\\begin{defn*}[1.5.1]\n  Given a group \\(G\\) and set \\(X\\) we say that \\(G\\) \\emph{acts} on \\(X\\) (on the left)\n  if\n  \\begin{align*}\n    G &\\times X \\to X\\\\\n      &(g,x) \\mapsto g\\cdot x\n  \\end{align*}\n  \\begin{enumerate}\n  \\item[i.] \\(g(h\\cdot x)=(gh)\\cdot x\\) for all \\(g,h \\in G\\) and \\(x \\in X\\)\n  \\item[ii.] \\(e\\cdot x = x\\)\n  \\end{enumerate}\n\\end{defn*}\n\\noindent Consequences:\\\\\nFor each \\(g \\in G\\), we have a map\n\\begin{align*}\n  \\pi_g &\\colon X \\to X\\\\\n  x &\\mapsto g \\cdot x\n\\end{align*}\n\\begin{enumerate}\n\\item[(i)] says that \\(\\pi_g \\circ \\pi_h = \\pi_{gh}\\)\n\\item[(ii)] says that \\(\\pi_g \\pi_{g^{-1}} = 1_X\\)\n\\end{enumerate}\nThus we have that \\(\\pi_g\\) is a bijection, hence \\(\\pi_g\\) really is a permutation of \\(X\\).\n\\[\\varphi \\colon G \\to S(X)=\\{G \\colon X \\to X | G \\text{ is a bijection}\\}\\]\nHence \\(\\varphi\\) is a group homomorphism.\n\\begin{align*}\n  G \\times X &\\to X\\\\\n  (g,x) &\\mapsto \\varphi(g)(x)\n\\end{align*}\nConcepts: G acts on \\(X\\) \\(\\iff\\) there is a homomorphism from \\(G \\to S(X)\\).\n\\begin{defn*}[1.5.2]\n  The action of \\(G\\) on \\(X\\) is \\emph{faithful} if \\(\\ker\\varphi = 1\\).\n\\end{defn*}\n\\begin{example}[1.5.4]\n  \\begin{enumerate}\n    \\item[a.] \\(S_n\\) acts on \\(X=\\{1,\\ldots,n\\}\\), \\(\\varphi\\) is the identity\n    \\item[b.] \\(\\GL_n(\\mathbb{F})\\) acts on \\(\\mathbb{F}^n\\) (column vectors)\n    \\item[c.] IF \\(G\\) acts on \\(X\\), and \\(H \\le G\\) then \\(G\\) acts on \\(H\\) also\n      \\begin{align*}\n        \\varphi \\colon G &\\to S(X)\\\\\n        \\varphi|_H \\colon H &\\to S(X)\n      \\end{align*}\n    \\item[d.] \\(G\\) acts on the set \\(X=G\\) by left multiplication\n      \\begin{align*}\n        G \\times G &\\to G\\\\\n        (g,x) &\\mapsto gx\n      \\end{align*}\n      Here \\(\\pi_g\\) is just a permutation, and not a group homomorphism we ignore the extra structure.\n    \\item[e.] If \\(H \\le G\\) we can consider action \\(G\\) on \\(X=G/H\\), by left multiplication.\n      \\lambdadeclaration{G\\times G/H}{G/H}{(g,g'H)}{(gg')H}\n    \\item[f.] \\(G\\) acts on the group. \\(X=G\\) by conjugation\n      \\lambdadeclaration{G \\times G}{G}{(g,x)}{gxg^{-1}}\n  \\end{enumerate}\n\\end{example}\n\n\\subsection{Sylow Consequences to Know}\n\\newcommand{\\syl}{\\text{Syl}}\n\\begin{prop*}{1.7.6}\n  \\(P \\in \\syl_p(G) \\implies N_G(N_G(P))=N_G(P)\\)\n\\end{prop*}\n\n\\begin{thm*}{1.7.7}\n  Let \\(G \\neq \\{e\\}\\) be a finite group. If \\(p_1, \\ldots p_r\\) are the distinct prime divisors of \\(|G|\\) then the\n  following are equivalent (where \\(P_i \\in \\syl_{p_i}(G)\\)):\n  \\begin{enumerate}\n  \\item \\(G\\) is nilpotent\n  \\item \\(H \\neq N_G(H)\\) for all \\(H < G\\)\n  \\item \\(\\forall P_i \\unlhd G \\implies G = P_1 \\times \\ldots \\times P_r\\) \n  \\end{enumerate}\n\\end{thm*}\n\n\\begin{lem*}{1.7.8}\n  \\(|G|=p^e m\\) with \\(p > m \\implies n_p = 1\\).\n\\end{lem*}\n\n\\begin{prop*}{1.7.9}\n  If \\(|G|=pqr\\) with \\(p > q > r\\) then \\(P,PQ \\unlhd G\\) furthermore\n  \\[G (P \\rtimes Q) \\rtimes R \\cong (\\Z_p \\rtimes \\Z_q) \\rtimes \\Z_r.\\]\n\\end{prop*}\n\n\\begin{prop*}\n  If \\(|G|=p^em\\) with \\(m > p\\) and \\(p\\) does not divide either \\(m\\) or \\((m-1)!\\) then \\(G\\) is not simple.\n\\end{prop*}\n\n\\subsection*{Free Groups and Presentations}\n\nLet \\(X\\) be a non-empty set. Define \\(X^{-1}=\\{x^{-1} \\mid x \\in X\\}\\) with \\(X \\cap X^{-1} = \\emptyset\\) and where\nthere exists an injection \\(X \\to X^{-1}\\). Set \\(Y = X \\coprod X^{-1}\\). There define \\(\\iota \\colon Y \\to Y\\) by\n\\begin{align*}\n  x &\\mapsto x^{-1}\\\\\n  x^{-1} &\\mapsto x\n\\end{align*}\nThink of \\(Y\\) as an alphabet and \n\\[W(X)=\\{(y_1,\\ldots,y_n) \\mid n \\in \\N, y_i \\in Y\\}\\]\nas the set of words over that alphabet. For convenience we write \\(y_1\\cdots y_n\\) for \\((y_1,\\ldots,y_n)\\). We may\ndefine an associative multiplication on \\(W(x)\\) by\n\\[(y_1,\\ldots,y_n)(y_{n+1},\\ldots,y_m)=(y_1,\\ldots,y_n,y_{n+1},\\ldots,y_m).\\]\nThen \\(W(X)\\) is a free monoid on \\(Y\\).\n\n\\begin{defn*}\n  Words \\(v,w \\in W(X)\\) are \\emph{elementary equivalent} if either one of the following hold:\n  \\begin{enumerate}\n  \\item \\(w=w_1w_2\\) and \\(v=w_1y y^{-1}w_2\\)\n  \\item \\(w=w_1y^{-1}yw_2\\) and \\(v=w_1w_2\\)\n  \\end{enumerate}\n\\end{defn*}\n\n\\begin{defn}\n  \\(v,w \\in W(X)\\) are \\emph{equivalent} denote \\(\\sim\\)if \n  \\begin{enumerate}\n  \\item \\(w=v\\)\n  \\item There exists a finite chain of elementary equivalences.\n  \\end{enumerate}\n\\end{defn}\n\nDenote the equivalence class of words equivalent to \\(w\\) by \\([w]\\). Now define \n\\[F(x)=W(x)/\\sim\\]\nwhere this is just given by the equivalence relation on the set \\(W(X)\\). Now define multiplication on \\(F(x)\\) by\ninheriting it \nfrom \\(W(X)\\), that is set \\([w][v]=[wv]\\). Now inversion is well defined by \\([w]^{-1}=[w^{-1}]\\). \n\\begin{defn}\n  The set \\(F(X)\\) defined above together with the multiplication \\([w][v]=[wv]\\) is called the \\emph{free group} on \\(X\\).\n\\end{defn}\n\\end{document}%\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"master.tex\"\n%%% End:\n", "meta": {"hexsha": "c1ba8e165e91df34d4860f6b4b25ad9e10b0c851", "size": 50149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "server/resources/group_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/group_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/group_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": 41.5140728477, "max_line_length": 473, "alphanum_fraction": 0.5802907336, "num_tokens": 18965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6909137897960218}}
{"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\\section{Gravity Inversion}\\label{sec:forward gravity}\nFor the gravity inversion we use the anomaly of the gravity acceleration~\\index{gravity acceleration} of the Earth.\nThe controlling material parameter is the density~\\index{density} $\\rho$ of\nthe rock.\nIf the density field $\\rho$ is known the gravitational potential $\\psi$ is\ngiven as the solution of the PDE\n\\begin{equation}\\label{ref:GRAV:EQU:100}\n-\\psi_{,ii} = -4\\pi G \\cdot  \\rho\n\\end{equation}\nwhere $G=6.6730 \\cdot 10^{-11}  \\frac{m^3}{kg \\cdot s^2}$ is the gravitational\nconstant.\nThe gravitational potential is set to zero at the top of the\ndomain $\\Gamma_0$.\nOn all other faces the normal component of the gravity acceleration anomaly\n$g_i$ is set to zero, i.e. $n_i \\psi_{,i} = 0$ with outer normal field $n_i$.\nThe gravity force $g_i$ is given as the negative of the gradient of the gravity\npotential $\\psi$:\n\\begin{equation}\\label{ref:GRAV:EQU:101}\n g_i = - \\psi_{,i} \n\\end{equation} \nFrom the gravitational potential we can calculate the gravity acceleration\nanomaly via Equation~(\\ref{ref:GRAV:EQU:101}) to obtain the defect to the\ngiven data.\nIf $g^{(s)}_i$ is a measurement of the gravity acceleration anomaly for\nsurvey $s$ and $\\omega^{(s)}_i$ is a weighting factor the data defect\n$J^{grav}(k)$ in the notation of Chapter~\\ref{chapter:ref:inversion cost function} is given as\n\\begin{equation}\\label{ref:GRAV:EQU:9}\nJ^{grav}(k) = \\frac{1}{2}\\sum_{s} \\int_{\\Omega} ( \\omega^{(s)}_i \\cdot (g_{i}- g^{(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:GRAV:EQU:10}\nK^{grav}(\\psi_{,i},k) = \\frac{1}{2}\\sum_{s} ( \\omega^{(s)}_i \\cdot (\\psi_{,i}+ g^{(s)}_i) ) ^2\n\\end{equation} \nIn practice the gravity acceleration $g^{(s)}$ is measured in vertical\ndirection $z$ with a standard error deviation $\\sigma^{(s)}$ at certain\nlocations in the domain.\nIn this case one sets the weighting factors $\\omega^{(s)}$ as\n\\begin{equation}\\label{ref:GRAV:EQU:11}\n\\omega^{(s)}_i \n= \\left\\{\n\\begin{array}{lcl}\nf \\cdot  \\frac{\\delta_{iz}}{\\sigma^{(s)}} & & \\mbox{data are available} \\\\\n& \\mbox{ where } & \\\\\n0 & & \\mbox{ otherwise } \\\\\n\\end{array}\n\\right.\n\\end{equation} \nWith the objective to control the \ngradient of the cost function \nthe scaling factor $f$ is chosen in the way that\n\\begin{equation}\\label{ref:GRAV:EQU:12}\n\\sum_{s} \\int_{\\Omega} ( \\omega^{(s)}_i g^{(s)}_i ) \\cdot ( \\omega^{(s)}_j \\frac{1}{L_j} ) \\cdot 4\\pi G L^2 \\cdot \\rho' \\;  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}). $\\rho'$ is considering the \nderivative of the density with respect to the level set function. \n\n\n\\subsection{Usage}\n\n\\begin{classdesc}{GravityModel}{domain, \nw, g,\n\\optional{, coordinates=\\None}\n\\optional{, fixPotentialAtBottom=False},\n\\optional{, tol=1e-8}\n}\nopens a gravity forward model over the \\Domain \\member{domain} with \nweighting factors \\member{w} ($=\\omega^{(s)}$) and measured gravity acceleration anomalies \\member{g} ($=g^{(s)}$).\nThe weighting factors and the  measured gravity acceleration anomalies must be vectors\nwhere components refer to the components \n$(x_0,x_1,x_2)$ for the Cartesian coordinate system \nand to $(\\phi, \\lambda, h)$ for the geodetic coordinate system. \nIf \\member{reference} defines the reference coordinate system to be used, see Chapter~\\ref{Chp:ref:coordinates}.\n\\member{tol} set the tolerance for the solution of the PDE~(\\ref{ref:GRAV:EQU:100}).\nIf \\member{fixPotentialAtBottom} is set to  \\True, the gravitational 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}[GravityModel]{rescaleWeights}{\n        \\optional{scale=1.}\n \\optional{rho_scale=1.}}\nrescale the weighting factors such condition~(\\ref{ref:GRAV:EQU:12}) holds where \n\\member{scale} sets the scale $\\alpha$\nand \\member{rho_scale} sets $\\rho'$. 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^{grav}}{\\partial \\rho}$ of the cost function $J^{grav}$ with\nrespect to the density $\\rho$ is calculated. We follow the concept as outlined in section~\\ref{chapter:ref:inversion cost function:gradient}.\nThe gravity potential $\\psi$ from PDE~(\\ref{ref:GRAV:EQU:100}) is solved in\nweak form:\n\\begin{equation}\\label{ref:GRAV:EQU:201}\n\\int_{\\Omega} q_{,i} \\psi_{,i} \\; dx  = - \\int_{\\Omega}  4\\pi G \\cdot q \\rho\\; dx \n\\end{equation} \nfor all $q$ with $q=0$ on $\\Gamma_0$.\nIn the following we set $\\Psi[\\cdot]=\\psi$ for a given density $\\cdot$ as\nsolution of the variational problem~(\\ref{ref:GRAV:EQU:201}).\nIf $\\Gamma_{\\rho}$ denotes the region of the domain where the density is known\nand for a given direction $p$ with $p=0$ on $\\Gamma_{\\rho}$ one has\n\\begin{equation}\\label{ref:GRAV:EQU:201aa}\n\\int_{\\Omega}   \\frac{\\partial J^{grav}}{\\partial \\rho} \\cdot p \\; dx  =  \\int_{\\Omega}  \n\\sum_{s} (\\omega^{(s)}_j \\cdot \n(g^{(s)}_j-g_{j}) ) \\cdot ( \\omega^{(s)}_i \\Psi[p]_{,i})  \\; dx  \n\\end{equation} \nwith \n\\begin{equation}\\label{ref:GRAV:EQU:202c}\nY_i[\\psi]=  \\sum_{s} (\\omega^{(s)}_j \\cdot \n(g^{(s)}_j-g_{j}) ) \\cdot  \\omega^{(s)}_i\n\\end{equation} \nThis is written as \n\\begin{equation}\\label{ref:GRAV:EQU:202cc}\n\\int_{\\Omega}   \\frac{\\partial J^{grav}}{\\partial \\rho} \\cdot p \\;  dx  = \\int_{\\Omega}  \nY_i[\\psi] \\Psi[p]_{,i} \\; dx  \n\\end{equation} \nWe then set $Y^*[\\psi]$ as the solution of the equation \n\\begin{equation}\\label{ref:GRAV:EQU:202d}\n\\int_{\\Omega} r_{,i} Y^*[\\psi]_{,i} \\; dx  =  \\int_{\\Omega} r_{,i} ,Y_i[\\psi]  \\; dx  \\mbox{ for all } p \\mbox{ with } r=0 \\mbox{ on } \\Gamma_{top}\n\\end{equation} \nwith $Y^*[\\psi]=0$ on $\\Gamma_0$. With $r=\\Psi[p]$ we get\n\\begin{equation}\\label{ref:GRAV: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:GRAV:EQU:201}) with $q=Y^*[\\psi]$ we get\n\\begin{equation}\\label{ref:GRAV:EQU:20e}\n\\int_{\\Omega} Y^*[\\psi]_{,i}  \\Psi[p]_{,i} \\; dx  = - \\int_{\\Omega}  4\\pi G \\cdot Y^*[\\psi] \\cdot  p\\;  dx  \n\\end{equation}\nwhich leads to \n\\begin{equation}\\label{ref:GRAV:EQU:20ee}\n\\int_{\\Omega} \\Psi[p]_{,i} ,Y_i[\\psi]  \\; dx  = - \\int_{\\Omega}  4\\pi G \\cdot Y^*[\\psi] \\cdot  p \\; dx  \n\\end{equation}\nand finally\n\\begin{equation}\\label{ref:GRAV:EQU:201a}\n\\int_{\\Omega}   \\frac{\\partial J^{grav}}{\\partial \\rho} \\cdot p \\;  dx  = - \\int_{\\Omega}  \n4\\pi G \\cdot Y^*[\\psi] \\cdot  p \\; dx  \n\\end{equation} \nor \n\\begin{equation}\\label{ref:GRAV:EQU:201b}\n\\frac{\\partial J^{grav}}{\\partial \\rho}  =- 4\\pi G \\cdot Y^*[\\psi]\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:GRAV:EQU:9}:\n\\begin{equation}\\label{ref:GRAV:EQU:300}\n\\omega^{(s)}_i \\cdot (g_{i}- g^{(s)}_i) = \\omega^{(s)}_{\\alpha} \\cdot (g_{{\\alpha}}- g^{(s)}_{\\alpha}) \n\\end{equation} \nwhere now $g^{(s)}_{\\alpha}$ are the observational data with weighting factors $\\omega^{(s)}_{\\alpha}$.  Using the \nfact that $g_{{\\alpha}} = - d_{\\alpha \\alpha} \\psi_{,\\alpha}$ \nequation~\\ref{ref:GRAV:EQU:10} translates to \n\\begin{equation}\\label{ref:GRAV:EQU:301}\nJ^{grav}(k) = \\frac{1}{2}\\sum_{s} \\int_{\\widehat{\\Omega}} \n( \\omega^{(s)}_{\\alpha} \\cdot (d_{\\alpha \\alpha}  \\psi_{,\\alpha} + g^{(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:GRAV:EQU:301bb}\nJ^{grav}(k) = \\frac{1}{2}\\sum_{s} \\int_{\\widehat{\\Omega}} \n(  \\omega^{(s)}_{\\alpha} v^{\\frac{1}{2}} d_{\\alpha \\alpha} \\cdot ( \\psi_{,\\alpha} + \\frac{1}{d_{\\alpha \\alpha}} g^{(s)}_{\\alpha} ) ) ^2 \\; d\\widehat{x}\n=\\frac{1}{2}\\sum_{s} \\int_{\\widehat{\\Omega}} \n(  {\\widehat{\\omega}}^{(s)}_{\\alpha}\\cdot ( \\psi_{,\\alpha} + \\widehat{g}^{(s)}_{\\alpha} ) ) ^2 \\; d\\widehat{x}\n\\end{equation} \nwith \n\\begin{equation}\\label{ref:GRAV:EQU:301b}\n \\widehat{\\omega}^{(s)}_{\\alpha} =\\omega^{(s)}_{\\alpha} v^{\\frac{1}{2}} d_{\\alpha \\alpha} \\mbox{ and }\n\\widehat{ g}^{(s)}_{\\alpha}=\n\\frac{1}{d_{\\alpha \\alpha}} g^{(s)}_{\\alpha}\n\\end{equation} \nwhich means one can apply the Cartesian formulation to the geodetic coordinates using modified data. \nThe gravity potential is calculated from \n\\begin{equation}\\label{ref:GRAV:EQU:302}\n\\int_{\\widehat{\\Omega}} v \\; d_{\\alpha \\alpha}^2 q_{,\\alpha} \\psi_{,\\alpha} \\;  d\\widehat{x}  \n= - \\int_{\\widehat{\\Omega}}  (4\\pi G v) \\cdot q \\rho\\;  d\\widehat{x} \n\\end{equation} \nsee equation~\\ref{ref:GRAV:EQU:201}, and the adjoint function $Y^*[\\psi]$ for $Y_{\\alpha}[\\psi]$ is given from\n\\begin{equation}\\label{ref:GRAV:EQU:303}\n\\int_{\\widehat{\\Omega}} v  \\; d_{\\alpha \\alpha}^2 q_{,\\alpha} Y^*[\\psi]_{,\\alpha } \\;d\\widehat{x}  =\n  \\int_{\\widehat{\\Omega}} q_{,\\alpha} Y_{\\alpha}[\\psi]  \\; d\\widehat{x} \n\\end{equation} \nand finally \n\\begin{equation}\\label{ref:GRAV:EQU:310}\n \\frac{\\partial J^{grav}}{\\partial \\rho}  = - \n(4\\pi G v) \\cdot Y^*[\\psi]\n\\end{equation} \n", "meta": {"hexsha": "4f7c395b84a47aae4a7e519b2dc02f1e81da6241", "size": 10119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/inversion/ForwardGravity.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/ForwardGravity.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/ForwardGravity.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": 49.6029411765, "max_line_length": 152, "alphanum_fraction": 0.6706196264, "num_tokens": 3549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6908321028403874}}
{"text": "\\lesson{3}{Oct 12 2021 Tue (10:03:31)}{Sum and Difference of Cubes}{Unit 2}\n\n\\subsubsection*{Factoring the Sums and Differences of Cubes}\n\n\\begin{example}[Factor $30c^3 - 20c^2 - 15c + 10$]\n    \\begin{align}\n        2z^3 + 250 &= 2(z^3 + 125) \\\\\n                   &= z^3 + 5^3 = (z + 5)(z^2 - z \\times 5 + 5^2) \\\\\n                   &= 2(z + 5)(z^2 - z \\times 5 + 5^2) \\\\\n    \\end{align}\n\\end{example}\n\n\\newpage\n", "meta": {"hexsha": "a7588b4c534757cbfa4ab5689bfa9be607fce891", "size": 413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-3.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-3.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-3.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5, "max_line_length": 75, "alphanum_fraction": 0.5133171913, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389113, "lm_q2_score": 0.7772998508568417, "lm_q1q2_score": 0.6908320799196719}}
{"text": "\\lab{Floating Point Numbers}{Floating Point Numbers}\n\\label{lab:IEEE}\n\\objective{Gain a basic understanding of the IEEE floating point standard.}\n\n\\section*{Introduction}\nFloating point numbers permeate modern computing, but it is not always good to use them without knowledge of what they are and how they work.\nA fundamental understanding of the inner workings of floating point numbers can be very helpful when working with a wide variety of floating point computations.\nBy far the most common floating point standard is the IEEE floating point standard described by in the standards IEEE-754-1985, IEEE-854-1987, and IEEE-754-2008.\nThese standards outline how floating point numbers are represented in binary form and how operations like addition, subtraction, multiplication, division, and rounding should work.\nMost floating point numbers are either 32 or 64 bits long.\n32 bit floating point numbers are known as \"single precision floating point numbers\" and 64 bit floating point numbers are known as \"double precision floating point numbers.\"\nThere are also 16, 128, and 256 bit versions, but they are much less common.\nFloating point numbers in Python are stored as double precision values.\nHere we will consider 32 bit floating point numbers.\n\nBefore considering any more of the details of IEEE floating point representation, it will be good to establish what a floating point number is at all.\nFloating point representation is a way of representing a number that is similar to the \"scientific notation\" commonly used to represent numbers that are extremely large or small.\nIn general, a floating point number is a number written in the form $d \\times \\beta^p$ where $\\beta \\in \\mathbb{N}, \\beta \\geq 2$ is the base used for computation, $d$ is a decimal (like 1.10110) with base $\\beta$ and $p\\in \\mathbb{Z}$ is the power of $\\beta$.\nTheoretically, for a given base $\\beta \\in \\mathbb{N}, \\beta \\geq 2$, any real number $r \\in \\mathbb{R}$ can be represented at least one way by a series of the form\n\\begin{equation*}\nr = d_0 \\beta^{p} + d_1 \\beta^{p-1} + \\dots = \\sum_{i=0}^{\\infty} d_i \\beta^{p-i}\n\\end{equation*}\nwhere the $d_i$ are the digits of a decimal number $d$.\nThis representation is not necessarily unique, but finite approximations of this sort of sum can be useful in performing actual computations.\nThe floating point representation of a number allows easy representation of real numbers, particularly when they are extremely large, or when they are not integers.\nThe normal mathematical operations on real numbers apply in the theoretical context.\n\nIn real applications, floating point numbers can be used to make an \\textit{approximate} representation of \\textit{a useful number} of real numbers.\nThere are uncountably many real numbers, so it is impossible to create a computer system that can distinguish perfectly between all of them, but that is okay since measurements are imperfect and approximate computations are usually good enough.\n\nIt is also worth noting that often, for brevity, hexadecimal numbers are used to represent integers and floating point nubmers.\nA hexadecimal number is a number base 16.\nEach digit of a hexadecimal number can be used to represent four binary digits.\nThe letters a through f are used to represent the additional 6 values needed.\nFor example a1f23 is the same as 10100001111100100011.\nPython has the built in functions \\li{bin} and \\li{hex} to convert integers to binary and hexadecimal values.\nA binary and hexadecimal numbers stored as strings can be converted to integers using the \\li{base} argument of the built in \\li{int} funciton.\nFor example \\li{int(\"a1f23\", base=16)} will return 663331, the base 10 representation of the number.\n\n\\begin{problem}\n\\begin{itemize}\n\n\\item Make a Python class representing an arbitrary precision floating point number.\nThis shouldn't be too hard since Python's integers are arbitrary precision as well, just store one integer representing the exponent in some way and another representing the significand.\nMake methods to do all of the following:\n\t\\begin{itemize}\n\n\t\\item Convert a floating point object to a Python float.\n\n\t\\item Print the floating point number correctly.\n\n\t\\item Copy the floating point number.\n\n\t\\item Perform addition of two of your floating point objects (perform all operations without any sort of rounding first).\n\n\t\\item Perform subtraction of two of your floating point objects.\n\n\t\\item Perform multiplication of two of your floating point objects.\n\n\t\\item Truncate the significand of the floating point number to remove all digits below a given power of 10.\n\n\t\\end{itemize}\n\n\\item Now, make another class using the class you just wrote that tracks errors in computation.\nTrack two values, one for the exact value, and one for the exact error.\nComputations involving the value and error should be carried out like they would be for your arbitrary precision floating point class.\nHave it track the exact value of the significand and the error until you have it truncate all digits that fall within the error.\nMake methods that do all of the following:\n\t\\begin{itemize}\n\n\t\\item Print the floating point number correctly.\n\n\t\\item Copy the floating point nubmer.\n\n\t\\item Perform addition of two of your floating point objects.\n\t\tBe sure to add the corresponding errors as well to represent that the possible range of values has increased.\n\n\t\\item Perform subtraction of two floating point objects.\n\t\tAgain, be sure to add the corresponding errors.\n\n\t\\item Perform multiplication of two floating point objects.\n\t\tHere's how you can calculate the error term:\n\t\tGiven two floating point numbers $a\\pm\\epsilon$ and $b\\pm\\delta$ where $a$ and $b$ are the values and $\\epsilon$ and $\\delta$ are the error terms, the result will be $ab \\pm a\\delta \\pm b\\epsilon \\pm \\epsilon\\delta$.\n\t\tThe first term in the expanded product will be the significand of the product and the rest will be the new error term.\n\t\tBe sure to take absolute values of $a$ and $b$ when calculating the error so that there is never a negative error term.\n\n\t\\item Truncate the floating point number to the smallest power of ten that is larger than the error term.\n\t\tSet the new error term to be this same power of ten.\n\t\t(If you want to do many different calculations involving these floating point numbers, you may, at times have to truncate the values to prevent the integer storing the significand from becoming too large.)\n\n\t\\end{itemize}\n\n\\end{itemize}\n\\end{problem}\n\n\\section*{Binary Representation}\nA 32 bit floating point number is represented by 32 bits, each storing either a 0 or a 1.\n\nThe first bit in the binary representation of a floating point number represents the sign of the number.\nIf it is 0, the number is positive.\nIf it is 1, the number is negative.\n\nThe next 8 bits are used to store the exponent of the floating point number.\nThe exponent does not have an explicit sign bit, but is instead scaled so that the counting runs from -127 to 128.\n\nThe final 23 bits are used to store the binary decimal number.\nThis portion of the number is often called the \"mantissa\" or the \"significand\".\nSince the first number of any decimal in binary is always one, the first number in the significand is assumed to be one and the bits included in the significand are used to represent the remaining digits.\n\nFor example, the following is the binary representation of the number .25.\n\n\\begin{equation*}\n\\underbrace{0}_{sign} \\underbrace{01111101}_{exponent}\\underbrace{(1.)}_{Implied 1.} \\underbrace{00000000000000000000000}_{significand}\n\\end{equation*}\n\nSince there is a limit on the number of digits used to represent the significand, rounding must occur at each step.\nThere are several possible rounding conventions, but IEEE floating point rounds the significand to the nearest even value, which in binary means that the last digit must become 0.\nFor example, using binary decimals, the value $1011011.1$ would round to $1011100$ since that is the nearest even number.\n\nSince rounding occurs after each operation, addition, subtraction, multiplication, and division behave \\textit{approximately} how they should.\nIn some cases, the usual properties you would expect from these operations do not hold.\nMore on that later.\n\nFor a double precision floating point number, there is still one bit to store the sign.\nThere are 11 bits to store the exponent, and 52 bits used to store the value (with the one still implied).\n\nFloating point operations on modern processors are heavily optimized.\nThere are built in operations that allow for addition, subtraction, multiplication, division, square roots, and several other operations.\nFloating point operations are actually a common way of measuring the performance of computer systems.\nWhat is considered a single floating point operation depends somewhat on the system.\nSome processors can perform a single addition and multiplication in a single clock cycle, so a floationg point operation is sometimes considered to be an addition and a multiplication.\nIt can also be measured as an addition or a multiplication.\n\nThe highest and lowest values in the exponent are reserved for modified numbers.\nZero is represented using the smallest exponent value (binary 0, representing a negative power of 2 since the exponent is scaled) with a significand of 0.\nWhen the exponent is as small as possible, the significand is no longer considered normalized and the implied one is no longer considered.\nThis allows for the representation of even smaller numbers, but it implies the loss of some precision.\nFor example, the following code in Python yields 0\n\\begin{lstlisting}\n1.123456789012345 * 10.**-306 * 10.**153 * 10.**153 - 1.123456789012345\n\\end{lstlisting}\nWhile this yields -0.0365123681616.\n\\begin{lstlisting}\n1.123456789012345 * 10.**-322 * 10.**161 * 10.**161 - 1.123456789012345\n\\end{lstlisting}\nNumbers represented in this way are called \"denormalized numbers\" or \"subnormal numbers.\"\nFloating point zero is also still allowed to have a sign, so for example, \\li{-0.} is valid in Python and prints as \\li{-0.0}.\n\\li{0.} is considered equal to \\li{-0.}, but the sign still carries through in multiplication, so for example \\li{-0. *  0.} is \\li{-0.}.\nThere are no analogues of the denormalized numbers.\nThe values of the highest exponent are used to store different kinds of infinity and \"nan\" values (nan stands for \"not a number\").\nIEEE floating point allows for both negative and positive infinity.\n\\li{nan} values are defined to never be equal to one another.\nPositive and negative infinity can be used for equality testing, for example, the following returns \\li{True}.\n\\begin{lstlisting}\na = (10.**300)\na *= a # a is now positive infinity\na == a\n\\end{lstlisting}\n\n% see how they measure it at http://software.intel.com/en-us/articles/estimating-flops-using-event-based-sampling-ebs\n\n\\section*{Fast Approximation of the Square Root}\n% An amusing application, see http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Approximations_that_depend_on_IEEE_representation\nThere are a variety of flaws involved with floating point computations, but those will be discussed in a later lab.\nHere we will present an example of a clever manipulation of the IEEE floating point format.\nAround the end of the 90's an algorithm was discovered which can give a quick approximation of the square root of a number.\nIt takes advantage of the layout of the bits in the IEEE floating point standard.\nThe main idea of it is that the exponent of a binary floating point number $d$ can be used as a rough approximation of the number $\\log_2\\left(d\\right)$.\nIn performing this computation, we must account for the fact that the exponent has been scaled to allow representation of negative numbers.\nThe smallest exponent for 32 bit floating point integers is $-2^7 - 1 = -127$.\nSince a floating point number has 23 bits in the significand, scaling the exponent can be represented in integer form as addition of $2^{30} - 2^{23}$.\nOnce we have scaled the exponent, we can divide it by two.\nWe then scale the exponent back to its original value.\nWith some extra arithmetic, the two scaling values can be reduced into the addition of a single constant.\nWhen all is said and done, some simple code to calculate the square root of a function looks like this:\n\\begin{lstlisting}\ndef pysqrt32(A, reps):\n    Ac = A.copy()\n    I = Ac.view(dtype=np.int32) # get an integer view of the array\n    I >>= 1 # divide by two using a binary bit flip\n    I += (1<<29) - (1<<22) # scale by a constant value\n    for i in xrange(reps):\n        Ac = .5 *(Ac + A / Ac) # use an iterative method to increase accuracy, reps is the number of times.\n    return Ac\n\\end{lstlisting}\nThe iterative method mentioned here is Newton's method, it is discussed at length in Volume 1, this is one of its many applications.\nWithout using any additional iterations of Newton's method, the above code gives the approximation to the square root shown in Figure \\ref{float:sqrtapprox0}.\nWith one iteration of Newton's Method, the above code gives the approximation shown in Figure \\ref{float:sqrtapprox1}.\nNotice that there is no visible difference between the square root and the approximation.\nThe results should be the same for 64 bit floating point numbers.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{sqrt0}\n\\caption{The initial approximation for the square root chosen using the binary representation of the floating point number}\n\\label{float:sqrtapprox0}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{sqrt1}\n\\caption{The approximation of the square root after one iteration of an iterative method to increase accuracy.}\n\\label{float:sqrtapprox1}\n\\end{figure}\n\nSomething similar can be done to find the reciprocal of the square root.\nThe first two of the following Cython functions calculate the inverse square root for 32 and 64 bit floating point arrays respectively.\nThe last two functions are equivalents that use the square root function built into C.\n\n\\lstinputlisting[name=]{sqrts.pyx}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{invsqrt0}\n\\caption{An initial guess for the inverse square root of a number obtained using the floating point representation.}\n\\label{float:invsqrt0}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{invsqrt1}\n\\caption{An approximation for the inverse square root of a number after one iteration of Newton's Method.}\n\\label{float:invsqrt1}\n\\end{figure}\n\nThis fast inverse square root has been widely used in computer graphics to quickly normalize vectors.\nThis is a key part of shading 3D surfaces.\nIt has also been used in a variety of other applications.\n\n\\begin{problem}\nMake a version of the square root function above that operates on 64 bit floating point arrays.\nHint: you will have to change the type you use for the new view of \\li{Ac} and you will have to change the constants $29$ and $22$.\nNotice that $29$ is $32-3$ and that $22$ is $29-(e-1)$ where $e$ is the number of bits used for the exponent.\n\nTime the 64 bit square root against NumPy's square root.\nNumPy will probably be faster for full accuracy, but the initial guess should run faster than NumPy's square root.\nHow do the implementations that take advantage of the format of floating point numbers compare with simply taking the reciprocal of the square root of a number using the square root function built in to C?\nWhy do you think that is?\n\\end{problem}\n\nNote: It can be interesting to know about these sorts of bitwise operations but, unless you are desperate to optimize an algorithm a little further, it is probably easier and safer to use the built in implementations.", "meta": {"hexsha": "26863228e6a11f3b570763815d13fd853e4fa013", "size": 15638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FloatingPointIEEE/float.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/FloatingPointIEEE/float.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/FloatingPointIEEE/float.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": 65.9831223629, "max_line_length": 260, "alphanum_fraction": 0.785010871, "num_tokens": 3589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.6907987833848462}}
{"text": "\\section{Vectors in Euclidean Spaces of High Dimensions}\r\n\\subsection{Vectors in the Real Vector spaces}\r\nIf we regard $\\mathbb R^n$ algebraically, i.e. see vectors as just a set of components, then it is easy to generalize from $3$ to $n$ dimensions.\r\n\\begin{definition}\r\n    Let $\\mathbb R^n$ be the set of real $n$-tuples.\r\n    We define addition by $(x_1,x_2,\\ldots,x_n)+(y_1,y_2,\\ldots,y_n)=(x_1+y_1,x_2+y_2,\\ldots, x_n+y_n)$ and scalar multiplication by $\\lambda(x_1,x_2,\\ldots,x_n)=(\\lambda x_1,\\lambda x_2,\\ldots,\\lambda x_n)$.\\\\\r\n    So we can define linear combinations and the notion of parallel similarly.\r\n\\end{definition}\r\nFor any $\\underline{x}\\in\\mathbb R^n$, we can write $\\underline{x}=\\sum_ix_i\\underline{e_i}$ where $\\underline{e_i}$ is a set of orthorgonal basis.\r\nFor example, we can take $e_1=(1,0,\\ldots,0), e_2=(0,1,\\ldots,0), \\ldots, e_n=(0,0,\\ldots,1)$.\r\nThis is called the standard basis of $\\mathbb R^n$.\\\\\r\nWe can define the inner (dot) product in a similar way:\r\n\\begin{definition}\r\n    The inner product (aka scalar product, dot product) is defined by\r\n    $$\\underline{x}\\cdot\\underline{y}=\\sum_ix_iy_i$$\r\n\\end{definition}\r\nWe have a few properties for the inner products, which is basically analogous to the case in the $3$-dimensional case.\r\n\\begin{proposition}\r\n    1. The inner product is symmetric.\\\\\r\n    2. The inner product is bilinear.\\\\\r\n    3. $\\underline{x}\\cdot\\underline{x}\\ge 0$ and the equality hold if and only if $\\underline{x}=\\underline{0}$.\r\n    That is, it is positive definite.\r\n    We thus define the length or norm $|\\underline{x}|$ to be $\\sqrt{\\underline{x}\\cdot\\underline{x}}$.\r\n    4. The standard basis in $\\mathbb R^n$ is an orthonormal basis.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{theorem}[Cauchy-Schwartz Inequality]\r\n    $$|\\underline{x}\\cdot\\underline{y}|\\le |\\underline{x}||\\underline{y}|$$\r\n    The equality hold if and only if $\\underline{x},\\underline{y}$ are parallel to each other.\r\n\\end{theorem}\r\nThe deduction from this is that we can define the angle between two vectors by examining the ratio between the right and left hand side of the inequality.\\\\\r\nWe can also have the triangle inequality, as one may expect norms to satisfy.\r\n\\begin{proof}\r\n    Consider\r\n    $$0\\le|\\underline{x}-\\lambda\\underline{y}|^2=|x|^2-2\\lambda\\underline{x}\\cdot\\underline{y}+\\lambda^2|y|^2$$\r\n    Taking this as a quadratic in $\\lambda$, we have\r\n    $$\\delta=4(x\\cdot y)^2-4|x|^2|y|^2\\le 0\\implies|\\underline{x}\\cdot\\underline{y}|\\le |\\underline{x}||\\underline{y}|$$\r\n    The equality holds if and only if $\\delta=0\\iff 0=|\\underline{x}-\\lambda\\underline{y}|^2\\iff\\underline{x}\\parallel\\underline{y}$.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    $|\\underline{x}+\\underline{y}|\\le|\\underline{x}|+|\\underline{y}|$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Square both sides and use Cauchy-Schwartz.\r\n\\end{proof}\r\nNote that by $\\underline{x}\\cdot\\underline{y}$, we can think of $\\underline{x},\\underline{y}$ as both row and column vectors, since it doesn't matter.\r\nBut still if we take them as for example column vectors, then their transposes are row vectors, so $\\underline{x}\\cdot\\underline{y}=\\underline{x}^\\top\\underline{y}$.\\\\\r\nThe algebraic definition of of the inner product can be also written by $\\delta_{ij}$, so it gives us the initiative to generalize the summation convention.\r\nIn $\\mathbb R^3$, we also have an algebraic definition of cross product. but we cannot really generalize it to $\\mathbb R^n$.\r\nWe have a generalization of $\\epsilon$ though, which is also antisymmetric.\\\\\r\nBut in $\\mathbb R^2$, this generalization gives $\\epsilon_{ij}$, where we can define a product by\r\n$$[\\underline{a},\\underline{b}]=\\epsilon_{ij}a_ib_j=a_1b_2-a_2b_1$$\r\nGeometrically, this gives the signed area of the parallelogram that $a,b$ defined.\\\\\r\nIn comparison, $[\\underline{a},\\underline{b},\\underline{c}]=\\underline{a}\\cdot(\\underline{b}\\times\\underline{c})=\\epsilon_{ijk}a_ib_jc_k$ is the volume of the size of a parallelopiped that these three vectors construct.\r\n\\subsection{Axioms of Real Vector Spaces}\r\n\\begin{definition}\r\n    Let $V$ be a set of objects called vectors with operations:\\\\\r\n    1. $\\underline{v}+\\underline{w}\\in V$.\\\\\r\n    2. $\\lambda\\underline{v}\\in V$.\\\\\r\n    For $\\underline{v},\\underline{w}\\in V, \\lambda\\in\\mathbb R$.\\\\\r\n    Then $V$ is called a real vector space if $(V,+,\\underline{0})$ is an abelian group addition\\\\\r\n    1. $\\lambda (\\underline{v}+\\underline{w})=\\lambda\\underline{v}+\\lambda\\underline{w}$.\\\\\r\n    2. $(\\lambda+\\mu)\\underline{v}=\\lambda\\underline{v}+\\mu\\underline{v}$.\\\\\r\n    3. $(\\lambda\\mu)\\underline{v}=\\lambda(\\mu(\\underline{v}))$.\\\\\r\n    4. $1\\underline{v}=\\underline{v}$.\\\\\r\n    where $\\lambda,\\mu\\in\\mathbb R, \\underline{v},\\underline{w}\\in V$\r\n\\end{definition}\r\n\\begin{definition}\r\n    For any vectors $\\underline{v_1},\\underline{v_2},\\ldots\\underline{v_r}\\in V$, we can form a linear combination\r\n    $$\\sum_{i=1}^ra_i\\underline{v_i}$$\r\n    where $a_i\\in\\mathbb R$.\r\n    The span of these vectors $\\operatorname{span}\\{v_1,v_2,\\ldots,v_r\\}$ consists of all linear combinations of these vectors.\\\\\r\n    The span is a subspace, that is, a subset of the vector space that is itself a vector space under the same way of vector addition and scalar multiplication.\r\n\\end{definition}\r\nIt is immediate that nonempty subset $U\\subseteq V$ is a subspace if and only if $\\operatorname{span} U=U$.\r\n\\begin{example}\r\n    Take $V=\\mathbb R^3$, then any line or plane through the origin is a subspace, but a line or plane that does not contain the origin is not since \\underline{0}=$\\underline{v}+(-1)\\underline{v}\\in\\operatorname{span}\\{\\underline{v}\\}$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A set of vectors $\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_r}$, a linear relation of them is an equation\r\n    $$\\sum_{i=1}^r\\lambda_i\\underline{v_i}=\\underline{0}$$\r\n    If the equation if true only if $\\lambda_i=0$ for every $i$, then the vectors are called linearly independent and that they obey only the trivial linear relation.\r\n    And we say this set of vectors is a independent set.\\\\\r\n    Otherwise, we say they are linearly dependent, and the set of vectors a dependent set.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. So for example, if we take $V=\\mathbb R^2$ and consider the set $(0,1),(1,0),(0,2)$.\r\n    It is a dependent set since $2(0,1)-(0,2)=(0,0)$.\\\\\r\n    2. Any set containing $\\underline{0}$ is dependent.\\\\\r\n    3. $\\{\\underline{a}\\}$ is independent if and only if $\\underline{a}\\neq\\underline{0}$.\\\\\r\n    4. $\\{\\underline{a},\\underline{b}\\}$ is independent if and only if $\\underline{a}\\nparallel\\underline{b}$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A function $\\cdot:V\\times V\\to\\mathbb R$ is called an inner product on $V$ if and only if:\\\\\r\n    1. $\\underline{v}\\cdot\\underline{w}=\\underline{w}\\cdot\\underline{v}$.\\\\\r\n    2. It is bilinear.\\\\\r\n    3. $\\underline{v}\\cdot\\underline{v}\\ge 0$ and the equality hold if and only if $\\underline{v}=\\underline{0}$.\r\n\\end{definition}\r\n\\subsection{Basis and Dimension}\r\nFor general vector spaces, a basis $\\mathscr{B}$ is a independent set of vectors such that $\\operatorname{span}\\mathscr{B}=V$.\r\nGiven this property, it is trivial that the coefficients of any vector as a linear combination of elements in $\\mathscr{B}$ are unique.\r\n\\begin{example}\r\n    The standard basis for $\\mathbb R^n$ consisting of\r\n    $$\\underline{e_1}=(1,0,\\ldots,0),\\underline{e_2}=(0,1,\\ldots,0),\\ldots,\\underline{e_n}=(0,0,\\ldots,1)$$\r\n    is a basis.\r\n    There are many other basis can be chosen though.\r\n    For example, in $\\mathbb R^2$, $\\{(1,0),(1,1)\\}$, $\\{(1,-1),(1,1)\\}$ or simply any $\\{\\underline{a},\\underline{b}\\}$ that are not parallel would be a basis.\r\n\\end{example}\r\n\\begin{theorem}\r\n    If $\\{\\underline{e_1},\\underline{e_2},\\ldots.\\underline{e_n}\\}$ and $\\{\\underline{f_1},\\underline{f_2},\\ldots.\\underline{f_m}\\}$, then $m=n$.\r\n\\end{theorem}\r\nIt follows that we can define the following\r\n\\begin{definition}\r\n    The number of vectors in a basis in a vector space is called its dimension.\r\n    So with this definition, $\\mathbb R^n$ has dimension $n$.\r\n\\end{definition}\r\nNow we can prove the theorem.\r\n\\begin{proof}\r\n    Note that we can find coefficients $A_{ai}$ such that $\\underline{f_a}=\\sum_iA_{ai}\\underline{e_i}$ for each $a$.\r\n    Similarly, $\\underline{e_i}=\\sum_aB_{ia}\\underline{f_a}$.\\\\\r\n    Then $\\underline{f_a}=\\sum_b(\\sum_iA_{ai}B_{ib})\\underline{f_b}$ and $\\underline{e_i}=\\sum_j(\\sum_aB_{ia}A_{aj})\\underline{e_j}$.\r\n    So $\\sum_iA_{ai}B_{ib}=\\delta_{ij}$ and $\\sum_aB_{ia}A_{aj}=\\delta_{ij}$.\\\\\r\n    $\\sum_{i,a}A_{ai}B_{ia}=\\sum_i\\delta_{ii}$ and $\\sum_{i,a}A_{ai}B_{ia}=\\sum_a\\delta_{aa}$, thus $n=m$.\r\n\\end{proof}\r\nIn fact we did secretly used traces, but we have presented it within the scope of this course.\r\nThe proof in the general case can be done elegantly using matrices.\\\\\r\nWe can also apply our notions to the following:\r\n\\begin{proposition}\r\n    Let $V$ be a vector space of dimension $n$.\\\\\r\n    1. If $Y=\\{\\underline{w_1},\\underline{w_2},\\ldots,\\underline{w_m}\\}$ spans $V$, then $m\\ge n$ and if $m>n$ we can remove an element from $Y$ such that the new set of vectors still spans $V$.\r\n    Thus we can continue doing it till it becomes a basis.\\\\\r\n    2. If $X=\\{\\underline{u_1},\\underline{u_2},\\ldots,\\underline{u_k}\\}$ be an independent set of vectors, then $k\\le n$ and if $k<n$ we can add vector to $X$ until we have a basis.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1. If $Y$ is linearly independent, then we are done and $m=n$.\r\n    Otherwise, there is some linear relation $\\sum_i\\lambda_i\\underline{w_i}=0$ such that $\\exists i, \\lambda_i\\neq 0$.\r\n    WLOG $i=m$, then $\\underline{w_m}=\\lambda_m^{-1}(\\sum_{i,i\\neq m}\\underline{w_i})$.\r\n    So $Y'=Y\\setminus\\{\\underline{w_m}\\}$ spans $V$.\r\n    We can repeat this till it becomes independent, i.e. we obtain a basis.\\\\\r\n    2. If $X$ spans $V$, we are done and then $k=m$.\r\n    Otherwise, there is some $\\underline{u_{k+1}}\\in V\\setminus\\operatorname{span}X$, then $X\\cup\\{\\underline{u_{k+1}}\\}$ is still independent.\r\n    Indeed, if there is some nontrivial linear relation $\\sum_i\\mu_i\\underline{u_i}=0$, then $\\mu_{k+1}\\neq 0$ since $X$ is independent, but then $\\underline{u_{k+1}}$ can be written as a linear combination of $\\underline{u_i}$ for $i\\in\\{1,2,\\ldots,k\\}$, contradiction.\\\\\r\n    So we can do it over again and obtain a basis at last.\r\n\\end{proof}\r\nNote that the basis does not use nor depend on the inner product structure of the vector space.\r\nBut we can make use of it to obtain an orthorgonal basis.\r\n\\begin{definition}\r\n    A basis is called orthorgonal if they are pairwisely orthorgonal.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Any set of pairwise orthogonal vectors is independent.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Easy.\r\n\\end{proof}\r\n\\subsection{Vectors in the Complex Vector Space}\r\n\\begin{definition}\r\n    Let $\\mathbb C^n$ consist of all complex $n$-tuples.\r\n    We define the vector space by taking the vector addition and scalar multiplication analogously to the $\\mathbb R^n$ case.\r\n\\end{definition}\r\nTaking real scalars in scalar multiplication, then $\\mathbb C^n$ is just a real vector space of dimension $2n$.\r\nTaking complex scalars, $\\mathbb C^n$ is a complex vector space.\\\\\r\nThe definitions of linear combinations, linear independence, basis, dimensions are all analogous.\r\nConsider\r\n$$(z_1,\\ldots,z_n)=(x_1+iy_1,\\ldots,x_n+iy_n)=(x_1,\\ldots,x_n)+i(y_1,\\ldots,y_n)$$\r\nthen $\\underline{e_j}$ and $i\\underline{e_j}$ gives a basis for $\\mathbb C^n$ as a real vector space.\r\nAnd the $\\underline{e_j}$ is a basis for $\\mathbb C^n$ as a complex vector space.\r\nWe view $\\mathbb C_n$ to be over $\\mathbb C$ unless otherwise stated.\r\n\\begin{definition}\r\n    The inner product on $\\mathbb C^n$ is defined by\r\n    $(\\underline{z},\\underline{w})=\\sum_{j}\\bar{z}_jw_j$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    The complex inner product is:\\\\\r\n    1. Hermitian, $(\\underline{z},\\underline{w})=\\overline{(\\underline{w},\\underline{z})}$.\\\\\r\n    2. Anti-linear, $(\\underline{z},\\lambda\\underline{w}+\\lambda'\\underline{w'})=\\lambda(\\underline{z},\\underline{w})+\\lambda'(\\underline{z},\\underline{w'})$ and $(\\lambda\\underline{z}+\\lambda'\\underline{z'},\\underline{w})=\\bar\\lambda(\\underline{z},\\underline{w})+\\bar\\lambda'(\\underline{z'}+\\underline{w})$.\\\\\r\n    3. Positive definite.\r\n\\end{proposition}\r\nThe geometric content of this sort of inner product is a little more subtle than in the real case.\r\n\\begin{example}\r\n    Consider the complex inner product on $\\mathbb C$, that is $n=1$, since there is only one component, $(z,w)=\\bar zw$.\r\n    Suppose $z=a_1+ia_2,w=b_1+ib_2$ where $a_1,a_2,b_1,b_2\\in\\mathbb R$.\r\n    Let $\\underline{a}=(a_1,a_2),\\underline{b}=(b_1,b_2)$, then\r\n    $$(z,w)=a_1b_1+a_2b_2+i(a_1b_2-a_2b_1)=\\underline{a}\\cdot\\underline{b}+i[\\underline{a},\\underline{b}]$$\r\n\\end{example}\r\nGiven the positive definite property, we can define the length or norm $|\\underline{z}|$ for any $\\underline{z}\\in\\mathbb C^n$ by $|\\underline{z}|=\\sqrt{(\\underline{z},\\underline{z})}$.\r\nWe still say that two complex vectors are orthorgonal if their (complex) inner product vanishes.\r\nIn this way, the standard basis for $\\mathbb C^n$ is orthorgonal.\\\\\r\nIf $\\underline{z_1},\\underline{z_2},\\ldots,\\underline{z_k}$ are nonzero and orthorgonal, then they are linearly independent.\\\\\r\nNotationally, we think of the vectors in $\\mathbb C^n$ as column vector, and the Hermitian conjugate $\\underline{z}^{\\dagger}$ the row vector consisting of the conjugates of the entries.", "meta": {"hexsha": "c95913d5672d70683a9e2d3bc7be25f102564e26", "size": 13595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/nd.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": "3/nd.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": "3/nd.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": 70.8072916667, "max_line_length": 311, "alphanum_fraction": 0.6937109231, "num_tokens": 4270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430311279742, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.6907987555742311}}
{"text": "\\chapter{Affine varieties}\nIn this chapter we introduce affine varieties.\nWe introduce them in the context of coordinates,\nbut over the course of the other chapters\nwe'll gradually move away from this perspective to\nviewing varieties as ``intrinsic objects'',\nrather than embedded in coordinates.\n\nFor simplicity, we'll do almost everything over the field of complex numbers,\nbut the discussion generalizes to any algebraically closed field.\n\n\\section{Affine varieties}\n\\prototype{$\\VV(y-x^2)$ is a parabola in $\\Aff^2$.}\n%An \\vocab{affine variety} is just the zero locus of a set of polynomials.\n%We think of it as living in the $n$-dimensional space $\\Aff^n$.\n\n\\begin{definition}\n\tGiven a set of polynomials $S \\subseteq \\CC[x_1, \\dots, x_n]$\n\t(not necessarily finite or even countable),\n\twe let $\\VV(S)$ denote the set of points vanishing on \\emph{all}\n\tthe polynomials in $S$.\n\tSuch a set is called an \\vocab{affine variety}.\n\tIt lives in \\vocab{$n$-dimensional affine space}, denoted $\\Aff^n$\n\t(to distinguish it from projective space later).\n\\end{definition}\nFor example, a parabola is the zero locus of the polynomial $\\VV(y-x^2)$. Picture:\n\\begin{center}\n\t\\begin{asy}\n\t\timport graph;\n\t\tsize(5cm);\n\n\t\treal f(real x) { return x*x; }\n\t\tgraph.xaxis(\"$x$\");\n\t\tgraph.yaxis(\"$y$\");\n\t\tdraw(graph(f,-2,2,operator ..), blue, Arrows);\n\t\tlabel(\"$\\mathcal V(y-x^2)$\", (0.8, f(0.8)), dir(-45), blue);\n\t\tlabel(\"$\\mathbb A^2$\", (2,3), dir(45));\n\t\\end{asy}\n\\end{center}\n\n\\begin{example}[Examples of affine varieties]\n\tThese examples are in two-dimensional space $\\Aff^2$,\n\twhose points are pairs $(x,y)$.\n\t\\begin{enumerate}[(a)]\n\t\\ii A straight line can be thought of as $\\VV(Ax + By + C)$.\n\t\\ii A parabola as above can be pictured as $\\VV(y-x^2)$.\n\t\\ii A hyperbola might be the zero locus of the polynomial $\\VV(xy-1)$.\n\t\\ii The two axes can be thought of as $\\VV(xy)$; this is the set of points\n\tsuch that $x=0$ \\emph{or} $y=0$.\n\t\\ii A point $(x_0, y_0)$ can be thought of as $\\VV(x-x_0, y-y_0)$.\n\t\\ii The entire space $\\Aff^2$ can be thought of as $\\VV(0)$.\n\t\\ii The empty set is the zero locus of the constant polynomial $1$, that is $\\VV(1)$.\n\t\\end{enumerate}\n\\end{example}\n\n\\section{Naming affine varieties via ideals}\n\\prototype{$\\VV(I)$ is a parabola, where $I=(y-x^2)$.}\nAs you might have already noticed, a variety can be named by $\\VV(-)$ in multiple ways.\nFor example, the set of solutions to\n\\[ x=3 \\text{ and } y=4 \\]\nis just the point $(3,4)$.\nBut this is also the set of solutions to\n\\[ x=3 \\text{ and } y=x+1. \\]\nSo, for example\n\\[ \\{(3,4)\\}\n\t= \\VV(x-3, y-4)\n\t= \\VV(x-3, y-x-1).\n\t\\]\nThat's a little annoying, because in an ideal\\footnote{Pun not intended\n\tbut left for amusement value.}\nworld we would have \\emph{one} name\nfor every variety.\nLet's see if we can achieve this.\n\nA partial solution is to use \\emph{ideals} rather than small sets.\nThat is, consider the ideal\n\\[\n\tI = \\left( x-3, y-4 \\right)\n\t= \\left\\{ p(x,y) \\cdot (x-3) + q(x,y) \\cdot (y-4)\n\t\\mid p,q \\in \\CC[x,y] \\right\\}\n\\]\nand look at $\\VV(I)$.\n\\begin{ques}\n\tConvince yourself that $\\VV(I) = \\{(3,4)\\}$.\n\\end{ques}\nSo rather than writing $\\VV(x-3, y-4)$ it makes sense to\nthink about this as $\\VV\\left( I \\right)$, where $I = (x-3,y-4)$ is the \\emph{ideal}\ngenerated by the two polynomials $x-3$ and $y-4$.\nThis is an improvement because\n\\begin{ques}\n\tCheck that $(x-3, y-x-1) = (x-3, y-4)$.\n\\end{ques}\n\nNeedless to say, this pattern holds in general.\n\\begin{ques}\n\tLet $\\{f_i\\}$ be a set of polynomials, and consider\n\tthe ideal $I$ generated by these $\\{f_i\\}$.\n\tShow that $\\VV(\\{f_i\\}) = \\VV(I)$.\n\\end{ques}\n\nThus we will only consider $\\VV(I)$ when $I$ is an ideal.\nOf course, frequently our ideals are generated by one or two polynomials,\nwhich leads to:\n\\begin{abuse}\n\tGiven a set of polynomials $f_1, \\dots, f_m$\n\twe let $\\VV(f_1, \\dots, f_m)$ be shorthand for\n\t$\\VV\\left( \\left( f_1, \\dots, f_m \\right) \\right)$.\n\tIn other words we let $\\VV(f_1, \\dots, f_m)$\n\tabbreviate $\\VV(I)$, where $I$ is the \\emph{ideal} $I=(f_1, \\dots, f_m)$.\n\\end{abuse}\n\nThis is where the Noetherian condition really shines:\nit guarantees that every ideal $I \\subseteq \\CC[x_1, \\dots, x_n]$\ncan be written in the form above with \\emph{finitely} many polynomials,\nbecause it is \\emph{finitely generated}.\n(The fact that $\\CC[x_1, \\dots, x_n]$ is Noetherian follows from the Hilbert basis theorem,\nwhich is \\Cref{thm:hilbert_basis}).\nThis is a relief, because dealing with infinite sets of polynomials is not much fun.\n\n\\section{Radical ideals and Hilbert's Nullstellensatz}\n\\prototype{$\\sqrt{(x^2)} = (x)$ in $\\CC[x]$, $\\sqrt{(12)} = (6)$ in $\\ZZ$.}\nYou might ask whether the name is unique now:\nthat is, if $\\VV(I) = \\VV(J)$, does it follow that $I=J$?\nThe answer is unfortunately no: the counterexample can be found in just $\\Aff^1$.\nIt is\n\\[ \\VV(x) = \\VV(x^2). \\]\nIn other words, the set of solutions to $x=0$\nis the same as the set of solutions to $x^2=0$.\n\nWell, that's stupid.\nWe want an operation which takes the ideal $(x^2)$ and makes it into the ideal $(x)$.\nThe way to do so is using the radical of an ideal.\n\n\\begin{definition}\n\tLet $R$ be a ring.\n\tThe \\vocab{radical} of an ideal $I \\subseteq R$, denoted $\\sqrt I$,\n\tis defined by\n\t\\[ \\sqrt I = \\left\\{ r \\in R\n\t\t\t\\mid r^m \\in I \\text{ for some integer $m \\ge 1$} \\right\\}. \\]\n\tIf $I = \\sqrt I$, we say the ideal $I$ itself is \\vocab{radical}.\n\\end{definition}\nFor example, $\\sqrt{(x^2)} = (x)$.\nYou may like to take the time to verify that $\\sqrt I$ is actually an ideal.\n\n\\begin{remark}\n\t[Number theoretic motivation]\n\tThis is actually the same as the notion of ``radical'' in number theory.\n\tIn $\\ZZ$, the radical of an ideal $(n)$ corresponds to just\n\tremoving all the duplicate prime factors, so for example\n\t\\[ \\sqrt{(12)} = (6). \\]\n\tIn particular, if you try to take $\\sqrt{(6)}$,\n\tyou just get $(6)$ back;\n\tyou don't squeeze out any new prime factors.\n\n\tThis is actually true more generally,\n\tand there is a nice corresponding alternate definition:\n\tfor any ideal $I$, we have\n\t\\[ \\sqrt I = \\bigcap_{I \\subseteq \\kp \\text{ prime}} \\kp. \\]\n\tAlthough we could prove this now,\n\tit will be proved later in \\Cref{thm:radical_intersect_prime},\n\twhen we first need it.\n\\end{remark}\n\nHere are the immediate properties you should know.\n\\begin{proposition}\n\t[Properties of radical]\n\t\\label{prop:radical}\n\tIn any ring:\n\t\\begin{itemize}\n\t\t\\ii If $I$ is an ideal, then $\\sqrt I$ is always a radical ideal.\n\t\t\\ii Prime ideals are radical.\n\t\t\\ii For $I \\subseteq \\CC[x_1, \\dots, x_n]$\n\t\twe have $\\VV(I) = \\VV(\\sqrt I)$.\n\t\\end{itemize}\n\\end{proposition}\n\\begin{proof}\n\tThese are all obvious.\n\t\\begin{itemize}\n\t\t\\ii If $f^m \\in \\sqrt I$ then $f^{mn} \\in I$, so $f \\in \\sqrt I$.\n\t\t\\ii If $f^n \\in \\kp$ for a prime $\\kp$,\n\t\tthen either $f \\in \\kp$ or $f^{n-1} \\in \\kp$,\n\t\tand in the latter case we may continue by induction.\n\t\t\\ii We have $f(x_1, \\dots, x_n) = 0$\n\t\tif and only if $f(x_1, \\dots, x_n)^m = 0$ for some integer $m$.\n\t\t\\qedhere\n\t\\end{itemize}\n\\end{proof}\n\nThe last bit makes sense: you would never refer to $x=0$ as $x^2=0$,\nand hence we would always want to call $\\VV(x^2)$ just $\\VV(x)$.\nWith this, we obtain a theorem called Hilbert's Nullstellensatz.\n\\begin{theorem}[Hilbert's Nullstellensatz]\n\t\\label{thm:hilbert_null}\n\tGiven an affine variety $V = \\VV(I)$,\n\tthe set of polynomials which vanish\n\ton all points of $V$ is precisely $\\sqrt I$.\n\tThus if $I$ and $J$ are ideals in $\\CC[x_1, \\dots, x_n]$, then\n\t\\[ \\VV(I) = \\VV(J) \\text{ if and only if $\\sqrt I = \\sqrt J$}. \\]\n\\end{theorem}\nIn other words\n\\begin{moral}\n\tRadical ideals in $\\CC[x_1, \\dots, x_n]$ correspond\n\texactly to $n$-dimensional affine varieties.\n\\end{moral}\nThe proof of Hilbert's Nullstellensatz will be given in\n\\Cref{prob:hilbert_from_weak}; for now it is worth remarking that\nit relies essentially on the fact that $\\CC$ is \n\\emph{algebraically closed}.\nFor example, it is false in $\\RR[x]$,\nwith $(x^2+1)$ being a maximal ideal with empty vanishing set.\n\n\\section{Pictures of varieties in $\\Aff^1$}\n\\prototype{Finite sets of points (in fact these are the only nontrivial examples).}\nLet's first draw some pictures.\nIn what follows I'll draw $\\CC$ as a straight line\\dots sorry.\n\nFirst of all, let's look at just the complex line $\\Aff^1$.\nWhat are the various varieties on it?\nFor starters, we have a single point $9 \\in \\CC$,\ngenerated by $(x-9)$.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(6cm);\n\t\tpair A = (-9,0); pair B = (9,0);\n\t\tdraw(A--B, Arrows);\n\t\tlabel(\"$\\mathcal V(x-9)$\", (0,0), 2*dir(-90), blue);\n\t\tdot(\"$9$\", (3,0), dir(90), blue);\n\t\tlabel(\"$\\mathbb A^1$\", A+(2,0), dir(90));\n\t\\end{asy}\n\\end{center}\n\nAnother example is the point $4$.\nAnd in fact, if we like we can get an ideal consisting of just these two points;\nconsider $\\VV\\left( (x-4)(x-9) \\right)$.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(6cm);\n\t\tpair A = (-9,0); pair B = (9,0);\n\t\tdraw(A--B, Arrows);\n\t\tlabel(\"$\\mathcal V( (x-4)(x-9) )$\", (0,0), 2*dir(-90), blue);\n\t\tdot(\"$4$\", (-1,0), dir(90), blue);\n\t\tdot(\"$9$\", (3,0), dir(90), blue);\n\t\tlabel(\"$\\mathbb A^1$\", A+(2,0), dir(90));\n\t\\end{asy}\n\\end{center}\n\nIn general, in $\\Aff^1$ you can get finitely\nmany points $\\left\\{ a_1, \\dots, a_n \\right\\}$ by\njust taking \\[ \\VV\\left( (x-a_1)(x-a_2)\\dots(x-a_n) \\right). \\]\nOn the other hand, you can't get the set $\\{0,1,2,\\dots\\}$ as an affine variety;\nthe only polynomial vanishing\non all those points is the zero polynomial.\nIn fact, you can convince yourself that these\nare the only affine varieties, with two exceptions:\n\\begin{itemize}\n\t\\ii The entire line $\\Aff^1$ is given by $\\VV(0)$, and\n\t\\ii The empty set is given by $\\VV(1)$.\n\\end{itemize}\n\\begin{exercise}\n\tShow that these are the only varieties of $\\Aff^1$.\n\t(Let $\\VV(I)$ be the variety and pick a $0 \\neq f \\in I$.)\n\\end{exercise}\n\nAs you might correctly guess, we have:\n\\begin{theorem}[Intersections and unions of varieties]\n\t\\label{thm:many_aff_variety}\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The intersection of affine varieties\n\t\t(even infinitely many) is an affine variety.\n\t\t\\ii The union of finitely many affine varieties\n\t\tis an affine variety.\n\t\\end{enumerate}\n\tIn fact we have\n\t\\[ \\bigcap_\\alpha \\VV(I_\\alpha)\n\t\t= \\VV\\left( \\sum_\\alpha I_\\alpha \\right)\n\t\t\\qquad\\text{and}\\qquad\n\t\t\\bigcup_{k=1}^n \\VV(I_k)\n\t\t= \\VV\\left( \\bigcap_{k=1}^n I_k \\right). \\]\n\\end{theorem}\nYou are welcome to prove this easy result yourself.\n\\begin{remark}\n\tPart (a) is a little misleading in that the sum $I+J$ need not be radical:\n\ttake for example $I = (y-x^2)$ and $J = (y)$ in $\\CC[x,y]$,\n\twhere $x \\in \\sqrt{I+J}$ and $x \\notin I+J$.\n\tBut in part (b) for radical ideals $I$ and $J$,\n\tthe intersection $I \\cap J$ is radical.\n\\end{remark}\n\n\\section{Prime ideals correspond to irreducible affine varieties}\n\\prototype{$(xy)$ corresponds to the union of two lines in $\\Aff^2$.}\n\nNote that most of the affine varieties of $\\Aff^1$, like $\\{4,9\\}$,\nare just unions of the simplest ``one-point'' ideals.\nTo ease our classification,\nwe can restrict our attention to the case of \\emph{irreducible} varieties:\n\\begin{definition}\n\tA variety $V$ is \\vocab{irreducible} if it cannot be written\n\tas the union of two proper sub-varieties $V = V_1 \\cup V_2$.\n\\end{definition}\n\\begin{abuse}\n\tWarning: in other literature,\n\tirreducible is part of the definition of variety.\n\\end{abuse}\n\n\\begin{example}\n\t[Irreducible varieties of $\\Aff^1$]\n\tThe irreducible varieties of $\\Aff^1$ are:\n\t\\begin{itemize}\n\t\t\\ii the empty set $\\VV(1)$,\n\t\t\\ii a single point $\\VV(x-a)$, and\n\t\t\\ii the entire line $\\Aff^1 = \\VV(0)$.\n\t\\end{itemize}\n\\end{example}\n\\begin{example}\n\t[The union of two axes]\n\tLet's take a non-prime ideal in $\\CC[x,y]$, such as $I = (xy)$.\n\tIts vanishing set $\\VV(I)$ is the union of two lines $x=0$ and $y=0$.\n\tSo $\\VV(I)$ is reducible.\n\\end{example}\n\n%We have already seen that the radical ideals\n%are in one-to-one correspondence with affine varieties.\n%In the next sections we answer the two questions:\n%\\begin{itemize}\n%\t\\ii What property of $\\VV(I)$ corresponds to $I$ being prime?\n%\t\\ii What property of $\\VV(I)$ corresponds to $I$ being maximal?\n%\\end{itemize}\n%The first question is easier to answer.\n\nIn general:\n\\begin{theorem}[Prime $\\iff$ irreducible]\n\tLet $I$ be a radical ideal, and $V = \\VV(I)$ a nonempty variety.\n\tThen $I$ is prime if and only if $V$ is irreducible.\n\\end{theorem}\n\\begin{proof}\n\tFirst, assume $V$ is irreducible; we'll show $I$ is prime.\n\tLet $f,g \\in \\CC[x_1, \\dots, x_n]$ so that $fg \\in I$.\n\tThen $V$ is a subset of the union $\\VV(f) \\cup \\VV(g)$;\n\tactually, $V = \\left( V \\cap \\VV(f) \\right) \\cup \\left( V \\cap \\VV(g) \\right)$.\n\tSince $V$ is irreducible, we may assume $V = V \\cap \\VV(f)$,\n\thence $f$ vanishes on all of $V$. So $f \\in I$.\n\n\tThe reverse direction is similar.\n\\end{proof}\n\n%\\begin{remark}\n%\tThe above proof illustrates the following principle:\n%\tLet $V$ be an irreducible variety.\n%\tSuppose that $V \\subseteq V_1 \\cup V_2$;\n%\tthis implies $V = (V_1 \\cap V) \\cup (V_2 \\cap V)$.\n%\tRecall that the intersection of two varieties is a variety.\n%\tThus an irreducible variety can't even be \\emph{contained}\n%\tin a nontrivial union of two varieties.\n%\\end{remark}\n\n\\section{Pictures in $\\Aff^2$ and $\\Aff^3$}\n\\prototype{Various curves and hypersurfaces.}\n\nWith this notion, we can now draw pictures in\n``complex affine plane'', $\\Aff^2$.\nWhat are the irreducible affine varieties in it?\n\nAs we saw in the previous discussion,\nnaming irreducible affine varieties in $\\Aff^2$\namounts to naming the prime ideals of $\\CC[x,y]$.\nHere are a few.\n\\begin{itemize}\n\t\\ii The ideal $(0)$ is prime. $\\VV(0)$ as usual corresponds to the entire plane.\n\t\\ii The ideal $(x-a, y-b)$ is prime,\n\tsince $\\CC[x,y] / (x-a, y-b) \\cong \\CC$ is an integral domain.\n\t(In fact, since $\\CC$ is a field, the ideal $(x-a,y-b)$ is \\emph{maximal}).\n\tThe vanishing set of this is $\\VV(x-a, y-b) = \\{ (a,b) \\} \\in \\CC^2$,\n\tso these ideals correspond to a single point.\n\t\\ii Let $f(x,y)$ be an irreducible polynomial, like $y-x^2$.\n\tThen $(f)$ is a prime ideal! Here $\\VV(I)$ is a ``degree one curve''.\n\\end{itemize}\n\nBy using some polynomial algebra\n(again you're welcome to check this; Euclidean algorithm),\nthese are in fact the only prime ideals of $\\CC[x,y]$.\nHere's a picture.\n\n\\begin{center}\n\t\\begin{asy}\n\t\timport graph;\n\t\tgraph.xaxis(\"$x$\", -4, 4);\n\t\tgraph.yaxis(\"$y$\", -4, 4);\n\n\t\treal f (real x) { return x*x; }\n\t\tdraw(graph(f,-2,2,operator ..), blue);\n\t\tlabel(\"$\\mathcal V(y-x^2)$\", (1,1), dir(-45), blue);\n\t\tdot(\"$\\mathcal V(x-1,y+2)$\", (1,-2), dir(-45), red);\n\t\\end{asy}\n\\end{center}\n\n\nAs usual, you can make varieties which are just unions of these irreducible ones.\nFor example, if you wanted the variety consisting of a parabola $y=x^2$\nplus the point $(20,15)$ you would write\n\\[ \\VV \\left( (y-x^2)(x-20), (y-x^2)(y-15) \\right). \\]\n\nThe picture in $\\Aff^3$ is harder to describe.\nAgain, you have points $\\VV(x-a, y-b, z-c)$ corresponding to \nbe zero-dimensional points $(a,b,c)$, and two-dimensional surfaces\n$\\VV(f)$ for each irreducible polynomial $f$ (for example, $x+y+z=0$ is a plane).\nBut there are more prime ideals, like $\\VV(x,y)$, which corresponds to the\nintersection of the planes $x=0$ and $y=0$: this is the one-dimensional $z$-axis.\nIt turns out there is no reasonable way to classify the ``one-dimensional'' varieties;\nthey correspond to ``irreducible curves''.\n\nThus, as Ravi Vakil \\cite{ref:vakil} says:\nthe purely algebraic question \nof determining the prime ideals of $\\CC[x,y,z]$\nhas a fundamentally geometric answer.\n\n\\section{Maximal ideals}\n\\prototype{All maximal ideals are $(x_1-a_1, \\dots, x_n-a_n)$.}\nWe begin by noting:\n\\begin{proposition}\n\t[$\\VV(-)$ is inclusion reversing]\n\tIf $I \\subseteq J$ then $\\VV(I) \\supseteq \\VV(J)$.\n\tThus $\\VV(-)$ is \\emph{inclusion-reversing}.\n\\end{proposition}\n\\begin{ques}\n\tVerify this.\n\\end{ques}\nThus, bigger ideals correspond to smaller varieties.\nAs the above pictures might have indicated,\nthe smallest varieties are \\emph{single points}.\nMoreover, as you might guess from the name,\nthe biggest ideals are the \\emph{maximal ideals}.\nAs an example, all ideals of the form\n\\[ \\left( x_1-a_1, \\dots, x_n-a_n \\right) \\]\nare maximal, since the quotient\n\\[ \\CC[x_1, \\dots, x_n] / \\left( x_1-a_1, \\dots, x_n-a_n \\right) \\cong \\CC \\]\nis a field.\nThe question is: are all maximal ideals of this form?\n\nThe answer is in the affirmative.\n%It's equivalent to:\n%\\begin{theorem}\n%\t[Weak Nullstellensatz, phrased as nonempty varieties]\n%\tLet $I \\subsetneq \\CC[x_1, \\dots, x_n]$ be a proper ideal.\n%\tThen the variety $\\VV(I) \\neq \\varnothing$.\n%\\end{theorem}\n% From this we can deduce that all maximal ideals are of the above form.\n\\begin{theorem}\n\t[Weak Nullstellensatz, phrased with maximal ideals]\n\tEvery maximal ideal of $\\CC[x_1, \\dots, x_n]$\n\tis of the form $(x_1-a_1, \\dots, x_n-a_n)$.\n\\end{theorem}\nThe proof of this is surprisingly nontrivial,\nso we won't include it here yet; see \\cite[\\S7.4.3]{ref:vakil}.\n%% TODO we might include this eventually\n%\\begin{proof}\n%\t[WN implies MI]\n%\tLet $J$ be a maximal ideal, and consider the corresponding variety $V = \\VV(J)$.\n%\tBy WN, it contains some point $p=(a_1, \\dots, a_n)$.\n%\tNow, define $I = (x_1-a_1, \\dots, x_n-a_n)$; this ideal contains all polynomials\n%\tvanishing at $p$, so necessarily $J \\subseteq I \\subsetneq \\CC[x_1, \\dots, x_n]$.\n%\tThen by maximality of $J$ we have $J=I$.\n%\\end{proof}\nAgain this uses the fact that $\\CC$ is algebraically closed.\n(For example $(x^2+1)$ is a maximal ideal of $\\RR[x]$.)\nThus:\n\\begin{moral}\n\tOver $\\CC$, maximal ideals correspond to single points.\n\\end{moral}\n\nConsequently, our various ideals over $\\CC$ correspond to various flavors\nof affine varieties:\n\\begin{center}\n\t\\begin{tabular}[h]{|cc|}\n\t\t\\hline\n\t\tAlgebraic flavor & Geometric flavor \\\\ \\hline\n\t\tradical ideal & affine variety \\\\\n\t\tprime ideal & irreducible variety \\\\\n\t\tmaximal ideal & single point \\\\\n\t\tany ideal & (scheme?) \\\\ \\hline\n\t\\end{tabular}\n\\end{center}\nThere's one thing I haven't talked about: what's the last entry?\n\n\\section{Motivating schemes with non-radical ideals}\nOne of the most elementary motivations for the scheme\nis that we would like to use them to count multiplicity.\nThat is, consider the intersection\n\\[ \\VV(y-x^2) \\cap \\VV(y) \\subseteq \\Aff^2 \\]\nThis is the intersection of the parabola with the tangent $x$-axis,\nthis is the green dot below.\n\n\\begin{center}\n\t\\begin{asy}\n\t\timport graph;\n\t\tsize(5cm);\n\n\t\treal f(real x) { return x*x; }\n\t\tgraph.xaxis(\"$x$\", red);\n\t\tgraph.yaxis(\"$y$\");\n\t\tdraw(graph(f,-2,2,operator ..), blue, Arrows);\n\t\tlabel(\"$\\mathcal V(y-x^2)$\", (0.8, f(0.8)), dir(-45), blue);\n\t\tlabel(\"$\\mathbb A^2$\", (2,3), dir(45));\n\t\tdotfactor *= 1.5;\n\t\tdot(origin, heavygreen);\n\t\\end{asy}\n\\end{center}\n\nUnfortunately, as a variety, it is just a single point!\nHowever, we want to think of this as a ``double point'':\nafter all, in some sense it has multiplicity $2$.\nYou can detect this when you look at the ideals:\n\\[ (y-x^2) + (y) = (x^2,y) \\]\nand thus, if we blithely ignore taking the radical, we get\n\\[ \\CC[x,y] / (x^2,y) \\cong \\CC[\\eps] / (\\eps^2). \\]\nSo the ideals in question are noticing the presence of a double point.\n\nIn order to encapsulate this, we need a more refined object than\na variety, which (at the end of the day) is just a set of points;\nit's not possible using topology along to encode more information\n(there is only one topology on a single point!).\nThis refined object is the \\emph{scheme}.\n\n\\section\\problemhead\n\\todo{some actual computation here would be good}\n\n\\begin{problem}\n\tShow that a \\emph{real} affine variety $V \\subseteq \\Aff_\\RR^n$\n\tcan always be written in the form $\\VV(f)$.\n\t\\begin{hint}\n\t\tSquares are nonnegative.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIf $V = \\VV(I)$ with $I = (f_1, \\dots, f_m)$\n\t\t(as usual there are finitely many polynomials since $\\RR[x_1, \\dots, x_n]$ is Noetherian)\n\t\tthen we can take $f = f_1^2 + \\dots + f_m^2$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Complex varieties can't be empty]\n\t\\label{prob:complex_variety_nonempty}\n\tProve that if $I$ is a proper ideal in $\\CC[x_1, \\dots, x_n]$\n\tthen $\\VV(I) \\ne \\varnothing$.\n\t\\begin{hint}\n\t\tThis is actually an equivalent formulation\n\t\tof the Weak Nullstellensatz.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tLet $I$ be an ideal, and let $\\km$ be a maximal ideal contained in it.\n\t\t(If you are worried about the existence of $\\km$,\n\t\tit follows from Krull's Theorem, \\Cref{prob:krull_max_ideal}).\n\t\tThen $\\km = (x_1 - a_1, \\dots, x_n - a_n)$ by Weak Nullstellensatz.\n\t\tConsequently, $(a_1, \\dots, a_n)$ is the unique point of $\\VV(\\km)$,\n\t\tand hence this point is also in $\\VV(I)$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t\\yod\n\t\\label{prob:hilbert_from_weak}\n\tShow that Hilbert's Nullstellensatz in $n$ dimensions\n\tfollows from the Weak Nullstellensatz.\n\t(This solution is called the \\vocab{Rabinowitsch Trick}.)\n\t\\begin{hint}\n\t\tUse the weak Nullstellensatz on $n+1$ dimensions.\n\t\tGiven $f$ vanishing on everything,\n\t\tconsider $x_{n+1}f-1$. \n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe point is is to check that if $f$ vanishes on all of $\\VV(I)$,\n\t\tthen $f \\in \\sqrt I$.\n\n\t\tTake a set of generators $f_1, \\dots, f_m$,\n\t\tin the original ring $\\CC[x_1, \\dots, x_n]$;\n\t\twe may assume it's finite by the Hilbert basis theorem.\n\n\t\tWe're going to do a trick now:\n\t\tconsider $S = \\CC[x_1, \\dots, x_n, x_{n+1}]$ instead.\n\t\tConsider the ideal $I' \\subseteq S$ in the bigger ring\n\t\tgenerated by $\\{f_1, \\dots, f_m\\}$ and the polynomial $x_{n+1} f - 1$.\n\t\tThe point of the last guy is that its zero locus\n\t\tdoes not touch our copy $x_{n+1}=0$ of $\\Aff^n$\n\t\tnor any point in the ``projection'' of $f$ through $\\Aff^{n+1}$\n\t\t(one can think of this as $\\VV(I)$ in the smaller ring\n\t\tdirect multiplied with $\\CC$).\n\t\tThus $\\VV(I') = \\varnothing$, and by the weak Nullstellensatz\n\t\twe in fact have $I' = \\CC[x_1, \\dots, x_{n+1}]$.\n\t\tSo\n\t\t\\[ 1 = g_1f_1 + \\dots + g_mf_m + g_{m+1} \\left( x_{n+1}f-1 \\right). \\]\n\t\tNow the hack: \\textbf{replace every instance of $x_{n+1}$ by $\\frac 1f$},\n\t\tand then clear all denominators.\n\t\tThus for some large enough integer $N$ we can get\n\t\t\\[ f^N = f^N(g_1f_1 + \\dots + g_mf_m) \\]\n\t\twhich eliminates any fractional powers of $f$ in the right-hand side.\n\t\tIt follows that $f^N \\in I$.\n\t\\end{sol}\n\\end{problem}\n\n\n", "meta": {"hexsha": "7b35a3dbc7f47622af363797a98cba4d1f3b8586", "size": 22181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-geom/affine-var.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-geom/affine-var.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-geom/affine-var.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.7844112769, "max_line_length": 91, "alphanum_fraction": 0.6790496371, "num_tokens": 7313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.6907862586474511}}
{"text": "\n\\section{MATLAB}\n\n\\subsection{Plots}\n\\par First things first: to create a vector of equally spaced elements is best to use \\bb{linspace}. It guarantees the same amount of points in each array more easily.\n\n\\begin{lstlisting}[language=matlab]\nt = linspace(-Ts, Ts, 200);\nplot(t, 2*t);\nxlabel('x axis, duh');\nylabel('y axis, hud'); \ntitle('guess?');\ngrid minor; %sometimes..\n\\end{lstlisting}\n\n\\par Use \\bb{meshgrid} and \\bb{surf}\\hspace{-.18cm}ace to plot functions with multiple variables:\n\n\\begin{lstlisting}\n[xx, yy] = meshgrid(x,y);  \nsurf(xx,yy, 2 * xx, 'EdgeColor', 'none');\n\\end{lstlisting}\n\n\\par \\bb{Meshgrid} is necessary because matlab doesn't know how to take do value iteration! The \\bb{surf} function DOES know that should take one value from x, run for all values of y and get the (x,y) value for each iteration from z. THEREFORE, z must be an length(x) by length(y) matrix! This is why the mesh grid command is used. It allows for this matrix creation just in the same way as one creates values for a 2D plot.\n\\par What \\bb{surf} will do is: check the sizes of the x and y vectors to see if it should iterate or just choose the right values. If x and y are row vectors, it will have to manually calculate all the possible combinations. If they are matrices (like the ones returned by meshgrid), it is able to just choose the appropriate combinations: take each element of each vector and plot it in space - notice what is returned by meshgrid is exactly the same dimensions as the Z vector will be.\n\\par To conclude: is possible to give x and y or X and Y as inputs for the \\bb{surf} function of MATLAB, however, Z must be a matrix! And that will only happen with meshgrid, otherwise it will be a vector without all combinations of values in x an y.\n\n\n\\subsubsection{Contour}\nIn portuguese \"contorno\", returns the levels curves of the function.\n\ncontour(X1, X2, Z, 10.\\textasciicircum(-20:3:0)') will plot the Z points of the coordinates X1, X2, on the levels 10.\\textasciicircum[-20 -17 -14 -11 -8 -5 -2].\nNote that if the points X1 and X2 are not provided, there is no \"set\" where to which is possible to compute the level curves, so Matlab chooses one and it may not fit your previous graph.\n\n\\subsubsection{Extra Stuff for Graphs}\nCheck all properties of a graph \\href{https://nl.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.line-properties.html}{\\uline{here}}. Some of them:\n\n\\bb{Subplots} - allow several figures in the same window.\n    Writing subplot(1,2,1) divides a window in a grid of 1x2 and will access the first element of it. Increasing the final number changes the division of the grid selected which is where the subsequent plots are going to end up on.\n\n\\bb{xlabel, ylabel} - labels for the Graphs\n\n\\bb{xlim, ylim} - limits for the Graphs\n\n\\bb{set current figure position (and size)} - set(gcf,'position',[x0, y0, width, height]); x0 is measure from the left of the screen. y0 is measure from the bottom of the screen. width is along x, height along y.\n\n\\bb{imagesc} - Image with scaled colours. imagesc(A); colorbar; shows quite fast the values that the matrix A has. A very useful tool to debug and to quickly have an insight on the matrix contents and patterns.\n\n\\bb{LineWidth}: a number for the thickness of the line \n\n\\bb{Dashed line}: '--' makes the line dashed.\n\n\\bb{DisplayName}: To specify a specific legend\n\n\\bb{legend} is possible to position the legend according to the cardinal points, \"North\", etc\\dots Use \\uline{legend('Location', 'North')}.It is also possible to put it in a desired location with legend('Position', [.25 .25 .25 .25]).\n\n\\bb{'HandleVisibility'} 'on' by default. This doesn't show a legend for a certain graph, useful for when we need to plot thresholds or something that we don't want to have a legend about.\n\n\n\\subsection{Functions}\n\nTo make a function, create a new file and write in the first line:\n\n\\begin{lstlisting}[language=matlab]\nfunction [o1,o2,o3] = nameOfTheFunction(i1,i2,i3) \n    %func code here\nend\n\\end{lstlisting}\nWhere the o's are the outputs and the i's are inputs.\n\nIs also possible to pass a function as an argument! For instance, if that function is what is suppose to be used inside another function.\n\nintegral(@log, x) is passing the built-in function \\ii{log} as an argument. \n\n\\subsection{Set and Matlab Objects}\nSince you've probably done something with Java or something with python oriented in that sense, you probably know what an object is. In Matlab, there are many object as well. Instead of changing its properties in the arguments of the instantiation of that object, one may create that object and then use the \\uline{set} method.\n\nThe following two pieces of code do exactly the same thing regarding legends.\n\n\\begin{lstlisting}[language=Matlab]\n    h = legend;\n    rect = [0.25, 0.25, .25, .25];\n    set(h, 'Position', rect);\n\n    legend('Position', rect);\n\\end{lstlisting}\n\nThe rectangle should be [x0, y0, width, height], in percentages, given that 1 is the size of the figure.\n\n\n\\todo{check}\n\nActually, I have the sensation that in this case, \"Position\" is nothing more than an internal variable.\n\n\n\\subsection{Save images}\n\n\\begin{lstlisting}[language=matlab,numbers=none]\nfig = figure;\nplot(t,x);\npause(0.2); %may be necessary so that the figures ends plotting, before it starts saving\nprint(fig,'-dpng','img_filename'); %as png\n\\end{lstlisting}\n\n\\par Or use the following for printing the current figure:\n\\begin{lstlisting}[language=matlab,numbers=none]\nplot(t,x);\nprint('myfig.png', '-dpng');\n\\end{lstlisting}\n\n\\par \\bb{OR EVEN} imagining it was necessary to open a file to plot that picture. File named 'ola.bin' (binary file), for instance. If the image is going to be included in some report, using .eps is a good idea since it allows \"infinite zoom\" because it describes the picture by vectors, instead of saving the information of each pixel of compressed.\n\\par The code below will save as .eps (Encapsulated PostScript) file.\n\\begin{lstlisting}[language=matlab]\nplot(t,x, 'r');\nhold on;\nplot(t, x_window, 'b');\nprint([file(1:end-4) '-hamming'], '-depsc')\n\\end{lstlisting}\n\\par Check more formats in \\href{https://nl.mathworks.com/help/matlab/ref/print.html}{print page of matlab}.\n\n\n\\subsection{Opening stuff}\n\\par In CSV format:\n\\begin{lstlisting}[language=matlab]\nfile = csvread('file.csv');\n\\end{lstlisting}\n\n\\par But better is to open as a matrix, in a big variety of formats:\n\\begin{lstlisting}[language = matlab]\n    %Excel\n    A = readmatrix('File.xlsx','Sheet', 3,'Range','A1:AX5000');\n    A = readmatrix('file.xlsx','Sheet', \"name of sheet3\",'Range','A1:AX5000');\n    %More formats coming when I use it for them\n\\end{lstlisting}\n\n\\subsection{Max and Min}\n\\par \\bb{Max} function is incredibly useful. Returns the maximum of a vector and the place it appears in! Of course, the \\bb{min} flavour exists too.\n    \\begin{lstlisting} [language = matlab]\n        [maximum, index] = max(1:10)\n    \\end{lstlisting}\n    \nYou can even specify the dimension on which you want the maximum. So, if you want the maximum of each row, max(A, 2) will do a column vector with as many maximums as there are rows, thus a column vector.\n\n\n\n\n\\subsection{Other useful tools}\n\n\\begin{itemize}\n\t\\item It is possible to see \\bb{EVERY} command written in matlab. Just write 'commandhistory' or press the above arrow. The commands there are OLD!\n\n\t\\item \\bb{Load}, \\bb{save}, \\bb{exist}, \\bb{return} to stop execution and \\bb{clear} one variable:\n\t\\begin{lstlisting}[language=matlab]\n        try \n            B = load(\"A.mat\");\n            B = B.A; %to get the matrix out of the structure\n        catch\n            if ~exist('Traces.xlsx', 'file')\n                return\n            end\n            %create A code here;\n            clear aux;\n            save('A.mat', 'A');\n        end\n    \\end{lstlisting}\n    \\item \\bb{squeeze} to take away not needed dimensions. For instance in a 1x1x5000 vector, the following code will result in a 5000x1 vector.\n    \\begin{lstlisting}[language = matlab]\n        squeeze(R(prb,1,:))\n    \\end{lstlisting}\n    \\item \\bb{find} to find an element in an array! Simply returns a vector with the indexes of where that element appears.\n    \\begin{lstlisting}[language=matlab]\n        find(a == 0)\n        find(a < 5)\n        find(a == b) %return all i that a(i) == b(i), i.e all elements that are in both vectors\n    \\end{lstlisting}\n    ``The relational operators ($>$, $<$, $>=$, $<=$, $==$, $\\sim =$) impose conditions on the array, and you can apply multiple conditions by connecting them with the logical operators and, or, and not, respectively denoted by the symbols \\&, $|$, and $\\sim$.'' From the \\href{https://nl.mathworks.com/help/matlab/matlab_prog/find-array-elements-that-meet-a-condition.html}{\\ul{Matlab Docs}}.\n    \\par Additionally: ``[row,col] = find(X) returns the row and column subscripts of each non-zero element in array X '' And this explains the above uses of this function.\n    \\item A cool way of \\bb{copying an array size}:\n    \\begin{lstlisting}[language=matlab]\n        a = zeros(size(b)) %copies size of b to the use we want to give a\n    \\end{lstlisting}\n    \n    \\item To select random elements of an array: permute the indexes and select the first n elements of that permutation.\n    \\begin{lstlisting}[language=matlab]\n        m = 100; n = 10;\n        a = 1:m;\n        randIndexes = randperm(m);\n        b = a(randIndexes(1:n));\n    \\end{lstlisting}\n    \n    \\item Cell to Logical to Double:\n    \\vspace{-.1cm}\n    \\quickimage{cellToLogicalToDouble.png}{.4}\n\\end{itemize}\n\n\n\n\n\n\n\\subsection{Label data in Scatter plots}\n\\par By far the best way of getting a decent result is to use an already written function. Adam Danz published \\href{https://nl.mathworks.com/matlabcentral/fileexchange/46891-labelpoints}{\\ul{here}} a function that does this perfectly for you. \n\n\\par From the examples it becomes very evident the use. The function requires at least the coordinates of every point and the labels to put in every data point.\n\n\\begin{lstlisting}[language=matlab]\n    labelpoints(x, y, 'Color', [1 0.5 0.5], 'FontSize', 12);\n\\end{lstlisting}\n\n\n\n\n\n\n\\subsection{Create Gif from plots}\n\\par It can't get easier than this. Chad Greene wrote a miraculous script and published it \\href{https://nl.mathworks.com/matlabcentral/fileexchange/63239-gif}{\\ul{here}}.\n\n\\par Before any plot, write:\n\\begin{lstlisting}[language=matlab]\n    gif('mygiffilename.gif');\n    gif(gif_name,'DelayTime',0.2,'LoopCount',1,'frame',gcf);\n\\end{lstlisting}\n\\par Then, to insert a frame simply write \\bb{gif}:\n\n\\begin{lstlisting}[language=matlab]\n    for i = 1:10\n        plot(x,y);\n        gif;\n    end\n\n    web('mygiffilename.gif'); %will open on matlab web.\n\\end{lstlisting}\n\n\\par That is it. It can't get simpler. To view the gif with controls you can use a video player.\n\n\n\n\\subsection{Write table to Excel}\n\\par A matrix looks like a table but will look like a line if you use the writematrix. Instead, use \\bb{writetable} and convert the matrix to a table before!\n\n\\begin{lstlisting}[language=matlab]\n    table = array2table(squeeze(avg_rates_perTest(1,:,:)))\n\n    for scheduler = 1:length(schedulers_for_testing)\n        writetable(table, ...\n                    num2str(scheduler) +\"-avg_rates_per_test\"+ \".xlsx\");\n    end\n\\end{lstlisting}\n\n\\par Additionally, is possible to add the correct names to the columns, but they have to have possible variable names... So there are some limitations: just letters, numbers and underscores and has to start with a letter.\n\n\\begin{lstlisting}[language=matlab]\n    table = array2table(array, 'VariableNames', {'first_name', 'second', 'etc'});\n\\end{lstlisting}\n\n\n", "meta": {"hexsha": "3d0acb9486a01a4509673e52a7a313576c8ce997", "size": 11661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Matlab.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/Matlab.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/Matlab.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": 45.55078125, "max_line_length": 488, "alphanum_fraction": 0.7167481348, "num_tokens": 3095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8856314677809303, "lm_q1q2_score": 0.6907862571107494}}
{"text": "\\subsection{Graph Theoretical Approach}\n\nThis section aims to investigate the connection between Markov chains and graph \ntheory by exploring alternative ways of calculating the steady state probabilities \nand considering the problem from different perspectives.\n\n\\subsubsection{Parameters}\nThe parameters considered as inputs are:\n\\begin{multicols}{2}\n    \\begin{itemize}\n        \\item the number of servers \\(C\\),\n        \\item the threshold \\(T\\), \n        \\item the capacity of the service centre \\(N\\),\n        \\item the capacity of the buffer centre \\(M\\). \n    \\end{itemize}\n\\end{multicols}\n\nAdditional parameters of the model are the class 1 individuals arrival rate, \nthe class 2 individuals\narrival rate and the service rate (\\(\\lambda_2, \\lambda_1, \\mu\\)). \nMore specifically, the way these parameters are translated into the model are:\n\n\\begin{itemize}\n    \\item \\textbf{Number of servers (\\(C\\)):} Affects the weight of all edges \n    \\((v_i, v_j) \\in E\\) in the Markov chain that correspond to a service rate. \n    These edges have a weight of: \n    \\begin{equation*}\n        w_{(v_i, v_j)} = q_{v_i, v_j}\n    \\end{equation*}\n    where \\(q_{i,j}\\) is defined in equation \\ref{eq:markov_transition_rate}.\n    Thus, the coefficients of the service rate have a lower bound of \\(1\\) and \n    an upper bound of \\(C\\).\n    \\item \\textbf{Threshold (\\(T\\)):} Determines the length of the left \n    \\textit{arm} of the model. \n    In essence the threshold acts as a breakpoint between states where \\(u=0\\) \n    and states where \\(0 \\leq u \\leq M\\). \n    Increasing \\(T\\) results in having more set of states where \\(u\\) can only \n    be \\(0\\).\n    \\item \\textbf{Service centre capacity (\\(N\\)):} Is the upper bound of \\(v\\) for all \n    states \\((u,v)\\).\n    \\item \\textbf{Buffer centre capacity (\\(M\\)):} Is the upper bound of \\(u\\) for all \n    states \\((u,v)\\) such that \\(v \\geq T\\).\n\\end{itemize}\n\n\n\\subsubsection{Example figure of Markov Model}\n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.7}{\n        \\input{MarkovChain/closed_form_state_probs/example_model_1352/main.tex}\n        }\n    \\caption{\\(C=1, T=3, N=5, M=2\\)}\n    \\label{fig:Markov_1352_example_for_closed_form}\n\\end{figure}\n\nIn figure \\ref{fig:Markov_1352_example_for_closed_form} an example of such a \nMarkov model is shown where \\(C=1\\), \\(T=3\\) which means that the \\textit{left \narm} \nof the model has a length of \\(3\\), \\(N=5\\) that indicates that the right-most \nstates \\((u,v)\\) are of the form \\((u,5)\\) and \\(M=2\\) that equivalently shows \nthat the bottom states are of the form \\((2,v)\\).\n\n\\subsubsection{A graph theoretic model underling the Markov chain}\n\nAn additional approach that one may consider to get the state probabilities is \nthe graph theoretical approach for state probabilities.\nThus, it can be assumed that a Markov chain model \\(M\\) can be translated as a \nweighted directed graph \\(G_M = (V, E)\\) where \\(V=S\\) from equation \n\\ref{eq:state_space} and \\((v_i, v_j)\\in E\\) if and only if \\(q_{v_i, v_j}>0\\). \nFurthermore, the weights are given by:\n\\[\n    w(v_i, v_j) = q_{v_i, v_j}\n\\]\n\nA \\textit{directed spanning tree} of a directed graph is defined as a subset of \nthe graph that visits all the vertices of the graph and does not include any cycles. \nUnlike undirected spanning trees, directed ones also have a root which means \nthat a directed spanning tree that is rooted at a vertex \\(v\\) has to have a \npath from any other vertex to vertex \\(v\\). \nFor example, consider the graph shown in figure \\ref{fig:example_spanning_tree}.\nThe graph points out a spanning tree that is rooted at vertex 3.\n\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}\n        \\node[state](u1){1};\n        \\node[state, right=of u1](u2){2};\n        \\node[state, right=of u2](u3){3};\n        \\node[state, right=of u3](u4){4};\n        \\node[state, below=of u2](u5){5};\n        \\node[state, below=of u3](u6){6};\n        \\node[state, below=of u4](u7){7};\n        \\draw[->, thick] (u1) -- (u2);\n        \\draw[->, thick] (u2) -- (u3);\n        \\draw[->, thick] (u4) -- (u3);\n        \\draw[->, thick] (u5) -- (u2);\n        \\draw[->, thick] (u6) -- (u5);\n        \\draw[->, thick] (u7) -- (u6);\n    \\end{tikzpicture}\n    \\caption{Spanning tree of a graph rooted at vertex 3}\n    \\label{fig:example_spanning_tree}\n\\end{figure}\n\nAdditionally, let us denote the set of all spanning trees of \\(G\\) as \\(T(G)\\) \nand the subset of \\(T(G)\\) that includes only the spanning trees that are rooted \nat vertex \\(v\\) as \\(T_v(G)\\). \nThe weight of a spanning tree \\(t\\) can be defined as the product of the weights \nof the edges it contains: \n\n\\[w(t)=\\prod_{e \\in t} w(e)\\]\n\n\n\n\\textbf{Theorem: Markov chain tree theorem} \\cite{broder1989generating} \\newline\n\\textit{Let M be an irreducible Markov chain on n states with stationary \ndistribution \\(\\pi_1, \\pi_2, \\dots, \\pi_n\\). \nLet \\(G_M\\) be the directed graph associated with \\(M\\). \nThen the probability of being at state \\(u\\) is given by:}\n\n\\begin{equation}\\label{markov-chain-tree-theorem}\n    \\pi_i = \\frac{\\sum_{t \\in T_i(G_M)} w(t)}{\\sum_{t \\in T(G_M)}w(t)}\n\\end{equation}\n\nEquation \\ref{markov-chain-tree-theorem} states that the probability of being at\nstate \\(u\\) can be found by dividing the sum of the weights of all trees in \n\\(T_u(G)\\) by the sum of the weights of all tress in \\(T(G)\\). \nLet us ignore the denominator of that fraction for now and focus only on the \nnumerator denoted as \\(\\tilde{\\pi}_i=\\sum_{t \\in T_i(G_M)} w(t)\\)\n\n \n\n\\newpage\n\\subsubsection{Spanning Trees rooted at \\((0,0)\\)}\n\nLet us now consider some examples of spanning trees that are rooted at \\((0,0)\\). \nFor each of the following examples the complete graph \\(G\\) is shown, then all \npossible trees of \\(T_{(0,0)}(G)\\) along with the weight associated with each \nspanning tree.\nAs well as this, the sum of all the weights of the spanning trees denoted by \n\\(\\tilde{\\pi}_{(0,0)}\\) is also included.\n\n\\begin{figure}[h]\n    \\centering\n    \\input{MarkovChain/closed_form_state_probs/example_model_1121/main.tex}\n\\end{figure}\n\n\\begin{multicols}{2}\n    \\begin{center}\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1121/main_0.tex}\n    \\end{center}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} \\lambda_2 \\mu^3\n    \\end{flalign*}\n\\end{multicols}\n\n\n\\begin{multicols}{2}\n    \\begin{center}\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1121/main_1.tex}\n    \\end{center}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} \\mu^4\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{equation*}\n    \\tilde{\\pi}_{(0,0)} = \\mu^4 + \\lambda_2 \\mu^3\n\\end{equation*}\n\n\n\n\\newpage\n\\begin{figure}[h]\n    \\centering\n    \\input{MarkovChain/closed_form_state_probs/example_model_1131/main.tex}\n\\end{figure}\n\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.7}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_0.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} (\\lambda_2)^2 \\mu^4\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.7}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_1.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} \\lambda_2 \\mu^5\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.7}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_2.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} \\lambda_2 \\mu^5\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.7}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_3.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} \\lambda_2 \\lambda_1 \\mu^4\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.7}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_4.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} \\mu^6\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{equation*}\n    \\tilde{\\pi}_{(0,0)} = (\\lambda_2)^2 \\mu^4 + 2 \\lambda_2 \\mu^5 + \n    \\lambda_2 \\lambda_1 \\mu^4 + \\mu^6\n\\end{equation*}\n\n\n\\newpage\n\\begin{figure}[h]\n    \\centering\n    \\input{MarkovChain/closed_form_state_probs/example_model_1122/main.tex}\n\\end{figure}\n\n\\begin{multicols}{4}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1122/main_0.tex}}\n    \\end{figure}\n    \\vspace*{\\fill}\n    \\columnbreak\n    \\vspace*{0cm}\n    \\begin{equation*}\n        (\\lambda_2)^2 \\mu^4\n    \\end{equation*}\n    \\vspace*{\\fill}\n    \\columnbreak\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1122/main_1.tex}}\n    \\end{figure}\n    \\vspace*{\\fill}\n    \\columnbreak\n    \\vspace*{0.3cm}\n    \\begin{equation*}\n        \\lambda_2 \\mu^5\n    \\end{equation*}\n\\end{multicols}\n\n\\begin{multicols}{4}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1122/main_2.tex}}\n    \\end{figure}\n    \\vspace*{\\fill}\n    \\columnbreak\n    \\vspace*{0.3cm}\n    \\begin{equation*}\n        \\lambda_2 \\mu^5\n    \\end{equation*}\n    \\vspace*{\\fill}\n    \\columnbreak\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1122/main_3.tex}}\n    \\end{figure}\n    \\vspace*{\\fill}\n    \\columnbreak\n    \\vspace*{0.3cm}\n    \\begin{equation*}\n        \\mu^6\n    \\end{equation*}\n\\end{multicols}\n\n\n\\begin{equation*}\n    \\tilde{\\pi}_{(0,0)} = (\\lambda_2)^2 \\mu^4 + 2 \\lambda_2 \\mu^5 + \\mu^6\n\\end{equation*}\n\n\\newpage\n\\subsubsection{Conjecture of adding rows}\n\nLet us consider three Markov models with the same number of servers \\(C=1\\), \nthe same threshold \\(T=1\\), the same service centre capacity \\(N=2\\) but \n\\(M\\in\\{1, 2, 3\\}\\).\n\n\n\\begin{multicols}{3}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.8}{\n            \\input{MarkovChain/closed_form_state_probs/example_model_1121/main.tex}}\n        \\caption{\\(M=1\\)}\n    \\end{figure}\n    \\columnbreak\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.8}{\n            \\input{MarkovChain/closed_form_state_probs/example_model_1122/main.tex}}\n        \\caption{\\(M=2\\)}\n    \\end{figure}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.8}{\n            \\input{MarkovChain/closed_form_state_probs/example_model_1123/main.tex}}\n        \\caption{\\(M=3\\)}\n    \\end{figure}\n\\end{multicols}\n\nBy increasing the buffer centre capacity of the system it can be observed that \n\\(|T_{(0,0)}(G)|\\) increases as well since more combinations of paths can be \ngenerated using the new edges and vertices. \nThe corresponding values of \\(\\tilde{\\pi}_{(0,0)}\\) of the three systems are:\n\n\\begin{align}\n    M = 1: \\tilde{\\pi}_{(0,0)} &= \\mu^4 + \\mu^3 \\lambda_2 = \n    \\mu^3 (\\mu + \\lambda_2) \\label{eq:rows-conjecture-1}\\\\\n    M = 2: \\tilde{\\pi}_{(0,0)} &= \\mu^6 + 2\\mu^5 \\lambda_2 + \\mu^4 (\\lambda_2)^2 \n    = \\mu^4(\\mu^2 + 2\\mu \\lambda_2 + (\\lambda_2)^2) \n    = \\mu^4 (\\mu + \\lambda_2) ^ 2 \\label{eq:rows-conjecture-2}\\\\\n    M = 3: \\tilde{\\pi}_{(0,0)} &= \\mu^8 + 3 \\mu^7 \\lambda_2 + \n    3 \\mu^6 (\\lambda_2)^2 + \\mu^5(\\lambda_2)^3 \\nonumber \\\\\n    &= \\mu^5 (\\mu^3 + 3 \\mu ^2 \\lambda_2 + 3 \\mu (\\lambda_2)^2 + (\\lambda_2)^3) \n    \\nonumber \\\\\n    &= \\mu^5 (\\mu + \\lambda_2) ^ 3 \\label{eq:rows-conjecture-3}\n\\end{align}\n\nNote that in equations (\\ref{eq:rows-conjecture-1}),(\\ref{eq:rows-conjecture-2}) \nand (\\ref{eq:rows-conjecture-3}), the following equation holds: \n\n\\begin{equation}\\label{eq:rows-conjecture-general}\n    \\tilde{\\pi}_{(0,0)} = \\mu^{(N+M)} (\\mu + \\lambda_2)^M\n\\end{equation}\n\n% TODO: Perform experiments to validate this\nThis relationship has been verified experimentally for ... and the data set is \narchived at ... \nA generalisation of equation \\ref{eq:rows-conjecture-general}, where \\(N \\geq 1\\), \nis given in terms of an unknown function \\(k(C,T,N)\\) as:\n\n\\begin{equation}\n    \\tilde{\\pi}_{(0,0)} = \\mu^{(N+M)} (k(C,T,N))^M\n\\end{equation}\n\nThus, having investigated the effect of adding rows (increasing \\(M\\)) it remains \nto investigate the effect of adding columns (increasing \\(N\\)) and finding an \nexpression for \\(k(C,T,N)\\).\n\n\\subsubsection{The effect of increasing \\(N\\) (Incomplete section)}\nIn this section we will consider a buffer centre capacity of \\(M=1\\) and see the \neffect \nof modifying other parameters on \\(k(C, T, N)\\).\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.9}{\n            \\input{MarkovChain/closed_form_state_probs/example_model_1121/main.tex}}\n    \\end{figure}\n    \\columnbreak\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.9}{\n            \\input{MarkovChain/closed_form_state_probs/example_model_1131/main.tex}}\n    \\end{figure}\n\\end{multicols}\n\\vspace{-0.5cm}\n\\begin{alignat}{2} \\label{eq:00_rate_1131}\n    \\hspace{4em} & \\tilde{\\pi}_{(0,0)} = \\mu^3[\\lambda_2 + \\mu] \\hspace{8em} & \n    \\tilde{\\pi}_{(0,0)} = \\mu^4[(\\lambda_2)^2 + \\lambda_2 \\lambda_1 + 2\\lambda_2 \n    \\mu + \\mu^2] \n\\end{alignat}\n\n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.8}{\n        \\input{MarkovChain/closed_form_state_probs/example_model_1141/main.tex}}\n\\end{figure}\n\\begin{equation}\\label{eq:00_rate_1141}\n    \\tilde{\\pi}_{(0,0)} = \\mu^5[(\\lambda_2)^3 + 2(\\lambda_2)^2 \\lambda_1 + \n    3(\\lambda_2)^2 \\mu + \\lambda_2 (\\lambda_1)^2 + 2\\lambda_2 \\lambda_1 \\mu + \n    3\\lambda_2 \\mu^2 + \\mu^3]\n\\end{equation}\n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.8}{\n        \\input{MarkovChain/closed_form_state_probs/example_model_1151/main.tex}}\n\\end{figure}\n\\begin{align}\\label{eq:00_rate_1151}\n    \\tilde{\\pi}_{(0,0)} =& \\mu^6[(\\lambda_2)^4 + 3(\\lambda_2)^3 \\lambda_1 + \n    4(\\lambda_2)^3 \\mu + 3(\\lambda_2)^2 (\\lambda_1)^2 + \n    6(\\lambda_2)^2 \\lambda_1 \\mu \\\\\n    & + 6(\\lambda_2)^2 \\mu^2 + \\lambda_2 (\\lambda_1)^3 + \n    2\\lambda_2 (\\lambda_1)^2 \\mu + 3\\lambda_2 \\lambda_1 \\mu^2 + \n    4\\lambda_2 \\mu^3 + \\mu^4] \\nonumber\n\\end{align}\n\n\\newpage\nAs explained in equation \\ref{eq:rows-conjecture-general} the expressions defined \nabove can boil down to a general form equation of the form \n\\(\\tilde{\\pi}_{(0,0)} = \\mu^{(N+M)} (k(C,T,N))^M\\). \nThe only thing missing is an expression for \\(k(C,T,N)\\). \nAn initial attempt to get such an expression can be seen below:\n\n\\begin{align}\\label{eq:columns-conjecture-general}\n    k(C,T,N) &= \\sum_{p_1=0}^{C-1} \\sum_{p_2=0}^{C-p_1-1} \n    \\sum_{p_3=C - p_1 - p_2 - 1}^{C - p_1 - p_2 - 1} R(p_1, p_2, p_3) \n    (\\lambda_2)^{p_1} (\\lambda_1)^{p_2} \\mu^{p_3} \\nonumber \\\\ \n    &= \\sum_{p_1=0}^{C-1} \\sum_{p_2=0}^{C-p_1-1} R(p_1, p_2, C-p_1-p_2-1) \n    (\\lambda_2)^{p_1} (\\lambda_1)^{p_2} \\mu^{C-p_1-p_2-1} \n\\end{align}\n\nIn equation \\ref{eq:columns-conjecture-general} the coefficient function \n\\(R(p_1,p_2,p_3)\\) is introduced were takes as arguments the powers of \n\\(\\lambda_2, \\lambda_1 \\text{ and } \\mu\\). \nNote here that \\(p_3\\), the power of \\(\\mu\\), is defined as \\(p_3=C-p_1-p_2-1\\) \nsince for all base models they need to satisfy \\(p_1 + p_2 + p_3 = C-1\\). \nFor the starting coefficients of the model the function \\(R(p_1,p_2,p_3)\\) gives \nthe values of the coefficients and is defined as:\n\n\\begin{equation} \\label{eq:coefficient-function}\n    R(p_1,p_2,p_3) = \n    \\begin{cases}\n        0 & \\text{if } p_1 = 0 \\text{ and } p_2 > 0 \\vspace{0.1cm} \\\\\n        1 & \\text{if } p_1, p_2 = 0 \\text{ and } p_3 > 0 \\vspace{0.2cm} \\\\\n        \\binom{p_1 + p_3}{p_3} & \\text{if } p_2 = 0 \n        \\text{ and } p_1 > 0 \\vspace{0.2cm} \\\\\n        \\binom{p_1 + p_2 - 1}{p_2} & \\text{if } p_3 = 0 \n        \\text{ and } p_1, p_2 > 0 \\vspace{0.2cm} \\\\\n        p_3 + 1 & \\text{if } p_1 = 1 \\vspace{0.2cm} \\\\\n        \\binom{p_1 + p_3 + 1}{p_1} + p_3 \\binom{p_1 + p_3}{p_3+1} - \n        \\binom{p_1 + p_3}{p_3} & \\text{if } p_2 = 1 \n        \\text{ and } p_1 > 1 \\vspace{0.2cm} \\\\\n        \\binom{p_1 + p_2 + 1}{p_1} - \\binom{p_1 + p_2 - 1}{p_2-1} + \n        \\sum_{i=p_2}^{p_1 + p_2 - 2} i \\binom{i-1}{p_2 - 1} & \\text{if } p_3 = 1 \n        \\text{ and } p_1,p_2 > 1 \\vspace{0.2cm} \\\\\n        U_{p_1,p_2,p_3} & \\text{otherwise}\n    \\end{cases}\n\\end{equation}\n\nNote here that the final value \\(U_{p_1,p_2,p_3}\\) corresponds to coefficients \nthat are unknown and are currently investigated. \nThe function \\(R\\) takes as arguments a possible combination of numbers of \n\\(\\lambda_2, \\lambda_1 \\text{ and } \\mu \\) for a given system and outputs the \ncoefficient of that term which in turn represents how many spanning trees exist \nin the graph with that specific combination. \nFor instance consider the coefficients \\((p_1,p_2,p_3)\\) of some of the terms \nfrom the equations above:\n\n\\begin{multicols}{2}\n    \\begin{itemize}\n        \\item (\\ref{eq:00_rate_1131}) \\( \\Rightarrow (\\lambda_2)^2\\): \n        \\(R(2,0,0) = \\binom{2+0}{0} = 1\\)\n        \\item (\\ref{eq:00_rate_1131}) \\( \\Rightarrow \\lambda_2 \\lambda_1\\): \n        \\(R(1,1,0) = \\binom{1+1-1}{1} = 1\\)\n        \\item (\\ref{eq:00_rate_1131}) \\( \\Rightarrow 2 \\lambda_2 \\mu\\): \n        \\(R(1,0,1) = \\binom{1+1}{1} = 2\\)\n        \\item (\\ref{eq:00_rate_1131}) \\( \\Rightarrow \\mu^2\\): \\(R(0,0,2) = 1\\)\n        \\item (\\ref{eq:00_rate_1141}) \\( \\Rightarrow 2(\\lambda_2)^2 \\lambda_1\\): \n        \\(R(2,1,0) = \\binom{2+1-1}{1} = 2\\)\n        \\item (\\ref{eq:00_rate_1141}) \\( \\Rightarrow 3(\\lambda_2)^2 \\mu\\): \n        \\(R(2,0,1) = \\binom{2+1}{1} = 3\\)\n        \\item (\\ref{eq:00_rate_1141}) \\( \\Rightarrow 3 \\lambda_2 \\mu^2\\): \n        \\(R(1,0,2) = \\binom{1+2}{2} = 3\\)\n        \\item (\\ref{eq:00_rate_1151}) \\( \\Rightarrow 3 (\\lambda_2)^3 \\lambda_1\\): \n        \\(R(3,1,0) = \\binom{3+1-1}{1} = 3\\)\n        \\item (\\ref{eq:00_rate_1151}) \\( \\Rightarrow 3 (\\lambda_2)^2 (\\lambda_1)^2 \\): \n        \\(R(2,2,0) = \\binom{3}{2} = 3\\)\n        \\item (\\ref{eq:00_rate_1151}) \\( \\Rightarrow 6 (\\lambda_2)^2 \\mu ^ 2\\): \n        \\(R(2,0,2) = \\binom{2+2}{2} = 6\\)\n    \\end{itemize}\n\\end{multicols}\n\n\\begin{itemize}\n    \\item (\\ref{eq:00_rate_1151}) \\( \\Rightarrow 6 (\\lambda_2)^2 \\lambda_1 \\mu\\): \n    \\(R(2,1,1) = \\binom{2+1+1}{2} + 1\\binom{2+1}{1+1} - \\binom{2+1}{1} = 6 + 3 - 3 = 6\\)\n    \\item \\small{(e.g)} \\( \\Rightarrow (\\lambda_2)^2 (\\lambda_1)^2 \\mu\\): \n    \\(R(2,2,1) = \\binom{2+2+1}{2} - \\binom{2+2-1}{2-1} + \\sum_{i=2}^{2+2-2} \n    i\\binom{i-1}{2-1} = 10 - 3 + (2 \\times 1) = 9\\)\n\\end{itemize}\n\n\n\n\\subsubsection{Unknown terms}\n\nThe terms that remain unknown are the terms where \\(p_1, p_2, p_3 \\geq 2\\). \nHere are some of these values with the corresponding values of the \n\\(R(p_1,p_2,p_3)\\) function.\n\n\\begin{multicols}{2}\n    \\begin{itemize}\n        \\item \\(R(2,2,2) = 18\\) \n        \\item \\(R(3,2,2) = 60\\)\n        \\item \\(R(2,3,2) = 24\\)\n        \\item \\(R(2,2,3) = 30\\)\n        \\item \\(R(4,2,2) = 150\\)\n        \\item \\(R(3,3,2) = 100\\)\n        \\item \\(R(3,2,3) = 120\\)\n        \\item \\(R(2,4,2) = 30\\)\n        \\item \\(R(2,3,3) = 40\\)\n        \\item \\(R(2,2,4) = 45\\)\n    \\end{itemize}\n\\end{multicols}\n\n\\subsubsection{DRL arrays}\n\nIn this section a new combinatorial object is defined: DRL arrays. \nIt will be shown that there is a bijection between DRL arrays and the spanning \ntrees in \\(G_M\\).\nDRL arrays will then be enumerated which in turn enumerates the trees of \n\\(T_{(0,0)}(G_M)\\).\nConsider the following Markov model and the spanning trees rooted at state \n\\((0,0)\\) that are associated with it. \n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.8}{\n        \\input{MarkovChain/closed_form_state_probs/example_model_1131/main.tex}} \n        \\vspace{0.8cm} \\\\\n    \\scalebox{0.6}{\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_0.tex}} \n        \\hspace{0.7cm}\n    \\scalebox{0.6}{\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_1.tex}} \n        \\vspace{0.4cm} \\\\\n    \\scalebox{0.6}{\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_2.tex}} \n        \\hspace{0.7cm}\n    \\scalebox{0.6}{\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_3.tex}}\n        \\vspace{0.4cm} \\\\\n    \\scalebox{0.6}{\n        \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_4.tex}}\n\\end{figure}\n\nLooking at these spanning trees from a different perspective it can be observed \nthat all spanning trees of the specific model have some edges in common. \n\n\\begin{multicols}{4}\n    \\begin{itemize}\n        \\item \\((0,1) \\rightarrow (0,0)\\)\n        \\item \\((1,1) \\rightarrow (0,1)\\)\n        \\item \\((1,2) \\rightarrow (1,1)\\)\n        \\item \\((1,3) \\rightarrow (1,2)\\)\n    \\end{itemize}\n\\end{multicols}\n\nThese edges are the ones on the bottom row of the model, on the \n\\textit{threshold column} and on the \\textit{arm} of the model. \nIn general the set of edges that are present on all spanning trees can be \ndenoted by:\n\\begin{align} \\label{eq:common_edges_set}\n    S &= S_1 \\cup S_2 \\cup S_3 \\nonumber\\\\\n    S_2 &= \\{(M,v) \\rightarrow (M,v-1) \\; | \\; T < v \\leq N\\} \\nonumber \\\\\n    S_1 &= \\{(u,T) \\rightarrow (u-1,T) \\; | \\; 0 < u \\leq M\\} \\nonumber \\\\\n    S_3 &= \\{(0,v) \\rightarrow (0,v-1) \\; | \\; 0 < v \\leq T\\} \\nonumber \\\\\n\\end{align}\n\nIn addition, these edges that are common to every spanning tree (for a threshold \nof \\(T=1\\)) have the same weight of \\(\\mu\\). \nIn this specified model there are four of these edges, each with a weight of \n\\(\\mu\\). \nThus, since these edges exist on all spanning trees, the weight of every spanning \ntree must have include a term \\(\\mu^4\\). \nConsider the expression of \\(\\tilde{\\pi}_{(0,0)}\\) associated with this Markov \nmodel:\n\n\\begin{equation}\\label{eq:pi_00_rate_example}\n    \\tilde{\\pi}_{(0,0)} = \\mu^4[(\\lambda_2)^2 + \\lambda_2 \\lambda_1 \n    + 2\\lambda_2 \\mu + \\mu^2] \n\\end{equation}\n\nIt can be seen that there is a \\(\\mu^4\\) term that is a common factor of all the\n terms. \nThis term can be more generally calculated as \\(\\mu^{M+N}\\) and by not worrying \nabout all these edges that belong in \\(S\\) the problem can be slightly simplified.\n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.7}{\n        \\begin{tikzpicture}[-, node distance = 1cm, auto]\n            \\node[state] (u0v0) {(0,0)};\n            \\node[state, right=of u0v0] (u0v1) {(0,1)};\n            \\draw[->](u0v1) edge node {\\(\\mu \\)} (u0v0);\n            \\node[state, below=of u0v1] (u1v1) {(1,1)};\n            \\draw[->](u1v1) edge node {\\(\\mu \\)} (u0v1);\n            \\node[state, right=of u0v1] (u0v2) {(0,2)};\n            \\node[state, right=of u1v1] (u1v2) {(1,2)};\n            \\draw[->](u1v2) edge node {\\(\\mu \\)} (u1v1);\n            \\node[state, right=of u0v2] (u0v3) {(0,3)};\n            \\node[state, right=of u1v2] (u1v3) {(1,3)};\n            \\draw[->](u1v3) edge node {\\(\\mu \\)} (u1v2);\n        \\end{tikzpicture}\n    }\n\\end{figure}\n\nThe specific problem has now been reduced to finding all possible combinations \nof two edges where one starts from \\((0,2)\\) and the other from \\((0,3)\\). \nThe possible edges that can be utilised here may have a direction of either \nleft, right, or down. \nThus, the objective of the problem can be transformed into finding all possible \npermutations of an array of size \\(2\\) where elements can be \\(L, R \\text{ or } D\\)\nand obey certain rules so that the permutation corresponds to a valid spanning \n tree. \n These rules are:\n\n\\begin{enumerate}\n    \\item Permutations ending with an \\(R\\) are not valid. \\label{rule1}\n    \\item Permutations that have an \\(R\\) followed by an \\(L\\) are not valid. \\label{rule2}\n\\end{enumerate}\n\nIf any of these two rules does not hold then the permutation is immediately invalid. \nRule \\ref{rule1} points to the cases where the final state has an edge pointing \nto the right of it, which cannot occur since that state is the right-most state \nof the first row. \nRule \\ref{rule2} makes sure that there are no neighbour states that point to \neach other since that would create a cycle and would not generate a valid \nspanning tree.\n\nFor instance, consider the model above. \nShown below, are all possible permutations of the array along with the excluded \ncases. \nThe valid permutations (on the left) are shown in the same order with their \ncorresponding spanning trees from the above figure and the invalid permutations \n(on the right) are followed by the rule that determines them invalid.\n\n\\begin{multicols}{2}\n    \\begin{itemize}\n        \\item \\([D, D]\\)\n        \\item \\([L, D]\\)\n        \\item \\([D, L]\\)\n        \\item \\([R, D]\\)\n        \\item \\([L, L]\\)\n        \\item \\(\\xcancel{[R, R]} \\rightarrow \\text{ Rule 1}\\) \n        \\item \\(\\xcancel{[L, R]} \\rightarrow \\text{ Rule 1}\\)\n        \\item \\(\\xcancel{[R, L]} \\rightarrow \\text{ Rule 2}\\)\n        \\item \\(\\xcancel{[D, R]} \\rightarrow \\text{ Rule 1}\\)\n    \\end{itemize}\n\\end{multicols}\n\n\\subsubsection{\n    Examples of mappings of directed spanning trees to permutation arrays}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_0.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\hspace*{-4cm} \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} [D, D]\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_1.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\hspace*{-4cm} \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} [L, D]\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_2.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\hspace*{-4cm} \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} [D, L]\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_3.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\hspace*{-4cm} \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} [R, D]\n    \\end{flalign*}\n\\end{multicols}\n\n\\begin{multicols}{2}\n    \\begin{figure}[H]\n        \\centering\n        \\scalebox{0.6}{\n            \\input{MarkovChain/closed_form_state_probs/spanning_trees_1131/main_4.tex}}\n    \\end{figure}\n\n    \\begin{flalign*}\n        \\hspace*{-4cm} \\xrightarrow{\\hspace*{2cm}} \\hspace{1cm} [L, L]\n    \\end{flalign*}\n\\end{multicols}\n\n\\subsubsection{Closed-form formula}\nA general formula for finding all such permutations can be found, where the \ninputs are \\( p_1\\), \\(p_2\\) and \\(p_3\\) that correspond to the number of \\(D\\),\n\\(R\\) and \\(L\\) respectively and the output would be the coefficient of the term \n\\((\\lambda_2)^{p_1} (\\lambda_1)^{p_2} \\mu^{p_3}\\). \nFor instance, by applying such a formula to the example in equation \n\\ref{eq:pi_00_rate_example}, the desired output should be:\n\n\\begin{itemize}\n    \\item \\((\\lambda_2)^2 \\hspace{0.95cm} \\rightarrow \\hspace{1cm} \n    p_1 = 2, p_2=0, p_3=0 \\hspace{1cm} \\rightarrow \\hspace{1cm} \n    \\text{coefficient } = 1\\)\n    \\item \\(\\lambda_2 \\lambda_1 \\hspace{1cm} \\rightarrow \\hspace{1cm} \n    p_1 = 1, p_2=1, p_3=0 \\hspace{1cm} \\rightarrow \\hspace{1cm} \n    \\text{coefficient } = 1\\)\n    \\item \\(2 \\lambda_2 \\mu \\hspace{1cm} \\rightarrow \\hspace{1cm}\n     p_1 = 1, p_2=0, p_3=1 \\hspace{1cm} \\rightarrow \\hspace{1cm} \n     \\text{coefficient } = 2\\)\n    \\item \\(\\mu^2 \\hspace{1.45cm} \\rightarrow \\hspace{1cm} \n    p_1=0, p_2=0, p_3=2 \\hspace{1cm} \\rightarrow \\hspace{1cm} \n    \\text{coefficient } = 1\\)\n\\end{itemize}\n\nThus, given all possible and valid combinations of powers among \\(\\lambda_2, \n\\lambda_1 \\text{ and } \\mu\\) (i.e. \\(p_1,p_2,p_3\\)) generated by equation \n\\ref{eq:columns-conjecture-general}, an alternative and improved form of the \nvalue of \\(R(p_1, p_2, p_3)\\) described in equation \\ref{eq:coefficient-function} \nis given by:\n\n\\begin{equation} \\label{eq:permutation formula}\n    R(p_1, p_2, p_3) = T(p_1, p_2, p_3) - E_R(p_1, p_2, p_3) - E_D(p_1, p_2, p_3) \n    - E_L(p_1, p_2, p_3) - E_{RL}(p_1, p_2, p_3)\n\\end{equation}\n\nConsider the above undefined equations. \nThe term \\(T(p_1,p_2,p_3)\\) denotes the number of all permutations where neither \nrule is applied, i.e. all possible ways one can arrange the elements of the array.\nThe term \\(E_R(p_1,p_2,p_3)\\) denotes the number of permutations that end in \\(R\\), \nwhich needs to be removed from the total of all permutations so that rule \\ref{rule1} \nis satisfied.\nHaving excluded all permutations that end in \\(R\\) it only remains to leave out \npermutations that have an \\(R\\) followed by an \\(L\\) (rule \\ref{rule2}).\nAlthough, removing all permutations ending in \\(R\\) was relatively straight forward,\nremoving all permutations that follow rule \\ref{rule2} is not that easy.\nThis is because equation \\(E_R(p_1,p_2,p_3)\\) already considers some cases where \nthere is an \\(R\\) followed by an \\(L\\).\nTherefore, in order to consider only new cases, permutations of rule \\ref{rule2} \nare split into three new terms; \\(E_D\\), \\(E_L\\) and \\(E_{RL}\\).\nThese terms denote the permutations that have an \\(R\\) followed by an \\(L\\) AND \ndo not end in \\(R\\).\nThe term \\(E_D\\) considers all permutations that end in \\(D\\) while \\(E_L\\) the \nones that end in \\(L\\).\nFinally, the last term (\\(E_{RL}\\)) denotes all permutations that end in \\(R\\), \n\\(L\\) where there is no other \\(R\\) followed by an \\(L\\) in any other position apart \nfrom the last two. \nThis term is used because in the \\(E_L\\) term, such cases (where \\(R\\) and \\(L\\) \nare in the last two positions) are only considered when there is another \\(R\\) followed \nby an \\(L\\) somewhere.\nThus, the term \\(E_{RL}\\) is a particular set of permutations that the formula of \n\\(E_L\\) fails to include by itself.\n\n\\begin{align}\n    T(p_1, p_2, p_3) &= \\frac{(p_1 + p_2 + p_3)!}{p_1! \\times p_2! \\times p_3!} \\\\\n    E_R(p_1, p_2, p_3) &= \\frac{(p_1 + p_2 + p_3 - 1)!}\n    {p_1! \\times (p_2-1)! \\times p_3!} \\\\\n    E_D(p_1, p_2, p_3) &= \\sum_{i=1}^{\\min(R,L)} (-1)^{i+1} \n    \\frac{(p_1 + p_2 + p_3 - i - 1)!}\n    {(p_1 - 1)! \\times (p_2 - i)! \\times (p_3 - i)! \\times (i)!} \\\\\n    E_L(p_1, p_2, p_3) &= \\sum_{i=1}^{\\min(R,L-1)} (-1)^{i+1} \n    \\frac{(p_1 + p_2 + p_3 - i - 1)!}\n    {p_1! \\times (p_2 - i)! \\times (p_3 - i - 1)! \\times (i)!} \\\\\n    E_{RL}(p_1, p_2, p_3) &= \\sum_{i=1}^{\\min(R,L)} (-1)^{i+1} \n    \\frac{(p_1 + p_2 + p_3 - i - 1)!}\n    {p_1! \\times (p_2 - i)! \\times (p_3 - i)! \\times (i - 1)!} \n\\end{align}\n\n\\begin{equation*}\n    R(p_1, p_2, p_3) = T(p_1, p_2, p_3) - E_R(p_1, p_2, p_3) - E_D(p_1, p_2, p_3) \n    - E_L(p_1, p_2, p_3) - E_{RL}(p_1, p_2, p_3)\n\\end{equation*}\n\n\\subsubsection{Example of the permutation algorithm}\nConsider the term \\((\\lambda_2) (\\lambda_1) \\mu^2\\) and the above expressions.\nIn order to get the coefficient of that term the permutation algorithm needs to \nbe applied with an input of \\(p_1=1, p_2=1, p_3=2\\), i.e. 1 \\(D\\), 1 \\(R\\) and 2 \n\\(L\\)s in the array.\nThe permutations that correspond to each expression can be seen below:\n\n\\begin{equation*}\n    T(p_1, p_2, p_3) = \\frac{(1+1+2)!}{1! \\; 1! \\; 2!} = 12\n\\end{equation*}\n\n\\begin{align*}\n    & [D, R, L, L] \\quad [R, D, L, L] \\quad [D, L, R, L] \\quad \n    [R, L, D, L] \\quad [D, L, L, R] \\quad [R, L, L, D] \\\\\n    & [L, D, R, L] \\quad [L, R, D, L] \\quad [L, D, L, R] \\quad \n    [L, R, L, D] \\quad [L, L, D, R] \\quad [L, L, R, D]\n\\end{align*}\n\n\\begin{equation*}\n    E_R(p_1, p_2, p_3) = \\frac{(1+1+2-1)!}{1! \\; (1-1)! \\; 2!} = 3\n\\end{equation*}\n\n\\begin{align*}\n    & [D, L, L, | R] \\quad [L, D, L, | R] \\quad [L, L, D, | R]\n\\end{align*}\n\n\n\\begin{equation*}\n    E_D(p_1, p_2, p_3) = \\sum_{i=1}^{1} (-1)^{i+1} \\frac{(1+1+2-i-1)!}{0! \\; \n    (1-i)! \\; (2-i)! \\; (i)!} = 1 \\times \\frac{2}{0! \\; 0! \\; 1! \\; 1!} = 2\n\\end{equation*}\n\n\\begin{align*}\n    & [R, L, L, | D] \\quad [L, R, L, | D] \n\\end{align*}\n\n\n\\begin{equation*}\n    E_L(p_1, p_2, p_3) = \\sum_{i=1}^{1} (-1)^{i+1} \n    \\frac{(1+1+2-i-1)!}{1! \\; (1-i)! \\; (2-i-1)! \\; (i)!} \n    = 1 \\times \\frac{2}{1! \\; 0! \\; 0! \\; 1!} = 2\n\\end{equation*}\n\n\\begin{align*}\n    & [D, R, L, | L] \\quad [R, L, D, | L] \n\\end{align*}\n\n\n\\begin{equation*}\n    E_{RL}(p_1, p_2, p_3) = \\sum_{i=1}^{1} (-1)^{i+1} \n    \\frac{(1+1+2-i-1)!}{1! \\; (1-i)! \\; (2-i)! \\; (i_1)!} \n    = 1 \\times \\frac{2}{1! \\; 0! \\; 1! \\; 0!} = 2\n\\end{equation*}\n\n\\begin{align*}\n    & [D, L, | R, L] \\quad [L, D, | R, L] \n\\end{align*}\n\n\n\n\\subsubsection{Possibly useful theorem: Matrix-tree theorem for directed graphs \n(Kirchhoff's theorem) \\cite{chaiken1978matrix}: }\n\\textit{The number of directed spanning trees rooted at a state \\(i\\) can be found \nby calculating the determinant of the Laplacian matrix \\(Q\\) of the directed graph \nand removing row \\(i\\) and column \\(i\\).}\n", "meta": {"hexsha": "272a114e39123d5654fd1fbd0c0401c6c8b1b0b9", "size": 33063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/main/MarkovChain/closed_form_state_probs/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/closed_form_state_probs/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/closed_form_state_probs/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": 37.3171557562, "max_line_length": 91, "alphanum_fraction": 0.6259565073, "num_tokens": 11984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.690775098698523}}
{"text": "\n\n \nRegression reports are generated using software you have already encountered: \\code{lm} to fit a model and \\code{summary} to construct the report from\nthe fitted model.  To illustrate: \\datasetSwimming\n\\begin{Schunk}\n\\begin{Sinput}\n> swim = fetchData(\"swim100m.csv\")\n> mod = lm(time ~ year + sex, data=swim)\n> summary(mod)\n\\end{Sinput}\n\\begin{Soutput}\n...\n            Estimate Std. Error t value Pr(>|t|)    \n(Intercept) 555.7168    33.7999   16.44  < 2e-16 ***\nyear         -0.2515     0.0173  -14.52  < 2e-16 ***\nsexM         -9.7980     1.0129   -9.67  8.8e-14 ***\n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n\nResidual standard error: 3.98 on 59 degrees of freedom\nMultiple R-squared: 0.844,\tAdjusted R-squared: 0.839 \nF-statistic:  160 on 2 and 59 DF,  p-value: <2e-16 \n\\end{Soutput}\n\\end{Schunk}\n\n\n\\subsection{Confidence Intervals from Standard Errors}\n\n\\index{P}{Confidence Intervals}\n\nGiven the coefficient estimate and the standard error\nfrom the regression report, the confidence interval is easily generated.  \nFor a 95\\% confidence interval, you just multiply the standard error by 2 \nto get the margin of error.  For example, in the above, the\nmargin of error on \\indicatorVar{sex}{M} is $2 \\times 1.013 = 2.03$, or, in \ncomputer notation:\n\\begin{Schunk}\n\\begin{Sinput}\n> 2 * 1.0129\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2.03\n\\end{Soutput}\n\\end{Schunk}\n\nIf you want the two endpoints of the confidence interval, rather than \njust the margin of error, do these\nsimple calculations: (1) subtract the margin of error from the estimate; \n(2) add the margin of error to the estimate.  So, \n\\begin{Schunk}\n\\begin{Sinput}\n> -9.798 - 2*1.0129\n\\end{Sinput}\n\\begin{Soutput}\n[1] -11.8\n\\end{Soutput}\n\\begin{Sinput}\n> -9.798 + 2*1.0129\n\\end{Sinput}\n\\begin{Soutput}\n[1] -7.77\n\\end{Soutput}\n\\end{Schunk}\nThe key thing is to remember the multiplier that is applied \nto the standard error.  A multiplier of approximately 2 is for\na 95\\% confidence level.  \n\nThe \\function{confint} function provides a convenient way to calculate\nconfidence intervals directly.\n\\index{C}{confidence interval!computation}\n\\index{P}{confint@\\texttt{confint}}\n\\index{P}{Confidence Intervals!confint@\\texttt{confint}}\nIt calculates the exact multiplier (which depends somewhat on the\nsample size)  and applies it to the standard error to produce the confidence intervals.\n\\begin{Schunk}\n\\begin{Sinput}\n> mod = lm(time ~ year + sex, data=swim)\n> confint(mod)\n\\end{Sinput}\n\\begin{Soutput}\n              2.5 %  97.5 %\n(Intercept) 488.083 623.350\nyear         -0.286  -0.217\nsexM        -11.825  -7.771\n\\end{Soutput}\n\\end{Schunk}\n\nIt would be convenient if the regression report included confidence\nintervals rather than the standard error.  Part of the reason it\ndoesn't is historical: the desire to connect to the traditional by-hand calculations.\n\n\n\n\\subsection{Bootstrapping Confidence Intervals}\n\nConfidence intervals on model coefficients can be computed using the\nsame bootstrapping technique introduced in Chapter \\ref{chap:statistical-inference}.\n\nStart with your fitted model. To illustrate, here is a model of\nswimming time over the years, taking into account sex:\n\\begin{Schunk}\n\\begin{Sinput}\n> swim = fetchData(\"swim100m.csv\")\n> lm(time ~ year + sex, data=swim)\n\\end{Sinput}\n\\begin{Soutput}\n...\n(Intercept)         year         sexM  \n    555.717       -0.251       -9.798  \n\\end{Soutput}\n\\end{Schunk}\nThese coefficients reflect one hypothetical draw from the\npopulation-based sampling\ndistribution.  It's impossible to get another draw from the\n``population'' here: the actual records are all you've got.\n\nBut to approximate sampling variation, you can treat the sample as\nyour population and re-sample:\n\\begin{Schunk}\n\\begin{Sinput}\n> lm(time ~ year + sex, data=resample(swim))\n\\end{Sinput}\n\\begin{Soutput}\n...\n(Intercept)         year         sexM  \n    495.600       -0.221       -8.717  \n\\end{Soutput}\n\\end{Schunk}\n\nConstructing many such re-sampling trials and collect the results \n\\begin{Schunk}\n\\begin{Sinput}\n> s = do(500) * lm(time ~ year + sex, data=resample(swim))\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Sinput}\n> s\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Soutput}\n  Intercept   year   sexM sigma r-squared\n1       531 -0.239  -9.60  3.71     0.853\n2       514 -0.230 -10.25  3.28     0.893\n3       525 -0.236  -9.70  3.67     0.827\n4       562 -0.255  -9.41  3.97     0.846\n5       568 -0.257 -10.76  4.65     0.819\n... for 500 cases altogether ...\n\\end{Soutput}\n\\end{Schunk}\n\nTo find the standard error of the coefficients, just take the standard\ndeviation across the re-sampling trials:\n\\begin{Schunk}\n\\begin{Sinput}\n> sd(s)\n\\end{Sinput}\n\\begin{Soutput}\nIntercept      year      sexM     sigma r-squared \n  43.5426    0.0220    0.9530    0.8057    0.0343 \n\\end{Soutput}\n\\end{Schunk}\n\nMultiplying the standard error by 2 gives the approximate 95\\% margin\nof error.  Alternatively, you can use the \\function{confint} function\nto calculate this for you:\n\\begin{Schunk}\n\\begin{Sinput}\n> confint(s, method=\"stderr\")\n\\end{Sinput}\n\\begin{Soutput}\n       name    2.5%   97.5%\n1 Intercept 472.355 643.454\n2      year  -0.296  -0.209\n3      sexM -11.621  -7.876\n4     sigma   2.215   5.381\n5 r-squared   0.788   0.923\n\\end{Soutput}\n\\end{Schunk}\n\n\n\n\\subsection{Prediction Confidence Intervals}\n\n\\index{C}{confidence interval!for prediction}\n\\index{C}{prediction!confidence interval}\n\nWhen a model is used to make a prediction, it's helpful to be able to\ndescribe how precise the prediction is.  For instance, suppose you \\datasetFeet\nwant to use the \\texttt{kidsfeet.csv} data set to make a prediction of\nthe foot width of a girl whose foot length is 25 cm. \n\n\\index{P}{predict@\\texttt{predict}}\n\\index{P}{Modeling!predict@\\texttt{predict}}\n\nFirst, fit your model:\n\\begin{Schunk}\n\\begin{Sinput}\n> feet = fetchData(\"kidsfeet.csv\")\n> names(kids)\n\\end{Sinput}\n\\begin{Soutput}\n [1] \"Gender\"      \"Grade\"       \"Age\"         \"Race\"       \n [5] \"Urban.Rural\" \"School\"      \"Goals\"       \"Grades\"     \n [9] \"Sports\"      \"Looks\"       \"Money\"      \n\\end{Soutput}\n\\begin{Sinput}\n> levels(kids$sex)\n\\end{Sinput}\n\\begin{Soutput}\nNULL\n\\end{Soutput}\n\\begin{Sinput}\n> mod = lm(width ~ length + sex, data=feet)\n\\end{Sinput}\n\\end{Schunk}\n\nNow apply the model to the new data for which you want to make a\nprediction.  Take care to use the right coding for categorical variables.\n\\begin{Schunk}\n\\begin{Sinput}\n> predict(mod, newdata=data.frame( length=25, sex=\"G\" ))\n\\end{Sinput}\n\\begin{Soutput}\n   1 \n8.93 \n\\end{Soutput}\n\\end{Schunk}\n\nIn order to generate a confidence interval, the \\code{predict}\noperator needs to be told what type of interval is wanted.  There are\ntwo types of prediction confidence intervals:\n\\begin{description}\n\\item[Interval on the model value] which reflects the sampling\n  distributions of the coefficients themselves.  To calculate this,\n  use the \\code{interval=\"confidence\"} named argument:\n\\begin{Schunk}\n\\begin{Sinput}\n> predict(mod, newdata=data.frame( length=25, sex=\"G\" ), \n         interval=\"confidence\")\n\\end{Sinput}\n\\begin{Soutput}\n   fit  lwr  upr\n1 8.93 8.74 9.13\n\\end{Soutput}\n\\end{Schunk}\n\nThe components named \\code{lwr} and \\code{upr} are the lower and upper\nlimits of the confidence interval, respectively.\n\\index{P}{interval@\\texttt{interval=}!in \\texttt{predict}}\n\\index{P}{Confidence Intervals!interval@\\texttt{interval=}!in \\texttt{predict}}\n\n\\item[Interval on the prediction] which includes the variation due to\n  the uncertainty in the coefficients as well as the size of a typical\n  residual.  To find this interval, use the\n  \\code{interval=\"prediction\"} named argument:\n\\begin{Schunk}\n\\begin{Sinput}\n> predict(mod, newdata=data.frame( length=25, sex=\"G\" ), \n         interval=\"confidence\")\n\\end{Sinput}\n\\begin{Soutput}\n   fit  lwr  upr\n1 8.93 8.74 9.13\n\\end{Soutput}\n\\end{Schunk}\n\nThe prediction interval is larger than the model-value confidence\ninterval because the residual always gives additional uncertainty\naround the model value.\n\\end{description} \n\n\n", "meta": {"hexsha": "5dcc01d51d5a0dedf8c60bb47eab51205f068dcd", "size": 8022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ComputationalTechnique-Orig/ConfidenceInModels/computer-confidence.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/ConfidenceInModels/computer-confidence.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/ConfidenceInModels/computer-confidence.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": 29.0652173913, "max_line_length": 150, "alphanum_fraction": 0.7039391673, "num_tokens": 2520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289387914176259, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6907750846121793}}
{"text": "\\subsection{Precision}\n\\label{chp:fundamentals:sec:metrics:subsec:precision}\n\nThe first metric used is \\textit{precision}.\nIt is defined \\textit{\"as the probability that an item is relevant given that it is detected by the algorithm\"} \\parencite{Zhu:2004}.\nThis means if an algorithm is optimized for precision, the aim is that all selected items are relevant.\nHowever, this measure only considers the items selected by the algorithm meaning it neglects the relevant items which were not selected.\nPrecision is defined as:\n\n\\begin{equation}\\label{eq:precision}\n    prec = \\frac{\\acp{TP}}{\\acp{TP}+\\acp{FP}}\n\\end{equation}\n\nAs an example the algorithm which was used to classify the elements in \\cref{fig:metrics:tp_vis} has a precision $prec = \\frac{3}{3+4} = \\frac{3}{7}\\approx 0.43$.\n", "meta": {"hexsha": "94c4513b19fe0f215e230e88ed682f9de99bd2c0", "size": 786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/precision.tex", "max_stars_repo_name": "HaaLeo/vague-requirements-thesis", "max_stars_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/precision.tex", "max_issues_repo_name": "HaaLeo/vague-requirements-thesis", "max_issues_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/precision.tex", "max_forks_repo_name": "HaaLeo/vague-requirements-thesis", "max_forks_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.4, "max_line_length": 162, "alphanum_fraction": 0.7646310433, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802417938533, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6907086803694114}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\n\\title{Vibing Math (Floor Function Problem)}\n\\author{Shreenabh Agrawal}\n\\date{\\today}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\geometry{a4paper, portrait, margin=1in}\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage[makeroom]{cancel}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\n\n    Find $x$ if\n$$x{\\lfloor x {\\lfloor x {\\lfloor x \\rfloor}\\rfloor}\\rfloor}=88$$\nHere $x>0$, $\\lfloor x \\rfloor$ is the floor function.\n\n\\section{Solution}\nApproximating given expression as $x^4\\approx88$, we have $$x\\approx3.0628$$Also, the given expression can be rewritten as: $${\\lfloor x {\\lfloor x {\\lfloor x \\rfloor}\\rfloor}\\rfloor}=\\frac{88}{x}$$\nThis implies that $\\frac{88}{x}$ is an integer. By substituting our approximate value of $x$, we get $$\\frac{88}{x} \\approx 28.7318$$\nThis further means that $$x = \\frac{88}{28} \\: \\left(=\\frac{22}{7}\\right) \\:or\\: \\frac{88}{29}$$\nSubstituting back and checking, we find that, \n$$\\frac{22}{7} {\\left\\lfloor \\frac{22}{7} {\\left\\lfloor \\frac{22}{7} {\\left\\lfloor \\frac{22}{7} \\right\\rfloor}\\right\\rfloor}\\right\\rfloor} = 88$$\nTherefore\n$$\\boxed{x = \\frac{22}{7}}$$\n\\end{document}\n\n", "meta": {"hexsha": "2bbb09833c3fba2214fb624c6562995371e1eb07", "size": 1225, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Misc/vibing_math's questions/Floor Function.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": "Misc/vibing_math's questions/Floor Function.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": "Misc/vibing_math's questions/Floor Function.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": 33.1081081081, "max_line_length": 198, "alphanum_fraction": 0.7012244898, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.6907041098368094}}
{"text": "\\chapter{Bijections, Surjections, and Injections}\n\\label{chapter:bijections-surjections-injections}\n\\marginurl{%\n  Bijections, Surjections, and Injections:\\\\\\noindent\n  Introduction to Combinatorics \\#1\n}{youtu.be/fW5Zxg0TMDc}\n\nCombinatorics is an area of mathematics primarily concerned with counting;\nhence, the questions studied in combinatorics are usually formulated as results\nabout the sizes of sets. This chapter uses informal notion of size of a set, for\nthe formal definition see \\Cref{chapter:cardinality}.\n\\section{Bijections}\nThe simplest way to explain that one set has the same number of elements as\nanother is to show a correspondence between elements of these sets. For example,\nin order to explain that the set $\\set{0, \\pi, 1 / 4}$ has the same number of\nelements as $\\set{1, 2, 3}$ we may just say that $0$ corresponds to $1$,\n$\\pi$ corresponds to $2$, and $1 / 4$ corresponds to $3$. More formally such a\ncorrespondence is defined using the following definition.\n\\begin{definition}\n    Let $f : X \\to Y$ be a function. We say that $f$ is a bijection iff the\n    following properties are satisfied.\n    \\begin{itemize}\n        \\item Every element of $Y$ is an image of some element of $X$. In other\n            words,\n            \\[\n                \\forall y \\in Y~\\exists x \\in X\\ f(x) = y.\n            \\]\n        \\item Images of any two elements\n            of $X$ are different. In other words,\n            \\[\n                \\forall x_1, x_2 \\in X\\ f(x_1) \\neq f(x_2).\n            \\]\n    \\end{itemize}\n\\end{definition}\n\nLet us consider the following example. Let $f : \\mathbb{R} \\to \\mathbb{R}$ be a\nfunction such that $f(x) = x + 1$; Note that it is a bijection:\n\\begin{itemize}\n    \\item For any $y \\in \\mathbb{R}$, $f(y - 1) = (y - 1) + 1 = y$.\n    \\item If $f(x_1) = f(x_2)$, then $x_1 + 1 = x_2 + 1$ i.e. $x_1 = x_2$.\n\\end{itemize}\n\n\\begin{exercise}\n    Show that $x^3$ is a bijection.\n\\end{exercise}\n\nOne of the nicest properties of bijections is that composition of two bijections\nis a bijection.\n\\begin{theorem}\n\\label{theorem:bijections-composition}\n    Let $X$, $Y$, and $Z$ be some sets and $f : X \\to Y$ and $g : Y \\to Z$ be\n    bijections. Then $(g \\circ f) : X \\to Z$ is also a bijection.\n\\end{theorem}\n\\begin{proof}\n    We need to check two properties.\n    \\begin{itemize}\n        \\item Let $x_1 \\neq x_2 \\in X$. Note that $f(x_1) \\neq f(x_2)$ since $f$\n            is a bijection. Hence, $g(f(x_1)) \\neq g(f(x_2))$ since $g$ is a bijection\n            as well. As a result, $(g \\circ f)(x_1) \\neq (g \\circ f)(x_2)$.\n        \\item Let $z \\in Z$; we need to find $x \\in X$ such that\n            $(g \\circ f)(x) = z$. Note that since $g$ is a bijection there is\n            $y \\in Y$ such that $g(y) = z$. Additionally, there is $x \\in X$ such\n            that $f(x) = y$ since $f$ is a bijection. Thus,\n            $(g \\circ f)(x) = g(f(x)) = z$.\n    \\end{itemize}\n\\end{proof}\n\nAnother important property of bijections is that they can be inverted.\n\\begin{theorem}\n\\label{theorem:inverse-of-bijections}\n    Let $f : X \\to Y$ be a function. $f$ is invertible (i.e. there is a function\n    $g : Y \\to X$ such that $(f \\circ g)(y) = y$ and $(g \\circ f)(x) = x$ for all\n    $x \\in X$ and $y \\in Y$) iff $f$ is a bijection.\n\\end{theorem}\n\\begin{proof}\n    \\begin{description}\n        \\item[$\\Rightarrow$] Let's assume that $f$ is invertible. We need to prove\n            that $f$ is a bijection.\n            \\begin{itemize}\n                \\item Let's assume that $f$ does not satisfy the first property in the\n                    definitions of bijections i.e. there are\n                    $x_1, x_2 \\in X$ such that $f(x_1) = f(x_2)$ but\n                    $x_1 = g(f(x_1)) = g(f(x_2)) = x_2$, which is a\n                    contradiction.\n                \\item Let $y \\in Y$. Note that $f(g(y)) = y$, hence,\n                    $\\Im f = Y$.\n            \\end{itemize}\n\n        \\item[$\\Leftarrow$] Let's assume that $f$ is bijective. We need to define a\n            function $g : Y \\to X$ which is an inverse of $f$. Let $y \\in Y$, note\n            that there is a unique $x$ such that $f(x) = y$, we define $g(y) = x$.\n            Note that $f(g(y)) = y$ for every $y$ by the construction of $g$.\n            Additionally, $g(f(x)) = x$ since $f(g(f(x))) = f(x)$ and $f$ is a\n            bijection.\n    \\end{description}\n\\end{proof}\n\\noindent We denote $g$ from this theorem as $f^{-1}$ and in case when $f$ is\nnot a bijection $f^{-1}(y)$ denotes the set $\\set[f(x) = y]{x \\in X}$.\n\\nomenclature[F]{$f^{-1}$}{denotes the inverse of the function $f$ (it's\ndefined only when $f$ is a bijection)}\n\\nomenclature[F]{$f^{-1}(y)$}{depend on the context if $f$ is not a bijection\nit denotes the set $\\set[f(x) = y]{x \\in X}$ and it denotes the value of\n$f^{-1}$ at $y$ if $f$ is a bijection}\n\nBecause of the following theorem, bijections are very useful in combinatorics.\n\\begin{theorem}\n\\label{theorem:bijection-to-equality}\n    Let $X$ and $Y$ be two finite sets such that there is a bijection $f$ from\n    $X$ to $Y$. Then $\\cardinality{X} = \\cardinality{Y}$.\n\\end{theorem}\n\nUsing this result we can make prove the following equality.\n\\begin{corollary}\n\\label{corollary:power-set-and-set-of-binary-strings}\n    Let $X$ be a finite set of cardinality $n$. Then $2^X$ has the same\n    cardinality as $\\set{0, 1}^{\\cardinality{X}}$.\n\\end{corollary}\n\\begin{proof}\n  We are going to prove this statement for $X = \\range{n}$ since for the full\n  proof we would need a formal definition a finite set.\n\n  Now we need to construct a bijection $g$ from $2^{\\range{n}}$ to\n  $\\set{0, 1}^n$ such that $g(Y) = (u_1, \\dots, u_n)$, where $u_i = 1$ iff $i \\in Y$.\n  It is clear that $g^{-1}(u_1, \\dots, u_n) = \\set[u_i = 1]{i \\in \\range{n}}$ is an\n  inverse of $g$ so $g$ is indeed a bijection.\n\\end{proof}\n\n\\section{Surjections and Injections}\n\nIt is possible to note that the definition of the bijection consists of two part.\nBoth of these parts are interesting in their own regard, so they have their own\nnames.\n\\begin{definition}\n  Let $f : X \\to Y$ be a function.\n  \\begin{itemize}\n    \\item We say that $f$ is a surjection iff every element of $Y$ is an image\n      of some element of $X$. In other words,\n      \\[\n        \\forall y \\in Y~\\exists x \\in X\\ f(x) = y.\n      \\]\n      \\item We say that $f$ is an injection iff images of any two elements\n        of $X$ are different. In other words,\n        \\[\n          \\forall x_1, x_2 \\in X\\ f(x_1) \\neq f(x_2).\n        \\]\n  \\end{itemize}\n\\end{definition}\n\n\\begin{remark}\n  Let $f : X \\to Y$ be an injection. Then $g : X \\to \\Im f$ such that\n  $f(x) = g(x)$ is a bijection.\n\\end{remark}\n\n\\begin{exercise}\n  Let $\\R^+ = \\set[x > 0]{x \\in \\R}$. Is $f : \\R^+ \\to \\R^+$ such that\n  $f(x) = x + 1$ a surjection/injection?\n\\end{exercise}\n\nLike in the case of the bijection we may use surjections and injections to\ncompare sizes of sets.\n\\begin{theorem}\n\\label{theorem:injections-surjections-inequalities}\n  Let $X$ and $Y$ be finite sets.\n  \\begin{itemize}\n    \\item If there is an injection from $X$ to $Y$, then $\\cardinality{X}\n      \\le \\cardinality{Y}$.\n    \\item If there is a surjection from $X$ to $Y$, then $\\cardinality{X}\n      \\ge \\cardinality{Y}$.\n  \\end{itemize}\n\\end{theorem}\n\n\\begin{chapterendexercises}\n  \\exercise Let $p$ be a polynomial of even degree. Is it possible that $p$ is a\n    bijection from $\\R$ to $\\R$?\n  \\exercise[recommended] Construct a bijection from\n    \\[\n      \\set[{A, B \\subseteq \\range{n} \\text{ and } A, B \\text{ are disjoint}}]{(A, B)}.\n    \\]\n    to $\\set{0, 1, 2}^n$.\n    \\begin{solution}\n      Let us start from an informal proof. For each $i \\in \\range{n}$ there are\n      three ways to put or not put it into sets $A$ and $B$ such that $A \\cap B\n      = \\emptyset$:\n      \\begin{enumerate}\n        \\item we may not put $i$ to both of them,\n        \\item we may put $i$ only to $A$,\n        \\item we may put $i$ only to $B$.\n      \\end{enumerate}\n      Which defines a bijection from \n      $\\set[{A, B \\subseteq [n] \\text{ and } A \\cap B = \\emptyset}]{(A, B)}$ to\n      $\\set{0, 1, 2}^n$.\n\n      Now we are ready give a more formal construction of the bijection from\n      $\\set[{A, B \\subseteq [n] \\text{ and } A \\cap B = \\emptyset}]{(A, B)}$ to\n      $\\set{0, 1, 2}^n$.\n\n      Consider \n      $f : \\set[{A, B \\subseteq [n] \\text{ and } A \\cap B = \\emptyset}]{(A, B)} \\to\n        \\set{0, 1, 2}^n$ such that\n      $f(A, B) = (x_1, \\dots, x_n)$, where\n      \\[\n        x_i =\n        \\begin{cases}\n          0 & \\text{if } i \\in A \\text{ and } i \\not\\in B \\\\\n          1 & \\text{if } i \\not\\in A \\text{ and } i \\in B \\\\\n          2 & \\text{if } i \\not\\in A \\text{ and } i \\not\\in B\n        \\end{cases}.\n      \\]\n      Note that the function is well defined due to the fact that $A \\cap B =\n      \\emptyset$.\n      We need to prove now that it is a bijection. To do this we can simply\n      construct the inverse function $e$; $e : \\set{0, 1, 2}^n \\to \n      \\set[{A, B \\subseteq [n] \\text{ and } A \\cap B = \\emptyset}]{(A, B)}$ such\n      that $e(x_1, \\dots, x_n) = (A, B)$, where\n      $A = \\set[x_i = 1]{i \\in \\range{n}}$ and \n      $B = \\set[x_i = 2]{i \\in \\range{n}}$.\n      Obviously $e$ is the inverse of $f$, hence, $f$ is a bijection.\n    \\end{solution}\n  \\exercise[recommended] Construct a bijection from  $\\range{2n}$ to \n    $\\set{0, 1} \\times \\range{n}$.\n    \\begin{solution}\n      Consider the function\n      \\[\n        f(i) =\n        \\begin{cases}\n          (0, i) & i \\le n \\\\\n          (1, i - n) & n < i \\le 2n\n        \\end{cases}.\n      \\]\n      Note that the function is defined correctly since the first coordinate is\n      always $0$ or $1$ and the second coordinate is always from $\\range{n}$ due to the\n      fact that if $i \\le n$, then $i \\in \\range{n}$ and if $i > n$, then \n      $(i - n) \\in \\range{n}$.\n      We are going to prove now that it is a bijection.\n      \\begin{description}\n        \\item[injection:]\n          Assume the opposite i.e. that there are $i_0 \\neq i_1$ such that\n          $f(i_0) = f(i_1)$. Without loss of generality we may assume that $i_0\n          < i_1$.\n          Consider three cases:\n          \\begin{enumerate}\n            \\item ($i_0, i_1 \\le n$) Note that $(0, i_0) = f(i_0)$ and\n              $f(i_1) = (0, i_1)$. So $i_0 = i_1$ since $f(i_0) = f(i_1)$, which\n              is a contradiction.\n            \\item ($i_0, i_1 > n$) Note that $(1, i_0 - n) = f(i_0)$ and\n              $f(i_1) = (1, i_1 - n)$. So $i_0 = i_1$ since $f(i_0) = f(i_1)$, which\n              is a contradiction.\n            \\item ($i_0 \\le n < i_1$) Note that $(0, i_0) = f(i_0)$ and\n              $f(i_1) = (1, i_1 - n)$. So $0 = 1$ since $f(i_0) = f(i_1)$, which\n              is a contradiction.\n          \\end{enumerate}\n        \\item[surjection:]\n          Let us fix some $(a, b) \\in \\set{0, 1} \\times \\range{n}$. We need to show that\n          it belongs to $\\Im f$.\n          \\begin{enumerate}\n            \\item ($a = 0$) Note that $b \\le n$, hence, $f(b) = (0, b) = \n              (a, b)$. So $(a, b) \\in \\Im f$.\n            \\item ($a = 1$) Note that $2n \\ge n + b > n$, hence,\n              $f(n + b) = (1, (n + b) - b) = (1, b) = (a, b)$.\n              So $(a, b) \\in \\Im f$.\n          \\end{enumerate}\n      \\end{description}\n    \\end{solution}\n  \\exercise We say that $u, v \\in \\set{0, 1}^n$ are orthogonal over $\\F_2$ iff\n    $\\sum_{i = 1}^n u_i v_i$ is even. Let $v \\in \\set{0, 1}^n$ be a tuple such\n    that $v_i \\neq 0$ for some $i \\in \\range{n}$. Show that if we choose a\n    tuple $u \\in \\set{0, 1}^n$ uniformly at random, then $u$ and $v$ are\n    orthogonal over $\\F_2$ with probability $1 / 2$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "15480b6205c1d4751c65d496f7406bf4ff0e98bc", "size": 11691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_17_bijections.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_4/chapter_17_bijections.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_4/chapter_17_bijections.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 43.3, "max_line_length": 88, "alphanum_fraction": 0.5783936361, "num_tokens": 3976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6907041092048399}}
{"text": "\\section{Spans}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine the span of a set of vectors.\n  \\item Determine if a vector is contained in a specified span.\n  \\end{enumerate}\n\\end{outcome}\n\nLet $\\vect{u}$ and $\\vect{v}$ be two non-parallel vectors in\n$\\R^n$. We can picture the set of their linear combinations as follows:\n\\begin{center}\n  \\begin{tikzpicture}[scale=1.5]\n    \\draw[->, thick, blue] (0,0) -- node[below]{$\\vect{u}$} (1.5,0.5);\n    \\draw[->, thick, red] (0,0) -- node[left]{$\\vect{v}$} (0.5,1);\n    \\draw[-, gray] (-2,-1.5)--(4,0.5);\n    \\draw[-, gray] (-1.5,-0.5)--(0,0);\n    \\draw[-, gray] (1.5,0.5)--(4.5,1.5);\n    \\draw[-, gray] (-1,0.5)--(5,2.5);\n    \\draw[-, gray] (-0.5,1.5)--(5.5,3.5);\n    \\draw[-, gray] (0,2.5)--(6,4.5);\n    \\draw[-, gray] (-2,-1.5)--(0,2.5);\n    \\draw[-, gray] (-0.5,-1)--(0,0);\n    \\draw[-, gray] (0.5,1)--(1.5,3);\n    \\draw[-, gray] (1,-0.5)--(3,3.5);\n    \\draw[-, gray] (2.5,0)--(4.5,4);\n    \\draw[-, gray] (4,0.5)--(6,4.5);\n    \\draw (-2.0,-1.5) node[left]{$-1\\vect{u}-1\\vect{v}$};\n    \\draw (-1.5,-0.5) node[left]{$-1\\vect{u}+0\\vect{v}$};\n    \\draw (-1.0,0.5) node[left]{$-1\\vect{u}+1\\vect{v}$};\n    \\draw (-0.5,1.5) node[left]{$-1\\vect{u}+2\\vect{v}$};\n    \\draw (0.0,2.5) node[left]{$-1\\vect{u}+3\\vect{v}$};\n    \\draw (1.5,3.0) node[above=0.75ex]{$0\\vect{u}+3\\vect{v}$};\n    \\draw (3.0,3.5) node[above=0.75ex]{$1\\vect{u}+3\\vect{v}$};\n    \\draw (4.5,4.0) node[above=0.75ex]{$1\\vect{u}+3\\vect{v}$};\n    \\draw (6.0,4.5) node[right]{$3\\vect{u}+3\\vect{v}$};\n    \\draw (5.5,3.5) node[right]{$3\\vect{u}+2\\vect{v}$};\n    \\draw (5.0,2.5) node[right]{$3\\vect{u}+1\\vect{v}$};\n    \\draw (4.5,1.5) node[right]{$3\\vect{u}+0\\vect{v}$};\n    \\draw (4.0,0.5) node[right]{$3\\vect{u}-1\\vect{v}$};\n    \\draw (2.5,0.0) node[below=0.75ex]{$2\\vect{u}-1\\vect{v}$};\n    \\draw (1.0,-0.5) node[below=0.75ex]{$1\\vect{u}-1\\vect{v}$};\n    \\draw (-0.5,-1.0) node[below=0.75ex]{$0\\vect{u}-1\\vect{v}$};\n    \\draw[fill] (0,0) circle [radius=1.2pt] node[below right]{$\\vect{0}$};\n  \\end{tikzpicture}\n\\end{center}\nAs the picture shows, the linear combinations of $\\vect{u}$ and\n$\\vect{v}$ form a $2$-dimensional plane through the origin. We say\nthat this plane is \\textbf{spanned}%\n\\index{span}%\n\\index{vector!span} by the vectors $\\vect{u}$ and $\\vect{v}$.  This\nconcept generalizes to more than two vectors. For example, three\nvectors may span a $3$-dimensional space (although sometimes, they\nspan only a $2$-dimensional space, or even a line). This motivates the\nfollowing definition.\n\n\\begin{definition}{Span of a set of vectors}{span}\n  The set of all linear combinations of the vectors\n  $\\vect{u}_1, \\ldots,\\vect{u}_k$ in $\\R^n$ is known as the\n  \\textbf{span}%\n  \\index{span}%\n  \\index{vector!span} of these vectors and is written as\n  $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$. Using set notation, we\n  can write\n  \\begin{equation*}\n    \\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}\n    ~=~ \\set{a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k \\mid a_1,\\ldots,a_k\\in\\R}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{Vectors in a span}{vector-in-span}\n  Let $\\vect{u}=\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}$ and\n  $\\vect{v}=\\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix}$. Which\n  of the following vectors are elements of\n  $\\sspan\\set{\\vect{u},\\vect{v}}$?\n  \\begin{equation*}\n    (a)\\quad\\vect{w} = \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 4 \\end{mymatrix},\n    \\qquad\n    (b)\\quad\\vect{z} = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  (a) For a vector to be in $\\sspan\\set{\\vect{u},\\vect{v}}$, it must\n  be a linear combination of $\\vect{u}$ and $\\vect{v}$. Therefore,\n  $\\vect{w}\\in\\sspan\\set{\\vect{u},\\vect{v}}$ if and only if we can\n  find find scalars $a,b$ such that\n  $a\\,\\vect{u} + b\\,\\vect{v} = \\vect{w}$. We must therefore solve the\n  equation\n  \\begin{equation*}\n    a \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    + b \\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  We write this as an augmented matrix and solve.\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & 3 & 2 \\\\\n      1 & 2 & 3 \\\\\n      1 & 1 & 4 \\\\\n    \\end{mymatrix}\n    \\roweq\\ldots\\roweq\n    \\begin{mymatrix}{rr|r}\n      1 & 0 & 5 \\\\\n      0 & 1 & -1 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The solution is $a=5$ and $b=-1$. This means that\n  $\\vect{w} = 5\\vect{u} + (-1)\\vect{v}$. Therefore, $\\vect{w}$ is an\n  element of $\\sspan\\set{\\vect{u},\\vect{v}}$.\n\n  (b) We repeat the same method with the vector $\\vect{z}$. This time,\n  we have to find $a,b$ such that\n  $a\\,\\vect{u} + b\\,\\vect{v} = \\vect{z}$. The system of equations is\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & 3 & 1 \\\\\n      1 & 2 & 1 \\\\\n      1 & 1 & 2 \\\\\n    \\end{mymatrix}\n    \\roweq\\ldots\\roweq\n    \\begin{mymatrix}{rr|r}\n      1 & 3 & 1 \\\\\n      0 & -1 & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  which is inconsistent. Therefore, there is no solution. We conclude\n  that $\\vect{z}$ is not an element of\n  $\\sspan\\set{\\vect{u},\\vect{v}}$.\n\\end{solution}\n\n\\begin{example}{Describing the span}{describe-span}\n  Describe the span of the vectors\n  $\\vect{u}=\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}$ and\n  $\\vect{v}=\\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix}$ in\n  $\\R^3$.\n\\end{example}\n\n\\begin{solution}\n  Let $\\vect{w} = \\mat{x, y, z}^T$ be any vector. Proceeding as in the\n  previous example, we know that $\\vect{w}$ is an element of\n  $\\sspan\\set{\\vect{u},\\vect{v}}$ if and only if the equation\n  \\begin{equation*}\n    a \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    + b \\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n  \\end{equation*}\n  is consistent. Note that the variables of this equation are $a,b$;\n  we regard $x,y,z$ as constants for the moment. We write the augmented\n  matrix of this system and reduce to {\\ef}:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|c}\n      1 & 3 & x \\\\\n      1 & 2 & y \\\\\n      1 & 1 & z \\\\\n    \\end{mymatrix}\n    \\stackrel{R_2\\leftarrow R_2-R_1}{\\stackrel{R_2\\leftarrow R_3-R_1}{\\roweq}}\n    \\begin{mymatrix}{rr|c}\n      1 & 3 & x \\\\\n      0 & -1 & y-x \\\\\n      0 & -2 & z-x \\\\\n    \\end{mymatrix}\n    \\stackrel{R_3\\leftarrow R_3-2R_2}{\\roweq}\n    \\begin{mymatrix}{rr|c}\n      1 & 3 & x \\\\\n      0 & -1 & y-x \\\\\n      0 & 0 & (z-x)-2(y-x) \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  From the {\\ef}, we see that the system is consistent if and only if\n  $(z-x)-2(y-x)=0$, or equivalently $x - 2y + z = 0$. Therefore, the\n  vector $\\vect{w}$ is in $\\sspan\\set{\\vect{u},\\vect{v}}$ if and only\n  if $x - 2y + z = 0$. In other words, the span of $\\vect{u}$ and\n  $\\vect{v}$ is the plane $x - 2y + z = 0$.\n\\end{solution}\n\n\\begin{example}{Span of redundant vectors}{redundant-span}\n  Let $\\vect{u}=\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}$,\n  $\\vect{v}=\\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix}$, and\n  $\\vect{w}=\\begin{mymatrix}{r} 11 \\\\ 8 \\\\ 5 \\end{mymatrix}$.\n  Show that\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}} =\n  \\sspan\\set{\\vect{u},\\vect{v}}$.\n\\end{example}\n\n\\begin{solution}\n  Observe that $\\vect{w} = 2\\,\\vect{u}+3\\,\\vect{v}$. Therefore,\n  $\\vect{w}$ is already in the span of $\\vect{u}$ and $\\vect{v}$.  Two\n  sets are equal if they have the same elements, i.e., each element of\n  the first set is an element of the second set and vice\n  versa. Therefore, to show\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}} =\n  \\sspan\\set{\\vect{u},\\vect{v}}$, we must show (a) that every element\n  of $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}}$ is an element of\n  $\\sspan\\set{\\vect{u},\\vect{v}}$ and (b) vice versa.\n\n  (a) Let $\\vect{z}$ be an arbitrary element of\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}}$. Then, by definition of\n  span, there exist scalars $a,b,c$ such that\n  \\begin{eqnarray*}\n    \\vect{z} &=& a\\,\\vect{u} + b\\,\\vect{v} + c\\,\\vect{w}.\n  \\end{eqnarray*}\n  But as observed above, we have $\\vect{w} = 2\\,\\vect{u}+3\\,\\vect{v}$,\n  and therefore we can also write\n  \\begin{eqnarray*}\n    \\vect{z}\n    &=& a\\,\\vect{u} + b\\,\\vect{v} + c(2\\,\\vect{u}+3\\,\\vect{v}) \\\\\n    &=& (a+2c)\\vect{u} + (b+3c)\\vect{v}.\n  \\end{eqnarray*}\n  It follows that $\\vect{z}$ is a linear combination of $\\vect{u}$ and\n  $\\vect{v}$, and therefore, $\\vect{z}\\in \\sspan\\set{\\vect{u},\\vect{v}}$.\n\n  (b) Clearly every linear combination of $\\vect{u}$ and $\\vect{v}$ is\n  also a linear combination of $\\vect{u}$, $\\vect{v}$, and $\\vect{w}$,\n  namely, taking the coefficient of $\\vect{w}$ to be $0$. Therefore,\n  every element of $\\sspan\\set{\\vect{u},\\vect{v}}$ is an element of\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}}$.\n\n  Because we have shown that every element of\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}}$ is an element of\n  $\\sspan\\set{\\vect{u},\\vect{v}}$ and vice versa, it follows that\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}}$ and\n  $\\sspan\\set{\\vect{u},\\vect{v}}$ are the same set of vectors.\n\\end{solution}\n\nIn the situation of the last example, we say that the vector\n$\\vect{w}$ is \\textbf{redundant}%\n\\index{redundant vector}%\n\\index{vector!redundant}; it does not contribute anything to\n$\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}}$. Geometrically, the three\nvectors $\\vect{u}$, $\\vect{v}$, and $\\vect{w}$ lie in a plane. Since\nthe two vectors $\\vect{u}$ and $\\vect{v}$ are sufficient to span this\nplane, the third vector $\\vect{w}$ is not really needed. We will study\nthis situation more systematically in the next section.\n\n\\begin{example}{Span of the empty set}{span-empty-set}\n  We talked about the span of $k$ vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$.  What if $k=0$? What is\n  the span of an empty set of vectors?\n\\end{example}\n\n\\begin{solution}\n  Consider what happens when we compute the sum of three numbers. We\n  usually write this as $b_1+b_2+b_3$. We can also compute the sum of\n  three numbers by starting from $0$ and then adding each of the three\n  numbers to it. I.e., the sum can be computed as\n  $0+b_1+b_2+b_3$. Similarly, we can write the sum of two numbers as\n  $0+b_1+b_2$, and the sum of just one number as $0+b_1$. Continuing\n  the pattern, it follows that the sum of zero numbers should be $0$:\n  \\begin{center}\n    \\begin{tabular}{ll}\n      Sum of 3 numbers: & $0+b_1+b_2+b_3$. \\\\\n      Sum of 2 numbers: & $0+b_1+b_2$. \\\\\n      Sum of 1 numbers: & $0+b_1$. \\\\\n      Sum of 0 numbers: & $0$. \\\\\n    \\end{tabular}\n  \\end{center}\n  The sum of zero numbers is also called the \\textbf{empty sum}%\n  \\index{empty sum}. It is equal to the unit of addition, i.e., $0$.\n  By an analogous argument, the empty sum of vectors is equal to the\n  unit of vector addition, i.e., to the zero vector $\\vect{0}$%\n  \\index{zero vector}%\n  \\index{vector!zero vector}.  In general, if we have $k$ vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$, the span consists of all vectors of\n  the form $a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k$, which is a sum of $k$\n  vectors.  In case $k=0$, the span consists only of the empty sum,\n  i.e., the zero vector $\\vect{0}$, which we also call the\n  \\textbf{empty linear combination}%\n  \\index{empty linear combination}%\n  \\index{vector!empty linear combination}%\n  \\index{linear combination!empty}. Therefore, the span of the empty\n  set of vectors is $\\set{\\vect{0}}$.\n\\end{solution}\n", "meta": {"hexsha": "6d2a5f86e9ab9de1e239a7988a680be24b930a7e", "size": 11269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SpanIndependenceBasis-Span.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/SpanIndependenceBasis-Span.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/SpanIndependenceBasis-Span.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.8297101449, "max_line_length": 78, "alphanum_fraction": 0.6041352383, "num_tokens": 4499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6907040993161745}}
{"text": "\n% \t\\begin{exercise}\n% \t\t\\begin{align*}\n% \t\t\t\\sqrt{1 - x^2}\n% \t\t\\end{align*}\n% \t\\end{exercise}\n\n\n\n\\section*{Solutions to Selected Problems}\n\n\\begin{exercise*}\n  Find\n  $\\lim \\limits_{x \\rightarrow 0} f(x)$ where $$f(x) = \\begin{cases}\n            x & \\mbox{ if $x$ is rational}   \\\\\n            0 & \\mbox{ if $x$ is irrational}\n          \\end{cases}$$\n\\end{exercise*}\n\\begin{proof}\n  We'll prove that $\\lim \\limits_{x \\rightarrow 0} f(x) = 0$. For this we need to show that for every $\\epsilon$, there exists a $\\delta$ such that for every $x$, if $0 < |x| < \\delta$ then $|f(x)| < \\epsilon$.\n\n  Let $\\epsilon > 0$, let $\\delta = \\epsilon$ and let $0 < |x| < \\delta$ then either $x$ is a rational number or it is an irrational number.\n\n  If $x$ is a rational number then\n  \\begin{align*}\n    |f(x)| = |x| < \\delta = \\epsilon\n  \\end{align*}\n  If $x$ is an irrational number then\n  \\begin{align*}\n    |f(x)| = 0 < \\epsilon\n  \\end{align*}\n  which shows that $|f(x)|< \\epsilon$ for all $0 < |x| < \\delta$, which is what we wanted to prove.\n\\end{proof}\n\n\\begin{exercise*}\n  Let $\n    f(x) = \\begin{cases}\n      1 & \\mbox{if $x$ is rational,}   \\\\\n      0 & \\mbox{if $x$ is irrational.}\n    \\end{cases}\n  $\n  \\begin{enumerate}\n    \\item Prove that for every real number $L$, $\\lim \\limits_{x \\rightarrow 0} f(x) \\neq L$.\n    \\item Prove that $\\lim \\limits_{x \\rightarrow 0} f(x) \\neq \\infty$. (Similarly for $-\\infty$.)\n  \\end{enumerate}\n  Hence the limit of $f$ at $0$ does not exist.\n\\end{exercise*}\n\\begin{proof}\n  \\begin{enumerate}\n    \\item   For the first part, we need to show that for any real number $L$, there exists an $\\epsilon > 0$ such that for every $\\delta > 0$ there exists an $x$ such that $0 < |x| < \\delta$ and $|f(x) - L | \\ge \\epsilon$. We'll show that this is true for $\\epsilon = 1/2$.\n\n    Let $\\epsilon = 1/2$, let $\\delta > 0$, let $x_1$ be an irrational number satisfying $0 < |x_1| < \\delta$ and let $x_2$ be a rational number satisfying $0 < |x_2 | < \\delta$.\n\n    We have already shown that for any $L$ at least one of $|L|$ or $|1 - L|$ is $\\ge 1/2$. Hence either \\begin{align*}\n      |f(x_1) - L| \\ge 1/2 \\quad \\mbox{ or } \\quad |f(x_2) - L | \\ge 1/2\n    \\end{align*}\n    Thus the inequality $|f(x) - L | \\ge \\epsilon$ is true for either $\\epsilon = x_1$ or $x_2$, which completes the proof.\n\n    \\item For the second part, we need to show that there exists an $\\epsilon > 0$ such that for every $\\delta > 0$ there exists an $x$ such that $0 < |x| < \\delta$ and $|f(x)| \\le \\epsilon$. We'll show that this is true for $\\epsilon = 1$.\n\n    Let $\\epsilon = 1$, let $\\delta > 0$, let $x$ be an irrational number satisfying $0 < |x| < \\delta$.\n\n    Then $|f(x)| = 0 \\le 1 = \\epsilon$ which is what we wanted to prove.\n\n    Similar proof works for $-\\infty$.\\\\\n  \\end{enumerate}\n  Since $\\lim \\limits_{x \\rightarrow 0} f(x)$ does not equal any real number, $\\infty$, or $-\\infty$, the limit of $f$ at 0 does not exist.\n\\end{proof}\n", "meta": {"hexsha": "ef83c22ec7df0e67d8c81f9100be2de9c6ef2f05", "size": 2953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/dump.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/dump.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/dump.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": 42.7971014493, "max_line_length": 273, "alphanum_fraction": 0.6010836438, "num_tokens": 1036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070838, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6907040904887909}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%   heap and priprity queue\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn this chapter, we introduce heap data structures which is essentially an array object but it can be viewed as a nearly complete binary tree. The concept of the data structures in this chapter is between liner and non-linear, that is using linear data structures to mimic the non-linear data structures and its behavior for higher efficiency under certain context. \n%%%%%%%%%%%%%%%%%heap%%%%%%%%%%%%%%%%%\n\\section{Heap}\n\\label{sec_heap}\nHeap is a tree based data structures that satisfies \\textbf{heap property} but implemented as an array data structure. There are two kinds of heaps: \\textbf{max-heaps} and \\textbf{min-heaps}. In both kinds, the values in the nodes satisfy a \\textbf{heap property}. For max-heap, the property states as for each node in the heap at $i$, $A[p[i]] <= A[i]$.  Normally, heap is based on binary tree, which makes it a binary heap. Fig.~\\ref{fig:max-heap-1} show a binary max-heap and how it looks like in a binary tree data structure. In the following content, we default our heap is a binary heap. Thus, the largest element in a max-heap is stored at the root. For a heap of $n$ elements the height is $\\log n)$. % as for every node i other than root. $A[PARENT(i)]>= A[i]$.  The unique usage of Heap, including miniHeap and maxiHeap, Monotic Heap.  The (binary) heap data structure is an array that we can view as a nearly complete binary tree. The tree is completely filled on all levels except possibly the lowest, which is filled from left up to a point. \n% \\subsection{Introduction}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width = 0.98\\columnwidth]{fig/binary_tree.png}\n    \\caption{Max-heap be visualized with binary tree structure on the left, and implemnted with Array on the right.}\n    \\label{fig:max-heap-1}\n\\end{figure}\n\nAs we can see we can implement heap as an array due to the fact that the tree is complete. A complete binary tree is one in which each level must be fully filled before starting to fill the next level. Array-based heap is more space efficient compared with tree based due to the non-existence of the child pointers for each node. To make the math easy, we iterate node in the tree starting from root in the order of level by level and from left to right with beginning index as 1 (shown in Fig.~\\ref{fig:max-heap-1}).  According to such assigning rule, the node in the tree is mapped and saved in the array by the assigned index (shown in Fig.~\\ref{fig:max-heap-1}). In heap, we can traverse the imaginary binary tree in two directions:  \\textbf{root-to-leaf} and  \\textbf{leaf-to-root}. Given a parent node with p as index, the left child of can be found in position $2p$ in the array. Similarly, the right child of the parent is at position $2p + 1$ in the list. To find the parent of any node in the tree,  we can simply use $\\lfloor p/2\\rfloor$.  In Python3, use integer division $n//2$. \\textit{Note: we can start index with 0 as used in \\textbf{heapq} library introduced later in this section. Given a node $x$, the left and right child will be $2*x+1$, $2*x+2$, and the parent node will have index $(x-1)//2$.}\n\nThe common application of heap data structure include:\n\\begin{itemize}\n    \\item Implementing a priority-queue data structure which will be detailed in the next section so that insertion and deletion can be implemented in $O(\\log n)$; Priority Queue is an important component in algorithms like Kruskal's for minimum spanning tree (MST) problem and Dijkstra's for single-source shortest paths (SSSP) problem. \n    \\item Implementing heapsort algorithm,\n\\end{itemize}\n\nNormally, there is usually no notion of 'search' in heap, but only insertion and deletion, which can be done by traversing a $O(\\log n)$ leaf-to-root or root-to-leaf path. \n%%%%%%%%%%%%%%%%%%Basic Implementation%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Basic Implementation}\nThe basic methods of a heap class should include: \\textbf{pop}, \\textbf{push}, and \\textbf{heapify}. \\textbf{push} an item into the heap and \\textbf{pop} the root item at the heap out, and still maintain the heap property.  And \\textbf{heapify} denotes the operation needed for an given array, to convert it to a heap directly and efficiently. \n\nLet's implement a heap class using list. Because the first element of the heap is actually empty, we define our class as follows:\n\\begin{lstlisting}[language=Python]\nclass Heap:\n    def __init__(self):\n        self.heap = [None]\n        self.size = 0\n    def __str__(self):\n        out = ''\n        for i in range(1, self.size + 1):\n            out += str(self.heap[i]) + ' '\n        return out\n\\end{lstlisting}\nAssuming we already have got a heap shown in Fig.~\\ref{fig:max-heap-1}, push or pop an item from the current heap requires us to do post-processing in order to maintain the heap property. Let's discuss the two cases. Change it to use max heap as example.\n\n\\paragraph{Push with Floating} When we push an item into, to maintain the complete binary tree property, the new item goes to the end of the heap(array) first. Assuming the new item a[i] is the smallest item up till now, there will be violation of the heap property through the \\textbf{a[i]->root path}. To correct the potential violation, we traverse the path a[i]->root, and compare each node and its parent  to decide if a swap operation is needed. For a min-heap, if the child node is smaller than the parent, that is a violation, and we swap these two nodes to let a[i] \\textbf{float up} to make sure the subtree of a[i].parent obey the min-heap property.  For example, in the min-heap.  The time complexity is the same as the height of the complete tree, which is $O(\\log n)$.\n\\begin{lstlisting}[language=Python]\n    def _float(self, index): # enforce min-heap, leaf-to-root\n      while index // 2: # while parent exist\n          p_index = index // 2\n          print('p', p_index, index)\n          if self.heap[index] < self.heap[p_index]: # a violation\n              # swap\n              self.heap[index], self.heap[p_index] = self.heap[p_index], self.heap[index]\n          else:\n            break\n          index = p_index # move up the node\n    def insert(self, val):\n        self.heap.append(val)\n        self.size += 1\n        self._float(index = self.size)\n\\end{lstlisting}\n\n\\paragraph{Pop with Sinking} When we pop out the item at root node,  or delete any item a[i], an empty spot appears at that position. To maintain the complete binary tree, we first  simply use the last item to fill in this spot. However, in a min-heap, the last item will mostly not be the smallest item among the subtree rooted at a[i]. The smallest item will appear anywhere in the subtree. We simply do a search starts from node a[i] and compare its value with left and right child. The left and right subtree obey the min-heap property already, therefore the smallest item is among a[i], left, right. If the node is larger than its smaller child node, we swap the parent with the smaller child, and move our pointer to the smaller child node and repeat the above process until the current node is the smallest among these three nodes.   This process is called like sinking down a[i] along the \\textbf{path a[i]->leaf}. Same as the insert in the case of complexity, $O(\\log n)$. \n\\begin{lstlisting}[language=Python]\n    def _sink(self, index): # enforce min-heap, root-to-leaf\n        while 2 * index <= self.size:\n            li = 2 * index\n            ri = li + 1\n            mi = index\n            if self.heap[li] < self.heap[mi]:\n              mi = li\n            if ri <= self.size and self.heap[ri] < self.heap[mi]:\n              mi = ri\n            if mi != index:\n                # swap index with mi\n                self.heap[index], self.heap[mi] = self.heap[mi], self.heap[index]\n            else:\n              break\n            index = mi\n    def pop(self):\n        val = self.heap[1]\n        self.heap[1] = self. heap.pop()\n        self.size -= 1\n        self._sink(index = 1)\n        return val\n\\end{lstlisting}\nNow, let us run an example:\n\\begin{lstlisting}[language=Python]\nh = Heap()\nlst = [21, 1, 45, 78, 3, 5]\nfor v in lst:\n    h.insert(v)\nprint('heapify with insertion: ', h)\nh.pop()\nprint('after pop(): ', h)\n\\end{lstlisting}\nThe output is listed as:\n\\begin{lstlisting}\nheapify with insertion: 1 3 5 78 21 45 \nafter pop(): 3 21 5 78 45 \n\\end{lstlisting}\n\n\\paragraph{Heapify with Bottom-up Sinking}  Heapify is a procedure that convert a list to a heap data structure.  We have learned the insert procedure. To heapify a list, we can do it through a series of insert iterating through the items in the list and we get an upper-bound complexity of $O(n\\log n)$. However, a more efficient way to do it is is to treat the given list as a tree and to heapify directly on the list. %There are two possibly two ways to do this: (1) through sinking and (2) through floating.  \nTo satisfy the heap property, we need to first start from the smallest subtree. For leaf nodes, they have no children which satisfies the heap property naturally. Therefore we can jumpy to the last parent node, which will be at position a[n//2]. We apply the sinking process as used in \\textbf{pop} so that this subtree rooted at current node obeys the heap property. And we   iterate through all the parents nodes that is a[1...n//2] in reversed order, we can guarentee that final complete binary tree still obeys the heap property. This follows a divide-and-conquer (DP) fashion. Instead of heaipfy A[1...n], we first, heaipfy A[n], A[n-1...n], A[n-2...n], ..., A[1...n].  The process is shown in Fig.~\\ref{fig:heapify}. With this process, it can give us a tighter upper bound and close to $O(n)$. \n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width = 0.98\\columnwidth]{fig/heapify.png}\n    \\caption{Heapify for a given list.}\n    \\label{fig:heapify}\n\\end{figure}\n\\begin{lstlisting}[language=Python]\n  def heapify_sink(self, lst):\n      self.heap = [None] + lst\n      self.size = len(lst)\n      for i in range(self.size//2, 0, -1):\n        self._sink(i)\n\\end{lstlisting}\n\nNow, run the following code:\n\\begin{lstlisting}[language=Python]\nh = Heap()\nh.heapify(lst)\nprint('heapify with heapify:', h)\n\\end{lstlisting}\nOut put is:\n\\begin{lstlisting}\nheapify with heapify: 1 5 21 78 3 45 \n\\end{lstlisting}\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Which way is more efficient building a heap from a list?} Using insertion or heapify? What is the efficiency of each method? The experimental result can be seen in the code.\n\\end{bclogo}\nWhen we are solving a problem, unless specifically required for implementation, we can always use an existent Python module/package. Here, we introduce one Python module: heapq that implements heap data structure for us. \n% \\begin{enumerate}\n% \\item MAX-HEAPIFY, runs in $O(lgn)$, is the key to maintaining the max-heap property\n% \\item BUILD-MAX-HEAP, runs in linear time, produces a maxheap from an unordered input array\n% \\item MAX-HEAP-INSERT, HEAP-EXTRACT-MAX, HEAP-INCREASE-KEY, and HEAP-MAXIMUM, runs in $O(lgn)$ time, allow the heap data structure to implement a priority queue\n% \\end{enumerate}\n%%%%%%%%%%%%%%%%%%Python Built-in Module: heapq%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Python Built-in Library: heapq}\n\\textbf{heapq}: heapq is a built-in library in Python that implements relevant functions to carry out various operations on heap data structure. These functions are listed and described in Table~\\ref{tab:functions_in_heapq}. \\textit{To note that heapq is not a data type like queue.Queue() or collections.deque(), it is a library (or class) that can do operations like it is on a heap.} %, which can be used to maintain a priority queue. Operations include heappush, heappop, and nsmallest. heapq in python to maintain a priority queue with $O(logn)$.\n\\begin{table}[h]\n\\begin{small}\n\\centering\n\\noindent\\captionof{table}{ Methods of \\textbf{heapq}}\n \\noindent \\begin{tabular}{|p{0.25\\columnwidth}|p{0.75\\columnwidth}| }\n  \\hline\nMethod & Description   \\\\ \\hline\nheappush(h, x)  &  Push the value item onto the heap, maintaining the heap invariant.  \\\\\\hline\nheappop(h)  &Pop and return the \\textit{smallest} item from the heap, maintaining the heap invariant. If the heap is empty, IndexError is raised.\\\\ \\hline\nheappushpop(h, x)  &Push item on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().\\\\ \\hline\nheapify(x) & Transform list x into a heap, in-place, in linear time.\\\\ \\hline\nheapreplace(h, x) & Pop and return the smallest item from the heap, and also push the new item. The heap size doesn’t change. If the heap is empty, IndexError is raised. This is more efficient than heappop() followed by heappush(), and can be more appropriate when using a fixed-size heap.\\\\ \\hline\nnlargest(k, iterable, key = fun) & This function is used to return the k largest elements from the iterable specified and satisfying the key if mentioned. \\\\ \\hline\nnsmallest(k, iterable, key = fun) & This function is used to return the k smallest elements from the iterable specified and satisfying the key if mentioned. \\\\ \\hline\n\\end{tabular}\n  \\label{tab:functions_in_heapq}\n  \\end{small}\n\\end{table} \nheapq has some other functions like merge(), nlargest(), nsmallest() that we can use. Check out \\url{https://docs.python.org/3.0/library/heapq.html} for more detials. \n\n\\paragraph{Min-Heap} Now, let us try to heapify the same examplary list as used in the last section, [21, 1, 45, 78, 3, 5], we use need to call the function heapify(). The time complexity of heapify is $O(n)$\n\\begin{lstlisting}[language = Python]\n'''implementing with heapq'''\nfrom heapq import heappush, heappop, heapify\nh = [21, 1, 45, 78, 3, 5]\nheapify(h) # inplace\nprint('heapify with heapq: ', h)\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nheapify with heapq:  [1, 3, 5, 78, 21, 45]\n\\end{lstlisting}\n\n Here we demonstrate how to use function nlargest() and nsmallest() if getting the first n largest or smallest is what we need, we do not need to heapify() the list as we needed in the heap and pop out the smallest. The step of heapify is built in these two functions.\n\\begin{lstlisting}[language=Python]\n''' use heapq to get nlargest and nsmallest'''\nli1 = [21, 1, 45, 78, 3, 5]\n# using nlargest to print 3 largest numbers\nprint(\"The 3 largest numbers in list are : \", end=\"\")\nprint(heapq.nlargest(3, li1))\n\n# using nsmallest to print 3 smallest numbers\nprint(\"The 3 smallest numbers in list are : \", end=\"\")\nprint(heapq.nsmallest(3, li1))\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nThe 3 largest numbers in list are : [78, 45, 21]\nThe 3 smallest numbers in list are : [1, 3, 5]\n\\end{lstlisting}\n\n\n\\paragraph{Max-Heap} As we can see the default heap implemented in the heapq library is forcing the heap property of the min-heap. What if we want a max-heap instead? In heapq library, it does offer us function, but it is intentionally hided from users. It can be accessed like: heapq.\\_[function]\\_max(). Now, let us implement a max-heap instead. \n\\begin{lstlisting}[language = Python]\n# implement a max-heap\nh = [21, 1, 45, 78, 3, 5]\nheapq._heapify_max(h) # inplace\nprint('heapify max-heap with heapq: ', h)\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nheapify max-heap with heapq:  [78, 21, 45, 1, 3, 5]\n\\end{lstlisting}\n\nAlso, in practise, a simple hack for the max-heap is to save data as negative. Also, in the priority queue.\n% What is we want a max-heap which returns the largest number instead of the smallest each time? \n% \\subsubsection{Max-heap and Min-heap}\n% We can write our own MinHeap and MaxHeap class wrapper as follows so that it can be easier to use:\n% \\begin{lstlisting}[language = Python]\n% class MaxHeapObj(object):\n%     def __init__(self,val): self.val = val\n%     def __lt__(self,other): return self.val > other.val\n%     def __eq__(self,other): return self.val == other.val\n%     def __str__(self): return str(self.val)\n    \n% class MinHeap(object):\n%     def __init__(self): self.h = []\n%     def heappush(self,x): heapq.heappush(self.h,x)\n%     def heappop(self): return heapq.heappop(self.h)\n%     def __getitem__(self,i): return self.h[i]\n%     def __len__(self): return len(self.h)\n\n% class MaxHeap(MinHeap):\n%     def heappush(self,x): heapq.heappush(self.h,MaxHeapObj(x))\n%     def heappop(self): return heapq.heappop(self.h).val\n%     def __getitem__(self,i): return self.h[i].val\n% \\end{lstlisting}\n\\paragraph{More Private Functions}\n\\begin{table}[h]\n\\begin{small}\n\\centering\n\\noindent\\captionof{table}{ Private Methods of \\textbf{heapq}}\n \\noindent \\begin{tabular}{|p{0.25\\columnwidth}|p{0.75\\columnwidth}| }\n  \\hline\nMethod & Description   \\\\ \\hline\nheappush(h, x)  &  Push the value item onto the heap, maintaining the heap invariant.  \\\\\\hline\nheappop(h)  &Pop and return the \\textit{smallest} item from the heap, maintaining the heap invariant. If the heap is empty, IndexError is raised.\\\\ \\hline\nheappushpop(h, x)  &Push item on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().\\\\ \\hline\nheapify(x) & Transform list x into a heap, in-place, in linear time.\\\\ \\hline\nheapreplace(h, x) & Pop and return the smallest item from the heap, and also push the new item. The heap size doesn’t change. If the heap is empty, IndexError is raised. This is more efficient than heappop() followed by heappush(), and can be more appropriate when using a fixed-size heap.\\\\ \\hline\nnlargest(k, iterable, key = fun) & This function is used to return the k largest elements from the iterable specified and satisfying the key if mentioned. \\\\ \\hline\nnsmallest(k, iterable, key = fun) & This function is used to return the k smallest elements from the iterable specified and satisfying the key if mentioned. \\\\ \\hline\n\\end{tabular}\n  \\label{tab:functions_in_heapq}\n  \\end{small}\n\\end{table} \n\n\\paragraph{With Tuple/List or Customized Object as Elements}\nAny object that supports comparison (\\texttt{\\_cmp\\_()}) can be used in heap with \\texttt{heapq}. When we want our item includes information as (priority, task), we can either put it in tuple or list. In the heap, we can change the value of any item just as in the list. However, the problem occurs after the change that the list will violate the heap priority. What we can do is use function such as \\texttt{\\_siftdown(heap, 0, len(heap)-1)} (used to implement heappush, and called with decreased priority ) and \\texttt{\\_siftup(heap, 0)} (used to implement heappop, and called with increased priority). \n\\begin{lstlisting}[language=Python]\nimport heapq\n\nheap = [[3, 'a'], [10, 'b'], [5,'c']]\nheapq.heapify(heap)\nprint(heap)\n\nheap[0] = [6, 'a']\nprint(heap)\nheapq._siftup(heap, 0) #simlar to remove heap[0], put this item at the end\nprint(heap)\n\\end{lstlisting}\n\n%%%%%%%%%%%%%%%%%%%%priority Queue%%%%%%%%%%%%%%%%%%%\n\\section{Priority Queue}\n\\label{sec_priority_queue}\nA priority queue is an abstract data type(ADT) and an extension of queue with properties: (1) additionally each item has a priority associated with it. (2) In a priority queue, an item with high priority is served (dequeued) before an item with low priority. (3) If two items have the same priority, they are served according to their order in the queue. \n\nHeap is generally preferred for priority queue implementation because of its better performance compared with arrays or linked list. Also, in Python queue module, we have \\texttt{PriorityQueue()} class that provided us the implementation. Beside, we can can implement priority queue with  \\texttt{heapq} library too. These contents will be covered in the next two subsection. \n\nApplications of Priority Queue:\n\\begin{enumerate}\n    \\item CPU Scheduling\n    \\item Graph algorithms like Dijkstra’s shortest path algorithm, Prim’s Minimum Spanning Tree, etc\n    \\item All queue applications where priority is involved. \n\\end{enumerate}\n\n\\subsubsection{Implement with \\texttt{heapq}  Library} The core function is the ones used to implement the heap: \\texttt{heapify()}, \\texttt{push()}, and \\texttt{pop()}. The official document:\\url{https://docs.python.org/2/library/heapq.html} gave the exact implementation. However, we are still going to summarize and organize this information in our book. In order to implement priority queue, our binary heap needs to have the following features:\n\\begin{enumerate}\n    \\item Sort stability: when we get two tasks with equal priorities, we return them in the order as of they were originally added. A potential solution is to modify the original 2-element list (priority, task) into a 3-element list as (priority, count, task). The entry \\texttt{count} serves as a tie-breaker so that two tasks with the same priority are returned in the order they were added. And also, since no two entry counts are the same the tuple comparison will never attemp to directly compare two tasks.\n    \\item Find a task in the heap, and either remove it or update its priority. Situations like the priority of a task changes or if a pending task needs to be removed. We understand how inconvenient it can be to find the non-root item and update its value. Normally, finding the item is a linear search which takes $O(n)$ and update its value using either \\texttt{\\_siftdown()} or \\texttt{\\_siftup()} can be $O(\\log n)$. The solution is: (1) do not remove the task other than the \\texttt{pop} operation, but mark it as REMOVED instead; (2) to define a dictionary that use \\texttt{task} as key and the 3-element list as value. We name it \\texttt{entry\\_finder}. When the entry is a list, in the heap that encompass these items will only get pointers. Therefore, we can execute the find/mark as removed operation using task as key and do it in the \\texttt{entry\\_finder} instead.\n\\end{enumerate}\nPython code:\n\\begin{lstlisting}[language=Python]\nfrom heapq import heappush, heappop, heapify\nfrom typing import List\nimport itertools\nclass PriorityQueue:\n  def __init__(self, items:List[List]=[]):\n      self.pq = []                         # list of entries arranged in a heap\n      self.entry_finder = {}               # mapping of tasks to entries\n      self.REMOVED = '<removed-task>'      # placeholder for a removed task\n      self.counter = itertools.count()     # unique sequence count\n      # add count to items\n      for p, t in items:\n        item = [p, next(self.counter), t]\n        self.entry_finder[t] = item\n        self.pq.append(item)\n      heapify(self.pq)\n        \n  def add_task(self, task, priority=0):\n      'Add a new task or update the priority of an existing task'\n      if task in self.entry_finder:\n          self.remove_task(task)\n      count = next(self.counter)\n      entry = [priority, count, task]\n      self.entry_finder[task] = entry\n      heappush(self.pq, entry)\n      \n  def remove_task(self, task):\n      'Mark an existing task as REMOVED.  Raise KeyError if not found.'\n      entry = self.entry_finder.pop(task)\n      entry[-1] = self.REMOVED\n\n  def pop_task(self):\n      'Remove and return the lowest priority task. Raise KeyError if empty.'\n      while self.pq:\n          priority, count, task = heappop(self.pq)\n          if task is not self.REMOVED:\n              del self.entry_finder[task]\n              return task\n      raise KeyError('pop from an empty priority queue')\n\\end{lstlisting}\nLet's run an example with our customized \\texttt{PriorityQueue} class:\n\\begin{lstlisting}[language=Python]\npq = PriorityQueue(items=[[6, 'task 6'], [5, 'task5'], [19, 'task19']])\nprint(pq.pq)\npq.add_task('task 10', 10)\nprint(pq.pq)\npq.remove_task('task5')\nprint(pq.pq)\npq.pop_task()\n\\end{lstlisting}\nWith output as:\n\\begin{lstlisting}[numbers=none]\n[[5, 1, 'task5'], [6, 0, 'task 6'], [19, 2, 'task19']]\n[[5, 1, 'task5'], [6, 0, 'task 6'], [19, 2, 'task19'], [10, 3, 'task 10']]\n[[5, 1, '<removed-task>'], [6, 0, 'task 6'], [19, 2, 'task19'], [10, 3, 'task 10']]\n'task 6'\n\\end{lstlisting}\n\n\\subsubsection{Implement with \\texttt{PriorityQueue} class} Class \\texttt{PriorityQueue()} is the same as \\texttt{Queue()}, \\texttt{LifoQueue()}, they have same member functions as shown in Table~\\ref{tab:methods_of_queue}. Therefore, we skip the semantic introduction. \\texttt{PriorityQueue()} normally thinks that the smaller the value is the higher the priority is. We use a similar example as above to demonstrate its function. \n\\begin{lstlisting}[language=Python]\nimport queue\npq = queue.PriorityQueue()\nitems=[[6, 'task 6'], [5, 'task5'], [19, 'task19']]\nfor item in items:\n  pq.put(item)\n\nprint(pq.queue)\nnext_job = pq.get()\nprint('processing job:', next_job)\nprint(pq.queue)\n\\end{lstlisting}\nThe output is:\n\\begin{lstlisting}\n[[5, 'task5'], [6, 'task 6'], [19, 'task19']]\nprocessing job: [5, 'task5']\n[[6, 'task 6'], [19, 'task19']]\n\\end{lstlisting}\nIf we want to give the number with larger value as higher priority, a simple hack is to pass by negative value. Another more professional way is to pass by a customized object and rewrite the comparison operator: < and == in the class with \\_\\_lt\\_\\_() and \\_\\_eq\\_\\_(). In the following code, we show how to use higher value as higher priority. \n\\begin{lstlisting}[language = Python]\nclass Job(object):\n    def __init__(self, priority, description):\n        self.priority = priority\n        self.description = description\n        print('New job:', description)\n        return\n    # def __cmp__(self, other):\n    #     return cmp(self.priority, other.priority)\n    '''customize the comparison operators '''\n    def __lt__(self, other): # <\n        try:\n            return self.priority > other.priority\n        except AttributeError:\n            return NotImplemented\n    def __eq__(self, other): # ==\n        try:\n            return self.priority == other.priority\n        except AttributeError:\n            return NotImplemented\n\nq = Queue.PriorityQueue()\n\nq.put( Job(3, 'Mid-level job') )\nq.put( Job(10, 'Low-level job') )\nq.put( Job(1, 'Important job') )\n\nwhile not q.empty():\n    next_job = q.get()\n    print('Processing job:', next_job.priority)\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nProcessing job: 10\nProcessing job: 3\nProcessing job: 1\n\\end{lstlisting}\nIf we want the priority queue to be able to update the priority of a task, we can apply similar wrapper in the \\texttt{heapq} section. \n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{In single thread programming, is \\textbf{heapq} or \\textbf{PriorityQueue} more efficient?} In fact, the PriorityQueue implementation uses heapq under the hood to do all prioritisation work, with the base Queue class providing the locking to make it thread-safe. While heapq module offers no locking, and operates on standard list objects. This makes the heapq module faster; there is no locking overhead. In addition, you are free to use the various heapq functions in different, noval ways, while the PriorityQueue only offers the straight-up queueing functionality. \n\\end{bclogo}\nLet us take these knowledge into practice with a LeetCode Problem:\n347. Top K Frequent Elements (medium). Given a non-empty array of integers, return the k most frequent elements.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: nums = [1,1,1,2,2,3], k = 2\nOutput: [1,2]\n\nExample 2:\n\nInput: nums = [1], k = 1\nOutput: [1]\n\\end{lstlisting}\n\nAnalysis: to solve this problem, we need to first using a hashmap to get information as: item and its freqency. Then, we need to obtain the top frequent elements. The second step can be down with sorting, or using heap we learned.\n\n\\textbf{Solution 1: Use Counter().} Counter() has a function most\\_common(k) that will return the top k most frequent items. However, its complexity will be $O(n \\log n)$. \n\\begin{lstlisting}[language=Python]\nfrom collections import Counter\ndef topKFrequent(self, nums, k):\n    return [x for x, _ in Counter(nums).most_common(k)]\n\\end{lstlisting}\n\n\\textbf{Solution 2: Use dict and heapq.nlargest()}. The complexity should be better than $O(n \\log n)$. \n\\begin{lstlisting}[language=Python]\nfrom collections import Counter\nimport heapq\ndef topKFrequent(self, nums, k):\n    count = collections.Counter(nums)   \n    return heapq.nlargest(k, count.keys(), key=count.get) \n\\end{lstlisting}\n\nWe can also use PriorityQueue(). \n\\begin{lstlisting}[language=Python]\nfrom queue import PriorityQueue\nclass Solution:\ndef topKFrequent(self, nums, k):\n    h = PriorityQueue()\n    \n    # build a hashmap (element, frequency)\n    temp = {}\n    for n in nums:\n        if n not in temp:\n            temp[n] = 1\n        else:\n            temp[n] += 1\n    # put them as (-frequency, element) in the queue or heap\n    for key, item in temp.items():\n        h.put((-item, key))\n    \n    # get the top k frequent ones\n    ans = [None]*k\n    for i in range(k):\n        _, ans[i] = h.get()\n    return ans\n\\end{lstlisting}\n\n\\section{Bonus}\n\\label{heap_sec_bonus}\n\\paragraph{Fibonacci heap} With fibonacc heap, insert() and getHighestPriority() can be implemented in O(1) amortized time and deleteHighestPriority() can be implemented in O(Logn) amortized time.\n%%%%%%%%%%%%%%%%%%%%%%%LeetCode problems%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Exercises}\n\n\\textbf{selection with key word: kth. These problems can be solved by sorting, using heap, or use quickselect}\n\\begin{enumerate}\n\\item 703. Kth Largest Element in a Stream (easy)\n    \\item 215. Kth Largest Element in an Array (medium)\n    \\item \t347. Top K Frequent Elements (medium)\n    \\item 373. Find K Pairs with Smallest Sums (Medium\t\n\t\\item 378. Kth Smallest Element in a Sorted Matrix (medium)\n\\end{enumerate}\n\\textbf{priority queue or quicksort, quickselect}\n\\begin{enumerate}\n    \\item 23. Merge k Sorted Lists (hard)\n    \\item 253. Meeting Rooms II (medium)\n    \\item 621. Task Scheduler (medium)\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "c403ab83fd44445e9e4fd80c0007a0dbcade5d12", "size": 30123, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_8_heap_priority_queue.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_8_heap_priority_queue.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_8_heap_priority_queue.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": 63.0188284519, "max_line_length": 1317, "alphanum_fraction": 0.7102214255, "num_tokens": 7930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.6907040903082283}}
{"text": "\\section{Introduction}\nLet us first briefly describe finite difference methods and finite element methods used to solve the \nfollowing boundary value problem\n\\begin{equation}\n\\label{laplace}\n-\\Delta u = f,  \\mbox{ in } \\Omega,\\quad\nu=0  \\mbox{ on } \\partial\\Omega,\\quad\n\\Omega=(0,1)^2.\n\\end{equation}\nFor the $x$ direction and the $y$ direction, we consider the partition:\n\\begin{equation}\\label{partitionyx}\n 0=x_0<x_1<\\cdots<x_{n+1}=1, \\quad x_j=\\frac{j}{n+1},\\quad (j=0,\\cdots,n+1);\n \\end{equation}\n \\begin{equation}\\label{partitiony}\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{equation}\nSuch a uniform partition in the $x$ and $y$ directions leads us to a special example in two dimensions, \na uniform square mesh $\\R_h^2 = \\big\\{(mh,nh); n, m \\in \\Z\\big\\}$ (Figure \\ref{fig:2dpartition}). \nLet $\\Omega_h = \\Omega\\cap\\R_h^2$, the set of interior mesh points and $\\partial\\Omega_h = \\partial\\Omega\\cap\\R_h^2$, the set of boundary mesh points.\n\n\\begin{figure}\n\\begin{center}\n\\setlength{\\unitlength}{0.5mm}\n\\begin{picture}(45,45)(50,0)\n\\linethickness{0.25mm}\n\\multiput(0,0)(10,0){6}{\\line(0,1){50}}\n\\multiput(0,0)(0,10){6}{\\line(1,0){50}}\n\\put(0,0){\\line(1,1){50}}\n\\put(10,0){\\line(1,1){40}}\n\\put(20,0){\\line(1,1){30}}\n\\put(30,0){\\line(1,1){20}}\n\\put(40,0){\\line(1,1){10}}\n\\put(0,10){\\line(1,1){40}}\n\\put(0,20){\\line(1,1){30}}\n\\put(0,30){\\line(1,1){20}}\n\\put(0,40){\\line(1,1){10}}\n\\put(47,34){$\\displaystyle \\left. \\begin{array}{l}~ \\\\ ~\\end{array}\n\\right\\} h={1\\over n+1}$}\n\\put(54,14){$\\displaystyle N = n^2$}\n\\multiput(100,0)(10,0){6}{\\line(0,1){50}}\n\\multiput(100,0)(0,10){6}{\\line(1,0){50}}\n\\put(147,34){$\\displaystyle \\left. \\begin{array}{l}~ \\\\ ~\\end{array}\n\\right\\} h={1\\over n+1}$}\n\\put(154,14){$\\displaystyle N = n^2$}\n\\end{picture}\n\\setlength{\\unitlength}{0.5mm}\n\\end{center}\n\\label{fig:2dpartition}\n\\caption{Two-dimensional uniform grid for finite element and finite difference}\n\\end{figure}\n\n\\subsection{Five-point finite difference methods}\nWe can use the center difference to approximate the derivatives as follows:\n$$\n\\frac{\\partial^2 u}{\\partial x^2}(x_i,y_j)=\n\\frac{u(x_{i+1},y_j)-2u(x_i,y_j)+u(x_{i-1},y_j)}{h^2}+{\\mathcal O}(h^2),\n$$\n$$\n\\frac{\\partial^2 u}{\\partial y^2}(x_i,x_j)=\n\\frac{u(x_{i},y_{j+1})-2u(x_i,y_j)+u(x_{i},y_{j-1})}{h^2}+{\\mathcal\n O}(h^2). \n$$\nThus, \n\\begin{equation}\\label{2dfd-truncation}\n(-\\Delta_hu)(x_i,y_j)=(-\\Delta u)(x_i,y_j)+{\\mathcal O}(h^2)\n\\end{equation}\nwhere $-\\Delta_h$ is a discretized operator for $-\\Delta$ given by \n\\begin{equation}\n  \\label{Delta-h}\n(-\\Delta_hu)(x_i,y_j)= \\frac{1}{h^2}(4u(x_i,y_j)-(u(x_{i+1},y_j)+u(x_{i-1},y_j)\n+u(x_i,y_{j+1})+u(x_i,y_{j-1}))).\n\\end{equation}\nThe truncation error \\eqref{2dfd-truncation} can be proved by applying Taylor's expansion directly.\n\nThe finite difference scheme is then formed by\n\\begin{equation}\n  \\label{2d-fd0}\n4u_{ij}-(u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1})=f_{i,j},~~u_{i,j}=0~~\\hbox{if}~~i ~~\\hbox{or}~~ j\\in \\{0, n+1\\}\n\\end{equation}\nwhere \n\\begin{equation}\n  \\label{fij-fd}\nf_{i,j} =h^2 f(x_i, y_j).\n\\end{equation}\n\n\\begin{proposition}\nThe mapping $A$ in \\eqref{uniform-laplace} has following properties\n\\begin{enumerate}\n\\item $A$ is symmetric, namely \n$$\n(Au, v)_F=(u,Av)_F, ~~~\\hbox{where}~~~ (u,v)_F=\\sum_{i,j=1}^nu_{i,j}v_{i,j}.\n$$\n\\item  $(Av, v)_F>0, ~~~\\hbox{if}~~~v\\neq 0.$\n\\item  $\\rho(A)\\le 8$.\n\\end{enumerate}\n\\end{proposition}\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(\\nabla u_h, \\nabla v_h)=(f, v_h),\\ \\forall v_h\\in V_h.\n$$\nThe basis functions $\\phi_{i,j}\\in V_h$ such that \n\\begin{equation*}\n\\phi_{i,j}(x_k,y_l)=\\delta_{(i,j), (k,l)}=\n\\left\\{\n\\begin{array}{rl}\n1& (i,j)= (k,l)\\\\\n0& (i,j)\\neq (k,l)\n\\end{array}\n\\right.\n\\end{equation*}\nThe above formulation can be written as \n$$\nAu=f,\n$$\nwith $A_{(j-1)n+i, (l-1)n+k}=(\\nabla \\phi_{kl}, \\nabla \\phi_{ij})$ and $f_{(j-1)n+i, (l-1)n+k}=(f, \\phi_{ij})$.\n\\begin{enumerate}\n\\item Continuous linear finite element discretization of\n\\eqref{laplace} on the left triangulation in Fig \\ref{fig:2dpartition}. The discrete space for linear finite element is \n$$\nV_h=\\{v_h: v_h|_K\\in P_1(K) \\text{ and } v_h \\text{ is continuous on each interior edge}\\}.\n$$ \nThe basis functions according to the three vertice on the element below are $1-x$, $y$ and $x-y$.\n%Here we need to notice that, $n_\\ell = 2^{k_\\ell} + 1$ for general PDEs grid \n%with the above boundary condition. For general images, we can take them as\n%discrete functions on grid with size $n_\\ell = 2^{k_\\ell}m$ with small $m = 1,3,\\cdots$.\n%Then generally speaking, the coarse grid size is $n_{\\ell+1} = \\frac{n_\\ell}{2}=2^{k\\ell - 1}m$.\nIt is easy to verify that the formulation for the linear element method is exactly the same as the five-point finite difference scheme, namely \n\\begin{equation}\n  \\label{2d-fe0}\n4u_{ij}-(u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1})=f_{i,j},~~u_{i,j}=0~~\\hbox{if}~~i ~~\\hbox{or}~~ j\\in \\{0, n+1\\}.\n\\end{equation}\nThe linear finite element method solves\n\\begin{equation}\n\\label{laplace}\nAu=f\n\\end{equation}\nwith\n\\begin{equation}\n  \\label{2d-fd}\nA=tridiag (-I, B, -I), \\quad B=tridiag (-1, 4, -1).\n\\end{equation}\nThe matrix $A$ is a block tridiagonal matrix. \n\n\\begin{figure}[!ht]\n\\begin{center}\n\\begin{tikzpicture}[xscale=2,yscale=2]\n\\tikzstyle{every node}=[font=\\Large,scale=0.9]\n\\draw[-] (0,0) -- (1,0);\n\\draw[-] (0,0) -- (1,1);\n\\draw[-] (1,0) -- (1,1);\n\\node[below] at (0,0) {$(0,0)$};\n\\node[below] at (1,0) {$(1,0)$};\n\\node[above] at (1,1) {$(1,1)$};\n\\draw[-] (3,0) -- (4,0);\n\\draw[-] (3,0) -- (3,1);\n\\draw[-] (4,0) -- (4,1);\n\\draw[-] (3,1) -- (4,1);\n\\node[below] at (3,0) {$(0,0)$};\n\\node[below] at (4,0) {$(1,0)$};\n\\node[above] at (3,1) {$(1,1)$};\n\\node[above] at (4,1) {$(0,1)$};\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\\item Continuous bilinear finite element discretization of\n\\eqref{laplace} on the right mesh in \nFig. \\ref{fig:2dpartition}. The discrete space for linear finite element is \n$$\nV_h=\\{v_h: v_h|_K\\in \\{1,\\ x,\\ y,\\ xy \\} \\text{ and } v_h \\text{ is continuous on each interior edge}\\}.\n$$ \nThe basis functions according to the four vertice on the element above \nare $\\frac{1}{4}(1-x)(1-y)$, $\\frac{1}{4}(1+x)(1-y)$, $\\frac{1}{4}(1-x)(1+y)$ and $\\frac{1}{4}(1+x)(1+y)$. \nAnd we have\n\\begin{equation}\n  \\label{2d-fe1}\n8u_{ij}-(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})=f_{i,j},\n\\end{equation}\nand \n$$\nu_{i,j}=0~~\\hbox{if}~~i ~~\\hbox{or}~~ j\\in \\{0, n+1\\}.\n$$\n\nThe bilinear finite element method solves\n\\begin{equation}\n\\label{laplace-h}\nAu=f\n\\end{equation}\nwith\n%Here we need to notice that, $n_\\ell = 2^{k_\\ell} + 1$ for general PDEs grid \n%with the above boundary condition. For general images, we can take them as\n%discrete functions on grid with size $n_\\ell = 2^{k_\\ell}m$ with small $m = 1,3,\\cdots$.\n%Then generally speaking, the coarse grid size is $n_{\\ell+1} = \\frac{n_\\ell}{2}=2^{k\\ell - 1}m$.\n\\begin{equation}\\label{uniformbilinear-laplace}\n\\tilde A=\n\\begin{pmatrix}\n\\tilde A_1&\\tilde A_2&\\\\\n\\tilde A_2&\\tilde A_1&\\tilde A_2&\\\\\n     &\\ddots&\\ddots&\\ddots&\\\\\n     &     &\\tilde A_2&\\tilde A_1&\\tilde A_2\\\\\n     &     &     &\\tilde A_2&\\tilde A_1\n\\end{pmatrix},\n\\end{equation}\n\\begin{equation*}\n\\tilde A_1=\n\\begin{pmatrix}\n8&-1&\\\\\n-1&8&-1&\\\\\n     &\\ddots&\\ddots&\\ddots&\\\\\n     &     &-1&8&-1\\\\\n     &     &     &-1&8\n\\end{pmatrix},\n\\tilde A_2=\n\\begin{pmatrix}\n-1&-1&\\\\\n-1&-1&-1&\\\\\n     &\\ddots&\\ddots&\\ddots&\\\\\n     &     &-1&-1&-1\\\\\n     &     &     &-1&-1\n\\end{pmatrix},\n\\end{equation*}\n\\end{enumerate}\n\n\n", "meta": {"hexsha": "642c8e8424b4841929bd040603aa2a53d2351bfe", "size": 7632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MgNet_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/MgNet_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/MgNet_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": 33.7699115044, "max_line_length": 150, "alphanum_fraction": 0.6367924528, "num_tokens": 3218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6907040901276654}}
{"text": "In CMSC250, there are only about two ways in which you might prove a number $\\sqrt[n]{q}$ irrational for some $n \\in \\mathbb{Z}^{>0}$ and some $q \\in \\mathbb{Z}^{>1}$:\n\n\\begin{itemize}\n    \\item A Euclidean argument. That is, you prove some lemma of the form ``if $q \\mid a^n$ then $q \\mid a$''.\n    \\item Use the unique prime factorization theorem and compare the exponents on prime factors modulo $n$.\n\\end{itemize}\n\nThere are two main problems with both approaches:\n\\begin{itemize}\n    \\item The Euclidean argument scales poorly to large values of $n$ and large values of $q$, especially when proving a statement like this by contrapositive, where the naive thing to do is to prove separately each remainder case out of the quotient remainder theorem.\n    \\item Proofs by UPFT are hard to write correctly, are a mess of indices, and are difficult to grade and give feedback. Especially if you have an equation of the form\n    \\[2p_1^{2e_1}\\cdots p_n^{2e_n} = q_1^{2f_1}\\cdots q_k^{2f_k},\\]\n    it is tricky to talk about the exponent of the $2$ in the unique prime factorization of the number on the left hand side.\n\\end{itemize}\n\nHere in this handout I outline better tools (Bezout's Lemma, and the $p \\mid ab$ lemma) which completely resolve these two issues. Proofs using these two methods both scale well to large numbers and are not too hard to write correctly.\n\n\\section{Preliminary Definitions and Results}\n\n\\begin{definition}\n Given integers $a$ and $b$, we say that $a$ divides $b$ (and we write $a \\mid b$) if there exists an integer $k$ such that $a \\cdot k = b$.\n\\end{definition}\n\n\\begin{definition}\n Given integers $a$ and $b$ and positive integer $m$ we say that $a$ is congruent to $b$ modulo $m$ (and we write $a \\equiv b \\pmod{m}$) if $m \\mid (a - b)$.\n\\end{definition}\n\nHere in this document $\\mathbb{Z}$ denotes the integers and $\\mathbb{N}$ denotes the integers greater than $0$. \\textbf{Note that this is different from standard CMSC250 convention!} I'll also abuse the following fact a lot, which is often taken as a given (axiomatic) property of the natural numbers:\n\n\\begin{tcolorbox}\n Let $S \\subseteq \\mathbb{N}$. Then $S$ has a least element. That is, there is an $s \\in S$ such that for all $t \\in S$, $s \\leq t$.\n\\end{tcolorbox}\n\nThis property is called the \\textbf{well ordering property} of $\\mathbb{N}$. As an aside, note that this property that $T$ is equivalent to the principle of mathematical induction, as proven in the box below.\n\\begin{tcolorbox}\n To fill in later. It's not too important.\n\\end{tcolorbox}\n\n\\begin{definition}\n Let $a$ and $b$ be \\textbf{non-zero} integers. Then the greatest common denominator of $a$ and $b$ (we write $\\gcd(a, b)$) is the largest number $g$ which divides $a$ and $b$.\n\\end{definition}\n\n\\begin{example} Here are some simple examples illustrating the gcd.\n    \\begin{tcolorbox}\n      The greatest common denominator of $12$ and $8$ is $4$. \\\\ For any integer $n$, the greatest common denominator of $n$ and $n + 1$ is $1$. How do we show this? Suppose $a \\geq 2$, $a \\mid n$ (that is, $ak = n$ for some $k \\in \\mathbb{Z}$). Then $ak + 1 = n + 1$, and by the quotient remainder theorem it follows that $a$ does not divide $n + 1$. We've deduced that no divisor of $a$ greater than $2$ can also divide $n + 1$. Hence the \\textit{greatest} common divisor of $n$ and $n + 1$ is $1$.\n    \\end{tcolorbox}\n\\end{example}\n\n\\begin{definition}\n A prime number $p$ is a natural number greater than $1$ with the property that the only natural numbers which divide $p$ are $1$ and $p$.\n\\end{definition}\n\nThe following lemma is the key to most irrationality applications. It says that if $p$ is prime and $p \\nmid a$, then $p$ and $a$ have no commmon factors other than $1$. Intuitively and formally, this is clear because $p$ only has $2$ factors, $1$ and $p$.\n\\begin{lemma}\n    Suppose $p$ is a prime and $a$ is an integer with $p \\nmid a$. Then $\\gcd(p, a) = 1$.\n\\end{lemma}\n\\begin{proof}\nThe only divisors of $p$ are $1$ and $p$. The condition $p \\nmid a$ shows that $p$ is not a divisor of $a$. Hence $1$ must be the \\textit{greatest} common divisor of $p$ and $a$, as desired.\n\\end{proof}\n\nWe also use the following lemma a lot, which is just a way to bound numbers by divisors.\n\\begin{lemma}\n    Suppose $a$ and $b$ are integers, $b$ non-zero, with $a \\mid b$. Then $|a| \\leq |b|$. In particular, if $a$ and $b$ are positive, then $a \\leq b$.\n\\end{lemma}\n\\begin{proof}\n    $a \\mid b$ implies that there is an integer $k$ such that $a\\cdot k = b$. Since $b \\neq 0$ it follows that $k \\neq 0$. So $|k| \\geq 1$. It follows that \n    \\[|a| = |a| \\cdot 1 \\leq |a||k| = |ak| = |b|,\\] as desired.\n\\end{proof}\n\n\\section{Bezout's Lemma, and the $p \\mid ab$ Lemma}\n\n\\begin{definition}\n Suppose $m$ and $n$ are integers. An \\textbf{integer linear combination} of $m$ and $n$ is any integer of the form \n \\[mx + ny\\] where $x, y \\in \\mathbb{Z}$.\n\\end{definition}\n\n\\begin{example}\n    $1$ is an integer linear combination of $13$ and $9$, since\n    \\[1 = 91 - 90 = 13(7) - 9(10).\\]\n\\end{example}\n\nGiven non-zero integers $m$ and $n$, let \\[S = \\{mx + ny \\mid x, y \\in \\mathbb{Z}, mx + ny > 0\\}.\\]\nIn English, $S$ is all the positive integer linear combinations. Since $S \\subseteq \\mathbb{N}$, it has a least element $\\ell$. Bezout's Lemma states that $\\ell = \\gcd(m, n)$, a surprising result to take in at first.\n\n\\begin{lemma}\n    Let $m$ and $n$ be non-zero integers, and let $g = \\gcd(m, n)$. Then $g$ is the smallest positive integer linear combination of $m$ and $n$, that is, there exist some integers $x_0$, $y_0$ where\n    \\[g = mx_0 + ny_0,\\] and moreover $g$ is the smallest number where such $x_0$ and $y_0$ exist.\n\\end{lemma}\n\n\\begin{proof}\nThe proof strategy is as follows: define $\\ell$ as earlier, that is, as the least positive integer linear combination of $m$ and $n$ (that is, the smallest natural number where $mx_0 + ny_0 = \\ell$ for some integer $x_0$ and $y_0$). We prove two intermediate results:\n\\begin{enumerate}\n    \\item $\\ell \\mid n$ and $\\ell \\mid n$.\n    \\item $g \\mid \\ell$\n\\end{enumerate}\n\nThese two things imply $\\ell = g$, for the first step tells us $\\ell$ is a common divisor of $m$ and $n$, and the second step tells us that the \\textit{greatest} common divisor divides $\\ell$, hence is less than or equal to $\\ell$. But $g$ is the greatest common divisor, so $g = \\ell$.\n\nLet's prove these two steps. Suppose (by contradiction), $\\ell \\nmid m$. Then by the quotient remainder theorem there exist integers $q$ and $r$ where $0 < r < \\ell$ such that $m = q\\ell + r$. Then we have\n\\[r = m - \\ell q = m - (mx_0 + ny_0)\\ell = m(1 - x_0\\ell) + n(b_0\\ell).\\]\nBoth expressions in the parentheses in the right hand side are integers by closure under addition and multiplication. So we have expressed $r > 0$, strictly less than $\\ell$, as an integer linear combination of $m$ and $n$. But $\\ell$ was defined as the \\textbf{least} integer linear combination! This is a contradiction, so $\\ell \\mid m$. Similarly, $\\ell \\mid n$.\n\nLet $g = \\gcd(m, n)$. There exist $k_1, k_2 \\in \\mathbb{Z}$ such that $gk_1 = m$ and $gk_2 = n$. Then using the $x_0$ and $y_0$ as above we get\n\\[\\ell = mx_0 + ny_0 = g(k_1x_0 + k_2y_0),\\]\nwhich shows that $g \\mid \\ell$, as desired.\n\\end{proof}\n\nWhat immediately follows is a very nice lemma about a prime dividing a product.\n\n\\begin{lemma}\n    Let $p$ be a prime and $a$ and $b$ be integers. If $p \\mid ab$ then $p \\mid a$ or $p \\mid b$.\n\\end{lemma}\n\\begin{proof}\n    To prove this statement we need to show that the statement\n    \\[(p \\mid a) \\lor (p \\mid b).\\]\n    \n    is always true. To prove this or statement, there are two cases. Either $(p \\mid a)$, which means the or statement is true. So there is nothing to do here. So suppose $p \\nmid a$. We need to show that $(p \\mid b)$ to show that the or statement is true.\n    \n    If $p \\nmid a$ then $\\gcd(a, p) = 1$. So there exist integers $x, y$ such that $ax + py = 1$. Multiplying this equation by $b$, we get $abx + pby = b$. But since $p \\mid ab$ there exists an integer $k$ such that $pk = ab$. So substituting this into the above equation we get\n    \\[pkx + pby = p(kx + by) = b,\\] and since $kx + by$ is an integer it follows that $p \\mid b$, as desired.\n\\end{proof}\n\n\\section{Immediate applications to irrationality proofs}\n\nUsing the $p \\mid ab$ lemma we can immediately deduce the Euclidean lemma for any prime and any exponent, as highlighted below.\n\n\\begin{lemma}\nSuppose $p$ is a prime and $a$ is an integer with $p \\mid a^2$. Then $p \\mid a$.\n\\end{lemma}\nI'll give two different proofs of this fact, one using Bezout's Lemma and one using the $p \\mid ab$ lemma.\n\\begin{proof}\n    By contrapositive. Suppose $p \\nmid a$. Then $\\gcd(p, a) = 1$, so there exist integers $x$ and $y$ such that $px + ay = 1$. Squaring this equation we get \n    \\[p^2x^2 + 2pxay + a^2y^2 = p(px^2 + 2pxy) + a^2(y^2) = 1.\\]\n    This shows that $1$ is an integer linear combination of $p$ and $a^2$. Since it is the smallest possible integer linear combination we can conclude that $\\gcd(a^2, p) = 1$. That is,\n    $p \\nmid a^2$, as desired.\n\\end{proof}\nIsn't that neat? No nightmare of indices. No dealing with $p-1$ cases (especially as $p$ gets very large). Just square the equation $ax + py = 1$ to get what you want. The second proof is even easier.\n\n\\begin{proof}\n    Suppose $p \\mid a^2$. Then $p \\mid a \\cdot a$. So $p \\mid a$ or $p \\mid a$, which means that $p \\mid a$, as desired.\n\\end{proof}\n\nIn fact, this proof is so nice that it leads the way to an easy proof by induction.\n\n\\begin{lemma} \\label{gen_euclid}\nSuppose that $p$ is a prime and $a$ is an integer with $p \\mid a^n$. Then $p \\mid a$.\n\\end{lemma}\n\n\\begin{proof}\nWe'll prove this by induction on $n$. For the case $n = 1$, clearly $p \\mid a$ implies $p \\mid a$. Now assume that for $n \\geq 1$ that $p \\mid a^n$ implies $p \\mid a$. Suppose $p \\mid a^{n + 1}$. Then $p \\mid a$ or $p \\mid a^n$. Clearly if $p \\mid a$ we would be done. Even if we suppose not, then $p \\mid a^n$ and our inductive step gives us $p \\mid a$ anyway. So the inductive step is complete and we are done.\n\\end{proof}\n\nThe next lemma shows that mod a prime, any non-zero integer has an inverse modulo $p$.\n\n\\begin{lemma} \\label{inverse}\nSuppose $p$ is any prime, and $k$ is not a multiple of $p$. Then there exists an integer $\\ell$ such that \n\\[k \\ell \\equiv 1 \\pmod{p}.\\]\n\\end{lemma}\n\n\\begin{proof}\nSince $k$ is not a multiple of $p$, it follows that $\\gcd(k, p) = 1$. So there exist integers $x$ and $y$ such that $kx - py = 1$, or $kx - 1 = py$. This implies that $p \\mid (kx - 1)$, or $kx \\equiv 1 \\pmod{p}$, as desired.\n\\end{proof}\n\n\\begin{example}\nWe'll find all the solutions $n$ to the equation $5n \\equiv 3 \\pmod{7}$.\n\\begin{tcolorbox}\n By Lemma \\ref{inverse} there exists some $k$ such that $5k \\equiv 1 \\pmod{7}$. After some searching we see that $k = 3$ is an integer such that $5k \\equiv 1 \\pmod{7}$. Hence\n \\[5kn \\equiv 3k \\pmod{7} \\implies n \\equiv 3(3) \\equiv 2 \\pmod{7}.\\]\n \n So all such $n$ must be of the form $7k + 2$ for some integer $k$. Conversely, if $n = 7k + 2$, then \n \\[5n = 35k + 10 = 7(5k + 1) + 3,\\] or $5n \\equiv 3 \\pmod{7}$. This shows that all solutions $n$ to the equation are the integers $7k + 2$ where $k$ is \\textbf{any} integer.\n\\end{tcolorbox}\n\\end{example}\n\n\\section{Exercises}\n \\begin{enumerate}\n   \\item \\input{Ch6/1_ex/problem_1}\n   \\item \\input{Ch6/1_ex/problem_2}\n   \\item \\input{Ch6/1_ex/problem_3}\n   \\item \\input{Ch6/1_ex/problem_4}\n   \\item \\input{Ch6/1_ex/problem_5}\n   \\item \\input{Ch6/1_ex/problem_6}\n   \\item \\input{Ch6/1_ex/problem_7}\n   % add more problem files here\n \\end{enumerate}\n", "meta": {"hexsha": "43174b229dc6c9d1380211e72ee1e7ccc5fda1c6", "size": 11644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch6/chapter.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch6/chapter.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch6/chapter.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.6021505376, "max_line_length": 500, "alphanum_fraction": 0.6780316043, "num_tokens": 3781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6907040833546589}}
{"text": "\\section{Abstract}\nA model for the solar system using ordinary differential equations was developed with the Velocity Verlet method. The earth sun system, earth sun jupiter system and the whole solar system was examined.\n\n\n\\section{Introduction}\nIn this project I will develop a model simulating the solar system using a set of ordinary differential equations based on Newton's laws of motion:\n\n$\\frac{d^2x}{dt^2} = \\frac{F_{G,x}}{M_{earth}}$\\\\\n\n$\\frac{d^2y}{dt^2} = \\frac{F_{G,y}}{M_{earth}}$\\\\\n\n$\\frac{d^2y}{dt^2} = \\frac{F_{G,z}}{M_{earth}}$\\\\\n\n$F_{G,x}$ = $\\frac{-GM_{\\odot}M_{earth}}{r^2}cos\\theta sin\\psi$= $\\frac{-GM_{\\odot}M_{earth}}{r^3}x$\\\\\n\nand\\\\\n\n$F_{G,y}$ = $\\frac{-GM_{\\odot}M_{earth}}{r^2}sin\\theta sin\\psi$= $\\frac{-GM_{\\odot}M_{earth}}{r^3}y$\\\\\n\nsimilarly\\\\\n\n$F_{G,z}$ = $\\frac{-GM_{\\odot}M_{earth}}{r^2}cos\\psi$= $\\frac{-GM_{\\odot}M_{earth}}{r^3}z$\\\\\n\n\nNumerical methods will be used to solve these equations. An initial test for various methods include the Forward Euler, Central Euler and the velocity Verlet methods. For the complete system the velocity Verlet method will be used.\\\\\n\n\nIn the process of ending up with a solar system I will start by considering basic interaction between the Earth and Sun, before expanding the model to a 3-body problem involving Jupiter, and finally including all planets of the solar system. \n\n\n\n\n\n\\section{Methods}\n%*Formalism/methods: Discussion of the methods used and their basis/suitability. Total number of possible points 20*\n\\subsection{Forward Euler}\nThe Euler method tries to calculate an unknown curve starting in a given point satisfying a certain differential equation.\\\\\n\\begin{equation}\n\\frac{dy}{dt}=f(t,y)\n\\label{Eq:diffeq}\n\\end{equation}\n, where $y(t_0)=y_0$ and $y'(t_0) = v_0$\\\\\n\n\nForward Euler tries to approximate a function curve by a polynomial. The derivative on the left hand side is approximated with a forward step using a Taylor expansion:\\\\\n$y(t+\\Delta t) = y(t) + y'(t)\\Delta t + O(\\Delta t^2)$\\\\\nNeglecting 2nd order terms and higher and solving for y'(t):\\\\\n$y'(t) = \\frac{y(t+\\Delta t)-y(t)}{\\Delta t}$\\\\\nInserting into equation~\\ref{Eq:diffeq} and solving for $y(t+\\Delta t)$:\\\\\n$y(t+\\Delta t) = y(t)+\\Delta t f(t,y(t))$\\\\\n\n\nLet $t_n = t_0+n\\Delta t$\\\\\n\n\nThe total solution can be found by iterating from n=0 to n:\\\\\n\\begin{equation}\ny_{n+1} = y_n+f(t_n, y_n)\\Delta t\n\\label{Eq:Forward_Euler}\n\\end{equation}\\\\\n\n\\subsection{Central Euler}\nCentral Euler method approximates the derivative $\\frac{dy}{dt}$ with a central approximation:\n$\\frac{dy}{dt} \\approx \\frac{y(t+\\Delta t) -y(t-\\Delta t)}{2\\Delta t}$\\\\\n\nInserting into equation~\\ref{Eq:diffeq} and solving for $y(t+\\Delta t)$:\\\\\n\n$y(t+\\Delta t) = y(t-\\Delta t)+2\\Delta t f(t,y(t))$\\\\\n\n\nLet $t_n = t_0+n\\Delta t$.\\\\\n\n\nThe total solution can be found by iterating from n=0 to n:\\\\\n\\begin{equation}\ny_{n+1} = y_{n-1}+2f(t_n, y_n)\\Delta t\n\\label{Eq:Central_Euler}\n\\end{equation}\\\\\n\nComputing $y_1$ at the start of Central Euler iteration is problematic, because it depends on position $y_{-1}$, which is unknown. Therefore in the first step we use the Forward Euler method. The error of the first time step is then of order $O(\\Delta t^2)$. This is not considered a problem because the error of the initial value is small compared to the total error accumulated at time $t=t_n$\n\n\\subsection{Velocity Verlet}\nThe Velocity Verlet method uses a central method to approximate the 2nd order derivative. Velocity Verlet method builds on the basic Verlet method:\\\\\n\n\\begin{equation}\n\\frac{d^2y}{dt^2}=f(t,y)\n\\label{Eq:diffeq_verlet}\n\\end{equation}\n, where $y(t_0)=y_0$ and $y'(t_0) = v_0$\\\\\n\n\n\n$\\frac{d^2y}{dt^2} \\approx \\frac{y(t+\\Delta t) -2y(t)+y(t-\\Delta t)}{\\Delta t^2}$\\\\\n\ninserting into equation~\\ref{Eq:diffeq_verlet} and solving for $y(t+\\Delta t)$:\\\\\n\n$y(t+\\Delta t) = 2y(t)-y(t-\\Delta t)+\\Delta t^2 f(t,y(t))$\\\\\n\n\nLet $t_n = t_0+n\\Delta t$.\\\\\n\nThe total solution can be found by iterating from n=0 to n:\\\\\n\\begin{equation}\ny_{n+1} = 2y_n - y_{n-1} + f(t_n, y_n)\\Delta t^2\n\\label{Eq:Verlet}\n\\end{equation}\\\\\n\nComputing $y_2$ at the start of Verlet iteration at n=1, time $t=t_1=\\Delta t$, one already needs the position vector $y_1$ at time $t=t_1$. At first sight this could give problems, because the initial conditions are known only at the initial times $t_0 = 0$. However, from these the acceleration $a_0 = f(y_0, t_o)$ is known, and a suitable approximation for the first time step position can be obtained using the taylor polynomial of second degree:\\\\\n\n$y_1 = y_0 +v_0\\Delta t + \\frac{a_0\\Delta t^2}{2}\\approx y(\\Delta t)+O(\\Delta t^3)$\\\\\n\nThe error of the first time step calculation then is of order $O(\\Delta t^3)$. This is not considered a problem because on a simulation over a large number of time steps, the error of the first time step is negligibly small compared to the total error at time $t=t_n$.\\\\\n\n\nThe velocities are often needed to calculate physical properties of a system, like kinetic energy. The velocities are not given explicitly given by the basic Verlet method. The Velocity Verlet method incorporates velocities solving the first time step problem in the basic Verlet method by:\n$y(t+\\Delta t) = y(t) +v(t)\\Delta t + \\frac{a(t)\\Delta t^2}{2}$\\\\\n\nWe can calculate the acceleration at the next step by using the differential equation~\\ref{Eq:diffeq_verlet}\\\\\n\n$a(t+\\Delta t) = f((t+\\Delta t), y(t+\\Delta t))$\\\\\n\nThis acceleration is then used to calculate the velocity in the next step\\\\\n\n$v(t+\\Delta t) = v(t) +\\frac{a(t)+a(t+\\Delta t)}{2}\\Delta t$\\\\\n\nIt can be shown that the error for the Velocity Verlet is of the same order as that of the basic Verlet. \\\\\n\nTherefore the final solution set for the Velocity Verlet becomes:\\\\\n\\begin{gather}\n\t\ta_n = f(t_n, y_n)\\\\\n        y_{n+1} = y_n + \\Delta t (v_n + 0.5 a_n \\Delta t) \\\\\n        v_{n+1} = v_k + 0.5 \\Delta t (a_n + f(y_{n+1}, t_{n+1}))\n\\end{gather}\n\n\n\\newpage\n\\section{Implementation}\nFor all programs, see:\\\\\n$\\href{https://github.com/larsjbro/FYS4150/tree/master/Project_3/source}{https://github.com/larsjbro/FYS4150/tree/master/Project_3/source}$\n\\subsection{Testing stability of algorithms}\nIn this section all main results come from this program found at github:\\\\\n$\\href{https://github.com/larsjbro/FYS4150/blob/master/Project_3/source/test_algorithms/test_algorithms.py}{https://github.com/larsjbro/FYS4150/blob/master/Project_3/source/test_algorithms/test_algorithms.py}$\n\n\\subsubsection{Initial velocity for circular orbit}\nThe centripetal force must equal the gravitational force in order to get a circular orbit:\\\\\n\n$\\frac{v^2}{r} = GM_{\\odot} = 4\\pi^2 [AU^3/Yr^2]$\\\\\n\nSolving for v and using that the initial distance from the earth to the sun is 1 AU, we have that a circular orbit is obtained for:\\\\\n\n$v = 2\\pi$\\\\\n\n\n\\subsubsection{Stability for different time steps dt}\nEarth orbit sun for different dt, stability test:\\\\\n\nI can see that the Forward Euler is suspect for large step values of dt, and not even reliable compared to the other methods for the shortest time step. Large step lengths gave an unstable solution as shown in Figures 1, 2 and 4.\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k4beta200ForwardEuler.png}\n\n\\caption{Earth orbit around the sun using the Forward Euler method with $dt = \\frac{1}{2^4}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_4}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k5beta200ForwardEuler.png}\n\n\\caption{Earth orbit around the sun using the Forward Euler method with $dt = \\frac{1}{2^5}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_5}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k8beta200ForwardEuler.png}\n\n\\caption{Earth orbit around the sun using the Forward Euler method with $dt = \\frac{1}{2^8}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k4beta200CentralEuler.png}\n\n\\caption{Earth orbit around the sun using the Central Euler method with $dt = \\frac{1}{2^4}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k5beta200CentralEuler.png}\n\n\\caption{Earth orbit around the sun using the Central Euler method with $dt = \\frac{1}{2^5}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k8beta200CentralEuler.png}\n\n\\caption{Earth orbit around the sun using the Central Euler method with $dt = \\frac{1}{2^8}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k4beta200VelocityVerlet.png}\n\n\\caption{Earth orbit around the sun using the Velocity Verlet method with $dt = \\frac{1}{2^4}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k5beta200VelocityVerlet.png}\n\n\\caption{Earth orbit around the sun using the Velocity Verlet method with $dt = \\frac{1}{2^5}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/stability_test_k8beta200VelocityVerlet.png}\n\n\\caption{Earth orbit around the sun using the Velocity Verlet method with $dt = \\frac{1}{2^8}$}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\\subsubsection{Conservation of kinetic and potential energies and angular momentum}\nAngular momentum for a body in motion under a central force F is defined as follows:\\\\\n$\\frac{dL}{dt}=r \\times F$\\\\\n, where L is the angular momentum, r is the radius and F is the central force. For a circular orbit, we must assume that the central force and the radius are parallel, which gives a change of angular momentum with respect to time being 0. Therefore the angular momentum must be conserved for circular motion. \\\\\n\\\\\n$E_p = -GM/r$\\\\\n$E_k = 1/2mv^2$\\\\,\n\\\\\n$E_{tot} = constant$\\\\\n\nSince the radius with respect to time is not changing as well, we have that both the kinetic energy and the potential energy must remain constant.\n\nNow checking for a circular orbits, that the angular momentum, kinetic and potential energies are conserved:\\\\\n\nFor every position we have the velocities. These are decomposed in each direction, x, y and z. The total velocity squared is the sum of the squared velocities in each direction. This is directly linked to kinetic energy. Large maximum differences of the velocities squared for each method, indicates unstable solutions.\\\\\n\nLow standard deviation for L(angular momentum), $E_k$(kinetic energy ~$v^2$) and $E_p$(potential energy ~$1/r$) would mean that the system is stable. \\\\\n\nFor both CentralEuler and VelocityVerlet, the solutions are decent, with the Velocity Verlet being the most stable. The ForwardEuler is the most unstable, also shown by figures 1, 2 and 3, showing that this method does not approximate an orbit, even when the two other methods do. \\\\\n\nTrue values are shown in Table ~\\ref{tab:Stability_methods_tabular}\\\\\n\n\\FloatBarrier\n\\begin{table}\n\\begin{tabular}{llrrr}\n\\toprule \nMetric & Unit & Forward Euler & Central Euler & Velocity Verlet \\\\ \n\\midrule \nmax diff($v^2$) & $[AU^2/Yr^2]$  & 0.08430  & 0.02381 & 0.00029 \\\\ \nstd($v^2$) &$[AU^2/Yr^2]$ & 4.86822 & 0.02656 & 0.00840 \\\\  \nstd(L/$M_{earth}$) &$[AU^2/Yr]$ & 1.52866 &  0.00134 & 1.12180e-14 \\\\ \nstd(1/r) & $[1/AU]$ & 0.11873 & 0.00034 & 0.00011 \\\\ \n\\bottomrule\n\\end{tabular}\n\\caption{Stability of methods}\n\\label{tab:Stability_methods_tabular}\n\\end{table}\n\\FloatBarrier\n\n\\subsubsection{Timing differences between methods and FLOPs}\nFloating point operations are as follows:\\\\\nCentral Euler has 2 additions and 2 multiplications = 4n flops\\\\\nForward Euler has 2 additions and 1 multiplication = 3n flops\\\\\nVelocity Verlet has 3 additions and 3 multiplications = 6n flops\\\\\n\n\nTable ~\\ref{tab:Timing_differences_FLOPS} shows the runtime differences for each method for varying time steps. The Forward Euler was the fastest method, but clearly this was compensated with bad precision. The Central Euler method had much better precision, and was just slightly slower. The VelocityVerlet was the most precise, and also the slowest. The runtimes can be directly linked to the number of flops as calculated above. \n\n\\FloatBarrier\n\\begin{table}\n\n\\begin{tabular}{lrrrr}\n\\toprule\n{} &  k &  CentralEuler &  ForwardEuler &  VelocityVerlet \\\\\n\\midrule\n0 &  4 &      0.022213 &      0.019871 &        0.048964 \\\\\n1 &  5 &      0.065837 &      0.048205 &        0.128394 \\\\\n2 &  6 &      0.109570 &      0.101608 &        0.188569 \\\\\n3 &  7 &      0.267016 &      0.214553 &        0.437121 \\\\\n4 &  8 &      0.404209 &      0.396895 &        0.856961 \\\\\n\\bottomrule\n\n\\end{tabular}\n\n\\caption{Runtime in seconds for different sampling time dt. $dt = 1/(2^k)$}\n\\label{tab:Timing_differences_FLOPS}\n\\end{table}\n\\FloatBarrier\n\n%*Code/Implementations/test: Readability of code, implementation, testing and discussion of benchmarks. Total number of possible points 20*\n\n \n\n\\section{Results}\n%*Analysis: of results and the effectiveness of their selection and presentation. Are the results well understood and discussed? Total number of possible points: 20*\n\n\n\n\\subsection{Escape velocities}\n\\subsubsection{Analytic solution}\nAnalytically the escape velocity should occur when the kinetic energy is great enough for the object to escape the gravitational force. We have that:\\\\\n\n$v_{crit} = E_k>E_p$\\\\\n\n$\\frac{M_{earth}v^2}{2} = \\frac{GM_{\\odot}M_{earth}}{r}$\\\\\n\n$\\implies v_{crit}=\\sqrt{\\frac{2M_{\\odot}G}{r}}$\\\\\n\nusing $GM_{\\odot} = 4\\pi^2 [AU^3/Yr^2]$\\\\\n\n$v_{crit} = 2\\sqrt{2}\\pi [AU/yr]$\\\\\n\nThis means that analytically an initial velocity larger than $2\\sqrt{2}\\pi [AU/yr]$ would result in the Earth escaping from the sun.\\\\\n\n\\subsubsection{Numerical solution}\nIf the initial velocity is smaller than $2\\pi$ I get the figure ~\\ref{fig:Earth_sun_jupiter_v0_pi} showing that small velocities also do not result a circular orbit:\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/escape_velocity_test_k9beta200v010VelocityVerlet.png}\n\n\\caption{Initial velocity = $\\pi$ [AU/Yr]}\n\\label{fig:Earth_sun_jupiter_v0_pi}\n\\end{figure}\n\\FloatBarrier\n\nFigure ~\\ref{fig:Earth_sun_jupiter_v0_2.6_pi} shows that an initial velocity of 2.6$\\pi$ gives an elliptical orbit, since we are not at escape velocities.\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/escape_velocity_test_k9beta200v026VelocityVerlet.png}\n\n\\caption{Initial velocity = $2.6\\pi$ [AU/Yr]}\n\\label{fig:Earth_sun_jupiter_v0_2.6_pi}\n\\end{figure}\n\\FloatBarrier\n\nFigure ~\\ref{fig:Earth_sun_jupiter_v0_3.0_pi} shows that an initial velocity of 3.0$\\pi$ escapes the sun.\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/escape_velocity_test_k9beta200v030VelocityVerlet.png}\n\n\\caption{Initial velocity = $3.0\\pi$ [AU/Yr]}\n\\label{fig:Earth_sun_jupiter_v0_3.0_pi}\n\\end{figure}\n\\FloatBarrier\n\n\\subsubsection{Varying beta values}\n\nIncreasing the beta value means reducing the gravitational force. Figure ~\\ref{fig:Earth_sun_jupiter_beta_230_v0_2.0_pi}, ~\\ref{fig:Earth_sun_jupiter_beta_270_v0_2.0_pi} and ~\\ref{fig:Earth_sun_jupiter_beta_300_v0_2.0_pi} shows that a higher beta value results in a larger radius for the orbit. When beta approaches 3 the orbit of the Earth will spiral out and escape the sun.\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/escape_velocity_test_k9beta230v020VelocityVerlet.png}\n\n\\caption{Initial velocity = $2.0\\pi$ and beta = 2.3 [AU/Yr]}\n\\label{fig:Earth_sun_jupiter_beta_230_v0_2.0_pi}\n\\end{figure}\n\\FloatBarrier\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/escape_velocity_test_k9beta270v020VelocityVerlet.png}\n\n\\caption{Initial velocity = $2.0\\pi$ and beta = 2.7 [AU/Yr]}\n\\label{fig:Earth_sun_jupiter_beta_270_v0_2.0_pi}\n\\end{figure}\n\\FloatBarrier\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_algorithms/escape_velocity_test_k9beta300v020VelocityVerlet.png}\n\n\\caption{Initial velocity = $2.0\\pi$ and beta = 3.0 [AU/Yr]}\n\\label{fig:Earth_sun_jupiter_beta_300_v0_2.0_pi}\n\\end{figure}\n\\FloatBarrier\n\n\n\\subsection{3-body-problem}\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{test_three_body_problem/stability_2d_test_k70beta200VelocityVerlet.png}\n\n\\caption{The difference in discretization shows how vital the differences can be}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\nFigure ~\\ref{fig:Earth_jupiter} shows the Earth, Sun and Jupiter in one plot.\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{final_model/stability_2d_test_k8beta200VelocityVerlet.png}\n\n\\caption{Earth, Sun and Jupiter in one plot}\n\\label{fig:Earth_jupiter}\n\\end{figure}\n\\FloatBarrier\n\n\n\n\\subsection{Final Model}\nBelow is a final plot of the solar system:\\\\\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.70\\textwidth]{final_model/stability_3d_test_k8beta200VelocityVerlet.png}\n\n\\caption{Final model of the solar system}\n\\label{fig:Earth_orbit_sun_Forward_Euler_k_8}\n\\end{figure}\n\\FloatBarrier\n\n\n\n\n\\subsection{The perihelion precession of Mercury}\nI was not able to finish the general relativity problem trying to figure out if the observed perihelion precession of Mercury quite in time, but I have given a link to the program I have made here:\n$\\href{https://github.com/larsjbro/FYS4150/blob/master/Project_3/source/test_perihelion/test_perihelion.py}{https://github.com/larsjbro/FYS4150/blob/master/Project_3/source/test_perihelion/test_perihelion.py}$\n \n\n\n\\section{Conclusion}\nTo start with the test for numerical method of choice showed that the Velocity Verlet method was the best of the three. I could see that the method of choice plays a huge role in the search for reliable results. Also I found that the runtimes depended very much on number of floating point operations. Nevertheless the precision needs to be at a minimum regardless of speed. The sun is huge, and it took a lot of effort to neutralize the gravitational force\\\\\n\n\n%*Conclusions, discussions and critical comments: on what was learned about the method used and on the results obtained. Possible directions and future improvements? Total number of possible points: 10*\n\n\n\n\n\\section{References}\n\\subsection{Internet sources}\n\n-$\\href{https://github.com/CompPhysics/ComputationalPhysics/blob/gh-pages/doc/Lectures/lectures2015.pdf}{https://github.com/CompPhysics/ComputationalPhysics/blob/gh-pages/doc/Lectures/lectures2015.pdf}$, October 2017\\\\\n\n$\\href{https://ssd.jpl.nasa.gov/horizons.cgi}{https://ssd.jpl.nasa.gov/horizons.cgi}$, NASA, October 2017, used to generate ephemerides\\\\\n\n\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", "meta": {"hexsha": "a997ad25332dd95eb86f603b15c13a08f6546b8d", "size": 20064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project_3/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_3/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_3/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": 38.5105566219, "max_line_length": 459, "alphanum_fraction": 0.7563297448, "num_tokens": 6023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6907040803292805}}
{"text": "\\chapter{Permutations and Sorting}\n\nIn the previous chapter, we talked about permutations. If you have a list\nof three letters, like $[a, b, c, d]$, you can rearrange them in $4!$\nways:\\index{permutations}\n\n\\begin{tabular}{c c c c c c}\n  a,b,c,d & a,b,d,c & a, d, b, c & a, d, c, b & a, c, b, d & a, c, d, b \\\\\n  b,a,c,d & b,a,d,c & b, d, a, c & b, d, c, a & b, c, a, d & b, c, d, a \\\\\n  c,b,a,d & c,b,d,a & c, d, b, a & c, d, a, b & c, a, b, d & c, a, d, b \\\\\n  d,b,c,a & d,b,a,c & d, a, b, c & d, a, c, b & d, c, b, a & d, c, a, b\n\\end{tabular}\n% KA: https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:prob-comb/x9e81a4f98389efdf:combinations/v/combination-formula\n\nYou can make Python generate all the permutations for you:\n\n\\begin{Verbatim}\nfrom itertools import permutations\nall_permutations = permutations(('a', 'b', 'c', 'd'))\nfor p in all_permutations:\n    print(p)\n\\end{Verbatim}\n% KA: https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:prob-comb/x9e81a4f98389efdf:combinations/v/introduction-to-combinations\n\n\\section{Notation}\n\nHow do we define or write down a single permutation? You could say\nsomething like ``Swap the first and second items and swap the third\nand fourth items.'' However, that gets pretty difficult to read. So we\nusually write a permutation as two lines: the first line is before\npermutation and the second line is after.  Like this:\n\n$$\\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  2 & 1 & 4 & 3\n\\end{pmatrix}$$\n\nAnd can we assign permutations to variables. For example, if we wanted the\nvariable $A$ to represent ``swapping the first and second item'', we\nwould write this:\n\n$$A = \\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  2 & 1 & 3 & 4\n\\end{pmatrix}$$\n\nAnd if we wanted $B$ to represent ``swapping the third and fourth item'', we would write:\n\n$$B = \\begin{pmatrix}                                                                                                                             \n  1 & 2 & 3 & 4 \\\\                                                                                                                                \n  1 & 2 & 4 & 3\n\\end{pmatrix}$$\n\nNow, we can \\textit{compose} permutations together. For example, we might say:\\index{permutations!composing}\n\n$$B \\circ A = \\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  2 & 1 & 4 & 3\n\\end{pmatrix}$$\n\nThat is, if we have the list $[a, b, c, d]$ and we apply permutation $A$ and then permutation $B$, we get $[b, a, d, c]$.\n\n\\textbf{Important:} Note that permutations are applied from right to\nleft. $B \\circ A$ means ``Applying $A$ and then $B$.''  Why does this matter?\nPermutations are not necessarily commutative. That is, if you have two\npermutations $S$ and $T$, $S \\circ T$ is not always the same as $T\n\\circ S$.\n\nAlso, note that ``don't change anything'' is a permutation. We call it\n\\textit{the identity permutation}. If you have four items, the identity\npermutation would be written:\\index{permutations!identity permutation}\n\n$$I = \\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  1 & 2 & 3 & 4\n\\end{pmatrix}$$\n\n(We use capital ``I'' for the identity.)\n\n\\subsection{Challenge} Find an example of two permutations $S$ and $T$ such that $S \\circ T$ does not equal $T \\circ S$.\n\n\\section{Sorting in Python}\n\nOne of the common forms of permutation in software is sorting.\nSorting is putting data in a particular order. For example, in Python,\nif you had a list of numbers, you can sort it in ascending order like\nthis:\\index{sorting}\n\n\\begin{Verbatim}\nmy_grades = [92, 87, 76, 99, 91, 93]\ngrades_worst_to_best = sorted(my_grades)\n\\end{Verbatim}\n\nYou want to sort backwards?\n\n\\begin{Verbatim}\nmy_grades = [92, 87, 76, 99, 91, 93]\ngrades_best_to_worst = sorted(my_grades, reverse=True)\n\\end{Verbatim}\n\nNote that \\pyfunction{sorted} makes a new list with the correct\norder. If you want to sort the array in place, you can use the\n\\pyfunction{sort} method:\n% ADD: Need to define array\n\n\\begin{Verbatim}\nmy_grades = [92, 87, 76, 99, 91, 93]\nmy_grades.sort(reverse=True)\n\\end{Verbatim}\n\n\\section{Inverses}\n\nThink for a second about this permutation:\n\n$$S = \\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  3 & 4 & 2 & 1\n\\end{pmatrix}$$\n\nYou could say this permutation shuffles a list a bit.  What is its\ninverse? That is, what is the permutation that unshuffles the items\nback to where they were originally?\\index{permutations!inverses}\n\n$$S^{-1} = \\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  4 & 3 & 1 & 2\n\\end{pmatrix}$$\n\nThat is, the original moved an item in the first spot to the third\nspot. The inverse must move what ever was in the third spot back to\nthe first spot.\n\n(Notation note: Because in multiplication, $b \\times b^{-1} = 1$, we\nuse ``to the negative one'' to indicate inverses in lots of places.)\n\nMechanically, how do you find the inverse? Flip the rows, and then sort the columns using the top number:\n% ADD: Inveserse should probably be defined\n$$\\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  3 & 4 & 2 & 1\n\\end{pmatrix}\n\\text{ flip }\\rightarrow\n\\begin{pmatrix}\n  3 & 4 & 2 & 1 \\\\\n  1 & 2 & 3 & 4\n\\end{pmatrix}\n\\text{ sort }\\rightarrow\n\\begin{pmatrix}\n  1 & 2 & 3 & 4 \\\\\n  4 & 3 & 1 & 2\n\\end{pmatrix}\n$$    \n\nLet's say you have two permutations $A$ and $B$. Permuting by $B$ and then $A$ would look like this:\n\n$$C = A \\circ B$$\n\nIf you know $A^{-1}$ and $B^{-1}$, what is $C^{-1}$?  You would undo-$A$ and then undo-$B$, so\n\n$$C^{-1} = B^{-1} \\circ A^{-1}$$\n\n\\section{Cycles}\n\nHere is a permutation:\n\n$$\\begin{pmatrix}\n  1 & 2 & 3 & 4 & 5 \\\\\n  2 & 4 & 5 & 1 & 3\n\\end{pmatrix}$$\n\nWhen this is applied, whatever is at 1 gets moved to 2, 2 gets moved\nto 4, and 4 gets moved to 1.  That is a \\textit{cycle}: $1 \\rightarrow\n2 \\rightarrow 4$ and then it goes back to 1. It involves three locations, so we say\nit is a \\textit{3-cycle}.\\index{permutations!cycles}\n\nThere is another cycle in this permutation: $3 \\rightarrow 5$ and then it goes back to 3.\n\nBecause these cycles share no members, we say the cycles are \\textit{disjoint}.\n\nEvery permutation can be broken down into a collection of disjoint cycles.\n\n$$T = \\begin{pmatrix}\n  1 & 2 & 3 & 4 & 5 \\\\\n  2 & 4 & 5 & 1 & 3\n\\end{pmatrix} = (1 \\rightarrow 2 \\rightarrow 4)(3 \\rightarrow 5)$$\n\nThe first handy thing about this notation is that it makes it easy for\nus to describe the inverse: we just run the cycles backwards:\n\n$$T^{-1} = (4 \\rightarrow 2 \\rightarrow 1)(5 \\rightarrow 3)$$\n\nStarting with the list $[a, b, c, d, e]$, lets repeatedly apply the permutation $T$\n\n\\begin{tabular}{r | l}\n  Initial & {\\color{red} a, b,} {\\color{blue} c,} {\\color{red} d,} {\\color{blue} e} \\\\ \n  $T$ applied & {\\color{red} d, a,}  {\\color{blue} e,} {\\color{red} b,} {\\color{blue} c}\\\\\n  $T \\circ T$ applied & {\\color{red} b, d,} {\\color{blue} c,} {\\color{red} a,}  {\\color{blue} e} \\\\\n  $T \\circ T \\circ T$ applied & {\\color{red} a, b,}  {\\color{blue} e,} {\\color{red} d,} {\\color{blue} c} \\\\\n  $T \\circ T \\circ T \\circ T$ applied & {\\color{red} d, a,} {\\color{blue} c,} {\\color{red}b,}  {\\color{blue} e} \\\\\n  $T \\circ T \\circ T \\circ T \\circ T$ applied & {\\color{red} b, d,}  {\\color{blue} e,} {\\color{red} a,} {\\color{blue} c} \\\\\n  $T \\circ T \\circ T \\circ T \\circ T \\circ T$ applied & {\\color{red} a, b,} {\\color{blue} c,} {\\color{red} d,}  {\\color{blue} e}\\\\\n\\end{tabular}\n\nThis permutation, results in six combinations, and then it loops back\non itself. The number of combinations is the least common multiple of\nall the cycles.  In this case, there is a 3-cycle and a 2-cycle. The\nleast common multiple of 2 and 3 is 6.\n\n", "meta": {"hexsha": "a9c5aab539d7e59dcaddc90424326240151d404d", "size": 7451, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/DiscreteProbability/permutations-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/DiscreteProbability/permutations-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/DiscreteProbability/permutations-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": 35.6507177033, "max_line_length": 146, "alphanum_fraction": 0.6399141055, "num_tokens": 2518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835248143776, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6907040783651851}}
{"text": "\\chapter{A Point-Classification Neural Network}\n%\\usepackage{amsfonts}\n%\\usepackage{amsmath}\n%\\usepackage{graphicx}\n%\\usepackage{listings}\n\n\\section{Introduction}\nIn this article we implement a simplest neural network with python 3. This implementation is mainly for learning and understanding, without a regularization term and any use of existing deep learning framework.\n\n\\subsection{What's A Point-classification Neural Network}\nSuppose we draw a curve on a canvas, which separates the canvas, or every point on it, into several classes. Now, suppose we have only finite points and their classes, we want to reconstruct the curve. The reconstruction is done by a neural network, trained with the given points. We use it to predict the class of every point on the canvas, and the boundary of the different classes points is the curve we want.\n\\begin{center}\n\\includegraphics[width=0.3\\textwidth]{figures/pcNN_train3.png}\n\\end{center}\n\n\\subsection{What Does the Neural Network Look Like}\nViewed as a function $f$, the neural network can be written as\n\\[f(x)=L_3\\circ L_2\\circ L_1(x)\\]\nwhere $x$ denotes the input vector,  $L_1$ and $L_2$ denote the two hidden layers, and $L_3$ denotes the output layer.\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{figures/pcNN_Fig2}\n\\end{center}\n\n\\subsection{Mathematical Expression of Each Part}\nThe neural network is \\[f(x)=y,\\quad x,y\\in\\mathbb{R}^2,\\]\nand the loss function is \\[L(y)=\\frac{1}{2}\\|y-p\\|^2=\\frac{1}{2}\\sum_{i=1}^2{(y_i-p_i)^2}\\]\nwhere $p$ is the true classification vector.\\\\\n$f(x)=L_3\\circ L_2\\circ L_1(x)$, where\n\\[\n\\begin{split}\nL_1(x)=A(xW_1+b_1)=\\frac{1}{1+e^{-(xW_1+b_1)}}\\in\\mathbb{R}^{10},\\\\\nx\\in\\mathbb{R}^{2},W_1\\in\\mathbb{R}^{10\\times2},b_1\\in\\mathbb{R}^{10},\n\\end{split}\n\\]\n\\[\n\\begin{split}\nL_2(x)=A(xW_2+b_2)=\\frac{1}{1+e^{-(xW_2+b_2)}}\\in\\mathbb{R}^{10},\\\\\nx\\in\\mathbb{R}^{10},W_2\\in\\mathbb{R}^{10\\times10},b_2\\in\\mathbb{R}^{10},\n\\end{split}\n\\]\n\\[\n\\begin{split}\nL_3(x)=A(xW_3+b_3)=\\frac{1}{1+e^{-(xW_3+b_3)}}\\in\\mathbb{R}^{2},\\\\\nx\\in\\mathbb{R}^{10},W_3\\in\\mathbb{R}^{2\\times10},b_3\\in\\mathbb{R}^{2}.\n\\end{split}\n\\]\nEach column of the matrix $W_i$ represents a neuron in the layer $i$. So, layer $1$ has $10$ neurons, layer $2$ has $10$ neurons, and layer $3$ has $2$ neurons.\\\\\n\n\\subsection{What Does A Digital Picture Look Like}\nThe input picture will first be transformed into a grey-scale picture. Then, the values of pixels correspond to a matrix, and we have a matrix as our picture.\n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{figures/pcNN_mesh.png}\n\\end{center}\n\n\\section{The Implementation}\n\\subsection{Produce Training Data}\n\n\\subsection{Produce A Training Curve}\n\nTo give such a curve, or picture, for example, one can draw it by \\emph{paint} on windows, or any other tools on different platforms.\\\\\nIf you use \\emph{paint}, save it as \\emph{train.png} and use the following to load it.\n\n\\begin{lstlisting}\nfrom PIL import Image\nimport numpy as np\npil_im = Image.open('train.png').convert('L')\ndata = np.asarray(pil_im)\n\\end{lstlisting}\n\nThis will load the picture in \\emph{pil\\_im}, and transform it into an array \\emph{data}. Now, each element of \\emph{data} corresponds to the grey scale of a pixel.\\\\\n\n\\section{Generate A Training Dataset}\n\nTo get a training dataset, we generate a couple of coordinates randomly. We then generate the classification from the picture, and scale the dataset by dividing its length.\n\n\\subsection{Backward Propagation}\n\\subsubsection{Backward Propagation (BP) in A Layer}\nViewed as a unity, a layer will carry out the follows.\n\\begin{itemize}\n\\item Recive an input row vector $x$\n\\item Compute $y=xW+b$\n\\item Send $A(y)=\\frac{1}{1+e^{-y}}$ to the next layer\n\\end{itemize}\nIn BP, We want to update $W$ and $b$ by the gradient descent method.\\\\\nWe already have a loss function $L$, and we know the update process is\n\\[W = W + \\delta D_WL,\\]\n\\[b = b+\\delta D_bL.\\]\nLet's figure out how to compute $D_WL$ and $D_bL$.\n\n\\subsubsection{Backward Propagation (BP) in A Layer, Update W}\nLet $W_i$ be the $i$th column of W, we have\n\\[\\nabla_{W_i}L=D_{W_i}L=\\partial_{y_i}L\\nabla_{W_i}y_i\\]\nas a cloumn vector. We then have\n\\[\n\\begin{split}\nD_WL&=\n\\begin{pmatrix} \\nabla_{W_1}L & \\dots & \\nabla_{W_m}L\n\\end{pmatrix}\\\\\n&=\n\\begin{pmatrix}\n\\partial_{y_1}L & \\dots &\\partial_{y_m}L\n\\end{pmatrix}\n\\times\n\\begin{pmatrix}\n\\nabla_{W_1}y_1 & \\dots & \\nabla_{W_m}y_m\n\\end{pmatrix}\n\\end{split}\n\\]\nwhere the multiplication is element-wise.\nWe know that\n\\[\n\\nabla_{W_i}y_i=\\nabla_{W_i}{(xW_i+b_i)}=x^T.\n\\]\nThus we have\n\\[\nD_WL=x^T\n\\begin{pmatrix}\n\\partial_{y_1}L & \\dots &\\partial_{y_m}L\n\\end{pmatrix}.\n\\]\n\n\\subsubsection{Backward Propagation (BP) in A Layer, Update b}\nVery similar to $W$, we update $b_i$ by\n\\[\\partial_{b_i}L=\\partial_{y_i}L\\nabla_{b_i}y_i=\\partial_{y_i}L.\\]\nSo we have\n\\[D_bL=\n\\begin{pmatrix}\n\\partial_{y_1}L & \\dots &\\partial_{y_m}L\n\\end{pmatrix}.\n\\]\nNow we show how to compute\n\\[\nD_yL=\\nabla_yL=\n\\begin{pmatrix}\n\\partial_{y_1}L & \\dots &\\partial_{y_m}L\n\\end{pmatrix}.\n\\]\nBasically, one should follow the steps below.\n\\begin{itemize}\n\\item When you are in a hidden layer, just call the next layer to make it send $\\nabla_yL$ to you.\n\\item If the prior layer asked you for $\\nabla_{\\hat y}L$, follow the steps below.\n\\end{itemize}\nBy the chain rule we have\n\\[\n\\nabla_{\\hat y}L=D_{y}L\\cdot D_xy\\cdot D_{\\hat y}x.\n\\]\nWe have already get $D_yL$. For the rest two, we have\n\\[\nD_xy_i=\\nabla_xy_i=\\nabla_x(xW_i+b_i)=W_i^T,\n\\]\nso we have\n\\[\nD_xy=\n\\begin{pmatrix}\nW_1^T \\\\ \\dots\\\\ W_m^T\n\\end{pmatrix}\n=W^T\n\\]\n\nOn the other hand,\n\\[\nD_{\\hat y}x_i=D_{\\hat y}A({\\hat y}_i)=(1-{\\hat y}_i){\\hat y}_i1_i,\n\\]\nso we have\n\\[\nD_{\\hat y}x=D_{\\hat y}A({\\hat y}_i)=\\text{diag}{((1-{\\hat y}_i){\\hat y}_i)}.\n\\]\nAs a result, we have\n\\[\n\\begin{split}\nD_{\\hat y}L&=D_yL\\cdot\n\\begin{pmatrix}\nW_1^T(1-{\\hat y}_1){\\hat y}_1 \\\\ \\dots\\\\ W_m^T(1-{\\hat y}_m){\\hat y}_m\n\\end{pmatrix}\\\\\n&=(D_yL\\times\n\\begin{pmatrix}\n(1-{\\hat y}_1){\\hat y}_1 & \\dots & (1-{\\hat y}_m){\\hat y}_m\n\\end{pmatrix})\n\\cdot W^T\\\\\n&=(D_yL\\times(1-{\\hat y}){\\hat y})\\cdot W^T\n\\end{split}.\n\\]\n\n\n\nWhen you are in the last layer, there's no next layer to call. What we need is\n\\[\n\\nabla_yL=\n\\begin{pmatrix}\n\\partial_{y_1}L & \\dots &\\partial_{y_m}L\n\\end{pmatrix}.\n\\]\nOur loss function is\n\\[\nL(y)=\\frac{1}{2}\\sum_i{(y_i-p_i)}^2,\n\\]\nso we have\n\\[\n\\nabla_yL=\n\\begin{pmatrix}\ny_1-p_1 & \\dots & y_n-p_n\n\\end{pmatrix}\n\\]\nwhere $n$ is the number of classes.\n\nWe propagate only one vector $x$ in the above discussions, which is not efficient. Now we want to propagate a \\emph{batch} of $x$, denote as a matrix $X$, with each row an input vector.\n\\begin{itemize}\n    \\item When update $W$ and $b$, we just sum up the gradients to get our new gradients,\n\\[W = W + \\delta\\sum_i D_WL(X_i)=W+\\delta\\Delta W,\\]\n\\[b = b+\\delta\\sum_i D_bL(X_i)=b+\\delta\\Delta b.\\]\nwhere $X_i$ denotes the $i$th row of $X$, and $\\delta$ is the step size.\n\\end{itemize}\n\nThis can be rewritten as\n\\[\n\\Delta W=X^T\\nabla_yL,\n\\]\n\\[\n\\Delta b=1^T\\nabla_yL.\n\\]\nWe now finished the backforward propagation\n\\[\nW=W+\\delta X^T\\nabla_yL\n\\]\n\\[\nb=b+\\delta 1^T\\nabla_yL\n\\]\n\\[\nD_{\\hat y}=(D_yL\\times(1-{\\hat y}){\\hat y})\\cdot W^T\n\\]\nA note for batches. We can choose a batch, i.e. a subset of dataset randomly, and update them at one time. After this, we do this again, until the result is acceptable.\n\n\n\\subsection{The Step Size $\\delta$}\n\nFixed step size and others like optimal step size show different performance in decreasing the loss function.\n\\begin{center}\n\\includegraphics[width=\\textwidth]{figures/pcNN_a2.png}\n\\end{center}\n", "meta": {"hexsha": "46cf753310e6d549360963989a1abe72bfa90f57", "size": 7544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/APoint-classificationNeuralNetworkNote.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/APoint-classificationNeuralNetworkNote.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/APoint-classificationNeuralNetworkNote.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3029045643, "max_line_length": 412, "alphanum_fraction": 0.703340403, "num_tokens": 2717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129515, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.690686005996727}}
{"text": "\\chapter{REMPS derivation}\n\\label{sec:remps_deriv}\n\\thispagestyle{empty}\n\n\\noindent This appendix provides the derivation of the REMPS solution.\nWe report here the formulation of the REMPS problem. For the sake of brevity we use $\\mathcal{X} = \\mathcal{S} \\times \\mathcal{A} \\times \\mathcal{S}$ and $(s,a,s') = x \\in \\mathcal{X}$, moreover we indicate with $d(\\cdot)$ the optimized distribution and with $d^{P,\\pi}(\\cdot)$ the sampling distribution.\n\\begin{align}\n\t\\underset{d}{\\text{maximize}} & \\; \\int_\\mathcal{X}d(x)R(x) \\\\\n\t\\text{subject to} &  \\; \\int_\\mathcal{X}d(x) \\log \\frac{d(x)}{d^{P,\\pi}(x)} \\mathrm{d}x \\leq \\epsilon \\\\\n\t& \\int_\\mathcal{X} d(x) \\mathrm{d}x = 1 \\ \\, .\n\\end{align} \n\nWe solve the problem with Lagrangian multipliers. We denote with $\\eta$ the langrangian multiplier associated with the KL constraint and with $\\lambda$ the multiplier associated with the constraint of being a valid distribution.\n\\begin{align}\n\t\\mathcal{L}(d(\\cdot), \\eta, \\lambda) = &\\int_\\mathcal{X} d(x)R(x) \\mathrm{d}x +\\\\ &+ \\eta \\left( \\epsilon - \\int_\\mathcal{X} d'(x) \\log \\frac{d(x)}{d^{P,\\pi}(x)} \\mathrm{d}x \\right) +\\\\ &+ \\lambda \\left(1 - \\int_\\mathcal{X} d(x) \\mathrm{d}x \\right) \\, .\n\t\\label{eq:lagrangian}\n\\end{align}\nObserve that $\\frac{\\partial}{\\partial f(x_0)} \\int f(x) g(x) dx = g(x_0)$. So we take the derivative with respect to $d(x)$ to get:\n\\begin{equation}\n\tR(x) - \\eta \\log \\frac{d(x)}{d^{P,\\pi}(x)} + \\eta - \\lambda = 0 \\, ,\n\\end{equation}\nfrom which we get, solving for $d(x)$:\n\\begin{equation}\n\td(x) = d^{P,\\pi}(x) \\exp \\left(\\frac{R(x)}{\\eta} \\right) \\exp \\left( 1 - \\frac{\\lambda}{\\eta} \\right) \\, .\n\t\\label{eq:remps-pol}\n\\end{equation}\nBy enforcing the constraint that $d$ should be a valid distribution we obtain:\n\\begin{equation}\n\td(x) = \\frac{d^{P,\\pi}(x) \\exp \\left(\\frac{R(x)}{\\eta} \\right)}{\\int_\\mathcal{X} d^{P,\\pi}(x) \\exp \\left( \\frac{R(x)}{\\eta} \\right) \\mathrm{d}x} \\, .\n\\end{equation}\n\nSubstituting into the Lagrangian function (\\ref{eq:lagrangian}), we obtain the dual function:\n\\begin{align}\n\tg(\\eta, \\lambda) &= -\\eta + \\eta\\epsilon + \\lambda \\\\\n\t&= \\eta \\log \\left( \\int_\\mathcal{X} d^{P,\\pi}(x) \\exp \\left(\\epsilon + \\frac{R(x)}{\\eta} \\right)\\mathrm{d}x \\right) \\, .\n\\end{align}\n\nFrom (\\ref{eq:remps-pol}) we extract the policy and model inducing the distribution $d$. We return to the original formulation for the sake of clarity.\n\\begin{align}\n\t\\pi'(a | s) &= \\frac{\\int_\\mathcal{S}d(s,a,s') \\mathrm{d}s'}{\\int_\\mathcal{A}\\int_\\mathcal{S}d(s,a,s') \\mathrm{d}s' \\mathrm{d}a} \\\\\n\t&= \\frac{\\pi(a | s) \\int_\\mathcal{S} P(s' | s,a) \\exp \\left( \\epsilon + \\frac{R(x)}{\\eta} \\right) \\mathrm{d}s'}{\\int_\\mathcal{A} \\pi(a | s) \\int_\\mathcal{S} P(s'|s,a) \\exp \\left( \\epsilon + \\frac{R(x)}{\\eta} \\right) \\mathrm{d}s' \\mathrm{d}a}, \\\\\n\tP'(s' | a, s) &= \\frac{d(s,a,s')}{\\int_\\mathcal{S}d(s,a,s') \\mathrm{d}s'} \\\\\n\t&= \\frac{P(s' | s,a) \\exp \\left( \\epsilon + \\frac{R(x)}{\\eta} \\right)}{\\int_\\mathcal{S} P(s' | s,a) \\exp \\left( \\epsilon + \\frac{R(x)}{\\eta} \\right) \\mathrm{d}s'} \\; .\n\\end{align}", "meta": {"hexsha": "ae03570b9a715d4805e29bff0d48232760a56342", "size": 3031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/remps_proof.tex", "max_stars_repo_name": "EmanueleGhelfi/thesis-remps-cmdp", "max_stars_repo_head_hexsha": "1b512b1684cfa6c8bac9a513b7f0f2e9cbc1eed5", "max_stars_repo_licenses": ["MIT"], "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/remps_proof.tex", "max_issues_repo_name": "EmanueleGhelfi/thesis-remps-cmdp", "max_issues_repo_head_hexsha": "1b512b1684cfa6c8bac9a513b7f0f2e9cbc1eed5", "max_issues_repo_licenses": ["MIT"], "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/remps_proof.tex", "max_forks_repo_name": "EmanueleGhelfi/thesis-remps-cmdp", "max_forks_repo_head_hexsha": "1b512b1684cfa6c8bac9a513b7f0f2e9cbc1eed5", "max_forks_repo_licenses": ["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.8863636364, "max_line_length": 304, "alphanum_fraction": 0.6327944573, "num_tokens": 1164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6906431952431608}}
{"text": "\\chapter{Linearized theory and Newtonian limit}\n\\section{Linearized theory}\nConsider a weak gravitational field. Then we can split the full spacetime metric $\\tensor{g}{_\\mu_\\nu}(x)$ into two parts.\n\\begin{definition}[Linearization of the metric field.]\n    \\begin{equation}\n        \\tensor{g}{_\\mu_\\nu}(x) = \\tensor{\\eta}{_\\mu_\\nu} +\n        \\tensor{h}{_\\mu_\\nu}(x) + \\landauO(h^2) \\, .\n    \\end{equation}\n\\end{definition}\nThereby $\\tensor{h}{_\\mu_\\nu}$ is the flat, constant ``background'' metric of Minkowski\nspace, i.e.\\ there is no gravitational field present.\nThe field $h_{\\mu\\nu}(x)$ can be interpreted as a perturbation on the fixed background $\\eta_{\\mu\\nu}$.\nOne can identify a spin-2 particle, the so-called \\emph{graviton}, with the excitations (quantized fluctuations) of this field.\nBecause only the linear order of $h$ is considered, the nonlinearity of Einstein's equations is lost.\nWe can raise and lower indices with $\\tensor{h}{_\\mu_\\nu}$ and\n$\\tensor{h}{^\\mu^\\nu}$.\n\n\\begin{remark}\nThis works only for a weak gravitational field, since a strong gravitational field produces a strong back reaction of ``matter''\non the geometry, which follows from the nonlinearity of Einstein's equations.\nExactly this back reaction is neglected in the linearized theory.\n\\end{remark}\n\n\\subsection{Derivation of the linearized Einstein's equations}\nIn the following we neglect all terms with $\\landauO(h^2)$.\nOur goal is to express Einstein's field equations in the linearized approximation.\nFor this we need to calculate the Christoffel symbols, the Riemann tensor, the Ricci tensor and the Ricci scalar.\n\n\\subsubsection*{Christoffel symbols}\n\\begin{equation}\n    \\csym{\\mu}{\\nu}{\\varrho} = \\frac{1}{2} \\left( \\tensor{h}{_\\mu_\\varrho_,_\\nu} + \\tensor{h}{_\\nu_\\varrho_,_\\mu}\n    - \\tensor{h}{_\\mu_\\nu_,_\\varrho} \\right) + \\landauO(h^2) \\, .\n\\end{equation}\nChristoffel symbols of the second kind:\n\\begin{equation}\n    \\cSym{\\varrho}{\\mu}{\\nu} = g^{\\varrho\\sigma} \\csym{\\mu}{\\nu}{\\sigma} = \\eta^{\\varrho\\sigma} \\csym{\\mu}{\\nu}{\\sigma} + \\landauO(h^2)\n    = \\frac{1}{2} \\left( \\tensor{h}{_\\mu^\\varrho_,_\\nu} + \\tensor{h}{_\\nu^\\varrho_,_\\mu} - \\tensor{h}{_\\mu_\\nu^,^\\varrho} \\right) + \\landauO(h^2) \\, .\n\\end{equation}\n\\subsubsection*{Riemann tensor}\nThe Riemann tensor can be calculated to\n\\begin{equation}\n    \\begin{split}\n        \\tensor{R}{^\\varrho_\\sigma_\\mu_\\nu}\n        &= \\partial_\\mu \\cSym{\\varrho}{\\nu}{\\sigma} - \\partial_\\nu \\cSym{\\varrho}{\\mu}{\\sigma}\n        + \\underbrace{\\cSym{\\varrho}{\\mu}{\\lambda} \\cSym{\\lambda}{\\nu}{\\sigma} - \\cSym{\\varrho}{\\nu}{\\lambda} \\cSym{\\lambda}{\\mu}{\\sigma}}_{\\landauO(h^2)} \\\\\n        &= \\frac{1}{2} \\left( \\tensor{h}{_\\nu^\\varrho_,_\\sigma_\\mu} +\n        {\\tensor{h}{_\\sigma^\\varrho_,_\\nu_\\mu}} - \\tensor{h}{_\\nu_\\sigma^,^\\varrho_\\mu} - \\tensor{h}{^\\varrho_\\mu_,_\\sigma_\\nu} -\n        {\\tensor{h}{_\\sigma^\\varrho_,_\\mu_\\nu}} +\n        \\tensor{h}{_\\mu_\\sigma^,^\\varrho_\\nu} \\right) + \\landauO(h^2) \\\\\n        &= \\frac{1}{2} \\left( \\tensor{h}{_\\nu^\\varrho_,_\\sigma_\\mu} - \\tensor{h}{_\\nu_\\sigma^,^\\varrho_\\mu}\n        - \\tensor{h}{^\\varrho_\\mu_,_\\sigma_\\nu} +\n        \\tensor{h}{_\\mu_\\sigma^,^\\varrho_\\nu} \\right) + \\landauO(h^2) \\, .\n    \\end{split}\n\\end{equation}\nBy contracting we get the Ricci tensor\n\\begin{equation}\n    \\tensor{R}{_\\sigma_\\nu} = \\tensor{R}{^\\varrho_\\sigma_\\varrho_\\nu}\n    = \\frac{1}{2} \\left( \\tensor{h}{_\\nu^\\varrho_,_\\sigma_\\varrho} - \\tensor{h}{_\\nu_\\sigma^,^\\varrho_\\varrho}\n    - \\tensor{h}{_,_\\sigma_\\nu} + \\tensor{h}{_\\varrho_\\sigma^,^\\varrho_\\nu} \\right) + \\landauO(h^2)\\, ,\n\\end{equation}\nwhere for convenience the trace of $h$ is denoted with $h\\coloneqq\nh_{\\mu\\nu}\\eta^{\\mu\\nu}$. Lastly the Ricci scalar is given by\n\\begin{equation}\n    R = g^{\\sigma\\nu}R_{\\sigma\\nu} = \\eta^{\\sigma\\nu}R_{\\sigma\\nu} + \\landauO(h^2)\n    = \\tensor{h}{^\\sigma^\\nu_,_\\sigma_\\nu} - \\tensor{h}{_,_\\sigma^\\sigma} + \\landauO(h^2)\n\\end{equation}\nWe define\n\\begin{equation}\n    \\overline{h}_{\\mu\\nu} \\coloneqq h_{\\mu\\nu} - \\frac{1}{2} \\eta_{\\mu\\nu}h\\,.\n\\end{equation}\nThe trace is given by\n\\begin{equation}\n    \\overline{h} \\coloneqq  \\overline{h}_{\\mu\\nu}\\eta^{\\mu\\nu} = h -   \n    \\frac{h}{2} = \\frac{h}{2}\\,.\n\\end{equation}\nIf we repeat the procedure we arrive at the initial metric:\n\\begin{equation}\n    \\overline{\\overline{h}}_{\\mu\\nu} = \\overline{h}_{\\mu\\nu} - \\frac{1}{2}\n    \\eta_{\\mu\\nu}\\overline{h} = \\overline{h}_{\\mu\\nu} + \\frac{1}{2}\n    \\eta_{\\mu\\nu}h= h_{\\mu\\nu}\\,.\n\\end{equation}\n\\subsubsection{Linearized Einstein tensor \\texorpdfstring{$G_{\\mu\\nu}$}{Gmunu} in terms of \\texorpdfstring{$\\overline{h}_{\\mu\\nu}$}{hbarmunu}}\nThe linearized Einstein Tensor is given as\n\\begin{equation}\n    \\begin{split}\n        G_{\\mu\\nu}^{\\text{(L)}} =\\ & R_{\\mu\\nu}^{\\text{(L)}} - \\frac{1}{2} \\eta_{\\mu\\nu} R^{\\text{(L)}} \\\\\n        =\\ & \\frac{1}{2} \\partial_\\mu \\partial_\\varrho \\tensor{h}{_\\nu^\\varrho} + \\frac{1}{2} \\partial_\\nu \\partial_\\varrho \\tensor{h}{_\\mu^\\varrho}\n        - \\frac{1}{2} \\Box h_{\\mu\\nu} - \\frac{1}{2}\n        \\partial_{\\mu}\\partial_\\nu h-\\frac{1}{2}\n        \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma h^{\\varrho\\sigma} + \\frac{1}{2} \\eta_{\\mu\\nu}\\Box h \\\\\n        =\\ & \\frac{1}{2} \\partial_\\mu\\partial_\\varrho \\tensor{\\overline{h}}{_\\nu^\\varrho}\n        - {\\frac{1}{4}\\partial_\\mu\\partial_\\nu\\overline{h}}\n        + \\frac{1}{2} \\partial_\\nu\\partial_\\varrho\\tensor{\\overline{h}}{_\\mu^\\varrho}\n        - {\\frac{1}{4}\\partial_\\nu\\partial_\\mu\\overline{h}} - \\frac{1}{2}\\Box\\overline{h}_{\\mu\\nu} \\\\\n        & + {\\frac{1}{2}\\eta_{\\mu\\nu}\\Box\\overline{h}} + {\\frac{1}{2}\\partial_\\mu\\partial_\\nu\\overline{h}}\n        - \\frac{1}{2}\\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma\\overline{h}^{\\varrho\\sigma}\n        + {\\frac{1}{4}\\eta_{\\mu\\nu}\\Box\\overline{h}} - {\\frac{1}{2}\\eta_{\\mu\\nu}\\Box\\overline{h}} \\\\\n        =\\ & -\\frac{1}{2} \\Box \\overline{h}_{\\mu\\nu} + \\partial_\\varrho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h}}{_\\nu_)^\\varrho}\n        - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma\n        \\overline{h}^{\\varrho\\sigma}\\,,\n    \\end{split}\n\\end{equation} \n% \\begin{equation}\n%     \\begin{split}\n%         G_{\\mu\\nu}^{\\text{(L)}} =\\ & R_{\\mu\\nu}^{\\text{(L)}} - \\frac{1}{2} \\eta_{\\mu\\nu} R^{\\text{(L)}} \\\\\n%         =\\ & \\frac{1}{2} \\partial_\\mu \\partial_\\varrho \\tensor{h}{_\\nu^\\varrho} + \\frac{1}{2} \\partial_\\nu \\partial_\\varrho \\tensor{h}{_\\mu^\\varrho}\n%         - \\frac{1}{2} \\Box h_{\\mu\\nu} - \\frac{1}{2}\n%         \\partial_{\\mu}\\partial_\\nu h-\\frac{1}{2}\n%         \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma h^{\\varrho\\sigma} + \\frac{1}{2} \\eta_{\\mu\\nu}\\Box h \\\\\n%         =\\ & \\frac{1}{2} \\partial_\\mu\\partial_\\varrho \\tensor{\\overline{h}}{_\\nu^\\varrho}\n%         - \\mathunderline{blue}{\\frac{1}{4}\\partial_\\mu\\partial_\\nu\\overline{h}}\n%         + \\frac{1}{2} \\partial_\\nu\\partial_\\varrho\\tensor{\\overline{h}}{_\\mu^\\varrho}\n%         - \\mathunderline{blue}{\\frac{1}{4}\\partial_\\nu\\partial_\\mu\\overline{h}} - \\frac{1}{2}\\Box\\overline{h}_{\\mu\\nu} \\\\\n%         & + \\mathunderline{green}{\\frac{1}{2}\\eta_{\\mu\\nu}\\Box\\overline{h}} + \\mathunderline{blue}{\\frac{1}{2}\\partial_\\mu\\partial_\\nu\\overline{h}}\n%         - \\frac{1}{2}\\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma\\overline{h}^{\\varrho\\sigma}\n%         + \\mathunderline{green}{\\frac{1}{4}\\eta_{\\mu\\nu}\\Box\\overline{h}} - \\mathunderline{green}{\\frac{1}{2}\\eta_{\\mu\\nu}\\Box\\overline{h}} \\\\\n%         =\\ & -\\frac{1}{2} \\Box \\overline{h}_{\\mu\\nu} + \\partial_\\varrho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h}}{_\\nu_)^\\varrho}\n%         - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h}^{\\varrho\\sigma} \\\\\n%         \\overset{!}{=}\\ & \\kappa T_{\\mu\\nu}\n%     \\end{split}\n% \\end{equation}\n\n\n%TODO introduce symmetration brackets somewhere\nwith the (linearized) d'Alembert operator\n\\begin{equation}\n    \\Box^{\\text{(L)}} = \\Box = \\partial_\\mu\\partial_\\nu\n    \\eta^{\\mu\\nu}=\\partial_\\mu\\partial^\\mu\\,.\n\\end{equation}\n\\begin{definition}[Linearized Einstein equations]\n    \\begin{equation}\n        \\label{eq:lineinsteineqs}\n        -\\frac{1}{2} \\Box \\overline{h}_{\\mu\\nu} + \\partial_\\varrho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h}}{_\\nu_)^\\varrho}\n        - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h}^{\\varrho\\sigma} = \\kappa T_{\\mu\\nu}\n    \\end{equation}\n\\end{definition}\n\n\\subsubsection{Gauge transformations}\nUsually field equations are in the form of\n\\begin{equation}\n    \\Box \\text{``field''} = \\text{``source''}\\,.\n\\end{equation}\nEquation~\\eqref{eq:lineinsteineqs} can be written in this form:\n\\begin{equation}\n    \\underbrace{\\Box \\overline{h}_{\\mu\\nu}}_{\\Box\\text{``field''}}\n    \\underbrace{- 2 \\partial_\\varrho \\tensor{\\partial}{_(_\\mu} \\tensor{\\overline{h}}{_\\nu_)^\\varrho}\n    + \\eta_{\\mu\\nu}\\partial_\\varrho \\overline{h}^{\\varrho\\sigma}}_{\\text{ensures gauge invariance of equation}}\n    = \\underbrace{-2\\kappa T_{\\mu\\nu}}_{\\text{``source''}}\n\\end{equation}\n\nWe are now considering infinitesimal diffeomorphisms, which are given by affine\ntransformations\n\\begin{equation}\n    x^\\mu = x'^\\mu + \\xi^\\mu(x'^\\mu), \\qquad \\xi^\\mu \\ll 1\n\\end{equation}\nIn the following we neglect terms with $\\landauO(\\xi^2)$, $\\landauO(\\xi h)$, and\n$\\landauO(h^2)$ and higher order terms, which we denote by $\\landauO$.\nThe transformed metric reads\n\\begin{equation}\n    \\begin{split}\n        \\eta_{\\mu\\nu} + h'_{\\mu\\nu}(x') &= g'_{\\mu\\nu} \\\\\n        &= \\frac{\\partial x^\\varrho}{\\partial x'^\\mu} \\frac{\\partial x^\\sigma}{\\partial x'^\\nu} g_{\\varrho\\sigma}(x) \\\\\n        &= \\frac{\\partial \\left( x'^\\varrho + \\xi^\\varrho \\right)}{\\partial x'^\\mu}\n        \\frac{\\partial \\left( x'^\\sigma + \\xi^\\sigma \\right)}{\\partial x'^\\nu}\n        \\left( \\eta_{\\varrho\\sigma} + h_{\\varrho\\sigma}(x) \\right) + \\landauO \\\\\n        &= \\left( \\tensor{\\delta}{_\\mu^\\varrho} + \\tensor{\\xi}{^\\varrho_,_\\mu} \\right)\n        \\left( \\tensor{\\delta}{_\\nu^\\sigma} + \\tensor{\\xi}{^\\sigma_,_\\nu} \\right)\n        \\left( \\eta_{\\varrho\\sigma} + h_{\\varrho\\sigma}(x) \\right) + \\landauO \\\\\n        &= \\left( \\tensor{\\delta}{_\\mu^\\varrho} + \\tensor{\\xi}{^\\varrho_,_\\mu} \\right)\n        \\left( \\eta_{\\varrho\\nu} + h_{\\varrho\\nu} + \\tensor{\\xi}{_\\varrho_,_\\nu}\n        \\right) + \\landauO \\\\\n        &= \\eta_{\\mu\\nu} + h_{\\mu\\nu} + \\tensor{\\xi}{_\\mu_,_\\nu} +\n        \\tensor{\\xi}{_\\nu_,_\\mu} + \\landauO\\,.\n    \\end{split}\n\\end{equation}\nThe perturbation $h_{\\mu\\nu}$ therefore transforms  under infinitesimal\ndiffeomorphisms in the following way\n\\begin{equation}\n    \\begin{split}\n        h'_{\\mu\\nu}(x) &= h_{\\mu\\nu}(x) + \\tensor{\\xi}{_\\mu_,_\\nu} + \\tensor{\\xi}{_\\nu_,_\\mu} \\\\\n        &= h_{\\mu\\nu}(x) + \\left(\\liedif{\\xi}{\\eta} \\right)_{\\mu\\nu}\\,.\n    \\end{split}\n\\end{equation}\n\\begin{definition}[Lie derivative]\n    The Lie derivative off a tensor field $T$ with $k$ contravariant and $l$\n    covariant indices along the vector $\\xi$ is defined as\n    \\begin{equation}\n        \\begin{split}\n            \\left( \\liedif{\\xi}{T} \\right)^{\\alpha_1\\ldots\\alpha_k}_{\\beta_1\\ldots\\beta_l}\n            \\coloneqq \\xi^\\mu \\partial_\\mu T^{\\alpha_1\\ldots\\alpha_k}_{\\beta_1\\ldots\\beta_l}\n            & - \\left( \\partial_\\mu \\xi^{\\alpha_1} \\right) T^{\\mu\\alpha_2\\ldots\\alpha_k}_{\\beta_1\\ldots\\beta_l} - \\ldots\n            - \\left( \\partial_\\mu \\xi^{\\alpha_k} \\right) T^{\\alpha_1\\ldots\\alpha_{k-1}\\mu}_{\\beta_1\\ldots\\beta_l} \\\\\n            & + \\left( \\partial_{\\beta_1} \\xi^\\mu \\right) T^{\\alpha_1\\ldots\\alpha_k}_{\\mu\\beta_2\\ldots\\beta_l} + \\ldots\n            +  \\left( \\partial_{\\beta_l} \\xi^\\mu \\right)\n            T^{\\alpha_1\\ldots\\alpha_k}_{\\beta_1\\ldots\\beta_{l-1}\\mu}\\,.\n        \\end{split}\n    \\end{equation}\n\\end{definition}\nTherefore\n\\begin{equation}\n    \\left( \\liedif{\\xi}{\\eta} \\right)_{\\mu\\nu} = \\underbrace{\\xi^\\varrho\\partial_\\varrho\\eta_{\\mu\\nu}}_{=0}\n    + \\tensor{\\xi}{_\\mu_,_\\nu} + \\tensor{\\xi}{_\\nu_,_\\mu} =\n    \\tensor{\\xi}{_\\mu_,_\\nu} + \\tensor{\\xi}{_\\nu_,_\\mu}\\,.\n\\end{equation}\nIf the derivative of a metric vanishes for a given $\\xi^\\mu$, then one obtains\nthe killing equations \n\\begin{equation}\n    \\tensor{\\xi}{_\\mu_,_\\nu} + \\tensor{\\xi}{_\\nu_,_\\mu}=0 \n\\end{equation}\nfor $\\xi^\\mu$ and the solutions are referred to as \\emph{killing vector fields}.\nIn Minkowski-space the ten infinitesimal killing vectors correspond to the Poincaré-generators.\n\\begin{sidenote}\nWe can use the Lie-derivative on metric to detect symmetries of the Manifold.\n\\end{sidenote}\n\\subsubsection{Invariance of the linearized field equations under infinitesimal\ndiffeomorphisms} \nWe now check that linearized field equations are invariant under infinitesimal\ndiffeomorphism\n\\begin{equation}\n    h'_{\\mu\\nu} = h_{\\mu\\nu} + \\tensor{\\xi}{_\\mu_,_\\nu} +\n    \\tensor{\\xi}{_\\nu_,_\\mu}\\,.\n\\end{equation}\nThe barred metric transforms as\n\\begin{equation}\n    \\begin{split}\n        \\overline{h'}_{\\mu\\nu} &= h'_{\\mu\\nu} - \\frac{1}{2} \\eta_{\\mu\\nu}h' \\\\\n        &= h_{\\mu\\nu} + \\tensor{\\xi}{_\\mu_,_\\nu} + \\tensor{\\xi}{_\\nu_,_\\mu} - \\frac{1}{2} \\eta_{\\mu\\nu}h\n        -\\frac{1}{2}\\eta_{\\mu\\nu}\\partial^\\varrho\\xi_\\varrho - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial^\\varrho\\xi_\\varrho \\\\\n        &= \\overline{h}_{\\mu\\nu} + \\tensor{\\xi}{_\\mu_,_\\nu} +\n        \\tensor{\\xi}{_\\nu_,_\\mu} -\n        \\eta_{\\mu\\nu}\\tensor{\\xi}{^\\varrho_,_\\varrho}\\,.\n    \\end{split}\n\\end{equation}\nWe proceed by plugging this into Einstein's equations, the relevant terms are\n\\begin{align}\n    -\\frac{1}{2}\\Box \\overline{h'}_{\\mu\\nu} &= -\\frac{1}{2}\\Box\\overline{h}_{\\mu\\nu} - \\frac{1}{2}\\Box\\tensor{\\xi}{_\\mu_,_\\nu}\n    -\\frac{1}{2}\\Box\\tensor{\\xi}{_\\nu_,_\\mu} + \\frac{1}{2}\n    \\eta_{\\mu\\nu}\\Box\\tensor{\\xi}{^\\varrho_,_\\varrho}\\,, \\\\\n    -\\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h'}^{\\varrho\\sigma} &=\n    -\\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\left( \\tensor{\\xi}{^\\varrho^,^\\sigma} + \\tensor{\\xi}{^\\sigma^,^\\varrho}\n    - \\eta^{\\varrho\\sigma} \\tensor{\\xi}{^\\alpha_,_\\alpha} \\right) - \\frac{1}{2}\n    \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h}^{\\varrho\\sigma}\\,,\n    \\\\\n    \\partial^\\varrho \\tensor{\\partial}{_(_\\mu} \\tensor{\\overline{h'}}{_\\nu_)_\\varrho} &=\n    \\partial^\\varrho \\tensor{\\partial}{_(_\\mu} \\tensor{\\overline{h}}{_\\nu_)_\\varrho} + \\frac{1}{2}\\Box\\tensor{\\xi}{_\\nu_,_\\mu}\n    + \\frac{1}{2}\\Box\\eta_{\\mu\\nu}\\,.\n\\end{align}\nTherefore\n\\begin{equation}\n    \\begin{split}\n        & -\\frac{1}{2} \\Box \\overline{h'}_{\\mu\\nu} + \\partial_\\varrho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h'}}{_\\nu_)^\\varrho}\n        - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h'}^{\\varrho\\sigma} \\\\\n        =\\ & -\\frac{1}{2}\\Box\\overline{h}_{\\mu\\nu} - {\\frac{1}{2}\\Box\\tensor{\\xi}{_\\mu_,_\\nu}}\n        -{\\frac{1}{2}\\Box\\tensor{\\xi}{_\\nu_,_\\mu}}\n        + {\\frac{1}{2} \\eta_{\\mu\\nu}\\Box\\tensor{\\xi}{^\\varrho_,_\\varrho}}\n        + \\partial^\\varrho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h}}{_\\nu_)_\\varrho} \\\\\n        & + {\\Box\\tensor{\\xi}{_(_\\mu_,_\\nu_)}}\n        - {\\frac{1}{2}\\eta_{\\mu\\nu}\\Box\\tensor{\\xi}{^\\varrho_,_\\varrho}}\n        - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h}^{\\varrho\\sigma} \\\\\n        =\\ & -\\frac{1}{2} \\Box \\overline{h}_{\\mu\\nu} + \\partial_\\varrho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h}}{_\\nu_)^\\varrho}\n        - \\frac{1}{2} \\eta_{\\mu\\nu}\\partial_\\varrho\\partial_\\sigma \\overline{h}^{\\varrho\\sigma}\n    \\end{split}\n\\end{equation}\nThis shows that the Einstein equations are invariant under an infinitesimal diffeomorphisms.\nTherefore $\\overline{h}_{\\mu\\nu}$ and $\\overline{h'}_{\\mu\\nu}$ are the same \\emph{physical} field.\n\n\\subsubsection{Harmonic gauge in linearized gravity}\nAs described above we want to bring the field equation in the form\n$\\Box\\text{``field''}=\\text{``source''}$, i.e. a wave equation.\nThis can ge done with the gauge condition\n\\begin{equation}\n    \\chi_\\nu \\left[ \\overline{h} \\right] \\coloneqq \\partial^\\mu \\overline{h}_{\\mu\\nu} = 0.\n\\end{equation}\nIn therms of the original field this condition reads\n\\begin{definition}[de Donder gauge, harmonic gauge]\n    \\begin{equation}\n        \\chi_\\nu \\left[ h \\right] = \\partial^\\mu h_{\\mu\\nu} - \\frac{1}{2} h_{\\mu\\nu} \\partial^\\mu h = 0\n    \\end{equation}\n\\end{definition}\nProof:\n\\begin{equation}\n    \\begin{split}\n        \\partial^\\mu \\overline{h'}_{\\mu\\nu} &= \\partial^\\mu \\overline{h}_{\\mu\\nu} + \\Box \\xi_\\nu + \\partial_\\nu \\partial^\\mu \\xi_\\mu -\n        \\eta_{\\mu\\nu} \\partial^\\mu\\partial_\\varrho\\xi^\\varrho \\\\\n        &= \\partial^\\mu \\overline{h}_{\\mu\\nu} + \\Box \\xi_\\nu = 0\n    \\end{split}\n\\end{equation}\nSolve for $\\Box\\xi_\\nu$\n\\begin{equation}\n    \\implies \\Box \\overline{h'}_{\\mu\\nu} = -2\\kappa T_{\\mu\\nu}\n\\end{equation}\nSince $\\overline{h}_{\\mu\\nu}$ and $\\overline{h'}_{\\mu\\nu}$ correspond to the same physical field configuration, we can drop the prime.\n\\begin{definition}{Linearized field equations in de Donder gauge.}\n    \\begin{equation}\n        \\Box \\overline{h}_{\\mu\\nu} = - 2 \\kappa T_{\\mu\\nu}\n\\end{equation}\n\\end{definition}\n\\afterpage{\n\\clearpage\n\\thispagestyle{empty}\n\\begin{landscape}\n    \\begin{table}[h]\n        \\caption{Comparison between linearized gravity and electrodynamics.}\n        \\centering\n        \\begin{tabulars}{lll}\n            \\toprule\n            & linearized gravity & electrodynamics \\\\\n            \\midrule\n\n            basic field\n            & $\\overline{h}_{\\mu\\nu}$ ($h_{\\mu\\nu}$), spin-2, \\emph{graviton}\n            & $A_\\mu$, spin-1, \\emph{gauge boson}, \\emph{gauge potential}\n            \\\\%Photon????\n\n\n            field equations\n            & $ \\underbrace{\\Box \\overline{h}_{\\mu\\nu}}_{\\Box\\text{``field''}} - \\underbrace{2 \\partial_\\rho \\tensor{\\partial}{_(_\\mu}\\tensor{\\overline{h}}{_\\nu_)^\\rho} - \\eta_{\\mu\\nu}\\partial_\\rho\\partial_\\sigma \\overline{h}^{\\rho\\sigma}}_{\\text{ensures gauge inv.}} = -\\underbrace{2 \\kappa T_{\\mu\\nu}}_{\\text{``source''}}$\n            & $\\underbrace{\\Box A_\\mu}_{\\Box\\text{``field''}} - \\underbrace{\\partial_\\mu \\left( \\partial_\\nu A^\\nu \\right)}_{\\text{ensures gauge inv.}} = - \\underbrace{4 \\pi j_\\mu}_{\\text{source}}$ \\\\\n\n            transf. under inf. gauge trafos\n            & $\\overline{h'}_{\\mu\\nu} = h_{\\mu\\nu}+\\tensor{\\xi}{_\\mu_,_\\nu} + \\tensor{\\xi}{_\\nu_,_\\mu} - \\eta_{\\mu\\nu} \\tensor{\\xi}{^\\rho_,_\\rho}$\n            & $A'_\\mu = A_\\mu + \\partial_\\mu\\lambda(x)$\\\\\n\n            & inf. coordinate transformation\n            & internal symmetry \\\\\n\n            inv. of field eqs\n            & yes\n            & yes \\\\\n\n            specific gauges\n            & de Donder gauge, $\\partial_\\mu \\overline{h}^{\\mu\\nu}=0$\n            & Lorentz gauge, $\\partial_\\mu A^\\mu = 0$ \\\\\n\n            field eqs. in specific gauges\n            & $\\Box \\overline{h}_{\\mu\\nu} = - 2 \\kappa T_{\\mu\\nu}$\n            & $\\Box A_\\mu = - 4 \\pi j_\\mu$ \\\\\n\n            inv. tensors under gauge trafo\n            & $\\tensor*{R}{^{(\\text{L})\\prime}_\\mu_\\nu} =\n             \\tensor*{R}{^{(\\text{L})}_\\mu_\\nu}$ \n            & $F'_{\\mu\\nu} =F_{\\mu\\nu}$\\\\\n            \\bottomrule\n        \\end{tabulars}\n    \\end{table}\n\\end{landscape}\n}\n\n\\begin{remark}[Fierz-Pauli action, 1939]\n\\begin{equation}\n    \\lagrangian_{\\text{FP}} =\n    \\frac{1}{2} \\left( \\partial_\\mu h^{\\mu\\nu} \\right) \\left( \\partial_\\nu h \\right)\n    - \\partial_\\mu h^{\\rho \\sigma} \\partial_\\rho \\tensor{h}{^\\mu_\\sigma}\n    + \\frac{1}{2} \\eta^{\\mu\\nu} \\left( \\partial_\\mu h^{\\rho\\sigma} \\right) \\left( \\partial_\\nu h_{\\rho \\sigma} \\right)\n    - \\frac{1}{2} \\eta^{\\mu\\nu} \\left( \\partial_\\mu h \\right) \\left( \\partial_\\nu h \\right)\n\\end{equation}\nFor vacuum this is the Lagrangian of a massless spin-2 field $h_{\\mu\\nu}(x)$ (``the graviton'') in flat spacetime $h^{\\mu\\nu}$. \\\\\nProblem: non-linearity (in electrodynamics: linear coupling)\n\\begin{equation}\n    T_{\\mu\\nu}h^{\\mu\\nu} \\rightarrow h_{\\mu\\nu}^{(2)} \\propto \\left( h_{\\mu\\nu}^{(1)}  \\right)^2\n\\end{equation}\n$\\rightarrow$ Deser 1970: Iterative procedure \\\\\n$\\hookrightarrow$ including gravitational self energy and resuming one recovers the full nonlinear Einstein equations.\n\\end{remark}\n\n\\newpage\n\n\\section{Newtonian Limit}\nEmpirically we know\n\\begin{enumerate}\n    \\item Newtonian gravity describes the dynamics in our solar system to a high accuracy\n    \\item On earth, we can measure the gravitation constant $G_\\text{N}$ e.g.\\ by Cavendish-type  experiments\n\\end{enumerate}\nIf General Relativity is a more fundamental gravitational theory than Newton's theory it should\n\\begin{enumerate}\n    \\item recover \\name{Newton}'s theory in appropriate limit, i.e.\\ in the domain where Newtonian Gravity is a good description\n    \\item be more accurate than Newton's theory, i.e.\\ it should predict small corrections to Newtonian Gravity.\n\\end{enumerate}\nConditions for the Newtonian limit:\n\\begin{enumerate}\n    \\item $v \\ll c$ (sources move slowly) \\\\\n    slowly changing geometry $\\approx$ static: no $\\dif{x}^i\\dif t$ terms in\n    $\\dif{s}^2$ (would violate $t\\rightarrow -t$ invariance)\n    \\item $g_{\\mu\\nu} = \\eta_{\\mu\\nu} + h_{\\mu\\nu}$ with $\\abs{h_{\\mu\\nu}} \\ll 1$ (weak gravitational field)\n    \\item $p \\ll \\rho$ (sources have low internal pressure)\n\\end{enumerate}\n\\begin{enumerate}[{ad} 1.]\n    \\item $v\\ll c$ is required as (special) relativistic effects must be small\n    \\item Consider the solar system as a closed system: Then a particle in the outer region with $v\\ll c$ initially,\n    will fall into the inner region (center of mass) and it will be accelerated by gravity. It will be then have a kinetic energy\n    $E_\\text{kin} = \\frac{1}{2} m v^2 \\sim \\abs{m \\Phi}$, where $\\Phi < 0$ is the gravitational Newtonian potential with boundary condition\n    $\\displaystyle \\lim_{x\\to \\infty}\\Phi(x) = 0$. Small velocities of the\n    sources imply weak gravitational fields.\n    \\item Speed of sound\n    \\begin{align}\n        & c_s \\coloneqq \\abs{\\frac{T_{ij}}{T_{00}}} \\quad \\text{with} \\quad T_{\\mu\\nu} = \\diag \\left( \\rho, \\frac{p}{c^2}, \\frac{p}{c^2}, \\frac{p}{c^2} \\right) \\quad \\text{(perfect fluid)} \\\\\n        & c_s \\sim \\left( \\frac{p}{\\rho} \\right)^{1/2}\n    \\end{align}\n    The internal pressure of the sources must be small, otherwise they would also create (fast) motion of sound waves. \\\\\n    $\\implies p \\ll \\rho$ \\\\\n    $\\implies$ energy-momentum tensor of dust\n    \\begin{align}\n        T^{\\mu\\nu} &= \\rho_0 t^\\mu t^\\nu \\\\\n        t^\\mu &= \\delta^\\mu_0 = \\left( \\frac{\\partial}{\\partial x^0} \\right)^\\mu\n    \\end{align}\n    $t^\\mu$ is the ``direction'' of an internal coordinate system of time\n    \\begin{equation}\n        \\Box \\overline{h}_{\\mu\\nu} \\approx \\Delta \\overline{h}_{\\mu\\nu}\n    \\end{equation}\n    alternatively $\\Box = - \\frac{1}{c^2} \\frac{\\partial^2}{\\partial t^2} + \\Delta \\approx \\Delta$ as \n    $\\frac{1}{c} \\frac{\\partial}{\\partial t} = \\frac{1}{c} \\frac{\\partial}{\\partial x} \\frac{\\partial x}{\\partial t} \n    \\sim \\frac{v}{c} \\frac{\\partial}{\\partial x} \\ll \\frac{\\partial}{\\partial x}$\n\\end{enumerate}\n\nFor the Newtonian limit, we must look for solutions to $\\Box \\overline{h}_{\\mu\\nu} = - 2 \\kappa T_{\\mu\\nu}$, where time-derivatives are \nnegligible and where the energy-momentum tensor is the one of dust. \n\\begin{equation}\n    \\Delta \\overline{h}_{\\mu\\nu} = \n    \\begin{cases}\n    \t-2 \\kappa \\rho_0 & \\mu=\\nu=0 \\\\\n    \t0 & \\text{else}\n    \\end{cases}\n\\end{equation}\nConsider first the \\name{Poisson} equation with vanishing sources. \nThe unique solution is $\\overline{h}_{\\mu\\nu} = \\const$. The $\\const$ can be always adjusted to zero by a residual gauge transformation:\n\\begin{equation}\n    \\overline{h}_{\\mu\\nu} = 0, \\quad \\mu \\neq \\nu = 0\n\\end{equation}\nResidual gauge transformation\n\\begin{equation}\n    \\partial^\\mu \\overline{h'}_{_\\mu\\nu} = \\underbrace{\\partial^\\mu \\overline{h}_{\\mu\\nu}}_{=0} + \\Box \\xi_\\nu = 0\n\\end{equation}\nThis means that all gauge transformations $\\xi_\\mu$ with $\\Box \\xi_\\mu = 0$ are compatible with the de Donder gauge \n(i.e.\\ that doesn't lead out of the de Donder gauge). \\\\\nAs far we know:\n\\begin{align}\n    \\overline{h}_{\\mu\\nu} &= 0 \\qquad \\text{for the 0-0 component } \\\\\n    \\Delta \\overline{h}_{00} &= - 2\\kappa \\rho_0 \\qquad \\mu \\neq \\nu = 0\n\\end{align}\nWe identify the gravitational potential as\n\\begin{equation}\n    \\Phi \\coloneqq -\\frac{1}{4} \\overline{h}_{00}\n\\end{equation}\nWe obtain the \\name{Poisson} equation\n\\begin{equation}\n    \\Delta \\Phi = \\frac{\\kappa}{2} \\rho_0 = 4 \\pi G_\\text{N} \\rho_0\n\\end{equation}\nSolution in terms of the original field $h_{\\mu\\nu}$:\n\\begin{equation}\n    h_{\\mu\\nu} = \\overline{h}_{\\mu\\nu} - \\frac{1}{2} \\eta_{\\mu\\nu} \\overline{h} \n    = \\overline{h}_{00} \\left( \\tensor{\\delta}{_\\mu^0} \\tensor{\\delta}{_\\nu^0} + \\frac{1}{2} \\eta_{\\mu\\nu} \\right) \n    = - 4\\Phi \\left( \\tensor{\\delta}{_\\mu^0} \\tensor{\\delta}{_\\nu^0} + \\frac{1}{2} \\eta_{\\mu\\nu} \\right)\n\\end{equation}\nWe have used $\\overline{h}=\\eta^{\\rho\\sigma}\\overline{h}_{\\rho\\sigma} = -\\overline{h}_{00} = 4 \\Phi$\n\\begin{align}\n    & \\implies h_{00}=-2\\Phi \\qquad h_{ij}=-2\\Phi\\delta_{ij} \\qquad h_{0\\mu}=0 \\\\\n    & \\implies \\dif{s}^2 = g_{\\mu\\nu} \\dif{x}^\\mu \\dif{x}^\\nu = - (1+2\\Phi)\\dif{t}^2 + (1-2\\Phi)\\delta_{ij} \\dif{x}^i \\dif{x}^j\n\\end{align}\nThis is the Newtonian geometry.\n%TODO ref to first appearance newt. geo.\n\\subsection{Motion of test particles in Newtonian Geometry}\nTest particles carry clocks that read universal time in Newton Geometry.\n\\begin{align}\n    & \\frac{\\dif{}^2 x^i}{\\dif{} t^2} = \\frac{\\dif{}^2 x^i}{\\dif{} \\tau^2} \n    = - \\cSym{i}{\\alpha}{\\beta} \\frac{\\dif x^\\alpha}{\\dif \\tau} \\frac{\\dif x^\\beta}{\\dif \\tau}\n    = - \\cSym{i}{0}{0}\n    = - \\csym{0}{0}{i}\n    = \\frac{1}{2} \\tensor{h}{_0_0_,_i} - \\tensor{h}{_0_i_,_0} \n    = \\frac{1}{2} \\tensor{h}{_0_0_,_i} = - \\tensor{\\Phi}{_,_i} \\\\\n    & \\implies \\frac{\\dif{}^2 x^i}{\\dif{} t^2} =  - \\tensor{\\Phi}{_,_i} \\qquad \\left( \\quad \\widehat{=} \\quad \\vec{a} = -\\nabla \\Phi \\right) \n\\end{align}\nwhere we used $\\frac{\\dif \\tau}{\\dif t} = 1$,$v^i \\sim \\abs{\\frac{\\dif x^i}{\\dif \\tau}} \\ll 1$, $g_{\\mu\\nu}=\\eta_{\\mu\\nu}$, and\n$\\dif{}_t \\sim \\frac{v^i}{c} \\dif{}_{x_i} \\ll 1$.\nIn Newtonian Gravity, we have two equations\n\\begin{enumerate}\n    \\item ``field equations'': $\\Delta \\Phi = 4 \\pi G_\\text{N} \\rho_0$ (Poisson equation), describes how the gravitational potential\n    (geometry in General Relativity) reacts on matter $\\rho_0$\n    \\item ``geodesic equation'': $\\frac{\\dif{}^2 x^i}{\\dif{}t^2} = - \\tensor{\\Phi}{_,_i}$, describes how matter (test particles, dust)\n    moves under the influence of the gravitational potential $\\Phi$ (in General Relativity: moves in curved geometry)\n\\end{enumerate}\n\n\\subsection{Geodesic deviation in Newtonian Geometry}\nFrom the last analysis, we know\n\\begin{equation}\n    \\cSym{i}{0}{0} = \\tensor{\\Phi}{^,^i} \\qquad \\text{(all other components are zero).}\n\\end{equation} \nInsert this in the Riemannian curvature tensor:\n\\begin{equation}\n    \\tensor{R}{^i_0_j_0} = -\\tensor{R}{^i_0_0_j} = \\tensor{\\Phi}{^,^i_j} \\qquad \\text{(all other components are zero).}\n\\end{equation}\nRicci-tensor: \n\\begin{equation}\n    R_{00} = \\Delta \\Phi = 4 \\pi G_\\text{N} \\rho_0\n\\end{equation}\n\n\\subsubsection{geodesic deviation}\n\\begin{equation}\n    \\frac{\\difD^2 \\eta^i}{\\difD \\tau^2} \\approx \\frac{\\dif{}^2 \\eta^i}{\\dif{} \\tau^2} \n    = - \\tensor{R}{^i_0_j_0} \\eta^j = - \\tensor{\\Phi}{^,^i_j}\\tensor{\\eta}{^j}\n\\end{equation}\nwhere we used that\n\\begin{equation}\n    \\frac{\\difD{} \\eta^i}{\\difD{} \\tau} = \\nabla_j \\eta^i \\frac{\\dif x^j}{\\dif \\tau} = \\partial_j \\eta^i x^j = \\frac{\\dif \\eta^i}{\\dif t}\n\\end{equation}\nCompare to the deviation equation due to tidal forces in Newtonian Gravity.\n\\begin{equation}\n    \\begin{split}\n        \\frac{\\dif{}^2 \\eta^i}{\\dif \\tau^2} &= \\frac{\\dif{}^2 \\left( x^i + \\eta^i \\right)}{\\dif{} t^2} - \\frac{\\dif{}^2 x^i}{\\dif{}t^2} \\\\\n        &= - \\left. \\frac{\\partial \\Phi}{\\partial x_i} \\right|_{x+\\eta} + \\left. \\frac{\\partial \\Phi}{\\partial x_i} \\right|_{x} \\\\\n        &= - \\left. \\frac{\\partial \\Phi}{\\partial x_i} \\right|_{x} \n        - \\left. \\frac{\\partial^2 \\Phi}{\\partial x_i \\partial x^j} \\right|_{x} \\eta^j \n        + \\left. \\frac{\\partial \\Phi}{\\partial x_i} \\right|_{x} \\\\\n        &= - \\tensor{\\Phi}{^,^i_j} \\eta^j\n    \\end{split}\n\\end{equation}\nThis shows again that tidal forces are a genuine gravitational effect that is related to curvature of spacetime (in General Relativity) \nand cannot be transformed away.\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{geodesicdeviation.pdf}\n\\caption{}\n%TODO Caption\n\\end{figure}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{Tidalforce.pdf}\n\\caption{Tidal forces acting on particles on a ring }\n\\end{figure}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{Tidalforces1.pdf}\n%TODO Caption\n\\end{figure}\n\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{Tidalforces2.pdf}\n%TODO Caption\n\\end{figure}\n\n\n", "meta": {"hexsha": "6f515c28a6361299546c5e59928e66d966bc93e2", "size": 28562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/07-linearised-theory-and-newtonian-limit.tex", "max_stars_repo_name": "Bigben37/GeneralRelativity", "max_stars_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-31T13:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T13:18:57.000Z", "max_issues_repo_path": "src/07-linearised-theory-and-newtonian-limit.tex", "max_issues_repo_name": "QuantumDancer/GeneralRelativity", "max_issues_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/07-linearised-theory-and-newtonian-limit.tex", "max_forks_repo_name": "QuantumDancer/GeneralRelativity", "max_forks_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.6974169742, "max_line_length": 324, "alphanum_fraction": 0.6284924025, "num_tokens": 10454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6906431790364634}}
{"text": "\\subsection{Greedy Algorithm}\n\nIt is a simple algorithm: add the vertices which minimize the added weight and does not violate the precedence-constraint iteratively until no more vertex can be added without exceeding the knapsack capacity. Such algorithm is presented below:\n\n\\begin{algorithm}[ht!]\n    \\caption{Greedy}\n    \\begin{algorithmic}[1]\n        \\Require{$\\vertices, \\edges, \\weight, \\maximumWeight$}\n        \\State{$S \\gets \\emptyset$}\n        \\State{$X \\gets $ all leaf vertices}\n        \\State{$Y \\gets 0$}\n        \\State{$\\solutionE \\gets \\mathop{\\mathrm{arg\\,min}}\\limits_{\\solutionE \\in X} \\weightE$}\n        \\While{$Y + \\weightE \\leqslant \\maximumWeight$}\n            \\State{$S \\gets S \\cup \\Set{\\solutionE}$}\n            \\State{$Y \\gets Y + \\weightE$}\n            \\State{$X \\gets $ all the vertices not yet in $S$ that can be added to $S$ without violating the constraints}\n            \\State{$\\solutionE \\gets \\mathop{\\mathrm{arg\\,min}}\\limits_{\\solutionE \\in X} \\norm{\\weightE}$}\n        \\EndWhile\n        \\\\\\Return{$S$}\n    \\end{algorithmic}\n    \\label{algorithm:greedy}\n\\end{algorithm}\n", "meta": {"hexsha": "496e3893ff92993771e107c6c693d10862038615", "size": 1107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/report/textual/greedy.tex", "max_stars_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_stars_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project/report/textual/greedy.tex", "max_issues_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_issues_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project/report/textual/greedy.tex", "max_forks_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_forks_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.1304347826, "max_line_length": 243, "alphanum_fraction": 0.6449864499, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7718434925908524, "lm_q1q2_score": 0.6906374244845842}}
{"text": "% based on example 7 in pythontex_gallery\n% https://github.com/gpoore/pythontex/\n\n\\documentclass[12pt]{mmalatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{A table of derivatives and anti-derivatives}\n\nThis example is based upon a nice example in the Pythontex gallery, see\n\\ \\url{https://github.com/gpoore/pythontex/}.\nIt uses a tagged block to capture the Mathematica output for later use\nin the body of the LaTeX table.\n\n\\lstset{numbers=left}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{mathematica}\n   (* Create a list of functions to include in the table *)\n   fun = {Sin[x],      Cos[x],      Tan[x],\n          ArcSin[x],   ArcCos[x],   ArcTan[x],\n          Sinh[x],     Cosh[x],     Tanh[x]};\n\n   eol = {\"\\\\\\\\\" ,     \"\\\\\\\\\",      \"\\\\\\\\\",\n          \"\\\\\\\\[5pt]\", \"\\\\\\\\[5pt]\", \"\\\\\\\\[5pt]\",\n          \"\\\\\\\\\",      \"\\\\\\\\\",      \" \"};\n\n   ddxfun = D[#, x] & /@ fun;\n   intfun = Integrate[#, x] & /@ fun;\n\n   ddxfunHold = HoldForm[D[#, x]] & /@ fun;\n   intfunHold = HoldForm[Integrate[#, x]] & /@ fun;\n\n   (* mmaBeg (CalculusTable) *)\n   Do[Print[OutputForm[\n      ToString[TeXForm[ddxfunHold[[i]]]] <> \"&=\" <>\n      ToString[TeXForm[ddxfun[[i]]]]     <> \"\\\\quad & \\\\quad\"\n      ToString[TeXForm[intfunHold[[i]]]] <> \"&=\" <>\n      ToString[TeXForm[intfun[[i]]]]     <>\n      eol[[i]]\n      ]], {i,1,9}]\n   (* mmaEnd (CalculusTable) *)\n\\end{mathematica}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      \\mma {CalculusTable}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\clearpage\n\n\\begin{align*}\n   \\mma {CalculusTable}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "8e9f89418056db5be7c632694a33c7d091e4acd0", "size": 1606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematica/examples/example-02.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "mathematica/examples/example-02.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mathematica/examples/example-02.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 25.9032258065, "max_line_length": 71, "alphanum_fraction": 0.5753424658, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6906104072454904}}
{"text": "\\section{Series}\n\\subsection{Finite Series}\n\\declareexercise{7.1.1}\n\\begin{proof}\n(a)\nInduct on $p$. When $p=m+1$, $n=m$, and \n\\[\n\\sum_{i=m}^n{a_i} + \\sum_{i=n+1}^p{a_i} = a_m + a_{m+1} = \\sum_{i=m}^p{a_i}\n\\]\n\nWe suppose inductively that for some $p$ the property still holds, then for $p+1$,\n\\begin{align*}\n&\\sum_{i=m}^n{a_i} + \\sum_{i=n+1}^{p+1}{a_i}\\\\\n&= \\sum_{i=m}^n{a_i} +\\sum_{i=n+1}^{p}{a_i} + a_{p+1} \\tag{By def.}\\\\\n&= \\sum_{i=m}^{p}{a_i} + a_{p+1} \\tag{Induction Hypothesis} \\\\\n&= \\sum_{i=m}^{p+1}{a_i} \\tag{By def.} \n\\end{align*}\n\n(b)\nInduct on $n$. The inductive step is \n\\[\n\\sum_{i=m}^{n+1}a_i = \\sum_{i=m}^{n}a_i + a_{n+1} = \\sum_{i=m+k}^{n+k}a_i + a_{n+k+1-k} = \\sum_{i=m+k}^{n+k}a_i\n\\]\n\n(c)\nThe inductive step is\n\\begin{align*}\n\\sum_{i=1}^{n+1}{(a_i+b_i)} \n&= \\sum_{i=1}^{n}{(a_i+b_i)} + (a_{n+1}+b_{n+1}) \\\\\n&= \\sum_{i=1}^{n}{a_i}+\\sum_{i=1}^{n}{b_i}+ (a_{n+1}+b_{n+1}) \\\\\n&= \\sum_{i=1}^{n+1}{a_i}+\\sum_{i=1}^{n+1}{b_i}\n\\end{align*}\n\n(d)\nThe inductive step is\n\\begin{align*}\n\\sum_{i=1}^{n+1}{ca_i} \n&= \\sum_{i=1}^{n}{ca_i} + ca_{n+1} \\\\\n&= c\\sum_{i=1}^{n}{a_i}+ c(a_{n+1}) \\\\\n&= c\\sum_{i=1}^{n+1}{a_i}\n\\end{align*}\n\n(e) \nThe inductive step is \n\\begin{align*}\n\\left|\\sum_{i=1}^{n+1}{a_i}\\right|\n&= \\left|\\sum_{i=1}^{n}{a_i} + a_{n+1}\\right| \\\\\n&\\leq \\left|\\sum_{i=1}^{n}{a_i}\\right| + \\left|a_{n+1}\\right| \\\\\n&\\leq \\sum_{i=1}^{n}{|a_i|} + |a_{n+1}| \\\\\n&= \\sum_{i=1}^{n+1}{|a_i|}\n\\end{align*}\n\n(f)\nThe inductive step is\n\\begin{align*}\n\\sum_{i=1}^{n+1}{a_i}\n&= \\sum_{i=1}^{n}{a_i} + a_{n+1} \\\\\n&\\leq \\sum_{i=1}^{n}{b_i} + b_{n+1} \\\\\n&= \\sum_{i=1}^{n+1}{b_i}\n\\end{align*}\n\\end{proof}\n\n\\declareexercise{7.1.2}\n\\begin{proof}\n(a) \nAny function $g$ from the empty set ($\\{i:1\\leq i \\leq 0\\}$) to the empty set is a bijection. So $\\sum_{x \\in \\varnothing}{f(x)} = \\sum_{i=1}^0{f(g(i))} = 0$.\n\n(b)\nThis time the bijection $g$ would be $\\{1\\} \\to \\{x_0\\}$. And we have $\\sum_{x \\in \\{x_0\\}}{f(x)} = \\sum_{i=1}^1{f(g(i))} = f(g(1)) = f(x_0)$.\n\n(c)\n\n\\end{proof}\n\n\\subsection{Infinite Series}\n\\declareexercise{7.2.1}\nIt is divergent.\n\\begin{proof}\nIt is immediately derived from $((-1)^n)^\\infty_n$ being divergent.\n\\end{proof}\n\n\n\\declareexercise{7.2.2}\n\\begin{proof}\nAccording to Theorem 6.4.18, $(S_n)_n^\\infty$ is convergent iff it is Cauchy. That is, iff \n\\[\n\\forall \\varepsilon>0(\\exists N(\\forall p,q\\geq N(|S_p-S_q|\\leq \\varepsilon)))\n\\]\nIf $p\\geq q$, then according to Lemma 7.1.4, (a), $|S_p-S_q| = |\\sum_{i=q+1}^p{a_i}|$. If $p \\leq q$, then \n\\[\n|S_p-S_q| = \\left|\\sum_{i=1}^p{a_i}-(\\sum_{i=1}^p{a_i}+\\sum_{i=q+1}^p{a_i})\\right| = \\left|-\\sum_{i=q+1}^p{a_i}\\right| = \\left|\\sum_{i=q+1}^p{a_i}\\right|\n\\]\nWe nearly finished the proof except that here $i$ starts at $q+1$, not $q$. But this is an unimportant matter. In fact, on one hand, $\\forall p,q \\geq N(|\\sum_{i=q}^p{a_i}|) \\rightarrow \\forall p,q \\geq N(|\\sum_{i=q+1}^p{a_i}|)$; on the other hand, $\\forall p,q \\geq N(|\\sum_{i=q+1}^p{a_i}|) \\rightarrow \\forall p,q \\geq N+1(|\\sum_{i=q}^p{a_i}|)$. We only requires the existence of $N$ for any arbitrary $\\varepsilon >0$, so the two statements are equivalent.\n\\end{proof}\n\n\\declareexercise{7.2.3}\n\\begin{proof}\nSimply let $p=q$ in Proposition 7.2.5 to obtain $\\forall \\varepsilon >0 (\\exists N(\\forall p\\geq N(|a_p|\\leq \\varepsilon)))$ and we are finished.\n\\end{proof}\n\n\\declareexercise{7.2.4}\n\\begin{proof}\nAccording to Lemma 7.1.4, (e), we have $|\\sum_{i=q}^p{a_i}| \\leq \\sum_{i=q}^p{|a_i|} = |\\sum_{i=q}^p{|a_i|}|$ as $\\sum_{i=q}^p{|a_i|}\\geq 0$. So if $|\\sum_{i=q}^p{|a_i|}| \\leq \\varepsilon$, then $|\\sum_{i=q}^p{a_i}|$ must also satisfy it.\n\\end{proof}\n\n\\declareexercise{7.2.5}\n\\begin{proof}\n(a)\nAccording to Lemma 7.1.4, (c), the partial sum of $\\sum_{n=m}^\\infty{a_n+b_n}$ is $\\sum_{n=m}^Na_n + \\sum_{n=m}^Nb_n$. The limit of this sequence, according to Proposition 6.1.19, is the sum of the two limits, $\\sum_{n=m}^\\infty a_n+ \\sum_{n=m}^\\infty b_n$.\n\n(b)\nThe partial sum can be seen as $c \\sum_{n=m}^Na_n$.\n\n(c)\nThis statement immediately follows from taking limits on both sides of the following equation derived from Lemma 7.1.4 (for $N \\geq m+k$)\n\\[\n\\sum_{n=m}^Na_n = \\sum_{n=m}^{m+k-1}a_n + \\sum_{n=m+k}^Na_n\n\\]\n\n(d)\nThis statement immediately follows from \n\\[\n\\sum_{n=m}^Na_n = \\sum_{n=m+k}^{N+k}a_{n-k}\n\\]\n\\end{proof}\n\n\\declareexercise{7.2.6}\n\\begin{proof}\nBy induction we can easily show that $\\sum_{i=0}^N{a_n-a_{n+1}} = a_0-a_{N+1}$. Taking limits on both sides of this equation immediately gives \n$\\sum_{n=0}^\\infty = a_0-\\lim_{n \\to \\infty}a_n$.\n\\end{proof}\n\n\\subsection{Sums of non-negative numbers}\n\\declareexercise{7.3.1}\n\\begin{proof}\nBy Lemma 7.1.4, we know that $\\sum_{n=m}^N|a_n| \\leq \\sum_{n=m}^Nb_n$. Since that $\\sum_{n=m}^\\infty b_n$ converges, there is a $M$ such that \n$\\sum_{n=m}^N|a_n| \\leq \\sum_{n=m}^Nb_n \\leq M$. This fact plus that $|a_n| \\geq 0$ immediately leads to the convergence of $\\sum_{n=m}^\\infty|a_n$. We can draw a similar conclusion for $|\\sum_{n=m}^Na_{n}|$.\n\nTo show that the limits of them still follows the order, however, it is not so obvious. We must prove that limit preserves order.\n\\end{proof}\n\n\\declareexercise{7.3.2}\n\\begin{proof}\nIf $|x| \\geq 1$, then $x^n \\to$ either $\\infty$ or $-\\infty$. Thus the series is divergent.\n\nIf $|x| < 1$, then the partial sum of $|x|^n$ equals $\\frac{1-|x|^{N+1}}{1-|x|}$. Since $|x|^{N+1} \\to 0$, taking limit gives $\\sum_{n=0}^\\infty {|x|^n} = \\frac{1}{1-|x|}$. This immediately implies that the original series is conditionally convergent. So taking limit on the not absolute partial sum gives what we want.\n\\end{proof}\n\n\\declareexercise{7.3.3}\n\\begin{proof}\nAssume that negation, that is, at least for some $n \\in X$, $a_n \\neq 0$.\n\\end{proof}", "meta": {"hexsha": "3ceec98f3fe9ca8ee15f5efb9054d54faf9370f6", "size": 5659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Series.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": "Series.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": "Series.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": 37.2302631579, "max_line_length": 459, "alphanum_fraction": 0.6184838311, "num_tokens": 2485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290699, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.6905857846632504}}
{"text": "\\section{Cartesian Products}\n\n\\begin{definition}\n  Let $\\mathcal{A}$ be a nonempty collection of sets. An \\textbf{indexing\n  function} for $\\mathcal{A}$ is a surjective function $f$ from some set $J$,\n  called the \\textbf{index set}, to $\\mathcal{A}$. The collection $\\mathcal{A}$, together with the indexing function $f$ is called an \\textbf{indexed family of sets}. Given $\\alpha \\in J$, we shall denote the set $f(\\alpha)$ by the symbol $A_\\alpha$. And we shall denote the indexed family itself by the symbol\n  \\begin{equation}\n    \\pbrac{\n      A_\\alpha\n    }_{\n      \\alpha \\in J\n    },\n  \\end{equation}\n  which is read as ``the family of all $A_\\alpha$, as $\\alpha$ ranges over $J$.''\n\\end{definition}\n\n\\section*{Exercises}\n\n\\bx{\n  Consider $f : A \\to B$\n  \\begin{align*}\n    f(a, b) &= (b, a)\\\\\n    f^{-1}(b, a) &= (a, b)\n  \\end{align*}\n}\n\n\\bx{\n  I'm just going to write out functions that you can check are bijective.\n  \\ea{\n    \\item $f(a_1, a_2, \\dots, a_n) = ((a_1, \\dots, a_{n-1}), a_n)$\n    \\item \\begin{align*}\n      f_{-1} (a_1, a_2, \\dots) &= ((a_1, a_2), (a_3, a_4), \\dots) = (b_1, b_2, \\dots)\\\\\n      f^{-1} (b_1, b_2, \\dots) &= f^{-1}((a_1, a_2), (a_3, a_4), \\dots)\\\\\n        &= (a_1, a_2, \\dots)\n    \\end{align*}\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item For any $b \\in B$, we have that every index element $\\in A_i$, so\n    therefore $b \\in A$. Therefore $B \\subset A$.\n    \\item The converse is if $B \\subset A$, then $B_i \\subset A_i$. This is true\n    because AFSOC $\\exists b \\in B$ such that $\\exists i$ such that $B_i \\not\\subset\n    A_i$. Then $b \\not \\in A$, and therefore $B \\not\\subset A$. But this is a\n    contradiction.\n    \\item AFSOC $\\exists i$ such that $A_i$ is empty. Then, $A$ must be empty,\n    because there is no element that can be in the $i^\\text{th}$ tuple. If every\n    $A_i$ is nonempty, then $A$ must also be nonempty.\n    \\item \\begin{itemize}\n      \\item $A \\cup B \\subset \\prod_i A_i \\cup B_i$\n      \\item $A \\cap B \\supset \\prod_i A_i \\cap B_i$\n    \\end{itemize}\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item Just map the first $m$ tuples to the first $m$, and the remainder just map to any element of $X$\n    \\item $f((x_1, \\dots, x_m), (x'_1, \\dots, x'_n)) = (x_1, \\dots, x_m, x'_1, \\dots, x'_n)$\n    \\item Just map the first $n$ elements, and for the rest just use any element of $X$\n    \\item Map first $n$, then map the rest. Other way, Map first $n$, then map the rest\n    \\item $f((x_1, x_2, \\dots), (x'_1, x'_2, \\dots)) = (x_1, x'_1, x_2, x'_2, \\dots)$\n    \\label{chap1:sec5:prob4:part3}\n    \\item Just cycle through the $n$ coordinates for mapping, similar to\n    \\ref{chap1:sec5:prob4:part3}.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item Yes, just do $\\prod_i \\mathbb{Z}$\n    \\item Easy, just $\\prod_i [i, \\infty)$\n    \\item $\\prod_{i=1}^{100} \\mathbb{R} \\times \\prod_{i=101}^\\infty \\mathbb{Z}$\n    \\item Cannot be expressed.\n  }\n}", "meta": {"hexsha": "3c23173553a606cde2702ffc1a0c06754023546f", "size": 2849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1/chapter1-5.tex", "max_stars_repo_name": "mikinty/Topology-Munkres-Solutions", "max_stars_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T04:11:03.000Z", "max_issues_repo_path": "chapters/chapter1/chapter1-5.tex", "max_issues_repo_name": "mikinty/Topology-Munkres-Solutions", "max_issues_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1/chapter1-5.tex", "max_forks_repo_name": "mikinty/Topology-Munkres-Solutions", "max_forks_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0, "max_line_length": 310, "alphanum_fraction": 0.6040716041, "num_tokens": 1065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.6905857752251423}}
{"text": "\\section{Matrix inverses}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a matrix is invertible, and compute the\n    inverse if it exists.\n  \\item Solve a system of linear equations using matrix algebra.\n  \\item Prove algebraic properties of matrix inverses.\n  \\item Determine whether a matrix is a left inverse, right inverse, or\n    inverse of another matrix.\n  \\end{enumerate}\n\\end{outcome}\n\n", "meta": {"hexsha": "900ffbe7f262361f0b84974b66f4e3fc65b17476", "size": 411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Inverses.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.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.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 29.3571428571, "max_line_length": 71, "alphanum_fraction": 0.7542579075, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619350028205, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.6905857724248018}}
{"text": "\\subsection*{Q. 2}\n\\subsubsection*{Four-bit Parity Generator}\n\\vspace{-1.2em}\n\\begin{longtable}[c]{cccc|c}\n\\multicolumn{4}{l|}{Input 4-bit message} & \\multicolumn{1}{l}{Odd parity generator} \\\\ \\hline\n\\endfirsthead\n%\n\\endhead\n%\n\\hline\n\\endfoot\n%\n\\endlastfoot\n%\nA        & B        & C        & D       & P                                        \\\\ \\hline\n0        & 0        & 0        & 0       & 1                                        \\\\\n0        & 0        & 0        & 1       & 0                                        \\\\\n0        & 0        & 1        & 0       & 0                                        \\\\\n0        & 0        & 1        & 1       & 1                                        \\\\\n0        & 1        & 0        & 0       & 0                                        \\\\\n0        & 1        & 0        & 1       & 1                                        \\\\\n0        & 1        & 1        & 0       & 1                                        \\\\\n0        & 1        & 1        & 1       & 0                                        \\\\\n1        & 0        & 0        & 0       & 0                                        \\\\\n1        & 0        & 0        & 1       & 1                                        \\\\\n1        & 0        & 1        & 0       & 1                                        \\\\\n1        & 0        & 1        & 1       & 0                                        \\\\\n1        & 1        & 0        & 0       & 1                                        \\\\\n1        & 1        & 0        & 1       & 0                                        \\\\\n1        & 1        & 1        & 0       & 0                                        \\\\\n1        & 1        & 1        & 1       & 1                                        \\\\ \\hline\n\\end{longtable}\n\\begin{center}\n\\begin{karnaugh-map}[4][4][1][$CD$][$AB$]\n\\minterms{0,3,5,6,9,10,12,15}\n\\implicant{0}{0}\n\\implicant{3}{3}\n\\implicant{5}{5}\n\\implicant{6}{6}\n\\implicant{9}{9}\n\\implicant{10}{10}\n\\implicant{12}{12}\n\\implicant{15}{15}\n\\end{karnaugh-map}\n\\end{center}\n\\vspace{-2.5em}\n\\begin{align*}\nF(A,B,C,D)&=A'B'C'D'+A'B'CD+A'BC'D+A'BCD'+ABC'D'+ABCD+AB'C'D+AB'CD'\\\\\n&=A'D'(BC+B'C')+A'D(B'C+BC')+AD'(BC'+B'C)+AD(BC+B'C')\\\\\n&=A'D'(B\\oplus C)'+A'D(B\\oplus C)+AD'(B\\oplus C)+AD(B\\oplus C)'\\\\\n&=(A'D'+AD)(B\\oplus C)'+(A'D+AD')(B\\oplus C)\\\\\n&=(A\\oplus D)'(B\\oplus C)'+(A\\oplus D)(B\\oplus C)\\\\\n&=((A\\oplus D)\\oplus (B\\oplus C))'\n\\end{align*}\n\\centerline{\\includegraphics[width=0.4\\textwidth]{fig/f21}}\n\n\n\\subsubsection*{Three-bit Parity Checker}\n\\vspace{-1.2em}\n% Please add the following required packages to your document preamble:\n% \\usepackage{longtable}\n% Note: It may be necessary to compile the document several times to get a multi-page table to line up properly\n\\begin{longtable}[c]{cccc|c}\n\\multicolumn{4}{l|}{Input (3+1)-bit} & \\multicolumn{1}{l}{Odd parity checker} \\\\ \\hline\n\\endfirsthead\n%\n\\endhead\n%\n\\hline\n\\endfoot\n%\n\\endlastfoot\n%\nA       & B       & C       & P      & $C_P$                                   \\\\ \\hline\n0       & 0       & 0       & 0      & 1                                      \\\\\n0       & 0       & 0       & 1      & 0                                      \\\\\n0       & 0       & 1       & 0      & 0                                      \\\\\n0       & 0       & 1       & 1      & 1                                      \\\\\n0       & 1       & 0       & 0      & 0                                      \\\\\n0       & 1       & 0       & 1      & 1                                      \\\\\n0       & 1       & 1       & 0      & 1                                      \\\\\n0       & 1       & 1       & 1      & 0                                      \\\\\n1       & 0       & 0       & 0      & 0                                      \\\\\n1       & 0       & 0       & 1      & 1                                      \\\\\n1       & 0       & 1       & 0      & 1                                      \\\\\n1       & 0       & 1       & 1      & 0                                      \\\\\n1       & 1       & 0       & 0      & 1                                      \\\\\n1       & 1       & 0       & 1      & 0                                      \\\\\n1       & 1       & 1       & 0      & 0                                      \\\\\n1       & 1       & 1       & 1      & 1                                      \\\\ \\hline\n\\end{longtable}\n\\begin{center}\n\\begin{karnaugh-map}[4][4][1][$CP$][$AB$]\n\\minterms{0,3,5,6,9,10,12,15}\n\\implicant{0}{0}\n\\implicant{3}{3}\n\\implicant{5}{5}\n\\implicant{6}{6}\n\\implicant{9}{9}\n\\implicant{10}{10}\n\\implicant{12}{12}\n\\implicant{15}{15}\n\\end{karnaugh-map}\n\\end{center}\n\\vspace{-2.5em}\n\\begin{align*}\nF(A,B,C,P)&=A'B'C'P'+A'B'CP+A'BC'P+A'BCP'+ABC'P'+ABCP+AB'C'P+AB'CP'\\\\\n&=A'P'(BC+B'C')+A'P(B'C+BC')+AP'(BC'+B'C)+AP(BC+B'C')\\\\\n&=A'P'(B\\oplus C)'+A'P(B\\oplus C)+AP'(B\\oplus C)+AP(B\\oplus C)'\\\\\n&=(A'P'+AP)(B\\oplus C)'+(A'P+AP')(B\\oplus C)\\\\\n&=(A\\oplus P)'(B\\oplus C)'+(A\\oplus P)(B\\oplus C)\\\\\n&=((A\\oplus P)\\oplus (B\\oplus C))'\n\\end{align*}\n\\centerline{\\includegraphics[width=0.4\\textwidth]{fig/f22}}\n", "meta": {"hexsha": "8323f0bd1df6dafa23551384f442da950afeef45", "size": 5006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2021F/CS207/A3/q2.tex", "max_stars_repo_name": "HeZean/SUSTech-Archive", "max_stars_repo_head_hexsha": "0c89d78f232fdef427ca17b7e508881b782d7826", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2021F/CS207/A3/q2.tex", "max_issues_repo_name": "HeZean/SUSTech-Archive", "max_issues_repo_head_hexsha": "0c89d78f232fdef427ca17b7e508881b782d7826", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2021F/CS207/A3/q2.tex", "max_forks_repo_name": "HeZean/SUSTech-Archive", "max_forks_repo_head_hexsha": "0c89d78f232fdef427ca17b7e508881b782d7826", "max_forks_repo_licenses": ["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.5304347826, "max_line_length": 111, "alphanum_fraction": 0.3098282062, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6904897871709916}}
{"text": "\\documentclass{article}\n\n\\usepackage[letterpaper, margin=1.3cm]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{siunitx}\n\\usepackage[fleqn]{mathtools}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\\usepackage{datetime}\n\\newcommand\\aug{\\fboxsep=-\\fboxrule\\!\\!\\!\\fbox{\\strut}\\!\\!\\!}\n\n\\title{MATH 225 Assignment 2}\n\\author{Michael Kwok}\n\\date{2020-07-20}\n\\begin{document}\n\\maketitle\n\\subsection*{1}\nA linear transformation must be both additive and homogenous.\n\nShow that the Trace function $Tr : M_{2,2} \\rightarrow \\mathbb{R}$ is linear, i.e. $Tr(\\alpha A + \\beta B) = \\alpha Tr(A) + \\beta Tr(B)$:\n\nlet $\\alpha, \\beta \\in \\mathbb{R}$\n\nlet $A = \\begin{bmatrix}\na_1 & b_1\\\\\nc_1 & d_1\n\\end{bmatrix}$\n\nlet $B = \\begin{bmatrix}\na_2 & b_2\\\\\nc_2 & d_2\n\\end{bmatrix}$\n\n\\begin{align*}\nTr(\\alpha A + \\beta B) &= Tr\\left(\\alpha \\begin{bmatrix}\na_1 & b_1\\\\\nc_1 & d_1\n\\end{bmatrix} + \\beta \\begin{bmatrix}\na_2 & b_2\\\\\nc_2 & d_2\n\\end{bmatrix} \\right)\\\\ \n&= Tr\\left( \\begin{bmatrix}\n\\alpha a_1 + \\beta a_2 & \\alpha b_1 + \\beta b_2\\\\\n\\alpha c_1 + \\beta c_2 & \\alpha d_1 + \\beta d_2\n\\end{bmatrix} \\right)\\\\\n&= \\alpha a_1 + \\beta a_2 + \\alpha d_1 + \\beta d_2\\\\\n&= \\alpha (a_1 + d_1) + \\beta (a_2  + d_2)\\\\\n&= \\alpha Tr\\left(\\begin{bmatrix}\na_1 & b_1\\\\\nc_1 & d_1\n\\end{bmatrix}\\right) + \\beta Tr\\left(\\begin{bmatrix}\na_2 & b_2\\\\\nc_2 & d_2\n\\end{bmatrix}\\right)\\\\\n&= \\alpha Tr(A) + \\beta Tr(B)\n\\end{align*}\n\n$\\therefore$ the Trace function $Tr : M_{2,2} \\rightarrow \\mathbb{R}$ is linear\n\\newpage\n\\subsection*{2a}\n\\begin{align*}\n    p(x) &= 5(1) + 2(x-1) - (x-1)^2\\\\\n    &= 5 + 2x - 2 - x^2 + 2x - 1\\\\\n    &= 2+ 4x -x^2\n\\end{align*}\n\\subsection*{2b}\nDefine the basis set with standard bases:\n\n\\begin{align*}\nB_1 = \\begin{bmatrix}\n1\\\\\n0\\\\\n0\\\\\n\\end{bmatrix} B_2 = \\begin{bmatrix}\n-1\\\\\n1\\\\\n0\\\\\n\\end{bmatrix} B_3 = \\begin{bmatrix}\n1\\\\\n-2\\\\\n1\\\\\n\\end{bmatrix}\n\\end{align*}\n\nAugmented matrix of the system:\n\n\\begin{align*}\n\\begin{bmatrix}\n1 & -1 & 1  &\\aug & 6 \\\\\n0 & 1  & -2 &\\aug & -4\\\\\n0 & 0  & 1  &\\aug & 1\n\\end{bmatrix} \\xrightarrow{\\text{rref}} \\begin{bmatrix}\n1 & 0 & 0 &\\aug & 3 \\\\\n0 & 1 & 0 &\\aug & -2\\\\\n0 & 0 & 1 &\\aug & 1\n\\end{bmatrix}\n\\end{align*}\n\n\\begin{align*}\n[q(x)]_{\\mathcal{B}} &= \\begin{bmatrix}\n3\\\\\n-2\\\\\n1\\\\\n\\end{bmatrix}\n\\end{align*}\n\\subsection*{2c}\nValue of $C_\\mathcal{B}(a+bx^2+cx^2) = (a+b+c) + (b+2c)(x-1)+c(x-1)^2$\n\n\\begin{align*}\n    &R((a+b+c)+(b+2c)(x-1)+c(x-1)^2)\\\\\n    &= (a+b+c - b-2c) + (b+2c-c)x + (c-a-b-c) x^2\\\\\n    &= (a-c) + (b+c)x - (a + b)x^2\n\\end{align*}\n\\newpage\n\n\\subsection*{2d}\nFor the map $R \\circ C_B$ to be invertible, both the change of basis and transformation $R$ must be invertible. A change of basis by definition is invertible, so test for R.\n\nGet the transformation matrix of R by inspection: $\n\\begin{bmatrix}\n1 & -1 & 0 \\\\\n0 & 1 & -1\\\\\n-1 & 0 & 1 \n\\end{bmatrix}$\n\nGet $det(R)$ by row reduction:\n\n\\begin{align*}\ndet(R) &= det\\begin{bmatrix}\n1 & -1 & 0 \\\\\n0 & 1 & -1\\\\\n-1 & 0 & 1\n\\end{bmatrix}\\\\\n&= det\\begin{bmatrix}\n0 & -1 & 1 \\\\\n0 & 1 & -1\\\\\n-1 & 0 & 1\n\\end{bmatrix}\\\\\n&= det\\begin{bmatrix}\n0 & 0 & 0 \\\\\n0 & 1 & -1\\\\\n-1 & 0 & 1\n\\end{bmatrix}\\\\\n&= det\\begin{bmatrix}\n1 & 0 & -1 \\\\\n0 & 1 & -1\\\\\n0 & 0 & 0\n\\end{bmatrix}\n\\end{align*}\n\nSince matrix is upper triangle, determinant is product of diagonal entries:\n\\begin{align*}\n     det(R) &= 1\\cdot1\\cdot0\\\\\n     &= 0\n\\end{align*}\n\nSince the determinant of the transformation matrix is zero, the map is non invertible\n\\newpage\n\\subsection*{3a}\nLet $p(x) = a + bx + cx^2 + dx^3$.\n\n\\begin{align*}\n    E_5\\left(p\\left(x\\right)\\right) = a+5b+25c+125d\n\\end{align*}\n\nThe image of $E_5 \\text{ is all of } \\mathbb{R}$. The mapping is onto $\\mathbb{R}$ as any value in $\\mathbb{R}$ can be represented by replacing $a, b, c,\\text{or }d$ with appropriate values in $\\mathbb{R}$\n\nLet $k \\in \\mathbb{R}$.\n\nThere must exist some $q(x) \\in mathscr{P}_3$ such that $E_5(q(x)) = k$.\n\n\\begin{align*}\n\\text{Let } q(x) &= k + 0x + 0x^2 + 0x^3\\\\\nE_5(q(x)) &= k + 0\\cdot5 + 0\\cdot25 + 0\\cdot125\\\\\n&= k\n\\end{align*}\n$\\therefore$ any value $k \\in \\mathbb{R}$ can be calculated with the appropriate polynomial $q(x) \\in \\mathscr{P}_3$\n\\subsection*{3b}\n\\begin{align*}\n    rank(E_5) + nullity(E_5) &= dim(\\mathscr{P}_3)\\\\\n    1 + nullity(E_5) &= 4\\\\\n    nullity(E_5) &= 3\n\\end{align*}\n\\subsection*{3c}\n\\begin{align*}\n    \\text{Let } p(x) &= a+bx+cx^2+dx^3\\\\\n    E_5(p(x)) &= a+5b+25c+125d\\\\\n    ker(E_5) &= \\left\\{a+bx+cx^2+dx^3: a+5b+25c+125d = 0\\right\\}\n\\end{align*}\nUse $B$ to denote the basis of $ker(E_5).~B = Nul(ker(E_5))$\n\nFind Null space of the kernel.\n\nCoeffecient matrix of the kernel: $\\begin{bmatrix}\n1 &5 &25& 125\n\\end{bmatrix}$\n\nNull space of kernel: $\\left\\{\\begin{bmatrix}\n-5\\\\1 \\\\0\\\\ 0\n\\end{bmatrix}, \\begin{bmatrix}\n-25\\\\0 \\\\1\\\\ 0\n\\end{bmatrix}, \\begin{bmatrix}\n-125\\\\0 \\\\0\\\\ 1\n\\end{bmatrix}\\right\\}$\n\nBy converting the bases to a form in $\\mathbb{R}$ space, we can find the basis of the kernel.\n\\begin{align*}\n    Basis(ker(E_5)) = \\left\\{-5a+b,-25a+c,-125a+d\\right\\}\n\\end{align*}\n\\end{document}", "meta": {"hexsha": "202d9d4704e9633ee1be73e504f5e92d606bea59", "size": 4983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/MATH225/MATH225As2.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/MATH225/MATH225As2.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/MATH225/MATH225As2.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": 23.6161137441, "max_line_length": 205, "alphanum_fraction": 0.6092715232, "num_tokens": 2183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6904897856477193}}
{"text": "\\lab{Applications}{Web Page Experiments}{Web Page Experiments}\n\\objective{This lab applies multi-armed bandit problems to web page experiments.}\n\n\\section*{Web Page Experiments}\nOne application of the multi-armed bandit problem is in web page design.\nBandit problems provide a way to compare the success of different variations of a web page.\nSuppose a business wants to test new versions of a web page.\nThe goal of the page might be to get the user to click a certain link, make a purchase, etc.\nWhen the user does this, we call it a conversion.  The proportion of web page visits\nthat results in a conversion is called the conversion rate, or CvR.\nThe website designer wants to determine which variation of the web page has the best CvR.\n\nWe can model this situation as a bandit problem by considering each page as a different arm.\nEach page has some unknown probability (the CvR) that a user will perform the desired action.\nThe company then wants to experiment with giving different users different versions of\nthe page in order to determine which variation is most successful.\n\nThis method is the same that is used by Google Analytics.  Take a moment to skim their description located here:\n\\url{http://analytics.blogspot.com/2013/01/multi-armed-bandit-experiments.html}.\n\nIn this lab we will apply the Thompson Sampling method from the previous lab (the same method used by Google)\nto solve this problem.  We will simulate the results and attempt to replicate Google's results found at the website above.\n\n\\section*{The Experiment}\nHere we describe how we will design our web page experiment using bandits and how we will simulate it.\nWe will have some number of variations of a web page, $n$.  Each day, the web-page will receive 100 visitors\n(for the purposes of our simulation).  Twice each day, at the beginning and after 50 visits,\nwe will compute the number of each variation to deliver to the next 50 visitors using the weights\nmethod described in the previous lab (you should have written a function that does this in Problem 4\nof the previous algorithms lab).\n\n\\begin{problem}\nWrite a function that simulates the experiment for one day.\nThe function should accept a vector of length $n$ of the true probabilities (CvR)\nfor different web page variations.  It should also accept the state of the variations\nat the beginning of the day; this is an $n \\times 2$ array with the number of previous\nsuccesses plus one in the first column and the number of previous failures plus one in\nthe second column (so if it is the first day the state for any arm would be $(1,1)$\ncorresponding to a $Beta(1,1)$ distribution).\n\nThe function could be outlined like this: first compute how many times each variation\nshould be used in the next 50 visits.  When determining the weights you will need to use\nthe \\li{sim_data} function.  Use 100 as the number of draws here and throughout this lab.\nThen ``visit'' each page the number of times given by the weights.\nWhether each visit results in a conversion (1) or not (0) can be randomly determined using the following function:\n\\begin{lstlisting}\nimport scipy as sp\ndef pull(p):\n    return sp.random.binomial(1,p,size = None).\n\\end{lstlisting}\nThis will return a random one or zero based on the probability input \\li{p}.\n\nAfter the first 50 visits, update the state of each arm.\nThen recompute the weights and do the same for the next 50 visits, resulting in 100 visits total.\n\nThis function should return the resulting states and their corresponding weights.\n\\end{problem}\n\nIn this manner we will continue from day to day, always updating the state of each arm\n(the beta distribution for the CvR of each arm).  We will have three criteria to determine when to stop the experiment.\nThe first, is that the experiment must run at least two weeks to make sure the\nresults are not overly influenced by a small number of random draws.\n\nThe second stopping criteria is that there be a $95\\%$ probability that one of the variations is the best variation.\nThis is the same as saying that, of the weights for each variation, the largest is greater than $.95$.\n\nIt may seem that these two criteria should be enough; however, in some cases, the\nexperiment could last a very long time using just these criteria.\nFor example, consider the case that two of the web page variations have nearly the same CvR.\nIn this case it will be very difficult to determine which is best.\nIt will also not be very important since the results are so similar.\nThus we will use a measure that we will call the potential value remaining\nin the experiment as the third criteria.  The value remaining is computed by\nsimulating many draws for each arm.  Using this data, the potential value remaining\nfor arm $i$ is obtained by computing the following for each simulated data point:\n\\begin{equation}\\label{valrem}\n\\frac{\\theta_{max} - \\theta^*}{\\theta^*}\n\\end{equation}\nwhere $\\theta_{max}$ is the largest value for the random draw and $\\theta^*$ is the\nvalue of the arm that is currently believed to be the best\n(the arm with the highest weighting, or probability of being optimal).\nThe result is some distribution of numbers between $0$ and $1$ that we can think\nof as the distribution of value remaining.  For example, if $50\\%$ of the numbers are 0,\nthen about $50\\%$ of the time the arm that is currently believed optimal will perform the best.\nThe potential value remaining is the $95$th percentile of this distribution.\nIf the potential value remaining were $.2$, we could interpret it as meaning\nthat there is about a $5\\%$ chance that another arm beats the current best arm by $.2$ or more.\nWe stop the experiment if this value is less than $1\\%$ of the current best arm's CvR.\nThis way we stop the experiment if there seems to be little chance of improvement over\nthe current best arm, regardless of whether we've met the $95\\%$ tolerance for the weights.\n\nThe value remaining can be computed using the following code:\n\\begin{lstlisting}\nimport scipy as sp\ndef val_remaining(data,prob):\n    champ_ind = sp.argmax(prob)\n    thetaM = sp.amax(data,1)\n    valrem = (thetaM - data[:,champ_ind])/data[:,champ_ind]\n    pvr = sp.stats.mstats.mquantiles(valrem,.95)\n    return valrem,pvr\n\\end{lstlisting}\nwhere data is simulated using the \\li{sim_data} function from the previous algorithms lab,\nand prob is a vector containing the probabilities that each arm is optimal\n(also computed using a function from the previous lab).\n\n\\begin{problem}\nWrite a function that simulates the problem described above, using the stopping criteria described above.\nThe function should accept a vector of the true probabilities of the arms.\nIt should use the function from the previous problem to simulate each day and\ncontinue until the stopping criteria are met.\n\nThe function should return the state of each arm (i.e. an $n$ by $2$ matrix with the\nsuccesses and failures of each arm), a matrix that contains the weights assigned to\neach arm each day, the index of the winning variation, and the number of days it took to converge.\n\nYour code should have a while loop that checks for the stopping criteria after each day.\nIt might look something like this:\n\\begin{lstlisting}\nwhile ((delta < p_tol) and (champ_cvr/100. < v_quant)) or days < 14:\n\\end{lstlisting}\nwhere \\li{delta} is the largest weight for the current day, meaning if there were two arms and you determined the weights to be .9 and .1, then delta would be .9.  We stop when the largest weight is greater than .95, so \\li{p_tol} is .95.  The variables \\li{champ_cvr} and \\li{v_quant} describe the stop mechanism that accounts for the potential value remaining.  First, \\li{champ_cvr} is the conversion rate of the current best arm over the course of the experiment.  So if it has been used 100 times with 4 successes, then \\li{champ_cvr} would be .04.  The variable \\li{v_quant} is the potential value remaining, i.e. the $95$th percentile of the value remaining distribution described above.  The variable \\li{pvr} can be computed using the \\li{val_remaining} function given above.\nThe \\li{days} variable simply keeps track of how many days the experiment has been running.\n\\end{problem}\n\nNow let's see how our bandit performs with specific examples.\n\n\\begin{problem}\nSuppose a web page has two variations and the true CvR of the original is\n$.04$ and the true CvR of the new variation is $.05$.\nCreate a plot similar to \\ref{fig:weights1} that shows how the weights\nassigned to the pages changes from day to day until the optimal page is chosen and the experiment stops.\n\nNext run the same simulation 200 times and keep track of how many days\nthe experiment took in each case.  Create a histogram that shows the\nnumber of days it takes to complete the experiment.\nThe following code will create such a histogram:\n\\begin{lstlisting}\nimport scipy as sp\nfrom matplotlib import pyplot as plt\nhist, bins = sp.histogram(dayvec, bins = 12)\nwidth = (bins[1]-bins[0])\ncenter = (bins[:-1]+bins[1:]) / 2\nplt.bar(center, hist, align = 'center', width = width, color = 'g')\nplt.show()\n\\end{lstlisting}\nwhere \\li{dayvec} is a vector containing the number of days each simulation took to complete.\nAlso track which arm is determined to be optimal in each simulation.\nWhat percent of the time did the bandit find the optimal arm?\n\nCreate the same two types of plots, this time with six variations having\nweights $.04,.02,.03,.035,.045,.05$.  This time only run the simulation 100 times.\nWhat percent of the time did the bandit find the optimal arm in this case?\n\\end{problem}\n\n\\begin{figure}[h]\n\\centering\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{weights1.pdf}\n\\caption{Optimal arm probabilities in the two arm case}\n\\label{fig:weights1}\n\\end{subfigure}\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{weights2.pdf}\n\\caption{Optimal arm probabilities in the six arm case}\n\\label{fig:weights2}\n\\end{subfigure}\n\\end{figure}\n\n% \\begin{figure}[h]\n% \\centering\n% \\includegraphics[width=\\textwidth]{weights2.pdf}\n% \\caption{Optimal arm probabilities in the six arm case}\n% \\label{fig:weights2}\n% \\end{figure}\n\n\n\\section*{Comparison with Classical Tests}\nA more classical approach to this problem would be to split traffic between each\nvariation for a predetermined amount of time, which should give enough data to\ndetermine the best arm with some level of confidence.\nUsing the bandit approach described here has significant advantages over a classical test.\nThere are two main reasons why the bandit approach is more efficient.\n\nThe first reason is that the bandit method generally converges more quickly.\nA standard test would require splitting the web page views between the different\nvariations over a long period of time.  According to Google's explanation in the\nwebsite mentioned at the beginning of this lab, the two arm case would take 223 days\nand the 6 arm case would take 919 days.  The results from the simulations you performed\nshould show that on average the bandit method finishes much faster.\nThere are other ways we could choose our stopping criteria that may result in even shorter experiment times.\nIn general, we can always adjust the tolerance of our stopping criteria to shorten experiment time or increase accuracy.\n\nThe second reason the bandit approach is more efficient is that, as we gain more information,\nwe allocate more visits to the variation that we believe has a better CvR.\nIn the classical method we would split the visits evenly until the end of the experiment.\nThis way we gain many more conversions during testing than we would using classical tests.\n", "meta": {"hexsha": "1d2eb3bc9e0c6c4c4d395ad8704860e0afb2d065", "size": 11605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/MarkDecProc/Web_Exper.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/MarkDecProc/Web_Exper.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/MarkDecProc/Web_Exper.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": 58.3165829146, "max_line_length": 784, "alphanum_fraction": 0.7808703145, "num_tokens": 2701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.690489778701172}}
{"text": "\n\\subsection{Breadth-first search}\n\nA breadth-first search operates First-in First-out (FiFo). That is, it selects the oldest frontier node. This results in a broad, rather than a deep search. Once all branches have been explored, the algorithm will move deeper. Path cost is not considered in this algorithm.\n\nInformed: No\n\nTime: \\(O(b^d)\\)\n\nSpace: \\(O(b^d)\\)\n\nComplete: Yes\n\nOptimal: Picks the shallowest solution. Optimal of path costs are identical.\n\n", "meta": {"hexsha": "906c7a21db3030872324b9560b05f580134892f3", "size": 455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/nodes/02-01-BFS.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/nodes/02-01-BFS.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/nodes/02-01-BFS.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.4375, "max_line_length": 273, "alphanum_fraction": 0.756043956, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6904897732778968}}
{"text": "\\documentclass[11pt,a4]{article}\n\n\n% PACKAGES ----------\n\\usepackage[utf8]{inputenc} \\usepackage{amsmath,amsfonts,amssymb}\n\\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2cm]{geometry}\n\\usepackage{xcolor} \\usepackage{graphicx} \\usepackage{hyperref}\n\\usepackage[lite]{mtpro2}\n\n\n% MACROS ------\n\\newcommand{\\ket}[1]{\\left\\vert #1 \\right\\rangle}\n\\newcommand{\\bra}[1]{\\left\\langle #1 \\right\\vert}\n\\newcommand{\\braket}[2]{\\left\\langle #1 \\middle\\vert #2\\right\\rangle}\n\\newcommand{\\commut}[1]{\\left[#1\\right]}\n\\newcommand{\\de}{\\mathrm{d}}\n\\newcommand{\\dx}{\\de x}\n\\newcommand{\\tdev}[2]{\\frac{\\de #1}{\\de #2}}\n\\newcommand{\\pdev}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\tdevzero}[1]{\\left.\\tdev{}{#1}\\right\\vert_{#1 = 0}}\n\\newcommand{\\set}[1]{\\left\\{#1\\right\\}}\n% DOCUMENT INFO ----------\n\\title{Why is momentum the generator of translations?}\n\\author{Santiago Quintero de los Ríos\\\\{\\small for homotopico.com}} \\date{\\today}\n\n% BEGIN DOCUMENT ----------\n\n\\begin{document}\n\\maketitle\n\nIn quantum mechanics, it is often stated that \\emph{the momentum [operator] is the generator of translations}. However, most texts fail to give a satisfactory justification to this claim, if any is given at all. In some cases, the proof is simply begging the question. In others, the burden of proof is shifted to classical mechanics, stating that ``this was already proved in classical mechanics''. Again, most standard texts of classical mechanics fail to give a clear proof of this claim, although the mathematical apparatus is there. What we will do here is define \\emph{precisely} what it means for observable to be a generator of a group of transformations, both in quantum and classical mechanics, and prove that, indeed, the momentum observable \\emph{is} the generator of translations in classical mechanics.\n\n\n\\section*{The origin of the question}\n\\label{sec:origin-question}\n\nWe define the translation operator $\\hat{T}_a$ acting on elements $\\psi\\in L^2(\\mathbb{R})$ (the Hilbert space of square-integrable complex functions\nover $\\mathbb{R}$) by,\nof course, translating the wavefunction a distance $a$ to the right:\n\\begin{equation}\n  (\\hat{T}_a\\psi)(x) := \\psi(x-a).\n\\end{equation}\nThis operator is actually a whole family of operators that depend on the parameter $a$.\nIt is clear that $\\hat{T}_0$ is the identity operator. Now since this family of operators\nis particularly well-behaved\\footnote{That is, it is a one-parameter absolutely continuous group.}, it has an\n\\textbf{infinitesimal generator}, which is some operator $\\hat{w}$ such that\n\\begin{equation}\n  \\label{eq:1}\n  \\hat{T}_a = \\exp\\left(-ia\\hat{w}\\right).\n\\end{equation}\nYes, I know that the standard name for this generator is $\\hat{p}$, but\nI am trying to remove any possible meaning to this operator. For the time being, we only\nknow that $\\hat{w}$ is the generator of translations. That's why I don't call it $\\hat{p}$.\n\nWhat does $\\hat{w}$ look like? One way to calculate the infinitesimal generator of a family of operators is\nby evaluating the derivative at $a=0$. If we expand the right-hand side of equation \\ref{eq:1} as a power series, then\n\\begin{equation}\n  \\label{eq:3}\n  \\exp\\left(-ia\\hat{w}\\right) = \\sum_{n=0}^{\\infty}\\frac{1}{n!}(-ia\\hat{w})^n,\n\\end{equation}\nthen it follows that\n\\begin{equation}\n  \\label{eq:4}\n  \\tdevzero{a}\\hat{T}_a = \\tdevzero{a} \\exp\\left(-ia\\hat{w}\\right) = -i\\hat{w}.\n\\end{equation}\nSo let $\\psi$ be any function on $L^2(\\mathbb{R})$. We have that\n\\begin{equation}\n  \\tdevzero{a}\\hat{T}_a\\psi(x) = \\tdevzero{a}\\psi(x-a) = -\\tdev{}{x}\\psi(x),\n\\end{equation}\nso we can say that the infinitesimal generator is\n\\begin{equation}\n  \\label{eq:5}\n  \\hat{w} = -i\\tdev{}{x}.\n\\end{equation}\nAnd hey, look at that. It turns out that this is what we call the momentum operator in quantum mechanics.\n\nHowever, it is not clear \\textbf{at all} why the operator $-i\\tdev{}{x}$ should be given the highly suggestive name of ``momentum''. So\nthis it's not that the generator of translations is momentum because it has\nthe form $-i\\tdev{}{x}$, but the other way around:\n\nWe say that $-i\\tdev{}{x}$ is the momentum operator, because it is the one that generates translations.\n\nTherefore, the question is shifted: \\textbf{Why do we give the name ``momentum'' to the operator that generates translations?}\n\n\\section*{The usual answers}\n\\label{sec:first-answer}\n\nIf you only want a half-plausible argument, here it goes. Let $\\hat{x}$ be the position operator, that is\nthe expectation value $\\braket{\\psi}{\\hat{x}\\psi}$ is the expected value for the position of a particle in\nstate $\\psi$. It can be shown that the position operator acts on wavefunctions by multiplication by the variable\n$x$, i.e.\n\\begin{equation}\n  (\\hat{x}\\psi)(x)=x\\psi(x).\n\\end{equation}\nThis equation can also be used to define $\\hat{x}$. Now we want to compute the commutator $\\commut{\\hat{x},\\hat{w}}$.\nOn one hand, we have:\n\\begin{equation}\n  (\\hat{x}\\hat{w}\\psi)(x) = -ix\\tdev{}{x}\\psi(x),\n\\end{equation}\nbut on the other hand,\n\\begin{equation}\n  (\\hat{w}\\hat{x}\\psi)(x) = -i\\tdev{}{x}\\left(x\\psi(x)\\right) = -i\\left(\\psi(x) + x\\tdev{}{x}\\psi(x)\\right).\n\\end{equation}\nThen, clearly\n\\begin{equation}\n  \\commut{\\hat{x},\\hat{w}}\\psi(x) = i\\psi(x),\n\\end{equation}\nand so $\\commut{\\hat{x},\\hat{w}}=i\\hat{I}$. Now we consider the ``quantization rule'' that\nturns \\emph{classical} observables $f$ into Hermitian operators $\\hat{f}$ and that turns Poisson brackets\n\\emph{almost} into Lie brackets \n\\begin{equation}\n  \\set{f,g} \\mapsto i\\commut{\\hat{f},\\hat{g}},\n\\end{equation}\nand what we do is go backwards! We found an operator $\\hat{w}$ that satisfies the commutation relation\n$\\commut{\\hat{x},\\hat{w}}=i\\hat{I}$, so the \\emph{classical} observables they come from satisfy the Poisson-bracket\nrelation $\\set{x,w}=1$. We know that $\\hat{x}$ is the position operator, so $x$ must be the position observable. On the other\nhand, we know that for the canonical momentum $p$,\n\\begin{equation}\n  \\set{x,p} = \\pdev{x}{x} \\pdev{p}{p}-\\pdev{x}{p} \\pdev{p}{x} = 1.\n\\end{equation}\nWe can clearly see that $\\set{x,p}=\\set{x,w}=1$, so this suggests that $w=p$! And we're done. $w$ is the momentum, so the operator\n$\\hat{w}$ is the momentum operator.\n\n\\textbf{But wait a minute...}\n\nThe relation\n\\begin{equation}\n  \\set{x,w} = 1\n\\end{equation}\nis not enough to \\emph{define} $w$! This is because the operator $f\\mapsto\\set{x,f}$ is degenerate. As a trivial example,\n\\begin{equation}\n  \\set{x,p+x} = 1,\n\\end{equation}\nand actually, for any function $f(x)$ that \\emph{does not depend on }$p$, it follows that\n\\begin{equation}\n  \\set{x,p+f(x)}=1.\n\\end{equation}\nThis means that $w$ is an observable of the form $ w = p + f(x)$ for \\emph{some} function $f(x)$.\nAt this point you might think ``eh, close enough''. And fair enough, then you're done!\n\nBut I'm not thoroughly (actually, not at all) satisfied. There is another clue though. This previous\nargument is one of two that I've seen in QM books. The other one is as follows:\n\\begin{center}\n  \\textit{In classical mechanics it is shown that momentum is the generator of\n    translations.}\n\\end{center}\nAnd well, yes, that could be enough for our purposes. We can't expect\nevery new theory to work out of the box and be able to stand by itself, right? When\nwe construct a new theory from a mathematical perspective, we look back to\nother theories that are well-established and we understand, look for analogies and\nsimilarities, and interpret the symbols in such a way that everything is as consistent\nas possible with what came before.\n\nTherefore it is quite reasonable to say that this operator $\\hat{w}$ is the momentum operator if\nwe already know from classical mechanics that the generator of translations is the momentum. We've shown that\nin quantum mechanics, translations \\emph{also} have infinitesimal generators, so it is natural\nto interpret those as momenta.\n\nAgain, that is \\textbf{if} we already know from classical mechanics that momentum is the generator of translations.\nAnd I think I missed that lecture? That's a big ``if''.\n\nThat quote up there shifts the burden of proof to classical mechanics. So what we're going to do is plunge into classical mechanics\nand try to show that momentum is the generator of translations from two different points of view: the ``standard'' Goldstein point-of-view, and the\nmore modern symplectic geometry point-of-view. We will see from both that we can reasonably show that, in a certain way, momentum\nis the generator of translations.\n\n\\section*{The standard point of view}\n\\label{sec:standard-pov}\n\nMore precisely, what we will prove is the following:\\\\\nTo each (classical) observable $f$ we can \\emph{canonically} assign a one-parameter group\nof \\emph{canonical} transformations $\\Phi_a$ that preserve $f$. In this case, we say that $f$ generates $\\Phi_a$. When we choose the canonical momentum $f=p$, the\nresulting transformations are translations, and thus we say that $p$ is the generator of translations.\n\nIn this first section, we will do it in a bit of a dirty way. If infinitesimals make you uncomfortable (completely understandable), then\nalways note that when we write, e.g. $\\tilde{x} = x + \\epsilon X$, what we mean is that $\\tilde{x}=\\tilde{x}(\\epsilon)$ is a function of $\\epsilon$, that $\\tilde{x}(0)=x$, and $X = \\lim_{\\epsilon\\to 0}\\frac{1}{\\epsilon}\\tilde{x}(\\epsilon)$. If you would like to see a more concise proof that requires a bit of differential topology, skip to the next section.\n\nConsider some system with phase space $\\mathcal{S}$, with canonical coordinates $q^i,p_j$, and let $f$ be an arbitrary observable. We want to find a \\emph{canonical} transformation\\footnote{And an additional question that I would like to explore is ``what's the huge deal about canonical transformations''? We know that they preserve the structure of the Hamilton-Jacobi equations, but not necessarily the Hamiltonian, so that doesn't seem like much, does it? Well it turns out that the \\emph{structure} itself of the equations has an interesting and beautiful mathematical background... But I'm saving that for later. }\n$Q^i = Q^i(q,p)$, $P_j = P_j(q,p)$ that preserves $f$ and depends on only one parameter $\\epsilon$. For small $\\epsilon$, we can write\n\\begin{equation}\n  \\begin{aligned}\n    Q^i(\\epsilon) &= q^i + \\epsilon A^i\\\\\n    P_j(\\epsilon) &= p_j + \\epsilon B_j\n  \\end{aligned},\n\\end{equation}\nwith $A^i,B_j$ functions of $q,p$ that we want to determine. Since we want these transformations to be canonical, the Poisson brackets must be conserved, so\n\\begin{equation}\n  \\begin{aligned}\n    \\set{q^i,p_i} = 1 &= \\set{Q^i,P_i} \\\\\n    &= \\set{q^i + \\epsilon A^i,p_i + \\epsilon B_i}\\\\\n    &= \\set{q^i,p_i} + \\epsilon\\left(\\set{A^i,p_i}+\\set{q^i,B_i}\\right) + \\mathcal{O}(\\epsilon^2).\n  \\end{aligned}\n\\end{equation}\nThen, working up to first order in $\\epsilon$, we require that\n\\begin{equation}\n  \\set{A^i,p_i}+\\set{q^i,B_i} = 0.\n\\end{equation}\nUnravel these Poisson brackets,\n\\begin{equation}\n  \\set{A^i,p_i} = \\sum_k\\left(\\pdev{A^i}{q^k}\\pdev{p_i}{p_k} - \\pdev{A^i}{p_k}\\pdev{p_i}{q^k}\\right) = \\pdev{A^i}{q^i}\n\\end{equation}\n\\begin{equation}\n  \\set{q^i,B_i} = \\sum_k\\left(\\pdev{q^i}{q^k}\\pdev{B_i}{p_k} - \\pdev{q^i}{p_k}\\pdev{B_i}{q^k}\\right) = \\pdev{B_i}{p_i},\n\\end{equation}\nthen we require $A^i,B_i$ to be such that\n\\begin{equation}\n  \\label{eq:2}\n  \\pdev{A^i}{q^i} + \\pdev{B_i}{p_i} = 0.\n\\end{equation}\nOne way to guarantee that condition \\eqref{eq:2} is satisfied is by finding some \\emph{other} observable, say $g$, and write\n\\begin{equation}\n  \\label{eq:7}\n  \\begin{aligned}\n    A^i &= \\pdev{g}{p_i}\\\\\n    B_j &= -\\pdev{g}{q^j}\n  \\end{aligned}.\n\\end{equation}\nHowever, not every $g$ will work, since we also require the transformation to preserve the observable $f$. So again, for small\n$\\epsilon$, we can write\n\\begin{equation}\n  \\begin{aligned}\n    f\\left(Q^i,P_j \\right) &= f\\left(q^i+\\epsilon A^i,p_j+\\epsilon B_j\\right)\\\\\n    &= f\\left(q^i,p_j\\right) + \\epsilon\\sum_k\\left(A^k\\pdev{f}{q^k} + B_k\\pdev{f}{p_k}\\right) + \\mathcal{O}(\\epsilon^2).\n\\end{aligned}\n\\end{equation}\nSince we require the transformation to preserve $f$, then $f\\left(Q^i,P_j \\right) = f(q^i,p_j)$ and thus\n\\begin{equation}\n  \\label{eq:6}\n  \\sum_k\\left(A^k\\pdev{f}{q^k} + B_k\\pdev{f}{p_k}\\right) = 0.\n\\end{equation}\nBut again, if we assume that $A^i,B_j$ come from an observable $g$ as in equation \\eqref{eq:7}, this condition\nbecomes\n\\begin{equation}\n  \\label{eq:6}\n  \\sum_k\\left(\\pdev{g}{p^k}\\pdev{f}{q^k} - \\pdev{g}{q^k}\\pdev{f}{p_k}\\right) = \\set{f,g}=0.\n\\end{equation}\nTherefore the admissible observables $g$ that can be used for equation \\eqref{eq:7} are such that $\\set{f,g}=0$.\nWhich one is the \\emph{absolute simplest one} to choose? Well $f$ itself! This works since $\\set{f,f}=0$.\nTherefore the \\emph{natural} choice is $g=f$, so that the transformation \\emph{for infinitesimal} $\\epsilon$ is\n\\begin{equation}\n  \\label{eq:8}\n  \\begin{aligned}\n    Q^i(\\epsilon) &= q^i + \\epsilon \\pdev{f}{p^i}\\\\\n    P_j(\\epsilon) &= p_j - \\epsilon \\pdev{f}{q^j}\n  \\end{aligned}.\n\\end{equation}\nThis equation only holds for infinitesimally small $\\epsilon$, since we've been working only up to first order. What we want now is to write the exact solution  to large $\\epsilon$. To do so, note that equation~\\eqref{eq:8}\ngives us a \\emph{differential equation} for $Q$ and $P$: writing $q^i=Q^i(0), p_j=P_j(0)$, it can be easily seen that\n\\begin{equation}\n  \\label{eq:13}\n  \\begin{aligned}\n    \\tdev{Q^i}{\\epsilon} &= \\pdev{f}{p^i}\\\\\n    \\tdev{P_j}{\\epsilon} &= -\\pdev{f}{q^j}.\n  \\end{aligned}\n\\end{equation}\nNote that these are just like the Hamilton-Jacobi equations, except that ``time'' is $\\epsilon$ and the ``Hamiltonian''\nis $f$!\n\nNow we see how any general observable\nchanges when we do an infinitesimal transformation \\eqref{eq:8}. Let $g$ be any observable. Then,\nif we start at a point $(q_0,p_0)$, and write $(q_1,p_1)=(Q(\\epsilon),P(\\epsilon))$ (I'm dropping the $i,j$ indices), then\n\\begin{equation}\n  \\label{eq:9}\n    \\begin{aligned}\n    g\\left(Q^i(\\epsilon),P_j(\\epsilon) \\right) &= g\\left(q_0^i+\\epsilon \\left.\\pdev{f}{p_{j}}\\right|_{(q_0,p_0)},p_{0,j}-\\left.\\pdev{f}{q^j}\\right|_{(q_0,p_0)}\\right)\\\\\n    g(q_1,p_1)&= g\\left(q_0,p_{0}\\right) + \\epsilon\\sum_k\\left(\\left.\\pdev{f}{p_{k}}\\right|_{(q_0,p_0)}\\left.\\pdev{g}{q^k}\\right|_{(q_0,p_0)} - \\left.\\pdev{f}{q^k}\\right|_{(q_0,p_0)}\\left.\\pdev{g}{p_k}\\right|_{(q_0,p_0)}\\right) + \\mathcal{O}(\\epsilon^2)\\\\\n    g(q_1,p_1)&= g\\left(q_0,p_{0}\\right) + \\epsilon\\left.\\set{g,f}\\right|_{(q_0,p_0)} +\\mathcal{O}(\\epsilon^2).\n\\end{aligned}\n\\end{equation}\nHow do we go to large $\\epsilon$? Well, the last equation tells us that\n\\begin{equation}\n  \\tdev{}{\\epsilon}g\\left(Q(\\epsilon),P(\\epsilon)\\right) = \\set{g,f}_{Q(\\epsilon),P(\\epsilon)},\n\\end{equation}\ntherefore, if we write $g(\\epsilon) = g(Q(\\epsilon),P(\\epsilon))$, taking the derivative with respect to $\\epsilon$ again we obtain:\n\\begin{equation}\n  \\tdev{^2}{\\epsilon^2}g\\left(\\epsilon\\right) = \\tdev{}{\\epsilon}\\set{g,f}_\\epsilon = \\set{\\set{g,f},f}_\\epsilon.\n\\end{equation}\nSo if we call $X_f$ the differential operator $X_f(g):=\\set{g,f}$, we can see that\n\\begin{equation}\n  \\tdev{^n}{\\epsilon^n}g\\left(\\epsilon\\right) = X_f(X_f(\\dots X_f(g)))_{\\epsilon}={X_f}^n(g)_{\\epsilon}.\n\\end{equation}\nAnd thus, by Taylor-expanding $g$ with respect to $\\epsilon$ around $\\epsilon=0$, we see that\n\\begin{equation}\n  \\label{eq:12}\n  g(\\epsilon) = \\sum_{n=0}^{\\infty}\\frac{1}{n!}\\left.\\tdev{^n}{\\epsilon^n}\\right|_{\\epsilon=0}g(\\epsilon) = \\sum_{n=0}^{\\infty}\\frac{1}{n!}{X_f}^n(g)_{(q_0,p_0)} = \\exp\\left(\\epsilon {X_f}(0)\\right)g.\n\\end{equation}\nWe call $X_f$ the \\textbf{infinitesimal generator} associated to $f$.\n\nAlright. We should stop here for a bit and gather what we have. We have shown that for any observable $f$, we can find a family of\ncanonical transformations, which we write as $Q(\\epsilon),P(\\epsilon)$, given by the set of Hamilton-Jacobi-like equations~\\eqref{eq:13}.\nNote that if we fix a starting point $(q_0,p_0)$, this family of transformations gives rise to a \\emph{curve} in phase space, given by\n$q= Q(\\epsilon),p=P(\\epsilon)$.\nAny other observable $g$ also changes along this curve as $g(\\epsilon) = \\exp(\\epsilon X_f(0))g$, or rather as $\\tdev{g}{\\epsilon}=\\set{g,f}$.\nIn particular, $f$ is constant along this curve, since $\\tdev{}{\\epsilon}f = \\set{f,f}=0$. Therefore the family of transformations is\ncanonical and preserves $f$, as was desired.\n\nNow here comes what was promised. If we choose $f=p_j$, the momentum observable, then the infinitesimal\ngenerator associated to $p_j$, $X_{p_j}$, is the differential operator\n\\begin{equation}\n  X_{p_j}(g) = \\set{g,p_j} = \\sum_{k}\\pdev{g}{q^k}\\pdev{p_j}{p_k} - \\pdev{g}{p_k}\\pdev{p_j}{q^k} = \\pdev{}{q^j}(g).\n\\end{equation}\nRing any bells?\n\nFurthermore, the family of transformations is the solution to the Hamilton-Jacobi-like equations~\\eqref{eq:13} with $f=p_j$, i.e.\n\\begin{equation}\n  \\label{eq:14}\n  \\begin{aligned}\n    \\tdev{Q^i}{\\epsilon} &= \\pdev{p_j}{p^i} = \\delta^i_j\\\\\n    \\tdev{P_k}{\\epsilon} &= -\\pdev{p_j}{q^k} = 0,\n  \\end{aligned}\n\\end{equation}\nwhich is readily integrated, given an initial point $q_0 = Q(0),p_0=P(0)$:\n\\begin{equation}\n  Q^j(\\epsilon) = q_{0}^j + \\epsilon;\n\\end{equation}\nand all the other coordinates constant. This is indeed a translation in the $j$-th space coordinate.\n\nSo there you have it! In classical mechanics, to each observable $f$ we assign a differential operator $X_f$ that\ngenerates one-parameter canonical transformations that preserve $f$. In the case where $f=p$, the differential operator is $X_p = \\pdev{}{q}$,\nand the canonical transformations are translations! Therefore we say that \\textbf{momentum is the generator of translations}.\n\n\\section*{The mathematician's way}\n\\label{sec:mathematicians-way}\n\nThis way is basically exactly the same as the one before, just with the more sophisticated language\nof differential topology, specifically in the context of symplectic manifolds. It can be easily seen\nthat the results given here are exactly the same as the results given in the previous section, when\nwe write them in Darboux coordinates.\n\nSo first, some definitions.\n\nA \\textbf{symplectic manifold} is a smooth manifold $\\mathcal{M}$ of dimension $2n$ endowed with a closed, non-degenerate $2$-form $\\omega$, which we call a \\textbf{symplectic form}. It can be shown that for each point\n$x\\in \\mathcal{M}$ there exists a neighborhood $U$ of $x$ and coordinates $q^1,\\dots,q^n,p_1,\\dots,p_n$ such\nthat the symplectic form can be written as\n\\begin{equation}\n  \\label{eq:11}\n  \\omega = \\de q^{\\mu}\\wedge\\de p_{\\mu}.\n\\end{equation}\nHere we are using Einstein's sum notation. This result is \\textbf{Darboux's theorem}, and the coordinates $(q^\\mu,p_\\mu)$ are called \\textbf{Darboux coordinates}.\n\n\nSince\n$\\omega$ is non-degenerate, it induces an isomorphism $(-)_\\flat:T_p\\mathcal{M}\\to T_p^*\\mathcal{M}$, given\npointwise by the relation\n\\begin{equation}\n  \\label{eq:10}\n  v_\\flat(u):=\\omega(v,u)\n\\end{equation}\nfor all $u,v\\in T_p\\mathcal{M}$ and all $p\\in\\mathcal{M}$. The inverse of $(-)_\\flat$ is denoted\nby $(-)^\\sharp:T_p^*\\mathcal{M}\\to T_p\\mathcal{M}$.\n\nThis is basically all we need! Let $f\\in C^{\\infty}(\\mathcal{M})$. Then we can define the \\textbf{Hamiltonian vector field associated to $f$}, denoted by $X_f\\in\\mathfrak{X}(\\mathcal{M})$, as\n\\begin{equation}\n  \\label{eq:15}\n  X_f = (\\de f)^{\\sharp}.\n\\end{equation}\nBy this definition, for any other vector field $Y$, we have that\n\\begin{equation}\n  \\label{eq:16}\n  \\omega(X_f,Y) = \\de f(Y)= Y[f].\n\\end{equation}\nTherefore an alternative definition for $X_f$ is the unique vector field such that $\\iota_{X_f}\\omega = \\de f$.\n\nUsing Cartan's magic formula, we see that\n\\begin{equation}\n  \\label{eq:17}\n  L_{X_f}\\omega = \\iota_{X_f}(\\de\\omega) + \\de\\left(\\iota_{X_f}\\omega\\right) = 0.\n\\end{equation}\nHere, the first term is zero since $\\omega$ is closed (i.e. $\\de\\omega=0$), and the second one is zero too since $\\iota_{X_f}\\omega=\\de f$, and $\\de^2=0$. In addition to this, the directional derivative of $f$ along $X_f$ is zero, since\n\\begin{equation}\n  \\label{eq:19}\n  X_f(f) = \\de f(X_f) = \\iota_{X_f}\\omega(X_f)=\\omega(X_f,X_f)=0.\n\\end{equation}\nThis means that if $\\Phi^f_\\tau$ is the flow of $X_f$, then\nfor all values of $\\tau$\n\\begin{equation}\n  \\label{eq:18}\n  \\left(\\Phi^f_{\\tau}\\right)^*\\omega = \\omega,\n\\end{equation}\nand $f\\circ\\Phi^f_\\tau = f$. That is, neither $f$ nor $\\omega$ change along the integral curves of the Hamiltonian vector field associated to $f$.\n\nFurthermore, since $\\Phi^f_{\\tau}:\\mathcal{M}\\to\\mathcal{M}$ is a diffeomorphism, then it satisfies the conditions for being a \\textbf{symplectomorphism} or \\textbf{canonical transformation}. Namely, a diffeomorphism $f:\\mathcal{M}\\to\\mathcal{N}$ between two symplectic manifolds $(\\mathcal{M},\\omega)$ and $(\\mathcal{N},\\Omega)$ is a symplectomorphism if $f^*\\Omega=\\omega$.\n\nWhat we have now is the following: to any $f\\in C^\\infty(\\mathcal{M})$ we can assign a Hamiltonian vector field $X_f\\in \\mathfrak{X}(\\mathcal{M})$ whose flow $\\Phi^f_\\tau$ is a symplectomorphism that preserves $f$. Now if we work locally in Darboux coordinates $(q^\\mu,p_\\mu)$, so that $\\omega = \\de q^\\mu\\wedge \\de p_\\mu$. If\nwe write $X_f$ locally as\n\\begin{equation}\n  \\label{eq:20}\n  X_f = A^\\mu\\pdev{}{q^\\mu} + B_{\\nu}\\pdev{}{p_\\nu},\n\\end{equation}\nthen we have that\n\\begin{equation}\n  \\label{eq:21}\n  \\begin{aligned}\n    \\iota_{X_f}\\omega &= \\iota_{X_f}\\left(\\de q^\\mu\\wedge \\de p_\\mu\\right)\\\\\n    &= \\de q^\\mu(X_f)\\de p_\\mu - \\de q^\\mu\\de p_\\mu(X_f)\\\\\n    &= A^\\mu\\de p_\\mu - B_\\mu\\de q^\\mu = \\de f.\n  \\end{aligned}\n\\end{equation}\nHowever, since\n\\begin{equation*}\n  \\de f = \\pdev{f}{q^\\mu}\\de q^\\mu + \\pdev{f}{p_\\mu}\\de p_\\mu,\n\\end{equation*}\nthen necessarily the components of $X_f$ must be\n\\begin{equation}\n  \\label{eq:22}\n  \\begin{aligned}\n    A^\\mu &= \\pdev{f}{p_\\mu}\\\\\n    B_\\mu &= -\\pdev{f}{q^\\mu}\\\\\n  \\end{aligned}.\n\\end{equation}\nThe Hamiltonian vector field associated to $f$ is then, in Darboux coordinates,\n\\begin{equation}\n  \\label{eq:23}\n  X_f = \\pdev{f}{p_\\mu}\\pdev{}{q^\\mu} -\\pdev{f}{q^\\mu}\\pdev{}{p_\\mu} = \\set{-,f}.\n\\end{equation}\n\nAnd once again, if we choose $p_\\nu =f$, then the Hamiltonian vector field is\n\\begin{equation}\n  \\label{eq:24}\n  X_{p_\\nu} = \\pdev{}{q^\\nu},\n\\end{equation}\nSo that the flow of $X_{p_\\nu}$ is simply translation along the $q^\\nu$ coordinate. Once again, we can\nsay that the [Hamiltonian vector field associated to the] canonical momentum is the generator of translations.\n\n\\section*{The takeaway}\n\\label{sec:takeaway}\n\nWe proved a general result in classical mechanics: to any observable $f$, we can assign a differential\noperator $X_f=\\set{-,f}$, called the infinitesimal generator or Hamiltonian vector field associated to $f$,\nthat \\emph{generates} canonical transformations that preserve $f$. The one-parameter group of\ncanonical transformations associated to $X_f$ is given by $\\Phi^f_\\tau = \\exp(\\tau X_f)$, and we\nsay that $f$ is the generator of $\\Phi^f$.\n\nIn particular, if we choose the canonical momentum $p$ to be the observable $f$, then the infinitesimal generator is $X_p = \\tdev{}{q}$ and the group of canonical transformations associated to $X_p$ is precisely the group of translations of the $q$ coordinate.\nTherefore, we can say that \\textbf{the momentum is the generator of translations}.\n\nNow in quantum mechanics, we simply \\textbf{define} the momentum operator $\\hat{p}$ to be the infinitesimal\ngenerator of the unitary group of translations, and we see that this definition is consistent with canonical\nquantization.\n\n\\subsection*{References}\n\\label{sec:references}\n\n\\begin{itemize}\n\\item Sakurai, J. J. (1995). \\textit{Modern Quantum Mechanics, Revised Edition}.\n\\item Goldstein, H. , Poole, C. \\& Safko, J. (2001). \\textit{Classical Mechanics, Third Edition}.\n\\item José, J. V. \\& Saletan, E. (1998). \\textit{Classical Dynamics: A Contemporary Approach}. This book is great. I love it. Read it.\n\\item Abraham, R. \\& Marsden, J. (2008). \\textit{Foundations of Mechanics}.\n\\end{itemize}\nGreat thanks to Laura Arboleda for checking style and consistency.\n\\end{document}\n\n% END DOCUMENT ----------\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "77c971d865daea3a23ee7528c080904c4d66f99b", "size": 24238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/docs/pdf_posts/momentum_generator_translations.tex", "max_stars_repo_name": "squinterodlr/squinterodlr.github.io", "max_stars_repo_head_hexsha": "578f39516956855b66b58801b6ba167428dd8c34", "max_stars_repo_licenses": ["MIT"], "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/docs/pdf_posts/momentum_generator_translations.tex", "max_issues_repo_name": "squinterodlr/squinterodlr.github.io", "max_issues_repo_head_hexsha": "578f39516956855b66b58801b6ba167428dd8c34", "max_issues_repo_licenses": ["MIT"], "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/docs/pdf_posts/momentum_generator_translations.tex", "max_forks_repo_name": "squinterodlr/squinterodlr.github.io", "max_forks_repo_head_hexsha": "578f39516956855b66b58801b6ba167428dd8c34", "max_forks_repo_licenses": ["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.6913043478, "max_line_length": 816, "alphanum_fraction": 0.7061638749, "num_tokens": 7826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6904897663313493}}
{"text": "\\section{Functions on Euclidean Space}\n\\textbf{NOTE:} My notes differ from Spivak's text in that I use subscripts to denote\ncomponents instead of superscripts.\n\n\\subsection{Norm and Inner Product}\n\n\\subsubsection{Exercise 1}\n\\begin{align*}\n        \\sum_{i = 1}^n x_i^2  = \\sum_{i = 1}^n \\abs{x_i}^2 \\leq \\bigg(\\sum_{i = 1}^n \\abs{x_i}\\bigg)^2 \n        \\implies \\sqrt{\\sum_{i = 1}^n x_i^2} \\leq \\sum_{i = 1}^n \\abs{x_i}^2 \n\\end{align*}\n\n\\subsubsection{Exercise 2}\nWe need $\\sum_{i = 1}^n x_i y_i = \\abs{x} \\abs{y}$. Linear dependence by itself is not enough, since if\n$x$ and $y$ are opposite sign we see that the lefthand sum will be negative. Thus, we need linear dependence \nas well as $x$ and $y$ having the same sign.\n\n\\subsubsection{Exercise 3}\nThe proof is identical to the $\\abs{x + y}$ case, except now we have a $-2 \\sum_{i = 1}^n x_i y_i$ term.\nThus, equality holds when $x$ and $y$ are linearly dependent and have opposite signs.\n\n\\subsubsection{Exercise 4}\n$\\abs{\\abs{x} - \\abs{y}}^2 = \\abs{x}^2 + \\abs{y}^2 - 2\\abs{x} \\abs{y}$. Since $\\abs{x} \\abs{y} \\geq \\langle x, y \\rangle$, we have the desired inequality.\n\n\\subsubsection{Exercise 5}\n\\begin{align*}\n        \\abs{z - x} = \\abs{z - y + y - x} \\leq \\abs{z - y} + \\abs{y - x}\n\\end{align*}\nGeometrically, this is just the fact that any sidelength of a triangle must be bounded by the sum of the\nother two sidelengths.\n\n\\subsubsection{Exercise 6}\n(a) We can proceed as Spivak hints by noting that for the $\\int_{a}^{b} (f - \\lambda g)^2 > 0$ case, the\nproof is identical to that of Theorem 1-1 (2). For the $\\int_{a}^{b} (f - \\lambda g)^2 = 0$ case (which is when equality is obtained), we\ncan use the fact that $(f - \\lambda g)^2 = 0$ almost everywhere.\n\nHowever, I think it's a little smoother to handle both cases at once:\n\\begin{align*}\n        \\int_{a}^{b} (f - \\lambda g)^2 = \\int_{a}^{b} f^2 - 2\\lambda \\int_{a}^{b} fg + \\lambda^2 \\int_{a}^{b} g^2 &\\geq 0 \\\\ \n        \\int_{a}^{b} f^2 - \\frac{2 \\bigg(\\int_{a}^{b} fg\\bigg)^2}{\\int_{a}^{b} g^2} + \\frac{\\bigg(\\int_{a}^{b} fg\\bigg)^2}{\\int_{a}^{b} g^2} &\\geq 0 \\quad \\text{for} \\: \\: \\lambda = \\frac{\\int_{a}^{b} fg}{\\int_{a}^{b} g^2} \\\\\n        \\sqrt{\\int_{a}^{b} f^2 \\int_{a}^{b} g^2} &\\geq \\abs{\\int_{a}^{b} fg}\n\\end{align*}\n\n(b) Equality does not necessarily imply that $f = \\lambda g$, since we could consider $f$ and $g$ to be\n0 everywhere except two points $a$ and $b$ such that $f(a) \\neq \\lambda g(a)$ and $f(b) \\neq \\lambda g(b)$.\nHowever, if $f$ and $g$ are continuous, then $\\int_{a}^{b} (f - \\lambda g)^2 = 0$ implies that $f = \\lambda g$.\n\n(c) Define $f(m) = x_i$ and $g(m) = y_i$ for $m \\in [i, i + 1)$. Then $\\int_{1}^{n} f g = \\sum_{1}^n x_i y_i$ \n(we can break up the integral at the points of discontinuity) and Theorem 1-1 (2) follows.\n\n\\subsubsection{Exercise 7}\n(a) If $T$ is inner product preserving then we have $\\langle Tx, Tx \\rangle = \\langle x, x \\rangle$, so\n$T$ is norm preserving. If $T$ is norm preserving, then\n\\begin{align*}\n        \\langle T(x - y), T(x - y) \\rangle &= \\abs{T(x)}^2 + \\abs{T(y)}^2 - 2\\langle T(x), T(y) \\rangle \\\\\n        \\langle x - y, x - y \\rangle &= \\abs{x}^2 + \\abs{y}^2 - 2 \\langle x, y \\rangle \\\\\n        \\implies \\langle T(x), T(y) \\rangle &= \\langle x, y \\rangle\n\\end{align*}\nso $T$ is inner product preserving.\n\n(b) Since $Tx = Ty \\implies T(x - y) = 0 \\implies \\abs{x - y} = 0$, $T$ is injective. Furthermore,  \n$Tx = 0 \\implies \\abs{x} = 0$, so the nullspace of $T$ is trivial and $T$ is thus surjective. Now if we\nconsider $T^{-1} y = x$, then we have $\\langle y, y \\rangle = \\langle TT^{-1} y, TT^{-1} y \\rangle = \\langle T^{-1} y, T^{-1} y \\rangle$.\n\n\\subsubsection{Exercise 10}\nLet $\\norm{T}_F = \\sqrt{\\sum_{i = 1}^n \\sum_{j = 1}^m T_{ij}^2}$ (Frobenius norm). Then we have\n\\begin{align*}\n        \\abs{T h}^2 = \\sum_{i = 1}^n \\bigg(\\sum_{j = 1}^m T_{ij} h_j\\bigg)^2 &\\leq \\sum_{i = 1}^n \\sum_{j = 1}^m T_ij^2 \\sum_{j = 1}^m h_j^2 = \\norm{T}_F^2 \\abs{h}^2\n\\end{align*}\nso letting $M = \\norm{T}_F$ gives the desired inequality.\n\n\\subsubsection{Exercise 12}\nLinearity and injectivity of $T$ follow from linearity of inner product. To see surjectivity, we note that \nany element $f \\in (\\mathbb{R}^n)^*$ is determined entirely by $f(e_1), ..., f(e_n)$ due to linearity. Thus,\n$f(y) = \\langle x, y \\rangle$ for the unique $x$ satisfying $x_i = f(e_i)$.\n\n\\subsubsection{Exercise 13}\nExpanding $\\langle x + y, x + y \\rangle$ gives the desired result.\n\n\\subsection{Subsets of Euclidean Space}\n\n\\subsubsection{Exercise 14}\nAny point $a$ in the union is also in some set which contains an open set around $a$, and by the definition of\nunion this open set is also in the union. For finite intersection, if a point is in two open sets, then both\nsets must contain some open rectangles around that point; the smaller of these rectangles is in the \nintersection of both sets. For infinite intersection, we can consider the intersection of \n$(-\\frac{1}{n}, \\frac{1}{n})$ for all $n \\in \\mathbb{N}$, as it consists only of the single point 0.\n\n\\subsubsection{Exercise 17}\nThe procedure hinted by Spivak seems to be to split the square into 4 quadrants and then select a point from\neach quadrant while satisfying the constraint, then repeat this procedure indefinitely (split the 4 quadrants\ninto 16 quadrants, etc.). However, I'm not sure how to make this procedure more rigorous.\n\n\\subsubsection{Exercise 19}\nWe can use the facts that the rationals are dense in $\\mathbb{R}$ and that closed sets contain all of their\nlimit points (although neither fact is proved so far in this book) to immediately get the desired result.\n\n\\subsubsection{Exercise 21}\n(a) Since $A$ is closed, $A^c$ is open, which means $x$ has an open rectangle (and thus, an open ball) around\nit that is contained within $A^c$. Therefore, there exists $d > 0$ such that $\\abs{y - x} \\geq d$ for all\n$y \\in A$.\n\n(b) Suppose that for every $d > 0$, we could choose $y_i \\in A$ and $x_i \\in B$ such that $\\abs{y_i - x_i} < d$.\nThis would imply that we could pick a sequence $\\{y_n\\} \\in A$ and a sequence $\\{x_n\\} \\in B$ such that\n $\\lim_{n \\to \\infty} y_n = \\lim_{n \\to \\infty} x_n$. Since $B$ is compact, this limit must be a point in\n  $B$, which contradicts the disjointness of  $A$ and  $B$.\n\n(c) Consider $A = \\{(0, i) \\: | \\: i \\in \\mathbb{N}\\}$ and $B = \\{(0, i + \\frac{1}{i}) \\: | \\: i \\in \\mathbb{N}\\}$.\nFor any $d$, we can choose $i$  such that $\\frac{1}{i} < d$.\n\n\\subsubsection{Exercise 22}\nThis is easier to argue with open/closed balls instead of open/closed rectangles (for me). Every point\n$c \\in C$ must have an open ball $B_{\\delta} (c) \\subset U$ for some $\\delta > 0$. For each such ball,\nconsider instead $B_{r} (c)$ with $r < \\delta$. The closure of $B_r(c)$ is a closed ball that is contained\nwithin $U$. Now, since $C$ is compact, it can be covered by finitely many of these closed balls. Since\nclosed sets are closed under finite union, we can take $D$ to be the union of these balls to get a compact\nset whose interior contains $C$.\n\n\\subsection{Functions and Continuity}\n\n\\subsubsection{Exercise 23}\nSuppose $\\lim_{x \\to a} f(x) = b$. Then we can choose $\\delta$ such that $\\abs{x - a} < \\delta$ implies\n$\\abs{f(x) - b} < \\epsilon$ for any $\\epsilon > 0$. Rewriting $\\abs{f(x) - b}$ as \n$\\sqrt{\\sum_{i = 1}^m (f_i (x) - b_i)^2}$ gives $\\abs{f_i(x) - b_i} < \\epsilon$ for the same $\\delta$, so\nwe get $\\lim_{x \\to a} f_i(x) = b_i$. The other direction reverses the steps after choosing \n$\\abs{f_i(x) - b_i} < \\frac{\\epsilon}{\\sqrt{m}}$. \n\n\\subsubsection{Exercise 24}\nThis is basically the same as the previous exercise.\n\n\\subsubsection{Exercise 25}\nFrom Exercise 1-10 we have that there exists  $M$  such that $\\abs{T(x)} \\leq M \\abs{x}$. Thus, for any\n$\\epsilon > 0$ and $a \\in \\mathbb{R}^n$, we can choose $\\delta = \\frac{\\epsilon}{M}$. Using this $\\delta$,\nwe get $\\abs{x - a} < \\delta$ implies $\\abs{T(x) - T(a)} = \\abs{T(x - a)} < \\epsilon$, so $T$ is continuous.\n\n\\subsubsection{Exercise 28}\nChoose any $x$ on the boundary of  $A$ and let  $f(y) = \\frac{1}{\\abs{y - x}}$. Since $f$ is the quotient\nof two continuous functions ($g(y) = 1$ and  $h(y) = \\abs{y - x}$) with non-zero denonimator, $f$ is continuous.\nFurthermore, by construction we can choose  $y$ arbitrarily close to  $x$, so  $f$ is unbounded.\n\n\\subsubsection{Exercise 29}\nSince $f$ is continuous,  $f(A)$ is compact. By Heine-Borel,  $f(A) \\subset \\mathbb{R}$ is closed and bounded,\nso it contains its maximum and minimum.\n\n\\subsubsection{Exercise 30}\nLet $x_0 = a$. We have that\n\\begin{align*}\n        \\sum_{i = 1}^n o(f, x_i) &= \\lim_{\\delta \\to 0} \\sum_{i = 1}^n [M(f, x_i, \\delta) - m(f, x_i, \\delta)] \\\\\n                                 &\\leq \\lim_{\\delta \\to 0} \\sum_{i = 1}^n [M(f, x_i, \\delta) - M(f, x_{i - 1}, \\delta)] \\\\\n                                 &\\leq \\lim_{\\delta \\to 0} M(f, x_n, \\delta) - m(f, a, \\delta) \\\\\n                                 &\\leq f(b) - f(a)\n\\end{align*}\nWhere we used the fact that $f$ is increasing to get $m(f, x_i, \\delta) \\geq M(f, x_{i - 1}, \\delta)$.\n", "meta": {"hexsha": "49e17ac78545b1e04d333fd30d231ede9c9e3500", "size": 9031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus_on_Manifolds_Spivak/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": "Calculus_on_Manifolds_Spivak/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": "Calculus_on_Manifolds_Spivak/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": 58.6428571429, "max_line_length": 225, "alphanum_fraction": 0.6410142841, "num_tokens": 3187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6904897663313493}}
{"text": "\\subsection{Complex functions}\\label{subsec:complex_functions}\n\n\\begin{definition}\\label{def:sequence_spaces}\n  We will define multiple Banach spaces of sequences over \\( \\BbbC \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:sequence_spaces/c00} The simplest nontrivial sequence space is that of all sequences with only finitely many nonzero elements. It is denoted by \\( c_{00} \\). It can be defined as\n    \\begin{equation*}\n      c_{00} \\coloneqq \\bigcup_{i=1}^\\infty \\BbbC^k,\n    \\end{equation*}\n    where \\( \\BbbC^k \\) is the corresponding \\hyperref[def:module_of_tuples]{tuple space}.\n\n    This space can be generalized to modules over \\hyperref[def:module]{semirings}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:function_spaces}\n  We will define multiple Banach spaces of functions over \\( \\BbbK \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:function_spaces/c0} Define the set of functions \\term{vanishing at infinity}:\n    \\begin{equation*}\n      C_0(\\BbbC) \\coloneqq \\{ f: \\BbbC \\to \\BbbC \\colon f(x) \\xrightarrow[\\abs{x} \\to \\infty]{} 0 \\}.\n    \\end{equation*}\n\n    \\thmitem{def:function_spaces/c} Fix \\hyperref[def:topological_space]{topological space} \\( X \\). The set \\( C(X) = C(X, \\BbbK) \\) of all \\( \\BbbK \\)-valued continuous functions on \\( X \\) in a Banach space over \\( \\BbbK \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{theorem}[Arzela-Ascoli]\\label{thm:arzela_ascoli}\\mcite[cor. 10.49]{Knapp2016BasicAlgebra}\n  Let \\( X \\) be a \\hyperref[def:compact_space]{compact} \\hyperref[def:separation_axioms/T2]{Hausdorff} space.\n\n  A family \\( \\mscrF \\subseteq C(X, \\BbbR) \\) of continuous real-valued functions is totally \\hyperref[def:totally_bounded_set]{bounded} if and only if it is pointwise \\hyperref[def:bounded_function/pointwise]{bounded} and \\hyperref[def:function_set_continuity/equicontinuous]{equicontinuous}.\n\\end{theorem}\n", "meta": {"hexsha": "62203b5a242394c4e2217ce83715a24481e78cca", "size": 1856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/complex_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/complex_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/complex_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": 53.0285714286, "max_line_length": 293, "alphanum_fraction": 0.7225215517, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325345, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.6904897649917203}}
{"text": "\\subsection{Lattices}\\label{subsec:lattices}\n\n\\begin{definition}\\label{def:semilattice}\\mcite[3]{Gratzer1978}\n  Lattices are \\hyperref[def:partially_ordered_set]{partially ordered sets} in which \\hyperref[def:partially_ordered_set_extremal_points/supremum_and_infimum]{suprema and infima} are taken as basic operations called \\enquote{joins} and \\enquote{meets}. See \\fullref{rem:lattice_operation_etymology} for a discussion of the operation names. This shifts the focus from ordering to operations, i.e. from predicates to functions.\n\n  Joins and meets may also be defined axiomatically as binary operations (see \\fullref{thm:binary_lattice_operations}) rather than via some partial order, however this restricts us to taking suprema of finite sets and prevents us from taking the supremum of an arbitrary set. In other words, it is possible for the order to carry more information than joins and meets. See \\fullref{thm:binary_lattice_operations/new_lattice} for a discussion. Unless explicitly noted otherwise, we assume that lattices have their partial order defined.\n\n  \\begin{thmenum}[series=def:semilattice]\n    \\thmitem{def:semilattice/join} A \\term{join-semilattice} is a \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded from above} partially ordered set in which every finite supremum exists. The operation itself is denoted by \\( \\vee \\) and referred to as \\term{join} and rather than supremum. In contrast to suprema, joins are usually written in \\hyperref[rem:first_order_formula_conventions/infix]{infix} notation, e.g. \\( x \\vee y \\vee z \\) rather than \\( \\sup\\set{ x, y, z } \\).\n\n    \\thmitem{def:semilattice/meet} Analogously, a \\term{meet-semilattice} is a partially ordered set in which every finite infimum exists. The infimum is denoted by \\( \\wedge \\) and called \\term{meet}.\n\n    \\thmitem{def:semilattice/bounded} A \\term{bounded semilattice} is a semilattice that is \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded} as a \\hyperref[def:partially_ordered_set]{partially ordered set}, either from above for join-semilattices or from below for meet-semilattices.\n\n    \\thmitem{def:semilattice/complete}\\mcite[24]{Gratzer1978} A semilattice is said to be \\term{complete} if the corresponding operation is defined for arbitrary sets rather than only finite ones. Finite lattices are trivially complete and complete lattices are trivially bounded.\n\n    \\thmitem{def:semilattice/lattice} A \\term{lattice} is a partially ordered set which is both a join-semilattice and a meet-semilattice. It is called \\term{bounded} if both semilattices are bounded, i.e. if the partially ordered set itself is \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded}. It is called \\term{complete} if both semilattices are complete.\n\n    \\thmitem{def:semilattice/distributive_lattice}\\mcite[30]{Gratzer1978} A lattice is said to be \\term{distributive} if the following two distributive conditions hold:\n    \\begin{align}\n      x \\vee (y_1 \\wedge y_2) &= (x \\vee y_1) \\wedge (x \\vee y_2) \\label{eq:def:semilattice/distributive_lattice/finite/join_over_meet} \\\\\n      x \\wedge (y_1 \\vee y_2) &= (x \\wedge y_1) \\vee (x \\wedge y_2) \\label{eq:def:semilattice/distributive_lattice/finite/meet_over_join}.\n    \\end{align}\n\n    If the lattice is \\hyperref[def:semilattice/complete]{complete}, the above conditions are not enough. A complete lattice \\( \\mscrX \\) it is said to be \\term{distributive} if any of the following more general distributive axioms hold for any \\( x \\in \\mscrX \\) and \\hyperref[def:cartesian_product/indexed_family]{family} \\( \\seq{ y_k }_{k \\in \\mscrK} \\subseteq \\mscrX \\):\n    \\begin{align}\n      x \\vee \\parens*{ \\bigwedge_{k \\in \\mscrK} y_k } &= \\bigwedge_{k \\in \\mscrK} \\parens{ x \\vee y_k } \\label{eq:def:semilattice/distributive_lattice/arbitrary/join_over_meet} \\\\\n      x \\wedge \\parens*{ \\bigvee_{k \\in \\mscrK} y_k } &= \\bigvee_{k \\in \\mscrK} \\parens{ x \\wedge y_k } \\label{eq:def:semilattice/distributive_lattice/arbitrary/meet_over_join}\n    \\end{align}\n  \\end{thmenum}\n\n  Lattices have the following metamathematical properties:\n  \\begin{thmenum}[resume=def:semilattice]\n    \\thmitem{def:semilattice/theory} The language of the theory of lattices consists of the language of the \\hyperref[def:partially_ordered_set/theory]{theory of partially ordered sets} with the addition of the binary infix functional symbols \\( \\vee \\) and \\( \\wedge \\). If we only want to restrict ourselves to semilattices, we can add only one of the two operations as functional symbols. If we wish to study \\hyperref[def:semilattice/bounded]{bounded lattices}, as it is often done, we must also add the constants \\( \\top \\) and \\( \\bot \\).\n\n    For meet-semilattices, we add the following axiom schema to the theory to ensure compatibility between infima and meets (we use \\( \\mathbin\\& \\) to denote \\hyperref[def:propositional_language/connectives/conjunction]{logical conjunction} to avoid symbol collision with meets):\n    \\begin{equation}\\label{eq:def:semilattice/theory/meet_compat}\n      \\parens[\\Big]{ \\xi \\wedge \\eta \\doteq \\alpha } \\leftrightarrow \\parens[\\Big]{ \\alpha \\leq \\xi \\mathbin\\& \\alpha \\leq \\eta \\mathbin\\& \\qforall \\alpha ((\\alpha \\leq \\xi \\mathbin\\& \\alpha \\leq \\eta) \\rightarrow \\alpha \\leq \\alpha) }\n    \\end{equation}\n    and, for bounded lattices, the following axiom to ensure that \\( \\bot \\) is indeed the minimum:\n    \\begin{equation}\\label{eq:def:semilattice/theory/bottom_compat}\n      \\qforall \\xi (\\bot \\leq \\xi).\n    \\end{equation}\n\n    Analogous axioms need to be added for join-semilattices.\n\n    We cannot proper express the theory of complete (semi)lattices as an extension of this theory since we must define join and meet as unary operations on subsets of the domain rather than binary operations on members of the domain. Complete semilattices can instead be defined within \\hyperref[def:zfc]{\\logic{ZFC}}.\n\n    \\thmitem{def:semilattice/submodel} Unlike for partially ordered sets (see \\fullref{def:partially_ordered_set/submodel}), not any subset of a semilattice is a subsemilattice because \\( \\vee \\) and \\( \\wedge \\) are now regarded as functional symbols. The axiom \\eqref{eq:def:semilattice/theory/meet_compat} is not a positive formula, but does not cause trouble itself as it merely specifies compatibility of \\( \\leq \\) and \\( \\wedge \\).\n\n    For bounded semilattices, the relevant constants should be present in any bounded subsemilattice.\n\n    \\thmitem{def:semilattice/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial join-semilattice} and the trivial meet-semilattice are the empty set. The trivial bounded join-semilattice is the singleton \\( \\set{ \\top } \\) and the trivial bounded meet-semilattice is \\( \\set{ \\bot } \\).\n\n    The trivial bounded lattice is \\( \\set{ \\top, \\bot } \\).\n\n    Note that the elements \\( \\top \\) and \\( \\bot \\) formally differ between different semilattices, however all trivial bounded lattices are isomorphic and hence it makes sense to speak of \\enquote{the} bounded lattice.\n\n    \\thmitem{def:semilattice/homomorphism} \\hyperref[def:first_order_homomorphism]{Homomorphisms} between (semi)lattices are simply the monotone maps.\n\n    Alternatively, without referring to the order, we can characterize homomorphisms as functions preserving joins, meets and constants. No axioms follow automatically as in \\fullref{thm:group_homomorphism_single_condition}.\n\n    \\thmitem{def:semilattice/category} The \\hyperref[def:category_of_small_first_order_models]{categories of models} for (semi)lattices are full subcategories of \\hyperref[def:partially_ordered_set/category]{\\( \\cat{Pos} \\)}. We only give a special name for the category \\( \\cat{Lat} \\) of lattices.\n\n    \\thmitem{def:semilattice/lattice_duality} The \\hyperref[def:partially_ordered_set/duality]{principle of duality for partially ordered sets} holds for lattices if we also swap the binary operations \\( \\vee \\) and \\( \\wedge \\).\n\n    If the lattice is bounded, we must additionally swap the constants \\( \\top \\) and \\( \\bot \\).\n\n    If the lattice is bounded from only one side, the principle of duality does not hold unless we restrict ourselves to formulas that do not contain the constants.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:lattice_operation_etymology}\n  The terms \\hyperref[def:semilattice/join]{\\enquote{join}} for \\( \\vee \\) and \\hyperref[def:semilattice/meet]{\\enquote{meet}} for \\( \\wedge \\) are notoriously difficult to remember. A helpful accident is the ability to write \\enquote{meet} as \\enquote{\\( \\wedge \\wedge \\)eet}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:binary_lattice_operations}\n  Let \\( (\\mscrP, \\leq) \\) be a partially ordered set.\n\n  \\begin{thmenum}\n    \\thmitem{thm:binary_lattice_operations/semilattices} If it is a \\hyperref[def:semilattice/join]{join-semilattice} (resp. \\hyperref[def:semilattice/meet]{meet-semilattice}), then \\( \\vee \\) (resp. \\( \\wedge \\)) is \\hyperref[def:magma/associative]{associative}, \\hyperref[def:magma/commutative]{commutative} and \\hyperref[def:magma/idempotent]{idempotent} when considered as a binary operation.\n\n    \\thmitem{thm:binary_lattice_operations/identity} If \\( \\mscrP \\) is a (semi)lattice, the constants act as \\hyperref[def:magma_identity]{magma identities}. That is, for each \\( x \\in \\mscrP \\),\n    \\begin{align}\n      x \\vee \\bot = x \\label{eq:thm:binary_lattice_operations/identity/join} \\\\\n      x \\wedge \\top = x \\label{eq:thm:binary_lattice_operations/identity/meet}\n    \\end{align}\n\n    \\thmitem{thm:binary_lattice_operations/absorption} If \\( \\mscrP \\) is a lattice, then the following absorption laws hold:\n    \\begin{align}\n      x \\vee (x \\wedge y) &= x \\label{eq:thm:binary_lattice_operations/absorption/join} \\\\\n      x \\wedge (x \\vee y) &= x \\label{eq:thm:binary_lattice_operations/absorption/meet}.\n    \\end{align}\n\n    \\thmitem{thm:binary_lattice_operations/compatibility} The following conditions for compatibility with \\( \\leq \\) hold:\n    \\begin{align}\n      x \\leq y &\\T{if and only if} x \\vee y = y \\label{eq:thm:binary_lattice_operations/compatibility/join} \\\\\n      x \\leq y &\\T{if and only if} x \\wedge y = x \\label{eq:thm:binary_lattice_operations/compatibility/meet}.\n    \\end{align}\n\n    \\thmitem{thm:binary_lattice_operations/new_lattice} If \\( S \\) is an arbitrary \\hyperref[def:set]{set} and if \\( \\vee \\) is a binary operation that is associative, commutative and idempotent (the conclusion of \\fullref{thm:binary_lattice_operations/semilattices}), then \\( (S, \\leq) \\) is a join-semilattice with an ordering defined by \\eqref{eq:thm:binary_lattice_operations/compatibility/join}. If there exists a distinguished element \\( \\top \\) such that \\eqref{eq:thm:binary_lattice_operations/identity/join} holds, then \\( (S, \\leq) \\) is a meet-semilattice.\n\n    A completely analogous statement holds for meet-semilattices.\n\n    If \\( (S, \\leq) \\) is both a join-semilattice and meet-semilattice and if \\( \\vee \\) and \\( \\wedge \\) satisfy the absorption conditions \\eqref{eq:thm:binary_lattice_operations/absorption/join} and \\eqref{eq:thm:binary_lattice_operations/absorption/meet}, then \\( (S, \\leq) \\) is a lattice. Furthermore, proving idempotence for \\( \\vee \\) or \\( \\wedge \\) is unnecessary because both follow from the absorption conditions.\n\n    It may turn out that \\( (S, \\leq) \\) is a complete lattice under this definition. This can allow us, for example, to transparently extend the binary operations join and meet into infinitary operations.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:binary_lattice_operations/semilattices} Suprema and infima are obviously associative and commutative as binary operations because ordering is immaterial for pure sets and \\( x \\vee y \\) is defined as \\( \\sup\\set{ x, y } \\).\n\n  Idempotence is also obvious because \\( x \\vee x = \\sup\\set{ x } = x \\).\n\n  \\SubProofOf{thm:binary_lattice_operations/identity} Obvious since \\( \\bot \\leq x \\leq \\top \\) for all \\( x \\in \\mscrP \\).\n\n  \\SubProofOf{thm:binary_lattice_operations/absorption} If we rewrite \\eqref{eq:thm:binary_lattice_operations/absorption/join} using suprema and infima, we obtain\n  \\begin{equation*}\n    \\sup\\set{ x, \\inf\\set{ y, x } } = x.\n  \\end{equation*}\n\n  If \\( x \\leq y \\), then \\( \\inf\\set{ y, x } = x \\) and \\( \\sup\\set{ x, \\inf\\set{ y, x } } = \\sup\\set{ x, x } = x \\).\n\n  If \\( x \\geq y \\), then \\( \\inf\\set{ y, x } = y \\) and \\( \\sup\\set{ x, \\inf\\set{ y, x } } = \\sup\\set{ x, y } = x \\).\n\n  This proves \\eqref{eq:thm:binary_lattice_operations/absorption/join}. Since \\( \\wedge \\) is \\( \\vee \\) in the \\hyperref[def:preordered_set/duality]{dual partially ordered set}, \\eqref{eq:thm:binary_lattice_operations/absorption/meet} follows automatically.\n\n  \\SubProofOf{thm:binary_lattice_operations/compatibility} We have\n  \\begin{equation*}\n    x \\vee y\n    =\n    \\sup\\set{ x, y }\n    =\n    \\begin{cases}\n      y, &x \\leq y \\\\\n      x, &x > y\n    \\end{cases}\n  \\end{equation*}\n  and dually for \\( \\wedge \\).\n\n  \\SubProofOf{thm:binary_lattice_operations/new_lattice} Since the binary join and/or meet are defined for all members of the set \\( S \\), it is indeed a join-semilattice because all finite joins and meets exist by definition.\n\n  Idempotence of \\( \\vee \\) follows from \\eqref{eq:thm:binary_lattice_operations/absorption/meet}:\n  \\begin{equation*}\n    x \\vee x = x \\vee (x \\wedge (x \\vee x)) = x\n  \\end{equation*}\n  and dually for \\( \\wedge \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:fixed_point}\n  Given a \\hyperref[def:function]{function} \\( f: A \\to A \\) between arbitrary sets, we call \\( x \\in A \\) a \\term{fixed point} of \\( f \\) if \\( x = f(x) \\).\n\\end{definition}\n\n\\begin{theorem}[Knaster-Tarski theorem]\\label{thm:knaster_tarski_theorem}\n  The \\hyperref[def:fixed_point]{fixed points} of a \\hyperref[def:partially_ordered_set/homomorphism]{monotone} \\hyperref[def:multi_valued_function/endofunction]{endofunction} in a \\hyperref[def:semilattice/lattice]{complete lattice} form a complete sublattice. In particular, the function has at least one fixed point.\n\\end{theorem}\n\\begin{proof}\n  Let \\( (\\mscrX, \\leq) \\) be a complete lattice and let \\( \\varphi: \\mscrX \\to \\mscrX \\) be a monotone function. Define\n  \\begin{equation*}\n    L \\coloneqq \\{ x \\in \\mscrX \\colon f(x) \\leq x \\}.\n  \\end{equation*}\n\n  We know that \\( L \\) is nonempty because \\( \\top \\in L \\).\n\n  Since the lattice is complete, we can take \\( l \\coloneqq \\inf L \\). Note that \\( f(l) \\) is a lower bound of \\( L \\) because for any \\( y \\in L \\) we have\n  \\begin{equation*}\n    f(l) \\leq f(y) \\leq y.\n  \\end{equation*}\n\n  But \\( l \\) is the largest lower bound of \\( L \\), hence\n  \\begin{equation}\\label{eq:thm:knaster_tarski/f_lower}\n    f(l) \\leq l.\n  \\end{equation}\n\n  Therefore, \\( f(f(l)) \\leq f(l) \\) and \\( f(l) \\in L \\). Hence, \\( l \\) is a lower bound for \\( \\{ f(l) \\} \\) and\n  \\begin{equation}\\label{eq:thm:knaster_tarski/f_upper}\n    l \\leq f(l).\n  \\end{equation}\n\n  From \\eqref{eq:thm:knaster_tarski/f_lower} and \\eqref{eq:thm:knaster_tarski/f_upper} it follows that \\( l = f(l) \\), that is, \\( l \\) is a fixed point of \\( f \\).\n\n  Denote by \\( F \\) the set of all fixed points of \\( \\mscrX \\). We just showed that \\( F \\) is nonempty. Let \\( G \\subseteq F \\). We will show that the infimum and supremum of \\( G \\) is in \\( F \\).\n\n  Denote\n  \\begin{equation*}\n    l_G \\coloneqq \\inf G.\n  \\end{equation*}\n\n  For any \\( g \\in G \\) we have \\( l_G \\leq g \\). From monotonicity of \\( f \\),\n  \\begin{equation*}\n    f(l_G) \\leq f(g) = g,\n  \\end{equation*}\n  therefore \\( f(l_G) \\leq l_G \\) because \\( l_G \\) is the greatest lower bound of \\( G \\). But, from monotonicity of \\( f \\), we have \\( l_G \\leq f(l_G) \\). Therefore, \\( f(l_G) = l_G \\) and \\( l_G \\in F \\).\n\n  We can analogously show that \\( \\sup G \\in F \\) and conclude that \\( (F, \\leq) \\) is itself a complete lattice.\n\\end{proof}\n\n\\begin{remark}\\label{def:semilattice/lattice_categorical_product}\n  The existence of finite joins and meets is equivalent to the existence of finite products and coproducts in the respective partially ordered set category defined in \\fullref{thm:order_category_isomorphism/partially_ordered}.\n\\end{remark}\n", "meta": {"hexsha": "165864f679dcff9fe9b3f1a9c31412cb0132d2e4", "size": 16208, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lattices.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/lattices.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/lattices.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": 80.6368159204, "max_line_length": 567, "alphanum_fraction": 0.7279121422, "num_tokens": 4939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914786, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.6904897602382596}}
{"text": "\\section{Extraction of Linearized Models}\nModels that represent the linearized dynamics of a system in the neighborhood of an equilibrium point (trim condition) can be used to gain insight into system stability characteristics. Consider the dynamics represented by Eqs. (\\ref{eqn:allodes}). Expanding the left hand side in a Taylor series, we obtain\n\\begin{equation}\n\\vector{f} \\quad + \\quad \\frac{\\partial \\vector{f}}{\\partial \\dot{\\vector{y}}} \\Delta \\dot{\\vector{y}} \\quad + \\quad \\frac{\\partial \\vector{f}}{\\partial \\vector{y}} \\Delta \\vector{y} \\quad + \\quad \\frac{\\partial \\vector{f}}{\\partial \\vector{u}} \\Delta \\vector{u} \\quad + \\quad \\cdots \\quad = \\quad \\grkvec{\\epsilon} \\quad\n\\end{equation}\nAt equilibrium (trim), $\\vector{f}$ = $\\grkvec{\\epsilon}$ $\\stackrel{\\text{def}}{=}$ $\\vector{0}$. Let the Jacobian matrices be \n\\[ \\textbf{E} \\quad = \\quad \\frac{\\partial \\grkvec{\\epsilon}}{\\partial \\dot{\\vector{y}}}\\biggr\\rvert_\\textrm{trim} \\qquad \\textrm{;} \\qquad \\textbf{F} \\quad = \\quad \\frac{\\partial \\grkvec{\\epsilon}}{\\partial \\vector{y}}\\biggr\\rvert_\\textrm{trim} \\qquad \\textrm{;} \\qquad \\textbf{G} \\quad = \\quad \\frac{\\partial \\grkvec{\\epsilon}}{\\partial \\vector{u}}\\biggr\\rvert_\\textrm{trim} \\]\n Neglecting the higher-order terms, we obtain the linearized system dynamics about equilibrium, given by \n\\begin{equation}\n\\textbf{E} \\textrm{ }\\Delta \\dot{\\vector{y}} \\quad + \\quad \\textbf{F} \\textrm{ }\\Delta \\vector{y} \\quad + \\quad \\textbf{G} \\textrm{ }\\Delta \\vector{u} \\quad = \\quad \\vector{0}\n\\end{equation}\nRearranging the equations and isolating $\\Delta \\dot{\\vector{y}}$, we obtain\n\\begin{align}\n\\label{eqn:lindyn}\n\\Delta \\dot{\\vector{y}} \\quad = \\quad &\\textbf{A} \\textrm{ }\\Delta \\vector{y} \\quad + \\textbf{B} \\textrm{ }\\Delta \\vector{u} \\\\\n\\textrm{Where} \\qquad \\qquad \\qquad & \\qquad \\qquad \\qquad \\qquad \\qquad \\qquad \\notag \\\\\n\\textbf{A} \\quad = \\quad &-\\textbf{E}^{-1} \\textbf{F} \\notag \\\\\n\\textbf{B} \\quad = \\quad &-\\textbf{E}^{-1} \\textbf{G} \\notag \n\\end{align}\nThe linearization process is performed by the routine \\textbf{linrzODEs}, which calls \\textbf{ODEResiduals} repeatedly. Using Eq. (\\ref{eqn:lindyn}) and an appropriate state-to-output conversion matrix \\textbf{C}, transfer functions between \\textit{pilot inputs} and system outputs for the relevant physical quantities can be constructed as \n\\begin{equation}\n\\textbf{H}(s) \\quad = \\quad \\textbf{C} \\textrm{ }\\left(s \\textrm{ }\\textbf{I} \\textrm{ }- \\textrm{ }\\textbf{A}_\\textrm{NR}\\right)^{-1} \\spc\\textbf{B}_\\textrm{NR} \\spc + \\spc \\textbf{D}\n\\end{equation}\nThe transfer function magnitude and phase are obtained from the system \\textbf{A} and \\textbf{B} matrices using a wrapper routine \\textbf{freq\\_response\\_wrapper} for a NETLIB program. \n\n\\subsection{Multiblade Coordinate Transform}\nBefore the system frequency response can be constructed, it is necessary to obtain the system \\textbf{A}  and \\textbf{B} matrices in the fixed frame. However, the \\textbf{A} and \\textbf{B} matrices obtained from the application of finite-difference perturbations on \\textbf{ODEResiduals} are azimuth dependent, since the rotor states are defined in the rotating preconed undeformed axes. Therefore, an additional coordinate transform is required to convert the resulting \\textbf{A} and \\textbf{B} matrices to the fixed frame.\n\nLet the matrix \\textbf{P} represent the time-varying coordinate transform that converts the system states from the fixed frame to the rotating frame, and let \\textbf{y$_\\textrm{NR}$} denote the system state vector in the fixed frame. By definition,\n\\[ \\textbf{y}(t) \\quad = \\quad \\textbf{P}(t) \\spc \\textbf{y}_\\textrm{NR}(t) \\]\n\nSubstituting the above expression in the linearized governing equations\n\\begin{align*}\n\\vector{P} \\spc \\Delta \\dot{\\vector{y}}_\\textrm{NR} \\spc + \\spc \\dot{\\vector{P}} \\spc \\Delta \\vector{y}_\\textrm{NR} \\quad = \\quad & \\quad \\textbf{A} \\spc \\vector{P} \\spc & \\Delta \\vector{y}_\\textrm{NR} \\quad + \\quad & \\textbf{B} \\spc\\Delta \\vector{u} \\\\\n\\Rightarrow \\vector{P} \\spc \\Delta \\dot{\\vector{y}}_\\textrm{NR} \\quad = \\quad & \\left( \\textbf{A} \\spc \\vector{P} - \\dot{\\vector{P}} \\right) &\\Delta \\vector{y}_\\textrm{NR} \\quad + \\quad & \\textbf{B} \\spc\\Delta \\vector{u} \\\\\n\\Rightarrow \\Delta \\dot{\\vector{y}}_\\textrm{NR} \\quad = \\quad & \\vector{P}^{-1} \\left( \\textbf{A} \\spc \\vector{P} - \\dot{\\vector{P}} \\right) &\\Delta \\vector{y}_\\textrm{NR} \\quad + \\quad & \\vector{P}^{-1} \\spc \\textbf{B} \\spc\\Delta \\vector{u}\n\\end{align*}\nThis equation is of the form \n\\[ \\Delta \\dot{\\vector{y}}_\\textrm{NR} \\quad = \\quad \\vector{A}_\\textrm{NR} \\Delta \\vector{y}_\\textrm{NR} \\quad + \\quad \\textbf{B}_\\textrm{NR} \\spc\\Delta \\vector{u} \\]\nWhere\n\\begin{align}\n\\vector{A}_\\textrm{NR} \\quad = \\quad & \\vector{P}^{-1} \\left( \\vector{A} \\spc \\vector{P} - \\dot{\\vector{P}} \\right) \\\\\n\\vector{B}_\\textrm{NR} \\quad = \\quad & \\vector{P}^{-1} \\spc \\vector{B} \n\\end{align}\n\nThe system \\textbf{A} and \\textbf{B} matrices are obtained at multiple azimuths, converted to the fixed frame and averaged to obtain an engineering representation of a Linear Time-Invariant (\\textbf{LTI}) system. The fixed-frame conversion at each azimuth is performed by a modified version of the Heli-UM routine \\textbf{linea2}.\n\n\\subsubsection*{The Multiblade Coordinate Transformation}\nThe system state vector can be partitioned into two sets of vectors: those states defined in the fixed frame, \\textbf{y}$_\\textrm{NR}$ and the rotor states defined in the rotating frame \\textbf{y}$_\\textrm{R}$. The rotation matrix that converts the \\textit{entire} system state vector \\textbf{y} to its fixed-frame counterpart is \\textbf{P}, given by \n\\[ \\vector{P} = \\begin{bmatrix}\n\\vector{P}_\\textrm{NR} & \\vector{0} \\\\\n\\vector{0} & \\vector{P}_\\textrm{R} \\end{bmatrix} \\]\nIt is assumed that the rotor states constitute the last partition in the state vector. The partition \\textbf{P}$_\\textrm{NR}$ is an identity matrix whose size is equal to the number of states defined in the non-rotating frame. \\textbf{P}$_\\textrm{R}$ is the multi-blade transformation matrix. Before writing out an expansion for \\textbf{P}$_\\textrm{R}$, we recall the partition of state vector corresponding to the rotor modes is given by \n\\[ \\vector{y}_\\textrm{rotor} \\quad = \\quad \\renewcommand\\arraystretch{0.5}\\begin{Bmatrix} \\spc \\dot{\\grkvec{\\eta}}_1\\tr \\quad \\grkvec{\\eta}_{1}\\tr \\qquad \\dot{\\grkvec{\\eta}}_2\\tr \\quad \\grkvec{\\eta}_{2}\\tr \\quad \\cdots \\quad \\dot{\\grkvec{\\eta}}_\\textrm{Nm}\\tr \\quad \\grkvec{\\eta}_\\textrm{Nm}\\tr \\spc  \\end{Bmatrix}\\tr \\] \nThe vector of generalized displacements for the `` $j^\\textrm{th}$ '' mode is given by \n\\[ \\grkvec{\\eta}_j \\quad = \\quad \\renewcommand\\arraystretch{0.5}\\begin{Bmatrix} \\spc  \\eta_{j,1} \\qquad \\eta_{j,2} \\quad \\cdots \\quad \\eta_{j,\\textrm{Nb}} \\spc  \\end{Bmatrix}\\tr \\]\n$\\eta_{j,i}$ represents the `` $j^\\textrm{th}$ '' generalized displacement of blade `` $i$ ''. These generalized displacements are the coefficients of the normal modes corresponding to the rotating beam structure of the blade. This particular arrangement of the rotor states is useful, since it allows us to construct the partition of the fixed-frame transformation \\textbf{P}$_\\textrm{R}$ as repeating diagonal blocks, given by \n\\[ \\textbf{P}_\\textrm{R} \\quad = \\quad \\begin{bmatrix}\n\\textbf{P}_\\textrm{mode} & \\textbf{0} & \\cdots & \\textbf{0} & \\textbf{0} \\\\\n\\textbf{0} & \\textbf{P}_\\textrm{mode}  & \\cdots & \\textbf{0} & \\textbf{0} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n\\textbf{0}& \\textbf{0} & \\cdots  & \\textbf{P}_\\textrm{mode}  & \\textbf{0} \\\\\n\\textbf{0} & \\textbf{0} & \\cdots & \\textbf{0} & \\textbf{P}_\\textrm{mode} \n\\end{bmatrix} \\]\nThe diagonal block \\textbf{P}$_\\textrm{mode}$ repeats N$_\\textrm{m}$ times, where N$_\\textrm{m}$ is the number of blade modes. All that remains is to obtain an expression for the matrix \\textbf{P}$_\\textrm{mode}$, which is a square matrix of size $2\\textrm{N}_\\textrm{b} \\times 2\\textrm{N}_\\textrm{b}$. \n\nConsider a mode $\\eta$ of a blade contained in a rotor system. $\\eta(t)$ is defined in the rotating frame, and the frame is unique to each blade. This mode can be expressed as a Fourier series expansion in azimuth as \n\\[\\eta_i(t) \\quad = \\quad \\eta_0(t) \\spc + \\spc \\sum_{k=1}^{N} \\left[ \\spc \\eta_{kc} \\spc \\cos (k \\psi_i) \\quad + \\quad \\eta_{ks} \\spc \\sin (k \\psi_i) \\right] \\]\nFor an even bladed rotor, an additional term exists, corresponding to the differential mode, and the mode is \n\\[\\eta_i(t) \\quad = \\quad \\eta_0(t) \\spc + \\spc \\sum_{k=1}^{N} \\left[ \\spc \\eta_{kc} \\spc \\cos (k \\psi_i) \\quad + \\quad \\eta_{ks} \\spc \\sin (k \\psi_i) \\spc \\right] + \\spc \\eta_d (-1)^{i-1} \\]\n$\\eta_0$, $\\eta_{kc}$, $\\eta_{ks}$ (and $\\eta_d$ for even-bladed rotors) are the fixed-frame equivalents of the blade mode $\\eta(t)$ for all blades. These transformations from fixed to rotating frame (or vice versa) are exact, hence there are as many fixed-frame coefficients as there are blades. In matrix-vector form, we have\n\\begin{equation}\n\\grkvec\\eta \\quad = \\quad \\vector{T} \\spc \\grkvec\\eta_\\textrm{F}\n\\end{equation}\nDifferentiate once with respect to time to obtain\n\\[ \\dot{\\grkvec\\eta} \\quad = \\quad \\dot{\\vector{T}} \\spc \\grkvec\\eta_\\textrm{F} \\spc + \\spc \\vector{T} \\spc \\dot{\\grkvec\\eta}_\\textrm{F} \\]\nIn matrix-vector product form, \n\\begin{equation*}\n\\begin{Bmatrix} \\dot{\\grkvec\\eta} \\\\ \\grkvec\\eta \\end{Bmatrix} \\quad = \\quad \\begin{bmatrix}\n\\vector{T} & \\dot{\\vector{T}} \\\\\n\\vector{0} & \\vector{T}\n\\end{bmatrix} \\begin{Bmatrix} \\dot{\\grkvec\\eta}_\\textrm{F} \\\\ \\grkvec\\eta_\\textrm{F} \\end{Bmatrix}\n\\end{equation*}\nWhere \n\\begin{equation}\n\\grkvec\\eta_\\textrm{F} \\quad = \\quad \\begin{Bmatrix} \\eta_0 \\\\ \\eta_\\textrm{1c} \\\\ \\eta_\\textrm{1s} \\\\ \\vdots \\\\ \\eta_d \\end{Bmatrix}\n\\end{equation}\n\\begin{equation}\n\\grkvec\\eta \\quad = \\quad \\begin{Bmatrix} \\eta_1 \\\\ \\eta_2 \\\\ \\vdots \\\\ \\eta_{\\textrm{N}_b}\\end{Bmatrix}\n\\end{equation}\nFor an even bladed rotor, the transformation between rotating blade modes and their fixed-frame counterparts is \n\\begin{equation}\n\\vector{T}_\\textrm{even} \\quad = \\quad \\begin{bmatrix} \n1 & \\cos \\psi_1 & \\sin \\psi_1 & \\cdots & -1 \\\\\n1 & \\cos \\psi_2 & \\sin \\psi_2 & \\cdots &  1 \\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\vdots \\\\\n1 & \\cos \\psi_{\\textrm{N}_b} & \\sin \\psi_{\\textrm{N}_b} & \\cdots & 1 \n\\end{bmatrix}\n\\end{equation}\nFor an odd-bladed rotor, the corresponding transformation between rotating blade modes and their fixed-frame counterparts is \n\\begin{equation}\n\\vector{T}_\\textrm{odd} \\quad = \\quad \\begin{bmatrix} \n1 & \\cos \\psi_1 & \\sin \\psi_1 & \\cdots \\\\\n1 & \\cos \\psi_2 & \\sin \\psi_2 & \\cdots \\\\\n\\vdots & \\vdots & \\vdots & \\vdots \\\\\n1 & \\cos \\psi_{\\textrm{N}_b} & \\sin \\psi_{\\textrm{N}_b} & \\cdots \n\\end{bmatrix}\n\\end{equation}\n\\subsection{LQR and the Riccati Equation}\nFeedback control inputs based on linearized models are used in the present analysis to track prescribed vehicle motions and obtain the control inputs required to fly a certain trajectory. To obtain the feedback gains \\textbf{K} from the linearized dynamics, the Linear Quadratic Regulator (LQR)  (Ref. \\cite{Kirk}) is used, which provides a methodology to stabilize and control a linear system by minimizing a designer-weighted quadratic cost functional in the state deviations from targets and the control inputs. For an LTI system with dynamics given by Eq. (\\ref{eqn:lindyn}), the infinite-horizon continuous-time LQR controller yields state feedback gains \\textbf{K} to minimize the quadratic cost functional\n\\begin{equation}\n\\label{eqn:quadcost}\nJ \\quad = \\quad \\int_{0}^{\\infty} \\left(\\textrm{ } \\vector{x}^T \\textrm{ } \\textbf{Q} \\textrm{ } \\vector{x} \\textrm{ } + \\textrm{ } \\Delta \\vector{u}^T \\textrm{ } \\textbf{R} \\textrm{ } \\Delta \\vector{u}\\textrm{ } \\right) dt\n\\end{equation}\nWhere\n\\[ \\vector{x} \\quad = \\quad ( \\textrm{ } \\vector{y} \\textrm{ } - \\textrm{ } \\vector{y}_\\textrm{target} \\textrm{ } ) \\]\nThe state feedback controls are given by \n\\begin{equation*}\n\\Delta \\vector{u} \\quad = -\\textbf{K} \\textrm{ } \\vector{x} \n\\end{equation*}\nThe feedback gains are obtained from\n\\begin{equation}\n\\label{eqn:LQRfeedback}\n\\textbf{K} \\quad = \\quad \\textbf{R}^{-1} \\textbf{B}^T \\textbf{P} \n\\end{equation}\n\\textbf{P} is the unique positive definite steady-state solution of the continuous-time Riccati Equation \n\\begin{equation}\n\\label{eqn:Riccati}\n\\frac{d \\textbf{P}}{dt} \\textrm{ } + \\textrm{ } \\textbf{A}^T \\textbf{P} \\textrm{ } + \\textrm{ } \\textbf{P} \\textbf{A} \\textrm{ } - \\textrm{ } \\textbf{P} \\textbf{B}\\textbf{R}^{-1}\\textbf{B}^T \\textbf{P} \\textrm{ } + \\textrm{ } \\textbf{Q} \\quad = \\quad \\textbf{0}\n\\end{equation}\nAt steady-state, the time derivatives vanish, and the stabilizing solution satisfies the algebraic Riccati equation\n\\begin{equation}\n\\label{eqn:SSR1}\n\\textbf{A}^T \\textbf{P} \\textrm{ }+\\textrm{ } \\textbf{P} \\textbf{A} \\textrm{ }-\\textrm{ } \\textbf{P} \\textbf{B} \\textbf{R}^{-1} \\textbf{B}^T \\textbf{P} \\textrm{ }+ \\textrm{ }\\textbf{Q} \\quad = \\quad \\textbf{0}\n\\end{equation}\nTaking transpose on both sides\n\\begin{equation*}\n\\textbf{A}^T \\textbf{P}^T \\textrm{ }+ \\textrm{ }\\textbf{P}^T \\textbf{A} \\textrm{ }- \\textrm{ }\\textbf{P}^T \\textbf{B}{\\textbf{R}^{-1}}^T\\textbf{B}^T \\textbf{P}^T \\textrm{ }+ \\textrm{ }\\textbf{Q}^T \\quad = \\quad \\textbf{0}\n\\end{equation*}\nThe vehicle and load rigid-body states are assigned non-zero weights, and the control inputs are penalized with a unit weight. All other states and off-diagonal weights (entries of \\textbf{Q},\\textbf{R}) are assigned to zero. The diagonal form of the weighting matrices for controls and states allows for further simplification of the solution procedure to obtain the feedback gains \\textbf{K} from the Riccati equation. The steady-state equation simplifies to\n\\begin{equation}\n\\label{eqn:SSR2}\n\\textbf{A}^T \\textbf{P}^T \\textrm{ }+ \\textrm{ }\\textbf{P}^T \\textbf{A} \\textrm{ }- \\textrm{ }\\textbf{P}^T \\textbf{B}{\\textbf{R}^{-1}}\\textbf{B}^T \\textbf{P}^T \\textrm{ }+ \\textrm{ }\\textbf{Q} \\quad =\\quad \\textbf{0}\n\\end{equation}\nEq. (\\ref{eqn:SSR2}) is very similar to Eq. (\\ref{eqn:SSR1}), with \\textbf{P} replaced by $\\textbf{P}^T$. Thus, if \\textbf{P} is a stabilizing solution, \\textbf{P}$^T$ is also a stabilizing solution and if a unique stabilizing solution exists, the matrix \\textbf{P} must be symmetric. For a matrix of size \\emph{n}$\\times$\\emph{n}, the number of elements of \\textbf{P} to find are ${\\frac{n \\left(n+1\\right)}{2}}$. Thus, Eq. (\\ref{eqn:Riccati}) can be integrated numerically from an initial condition towards the stabilizing solution by exploiting symmetry and updating the upper or lower-triangular elements of \\textbf{P}.\n\n\\subsection{Practical Considerations}\n\\begin{itemize}\n\\item \\textbf{Controllability} \\\\\nA few candidate flight conditions (straight and turning flight at various speeds) were considered to determine whether the system is controllable, which is a necessary condition for a stabilizing solution of the Riccati equation to exist. In all cases, the Grammian was found to be full-rank. \n\\item \\textbf{Solving the Riccati Equation} \\\\\nA Runge-Kutta (fourth-order) scheme is used to advance the Riccati equation forward in time starting from \\textbf{0}. For computational efficiency, the time step is increased as the infinity-norm of $\\dot{\\textbf{P}}$ decreases, and marching is terminated when it falls below a threshold value ($10^{-8}$)\n\\item \\textbf{Computation efficiency} \\\\\nAdditional time savings are obtained by marching the Riccati equation forward from the previous steady-state solution instead of the original initial condition (\\textbf{0}). In case the Riccati equation does not converge to a steady-state solution within a prefixed number of iterations (30000 in this case), the feedback gains from the previous update are used and the initial condition is reset to \\textbf{0}.\n\\item \\textbf{Gain Scheduling and Control Smoothness} \\\\\nIt is possible, but practically cumbersome, to generate feedback gain matrices for a combination of speeds, climb angles, turn rates and altitudes. Every additional parameter (e.g. fin pitch settings) increases the number of potential pre-computations exponentially. Instead, a dynamic update of the system \\textbf{A} and \\textbf{B} matrices is performed every 30 revolutions following a re-trim based on the current flight condition and altitude, and the feedback gains \\textbf{K} are smoothly transitioned from the previous set to the current one over a few rotor revolutions to avoid abrupt changes in the control inputs.\n\\end{itemize}\n\n\\begin{Figure}\n \\centering\n \\includegraphics[width=1.3\\textwidth, angle=90]{images/feedback_gains_callgraph.png}\n \\vspace{-0.5cm}\n \\captionof{figure}{Abbreviated call graph to perform linearized analysis}\n \\label{fig:cg}\n\\end{Figure}\n", "meta": {"hexsha": "a5c64c9c7d1ee4a80cab880db51252b3b0ca5158", "size": 16702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Autodoc/theory_prog_manual/Stability.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/Stability.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/Stability.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": 100.6144578313, "max_line_length": 712, "alphanum_fraction": 0.7160819064, "num_tokens": 5669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7577943822145997, "lm_q1q2_score": 0.6904868654348864}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\n\\subsubsection{Map}\nThe $map$ operation takes in a function $fn?$, Collection $coll?$ and additional Arguments $args?$ (as necessary)\nand returns a modified Collection $coll!$ with members $fn!_{n}$. The ordering of $coll?$ is maintained within $coll!$\n\\begin{schema}{Map[(\\_~\\pfun~\\_), Collection, V]}\n  fn? : (\\_~\\pfun~\\_) \\\\\n  args? : V \\\\\n  coll?, coll! : Collection \\\\\n  map~\\_ : (\\_~\\pfun~\\_) \\cross Collection \\cross V \\surj Collection\n  \\where\n  coll! = map(fn?, coll?, args?) @ \\\\\n  \\t3 \\langle ~\\forall n : i~..~j \\in coll? ~|~ i \\leq n \\leq j ~\\land ~j = ~\\# ~coll? @ \\\\\n  \\t4 \\exists_1 ~fn!_{n} : V ~|~ fn!_{n} = \\\\\n  \\t5 (fn?(coll?_{n}, args?) \\iff args? \\not = \\emptyset) ~\\lor \\\\\n  \\t5 (fn?(coll?_{n}) \\iff args? = \\emptyset) \\rangle \\implies fn!_{i} \\cat fn!_{n} \\cat fn!_{j} \\\\\n\\end{schema}\nAbove, $fn!_{n}$ is introduced to handle the case where $fn?$ only requires a single argument.\nAdditional arguments may be necessary but if they are not ($args? = \\emptyset$) then only $coll?_{n}$ is passed to $fn?$.\n\\begin{argue}\n  X = \\langle 1, 2, 3 \\rangle \\\\\n  \\t1 map~(succ, X) = \\langle 2, 3, 4 \\rangle & increment each member of $X$ \\\\\n  \\t1 map~(+, X, 2) = \\langle 3, 4, 5 \\rangle & add 2 to each member of $X$\n\\end{argue}\n\n\\end{document}\n", "meta": {"hexsha": "6160be14da5a95213581ca0c8679c4391cc5ee63", "size": 1315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/util/map.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/map.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/map.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.9642857143, "max_line_length": 121, "alphanum_fraction": 0.6129277567, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6904868581238706}}
{"text": "\\subsection{Complete metric spaces}\\label{subsec:metric_convergence}\n\n\\begin{definition}\\label{def:complete_metric_space}\n  A metric space is said to be \\term{complete} if\n  \\begin{thmenum}\n    \\thmitem{def:complete_metric_space/sequences} Every fundamental sequence converges.\n    \\thmitem{def:complete_metric_space/uniform} It is complete as a uniform space in the sense of \\fullref{def:complete_uniform_space}\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  The equivalence is due to \\fullref{thm:def:metric_topology/sequential} and \\fullref{thm:def:metric_topology/hausdorff}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:fundamental_sequence_is_bounded}\n  In a metric space, any \\hyperref[def:fundamental_net]{fundamental sequence} \\( \\{ x_k \\}_{i=1}^n \\) is \\hyperref[def:metric_space/bounded_sequence]{bounded}.\n\\end{proposition}\n\\begin{proof}\n  Since the set\n  \\begin{equation*}\n    I \\coloneqq \\{ x_k \\colon k \\leq k_0 \\}\n  \\end{equation*}\n  is finite, it has a finite \\hyperref[def:metric_space/diameter]{diameter}.\n\n  Fix \\( \\varepsilon > 0 \\). Since the sequence is fundamental, there exists an index \\( k_0 \\) such that\n  \\begin{equation*}\n    \\rho(x_k, x_m) < \\varepsilon \\quad\\forall k, m \\geq k_0.\n  \\end{equation*}\n\n  We are only interested in the case \\( \\rho(x_{k_0}, x_m) < \\varepsilon \\).\n\n  Let \\( k < k_0 \\) and \\( m \\geq k_0 \\). Then\n  \\begin{equation*}\n    \\rho(x_k, x_m) \\leq \\rho(x_k, x_{k_0}) + \\rho(x_{k_0}, x_m) < \\diam(I) + \\varepsilon,\n  \\end{equation*}\n  which is a finite number.\n\n  Thus, the distance between any two elements of the sequence is finite and the sequence is bounded.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:fundamental_subsequence_convergence}\n  In any \\hyperref[def:complete_metric_space]{metric space}, a \\hyperref[def:fundamental_net]{fundamental sequence} converges to a value if and only if it has a subsequence that converges to the same value.\n\\end{proposition}\n\\begin{proof}\n  Let \\( (X, \\rho) \\) be a metric space and let \\( \\{ x_k \\}_{k=1}^\\infty \\) be a fundamental sequence.\n\n  \\SufficiencySubProof Obvious\n  \\NecessitySubProof Assume that the subsequence \\( \\{ x_{k_n} \\}_{n=1}^\\infty \\) converges to \\( x \\). Fix \\( \\varepsilon > 0 \\). There exist \\( k_0 \\) and \\( n_0 \\) such that\n  \\begin{balign*}\n     & \\rho(x_k, x_m) < \\tfrac \\varepsilon 2 \\quad\\forall k, m \\geq k_0\n     & \\rho(x, x_{k_n}) < \\tfrac \\varepsilon 2 \\quad\\forall n \\geq n_0.\n  \\end{balign*}\n\n  Fix \\( k \\geq k_0 \\) and let \\( n \\geq n_0 \\) be such that \\( k_n \\geq k_0 \\). Then\n  \\begin{equation*}\n    \\rho(x, x_k) \\leq \\rho(x, x_{k_n}) + \\rho(x_{k_n}, x_k) < \\varepsilon.\n  \\end{equation*}\n\n  Since \\( \\varepsilon \\) was arbitrary, we conclude that \\( \\lim_{k \\to \\infty} x_k = \\lim_{n \\to \\infty} x_{k_n} = x \\).\n\\end{proof}\n\n\\begin{lemma}\\label{thm:metric_space_completion_uniqueness}\n  Let \\( X \\) be a metric space. If both \\( f: X \\to Y \\) and \\( g: X \\to Z \\) are \\hyperref[def:complete_metric_space]{completions} of \\( X \\), then \\( Y \\) and \\( Z \\) are isometric.\n\\end{lemma}\n\\begin{proof}\n  Let \\( y \\in Y \\) and let \\( \\{ x_k \\}_{k \\to \\infty} \\subseteq X \\) be a sequence such that\n  \\begin{equation*}\n    f(x_k) \\xrightarrow[k \\to \\infty]{} y.\n  \\end{equation*}\n\n  Such a sequence exists since \\( f(X) \\) is dense in \\( Y \\).\n\n  Define \\( z \\coloneqq \\lim_{k \\to \\infty} g(x_k) \\). Since both \\( f \\) and \\( g \\) are isometries, \\( z \\) does not depend on the choice of sequence \\( \\{ x_k \\}_{k \\to \\infty} \\) such that \\( f(x_k) \\to y \\). Furthermore, if \\( z \\in Z \\) is given rather than \\( y \\in Y \\), an analogous process allows us to determine \\( y \\) uniquely based on \\( z \\).\n\n  Thus, we have a bijective isometry between \\( Y \\) and \\( Z \\).\n\\end{proof}\n\n\\begin{theorem}[Metric space completion]\\label{thm:metric_space_completion}\n  Every metric space has a unique (up to an isometry) \\hyperref[def:complete_metric_space]{completion}.\n\n  This is a special case of \\fullref{thm:uniform_space_completion} that we prove fully.\n\\end{theorem}\n\\begin{proof}\n  Let \\( (X, \\rho) \\) be a metric space. Uniqueness of the completion follows from \\fullref{thm:metric_space_completion_uniqueness}. We will only show existence.\n\n  \\begin{thmenum}\n    \\thmitem{thm:metric_space_completion/part_a} First, we build the pseudometric space \\( (F, \\rho) \\). We deal with fundamental sequences and isometries in pseudometric spaces, where the definitions, however, does not change.\n\n    Define \\( F \\) to be the set of all fundamental \\hyperref[def:fundamental_net]{sequences} in X. Define the pseudometric\n    \\begin{balign*}\n       & \\rho: F \\times F \\to \\BbbR_{\\geq 0}                                                                               \\\\\n       & \\rho\\left( \\{ x_k \\}_{k=1}^\\infty, \\{ y_k \\}_{k=1}^\\infty \\right) \\coloneqq \\lim_{k \\to \\infty} \\rho(x_k, y_k).\n    \\end{balign*}\n\n    We first show that is well-defined as a \\hyperref[def:function]{function}. Let \\( \\{ x_k \\}_{k=1}^\\infty \\) and \\( \\{ y_k \\}_{k=1}^\\infty \\) be two sequences. Fix \\( \\varepsilon > 0 \\). Then there exists an \\( k_0 \\) such that\n    \\begin{equation*}\n      \\rho(x_k, x_k) < \\tfrac \\varepsilon 2 \\text{ and } \\rho(y_k, y_m) <  \\quad\\forall k, m \\geq k_0.tfrac \\varepsilon 2.\n    \\end{equation*}\n\n    Fix \\( k, m \\geq k_0 \\). Then\n    \\begin{equation*}\n      \\rho(x_k, y_k) \\leq \\rho(x_k, x_m) + \\rho(x_m, y_m) + \\rho(y_m, y_k) < \\rho(x_m, y_m) + \\varepsilon,\n    \\end{equation*}\n    hence\n    \\begin{equation*}\n      \\abs{\\rho(x_k, y_k) - \\rho(x_m, y_m)} < \\varepsilon.\n    \\end{equation*}\n\n    Thus, the sequence \\( \\{ \\rho(x_k, y_k) \\}_{k=1}^\\infty \\) is fundamental and, by \\fullref{def:set_of_real_numbers_complete_metric_space}, it is convergent.\n\n    Now we check that \\( \\rho \\) is indeed a pseudometric:\n    \\SubProofOf{def:metric_space/pseudometric_identity} For every sequence \\( x \\in F \\),\n    \\begin{equation*}\n      \\rho(x, x) = \\lim_{k \\to \\infty} \\rho(x_k, x_k) = 0.\n    \\end{equation*}\n    \\SubProofOf{def:metric_space/M2} For all sequences \\( x, y \\in F \\),\n    \\begin{equation*}\n      \\rho(x, y) = \\lim_{k \\to \\infty} \\rho(x_k, y_k) = \\lim_{k \\to \\infty} \\rho(y_k, x_k) = \\rho(y, x).\n    \\end{equation*}\n\n    \\SubProofOf{def:metric_space/M3} For all sequences \\( x, y, z \\in F \\),\n    \\begin{equation*}\n      \\rho(x, z) = \\lim_{k \\to \\infty} \\rho(x_k, z_i) \\leq \\lim_{k \\to \\infty} \\rho(x_k, y_k) + \\lim_{k \\to \\infty} \\rho(y_k, z_i) = \\rho(x, y) + \\rho(y, z).\n    \\end{equation*}\n\n    \\thmitem{thm:metric_space_completion/part_b} We prove that every fundamental sequence in \\( (F, \\rho) \\) is convergent.\n\n    Let \\( \\{ c^{(k)} \\}_{k=1}^\\infty \\) be a fundamental sequence (of sequences) in \\( (F, \\rho) \\). Thus, for every \\( k = 1, 2, \\ldots \\), there exists an index \\( n_k \\) such that\n    \\begin{equation*}\n      \\rho(c_m^{(k)}, c_{n_k}^{(k)}) < \\tfrac 1 k \\quad\\forall m \\geq n_k.\n    \\end{equation*}\n\n    Define the sequence\n    \\begin{equation*}\n      d_k \\coloneqq c_{n_k}^{(k)}, k = 1, 2, \\ldots\n    \\end{equation*}\n\n    To see that it is fundamental, fix \\( \\varepsilon > 0 \\). Now since the sequence \\( \\{ c^{(k)} \\} \\) in \\( F \\) is fundamental, there exists \\( k_0 \\) such that\n    \\begin{equation*}\n      \\rho(c^{(k)}, c^{(m)}) = \\lim_{k \\to \\infty} \\rho(c_k^{(k)}, c_k^{(m)}) < \\frac \\varepsilon 2 \\quad\\forall k, m \\geq k_0.\n    \\end{equation*}\n\n    Let \\( m_0 \\geq k_0 \\) be an index such that\n    \\begin{equation*}\n      \\frac 2 {m_0} < \\frac \\varepsilon 2.\n    \\end{equation*}\n\n    Fix \\( k \\geq m \\geq m_0 \\). Let \\( l \\geq \\max \\{ n_k, n_m \\} \\) be such that\n    \\begin{equation*}\n      \\rho(c_l^{(k)}, c_l^{(m)}) < \\frac \\varepsilon 2.\n    \\end{equation*}\n\n    Then\n    \\begin{balign*}\n      \\rho(d_k, d_m)\n       & =\n      \\rho(c_{n_k}^{(k)}, c_{n_m}^{(m)})\n      \\leq \\\\ &\\leq\n      \\rho(c_{n_k}^{(k)}, c_l^{(k)}) + \\rho(c_l^{(k)}, c_l^{(m)}) + \\rho(c_l^{(m)}, c_{n_m}^{(m)})\n      \\leq \\\\ &\\leq\n      \\frac 1 k + \\frac \\varepsilon 2 + \\frac 1 m\n      \\leq\n      \\frac 2 m + \\frac \\varepsilon 2\n      <\n      \\varepsilon.\n    \\end{balign*}\n\n    Thus, we have\n    \\begin{equation*}\n      \\rho(d_k, d_m) < \\varepsilon \\quad\\forall k \\geq m \\geq m_0,\n    \\end{equation*}\n    which proves that the sequence \\( \\{ d_k \\}_{k=1}^\\infty \\) is fundamental in \\( (X, \\rho) \\).\n\n    Now it remains to show that \\( c^{(k)} \\xrightarrow[k \\to \\infty]{} d \\) in \\( (F, \\rho) \\).\n\n    Fix \\( \\varepsilon > 0 \\) and let \\( k_0 \\) be such that\n    \\begin{equation*}\n      \\frac 1 {k_0} \\leq \\frac \\varepsilon 2.\n    \\end{equation*}\n    and\n    \\begin{equation*}\n      \\rho(d_k, d_m) < \\frac \\varepsilon 2 \\quad\\forall k, m \\geq k_0.\n    \\end{equation*}\n\n    Now fix \\( i \\geq k_0 \\). We have, for all \\( k \\geq i \\),\n    \\begin{balign*}\n      \\rho(c_{n_k}^{(k)}, d_k)\n       & =\n      \\rho(c_{n_k}^{(k)}, c_{n_k}^{(k)})\n      \\leq \\\\ &\\leq\n      \\rho(c_{n_k}^{(k)}, c_{n_k}^{(k)}) + \\rho(c_{n_k}^{(k)}, c_{n_k}^{(k)})\n      =    \\\\ &=\n      \\rho(c_{n_k}^{(k)}, c_{n_k}^{(k)}) + \\rho(d_k, d_k)\n      <    \\\\ &<\n      \\frac 1 k + \\frac \\varepsilon 2\n      <\n      \\varepsilon.\n    \\end{balign*}\n\n    Hence,\n    \\begin{balign*}\n      \\rho(c^{(k)}, d)\n      =\n      \\lim_{k \\to \\infty} \\rho(c_k^{(k)}, d_k)\n      =\n      \\lim_{k \\to \\infty} \\rho(c_k^{(k)}, c_{n_k}^{(k)})\n      <\n      \\varepsilon.\n    \\end{balign*}\n\n    Thus, given \\( \\varepsilon > 0 \\), we found an index \\( k_0 \\) such that\n    \\begin{equation*}\n      \\rho(c^{(k)}, d) < \\varepsilon \\quad\\forall g \\geq k_0.\n    \\end{equation*}\n\n    Thus, \\( d = \\lim_{k \\to \\infty} c^{(k)} \\) and \\( (F, \\rho) \\) is a complete pseudometric space.\n\n    \\thmitem{thm:metric_space_completion/part_c} We construct an isometry of \\( (X, \\rho) \\) into \\( (F, \\rho) \\).\n\n    Define the function\n    \\begin{balign*}\n       & \\iota: X \\to F                        \\\\\n       & \\iota(x) \\coloneqq (x, x, x, \\ldots),\n    \\end{balign*}\n    which sends each element of \\( X \\) into the corresponding constant sequence in \\( F \\).\n\n    It is an \\hyperref[def:isometry]{isometry} since\n    \\begin{equation*}\n      \\rho(\\iota(x),\\iota(y)) = \\lim_{k \\to \\infty} \\rho(x, y) = \\rho(x, y).\n    \\end{equation*}\n\n    \\thmitem{thm:metric_space_completion/part_d} We show that the image \\( \\iota(X) \\) is dense in \\( (F, \\rho) \\).\n\n    Fix the fundamental sequence \\( y \\coloneqq \\{ y_k \\}_{k=1}^\\infty \\). Define the sequence \\( x \\) of sequences\n    \\begin{equation*}\n      x^{(k)} \\coloneqq \\iota(y_k), i = 1, 2, \\ldots\n    \\end{equation*}\n\n    It is fundamental in \\( (F, \\rho) \\) since \\( e \\) is an isometry and since \\( y \\) is fundamental in \\( (X, \\rho) \\).\n\n    Fix \\( \\varepsilon > 0 \\). Let \\( k_0 \\) be such that\n    \\begin{equation*}\n      \\rho(y_k, y_m) < \\varepsilon \\quad\\forall k, m \\geq k_0.\n    \\end{equation*}\n\n    For \\( i, k \\geq k_0 \\), we have\n    \\begin{balign*}\n      \\rho(x_k^{(k)}, y_k)\n      \\leq\n      \\rho(x_k^{(k)}, y_k) + \\rho(y_k, y_k)\n      =\n      0 + \\rho(y_k, y_k)\n      <\n      \\varepsilon,\n    \\end{balign*}\n    hence\n    \\begin{equation*}\n      \\rho(x^{(k)}, y) = \\lim_{k \\to \\infty} \\rho(x_k^{(k)}, y_k) < \\varepsilon.\n    \\end{equation*}\n\n    We conclude that \\( x^{(k)} \\xrightarrow[k \\to \\infty]{} y \\) in \\( (F, \\rho) \\), which implies that \\( e(X) \\) is dense in \\( (F, \\rho) \\).\n\n    \\thmitem{thm:metric_space_completion/part_e} We build a complete metric space \\( (C, \\nu) \\) from \\( (F, \\rho) \\).\n\n    We use \\fullref{thm:pseudometric_to_metric} to construct a complete metric space \\( (C, \\nu) \\) from the complete pseudometric space \\( (F, \\rho) \\).\n\n    We adapt \\( \\iota \\) to the equivalence classes on \\( C \\):\n    \\begin{balign*}\n       & \\hat\\iota: X \\to C                 \\\\\n       & \\hat\\iota(x) \\coloneqq [\\iota(x)].\n    \\end{balign*}\n\n    Thus, \\( \\hat\\iota \\) embeds \\( X \\) into the complete metric space \\( C \\).\n  \\end{thmenum}\n\\end{proof}\n\n\\begin{theorem}[Cantor's nested compact theorem]\\label{thm:cantors_nested_compact_theorem}\n  A descending sequence of nonempty compact sets \\( F_1 \\supseteq F_2 \\supseteq \\ldots \\) in a complete metric space such that \\( \\diam(F_i) \\to 0 \\) intersects at exactly one point (compare with \\fullref{thm:noncompact_kuratowskis_lemma}).\n\\end{theorem}\n\\begin{proof}\n  Choose an element \\( x_k \\in F_k \\) for any \\( i = 1, 2, \\ldots \\). Then the sequence \\( \\{ x_k \\}_{k=1}^\\infty \\) is fundamental. To see this, let \\( \\varepsilon > 0 \\) and let \\( k_0 \\) be an index such that \\( \\diam(F_{k_0}) < \\varepsilon \\). Then if \\( j \\geq i \\geq k_0 \\), \\( x_m \\) is contained in \\( F_k \\) and \\( \\rho(x_k, x_m) < \\varepsilon \\). Thus, the sequence is indeed fundamental and, since the space is complete, it has a limit point \\( x \\).\n\n  The point \\( x \\) is contained in every set \\( F_k, i = 1, 2, \\ldots \\) since all of the sets \\( F_k \\) are closed (by \\fullref{thm:complete_metric_space_compact_conditions}) and contain their limit \\hyperref[thm:limit_point_iff_in_closure]{points}. Thus,\n  \\begin{equation*}\n    x \\in \\bigcap_{k=1}^\\infty F_k.\n  \\end{equation*}\n\n  Furthermore,\n  \\begin{equation*}\n    \\diam\\left( \\bigcap_{k=1}^\\infty F_k \\right) = 0,\n  \\end{equation*}\n  hence \\( x \\) is the only point in the intersection.\n\\end{proof}\n", "meta": {"hexsha": "bb683ba5bacf334c8f3df28de5c8ff9fdce13b5f", "size": 13122, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/complete_metric_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/complete_metric_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/complete_metric_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": 44.7849829352, "max_line_length": 461, "alphanum_fraction": 0.5996799268, "num_tokens": 4782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.6904758845055556}}
{"text": "\\section{Ordinal Numbers}\n\n\\subsection{Well Ordering}\n\\begin{definition}\n    A binary relation $<$ is a \\cindex{partial ordering} of $P$ if :\n    \\begin{enumerate}\n        \\item $\\forall p \\in P (p \\nless p)$.\n        \\item $p < q \\wedge q < r \\rightarrow p < r$.\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\n    A partial order $(P, <)$ is \\cindex{linear ordering} if $\\forall p \\forall q (p < q \\wedge p = q \\wedge q < p )$.\n\\end{definition}\n\n\n\\begin{definition}\n    $\\alpha$ is the \\cindex{supremum} of $X$ if $\\alpha$ is the \\cindex{least upper bound} of $X$: $\\alpha = \\supremum{X}$.\n\\end{definition}\n\n\\begin{definition}\n    $\\alpha$ is the \\cindex{infimum} of $X$ if $\\alpha$ is the \\cindex{greatest lower bound} of $X$: $\\alpha = \\infimum {X}$.\n\\end{definition}\n\n\n\\begin{definition}\n    If $(P, <)$ and $(Q,<)$ are partially ordered sets and $f: P \\rightarrow Q$, then $f$ is \\cindex{order-preserving} if $x < y \\rightarrow f(x) < f(y)$. If $P$ and $Q$ are linearly ordered, $f$ is called \\cindex{increasing}.\n\\end{definition}\n\n\\begin{definition}\n    $f: P \\rightarrow Q$  is \\cindex{isomorphism} of $P$ and $Q$ if $f$ and $f^{-1}$ are order-preserving. An isomorphism of $P$ onto itself is \\cindex{automorphism}.\n\\end{definition}\n\n\n\\begin{definition}\n    A linear ordering $<$ is \\cindex{well-ordering} if every nonempty subset of $P$ has a least element.\n\\end{definition}\n\n\\begin{theorem}\\label{wellorderedsetisomorphismisbigger}\n    If $(W,<)$ is a well-ordered set and $f:W \\rightarrow W$ is an increasing function, then $\\forall x\\in W \\left( f(x) \\geq x \\right)$.\n\\end{theorem}\n\\begin{proof}\n    If the set $X = \\set{x \\in W: f(x) < x}$ is nonempty, let $z$ be its least element and $w = f(z)$. Then $f(w) = ff(z) < f(z) = w $. So $f(w) < w \\rightarrow w \\in X \\wedge w < z$.\n\\end{proof}\n\n\\begin{theorem}\n    The only automorphism of a well-ordered set is the identity.    \n\\end{theorem}\n\\begin{proof}\n    $f(x) \\geq x$ and $f^{-1} \\geq x$.\n\\end{proof}\n\n\n\\begin{theorem}\n    If two well-ordered set $W_1$ and $W_2$ are isomorphic, then the isomorphism is unique.\n\\end{theorem}\n\\begin{proof}\n    construct a automorphism using two isomorphism.\n\\end{proof}\n\n\\begin{definition}\n    Let $(W,<)$ be an well-ordered set. $\\alpha \\in W$, the \\cindex{initial segment} $W_\\alpha$ of $W$ is defined as\n    \\begin{equation}\n        W_\\alpha = \\set{x \\in W: x < \\alpha}\n    \\end{equation}\n\\end{definition}\n\n\\begin{theorem}\n    no well-ordered set is isomorphic to an initial segment of itself.    \n\\end{theorem}\n\\begin{proof}\n    If $\\range{f} = \\set{x: x < u}$ is an initial segment, then $f(u) < u$, contrary to \\thmref{wellorderedsetisomorphismisbigger}.\n\\end{proof}\n\n\\begin{theorem}\n    If $W$ and $V$ are well-ordered sets, then one of the following holds:\n    \\begin{enumerate}\n        \\item $W$ is isomorphic to $V$.\n        \\item $W$ is isomorphic to an initial segment of $V$.\n        \\item an initial segment of $W$ is isomorphic to $V$.\n    \\end{enumerate}    \n\\end{theorem}\n\\begin{proof}\n    Define a set $f = \\set{(x,y)\\in W \\times V: W_x \\text{ is isomorphic to } V_y}$. Check the $\\domain{f}$ and $\\range{f}$.\n\\end{proof}\n\n\n\n\n\n% Ordinal Numbers\n\\subsection{Ordinal Numbers}\n\n\\begin{definition}\n    A set $T$ is \\cindex{transitive} if every element of $T$ is a subset of $T$:\n    \\begin{equation}\n        a \\in T \\rightarrow a \\subset T\n    \\end{equation}\n    or $\\cup T \\subset T$.\n\\end{definition}\n\n\\begin{definition}\n    A set is an \\cindex{ordinal number} if it is transitive and well-ordered by $\\in$. The class of all ordinals is $\\allordinals$.\n\\end{definition}\n\n\\begin{definition}\n    For two sets $\\alpha$ and $\\beta$, define a relation $<$ as $\\alpha < \\beta \\leftrightarrow \\alpha \\in \\beta$.\n\\end{definition}\n\n\\begin{theorem}\n    $\\emptyset \\in \\allordinals$\n\\end{theorem}\n\\begin{proof}\n    by definition.\n\\end{proof}\n\n\\begin{theorem}\n    $\\alpha \\in \\allordinals \\wedge \\beta \\in \\alpha \\rightarrow \\beta \\in \\allordinals$\n\\end{theorem}\n\\begin{proof}\n    $\\forall x \\in \\beta$, $x \\in \\beta \\wedge \\beta \\subset \\alpha \\rightarrow x \\in \\alpha \\rightarrow x \\subset \\alpha \\rightarrow x \\subset \\beta $.\n\\end{proof}\n\n\\begin{theorem}\n    $\\alpha \\in \\allordinals \\wedge \\beta \\in \\allordinals \\wedge \\alpha \\neq \\beta \\wedge \\alpha \\subset \\beta  \\rightarrow \\alpha \\in \\beta$    \n\\end{theorem}\n\\begin{proof}\n    Let $\\gamma$ be the least element of $\\beta - \\alpha$. Since $\\alpha$ is transitive, $\\alpha$ is an initial segment of $\\beta_\\gamma$. So $\\alpha = \\set{\\epsilon \\in \\beta: \\epsilon < \\gamma} = \\gamma$, so $\\alpha \\in \\beta$.\n\\end{proof}\n\n\\begin{theorem} \n    $\\forall \\alpha, \\beta \\in \\allordinals \\rightarrow \\alpha \\subset \\beta \\vee \\beta \\subset \\alpha$\n\\end{theorem}\n\\begin{proof}\n    Let $\\gamma = \\alpha \\cap \\beta$. $\\gamma$ is an ordinal. So $\\gamma \\subset \\alpha \\rightarrow \\gamma \\in \\alpha$, and $\\gamma \\in \\beta$, so $\\gamma \\in \\alpha \\cap \\beta = \\gamma$ and $\\gamma \\in \\gamma$.\n\\end{proof}\n\n\\begin{theorem}\n    The facts about ordinal numbers are:\n    \\begin{enumerate}\n        \\item $\\alpha = \\set{\\beta: \\beta < \\alpha}$\n        \\item If $C$ is a nonempty class of ordinals, then $\\cap C$ and $\\cup C$ are ordinals.\n        \\item $\\forall \\alpha \\in \\allordinals \\left(\\alpha \\cup \\set{\\alpha} \\in \\allordinals \\right)$ and $\\alpha \\cup \\set{\\alpha} = \\mathbf{inf} \\set{\\beta: \\beta > \\alpha}$.\n    \\end{enumerate}    \n\\end{theorem}\n\n\\begin{definition}\n    We define $\\alpha + 1 = \\alpha \\cup \\set{\\alpha}$, the \\cindex{successor} of $\\alpha$.\n\\end{definition}\n\n\\begin{theorem}\n    Every well-ordered set is isomorphic to a unique ordinal number.    \n\\end{theorem}\n\n\\begin{definition}\n    If $\\alpha = \\beta + 1$, $\\alpha$ is a \\cindex{successor ordinal}. If $\\alpha$ is not a successor ordinal, then $\\alpha = \\supremum{\\beta: \\beta < \\alpha} = \\cup \\alpha$, and is a \\cindex{limit ordinal}. $0$ is defined as a limit ordinal.\n\\end{definition}\n\n\\begin{definition}[natural numbers]\n    The least nonzero limit ordinal is denoted as $\\omega$. The ordinals less than $\\omega$ is called \\cindex{finite ordinals}, or \\cindex{natural numbers}.\n\\end{definition}\n\n\\begin{theorem}[\\cindex{Transfinite Induction}]\n    Let $C$ be a class of ordinals and assume that:\n    \\begin{enumerate}\n        \\item $0 \\in C$\n        \\item $\\alpha \\in C \\rightarrow \\alpha + 1 \\in C$\n        \\item If $\\alpha$ is a nonzero limit ordinal and $\\forall \\beta \\in \\alpha (\\beta \\in C) \\rightarrow \\alpha \\in C$.\n    \\end{enumerate}\n    Then $C = \\allordinals$.\n\\end{theorem}\n\\begin{proof}\n    choose the least $\\alpha \\notin C$.\n\\end{proof}\n\n\\begin{definition}\n    A \\cindex{transfinite sequence} is a function that the domain is an ordinal:\n    \\begin{equation}\n        \\transfinitesequence{\\alpha_\\xi : \\xi < \\alpha}\n    \\end{equation}\n\\end{definition}\n\n\\begin{theorem}[\\cindex{Transfinite Recursion}]\n    Let $G$ be a function on the class of transfinite sequence, then there is a unique function $F$ on $\\allordinals$ that $\\forall \\alpha \\in \\allordinals$:\n    \\begin{equation}\n        F(\\alpha) = G(F\\restriction_\\alpha)\n    \\end{equation}\n\\end{theorem}\n\n\\begin{definition}\n    Let $\\alpha>0$ be a limit ordinal and $\\transfinitesequence{\\gamma_\\xi : \\xi < \\alpha}$ be a nondecreasing sequence of ordinals. The \\cindex{limit} of the sequence is\n    \\begin{equation}\n        \\lim_{\\xi \\rightarrow \\alpha} \\gamma_\\xi = \\supremum{\\gamma_\\xi : \\xi < \\alpha}\n    \\end{equation}\n    It is possible that $\\displaystyle \\lim_{\\xi \\rightarrow \\alpha} \\gamma_\\xi \\notin \\transfinitesequence{\\gamma_\\xi : \\xi < \\alpha}$.\n\\end{definition}\n\n\\begin{definition}\n    A sequence of ordinal $\\transfinitesequence{\\gamma_\\alpha : \\alpha \\in \\allordinals}$ is \\cindex{normal} if it is increasing and \\cindex{continuous}, that is for every limit ordinal $\\alpha$, $\\displaystyle \\gamma_\\alpha = \\lim_{\\beta \\rightarrow \\alpha} \\gamma_\\beta$.\n\\end{definition}\n\n\n\n% Ordinal Arithmetic\n\\subsection{Ordinal Arithmetic}\n\n\\begin{theorem}\n    For all ordinal $\\alpha$ and $\\beta$, we have:\n    \\begin{enumerate}\n        \\item $\\alpha + 0 = \\alpha$\n        \\item $\\alpha + (\\beta + 1) = (\\alpha + \\beta) + 1$\n        \\item $\\displaystyle \\alpha + \\beta = \\lim_{\\xi \\rightarrow \\beta} (\\alpha + \\xi)$ for all limit ordinal $\\beta > 0$.\n        \\item $\\alpha \\cdot 0 = 0$\n        \\item $\\alpha \\cdot (\\beta + 1) = \\alpha \\cdot \\beta + \\alpha$\n        \\item $\\displaystyle \\alpha \\cdot \\beta = \\lim_{\\xi \\rightarrow \\beta} \\alpha \\cdot \\beta$ for all limit ordinal $\\beta > 0$\n        \\item $\\alpha^0 = 1$\n        \\item $\\alpha^{\\beta + 1} = \\alpha^\\beta \\cdot \\alpha$\n        \\item $\\displaystyle \\alpha^\\beta = \\lim_{\\xi \\rightarrow \\beta} \\alpha^\\xi$ for all limit ordinal $\\beta > 0$.\n    \\end{enumerate}    \n    So $\\alpha + \\beta$, $\\alpha \\cdot \\beta$, and $\\alpha^\\beta$ are normal function in second variable $\\beta$. Note that neither $+$ nor $\\cdot$ is commutative:\n    \\begin{equation}\n        \\begin{aligned}\n            1 + \\omega = \\omega &\\neq \\omega + 1 \\\\\n            2 \\cdot \\omega = \\omega &\\neq \\omega \\cdot 2 = \\omega + \\omega\n        \\end{aligned}\n    \\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\n    For all ordinal $\\alpha$ and $\\beta$, we have:\n    \\begin{enumerate}\n        \\item $\\beta < \\gamma \\rightarrow \\alpha + \\beta < \\alpha + \\gamma$\n        \\item If $ \\alpha < \\beta$, there is a unique $\\delta$ that $\\alpha + \\delta = \\beta$.\n        \\item $\\beta < \\gamma \\wedge \\alpha > 0 \\rightarrow \\alpha \\cdot \\beta < \\alpha \\cdot \\gamma$\n        \\item If $\\alpha > 0$, there is a unique $\\beta$ and $\\rho < \\alpha$ that $\\gamma = \\alpha \\cdot \\beta + \\rho$.\n        \\item $\\beta < \\gamma \\wedge \\alpha > 1 \\rightarrow \\alpha^\\beta < \\alpha^\\gamma$\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}[\\cindex{Cantor's Normal Form Theorem}]\n    Every ordinal $\\alpha > 0$ has a unique representation:\n    \\begin{equation}\n        \\alpha = \\omega^{\\beta_1} \\cdot k_1 + \\dots + \\omega^{\\beta_n} \\cdot k_n\n    \\end{equation}\n    where $n \\geq 1$, $\\alpha \\geq \\beta_1 > \\dots > \\beta_n$, and $k_i$ are nonzero natural numbers.\n\\end{theorem}\n\\begin{proof}\n    use induction. $\\forall \\alpha > 0$, let $\\beta$ be the greatest ordinal number that $\\omega^\\beta \\leq \\alpha$. There is a unique $\\delta$ and $\\rho < \\omega^\\beta$ that $\\alpha = \\omega^\\beta + \\rho$. \n\\end{proof}\n\n\n\n\n% well-founded relations\n\\subsection{Well-Founded Relations}\n\n\\begin{definition}\n    A binary relation $E$ on a set $P$ is \\cindex{well-founded} if every nonempty $X \\subset P$ has a $E$-minimal element, that is $\\forall a \\in X$ there is no $x \\in X$ that $x E a$.\n\\end{definition}\n\n\\begin{theorem}\n    If $E$ is a well-founded relation on $P$, there is a unique function $\\rho : P \\rightarrow \\allordinals$ that $\\forall x \\in P$:\n    \\begin{equation}\n        \\rho(x) = \\supremum{\\rho (y) + 1: y E x}\n    \\end{equation}\n    \n    The range of $\\rho$ is an initial segment of ordinals and is an ordinal number, which is the \\cindex{height} of $E$.\n\\end{theorem}\n\\begin{proof}\n    Define a $P$ that\n    \\begin{equation}\n        \\begin{aligned}\n            P_0 &= \\emptyset \\\\\n            P_{\\alpha + 1} &= \\set{x \\in P: \\forall y (y E x \\rightarrow y \\in P_\\alpha )} \\\\\n            P_\\alpha &= \\bigcup_{\\xi < \\alpha} P_\\xi \\text{ , if } \\alpha \\text{ is a limit ordinal}\n        \\end{aligned}\n    \\end{equation}\n    Let $\\theta$ be the least ordinal that $P_{\\theta +1} = P_\\theta$.\n\\end{proof}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "0d5a0a854f0c1d4b96f39c57870fca1504618eb9", "size": 11458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/set_theory/st.2.ordinalnumbers.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/set_theory/st.2.ordinalnumbers.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/set_theory/st.2.ordinalnumbers.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": 35.9184952978, "max_line_length": 273, "alphanum_fraction": 0.6378949206, "num_tokens": 3607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6904594038629425}}
{"text": "\\lab{Algorithms}{Krylov Subspaces}{Finding Eigenvalues Using Iterative Methods}\n\\label{lab:kry_arnoldi}\n\n\\objective{Discuss simple Krylov Subspace Methods for finding eigenvalues and show some interesting applications.}\n\nIn the realm of numerical linear algebra, Krylov Subspace Methods are considered some of the most successful  methods ever invented.\nThey are simple and robust and can be used to find approximate solutions to linear systems and eigenvalue problems involving extremely\nlarge matrices.\nOne of the reasons for this success is that they do not require copies or modifications of the original\nmatrix.\nKrylov subspace methods are used to estimate certain properties of a matrix based on how it acts on vectors through matrix multiplication.\nThis is especially useful for large sparse matrices (allowing us to deal with the matrix in compressed form),\nand for matrices that have symmetries that reduce storage and enable faster matrix multiplication (allowing us to use\nspecialized algorithms like the Fast Fourier Transform rather than the full matrix).\n\nThe general approach of Krylov subspace methods is to consider how a given matrix $A$ acts on the span of\n$\\{ x, Ax, A^2 x, \\ldots, A^{N-1} x \\}$ (called an \\emph{order-$N$ Krylov Subspace generated by $A$ and $x$}), where $N$ is significantly\nsmaller than the number of rows of $A$.\nThe formation of these subspaces in an efficient and numerically stable manner is usually based on either the \\emph{Arnoldi\niteration} or the \\emph{Lanczos iteration}. We will discuss both of these algorithms here.\n\n\\section*{The Arnoldi Iteration}\n\nBefore discussing the specific uses of the Krylov subspace in linear systems and eigenvalue problems, let us address a very\npractical concern: how can we best compute a basis for the Krylov subspace? The obvious answer is simply to\ncalculate 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$\nas $n$ gets large, and consequently these vectors become nearly parallel. Thus, the basis $\\{x, Ax, A^2x, \\ldots, A^{N-1} x\\}$\nis far from orthogonal, and matrix computations associated with this basis will likely be ill-conditioned and prone to\nnumerical instability. To redress this problem, we may think to apply the Gram-Schmidt orthogonalization process to the\nbasis, obtaining an orthonormal basis for the Krylov subspace that enjoys much better numerical properties. This turns out to\nbe 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\nvectors but does not require that we run the algorithm to is 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\n 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,\nsubtracting out these projections, and then normalizing. To make this more precise, let $h_{i,n} = \\langle q_i, A q_n\\rangle$\nfor $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. This 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,\ndespite this difference. And because of this detail, we do not need to compute and store the original Krylov basis\n$x, Ax, \\ldots, A^{N-1}x$.\nAdditionally, each iteration only requires one matrix-vector calculation, and the individual entries in $A$ are never\nreferenced or modified. Thus, even if the matrix $A$ is very large in theory, as long as we have a reasonably efficient\nsubroutine to calculate $Ax$ for any vector $x$, the Arnoldi iteration is computationally tractable.\n\nThis algorithm produces an othonormal basis $q_1,\\ldots,q_N$ for the order-$N$ Krylov subspace generated by $A$ and $x$, as well\nas a collection of numbers $h_{i,j}$. If we define a matrix $H_N$ whose $i,j$'th entry is $h_{i,j}$ for $i \\leq j+1$ and\nis $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\nare equal to zero. Any square matrix is unitarily similar to an upper Hessenberg matrix. Dealing with a Hessenberg matrix is\noften more convenient than dealing with a general matrix, especially when it comes to finding eigenvalues or solving systems\nof 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\nthe upper left $N \\times N$ submatrix of $H$ is equal to $H_N$. Hence, the Arnoldi iteration provides a connection between\nthe Krylov subspace and the Hessenberg factorization of a matrix. Each step in the Arnoldi iteration can be thought of as computing\nanother step in the Hessenberg reduction of $A$. Each $H_N$ is really just the $N \\times N + 1$ upper-left block of $H$.\nSolving eigenvalue problems or systems of equations for\na general square matrix can thus be reduced, via Arnoldi iteration, to solving these problems for a Hessenberg matrix,\na 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\nalternatively, 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\nHessenberg 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. This is advantageous when, as\nis often the case, the behavior and properties of a matrix can be well-approximated by only a small portion of its Hessenberg\nform.\n\n%The idea is to construct a set of vectors that allow us to roughly approximate the action of a very large matrix on the subspace.\n%This involves forming only a portion of the actual Hessenberg reduction of the Hessenberg factorization of the matrix.\n%You may recall from lab \\ref{lab:QRdecomp} that the Modified Gram-Schmidt algorithm allows us to find an increasing number of orthogonal\n%vectors but does not require that we run the algorithm to is completion to find a full basis.\n%In the Arnoldi iteration we use the Modified Gram-Schmidt algorithm to compute progressively larger portions of the matrices $Q$ and $H$\n%in the Hessenberg factorization of $A$.\n%These intermediate matrices often carry a significant amount of information about $A$, and we can get away with storing small portions of\n%them instead of having to store a dense version of the matrix $A$.\n%The Arnoldi iteration is outlined in Algorithm \\ref{alg:arnoldi_iteration}.\n%We will now consider the ideas underlying the Arnoldi iteration in further detail.\n%\n%Let $A$ be an extremely large matrix that we do not wish to modify.\n%We will assume that we have some sort of method for computing $A v$ for any vector $v$, but we will not make any other assumptions\n%relating to how $A$ is stored or what properties it has.\n%Write the Hessenberg factorization of $A$ as\n%\\[\n%Q^* A Q = H,\n%\\]\n%where $Q$ is a unitary matrix and $H$ is Upper Hessenberg.\n%\n%We would like to compute the columns of $Q$ one-by-one.\n%Let $q_k$ be the $k$'th column of $Q$ and $h_{i,j}$ be the $i,j$'th element of $H$.\n%From matrix multiplication we have that\n%\\[A q_n = h_{0, n} q_0 + \\dots + h_{n, n} q_n + h_{n+1, n} q_{n+1}\\]\n%This can be rewritten as\n%\\[h_{n+1, n} q_{n+1} = A q_n - h_{0,n} q_0 - \\dots - h_{n,n} q_n\\]\n%Since each column of $Q$ has norm $1$, this allows computation of each $q_k$ based on each of the previous columns.\n%This recurrence relation does not provide any constraint on the first column of $Q$.\n%In practice, if we are searching for eigenvalues we can use a normalized random vector as the first column of $Q$.\n%These columns of $Q$ allow compution of partial reductions of $A$ to Hessenberg form without any modification of $A$.\n%This can seen as follows:\n%\n%Let $Q_k$ be the first $k$ columns of $Q$.\n%Let $Q_u$ be the remaining columns of $Q$.\n%We then have that\n%\\[H = Q^T A Q =\n%\\begin{bmatrix}\n%Q_k^* A Q_k & Q_k^* A Q_u \\\\\n%Q_u^* A Q_k & Q_u^* A Q_u\n%\\end{bmatrix}\\]\n%Since $H$ is Upper Hessenberg, so is the matrix $Q_k^* A Q_k$ in the upper left corner.\n%Let $H_k = Q_k^* A Q_k$.\n%Note that we really only need to store the columns of $Q$ that we have already computed.\n%We can also construct the $H_k$ as we go.\n%\n%\\begin{info}\n%The recurrence relation for computing $q_{n+1}$ is the same expression that would be used to perform Gram-Schmidt orthogonalization\n%to project $A q_n$ orthogonal to the vectors $\\{ q_0, \\dots, q_n \\}$.\n%This allows for an alternate characterization of the Arnoldi iteration.\n%We first choose a normalized random vector $q_0$, then perform the Modified Gram-Schmidt algorithm on the vectors\n%$A q_0, A q_1, A q_2, \\dots$.\n%\\end{info}\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{arnoldi}{$b, Amul, k, tol=1E-8$}\n\t\\State $m \\gets b.size$\t\t\t\t\t\t\\Comment{Some initialization steps}\n\t\\State $Q \\gets \\text{empty}\\left(m, k+1\\right)$\n\t\\State $H \\gets \\text{zeros}\\left( k+1, k\\right)$\n\t\\State $q_0 = b$\t\t\t\t\t\t\t\\Comment{Set $q_0$ equal to $b$.}\n\t\\State $q_0 /= \\|q_0\\|_2$\t\t\t\t\t\t\\Comment{Normalize $q_0$.}\n\t\\For{$j=0$, $j<k$}\t\t\t\t\t\t\t\\Comment{Perform the actual iteration.}\n\t\t\\State $q_{j+1} = Amul \\left(q_j\\right)$\t\t\\Comment{Compute $A q_j$.}\n\t\t\\For{$i=0$, $i<j+1$}\t\t\t\t\t\\Comment{Modified Gram-Schmidt.}\n\t\t\t\\State $h_{i,j} = \\langle q_i, q_{j+1}\\rangle$\t\t\\Comment{Set values of $H$.}\n\t\t\t\\State $q_{j+1} -= h_{i,j} q_i$\n\t\t\\EndFor\n\t\t\\State $h_{j+1,j} = \\|q_{j+1}\\|_2$\t\t\t\\Comment{Set subdiagonal element of $H$.}\n            \\If{$|h_{j+1,j}|<tol$}\t\t\t\t\t\\Comment{Stop if $\\|q_{j+1}\\|_2$ is too small.}\n\t\t\t\\State \\pseudoli{return} $H[:j,:j]$\n\t\t\\EndIf\n\t\t\\State $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]$\t\t\t\t\\Comment{Return $H_{k}$.}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Arnoldi Iteration}\n\\label{alg:arnoldi_iteration}\n\\end{algorithm}\n\n\\begin{warn}\nTo avoid errors involving the casting of complex numbers to real numbers make the datatypes of $H$ and $Q$ complex.\nMake sure you account for the use of complex numbers when computing the norm.\nYou will also want to use the complex version of the \\li{sqrt} function.\nThis function is in the built in \\li{cmath} library.\n\\end{warn}\n\nNotice that in Algorithm \\ref{alg:arnoldi_iteration}, $k$ is the number of times to multiply by $A$.\nThis will result in a dimension $k+1$ Krylov Subspace.\n\n\\begin{problem}\nWrite a Python function that performs the Arnoldi iteration given a nonzero starting vector $b$, a function to multiply a\nvector on the left by some matrix $A$, and a number $n$ of steps to perform.\nAlso have it accept a tolerance parameter that defaults to \\li{1E-8}.\nHave it return the computed $H_n$ and $Q_n$.\n\\end{problem}\n\n\\begin{info}\nDepending on the matrix $A$, the Arnoldi iteration may end quickly.\nThis happens when there is a subspace $G$ that is fixed under left multiplication by $A$.\nIn this particular case, the matrix $H_k$ exactly matches the way $A$ acts on $G$.\nThis means that the eigenvalues of $H_k$ are eigenvalues of $A$.\nThe eigenvectors of $H$ will also be eigenvectors of $A$ after the change of basis defined by $Q_k$.\n\\end{info}\n\n% Make a 3D plot showing the projection. Label the initial vector x and Ax.\n\n\\section*{Finding Eigenvalues Using Arnoldi iteration}\n\nIt is relatively easy to understand how Arnoldi iteration finds eigenvalues of a matrix.\nIn simple terms, the eigenvalues of the $H_k$ converge to the eigenvalues of $A$.\nThe eigenvalues of the $H_k$ are called Ritz values.\nThis can happen very quickly, but, in general, the rate of convergence depends on the matrix $A$.\nThis works because each $H_k$ is a kind of lower-dimensional approximation of $A$.\nIn adding the projection of $A q_n$ orthogonal to $q_0, \\ldots, q_n$, we are really including the only portion\nof the space spanned by the image of $q_0, \\dots, q_n$ under $A$ that is not already included in their span.\nGenerally speaking, the Ritz values converge most quickly to the eigenvalues of largest magnitude.\nConvergence is also faster for eigenvalues that are relatively far from the other eigenvalues of $A$.\nFigures \\ref{fig:arnoldi_random_eig_conv} and \\ref{fig:arnoldi_random_val_conv} show the convergence of the\nRitz values to the largest eigenvalues of some different matrices.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{rand_eigs_conv.pdf}\n\\caption{The convergence of the Ritz values to the largest eigenvalues of a matrix with random eigenvalues between $0$ and $1$.}\n\\label{fig:arnoldi_random_eig_conv}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{rand_vals_conv.pdf}\n\\caption{The convergence of the Ritz values to the largest eigenvalues of a matrix with random entries between $0$ and $1$.\nMatrices of this form generally have a single isolated eigenvalue that is much larger than the rest.\nIt can be seen here that the Ritz values converge to this eigenvalue much more quickly.}\n\\label{fig:arnoldi_random_val_conv}\n\\end{figure}\n\n\\begin{problem}\nRun the Arnoldi iteration on a random $100 \\times 100$ array $A$.\nUse a random vector as a starting point.\nFind $H_{40}$ and compare the $10$ eigenvalues of largest magnitude of $H_{40}$ with the $10$ eigenvalues of largest magnitude of $A$.\nArnoldi iteration is not the most effective way to work with dense matrices without significant patterns, but this example does illustrate the desired convergence.\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:fourier_eigs}\nThe Discrete Fourier Transform is a linear operator, so it has a matrix representation.\nThis matrix representation is well known and the symmetries that arise in it are used in computing the Fast Fourier Transform.\nFast Fourier Transforms are discussed in much greater detail in Volume 2.\n\nSince the Fast Fourier Transform is a linear operator, it also has eigenvalues and eigenvectors.\nThe eigenvalues are known to be $\\{ -1, 1, -i, i \\}$.\nUse your implementation of the Arnoldi iteration to estimate the eigenvalues of the Discrete Fourier Transform.\nThis can be done by passing the \\li{fft} function from either \\li{pyfftw.interfaces.scipy_fftpack} or \\li{scipy.fftpack} as the argument \\li{Amul} to your function for the Arnoldi iteration.\nLet $b$ be a random real-valued array of size $2^{20}$.\nLet $k = 10$.\nYou will need to either divide your computed eigenvalues or your computed value for each $A q_i$ by $2^{10}$ (the square root of the length of $b$).\nThis is a normalizing factor that comes from the way the Fast Fourier Transform is defined.\n\nAll the eigenvalues of the Discrete Fourier Transform should show up most of the times this code is run.\n\\end{problem}\n\nProblem \\ref{prob:fourier_eigs} shows how Arnoldi Iteration works nicely on matrices with useful patterns.\nWhat is remarkable is that the matrix representation of the Fast Fourier Transform for length $2^{20}$ vectors would be a $2^{20} \\times 2^{20}$ complex valued matrix.\nAt that size it would take $64$ TB of space just to store it.\nThanks to the Fast Fourier Transform algorithm we are able to compute the Fourier Transform without ever explicitly forming this massive matrix.\nUsing the Arnoldi iteration we can also estimate its eigenvalues.\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\\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\\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\\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.absolute(roots).argsort()][::-1]\n\\end{lstlisting}\nHow close are the first few zeros of largest norm?\n\\end{problem}\n\n\\section*{Lanczos Iteration}\n\nDepending on the symmetry of the problem we may be able to make the Arnoldi iteration more efficient.\nConsider the case that $A$ is symmetric.\nThis means that the matrx $H$ is both Upper Hessenberg and symmetric, so it is tridiagonal.\nSince $H$ is tridiagonal, we \\textit{should} have that each $A q_n$ is orthogonal to $q_0, \\dots, q_{n-2}$.\nThis means that storage of all the columns of $Q_k$ is no longer necessary.\nWe can run the entire algorithm while storing only the previous two columns of $Q$ that we have computed.\nWe can also represent $H$ as two vectors: a vector $\\alpha$ storing the values along the main diagonal of $H$, and a vector $\\beta$ storing the values in the first subdiagonal (the values in the first superdiagonal are the same).\nThis change in the way things are stored allows Algorithm \\ref{alg:arnoldi_iteration} to be simplified to Algorithm \\ref{alg:lanczos_iteration}.\nAlgorithm \\ref{alg:lanczos_iteration} is known as the Lanczos iteration.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{lanczos}{$b, Amul, k, tol=1E-8$}\n\t\\State $q_0 \\gets 0$\t\t\t\t\t\t\t\t\\Comment{Some initialization}\n\t\\State $q_1 \\gets \\frac{b}{\\|b\\|_2}$\n\t\\State $\\alpha \\gets \\text{empty}\\left(k\\right)$\n\t\\State $\\beta \\gets \\text{empty}\\left(k\\right)$\n\t\\State $\\beta_{-1} = 0$\n\t\\For{$i=0$, $i<k$}\t\t\t\t\t\t\t\t\t\\Comment{Perform the iteration.}\n\t\t\\State $z \\gets Amul\\left(q_1\\right)$\t\t\t\t\t\\Comment{$z$ is a temporary vector to store $q_{i+1}$.}\n\t\t\\State $\\alpha_i = \\langle q_1, z \\rangle$\t\t\t\t\\Comment{$q_1$ is used to store the previous $q_i$.}\n\t\t\\State $z -= \\alpha_i q_1 + \\beta_{i-1} q_0$\t\t\t\t\\Comment{$q_0$ is used to store $q_{i-1}$.}\n\t\t\\State $\\beta_{i} = \\|z\\|_2$\t\t\t\t\t\t\\Comment{Initialize $\\beta_i$.}\n\t\t\\If{$\\beta_i<tol$}\t\t\t\t\t\t\t\t\\Comment{Stop if $\\|q_{i+1}\\|_2$ is too small.}\n\t\t\t\\State \\pseudoli{return} $\\alpha [: i+1]$, $\\beta [: i]$\n\t\t\\EndIf\n\t\t\\State $z /= \\beta_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} $\\alpha$, $\\beta [: -1]$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Lanczos Iteration}\n\\label{alg:lanczos_iteration}\n\\end{algorithm}\n\n\\begin{problem}\n\\label{prob:lanczos}\nWrite a Python function that performs the Lanczos iteration.\nHave it accept a starting vector $b$, a function $Amul$ that computes $A x$ for any vector $x$, a number $k$ of iterations to perform, and an optional argument $tol$ that defaults to \\li{1E-8}.\n\\end{problem}\n\nIn its most basic form the Lanczos iteration is not stable.\nIn exact arithmetic the vectors $q_i$ are exactly orthogonal, but in the presence of roundoff error this may be absolutely false.\nIn imprecise arithmetic, it is possible for the $q_i$ to suffer from so much roundoff error that \\textit{they may no longer even be linearly independent}.\nThere are a variety of modifications to the Lanczos iteration that address this instability.\nThe library used for Lanczos iteration in Scipy uses an algorithm called the Implicitly Restarted Lanczos Method.\nWe will not discuss these algorithms in detail here.\n\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{problem}\nThe following code performs matrix multiplication by a tridiagonal symmetric matrix.\nIt accepts vectors $a$ and $b$ and $u$.\n$a$ stores the entries in the main diagonal of the matrix.\n$b$ stores the entries in the first sub/superdiagonal.\nThe function returns the image of $u$ under the matrix represented by $a$ and $b$.\n\n\\begin{lstlisting}\ndef tri_mul(a, b, u):\n    v = a * u\n    v[:-1] += b * u[1:]\n    v[1:] += b * u[:-1]\n    return v\n\\end{lstlisting}\n\nUse the Lanczos iteration function you wrote for Problem \\ref{prob:lanczos} to estimate the $5$ largest eigenvalues of a symmetric tridiagonal matrix $A$ with random values in its nonzero diagonals (i.e. make $a$ and $b$ random).\nFor demonstration purposes, let $A$ be $1000 \\times 1000$.\nPerform $100$ iterations.\nCompare the $5$ eigenvalues of largest absolute value with the $5$ Ritz values of largest norm.\nHow do they compare?\n\nTry running your simulation a few times for different vectors $a$ and $b$.\nYou may notice that, occasionally, the largest eigenvalue is repeated in the Ritz values.\nThis happens because of the lack of orthogonality between the vectors used in the Lanczos iteration.\nThese erroneous eigenvaleus are called ``ghost eigenvalues.\"\nThey 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\n\\section*{Arnoldi Iteration in SciPy}\n\nSciPy interfaces with a Fortran library called ARPACK that has good implementations of the Arnoldi and Lanczos algorithms.\nThe Arnoldi iteration is found in \\li{scipy.sparse.linalg.eigs}.\nThe Implicitly Restarted Lanczos iteration is found in \\li{scipy.sparse.linalg.eigsh}\nThese functions allow you to find either the largest or smallest eigenvalues of a sparse or dense matrix.\nThe function \\li{scipy.sparse.linalg.svds} uses the Implicitly Restarted Lanczos iteration on $A^* A$ to find singular values.\n\n\\begin{problem}\nIn Lab \\ref{lab:MarkovGraph} we discussed how to find the Laplacian Matrix of a graph.\nThe second-smallest eigenvalue of a graph is known as the ``Fiedler Value\" or the ``algebraic connectivity.\"\nThe algebraic connectivity of a graph is positive if the graph is connected and zero if it is not.\nIn general, the multiplicity of the eigenvalue $0$ in the Laplacian matrix of a graph is the number of connected components of that graph.\nThe following code constructs the Laplacian matrix of a graph composed of a line of nodes.\nThe matrix is stored in \\li{dia_matrix} format.\n\\begin{lstlisting}\nimport scipy.sparse as ss\nm = 1000\nd = np.ones(m)\nd[1:-1] += np.ones(m-2)\nl = ss.diags([-np.ones(m-1), d, -np.ones(m-1)], [-1, 0, 1])\n\\end{lstlisting}\nUse the \\li{eigsh} function to verify that this graph is connected.\nYou should look at documentation for the \\li{scipy.sparse} library and find the options you need to use.\nFor proper convergence you will want to leave the number of eigenvalues computed at its default value.\n\nThe following code constructs the Laplacian matrix the same graph as before except that a single edge has been removed.\n\\begin{lstlisting}\nm = 1000\ncut = 500\nd = np.ones(m)\nd[1:-1] += np.ones(m-2)\nd1 = -np.ones(m-1)\nd1[cut] = 0\nd[[cut, cut+1]] =1\nl = ss.diags([d1, d, d1], [-1, 0, 1])\n\\end{lstlisting}\nVerify that this graph is not connected.\n\\end{problem}\n", "meta": {"hexsha": "30566a0184bd12cde468fdde98a319d66126261a", "size": 25088, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/arnoldi_iteration/arnoldi_iteration.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/arnoldi_iteration/arnoldi_iteration.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/arnoldi_iteration/arnoldi_iteration.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": 60.1630695444, "max_line_length": 229, "alphanum_fraction": 0.7498007015, "num_tokens": 6938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.6904201391013592}}
{"text": "% !TEX root = main.tex\n\n%------------------------------------------------\n\\chapter{Introductory Examples}\n\n\\begin{example} \nRadioactive isotope decays according to the differential $$\\frac{dm}{dt} = -km$$ where $k > 0$ is constant. $m$ is the mass present at time $t$.\nFind the half life such that $m(\\tau) = \\frac{1}{2}m(0)$\n\\end{example}\n\\bigskip\n\n\\begin{example}  A student goes home for Christmas leaving a mouldy burger under the sofa. The mould grows according to $$\\frac{dm}{dt} = km$$ where $ k > 0$ is constant. Find the time $\\tau = 0$ at which $m(\\tau) > M$, assuming $m(0)$ is known. Here $M$ is the mass of the sofa.\n\\end{example}\n\\bigskip\n\n\\begin{example}  The previous model is changed to $$\\frac{dm}{dt} = km(M-m)$$ where $k > 0$, $M > 0$ are constants. Show how the solution behaves.\n\\end{example}\n\\bigskip\n\n\\begin{example}  Show that the differential equation $$\\frac{dy}{dt} = 2\\sqrt[]{y}$$ has more than one solution with :\n$$y_1(t) = t^2 \\mbox{ for t } {\\geq} \\mbox{ 0}$$\n$$y_2(t) = \\mbox{ 0 for all t }$$\nA third solution :\n$$\ny_3 (t) = \\begin{cases}\ny_2(t) \\mbox{ for t } \\leq \\mbox{ 0} \\\\\ny_1(t) \\mbox{ for t } > \\mbox{ 0} \n\\end{cases} $$\n\\end{example}\n\\bigskip\n\n\\begin{example}\nShow that the solutions of the equation : $$\\frac{dy}{dt} = 1 + y^2$$ blows up in finite time.\n\\end{example}\n\n\n%------------------------------------------------\n\\endinput\n", "meta": {"hexsha": "a9f135dc11c0439a3a30164ad7a035fb0e705833", "size": 1374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L4/MA1001/Introductory_Examples.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/Introductory_Examples.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/Introductory_Examples.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 35.2307692308, "max_line_length": 279, "alphanum_fraction": 0.6048034934, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.6904201358037054}}
{"text": "\\subsubsection{Hyperboloids of Two Sheets}\r\n\\noindent\r\nA hyperboloid of two sheets has 2 -'s and 1 + in its equation. It is made up of two disconnected, mirror image, surfaces.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./Images/differentialMultivariableCalculus/two_sheets.png}\r\n\t\\caption{A hyperboloid of two sheets}\r\n\\end{figure}", "meta": {"hexsha": "5d50babddc02cd0406a9b8b38d8ecd29af36b474", "size": 364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/hyperboloidTwoSheet.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/hyperboloidTwoSheet.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/hyperboloidTwoSheet.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": 40.4444444444, "max_line_length": 122, "alphanum_fraction": 0.7664835165, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.6904201352621983}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Airplane seating}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Airplane seating}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Airplane seating}\n\n\\vspace{10 mm}\n\\begin{problem}\n A line of $n$ airline passengers is waiting to board a plane. They each hold a ticket to one of the $n$ seats on that flight. (For convenience, let's say that the $i$th passenger in line has a ticket for the seat number $i$.) Unfortunately, the first person in line is crazy, and will ignore the seat number on their ticket, picking a random seat to occupy. All of the other passengers are quite normal, and will go to their proper seat unless it is already occupied. If it is occupied they will then find a free seat to sit in, at random. What is the probability that the last ($n$th)\nperson to board the plane will sit in their proper seat (\\#$n$)?\n\\end{problem}\n\nAny seat arrangement under the rules of the problem is a permutation $\\pi$ from the set $S_n$ of permutations of size $n$. Let's define $A_n \\subseteq S_n$ the subset of permutations of size $n$ that are valid seat arrangements. \n\nLet $B_n := \\{\\pi \\in A_n: \\pi(n) = n\\}$ be the subset of $A_n$ where the last person gets their proper seat. A strategy to solve the problem would be to count $|A_n|$ and $|B_n|$ and then divide them up to get the probability. \n\nWe will use the permutation cycle notation $(i_1,i_2,\\ldots,i_k)$ for a cycle of length $k$ that maps $i_1 \\mapsto i_2 \\mapsto \\ldots i_k\\mapsto i_1$. Also let $\\iota_n$ be the identity permutation in $S_n$ and let $A_n^* = A_n \\setminus \\{\\iota_n\\}$ and $B_n^* = B_n \\setminus \\{\\iota_n\\}$.\n\nLet's characterize permutations in $A_n^*$.\n\n\\begin{lem}\\label{a_n}\nA permutation $\\pi \\in A_n^*$ is a cycle of the form\n\\begin{equation*}\n\\pi = (1, i_1, i_2,\\ldots, i_k)  \\text{ with } 2 \\leq i_1 < i_2 < \\ldots < i_k \\leq n\n\\end{equation*}  \n\\end{lem}\n\n\\begin{proof}\n\nConsider $\\pi \\in A_n^*$. Suppose $\\pi(1) = 1$ then under the rules of the problem all other passengers can occupy their seat and $\\pi =\\iota_n$ which is a contradiction because $A_n^*$ doesn't have the identity permutation. So there exists a $i_1 \\in \\{2,\\ldots,n\\}$ with $\\pi(1) = i_1$.  $i_1$ cannot map to any $j  <  i_1$ because under the rules of the problem every $j  < i_1$ maps to itself (every $j < i_1$ finds their seat unoccupied so they take it). So there exists a $i_2 \\in \\{2,\\ldots,n\\}$ with $i_2 >i_1$ and $i_1 \\mapsto i_2$. And so on. This means that $\\pi$ has at least the cycle $(1, i_1, i_2,\\ldots, i_k)$ with $2 \\leq i_1 < i_2 < \\ldots < i_k \\leq n$. It cannot have any other cycles that don't have $1$ in them because under the rules of the problem only passenger $1$ can start a seat rearrangement and all passengers not affected by that rearrangement will occupy their seat. \n\n\\end{proof}\n\n\\begin{defn}\\label{func}\nLet $2^{\\{2,\\ldots,n\\}}$ be the set of all subsets of $\\{2,\\ldots,n\\}$. The function $\\varphi: 2^{\\{2,\\ldots,n\\}} \\rightarrow S_n$ is defined as:\n\\begin{equation*}\n    \\begin{split}\n        \\varphi(\\oslash) & = \\iota_n \\\\\n        \\varphi(\\{i_1, i_2,\\ldots, i_k\\}) & =  (1, i_1, i_2,\\ldots, i_k) \\\\\n             \\text{assuming } & 2 \\leq i_1 < i_2 < \\ldots < i_k \\leq n\n    \\end{split}\n\\end{equation*}\n\\end{defn}\n\n$\\varphi$ is a valid function because for each subset there is only one cycle possible with the monotonically increasing ordering. From lemma \\ref{a_n} it then follows that  $\\varphi(2^{\\{2,\\ldots,n\\}}) = A_n$, so $|A_n| = 2^{n -1}$.\n\nFor $B_n$ we apply the same arguments, except we take out the n-th passenger. A permutation $\\pi' \\in B_n^*$ is a cycle of the form\n\n\\begin{equation*}\n\\pi' = (1, i_1, i_2,\\ldots, i_k)  \\text{ with } 2 \\leq i_1 < i_2 < \\ldots < i_k \\leq n -1\n\\end{equation*}  \n\nand there is a function $\\varphi'$ defined as \n\n\\begin{equation*}\n    \\begin{split}\n        \\varphi'(\\oslash) & = \\iota_n \\\\\n        \\varphi'(\\{i_1, i_2,\\ldots, i_k\\}) & =  (1, i_1, i_2,\\ldots, i_k) \\\\\n             \\text{assuming } & 2 \\leq i_1 < i_2 < \\ldots < i_k \\leq n -1\n    \\end{split}\n\\end{equation*}\n\nthat defines a bijection from $2^{\\{2,\\ldots,n - 1\\}}$ to $B_n$. It means that $|B_n| = 2^{n - 2}$ for $n \\geq 2$.\n\nSo the probability that the last ($n$th) person to board the plane will sit in their proper seat is $\\frac{|B_n|}{|A_n|} = 0.5$ for $n \\geq 2$.\n\n\\end{document}\n\n", "meta": {"hexsha": "75ed878cae3ac3c99222b39c2c140290789502e5", "size": 4383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "airplane_seating/airplane_seating.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": "airplane_seating/airplane_seating.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": "airplane_seating/airplane_seating.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": 59.2297297297, "max_line_length": 900, "alphanum_fraction": 0.6741957563, "num_tokens": 1492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384735, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.6904014890635483}}
{"text": "\n% JuliaCon proceedings template\n\\documentclass{juliacon}\n\\setcounter{page}{1}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\input{header}\n\n\\maketitle\n\n\\begin{abstract}\nPairwise learning is a machine learning paradigm where the goal is to predict properties of pairs of objects.\nApplications include recommender systems, molecular network inference, and ecological interaction prediction.\nKronecker-based learning systems provide a simple yet elegant method to learn from such pairs.\nUsing tricks from linear algebra, these models can be trained, tuned, and validated on large datasets.\nOur Julia package \\texttt{Kronecker.jl} aggregates these shortcuts and efficient algorithms using a lazily-evaluated Kronecker product `$\\otimes$', such that it is easy to experiment with learning algorithms using the Kronecker product.\n\n\\end{abstract}\n\n\\section{Background}\n\nThe Kronecker product, denoted by $\\otimes$, between an $(n\\times m)$ matrix $A=[A_{ij}]$ and an $(p\\times q)$ matrix $B=[B_{kl}]$ is computed as\n\\begin{equation}\\label{eq:kron}\n  {A} \\otimes  {B} ={\\begin{bmatrix}A_{1,1} {B} &\\cdots &A_{1,m} {B} \\\\\\vdots &\\ddots &\\vdots \\\\A_{n,1} {B} &\\cdots &A_{n,m} {B} \\end{bmatrix}}\\,.\n\\end{equation}\nSimply put, the Kronecker product creates a new $(np\\times mq)$ matrix containing all element-wise products between the respective elements of the two matrices.\n\nThough conceptually simple, the Kronecker product gives rise to some elegant mathematics which allows performing many important computations, such as the eigenvalue decomposition, determinant or trace, in an efficient way~\\cite{Sch2013,VanLoan2000}.\nThe Kronecker product has numerous applications in applied mathematics, for example in defining the matrix normal distribution, modeling complex networks~\\cite{Leskovec2008} and pairwise learning~\\cite{Stock2017tskrr}.\nThe reason that one can use the Kronecker product in large numerical problems is that (\\ref{eq:kron}) often does not have to be computed explicitly, but it can be circumvented using various computational shortcuts.\n\n\\section{Basic use}\n\nOur package aims to be a toolkit to effortless build Kronecker-based applications, where the focus is on the mathematics, and computational efficiency is taken care of under the hood. Essentially, it provides a lazily-evaluated Kronecker product of a \\texttt{Kronecker} type.\n\n%\\begin{verbatim}\n\\begin{lstlisting}[language = Julia]\n(n, m), (p, q) = (20, 20), (30, 30);  # A and B do not have to be square\nA = rand(n, m); B = randn(p, q);\nK = kronecker(A, B)  # lazy Kronecker product\n\\end{lstlisting}\n%\\end{verbatim}\n\nAlternatively, one can make use of Unicode, i.e.  $\\text{\\texttt{K = A $\\otimes$ B}}\\,.$\n\nThe elementary functions of \\texttt{LinearAlgebra} are overloaded to work with the respective subtypes of \\texttt{GeneralizedKroneckerProduct} and provide the most efficient implementation.\n\n\\begin{lstlisting}[language = Julia]\ntr(K)  # computed as tr(A) * tr(B)\ndet(K)  # computed as det(A)^n * det(B)^q\neigen(K)  # kronecker(eigen(A), eigen(B))\ninv(K)  # yields a Kronecker instance\nv = randn(600);\nK * v  # computed using the vec trick\n\\end{lstlisting}\n\nFor example, the last line is evaluated using the so-called \"vec trick\"~\\cite{VanLoan2000} with a time complexity of $\\mathcal{O}(nm+pq)$ instead of $\\mathcal{O}(nmpq)$ naively.\nSimilarly, efficiently solving large shifted Kronecker systems can be done directly as \\texttt{eigen(A $\\otimes$ B +$\\lambda$I) $\\backslash$ v}, exploiting the fast eigenvalue decomposition for Kronecker products.\n\nOur package fully supports higher-order Kronecker products, e.g. \\texttt{A $\\otimes$ B $\\otimes$ C}.\nThe structure \\texttt{KroneckerPower} (for example constructed as \\texttt{kronecker(A, 4)} for $A \\otimes A \\otimes A \\otimes A$) and its methods provide efficient storage and manipulation of repeated Kronecker multiplications of the same matrix. We also provide the functionality to generate Kronecker graphs.\n\nWe provide support for dealing with submatrices of a Kronecker product through the sampled vec trick~\\cite{Airola2017genvectric}.\n\n\\begin{lstlisting}[language = Julia]\n# subsample a 200 x 100 submatrix of K\ni, j = rand(1:n, 200), rand(1:m, 200);\nk, l = rand(1:p, 100), rand(1:q, 100);\nKsubset = K[i,j,k,l];\nu = randn(100);\nKsubset * u  # computed using sampled vec trick\n\\end{lstlisting}\n\n\\section{Prospects}\n\n\\texttt{Kronecker.jl} is a package in development. The developers are continuously adding new features.\nTo fully make use of the power of Julia, we will explore three directions.\nFirstly, we will integrate libraries for automatic differentiation, such as \\texttt{Zygote.jl}~\\cite{Innes2019}.\nThis will allow for developing pairwise learning methods with complex loss and regularization functions. Secondly, we want to leverage the GPU support to make these methods scalable to large datasets using \\texttt{CuArrays.jl}~\\cite{Besard2019}.\nFinally, we want to explore how symmetries and anti-symmetries can be incorporated, for example, when switching the order of two matrices would not change the result or only influences the sign of the result.\n\\input{bib.tex}\n\n\\end{document}\n\n% Inspired by the International Journal of Computer Applications template\n", "meta": {"hexsha": "8fbf8662539605b09007d3fdef0b773681e581c7", "size": 5201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/paper.tex", "max_stars_repo_name": "mcabbott/Kronecker.jl", "max_stars_repo_head_hexsha": "970b801b919670a6fd273a43d3dc18496b95b899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2019-06-25T05:49:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T11:39:29.000Z", "max_issues_repo_path": "paper/paper.tex", "max_issues_repo_name": "mcabbott/Kronecker.jl", "max_issues_repo_head_hexsha": "970b801b919670a6fd273a43d3dc18496b95b899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 98, "max_issues_repo_issues_event_min_datetime": "2019-06-20T16:40:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T08:27:25.000Z", "max_forks_repo_path": "paper/paper.tex", "max_forks_repo_name": "mcabbott/Kronecker.jl", "max_forks_repo_head_hexsha": "970b801b919670a6fd273a43d3dc18496b95b899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2019-07-23T16:10:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T16:02:26.000Z", "avg_line_length": 59.1022727273, "max_line_length": 310, "alphanum_fraction": 0.7683137858, "num_tokens": 1379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6903997191374038}}
{"text": "%---------------------------Minimum Angle-----------------------------\n\\section{Minimum Angle}\n\nIn order to properly compute the included angle, we'll need to\ncorrect for incorrectly oriented elements.\nLet\n\\[\ns_i = \\left\\{ \\begin{array}{ll}\n  1\\rule{2em}{0pt} & \\alpha_i < 0\\\\\n  0                & \\alpha_i \\geq 0\n  \\end{array}\\right.\n\\]\nThe included angle between two neighboring edges is\n\\[\n\\theta_i = (-1)^{s_i} \\arccos{ \\left( - \\frac {\\vec L_{i} \\cdot \\vec L_{i+1} }\n                                {\\normvec{L_{i}} \\normvec{L_{i+1}}} \\right) } \n                                  \\left( \\frac {180} {\\pi} \\right) \n           + 360\\dgr s_i\n\\]\nwhere $i\\in\\{0,1,2,3\\}$ and $\\vec L_4 = \\vec L_0$.\nWe take the minimum of this quantity as the value of the metric:\n\\[\nq = \\min_{i\\in\\{0,1,2,3\\}}\\left\\{ \\theta_i \\right\\}\n\\]\n\nNote that if $\\normvec{L_i} \\leq DBL\\_MIN$ or $\\normvec{L_{i+1}} \\leq DBL\\_MIN$,\n\\verd\\ returns $q = 360\\dgr$.\n\n\\quadmetrictable{minimum included angle}%\n{$A^1$}%                                    Dimension\n{$[45\\dgr,90\\dgr]$}%                        Acceptable range\n{$[0\\dgr,90\\dgr]$}%                         Normal range\n{$[0\\dgr,360\\dgr]$}%                        Full range\n{$90\\dgr$}%                                 Unit square\n{--}%                                       Citation\n{v\\_quad\\_minimum\\_angle}%                  Verdict function name\n\n", "meta": {"hexsha": "ad3ed0436591ec45f1c59ced892f3b5e1d20e4ac", "size": 1379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadMinimumAngle.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/QuadMinimumAngle.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/QuadMinimumAngle.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 36.2894736842, "max_line_length": 80, "alphanum_fraction": 0.4873096447, "num_tokens": 425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6903997038612507}}
{"text": "\\subsection{part b}\nI use a zero and a far pole to make controller feasible.\n\nController:\n$$\nC(s) = \\dfrac{2.2368\\times10^5(s+11.91)}{s+10^4}\n$$\nPhase margin is above 40 degree.\n\\begin{figure}[H]\n    \\caption{Phase margin with controller}\n    \\centering\n    \\includegraphics[width=12cm]{../Figure/Q1/Q1_b/margin.png}\n\\end{figure}\nMaximum closed loop is below than 3 decibels.\n\\begin{figure}[H]\n    \\caption{Nichols chart with controller}\n    \\centering\n    \\includegraphics[width=16cm]{../Figure/Q1/Q1_b/nichols.png}\n\\end{figure}\nSetteing time and overshoot for step responde in closed loop system are shown in figure.\n\\begin{figure}[H]\n    \\caption{Step responde}\n    \\centering\n    \\includegraphics[width=12cm]{../Figure/Q1/Q1_b/step.png}\n\\end{figure}\n", "meta": {"hexsha": "963194a62bfdc4c733279c48e2ad97e00f4b1087", "size": 754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW IV/Report/Q1/Q1_b/Q1_b.tex", "max_stars_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_stars_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW/HW IV/Report/Q1/Q1_b/Q1_b.tex", "max_issues_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_issues_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW IV/Report/Q1/Q1_b/Q1_b.tex", "max_forks_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_forks_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0, "max_line_length": 88, "alphanum_fraction": 0.7188328912, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686199, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6903501454298953}}
{"text": "In this section I explore four methods of dimensionality reduction on both of my datasets.\n\n\\subsection{Principal Components Analysis}\\label{subsec:principal-components-analysis}\nFor principal component analysis I chose to vary the number of components to explain variance, and collected their resulting eigenvalues to better understand this DR technique.\nBelow is a table of results for both data sets.\n\\begin{center}\n    \\begin{tabular}{|c| c |c|}\n        \\hline\n        & Minimum Components to Explain 99.9\\% Variance & Eigenvalues                               \\\\\n        \\hline\n        \\hline\n        Dataset 1 & 2                                             & [11320901200.524, 54484006.504]           \\\\\n        \\hline\n        Dataset 2 & 4                                             & [65088.565, 37527.175, 4525.986, 106.278] \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\nTwo features explain 100\\% of the variance in the data in the case of PCA for dimensionality reduction, and four features explain\n99.9\\% of the variance in the case of the second dataset.\nIn the case of dataset one the eigenvalues are very large which would seem to imply that the data are close together and\nthe are being multiplied by a large number to separate.\nBy contrast, data set two seems to have more components needed to explain the variance and each of those as a slightly smaller eigenvalue.\nFigures~\\ref{Fig:PCA DS1} and~\\ref{Fig:PCA DS2} show the projection of the transformed data according to their principal\ncomponents for the first two features (to allow for plotting).\n\\begin{figure}\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{pcads1.png}\n        \\caption{DS1 Projection via PCA}\\label{Fig:PCA DS1}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{pcads2.png}\n        \\caption{DS1 Projection via PCA}\\label{Fig:PCA DS2}\n    \\end{minipage}\n\\end{figure}\n\n\\subsection{Independent Components Analysis}\\label{subsec:independent-components-analysis}\nSimilar to the previous I also attempted to search for the best number of independent \"source components\" for each dataset.\nAccording to Carsten Klein\\cite{klein_2019}\n\"An interesting thing about two independent, non-Gaussian signals is that their sum is more Gaussian than any of the source signals.\nTherefore we need to optimize W in a way that the resulting signals of Wx are as non-Gaussian as possible.\"\nIn other words, using a measurement like Kurtosis we can compare the \"Gaussianity\" of different ICA runs.\nSince the normal distribution (Gaussian) has a kurtosis of 3, we are searching for ICA components with kurtosis of $<$ 3.\nIn order to reduce the covariance of the feature vectors as much as possible (to in effect ensure they were independent\ncomponents, I elected to whiten the feature space before processing.)\nBelow is a table depicting the n-components selected for each dataset and the resulting Kurtosis.\n\\begin{figure}\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{icads1.png}\n        \\caption{ICA Kurtosis vs RCError DS1}\\label{Fig:ICA DS1}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{icads2.png}\n        \\caption{ICA Kurtosis vs RCError DS2}\\label{Fig:ICA DS2}\n    \\end{minipage}\n\\end{figure}\nLooking at figures~\\ref{Fig:ICA DS1} and~\\ref{Fig:ICA DS2} we can see the relationship between the number of components (the dimensions reduced to)\nand both Kurtosis and Reconstruction Error (as measured by mean squared error).\nSimilar to PCA, for small values of n\\_components reconstruction error quickly approaches zero where the kurtosis gradually\nrises for each additional component.\nThis would seem to suggest that for $n=2$ (Dataset 1) and $n=4$ (Dataset 2) we reach the optimal tradeoff between treating\neach source attribute \"as a seperate mixed signal\" and reducing RC error (the obvious bias in DR being that we want n to be as\nsmall as possible.)\nWith respect to each dataset the meaningfulness of this result is that it is possible to reconstruct the distribution with\nsignificantly less data than the many more attributes which generated the original.\n\n\n\\subsection{Randomized Projection}\\label{subsec:randomized-projection}\nRandomized projections allowed me to generate random dimensionality reduction transformations from the data.\nI chose to repeat this process 10 times for each dataset and to utilize a Gaussian Randomized projection such that each\nfeature was itself equally likely to be a part of the final dimensionally reduced output.\nAlong with repeating each experiment I chose to vary the number of components as I did in other experiments to search\nfor an optimal reconstruction error.\nPerhaps unsurprisingly looking at figures~\\ref{Fig:RP DS1} and~\\ref{Fig:RP DS2} we can see that for larger values of\n\\texttt{n\\_components} the reconstruction error was lower.\nThe oscillations in the graph can be explained by the fact that the random projections can increase or decrease the RCError\nby small amounts.\nThere was a significant amount of variance between runs as shown in the table~\\ref{RP Var}.\nDataset 1 had much more variance than dataset 2 during randomized projection runs.\nThis is most likely due to the 30+ additional features in the space for which a random selection/transformation needed\nto be made.\n\\begin{center}\\label{RP Var}\n    \\begin{tabular}{|c| c |c|}\n        \\hline\n        & Variance               & Standard Deviation \\\\\n        \\hline\n        \\hline\n        Dataset 1 & 5.4456097845336664e+16 & 233358303.57057506 \\\\\n        \\hline\n        Dataset 2 & 34540925361.18495      & 185851.89092711688 \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\n\\begin{figure}\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{rpds1.png}\n        \\caption{RCError RP DS1}\\label{Fig:RP DS1}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{rpds2.png}\n        \\caption{RCError RP DS1}\\label{Fig:RP DS2}\n    \\end{minipage}\n\\end{figure}\n\n\\subsection{Linear Discriminant Analysis}\\label{subsec:linear-discriminant-analysis}\nFor my final dimensionality reduction technique, I chose to use linear discriminant analysis.\nDue to the fact that each of my problems are binary classification, and while not linearly seperable (otherwise accuracy would be better,)\na linear decision boundary with Bayesian conditional density would allow me to reduce the dimensionality of the dataset similar\nto PCA in the direction of the largest discriminant.\nHowever the difference here is the introduction of a priori information in the form of class labels.\nThe number of components had to be $min(num\\_features, unique\\_labels - 1)$ which in my case was $1$ for both datasets given\nthat they were both binary classification problems.\nSince LDA takes into account class labels I chose (similar to classifiers) to split the data between a test/training set (25/75\\% respectively.)\nAfter the transformation I opted to classify the remainder of instances, below is the result on test data.\n\\begin{center}\n    \\begin{tabular}{|c| c |}\n        \\hline\n        & Accuracy \\\\\n        \\hline\n        \\hline\n        Dataset 1 & 82.86\\%  \\\\\n        \\hline\n        Dataset 2 & 91.17\\%  \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\nAs you can see these results are comparable to the accuracy scores of some of the better trained classifiers from assignment 1.\nThis I believe speaks to the power of LDA being able to consider apriori information in constructing the DR projection.\nUnfortunately given that there was only one value for \\texttt{n\\_components} I cannot compare reconstruction error over time,\nbut given the positive results, I don't think that the reconstruction error would be very high.", "meta": {"hexsha": "26b3993c035a1fc4868c609e84fe162272fa5117", "size": 7957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment3/dimensionality-reduction.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/dimensionality-reduction.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/dimensionality-reduction.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": 58.9407407407, "max_line_length": 176, "alphanum_fraction": 0.7385949478, "num_tokens": 1936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256353465629, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6902072321265794}}
{"text": "% !TeX root = thoughts.tex\n\\section{Simple linear systems}\n\n\\subsection{Introduction with a 2 parameter system}\nIn a first analysis a simple linear system is considered, which allows us to get a grip on what is happening behind the scenes. A first analysis will be done on a two dimensional system given by the following linear system;\n\\begin{gather}\\label{eq:linear_system.system}\n\t\\begin{pmatrix}\n\td_1\\\\\n\td_2\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t1 & 0\\\\\n\t0 & 2\\\\\n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\tq_1\\\\q_2\n\t\\end{pmatrix}.\n\\end{gather}\nFor our synthetic data I choose $q_1 = 1$ and $q_2 = 3$. Prior information and measurement uncertainty all have an impact on posterior exploration, but for now I will set some arbitrary values. Our prior I synthetically set to have all means of 2 and standard deviations of 1. Measurement errors are chosen to be uncorrelated and having a standard deviation of 0.5. The influence of the two covariance matrices on the misfit functional are given in Figure~\\ref{fig:linear_system.prior_influence}.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/linear_systems/gradient_2d_narrow_prior}\n\t\t\\caption{Gradient with standard deviation $\\sigma = 1$}\n\t\t\\label{fig:linear_system.prior_influence.narrow}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/linear_systems/gradient_2d_wide_prior}\n\t\t\\caption{Gradient with standard deviation $\\sigma = 5$}\n\t\t\\label{fig:linear_system.prior_influence.wide}\n\t\\end{subfigure}\n\t\\caption{Normalized gradient of 2D misfit functionals with differently confined prior information. The means of the prior are for both parameters 2. It is obvious that decreasing the standard deviation for all parameters means that we increase the importance of the prior over the data, `pulling' the minimal gradient more towards the prior mean. Similar effects can be attained with increasing the magnitude of the data covariance matrix. Together, these matrices finely tune the minimum of the misfit function. Choosing well informed data and parameter covariace matrices is essential to meaningful \\gls{HMC} sampling. In this example, the data covariance was uniformly 0.5.}\n\t\\label{fig:linear_system.prior_influence}\n\\end{figure}\n\n\\index{Trajectories}For illustration purposes, 50 time steps were taken with a stepsize of 0.05 in time units (actual units of time might be a bit meaningless, without defining the units of length and mass). Using the unit mass matrix now generates trajectories like the one described in Figure~\\ref{fig:linear_system.trajectory_simple}. \n\n\\begin{figure}\n\t\\centering\n\n\t\\includegraphics[width=0.5\\textwidth]{figures/linear_systems/trajectory_simple}\n\n\t\\caption{Untuned trajectory of the simple linear system described in Equation~\\eqref{eq:linear_system.system}. The color of the trajectory points represents the normalized misfit, with red being the highest value, and dark blue being the lowest. Note that the direction of the trajectory can not be determined upon inspection of the trajectory itself; Hamilton's equation are invariant under time reversal. A particle would traverse exactly the same trajectory in reverse if at the end it's momentum would be reversed. The trajectory is superimposed on the gradient of the misfit functional $\\chi$, which acts as the direction of the largest increase in gravitational potential. A particle starting without momentum would start to roll in opposite direction of these vectors, eventually orbiting the point of zero gradient (without energy loss it can never reach a steady state in the point of minimum energy).}\n\t\\label{fig:linear_system.trajectory_simple}\n\\end{figure}\t\n\n\\paragraph{Mass matrix optimization}\\index{Mass matrix}\\index{Trajectories!Tuning the}There are some undesirable characteristics of this trajectory. Due to the mass matrix being a diagonal unit matrix, but the misfit functional being elongated along the dimension of parameter $q_1$ the oscillations in either dimension do not have the same period. Using a mass matrix based on Equation~\\eqref{eq:massMatrixForward} (which is still diagonal with the current forward model) will equalize oscillations. The reason this behavior is desired is that this way we see as many different energy levels in every dimension. The result of assigning the mass matrix based on the trace of $\\MatrixVariable{G}^T\\MatrixVariable{G}$ is seen in Figure~\\ref{fig:linear_system.trajectory_massTuned}. The resulting mass matrix is ~\n\\begin{gather}\\label{eq:linear_system.massMatrix}\n\\MatrixVariable{M} = \n\\begin{pmatrix}\n1 & 0\\\\\n0 & 4\\\\\n\\end{pmatrix}.\n\\end{gather}\n\n\\begin{figure}\n\t\\centering\n\t\n\t\\includegraphics[width=0.5\\textwidth]{figures/linear_systems/trajectory_massTuned}\n\t\n\t\\caption{Trajectory tuned with mass matrix, according to the simple linear system described in Equation~\\eqref{eq:linear_system.system}. The color of the trajectory points represents the normalized misfit, with red being the highest value, and dark blue being the lowest. With this augmented mass matrix, oscillations are equal in duration for each dimension.}\n\t\\label{fig:linear_system.trajectory_massTuned}\n\\end{figure}\n\n\\paragraph{No U-Turn Criterion}\\index{Trajectories!Trajectory length}\\index{Trajectories!Tuning the}\\index{No U-Turn Criterion}Visible now in Figure~\\ref{fig:linear_system.trajectory_massTuned} is another characteristic of untuned trajectories. What would be ideal is that the algorithm explores the model space as efficiently as possible. The trajectory depicted in the figure traverses the model space around the minimum fully, but also start to come back to the original position. This so called `U-Turn' behavior can be mitigated by terminating the trajectory as soon as one detects the propagated model coming closer to the initial model. This point is reached as\n\\begin{gather}\n\t  \\mathbf{v}(t) \\cdot \\left[ \\mathbf{m}(t) - \\mathbf{m}_0 \\right] < 0, \\quad\n\t \\text{and} \\quad\n\t \\mathbf{v}_0\\cdot \\left[ \\mathbf{m}_0 - \\mathbf{m}(t) \\right] < 0.\n\\end{gather}\nThis means that as soon as the momenta vectors for both the beginning and end of the trajectory both make an angle of less than 90 degrees with the vector connecting the points, so if the two models are `moving towards' each other, the trajectory is terminated. An illustration of a terminated trajectory is given in Figure~\\ref{fig:linear_system.trajectory_uTurn}. By limiting the trajectories using this criterion, and additionally increasing the step size so only a few samples are needed to traverse to model space will effectively reduce computational costs of proposing new models.\n\n\\begin{figure}\n\t\\centering\n\t\n\t\\includegraphics[width=0.5\\textwidth]{figures/linear_systems/trajectory_uTurn_29_samples}\n\t\n\t\\caption{Trajectory tuned with the \\textbf{No U-Turn Criterion} and forward model based mass matrix. The color of the trajectory points represents the normalized misfit, with red being the highest value, and dark blue being the lowest. As soon as the momentum of the initial point and the last point of the trajectory point `towards' eachother the trajectory is terminated. In this case, 29 samples were made before the trajectory was terminated.}\n\t\\label{fig:linear_system.trajectory_uTurn}\n\\end{figure}\n\n\\paragraph{Stepsize of the trajectories}\\index{Trajectories!Tuning the}\\index{Trajectories!Stepsize} The step size is another important tuning parameter. Wasting many computation on many steps is wasteful if the `particle' will end up in the same place, as was done in previous illustrations. According to \\cite{neal2011mcmc} the maximum step size is defined by the minimum standard deviation of momentum, or square root of the mass matrix.\n\n\\paragraph{Results}\nUsing optimized parameters, given in Table~\\ref{tab:naive_params}, multiple inversions were performed using \\gls{HMC}. The used stepsize is well below the upper limit of stability predicted by the mass matrix, according to \\cite{neal2011mcmc}. As can be seen in Figure~\\ref{fig:linear_system.accepted}, over many iterations the amount of accepted models evens out to approximately 66\\%. I'll call this method `naive' for now, for reasons which will become apparent later.\n\n\\begin{table}[]\n\\centering\n\\begin{tabular}{l|l}\n Number of timesteps & 50 \\\\\n Length of timestep & 0.05 \\\\\n Predicted stability &  0.5\n\\end{tabular}\n\\caption{Inversion parameters for `naive' trajectory settings.}\n\\label{tab:naive_params}\n\\end{table}\n\nIn Figure~\\ref{fig:linear_system.histq2} one sees what we'd expect to see with a linear model with Gaussian uncertainties. After more and more iterations the marginal posterior probability density functions approaches a normal distribution. It's actual mean in the last iteration is $\\mu_1 = 2.941$, close to the original parameter. This value is reached to within 1\\% as soon as 500 iterations. The actual development of the value is given in Figure~\\ref{fig:linear_system.evolution_q2}. This all seems like ideal behaviour, our sampler is able to get meaningful statistic from our dataset after only 500 iterations, and after 50,000 iterations we have a very nice looking posterior.\n\nWhen one however examines not only the marginal posterior of parameter 2, but also the marginal posterior of parameter 1 (Figure~\\ref{fig:linear_system.histq1}) and the full two dimensional posterior (Figure~\\ref{fig:linear_system.hist2d}) unexpected characteristics are found. It seems that parameter 1 has a bimodal distribution, while none of our input prior information nor forward model suggests such behaviour.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_naive/accepted.pdf}\n\t\\caption{Acceptance rates of the 'naive' sampling.}\n\t\\label{fig:linear_system.accepted}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_naive/histogram_p2.pdf}\n\t\\caption{Histogram for marginal probability density of parameter 2 after `naive' HMC sampling using different amount of\n\tsamples.}\n\t\\label{fig:linear_system.histq2}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.75\\textwidth]{figures/linear_systems/2d_naive/means2.pdf}\n\t\\caption{Evolution of mean of parameter 2 as the number of samples increases during the `naive' sampling.}\n\t\\label{fig:linear_system.evolution_q2}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_naive/histogram_p1.pdf}\n\t\\caption{Histogram for marginal probability density of parameter 1 after `naive' HMC sampling using different amount of\n\tsamples.}\n\t\\label{fig:linear_system.histq1}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_naive/histogram_2d.pdf}\n\t\\caption{Full 2D marginal probability density after `naive' HMC sampling using different amount of\n\tsamples.}\n\t\\label{fig:linear_system.hist2d}\n\\end{figure}\n\n\\afterpage{\\clearpage}\n\nUpon closer inspection of the random walk trajectory done after 50,000 iterations (Figure~\\ref{fig:linear_system.randomWalk50000naive}), there seems to be some bias in proposing new models. What happened in this case which spefically leads to the bimodal distribution is theorized as follows; the prior information always leads to propose the first model close to $\\mathbf{q} = (2,2)^T$. This starting point coupled with the rather long trajectory length of 50 samples and still rather large stepsize, result in every iteration traversing almost the complete model space.\n\nThis, in addition with the No U-Turn Criterion, makes these trajectories `resonate', always exploring the same portion of the model space. If a model is launched away from the misfit minimum, it wil return towards its original position and then be killed by the No U-Turn Criterion. If it is launched in a relatively beneficial direction. it will traverse a lot of space and turn at the opposite side of the model space. I would not go as far as to call it \\index{Hysteresis}hysteresis, but rather a fundamental result of the \\index{Tuning parameters}tuning parameters.\n\nThere's two ways to test this hypothesis. First, the random walk using a different prior is analysed. Now the prior means are chosen at exactly the values of the parameters used for the synthetics. The result, given in Figure~\\ref{fig:linear_system.improvedmean}, is that sampling is a little bit improved. The sampling is more uniform in the 2D space, but there is still some kind of `orbiting' behaviour, the sampler never reaches the minimum potential. This is because all trajectories passing through this point are not yet terminated. Making trajectories even longer won't work, because the No U-Turn Criterion will terminate them anyway. This leads us to testing another method of avoiding \\index{Biased sampling}biased sampling; shorter trajectories.\n\n\\index{Trajectories!Trajectory length}I think that this is a better solution. By decreasing total trajectory length, one does not need to tune actual physical intuition or information (the prior) to the needs of the algorithm. Recognizing this behaviour in non-linear or high dimensional systems might prove very challenging upon inspection of marginal probability distributions. One quality check one could do, even during sampling, is to monitor how often the No U-Turn Criterion triggers the termination of a trajectory, relative to total models ran. The promising result is given in Figure~\\ref{fig:linear_system.improvedtrajectory}.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.66\\textwidth]{figures/linear_systems/2d_naive/randomWalk_50000.png}\n\t\\caption{Random walk during 50,000 `naive' \\gls{HMC} samples.}\n\t\\label{fig:linear_system.randomWalk50000naive}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.43\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_improved/mean_histogram_2d}\n\t\t\\caption{Full 2D posterior}\n\t\t\\label{}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.57\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_improved/mean_randomWalk}\n\t\t\\caption{Random walk sequence}\n\t\t\\label{}\n\t\\end{subfigure}\n\t\\caption{50,000 samples of the same 2D posterior as Figure~\\ref{fig:linear_system.hist2d}, tuned with a different starting prior. Note that the random walk still traverse most of the model space in each proposal, leading again to `orbiting' of the minimum.}\n\t\\label{fig:linear_system.improvedmean}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.43\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_improved/short_histogram_2d}\n\t\t\\caption{Full 2D posterior}\n\t\t\\label{}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.57\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/linear_systems/2d_improved/short_randomWalk}\n\t\t\\caption{Random walk sequence}\n\t\t\\label{}\n\t\\end{subfigure}\n\t\\caption{50,000 samples of the same 2D posterior as Figure~\\ref{fig:linear_system.hist2d}, tuned with a much smaller trajectory length. Note that now each new model only has a small distance from the previous, but that the model space is much more evenly sampled.}\n\t\\label{fig:linear_system.improvedtrajectory}\n\\end{figure}\n\n\\subsection{Performance of higher dimensional systems}\n\nIn this section I want to look at the influence of dimensionality; how it affects computation time and acceptance rates. A general forward model is presented for $n$-dimensions;\n\n\\begin{gather}\n\t\\MatrixVariable{G} =\n\t\\begin{bmatrix}\n\t\t1\\cdot 1 &   &        & \\\\\n\t\t  & 2\\cdot 2 &        & \\\\\n\t\t  &   & \\ddots & \\\\\n\t\t  &   &        & n \\cdot n\n\t\\end{bmatrix}\n\\end{gather}\n\\paragraph{A note on the mass matrix}\\index{Mass matrix!revised}The mass matrix was initially again based upon the trace of $\\MatrixVariable{G}^T\\MatrixVariable{G}$. This \\textbf{did not} produce equally oscillating trajectories with models larger than 2 dimension and varying forward models. After some trial and error, and revisiting the theory, an extension upon the mass matrix is made. In the aforementioned reader, the covariance matrices were not analyzed in the general solution. By substituting the `new' $\\MatrixVariable{A}$ and $\\mathbf{b}$ from equations \\eqref{eq:linear_system.misfit_A} and \\eqref{eq:linear_system.misfit_b}, we see that a more optimized mass matrix could be constructed from (the trace of) $\\MatrixVariable{A}$ like so;\n\\begin{align}\\label{eq:extendedMassMatrix}\n\t\\MatrixVariable{M} = \\MatrixVariable{C}_M^{-1} + \\MatrixVariable{G}^T \\MatrixVariable{C}_D^{-1}\\MatrixVariable{G}.\n\\end{align}\nThis deficit was not apparent in the analysis of the 2 dimensional system probably due to the small difference in forward matrix components and parameters.\n\nOne important note is that this matrix is required to be positive definite to allow us to sample the full model space. If the $n\\times n$ matrix $\\MatrixVariable{M}$ is not of full rank, the column space is not completely $\\mathbb{R}^n$, and one does not explore the `interesting' part of our model space \\textbf{I want to refine this wording, be a bit more specific}. Now, one does not generally now much about the properties $\\MatrixVariable{G}^T$ if the system is very large. We'll also see later that if the mass matrix is not positive definite, the suggested code won't run since the required matrix decomposition does not exist. \n\nUsually, we can see that a system is under-determined or mixed-determined, but it is not easily verifiable if the system is over-determined (i.e. full rank). In this sense, the prior information in parameter space acts as a stabilizer. \n\nPositive definiteness is defined by;\n\n\\begin{align}\n\t\\mathbf{x}^T \\MatrixVariable{A}\\; \\mathbf{x} > 0, \\quad \\forall\\, \\mathbf{x} \\neq \\mathbf{0}\n\\end{align}\n\nWe first assume that our prior covariance for both the data and parameters are positive definite. I think for data covariances this describes independence of measured values, and the same goes for parameter covariances. Positive definiteness ensures that matrices can be inverted, and that their inverse is also positive definite.\n\nNow, we can easily show that the second term of the right hand side of Equation~\\eqref{eq:extendedMassMatrix} is at least positive semi-definite;\n\n\\begin{align}\n\t\\mathbf{x}^T \\MatrixVariable{G}^T \\MatrixVariable{C}_D^{-1}\\MatrixVariable{G} \\mathbf{x} =\\;\n\t\\left( \\MatrixVariable{G} \\mathbf{x} \\right)^T \\MatrixVariable{C}_D^{-1}\\MatrixVariable{G} \\mathbf{x} \\geq\n\t0, \\quad \\forall\\, \\mathbf{x} \\neq \\mathbf{0}\n\\end{align}\nThe reason this semi-definiteness creeps in is that one can't be sure that $\\MatrixVariable{G}$ doesn't map $\\mathbf{x}$ to $\\mathbf{0}$, since we don't know the dimension of it's null space. This is directly related to a system being under- or mixed determined, as $\\text{rank}(\\MatrixVariable{G})+\\text{nullity}(\\MatrixVariable{G}) = n$. If a system is under-determined, the second term is positive semi-definite. If one knows that $\\MatrixVariable{G}$ is of full rank, then the resulting second term is positive definite.\n\n\\index{Mass matrix!positive definite}This is also where our prior knowledge comes in, and acts as a stabilizer when the data prior is not sufficient for an inversion. If given two matrices for which hold $\\mathbf{x}^T \\MatrixVariable{A}\\, \\mathbf{x} > 0, \\quad \\forall\\, \\mathbf{x} \\neq \\mathbf{0}$ and $\\mathbf{x}^T \\MatrixVariable{B}\\, \\mathbf{x} \\geq 0, \\quad \\forall\\, \\mathbf{x} \\neq \\mathbf{0}$ then the following holds:\n\n\\begin{align}\n\t\\mathbf{x}^T \\left( \\MatrixVariable{A} + \\MatrixVariable{B} \\right) \\mathbf{x} =\\;\n\t\\mathbf{x}^T  \\MatrixVariable{A}  \\mathbf{x} + \\mathbf{x}^T \\MatrixVariable{B}  \\mathbf{x} >\n\t0, \\quad \\forall\\, \\mathbf{x} \\neq \\mathbf{0},\n\\end{align}\nthus, proving that the mass matrix is always positive definite if $C_M^{-1}$ and $C_D^{-1}$ are too.\n\n\\paragraph{Performance increase}\\index{Algorithm performance}At this stage I also realized that there are two main points on which we can increase performance. The code at this stage was sped up threefold by compiling using any of the -O\\# g++ flags. Any specific compiler flag (-O1 through -O4) didn't noticeably alter performance, mostly invisible due to the random nature of the sampling. I advise therefore to use -O2, the most tested mode, which alters your code the least. Also, RAM usage can be easily decreased by limiting the amount of std::vector$<>$ copies. Every time one of those objects is passed and used only once, (near) perfect forwarding can be achieved using std::move().\n\n\n\\paragraph{Inversion characteristics}The step size of any model is fixed at 0.05, since the first dimension provides the upper bound to the stability. For the trajectory, 10 different iterations are done, or whenever the U-Turn criterion is met. In total, 50,000 samples are drawn. Prior information for every parameter is set at 10, with a standard deviation of 5. This means that as the dimensionality increases, the prior becomes worse with respect to the actual parameter. Data covariance is fixed at 10 percent of the observed value, as to negate it's influence on the algorithm as much as possible. \n\n\\paragraph{Results}\\index{Algorithm performance!runtime}The computation time versus number of parameters exhibits an almost linear relationship, as seen in Figure~\\ref{fig:linear_system.high_dim.time}. The acceptance rate seems to suffer from the increasing dimensions, appearing inversely proportional to the amount of parameters (Figure~\\ref{fig:linear_system.high_dim.acceptance}). The results are rather good, but decreasing in quality as the number of accepted models decreases. This performance might be improved by actually drawing correlated samples from the mass matrix (I advise Cholesky decomposition).\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{figures/linear_systems/higher_dim/performance}\n\t\\caption{Computation time of 50,000 samples for a varying amount of parameters.}\n\t\\label{fig:linear_system.high_dim.time}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{figures/linear_systems/higher_dim/acceptance_rate}\n\t\\caption{Acceptance rate of 50,000 samples for a varying amount of parameters.}\n\t\\label{fig:linear_system.high_dim.acceptance}\n\\end{figure}\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "49e8b37935b2ac35f861e6e7340476913e305f27", "size": 22260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thoughts/simple_linear.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/simple_linear.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/simple_linear.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": 80.9454545455, "max_line_length": 912, "alphanum_fraction": 0.7877807727, "num_tokens": 5615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.69020722982306}}
{"text": "\\documentclass[11pt]{article}\n\\title{Math 20D: Ordinary Differential Equations}\n\\author{Suhas Arehalli}\n\n\\usepackage[margin=1.0in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{mathrsfs}\n\n\\begin{document}\n\\maketitle\n\n\\section{1st Order ODEs}\n\\subsection{Integrating Factor}\n\\subsubsection{Given}\nA 1st order linear differential equation of the form\n    \\[ \\frac{dy}{dt} + p(t)y = g(t) \\]\n\\subsubsection{Technique}\nBegin by calculating the integrating factor (feel free to ignore the constant of integration - it's \nirrelevant),\n    \\[ \\mu (t) = e^{\\int p(t)dt} \\]\nThen multiply both sides by it\n\\begin{align*}\n    \\frac{dy}{dt} e^{\\int p(t)dt} + p(t)e^{\\int p(t)}y &= g(t)e^{\\int p(t)}  \\\\\n    \\frac{dy}{dt} \\mu (t) + \\frac{d\\mu}{dt}y &= g(t)\\mu (t) \n\\end{align*}\nNote that the right-hand side is just $\\frac{d}{dt}[y \\mu (t)]$\n\\begin{align*}\n    \\frac{d}{dt}[y \\mu (t)] &= g(t)\\mu (t) \\\\\n    y \\mu(t) &= \\int g(t)\\mu (t)dt \\\\\n    y &= \\frac{\\int g(t) \\mu (t)dt}{\\mu (t)}\n\\end{align*}\n\n\n\\subsection{Separable Equations}\n\\subsubsection{Given}\nA 1st order differential equation of the form \n    \\[ M(x) + N(y)\\frac{dy}{dx} = 0 \\]\nThese are called \\textbf{separable}.\n\\subsubsection{Technique}\nSeparate your variables\n    \\[ N(y)\\frac{dy}{dx} = M(x) \\]\nAnd integrate\n    \\[ \\int N(y)dy = \\int M(x)dx \\]\nAnd then solve for y.\n\n\n\\subsection{Exact Equations}\n\\subsubsection{Given}\nA 1st order differential equation of the form\n    \\[ M(x,y) + N(x,y)\\frac{dy}{dx} = 0 \\]\nSuch that\n\\begin{align*}\n    \\frac{d}{dy}[M(x,y)] = \\frac{d}{dx}[ N(x,y)]\n\\end{align*}\n\\subsubsection{Technique}\nCalculate $\\psi (x,y)$ from\n\\begin{align*}\n    \\psi (x,y) = \\int M(x,y)dx + C_1(y) \\\\\n    \\psi (x,y) = \\int N(x,y)dy + C_2(x) \n\\end{align*}\nThere should be one function that satisfies both of these equations with varying functions $C_1(x)$ and \n$C_2(y)$: That is $\\psi (x,y)$. Then we can rewrite the differential equation as\n\\begin{align*}\n\\frac{d\\psi}{dx} + \\frac{d\\psi}{dy}\\frac{dy}{dx} &= 0 \\\\\n\\frac{d}{dx}[\\psi (x,y)] &= 0\\\\\n\\psi (x,y) &= C\n\\end{align*}\nWhich we can proceed to algebraically solve for y.\n\n\\section{Second Order ODEs}\n\\subsection{The Wronskian}\nIn first order ODEs, we know there is only one solution to each Differential Equation (plus all of it's\nscalar multiples). With 2nd Order ODEs, we expect 2 linearly independent solutions. How do we determine\nif these solutions are independent? By calculating the Wronskian:\n\\[\n    W = det\\begin{bmatrix}\n            y_1  & y_2 \\\\  \n            y_1' & y_2'\\\\\n            \\end{bmatrix}\n\\]\nIf $ W \\neq 0 $, then the 2 solutions are linearly independent enough. \n\\subsection{Characteristic Equation }\n\\subsubsection{Given}\nA homogenous 2nd order differential equation of the form \n\\[ y'' + ay' + b = 0 \\]\n\\subsubsection{Technique}\nAssume our solution is of the form $y = e^{rt}$. Substituting it in gives us\n\\begin{align*}\n    r^2e^{rt} + are^{rt} + be^{rt} &= 0 \\\\\n    (r^2 + ar + b)e^{rt} &= 0\n\\end{align*}\nHowever, since $e^{rt} \\neq 0, \\forall r \\in \\mathbb{R}$, we can divide by \n$e^{rt}$ and obtain the characteristic equation\n    \\[ r^2 + ar + b = 0 \\]\nand solve for the $r_1, r_2$ that satisfy the equation (the roots of the polynomial on the LHS). Depending\non the kind of roots obtained, follow one of the techniques below:\n\\subsubsection{Technique: Real and Unique Roots}\nIn this case, your solution is simply\n    \\[ y = C_1e^{r_1t} + C_2e^{r_2t} \\]\nWhy? If you followed along above, you see that we assumed that solutions would be of the form $y = e^{rt}$.\nHowever, since there are 2 solutions for that equations, by the Law of Superposition, every linear \ncombination of those solutions is also a solution.\n\\subsubsection{Technique: Complex Roots}\nHere we can say that out solution is simply the same as above. However, we don't care about imaginary \nsolutions: The DE was real-valued, so so should our solution. Thus, we will inspect one solution (which\nis complete, as we could show with the Wronskian) and remove the imaginary terms. Consider\n\\begin{align*}\n    y = Ce^{rt} &= Ce^{(a+bi)t} \\\\\n    &= Ce^{at}e^{(bt)i} \\\\\n    &= Ce^{at}(cos(bt) + isin(bt)) \\\\\n    &= (C_1 + C_2i)e^{at}(cos(bt) + isin(bt)) \\\\\n    &= e^{at}(C_1cos(bt) - C_2sin(bt)) + ie^{at}(C_1sin(bt) + C_2cos(bt))\\\\\n\\end{align*}\nIf we swap the sign on $C_2$ and drop the imaginary part, we obtain our real solution\n\\[ y = e^{at}(C_1cos(bt) + C_2sin(bt)) \\]\n\\subsubsection{Technique: Repeated Roots}\nIf we only have a single root, we can simply say the answer is\n\\[ y = C_1e^{rt} + C_2te^{rt} \\]\nWhy? This is a special case of the next technique, Reduction of Order.\n\\subsection{Reduction of Order}\n\\subsubsection{Given}\nA 2nd order linear DE of the form\n    \\[ y'' + p(t)y' + q(t)y = 0 \\]\nand a single solution $y_1(t)$.\n\\subsubsection{Technique}\nAssume that\n    \\[ y_2(t) = v(t)y_1(t) \\]\nfor some function $v(t)$. Our goal is to find this function $v(t)$, and thus find $y_2(t)$. Now\nsimply substitute into the original equation, first finding that\n\\begin{align*}\n    y_2(t)   &= v(t)y_1(t) \\\\\n    y_2'(t)  &= v'(t)y_1(t) + v(t)y_1'(t) \\\\\n    y_2''(t) &= v''(t)y_1(t) + 2v'(t)y_1'(t) + v(t)y_1''(t)\n\\end{align*}\nAnd then substiting fully, getting\n\\begin{align*}\n    \\left[v''(t)y_1(t) + 2v'(t)y_1'(t) + v(t)y_1''(t)\\right] + p(t)\\left[v'(t)y_1(t) + v(t)y_1'(t)\\right] + q(t)\\left[v(t)y_1(t)\\right]  = 0 \\\\\n    \\left[v''(t)y_1(t) + 2v'(t)y_1'(t) \\right] + p(t)\\left[v'(t)y_1(t)\\right] + v(t)\\left[y_2''(t) + p(t)y_1'(t) + q(t)y_1(t)\\right]  = 0 \\\\\n    \\left[v''(t)y_1(t) + 2v'(t)y_1'(t) \\right] + p(t)\\left[v'(t)y_1(t)\\right] = 0 \\\\\n\\end{align*}\nAt this point, since all terms with v(t) were eliminated, we can define a new variable $w(t) = v'(t)$. Now\nWe're left with\n    \\[ \\left[w'(t)y_1(t) + 2w(t)y_1'(t) \\right] + p(t)\\left[w(t)y_1(t)\\right] = 0 \\]\nAnd since $y_1(t)$ is known, we have a 1st order DE that we can solve using the previous methods, finding\n$w = v'(t)$, from which we can find $v(t) = \\int w(t)dt$, which in turn lets us find $y_2(t) = v(t)y_1(t)$.\n\\subsection{Method of Undetermined Coefficients}\n\\subsubsection{Given}\nA second order nonhomogenous ODE of the form\n    \\[ y'' + p(t)y' + q(t)y = g(t) \\]\nwith a g(t) that is a sum/product of sin/cos, polynomials, or exponentials,\nplus homogenous solutions $y_1(t)$ and $y_2(t)$ that satisfy\n    \\[ y'' + p(t)y' + q(t)y = 0 \\]\nWe could obtain these with the other homogenous 2nd order techniques discussed above. \n\\subsubsection{Technique}\nWe need to add an additional term, $Y(t)$ to our homogenous solution to account for the function $g(t)$\non the RHS. To find $Y(t)$, first, guess a generalized version of $g(t)$: Replace an nth order polynomial\nwith $\\sum_{i=0}^n A_it^i$, sine or cosine with $Acos(Bt) + Csin(Dt)$, and any exponential with\n$Ae^{Bt}$.\n\nThen find $Y'(t), Y''(t)$ and substitute into the differential equation. The equate all of the coefficients\nof equal terms, obtaining a system of linear equations which you can proceed to solve for the undetermined\ncoefficients you got from \"generalizing\" when guessing $Y(t)$. Then our final solution will be\n    \\[ y = y_1(t) + y_2(t) + Y(t) \\]\nSometimes the system we find will have no solutions. In this case, we can multiply any $Ae^{Bt}$ terms \nby $t$ and try again, and if that doesn't work repeat. Don't ask me why this works. \\textbf{TIP}: If something \nof the form $Ae^{Bt}$ appears in the homogenous solution, multiply by t. If something of the form $Ate^{Bt}$ \nappears in the homogenous solution, multiply by t again. \nTo recap:\n\\begin{enumerate}\n    \\item Construct a guess Y(t)\n    \\item Differentiate Y(t) and substitute into the DE\n    \\item Equate coefficients of similar terms, getting a system of linear equations for the coefficients\n    \\item Solve the system to get the coefficients\n    \\item If the system has no solutions, multiply $Ae^{Bt}$ terms by t and go back to 2.\n    \\item Write the final solution\n\\end{enumerate}\n\\subsection{Variation of Parameters}\n\\subsubsection{Given}\nA second order nonhomogenous ODE of the form\n    \\[ y'' + p(t)y' + q(t)y = g(t) \\]\nwith homogenous solutions $y_1(t)$ and $y_2(t)$ that satisfy\n    \\[ y'' + p(t)y' + q(t)y = 0 \\]\nWe could obtain these with the other homogenous 2nd order techniques discussed above. \n\\subsubsection{Technique}\nAgain we begin by making an assumption about $Y(t)$: \n    \\[ Y(t) = u_1(t)y_1(t) + u_2(t)y_2(t) \\]\nFrom this, we again differentiate\n\\begin{align*}\n    Y(t) &= u_1(t)y_1(t) + u_2(t)y_2(t) \\\\\n    Y'(t) &= u_1(t)y_1'(t) + u_1'(t)y_1(t) + u_2(t)y_2'(t) + u_2'(t)y_2(t) \\\\\n\\end{align*}\nAnd now, since that looks disgusting, and because we have the freedom to, let's impose an additional constraint:\n\\begin{equation}\nu_1'(t)y_1(t) + u_2'(t)y_1(t) = 0  \\\\\n\\end{equation}\nwhich gets us\n\\begin{align*}\n    Y'(t) &= u_1(t)y_1'(t) + u_2(t)y_2'(t)\\\\\n    Y''(t) &= u_1'(t)y_1'(t) + u_1(t)y_1''(t) + u_2'(t)y_2'(t) + u_2(t)y_2''(t) \\\\\n\\end{align*}\nNow substitute into the DE, getting\n\\begin{eqnarray*}\n\\begin{split}\n    [ u_1'(t)y_1'(t) + u_1(t)y_1''(t) + u_2'(t)&y_2'(t) + u_2(t)y_2''(t)] \\\\\n    + p(t)[ u_1(t)y_1'(t) &+ u_2(t)y_2'(t)]  \\\\\n    + &q(t)\\left[ u_1(t)y_1(t) + u_2(t)y_2(t) \\right] = g(t)\n\\end{split}\n\\end{eqnarray*}\n\\begin{eqnarray*}\n\\begin{split}\n   u_1(t)[y_1''(t) + p(t)y_1'(t) + q(t)y_1(t)&] \\\\\n   + u_2(t)[y_2''(t) + p(t)&y_2'(t) + q(t)y_2(t)] \\\\\n   &+ u_1'(t)y_1'(t) + u_2'(t)y_2'(t) = g(t)\n\\end{split}\n\\end{eqnarray*}\n\\begin{equation}\n    u_1'(t)y_1'(t) + u_2'(t)y_2'(t) = g(t) \\\\\n\\end{equation}\nThis paired with (1) gives us a system of equations we can use to solve for $u_1'(t)$ and $u_2'(t)$, \ngiving us\n\\begin{align*}\n    u_1'(t) &= -\\frac{y_2(t)g(t)}{W(y_1, y_2)(t)} \\\\\n    u_2'(t) &= \\frac{y_1(t)g(t)}{W(y_1, y_2)(t)}\n\\end{align*}\nWhich, of course leads to\n\\begin{align}\n    u_1(t) &= -\\int \\frac{y_2(t)g(t)}{W(y_1, y_2)(t)} \\\\\n    u_2(t) &= \\int \\frac{y_1(t)g(t)}{W(y_1, y_2)(t)}\n\\end{align}\nAs part of \n\\[ Y(t) = u_1(t)y_1(t) + u_2(t)y_2(t) \\]\nWhich gives us our final answer\n\\[ y = y_1(t) + y_2(t) + Y(t) \\]\nFor normal use of this technique:\n\\begin{enumerate}\n    \\item Find $u_1(t)$ and $u_2(t)$ using equations (3) and (4)\n    \\item Write the final solution\n    \\end{enumerate}\nNot actually that bad.\n\\section{Systems of ODEs}\n\\subsection{The Wronskian for Systems}\nAgain we must ask ourselves the question: How do we know if we've found all of the solutions. \nAgain we answer by checking is $W \\neq 0, \\forall t$. How do we compute the Wronskian for \na system of equations? Since our solutions $y_1, ..., y_n$ are vector valued functions \n$y_i: \\mathbb{R} \\rightarrow \\mathbb{R}^n$, we say that\n\\[ W(y_1, ..., y_n) = det \\left[y_1, ..., y_n \\right] \\]\nIn this case, we literally mean that our solutions are linearly independent over all $t$. \n\\subsection{Characteristic Equation}\n\\subsubsection{Given}\nGiven a system of $n$ linear ODEs of order $n$ with coefficients that can be written in the form\n\\[ x' = Ax \\]\nWith A being an $n$ x $n$ matrix and $x$ being a vector-valued functions $x: \\mathbb{R} \n\\rightarrow \\mathbb{R}^n$\n\\subsubsection{Technique}\nAssume that solutions are of the form\n\\[ y = \\xi e^{\\lambda t} \\]\nThen we get\n\\begin{align*}\n    \\lambda \\xi e^{\\lambda t} &= A \\xi e^{\\lambda t} \\\\\n    \\lambda \\xi &= A \\xi  \n\\end{align*}\nThus we discover that $\\xi$ must be an eigenvector of $A$ with eigenvalue $\\lambda$. To find the\neigenvalue, we must first find the roots of the characteristic polynomial of $A$, since\n\\begin{align*}\n    A \\xi - \\lambda \\xi &= 0 \\\\\n    (A - \\lambda I) \\xi &= 0 \n\\end{align*}\nAnd in order for this system to have a solution for $\\xi$ other than the 0 vector, we must have that\n\\begin{align*}\n    det(A - \\lambda I) &= 0 \n\\end{align*}\nDepending on the $\\lambda$'s we find, we can use different techniques to find the individual solutions \nfor each eigenvalue, and use the Principle of Superposition (the linear combination of all solutions is\nthe general solution) to give the general solution.\n\nNote that these directly parallel the 2nd order techniques discussed. If we formulate a 2nd order \nequation\n\\begin{equation*}\n    y'' + ay' + by = 0\n\\end{equation*}\nas \n\\begin{align*}\n    x_1' &= x_2 \\\\\n    x_2' &= -ax_2 - bx_1\n\\end{align*}\nWith $y = x_1$.\n\\subsubsection{Technique: Real and Unique Eigenvalues}\nThe solution is simply\n\\[ x(t) = \\sum_{i = 1}^n C_i \\xi_i e^{\\lambda_i t}  \\]\nfor each real eigenvalue $\\lambda_i$ and associated eigenvector $\\xi_i$.\n\\subsection{Technique: Imaginary Eigenvalues}\nFor reasons similar to the 2nd order ODEs, we'll drop the imaginary portion. Let $\\lambda = a + bi$\nbe one of the conjugate pair of imaginary eigenvalues and $\\xi$ be the corresponding eigenvector. Their \n\\begin{align*}\n    x(t) &= C\\xi e^{(a + bi)t} \\\\\n         &= C\\xi e^{at} (cos(bt) + isin(bt)) \\\\\n        \\dots \\\\\n         &= y_1 + iy_2 \n\\end{align*}\nSince $\\xi$ can have imaginary parts, you must multiply through and separate imaginary and real\nparts. Then, since the coefficient $C \\in \\mathbb{C}$, you may take both the real and imaginary parts\nof this solution as your $x_1$ and $x_2$. \n\nThen your solution will be\n\n\\[ x(t) = C_1y_1 + C_2y_2 \\]\n\n\\subsubsection{Technique: Repeated Eigenvalues}\nIf there is a repeated eigenvalue $\\lambda$ with corresponding eigenvector $\\xi$, it is tempting to \nfollow our logic from 2nd order DEs and simply multiply our solution by t. However, that is \\textbf{wrong}.\nInstead, we must assume our second solution is of the form \n\\[ x_2(t) = \\xi te^{\\lambda t} + \\eta e^{\\lambda t} \\]\nWith vector $\\eta$. Derive, getting\n\\[ x_2'(t) = (\\lambda t + 1)\\xi e^{\\lambda t} + \\lambda \\eta e^{\\lambda t} \\]\nAnd substitute into our system\n\\begin{align*}\n    x' &= Ax \\\\ \n    (\\lambda t + 1)\\xi e^{\\lambda t} + \\lambda \\eta e^{\\lambda t} &= A(t\\xi e^{\\lambda t} + \\eta e^{\\lambda t})  \\\\\n    \\lambda t \\xi e^{\\lambda t} + \\xi e^{\\lambda t} + \\lambda \\eta e^{\\lambda t} &= \\lambda \\xi t e^{\\lambda t} + A\\eta e^{\\lambda t} \\\\\n     \\xi e^{\\lambda t} + \\lambda \\eta e^{\\lambda t} &= A\\eta e^{\\lambda t} \\\\\n     \\xi  + \\lambda \\eta &= A\\eta  \\\\\n    (A - \\lambda I)\\eta &= \\xi\n\\end{align*}\nThis will create a linear system, which we can solve for $\\eta$. Then we have that\n\\begin{equation}\nx(t) = C_1\\xi e^{\\lambda t} + C_2(\\xi te^{\\lambda t} + \\eta e^{\\lambda t}) \n\\end{equation}\nTo summarize:\n\\begin{enumerate}\n    \\item Find eigenvalues of the matrix A, and determine that one of the roots is repeated.\n    \\item Solve $(A - \\lambda I)\\eta = \\xi$ to find $\\eta$.\n    \\item The solution for that repeated eigenvalue is as given in (5).\n\\end{enumerate}\n\\subsection{Undetermined Coefficents}\n\\subsubsection{Given}\nA non-homogenous 2nd order system of ODEs of the form\n\\begin{align*}\n    x' = At + g(t) \\\\\n\\end{align*}\nAnd a homogenous solution, $x_h(t)$ presumably obtained using the characteristic equation method above.\n\n\\subsubsection{Technique}\nUsing the same generalization techniques as for 2nd order ODEs, craft a guess for an additional\nterm we'll call $v(t)$, except instead of multiplying a term by t, add the higher order term. e.g.\n\\[ ae^{Bt} \\rightarrow ate^{Bt} + be^{Bt} \\]\n\nThe process is then pretty much the same:\n\\begin{enumerate}\n    \\item Derive and substitute into the original equation\n    \\item Equate coeffients of similar terms to get systems of systems of equations, \n          some corresponding to eigenvalue equations, others solvable by row reduction, \n          and so on. \n    \\item Solve them. If you decide to go down this painful road and the system of systems is\n          unsolvable, then go back and do the \"add a higher order\" thing mentioned above. The\n          tips on that above are relevant here too.\n    \\item Now you know $v(t)$, so write the final solution: $x(t) = x_h(t) + v(t)$\n\\end{enumerate}\n\\subsection{Diagonalization}\n\\subsubsection{Given}\nA system of ODEs of the form\n\\[ x' = Ax + g(t) \\]\n\nNo homogenous solutions needed!\n\n\\subsubsection{Technique}\nRemember that given a matrix $A$ and an eigenbasis $\\{\\xi_1, ..., \\xi_n\\}$, we can construct a\nChange of Basis matrix $T = \\left[ \\xi_1, ..., \\xi_n \\right]$, with \n\\begin{align}\n    T^{-1}AT &= D = \\begin{bmatrix} \n                        \\lambda_1 & 0 & \\dots & \\\\\n                        0 & \\lambda_2 & \\dots \\\\\n                        \\dots & \\dots & \\dots \\\\\n                    \\end{bmatrix} \n\\end{align}\nGiven these properties, we can reduce a system of ODEs into a series of 1st order DEs. How? First\nlet \n    \\[ x = Ty \\] \nFor some $y$. We then get\n    \\[ Ty' = ATy + g(t) \\]\nThen we simply multiply on the left (because matrix multiplication order matters!) by $T^{-1}$\n    \\[ y = T^{-1}ATy + T^{-1}g(t) \\]\nAnd, using (6) we get\n    \\[ y = Dy + T^{-1}g(t) \\]\nNow, since $D$ is diagonal, we have a series of 1st order ODEs! Split the one matrix equation into\nit's component system, and the $i$th equation/row will only have \n    \\[y_i' = \\lambda_i y_i + \\left[ T^{-1}g(t) \\right]_i \\]  \nUsing a method like the Integrating factor to solve each of these, we can obtain $y$, and can now reverse\nthe transformation to get back the solution to our first equation, $x$. Our final solution will be\n\\begin{align*}\n    x(t) = Ty\n\\end{align*}\nTo summarize\n\\begin{enumerate}\n    \\item Find the eigenvectors and the eigenbasis for $A$ (solving the characteristic equation and doing \n          row reduction is the simplest method)\n    \\item Construct $T$ by normalizing each eigenvector and making them the columns of $T$.\n    \\item Let $x = Ty$, and multiply to the left by $T^{-1}$. Remember $T^{-1}AT = D$, the matrix\n          with $D_{i,i} = \\lambda_i$ and all else $0$. \n    \\item Separate this into $n$ 1st order linear equations with the form \n            $y_i' = \\lambda_i y_i + \\left[ T^{-1}g(t) \\right]_i $. Solve them using whatever technique (Integrating\n          factor always works).\n    \\item Reconstruct the vector function $y$. The final solution will be $x(t) = Ty$, as we used before\n          in 2.\n\\end{enumerate}\n\\section{More Powerful Techniques}\n\\subsection{Power Series}\n\\subsubsection{Given}\nAnything. Seriously. Any ODE. We can get \\textit{a} solution. Possibly a disgusting one. For the\nsake of making the example easy, we'll assume a 2nd order equation of the form\n    \\[ y'' + p(t)y' + q(t)y = g(t) \\] \n\\subsubsection{Technique}\nAssume our solution is a \\textbf{Power Series}. This is what makes this technique so \\textbf{power}ful.\nGet it? No? Ok. \n    \\[ y = \\sum_{n=0}^{\\infty}a_n(x - x_0)^n \\]\nNote that \n\\begin{align*}\n    y' &= \\sum_{n=0}^{\\infty}na_n(x - x_0)^{n-1} \\\\\n    y'' &= \\sum_{n=0}^{\\infty}n(n-1)a_n(x - x_0)^{n-2}\n\\end{align*}\nThen note these 2 techniques to shift indices of summations and the power of the $(x-x_0)^n$ term.\n\\begin{align}\n    \\sum_{n=k}^{\\infty} a_n (x - x_0)^{n-k} &= \\sum_{n=k}^{\\infty} a_{n+k} (x - x_0)^n \\\\\n    \\sum_{n=0}^{\\infty} a_n (x - x_0)^n = a_0 + a_1(x - x_0) + &... + a_k(x - x_0)^k + \\sum_{n=k+1}^{\\infty} a_n (x - x_0)^n\n\\end{align}\nWith these techniques and derivatives, we have one goal: rearrange the differential equation into the \nform\n\\[ a_0 + ... + a_k(x - x_0)^k + \\sum_{n=k+1}^{\\infty} F(a_n, a_{n+1}, ..., a_{n+l}) = 0 \\]\nFrom which we learn that $a_0 = ... = a_k = 0$ and $F(a_n,..., a_{n+l}) = 0, \\forall n > k$. From this\nsecond equation, we can derive a \\textbf{Recurrence Relation} that relates $a_{n+l}$ to the previous \n$l$ terms. \nWe can always let $a_0$ and $a_1$ vary (since it's a 2nd order ODE), analagous to our $C_1$ and $C_2$ \nin previous techniques, and solve for all higher $a_n$ through these. Sometimes we will be able to \nfind a closed form solution for $a_n$, and in even rarer circumstances, we may be able to identify that \nas a taylor series of a function, in which case we can remove summations from our answer. But in general, \nour solution will look like what we originally guessed,\n    \\[ y = \\sum_{n=0}^{\\infty}a_n(x - x_0)^n \\]\nWith some sort of recurrance relation for $a_n$. Yeah, this is pretty ugly. To sum up\n\\begin{enumerate}\n    \\item Substitute in a general power series.\n    \\item Manipulate sums and powers until we get one large sum equal to zero.\n    \\item Set all coefficients equal to 0. Obtain a recurrence relation for $a_n$\n    \\item Attempt to find a closed source form for $a_n$ (this is tricky - have fun). Further, see \n          if this is a taylor series for an elementary function. Even if not, we \"solved\" it, to\n          an arbitrary precision.\n\\end{enumerate}\n\\subsection{Laplace Transform}\n\\subsubsection{Given}\nAn ODE. That's really about it. One caveat is that the functions involved must have Laplace and \nInverse Laplace transforms that we know of. We'll just say it looks like\n    \\[ \\sum_{i=0}^n a_i(t)y^{(i)}= g(t) \\]\nYeah. That general.\n\\subsubsection{Technique}\nWe define the Laplace Transform of a function as\n\\[ \\mathscr{L}\\{f(x)\\} = \\int_{0}^{\\infty} e^{-st}f(t)dt \\]\nNote that it's linear: that\n\\[ \\mathscr{L}\\{af(x) + bg(x)\\} = a\\mathscr{L}\\{f(x)\\} + b\\mathscr{L}\\{g(x)\\} \\]\nMost importantly, if we evaluate this for a derivative,\n\\begin{align*}\n    \\mathscr{L}\\{f'(x)\\} &= \\int_{0}^{\\infty} e^{st}f'(t)dt  \\\\\n    \\mathscr{L}\\{f'(x)\\} &=  \\left[ e^{-st}f(t)\\right]_0^{\\infty} -\\left(- s\\int_0^{\\infty} e^{-st}f(t)dt \\right)  \\\\\n    \\mathscr{L}\\{f'(x)\\} &=   -f(0) + s\\int_0^{\\infty} e^{-st}f(t)dt  \\\\\n    \\mathscr{L}\\{f'(x)\\} &=   s\\mathscr{L}\\{f(x)\\} - f(0)\n\\end{align*}\nWith $f(0)$ and $f'(0)$ either being arbitrary constants of the general solution, or initial conditions.\n\nApplying this further\n\\[ \\mathscr{L}\\{f^{(n)}\\} = s^n\\mathscr{L}\\{f(x)\\} - \\sum_{i=0}^{n} s^{n-i-1}f^{(i)}(0) \\]\nBut we probably don't want to use this since it's so ugly.\n\nNow the amazing thing is that this transforms differential equations into algebraic equations. That means that\ngiven any differential equation, we can get some algebraic equation we can solve for $\\mathscr{L}\\{y\\}$. \nTransforming something merely requires an indefinite integral. however, the inverse transform $\\mathscr{L}^{-1}$\nis a lot more difficult to compute. For that reason, we typically have look-up tables to transform \n$\\mathscr{L}\\{y\\}$ back into $y$.\n\nTo summarize the technique:\n\\begin{enumerate}\n    \\item Apply the Laplace Transform to both sides of the DE.\n    \\item Solve for $\\mathscr{L}\\{y\\}$ algebraically.\n    \\item Manipulate the RHS until we can use a lookup table to apply the inverse transform (typically partial\n          fractions).\n\\end{enumerate}\nAND WE'RE DONE HERE FAM.\n\\end{document}\n", "meta": {"hexsha": "b59c02b6927af850512ab889dee7d273aacb7cfc", "size": 22396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Math20D/Math20D.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": "Math20D/Math20D.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": "Math20D/Math20D.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": 46.0823045267, "max_line_length": 143, "alphanum_fraction": 0.6562332559, "num_tokens": 7598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.6902072177587053}}
{"text": "\\subsection{ROOT\\_VAL Operator}\n\nThe {\\tt ROOT\\_VAL} operator takes a single univariate polynomial as\nargument, and returns a list of root values at system precision (or\ngreater if required to separate roots).  It is used with the syntax\n\\begin{verbatim}\n\tROOT_VAL(EXPRN:univariate polynomial):list.\n\\end{verbatim}\nFor example, the sequence\n\\begin{verbatim}\n        on rounded; root_val(x^3-x-1);\n\\end{verbatim}\ngives the result\n\\begin{verbatim}\n        {0.562279512062*I - 0.662358978622, - 0.562279512062*I\n\n          - 0.662358978622,1.32471795724}\n\\end{verbatim}\n", "meta": {"hexsha": "1c26f9dac30c18ec1770e76794e48debacc547e3", "size": 567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "atomic_Decomp/Redlog/reduce.doc/rest.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/rest.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/rest.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": 29.8421052632, "max_line_length": 68, "alphanum_fraction": 0.7389770723, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6900702505117003}}
{"text": "\\section{Theory}\n\\label{sec:theory}\n\nThe following is a short summary of the used equations, which were adopted\nfrom chapter 3 of the course book~\\cite{Bonet2008}.\nUnless stated otherwise, the uppercase letters refer to the initial (reference)\nconfiguration of the problem, while the lowercase ones refer to the current\nconfiguration. The boldface letters denote vectors, matrices and tensors.\n\nFor a given load, solving the problem implies finding a configuration that\nsimultaneously satisfies both the global (system) equilibrium equations and\nthe constitutive equations.\nThe equilibrium equations are expressed in terms of the residual (out-of-balance)\nvector \\(\\bm{R} (\\bm{x})\\) as the balance between internal and external forces:\n\\begin{equation}\n  \\bm{R} (\\bm{x}) = \\bm{T} (\\bm{x}) - \\bm{F} = \\bm{0},\n\\end{equation}\nwhere \\(\\bm{x} =\\left[ \\bm{x}_{1}, \\bm{x}_{2}, \\cdots, \\bm{x}_{N} \\right]^{\\text{T}}\\)\nis the vector of current nodal positions;\n\\(\\bm{T} =\\left[ \\bm{T}_{1}, \\bm{T}_{2}, \\cdots, \\bm{T}_{N} \\right]^{\\text{T}}\\) is\nthe vector of internal nodal forces;\n\\(\\bm{F} =\\left[ \\bm{F}_{1}, \\bm{F}_{2}, \\cdots, \\bm{F}_{N} \\right]^{\\text{T}}\\) is\nthe vector of external nodal forces, where it is assumed to be independent\nof the current nodal positions \\(x\\) (generally this is not true);\nand \\(N\\) is the number of nodes.\n\n\\subsection{Hyperelasticity}\n\\label{sec:hyperelasticity}\n\nIn the case of hyperelastic material behaviour of a rod, i.e.\\ material whose\nstrain energy per unit volume \\(V\\) does not depend on the path taken by the rod as\nit moved from initial length \\(L\\) to the current length \\(l\\), the internal\ntruss forces \\(\\bm{T}_{a}\\) and \\(\\bm{T}_{b}\\) can be computed as\n\\begin{equation}\n  \\bm{T}_{b} = \\frac{V E}{l} \\ln \\left( \\frac{l}{L} \\right) \\bm{n}\n             = \\tau \\frac{V}{l} \\bm{n}, \\quad\n  \\bm{T}_{a} = - \\bm{T}_{b}.\n\\end{equation}\nHere, a Young's modulus like constant \\(E\\) has been used to relate Kirchhoff\nstress \\(\\tau = E \\varepsilon = \\sigma v / V\\) to logarithmic strain\n\\(\\varepsilon = \\ln(l/L)\\).\n\nFinding equilibrium position is carried out using Newton-Raphson method, which\ninvolves linearisation of the equilibrium equations. The linearisation yields\nthe directional derivative \\(D \\bm{T}^{(e)} (\\bm{x}^{(e)}) [\\bm{u}^{(e)}]\\),\nwhich gives the\nexpression for the tangent stiffness matrix:\n\\begin{equation}\n  D \\bm{T}^{(e)} (\\bm{x}^{(e)}) [\\bm{u}^{(e)}] = \\bm{K}^{(e)} \\bm{u}^{(e)} =\n  \\begin{bmatrix}\n    \\bm{K}_{aa}^{(e)} & \\bm{K}_{ab}^{(e)} \\\\\n    \\bm{K}_{ba}^{(e)} & \\bm{K}_{bb}^{(e)}\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\bm{u}_{a} \\\\\n    \\bm{u}_{b}\n  \\end{bmatrix}\n\\end{equation}\nwith\n\\begin{align}\n  \\bm{K}_{aa}^{(e)} &= \\bm{K}_{bb}^{(e)} =\\left( \\frac{V}{v}\n                      \\frac{d \\tau}{d \\varepsilon} \\frac{a}{l} -\n                      \\frac{2 \\sigma a}{l} \\right)\n                      \\bm{n} \\otimes \\bm{n} + \\frac{\\sigma a}{l} \\bm{I} \\\\\n  \\bm{K}_{ab}^{(e)} &= \\bm{K}_{ba}^{(e)} = - \\bm{K}_{aa}^{(e)},\n\\end{align}\nwhere \\(d \\tau / d \\varepsilon = E\\) is the elastic material tangent modulus.\n\n\\subsection{Rate-independent plasticity}\n\\label{sec:plasticity}\n\nIn the case of rate-independent finite strain plasticity with isotropic hardening,\nthe stress is defined via elastic strain \\(\\varepsilon_{e}\\):\n\\begin{align}\n  \\tau &= E \\varepsilon_{e} = E \\left( \\varepsilon - \\varepsilon_{p} \\right) \\\\\n  \\varepsilon_{p} &= \\int_{0}^{t} \\dot{\\varepsilon}_{p} dt \\label{eq:plastic-strain}\n\\end{align}\n\nThe onset of plastic deformation is governed by the yield condition, which for the\nproblem at issue is\n\\begin{equation}\n  f (\\tau, \\bar{\\varepsilon}_{p}) = \\left| \\tau \\right| - \\left(\n    \\tau_{y}^{0} + H \\bar{\\varepsilon}_{p} \\right) \\leq 0, \\quad \n  \\bar{\\varepsilon}_{p} \\geq 0, \n\\end{equation}\nwhere \\(\\tau_{y}^{0}\\) is the initial yield stress,\n\\(\\bar{\\varepsilon}_{p}\\) is the hardening parameter and \\(H\\) is a material\nproperty called plastic modulus.\nAt its simplest, the hardening parameter is defined as the accumulated absolute\nplastic strain occurring over time:\n\\begin{equation}\n  \\bar{\\varepsilon}_{p} = \\int_{0}^{t} \\dot{\\bar{\\varepsilon}}_{p} dt,\n  \\quad \\dot{\\bar{\\varepsilon}}_{p} = \\left| \\dot{\\varepsilon}_{p} \\right|,\n  \\quad \\dot{\\varepsilon}_{p} = \\dot{\\gamma} \\frac{\\partial f}{\\partial \\tau},\n\\end{equation}\nwhere \\(\\dot{\\gamma}\\) is plastic multiplier.\n\nIn a computational setting the time integration of \\eqref{eq:plastic-strain} can\nonly be performed approximately from a finite sequence of values determined at\ndifferent time steps.\nIn order to satisfy the yield condition exactly at each incremental time step,\na return-mapping algorithm described in figure~\\ref{fig:return-mapping} is used,\nwhich employs incremental kinematics (see figure~\\ref{fig:incr-kinematics}).\n\\begin{figure}[th]\n  \\begin{subfigure}[t]{0.38\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{return_mapping.png}\n    \\caption{Return-mapping algorithm.}\n    \\label{fig:return-mapping}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[t]{0.56\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{incremental_kinematics.png}\n    \\caption{Incremental kinematics. \\(\\lambda = l / L\\).}\n    \\label{fig:incr-kinematics}\n  \\end{subfigure}\n  \\caption{Two figures from \\cite{Bonet2008}.}\n\\end{figure}\n\nThe last matter to be addressed in the presence of plasticity is the material\ntangent modulus \\(d \\tau / d \\varepsilon\\).\nThe tangent modulus derived from incremental considerations is generally not\nthe same as the one obtained from the rate equations.\nThe reason is that the incremental change in stress imposed by the chosen\nreturn-mapping algorithm is different from the continuous change in stress\nstemming from the rate equations.\nThat is why the algorithmic tangent modulus is used:\n\\begin{equation}\n  \\frac{d \\tau_{n+1}}{d \\varepsilon_{n+1}} = \\frac{E H}{E + H}\n\\end{equation}\nWhen plasticity occurs, this replaces the elastic tangent stiffness\n\\(d \\tau / d \\varepsilon = E \\).\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "b31e538ebf8acb33537b7cfd2678c4462e136968", "size": 6042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/theory.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/theory.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/theory.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": 43.4676258993, "max_line_length": 86, "alphanum_fraction": 0.6820589209, "num_tokens": 1883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.6900599001802143}}
{"text": "%intro\n\\section{Introduction}\n\nWe briefly dicuss the prerequisit of category theoretic basics. We implicitly assume for each object $X$ an Grothendieck universe $\\calu(X)$ such that $X \\in \\calu(X)$.\n\\\\\n\\subsection{Basic definitions}\n\nA category $\\calc$ consists of the following four data -\n\\bd\n\\item[Objects] the class of objects - similar to elements in sets. The class of objects are denoted as\n$$\\objc,$$\nhowever, for brevity and if no ambiguity can arise, $A \\in \\calc$ (reading - $A$ an object in category $\\calc$).\n\\item[Morphisms] for two objects $A, B$ in $\\calc$ we call an arrow or simply a map $f : A \\longrightarrow B$ a morphism and its class is denoted by\n$$\\homcab.$$\nIrrespective of objects one writes $\\mrm{Hom}^{\\calc}$.\n\\item[Identity] is always an object in the class of morphisms for any object $A \\in \\calc$:\n$$id_A = [a \\longmapsto a] \\in \\mrm{Hom}^{\\calc}(A,A).$$\n\\item[Composition] For any triplet $A, B, C \\in \\calc$ and arrows\n$$f \\in  \\mrm{Hom}^{\\calc}(A, B),\\ g \\in \\mrm{Hom}^{\\calc}(B, C)$$\nthere exists a unique arrow\n$$h := g \\circ f \\in \\mrm{Hom}^{\\calc}(A,C).$$\nAs a commutative diagram:\n$$\\xymatrix{A \\ar[r]^{f}\\ar[rd]_{\\exists!h}&B\\ar[d]^g\\\\\n&C.}$$\nThis is usually combined in the quadruplet $(\\objc,\\mrm{Hom}^{\\calc},id,\\circ)$.\n\\ed\nFurthermore, we call $\\calc$\n\\bd\n\\item[small] category if its class of objects is small - i.e. the class of its objects is set-like.\n\\item[dual] given $\\calc$ its opposite category $\\mrm{C^{\\mrm{op}}}$ has the same class of objects just with its arrows reverted:\n$$\\op{f} \\in \\homcopab \\Leftrightarrow f \\in \\homc{B}{A}.$$\nIts composition is for all $A, B, C \\in \\calcop$ and $\\op{f} \\in \\homcopab$ and $\\op{g} \\in \\homcop{B}{C}$:\n$$\\op{g} \\op{\\circ} \\op{f} \\in \\homcop{A}{C} \\Leftrightarrow f \\circ g \\in \\homc{C}{A}.$$\n\\item[monomorphims] we call a morphism $f \\in \\mrm{Hom}(A,B)$ a monomorphism if for all $g_1, g_2 \\in \\mrm{Hom}(B,C)$\n$f \\circ g_1 = f \\circ g_2$ implies $g_1 = g_2$.\n\\item[epimorphims] we call a morphism $f \\in \\mrm{Hom}(A,B)$ a epimorphism if for all $g_1, g_2 \\in \\mrm{Hom}(C,A)$\n$g_1 \\circ f = g_2 \\circ f$ implies $g_1 = g_2$ (aquivalently, $\\op{f}$ is a monomorphism).\n\\item[isomorphisms] $f \\in \\homcab$ is an isomorphism if it is an epimorphism and a monomorphism within the same category. An automorphism is an isomorphism in $\\homc{A}{A}$.\n\\item[initial] we call $\\calc$ a category with initial object $\\ast$ if for each object $A \\in \\calc$ we get\n$$\\exists ! f \\in \\homc{\\ast}{A}.$$\n$\\ast$ is its initial object\n\\item[terminal] we call $\\calc$ a category with terminal object $\\ast$ if for each object $A \\in \\calc$ we\nget\n$$\\exists ! f \\in \\homc{A}{\\ast}.$$\n\\item[null] a null object is terminal and inital.\n\\item[equalizer] given two objects $A, B \\in \\calc$ and two morphisms $f, g \\in \\homcab$, we call an object $X \\in \\calc$ an equalizer if for any object $O \\in \\calc$ and arrow $h \\in \\homc{O}{A}$ we get two unique morphisms $o \\in \\homc{O}{X}, e \\in \\homc{X}{A}$ \n$$\\xymatrix{\n&O\\ar[rd]^h\\ar[ld]_h\\ar[d]_o&\\\\\nA\\ar[rd]_f&X\\ar[l]_e\\ar[r]^e&A\\ar[ld]^g\\\\\n&B&\\\\\n}$$\ncommutes. Not all category have equalizers for all pairs of morphisms. But, if they exist they are unique up to isomorhism. Coequalizers are equalizers in $\\op{\\calc}$.\n\\item[products] we call $\\calc$ a category with finite products if \n\\bn\n\\item for each $A, B$ in $\\calc$ there exists an object $P$ and two morphisms $\\pi_A : P \\longrightarrow A, \\pi_B : P \\longrightarrow B$ such that for each $O \\in \\calc$ with $f \\in \\homc{O}{A}$ and $g \\in \\homc{O}{B}$ there is a unique $h \\in \\homc{O}{P}$ so that the following diagram:\n$$\\xymatrix{\n&O\\ar[d]^h\\ar[dl]_f\\ar[dr]^g&\\\\\nA&P\\ar[l]^{\\pi_A}\\ar[r]_{\\pi_B}&B\\\\\n}$$\ncommutes. $P$ is usually denoted by the cartesian product notation $P = A \\times B$. This, in turn, enables us to define the $\\call{J}$ products: given a subclass of objects $A_J$ indexed by $\\call{J}$ then its product is defined to be an object $P \\in \\calc$ such that\n$$\\xymatrix{\nO \\ar[dd]_{h}\\ar[rd]_{f_J}\\ar[rrrd]_{f_{J'}}\\ar[rrrrrd]_{f_{J''}}\\\\\n&A_J && A_{J'} && A_{J''}&\\ldots\\\\\n\\prod_{J \\in \\call{J}} A_J =: P\\ar[ur]^{\\pi_J} \\ar[urrr]^{\\pi_{J'}}\\ar[urrrrr]^{\\pi_{J''}}\\\\\n}$$\n\\en\nCoproducts are products in $\\op{\\calc}$.\n\\item[pullback] Given three objects $A, B, C \\in \\calc$ and two morphisms $f: A \\longrightarrow C, g : B \\longrightarrow C$ we call an object $P \\in \\calc$ the pullback of $(f,g)$ if $P$ is the equalizer of $(\\pi_A \\circ f, \\pi_B \\circ g)$ in $\\homc{A \\times B}{C}$ and projections $\\pi_A : A \\times B \\longrightarrow A, \\pi_B : A \\times B \\longrightarrow B$:\n$$\\xymatrix{\n&O\\ar[rd]^h\\ar[ld]_h\\ar[d]_o&\\\\\nA \\times B\\ar[d]_{\\pi_A}&P\\ar[l]_e\\ar[r]^e&A \\times B\\ar[d]^{\\pi_B}\\\\\nA\\ar[rd]_f&&B \\ar[ld]^g\\\\\n&C&\\\\\n}$$\n$P$ is denoted by $A \\times_{C} B$ and can be thought off as \n\\ed\nGiven two categories $\\calc$ and $\\call{D}$ - we call \n\\begin{defi}[Functors]\na pairing $F : \\calc \\longrightarrow \\call{D}$ a functor for any two objects $A, B \\in \\calc$ with arrow  $f \\in \\homcab$ - if one of the following holds:\n\\bd\n\\item[Covariant] $$\\xymatrix{\nA \\ar[d]_F\\ar[r]^f &B\\ar[d]^F\\\\\nF(A) \\ar[r]_{F(f)}&F(B).\\\\\n}$$ and $F(id_A) = id_{F(A)}$. In particular, $F(f) \\in \\homo{\\call{D}}{F(A)}{F(B)}$.\n\\item[Contravariant] $$\\xymatrix{\nA \\ar[d]_F\\ar[r]^f &B\\ar[d]^F\\\\\nF(A) &F(B)\\ar[l]_{F(f)}\\\\\n}$$ and $F(id_A) = id^{-1}_{F(A)}$. In particular, $F(f) \\in \\homo{\\op{\\call{D}}}{F(A)}{F(B)}$.\n\\ed\n\\end{defi}\n\\subsection{Examples} \nWe will be discussing some promiment examples:\n\\subsubsection{General categories}\n\\paragraph{Category $\\mrm{Set}$}\nThe category of sets is denoted by $\\mrm{Set}$ and consists of all objects the behave \"set-like\" (the most basic property is the choice property - $\\chi_{x} : \\{A \\subset X\\} \\longrightarrow \\{Y: Y \\subset X,\\ |Y| = 0,1 \\}$ mapping singleton subsets to itself or empty set\n$$\\chi_{x} = \\left[A \\longmapsto \\begin{cases}\n\\emptyset, & x \\notin A\\\\\n\\{x\\},& \\mrm{else}\\\\\\end{cases}\\right]$$\n). With these classes of maps we may define the equality property - elements are equal if and only if the choice function collide. Its class of arrows are simply all maps among sets.\nThe category of pointed spaces is denoted by $\\mrm{pspc}$ and consists of objects $X$ with a \"choice function\":\n$ \\chi : X \\longrightarrow \\mrm{sing}, x' \\longmapsto \\ast$. With $\\ast$ the base point. This definitions is equivalent to $\\mrm{Set}$ except that no subspace (sub object) may ever be empty (empty set is not an object in $\\mrm{pspc}$. Its morphisms are the base point preserving maps in $\\mrm{Set}$.\n\n\\paragraph{Power set as functor} Given an arbitrary set $X$, its power set $\\call{P}(X)$ defines a functor\n$$\\calp : \\mrm{set} \\longrightarrow \\mrm{set},\\ X \\longmapsto \\calp(X).$$\nwhich is contravariant and covariant at the same time. Consider a map $f : A \\longrightarrow B$:\n\\bn\n\\item is covariant as  $\\calp(f) : \\calp(A) \\longrightarrow \\calp(B)$ simply maps each subset of $A$ to the subsets of $B$ containing images of each subset mapped:\n\n$$f(A') \\cap \\calp(B) = \\{f(A') \\cap B' : B' \\subset B\\},\\ \\forall A' \\subset A.$$\n\\item is contravariant as with the same we get\n$$\\calp(f) : \\calp(B) \\longrightarrow \\calp(A),\\ B' \\longmapsto f^{-1}(B') \\subset A.$$\n\\en\nThus, within $\\mrm{set}$ both concepts (Co/Contravariance), with respect to $\\calp$, are isomorphic.\n\\subsection{Algebraic catories}\nThere a some prominent examples we will be discussing algebraic categories as we will be revisiting some of them later on.\n\n\\subsubsection{Semi groups} We call $(S, m) \\in \\mrm{SGrp}$ - if $m : S \\times S \\longrightarrow S$ is a closed associative binary operation:\n\\bn\n\\item Closedness:\n$$m(s,t) \\in S\\ \\forall (s,t) \\in S^2,$$\n$$\\Leftrightarrow m^{-1}(S) \\supset S^2.$$\n\\item Associativity: \n$$\\xymatrix{\nS^3 \\ar[r]^{m \\times id_S}\\ar[d]_{id_S \\times m}& S^2 \\ar[d]^m\\\\\nS^2 \\ar[r]_m &S\\\\\n}\n$$\n\\en\nWe remark that the empty set is a semi group as clearly the diagonal projection defines a map $\\emptyset \\times \\emptyset \\longrightarrow \\emptyset$.\n\\subsubsection{Monoids} A semi group is a monoid or, $(M, m, e) \\in \\mrm{Mon}$, if there is an initial object $\\ast \\in \\mrm{Mon}$ and an arrow $e : \\ast \\longrightarrow M \\in \\homo{\\mrm{Mon}}{\\ast}{M}$, such that\n$$\\xymatrix{\n\\ast \\times M \\ar[rr]^{e \\times id_M}\\ar[rrd]_\\simeq&&M^2 \\ar[d]_m&&M \\times \\ast\\ar[ll]_{id_M \\times e} \\ar[lld]^{\\simeq}\\\\\n&&M&&\\\\\n}$$\ncommutes. The map $e$ is is called the unit.\n\\subsubsection{Groups} Monoids are the quatuple $(G,m,e,S)$ with map $S : G \\longrightarrow G$ such that\n$$\\xymatrix{\n&G \\ar[rd]^\\Delta\\ar[ld]_\\Delta\\ar[dd]&\\\\\nG^2\\ar[dd]_{S \\times id_G}&&G^2\\ar[dd]^{id_G \\times S}\\\\\n&\\ast\\ar[dd]_e&\\\\\nG^2\\ar[rd]_m&&G^2\\ar[ld]^m\\\\\n&G&\\\\\n}$$\nwith $\\Delta : G \\longrightarrow G^2$, the diagonal map:\n$$\\xymatrix{\nG \\ar[r]^\\Delta\\ar[d]_\\Delta\\ar[rd]_\\simeq&G^2\\ar[d]^{\\pi_1}\\\\\nG^2\\ar[r]_{\\pi_2}&G\\\\\n}$$\nfor the two projections $\\pi_1, \\pi_2$ in the first and second factor, respectively. The map $S$, the so called antipode, is ań antiisomorphism - that is it is an isomorphism in $\\grp$, but its image object is in general not $G$ itself. Rather, it is the so called opposite group:\n$$\\op{G} \\in \\grp: \\op{G} := G \\in \\obj{\\grp},\\ \\op{m} := m_G \\circ \\tau.$$\nThe object is $G$ itself but its multiplication is is the flipped version of $m_G = m$. We remark that the object $G$ need not to be an object in $\\grp$ - it suffice for $G$ to be a semi group. Inversion and unity are of no consequence.\n\\subsubsection{Abelian groups} We call an object $(A,m,e,S,\\tau) \\in \\abel \\subset \\grp$ abelian (group) if $\\op{A} = A$, that is $\\op{m} = m$. Aquivalently, $S$ is a group automorphism. The map $\\tau$ is the flip isomorphism:\n$$\\tau = \\tau_{A\\times B}: A \\times B \\longrightarrow B \\times A$$\nsuch that\n$$\\xymatrix{\n&A \\times B \\ar[ld]_{\\pi_A}\\ar[rd]^{\\pi_B}\\ar[dd]_\\tau&\\\\\nA & & B\\\\\n&B \\times A\\ar[lu]^{\\pi_A}\\ar[ru]_{\\pi_B}\\\\\n}$$\ncommutes.\n\\subsubsection{Rings} Rings $(R,m_+,e_+,S_+,m_*,\\tau) \\in \\mrm{Rng}$ are subobjects $(R,m_+,e_+,S_+,\\tau) \\in \\mrm{Abel}$ such that $(R,m_*)$ is a semi group and the following diagrams commute:\n$$\\bao{cc}\n\\xymatrix{\nR^4\\ar[rrr]^{id_R \\times \\tau \\times id_R}&&&R^4\\ar[d]^{m_* \\times m_*}\\\\\nR^3\\ar[d]_{id_R \\times m_+}\\ar[u]^{\\Delta \\times id_{R^2}}&&&R^2\\ar[d]^{m_+}\\\\\nR^2 \\ar[rrr]_{m_*}&&\n&R\\\\\n} & \\xymatrix{\nR^4\\ar[rrr]^{id_R \\times \\tau \\times id_R}&&&R^4\\ar[d]^{m_* \\times m_*}\\\\\nR^3\\ar[d]_{m_+ \\times id_R}\\ar[u]^{id_{R^2} \\times \\Delta}&&&R^2\\ar[d]^{m_+}\\\\\nR^2 \\ar[rrr]_{m_*}&&\n&R\\\\\n}\n\\ea$$\nThe left hand side represents the left dissociativity and the right hand side the right dissociativity. We call $R \\in \\mrm{Rng}$ unital or $R \\in \\mrm{URng}$ is there is an arrow $e_* : \\ast \\longrightarrow R$ such that $(R,m_*,e_*)$ is a monoid and commutative or $R \\in \\mrm{CRng}$ if $\\op{(R,m_*)} = (R,m_*)$.\n\\newcommand{\\htalpha}{\\hat{\\alpha}}\n\\subsubsection{Modules} Given a ring $(R,m_+,e_+,S_+,m_*)$ we call an abelian group $(M,m_M,e_M,S_M) \\in \\abel$ an $R$ left module if there is an arrow $$\\alpha \\in \\homo{\\grp}{R}{S(M) := \\mrm{Aut}^{\\grp}(M)}$$ such that for $\\htalpha : R \\times M \\longrightarrow M, \\htalpha = eval \\circ (\\alpha \\times id_M)$ and $eval: S(M) \\times M \\longrightarrow M,$:\n$$\\bao{cc}\n \\xymatrix{\nR^2 \\times M^2\\ar[rr]^{id_R \\times \\tau_{R \\times M} \\times id_M}&&(R \\times M)^2\\ar[d]^{\\htalpha \\times \\htalpha}\\\\\nR \\times M^2\\ar[d]_{id_R \\times m_M}\\ar[u]^{\\Delta_R \\times id_{M^2}}&&M^2\\ar[d]^{m_M}\\\\\nR \\times M \\ar[rr]_{\\htalpha}&&M\\\\\n}\n& \\xymatrix{\nR^2 \\times M \\ar[d]_{m_* \\times id_M}\\ar[r]^{id_R \\times \\htalpha}&R \\times M\\ar[d]^\\htalpha\\\\\nR \\times M \\ar[r]_\\htalpha &M\\\\\n}\n\\\\ \\xymatrix{\nR^2 \\times M^2\\ar[rr]^{id_R \\times \\tau_{R \\times M} \\times id_M}&&(R \\times M)^2\\ar[d]^{\\htalpha \\times \\htalpha}\\\\\nR^2 \\times M\\ar[d]_{m_+ \\times id_M}\\ar[u]^{id_{R^2} \\times \\Delta_M}&&M^2\\ar[d]^{m_M}\\\\\nR \\times M \\ar[rr]_{\\htalpha}&&M\\\\\n}\n\\ea$$\ncommute. The first column represents the ring and module dissociativities, respectively. The second column is the semi group torsor property - $\\htalpha$ commutes with ring multiplication $m_*$. $R$ right modules are $\\op{R}$ left modules and aquivalently, an $R$ left module is an $\\op{R}$ right module. Here, $\\op{m_+} = m_+$ and $\\op{m_*} = m_* \\circ \\tau_{R^2}$. Therefore,\n$$\\op{\\alpha} = \\alpha,\\ \\op{eval} = eval \\circ \\tau_{S(M) \\times R} \\ \\mrm{and}\\ \\op{\\htalpha} = \\op{eval} \\circ (id_M \\times \\alpha).$$\nA two sided module is left and right sided $R$ module. Two sided modules are of specifial interest as they do have products: given two ts-$R$ modules $M$ and $N$ for any bi-linear map $f : M \\times N \\longrightarrow P$ and module $P$ there is the following universal property:\n$$\\xymatrix{\nM \\times N \\ar[r]^{\\otimes_R}\\ar[rd]_{f}&M \\otimes_R N\\ar[d]^{\\exists! g \\in \\mrm{Hom}_R(M\\otimes N,P)}\\\\\n&P\\\\\n}$$\nWe call $M \\otimes_R N$ the tensor product of $M$ and $N$ being also a two sided module. In general, a right module $M$ can have (tensor) products $M \\otimes_R N$ with left modules $N$. However, these objects are no longer modules. They are merely objects in $\\abel$. \n\\subsubsection{Algebras} A two sided $R$ module $A$ is an algebra if there is an $R$ linear map $\\mu : A \\otimes_R A \\longrightarrow A$ making $A$ a two-sided $A$ module.\n\n\n\n", "meta": {"hexsha": "a1e51e0011ec4c351d50a43fffd9af0369f91f2f", "size": 13200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "galois_objects/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": "galois_objects/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": "galois_objects/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": 64.0776699029, "max_line_length": 377, "alphanum_fraction": 0.6577272727, "num_tokens": 4937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6900598991211261}}
{"text": "\\subsection{Bonus: Lebesgue Integral}\r\nIf we want to find the area under a curve, we choose to slice up the horizontal region (domain) of the function (Riemannian integration).\r\nBut can we choose to slice up the vertical region that is the range of the function?\r\nThis is known as the Lebesgue integration.\r\nSometimes this is better.\r\nFor example if we want to integrate $f(x)=1_{\\mathbb Q}$, Riemannian integration would not work if we want to evaluate\r\n$$\\int_0^1f(x)\\,\\mathrm dx$$\r\nBut if we do it by Lebesgue intgeral, but since $\\mathbb Q$ is countable\r\n\\footnote{Hence of Lebesgue measure $0$.}\r\nthis integral is obviously $0$.", "meta": {"hexsha": "b7e051010323f8bc3487d45309af0eedaed3251a", "size": 633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/leb.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/leb.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/leb.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": 63.3, "max_line_length": 138, "alphanum_fraction": 0.75671406, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6900598973143371}}
{"text": "\\chapter{Deconvolution}\n\\section{Wavelet and Deconvolution}\n\\label{wdec}\nConsider an image characterized by its intensity\ndistribution $I$, corresponding to the observation of a\n``real image'' $O$ through an optical system. If the\nimaging system is linear and shift-invariant, the relation between\nthe data and the image in the same coordinate frame is a\nconvolution:\n$I(x,y) = (P * O)(x,y) + N(x,y)$,\nwhere\n$P$ is the point spread function (PSF) of the imaging system, and $N$\nis additive noise. We want to determine $O(x,y)$ knowing $I$ and $P$. This\ninverse problem has led to a large amount of work, the main difficulties \nbeing the existence of: (i) a cut-off frequency of the \nPSF, \nand (ii) the additive noise (see for example \\cite{ima:bertero98}).\n\nThe wavelet based non-iterative algorithm, \nthe wavelet-vaguelette decomposition \\cite{rest:donoho95b},\nconsists of first applying an inverse filtering\n($F = P^{-1} * I  +  P^{-1} * N = O + Z$\nwhere $\\hat{P}^{-1}(\\nu) = \\frac{1}{\\hat{P}(\\nu)}$). \nThe noise $Z =  P^{-1} * N$ is not white but remains \nGaussian. It is amplified when the deconvolution\nproblem is unstable. \nThen, a wavelet transform is applied on $F$, the wavelet coefficients\nare soft or hard thresholded \\cite{rest:donoho93_2}, \nand the inverse wavelet transform \nfurnishes the solution. \n\nThe method has been refined by \nadapting the wavelet basis to the frequency response of the inverse of $P$\n\\cite{rest:kalifa99}. This leads to a special basis,\nthe {\\em Mirror Wavelet Basis}.  This basis has a \ntime-frequency tiling structure different from the conventional wavelets one.\nIt isolates the frequency $\\nu_s$ where $\\hat{P}$ is close to zero, because \na singularity in $\\hat{P}^{-1}(\\nu_s)$ influences the noise variance in\nthe wavelet scale corresponding to the frequency band which includes $\\nu_s$.\nBecause it may not be possible to isolate all singularities, Neelamani\n\\cite{rest:neelamani99} has advocated a hybrid approach,\nand proposes to still use the Fourier domain to restrict excessive noise\namplification. These approaches are fast and competitive compared to linear methods, and\nthe wavelet thresholding removes the Gibbs oscillations. \nThis  presents however several drawbacks:\n(i) the first step (division in the Fourier space by the PSF) \ncannot always be done properly,\n(ii) the positivity a priori is not used, and\n(iii) it is not trivial to consider non-Gaussian noise.\n\nAs an alternative, \nseveral wavelet-based iterative algorithms have been proposed \n \\cite{starck:book98}, especially in the astronomical\ndomain where the positivity a priori is known to improve \nsignificantly the result. The simplest method consists of first \nestimating the multiresolution support $M$ (i.e. $M(j,x,y)= 1$ if   \nthe wavelet transform of the data presents a significant coefficient \nat band $j$ and at pixel position $(x,y)$, and $0$ otherwise), and to\napply the following iterative scheme:\n\\begin{equation}\nO^{n+1} = O^{n} + P^* * \\cW^{-1}[M.\\cW (I - P * O^n)]\n\\end{equation}\nwhere $\\cW$ is the wavelet transform operator.\nAt each iteration, information is extracted from the \nresidual only at scales and positions defined by the multiresolution support.\n$M$ is estimated from the input data and the correct noise modeling\ncan easily be considered.\n\n \n\\section{The Combined Deconvolution Method}\n\\label{cbdec}\n Similar to the filtering, we expect that the combination \nof different transforms can improve the quality of the result.\nThe combined approach for the deconvolution leads to two different \nmethods. \n\nIf the noise is Gaussian and if the division by the PSF in the Fourier space \ncan be carried out properly, then the deconvolution problem becomes a \nfiltering problem where the noise is still Gaussian, but not white.\nThe Combined Filtering Algorithm can then be applied using the curvelet \ntransform and the wavelet transform, but by estimating first the \ncorrect thresholds in the different bands of both transforms.  \nSince the mirror wavelet basis is known to produce better results than\nthe wavelet basis, it is recommended to use it instead of the standard\nundecimated wavelet transform.\n\nAn iterative deconvolution method \n is more general and can always be applied. \nFurthermore,\nthe correct noise modeling can much more easily be taken into account.\nThis approach consists of detecting, first, all the significant coefficients\nwith all multiscale transforms used. If we use $K$ transforms\n$T_1, \\dots, T_K$, we derive $K$ multiresolution supports $M_1, \\dots, M_K$\nfrom the input image $I$ using noise modeling.\n\nFor instance, in the case of Poisson noise, we apply the Anscombe transform\nto the data (i.e. $\\cA(I) = 2 \\sqrt{I + \\frac{3}{8}}$). Then\nwe detect the significant coefficients with the kth transform $T_k$, \nassuming Gaussian noise with standard deviation equal to 1,\nin $T_k \\cA(I)$ instead of $T_k I$.  $M_k(j,x,y) = 1$ if a coefficient\nin band $j$ at pixel position $(x,y)$ is detected , and  $M_k(j,x,y) = 0$\notherwise. For the band $J$ which corresponds to the smooth array\nin transforms such as the wavelet or the curvelet transform, \nwe force $M_k(J,x,y) = 1$ for all $(x,y)$.\n\nFollowing determination of a set of multiresolution supports, \nwe propose to solve\nthe following optimization problem:\n\\begin{equation}\n  \\label{eq:dec-min}\n  \\min \\cS(\\tilde O), \\quad \\mbox{subject to} \\quad \\tilde O \\in C,  \n\\end{equation}\nwhere $\\cS$ is an edge preservation penalization term defined by:\n\\[ \\cS(\\tilde O) = \\int \\parallel \\nabla \\tilde O \\parallel_p, \\] \nwith $p=1.1$.\n $C$ is the set of images $\\tilde{O}$ \nwhich obey the two constraints:\n\\begin{enumerate}\n\\item $\\tilde{O} \\ge 0$ (positivity).\n\\item $ M_k T_k I = M_k T_k [P *\\tilde{O}]$, for all $k$. \n\\end{enumerate}\nThe second constraint\nimposes fidelity to the data, or more exactly, \nto the significant coefficients of the data, \nobtained by the different transforms.\nNon-significant (i.e. noisy) coefficients are not taken into account, \npreventing any noise amplification in the final algorithm.\n\nThe solution is computed by using the \nprojected Landweber method \\cite{ima:bertero98}:\n\\begin{eqnarray}\n\\tilde O^{n+1} = {\\cP}_c \\left[ \n\\tilde O^n + \\alpha( P^* * {\\bar R}^n - \\lambda \\frac{\\partial \\cS(\\tilde O)}{\\partial O}) \\right]\n\\end{eqnarray}\nwhere ${\\cP}_c$ is the projection operator which enforces the positivity\n(i.e. set to 0 all negative values).\n${\\bar R}^n$ is the significant residual which\n is obtained using the following algorithm:\n\\begin{itemize}\n\\item Set $I^n_{0} = I^n = P * \\tilde O^n$.\n\\item For $k=1,\\dots,K$ do \n$\nI^n_k = I^n_{k-1} + T_k^{-1} \\left[ M_k (T_k I - T_k I^n_{k-1}) \\right] \\nonumber\n$\n\\item The significant residual ${\\bar R}^n$ is obtained by:\n  $ {\\bar R}^n = I^n_K - I^n $.\n\\end{itemize}\n\n$\\alpha$ is a convergence parameter and $\\lambda$ is the \nregularization hyperparameter. Since the noise is controlled by the\nmultiscale transforms, the regularization parameter does not   \nhave the same importance as in standard deconvolution methods.\nA much lower value is enough to remove the artifacts relative to the\nuse of the wavelets and the curvelets. The positivity constraint can\nbe applied at each iteration.\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n\\psfig{figure=phantom.ps,bbllx=8.2cm,bblly=12.6cm,bburx=12.7cm,bbury=17.1cm,width=7cm,height=7cm,clip=}\n\\psfig{figure=phantom_p.ps,bbllx=8.2cm,bblly=12.6cm,bburx=12.7cm,bbury=17.1cm,width=7cm,height=7cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=dec_mr_t24_p_n5_i400_s5.ps,bbllx=8.2cm,bblly=12.6cm,bburx=12.7cm,bbury=17.1cm,width=7cm,height=7cm,clip=}\n\\psfig{figure=dec_cb_s5_i400.ps,bbllx=8.2cm,bblly=12.6cm,bburx=12.7cm,bbury=17.1cm,width=7cm,height=7cm,clip=}\n}}\n}\n\\caption{Top, original image (phantom) and simulated data\n(i.e. convolved image plus Poisson noise). Bottom, deconvolved image\nby the wavelet based method and the combined approach.}\n\\label{fig_dec_phantom}\n\\end{figure}\nFigure~\\ref{fig_dec_phantom}, top, shows the Logan-Shepp Phantom \nand the simulated data, i.e. original image convolved by a Gaussian \nPSF (full width at half maximum,\nFWHM=3.2) and Poisson noise. Figure~\\ref{fig_dec_phantom}, \nbottom, shows the deconvolution with  (left) a pure wavelet deconvolution\nmethod (no penalization term) and (right) the combined deconvolution method\n(parameter $\\lambda = 0.4$).\n\n\n\\clearpage\n\\newpage\n", "meta": {"hexsha": "623e6ffec22376982b71d04595a4b111c3459943", "size": 8349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr4/ch_combdeconv.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_combdeconv.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_combdeconv.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.8870967742, "max_line_length": 119, "alphanum_fraction": 0.7514672416, "num_tokens": 2392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6900598849157447}}
{"text": "\\section{Constant Coefficients}\r\nThe general form of an nth order linear equation is\r\n\\begin{equation*}\r\n\ta_n(x)y^{(n)} + a_{n-1}y^{(n-1)} + \\ldots + a_1(x)y' + a_0y = b(x)\r\n\\end{equation*}\r\nIf each $a_i(x)$ is a constant, then the equation has constant coefficients.\\\\\r\n\r\n\\noindent\r\nWe already know how to solve linear first order differential equations using an integrating factor, but let's see if we can develop a method that can solve any order linear, homogeneous differential equation with constant coefficients.\r\n\r\n\\ifodd\\includeHigherOrderExamples\\input{./higherOrder/constCoeffs/constCoeffs_example.tex}\\fi\r\n\r\n% Auxillary Equation\r\n\\input{./higherOrder/constCoeffs/auxillaryEquation.tex}", "meta": {"hexsha": "43cdf6c86de95f4ca2cceccabd0926b241f5ba58", "size": 697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/constCoeffs/constCoeffs.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/higherOrder/constCoeffs/constCoeffs.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/higherOrder/constCoeffs/constCoeffs.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.7857142857, "max_line_length": 236, "alphanum_fraction": 0.7618364419, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6900189148584394}}
{"text": "\\documentclass[ag.tex]{subfiles}\n\n\\begin{document}\n\n\\chapter{Preliminaries}\n\n\\section{Commutative algebra}\n\nWe begin with some algebraic prerequisites.  For more see \\cite{atiyah2018introduction}.\n\n\\begin{definition}\nA \\textit{commutative ring} $(R, +, \\cdot, 0,1)$ is an abelian group $(R,+,0)$ along with an associative binary operator $\\cdot$ and a unit element $1$ such that for all $x,y,z \\in R$\n\n\\begin{enumerate}\n\\item $x \\cdot y = y \\cdot x$,\n\\item $x \\cdot 1 = 1$, and\n\\item $x\\cdot(y+z) = x\\cdot y+x\\cdot z$\n\n\\end{enumerate}\n\n\\end{definition}\n\nWe call a commutative ring $(R, +, \\cdot , 0,1)$ simply a \\textit{ring} and write it as $R$ when there is no ambiguity. Also we denote $x \\cdot y$ by $xy$.\n\n\\begin{definition}\nAn \\textit{ideal} of a ring $R$ is a subset $I \\subset R$ that is closed under addition ($+$) and \"absorbs\" multiplication from elements of $R$: for all $x \\in R$ and $y \\in I$,  $xy \\in I$.\n\\end{definition}\n\n\\begin{proposition}\\label{primes_map_to_primes}\nThe images and preimages of a prime ideal under ring homomorphisms are prime.\n\\end{proposition}\n\n\\section{Categories and functors}\n\n\\begin{definition}\nA \\textit{category} $\\mathcal{C}$ consists of a collection of \\textit{objects}, a set $\\mathcal{C}(A,B)$ of \\textit{morphisms} between any two objects, an \\textit{identity} morphism $id_A \\in \\mathcal{C}(A,A)$ for each object $A$, and a composition law\n\n\\begin{equation}\n\\circ : \\mathcal{C} ( B , C ) \\times \\mathcal{C} ( A , B ) \\to \\mathcal{C} ( A , C )\n\\end{equation}\n\nfor each triple of objects $A, B, C$.  Composition must be associative, and identity\nmorphisms must behave as their names indicate: $h \\circ (g\\circ f)=(h\\circ g)\\circ f, id\\circ f=f$, and $f\\circ id=f$\nwhenever the the composites are defined.\n\\end{definition}\n\n\\begin{definition}\\label{terminal object}\nA \\textit{terminal object} of a category $\\mathcal{C}$ is an object $T$ to which there is a unique morphism from each object of $\\mathcal{C}$.\n\\end{definition}\n\n\\begin{definition}\nA \\textit{functor} $F : \\mathcal{C} \\to \\mathcal{D}$ assigns an object $F(A)$ of $\\mathcal{D}$ to each object $A$ of $\\mathcal{C}$ and a morphism $F(f) : F(A) \\to F(B)$ of $\\mathcal{D}$ to each morphism $f:A\\to B$ of $\\mathcal{C}$ such that \n\n\\begin{equation}\nF(id_A) = id_{F(A)} \\text{ and } F(g \\circ f) = F(g) \\circ F(f).\n\\end{equation}\n\n\\begin{definition}\nA \\textit{natural transformation} $\\alpha : F \\to G$ between functors $F, G: \\mathcal{C} \\to \\mathcal{D}$ consists of a morphism $\\alpha_A : F(A) \\to G(A)$ for each object $A$ of $\\mathcal{C}$ such that the following diagram commutes for each morphism $f : A \\to B$ of $\\mathcal{C}$:\n\n\\begin{center}\n\\begin{tikzcd}\nF(A) \\arrow[r, \"F(f)\"] \\arrow[d, \"\\alpha_A\"]\n& F(B) \\arrow[d, \"\\alpha_B\"] \\\\\nG(A) \\arrow[r, \"G(f)\"]\n& |[]| G(B)\n\\end{tikzcd}\n\\end{center}\n\\end{definition}\n\n\\end{definition}\n\n\\end{document}", "meta": {"hexsha": "c1bd5993f45c8fb18c30e840d1fe1e15ead5985e", "size": 2857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prelim.tex", "max_stars_repo_name": "saran-sankar/ag", "max_stars_repo_head_hexsha": "f25f9dcd03c844c4c5eabb29b0f75e0e1c523741", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "prelim.tex", "max_issues_repo_name": "saran-sankar/ag", "max_issues_repo_head_hexsha": "f25f9dcd03c844c4c5eabb29b0f75e0e1c523741", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prelim.tex", "max_forks_repo_name": "saran-sankar/ag", "max_forks_repo_head_hexsha": "f25f9dcd03c844c4c5eabb29b0f75e0e1c523741", "max_forks_repo_licenses": ["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.1369863014, "max_line_length": 283, "alphanum_fraction": 0.6821841092, "num_tokens": 970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694177, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6900189058459527}}
{"text": "\\section{Equivalence of Partial Recursive and TM Computable \\mbox{Functions}}\n\nA key theorem is that all partial recursive functions are Turing Machine computable, and vice versa.\n\n\\subsection{TM Computable Functions Are Partial Recursive}\n\nRecall that a partial function $ f: \\Nat^n \\to \\Nat $ is TM computable if $ f = \\varphi_{T, n} $ for some numerical TM $ T $.\n\nLet $ T = (Q, F, A, I, \\tau, q_0) $ be a numerical Turing machine (i.e. deterministic, $ F = I = \\emptyset $, $ A = \\set{0, 1} $).\n\nRecall that $ \\varphi_{T, n}(\\vec{x}) = \\begin{cases}\ny &\\text{if the computation starting with } (q_0, \\underline{0}1^{x_1} \\dots 01^{x_n}) \\text{ halts with } (q, \\underline{0}1^y)\\\\\n\\textit{undefined} &\\text{otherwise}\n\\end{cases} $\n\nIt is convenient to modify $ T $ slightly. Add two new states $ p $ and $ h $, and the transitions:\n\n\\begin{itemize}\n\t\n\t\\item $ (q, a, p, a, L) $ for all $ (q, a) \\in Q \\times A $ s.t. no element in $ \\tau $ starts with $ (q, a) $\n\t\n\t\\item $ (p, a, h, a, R) $ for all $ a \\in A $ (i.e. for $ a = 0 $ and $ a = 1 $)\n\t\n\t\\item $ (h, a, p, a, L) $ for all $ a \\in A $\n\t\n\\end{itemize}\n\nCall the new machine $ T' $, so $ Q' = Q \\cup \\set{p, h} $, with $ C' $ being the set of configurations.\n\nThen $ T' $ is still deterministic, and transitions have the form:\n\\begin{equation*}\n(q, a, N(q, a), R(q, a), D(q, a)) \\in Q' \\times A \\times Q' \\times A \\times \\set{L, R}\n\\end{equation*}\nwhere $ N, R, D $ are functions on $ Q' \\times A $.\n\nThen, we number the states such that $ Q = \\set{0, 1, \\dots, r - 1} $, where $ h = 0 $ and $ p = 1 $. We encode $ L = 0 $ and $ R = 1 $.\n\nNow, $ Q' \\times A $ is a finite subset of $ \\Nat^2 $; put $ N(x, y) = R(x, y) = D(x, y) = 0 $ for $ (x, y) \\in \\Nat^2 \\setminus (Q' \\times A) $. Then, $ N, R, D $ are primitive recursive functions $ \\Nat^2 \\to \\Nat $.\n\nDefine $ Code: C' \\to \\Nat $ by $ Code(q, a, \\alpha, \\beta) = 2^q 3^a 5^{\\sigma(\\alpha)} 7^{\\sigma(\\beta)} $, where $ \\sigma $ encodes a function in the binary representation of an integer:\n\\begin{equation*}\n\\sigma(f) = f(0) + 2 \\cdot f(1) + 2^2 \\cdot f(2) + \\dots\n\\end{equation*}\nThen $ Code $ is an injective (one-to-one) function.\n\nThere is a primitive recursive function $ Next: \\Nat \\to \\Nat $ s.t. $ Next(Code(c)) = Code(\\delta(c)) $, for $ c \\in C' $ where $ \\delta $ is the transition function of $ T' $.\n\n\\begin{proof}\n\nLet $ c = (q, a, \\alpha, \\beta) $; let $ x \\in \\Nat = Code(c) = 2^q 3^a 5^{\\sigma(\\alpha)} 7^{\\sigma(\\beta)} $.\n\nThen, we express $ Next(x) = Code(\\delta(c)) $ in terms of $ x $.\n\nFirst, note that $ q = \\log_2 x $ and $ a = \\log_3 x $ (here $ \\log $ simply retrieves the exponents, it is not the normal logarithm function from calculus/analysis).\n\nWe have that $ N(q, a) = N(\\log_2 x, \\log_3 x) $; the $ \\log $ and $ N $ functions are primitive recursive.\n\nThere are then two cases, moving left or right:\n\n\\newpage\n\n\\subsubsection{Move left - $ D(q, a) = 0 $}\n\nWe have that $ \\delta(c) = (q', a', \\alpha', \\beta') $, where $ q' = N(q, a) $ and $ a' = \\beta(0) $.\n\n$ Next(x) = Code(\\delta(c)) = 2^{N(q, a)} 3^{\\beta(0)} 5^{\\sigma(\\alpha')} 7^{\\sigma(\\beta')} $\n\n$ \\beta(0) = rem(2, \\log_7 (x)) $ where $ rem $ is the remainder function (which is prim. rec.).\n\n$ \\sigma(\\alpha') = R(q, a) + 2 \\alpha(0) + 2^2 \\alpha(1) + \\dots = R(\\log_2 x, \\log_3 x) + 2 \\log_5 x$, where $ R $ is prim. rec.\n\n$ \\sigma(\\beta') = \\beta(1) + 2 \\beta(2) + 2^2 \\beta(3) + \\dots = quo(2, \\sigma(\\beta)) = quo(2, \\log_7 x) $, where $ quo $ is the quotient / `integer division' function (which is prim. rec.).\n\n\\subsubsection{Move right - $ D(q, a) = 1 $}\n\nIn this case we have that $ \\delta(c) = (q', a', \\alpha', \\beta') $, where $ q' = N(q, a) $ and $ a' = \\alpha(0) $.\n\n$ \\alpha(0) = rem(2, \\log_5 x) $\n\n$ \\sigma(\\alpha') = quo(2, \\log_5 x) $\n\n$ \\sigma(\\beta') = R(\\log_2 x, \\log_3 x) + 2 \\log_7 x $\n\n\\subsubsection{Conclusion}\n\nWe can combine both cases using $ E(x) = D(\\log_2 x, \\log_3 x) $. This gives us the functions:\n\n$ F_1(x) = N(\\log_2 x, \\log_3 x) $\n\n$ F_2(x) = (1 \\monus E(x)) \\cdot rem(2, \\log_7 x) + E(x) rem(2, \\log_5 x) $\n\n$ F_3(x) = (1 \\monus E(x)) \\cdot (R(\\log_2 x \\log_3 x) + 2 \\log_5 x) + E(x) \\cdot quo(2, \\log_5 x) $\n\n$ F_4(x) = (1 \\monus E(x)) \\cdot quo(2, \\log_7 x) + E(x) \\cdot(R(\\log_2 x, \\log_3 x) + 2 \\log_7 x) $\n\nClearly each of these is a composition of primitive recursive functions, and so each is primitive recursive.\n\nThen, $ Next(x) = 2^{F_1(x)} 3^{F_2(x)} 5^{F_3(x)} 7^{F_4(x)} $. This is a composition of exponentiation and functions known to be primitive recursive, so $ Next(x) $ is also primitive recursive.\n\n\\end{proof}\n\nRecall that if $ f: \\Nat \\to \\Nat $ is primitive recursive, then its iterate $ F: \\Nat^2 \\to \\Nat $ is also prim. rec.\n\nLet $ \\bar{\\delta} $ be the iterate of $ \\delta $. If $ Comp $ is the iterate of $ Next $, then $ Comp(Code(c), t) = Code(\\bar{\\delta}(c, t)) $ for any $ c \\in C' $ and $ t \\in \\Nat $.\n \n\\begin{proof}\n\tUse induction on $ t $.\n\t\n\tFirst, $ Comp(Code(c), 0) = Code(c) = Code(\\bar{\\delta}(c, 0)) $.\n\t\n\tNow, assume that $ Comp(Code(c), t) = Code(\\bar{\\delta}(c, t)) $ holds.\n\t\n\tThen, we have:\n\t\\begin{align*}\n\tComp(Code(c), t + 1) &= Next(Comp(Code(c), t))\\\\\n\t\t\t\t\t\t &= Next(Code(\\bar{\\delta}(c, t)))\\\\\n\t\t\t\t\t\t &= Code(\\delta(\\bar{\\delta}(c, t)))\\\\\n\t\t\t\t\t\t &= Code(\\bar{\\delta}(c, t + 1))\n\t\\end{align*}\n\\end{proof}\n\n\\newpage\n\nDefine the function $ In_{T, n}: \\Nat^n \\to C' $, such that $ In_{T, n}(\\vec{x}) $ returns the initial configuration of $ T $ when started with the tape described by $ Tape(\\vec{x}) $.\n\n\\textbf{Main theorem}: the function $ \\varphi_{T, n} $ is partial recursive.\n\n\\begin{proof}\n\t\nNote $ \\varphi_{T, n}(\\vec{x}) = \\begin{cases}\ny &\\text{ if } \\exists t \\in \\Nat \\text{ s.t. } \\bar{\\delta}(In_{T, n}(\\vec{x}), t) = (h, \\underline{0} 1^y) \\text{ for some } y \\in \\Nat\\\\\n\\textit{undefined} &\\text{otherwise}\n\\end{cases} $\n\nAlso note that $ Code(h, \\underline{0} 1^y) = 2^0 3^0 5^{1 + 2 + 2^2 + \\dots + 2^{y - 1}} 7^0 = 5^{2^y - 1}$.\n\nIf $ \\bar{\\delta}(In_{T, n}(\\vec{x}), t) = (h, \\underline{0} 1^y) $ for some $ t, y \\in \\Nat $, then we have that:\n\n$ Comp(Code(In_{T, n}(\\vec{x})), t) = Code(\\bar{\\delta}(In_{T, n}(\\vec{x}), t)) = 5^{2^y - 1} $\n\nDefine $ \\psi: \\Nat^{n+1} \\to \\Nat $ by $ \\psi(\\vec{x}, t) = Comp(Code(In_{T, n}(\\vec{x})), t) $.\n\nThe composition $ Code(In_{T, n}(\\vec{x})) $ is primitive recursive (from assignments), and $ Comp $ is primitive recursive since it is the iterate of the primitive recursive $ Next $. Therefore $ \\psi $ is primitive recursive. Then:\n\\begin{equation*}\n\\varphi_{T, n}(\\vec{x}) = \\begin{cases}\n\\log_2 (1 + \\log_5(\\psi(\\vec{x}, t))) &\\text{ for any } t \\in \\Nat \\text{ s.t. } \\psi(\\vec{x}, t) = 5^{2^y - 1} \\text{ for some } y\\\\\n\\textit{undefined} &\\text{otherwise}\n\\end{cases}\n\\end{equation*}e $ P $ defined by $ P(\\vec{x}, t) \\text{ is true } \\iff \\psi(\\vec{x}, t) = S^{s^y - 1} \\text{ for some y} $ is primitive recursive.\nThe functions functions $ F $ and $ G $ defined as follows are then also primitive recursive:\n\\begin{align*}\n&F(\\vec{x}, t) = \\log_2 (1 + \\log_5(\\psi(\\vec{x}, t)))\\\\\n&G(\\vec{x}, t) = 1 - \\chi_{P}(\\vec{x}, t)\n\\end{align*}\n\nThen we have that:\n\\begin{equation*}\n\\varphi_{T, n}(\\vec{x}) = \\begin{cases}\nF(\\vec{x}, t) &\\text{ for any } t \\in \\Nat \\text{ s.t. } G(\\vec{x}, t) = 0\\\\\n\\textit{undefined} &\\text{otherwise}\n\\end{cases} \n\\end{equation*}\nOr equivalently:\n\\begin{equation*}\n\\varphi_{T, n}(\\vec{x}) = F(\\vec{x}, \\mu t (G(\\vec{x}, t) = 0))\n\\end{equation*}\n\nwhich is a composition of primitive recursive functions and unbounded minimisation. Therefore $ \\varphi_{T, n} $ is partial recursive.\n\n\\end{proof}\n\nAs it turns out, for a partial function $ f: \\Nat^n \\to \\Nat $, the following are equivalent:\n\n\\begin{enumerate}\n\t\\item $ f $ is partial recursive\n\t\\item $ f $ is abacus computable\n\t\\item $ f $ is computable by a register program\n\t\\item $ f $ is Turing Machine computable\n\\end{enumerate}\n\n\n\n\\subsection{Other Results in Computability Theory}\n\nAnother result is that the class of recursive functions is the same as the class of partial recursive functions that are total (not actually a trivial statement!)\n\n\\subsubsection{The Halting Problem}\n\nLet $ \\TMs $ be the set of numerical Turing machines whose set of states is $ \\text{0, 1, \\dots, r} $ for some $ r \\in \\Nat $. Then $ \\TMs $ is countable, and as a corollary, there are countably many partial recursive functions.\n\nAn \\textit{indexing} of a countable set is an infinite sequence $ \\psi_0, \\psi_1, \\dots $ of elements of $ S $ that includes all elements of $ S $ (though there may be repetitions).\n\nImportant theorem: Let $ T_0, T_1, \\dots $ be any indexing of $ \\TMs $. Let $ \\psi_m := \\varphi_{T_m, 1} $. Then the function $ f: \\Nat^2 \\to \\Nat $ defined by:\n\\begin{equation*}\nf(x, y) = \\begin{cases}\n1 &\\text{if } \\psi_x(y) \\text{ is defined}\\\\\n2 &\\text{if } \\psi_x(y) \\text{ is undefined}\n\\end{cases}\n\\end{equation*}\nis not recursive.\n\n\\begin{proof}\n\nAssume that $ f $ is recursive, and let $ g: \\Nat \\to \\Nat $ be defined by $ g(x) = f(x, x) $ for $ x \\in \\Nat $. Clearly $ g $ is recursive.\n\nDefine $ \\theta: \\Nat \\to \\Nat $ by:\n\\begin{equation*}\n\\theta(x) = \\begin{cases}\n0 &\\text{if } g(x) = 0\\\\\n\\textit{undefined} &\\text{if } g(x) = 1\n\\end{cases}\n\\end{equation*}\n\nNote that $ \\theta(x) = \\mu y((y  + 1) \\cdot g(x) = 0) $, so $ \\theta $ is partial recursive.\n\nNow we claim that $ \\theta $ \\textit{cannot} be partial recursive.\n\nNote that:\n\\begin{equation*}\n\\theta(x) = \\begin{cases}\n0 &\\text{if } \\psi_x(x) \\text{ is undefined}\\\\\n\\textit{undefined} &\\text{if } \\psi_x(x) \\text{ is defined}\n\\end{cases}\n\\end{equation*}\n\nSince $ \\theta $ is partial recursive, $ \\theta = \\psi_i $ for some $ i \\in \\Nat $, and so $ \\theta(i) = \\psi_i(i) $. Then let the predicate $ P(x) $ represent the statement ``$ \\theta(x) $ is defined\", or equivalently, ``$ \\psi_x(x) $ is undefined\".\n\nThen consider $ P(i) $, which is:\n\\begin{equation*}\n\\theta(i) \\text{ is defined} \\iff \\psi_i(i) \\text{ is defined} \\iff \\psi_i(i) \\text{ is undefined}\n\\end{equation*}\n\nThis is a contradiction. Therefore, the initial assumption (that $ f $ is recursive) is false.\n\n\\end{proof}", "meta": {"hexsha": "d23554b590933dc5371c9dfb73402806b41a0b11", "size": 10113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH3306/computability/c_equiv.tex", "max_stars_repo_name": "mcoot/CourseNotes", "max_stars_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATH3306/computability/c_equiv.tex", "max_issues_repo_name": "mcoot/CourseNotes", "max_issues_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATH3306/computability/c_equiv.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": 43.0340425532, "max_line_length": 250, "alphanum_fraction": 0.6082270345, "num_tokens": 3722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6900189039604018}}
{"text": "\\section{The Hierarchization Problem}\n\\label{sec:41problem}\n\nLet $\\sgset \\subset \\clint{0, 1}^d$ be a general (sparse) grid that\nmay be spatially adaptive, i.e.,\nof the form $\\sgset = \\{\\gp{\\*l,\\*i} \\mid (\\*l, \\*i) \\in \\liset\\}$,\nwhere $\\liset$ is a set of level-index pairs $(\\*l, \\*i)$ with $\\*l \\in \\natz^d$\nand $\\*i \\in \\hiset{\\*l}$ such that\n$\\ngp \\ceq \\setsize{\\sgset} = \\setsize{\\liset} < \\infty$\n(see \\cref{sec:233spatiallyAdaptiveSG}).\nThe \\term{hierarchization problem} is finding\n\\term{hierarchical surpluses}\n$(\\surplus{\\*l',\\*i'})_{(\\*l',\\*i') \\in \\liset} \\in \\real^{\\ngp}$ such that\n\\begin{equation}\n  \\label{eq:hierarchizationProblem}\n  \\largesum{(\\*l', \\*i') \\in \\liset} \\surplus{\\*l',\\*i'}\n  \\basis{\\*l',\\*i'}(\\gp{\\*l,\\*i}) = \\fcnval{\\*l,\\*i}\n  \\quad\\text{for all}\\quad\n  (\\*l, \\*i) \\in \\liset,\n\\end{equation}\nwhere $\\basis{\\*l',\\*i'}$ are arbitrary tensor product basis functions and\n$(\\fcnval{\\*l,\\*i})_{(\\*l,\\*i) \\in \\liset} \\in \\real^{\\ngp}$ is a set of\nfunction values $\\objfun(\\gp{\\*l,\\*i})$\nat the grid points $\\gp{\\*l,\\*i}$.\nThis then defines the interpolant $\\sgintp$ as\n\\begin{equation}\n  \\label{eq:hierarchizationInterpolant}\n  \\sgintp\\colon \\clint{\\*0, \\*1} \\to \\real,\\quad\n  \\sgintp \\ceq\n  \\largesum{(\\*l', \\*i') \\in \\liset} \\surplus{\\*l',\\*i'}\n  \\basis{\\*l',\\*i'},\n\\end{equation}\nwhich interpolates $\\objfun$ at the grid points $\\gp{\\*l,\\*i}$ of $\\sgset$.\n\\Cref{fig:hierarchization} shows the process of hierarchizing given\nfunction values and evaluating the resulting interpolant.\n\n\\begin{figure}\n  \\subcaptionbox{%\n    The objective function $\\objfun$ is sampled at the grid points\n    $\\gp{l,i} \\in \\sgset$ to obtain function values $\\fcnval{l,i}$,\n    which form the input vector $\\vlinin$ for the linear operator\n    $\\linop = \\intpmatinv$.%\n  }[46mm]{%\n    \\includegraphics{hierarchization_1}%\n  }%\n  \\hfill%\n  \\subcaptionbox{%\n    The linear operator $\\linop$ is applied to $\\vlinin$ to obtain\n    the output vector $\\vlinout$, which contains the hierarchical surpluses\n    $\\surplus{l,i}$ ($(l,i) \\in \\liset$).%\n  }[46mm]{%\n    \\includegraphics{hierarchization_2}%\n  }%\n  \\hfill%\n  \\subcaptionbox{%\n    The interpolant $\\sgintp$ \\emph{(black dashed line)}\n    is evaluated at $x \\in \\clint{0, 1}$\n    by adding contributions \\emph{(black dotted lines)}\n    of weighted basis functions $\\surplus{l,i} \\basis{l,i}$\n    \\emph{(colored),} obtaining $\\sgintp(x)$ \\emph{(cross).}%\n  }[46mm]{%\n    \\includegraphics{hierarchization_3}%\n  }%\n  \\caption[%\n    Hierarchization of function values and evaluation of interpolant%\n  ]{%\n    Hierarchization of function values $\\fcnval{l,i}$ \\emph{(left)}\n    to obtain hierarchical surpluses $\\surplus{l,i}$ \\emph{(center)} and\n    evaluation of the resulting interpolant $\\sgintp$ \\emph{(right),}\n    using a univariate grid and the piecewise linear basis as an example.%\n  }%\n  \\label{fig:hierarchization}%\n\\end{figure}\n\nWe explicitly allow $\\basis{\\*l',\\*i'}$ to be nodal basis functions,\nin which case $\\*l'$ is constant and\n$\\sgset$ is a full grid.\nStrictly speaking, the problem is then an \\term{interpolation problem}\nand the $\\surplus{\\*l',\\*i'}$ are \\term{interpolation coefficients.}\nHowever, we still apply the terms\n``hierarchization'' and ``hierarchical surpluses'' in this case\nto keep the terminology consistent.\n\n\\paragraph{Hierarchization as a linear operator}\n\nThe example of hierarchization can be generalized\nto arbitrary linear operators\n\\begin{equation}\n  \\linop\\colon \\real^{\\ngp} \\to \\real^{\\ngp},\\quad\n  \\vlinin \\mapsto \\vlinout = \\linop[\\vlinin],\n\\end{equation}\nwhere $\\linop$ depends on the grid $\\sgset$ at hand.\nInput $\\vlinin$ and output $\\vlinout$ are scalar-valued data%\n\\begin{equation}\n  \\vlinin = (\\linin{\\*l,\\*i})_{(\\*l,\\*i) \\in \\liset} \\in \\real^{\\ngp},\\quad\n  \\vlinout = (\\linout{\\*l,\\*i})_{(\\*l,\\*i) \\in \\liset} \\in \\real^{\\ngp},\n\\end{equation}\nwhich give one scalar per grid point $\\gp{\\*l,\\*i} \\in \\sgset$.\nFor the case of hierarchization,\n$\\linop$ is the inverse of the \\term{interpolation matrix}\n$\\intpmat \\in \\real^{\\ngp \\times \\ngp}$:\n\\begin{subequations}\n  \\label{eq:hierarchizationSLE}\n  \\begin{equation}\n    \\linop = \\intpmatinv,\\quad\n    \\intpmat = (\\basis{\\*l',\\*i'}(\\gp{\\*l,\\*i}))_%\n    {(\\*l,\\*i),(\\*l',\\*i') \\in \\liset},\\quad\n    \\vlinin = (\\fcnval{\\*l,\\*i})_{(\\*l,\\*i) \\in \\liset},\\quad\n    \\vlinout = (\\surplus{\\*l',\\*i'})_{(\\*l',\\*i') \\in \\liset}.\n    \\hspace*{-1mm}\n  \\end{equation}\n  This means that we can determine the $\\surplus{\\*l',\\*i'}$ by solving\n  the $\\ngp \\times \\ngp$ system of linear equations\n  \\begin{equation}\n    \\vlinout = \\linop[\\vlinin]\n    \\quad\\iff\\quad\n    \\intpmat \\cdot (\\surplus{\\*l',\\*i'})_{(\\*l',\\*i') \\in \\liset}\n    = (\\fcnval{\\*l,\\*i})_{(\\*l,\\*i) \\in \\liset}.\n  \\end{equation}\n\\end{subequations}\n\n\\paragraph{Complexity of B-spline hierarchization}\n\nAs noted in \\cite{Valentin18Fundamental},\nhierarchization on sparse grids with hierarchical B-splines\n$\\bspl{\\*l,\\*i}{\\*p}$ of degree $\\*p$\nas basis functions $\\basis{\\*l,\\*i}$ is a tedious task.\nThe corresponding linear system \\eqref{eq:hierarchizationSLE} is in general\nnon-symmetric\n(i.e., $\\bspl{\\*l',\\*i'}{\\*p}(\\gp{\\*l,\\*i}) \\not=\n\\bspl{\\*l,\\*i}{\\*p}(\\gp{\\*l',\\*i'})$) and densely populated.\nThis is because the matrix entry in the $(\\*l,\\*i)$-th row and\n$(\\*l',\\*i')$-th column vanishes if and only if\n\\begin{equation}\n  \\gp{\\*l,\\*i} \\notin \\interiorsupp \\bspl{\\*l',\\*i'}{\\*p}\n  \\iff\n  \\exlarge{t = 1, \\dotsc, d}{\n    \\gp{l_t,i_t} \\notin\n    \\opintscaled{\n      \\gp{l'_t,i'_t} - \\tfrac{p_t+1}{2} \\ms{l'_t},\\,\n      \\gp{l'_t,i'_t} + \\tfrac{p_t+1}{2} \\ms{l'_t}\n    }\n  },\n\\end{equation}\nwhere $\\interiorsupp$ is the interior of the support\n\\cite{Valentin18Fundamental}.\nFor coarse levels $\\*l'$, the mesh size $\\ms{l'_t}$ is large in\nevery dimension $t$, which implies that $\\interiorsupp \\bspl{\\*l',\\*i'}{\\*p}$\ncontains most of the grid points.\nIn contrast to the hat function case ($\\*p = \\*1$),\nthe value of $\\surplus{\\*l',\\*i'}$ depends not only on\n$\\fcnval{\\*l,\\*i}$ and the data of the $3^d - 1$ neighboring grid points\non the boundary of $\\supp \\bspl{\\*l',\\*i'}{\\*1}$,\nbut potentially on the data of the whole grid.\nThis is shown in \\cref{fig:matrixDensityPattern}:\nThere are at most $3^d = 9$ non-zero entries in each row of $\\intpmatinv$\nfor $\\*p = \\*1$ and $d = 2$.\nAs soon as the B-spline degree is increased,\nboth $\\intpmat$ and $\\intpmatinv$ become significantly denser.\n\n\\begin{SCfigure}\n  \\includegraphics{matrixDensityPattern_1}%\n  \\caption[%\n    Density pattern of hierarchization matrices and of their inverses%\n  ]{%\n    Density pattern\n    of the hierarchization matrix $\\intpmat$\n    \\emph{(middle row, \\textcolor{C0}{blue})} and\n    of its inverse $\\intpmatinv$\n    \\emph{(bottom row, \\textcolor{C1}{red})}\n    for the regular sparse grid $\\coarseregsgset{n}{d}{1}$\n    with $n = 4$ and $d = 2$ \\emph{(top row)}\n    and uniform hierarchical B-splines $\\bspl{\\*l,\\*i}{\\*p}$\n    for degrees $\\*p \\in \\{\\*1, \\*3, \\*5\\}$.\n    The \\textcolor{C0}{blue areas} in the top row\n    show the extent of the support of one specific basis function\n    $\\bspl{\\*l',\\*i'}{\\*p}$ with $\\*l' = (2, 2)$ and $\\*i' = (1, 1)$\n    (\\emph{cross:} corresponding grid point $\\gp{\\*l',\\*i'}$).\n    The \\textcolor{C0}{blue points} are the grid points at which\n    $\\bspl{\\*l',\\*i'}{\\*p}$ is non-zero.%\n  }%\n  \\label{fig:matrixDensityPattern}%\n\\end{SCfigure}\n\nThis prohibits the use of the \\up\\punctfix{,}\nwhich we will discuss in the next section,\non sparse grids with hierarchical B-splines.\nConsequently, we have to solve the linear system\n\\eqref{eq:hierarchizationSLE}, which is significantly more time-consuming,\nas it takes between $\\landauOmega{\\ngp^2 d}$ and $\\landauO{\\ngp^2 (N+d)}$ time\nvia Gaussian elimination.%\n\\footnote{%\n  $\\landauOmega{\\ngp^2 d}$ for assembling $\\intpmat$ and\n  $\\landauO{\\ngp^3}$ for solving the system.\n}\nIn addition, if we use an explicit solver for the linear system,\nwe additionally have to store an $\\ngp \\times \\ngp$ matrix in memory.\nHowever, a grid of size $\\ngp = \\num{116000}$ already exceeds the memory\nof a \\SI{128}{\\gibi\\byte} supercomputer node,\nif we explicitly store the full matrix in double precision.\nIn comparison, for the hat function basis,\nthe \\up only requires $\\landauO{\\ngp d}$ time and $\\landauO{\\ngp}$ memory.\n\n\\paragraph{Notation}\n\nWe do not need the hierarchical level-index information $(\\*l, \\*i)$ in\n$\\sgset$, $\\liset$, $\\vlinin$, and $\\vlinout$\nfor most of the considerations in this chapter.\nIn these cases, we assume that in each dimension $t$, the level-index pairs\n$(l_t, i_t)$ ($l_t \\in \\natz$, $i_t \\in \\hiset{l_t}$)\nare continuously enumerated by a single index $k_t = k_t(l_t, i_t) \\in \\natz$.\nWe identify $(\\*l, \\*i)$ with a single index $\\*k$,\nwhose $t$-th component is given by $k_t(l_t, i_t)$.\nHence,\nwe regard $\\liset$ as a subset $\\liset \\ceq \\{\\*k \\mid \\*x_\\*k \\in \\sgset\\}$\nof $\\natz^d$.\nWe will switch between the notations whenever appropriate.\nAll statements that are formulated in the $\\*k$ notation are\nvalid for both the nodal and the hierarchical basis.\n\n\\usenotation{kT00}\nIn the following, $k_t$ denotes the $t$-th component of a $d$-vector $\\*k$\nas usual.\n\\usenotation{kT10}\nWith $\\*k_{-t}$, we denote the $(d-1)$-vector that is obtained from $\\*k$\nby omitting the $t$-th component,\ni.e., $\\*k_{-t} \\ceq (k_1, \\dotsc, k_{t-1}, k_{t+1}, \\dotsc, k_d)$.\n\\usenotation{kT20}\nFor a $j$-tuple $T = (t_1, \\dotsc, t_j) \\in \\{1, \\dotsc, d\\}^j$,\nwe define $\\*k_T$ to be the $j$-vector $(k_{t_1}, \\dotsc, k_{t_j})$\nthat only contains the entries of the dimensions listed in $T$.\n\\usenotation{kT30}\nAccordingly, $\\*k_{-T}$ is defined as the $(d-j)$-vector\nthat contains the entries of the remaining dimensions\n(sorted by the dimension $t$).\nWe define $\\*k_{\\range{a}{b}} \\ceq (k_a, k_{a+1}, \\dotsc, k_b)$\nas an indexing shortcut ($a \\le b$).\n", "meta": {"hexsha": "6e8389cc061b269d58d23996ff22a080c6ca68d8", "size": 9831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/41problem.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/41problem.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/41problem.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": 41.3067226891, "max_line_length": 80, "alphanum_fraction": 0.6566981996, "num_tokens": 3498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.690018901986933}}
{"text": "% !TEX root = ../../../proposal.tex\n\\label{sec:adapted-bb}\n\n\\subsection{Success probability of fractions}\n\\label{sec:fraction-probability}\n\nFor a given fraction $u/t$, the success probability with a randomly chosen\n\\tlsconform ciphertext can be computed as follows.  Let $m_0$ be a random\n\\tlsconform message, $m_1 = m_0 \\cdot u/t$, and let $\\ell_k$ be the expected\nlength of the unpadded message.  For $s = u/t \\bmod N$ where $u$ and $t$ are coprime, $m_1$ will be \\sslconform if the following conditions all hold:\n\n\\begin{enumerate}\n\t\\item $m_0$ is divisible by $t$. For a randomly generated $m_0$, this\n\tcondition holds with probability $1/t$.\n\n\t\\item $m_1[1] = 0$ and $m_1[2] = 2$, or the integer\n\t$m \\cdot u/t \\in [2B, 3B)$.\n\tFor a randomly generated $m_0$ divisible by $t$, this condition holds\n\twith probability\n\\begin{equation*}\nP = \n\\begin{cases}\n3 - 2 \\cdot t/u & \\text{for }   2/3 < u/t < 1 \\\\\n3 \\cdot t/u - 2 & \\text{for }   1 < u/t < 3/2 \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\label{eq:oracle}\n\\end{equation*} \n\n\t\\item $\\forall i \\in [3, \\ell_m-(\\ell_k+1)], m_1[i] \\neq 0$, or all bytes\n\tbetween the first two bytes and the $(k+1)$ least significant bytes are\n\tnon-zero.  This condition holds with probability\n\t$(1 - 1/256)^{\\ell_m-(\\ell_k+3)}$.\n\n\t\\item $m_1[\\ell_m-\\ell_k] = 0$: the $(\\ell_k+1)$st least significant\n\tbyte is 0. This condition holds with probability $1/256$.\n\\end{enumerate}\n\n\\ifext\nAs an example, let us assume a 2048-bit RSA ciphertext with $\\ell_k = 5$, and consider the fraction $u = 7, t = 8$.  We have\n\\begin{align*}\nP(t|m_0)= 1/t &= 1/8 \\\\\nP( m_1[1,2] = 00||02 \\, \\big\\vert \\, t|m_0) &= 0.71\\\\\nP(\\forall i \\in [3, \\ell_m-6] \\, m_1[i] \\neq 0) = (1 - 1/256)^{248} &= 0.37\\\\\nP(m_1[\\ell_m-5] = 0) &= 1/256\n\\end{align*}\n\\fi\n\nUsing the above formulas for $u/t = 7/8$,\nthe overall probability of success is $P = 1/8 \\cdot 0.71 \\cdot 0.37 \\cdot 1/256 = 1 / 7,774$; thus the attacker expects to find an \\sslconform ciphertext after testing 7,774 randomly chosen \\tlsconform ciphertexts.  The attacker can decrease the number of \\tlsconform ciphertexts needed by multiplying each candidate ciphertext by several fractions.\n\nNote that testing random $s$ values until $c_1 = c_0 \\cdot s^e \\bmod N$ is \\sslconform yields a success probability of\n$P_{rnd} \\approx (1/256)^3 * (255/256)^{249} \\approx 2^{-25}$.\n\n\\subsection{Optimizing the chosen set of fractions}\n\\label{sec:fraction-optimization}\n%Section~\\ref{sec:adapted-bb-compact} already introduced the optimization that allows us to narrow the key space for a single query by observing that, for example, using the fraction $u/t=8/7$ results in the new candidate message $m_1 = m_0 / t \\cdot u$ is divisible by $u=8$, and the last three bits of $m_1$ (and thus \\texttt{master\\_key}) are zero.\n\nIn order to deduce the validity of a single ciphertext, the attacker would have to perform a non-trivial brute-force search over all 5 byte \\texttt{master\\_key} values. This translates into $2^{40}$ encryption operations.\n\nThe search space can be reduced by an additional optimization, relying on the fractional multipliers used in the first step.\nIf the attacker uses $u/t=8/7$ to compute a new \\sslconform candidate, and $m_0$ is indeed divisible by $t=7$,\nthen the new candidate message $m_1 = m_0 / t \\cdot u$ is divisible by $u=8$, and the last three bits of $m_1$ (and thus \\texttt{$mk_{secret}$}) are zero. \nThis allows reducing the searched \\texttt{master\\_key} space by selecting specific fractions.\n\nMore generally, for an integer $u$, the largest power of 2 by which $u$ is\ndivisible is denoted by $v_2(u)$, and multiplying by a fraction $u/t$ reduces\nthe search space by a factor of $v_2(u)$.\nWith this observation, the trade-off between the 3 metrics: the required number of intercepted ciphertexts, the required number of queries, and the required number of encryption attempts, becomes non-trivial to analyze.\n\nTherefore, we have resorted to using simulations when evaluating the performance metrics for sets of fractions.\nThe probability that multiplying a ciphertext by any fraction out of a given set of fractions results in an \\sslconform message is difficult to compute, since the events are in fact inter-dependent: If $m \\cdot 16/15$ is conforming, then $m$ is divisible by $5$, greatly increasing the probability that $m \\cdot 4/5$ is also conforming.\nHowever, it is easy to perform a Monte Carlo simulation, where we randomly generate ciphertexts, and measure the probability that any fraction out of a given set produces a conforming message.\nThe expected required number of intercepted ciphertexts is the inverse of that probability.\n\nFormally, if we denote the set of fractions as $F$, and the event that a message $m$ is conforming as $C(m)$, we perform a Monte Carlo estimation of the probability\n$ P_F = P(\\exists f \\in F: C(m \\cdot f)) $, and the expected number of required intercepted ciphertexts equals $1/{P_F}$.\nThe required number of oracle queries is simply $ 1/P_F \\cdot |F| $.\nAccordingly, the required number of server connections is $ 2 \\cdot 1/P_F \\cdot |F| $, since each oracle query requires two server connections.\nAnd as for the required number of encryption attempts, if we denote this number when querying with a given fraction $f = u/t$ as $E_f$, then\n$E_f = E_{u/t} = 2^{40-v_2(u)}$.\nWe further define the required encryption attempts when testing a ciphertext\nwith a given set of fraction $F$ as\n$E_F = \\sum_{f \\in F} E_f$.\nThen the required number of encryption attempts in Phase 1 for a given set of fractions is $(1/{P_F}) \\cdot E_F$.\n\nWe can now give precise figures for the expected number of required intercepted ciphertexts, connections to the targeted server, and encryption attempts.\nThe results presented in Table~\\ref{tab:reasonable_parameters} were obtained using the above approach with one billion random ciphertexts per fraction set $F$.\n\n\\subsection{Rotation and multiplier speedups}\n\\label{sec:rotation-details}\n\nFor a randomly chosen $s$, the probability that the two most significant bytes are $\\hexb{00}{02}$ is $2^{-16}$; for a 2028-bit modulus $N$ the probability that the next $\\ell_m - \\ell_k - 3$ bytes of $m_2$ are all nonzero is about 0.37 as in the previous section, and the probability that the $\\ell_k+1$ least significant delimiter byte is $\\hex{00}$ is 1/256.  Thus a randomly chosen $s$ will work with probability $2^{-25.4}$ and the attacker expects to try $2^{25.4}$ values for $s$ before succeeding.\n\nHowever, since the attacker has already learned $\\ell_k+3$ most significant bytes of $m_1 \\cdot R^{-1} \\bmod N$,\nfor $\\ell_k \\ge 4$ and $s < 2^{30}$ they do not need to query the oracle to learn if the two most significant bytes are \\sslconform; they can compute this themselves from their knowledge of $\\tilde{m_1} \\cdot R^{-1}$.  They iterate through values of $s$, test that the top two bytes of $\\tilde{m_1} \\cdot R^{-1} \\bmod N$ are \\hexb{00}{02}, and only query the oracle for $s$ values that satisfy this test. Therefore, for a 2048-bit modulus they expect to test $2^{16}$ values offline per oracle query.  The probability that a query is conformant is then $P = (1/256) * (255/256)^{249} \\approx 1/678$, so they expect to perform 678 oracle queries before finding a fully \\sslconform ciphertext $c_2 = (s \\cdot R^{-1})^e c_1 \\bmod N$.\n\nWe can speed up the brute force testing of $2^{16}$ values of $s$ using algebraic lattices.  We are searching for values of $s$ satisfying $\\tilde{m_1} R^{-1} s < 3 B \\bmod N$, or given an offset $s_0$ we would like to find solutions $x$ and $z$ to the equation $\\tilde{m_1} R^{-1} (s_0 + x) = 2 B + z \\bmod N$ where $|x| < 2^{16}$ and $|z| < B$.  Let $X =  2^{15}$.  We can construct the lattice basis\n\\[\nL = \n\\begin{bmatrix}\n-B & X\\tilde{m_1} R^{-1} & \\tilde{m_1} R^{-1} s_0 + B \\\\\n0 & XN & 0 \\\\\n0 & 0 & N\n\\end{bmatrix}\n\\]\nWe then run the LLL algorithm~\\cite{lll} on $L$ to obtain a reduced lattice basis $V$ containing vectors $v_1, v_2, v_3$.  We then construct the linear equations $f_1(x,z) = v_{1,1}/B \\cdot z +v_{1,2}/X \\cdot x + v_{1,3} = 0$ and $f_2(x,z) = v_{2,1}/B \\cdot z +v_{2,2}/X \\cdot x + v_{2,3} = 0$ and solve the system of equations to find a candidate integer solution $x = \\tilde{s}$.  We then test $s = \\tilde{s} + s_0$ as our candidate solution in this range.\n\n$\\det L = XZN^2$ and $\\dim L = 3$, thus we expect the vectors $v_i$ in $V$ to have length approximately $|v_i| \\approx (XZN^2)^{1/3}$.  We will succeed if $|v_i| < N$, or in other words $XZ < N$.  $N \\approx 2^{8\\ell_m}$, so we expect to find short enough vectors. This approach works well in practice and is significantly faster than iterating through $2^{16}$ possible values of $\\tilde{s}$ for each query.\n\nIn summary, given an \\sslconform ciphertext $c_1 = m_1^e \\bmod N$, we can efficiently generate an \\sslconform ciphertext $c_2 = m_2^e \\bmod N$ where $m_2 = s \\cdot m_1 \\cdot R^{-1} \\bmod N$ and we know several most significant bytes of $m_2$, using only a few hundred oracle queries in expectation.  We can iterate this process as many times as we like to continue generating \\sslconform ciphertexts $c_i$ for which we know increasing numbers of most significant bytes, and which have a known multiplicative relationship to our original message $c_0$. \n\n\\subsection{Rotations in the general DROWN attack}\n\\label{sec:general-rotations}\nAfter the first phase, we have learned an \\sslconform ciphertext $c_1$, and we wish to shift known plaintext bytes from least to most significant bits.\nSince we learn the least significant 6 bytes of plaintext of $m_1$ from a successful oracle $\\OracleSSLexp$ query, we could use a shift of $2^{-48}$ to transfer 48 bits of known plaintext to the most significant bits of a new ciphertext.  However, we perform a slight optimization here, to reduce the number of encryption attempts.  We instead use a shift of $2^{-40}$, so that the least significant byte of $m_1 \\cdot 2^{-40}$ and $\\tilde{m_1} \\cdot 2^{-40}$ will be known.  This means that we can compute the least significant byte of $m_1 \\cdot 2^{-40} \\cdot s \\bmod N$, so oracle queries now only require $2^{32}$ encryption attempts each. This brings the total expected number of encryption attempts for each shift to $2^{32} * 678 \\approx 2^{41}$.\n\nWe perform two such plaintext shifts in order to obtain an \\sslconform message, $m_3$ that resides in a narrow interval of length at most $2^{8\\ell-66}$. We can then obtain a multiplier $s_3$ such that $m_3 \\cdot s_3$ is also \\sslconform.\nSince $m_3$ lies in an interval of length at most $2^{8\\ell-66}$, with high probability for any $s_3 < 2^{30}$, $m_3 \\cdot s_3$ lies in an interval of length  at most $2^{8\\ell_m-36} < B$, so we know the two most significant bytes of $m_3 \\cdot s_3$.\nFurthermore, we know the value of the 6 least significant bytes after multiplication.\nWe therefore test possible values of $s_3$, and for values such that\n$m_3 \\cdot s_3 \\in [2B, 3B)$, and $(m_3 \\cdot s_3) [\\ell_m - 5] = 0$,\nwe query the oracle with $c_3 \\cdot s_3^e \\bmod N$.\nThe only condition for PKCS conformance which we haven't verified before querying the oracle is the requirement of non-zero padding, which holds with probability 0.37.\n\nIn summary, after roughly $1 / 0.37 = 2.72$ queries we expect a positive response from the oracle.\nSince we know the value of the 6 least significant bytes after multiplication,\nthis phase does not require performing an exhaustive search. If the message is \\sslconform after multiplication, we know the symmetric key, and can test whether it correctly decrypts the \\texttt{ServerVerify} message.\n\n\\subsection{Adapted Bleichenbacher iteration}\n\\label{sec:general-bleichenbacher}\nAfter we have bootstrapped the attack using rotations, the original algorithm proposed by Bleichenbacher can be applied with minimal modifications.\n\nThe original step obtains a message that starts with the required \\hexb{00}{02} bytes once in roughly every two queries on average, and requires the number of queries to be roughly $16 \\ell_m$.\nSince we know the value of the 6 least significant bytes after multiplying by any integer, we can only query the oracle for multipliers that result in a zero 6th least significant byte, and again an exhaustive search over keys is not required.\nHowever, we cannot ensure that the padding is non-zero when querying, which again holds with probability 0.37.\nTherefore, for a 2048-bit modulus, the overall expected number of queries for this phase is roughly $2048 * 2 / 0.37 = 11,070$.\n\n\\ifext\n\\subsection{General DROWN attack performance}\n\\label{sec:general-performance}\n\nFor a given set of fractions, $F$,\nthe required number of recorded client connections $A$ is a random variable distributed geometrically with a success probability $P = P_F$.\nFor typical fraction sets, $1/13,000 < P_F < 1/600$.\nThe required number of Bleichenbacher queries against the target server during the first step of the attack is a random variable, $B$, such that $B = |F| \\cdot A$.\nAs each query consists of two separate connections to the target server, the required number of connections is always  twice the number of queries.\nAnd last, the required keys to be tested overall is another random variable $C = k_F \\cdot B; k_F \\approx 2^{40}$.\n\nSumming the figures from the different phases for a 2048-bit RSA modulus, the attack requires in expectation $13,838 + 1,393 + 1,393 + 6 + 22,140 = 38,770$ connections to the target server, when optimizing for the number of queries in phase 1.  Each oracle query requires two connections to the server.\n\nRe-calculating the numbers for a 1024 bit modulus, the primary element that needs to change is $P_1 = P(\\forall i \\in [3, \\ell_m-6]: m_i \\neq 0) = (1 - 1/256)^{120} = 0.62$, which appears in phases 1, 2, 3 and 5. For phase 5, the number of queries is now in expectation $1024 * 2 / 0.62 = 3,303$. The total expected number of server connections is therefore $8,258 + 826 + 826 + 6 + 6,606 = 16,522$, again when optimizing for the number of queries in phase 1.\n\nSimilarly, re-calculating the numbers for a 4096 bit modulus, $P_1 = (1 - 1/256)^{504} = 0.14$, and the number of queries in phase 5 is now roughly $4096 * 2 / 0.14 = 58,514$. The algorithm for phase 5 can be further optimized if that is the case of interest; we omit these optimizations for space reasons. Again, summing up yields $36,571 + 3,657 + 3,657 + 29 + 117,028 = 160,942$ required connections to the server.\n\\fi\n\n\\balance\n\n\\subsection{Special DROWN MITM performance}\n\\label{sec:special-performance}\n\nFor the first step, the probability that the three padding bytes are correct remains unchanged. The probability that all the intermediate padding bytes are non-zero is now slightly higher, $P_1 = (1 - 1/256)^{229} = 0.41$, yielding an overall maximal success probability $P = 0.1 \\cdot 0.41 \\cdot \\frac{1}{256} = 1/6,244$ per oracle query. Since the attacker now only needs to connect to the server once per oracle query, the expected number of connections in this step is the same, $6,243$. Phase~1 now yields a message with 3 known padding bytes and 24 known plaintext bytes.\n\nFor the remaining rotation steps, each rotation requires an expected 630 oracle queries.  The attacker could now complete the original Bleichenbacher attack by performing 11,000 sequential queries in the final phase.  However, with this more powerful oracle it is more efficient to apply a rotation 10 more times to recover the remaining plaintext bits. The number of queries required in this phase is now $10\\cdot 256/0.41\\approx 6,300$, and the queries for each of the 10 steps can be executed in parallel.\n\n\\paragraph{Using multiple queries per fraction.}\nFor the $\\OracleSSLclear$ oracle, the attacker can increase their chances of\nsuccess by querying the server multiple times per\nciphertext and fraction, using different cipher suites with different key lengths. They can negotiate DES and hope\nthe 9th least significant byte is zero, then negotiate 128-bit RC4\nand hope the 17th least significant byte is zero, then negotiate\n3DES and hope the 25th least significant is zero. All three queries also require\nthe intermediate padding bytes to be non-zero. This technique\ntriples the success probability for a given pair of (ciphertext, fraction),\nat a cost of triple the queries. Its primary benefit is that fractions with smaller\ndenominators (and thus higher probabilities of success) are now even more likely\nto succeed.\n\nFor a random ciphertext, when choosing 70 fractions, the probability of the\nfirst zero delimiter byte being in one of these three positions is 0.01.\n% Nimrod: literally 0.01004702047755441\nHence, the attacker can use only 100 recorded ciphertexts, and expect to use\n$100 * 70 * 3 = 21,000$ oracle queries. For the \\tOracleSSLclear, each\nquery requires one SSLv2 connection to the server.\nAfter obtaining the first positive response from the oracle, the attacker\nproceeds to phase~2 using 3DES.\n\n\\subsection{Special DROWN with combined oracles}\n\\label{sec:special-both}\n\nUsing the Leaky Export oracle, the probability that a fraction $u/t$ will result\nin a positive response is $P = P_0 * P_3$, where the formula for\ncomputing $P_0 = P((m \\cdot u/t)[1,2] = 00||02)$ is provided in \\S\\ref{sec:fraction-probability},\nand $P_3$ is, for a 2048-bit modulus:\n\\begin{equation}\n\\begin{aligned}\nP_3 = P(\n\\hex{00} \\text{ } \\not \\in \\text{ } \\{m_3, \\ldots,m_{10}\\} \\wedge \\\\\n\\hex{00} \\text{ } \\in \\text{ } \\{m_{11}, \\ldots,m_{\\ell}\\}) \\\\\n = (1 - 1/256)^{8} * (1 - (1 - 1/256)^{246}) = 0.60\n\\end{aligned}\n\\end{equation}\n\n%Since $P_0$ is also non-negligible for small fractions, the overall probability of\n%obtaining a positive response is now also non-negligible.\n\n\\paragraph{Phase 1.}\nOur goal for this phase is to obtain a divisor $t$ as large as possible,\nsuch that $t|m$. We generate a list of\nfractions, sorted in descending order of the probability of\nresulting in a positive response from $\\OracleSSLleaky$. For a given ciphertext $c$, we then query with\nthe 50 fractions in the list with the highest probability,\nuntil we obtain a first positive response for a fraction $u_0/t_0$.\nWe can now deduce that $t_0|m$.\nWe then generate a list of fractions $u/t$ where $t$ is a multiple of $t_0$, sort them again\nby success probability, and again query with the 50 most probable fractions, until a positive answer is obtained,\nor the list is exhausted.\nIf a positive answer is obtained, we iteratively re-apply this process,\nuntil the list is exhausted, resulting in a final fraction $u^*/t^*$.\n\n\\paragraph{Phase 2.}\nWe then query with all fractions\ndenominated by $t^*$, and hope the ciphertext decrypts to a plaintext of\none of seven possible lengths: $\\{2, 3, 4, 5, 8, 16, 24\\}$.\nAssuming that this is the case, we learn at least three least significant bytes,\nwhich allows us to use the shifting technique in order to continue the attack.\nDetecting plaintext lengths 8, 16 and 24 can be accomplished using three Extra Clear oracle\nqueries, employing DES, 128-bit RC4 and 3DES, respectively, as the chosen cipher suite.\nDetecting plaintext lengths 2, 3, 4 and 5 can be accomplishing by using a single\nLeaky Export oracle query, which requires at most $2^{41}$ offline computation.\nIn fact, the optimization over the key search space described in\nSection~\\ref{sec:trimmers} is applicable here and can slightly reduce the required computation.\nTherefore, by initiating four SSLv2 connections and performing at most $2^{41}$ offline\nwork, the attacker can test for ciphertexts which decrypt to one of these seven lengths.\n%\\looseness=-1\n\nIn practice, choosing 50 fractions per iteration as described above\nresults in a success probability of 0.066 for a single ciphertext.\nHence, the expected number of required ciphertexts is merely $1/0.066 = 15$.\nThe expected number of fractions per ciphertext for phase 1 is 60, as in most cases phase 1\nconsists of just a few successful iterations.\nSince each fraction requires a single query to $\\OracleSSLleaky$,\nthe overall number of queries for this stage is\n$15 * 60 = 900$, and the required offline computation is at most\n$900 * 2^{41} \\approx 2^{51}$, which is similar to general DROWN\\@.\nFor a 2048-bit RSA modulus, the expected number of queries for phase 2 is 16.\nEach query consists of three queries to $\\OracleSSLclear$ and one query\nto $\\OracleSSLleaky$, which requires at most $2^{41}$ computation.\nTherefore in expectancy the attacker has to perform $2^{45}$ offline computation for phase 2.\n", "meta": {"hexsha": "8198817705bf457237ae33cf1cd62903af916654", "size": 20443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/drown/paper/adapting-bleichenbacher.tex", "max_stars_repo_name": "dadrian/dissertation", "max_stars_repo_head_hexsha": "5607114fb4340c5b6e944c73ed6019006d3ebec9", "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/drown/paper/adapting-bleichenbacher.tex", "max_issues_repo_name": "dadrian/dissertation", "max_issues_repo_head_hexsha": "5607114fb4340c5b6e944c73ed6019006d3ebec9", "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/drown/paper/adapting-bleichenbacher.tex", "max_forks_repo_name": "dadrian/dissertation", "max_forks_repo_head_hexsha": "5607114fb4340c5b6e944c73ed6019006d3ebec9", "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.772, "max_line_length": 753, "alphanum_fraction": 0.7437753754, "num_tokens": 5795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6900188969213841}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\subsection{Graphs and their corresponding Matroid Theory}\nIn this section we introduce the graph theoretic definitions and results needed to understand the algorithms and subsequent optimisation in later sections. These definitions and results come mainly from Jungnickel's\\cite{jungnickel} text. We will also see how these properties of graphs naturally align with the properties of matroids and in particular to bases of matroids which are the cornerstone of the results in the later sections.\n\n\\begin{defn}[Connected]\nA graph is connected when there is a path between each pair of vertices.\n\\end{defn}\n \n\\begin{defn}[Acyclic]\nAn acyclic graph is a graph which contains no closed walks.\n\\end{defn}\n\n\\begin{defn}[Walk]\nIf there are vertices $v_{i-1}v_i$ for $i = 1, ..., n$ the sequence is called a walk. If $v_0 = v_n$ this sequence is called a closed walk.\n\\end{defn} \n\n\\begin{defn}[Tree]\nA connected graph containing no circuits. In other words, acyclic graphs.\\\\\n\\noindent A forest is a disconnected graph containing no circuits\\\\\n\\end{defn}\n\n\\noindent We know from \\textit{theorem 1.7}. If we let $E$ be the edge set of our graph $G.$ And we define $\\mathcal{I}$ as the subsets of $E$ not containing all of the edges of any cycle in $G$ we have $M(G),$ the cycle matroid of G. We know that this is a matroid, and it is easy to see that in this case the elements of $\\mathcal{I}$ correspond exactly to the trees of $G.$\n\n \n\\begin{defn}[Spanning Tree]\nA spanning tree $T$ of an graph $G$ is a subgraph that is a \\textit{tree} which includes all of the vertices of $G.$\\\\\n\\noindent A disconnected graph cannot contain a spanning tree as we cannot find a walk which brings us to all of the disconnected vertices.\n\\end{defn}\n\n\\begin{prop}\n A theorem of Cayley(1889) states that the number of distinct labelled trees which can be drawn using $n$ labelled points is $ n^{n-2}$.\n \\end{prop}\n\n\\begin{cor}\nThe number of distinct labelled spanning trees which can be drawn using $n$ labelled points is $n^2.$ \n\\end{cor}\n\n\\pagebreak\n\\begin{lem}\\cite{jungnickel}\nAny acyclic graph on $n$ vertices has at most $n-1$ edges.\n\\end{lem}\n\\noindent\\Proof Let G be an acyclic graph with n vertices.\\\\\n\\noindent If n = 1 then we have no edges hence nothing to prove.\\\\\n\\noindent Assume $n>1,$ let $e$ be an edge in $G$ connecting two vertices $ab$ in the vertex set of $G.$\\\\\n\\noindent Let $H = G \\setminus \\{e\\}, H$ has one more connected component than $G.$ $H$ has two maximal acyclic connected components, and thus can be decomposed into acyclic connected graphs $H_1, H_2, ..., H_k$ where $k \\geq 2.$\\\\\n\\noindent By induction, we can assume each graph $H_i$ contains at most $n_i - 1$ edges where $n_i$ is the number of vertices of $H_i.$\\\\\n\\noindent Then $G$ has at most $n-1$ edges.\\\\\n\\noindent $(n_1 - 1) + ... + (n_k - 1) + 1 = (n_1 + ... + n_k) - (k - 1) \\leq n - 1$ edges.\n\\\\ \\qed\n\n\\begin{defn}[Bridge]\nA bridge(or cut edge) is an edge of a graph whose deletion increases the number of connected components. Equivalently, an edge is a bridge if and only if it is not contained in any cycle.\n\\end{defn}\n\n\\noindent The above definition is mainly useful for us in proving the next lemma, which comes from Jungnickel's text and will help us visualise the characteristics of a spanning tree of a graph. In particular condition $(1)$ and $(2)$, will allow us to see that the spanning trees of a graph directly correspond to the bases of a matroid.\n\n \\begin{lem}\\cite{jungnickel}\n Let $G$ be a graph. Then the following conditions are equivalent:\\\\\n 1) $G$ is a tree.\\\\\n 2) $G$ does not contain any cycles, but adding any further edge yields a cycle.\\\\\n 3) Any two vertices of $G$ are connected by a unique path.\\\\\n 4) $G$ is connected, and any edge of $G$ is a bridge.\n \\end{lem}\n \n \\noindent\\Proof $(1) \\Longrightarrow (2)$\\\\\n \\noindent Suppose that $G$ is a tree,then $G$ is a connected graph with no circuits. Let $e$ be a new edge in G with $e = g_ig_k$ where $g_i,g_k$ are in the vertex set of $G.$ Then as $G \\cup \\{e\\}$ must be connected, there exists a walk between any pair of vertices of $G$. So there is a walk $K$ from $g_j \\rightarrow g_k$ and there is also a walk $L$ from $g_k \\rightarrow g_j$ where $K$ does not traverse $e$ and $L$ does traverse $e$ and so we have a cycle.\\\\\n\n\\noindent\\Proof $(2) \\Longrightarrow (3)$\\\\\n\\noindent Let $u,v$ be vertices of $G.$ If there was no path joining $uv$ in $G$ then $e = uv$ does not create a cycle in $G.$ Thus $G$ must be connected.\\\\\n\\noindent Suppose $G$ contained two different paths $W_1, W_2$ from $u$ to $v.$\\\\\n\\noindent Then $ u \\longrightarrow v \\longrightarrow u$ would be a closed walk in $G. \\\\ \\implies G$ contains a cycle. Which is a contradiction.\\\\\n\n\\noindent\\Proof $(3) \\Longrightarrow (4)$\\\\\n\\noindent $G$ is connected by hypothesis. Let $e = uv$ be an edge in $G.$\\\\\n\\noindent Suppose $e$ is not a bridge, then $G \\setminus \\{e\\}$ is still connected. But then we have two distinct paths from $u$ to $v$ in $G.$\\\\\n\n\\noindent\\Proof $(4) \\Longrightarrow (1)$\\\\\n\\noindent G is connected by hypothesis.\\\\\n\\noindent Suppose $G$ contains a cycle $K.$ Then any edge of $K$ could be ommited from $G,$ and the resulting graph would still be connected. In other words, no edge of $K$ would be a bridge, a contradiction.\\\\\n\\qed\n\n\\noindent The vertices of a graph/network can be labelled and referred to as nodes. Information may then be recorded in them along with a cost, penalty or probability associated with each edge. For example, the problem of joining all nodes in a graph by the minimum length using our respective metric to a tree known as a \\textit{minimum spanning tree}.\n\n\\noindent Weights can be assigned using a process as detailed below. We will later redefine this process in a more suitable way to take advantage of matroid properties in order to determine the minimum spanning trees in graphs.\n\\begin{defn}\nLet $(G,\\omega)$ be a network. For any subset $T$ of the edge set of $G, \\omega$ is called the weight of $T.$\\\\\n\\begin{equation}\n\\omega (T) = \\displaystyle\\sum_{e \\in T} \\omega (T)\n\\end{equation}\n\\end{defn}\n\n\\begin{defn}[Minimal Spanning Tree]\nA spanning tree is a \\textit{minimal} spanning tree if its weight is minimal of all the weights of spanning trees.\n\\noindent A forest can be considered by finding a minimal spanning tree for each connected component of $G.$\n\\end{defn}\n\n\\begin{rem}\nIf the weight $\\omega$ is constant, any spanning tree is minimal.\\\\\n\\noindent In this case, determining a minimal spanning tree could be done using a breadth-first search. Which is a similar procedure to the described depth-first section in \\textit{appendix,algorithm 6}.\n\\end{rem}\n\n \\end{document}", "meta": {"hexsha": "fa46d6cad23debf0873eb62738ba488b519a8dea", "size": 6726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/g1.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/g1.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/g1.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": 65.3009708738, "max_line_length": 465, "alphanum_fraction": 0.72970562, "num_tokens": 1909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749421, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.6900188968334654}}
{"text": "\\section{It\\^o's Formulas}\n\n%\\begin{frame}\n%  \\frametitle{Differentiation and Integration of Stochastic Processes}\n%\n%  \\begin{itemize}\n%   \\item Brownian motion is a continuous time stochastic process that is nowhere differentiable.\\\\\n%  \\item  How do we make sense of $\\frac{dB}{dt}$?\\\\\n%\\end{itemize}\n%\n%\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Riemann-Stieltjes Integration of Stochastic Processes}\n  \\begin{itemize}\n  \\item Riemann-Stieltjes Integral \\\\\n    $$\\int_{a}^{b} f(x) d\\alpha(x)=\\lim_{n\\to\\infty}\\sum_{i=1}^{n} f(x_i) (\\alpha(x_i)-\\alpha(x_{i-1}))$$\\\\\n  \\item  Stochastic Integral \\\\\n    $$\\int_{a}^{b} f(t) dB=\\lim_{n\\to\\infty}\\sum_{i=1}^{n} f(t_{i-1}) (B(t_i)-B(t_{i-1}))$$\\\\\n  %\\item  Form the Taylor expansion on $f(B(b))-f(B(a))$\\\\\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Left and Right Stochastic Sums}\n  \\begin{itemize}\n  \\item Left Side Stochastic sum $$L=\\lim_{n\\to\\infty}\\sum_{i=1}^{n} f(t_{i-1}) (B(t_i)-B(t_{i-1}))$$\\\\\n  \\item Right Side Stochastic sum $$R=\\lim_{n\\to\\infty}\\sum_{i=1}^{n} f(t_i) (B(t_i)-B(t_{i-1}))$$\\\\\n\n  \\end{itemize}\n\\end{frame}\n  \n\\begin{frame}\n  \\frametitle{Left and Right Riemann-Stieltjes Sums}\n  \\begin{itemize}\n  \\item Considering $$\\int_{a}^{b}{B(t)d(B(t))}$$\\\\\n  \\item The left sided limit \\\\\n    $$L=\\frac{1}{2}B^2(t)-\\frac{t}{2}$$\\\\\n  \\item The right sided limit \\\\\n    $$R=\\frac{1}{2}B^2(t)+\\frac{t}{2}$$\\\\\n  \\end{itemize}  \n\\end{frame}\n  \n\\begin{frame}\n  \\frametitle{It\\^{o}'s Formula (First Formulation)}\n  \\begin{itemize}\n  \\item $\\Delta B^2 \\to \\Delta t$\\\\\n  \\item  The Taylor expansion is\n  \\begin{eqnarray*}\n    f(B(t_i))-f(B(t_{i-1}))&=&f'(B(t_{i-1}))(B(t_i)-B(t_{i-1}))+\\\\\n    & &\\frac{1}{2}f''(B(t_{i-1}))(B(t_i)-B(t_{i-1}))^2+\\\\\n    %& &\\frac{1}{3}f'''(B(t_{i-1}))(B(t_i)-B(t_{i-1}))^3+\\\\\n    & &\\mathrm{Higher Order Terms}\\\\\n  \\end{eqnarray*}\n  %f(B(b))-f(B(a))&=&\\sum_{i=1}^{n}(f'(B(t_{i-1}))(B(t_i)-B(t_{i-1}))+\\\\\n  %& &\\frac{1}{2}f''(B(t_{i-1}))(B(t_i)-B(t_{i-1}))^2+\\\\\n  %& &\\frac{1}{3}f'''(B(t_{i-1}))(B(t_i)-B(t_{i-1}))^3+\\\\\n  %& &\\mathrm{Higher Order Terms})\\\\\n  \\item Taking the sum of the telescoping series $$f(B(b))-f(B(a))=\\sum_{i=1}^{n}(f(B(t_i))-f(B(t_{i-1})))$$\\\\\n  \\item It\\^o's Formula (first version) $$f(B(b))-f(B(a))=\\int_{a}^{b}{\\frac{\\partial f}{\\partial B} dB}+\\int_{a}^{b}{\\frac{1}{2} \\frac{\\partial^2 f}{\\partial B^2} dt} $$\\\\\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{It\\^o's Formula (Second and Third Formulation)}\n  \\begin{itemize}\n\n  \\item  It\\^o's Formula (second version) $$f(b,B(b))-f(a,B(a))=\\int_{a}^{b}{\\frac{\\partial f}{\\partial B} dB}+\\int_{a}^{b}{(\\frac{\\partial f}{\\partial s}+\\frac{1}{2}\\frac{\\partial ^2 f}{\\partial B^2}) ds}$$\\\\\n  \\item  It\\^o's Formula (third version): The Stochastic Chain Rule $$d\\theta=\\frac{\\partial\\theta}{\\partial t}dt+\\frac{\\partial\\theta}{\\partial x}f dB+\\frac{\\partial\\theta}{\\partial x}g dt+\\frac{1}{2}\\frac{\\partial^2\\theta}{\\partial x^2}f^2dt$$\\\\\n  where $\\theta$ is a function of t and x\\\\\n  and f and g are functions of t and B\\\\\n  and x satisfies $dx=fdt+gdB$\n\n  \\end{itemize}\n  \n\\end{frame}\n\n%\\begin{frame}\n%  \\frametitle{Integration by Parts}\n%  \\begin{itemize}\n%  \\item $$\\int_{a}^{b}{f(t)dB}=f(t)B(t)|_{a}^{b}-\\int_{a}^{b}{B(t)df}$$\n%  \\end{itemize}\n\n%\\end{frame}\n\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"Presentation1\"\n%%% End:\n\n%\\\n", "meta": {"hexsha": "74e3b8d0b32b00a9777f1efa7baa167ae1512794", "size": 3332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Presentations/Midterm/Ito.tex", "max_stars_repo_name": "SUNY-SDE-2015/REU15", "max_stars_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Presentations/Midterm/Ito.tex", "max_issues_repo_name": "SUNY-SDE-2015/REU15", "max_issues_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-06-04T17:55:32.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-09T15:38:17.000Z", "max_forks_repo_path": "Presentations/Midterm/Ito.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": 34.3505154639, "max_line_length": 247, "alphanum_fraction": 0.5924369748, "num_tokens": 1399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.6900188959786087}}
{"text": "%\n% 82\n%\n\\chapter{The Fundamental Properties of Analytic Functions;\nTaylor's, Laurent's and Liouville's Theorems}\n\n\\Section{5}{1}{Property of the elementary functions.}\n\nThe reader will be already familiar with the term elementary function,\nas used (in text-books on Algebra, Trigonometry, and the Differential\nCalculus) to denote certain analytical expressions* depending on a\nvariable z, the symbols involved therein being those of elementary\nalgebra together with exponentials, logarithms and the trigonometrical\nfunctions; examples of such\n\nexpressions are\n\n1  §\n\nZ-, e~, iogz, arcsm '-.\n\nSuch combinations of the elementary functions of analysis have in\ncommon a remarkable property, which will now be investigated.\n\nTake as an example the function e .\n\nWrite e'=f z).\n\nThen, if 2 be a fixed point and if z' be any other point, we have\n\nf z')-f z) \\ e~ -e' \\, e' '- ' - 1 z -z z - z z - z\n\nf, z' - z (z -z)-\n\nand since the last series in brackets is uniformly convergent for all\nvalues of it follows \\hardsectionref{3}{7}) that, as z'->z, the quotient\n\nz - z tends to the limit e, uniformly for all values of arg z - z).\nThis shews that tlie limit of\n\nf z:)-f z)\n\nz - z\n\nis in this case independent of the path by which the point z tends\ntowards coincidence witJt z.\n\nIt wall be found that this property is shared by many of the\nwell-known elementary functions; namely, that iif(z) be one of these\nfunctions and h. be\n\n* The reader will observe that this is uot the sense in which the term\nfunction is defined \\hardsectionref{3}{1}) in this work. Thus e.g. .r - hj and | z \\\nare functions of z (-x + iy) in the sense of \\hardsectionref{3}{1}, but are not\nelementary functions of the type under consideration.\n\n%\n% 83\n%\nany complex\nnumber, the limiting value of\n\nexists and is independent of the mode in luhich h fends to zero.\n\nThe reader will, however, easily prove that, ii f(z)=x -iy, where z =\nx- iy, then lim' - - - - IXJ- is not independent of the mode in which\nA- >0.\n\n\\Subsection{5}{1}{1}{Occasional failure of the jwoperty.}\n\nFor each of the elementary functions, however, there will be certain\npoints z at which this property will cease to hold good. Thus it does\nnot hold for the function l/( - a) at the point z = a, since\n\n i Qh\\ z - a+h z-a\n\ndoes not exist when z = a. Similarly it does not hold for the\nfunctions log z\n\nand z at the point z = Q.\n\nThese exceptional points are called singular points or singulaHties of\nthe function f(z) under consideration; at other points f(z) is said\nto be analytic.\n\nThe property does not hold good at any point for the function \\ z.\n\n\\Subsection{5}{1}{2}{Cauchy's* definition of an analytic function of a complex variable.}\n\nThe property considered in § b\\ \\ will be taken as the basis of the\ndefinition of an analytic function, which may be stated as follows.\n\nLet a two-dimensional region in the -plane be given; and let w be a\nfunction of z defined uniquely at all points of the region. Let z, z-\nhz be values of the variable z at two points, and u, u + Bu the\ncorresponding values\n\nof u. Then, if, at any point z within the area, - tends to a limit\nwhen 8x->0,\n\nBy-*0, independently (where 8z = 8x + iBy), u is said to be a function\nof z which is monogenic or analytic j\" at the point. If the function\nis analytic and one-valued at all points of the region, we say that\nthe function is analytic throughout the region.\n\nWe shall frequently use the word ' function ' alone to denote an\nanalytic function, as the functions studied in this work will be\nalmost exclusively analytic functions.\n\n* See the memoir cited in § 5 \"2.\n\nt The words ' regular ' and ' holomorphic ' are sometimes used. A\ndistinctiou has been made by Borel between ' monogenic ' and '\nanalytic ' functions in the case of functions with an infinite number\nof singularities. See \\hardsubsectionref{5}{5}{1}.\n\nX See \\hardsectionref{5}{2} cor. 2, footnote.\n\n6-2\n\n%\n% 84\n%\n\nIn the foregoing definition, the function u has been defined only\nwithin a certain region in the -plane. As will be seen subsequently,\nhowever, the function u can generally be defined for other values of 2\nnot included in this region; and (as in the case of the elementary\nfunctions already discussed) may have singularities, for which the\nfundamental property no longer holds, at certain points outside the\nlimits of the region.\n\nWe shall now state the definition of analytic functionality in a more\narithmetical form.\n\nLet f(z) be analytic at z, and let e be an arbitrary positive number;\nthen we can find numbers I and h, h depending on e) such that\n\nz -z I\n\nwhenever \\ z' - z\\ < h.\n\nVi f(z) is analytic at all points of a region, I obviously depends on\nz; we consequently write 1 = f z).\n\nHence /(/) = f(z) + - z) f(z) + v z'- z\\\n\nwhere v is a function of z and z such that ! v < e when \\ z -z\\ < t>.\n\nExample 1. Find the points at which the following functions are not\nanalytic :\n\nz - \\ (i) 2 . (ii) cosec2 (2 = /itt, w any integer). (iii) - - - - -\n(3 = 2,3).\n\n1\n\n(iv) ez (j = 0). (V) z- ) zf (2 = 0,1).\n\nExample 2. If z = x - iy, f(z) = u ii\\ where u, v, x, y are real and /\nis an analytic function, shew that\n\n8m \"bv cu cv /T - s\n\n :r =, : =-; . \\addexamplecitation{Kiemann.}\n\nex oy oy ex\n\n\\Subsection{5}{1}{3}{An application of the modified Heine-Borel theorem.}\n\nLet f(z) be analytic at all points of a continuum; and on any point z\nof\n\nthe boundar ' of the continuum let numbers f (z), S (S depending on z)\nexist\n\nsuch that\n\n\\ f(z')-f(z)- z'-z)Mz)<e,z'-z\\\n\nwhenever \\ z - z < 8 and z is a point of the continuum or its\nboundary.\n\n[We write /i iz) instead of /' z) as the differential coefficient\nmight not exist when c approaches z from outside the boundary so\nthat/j (2) is not necessarily a unique derivate.]\n\nThe above inequality is obviously satisfied for all points z of the\ncontinuum as well as boundary points.\n\nApplying the two-dimensional form of the theorem of \\hardsectionref{3}{6}, we see that\nthe region formed by the continuum and its boundary can be divided\ninto a jinite number of parts (squares with sides parallel to the axes\nand their\n\n%\n% 85\n%\n\ninteriors, or portions of such squares) such that inside or on the\nboundary of any j art there is one point z such that the inequality\n\nfiz') - f z,) - (/ - z,)f, z,) .<e\\ z'-z, \\ is satisfied by all points\nz inside or on the boundary of that part.\n\n\\Section{5}{2}{Cauchy's theorem* on the integral of a function round a contour.}\n\nA simple closed curve C in the plane of the variable z is often called\na contour; ii A, B, D he points taken in order in the\ncounter-clockwise sense along the arc of the contour, and if f(z) be a\none-valued continuousf function of z (not necessarily analytic) at all\npoints on the arc, then the integral\n\nf f z)dz or f f z)dz\n\ntaken round the contour, starting from the point A and returning to A\nagain, is called the integral of f(z) taken along the contour. Clearly\nthe value of the integral taken along the contour is unaltered if some\npoint in the contour other than A is taken as the starting-point.\n\nWe shall now prove a result due to Cauchy, which may be stated as\nfollows. If fiz) is a function of z, analytic at all points on and\ninside a contour G, then\n\nI f z)dz = 0.\n\nFor divide up the interior of C by lines parallel to the real and\nimaginary\n\naxes in the manner of \\hardsubsectionref{5}{1}{3}; then the interior\nof $C$ is divided into a number\n\nof regions whose boundaries are squares Cj, C, ... Cm and other\nregions\n\nwhose boundaries D,, D,, ... Dy are portions of sides of squares and\nparts\n\nof G; consider\n\nMr N r\n\nX f(z)dz+ S f z)dz,\n\nn = lJ(,C ) n=lJ(.D )\n\neach of the paths of integration being taken counter-clockwise; in\nthe complete sum each side of each square appears twice as a path of\nintegration, and the integrals along it are taken in opposite\ndirections and consequently cancel §; the only parts of the sum which\nsurvive are the integrals oi f z)\n\n* Memoire sur les integrates definies prises entre des limites\nimarjinaires (1825). The proof here given is that due to Goursat,\nTrans. American Math. Soc. i. (1900), p. 14.\n\nt It is sufficient for f(z) to be continuous when variations of z\nalong the arc only are considered.\n\n:J: It is not necessary that f(z) should be analytic on C (it is\nsufficient that it be continuous on and inside C), but if /( ) is not\nanalytic on C, the theorem is much harder to prove. This proof merely\nassumes that /' [z) exists at all points on and inside C. Earlier\nproofs made more extended assumptions; thus Cauchy's proof assumed the\ncontinuity of f' z). Eiemann's proof made an equivalent assumption.\nGoursat's first proof assumed that f(z) was uniformly differentiable\nthroughout C.\n\n§ See § 4G, example.\n\n/\n\nJ (On)\n\n%\n% 86\n%\n\ntaken along a number of arcs which together make up G, each arc being\n\ntaken in the same sense as in I f\\ z)dz; these integrals therefore\njust make\n\nhc)'\n\nup f z)dz.\n\nNow consider 1 f z)dz. With the notation of \\hardsubsectionref{5}{1}{2},\n\nJ (Cn)\n\nf z) dz = [ f z,) + ( - z,)f' (.-,) + z- z,) v] dz\n\n-' (C )\n\n= /( i) - V ( 01 f dz +/' (z,) I zdz+l (z- z,) vdz.\n\n\\ f? = Mc = 0, f zdz\n\nby the examples of \\hardsectionref{4}{6}, since the end points of C coincide. Now let\nIn be the side of Cn and An the area of C . Then, using \\hardsubsectionref{4}{6}{2},\n\nTODO\n\nBut\n\nl\\ \\ l n\n\n= 0,\n\nI\n\n! (C )\n\nIn like manner\n\n< e V2 . f \\ dz\\= eln \\/2 . 4,, = 4e sj'2.\n\nJ Cn\n\nI f z)dz\\ \\ i \\ \\ {z-z )vdz\\\n\nJ (Dn) I J (Dn)\n\n(Dn)\n\n  4>e (An + In Xi)\\ \\ '2,\n\nAvhere An is the area of the complete square of which Dn is part, In\nis the side of this square and \\ n is the length of the part of G\nwhich lies inside this square. Hence, if \\ be the whole length of G,\nwhile I is the side of a square which encloses all the squares Gn and\nDn,\n\nf(z)dz k S f z)dz + t \\ f z)dz\n\n|J(0 I n = \\'J(Cn) I n = \\ \\ J Dn) |\n\n( M N iV )\n\n<4eV2 An+ S An' + l tXn\\ (m = 1 m = 1 n=l )\n\n< 4e V2 . I' + X).\n\nNow e is arbitrarily small, and I, \\ and 1 f z)dz are independent of\ne.\n\nI iC)'\n\nIt therefore follows from this inequality that the only value which I\nf(z) dz can have is zero; and this is Cauchy's result.\n\n%\n% 87\n%\n\nCorollary . If there are two jjaths z AZ and Zq,BZ from 2o to Z, and\nif /(z) is a function of z analytic at all points on these curves and\nthroughout the domain enclosed by\n\nthese two paths, then / f(z) dz has the same value whether the path of\nintegration is\n\nZ(iAZ (jv ZqBZ. This follows from the fact that ZqAZBzq is a contour,\nand so the integral taken round it (which is the difference of the\nintegrals along zqAZ and ZoBZ) is zero.\n\nThus, if /(2) be an analytic function of z, the value of / f z)dz is\nto a certain extent\n\nJ AB\n\nindependent of the choice of the arc AB, and depends only on the\nterminal points A and B. It must be borne in mind that (his is only\nthe case whenf z) is an analytic function in the sense of \\hardsubsectionref{5}{1}{2}.\n\nCorollary 2. Suppose that two simple closed curves (7 and Cj are\ngiven, such that Co completely encloses Cj, as e.g. would be the case\nif Cq and Ci were confocal ellipses.\n\nSuppose moreover that/ (2) is a function which is analytic* at all\npoints on Cq and Cj and throughout the ring-shaped region contained\nbetween Cq and C . Then by drawing a network of intersecting lines in\nthis ring-shaped space, we can shew, exactly as in the theorem just\nproved, that the integral\n\n//(\n\ndz\n\nis zero, ivhere the integration is taken round the whole boundary of\nthe nng-shaped space; this boundary consisting of two curves Co and C\n, the one described in the counter-clochvise direction aiid the other\ndescribed in the qlockwise direction.\n\nCorollary 3. In general, if any connected region be given in the\n3-plane, bounded by any number of simple closed curves Co, Ci, Co,\n..., and if /(z) be any function of z which is analytic and one-valued\neverywhere in this region, then\n\nI\n\nf z)dz\n\nis zero, where the integral is taken round the whole boundary of the\nregion; this boundary consisting of the curves Co, Ci, ..., each\ndescribed in such a sense that the region is kept either uhvays on the\nright or always on the left of a person walking in the sense in\nquestion round the boundary.\n\nAn extension of Cauchy's theorem I f(z) dz = 0, to curves lying on a\ncone whose vertex\n\nis at the origin, has been made by Ravut (N'ouv. Annales de Math. (3)\nxvi. (1897), pp. 365-7). Morera, Moid, del 1st. Lombardo, xxii.\n(1889), p. 191, and Osgood, Bull.\n\nAmer. Math. Soc. II. (1896), pp. 296-302, have shewn that the property\nf z)dz =\n\nmay be taken as the property defining an analytic function, the other\nproperties being deducible from it. (See p. 110, example 16.)\n\nExample. A ring-shaped region is bounded by the two circles | s | = 1\nand | z | = 2 in the 2-plane. Verify that the value of I -, where the\nintegral is taken round the boundary of this region, is zero.\n\n* The phrase 'analytic throughout a region' implies one-valuedness (§\n5-12); that is to say that after z has described a closed path\nsurrounding Co, f(z) has returned to its initial value. A function\nsuch as log z considered in the region 1 | | 2 will be said to be '\nanalytic at all points of the region. '\n\n\n\n%\n% 88\n%\n\nFor the boundary consists of the circumference ]2| = 1, described in\nthe clockwise direction, together with the circumference |s| = 2,\ndescribed in the counter-clockwise direction. Thus, if for points on\nthe iirst circumference we write 2 = e, and for points on the second\ncircumference we write z = '2e<'t>, then 6 and cp are real, and the\nintegral becomes\n\njo e' jo 2e'*\n\n\\Subsection{5}{2}{1}{The value of an analytic function at a 'point, expressed as an integral taken round a contour enclosing the point.}\n\nLet C he a contour within and on which /( ) is an analytic function of\nz. Then, if a be any point within the contour,\n\nz - a is a function of z, which is analytic at all points within the\ncontour G except the point z = a.\n\nNow, given e, we can find 3 such that\n\n\\ fi z)-f a)- z-a)f' a)\\ \\ \\ z-a\\\n\nwhenever | - a | < S; with the point a as centre describe a circle 7\nof radius 7' < 8, r being so small that 7 lies wholly inside C\n\nThen in the space between 7 and G f z)\\ \\ {z - a) is analytic, and so,\nby \\hardsectionref{5}{2} corollary 2, we have\n\nf z)dz\\ [f z)dz\n\nc z - a Jy z - a where I and I denote integrals taken\ncounter-clockwise along the curves\n\nG and 7 respectively.\n\nBut, since 1 2 - a | < S on 7, we have\n\nr f(z) dz\\ f f a)+iz- a)f (a) + v(z-a) J y z - a J y z - a\n\nwhere \\ v\\ < e; and so\n\nr m y j f dz f ( ) dz -\\ vdz.\n\nJ C Z-a \\ lyZ -a - Jy Jy\n\nNow, if z be on 7, we may write\n\nz - a = re, where r is the radius of the circle 7, and consequently\n\n\"2t ire dO\n\njyZ - a Jo\n\n= I I de = 2771, y j, re'\" Jo\n\nand dz= ire' dd = 0;\n\nalso, by \\hardsubsectionref{4}{6}{2},\n\nvdz\n\n< e . 27rr.\n\ni\n\n%\n% 89\n%\n\nr f(z)d2 \\ 2 if( a) I = f €dz\\ \\ 2irre.\n\nJ c z - a \\ J y 1\n\n( r ( 5: 1 n.7: i /'\n\nThus\n\nc z - a\n\nBut the left-hand side is independent of e, and so it must be zero,\nsince e is arbitrary; that is to say\n\n    2771 ] c z - a\n\nThis remarkable result expresses the value of a function f z\\ (which\nis analytic on and inside (7) at any point a within a contour C, in\nterms of an integral which depends only on the value of/( ) at points\non the contour itself.\n\nCorollary. If f(z) is an analytic one-valued function of 2 in a\nring-shaped region bounded by two curves C and C\", and a is a point in\nthe region, then\n\n' 2ni J c -(i \"tti c' Z - a\n\nwhere C is the outer of the ciu-ves and the integi-als are taken\ncounter-clockwise.\n\n\\Subsection{5}{2}{2}{The derivates of an analytic function $f(z)$.}\n\nThe function/' (2'), which is the limit of\n\nf z + h)-f z) h\n\nas h tends to zero, is called the derivate of / z). We shall now shew\nthat f' z) is itself an analytic function of z, and consequently\nitself possesses a derivate.\n\nFor if be a contour surrounding the point a, and situated entirely\nwithin the region in which f(z) is analytic, we have\n\nf(a+h)-f(a)\n\nf (a) = hm --,\n\nh o n\n\n,, 0 2TTih [J c z-a-h (j z-a )\n\n= Km -I- \\ /( ) dz\n\nh Q liri J c z-a) z- a~h)\n\nItti J c z - af h 27ri J c z - ay z-a- h)\n\nNow, on C, f(z) is continuous and therefore bounded, and so is (z -\na)~; while we can take | h less than the upper bound of U - a |.\n\n\\\n\n%\n% 90\n%\n\nTherefore\n\n(z - a)- z - a - h) Then, if I be the length of C,\n\nh f f z)dz\n\n[chap. V\n\nis bounded; let its upper bound be K.\n\nTODO:missingpagenum?\n\nlim\n\n<lim !A|(27r)- 7 : = 0,\n\nI h Q lirij c z -af z-a- h)\n\nand consequently f (a) = - . |, .\n\n   Ziri J c z - a)- '\n\na formula which expresses the value of the derivate of a function at a\npoint as an integral taken along a contour enclosing the point.\n\nFrom this formula we have, if the points a and a + h are inside C,\n\nf(a + h)-f'(a) J\\ r f z)dz 1 1\n\nh 27ri J c h\n\n(z - a- hy z - ay\n\nc (z - a - hy z - ay\n\nf(z) dz\n\n= 9:Z;f f )dz.\n\niTTl J c\n\n... +hAh,\n\nZTTi J c \\ Z - ay\n\nand it is easily seen that J./ is a bounded function of z when \\ h\\ <\n\\ z - a.\n\nTherefore, as h tends to zero, A~' /'( - + A) - /' (a) tends to a\nlimit, namely\n\nJ\\ / f(z)dz 27ri J c z - ay '\n\nSince /' (a) has a unique differential coefficient, it is an analytic\nfunction of a; its derivate, which is represented by the expression\njust given, is denoted by/\" (a), and is called the second derivate of\n/(a).\n\nSimilarly it can be shewn that /\"(a) is an analytic function of a,\npossessing a derivate equal to\n\n2 f f(z)dz\\ 27ri Jc z-ay'\n\nthis is denoted by f\" (a), and is called the third derivate of /(a).\nAnd in general an nth derivate/*\"' (a) of /(ct) exists, expressible by\nthe integral\n\nr. n r f(z)dz P 2'rTiJc z-aT+ '\n\nand having itself a derivate of the form\n\n(n + 1)! r f z)dz .\n\n27ri Jciz- a)\"+ ' the reader will see that this can be proved by\ninduction without difficulty.\n\n '\n\n%\n% 91\n%\n\nA function which possesses a first derivate with respect to the\ncomplex variable z at all points of a closed two-dimensional region in\nthe -plane therefore possesses derivates of all orders at all points\ninside the region.\n\n\\Subsection{5}{2}{3}{Caiichys inequality for f \" (a).}\n\nLet f(z) be analytic on and inside a circle G with centre a and radius\n?\\ Let M be the upper bound oif z) on the circle. Then, by \\hardsubsectionref{4}{6}{2},\n\n!/\"\"( )i;4/c; 'i'' '\n\nM.n\\\n\nExample. l f(z) is analytic, z = x- iij and V- =;, + -2, .shew that\n\nV2 log 1/(2) 1 = 0; andy2|/(e)|>0 unle.ss/(2) = or/' z) = Q.\n\\addexamplecitation{Trinity, 1910.}\n\n\\Section{5}{3}{Analytic functions represented by uniformly convergent series.}\n\n X)\n\nLet X fn (z) be a series such that (i) it converges uniformly along a\n=o\n\ncontour C, (ii) / (z) is analytic throughout C and its interior.\n\n00 Then 2 fni ) converges, and the sum* of the series is an analytic\n\nn =\n\nfunction throughout C and its interior.\n\n00\n\nFor let a be any point inside C; on C, let S fn z) = (z).\n\nThen -. - dz = j- \\ fn( )\\\n\n27ri J c z - a 27ri j c Im=o ] z -a\n\n .o \\ 2mlc 2-a \\ '\n\n00\n\nby* \\hardsectionref{4}{7}. But this last series, by \\hardsubsectionref{5}{2}{1}, is S fiid)', the series\nunder\n\nn =\n\nconsideration therefore converges at all points inside C; let its sum\ninside G (as well as on C) be called (z). Then the function is\nanalytic if it ha,s a unique differential coefficient at all points\ninside G.\n\nBut if a and a + h be inside G,\n\n (a + h)- (a) \\ J f ( ) (\n\nA 27rt J c z - a) z - a - h)'\n\nand hence, as in \\hardsubsectionref{5}{2}{2}, lim W a- h) - a)] A~ ] exists and is equal to\n\n7t-*0 * Since | 2 - a |~i is bounded when a is fixed and z is on C,\nthe uniformity of the convergence of S / z)l[z - a) follows from that\nof 2 / [z).\n\nn=0 n=0\n\n%\n% 92\n%\n\n  - : 7 - dz; and therefore <I> (z) is analytic inside G. Further, by\n27rt J c z- a)\n\ntransforming the last integral in the same way as we transformed the\nfirst\n\n00 ao\n\none, we see that <!>' (a) = S / ' (a), so that 2 fn (a) may be '\ndifferentiated\n\nn=0 n=0\n\nterm by term.'\n\nIf a series of analytic functions converges only at points of a curve\nwhich is not closed nothing can be inferred as to the convergence of\nthe derived series*.\n\n'COS 7hJ7\n\nThus 2 ( - )\" - 2 - converges uniformly for real values of x \\hardsubsectionref{3}{3}{4}).\nBut the derived\n\nH = l 'i\n\n  sin ij series 2 ( - )\"\"* converges non-uniformly near A' = (2m+1)\ntt, (m any integer); and\n\nH = l 'ii\n\nthe derived series of this, viz. 2 ( - )\"~ cos n.v, does not converge\nat all.\n\n(1=1\n\nCorollary. By \\hardsectionref{3}{7}, the sum of a power series is analytic inside its\ncircle of con- vergence.\n\n\\Subsection{5}{3}{1}{Analytic functions represented by integrals.}\n\nLet f t, z) satisfy the following conditions when t lies on a certain\npath of integration (a, h) and z is any point of a region >S' :\n\n(i) f and ~ are continuous functions of t.\n\n   dz\n\n(ii) / is an analytic function of z.\n\ndf * (in) The continuity of ~- qua function of z is uniform with\nrespect to\n\nthe variable t.\n\nrb .\n\nThen I f(t, z)dt is an analytic function of z. For, by \\hardsectionref{4}{2}, it has\nthe\n\n, !* f* dt\\ t, z) . unique derivate - - - - dt.\n\n\\Subsection{5}{3}{2}{Analytic functions represented by infinite integrals.}\n\nFrom \\hardsubsectionref{4}{4}{4} (II) corollary, it follows that I f (t, z) dt is an\nanalytic\n\nJ a\n\nfunction of z at all points of a region >S' if (i) the integral\nconverges, (ii) f t, z) is an analytic function of z when t is on the\npath of integration and z is on S,\n\n(iii) - : ' is a continuous function of both variables, (iv) - - - dt\n\ndz J a OZ\n\nconverges uniformly throughout 8.\n\nFor if these conditions are satisfied f t, z) dt has the unique\nderivate\n\nJ a\n\nJ a\n\ndz\n\n* This might have been anticipated as the main theorem of this section\ndeals with uniformity of convergence over a two-dimensional region.\n\n%\n% 93\n%\n\nA case of very great importance is afforded by the integral I e~' /(0\ndt,\n\nJo where /(t) is continuous and \\ f t)\\ < Ke' where K, r are\nindependent of t; it is obvious from the conditions stated that the\nintegral is an analytic function of z when R z) r, > r. [Condition\n(iv) is satisfied, by \\hardsubsubsectionref{4}{4}{3}{1} (I),\n\nr\n\nsince I fe\"\"\"''*' rf converges.]\n\nJo\n\n\\Section{5}{4}{Taylor's Theorem*TODO.}\n\nConsider a function f z), which is analytic in the neighbourhood of a\npoint z = a. Let (7 be a circle with a as centre in the -plane, which\ndoes not have any singular point of the function f(z) on or inside it\n; so that f(z) is analytic at all points on and inside C. Let z = a +\nh be any point inside the circle C. Then, by \\hardsubsectionref{5}{2}{1}, we have\n\n    Itti J c z-a-h\n\n -rriJc Xz-a iz-af ' ' ' z - ay- ' z - a)'' ' z - a - h)]\n\nf z) But when z is on C, the modulus of - - -j is continuous, and so,\n\nz - a - h\n\nby \\hardsubsectionref{3}{6}{1} cor. (ii), will not exceed some finite number M. Therefore,\nby \\hardsubsectionref{4}{6}{2},\n\n1 f f(z)dz.h''+\n\n27riJc z-ay'+' z-a-h) \" 27r [rJ '\n\nwhere R is the radius of the circle C, so that 'IttR is the length of\nthe path of integration in the last integral, and R = \\ z - a\\ for\npoints z on the cir- cumference of C.\n\nThe right-hand side of the last inequality tends to zero as ?? - > oo\n. We have therefore\n\n/(a + /0=/(a) + / /'(a)-h|,/\"(a)+...-f |/-'(a) + ..., which we can\nwrite\n\nf(z)=f a) + (z - a)/' (a) + ~ ~ff\" a) + ... + ri /< ) (a) + ....\n\nThis result is known as Taylors Theorem; and the proof given is due\nto Cauchy. It follows that the radius of convergence of a poiuer\nseries is always\n\n* The formal expansion was first published by Dr Brook Taylor (1715)\nin his Methodus Incrementonim.\n\n%\n% 94\n%\n\nat least so large as only just to exclude from the interior of the\ncircle of con- vergence the nearest singularity of the function\nrepresented by the series. And by \\hardsectionref{5}{3} corollary, it follows that the\nradius of convergence is not larger than the number just specified.\nHence the radius of convergence is just such as to exclude from the\ninterior of the circle that singularity of the function which is\nnearest to a.\n\nAt this stage we may introduce some terms which will be frequently\nused.\n\nIf f(a) = 0, the function f(z) is said to have a zero at the point z =\na. If at such a point f (a) is different from zero, the zero of f(a)\nis said to be simple; if, however,/' a),f\" a), .../\"*\"'' (a) are all\nzero, so that the Taylor's expansion of f(z) at z = a begins with a\nterm in (z - a)\", then the function f(z) is said to have a zero of the\nnth. order at the point z = a.\n\nExample 1. Find the function / (s), which is analytic throughout the\ncircle C and its interior, whose centre is at the origin and whose\nradius is unity, and has the value\n\na - cos 6 . sin 6\n\na -2acos6 + l a -2acos0 + l\n\n(where a> 1 and 6 is the vectorial angle) at points on the\ncircumference of C.\n\n[We have\n\nf z) dz\n\n/( )(0) = .f - - ' ' 2mjc z\"\n\nn ! /\"St\n\n27nJo\n\n\\ n\\ n e~\"i9d6 \\ n \\ f dz f d\"\" 1 \"1\n\n~2ffjo a-e<9 ~2iriJcz''(a-z)~~\\ \\ ds a-zJ\n\ne- 'O.idd. -7- - ~;r ., (puttuig z = e*e) a- -2a cos + 1 ' ° '\n\nTherefore by Maclaurin's Theorem*,\n\n)l=0 \"\n\nor/(2) = (a-2)~' for all points within the circle.\n\nThis example raises the interesting question, Will it still be\nconvenient to define f(z) as (a-2)~ at points outside the circle ?\nThis will be discussed in \\hardsubsectionref{5}{5}{1}.]\n\nExample 2. Prove that the arithmetic mean of all values of 2\"\" 2 cv,\nfor points z on\n\nthe circumference of the circle \\ z\\ = l, is a, if Sc? \" is analytic\nthroughout the circle and its interior.\n\n/ (\") (0) [Let 2 v2''=/(2), so that a, =;- . Then, writing z = e',\nand calling C the circle\n\nK=0 \"\n\n277 jo 2\" ~ 2ni j c 2\"* ~ n\\ \"\"\" -'\n\nz'i * The re8ult/ 2) =/(0) +2/' (0) + -/\" (0) + ..., obtained By\nputting a = in Taylor's Theorem,\n\nis usually called Maclaurin's Theorem; it was discovered by Stirling\n(1717) and published by Maclaurin (1742) in his Fluxions.\n\n%\n% 95\n%\n\nExample 3. Let $f(z) = z^{r}$; then $f(z+h)$ is an analytic function\nof $h$ when $\\absval{h} < \\absval{z}$ for all values of $r$; and so\n$(z + h)^{r} = z^{r} + rz^{r-1} h + \\frac{ r (r-1) }{2} z^{r-2} h^{2}\n+ \\cdots, $ this series converging when $\\absval{h} < \\absval{z}$.\nThis is the binomial theorem.\\index{Binomial theorem}\n\nExample 4. Prove that if h is a positive constant, and (1 - 2zh- h?) ~\nin expanded in the form\n\n\\ + hP z) + h''P.2 z) + h P z) + (A),\n\n(where P (2) is easily seen to be a polynomial of degree n in z), then\nthis series converges so long as z is in the interior of an ellipse\nwhose foci are the points z = \\ and 2= -1, and whose semi-major axis\nis (A + A\"').\n\nLet the series be first regarded as a function of A. It is a power\nseries in A, and therefore converges so long as the point A lies\nwithin a circle in the /; -plane. The centre of this circle is the\npoint A = 0, and its circumference will be such as to pass through\nthat\n\nsingularity of (1 - 2zh- h' )~ which is nearest to A = 0.\n\nBut 1 - 22A -1- A2 = A - 2 + (22 - 1 )5>. /i \\ 2 \\ ( 2 \\ 1 )ij,\n\nso the singularities of (1 - 22A-|-A-)~2 are the points h=z - z' - ) '\nand h=z + z - ) . [These singularities are branch points (see \\hardsectionref{5}{7}).]\n\nThus the series (A) converges so long as | A | is less than both\n|2-(22-l) | and |2-f(22\\ l) |.\n\nDraw an ellipse in the 2-plane passing through the point 2 and having\nits foci at +L Let a be its semi-major axis, and 6 the eccentric angle\nof 2 on it.\n\nThen 2 = a cos -f i (a - 1 ) sin 9,\n\nwhich gives 2 ± (22 - 1 )i = a + (a2 \\ i) (cos + 1 sin 6),\n\nso i2±(22-l)i | = a + (a2\\ i)4.\n\nThus the series (A) converges so long as A is less than the smaller of\nthe numbers a-|-(a2- 1) and a- a - 1)2, i.e. so long as A is less than\na-(a2\\ i)5. But A = a - (a2- 1) when a = |(A-f-A~i).\n\nTherefore the series (A) converges so long as 2 is within an ellipse\nwhose foci are 1 and - 1, and whose semi-major axis is h h + h~ ).\n\n\\Subsection{5}{4}{1}{Forms of the remainder in Taylor's series.}\n\nLet f(x) be a real function of a real variable; and let it have\ncontinuous differential coefficients of the first n orders when a x a\n+ h.\n\nIf O i l, we have\n\nfl (71-1 hm ) /i n -f\\ n-\\\n\nIt li. 7! (1 - ') \"/'\"\" ( + *> = ifr /'\"' ( + \"'> - ''/' ( + \"')\n\nIntegrating this between the limits and 1, we have\n\nn-l hm /! hn /I \\ f\\ n-i\n\nf(a + h)=f a)+ -,f (a)+ ] ', f'Ha + th)dt.\n\nni = im: Jo n-L)l\n\nLet Rn = J~iyi ] \\ l - 0' - V'\"* ( + ih) dt;\n\nand let j-j be a positive integer such that p n.\n\n%\n% 96\n%\n\nThen Rn = r - f ' ( \" y~\" ' ( \" O\"\" /'\"* ( + th) dt. Let U, L be the\nupper and lower bounds of (1 - )' -p/(\"' (a + th). Then\n\nf ' X (1 - 0 \"' dt<\\ \\ t)P-' . (1 - O' -P/\"'' (a + th) dt<[ U(l- t)P-'\ndt. Jo Jo Jo\n\nSince (1 - t)' ~P / '\" (a + th) is a continuous function it passes\nthrough all\n\nvalues between U and L, and hence we can find 6 such that 1, and\n\n[ I- ) -y <' ' (a + th) dt = -1(1- ey-Pf \" (a + Oh). Jo\n\nTherefore R = .J \\ y;(1 - f- /*\"' (a + 6h).\n\nA\" Writing p = n, we get Rn = - /\"\" (a + Oh), which is Lagrange s form\nfor\n\nA\" Me remainder; and writing j9 = 1, we get Rn = - \\, y, (1 -\n)''-'/''\" (a + A),\n\nwhich is Cauchys form for the remainder. Taking n = \\ in this result,\nwe get\n\nf a h)-f a) = hf a + 6h) \\ i f(x) is continuous when a x a + h; this\nresult is usually known as the First Mean Value Theorem (see also §\n4-14).\n\nDarboux gave in 1876 Journal de Math. (3) ii. p. 291) a form for the\nremainder in Taylor's Series, which is applicable to complex variables\nand resembles the above form given by Lagrange for the case of real\nvariables.\n\n\\Section{5}{5}{The Process of Continuation.}\n\nNear every point P, Zq, in the neighbourhood of which a function f z)\nis analytic, we have seen that an expansion exists for the function as\na sei'ies of ascending positive integral powers of z - Zq), the\ncoefficients in which involve the successive derivates of the function\nat z .\n\nNow let A be the singularity of f(z) which is nearest to P. Then the\ncircle within which this expansion is valid has P for centre and PA\nfor radius.\n\nSuppose that we are merely given the values of a function at all\npoints of the circumference of a circle slightly smaller than the\ncircle of convergence and concentric with it together with the\ncondition that the function is to be analytic throughout the interior\nof the larger circle. Then the preceding theorems enable us to find\nits value at all points within the smaller circle and to determine the\ncoefficients in the Taylor series proceeding in powers of z - Zq. The\nquestion arises, Is it possible to define the function at points\noutside the circle in such a way that the function is analytic\nthroughout a larger domain than the interior of the circle ?,\n\n%\n% 97\n%\n\nIn other words, given a potver series which converges and represents a\nfunction only at poiiits within a circle, to define hy means of it the\nvalues of the function at points outside the circle.\n\nFor this purpose choose any point TODO within the circle, not on the\nline PA. We know the value of the function and all its derivates at\nPj, from the series, and so we can form the Taylor series (for the\nsame function) with Pi as origin, which will define a function\nanalytic throughout some circle of centre Pj. Now this circle will\nextend as far as the singularity* which is nearest to Pi, which may or\nmay not be A; but in either case, this- new circle will iisuall '!\nlie partly outside the old circle of convergence, and for jjoints in\nthe region which is included in the new circle but not in the old\ncircle, the new series may he used to define the values of the\nfunction, although the old series failed to do so.\n\nSimilarly we can take any other point Po, in the region for which the\nvalues of the function are now known, and form the Taylor series with\nP as origin, which will in general enable us to define the function at\nother points, at which its values were not previously known; and so\non.\n\nThis process is called continuation . By means of it, starting from a\nrepresentation of a function by any one power series we can find any\nnumber of other power series, which between them define the value of\nthe function at all points of a domain, any point of which can be\nreached from P without passing through a singularity of the function;\nand the aggregate § of all the power series thus obtained constitutes\nthe analytical expression of the function.\n\nIt is important to know whether continuation by two different paths\nfBQ, PB'Q will give the same final power series; it will be seen that\nthis is the case, if the function have no singularity inside the\nclosed curve PBQB'P, in the following way : Let P be any point on PBQ,\ninside the circle C' with centre P; obtain the continuation of the\nfunction with Pi as origin, and let it converge inside a circle Ci;\nlet P be any point inside both circles and also inside the curve\nPBQB'P; let S, Si, Si be the power series with P, Pi, Pi as origins;\nthen|| *S'i = S'i' over a certain domain which will contain Pi, if Pi'\nbe taken sufficiently near Pi; and hence Si will be the continuation\nof Si; for if Ti were the continuation of Si, we have Ti = Si over a\ndomain containing Pj, and so \\hardsubsectionref{3}{7}{3}) corresponding coefficients in i\nand Ti are the same. By carrying out such a process a sufficient\nnumber of times, we deform the path PBQ into the path PB'Q if no\nsingular point is inside PBQB'P. The reader will convince himself by\ndrawing a figure that the process can be carried out in a finite\nnumber of steps.\n\n* Of the function defined by the new sei'ies.\n\n+ The word ' usually ' must be taken as referring to the cases which\nare likely to come under the reader's notice while studying the less\nadvanced parts of the subject.\n\nX French, prolongement; German, Fortsetzung.\n\n§ Such an aggregate of power series has been obtained for various\nfunctions by M. J. M. Hill, by purely algebraical processes, Proc.\nLondon Math. Soc. xxxv. (1903), pp. 388-416.\n\nII Since each is equal to S.\n\nW. M. A. 7\n\n%\n% 98\n%\n\nExample. The series\n\n1, Z 22 3\n\na a a\" a* represents the function\n\n/('-) = -- a - z\n\nonly for points z within the circle | I = | a | .\n\nBut any number of other power series exist, of the type\n\n1 z-h z-hf z-hf\n\na-b' a-hf\" a-bf' a-bf '-' '\n\nif b/a is not real and positive these converge at points inside a\ncircle which is partly inside and partly outside | s | = | a j; these\nseries represent this same function at points outside this circle.\n\n\\Subsubsection{5}{5}{0}{1}{On functions to which the continuation-process cannot be applied.}\n\nIt is not always possible to carry out the process of continuation.\nTake as an example the function /(2) defined by the power series\n\nwhich clearly converges in the interior of a circle whose radius is\nunity and w hose centre is at the origin.\n\nNow it is obvious that, as -1-0, /(2) +qc; the point +1 is therefore\na singularity of/ (2).\n\nBut /(2)=22+/( 2)\n\nand if z-- 0, f(z )- x and so /(s)- x, and hence the points for which\nz- = l are singularities oi f z); the point 2= - 1 is therefore also\na singularity oif z). Similarly since\n\nwe see that if 2 is such that 2* = 1, then z is a singularity of/ (2)\n; and, in general, any root of any of the equations\n\n22=1, 2* = 1, 28 = 1, 2l =l, ...,\n\nis a singularity of f z). But these points all lie on the circle | 2 |\n= 1; and in any arc of this circle, however small, there are an\nunlimited number of them. The attempt to carry out the process of\ncontinuation will therefore be frustrated by the existence of this\nimbroken front of singularities, beyond which it is impossible to\npass.\n\nIn such a case the function f(z) cannot be continued at all to points\n2 situated outside the circle i 2 | = 1; such a function is called a\nlacuvary f miction, and the circle is said to be a limiting circle for\nthe function.\n\n\\Subsection{5}{5}{1}{The identity of two functions. .,}\n\nThe two series\n\n1 + 2 + ' + 2' + . . .\n\nand - 1 + ( - 2) - ( - 2y- + ( - 2) - (2 - 2 + ...\n\ndo not both converge for any value, of z, and are distinct expansions.\n\nNevertheless, we generally say that they represent the same function,\non the\n\nstrength of the fact that they can both be represented by the same\nrational\n\n1 expression .\n\n%\n% 99\n%\n\nThis raises the question of the identity of two functions. When can\ntwo different expansions be said to represent the same function ?\n\nWe might define a function (after Weierstrass), by means of the last\narticle, as consisting of one power series together with all the other\npower series which can be derived from it by the process of\ncontinuation. Two different analytical expressions will then define\nthe same function, if they represent power series derivable from each\nother by continuation.\n\nSince if a function is analytic (in the sense of Cauchy,\\hardsubsectionref{5}{1}{2}) at\nand near a point it can be expanded into a Taylor's series, and since\na convergent power series has a unique differential coefficient (§\n5'3), it follows that the definition of Weierstrass is really\nequivalent to that of Cauchy.\n\nIt is important to observe that the limit of a combination of analytic\nfunctions can represent different analytic functions in different\nparts of the plane. This can be seen by considering the series\n\n5(' + j)\\!,('\"i)(TT7.-r;i )\n\nThe sum of the first n + 1 terms of this series is\n\n1 / 1\\ 1\n\nz \\ zJ' I + z' '\n\nThe series therefore converges for all values of z (zero excepted) not\non the circle j 2 | = 1. But, as w - > oo, | 2:'* | - > or j £\" i -\noo according as | j is less or greater than unity; hence we see that\nthe sum to infinity of the series is\n\nz when \\ z\\ < 1, and - when | j > 1. This series therefore represents\none\n\nfunction at points in the interior of the circle | j = 1, and an\nentirely different function at points outside the same circle. The\nreader will see from \\hardsectionref{5}{3} that this result is connected with the\nnon-uniformity of the convergence of the series near | j = 1.\n\nIt has been shewn by Borel* that if a region C is taken and a set of\npoints S such that points of the set S are arbitrarily near every\npoint of 6', it may be possible to define a function which has a\nunique differential coefficient (i.e. is monogenic) at all points of C\nwhich do not belong to *S'; but the function is not analytic in C in\nthe sense of Weierstrass.\n\nSuch a function is\n\n.,, 00 w n exp(-expw*) f z)= 2 2 2; . . n=ip=oq=o z- p + qi)jn\n\n* Proc. Math. Congress, Cambridge (1912), i. pp. 137-liJ8. Leqons sur\nles fonctions mono- genes (1917). The functions are not monogenic\nstrictly in the sense of \\hardsectionref{5}{1} because, in the example quoted, in\nworking out f z + h) -f(z)]jli, it must be su Dposed that R z + h) and\nI z + ]i) are not botli rational fractions.\n\n%\n% 100\n%\n\n\\Section{5}{6}{Laurent's Theorem.}\n\nA very important theorem was published in 1843 by Laurent*; it\nrelates to expansions of functions to which Taylor's Theorem cannot be\napplied.\n\nLet G and C be two concentric circles of centre a, of which C is the\ninner; and let f(z) be a function which is analytic i* at all points\non G and G' and throughout the annulus between G and C. Let a + A be\nany point in this ring-shaped space. Then we have \\hardsubsectionref{5}{2}{1} corollary)\n\n ZTTt j cz - a - h liTi j c z - a - h\n\nwhere the integrals are supposed taken in the positive or\ncounter-clockwise direction round the circles.\n\nThis can be written\n\nWe find, as in the proof of Taylor's Theorem, that\n\nf(z)dz.h- r f(z)dz(z-ar+\n\nc(z-a)\"+' z-a-h) Jc z-a-h)h +'\n\ntend to zero as n- cc; and thus we have\n\n/(a + h) = cio + a h + ajr + ... + -~ + j + ...,\n\nwhere + a = - / K, and 6 = 5- . I z - ay'-'f(z) dz.\n\nThis result is Laurent's Theorem; changing the notation, it can be\nexpressed in the following form: If f(z) be analytic on the concentric\ncircles G and G' of centre a, and throughout the annulus between them,\nthen at any point z of the annidus f(z) can he expanded in the form\n$$\nTODO\n$$\nwhere a = . j a.nd b = . [ (t - aT' f(t) dt.\n\nAn important case of Laurent's Theorem arises when there is only one\nsingularity within the inner circle G', namely at the centre a. In\nthis case the circle G' can be taken as small as we please, and so\nLaurent's expansion is valid for all points in the interior of the\ncircle C, except the centre a.\n\n* Comptes Rendus, xvii. (1843), pp. 348-349. t See \\hardsectionref{5}{2} corollary 2,\nfootnote.\n\nX We cannot write a- = fW (a)ln ! as in Taylor's Theorem since /(2) is\nnot necessarily analytic inside C.\n\n%\n% 101\n%\n\nExample 1. Prove that\n\ne ' = J x)+zJ x) + z' J x) + ...-irz-J,, x)- ...\n\n1 /\"St\n\nwhere Jn (*) = s~ I ' ~ \" )\n\n TT J\n\n[For the function of z under consideration is analytic in any domain\nwhich does not include the point z=Q; and so by Laurent's Theorem,\n\ng2V z) = a,, + axZ + aoz'-+... + - ->r + ...,\n\nwhere n = s - I - n and G = i, - . I e z dz,\n\nand where 6' and C\" are any circles with the origin as centre. Taking\nC to be the circle of\n\nradius unity, and writing = e', we have\n\n1 Z\"' \"\" 1 /' -'f\n\n -=--, / e:' sin .e- ' irf = jr- / COS (n6 - X H\\ n 0) dB, 27ri. Jo\n27r y\n\nI sin (/i - i'sin ) tZ vanishes, as may be seen by writing in-cf) for\n9. ThiLS\n\nsuice\n\na = J (A'), and \\& = ( -)\", since the function expanded is unaltered\nif -z  l)e written for z, so that 6 = ( - )\" Ai(.:i ), and the proof\nis complete.]\n\nExample 2. Shew that, in the annulus defined by|a|<|3|<i6|, the\nfunction\n\nr bz i\n\nI'\n\n\\ \\ {z-a) b-z) can be expanded in the form\n\n*\"+.?,* '(? + 6-.) c. * 1.3. ..(2 -1). 1.3... (2i + 2>i-l) /a\\' \" ' =\n,!o 2 .ll l + n)l [b)\n\nThe function is one- valued and analytic in the annulus (see \\hardsectionref{5}{7}),\nfor the branch-points 0, a neutralise each other, and so, by Laurent's\nTheorem, if C denote the circle \\ z\\=r, where | o ' < / < | 6 |, the\ncoefficient of 2\" in the required expansion is\n\n1 f dz ( bz 1\n\n27riJ c '- \\ \\ {z-a) b-z) ' Putting z = re', this becomes\n\n1 [-' .,, 1.3... (2i-l) ?*<*\" 1.3... (2i-l)a' -''\n\nthe series being absolutely convergent and uniformly convergent with\nregard to 6.\n\nThe only terms which give integrals different from zero are those for\nwhich k = l + n. So the coefficient of z\" is\n\n(2 -1) 1 . 3 ...(2 + 2/i-l) a \\ Sn\n\n1 r 'T * 1\n\n2ir J 1=0\n\n2Kl\\ 2* + ™.(/+m) ! ¥*\" b\" '\n\nSimilarly it can be shewn that the coefficient of - is S a'\\\n\n%\n% 102\n%\n\nExample 3. Shew that\n\nZ Z''\n\n1 rsT\n\nwhere = '\" '' \"> '''\" cos ( - v) sin (9 - ?i(9 o?,\n\nZTT / 1 /\"-\"\n\nand i = 5- / e'\" + \")'=°' cos (i'-?Osi\" - '<9 < <9-\n\nZTry\n\n\\Subsection{5}{6}{1}{T ie nature of the singularities of one-valued functions.}\n\nConsider first a function f(z) which is analytic throughout a closed\nregion 8, except at a single point a inside the region.\n\nLet it be possible to define a function z) such that (i) z) is analj\ntic throughout S,\n\n(ii) when a, /( ) = < ( ) + - 4-A . + ...+ \"\n\nz - a (z - a)- z - ay-\n\nThen f(z) is said to have a 'pole of order n at a'; and the terms\n\nh, -T + ... + -. are called the principal part of f(z) near a.\n\nz - a. (z - a) (z - aY r r j \\ /\n\nBy the definition of a singularity \\hardsubsectionref{5}{1}{2}) a pole is a singularity.\nIf n = 1,\n\nthe singularity is called a simple pole.\n\nAny singularity of a one-valued function other than a pole is called\nan essential singularity.\n\nIf the essential singularity, a, is isolated (i.e. if a region, of\nwhich a is an interior point, can be found containing no singularities\nother than a), then a Laurent expansion can be found, in ascending and\ndescending powers of a valid when dk>\\ z - a h, where A depends on the\nother singularities of the function, and 8 is arbitrarily small. Hence\nthe ' principal part ' of a function near an isolated essential\nsingularity consists of an infinite series.\n\nIt should be noted that a pole is, by definition, an isolated\nsingularity, so that all singularities which are not isolated (e.g.\nthe limiting point of a sequence of poles) are essential\nsingularities.\n\nThere does not exist, in general, an expansion of a function valid\nnear a non-isolated singularity in the way that Laurent's expansion is\nvalid near an isolated singularity.\n\nCorollary. If f(z) has a pole of order n at a, and z) = z - aYf z) z\na), i\\ r a)= lim z-a)' f z), then y\\ r z) is analytic at a.\n\nExample 1. A function is not bounded near an isolated essential\nsingularity.\n\n[Prove that if the function were bounded near z=a, the coefficients of\nnegative powers of 2 - a would all vanish.]\n\n%\n% 103\n%\n\nc z\\\n\nExample 2. Find the singularities of the function e ~ 7 e - 1 .\n\nAt 2 = 0, the numerator is analytic, and the denominator has a simple\nzero. Hence the function has a simple pole at 2 = 0.\n\nSimilarly there is a simple pole at each of the points mria ( = + 1,\n+2, +3, ...); the denominator is analytic and does not vanish for\nother values of z.\n\nA.t z = a, the numerator has an isolated singularity, so Laurent's\nTheorem is applicable, and the coefficients in the Laurent expansion\nmay be obtained from the quotient\n\nc c\n\nz- a 2 I (z - aV\n\nMl+'--\" + ...)-l\n\nwhich gives an expansion involving all positive and negative powers of\nz - a). So there is an essential singularity at 2 = a.\n\nExample 3. Shew that the function defined by the series\n\nI wg\"- (l +)t- )\"-l\n\n =1 (2 -l) 2 -(l+/i-l)\n\nhas simple poles at the points 2 = (1 + ~i)e- ''' / ( =0, 1, 2, ... n\n- \\; ?i = l, 2, 3, ...). y \\addexamplecitation{Math. Trip. 1899.}\n\n\\Subsection{5}{6}{2}{The 'point at infinity.'}\n\nThe behaviour of a function /C ') as | ' - oo can be treated in a\nsimilar way to its behaviour as z tends to a finite limit.\n\nIf we write z = -,, so that large values of z are represented by small\n\nvalues of z' in the '-plane, there is a one-one correspondence between\nz and z, provided that neither is zero; and to make the\ncorrespondence complete it is sometimes convenient to say that when z\nis the origin, z is the * point at infinity.' But the reader must be\ncareful to observe that this is not a definite point, and any\nproposition about it is really a proposition concerning the point / =\n0.\n\nLet/(2 ) = 4> z'). Then < z') is not defined at z = 0, but its\nbehaviour near z = is determined by its Taylor (or Laurent) expansion\nin powers of z \\ and we define < (0) as lim (/) if that limit exists.\nFor instance\n\nthe function (/) may have a zero of order m at the point 2' =; in\nthis case the Taylor expansion of ( ') will be of the form\n\nand so the expansion of f(z) valid for sufficiently large values of |\n.0 j will be of the form\n\nIn this case,/(0) is said to have a zero of order m at ' infinity.'\n\n%\n% 104\n%\n\nAgain, the function (f)(2') may have a pole of order m at the point z'\n= 0; in this case\n\nand so, for sufficiently large values of \\ z\\, f(z) can be expanded in\nthe form\n\nN P\n\nf z) = Az\"' + Bz'''-' + Cz'\"-- +...+Lz + M+- + - + ....\n\nIn this case,/(2 ) is said to have a pole of order m at ' infinity. '\nSimilarly f(z) is said to have an essential singularity at infinity,\nif z) has an essential singularity at the point / = 0. Thus the\nfunction e' has an\n\nessential singularity at infinity, since the function e~' or\n\n1 \\ 1\\ 1\n\nhas an essential singularity at z = 0.\n\nExample. Discuss the function represented by the series\n\n2 -, :; 5-5, ( >1).\n\nZ 1\n\nThe function represented by this series has singularities at 2=- and\n2= - i\n\n n=\\, 2, 3, ...), since at each of these points the denominator of one\nof the terms in the series is zero. These singularities are on the\nimaginary axis, and have 3 = as a limiting point; so no Taylor or\nLaurent expansion can be foi med for the function valid throughout any\nregion of which the origin is an interior point.\n\nFor values of z, other than these singularities, the series converges\nabsolutely, since the limit of the ratio of the (?i + l)th term to the\n?ith is lim (?i+ l)~i a~ = 0. The function is\n\nan even function of z (i.e. is unchanged if the sign of z be changed),\ntends to zero as I 2 I - Qc, and is analytic on and outside a circle\nC of radius greater than unity and centre at the origin. So, for\npoints outside this circle, it can be expanded in the form\n\nh + j + b+\n\nwhere, by Laurent's Theorem,\n\nTODO\n\nThis double .series converges absolutely when | 2 | > 1, and if it be\nrearranged in powers of 2 it converges uniformly.\n\nSince the coefficient of 2 ~ Ms 2 -; and the only term which\nfurnishes a non-\n\nH=o n !\n\nzero integral is the term in z~, we have\n\n(\\ )fc-ia-2A- dz\n\nb'k  1 - .\n\nItti J c =o, fo n\\ a2*\n\n%\n% 105\n%\n\nTherefore, when | 2 | > 1, the function can be expanded in the form\n\nill\n\ne\"' e * e\n\nThe function has a zero of the second order at infinity, since the\nexpansion begins with a term in z~' .\n\n\\Subsection{5}{6}{3}{Liouville's Theorem*.}\n\nLet f(z) he analytic for all values of z and let \\ f z)\\ < K for all\nvalues of z, where K is a constant (so that \\ f(z) is bounded as | r |\n- > x ). Then f(z) is a constant.\n\nLet z, z' be any two points and let C be a contour such that z, z are\ninside it. Then, by \\hardsubsectionref{5}{2}{1},\n\ntake C to be a circle whose centre is z and whose radius is p 2 | / -\ns |; on\n\nC write \\ \\ = z pe' \\ since jf - /| 2P when is on C it follows from §\n4-62 that\n\n= 2\\ z -z\\ Kp-K Make p- cc keeping z and z' fixed; then it is obvious\nthat/(/) -f(z) = 0; that is to say, f(z) is constant.\n\nAs will 1)0 seen in the next article, and again frequently in the\nlatter half of this volume (Chapters xx, xxi and xxii), Liouville's\ntheorem furnishes short and convenient proofs of some of the most\nimportant results in Analysis.\n\n\\Subsection{5}{6}{4}{Functions with no essential singularities.}\n\nWe shall now shew that the only one-valued functions luhich have no\nsingidarities, except poles, at any jjoint (including oo ) are\nrational functions.\n\nFor let f(z) be such a function; let its singularities in the finite\npart of the plane be at the points Cj, c-j, ... Ck'. and let the\nprincipal part \\hardsubsectionref{5}{6}{1}) of its expansion at the pole Cr be\n\n+ 1 ::; + . . . + - 7 -\n\nZ - Cr (Z - Crf '\" (Z - CyJ\n\nLet the principal part of its expansion at the pole at infinity be\n\na- z + a-iZ + ... + anZ \\\n\nif there is not a pole at infinity, then all the coefficients in this\nexpansion\n\nwill be zero.\n\n* This theorem, which is really due to Cauchy, Comptes Rendus, xix.\n(1844), pp. 1377, 1378, was given this name by Borchardt, Journal fvr\nMath, lxxxviii. (1880), pp. 277-310, who heard it in Liouville's\nlectures in 1847.\n\n%\n% 106\n%\n\nNow the function\n\nhas clearly no singularities at the points c, c.j, ... Ck, or at\ninfinity; it is therefore analytic everywhere and is bounded as \\ z -\n>cc, and so, by Liou\\ dlle's Theorem, is a constant; that is,\n\n/(.) = + .. + a..= + . . . +,,.. + I l i + ( . +   + (i J\n\nwhere C is constant; f(z) is therefore a rational function, and the\ntheorem is established.\n\nIt is evident from Liouville's theorem (combined with\n\\hardsubsectionref{3}{6}{1} corollary (ii)) that a function which is\nanalytic everywhere (including oc ) is merely a constant. Functions\nwhich are analytic everywhere except at oc are of considerable\nimportance; they are known as integral functions*. Examples of such\nfunctions are e, sin z, e . From \\hardsectionref{5}{4} it is apparent\nthat there is no finite radius of convergence of a Taylor's series\nwhich represents an integral function; and from the result of this\nsection it is evident that all integral functions (except mere\npolynomials) have essential singularities at oo .\n\n\\Section{5}{7}{Many-valued functions.}\n\nIn all the previous work, the functions under consideration have had a\nunique value (or limit) corresponding to each value (other than\nsingularities) of .\n\nBut functions may be defined which have more than one value for each\nvalue of z; thus if 2- = r (cos 6 + i sin 6), the function 2- has the\ntwo values\n\nr* (cos 1(9 + t sin (9), r jcos \\ 0 + lir) + i sin \\ (6 + 27r)|;\n\nand the function arc tan x (x real) has an unlimited number of values,\nviz. Arc tan x + mr, where - tt < Arc tan x <- 'tt and n is any\ninteger; further\n\nexamples of many- valued functions are log z, z, sin z~).\n\nEither of the two functions which z represents is. however, analytic\nexcept at = 0, and we can apply to them the theorems of this chapter;\nand the two functions are called ' branches of the many-valued\nfunction z'-.' There will be certain points in general at which two or\nmore branches coincide or at which one branch has an infinite limit;\nthese points are called ' branch-points.' Thus z- has a branch-point\nat; and, if we consider the change in z as z describes a circle\ncounter-clockwise round 0, we see that 6\n\n* Vxench, fonction entilre; Germa,n, game Funktion.\n\n%\n% 107\n%\n\nincreases by 27r, r remains unchanged, and either branch of the\nfunction passes over into the other branch. This will be found to be a\ngeneral characteristic of branch-points. It is not the purpose of this\nbook to give a full discussion of the properties of many-valued\nfunctions, as we shall always have to consider particular branches of\nfunctions in regions not containing branch- points, so that there will\nbe comparatively little difficulty in seeing whether or not Cauchy's\nTheorem may be applied.\n\nThus we cannot apply Cauchy's Theorem to such a function as z when the\npath of iutegi-ation is a circle surrounding tlie origin; but it is\npermissible to apply it to one of\n\nthe branches of z when the path of integration is like that shewn in §\n6 '24, for through- out the contour and its interior the function has\na single definite value.\n\nExample. Prove that if the different values of a, corresponding to a\ngiven value of z, are represented on an Argand diagram, the\nrepresentative points will be the vertices of an equiangular polygon\ninscribed in an equiangular spiral, the angle of the spiral being\nindependent of a.\n\\addexamplecitation{Math. Trip. 1899.}\n\nThe idea of the different braiickes of a function helps us to\nunderstand such a paradox as the following.\n\nConsider the function y = ' i\n\nfor which ~=x log x).\n\nAVhen x is negative and real, is not real. But if x is negative and of\nthe form\n\nP (where p and q are positive or negative integers), y is real.\n\nZ'j -f- 1\n\nIf therefore we draw the real c\\ irve\n\nwe have for negative values of ./ a set of conjugate points, one point\ncorresponding to each rational value of x with an odd denominator;\nand then we might think of proceeding to form the tangent as the limit\nof the chord, just as if the curve were continuous; and\n\nthus --, when derived from the inclination of the tangent to the axis\nof x, would appear\n\nto be real. The question thus arises, Why does the ordinary process of\ndifferentiation\n\ngive a non-real value for - ? The explanation is, that these conjugate\npoints do not all\n\narise from the same branch of the function y = x' . We have in fact\n\ny - 5\n\nwhere k is any integer. To each value of k corresponds one branch of\nthe function y. Now in order to get a real value of y when x is\nnegative, we have to choose a suitable value for k : and this value of\nk varies as we go from one conjugate point to an adjacent one. So the\nconjugate points do not represent values of y arising from the same\nbranch of the\n\nfunction y=x, and consequently we cannot expect the value of - when\nevaluated\n\nfor a definite branch to be given by the tangent of the inclination to\nthe axis of x of the line joining two arbitrarily close members of the\nseries of conjugate points.\n\n%\n% 108\n%\n\nREFERENCES.\n\nE. Goursat, Cours dJ Analyse, ii. (Paris, 1911), Chs. xiv and xvi.\n\nJ. Hadamard, La Serie de Taylor et son prolongement analytique\n(Scientia, 1901).\n\nE. LiNDELOF, Le Calmd des Residus (Paris, 1905).\n\nC. J. DE LA Vallee Poussin, Covrs d' Analyse Infinitesimale, i. (Paris\nand Louvain, 1914), Ch. X.\n\nE. BoREL, Lecons stir les Fonctions Entieres (Paris, 1900).\n\nG. N. Watson, Complex Integration and Cauchy's Theorem (Camb. Math.\nTracts, no. 15, 1914).\n\nMiscellaneous Examples.\n\n1. Obtain the expansion\n\n/(.)=/( ) + 2 1 -/ (- + -3-3-r/ ( -2-j + -25751- ' \\ \\ r-] ' and\ndetermine the circumstances and range of its vaUdity.\n\n2. Obtain, under suitable circumstances, the expansion\n\n+ .... (Corey, Ann. of Math. (2), i. (1900), p. 77.)\n\n3. Shew that for the series\n\n  1\n\n)i=o -r~\n\nthe region of convergence consists of two distinct areas, namely\noutside and inside a circle of radius unity, and that in each of these\nthe series represents one function and represents it completely.\n\n(Weierstrass, Berliner Monatsherichte., 1880, p. 731; Ges. Werke, 11.\n(1895), p. 227.)\n\n4. Shew that the function\n\n2 s\"'\n\ntends to infinity as 2- -exp i-niplm !) along the radius through the\npoint; where m is any integer and p takes the values 0, 1, 2, ..'.\n(ni I - 1).\n\nDeduce that the function cannot be continued beyond the unit circle.\n\n(Lerch, Sitz. BOhm. Acad., 1885-6, pp. 571-582.)\n\n5. Shew that, if z-- 1 is not a positive real number, then\n\n-\". .s:)\"<'-\")- /:'=-('-'- '-**-\n\n\\addexamplecitation{Jacobi and Scheibner.}\n\n%\n% 109\n%\n\n6. Shew that, if s - 1 is not a positive real number, then\n\n,,,, m, m(m+ ) to (m + 1) ... (to + ?i - 1)\n\n(1-2) - =l+-2 + - 2 \"\" +-+ -1 .\n\nn : J\n\n\\addexamplecitation{Jacobi and Scheibner.}\n\n7. Shew that, if z and 1-2 are not negative real numbers, then\n\n  Jo m+l [ m + 3 (m+3) ... (m + 27i- 1) J\n\n+ \"') (m+l)(w + 3)...(m + 27i-l)Jo ' -\n\n\\addexamplecitation{Jacobi and Scheibner.}\n\n8. If, in the expansion of (a + i2 + a22 )'\" by the multinomial\ntheorem, the remainder after n terms be denoted by R (2), so that\n\n(a4- i2 + a2S-)'\" = o + - i2 + -'-l2-\"\" + --- + n-iS\"'\"' + (s), shew\nthat\n\n/4(.) = ( + a.. + ..r j, - (a + .M+a, r \" '\n\n9. If (ao + i2 + a22 )\"\"'\"' /'(ao + i< + 2 -)'\"o?<\n\ny\n\n\\addexamplecitation{Scheibner.}\n\nbe expanded in ascending powers of 2 in the form\n\nJl2 + .4222+...,\n\nshew that the remainder after n-\\ terms is\n\n(ao + ai2 + a22 )~'\"\" I (ao + a, + a2 )'\" o .i-(2?'i + ? + 1) 2 -i\n\"\"'c C\n\n\\addexamplecitation{Scheibner*.}\n\n10. Shew that the series\n\nwhere X (2)= - 1 +2- f, + I\",- - + (- )\", '\n\nand where (2) is analytic near 2 = 0, is convergent near the point 2 =\n; and shew that if the sum of the series be denoted by/(2), then/(2)\nsatisfies the differential equation\n\n/'(--)=/( )-0(4\n\n(Pincherle, Rend, dei Lincei (5), v. (1896), p. 27.)\n\n11. Shew that the arithmetic mean of the squares of the moduli of all\nthe values of the series \"2 0, on a circle |2| = r, situated within\nits circle of convergence, is equal\n\n i=0\n\nto the sum of the squares of the moduli of the separate terms.\n\n(Gutzmer, Math. Ann. xxxii. (1888), pp. .596-600.)\n\n* The results of examples 5, 6 and 7 are special cases of formulae\ncontained in Jacobi's dissertation (Berlin, 182.5) published in bis\nGes. Werke, in. (1884), pp. 1-44. Jacobi's formulae were generalised\nby Scheibner, Lelpziger Berichte, xlv. (1893), pp. 432-443,\n\n%\n% 110\n%\n\n12. Shew that the series\n\n2 e-2(am) -m-l m = l\n\nconverges when | 2 | < 1; and that, when a > 0, the function which it\nrepresents can also be represented when | s ! < 1 by the integral\n\n/ay f\" e-\"\" dx n-J Jo ex\\ 2 x '\n\nand that it has no singularities except at the point z=l.\n\n(Lerch, Monatshefte fiir Math, und Phys. viii.) 13. Shew that the\nseries\n\n2\n\n\\ \\,, 2 r z\\ zj \\\n\n z + z )-V- 2 ( i\\ 2 \\ 2y'zi)(2v + iv'zif' iv-2v'z- i) 2v + 2v'z-'\nxf]'\n\nin which the summation extends over all integral values of v, v',\nexcept the combination (i' = 0, v' = 0), converges absolutely for all\nvalues of z except purely imaginary values; and that its sum is + 1\nor - 1, according as the real part of z is positive or negative.\n\n(Weierstrass, Berliner Monatsherichte, 1880, p. 735.)\n\n14. Shew that sin \\ u ( + -)[ can be expanded in a series of the type\n\na, + aiZ + aoy-+...+- + j, + ...,\n\nin which the coefficients, both of s\" and of z~'\\ are\n\n1 / 2t\n\n-- I sm (2m cos ) cos Ji o? . 2ir J )\n\nn=i n-z' + a-\n\nshew that/ (2) is finite and continuous for all real values of z, but\ncannot be expanded as a Maclaurin's series in ascending powers of z;\nand explain this apparent anomaly.\n\n[For other cases of failure of Maclaurin's theorem, see a posthumous\nmemoir by Cellerier, Bidl. des Set. Math. (2), xiv. (1890), pp.\n145-599; Lerch, Journal fiir Math. cm. (1888), pp. 126-138;\nPringsheim, Math. Ann. XLii. (1893), pp. 153-184; and Du Bois\nReymond, Miinehener Sitzungsberichte, vi. (1876), p. 235.]\n\n16. If f(z) be a continuous one- valued function of z throughout a\ntwo-dimensional region, and if\n\n   f z)dz =\n\nh\n\nfor all closed contours C lying inside the region, then f(z) is an\nanalytic function of z throughout the interior of the region.\n\n[Let a be any point of the region and let\n\nF z)=\\'f z)dz\n\nJ a\n\nIt follows from the data that F(z) has the unique derivate f z). Hence\nF z) is analytic \\hardsectionref{5}{1}) and so \\hardsubsectionref{5}{2}{2}) its derivate /(z) is also\nanalytic. This important converse of Cauchy's theorem is due to\nMorera, Rendiconti del R. 1st. Lomhardo Milano), xxil. (1889), p.\n191.]\n", "meta": {"hexsha": "d62f3109bc5488214a9cb4b35ca12f2dd3fcb424", "size": 60363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch05.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-ch05.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-ch05.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": 29.4741210938, "max_line_length": 136, "alphanum_fraction": 0.6945479847, "num_tokens": 18465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6899471009775578}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{pylatex}\n\\usepackage{mpllatex}\n\\usepackage{geometry}\n\\usepackage{amsmath}\n\\usepackage{pgf}\n\\usepackage{caption}\n\\usepackage{hyperref}\n\\usepackage{examples}\n\n% portrait\n\\geometry{papersize={210mm,297mm},hmargin=2cm,tmargin=1.0cm,bmargin=1.5cm}\n\\parskip=8pt plus 4pt minus 2pt\n\n% landscape\n% \\geometry{papersize={297mm,210mm},hmargin=2cm,tmargin=1.0cm,bmargin=1.5cm}\n% \\parskip=6pt plus 3pt minus 2pt\n\n\\begin{document}\n\n\\section*{A mixed Maple-Python example}\n\nThis example demonstrates a cooperative effort where Maple is used to do the analytic computations while Python is used to plot the data.\n\nThe example chosen here is to find and plot the solution to the boundary value problem defined by\n\\begin{align*}\n   \\frac{d^2y}{dx^2} + 2 \\frac{dy}{dx} +10 y = 0\\quad\\quad\\text{with }y(0)=3,\\> y'(0)=0\n\\end{align*}\n\nThis example requires two passes, once for Maple and once for Python (and in that order). This example can be run using\n\n\\vspace{5pt}\n\n\\begin{lstlisting}\n   mpllatex.sh -x -i mixed\n   pylatex.sh  -x -i mixed\n   pdflatex          mixed\n\\end{lstlisting}\n\n\\vspace{5pt}\n\nNote that the last pair of commands could also be combined as {\\small\\tt pylatex.sh -i mixed}.\n\n\\subsection*{The Maple code}\n\nHere Maple is used to first find the general solution of th differential equation. The boundary conitions are then imposed and finally a uniform sampling of the solution is written to a file for later use by Python and Matplotlib.\n\n\\begin{maple}\n   # a second order ode\n   ode := diff(y(x), x, x) + 2*diff(y(x),x) + 10*y(x) = 0:  # mpl (ans.101,ode)\n\n   # find the general solution\n   ans := dsolve(ode):                     # mpl (ans.102,ans)\n\n   # set initial conditions\n   ics := y(0) = 3, (D(y))(0) = 0:\n   tmp := {ics}:                           # mpl (ans.103,tmp)\n\n   # find the particular solution\n    f := rhs(dsolve([ics, ode])):          # mpl (ans.104,f)\n   df := diff(f,x):                        # mpl (ans.105,df)\n\n    y := x -> f:\n   dy := x -> df:\n\n   # now sample y and dy at selected points\n   a,b,n := 0.0,2.0*Pi,300:        # domain and number of samples\n   dx := (b-a)/n:                  # uniform step\n\n   fd := fopen (\"mixed.txt\", WRITE):\n   for i from 0 to n by 1 do\n      x := a + dx*i:\n      fprintf(fd,\"% .10e % .10e % .10e\\n\",x,evalf(y(x)),evalf(dy(x))):\n   end do:\n   fclose(fd):\n\\end{maple}\n\nThe general solution of the differential equation is\n\\begin{equation*}\n  \\mpl{ans.102}\n\\end{equation*}\nwhile the particular solution satifying the boundary conditions is given by\n\\vspace{5pt}\n\\begin{align*}\n    y(x) &= \\mpl{ans.104}\n\\end{align*}\n\n\\subsection*{The Python code}\n\nThis is a straighforward use of Matplotlib to plot two functions. The code reads the datafile created previously by Maple and then calls Matplotlib to plot that data.\n\n\\begin{python}\n   import numpy as np\n   import matplotlib.pyplot as plt\n\n   plt.matplotlib.rc('text', usetex = True)\n   plt.matplotlib.rc('grid', linestyle = 'dotted')\n   plt.matplotlib.rc('figure', figsize = (5.5,4.1)) # (width,height) inches\n\n   x, y, dy = np.loadtxt ('mixed.txt', unpack=True)\n\n   plt.plot (x,y)\n   plt.plot (x,dy)\n\n   plt.xlim (0.0,4.0)\n\n   plt.legend(('$y(x)$', '$dy(x)/dx$'), loc = 0)\n   plt.xlabel('$x$')\n   plt.ylabel('$y(x),\\> dy/dx$')\n   plt.grid(True)\n   plt.tight_layout(0.5)\n\n   plt.savefig('mixed-fig.pdf')\n\\end{python}\n\n\\vspace{10pt}\n\n\\begin{minipage}{\\textwidth}\n   \\centering\n   \\IfFileExists{mixed-fig.pdf}%\n   {\\includegraphics[width=0.75\\textwidth]{mixed-fig.pdf}}{Failed to create pdf plot.}\n   \\captionof{figure}{The function and its derivative.}\n\\end{minipage}\n\n\\end{document}\n", "meta": {"hexsha": "c01344e66673fb98280e9344526126a1ff537ab7", "size": 3636, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maple/examples/mixed.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": "maple/examples/mixed.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": "maple/examples/mixed.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.8571428571, "max_line_length": 230, "alphanum_fraction": 0.6575907591, "num_tokens": 1139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.6899470996432443}}
{"text": "\\documentclass{article}\r\n\\begin{document}\r\n\\section*{Quadratic equations}\r\nThe quadratic equation\r\n\\begin{equation}\r\n  \\label{quad}\r\n  ax^2 + bx + c = 0,\r\n\\end{equation}\r\nwhere \\( a, b \\) and \\( c \\) are constants and \\( a \\neq 0 \\),\r\nhas two solutions for the variable \\( x \\):\r\n\\begin{equation}\r\n  \\label{root}\r\n  x_{1,2} = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}. \r\n\\end{equation}\r\nIf the \\emph{discriminant} \\( \\Delta \\) with\r\n\\[\r\n  \\Delta = b^2 - 4ac\r\n\\]\r\nis zero, then the equation (\\ref{quad}) has a double solution:\r\n(\\ref{root}) becomes\r\n\\[\r\n  x = - \\frac{b}{2a}.\r\n\\]\r\n\\end{document}", "meta": {"hexsha": "613c02e4af12c450d7154b52e47be1ea2ac70773", "size": 585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter_09_-_Writing_Math_Formulas/01_equations.tex", "max_stars_repo_name": "PacktPublishing/LaTeX-Beginner-s-Guide---Second-Edition", "max_stars_repo_head_hexsha": "26931e5c56bcfdf3d7a924ab6c2ae2f3f5c54332", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2021-08-31T19:46:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T10:00:53.000Z", "max_issues_repo_path": "Chapter_09_-_Writing_Math_Formulas/01_equations.tex", "max_issues_repo_name": "PacktPublishing/LaTeX-Beginner-s-Guide---Second-Edition", "max_issues_repo_head_hexsha": "26931e5c56bcfdf3d7a924ab6c2ae2f3f5c54332", "max_issues_repo_licenses": ["MIT"], "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_09_-_Writing_Math_Formulas/01_equations.tex", "max_forks_repo_name": "PacktPublishing/LaTeX-Beginner-s-Guide---Second-Edition", "max_forks_repo_head_hexsha": "26931e5c56bcfdf3d7a924ab6c2ae2f3f5c54332", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-08-10T18:01:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T14:46:25.000Z", "avg_line_length": 24.375, "max_line_length": 63, "alphanum_fraction": 0.6034188034, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6898640349995558}}
{"text": "%!TEX root = index.tex\n\\section{Solving the Quartic}\n\\epigraph{The purpose of computation is insight, not numbers.}{Richard Hamming}\n\nMoving on to the fourth degree, the idea is the same. The method gets much more complicated, and isn't quite useful in practice. You should aim at understanding the ideas and move on.\n\nConsider a \\emph{depressed quartic} with roots $ \\gamma_1, \\gamma_2, \\gamma_3, \\gamma_4$: \n\\begin{align*}\n  P(x) = x^4 + a_2 x^2 + a_1 x + a_0\n\\end{align*}\nAs before, to simplify the calculations we're forcing $$ 0 =\\gamma_1+ \\gamma_2+ \\gamma_3+ \\gamma_4$$\nIf $ a_0 = 0$ we can factor out an $ x$ and reduce the quartic to a cubic. So we'll assume this is not the case.\n\\begin{questions}\n  \\item Express $ a_2, a_1, a_0$ in terms of $ \\gamma_1, \\gamma_2, \\gamma_3, \\gamma_4$.\n\\end{questions}\nWe need to find an intermediate third degree polynomial with roots $ \\lambda_1, \\lambda_2, \\lambda_3$ which have \\emph{fewer} symmetries than $ a_2, a_1, a_0$.\n\n... and here they are: \n  \\begin{align*}\n    \\lambda_1 &= \\gamma_1 \\gamma_2 + \\gamma_3 \\gamma_4 \\\\\n    \\lambda_2 &= \\gamma_1 \\gamma_3 + \\gamma_2 \\gamma_4 \\\\\n    \\lambda_3 &= \\gamma_1 \\gamma_4 + \\gamma_2 \\gamma_3 \n  \\end{align*}\n\\begin{questions}[resume]\n  \\item \\begin{enumerate}\n    \\item How many ways are there to permute the 4 roots $ \\gamma_1, \\gamma_2, \\gamma_3, \\gamma_4$?\n    \\item Of these, which permutations leave \\emph{all} the $\\lambda_i$'s unchanged?\n    \\item What do the rest of the permutations do to the $\\lambda_i$'s?\n    \\item Conclude that $\\lambda_1 + \\lambda_2 + \\lambda_3$, $\\lambda_1\\lambda_2 + \\lambda_2\\lambda_3 + \\lambda_3\\lambda_1$ and $\\lambda_1 \\lambda_2 \\lambda_3$ are symmetric in $ \\gamma_1, \\gamma_2, \\gamma_3, \\gamma_4$.\n  \\end{enumerate}\n\\end{questions}\n\n\n\\newpage\nBy the previous exercise the coefficients of the cubic polynomial whose roots are $ \\lambda_1, \\lambda_2, \\lambda_3$ are polynomials in  $ a_2, a_1, a_0$.\n\\begin{questions}[resume]\n  \\item Verify the following identities (only for the intrepid)\n    \\begin{align*}\n      a_2 &= \\lambda_1 +\\lambda_2 +\\lambda_3\\\\\n      -4 a_0 &= \\lambda_1\\lambda_2 +\\lambda_1 \\lambda_3 + \\lambda_2 \\lambda_3\\\\\n      a_1^2 - 4a_0 a_2&=\\lambda_1 \\lambda_2 \\lambda_3\n    \\end{align*}\n    and hence $ \\lambda_1, \\lambda_2, \\lambda_3$ are the roots of\n    \\begin{align*}\n      R(x) = x^3 - a_2 x^2 - 4a_0x + (4a_0 a_2 - a_1^2)\n    \\end{align*}\n\\end{questions}\n\nThus we've reduced the problem from a quartic to a cubic. The last step is recovering $ \\gamma_1, \\gamma_2, \\gamma_3, \\gamma_4$ from $ \\lambda_1, \\lambda_2, \\lambda_3$. For this notice that \n  \\begin{align*}\n    \\lambda_1 &= \\gamma_1 \\gamma_2 + \\gamma_3 \\gamma_4 \\\\\n    a_0 &= \\gamma_1 \\gamma_2 \\gamma_3 \\gamma_4\n  \\end{align*}\nand hence $ \\gamma_1 \\gamma_2$ and $ \\gamma_3 \\gamma_4$ are the roots of the quadratic $x^2 - \\lambda_1 x + a_0$. Similarly for the others.  We have the identities\n  \\begin{align*}\n    \\lambda_1^2 = (\\lambda_1\\lambda_2).(\\lambda_1\\lambda_3).(\\lambda_1\\lambda_4)/a_0\n  \\end{align*}\nwhich we can use to find $ \\lambda_1^2$ and then test the two possible square roots to see which one works. The other $ \\lambda_i$'s can be found by inspection.\n\n\\begin{questions}[resume]\n  \\item Find the roots of the following polynomials:\n    \\begin{enumerate}\n      \\item $x^4 - 1$\n      \\item $x^4 + 1$\n    \\end{enumerate}\n\\end{questions}\n\n\n", "meta": {"hexsha": "a0a099844f4042f50501e2164b4bfcdbecd6d160", "size": 3365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "The_Quartic.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": "The_Quartic.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": "The_Quartic.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": 48.768115942, "max_line_length": 219, "alphanum_fraction": 0.690936107, "num_tokens": 1194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.6898267591398638}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath, amssymb, amsthm}\n\\usepackage{gensymb}\n\\usepackage[nodayofweek]{datetime}\n\n\\usepackage{tikz}\n\n% Set size of text area with total parameter\n\\usepackage[a4paper, total={135mm, 255mm}]{geometry}\n\n\\title{Complex Binomial Sequences}\n\\author{Dyson}\n\\date{\\today}\n\n\\newcommand{\\abs}[1]{\\left| #1 \\right|}\n\\newcommand{\\opi}{(1 + i)}\n\\newcommand{\\mopi}{(-1 + i)}\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\nThroughout this paper, all $n \\in \\mathbb{N}$ and $0 \\in \\mathbb{N}$.\n\n\\section{Looking at $\\opi^n$}\n\nThe sequence $\\opi^n$ creates an interesting graph when plotted sequentially on an Argand diagram.\n\n\\begin{center}\n\\resizebox{135mm}{!}{\n\\begin{tikzpicture}\n    \\begin{scope}[thick,font=\\scriptsize]\n        % Axes\n        \\draw (-18,0) -- (18,0);\n        \\draw (0,-18) -- (0,18);\n\n        % Axes labels\n        \\foreach \\n in {-17,...,-1,1,2,...,17}{\n            \\draw (\\n,-3pt) -- (\\n,3pt);\n            \\draw (-3pt,\\n) -- (3pt,\\n);\n        }\n\n        % Draw the actual plot of the sequence\n        \\draw (1,0) -- (1,1) -- (0,2) -- (-2,2) -- (-4,0) -- (-4,-4) -- (0,-8) -- (8,-8) -- (16,0) -- (16,16);\n    \\end{scope}\n\\end{tikzpicture}\n}\n\\end{center}\n\nInitially, I confused this shape for a coarse approximation of a Golden Spiral. If this were the case, then the ratio between the moduli of successive elements of the sequence would tend to $\\phi$ as $n$ grows to $\\infty$. Here's an example:\n\n\\begin{align*}\n\\dfrac{\\abs{\\opi^3}}{\\abs{\\opi^2}} = \\dfrac{\\abs{-2 + 2i}}{\\abs{2i}} = \\dfrac{\\sqrt{8}}{2} = \\dfrac{2\\sqrt{2}}{2} = \\sqrt{2}\n\\end{align*}\n\nThe ratio is $\\sqrt{2}$, which is not $\\phi$. This ratio is true for all $\\dfrac{\\abs{\\opi^{n + 1}}}{\\abs{\\opi^n}}$, meaning this shape is not a Golden Spiral.\n\n\\begin{proof}\nLet $z_1$ and $z_2$ be two consecutive elements of the sequence $\\opi^n$.\n\nWe want the ratio between the moduli of these elements, $\\dfrac{\\abs{z_2}}{\\abs{z_1}}$.\n\nLet $f(n) = \\dfrac{\\abs{\\opi^{n + 1}}}{\\abs{\\opi^n}}$.\n\nWe can easily show that $f(0) = \\dfrac{\\abs{\\opi^1}}{\\abs{\\opi^0}} = \\dfrac{\\abs{1 + i}}{\\abs{1}} = \\sqrt{2}$.\n\nWe can then show:\n\\begin{gather*}\nf(n) = \\dfrac{\\abs{\\opi^{n + 1}}}{\\abs{\\opi^n}}\\\\[0.5em]\n= \\dfrac{\\abs{\\opi\\opi^n}}{\\abs{\\opi\\opi^{n - 1}}} = \\dfrac{\\abs{\\opi}}{\\abs{\\opi}} \\times \\dfrac{\\abs{\\opi^n}}{\\abs{\\opi^{n - 1}}}\\\\[0.5em]\n= 1 \\times \\dfrac{\\abs{\\opi^n}}{\\abs{\\opi^{n - 1}}} = f(n - 1)\n\\end{gather*}\n\nWe can do this because for $z, w \\in \\mathbb{C}$, $\\abs{zw} = \\abs{z} \\times \\abs{w}$.\n\nWe've now shown that for $n > 0$, $f(n) = f(n - 1)$. This always recurs to the base case of $f(0)$ and means that all $f(n) = \\sqrt{2}$.\n\nThis means that the ratio of the moduli between any two consecutive members of the sequence $\\opi^n$ is always $\\sqrt{2}$.\n\\end{proof}\n\n\\newpage\n\n\\section{Looking at $\\mopi^n$}\n\nIf we look at the series $(1 - i)^n$ and plot it sequentially on an Argand diagram, then we get the same spiral as when plotting $\\opi$ but reflected in the real axis.\n\nHowever, if we look at $\\mopi^n$, then we get something completely different.\n\n\\begin{center}\n    \\resizebox{135mm}{!}{\n        \\begin{tikzpicture}\n        \\begin{scope}[thick,font=\\scriptsize]\n        % Axes\n        \\draw (-18,0) -- (18,0);\n        \\draw (0,-18) -- (0,18);\n\n        % Axes labels\n        \\foreach \\n in {-17,...,-1,1,2,...,17}{\n            \\draw (\\n,-3pt) -- (\\n,3pt);\n            \\draw (-3pt,\\n) -- (3pt,\\n);\n        }\n\n        % Draw the actual plot of the sequence\n        \\draw (1,0) -- (-1,1) -- (0,-2) -- (2,2) -- (-4,0) -- (4,-4) -- (0,8) -- (-8,-8) -- (16,0) -- (-16,16);\n        \\end{scope}\n        \\end{tikzpicture}\n    }\n\\end{center}\n\nThis is a very interesting plot. We can use a very similar proof to the one at the end of \\S1 to prove that the ratio between the moduli of any two elements of the sequence is $\\sqrt{2}$. However, the more interesting thing with this sequence is not the moduli of the elements, but the arguments. How does the angle of each point relative to the origin change?\n\nLooking at the sequence $\\arg(n)$ (in degrees) for $n \\in \\{0,1,...,10\\}$, we get\n% This text environment is to add spaces between each element. Yes, a text env in a math env is a bodge. Sue me.\n$$\\text{0, 135, 270, 405, 540, 675, 810, 945, 1080, 1215, 1350}$$\n\nIf we take each of these elements mod 360, we get\n$$\\text{0, 135, 270, 45, 180, 315, 90, 225, 0, 135, 270}$$\n\nThe arguments of the members of $\\mopi^n$ rotate around the unit circle with a period of 8. This is the same period as $\\opi^n$.\n\nBut, despite the two sequences having the same ratio of moduli, and the same rotation period, this second sequence creates a completely different graph. This is because the rotation of each term of $\\opi^n$ relative to the last is 45. This means that it takes a whole rotation of 8 terms to get back to the initial angle.\n\nHowever, the relative rotation of $\\mopi^n$ is 135, meaning that we after 3 terms, we've rotated $45\\degree$ from the initial value. This creates a very interesting pattern of triangles on the plot.\n\n\\end{document}\n", "meta": {"hexsha": "65e922b28992b333cdfa2b1442dd140502c89c31", "size": 5185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Investigations/Complex_Binomial_Sequences.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": "Investigations/Complex_Binomial_Sequences.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": "Investigations/Complex_Binomial_Sequences.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": 39.5801526718, "max_line_length": 360, "alphanum_fraction": 0.6273866924, "num_tokens": 1746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.6898267523682203}}
{"text": "\n\\subsection{Integration by parts}\n\nWe have:\n\n\\(\\dfrac{\\delta y}{\\delta x}=f(x)g(x)\\)\n\nWe want that in terms of \\(y\\).\n\nWe know from the product rule of differentiation:\n\n\\(y=a(x)b(x)\\)\n\nMeans that:\n\n\\(\\dfrac{\\delta y}{\\delta x}=a'(x)b(x)+a(x)b'(x)\\)\n\nSo let's relabel \\(f(x)\\) as \\(h'(x)\\)\n\n\\(\\delta\\)\n\n\\(\\dfrac{\\delta y}{\\delta x}=h'(x)g(x)\\)\n\n\\(\\dfrac{\\delta y}{\\delta x}+h(x)g'(x)=h'(x)g(x)+h(x)g'(x)\\)\n\n\\(y+\\int h(x)g'(x)=\\int h'(x)g(x)+h(x)g'(x)\\)\n\n\\(y+\\int h(x)g'(x)=h(x)g(x)\\)\n\n\\(y=h(x)g(x)-\\int h(x)g'(x)\\)\n\nFor example:\n\n\\(\\dfrac{\\delta y}{\\delta x}=x.\\cos(x)\\)\n\n\\(f(x)=\\cos(x)\\)\n\n\\(g(x)=x\\)\n\n\\(h(x)=\\sin(x)\\)\n\n\\(g'(x)=1\\)\n\nSo:\n\n\\(y=x\\int \\cos(x) dx-\\int \\sin(x)dx\\)\n\n\\(y=x\\sin(x)-\\cos(x)+c\\)\n\n", "meta": {"hexsha": "44e3b79753afeb195f229883b1ec28d2fbc061f3", "size": 704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/integration/05-01-integrationParts.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/05-01-integrationParts.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/05-01-integrationParts.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.08, "max_line_length": 60, "alphanum_fraction": 0.5042613636, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.689751780592326}}
{"text": "%&LaTeX\n\n\\section{Let's Get Physical}\n\nIn this lab, you will use Matlab to explore the effects of summing\nsinusoids. You will then investigate how a physical signal can be\nconsidered to be composed of a sum of sinusoids --- its \\emph{Fourier\n  series}. You will be using the Matlab \\texttt{AnalogSignal} class\nand functions at\n\\url{http://faculty.washington.edu/stiber/pubs/Signal-Computing/}.\n\n\\subsection{Beating}\n\nIn this section, you will use the Matlab \\texttt{AnalogSignal} class\n(described previously in lab~1 and its\nfigure~\\ref{fg:analogsignal-help}) to simulate an analog signal\ngenerator. The constructor takes the following arguments:\n\\begin{lstlisting}[style=Matlab-editor,basicstyle=\\mlttfamily\\small]\n% AnalogSignal(type, amplitude, frequency, dur)\n%    Where:\n%    type = 'sine', 'cosine', 'square', 'sawtooth', or 'triangle'\n%    amplitude = signal amplitude\n%    frequency = signal frequency\n%    dur = signal duration\n\\end{lstlisting}\n\nRemember that, though an \\texttt{AnalogSignal} is simulating an analog\nsignal, in Matlab all functions are sampled at discrete points in\ntime. The crufty details of this are hidden away in the class's\nimplementation. Remember also that you can always plot an\n\\texttt{AnalogSignal} to see what you have; include such figures in\nyour report \n\n\\paragraph{Step 1.1} Verify that you can get a triangle wave. What is\nthe code to generate and plot a triangle wave ranging from -1 to 1\nVolts with a frequency of 10Hz and a duration of 1 second?\n\n\\paragraph{Step 1.2} Next, verify that you can generate a sine wave of\n1 second duration at a frequency of 440Hz, ranging from -1 to +1. What\nis the Matlab code to do this? Use the \\texttt{AnalogSignal}\n\\texttt{soundsc} method to play this as a sound. This pitch\ncorresponds to ``standard A'' on a musical scale --- A above middle\nC. Use the Matlab \\texttt{set(gca, 'XLim', [\\itshape{Xmin},\n  \\itshape{Xmax}])} function call to set the X axis limits so that the\nwaveform is apparent (i.e., you're not just plotting a solid blob).\n\n\\paragraph{Step 1.3} Generate three sine waves of identical range and\nduration, but with frequencies of 442, 444, and 448 Hz. Next, generate\nthe three sums of 440Hz and each of these new signals separately (so,\n440Hz + 442Hz, 440Hz + 444Hz, and 440Hz + 448Hz) to generate beating\nakin to tuning an instrument against the 440Hz standard. Play each sum\nsignal; can you hear the beating? Plot each sum signal for its full 1s\nduration. The beating ``envelope'' should be obvious. What is the beat\nfrequency in each case? How does the beat frequency and amplitude\nrelate to the textbook discussion of beating?\n\n\n\\subsection{Fourier series representation of a physical signal}\n\n\n\\paragraph{Step 2.1} Recall that any periodic signal can be\nrepresented as a sum of harmonic sinusoids.  The amplitudes of these\nharmonics is collectively known as the Fourier Series. It may at first seem like\nsums of sinusoids would be poor approximations of real periodic\nsignals, but this is not the case. We can illustrate this using a\ntriangle wave. The formula for synthesis of a triangle wave with\nfrequency $\\omega_0$ is a sum of harmonically related sine waves (its\nFourier series):\n  \\[\n  x(t) = \\sum_{k=0}^{\\infty}\n  \\left( \n    \\underbrace{ \\frac{8}{\\pi^2} \\frac{(-1)^k}{(2k+ 1)^2} }_{ \\text{amplitude} } \n    \\underbrace{ \\sin((2k+1)\\omega_0 t) }_{ (2k+1)^{th}\\text{ harmonic} } \n  \\right)\n  \\]\n  In this case, in the analog domain, we are dealing with frequencies\n  in Hz, and so $\\omega_0 = 2\\pi f_0$. Notice that the Fourier Series\n  of the triangle wave only uses odd harmonics (i.e., the only\n  non-zero frequencies are $(2k+1)\\omega_0=\\omega_0, 3\\omega_0,\n  5\\omega_0 \\cdots$). Also notice that the resulting wave will have zero\n  mean because there is no ``DC'' term (i.e., $2k+1 \\neq 0$ for any\n  integer k).\n\n  Write a Matlab script that approximates a triangle wave by summing\n  together the first 7 harmonics of its Fourier series; plot the\n  resultant signal (i.e., use $f_0$, $2f_0$, $3f_0$, $\\cdots 7f_0$,\n  where $f_0=$10 Hz). How does this signal compare to the triangle\n  wave computed directly in the previous step?\n\n\n\n\\paragraph{Step 2.2} Another way to view a signal is in the\n\\emph{frequency domain}. For a signal expressed in terms of its\nFourier series, the frequency representation is merely the\ncoefficients of the harmonics. Write a Matlab function or script to\ncompute and plot the spectrum of a triangle wave. You may find the\nMATLAB function \\texttt{stem} useful.  Note that you are \\emph{not}\nbeing asked to plot the triangle wave as a function of time; you\nshould plot the amplitudes of the component sinusoids as a function of\nthose sinusoids' frequencies (like the vertical lines in textbook\nfigure~1.12).  Use your code to plot the spectrum of the triangle wave\nfrom the previous step (first 7 harmonics).\n", "meta": {"hexsha": "d1898b8ce00720907c3e90a51e2103a7442eab02", "size": 4850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Matlab Labs/lab2/lab2.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/lab2/lab2.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/lab2/lab2.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": 47.0873786408, "max_line_length": 81, "alphanum_fraction": 0.753814433, "num_tokens": 1351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6896397552180165}}
{"text": "\\section{Type classes}\n\\label{sec:typeclasses}\n\nThe first part of this section will give a short description of the concept of a type class. The second part will describe monoids in general and the type class \\verb|Monoid|.\n\nThe concept of a type class was introduced as a construct that supports overloaded functions and \\emph{\\gls{adhoc_polymorphism}} \\cite{Wadler}. Overloaded functions can be used with a variety of types, but with different definitions for the different types. For example, the function calls \\verb|show 1| and \\verb|show \"hello\"| use different \\glspl{function-definition}. The function \\verb|show 1| is of type \\verb|Int -> String| and \\verb|show \"hello\"| is of type \\verb|String -> String|. The definition used depends on the type of the argument.  The next section will describe \\gls{adhoc_polymorphism} and the relation to type classes in more detail.\n\n\\subsection{Polymorphism and type classes}\n\\label{sec:polymorphism}\n%%In this section we will describe relation between type classes and polymorphism.\nThere are two types of polymorphism in Haskell \\cite{Cardelli}: Parametric polymorphism and \\gls{adhoc_polymorphism}. Type classes are used for \\gls{adhoc_polymorphism}.\n\\begin{description}\n\\item[Parametric polymorphism] refers to functions which work over more than one type. For example, the library function \\verb|length| returns the length of a list \\verb|[]| that contains items of arbitrary type. It can be used to calculate the length of a list of integers, a list of strings, a list of booleans, etc. There are no constraints. The type of \\verb|length| is\n\\begin{verbatim}\nlength :: [t] -> Int\n\\end{verbatim}\n\\verb|t| is a \\emph{type variable}. That is, for any type \\verb|t| the function \\verb|length| has type \\verb|[t] -> Int|. A type that contains a type variable is called \\emph{polymorphic}. Hence, \\verb|length| is a polymorphic type.\nThe \\verb|length| function can be used with any type but it has a \\emph{single} definition.  At compile time, the type variables are substituted with a concrete type. For example\n\\verb|[Int] -> Int|. \n\\item[Ad hoc polymorphism] is a synonym for function overloading or operator overloading. An overloaded function uses different function definitions depending on the types of the arguments. Suppose we want to define a function that converts a list containing items of arbitrary type (\\verb|[t]|) to a string. We would write a function with the following \\gls{typesignature}:\n\\begin{verbatim}\nshowlist :: [t] -> String\n\\end{verbatim}\nIt takes a list of arbitrary type \\verb|t| and returns a string. The definition could look like this:\n\\begin{verbatim}\nshowlist [] = \"\"\nshowlist (x:xs) = show x ++ showlist xs\n\\end{verbatim}\nWe need a way to make sure that the function \\verb|show| is defined for the type of the value \\verb|x|. \\verb|show| can't be a polymorphic type because the conversion depends on the type. There's no single definition that can convert an arbitrary type to a string. \n\nThere's a set of types. \\verb|show| is defined over all members of this set. This set is called a type class. The type class \\verb|Show| for example contains all types that can be converted to a string with the function \\verb|show|. In order to prevent the application of the function \\verb|showlist| with an argument that isn't a member of the type class \\verb|Show|, we must constraint the type variable in the type signature declaration \\verb|t|:\n\\begin{verbatim}\nshowlist :: Show t => [t] -> String\n\\end{verbatim}\n\\end{description}\n\nFunctions declared by the type class are defined over all members of the type class. And certain type classes exhibit properties that every definition of the corresponding functions must obey.\n\n\\subsection{Monoid}\n\\label{sec:monoid}\n\nIn mathematics, a \\gls{monoid} is an algebraic structure with single associative binary operation and an identity element. Monoids are semigroups with identity \\cite{wiki:monoid} \\cite{renshaw}. Several elements of a monoid can always be reduced to a single element by applying the corresponding binary operator. It doesn't matter in which order we apply the operator, the result is always the same. This is called \\emph{\\gls{associativity}}. The set of elements has an identity element. For example, the set of natural numbers $\\mathbb{N}$ form a monoid under multiplication.  The number 1 is the identity element. Multiplication of the identity and any other number $x$ results always in $x$.\n\nIn Haskell there is a type class for monoids. Types that form a monoid can become part of the \\verb|Monoid| type class. For example, the type list \\verb|[]| forms a monoid. Two values of type list can always concatenated to another list with the \\verb|++| operator. The empty list \\verb|[]| is the identity element. \n\nThe example in section \\ref{sec:example} shows a plugin system that contains a monoid. Plugins can be composed with a binary operator. An arbitrary number of plugins can be composed to a single plugin. Because the composition operator is associative, plugins can be evaluated in arbitrary order.\n\n\\subsubsection{Functions of the type class monoid}\n\nMembers of the type class \\verb|Monoid| have to implement the functions \\verb|mempty| and \\verb|mappend| amongst others (see appendix \\ref{sec:monoiddefinition} for a complete declaration).\nThese functions have the following type signature declaration.\n\\begin{verbatim}\n    mempty :: m\n    mappend :: m -> m -> m\n\\end{verbatim}\nThe type variable \\verb|m| is the type of the corresponding monoid.\n\\verb|mempty| returns the identity value. \\verb|mappend| is the binary function that takes two values of the same type and returns another value of that type. \n\nThe type class \\verb|Monoid| exhibits several laws. We will only describe the one that we will prove in the example of section \\ref{sec:example}, the \\emph{left identity law}.\nWhen making monoid instances, we need to make sure that \\verb|mempty| acts like the identity with respect to the \\verb|mappend| function. This property can be expressed with the following equation:\n\\begin{equation}\n  \\label{eq:firstmonoidlaw}\n  \\text{mappend}(\\text{mempty}, x) = x\n\\end{equation}\nEquation \\ref{eq:firstmonoidlaw} states that \\verb|mempty| has to behave like the identity with respect to \\verb|mappend|. When \\verb|mappend| is applied with the identity and an other element \\verb|x| of the monoid, it returns \\verb|x|.\n\n\\subsubsection{Example monoid implementation}\n\nThere is a useful property of the \\verb|Applicative| type class with respect to the \\verb|Monoid| type class (the \\verb|Applicative| type class is described in more detail in the appendix, section \\ref{sec:applicatives}). The example in section \\ref{sec:example} will use this property. If \\verb|f| is an \\verb|Applicative| and \\verb|b| is a \\verb|Monoid| then \\verb|f b| is also a \\verb|Monoid|. If a type is part of the \\verb|Applicative| type class and the type contains a \\verb|Monoid| we can create a \\verb|Monoid| instance with the implementation in listing \\ref{lst:monoidinstance1}. Figure \\ref{fig:applicative_monoid} illustrates this property.\n\n\\begin{figure}\n  \\centering\n     \\includegraphics[width=0.7\\textwidth]{monoid}\n  \\caption{An {\\ttfamily Applicative} that encapsulates a {\\ttfamily Monoid} is a {\\ttfamily Monoid}}\n  \\label{fig:applicative_monoid}\n\\end{figure}\n\n\\lstset{\nbasicstyle=\\ttfamily,\ncolumns=fullflexible,\nkeepspaces=true,\ncaptionpos=b\n}\n\\begin{lstlisting}[caption={{\\ttfamily Monoid} instance implementation of {\\ttfamily IO}},label={lst:monoidinstance1}]\n\n\n\n{-# LANGUAGE FlexibleInstances #-} \nimport Data.Monoid\nimport Control.Applicative \n\ninstance (Applicative f, Monoid a) => Monoid (f a) where\n    mempty = pure mempty\n    mappend = liftA2 mappend\n\\end{lstlisting}\n\n\\verb|mempty| is of type \\verb|f a| . Hence \\verb|pure mempty| has to be of type \\verb|f a|.\nAs \\verb|f| is an \\verb|Applicative|, it implements \\verb|pure|. The type of \\verb|pure| is \\verb|a -> f a| (see appendix \\ref{sec:applicatives}). We call \\verb|pure| with \\verb|mempty| of type \\verb|a|. We know that \\verb|a| is part of \\verb|Monoid| because of the type constraints. The compiler will use \\verb|mempty| of \\verb|a|. \\verb|liftA2| is an utility function of \\verb|Applicative|. It encapsulates the \\verb|mappend| function in an applicative functor. \n\nIn section \\ref{sec:example} we prove that the \\gls{function-definition} of listing \\ref{lst:monoidinstance1} obeys the first monoid law formed by equation \\ref{eq:firstmonoidlaw} with  the verification technique equational reasoning.\n\n\n", "meta": {"hexsha": "7345550355cef0bf1daed4219991494ef06aea64", "size": 8521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "typeclass.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": "typeclass.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": "typeclass.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": 82.7281553398, "max_line_length": 694, "alphanum_fraction": 0.7688064781, "num_tokens": 2177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8152324871074607, "lm_q1q2_score": 0.6896397507841183}}
{"text": "\\section{Polynomials}\n\\subsection{Definition and Basics}\nA polynomial is defined as $P(x) = a_nx^n + a_{n-1}x^{n-1} + \\cdots + a_2x^2 + a_1x + a_0$ \nwith names corresponding to their degree (constant, linear, quadratic, cubic, quartic).\n\nThe factored form is written as $P(x) = a(x-r)(x-p)\\cdots(x-q)$.\nThe simplest and most useful polynomial is the quadratic. It can be written as $ax^2+bx+c$ and factored respectively.\nThe formula to solve for $x$ is $x=\\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$. \nThe most important formula for polynomials is the Vieta Formulas.\n\n\\begin{formula}[Vieta Formulas]\n  Sum of roots ($r_1+r_2+r_3+\\cdots+r_n$): $-\\frac{a_{n-1}}{a_{n}}$ \\\\\n  Product of roots ($r_1  r_2  r_3 \\cdots r_n$): $(-1)^n \\cdot \\frac{a_0}{a_n}$ \\\\\n  Pairwise sums of $p$  ($p=2$: $r_1r_2+r_1r_3+r_1r_4+\\cdots+r_{n-1}r_n$): $(-1)^p \\cdot \\frac{a_{n - p}}{a_{n}}$\n\\end{formula}\n\n\\begin{theorem}[Fundamental theorem of algebra]\n  It states that a single variable polynomial with degree\n  $n$ has exactly $n$ complex roots.\n\\end{theorem}\n\n\\begin{problem}\n  Let $r,s,$ and $t$ be the roots of $3x^3-4x^2+5x+7=0$. (\\ia, 8.20 pg.249)\n  \\begin{enumerate}\n    \\item Find $r+s+t$ ($\\frac{4}{3}$).\n    \\item Find $r^2+s^2+t^2$ ($\\frac{-14}{9}$).\n    \\item Find $\\frac{1}{r} + \\frac{1}{s} + \\frac{1}{t}$ ($\\frac{-5}{7}$).\n  \\end{enumerate}\n\\end{problem}\n\n\\subsection{Synthetic Division}\nA simplification of traditional polynomial division. Note this only works when the coefficients of \nthe linear term in the divisor is $1$. It is also know as the \\textbf{Ruffini's Rule}.\n\n\\textbf{Example:}\n$\\begin{array}{c|rrrrr} 3&\\parbox[b]{0.2in}{\\raggedleft 1}&\\parbox[b]{0.2in}{\\raggedleft -3}&\\parbox[b]{0.2in}{\\raggedleft 7}&\\parbox[b]{0.2in}{\\raggedleft -1}&\\parbox[b]{0.2in}{\\raggedleft 5}\\\\ &&{3}&{0}&21&60 \\\\\\cline{2-6} \\multicolumn{2}{r}{{1}}& {0}&7&20&\\multicolumn{1}{|r}{65} \\end{array}$\n\nWhich is the same as $(x^4 - 3x^3 + 7x^2 - x + 5) \\div (x - 3) = x^3+7x+20+\\frac{65}{x-3}$. Notice you work from left to right, and multiply to get the next number in the second row.\nIf your divisor doesn't have $1$ as its coefficient in the linear term, you can divide it by $1/n$ and in the end also multiply the quotient and remainder by $1/n$.\n\nUsually, you write the result of polynomial division as $\\frac{f(x)}{d(x)}=q(x)+\\frac{r(x)}{d(x)}$.\n\n\\subsection{Rational Root Theorem}\n\\begin{theorem}[Rational Root Theorem]\n  A rational root of a polynomial in the form $\\pm\\frac{p}{q}$ where $p$ and $q$ are relatively prime must follow the condition\n  $p | a_0$ and $q | a_n$.\n\\end{theorem}\n\n\\subsection{Remainder Theorem}\n\\begin{theorem}[Remainder Theorem]\n  When a polynomial $f(x)$ is divided by $x-a$, the remainder is determined by $f(a)$.\n\\end{theorem}\n\nTheorem 1.3 can be proven using the form $\\frac{f(x)}{d(x)}=q(x)+\\frac{r(x)}{d(x)}$ and synthetic division.\n\n\\begin{proof}[Remainder Theorem]\n  \\begin{align*}\n    f(x) &= (x-a)q(x) + r(x) \\\\\n    &= (x-a)q(x)+c. \\\\\n    f(a)&=(a-a)q(a)+c \\\\\n    &=0 \\cdot q(a) + c = c\n  \\end{align*}\n  Thus, $f(a)$ always returns the remainder of $f(x) \\div (x-a)$.\n\\end{proof}\n\n\\subsection{Factor Theorem}\n\\begin{theorem}[Factor Theorem]\ngiven the expression $x-a$, it is a divisor of $p(x)$ if and only if $p(a)=0$. This can be proven with the remainder theorem.\n\\end{theorem}\n\n\\subsection{Miscellaneous}\nTo find the sum of the coefficients of a polynomial $P(x)$, plug $x=1$! \nExample problem: Practice problem \\#2\n \n\\subsection{Practice Problems}\nProblems from \\ia.\n\\begin{enumerate}\n  \\item \\sout{6.11, pg. 181}\n  \\item 6.21 pg. 191\n  \\item 6.17, pg. 187\n  \\item 6.22, pg. 191\n  \\item 6.27, pg. 191\n  \\item 6.29, pg. 192\n  \\item $\\star$ Challenge Problems, pg. 192\n  \\item \\url{https://numbertheoryguydotcom.files.wordpress.com/2016/03/polynomials.pdf}\n\\end{enumerate}", "meta": {"hexsha": "348f4c38223e3ffd1b98ddbef6d97775fec02510", "size": 3793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/algebra/polynomials/polynomials.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/polynomials/polynomials.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/polynomials/polynomials.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.1046511628, "max_line_length": 295, "alphanum_fraction": 0.6622726074, "num_tokens": 1401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956856, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.6896397485749967}}
{"text": "%!TEX root = forallxyyc.tex\n\\chapter[Quick reference]{Quick reference}\n%\\pagestyle{plain}\n\\section{Characteristic truth tables}\n\\label{app.CharacteristicTTs}\n\n\\begin{tabular}{c|c}\n\\meta{A} & \\enot\\meta{A}\\\\\n\\hline\nT & F\\\\\nF & T \\\\\n\\phantom{.}\\\\\n\\phantom{.}\n\\end{tabular}\n\\hfill\n\\begin{tabular}{c c|c|c|c|c}\n\\meta{A} & \\meta{B} & $\\meta{A}\\eand\\meta{B}$ & $\\meta{A}\\eor\\meta{B}$ & $\\meta{A}\\eif\\meta{B}$ & $\\meta{A}\\eiff\\meta{B}$\\\\\n\\hline\nT & T & T & T & T & T\\\\\nT & F & F & T & F & F\\\\\nF & T & F & T & T & F\\\\\nF & F & F & F & T & T\n\\end{tabular}\n\n\n\\vfill\n\n\\section{Symbolization}\n\\begin{center}\n\\label{app.symbolization}\n\\begin{tabular*}{\\textwidth}{rl}\n\\multicolumn{2}{c}{\\textsc{Sentential Connectives}}\\\\ \\\\\nIt is not the case that $P$ & $\\enot P$\\\\\nEither $P$ or $Q$ & $(P \\eor Q)$\\\\\nNeither $P$ nor $Q$ & $\\enot(P \\eor Q)$\\ or \\ $(\\enot P \\eand \\enot Q)$\\\\\nBoth $P$ and $Q$ & $(P \\eand Q)$\\\\\nIf $P$ then $Q$ & $(P \\eif Q)$\\\\\n$P$ only if $Q$ & $(P \\eif Q)$\\\\\n$P$ if and only if $Q$ & $(P \\eiff Q)$\\\\\n$P$ unless $Q$ & $(P \\eor Q)$\\\\\n\\\\\n\\multicolumn{2}{c}{\\label{SymbolizingPredicates}\\textsc{Predicates}}\\\\ \\\\\nAll $F$s are $G$s & $\\forall x(\\atom{F}{x} \\eif \\atom{G}{x})$\\\\\nSome $F$s are $G$s & $\\exists x(\\atom{F}{x} \\eand \\atom{G}{x})$\\\\\nNot all $F$s are $G$s & $\\enot\\forall x(\\atom{F}{x} \\eif \\atom{G}{x})$\\ or\\\\\n& $\\exists x(\\atom{F}{x} \\eand \\enot \\atom{G}{x})$\\\\\nNo $F$s are $G$s & $\\forall x(\\atom{F}{x} \\eif\\enot \\atom{G}{x})$\\ or\\\\\n& $\\enot\\exists x(\\atom{F}{x} \\eand \\atom{G}{x})$\\\\\n\\\\\n\\multicolumn{2}{c}{\\textsc{Identity}}\\\\ \\\\\nOnly $c$ is $G$ & $\\forall x(\\atom{G}{x} \\eiff x=c)$\\\\\nEverything besides $c$ is $G$ & $\\forall x(\\enot x = c \\eif \\atom{G}{x} )$\\\\\n%$j$ is more $R$ than anyone else. & $\\forall x(x\\neq j \\eif Rjx)$\\\\\nThe $F$ is $G$ & $\\exists x(\\atom{F}{x} \\eand \\forall y(\\atom{F}{y} \\eif x=y) \\eand \\atom{G}{x} )$\\\\\nIt is not the case that\\\\\n the $F$ is $G$ & $\\enot\\exists x(\\atom{F}{x} \\eand \\forall y(\\atom{F}{y} \\eif x=y) \\eand \\atom{G}{x} )$\\\\\nThe $F$ is non-$G$ & $\\exists x(\\atom{F}{x} \\eand \\forall y(\\atom{F}{y} \\eif x=y) \\eand \\enot \\atom{G}{x} )$\n\\end{tabular*}\n\\end{center}\n\n\n\n\n\n\n% BEGIN: symbolizing cardinality\n\n\\newpage\n\\section{Using identity to symbolize quantities}\n\n\\subsection*{There are at least \\blank\\ $F$s.}\n\\label{summary.atleast}\n\n\\begin{tabular*}{\\textwidth}{rl}\none & $\\exists x\\,\\atom{F}{x}$\\\\\ntwo & $\\exists x_1\\exists x_2(\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\enot x_1  = x_2)$\\\\\nthree & $\\exists x_1\\exists x_2\\exists x_3(\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\atom{F}{x_3} \\eand {}$\\\\\n& $\\enot x_1 = x_2 \\eand\\enot x_1 = x_3 \\eand \\enot x_2 = x_3)$\\\\\nfour & $\\exists x_1\\exists x_2\\exists x_3\\exists x_4 (\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\atom{F}{x_3} \\eand \\atom{F}{x_4} \\eand {}$\\\\\n& $\\enot x_1 = x_2 \\eand \\enot x_1 = x_3 \\eand \\enot x_1 = x_4 \\eand {}$\\\\\n& $ \\enot x_2 = x_3 \\eand \\enot x_2 = x_4 \\eand \\enot x_3 = x_4)$\\\\\n$n$ & $\\exists x_1\\ldots\\exists x_n(\\atom{F}{x_1} \\eand \\ldots \\eand \\atom{F}{x_n} \\eand {}$\\\\\n& $\\enot x_1 = x_2 \\eand\\ldots\\eand \\enot x_{n-1} = x_n)$ \n\\end{tabular*}\n\n\\subsection*{There are at most \\blank\\ $F$s.}\n\\label{summary.atmost}\n\nOne way to say `there are at most $n$ $F$s' is to put a negation sign in front of the symbolization for `there are at least $n+1$ $F$s'. Equivalently, we can offer:\n\\begin{tabular*}{\\textwidth}{rl}\none & $\\forall x_1\\forall x_2\\bigl[(\\atom{F}{x_1} \\eand \\atom{F}{x_2}) \\eif x_1=x_2\\bigr]$\\\\\ntwo & $\\forall x_1\\forall x_2\\forall x_3\\bigl[(\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\atom{F}{x_3}) \\eif {}$\\\\ & $(x_1=x_2 \\eor x_1=x_3 \\eor x_2=x_3)\\bigr]$\\\\\nthree & $\\forall x_1\\forall x_2\\forall x_3\\forall x_4\\bigl[(\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\atom{F}{x_3} \\eand \\atom{F}{x_4}) \\eif {}$\\\\\n& $(x_1=x_2 \\eor x_1=x_3 \\eor x_1=x_4 \\eor {}$\\\\\n& $x_2=x_3 \\eor x_2=x_4 \\eor x_3=x_4)\\bigr]$\\\\\n$n$ & $\\forall x_1\\ldots\\forall x_{n+1}\n\\bigl[(\\atom{F}{x_1} \\eand \\ldots \\eand \\atom{F}{x_{n+1}}) \\eif {}$\\\\\n& $(x_1=x_2 \\eor \\ldots \\eor x_n=x_{n+1})\\bigr]$ \n\\end{tabular*}\n\n\n\\subsection*{There are exactly \\blank\\ $F$s.}\n\\label{summary.exactly}\n\nOne way to say `there are exactly $n$ $F$s' is to conjoin two of the symbolizations above and say `there are at least $n$ $F$s and there are at most $n$ $F$s.' The following equivalent formulas are shorter:\n\\begin{tabular*}{\\textwidth}{rl}\nzero & $\\forall x\\,\\enot \\atom{F}{x}$\\\\\none & $\\exists x\\bigl[\\atom{F}{x} \\eand \\forall y(\\atom{F}{y} \\eif x = y)\\bigr]$\\\\\ntwo & $\\exists x_1\\exists x_2\\bigl[\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand {}$\\\\\n& $\\enot x_1 = x_2 \\eand \\forall y\\bigl(\\atom{F}{y} \\eif (y= x_1 \\eor y = x_2)\\bigr) \\bigr]$\\\\\nthree & $\\exists x_1\\exists x_2\\exists x_3\\bigl[\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\atom{F}{x_3} \\eand {}$\\\\\n& $\\enot x_1 =  x_2 \\eand \\enot  x_1 = x_3 \\eand \\enot x_2 = x_3 \\eand {}$\\\\\n& $\\forall y\\bigl(\\atom{F}{y} \\eif (y = x_1 \\eor y = x_2 \\eor y =  x_3)\\bigr) \\bigr]$\\\\\n$n$ & $\\exists x_1\\ldots\\exists x_n\\bigl[\\atom{F}{x_1} \\eand\\ldots\\eand \\atom{F}{x_n}  \\eand {}$\\\\\n&$ \\enot x_1 = x_2 \\eand\\ldots\\eand \\enot x_{n-1}= x_n \\eand \\phantom{.}$\\\\\n& $\\forall y\\bigl(\\atom{F}{y} \\eif (y= x_1 \\eor \\ldots \\eor y= x_n)\\bigr)\\bigr]$ \n%\\item[one] $\\exists x\\forall y\\bigl[\\atom{F}{x} \\eand (\\atom{F}{y} \\eif y = x)\\bigr]$\n%\\item[two] $\\exists x\\exists y\\forall z\\Bigl(\\atom{F}{x} \\eand \\atom{F}{y} \\eand \\bigl[\\atom{F}{z} \\eif (z=x \\eor z=y)\\bigr] \\eand x \\neq y\\Bigr)$\n%\\item[three] $\\exists x_1\\exists x_2\\exists x_3\\forall y\\Bigl(\\atom{F}{x_1} \\eand \\atom{F}{x_2} \\eand \\atom{F}{x_3} \\eand [\\atom{F}{y} \\eif (y=x_1 \\eor y=x_2 \\eor y=x_3)] \\eand x_1 \\neq x_2 \\eand x_1 \\neq x_3 \\eand x_2 \\neq x_3\\Bigr)$\n%\\item[n] $\\exists x_1\\cdots\\exists x_n\\forall y\\Bigl(\\atom{F}{x_1} \\eand \\cdots \\eand \\atom{F}{x_n} \\eand \\bigl[\\atom{F}{y} \\eif (y=x_1 \\eor \\cdots \\eor y=x_n)\\bigr] \\eand x_1 \\neq x_2 \\eand\\cdots\\eand x_{n-1}\\neq x_n\\Bigr)$ \n\\end{tabular*}\n\n\n\\label{ProofRules}\n\\newpage\\section{Basic deduction rules for TFL}\n\\renewenvironment{proof}\n\t{\\noindent\\par\\noindent\\small$\\begin{nd}}\n\t{\\end{nd}$\\noindent\\normalsize\\ignorespacesafterend}\n\n%{\\LARGE \\textbf{Basic Rules of Proof}}\n\\begin{multicols}{2}\n\\subsection*{Reiteration}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}}\n\t\\have[\\ ]{c}{\\meta{A}} \\by{R}{a}\n\\end{proof}\n\n\\subsection*{Conjunction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}}\n\t\\have[n]{b}{\\meta{B}}\n\t\\have[\\ ]{c}{\\meta{A}\\eand\\meta{B}} \\ai{a, b}\n\n\t\\have[m]{ab}{\\meta{A}\\eand\\meta{B}}\n\\\\\t\\have[\\ ]{a}{\\meta{A}} \\ae{ab}\n\n\t\\have[m]{ab}{\\meta{A}\\eand\\meta{B}}\n\\\\\t\\have[\\ ]{b}{\\meta{B}} \\ae{ab}\n\\end{proof}\n\n\\subsection*{Conditional}\n\n\\begin{proof}\n\t\\open\n\t\t\\hypo[i]{a}{\\meta{A}}\n\t\t\\have[j]{b}{\\meta{B}}\n\t\\close\n\t\\have[\\ ]{ab}{\\meta{A}\\eif\\meta{B}}\\ci{a-b}\n\n\t\\have[m]{ab}{\\meta{A}\\eif\\meta{B}}\n\\\\\t\\have[n]{a}{\\meta{A}}\n\t\\have[\\ ]{b}{\\meta{B}} \\ce{ab,a}\n\\end{proof}\n\n\\subsection*{Negation}\n\n\\begin{proof}\n\\open\n\t\\hypo[i]{a}{\\meta{A}}\n\t\\have[j]{nb}{\\ered}\n\\close\n\\have[\\ ]{na}{\\enot\\meta{A}}\\ni{a-nb}\n\n\\have[m]{na}{\\enot\\meta{A}}\n\\\\ \\have[n]{a}{\\meta{A}}\n\\have[ ]{bot}{\\ered}\\ri{na, a}\n\\end{proof}\n\n\\subsection*{Indirect proof}\n\n\\begin{proof}\n\\open\n\t\\hypo[i]{a}{\\enot\\meta{A}}\n\t\\have[j]{nb}{\\ered}\n\\close\n\\have[\\ ]{na}{\\meta{A}}\\ip{a-nb}\n\\end{proof}\n\n\n\\subsection*{Explosion}\n\n\\begin{proof}\n\\have[m]{bot}{\\ered}\n\\\\\\have[ ]{}{\\meta{A}}\\re{bot}\n\\end{proof}\n\n\\subsection*{Disjunction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}}\n\t\\have[\\ ]{ab}{\\meta{A}\\eor\\meta{B}}\\oi{a}\n\n\t\\have[m]{a}{\\meta{A}}\n\\\\\t\\have[\\ ]{ba}{\\meta{B}\\eor\\meta{A}}\\oi{a}\n\n\t\\have[m]{ab}{\\meta{A}\\eor\\meta{B}}\n\\\\\t\\open\n\t\t\\hypo[i]{a}{\\meta{A}}\n\t\t\\have[j]{c1}{\\meta{C}}\n\t\\close\n\t\\open\n\t\t\\hypo[k]{b}{\\meta{B}}\n\t\t\\have[l]{c2}{\\meta{C}}\n\t\\close\n\t\\have[\\ ]{c}{\\meta{C}} \\oe{ab,a-c1, b-c2}\n\\end{proof}\n\n\\subsection*{Biconditional}\n\n\\begin{proof}\n\t\\open\n\t\t\\hypo[i]{a1}{\\meta{A}} \n\t\t\\have[j]{b1}{\\meta{B}}\n\t\\close\n\t\\open\n\t\t\\hypo[k]{b2}{\\meta{B}}\n\t\t\\have[l]{a2}{\\meta{A}}\n\t\\close\n\t\\have[\\ ]{ab}{\\meta{A}\\eiff\\meta{B}}\\bi{a1-b1,b2-a2}\n\n\t\\have[m]{ab}{\\meta{A}\\eiff\\meta{B}}\n\\\\\t\\have[n]{a}{\\meta{A}}\n\t\\have[\\ ]{b}{\\meta{B}} \\be{ab,a}\n\n\t\\have[m]{ab}{\\meta{A}\\eiff\\meta{B}}\n\\\\\t\\have[n]{a}{\\meta{B}}\n\t\\have[\\ ]{b}{\\meta{A}} \\be{ab,a}\n\\end{proof}\n\n\\end{multicols}\n\n\\newpage\n\\section{Derived rules for TFL}\n\\begin{multicols}{2}\n\\subsection*{Disjunctive syllogism}\n\\begin{proof}\n\t\\have[m]{ab}{\\meta{A} \\eor \\meta{B}}\n\t\\have[n]{nb}{\\enot \\meta{A}}\n\t\\have[\\ ]{con}{\\meta{B}}\\by{DS}{ab, nb}\n\n\t\\have[m]{ab}{\\meta{A} \\eor \\meta{B}}\n\\\\\t\\have[n]{nb}{\\enot \\meta{B}}\n\t\\have[\\ ]{con}{\\meta{A}}\\by{DS}{ab, nb}\n\\end{proof}\n\n\\subsection*{Modus Tollens}\n\n\\begin{proof}\n\t\\have[m]{ab}{\\meta{A}\\eif\\meta{B}}\n\t\\have[n]{a}{\\enot\\meta{B}}\n\t\\have[\\ ]{b}{\\enot\\meta{A}} \\by{MT}{ab,a}\n\\end{proof}\n\n\\subsection*{Double-negation elimination}\n\t\\begin{proof}\n\t\t\\have[m]{dna}{\\enot \\enot \\meta{A}}\n\t\t\\have[ ]{a}{\\meta{A}}\\dne{dna}\n\t\\end{proof}\n\n\n\\subsection*{Excluded middle}\n\t\\begin{proof}\n\t\t\\open\n\t\t\t\\hypo[i]{a}{\\meta{A}}\n\t\t\t\\have[j]{c1}{\\meta{B}}\n\t\t\\close\n\t\t\\open\n\t\t\t\\hypo[k]{b}{\\enot\\meta{A}}\n\t\t\t\\have[l]{c2}{\\meta{B}}\n\t\t\\close\n\t\t\\have[\\ ]{ab}{\\meta{B}}\\tnd{a-c1,b-c2}\n\t\\end{proof}\n\n%\n%\\subsection*{Hypothetical Syllogism}\n%\n%\\begin{proof}\n%\t\\have[m]{ab}{\\meta{A}\\eif\\meta{B}}\n%\t\\have[n]{bc}{\\meta{B}\\eif\\meta{C}}\n%\t\\have[\\ ]{ac}{\\meta{A}\\eif\\meta{C}}\\by{HS}{ab,bc}\n%\\end{proof}\n\n\\subsection*{De Morgan Rules}\n\\begin{proof}\n\t\\have[m]{ab}{\\enot (\\meta{A} \\eor \\meta{B})}\n\t\\have[\\ ]{dm}{\\enot \\meta{A} \\eand \\enot \\meta{B}}\\dem{ab}\n\n\t\\have[m]{ab}{\\enot \\meta{A} \\eand \\enot \\meta{B}}\n\\\\\t\\have[\\ ]{dm}{\\enot (\\meta{A} \\eor \\meta{B})}\\dem{ab}\n\n\t\\have[m]{ab}{\\enot (\\meta{A} \\eand \\meta{B})}\n\\\\\t\\have[\\ ]{dm}{\\enot \\meta{A} \\eor \\enot \\meta{B}}\\dem{ab}\n\n\t\\have[m]{ab}{\\enot \\meta{A} \\eor \\enot \\meta{B}}\n\\\\\t\\have[\\ ]{dm}{\\enot (\\meta{A} \\eand \\meta{B})}\\dem{ab}\n\\end{proof}\n\\end{multicols}\n\n\\newpage\n\n\\section{Basic deduction rules for FOL}\n\n\\begin{multicols}{2}\n\\subsection*{Universal elimination}\n\n\\begin{proof}\n\t\\have[m]{a}{\\forall \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)}\n\t\\have[\\ ]{c}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)} \\Ae{a}\n\\end{proof}\n\n\\subsection*{Universal introduction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)}\n\t\\have[\\ ]{c}{\\forall \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)} \\Ai{a}\n\\end{proof}\n\n\\medskip\\begin{raggedright}\n\\meta{c} must not occur in any undischarged assumption\n\n\\meta{x} must not occur in\\\\ $\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)$\n\\end{raggedright}\n\n\\subsection*{Existential introduction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)}\n\t\\have[\\ ]{c}{\\exists \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{c}\\ldots)}\\Ei{a}\n\\end{proof}\n\n\\medskip\\begin{raggedright}\n\\noindent \\meta{x} must not occur in\\\\ $\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)$\n\\end{raggedright}\n%\\noindent You can replace one or more instance of \\meta{c} with \\meta{x}.\n\n\\subsection*{Existential elimination}\n\n\\begin{proof}\n\t\\have[m]{a}{\\exists \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)}\n\t\\open\t\n\t\t\\hypo[i]{b}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)}\n\t\t\\have[j]{c}{\\meta{B}}\n\t\\close\n\t\\have[\\ ]{d}{\\meta{B}}\\Ee{a,b-c}\n\\end{proof}\n\n\\medskip\\begin{raggedright}\n\\noindent \\meta{c} must not occur in any undischarged assumption, in $\\exists \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)$, or in \\meta{B}\\end{raggedright}\\vfill\\columnbreak\n\n\\end{multicols}\n\n\\subsection*{Identity introduction}\n\n\\begin{proof}\n\t\\have[\\ \\,\\,\\,]{x}{\\meta{c}=\\meta{c}} \\by{=I}{}\n\\end{proof}\n\n\n\\subsection*{Identity elimination}\n\n\\begin{multicols}{2}\n\\begin{proof}\n\t\\have[m]{e}{\\meta{a}=\\meta{b}}\n\t\\have[n]{a}{\\meta{A}(\\ldots \\meta{a} \\ldots \\meta{a}\\ldots)}\n\t\\have[\\ ]{ea1}{\\meta{A}(\\ldots \\meta{b} \\ldots \\meta{a}\\ldots)} \\by{=E}{e,a}\n\\end{proof}\n\\begin{proof}\n\t\\have[m]{e}{\\meta{a}=\\meta{b}}\n\t\\have[n]{a}{\\meta{A}(\\ldots \\meta{b} \\ldots \\meta{b}\\ldots)}\n\t\\have[\\ ]{ea2}{\\meta{A}(\\ldots \\meta{a} \\ldots \\meta{b}\\ldots)} \\by{=E}{e,a}\n\\end{proof}\n\\end{multicols}\n\n\\begin{minipage}{\\textwidth} % hack to keep section header with table\n\\section{Derived rules for FOL}\n\n\\begin{multicols}{2}\n\\begin{proof}\n\t\\have[m]{ab}{\\forall \\meta{x}\\enot \\meta{A}}\n\t\\have[\\ ]{ac}{\\enot \\exists \\meta{x} \\meta{A}}\\cq{m}\n\n\t\\have[m]{ab}{\\enot \\exists \\meta{x}  \\meta{A}}\n\\\\\t\\have[\\ ]{ac}{\\forall \\meta{x}\\enot\\meta{A}}\\cq{m}\n\\end{proof}\n\\begin{proof}\n\t\\have[m]{ab}{\\exists \\meta{x}\\enot\\meta{A}}\n\t\\have[\\ ]{ac}{\\enot \\forall \\meta{x} \\meta{A}}\\cq{m}\n\n\t\\have[m]{ab}{\\enot \\forall \\meta{x}  \\meta{A}}\n\\\\\t\\have[\\ ]{ac}{\\exists \\meta{x}\\enot \\meta{A}}\\cq{m}\n\\end{proof}\n\\end{multicols}\n\\end{minipage}\n", "meta": {"hexsha": "f51b21e542a958b0d127ebc0277b63f46bcc1bdd", "size": 12533, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "forallx-yyc-quickreference.tex", "max_stars_repo_name": "tedshear/forallx-yyc", "max_stars_repo_head_hexsha": "20fd769dea1683f18d57ba03b1230afc13b5199d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-18T23:09:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-18T23:09:38.000Z", "max_issues_repo_path": "forallx-yyc-quickreference.tex", "max_issues_repo_name": "tedshear/forallx-yyc", "max_issues_repo_head_hexsha": "20fd769dea1683f18d57ba03b1230afc13b5199d", "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": "forallx-yyc-quickreference.tex", "max_forks_repo_name": "tedshear/forallx-yyc", "max_forks_repo_head_hexsha": "20fd769dea1683f18d57ba03b1230afc13b5199d", "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.8694581281, "max_line_length": 235, "alphanum_fraction": 0.6000159579, "num_tokens": 5802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8872045996818986, "lm_q1q2_score": 0.6896240121662871}}
{"text": "\\section{Two-particle scattering}\\label{sec:scattering}\n\nTwo non-relativistic particles interacting via a contact interaction of strength $C$ in $D$ dimensions are described by the Hamiltonian\n\\begin{equation}\n    \\label{eq:particle hamiltonian}\n    \\hat H = \\frac{\\hat p_1^2}{2 m_1} + \\frac{\\hat p_2^2}{2 m_2} + C \\delta^D(\\hat x_1 - \\hat x_2)\n    \\,,\n\\end{equation}\nwhere the subscripts identify the particle of the position and momentum operators.\nMoving to center-of-mass and relative coordinates, this Hamiltonian may be rewritten\n\\begin{equation}\n    \\label{eq:hamiltonian}\n    \\hat H = \\frac{\\hat P^2}{2 M} + \\frac{\\hat p^2}{2 \\mu} + C\\delta^D(\\hat{x})\n\\end{equation}\nwhere capital letters represent center-of-mass variables, lower case implies relative coordinates, and $\\mu$ is the reduced mass.\nSpecializing to the center of mass frame by setting $P=0$ we reduce the problem to an effective one-body quantum mechanics in an external delta-function potential.\n\nFor a general two-body interaction $V$ in $D$ dimensions we can obtain scattering data by solving the Lippmann-Schwinger equation,\n\\begin{align}\n\tT_D(\\vec p', \\vec p, E)\n\t&=\n\tV(\\vec p', \\vec p) + \\lim\\limits_{\\epsilon \\to 0}\\int \\frac{d \\vec k^D}{(2\\pi)^D} V(\\vec p', \\vec k) G(\\vec k, E + i \\epsilon) T(\\vec k, \\vec p, E) \\, ,\n\t&\n\tG(\\vec k, E+ i \\epsilon) = \\frac{1}{E + i \\epsilon - \\frac{k^2}{2\\mu}}\n\t\\, .\n\\end{align}\nwhere $G$ is the free Green's function.\nProjecting onto the set of partial waves in $D$ dimensions labelled by $\\l$, the $T$ matrix may be re-expressed in terms of phase shifts.\nFor a central interaction like the contact interaction, partial waves do not mix and $\\l$ labels the orbital angular momentum, which is conserved.\nIn this case, the phase shifts can be extracted from the scattering or $T$-matrix by\n\\begin{align}\\label{eq:on-shell-T}\n\t\\frac{1}{T_{D\\l}(p)}\n    \\equiv\n    \\frac{1}{T_{D\\l}(p, p, E_p)}\n    = \\frac{\\mu}{2}\n    \\frac{1}{\\mathcal F_{D\\l}(p)} \\left[\\cot (\\delta_{D\\l}(p)) - i\\right] \\, ,\n\\end{align}\nwhere $E_p = p^2 / (2 \\mu)$ and $\\mathcal F_{l D}(p)$ is a dimension-dependent kinematic function of the on-shell momentum.\n\nAt low energy one often considers the expansion of \\eqref{on-shell-T} in scattering momentum $p$, called the effective range expansion (ERE), which takes the form \\cite{Hammer:2010fw}\n\\begin{align}\n    \\label{eq:ere}\n    \\cot \\left(\\delta_{D\\l}(p)\\right)\n    &=\n    \\theta_D \\frac{2}{\\pi}  \\ln \\left(p R_{D\\l}\\right)\n    -\n    \\frac{1}{a_{D\\l}} p^{2 - 2 \\l - D} +\\frac{1}{2} r_{D\\l} p^{4 - 2 \\l - D} + \\order{p^{6 - 2 \\l - D}}\n    \\, , &\n    \\theta_D &= \\begin{cases}\n        0 & D \\;\\text{odd} \\\\ 1 & D \\;\\text{even}\n    \\end{cases}\n    \\, ,\n\\end{align}\nwhere $R_{D \\l}$ is an arbitrary length scale that enters in even dimensions and $a_{D\\l}$, $r_{D\\l}$ and subsequent higher-order coefficients describe the properties of the two-particle interaction.\nIn three spatial dimensions, the S-wave phase shift is described by the \\emph{scattering length} $a_{30}$, the \\emph{effective range} $r_{30}$ and further shape parameters.\n\nIn this paper we refer to $a$ as the scattering length and $r$ the effective range, even when, by simple dimensional analysis, they may not be actual lengths.\nMoreover, in this work we will focus on the S-wave or its $D$-dimensional equivalent partial wave for simplicity, and henceforth suppress the $\\l$ label\n\\begin{align}\n\t\\delta_{D} &\\equiv \\delta_{D0}\\, , &\n\ta_{D} &\\equiv a_{D0}\\, , &\n\tr_{D} &\\equiv r_{D0}\\, , &\n\t\\cdots &\n\t\\,\n\\end{align}\nWe work in three, two, and one spatial dimension.\n\nContact interactions, which are analytically tractable, correspond to a momentum-independent scattering amplitude when properly renormalized (as long as the log dependence is handled carefully in even dimensions).\nSo, the strength of the contact interaction $C$ may be traded for the scattering length $a$ and all other scattering parameters vanish.\nThe lattice interactions we will construct, when analyzed appropriately, will exhibit this momentum independence.\n", "meta": {"hexsha": "ac487a62a8e31151408004bdb5b54d949da6c7a2", "size": 4028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/two-particle-scattering.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-particle-scattering.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-particle-scattering.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": 56.7323943662, "max_line_length": 213, "alphanum_fraction": 0.6971201589, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7905303285397348, "lm_q1q2_score": 0.689617051458058}}
{"text": "\\chapter{Photonics}\n\\label{ch:marketbasics}\n\n\\section{Basics}\n\nThe speed of light is given by $c=2.99\\times10^8m/s$ in vacuum, and slower in other medium. Light can experience \\textbf{refraction}\\sidenote{deflection when passing from one medium to another} and \\textbf{reflection}\\sidenote{bouncing off a surface}. Detection and measurement of light energy is a field known as {\\it radiometry}. The properties of light can be described by both particle and wave analogies. \n\n\\subsection{Light as a particle}\n\nA \"light particle\" is called a photon, which is a particle with no mass or charge. It carries electromagnetic energy and can interact with other particles. The amount of energy $E$ for a photon is given by \n\n\\begin{equation}\nE=\\frac{hc}{\\lambda}\n\\end{equation}\nWhere $h$ is Planck's constant ($6.25\\times10^{-34}$), $c$ is the speed of light and $\\lambda$ is the light's wavelength in meters.\n\nThe {\\it photoelectric} effect gives evidence of light's particle like properties. This is the effect seen where some materials when a light is shone on them emit electrons. This behaviour reflects light as a particle because more intense radiation did not cause higher energy electrons to be emitted and electron energy was dependent on wavelength, not amplitude of the wave.\n\nNo matter how intense the light, photons below a given minimum frequency do not cause electrons to be emitted. The relationship governing the energy of emitted electrons is\n\n\\begin{equation}\nE_{e-} = \\frac{hc}{\\lambda} - p\n\\end{equation}\nWhere $p$ is the characteristic escape energy for the given metal and $E_{e-}$ is the energy of the escaping electron.\n\n\n\\subsection{Light as a wave}\n\nLight also exhibits the properties of {\\it interference} and {\\it diffraction} which fit the idea of a wave model of light. Waves move energy without moving mass at a speed independent of intensity or wavelength. Light waves have an electric and magnetic field which changes at right angles to the direction of motion. The wavelength ($\\lambda$) is the distance between successive peaks or troughs in a wave. The wave number $\\nu$ is the inverse of the wave length. Standard mathematical properties such as period $\\tau$ and frequency $f$ can be calculated. \n\nLight waves are not always sinusoidal in shape. In addition any particle light wave may consist of a series of waves with peaks in all different directions perpendicular to the direction of travel. The amount of energy that flows across a unit area perpendicular ot the direction of travel is called the irradiance or flux density of the wave. \n\nLight waves may also be polarised, where the waves vibrate in specific directions perpendicular to the direction of travel. The intensity of light travelling through a linear polariser can be given by \n\n\\begin{equation}\nI(\\theta) = I_0\\cos^2(\\theta)\n\\end{equation}\nwhere $I(\\theta)$ is the light intensity passed by the polariser and $I_0$ is the incident light density. \n\nLight waves exhibit the properties of {\\it superposition}, {\\it reflection}, {\\it refraction}, {\\it diffraction} and {\\it interference}.\n\nFor refraction, the angle of incidence is the same as the angle of reflection, when measured from the surface normal. \n\nRefraction occurs at the interface between surfaces due to the difference in speed of light in the particular material. The ratio of speeds for two surfaces can be given by the index of refraction:\n\n\\begin{equation}\n\t\\frac{n_2}{n_1} = \\frac{\\sin\\theta}{\\sin\\phi}\n\\end{equation}\nWhere $n_2$ and $n_1$ are the indices of refraction for the two media, $\\theta$ is the angle of incidence (from the surface normal) and $\\phi$ is the angle of refraction (measured from the normal). \n\nthe index of refraction can be calculated by \n\n\\begin{equation}\nn_i = \\frac{c}{v_i}\n\\end{equation}\nWhere $v_i$ is the velocity of light in the medium $i$.\n\nThe slit test proved the wave like properties of light. A slit of width d has a plane wave shone on it. Where $d < \\lambda$ a very even diffuse light is shone on to a surface on the far side of the slit. Essentially small spherical waves are emitted from the slit . Where $d \\approx \\lambda$, then emitted wave appears to have similar properties to the plane wave. \n\nThe two slit experiment in 1801 showed the two waves of light emitted through the slits interfering, resulting in a ``zebra strip'' sort of pattern on the far surface. \n\n\\subsection{The electromagnetic spectrum}\n\nOnly a small spectrum of electromagnetic radiation is visible light. Waves go from long wave to radio through infrared, visible light, ultraviolet, xrays and gamma rays in order of decreasing wave length. \n\nWhite light contains a mixture of different coloured light, each of which has a different wavelength. Due to their differing wavelength, the white light can be separated when refracted through a particular medium.\n\nAny material above absolute zero emits electromagnetic radiation, with molecules having a characteristic set of spectral lines. Atoms changing state produce visible and ultraviolet radiation, whilst molecules changing vibrational or rotational states emit infrared radiation. Liquids and solids typically have much broader spectral lines than gases as they can take on a much wider range of energy states. \n\nAt an atomic level, an atom consisting of protons and neutrons has a series of energy shells (labelled K through O) which can contain electrons. In their {\\it grounded} state electrons have limited energy. However as energy is added they can become excited and move into higher energy shells. As they do this they absorb or emit quanta (unique amounts) of energy, with the exact nature depending on the electronic structure of the atom. \n\nFor a hydrogen atom there are 6 major energy levels, ranging from $-0.38eV$ to $-13.6eV$. This means that if an electron is in the $n=3$ layer (which has an energy of $-1.5eV$ then it can emit a photon with \n\n\\begin{equation}\n\t-1.51 - (-13.6) = 12.09eV\n\\end{equation}\nIf an electron is freed from the atom then its energy level $E_\\infty = 0$. Atoms can also absorb photons which have energy exactly matching the difference between electron energy levels. Additionally a molecule in a gas or liquid may absorb a photon where it has a vibrational or rotational energy level matching the energy of the photon.\n\n\\subsection{Blackbody radiation}\n\nBlackbody radiation is the theoretical maximum radiation expected for temperature related self-radiation. That is the amount of energy radiated from a body (in various spectra) based on its temperature (in Kelvin).\n\nThe energy radiated by a black body in a given wave band is the sum of all energies radiated at the wavelengths within the band. The same holds for the power emitted, which can be calculated in watts per square meter using the Stefan-Boltzmann law:\n\n\\begin{equation}\nW_s = \\sigma_sT^4\n\\end{equation}\nWhere $W_s$ is the radiated power, $\\sigma_s$ is the Stefan-Boltzmann constant, $5.67\\times10^{-8}$ and $T$ is the temperature in Kelvin. $W_s$ is the power per unit area, also known as the emitted radiant flux density. Typically graybodies do not perfectly emit and the above equation is factored down bt the emissivity ($\\varepsilon$) of the material.\n\n\\begin{equation}\nW_s = \\varepsilon\\sigma_sT^4\n\\end{equation}\nBlackbodies emit radiation over a range of wavelengths. The power radiated per unit area $W_\\lambda$ within a given waveband $\\Delta\\lambda$ is given by Planck's radiation formula:\n\n\\begin{equation}\nW_\\lambda = \\frac{c_1}{\\lambda^5} - \\frac{1}{\\frac{c_2}{e\\lambda T}-1}\n\\end{equation}\nWhere \n\n\\begin{equation}\nc_1 = 2\\pi c^2 h = 3.75\\times10^{-16}\n\\end{equation}\n\n\\begin{equation}\nc_2 = \\frac{hc}{k} = 1.44\\times10^{-4}\n\\end{equation}\n\n\\begin{equation}\nc = 3\\times10^8\n\\end{equation}\n\n\\begin{equation}\nh = 6.626\\times10^{-34}\n\\end{equation}\n\n\\begin{equation}\nk = 1.38\\times10^{-28}\n\\end{equation}\nThere is a maximum emission wavelength which can be given by Wien's displacement law:\n\n\\begin{equation}\n\t\\lambda_{max}T = 2.898\\times10^{-3}m\\cdot K\n\\end{equation}\t\n\n\\subsection{Interaction with matter}\nThe two main interactions are {\\it absorption} and {\\it scattering}. \nAbsorption has been discussed as moving an electron into a higher energy level or exciting a molecule's vibration or rotation. The spectrum of absorbed light may have missing or removed wavelengths depending on what has been absorbed. This is the basis for objects having colour.\n\nScattering is redirection of light based on interaction with matter. Scattered radiation may have the same or longer wavelength (reduced energy) and may have a different polarisation. \n\nIf the scatterer are significantly smaller than the wavelength $\\lambda$ then they may absorb and immediately re-emit photons in a different direction. Where the emitted photon has the same wavelength as the incident light it is known as {\\it Rayleigh scattering}. \n\nWhere the wavelength of the emitted radiation is longer and the molecule is left in an excited state, it is known as {\\it Raman scattering}. For Raman scattering, secondary photons may later be emitted when the molecule returns to the ground state.\n\nWhere the scatterer is of similar size or larger than the wavelength, all wavelengths of the incident light are equally scattered, a process known as {\\it Mie scattering}. \n\n", "meta": {"hexsha": "6d2ce0deaabc878d46f4bbcd8f70a09be800fc54", "size": 9293, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "photonics.tex", "max_stars_repo_name": "will-hart/interesting-notes", "max_stars_repo_head_hexsha": "fd3e8c8777924e7e46521e62556052d18dffa15f", "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": "photonics.tex", "max_issues_repo_name": "will-hart/interesting-notes", "max_issues_repo_head_hexsha": "fd3e8c8777924e7e46521e62556052d18dffa15f", "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": "photonics.tex", "max_forks_repo_name": "will-hart/interesting-notes", "max_forks_repo_head_hexsha": "fd3e8c8777924e7e46521e62556052d18dffa15f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.8321167883, "max_line_length": 558, "alphanum_fraction": 0.7796190681, "num_tokens": 2214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6896071259688151}}
{"text": "\\chapter{Straight Line}\n\n\n\\section{Gradient \\& Equation of a Straight Line}\nThe gradient is the line's steepness. The bigger the number, the steeper it is. Its symbol is $m$.\n\nIts equation is\n\\begin{equation*}\nm = \\frac{\\text{vertical distance}}{\\text{horizontal distance}}\n\\end{equation*}\nor\n\\begin{equation}\nm = \\frac{y_2-y_1}{x_2-x_1}\n\\end{equation}\n\nIf the line is vertical ($\\vert$), then it has an undefined gradient, e.g. when $x=1$. If it is horizontal (—), then $m=0$, e.g. when $y=1$.\n\nFrom National 5, it should be known that, given a point and gradient, the equation of a line can be written using\n\n\\begin{equation}\ny-b=m(x-a).\n\\end{equation}\n\n\\subsection{Example}\nIf $m=3$ and the line goes through point (-2,3), find the equation of the line.\n\n\\begin{align*}\ny-b&=m(x-a)\\\\\ny-3&=3(x+2)\\\\\ny&=3(x+2)+3\\\\\ny&=3x+6+9\\\\\ny&=3x+9\\\\\n\\end{align*}\n\nNote that the equation can be left in any form, no extra marks are awarded for leaving it in the form $0 = 3x - y + 9$\n\n\n\\section{$m=\\tan\\theta$}\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{tikzpicture}% function\n\t\t\\begin{axis}\n\t\t[\n\t\t\txlabel=$x$,\n\t\t\tylabel=$y$,\n\t\t\taxis lines = left, % Only show axis on the left and bottom.\n\t\t\taxis equal,\n\t\t\tymin = 0,\n\t\t\txmin = 0,\n\t\t]\n\t\t\\pgfplotsset{ticks=none}\n\t\t\\addplot\n\t\t[\n\t\t\tsamples = 100,\n\t\t\tcolor = black,\n\t\t]{sqrt(3)*x};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Here, $\\theta$ is 60$^\\circ$.}\n\t\\label{fig:mtan60}\n\\end{figure}\n$\\theta$ is the (in figure \\ref{fig:mtan60} an acute) angle made from the $x$-axis in an anti-clockwise direction (also called in the positive direction of the $x$-axis). If $\\theta$ is known, the gradient of the line can be found, and vice versa, by using\n\n\\begin{equation}\n\tm=\\tan\\theta\n\\end{equation}\n\n\\subsection{Examples}\n\\begin{enumerate}\n\t\\item\n\tA line makes an angle of 120$^\\circ$ with the positive direction of the $x$-axis. Find its gradient.\n\t\n\tOne could just enter 120$^\\circ$ into their calculator and get the right answer, but the following is a method of working it out if the question would appear in a non-calculator paper.\n\t\\begin{align*}\n\tm&=\\tan\\theta\\\\\n\t&=\\tan120^\\circ\\\\\n\t&=-\\tan60\\\\\n\t&=-\\sqrt{3}\n\t\\end{align*}\n\t\n\t\\item\n\tA line's gradient is $-2$. Find the angle it makes in the positive direction of the $x$-axis.\n\t\\begin{align*}\n\t\\text{If $m=2$,}\\\\\n\t\\tan\\theta&=2\\\\\n\t\\theta&=\\tan^{-1}2\\\\\n\t&=63.43...\\\\\n\t\\text{Now the proper line where $m=-2$,}\\\\\n\t\\theta&=180-63.43...\\\\\n\t&=116.56...\\\\\n\t&\\approx116.6^\\circ\n\t\\end{align*}\n\n\\end{enumerate}\n\n\n\\section{Perpendicular Lines ($\\perp$)}\nPerpendicular lines sit at right angles to each other. If lines are perpendicular, then\n\\begin{equation}\nm_1 m_2 = -1.\n\\end{equation}\n\n\\subsection{Examples}\nIf two lines are perpendicular, calculate $m_1$ if $m_2$ is\n\\begin{enumerate}\n\t\\item 6\n\t\\item -7\n\t\\item $\\frac{2}{7}$\n\\end{enumerate}\n\n\\begin{enumerate}\n\t\\item\n\t\\begin{align*}\n\tm_1 m_2 &= -1\\\\\n\t3m_1 &= -1\\\\\n\tm_1&=-\\frac{1}{3}\n\t\\end{align*}\n\t\n\t\\item\n\t\\begin{align*}\n\tm_1 m_2 &= -1\\\\\n\t-7m_1 &= -1\\\\\n\tm_1&=\\frac{1}{7}\n\t\\end{align*}\n\t\n\t\\item\n\t\\begin{align*}\n\tm_1 m_2 &= -1\\\\\n\t\\frac{2}{7}m_1 &= -1\\\\\n\t2m_1&=-7\\\\\n\tm_1&=-\\frac{7}{2}\n\t\\end{align*}\n\\end{enumerate}\n\nAs a shortcut, take the recipricol and change the sign.\n\n\\begin{enumerate}\n\t\\setcounter{enumi}{3}\n\t\\item\n\tFind the equation of the line perpendicular to $y=-\\frac{2}{3}x+5$ that passes through the point $\\left(1,7\\right)$.\n\n\t\\begin{align*}\n\t\tm &= -\\frac{2}{3} & m_\\perp &= \\frac{3}{2}\n\t\\end{align*}\n\n\tNow that the gradient of the perpendicular line has been found, it can be used in the equation.\n\t\n\t\\begin{align*}\n\t\ty-b&=m(x-a)\\\\\n\t\ty-7&=\\frac{3}{2}(x-1)\\\\\n\t\ty&=\\frac{3}{2}x - \\frac{3}{2} + 7\\\\\n\t\ty&=\\frac{3}{2}x + \\frac{11}{2}\n\t\\end{align*}\n\\end{enumerate}\n\n\n\\section{Mid Point Formula}\nTo find the point in the middle of a line, use\n\\begin{equation}\n\\text{mid point} = \\left(\\frac{x_1 + x_2}{2},\\frac{y_1 + y_2}{2}\\right)\n\\end{equation}\n\n\\subsection{Examples}\n\\begin{enumerate}\n\t\\item\n\tFind the mid point of $\\left(1,-4\\right)$ and $\\left(7,8\\right)$.\n\t\n\t\\begin{align*}\n\t\t\\text{mid point} &= \\left(\\frac{x_1 + x_2}{2},\\frac{y_1 + y_2}{2}\\right)\\\\\n\t\t&= \\left(\\frac{1 + 7}{2},\\frac{-4 + 8}{2}\\right)\\\\\n\t\t&= \\left(4,2\\right)\n\t\\end{align*}\n\t\n\t\\item\n\tA circle has centre point $(6,10)$. Two points $A(5,5)$ and $B$ are drawn on its circumference, these are connecting by a diameter (see figure \\ref{fig:MidPointQ2}). Find the coordinates of B.\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t[\n\t\t\tscale=0.5,\n\t\t\t% Make a style for a black coordinate.\n\t\t\tcmark/.style={label={[anchor=center, color=black]:\\pgfuseplotmark{#1}}},\n\t\t\t% And one for a blue coordinate.\n\t\t\tbmark/.style={label={[anchor=center, color=blue]:\\pgfuseplotmark{#1}}}\n\t\t]\n\t\t\t\\draw (6,10) circle [radius=sqrt(26)];\n\t\t\t\\coordinate\n\t\t\t[\n\t\t\t\tlabel=below:{$A(5,5)$},\n\t\t\t\tblack,\n\t\t\t\tcmark=*,\n\t\t\t] (a) at (5,5);\n\t\t\t\\coordinate\n\t\t\t[\n\t\t\t\tlabel=right:{$C(6,10)$},\n\t\t\t\tblack,\n\t\t\t\tcmark=*,\n\t\t\t] (c) at (6,10);\n\t\t\t\\coordinate\n\t\t\t[\n\t\t\t\tlabel=above:{$B$},\n\t\t\t\tblue,\n\t\t\t\tbmark=*,\n\t\t\t] (b) at (7,15);\n\t\t\t\n\t\t\t% Draw diameter.\n\t\t\t\\draw (a) -- (c) -- (b);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Circle mentioned in example 2.}\n\t\t\\label{fig:MidPointQ2}\n\t\\end{figure}\n\t\\begin{align*}\n\t\t\\text{mid point} &= \\left(\\frac{x_1 + x_2}{2},\\frac{y_1 + y_2}{2}\\right)\\\\\n\t\t\\left(17, 12\\right) &= \\left(\\frac{9+x}{2},\\frac{-2 + y_2}{2}\\right)\n\t\\end{align*}\n\t\\begin{align*}\n\t\t\\frac{9+x}{2} &= 17 & \\frac{-2+y}{2} &= 12\\\\\n\t\t9+x &= 34 & -2+y &= 24\\\\\n\t\tx &= 25 & y &= 26\n\t\\end{align*}\n\t\n\tSo the coordinate of B is $\\left(25,26\\right)$.\n\\end{enumerate}\n\n\n\\section{Collinearity}\nPoints that are collinear lie on a straight line.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{subfigure}[b]{0.4\\linewidth}\n\t\t\\begin{tikzpicture}% coordinates\n\t\t\t\\begin{axis}\n\t\t\t[\n\t\t\t\taxis equal,\n\t\t\t\taxis line style={draw=none},\n\t\t\t]\n\t\t\t\\pgfplotsset{ticks=none} % Get rid of numbers and ticks.\n\t\t\t\\addplot\n\t\t\t[\n\t\t\t\tcolor=black,\n\t\t\t\tmark=*,\n\t\t\t] coordinates\n\t\t\t{\n\t\t\t\t(3,0)(6,1)(9,2)\n\t\t\t};\n\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Collinear.}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{0.4\\linewidth}\n\t\t\\begin{tikzpicture}% coordinates\n\t\t\t\\begin{axis}\n\t\t\t[\n\t\t\t\taxis equal,\n\t\t\t\taxis line style={draw=none},\n\t\t\t]\n\t\t\t\\pgfplotsset{ticks=none} % Get rid of numbers and ticks.\n\t\t\t\\addplot\n\t\t\t[\n\t\t\t\tcolor=black,\n\t\t\t\tmark=*,\n\t\t\t] coordinates\n\t\t\t{\n\t\t\t\t(1,0)(2,1)(7,2)\n\t\t\t};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Not collinear.}\n\t\\end{subfigure}\n\t\\caption{Examples of collinearity.}\n\t\\label{fig:collinearityExample}\n\\end{figure}\n\nTo test for collinearity of three points $A,B,C$:\n\\begin{enumerate}\n\t\\item find $m_{AB}$,\n\t\\item find $m_{BC}$,\n\t\\item if $m_{AB}=m_{BC}$, then (because $B$ is a common point) they are collinear.\n\\end{enumerate}\n\n\\subsection{Examples}\n\\begin{enumerate}\n\t\\item\n\tShow that the points $P\\left(-6,-1\\right), Q\\left(0,2\\right), R\\left(8,6\\right)$ are collinear.\n\t\n\t\\begin{align*}\n\t\tm_{PQ}&=\\frac{2+1}{0+6} & m_{QR}&=\\frac{6-2}{8-0}\\\\\n\t\t&=\\frac{3}{6} & &=\\frac{4}{8}\\\\\n\t\t&=\\frac{1}{2} & &=\\frac{1}{2}\n\t\\end{align*}\n\tSince $m_{PQ} = m_{QR}$, and $Q$ is a common point, $PQR$ are collinear.\n\t\n\t\\item\n\tIf $A\\left(1,-1\\right), B\\left(-1,k\\right), C\\left(5,7\\right)$ are collinear, find k.\n\t\n\t\\begin{align*}\n\t\tm_{AB}&=m_{BC}\\\\\n\t\t\\frac{k-(-1)}{-1-1}&=\\frac{7-k}{5-(-1)}\\\\\n\t\t\\frac{k+1}{-2}&=\\frac{7-k}{6}\\\\\n\t\t6(k+1)&=-2(7-k)\\\\\n\t\t6k+6&=-14+2k\\\\\n\t\t4k&=-20\\\\\n\t\tk&=5\n\t\\end{align*}\n\\end{enumerate}\n\n\n\\section{Median Lines}\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{tikzpicture}[scale=8]\n\t\t% Draw triangle.\n\t\t\\coordinate[label=left:{$A$}] (a) at (0mm,0mm);\t\t\\coordinate[label=above:{$B$}] (b) at (7mm,5mm);\t\t\\coordinate[label=right:{$C$}] (c) at (10mm,1mm);\n\t\t\\draw (a) -- (b) -- (c) -- cycle;\n\t\t\n\t\t% Draw point M.\n\t\t\\coordinate\n\t\t[\n\t\t\tlabel=below:{$M$},\n\t\t\tcircle,\n\t\t\tfill,\n\t\t\tcolor=blue,\n\t\t\tinner sep=1mm,\n\t\t\tscale=0.5\n\t\t] (m) at (5mm,0.5mm);\n\t\t\n\t\t% Connect point M and B.\n\t\t\\draw[color=blue] (m) -- (b) -- cycle;\n\t\\end{tikzpicture}\n\t\\caption{Median from B.}\n\t\\label{fig:median}\n\\end{figure}\n\nThe median is a line from a vertex of a triangle to the mid point of the opposite.\n\nTo find the median from $B$ in a triangle $ABC$ (such as in figure \\ref{fig:median}):\n\\begin{enumerate}\n\t\\item find the mid point of $AC$ (hereafter called $M$), since the opposite of $B$ is $AC$,\n\t\\item find $m_{BM}$,\n\t\\item use $y-b=m(x-a)$ with $B$ or $M$ and $m_{BM}$.\n\\end{enumerate}\n\n\\subsection{Example}\nIn $\\triangle ABC$, $A(4,-9)$, $B(10,2)$, and $C(4,-4)$. Find the equation of the median from A.\n\n\\begin{align*}\n\t\\text{mid point} &= \\left(\\frac{10+4}{2},\\frac{2-4}{2}\\right) & m_{AM} &= \\frac{-1-(-9)}{7-4}\\\\\n\t&=\\left(7,-1\\right) & &= \\frac{8}{3}\n\\end{align*}\n\\begin{align*}\n\ty-b&=m(x-a)\\\\\n\ty+9&=\\frac{8}{3}\\left(x-4\\right)\\\\\n\t3y+27&=8\\left(x-4\\right)\\\\\n\t3y&=8x-32-27\\\\\n\t3y&=8x-59\n\\end{align*}\n\n\n\\section{Altitude}\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{tikzpicture}[scale=2]\n\t\t% Draw triangle.\n\t\t\\coordinate[label=left:{$A$}] (a) at (0cm,0cm);\t\t\\coordinate[label=above:{$B$}] (b) at (1cm,2.5cm);\t\t\\coordinate[label=right:{$C$}] (c) at (2.5cm,0.5cm);\n\t\t\\coordinate[] (q) at ($(c)!(b)!(a)$) {};\n\t\t\\draw (a) -- (b) -- (c) -- cycle;\n\t\t\\draw[color=blue] (b) -- (q);\n\t\t\n\t\t\\tkzMarkRightAngle[radius=0.05cm](b,q,c)\n\t\\end{tikzpicture}\n\t\\caption{Altitude from B.}\n\t\\label{fig:altitude}\n\\end{figure}\n\nThe altitude is a straight line from a vertex to the other side at right angles.\n\nTo find the altitude from $B$ in a triangle $ABC$ (such as in figure \\ref{fig:altitude}):\n\\begin{enumerate}\n\t\\item find $m_{AC}$,\n\t\\item find $m_\\perp$,\n\t\\item use $y-b=m(x-a)$ with $m_\\perp$ and $B$.\n\\end{enumerate}\n\n\\subsection{Example}\nThe triangle $ABC$ has vertices $A(3,-5)$, $B(4,3)$, and $C(-7,2)$. Find the altitude from A.\n\n\\begin{align*}\n\tm_{CB}&=\\frac{3-2}{4-(-7)} & m_\\perp&=-11\\\\\n\t&=\\frac{1}{11}\n\\end{align*}\n\\begin{align*}\n\ty-b&=m(x-a)\\\\\n\ty+5&=-11(x-3)\\\\\n\ty&=-11x+33-5\\\\\n\ty&=-11x+28\n\\end{align*}\n\n\n\\section{Perpendicular Bisector}\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{tikzpicture}[scale=2]\n\t\t% Draw triangle.\n\t\t\\coordinate[label=above:{$A$}] (a) at (0cm,0cm);\n\t\t\\coordinate[label=above:{$B$}] (b) at (4cm,0cm);\n\t\t\\coordinate[] (p) at (2cm,0.75cm);\n\t\t\\coordinate[] (q) at (2cm,0cm);\n\t\t\\coordinate[] (r) at (2cm,-0.75cm);\n\t\t\\draw (a) -- (b);\n\t\t\\draw[color=blue] (p) -- (r);\n\t\t\n\t\t\\tkzMarkRightAngle[radius=0.05cm](p,q,b)\n\t\\end{tikzpicture}\n\t\\caption{The perpendicular bisector of $AB$ is here in blue.}\n\t\\label{fig:pb}\n\\end{figure}\n\nThe perpendicular bisector (abbr. PB) is a line that cuts another line in the middle and sits at right angles.\n\nTo find the PB of a line $AB$:\n\\begin{enumerate}\n\t\\item find the mid point $AB$,\n\t\\item find $m_{AB}$,\n\t\\item find $m_\\perp$,\n\t\\item use $y-b=m(x-a)$ with the mid point $AB$ and $m_\\perp$.\n\\end{enumerate}\n\n\\subsection{Example}\nTwo points are $A(-2,1)$ and $B(4,7)$ are connected by a line. Find the equation of the perpendicular bisector.\n\n\\begin{align*}\n\t\\text{mid point} &= \\left(\\frac{-2+4}{2},\\frac{1+7}{2}\\right) & m_{AB} &= \\frac{7-1}{4-(-2)} & m_\\perp&=-1\\\\\n\t&=(1,4) & &=1\n\\end{align*}\n\\begin{align*}\n\ty-b&=m(x-a)\\\\\n\ty-4&=-1(x-1)\\\\\n\ty&=-x+1+4\\\\\n\ty&=-x+5\n\\end{align*}\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{tikzpicture}\n\t[\n\t\tscale=0.5,\n\t\t% Make a style for a black coordinate.\n\t\tcmark/.style={label={[anchor=center, color=black]:\\pgfuseplotmark{#1}}},\n\t\t% And one for a blue coordinate.\n\t\tbmark/.style={label={[anchor=center, color=blue]:\\pgfuseplotmark{#1}}}\n\t]\n\t\t\\coordinate\n\t\t[\n\t\t\tlabel=left:{$A(-2,1)$},\n\t\t\tblack,\n\t\t\tcmark=*,\n\t\t\t] (a) at (-2,1);\n\t\t\\coordinate\n\t\t[\n\t\t\tlabel=right:{$B(4,7)$},\n\t\t\tblack,\n\t\t\tcmark=*,\n\t\t] (b) at (4,7);\n\t\t\\coordinate (p) at (0,5);\n\t\t\\coordinate [label=right:{$y=-x+5$}] (q) at (2,3);\n\t\t\n\t\t% Draw line\n\t\t\\draw (a) -- (b);\n\t\t\\draw[blue] (p) -- (q);\n\t\\end{tikzpicture}\n\t\\caption{Perpendicular bisector in blue. Note that this is only to show what's happening, it's not required to sketch this in an exam unless specifically asked for.}\n\t\\label{fig:PBexample}\n\\end{figure}\n\n\n\\section{Intersection of Lines}\nThe point of intersection (abbr. POI) of two lines can be found through solving each line's equation simultaneously.\n\nThe National 5 course most likely focussed on the method of elimination, a better method is to use substitution. However, sometimes, such as in the second example, the equations are so simple that it would be stupid to not eliminate.\n\n\\subsection{Examples}\n\\begin{enumerate}\n\t\\item\n\tTwo lines have equations $2x-y+11=0$ and $x+2y-7 = 0$. Find the point of intersection.\n\t\n\t\\begin{align*}\n\t\t2x-y+11&=0\\\\\n\t\ty&=2x+11\n\t\\end{align*}\n\tSub $y=2x+11$ into $x+2y-7=0$,\n\t\\begin{align*}\n\t\tx+2(2x+11)-7&=0\\\\\n\t\tx+4x+22-7&=0\\\\\n\t\t5x+15&=0\\\\\n\t\t5x&=-15\\\\\n\t\tx&=-3\n\t\\end{align*}\n\t\\begin{align*}\n\t\ty&=2x+11 & POI=(-3,5)\\\\\n\t\ty&=2(-3)+11\\\\\n\t\t&=-6+11\\\\\n\t\t&=5\n\t\\end{align*}\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[bmark/.style={label={[anchor=center, color=blue]:\\pgfuseplotmark{#1}}}]\n\t\t\t\\begin{axis}\n\t\t\t[\n\t\t\t\txlabel=$x$,\n\t\t\t\tylabel=$y$,\n\t\t\t\txmin=-6,\n\t\t\t\txmax=2,\n\t\t\t\txtick={-6,-5,...,1},\n\t\t\t\tymin=0,\n\t\t\t\tymax=7,\n\t\t\t\tytick={0,1,...,6},\n\t\t\t\taxis lines=center,\n\t\t\t\taxis equal,\n\t\t\t\tsmooth,\n\t\t\t\tscale=0.8,\n\t\t\t]\n\t\t\t\t\\addplot [color=black,mark=none] {2*x+11};\n\t\t\t\t\\addplot [color=black,mark=none] {3.5-0.5*x};\n\t\t\t\t\\coordinate\n\t\t\t\t[\n\t\t\t\t\tlabel=right:{$(-3,5)$},\n\t\t\t\t\tbmark=*,\n\t\t\t\t] (a) at (-3,5);\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Solution to the first example, point of intersection in blue. Again, it's not required to sketch these two lines, this figure is simply there to give further clarification as to what's happening.}\n\t\t\\label{fig:POIexample}\n\t\\end{figure}\n\t\n\t\\item\n\tIn triangle $ABC$ with points $A(1,0)$, $B(-4,3)$, $C(0,-1)$, find the median from A, the altitude from C, and henceforth the POI.\n\t\n\t\\textit{Median from A:}\n\t\\begin{align*}\n\t\t\\text{mid point} &= \\left(\\frac{-4+0}{2},\\frac{3+(-1)}{2}\\right) & m &= \\frac{3-0}{-4-1} \\\\\n\t\t&= (-2,1) & &=-\\frac{1}{3}\n\t\\end{align*}\n\t\\begin{align*}\n\t\ty-b&=m(x-a)\\\\\n\t\ty-1&=-\\frac{1}{3}\\left(x+2\\right)\\\\\n\t\t3y-3&=-\\left(x+2\\right)\\\\\n\t\t3y&=-x-2+3\\\\\n\t\t3y&=-x+1\n\t\\end{align*}\n\t\n\t\\textit{Altitude from C:}\n\t\\begin{align*}\n\t\tm_{AB}&=\\frac{3-0}{-4-1} & m_\\perp&=\\frac{5}{3} \\\\\n\t\t&=-\\frac{3}{5}\n\t\\end{align*}\n\t\\begin{align*}\n\t\ty-b&=m(x-a)\\\\\n\t\ty+1&=\\frac{5}{3}\\left(x+0\\right)\\\\\n\t\t3y+3&=5\\left(x+0\\right)\\\\\n\t\t3y&=5x-3\n\t\\end{align*}\n\t\n\t\\textit{Point of intersection:}\n\t\\begin{align*}\n\t\t3y&=-x+1 & 3y&=-x+1\\\\\n\t\t\\makebox[0pt][l]{\\uline{\\phantom{$--3y=5x-3$}}}\n\t\t-\\;\\;3y&=5x-3 & 3y&=-\\frac{2}{3}+1\\\\\n\t\t0&=-6x+4 & 9y&=-2+3\\\\\n\t\t6x&=4 & 9y&=1\\\\\n\t\tx&=\\frac{2}{3} & y=\\frac{1}{9}\\\\\n\t\\end{align*}\n\t\\begin{equation*}\n\t\tPOI = \\left(\\frac{2}{3},\\frac{1}{9}\\right)\n\t\\end{equation*}\n\\end{enumerate}\n", "meta": {"hexsha": "7e117d82087998b2b500e20018caa41945257a90", "size": 14545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX_files/StraightLine.tex", "max_stars_repo_name": "TheSheepGuy/Open_Higher_Maths", "max_stars_repo_head_hexsha": "2667a8da00b2cab502a92fd0ec9c9db9c86bea5c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-12-09T14:56:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-09T15:08:38.000Z", "max_issues_repo_path": "TeX_files/StraightLine.tex", "max_issues_repo_name": "TheSheepGuy/Definitive_Higher_Maths", "max_issues_repo_head_hexsha": "2667a8da00b2cab502a92fd0ec9c9db9c86bea5c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-09T15:22:21.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-11T20:19:01.000Z", "max_forks_repo_path": "TeX_files/StraightLine.tex", "max_forks_repo_name": "TheSheepGuy/Definitive_Higher_Maths", "max_forks_repo_head_hexsha": "2667a8da00b2cab502a92fd0ec9c9db9c86bea5c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-09T20:16:01.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-09T20:16:01.000Z", "avg_line_length": 25.1643598616, "max_line_length": 256, "alphanum_fraction": 0.6118253695, "num_tokens": 5995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.80563219364797, "lm_q1q2_score": 0.6895012458535952}}
{"text": "\\documentclass{article}\n%Some packages I commonly use.\n\\usepackage{amsmath}\n\n%A bunch of definitions that make my life easier\n\n\\title{JPCB 2013 Detailed Math}\n\\author{Yi-Tsao Chen}\n\\date{April 2019}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{From Langevin to Fokker-Planck}\n\n\\begin{equation}\n\\label{eq:ODLD}\ndx_t=D F(x_t)dt  + \\sqrt{2D}d{W}_t\n\\end{equation}\n\n\\begin{equation}\n\\begin{split}\nx(t+d{t}) = x(t) + D F(x_t) d{t} + \\sqrt{2D}d{W}_t \\\\\n= x(t) + D F(x_t) d{t} + \\xi(t) d{t}\n\\end{split}\n\\end{equation}\n\nwhere\n\n\\begin{equation}\n\\begin{cases}\n\\xi(t) d{t} =  \\sqrt{2D}d{W}_t \\\\\n\\langle \\xi(t) \\rangle = 0 \\\\\n\\langle \\xi(t)^2 \\rangle = \\frac{2D}{d{t}} \\\\\n\\langle (\\xi(t) d{t})^2 \\rangle = 2D d{t} \\\\\n\\ P_{G}(\\xi(t) d{t})= \\frac{1}{\\sqrt{4 \\pi D d{t}}}exp{(\\frac{-\\xi^2}{4D d{t}})}\n\\end{cases}\n\\end{equation}\n\nAccording to the Chapman-Kolmogorov equation:\n\\begin{equation}\n\\label{eq:lgtofk1}\n\\begin{split}\nP(x, t+d{t}) = \\int \\int P(y,t) P_{G}(\\xi d{t}) \\delta(x-y-D F d{t} - \\xi d{t}) d{(\\xi d{t})} d{y} \\\\\n= \\int \\int P(y,t) P_{G}(\\xi d{t}) \\delta(y - (x -D F d{t} - \\xi d{t})) d{(\\xi d{t})} d{y} \\\\\n= \\int P(x -D F d{t} - \\xi d{t}, t) P_{G}(\\xi d{t}) d{(\\xi d{t})} \\\\\n= \\int P(x  + (-D F - \\xi) d{t}, t) P_{G}(\\xi d{t}) d{(\\xi d{t})} \\\\\n= \\int ( P(x,t) + (-D F - \\xi) d{t} \\frac{\\partial P(x,t)}{\\partial x} + \\frac{(-D F - \\xi)^2 d{t}^2}{2}\\frac{\\partial^2 P(x,t)}{\\partial x^2})P_{G}(\\xi d{t}) d{(\\xi d{t})}\\\\\n=P(x,t)- D F d{t}\\frac{\\partial P(x,t)}{\\partial x} + \\frac{D^2 F^2 d{t}^2}{2}\\frac{\\partial^2 P(x,t)}{\\partial x^2}+ D d{t} \\frac{\\partial^2 P(x,t)}{\\partial x^2}\n\\end{split}\n\\end{equation}\n\nThe last two lines in equation (\\ref{eq:lgtofk1}) we used the following:\n\\begin{equation}\n\\int P(x,t) P_{G}(\\xi d{t}) d{(\\xi d{t})} = P(x,t) \\int P_{G}(\\xi d{t}) d{(\\xi d{t})} = P(x,t)\n\\end{equation}\n\n\\begin{equation}\n\\int (-D F d{t}) P_{G}(\\xi d{t}) d{(\\xi d{t})} = P(x,t) \\int P_{G}(\\xi d{t}) d{(\\xi d{t})} = -D F d{t}\n\\end{equation}\n\n\\begin{equation}\n\\int (-\\xi d{t}) P_{G}(\\xi d{t}) d{(\\xi d{t})} = \\langle \\xi(t)d{t} \\rangle = 0\n\\end{equation}\n\n\\begin{equation}\n\\begin{split}\n\\frac{1}{2} \\int (D^2 F^2 d{t}^2 - 2 DF\\xi d{t}^2 + \\xi^{2}d{t}^2) P_{G}(\\xi d{t}) d{(\\xi d{t})} \\\\\n= \\frac{D^2F^2 d{t}^2}{2} + \\frac{\\langle (\\xi(t) d{t})^2 \\rangle}{2} \\\\ \n= \\frac{D^2F^2 d{t}^2}{2} + D d{t}\n\\end{split}\n\\end{equation}\n\nThen, continue equation (\\ref{eq:lgtofk1}),\n\\begin{equation}\n\\frac{P(x, t+d{t}) - P(x,t)}{dt} = - D F \\frac{\\partial P(x,t)}{\\partial x} + \\frac{D^2 F^2 d{t}}{2}\\frac{\\partial^2 P(x,t)}{\\partial x^2}+ D \\frac{\\partial^2 P(x,t)}{\\partial x^2}\n\\end{equation}\nand make $d{t}$ very small,\n\\begin{equation}\n\\lim_{d{t}\\to 0}\\frac{P(x, t+d{t}) - P(x,t)}{dt} = - D F \\frac{\\partial P(x,t)}{\\partial x} + D \\frac{\\partial^2 P(x,t)}{\\partial x^2}\n\\end{equation}\n\nwhere the second term disappears because\n\\begin{equation}\n\\lim_{d{t}\\to 0}\\frac{D^2 F^2 d{t}}{2}\\frac{\\partial^2 P(x,t)}{\\partial x^2} = 0\n\\end{equation}\nAt last, we obtain Fokker-Planck equation,\n\n\\begin{equation}\n\\label{eq:FP}\n\\frac{\\partial P(x,t)}{\\partial t} = D \\frac{\\partial^2 P(x,t)}{\\partial x^2} - D F \\frac{\\partial P(x,t)}{\\partial x} \n\\end{equation}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "4e2b04c21b3f389b87bea4ac65c3e1615bdbad13", "size": 3158, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/fret_technicalreport.tex", "max_stars_repo_name": "yizaochen/em_theory", "max_stars_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_stars_repo_licenses": ["MIT"], "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/fret_technicalreport.tex", "max_issues_repo_name": "yizaochen/em_theory", "max_issues_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_issues_repo_licenses": ["MIT"], "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/fret_technicalreport.tex", "max_forks_repo_name": "yizaochen/em_theory", "max_forks_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_forks_repo_licenses": ["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.2244897959, "max_line_length": 180, "alphanum_fraction": 0.5715642812, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6895012389643711}}
{"text": "\\section{Model}\n\\subsection{Notation}\nBefore presenting the model we describe some notation used through out the appendix. For a $m \\times n$ matrix $r$ we use the following broadcasting notation $\\mv{r}_{k,j:l}=[ r_{k,j}, r_{k,j+1}, \\ldots, r_{k,l}]$.\nFurther $x | y \\sim \\pi(.)$ implies that the random variable $x$ if we conditioning on $y$ follows distribution $\\pi(.)$.\nThe relevant variables in the model are the following:\n\n\t\\begin{tabularx}{\\linewidth}{ccL}\n\t\tVariable name & Dimension & Description \\\\  \\hline\n\t\t$\\mv{d}$ & $T \\times 1$ & $d_i$ is the number of deaths that occurred day $i$. \\\\\n\t\t$\\mv{r}$ & $T \\times T$ & $r_{ij}$ is number of death recorded for day $i$ at day $j$.  Note that $r_{ij}$ for $i<j$ is not defined.   \\\\\n\t\t$\\mv{p}$ & $T \\times T$ & $p_{ij}$ is the probability of that a death for day $i$ not yet recorded is recorded at day $j$.\n\t\t  Note that $p_{ij}$ for $i<j$ is not defined.  \\\\\n\t\t$\\mv{\\alpha}$ & $K \\times 1$ & Latent prior parameter for $\\mv{p}$ \\\\\n\t\t$\\mv{\\beta}$ & $K \\times 1$ & Latent prior parameter for $\\mv{p}$ \\\\\n\t\t$\\mv{\\alpha}^H$ & $2 \\times 1$ & parameter for the probability, $\\mv{p}$ for holiday adjustment. \\\\\n\t\t$\\mv{\\beta}^H$ & $2 \\times 1$ & parameter for the probability, $\\mv{p}$ for holiday adjustment. \\\\\n\t\t$\\mv{\\mu}$ &  $T \\times 1$ &  $\\mu_i$  is the intensity of the expected number of deaths at day $i$. \\\\\n\t\t$\\sigma^2$ & $1\\times 1$ & Variation of the random walk prior for the log intensity. \\\\\n\t\t$\\phi$ & $1\\times 1$ & overdispersion parameter for negative binomial distribution. \\\\\n\t\t$p_0$ & $1\\times 1$ & probability of reporting for a low reporting event. \\\\\n\t\t$pi$ & $1\\times 1$ & probability of a low reporting event.\n\t\\end{tabularx}\n\\subsection{likelihood}\nThe most complex part of our model is the likelihood, i.e. the density of the observations given the parameters. Here the data consist the daily report of recorded deaths for the past days. This can conveniently be represented upper triangular matrix, $\\mv{r}$, where $r_{i,j}$ represents number of new reported deaths for day $i$ reported at day $j$. This matrix is displayed on the left in Table \\ref{tab:Data}.\n\n\\begin{table}\n\t\\centering\n\t\\begin{tabular}{cccccc}\n\t\t\\multicolumn{1}{c}{} & \\multicolumn{5}{c}{Reported date}                                             \\\\\n\t\t\\parbox[t]{2mm}{\\multirow{5}{*}{\\rotatebox[origin=c]{90}{Death date}}}   & $r_{11}$ & $r_{12}$ & $\\cdots$ &$\\cdots$  &  $r_{1T}$\\\\\n\t\t& & $r_{22}$ &  $\\cdots$ & $\\cdots$   &$r_{2T}$ \\\\\n\t\t& & &$r_{33}$ &  $\\cdots$ &  $r_{3T}$ \\\\\n\t\t& & & &  $\\ddots$ & $\\vdots$  \\\\\n\t\t& & & &  &  $r_{TT}$ \\\\\n\n\t\\end{tabular}\n\n\t\\caption{The table describes the observations data.}\n\t\\label{tab:Data}\n\\end{table}\n\n We assume that given the true number of deaths at day $i$, $d_i$, that each reported day $j$ the remaining death $d_i - \\sum_{k=1}^{j-1}r_{i,k}$ each recored with probability $p_{ij}$, i.e. $$r_{i,j}|D_i,r_{1,1:j}.p \\sim Bin(d_i - \\sum_{k=1}^{j-1}r_{i,k}, p_{i,j}).$$\n\nTypically in removal sampling one would set the probability of reporting uniform, i.e. $p_{i,j}:=p$. However for this data this is clearly not realistic given weekly patterns in reporting --very little reporting during the weekends. Instead we assume that we have $k$ different probabilities. Further, to account for overdispertion, we assume that each probability rather being a fixed scalar is a random variable with a Beta distribution. The Beta distribution has two parameters $\\alpha$ and $\\beta$. This resulting the following distribution for the probabilities\n$$\np_{i,j}| \\mv{\\alpha},\\mv{\\beta}, \\mv{\\alpha}^H,\\mv{\\beta}^H  \\sim Beta(\\alpha^H_j\\alpha_{min(j-i,k)},\\beta^H_j\\beta_{min(j-i,k)}).\n$$\nHere, if $j\\in H$ then day $j$ is a holidays or weekends, and the parameters above are\n$$\n\\alpha^H_j = \\begin{cases}\n\\alpha_1^H \\alpha_2^H & \\mbox{if }  \\{j\\in H \\}\\cup  \\{j-1\\in H \\},  \\\\\n\\alpha_1^H & \\mbox{if }  \\{j\\in H \\}\\cup  \\{j-1\\in H^c \\}, \\\\\n\\alpha_2^H & \\mbox{if }  \\{j\\in H^c \\}\\cup  \\{j-1\\in H \\}, \\\\\n1 & \\mbox{else,}\n\\end{cases}\n$$\nand\n$$\n\\beta^H_j = \\begin{cases}\n\\beta_1^H \\beta_2^H & \\mbox{if }  \\{j\\in H \\}\\cup  \\{j-1\\in H \\},  \\\\\n\\beta_1^H & \\mbox{if }  \\{j\\in H \\}\\cup  \\{j-1\\in H^c \\}, \\\\\n\\beta_2^H & \\mbox{if }  \\{j\\in H^c \\}\\cup  \\{j-1\\in H \\}, \\\\\n1 & \\mbox{else.}\n\\end{cases}\n$$\nThese extra parameters are created to account for the under-reporting that occurs during weekend and holidays.\nFinally we add an extra mixture component that allows for very low reporting.\n\n\\subsection{Priors}\nFor the $\\mv{\\alpha}$ and $\\mv{\\beta}$ parameters we use an (improper) uniform prior. For the deaths, $\\mv{d}$, one could imagine several different prior ideally some sort of epidemiological model. However, here we just assume a log-Gaussian Cox processes \\citep{Moller1998_log_gaussian}, but instead of Poisson distribution we use a negative binomial to handle possible over dispersion. The latent Gaussian processes has a intrinsic random walk distribution \\citep{Rue2005_gaussian_markov} i.e.\n\\begin{align*}\n\\log(\\mu_i) - \\log(\\mu_{i-1}) &\\sim N(0,\\sigma^2),\\\\\nd_i| \\lambda_i  &\\sim NegBin(\\mu_i, \\phi).\n\\end{align*}\nThis model is created to create a temporal smoothing between the reported deaths.\nFor the hyperparameter $\\sigma^2$ we impose a inverse Gamma distribution, this prior is suitable here because it guarantees that the process is not constant ($\\sigma^2=0$) which we know is not the case.\n\\subsection{Full model}\nPutting the likelihood and priors together we get the following hierarchical Bayesian model\n\\begin{align*}\n\\sigma^2 &\\sim \\Gamma(1,0.01) \\\\\n\\phi &\\sim \\Gamma(1,0.01) \\\\\n\\alpha_k &\\sim U[0,\\infty] \\\\\n\\beta_k &\\sim U[0,\\infty] \\\\\n\\alpha_k^H &\\sim U[0,\\infty] \\\\\n\\beta_k^H &\\sim U[0,\\infty] \\\\\n\\log(\\mu_i) - \\log(\\mu{i-1}) &\\sim N(0,\\sigma^2)\\\\\nd_i| \\lambda_i  &\\sim NegBin(\\mu_i,\\phi) \\\\\np_{i,j}|  \\mv{\\alpha},\\mv{\\beta}, \\mv{\\alpha}^H,\\mv{\\beta}^H &\\sim Beta(\\alpha^H_j\\alpha_{min(j-i,k)},\\beta^H_j\\beta_{min(j-i,k)}) \\\\\nr_{i,j}|d_i,\\mv{r}_{1,1:j},p &\\sim \\pi Bin(d_i - \\sum_{k=1}^{j-1}r_{i,k},p_0)+ (1-\\pi) Bin(d_i - \\sum_{k=1}^{j-1}r_{i,k}, p_{i,j}),\n\\end{align*}\nwhere where and $j\\leq i$ and $i=1,\\ldots,T$.\n\n\\section{Inference}\nAs the main goal to generate inference of the number of death $\\mv{d}$ is through the posterior distribution of number of deaths $\\mv{d}$ given the observations $\\mv{r}$.\nIn order to generate samples from this distribution we use a Markov Chain Monte Carlo method \\citep{Brooks2011_handbook_markov}. In more detail we use a blocked Gibbs sampler, which generates samples in the following sequence:\n\\begin{itemize}\n\t\\item  We sample $\\mv{\\alpha},\\mv{\\beta}, \\mv{\\alpha}^H,\\mv{\\beta}^H|\\mv{d}, \\mv{r}$ using the fact that one can integrate out $p$ in the model, and then  $\\mv{d}|\\mv{\\alpha},\\mv{\\beta}, \\mv{\\alpha}^H,\\mv{\\beta}^H,\\mv{r},\\mv{\\lambda}$  follows a Beta-Binomial distribution. Here to we use an adaptive MALA \\citep{Atchade2006_adaptive_version} to sample from these parameters.\n\t\\item  To sample $\\mv{d}|\\mv{\\alpha},\\mv{\\beta}, \\mv{\\alpha}^H,\\mv{\\beta}^H,\\mv{r},\\mv{\\lambda}$, that each death, $d_i$ is conditionally independent, and we just use a Metropolis Hastings random walk to sample each one.\n\t\\item To sample $\\mv{\\lambda} | \\mv{d},\\sigma^2$ we again use an adaptive MALA.\n\t\\item Finally We sample $\\sigma^2|\\mv{d}$,and  $p_0,\\pi$ directly since this distribution is explicit, and $\\phi$ using a MH-RW.\n\\end{itemize}\n\n\\section{Model Benchmark}\nIn this section, we present additional comparison of the model to the benchmark. We first describe the benchmark model in detail.\n\nThe benchmark model simply takes the sum of average historical reporting lags for the preceding 14 days. As before $r_{ij}$ is the number of deaths that happened on day $i$ and were recorded on day $j$. To predict the number of people that died on a given day, we first calculate lag averages:\n\n\\begin{align}\n    \\hat{r}_{i, i+L} = \\frac{\\sum^{14}_{k=i-14} r_{k - L, k}}{14},\n\\end{align}\n\nwhere $\\hat{r}_{i, i+L}$ is the average number of deaths reported with a lag of $L$ days, based on the 14 reports closest preceding day $i$. If we are looking at data released $2020-04-28$ and call this day 0, the latest death date that we have 10-day ($L=10$) reporting lag observation for is $r_{-10,0}$. The average for $Lag(0, 10)$ is therefore taken over the 14 days between $r_{-24,-14}$ and $r_{-10,0}$ (2020-04-04 and 2020-04-18). For this reason, some of the earlier predictions will not have data from $14$ days. The average is then taken over all available reports.\n\nIn the comparisons we aim at predicting the total number of deaths that will have been reported within 14 days of the death date. To do so, we sum over the average lag that has yet to be reported. If we are predicting the number of people that have yet to be reported dead for day -3, we already know the true values for $r_{-3,-3}$, $r_{-3,-2}$, $r_{-3,-1}$, and $r_{-3,0}$ so we only need to predict $r_{-3,1}\\ldots r_{-3,10}$. The prediction is then\n\n\\begin{align}\n    Benchmark(i, j) = \\sum_{l=i}^{j} r_{i,l}+ \\sum_{l = j}^{14} \\hat{r}_{i, l}.\n\\end{align}\n\nAs confidence interval we simply use a Normal assumption with standard deviations of the reporting lags, assuming independence, i.e. this is just the square root of the sum of $Var(\\hat{r})$.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{plots/SCRPS_over_states}\n    \\caption{Average SCRPS as the pandemic progresses.}\n    \\label{fig:SCRPS_states}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{plots/SCRPS_over_weekdays}\n    \\caption{Average SCRPS per weekday.}\n    \\label{fig:SCRPS_weekdays}\n\\end{figure}", "meta": {"hexsha": "7e55bdef2fcd5a09287a9898de0346067d65177d", "size": 9639, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "output/paper/appendix.tex", "max_stars_repo_name": "adamaltmejd/covid_reporting_delay_prediction", "max_stars_repo_head_hexsha": "d518e978b296fca3d99089c01f3d56ac09dc8e17", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "output/paper/appendix.tex", "max_issues_repo_name": "adamaltmejd/covid_reporting_delay_prediction", "max_issues_repo_head_hexsha": "d518e978b296fca3d99089c01f3d56ac09dc8e17", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "output/paper/appendix.tex", "max_forks_repo_name": "adamaltmejd/covid_reporting_delay_prediction", "max_forks_repo_head_hexsha": "d518e978b296fca3d99089c01f3d56ac09dc8e17", "max_forks_repo_licenses": ["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.9328358209, "max_line_length": 576, "alphanum_fraction": 0.6802572881, "num_tokens": 3150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6894950638057696}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - No consecutive integers}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - No consecutive integers}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{No consecutive integers}\n\n\\newthought{Integer equations} and multisets are the topics of the problem \\footnote{Variation of Problem 1-72. on page 45 in \\bibentry{loehr2017combinatorics}} in this note.\\index{integer equation}\\index{multiset}\n\n\\vspace{10 mm}\n\\begin{problem}\nDetermine the number of subsets of size $k$ from set $\\{1, 2, \\ldots, n\\}$ that do not contain consecutive integers.\n\\end{problem}\n\nThe number of subsets of size $k$ from set $\\{1, 2, \\ldots, n\\}$ (without any constraints) is given by the binomial coefficient $\\binom{n}{k}$. Each subset of size $k$ can be represented as a word of length $n$ from alphabet $\\{\\bigstar, \\talloblong\\}$ with $k$ $\\talloblong$'s and $n-k$ $\\bigstar$'s: if $i$ is in the subset then the corresponding word has a $\\talloblong$ at position $i$ otherwise it has a $\\bigstar$ at position $i$. This representation is clearly a bijection. The constraint of no consecutive integers in a subset implies no adjacent $\\talloblong$'s in the corresponding word\\footnote{For example given set $\\{1, 2, 3, 4\\}$ the subset $\\{2, 4\\}$ corresponds to $\\bigstar\\talloblong\\bigstar\\talloblong$. The subset $\\{1, 2\\}$ has consecutive integers and corresponds to $\\talloblong\\talloblong\\bigstar\\bigstar$. The reason why we chose $\\talloblong$ to indicate inclusion into a subset will become clear soon.}.\n\nWe will now associate words from $\\{\\bigstar, \\talloblong\\}^n$ with other combinatorial objects: the integer equations.\n\n\\begin{defn}\nGiven fixed integers $m > 0$ and $t \\geq 0$ a sequence $(z_1, z_2, \\ldots, z_m)$ is an \\textbf{integer equation} if $\\forall i: 1 \\leq i \\leq m: z_i \\in \\mathbb{N}_0$ and\n$$\n\\sum_{i = 1}^m z_i = t\n$$\nThe number $t$ is called the \\textbf{target}\tof the integer equation.\n\\end{defn}\n\nNote that these are sequences and order matters. From an integer equation $(z_1, z_2, \\ldots, z_m)$ we construct a $\\{\\bigstar, \\talloblong\\}^{t + m - 1}$ word in the following way: start with $z_1$ number of $\\bigstar$'s, then a $\\talloblong$, then $z_2$ number of $\\bigstar$'s, then a $\\talloblong$ and so on finishing with the $z_m$ number of $\\bigstar$'s which are \\textbf{not} followed by a $\\talloblong$. The word will contain exactly $t$ $\\bigstar$'s and they will need exactly $m - 1$ $\\talloblong$ separators to know which stars belong to which $z_i$. It's easy to verify that this encoding is also a bijection\\footnote{As an example let $m = 5$ and target $t = 10$. The sequence $(1, 2, 1, 3, 3)$ is an integer equation since \n$$\n1 + 2 + 1 + 3 + 3 = 10\n$$ \nand it corresponds to the word \n$$\n\\bigstar\\talloblong\\bigstar\\bigstar\\talloblong\\bigstar\\talloblong\\bigstar\\bigstar\\bigstar\\talloblong\\bigstar\\bigstar\\bigstar\n$$\nThis in turn corresponds to the subset $\\{2, 5, 7, 11\\}$ of set $\\{1, \\ldots, 14\\}$.}.\n\n\\begin{lem}\\label{consec_ints_association}\nIf we set $t = n - k$ (the number of $\\bigstar$'s) and from $t + m - 1 = n$ we get $m = k + 1$ (the word length) then we can associate subsets of size $k$ from set $\\{1, 2, \\ldots, n\\}$ with integer equations $(z_1, z_2, \\ldots, z_{k + 1})$ for target $n - k$. The constraint of not having consecutive integers in the subsets translates to integer equations $(z_1, z_2, \\ldots, z_{k + 1})$ where $z_i > 0$ except for $z_1$ and $z_{k + 1}$ (the first and the last in the sequence). This follows from the encoding not allowing adjacent $\\talloblong$'s so there need to be $\\bigstar$'s separating the $\\talloblong$'s.\n\\end{lem}\n\nAccording to this association if we can count the number of integer equations with all but the first and last $z_i$ strictly positive then we also have the number of subsets with no consecutive integers. To get there we will first count the number of anagrams, then the number of multisets, then the number of integer equations and finally the number of integer equations with all but the first and last $z_i$ strictly positive. In what follows we will use $n$ and $k$ for other things before we bring it back in the end to our initial problem.\n\nLet's start this journey with anagrams. Let $\\{s_1, s_2, \\ldots, s_k\\}$ be an alphabet of distinct symbols. We can build words with these symbols, for example $s_2s_2s_1s_3s_3s_1$. As a notational convenience $s_is_is_i \\ldots s_i=s_i^j$ if $s_i$ appears $j$ consecutive times in a word, so the example would be $s_2^2s_1s_3^2s_1$.\n\n\\begin{defn}\nA word is an \\textbf{anagram}\\footnote{For example given word $a^2b$ the words $aba$ and $baa$ are anagrams of it. The word $abb$ is not.} of $s_1^{n_1}s_2^{n_2} \\ldots s_k^{n_k}$ with $n_i > 0$ if it is a word containing exactly $n_i$ number of $s_i$ symbols for each $1 \\leq i \\leq k$. We denote with $\\mathcal{A}(s_1^{n_1}s_2^{n_2} \\ldots s_k^{n_k})$ the set of all anagrams of $s_1^{n_1}s_2^{n_2} \\ldots s_k^{n_k}$.\n\\end{defn}\n\n\\begin{thm}\\label{num_anagrams}\nGiven the set of anagrams $\\mathcal{A}(s_1^{n_1}s_2^{n_2} \\ldots s_k^{n_k})$  let $n = \\sum_{i = 1}^k n_k$. Then\n$$\n|\\mathcal{A}(s_1^{n_1}s_2^{n_2} \\ldots s_k^{n_k})| = \\binom{n}{n_1,n_2, \\ldots, n_k}\n$$\t\nwhere $\\binom{n}{n_1,n_2, \\ldots, n_k}$ is the multinomial coefficient\\footnote{The multinomial coefficient is defined as\n$$\n\\binom{n}{n_1,n_2, \\ldots, n_k} = \\frac{n!}{\\prod_{i = 1}^k n_i!}\n$$}.\n\\end{thm}\n\n\\begin{proof}\nWe have $n$ positions in our word that we need to fill with symbols. We are going to make the following choices: first we choose $n_1$ positions from those $n$ positions where we fill in the symbol $s_1$. Then we choose the $n_2$ positions from the remaining unfilled positions where we fill in $s_2$ and so on. In total we make $k$ such choices and the number of remaining unfilled positions at each stage is independent of the previous choices, so the multiplication rule applies. For our first symbol $s_1$ we have $\\binom{n}{n_1}$ possibilities, for our second symbol we have $\\binom{n - n_1}{n_2}$ possibilities and so on. Because of the multiplication rule the total number of choices is the product of all these binomial coefficients, so\n$$\n|\\mathcal{A}(s_1^{n_1}s_2^{n_2} \\ldots s_k^{n_k})| = \\prod_{i = 1}^k \\binom{n - (\\sum_{j = 1}^{i - 1})}{n_i}\n$$\n\nExpanding\\footnote{After the binomial coefficients are expanded the product becomes a telescoping product that simplifies to exactly the multinomial coefficient.} the binomial coefficients on the right-hand side into factorials according to the binomial coefficient definition and simplifying the expression gives us the desired result.\n\\end{proof}\n\nWe move on to \\textbf{multisets}. Informally multisets are sets (order does not matter) where each element can appear more than once. So given a set $A$ (the alphabet) a multiset is a tuple of $A$ together with a function $\\mu: A \\mapsto \\mathbb{N}$ that determines how often an element $a \\in A$ appears in the multiset. For notational convenience we will use curly braces and list elements (with exponents if they appear more than once). For example $\\{a^2, b, c^4\\}$ is a multiset where $a$ appears twice, $b$ once and $c$ four times. Note that order does not matter, so $\\{a^2, b, c^4\\}$ is the same multiset as $\\{b, a^2, c^4\\}$. The size of the multiset is the number of elements in it with elements appearing more than once counted accordingly, so \n$$\n|(A, \\mu)| = \\sum_{a \\in A} \\mu(a)\n$$\n\n\\begin{thm}\\label{num_multisets}\nThe number of multisets of size $k$ from an alphabet set of size $n$ is\\footnote{For example with alphabet set $\\{a, b\\}$ the multisets of size two are $\\{a^2\\}$, $\\{b^2\\}$, $\\{a, b\\}$, so there are three of them.}\n$$\n\\binom{k + n - 1}{k}\n$$\n\\end{thm}\n\n\\begin{proof}\nWe will do an encoding of multisets to anagrams similar to what we did at the beginning of this section with $\\bigstar$'s and $\\talloblong$'s. To avoid confusion with that previous encoding in this proof we will use the symbols $\\circ$ and $|$.\n\nLet $A=\\{a_1, a_2, \\ldots, a_n\\}$ be our alphabet. For a multiset $(A, \\mu)$ with size $k$ we define the following word\\footnote{The multisets from the previous example would be encoded as follows:\n\\begin{align*}\n\\{a^2\\} & \\mapsto \\circ\\circ|\\\\\n\\{b^2\\} & \\mapsto |\\circ\\circ\\\\\n\\{a, b\\} & \\mapsto \\circ|\\circ\n\\end{align*}} with symbols $\\{\\circ,|\\}$:\n$$\n\\circ^{\\mu(a_1)}|\\circ^{\\mu(a_2)}| \\ldots |\\circ^{\\mu(a_n)}\n$$\nThe first circles denote how often $a_1$ is in the multiset. They are separated by a $|$ from the circles that denote how often $a_2$ is in the multiset and so on. In total there are $k$ circles because the multiset has size $k$ and there need to be $n-1$ separators because the alphabet has size $n$ and the circles for each element need to be kept apart. It's easy to see that we have defined a bijection from the set of multisets of size $k$ with alphabet of size $n$ to the set of anagrams $\\mathcal{A}(\\circ^k|^{n-1})$. From theorem \\ref{num_anagrams} we already know how to count the size of $\\mathcal{A}(\\circ^k|^{n-1})$ and with the bijection it proves this theorem.\n\\end{proof}\n\nOur next stop are the number of integer equations. Given $m$ and $t$ how many integer equations $(z_1, z_2, \\ldots, z_m)$ for target $t$ are there?\n\n\\begin{thm}\\label{num_int_equations}\nThe number of integer equations $(z_1, z_2, \\ldots, z_m)$ for target $t$ is\n$$\n\\binom{t + m - 1}{t}\n$$\n\\end{thm}\n\n\\begin{proof}\nWe will associate a multiset with each integer equation\\footnote{For example with $m = 5$ and target $t = 10$ the integer equation $(1, 2, 1, 3, 3)$ would correspond to multiset $\\{1, 2^2, 3, 4^3, 5^3\\}$.}. The multiset will contain the element $i$ $z_i$ many times, for $1 \\leq i \\leq m$. Again it can be checked that this defines a bijection. These multisets belong to the set of multisets of size $t$ from an alphabet of size $m$ and theorem \\ref{num_multisets} counts them. By the bijection rule we have proven this theorem.\n\\end{proof}\n\nWe are almost done. In the beginning of this section we encoded our subsets without consecutive integers as integer equations with all but the first and last summand strictly positive. So we need to count these types of integer equations with this constraint.\n\n\\begin{thm}\\label{num_int_equations_pos}\nThe number of integer equations $(y_1, y_2, \\ldots, y_m)$ for target $t$ with $y_i > 0$ for all $1 < i < m$ is \n$$\n\\binom{t + 1}{m - 1}\n$$\n\\end{thm}\n\n\\begin{proof}\nFor an integer equation $(y_1, y_2, \\ldots, y_m)$ we have $\\sum_{i = 1}^m y_i = t$ and $y_i > 0$ for all $1 < i < m$. So we can write\n$$\ny_1 + \\sum_{i = 2}^{m-1} (y_i - 1) + y_m = t - (m - 2)\n$$\nThis shows that we can transform the integer equations with the strictly positive constraints into normal integer equations without constraints but with a new target. This again is a bijection. We know how to count these from theorem \\ref{num_int_equations}. The new target is $t - m + 2$. Plugging it in we get \n$$\n\\binom{t - m + 2 + m - 1}{m - 1} = \\binom{t + 1}{m - 1}\n$$\n\\end{proof}\n\nUsing \\ref{num_int_equations_pos} and $t = n - k$ and $m = k + 1$ as described by our association \\ref{consec_ints_association} of subsets of size $k$ without consecutive integers from set $\\mathbb{N}_n$ to integer equations with all but the first and last strictly positive terms, we are finally able to solve the problem in this section. The answer is $\\binom{n - k + 1}{k}$.\n\n\\bibliographystyle{plainnat}\n\\bibliography{../common/math}\n\n\\end{document}\n\n", "meta": {"hexsha": "19da392b025c9e1c08e2850934a823df3f3b3be3", "size": 11465, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "noconsecutiveints/noconsecutiveints.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": "noconsecutiveints/noconsecutiveints.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": "noconsecutiveints/noconsecutiveints.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": 81.8928571429, "max_line_length": 931, "alphanum_fraction": 0.7155691234, "num_tokens": 3685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8933094110250333, "lm_q1q2_score": 0.6894950604581254}}
{"text": "\\chapter{Statistical model}\n    \\label{chapter:StatisticalModel}\n\nThis chapter describes the statistical treatment that is used in the analysis to calculate the normalization of the different background processes, the new physics signal strength, and to estimate the uncertainties.\nThe general procedure to search for new phenomena is also explained.\n\n\n\\section{Preliminary}\n    \\label{sec:StatisticsPreliminary}\n\nSome simple case examples are studied first as a way to introduce the complete statistical machinery that will be used in the analysis.\n\n\\subsection{One signal region only}\n\nA single region is considered, in which only one signal and one background process are present.\nIf the presence of any systematic effect is neglected, the probability of finding $n$ data events assuming $B$ expected background events and $S$ expected signal events, the latest normalized with a ``signal strength'', $\\mu_s$, follows a Poissonian distribution, and is found to be:\n\n\\begin{equation}\nP(n | \\mu_s S + B) = \\frac{(\\mu_s S + B)^n}{n!} \\exp{\\left[-(\\mu_s S + B)\\right]}.\n\\label{eq:simplifiedPoisson}\n\\end{equation}\n\nIn the case where $\\mu_s=0$, the signal yield is forced to be zero, thus corresponding to a ``background-only'' hypothesis.\nOn the other hand, $\\mu_s=1$ corresponds to the nominal ``signal+background'' hypothesis \\cite{Cranmer:2012sba}.\nIf the probability $P(n | \\mu_s S + B)$ is regarded as a function of $\\mu_s$, then it is called the likelihood of $\\mu_s$, $L(\\mu_s)$.\nIn particular, the maximization of this likelihood function (or equivalently, the minimization of this minus log-likelihood function),\n\n\\begin{equation}\n-\\ln{L(\\mu_s)} = -n \\ln{(\\mu_s S + B)} + (\\mu_s S + B) + \\ln{n!},\n\\label{eq:simplifiedLogLikelihood}\n\\end{equation}\n\n\\noindent determines the optimal value for $\\mu_s$.\n\n\n\\subsection{Multiple regions, one background process}\n\nThe previous example can be extended by considering the background to be corrected by a normalization factor, $\\mu_b$, extracted from a calibration measurement in a control region.\nTherefore, two regions are considered: a signal region, defined to enhance the signal process, and a control region, orthogonal to the signal region and optimized to enhance the background process.\nThe probability for finding $\\vec{n} = (n_{\\text{SR}}, n_{\\text{CR}})$ data events assuming $\\vec{B} = (B_{\\text{SR}}, B_{\\text{CR}})$ expected background events and $\\vec{S} = (S_{\\text{SR}}, S_{\\text{CR}})$ expected signal events in both regions is:\n\n\\begin{equation}\n\\begin{split}\nP(\\vec{n} | \\mu_s \\vec{S} + \\mu_b\\vec{B}) &= \\frac{(\\mu_s S_{\\text{SR}} + \\mu_b B_{\\text{SR}})^{n_{\\text{SR}}}}{n_{\\text{SR}}!} \\exp{\\left[-(\\mu_s S_{\\text{SR}} + \\mu_b B_{\\text{SR}})\\right]} \\\\\n& \\times \\frac{(\\mu_s S_{\\text{CR}} + \\mu_b B_{\\text{CR}})^{n_{\\text{CR}}}}{n_{\\text{CR}}!} \\exp{\\left[-(\\mu_s S_{\\text{CR}} + \\mu_b B_{\\text{CR}})\\right]} ,\n\\end{split}\n\\label{eq:simplifiedPoissonControlRegion}\n\\end{equation}\n\n\\noindent where $\\mu_s$ and $\\mu_b$ are the scale factors for the signal and background processes respectively.\nFrom this probability, the following minus log-likelihood function is derived:\n\n\\begin{equation}\n\\begin{split}\n-\\ln{L(\\mu_s, \\mu_b)} =& -n_{\\text{SR}} \\ln{(\\mu_s S_{\\text{SR}} + \\mu_b B_{\\text{SR}})} + (\\mu_s S_{\\text{SR}} + \\mu_b B_{\\text{SR}}) \\\\\n                       & -n_{\\text{CR}} \\ln{(\\mu_s S_{\\text{CR}} + \\mu_b B_{\\text{CR}})} + (\\mu_s S_{\\text{CR}} + \\mu_b B_{\\text{CR}}) \\\\\n                       & + \\ln{n_{\\text{SR}}!} + \\ln{n_{\\text{CR}}!}.\n\\end{split}\n\\label{eq:simplifiedLogLikelihoodControlRegion}\n\\end{equation}\n\nThe minimization of $-\\ln{L(\\mu_s, \\mu_b)}$ leads to a system of equations from which the two normalization factors, $\\mu_s$ and $\\mu_b$ can be computed.\n\n\n\\subsection{Multiple regions, several background processes}\n    \\label{subsec:StatisticsMultipleRegionsNoSystematics}\n\nThe example from the previous subsection can be generalized to having more than one background, normalized with more than one normalization factor.\nAs a simplification, the signal yield in all the control regions will be considered negligible, $\\vec{S} = (S_{\\text{SR}}, 0, \\ldots)$.\nThen, the probability for finding $\\vec{n} = (n_\\text{SR}, n_\\text{CR1}, \\ldots)$ data events assuming $\\mu_s \\cdot \\vec{S} + \\vec{\\mu_b}\\cdot \\hat{B}$ expected events in the different regions, is found to be:\n\n\\begin{equation}\n\\begin{split}\nP(\\vec{n} | \\mu_s \\cdot \\vec{S} + \\vec{\\mu_b}\\cdot \\hat{B}) &= \\frac{(\\mu_s S_{\\text{SR}} + \\sum_{b}^{\\text{bkg}}{\\mu_{b} B_{{\\text{SR}}b}})^{n_{\\text{SR}}}}{n_{{\\text{SR}}}!} \\exp{\\left[-(\\mu_s S_{{\\text{SR}}} + \\sum_{b}^{\\text{bkg}}{\\mu_{b} B_{{\\text{SR}}b}})\\right]} \\\\\n& \\times \\prod_{i}^{\\text{control}}{ \\frac{\\left(\\sum_{b}^{\\text{bkg}}{\\mu_{b} B_{ib}}\\right)^{n_{i}}}{n_{i}!}} \\exp{\\left[-\\sum_{b}^{\\text{bkg}}\\mu_{b} B_{ib}\\right] }.\n\\end{split}\n\\label{eq:simplifiedPoissonSeveralBkg}\n\\end{equation}\n\nFrom the previous equation, the likelihood function of $\\vec{\\mu} = (\\mu_s, \\mu_{b_1}, \\ldots)$ is determined:\n\n\\begin{equation}\nL(\\vec{\\mu}) = \n \\prod_{c \\in \\text{regions}}{\\frac{[\\nu_c(\\vec{\\mu})]^{n_c}}{n_c!}e^{-\\nu_c(\\vec{\\mu})}},\n\\label{eq:generalLikelihoodNoSystematics}\n\\end{equation}\n\n\\noindent where $n_c$ are the number of observed events in the region $c$, and\n\n\\begin{equation}\n\\nu_c = \\mu_s S_c + \\sum_{j}^{\\text{bkg}}{\\mu_{b,j}B_{c,j}} = \\sum_{s}^{\\text{samples}}{\\mu_s \\nu_{cs}^0},\n\\label{eq:definitionNuSimple}\n\\end{equation}\n\n\\noindent being $\\nu_{cs}^0$ the nominal number of events for the process $s$, in the signal or control region $c$.\nEquation~\\ref{eq:generalLikelihoodNoSystematics} provides a general likelihood function for a model in which several processes normalized with different normalization factors are measured in different regions, ignoring the effect of any systematic uncertainty.\n\n\n\\subsection{Parametrization of the systematic uncertainties}\n    \\label{subsec:StatisticsSystematicSimplified}\n\nThe expected number of events for a process $s$, in a given region, $c$, can be written as $\\eta_{cs} \\nu_{cs}^0$, being $\\nu_{cs}^0$ the expected nominal yield.\nThe factor $\\eta_{cs}$ is the the relative variation with respect to the nominal expectation due to any systematic effect, and can be regarded as a function of a \\emph{nuisance parameter}, $\\alpha_p$, which parametrizes the ``number of standard deviations''.\n\nAs detailed in Ref.~\\cite{Cranmer:2012sba}, different parametrization functions for $\\eta_{cs}(\\alpha_p)$ can be used, providing that $\\eta_{cs}(0)=1$ (by definition, a variation of zero standard deviations must return the nominal yield), and $\\eta_{cs}(\\pm 1)$ returns exactly the $\\pm 1$ standard deviation effect of the systematic uncertainty under study, determined with an auxiliary measurement.\n\nIn this example, the nuisance parameter $\\alpha_p$ is considered normally distributed according to the probability density function:\n\n\\begin{equation}\nP(a_p | \\alpha_p, \\sigma_p) = \\frac{1}{\\sqrt{2\\pi\\sigma_p^2}} \\exp{\\left(-\\frac{(a_p - \\alpha_p)^2}{2\\sigma_p^2}\\right)},\n\\label{eq:simplifiedAlphaParametersPDF}\n\\end{equation}\n\n\\noindent  where $a_p$ is the central value of the auxiliary measurement around which the $\\alpha_p$ with standard deviation $\\sigma_p$ can be varied when maximizing the likelihood.\nThe auxiliary measurement $a_p$ and the standard deviation of the gaussian, $\\sigma_p$, are typically fixed to 0 and 1, respectively.\n\nThe introduction of systematic uncertainties in the analysis implies that the likelihood from Equation~\\ref{eq:generalLikelihoodNoSystematics} needs to be multiplied by the PDF from Equation~\\ref{eq:simplifiedAlphaParametersPDF}.\nThis introduces a dependence on $\\alpha$ in the sample yields, $\\nu_{cs}$.\n\n\n\\section{Complete statistical treatment}\n    \\label{sec:StatisticalTreatment}\n\nThe complete statistical treatment of the analysis is based on the profile likelihood method, which results from the combination and generalization of the simplified examples discussed above.\nThis method allows to determine the normalization factors to be applied to estimate the different processes as well as the systematic variations and the correlations among them.\nAs in the previous examples, no shape information is used in the analysis presented in this Thesis: the distributions in the signal and control regions consist of just one single bin.\n\n\\subsection{Parametrization of the model}\n    \\label{subsec:ParametrizationModel}\n\nThe signal and the backgrounds in the different region definitions, as well as the systematic uncertainties under consideration are parametrized by the likelihood function (see Equations~\\ref{eq:generalLikelihoodNoSystematics} and \\ref{eq:simplifiedAlphaParametersPDF}, in the previous section):\n\n\\begin{equation}\nL(\\vec{\\mu}, \\vec{\\alpha}) = \n \\prod_{c \\in \\text{regions}}{\\frac{[\\nu_c(\\vec{\\mu}, \\vec{\\alpha})]^{n_c}}{n_c!}e^{-\\nu_c(\\vec{\\mu}, \\vec{\\alpha})}}\n \\prod_{p\\in\\text{params}}{P_p(\\alpha_p)},\n\\label{eq:PdfFit}\n\\end{equation}\n\n\\noindent where $n_c$ are the number of events measured in each region, $\\vec{\\mu}$ is the set of normalization factors used to normalize the different background and signal processes, and $\\vec{\\alpha}$ is a set of nuisance parameters that parametrize the different systematic uncertainties.\nFurthermore, $\\nu_c$ are the number of events expected in each region, in particular (see Equation~\\ref{eq:definitionNuSimple}):\n\n\\begin{equation}\n\\nu_c(\\vec{\\mu}, \\vec{\\alpha}) = \\sum_{s\\in\\text{samples}}{\\mu_s(\\vec{\\alpha})\\;\\eta_{cs}(\\vec{\\alpha})\\;\\nu^0_{cs}},\n\\label{eq:nuInPdfFit}\n\\end{equation}\n\n\\noindent where $\\nu^0_{cs}$ is the expected nominal number of events and $\\eta_{cs}$ is the parametrized normalization uncertainty, that depend on the nuisance parameters $\\vec{\\alpha}$.\nFinally, $P_p$ is a constraining term, that describes an auxiliary measurement to used constrain the nuisance parameter $\\alpha_p$.\nIn the present analysis, the constraining term is assumed to be a gaussian, except for the nuisance parameters dedicated to the statistical uncertainties, which are poissonian distributed.\n\nThe maximization of this function allows to calculate the normalization factors and nuisance parameters used to estimate the yield of each process and the level of systematics in the different regions.\nIn the analysis, three fit configurations will be used for different purposes \\cite{Baak:2014wma}:\n\n\\paragraph{Background-only fit:}Only the control regions are used to constrain the fit parameters. \nAny potential signal contribution is neglected everywhere ($\\mu_\\text{signal} = 0$).\nThis fit is used to extract the normalization factors of the background processes and their systematic uncertainties.\n\n\\paragraph{Model independent signal fit:}Both control and signal regions are used in the fit. \nThe signal is independently considered in each signal region but neglected in the control regions.\nThis background prediction is conservative since any signal contribution in the control regions is attributed to background and thus results in a possible overestimation of the background in the signal regions. \nIn this analysis this contribution is negligible due to the requirement of leptons in the control regions.\nThis fit configuration is used to extract the 95\\%~CL model independent upper limits on the visible cross section.\n\n\\paragraph{Model dependent signal fit:}Both control and signal regions are used in the fit. \nThe signal contribution is taken into account as predicted by the tested model in all the regions.\nThe model dependent signal fit configuration is used to interpret the results of this analysis in terms of the different new physics models that are studied.\n\n\n\\section{Statistical tests}\n    \\label{subsec:StatisticalTests}\n\nThis section describes the general procedure used to search for a new phenomena in the context of a frequentist statistical test.\nIf the purpose of the analysis is to discover a new signal process, the null hypothesis, $H_0$, is defined as describing the known SM processes, to be tested against $H_1$, which includes both background as well as the signal model.\nInstead, if the purpose of the analysis is to set limits on a signal process, the model with signal plus background plays the role of $H_0$, tested against the background-only hypothesis, $H_1$.\nIn the outcome of such search, the level of agreement of the observed data with a given hypothesis $H$ is quantified by computing the probability, under the assumption of $H$, of finding data with equal or less incompatibility with the prediction of $H$.\n\nAccording to Equation \\ref{eq:nuInPdfFit}, each process is multiplied by a normalization factor, $\\mu$.\nA background-only hypothesis is constructed by fixing $\\mu_\\text{signal}=0$, while a signal+background hypothesis will be defined as having $\\mu_\\text{signal}\\gt0$.\nTo test an hypothesized value of $\\mu$, the profile likelihood can be defined as the ratio:\n\n\\begin{equation}\n\\lambda(\\mu) = \\frac{L(\\mu, \\vec{\\hat{\\hat{\\theta}}})}{L(\\hat{\\mu}, \\vec{\\hat{\\theta}})},\n\\label{eq:profileLikelihood}\n\\end{equation}\n\n\\noindent where $\\mu$ here is the shortcut for $\\mu_\\text{signal}$ and $\\vec{\\theta}\\supset\\{\\mu_{\\text{no signal}}, \\vec{\\alpha}\\}$.\n$\\vec{\\hat{\\hat{\\theta}}}$ in the numerator denotes the value of $\\vec{\\theta}$ that maximizes $L$ for the specified $\\mu$ (it is a conditional maximum likelihood estimator of $\\theta$, and therefore a function of $\\mu$).\nThe denominator is the maximized (unconditional) likelihood function.\nBased on Equation~\\ref{eq:profileLikelihood}, the test statistic $q_\\mu$ is defined as:\n\n\\begin{equation}\nq_\\mu = -2\\ln{\\lambda(\\mu)}.\n\\label{eq:testStatistic}\n\\end{equation}\n\nHigher values of $q_\\mu$ correspond to increasing compatibility between the data and $\\mu$.\nThe $p$-value, defined to quantify the level of agreement between the data and the different hypotheses, is defined as:\n\n\\begin{equation}\np_\\mu = \\int_{q_{\\mu,\\;\\text{obs}}}^{\\infty}{f(q_\\mu|\\mu')\\;dq_\\mu},\n\\label{eq:pValueDefinition}\n\\end{equation}\n\n\\noindent where $f(q_\\mu|\\mu')$ denotes the PDF of $q_\\mu$ under the assumption of the signal strength $\\mu'$.\nThe estimations of $f(q_\\mu|\\mu')$ can be done with pseudo-experiments using Monte Carlo methods (Toy MC).\nThese methods are computationally heavy, especially when upper limits are calculated.\nFor this reason, an approximation valid in the large sample limit is normally used to describe the profile likelihood ratio instead (asymptotic approximation).\n\nIn the large sample limit, where the asymptotic approximation becomes exact, the PDF of $q_\\mu$ assuming that the fitted strength parameter $\\hat{\\mu}$ follows a gaussian of mean $\\mu'$ and standard deviation $\\sigma$ is found to be \\cite{Cowan:2010js}:\n\n\\begin{equation}\n\\begin{split}\n&f(q_\\mu|\\mu')  = \n\\frac{1}{2\\sqrt{q_\\mu}}\\frac{1}{\\sqrt{2\\pi}} \\times \\\\\n& \\left[\\exp{\\left(-\\frac{1}{2}\\left(\\sqrt{q_\\mu}+\\frac{\\mu-\\mu'}{\\sigma}\\right)^2 \\right)} \n+ \\exp{\\left(-\\frac{1}{2}\\left(\\sqrt{q_\\mu}-\\frac{\\mu-\\mu'}{\\sigma}\\right)^2 \\right)} \\right].\n\\end{split}\n\\label{eq:pdfTestStatistic}\n\\end{equation}\n\nFigure~\\ref{fig:pdfTestStatisticExample} illustrates the previous equation, for the particular case of $q_{\\mu=1}$ under a signal plus background and a background-only hypotheses, namely $\\mu'=1$ and $\\mu'=0$, respectively.\nIn this example, the requirement that the $p$-value computed from the $f(q_{\\mu=1}|1)$ PDF is smaller than 0.05, would be enough to exclude the signal model at 95\\% confidence level (CL).\nHowever, the PDFs for both hypotheses could be similar.\nThese are cases in which the analysis has very low sensitivity and the effect produced by a statistical fluctuation could allow the exclusion of both the null (in this case, the signal plus background) and the alternate (background-only) hypotheses at the same time.\nIn an attempt to address this spurious exclusion, the $CL_s$ method is developed.\nThe $CL_s$ solution bases the test not only on the rejection of the null hypothesis but rather in the $p$-value of the null hypothesis divided by one minus the p-value of the alternate hypothesis.\nFollowing the same illustrative example from Figure~\\ref{fig:pdfTestStatisticExample}, in which the existence of a given signal model is tested, the $CL_{s+b}$, $CL_{b}$ and $CL_{s}$ can be defined, respectively, as:\n\n\\begin{equation}\n\\begin{split}\nCL_{s+b} = p_{s+b} \\\\\nCL_{b} = 1-p_{b} \\\\\nCL_{s} = \\frac{CL_{s+b}}{CL_{b}}.\n\\end{split}\n\\label{eq:CLsDefinition}\n\\end{equation}\n\n\\begin{figure}[!t]\n  \\begin{center}\n    \\mbox{\n      \\includegraphics[width=0.75\\textwidth]{MonojetAnalysis/Figures/pdfTestHypothesisExample.eps}\n    }\n  \\end{center}\n  \\caption[Illustration of the PDF of $q_{\\mu}$ under the signal plus background and background-only hypotheses.]{Illustration of the PDF of $q_{\\mu=1}$ under two different hypothesis: signal plus background (null, $\\mu=1$) and background-only (alternative, $\\mu=0$). The $CL_{s+b}$, $CL_b$ and $CL_s$ are also shown for this particular example.}\n  \\label{fig:pdfTestStatisticExample}\n\\end{figure}\n\nIn the work presented in this thesis, the $CL_s$ is calculated for each signal model under evaluation.\nThe models for which $CL_s < 0.05$, are excluded at 95\\% CL.\nWith the $CL_s$ method, $CL_s \\approx CL_{s+b}$ in the cases where the analysis is sensitive to the signal process under study.\nInstead, in the cases where the analysis is insensitive, $CL_b$ is be small, thus increasing the value of $CL_s$ and therefore avoiding the exclusion of the signal model.\n", "meta": {"hexsha": "2ddbb9a290923b623be36b0575169181b988b621", "size": 17496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "StatisticalModel/StatisticalModel.tex", "max_stars_repo_name": "rogercaminal/PhDThesis", "max_stars_repo_head_hexsha": "b4582c8c1c5858878dfdb8e69986a55c1aeb9e3e", "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": "StatisticalModel/StatisticalModel.tex", "max_issues_repo_name": "rogercaminal/PhDThesis", "max_issues_repo_head_hexsha": "b4582c8c1c5858878dfdb8e69986a55c1aeb9e3e", "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": "StatisticalModel/StatisticalModel.tex", "max_forks_repo_name": "rogercaminal/PhDThesis", "max_forks_repo_head_hexsha": "b4582c8c1c5858878dfdb8e69986a55c1aeb9e3e", "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": 69.1541501976, "max_line_length": 400, "alphanum_fraction": 0.7445701875, "num_tokens": 4703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6893668363167906}}
{"text": "%!TEX root = ./jctt.tex\n\n\\subsection{Mixed Finite-Element Method for VEF Equation}\n\\begin{figure}\n\t\\centering\n\t% \\def\\svgwidth{\\textwidth}\n\t\\input{figs/mfemgrid.pdf_tex} \n\t\\caption{The distribution of unknowns in cell $i$ for MFEM. }\n\t\\label{fig:mfem_grid}\n\\end{figure}\nWe apply the MFEM method to Eqs.~\\ref{eq:zero} and \\ref{eq:first} and then eliminate the currents to obtain a discretization for Eq.~\\ref{eq:drift}.  In this \nmethod, the grid is identical to that used in the LLDG \\SN discretization. The unknowns in an MFEM cell are depicted in Fig.~\\ref{fig:mfem_grid}. In MFEM, separate basis functions are used for the scalar flux and \ncurrent. The scalar flux is constant within the cell with discontinuous jumps at the cell edges and the current is a linear function defined by: \n\t\\begin{equation} \\label{eq:MFEM_current}\n\t\tJ_i(x) = J_{i,L} B_{i,L}(x) + J_{i,R} B_{R,i}(x) \\,, \n\t\\end{equation} \nwhere $J_{i,L/R}$ are the currents at the left and right edges of the cell, and the basis functions are identical to those \ndefined by Eqs.~\\ref{eq:bfunL} and \\ref{eq:bfunR} for the LLDG \\SN discretization. The constant-linear MFEM yields second \norder accuracy for both the scalar flux and the current.  \n\nThe MFEM representation yields five unknowns per cell: $\\phi_{i-1/2}$, $\\phi_i$, $\\phi_{i+1/2}$, $J_{i,L}$, and $J_{i,R}$. However, \neach edge flux on the mesh interior is shared by two cells, so with $I$ cells there are $I$ cell-center scalar fluxes, $2I$ currents, \n$2I-1$ interior-mesh cell-edge scalar fluxes, and 2 boundary cell-edge scalar fluxes. An equation for $\\phi_i$ is found by integrating Eq.~\\ref{eq:zero} over cell $i$: \n\t\\begin{equation} \\label{mfem:balance}\n\t\tJ_{i,R} - J_{i,L} + \\sigma_{a,i} h_i \\phi_i = Q_i h_i \\,,\n\t\\end{equation}\nwhere $\\sigma_{a,i}$ and $Q_i$ are the absorption cross section and source in cell $i$. Equations for $J_{i,L/R}$ are found by multiplying Eq.~\\ref{eq:first} by $B_{i,L/R}$ and integrating over cell $i$: \n\t\\begin{subequations}\n\t\t\\begin{equation} \\label{mfem:bli}\n\t\t\t-\\edd_{i-1/2} \\phi_{i-1/2} + \\edd_i \\phi_i + \\sigma_{t,i} h_i \\left(\\frac{1}{3} J_{i,L} + \\frac{1}{6}J_{i,R}\\right) = 0 \\,,\n\t\t\\end{equation}\n\t\t\\begin{equation} \\label{mfem:bri}\n\t\t\t\\edd_{i+1/2} \\phi_{i+1/2} - \\edd_i \\phi_i + \\sigma_{t,i} h_i \\left(\\frac{1}{6} J_{i,L} + \\frac{1}{3} J_{i,R}\\right) = 0 \\,. \n\t\t\\end{equation}\n\t\\end{subequations}\nAll Eddington factors are computed using the angular fluxes from the LLDG \\SN step. Note that $\\edd_{i\\pm 1/2}$ denotes cell edge Eddington factors, while \n$\\edd_{i}$ denotes an average over cell $i$ of the Eddington factors. The edge Eddington factors are defined by Eq.~\\ref{lldg:edde}, while the Eddington factors within each cell \nare defined by Eq.~\\ref{lldg:eddi}. We stress that evaluating Eq.~\\ref{lldg:eddi} at $x_{i\\pm1/2}$ does not yield $\\edd_{i\\pm 1/2}$ \nbecause of the upwinding used to define the cell edge angular fluxes. The spatial dependence of the Eddington factors within each cell takes the form of a rational polynomial prompting the use of numerical quadrature to compute the average. Two point Gauss quadrature was used:\n\t\\be\n\t\\edd_{i} = \\frac{1}{2} \\bracket{ \\langle \\mu^2 \\rangle (x^G_{i,L}) + \\langle \\mu^2 \\rangle (x^G_{i,R}) } \n\t\\ee\nwhere \n\\begin{equation} \n\t\t% x^G_{i,L/R} = \\frac{h_i}{2} \\mp \\frac{x_{i+1/2} + x_{i-1/2}}{2\\sqrt{3}} \\,.\n\t\tx^G_{i,L/R} = \\frac{x_{i+1/2} + x_{i-1/2}}{2} \\mp \\frac{h_i}{2\\sqrt{3}} \\,.\n\\end{equation}\n\nEliminating $J_{i,R}$ from Eq.~\\ref{mfem:bli} and $J_{i,L}$ from Eq.~\\ref{mfem:bri} yields: \n\t\\begin{subequations}\n\t\t\\begin{equation} \\label{mfem:jli}\n\t\t\tJ_{i,L} = \\frac{-2}{\\sigma_{t,i} h_i} \\bigg\\{\n\t\t\t\t2\\br{\\eddphi{i} - \\eddphi{i-1/2}}\n\t\t\t\t- \\br{\\eddphi{i+1/2} - \\eddphi{i}}\n\t\t\t\\bigg\\} \\,,\n\t\t\\end{equation}\n\t\t\\begin{equation} \\label{mfem:jri}\n\t\t\tJ_{i,R} = \\frac{-2}{\\sigma_{t,i} h_i} \\bigg\\{\n\t\t\t\t2\\br{\\eddphi{i+1/2} - \\eddphi{i}} \n\t\t\t\t- \\br{\\eddphi{i} - \\eddphi{i-1/2}}\n\t\t\t\\bigg\\} \\,.\n\t\t\\end{equation}\n\t\\end{subequations}\nAn equation for $\\phi_{i+1/2}$ on the mesh interior is found by enforcing continuity of current at the cell edges: \n\t\\begin{equation} \\label{mfem:continuity}\n\t\tJ_{i,R} = J_{i+1, L} \\,. \n\t\\end{equation}\n\nUsing the definitions of $J_{i,L}$ and $J_{i,R}$ from Eqs.~\\ref{mfem:jli} and \\ref{mfem:jri} in the balance equation (Eq.~\\ref{mfem:balance}) and continuity equation (Eq.~\\ref{mfem:continuity}) yields equations for all cell-center fluxes and \ninterior-mesh cell-edge fluxes, respectively.  The resulting balance equation for cell $i$ and continuity equation for \nedge $i+1/2$ are respectively:\n\t\\begin{subequations}\n\t\t\\begin{equation} \\label{mfem:center}\n\t\t\t-\\frac{6}{\\sigma_{t,i}h_i} \\edd_{i-1/2} \\phi_{i-1/2}\n\t\t\t+ \\left(\\frac{12}{\\sigma_{t,i}h_i} \\edd_i + \\sigma_{a,i} h_i\\right) \\phi_i \n\t\t\t- \\frac{6}{\\sigma_{t,i} h_i} \\edd_{i+1/2} \\phi_{i+1/2} \n\t\t\t= Q_i h_i \\,,\n\t\t\\end{equation}\n\t\tand \n\t\t\\begin{multline} \\label{mfem:edge}\n\t\t\t-\\ALPHA{2}{i} \\eddphi{i-1/2} + \\ALPHA{6}{i} \\eddphi{i} \n\t\t\t- 4\\paren{\\ALPHA{1}{i} + \\ALPHA{1}{i+1}} \\eddphi{i+1/2} \\\\\n\t\t\t+ \\ALPHA{6}{i+1}\\eddphi{i+1} \n\t\t\t- \\ALPHA{2}{i+1} \\eddphi{i+3/2}\n\t\t\t= 0 \\,. \n\t\t\\end{multline}\n\t\\end{subequations}\nThe equations for the outer boundary fluxes, $\\phi_{1/2}$ and $\\phi_{I+1/2}$, involve boundary conditions together with continuity conditions.  For instance,\nthe equation for $\\phi_{1/2}$ is \n\\begin{equation}\n\t\tJ_{1,L} = J_{1/2} \\,,\n\\end{equation}\t\t\nwhere $J_{1,L}$ is defined by Eq.~\\ref{mfem:jli}, and $J_{1/2}$ is the left boundary current defined by a boundary condition.  For a reflective condition,\n\\begin{equation}\n    J_{1/2} = 0 \\, .\n\\end{equation}\nFor a source condition,\n\\begin{equation}\n\t\tJ_{1/2} = 2 \\sum_{\\mu_n>0} \\mu_n \\psi_{n,1/2} w_n - B_{1/2} \\phi_{1/2} \\,,\n\\end{equation}  \n where  \n\\begin{equation}\n\t\tB_{1/2} = \\frac{\\sum_{n=1}^N |\\mu_n| \\psi_{n,1/2} w_n}{\n\t\t\t\\sum_{n=1}^N \\psi_{n,1/2} w_n \n\t\t} \n\\end{equation}\nis the boundary Eddington factor \\cite{QDBC}.  The equation for  $\\phi_{I+1/2}$ is \n\\begin{equation}\n\t\tJ_{I,R} = J_{I+1/2} \\, .\n\\end{equation}\t\t\nwhere $J_{I,R}$ is defined by Eq.~\\ref{mfem:jri}, and $J_{I+1/2}$ is the right boundary current.  For a reflective condition,\n\\begin{equation}\n    J_{I+1/2} = 0 \\, .\n\\end{equation}\nFor a source condition,\n\\begin{equation}\n\t\tJ_{I+1/2} = B_{I+1/2} \\phi_{I+1/2} - 2 \\sum_{\\mu_n<0} |\\mu_n| \\psi_{n,I+1/2} w_n  \\,,\n\\end{equation}  \nwhere \n\\begin{equation}\n\t\tB_{I+1/2} = \\frac{\\sum_{n=1}^N |\\mu_n| \\psi_{n,I+1/2} w_n}{\n\t\t\t\\sum_{n=1}^N \\psi_{n,I+1/2} w_n \n\t\t} \\, .\n\\end{equation}\n\nThese transport-consistent, Marshak-like source boundary conditions are derived starting with the identity\n\\begin{equation}\nJ_{1/2}=j^+ - j^- \\,,\n\\end{equation}\nwhere $j^\\pm$ denotes the positive half-range currents associated with $\\mu >0$ and $\\mu <0$, respectively.  For the left boundary condition, we simply perform the following algebraic manipulations:\n\\begin{equation}\nJ_{1/2} = j^+ - j^-  = 2j^+ - (j^+ + j^-) = 2j^+ - \\frac{j^+ + j^-}{\\phi} \\phi = 2j^+ - B_{1/2} \\phi  \\, .\n\\end{equation}\nFor the right boundary condition, we similarly obtain\n\\begin{equation}\nJ_{I+1/2} = j^+ - j^-  = (j^+ + j^-) - 2j^- = \\frac{j^+ + j^-}{\\phi} \\phi - 2j^- = B_{I+1/2} \\phi - 2j^-\\, .\n\\end{equation}\nNote that these source boundary conditions become equivalent to the standard Marshak boundary conditions if the \\SN angular flux \nis isotropic. \nThe resulting system of $2I+1$ equations for the cell-center and cell-edge fluxes can be assembled into a matrix of both cell-center and cell-edge scalar fluxes and solved with a banded matrix solver of bandwidth five. The resulting drift-diffusion scalar flux can either be used as the final solution if the solution has converged or as an update to the LLDG \\SN scattering source. Use of these piecewise-constant fluxes to represent the LLDG \\SN scattering source is the default method, and is referred to as the flat update method.\n\n% Applying the MFEM to Eqs.~\\ref{eq:zero} and \\ref{eq:first} and enforcing continuity of current yields: \n% \t\\begin{subequations} \\label{eq:mfem}\n\t\n% \t\\begin{multline}\n% \t\t-\\frac{2}{\\sigma_{t,i} h_i} \\edd_{i-1/2}\\phi_{i-1/2} + \n% \t\t\\frac{6}{\\sigma_{t,i} h_i} \\edd_i \\phi_i \n% \t\t- 4\\left(\\frac{1}{\\sigma_{t,i} h_i} + \\frac{1}{\\sigma_{t,i+1} h_{i+1}}\\right) \n% \t\t\t\\edd_{i+1/2} \\phi_{i+1/2}\n% \t\t\\\\ + \\frac{6}{\\sigma_{t,i+1} h_{i+1}} \\edd_{i+1} \\phi_{i+1} \n% \t\t- \\frac{2}{\\sigma_{t,i+1} h_{i+1}} \\edd_{i+3/2} \\phi_{i+3/2} \n% \t\t= 0 \\,,\n% \t\\end{multline}\n% \t\\end{subequations}\n% where the Eddington factor is evaluated at iteration $\\ell+1/2$ and the scalar flux at $\\ell+1$. \n% Here, the Eddington factor has been assumed to be constant in each cell with discontinuous jumps at the edges. \n% The simplest method of converting the Eddington factor from LLDG to MFEM is to compute the Eddington factor using the cell centered and cell edged angular fluxes using Eqs.~\\ref{eq:lldg_i}, \\ref{eq:downwind}, and \\ref{eq:upwind}. A more consistent way to transfer the Eddington factor is to represent the LLDG angular flux as a linear function using the MFEM basis functions: \n% \t\\begin{equation} \\label{eq:eddquad}\n% \t\t\\edd_i(x) = \\frac{\n% \t\t\t\\sum_{n=1}^N \\mu_n^2 \\left[\\psi_{n,i,L}B_{i,L}(x) + \\psi_{n,i,R} B_{i,R}(x)\\right]\n% \t\t}\n% \t\t{\n% \t\t\tB_{i,L}(x) \\sum_{n=1}^N w_n \\psi_{n,i,L} + B_{i,R}(x) \\sum_{n=1}^N w_n \\psi_{n,i,R} \n% \t\t} \\,,\n% \t\\end{equation}\n% where \n\t\n% and \n\n% When MFEM is applied, the integral over cell $i$ of the rational polynomial given in Eq.~\\ref{eq:eddquad} is approximated with 2 point Gauss quadrature. The cell centered Eddington factors used in Eq.~\\ref{eq:mfem} are then: \n% \t\\begin{equation} \n% \t\t\\edd_i = \\half \\left[ \\edd_i(x_{i,L}) + \\edd_i(x_{i,R}) \\right] \\,,\n% \t\\end{equation}\n% where \n% \t\\begin{equation}\n% \t\tx_{i,L/R} = \\frac{x_{i+1/2} - x_{i-1/2}}{2} \\mp \\frac{x_{i+1/2} + x_{i-1/2}}{2\\sqrt{3}}\n% \t\\end{equation}\n% are the quadrature points in cell $i$. \n\n% Transport consistent vacuum boundary conditions are applied through a modified Marshak boundary condition: \n% \t\\begin{equation} \n% \t\tJ(x) = B(x) \\phi(x) \\,,\n% \t\\end{equation} \n% where \n% \t\\begin{equation} \n% \t\tB(x) = \\frac{\\int_{-1}^1 |\\mu| \\psi(x, \\mu) \\ud \\mu}\n% \t\t{\\int_{-1}^1 \\psi(x, \\mu) \\ud \\mu} \\,. \n% \t\\end{equation}\n\n\\subsection{Increased Consistency Between LLDG and MFEM}\n\nThe MFEM representation for the scalar flux is constant within a cell, but the LLDG representation for the scalar flux is linear.  This suggests that improved \naccuracy of the \\SN solution could be achieved by somehow constructing a linear scalar flux dependence from the MFEM solution.  One simple method for doing \nthis is to use the MFEM cell-edge scalar fluxes to compute a slope, which is then combined with the MFEM cell-center flux value to \nobtain a linear dependence.   This works quite well for neutronics.  However, it will be inadequate in a radiative transfer calculation because slopes must also be generated for the material temperatures, and an MFEM approximation for the temperatures will not include \nedge temperatures.  We have chosen to use a more generally applicable approach based upon standard data reconstruction techniques \nthat require only cell-centered values to compute slopes \\cite{vanLeer}.  We also limit such slopes to avoid non-physical scalar fluxes.  For example, the reconstructed left and right scalar fluxes in cell $i$ are given by \n\t\\begin{equation} \\label{consistent:reconstruction}\n\t\t\\phi_{i,L/R} = \\phi_i \\mp \\frac{1}{4} \\xi_i \\left(\\Delta \\phi_{i+1/2} + \\Delta \\phi_{i-1/2}\\right) \\,,\n\t\\end{equation}\nwhere $\\xi$ is a van Leer-type slope limiter \\cite{vanLeer}: \n\\begin{subequations}\n\t\\begin{equation} \n\t\t\\xi_i = \\begin{cases}\n\t\t\t0, & r_i \\leq 0 \\,, \\\\\n\t\t\t\\text{min}\\bracet{\\frac{2r_i}{1+r_i} , \\frac{2}{1+r_i}} \\,, & r_i > 0\n\t\t\\end{cases} \\,,\n\t\\end{equation}\n\t\\begin{equation}\n\t\tr_i = \\frac{\\Delta\\phi_{i-1/2}}{\\Delta \\phi_{i+1/2}} \\,,\n\t\\end{equation}\n\\end{subequations}\nand\n\t\\begin{subequations}\n\t\t\\begin{equation}\n\t\t\t\\Delta \\phi_{i+1/2} = \\phi_{i+1} - \\phi_i \\,, \n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\Delta \\phi_{i-1/2} = \\phi_i - \\phi_{i-1} \\,.\n\t\t\\end{equation}\n\t\\end{subequations}\n\nOn the boundaries, we use \n\t\\begin{subequations}\n\t\t\\begin{equation}\n\t\t\t\\phi_{1,L/R} = \\phi_1 \\mp \\frac{1}{2} \\Delta \\phi_{3/2} \\,,\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\phi_{I,L/R} = \\phi_I \\mp \\frac{1}{2} \\Delta \\phi_{I-1/2} \\,.\n\t\t\\end{equation}\n\t\\end{subequations}\nWe also set any negative left or right flux values in the boundary cells to zero by appropriately rotating the slopes. \n", "meta": {"hexsha": "9bad49315b73808a18b8fab8d33944a2d4f1d6d0", "size": 12445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/paper/mfem.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/paper/mfem.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/paper/mfem.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": 53.4120171674, "max_line_length": 534, "alphanum_fraction": 0.6734431499, "num_tokens": 4648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6892892121308266}}
{"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 5\n\t\\end{large} }\n\n\t\n\t\\maketitle\n\t\n\t\\section*{Module 2: Expectations from Browninan integrals}\n\t\nLet's look at more expectations involving\nour stochastic processes.\nWe know that $dB$ is a Gaussian random variable\nwith a mean $0$ and variance $dt$.\n\n$$ dB \\sim N(0,dt) $$\n\nWe also know that if we integrate $\\int_{0}^{t} dB$ , and for convenience, I can write this as:\n\n$$  \\int_{0}^{t} dB = B_t - B_0 \\sim N(0,t ) $$\n\n\nLet's agree that $B_0=0$. \n\nSo since that is the case, we have an easy way that we can write things.\nWe know that the expectation of $B$ is going to be 0.\nWe know that its variance is going to be $t$.\n\n\nSo let's just replace the random variable $B_t-B_0$ by $\\sqrt{t}z$ where $z \\sim N(0,1)$\n\n\nWhere $z$ doesn't have any time dependence.  So that's just simplifying things and putting everything\nin an even more standard form. But it also makes explicit the time dependent.\nAnd it's the scaling with time that's going to be important for a lot of financial applications, and for risk management.\nSo, what that means is that any time\nwhere we see a $B_t$, or a $B_t$ minus $B_0$,\nwe can replace it by that function.\nSo if we want to compute the expectation of some function, we can just write: $$E[f(B_t-B_0)] = E[f(\\sqrt{t} z)]$$  and compute that.\n\nAnd remember, these are our Gaussian intervals. So we just need to do an integral. That's all it is. So this is equal:\n\n $$E[f(B_t-B_0)] = E[f(\\sqrt{t} z)] = \\frac{1}{\\sqrt{2\\pi}} \\int e^{-z^2/2}f(\\sqrt{t}z) dz$$ \n\nEasy.\n\nSo for example, suppose we wanted to compute the expectation of the fourth power.\n $$ f(x) = x^4$$\nSo we'd like to compute:\n\n $$E[f(B_t-B_0)] = E[(B_t-B_0)^4] = E[(\\sqrt{t} z)^4] = t^2 E[z^4] = 3t^2 $$ \n\nWe can pull out $\\sqrt{t}$,which is nonstochastic to get $t^2 E[z^4]$\n, $E[z^4]$ is a well-known Gaussian integal that we use in the kurtosis.\nIt's just equal to 3.\n\nAll right.\n\nSo this way of standardizing things and writing things\nin terms of $z$ when we work in the integral form,\nwhen we integrate our processes, is very convenient.\nLet's do an example, and I want to review\na very useful trick with you.\nSo let's take a look.\n\n\\subsection*{Example}\nSuppose we wanted to compute\n$$ E[e^{6X}] \\text{ where }  dX = \\mu dt + \\sigma dB $$  \n\nwhere $dX$, let's just say it's ordinary Brownian motion.\n\n\nOK, because it's on this form, you can integrate as:\n\n$$ \\text{integrate:}  X_t-X_0 = \\mu t + \\sigma \\sqrt{t} z $$\n\nSo if we go to compute the expectation :\n\n$$ E[e^{6(\\mu t + \\sigma \\sqrt{t} z)}] = e^{6\\mu t}  E[e^{6 \\sigma \\sqrt{t} z}]  $$\n\n\n\\subsubsection*{Useful Formula}\n\n\n\nSuppose that we have $E[e^{\\alpha z + \\beta}]$. And this shows up a lot in particular in asset\npricing formulas.\nSo this is clearly equal to\n\n$$ $$ \n\n\\begin{equation*} \n\t\\begin{split}\n\t\tE[e^{\\alpha z + \\beta}]  & = e^{\\beta} E[e^{\\alpha z }]  \\\\\n                                 & = \\frac{e^{\\beta}}{\\sqrt{2 \\pi}} \\int e^{-z^2/2}e^{\\alpha z} dz \\\\\n                                 & = \\frac{e^{\\beta}}{\\sqrt{2 \\pi}} \\int e^{-z^2/2 + \\alpha z - \\alpha^2/2 + \\alpha^2/2 } dz \\\\\n                                 & = \\frac{e^{\\beta}}{\\sqrt{2 \\pi}} \\int e^{-(z^2 - 2 \\alpha z + \\alpha^2)/2 + \\alpha^2/2 } dz \\\\\n                                 & = \\frac{e^{\\beta}}{\\sqrt{2 \\pi}} \\int e^{-(z-\\alpha)^2/2 + \\alpha^2/2} dz \\\\\n                                  & = e^{\\beta+ \\alpha^2/2} \\Big[\\frac{1}{\\sqrt{2 \\pi}} \\int e^{-(z-\\alpha)^2/2 } dz \\Big]\n\t\\end{split}\n\\end{equation*}\n\nWe do the Gaussian integral, with the trick of completing the square in the exponent.\nAnd because the integral goes from minus infinity to infinity, the difference in the exponential between $z$ \nand $z-\\alpha$ makes no difference at all.\nIf you'd like, you can shift the variable of integration.\nThe integral inside the square brackets\nwith $\\frac{1}{\\sqrt{2 \\pi}}$ in front is equal to 1.\nSo our final result, our final useful formula, is that:\n\n$$ E[e^{\\alpha z + \\beta}]  = e^{\\beta+ \\alpha^2/2}$$\n\nNow, let's apply that to our example.\n\n$$\tE[e^{6X}]   = E[e^{ 6\\mu t + 6 \\sigma \\sqrt{t} z}]   $$\n\n\nwith $\\alpha=6 \\sigma \\sqrt{t}$ and $\\beta = 6 \\mu t$ , we apply $ E[e^{\\alpha z + \\beta}]  = e^{\\beta+ \\alpha^2/2}$\n\n\n\\begin{equation*} \n\t\\begin{split}\n\t\tE[e^{6X}] &= e^{6 \\mu t + (6 \\sigma \\sqrt{t})^2/2}  \\\\\n\t    &= e^{6 \\mu t + 18 \\sigma^2 t}  \n\t\\end{split}\n\\end{equation*}\n\n\nSo there's our answer for finding this expectation.\nAnd this works, generally, for a larger class\nof functions that show up for different kinds of Ito\nprocesses.\n\n\n\t\\section*{Module 3: Solutions to the diffusion equation}\n\nLet's take a closer look at the diffusion equation. So the general diffusion equation is given right here.\n\nSo we say that we have a function $p(z,t)$,\n$$ p(z,t) = \\int p_0(z-w,t)f(w)dw $$\n\nand they need to satisfy this differential equation.\n$$ \\frac{\\partial p}{\\partial t} - \\frac{1}{2} \\frac{\\partial ^2 p}{\\partial z^2} = 0 $$\n\nAnd we've seen that there's a very special solution, $p_0$, that satisfies that equation, which\nwe can find by plugging it in and taking some derivatives. So here's our $p_0$.\n\n\n$$ p_0 = \\frac{1}{\\sqrt{2 \\pi t}} e^{-\\frac{z^2}{2t}} $$\n\n\n\nNow, I claimed that if we construct this integral on top,\nthat this is the solution to the equation.\nSo what I'd like to do is, let's check that,\nand then let's apply it.\nSo the first thing to do is to check it.\nAnd the way we do it is we take derivatives.\nAnd what we find is that if we take that integral expression,\nand we stick it into the differential equation, what\nwe'll do is, we'll move the differential operators inside.\nSo for example,\n\n\n\n\n$$ \\frac{\\partial}{\\partial t} p(z,t) = \\int \\frac{\\partial}{\\partial t} \\Big[  p_0(z-w,t)f(w)dw \\Big] $$\n\n\nBut where is the $t$ dependence?\nThe $t$ dependence is only in one place.\nIt's in $p_0$.\n\nAnd similarly,\n\n\n$$ \\Big( \\frac{\\partial}{\\partial t} -\\frac{1}{2} \\frac{\\partial^2}{\\partial z^2} \\Big)p(z,t) = \\int  \\Big[  \\frac{\\partial}{\\partial t} -\\frac{1}{2} \\frac{\\partial^2}{\\partial z^2}  \\Big]  p_0(z-w,t)f(w)dw $$\n\n\n\\subsection*{Exercise}\n\n\nSuppose that \n\n$$ f(z) = z^2 $$\n$$ p(z,0) = z^2 $$\n$$ \\text{find } p(z,t) $$\n\nSo what we need to do is, we've got a formula.\nLet's just plug and chug.\n\n\n\n\\begin{equation*} \n\t\\begin{split}\n\t\tp(z,t) &= \\int p_0(z-w,t)f(w)dw  \\\\\n\t\t       &= \\int  \\frac{1}{\\sqrt{2 \\pi t}} e^{-\\frac{(z-w)^2}{2t}} w^2 dw  \n\t\\end{split}\n\\end{equation*}\n\n\nRemember, it's a Gaussian where the variance is $t$.\nSo it's not completely standardized.\nSo there is $t$ dependence in this.\nHow do we do this integral?\nWell, let's change variables. So what we'd like to do is, let's simplify the exponent\nand pick a new variable.\n\n$$ \\text{let } u=\\frac{w-z}{\\sqrt{t}}  \\implies  du=\\frac{dw}{\\sqrt{t}} $$\n$$ \\implies  w=u \\sqrt{t} + z $$\n\nSo let's make those substitutions.\n\n\n\n\\begin{equation*} \n\t\\begin{split}\n\t\tp(z,t) &=   \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty}  e^{-\\frac{u^2}{2}} (u \\sqrt{t} + z)^2 du \n\t\\end{split}\n\\end{equation*}\n\n\nBecause now we almost have things in standardized form\nfor a Gaussian interval, let's just expand that out.\n\n\\begin{equation*} \n\t\\begin{split}\n\t\tp(z,t) &=   \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty}  e^{-\\frac{u^2}{2}} (u^2t + 2u \\sqrt{t}z + z^2) du  \\\\\t\n\t\t &=   t \\Big[\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty}  e^{-\\frac{u^2}{2}} u^2 \\Big] + 0 + \n\t\t z^2 \\cancelto{1}{\\Big[\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty}  e^{-\\frac{u^2}{2}} u^2 \\Big]}\n\t\\end{split}\n\\end{equation*}\n\nLet's look at each of these terms.\nThe first term,  is going to be $u^2t$.\nRemember, $t$ is a constant with respect\nto the variable of integration.\nThe second term, $ 2u \\sqrt{t}z$, is going to vanish.\nBecause it's linear in $u$, this is an odd function in $u$.\nWe're going from minus infinity to infinity.\nAnd odd functions are going to have varnishing integrals.\nIt's just a plus sign to the minus sign\nare going to cancel each other out.\nAnd then, the last term, $z^2$, that's just going to be multiplied by a constant a constant equal to 1.\n\nBecause $\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty}  e^{-\\frac{u^2}{2}} u^2$ is just the variance\nof the standardized Gaussian distribution.\n\nSo we do the integrals. And what we're left with is :\n\n\t$$ p(z,t) = z^2+t $$\n\t\n\nAnd we can check that it satisfies our differential\nequation.\n\n$$ \\frac{\\partial p}{\\partial t} = 1 \\text{ , } \\frac{1}{2} \\frac{\\partial ^2 p}{\\partial z} = 1 $$\n\nAnd if we subtract the two of them, we get 0.\nSo we're done.\nSo this is the answer.\nLet's do one more exercise.\n\n\\subsection*{Exercise}\n\nSlightly different version of the one that we did in lecture.\nBut now, don't refer back to the lecture.\nJust take a look at what we've done for the integrals.\nAnd do this one yourself.\nSo what I'd like to do is introduce the Gaussian\ncumulative distribution function,\nwhich is going to be useful and show up in a few places.\nI will call this $\\Phi(x)$.\nIt's going to be defined as:\n\n$$ \\Phi(x) =  \\frac{1}{\\sqrt{2 \\pi}}\\int_{-\\infty}^{x} e^{-z^2/2} dz = Prob(Z<x) $$\n\n\nSo I compute the left side of the integral\nof the bell curve for the Gaussian distribution\nup to some point $x$.\nSo in terms of Gaussian probabilities,\nthis is the same thing as the probability\nthat a Gaussian random variable $Z$ is less\nthan some particular value $x$.\nNow, from the fundamental theorem of calculus of course,\nI know that :\n\n$$ \\frac{d}{dx}\\Phi(x) =  \\frac{1}{\\sqrt{2 \\pi}} e^{-x^2/2} $$\n\n\nSo I can differentiate or I can integrate.\nI can go back and forth.\nBut this basic idea that it's an incomplete integral.\nSo I integrate from minus infinity\nup to a particular value $x$ that's defined out here.\nIt's going to be useful, and we'll\nsee that it shows up in a bunch of places.\nHere's a really simple example.\n\n\n\\begin{equation*}\n\tf(w) =\n\t\\begin{cases}\n\t\t1 & \\text{if $w<\\kappa$ }\\\\\n\t\t0 & \\text{if $w>\\kappa$}\n\t\\end{cases}       \n\\end{equation*}\n\n$ f(w) = p(w,0)$  find $p(z,t)$\n\nSo the question is, find $p(z,t)$,\n\nSo at time 0, it's a step function.\nIt's either 0 or 1 depending on the value of its argument.\n\nSo what we'd like to do is, we want to find $p(z,t)$\nfor the general case.\nSo take a moment, see if you can work it out\nfrom our general definition.\n\n\n\n\nRemember that our definition is, we integrate $p_0$\nagainst $p_0$ evaluated at $z-2$ against the function $f(w)$.\nAnd we integrate that over $w$ in an explicit expression\nin terms of $z$.\nGo take a moment to do that.\nAnd then, we'll take a look at this together.\n\nOK?\nLet's go.\nLet's just work from the definition.\nThe reason why this is particularly nice\nis the integrand is either 1 or 0.\nSo there's an interesting generalization\nthat's important for the Black-Scholes case, where\nwe might-- instead of 1 or 0, we might\nlike to let it be 0 in the lower case, but $\\kappa-w$\nin the upper case.\nSo after you've done this one, I'd\nsuggest trying that one as an extension.\nBut this one's fairly straightforward.\nSo let's do this one together just\nto make sure we've got the concepts and our definitions\nof the integral.\n\n\nSo this is going to be: \n\n$$\tp(z,t) =    \\int_{-\\infty}^{\\kappa} \\frac{1}{\\sqrt{2 \\pi t}} e^{-\\frac{(z-w)^2}{2t}} dw  $$\n\n$$ \\text{let } u = \\frac{w-z}{\\sqrt{t}}  \\implies du = \\frac{dw}{\\sqrt{t}}$$\n\nIn addition, our upper limit of integration is $w=\\kappa$.\nAnd that's going to translate into an upper limit of \n$$u* = \\frac{\\kappa-z}{\\sqrt{t}} $$\n\nSo, now we have:\n\n\\begin{equation*} \n\t\\begin{split}\n\t\tp(z,t) &=   \\int_{-\\infty}^{\\frac{\\kappa-z}{\\sqrt{t}}} \\frac{1}{\\sqrt{2 \\pi }} e^{-\\frac{u^2}{2}} du \\\\\t\n\t\t&=   \\Phi \\Big(\\frac{\\kappa-z}{\\sqrt{t}} \\Big)\n\t\\end{split}\n\\end{equation*}\n\nWhich is a very well behaved function\nfor positive values of $t$.\nAnd it would be interesting to take a look\nand plot this as t goes to 0.\nBut right now, we have the result that we saw it.\nAnd we can check this, again, by differentiating and putting it\ninto the differential equation, and verifying that it satisfies\nthe equation, and verifying that it\nsatisfies the initial conditions a $t$ equals 0.\nWhich as I said, it requires taking a limit,\nbecause we can't immediately set $t$ equals 0\nin this case in the way we did previously.\n\n\t\n\\end{document}", "meta": {"hexsha": "e8468305a2e9910489b031cfbea6b9ff21d73301", "size": 12471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.455x/recitation_05.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_05.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_05.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": 31.4924242424, "max_line_length": 209, "alphanum_fraction": 0.6590489937, "num_tokens": 4073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8962513724408292, "lm_q1q2_score": 0.689289208504457}}
{"text": "\\documentclass[pdftex,a4paper,12pt]{scrartcl}\n\n\\usepackage[T1]{fontenc}\n\\usepackage{lmodern} % Latin Modern font\n\n\\usepackage{amsmath,amssymb,amsthm}\n\\usepackage{mathtools}\n\\usepackage{enumitem}\n\\usepackage{hyperref}\n\\usepackage[capitalise]{cleveref}\n\\usepackage{tikz}\n\\usetikzlibrary{cd}\n%\\usepackage{algpseudocode}\n\n%%%\n%%% THEOREM ENVIRONMENTS (amsthm.sty)\n%%%\n\\theoremstyle{plain}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{proposition}[theorem]{Proposition}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}\n\\newtheorem{problem}{Problem}\n\n\\theoremstyle{remark}\n\\newtheorem{example}[theorem]{Example}\n\\newtheorem{remark}[theorem]{Remark}\n\\newtheorem*{notation}{Notation}\n\n\\numberwithin{equation}{section}\n\n%%%\n%%% Article data\n%%%\n\\title{Technical Materials}\n\\author{Jun Yoshida}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\nIn this note, we explain some technical materials used in the codes.\n\n\\tableofcontents\n\n\\section{On the second fundamental forms}\n\n\\subsection{Definition}\n\n\\begin{definition}\nLet $M$ be an orientable $n$-dimensional manifold embedded in the Euclidean space $\\mathbb R^{n+1}$.\nThen, a \\emph{normal vector field} is a section $\\mathbf n$ of the vector bundle $\\left.T\\mathbb R^{n+1}\\right|_M\\to M$ such that, for each $p\\in M$, we have\n\\begin{equation}\n\\label{eq:normal-vf}\nT\\mathbb R^{n+1}= T_pM\\oplus \\mathbb R\\mathbf n(p)\n\\quad.\n\\end{equation}\nWe in addition say that $\\mathbf n$ is positive provided the identity \\eqref{eq:normal-vf} respects the orientation.\n\\end{definition}\n\nNote that every $M$ as in the definition above admits a unique normal vector field of constant length $1$; indeed, the standard metrin con $\\mathbb R^{n+1}$ and the orientation on $M$ determine a splitting of the following short exact sequence of vector bundles:\n\\[\n0\\to TM\\to \\left.T\\mathbb R^{n+1}\\right|_M \\to \\nu M\\to 0\n\\quad,\n\\]\nwhere $\\nu M$ is the normal bundle of the embedding $M\\hookrightarrow\\mathbb R^{n+1}$.\nOn the other hand, since $M$ is orientable, the bundle $\\nu M$ is orientable and hence a trivial bundle.\nThus, one can choose a nowhere-vanishing section $s:M\\to \\nu M$, and a unit normal vector field $\\mathbf n$ is obtained by normalizing $s$; here is only one choice of $\\mathbf n$ so that it is positive.\n\nIn the case above, let us denote by $S\\mathbb R^{n+1}$ the unit sphere bundle associated to the tangent bundle $\\mathbb R^{n+1}$; hence, if $\\mathbf n$ is a positive normal vector field on $M$, then the assignment\n\\[\nM \\to S\\mathbb R^{n+1}\n\\ ;\\quad p\\mapsto \\frac{\\mathbf n(p)}{\\|\\mathbf n(p)\\|}\n\\]\ndefines a section of the bundle $\\left. S\\mathbb R^{n+1}\\right|_M\\to M$.\nSince $S\\mathbb R^{n+1}$ has a canonical trivialization, this gives rise to a smooth map $\\nu:M\\to S^n$, which we call the \\emph{Gauss map}.\n\n\\begin{definition}\nLet $\\nu$ be the Gauss map on $M$.\nThen, the \\emph{second fundamental form} is the bilinear form\n\\[\n\\mathbf{II}_M:TM\\otimes_M TM\\to\\underline{\\mathbb R}_M\n\\]\ngiven by\n\\[\n\\mathbf{II}_M(v,w)\n\\coloneqq -\\langle d\\nu(v),w\\rangle\n\\quad.\n\\]\n\\end{definition}\n\n\\begin{example}\nIn case $n=1$, let $\\gamma=(\\gamma_1,\\gamma_2):(-\\varepsilon,\\varepsilon)\\to M\\subset\\mathbb R^2$ be a regular curve which gives a coordinate around a point $\\gamma(0)=p\\in M$.\nThen, we have a positive normal vector field on the coordinate given by\n\\[\n\\gamma^\\perp(t)\\coloneqq \\left(-\\frac{d\\gamma_2}{dt}(t),\\frac{d\\gamma_1}{dt}(t)\\right)\n\\quad.\n\\]\nIn particular, if $\\gamma$ is parametrized by arc-length, $\\gamma^\\perp$ gives the Gauss map as $\\nu\\gamma=\\gamma^\\perp$.\nIt follows that\n\\[\nd\\nu\\left(\\frac{d\\gamma}{dt}(0)\\right)\n= \\frac{d\\gamma^\\perp}{dt}(0)\n= \\left(-\\frac{d^2\\gamma_2}{dt^2}(0),\\frac{d^2\\gamma_1}{dt^2}(0)\\right)\n\\]\nand the second fundamental form is determined by the equation\n\\[\n\\mathbf{II}_\\gamma\\left(\\frac{d\\gamma}{dt}(0),\\frac{d\\gamma}{dt}(0)\\right)\n= \\frac{d^2\\gamma_2}{dt^2}(0)\\frac{d\\gamma_1}{dt}(0) - \\frac{d^2\\gamma_1}{dt^2}(0)\\frac{d\\gamma_2}{dt}(0)\n= \\left\\langle \\frac{d^2\\gamma}{dt^2}(0), \\gamma^\\perp(0)\\right\\rangle\n\\quad.\n\\]\nNote that, since $\\gamma$ has a constant velocity, namely $\\|d\\gamma/dt\\|\\equiv1$, the vector $d^2\\gamma/dt^2(0)$ is parallel to $\\gamma^\\perp$.\nHence, we have\n\\[\n\\mathbf{II}_\\gamma\\left(\\frac{d\\gamma}{dt}(0),\\frac{d\\gamma}{dt}(0)\\right)\\cdot\\gamma^\\perp(0)\n= \\frac{d^2\\gamma}{dt^2}(0)\n\\quad,\n\\]\nwhich is exactly the curvature vector of the curve $\\gamma$.\n\\end{example}\n\n\\subsection{Formula for the regular level sets}\n\nWe now compute the second fundamental form for the regular level set of a function.\nLet $f:\\mathbb R^{n+1}\\to\\mathbb R$ be a smooth function with $0\\in\\mathbb R$ as a regular value.\nWe compute the second fundamental form on the submanifold\n\\[\nM\\coloneqq\\{x\\in\\mathbb R^{n+1}\\mid f(x)=0\\}\n\\quad.\n\\]\nIt directly follows from the definition that the following is an exact sequence of vector bundles over $M$:\n\\[\n0\\to TM\\hookrightarrow \\left.T\\mathbb R^{n+1}\\right|_M \\xrightarrow{df} \\underline{\\mathbb R}_M\\to 0\n\\quad,\n\\]\nwhere $\\underline{\\mathbb R}_M$ is the trivial bundle with fiber $\\mathbb R$.\nIn other words, a vector $a_0\\frac\\partial{\\partial x_0}+\\dots+a_n\\frac\\partial{\\partial x_n}$ on $\\mathbb R^{n+1}$ is tangent to $M$ if and only if the vector\n\\begin{equation}\n\\label{eq:df-normal}\ndf\\left(\\sum_{i=0}^n a_i\\frac\\partial{\\partial x_i}\\right)\n= \\sum_{i=0}^n a_i\\frac{\\partial f}{\\partial x_i}\n\\end{equation}\nvanishes.\nThis implies that, for each $\\vec x=(x_0,\\dots,x_n)\\in M$, the vector\n\\[\ndf^\\ast(\\vec x)\n\\coloneqq \\left(\\frac{\\partial f}{\\partial x_0}(\\vec x),\\dots,\\frac{\\partial f}{\\partial x_n}(\\vec x)\\right)\n\\]\nis normal to $M$.\nWe endow $M$ with the orientation so that $\\mathbf n_f$ is positive.\nThen, for the Gauss map $\\nu$, we have\n\\begin{equation}\n\\label{eq:f-Gauss}\nd_{\\vec x}\\nu\\left(\\sum_{i=0}^n a_i\\frac\\partial{\\partial x_i}\\right)\n= \\sum_{i=0}^n a_i \\left.\\frac{\\partial}{\\partial x_i}\\right|_{\\vec x} \\frac{df^\\ast}{\\|df^\\ast\\|}\n\\quad.\n\\end{equation}\nNote that the equation \\eqref{eq:df-normal} implies that\n\\begin{equation}\n\\label{eq:diff-normrec}\n\\begin{split}\n\\sum_{i=0}^n a_i\\left.\\frac{\\partial}{\\partial x_i}\\right|_{\\vec x}\n\\frac1{\\|df^\\ast\\|}\n&= \\sum_{i=0}^n a_i\\left.\\frac{\\partial}{\\partial x_i}\\right|_{\\vec x}\\left(\\sum_{j=0}^n\\left(\\frac{\\partial f}{\\partial x_j}\\right)^2\\right)^{-1/2} \\\\\n& = -\\frac1{2\\|df^\\ast(\\vec x)\\|^3} \\sum_{i=0}^n\\sum_{j=0}^n 2a_i\\frac{\\partial f}{\\partial x_j}(\\vec x)\\frac{\\partial^2f}{\\partial x_i\\partial x_j}(\\vec x) \\\\\n& = -\\frac1{\\|df^\\ast(\\vec x)\\|^3}\\sum_{j=0}^n \\frac{\\partial f}{\\partial x_j}(\\vec x)\\left.\\frac{\\partial}{\\partial x_j}\\right|_{\\vec x} \\sum_{i=0}^n a_i\\frac{\\partial f}{\\partial x_i} \\\\\n& = 0\n\\quad.\n\\end{split}\n\\end{equation}\nCombining \\eqref{eq:f-Gauss} and \\eqref{eq:diff-normrec}, we obtain\n\\begin{equation}\n\\label{eq:f-II-form}\n\\mathbf{II}_{\\{f=0\\}}\\left(\\sum_{i=0}^na_i\\frac{\\partial}{\\partial x_i},\\sum_{j=0}^nb_j\\frac\\partial{\\partial x_j}\\right)\n= -\\frac{1}{\\|df^\\ast\\|}\\sum_{i=0}^n\\sum_{j=0}^n a_ib_j\\frac{\\partial^2f }{\\partial x_i\\partial x_j}\n\\quad.\n\\end{equation}\nIf we denote by $H_f$ the Hessian matrix, then the bilinear form $\\mathbf{II}_{\\{f=0\\}}$ is represented by the matrix $H_f/\\|df^\\ast\\|$.\n\n\\begin{example}\n\\label{ex:II-on-circle}\nFor a positive real number $r$, define $f:\\mathbb R^2\\to\\mathbb R$ by\n\\begin{equation}\n\\label{eq:circle-deffun}\nf(x,y)\\coloneqq x^2+y^2-r^2\n\\quad.\n\\end{equation}\nPut $C\\coloneqq\\{f=0\\}$ the zero-set; i.e. the circle of radius $r$.\nFor each $(x,y)\\in C$, we have\n\\[\ndf^\\ast(x,y) = (2x,2y)\n\\ ,\\quad\n\\|df^\\ast(x,y)\\| = \\sqrt{4x^2 + 4y^2} = 2r\n\\quad.\n\\]\nOn the other hand, $C$ is parametrized by the map\n\\[\n\\gamma:\\mathbb R\\to C\n\\ ;\\quad \\theta\\mapsto \\left(r\\cos\\frac\\theta{r},r\\sin\\frac\\theta{r}\\right)\n\\]\nso that $\\|d\\gamma/d\\theta\\|\\equiv 1$.\nWe have\n\\[\n\\mathbf{II}_C\\left(\\frac{d\\gamma}{dt}(\\theta),\\frac{d\\gamma}{dt}(\\theta)\\right)\n= \\frac1{2r}\\left(2\\left(-\\sin\\frac\\theta{r}\\right)^2 + 2\\left(\\cos\\frac\\theta{r}\\right)^2\\right) = \\frac1{r}\n\\quad.\n\\]\nNote that the vector\n\\begin{equation}\n\\label{eq:II-curvature}\n\\mathbf{II}_C\\left(\\frac{d\\gamma}{dt}(\\theta),\\frac{d\\gamma}{dt}(\\theta)\\right)\\cdot \\frac{df^\\ast}{\\|df^\\ast\\|}\n= -\\frac{1}{r^2}\\gamma(\\theta)\n\\end{equation}\nequals the curvature vector of $C$.\n\\end{example}\n\n\\begin{remark}\nIf a codimension $1$ submanifold $M\\subset\\mathbb R^{n+1}$ is defined as a zero-set of a function $f$, then the orientation on $M$ does depend on $f$.\nFor example, to define the same submanifold $C$ as in \\cref{ex:II-on-circle}, one can take a function $g:\\mathbb R^2\\to\\mathbb R^2$ given by\n\\[\ng(x,y)\\coloneqq -x^2-y^2+r^2\n\\]\ninstead of $f$ in \\eqref{eq:circle-deffun}.\nThen, the induced orientation on $C$ is reversed; so we have\n\\[\n\\mathbf{II}_{\\{g=0\\}}\\left(\\frac{d\\gamma}{dt}(\\theta),\\frac{d\\gamma}{dt}(\\theta)\\right)\n= -\\frac1{r}\n\\quad.\n\\]\nIn contrast, since $df^\\ast = -dg^\\ast$, the curvature vector \\eqref{eq:II-curvature} is invariant of the choice of the defining function.\n\\end{remark}\n\nMore generally, we have the following result in the $2$-dimensional cases.\n\n\\begin{proposition}\n\\label{prop:f-curvature}\nLet $f:\\mathbb R^2\\to\\mathbb R$ be a smooth function with $0\\in\\mathbb R$ being a regular value; put $C\\coloneqq\\{(x,y)\\mid f(x,y)=0\\}$.\nThen, the curvature vector $\\kappa$ of $C$ is, as a function on $C$, given by\n\\[\n\\kappa\n= -\\left(\n\\left(\\frac{\\partial f}{\\partial y}\\right)^2\\frac{\\partial^2 f}{\\partial x^2}\n-2\\frac{\\partial f}{\\partial x}\\frac{\\partial f}{\\partial y}\\frac{\\partial^2 f}{\\partial x\\partial y}\n+\\left(\\frac{\\partial f}{\\partial x}\\right)^2\\frac{\\partial^2 f}{\\partial y^2}\n\\right)\\cdot\n\\frac{df^\\ast}{\\|df^\\ast\\|^4}\n\\]\n\\end{proposition}\n\\begin{proof}\nWe set\n\\[\ndf^\\perp(x,y)\n\\coloneqq \\left(-\\frac{\\partial f}{\\partial y}(x,y), \\frac{\\partial f}{\\partial x}(x,y)\\right)\n\\quad.\n\\]\nIt is easily verify that, if $(x,y)\\in C$, then $df^\\perp(x,y)$ is a tangent vector at $(x,y)$.\nWe also have $\\|df^\\perp(x,y)\\|=\\|df^\\ast(x,y)\\|$.\nHence, using the formula \\eqref{eq:f-II-form}, we obtain\n\\[\n\\begin{split}\n\\kappa\n&= -\\mathbf{II}_C\\left(\\frac{df^\\perp}{\\|df^\\perp\\|},\\frac{df^\\perp}{\\|df^\\perp\\|}\\right)\\cdot\\frac{df^\\ast}{\\|df^\\ast\\|} \\\\\n&= -\\left(\n\\left(\\frac{\\partial f}{\\partial y}\\right)^2\\frac{\\partial^2 f}{\\partial x^2}\n-2\\frac{\\partial f}{\\partial x}\\frac{\\partial f}{\\partial y}\\frac{\\partial^2 f}{\\partial x\\partial y}\n+\\left(\\frac{\\partial f}{\\partial x}\\right)^2\\frac{\\partial^2 f}{\\partial y^2}\n\\right)\\cdot\n\\frac{df^\\ast}{\\|df^\\ast\\|^4}\n\\quad.\n\\end{split}\n\\]\n\\end{proof}\n\n\\begin{example}\nLet $f:\\mathbb R^2\\to\\mathbb R$ be a quadratic function of the form\n\\[\nf(x,y)=ax^2+by^2-c\n\\]\nwith $ab\\neq 0$ and $c\\neq 0$.\nThen,\n\\[\ndf^\\ast(x,y) = (2ax, 2by)\n\\ ,\\quad\n\\|df^\\ast(x,y)\\| = 2\\sqrt{a^2x^2+b^2y^2}\n\\quad;\n\\]\nso in particular, $0\\in\\mathbb R$ is a regular value of $f$.\nBy virtue of \\cref{prop:f-curvature}, we obtain\n\\[\n\\kappa(x,y)\n= -\\frac{8ab^2y^2+8a^2bx^2}{16(a^2x^2+b^2y^2)^2}(2ax,2by)\n= -\\frac{abc}{(a^2x^2+b^2y^2)^2}(ax,by)\n\\quad.\n\\]\nFor example, if $a=b=1$ and $c=r^2$, this agrees with the computation in \\cref{ex:II-on-circle}.\n\\end{example}\n\n\n\\section{Quadratic B\\'ezier triangles}\n\\label{sec:qbeztri}\n\n\\subsection{Definition}\n\nLet $V$ be a (finite dimensional) real vector space, so there is a canonical identification $TV=V\\times V$.\nWe write\n\\[\n\\Delta^2\\coloneqq\\{(t_0,t_1,t_2)\\in\\mathbb R^3\\mid t_0+t_1+t_2=1,\\,t_i\\ge0\\ \\text{for $i=0,1,2$}\\}\n\\]\nthe (geometric) $2$-simplex.\n\n\\begin{definition}\nA \\emph{quadratic B\\'ezier triangle} in $V$ is a map $p:\\Delta^2\\to V$ of the form\n\\[\np(t_0,t_1,t_2)\n= \\sum_{i=0}^2 t_i^2 v^{(i)}+2\\sum_{\\{i,j,k\\}=\\{0,1,2\\}} t_i t_je^{(k)}\n\\]\nfor six points $v^{(0)},v^{(1)},v^{(2)},e^{(0)},e^{(1)},e^{(2)}\\in V$, which are called the \\emph{control points} of $p$.\n\\end{definition}\n\nIt is easily seen that\n\\[\np(1,0,0) = v^{(0)}\n\\ ,\\quad p(0,1,0) = v^{(1)}\n\\ ,\\quad p(0,0,1) = v^{(2)}\n\\ ,\n\\]\nwhile the image $p(\\Delta^2)$ may not contain the points $e^{(0)}$, $e^{(1)}$, and $e^{(2)}$.\n\n\\begin{lemma}\nA quadratic B\\'ezier triangle restricts to a quadratic B\\'ezier curve on each edge of $\\Delta^2$.\n\\end{lemma}\n\\begin{proof}\nNote that an edge of $\\Delta^2$, namely\n\\[\n\\partial_i\\Delta^2\\coloneqq \\{(t_0,t_1,t_2)\\in\\Delta^2\\mid t_i=0\\}\n\\]\nfor $i=0,1,2$, is parametrized so that, with cyclic indices,\n\\[\nt_i=0\n,\\,\nt_{i+1}=t\n,\\,\nt_{i+2}=1-t\n\\quad.\n\\]\nIn this point of view, we have\n\\[\n\\left.p\\right|_{\\partial_i\\Delta^2}(t)\n= t^2v^{(i+1)} + 2t(1-t) e^{(i)} + (1-t)^2 v^{(i+2)}\n\\quad.\n\\]\n\\end{proof}\n\n\\subsection{Tangent space}\n\\label{sec:Beztri:tangent}\n\nWe compute the tangent spaces of quadratic B\\'ezier triangles.\nWe fix a quadratic B\\'ezier triangle $p:\\Delta^2\\to V$ with control points $v^{(0)},v^{(1)},v^{(2)},e^{(0)},e^{(1)},e^{(2)}\\in V$.\n\nFirst observe that, a vector\n\\[\nX=a\\frac\\partial{\\partial t_0}+b\\frac\\partial{\\partial t_1}+c\\frac\\partial{\\partial t_2}\n\\]\non a point of $\\Delta^2$ is tangent to $\\Delta^2$ if and only if $a+b+c=0$.\nWe in particular set\n\\[\nX^{ij}\\coloneqq  \\frac12\\left(\\frac\\partial{\\partial t_i}-\\frac\\partial{\\partial t_j}\\right)\n\\quad.\n\\]\nThen, for each point $\\vec t\\in\\Delta^2$, the tangent space $T_{\\vec t}\\Delta^2$ is spanned by two vectors $X^{ij}$ and $X^{ik}$ provided $\\{i,j,k\\}=\\{0,1,2\\}$.\nOn the other hand, we have\n\\[\np_\\ast\\left(\\frac\\partial{\\partial t_i}\\right)\n= 2t_iv^{(i)}+2t_je^{(k)}+2t_ke^{(j)}\n\\]\nand hence\n\\begin{equation}\n\\label{eq:dpX}\n\\begin{split}\np_\\ast(X^{ij})\n&= t_iv^{(i)}-t_jv^{(j)}+(t_j-t_i)e^{(k)}+t_k(e^{(j)}-e^{(i)}) \\\\\n&= t_i(v^{(i)}-e^{(k)})+t_j(e^{(k)}-v^{(j)})+t_k(e^{(j)}-e^{(i)})\n\\quad.\n\\end{split}\n\\end{equation}\nPutting $w_{ij}\\coloneqq e^{(k)}-v^{(i)}$, one also obtains\n\\begin{equation}\n\\label{eq:dpX-inw}\np_\\ast(X^{ij})\n= -t_iw_{ij}+t_jw_{ji}+t_k(w_{ki}-w_{kj})\n\\quad.\n\\end{equation}\n\n\\subsection{Singular loci}\n\\label{sec:Beztri:sing}\n\nWe are interested in the singular locus of a quadratic B\\'ezier triangle $p:\\Delta^2\\to V$ for $\\dim V\\ge 2$.\nIn view of the previous section, a point $\\vec t=(t_0,t_1,t_2)\\in\\Delta^2$ is a critical point of $p$ if and only if two vectors $p_\\ast(X^{ij})$ and $p_\\ast(X^{ik})$ are in parallel for $\\{i,j,k\\}=\\{0,1,2\\}$.\nUsing the exterior product $V\\wedge V$, this is equivalent to the equation\n\\[\np_\\ast(X^{ij})\\wedge p_\\ast(X^{ik})=0\n\\quad.\n\\]\nOn the other hand, by virtue of the equation \\eqref{eq:dpX-inw}, we have\n\\begin{equation}\n\\label{eq:singlocus-def}\n\\begin{split}\n& p_\\ast(X^{ij})\\wedge p_\\ast(X^{ik}) \\\\\n&= \\left(-t_iw_{ij}+t_jw_{ji}+t_k(w_{ki}-w_{kj})\\right)\\wedge\\left(-t_iw_{ik}+t_j(w_{ji}-w_{jk})+t_kw_{ki}\\right) \\\\\n&=\n\\begin{multlined}[t]\nt_i^2 w_{ij}\\wedge w_{ik}-t_j^2w_{ji}\\wedge w_{jk}-t_k^2w_{kj}\\wedge w_{ki}\n- t_it_j\\left(w_{ij}\\wedge(w_{ji}-w_{jk})+w_{ji}\\wedge w_{ik}\\right) \\\\\n- t_jt_k\\left(w_{ki}\\wedge w_{jk}+w_{kj}\\wedge(w_{ji}-w_{jk})\\right)\n- t_it_k\\left(w_{ij}\\wedge w_{ki}+(w_{ki}-w_{kj})\\wedge w_{ik}\\right)\n\\quad.\n\\end{multlined}\n\\end{split}\n\\end{equation}\nIt follows that the quadratic form \\eqref{eq:singlocus-def} together with the linear equation $t_i+t_j+t_K=1$ defines the singular locus of $p$.\nNote that, if $\\dim V=n$, then $V\\wedge V$ is of dimension $n(n-1)/2$; so we have $n(n-1)/2$ defining polynomials.\nIn particular, there is generically no critical point of $p$ except in the case $n=2$ where they form a $1$-dimensional submanifold of $\\Delta^2$.\n\n\n\\section{On quadratic curves}\n\n\\subsection{Definition}\n\nRecall that a \\emph{quadratic form} on $\\mathbb R^n$ is nothing but a real homogeneous polynomial of degree $2$ with $n$ variables.\nMore precisely, it is a polynomial of the form\n\\begin{equation}\n\\label{eq:quad-form-alph}\nq(x_1,\\dots,x_n)\n= \\sum_{i=1}^n A_ix_i^2+2\\sum_{1\\le i<j\\le n} B_{ij}x_ix_j\n\\quad.\n\\end{equation}\nFor a quadratic form $q$ on $\\mathbb R^n$, we define the associated matrix $M_q$ to be\n\\[\n\\begin{bmatrix}\nA_1 & B_{12} & \\cdots & B_{1n} \\\\\nB_{12} & A_2 & \\cdots & B_{2n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nB_{1n} & B_{2n} & \\cdots & A_n\n\\end{bmatrix}\n\\quad.\n\\]\nThen, we can write\n\\begin{equation}\n\\label{eq:quad-form-mat}\nq(x_1,\\dots,x_n)\n= \\vec x^{\\mathsf T} M_q\\vec x\n=\n\\begin{bmatrix}\nx_1 & \\cdots & x_n\n\\end{bmatrix}\nM_q\n\\begin{bmatrix}\nx_1 \\\\ \\vdots \\\\ x_n\n\\end{bmatrix}\n\\quad.\n\\end{equation}\n\n\\begin{definition}\nA quadratic form $q$ on $\\mathbb R^n$ is said to be \\emph{non-degenerate} (resp. \\emph{degenerate}) if $\\det M_q\\neq 0$ (resp. $\\det M_q=0$).\n\\end{definition}\n\n\\begin{lemma}\nIf $q$ is a non-degenerate quadratic form on $\\mathbb R^n$, then for the map\n\\[\nf_q:\\mathbb R^{n-1}\\to\\mathbb R\\ ;\\quad (y_1,\\dots,y_{n-1}) \\mapsto q(y,\\dots ,y_{n-1},1)\n\\quad,\n\\]\n$0\\in\\mathbb R$ is a regular value of $f_q$.\n\\end{lemma}\n\\begin{proof}\nWe prove the contraposition; in particular, we show that if $\\vec y=(y_1,\\dots,y_{n-1})\\in\\mathbb R^{n-1}$ is a critical point of $f_q$ with $f_q(\\vec y)=0$, then the vector $(y_1,\\dots,y_{n-1},1)$ belongs to the kernel of $M_q$.\n\nThe direct computation shows that the total derivative $df:\\mathbb R^{n-1}\\to T^\\ast\\mathbb R^{n-1}$ is given by\n\\[\ndf_q(y_1,\\dots,y_{n-1})\n= \\sum_{i=1}^{n-1}\\left(\\vec e^{(i)\\mathsf T} M_q\\widehat y+\\widehat y^{\\mathsf T} M_q e_i\\right) dy_i \\\\\n= 2 \\sum_{i-1}^{n-1} \\vec e^{(i)\\mathsf T}M_q\\widehat y\\, dy_i\n\\quad,\n\\]\nhere $\\widehat y=(y_1,\\dots,y_{n-1},1)$ and $\\vec e^{(i)}=(0,\\dots,\\overset{\\substack{i\\\\\\smash\\smile}}{1},\\dots,0)$ seen as column vectors.\nUnder the canonical identification $T^\\ast\\mathbb R^{n-1}\\cong \\mathbb R^{n-1}\\times\\mathbb R^{n-1}$, it turns out that $df$ can be seen as the map given by\n\\begin{equation}\n\\label{eq:prf:fq-diff}\ndf_q(y_1,\\dots,y_{n-1})\n= 2M_q'\\vec y+ 2v_q\n\\quad,\n\\end{equation}\nwhere $\\vec y=(y_1,\\dots,y_{n-1},0)$ and $M_q'$ and $v_q$ are defined so that\n\\[\nM_q =\n\\left[\n\\begin{array}{c|c}\n  M_q' & v_q  \\rule[-1.5ex]{0pt}{4ex}\\\\\\hline\\rule[-1.5ex]{0pt}{4ex}\n  v_q^{\\mathsf T} & A_n\n\\end{array}\n\\right]\n\\quad.\n\\]\nOn the other hand, we have\n\\[\n\\begin{split}\nf_q(y_1,\\dots,y_{n-1})\n&= q(y_1,\\dots,y_{n-1},1) \\\\\n&= \\widehat y^{\\mathsf T} M_q\\widehat y \\\\\n&= \\vec y^{\\mathsf T} M_q'\\vec y + 2v_q^{\\mathsf T}\\vec y + A_n\n\\quad.\n\\end{split}\n\\]\nHence, for $(y_1,\\dots,y_{n-1})\\in\\mathbb R^{n-1}$ with $df(y_1,\\dots,y_{n-1})=0$, we have\n\\begin{equation}\n\\label{eq:prf:fq-critv}\nf_q(y_1,\\dots,y_{n-1})\n= v_q^{\\mathsf T}\\vec y + A_n\n\\quad.\n\\end{equation}\nCombining \\eqref{eq:prf:fq-diff} and \\eqref{eq:prf:fq-critv}, we obtain $M_q\\widehat y=0$ provided $df_q(y_1,\\dots,y_{n-1})=f_q(y_1,\\dots,y_{n-1})=0$.\nThis is exactly what we want to show.\n\\end{proof}\n\n\\begin{definition}\nA \\emph{(real) quadratic curve} is a curve $C$ in $\\mathbb R^2$ such that\n\\[\nC=\\{(x,y)\\in\\mathbb R^2\\mid q(x,y,1)=0\\}\n\\]\nfor a quadratic form $q(x,y,z)$ on $\\mathbb R^3$.\n\\end{definition}\n\n\\begin{remark}\nIt is easily seen that a quadratic form actually defines an algebraic function on the projective space $\\mathbb P^n$.\nOne may sometimes use the word ``quadratic curves'' to refer algebraic subsets of the projective space $\\mathbb P^2$ defined by quadratic forms of three variables.\nIn such cases, ``quadratic curves'' are always compact while ours might not.\n\\end{remark}\n\n\\subsection{The srandard forms}\n\n\\begin{proposition}\n\\label{prop:quad-standard}\nLet $q$ be a quadratic form on $\\mathbb R^n$ with matrices $M_q$ and $M'_q$ as in the previous section.\nSuppose both the determinants $\\det M_q$ and $\\det M_q$ are non-zero.\nThen, there is an orthogonal matrix $P\\in\\mathcal O(n-1)$ such that\n\\begin{gather}\n\\label{eq:M'-diag}\nM'_q = P\n\\begin{bmatrix}\n\\lambda_1 && O \\\\\n& \\ddots & \\\\\nO && \\lambda_{n-1}\n\\end{bmatrix}\nP^{\\mathsf T}\n\\qquad\\text{with $\\lambda_i\\in\\mathbb R$}\n\\quad;\n\\\\\n\\label{eq:q-standard}\nq(y_1,\\dots,y_{n-1},1)\n= \\sum_{i=1}^{n-1} \\lambda_i\\left(Y_i+\\frac{\\widetilde B_{i n}}{\\lambda_i}\\right)^2 + \\frac{\\det M_q}{\\det M'_q}\n\\quad,\n\\end{gather}\nwhere\n\\[\n\\begin{bmatrix}\nY_1\\\\\\vdots\\\\ Y_{n-1}\n\\end{bmatrix}\n\\coloneqq P^{\\mathsf T}\n\\begin{bmatrix}\ny_1\\\\\\vdots\\\\ y_{n-1}\n\\end{bmatrix}\n\\quad, \\qquad\n\\begin{bmatrix}\n\\widetilde B_{1n} \\\\ \\vdots \\\\ \\widetilde B_{(n-1)n}\n\\end{bmatrix}\n\\coloneqq P^{\\mathsf T}\n\\begin{bmatrix}\nB_{1n} \\\\ \\vdots \\\\ B_{(n-1)n}\n\\end{bmatrix}\n\\]\n\\end{proposition}\n\\begin{proof}\nSince $M'_q$ is a symmetric matrix, we can take an orthogonal matrix $P$ satisfying \\eqref{eq:M'-diag}.\nThen, we have\n\\[\n\\begin{split}\n& q(y_1,\\dots,y_{n-1},1) \\\\\n&=\n\\begin{bmatrix}\ny_1 & \\cdots & y_{n-1} & 1\n\\end{bmatrix}\n\\left[\n\\begin{array}{c|c}\n  P\n  \\begin{bmatrix}\n  \\lambda_1 && \\\\\n  & \\ddots & \\\\\n  && \\lambda_{n=1}\n  \\end{bmatrix}\n     P^{\\mathsf T}\n  &\n    \\begin{matrix}\n    B_{1n} \\\\ \\vdots \\\\ B_{(n-1)n}\n    \\end{matrix}\n  \\\\\\hline\n  \\begin{matrix}\n  B_{1n} & \\cdots & B_{(n-1)n}\n  \\end{matrix}\n      & A_n\n\\end{array}\n\\right]\n\\begin{bmatrix}\ny_1 \\\\ \\vdots \\\\ y_{n-1} \\\\ 1\n\\end{bmatrix}\n\\\\\n&=\n\\begin{bmatrix}\nY_1 & \\cdots & Y_{n-1} & 1\n\\end{bmatrix}\n\\left[\n\\begin{array}{c|c}\n  \\begin{matrix}\n  \\lambda_1 && \\\\ & \\ddots & \\\\ && \\lambda_{n-1}\n  \\end{matrix}\n             & P^{\\mathsf T}\n               \\begin{bmatrix}\n               B_{1n} \\\\ \\vdots \\\\ B_{(n-1)n}\n               \\end{bmatrix}\n  \\\\\\hline\n  \\begin{bmatrix}\n  B_{1n} & \\cdots & B_{(n-1)n}\n  \\end{bmatrix} P\n                 & A_n\n\\end{array}\n\\right]\n\\begin{bmatrix}\nY_1 \\\\ \\vdots \\\\ Y_{n-1} \\\\ 1\n\\end{bmatrix}\n\\\\\n&= \n\\begin{bmatrix}\nY_1 & \\cdots & Y_{n-1} & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\lambda_1  && &\\widetilde B_{1n} \\\\\n& \\ddots && \\vdots \\\\\n&& \\lambda_{n-1} & \\widetilde B_{(n-1)n} \\\\\n\\widetilde B_{1n} & \\cdots & \\widetilde B_{(n-1)n} & A_n\n\\end{bmatrix}\n\\begin{bmatrix}\nY_1 \\\\ \\vdots \\\\ Y_{n-1} \\\\ 1\n\\end{bmatrix}\n\\\\\n&= \\sum_{i=1}^{n-1} (\\lambda_i Y_i^2 + 2\\widetilde B_{in}Y_i) + A_n\n\\\\\n\\end{split}\n\\]\nWe denote by $\\widetilde M_q$ the middle matrix in the fourth line.\nThen, we have $\\det M_q = \\det \\widetilde M_q$ and $\\det M'_q =\\lambda_1\\dots\\lambda_{n-1}$.\nThe asumption $\\det M'_q=0$ guarantees that all of $\\lambda_i$'s are non-zero.\nHence, we obtain\n\\[\n\\begin{split}\nq(y_1,\\dots,y_{n-1},1)\n&= \\sum_{i=1}^{n-1} \\lambda_i\\left(Y_i + \\frac{\\widetilde B_{in}}{\\lambda_i}\\right)^2\n+ A_n-\\sum_{i=1}^{n-1}\\frac{B_{in}^2}{\\lambda_i} \\\\\n&= \\sum_{i=1}^{n-1} \\lambda_i\\left(Y_i + \\frac{\\widetilde B_{in}}{\\lambda_i}\\right)^2 + \\frac{\\det M_q}{\\det M'_q}\n\\end{split}\n\\]\nas required.\n\\end{proof}\n\n\\begin{corollary}\nLet $q$ be a quadratic form on $\\mathbb R^n$ with $\\det M_q\\neq 0$ and $\\det M'_q\\neq 0$.\nSet $\\Lambda_-\\subset\\mathbb R$ the set of those eigen values of $M'_q$ which have different signs from the number $(\\det M_q)/(\\det M'_q)$, and for each $\\lambda\\in\\Lambda_-$, fix an eigenvector $v_\\lambda\\in\\mathbb R^{n-1}$ of $M'_q$ associated to $\\lambda$.\nWe define an affine subspace $H\\subset\\mathbb R^{n-1}$ by\n\\[\nH\n\\coloneqq\\left\\{\n\\vec y\\in\\mathbb R^{n-1}\\mid \\forall\\lambda\\in\\Lambda_-:\\langle v_\\lambda,M'_q\\vec y+\\vec B_n\\rangle=0\n\\right\\}\n\\quad,\n\\]\nwhere $\\vec B_n \\coloneqq (B_{11},\\dots,B_{(n-1)n})$.\nThen, we have\n\\[\nH\\cap\\{(y_1,\\dots,y_{n-1})\\in\\mathbb R^{n-1}\\mid q(y_1,\\dots,y_{n-1},1)=0\\}\n= \\varnothing\n\\quad.\n\\]\n\\end{corollary}\n\\begin{proof}\nLet $\\lambda_1\\le\\dots\\lambda_{n-1}$ be the eigen values of $M'_q$ and $v^{(1)},\\dots,v^{(n-1)}\\in\\mathbb R^{n-1}$ associated unit eigenvectors which are mutually orthogonal.\nThen, the matrix $M'_q$ is diagonalized by the orthogonal matrix\n\\[\nP =\n\\begin{bmatrix}\nv^{(1)} & \\cdots & v^{(n-1)}\n\\end{bmatrix}\n\\quad.\n\\]\nSet $Y_i$ and $\\widetilde B_i$ as in \\cref{prop:quad-standard}, so we have\n\\[\nY_i = \\langle v^{(i)},\\vec y\\rangle\n\\ ,\\quad \\widetilde B_i = \\langle v^{(i)},\\vec B_n\\rangle\n\\]\nand hence\n\\[\n\\langle v^{(i)},M'_q\\vec y + \\vec B_n\\rangle\n= \\langle M'_q v^{(i)},\\vec y\\rangle + \\langle v^{(i)},\\vec B_n\\rangle\n= \\lambda_i Y_i + \\widetilde B_n\n\\quad.\n\\]\nIt follows that, if $\\vec y\\in H$, then all the terms in the sum \\eqref{eq:q-standard} have the same sign, which implies the result.\n\\end{proof}\n\n\\begin{example}\nDefine $q:\\mathbb R^3\\to\\mathbb R$ by\n\\[\nq(x,y,z)\n\\coloneqq 2(x-z)(y-z) - 2z^2 = 2xy - 2xz - 2yz\n\\quad.\n\\]\nThe associated matrices are given by\n\\[\nM_q =\n\\begin{bmatrix}\n0 & 1 & -1 \\\\\n1 & 0 & -1 \\\\\n-1 & -1 & 0\n\\end{bmatrix}\n\\quad,\\qquad\nM'_q =\n\\begin{bmatrix}\n0 & 1 \\\\ 1 & 0\n\\end{bmatrix}\n\\quad.\n\\]\nIt turns out that the eigenvalues of $M'_q$ are $1$ and $-1$ for which associated eigenvectors are given by\n\\[\nv_\\pm =\n\\begin{bmatrix}\n1 \\\\ \\pm 1\n\\end{bmatrix}\n\\quad.\n\\]\nWe also have\n\\[\n\\det M_q = 2\n\\ ,\\quad\n\\det M'_q = -1\n\\quad.\n\\]\nNow, we set\n\\[\n\\begin{split}\nH\n&\\coloneqq\\left\\{\n(x,y)\\in\\mathbb R^2\n\\;\\middle|\\;\n\\left\\langle v_+,M'_q\\begin{bmatrix} x \\\\ y \\end{bmatrix} + \\begin{bmatrix} -1 \\\\ -1 \\end{bmatrix}\\right\\rangle\n\\right\\}\n\\\\\n&= \\left\\{\n(x,y)\\in\\mathbb R^2\n\\;\\middle|\\;\nx+y-2 = 0\n\\right\\}\n\\end{split}\n\\quad,\n\\]\nthen $H$ does not intersect to the zero-set $\\{(x,y)\\mid q(x,y,1)=0\\}$, which is a hyperbolic curve.\n\\end{example}\n\nNote that the equation $q(\\vec y,1)=0$ is invariant under reflections along the eigenvectors of $M'_q$.\nIn particular, if $H$ is of codimension $1$, then it separates the two connected components of the zero-set.\n\n\\subsection{Intersections with segments}\n\nWe next discuss the intersections of quadratic curves with line segments.\nRecall that, for two points $v,w\\in\\mathbb R^{n-1}$ in the Euclidean space, the line segment connecting them is given as the function $\\gamma_{vw}:[0,1]\\to\\mathbb R^{n-1}$ with\n\\[\n\\gamma_{vw}(t)\\coloneqq (1-t)v + tw\n\\quad.\n\\]\n\n\\begin{lemma}\nLet $q$ be a quadratic form on $\\mathbb R^n$ and $v,w\\in\\mathbb R^{n-1}$.\nThen, the line segment $\\gamma_{vw}$ intersects with the set\n\\[\nQ\\coloneqq \\left\\{(y_1,\\dots,y_{n-1})\\mid q(y_1,\\dots,y_{n-1},1)=0\\right\\}\n\\]\nat a parameter $t\\in[0,1]$ if and only if $t$ is the solution of the following equation:\n\\[\n\\left((w-v)^{\\mathsf T}M'_q(w-v)\\right)t^2\n+ 2\\left((w-v)^{\\mathsf T}(M'_q v + v_q)\\right)t\n+ \\widehat v^{\\mathsf T}M_q \\widehat v\n= 0\n\\quad,\n\\]\nwhere $M_q$, $M'_q$, and $v_q$ are defined as in the previous section.\n\\end{lemma}\n\\begin{proof}\nWe put $f_q(y_1,\\dots,y_{n-1})\\coloneqq q(y_1,\\dots,y_{n-1},1)$, then we have to solve the equation $f_q(\\gamma_{vw}(t))=0$.\nSince $f_q$ is a polynomial of degree at most $2$, computing the Taylor series of the composition $f_q\\gamma_{vw}$, we obtain\n\\[\n\\begin{split}\n&[f_q\\circ\\gamma_{vw}](t) \\\\\n&= f_q(v+t(w-v)) \\\\\n&= f_q(v)\n+ t\\cdot\\left(\\left.\\frac{d}{dt}\\right|_{t=0} f_q(v+t(w-v))\\right)\n+ \\frac{t^2}{2}\\left(\\left.\\frac{d^2}{dt^2}\\right|_{t=0} f_q(v+t(w-v))\\right)\n\\quad.\n\\end{split}\n\\]\nOn the other hand, we have\n\\[\n(\\gamma_{vw})_\\ast\\left(\\frac{d}{dt}\\right)\n= \\sum_{i=1}^{n-1} (v_i-w_i)\\frac\\partial{\\partial y_i}\n\\quad.\n\\]\nThus, combining with the equation \\eqref{eq:prf:fq-diff}, one obtains the result.\n\\end{proof}\n\n\n\\section{Rendering ridgelines of quadratic B\\'ezier triangles}\n\n\\subsection{Problem}\n\nSuppose we are given a quadratic B\\'ezier triangle $u:\\Delta^2\\to\\mathbb R^3$ in the $3$-dimensional Euclidean space.\nThe main problem in the section is the following.\n\n\\begin{problem}\nFor a given surjective $\\mathbb R$-linear map $P:\\mathbb R^3\\to\\mathbb R^2$, render the boundary of the image $Pu(\\Delta^2)\\subset\\mathbb R^2$.\n\\end{problem}\n\nNote that, since the composition $Pu$ is again a B\\'ezier triangle, it is easy to render the images of the image$Pu(\\partial\\Delta^2)$.\nOn the other hand, the boundary $Pu(\\Delta^2)$ may contain points coming from the interior of $\\Delta^2$.\nIn fact, they are critical values of the map $Pu$; they form a closed subset of $\\mathbb R^2$ whose connected components we call the \\emph{ridgelines} of the B\\'ezier triangle $Pu$.\nThis observation shows that the boundary of $Pu(\\Delta^2)$ is contained in the union of following materials:\n\\begin{itemize}\n  \\item the B\\'ezier curves $\\left.Pu\\right|_{\\partial_i\\Delta^2}$ for $i=0,1,2$;\n  \\item the ridgelines.\n\\end{itemize}\nSince the former is obvious, we discuss the second in the following subsections.\n\n\\subsection{Ridgelines and quadratic curves}\n\nAs a result of \\cref{sec:Beztri:sing}, the critical locus of a B\\'ezier triangle in $\\mathbb R^2$ is defined by a quadratic function.\nHence, since ridgelines are images of critical loci, the problem is now reduced to the following more general one.\n\n\\begin{problem}\nLet $f:\\mathbb R^2\\to\\mathbb R$ be a quadratic function.\nGiven triangle $T\\subset\\mathbb R^2$, render the subset\n\\[\nT\\cap\\{(x,y)\\mid f(x,y)=0\\}\\subset T\n\\quad.\n\\]\n\\end{problem}\n\nIn other words, we want to render the intersection of a triangle with a quadratic curve.\nWe concentrate on the case where $0\\in\\mathbb R$ is a regular value of the quadratic function $f$.\nWe write $C\\coloneqq \\{f=0\\}$, which is a $1$-dimensional submanifold of $\\mathbb R$.\nWe render $T\\cap C$ in the following steps.\n\\begin{enumerate}[label=\\underline{\\textit{Step~\\arabic*}}:\\:,leftmargin=\\widthof{\\itshape Step00:}]\n  \\item Compute the subset $S\\subset \\partial T\\cap C$ of points $c\\in\\partial T\\cap C$ such that\n\\begin{itemize}\n  \\item $C$ intersects to an edge of $T$ at $c$ transversely;\n  \\item in case where $c$ is a vertex of $T$, the tangent line of $C$ at $c$ either contains an edge of $T$ or separates the other two vertices.\n\\end{itemize}\n  \\item Divide $S$ into pairs $\\{c_1,c_2\\}$ so that $c_1$ and $c_2$ belong to the same connected component of $T\\cap C$.\n  \\item For each pair $\\{c_1,c_2\\}$, render the curves connecting $c_1$ and $c_2$.\n\\end{enumerate}\n\nThe first and the last steps are obvious.\nTo achieve the second, we can make use of the following results.\n\n\\begin{lemma}\n\\label{lem:S-bndry}\nThere is a $1$-dimensional submanifold $C'\\subset T$ such that $S= \\partial C'$.\nConsequently, the number of elements in the subset $S\\subset\\partial T\\cap C$ is even and at most six.\n\\end{lemma}\n\\begin{proof}\nIt is seen that the intersection $T\\cap C$ consists of a submanifold $C'\\subset T$ together with isolated points.\nWe claim that $\\partial C'=S$.\nIt is obvious that $S\\subset\\partial C'$.\nConversely, let $c\\in \\partial C'$; we hence have $c\\in\\partial T$ since $C$ has no boundary.\nIf $c$ is a vertex of $T$, then it is clear that $c\\in S$.\nOn the other hand, suppose $c$ lies in the interior of an edge, say $e$, of $T$; hence $c$ belongs to the intersection of $C\\cap \\operatorname{int}e$.\nThis implies that $c$ is specified by a quadratic equation so that $e$ is tangent to $C$ at $c$ if and only if the equation has a double root.\nIt follows that the intersection is transverse as soon as $c\\in\\partial C'$.\nThus, we also obtain $\\partial C'\\subset S$, so $\\partial C'=S$.\nIn particular, $S$ consists of even number of elements.\nMoreover, the above observation also shows that that each edge of $T$ has at most two intersections with $C$, so $\\partial T\\cap C$ and hence $S$ consist of at most six elements.\n\\end{proof}\n\n\\begin{lemma}\n\\label{lem:comp-curve}\nFor every pair $c_1,c_2\\in S$, either of the following holds:\n\\begin{enumerate}[label=\\upshape(\\roman*)]\n  \\item if $v=c_2-c_1\\in\\mathbb R^2$, then $\\langle\\kappa(c_1),v\\rangle > 0$, here $\\kappa(c_1)$ is the curvature vector of $C$ at $c_1$;\n  \\item the curve $C$ is a hyperbola, and $c_1$ and $c_2$ lie in the different components.\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{corollary}\nIf $c_1,c_2\\in S$ lie in the same component of $T\\cap C$, then they are consequtive in $\\partial T\\cong S^1$.\n\\end{corollary}\n\\begin{proof}\nThis follows from \\cref{lem:S-bndry}, \\cref{lem:comp-curve}, and the observation that $C'$ has no self-intersection.\n\\end{proof}\n\nNow, fix a numbering on the vertices of $T$ to write $\\{p_0,p_1,p_2\\}$.\nWe say an element $c\\in S$ is \\emph{positive} (resp. \\emph{negative}) if it belongs to an edge spanned by $p_i$ and $p_{i+1}$ and transverse to $C$ at $c$ such that\n\\[\n\\langle\\kappa(c),p_{i+1}-p_i\\rangle > 0\n\\quad\\text{(resp. } \\langle\\kappa(c),p_{i+1}-p_i\\rangle < 0\\text{ )}\n\\quad,\n\\]\nhere we use the cyclic indexing modulo $3$.\nNote that, even if $c=p_k$, the definition does not depend on the choice of the edge.\nIndeed, thanks to the definition of $S$, we have\n\\[\n\\langle\\kappa(c),p_k-p_{k-1}\\rangle\\cdot\\langle\\kappa(c),p_{k+1}-p_k\\rangle\\ge 0\n\\quad.\n\\]\nOn the other hand, we consider the cyclic ordering on $\\partial T$ with $p_{i-1}<p_i<p_{i+1}$ and restrict it to $S$.\nFor $c_1,c_2\\in S$, we write $c_1\\lessdot c_2$ if $c_2$ is the ``next'' element of $c_1$ in this cyclic order.\n\n\\begin{lemma}\nFor two elements $c_1,c_2\\in S$, the following statements are all equivalent:\n\\begin{enumerate}[label=\\upshape(\\alph*)]\n  \\item $c_1$ and $c_2$ belong to the same connected component of $T\\cap C$;\n  \\item either $c_1\\lessdot c_2$ with $c_1$ negative or $c_2\\lessdot c_1$ with $c_2$ negative;\n  \\item either $c_1\\lessdot c_2$ with $c_2$ positive or $c_2\\lessdot c_1$ with $c_1$ positive;\n\\end{enumerate}\n\\end{lemma}\n\n\n\\section{Intersections of B\\'ezier curves}\n\nIn this section, we explain the \\emph{B\\'ezier clipping algorithm} developed in \\cite{NishitaTakitaNakamae1992} to find intersection of B\\'ezier curves.\n\n\\subsection{Generalized binomial coefficients}\n\nWe first extend the binomial coefficients.\n\n\\begin{definition}\nLet $R$ be an integral domain of charateristic $0$.\nFor an element $\\alpha\\in R$ and an arbitrary integer $n\\in\\mathbb Z$, we set\n\\[\n\\binom{\\alpha}{n}\n\\coloneqq\n\\begin{cases}\n\\displaystyle\\frac{\\alpha(\\alpha-1)\\dots(\\alpha-n+1)}{n!} & n> 0\\quad, \\\\\n1 & n = 0\\quad, \\\\\n0 & n < 0 \\quad,\n\\end{cases}\n\\]\nas long as it exists in $R$.\n\\end{definition}\n\n\\begin{remark}\nThe binomial coefficients may not exist.\nFor example, we have\n\\[\n\\binom{\\sqrt{-1}}{2}\n= \\frac{\\sqrt{-1}(\\sqrt{-1}-1)}2\n= \\frac{-1-\\sqrt{-1}}2\n\\quad,\n\\]\nwhich does not belong to the ring $\\mathbb Z[\\sqrt{-1}]$.\n\\end{remark}\n\n\\begin{lemma}\n\\label{lem:binom-recurrence}\nLet $R$ be an integral domain of characterstic $0$.\nThen, for each $\\alpha\\in R$ and $n\\in\\mathbb Z$, we have\n\\begin{equation}\n\\label{eq:binom-recur}\n\\binom{\\alpha}{n} = \\binom{\\alpha-1}{n} + \\binom{\\alpha-1}{n-1}\n\\end{equation}\nwhenever each term makes sense.\n\\end{lemma}\n\\begin{proof}\nIf $n\\le 1$, the equation \\eqref{eq:binom-recur} is obvious.\nIn case $n\\ge 2$, unwinding the definition, we have the following equalities in the field of fractions $F$ of $R$:\n\\[\n\\begin{split}\n\\text{RHS}\n&= \\frac{(\\alpha-1)\\dots(\\alpha-k)}{k!} + \\frac{(\\alpha-1)\\dots(\\alpha-k+1)}{(k-1)!} \\\\\n&= \\frac{(\\alpha-1)\\dots(\\alpha-k+1)}{(k-1)!}\\left(\\frac{\\alpha-k}{k}+1\\right) \\\\\n&= \\frac{(\\alpha-1)\\dots(\\alpha-k+1)}{(k-1)!}\\cdot\\frac{\\alpha}{k} \\\\\n&= \\binom{\\alpha}{k}\n\\quad.\n\\end{split}\n\\]\nSince $R$ is an integral domain, the map $R\\to F$ is injective; hence the result follows.\n\\end{proof}\n\n\\begin{lemma}\n\\label{lem:binom-altsum}\nLet $R$ be an above, and let $\\alpha\\in R$ and $n\\in\\mathbb Z$\nThen, for every non-negative integer $k$, we have\n\\begin{equation}\n\\label{eq:binom-altsum}\n\\binom{\\alpha}{n}\n= \\sum_{i=0}^k (-1)^{k-i}\\binom{k}{i}\\binom{\\alpha+i}{n+k}\n\\quad.\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\nWe prove the result by induction on the non-negative integer $k$.\nIn the base case where $k=0$, there is nothing to prove.\nOn the other hand, if $k\\ge 1$, the induction hypothesis implies that\n\\[\n\\begin{split}\n\\binom{\\alpha}{n}\n&= \\sum_{i=0}^{k-1}(-1)^{k-1-i}\\binom{k-1}{i}\\binom{\\alpha+i}{n+k-1} \\\\\n&= \\sum_{i=0}^{k-1}(-1)^{k-1-i}\\binom{k-1}{i}\\left(\\binom{\\alpha+i+1}{n+k}-\\binom{\\alpha+i}{n+k}\\right) \\\\\n&= \\sum_{i=1}^k(-1)^{k-i}\\binom{k-1}{i-1}\\binom{\\alpha+i}{n+k} - \\sum_{i=0}^{k-1}(-1)^{k-1-i}\\binom{k-1}{i}\\binom{\\alpha+i}{n+k} \\\\\n&= \\sum_{i=0}^k (-1)^{k-i}\\left(\\binom{k-1}{i-1}+\\binom{k-1}{i}\\right)\\binom{\\alpha+i}{n+k} \\\\\n&= \\sum_{i=0}^k (-1)^{k-i}\\binom{k}{i}\\binom{\\alpha+i}{n+k}\n\\quad.\n\\end{split}\n\\]\n\\end{proof}\n\n\\subsection{Clipping B\\'ezier curves}\n\nWe discuss clipping a piece of a B\\'ezier curve.\nMore precisely, suppose $\\gamma:[0,1]\\to\\mathbb R^n$ is a B\\'ezier curve with control points $\\beta_0,\\dots,\\beta_d$; i.e.\n\\[\n\\gamma(t)\n= \\sum_{i=0}^n \\beta_i\\binom{n}{i}t^i(1-t)^{n-i}\n\\quad.\n\\]\nFor a subinterval $I=[a,b]\\subset[0,1]$, we want a B\\'ezier curve $\\gamma_I$ satisfying the following equation:\n\\[\n\\gamma_I(t) = \\gamma(a+(b-a)t)\n\\quad;\n\\]\nin other words, $\\gamma_I$ is obtained by normalizing the parameter of the composition\n\\[\nI\\hookrightarrow[0,1]\\xrightarrow{\\gamma}\\mathbb R^n\n\\quad.\n\\]\n\n\\begin{proposition}[De Casteljau's algorithm]\n\\label{prop:de-casteljau}\nLet $\\gamma$ be a B\\'ezier curve with control points $\\beta_0,\\dots,\\beta_d$.\nFor each $0\\le a\\le 1$, the restrictions $\\left.\\gamma\\right|_{[0,a]}$ and $\\left.\\gamma\\right|_{[a,1]}$ are again B\\'ezier curves of the same degree after appropriate normalizations of parameters.\nFurthermore, the following hold:\n\\begin{itemize}\n  \\item on the left half $[0,a]$, $\\left.\\gamma\\right|_{[0,a]}$ has control points $\\beta^L_0,\\dots,\\beta^L_d$ with\n\\[\n\\beta^L_j = \\sum_{i=0}^j\\beta_i\\binom{j}{i}a^i(1-a)^{j-i}\n\\quad;\n\\]\n  \\item on the right half $[a,0]$, $\\left.\\gamma\\right|_{[a,1]}$ has control points $\\beta^R_0,\\dots,\\beta^R_d$ with\n\\[\n\\beta^R_j = \\sum_{i=j}^d\\beta_i\\binom{d-j}{i-j}a^{i-j}(1-a)^{d-i}\n\\quad.\n\\]\n\\end{itemize}\n\\end{proposition}\n\nIn view of De Casteljau's algorithm, it is convenient to represent a B\\'ezier curve as a $n\\times (d+1)$-matrix\n\\[\n\\begin{bmatrix}\\beta_0 & \\cdots & \\beta_d\\end{bmatrix}\n\\]\nby arranging the control points as column vectors.\nThen, the ``left-half'' in \\cref{prop:de-casteljau} is obtained by the matrix multiplication\n\\[\n\\begin{bmatrix}\\beta^L_0 & \\cdots & \\beta^L_d\\end{bmatrix}\n= \\begin{bmatrix}\\beta_0 & \\cdots & \\beta_d\\end{bmatrix}\n\\begin{bmatrix}\n1 & \\cdots & b^j & \\cdots & b^d \\\\\n& \\ddots & \\vdots && \\vdots\\\\\n&& \\binom{j}{i}a^ib^{j-i} & \\cdots & \\binom{d}{i}a^ib^{d-i} \\\\\n&&& \\ddots & \\vdots \\\\\n&&&& a^d\n\\end{bmatrix}\n\\quad,\n\\]\nwhere $a+b=1$, while the ``right-half'' is\n\\[\n\\begin{bmatrix}\\beta^R_0 & \\cdots & \\beta^R_d\\end{bmatrix}\n= \\begin{bmatrix}\\beta_0 & \\cdots & \\beta_d\\end{bmatrix}\n\\begin{bmatrix}\nb^d &&&& \\\\\n\\vdots & \\ddots &&& \\\\\n\\binom{d}{i}a^ib^{d-i} & \\cdots & \\binom{d-j}{i-j}a^{i-j}b^{d-i} && \\\\\n\\vdots && \\vdots & \\ddots & \\\\\na^d & \\cdots & a^{d-j} & \\cdots & 1\n\\end{bmatrix}\n\\quad.\n\\]\nTo simplify the notation, we denote them by $S^L(a,b)$ and $S^R(a,b)$ respectively.\nSpecifically,\n\\[\n\\begin{split}\nS^L(a,b)_{ij} &=\n\\begin{cases}\n\\displaystyle\\binom{j}{i}a^ib^{j-i} & j\\ge i\\\\\n\\ 0 & j < i\n\\end{cases}\n\\quad,\n\\\\\nS^R(a,b)_{ij} &=\n\\begin{cases}\n\\displaystyle\\binom{d-j}{i-j}a^{i-j}b^{d-i} & j \\le i\\\\\n\\ 0 & j > i\n\\end{cases}\n\\quad.\n\\end{split}\n\\]\nFinally, for a subinterval $I=[a_0,a_1]\\subset[0,1]$, we can realize the clipped B\\'ezier curve $\\gamma_I$ by the control points\n\\[\n\\begin{bmatrix}\n\\beta^I_0,\\dots,\\beta^I_d\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\\beta_0,\\dots,\\beta_d\n\\end{bmatrix}\nS^L(a_1,b_1)S^R\\bigl(\\frac{a_0}{a_1},b_0-\\frac{a_0b_1}{a_1}\\bigr)\n\\]\nwith $a_i+b_i=0$ for $i=0,1$.\nNote that we have\n\\[\n\\begin{split}\n&\\left(S^L(a_1,b_1)S^R\\bigl(\\frac{a_0}{a_1},b_0-\\frac{a_0b_1}{a_1}\\bigr)\\right)_{ij}\n= \\sum_{k=0}^d S^L(a_1,b_1)_{ik}S^R\\bigl(\\frac{a_0}{a_1},b_0-\\frac{a_0b_1}{a_1}\\bigr)_{kj} \\\\\n&= \\sum_{k=\\max\\{i,j\\}}^d\\binom{k}{i}a_1^ib_1^{k-i}\\cdot\\binom{d-j}{k-j}\\left(\\frac{a_0}{a_1}\\right)^{k-j}\\left(b_0-\\frac{a_0b_1}{a_1}\\right)^{d-k} \\\\\n&= a_1^{i+j-d}\\sum_{k=\\max\\{i,j\\}}^d\\binom{k}{i}\\binom{d-j}{k-j}a_0^{k-j}b_1^{k-i}(a_1b_0-a_0b_1)^{d-k} \\\\\n&= a_1^{i+j-d}\\sum_{k=\\max\\{i,j\\}}^d\\binom{k}{i}\\binom{d-j}{k-j}a_0^{k-j}b_1^{k-i}\\sum_{l=0}^{d-k}\\binom{d-k}{l}(a_1b_0)^l(-a_0b_1)^{d-k-l} \\\\\n&= a_1^{i+j-d}\\sum_{k=\\max\\{i,j\\}}^d\\sum_{l=0}^{d-k} (-1)^{d-k-l}\\binom{k}{i}\\binom{d-j}{k-j}\\binom{d-k}{l}a_0^{d-j-l}a_1^lb_0^lb_1^{d-i-l}\n\\quad.\n\\end{split}\n\\]\nUsing the equality $\\binom{N}{n}\\binom{N-n}{m} = \\binom{N}{m}\\binom{N-m}{n}$, we further have\n\\[\n\\begin{split}\n&\\mathrm{RHS} \\\\\n&= a_1^{i+j-d}\\sum_{l=0}^{d-\\max\\{i,j\\}}\\sum_{k=\\max\\{i,j\\}}^{d-l} (-1)^{d-k-l}\\binom{k}{i}\\binom{d-j}{l}\\binom{d-j-l}{k-j}a_0^{d-j-l}a_1^lb_0^lb_1^{d-i-l}\n\\quad.\n\\end{split}\n\\]\nTherefore, putting\n\\begin{equation}\n\\label{eq:def-Cijn}\n\\begin{split}\nC_{i,j,n}\n&\\coloneqq \\sum_{k=\\max\\{i,j\\}}^n (-1)^{n-k}\\binom{k}{i}\\binom{n-j}{k-j} \\\\\n&=\n\\sum_{k'=\\max\\{i-j,0\\}}^{n-j}(-1)^{n-j-k'}\\binom{j+k'}{i}\\binom{n-j}{k'}\n\\quad,\n\\end{split}\n\\end{equation}\nthen we obtain the following equation:\n\\begin{equation}\n\\label{eq:clip-coeff}\n\\left(S^L(a_1,b_1)S^R\\bigl(\\frac{a_0}{a_1},b_0-\\frac{a_0b_1}{a_1}\\bigr)\\right)_{ij}\n= a_1^{i+j-d}\\sum_{l=0}^{d-\\max\\{i,j\\}}\\binom{d-j}{l}C_{i,j,d-l}a_0^{d-j-l}a_1^lb_0^lb_1^{d-i-l}\n\\end{equation}\n\n\\begin{lemma}\n\\label{lem:formula-Cijn}\nFor every non-negative integers $i,j$ and for every integer $n$, we have\n\\begin{equation}\n\\label{eq:formula-Cijn}\nC_{i,j,n} = \\binom{j}{i+j-n} = \\binom{j}{n-i}\n\\quad.\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\nNotice that, for each $0\\le k'\\le \\max\\{i-j,0\\}-1$, we have\n\\[\n\\binom{j+k'}{i}=0\n\\]\nsince $j+k'$ is a non-negative integer less than $i$.\nHence, by \\eqref{eq:def-Cijn}, we actually have\n\\[\nC_{i,j,n}\n= \\sum_{k'=0}^{n-j}(-1)^{n-j-k'}\\binom{j+k'}{i}\\binom{n-j}{k'}\n\\]\nno matter which of $i$ and $j$ is larger.\nThe result then follows directly from \\cref{lem:binom-altsum}.\n\\end{proof}\n\nSubstituting \\eqref{eq:formula-Cijn} into \\eqref{eq:clip-coeff}, we finally get\n\\[\n\\begin{split}\n&\\left(S^L(a_1,b_1)S^R\\bigl(\\frac{a_0}{a_1},b_0-\\frac{a_0b_1}{a_1}\\bigr)\\right)_{ij} \\\\\n&= a_1^{i+j-d}\\sum_{l=0}^{d-\\max\\{i,j\\}}\\binom{d-j}{l}\\binom{j}{d-l-i}a_0^{d-j-l}a_1^lb_0^lb_1^{d-i-l} \\\\\n&= a_1^{i+j-d}\\sum_{l=d-i-j}^{d-\\max\\{i,j\\}}\\binom{d-j}{l}\\binom{j}{d-l-i}a_0^{d-j-l}a_1^lb_0^lb_1^{d-i-l} \\\\\n&= a_1^{i+j-d}\\sum_{l'=0}^{\\min\\{i,j\\}}\\binom{d-j}{d-i-j+l'}\\binom{j}{j-l'}a_0^{i-l'}a_1^{d-i-j+l'}b_0^{d-i-j+l'}b_1^{j-l'} \\\\\n&= \\sum_{l'=0}^{\\min\\{i,j\\}}\\binom{d-j}{i-l'}\\binom{j}{j-l'}a_0^{i-l'}a_1^{l'}b_0^{d-i-j+l'}b_1^{j-l'}\n\\end{split}\n\\]\n\n\\begin{thebibliography}{99}\n  \\bibitem{NishitaTakitaNakamae1992} T.~Nishita, S.~Takita, and E.~Nakamae, ``Hidden Curve Elimination of Trimmed Surfaces Using Bezier Clipping,'' CG International'92, 1992-6, pp.595--619.\n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "ee41dcb9cb758a5dada96eb55b5ca2f5ed964db4", "size": 41719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/technical_material.tex", "max_stars_repo_name": "Junology/bord2", "max_stars_repo_head_hexsha": "0068885144032d4a8e30c6f2c5898918d00b1d8f", "max_stars_repo_licenses": ["MIT"], "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/technical_material.tex", "max_issues_repo_name": "Junology/bord2", "max_issues_repo_head_hexsha": "0068885144032d4a8e30c6f2c5898918d00b1d8f", "max_issues_repo_licenses": ["MIT"], "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/technical_material.tex", "max_forks_repo_name": "Junology/bord2", "max_forks_repo_head_hexsha": "0068885144032d4a8e30c6f2c5898918d00b1d8f", "max_forks_repo_licenses": ["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.4500412882, "max_line_length": 262, "alphanum_fraction": 0.6607540929, "num_tokens": 16541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6892852672750021}}
{"text": "\\documentclass{article}\n\n\\usepackage{cite}\n\\usepackage{amsmath,amssymb,amsfonts}\n\\usepackage{algorithm}\n\\usepackage{booktabs}\n\\usepackage{algorithmic}\n\\usepackage{graphicx}\n\\usepackage[font=small]{caption}\n%\\usepackage{subcaption}\n%\\expandafter\\def\\csname ver@subfig.sty\\endcsname{}\n\\usepackage{tabularx}\n\\usepackage{subfig}\n\\usepackage{pgffor}\n\\usepackage{hyperref}\n\\usepackage{soul}\n\n% for tables\n\\newcommand{\\centertab}[1]{\\multicolumn{1}{|c|}{\\textbf{#1} }}\n\\newcommand{\\bigcell}[2]{\\begin{tabular}{@{}#1@{}}#2\\end{tabular}}\n\n\\begin{document}\n\\input{math_definitions}\n\n\n\\section{Basic Linear Algebra}\n\\begin{itemize}\n  \\item $ \\vA^{-T} \\triangleq \\group{\\vA^T}^{-1} = \\group{\\vA^{-1}}^{T} $\n  \\item $ (\\vA \\vB)^{T} = \\vB^{T} \\vA^{T} $\n  \\item $ (\\vA \\vB)^{-1} = \\vB^{-1} \\vA^{-1} $,\n    iff $ \\vA$ and $\\vB$ are invertible\n  \\item Frobenius norm $ \\fnorm{\\vA} = \\sqrt{\\Tr{\\vA \\vA^T}}$\n  \\item \\textbf{trace:}\n  \\begin{itemize}\n    \\let\\labelitemii\\labelitemi\n    \\item $ \\Tr{\\vA^{T}} = \\Tr{\\vA} $\n    \\item $ \\Tr{\\vA + \\vB} = \\Tr{\\vA} + \\Tr{\\vB} $\n    \\item $ \\Tr{\\vA \\vB^{T}} = \\Tr{\\vA^{T} \\vB} =\n      \\sum_{i,j}{\\group{\\vA \\circ \\vB}_{(i,j)}} $\n    \\item $ \\Tr{\\vA \\vB \\vC} = \\Tr{\\vC \\vA \\vB} = \\Tr{\\vB \\vC \\vA} $\n  \\end{itemize}\n  \\item \\textbf{determinant:}\n  \\begin{itemize}\n    \\item $ \\det{\\vA^T} = \\det{\\vA} $\n    \\item $ \\det{\\vA^{-1}} = \\group{\\det{\\vA}}^{-1} $\n    \\item $ \\func{\\det}{\\vA \\vB} = \\func{\\det}{\\vA} \\func{\\det}{\\vB} $,\n      for square matrices of equal size.\n    \\item If $\\vA$ is a triangular matrix (lower triangular or upper triangular),\n    $$ \\det{\\vA} = \\prod_i{A_{(i,i)}}$$\n  \\end{itemize}\n\\end{itemize}\n\n\\section{Cholesky decomposition}\nThe Cholesky decomposition of a positive-definite matrix A is a decomposition\n  of the form:\n$$ \\vSigma = \\vL \\vL^{T} $$\nwhere $\\vL$ is a lower triangular matrix\n\\begin{itemize}\n  \\item $\\vSigma^{-1} = \\group{\\vL \\vL^{T}}^{-1} = \\vL^{-T} \\vL^{-1}$\n  \\item $\\vL \\solve \\vx \\triangleq \\vL^{-1} \\vx$\n  \\item $\\vSigma^{-1} \\vx = \\vL^{T} \\solve \\vL \\solve \\vx$\n  \\item $\\vx^T \\vSigma^{-1} \\vx = \\ltwogroup{ \\vL \\solve \\vx}^2 $\n  \\item $\\Tr{\\vSigma_b^{-1} \\vSigma_a} = \\fnorm{\\vL_b \\solve \\vL_a}^2 $\\\\\n    Proof:\n    \\begin{align*}\n      \\Tr{\\vSigma_b^{-1} \\vSigma_a}\n        & = \\Tr{\\group{\\vL_b \\vL_b^T}^{-1} \\vL_a \\vL_a^T} \\\\\n        & = \\Tr{\\vL_b^{-T} \\vL_b^{-1} \\vL_a \\vL_a^T}\n          = \\Tr{ \\vL_a^T \\vL_b^{-T} \\vL_b^{-1} \\vL_a } \\\\\n        & = \\Tr{ \\group{\\vL_b^{-1} \\vL_a}^T  \\group{\\vL_b^{-1} \\vL_a} }\n          = \\fnorm{\\vL_b \\solve \\vL_a}^2\n    \\end{align*}\n  \\item $\\func{\\log}{\\abs{\\vSigma}}\n    = 2 \\sum_i \\func{\\log}{L_{(i,i)}}\n    = 2 \\Tr{ \\func{\\log}{\\vL} }$\n\\end{itemize}\n\n\\section{Inverse}\n  \\begin{flalign}\n    & \\group{\\eye + \\vP}^{-1} = \\eye - \\group{\\eye + \\vP}^{-1} \\vP &\n    \\label{eq:inv_identity_1} \\\\\n    & \\group{\\eye + \\vP \\vQ}^{-1} \\vP = \\vP \\group{\\eye + \\vQ \\vP}^{-1} &\n    \\label{eq:inv_identity_2}\n  \\end{flalign}\n\n\\subsection{Matrix inversion lemma (Sherman-Morrison-Woodbury)}\n\\begin{itemize}\n  \\item\n    \\begin{flalign}\n      & \\group{\\vA + \\vB \\vC \\vD}^{-1} =\n      \\vA^{-1} - \\vA^{-1} \\vB \\group{\\vC^{-1} + \\vD \\vA^{-1} \\vB}^{-1} \\vD \\vA^{-1} &\n      \\label{eq:inv_identity_3}\n    \\end{flalign}\n  \\item $ \\group{\\vA + \\vB \\vC \\vD}^{-1} =\n    \\vA^{-1} - \\vA^{-1} \\vB \\group{\\eye + \\vC \\vD \\vA^{-1} \\vB}^{-1} \\vC \\vD \\vA^{-1}\n    $\n  \\item $ \\group{\\vA + \\vX \\vB \\vX^T}^{-1} =\n    \\vA^{-1} - \\vA^{-1} \\vX \\group{\\vB^{-1} + \\vX^T \\vA^{-1} \\vB}^{-1} \\vX^T \\vA^{-1}\n    $\n  \\item $ \\group{\\vA + \\vB \\vC \\vD}^{-1} \\vB \\vC =\n    \\vA^{-1} \\vB \\group{\\vC^{-1} + \\vD \\vA^{-1} \\vB}^{-1} $,\n    using \\ref{eq:inv_identity_3} and \\ref{eq:inv_identity_1} \\ref{eq:inv_identity_2}\n  \\item $ \\group{\\vA + \\vB}^{-1} = \\vA^{-1} \\group{\\vA^{-1} + \\vB^{-1}}^{-1} \\vB^{-1} $\n  \\item $ \\group{\\vA^{-1} + \\vB^{-1}}^{-1} = \\vA \\group{\\vA^{-1} + \\vB^{-1}} \\vB $\n\n  where $\\vA$ and $\\vB$ are square and invertible matrices.\n\\end{itemize}\n\n\\section{square}\n\\begin{align}\n  \\vx^T \\vM \\vx - 2 \\vb^T \\vx =\n    \\group{\\vx - \\vM^{-1} \\vb}^T \\vM \\group{\\vx - \\vM^{-1} \\vb}\n    - \\vb^T \\vM^{-1} \\vb\n\\end{align}\n\n\n\\appendix\n\\section{Notation}\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{| c | c |}\n \\hline\n \\bigcell{c}{\\textbf{Notation}}  & \\textbf{Description} \\\\\n \\hline \\rule{0pt}{3ex}\n $\\tX \\in \\reals^{I_1 \\times I_2 \\times \\cdots \\times I_N}$ & Tensor of order $N$  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $x, \\vx, \\vX$ & \\bigcell{c}{Scalar, vector and matrix. \\\\ Non-bold letters do not strictly represent scalars, \\\\in many cases their meaning should be extracted \\\\from context}  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $x_{i_1,i_2, ..., i_N}, \\; \\tX_{(i_1,i_2, ..., i_N)} $ & $(i_1, i_2, ..., i_N)$th entry of $\\tX$  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\vx_{:,i}, \\; \\vX_{(:,i)} $ & \\bigcell{c}{$i$th column of the matrix $\\vX$. \\\\Colons are used for indexing an entire dimension.} \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\vx_{:,i_2, ..., i_N}, \\; \\tX_{(:,i_2, ..., i_N)} $ & Mode-1 fiver of $\\tX$  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\vX_{:,:, ..., i_N}, \\; \\tX_{(:, :, ..., i_N)} $ & Frontal slice of $\\tX$  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\tX_{(+, :, \\ldots, :)} $ & Partial sum-reduction over first dimension \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\tX_{(+)}$ & Sum-reduction over all elements in the tensor \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\ones$ & \\bigcell{c}{Tensor whose elements are equal to one. \\\\ Their order and size is usually extracted from context}  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\tA \\odot \\tB$ & \\bigcell{c}{Element-wise product between tensors $\\tA$ and $\\tB$}  \\\\[0.3cm]\n \\hline \\rule{0pt}{3ex}\n $\\tC_{(i,j)} = \\tA_{(i,k)} \\tB_{(k,j)}$ & \\bigcell{c}{ Tensor contraction using Einstein notation. \\\\ In this case is just the matrix multiplication \\\\ between $\\tA$ and $\\tB$}  \\\\[0.3cm]\n \\hline\n\n\\end{tabular}\n\\caption{ Notation for vectors, matrices and tensors }\\label{table:tensor_notation}\n\\end{table}\n\n\\end{document}\n", "meta": {"hexsha": "ad25fc269400968cb1f41f7d41f6654c43c7cc76", "size": 5918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/linear_algebra.tex", "max_stars_repo_name": "danmar3/twodlearn", "max_stars_repo_head_hexsha": "02b23bf07618d5288e338bd8f312cc38aa58c195", "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/linear_algebra.tex", "max_issues_repo_name": "danmar3/twodlearn", "max_issues_repo_head_hexsha": "02b23bf07618d5288e338bd8f312cc38aa58c195", "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/linear_algebra.tex", "max_forks_repo_name": "danmar3/twodlearn", "max_forks_repo_head_hexsha": "02b23bf07618d5288e338bd8f312cc38aa58c195", "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.6797385621, "max_line_length": 188, "alphanum_fraction": 0.562521122, "num_tokens": 2589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6891477845324808}}
{"text": "\\section[The Real and Complex Number Systems]{\\hyperlink{toc}{The Real and Complex Number Systems}}\n\\subsection{The Naturals, Integers, and Rationals}\nWe begin by a review of number systems which are already familiar.\n\n\\begin{ndef}{: The Natural Numbers}\n    The \\textbf{Naturals}, denoted by $\\NN$, is the set $\\set{1, 2, 3, \\ldots}$.\n\\end{ndef}\n\n\\noindent For $x, y \\in \\NN$, we have that $x + y \\in \\NN$ and $xy \\in \\NN$, so the naturals are closed under addition and multiplication. However, we note that it is not closed under subtraction; take for example $2 - 4 = -2 \\notin \\NN$.\n\n\\begin{ndef}{: The Integers}\n    The \\textbf{Integers}, denoted by $\\ZZ$, is the set $\\set{\\ldots, -3, -2, -1, 0, 1, 2, 3, \\ldots}$.\n\\end{ndef}\n\n\\noindent The integers are closed under addition, multiplication, and subtraction. However, it is not closed under division; for example, $1/2 \\notin \\ZZ$. \n\n\\begin{ndef}{: The Rationals (informal)}\n    The \\textbf{Rationals}, denoted by $\\QQ$, can be defined as $\\set{\\frac{m}{n}: m \\in \\ZZ, n \\in \\NN}$, where $\\frac{m_1}{n_1}$ and $\\frac{m_2}{n_2}$ are identified if $m_1n_2 = m_2n_1$.\n\\end{ndef}\n\n\\noindent We note that unlike the naturals/integers, the rationals do not have as obvious of a denumeration. This above is a good definition if we already have the same rigorous idea of what a rational number is in our mind; i.e. it works because we have a shared preconceived understanding of a rational number.\n\nIf this is not the case, it may help to define the rational numbers more rigorously/formally (even if the definition may be slightly harder to parse). As a second attempt at a definition, we can say that $\\QQ$ is the set of ordered pairs $\\set{(m, n): m \\in \\ZZ, n \\in \\NN}$. However, this is not quite enough as we need a notion of equivalence between two rational numbers (e.g. $(1, 2) = (2, 4)$). Hence, a complete and rigorous definition would be:\n\n\\begin{ndef}{: The Rationals (formal)}\n    The \\textbf{Rationals}, denoted by $\\QQ$, is the set $\\set{(m, n): m \\in \\ZZ, n \\in \\NN}/\\sim$ where $(m_1, n_1) \\sim (m_2, n_2)$ if $m_1n_2 = m_2n_1$.\n\\end{ndef}\n\\noindent Under the formal definition, the rationals are a set of equivalence classes of ordered pairs, under the equivalence relation $\\sim$. We note that the rationals are closed under addition, subtraction, multiplication, and division.\n\nThis formal definition might be slightly harder to parse, so it might be useful to consider an example with a similar flavour. Consider the set $X = \\set{m \\in \\ZZ}/\\sim$ such that $m_1 \\sim m_2$ if $m_1 - m_2$ is divisible by 12. This is \"clock arithmetic\", with equivalence classes $[0], [1], [2], \\ldots$ for each hour on an analog clock. A fun side note: If instead of 12 we picked a prime number, we would get a field (we will discuss what this is in a later lecture)!\n\nNote that under this definition, $(1, 2)$ and $(2, 4)$ are different representations of the same rational number. With this definition, we would define addition such that $(m_1, n_1) + (m_2, n_2) = (m_1n_2 + m_2n_1, n_1n_2)$. Note that $(2m_1, 2n_2) + (m_2, n_2) = (2m_1n_2 + 2m_2n_1, 2n_1n_2)$ and we can identify $(m_1n_2 + m_2n_1, n_1n_2)$ with $(2m_1n_2 + 2m_2n_1, 2n_1n_2)$. If we choose different representations when we do addition, we might get a different representation in our result, but it will represent the same rational number regardless of the choice of representations we originally chose to do the addition. \n\nA natural question then becomes if the rationals are sufficient for doing all of real analysis. Certainly, it seems as we have a number system that is closed under all our basic arithmetic operations; but is this enough? For example, are we able to take limits just using the rationals? The answer turns out to be no (they are insufficient!) and the following example will serve as one illustration of this fact. \n\n\\begin{example}{Incompleteness of the Rationals}{1.1a}\n    There exists no $p \\in \\QQ$ such that $p^2 = 2$.\n\\end{example}\n\\noindent We proceed via proof by contradiction. Recall in that these types of proof, we start with a certain wrong assumption, follow a correct/true line of reasoning, reach an eventual absurdity, and therefore conclude that the original assumption was mistaken. \n\\begin{nproof}\n    Let us then suppose for the contradiction that there exists $p = \\frac{m}{n}$ with $p^2 = 2$. We then have that not both $m, n$ are even, and hence at least one is odd. Then, we have that $2 = p^2 = \\frac{m^2}{n^2}$ and hence $m^2 = 2n^2$, so $m^2$ is even, implying $m$ is even. So, let us write $m = 2k$ for $k \\in \\ZZ$. Then, $(2k)^2 = 4k^2 = 2n^2$, and hence $2k^2 = n^2$. Therefore, $n^2$ is even and hence $n$ is even. $m$ and $n$ are therefore both even, a contradiction. We conclude that no such $p$ exists. \\qed\n\\end{nproof}\n\\noindent Why can we conclude that not both $m, n$ are even in the above proof? This is the case as if $m, n$ we both even, then we could write $m = 2m'$, $n = 2n'$ for some $m', n'$, and then $p = \\frac{m}{n} = \\frac{2m'}{2n'} = \\frac{m'}{n'}$ which we can continue until either the numerator or denominator is odd. A natural question to consider is how to prove that this process of reducing fractions will eventually conclude. The resolution is to invoke the fundamental theorem of arithmetic, and write $m, n$ in terms of their unique prime factorization. We are then able to cancel out factors of 2 from the numerator/denominator until at least one is odd.\n\nWe note that this example leads us to conclude that the rationals have certain ``holes'' in them. This is concerning, as there are sequences of rational numbers that tend to $\\sqrt{2}$. Conversely, its not as concerning that there is no rational number $x$ such that $x^2 = -1$, as there is no such sequence of rational numbers that is \"close to\" $i$ (note that both $\\sqrt{2}$ and $i$ have not yet been defined, but this will come shortly).\n\n\\setcounter{rudin}{0}\n\n\\begin{example}{Incompleteness of the Rationals}{1.1b}\n    Let $A = \\set{p \\in \\QQ: p > 0, p^2 < 2}$, and $B = \\set{p \\in \\QQ: p > 0, p^2 > 2}$. Then, $\\forall p \\in A, \\exists q \\in A$ such that $p < q$, and $\\forall p \\in B, \\exists q \\in B$ such that $q < p$. \n\\end{example}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n        \\draw[latex-latex, very thick] (-6, 0) -- (6,0) node[anchor=south] {$\\QQ$};\n        \\draw[] (0, 0) -- (0, -0.25) node[anchor=north] {0};\n        \\foreach \\i in {-5.7,-5.6,...,5.7}{ \n        \\draw[] (\\i,0) -- (\\i,-0.1);\n        }\n        \\draw[] (1,0.1) node[anchor=south] {$\\sqrt{2}$};\n        \\draw[] (0.96,0) node[] {$)$};\n        \\draw[] (1.04,0) node[] {$($};\n        \\draw[] (-2.5, 0) node[anchor=south] {$A$};\n        \\draw[] (3.5, 0) node[anchor=south] {$B$};\n    \\end{tikzpicture}\n    \\caption{Visualization of sets $A$ and $B$. We note that $\\sqrt{2}$ has not been defined in our formalism yet, but from our prior mathematical intuition it would be what goes in the \"hole\" of the rationals.}\n    \\label{fig1}\n\\end{figure}\n\n\\noindent For the proof of this statement, we consider playing a 2 person game. One person is $\\forall$, one person is $\\exists$, and we consider if one person has a winning strategy. $\\forall$ goes first, and then $\\exists$ goes next, having seen the choice that $\\forall$ has made. Then, we check if indeed $p < q$. If $p < q$, then $\\exists$ wins. If $p \\not< q$, then $\\forall$ wins. \n\n\\begin{nproof}\n    Let $p \\in A$. Then, let $q = \\frac{2p + 2}{2 + p}$. Since $p \\in \\QQ$, it follows that $2p + 2 \\in \\QQ$ and $2 + p \\in \\QQ$ so $q \\in \\QQ$. Furthermore, we have that $2p + 2 > 0$ and $2 + p > 0$, so $q > 0$. We also have that:\n    \\[q^2 = \\frac{(2p+2)^2}{(2+p)^2} = 2 + \\frac{2(p^2 - 2)}{(p+2)^2} < 2\\]\n    Where the inequality follows from the fact that $p^2 < 2$ and hence $(p^2 - 2) < 0$. It therefore follows that $q \\in A$. Finally, we have that:\n    \\[q = p + \\frac{2-p^2}{2+p} > p\\]\n    so $q > p$, completing the proof of the first part of the claim. The second part is left as an exercise (we note that the same $q$ can be used). \\qed\n\\end{nproof}\n\n\\noindent The number $q = \\frac{2p+ 2}{2 + p}$ seems to be pulled out of a hat, but actually comes from a fairly geometric picture (the secant method of approximating roots). Discussion on this topic can be found here: \\url{https://math.stackexchange.com/questions/141774/choice-of-q-in-baby-rudins-example-1-1}.\n\n\\subsection{Ordered Sets}\nOver the next couple sections, we will be discussing certain properties of sets that will give us a better understanding of the real numbers, and allow us to construct them.\n\n\\setcounter{rudin}{4}\n\n\\begin{definition}{Order}{1.5}\n    An \\textbf{order} $<$ on a set $S$ is a relation with the following properties:\n    \\begin{enumerate}[(i)]\n        \\item For every pair $x, y \\in S$, exactly one of $x < y$, $x = y$, or $y < x$ is true. \n        \\item For $x, y, z \\in S$, if $x < y$ and $y < z$, then $x < z$. \n    \\end{enumerate}\n    A point on notation; We note that $x > y$ means $y < x$, and $x \\leq y$ means $x < y$ or $x = y$. \n\\end{definition}\n\n\\begin{definition}{Ordered Sets}{1.6}\n    An \\textbf{ordered set} is a pair $(S, <)$. We may write just $S$ if the order can be inferred by the context.\n\\end{definition}\n\\noindent A familiar (and useful) set of examples is $S = \\NN$ or $S = \\ZZ$ or $S = \\QQ$. For these three sets, we have that $x < y$ if $y-x$ is positive. For another example, consider the set $S$ of english words; then the order $<$ can be the dictionary/lexographic order. \n\n\\begin{definition}{Upper \\& Lower Bounds}{1.7}\n    Let $S$ be an ordered set and $E \\subset S$ (for the duration of these notes, we will follow Rudin's notation, with $E \\subset S$ as a non-strict subset, and $E \\subsetneq S$ as a strict subset). $E$ is \\textbf{bounded above} if there exists an element $\\beta \\in S$ such that $\\forall x \\in E$, $x \\leq \\beta$. Any such $\\beta$ is an \\textbf{upper bound} of $E$. Similarly, we say that $E$ is \\textbf{bounded below} if there exists an element $\\alpha \\in S$ such that $\\forall x \\in E$, $\\alpha \\leq x$. In this case, $\\alpha$ is a \\textbf{lower bound} of $E$.\n\\end{definition}\n\\noindent As an example, one can take $S = \\QQ$, $E = A = \\set{p \\in \\QQ: p > 0, p^2 > 2}$ (as in Example \\ref{exam:1.1b}(b)). Here, $E$ is bounded above, with $\\beta = 2$ as one possible upper bound. to see this is the case, consider that if $p \\in E$:\n\\[2 - p = \\frac{4 - p^2}{2+p} > \\frac{4-2}{2+p} > 0\\]\n\\noindent However, if we take $S = A$, $E = A$, then $E$ is not bounded above as we saw in the example. There is no upper bound of $A$ in $A$. In general, this example reveals the subtle point that \"the upper bound of a set\" is ill-defined; we need to specify $E \\subset S$. \n\n\\subsection{The Least Upper Bound Property}\n\\begin{definition}{Least Upper Bound \\& Greatest Lower Bound}{1.8}\n    Let $S$ be an ordered set, and let $E \\subset S$ with $E$ bounded above. If $\\exists \\alpha \\in S$ such that:\n    \\begin{enumerate}[(i)]\n        \\item $\\alpha$ is an upper bound for $E$\n        \\item If $\\gamma < \\alpha$, then $\\gamma$ is not an upper bound for $E$\n    \\end{enumerate} \n    The $\\alpha$ is the \\textbf{least upper bound}, or \\textbf{supermum} of $E$. This can be denoted as $\\alpha = \\sup(E)$. Analogously, the \\textbf{greatest lower bound}, or \\textbf{infimum} of E (denoted $\\alpha = \\inf(E)$) is an element $\\alpha \\in S$ (if it exists) such that:\n    \\begin{enumerate}[(i)]\n        \\item $\\alpha$ is a lower bound for $E$\n        \\item If $\\gamma > \\alpha$, then $\\gamma$ is not an upper bound of $E$. \n    \\end{enumerate}\n\\end{definition}\n\n\\begin{ntheorem}{}\n    If the supremum/infimum of $E \\subset S$ exist, they are unique.\n\\end{ntheorem}\n\\begin{nproof}\n        Let $E \\subset S$. Suppose that there exist $\\alpha_1, \\alpha_2$ such that $\\alpha_1 = \\sup(E)$ and $\\alpha_2 = \\sup(E)$. If $\\alpha_1 < \\alpha_2$, as $\\alpha_1$ is an upper bound of $E$, this contradicts the fact that $\\alpha_2$ is the least upper bound of $E$. We reach an identical contradiction if $\\alpha_2 < \\alpha_1$. Therefore we conclude that $\\alpha_1 = \\alpha_2$ and the supremum of $E$ is unique (if it exists). The proof for the infimum is analogous. \\qed\n\\end{nproof}\n\n\\begin{ntheorem}{}\n    If $E \\subset S$ has a maximum element $\\alpha$ (that is, an element such that $x < \\alpha$ for all $x \\in E$) then $\\alpha = \\sup(E)$. Similarly, if $E$ has a minimum element $\\alpha$, then $\\alpha = \\inf(E)$.\n\\end{ntheorem}\n\n\\begin{nproof}\n    Let $E \\subset S$ and $\\alpha = \\max(E)$. By definition $\\alpha$ is an upper bound of $E$, and if $x < \\alpha$ for some $x \\in E$ then $x$ is not an upper bound of $E$ as it is not greater than $\\alpha \\in E$. The claim follows (with an identical proof for the minimum). \\qed\n\\end{nproof}\n\n\\begin{example}{}{1.9}\n    \\begin{enumerate}\n        \\item Consider again the sets $A, B \\subset \\QQ$ from example \\ref{exam:1.1b}. $A$ is bounded above by any element in $B$, and the upper bounds of $A$ are exactly the elements of $B$. Since $B$ has no smallest member, $A$ does not have a least upper bound in $\\QQ$.\n        \\item Let $E_1, E_2 \\subset \\QQ$ such that $E_1 = \\set{r: \\QQ, r < 0}$ and $E_2 = \\set{r: \\QQ, r \\leq 0}$. Then $\\sup(E_1) = \\sup(E_2) = 0$. Note that this example shows that the supremum can either be contained or not contained in the set; $0 \\notin E_1$ but $0 \\in E_2$. \n        \\item Let $E \\subset \\QQ$ such that $E = \\set{\\frac{1}{n}: n \\in \\NN}$. Then $\\sup(E) = 1$ and $\\inf(E) = 0$. This is proven below. \n    \\end{enumerate}\n\\end{example}\n\\begin{nproof}\n    $\\sup(E) = 1$ immediately follows from the equivalence of the maximum and supremum as proven above. To see that $\\inf(E) = 0$, first note that $0$ is a lower bound for $E$ as all of the elements of $E$ are positive. To see that it is the lower bound, take any $x > 0$. Then, we have that for any $n > \\frac{1}{x}$, $\\frac{1}{n} < x$ and hence $x$ is not an upper bound of $E$. This proves the claim. \\qed\n\\end{nproof}\n\n\\begin{definition}{The LUB/GUB Property}{1.10}\n    An ordered set $S$ has the \\textbf{least upper bound property} if for every $E \\subset S$, if $E \\neq \\emptyset$ and $E$ is bounded above, then $E$ has a least upper bound (that is, $\\sup(E)$ exists in $S$). Similarly, an ordered set $S$ has the \\textbf{greatest lower bound property} if for every $E \\subset S$, if $E \\neq \\emptyset$ and $E$ is bounded below, then $E$ has a greatest lower bound.\n\\end{definition}\n\\noindent We will show in the next theorem that these properties are actually equivalent; before then, we briefly consider two examples.\n\\begin{nexample}{}\n    $\\ZZ$ has the least upper bound property, while $\\QQ$ does not. \n\\end{nexample}\n\\begin{nproof}\n    For the first claim, consider any nonempty $E \\subset \\ZZ$ that is bounded above. Choose any $x \\in E$. Since $\\ZZ$ is bounded above, there exist finitely many elements that are greater than $x$. Take the maximum of these finitely many elements. This maximum is also the maximum of $E$, so it is the supremum of $E$. Therefore $\\ZZ$ has the LUB property as claimed.\n    \n    The second claim immediately follows from Example \\ref{exam:1.9}(a). \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{1.11}\n    Let $S$ be an ordered set. Then $S$ has the LUB property if and only if it has the GUB property. \n\\end{theorem}\n\\begin{nproof}\n    $\\boxed{\\implies}$ Let $S$ be an ordered set with the LUB property. Let $E \\subset S$ with $E \\neq \\emptyset$, with $E$ bounded below. Let $L = \\set{x \\in S: x\\text{ is a lower bound of $E$.}}$. $L \\neq \\emptyset$ as $E$ is bounded below (and hence has at least one lower bound). If $y \\in E$, then $y$ is an upper bound for $L$. Since $E$ is nonempty, $L$ is therefore bounded above. Since $S$ has the LUB property, then $\\sup(L)$ must exist. Let us call this $\\alpha$. Then, $\\alpha \\leq x\\ \\forall x \\in E$ (as if $\\gamma < \\alpha$, then $\\gamma$ is not an upper bound of $L$ and hence $\\gamma \\neq E$). Hence, $\\alpha$ is a lower bound for $E$ and hence $\\alpha \\in L$. Since $\\alpha = \\sup(L)$ and $\\alpha$ is an upper bound for $L$, we have that $\\alpha \\geq \\gamma\\ \\forall \\gamma \\in L$. Thus, $\\alpha = \\inf(E)$. \n\n    $\\boxed{\\impliedby}$ Left as an exercise. \\qed\n\\end{nproof}\n\n\\subsection{Fields and Ordered Fields}\n\\begin{definition}{Fields}{1.12}\n    A \\textbf{field} $F$ is a set with two binary operations, $+$ and $\\cdot$ (addition and multiplication) such that the following axioms are satisfied:\n    \\begin{enumerate}[start=1, label={(A\\arabic*):}]\n    \\item If $x, y \\in F$, then $x + y \\in F$. (Closure under addition)\n    \\item $x + y = y + x$ for all $x, y \\in F$. (Commutativity of addition)\n    \\item $(x+y) + z = x + (y + z)$ for all $x, y, z \\in F$. (Associativity of addition)\n    \\item $\\exists 0 \\in F$ such that $\\forall x \\in F$, $0 + x = x$. (Additive identity)\n    \\item $\\forall x \\in F$, $\\exists y$ such that $x + y = 0$. We can denote $y = -x$. (Additive inverse)\n    \\end{enumerate}\n    \\begin{enumerate}[start=1, label={(M\\arabic*):}]\n        \\item If $x, y \\in F$, then $x\\cdot y\\in F$. (Closure under multiplication)\n        \\item $x \\cdot y = y \\cdot x$ for all $x, y \\in F$.\n        \\item $(x\\cdot y)\\cdot z = x \\cdot (y \\cdot z)$ for all $x, y, z \\in F$. (Associativity under multiplication)\n        \\item $\\exists 1 \\in F$ such that $1 \\neq 0$ and $\\forall x \\in F$, $1 \\cdot x = x$. (Multiplicative identity)\n        \\item $\\forall x \\in F$, exists $y \\in F$ such that $x \\cdot y = 1$. We can denote $y = \\frac{1}{x}$. (Multiplicative inverse)\n    \\end{enumerate}\n    (D): $x \\cdot (y + z) = x \\cdot y + x \\cdot z$, $\\forall x, y, z \\in F$. (Distributive law)\n\\end{definition}\n\\noindent Note that A3/M3 show that $x + y + z$ and $x\\cdot y\\cdot z$ are well defined in a mathematical sense; however, associativity may not hold for computers that do math with finite precision! \n\\begin{ntheorem}{}\n    The additive/multiplicative identities given by (A4)/(M4) and the additive/multiplicative inverses given by (A5)/(M5) are unique. \n\\end{ntheorem}\n\\begin{nproof}\n    Let $F$ be an ordered field. Suppose that there exist $0_1, 0_2 \\in F$ such that $0_1 + x= x$ and $0_2 + x = x$ for all $x \\in F$. We then have that:\n    \\begin{align*}\n        0_1 + 0_2 &= 0_1 + 0_2\n        \\\\ 0_1 + 0_2 &= 0_2 + 0_1 & \\text{(A2)}\n        \\\\ 0_2 &= 0_1 & \\text{(Property of additive identity)}\n    \\end{align*}\n    Which shows that the additive identity is unique. The remaining proofs are left as an exercise. \\qed\n\\end{nproof}\n\\noindent Some easy (and familiar) consequences of the field axioms can be found in Rudin 1.14-1.16. Instead of repeating those here, we will discuss some examples. \n\nThe rationals form a field (under the usual notions of addition/multiplication), but the integers do not, as there are no multiplicative inverses (e.g. there exists no integer $x \\in \\ZZ$ such that $2\\cdot x = 1$). The simplest example of a field is $F = \\set{0, 1}$, with the relations:\n\\begin{align*}\n    0 + 0 = 0\\quad 0\\cdot0 = 1\n    \\\\ 0 + 1 = 0 \\quad 0 \\cdot 1 = 0\n    \\\\ 1 + 1 = 0 \\quad 1 \\cdot 1 = 1\n\\end{align*}\nThis field is often called $\\mathbb{F}_2$ or $F_2$, and is useful in computer science (where bits can take on two states, 0 or 1). As a slight tangent, a byte (8 bits) can be considered an element of an 8-dimensional vector space over the field $\\mathbb{F}_2$, where $+$ would be the XOR operator and $\\cdot$ would be the AND operation. \n\nA generalization of the above example is $\\mathbb{F}_p$ or $F_p$, for a prime number $p$. This field would consist of the elements $0, 1, \\ldots, p-1$. The addition and multiplication are carried out mod $p$. An interesting result is that in general, finite fields must have cardinality of some prime power. \n\nNote that a field cannot have a single element; the field axioms (A4) and (M4) require the existence of distinct additive and multiplicative identities, which a singleton set cannot satisfy. \n\nAlthough algebra is not the focus of this course, it may be interesting to briefly think about sets with less structure than a field. We start by considering a group. \n\n\\phantom{i}\n\n\\noindent A \\textbf{group} $G$ is a set with a binary operation $(a,b) \\mapsto a\\cdot b$ such that the following axioms are satisfied:\n\\begin{enumerate}[start=1, label={(M\\arabic*):}]\n    \\item If $a, b \\in G$, then $a\\cdot b \\in G$ (Closure)\n    \\stepcounter{enumi}\n    \\item For $a, b, c \\in G$, $(a\\cdot b)\\cdot c = a\\cdot(b\\cdot c)$ (Associativity)\n    \\item There exists $1 \\in G$ such that $\\forall x \\in G$, $1 \\cdot x = x$. (Identity)\n    \\item $\\forall x \\in G$, there exists $y \\in G$ such that $x \\cdot y = 1$. (Inverse) \n\\end{enumerate}\n\nWe note that $\\ZZ$ is a group under addition, but not under multiplication (due to lack of multiplicative inverses). We can also consider the set of 2x2 matrices with integer entries:\n\\[G = \\set{\\m{a & b \\\\ c & d}: a, b, c, d \\in \\ZZ}\\]\n$G$ is again a group under matrix addition, but not under matrix multiplication (as not every matrix in $G$ is invertible). If we restricted $G$ to be the set of $2\\times 2$ invertible matrices, in this case it could form a group under matrix multiplication. A set with slightly more structure than a group (though not quite as structured as a field) is a ring:\n\\newpage \n\\noindent A \\textbf{ring} $R$ is a set with two binary operations $(a,b) \\mapsto a + b$ and $(a, b) \\mapsto a \\cdot b$ such that the following axioms are satisfied:\n\\begin{enumerate}[start=1, label={(A\\arabic*):}]\n    \\item If $x, y \\in R$, then $x + y \\in R$. (Closure under addition)\n    \\item $x + y = y + x$ for all $x, y \\in R$. (Commutativity of addition)\n    \\item $(x+y) + z = x + (y + z)$ for all $x, y, z \\in R$. (Associativity of addition)\n    \\item $\\exists 0 \\in R$ such that $\\forall x \\in R$, $0 + x = x$. (Additive identity)\n    \\item $\\forall x \\in R$, $\\exists y$ such that $x + y = 0$. We can denote $y = -x$. (Additive inverse)\n    \\end{enumerate}\n    \\begin{enumerate}[start=1, label={(M\\arabic*):}]\n        \\item If $x, y \\in R$, then $x\\cdot y\\in R$. (Closure under multiplication)\n        \\stepcounter{enumi}\n        \\item $(x\\cdot y)\\cdot z = x \\cdot (y \\cdot z)$ for all $x, y, z \\in R$. (Associativity under multiplication)\n        \\item $\\exists 1 \\in R$ such that $1 \\neq 0$ and $\\forall x \\in R$, $1 \\cdot x = x$. (Multiplicative identity)\n    \\end{enumerate}\n    \\begin{enumerate}[start=1, label={(D\\arabic*):}]\n        \\item $x \\cdot (y + z) = x \\cdot y + x \\cdot z$, $\\forall x, y, z \\in R$. (Left distributivity)\n        \\item $(y + z) \\cdot x = y \\cdot x + z \\cdot x$, $\\forall x, y, z \\in R$. (Right distributivity)\n    \\end{enumerate}\n\n\\noindent Rings have the same axioms as fields under addition, but multiplication is not necessarily commutative (this is why an additional distributivity axiom is added), and multiplicative inverses are not required. We note that $\\ZZ$ and $G$ are both rings under their respective operations of addition and multiplication. \n\nFor the remainder of this course, we will really only be discussing fields; however, they will be the objects of interest in abstract algebra courses!\n\n\\setcounter{rudin}{16}\n\\begin{definition}{Ordered Field}{1.13}\n    An \\textbf{Ordered field} is a field $F$ that is also an ordered set, such that the following axioms are satisfied:\n    \\begin{enumerate}[(i)]\n        \\item If $x, y, z \\in F$ and $y < z$, then $x + y < x + z$.\n        \\item If $x, y \\in F$ and $x > 0, y > 0$, then $x\\cdot y > 0$.\n    \\end{enumerate}\n\\end{definition}\n\\noindent Some properties of ordered fields are discussed in Rudin 1.18. We will again refer the reader to the discussion in the textbook for these properties, and here consider some examples.\n\n$\\QQ$ is an ordered field, with the familiar order of $a > b$ if $a - b > 0$. A question may arise if $\\mathbb{F}_2$ is an ordered field. A priori fields do not have order, but is it possible to impose an order on this set such that it is an ordered field? The answer turns out to be no.\n\n\\begin{proof}\n    It suffices to show that both possible orderings leads to a contradiction. Suppose $0 < 1$. Then, $1 = 0 + 1 < 1 + 1 = 0$ which is a contradiction. Suppose instead that $1 < 0$. Then, $0 = 1 + 1 < 1 + 0 = 1$ which again is a contradiction.\n\\end{proof}\n\n\\stepcounter{rudin}\n\n\\begin{theorem}{Existence of $\\RR$}{1.19}\n    There exists an ordered field $\\RR$ which has the LUB property and contains $\\QQ$ as a subfield. \n\\end{theorem}\n\\noindent What does it mean for $\\QQ$ to be a subfield? It means that there exists an injective function $\\QQ \\mapsto \\RR$ that respects the properties of an ordered field.\n\nThis field $\\RR$ happens to be exactly the set of real numbers we are familiar with. However, a natural question is ``what does it mean that there exsits a field?\" It turns out that we can define the reals based on the definitions we have made already. One further question might be that could there not exists several fields with the above property; however, taking the appropriate view, we will find that there is a unqiue such field. \n\n\\subsection{Consequences of the LUB Property}\nWe will use the least upper bound property and the fact that $\\RR$ has $\\QQ$ as a subfield to derive its properties.\n\\begin{theorem}{Archimedian Property, Density of Rationals/Irrationals in $\\RR$}{1.20}\n    \\begin{enumerate}\n        \\item If $x, y \\in \\RR$ and $x > 0$, then $\\exists n \\in \\NN$ such that $nx > y$.\n        \\item If $x, y \\in \\RR$, and $x < y$, then $\\exists p \\in \\QQ$ such that $x < p < y$. ($\\QQ$ is dense in $\\RR$)\n        \\item If $x, y \\in \\RR$, and $x < y$, then $\\exists \\alpha \\in \\RR \\setminus \\QQ$ such that $x < \\alpha < y$. ($\\RR\\setminus\\QQ$ is dense in $\\RR$)\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{nproof}\n    (a) Let $A = \\set{nx: n \\in \\NN}$. Suppose for the sake of contradiction that the conclusion was false; then $y$ is an upper bound of $A$. Then, $\\alpha = \\sup(A)$ exists by the LUB property of $\\RR$. Since $x > 0$, we then have that $\\alpha - x < \\alpha$ by the property of an ordered field. Hence, $\\alpha - x$ is not an upper bound for $A$. Therefore, there exists some $m \\in \\NN$ such that $mx > \\alpha - x$. It then follows that $(m+1)x > \\alpha$. We therefore have found $m+1 = k \\in \\NN$ such that $kx > \\alpha$, contradicting $\\alpha$ being the least upper bound of $A$. \\qed\n\\end{nproof}\n\n\\noindent In order to prove (b) and (c), we first prove a stronger version of 1.20(a):\n\n\\begin{nlemma}{}\n    If $x, y \\in \\RR$ and $x > 0$, then there exists $n \\in \\ZZ$ such that $(n-1)x \\leq y < nx$. \n\\end{nlemma}\n\\begin{nproof}\n    Suppose $y \\geq 0$. Let $A = \\set{m \\in \\NN: y < mx} \\subset \\NN$. By Theorem \\ref{thm:1.20} (a), we have that $A \\neq \\emptyset$. Every non-empty subset of $\\NN$ has a smallest element (to see this, let $x \\in A$, and define $A' = \\set{y \\in A: y \\leq x}$. This is finite and nonempty and so has a smallest element, and the minimum element of this set will also be a lower bound and hence the minimum element of all of $A$), so let $n = \\min(A)$. The claim holds for this $n$.\n    The case for $y < 0$ is left as an exercise. \\qed\n\\end{nproof}\n\\begin{nproof}\n    (b) Since $y - x > 0$, by (a), $\\exists n \\in \\NN$ such that $1 < n(y-x)$. Furthermore, by the Lemma we have that $\\exists m \\in \\ZZ$ such that $m - 1 \\leq nx < m$ and hence $m \\leq nx + 1$. From these inequalities we obtain that $nx < m \\leq nx + 1 < ny$, and therefore $x < \\frac{m}{n} < y$ for some $m \\in \\ZZ$, $n \\in \\NN$. \\qed\n\\end{nproof}\n\\noindent For the proof of part (c), we will use the result of Theorem \\ref{thm:1.21} from the next section, specifically that there exists $s \\in \\RR \\setminus \\QQ$ such that $s > 0$ and $s^2 = 2$. We will call this $\\sqrt{2}$.\n\\begin{nproof}\n    (c) First, we have that $\\sqrt{2} < 2$ as if $\\sqrt{2} = 2$ then $(\\sqrt{2})^2 = 2 = 2^2 = 4$ which is a contradiction, and if $\\sqrt{2} > 2$ then $2 = \\sqrt{2}\\cdot \\sqrt{2} > 2\\cdot 2 = 4$ by Rudin 1.18 which is yet again a contradiction. Thus, $\\frac{\\sqrt{2}}{2} < 1$. \n    \n    Let $x, y \\in \\RR$ such that $x < y$. By Theorem \\ref{thm:1.20}(b), there exists $p, q \\in \\QQ$ such that $x < p < q < y$. Let $\\alpha = p + \\frac{\\sqrt{2}}{2}(q - p)$. Then, we have that $p  <\\alpha < p + 1(q-p) < q$ and hence $x < p < \\alpha < q < y$.\n\n    If $\\alpha \\in \\QQ$, then $\\sqrt{2} = 2\\left(\\frac{\\alpha-p}{q-p}\\right) \\in \\QQ$, which is a contradiction, so it follows that $\\alpha \\in \\RR \\setminus \\QQ$. \\qed\n\\end{nproof}\n\n\\subsection{Integer Roots of the Reals}\nIn this section, we will prove that $\\sqrt{2}$ exists and is an irrational number, but we will not use the fact that $\\RR \\setminus \\QQ$ is dense in $\\RR$; this would of course be circular reasoning. The more general idea will be to prove that for any $n \\in \\NN$, there exists $y \\in \\RR$ such that $y = x^{1/n}$. Before this, we prove a lemma.\n\\begin{nlemma}{}\n    If $0 < a < b$ and $n \\in \\NN$, then $0 < b^n - a^n \\leq nb^{n-1}(b-a)$\n\\end{nlemma}\n\\noindent Note that a ``Calculus proof'' of this Lemma would be to let $f(x) = x^n$, and then\n\\[f(b) - f(a) = f'(c)(b-a) = nc^{n-1}(b-a) \\leq nb^{n-1}(b-a)\\]\nWhere we invoke the mean value theorem. But this obviously doesn't work as we have neither defined a derivative nor proven the mean value theorem. A proper proof would be:\n\\begin{nproof}\n    Let $0 < a < b$. Then, we may factor $b^n - a^n$ such that:\n    \\[b^n - a^n = (b-a)(b^{n-1} + ab^{n-2} + a^2b^{n-3} + \\ldots + a^{n-2}b + a^{n-1})\\]\n    The second factor is a sum of $n$ terms, each positive, and in between $0$ and $b^{n-1}$. ThereforE:\n    \\[b^n - a^n \\leq nb^{n-1}(b-a)\\]\n    which proves the claim. \\qed\n\\end{nproof}\n\\noindent We will now state the theorem formally:\n\\begin{theorem}{Integer Roots of the Reals}{1.21}\n    Let $x \\in \\RR$, $x > 0$, and $n \\in \\NN$. Then, there exists a unique $y \\in \\RR$ such that $y > 0$ and $y^n = x$. \n\\end{theorem}\n\\noindent Note that somewhere in the proof, we will use the fact that $y \\in \\RR$; this statement doesn't hold for rationals (see Example \\ref{exam:1.1a}) so some property of the reals must come into play somewhere.\n\\begin{nproof}\n    If $n = 1$, then the unique solution is $y = x$; we may therefore assume that $n \\geq 2$.\n    \\\\ \\textbf{Uniqueness:} Suppose there exist two distinct numbers $y_1, y_2$ with $y_1 > 0, y_2 > 0$, and $y_1^n = y_2^n = x$. WLOG, suppose $0 < y_1 < y_2$. We then have that $0 < y_1^n < y_2^n$ which is a contradiction. \n    \\\\ \\textbf{Existence:} We prove existence in three steps.\n    \\begin{enumerate}[1.]\n        \\item We show that $E \\neq \\emptyset$. Let $E = \\set{t \\in \\RR: t > 0, t^n < x}$. If $x < 1$, then $x^n < x$, so $x \\in E$. If $x \\geq 1$, then $\\left(\\frac{1}{2}\\right)^n < \\frac{1}{2} < x$, so $\\frac{1}{2} \\in E$. Therefore, $E \\neq \\emptyset$.\n        \\item We show that $E$ is bounded above and has a supremum in $\\RR$. If $t > 1 + x$, then it follows that $t^n > t > x$, so $t \\neq E$. Hence, $1 + x$ is an upper bound of $E$. By Theorem \\ref{thm:1.19} (the LUB property of $\\RR$), it follows that $\\sup(E) \\in \\RR$ exists. \n        \\item We show that $y = \\sup(E)$ satisfies $y^n = x$. As $\\RR$ is an ordered field, one of $y^n < x$, $y^n = x$, or $y^n > x$ must be true; we show that the first and third are impossible.\n        \\begin{enumerate}\n            \\item Suppose $y^n < x$. We will obtain a contradiction by finding $h > 0$ such that $(y+h)^n < x$. (Why is this a contradiction? $y+ h > y$, so if $(y+h)^n < x$, then $y + h \\in E$, contradicting the fact that $y + h$ would be an upper bound of $E$). WLOG, suppose that $h < 1$. By the above Lemma, we have that:\n            \\[(y+h)^n - y^n \\leq n(y+h)^{n-1}h \\leq n(y+1)^{n-1}h\\]\n            By choosing $h$ sufficiently small, that is:\n            \\[h < \\min\\set{1, \\frac{x-y^n}{n(y+1)^{n-1}}}\\]\n            Then $n(y+1)^{n-1}h < x^n - y^n$ from which it follows that $(y+h)^n - y^n < x^n - y^n$ and so $y+h < x$, which is the desired contradiction.\n            \\item Suppose $y^n > x$. We will obtain a contradivction by finding $h > 0$ such that $(y-h)^n > x$. If this is true, then $y-h$ is an upper bound for $E$, contradicting the fact that $y$ is the least upper bound for $E$. WLOG suppose that $h < 0$. Again applying the Lemma, we have that:\n            \\[y^n - (y-h)^n \\leq ny^{n-1}h\\]\n            By choosing $h$ sufficiently small, that is:\n            \\[h < \\min\\set{1, \\frac{y^n-x}{ny^{n-1}}}\\]\n            It then follows that:\n            \\[y^n - (y-h)^n \\leq ny^{n-1}h < y^n - x\\]\n            and hence $(y-h)^n > x$, which is the desired contradiction. \\qed\n        \\end{enumerate} \n    \\end{enumerate}\n\\end{nproof}\n\\subsection{Construction of the Reals}\nTheorem \\ref{thm:1.19} says that there exists an ordered field that contains $\\QQ$ as a subfield. We now go about proving this statement. The construction is fairly technical and hence will be carried out in multiple steps. Some of the steps are left as exercises (one can refer to Rudin for the fully complete construction).\n\n\\begin{nblank}{Step 1: Defining the elements of $\\RR$}\n    The members of $\\RR$ will be proper subsets of $\\QQ$, called cuts. $\\RR = \\set{\\text{all cuts}}$. \n    \\begin{ndef}{: Cuts}\n        A \\textbf{cut} is a proper subset $\\alpha \\subsetneq \\QQ$ with the three properties:\n        \\begin{enumerate}[(I)]\n            \\item $\\alpha \\neq \\emptyset$\n            \\item If $p \\in \\alpha$, then $q \\in \\alpha \\; \\forall q < p$. \n            \\item If $p \\in \\alpha$, then $\\exists r \\in \\alpha$ such that $p < r$. \n        \\end{enumerate}\n    \\end{ndef}\n\\end{nblank}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n        \\draw[latex-latex, very thick] (-6, 0) -- (6,0) node[anchor=south] {$\\QQ$};\n        \\foreach \\i in {-5.7,-5.6,...,0.9}{ \n        \\draw[] (\\i,0) -- (\\i,-0.1);\n        }\n        \\draw[] (1,0.1) node[anchor=south] {$\\downarrow$};\n        \\draw[] (0.96,0) node[] {$)$};\n        \\draw[] (-2.5, 0) node[anchor=south] {$\\alpha$};\n    \\end{tikzpicture}\n    \\caption{Visualization of a cut $\\alpha$. The real number being described of this cut can be thought of as the number at the right boundary (the arrow).}\n    \\label{fig2} \n\\end{figure}\n\\noindent In a sense, a cut gives us a way of discussing the real numbers (in the way we are familiar with them already) without referring to them directly; much like we could formally define/refer to rationals as equivalence classes of ordered pairs.  \n\n\\noindent As a note, we could very well define cuts to be bounded below rather than above, and the following construction would still work out.\n\n\\begin{nblank}{Step 2: $\\RR$ is an ordered set}\n    We define $\\alpha < \\beta$ to mean $\\alpha \\subsetneq \\beta$. We show that this makes $\\RR$ into an ordered set. First checking transitivity, we have that if $\\alpha < \\beta$ and $\\beta < \\gamma$ then $\\alpha < \\gamma$ by the fact that set inclusion is transitive. Furthermore, at most one of $\\alpha < \\beta$, $\\alpha = \\beta$, and $\\beta < \\alpha$ hold; to see this is the case, suppose the first two fail. Then, $\\alpha \\nsubseteq \\beta$. Hence, $\\exists p \\in \\alpha$ with $p \\notin \\beta$. If $q \\in \\beta$, $q < p$  and hence $q \\in \\alpha$ by (II), so $\\beta \\subset \\alpha$, and since $\\beta \\neq \\alpha$ it follows that $\\beta \\subsetneq \\alpha$. \n\\end{nblank}\n\n\\begin{nblank}{Step 3: $\\RR$ has the LUB property}\n    We show that $\\RR$ has the LUB property. To see this is the case, let $A \\subset \\RR$ with $A \\neq \\emptyset$, and suppose that there exists $\\beta \\in \\RR$ that is an upper bound for $A$. We will now define $\\gamma = \\bigcup_{\\alpha \\in A}\\alpha$ and prove that $\\gamma \\in \\RR$ and $\\gamma = \\sup A$ (hence $A$ has a supremum and $\\RR$ has the LUB property).\n\n    Since $A \\neq \\emptyset$, $\\exists \\alpha_0 \\in A$, and since $\\alpha_0 \\neq \\emptyset$ (as it is a cut) and $\\alpha \\subset \\gamma$, it follows that $\\gamma \\neq \\emptyset$. Next, we have that $\\gamma \\subset \\beta$, since $\\alpha \\subset \\beta$ for every $\\alpha \\in A$, and hence $\\gamma \\neq \\QQ$, that is, $\\gamma \\subsetneq \\QQ$. Hence $\\gamma$ satisfies property (I) of a cut. \n\n    Take $p \\in \\gamma$. Then $p \\in \\alpha_1$ for some $\\alpha_1 \\in A$. If $q < p$, then $q \\in \\alpha$ (as $\\alpha$ is a cut) so $q \\in \\gamma$, satisfying property (II).\n\n    Next, choose $r \\in \\alpha_1$ such that $r > p$, then $r \\in \\gamma$ (as $\\alpha_1 \\subset \\gamma$) and hence $\\gamma$ satisfies property (III). Hence $\\gamma$ is a cut, and $\\gamma \\in \\RR$.\n\n    Finally, we show that $\\gamma = \\sup A$. Clearly, $\\alpha \\leq \\gamma$ for all $\\alpha \\in A$, as $\\gamma = \\bigcup_{\\alpha \\in A}\\alpha$, so $\\gamma$ is an upper boun dof $A$. To show that it is the least upper bound, let $\\delta < \\gamma$ be a cut. Then, $\\exists s \\in \\gamma$ such that $s \\notin \\delta$. Therefore, $\\exists \\alpha_2 \\in A$ such that $s \\in \\alpha_2$; hence $\\delta < \\alpha_2$, so $\\delta$ is not an upper bound for $A$, giving the desired result. \n\\end{nblank}\n\n\\begin{nblank}{Step 4: Addition on $\\RR$}\n    \\begin{ndef}{: Addition}\n        If $\\alpha, \\beta \\in \\RR$, we define $\\alpha + \\beta = \\set{s + t: s \\in \\alpha, t \\in \\beta}$. Showing that this is a cut is left as an exercise.\n    \\end{ndef}\n    \\begin{ndef}{: Zero}\n        $0^* = \\set{s \\in \\QQ}$. Showing that this is a cut is left as an exercise.\n    \\end{ndef}\n\n    We leave it as an exercise to show that the addition axioms (A1)-(A5) of a field are satisfied under this definition of addition on $\\RR$, with the 0 element as $0^*$ defined above.\n\\end{nblank}\n\n\\begin{nblank}{Step 5: $\\RR$ satisfies the Ordered Field Property (i)}\n    We verify that if $\\alpha, \\beta, \\gamma \\in \\RR$ and $\\beta < \\gamma$, then $\\alpha + \\beta < \\alpha + \\gamma$. \n\n    For every $s \\in \\alpha, t \\in \\beta$, we have that $t \\in \\gamma$ as $\\beta$ is a subset of $\\gamma$ by the definition of order on $\\RR$. Hence, $s + t \\in \\alpha + \\beta$ implies $s + t \\in \\alpha + \\gamma$. Therefore, $\\alpha + \\beta \\subset \\alpha + \\gamma$ and hence $\\alpha + \\beta \\leq \\alpha + \\gamma$. \n\n    We are then left to check that $\\alpha + \\beta \\neq \\alpha + \\gamma$. To see that this is the case, if $\\alpha + \\beta = \\alpha + \\gamma$, then $\\beta = \\alpha + \\beta - \\alpha = \\alpha + \\gamma - \\alpha = \\gamma$ by the field axioms for addition. Therefore we obtain that $\\beta = \\gamma$, contradicting that $\\beta < \\gamma$. Hence the claim is proven.\n\n    As a remark, note that $0^* < \\alpha \\iff -\\alpha < 0^*$.\n\\end{nblank}\n\\noindent Next we will define multiplication on $\\RR$. A first attempt would be $\\alpha \\cdot \\beta = \\set{s \\cdot t: s\\in \\alpha, t \\in \\beta}$. However, this definition is incosistent with negative numbers from what we require multiplication to accomplish. $-1 \\cdot -1$ would fail to be a cut (it would not contain any negative numbers and hence fail criteria (II)) and $-1 \\cdot 1$ would yield the entirety of the rationals (again not a cut!)\n\n\\begin{nblank}{Step 6: Positive Multiplication on $\\RR$}\n    \\begin{ndef}{: Positive Reals}\n        We define $\\RR^+ = \\set{\\alpha \\in \\RR: \\alpha > 0^*}$\n    \\end{ndef}\n    \\begin{ndef}{Multiplication of Positive Reals}\n        If $\\alpha, \\beta \\in \\RR^+$, we define $\\alpha \\cdot \\beta = \\set{r \\cdot s: r \\in \\alpha, r> 0, s \\in \\beta, s > 0} \\cup \\set{t \\in \\QQ, t \\leq 0}$. Equivalently, $\\alpha \\cdot \\beta = \\set{p \\in \\QQ:  \\leq r \\cdot s: r \\in \\alpha, r > 0, s \\in \\beta, s > 0}$. We leave it as an exercise to show that $\\alpha \\cdot \\beta \\in \\RR$, and moreover, $\\alpha \\cdot \\beta \\in \\RR^+$. Showing this second fact proves ordered field property (ii).\n    \\end{ndef}\n    \\begin{ndef}{: One}\n        $1^* = \\set{r \\in \\QQ: r < 1}$. We again leave showing $1^* \\in \\RR^+$ as an exercise. \n    \\end{ndef}\n\\end{nblank}\n\n\\begin{nblank}{Step 7: Multiplication on all of $\\RR$}\n    \\begin{ndef}{: Multiplication by zero}\n        $\\alpha \\cdot 0^* = 0^* = 0^* \\cdot \\alpha$\n    \\end{ndef}\n    \\begin{ndef}{: Multiplication}\n        We define general multiplication as below, where the $\\cdot$ on the RHS represents the multiplication of positive reals as outlined in Step 5. \n        \\begin{align*}\n            \\alpha \\cdot \\beta = \n            \\begin{cases}\n            (-\\alpha)\\cdot(-\\beta) & \\text{if $\\alpha < 0^*$ and $\\beta < 0^*$}\n            \\\\ -\\left((-\\alpha)\\cdot\\beta\\right) & \\text{if $\\alpha < 0^*$ and $\\beta > 0^*$}\n            \\\\ -\\left(\\alpha \\cdot (-\\beta)\\right) & \\text{if $\\alpha > 0^*$ and $\\beta < 0^*$}\n            \\end{cases}\n        \\end{align*}\n    \\end{ndef}\n    We leave it as an exercise to show that the multiplicative axioms (M1)-(M5), as well as the distributive law (D) of a field are satisfied under this definition of multiplication on $\\RR$. \n\\end{nblank}\n\\noindent Up until this point, we have shown $\\RR$ is an ordered field with the LUB property; we last check that it contains $\\QQ$ as a subfield. Note that we do have to be a bit careful with what we mean here; $\\RR$ does not literally contain $\\QQ$; $\\RR$ is indeed a set of proper subsets of $\\QQ$. What we really mean is to associate every element of $\\QQ$ to an element of $\\RR$ such that the field structure is preserved. \n\\begin{nblank}{Step 8: $\\RR$ contains $\\QQ$ as a subfield}\n    For each $r \\in \\QQ$, associate the cut $r^* = \\set{p \\in \\QQ, p < r^*}$. We then leave as an easy exercise to verify that $r^* < s^* \\iff r < s$, $r^* + s^* = r + s$, and $r^*\\cdot s^* = r\\cdot s$. This concludes the construction of the reals. \\qed\n\\end{nblank}\n\\noindent Note that later on in the course, we will construct the real numbers in a different fashion; by considering Cauchy sequences modulo an equivalence relation. Also note that from here on out, it will suffice to have the standard/traditional picture of a \"real number\" in mind (i.e. infinite decimal expansions) and we will not have to really think about the real numbers as cuts; this was just necessary for the formal construction.\n\n\\subsection{The Complex Field}\n\\setcounter{rudin}{23}\n\\begin{definition}{The Complex Numbers}{1.24}\n    We define the set of \\textbf{complex numbers} to be $\\set{(a, b): a, b \\in \\RR}$, denoted by $\\CC$. For $x = (a, b) \\in \\CC$ and $y = (c, d) \\in \\CC$, we write $x = y$ if and only if $a = c$ and $b = d$ (note that this is a very different notion of equality compared to the rationals). We define the zero element to be $(0, 0)$ and the one element to be $(1, 0)$. We define addition of complex numbers such that:\n    \\begin{align*}\n        x + y = (a, b) + (c, d) = (a + c, b + d)\n    \\end{align*}\n    And multiplication of complex numbers such that:\n    \\begin{align*}\n        x\\cdot y = (a, b)\\cdot (c, d) = (ac - ba, ad + bc)\n    \\end{align*}\n\\end{definition}\n\\begin{theorem}{}{1.25}\n    The operations of $+$ and $\\cdot$, as well as the zero/one elements defined above turn $\\CC$ into a field. \n\\end{theorem}\n\\begin{nproof}\n    It suffices to verify the field axioms (A1)-(A5), (M1)-(M5), and (D) as discussed in \\ref{def:1.12}. We will here show (M3), (M4), and (M5) and leave the rest as exercises. \n    \\begin{enumerate}[start=3, label={(M\\arabic*):}]\n    \\item Let $x, y, z \\in \\CC$. We show that $(x\\cdot y)\\cdot z = x \\cdot (y \\cdot z)$. Let $x = (a, b), y = (c, d)$, and $z = (e, f)$. We then have that:\n    \\begin{align*}\n        (x\\cdot y) \\cdot z &= (ac - bd, ad + bc) \\cdot (e, f)\n        \\\\ &= ((ac-bd)e - (ad+bc)f, (ac-bd)f + (ad+bc)e)\n    \\end{align*}\n    We also have that:\n    \\begin{align*}\n        x \\cdot(y\\cdot z) &= (a, b)\\cdot(ce - df, cf + de)\n        \\\\ &= (a(ce-df) - b(cf+de), a(cf+de) + b(ce-df))\n        \\\\ &= (ace - adf - bcf - bde, acf + ade + bce - bdf)\n        \\\\ &= ((ac-bd)e - (ad+bc)f, (ac-bd)f + (ad+bc)e)\n    \\end{align*}\n    So the claim is proven.\n    \\item $(a, b)(1, 0) = (a \\cdot 1 - b \\cdot 0, a \\cdot 0 + b \\cdot 1) = (a, b)$\n    \\item Let $x \\in \\CC$ such that $x \\neq 0$. Then, $x = (a, b)$ where either $a \\neq 0$ or $b \\neq 0$ or both. Hence, $a^2 + b^2 > 0$. Then, let $\\frac{1}{x} = (\\frac{a}{a^2 + b^2}, -\\frac{b}{a^2+b^2})$. We then have that:\n    \\begin{align*}\n        x\\frac{1}{x} &= (a, b)\\left(\\frac{a}{a^2 + b^2}, -\\frac{b}{a^2+b^2}\\right)\n        \\\\ &= \\left(a\\frac{a}{a^2 + b^2} - b\\left(-\\frac{b}{a^2+b^2}\\right), a\\left(-\\frac{b}{a^2+b^2}\\right) + b\\left(\\frac{a}{a^2+b^2}\\right)\\right)\n        \\\\ &= \\left(\\frac{a^2 +b^2}{a^2 + b^2}, -\\frac{ab}{a^2+b^2} + \\frac{ab}{a^2+b^2}\\right)\n        \\\\ &= (1, 0)\n    \\end{align*}\n    Which proves the claim. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\\noindent Much like $\\QQ$ was a subfield of $\\RR$, $\\RR$ is a subfield of $\\CC$, and there exists a map $\\phi$ from $\\RR$ to $\\CC$ that respects the field axioms, namely:\n\\begin{align*}\n    \\fullfunction{\\phi}{\\RR}{\\CC}{x}{(x, 0)}\n\\end{align*}\nThe theorem below shows that $\\phi$ preserves the field structure:\n\\begin{theorem}{}{1.26}\n    For $a, b \\in \\RR$ we have that $(a, 0) + (b, 0) = (a + b, 0)$ and $(a, 0)(b, 0) = (ab, 0)$.\n\\end{theorem}\n\\begin{definition}{i}{1.27}\n    $i = (0, 1)$. \n\\end{definition}\n\\begin{theorem}{}{1.28}\n    $i^2 = -1$. \n\\end{theorem}\n\\begin{theorem}{}{1.29}\n    If $a, b \\in \\RR$, then $(a, b) = a + bi$. \n\\end{theorem}\n\\begin{nproof}\n    Below are the trivial proofs for the above three theorems. \n    \\begin{align*}\n        (a, 0) + (b, 0) = (a + b, 0 + 0) = (a + b, 0)\n        \\\\ (a, 0)\\cdot(b, 0) = (a\\cdot b - 0 \\cdot 0, a \\cdot 0 + 0 \\cdot b) = (ab, 0)\n        \\\\ i^2 = i\\cdot i = (0, 1) \\cdot (0, 1) = (-1, 0) = -1\n        \\\\ a + bi = (a, 0) + b(0, 1) = (a, 0) + (0, b) = (a, b)\n    \\end{align*}\n\\end{nproof}\n\\noindent A slightly odd question may be to ask whether $\\CC$ is a subfield of $\\RR$, i.e. does there exist $\\psi: \\CC \\mapsto \\RR$ such that $\\psi(a + b) = \\psi(a) + \\psi(b)$ and $\\psi(a\\cdot b) = \\psi(a) \\cdot \\psi(b)$. As we will prove in Chapter 2, we do have that $\\abs{\\CC} = \\abs{\\RR^2} = \\abs{\\RR}$ (where $\\abs{}$ denotes cardinality of the set, to be defined shortly), so there does exist a bijection (i.e. a function that is both injective/one-to-one and surjective/onto; we will define these terms precisely in the next chapter) between the two sets.\n\nAs a Lemma, we have that the only injective function $f: \\QQ \\mapsto \\RR$ that satisfies $f(a+b) = f(a) + f(b)$ and $f(a\\cdot b) = f(a)\\cdot f(b)$ is $f(x) = x$. The proof of this is left as a homework problem (HW2). Therefore, it follows that the only injective function $g: \\QQ \\times \\set{0} \\mapsto \\RR$ (where $\\times$ denotes the Cartesian product) is given by $g((x, 0)) = x$. We now give a proof that $\\CC$ is not a subfield of $\\RR$. \n\n\\begin{proof}\n    Suppose then for the sake of contradiction that there exists an injective function $\\psi: \\QQ \\times \\set{0, 1} \\mapsto \\RR$. Such a function then must satisfy$\\psi(i \\cdot i) = \\psi(-1) = -1$, and $\\psi(i \\cdot i) = \\psi(i) \\cdot \\psi(i) = \\psi((0, 1))\\cdot \\psi((0, 1)) = 0 \\cdot 0 = 0$ which is a contradiction. Hence, no such injection exists from $\\QQ \\times \\set{0, 1}$ to $\\RR$ and hence no such injection could exist from $\\CC$ ($\\RR^2$) to $\\RR$. Hence $\\CC$ is not a subfield of $\\RR$. \n\\end{proof}\n\n\n\n\\begin{definition}{Real/Imaginary Parts and Complex Conjugates}{1.30}\nLet $z = a + bi \\in \\CC$. Then, $\\Re(z) = a$ is the \\textbf{real part} of $z$ and $\\Im(z) = b$ is the \\textbf{imaginary part} of $z$. The \\textbf{complex conjugate} of $z$, denoted by $\\bar{z}$, is defined as $\\bar{z} = a - bi$. \n\\end{definition}\n\n\\begin{theorem}{}{1.31}\n    Let $z, w \\in \\CC$. It then follows that:\n    \\begin{enumerate}\n        \\item $\\overline{z + w} = \\bar{z} + \\bar{w}$.\n        \\item $\\overline{zw} = \\bar{z} \\cdot \\bar{w}$.\n        \\item $z + \\bar{z} = 2\\Re(z)$, $z - \\bar{z} = 2i\\Im(z)$.\n        \\item $z\\bar{z}$ is real and positive (except when $z = 0$).\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{nproof}\n    We prove (d). We have that:\n    \\begin{align*}\n        z\\bar{z} = (a + bi)(a-bi) = a^2 + b^2 \n    \\end{align*}\n    $a^2 + b^2 \\geq 0$, and $a^2 + b^2 = 0 \\iff a = 0, b = 0$ which proves the claim. \\qed\n\\end{nproof}\n\n\\begin{definition}{Absolute Value}{1.32}\n    We define the \\textbf{absolute value} $\\abs{z}$ of a complex number $z$ as $\\abs{z} = \\sqrt{z\\bar{z}}$. Note that if $a \\in \\RR$ and $z = (a, 0)$, then\n    \\begin{align*}\n        \\abs{z} = \\sqrt{a^2} =\n        \\begin{cases}\n            a & \\text{if $a \\geq 0$}\n            \\\\ -a & \\text{if $a < 0$}\n        \\end{cases}\n    \\end{align*}\n    Hence if $a \\in \\RR$, we can define $\\abs{a} = \\abs{(a, 0)}$. \n\\end{definition}\n\n\\begin{theorem}{}{1.33}\n    Let $z, w \\in \\CC$.\n    \\begin{enumerate}\n        \\item $\\abs{z} \\geq 0$, $\\abs{z} = 0 \\iff z = 0$. \n        \\item $\\abs{\\bar{z}} = \\abs{z}$.\n        \\item $\\abs{z}\\abs{w} = \\abs{zw}$.\n        \\item $\\abs{\\Re(z)} \\leq \\abs{z}$, $\\abs{\\Im(z)} \\leq \\abs{z}$.\n        \\item $\\abs{z + w} \\leq \\abs{z} + \\abs{w}$.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    We prove (d) and (e). Let $z, w \\in \\CC$, with $z = a + bi$. For (d) we have that $\\Re(z) = a$, so \\begin{align*}\n        \\abs{\\Re(a)} = \\sqrt{a^2} \\leq \\sqrt{a^2 + b^2} = \\abs{z}\n    \\end{align*}\n    And an equivalent proof follows for $\\Im(z)$. For (e), we have that:\n    \\begin{align*}\n        \\abs{z + w}^2 &= (z + w)(\\overline{z + w})\n        \\\\ &= z\\bar{z} + z\\bar{w} + w\\bar{z} + w\\bar{w}\n        \\\\ &= \\abs{z}^2 + 2\\Re(z\\bar{w}) + \\abs{w}^2\n        \\\\ &\\leq \\abs{z}^2 + 2\\abs{\\Re(z\\bar{w})} + \\abs{y}^2 & \\text{($\\abs{x} > x$)}\n        \\\\ &= \\abs{z}^2 + 2\\abs{z\\bar{w}} + \\abs{w}^2 & \\text{(1.33(d))}\n        \\\\ &= \\abs{z}^2 + 2\\abs{z}\\abs{\\bar{w}} + \\abs{w}^2 & \\text{(1.33(c))}\n        \\\\ &= \\abs{z}^2 + 2\\abs{z}\\abs{w} + \\abs{w}^2 & \\text{(1.33(b))}\n        \\\\ &= (\\abs{z} + \\abs{w})^2\n    \\end{align*}\nThe claim follows by taking square roots on both sides. \\qed\n\\end{nproof}\n\n\n\n\\subsection{The Cauchy-Shwartz Inequality}\nRecall the summation notation:\n\\begin{align*}\n    x_1 + x_2 + \\ldots + x_n = \\sum_{j=1}^{n}x_i\n\\end{align*}\n\\stepcounter{rudin}\n\\begin{theorem}{Cauchy-Shwartz Inequality}{1.35}\n    Let $a_1, \\ldots, a_n, b_1, \\ldots, b_n \\in \\CC$. We then have that:\n    \\begin{align*}\n        \\abs{\\sum_{j=1}^na_j\\bar{b}_j}^2 \\leq \\left(\\sum_{j=1}^n\\abs{a_j}^2\\right)\\left(\\sum_{j=1}^n\\abs{b_j}^2\\right)\n    \\end{align*}\n\\end{theorem}\n\\noindent Note that in the above theorem, both the RHS and the LHS are real numbers (check!) so the equality makes sense (recall that there is no order on $\\CC$; in fact, it is impossible to define one). \n\nA geometric interpretation of the above inequality is as follows. Let $\\v{a}, \\v{b}$ be vectors in $\\CC^n$. Then, $\\avg{\\v{a}, \\v{b}} = \\sum_{j=1}^na_j\\bar{b}_j$ is the inner product of $\\v{a}$ and $\\v{b}$. Then, the inequality says that $\\abs{\\avg{\\v{a}, \\v{b}}}^2 \\leq \\avg{\\v{a}, \\v{a}}\\cdot\\avg{\\v{b}, \\v{b}}$. \n\\begin{nproof}\n    Define $A = \\sum_{j=1}^n\\abs{a_j}^2$, $B = \\sum_{j=1}^n\\abs{b_j}^2$, and $C = \\sum_{j=1}^na_j\\bar{b}_j$. If $B = 0$ (that is, all of the $b_j$s are zero) then the LHS/RHS are both zero and we are done. So, let us assume that $B > 0$. Let $\\lambda \\in \\CC$, and we then have that:\n    \\begin{align*}\n        0 &\\leq \\sum_{j=1}^n\\abs{a_j + \\lambda b_j}^2 \\\\ &= \\sum_{j=1}^n(a_j + \\lambda b_j)(\\bar{a}_j + \\bar{\\lambda}\\bar{b}_j)\n        \\\\ &= \\sum_{j=1}^n\\abs{a_j}^2 + \\bar{\\lambda}\\sum_{j=1}^na_j\\bar{b}_j + \\lambda\\sum_{j=1}^n\\bar{a}_jb_j + \\abs{\\lambda}^2\\sum_{j=1}^n\\abs{b_j}^2\n        \\\\ &= A + \\bar{\\lambda}C + \\lambda\\bar{C} + \\abs{\\lambda}^2B\n    \\end{align*}\n    This inequality holds for any $\\lambda$; it therefore holds for $\\lambda = -\\frac{C}{B}$, so:\n    \\begin{align*}\n        0 &\\leq A - \\frac{\\bar{C}}{B}C - \\frac{C}{B}\\bar{C} + \\frac{C\\bar{C}}{B^2}B\n        \\\\ &= A - \\frac{\\abs{C}^2}{B}\n    \\end{align*}\n    So we therefore obtain that $\\abs{C}^2 \\leq AB$ which is the desired inequality. \\qed\n\\end{nproof}\n\\noindent A natural question given any inequality is when does equality hold; the answer turns out to be if the vectors are linearly independent, that is, at least one of $\\v{a} = \\alpha \\v{b}$ and $\\v{b} = \\beta \\v{a}$ ($\\alpha, \\beta \\in \\CC$) hold. Note that we only require one of the two relations to hold; in the case that one of $\\v{a}, \\v{b}$ are $\\v{0}$ (the vector of all zeros) both equalities cannot be true. It is left as a homework problem to verify equality in the Cauchy-Shwartz inequality if and only if at least one of the two conditions holds (HW3). \n\n\\subsection{Euclidean Space}\n\\begin{definition}{Euclidean k-space}{1.36}\n    If $k \\in \\NN$, define $\\RR^k$ as the set of $k$-tuples of real numbers:\n    \\begin{align*}\n        \\RR^k = \\set{\\v{x} = (x_1, x_2, \\ldots, x_k): x_1, x_2, \\ldots, x_k \\in \\RR}\n    \\end{align*}\n    We can then define vector addition as:\n    \\begin{align*}\n        \\v{x} + \\v{y} = (x_1 + y_1, x_2 + y_2, \\ldots, x_k + y_k)\n    \\end{align*}\n    And scalar multiplication (for $\\alpha \\in \\RR$) to be:\n    \\begin{align*}\n        \\alpha\\v{x} = (\\alpha x_1, \\alpha x_2, \\ldots, \\alpha x_k)\n    \\end{align*}\n    These operations make $\\RR^k$ into a vector space over the real field. We can define the inner product over $\\RR^k$ to be:\n    \\begin{align*}\n        (\\v{x}, \\v{y}) = \\v{x} \\cdot \\v{y} = \\sum_{j=1}^k x_jy_j\n    \\end{align*}\n    This allows us to define the norm of $\\v{x}$ to be:\n    \\begin{align*}\n        \\abs{\\v{x}} = \\sqrt{\\v{x} \\cdot \\v{x}} = \\left(\\sum_{j=1}^n x_j^2\\right)^{1/2}\n    \\end{align*}\n    $\\RR^k$ with the above inner product and norm is called \\textbf{Euclidean k-space}.\n\\end{definition}\n\\noindent We briefly remark that the above inner product we defined agrees with the inner product we defined over $\\CC^k$; we can identify $r \\in \\RR$ with $(r, 0) \\in \\CC$, and hence recognize that $\\RR^k \\subset \\CC^k$ where the imaginary part of each coordinate is zero. Then, for the inner product we get the exact same result, as $\\bar{b}_j = b_j$ for any complex numbers with imaginary part zero. From this we can conclude that the Cauchy-Shwartz inequality also holds in $\\RR^k$. \n\nNote that although the field $\\CC$ is $\\RR^2$ with multiplication defined as in Definition \\ref{def:1.24}, in general vector multiplication on $\\RR^n$ is not well defined. That is, we cannot make $\\RR^n$ into a field in general; though we can make it into a vector space, which has slightly less structure.\n\nOne possibly familiar notion of vector multiplication in $\\RR^3$ is the cross product. For $\\v{x} = (x_1, x_2, x_3)$ and $\\v{y} = (y_1, y_2, y_3)$, the cross product is defined as:\n\\begin{align*}\n    \\v{x} \\times \\v{y} = (x_2y_3 - x_3y_2, x_3y_1 - x_1y_3, x_1y_2 - x_2y_1)\n\\end{align*}\nHowever, the cross product does not satisfy properties that would be necessary to make $\\RR^3$ a field. For one, it is not commutative, but anticommutative; $\\v{x} \\times \\v{y} = -\\v{y} \\times \\v{x}$. One might ask whether vectors in $\\RR^3$ have well-defind inverses, but even before that, there does not exist an identity vector in $\\RR^3$ under the cross product! In fact, $\\RR^3$ under vector addition and cross product multiplication can be viewed as a noncommutative ring without an identity. \n\nNote that there is a more general notion of a ``wedge product'' between vectors in $\\RR^n$. We are in a sense very ``lucky'' that in $\\RR^3$, the wedge product of two vectors returns another vector in $\\RR^3$. \n\n\\begin{theorem}{}{1.37}\n    Let $\\v{x}, \\v{y}, \\v{z} \\in \\RR^k$, and $\\alpha \\in \\RR$. Then:\n    \\begin{enumerate}\n        \\item $\\abs{\\v{x}} \\geq 0$\n        \\item $\\abs{\\v{x}} = 0 \\iff \\v{x} = (0, \\ldots, 0)$. This is often denoted as $\\v{0}$, the ``zero vector''. \n        \\item $\\abs{\\alpha\\v{x}} = \\abs{\\alpha}\\abs{\\v{x}}$\n        \\item $\\abs{\\v{x} \\cdot \\v{y}} \\leq \\abs{\\v{x}}\\abs{\\v{y}}$ \n        \\item $\\abs{\\v{x} + \\v{y}} \\leq \\abs{\\v{x}} + \\abs{\\v{y}}$\n        \\item $\\abs{\\v{x} - \\v{z}} \\leq \\abs{\\v{x} - \\v{y}} + \\abs{\\v{y} - \\v{z}}$\n    \\end{enumerate}\n\\end{theorem}\n\\noindent (e) and (f) are often called ``triangle inequalities''; a visual intuition for these inequalities is given in the following figure:\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n    \\draw[black, thick] (0, 0) node[anchor=north] {$\\v{z}$} -- (2, 2) node[anchor=south] {$\\v{y}$}  -- (-2, 2) node[anchor=south] {$\\v{x}$} -- (0, 0);\n    \\draw[] (1.6, 1) node[anchor=north] {$\\abs{\\v{y} - \\v{z}}$};\n    \\draw[] (-1.6, 1) node[anchor=north] {$\\abs{\\v{x} - \\v{z}}$};\n    \\draw[] (0, 2) node[anchor=south]  {$\\abs{\\v{x} - \\v{y}}$};\n    \\end{tikzpicture}\n    \\caption{Visual picture for Theorem \\ref{thm:1.37}(f), drawn in $\\RR^2$. Suppose we started at $\\v{x}$ and wanted the shortest path to $\\v{z}$; we could try walking directly to $\\v{z}$, or we could try walking somewhere else first ($\\v{y}$) and then to $\\v{z}$. However, the theorem tells us that the direct path will always be shorter in Euclidean space.}\n    \\label{fig3}\n\\end{figure}\n\n\\noindent Note that equality in part (f) arises if and only if $\\v{y}$ lies on the line segment between $\\v{x}$ and $\\v{z}$.\n\n\\begin{nproof}\n    (a)-(c) are immediate, and (d) immediately follows from Theorem \\ref{thm:1.35} (Cauchy-Shwartz). For (e), we have that:\n    \\begin{align*}\n        \\abs{\\v{x} + \\v{y}}^2 &= (\\v{x} + \\v{y})(\\v{x} + \\v{y})\n        \\\\ &= \\abs{\\v{x}}^2 + 2\\v{x}\\cdot\\v{y} + \\abs{\\v{y}}^2\n        \\\\ &\\leq \\abs{\\v{x}}^2 + \\abs{2\\v{x}\\cdot\\v{y}} + \\abs{\\v{y}}^2\n        \\\\ &\\leq \\abs{\\v{x}}^2 + 2\\abs{\\v{x}}\\abs{\\v{y}} + \\abs{\\v{y}}^2 \\quad \\text{(1.37(d))}\n        \\\\ &= (\\abs{\\v{x}} + \\abs{\\v{y}})^2\n    \\end{align*}\n    And the claim follows by taking square roots on both sides. For (f), substitute $\\v{x} \\mapsto \\v{x} - \\v{y}$ and $\\v{y} \\mapsto \\v{y} - \\v{z}$ into (e). \\qed\n\\end{nproof}\n\nThough we discuss the Euclidean norm here, it may also be of interest to consider/discuss other norms. One example is the $L_1$ norm (c.f. the norm discussed in Definition \\ref{def:1.36}, which is the $L_2$ norm), which is the sum of the absolute values of each of the components. For $\\v{x} = (x_1, x_2, \\ldots, x_n)$ and $\\v{y} = (y_1, y_2, \\ldots, y_n)$ we have that:\n\\begin{align*}\n    \\abs{\\v{x}}_1 = \\abs{x_1} + \\abs{x_2} + \\ldots + \\abs{x_n}, \\quad \\abs{\\v{x} - \\v{y}}_{1} = \\abs{x_1 - y_1} + \\abs{x_2 - y_2} + \\ldots + \\abs{x_n - y_n}\n\\end{align*}\nThe $L_1$ norm is often called the ``Taxicab norm'' or the ``Manhattan norm'' as the way it quantifies distance is akin to walking in discrete NSEW chunks; much like a taxi running through a grid-like New York City!\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n    \\draw[black, thick] (-3, 0) node[anchor=north] {$(0, 0)$} -- (1, 0) node[anchor=north] {$(x_1, 0)$}  -- (1, 2) node[anchor=south] {$\\v{x} = (x_1, x_2)$} -- (-3, 0);\n    \\draw[] (-1, 0) node[anchor=north] {$\\abs{x_1}$};\n    \\draw[] (1, 1) node[anchor=west] {$\\abs{x_2}$};\n    \\draw[] (-2, 1.2) node[anchor=south]  {$\\abs{\\v{x}}_2 = \\sqrt{x_1^2 + x_2^2}$};\n    \\draw[] (3.5, 1) node {$\\abs{\\v{x}}_{1} = \\abs{x_1} + \\abs{x_2}$};\n    \\end{tikzpicture}\n    \\caption{Visual comparison of the $L_1$ and $L_2$ norms in $\\RR^2$.}\n    \\label{fig4}\n\\end{figure}\n\n\\noindent We are free to generalize this notion to the $L_n$ norm, and we may also define the $L_{\\infty}$ norm, which for $\\v{x} \\in \\RR^n$ is defined as:\n\\begin{align*}\n    \\abs{\\v{x}}_\\infty = \\max_i \\abs{x_i}\n\\end{align*}\nIn general for any $\\v{x} \\in \\RR^n$, we have that $\\abs{x}_1 \\geq \\abs{x}_2 \\geq \\abs{x}_3 \\geq \\ldots \\geq \\abs{x}_\\infty$. We note that we that we can generalize these norms to the cases where we have infinite components:\n\\begin{align*}\n    \\norm{\\v{x}}_p = \\left(\\sum_{i = 1}^\\infty \\abs{x_i}^p\\right)^{1/p} < \\infty \\quad\n    \\|f\\|_{p} \\equiv\\left(\\int_{S}|f|^{p} \\mathrm{~d} \\mu\\right)^{1 / p}<\\infty\n\\end{align*}\nWhich allow us to define norms for function spaces. However, a detailed discussion of these are beyond the scope of this course (to be covered in a later course in functional analysis!) Moreover, we haven't even defined what an infinite sum or integral are yet, which we will get to in later chapters. ", "meta": {"hexsha": "7bc8e55b492e3c2d367b0d3830c678bdf6cb5eb9", "size": 59893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ch1.tex", "max_stars_repo_name": "RioWeil/MATH320-321-Notes", "max_stars_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ch1.tex", "max_issues_repo_name": "RioWeil/MATH320-321-Notes", "max_issues_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-10T23:18:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-25T17:05:30.000Z", "max_forks_repo_path": "Chapters/ch1.tex", "max_forks_repo_name": "RioWeil/MATH320-321-notes", "max_forks_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.0460081191, "max_line_length": 826, "alphanum_fraction": 0.6340807774, "num_tokens": 20318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8633916222765629, "lm_q1q2_score": 0.6891477769123139}}
{"text": "\\section{Group actions on topological spaces}\n  Let us start with reviewing some topology.\n\n  \\subsection{Topological prelimaniraries}\n  A topological spaces $\\calx$ is a set with a collection of open sets.\n  The only facts we need from topology are the following.\n  \\begin{enumerate}\n    \\item For every point $x \\in \\calx$, there is an open set (called a \\emph{neighborhood} of $x$) $U$ containing $x$.\n    \\item For every continuous function $f: \\calx \\rightarrow \\caly$ the inverse $f^{-1}(U)$ of an open set $U$ is open.\n  \\end{enumerate}\n\n  The examples of importance to us come from graphs.\n  From a graph we can form a topological space by taking a point for each vertex $v$ and gluing a segment $[0,1]$ appropriately for each edge.\n\n  \\begin{ex}[Examples of graphs]\n    \\begin{enumerate}\n      \\item $S^1$\n      \\item $[0,n]$\n      \\item\n      \\item\n    \\end{enumerate}\n  \\end{ex}\n\n  A \\emph{space over $\\calx$} is a space $\\caly$ with a continuous map $\\pi_\\caly: \\caly \\rightarrow \\calx$.\n  Denote by $\\cat{Spaces}_\\calx$ the collection of all spaces over $\\calx$.\n  A map lying over $\\calx$ between $\\caly, \\calz \\in \\cat{Spaces}_\\calx$ is a map $f: \\caly \\rightarrow \\calz$ such that the following diagram commutes\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\caly \\arrow[rr,\"f\"] \\arrow[rd,\"\\pi_\\caly\"']\n      &&\n      \\calz \\arrow[ld,\"\\pi_\\calz\"]\\\\\n      & \\calx\n    \\end{tikzcd}.\n  \\end{equation*}\n  For $\\caly \\in \\cat{Spaces}_\\calx$, the \\emph{fiber} over a vertex $v \\in \\calx_0$ is the set $\\pi_\\caly^{-1}(v)$.\n\n  We now come to our first non-trivial definition.\n  \\begin{definition}\n    $\\caly \\in \\cat{Spaces}_\\calx$ is called a \\emph{cover} (or a \\emph{covering space}) of $\\calx$ if every point $y \\in \\caly$ has an open neighborhood $U$ satisfying\n    \\begin{enumerate}\n      \\item $\\pi_\\caly^{-1}(U)$ is homeomorphic to a disjoint union of spaces $\\bigsqcup_{i \\in I} U_i $,\n      \\item $\\pi_\\caly$ restricted to each $U_i$, for $i \\in I$, is a homeomorphism onto $U$.\n    \\end{enumerate}\n    A cover $\\caly$ is a \\emph{finite} cover if the set $I$ is finite for each such $U$.\n  \\end{definition}\n\n\n    \\begin{figure}[H]\n    \\centering\n      \\includegraphics[width=5cm]{example-image}\n      % \\includegraphics[width=]{}\n      \\caption{pancake picture of covering space}\n    \\end{figure}\n\n\n\n\n\n\n\n\n\n\n\n  \\subsection{Group actions}\n  Whenever a group $G$ acts on a set $X$ we can form the set of orbits $\\calG \\backslash X$, and there is a natural projection map\n  \\begin{align*}\n    \\pi: X \\rightarrow G \\backslash X.\n  \\end{align*}\n  We'll use this to produce covering  maps.\n\n  A left group action of $G$ on a space $\\calx$, denoted $G \\groupaction \\calx$, is a collection of continuous maps\n  \\begin{align*}\n    g \\cdot - : X &\\longrightarrow X\\\\\n    x &\\longmapsto gx\n  \\end{align*}\n  satisfying $ex = x$, where $e$ is the identity element in $G$ and $g(hx) = (gh)x$ for all $g,h \\in G$.\n\n  We say that the action of $G$ is \\emph{properly discontinous} if every $x \\in \\calx$ has an open neighborhood $U_x$ such that\n  \\begin{align*}\n    gU_x \\cap hU_x = \\varnothing\n  \\end{align*}\n  for all $g \\neq h \\in G$.\n  We'll call such a neighborhood \\emph{good}. Note that if $U_x$ is a good neighborhood of $x$ and $V \\subseteq U_x$ then $V$ is also good.\n\n  If $G \\groupaction \\calx$ is properly discontinous, then $\\calG \\backslash X$ is a topological space whose underlying set is the set of orbits $\\calG \\backslash X$ and the neighborhood of each point $x$ is the image of a good neighborhood $U_x$ under the quotienting map\n\n\n\n  The covering maps which can be obtained in this manner are called \\emph{Galois coverings} i.e. a covering $\\caly \\rightarrow \\calx$ is called a \\emph{Galois cover} if there is a group $G$ such that $\\calx \\cong \\caly / G$.\n  The \\emph{Galois group}, of a cover $p:Y \\rightarrow X$ is the group of self-maps $q: Y \\rightarrow Y$ lying over $X$\n  \\begin{align*}\n    \\Gal(\\caly|\\calx) = \\{ q: Y \\rightarrow Y : p = q \\circ p \\}.\n  \\end{align*}\n\n  The group $\\Gal(\\caly|\\calx)$ naturally acts on the space $\\caly$, and it fixes the fiber over each $v \\in \\calx_0 $.\n  Because of this $\\Gal(\\caly|\\calx)$ is called the group of \\emph{deck transformations}, as one can think of the action of $\\Gal(\\caly|\\calx)$ on the fibers over $x$ as shuffling a deck of cards.\n\n\tThus there is a homomorphism $\\Gal(\\caly|\\calx) \\rightarrow \\Gal(\\pi^{-1}(v))$, where $\\Gal(\\pi^{-1}(v))$ is the permutation group of the set $\\pi^{-1}(v)$. Turns out, this homomorphism is injective, in fact, a much stronger statement is true.\n\n\t\\begin{theorem}\n\t\tIf $g \\in \\Gal(\\caly|\\calx)$ fixes a point $y \\in Y$ then $g = \\id_{\\caly}$.\n\t\\end{theorem}\n\n\t\\begin{theorem}\n\t\tIf $G$ acts on a graph $\\caly$ and $\\calx = \\caly / G $ then $\\Gal(\\caly|\\calx) \\cong G$.\n\t\\end{theorem}\n\tNote that this determines $G$ completely in terms of the spaces $X$ and $Y$.\n\t\\begin{proof}\n\t\tThere is a natural map $G \\rightarrow \\Gal(\\caly|\\calx)$.\n\t\\end{proof}\n\n  \\begin{theorem}\n    A finite cover $p:Y \\rightarrow X$ is Galois if and only if the Galois group $\\Gal(\\caly|\\calx)$ acts transitively on the fibers $\\pi^{-1}(x)$ for any $x \\in X$.\n  \\end{theorem}\n\n  \\begin{corollary}\n    A finite cover $p: Y \\rightarrow X$ is Galois if and only if $\\abs{\\Gal(\\caly|\\calx)} = \\abs{{p}^{-1}(x)}$.\n  \\end{corollary}\n\n  For a cover $p:Y \\rightarrow X$, we say that a cover $q:Z \\rightarrow X$ lies between $X$ and $Y$ if the map $p$ factors as\n  \\begin{equation*}\n    \\begin{tikzcd}\n      Y \\ar[rd, \"p\"'] \\ar[r,\"p'\"]& Z \\ar[d, \"q\"]\n      \\\\\n      &X\n    \\end{tikzcd}\n  \\end{equation*}\n\n  \\begin{proposition}\n    With the notation as above, $p':Y \\rightarrow Z$ is also a covering map. Further if $p$ is Galois then so is $p'$.\n  \\end{proposition}\n\n  \n", "meta": {"hexsha": "d62040977d02e5ebc726113ffc459320aacad677", "size": 5749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.1.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": "01.1.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": "01.1.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.5851851852, "max_line_length": 272, "alphanum_fraction": 0.6562880501, "num_tokens": 1909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.689147774776218}}
{"text": "% tex file for clustering \n\\par The heart of our analysis consists of different implementations of \nprocedures for multiple comparisons between the 24 subjects. More \nspecifically, we focused on an implementation of the Benjamini-Hochberg \nprocedure, the grouping of t-statistics, and the grouping of $\\hat{\\beta}$ \nvalues. For each of the three cases, we found appropriate parameters to be \nused for all subjects by observing the images from a few subjects at different \npoints of input. The parameters that we played around with include the false \ndiscovery rate, the cutoff value for significant t-values and $\\hat{\\beta}$-\nvalues, and the number of neighbors to use when smoothing data. We also \nconsidered hierarchical clustering. For hierarchical clustering using the \nward metric, we compared different parameter selections for the number of \nclusters.\n\n\\subsubsection{Benjamini-Hochberg Correction}\n\n\\par When conducting multiple comparisons, it is important to have an \nidea of the quantity of Type I errors that may be prevalent in the analysis. \nIn our analysis of the voxel time course data, we decided that limiting and \ncontrolling the number of Type I errors is important to the process of \nidentifying active regions. The processes of limiting the number of Type I \nerrors are called FDR-controlling procedures. In the grand scheme of things, \nFDR-controlling procedures give greater statistical power at the cost of \nproducing more Type I errors.  \n\n\\par Once we coded the hypothesis function that will return t-test \nvalues and ``p-values'', we implemented the Benjamini-Hochberg procedure to \ncontrol the proportion of rejected null hypotheses in the data. The Benjamini-\nHochberg procedure works by multiplying each of the ``p-values'' to a ratio of \nthe number of tests times the rank of the ``p-value'' in the ordered set, \nand the chosen false discovery rate --- from these adjusted ``p-values'', only \nthe values that are less than the chosen false discovery rate will be chosen \nto be returned. This way, we are able to adjust the proportion of null \nhypotheses that will be rejected and the proportion that will return the \ndesired proportion of significant tests. This will reduce the\nnumber of false positives returned in the data and extend greater statistical \npower in later analysis performed on the voxel dataset.\n\n\\par The Benjamini-Hochberg procedure was not the only analysis we performed \nover multiple subjects. After completing grouping of the t-statistics and \n$\\hat{\\beta}$ values. we noticed that the variability between the subjects \nof the study is different between the Benjamini-Hochberg procedure outputs, \nbut that the t-statistics and $\\hat{\\beta}$ value grouping procedure \noutputs. Moreover, when performing the Benjamini-Hochberg procedure, along with\nthe t-statistics grouping procedures, we did play around with smoothing over \nneighboring voxels. Ultimately, however, we decided to forgo the neighbor \nsmoothing to prevent loss of information in the plots that we generated in the \nend, and neighbor smoothing didn't visually appear very needed.\n\n\n\n\\subsubsection{t-Statistics Grouping}\n\n\\par We use the t-statistics that we found earlier for another type of cutoff\nanalysis. The t-statistics measure the size of the difference relative to the \nvariation in the data. Thus, a small ``p-value'' corresponds directly to large\nabsolute values of t-statistics. In fact, the ``p-value'' and the t-statistics\nare related by the following statement: More extreme t-statistics will return \nlower ``p-values'', which increases the chances of the null hypothesis being \nindicated as false. Although the t-statistics go hand in hand with the \nBenjamini-Hochberg analysis on the ``p-values'', we ultimately decided that an \nadditional process of selecting t-statistics based on a threshold was \nnecessary because the ``p-values'' assume a normal distribution while the \nt-statistics do not assume this from the data. It should be noted that the \nt-statistics grouping analysis performed as well, if not better, than the \n``p-value'' analysis using the Benjamini-Hochberg procedure.\n\n\\par Since the magnitude from zero represents how significant the test is for\nt-statistics, we collected the absolute value t-statistics that were above a \ncertain threshold. This was the opposite of the procedure for finding the \nsignificant tests in the Benjamini-Hochberg process. The threshold, also called\nthe cutoff in the scripts that were written when developing this process, is \ncalculated in a very similar fashion to the Benjamini-Hochberg false discovery \nrate. This is because the t-values and the ``p-values'' are strongly linked, in \nfact there is a 1-to-1 relation between the absolute value of t - values to \np-values.\n\n\\par Implementing the t-value grouping function was almost trivial because it \nis the flip side of the Benjamini-Hochberg function that was implemented \npreviously. However, since we do not know if there's a function that relates \nthe absolute values of t-statistics to ``p-values'', there was a lot of \nexperimenting with different values to see which values of cutoff points versus\nfalse discovery rates (the Q value in the Benjamini-Hochberg function) would \ndeliver similarly focused results.\n\n\\subsubsection{$\\hat{\\beta}$ Grouping}\n\n\\par Using the same function that we created to group a certain subset of the \nt-statistics, we also looked over the $\\hat{\\beta}$ values as a part of our \nanalysis. Much of what we know in statistics tells us that observing \n$\\hat{\\beta}$ values on top of looking at t-statistics would not tell us much \nsince the two variables are not explicitly connected; however, the main reason \nwhy we decided it was of utmost importance to look at both the t-statistics \nand the $\\hat{\\beta}$ values is that there might be a relationship between the \ntrends in each respective variables' output to the cutoff point, that is lost\nwhen going from $\\hat{beta}$ to t-statistic (dividing by variance). \n\n\\par Granted, it is pretty clear that the t-statistics grouping is very \ntheoretically similar to the Benjamini-Hochberg procedure. This is why the \n$\\hat{\\beta}$ grouping portion of the analysis was added on. Since $\\hat{\\beta}$ \nvalues do not directly use normality assumptions, we thought it would offer \neither a different angle on how to approach analysis, or confirm the results \nfound in the analysis that depended on the assumptions of normality. \n\n\\subsubsection{Hierarchical Clustering}\n\n\\par Using the across-subject average t-statistics for every voxel in the\nbrain, we are left with a 3-d array of t-statistics that contain both negative\nand positive values. Instead of manually observing patterns in these images, we\ninstead implemented a clustering algorithm to split the entire 3-d images into\nclusters based on the voxels' relative location to each other as well as the\nvalues of their t-statistics.\n\n\\par In order to find a proper clustering algorithm, we decided to treat this\nproblem like a grayscale image segmentation problem and implemented a\nagglomerative hierarchical cluster using Ward's method. Agglomerative means\nthat the clusters are built bottom up with each observation starting as its\nown cluster and pairs being moved up the hierarchy. Ward's method creates\nclusters based on a minimum variance criterion that minimizes the total\nwithin-cluster variances. An example of this implementation for a 2-d image is\nseen here: \n\\url{http://scikit-learn.org/stable/auto_examples/cluster/plot_lena_ward_segmen\ntation.html}.\n\nIn our implementation, we defined a structure to our data using a connectivity\ngraph in order to ensure that each cluster is spatially constrained. Also,\nsince our scenario uses a 3-d image, the connectivity graph will also have to\ntake into account this extra dimension.\n\n\\par Ultimately, we did not use this clustering algorithm in our main paper\nbecause it did not add any useful information on top of our other clustering\nmethods we used. See figure \\ref{fig:cluster_comparison} to see similarities. \nFurthermore, we faced a few\nproblems when trying to implement the algorithm. Most significantly, creating\nthe 3-d connectivity graph was a problem, and we were not able to properly\nimplement this in z-direction. Furthermore, runtime was an issue when compared\nto our other options. Ultimately, the idea around using a hierarchical\nclustering method was intriguing; however, the same results could be achieved\nusing simpler and faster methods.\n\n\n\\subsubsection{Comparison of Clustering Techniques}\nGenerally the clustering techniques for the multiple comparison and the \nhierarchical clustering produces similar results, which can be seen if a \nside by side comparison of the hierarchical clustering method using Ward\nagainst the quantile-based clustering algorithm for t-statistics (we've\nincluded the actual t-values as well in the center for comparisons) \n[Figure \\ref{fig:cluster_comparison}]. Depending upon the subject, the clustering \nfrom Benjamini Hochberg, t grouping and $\\hat{\\beta}$ grouping can be \nvery different or very similar.\n\n\n\n\\begin{figure}[ht]\n\n\t\\centering\n\t\\includegraphics[width=.8\\linewidth]{../images/cluster_comparison.png} \n\t\\caption{Clustering Comparison between WARD, t-statistics, and t-grouping}\n\t\\label{fig:cluster_comparison}\n\n\\end{figure}\n", "meta": {"hexsha": "12e47ee0c17235c7ba51628bc85a2ab92c10c316", "size": 9321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/main_sections/clustering.tex", "max_stars_repo_name": "berkeley-stat159/project-alpha", "max_stars_repo_head_hexsha": "330d025c4eda94d390a82e86deecb791086c9dbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-10-30T23:08:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T03:44:02.000Z", "max_issues_repo_path": "paper/main_sections/clustering.tex", "max_issues_repo_name": "berkeley-stat159/project-alpha", "max_issues_repo_head_hexsha": "330d025c4eda94d390a82e86deecb791086c9dbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 179, "max_issues_repo_issues_event_min_datetime": "2015-10-25T15:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-31T02:40:24.000Z", "max_forks_repo_path": "paper/main_sections/clustering.tex", "max_forks_repo_name": "berkeley-stat159/project-alpha", "max_forks_repo_head_hexsha": "330d025c4eda94d390a82e86deecb791086c9dbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2015-10-20T19:15:10.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-23T19:33:03.000Z", "avg_line_length": 57.537037037, "max_line_length": 82, "alphanum_fraction": 0.7993777492, "num_tokens": 2003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6891477629475146}}
{"text": "\\section{Background and objectives of the thesis}\n\n\\section{Notations}\n\\begin{flushleft}\n\\begin{tabular}{l l}\n\n$t \\in \\mathbb{Q}$ & Discrete or continuos time\\\\\n$D \\in \\mathbb{N}$ & Space dimension\\\\\n$P \\in \\mathbb{N}$ & Number of variables: univariate, multivariate\\\\\n$S \\in \\mathbb{N}$ & Number of sensors\\\\\n$x_t \\in \\mathbb{R}^{D\\times P}$ & Matrix representing state $x$ at time $t$\\\\\n$z_t \\in \\mathbb{R}^S$  & Vector of measurement $z$ at time $t$\\\\\n$u_t \\in \\mathbb{R}$ & Action $u$ at time $t$\\\\\n$\\hat z: \\mathbb{R}^{D\\times P}  \\rightarrow \\mathbb{R}^S $ & Function that predicts sensor measurements given a state\\\\\n$\\hat x_t \\in \\mathbb{R}^{D\\times P}$ & Matrix representing predicted state $\\hat x$ at time $t$\\\\\n$\\hat x_t^* \\in \\mathbb{R}^{D\\times P}$ & Matrix representing best predicted state $\\hat x$ at time $t$\\\\\n$\\theta_t \\in \\mathbb{R}$ & Angle of orientation at time $t$\\\\\n$bel(x_t)$ & Belief of state $x$ at time $t$\\\\\n$\\overline{bel}(x_t)$ & Prediction belief of state $x$ at time $t$\\\\\n$p(x)$ & Probability of continuous or discrete random variable $x$\\\\\n$p(x | y)$ & Conditional probability of $x$ given $y$\\\\\n$x_{1:t}$ & Sequence containing $\\{x_1, x_2, ..., x_t\\}$\\\\ \n$M$ & Number of Particles used in the Particles Filter\\\\\n$x_t^{[m]}$ & State $x$ at time $t$ of particle $m$\\\\\n$a \\approx b$ & $a$ is approximately equal to $b$\\\\\n$a \\sim b$ & $a$ is similar to $b$\\\\\n$a \\propto b$ & $a$ is proportional to $b$\\\\\n\\end{tabular}\n\\end{flushleft}\n\n\\section{Abbreviations}\n\\begin{flushleft}\n\\begin{tabular}{l l}\nEPFL & Swiss Federal Institute of Technology in Lausanne\\\\\nROS & Robot Operative System\\\\\n3D & Three-Dimensional\\\\\nDOF & Degrees Of Freedom\\\\\npdf & Probability Density Function\\\\\nKF & Kalman Filter\\\\\nPF & Particles Filter\\\\\nEKF & Extended Kalman Filter\\\\\nMCKF & Maximum Correntropy Kalman Filter\\\\\nMMSE & Minimum Mean Square Error\\\\\nMCC & Maximum Correntropy Criterion\\\\\nIEKF & Invariant Extended Kalman Filter\\\\\nPCC & Pearson Correlation Coefficient\\\\\nPPF & Pearson Particles Filter\\\\\nGPU & Grafical Processing Unit\\\\\nGPGPU & General Purpose Graphical Processing Unit\\\\\nMCL & Monte Carlo localization\\\\\nSLAM & Simultaneous Localization And Mapping Problem\\\\\nDP & Differentiable Programming\\\\\nDPFs & Differentiable Particle Filters\\\\\nPF-net & Particle Filter Network\\\\\nHF & Histogram Filter\\\\\nDMN & Differentiable Mapping Network\\\\\nDPFRL & Discriminative Particle Filter Reinforcement Learning\\\\\nDVRL & Deep Variational Reinforcement Learning \\\\\nGRU & Gated Recurrent Unit \\\\\nRNN & Recurrent Neural Networks\\\\\nPF-RNN & Particles Filter Recurrent Neural Networks\\\\\n\n\\end{tabular}\n\\end{flushleft}\n\n", "meta": {"hexsha": "4b92537d2ef420ac7b31923615222e0c225b31ae", "size": 2628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/thesis-doc/chapters/introduction.tex", "max_stars_repo_name": "qiuwenhui/webots-thesis", "max_stars_repo_head_hexsha": "9f49928aae755fb89d5fc884927de6593d5e122c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-17T22:19:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-17T22:19:35.000Z", "max_issues_repo_path": "documents/thesis-doc/chapters/introduction.tex", "max_issues_repo_name": "qiuwenhui/webots-thesis", "max_issues_repo_head_hexsha": "9f49928aae755fb89d5fc884927de6593d5e122c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-11-13T18:48:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-25T16:05:09.000Z", "max_forks_repo_path": "documents/thesis-doc/chapters/introduction.tex", "max_forks_repo_name": "qiuwenhui/webots-thesis", "max_forks_repo_head_hexsha": "9f49928aae755fb89d5fc884927de6593d5e122c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-25T21:07:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-25T21:07:09.000Z", "avg_line_length": 39.8181818182, "max_line_length": 120, "alphanum_fraction": 0.700913242, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.689147757942072}}
{"text": "\n\\documentclass[openany,11pt]{homework}\n\n\\coursename{ELEN 4903 Machine Learning (Spring 2018)} % DON'T CHANGE THIS\n\n\\studname{Pratyus Pati}    % YOUR NAME GOES HERE\n\\studmail{pp2636@columbia.edu}% YOUR UNI GOES HERE\n\\hwNo{1}                   % THE HOMEWORK NUMBER GOES HERE\n\n% Uncomment the next line if you want to use \\includegraphics.\n\\usepackage{graphicx}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 1(a)}\n\nGiven:\n\\begin{equation}\nx_i \\in \\{0, 1\\}\n\\end{equation}\nEvery random variable is taken from a Bernoulli's distribution\n\\begin{equation}\np(x_i\\mid\\pi) = \\pi^{x_i}(1-\\pi)^{1-x_i}, \\pi \\in [0, 1]\n\\end{equation}\nTo find:\\\\\nJoint distribution of the data:\n$$\np(x_1, x_2, ..., x_n \\mid \\pi)\n$$\nSince each random variable is I.I.D,\n\\begin{align}\n\tp(x_1, x_2, ..., x_n \\mid \\pi) & = \\prod_{i = 1}^{n} p(x_i \\mid \\pi) \\\\\n\t\t\t\t\t\t\t\t   & = \\prod_{i = 1}^{n} \\pi^{x_i}(1-\\pi)^{1-x_i} \\\\\n\t\t\t\t\t\t\t\t   & = \\pi^{\\sum_{i=1}^{n} x_i}(1-\\pi)^{(n-\\sum_{i=1}^{n} x_i)}\n\\end{align}\nLet $\\mu = (\\sum_{i=1}^{n} x_i)/ n$ In which case, \\\\\n$$\np(x_1, x_2, ..., x_n \\mid \\pi) = \\pi^{n\\mu}(1-\\pi)^{n-n\\mu}\n$$\n\n\\section*{Problem 1(b)}\n\n\\begin{align}\n\\hat{\\pi}_{ML} & = \\operatornamewithlimits{arg\\,max}_{\\pi} p(x_1, x_2, ..., x_n \\mid \\pi) \\\\\n\t\t\t   & = \\operatornamewithlimits{arg\\,max}_{\\pi} \\pi^{n\\mu}(1-\\pi)^{n-n\\mu} \\\\\n\t\t\t   & = \\operatornamewithlimits{arg\\,max}_{\\pi} \\ln(\\pi^{n\\mu}(1-\\pi)^{n-n\\mu}) \\\\\n\t\t\t   & = \\operatornamewithlimits{arg\\,max}_{\\pi} [(n\\mu) (\\ln \\pi)] + [(n - n\\mu)(\\ln (1-\\pi))]\n\\end{align}\n\nOn taking the derivative w.r.t. $\\pi$\\\\\n\\begin{align}\n\\frac{\\partial }{\\partial \\pi} [(n\\mu) (\\ln \\pi)] + [(n - n\\mu)(\\ln (1-\\pi))]\n& = \\left[n\\mu \\frac{\\partial \\ln \\pi}{\\partial \\pi}\\right] + \\left[(n - n\\mu)\\left(\\frac{\\partial \\ln(1-\\pi)}{\\partial \\pi}\\right)\\right] \\\\\n& = \\frac{n\\mu}{\\pi} -\\frac{n-n\\mu}{1-\\pi}\n\\end{align}\n\nOn setting the partial derivative w.r.t $\\pi$ as 0 to get $\\hat{\\pi}_{ML}$,\n\\begin{align}\n\\frac{n\\mu}{\\hat{\\pi}_{ML}} -\\frac{n-n\\mu}{1-\\hat{\\pi}_{ML}} & = 0 \\\\\n\\Rightarrow n\\mu(1-\\hat{\\pi}_{ML}) - (n-n\\mu)(\\hat{\\pi}_{ML}) & = 0 \\\\\n\\Rightarrow n\\mu - n\\mu\\hat{\\pi}_{ML} - n\\hat{\\pi}_{ML} + n\\mu\\hat{\\pi}_{ML} & = 0 \\\\\n\\Rightarrow n\\mu - n\\hat{\\pi}_{ML} & = 0 \\\\\n\\Rightarrow \\hat{\\pi}_{ML} & = \\mu = \\frac{\\sum_{i=1}^{n} x_i}{n}\n\\end{align}\n\n\\section*{Problem 1(c)}\n\n\\[\np(\\pi) = beta(a, b) = \\frac{\\pi^{a-1}(1-\\pi)^{b-1}}{B(a, b)}\n\\]\n\n\\begin{align}\np(\\pi \\mid x_1, x_2, ..., x_n) & = \\frac{p(x_1, x_2, ..., x_n \\mid \\pi)p(\\pi)}{p(x_1, x_2, ..., x_n)} \\\\\n\t\t\t\t\t\t\t   & = \\frac{\\pi^{n\\mu}(1-\\pi)^{n-n\\mu}\\pi^{a-1}(1-\\pi)^{b-1}}{B(a, b)p(x_1, x_2, ..., x_n)} \\\\\n\t\t\t\t\t\t\t   & = \\frac{\\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}}{B(a, b)p(x_1, x_2, ..., x_n)}\n\\end{align}\n\n\\begin{align}\n\\hat{\\pi}_{MAP} & = \\operatornamewithlimits{arg\\,max}_{\\pi} p(\\pi \\mid x_1, x_2, ..., x_n) \\\\\n& = \\operatornamewithlimits{arg\\,max}_{\\pi} \\frac{\\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}}{B(a, b)p(x_1, x_2, ..., x_n)} \\\\\n& = \\operatornamewithlimits{arg\\,max}_{\\pi} \\left[\\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}\\right] \\\\\n& = \\operatornamewithlimits{arg\\,max}_{\\pi} \\left[\\ln(\\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1})\\right]\t\\\\\n& = \\operatornamewithlimits{arg\\,max}_{\\pi} \\left[(n\\mu+a-1)\\ln\\pi + (n-n\\mu+b-1)\\ln(1-\\pi)\\right] \\\\\n\\end{align}\n\nOn taking the derivative w.r.t. $\\pi$\n\\begin{align}\n& \\frac{\\partial }{\\partial \\pi} \\left[(n\\mu+a-1)\\ln\\pi + (n-n\\mu+b-1)\\ln(1-\\pi)\\right] \\\\\n= & \\left[(n\\mu+a-1) \\frac{\\partial \\ln \\pi}{\\partial \\pi}\\right] + \\left[(n-n\\mu+b-1)\\left(\\frac{\\partial \\ln(1-\\pi)}{\\partial \\pi}\\right)\\right] \\\\\n& = \\frac{n\\mu+a-1}{\\pi} -\\frac{n-n\\mu+b-1}{1-\\pi}\n\\end{align}\n\nOn setting the partial derivative w.r.t $\\pi$ as 0 to get $\\hat{\\pi}_{MAP}$,\n\\begin{align}\n\\frac{n\\mu+a-1}{\\hat{\\pi}_{MAP}} -\\frac{n-n\\mu+b-1}{1-\\hat{\\pi}_{MAP}} & = 0 \\\\\n\\Rightarrow (n\\mu+a-1)(1-\\hat{\\pi}_{MAP}) - (n-n\\mu+b-1)(\\hat{\\pi}_{MAP}) & = 0 \\\\\n\\Rightarrow (n\\mu + a - 1) - (n\\mu + a - 1 + n - n\\mu + b - 1)\\hat{\\pi}_{MAP} & = 0 \\\\\n\\Rightarrow (n\\mu + a - 1) - (n + a + b - 2)\\hat{\\pi}_{MAP} & = 0 \\\\\n\\Rightarrow \\hat{\\pi}_{MAP} & = \\frac{n\\mu + a - 1}{n + a + b - 2} \\\\\n\t\t\t\t\t\t\t& = \\frac{n\\sum_{i=1}^{n} x_i + a - 1}{n + a + b - 2}\n\\end{align}\n\n\\section*{Problem 1(d)}\n\n\\begin{align}\np(\\pi \\mid x_1, x_2, ..., x_n) & = \\frac{p(x_1, x_2, ..., x_n \\mid \\pi)p(\\pi)}{p(x_1, x_2, ..., x_n)} \\\\\n& = \\frac{\\pi^{n\\mu}(1-\\pi)^{n-n\\mu}\\pi^{a-1}(1-\\pi)^{b-1}}{B(a, b)p(x_1, x_2, ..., x_n)} \\\\\n& = \\frac{\\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}}{B(a, b)p(x_1, x_2, ..., x_n)} \\\\\n& \\propto \\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}\t\t\t\t\\\\\n\\end{align}\n\nTherefore, the posterior probability is proportional to the $beta$ distribution. We can convert the proportionality to an equality by adding the correct co-efficient to form the $beta$ distribution\n\n\\begin{align}\np(\\pi \\mid x_1, x_2, ..., x_n) & \\propto \\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}\\\\\n& = \\frac{\\pi^{n\\mu+a-1}(1-\\pi)^{n-n\\mu+b-1}}{B(a + n\\mu, b + n-n\\mu)} \\\\\n& = beta(a + n\\mu, b + n-n\\mu)\n\\end{align}\n\n\\section*{Problem 1(e)}\nThe mean of the distribution $beta(a, b)$ is given by $\\frac{a}{a+b}$ \\\\\nTherefore, \\\\\n\\begin{align}\n\\mathbb{E}[\\pi_{post}] & = \\frac{a + n\\mu}{b + n - n\\mu + a + n\\mu} \\\\\n\t\t\t\t& = \\frac{a + n\\mu}{a + b + n} \\\\\n\t\t\t\t& = \\frac{a}{a+b+n} + \\mu\\frac{n}{a+b+n} \\\\\n\t\t\t\t& = \\frac{a}{a+b}\\frac{a+b}{a+b+n} + \\mu\\frac{n}{a+b+n} \\\\\n\\end{align}\nThis can be represented as:\n\\begin{align}\n\\mathbb{E}[\\pi_{post}] & = \\alpha\\mathbb{E}[\\pi_{prior}] + (1-\\alpha)\\hat{\\pi}_{ML}\n\\end{align}\nThis proves that $\\mathbb{E}[\\pi_{post}]$ is a weighted average of $\\mathbb{E}[\\pi_{prior}]$ and $\\hat{\\pi}_{ML}$,where $\\alpha = \\frac{a+b}{a+b+n}$ that tends to 0 as n increases. Therefore, we can say:\n\\begin{align}\n\\lim_{n\\to\\infty}\\mathbb{E}[\\pi_{post}] & = \\hat{\\pi}_{ML}\n\\end{align}\n\nAlso, for relating $\\mathbb{E}[\\pi_{post}]$ and $\\hat{\\pi}_{MAP}$,\n\\begin{align}\n\t\\mathbb{E}[\\pi_{post}] & = \\frac{a + n\\mu}{a+b+n} \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t & = \\frac{a + n\\mu -1+1}{a+b+n} \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t & = \\frac{a+n\\mu-1}{a+b+n} + \\frac{1}{a+b+n} \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t & = \\frac{a+n\\mu-1}{a+b+n-2}\\frac{a+b+n-2}{a+b+n} + \\frac{1}{2}\\left(1-\\frac{a+b+n-2}{a+b+n}\\right)\n\\end{align}\n\nThis can be represented as:\n\\begin{align}\n\\mathbb{E}[\\pi_{post}] & = \\alpha\\hat{\\pi}_{MAP} + (1-\\alpha)(0.5)\n\\end{align}\n\nThis proves that $\\mathbb{E}[\\pi_{post}]$ lies between $\\hat{\\pi}_{MAP}$ and $0.5$, and approaches $\\hat{\\pi}_{MAP}$ as $n \\to \\infty$.\n\nThe variance of the distribution $beta(a, b)$ is given by $\\frac{ab}{(a+b)^2(a+b+1)}$ \\\\\nTherefore, \\\\\n\\begin{align}\nvar[\\pi_{post}] & = \\frac{(a + n\\mu)(b + n - n\\mu)}{(b + n - n\\mu + a + n\\mu)^2(b + n - n\\mu + a + n\\mu +1)} \\\\\n& = \\frac{(a + n\\mu)(b + n - n\\mu)}{(a + b + n)^2(a + b + n+1)}\n\\end{align}\nFor relating it with the mean, the variance can be further represented as:\n\\begin{align}\n\tvar[\\pi_{post}] & = \\left(\\frac{1}{a+b+n+1}\\right)\\left(\\frac{a+n\\mu}{a+b+n}\\right)\\left(1-\\frac{a+n\\mu}{a+b+n}\\right) \\\\\n\t& = \\left(\\frac{1}{a+b+n+1}\\right)\\left(\\mathbb{E}[\\pi_{post}]\\right)\\left(1-\\mathbb{E}[\\pi_{post}]\\right)\n\\end{align}\nFrom this relation, we can see that $var[\\hat{\\pi}_{MAP}]$ is a quadratic funtion of $\\mathbb{E}[\\pi_{post}]$ and exists for the range $\\mathbb{E}[\\pi_{post}] \\in [0, 1]$, 0 at $\\mathbb{E}[\\pi_{post}] \\in \\{0, 1\\}$ and achieves its maximum at $\\mathbb{E}[\\pi_{post}] = 0.5$\n\\\\\n\\\\\nFrom the above results, we can see how $var[\\pi_{post}]$ varies with respect $\\mathbb{E}[\\pi_{post}]$ due to changes in $\\hat{\\pi}_{ML}$ and $\\hat{\\pi}_{MAP}$. Also, as $n \\to \\infty$, $\\mathbb{E}[\\pi_{post}]$, $\\hat{\\pi}_{MAP}$ and $\\hat{\\pi}_{ML}$ converge.\n\n\n\n\\section*{Problem 2(a)}\n\\begin{figure}[h]\n\t\\includegraphics[width=\\textwidth]{wrr_vs_dfl}\n\t\\caption{Ridge Regression Weights vs. Degrees of Freedom $df(\\lambda)$}\n\\end{figure}\n\n\\section*{Problem 2(b)}\nFrom the figure plotting the relationship between $w_i$ and $df(\\lambda)$, it can be seen that there are two coefficients $w_3$ and $w_5$ that exhibit large magnitudes for normal least square condition. On decreasing the degrees of freedom ($df(\\lambda)$) by increasing $\\lambda$, these coefficients gradually converge towards 0.\n\\\\\n\\\\\nThese coefficients can either be uncorrelated values whose magnitudes signify their respective importance in calculating the predicted value. $w_5$ is positively correlated with the value of $\\hat{y}$, and therefore, $\\hat{y}$ increases as the $6^{th}$ feature increases. $w_3$ is negatively correlated with $\\hat{y}$, and therefore $\\hat{y}$ decreases as $4^{th}$ feature decreases.\n\\\\\n\\\\\nAlternatively, $4^{th}$ and $6^{th}$ features are correlated and as a result, $w_{LS}$ is poorely determined, with high variance. Ridge regression helps in decreasing the variance of such weights by restraining it around 0.\n\n\\section*{Problem 2(c)}\n\\begin{figure}[h]\n\t\\includegraphics[width=\\textwidth]{MSE_vs_lambda}\n\t\\caption{Mean Square Error vs. $\\lambda$}\n\\end{figure}\n\nFrom the figure, it can be seen that as $\\lambda$ increases, the Mean Square Error increases accordingly. In this case, trying to decrease the variance by increasing $\\lambda$, introduces too much bias into the model. In such a case, we would like to keep $\\lambda$ as low as possible to reduce the bias.\n\n\\section*{Problem 2(d)}\n\\begin{figure}[h]\n\t\\includegraphics[width=\\textwidth]{RMSE_vs_lambda_p}\n\t\\caption{Root Mean Square Error vs. $\\lambda$ for differernt values of $p$}\n\\end{figure}\n\nWe can see that as we add more $p^{th}$ order terms, the RMSE decrease. Also for p = 2 and 3, there is a clear local minima of the RMSE with respect to the $\\lambda$. Hence, we can set $\\lambda$ to the minumum value, and use the Occam's Razor heuristic to select p as 2 to create the simplest possible model that decreases the RMSE.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "85dde3e5a3ca0f39a6856cd3f0086437d41eafc4", "size": 9662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW1/MLHW/theory.tex", "max_stars_repo_name": "prtyspt/ml-course", "max_stars_repo_head_hexsha": "8c8dbc446977b5ec635f3a808878ef56710362da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T17:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:34:02.000Z", "max_issues_repo_path": "HW1/MLHW/theory.tex", "max_issues_repo_name": "Hubert51/ml-course", "max_issues_repo_head_hexsha": "8c8dbc446977b5ec635f3a808878ef56710362da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW1/MLHW/theory.tex", "max_forks_repo_name": "Hubert51/ml-course", "max_forks_repo_head_hexsha": "8c8dbc446977b5ec635f3a808878ef56710362da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-20T06:12:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-20T06:12:13.000Z", "avg_line_length": 46.9029126214, "max_line_length": 383, "alphanum_fraction": 0.5987373215, "num_tokens": 3801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.6890716702037892}}
{"text": "\\section{Number Theory}\n\\begin{code}{Extended Euclid}{$\\mathcal{O}(\\log(a + b))$}{math/extendedEuclid.cc} \n  Calculates $a$ and $b$ such that $\\gcd(x, y) = ax + by$\n\\end{code}\n\n\\lst{Modular Exponentiation}{$\\mathcal{O}(\\log b)$}{math/modpow.cc}\n\n\\begin{code}{Eulers Totoid Function}{$\\mathcal{O}(\\sqrt{n})$}{math/totoid.cc}\n%TODO(Alex): Improve this -> better(more) details/ what is important, applications\n$\\phi(n)$: Number of Integers in $[1, n]$ that are coprime to $n$.\\\\\n$p \\text{ prime}, k \\in \\mathbb{N} \\Rightarrow \\phi(p^k) = p^k - p^{k-1}$ \\\\\n$a, b \\text{ coprime} \\Rightarrow \\phi(a \\cdot b) = \\phi(a) \\cdot \\phi(b)$ \\\\\n$a, b \\in \\mathbb{N} \\Rightarrow \\phi(a \\cdot b) = \\phi(a) \\cdot \\phi(b) \\cdot \\frac{gcd(a, b)}{\\phi(gcd(a,b))}$ \\\\\n$P \\text{ prime factors of } n \\Rightarrow \\phi(n) = n \\cdot \\prod_{p \\in P} (1 - \\frac{1}{p})$\n\\end{code}\n", "meta": {"hexsha": "de60acea87f929d3c1d61dee1a4231df7996e3c5", "size": 854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/numberTheory.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/numberTheory.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/numberTheory.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": 53.375, "max_line_length": 115, "alphanum_fraction": 0.6194379391, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6890276385364461}}
{"text": "\\newpage\n\\section{Systems of Ordinary Differential Equations}\n\\subsection{}\nSystems of ordinary differential equations have 1 dependent variable and 1 independent variable. Let's look at an example.\n\n\\begin{eg}\n  Here is a system of 3 first order ordinary differential equations of dimension 3 \n  \\begin{align*}\n    x'&=4x-7y+z^2\\\\\n    y'&=2t-e^{t}y-z\\\\\n    z'&=z^2+y^2-yx\n  .\\end{align*}\n\\end{eg}\n\nWe can also turn higher order ODE's into systems of first-order ODEs.\n\\begin{eg}\n  Consider the equation $x''+7x''+7tx'+6x=t^2$. If we let $y=x',z=x''=y',x'''=z'$, then using the ODE,\n  \\[\n  z'=t^2-6x+7ty-7z\n  ,\\]\n  we can make a system of nonlinear, nonautonomous, nonhomogeneous ordinary differential equations.\\footnote{After this system we went to chapter 2.6}\n  \\begin{align*}\n    x'&=y\\\\\n    y'&=z\\\\\n    z'&=t^2-6x+ty-7z\n  .\\end{align*}\n\\subsection{Matrix Algebra}\nA matrix is a rectangular array of numbers. \n\\begin{eg}\n  Consider $A=\\begin{pmatrix} 2&3&1\\\\4&5&0 \\end{pmatrix} $. $A$ has 2 rows and 3 columns, so its size is $2\\times 3$. The $a_{ij}$ is an entry in $A$'s $i^{th}$ row and $j^{th}$ column.\n\\end{eg}\n\\begin{eg}\n  Consider $B=\\begin{pmatrix} 5&0&0\\\\0&-1&0\\\\0&0&3 \\end{pmatrix} $, which is a $3\\times 3$ matrix. This is also a square matrix, due to the size. $B$ is also a diagonal matrix, because it's only nonzero entries are on the main diagonals.\n\\end{eg}\nAn upper triangular matrix looks like \n\\[\n  \\begin{pmatrix} 5&2&0\\\\0&-1&3\\\\0&0&3 \\end{pmatrix} \n.\\] \nA lower triangular matrix looks like\n\\[\n  \\begin{pmatrix} 5&0&0\\\\ \\pi&-1&0\\\\-1&-\\frac{1}{2}&3 \\end{pmatrix} \n.\\] \n\\end{eg}\nWe can add and subtract matrices element-wise, but only if the matrices have the same size. We can also multiply a matrix by a scalar\n\\[\n  3\\begin{pmatrix} 4&5\\\\6&7 \\end{pmatrix} =\\begin{pmatrix} 12&15\\\\18&21 \\end{pmatrix} \n.\\] \nA row vector is $\\begin{pmatrix} 2&3&1 \\end{pmatrix} $, in this case the size would be $1\\times 3$. A column vector looks like $\\begin{pmatrix} 2\\\\3\\\\1 \\end{pmatrix} $ with the size $3\\times 1$. The zero vector is of size $n\\times n$, and has $0$ in every index in the matrix. The transpose of a matrix reverses all of the columns and rows. Consider\n\\[\n  \\begin{pmatrix} 2&3&1\\\\4&5&6 \\end{pmatrix} ^{T}=\\begin{pmatrix} 2&4\\\\3&5\\\\1&6 \\end{pmatrix} \n.\\] \nHere are the properties of a transpose:\n\\begin{itemize}\n  \\item $\\left( A^{T} \\right)^{T}=A $\n  \\item $\\left( A+B \\right) ^{T}=A^{T}+B^{T}$\n  \\item $(kA)^{T}=kA^{T}$\n  \\item $\\left( AB \\right) ^{T}=B^{T}A^{T}$\n\\end{itemize}\nNow we are going to start talking about matrix multiplication. Matrix multiplication is like the dot product. The $(i,j)^{th}$ entry of $AB$ is the dot product of the $i^{th}$ row of $A$ w/ $j^{th}$ column of $B$. Consider the following\n\\[\n  \\begin{pmatrix} 1&2&3 \\end{pmatrix} \\begin{pmatrix} 4\\\\5\\\\6 \\end{pmatrix} =(1\\times 4)+(2\\times 5)+(3\\times 6)= 32\n.\\] \nIn order to do matrix multiplication, rows of $A$ must match the columns of $B$ and vice versa. Matrix multiplication is not commutative. \n\\begin{eg}\n  If we let $A=\\begin{pmatrix} 1&4\\\\5&10\\\\8&12 \\end{pmatrix}$ and $B=\\begin{pmatrix} -4&7&-3\\\\1&-3&2 \\end{pmatrix} $. Does $AB=BA$? This is not true, because matrices are equal if and only if all entries are equal. If we just multiply $BA$, we get \\[\n  \\begin{pmatrix} -4&7&-3\\\\1&-3&2 \\end{pmatrix}\\begin{pmatrix} 1&4\\\\5&10\\\\7&12 \\end{pmatrix}  = \\begin{pmatrix}2&8\\\\2&-2\\end{pmatrix} \n  .\\] \n\\end{eg}\nHere are some properties of matrices. \n\\begin{note}\n  We must maintain the order from left to right.\n\\end{note}\n\\begin{itemize}\n  \\item $A(B+C)=AB+BC$\n  \\item $(A+B)C=AC+BC$\n  \\item $k(AB)=(kA)B=A(kB)$\n  \\item $ABC=(AB)C=A(BC)$\n\\end{itemize}\nThe identity matrix is a square diagonal matrix with ones on the diagonal. For example, the identity matrix of dimension 3 and 4 are the following \n\\begin{align*}\n  I_3&=\\begin{pmatrix} 1&0&0\\\\0&1&0\\\\0&0&1 \\end{pmatrix} \\\\\n  I_4&=\\begin{pmatrix} 1&0&0&0\\\\0&1&0&0\\\\0&0&1&0\\\\0&0&0&1 \\end{pmatrix} \n.\\end{align*}\nWith the identity matrix, if we multiply any matrix by the identity matrix, then we get the same answer. Back in lesson 2, we were given the general solution to a Cauchy-Euler ordinary differential equation as \\[\n  x(t)=C_1(1)+C_2t^3+C_3 \\frac{1}{t^2}\n.\\] Let's find a particular solution satisfying $x(1)=2,x'(1)=4,x'(1)=0$. We can do this by taking the derivative and second derivative of our functions to get \n\\begin{align*}\n  x'(t)=3C_2t^2-2C_3t ^{-3}\\\\\n  x''(t)=6C_2t+6C_3t ^{-4}\n.\\end{align*}\nNow using our initial conditions\n\\begin{align*}\n  x(1)=C_1+C_2+C_3=2\\\\\n  x'(1)=3C_2-2C_3=4\\\\\n  x''(1)=6C_2+6C_3=0\n.\\end{align*}\nWe can rewrite this in matrix form as \\[\n  \\begin{pmatrix} 1&1&1\\\\0&3&-2\\\\0&6&6 \\end{pmatrix} \\begin{pmatrix} C_1\\\\C_2\\\\C_3 \\end{pmatrix} =\\begin{pmatrix} 2\\\\4\\\\0 \\end{pmatrix} \n.\\] We will call the first matrix, $A$, the second matrix, $\\vec{x}$, and the third matrix, $\\vec{b}$, so we must solve $A\\vec{x}=\\vec{b}$ for $\\vec{x}$. We can solve this by doing the following techniques\n\\begin{enumerate}\n  \\item Cramer's Rule (See book appendix)\n  \\item Gaussian elimination\n  \\item (Left)-multiply by $A^{-1}$\n  \\item MATLAB: rref or $A / B$\n\\end{enumerate}\n\n\\begin{theorem}\n  This is the invertible matrix theorem. If $A$ is square, either all of case 1 or all of case 2 statements are true. Either $A$ is non-singular [good] or $A$ is singular [bad]. \\newline Considering case 1\n  \\begin{itemize}\n    \\item $det(A)\\neq 0$\n    \\item $A\\vec{x}=\\vec{b}$ has exactly one solution $\\vec{x}$ for each $\\vec{b}$.\n    \\item $A\\vec{x}=\\vec{0}$ has only the trivial solution, $\\vec{x}=\\vec{0}$.\n    \\item The rows (and columns) are linearly independent.\n    \\item $A^{-1}$ exists.\n  \\end{itemize}\n  Considering Case 2\n  \\begin{itemize}\n    \\item $det(A)=0$\n    \\item $A\\vec{x}=\\vec{b}$ has zero or infinite solutions\n    \\item $A\\vec{x}=\\vec{0}$ has infinite solutions.\n    \\item The rows (and columns) are linearly dependent.\n    \\item $A^{-1}$ does not exist.\n  \\end{itemize}\n\\end{theorem}\n$A^{-1}$ is a square matrix such that \\[\nA^{-1}A=A A^{-1}=I\n.\\] We find $A^{-1}$ through the following methods\n\\begin{enumerate}\n  \\item $rref(A|I)\\to(I|A^{-1})$\n  \\item $A^{-1}=\\frac{1}{det(A)}\\cdot adj(A)$ where $adj(A)$ is the transpose of the cofactor matrix.\n\\end{enumerate}\nHow do we use $A^{-1}$? Given $A\\vec{x}=\\vec{b}$, we must solve for $x$. In order to do this, we left multiply by $A^{-1}$ to get \n\\begin{align*}\n  A^{-1}A\\vec{x}&=A^{-1}\\vec{b}\\\\\n  I\\vec{x}&=A^{-1}\\vec{b}\\\\\n  \\vec{x}=A^{-1}\\vec{b}\n.\\end{align*}\nIf given a general $2\\times 2$ matrix, $A=\\begin{pmatrix} a&b\\\\c&d \\end{pmatrix} $, we can find the inverse by doing \n\\begin{align*}\n  A^{-1}&=\\frac{1}{ad-bc}\\begin{pmatrix} d&-c\\\\-b&a \\end{pmatrix} ^{T}\\\\\n        &=\\frac{1}{ad-bc}\\begin{pmatrix} d&-b\\\\-c&a \\end{pmatrix} \n.\\end{align*}\nThe trace of $A$ ($trace(A)$) is the sum along the diagonal.\n\\newline\nLet's write a linear system of first order differential equations in matrix form. If the equation is not first order, use Sect (4.1) technique to turn into 1st order system.\n\\begin{eg}\n  Consider the following system \n  \\begin{align*}\n    x'&=x-y+z\\\\\n    y'&=4x+y-5z+7\\\\\n    z'&=7x-8y-9z\n  .\\end{align*}\n  The $+7$ in the second equation makes this a nonhomogeneous ordinary differential equation with constant coefficients. We can rewrite this as $\\vec{x}'(t)=A(t)\\vec{x}+\\vec{b}(t)$, where $\\vec{x}(t)=$ a vector of dependent variables. In order to do this, let $\\vec{x}(t)=\\begin{bmatrix} x(t)\\\\y(t)\\\\z(t) \\end{bmatrix} $. Using the equation from before, we can set \\[\n  \\begin{bmatrix} x'\\\\y'\\\\z'\\\\ \\end{bmatrix} =\\begin{bmatrix} 1&-1&1\\\\4&1&-5\\\\7&-8&-9 \\end{bmatrix} +\\begin{bmatrix} 0\\\\7\\\\0 \\end{bmatrix} \n.\\] We can notice that all of our nonhomogeneous terms get moved into the $\\vec{b}(t)$ matrix.\n\\begin{note}\n  We might have $\\begin{bmatrix} c \\end{bmatrix} \\vec{x}'=A\\vec{x}+\\vec{b}$. From here we would need to do the following \n  \\begin{align*}\n    c^{-1}c\\vec{x}'=c^{-1}(A\\vec{x}+\\vec{b})\\\\\n    \\vec{x}'=c^{-1}A\\vec{x}+c^{-1}\\vec{b}\n  .\\end{align*}\n\\end{note}\n\\end{eg}\n\\begin{eg}\n  Consider the following ordinary differential equation and put it into matrix form.\n  \\begin{align*}\n    x''+4x'-4x+4y&=0\\\\\n    y''-4y'+5y-2x'+3x&=\\sin(t)\n  .\\end{align*}\n  In order to solve this we need to let $u=x'$, which makes $u'=x''$, and we need to let $v=y'$, which lets $u'=-4x'+4x-4y$ and $v'=y''=4y'-5y+2u-3x+\\sin(t)$. This makes our system \n  \\begin{align*}\n    u'&=-4u+4x-4y\\\\\n    v'&=4v-5y+2u-3x+\\sin(t)\\\\\n    x'&=u\\\\\n    y'&=v\n  .\\end{align*}\n  Now we can turn this into our $\\vec{x'}=A\\vec{x}+\\vec{b}$. This makes our equation \\[\n    \\begin{bmatrix} u'\\\\v'\\\\x'\\\\y'\\\\ \\end{bmatrix} =\\begin{bmatrix} -4&0&4&-4\\\\2&4&-3&-5\\\\1&0&0&0\\\\0&1&0&0 \\end{bmatrix} +\\begin{bmatrix} 0\\\\ \\sin(t)\\\\0\\\\0 \\end{bmatrix} \n  .\\] \n\\end{eg}\n\n\\subsection{Eigenvalues and Eigenvectors of Square Matrices}\nWe are going to be using $\\lambda$ for the eigenvalues and $\\vec{v}$ for the eigenvectors.\n\\begin{definition}\n  $\\lambda$ and $\\vec{v}$ are an eigenvalue/eigenvector of $A$ if \\[\n  A\\vec{v}=\\lambda\\vec{v}, v\\neq 0\n  .\\] \n\\end{definition}\n\nOur steps to find the eigenvector are the following:\n\\begin{enumerate}\n  \\item Find $\\lambda$'s with $det(A-\\lambda I)=0$ (polynomial in $\\lambda$).\n  \\item For each $\\lambda$ find its eigenvector $\\vec{v}$ using $A\\vec{v}=\\lambda\\vec{v}$ or $(A-\\lambda I)\\vec{v}=0$\n\\end{enumerate}\nWe need to make sure that $\\vec{v}$ is a non-zero solution to the equation. This means that we will have infinite solutions because every multiple of an eigenvector is also an eigenvector.\n\\begin{eg}\n  For $A=\\begin{bmatrix} 4&2\\\\5&1 \\end{bmatrix}$, find eigenvalues and eigenvectors. In order to find the eigen vector we take the deteminant of $A-\\lambda I$ and set it equal to zero.\n  \\begin{align*}\n    det(\\begin{bmatrix} 4&2\\\\5&1 \\end{bmatrix} -\\lambda\\begin{bmatrix} 1&0\\\\0&1 \\end{bmatrix} )&=0\\\\\n    \\left| \\begin{matrix} 4-\\lambda&2\\\\5&1-\\lambda \\end{matrix} \\right| &=0\\\\\n    (4-\\lambda)(1-\\lambda)-10&=0\\\\\n    4-5\\lambda+\\lambda^2-10&=0\\\\\n    \\lambda^2-5\\lambda-6&=0\\\\\n    \\lambda&=6,-1\n  .\\end{align*}\n  Now we need to solve for the eigenvectors. First, let $\\lambda=6$. Let $\\vec{v}=\\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix}$.\n  \\begin{align*}\n    \\begin{bmatrix} 4-6&2\\\\5&1-6 \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} &=\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \\\\\n    \\begin{bmatrix} -2&2\\\\5&-5 \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} =\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \n  .\\end{align*}\n  If we put this back into equation form we get \n  \\begin{align*}\n    -2v_1+2v_2&=0\\\\\n    5v_1-5v_2&=0\\\\\n    \\to v_1=v_2\n  .\\end{align*}\n  So this means that $v_2\\begin{bmatrix} 1\\\\1 \\end{bmatrix} $ is an eigenvalue for $\\lambda=6$ for all $v_2\\neq 0$. Let's now solve for $\\lambda=1:$\n  \\begin{align*}\n    \\begin{bmatrix} 5&2\\\\5&2 \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} &=\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \\\\\n    5v_1-1v_2=0\\to v_2=\\frac{-5}{2}v_1\n  .\\end{align*}\n  This means that any multiple of the vector $\\begin{bmatrix} 1\\\\-\\frac{5}{2} \\end{bmatrix}$ is an eigenvector for $\\lambda=1$.\n\\end{eg}\n\nLet's show that if $\\vec{v}$ is an eigenvector for $A$ with $\\lambda$, then $c\\vec{v}$ is an eigenvector for $A$ with $\\lambda$ if $c\\neq 0.$. We know that $A\\vec{v}=\\lambda\\vec{v}$. Is $A(c\\vec{v})=\\lambda(c\\vec{v})$? Yes.\nLet $X(t)=\\begin{bmatrix} x(t)\\\\y(t) \\end{bmatrix} $. If we solve for $\\vec{X}'=A\\vec{x}$, \n\\begin{align*}\n  \\begin{bmatrix} x\\\\y \\end{bmatrix} '=\\begin{bmatrix} 4&2\\\\5&1 \\end{bmatrix} \\begin{bmatrix} x\\\\y \\end{bmatrix} \\\\\n  x'=4x+2y\\\\\n  y'=5x+y\n.\\end{align*}\nWe can now write down our solutions as \n\\begin{align*}\n  \\vec{X}_1(t)=e^{6t}\\begin{bmatrix} 1\\\\1 \\end{bmatrix} =\\begin{bmatrix} e^{6t}\\\\e^{6t} \\end{bmatrix} \\\\\n  \\vec{X}_2(t)=e^{-t}\\begin{bmatrix} -2\\\\5 \\end{bmatrix} =\\begin{bmatrix} -2e^{-t}\\\\5e^{-t} \\end{bmatrix} \n.\\end{align*}\nThis means that we can determine that \\[\n  \\vec{X}(t)=c_1\\vec{x}_1+c_2\\vec{x}_2\n\\] is also a solution for all $c_1,c_2$. This means that our general solution is going to be \\[\n\\vec{X}=c_1e^{6t}\\begin{bmatrix} 1\\\\1 \\end{bmatrix} +c_2e^{-t}\\begin{bmatrix} -2\\\\5 \\end{bmatrix} \n.\\] We can also take our $c_1,c_2$ and distribute them to get \\[\n\\vec{X}(t)=\\begin{bmatrix} c_1e^{6t}-2c_2e^{-2}\\\\c_2e^{6t}+5c_2e^{-t} \\end{bmatrix} \n,\\] with $x(t)$ being the top equation and $y(t)$ being the bottom equation. We can verify the solutions in order to convince ourselves that this works. We can verify by using our $\\begin{bmatrix} -2e^{-t}\\\\5e^{-t} \\end{bmatrix} $. Our left hand side of the equation is going to be \\[\n\\vec{X}_2'=-e^{-t}\\begin{bmatrix} -2\\\\5 \\end{bmatrix} =e^{t}\\begin{bmatrix} 2\\\\-5 \\end{bmatrix} \n.\\] Our right hand side of the original equation is going to be \\[\nA\\vec{X}_2 = \\begin{bmatrix} 4&2\\\\5&1 \\end{bmatrix} e^{t}\\begin{bmatrix} -2\\\\5 \\end{bmatrix} \n.\\] After simplification of this equation, we get that the result is $e^{t}\\begin{bmatrix} 2\\\\-5 \\end{bmatrix} $.\n\\begin{eg}\n  Find the particular solution satisfying $x(0)=2,y(0)=-2$ for the general solution above. Now we just go through the following steps.\n  \\begin{align*}\n    \\vec{X}(0)=\\begin{bmatrix} 2\\\\-2 \\end{bmatrix} =c_1\\begin{bmatrix} 1\\\\1 \\end{bmatrix} +c_2\\begin{bmatrix} -2\\\\5 \\end{bmatrix} \\\\\n    2&=c_1-2c_2\\\\\n    -2&=c_1+5c_2\n  .\\end{align*}\n  Now we just solve for $c_1,c_2$ to get $c_1=\\frac{6}{7},c_2=-\\frac{4}{7}$, so our general solution is \\[\n    \\vec{X}(t)=\\frac{6}{7}e^{6t}\\begin{bmatrix} 1\\\\1 \\end{bmatrix} -\\frac{4}{7}e^{-t}\\begin{bmatrix} -2\\\\5 \\end{bmatrix} \n  .\\] \n\\end{eg}\n\nHow can we verify that two solutions are linearly independent\\footnote{This is a 4.4 idea but we are not quite there yet.}? We can solve this by using the wronskian. For the last equation we can check this by doing \\[\n  w(t)=\\left| \\begin{matrix} e^{6t}&-2e^{-t}\\\\e^{6t}&5e^{-t} \\end{matrix} \\right| = 5e^{5t}+2e^{5t}\\neq 0 \n.\\] Because the wronskian does not equal zero, the solutions are linearly independent.\\newline \n\n\\begin{eg}\n  \\begin{enumerate}\n    \\item Is $\\vec{v}=\\begin{bmatrix} 3\\\\2 \\end{bmatrix}$ an eigenvector for $A=\\begin{bmatrix} 2&3\\\\2&1 \\end{bmatrix} $. This can be tested by checking to see if $A\\vec{v}=\\lambda\\vec{v}$ for some $\\lambda$?\\[\n      A\\vec{v}=\\begin{bmatrix} 2&3\\\\2&1 \\end{bmatrix} \\begin{bmatrix} 3\\\\2 \\end{bmatrix} =\\begin{bmatrix} 12\\\\8 \\end{bmatrix} =\\lambda\\begin{bmatrix} 3\\\\2 \\end{bmatrix} \n    .\\] This is true for all $\\lambda=4$\n    \\item Is $\\lambda=-1$ and eigenvalue for $A=\\begin{bmatrix} 2&3\\\\2&1 \\end{bmatrix} $? We can check this by asking if $det(A-(-1)I)=0$?\\[\n      \\left| \\begin{matrix} 2+1&3\\\\2&1+1 \\end{matrix} \\right| =\\left| \\begin{matrix} 3&3\\\\2&2 \\end{matrix} \\right| =6-6=0\n    .\\] Because this determinant equals zero, $\\lambda=-1$ is an eigenvalue of $A$\n  \\end{enumerate}\n\\end{eg}\n\nFor repeated (real) eigenvalues, we can have many different options that can come out. For a $2\\times 2, \\lambda_1=\\lambda_2$. Here are our options \n\\begin{enumerate}\n  \\item Only one eigenvector (and its multiples).\n  \\item 2 linearly independent eigenvectors.\n\\end{enumerate}\nFor option 2, an example would be \n\\begin{align*}\n  \\vec{X}_1=e^{\\lambda t}\\begin{bmatrix} 2\\\\3 \\end{bmatrix} \\\\\n  \\vec{X}_2=e^{\\lambda t}\\begin{bmatrix} 4\\\\0 \\end{bmatrix} \n.\\end{align*}\nOur general solution is going to be \\[\n  \\vec{X}(t)=C_1\\vec{X}_1+C_2\\vec{X}_2=e^{2t}\\begin{bmatrix} 2C_1+4C_2\\\\3C_1 \\end{bmatrix} \n.\\] This means that every vector is an eigenvector. This only occurs if our eigenvector is a multiple of the identity matrix.\n \\begin{eg}\n  Find all eigenpairs of the matrix $A=\\begin{bmatrix} 4&5\\\\-2&6 \\end{bmatrix} $. First we need to find the eigenvalues by doing \n  \\begin{align*}\n    \\left| \\begin{matrix} 4-\\lambda&5\\\\-2&6-\\lambda \\end{matrix} \\right| &=(4-\\lambda)(6-\\lambda)+10\\\\\n                                   &=24-10\\lambda+\\lambda^2+10\\\\\n                                   &=\\lambda^2-10\\lambda+34=0\n  .\\end{align*}\n  We can solve this by completing the square by doing \n  \\begin{align*}\n    (\\lambda^2-10\\lambda+25)&=-34+25\\\\\n    (\\lambda-5)^2&=-9\\\\\n    |\\lambda-5|&=3i\\\\\n    \\lambda-5&=\\pm 3i\\\\\n    \\lambda &= 5\\pm 3i\n  .\\end{align*}\n  Now we need to find the eigenvectors by solving $A\\vec{v}=\\lambda\\vec{v}$ or doing $(A-\\lambda I)\\vec{v}=\\vec{0}$. Now solving for $\\lambda_1=5+3i$.\n  \\begin{align*}\n    \\begin{bmatrix} 4-(5+3i)&5\\\\-2&6-(5+3i) \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} &=\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \\\\\n    \\begin{bmatrix} -1-3i&5\\\\-2&1-3i \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} &=\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \\\\\n    (-1-3i)v_1+5v_2=0\\\\\n    -2v_1+(1-3i)v_2=0\n  .\\end{align*}\n  The two last equations above are equivalent so we can work with either of them, we are going to be working with $5v_2=(1+3i)v_1$. If we choose $v_1=5,v_2=1+\\lambda i$ we can solve $v_2=\\frac{1+3i}{5}v_1$ for all $v_1$.\n\\end{eg}\n\\begin{eg}\n  Show that $\\vec{v}=\\begin{bmatrix} 2+2i\\\\-1 \\end{bmatrix} $ is an eigenvector of $A=\\begin{bmatrix} 2&8\\\\-1&-2 \\end{bmatrix} $ We can set $A\\vec{v}=\\lambda\\vec{v}$ for some $\\lambda$ to get \\[\n  \\begin{bmatrix} 2&8\\\\-1&-2 \\end{bmatrix} \\begin{bmatrix} 2+2i\\\\-1 \\end{bmatrix} =\\begin{bmatrix} 4+4i-8\\\\-2-2i+3 \\end{bmatrix} =\\begin{bmatrix} 4i-4\\\\-2i \\end{bmatrix} \\stackrel{?}{=}\\lambda\\begin{bmatrix} 2+2i\\\\-1 \\end{bmatrix} \n  .\\] \n  We can check to see if $\\lambda=2i$ by doing \n  \\begin{align*}\n    2i&=(2+2i)\\stackrel{?}{=}4i-4\\\\\n    4i-4&=4i-4\n  .\\end{align*}\n  This means that $\\vec{v}$ is an eigenvector for $A$ with $\\lambda=2i$.\n\\end{eg}\nHow can we turn a complex eigenpair of $A$ into a solution of $\\vec{x}'=A\\vec{x}$? Last time we found that $\\lambda_1=5+3i$ had $\\vec{v}_1=\\begin{bmatrix} 5\\\\1+3i \\end{bmatrix} \\text{ or }\\begin{bmatrix} 1-3i\\\\2 \\end{bmatrix} $\n\\begin{note}\n  We know that $\\vec{x}_1(t)=e^{(5+3i)t}\\begin{bmatrix} 5\\\\1+3i \\end{bmatrix} $ is a solution, and so is $\\vec{x}_1(t)=e^{5-3i)t}\\begin{bmatrix} 5\\\\1-3i \\end{bmatrix} $ is a solution, so \\[\n  \\vec{x}(t)=C_1\\vec{x}_1(t)=C_2\\vec{x}_2(t)\n  .\\] \n\\end{note}\nHow are we able to turn these into real-valued solutions? The real and imaginary parts of a solution must also be solutions. We can do the following calculations\n\\begin{align*}\n  \\vec{x}_1(t)&=e^{5t}e^{3it}\\begin{bmatrix} 5\\\\1+3i \\end{bmatrix} \\\\\n              &=e^{5t}\\left( \\cos(3t)+i\\sin(3t) \\right)\\begin{bmatrix} 5\\\\1+3i \\end{bmatrix} \\\\\n              &=e^{5t}\\begin{bmatrix} 5\\cos(3t)+5i\\sin(3t)\\\\ \\cos(3t)+i\\sin(3t)+3i\\cos(3t)-3\\sin(3t) \\end{bmatrix}\\\\\n              &=e^{5t}\\begin{bmatrix} 5\\cos(3t)\\\\ \\cos(3t)-3\\sin(3t) \\end{bmatrix} +ie^{5t}\\begin{bmatrix} 5\\sin(3t)\\\\3\\cos(3t)+\\sin(3t) \\end{bmatrix} \n.\\end{align*}\nThe two sides of the addition are considered $\\vec{x}_3(t),\\vec{x}_4(t)$ respectively. ($x_4$ does not include the $i$). This makes our general solution \\[\n  \\vec{x}(t)=C_3\\vec{x}_3(t)+C_4\\vec{x}_4(t)\n.\\] \n\\begin{eg}\n  Find the eigenvalues of $A=\\begin{bmatrix} 2&-7&0\\\\5&10&4\\\\0&5&2 \\end{bmatrix} $. First we need to find the eigenvalues by doing $det(A-\\lambda I)=0.$ \n  \\begin{align*}\n    \\left| \\begin{matrix} 2-\\lambda&-7&0\\\\5&10-\\lambda&4\\\\0&5&2-\\lambda \\end{matrix} \\right| &= (2-\\lambda)\\left| \\begin{matrix} 10-\\lambda&4\\\\5&2-\\lambda \\end{matrix} \\right| + (7) \\left| \\begin{matrix} 5&4\\\\0&2-\\lambda \\end{matrix} \\right| \\\\\n                                   &=(2-\\lambda)[(10-\\lambda)(2-\\lambda)-20]+7.5(2-\\lambda)\\\\\n                                   &=(2-\\lambda)[20-12\\lambda+\\lambda^2-20+35]\\\\\n                                   &=(2-\\lambda)(\\lambda^2-12\\lambda+35)\\\\\n                                   &=(2-\\lambda)(\\lambda-5)(\\lambda-7)=0\\\\\n    \\lambda&=2,5,7\n  .\\end{align*}\n\\end{eg}\nHow can we find a second linearly independent solution to $\\vec{x}'=A\\vec{x}$ if $A$ only had 1 eigenpair?\n\\begin{eg}\n  Consider the equation $B=\\begin{bmatrix} 3&-18\\\\2&-9 \\end{bmatrix} $, which has the eigenvalues $\\lambda=-3,-3$ with an eigenvector of $\\vec{v}=\\begin{bmatrix} 3\\\\1 \\end{bmatrix} $. We know that $\\vec{x}_1=(t)e^{-3t}\\begin{bmatrix} 3\\\\1 \\end{bmatrix} $ is one solution. We need to find $\\vec{x}_2$. We can say that $\\vec{x}_2(t)=te^{\\lambda t}\\vec{v}+e^{\\lambda t}\\vec{w}$, where $(B-\\lambda I)\\vec{w}=\\vec{v}$ Let's find our $\\vec{w}$.\n  \\begin{align*}\n    \\begin{bmatrix} 3-(-3)&-18\\\\2&-9-(-3) \\end{bmatrix} \\begin{bmatrix} w_1\\\\w_2 \\end{bmatrix} =\\begin{bmatrix} 3\\\\1 \\end{bmatrix} \\\\\n    \\begin{bmatrix} 6&-18\\\\2&-6 \\end{bmatrix} \\begin{bmatrix} w_1\\\\w_2 \\end{bmatrix} =\\begin{bmatrix} 3\\\\1 \\end{bmatrix} \\\\\n    6w_1-18w_2&=3\\\\\n    2w_1-6w_2&=1\n  .\\end{align*}\n  We can choose any of the $w_1,w_2$ combinations that work. If we choose that $w_2=0,w_1=\\frac{1}{2}$. This makes our general solution \\[\n    \\vec{x}(t)=Ce^{-3t}\\begin{bmatrix} 3\\\\1 \\end{bmatrix} +C_2e^{-3t}\\left( t\\begin{bmatrix} 3\\\\1 \\end{bmatrix} +\\begin{bmatrix} 0\\\\\\frac{1}{2} \\end{bmatrix}  \\right) \n  .\\] \n\\end{eg}\n\\begin{eg}\n  Let's solve $\\vec{x}'=\\begin{bmatrix} 0&1\\\\0&6 \\end{bmatrix} \\vec{x}$ for $\\vec{x}(t)$. The first step we need to take is calculating the eigenvalues of the matrix.\n  \\begin{align*}\n    det(A-\\lambda I)=\\left| \\begin{matrix} 0-\\lambda&1\\\\0&6-\\lambda \\end{matrix} \\right| =0\\\\\n    -\\lambda(6-\\lambda)=0\\\\\n    \\lambda=0,6\n  .\\end{align*}\n  For $\\lambda=0$:\n  \\begin{align*}\n    \\begin{bmatrix} 0&1\\\\0&6 \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} &=\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \\\\\n    v_2&=0\\\\\n    6v_2&=0\\\\\n    \\vec{v}=\\begin{bmatrix} v_1\\\\0 \\end{bmatrix} &=v_1\\begin{bmatrix} 1\\\\0 \\end{bmatrix} \n  .\\end{align*}\n  For $\\lambda=6$\n  \\begin{align*}\n    \\begin{bmatrix} -6&1\\\\0&0 \\end{bmatrix} \\begin{bmatrix} v_1\\\\v_2 \\end{bmatrix} &=\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \\\\\n    -6v_1+v_2&=0\\\\\n    0&=0\\\\\n    v_2&=6v_1\\\\\n    \\vec{v}&=\\begin{bmatrix} v_1\\\\6v_1 \\end{bmatrix}=v_1\\begin{bmatrix} 1\\\\6 \\end{bmatrix}  \n  .\\end{align*}\n  This will make our general solution be \\[\n    \\vec{x}(t)=C_1e^{0t}\\begin{bmatrix} 1\\\\0 \\end{bmatrix} +C_2e^{6t}\\begin{bmatrix} 1\\\\6 \\end{bmatrix} = \\begin{bmatrix} C_1+C_2e^{6t}\\\\6C_2e^{6t} \\end{bmatrix} \n  .\\] \n\\end{eg}\n\\subsection{Undetermined Coefficients for Linear Systems}\n\\begin{eg}\n  Let's take a look at the differential equation \\[\n    \\vec{x}'=\\begin{bmatrix} 3&-18\\\\2&-9 \\end{bmatrix} \\vec{x}+\\begin{bmatrix} 2t\\\\0 \\end{bmatrix} \n  .\\] \n  This ordinary differential equation has the homogeneous solution of \\[\n    \\vec{x}_h(t)=C_1e^{-3t}\\begin{bmatrix} 3\\\\1 \\end{bmatrix} +C_2\\left[ te^{-3t}\\begin{bmatrix} 3\\\\1 \\end{bmatrix} +e^{-3t}\\begin{bmatrix} \\frac{1}{2}\\\\0 \\end{bmatrix}  \\right] \n  .\\] \n  If we were to make our initial $\\vec{x}_p(t)$ guess, we should guess $\\begin{bmatrix} At+B\\\\Ct+D \\end{bmatrix} $. Now we need to find $\\vec{x}_p'=\\begin{bmatrix} A\\\\C \\end{bmatrix}$ and plug it into the left hand side of the equation. The right hand side will now equal \\[\n  \\begin{bmatrix} 3&-18\\\\2&-9 \\end{bmatrix} \\begin{bmatrix} At+B\\\\Ct+D \\end{bmatrix} +\\begin{bmatrix} 2t\\\\0 \\end{bmatrix} \n  .\\] This means that this should be equal \\[\n  \\begin{bmatrix} A\\\\C \\end{bmatrix} =\\begin{bmatrix} 3At+3B-18Ct-18D+2t\\\\2At+2B-9Ct-9D \\end{bmatrix} \n  .\\] So \n  \\begin{align*}\n    A=3At+3B-18Ct-18D+2t\\\\\n    C=2At+2B-9Ct-9D\\\\\n  .\\end{align*}\n  We can separate our coefficients with 1's and t's like so \n  \\begin{align*}\n    1:A&=3B-18D\\\\\n    C&=2B-9D\\\\\n    t: 0=3A-18C+2\\\\\n    0=2A-9C\n  .\\end{align*} \n  Aftering doing algebra and simplifying we get that $A=2,C=\\frac{4}{9},B=-\\frac{10}{9},D=-\\frac{8}{27}$, so \\[\n    \\vec{x}_p=\\begin{bmatrix} 2t&-\\frac{10}{9}\\\\\\frac{4}{9}t&-\\frac{8}{27} \\end{bmatrix} \n  .\\] \n\\end{eg}\n\\subsection{Modeling with Systems}\nLet's start off by looking at an example.\n\\begin{eg}\n  \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{resource/images/4.4.2 Example 1.jpg}\n    \\caption{}\n    \\label{fig:}\n  \\end{figure}\n  Tanks $A$ and $B$ both have 100 gallons of brine. $A$ concentration $0.2 \\frac{lb}{gal}$ salt, $B$ concentration is $0.3 \\frac{lb}{gal}$. Let $x(t)$ and $y(t)$ be the amounts of salt in tanks $A$ and $B$ in pounds at time $t$(min).\n  \\begin{align*}\n    x'=0+\\left( 2 \\frac{gal}{min} \\right) \\left( \\frac{y}{100} \\frac{lb}{gal} \\right)-5 \\frac{x}{100} \\\\\n    y'=3 \\frac{x}{100}- \\frac{3y}{100}\\\\\n    x(0)=20\\\\\n    y(0)=30\n  .\\end{align*}\n  This gives us that \\[\n    \\begin{bmatrix} x\\\\y \\end{bmatrix} '=\\begin{bmatrix} -\\frac{1}{20}&\\frac{1}{50}\\\\\\frac{3}{100}&-\\frac{3}{100} \\end{bmatrix} \\begin{bmatrix} x\\\\y \\end{bmatrix} \n  .\\] \n\\end{eg}\n", "meta": {"hexsha": "e02da2bf6527fe970774e570e43bc1388be7fc33", "size": 24441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math260/chapters/4.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math260/chapters/4.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math260/chapters/4.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.9290617849, "max_line_length": 438, "alphanum_fraction": 0.6354895463, "num_tokens": 9891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.6889667311034099}}
{"text": "\\section{Complex LMS and Widely Linear Modelling}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n\n%% a)\n\\item\n%\n\nA Wide Linear Moving Average order 1, WLMA(1), process $y(n)$ is generated, whose \\texttt{real} and \\texttt{imag} parts are provided in figure \\ref{fig:4_1_a}.\nAs expected, the process is not circular, and we expect simple Complex Least Mean Squared (CLMS) algorithm to fail to model it.\n\nThe mean squared prediction error curve in figure \\ref{fig:4_1_a} agrees with our assumption, though the Augemented Complex Least Mean Squared (ACLMS) algorithm\nsuccessfully learns the process parameters. In more detail, the ACLMS achieves an $MPSE = -300dB$ in steady-state, while CLMS saturates at $MPSE = 7.6$. This is\nthe consequence of the inability of the CLMS to adapt to non-circular signals, due to its limited capacity.\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/complex-LMS-and-widely-linear-modelling/assets/a/comparison}\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/complex-LMS-and-widely-linear-modelling/assets/a/learning_curves}\n    \\end{subfigure}\n    \\caption{CLMS vs ACLMS: non-circularity and (A)CLMS learning curves.}\n    \\label{fig:4_1_a}\n\\end{figure}\n\n%% b)\n\\item\n%\n\nFigures \\ref{fig:4_1_b_1}, \\ref{fig:4_1_b_2}, \\ref{fig:4_1_b_3} illustrate the circularity plots (\\texttt{real}-\\texttt{imag} scatter plots) along with the learning curves\nof the ACLMS and CLMS algorithms for different model orders, on the \\texttt{wind-dataset}.\n\nDespite its non-obviously symmetric shape, the low regime wind data has lowest circularity coefficient, $\\rho = 0.159$, while the medium and high regimes have\n$\\rho = 0.454$ and $\\rho = 0.624$, repsectively. A complex-valued random variable is said to be circular if its probability distribution is not dependent on the angle, that is,\nthe distribution is rotationally invariant. In other words the variable’s probability distribution function should only depend on the Euclidean distance from the origin in the complex domain.\nBy definition, the higher the circularity coefficient, $\\rho$, the less circular the data is.\n\nHence, as shown in the previous part, ACLMS algorithm outperforms CLMS on non-circular data. This is verified again on the \\texttt{wind-dataset}, where the ACLMS has lower \nmean squared prediction error (MPSE) for any wind regime. More interesting is the fact that at high regime data, the least circular, the ACLMS has a larger margin in performance\n($0.1 dB$). Lastly, we observe that the MPSE is minimised for small model orders, $M \\in [3, 6]$, since over-modelling leads to over-fitting the noise and fail to generalise, despite\nthe excess degrees of freedom. For larger model order, $M > 10$, we observe that the ACLMS performs worse than the CLMS, due to its extra capacity (more parameters), which lead to\noverfitting.\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/complex-LMS-and-widely-linear-modelling/assets/b/circularity_1}\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/complex-LMS-and-widely-linear-modelling/assets/b/learning_curves_1}\n    \\end{subfigure}\n    \\caption{Low Regime:circularity plot and (A)CLMS learning curves.}\n    \\label{fig:4_1_b_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/complex-LMS-and-widely-linear-modelling/assets/b/circularity_2}\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/complex-LMS-and-widely-linear-modelling/assets/b/learning_curves_2}\n    \\end{subfigure}\n    \\caption{Medium Regime:circularity plot and (A)CLMS learning curves.}\n    \\label{fig:4_1_b_2}\n\\end{figure}\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/complex-LMS-and-widely-linear-modelling/assets/b/circularity_3}\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/complex-LMS-and-widely-linear-modelling/assets/b/learning_curves_3}\n    \\end{subfigure}\n    \\caption{High Regime:circularity plot and (A)CLMS learning curves.}\n    \\label{fig:4_1_b_3}\n\\end{figure}\n\n%% c)\n\\item\n%\n\nComplex voltages are synthetically generated for various magnitude, angle combinations leading to balanced and unbalanced configurations, while their illustrations in the complex plane\nare provided in figures \\ref{fig:4_1_c_1}, \\ref{fig:4_1_c_2}. Overall, we notice that balanced systems have a circular shape, while unbalanced don't.\nThis is also collaborated by the fact that the balanced system has circularity coefficient $\\rho = 0$, while the unbalanced system has a high circularity coefficient, $\\rho = 0.757$.\nFinally, the impact of the angle and magnitude distortions, $\\Delta_{b} \\neq \\Delta_{c} \\neq 0$ and $V_{a} \\neq V_{b} \\neq V_{c}$, respectively, is depicted in figure \\ref{fig:4_1_c_2}.\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/complex-LMS-and-widely-linear-modelling/assets/c/balanced}\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/complex-LMS-and-widely-linear-modelling/assets/c/unbalanced}\n    \\end{subfigure}\n    \\caption{Complex Voltage: balanced and unbalanced voltages.}\n    \\label{fig:4_1_c_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/complex-LMS-and-widely-linear-modelling/assets/c/unbalanced_angle}\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/complex-LMS-and-widely-linear-modelling/assets/c/unbalanced_magnitude}\n    \\end{subfigure}\n    \\caption{Complex Voltage: unbalanced voltages angle and magnitude distortions.}\n    \\label{fig:4_1_c_2}\n\\end{figure}\n\n%% d)\n\\item\n%\n\nBalanced complex $\\alpha\\ -\\ \\beta$ voltages satisfy:\n\n\\begin{equation}\n    u(n) = \\sqrt{\\frac{3}{2}} V e^{j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)}\n\\end{equation}\n\nFor time index $n+1$:\n\n\\begin{align}\n    u(n+1)  &= \\sqrt{\\frac{3}{2}} V e^{j(2\\pi \\frac{f_{o}}{f_{s}} (n+1) + \\phi)} \\\\\n            &= \\sqrt{\\frac{3}{2}} V e^{j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} e^{j 2 \\pi \\frac{f_{o}}{f_{s}}} \\\\\n            &= u(n) e^{j 2 \\pi \\frac{f_{o}}{f_{s}}}\n\\label{eq:u_n+1}\n\\end{align}\n\nUsing the strictly linear autoregressive model of order 1, equation, satisfying:\n\n\\begin{equation}\n    u(n+1) = u(n) h^{*}(n)\n\\end{equation}\n\nwe express the complex exponential in (\\ref{eq:u_n+1}) as a function of the model parameter $h(n)$:\n\n\\begin{align}\n    e^{j 2 \\pi \\frac{f_{o}}{f_{s}}} &= h^{*}(n) \\\\\n    e^{-j 2 \\pi \\frac{f_{o}}{f_{s}}}&= h(n) \\\\\n                                    &= | h(n) | e^{j\\big( arctan \\big(\\frac{\\Im\\{h(n)\\}}{\\Re\\{h(n)\\}} \\big) \\big)}\n\\end{align}\n\nTwo complex numbers are equal if and only of both their magnitudes and their angles are equal, therefore we set the angles to be equal, obtaining:\n\n\\begin{align}\n    2 \\pi \\frac{f_{o}}{f_{s}} = arctan \\big(\\frac{\\Im\\{h(n)\\}}{\\Re\\{h(n)\\}} \\big) \n\\end{align}\n\nSolving for $f_{o}$ concludes the proof:\n\n\\begin{equation}\n    f_{o} = \\frac{f_{s}}{2\\pi} arctan \\big(\\frac{\\Im\\{h(n)\\}}{\\Re\\{h(n)\\}} \\big)\n\\label{proof:fo_CLMS}\n\\end{equation}\n\nThe unbalanced system satisfies:\n\n\\begin{equation}\n    u(n) = A(n) e^{j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} + B(n) e^{-j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)}\n\\label{eq:u_unbalanced}\n\\end{equation}\n\nUsing the widely linear autoregressive model of order 1, equation, satisfying:\n\n\\begin{equation}\n    u(n+1) = h^{*}(n) u(n) + g^{*}(n) u^{*}(n)\n\\end{equation}\n\nwe substitute (\\ref{eq:u_unbalanced}) terms:\n\n\\begin{align}\n    u(n+1) =\\ \n        &h^{*}(n) \\bigg[ A(n) e^{j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} + B(n) e^{-j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} \\bigg] + \\nonumber\\\\\n        &g^{*}(n) \\bigg[ A^{*}(n) e^{-j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} + B^{*}(n) e^{j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} \\bigg]\n\\label{eq:u_n+1_ar}\n\\end{align}\n\nFor time index $n+1$, the complex voltage satisfies:\n\n\\begin{equation}\n    u(n+1) = A(n+1) e^{j(2\\pi \\frac{f_{o}}{f_{s}} (n+1) + \\phi)} + B(n+1) e^{-j(2\\pi \\frac{f_{o}}{f_{s}} (n+1) + \\phi)}\n\\label{eq:u_n+1_clarke}\n\\end{equation}\n\nEquating (\\ref{eq:u_n+1_ar}) and (\\ref{eq:u_n+1_clarke}), collecting common exponential terms:\n\n\\begin{align}\n    A(n+1) e^{j(2\\pi \\frac{f_{o}}{f_{s}} (n+1) + \\phi)} &= \\bigg[ h^{*}(n) A(n) + g^{*}(n) B^{*}(n) \\bigg] e^{j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)} \\\\\n    B(n+1) e^{-j(2\\pi \\frac{f_{o}}{f_{s}} (n+1) + \\phi)} &= \\bigg[ h^{*}(n) B(n) + g^{*}(n) A^{*}(n) \\bigg] e^{-j(2\\pi \\frac{f_{o}}{f_{s}} n + \\phi)}\n\\end{align}\n\nAssuming that the amplitude change over time is negligible, or equivalently $A(n+1) \\approx A(n)$ and $B(n+1) \\approx B(n)$, the equations simplify as:\n\n\\begin{align}\n    e^{j 2\\pi \\frac{f_{o}}{f_{s}}} = \\frac{h^{*}(n) A(n) + g^{*}(n) B^{*}(n)}{A(n+1)} \\approx h^{*}(n) + g^{*}(n) \\frac{B^{*}(n)}{A(n)} \\label{eq:e_A}\\\\\n    e^{-j 2\\pi \\frac{f_{o}}{f_{s}}} = \\frac{h^{*}(n) B(n) + g^{*}(n) A^{*}(n)}{B(n+1)} \\approx h^{*}(n) + g^{*}(n) \\frac{A^{*}(n)}{B(n)} \\label{eq:e_B}\n\\end{align}\n\nNote that (\\ref{eq:e_A}) is the complex conjugate of (\\ref{eq:e_B}, we reach:\n\n\n\\begin{align}\n    h^{*}(n) + g^{*}(n) \\frac{B^{*}(n)}{A(n)} = h(n) + g(n) \\frac{A(n)}{B^{*}(n)}\n\\end{align}\n\nMultiplying with $\\frac{B^{*}(n)}{A(n)}$ both sides:\n\n\\begin{align}\n    \\bigg( h^{*}(n) - h(n) \\bigg) \\frac{B^{*}(n)}{A(n)} + g^{*}(n) \\bigg( \\frac{B^{*}(n)}{A(n)} \\bigg)^{2} - g(n) = 0\n\\label{eq:quad}\n\\end{align}\n\nWe note that (\\ref{eq:quad}) is quadratic in $\\frac{B^{*}(n)}{A(n)}$, hence solving it we obtain:\n\n\\begin{align}\n    \\frac{B^{*}(n)}{A(n)}   &= \\frac{- \\bigg( h^{*}(n) - h(n) \\bigg) \\pm \\sqrt{\\bigg( h^{*}(n) - h(n) \\bigg)^{2} + 4 g^{*}(n) g(n)}}{2g^{*}(n)} \\\\\n                            &= \\frac{2 \\Im\\{h(n)\\}j \\pm j\\sqrt{-4 \\Im\\{h(n)\\}^{2} + 4 |g(n)|^{2}}}{2g^{*}(n)} \\\\\n                            &= \\frac{\\Im\\{h(n)\\}j \\pm j\\sqrt{\\Im\\{h(n)\\}^{2} - |g(n)|^{2}}}{g^{*}(n)}\n\\end{align}\n\nSubstitution in (\\ref{eq:e_A}), yields:\n\n\\begin{align}\n    e^{j 2\\pi \\frac{f_{o}}{f_{s}}}  &= h^{*}(n) + \\Im\\{h(n)\\}j \\pm j\\sqrt{\\Im\\{h(n)\\}^{2} - |g(n)|^{2}} \\\\\n                                    &= \\Re\\{h(n)\\} \\pm j\\sqrt{\\Im\\{h(n)\\}^{2} - |g(n)|^{2}} \\\\\n\\end{align}\n\nKeeping one solution ($+$ sign), since $f_{s} \\gg f_{o} > 0$:\n\n\\begin{align}\n    e^{j 2\\pi \\frac{f_{o}}{f_{s}}}  &= \\Re\\{h(n)\\} + j\\sqrt{\\Im\\{h(n)\\}^{2} - |g(n)|^{2}} \\\\\n                                    &= \\rho e^{j\\big(\\frac{\\sqrt{\\Im\\{h(n)\\}^{2} - |g(n)|^{2}}}{\\Re\\{h(n)\\}}\\big)}\n\\end{align}\n\nwhere $\\rho > 0$. Set the angles to be equal and solving for $f_{o}$ we complete the proof:\n\n\\begin{equation}\n    f_{o} = \\frac{f_{s}}{2 \\pi} arctan \\bigg(\\frac{\\sqrt{\\Im\\{h(n)\\}^{2} - |g(n)|^{2}}}{\\Re\\{h(n)\\}}\\bigg)\n\\label{proof:fo_ACLMS}\n\\end{equation}\n\n%% e)\n\\item\n%\n\nFirst order CLMS and ACLMS filters are trained on both the balanced and unbalanced (magnitude and angle) complex voltage synthetic data.\nThe derived formulae (\\ref{proof:fo_CLMS}) and (\\ref{proof:fo_ACLMS}) are used along with the learnt filter parameters, $h_{CLMS}$, $h_{ACLMS}$ \\& $g_{ACLMS}$,\nwhile the frequency estimates over time and the error curves are provided in figures \\ref{fig:4_1_e_1}, \\ref{fig:4_1_e_2} for the balanced and unbalanced complex voltage, respectively.\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/complex-LMS-and-widely-linear-modelling/assets/e/balanced_error}\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/complex-LMS-and-widely-linear-modelling/assets/e/balanced_frequency}\n    \\end{subfigure}\n    \\caption{Balanced Complex Voltage: mean squared prediction error (MPSE) and frequency estimation.}\n    \\label{fig:4_1_e_1}\n\\end{figure}\n\nIn case of the balanced grid, the CLMS filter excels, since it both converges faster to the nominal frequency $f_{o} = 50 Hz$, without overshooting (transient behaviour).\nOn the other hand, the ACLMS oscillates for the first $300$ timesteps and finally converges to the true frequency after that.\nThis is an expected result, since in figure \\ref{fig:4_1_c_1} we showed that the balanced system has a circular complex voltage, which can be sufficiently modelled by a CLMS filter.\nThe extra degrees of ACLMS freedom, put a burden on the model, which needs more time to converge.\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/complex-LMS-and-widely-linear-modelling/assets/e/unbalanced_error}\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/complex-LMS-and-widely-linear-modelling/assets/e/unbalanced_frequency}\n    \\end{subfigure}\n    \\caption{Unbalanced Complex Voltage: mean squared prediction error (MPSE) and frequency estimation.}\n    \\label{fig:4_1_e_2}\n\\end{figure}\n\nFigure \\ref{fig:4_1_e_2} depicts the mean squared prediction error and frequency estimates for the unbalanced system,\nwith $(V_{a}, V_{b}, V_{c}) = (0.1, 1.0, 1.9)$ and $(\\Delta_{b}, \\Delta_{c}) = (2.0, 0.5)$.\nIn this scenario, the ACLMS converges to the true nominal frequency value after 450 timesteps, though the CLMS filter oscillates around $\\hat{f}_{o} = 37 Hz$ and never adapts to the true $f_{o}$.\nUnsurprisingly, CLMS does not have the capacity to model non-circular distributions and hence fails to model unbalanced configurations ($\\rho = 0.757$).\n\n%\n\\end{enumerate}", "meta": {"hexsha": "c4f72553d3e1344d191b0083a2e88914e3af6c48", "size": 15039, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/widely-linear-filtering-and-adaptive-spectrum-estimation/complex-LMS-and-widely-linear-modelling/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/complex-LMS-and-widely-linear-modelling/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/complex-LMS-and-widely-linear-modelling/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": 47.8949044586, "max_line_length": 195, "alphanum_fraction": 0.6669326418, "num_tokens": 5088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.6889667241691949}}
{"text": "\\subsection{Special Case: 1-hidden Layer}\nFirst, let us define the so-called 1-hidden layer (shallow) neural network.\n\\begin{definition}The 1-hidden layer (shallow) neural network is defined as:\n\t$$\n\t{\\rm DNN}_1 = \\lbrace \\phi~:~ \\phi(x) = \\sum_{i=1}^N a_i \\sigma(w_i x + b_i ) + c, ~~ N \\in \\mathbb{N}^+\\rbrace.\n\t$$\n\\end{definition}\n\nTo consistent with above notation, we can write it as:\n$$\n\\phi = W^1 x^1 + b^1 = (a_1,\\cdots,a_N) \\sigma(W^0 x + b^0) + c \\in {\\rm DNN}_1.\n$$\n\nThe first question about ${\\rm DNN}_1$ is about the approximation properties for any continuous functions. Here we have the next theorem:\n\\begin{theorem}[Universal Approximation Property of Shallow Neural Networks] Let $\\Omega$ be bounded, if any $f\\in C(\\bar \\Omega)$, there exists a sequence $\\phi_n \\in {\\rm DNN}_1$ such that \n\t$$\n\t\\max_{x\\in \\bar \\Omega} |\\phi_n(x) - f(x)| \\to 0, \\quad n \\to \\infty.\n\t$$\n\tThis provide that $\\sigma$ is not a polynomial.\n\tOn the other hand, let $\\sigma$ be a non-polynomial Riemann integrable function and $\\sigma\\in L_{loc}^\\infty(\\mathbb{R})$ then we have\n\t$$\n\t\\overline{\\rm DNN}_1 = C(\\bar \\Omega).\n\t$$\n\\end{theorem}\nBefore the proof, let us give some notation.\nWe use $\\mathbb{P}_m(\\mathbb{R}^d)$ to define the polynomials\nof $d$-variables of degree less than $m$. \nLet $\\alpha = (\\alpha_1,\\cdots,\\alpha_d)$( $\\alpha_i $ non-negative integers), we note $|\\alpha| = \\sum_{i=1}^d \\alpha_i$ and \n$$\nx^{\\alpha} = x_1^{\\alpha_1}x_2^{\\alpha_2}\\cdots x_d^{\\alpha_d}.\n$$\n\\begin{lemma}\\label{lemm:dsigma}\n\tLet $\\sigma \\in C^{\\infty}(\\Omega)$ (i.e. $\\sigma$ is infinitely differentiable) and is not a polynomial, then for any $k \\ge 0$ there exists $t_k \\in \\mathbb{R}$ such that \n\t$$\n\t\\sigma^{(k)}(t_k) \\neq 0.\n\t$$\n\\end{lemma}\n\nNow we are going to give the proof of \n\\begin{proof}\n\tIf $\\sigma$ is a polynomial, say $\\sigma \\in \\mathbb{P}_m(\\mathbb{R})$, then we have that\n\t$$\n\t{\\rm DNN}_1 \\subset \\mathbb{P}_m(\\mathbb{R}^d).\n\t$$\n\tThus, ${\\rm DNN}_1$ cannot approximate polynomial of degree bigger than $m+1$. This implies that $\\sigma$ cannot be polynomial if ${\\rm DNN}_1$ has the approximation property.\n\t\n\tNow we prove that $\\overline{\\rm DNN}_1 = C(\\bar \\Omega)$ if $\\sigma$ is not a polynomials.\n\t\n\t\\begin{description}\n\t\t\\item[Case 1] First, let us assume that $\\sigma \\in C^{\\infty}(\\Omega)$. \n\t\t\n\t\t\\item[Fact 1:] We have the next relation:\n\t\t$$\n\t\t\\frac{\\partial}{\\partial [w]_i} \\left(\\sigma(wx + b) \\right) |_{w=0}= \\sigma'(wx+b)\\frac{\\partial}{\\partial [w]_i} (wx+b) = \\sigma'(wx+b)x_i |_{w=0}.\n\t\t$$\n\t\tThat is to say,\n\t\t$$\n\t\t\\frac{\\partial}{\\partial [w]_i} \\left(\\sigma(wx + b) \\right) |_{w=0} = \\sigma'(b)x_i.\n\t\t$$\n\t\tBy the lemma \\ref{lemm:dsigma}, there exists a $b \\in \\mathbb{R}$ such that \n\t\t$$\n\t\t\\sigma'(b) \\neq 0.\n\t\t$$\n\t\t\\item[Fact 2:] By using the definition of derivative, we have\n\t\t$$\n\t\t\\frac{\\partial}{\\partial [w]_i} \\left(\\sigma(wx + b) \\right) |_{w=0}=\n\t\t\\lim_{n\\to \\infty} \\frac{\\sigma((0 + \\frac{1}{n}e_i )\\cdot x + b) - \\sigma(b)}{\\frac{1}{n}} = \\lim_{n\\to\\infty} \\phi_n(x),\n\t\t$$\n\t\twhere \n\t\t$$\n\t\t\\phi_n(x) = n \\left(\\sigma(\\frac{1}{n}e_i \\cdot x + b) - \\sigma(b)\\right) \\in {\\rm DNN}_1.\n\t\t$$\n\t\tThis leads to the result that\n\t\t$$\n\t\t\\sigma'(b)x_i = \\lim_{n\\to\\infty} \\phi_n(x) \\in \\overline{\\rm DNN}_1,\n\t\t$$\n\t\tbecause of the definition that\n\t\t$$\n\t\t\\overline{\\rm DNN}_1 = {\\rm DNN}_1 \\cup \\{f ~:~f = \\lim_{n\\to\\infty} \\phi_n(x), \\phi_n \\in {\\rm DNN}_1 \\}. \n\t\t$$\n\t\\end{description}\n\tFollow there facts, we know that\n\t$$\n\t\\sigma'(b)x_i \\in {\\rm DNN}_1,\n\t$$\n\tthis leads to \n\t$$\n\tx_i \\in \t\\overline{\\rm DNN}_1,\n\t$$\n\tbecause  $[\\sigma'(b)]^{-1} \\phi_n(x) \\to x_i$.\n\t\n\tThus we have\n\t$$\n\t\\frac{\\partial^2}{\\partial [w]_1 \\partial [w]_2} \\left(\\sigma(wx+b)\\right) |_{w=0} = \\sigma^{(2)}(b)x_1x_2.\n\t$$\n\tUsing the Lemma \\ref{lemm:dsigma} again, there exists a $b \\in \\mathbb{R}$ such that\n\t$$\n\t\\sigma^{(2)}(b) \\neq 0.\n\t$$\n\tThis leads to \n\t$$\n\tx_1x_2 \\in \\overline{\\rm DNN}_1 .\n\t$$\n\tSimilarly, we can prove that\n\t$$\n\tx_1^{\\alpha_1} x_2^{\\alpha_2} \\cdots x_d^{\\alpha_d} \\in \\overline{\\rm DNN}_1.\n\t$$\n\tThis proves that ${\\rm DNN}_1$ can approximate any polynomials.\n\tCombine with the Weierstrass theorem, ${\\rm DNN}_1$ can approximate any continuous functions.\n\t\n\tThen we will finish the proof for any $\\sigma$ as a non-polynomial Riemann integrable function and $\\sigma\\in L_{loc}^\\infty(\\mathbb{R})$.\n\\end{proof}\n\n\\iffalse\nGiven an activation function\n\\begin{equation}\n  \\label{activation}\n\\sigma: \\mathbb R^1\\mapsto \\mathbb R^1  \n\\end{equation}\nWe consider the following shallow neural network function class\n\\begin{equation}\n  \\label{ShallowNN}\n\t\\Sigma_d(\\sigma)=\\mathrm{span}\\left\\{\\sigma(\\omega\\cdot x+\\theta):\\omega\\in\\mathbb{R}^d,\\theta\\in\\mathbb{R}\\right\\}.\n\\end{equation}\n\nIn this chapter, we will two theorems as follows. \n\\begin{theorem}\nLet $\\sigma$ be a non-polynomial Riemann integrable function and\n$\\sigma\\in L_{loc}^\\infty(\\mathbb{R})$. Then $\\Sigma_d(\\sigma)$ in dense in\n$C(\\mathbb R^d)$.\t\n\\end{theorem}\n\\fi \n\n\\begin{theorem}\nLet $\\Omega\\subset \\mathbb{R}^d$ be a bounded set, $\\sigma\\in W^{m,\\infty}(\\mathbb R)$ that has \ncompact support such that \n\\begin{equation}\n  \\label{eq:1}\n  \\hat\\sigma(a)\\neq 0, \\mbox{ for some } a\\neq 0.\n\\end{equation}\nThen\n\\begin{equation}\n  \\label{eq:2}\n\\inf_{f_n\\in\\Sigma_n}\\|f-f_n\\|_{H^m( \\Omega)}\n\\le C(d,m)\\;n^{-{1\\over2}}\\int_{\\mathbb R^d}(1+|\\omega|)^{m+1}|\\hat f(\\omega)|\n\\end{equation}\n\\end{theorem}\n\n\\iffalse\n\t\\begin{lemma}\n\t\tLet $\\sigma\\in C^\\infty(\\mathbb{R})$ and assume $\\sigma$ is not a polynomial. Then $\\Sigma_n(\\sigma)$ is dense in $C(\\mathbb{R}^n)$.\n\t\\end{lemma}\n\t\\begin{proof}\n\t\tSince $\\sigma\\in C^\\infty(\\mathbb{R})$, and $[\\sigma((\\omega+h e_j)\\cdot x+\\theta)-\\sigma(\\omega\\cdot x+\\theta)]/h\\in\\Sigma_n(\\sigma)$ for every $\\omega,\\theta$ and $h\\ne0$, it follows that \n\t\t$\\frac{\\partial}{\\partial \\omega_j}\\sigma(\\omega\\cdot x+\\theta)\\in\\overline{\\Sigma}_n(\\sigma)$ for all $j=1:n$. By the same argument $\\frac{\\partial^k}{\\partial \\omega^k_j}\\sigma(\\omega\\cdot x+\\theta)\\in\\overline{\\Sigma}_n(\\sigma)$ for all $k\\in\\mathbb{N}$, $j=1:n$, $\\omega\\in\\mathbb{R}^n$ and $\\theta\\in\\mathbb{R}$.\n\t\t\n\t\tNow $\\frac{\\partial^k}{\\partial \\omega^k_j}\\sigma(\\omega\\cdot x+\\theta)=x_j^k\\sigma^{(k)}(\\omega\\cdot x+\\theta)$, and since $\\sigma$ is not a polynomial there exists a $\\theta_k\\in\\mathbb{R}$ such that $\\sigma^{(k)}(\\theta_k)\\ne0$. Take $\\omega=0$ and $\\theta=\\theta_k$, we then have $x_j^k\\in\\overline{\\Sigma}_n(\\sigma)$. Similarly, for all polynomials of the form $x_1^{k_1}\\cdots x_n^{k_n}$, we can get them by taking the corresponding partial derivatives.\n\t\t\n\t\tThis implies that $\\overline{\\Sigma}_n(\\sigma)$ contains all polynomials. By Weierstrass's Theorem it follows that $\\overline{\\Sigma}_n(\\sigma)$ contains $C(K)$ for each compact $K\\subset\\mathbb{R}^n$. That is $\\Sigma_n(\\sigma)$ is dense in $C(\\mathbb{R}^n)$.\n\t\t\\end{proof}\n\t\n\t\\fi\n\nThe first proof for this lemma above can be found in \\cite{leshno1993multilayer} and summarized in \\cite{pinkus1999approximation}.\nThe next theorem plays an important role in the proof of above lemma, which is first proved\nin \\cite{leshno1993multilayer} with several steps. Here we can present a more direct and simple version.\n%\n%\\begin{proposition}\n%\tIf $\\Sigma_1$ is dense in $C(\\mathbb{R})$, then $\\Sigma_n$ is dense in $C(\\mathbb{R}^n)$.\n%\t\\end{proposition}\n%\n%\n%\n%From now on, we will focus on $\\mathbb{R}$.\n\n\\begin{theorem}\n\t\\label{prop:conti}\nLet $\\sigma$ be a non-polynomial Riemann integrable function and $\\sigma\\in L_{loc}^\\infty(\\mathbb{R})$. Then $\\Sigma_1(\\sigma)$ in dense in $C(\\mathbb{R})$.\n\\end{theorem}\n\\begin{proof}\n\tConsider the mollifier $\\eta$\n\t\\begin{equation*}\\eta(x)=\\left\\{\n\t\\begin{aligned}\n\tCexp(\\frac{1}{|x|^2-1}),\\quad&|x|<1,\\\\\n \t0,\\qquad\\qquad\\qquad\\quad  &|x|\\ge1.\n\t\\end{aligned}\n\t\\right.\n\t\\end{equation*}\n\there C is selected so that $\\int_{\\mathbb{R}}\\eta dx=1.$\n\t\n\tSet $\\eta_\\epsilon=\\frac{1}{\\epsilon}\\eta(\\frac{x}{\\epsilon})$. Then consider $\\sigma_{\\eta_\\epsilon}$\n\\begin{equation}\n\t\\sigma_{\\eta_\\epsilon}(x):=\\sigma\\ast{\\eta_\\epsilon}(x)=\\int_{\\mathbb{R}}\\sigma(x-y){\\eta_\\epsilon}(y)dy\n\\end{equation}\n\nIt can be seen that $\\sigma_{\\eta_\\epsilon}\\in\nC^\\infty(\\mathbb{R})$. Following the proof in the previous\nproposition, we want to show that $\\overline{\\Sigma}_1(\\sigma)$\ncontains all polynomials.  The first step is to show that\n$\\overline{\\Sigma}_1(\\sigma_{\\eta_\\epsilon})\\subset\\overline{\\Sigma}_1(\\sigma)$,\nwhich can be done easily by checking the Riemann sum of\n$\\sigma_{\\eta_\\epsilon}(x)=\\int_{\\mathbb{R}}\\sigma(x-y){\\eta_\\epsilon}(y)dy$\nis in $\\overline{\\Sigma}_1(\\sigma)$.\n\nThen it suffices to show that there exists $\\theta_k$ and\n$\\sigma_{\\eta_\\epsilon}$ such that\n$\\sigma_{\\eta_\\epsilon}^{(k)}(\\theta_k)\\ne0$ for each k. If not, then\nthere must be $k_0$ such that\n$\\sigma_{\\eta_\\epsilon}^{(k_0)}(\\theta)=0$ for all\n$\\theta\\in\\mathbb{R}$ and all $\\epsilon>0$.  Thus\n$\\sigma_{\\eta_\\epsilon}$'s are all polynomials with degree at most\n$k_0-1$.  In particular, It is known that $\\eta_\\epsilon\\in\nC_0^\\infty(\\mathbb{R})$ and $\\sigma\\ast\\eta_\\epsilon$ uniformly\nconverges to $\\sigma$ on compact sets in $\\mathbb{R}$ and\n$\\sigma\\ast\\eta_\\epsilon$'s are all polynomials of degree at most\n$k_0-1$. Polynomials of a fixed degree form a closed linear subspace,\ntherefore $\\sigma$ is also a polynomial of degree at most $k_0-1$,\nwhich leads to contradiction.\n\\end{proof}\n\n", "meta": {"hexsha": "82d7e746e01c0a337aa372fe497b654c7a82582f", "size": 9342, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/nonpoly.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/nonpoly.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/nonpoly.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.2714932127, "max_line_length": 461, "alphanum_fraction": 0.6668807536, "num_tokens": 3462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.6889368689807652}}
{"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\nBhabha scattering is the result of interactions between positrons and electrons.\nThe following diagram represents a collider experiment with\ncollinear electron and positron beams.\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] {$e^+$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$e^+$};\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\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, v_1$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$p_3, v_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 a typical collider experiment the momentum vectors are\n\\begin{equation*}\n\\underset{\\text{inbound positron}}\n{p_1=\\begin{pmatrix}E\\\\0\\\\0\\\\p\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound electron}}\n{p_2=\\begin{pmatrix}E\\\\0\\\\0\\\\-p\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound positron}}\n{p_3=\\begin{pmatrix}\nE\\\\\np\\sin\\theta\\cos\\phi\\\\\np\\sin\\theta\\sin\\phi\\\\\np\\cos\\theta\n\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound electron}}\n{p_4=\\begin{pmatrix}\nE\\\\\n-p\\sin\\theta\\cos\\phi\\\\\n-p\\sin\\theta\\sin\\phi\\\\\n-p\\cos\\theta\n\\end{pmatrix}}\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{gather*}\n\\underset{\\text{inbound positron, spin up}}\n{v_{11}=\\begin{pmatrix}p\\\\0\\\\E+m\\\\0\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound positron, spin down}}\n{v_{12}=\\begin{pmatrix}0\\\\-p\\\\0\\\\E+m\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound electron, spin up}}\n{u_{21}=\\begin{pmatrix}E+m\\\\0\\\\-p\\\\0\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound electron, spin down}}\n{u_{22}=\\begin{pmatrix}0\\\\E+m\\\\0\\\\p\\end{pmatrix}}\n\\\\\n\\underset{\\text{outbound positron, spin up}}\n{v_{31}=\\begin{pmatrix}p_3^z\\\\p_3^x+ip_3^y\\\\E+m\\\\0\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound positron, spin down}}\n{v_{32}=\\begin{pmatrix}p_3^x-ip_3^y\\\\-p_3^z\\\\0\\\\E+m\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound electron, spin up}}\n{u_{41}=\\begin{pmatrix}E+m\\\\0\\\\p_4^z\\\\p_4^x+ip_4^y\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound electron, spin down}}\n{u_{42}=\\begin{pmatrix}0\\\\E+m\\\\p_4^x-ip_4^y\\\\-p_4^z\\end{pmatrix}}\n\\end{gather*}\n\n\\noindent\nThe spinors shown above are not individually normalized.\nInstead, a combined spinor normalization constant $N=(E+m)^4$\nwill be used.\n\n\\bigskip\n\\noindent\nThe following formula computes a probability density $|\\mathcal{M}_{abcd}|^2$\nfor Bhabha scattering where $abcd$ are spin states.\n\\begin{equation*}\n|\\mathcal{M}_{abcd}|^2=\\frac{e^4}{N}\n\\left|\n-\\frac{1}{t}(\\bar{v}_{1a}\\gamma^\\mu v_{3c})(\\bar{u}_{4d}\\gamma_\\mu u_{2b})\n+\\frac{1}{s}(\\bar{v}_{1a}\\gamma^\\nu u_{2b})(\\bar{u}_{4d}\\gamma_\\nu v_{3c})\n\\right|^2\n\\end{equation*}\n\n\\noindent\nSymbol $e$ is electron charge.\nSymbols $s$ and $t$ are Mandelstam variables\n\\begin{align*}\ns&=(p_1+p_2)^2\n\\\\\nt&=(p_1-p_3)^2\n\\end{align*}\n\n\\noindent\nLet\n\\begin{equation*}\na_1=(\\bar{v}_{1a}\\gamma^\\mu v_{3c})(\\bar{u}_{4d}\\gamma_\\mu u_{2b})\n\\qquad\na_2=(\\bar{v}_{1a}\\gamma^\\nu u_{2b})(\\bar{u}_{4d}\\gamma_\\nu v_{3c})\n\\end{equation*}\n\n\\noindent\nThen\n\\begin{align*}\n|\\mathcal{M}_{abcd}|^2\n&=\n\\frac{e^4}{N}\\left|{-\\frac{a_1}{t}} + \\frac{a_2}{s}\\right|^2\\\\\n&=\n\\frac{e^4}{N}\\left(-\\frac{a_1}{t} + \\frac{a_2}{s}\\right)\\left(-\\frac{a_1}{t} + \\frac{a_2}{s}\\right)^*\\\\\n&=\n\\frac{e^4}{N}\n\\left(\n\\frac{a_1a_1^*}{t^2} - \\frac{a_1a_2^*}{st} -\n\\frac{a_1^*a_2}{st} + \\frac{a_2a_2^*}{s^2}\n\\right)\n\\end{align*}\n\n\\noindent\nThe expected probability density $\\langle|\\mathcal{M}|^2\\rangle$ is computed\nby summing $|\\mathcal{M}_{abcd}|^2$ over all spin states and then dividing by the number of inbound states.\nThere are four inbound states.\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=\n\\frac{1}{4}\\sum_{a=1}^2\\sum_{b=1}^2\\sum_{c=1}^2\\sum_{d=1}^2\n|\\mathcal{M}_{abcd}|^2\\\\\n&=\n\\frac{e^4}{4N}\\sum_{a=1}^2\\sum_{b=1}^2\\sum_{c=1}^2\\sum_{d=1}^2\n\\left(\n\\frac{a_1a_1^*}{t^2} - \\frac{a_1a_2^*}{st} -\n\\frac{a_1^*a_2}{st} + \\frac{a_2a_2^*}{s^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_{abcd}a_1a_1^*=\n\\mathop{\\rm Tr}\\left(\n(\\slashed{p}_1-m)\\gamma^\\mu(\\slashed{p}_3-m)\\gamma^\\nu\n\\right)\n\\mathop{\\rm Tr}\\left(\n(\\slashed{p}_4+m)\\gamma_\\mu(\\slashed{p}_2+m)\\gamma_\\nu\n\\right)\n\\\\\nf_{12}&=\\frac{1}{N}\\sum_{abcd}a_1a_2^*=\n\\mathop{\\rm Tr}\\left(\n(\\slashed{p}_1-m)\\gamma^\\mu(\\slashed{p}_2+m)\\gamma^\\nu\n(\\slashed{p}_4+m)\\gamma_\\mu(\\slashed{p}_3-m)\\gamma_\\nu\n\\right)\n\\\\\nf_{22}&=\\frac{1}{N}\\sum_{abcd}a_2a_2^*=\n\\mathop{\\rm Tr}\\left(\n(\\slashed{p}_1-m)\\gamma^\\mu(\\slashed{p}_2+m)\\gamma^\\nu\n\\right)\n\\mathop{\\rm Tr}\\left(\n(\\slashed{p}_4+m)\\gamma_\\mu(\\slashed{p}_3-m)\\gamma_\\nu\n\\right)\n\\end{align*}\n\n\\noindent\nHence\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=\\frac{e^4}{4}\n\\left(\n\\frac{f_{11}}{t^2} - \\frac{f_{12}}{st} -\n\\frac{f_{12}^*}{st} + \\frac{f_{22}}{s^2}\n\\right)\n\\end{equation*}\n\n\\noindent\nRun ``bhabha-scattering-1.txt'' to verify the Casimir trick.\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}&=\n32(p_1\\cdot p_2)^2\n+32(p_1\\cdot p_4)^2\n-64 m^2(p_1\\cdot p_3)\n+64 m^4\n\\\\\nf_{12}&=\n-32 (p_1\\cdot p_4)^2\n-32 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)\n-32 m^4\n\\\\\nf_{22}&=\n32(p_1\\cdot p_3)^2\n+32(p_1\\cdot p_4)^2\n+64 m^2(p_1\\cdot p_2)\n+64 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{align*}\nf_{11} &= 8 s^2 + 8 u^2 - 64 s m^2 - 64 u m^2 + 192 m^4\n\\\\\nf_{12} &= -8 u^2 + 64 u m^2 - 96 m^4\n\\\\\nf_{22} &= 8 t^2 + 8 u^2 - 64 t m^2 - 64 u m^2 + 192 m^4\n\\end{align*}\n\n\\subsection*{High energy approximation}\nWhen $E\\gg m$ a useful approximation is to set $m=0$ and obtain\n\\begin{align*}\nf_{11}&= 8 s^2 + 8 u^2\\\\\nf_{12}&= -8 u^2\\\\\nf_{22}&= 8 t^2 + 8 u^2\n\\end{align*}\n\n\\noindent\nHence\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=\\frac{e^4}{4}\n\\left(\n\\frac{f_{11}}{t^2} - \\frac{f_{12}}{st} -\n\\frac{f_{12}^*}{st} + \\frac{f_{22}}{s^2}\n\\right)\n\\\\\n&=\\frac{e^4}{4}\n\\left(\n\\frac{8s^2+8u^2}{t^2} - \\frac{-8u^2}{st} - \\frac{-8u^2}{st} + \\frac{8t^2+8u^2}{s^2}\n\\right)\n\\\\\n&=2e^4\n\\left(\n\\frac{s^2+u^2}{t^2} + \\frac{2u^2}{st} + \\frac{t^2+u^2}{s^2}\n\\right)\n\\end{align*}\n\n\\noindent\nCombine terms so $\\langle|\\mathcal{M}|^2\\rangle$ has a common denominator.\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=2e^4\n\\left(\\frac{s^2\\left(s^2+u^2\\right)+2stu^2+t^2\\left(t^2+u^2\\right)}{s^2t^2}\\right)\n\\end{equation*}\n\n\\noindent\nFor $m=0$ the Mandelstam variables are\n\\begin{align*}\ns&=4E^2\n\\\\\nt&=2E^2(\\cos\\theta-1)\n\\\\\nu&=-2E^2(\\cos\\theta+1)\n\\end{align*}\n\n\\noindent\nHence\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=2e^4\n\\left(\n\\frac{32E^8\\cos^4\\theta+192E^8\\cos^2\\theta+288E^8}{64E^8(\\cos\\theta-1)^2}\n\\right)\n\\\\\n&=e^4\n\\left(\n\\frac{\\cos^4\\theta+6\\cos^2\\theta+9}{(\\cos\\theta-1)^2}\n\\right)\n\\\\\n&=e^4\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^2\n\\end{align*}\n\n\\noindent\nRun ``bhabha-scattering-2.txt'' to verify.\n\n\\subsection*{Cross section}\nThe differential cross section is\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}\n=\\frac{\\langle|\\mathcal{M}|^2\\rangle}{64\\pi^2s}\n=\\frac{e^4}{64\\pi^2s}\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^2,\\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}{4s}\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^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*}\n\n\\noindent\nHence\n\\begin{equation*}\nd\\sigma=\\frac{\\alpha^2}{4s}\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^2\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&=\\frac{4s}{2\\pi\\alpha^2}\n\\int_0^{2\\pi}\\int d\\sigma\n\\\\\n&=\\int\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^2\n\\sin\\theta\\,d\\theta,\n\\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.\nAssume that $I(\\theta)-I(a)$ 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(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 in the interval $\\theta_1$ to $\\theta_2$\ncan 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{1}{C}\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^2\n\\sin\\theta\n\\end{equation*}\n\n\\noindent\nRun ``bhabha-scattering-3.txt'' to draw $f(\\theta)$ for $a=\\pi/4=45^\\circ$.\n\n\\begin{center}\n\\includegraphics[scale=0.5]{bhabha-scattering.png}\n\\end{center}\n\n\\noindent\nProbability distribution for $45^\\circ$ bins ($a=45^\\circ$).\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.13 \\\\\n$135^\\circ$ & $180^\\circ$ & 0.04 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection*{Data from SLAC SPEAR experiment}\n\\noindent\nThe following Bhabha scattering data is adapted from SLAC-PUB-1501.\n\n\\begin{center}\n\\begin{tabular}{|lr|c|c|}\n\\hline\n& Bin & $x_k$, $x_{k+1}$ & $y$\\\\\n\\hline\n(Smallest $\\theta$) & $k=1$ & $0.6, 0.5$ & 4432\\\\\n& 2 & $0.5, 0.4$ & 2841\\\\\n& 3 & $0.4, 0.3$ & 2045\\\\\n& 4 & $0.3, 0.2$ & 1420\\\\\n& 5 & $0.2, 0.1$ & 1136\\\\\n& 6 & $0.1, 0.0$ & 852\\\\\n& 7 & $0.0, -0.1$ & 656\\\\\n& 8 & $-0.1, -0.2$ & 625\\\\\n& 9 & $-0.2, -0.3$ & 511\\\\\n& 10 & $-0.3, -0.4$ & 455\\\\\n& 11 & $-0.4, -0.5$ & 402\\\\\n(Largest $\\theta$) & 12 & $-0.5, -0.6$ & 398\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nData column $x$ is $\\cos\\theta$ of scattering angle $\\theta$,\ndata column $y$ is number of scattering events.\n\n\\bigskip\n\\noindent\nTo compute predicted values $\\hat{y}$, start by integrating\nthe probability density function over each bin.\n\\begin{equation*}\nI_k=\\int_{\\arccos(x_k)}^{\\arccos(x_{k+1})}\n\\left(\n\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\n\\right)^2\\sin\\theta\\,d\\theta\n\\end{equation*}\n\n\\noindent\nNormalize $I_k$ to obtain scattering probability $P_k$.\n\\begin{equation*}\nP_k=\\frac{I_k}{N},\\quad N=\\sum_{j=1}^{12}I_j\n\\end{equation*}\n\n\\noindent\nMultiply $P_k$ by total counts to obtain $\\hat{y}_k$.\n\\begin{equation*}\n\\hat{y}_k=P_k T,\\quad T=\\sum_{j=1}^{12}y_j=15773\n\\end{equation*}\n\n\\begin{center}\n\\begin{tabular}{|r|c|c|c|}\n\\hline\nBin & $x_k$, $x_{k+1}$ & $y$ & $\\hat{y}$ \\\\\n\\hline\n1 & $0.6, 0.5$ & 4432 & 4598\\\\\n2 & $0.5, 0.4$ & 2841 & 2880\\\\\n3 & $0.4, 0.3$ & 2045 & 1955\\\\\n4 & $0.3, 0.2$ & 1420 & 1410\\\\\n5 & $0.2, 0.1$ & 1136 & 1068\\\\\n6 & $0.1, 0.0$ & 852 & 843\\\\\n7 & $0.0, -0.1$ & 656 & 689\\\\\n8 & $-0.1, -0.2$ & 625 & 582\\\\\n9 & $-0.2, -0.3$ & 511 & 505\\\\\n10 & $-0.3, -0.4$ & 455 & 450\\\\\n11 & $-0.4, -0.5$ & 402 & 411\\\\\n12 & $-0.5, -0.6$ & 398 & 382\\\\\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.997\n\\end{equation*}\n\n\\noindent\nThe result indicates that the model $d\\sigma$ explains\n99.7\\% of the variance in the data.\n\n\\bigskip\n\\noindent\nRun ``bhabha-scattering-4.txt'' to verify.\n\n\\subsection*{Data from DESY PETRA experiment}\nSee www.hepdata.net/record/ins191231, Table 3, 14.0 GeV.\n\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\n$x$ & $y$\\\\\n\\hline\n$-0.73\\phantom{00}$ & 0.10115\\\\\n$-0.6495$ & 0.12235\\\\\n$-0.5495$ & 0.11258\\\\\n$-0.4494$ & 0.09968\\\\\n$-0.3493$ & 0.14749\\\\\n$-0.2491$ & 0.14017\\\\\n$-0.149\\phantom{0}$ & 0.1819\\phantom{0}\\\\\n$-0.0488$ & 0.22964\\\\\n$\\phantom{+}0.0514$ & 0.25312\\\\\n$\\phantom{+}0.1516$ & 0.30998\\\\\n$\\phantom{+}0.252\\phantom{0}$ & 0.40898\\\\\n$\\phantom{+}0.3524$ & 0.62695\\\\\n$\\phantom{+}0.4529$ & 0.91803\\\\\n$\\phantom{+}0.5537$ & 1.51743\\\\\n$\\phantom{+}0.6548$ & 2.56714\\\\\n$\\phantom{+}0.7323$ & 4.30279\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nData $x$ and $y$ have the following relationship\nwith the cross section model.\n\\begin{equation*}\nx=\\cos\\theta\n\\qquad\ny=\\frac{d\\sigma}{d\\Omega}\n\\end{equation*}\n\n\\noindent\nThe cross section formula for Bhabha scattering is\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}\n=\\frac{\\alpha^2}{4s}\n\\left(\\frac{\\cos^2\\theta+3}{\\cos\\theta-1}\\right)^2\n\\end{equation*}\n\n\\noindent\nTo compute predicted values $\\hat{y}$,\nsubstitute $x$ for $\\cos\\theta$,\nmultiply by $(\\hbar c)^2$ to convert to SI,\nand multiply by $10^{37}$ to convert square meters to nanobarns.\n\\begin{equation*}\n\\hat{y}\n=\\frac{\\alpha^2}{4s}\n\\left(\\frac{x^2+3}{x-1}\\right)^2\n\\times(\\hbar c)^2\n\\times10^{37}\n\\end{equation*}\n\n\\noindent\nThe following table shows $\\hat{y}$ for $s=(14.0\\,\\text{GeV})^2$.\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$x$ & $y$ & $\\hat{y}$\\\\\n\\hline\n$-0.73\\phantom{00}$ & 0.10115 & 0.110296\\\\\n$-0.6495$ & 0.12235 & 0.113816\\\\\n$-0.5495$ & 0.11258 & 0.120101\\\\\n$-0.4494$ & 0.09968 & 0.129075\\\\\n$-0.3493$ & 0.14749 & 0.141592\\\\\n$-0.2491$ & 0.14017 & 0.158934\\\\\n$-0.149\\phantom{0}$ & 0.1819\\phantom{0} & 0.182976\\\\\n$-0.0488$ & 0.22964 & 0.216737\\\\\n$\\phantom{+}0.0514$ & 0.25312 & 0.264989\\\\\n$\\phantom{+}0.1516$ & 0.30998 & 0.335782\\\\\n$\\phantom{+}0.252\\phantom{0}$ & 0.40898 & 0.44363\\phantom{0}\\\\\n$\\phantom{+}0.3524$ & 0.62695 & 0.615528\\\\\n$\\phantom{+}0.4529$ & 0.91803 & 0.9077\\phantom{00}\\\\\n$\\phantom{+}0.5537$ & 1.51743 & 1.45175\\phantom{0}\\\\\n$\\phantom{+}0.6548$ & 2.56714 & 2.60928\\phantom{0}\\\\\n$\\phantom{+}0.7323$ & 4.30279 & 4.61509\\phantom{0}\\\\\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.995\n\\end{equation*}\n\n\\noindent\nThe result indicates that the model $d\\sigma$ explains 99.5\\% of the variance in the data.\n\n\\bigskip\n\\noindent\nRun ``bhabha-scattering-5.txt'' to verify.\n\n\\subsection*{Notes}\nHere are a few notes about how the Eigenmath scripts work.\nIn component notation the trace operators of the Casimir trick become sums over the repeated index $\\alpha$.\n\\begin{align*}\nf_{11}&=\n\\left(\n(\\slashed{p}_1-m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_3-m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\alpha\n\\right)\n\\left(\n(\\slashed{p}_4+m)^\\alpha{}_\\beta\n\\gamma_\\mu{}^\\beta{}_\\rho\n(\\slashed{p}_2+m)^\\rho{}_\\sigma\n\\gamma_\\nu{}^\\sigma{}_\\alpha\n\\right)\n\\\\\nf_{12}&=\n(\\slashed{p}_1-m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_2+m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\tau\n(\\slashed{p}_4+m)^\\tau{}_\\delta\n\\gamma_\\mu{}^\\delta{}_\\eta\n(\\slashed{p}_3-m)^\\eta{}_\\xi\n\\gamma_\\nu{}^\\xi{}_\\alpha\n\\\\\nf_{22}&=\n\\left(\n(\\slashed{p}_1-m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_2+m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\alpha\n\\right)\n\\left(\n(\\slashed{p}_4+m)^\\alpha{}_\\beta\n\\gamma_\\mu{}^\\beta{}_\\rho\n(\\slashed{p}_3-m)^\\rho{}_\\sigma\n\\gamma_\\nu{}^\\sigma{}_\\alpha\n\\right)\n\\end{align*}\n\n\\noindent\nTo convert the above formulas to Eigenmath code,\nthe $\\gamma$ tensors need to be transposed\nso that repeated indices are adjacent to each other.\nAlso, multiply $\\gamma^\\mu$ by the metric tensor to lower the index.\n\\begin{align*}\n\\gamma^{\\beta\\mu}{}_\\rho\\quad&\\rightarrow\\quad\n\\text{\\tt gammaT = transpose(gamma)}\\\\\n\\gamma^\\beta{}_{\\mu\\rho}\\quad&\\rightarrow\\quad\n\\text{\\tt gammaL = transpose(dot(gmunu,gamma))}\n\\end{align*}\n\n\\noindent\nDefine the following $4\\times4$ matrices.\n\\begin{align*}\n(\\slashed{p}_1-m)\\quad&\\rightarrow\\quad\\text{\\tt X1 = pslash1 - m I}\\\\\n(\\slashed{p}_2+m)\\quad&\\rightarrow\\quad\\text{\\tt X2 = pslash2 + m I}\\\\\n(\\slashed{p}_3-m)\\quad&\\rightarrow\\quad\\text{\\tt X3 = pslash3 - m I}\\\\\n(\\slashed{p}_4+m)\\quad&\\rightarrow\\quad\\text{\\tt X4 = pslash4 + m I}\n\\end{align*}\n\n\\noindent\nThen for $f_{11}$ we have the following Eigenmath code.\nThe contract function sums over $\\alpha$.\n\\begin{align*}\n(\\slashed{p}_1-m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_3-m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\alpha\n\\quad&\\rightarrow\\quad\n\\text{\\tt T1 = contract(dot(X1,gammaT,X3,gammaT),1,4)}\\\\\n(\\slashed{p}_4+m)^\\alpha{}_\\beta\n\\gamma_\\mu{}^\\beta{}_\\rho\n(\\slashed{p}_2+m)^\\rho{}_\\sigma\n\\gamma_\\nu{}^\\sigma{}_\\alpha\n\\quad&\\rightarrow\\quad\n\\text{\\tt T2 = contract(dot(X4,gammaL,X2,gammaL),1,4)}\n\\end{align*}\n\n\\noindent\nNext, multiply then sum over repeated indices.\nThe dot function sums over $\\nu$ then the contract function\nsums over $\\mu$. The transpose makes the $\\nu$ indices adjacent\nas required by the dot function.\n$$\nf_{11}=\n\\mathop{\\rm Tr}(\\cdots\\gamma^\\mu\\cdots\\gamma^\\nu)\n\\mathop{\\rm Tr}(\\cdots\\gamma_\\mu\\cdots\\gamma_\\nu)\n\\quad\\rightarrow\\quad\n\\text{\\tt f11 = contract(dot(T1,transpose(T2)))}\n$$\n\n\\noindent\nFollow suit for $f_{22}$.\n\\begin{align*}\n(\\slashed{p}_1-m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_2+m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\alpha\n\\quad&\\rightarrow\\quad\n\\text{\\tt T1 = contract(dot(X1,gammaT,X2,gammaT),1,4)}\n\\\\\n(\\slashed{p}_4+m)^\\alpha{}_\\beta\n\\gamma_\\mu{}^\\beta{}_\\rho\n(\\slashed{p}_3-m)^\\rho{}_\\sigma\n\\gamma_\\nu{}^\\sigma{}_\\alpha\n\\quad&\\rightarrow\\quad\n\\text{\\tt T2 = contract(dot(X4,gammaL,X3,gammaL),1,4)}\n\\end{align*}\n\n\\noindent\nHence\n$$\nf_{22}=\n\\mathop{\\rm Tr}(\\cdots\\gamma^\\mu\\cdots\\gamma^\\nu)\n\\mathop{\\rm Tr}(\\cdots\\gamma_\\mu\\cdots\\gamma_\\nu)\n\\quad\\rightarrow\\quad\n\\text{\\tt f22 = contract(dot(T1,transpose(T2)))}\n$$\n\n\\noindent\nThe calculation of $f_{12}$ begins with\n\\begin{multline*}\n(\\slashed{p}_1-m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_2+m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\tau\n(\\slashed{p}_4+m)^\\tau{}_\\delta\n\\gamma_\\mu{}^\\delta{}_\\eta\n(\\slashed{p}_3-m)^\\eta{}_\\xi\n\\gamma_\\nu{}^\\xi{}_\\alpha\n\\\\\n\\rightarrow\\quad\n\\text{\\tt T = contract(dot(X1,gammaT,X2,gammaT,X4,gammaL,X3,gammaL),1,6)}\n\\end{multline*}\n\n\\noindent\nThen sum over repeated indices $\\mu$ and $\\nu$.\n$$\nf_{12}=\\mathop{\\rm Tr}(\\cdots\\gamma^\\mu\\cdots\\gamma^\\nu\\cdots\\gamma_\\mu\\cdots\\gamma_\\nu)\n\\quad\\rightarrow\\quad\n\\text{\\tt f12 = contract(contract(T,1,3))}\n$$\n\n%F(theta) = -37/8 cos(theta) - 1/4 cos(2 theta) - 1/24 cos(3 theta) - 4 / sin(theta/2)^2 - 16 log(sin(theta/2))\n\n%\\subsection*{Epilogue}\n%This is the closed form of $I(\\theta)$.\n%\\begin{equation*}\n%I(\\theta)=-\\tfrac{37}{8}\\cos\\theta - \\tfrac{1}{4}\\cos(2\\theta)\n%- \\tfrac{1}{24}\\cos(3\\theta) - \\frac{4}{\\sin(\\theta/2)^2} - 16\\log(\\sin(\\theta/2))\n%\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "b6679a571dc94f677e45130174a3f35a7777c6fa", "size": 19422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bhabha-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": "bhabha-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": "bhabha-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.0606451613, "max_line_length": 111, "alphanum_fraction": 0.6485943775, "num_tokens": 8550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6889259500082433}}
{"text": "\n\\subsection{Generative and discriminative models}\n\n\\subsubsection{Recap}\n\nFor parametric models without dependent variables we have a form:\n\n\\(P(y| \\theta )\\)\n\nAnd we have various ways of estimating \\(\\theta \\).\n\nWe can write this as a likelihood function:\n\n\\(L(\\theta ;y )=P(y|\\theta)\\)\n\n\\subsubsection{Discriminative models}\n\nIn discriminative models we learn:\n\n\\(P(y|X, \\theta )\\)\n\nWhich we can write as a likelihood function:\n\n\\(L(\\theta ;y, X )=P(y| X, \\theta)\\)\n\n\\subsubsection{Generative models}\n\nIn generative models we learn:\n\n\\(P(y, X| \\theta )\\)\n\nWhich we can write as a likelihood function:\n\n\\(L(\\theta ;y, X )=P(y, X|\\theta)\\)\n\nWe can use the generative model to calculate dependent probabilities.\n\n\\(P(y| X, \\theta )=\\dfrac{P(y, X| \\theta )P(\\theta )}{P(X, \\theta )}\\)\n\n\\(P(y| X, \\theta )=\\dfrac{P(y, X| \\theta )}{P(X| \\theta )}\\)\n\n", "meta": {"hexsha": "5c0d529b1a0cbfc75f408ae6e9bd8490d4ac73e8", "size": 847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/01-01-generativeDiscriminative.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/01-01-generativeDiscriminative.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/01-01-generativeDiscriminative.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.1666666667, "max_line_length": 70, "alphanum_fraction": 0.6682408501, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6889259449922994}}
{"text": "\\section{Update equations}\n\\label{sec:GRU_eqs}\n\nThe RNN type that we choose for SWR detection is the so called \\emph{gated recurrent units} RNN, or \\emph{GRU} \\cite{Cho2014}. It is closely related to the popular ``long short-term memory'' (LSTM) RNN \\cite{Hochreiter1997,Greff2017}. The update equations for the GRU are simpler than those of the LSTM however, while achieving comparable performance \\cite{Chung2014}.\n\nThe state-update function $f$ and the readout function $g$ are defined as follows for a GRU RNN:\n%\n\\begin{align}\nf:\\ \\h_t     &= \\update \\had \\h\\prev \n                + (1-\\update) \\had \\hcand, \\label{eq:hnew}\\\\\ng:\\ n_t  &= \\sigma( \\vb{w}_{hn}\\trans \\h_t + b_n )      \\label{eq:out}\n\\end{align}\nwith\n\\begin{align}\n\\hcand  &= \\tanh( \\reset \\had \\W_{hh} \\h\\prev \n                   + \\W_{zh} \\z_t + \\bias_h ),  \\label{eq:hcand}\\\\\n\\update &= \\sigma( \\W_{hu} \\h\\prev \n                   + \\W_{zu} \\z_t + \\bias_u),   \\label{eq:update}\\\\\n\\reset  &= \\sigma( \\W_{hr} \\h\\prev \n                   + \\W_{zr} \\z_t + \\bias_r ).  \\label{eq:reset}\n\\end{align}\n$\\tanh$ is the hyperbolic tangent, and $\\sigma$ is the logistic sigmoid, defined as $\\sigma(x) = 1 / (1 + \\exp(-x))$. They are applied point-wise, i.e. separately to each element of their argument vector. Similarly, ``$\\had$'' denotes point-wise multiplication.  $\\sigma$ compresses the real number line to $(0, 1)$, while $\\tanh(x) = 2\\ \\sigma(x) - 1$ maps it to $(-1, 1)$. Therefore, for this RNN, $\\h_t \\in (-1, 1)^M$ and the output $n_t \\in (0, 1)$.\n\nThe coefficients in the matrices $\\W_\\_$ and in the vectors $\\bias_\\_$ are called the \\emph{weights} and \\emph{biases} of the RNN, respectively.\\footnotemark{} They are parameters of the algorithm, determined a priori (i.e. before online SWR detection), through an optimisation procedure described in \\cref{sec:RNN-optim}.\n\n\\footnotetext{Often collectively referred to simply as the weights. The vector $\\vb{w}_{hn}$ and the scalar $b_n$ are also part of the weights and biases. They may be regarded as a one-row matrix and a one-dimensional vector, respectively.}\n\nFrom \\cref{eq:hnew}, each element of the hidden state $\\h_t$ is thus a weighted average of its existing value in $\\h\\prev$, and a candidate new value in $\\hcand$. The weighting, in $\\update$, depends on both the current input $\\z_t$, and the full previous hidden state $\\h\\prev$ (\\cref{eq:update}).\n\nSimilarly, each element of the candidate new hidden state $\\hcand$ is a function of both the current input $\\z_t$, and all elements of the previous hidden state $\\h\\prev$ (\\cref{eq:hcand}). A so called ``reset'' multiplier, in $\\reset$ (\\cref{eq:reset}), determines how much the existing memory values in $\\h\\prev$ influence the candidate new memory value, compared to the influence of the current input $\\z_t$. (When an element of $\\reset$ is $0$, the corresponding hidden unit in $\\hcand$ is only a function of the current input, and is thus decoupled from its past. The hidden unit in $\\h_t$ can therefore be `reset').\n\nFinally, the output signal $n_t$ is a linear projection of the hidden state, translated and squashed to be in $(0, 1)$ (\\cref{eq:out}).\n\nThe above equations \\labelcref{eq:hnew} to \\labelcref{eq:reset} for the GRU RNN define a so called one-layer network.\\footnotemark{} An RNN with $L$ layers has $L$ corresponding hidden unit vectors $\\h^{(1)}, \\h^{(2)}, \\tdots, \\h^{(L)}$, that may each have a different dimension. The update functions for these hidden unit vectors can be formulated as follows. If $f^{(1)}(\\h^{(1)}\\prev, \\z_t)$ is the function defined by \\cref{eq:update,eq:hcand,eq:reset,eq:hnew}, we can define similar functions $f^{(2)}(\\h^{(2)}\\prev, \\h^{(1)}_t), \\  f^{(3)}(\\h^{(3)}\\prev, \\h^{(2)}_t)$, and so forth. These functions all have the same form, but do not share weights and biases (i.e. each layer has separately learnable weights and biases). The output is then: $n_t = \\sigma( \\vb{w}_{hn}\\trans \\h^{(L)}_t + b_n )$; i.e. a readout of the last layer.\n\n\\footnotetext{That is, one layer per timestep. A recurrent neural network can also be regarded as a very deep feedforward neural network in which all the layers share the same weights.}\n", "meta": {"hexsha": "601c92c4b6badf9870a6d923fecf17e8e2822ce2", "size": 4167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/RNN/GRU-eqs.tex", "max_stars_repo_name": "tfiers/master-thesis", "max_stars_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-23T01:39:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-23T01:39:24.000Z", "max_issues_repo_path": "modules/RNN/GRU-eqs.tex", "max_issues_repo_name": "tfiers/master-thesis", "max_issues_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-10T22:37:35.000Z", "max_forks_repo_path": "modules/RNN/GRU-eqs.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": 112.6216216216, "max_line_length": 835, "alphanum_fraction": 0.6933045356, "num_tokens": 1255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096044278533, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6889259363802828}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{Infinite Radical Limit}\n\\author{Shreenabh Agrawal }\n\\date{\\today}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\geometry{a4paper, portrait, margin=1in}\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\nFind $x$ for which\n$$\\lim_{x\\to\\infty}\\sqrt{1+\\sqrt{x+\\sqrt{x^{2}+...\\ +\\ \\sqrt{x^{n}}}}}=2 $$\n\\section{Solution}\nThe key observation here is that\n$$t+1\\ =\\ \\sqrt{t^{2}+2t+1}$$\n$$=\\sqrt{t^{2}+\\sqrt{\\left(2t+1\\right)^{2}}}$$\n$$=\\ \\sqrt{t^{2}+\\sqrt{4t^{2}+4t+1}}$$\n$$=\\ \\sqrt{t^{2}+\\sqrt{4t^{2}+\\sqrt{\\left(4t+1\\right)^{2}}}}$$\n$$=\\ \\sqrt{t^{2}+\\sqrt{4t^{2}+\\sqrt{16t^{2}+\\sqrt{64t^{2}+...}}}}$$\nNow putting $t=1$, we get,\n$$2=\\ \\sqrt{1+\\sqrt{4+\\sqrt{16+\\sqrt{64+...}}}}$$\nHence, the answer is \n$$\\boxed{x=4}$$\n\n\n\n\\end{document}\n", "meta": {"hexsha": "e4ea506479410900231409eb5d74b14893d61f53", "size": 829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/mathelonn's questions/Infinite Radical Limit.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/mathelonn's questions/Infinite Radical Limit.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/mathelonn's questions/Infinite Radical Limit.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": 23.6857142857, "max_line_length": 75, "alphanum_fraction": 0.6139927624, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6889192712336206}}
{"text": "\\documentclass{report}\n\n\\usepackage[latin1]{inputenc}\n\\usepackage[danish]{babel}\n\\usepackage[T1]{fontenc}\n\\usepackage{amsmath,amssymb,bm,mathtools}\n\\usepackage{enumitem}\n\\usepackage{listings}\n\\usepackage{forest}\n\\usepackage[margin=1in]{geometry}\n\n\\begin{document}\n\\section*{AD - assignment 2}\n\\subsection*{Task 1}\nLet $N(C, i)$ denote the number the number of ways to spend exactly $C$ DKK with prices $p_1,\\ldots, p_i$. This formula can be written recursively as \n$$\nN(C,i) = \n\t\\begin{cases}\n\t\t1 &, C = 0\\\\\n\t\t0 &, C < 0\\text{ or } c\\neq 0, i = 0 \\\\\n\t\tN(C, i-1) + N(C - p_i, i -1 ) &, \\text{else}\n\t\\end{cases}\n$$\n\\subsection*{Task 2}\nThe intuition about the the recursion, is that if an extra $i+1$ item is added, then all of the solution that existed when there were only $i$ items, must still be valid. As we already know how to spend exactly $C$ with $i$ items, then when one new item is added, we only have to figure out how to include this in the budget as all other possibilities where this item is not included is already accounted for. Hence the last part of the recursion $N(C-p_i, i-1)$.\n\nProof by induction: \n\n\\noindent\nBase case: $i=1$\n$$\nN(C,1) = N(C, 0) + N(\\overbrace{C - p_i}^{C'}, 0 ) = \n\t\\begin{cases}\n\t\t1 &, C' = 0\\\\\n\t\t0 &, \\text{else}\n\t\\end{cases}\n$$\nSo with one product the only way to spend exactly $C$ is if the price of the product equals $C$, which is the same as the first parameter in $N(C,i)$ equal 0. Hence the base case holds.\n\n\\noindent\nAssume it hold for $i$ then we want to show that it also holds for $i+1$. \n$$\nN(C, i+1) = N(C, i) + N(C - p_{i+1}, i) \n$$\nwhich is exactly what we want to show.\n\nPer induction the formula is correct. It is not difficult to see that the problem exhibits optimal substructure and overlapping problems, as the $i-1, i-2, \\ldots, 0$ problems are all part of problem $i$ and the solution to those problem does not depend on $i$ there is optimal substructure. As problem $i-1$ contains the problems for $i-2,\\ldots,0$ it share all but one problem of the same problems as the original problem $i$ hence there are overlapping problems.\n\n\\subsection*{Task 3}\nBelow is an dynamic programming memorization  algorithm with an $O(nC)$ runtime. There are made som assumtions that $C$ is an integer, $p$ is a list of positive integers prices. Furthermore; we also assume the list $p$ have some properties $p$.last which takes the last element in the list in constant time, and $p$.notLast which return a sublist with all but the last element, this also can be done in constant time.  $m$ is a two dimenaional (zero indexed) array, with $C+1$ rows and $p\\text{.length}+1$ columns and it is initialized with the values $-1$ at all index.\n\\begin{lstlisting}[frame=single]\nN(C, p, m)\n1   if C < 0\n2     return 0\n3   i = p.length\n4   if m[C, i] != -1\n5     return m[C, n]\n6   if C == 0\n7     m[C, i] = 1\n8     return 1\n9   if i == 0\n10    m[C, i] = 1\n11    return 1\n12  m[C, i] = N(C, p.notLast, m) + N(C - p.last, p.notLast, m)\n13  return m[C, i]\n\\end{lstlisting}\n\n\\subsection*{Task 4}\n\\emph{Show correctness: Show that for every input it will halt with the correct output.}\n\nThe running time if the algorithm is $O(iC)$ as lines 1-11, 13 all take constant time. The recursion in line 12 all terms are at most calculated once and there are at most $ic$ subproblems to solve, hence the algorithm takes $O(iC)$ time.\n\nThe memory usage of the algorithm is also $O(iC)$ as this is the size of the $m$ array which is the larges data we need to save. \n\\end{document}", "meta": {"hexsha": "a4eba9f9166a8d737ac8a0292d1a7d81ddbdc172", "size": 3509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AlgorithmsAndDatastructures/Opgave2/opgave2.tex", "max_stars_repo_name": "pdebesc/KU", "max_stars_repo_head_hexsha": "31a72fb179f62469404290b9e6bb8a7c70e2588e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AlgorithmsAndDatastructures/Opgave2/opgave2.tex", "max_issues_repo_name": "pdebesc/KU", "max_issues_repo_head_hexsha": "31a72fb179f62469404290b9e6bb8a7c70e2588e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AlgorithmsAndDatastructures/Opgave2/opgave2.tex", "max_forks_repo_name": "pdebesc/KU", "max_forks_repo_head_hexsha": "31a72fb179f62469404290b9e6bb8a7c70e2588e", "max_forks_repo_licenses": ["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.4189189189, "max_line_length": 570, "alphanum_fraction": 0.6990595611, "num_tokens": 1108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.688919266032618}}
{"text": "%!TEX root=report.tex\n\\subsection{Gaussian Mixture Model (GMM)}\nThe GMM is a more advanced clustering model than K-Means. \nThe main advantage is that GMM allows for hyper elliptical clusters. This uses gaussian kernels with its the shape described in a covariance matrix. A result similar to K-means could be obtained by forcing this covariance matrix to be the identity matrix.\n\nRestrictions on the covariance matrix (i.e. shared covariance, diagonal covariance, spherical covariance etc.) can easily be applied in GMM and is quite common. In this analysis however, no covariance restrictions will be used.\n\nIn the GMM the assumption is that data comes from a single density function.\nThe density function is assumed to be a combination (mixture) of $K$ Gaussian PDFs where K is finite and denotes the number of mixture components (i.e. clusters).\n\nEach mixture component has a centroid (the mean), a covariance matrix and a mixing weight.\nThe sum of mixing weights across components has to be one for the GMM to constitute an actual pdf.\n\nTo estimate the model parameters several different methods exists. The most common and is the expectation maximization (EM) algorithm which is quite complex and thus wont be described here. To the curious reader we recommend \\cite[p.~214,272,463]{statistical-learning}).\n\nIn practice if K is large and the vector space $X$ is high dimensional, estimation of the model parameters will take too much computing power, and even if one get model parameters to converge, the degrees of freedom will be low.\nIn our case the input space would be 341-dimensional (341 observations in time per location) and thus a dimensionality reduction of some kind is needed. \n\n\\subsubsection{Dimensionality reduction}\nIn many cases when dealing with high dimensional data, most of the data lies on a lower dimensional manifold. \nDifferent methods exists to try to identify such manifolds, but in this analysis the previously described technique PCA will be used.\nThis is done by selecting only the most important principal components from the PCA, thus forcing the data onto a lower dimensional manifold.\nThe GRACE data contains quite a bit of noise and one might hope that the noise will be primarily contained in its own principal components. Hopefully those PCs will only account for a small amount of the variance in the data. \nThus when selecting only the most significance PCs some of the noise will be \"lost\". It should be noted that the standard PCA method wasn't used, instead a more complex method called Kernel PCA is used.\n\nUsing kernel PCA combined with the more flexible GMM over K-Means, will hopefully lead to better clustering.\n", "meta": {"hexsha": "cc7ac0ebc07f6f632a410e3df14efb94850b5aab", "size": 2665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-gmm.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-gmm.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-gmm.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": 98.7037037037, "max_line_length": 270, "alphanum_fraction": 0.8033771107, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.6888837220340733}}
{"text": "\\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n\\setlength{\\parindent}{0in}\n\\usepackage{amsmath,mathtools,amsfonts,xfrac,hyperref}\n\n\\title{Paper Title\\\\[1ex] \\normalsize AMATH 383 Term Paper}\n\\date{}\n\\author{Saransh Kacharia, Abishek Hariharan, Alex Chkodrov}\n\\begin{document}\n\\maketitle\n\n% Instructions \n\\subsection*{Introduction} Hello. \\\\\n\\hrule\n\n% Projections\n\\subsection*{Section 2}\n\n% Exercise 1\n\\begin{enumerate}\t\n\\item Define the orthogonal projection of $\\mathbf{u} \\in \\mathbb{R}^n$ onto a linear space $S$ as\n\\[ \\text{proj}_{S} (\\mathbf{u}) = \\sum_{i=1}^k \\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i, \\]\nwhere $\\{ \\mathbf{v}_1, \\mathbf{v}_2, \\dots, \\mathbf{v}_k \\}$ forms an orthogonal (but not necessarily orthonormal) basis for $S$.\n\t\\begin{enumerate}\n\t\\item Show $\\mathbf{u} - \\text{proj}_S(\\mathbf{u})$ is orthogonal to $\\text{proj}_S(\\mathbf{u})$. \\\\\n\t\\\\\n\tTo show this we have to show that the dot product between $\\mathbf{u} - \\text{proj}_S(\\mathbf{u})$ and $\\text{proj}_S(\\mathbf{u})$ is zero.\n\t\\begin{align*}\n\t\t\\mathbf{u} - \\text{proj}_{S} (\\mathbf{u}) = \\sum_{i=1}^k \\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i \\\\\n\t\t\\\\\n\t\t|\\mathbf{u} - \\sum_{i=1}^k \\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i| \\cdot |\\sum_{i=1}^k \\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i|  &= \\\\\n\t\t\\mathbf{u} \\cdot \\sum_{i=1}^k \\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i - \\sum_{i=1}^k \\bigg(\\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i\\bigg) \\cdot \\bigg(\\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i\\bigg) \\\\\n\t\\end{align*}\n\t$\\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i$ can be split into a unit vector and a scalar. \\\\\n\t$\\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2} = \\beta$, a scalar and $\\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2}$ is a unit vector.\\\\\n\t\\begin{align*}\n\t\t\\mathbf{u} \\cdot \\sum_{i=1}^k \\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i - \\sum_{i=1}^k \\bigg(\\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i\\bigg) \\cdot \\bigg(\\frac{\\mathbf{v}_i \\cdot \\mathbf{u}}{\\| \\mathbf{v}_i \\|_2^2} \\, \\mathbf{v}_i\\bigg) &= \\\\\n\t\t\\mathbf{u} \\cdot \\sum_{i=1}^k \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2} - \\sum_{i=1}^k \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2} \\cdot \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2} &= \\\\\n\t\t\\mathbf{u} \\cdot \\sum_{i=1}^k \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2} - \\beta^2\n\t\\end{align*}\n\tBecause $\\sum_{i=1}^k \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2}$ is a projection of $\\mathbf{u}$. \n\t\\begin{align*}\n\t\t\\mathbf{u} \\cdot \\sum_{i=1}^k \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2} = \\beta^2 \\\\\n\t\t\\mathbf{u} \\cdot \\sum_{i=1}^k \\beta \\frac{\\mathbf{v}_i}{\\| \\mathbf{v}_i \\|_2} - \\beta^2 &= \\\\\n\t\t\\beta^2 - \\beta^2 &= 0\n\t\\end{align*}\n\t\\item Show that $\\| \\mathbf{u} \\|_2^2 = \\| \\text{proj}_S(\\mathbf{u)} \\|_2^2 + \\| \\mathbf{u} - \\text{proj}_S(\\mathbf{u}) \\|_2^2$\n\t\\end{enumerate}\n\t\n% Exercise 2\n\\item In this exercise, we prove the Cauchy-Schwarz inequality, which states that\n\\[ | \\mathbf{u} \\cdot \\mathbf{v} | \\leq \\| \\mathbf{u} \\|_2 \\| \\mathbf{v} \\|_2 \\]\nfor any vectors $\\mathbf{u, v} \\in \\mathbb{R}^n$.\n\t\\begin{enumerate}\n\t\\item Prove that $\\| \\text{proj}_{\\mathbf{v}}(\\mathbf{u}) \\|_2 \\leq \\| \\mathbf{u} \\|_2$.\n\t\\item Use part (a) to prove the Cauchy-Schwarz inequality.\n\t\\item Show that $| \\mathbf{u} \\cdot \\mathbf{v} | = \\| \\mathbf{u} \\|_2 \\| \\mathbf{v} \\|_2$ if and only if $\\mathbf{u} = \\alpha \\mathbf{v}$ for some $\\alpha \\in \\mathbb{R}$. That is, equality of the Cauchy-Schwarz inequality holds if and only if $\\mathbf{u}$ is a scalar multiple of $\\mathbf{v}$. \n\t\\end{enumerate}\n\\end{enumerate}\n\t\n% QR Factorization\n\\subsection*{QR Factorization}\n\n% Exercise 3\n\\begin{enumerate}\\setcounter{enumi}{2}\n\\item Compute (by hand) the reduced QR factorization of the given matrix $\\mathbf{A}$, and use it to solve (by hand) the linear system of equations $\\mathbf{Ax = b}$, where\n\\[ \\mathbf{A} = \\begin{bmatrix} 1 & 6 & 14 \\\\ 1 & -2 & -8 \\\\ 1 & 6 & 2 \\\\ 1 & -2 & 4 \\end{bmatrix} \\quad \\text{and} \\quad \\mathbf{b} = \\begin{bmatrix} 7 \\\\ -1 \\\\ 7 \\\\ -1 \\end{bmatrix}. \\]\n\n% Exercise 4\n\\item Compute (by hand) the full QR factorization for the following matrix:\n\\[ \\mathbf{A} = \\begin{bmatrix} 1 & 4 & 7 \\\\ 2 & 5 & 8 \\\\ 3 & 6 & 9 \\end{bmatrix} \\]\nNote that we allow the diagonal of $R$ to have zeros if $\\mathbf{A}$ is not full rank. \n\n% Exercise 5\n\\item Consider $\\mathcal{P}_2$, the space of polynomials of degree at most 2. For any functions $f,g \\in \\mathcal{P}_2$ define their inner product as\n\\[ \\langle f, g \\rangle = \\int_{-1}^1 f(t) g(t) \\, dt. \\]\n(You need not show that this is an inner product.) Starting from the basis $\\{ 1, x, x^2 \\}$, use the Gram-Schmidt process (Algorithm 2 on page 94) to build an orthonormal basis for $\\mathcal{P}_2$. \n\nThe resulting polynomials are scalar multiples of what are known as the Legendre polynomials, $P_j$, which are conventionally normalized so that $P_j(1) = 1$. Computations with such polynomials form the basis of spectral methods, one of the most powerful techniques for the numerical solution of partial differential equations.\n\\end{enumerate}\n\n% Matlab\n\\subsection*{Matlab}\n\n% Exercise 6\n\\begin{enumerate}\\setcounter{enumi}{5}\n\\item In this exercise, we will learn how to create functions in matlab to study the stability of different algorithms for QR factorization. Consider the matrix\n\t\\begin{enumerate}\n\\[ \\mathbf{A} = \\begin{bmatrix} 1 & 1 & 1 & 1 & 1 \\\\ \\epsilon & \\epsilon & 0 & 0 & 0 \\\\ \\epsilon & 0 & \\epsilon & 0 & 0 \\\\ \\epsilon & 0 & 0 & \\epsilon & 0 \\\\ \\epsilon & 0 & 0 & 0 & \\epsilon \\end{bmatrix} \\quad \\text{with} \\quad \\epsilon = 10^{-6}. \\]\n\t\\item Use the command {\\tt cond} to find the condition number of $\\mathbf{A}$ in the 1-norm. Would you say that this matrix is ill-conditioned? Save this result as {\\tt A1.dat}.\n\t\\item Watch the video tutorial on creating functions in matlab found at \\\\ {\\tt \\href{https://www.youtube.com/watch?v=qo3AtBoyBdM}{https://www.youtube.com/watch?v=qo3AtBoyBdM}}.\n\t\\item Create the function {\\tt classicalGS} (inside a new m-file named {\\tt classicalGS.m}) to compute the QR factorization using the classical Gram-Schmidt algorithm (Algorithm 1, page 90). This function should take as its input a matrix $\\mathbf{A}$ and return as its output the matrices $\\mathbf{Q}$ and $\\mathbf{R}$. Use this function to compute the QR factorization of our given matrix $\\mathbf{A}$, then compute the 1-norm of the error $\\| \\mathbf{Q}^T\\mathbf{Q} - \\mathbf{I} \\|_1$ and save it as {\\tt A2.dat}. Below is some code to get you started:\n\t\\item Create the function {\\tt modifiedGS} to compute the QR factorization using the modified Gram-Schmidt algorithm (Algorithm 4, page 106). Use this function to compute the QR factorization of our given matrix $\\mathbf{A}$, then compute the 1-norm of the error and save it as {\\tt A3.dat}. \n\t\\item Create the function {\\tt twostepGS} to compute the QR factorization using two steps of the Gram-Schmidt algorithm (Algorithm 5, page 106). Use this function to compute the QR factorization of our given matrix $\\mathbf{A}$, then compute the 1-norm of the error and save it as {\\tt A4.dat}. \n\t\\item Compute the QR factorization of our given matrix $\\mathbf{A}$ using the matlab command {\\tt qr}. Compute the 1-norm of the error and save it as {\\tt A5.dat}. \n\t\\item Which algorithms appeared to be the most stable for computing the QR factorization of $\\mathbf{A}$? In the table below, fill in the error values and rank the algorithms from most stable (1) to least stable(4). Include this table in your written homework. \n\t\n\t\\begin{center}\n\t\\begin{tabular}{| l | l | l |}\n\t\\hline\n\tAlgorithm & Error & Rank \\\\\n\t\\hline\n\tClassical Gram-Schmidt & & \\\\\n\tModified Gram-Schmidt & & \\\\\n\tTwo Steps Gram-Schmidt & & \\\\\n\tMatlab QR & & \\\\\n\t\\hline\n\t\\end{tabular}\n\t\\end{center}\n\t\n\t\\end{enumerate}\n\t\n\t\\bigskip\n\tFor this problem, you must submit four matlab files to Scorelator: the functions {\\tt classicalGS.m}, {\\tt modifiedGS.m}, and {\\tt twostepGS.m}, and your main script which generates your data files. Before clicking submit, {\\bf you must highlight your main script} by clicking on it. If you highlight one of the function files, Scorelator will give you a 0. \n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "832bd3118d035bbc4abbe7cb4724a7e33ab1d464", "size": 8498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Template 1.tex", "max_stars_repo_name": "SaranshPK/AMATH383Paper", "max_stars_repo_head_hexsha": "a6b4d00a92ba07895d5c2df7e793ed1c0ca48db5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Template 1.tex", "max_issues_repo_name": "SaranshPK/AMATH383Paper", "max_issues_repo_head_hexsha": "a6b4d00a92ba07895d5c2df7e793ed1c0ca48db5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Template 1.tex", "max_forks_repo_name": "SaranshPK/AMATH383Paper", "max_forks_repo_head_hexsha": "a6b4d00a92ba07895d5c2df7e793ed1c0ca48db5", "max_forks_repo_licenses": ["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.2586206897, "max_line_length": 556, "alphanum_fraction": 0.6675688397, "num_tokens": 3150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.6888837154683951}}
{"text": "\\chapter{Hierarchical Clustering}\n\\label{ch:hierarchical_clustering}\n\n\\newthought{We are interested in finding clusters in our data}. That is, we would like to identify groups of data instances that are close together, similar to each other. Consider a simple, two-featured data set (see the side note) and plot it in the \\widget{Scatter Plot}. How many clusters do we have? What defines a cluster? Which data instances should belong to the same cluster? How does the clustering algorithm actually work?\n\n\\begin{marginfigure}\n    \\includegraphics[scale=0.4]{workflow_scatterplot.png}\n    \\caption{We will introduce clustering with a simple data set on students and their grades in English and Algebra.\nLoad the data set from \\url{http://file.biolab.si/text/grades.tab}.}\n\\end{marginfigure}\n\nFirst, we need to define what we mean by \"similar\". We will assume that all our data instances are described (profiled) with continuous features. One simple measure of similarity is the Euclidean distance. So, we would like to group data instances with small Euclidean distances.\n\n\\begin{figure*}[h]\n    \\vspace{1cm}\n    \\centering\n    \\infinitewidthbox{\n    \\includegraphics[scale=0.4]{grades_table.png}\n    \\includegraphics[scale=0.4]{grades_scatterplot.png}\n    }\n    \\caption{There are different ways to measure the similarity between clusters. The estimate we have described is called average linkage. We could also estimate the distance through the two closest points in each clusters (single linkage), or through the two points that are furthest away (complete linkage).}\n\\end{figure*}\n\nNext, we need to define a clustering algorithm. Say that we start with each data instance being its own cluster, and then, at each step, we join the clusters that are closest together. We estimate the distance between the clusters with, say, the average distance between all their pairs of data points. This algorithm is called hierarchical clustering.\n\n\\clearpage\n\nOne possible way to observe the results of clustering on our small data set with grades is with the following workflow:\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[scale=0.6]{distances.png}\n\\end{marginfigure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4]{workflow_clustering.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n\nCouldn’t be simpler. Load the data, measure the distances, use them in hierarchical clustering, and visualize the results in a scatter plot. The \\widget{Hierarchical Clustering} widget allows us to cut the hierarchy at a certain distance score and output the corresponding clusters:\n\n\\begin{figure*}[h]\n    \\centering\n    \\newcommand{\\clustering}{\\includegraphics[scale=0.4]{hierarchical_clustering.png}}\n    \\newcommand{\\plot}{\\includegraphics[scale=0.4]{scatterplot_clustered.png}}\n    \\infinitewidthbox{\n    \\stackinset{r}{-0.5\\linewidth}{t}{+0.3\\linewidth}{\\plot}{\\clustering}\\hspace{8cm}\n    }\n\\end{figure*}\n", "meta": {"hexsha": "25875ff74432b4db2fb84b3904db8b290e03eef3", "size": 2950, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/010-hierarchical-clustering/hierarchical-clustering.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/010-hierarchical-clustering/hierarchical-clustering.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/010-hierarchical-clustering/hierarchical-clustering.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": 57.8431372549, "max_line_length": 433, "alphanum_fraction": 0.7715254237, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.688883709226603}}
{"text": "\\chapter{Gaussian processes}\n\n\\section{Parametric and nonparametric regression}\nConsider the standard regression problem: given $\\mathcal{D} = \\{(x_i,y_i)\\}_{i=1}^N$, with $x_i \\in \\mathcal{X}$ and $y_i \\in \\mathbb{R}$, one wants, for a $x_* \\in \\mathcal{X}$, find $p(y_*|x_*)$. If we assume a model $M$ for $y|x$, for all $x \\in \\mathcal{X}$, parameterized by $\\theta$, then by the Bayesian view one should marginalize over $\\theta$ resulting in \n\\begin{equation}\n p(y_*|x_*,M,\\mathcal{D}) = \\int_{\\Theta} p(y_*|x_*,\\theta,M,\\mathcal{D}) p(\\theta|\\mathcal{D}) d\\theta,\n\\end{equation}\nreducing the problem to one of posterior inference in $\\theta$, discussed in the previous chapter (equation \\eqref{marginalizationpred}).\n\nSince the model $M$ is parameterized, in a sense the model will be always limited, since there cannot be a mapping from finite parameters to all distributions. Nonparametric models by contrast are models that cannot be parameterized by a finite set of parameters, and Bayesian nonparametric regression is when a nonparametric model is used in the Bayesian setting \\cite{Ghahramani_2013,Hjort_2010}. \n\n\\section{Gaussian process regression}\nBayesian nonparametric regression seems to be an impossible task, since it requires working with distributions in infinite-dimensional spaces. However, Gaussian process regression \\cite{Rasmussen06} does this, by choosing a suitable model, given by a Gaussian process\n\\begin{Definition}\n\tA \\textit{Gaussian process} (GP) is a distribution over the space of functions from $\\mathcal{X}$ to $\\mathbb{R}$ such that, for each $\\mathbf{x} = (x_1,...,x_N) \\in \\mathcal{X}^N$, $\\mathbf{f} := (f(x_1),...,f(x_N))$ follows a multivariate normal distribution \\cite{Rasmussen06}. \n\\end{Definition}\n\nA GP is completely specified by a \\textit{mean function}\n\\begin{displaymath}\nm : \\mathcal{X} \\to \\mathbb{R}\n\\end{displaymath}\nand a \\textit{covariance function} \n\\begin{displaymath}\nk : \\mathcal{X} \\times \\mathcal{X} \\to \\mathbb{R},\n\\end{displaymath}\nin such a way that, for $\\mathbf{x} = (x_1,\\ldots,x_N)$, letting\n\\begin{equation}\n\\mathbf{m}(\\mathbf{x}) := (m(x_1),...,m(x_N))^T \\quad K(\\mathbf{x},\\mathbf{x}') = \\bigg(k(x_i,x_j')\\bigg)_{i,j},\n\\end{equation}\nthen $f(\\mathbf{x}) \\sim \\mathcal{N}(\\mathbf{m}(\\mathbf{x}),K(\\x,\\x))$. \n\nNotice that this requires the function $k$ to be a \\textit{positive-semidefinite} (PSD) function, that is, for any $N \\in \\mathbb{N}$, for any $\\mathbf{x} = (x_1,...,x_N) \\in \\mathcal{X}^N$, the matrix $K(\\mathbf{x},\\mathbf{x})$ defined by $(K(\\mathbf{x},\\mathbf{x}))_{i,j} = k(x_i,x_j)$ is PSD. Conversely, any pair $(m,k)$, with $k$ PSD defines a GP \\cite{Dudley_2002}, thus ensuring a correspondence between GPs and $(m,k)$ pairs as above. In the context of GPs, $k$ is also called an \\textit{kernel}. \\footnote{PSD functions have the property that, for $x,x' \\in \\mathcal{X}$, $k(x,x') = \\langle \\Phi(x), \\Phi(x') \\rangle_{\\mathcal{H}}$, where $\\Phi : \\mathcal{X} \\to \\mathcal{H}$ is a map from $\\mathcal{X}$ to a Hilbert space $\\mathcal{H}$ \\cite{Shawe_Taylor_2004}. In this context, $k$ is called a \\textit{kernel function}, and machine learning techniques that uses them are called kernel methods \\cite{Shawe_Taylor_2004}. Hence, in the context of GPs, the terms \\textit{kernel function} and {covariance function} are used interchangeably.}\n\nA \\textit{Gaussian process regression} is done, with $\\mathcal{D} = \\{(x_i,y_i)\\}_{i=1}^N$, by using the model $M$ that says, for each $x$, $p(y|x,M) = p(y|f(x),M)$, with the prior for $f$ being distributed as $GP(m,k)$. To see that this prior is attractive, assume for now $y = f(x)$. By letting $\\mathbf{x} = (x_1,\\ldots,x_N)$ \\footnote{Usually, $x_i \\in \\mathbb{R}^D$, and $\\mathbf{x}$ is written as a matrix whose $i$-th row is $x_i$. In this case, we may use $\\mathbf{X}$ to denote this matrix instead, and reserve $\\mathbf{x}$ to denote each point in $\\mathbb{R}^D$. We will however use a more general notation.} and $\\mathbf{y} = (y_1,\\ldots,y_N)^T$, and assuming $K(\\mathbf{x},\\mathbf{x})$ to be non-singular, one can find the posterior distribution for $y_*|x_*,\\mathcal{D},M$ without resorting to Bayes' rule, which is important since, in infinite-dimensional spaces, Bayes' rule is more involved, and may not result in a computable expression by itself \\cite{Kanagawa_2018}. \\footnote{For a derivation of Bayes' rule for infinite-dimensional spaces (which involves measure theory), see \\cite{Stuart_2010}, Section 6.6.}\n\nToo see why is this, notice that, by the definition of a GP, for any other $\\mathbf{x}^\\star \\in \\mathcal{X}^M$, \n\\begin{equation} \\label{jointGP}\n\\left[ \\begin{array}{c} \nf(\\mathbf{x}) \\\\\nf(\\mathbf{x}^*) \\end{array} \\right] \\sim \\mathcal{N} \n\\left( \\left[ \\begin{array}{c}\n\\mathbf{m}(\\mathbf{x}) \\\\\n\\mathbf{m}(\\mathbf{x}^*) \\end{array} \\right] , \n\\left[ \\begin{array}{c c} \nK(\\mathbf{x},\\mathbf{x}) & K(\\mathbf{x},\\mathbf{x}^*) \\\\\nK(\\mathbf{x}^*,\\mathbf{x}) & K(\\mathbf{x}^*,\\mathbf{x}^*) \\end{array} \\right]\n\\right).\n\\end{equation}\nHence, by conditioning on $f(\\mathbf{x})$, by Appendix \\ref{appendixconditional}:\n\\begin{equation}\\label{meancovGPRpure}\n\\begin{split}\n& f(\\mathbf{x}^*) | \\mathbf{x}^\\star, \\mathcal{D}, M = \\mathbf{f}^*|\\mathbf{f},M \\sim \\mathcal{N}(\\mu^\\star,\\Sigma^*) \\\\\n& \\mu^\\star = \\mathbf{m}(\\mathbf{x}^\\star) + K(\\mathbf{x}^\\star,\\mathbf{x}) K(\\mathbf{x},\\mathbf{x})^{-1} (f(\\mathbf{x}) - m(\\mathbf{x})) \\\\\n& \\Sigma^\\star = K(\\mathbf{x}^\\star,\\mathbf{x}^\\star) - K(\\mathbf{x}^\\star,\\mathbf{x}) K(\\mathbf{x},\\mathbf{x})^{-1} K(\\mathbf{x},\\mathbf{x}^\\star).\n\\end{split}\n\\end{equation}\nSince $\\x^*$ was chosen arbitrarily, this implies that $f|\\mathcal{D},M$ itself follows a GP, with mean function and covariance functions given by:\n\\begin{equation}\\label{GPRasGP}\n\\begin{split}\n& m_{\\mathcal{D}}(x) = \\mu^*(x) = m(x) + K(x,\\mathbf{x}) K(\\mathbf{x},\\mathbf{x})^{-1} (f(\\mathbf{x}) - m(x)) \\\\\n& k_{\\mathcal{D}}(x,x') = k(x,x') - K(x,\\mathbf{x}) K(\\mathbf{x},\\mathbf{x})^{-1} K(\\mathbf{x},x').\n\\end{split}\n\\end{equation}\nSince $y_* = f(x_*)$ and $\\mathbf{y} = f(\\mathbf{x}^*)$, $y_*|x_*,\\mathcal{D},M \\sim \\mathcal{N}(m_\\mathcal{D}(x_*),k_\\mathcal{D}(x_*,x_*))$. An illustration of GP regression is shown if Figure \\ref{gprfig}.\n\n\\begin{figure}\n\t\\centering\n\t\\subfloat[GP prior]{\\label{gprex1a}\\includegraphics[width=0.45\\textwidth]\n\t\t{figs/gprex1a.png}}\n\t\\subfloat[GP posterior]{\\label{gprex1b}\\includegraphics[width=0.45\\textwidth]\n\t\t{figs/gprex1b.png}}\n\t\n\t\\caption[Gaussian process regression of $f(x) = \\sin(\\pi x)$]{\\label{gprfig}Gaussian process regression of $f(x) = \\sin(\\pi x)$. In (a), it is shown the prior space distribution, with samples path in blue and confidence interval in red. In (b), the posterior space distribution, after 4 measurements (in green) of $f(x)$ (black). Generating code can be found in \\url{https://github.com/DFNaiff/Dissertation/blob/master/illustrations_dissertation/gp_prior_posterior}.}\n\\end{figure}\n\n\n\\subsection{Gaussian noise}\nThis equation can be generalized by assuming $p(y|x,M) = \\mathcal{N}(y|f(x),\\sigma^2_n)$. Then, letting $\\epsilon \\sim \\mathcal{N}(0,\\sigma^2_n)$, $\\mathbf{y} = f(\\mathbf{x})$, $\\mathbf{y}^* = f(\\mathbf{x}^*)$ and\n\\begin{equation} \\label{jointGPnoise}\n\\left[ \\begin{array}{c} \n\\mathbf{y} \\\\\n\\mathbf{y}^* \\end{array} \\right] \\sim \\mathcal{N} \n\\left( \\left[ \\begin{array}{c}\n\\mathbf{m}(\\mathbf{x}) \\\\\n\\mathbf{m}(\\mathbf{x}^*) \\end{array} \\right] , \n\\left[ \\begin{array}{c c} \nK(\\mathbf{x},\\mathbf{x}) + \\sigma_n^2 I & K(\\mathbf{x},\\mathbf{x}^*) \\\\\nK(\\mathbf{x}^*,\\mathbf{x}) & K(\\mathbf{x}^*,\\mathbf{x}^*) + \\sigma^2_n I \\end{array} \\right]\n\\right).\n\\end{equation}\nConditioning $\\mathbf{y}^*$ on $\\mathbf{y}$ and, letting $K_\\sigma(\\mathbf{x},\\mathbf{x}) := K(\\mathbf{x},\\mathbf{x}) + \\sigma_n I$, we have\n\\begin{equation}\\label{meancovGPR}\n\\begin{split}\n& \\mathbf{y}^* | \\mathbf{x}^\\star, \\mathcal{D}, M = \\mathbf{y}^*|\\mathbf{y},M \\sim \\mathcal{N}(\\mu^\\star,\\Sigma^*) \\\\\n& \\mu^\\star = \\mathbf{m}(\\mathbf{x}^\\star) + K(\\mathbf{x}^\\star,\\mathbf{x}) K_\\sigma(\\mathbf{x},\\mathbf{x}){-1} (\\mathbf{y} - m(\\mathbf{x})) \\\\\n& \\Sigma^\\star = K(\\mathbf{x}^\\star,\\mathbf{x}^\\star) - K(\\mathbf{x}^\\star,\\mathbf{x}) K_\\sigma(\\mathbf{x},\\mathbf{x})^{-1} K(\\mathbf{x}^\\star,\\mathbf{x}) + \\sigma_n I.\n\\end{split}\n\\end{equation}\nNotice \\eqref{meancovGPR} reduces to \\eqref{meancovGPRpure} when $\\sigma^2_n = 0$. \n\\subsection{General noise}\nIn the general case where $p(y|x,M)$ = $p(y|f(x))$, there is not a closed form solution and one must resort to explicit marginalization and Bayes' rule:\n\\begin{equation}\\label{generalnoise}\n\\begin{split}\n & p(y_*|x_*,\\mathcal{D}) = \\\\  & = \n  \\int p(y_*|f(x_*)) p(f(x_*)|x_*,\\mathbf{x},\\mathbf{y}) df(x_*)\\\\ & = \n  \\int p(y_*|f(x_*)) \\int p(f(x_*)|x_*,f(\\mathbf{x}), \\mathbf{x}) p(f(\\mathbf{x}) | \\mathbf{x},\\mathbf{y}) df(\\mathbf{x}) df(x_*) \\\\ & \\propto\n  \\int p(y_*|f(x_*)) \\int p(f(x_*)|x_*,f(\\mathbf{x}), \\mathbf{x}) p(\\mathbf{y}|f(\\mathbf{x})) p(f(\\mathbf{x})|\\mathbf{x}) df(\\mathbf{x})df(x_*).\n \\end{split}\n\\end{equation}\nSince $p(f(\\mathbf{x})|\\x) = \\mathcal{N}(f(\\mathbf{x})|m(\\mathbf{x}),K(\\mathbf{x},\\mathbf{x}))$ and $p(f(x_*)|x_*,f(\\mathbf{x}), \\mathbf{x})$ is given by \\eqref{meancovGPRpure}, these two terms may be joined together by \\eqref{productgaussians}. However, this still leaves a double integral, that must be treated by approximate inference methods.\n\n\\subsection{Mean function}\nUsually, the mean function $m$ is set to zero, letting the covariance function determine the whole structure of the regression. This is a reasonable assumption since, for any $f \\sim GP(m,k)$, due to the sum of a Gaussian distribution and a constant being itself Gaussian with the constant added to its mean, we have $f-m \\sim GP(0,k)$. Thus, fixed the model $(m,k)$, one can then do the GP regression on $f-m$ and then later add $m$. This is particularly useful if it is assumed that $f$ is modeled by some function $m$ that is known to be an incomplete model, thus complementing the regression by modeling this incompleteness by a zero mean GP.\n\n\\section{Covariance functions}\n\nAs said in the previous section, covariance functions $k$ must be PSD. This raises the question on which kind of functions are PSD, thus able to define a GP. A few functions can be easily shown to be PSD directly by their definitions, such as:\n\\begin{itemize}\n\t\\item The constant function $k(x,x') = c \\geq 0$, since the matrix $K_{i,j} = c$ is PSD, for all $c \\geq 0$\n\t\\item $k(x,x') = \\mathbb{I}_{x = x'}$, since the corresponding matrix $K$ is the identity matrix\n\t\\item If $\\mathcal{X} = \\{x_1,...,x_N\\}$  is a finite set of size $N$, and $k$ is such that, for $\\mathbf{x} = (x_1,...,x_N)$, \n\t$K(\\mathbf{x},\\mathbf{x})$ is PSD, then $k$ is PSD, since for any other subset of $\\mathcal{X}$, the corresponding kernel matrix will be a subset of $K$, thus also PSD \\cite{hogben14}.\n\t\\item If we have an explicit feature map $\\Phi : \\mathcal{X} \\to \\mathbb{R}^N$, then $k(x,x') = \\langle \\Phi(x),\\Phi(x') \\rangle$ is PSD \\cite{Shawe_Taylor_2004}. For instance, if $\\mathcal{X} = \\mathbb{R}$ and $\\Phi(x) = (x,x^2,\\ldots,x^N)$, then $k(x,x') = \\sum_{i=1}^N (x x')^i$ is PSD.\n\\end{itemize}\nHowever, for many covariance functions, direct proof of being PSD is infeasible. However, there are some covariance functions that can be shown to be PSD in a indirect way, as shown below.\n\\subsubsection{Stationary covariance functions}\n\\begin{Definition}\n\tLet $\\mathcal{X} = \\mathbb{R}^d$. An covariance function is \\textit{stationary} if $k(x,x') = k(x - x')$ , \n\tfor $k : \\mathbb{R}^d \\to \\mathbb{R}$ \\footnote{Here we overload the notation, letting the reader infer whether $k$ refers to a covariance function or an autocavariance function by the number of its arguments.}. Conversely, $k$ is a \\textit{autocovariance function} if $k(x,x') = k(x - x')$ is a covariance function.\n\\end{Definition}\nFor this class of functions, we can reduce the analysis of $k$ to that of $k$. In particular, the next theorem says that one can analyze the Fourier transform of $k$ to check if it is an autocovariance function, thus $k$ being a covariance function (here, it is conveniente to consider $k$ as a function into $\\mathbb{C}$).\n\n\\begin{Theorem}[Bochner's Theorem]\n\tA function $k : \\mathbb{R}^d \\to \\mathbb{C}$, continuous at $0$, is an autocovariance function if and only if \n\t\\begin{equation}\n\tk(\\tau) = \\int_{\\mathbb{R}^D} e^{2 \\pi i \\mathbf{s}^T \\tau} d \\mu (\\mathbf{s}),\n\t\\end{equation}\n\twhere $\\mu$ is a positive finite measure \\cite{Stein_1999,Rasmussen06}.\n\tIf $\\mu$ has a density $S$, then $S$ an $k$ are Fourier duals of each other \\cite{Chatfield_2004}.\n\t\\begin{displaymath}\n\t\\begin{split}\n\tk(\\tau) & = \\int_{\\mathbb{R}^D} e^{2 \\pi i \\mathbf{s}^T \\tau} S(\\mathbf{s}) d\\mathbf{s} \\\\\n\tS(\\mathbf{s}) & = \\int_{\\mathbb{R}^D} e^{-2 \\pi i \\mathbf{s}^T \\tau} k(\\tau) d \\tau.\n\t\\end{split}\n\t\\end{displaymath}\n\tIn this case, $S$ is called the \\text{spectral density} corresponding to $k$.\n\\end{Theorem}\n\n\nOne particular case of stationary functions are \\textit{isotropic} functions, in which $k(\\tau)$ is a function of $r = ||\\tau||_2$. In this case, $S(\\mathbf{s})$ is a function of $s = ||\\mathbf{s}||_2$ \\cite{CIS-4647}. For simplicity, those will also be referred as $k$ ans $S$. We show here some examples of isotropic covariance functions, along with their spectral densities (many others can be found in \\cite{Rasmussen06}):\n\\begin{itemize}\n\t\\item The squared exponential (SQE) kernel, also called RBF kernel \n\t\\begin{equation}\\label{sqekernel}\n\tk_{SQE}(r;l) = \\exp \\left(-\\frac{r^2}{l^2}\\right),\n\t\\end{equation}\n\twhose spectral density is given by a normal distribution\n\t\\begin{equation}\n\tS(s;l) = (2 \\pi l^2)^{D/2} \\exp(-2 \\pi^2 l^2 s^2)\n\t\\end{equation}\n\tThe squared exponential kernel is the most widely used in the field of Gaussian process, and kernel methods in general. However, the squared exponential kernel generates functions that are infinitely differentiable, thus being far too smooth for some applications. Moreover, the resulting kernel matrix tends to be very ill-conditioned, which results in numerical issues in applications with low noise.\n\t\\item The \\text{Matérn} class of kernels, parameterized by $\\nu > 0$, given by\n\t\\begin{equation}\\label{maternkernel}\n\tk_{Matern,\\nu}(r;l) = \\frac{2^{1-\\nu}}{\\Gamma(\\nu)} \\left(\\frac{\\sqrt{2 \\nu} r}{l} \\right)^\\nu\n\tK_\\nu \\left( \\frac{\\sqrt{2 \\nu} r}{l} \\right),\n\t\\end{equation}\n\twhere $K_\\nu$ is the modified Bessel function of second kind. The corresponding spectral density \n\tis a $2 \\nu$-degreed multivariate t-distribution\n\t\\begin{equation}\n\tS_\\nu(s;l) = 2^D \\pi^{D/2} \\frac{\\Gamma(\\nu + D/2)(2 \\nu)^\\nu}{\\Gamma(\\nu)l^{2 \\nu}}\\left(\\frac{2 \\nu}{l^2} + \n\t4 \\pi^2 s^2\\right)^{-(2 \\nu+D)/2}.\n\t\\end{equation}\n\tIf $\\nu$ is a half-integer, the kernel formula is simplified to a product of a polynomial of order $\\nu - 1/2$ and an exponential. The most commonly used values of $\\nu$ are:\n\t\\begin{itemize}\n\t\t\\item $\\nu = 1/2$, giving $k_{Matern,1/2}(s;l) = \\exp(-r/l)$.\n\t\t\\item $\\nu = 3/2$, giving $k_{Matern,3/2}(s;l) = \\left(1 + \\sqrt{3} r/l \\right) \\exp(-\\sqrt{3}r/l)$.\n\t\t\\item $\\nu = 5/2$, giving $k_{Matern,5/2}(s;l) = \\left(1 + \\sqrt{5} r/l + 5 r^2/l^2 \\right) \\exp(-\\sqrt{5}r/l)$.\n\t\\end{itemize}\n\tIn the limit $\\nu \\to \\infty$, the Matern kernel converges to the squared exponential kernel \\cite{Stein_1999}. In practice, for values of $\\nu \\geq 7/2$, the Matern kernel is similar enough to the squared exponential kernel to be of use, thus in practice only the three values of $\\nu$ shown above are used.\n\t\\item The spectral mixture kernel \\cite{wilson2013gaussian}\n\t\\begin{equation}\\label{spectralmixturekernel}\n\tk_{SM}(\\tau) = \\sum_{q=1}^Q w_q \\prod_{d=1}^D \\exp(-2 \\pi^2 \\tau_d^2 v_{q}^{(d)})\n\t\\cos(2 \\pi \\tau^{(d)} \\mu_q^{(d)}),\n\t\\end{equation}\n\twhich is constructed explicitly as the Fourier dual of mixtures of multivariate normal densities. In \\cite{wilson2013gaussian}, it is argued that the spectral mixture kernel approximates many of the kernels in \\cite{Rasmussen06}, given enough mixtures $Q$.\n\\end{itemize}\n\n\n\\subsection{Derived kernels}\nAlthough PSD functions are relatively hard to find, even with the use of Bochner's Theorem, one can prove that many compositions of base PSD functions are themselves PSD, thus providing many new classes of kernels.\nGiven $\\mathcal{X}$ an arbitrary set, $k_1$,$k_2$ PSD functions on $\\mathcal{X}$, and $k_3$ a PSD function on a set $\\mathcal{Y}$, we have:\n\\begin{itemize}\n\t\\item $k(x,x') := k_1(x,x') + k_2(x,x')$ is a PSD function, since, for $\\mathbf{x} = (x_1,...,x_N) \\in \\mathcal{X}^N$, $K(\\mathbf{x},\\mathbf{x}) = K_1(\\mathbf{x},\\mathbf{x}) + K_2(\\mathbf{x},\\mathbf{x})$, the sum \n\tof two PSD matrices, hence a PSD matrix. Similarly, $k(x,x') := k_1(x,x') k_2(x,x')$ is a PSD function, since $K(\\mathbf{x},\\mathbf{x}) = K_1(\\mathbf{x},\\mathbf{x}) \\odot K_2(\\mathbf{x},\\mathbf{x})$ (where $A \\odot B$ denotes the Hadamard product between $A$ and $B$), and, according to Schur product theorem \\cite{hogben14}, $K(\\mathbf{x},\\mathbf{x})$ is also PSD as the Hadamard product of two PSD matrices.\n\t\\item $k([x,y],[x',y']) = k_1(x,x') + k_3(y,y')$ is a PSD function, and so is $k([x,y],[x',y']) = k_1(x,x') k_3(y,y')$. This follows from the fact that both sum and Hadamard product of PSD matrices are PSD.\n\t\\item For a map $f : \\mathcal{Y} \\to \\mathcal{X}$, $k(y,y') = k_1(f(x),f(x'))$ is aPSD. This follows directly from the fact that if $y_i = f(x_i), \\ i=1,...,n$, \n\t$K(\\mathbf{y},\\mathbf{y}) = K_1(f(\\mathbf{x}),f(\\mathbf{x}'))$. This property allows us to construct non-stationary kernels from stationary kernels, by using input warping functions. Moreover, \n\tthis implies that we can substitute $r = ||\\mathbf{x} - \\mathbf{x}'||_2$ for $r = \\sqrt{(\\mathbf{x} - \\mathbf{x})^T A^{-1} (\\mathbf{x} - \\mathbf{x})}$, where $A$ is a positive definite matrix, by setting $f(x) = A^{-1/2} x$\n\\end{itemize}\nThe last item allows us to construct kernels with general \\textit{outputscale} and \\textit{lengthscale} from stationary kernels. That is, if $k_0$ is an autocovariance function such that $k_0(0) = 1$, then\n\\begin{equation}\\label{scaledkernels}\nk(x-x') = \\theta k\\left(\\frac{x_1-x'_1}{l_1},\\ldots,\\frac{x_D-x'_D}{l_D}\\right) \n\\end{equation}\nis a kernel with outputscale $\\theta$ and lengthscales $l_1,\\ldots,l_D$. We call such kernels \\textit{anisotropic} (although strictly speaking, every non-isotropic kernel is anisotropic).\n\n\\section{Model selection}\nIn the above discussion, the model $M = (m,k)$ was assumed to be fixed. In practice, since we have many different kernel functions, each parameterized by a continuous set of parameters (called \\textit{hyperparameters}), we need a way to choose the correct model. In the noisy measurement case, we also need to deal with the noise distribution parameters. Fortunately, the Bayesian framework gives a natural way to choose the model. \n\nAssume $p(y|f(x)) = \\mathcal{N}(f(x),\\sigma_n^2)$. Then, \n\\begin{displaymath}\n\\mathcal{D}|M,\\sigma_n = \\mathbf{y} | \\mathbf{x},M,\\sigma_n \\sim \n\\mathcal{N}(m(\\mathbf{x}),K(\\mathbf{x},\\mathbf{x}) + \\sigma_n \\mathbf{I}).\n\\end{displaymath}\nTherefore, the likelihood for the model is given by \n\\begin{equation}\\label{loglikelihoodGP}\n\\begin{split}\n\\log p(\\mathcal{D}|M,\\sigma_n) = & -\\frac{1}{2}(\\mathbf{y} - m(\\mathbf{x}))^T (K(\\mathbf{x},\\mathbf{x}) + \\sigma_n \\mathbf{I})^{-1} (\\mathbf{y} - m(\\mathbf{x})) + \\\\\n&-\\frac{1}{2} \\log \\det (K(\\mathbf{x},\\mathbf{x}) + \\sigma_n \\mathbf{I}) - \\frac{1}{2} N \\log(2\\pi).\n\\end{split}\n\\end{equation}\nThe important thing to notice is that the likelihood above is actually a marginal likelihood, since\n\\begin{equation}\np(\\mathcal{D}|M,\\sigma_n) = \\Ev_{f \\sim GP(m,k)} \\left[p(\\mathcal{D}|f,\\sigma_n) \\right].\n\\end{equation}\nHence, it should display the Occam's razor effect. In fact, the log-determinant term does exactly this, acting as a sort of regularizer. However, this does not mean that GP regression is protected from overfitting (see \\cite{Mohammed_2017}). Moreover, since the objective function is non-convex, there may be local optima that returns spurious results.\n\nA fully Bayesian approach to GP regression is desirable in order to incorporate fully the hyperparameter knowledge. However, when the number of data is considerably large, Monte Carlo methods becomes inefficient (although it can be used still, see for example \\cite{Neal_1997,Petelin_2014}). In \\cite{Osborne_2007}, an approach based on Bayesian Monte Carlo (to be presented in Chapter 4) is also explored. However, efficient marginalization of hyperparameters remains an open problem.\n\n\\section{Computational issues}\n\\subsection{Jittering}\nIf the noise $\\sigma_n^2$ is zero, the matrix $K(\\mathbf{x},\\mathbf{x})$ may be ill-conditioned, which is usually the case for the SQE kernel. One way to mitigate this problem is to force the existence of an \"artificial noise\" on $K(\\mathbf{x},\\mathbf{x})$, that is, one substitute it for $K(\\mathbf{x},\\mathbf{x}) + \\sigma^2_j I$, where $\\sigma^2_j$ is not a real noise parameter now, but just an stabilizer. In this case, the error caused by the addition of artificial noise is considerably smaller than the error of numerical operations in ill-conditioned matrices, if they are able to be performed at all. The Cholesky decomposition (described below) also helps with the stability of inverse matrix operations.\n\n\\subsection{Scaling with data}\\label{scalinggpsession}\nThe main issue with GP regression is that, given $N$ training points, for a fixed covariance function the evaluations in \\eqref{meancovGPR} requires at least one operation with the inverse of a $N \\times N$ matrix $K(\\mathbf{x},\\mathbf{x} + \\sigma_n \\mathbf{I})$, whose computational cost is of order $\\mathcal{O}(N^3)$. The problem is worsened in the case of training a model, since this operation has to be done for each evaluation of $\\log p(\\mathcal{D}|M,\\sigma_n,\\theta)$ while training. \n\nSince $K(\\mathbf{x},\\mathbf{x}) + \\sigma_n \\mathbf{I}$ is a positive definite matrix, one can try to mitigate the computational cost by computing the Cholesky decomposition\n\\begin{displaymath}\nK(\\mathbf{x},\\mathbf{x}) + \\sigma_n \\mathbf{I} = L L^T.\n\\end{displaymath}\nThen, given the decomposition, the inverse operations involve inverses of triangular matrices, whose operations costs are of order $\\mathcal{O}(N^2)$, while the determinant term in $\\log p(\\mathcal{D}|M,\\sigma_n,\\theta)$ can be calculated as $\\log \\det (L L^T) = 2 \\sum_i \\log L_{ii}$. However, Cholesky decomposition, although faster than other methods like the LU decomposition, still has a computational cost of $\\mathcal{O}(N^3)$, hence the scaling problem still exists.\n\n\\section{Online learning}\\label{onlinelearningsection}\nOne interesting aspect of GPs is its ability to accumulate online data in a relatively simple manner, provided we do not change its hyperparameters. Consider fixed an initial data $\\mathcal{D} = \\{(x_i,y_i)\\}_{i=1}^N$, and a GP model $(m,k)$, if we have a kernel matrix $K_{\\mathcal{D}}$, and its Cholesky factor $L_{\\mathcal{D}}$, resulting in a readily accessible posterior mean function $m_\\mathcal{D}(x)$ and covariance function $k_\\mathcal{D}(x,x')$. Now, suppose some new data $\\mathcal{D}' = \\{(x'_j,y'_j)\\}_{j=1}^M$ is available, and the practitioner wants to incorporate into a new posterior mean $m_{\\mathcal{D} \\cup \\mathcal{D}'}(x,x')$ and covariance $k_{\\mathcal{D} \\cup \\mathcal{D}'}(x,x')$. A naive manner for doing this would be constructing a new kernel matrix $K_{\\mathcal{D} \\cup \\mathcal{D}'}$ from scratch, and compute its Cholesky factor $L_{\\mathcal{D} \\cup \\mathcal{D}'}$, resulting in a operation cost $\\mathcal{O}((M + N)^3)$. Fortunately, there is a clever way to obtain $L_{\\mathcal{D} \\cup \\mathcal{D}'}$ from $L_\\mathcal{D}$ with $\\mathcal{O}(M^3 + MN^2)$ cost (assuming $K_{\\mathcal{D} \\cup \\mathcal{D}'}$ stays positive-definite). The following argument is adapted from \\cite{Osborne_2012}, where it is considered the upper Cholesky factor.\n\nTo see this, consider $\\mathbf{x}_N = (x_i)_{i=1}^N$, $\\mathbf{x}_M = (x'_j)_{j=1}^M$ and $\\mathbf{x} = \\mathbf{x}_N \\cup \\mathbf{x}_M$ (here $\\cup$ denotes concatenation). Then, noting $K_\\mathcal{D} = K(\\x_N,\\x_N)$, we have \n\\begin{equation}\n K_{\\mathcal{D}\\cup\\mathcal{D}'} = \\left[ \\begin{array}{cc}\nK(\\x_N,\\x_N) & K(\\x_N,\\x_M) \\\\\nK(\\x_M,\\x_N) & K(\\x_M,\\x_M) \\end{array} \\right].\n\\end{equation}\nThen $L_{\\mathcal{D}\\cup\\mathcal{D}'}$ must be of the form\n\\begin{equation}\\label{formatcholexpanded}\nL_{\\mathcal{D}\\cup\\mathcal{D}'} = \\left[ \\begin{array}{cc}\nL_\\mathcal{D} & 0 \\\\\nS & \\tilde{L} \\end{array} \\right],\n\\end{equation}\nwith $\\tilde{L}$ being lower triangular. This is because\n\\begin{equation}\n\\begin{split}\nL_{\\mathcal{D}\\cup\\mathcal{D}'} L_{\\mathcal{D}\\cup\\mathcal{D}'}^T = \\left[ \\begin{array}{cc}\nL_\\mathcal{D} & 0 \\\\\nS & \\tilde{L} \\end{array} \\right] \\left[ \\begin{array}{cc}\nL_\\mathcal{D}^T & S^T \\\\\n0 & \\tilde{L}^T \\end{array} \\right] & = \\left[ \\begin{array}{cc}\nL_\\mathcal{D} L_\\mathcal{D}^T & L_\\mathcal{D} S^T \\\\\nS L_\\mathcal{D}^T & S S^T + \\tilde{L} \\tilde{L}^T \\end{array} \\right] \\\\\n & = \\left[ \\begin{array}{cc}\nK(\\x_N,\\x_N) & K(\\x_N,\\x_M) \\\\\nK(\\x_M,\\x_N) & K(\\x_M,\\x_M) \\end{array} \\right] = K_{\\mathcal{D}\\cup\\mathcal{D}'}.\n\\end{split}\n\\end{equation}\nThis readily shows not only that $L_{\\mathcal{D}\\cup\\mathcal{D}'}$ must be of the format in \\eqref{formatcholexpanded}, but it gives a way to get $S$ and $\\tilde{L}$: calculate $S= \\big( L_\\mathcal{D}^{-1} K(\\x_N,\\x_M) \\big)^T$, and $\\tilde{L}$ is the lower Cholesky factor of $K(\\x_M,\\x_M) - SS^T$, whose operations are of cost $\\mathcal{O}(N^2 M)$ and $\\mathcal{O}(M^3)$.", "meta": {"hexsha": "c1f926e51c0192f90710bcd9cd6b1fc567b5d7cc", "size": 25604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex_copy/chapters/capituloB.tex", "max_stars_repo_name": "DFNaiff/Dissertation", "max_stars_repo_head_hexsha": "8db72a0e588042a582053625ec58cde6a661f2a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex_copy/chapters/capituloB.tex", "max_issues_repo_name": "DFNaiff/Dissertation", "max_issues_repo_head_hexsha": "8db72a0e588042a582053625ec58cde6a661f2a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex_copy/chapters/capituloB.tex", "max_forks_repo_name": "DFNaiff/Dissertation", "max_forks_repo_head_hexsha": "8db72a0e588042a582053625ec58cde6a661f2a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 94.479704797, "max_line_length": 1272, "alphanum_fraction": 0.6923918138, "num_tokens": 8689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290699, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6888243876249638}}
{"text": "\\problemname{Purple Rain}\n\n\\illustration{0.2}{purplerain/problem_statement/purplerain.png}\n\nPurple rain falls in the magic kingdom of Linearland which is a\nstraight, thin peninsula.\n\nOn close observation however, Prof. Nelson Rogers finds that actually\nit is a mix of Red and Blue drops.\n\nIn his zeal, he records the location and color of the raindrops in\ndifferent locations along the peninsula.\nLooking at the data, Professor Rogers wants to know which part of\nLinearland had the ``least'' purple rain.\n\nAfter some thought, he decides to model this problem as follows.\nDivide the peninsula into $n$ sections and number them West to East\nfrom $1$ to $n$.  Then, describe the raindrops as a sequence of {\\tt\nR} and {\\tt B}, depending on whether the rainfall in each section is\nprimarily red or blue.  Finally, find a subsequence of where the\ndifference between the number of {\\tt R} and the number of {\\tt B} is\nmaximized.\n\n\n\n\\section*{Input}\n\nThe input consists of a single line containing a string of $n$\ncharacters ($1 \\le n \\le 10^5$), describing the color of the raindrops\nin sections $1$ to $n$.\n\nIt is guaranteed that the string consists of uppercase ASCII letters\n`{\\tt R}' and `{\\tt B}' only.\n\n\n\\section*{Output}\n\nPrint, on a single line, two space-separated integers that describe\nthe starting and ending positions of the part of Linearland that had\nthe least purple rain.\n\nIf there are multiple possible answers, print the one that has the\nWesternmost (smallest-numbered) starting section.  If there are multiple\nanswers with the same Westernmost starting section, print the one with\nthe Westernmost ending section.\n\n\\section*{Examples}\n\n\n", "meta": {"hexsha": "4b92ffd0c81539f49c5a581387d288094ac45ba6", "size": 1650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homeworks/dynamic-basic/purplerain_source.tex", "max_stars_repo_name": "csonmezyucel/cs4102-f21", "max_stars_repo_head_hexsha": "75f93b5801644e50cb512f9d00e0fda3e9d5dcf7", "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": "homeworks/dynamic-basic/purplerain_source.tex", "max_issues_repo_name": "csonmezyucel/cs4102-f21", "max_issues_repo_head_hexsha": "75f93b5801644e50cb512f9d00e0fda3e9d5dcf7", "max_issues_repo_licenses": ["CC0-1.0"], "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/dynamic-basic/purplerain_source.tex", "max_forks_repo_name": "csonmezyucel/cs4102-f21", "max_forks_repo_head_hexsha": "75f93b5801644e50cb512f9d00e0fda3e9d5dcf7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-01-31T21:10:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-29T23:06:24.000Z", "avg_line_length": 33.0, "max_line_length": 72, "alphanum_fraction": 0.7709090909, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.6888243681448541}}
{"text": "\\subsection{Cohen's Kappa}\n\\label{chp:fundamentals:sec:inter_rater_agreement:subsec:cohens_kappa}\nCohen's Kappa $\\kappa$ was introduced by \\textcite{Cohen:1960} in 1960.\nHe states the hypothesis that even if all raters are unaware of the correct answer and purely guess, nevertheless some datapoints are congruent.\nIn his opinion random congruency should be considered by agreement statistics.\nTo tackle this issue he introduced the kappa statistics to account for the random agreement among two raters.\nSimilar to other correlation statistics, it can take values in the range from -1 to 1.\n0 indicates the agreement obtained by random choice, whereas 1 represents perfect agreement.\nThe kappa calculation includes two quantities.\n$P_o$ is the proportion of observed agreement of raters and $P_e$ is the proportion of rating agreement expected to be obtained by chance.\nThe overall formula of Cohen's $\\kappa$ is then given by the following equation:\n\n\\begin{equation}\\label{eq:Cohens_kappa}\n    \\kappa = \\frac{P_o - P_e}{1 - P_e}\n\\end{equation}\n\nConsider two raters, A and B respectively, assigning $N$ datapoints to $C$ categories.\n$n_{c_i, c_j}$ indicates how many datapoints were assigned to class $c_i$ by rater $A$ while the same datapoints were assigned to class $c_j$ by rater $B$.\n$p_{A, c_i}$ represents the proportion of assignments which were assigned to class $c_i$ by rater $A$.\nAn overview for $C=3$ is given in \\cref{tab:cohens_kappa_sample_definition}.\n\n\\begin{table}[htpb]\n    \\centering\n    \\begin{tabular}{l|l|c|c|c|c}\n        \\multicolumn{2}{c}{}&\\multicolumn{3}{c}{B}&\\\\\n        \\cline{3-5}\n        \\multicolumn{2}{c|}{}&$c_1$&$c_2$&$c_3$&\\multicolumn{1}{c}{Proportion}\\\\\n        \\cline{2-5}\n        \\multirow{3}{*}{A}& $c_1$ & $n_{c_1, c_1}$ & $n_{c_1, c_2}$ &$n_{c_1, c_3}$& $p_{A, c_1}$\\\\\n        \\cline{2-5}\n        & $c_2$ & $n_{c_2, c_1}$ & $n_{c_2, c_2}$ &$n_{c_2, c_3}$&$p_{A, c_2}$\\\\\n        \\cline{2-5}\n        & $c_3$ & $n_{c_3, c_1}$ & $n_{c_3, c_2}$ &$n_{c_3, c_3}$ & $p_{A, c_3}$\\\\\n        \\cline{2-5}\n        \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{Proportion} & \\multicolumn{1}{c}{$p_{B, c_1}$} & \\multicolumn{1}{c}{$p_{B, c_2}$} & \\multicolumn{1}{c}{$p_{B, c_3}$} & \\multicolumn{1}{c}{$1$}\\\\\n    \\end{tabular}\n    \\caption[Cohen's Kappa notation overview]{Example confusion matrix.}\\label{tab:cohens_kappa_sample_definition}\n\\end{table}\n\n$P_o$ is then given by: %TODO check here for unwanted page breaks\n\\begin{equation}\\label{eq:Cohens_kappa:p_o}\n    P_o = \\frac{\\sum_{i=1}^{C} n_{c_i, c_i}}{N}\n\\end{equation}\n\nWhereas the expected agreement by chance $P_e$ is calculated according to \\cref{eq:Cohens_kappa:p_e}:\n\\begin{equation}\\label{eq:Cohens_kappa:p_e}\n    P_e = \\sum_{i=1}^{C} p_{A, c_i} p_{B, c_i}\n\\end{equation}\n\nAn example for the case $C=2$ is illustrated in \\cref{tab:cohens_kappa_sample_data}.\nHere two raters rated 50 datapoints as \\textit{Good} or \\textit{Bad}.\n\n\\begin{table}[htpb]\n    \\centering\n    \\begin{tabular}{l|l|c|c|c}\n        \\multicolumn{2}{c}{}&\\multicolumn{2}{c}{A}&\\\\\n        \\cline{3-4}\n        \\multicolumn{2}{c|}{}&Good&Bad&\\multicolumn{1}{c}{Proportion}\\\\\n        \\cline{2-4}\n        \\multirow{2}{*}{B}& Good & $20$ & $5$ & $0.5$\\\\\n        \\cline{2-4}\n        & Bad & $10$ & $15$ & $0.5$\\\\\n        \\cline{2-4}\n        \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{Proportion} & \\multicolumn{1}{c}{$0.6$} & \\multicolumn{    1}{c}{$0.4$} & \\multicolumn{1}{c}{$1$}\\\\\n    \\end{tabular}\n    \\caption[Cohen's Kappa sample data]{Example data of 2 raters assigning 50 datapoints to two categories.}\\label{tab:cohens_kappa_sample_data}\n\\end{table}\n\nGiven \\cref{tab:cohens_kappa_sample_data}, one can directly calculate $P_o = \\frac{ 20 + 15 }{50} = 0.7$ and $P_e = 0.6 \\cdot 0.5 + 0.4 \\cdot 0.5 = 0.5$.\nNow $P_o$ and $P_e$ are plugged into \\cref{eq:Cohens_kappa} which yields a kappa $\\kappa = \\frac{0.7 - 0.5}{1 - 0.5} = 0.4$.\n", "meta": {"hexsha": "fcb2beb7b6f7288a831ea417f696142b294fd734", "size": 3889, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/cohens_kappa.tex", "max_stars_repo_name": "HaaLeo/vague-requirements-thesis", "max_stars_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/cohens_kappa.tex", "max_issues_repo_name": "HaaLeo/vague-requirements-thesis", "max_issues_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/cohens_kappa.tex", "max_forks_repo_name": "HaaLeo/vague-requirements-thesis", "max_forks_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7746478873, "max_line_length": 194, "alphanum_fraction": 0.6634096169, "num_tokens": 1437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6888243610508932}}
{"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}. It is conventional to use \\hyperref[rem:additive_magma]{additive notation} for abelian groups.\n\n  We denote by \\( \\cat{Ab} \\) the category of abelian groups.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:abelian_normal_subgroups}\n  All subgroups of an abelian group are \\hyperref[def:normal_subgroup]{normal}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\mscrG \\) be abelian and \\( \\mscrH \\) be a subgroup of \\( \\mscrG \\). Then \\( x \\mscrG x^{-1} = xx^{-1} \\mscrH = \\mscrH \\) for any \\( x \\in G \\) and thus \\( \\mscrH \\) is normal.\n\\end{proof}\n\n\\begin{definition}\\label{def:group_of_integers_modulo}\n  The \\hyperref[def:set_of_integers]{integers} \\( \\BbbZ \\) notoriously form an abelian group under addition. Fix a positive integer \\( n \\). We define the group\n  \\begin{equation*}\n    \\BbbZ_n \\coloneqq \\{ 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 \\).\n\\end{definition}\n\\begin{proof}\n  We will prove that \\( \\BbbZ_n \\) is an abelian group.\n\n  \\SubProofOf{def:magma/associative} 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:unital_magma} The zero is obviously the identity.\n\n  \\SubProofOf{def:unital_magma_inverse_element} 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[def:group_of_integers_modulo]{integers modulo \\( n \\)} is isomorphic to the quotient of \\( \\BbbZ \\) by \\( n\\BbbZ = \\{ nz : z \\in \\BbbZ \\} \\), i.e.\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 \\), there exists a bijection between \\( n \\BbbZ \\times \\BbbZ_n \\) and \\( \\BbbZ \\).\n\n  This bijection, however, is not necessarily a group isomorphism because \\eqref{thm:integers_modulo_isomorphic_to_quotient_group} may not hold.\n\n  Let \\( f: \\BbbZ \\to n \\BbbZ \\times \\BbbZ_n \\) be a bijection. Then, for every integer \\( k \\) there exist integers \\( m_k \\in \\BbbZ \\) and \\( r_k \\in \\BbbZ_n \\) such that\n  \\begin{equation*}\n    f(k) = (n m_k, r_k).\n  \\end{equation*}\n\n  For \\( (mn, p) \\in  \\)\n\\end{example}\n\n\\begin{proposition}\\label{thm:cyclic_group_isomorphic_to_integers_modulo_n}\n  Let \\( C \\) be a cyclic \\hyperref[def:cyclic_group]{group}. If \\( C \\) is finite of order \\( n \\), it is isomorphic to the group \\( \\BbbZ_n \\) of integers modulo \\( n \\) (see \\fullref{def:group_of_integers_modulo}).\n\\end{proposition}\n\\begin{proof}\n  The homomorphism\n  \\begin{balign*}\n     &\\varphi: \\BbbZ_n \\to C_n \\\\\n     &\\varphi(k) \\coloneqq a^k\n  \\end{balign*}\n  and the analogous homomorphism for the infinite group, is an isomorphism.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:abelian_group_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{Ab} \\). Fix an indexed family  \\( \\{ \\mscrX_k \\}_{k \\in \\mscrK} \\) of abelian groups.\n  \\begin{thmenum}\n    \\thmitem{thm:abelian_group_categorical_limits/product} Their \\hyperref[def:discrete_category_limits]{categorical product} is the direct product as inherited from \\fullref{thm:group_categorical_limits}.\n\n    \\thmitem{thm:abelian_group_categorical_limits/coproduct} Their \\hyperref[def:discrete_category_limits]{categorical coproduct} is the \\hyperref[def:group_direct_product]{direct sum} \\( \\oplus_{k \\in \\mscrK} \\mscrX_k \\), the embedding morphisms being\n    \\begin{align*}\n       &\\iota_m: \\mscrX_m \\to \\oplus_{k \\in \\mscrK} \\mscrX_k \\\\\n       &\\iota_m(x_m) \\coloneqq \\begin{dcases}\n        \\begin{drcases}\n          x_m, &k = m \\\\\n          0_k, &k \\neq m\n        \\end{drcases}\n      \\end{dcases}_{k \\in \\mscrK}.\n    \\end{align*}\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:monoid_completion_to_abelian_group}\\mcite{nLab:grothendieck_group_of_a_commutative_monoid}\n  Every \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:unital_magma/monoid]{monoid} can be \\hyperref[def:first_order_homomorphism_invertibility/embedding]{embedded} into an abelian group using the \\term{Grothendieck completion} presented in the proof.\n\\end{proposition}\n\\begin{proof}\n  Let \\( M \\) be a commutative monoid. Define the relation \\( \\cong \\) on tuples of members of \\( M \\) as\n  \\begin{equation*}\n    (x_1, x_2) \\cong (y_1, y_2) \\iff \\exists a: x_1 + y_2 + a = y_1 + x_2 + a.\n  \\end{equation*}\n\n  This is an equivalence relation because\n  \\SubProofOf{def:binary_relation/reflexive}\n  \\begin{equation*}\n    (x_1, x_2) \\cong (x_1, x_2) \\iff x_1 + x_2 + 0 = x_1 + x_2 + 0\n  \\end{equation*}\n\n  \\SubProofOf{def:binary_relation/symmetric} By commutativity,\n  \\begin{balign*}\n    (x_1, x_2) \\cong (y_1, y_2)\n     & \\iff\n    \\exists a: x_1 + y_2 + a = y_1 + x_2 + a\n    \\\\ &\\iff\n    \\exists a: y_1 + x_2 + a = x_1 + y_2 + a\n    \\\\ &\\iff\n    (y_1, y_2) \\cong (x_1, x_2)\n  \\end{balign*}\n\n  \\SubProofOf{def:binary_relation/transitive} Let \\( (x_1, x_2) \\cong (y_1, y_2) \\) and \\( (y_1, y_2) \\cong (z_1, z_2) \\). Thus, there exist \\( a, b \\in \\BbbN \\) such that\n  \\begin{equation*}\n    [x_1 + y_2 + a = y_1 + x_2 + a] \\T{and} [y_1 + z_2 + b = z_1 + y_2 + b]\n  \\end{equation*}\n\n  Summing both sides, we have\n  \\begin{equation*}\n    x_1 + y_2 + a + y_1 + z_2 + b = y_1 + x_2 + a + z_1 + y_2 + b\n  \\end{equation*}\n\n  We reorder both sides to obtain\n  \\begin{equation*}\n    (x_1 + z_2) + (y_1 + y_2 + a + b) = (x_2 + z_1) + (y_1 + y_2 + a + b),\n  \\end{equation*}\n  which implies \\( (x_1, x_2) \\cong (z_1, z_2) \\).\n\n  Define \\( G \\coloneqq M^2 / \\cong \\) to be the equivalence partition\\fullref{thm:equivalence_partition} of \\( M \\times M \\). Define addition in \\( G \\) on members of \\( M \\times M \\) by\n  \\begin{equation*}\n    (x_1, x_2) + (y_1, y_2)\n    \\coloneqq\n    (x_1 + y_1, x_2 + y_2).\n  \\end{equation*}\n\n  This addition does not depend on the representative of the equivalence class since \\( (x_1, x_2) \\cong (x_1', x_2') \\) and \\( (y_1, y_2) \\cong (y_1', y_2') \\) implies the existence of \\( k, m \\in \\BbbN \\), such that\n  \\begin{balign*}\n    x_1 + x_2' + a&= x_2 + x_1' + a,\n    y_1 + y_2' + b&= y_2 + y_1' + b,\n  \\end{balign*}\n  which, when combined, give\n  \\begin{balign*}\n    (x_1 + x_2' + a) + (y_1 + y_2' + b)\n    &=\n    (x_2 + x_1' + a) + (y_2 + y_1' + b)\n    \\\\\n    (x_1 + y_1) + (x_2' + y_2') + (a + b)\n    &=\n    (x_2 + y_2) + (y_1 + x_1) + (a + b).\n  \\end{balign*}\n\n  This implies\n  \\begin{balign*}\n    (x_1 + y_1, x_2 + y_2)\n    \\cong\n    (x_1' + y_1', x_2' + y_2').\n  \\end{balign*}\n\n  The equivalence class \\( [(0, 0)] \\) is obviously an identity in \\( G \\) and contains exactly the pairs \\( (x, x) \\) of identical elements.\n\n  For each member \\( (x_1, x_2) \\in M \\times M \\) we define its inverse as \\( (x_2, x_1) \\). It is indeed an inverse since\n  \\begin{equation*}\n    (x_1, x_2) + (x_2, x_1) = (x_1 + x_2, x_2 + x_1),\n  \\end{equation*}\n  which, by commutativity, belongs to \\( [(0, 0)] \\).\n\n  If \\( (x_1, x_2) \\cong (x_1', x_2') \\), then\n  \\begin{equation*}\n    (x_1, x_2) + (x_2', x_1')\n    =\n    (x_1 + x_2', x_2 + x_1'),\n  \\end{equation*}\n  where the two representatives of a pair of inverses are equal because of the equivalence \\( \\cong \\).\n\n  Thus, \\( + \\) is a well-defined commutative operation on \\( G \\) with identity, making it an abelian group.\n\n  Furthermore, the function\n  \\begin{balign*}\n     & \\varphi: M \\to G              \\\\\n     & \\varphi(x) \\coloneqq [(x, 0)]\n  \\end{balign*}\n  is a monoid homomorphism, hence \\( M \\) is indeed embedded in the group. Furthermore, any group that embeds \\( G \\) must also embed \\( M \\) since \\( G \\setminus \\varphi(M) \\) consists only of the \\enquote{inverse} elements of \\( \\varphi(M) \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:group_commutator}\n  Let \\( G \\) be any group. The commutator of \\( x, y \\in G \\) is defined as\n  \\begin{equation*}\n    [x, y] \\coloneqq xyx^{-1}y^{-1}.\n  \\end{equation*}\n\n  The commutator subgroup of \\( G \\) is the subgroup \\hyperref[def:group_presentation]{generated} by all the commutators in \\( G \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:quotient_by_commutator_subgroup}\\mcite[prop. 7.4]{Knapp2016BasicAlgebra}\n  The commutator group \\( G' \\) of any group \\( G \\) is \\hyperref[def:normal_subgroup]{normal} and the quotient \\( G / G' \\) is \\hyperref[def:abelian_group]{abelian}.\n\\end{proposition}\n", "meta": {"hexsha": "6e25792393855a689bd24d4b9b6ee517b829591a", "size": 10189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/abelian_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/abelian_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/abelian_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": 39.6459143969, "max_line_length": 264, "alphanum_fraction": 0.6327411915, "num_tokens": 3911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.6888243452874563}}
{"text": "\\section{Continuous data model}\n\\label{sec:continuousDataModel}\nA general nonlinear mixed effects model for continuous data for $N$ subjects and $n_i$ measurements per subject $i$ reads as follows (\\cite{Lavielle:2012b}):\n\\begin{align}\n \\underbrace{ y_{ij}}_{\\text{\\parbox{2cm}{\\centering Experimental \\\\[-4pt]  data}}} =\n \\underbrace{ f(x_{ij}, \\psi_{i})}_{\\text{\\parbox{2.5cm}{\\centering Model \\\\[-4pt]  prediction}}} + \n \\underbrace{ g(x_{ij}, \\psi_{i}, \\xi) \\; \\epsilon_{ij}}_{\\text{\\parbox{3cm}{\\centering Error}}} \n\\quad 1\\le i \\le N, \\quad 1\\le j \\le n_i \\label{eq:nlmeModel}\n \\end{align}\nwith\n\\begin{itemize}\n\\item\n$y_{ij}$ -- $j^{th}$ observation for subject $i$\n\\item\n$f$ -- structural model prediction\n\\item\n$x_{ij}$ -- regression variables, e.g. $time$ or $concentration$\n\\item\n$\\psi_{i}$ -- individual parameters\n\\item\n$\\epsilon_{ij}$ -- residual error\n\\item\n$g$ -- standard deviation of the residual error\n\\item \n$\\xi$ -- parameters of the residual model\n\\end{itemize}\nWith $\\epsilon_{ij}$ being normal distributed with mean 0 and variance 1, $y_{ij}$ is also normally distributed with mean $ f(x_{ij}, \\psi_{i})$ and the standard deviation $g(x_{ij}, \\psi_{i}, \\xi)$. \n", "meta": {"hexsha": "dd57674d288172cd41b37eaddbbdeb173dabcbaf", "size": 1184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "input/continuousDataModel_specSection.tex", "max_stars_repo_name": "pharmml/pharmml-spec", "max_stars_repo_head_hexsha": "b102aedd082e3114df26a072ba9fad2d1520e25f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-01-26T13:17:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-26T13:17:54.000Z", "max_issues_repo_path": "input/continuousDataModel_specSection.tex", "max_issues_repo_name": "pharmml/pharmml-spec", "max_issues_repo_head_hexsha": "b102aedd082e3114df26a072ba9fad2d1520e25f", "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": "input/continuousDataModel_specSection.tex", "max_forks_repo_name": "pharmml/pharmml-spec", "max_forks_repo_head_hexsha": "b102aedd082e3114df26a072ba9fad2d1520e25f", "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": 42.2857142857, "max_line_length": 200, "alphanum_fraction": 0.6908783784, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6887970238899145}}
{"text": "\n\n\\subsection{Scalar fields}\n\nA scalar field is a function on an underlying input which produces a real output.\n\nInputs are not limited to real numbers. In this section we consider functions on vector spaces.\n\n\\subsection{Del}\n\n\\(\\nabla =(\\sum_{i=1}^n e_i\\dfrac{\\delta }{\\delta x_i})\\)\n\nWhere \\(e\\) are the basis vectors.\n\nThis on its own means nothing. It is similar to the partial differentiation function.\n\n", "meta": {"hexsha": "545a4fe78d395e1be1fd90a61492eedc056edf19", "size": 410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiScalar/01-02-del.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/multiScalar/01-02-del.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/multiScalar/01-02-del.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.1176470588, "max_line_length": 95, "alphanum_fraction": 0.7463414634, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6887155121100719}}
{"text": "\\subsection{Integration}\r\n\\noindent\r\nThe line element is $\\mathrm{d}s^2 = \\mathrm{d}r^2 + r^2\\mathrm{d}\\theta^2$, meaning that $s = \\int_{\\theta_1}^{\\theta_2}{\\sqrt{r^2 + \\left(\\frac{\\mathrm{d}r}{\\mathrm{d}\\theta}\\right)}\\mathrm{d}\\theta}$.\\\\\r\nThe area element is $\\mathrm{d}A = r\\mathrm{d}r\\mathrm{d}\\theta$, meaning that $A = \\int_{\\theta_1}^{\\theta_2}{r^2\\mathrm{d}\\theta}$.\r\n\r\n\\input{./curvilinearCoordinates/gaussianIntegral}", "meta": {"hexsha": "1aa3c892f590190a54d16ba27e193019c29b1b8c", "size": 430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/integration_polar.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/integration_polar.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/integration_polar.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 71.6666666667, "max_line_length": 206, "alphanum_fraction": 0.676744186, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6886951482671779}}
{"text": "\\documentclass{amsart}\r\n\\newcommand{\\cC}{\\mathcal {C}}\r\n\\newcommand{\\RR}{\\mathbb {R}}\r\n\\newcommand{\\PP}{\\mathbb {P}}\r\n\\newcommand {\\bv} {\\mathbf {v}}\r\n\\newcommand {\\bw} {\\mathbf {w}}\r\n\\newcommand {\\be} {\\mathbf {e}}\r\n\\usepackage{tikz-cd}\r\n\\title {Obnoxious notes to perspective drawing}\r\n\\author {Hei}\r\n\\begin{document}\r\n\\maketitle\r\nThese are our notes to studying perspective without the crutch of cubes. Oh, well, as we added some notes on how to apply this to drawing, there are cubes now.  We think this definitely helped with our\r\ndrawing skills.  Please let us know any inaccuracies.\r\n\r\n\\section{The Perspective Projection Map}\r\n\\label{sec:persp-proj-map}\r\n\r\nWe consider the $3$-dimensional Euclidean space $\\RR^3$. Let $V$ be the viewing plane and $O$ be the eye point. Then the perspective drawing is, in essence,\r\nthe projection to $V$ with respect to $O$. More precisely, the image of a point $P$ in space is the point of\r\nintersection of the line $OP$ and the plane $V$. Let $f$ denote this map.\r\n\r\n[TODO: figure of map]\r\n\r\nWithout loss of generality, we set $O$ to be the origin and $V$ to be the plane $z=1$. Then the map $f$ is given by:\r\n\\begin{align*}\r\n  f: \\RR^3\\backslash \\{z=0\\} &\\rightarrow V \\\\\r\n  (x,y,z) &\\mapsto (x/z,y/z,1).\r\n\\end{align*}\r\nWe may identify the affine space $V$ with $\\RR^2$ by taking the vector part, more precisely, by dropping the $z$-coordinate. In application, we restrict $f$ to the domain  $z>0$.\r\n\r\nLet $W$ be a plane. As long as $W$ does not pass $O$, then $f|_W$ is a bijection.\r\n\r\nLet $C$ be intersection of the locus of a degree $n$ polynomial $p$ with the plane $W$, i.e., the points on $C$ satisfies $p$ in addition to a degree $1$ polynomial. In this case, it is easy to see that points on the image of $C$ also satisfies a degree $n$ polynomial.\r\n\r\nIn particular, $f$  maps lines to lines and conics to conics. Signature is not preserved however. Thus it is possible for the types of conics to change. In application, the image of an ellipse must be an ellipse; otherwise, the source ellipse intersects the $xy$-plane. This can be seen by going back to the original meaning of conics: curves cut from cones by planes.\r\n\r\n\r\n\r\n\\section{The Vanishing Point}\r\n\\label{sec:vanishing-point}\r\n\r\nLet $\\bv$ be a vector. Let $\\ell$ be a line passing through a point $P$ and parallel to $\\bv$. Then points on $\\ell$ can be parametrised as\r\n\\begin{equation*}\r\n  P + t\\bv,\\qquad t\\in\\RR.\r\n\\end{equation*}\r\n% Assume that when $t$ increases, the points go farther away from $V$. In particular, this assumes that $\\bv$ is not parallel to $V$.\r\nLet the coordinates of $P$ be given by $(x_P,y_P,z_P)$ and $\\bv$ given by $(v_1,v_2,v_3)$. Then if $v_3\\neq 0$, i.e., $\\bv$ is not parallel to $V$, then\r\n\\begin{equation*}\r\n  \\lim_{t\\rightarrow \\infty} f (P + t\\bv)\r\n  = \\lim_{t\\rightarrow \\infty} (\\frac{x_P+tv_1}{z_P+tv_3},\\frac{y_P+tv_2}{z_P+tv_3},1)\r\n  = (\\frac{v_1}{v_3},\\frac{v_2}{v_3},1).\r\n\\end{equation*}\r\nThis point is called the vanishing point of $\\ell$. If $v_3=0$, we should consider infinity to be the vanishing point. The meaning of infinity and which infinity point can be made precise by using projective geometry.\r\nLet $\\cC_\\bv$ be the collection of lines parallel to $\\bv$. In fact, the vanishing point depends only on $\\bv$, not on the choice of $\\ell$ in $\\cC_\\bv$. Let $\\cC_\\bv$ be the collection of lines parallel to $\\bv$. Thus every line in $\\cC_\\bv$ has the same vanishing point. Thus their images appear to radiate from one point. Note that if we restrict to the $z>0$ part, the image is a ray.\r\n\r\n[TODO: figure of VP for parallel lines.]\r\n\r\n\r\nLet $\\ell_O$ be the line which is parallel to $v$ and which contains $O$. Geometrically the vanishing point for $\\cC_\\bv$ is just the point of intersection of $\\ell_O$ and $V$.\r\n\r\nThus we can answer the question of how many vanishing points there are in a drawing. The answer is the number of lines with different direction vectors. In scenes like cityscape, there are generally three sets of parallel lines with different direction vectors. Each produces a vanishing point as long as the set of lines are not parallel to $V$. We get the so-called 3-point, 2-point and 1-point perspectives.\r\n\r\nLet $W$ be a plane. The set of vanishing points of lines contained in $W$ form a line. Geometrically it is given by intersecting the plane passing through $O$ and parallel to $W$ with $V$. Let us call it the vanishing line of $W$. In application, when $W$ is taken to be the ground plane, the  vanishing line  of $W$ is usually called the horizon or eye level.\r\n\r\n[TODO: figure of VL for parallel planes.]\r\n\r\nIn practice, image of lines are easy to determine once we put down the vanishing points. If we know a point to be the intersections of two lines, we may find its image by finding the intersection of the images of the two lines. As line segments of the same length do not map to line segments of the same length under the perspective projection, this provides an easy way to determine location of image of a point. We can find the image of the centre of a rectangle by intersecting the diagonals of the image of the rectangle, for example. Once we know the image of the centre, we can find image of the disecting points and hence we know how to find the image of the rectangle that extends the original rectangle by one time of its width.\r\n\r\n\\section{Measuring Distance}\r\n\\label{sec:transfer-distance}\r\n\r\nThe aim of this section is to study images of line segments of equal length. In application, essentially we operate on $V$ only. One problem arises often. We have the image of a line segment as reference. How do we find the image of the same length along another line?\r\n\r\nWhat we have available are the vanishing points and the reference line segment on $V$. Once we supply the information of the relative position of $O$ to the lines, then we can transfer the distance from one line to another.\r\n\r\nLet $\\ell$ be a line. Let $P$ and $Q$ be two points on $\\ell$.  Let $\\ell'$ be another line that passes through $P$. Let $R$ be a point on $\\ell'$ such that $|PQ|=|PR|$. Let $A$ be the vanishing point of $\\ell$ and $B$ that of $\\ell'$. We would like to find $f (R)$ in terms of $f (P)$, $f (Q)$, $A$ and $B$.\r\n\r\nOne  observation is that if we know the vanishing point $C$ of $QR$ then $f (R)$ can be found as the intersection of the line connecting $CQ$ and the line connecting $BP$. However the location of $C$ cannot be determined by $f (P)$, $f (Q)$, $A$ and $B$ alone.  We need an additional piece of data,  the location of $O$ relative to $\\ell$ and $\\ell'$. We focus on the plane $W$ through $O$ and parallel to both $\\ell$ and $\\ell'$. We translate $\\ell$ and $\\ell'$ to $W$ along a vector that is parallel to $V$ and orthogonal to $AB$. We use superscript $t$ to denote the translated object. On $(\\ell')^t$ find the point $S$ such that $|P^tS|=|P^tQ^t|$. Note that $QR$ is parallel to $Q^tS$. Then $C$ is the intersection of $AB$ and $Q^tS$.\r\n\r\n[TODO: figure view of $V$.]\r\n\r\n[TODO: figure view of $W$ to get $C$]\r\n\r\nIn practice, $\\ell$ and $\\ell'$ are orthogonal, forming two edges of a cube.\r\n\r\n\\section{Application to Drawing}\r\n\\label{sec:application-drawing}\r\n\r\n\\subsection{Centre of rectangle and extension of length}\r\n\\label{sec:centre-rect-extens}\r\n\r\nThis is already mentioned above.\r\n\r\n\\subsection{Shadow}\r\n\\label{sec:shadow}\r\n\r\nThis is an application of the intersection method. One common need is to find the cast shadow of a stick that stands vertically on the ground under sunlight. Sunlight can be considered as parallel light with given direction $\\bv$. The location of shadow of the foot $F$ of the stick is obvious. Let $P$ be the top of the stick. The location of shadow $Q$ of top of stick lies on the line parallel to $\\bv$ through $P$. It also lies on the ground plane $G$. Thus it lies on the line $L$ that is the intersection of the plane parallel to the vertical direction and $\\bv$ through $P$ and the plane $G$. Also consider the line $M$ through the shadow point $Q$ on the ground $G$ perpendicular to $V$. If we consider the component $\\bw$ of light that is parallel to $V$, then the line through $P$ along $\\bw$ intersects $M$ and call the intersection $R$. Thus we get two lines whose intersection gives the shadow point $Q$.\r\n\r\nTo find the image of $Q$ on $V$, we consider the two families of parallel lines determined by $L$ and $M$ respectively. The family of parallel lines associated to $L$ produces a vanishing point, which we call the ground vanishing point of light (GVPL). Thus $f (Q)$ lies on the line connecting $f (F)$ and GVPL. The point $f (R)$ is easy to find, if we know $f (F)$ and the horizon line and the $V$-component $\\bw$ of $\\bv$. Let $C$ be the vanishing point for the receding lines that are parallel to the normal of $V$. Then $f (Q)$ also lies on the line connecting $C$ and $f (R)$. Then using the intersection of the two lines we find $f (Q)$.\r\n\r\nSummary: Shadow of top=(GLVP--foot) $\\cap$ (centre--horizontal shadow drop).\r\n\r\nThis can be generalised to finding cast shadow of any point to any plane which may not be orthogonal to the viewing plane. In this case direction of light can be encoded in vanishing point of shadow on the plane and vanishing point of component of light on the plane which is orthogonal to the given plane and which is parallel to the line of intersection of the given plane and the viewing plane. We should give this plane a name to avoid long-winded sentences.\r\n\r\n\\section{Projective Geometry}\r\n\\label{sec:projective-geometry}\r\n\r\nIt is cumbersome to always have to differentiate between the cases when family of parallel lines has image lines that radiate from one point or lines that remain parallel. It is best to add points at `infinity'. How many points of infinities are there? In $\\RR^2$ the families of parallel lines are indexed by direction vectors. Thus we should glue on $\\PP^1:= (\\RR^2 - \\{0\\})/\\RR^\\times$ of them. This gives us the projective space $\\PP^2$, in which $\\RR^2$ is embedded as follows:\r\n\\begin{align*}\r\n  \\RR^2 &\\rightarrow \\PP^2 \\\\\r\n  (x,y) &\\mapsto (x:y:1)\r\n\\end{align*}\r\nwhile points at infinity embed as follows:\r\n\\begin{align*}\r\n  \\PP^1 &\\rightarrow \\PP^2\\\\\r\n  (a:b) &\\mapsto (a:b:0).\r\n\\end{align*}\r\nOnce we call the point $(a:b:0)$ the vanishing point of family of parallel line along the vector $(a,b,0)$, then we can write the theory in a more uniform way.\r\n\r\n\\section{Intersection Method}\r\n\\label{sec:intersection-method}\r\n\r\nOne can use two VLs to determine VP of the intersection  line and one can also use VPs of two lines to determine VL of the plane parallel to both lines.\r\n\r\n% For planes parallel to $V$, the effect of $f$ is obvious.\r\n% \\begin{equation*}\r\n%   \\begin{tikzcd}\r\n%     \\{z=z_0\\} \\ar [r] \\ar [d,\"\\simeq\",sloped] & V \\ar [d,\"\\simeq\", sloped]\\\\\r\n%     \\RR^2 \\ar [r] & \\RR^2 \\\\ [-10pt]\r\n%     (x,y)\\ar [r,mapsto] &(x/z_0,y/z_0),\r\n%   \\end{tikzcd}\r\n% \\end{equation*}\r\n% which is just scaling. Here the two vertical arrows means dropping $z$-coordinate. Thus an equispaced grid does the job.\r\n\r\n\r\n\r\n% Next we consider a line $\\ell$ not parallel to $V$. Let $A$ be the vanishing point of $\\ell$ and $P$ the intersection of $\\ell$ and $V$. Take orthonormal basis for $V$ (more precisely, the vector part of $V$) where one basis vector $\\be_1$ is along the direction of $f (\\ell)$ and the other $\\be_2$ orthogonal to $f (\\ell)$. This produces a grid on $V$. The aim now is to locate the image of the point on $\\ell$ that is at $x$ units to  $P$.\r\n\r\n% Let $Q=P+x\\be_1$ and $R=P+x\\be_2$. Let $S$ be the point on $\\ell$ at distance $x$ to $P$. Let $B$ be the vanishing point of $QS$. It lies on $f (\\ell)$. Then we can locate $f (S)$ geometrically as follows. Let $T=Q+x\\be_2$. Find the intersection of $AR$ and $BT$. Then project it orthogonally to $f (\\ell)$. The image is $f (S)$. When we take $x$ to be integers, we produce a grid on $\\ell$.\r\n\r\n% [TODO: figure of how to find $S$.]\r\n\r\n% In practice, one usually sets up vanishing points for lines corresponding to edges of a cube first. Then one may use the top down view to plot out the vanishing points for the 3 diagonal lines on facets of the cube. Then the vertices of the cube can be found using the method outlined above. In this way we can form a `3d grid' on $V$.\r\n\r\n% [TODO: figure of grid on $V$.]\r\n\\end{document}\r\n", "meta": {"hexsha": "241c4bfd1cc7a780e2b99d135590a68377be9666", "size": 12328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/perspective-drawing.tex", "max_stars_repo_name": "heiegg/arto", "max_stars_repo_head_hexsha": "1c9208cc4e93754282fe3ad2dfa25ac283f36929", "max_stars_repo_licenses": ["MIT"], "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/perspective-drawing.tex", "max_issues_repo_name": "heiegg/arto", "max_issues_repo_head_hexsha": "1c9208cc4e93754282fe3ad2dfa25ac283f36929", "max_issues_repo_licenses": ["MIT"], "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/perspective-drawing.tex", "max_forks_repo_name": "heiegg/arto", "max_forks_repo_head_hexsha": "1c9208cc4e93754282fe3ad2dfa25ac283f36929", "max_forks_repo_licenses": ["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.2972972973, "max_line_length": 918, "alphanum_fraction": 0.7118754056, "num_tokens": 3456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.688682039992461}}
{"text": "\\section{Groups in univalent mathematics}\n\nIn this section we demonstrate a typical way to use the univalence axiom\\index{univalence axiom}, showing that isomorphic groups can be identified.\nThis is an instance of the \\emph{structure identity principle}\\index{structure identity principle}, which is described in more detail in section 9.8 of \\cite{hottbook}.\nWe will see that in order to establish the fact that isomorphic groups can be identified, it has to be part of the definition of a group that its underlying type is a set. This is an important observation: in many branches of algebra the objects of study are \\emph{set-level} structures\\index{set-level structure}\\footnote{A notable exception is that of categories, which are objects at truncation level $1$, i.e., at the level of \\emph{groupoids}. We will briefly introduce categories in \\cref{sec:categories}. For more about categories we recommend Chapter 9 of \\cite{hottbook}.}.\n\n\\subsection{Semi-groups and groups}\nWe introduce the type of groups in two stages: first we introduce the type of \\emph{semi-groups}, and then we introduce groups as semi-groups that possess further structure. It will turn out that this further structure is in fact a property, and this fact will help us to prove that isomorphic groups are equal.\n\n\\begin{defn}\n  A \\define{semi-group}\\index{semi-group} consists of a set $G$ equipped with a term of type $\\hasassociativemul(G)$, which is the type of pairs $(\\mu_G,\\assoc_G)$ consisting of a binary operation\n  \\begin{equation*}\n    \\mu_G : G \\to (G \\to G)\n  \\end{equation*}\n  and a homotopy\n  \\begin{equation*}\n    \\assoc_G : \\prd{x,y,z:G}\\mu_G(\\mu_G(x,y),z)=\\mu_G(x,\\mu_G(y,z)).\n  \\end{equation*}\n  We write $\\semigroup$\\index{Semi-Group@{$\\semigroup$}} for the type of all semi-groups in $\\UU$.\n\\end{defn}\n\n\\begin{defn}\n  A semi-group $G$ is said to be \\define{unital}\\index{semi-group!unital}\\index{unital semi-group} if it comes equipped with a \\define{unit}\\index{unit!of a unital semi-group} $e_G:G$ that satisfies the left and right unit laws\\index{unit laws!for a unital semi-group}\n  \\begin{align*}\n    \\leftunit_G : \\prd{y:G}\\mu_G(e_G,y)=y \\\\\n    \\rightunit_G : \\prd{x:G}\\mu_G(x,e_G)=x.\n  \\end{align*}\n  We write $\\isunital(G)$\\index{is-unital@{$\\isunital$}} for the type of such triples $(e_G,\\leftunit_G,\\rightunit_G)$. Unital semi-groups are also called \\define{monoids}\\index{monoid}.\n\\end{defn}\n\nThe unit of a semi-group is of course unique once it exists. In univalent mathematics we express this fact by asserting that the type $\\isunital(G)$ is a proposition for each semi-group $G$. In other words, being unital is a \\emph{property} of semi-groups rather than structure on it. This is typical for univalent mathematics: we express that a structure is a property by proving that this structure is a proposition.\n\n\\begin{lem}\n  For a semi-group $G$ the type $\\isunital(G)$ is a proposition.\\index{is-unital@{$\\isunital$}!is a proposition}\n\\end{lem}\n\n\\begin{proof}\n  Let $G$ be a semi-group. Note that since $G$ is a set, it follows that the types of the left and right unit laws are propositions. Therefore it suffices to show that any two terms $e,e':G$ satisfying the left and right unit laws can be identified. This is easy:\n  \\begin{equation*}\n    e = \\mu_G(e,e') = e'.\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{defn}\n  Let $G$ be a unital semi-group. We say that $G$ \\define{has inverses}\\index{unital semi-group!has inverses}\\index{semi-group!has inverses} if it comes equipped with an operation $x\\mapsto x^{-1}$ of type $G\\to G$, satisfying the left and right inverse laws\\index{inverse laws!for a group}\n  \\begin{align*}\n    \\leftinv_G : \\prd{x:G}\\mu_G(x^{-1},x)=e_G \\\\\n    \\rightinv_G : \\prd{x:G}\\mu_G(x,x^{-1}) = e_G.\n  \\end{align*}\n  We write $\\isgroup'(G,e)$\\index{is-group'@{$\\isgroup'$}} for the type of such triples $((\\blank)^{-1},\\leftinv_G,\\rightinv_G)$, and we write\\index{is-group@{$\\isgroup$}}\n  \\begin{equation*}\n    \\isgroup(G)\\defeq\\sm{e:\\isunital(G)}\\isgroup'(G,e)\n  \\end{equation*}\n  A \\define{group}\\index{group} is a unital semi-group with inverses. We write $\\group$\\index{Group@{$\\group$}} for the type of all groups in $\\UU$.\n\\end{defn}\n\n\\begin{lem}\n  For any semi-group $G$ the type $\\isgroup(G)$ is a proposition.\\index{is-group@{$\\isgroup$}!is a proposition}\n\\end{lem}\n\n\\begin{proof}\n  We have already seen that the type $\\isunital(G)$ is a proposition. Therefore it suffices to show that the type $\\isgroup'(G,e)$ is a proposition\\index{is-group'@{$\\isgroup'$}!is a proposition} for any $e:\\isunital(G)$.\n\n  Since a semi-group $G$ is assumed to be a set, we note that the types of the inverse laws are propositions. Therefore it suffices to show that any two inverse operations satisfying the inverse laws are homotopic.\n\n  Let $x\\mapsto x^{-1}$ and $x\\mapsto \\bar{x}^{-1}$ be two inverse operations on a unital semi-group $G$, both satisfying the inverse laws. Then we have the following identifications\n  \\begin{align*}\n    x^{-1} & = \\mu_G(e_G,x^{-1}) \\\\\n    & = \\mu_G(\\mu_G(\\bar{x}^{-1},x),x^{-1}) \\\\\n    & = \\mu_G(\\bar{x}^{-1},\\mu_G(x,x^{-1})) \\\\\n    & = \\mu_G(\\bar{x}^{-1},e_G) \\\\\n    & = \\bar{x}^{-1}\n  \\end{align*}\n  for any $x:G$. Thus the two inverses of $x$ are the same, so the claim follows.\n\\end{proof}\n\n\\begin{eg}\n  An important class of examples consists of \\define{loop spaces}\\index{loop space!of 1-type is a group@{of $1$-type is a group}}\\index{group!loop space of 1-type@{loop space of $1$-type}} $x=x$ of a $1$-type $X$, for any $x:X$. \n  We will write $\\loopspace{X,x}$ for the loop space of $X$ at $x$. \n  Since $X$ is assumed to be a $1$-type, it follows that the type $\\loopspace{X,x}$ is a set. Then we have\n  \\begin{align*}\n    \\refl{x} & : \\loopspace{X,x} \\\\\n    \\invfunc & : \\loopspace{X,x} \\to \\loopspace{X,x} \\\\\n    \\concat & : \\loopspace{X,x} \\to (\\loopspace{X,x}\\to \\loopspace{X,x}),\n  \\end{align*}\n  and these operations satisfy the group laws, since the group laws are just a special case of the groupoid laws for identity types, constructed in \\cref{sec:groupoid}.\n\\end{eg}\n\n\\begin{eg}\n  The type $\\Z$ of integers\\index{Z@{$\\Z$}!is a group}\\index{group!Z@{$\\Z$}} can be given the structure of a group, with the group operation being addition. The fact that $\\Z$ is a set follows from \\cref{thm:eq_nat,ex:set_coprod}. The group laws were shown in \\cref{ex:int_group_laws}. \n\\end{eg}\n\n\\begin{eg}\n  Our last class of examples consists of the \\define{automorphism groups}\\index{automorphism group}\\index{group!automorphism group of set} on sets. Given a set $X$, we define\\index{Aut@{$\\Aut$}}\n  \\begin{equation*}\n    \\Aut(X)\\defeq (X\\simeq X).\n  \\end{equation*}\n  The group operation of $\\Aut(X)$ is just composition of equivalences, and the unit of the group is the identity function. Note however, that although function composition is strictly associative and satisfies the unit laws strictly, composition of equivalences only satisfies the group laws up to identification because the proof that composites are equivalences is carried along.\n\n  Important special cases of the automorphism groups are the \\define{symmetric groups}\\index{symmetric groups}\\index{Sn@{$\\mathcal{S}_n$}}\\index{group!Sn@{$\\mathcal{S}_n$}}\n  \\begin{equation*}\n    \\mathcal{S}_n\\defeq \\Aut(\\Fin(n)).\n  \\end{equation*}\n\\end{eg}\n\n\\subsection{Homomorphisms of semi-groups and groups}\n\n\\begin{defn}\n  Let $G$ and $H$ be semi-groups. A \\define{homomorphism}\\index{homomorphism!of semi-groups}\\index{semi-group!homomorphism} of semi-groups from $G$ to $H$ is a pair $(f,\\mu_f)$ consisting of a function $f:G\\to H$ between their underlying types, and a term\n  \\begin{equation*}\n    \\mu_f:\\prd{x,y:G} f(\\mu_G(x,y))=\\mu_H(f(x),f(y))\n  \\end{equation*}\n  witnessing that $f$ preserves the binary operation of $G$. We will write\\index{hom(G,H) for semi-groups@{$\\hom(G,H)$ for semi-groups}}\n  \\begin{equation*}\n    \\hom(G,H)\n  \\end{equation*}\n  for the type of all semi-group homomorphisms from $G$ to $H$.\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:is-set-hom-semi-group}\n  Since it is a property for a function to preserve the multiplication of a semi-group, it follows easily that equality of semi-group homomorphisms is equivalent to the type of homotopies between their underlying functions. In particular, it follows that the type of homomorphisms of semi-groups is a set.\n\\end{rmk}\n\n\\begin{rmk}\\label{rmk:category-semi-group}\n  The \\define{identity homomorphism}\\index{identity homomorphism!of semi-groups} on a semi-group $G$ is defined to be the pair consisting of\n  \\begin{align*}\n    \\idfunc & : G \\to G \\\\\n    \\lam{x}{y}\\refl{xy} & : \\prd{x,y:G} xy = xy.\n  \\end{align*}\n  Let $f:G\\to H$ and $g:H\\to K$ be semi-group homomorphisms. Then the composite function $g\\circ f:G\\to K$ is also a semi-group homomorphism\\index{composition!of semi-group homomorphisms}, since we have the identifications\n  \\begin{equation*}\n    \\begin{tikzcd}\n      g(f(xy)) \\arrow[r,equals] & g(f(x)f(y)) \\arrow[r,equals] & g(f(x))g(f(y)).\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the identity type of semi-group homomorphisms is equivalent to the type of homotopies between semi-group homomorphisms it is easy to see that semi-group homomorphisms satisfy the laws of a category, i.e., that we have the identifications\n  \\begin{align*}\n    \\idfunc\\circ f & = f \\\\\n    g\\circ \\idfunc & = g \\\\\n    (h\\circ g) \\circ f & = h \\circ (g \\circ f)\n  \\end{align*}\n  for any composable semi-group homomorphisms $f$, $g$, and $h$. Note, however that these equalities are not expected to hold judgmentally, since preservation of the semi-group operation is part of the data of a semi-group homomorphism.\n\\end{rmk}\n\n\\begin{defn}\n  Let $G$ and $H$ be groups. A \\define{homomorphism}\\index{homomorphism!of groups}\\index{group!homomorphism} of groups from $G$ to $H$ is defined to be a semi-group homomorphism between their underlying semi-groups. We will write\\index{hom(G,H) for groups@{$\\hom(G,H)$ for groups}}\n  \\begin{equation*}\n    \\hom(G,H)\n  \\end{equation*}\n  for the type of all group homomorphisms from $G$ to $H$.\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:category-group}\n  Since a group homomorphism is just a semi-group homomorphism between the underlying semi-groups, we immediately obtain the identity homomorphism\\index{identity homomorphism!for groups}, composition\\index{composition!of group homomorphisms}, and the category laws are satisfied.\n\\end{rmk}\n\n\\subsection{Isomorphic semi-groups are equal}\n\n\\begin{defn}\nLet $h:\\hom(G,H)$ be a homomorphism of semi-groups. Then $h$ is said to be an \\define{isomorphism}\\index{group homomorphism!isomorphism}\\index{isomorphism!of groups} if it comes equipped with a term of type $\\isiso(h)$\\index{is-iso for semi-groups@{$\\isiso$ for semi-groups}}, consisting of triples $(h^{-1},p,q)$ consisting of a homomorphism $h^{-1}:\\hom(H,G)$ of semi-groups and identifications\n\\begin{equation*}\np:h^{-1}\\circ h=\\idfunc[G]\\qquad\\text{and}\\qquad q:h\\circ h^{-1}=\\idfunc[H]\n\\end{equation*}\nwitnessing that $h^{-1}$ satisfies the inverse laws\\index{inverse laws!for semi-group isomorphisms}We write $G\\cong H$ for the type of all isomorphisms of semi-groups from $G$ to $H$, i.e.,\n\\begin{equation*}\nG\\cong H \\defeq \\sm{h:\\hom(G,H)}{k:\\hom(H,G)} (k\\circ h = \\idfunc[G])\\times (h\\circ k=\\idfunc[H]).\n\\end{equation*}\n\\end{defn}\n\nIf $f$ is an isomorphism, then its inverse is unique. In other words, being an isomorphism is a property.\n\n\\begin{lem}\n  For any semi-group homomorphism $h:\\hom(G,H)$, the type\n  \\begin{equation*}\n    \\isiso(h)\n  \\end{equation*}\n  is a proposition.\\index{is-iso for semi-groups@{$\\isiso$ for semi-groups}!is a proposition} It follows that the type $G\\cong H$ is a set for any two semi-groups $G$ and $H$.\n\\end{lem}\n\n\\begin{proof}\n  Let $k$ and $k'$ be two inverses of $h$. In \\cref{rmk:is-set-hom-semi-group} we have observed that the type of semi-group homomorphisms between any two semi-groups is a set. Therefore it follows that the types $h\\circ k=\\idfunc$ and $k\\circ h=\\idfunc$ are propositions, so it suffices to check that $k=k'$. In \\cref{rmk:is-set-hom-semi-group} we also observed that the equality type $k=k'$ is equivalent to the type of homotopies $k\\htpy k'$ between their underlying functions. We construct a homotopy $k\\htpy k'$ by the usual argument:\n  \\begin{equation*}\n    \\begin{tikzcd}\n      k(y) \\arrow[r,equals] & k(h(k'(y)) \\arrow[r,equals] & k'(y).\n    \\end{tikzcd}\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{lem}\\label{lem:grp_iso}\n  A semi-group homomorphism $h:\\hom(G,H)$ is an isomorphism if and only if its underlying map is an equivalence. Consequently, there is an equivalence\n  \\begin{equation*}\n    (G\\cong H)\\simeq \\sm{e:G\\simeq H}\\prd{x,y:G}e(\\mu_G(x,y))=\\mu_H(e(x),e(y))\n  \\end{equation*}\n\\end{lem}\n\n\\begin{proof}\n  If $h:\\hom(G,H)$ is an isomorphism, then the inverse semi-group homomorphism also provides an inverse of the underlying map of $h$. Thus we obtain that $h$ is an equivalence. The standard proof showing that if the underlying map $f:G\\to H$ of a group homomorphism is invertible then its inverse is again a group homomorphism also works in type theory.\n\\end{proof}\n\n\\begin{defn}\nLet $G$ and $H$ be a semi-groups. We define the map\\index{iso-eq for semi-groups@{$\\isoeq$ for semi-groups}}\n\\begin{equation*}\n\\isoeq : (G=H)\\to (G\\cong H)\n\\end{equation*}\nby path induction, taking $\\refl{G}$ to isomorphism $\\idfunc[G]$.\n\\end{defn}\n\n\\begin{thm}\\label{thm:iso-eq-semi-group}\nThe map\\index{identity type!of Semi-Group@{of $\\semigroup$}}\\index{Semi-Group@{$\\semigroup$}!identity type}\n\\begin{equation*}\n\\isoeq : (G=H)\\to (G\\cong H)\n\\end{equation*}\nis an equivalence for any two semi-groups $G$ and $H$.\n\\end{thm}\n\n\\begin{proof}\nBy the fundamental theorem of identity types \\cref{thm:id_fundamental}\\index{fundamental theorem of identity types} it suffices to show that the total space\n\\begin{equation*}\n\\sm{G':\\semigroup}G\\cong G'\n\\end{equation*}\nis contractible. Since the type of isomorphisms from $G$ to $G'$ is equivalent to the type of equivalences from $G$ to $G'$ it suffices to show that the type\n\\begin{equation*}\n  \\sm{G':\\semigroup}\\sm{e:\\eqv{G}{G'}}\\prd{x,y:G}e(\\mu_G(x,y))=\\mu_{G'}(e(x),e(y)))\n\\end{equation*}\nis contractible\\footnote{In order to show that a type of the form\n  \\begin{equation*}\n    \\sm{(x,y):\\sm{x:A}B(x)}\\sm{z:C(x)}D(x,y,z)\n  \\end{equation*}\n  is contractible, a useful strategy is to first show that the type $\\sm{x:A}C(x)$ is contractible. Once this is established, say with center of contraction $(x_0,z_0)$, it suffices to show that the type $\\sm{y:B(x_0)}D(x_0,y,z_0)$ is contractible.}. Since $\\semigroup$ is the $\\Sigma$-type\n\\begin{equation*}\n  \\sm{G':\\Set}\\hasassociativemul(G'),\n\\end{equation*}\nit suffices to show that the types\n\\begin{align*}\n  & \\sm{G':\\Set}\\eqv{G}{G'} \\\\\n  & \\sm{\\mu':\\hasassociativemul(G)}\\prd{x,y:G}\\mu_G(x,y)=\\mu'(x,y)\n\\end{align*}\nis contractible. The first type is contractible by the univalence axiom. The second type is contractible by function extensionality.\n\\end{proof}\n\n\\begin{cor}\nThe type $\\semigroup$ is a $1$-type.\\index{Semi-Group@{$\\semigroup$}!is a 1-type@{is a $1$-type}}\n\\end{cor}\n\n\\begin{proof}\nIt is straightforward to see that the type of group isomorphisms $G\\cong H$ is a set, for any two groups $G$ and $H$.\n\\end{proof}\n\n\\subsection{Isomorphic groups are equal}\n\nAnalogously to the map $\\isoeq$ of semi-groups, we have a map $\\isoeq$ of groups. Note, however, that the domain of this map is now the identity type $G=H$ of the \\emph{groups} $G$ and $H$, so the maps $\\isoeq$ of semi-groups and groups are not exactly the same maps.\n\n\\begin{defn}\n  Let $G$ and $H$ be groups. We define the map\\index{iso-eq for groups@{$\\isoeq$ for groups}}\n  \\begin{equation*}\n    \\isoeq : (G=H)\\to (G\\cong H)\n  \\end{equation*}\n  by path induction, taking $\\refl{G}$ to the identity isomorphism $\\idfunc:G\\cong G$.\n\\end{defn}\n\n\\begin{thm}\n  For any two groups $G$ and $H$, the map\\index{identity type!of Group@{of $\\group$}}\\index{Group@{$\\group$}!identity type}\n  \\begin{equation*}\n    \\isoeq:(G=H)\\to (G\\cong H)\n  \\end{equation*}\n  is an equivalence.\n\\end{thm}\n\n\\begin{proof}\n  Let $G$ and $H$ be groups, and write $UG$ and $UH$ for their underlying semi-groups, respectively. Then we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}\n      (G=H) \\arrow[rr,\"\\apfunc{\\proj 1}\"] \\arrow[dr,swap,\"\\isoeq\"] & & (UG=UH) \\arrow[dl,\"\\isoeq\"] \\\\\n      & (G\\cong H)\n    \\end{tikzcd}\n  \\end{equation*}\n  Since being a group is a property of semi-groups it follows that the projection map $\\group\\to\\semigroup$ forgetting the unit and inverses, is an embedding. Thus the top map in this triangle is an equivalence. The map on the right is an equivalence by \\cref{thm:iso-eq-semi-group}, so the claim follows by the 3-for-2 property.\n\\end{proof}\n\n\\begin{cor}\n  The type of groups is a $1$-type.\\index{Group@{$\\group$}!is a 1-type@{is a $1$-type}}\n\\end{cor}\n\n\\subsection{Categories in univalent mathematics}\n\\label{sec:categories}\n\nIn our proof of the fact that isomorphic groups are equal we have made extensive use of the notion of group homomorphism. What we have shown, in fact, is that there is a category of groups which is \\emph{Rezk complete} in the sense that the type of isomorphisms between two objects is equivalent to the type of identifications between those objects. In this final section we briefly introduce the notion of Rezk complete category. There are many more examples of categories, such as the categories of rings, or modules over a ring.\n\n\\begin{defn}\n  A \\define{pre-category}\\index{pre-category} $\\mathcal{C}$ consists of\n  \\begin{enumerate}\n  \\item A type $A$ of \\define{objects}.\\index{pre-category!objects}\\index{objects}\n  \\item For every two objects $x,y:A$ a set\n    \\begin{equation*}\n      \\hom(x,y)\n    \\end{equation*}\n    of \\define{morphisms}\\index{pre-category!morphisms}\\index{morphism} from $x$ to $y$.\n  \\item For every object $x:A$ an \\define{identity morphism}\\index{identity morphism}\\index{pre-category!identity morphism}\n    \\begin{equation*}\n      \\idfunc : \\hom(x,x)\n    \\end{equation*}\n  \\item For every two morphisms $f:\\hom(x,y)$ and $g:\\hom(y,z)$, a morphism\n    \\begin{equation*}\n      g\\circ f :\\hom(x,z)\n    \\end{equation*}\n    called the \\define{composition}\\index{composition!of morphisms} of $f$ and $g$.\n  \\item the following terms\n    \\begin{align*}\n      \\leftunit_{\\mathcal{C}} & : \\idfunc \\circ f = f \\\\\n      \\rightunit_{\\mathcal{C}} & : g \\circ \\idfunc = g \\\\\n      \\assoc_{\\mathcal{C}} & : (h \\circ g) \\circ f = h \\circ (g \\circ f)\n    \\end{align*}\n    witnessing that the category laws\\index{category laws}\\index{laws!of a category} are satisfied.\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{eg}\n  Since the type $X\\to Y$ of functions between sets is again a set, we have a pre-category of sets.\\index{pre-category!of sets}\n\\end{eg}\n\n\\begin{eg}\n  By \\cref{rmk:category-semi-group,rmk:category-group} we have pre-categories of semi-groups and of groups.\\index{semi-group!is a pre-category}\\index{pre-category!of semi-groups}\\index{group!is a category}\\index{pre-category!of groups}\n\\end{eg}\n\n\\begin{eg}\n  A pre-category satisfying the condition that every hom-set is a proposition is a \\define{preorder}.\\index{preorder}\\index{pre-category!preorder} \n\\end{eg}\n\n\\begin{defn}\n  Given a pre-category $\\mathcal{C}$, a morphism $f:\\hom(x,y)$ is said to be an \\define{isomorphism}\\index{isomorphism!in a pre-category} if there exists a morphism $g:\\hom(y,x)$ such that\n  \\begin{align*}\n    g \\circ f & = \\idfunc \\\\\n    f \\circ g & = \\idfunc.\n  \\end{align*}\n  We will write $\\iso(x,y)$\\index{iso(x,y)@{$\\iso(x,y)$}} for the type of all isomorphisms in $\\mathcal{C}$ from $x$ to $y$.\n\\end{defn}\n\n\\begin{rmk}\n  Just as in the case for semi-groups and groups, the condition that $f:\\hom(x,y)$ is an isomorphism is a property of $f$.\n\\end{rmk}\n\n\\begin{defn}\n  A pre-category $\\mathcal{C}$ is said to be \\define{Rezk-complete}\\index{Rezk-complete}\\index{pre-category!Rezk complete} if the canonical map\n  \\begin{equation*}\n    (x=y)\\to \\iso(x,y)\n  \\end{equation*}\n  is an equivalence for any two objects $x$ and $y$ of $\\mathcal{C}$. Rezk-complete pre-categories are also called \\define{categories}.\\index{category}\n\\end{defn}\n\n\\begin{eg}\n  The pre-category of sets is Rezk complete by the univalence axiom, so it is a category.\\index{sets!form a category}\\index{category!of sets}\n\\end{eg}\n\n\\begin{eg}\n  The pre-categories of semi-groups and groups are Rezk-complete. Therefore they form categories.\\index{Semi-Group@{$\\semigroup$}!is a category}\\index{Group@{$\\group$}!is a category}\\index{category!of groups}\\index{category!of semi-groups}\n\\end{eg}\n\n\\begin{eg}\n  A pre-order is Rezk-complete if and only if it is anti-symmetric. In other words, a poset is precisely a category for which all the hom-sets are propositions. Thus, we see that the anti-symmetry axiom can be seen as a univalence axiom for pre-orders.\\index{category!poset}\\index{poset!is a category}\n\\end{eg}\n\n\\begin{exercises}\n  \\exercise Let $X$ be a set. Show that the map\\index{equiv-eq@{$\\equiveq$}!is a group isomorphism}\n  \\begin{equation*}\n    \\equiveq : (X=X)\\to (\\eqv{X}{X})\n  \\end{equation*}\n  is a group isomorphism.\n  \\exercise \\label{ex:groupop-embedding}\n  \\begin{subexenum}\n  \\item Consider a group $G$. Show that the function\n    \\begin{equation*}\n      \\mu_G:G\\to (G\\simeq G)\n    \\end{equation*}\n    is an injective group homomorphism.\n  \\item Consider a pointed type $A$. Show that the concatenation function\n    \\begin{equation*}\n      \\concat:\\loopspace{A}\\to (\\loopspace{A}\\simeq\\loopspace{A})\n    \\end{equation*}\n    is an embedding.\\index{concat@{$\\concat$}!is an embedding}\n  \\end{subexenum}\n  \\exercise Let $f:\\hom(G,H)$ be a group homomorphism. Show that $f$ preserves units and inverses, i.e., show that\\index{group homomorphism!preserves units and inverses}\n  \\begin{align*}\n    f(e_G) & = e_H \\\\\n    f(x^{-1}) & = f(x)^{-1}.\n  \\end{align*}\n  \\exercise Give a direct proof and a proof using the univalence axiom of the fact that all semi-group isomorphisms between unital semi-groups preserve the unit. Conclude that isomorphic monoids are equal.\\index{isomorphism!of semi-groups!preserves unit}\n  \\exercise Consider a monoid $M$ with multiplication $\\mu:M\\to (M\\to M)$ and unit $e$. Write\n  \\begin{equation*}\n    \\bar{\\mu}\\defeq\\foldlist(e,\\mu):\\lst(M)\\to M\n  \\end{equation*}\n  for the iterated multiplication operation (see \\cref{ex:lists}). Show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\lst(\\lst(M)) \\arrow[r,\"\\flattenlist(M)\"] \\arrow[d,swap,\"\\lst(\\bar{\\mu})\"] & \\lst(M) \\arrow[d,\"\\bar{\\mu}\"] \\\\\n      \\lst(M) \\arrow[r,swap,\"\\bar{\\mu}\"] & M\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. \n  \\exercise Construct the category of posets.\\index{category!of posets}\n  \\exercise Consider the \\define{walking isomorphism}, i.e., the pre-category $\\mathcal{I}$ given by\n  \\begin{equation*}\n    \\begin{tikzcd}\n      0 \\arrow[r,bend left=15,\"f\"] & 1 \\arrow[l,bend left=15,\"{f^{-1}}\"]\n    \\end{tikzcd}\n  \\end{equation*}\n  satisfying $f\\circ f^{-1}=\\idfunc$ and $f^{-1}\\circ f=\\idfunc$. Show that for any pre-category $\\mathcal{C}$ the following are equivalent:\n  \\begin{enumerate}\n  \\item The pre-category $\\mathcal{C}$ is Rezk complete.\n  \\item The precomposition function\n    \\begin{equation*}\n      \\mathcal{C}\\to\\mathsf{Fun}(\\mathcal{I},\\mathcal{C})\n    \\end{equation*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{exercises}\n", "meta": {"hexsha": "cf0de707bc817a8b627c5d7d93b44d43e163e847", "size": 23405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/groups.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/groups.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/groups.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.2620192308, "max_line_length": 582, "alphanum_fraction": 0.703952147, "num_tokens": 7459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199754937771, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.688682033884874}}
{"text": "\\chapter{Power of filters}\n\n\\section{Germs of functions}\n\n\\begin{defn}\n  Functions $f, g \\in \\mathbf{Rel} (\\Ob \\mathcal{X} , B)$\n  \\emph{are of the same $\\mathcal{X}$-germ} for a filter object\n  $\\mathcal{X}$ iff there exists $X \\in \\up \\mathcal{X}$ such that $f|_X\n  = g|_X$.\n\\end{defn}\n\n\\begin{prop}\n  Being of the same germ is an equivalence relation.\n\\end{prop}\n\n\\begin{proof}\n  ~\n  \\begin{description}\n    \\item[Reflexivity] Take arbitrary $X \\in \\up \\mathcal{X}$.\n    \n    \\item[Symmetry] Obvious.\n    \n    \\item[Transitivity] Let $f|_X = g|_X$ and $g|_Y = h|_Y$. Then $f|_{X \\cap\n    Y} = h|_{X \\cap Y}$.\n  \\end{description}\n\\end{proof}\n\n\\begin{defn}\n  A \\emph{germ} is an equivalence class of being the same germ.\n\\end{defn}\n\n\\begin{obvious}\nEvery germ is a filter on $\\mathbf{Set}$.\n\\end{obvious}\n\n\\begin{thm}\n  Let $A$, $B$ be sets.\n\n  The following are mutually inverse bijections between monovalued reloids $f\n  : A \\rightarrow B$ with $\\dom f = \\mathcal{X}$ and $\\mathcal{X}$-germs\n  $S$ of functions $A \\rightarrow B$ for $\\mathcal{X} \\in \\mathscr{F} A$:\n  \\begin{enumerate}\n    \\item $f \\mapsto \\up^{\\mathbf{Set}} f$;\n    \\item $S \\mapsto s|_{\\mathcal{X}}$ if $s\\in S$.\n  \\end{enumerate}\n  The second bijection can also be written as $S \\mapsto \\left(\\bigsqcap^{\\mathsf{RLD}} S\\right)|_{\\mathcal{X}}$ or\n  if $\\card B\\ne 1$ as $S \\mapsto \\bigsqcap^{\\mathsf{RLD}} S$.\n\\end{thm}\n\n\\begin{rem}\n$s|_{\\mathcal{X}}$ is always defined because $S$ is nonempty (it is an equivalence class).\n\\end{rem}\n\n\\begin{proof}\n  First prove that $\\up^{\\mathbf{Set}} f$ is an\n  $\\mathcal{X}$-germ. Really, $F \\in \\up^{\\mathbf{Set}} f\n  \\Leftrightarrow F \\sqsupseteq f \\Leftrightarrow F|_{\\mathcal{X}} = f\n  \\Leftrightarrow \\exists X \\in \\up \\mathcal{X} : F|_X \\sqsupseteq f$;\n  thus $F, G \\in \\up^{\\mathbf{Set}} f \\Rightarrow \\exists X \\in\n  \\up \\mathcal{X} : F|_X \\sqsupseteq f \\wedge \\exists Y \\in \\up\n  \\mathcal{X} : G|_Y \\sqsupseteq f \\Rightarrow \\exists X \\in \\up\n  \\mathcal{X} : F|_{X \\cap Y} \\sqsupseteq f \\wedge \\exists Y \\in \\up\n  \\mathcal{X} : G|_{X \\cap Y} \\sqsupseteq f \\Rightarrow \\exists Z \\in\n  \\up \\mathcal{X} : (F|_Z \\sqsupseteq f \\wedge G|_Z \\sqsupseteq f)\n  \\Rightarrow \\exists Z \\in \\up \\mathcal{X} : (F \\sqcap G) |_Z\n  \\sqsupseteq f$ and $F \\in \\up^{\\mathbf{Set}} f \\wedge \\exists\n  X \\in \\up \\mathcal{X} : F|_X = G|_X \\Rightarrow F \\sqsupseteq f \\wedge\n  F|_{\\mathcal{X}} = G|_{\\mathcal{X}} \\Rightarrow G|_{\\mathcal{X}} \\sqsupseteq\n  f \\Rightarrow G \\in \\up^{\\mathbf{Set}} f$. We have proved\n  that $\\up^{\\mathbf{Set}} f$ is an equivalence class of the\n  suitable equivalence relation, that is $\\up^{\\mathbf{Set}} f$\n  is an $\\mathcal{X}$-germ.\n  \n  That $\\bigsqcap^{\\mathsf{RLD}} S$ is a monovalued reloid is obvious.\n  Also $\\im \\bigsqcap^{\\mathsf{RLD}} S = \\mathcal{X}$ is obvious.\n\n  Now prove that our correspondences are mutually inverse.\n\n  Let $f_0 : A \\rightarrow B$ be a monovalued reloid and $\\dom f =\n  \\mathcal{X}$. Let $S = \\up^{\\mathbf{Set}} f_0$ and $f_1 =\n  s|_{\\mathcal{X}}$ for an~$s\\in S$. We need to prove $f_1 = f_0$. Really,\n  $f_1 = F|_{\\mathcal{X}}$ for an $F\\in\\up^{\\mathbf{Set}}f_0$; thus $f_1=f_0$.\n  \n  Let $S_0$ be an $\\mathcal{X}$-germ of functions $A \\rightarrow B$. Let $f =\n  s|_{\\mathcal{X}}$ for an~$s\\in S_0$ and $S_1 =\n  \\up^{\\mathbf{Set}} f$. We need to prove $S_1 = S_0$. Really,\n  \\[\n  S_1 = \\up^{\\mathbf{Set}}(s|_{\\mathcal{X}}) =\n  \\setcond{F\\in\\mathbf{Set}}{F\\sqsupseteq s|_{\\mathcal{X}}} =\n  \\setcond{F\\in\\mathbf{Set}}{\\exists X\\in\\up\\mathcal{X}:F|_X\\sqsupseteq s|_X} =\n  \\setcond{F\\in\\mathbf{Set}}{\\exists X\\in\\up\\mathcal{X}:F|_X=s|_X} = S_0.\n  \\]\n  \n  $\\left(\\bigsqcap^{\\mathsf{RLD}} S\\right)|_{\\mathcal{X}} =\n  \\bigsqcap^{\\mathsf{RLD}}_{s\\in S} s|_{\\mathcal{X}} = s|_{\\mathcal{X}}$\n  for every choice of~$s\\in S$.\n\n  We can assume that $B \\neq \\emptyset$ because otherwise the theorem is\n  obvious. Thus we can assume $\\card B>1$.\n\n  If $\\mathcal{X} = X$ then obviously $S$ has just one element $F$ and\n  $\\im \\bigsqcap^{\\mathsf{RLD}} S = \\im F = X =\n  \\mathcal{X}$. Otherwise for every $X \\in \\up \\mathcal{X}$ there are\n  elements $F$, $G$ of $S$ such that $\\dom (F \\sqcap G) \\sqsubseteq X$\n  (using $\\card B > 1$).\n  \n  By properties of generalized filter bases $X \\times \\top \\sqsupseteq\n  \\bigsqcap^{\\mathsf{RLD}} S \\Leftrightarrow \\exists F, G \\in S : X\n  \\times \\top \\sqsupseteq F \\sqcap G \\Leftrightarrow X \\sqsupseteq\n  \\mathcal{X}$. Thus $\\im \\bigsqcap^{\\mathsf{RLD}} S =\n  \\mathcal{X}$.\n\\end{proof}\n\n\\section{Power of filters}\n\nLet's define $\\mathcal{Y}^{\\mathcal{X}}$ for filters~$\\mathcal{X}$,~$\\mathcal{Y}$:\n\nFirst define $Y^{\\mathcal{X}}$ for a set~$Y$:\n\\[ Y^{\\mathcal{X}} = \\setcond{ f \\in \\mathsf{RLD} (\\Ob \\mathcal{X}\n   , Y) }{ \\dom f = \\mathcal{X} \\wedge f\\text{ is monovalued} } . \\]\n\nNow $\\mathcal{Y}^{\\mathcal{X}} = \\bigsqcap^{\\mathsf{RLD}}_{Y \\in\n\\up \\mathcal{Y}} Y^{\\mathcal{X}}$.\n\n\\cite{filt-cat}~defines an isomorphic to this way to define ``exponentiation'' of filters.\n\nTODO: Check $\\mathcal{Y}^1 \\cong \\mathcal{Y}$; $\\mathcal{Z}^{\\mathcal{X}\n\\times^{\\mathsf{RLD}} \\mathcal{Y}} \\cong\n(\\mathcal{Z}^{\\mathcal{X}})^{\\mathcal{Y}}$; $\\mathcal{Z}^{\\mathcal{X} \\amalg\n\\mathcal{Y}} \\cong \\mathcal{Z}^{\\mathcal{X}} \\times^{\\mathsf{RLD}}\n\\mathcal{Z}^{\\mathcal{Y}}$; $\\mathcal{Y}^2 \\cong \\mathcal{Y}\\times^{\\mathsf{RLD}}\\mathcal{Y}$;\n$\\mathcal{Y}^0 \\cong 1$; $\\mathcal{Y}^N \\cong \\prod^{\\mathsf{RLD}}_{n\\in N}\\mathcal{Y}$.\nMore formulas at \\url{https://en.wikipedia.org/wiki/Cartesian_closed_category}.\n\nAndreas Blass says in a private email that it is not cartesian closed: ``Unfortunately, the two categories of filters in my paper are\nnot cartesian closed.  This is mentioned in a parenthetical comment\nnear the bottom of page 141.  The operation of cartesian product with\nthe cofinite filter on the natural numbers has no right adjoint,\nbecause it does not preserve infinite coproducts.''\nabout~\\cite{filt-cat}.\n\nBut it is probably a braided closed monoidal category?\n\nSee \\cite{filt-cat} for more categorical properties of filters.", "meta": {"hexsha": "c89ec0dbadd5b868112a41d503d4e0898aaf3786", "size": 6015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-filt-power.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-filt-power.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-filt-power.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": 41.7708333333, "max_line_length": 133, "alphanum_fraction": 0.6485453034, "num_tokens": 2417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199471193039, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.6886820178545865}}
{"text": "\\section{Diagonalization of symmetric matrices}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute the real eigenvalues of a symmetric matrix.\n  \\item Compute an orthogonal basis of eigenvectors for a symmetric\n    matrix.\n  \\item Orthogonally diagonalize a symmetric matrix. \n  \\end{enumerate}\n\\end{outcome}\n\nIn Chapter~\\ref{cha:eigenvalues}, we saw that some matrices are\ndiagonalizable, and others are not. In this section, we will see that\nthe theory of diagonalization is much nicer when the matrix to be\ndiagonalized is symmetric. Recall that a matrix $A$ is\n\\textbf{symmetric}%\n\\index{symmetric matrix}%\n\\index{matrix!symmetric} if $A=A^T$. We begin with some observations\nabout the eigenvalues and eigenvectors of a symmetric matrix.\n\n\\begin{proposition}{Eigenvalues and eigenvectors of symmetric matrices}{eigenvalues-symmetric}\n  Let $A$ be a symmetric matrix with real entries. Then\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item All eigenvalues of $A$ are real (i.e., not complex).\n    \\item Eigenvectors for distinct eigenvalues of $A$ are orthogonal.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n\n\\begin{proof}\n  (a) Suppose $\\eigenvar$ is a (possibly complex) eigenvalue of $A$,\n  with (possibly complex) eigenvector $\\vect{v}$. We will show that\n  $\\eigenvar$ is in fact real. Let $\\conjugate{\\eigenvar}$ be the\n  complex conjugate of $\\eigenvar$, and let $\\conjugate{\\vect{v}}$ be\n  the complex conjugate of $\\vect{v}$, i.e., the vector obtained from\n  $\\vect{v}$ by taking the complex conjugate of each of its entries.\n  Since $\\vect{v}$ is an eigenvector for eigenvalue $\\eigenvar$ of\n  $A$, we have\n  \\begin{equation}\\label{eqn:eigenvalues-symmetric-1}\n    \\conjugate{\\vect{v}}^T A\\vect{v}\n    = \\eigenvar \\conjugate{\\vect{v}}^T\\vect{v}.\n  \\end{equation}\n  Taking the complex conjugate of both sides of the equation, and\n  using the fact that $\\conjugate{A}=A$ (since $A$ is\n  real), we get\n  \\begin{equation}\n    \\vect{v}^T A\\conjugate{\\vect{v}}\n    = \\conjugate{\\eigenvar} \\vect{v}^T\\conjugate{\\vect{v}}.\n  \\end{equation}\n  Then, taking the transpose of both sides of the equation, and using\n  the fact that $A^T=A$ (since $A$ is symmetric), we have\n  \\begin{equation}\\label{eqn:eigenvalues-symmetric-2}\n    \\conjugate{\\vect{v}}^T A\\vect{v}\n    = \\conjugate{\\eigenvar} \\conjugate{\\vect{v}}^T\\vect{v}.\n  \\end{equation}\n  Comparing equations {\\eqref{eqn:eigenvalues-symmetric-1}} and\n  {\\eqref{eqn:eigenvalues-symmetric-2}}, we find that\n  $\\eigenvar \\conjugate{\\vect{v}}^T\\vect{v} = \\conjugate{\\eigenvar}\n  \\conjugate{\\vect{v}}^T\\vect{v}$. Since\n  $\\conjugate{\\vect{v}}^T\\vect{v}$ is a non-zero scalar, it follows\n  that $\\eigenvar = \\conjugate{\\eigenvar}$, i.e., $\\eigenvar$ is real.\n\n  \\noindent\n  (b) Suppose $\\vect{v}$ is an eigenvector for eigenvalue\n  $\\eigenvarA$, $\\vect{w}$ is an eigenvector for eigenvalue\n  $\\eigenvarB$, and $\\eigenvarA\\neq\\eigenvarB$.  We evaluate\n  $\\vect{v}^TA\\vect{w}$ in two different ways. On the on hand, we have\n  \\begin{equation*}\n    \\vect{v}^TA\\vect{w}\n    = \\vect{v}^T(A\\vect{w})\n    = \\vect{v}^T(\\eigenvarB\\vect{w})\n    = \\eigenvarB \\vect{v}^T\\vect{w}.\n  \\end{equation*}\n  On the other hand, we have\n  \\begin{equation*}\n    \\vect{v}^TA\\vect{w}\n    = (\\vect{v}^TA)\\vect{w}\n    = (A^T\\vect{v})^T\\vect{w}\n    = (A\\vect{v})^T\\vect{w}\n    = (\\eigenvarA\\vect{v})^T\\vect{w}\n    = \\eigenvarA\\vect{v}^T\\vect{w}.\n  \\end{equation*}\n  Therefore,\n  $\\eigenvarB\\vect{v}^T\\vect{w} = \\eigenvarA\\vect{v}^T\\vect{w}$, or\n  equivalently $(\\eigenvarA - \\eigenvarB)\\vect{v}^T\\vect{w} =\n  0$. Since by assumption, $\\eigenvarA - \\eigenvarB\\neq 0$, we must\n  have $\\vect{v}^T\\vect{w} = 0$, i.e., $\\vect{v}\\orth\\vect{w}$.\n\\end{proof}\n\nRecall that an $n\\times n$-matrix $A$ is \\textbf{diagonalizable}%\n\\index{diagonalizable matrix}%\n\\index{matrix!diagonalizable} if there exists an invertible matrix $P$\nand a diagonal matrix $D$ such that $D = P^{-1}AP$. We say that $A$ is\n\\textbf{orthogonally diagonalizable}%\n\\index{orthogonally diagonalizable matrix}%\n\\index{diagonalizable matrix!orthogonally diagonalizable}%\n\\index{diagonalization!orthogonal diagonalization}%\n\\index{matrix!orthogonally diagonalizable}%\n\\index{matrix!diagonalizable!orthogonally} if $P$ can, moreover, be\nchosen to be orthogonal. Orthogonal diagonalizability is a convenient\nproperty, because when $P$ is orthogonal, then $P^{-1}=P^T$, and we\ncan interchangeably write $D = P^{-1}AP$ or $D = P^TAP$.  The\nfollowing is the main theorem about the diagonalization of real\nsymmetric matrices.\n\n\\begin{theorem}{Diagonalization of symmetric matrices}{diagonalization-symmetric}\n  Every real symmetric matrix $A$ is orthogonally diagonalizable.\n\\end{theorem}\n\n\\begin{proof}\n  By induction on the size of the matrix. For a $1\\times 1$-matrix,\n  there is nothing to show, as it is already diagonal. Now consider a\n  real symmetric $n\\times n$-matrix $A$ with $n\\geq 2$. By the\n  fundamental theorem of algebra, the characteristic polynomial has at\n  least one root, so that $A$ has at least one (possibly complex)\n  eigenvalue $\\eigenvar$. By Proposition~\\ref{prop:eigenvalues-symmetric}(a),\n  $\\eigenvar$ is real. Since we can solve the system of equations\n  $(A-\\eigenvar I)\\vect{v}=\\vect{0}$ over the real numbers, there\n  exists a real eigenvector $\\vect{v}$ for the eigenvalue\n  $\\eigenvar$. We can assume without loss of generality that\n  $\\vect{v}$ is normalized, because else we could replace $\\vect{v}$\n  by $\\frac{1}{\\norm{\\vect{v}}}\\vect{v}$. By the Gram-Schmidt method,\n  we can find an orthonormal basis\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ of $\\R^n$ such that\n  $\\vect{u}_1=\\vect{v}$. Let $Q$ be the orthogonal matrix that has\n  $\\vect{u}_1,\\ldots,\\vect{u}_n$ as its columns, and consider\n  $B=Q^{-1}AQ$. Since\n  $B\\vect{e}_1 = Q^{-1}AQ\\vect{e}_1 = Q^{-1}A\\vect{u}_1 = \\eigenvar\n  Q^{-1}\\vect{u}_1 = \\eigenvar\\vect{e}_1$, the matrix $B$ is of the\n  form\n  \\begin{equation*}\n    B = \\begin{mymatrix}{cccc}\n      \\eigenvar & b_{12} & \\cdots & b_{1n} \\\\\n      0 & b_{22} & \\cdots & b_{2n} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      0 & b_{n2} & \\cdots & b_{nn} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Moreover, since $B=Q^{-1}AQ = Q^TAQ$, the matrix $B$ is symmetric.\n  Therefore $b_{12},\\ldots,b_{1n} = 0$, and $B$ is of the form\n  \\begin{equation*}\n    B = \\begin{mymatrix}{c|ccc}\n      \\eigenvar & 0 & \\cdots & 0 \\\\\\hline\n      0 &  & & \\\\\n      \\vdots & & C & \\\\\n      0 &  & & \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  where $C$ is a symmetric matrix of dimension $n-1$. By induction\n  hypothesis, $C$ is orthogonally diagonalizable, i.e., there exists\n  an orthogonal matrix $R$ such that $R^{-1}CR=D$ is diagonal. Let\n  \\begin{equation*}\n    S = \\begin{mymatrix}{c|ccc}\n      1 & 0 & \\cdots & 0 \\\\\\hline\n      0 &  & & \\\\\n      \\vdots & & R & \\\\\n      0 &  & & \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then $S$ is orthogonal by\n  Proposition~\\ref{prop:properties-orthogonal}(\\ref{item:properties-orthogonal-d}).\n  Let $E = S^{-1}BS$. Then\n  \\begin{equation*}\n    E =\n    S^{-1}BS =\n    \\begin{mymatrix}{c|ccc}\n      \\eigenvar & 0 & \\cdots & 0 \\\\\\hline\n      0 &  & & \\\\\n      \\vdots & & R^{-1}CR & \\\\\n      0 &  & & \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{c|ccc}\n      \\eigenvar & 0 & \\cdots & 0 \\\\\\hline\n      0 &  & & \\\\\n      \\vdots & & D & \\\\\n      0 &  & & \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, $E$ is diagonal. Let $P=QS$. Then $P$ is orthogonal\n  by\n  Proposition~\\ref{prop:properties-orthogonal}(\\ref{item:properties-orthogonal-a}). Moreover,\n  we have\n  \\begin{equation*}\n    P^{-1}AP = S^{-1}Q^{-1}AQS = S^{-1}BS = E.\n  \\end{equation*}\n  Therefore, $A$ is orthogonally diagonalizable.\n\\end{proof}\n\n\\begin{example}{Diagonalization of symmetric matrices}{diagonalization-symmetric}\n  Orthogonally diagonalize the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      3 & 2 \\\\\n      2 & 6 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  i.e., find an orthogonal matrix $P$ and a diagonal matrix $D$ such\n  that $D = P^{-1}AP$.\n\\end{example}\n\n\\begin{solution}\n  We proceed in much the same way as in Chapter~\\ref{cha:eigenvalues},\n  except that at a crucial moment, we ensure that $P$ is orthogonal.\n  We start by calculating the characteristic polynomial of $A$:\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\n    ~=~ \\begin{absmatrix}{cc}\n      3-\\eigenvar & 2 \\\\\n      2 & 6-\\eigenvar\n    \\end{absmatrix}\n    ~=~ (3-\\eigenvar)(6-\\eigenvar) - 4\n    ~=~ \\eigenvar^2 - 9\\eigenvar + 14.\n  \\end{equation*}\n  We find the roots using the quadratic formula. The roots of the\n  characteristic polynomial, and therefore the eigenvalues of $A$, are\n  $\\eigenvar=7$ and $\\eigenvar=2$. For the eigenvalue $\\eigenvar=7$,\n  we find the eigenvector\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{r} 1 \\\\ 2 \\end{mymatrix},\n  \\end{equation*}\n  and for the eigenvalue $\\eigenvar=2$, we find the eigenvector\n  \\begin{equation*}\n    \\vect{w} = \\begin{mymatrix}{r} -2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  We note that these two eigenvectors are orthogonal to each other,\n  exactly as predicted by Proposition~\\ref{prop:eigenvalues-symmetric}. So\n  the vectors $\\set{\\vect{v},\\vect{w}}$ form an orthogonal set. We\n  turn this into an orthonormal set by normalizing each eigenvector,\n  i.e., the normalized eigenvectors are\n  \\begin{equation*}\n    \\vect{u}_1\n    ~=~ \\frac{1}{\\norm{\\vect{v}}}\\vect{v}\n    ~=~ \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{r} 1 \\\\ 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2\n    ~=~ \\frac{1}{\\norm{\\vect{w}}}\\vect{w}\n    ~=~ \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{r} -2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  We let $P$ be the matrix that has columns $\\vect{u}_1$ and\n  $\\vect{u}_2$, i.e.,\n  \\begin{equation*}\n    P = \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{rr} 1 & -2 \\\\ 2 & 1 \\end{mymatrix}.\n  \\end{equation*}\n  Note that since $\\vect{u}_1$ and $\\vect{u}_2$ are orthonormal, $P$\n  is automatically orthogonal by\n  Proposition~\\ref{prop:conditions-orthogonal-matrix}. Moreover, we\n  have\n  \\begin{equation*}\n    P^{-1}\n    ~=~ P^T\n    ~=~ \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{rr} 1 & 2 \\\\ -2 & 1 \\end{mymatrix}.\n  \\end{equation*}\n  Finally,\n  \\begin{equation*}\n    P^{-1}AP\n    ~=~ P^TAP\n    ~=~ \\frac{1}{5}\n    \\begin{mymatrix}{rr} 1 & 2 \\\\ -2 & 1 \\end{mymatrix}\n    \\begin{mymatrix}{rr} 3 & 2 \\\\ 2 & 6 \\end{mymatrix}\n    \\begin{mymatrix}{rr} 1 & -2 \\\\ 2 & 1 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{rr} 7 & 0 \\\\ 0 & 2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Diagonalization of symmetric matrices}{diagonalization-symmetric2}\n  Find an orthogonal matrix $P$ and a diagonal matrix $D$ such $D =\n  P^{-1}AP$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      3  & 1 & -2 \\\\\n      1  & 3 &  2 \\\\\n      -2 & 2 &  0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Again, we start by calculating the characteristic polynomial and its roots:\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\n    ~=~ \\begin{absmatrix}{ccc}\n      3-\\eigenvar  & 1 & -2 \\\\\n      1  & 3-\\eigenvar &  2 \\\\\n      -2 & 2 &  -\\eigenvar  \\\\\n    \\end{absmatrix}\n    ~=~ - \\eigenvar^3 + 6\\eigenvar^2 -32.\n  \\end{equation*}\n  The roots are $\\eigenvar=4$ and $\\eigenvar=-2$. To find the\n  eigenvectors for $\\eigenvar=4$, we solve the system of equations\n  \\begin{equation*}\n    (A-4I)\\vect{v}\n    =\n    \\begin{mymatrix}{rrr}\n      -1  & 1 & -2 \\\\\n      1  & -1 &  2 \\\\\n      -2 & 2 &  -4 \\\\\n    \\end{mymatrix}\\vect{v}\n    = \\vect{0}.\n  \\end{equation*}\n  The solution space is 2-dimensional, with basis\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} 0 \\\\ 2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  To find the eigenvectors for $\\eigenvar=-2$, we solve the system of\n  equations\n  \\begin{equation*}\n    (A+2I)\\vect{v}\n    =\n    \\begin{mymatrix}{rrr}\n      5  & 1 & -2 \\\\\n      1  & 5 &  2 \\\\\n      -2 & 2 &  2 \\\\\n    \\end{mymatrix}\\vect{v}\n    = \\vect{0}.\n  \\end{equation*}\n  The solution space is 1-dimensional, with basis\n  \\begin{equation*}\n    \\vect{v}_3 = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  As predicted by Proposition~\\ref{prop:eigenvalues-symmetric},\n  $\\vect{v}_3$ is orthogonal to $\\vect{v}_1$ and\n  $\\vect{v}_2$. However, there is a slight complication: $\\vect{v}_1$\n  and $\\vect{v}_2$ are not orthogonal to each other. This is because\n  they are eigenvectors for the {\\em same} eigenvalue ($\\eigenvar=4$),\n  not for {\\em distinct} eigenvalues. We found basis\n  $\\set{\\vect{v}_1,\\vect{v}_2}$ for the eigenspace for $\\eigenvar=4$,\n  but it doesn't happen to be an orthogonal basis. However, we can fix\n  this by applying the Gram-Schmidt method to\n  $\\set{\\vect{v}_1,\\vect{v}_2}$. This yields the orthogonal basis\n  $\\set{\\vect{u}_1,\\vect{u}_2}$ for the eigenspace for $\\eigenvar=4$,\n  where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  We now have an orthogonal basis\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{v}_3}$ of eigenvectors of the\n  matrix $A$. We normalize the three vectors and use them as the\n  columns of $P$:\n  \\begin{equation*}\n    \\def\\arraystretch{1.4}\n    P = \\begin{mymatrix}{ccc}\n      \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{3}} & \\frac{1}{\\sqrt{6}}  \\\\\n      \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{3}}  & -\\frac{1}{\\sqrt{6}} \\\\\n      0                  & \\frac{1}{\\sqrt{3}}  & \\frac{2}{\\sqrt{6}}  \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  It seems that inverting $P$ will not be all that easy, but in fact,\n  since $P$ is orthogonal, the inverse is just the transpose:\n  \\begin{equation*}\n    \\def\\arraystretch{1.4}\n    P^{-1}\n    ~=~ P^T\n    ~=~ \\begin{mymatrix}{ccc}\n      \\frac{1}{\\sqrt{2}}  & \\frac{1}{\\sqrt{2}}  & 0 \\\\\n      -\\frac{1}{\\sqrt{3}} & \\frac{1}{\\sqrt{3}}  & \\frac{1}{\\sqrt{3}} \\\\\n      \\frac{1}{\\sqrt{6}}  & -\\frac{1}{\\sqrt{6}} & \\frac{2}{\\sqrt{6}} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  We have\n  \\begin{equation*}\n    P^{-1}AP\n    ~=~ D\n    ~=~ \\begin{mymatrix}{ccc} 4 & 0 & 0 \\\\ 0 & 4 & 0 \\\\ 0 & 0 & -2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "f80db2e193c71a51dc4e0a429e845a48ad3a53de", "size": 14225, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Diagonalization.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Diagonalization.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Diagonalization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.2392473118, "max_line_length": 94, "alphanum_fraction": 0.6336731107, "num_tokens": 5279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.9019206798249232, "lm_q1q2_score": 0.6886018047677187}}
{"text": "\\subsubsection{Na\\\"{i}ve Methods, Moving Averages, and Exponential Smoothing}\n\\label{ets}\n\nSimple forecasting methods are often employed as a benchmark for more\n    sophisticated ones.\nThe so-called na\\\"{i}ve and seasonal na\\\"{i}ve methods forecast the next time\n    step in a time series, $y_{T+1}$, with the last observation, $y_T$,\n    and, if a seasonal pattern is present, with the observation $k$ steps\n    before, $y_{T+1-k}$.\nAs variants, both methods can be generalized to include drift terms in the\n    presence of a trend or changing seasonal amplitude.\n\nIf a time series exhibits no trend, a simple moving average (SMA) is a\n    generalization of the na\\\"{i}ve method that is more robust to outliers.\nIt is defined as follows: $\\hat{y}_{T+1} = \\frac{1}{h} \\sum_{i=T-h}^{T} y_i$\n    where $h$ is the horizon over which the average is calculated.\nIf a time series exhibits a seasonal pattern, setting $h$ to a multiple of the\n    periodicity $k$ suffices that the forecast is unbiased.\n\nStarting in the 1950s, another popular family of forecasting methods,\n    so-called exponential smoothing methods, was introduced by\n    \\cite{brown1959}, \\cite{holt1957}, and \\cite{winters1960}.\nThe idea is that forecasts $\\hat{y}_{T+1}$ are a weighted average of past\n    observations where the weights decay over time; in the case of the simple\n    exponential smoothing (SES) method we obtain:\n$\n\\hat{y}_{T+1} = \\alpha y_T + \\alpha (1 - \\alpha) y_{T-1}\n                + \\alpha (1 - \\alpha)^2 y_{T-2}\n                + \\dots + \\alpha (1 - \\alpha)^{T-1} y_{1}\n$\nwhere $\\alpha$ (with $0 \\le \\alpha \\le 1$) is a smoothing parameter.\n\nExponential smoothing methods are often expressed in an alternative component\n    form that consists of a forecast equation and one or more smoothing\n    equations for unobservable components.\nBelow, we present a generalization of SES, the so-called Holt-Winters'\n    seasonal method, in an additive formulation.\n$\\ell_t$, $b_t$, and $s_t$ represent the unobservable level, trend, and\n    seasonal components inherent in $y_t$, and $\\beta$ and $\\gamma$ complement\n    $\\alpha$ as smoothing parameters:\n\\begin{align*}\n\\hat{y}_{t+1} & = \\ell_t + b_t + s_{t+1-k} \\\\\n\\ell_t        & = \\alpha(y_t - s_{t-k}) + (1 - \\alpha)(\\ell_{t-1} + b_{t-1}) \\\\\nb_t           & = \\beta (\\ell_{t} - \\ell_{t-1}) + (1 - \\beta) b_{t-1} \\\\\ns_t           & = \\gamma (y_t - \\ell_{t-1} - b_{t-1}) + (1-\\gamma)s_{t-k}\n\\end{align*}\nWith $b_t$, $s_t$, $\\beta$, and $\\gamma$ removed, this formulation reduces to\n    SES.\nDistinct variations exist: Besides the three components, \\cite{gardner1985}\n    add dampening for the trend, \\cite{pegels1969} provides multiplicative\n    formulations, and \\cite{taylor2003} adds dampening to the latter.\nThe accuracy measure commonly employed is the sum of squared errors between\n    the observations and their forecasts.\n\nOriginally introduced by \\cite{assimakopoulos2000}, \\cite{hyndman2003} show\n    how the Theta method can be regarded as an equivalent to SES with a drift\n    term.\nWe mention this method here only because \\cite{bell2018} emphasize that it\n    performs well at Uber.\nHowever, in our empirical study, we find that this is not true in general.\n\n\\cite{hyndman2002} introduce statistical processes, so-called innovations\t\n    state-space models, to generalize the methods in this sub-section.\nThey call this family of models ETS as they capture error, trend, and seasonal\n    terms.\nLinear and additive ETS models have a structure like so:\n\\begin{align*}\ny_t       & = \\vec{w} \\cdot \\vec{x}_{t-1} + \\epsilon_t \\\\\n\\vec{x_t} & = \\mat{F} \\vec{x}_{t-1} + \\vec{g} \\epsilon_t\n\\end{align*}\n$y_t$ denote the observations as before while $\\vec{x}_t$ is a state vector of\n    unobserved components.\n$\\epsilon_t$ is a white noise series and the matrix $\\mat{F}$ and the vectors\n    $\\vec{g}$ and $\\vec{w}$ contain a model's coefficients.\nJust as the models in the next sub-section, ETS models are commonly fitted\n    with maximum likelihood and evaluated using information theoretical\n    criteria against historical data.\nWe refer to \\cite{hyndman2008b} for a thorough summary.\n", "meta": {"hexsha": "53537dac5e03302b33b99aae1ed981b3a4257a01", "size": 4125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/2_class/2_ets.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/2_ets.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/2_ets.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": 52.2151898734, "max_line_length": 79, "alphanum_fraction": 0.7071515152, "num_tokens": 1149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6886018014235314}}
{"text": "% Chapter 2\n\\chapter{Traditional \\gls{RGBD} Cameras Calibration} % Main chapter title\n\\label{chapterTraditionalCalibration} % For referencing the chapter elsewhere, use \\ref{sens_introduction} \n%\\indent\nA pinhole-camera model can be used to describe an image sensor's field of view. When applying the pinhole camera model in world space, it explains the mapping relationship from world space to camera space, and then to image space. A $3\\times4$ pinhole-camera matrix expresses the mappings mathematically. It consists of an intrinsic matrix mapping from the \\gls{3D} camera space to 2D image space, and an extrinsic matrix map from \\gls{3D} world space to \\gls{3D} camera space. Traditionally, lens distortions correction is after, and separated from the pinhole-camera model calibration. In this chapter, we will introduce the camera calibration methods based on the pinhole-camera model in detail, and then discuss how to remove the lens distortions in traditional methods.\n%\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[width=0.45\\textwidth]{PinholeCameraFigure}\n\\caption{The Pinhole Camera Inspection}\n\\label{PinholeCameraFigure}\n\\end{figure}%\n%%\n\\section{Pinhole Camera}\n\\label{sectionPinholeCamera}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%                                                                                                   %%%%%%%%%%\n%%%%%%%%%%      1. Intrinsic, introduce camera model from \\gls{3D} to 2D:         %%%%%%%%%%%\n%%%%%%%%%%                 (X^c, Y^c, Z^c) --> \\(r, \\, c\\)                                          %%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\indent\nA pinhole camera is a simple optical imaging device in the shape of a closed box or chamber. A pinhole camera is completely dark on all the other sides of the box including the side where the pin-hole is created. Figure~\\ref{PinholeCameraFigure} shows an inspection of a pinhole camera. In its front is a pin-hole that help create an image of the outside space on the back side of the box. When the shutter is opened, the light shines through the pin-hole and imprint an image onto a sensor (or photographic paper, or film) placed at the back side of the box. In order to analyze parameters like focal distance, field of view, etc., pinhole camera has its own three dimensional space (noted as \\(\\gls{cameraX}\\), \\(\\gls{cameraY}\\), and \\(\\gls{cameraZ}\\)). Note that, according to Cartesian Coordinates \\enquote{right hand} principle, the camera is looking down the negative of \\(\\gls{cameraZ}\\)-axis, given \\(\\gls{cameraX}\\)\\(\\gls{cameraY}\\) directions as shown in the figure. Its focal length of the pinhole camera is the distance on the \\(Z^c\\)-axis, between the pinhole at the front of the camera and the paper or film at the back of the camera.\n\\\\\\indent\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{PinHoleVirtualFocalPlane}\n\\caption{Virtual Focal Plane of a Pinhole Camera}\n\\label{PinHoleVirtualFocalPlane}\n\\end{figure}%\n%\n%\nPinhole cameras are characterized by the fact that they do not have a lens. It rely on the fact that light travels in straight lines, which is a principle called the rectilinear theory of light. This makes the image appear upside down in the camera, as shown in Fig.~\\ref{PinHoleVirtualFocalPlane}. Tracing the corners of the camera sensor through the pin hole, those dark green lines show the limits of the field of view in \\gls{3D} coordinate space. The back side plane of the pinhole camera, which is behind the origin at a positive \\(\\gls{cameraZ}\\)-axis and also where our sensor sits, is also called the focal plane. It is not intuitive, nor convenient for mathematical analysis that the images on the focal plane are always upside down. So a virtual focal plane is defined in front of the pinhole on the negative \\(\\gls{cameraZ}\\)-axis, which is equal distant from the focal point (pin hole) as the actual focal plane is behind. Notice that the limits of the field of view intersect with the virtual focal plane at the four corners of the up-right image just as they disseminate from the four corners of the sensor at the real focal plane.\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.65\\textwidth]{CommonPinholeCameraModel}\n\\caption{Common Pinhole Camera Model for a $240\\times320$ Pixels Camera Sensor}\n\\label{CommonPinholeCameraModel}\n\\end{figure}%\n%\n\nWith the virtual focal plane, the camera body with the real focal plane could be removed. And the rest parts in front of the the camera body, the focal point and the virtual focal plane together, form the most common pinhole camera model. In order to employ this model to analyze arbitrary \\gls{3D} object points inside the camera's field of view in 2D image space, the prior step is to define the relationship between points in \\gls{3D} camera space and the 2D image space (\\(\\gls{imageRow}\\) and \\(\\gls{imageColumn}\\)). As shown in Fig.~\\ref{CommonPinholeCameraModel}, The focal point is right at the origin of the camera \\gls{3D} space coordinates, from where to the sensor is the vertical distance of \\(f\\), the focal distance. The 2D image coordinates are in dark green, and its origin is sitting at the up-left corner of the sensor. Only the a virtual sensor (in color red) is visible on the virtual focal plane, whose size in 2D image space is noted as 240 by 320 (using the size of PrimeSense camera). As long as both of the camera \\gls{3D} space coordinates and image 2D space coordinates are defined, the next job is to build a mapping between them.\n%\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.82\\textwidth]{RelationshipCameraToImage}\n\\caption{Mapping from Camera Space to Image Space}\n\\label{RelationshipCameraToImage}\n\\end{figure}%\n%\n\nSelect a random object point \\(P^C\\) in the camera space located at camera \\gls{3D} coordinates (\\(\\gls{cameraPointX0}\\), \\(\\gls{cameraPointY0}\\), \\(\\gls{cameraPointZ0}\\)). A line passing both of the point \\(P^C\\) and the \\emph{Focal Point} intersects with the virtual focal plane at \\(P^I\\), with its image 2D coordinates (\\(r, \\, c\\)). To determine the mapping function, we can start a the proportional relationship. As shown in Fig.~\\ref{RelationshipCameraToImage}, the center point in the image coordinates, which is usually called \\emph{\\gls{principlePoint}}, could be determined by column of half-width (\\(c_h\\)) and row of half-height (\\(r_h\\)). Concretely, the \\gls{principlePoint} (\\(r_h\\), \\(c_h\\)) is either (119.5, 159.5) if range is ([0:239], [0:319]), or (120, 320) if range is ([1:240], [1:320]). So, we could get the relative row and column distance of  \\(r_r\\) and \\(c_r\\) by:\n%\n\\begin{equation}\n\\begin{aligned}\nr_r &= r - r_h%\n\\\\%\nc_r &= c - c_h \\ \\ \\ .%\n\\end{aligned}\n\\label{relativeCRforProportional}\n\\end{equation}%\n%\nBased on by triangulation, it is straight forward to tell the proportional relationship between \\(f\\)/\\(\\gls{cameraPointZ0}\\) and \\(c_r\\)/\\(\\gls{cameraPointX0}\\), \\(r_r\\)/\\(\\gls{cameraPointY0}\\). Thus we get\n%\n\\begin{equation}\n\\left[ \\begin{array}{c} c_r \\\\ r_r \\end{array} \\right] %\n= f %\n\\left[ \\begin{array}{c} \\gls{cameraPointX0}/\\gls{cameraPointZ0} \\\\ \\gls{cameraPointY0}/\\gls{cameraPointZ0} \\end{array} \\right]  .%\n\\label{twoDRelativeFromCamToIm}\n\\end{equation}\n\\noindent\nAnd by changing the relative distance \\(r_r / c_r\\) back to the 2D image coordinates \\(r, \\, c\\), then eqn.~(\\ref{twoDRelativeFromCamToIm}) will be written as\n%\n\\begin{equation}\n\\left[ \\begin{array}{c} c \\\\ r \\end{array} \\right] %\n= f %\n\\left[ \\begin{array}{c} \\gls{cameraPointX0}/\\gls{cameraPointZ0} \\\\ \\gls{cameraPointY0}/\\gls{cameraPointZ0} \\end{array} \\right]%\n+\n\\left[ \\begin{array}{c}  c_h \\\\  r_h \\end{array} \\right] .%\n\\label{linearRelationFromCamToIm}\n\\end{equation}\n\\noindent\nIf written in homogeneous coordinates, we will get eqn.~(\\ref{HomoProportionalRelationFromCamToIm}):\n\\begin{equation}\n%\n\\gls{cameraPointZ0} \\left[ \\begin{array}{c} c \\\\ r \\\\ 1 \\end{array} \\right] %\n= %\n\\left[ \\begin{array}{c} fx^c \\\\ fy^c \\\\ \\gls{cameraPointZ0} \\end{array} \\right]%\n+\n\\left[ \\begin{array}{c}  \\gls{cameraPointZ0}c_h \\\\  \\gls{cameraPointZ0}r_h \\\\ 0\\end{array} \\right] %\n=  \\begin{bmatrix} f & 0 &  c_h  \\\\ 0 & f & r_h \\\\ 0 & 0 & 1 \\end{bmatrix}%\n\\left[ \\begin{array}{c} \\gls{cameraPointX0} \\\\ \\gls{cameraPointY0} \\\\ \\gls{cameraPointZ0} \\end{array} \\right] .%\n\\label{HomoProportionalRelationFromCamToIm}\n\\end{equation}%\n%\n\\\\\\indent\nTill Now, we haven't consider the units translation between the camera \\gls{3D} space the image 2D space. The random object point \\(P^C\\)'s mapping point \\(P^I\\) (\\(r, \\, c\\)) on the image space is expressed in millimeters (or inches). Since it is necessary to express the image space coordinates (\\(r, \\, c\\)) in pixels, we need to find out the resolution of the sensor in pixels/millimeter. Considering that, the pixels are not necessarily be square-shaped, we assume they are rectangle-shaped with resolution  $\\alpha_c$ and \\(\\alpha_r\\) pixels/millimeter in the \\(\\gls{imageColumn}\\) and \\(\\gls{imageRow}\\) direction respectively. Therefore, to express \\(P^I\\) in pixels, its \\(c\\) and \\(r\\) coordinates should be multiplied by \\(\\alpha_c\\) and \\(\\alpha_r\\) respectively, to get:\n%\n\\begin{equation}\n\\left[ \\begin{array}{c} \\gls{cameraPointZ0} c \\\\ \\gls{cameraPointZ0} r \\\\ \\gls{cameraPointZ0}  \\end{array} \\right] %\n= %\n\\left[ \\begin{array}{c} f\\alpha_c x^c \\\\ f \\alpha_r y^c \\\\ \\gls{cameraPointZ0} \\end{array} \\right]%\n+\n\\left[ \\begin{array}{c}  \\gls{cameraPointZ0} \\alpha_c c_h \\\\ \\gls{cameraPointZ0} \\alpha_r r_h \\\\ 0 \\end{array} \\right] %\n=  \\begin{bmatrix} \\alpha_c f & 0 &  \\alpha_c c_h  \\\\ 0 & \\alpha_r f & \\alpha_r r_h \\\\ 0 & 0 & 1 \\end{bmatrix}%\n\\left[ \\begin{array}{c} \\gls{cameraPointX0} \\\\ \\gls{cameraPointY0} \\\\ \\gls{cameraPointZ0} \\end{array} \\right]%\n= \\gls{intrinsicMatrixK} \\textbf{\\textit{P}}^C  .\n\\label{HomoProportionalFromCamToImInPixels}\n\\end{equation}%\n\n\\noindent\nNote that \\(\\gls{intrinsicMatrixK}\\) only depends on the intrinsic camera parameters like its focal length, resolution in pixels, and sensor's width and height. Thus, the mapping matrix \\(\\gls{intrinsicMatrixK}\\) is also called a camera's intrinsic matrix. Considering that the pixels might be parallelogram-shaped instead of rigid rectangle-shaped (when the image coordinate axis \\(\\gls{imageRow}\\) and \\(\\gls{imageColumn}\\) are not orthogonal to each other), usually \\(\\gls{intrinsicMatrixK}\\) has a skew parameter \\(s\\), given by\n\n\\begin{equation}\n\\gls{intrinsicMatrixK}%\n=  \\begin{bmatrix} \nf_c & s & t_c \\\\\n 0 & f_r & t_r \\\\\n 0 & 0 & 1 \\end{bmatrix} ,%\n\\label{intrinsicKmatrix}\n\\end{equation}%\n\\noindent\nwhere \\(f_c = \\alpha_c f\\) and \\(f_r = \\alpha_r f\\) are the focal length in pixels on the \\(\\gls{imageColumn}\\) and \\(\\gls{imageRow}\\) directions respectively,  \\(t_c = \\alpha_c r_h\\) and \\(t_r = \\alpha_r r_h\\) are the translation parameters that help move the origin of image coordinate to the \\gls{principlePoint}.\n\\\\\\indent\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%                                                                                                   %%%%%%%%%%\n%%%%%%%%%%      2. Extrinsic, (X^w, Y^w, Z^w) --> (X^c, Y^c, Z^c)          %%%%%%%%%%%\n%%%%%%%%%%                                                                                                    %%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nNow we have \\(\\gls{intrinsicMatrixK}\\), which helps map between camera \\gls{3D} space and image 2D space. But we are still not able to employ it yet. The camera \\gls{3D} space is with respect to the camera sensor only. Neither can we directly tell the camera \\gls{3D} coordinates of an object point, nor can we assign it. All we can do is to use the camera space as an intermediate space between the image coordinates and world coordinates, which we could assign by ourselves. %\n%\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[width=0.65\\textwidth]{FromWorldToCameraSpace}\n\\caption{Pinhole Camera in World Space}\n\\label{FromWorldToCameraSpace}\n\\end{figure}%\n%\nFigure~\\ref{FromWorldToCameraSpace} shows a pinhole camera observing an arbitrary object point P in the world  space. We assign the world coordinates so that the object point has world space coordinates \\(P^W(x^w, \\, y^w, \\, z^w)\\). Although the world space and camera space are two different spaces, we could easily transform between each other through rotation and translation, as long as both of the spaces are using rigid Cartesian Coordinates. With a standard rotation matrix \\(\\gls{exRotationR}\\) and a translation matrix \\(\\gls{exTranslationT}\\)\n%\n\\begin{equation}\n\\gls{exRotationR}%\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\\gls{exTranslationT}%\n=  \\begin{bmatrix} \nt_{1} \\\\\nt_{2} \\\\\nt_{3}\n \\end{bmatrix} ,%\n\\label{rotationTranslationMatrixRT}\n\\end{equation}%\n%\nwe can get the transformation matrix \\([\\gls{exRotationR} ,\\,\\, \\gls{exTranslationT}]\\) from the world space to camera space:\n%\n\\begin{equation}\n\\begin{bmatrix} \nX^{C} \\\\\nY^{C} \\\\\nZ^{C}\n \\end{bmatrix}%\n=  \\gls{exRotationR} \\begin{bmatrix} \nX^{W} \\\\\nY^{W} \\\\\nZ^{W}\n \\end{bmatrix}%\n + \\gls{exTranslationT}\n=\n\\begin{bmatrix} \n\\gls{exRotationR} & \\gls{exTranslationT} \\\\\n\\end{bmatrix}%\n \\begin{bmatrix} \nX^{W} \\\\\nY^{W} \\\\\nZ^{W} \\\\\n1\n \\end{bmatrix}  .%\n\\label{mappingFromWorldToCameraSpace}\n\\end{equation}%\n%\n%%%% 2.5 Pinhole Camera Matrix (X^w, Y^w, Z^w) --> (X^c, Y^c, Z^c) --> \\(r, \\, c\\)\n%\n\\noindent\nThe parameters that help map from world space to camera space depend on how we assign the world coordinates. Since none of them are from the camera even though they are belongs to an important part of camera calibration, usually the matrix \\([\\gls{exRotationR} \\,\\, \\gls{exTranslationT}]\\) is called extrinsic camera matrix. With both of the extrinsic camera matrix (help map from world space to camera space) and the intrinsic camera matrix (help map from camera space to image space), we are now able to build the connection between the world space coordinates, which could be assigned by ourselves, and the image space \\(\\gls{imageRow}\\) and \\(\\gls{imageColumn}\\), which are the streams we retrieved from the camera. \n\\\\\\indent\nTo combine the intrinsic camera matrix and extrinsic camera matrix (combine eqn.~(\\ref{HomoProportionalFromCamToImInPixels}) and eqn.(~\\ref{mappingFromWorldToCameraSpace})), we get \n\n\\begin{equation}\n\\gls{cameraZ}\\left[ \\begin{array}{c} C \\\\ R \\\\ 1 \\end{array} \\right] %\n=\\gls{intrinsicMatrixK} \\left[ \\begin{array}{c} \\gls{cameraX} \\\\ \\gls{cameraY} \\\\ \\gls{cameraZ}\\end{array} \\right]%\n=\\gls{intrinsicMatrixK} \\begin{bmatrix} \\gls{exRotationR} & \\gls{exTranslationT} \\end{bmatrix} \\left[ \\begin{array}{c} X^W \\\\ Y^W \\\\ Z^W \\\\ 1 \\end{array} \\right]%\n=\\gls{pinHoleCameraM} \\left[ \\begin{array}{c} X^W \\\\ Y^W \\\\ Z^W \\\\ 1 \\end{array} \\right]%\n , %\n\\label{pinholeCameraMatrixCalculation}\n\\end{equation}%\n\\noindent\nwhere: %\n\\begin{equation}\n\\gls{pinHoleCameraM} = \\gls{intrinsicMatrixK} \\begin{bmatrix} \\gls{exRotationR} & \\gls{exTranslationT} \\end{bmatrix}%\n= \\begin{bmatrix} \nm_{11} & m_{12} & m_{13} & m_{14} \\\\\nm_{21} & m_{22} & m_{23} & m_{24} \\\\\nm_{31} & m_{32} & m_{33} & m_{34} \\\\\n\\end{bmatrix} . %\n\\label{pinholeMatrix3x4M}\n\\end{equation}%\n%\n\\noindent\nNote that, although \\(\\gls{cameraZ}\\) values can be retrieved from the depth sensor streams, they will be employed during the calculation of \\(\\gls{pinHoleCameraM}\\), because they will be expressed by the third row parameters in matrix \\(\\gls{pinHoleCameraM}\\). \\(\\gls{cameraZ}\\) will only be used in the step of \\gls{3D} reconstruction after the pinhole camera matrix M is determined, as will be discussed in details in Section~\\ref{section3DcameraCalibration}. Thus, \\(\\gls{cameraZ}\\) in eqn.~(\\ref{pinholeCameraMatrixCalculation}) is commonly substituted as an intermediate parameter \\(k\\). We did not change \\(\\gls{cameraZ}\\) for the consistency of derivations.\nTo inspect the pinhole camera matrix \\(\\gls{pinHoleCameraM}\\), it is composed of rotation/translation matrix for \\gls{3D} space transforming and intrinsic perspective matrix for handling both of perspective view mapping and shape-skewing, all of which belong to linear processing. In other words, this $3\\times4$ transformation matrix is specially for handling perspective view, or perspective distortion. The pinhole camera model is based on the homogeneous coordinates, which means its matrix \\(\\gls{pinHoleCameraM}\\) is also limited by linear processing.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%                                                                                                   %%%%%%%%%%\n%%%%%%%%%%      3.        \\gls{3D} Reconstruction from Depth                               %%%%%%%%%%%\n%%%%%%%%%%                                                                                                    %%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n   \n\\section{\\gls{3D} Camera Calibration}\n\\label{section3DcameraCalibration}\n%    3. Pinhole camera matrix solving for matrix M\n\\indent\nThe calibration of a \\gls{3D} camera aims to be able to generate the world coordinates (\\(\\gls{worldX}, \\gls{worldY}, \\gls{worldZ}\\)) and corresponding \\(RGB\\) values for every single pixel, given the depth steams and RGB streams retrieved from the \\gls{3D} camera. From Section~\\ref{sectionPinholeCamera}, we know that the pinhole camera matrix \\(\\gls{pinHoleCameraM}\\) (eqn.~(\\ref{pinholeMatrix3x4M})) could help map from the world space to image space; however not able to directly transform image space data to world space coordinates. In order to determine \\(\\gls{worldX}/\\gls{worldY}/\\gls{worldZ}\\) (based on eqn.(~\\ref{HomoProportionalFromCamToImInPixels}) and eqn.(~\\ref{mappingFromWorldToCameraSpace})), both of the intrinsic camera matrix and extrinsic camera matrix are needed, both of which are intermediate parameters and practically can only be determined through matrix \\(\\gls{pinHoleCameraM}\\). Thus, the first job for \\gls{3D} camera calibration is to solve the pinhole camera matrix \\(\\gls{pinHoleCameraM}\\).\n\\\\\\indent\nTo solve the pinhole camera matrix, we can use least squares fit with known \\gls{3D} points (\\(\\gls{worldX}\\), \\(\\gls{worldY}\\), \\(\\gls{worldZ}\\)) and their corresponding image points (\\(R, C\\)). With one point, based on eqn.~(\\ref{pinholeMatrix3x4M}) and (\\ref{pinholeCameraMatrixCalculation}), we can get two equations.\n\\begin{equation}\n\\begin{aligned}\nm_{11}\\gls{worldX} + m_{12}\\gls{worldY} + m_{13}\\gls{worldZ} + m_{14} - m_{31}X^WC - m_{32}Y^WC - m_{33}Z^WC - m_{34}C = 0%\n\\\\%\nm_{21}\\gls{worldX} + m_{22}\\gls{worldY} + m_{23}\\gls{worldZ} + m_{24} - m_{31}X^WR - m_{32}Y^WR - m_{33}Z^WR - m_{34}R = 0\n\\end{aligned}\n\\label{onePointEquationCR}\n\\end{equation}%\n\\noindent\nThere are totally 12 unknowns to solve, thus we need at least six points to solve the $3\\times4$ pinhole camera matrix \\(\\gls{pinHoleCameraM}\\). Using $n$-points least squares to solve the best fit, we can build a $2n$ equations matrix, given by eqn.~(\\ref{nPoints2nEquationCR}).\n\n\\begin{equation}\n\\hspace*{-1cm}\n\\begin{bmatrix} \n\\gls{worldX}_1 & \\gls{worldY}_1 & \\gls{worldZ}_1 & 1 & 0 & 0 & 0 & 0 & -\\gls{worldX}_1C_1 & -\\gls{worldY}_1C_1 & -\\gls{worldZ}_1C_1 & -C_1\\\\\n0 & 0 & 0 & 0 & \\gls{worldX}_1 & \\gls{worldY}_1 & \\gls{worldZ}_1 & 1 &  -\\gls{worldX}_1R_1 & -\\gls{worldY}_1R_1 & -\\gls{worldZ}_1R_1 & -R_1\\\\\n\\gls{worldX}_2 & \\gls{worldY}_2 & \\gls{worldZ}_2 & 1 & 0 & 0 & 0 & 0 & -\\gls{worldX}_2C_2 & -\\gls{worldY}_2C_2 & -\\gls{worldZ}_2C_2 & -C_2\\\\\n0 & 0 & 0 & 0 & \\gls{worldX}_2 & \\gls{worldY}_2 & \\gls{worldZ}_2 & 1 &  -\\gls{worldX}_2R_2 & -\\gls{worldY}_2R_2 & -\\gls{worldZ}_2R_2 & -R_2\\\\\n & & & & & & & \\vdots & & & & \\\\\n\\gls{worldX}_n & \\gls{worldY}_n & Z^n_2 & 1 & 0 & 0 & 0 & 0 & -\\gls{worldX}_nC_n & -\\gls{worldY}_nC_n & -\\gls{worldZ}_nC_n & -C_n\\\\\n0 & 0 & 0 & 0 & \\gls{worldX}_n & \\gls{worldY}_n & \\gls{worldZ}_n & 1 & -\\gls{worldX}_nR_n & -\\gls{worldY}_nR_n & -\\gls{worldZ}_nR_n & -R_n\n\\end{bmatrix}\n\\begin{bmatrix} \nm_{11} \\\\ m_{12} \\\\ m_{13} \\\\ m_{14} \\\\\n\\vdots\n\\\\ m_{33} \\\\ m_{34} \n\\end{bmatrix}\n=\n\\begin{bmatrix} \n0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\\n\\vdots \\\\ 0 \\\\ 0\n\\end{bmatrix}\n\\label{nPoints2nEquationCR}\n\\end{equation}%\n\n\\noindent\nConsidering that this matrix is build on homogeneous system, there is no unique solution. There can always be a total-zeros solution. %\n\\\\\\indent\nTo make the solution unique, we select \\(m_{34} = 1\\), so that the homogeneous eqn.~(\\ref{nPoints2nEquationCR}) could be changed into an inhomogeneous format like \\(\\textbf{\\textit{A}}X = B\\), where the known matrix \\(\\textbf{\\textit{A}}\\) is a $2n\\times11$ matrix and known matrix \\(B\\) is a $2n$ vector:\n\n\\begin{equation}\n\\hspace*{-0.1cm}\n\\begin{bmatrix} \n\\gls{worldX}_1 & \\gls{worldY}_1 & \\gls{worldZ}_1 & 1 & 0 & 0 & 0 & 0 & -\\gls{worldX}_1C_1 & -\\gls{worldY}_1C_1 & -\\gls{worldZ}_1C_1\\\\\n0 & 0 & 0 & 0 & \\gls{worldX}_1 & \\gls{worldY}_1 & \\gls{worldZ}_1 & 1 &  -\\gls{worldX}_1R_1 & -\\gls{worldY}_1R_1 & -\\gls{worldZ}_1R_1\\\\\n\\gls{worldX}_2 & \\gls{worldY}_2 & \\gls{worldZ}_2 & 1 & 0 & 0 & 0 & 0 & -\\gls{worldX}_2C_2 & -\\gls{worldY}_2C_2 & -\\gls{worldZ}_2C_2\\\\\n0 & 0 & 0 & 0 & \\gls{worldX}_2 & \\gls{worldY}_2 & \\gls{worldZ}_2 & 1 &  -\\gls{worldX}_2R_2 & -\\gls{worldY}_2R_2 & -\\gls{worldZ}_2R_2\\\\\n & & & & & & & \\vdots & & &\\\\\n\\gls{worldX}_n & \\gls{worldY}_n & Z^n_2 & 1 & 0 & 0 & 0 & 0 & -\\gls{worldX}_nC_n & -\\gls{worldY}_nC_n & -\\gls{worldZ}_nC_n\\\\\n0 & 0 & 0 & 0 & \\gls{worldX}_n & \\gls{worldY}_n & \\gls{worldZ}_n & 1 & -\\gls{worldX}_nR_n & -\\gls{worldY}_nR_n & -\\gls{worldZ}_nR_n\n\\end{bmatrix}\n\\begin{bmatrix} \nm_{11} \\\\ m_{12} \\\\ m_{13} \\\\ m_{14} \\\\\n\\vdots\n \\\\ m_{32} \\\\ m_{33}\n\\end{bmatrix}\n=\n\\begin{bmatrix} \nC_1 \\\\ R_1 \\\\ C_2 \\\\ R_2 \\\\\n\\vdots \\\\ C_n \\\\ R_n\n\\end{bmatrix} .\n\\label{inHomogenousNPoints2nEquationCR}\n\\end{equation}%\n\\noindent\nUsing pseudo inverse, eqn.~(\\ref{inHomogenousNPoints2nEquationCR}) can be solved by \\(X = (\\textbf{\\textit{A}}^T\\textbf{\\textit{A}})^{-1}\\textbf{\\textit{A}}^TB\\), where \\(X\\) is an 11-elements vector and \\(X(1)\\)  \\texttildelow \\, \\(X(11)\\) correspond to \\(m_{11}\\) \\texttildelow \\, \\(m_{33}\\). And the $3\\times4$ pinhole camera matrix (eqn.~(\\ref{pinholeMatrix3x4M})) will be solved as: \n\n\\begin{equation}\n\\gls{pinHoleCameraM} =\n\\begin{bmatrix} \nX(1) & X(2) & X(3) & X(4) \\\\\nX(5) & X(6) & X(7) & X(8) \\\\\nX(9) & X(10) & X(11) & 1\n\\end{bmatrix}\n\\label{determinationOfPinhole3x4}\n\\end{equation}%\n\\\\\n\\noindent\nAfter we get the perspective projection matrix \\(\\gls{pinHoleCameraM}\\), the next step is to recover the intrinsic and extrinsic camera matrix \\(\\gls{intrinsicMatrixK}\\) and [\\(\\gls{exRotationR}, \\, \\gls{exTranslationT}\\)], with which we could generate the world coordinates \\(\\gls{worldX}/\\gls{worldY}/\\gls{worldZ}\\). \n\\\\\\indent\nStarting from the decomposition of eqn.~(\\ref{pinholeMatrix3x4M}) step by step:\n\n\\begin{equation}\n\\gls{pinHoleCameraM} =\n\\begin{bmatrix} \nm_{11} & m_{12} & m_{13} &  \\\\\nm_{21} & m_{22} & m_{23} & \\textbf{\\textit{O}}_{3*1} \\\\\nm_{31} & m_{32} & m_{33} &  \n\\end{bmatrix}%\n+\n\\begin{bmatrix} \n &  &  & m_{14} \\\\\n & \\textbf{\\textit{O}}_{3*3} &  & m_{24} \\\\\n &  &  & m_{34} \\\\\n\\end{bmatrix} , %\n\\label{decomposePerspectiveProjectionOne}\n\\end{equation}%\n\n\\begin{equation}\n\\gls{intrinsicMatrixK} [\\gls{exRotationR} \\, \\, \\gls{exTranslationT}] =\n\\begin{bmatrix} \n\\gls{intrinsicMatrixK} \\gls{exRotationR} & \\textbf{\\textit{O}}_{3*1}\n \\end{bmatrix}%\n+\n\\begin{bmatrix} \n\\textbf{\\textit{O}}_{3*3} & \\gls{intrinsicMatrixK} \\gls{exTranslationT}\n\\end{bmatrix} , %\n\\label{decomposePerspectiveProjectionTwo}\n\\end{equation}%\n%\nand \n\n\\begin{equation}\n\\textbf{\\textit{M}}_{3*3} =\n\\begin{bmatrix} \nm_{11} & m_{12} & m_{13} \\\\\nm_{21} & m_{22} & m_{23} \\\\\nm_{31} & m_{32} & m_{33}  \n\\end{bmatrix}%\n=\n\\gls{intrinsicMatrixK} \\gls{exRotationR}  ,\n\\label{QRdecompositionEquation}\n\\end{equation}%\n\\noindent\nwhere \\(\\textbf{\\textit{O}}\\) denotes zero matrices with their sizes noted by subscripts. From eqn.~(\\ref{rotationTranslationMatrixRT}), we know that \\(\\gls{exRotationR}\\) is a standard rotation matrix, which has its property of orthogonal. Also from eqn.~(\\ref{intrinsicKmatrix}), we know that \\(\\gls{intrinsicMatrixK}\\) is an upper triangular matrix. Thus, all of the above fit in the prerequisites of RQ decomposition, which is a technique that could help us decompose the \\(\\textbf{\\textit{M}}_{3*3}\\) into the upper triangular intrinsic matrix \\(\\gls{intrinsicMatrixK}\\) and rotation matrix \\(\\gls{exRotationR}\\). After we got \\(\\gls{exRotationR}\\), the translation matrix \\(\\gls{exTranslationT}\\) could be determined with eqn.~(\\ref{decomposePerspectiveProjectionTwo}).\n\\\\\\indent%\n% 4. cite/introduce the static 90 degree angle calibration system, collect data for solving equation 1.11\n%\nNow we find the way to determine both of the intrinsic camera matrix and the extrinsic camera matrix. With depth streams measuring \\(\\gls{cameraZ}\\), we are able to transform the 2D image data retrieved from the camera into \\gls{3D} camera space point cloud by eqn.~(\\ref{HomoProportionalFromCamToImInPixels}), and then generate the world space point cloud by eqn.~(\\ref{mappingFromWorldToCameraSpace}). The basic pinhole camera model calculation is widely used in various camera calibration techniques. Based on different calibration systems, Zhengyou \\cite{Zhengyou04} classified those calibration techniques into four categories: unknown scene points in the environment (self-calibration), 1D objects (wand with dots), 2D objects (planar patterns undergoing unknown motions) and \\gls{3D} apparatus (two or three planes orthogonal to each other). \n\\\\\\indent\nSelf-calibration technique do not use any calibration object, and can be considered as zero-dimension approach because only image point correspondences are required. Just by moving a camera in a static scene, the rigidity of the scene provides in general two constraints \\cite{selfCalibration3_1992} on the cameras' internal parameters from one camera displacement by using image information alone. Therefore, if images are taken by the same camera with fixed internal parameters, correspondences between three images are sufficient to recover both the internal and external parameters which allow us to reconstruct 3D structure up to a similarity \\cite{selfCalibration2_1997, selfCalibration1_1994}. \n\\\\\\indent\nOne-Dimension, points-line calibration employs one dimension objects composed of a set of collinear points. With much lower cost than two dimensional or even three dimensional calibration system, using one dimension objects in camera calibration is not only a theoretical aspect, but is also very important in practice especially when multi-cameras are involved in the environment. To calibrate the relative geometry between multiple cameras, it is necessary for all involving cameras to simultaneously observe a number of points. It is hardly possible to achieve this with \\gls{3D} or 2D calibration apparatus if one camera is mounted in the front of a room while another in the back. This is not a problem for 1D objects. Xiangjian \\cite{oneDcalibration1_2006} shows how to estimate the internal and external parameters using one dimensional pattern in the camera calibration. And Zijian \\cite{oneDcalibration2_2008} employed one dimensional objects as virtual environments in practical multiple cameras calibration.\n\\\\\\indent\nTwo and three dimensional object calibration systems usually give better calibrations. Sturm \\textit{et al}. \\cite{twoDcalibration1_1999} presented a general algorithm for plane-based calibration\nthat can deal with arbitrary numbers of views that observe a planar pattern shown at different orientations, so that almost anyone can make such a calibration pattern by him/her-self, and the setup is very easy. Both of Matlab and OpenCV have applied this two dimension plane calibration method in their applications. Zhengdong \\cite{twoDcalibration2_2011} compared this two dimension plane camera calibration method and self-calibration method. Hamid \\cite{twoDcalibration3_2015} applied this method into practical calibration and employed the calibrated camera into camera pose estimation and distance estimation application.\n\\\\\\indent\nIn three-dimensional object calibration technique, camera calibration is performed by observing a calibration object whose geometry in \\gls{3D} space is known for very good precision. Calibration can be done very efficiently \\cite{treeDcalibration1_1993}. The calibration objects usually consist of two or three planes orthogonal to each other. Paul \\cite{treeDcalibration2_1996} applied the three dimension object calibration in his PHD project. Mattia \\cite{threeDExample_2014} wrote a detailed tutorial from building the \\gls{3D} object (Fig.~\\ref{buildingThreeDCalibrationObject}) for calibration, to scanning using the calibrated camera. Figure~\\ref{threeDSixPointsCalibrating} shows how six points are selected for calibration and Fig.~\\ref{3DreconstructAfterCalibration} shows the \\gls{3D} reconstruction after calibration.\n%\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{buildingThreeDCalibrationObject}\n\\caption{Building \\gls{3D} Calibration Object \\cite{threeDExample_2014}}\n\\label{buildingThreeDCalibrationObject}\n\\end{figure}%\n%\n\\begin{figure}[!t]\n\\centering\n\\subfloat[Six Points to Calibrate]{\n\t\\includegraphics[height=0.6\\textwidth, width=0.45\\textwidth]{threeDSixPointsCalibrating}\n\t\\label{threeDSixPointsCalibrating}\n}\n\\subfloat[Reconstruction After Calibration]{\n\t\\includegraphics[height=0.6\\textwidth, width=0.45\\textwidth]{3DreconstructAfterCalibration}\n\t\\label{3DreconstructAfterCalibration}\n}\n\\caption{Three Dimension Object Camera Calibration \\cite{threeDExample_2014}}\n\\label{twoPlanesCalibration}\n\\end{figure}%\n%\n\n\n%\\begin{figure}[p]\n%\\centering\n%\\includegraphics[width=0.8\\textwidth]{buildingThreeDCalibrationObject}\n%\\caption{Building Three Dimension Object}\n%\\label{buildingThreeDCalibrationObject}\n%\\end{figure}%\n%\n%\\begin{figure}[b]\n%\\centering\n%\\includegraphics[width=0.8\\textwidth]{buildingThreeDCalibrationObject}\n%\\caption{Building Three Dimension Object}\n%\\label{buildingThreeDCalibrationObject}\n%\\end{figure}%\n\n\n\n\n%\\\\\\\\%\n\nZhengyou Zhang \\cite{zhangCalibration1_2004, zhangCalibration2_2000, Zhengyou04} has deep studies on camera calibration from one-dimension calibration to tree-dimension calibration. The accuracy of calibration from 1D to \\gls{3D} is getting better, but the calibration system set-up needs more and more work and cost as well. One dimension object is suitable for calibrating multiple cameras at once. Two dimension planer pattern approaches seems to be a good compromise, with good accuracy and simple setup. Also using the three dimension method for calibration, Kai \\cite{Kai10} derived the per-pixel  beam equation, the linear relationship that could map to \\(\\gls{worldX}/\\gls{worldY}\\) from \\(\\gls{worldZ}\\) as eqn.~(\\ref{kaiBeamEquation}) shows, directly from pinhole camera matrix \\(\\gls{pinHoleCameraM}\\). That is to say, we could easily look up \\(\\gls{worldX}/\\gls{worldY}\\) after calibration once found the way to get \\(\\gls{worldZ}\\).\n\n\\begin{equation}\n\\begin{aligned}\n\\gls{worldX} [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}] = a [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}]  \\gls{worldZ} [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}]+d [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}] \n\\\\%\n\\gls{worldY} [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}] = c [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}]  \\gls{worldZ} [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}]+d [\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}] \n\\end{aligned}\n\\label{kaiBeamEquation}\n\\end{equation}%\n\\noindent\nwhere \\(a/b/c/d\\) are per-pixel coefficients for the linear beam equations, and the subscripts \\([\\gls{imDiscreteRow}, \\, \\gls{imDiscreteColumn}] \\) are corresponding pixel address in image space.\n\n%\\gls{D}[r, c] ~= \\gls{worldZ}[r, c] -- > (X^c, Y^c)\n%\\gls{worldZ}[r, c] = Z^c[r, c] = \\gls{D}[r,c]\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%                                                                                                   %%%%%%%%%%\n%%%%%%%%%%      4.        Lens Distortion Removal                                                %%%%%%%%%%%\n%%%%%%%%%%                                                                                                    %%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Lens Distortion}\n%* distortion equation\n\\indent\nAll above in Chapter \\ref{chapterTraditionalCalibration} are talking about the ideal pinhole camera, without lenses. Whereas in practice, as a result of several types of imperfections in the design and assembly of lenses composing the camera optical system, there are always lens distortions for a camera, and the expressions in eqn.~(\\ref{twoDRelativeFromCamToIm}) are not valid any more. Lens distortion could be classified into two groups \\cite{distortion1_1992} : radial distortion and tangential distortion. Imperfect lens shape causes light rays bending more near the edges of a lens than they do at its optical center. Barrel distortions happen commonly on wide angle lenses, where the field of view of the lens is much wider than the size of the image sensor \\cite{whatisDistortion_2013}. Improper lens assembly will lead to tangential distortion, which occurs when the lens and the image plane are not parallel. Figure~\\ref{RadialAndTangentialDistortion} shows how radial distortion \\(d_\\text{r}\\) and tangential distortion \\(d_\\text{t}\\) affect the object point position in the image. Note that both of radial distortion and tangential distortion are with respect to image space row and column, and what we will take later is negative distortion instead of positive. Distortions are present because the field of view (\\gls{FoV}) in camera space has been affected by the lens. \n%\n\\begin{figure}[b]\n\\centering\n\\includegraphics[width=0.65\\textwidth]{RadialAndTangentialDistortion}\n\\caption{Radial and Tangential Distortion Affection In Image Space}\n\\label{RadialAndTangentialDistortion}\n\\end{figure}%\n%\nFor most consumer \\gls{RGBD} cameras with cheap lens, their distortions are usually barrel distortions (negative distortion) resulted by the enlarged field  of view in the camera space, because the larger view was squeezed into the sensor. Figure~\\ref{DistortionComprehension} intuitively shows how the lens enlarged the field of view of in the camera space and then generates the barrel distortions.\n%\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=\\textwidth]{DistortionComprehension}\n\\caption{From Camera Space to Image Space with Lens Distortions}\n\\label{DistortionComprehension}\n\\end{figure}%\n\nThere are (a)(b)(c) three parts shown in Fig.~\\ref{DistortionComprehension}. Each part has the pinhole camera only on the top, in contrast to the camera-with-lens situation at the bottom. To understand how the barrel distortion happens, we should go through from part (c) to part (a). In part (c), the gray background uniform grid is the \\enquote{object} our that the camera is going to observe, and the blue frames shows the \\gls{FoV} of the camera in the camera space. Due to the fact that, there will be worse and worse distortions as one pixel goes from the center to the edge, the enlarged \\gls{FoV} of a camera with lens in the camera space is in pincushion (or star) shape. With the enlarged \\gls{FoV} is mapped to the \\enquote{Virtual Focal Plane}, as defined in Fig.~\\ref{PinHoleVirtualFocalPlane}, the pincushion shape doesn't change because rays from the camera space have not gone through the lens yet. Note that we quoted the \\enquote{Virtual Focal Plane} because the image on this virtual plane, when considering lens distortion, does not equal to the real focal plane (where the sensor is) any more. We can tell from part (b) that, even though the image space coordinates still are composed of \\(\\gls{imageColumn}\\) and \\(\\gls{imageRow}\\), their ranges have changed from positive integers only to the whole real integers that include negative ones. But the sensor never changes, and so the image space in part (a) still has its range of positive integers. With rays going through the lens, the pincushion-shape \\gls{FoV} (the frame in blue) will be squeezed into a small rectangle, and thus we get the image in the real focal plane with its background grid showing a barrel distorted shape. %\n%\\\\\\indent%\nWith lens distortions counted, eqn.~(\\ref{twoDRelativeFromCamToIm}) now needs to be changed into \n%\n\\begin{equation}\n\\left[ \\begin{array}{c} c'_r \\\\ r'_r \\end{array} \\right] %\n= f %\n\\left[ \\begin{array}{c} \\gls{cameraPointX0}/\\gls{cameraPointZ0} \\\\ \\gls{cameraPointY0}/\\gls{cameraPointZ0} \\end{array} \\right]%\n\\label{undistortedRelativeFromCamToIm}\n\\end{equation}\nwhere \\(c'_r\\) and \\(r'_r\\) denote the relative pixel distance on the undistorted \\enquote{Virtual Focal Plane}, whose \\gls{FoV} is pincushion-shape and image coordinates' ranges include negative integers.%\n\\\\\\indent%\nDuane \\cite{distortion2_1966} gave the lens distortion equation, and the undistorted \\(\\gls{imageColumn}\\) and \\(\\gls{imageRow}\\) (\\(C'/R'\\) in our notation) can be expressed as power series in radial distance \\(r = \\sqrt{C^2 + R^2}\\):\n%\n\\begin{equation}\n\\begin{aligned}\n\\gls{UndistortedImColumn} =  C (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + [p_1 (r^2 + 2 C^2) + 2 p_2 CR] %\n\\\\\n\\gls{UndistortedImRow} =  R (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + [p_2 (r^2 + 2 R^2) + 2 p_1 CR]\n\\end{aligned}\n\\label{lensDistortion}\n\\end{equation}%\n%\n\\noindent\nwhere higher order parameters are omitted for being negligible; \\((\\gls{UndistortedImColumn} , \\, \\gls{UndistortedImRow})\\) denote the undistorted pixels in the \\enquote{Virtual Focal Plane}, \\((\\gls{imageColumn}, \\, \\gls{imageRow} )\\) denote the distorted pixel in real sensor image, \\(k_i\\)s are coefficients of radial distortion, and \\(p_j\\)s are coefficients of tangential distortion. The five parameters \\(k_1/k_2/k_3/p_1/p_2\\) are usually called distortion parameters. With the distortion parameters calculated, the distorted \\((\\gls{imageColumn}, \\, \\gls{imageRow} )\\) could be undistorted into \\((\\gls{UndistortedImColumn} , \\, \\gls{UndistortedImRow})\\), and then \\((\\gls{UndistortedImColumn} , \\, \\gls{UndistortedImRow})\\) could be used to generate the world space \\(\\gls{worldX}/\\gls{worldY}/\\gls{worldZ}\\) with intrinsic and extrinsic parameters.\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%                                                                                                   %%%%%%%%%%\n%%%%%%%%%%      4.       Summation                                                                  %%%%%%%%%%%\n%%%%%%%%%%                                                                                                    %%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\\section{Summation}\n%%\n\\indent \n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{flowChart}\n\\caption{Traditional Camera Calibration Flow Chart}\n\\label{flowChart}\n\\end{figure}%\n\\\\\\indent\nConsidering the lens distortion correction, Fig.~\\ref{flowChart} shows the flow chart of the whole traditional camera calibration method based on the pinhole camera model. Considering the lens distortions, both of the pinhole camera model (matrix \\(\\gls{pinHoleCameraM}\\)) and the lens distortions model (five parameters for undistortion) need to be determined. The pinhole camera model can help map from the world space (\\(\\gls{worldX}, \\, \\gls{worldY}, \\, \\gls{worldZ}\\)) to the undistorted image space  \\((\\gls{UndistortedImColumn} , \\, \\gls{UndistortedImRow})\\), which are on the \\enquote{Virtual Focal Plane} as noted in Fig.~\\ref{DistortionComprehension}. And the lens distortion model help remove the lens distortions by mapping from  \\((\\gls{UndistortedImColumn} , \\, \\gls{UndistortedImRow})\\) to \\((\\gls{imageColumn}, \\, \\gls{imageRow} )\\). The pinhole camera model can be determined by eqn.~(\\ref{determinationOfPinhole3x4}), and the lens distortion model could be determined by eqn.~(\\ref{lensDistortion}).\n\n\n\n\n%\n%\\begin{equation*}%\n%c_{[row, col]} %\n%= \\frac%\n%{(m_{22}m_{33} - m_{23}m_{32})col + (m_{13}m_{32} - m_{12}m_{33})row + (m_{12}m_{23} - m_{13}m_{22})}%\n%{(m_{21}m_{32} - m_{22}m_{31})col + (m_{12}m_{31} - m_{11}m_{32})row + (m_{11}m_{22} - m_{12}m_{21})} \\, ,\n%\\end{equation*}\n%%\n%\\begin{equation*}%\n%d_{[row, col]} %\n%= \\frac%\n%{(m_{22}m_{34} - m_{24}m_{32})col + (m_{14}m_{32} - m_{12}m_{34})row + (m_{12}m_{24} - m_{14}m_{22})}%\n%{(m_{21}m_{32} - m_{22}m_{31})col + (m_{12}m_{31} - m_{11}m_{32})row + (m_{11}m_{22} - m_{12}m_{21})} \\, ,\n%\\end{equation*}\n%%\n%\\begin{equation*}%\n%e_{[row, col]} %\n%= \\frac%\n%{(m_{23}m_{31} - m_{21}m_{33})col + (m_{11}m_{33} - m_{13}m_{31})row + (m_{13}m_{21} - m_{11}m_{23})}%\n%{(m_{21}m_{32} - m_{22}m_{31})col + (m_{12}m_{31} - m_{11}m_{32})row + (m_{11}m_{22} - m_{12}m_{21})} \\, ,\n%\\end{equation*}\n%%\n%\\begin{equation*}%\n%f_{[row, col]} %\n%= \\frac%\n%{(m_{23}m_{32} - m_{22}m_{33})col + (m_{12}m_{33} - m_{13}m_{32})row + (m_{13}m_{22} - m_{12}m_{23})}%\n%{(m_{21}m_{32} - m_{22}m_{31})col + (m_{12}m_{31} - m_{11}m_{32})row + (m_{11}m_{22} - m_{12}m_{21})}\n%\\end{equation*}\n%\n%\n\n\n\n\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": "37e39ead08d9f66c8cfa9a47795ea855317a8eec", "size": 41201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/02_PinHoleCameraStructuredLight.tex", "max_stars_repo_name": "SenonLi/Universal_Real-Time_XYZ_Rectified_Reconstruction", "max_stars_repo_head_hexsha": "d015ac2f53c5b0b2d9e12036b6fc69ca3e544596", "max_stars_repo_licenses": ["MIT"], "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_PinHoleCameraStructuredLight.tex", "max_issues_repo_name": "SenonLi/Universal_Real-Time_XYZ_Rectified_Reconstruction", "max_issues_repo_head_hexsha": "d015ac2f53c5b0b2d9e12036b6fc69ca3e544596", "max_issues_repo_licenses": ["MIT"], "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_PinHoleCameraStructuredLight.tex", "max_forks_repo_name": "SenonLi/Universal_Real-Time_XYZ_Rectified_Reconstruction", "max_forks_repo_head_hexsha": "d015ac2f53c5b0b2d9e12036b6fc69ca3e544596", "max_forks_repo_licenses": ["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.3700361011, "max_line_length": 1707, "alphanum_fraction": 0.6984053785, "num_tokens": 12600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.688601797397977}}
{"text": "\\begin{appendices}\n\n\\section{Python code used for producing the over-underfitting example in figure \\ref{fig:regr_example}} \\label{app:overfitting}\n\\begin{lstlisting}\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import PolynomialFeatures\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.model_selection import cross_val_score\n\n\ndef true_fun(X):\n    return np.cos(1.5 * np.pi * X)\n\n\nnp.random.seed(0)\n\nn_samples = 30\ndegrees = [1, 4, 15]\n\nX = np.sort(np.random.rand(n_samples))\ny = true_fun(X) + np.random.randn(n_samples) * 0.1\n\nplt.figure(figsize=(14, 5))\nfor i in range(len(degrees)):\n    ax = plt.subplot(1, len(degrees), i + 1)\n    plt.setp(ax, xticks=(), yticks=())\n\n    polynomial_features = PolynomialFeatures(degree=degrees[i],\n                                             include_bias=False)\n    linear_regression = LinearRegression()\n    pipeline = Pipeline([(\"polynomial_features\", polynomial_features),\n                         (\"linear_regression\", linear_regression)])\n    pipeline.fit(X[:, np.newaxis], y)\n\n    # Evaluate the models using crossvalidation\n    scores = cross_val_score(pipeline, X[:, np.newaxis], y,\n                             scoring=\"neg_mean_squared_error\", cv=10)\n\n    X_test = np.linspace(0, 1, 100)\n    plt.plot(X_test, pipeline.predict(X_test[:, np.newaxis]), label=\"Model\")\n    plt.plot(X_test, true_fun(X_test),\n             label=\"True function\", linestyle='dashed')\n    plt.scatter(X, y, edgecolor='b', s=20, label=\"Samples\")\n    plt.xlabel(\"x\")\n    plt.ylabel(\"y\")\n    plt.xlim((0, 1))\n    plt.ylim((-2, 2))\n    plt.legend(loc=\"best\")\n    plt.title(\"Degree {}\\nMSE_cv = {:.2e}(+/- {:.2e})\".format(\n        degrees[i], -scores.mean(), scores.std()))\nplt.show()\n\n\\end{lstlisting}\n\n\\section{Python code for producing the activation functions in figure \\ref{fig:act_funcs}} \\label{app:act_funcs}\n\n\\begin{lstlisting}\nimport tensorflow as tf\nimport matplotlib.pyplot as plt\n\nx = tf.linspace(-10., 10., 200)\ny_sigmoid = tf.keras.activations.sigmoid(x)\ny_tanh = tf.keras.activations.tanh(x)\ny_relu = tf.keras.activations.relu(x)\ny_elu = tf.keras.activations.elu(x)\ny_step = x > 0\n\nplt.plot(x, y_sigmoid, label='Sigmoid')\nplt.plot(x, y_tanh, label=r'$tanh$')\nplt.plot(x, y_relu, label='ReLU')\nplt.plot(x, y_elu, label='ELU')\nplt.plot(x, y_step, label='Step')\naxes = plt.gca()\naxes.set_ylim([-2, 2])\nplt.xlabel('x')\nplt.ylabel('g(x)')\nplt.legend()\nplt.savefig('act_func_fig.pdf')\nplt.show()\n\\end{lstlisting}\n\n\n\\section{Python code for implementing the simple Bayesian neural network illustrated in figure \\ref{fig:simple_BNN}} \\label{app:simple_BNN}\n\\begin{lstlisting}\n#import random as rn\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport tensorflow as tf\nimport tensorflow_probability as tfp\ntfd = tfp.distributions\n\n# -------------------------------- Creating sin-data -------------------------------\n\n\ndef true_fun(x):\n    return np.sin(3 * x)  # np.sin(1.5 * np.pi * x)\n\n\nnp.random.seed(42)\nn_x = 6\nx_train = np.sort(np.random.rand(n_x))\ny_train = true_fun(x_train)  \n\n\n# --------------------- Build and compile neural net -------------------------------\n\nmodel = tf.keras.models.Sequential([\n    tf.keras.layers.Dense(16, input_shape=([1, ]), activation='tanh'),\n    tf.keras.layers.Dense(1, activation='tanh')\n])\nmodel.summary()\n\n\n# --------------------- Sample weights through neural networks with acceptance-prop equal to likelihood ----------------------\n\nn_NN = 10**5\nweight_list = []\nlikelihood_list = []\nsigma_k = 0.1  # sd of assumed gauss P(y \\mid x), Neal's eq 1.8, Neal uses 0.1\ntf.random.set_seed(42)\n# Sample neural networks and save their likelihood and weights\nfor i in range(n_NN):\n    print(i)\n    # sample weights and set them to hidden layer \"dense\" and output layer \"dense_1\"\n    for layer in model.layers:\n        if layer.name == \"dense\":\n            layer.set_weights([np.random.normal(0, 8, size=w.shape)\n                               for w in layer.get_weights()])\n        if layer.name == \"dense_1\":\n            layer.set_weights([np.random.normal(\n                0, 1/np.sqrt(16), size=w.shape) for w in layer.get_weights()])\n    # save weights in list\n    weight_list.append(model.get_weights())\n    # Calculate gauss likelihood of y_train given weights and x_train, Neal's eq 1.11\n    mean = model.predict(x_train)\n    gauss = tfd.Normal(loc=mean, scale=sigma_k)\n    likelihood = 1\n    for j in range(n_x):\n        likelihood *= gauss[j].prob(y_train[j])\n    likelihood_list.append(likelihood)\n\n# Normalize likelihood to max prob is 1\nif max(likelihood_list) != 0:\n    likelihood_list = likelihood_list/max(likelihood_list)\n\n# Accept model with prob equal to normalized likelihood\naccepted_weights = []\naccepted_likelihood = []\nfor i in range(len(likelihood_list)):\n    uniform_dist = tfd.Uniform(0, 1)\n    if likelihood_list[i] >= uniform_dist.sample():\n        accepted_weights.append(weight_list[i])\n        accepted_likelihood.append(likelihood_list[i])\n\n\n# --------------------- Use sampled weights for predicting y's ----------------------\nx_pred = tf.linspace(0.0, 1, 200)\ny_pred = []\nfor i in range(len(accepted_weights)):\n    model.set_weights(accepted_weights[i])\n    y_pred.append(model.predict(x_pred))\n\n# mean y_pred\nmean_y_pred = np.array(y_pred).mean(axis=0)\n\ny_pred_std = np.array(y_pred).std(axis = 0)\n# Lower std-line\nlower_std = mean_y_pred - y_pred_std \n# Upper std-line\nupper_std = mean_y_pred + y_pred_std\n\n# --------------------- Plot of BNN results ----------------------\nplt.scatter(x_train, y_train,\n            edgecolor='b', s=40, label=\"Datapoint\")\nfor i in range(len(y_pred)):\n    plt.plot(x_pred, y_pred[i], color='k', linestyle='dashed')\nplt.plot(x_pred, mean_y_pred, color='coral', label=\"Average prediction\")\nplt.fill_between(x_pred, lower_std.flatten() , upper_std.flatten() , color='b', alpha=.1)\nplt.xlabel('x')\nplt.ylabel('y')\nplt.legend()\nplt.savefig('figure_simple_BNN.pdf')\nplt.show()\n\n\\end{lstlisting}\n\n\n\n\\section{Python code for Metropolis implementation used for producing figure \\ref{fig:MH_sampling} }\\label{app:MH_code}\n\\begin{lstlisting}\n# # ----------------------------- IMPORTS ---------------------------\n\nimport numpy as np\nimport scipy.stats as ss\nimport matplotlib.pyplot as plt\n\n# # ----------------------------- Defining functions ---------------------------\n# Defining target probability\ndef p(x):\n    sigma = np.array([[1, 0.6], [0.6, 1]])  # Covariance matrix\n    return ss.multivariate_normal.pdf(x, cov=sigma)\n\n# # ----------------------------- Sampling  ---------------------------\nsamples = np.zeros((1000, 2))\nnp.random.seed(42)\n\nx = np.array([7, 0])\nfor i in range(1000):\n    samples[i] = x\n    # Gaussian proposal for symmetry\n    x_prime = np.random.multivariate_normal(mean=x, cov=np.eye(2), size=1).flatten()\n    acceptance_prob = min(1, (p(x_prime) )/ (p(x)))\n    u = np.random.uniform(0, 1)\n    if u <= acceptance_prob:\n        x = x_prime\n    else:\n        x = x\n\n# # ----------------------------- Vizualising  ---------------------------\n \n# For vizualising normal contours       \nX, Y = np.mgrid[-3:3:0.05, -3:3:0.05]    \nX, Y = np.mgrid[-3:3:0.05, -3:3:0.05]\nXY = np.empty(X.shape + (2,))\nXY[:,:,0] = X; XY[:,:,1] = Y\ntarget_distribution = ss.multivariate_normal(mean=[0,0], cov=[[1, 0.6],[0.6, 1]])\n\n\nplt.subplot(2, 2, 1) # row 1, col 2 index 1\nplt.contour(X, Y, target_distribution.pdf(XY),cmap=plt.cm.Blues)\nplt.ylim(-3,5)\nplt.xlim(-3,8)\nplt.subplot(2, 2, 2) # index 2\nplt.plot(samples[0:100,0], samples[0:100,1], 'ro-', color=\"navy\", linewidth=.2, markersize=.7,label=\"First 100 samples\")\nplt.contour(X, Y, target_distribution.pdf(XY),cmap=plt.cm.Blues)\nplt.legend(loc=\"upper right\",fontsize=9)\nplt.ylim(-3,5)\nplt.xlim(-3,8)\nplt.subplot(2, 2, 3) # index 3\nplt.plot(samples[0:200,0], samples[0:200,1], 'ro-', color=\"navy\", linewidth=.2, markersize=.7,label=\"First 200 samples\")\nplt.contour(X, Y, target_distribution.pdf(XY),cmap=plt.cm.Blues)\nplt.legend(loc=\"upper right\",fontsize=9)\nplt.ylim(-3,5)\nplt.xlim(-3,8)\nplt.subplot(2, 2, 4) # index 4\nplt.plot(samples[0:300,0], samples[0:300,1], 'ro-', color=\"navy\", linewidth=.2, markersize=.7, label=\"First 300 samples\")\nplt.contour(X, Y, target_distribution.pdf(XY),cmap=plt.cm.Blues)\nplt.legend(loc=\"upper right\",fontsize=9)\nplt.ylim(-3,5)\nplt.xlim(-3,8)\nplt.savefig(\"metro_example.pdf\")\nplt.show()\n\n\\end{lstlisting}\n\n\n\n\n\n\\section{Python packages and specification for computer doing the evaluations in chapter \\ref{chap:eval_NN}} \\label{app:specs}\nThe code ran on a virtual machine for the Linux distribution Ubuntu 20.04.2 LTS. The virtual machine used VMWare Workstation 16.1.1 on a native Windows 10 64-bit version 2004. The hardware used is\n\\begin{itemize}\n    \\item GPU: NVidia GeForce GTX 970\n    \\item RAM allocated to virtual machine: 9.5 GB\n    \\item Processor: Intel® Core™ i5-6600K CPU @ 3.50GHz × 4\n    \\item A harddrive allocated only to this virtual machine with free space of 427 GB\n\\end{itemize}\nThe packages required for reproducing the evalutions are \n\\begin{itemize}\n    \\item \\texttt{PyMC3}==3.11.2\n    \\item \\texttt{Theano}==1.1.2\n    \\item \\texttt{Arviz}==0.11.2\n    \\item \\texttt{Numpy}==1.19.5\n    \\item \\texttt{tensorflow}==2.4.1\n    \\item \\texttt{tensorflow\\_probability}==0.12.2\n    \\item \\texttt{sklearn}==0.24.2\n    \\item \\texttt{numpy}==1.19.5\n    \\item \\texttt{seaborn}==0.11.1\n    \\item \\texttt{matplotlib.pyplot}==3.4.1\n\\end{itemize}\n\n\n\n\\section{Python code for the neural networks in table \\ref{tab:Boston_NN_performance}} \\label{app:Boston_NN}\nThe network with with early stopping is performed using the code\n\\begin{lstlisting}\nimport tensorflow as tf\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom keras.datasets import boston_housing\nimport time\n\n\ntf.random.set_seed(40)\n\n# ----------------------------- Prepare data ---------------------\n(X_train, y_train), (X_test, y_test) = boston_housing.load_data(seed=3030)\n\n# ----------------------------- Neural Network ---------------------\nn_hidden = 10\n\nmodel = tf.keras.Sequential([\n    tf.keras.Input((13, ), name='feature'),\n    tf.keras.layers.Dense(n_hidden, activation=tf.nn.relu),\n    tf.keras.layers.Dense(1)\n])\nmodel.summary()\n\n# Early stopping\nes = tf.keras.callbacks.EarlyStopping(\n    monitor='val_loss', mode='min', patience=10, min_delta=0.1)\n\nstart_time = time.time()\n# Compile, train, and evaluate.\nmodel.compile(optimizer='adam',\n              loss='mean_squared_error',\n              metrics=['mse'])\nhistory = model.fit(X_train, y_train, epochs=300,\n                    validation_split=0.3, callbacks=[es])\n\nprint(\"The algorithm ran\", len(history.history['loss']), \"epochs\")\n\n\n# ----------------------------- Overfitting? ---------------------\ntrain_acc = model.evaluate(X_train, y_train, verbose=0)[-1]\ntest_acc = model.evaluate(X_test, y_test, verbose=0)[-1]\nprint(\"--- %s seconds ---\" % (time.time() - start_time))\nprint('Train: %.3f, Test: %.3f' % (train_acc, test_acc))\n\nplt.plot(history.history['loss'], label='train')\nplt.plot(history.history['val_loss'], label='validation')\nplt.legend()\nplt.grid()\nplt.show()\n\n\\end{lstlisting}\nThe networks not using early stopping and their visualization of train and validation loss in figure \\ref{fig:Boston_NN_nohidden_wd_loss}, figure \\ref{fig:Boston_NN_1hidden_wd_loss} and figure \\ref{fig:Boston_NN_1hidden_noreg_loss} are produced using the code\n\\begin{lstlisting}\nimport tensorflow as tf\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom keras.datasets import boston_housing\nimport time\nfrom keras.regularizers import l2\n\ntf.random.set_seed(40)\n# ----------------------------- Prepare data ----------------------\n(X_train, y_train), (X_test, y_test) = boston_housing.load_data(seed=3030)\n\n\n# ----------------------------- Neural Network --------------------\nreg_const = 0.3\nn_hidden = 10\n\nmodel = tf.keras.Sequential([\n    tf.keras.Input((13, ), name='feature'),\n    tf.keras.layers.Dense(n_hidden, activation=tf.nn.relu, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const)),\n    tf.keras.layers.Dense(1, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const))\n])\nmodel.summary()\n\nstart_time = time.time()\n# Compile, train, and evaluate.\nmodel.compile(optimizer='adam',\n              loss='mean_squared_error',\n              metrics=['mse'])\nhistory = model.fit(X_train, y_train, epochs=300, validation_split=0.3)\nmodel.evaluate(X_test, y_test)\n\n\n# ----------------------------- Overfitting? --------------------\ntrain_acc = model.evaluate(X_train, y_train, verbose=0)[-1]\ntest_acc = model.evaluate(X_test, y_test, verbose=0)[-1]\nprint(\"--- %s seconds ---\" % (time.time() - start_time))\nprint('Train: %.3f, Test: %.3f' % (train_acc, test_acc))\n\nplt.plot(history.history['loss'], label='Train')\nplt.plot(history.history['val_loss'], label='Validation')\nplt.legend()\nplt.grid()\nplt.ylabel('Loss')\nplt.xlabel('Epochs')\nplt.ylim(0, 200)\nplt.savefig('figure_Boston_NN_1hidden_wd_loss.pdf')\nplt.show()\n\n\\end{lstlisting}\nwhere the network with no hidden layers are produced by removing the line \\begin{lstlisting}\ntf.keras.layers.Dense(n_hidden, activation=tf.nn.relu, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const))\n\\end{lstlisting}\nand the network with 1 hidden layer and no regularization is produced by removing the regularization arguments \\texttt{kernel\\_regularizer} and \\texttt{bias\\_regularizer} in \n\\begin{lstlisting}\ntf.keras.layers.Dense(n_hidden, activation=tf.nn.relu, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const)),\n    tf.keras.layers.Dense(1, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const))\n\\end{lstlisting}\n\n\n\n\n\\section{Python code for the Bayesian neural networks in table \\ref{tab:Boston_BNN_performance}} \\label{app:Boston_BNN}\nThe Bayesian neural network with hierarchical model is implemented by the following code\n\\begin{lstlisting}\n# # ----------------------------- IMPORTS -----------------------\nimport sys\nimport time\nfrom keras.datasets import boston_housing\nfrom sklearn import metrics\nimport numpy as np \nimport pymc3 as pm\nimport theano\nimport arviz as az\nfrom arviz.utils import Numba\nimport theano.tensor as tt\nNumba.disable_numba()\nNumba.numba_flag\nfloatX = theano.config.floatX\nimport seaborn as sns\nsns.set_style(\"white\")\nimport tensorflow as tf\n\n\n# Ignore warnings - NUTS provide many runtimeWarning\nimport warnings\nwarnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n\ntf.random.set_seed(42)\n# # ----------------------------- Loading Boston data --------------\n(X_train, y_train), (X_test, y_test) = boston_housing.load_data(seed=3030)\n\n#pad Xs with 1's to add bias\nones_train=np.ones(X_train.shape[0])\nones_test=np.ones(X_test.shape[0])\nX_train=np.insert(X_train,0,ones_train,axis=1)\nX_test=np.insert(X_test,0,ones_test,axis=1)\n\n\n# # ----------------------------- Implementing a BNN function -----\n\ndef construct_bnn(ann_input, ann_output, n_hidden):\n    # Initialize random weights between each layer\n    init_1 = np.random.randn(X_train.shape[1], n_hidden).astype(floatX)*.1\n    init_out = np.random.randn(n_hidden,1).astype(floatX)*.1\n    with pm.Model() as bayesian_neural_network:\n        ann_input = pm.Data(\"ann_input\", X_train)\n        ann_output = pm.Data(\"ann_output\", y_train)\n      \n    # prior on hyper parameters for weight 1\n        #mu1 = pm.Normal('mu1',shape=(X_train.shape[1], n_hidden), mu=0, sigma=1)\n        mu1 = pm.Cauchy('mu1',shape=(X_train.shape[1], n_hidden), alpha=0, beta=1)\n        sigma1 = pm.HalfNormal('sigma1',shape=(X_train.shape[1], n_hidden), sigma=1) \n        \n    # Input -> Layer 1\n        weights_1 = pm.Normal('w_1', mu=mu1, sd=sigma1,\n                          shape=(X_train.shape[1], n_hidden),\n                          testval=init_1)\n        acts_1 = pm.Deterministic('activations_1', tt.nnet.relu(tt.dot(ann_input, weights_1)))\n    \n    # prior on hyper parameters for weight_out \n        mu_out = pm.Cauchy('mu_out',shape=(n_hidden, 1), alpha=0, beta=1)\n        sigma_out = pm.HalfNormal('sigma_out',shape=(n_hidden, 1), sigma=1) \n    \n    # Layer 1 -> Output Layer\n        weights_out = pm.Normal('w_out', mu=mu_out, sd=sigma_out,\n                            shape=(n_hidden, 1),\n                            testval=init_out)\n        acts_out = pm.Deterministic('activations_out',tt.dot(acts_1, weights_out))\n        \n\n    #Define likelihood\n        out = pm.Normal('out', mu=acts_out[:,0], sd=1, observed=ann_output)        \n            \n    return bayesian_neural_network\n\n\n# # ---------------- Sampling from posterior ---------\n# Start time\ntic = time.perf_counter() # for timing\nbayesian_neural_network_NUTS = construct_bnn(X_train, y_train, n_hidden=10)\n\n# Sample from the posterior using the NUTS samplper\nwith bayesian_neural_network_NUTS:\n    trace = pm.sample(draws=3000, tune=1000, chains=3,target_accept=.90)\n    \n\n# # ------------------ Making predictions on training data ---------\nppc1=pm.sample_posterior_predictive(trace, model=bayesian_neural_network_NUTS)\n\n# Taking the mean over all samples to generate a prediction\ny_train_pred = ppc1['out'].mean(axis=0)\n\n\n# Replace shared variables with testing set\npm.set_data(new_data={\"ann_input\": X_test, \"ann_output\": y_test}, model=bayesian_neural_network_NUTS)\n\n\n\n# # ---------------- Making predictions on test data ------\nppc2 = pm.sample_posterior_predictive(trace, model=bayesian_neural_network_NUTS)\n\n# Taking the mean over all samples to generate a prediction\ny_test_pred = ppc2['out'].mean(axis=0)\n\n# End time\ntoc = time.perf_counter()\nprint(f\"Run time {toc - tic:0.4f} seconds\")\n\n# Printing the performance measures\nprint('MSE (NUTS) on training data:', metrics.mean_squared_error(y_train, y_train_pred))\nprint('MSE (NUTS) on test data:', metrics.mean_squared_error(y_test, y_test_pred))\n\n\\end{lstlisting}\nThe Bayesian neural network with one hidden layer is implemented by the following code\n\\begin{lstlisting}\n# # ----------------------------- IMPORTS -------------------\nimport sys\nimport time\nfrom keras.datasets import boston_housing\nfrom sklearn import metrics\nimport numpy as np \nimport pymc3 as pm\nimport theano\nimport arviz as az\nfrom arviz.utils import Numba\nimport theano.tensor as tt\nNumba.disable_numba()\nNumba.numba_flag\nfloatX = theano.config.floatX\n# seaborn for vizualzing \nimport seaborn as sns\nsns.set_style(\"white\")\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\n# # ----------------------------- Print versions -------------\n\nprint(\"Running on Python version %s\" % sys.version)\nprint(f\"Running on PyMC3 version{pm.__version__}\")\nprint(\"Running on Theano version %s\" % theano.__version__)\nprint(\"Running on Arviz version %s\" % az.__version__)\nprint(\"Running on Numpy version %s\" % np.__version__)\n\n# Ignore warnings - NUTS provide many runtimeWarning\nimport warnings\nwarnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n\ntf.random.set_seed(42)\n# # ----------------------------- Loading Boston data ------------\n(X_train, y_train), (X_test, y_test) = boston_housing.load_data(seed=3030)\n\n#pad Xs with 1's to add bias\nones_train=np.ones(X_train.shape[0])\nones_test=np.ones(X_test.shape[0])\nX_train=np.insert(X_train,0,ones_train,axis=1)\nX_test=np.insert(X_test,0,ones_test,axis=1)\n\n\n# # ----------------------------- Implementing a BNN function ------\n\ndef construct_bnn(ann_input, ann_output, n_hidden, prior_std):\n    # Initialize random weights between each layer\n    init_1 = np.random.randn(X_train.shape[1], n_hidden).astype(floatX)*prior_std\n    init_out = np.random.randn(n_hidden,1).astype(floatX)*prior_std\n\n    with pm.Model() as bayesian_neural_network:\n        ann_input = pm.Data(\"ann_input\", X_train)\n        ann_output = pm.Data(\"ann_output\", y_train)\n        \n    # Input -> Layer 1\n        weights_1 = pm.Normal('w_1', mu=0, sd=prior_std,\n                          shape=(X_train.shape[1], n_hidden),\n                          testval=init_1)\n        acts_1 = tt.nnet.relu(tt.dot(ann_input, weights_1))\n\n    # Layer 1 -> Output Layer\n        weights_out = pm.Normal('w_out', mu=0, sd=prior_std,\n                            shape=(n_hidden, 1),\n                            testval=init_out)\n        acts_out = tt.dot(acts_1, weights_out)\n        \n\n    #Define likelihood\n        out = pm.Normal('out', mu=acts_out[:,0], sd=1, observed=ann_output)        \n            \n    return bayesian_neural_network\n\n\n# # ----------------------------- Sampling from posterior -------\n# Start time\ntic = time.perf_counter() # for timing\nbayesian_neural_network_NUTS = construct_bnn(X_train, y_train, n_hidden=10, prior_std=.1)\n\n# Sample from the posterior using the NUTS samplper\nwith bayesian_neural_network_NUTS:\n    trace = pm.sample(draws=3000, tune=1000, chains=3,target_accept=.9, random_seed=42)\n    \n\n# # ------------------ Making predictions on training data --------\nppc1=pm.sample_posterior_predictive(trace, model=bayesian_neural_network_NUTS, random_seed=42)\n\n# Taking the mean over all samples to generate a prediction\ny_train_pred = ppc1['out'].mean(axis=0)\n\n\n# Replace shared variables with testing set\npm.set_data(new_data={\"ann_input\": X_test, \"ann_output\": y_test}, model=bayesian_neural_network_NUTS)\n\n\n\n# # ------------------- Making predictions on test data ------\nppc2 = pm.sample_posterior_predictive(trace, model=bayesian_neural_network_NUTS, random_seed=42)\n\n# Taking the mean over all samples to generate a prediction\ny_test_pred = ppc2['out'].mean(axis=0)\n\n# End time\ntoc = time.perf_counter()\nprint(f\"Run time {toc - tic:0.4f} seconds\")\n\n# Printing the performance measures\nprint('MSE (NUTS) on training data:', metrics.mean_squared_error(y_train, y_train_pred))\nprint('MSE (NUTS) on test data:', metrics.mean_squared_error(y_test, y_test_pred))\n\n\n# -------------------------------- Plots --------------------\n# Vizualize uncertainty\n# Define examples for which you want to examine the posterior predictive:\nexample_vec=np.array([1,2,4,9,10,11,15,16,22,24,27,28,30,44,55,62,68,72,84,93])\nfor example in example_vec:\n    plt_hist_array=np.array(ppc2['out'])\n    plt.hist(plt_hist_array[:,example], density=1, color=\"lightsteelblue\", bins=30)\n    plt.xlabel(f\"Predicted value for example {example}\",fontsize=13)\n    plt.ylabel(\"Density\",fontsize=13)\n    plt.savefig(f'Python_code/Boston_BNN_1hidden_postpred_{example}.pdf')\n    plt.show()\n\\end{lstlisting}\nwhere the network with no hidden layers is implemented by replacing the lines\n\\begin{lstlisting}\n# Input -> Layer 1\n    weights_1 = pm.Normal('w_1', mu=0, sd=prior_std,\n                    shape=(X_train.shape[1], n_hidden),\n                    testval=init_1)\n    acts_1 = tt.nnet.relu(tt.dot(ann_input, weights_1))\n\n# Layer 1 -> Output Layer\n    weights_out = pm.Normal('w_out', mu=0, sd=prior_std,\n                    shape=(n_hidden, 1),\n                    testval=init_out)\n    acts_out = tt.dot(acts_1, weights_out)\n\\end{lstlisting}\nwith\n\\begin{lstlisting}\n # Input layer -> Output layer\n        weights_out = pm.Normal('w_out', mu=0, sd=prior_std,\n        shape=(X_train.shape[1], 1), testval=init_out)\n    acts_out = pm.Deterministic(\n        'activations_out', tt.dot(ann_input, weights_out))\n\\end{lstlisting}\n\n\n\\section{Python code for the neural networks in table \\ref{tab:credit_NN_performance}} \\label{app:Credit_NN}\nThe neural network with early stopping is performed using the code\n\\begin{lstlisting}\n import time\nimport tensorflow as tf\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nimport seaborn as sns\n\ntf.random.set_seed(40)\n# ----------------------------- Prepare data -------------------\ncredit_data = pd.read_csv(\n    \"Python_code/data/UCI_Credit_Card.csv\", encoding=\"utf-8\", index_col=0)\ncredit_data.head()\n\n# Data to numpy\ndata = np.array(credit_data)\n\n# Extract labels\ndata_X = data[:, 0:23]\ndata_y = data[:, 23]\n\n\n# # -------------------------- Subsamling credit data -------\nX_train, X_test, y_train, y_test = train_test_split(\n    data_X, data_y, test_size=0.30, random_state=3030)\n\nN = 300\nN_test = 100\nX_train = X_train[0:N, :]\ny_train = y_train[0:N]\nX_test = X_test[0:N_test, :]\ny_test = y_test[0:N_test]\n\n\n# ------------------------- Neural Network ---------------\n\nmodel = tf.keras.Sequential([\n    tf.keras.Input((23, ), name='feature'),\n    tf.keras.layers.Dense(10, activation=tf.nn.tanh),\n    tf.keras.layers.Dense(1, activation=tf.nn.sigmoid)\n])\nmodel.summary()\n\n# Early stopping\nes = tf.keras.callbacks.EarlyStopping(\n    monitor='val_loss', mode='min', patience=0, min_delta=0)\n\nstart_time = time.time()\n\n# Compile, train, and evaluate.\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['binary_crossentropy'])\nhistory = model.fit(X_train, y_train,  validation_split=0.3,\n                    epochs=1000, callbacks=[es])\nprint(\"The algorithm ran\", len(history.history['loss']), \"epochs\")\n\nprint(\"--- %s seconds ---\" % (time.time() - start_time))\n\n\n# ------------------------- Overfitting? ----------------\ntrain_acc = model.evaluate(X_train, y_train, verbose=0)[-1]\ntest_acc = model.evaluate(X_test, y_test, verbose=0)[-1]\nprint('Train: %.3f, Test: %.3f' % (train_acc, test_acc))\n\n# taking mean of summed cross-entropy loss\ntrain_loss = np.array(history.history['loss'])\nval_loss = np.array(history.history['val_loss'])\n\nplt.plot(train_loss, label='train')\nplt.plot(val_loss, label='validation')\nplt.legend()\nplt.grid()\nplt.show()\n\n\\end{lstlisting}\nThe networks not using early stopping and their visualization of train and validation loss in figure \\ref{fig:Credit_NN_nohidden_wd_loss}, \\ref{fig:Credit_NN_1hidden_wd_loss} and figure \\ref{fig:Credit_NN_1hidden_noreg_loss} are produced using the code\n\\begin{lstlisting}\nfrom keras.regularizers import l2\nimport time\nimport tensorflow as tf\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nimport seaborn as sns\nstart_time = time.time()\ntf.random.set_seed(40)\n\n# ----------------------------- Prepare data ----------------\ncredit_data = pd.read_csv(\n    \"Python_code/data/UCI_Credit_Card.csv\", encoding=\"utf-8\", index_col=0)\ncredit_data.head()\n\n# Data to numpy\ndata = np.array(credit_data)\n\n# Extract labels\ndata_X = data[:, 0:23]\ndata_y = data[:, 23]\n\n# # ----------------------------- Subsamling credit data ------\nX_train, X_test, y_train, y_test = train_test_split(\n    data_X, data_y, test_size=0.30, random_state=3030)\n\nN = 300\nN_test = 100\nX_train = X_train[0:N, :]\ny_train = y_train[0:N]\nX_test = X_test[0:N_test, :]\ny_test = y_test[0:N_test]\n\n# ----------------------------- Neural Network ----------------\nreg_const = 0.1\nn_hidden = 10\n\nmodel = tf.keras.Sequential([\n    tf.keras.Input((23, ), name='feature'),\n    tf.keras.layers.Dense(n_hidden, activation=tf.nn.tanh, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const)),\n    tf.keras.layers.Dense(1, activation=tf.nn.sigmoid, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const))\n])\nmodel.summary()\n\n# Compile, train, and evaluate.\nval_ratio = 0.3\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['binary_crossentropy'])\nhistory = model.fit(X_train, y_train, epochs=1000,\n                    validation_split=val_ratio)\n\nmodel.evaluate(X_test, y_test)\n\nprint(\"--- %s seconds ---\" % (time.time() - start_time))\n\n\n# ----------------------------- Overfitting? ----------------\n\ntrain_acc = model.evaluate(X_train, y_train, verbose=0)[-1]\ntest_acc = model.evaluate(X_test, y_test, verbose=0)[-1]\nprint('Train: %.3f, Test: %.3f' % (train_acc, test_acc))\n\n# taking mean of summed cross-entropy loss\ntrain_loss = np.array(history.history['loss'])\nval_loss = np.array(history.history['val_loss'])\n\nplt.plot(train_loss, label='train')\nplt.plot(val_loss, label='validation')\nplt.legend()\nplt.grid()\nplt.ylim(0.4, 1)\nplt.savefig('Python_code/figure_Credit_NN_1hidden_wd_loss.pdf')\nplt.show()\n\n\\end{lstlisting}\nwhere the network with no hidden layers are produced by removing the line\n\\begin{lstlisting}\n tf.keras.layers.Dense(n_hidden, activation=tf.nn.tanh, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const)),\n\\end{lstlisting}\nand the network with 1 hidden layer and no regularization is produced by removing the regularization arguments \\texttt{kernel\\_regularizer} and \\texttt{bias\\_regularizer} in \n\\begin{lstlisting}\ntf.keras.layers.Dense(n_hidden, activation=tf.nn.tanh, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const)),\ntf.keras.layers.Dense(1, activation=tf.nn.sigmoid, kernel_regularizer=l2(\n        reg_const), bias_regularizer=l2(reg_const))\n\\end{lstlisting}\n\n\\section{Python code for the Bayesian neural networks in table \\ref{tab:credit_BNN_performance}} \\label{app:Credit_BNN}\nThe Bayesian neural network with hierarchical model is implemented by the following code\n\\begin{lstlisting}\n# # ----------------------------- IMPORTS -----------------\nimport warnings\nfrom sklearn.metrics import accuracy_score, log_loss\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport tensorflow as tf\nimport sys\nimport time\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nimport pandas as pd\nimport pymc3 as pm\nimport theano\nimport arviz as az\nfrom arviz.utils import Numba\nimport theano.tensor as tt\nfrom scipy.stats import mode\nNumba.disable_numba()\nNumba.numba_flag\nfloatX = theano.config.floatX\nsns.set_style(\"white\")\n\n\n# # ----------------------------- Print versions -----------------\nprint(\"Running on Python version %s\" % sys.version)\nprint(f\"Running on PyMC3 version{pm.__version__}\")\nprint(\"Running on Theano version %s\" % theano.__version__)\nprint(\"Running on Arviz version %s\" % az.__version__)\nprint(\"Running on Numpy version %s\" % np.__version__)\n\n# Ignore warnings - NUTS provide many runtimeWarning\nwarnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n\ntf.random.set_seed(42)\n\n\n# # ----------------------------- Loading credit data ---\ncredit_data = pd.read_csv(\"Python_code/data/UCI_Credit_Card.csv\",\n                          encoding=\"utf-8\", index_col=0, delimiter=\",\")\ncredit_data.head()\n# Data to numpy\ndata = np.array(credit_data)\n# seperating labels from features\ndata_X = data[:, 0:23]\ndata_y = data[:, 23]\n\n\n# # ----------------------------- Subsamling credit data --------\nX_train, X_test, y_train, y_test = train_test_split(\n    data_X, data_y, test_size=0.30, random_state=3030)\n\nN = 300\nN_test = 100\nX_train = X_train[0:N, :]\ny_train = y_train[0:N]\nX_test = X_test[0:N_test, :]\ny_test = y_test[0:N_test]\n\n\n# pad Xs with 1's to add bias\nones_train = np.ones(X_train.shape[0])\nones_test = np.ones(X_test.shape[0])\nX_train = np.insert(X_train, 0, ones_train, axis=1)\nX_test = np.insert(X_test, 0, ones_test, axis=1)\n\n# # ----------------------------- Implementing a BNN function -----\n\n\ndef construct_bnn(ann_input, ann_output, n_hidden):\n\n    with pm.Model() as bayesian_neural_network:\n        ann_input = pm.Data(\"ann_input\", X_train)\n        ann_output = pm.Data(\"ann_output\", y_train)\n\n        # prior on hyper parameters for weight 1\n        mu1 = pm.Cauchy('mu1', shape=(\n            X_train.shape[1], n_hidden), alpha=0, beta=1)\n        sigma1 = pm.HalfNormal('sigma1', shape=(\n            X_train.shape[1], n_hidden), sigma=1)\n\n        # Weights from input to hidden layer\n        weights_in_1 = pm.Normal(\n            \"w_in_1\", mu1, sigma1, shape=(X_train.shape[1], n_hidden))\n\n        # prior on hyper parameters for weight_out\n        mu_out = pm.Cauchy('mu_out', shape=(n_hidden, 1), alpha=0, beta=1)\n        sigma_out = pm.HalfNormal('sigma_out', shape=(n_hidden, 1), sigma=1)\n        # Weights from hidden layer to output\n        weights_1_out = pm.Normal(\n            \"weights_out\", mu_out, sigma=sigma_out, shape=(n_hidden, 1))\n\n        # Build neural-network using tanh activation function\n        act_1 = pm.math.tanh(pm.math.dot(ann_input, weights_in_1))\n\n        output = pm.Deterministic(\n            \"output\", pm.math.sigmoid(tt.dot(act_1, weights_1_out)))\n\n        # Binary classification -> Bernoulli likelihood\n        out = pm.Bernoulli(\n            \"out\",\n            output,\n            observed=ann_output,\n            total_size=y_train.shape[0],\n        )\n\n    return bayesian_neural_network\n\n\n# # ----------------------------- Sampling from posterior --------\ntic = time.time()  # for timing\nbayesian_neural_network_NUTS = construct_bnn(X_train, y_train, n_hidden=10)\n\n# Sample from the posterior using the NUTS samplper\ndraws = 1500\ntune = 10**3\nchains = 3\ntarget_accept = .9\nwith bayesian_neural_network_NUTS:\n    trace = pm.sample(draws=draws, tune=tune, chains=chains,\n                      target_accept=target_accept)\n\n\ny_train_pred = (trace[\"output\"]).mean(axis=0)\n\n\n# Replace shared variables with testing set\npm.set_data(new_data={\"ann_input\": X_test, \"ann_output\": y_test},\n            model=bayesian_neural_network_NUTS)\n\nppc2 = pm.sample_posterior_predictive(\n    trace, var_names=[\"output\"], model=bayesian_neural_network_NUTS)\ny_test_pred = (ppc2[\"output\"]).mean(axis=0)\n\n# y_test_pred = np.append(y_test_pred,1-y_test_pred,axis=1)\n\n# end time\ntoc = time.time()\nprint(f\"Running MCMC completed in {toc - tic:} seconds\")\n\n# Printing the performance measures\nprint('Cross-entropy loss on train data = {}'.format(log_loss(y_train, y_train_pred)))\nprint('Cross-entropy loss on test data = {}'.format(log_loss(y_test, y_test_pred)))\n\n\\end{lstlisting}\nThe Bayesian neural network with one hidden layer is implemented by the following code\n\\begin{lstlisting}\n# # ----------------------------- IMPORTS ------------------\nimport warnings\nfrom sklearn.metrics import accuracy_score, log_loss\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport tensorflow as tf\nimport sys\nimport time\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nimport pandas as pd\nimport pymc3 as pm\nimport theano\nimport arviz as az\nfrom arviz.utils import Numba\nimport theano.tensor as tt\nfrom scipy.stats import mode\nNumba.disable_numba()\nNumba.numba_flag\nfloatX = theano.config.floatX\nsns.set_style(\"white\")\n\n\n# # ----------------------------- Print versions -----------------\nprint(\"Running on Python version %s\" % sys.version)\nprint(f\"Running on PyMC3 version{pm.__version__}\")\nprint(\"Running on Theano version %s\" % theano.__version__)\nprint(\"Running on Arviz version %s\" % az.__version__)\nprint(\"Running on Numpy version %s\" % np.__version__)\n\n# Ignore warnings - NUTS provide many runtimeWarning\nwarnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n\ntf.random.set_seed(42)\n\n\n# # ----------------------------- Loading credit data ------\ncredit_data = pd.read_csv(\"Python_code/data/UCI_Credit_Card.csv\",\n                          encoding=\"utf-8\", index_col=0, delimiter=\",\")\ncredit_data.head()\n# Data to numpy\ndata = np.array(credit_data)\n# seperating labels from features\ndata_X = data[:, 0:23]\ndata_y = data[:, 23]\n\n\n# # ----------------------------- Subsamling credit data -----\nX_train, X_test, y_train, y_test = train_test_split(\n    data_X, data_y, test_size=0.30, random_state=3030)\n\nN = 300\nN_test = 100\nX_train = X_train[0:N, :]\ny_train = y_train[0:N]\nX_test = X_test[0:N_test, :]\ny_test = y_test[0:N_test]\n\n\n# pad Xs with 1's to add bias\nones_train = np.ones(X_train.shape[0])\nones_test = np.ones(X_test.shape[0])\nX_train = np.insert(X_train, 0, ones_train, axis=1)\nX_test = np.insert(X_test, 0, ones_test, axis=1)\n\n\n# # ----------------------------- Implementing a BNN function -----\ndef construct_bnn(ann_input, ann_output, n_hidden, prior_std):\n\n    with pm.Model() as bayesian_neural_network:\n        ann_input = pm.Data(\"ann_input\", X_train)\n        ann_output = pm.Data(\"ann_output\", y_train)\n\n        # Weights from input to hidden layer\n        weights_in_1 = pm.Normal(\n            \"w_in_1\", 0, sigma=prior_std, shape=(X_train.shape[1], n_hidden))\n\n        # Weights from hidden layer to output\n        weights_1_out = pm.Normal(\n            \"weights_out\", 0, sigma=prior_std, shape=(n_hidden, 1))\n\n        # Build neural-network using tanh activation function\n        act_1 = pm.math.tanh(pm.math.dot(ann_input, weights_in_1))\n        output = pm.Deterministic(\n            \"output\", pm.math.sigmoid(tt.dot(act_1, weights_1_out)))\n\n        # Binary classification -> Bernoulli likelihood\n        out = pm.Bernoulli(\n            \"out\",\n            output,\n            observed=ann_output,\n            total_size=y_train.shape[0],  # IMPORTANT for minibatches\n        )\n\n    return bayesian_neural_network\n\n\n# # ------------------ Sampling from posterior -----\ntic = time.time()  # for timing\nbayesian_neural_network_NUTS = construct_bnn(\n    X_train, y_train, n_hidden=10, prior_std=1)\n\n# Sample from the posterior using the NUTS samplper\ndraws = 1500\ntune = 10**3\nchains = 3\ntarget_accept = .9\nwith bayesian_neural_network_NUTS:\n    trace = pm.sample(draws=draws, tune=tune, chains=chains,\n                      target_accept=target_accept)\n\n\ny_train_pred = (trace[\"output\"]).mean(axis=0)\n\n# Replace shared variables with testing set\npm.set_data(new_data={\"ann_input\": X_test, \"ann_output\": y_test},\n            model=bayesian_neural_network_NUTS)\n\nppc2 = pm.sample_posterior_predictive(\n    trace, var_names=[\"output\"], model=bayesian_neural_network_NUTS)\ny_test_pred = (ppc2[\"output\"]).mean(axis=0)\n\n\n# end time\ntoc = time.time()\nprint(f\"Running MCMC completed in {toc - tic:} seconds\")\n\n# Printing the performance measures\nprint('Cross-entropy loss on train data = {}'.format(log_loss(y_train, y_train_pred)))\nprint('Cross-entropy loss on test data = {}'.format(log_loss(y_test, y_test_pred)))\n\n\n# Vizualize uncertainty\n# Define examples for which you want to examine the posterior predictive:\nexample_vec = np.array([5, 11, 25, 88])\nfor example in example_vec:\n    plt_hist_array = np.array(ppc2['output'])\n    plt.hist(plt_hist_array[:, example], density=1,\n             color=\"lightsteelblue\", bins=30)\n    plt.xlabel(f\"Predicted probability for example {example}\", fontsize=13)\n    plt.ylabel(\"Density\", fontsize=13)\n    plt.savefig(f'Python_code/Credit_BNN_1hidden_postpred_{example}.pdf')\n    plt.show()\n\n\\end{lstlisting}\nwhere the network with no hidden layers is implemented by replacing the lines\n\\begin{lstlisting}\n # Weights from input to hidden layer\n        weights_in_1 = pm.Normal(\n            \"w_in_1\", 0, sigma=prior_std, shape=(X_train.shape[1], n_hidden))\n\n# Weights from hidden layer to output\n    weights_1_out = pm.Normal(\n            \"weights_out\", 0, sigma=prior_std, shape=(n_hidden, 1))\n\n# Build neural-network using tanh activation function\n    act_1 = pm.math.tanh(pm.math.dot(ann_input, weights_in_1))\n    output = pm.Deterministic(\n            \"output\", pm.math.sigmoid(tt.dot(act_1, weights_1_out)))\n\\end{lstlisting}\nwith \n\\begin{lstlisting}\n # Weights from hidden layer to output\n        weights_in_out = pm.Normal(\"weights_out\", 0, sigma=prior_std, shape=(X_train.shape[1],1))\n\n        # Build neural-network using tanh activation function\n        output = pm.Deterministic(\"output\", pm.math.sigmoid(tt.dot(ann_input, weights_in_out)))\n\\end{lstlisting}\n\n\n\n\n\n\n\\end{appendices}\n", "meta": {"hexsha": "a52587c48755c4de01fc095277eb71e649e03890", "size": 39194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix.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": "appendix.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": "appendix.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": 33.7007738607, "max_line_length": 259, "alphanum_fraction": 0.6707404195, "num_tokens": 10243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6886017893468674}}
{"text": "\\subsection{Generating functions}\n\n\\subsubsection{Definition}\n\nA series can be described as:\n\n\\(\\sum_{i=0}^{\\infty }s_i x^i\\)\n\nIf we know the function equal to this series, we can identify the \\(i\\)th number.\n\n", "meta": {"hexsha": "390c8e5488e5f2a9385662d6f9e92f43572ea8f0", "size": 210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/generating/01-01-generating.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/generating/01-01-generating.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/generating/01-01-generating.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.0909090909, "max_line_length": 81, "alphanum_fraction": 0.7238095238, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347124, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6885455204343622}}
{"text": "%!TEX root = ../thesis.tex\n% ******************************* Thesis Appendix A ****************************\n\\chapter{Spherical Harmonics on Hyperspheres} \n\\label{appendix:spherical-harmonics}\n\nSpherical harmonics are a special set of functions defined on the hypersphere and play a central role in harmonic analysis and approximation theory \\citep{wendland2005}. They originate from solving Laplace's equation, and form a complete set of orthogonal functions. Any sufficiently regular function defined on the sphere can be written as a sum of these spherical harmonics, similar to the Fourier series with sines and cosines. Spherical harmonics are defined in arbitrary dimensions \\citep{frye2014,dai2013}, but lack explicit formulations and practical implementations in dimensions larger than three. %This is mainly due to the complexity of solving Laplace's equation in higher dimensions.\n\nIn this section, we propose a novel algorithm to construct spherical harmonics in $d$ dimensions. The algorithm is based on the existence of a fundamental system of points on the hypersphere, which we select in a greedy fashion through optimisation. This result in spherical harmonics that are a linear combination of zonal functions and form an ortho-normal basis on $\\dsphere$. The algorithm lends itself well for implementation in Python and TensorFlow, which we provide at: \\url{https://github.com/vdutor/SphericalHarmonics}. The code is accompanied by a series of tests that show that the properties of spherical harmonics, as detailed below, hold. Before outlining the algorithm, we briefly define and cover the important properties of spherical harmonics in $\\Reals^d$. We refer the interested reader to \\citet{dai2013,frye2014} for a comprehensive overview.\n% exist bases of spherical harmonics consisting of entirely zonal harmonics\n\nWe adopt the usual $L_2$ inner product for functions $f: \\dsphere \\rightarrow \\Reals$ and $g: \\dsphere \\rightarrow \\Reals$ restricted to the sphere \n\\begin{equation}\n     \\langle f, g\\rangle_{L_{2}(\\dsphere)} = \\frac{1}{\\darea} \\int_{\\dsphere} f(x)\\,g(x) \\, \\calcd{\\omega},\n\\end{equation}\nwhere $\\calcd{\\omega(x)}$ is the surface area measure such that $\\darea$ denotes the surface area of $\\dsphere$ \n\\begin{equation}\n\\label{eq:surface}\n    \\darea = \\int_{\\dsphere} \\calcd{\\omega(x)} = \\frac{2 \\pi ^ {d/2}}{\\Gamma(d/2)}.\n\\end{equation}\n\nThroughout this section we use the following notation and definitions. For $x = (x_1, \\ldots, x_d) \\in \\Reals^d$ and $\\alpha = (\\alpha_1, \\ldots, \\alpha_d) \\in \\Naturals^d$, a monomial $x^\\alpha$ is a product $x^\\alpha = x_1^{\\alpha_1} \\ldots x_d^{\\alpha_d}$, which has degree $|\\alpha| = \\alpha_1 + \\ldots \\alpha_d$. A real homogeneous polynomial $P(x)$ of degree $n$ is a linear combination of monomials of degree $n$ with real coefficients, that is $P(x) = \\sum_{|\\alpha| = n} c_{\\alpha} x^{\\alpha}$, with $c_\\alpha \\in \\Reals$. We denote $\\mathcal{P}_n^d$ as the space of real homogeneous polynomials of degree $n$, and can show that, counting the cardinality of the set $\\{\\alpha \\in \\Naturals^d: |\\alpha| = n\\}$, that $\\dim(\\mathcal{P}_n^d) = \\binom{n + d -1}{n}$. A function $f:\\Reals^d \\rightarrow \\Reals$ is said to be \\emph{harmonic} if $\\Delta f = 0$, where $\\Delta = \\partial_{x_1}^2 + \\ldots + \\partial_{x_d}^2$ and $\\partial_{x_i}$ the partial derivate w.r.t. the $i$-th variable.\n\n\\begin{definition}\n    The spherical harmonics of degree $n$ of $d$ variables, denoted by $\\mathcal{H}_{n}^d$, is the linear space of harmonic and homogeneous in degree $n$ polynomials on $\\dsphere$, that is \n    \\begin{equation}\n        \\mathcal{H}_{n}^d = \\{p \\in \\mathcal{P}_n^d: \\Delta p = 0\\ \\text{and}\\ p: \\dsphere \\rightarrow \\Reals \\}.\n    \\end{equation}\nThe dimensionality of $ \\mathcal{H}_{n}^d$ is given by\n\\begin{equation}\n\\label{eq:numharmonics}\n\\dim(\\mathcal{H}_{n}^d) = \\frac{2 n + d - 2}{n} \\binom{n + d - 3}{d - 1} := \\dnumharmonicsforlevel.\n\\end{equation}\n\\end{definition}\n\nThe space $\\mathcal{H}_{n}^d$ has an orthonormal basis consisting of $\\dnumharmonicsforlevel$ functions, denoted by $\\{\\phi_{n,j}\\}_{j=1}^{\\dnumharmonicsforlevel}$. The basis satisfy the following properties\n\\begin{equation}\n    \\mathcal{H}_{n}^d  = \\textrm{span}\\left(\\phi_{n,1}, \\ldots, \\phi_{n, \\dnumharmonicsforlevel}\\right),\\quad\\text{and}\\quad\\left\\langle \\phi_{n, j}, \\phi_{n', j'}\\right\\rangle_{L_2(\\dsphere)} = \\delta_{n n'} \\delta_{j j'}.\n\\end{equation}\n\nFrom the completeness and orthonormality of the spherical harmonic basis $\\{\\phi_{n,j}\\}_{n=0,j=1}^{\\infty,\\dnumharmonicsforlevel}$, it can be shown that they also form a basis of square-integrable functions \\citep{frye2014}. This means that we can decompose a function $f: \\dsphere \\rightarrow \\Reals$ as\n\\begin{equation}\n    f = \\sum_{n=0}^{\\infty} \\sum_{j=1}^{\\dnumharmonicsforlevel} \\widehat{f}_{n, j} \\phi_{n, j},\\quad\\text{with}\\quad\\widehat{f}_{n, j} = \\langle f, \\phi_{n, j} \\rangle_{L_2(\\dsphere)},\n\\end{equation}\nwhich can be seen as the spherical analogue of the Fourier decomposition of periodic functions onto a basis of sines and cosines.\n\nSubsequently, we will coin the set $\\{\\phi_{n,j}\\}$ as the spherical harmonics. They are indexed by $n$ and $j$, where $n=0,1,2,\\ldots$ denotes the degree (or level) and $j=1,\\cdots,\\dnumharmonicsforlevel$ denotes the orientation of the spherical harmonic. We are interested in finding $\\{\\phi_{n,j}\\}$ in arbitrary dimension. For $d=2$, is solving Laplace's equation ($\\Delta p = 0$) directly relatively straightforward. Doing so reveals that $N^{2}_0 = 1$ with $\\phi_{0, 1} = 1$ and $N^{2}_n = 2$ for all $n > 0$ with $\\phi_{n, 1}(\\theta) = \\sqrt{2} \\cos(n \\theta)$ and $\\phi_{n, 2}(\\theta) = \\sqrt{2} \\sin(n \\theta)$. This shows that on the unit circle $\\sphere^1$, the spherical harmonics correspond to the Fourier basis. For $d=3$, we can also directly solve Laplace's diffential equation to find $\\dnumharmonicsforlevel = 2n + 1$ and a closed form solution for $\\{\\phi_{n,j}\\}$. However, for $d > 3$, explicit formulations for the spherical harmonics become very rare. To the best of our knowledge, the only explicit formulation we could find is in \\citet[Theorem~5.1]{dai2013}, which consists of a product over polynomials. This makes the implementation cumbersome and numerically unstable, and only practically useful up to 10 dimensions \\citep{Dutordoir2020spherical}. However, making use of the following two theorems, we can derive another formulation for the basis of spherical harmonics as a sum of polynomials, rather than a product. The connection between spherical harmonics and orthogonal polynomials becomes clear in the next theorem.\n\\begin{theorem}[Addition]\n    \\label{theorem:addition}\n    Let $\\{\\phi_{n,j}\\}_{j=1}^{\\dnumharmonicsforlevel}$ be an orthonormal basis for the spherical harmonics of degree $n$ and $x,x' \\in \\dsphere$. Then the Gegenbauer polynomial $C_n^{(\\alpha)}: [-1, 1] \\rightarrow \\Reals$ of degree $n$ can be written as\n\\begin{equation}\n    \\sum_{j=1}^{\\dnumharmonicsforlevel} \\phi_{n, j}(x) \\phi _{n, j}(x') = \\frac{n + \\alpha}{\\alpha}\\,\n    C_n^{(\\alpha)}(x\\transpose x')\\quad\\text{with}\\quad \\alpha = \\frac{d-2}{2}.\n\\end{equation}\n\\end{theorem}\nAs a result of the relation between the Gegenbauer polynomial and the spherical harmonics, are the Gegenbauer polynomial sometimes referred to as ultraspherical polynomials. For $d=2$, Theorem~1 recovers the addition formula of the cosine function, as indeed $\\cos(\\theta) \\cos(\\theta') + \\sin(\\theta) \\sin(\\theta') = \\cos(\\theta - \\theta')$ and $C_n^{(0)}(t) = \\cos(n \\arccos(t))$. The Gegenbauer polynomials with $\\alpha=0$ are better known as the Chebyshev polynomials. Another connection between spherical harmonics and Gegenbauer polynomials is given by the Funk-Hecke theorem and applies to zonal functions. A zonal function on $\\dsphere$ is a function that is rotationally invariant w.r.t. to a point on the sphere, $\\eta \\in \\dsphere$. This means that the function only depends on the inner product $\\eta\\transpose x$, or equivalently, on the geodestic distance between $\\eta$ and $x$.\n\n\\begin{theorem}[Funk-Hecke]\n    \\label{appendix:theorem:funk}\n    Let $f$ be an integrable function such that $\\int_{-1}^1 \\| f(t)\\| (1 - t^2)^{(d-3)/2} \\calcd{t}$ is finite and $d \\ge 2$. Then for every $\\phi_{n,j}$  and $\\eta \\in \\dsphere$\n    \\begin{equation}\n        \\frac{1}{\\darea} \\int_{\\dsphere} f(\\eta\\transpose x)\\,\\phi_{n, j}(x)\\, \\calcd{\\omega(x)} = {\\lambda}_{n}\\,\\phi_{n,j}(\\eta),\n    \\end{equation}\n    where ${\\lambda}_{n}$ is a constant defined by\n    \\begin{equation}\n        \\lambda_{n}  = \n        % \\frac{\\Omega_{d-2}}{\\Omega_{d-1}} \n        \\frac{\\omega_{d}}{C_n^{(\\alpha)}(1)} \\int_{-1}^1 f(t)\\,C_n^{(\\alpha)}(t)\\,(1 - t^2)^{\\frac{d-3}{2}} \\calcd{t},\n    \\end{equation}\n    with $\\alpha = \\frac{d-2}{2}$ and $\\omega_d = \\frac{\\Omega_{d-2}}{\\Omega_{d-1}}$.\n\\end{theorem}\n\n\\section{Algorithm: Zonal Spherical Harmonics}\n\\label{sec:zonal-spherical-harmonics}\n\nFrom the Funk-Hecke and the Addition theorem, it is clear that there is a strong connection between spherical harmonics and Gegenbauer polynomials. The next theorem develops this connection further as it states that a basis for spherical harmonics can be written as zonal Gegenbauer polynomials. % , that is $\\phi_{n,j}(x) = \\sum_i \\beta_{j,i} C_n^{(\\alpha)}(\\eta_i\\transpose x)$. In what comes next we show how to select the weights $\\beta_{j,i}$ and zonal directions $\\eta_i \\in \\dsphere$.\n\n\\begin{theorem}\n    If $\\{\\eta_1, \\ldots, \\eta_{\\dnumharmonicsforlevel} \\} \\in \\dsphere$ is a fundamental system of points on the sphere, then $\\{C_n^{(\\alpha)}(\\eta_i \\cdot)\\}_{i=1}^{\\dnumharmonicsforlevel}$ is a basis for $\\mathcal{H}_n^d$. A collection of points $\\{\\eta_1, \\ldots, \\eta_M \\} \\in \\dsphere$ is called a fundamental system of degree $n$ consisting of $M$ points on the sphere if\n    \\begin{equation}\n        \\label{eq:fundamental-system}\n        \\textrm{det}\\ \n        \\begin{bmatrix}\n            C_n^{(\\alpha)}(1) & \\ldots & C_n^{(\\alpha)}(\\eta_1\\transpose\\eta_M) \\\\\n            \\vdots & & \\vdots \\\\\n            C_n^{(\\alpha)}(\\eta_M\\transpose\\eta_1) & \\ldots & C_n^{(\\alpha)}(1)\n        \\end{bmatrix} > 0.\n    \\end{equation}\n\\end{theorem}\nFinding a basis for $\\mathcal{H}_n^d$ is thus equivalent to finding a set of $\\dnumharmonicsforlevel$ points that satisfy \\cref{eq:fundamental-system}. Crucially, \\citet[Lemma~3]{dai2013} show that there always exists a fundamental system of degree $n$ and $\\dnumharmonicsforlevel$ points.\n\nFollowing the theorem, if we wish to construct $\\{\\phi_{n,j}\\}_{n,j}$, an \\emph{ortho-normal} basis for the spherical harmonics, we firstly need a fundamental system of points. Secondly, while $\\{C_n^{(\\alpha)}(\\eta_i \\cdot)\\}_{i=1}^{\\dnumharmonicsforlevel}$ forms a basis for $\\mathcal{H}_n^d$, the basis is not orthonormal. We will thus have to apply a Gram-Schmidt process for ortho-normalising the basis. We detail both steps in the next paragraphs.\n\n\\paragraph{Construction of a fundamental system of points}\nWe propose to build a fundamental system of points in a greedy fashion by repeatedly adding a point on the sphere that maximises the determinant as given in \\cref{eq:fundamental-system}. Therefore, let $\\veta = \\{\\eta_1, \\ldots, \\eta_M\\}$ contain the M points that are already in the fundamental system and define the following block-matrix of size $(M+1) \\times (M+1)$ as\n\\begin{equation}\n    \\renewcommand\\arraystretch{1.3}\n    \\MM(\\veta, \\eta_{*}) =\n    \\left[\n        \\begin{array}{c|c}\n          C_n^{\\alpha}(\\veta\\veta\\transpose) \\in \\Reals^{M \\times M} & C_n^{(\\alpha)}(\\veta\\eta_{*}\\transpose) \\in \\Reals^{M \\times 1} \\\\\n          \\hline\n          C_n^{(\\alpha)}(\\veta\\eta_{*}\\transpose)\\transpose \\in \\Reals^{1 \\times M} & C_n^{(\\alpha)}(1) \\in \\Reals\n        \\end{array}\n    \\right],\n\\end{equation}\nwhere $C_n^{(\\alpha)}(\\veta\\veta\\transpose)$ corresponds to element wise evaluating the Gegenbauer polynomial $C_n^{(\\alpha)}: [-1, 1] \\rightarrow \\Reals$ for each element of $\\veta \\veta\\transpose \\in \\Reals^{M \\times M}$. A new point $\\eta$ is added to the fundamental system if it maximises the determinant\n\\begin{equation}\n    \\eta = \\argmax_{\\eta_* \\in \\dsphere}\\ \\textrm{det}\\left(\\MM(\\veta, \\eta_{*})\\right),\n\\end{equation}\nin order to satisfy the condition in \\cref{eq:fundamental-system}.\n% \\begin{equation}\n%     \\textrm{det}(\\MC_n^{(\\alpha)}(\\veta, \\eta_{*})) = \\textrm{det}(C_n^{(\\alpha)}(\\veta\\veta\\transpose))\\left(C_n^{(\\alpha)}(1) - C_n^{(\\alpha)}(\\eta_{*}\\veta\\transpose) \\left[C_n^{(\\alpha)}(\\veta\\veta\\transpose)\\right]^{-1} C_n^{(\\alpha)}(\\veta\\eta_{*}\\transpose) \\right).\n% \\end{equation}\nComputing the determinant can be done efficiently using Schur' complement. Furthermore, as $\\veta$ and $C_n^{(\\alpha)}(1.0)$ are constants the optimisation problem boils down to\n\\begin{equation}\n    \\label{eq:optimisation-determinant}\n    \\eta = \\argmin_{\\eta_* \\in \\Reals^d}\\ C_n^{(\\alpha)}(\\frac{\\eta_{*}}{\\norm{\\eta_*}}\\veta\\transpose) \\left[C_n^{(\\alpha)}(\\veta\\veta\\transpose)\\right]^{-1} C_n^{(\\alpha)}(\\veta\\frac{\\eta_{*}\\transpose}{\\norm{\\eta_*}}).\n\\end{equation}\nThe complete algorithm is given in \\cref{alg:fundamental-system}.\n\n\\begin{algorithm}[H]\n    \\SetAlgoLined\n    \\DontPrintSemicolon\n    \\KwInput{Degree $n$ and dimension $d$}\n    \\KwResult{Fundamental system $\\veta = \\{\\eta_0, \\ldots \\eta_{\\dnumharmonicsforlevel}\\}$}\n    $\\eta_1 = (0,0,\\ldots,1)$ \\tcp*{d-dimensional vector pointing north}\n    $\\veta = \\{\\eta_1\\}$,\n    $\\alpha = \\frac{d-2}{2}$,\n    $i = 2$\\;\n     \\While{$i \\le \\dnumharmonicsforlevel$}{\n        $\\eta = \\argmax_{\\eta_* \\in \\Reals^d}\\ \\textrm{det}(\\MM(\\veta, \\frac{\\eta_{*}}{\\norm{\\eta_*}}))$\n        \\tcp*{Using a local optimisation method (e.g., BFGS) and \\cref{eq:optimisation-determinant}}\n        Add $\\eta$ to $\\veta$\\;\n        i = i + 1\\;\n      }\n     \\caption{Construction of fundamental system\\label{alg:fundamental-system}}\n\\end{algorithm}\n\n\\paragraph{Ortho-normalisation}\n\n\\begin{theorem}\n   Let $\\veta = \\{\\eta_1, \\ldots, \\eta_{\\dnumharmonicsforlevel}\\}$ be a fundamental system of degree $n$ consisting of $\\dnumharmonicsforlevel$ points, and $\\ML$ the inverse Cholesky factor of $C_n^{(\\alpha)}(\\veta\\veta\\transpose)$. Then for $j=1,\\ldots,\\dnumharmonicsforlevel$ and\n    \\begin{equation}\n    \\phi_{n,j}(x) = \\sum_{i=1}^{\\dnumharmonicsforlevel} \\ML_{j,i}\\,C_n^{(\\alpha)}(\\eta_i\\transpose x)\n    \\end{equation}\n    is $\\{\\phi_{n,j}\\}$ an ortho-normal basis for the spherical harmonics $\\mathcal{H}_n^d$.\n\\end{theorem}\n\nThe proof follows from $\\langle C_n^{(\\alpha)}(\\eta_i\\transpose \\cdot), C_n^{(\\alpha)}(\\eta_j\\transpose \\cdot) \\rangle_{L_2(\\dsphere)} = C_n^{(\\alpha)}(\\eta_i\\transpose\\eta_j)$ as a result of the Funk-Hecke theorem.\n\n\n% Let $\\MM = C_n^{(\\alpha)}(\\veta\\veta\\transpose)$ and $\\ML \\ML\\transpose = \\MM$, which exists because the set $\\veta$ satisfies \\cref{eq:fundamental-system}.\n% \\begin{equation}\n% \\phi_{n,j}(x) = \\sum_i [\\ML\\inv]_{j,i} C_n^{(\\alpha)}(\\eta_i\\transpose x)\n% \\end{equation}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{Appendix1/harmonics}\n    \\caption{Spherical Harmonics}\n    \\label{fig:appendix:harmonics}\n\\end{figure}", "meta": {"hexsha": "8a7d9eb13ae4aca0f33a9bdcf9a9afeaf14b8591", "size": 15153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix1/appendix1.tex", "max_stars_repo_name": "vdutor/FYR", "max_stars_repo_head_hexsha": "e32e175235720c7651c3b5200dcccf8046ab3099", "max_stars_repo_licenses": ["MIT"], "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": "vdutor/FYR", "max_issues_repo_head_hexsha": "e32e175235720c7651c3b5200dcccf8046ab3099", "max_issues_repo_licenses": ["MIT"], "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": "vdutor/FYR", "max_forks_repo_head_hexsha": "e32e175235720c7651c3b5200dcccf8046ab3099", "max_forks_repo_licenses": ["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.537037037, "max_line_length": 1552, "alphanum_fraction": 0.6963637564, "num_tokens": 4817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6884922906115929}}
{"text": "\\subsubsection{Circular Cylinders}\r\n\\noindent\r\nA circular cylinder is what we usually think of as a cylinder.\r\nIt is a circle extruded into 3D space.\r\nOne of its forms is \r\n\\begin{equation*}\r\n\tx^2 + y^2 = R^2,\r\n\\end{equation*}\r\nwhere $R$ is the cylinder's radius.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./differentialMultivariableCalculus/cylinder.png}\r\n\t\\caption{A circular cylinder}\r\n\\end{figure}", "meta": {"hexsha": "6302940323c7c1754eb467bd7a82b69fdb137f9a", "size": 434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/circularCylinder.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/circularCylinder.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/circularCylinder.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": 28.9333333333, "max_line_length": 90, "alphanum_fraction": 0.7350230415, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6884922887638184}}
{"text": "%\n% Chapter 1.5\n%\n\n\\section*{1.5 Limit of a Function}\n\n\\subsection*{Limit}\n\nWe can make the values of \\(f(x)\\) arbitrarily close to \\(L\\) by restricting \\(x\\) to be sufficiently close to \\(a\\) but never equal to \\(a\\).\n$$\\lim_{x \\to a}f(x)=L \\text{ means that } f(x) \\to L \\text{ as } x \\to a$$\n\n\\subsection*{One-sided Limit}\n\n$$\\lim_{x \\to a^-}f(x)=L$$\nmeans that the limit of \\(f(x)\\) as \\(x\\) approaches \\(a\\) from the left is equal to \\(L\\) if we can make the values of \\(f(x)\\) arbitrarily close to \\(L\\) by taking \\(x\\) to be sufficiently close to \\(a\\) with \\(x\\) less than \\(a\\).\n\n$$\\lim_{x \\to a}f(x)=L \\quad \\text{if} \\quad \\lim_{x \\to a^-}f(x)=L \\quad \\text{and} \\quad \\lim_{x \\to a^+}f(x)=L$$\n\n\\subsection*{Infinite Limits}\n\nLet \\(f\\) be a function defined on both side of \\(a\\), except possibly at \\(a\\) itself. Then \n$$\\lim_{x \\to a}f(x)=\\infty$$\nmeans that the values of \\(f(x)\\) can be made arbitrarily large by taking \\(x\\) sufficiently close to \\(a\\), but not equal to \\(a\\).\n\\\\\\\\\nLet \\(f\\) be a function defined on both side of \\(a\\), except possibly at \\(a\\) itself. Then \n$$\\lim_{x \\to a}f(x)=-\\infty$$\nmeans that the values of \\(f(x)\\) can be made arbitrarily large negative by taking \\(x\\) sufficiently close to \\(a\\), but not equal to \\(a\\).\n\n\\subsection*{Vertical Asymptotes}\n\nThe line \\(x=a\\) is called \\textbf{vertical asymptote} of the curve \\(y=f(x)\\) if at least one of the following statements is true:\n\n$$\\lim_{x \\to a}f(x)=\\infty \\quad \\lim_{x \\to a^-}f(x)=\\infty \\quad \\lim_{x \\to a^+}f(x)=\\infty$$\n$$\\lim_{x \\to a}f(x)=-\\infty \\quad \\lim_{x \\to a^-}f(x)=-\\infty \\quad \\lim_{x \\to a^+}f(x)=-\\infty$$\n\n", "meta": {"hexsha": "67b5d0a29c15209f99d548d26d5e4c9523b6b583", "size": 1635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-5.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/1-5.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/1-5.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4166666667, "max_line_length": 233, "alphanum_fraction": 0.623853211, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.6884922737622612}}
{"text": "\\section{Right to Left Computability Class}\\label{sec:right-to-left}\nAfter having developed\nformulas modifying rightmost bits in \\autoref{sec:combining},\nthe option arises to classify these kind of formulas.\n\\emph{Hacker's Delight} \\cite{Warren:2012:HD:2462741}\ntherefore introduces the so called ``right to left computability class''.\nEvery formula in this class shares the property,\nthat each result bit only depends on input bits\nat its position or to the right of it (see \\autoref{table:property}).\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{rrl}\n\\lstinline$x$: & \\lstinline$x$$_n\\ \\ \\dots$\n    & \\fbox{\\lstinline$x$$_i$ \\lstinline$x$$_{i-1} \\dots$\\lstinline$x$$_0$}\\\\\n\\lstinline$y$: & \\lstinline$y$$_n\\ \\ \\dots$\n    & \\fbox{\\lstinline$y$$_i$ \\lstinline$y$$_{i-1} \\dots$\\lstinline$y$$_0$}\\\\\nresult \\lstinline$r$: & \\lstinline$x$$_n\\ \\ \\dots$\n    & \\fbox{\\lstinline$r$$_i$}\\lstinline$ r$$_{i-}\\dots$\\lstinline$r$$_{i-1}$\\\\\n~\\\\\n\\multicolumn{3}{c}{\\fbox{\\lstinline$r$$_i$ only depends on\n    \\lstinline$x$$_i \\dots$\\lstinline$x$$_0$ and\n    \\lstinline$y$$_i \\dots$\\lstinline$y$$_0$}}\\\\\n\\end{tabular}\n\\caption{Right to left computability property}\n\\label{table:property}\n\\end{table}\n\nNotice that, as it is common for a lot of operators,\nthe result bit \\lstinline$r$$_i$ is allowed to depend on\n\\lstinline$r$$_{i-1}\\dots$\\lstinline$r$$_0$.\nThis is already given since\nevery of these result bits to the right of \\lstinline$r$$_i$\nonly depend on bits of \\lstinline$x$ and \\lstinline$y$.\n\nBefore defining the class,\nthe previously used set of operators will get slightly modified:\n\\lstinline$INC$ and \\lstinline$DEC$\nget exchanged for \\lstinline$ADD$ and \\lstinline$SUB$.\nThis will allow for more flexibility while not using\nmore powerful operations: they can simply be expressed with loops.\nThe instruction set is therefore:\n\\[\n    \\text{\\lstinline$NOT$},\n    \\underbrace{\\text{\\lstinline$ADD$, \\lstinline$SUB$}}\n    _{\\text{\\lstinline$INC$, \\lstinline$DEC$}},\n    \\text{\\lstinline$AND$},\n    \\text{\\lstinline$OR$}\n\\]\n\nIt should also be mentioned, that this selection is a rational choice.\nSmaller sets would also be possible,\nand there are other right to left computable operators\n-- they can be combined from the selected ones\n(e.g.~shifting left as a sequence of \\lstinline$ADD$s).\n\n\\begin{quote}\n``THEOREM. A function mapping words to words can be implemented\nwith world-parallel \\emph{add}, \\emph{subtract}, \\emph{or} and \\emph{not}\ninstructions if and only if each bit of the result\ndepends only on bits at and to the right of each input operand.''\n\\par\\hfill \\emph{Hacker's Delight},\npage \\texttt{12} \\cite{Warren:2012:HD:2462741}\n\\end{quote}\n\n\\begin{proof}~\n\\begin{description}\n\\item[``$\\implies$'':]\nIn \\autoref{sec:rightmost} \\lstinline$INC$ and \\lstinline$DEC$\nwhere established as right to left operations.\nThis then also applies to \\lstinline$ADD$ and \\lstinline$SUB$.\nRegarding \\lstinline$NOT$, \\lstinline$AND$, \\lstinline$OR$,\nthey clearly fulfil the right to left computability property,\nsince their result bits do not on any adjacent ones at all.\n\nThereby a formula using only\n\\lstinline$ADD$, \\lstinline$SUB$, \\lstinline$AND$,\n\\lstinline$OR$ and \\lstinline$NOT$\nonly depends on bits at and to the right of each input operand.\n\n\\item[``$\\impliedby$'':]\nThe result only depends on bits at and to the right of each input operand.\nThese can be isolated using \\lstinline$AND$ with the argument and a mask\n(a constant containing a single \\lstinline$1$ at the respective position).\n\nOnce every required bit is isolated, the function can be expressed\nusing only \\lstinline$NOT$, \\lstinline$OR$ and \\lstinline$AND$.\nThis is true because (as mentioned in \\autoref{sec:introduction})\n$\\{\\lnot, \\lor, \\land\\}$ is a complete set of logical operators,\nevery logical function can be expressed using only its elements.\n\\end{description}\n\\end{proof}\n\nThe obtained class contains all functions\nthat can calculate the $n$th result bit\nwith only knowing the input operands up to their $n$th bit.\nThis has applications e.g. in bitstreams when working on partial data.\n", "meta": {"hexsha": "d7478afb5d1b55c95a6486caac4d94fce424ac38", "size": 4064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/5-right-to-left.tex", "max_stars_repo_name": "NeoLegends/hackers-delight", "max_stars_repo_head_hexsha": "4cd924e1e10476d116b5e7b8b9504aa6c8d88e23", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/5-right-to-left.tex", "max_issues_repo_name": "NeoLegends/hackers-delight", "max_issues_repo_head_hexsha": "4cd924e1e10476d116b5e7b8b9504aa6c8d88e23", "max_issues_repo_licenses": ["CC0-1.0"], "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/5-right-to-left.tex", "max_forks_repo_name": "NeoLegends/hackers-delight", "max_forks_repo_head_hexsha": "4cd924e1e10476d116b5e7b8b9504aa6c8d88e23", "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.4693877551, "max_line_length": 79, "alphanum_fraction": 0.7391732283, "num_tokens": 1198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272544, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6884351357092986}}
{"text": "\\chapter{Calculus}\n\\textbf{Definition:} Calculus (from Latin calculus, literally 'small pebble', used for counting and calculations, as on an abacus) is the mathematical study of continuous change. It has two major branches:\n\\begin{itemize}  \n\t\\item \\textbf{differential calculus:} concerning rates of change and slopes of curves;\n\t\\item \\textbf{integral calculus:} concerning accumulation of quantities and the areas under and between curves\n\\end{itemize}\nThese two branches are related to each other by the fundamental theorem of calculus. \n\n\n\\section{Limits}\n\\subsection{Limits Rules}\nIf $ \\lim_{x \\rightarrow c }f(x) = L_1 $ and $ \\lim_{x \\rightarrow c } g(x) = L_2 $ then:\n\n\\begin{itemize}\n\t\\item $ \\displaystyle \\lim_{x \\rightarrow c} \\left[ f(x) \\pm g(x) \\right] = L_1 \\pm L_2 $\n\t\\item $ \\displaystyle \\lim_{x \\rightarrow c} \\left[ f(x) \\cdot g(x) \\right] = L_1 \\cdot L_2 $\n\t\\item $ \\displaystyle \\lim_{x \\rightarrow c} \\frac{f(x)}{g(x)} = \\frac{L_1}{L_2} $ \\ \\ \\ \\  if $L_2 \\ne 0$\n\t\\item $ \\displaystyle \\lim_{x \\rightarrow c} f(x)^n = L_1^n $ \\ \\ \\ \\  if $n$ is a positive integer\n\t\\item $ \\displaystyle \\lim_{x \\rightarrow c} f(x)^{\\frac{1}{n}} = L_1^{\\frac{1}{n}} $ \\ \\ \\ \\  if $n$ is a positive integer, and, if $n$ is even, then $L_1>0$\n\t\\item $ \\displaystyle \\lim_{x \\rightarrow c} \\frac{f(x)}{g(x)} = \\lim_{x \\rightarrow c} \\frac{f^\\prime(x)}{g^\\prime(x)}$ \\ \\ \\ \\ if $ \\lim_{x \\rightarrow c } f(x) = \\lim_{x \\rightarrow c } g(x) = L $ \\ \\ (L'Hôpital's rule)\n\\end{itemize}\n\n\\subsubsection{Substitution rule}\n $ \\displaystyle \n\\text{Given  } \\lim_{x\\rightarrow c}f(x)=l \\text{   then   } \\lim_{x\\rightarrow c}g(f(x))=\\lim_{y\\rightarrow l}g(y) \n$\n\n\\subsection{Common Limits}\n\\subsubsection{Simple functions}\n\n\\begin{tabularx}{\\textwidth}{ l l }\n $ \\displaystyle \\lim_{x \\rightarrow c} a = a $ & \n $ \\displaystyle \\lim_{x \\rightarrow c} x = c $ \\\\\n  $ \\displaystyle \\lim_{x \\rightarrow c} (ax + b) = ac+b $ &\n  $ \\displaystyle \\lim_{x \\rightarrow c} x^r = c^r $ \\ \\ \\ if $r$ is a positive integer \\\\\n \n $ \\displaystyle \\lim_{x \\rightarrow 0^+} \\frac{1}{x^r} = +\\infty $ &\n \n $ \\displaystyle \\lim_{x \\rightarrow 0^-} \\frac{1}{x^r} = \\begin{cases}\n -\\infty & \\text{ if $r$ is odd } \\\\\n +\\infty & \\text{ if $r$ is even }\n \\end{cases}\n $\n\\end{tabularx}\n\n\n\\subsubsection{Polynomials}\n$ \\displaystyle \\lim_{x\\rightarrow\\pm\\infty}P(x)=\\lim_{x\\rightarrow\\pm\\infty}a_nx^x=\\pm\\infty $\n\n$ \\displaystyle \\lim_{x\\rightarrow\\pm\\infty}\\frac{P(x)}{Q(x)}=\\lim_{x\\rightarrow\\pm\\infty}\\frac{a_nx^x}{b_mx^m}=\\lim_{x\\rightarrow\\pm\\infty}\\frac{a_n}{b_m}x^{n-m}=\n\\begin{cases}\n\\infty & \\text{if } n>m \\\\\n\\frac{a_n}{b_m} & \\text{if } n=m \\\\\n0 & \\text{if } n<m \\\\\n\\end{cases} $\n\n\\subsubsection{Trigonometric functions}\n\\begin{tabularx}{\\textwidth}{ X X X }\n\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{\\sin(x)}{x}=1 $ &\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{\\sin(\\alpha x)}{\\beta x}=\\frac{\\alpha}{\\beta} $ &\n$ \\displaystyle  \\lim_{x\\rightarrow0}\\frac{\\arcsin(x)}{x}=1 $\\\\ [1.7ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{1-\\cos(x)}{x}=0 $ &\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{1-\\cos(x)}{x^2}=\\frac{1}{2} $ \\\\ [1.7ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{\\tan(x)}{x}=1 $ &\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{\\arctan(x)}{x}=1 $ \n\n\\end{tabularx}\n\n\\subsubsection{Logarithmic and exponential functions}\n\\begin{tabularx}{\\textwidth}{ X X }\n\t\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{\\ln(x+a)}{x}=a $ &\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{\\log_a(x+1)}{x}=\\frac{1}{\\ln(a)} ~~~ (a>0) $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}x^\\alpha= \\begin{cases}\n+\\infty & a>0 \\\\\n0 & a<0\n\\end{cases} $ & \n$ \\displaystyle \\lim_{x\\rightarrow0^+}x^\\alpha= \\begin{cases}\n+\\infty & a<0 \\\\\n0 & a>0\n\\end{cases} $ \\\\ [2.2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}a^x= \\begin{cases}\n+\\infty & a>1 \\\\\n0 & a<1\n\\end{cases} $ & \n$ \\displaystyle \\lim_{x\\rightarrow-\\infty}a^x= \\begin{cases}\n0 & a>1 \\\\\n+\\infty & a<1 \n\\end{cases} $ \\\\ [2.2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\log_ax= \\begin{cases}\n-\\infty & a<1 \\\\\n+\\infty & a>1 \n\\end{cases} $ & \n$ \\displaystyle \\lim_{x\\rightarrow 0^+}\\log_ax= \\begin{cases}\n-\\infty & a>1 \\\\\n+\\infty & a<1 \n\\end{cases} $ \\\\ [2.2ex]\n\n$ \\displaystyle\\lim_{x\\rightarrow0}\\frac{a^x-1}{x}=ln(a) ~~ \\forall a>0 $ &\n $ \\displaystyle \\lim_{x\\rightarrow0}\\frac{e^x-1}{x}=1 $ \\\\[2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\frac{x^\\alpha}{a^x}=0  ~~~~ a>1 $ &\n$ \\displaystyle \\lim_{x\\rightarrow-\\infty}\\frac{e^x}{\\left|x\\right|^\\alpha}=0 ~~~~ a>1 $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\frac{\\ln(x)}{x^\\alpha}=0 $ &\n$ \\displaystyle \\lim_{x\\rightarrow 0^+}\\ln(x)x^\\alpha=0 ~~~~ a>0 $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\frac{\\ln(x)}{a^x}=0 ~~~ a>1$ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\left(1+\\frac{1}{x}\\right)^x=e $ & \n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\left(1-\\frac{1}{x}\\right)^x=\\frac{1}{e} $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\left(\\frac{x}{x+k}\\right)^x=\\frac{1}{e^k} $ & \n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\left(\\frac{x}{ \\sqrt[x]{x!} }\\right)=e $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow0}(1+x)^{1/x}={\\rm e} $ &\n$ \\displaystyle \\lim_{x\\rightarrow+\\infty}\\left(1+\\frac{n}{x}\\right)^{mx}={\\rm e}^{mn} $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow\\infty}\\frac{x^p}{a^x}=0~~\\mbox{als }|a|>1 $ &\n$ \\displaystyle \\lim_{x\\rightarrow0}\\frac{(1+x)^\\alpha-1}{x}=\\alpha ~~~ (a\\in\\mathbb{R}) $ \\\\ [2ex]\n\n$ \\displaystyle \\lim_{x\\rightarrow0}\\left(a^{1/x}-1\\right)=\\ln(a) $ &\n$ \\displaystyle \\lim_{x\\rightarrow\\infty}\\sqrt[x]{x}=1 $ \\\\ [2ex]\n\n\\end{tabularx}\n\n\\section{Series}\n\\textbf{Definition:} In mathematics, a series is, roughly speaking, a description of the operation of adding infinitely many quantities, one after the other, to a given starting quantity.\n\n\\subsection{Convergence and divergence}\nAbsolute Convergence: If $\\sum\\left|s_n\\right|$ is convergent.\n\nConditional Convergence: If $\\sum s_n$ is convergent but not absolutely convergent.\n\nIf $\\sum\\limits_n|u_n|$ converges, $\\sum\\limits_n u_n$ also converges.\n\nIf $\\lim\\limits_{n\\rightarrow\\infty}u_n\\neq0$ then $\\sum\\limits_n u_n$ is divergent.\n\n\\subsection{Positive Series}\nPositive Series: If all the terms $ s^n $ are positive.\n\nIf $u_n>0~\\forall n$ then $\\sum\\limits_n u_n$ is convergent if \n$\\sum\\limits_n\\ln(u_n+1)$ is convergent.\n\nIntegral Test: If $ f(n) = s_n $, continuous, positive, decreasing: $\\sum s_n$ converges $ \\Leftrightarrow \\int_{1}^{\\infty}f(x)dx $ converges.\n\nComparison Test: $\\sum a_n$ and $\\sum b_n$ where $a_k<b_k ~ (\\forall k\\ge m) \n\\begin{cases}\n\\text{If } \\sum b_n \\text{ converges, so does } \\sum a_n \\\\\n\\text{If } \\sum a_n \\text{ diverges, so does } \\sum b_n\n\\end{cases}\n$\n\nLimit Comparison Test: $\\sum a_n$ and $\\sum b_n$ such that $ \\lim_{n\\rightarrow\\infty} \\frac{a_n}{b_n}$ exists, $\\sum a_n$ converges $\\Leftrightarrow$ $\\sum b_n$ converges.\n\nRatio Test: if $\\lim_{n\\rightarrow \\infty}\\left|\\frac{s_{n+1}}{s_n}\\right| = \\begin{cases}\n<1 \\text{ then it is absolutely convergent} \\\\\n1 \\text{ then no conclusion} \\\\\n>1 \\text{ or } +\\infty \\text{ then it diverges}\n\\end{cases}\n$\n\nRoot Test: if  $\\lim_{n\\rightarrow \\infty} \\sqrt[n]{\\left|s_n\\right|} = \\begin{cases}\n<1 \\text{ then it is absolutely convergent} \\\\\n1 \\text{ then no conclusion} \\\\\n>1 \\text{ or } +\\infty \\text{ then it diverges}\n\\end{cases}\n$\n\n\\subsection{Alternating Series}\nAlternating Series: $ \\sum(-1)^{n+1}a_n=a_1-a_2+a_3-a_4+a_5-... $\n\nLeibniz Test: An alternating series of which the absolute values of the terms drop\nmonotonously to 0 is convergent.\n\n\\subsection{Common Series}\n\\subsubsection{Basic Series}\n\n\\begin{tabular}{ l l }\n$ \\displaystyle \\sum_{k=1}^n k = \\frac{n(n+1)}{2} $ &\n$ \\displaystyle \\sum_{k=1}^n (2k-1) = n^2 $ \\\\ [1.5em]\n$ \\displaystyle \\sum_{k=1}^n k^2 = \\frac{n(n+1)(2n+1)}{6} $ & \n$ \\displaystyle \\sum_{k=1}^n k^3 = \\frac{n^2(n+1)^2}{4} $\n\\end{tabular}\n\n\\subsubsection{Harmonic Series}\n\\[\n\\sum_{n=1}^\\infty \\frac{1}{n^p} ~ \\begin{cases}\n\t\t\t\t\t\t\t\t\t\\text{is convergent if } p>1 \\\\\n\t\t\t\t\t\t\t\t\t\\text{is divergent if } p\\leq1\n\t\t\t\t\t\t\t\t\t\\end{cases}\n\\]\n\n\\subsubsection{Geometric Series}\n\\[\n\\sum_{0}^{n}q^k=1+q+q^2+...+q^n= \\begin{cases}\n\t\t\t\t\t\t\t\t\tn+1 & q=1 \\\\\n\t\t\t\t\t\t\t\t\t\\frac{1-q^{k+1}}{1-q} & q\\ne1\n\t\t\t\t\t\t\t\t \\end{cases}\n~ \\text{ then } ~\n\\sum_{0}^{+\\infty}q^k= \\begin{cases}\n\\frac{1}{1-q} & \\left|q\\right|<1 \\\\\n+\\infty & q\\ge1 \\\\\n\\text{no conclusion} & q\\le-1\n\\end{cases}\n\\]\n\n\\subsubsection{Mengoli Series}\n\\[\ns_n=\\sum_{k=2}^{n}\\frac{1}{(k-1)k}=1-\\frac{1}{n} ~~ \\text{ then } ~~  \\lim_{n\\rightarrow\\infty}s_n=1\n\\]\n\n\\section{Landau Symbols}\n\\subsection{Big-O notation}\nThe Big-O provides a function that is at most the same order as that of a given function.\n\nIf $\\exists M>0$ such that $\\displaystyle \\lim_{x\\rightarrow c} \\left| \\frac{f(x)}{g(x)} \\right| < M $ then we say \"as $x\\rightarrow c, f(x)=O(g(x))$\"\n\n\\subsection{Little-O notation}\nThe little-o provides a function that is of lower order of magnitude than a given function.\n\nIf $\\displaystyle \\lim_{x\\rightarrow c} \\frac{f(x)}{g(x)} = 0 $ then we say \"as $x\\rightarrow c, f(x)=o(g(x))$\"\n\n\n\n\\section{Asymptotes}\nIn analytic geometry, an asymptote of a curve is a line such that the distance between the curve and the line approaches zero as one or both of the x or y coordinates tends to infinity.\n\n\\subsection{Vertical asymptotes}\nThe line $x = a$ is a vertical asymptote of the graph of the function $y = f(x)$ if:\n\n $\\displaystyle \\lim_{x\\rightarrow a^-} f(x) = \\pm \\infty $ or \n $\\displaystyle \\lim_{x\\rightarrow a^+} f(x) = \\pm \\infty $\n\n\n\\subsection{Horizontal asymptotes}\nThe horizontal line $y = c$ is a horizontal asymptote of the function $y = f(x)$ if:\n\n $\\displaystyle \\lim_{x\\rightarrow -\\infty} f(x) = c $ or \n $\\displaystyle \\lim_{x\\rightarrow + \\infty} f(x) = c $\n \n\\subsection{Oblique asymptotes}\nA function $f(x)$ is asymptotic to the straight line $y = mx + n (m \\ne 0)$ if:\n\n$\\displaystyle \\lim_{x\\rightarrow +\\infty} \\left[ f(x) - (mx+n) \\right] = 0 $ or \n$\\displaystyle \\lim_{x\\rightarrow -\\infty} \\left[ f(x) - (mx+n) \\right] = 0 $\n\nUsing the Landau symbols, the formula becomes:\n\n$\\displaystyle  f(x) = mx + n + 0(1), x\\rightarrow +\\infty$ \n\nFrom the last one, it is easy to find that:\n\n$\\displaystyle m=\\lim_{x\\rightarrow +\\infty} \\frac{f(x)}{x} $  and $\\displaystyle q=\\lim_{x\\rightarrow +\\infty} (f(x) - mx) $\n\n\\section{Derivatives}\nThe derivative of a function is the ratio of the difference of function value $ f(x) $ at points $ x+\\Delta x $ and $ x $ with $ \\Delta x $, when $ \\Delta x $ is infinitesimally small. The derivative is the function slope or slope of the tangent line at point x.\n\n\\[\nf^\\prime(x) = \\lim_{\\Delta x \\rightarrow 0} \\frac{ f( x + \\Delta x ) - f(x) }{\\Delta x}\n\\]\n\n\\subsection{Derivatives rules}\n\\begin{tabular}{ l l }\nSum rule:      & $ \\displaystyle (\\alpha f(x) \\pm \\beta g(x) )^\\prime = \\alpha f^\\prime(x) \\pm \\beta g^\\prime(x) $  \\\\\nProduct rule:  & $ \\displaystyle (f(x) \\cdot g(x) )^\\prime = f^\\prime(x) g(x) + f(x) g^\\prime(x) $ \\\\\nQuotient rule: & $ \\displaystyle \\left( \\frac{f(x)}{g(x)} \\right)^\\prime = \\frac{ f^\\prime(x) g(x) - f(x) g^\\prime(x) }{ g^2(x) } $ \\\\\nChain rule:    & $ \\displaystyle f\\left( g(x) \\right) ^\\prime = f^\\prime\\left( g(x) \\right) \\cdot g^\\prime(x) $\n\\end{tabular}\n\n\\subsection{Derivative test}\n\n\\subsubsection{Second derivative test}\nIf the function $f$ is twice differentiable at a critical point $x_0$ (i.e. $f^\\prime(x_0) = 0$), then:\n\\begin{itemize}\n\\item If $ f^{\\prime \\prime }(x_0)<0 $ then $f$  has a local maximum at $x_0$.\n\\item If $ f^{\\prime \\prime }(x_0)>0 $ then $f$  has a local minimum at $x_0$.\n\\item If $ f^{\\prime \\prime }(x_0)=0 $ the test is inconclusive.\n\\end{itemize}\n\n\\subsubsection{Concavity test}\nA twice-differentiable function $f$ is concave up if $ f^{\\prime \\prime }(x_0)>0 $ and concave down if $ f^{\\prime \\prime }(x_0)<0 $.\n\n\\subsubsection{Higher order derivative test}\nLet $f$ be a real-valued function $n$-times ($n\\ge2$) differentiable at a point $x_0$ with\n\\[\nf^\\prime(x_0) = ... = f^{(n)}(x_0) = 0 ~~~, ~~~ f^{(n+1)}(x_0) \\ne 0\n\\]\nthen\n\\begin{itemize}\n\t\\item If $n$ is odd and  $ f^{(n+1)}(x_0)<0 $ then $f$ has a local maximum at $x_0$.\n\t\\item If $n$ is odd and  $ f^{(n+1)}(x_0)>0 $ then $f$ has a local minimum at $x_0$.\n\t\\item If $n$ is even and  $ f^{(n+1)}(x_0)<0 $ then $x_0$ is a strictly decreasing point of inflection.\n\t\\item If $n$ is even and  $ f^{(n+1)}(x_0)>0 $ then $x_0$ is a strictly increasing point of inflection.\n\\end{itemize}\n\n\\medskip\nIn addition, when $x_0$ is not a critical point, we have:\n\nLet $f$ be a real-valued function $n$-times ($n\\ge3$) differentiable at a point $x_0$ with\n\\[\nf^\\prime(x_0)\\ne0 ~~~, ~~~ f^{\\prime\\prime}(x_0) = ... = f^{(n)}(x_0) = 0 ~~~, ~~~ f^{(n+1)}(x_0) \\ne 0\n\\]\nthen\n\\begin{itemize}\n\t\\item If $n$ is odd then $x_0$ is not an inflection point.\n\t\\item If $n$ is even and  $ f^{(n+1)}(x_0)<0 $ then $x_0$ is a strictly decreasing point of inflection.\n\t\\item If $n$ is even and  $ f^{(n+1)}(x_0)>0 $ then $x_0$ is a strictly increasing point of inflection.\n\\end{itemize}\n\n\n\n\\subsection{Common derivatives}\n\\subsubsection{Basic Derivatives}\n$ \\displaystyle f(x)=\\alpha ~ \\Rightarrow ~ f^\\prime(x)=0 $\n\n$ \\displaystyle f(x)=x ~ \\Rightarrow ~ f^\\prime(x)=1 $\n\n$ \\displaystyle f(x)=x^n ~ \\Rightarrow ~ f^\\prime(x)=n x^{n-1} $\n\n\\subsubsection{Trigonometric Derivatives}\n\\begin{tabular}{ l l }\n$ \\displaystyle f(x)=\\sin(x) ~ \\Rightarrow ~ f^\\prime(x)=\\cos(x) $ & \n$ \\displaystyle f(x)=\\arcsin(x) ~ \\Rightarrow ~ f^\\prime(x)= \\frac{1}{ \\sqrt{1-x^2} } $ \\\\ [2ex]\n$ \\displaystyle f(x)=\\cos(x) ~ \\Rightarrow ~ f^\\prime(x)=-\\sin(x) $ &\n$ \\displaystyle f(x)=\\arccos(x) ~ \\Rightarrow ~ f^\\prime(x)= -\\frac{1}{ \\sqrt{1-x^2} } $ \\\\ [2ex]\n$ \\displaystyle f(x)=\\tan(x) ~ \\Rightarrow ~ f^\\prime(x)=\\sec^2(x)= \\frac{1}{\\cos^2(x)} $ & \n$ \\displaystyle f(x)=\\arctan(x) ~ \\Rightarrow ~ f^\\prime(x)= \\frac{1}{ 1+x^2 } $ \\\\ [2ex]\n$ \\displaystyle f(x)=\\sec(x) ~ \\Rightarrow ~ f^\\prime(x)=\\sec(x)\\tan(x) $ \\\\ [2ex]\n$ \\displaystyle f(x)=\\cot(x) ~ \\Rightarrow ~ f^\\prime(x)=-\\csc^2(x) $ \\\\ [2ex]\n$ \\displaystyle f(x)=\\csc(x) ~ \\Rightarrow ~ f^\\prime(x)=-\\csc(x)\\cot(x) $\n\\end{tabular}\n\n\n\\subsubsection{Exponential Derivatives}\n\\begin{tabular}{ l l }\n$ \\displaystyle  f(x)=a^x ~ \\Rightarrow ~ f^\\prime(x)=\\ln(a)a^x $ & \n$ \\displaystyle  f(x)=e^x ~ \\Rightarrow ~ f^\\prime(x)=e^x $ \\\\ \n$ \\displaystyle  f(x)=a^{g(x)} ~ \\Rightarrow ~ f^\\prime(x)=\\ln(a)a^{g(x)}g^\\prime(x) $ & \n$ \\displaystyle  f(x)=e^{g(x)} ~ \\Rightarrow ~ f^\\prime(x)=e^{g(x)}g^\\prime(x) $ \n\\end{tabular}\n\n\n\\subsubsection{Logarithm Derivatives}\n\\begin{tabular}{ l l }\n$ \\displaystyle  f(x)=\\log_a(x) ~ \\Rightarrow ~ f^\\prime(x)= \\frac{1}{ \\ln(a)x } $ & \n$ \\displaystyle  f(x)=\\ln(x) ~ \\Rightarrow ~ f^\\prime(x)= \\frac{1}{ x } $ \\\\ [1.5ex] \n$ \\displaystyle  f(x)=\\log_a(g(x)) ~ \\Rightarrow ~ f^\\prime(x)= \\frac{g^\\prime(x)}{ \\ln(a)g(x) } $ & \n$ \\displaystyle  f(x)=\\ln(g(x)) ~ \\Rightarrow ~ f^\\prime(x)= \\frac{g^\\prime(x)}{ g(x) } $ \n\\end{tabular}\n\n\n\\section{Taylor Series}\nA Taylor series is a representation of a function as an infinite sum of terms that are calculated from the values of the function's derivatives at a single point.\n\n\\textbf{Taylor's Theorem:}\nLet $k \\ge 1$ be an integer and let the function $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ be $k$ times differentiable at the point $a \\in R$. Then there exists a function $h_k : \\mathbb{R} \\rightarrow \\mathbb{R}$ such that\n\\[\nf(x) = f(a) + f^{\\prime}(a)(x-a) + \\frac{f^{\\prime\\prime}(a)}{2!}(x-a)^2 + ... + \\frac{f^{k}(a)}{k!}(x-a)^k + h_k ( x ) (x-a)^k\n\\]\nand $\\lim_{x \\rightarrow a} h_k ( x ) = 0$. This is called the Peano form of the remainder.\n\n\nThe Taylor series of a real or complex-valued function $f(x)$ that is infinitely differentiable at a real or complex number $a$ is the power series:\n\\[\n\\sum_{n=0}^{+\\infty}\\frac{f^{(n)}(a)}{n!}(x-a)^n\n\\]\n\n\\textbf{Maclaurin series:}\nWhen $a = 0$, the series is also called a Maclaurin series.\n\n\\textbf{Even/Odd functions and Maclaurin Polynomials:}\n\\begin{itemize}\n\t\\item If $f$ be an even function, then each of $f$'s Maclaurin polynomials contains only even powers;\n\t\\item If $f$ be an odd function, then each of $f$'s Maclaurin polynomials contains only odd powers.\n\\end{itemize}\n\n\\subsection{Maclaurin series of common functions}\n\n\\subsubsection{Basic functions}\n$\\displaystyle \\sqrt{1+x} = 1 + \\frac{1}{2}x - \\frac{1}{8}x^2 + \\frac{1}{16}x^3 + o(x^3)$ \n\n\\subsubsection{Exponential functions}\n$\\displaystyle e^x = \\sum_{n=0}^{+\\infty}\\frac{x^n}{n!} = 1 + x + \\frac{x^2}{2!} + ... + \\frac{x^n}{n!} + o(x^n) $ \\ \\ \\ \\ It converges for all $x$\n\n\\subsubsection{Logarithm functions}\n$\\displaystyle \\ln(1+x) = \\sum_{n=1}^{+\\infty}(-1)^{n+1}\\frac{x^n}{n} = x - \\frac{x^2}{2} + ... + (-1)^{n+1}\\frac{x^n}{n} + o(x^n) $ \\ \\ \\ It conv. for $\\left|x\\right|<1$\n\n\\subsubsection{Geometric Series}\n$\\displaystyle \\frac{1}{1+x} = \\sum_{n=0}^{+\\infty}(-1)^n x^n = 1 - x + x^2 ... + (-1)^n x^n + o(x^n)$ \n\n$\\displaystyle \\frac{1}{1-x} = \\sum_{n=0}^{+\\infty}x^n $ \\ \\ \\ \\ It converges for $\\left|x\\right|<1$.\n\n$\\displaystyle \\frac{1}{(1-x)^2} = \\sum_{n=1}^{+\\infty}nx^{n-1} $ \\ \\ \\ \\ It converges for $\\left|x\\right|<1$.\n\n$\\displaystyle \\frac{1}{(1-x)^3} = \\sum_{n=2}^{+\\infty} \\frac{(n-1)n}{2} x^{n-2} $ \\ \\ \\ \\ It converges for $\\left|x\\right|<1$.\n\n\\subsubsection{Binomial Series}\n$\\displaystyle (1+x)^\\alpha = \\sum_{n=0}^{+\\infty} \\binom{\\alpha}{n} x^n $ \\ \\ It converges for $\\left|x\\right|<1$ for any real or complex number $\\alpha$.\n\n\\subsubsection{Trigonometric functions}\n\\begin{align*}\n\t\\sin(x) &= \\sum_{n=0}^{\\infty} \\frac{(-1)^n}{(2n+1)!}x^{2n+1} &= x - \\frac{x^3}{6} + \\frac{x^5}{120} - ... ~~~~~~ & \\forall x & \\\\\n\t\\cos(x) &= \\sum_{n=0}^{\\infty} \\frac{(-1)^n}{(2n)!}x^{2n} &= 1 - \\frac{x^2}{2} + \\frac{x^4}{24} - ... ~~~~~~ & \\forall x &\\\\\n\t\\tan(x) &= \\sum_{n=1}^{\\infty} \\frac{B_{2n}(-4)^n (1-4^n) }{(2n)!}x^{2n-1} &= x + \\frac{x^3}{3} + \\frac{2x^5}{15} + ... ~~~~~~ & \\text{for } |x|<\\frac{\\pi}{2} &\\\\\n\\end{align*}\n\n\\subsubsection{Hyperbolic functions}\n\\begin{align*}\n\\sinh(x) &= \\sum_{n=0}^{\\infty} \\frac{x^{2n+1}}{(2n+1)!} &= x + \\frac{x^3}{3!} + \\frac{x^5}{5!} + ... ~~~~~~ & \\forall x & \\\\\n\\cosh(x) &= \\sum_{n=0}^{\\infty} \\frac{x^{2n}}{(2n)!} &= 1 + \\frac{x^2}{2!} + \\frac{x^4}{4!} + ... ~~~~~~ & \\forall x & \\\\\n\\tanh(x) &= \\sum_{n=1}^{\\infty} \\frac{B_{2n} 4^n (4^n-1) }{(2n)!}x^{2n-1} &= x - \\frac{x^3}{3} + \\frac{2x^5}{15} - \\frac{17x^7}{315} + ... ~~~~~~ & \\text{for } |x|<\\frac{\\pi}{2} & \\\\\n\\end{align*}\n\n\\section{Integral Calculus}\n\\textbf{Definition:} In mathematics, Integral calculus is a subfield of calculus in which the notion of an integral, its properties and methods of calculation are studied. It concerns accumulation of quantities and the areas under and between curves.\n\n\\subsection{Integration rules}\n\\begin{tabular}{ l l }\n\tMultiplication by a constant:      & $ \\displaystyle \\int c f(x)dx = c \\int f(x)dx  $  \\\\\n\tSum rule:      & $ \\displaystyle \\int (f(x) + g(x)) dx = \\int f(x)dx + \\int g(x)dx $  \\\\\n\tIntegration by parts:   & $ \\displaystyle \\int f(x)g^\\prime(x)dx = f(x)g(x) + \\int f^\\prime(x)g(x)dx  $  \\\\\n\tSubstitution rule: & $ \\displaystyle \\int f(g(x))g^\\prime(x)dx = \\int f(y)dy ~~,~~ y=g(x) $  \\\\\n\t\\end{tabular}\n\n\n\\subsection{Integration of Rational Functions}\nA rational function $ \\frac{P(x)}{Q(x)}$, where $P(x)$ and $Q(x)$ are both polynomials, can be integrated in four steps:\n\\begin{enumerate}\n\\item Reduce the fraction if it is improper (i.e. degree of $P(x)$ is greater than degree of $Q(x)$);\n\\item Factor $Q(x)$ into linear and/or quadratic (irreducible) factors;\n\\item Decompose the fraction into a sum of partial fractions;\n\\item Calculate integrals of each partial fraction.\n\\end{enumerate}\n\n\n\\subsubsection{Step 1. Reducing an Improper Fraction}\nIf the fraction is improper, divide the $P(x)$ by $Q(x)$ to obtain\n\\[\\frac{P(x)}{Q(x)}=F(x)+\\frac{R(x)}{Q(x)}\\]\nwhere $\\frac{R(x)}{Q(x)}$ is a proper fraction.\n\n\\subsubsection{Step 2. Factoring Q(x) into Linear and/or Quadratic Factors}\nWrite the denominator $Q(x)$ as\n\\[\nQ(x) = (x-a)^\\alpha \\cdot\\cdot\\cdot (x-b)^\\beta(x^2+px+q)^\\mu \\cdot\\cdot\\cdot (x^2+rx+s)^\\nu\n\\]\nwhere quadratic functions are irreducible, i.e. do not have real roots.\n\n\\subsubsection{Step 3. Decomposing the Rational Fraction into a Sum of Partial Fractions}\nWrite the function as follows:\n\\[\\frac{R(x)}{Q(x)}= \\frac{A_1}{(x-a)^{\\alpha}} + \\frac{A_2}{(x-a)^{\\alpha-1}} + ... + \\frac{A_\\alpha}{(x-a)} + ... + \\frac{M_1 x + N_1}{(x^2+rx+s)^{\\nu}} + ... + \\frac{M_\\nu x + N_\\nu}{(x^2+rx+s)}\\]\nThen equate the coefficients of equal powers of $x$ by multiplying both sides of the latter expression by $Q(x)$ and write the system of linear equations in $A_i,B_i,M_i,N_i,...$ .\n\n\\subsubsection{Step 4. Integrating partial fractions}\nUse the following formulas to evaluate integrals of partial fractions with linear and quadratic denominators:\n\n\\begin{enumerate}\n\t\\item $\\displaystyle \\int \\frac{A}{x-a} dx = A \\ln \\left| x-a \\right| +C$\n\n\t\\item $\\displaystyle \\int \\frac{A}{(x-a)^k} dx = \\frac{A}{(1-k)(x-a)^{k-1}} +C$\n\t\n\t\\item $\\displaystyle \\int \\frac{1}{(x-b)^2+c^2} dx = \\frac{1}{c} \\arctan \\frac{x-b}{c} + C$\n\t\n\t\\item $\\displaystyle \\int \\frac{2x-2b}{(x-b)^2+c^2} dx = \\ln \\left| (x-b)^2 + c^2 \\right| +C$\n\t\n\t\\item $\\displaystyle \\int \\frac{1}{(x^2+bx+c)^n} dx = !!TODO!!$\n\t\n\\end{enumerate}\n\n\n\\subsection{Integration of Common Functions - TODO}\n\n\\section{Differential calculus}\n\\textbf{Definition:} In mathematics, differential calculus is a subfield of calculus concerned with the study of the rates at which quantities change.\n\n", "meta": {"hexsha": "3a7760bd4b27074752a224aabb28446c3c831af0", "size": 21487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics_Formulary/sections/calculus.tex", "max_stars_repo_name": "ufoscout/Physics_notes", "max_stars_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mathematics_Formulary/sections/calculus.tex", "max_issues_repo_name": "ufoscout/Physics_notes", "max_issues_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematics_Formulary/sections/calculus.tex", "max_forks_repo_name": "ufoscout/Physics_notes", "max_forks_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:25:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:25:09.000Z", "avg_line_length": 44.5788381743, "max_line_length": 262, "alphanum_fraction": 0.6317773537, "num_tokens": 8089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.688435129802481}}
{"text": "\\section{Transformations and Expectations}\n\n\\subsection{Exercise 1}\n(a) $F_Y(y) = P(X^3 \\leq y) = F_X (y^{\\frac{1}{3}})$. Differentiating, we get that \n$f_Y(y) = 14y(1 - y^{\\frac{1}{3}})$ which integrates to 1 over $(0, 1)$.\n\n(b)  $f_Y(y) = \\dv{y} F_X(\\frac{y - 3}{4}) = \\frac{7}{4} \\exp(\\frac{-7(y - 3)}{4})$, which again\nintegrates to 1 over $(3, \\infty)$. The sample space of $Y$ consists of $(3, \\infty)$ because \n$4X + 3$ is monotonically increasing and $4(0) + 3 = 3$.\n\n(c) We need only consider positive square roots, since  $x \\in (0, 1)$. Thus,\n$f_Y(y) = \\frac{1}{2\\sqrt{y}}30y (1 - \\sqrt{y})^2$, which integrates to 1 over $(0, 1)$.\n\n\\subsection{Exercise 2}\n(a) $f_Y(y) = \\frac{1}{2\\sqrt{y}} f_X(\\sqrt{y}) = \\frac{1}{2\\sqrt{y}}$\n\n(b) Plug $x = e^{-y}$ into $f_X(x)$ and multiply by $e^{-y}$ (the negative of the derivative, since $-\\log X$\nis decreasing).\n\n(c) Plug in  $x = \\log y$ and multiply by $\\frac{1}{y}$.\n\n\\subsection{Exercise 3}\nFrom the definition of $Y$, we can see that the sample space is\n$\\mathcal{Y} = \\big(\\frac{n}{n+1}\\big)_{\\mathbb{N}}$. Solving $y = \\frac{x}{x + 1}$ for $y$, we find that\n$f_Y(y) = f_X(\\frac{y}{1 - y})$.\n\n\\subsection{Exercise 4}\n(a) Integrating from $-\\infty$ to 0 gives $\\frac{1}{2}$ and likewise for 0 to  $\\infty$, so $f$ is a pdf.\n\n(b) If $t \\leq 0$, then we have that $P(X < t) = \\frac{1}{2} e^{\\lambda t}$. Otherwise, \n\\begin{align*}\n        P(X < t) &= \\int_{-\\infty}^{t} f(x) = \\int_{-\\infty}^{0} f(x) + \\int_{0}^{t} f(x) \\\\ \n                 &= \\frac{1}{2} + \\frac{1}{2} - \\frac{1}{2} e^{-\\lambda t} \\\\\n                 &= 1 - \\frac{1}{2}e^{-\\lambda t}\n\\end{align*}\n\n(c) If $t \\leq 0$, $P(\\abs{X} < t)$ is clearly 0. Otherwise,\n\\begin{align*}\n        P(\\abs{X} < t) &= P(-t < X < t) = P(X < t) - P(X < -t) \\\\\n                       &= 1 - e^{- \\lambda t} \n\\end{align*}\nfrom the CDFs computed in part (b). \n\n\\subsection{Exercise 5}\nThe sample space $\\mathcal{Y}$ is $[0, 1]$. Thus, we need to consider \n$P(Y \\leq y) = P(X \\leq \\sin^{-1} \\sqrt{y})$ for $y \\in [0, 1]$. By symmetry, we can just consider the case\nwhere $\\sin^{-1}$ is restricted to $[0, \\frac{\\pi}{2}]$, as the other three quadrants have the same area.\nTherefore,\n\\begin{align*}\n        f_Y(y) &= 4 \\dv{y} F_X(\\sin^{-1} \\sqrt{y}) \\\\\n               &= 4 \\dv{y} \\frac{\\sin^{-1} \\sqrt{y}}{2\\pi} \\\\\n               &= \\frac{1}{\\pi \\sqrt{y (1 - y)}}\n\\end{align*}\nAt $y = 0$ and $y = 1$, the density is infinite/undefined - I'm not really sure how to interpret this.\n\n\\subsection{Exercise 11}\n(a) We have that \n\\begin{align*}\n        \\mathrm{E} [X^2] = \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty} x^2 e^{-\\frac{x^2}{2}} &= \\frac{2}{\\sqrt{2\\pi}} \\int_{0}^{\\infty} x^2 e^{-\\frac{x^2}{2}} \\\\\n                                                                            &= \\frac{2}{\\sqrt{2\\pi}} \\big(\\lim_{x \\to \\infty} -x e^{-\\frac{x^2}{2}} + \\int_{0}^{\\infty} e^{-\\frac{x^2}{2}}\\big) \\\\\n                                                                            &= 1\n\\end{align*}\nWhere we integrated by parts using $dv = xe^{-\\frac{x^2}{2}}$ and $u = x$, applied L'H\\^opital's rule, \nand then compared to the CDF of the normal distribution.\n\n(b) The pdf $f_Y(y)$ is just $f_X(y) + f_X(-y)$, so $f_Y(y) = \\frac{2}{\\sqrt{2\\pi}} e^{-\\frac{y^2}{2}}$.\nWe can then compute $\\mathrm{E} [Y]$ as\n\\begin{align*}\n        \\mathrm{E} [Y] = \\frac{2}{\\sqrt{2\\pi}} \\int_{0}^{\\infty} y e^{-\\frac{y^2}{2}} &= \\frac{2}{\\sqrt{2\\pi}}  \n\\end{align*}\nTo compute the variance we need to compute $\\mathrm{E} [Y^2]$, which is identical to $\\mathrm{E} [X^2]$. Thus, \n$\\mathrm{Var} [Y] = \\mathrm{E} [Y^2] - \\mathrm{E} [Y]^2 = 1 - \\frac{2}{\\pi}$.\n\n\\subsection{Exercise 12}\nWe see that $y = d \\tan(x)$. Since $\\tan(x)$ is increasing on $(0, \\frac{\\pi}{2})$, we get that\n\\begin{align*}\n        f_Y(y) &= F_X\\big(\\tan^{-1} \\frac{y}{d}\\big) \\dv{y} \\tan^{-1} \\frac{y}{d} \\\\\n               &= \\frac{2\\tan^{-1} \\frac{y}{d}}{\\pi d\\big(1 + \\frac{y^2}{d^2}\\big)}\n\\end{align*}\nfor $y \\in (0, \\infty)$. We can compute $\\mathrm{E} [Y]$ directly from $f_X(x)$ as\n\\begin{align*}\n        \\mathrm{E} [Y] &= \\frac{2d}{\\pi}\\int_{0}^{\\frac{\\pi }{2}} \\tan(x) dx \\\\\n                       &= \\infty\n\\end{align*}\nSo $\\mathrm{E} [Y]$ does not exist.\n\n\\subsection{Exercise 13}\nA sequence of flips has length $l$ if there are either $l$ heads in a row or $l$ tails in a row, so\n$P(X = l) = p^l (1 - p) + (1 - p)^l p = p \\text{Geom}(1 - p) + (1 - p) \\text{Geom}(p)$. Therefore,\nby linearity of expected value, $\\mathrm{E} [X] = \\frac{p}{1 - p} + \\frac{1 - p}{p}$.\n\n\\subsection{Exercise 14}\n(a) We have that\n\\begin{align*}\n        \\int_{0}^{\\infty} 1 - F_X(x) dx = \\int_{x = 0}^{\\infty} \\int_{y = x}^{\\infty} f_X(y) dy dx  \n\\end{align*}\nSince $0 \\leq x \\leq \\infty$ and $x \\leq y \\leq \\infty$, we can change the order of integration by having\n$0 \\leq y \\leq \\infty$ on the outside and $0 \\leq x \\leq y$ on the inside\n\\begin{align*}\n        \\int_{x = 0}^{\\infty} \\int_{y = x}^{\\infty} f_X(y) dy dx &= \\int_{y = 0}^{\\infty} \\int_{x = 0}^{y} dx f_X(y) dy \\\\\n                                                                 &= \\int_{0}^{\\infty} y f_X(y) dy \\\\\n                                                                 &= E[X]\n\\end{align*}\n\n\n(b) We can rewrite the expected value as a sum of infinite sums to see that\n\\begin{align*}\n        E[X] &= \\sum_{k = 1}^\\infty k f(k) = \\sum_{k = 1}^\\infty f(k) + \\sum_{k = 2}^\\infty f(k) + ... \\\\\n             &= \\sum_{k = 0}^\\infty \\sum_{j = k + 1}^\\infty f(k) = \\sum_{k = 0}^\\infty (1 - F_X(k))\n\\end{align*}\n\n\\subsection{Exercise 17}\n(a) We need to solve $m^3 = 1 - m^3$, since $F_X(x) = x^3$. Solving gives $m = \\sqrt[3]{\\frac{1}{2}}$.\n\n(b) $f$ is an even function, so $m = 0$.\n\n\\subsection{Exercise 18}\nWe differentiate under the integral sign to get\n\\begin{align*}\n        \\dv{a} \\mathrm{E} [\\abs{X - a}] &= \\dv{a} \\bigg(\\int_{a}^{\\infty} (x - a) f_X(x) dx + \\int_{-\\infty}^{a} (a - x) f_X(x) dx\\bigg) \\\\\n                                        &= \\int_{a}^{\\infty} -f_X(x) dx + \\int_{-\\infty}^{a} f_X(x) dx \\\\  \n                                        &= 2F_X(a) - 1\n\\end{align*}\nSetting the last line equal to 0 yields $a = m$. To see that this is a minimum, we note that $2F_X(a) - 1 \\leq 0$\nwhen $a < m$ and $2F_X(a) - 1 \\geq 0$ when $a > m$.\n\n\\subsection{Exercise 25}\n(a)\n\\begin{align*}\n        F_{-X}(x) = P(X \\geq -x) &= 1 - F_X(-x) \\\\\n                                 &= \\int_{-x}^{\\infty} f_X(x) dx \\\\\n                                 &= \\int_{-x}^{0} f_X(x) dx + \\int_{0}^{\\infty} f_X(x) dx \\\\\n                                 &= \\int_{0}^{x} f_X(x) dx + \\int_{-\\infty}^{0} f_X(x) dx \\\\  \n                                 &= F_X(x)\n\\end{align*}\n\n(b)\n\\begin{align*}\n        M_X(t) &= \\int_{-\\infty}^{\\infty} e^{tx} f_X(x) dx \\\\ \n               &= \\int_{-\\infty}^{0} e^{tx} f_X(x) dx + \\int_{0}^{\\infty} e^{tx} f_X(x) dx \\\\  \n               &= \\int_{0}^{\\infty} e^{-tx} f_X(x) dx + \\int_{-\\infty}^{0} e^{-tx} f_X(x) dx \\\\\n               &= M_X(-t)\n\\end{align*}\n\n\\subsection{Exercise 29}\n(a) For binomial, we have\n\\begin{align*}\n        \\mathrm{E} [X(X - 1)] &= \\sum_{k = 0}^n k(k - 1) \\binom{n}{k} p^k (1 - p)^{n - k} \\\\\n                              &= n (n - 1) p^2 \\sum_{k = 2}^n \\binom{n - 2}{k - 2} p^(k - 2) (1 - p)^{(n - 2) - (k - 2)} \\\\\n                              &= n (n - 1) p^2\n\\end{align*}\nFor Poisson, we have\n\\begin{align*}\n        \\mathrm{E} [X(X - 1)] &= \\sum_{k = 0}^{\\infty} k(k - 1) \\frac{\\lambda^k e^{-\\lambda}}{k!} \\\\ \n                              &= \\lambda^2 \\sum_{k = 2}^{\\infty} \\frac{\\lambda^{k - 2} e^{-\\lambda}}{(k - 2)!} \\\\\n                              &= \\lambda^2\n\\end{align*}\n\n(b) To compute the variances, we can use linearity of expectation to see that \n$\\mathrm{E} [X(X - 1)] + \\mathrm{E} [X] - \\mathrm{E} [X]^2 = \\mathrm{Var} [X]$. So for binomial, we get\n\\begin{align*}\n        \\mathrm{Var} [X] &= n (n - 1) p^2 + np - n^2 p^2 = np - np^2 = np(1 - p)\n\\end{align*}\nAnd for Poisson, we get\n\\begin{align*}\n        \\mathrm{Var} [X] &= \\lambda^2 + \\lambda - \\lambda^2 = \\lambda \n\\end{align*}\n\n(c) This one is kind of a pain to typeset; the technique is the same as (a), although more involved.\n\n\\subsection{Exercise 31}\nNo such distribution exists, since $M_X(0) = 0$, which contradicts the fact that $\\mathrm{E} [1] = 1$.\n", "meta": {"hexsha": "ac4a74520f6a0b11f9285d168965c629a1eb5bf2", "size": 8272, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stat_Inference_Casella_Berger/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": "Stat_Inference_Casella_Berger/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": "Stat_Inference_Casella_Berger/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": 47.8150289017, "max_line_length": 194, "alphanum_fraction": 0.5001208897, "num_tokens": 3244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6884351246279214}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n\\begin{document}\n% Covers 11-20-19 and 11-22-19 (probably)\n\n\\section{Positive Operators and Isometries}\n\\label{sec:positive_operators_and_isometries}\n\\begin{defn}[Positive Operator]\n\tAn operator \\(T \\in \\mathcal{L}(V)\\) is called \\textbf{positive} if \\(T\\) is self-adjoint and\n\t\\begin{align*}\n\t\t\\langle Tv, v \\rangle \\geq 0\n\t\\end{align*}\n\tfor all \\(v \\in V\\).\n\\end{defn}\nIf \\(V\\) is a complex vector space, then \\(T\\) does not need to be self-adjoint (if an inner product is real for all values, then the operator must be self-adjoint; positivity implies real).\n\\begin{defn}[Square Root]\n\tAn operator \\(R\\) is called a \\textbf{square root} of an operator \\(T\\) if \\(R^2 = T\\).\n\\end{defn}\n\\begin{lemma}[Properties of Positive Operators]\n\tLet \\(T \\in \\mathcal{L}(V)\\). Then the following are equivalent:\n\t\\begin{itemize}\n\t\t\\item \\(T\\) is positive\n\t\t\\item \\(T\\) is self-adjoint and all the eigenvalues of \\(T\\) are nonnegative\n\t\t\\item \\(T\\) has a positive square root\n\t\t\\item \\(T\\) has a self-adjoint square root\n\t\t\\item there exists an operator \\(R \\in \\mathcal{L}(V)\\) such that \\(T = R^{*}R\\).\n\t\\end{itemize}\n\\end{lemma}\n\\begin{cor}\n\tEach positive operator on \\(V\\) has a unique positive square root.\n\\end{cor}\n\nUsing more tools, one can further state that if \\(V\\) is a complex vector space and \\(T\\) an invertible operator, then \\(T\\) has a square root.\n\n\\subsection{Isometries}\n\\label{subsec:isometries}\n\nWe can impose one further condition on isomorphisms to strengthen the relation.\n\\begin{defn}[Isometry]\n\tAn operator \\(A \\in \\mathcal{L}(V)\\) is an \\textbf{isometry} if\n\t\\begin{align*}\n\t\t\\|Av\\| = \\|v\\|\n\t\\end{align*}\n\tfor all \\(v \\in V\\).\n\\end{defn}\nNote that we haven't explicitly stated that isometries are isomorphisms. It turns out that this follows directly from the definition above.\n\n\\begin{prop}[Characterization of Isometries]\n\tLet \\(A \\in \\mathcal{L}(V)\\). The following are equivalent:\n\t\\begin{itemize}\n\t\t\\item \\(A\\) is an isometry\n\t\t\\item \\(\\langle Au,Av \\rangle = \\langle u,v \\rangle \\) for all \\(u,v \\in V\\)\n\t\t\\item \\(Ae_1,\\ldots,Ae_n\\) is orthonormal for all choices of orthonormal vectors \\(e_1,\\ldots,e_n \\in V\\)\n\t\t\\item There exists an orthonormal basis \\(e_1,\\ldots,e_n \\in V\\) such that \\(Se_1,\\ldots,Se_n\\) is orthonormal\n\t\t\\item \\(S^{*}S = SS^{*}= I\\) \n\t\t\\item \\(S^{*}\\) is an isometry\n\t\t\\item \\(S\\) is invertible and \\(S^{-1} = S^{*}\\)\n\t\\end{itemize}\n\\end{prop}\nOf course, this gives us that isometries are normal. This in fact gives us one more vital characterzation:\n\\begin{prop}\n\tLet \\(V\\) be a complex inner product space and \\(A \\in \\mathcal{L}(V)\\). Then there is an orthonormal basis of \\(V\\) consisting of eigenvalues of \\(A\\) with corresponding eigenvalues equal to \\(\\left| 1 \\right| \\) if and only if \\(A\\) is an isometry.\n\\end{prop}\n\\end{document}\n", "meta": {"hexsha": "dd19becfd8f3b10f5b92ec21afa9cec66e2092cf", "size": 2833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/11-20-19-PosOp.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/11-20-19-PosOp.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/11-20-19-PosOp.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": 42.9242424242, "max_line_length": 251, "alphanum_fraction": 0.6907871514, "num_tokens": 935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6884225406183946}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\usepackage{amsmath,amsthm,amsfonts,tikz}\n\\usepackage[euler-digits]{eulervm}\n\\usepackage{hyperref}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newcommand{\\iprod}[1]{\\langle#1\\rangle}\n\\newcommand{\\vecp}[1]{\\boldsymbol{p}}\n\\newcommand{\\hatvecp}{\\hat{\\boldsymbol{p}}}\n\\newcommand{\\Poly}{\\mathbb{P}}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\title{Notes on Gauss Quadrature for General Weight Functions}\n\\author{Bill McLean}\n\\date{\\today}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{document}\n\\maketitle\n\\tableofcontents\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Three-term recurrence relation}\nLet $\\Poly_k$ denote the $(k+1)$-dimensional vector space of real \npolynomials with degree at most~$k$, and denote the \ninfinite-dimensional space of all polynomials by~$\\Poly$.  Let $\\mu$ \nbe a positive measure on the real line with the property that, \n$\\int f(x)^2\\,d\\mu(x)=0$~and $f\\in\\Poly$ then $f=0$.\nWe can then define an inner product and norm on~$\\Poly$  by\n\\[\n\\iprod{f,g}=\\int f(x)g(x)\\,d\\mu(x)\\quad\\text{and}\\quad\n\\|f\\|=\\sqrt{\\iprod{f,f}}.\n\\]\nUsing the Gram--Schmidt procedure to orthogonalise the linearly \nindependent monomials $1$, $x$, $x^2$, $x^3$, \\dots, yields the\npolynomial~$p_j(x)$ of degree~$j$ by\n\\[\np_j(x)=x^j-\\sum_{k=0}^{j-1}\\frac{\\iprod{x^j,p_k}}{\\|p_k\\|^2}\\,p_k(x)\n\t\\quad\\text{for $j=0$, $1$, $2$, \\dots.}\n\\]\nTherefore, $p_j$ is the unique monic polynomial in~$\\Poly_j$ such \nthat $p_j\\perp\\Poly_{j-1}$; in particular,\n\\begin{equation}\\label{eq: orthog}\n\\iprod{p_j,p_k}=0\\quad\\text{if $j\\ne k$.}\n\\end{equation}\n\n\\begin{theorem}\\label{thm: 3 term}\nThe orthogonal polynomials defined above satisfy the three-term \nrecurrence relation\n\\begin{equation}\\label{eq: 3 term pj}\np_j(x)=(x-a_j)p_{j-1}(x)-b_j^2p_{j-2}(x)\n\t\\quad\\text{for $j=1$, $2$, $3$, \\dots,}\n\\end{equation}\nwith $p_0(x)=1$ and $p_{-1}(x)=0$. The coefficients satisfy\n\\[\na_j=\\frac{\\iprod{xp_{j-1},p_{j-1}}}{\\|p_{j-1}\\|^2}\n\\quad\\text{and}\\quad\nb_j=\\frac{\\|p_{j-1}\\|}{\\|p_{j-2}\\|},\n\\]\nexcept that, by convention, we put $b_1=\\sqrt{\\int d\\nu}=\\|p_0\\|$.\n\\end{theorem}\n\\begin{proof}\nSince $p_j(x)-xp_{j-1}(x)$ has degree at most~$j-1$, there are \nconstants~$c_{jk}$ such that\n\\[\np_j(x)-xp_{j-1}(x)=\\sum_{k=0}^{j-1}c_{jk}p_k(x).\n\\]\nTaking the inner product of both sides with~$p_{j-1}$ and using\nthe orthogonality property~\\eqref{eq: orthog}, we obtain\n\\[\n-\\iprod{xp_{j-1},p_{j-1}}=c_{j,j-1}\\|p_{j-1}\\|^2,\n\\]\nshowing that $c_{j,j-1}=-a_j$.  Also, taking the inner product of both\nsides with~$p_k$ for $k\\le j-3$ gives\n\\[\nc_{jk}\\|p_k\\|^2=\\iprod{p_j-xp_{j-1},p_k}=-\\iprod{p_{j-1},xp_k}=0,\n\\]\nso $p_j(x)=(x-a_j)p_{j-1}(x)+c_{j,j-2}p_{j-2}(x)$ and\n\\[\n0=\\iprod{p_j,p_{j-2}}=\\iprod{xp_{j-1},p_{j-2}}+c_{j,j-2}\\|p_{j-2}\\|^2.\n\\]\nFinally, \n\\begin{align*}\n\\iprod{xp_{j-1},p_{j-2}}&=\\iprod{p_{j-1},xp_{j-2}}\n\t=\\iprod{p_{j-1},p_{j-1}}+\\iprod{p_{j-1},xp_{j-2}-p_{j-1}}\\\\\n\t&=\\|p_{j-1}\\|^2+0,\n\\end{align*}\nand therefore $c_{j,j-2}=-\\|p_{j-1}\\|^2/\\|p_{j-2}\\|^2=-b_j^2$.\n\\end{proof}\n\n\\begin{corollary}\n$\\|p_j\\|=b_1b_2\\cdots b_{j+1}$ for $j=2$, $3$, \\dots.\n\\end{corollary}\n\nRecall that the Lagrange interpolation polynomial\n\\[\n\\ell_j(x)=\\prod_{\\substack{k=1\\\\ k\\ne j}}^n\\frac{x-x_k}{x_j-x_k}.\n\\]\nhas the property that $\\ell_j(x_k)=\\delta_{jk}$. The zeros of~$p_n$ \nhave the following important properties.  \n\n\\begin{theorem}\nSuppose that $d\\mu(x)=w(x)\\,dx$ with $w(x)>0$ for $a<x<b$.\n(We allow $a=-\\infty$ or $b=\\infty$.) The orthogonal polynomial has \nonly real and simple zeros~$x_j$ in the open interval~$(a,b)$, that \nis,\n\\[\na<x_1<x_2<\\cdots<x_n<b.\n\\]\n\\end{theorem}\n\\begin{proof}\nSuppose for a contradiction that $p_n$ has a zero $\\alpha+i\\beta$ \nwith~$\\beta\\ne0$.  Since $p_n$ has real coefficients, \nthe complex conjugate~$\\alpha-i\\beta$ is also a zero and thus\n\\[\np_n(x)=\\bigl[x-(\\alpha+i\\beta)\\bigr]\\bigl[x-(\\alpha-i\\beta)\\bigr]q(x)\n\t=[(x-\\alpha)^2+\\beta^2]q(x)\n\\]\nwith $n\\ge2$~and $q\\in\\Poly_{n-2}$. Since $p_n\\perp\\Poly_{n-2}$,\n\\[\n0=\\iprod{p_n,q}=\\iprod{[(x-\\alpha)^2+\\beta^2],q}\\\\\n\t=\\|(x-\\alpha)q\\|^2+\\beta^2\\|q\\|^2,\n\\]\nimplying that $q=0$ and thus $p_n=0$, a contradiction.\n\nLikewise, suppose for a contradiction that $p_n$ has a multiple real \nroot~$\\alpha$ and write $p_n(x)=(x-\\alpha)^2q(x)$ with \n$q\\in\\Poly_{n-2}$.  Then\n\\[\n0=\\iprod{p_n,q}=\\iprod{(x-\\alpha)^2q,q}=\\|(x-\\alpha)q\\|^2,\n\\]\nagain implying that $q=0$ and thus $p_n=0$.  We conclude that $p_n$ \nhas only distinct real zeros~$x_j$.\n\nThus, for $1\\le j\\le n$,\n\\[\np_n(x)=\\prod_{k=1}^n(x-x_k)=c_j(x-x_j)\\ell_j(x)\n\\quad\\text{where}\\quad\nc_j=\\prod_{\\substack{k=1\\\\ k\\ne j}}^n(x_j-x_k)\\ne0.\n\\]\nSince $\\ell_j\\in\\Poly_{n-1}$ and $p_n\\perp\\Poly_{n-1}$,\n\\[\n0=\\iprod{p_n,\\ell_j}=\\iprod{c_j(x-x_j)\\ell_j,\\ell_j}\n\t=c_j\\bigl[(x\\ell_j,\\ell_j)-x_j\\|\\ell_j\\|^2\\bigr],\n\\]\nimplying that\n\\[\nx_j=\\frac{\\iprod{x\\ell_j,\\ell_j}}{\\|\\ell_j\\|^2}.\n\\]\nBy integrating the strict inequalities\n\\[\na\\ell_j(x)^2w(x)<x\\ell_j(x)^2w(x)<b\\ell_j(x)^2w(x)\n\t\\quad\\text{for $a<x<b$,}\n\\]\nwe see that $a\\|\\ell_j\\|^2<\\iprod{x\\ell_j,\\ell_j}<b\\|\\ell_j\\|^2$\nand therefore $a<x_j<b$, as claimed.\n\\end{proof}\n\nWe denote the ortho\\emph{normal} polynomials by\n\\[\n\\hat p_j(x)=\\frac{p_j(x)}{\\|p_j\\|},\n\\]\nand find that\n\\[\nb_{j+1}\\hat p_j(x)=(x-a_j)\\hat p_{j-1}(x)-b_j\\hat p_{j-2}(x),\n\\]\nor equivalently,\n\\begin{equation}\\label{eq: 3 term orthog}\nb_j\\hat p_{j-2}(x)+a_j\\hat p_{j-1}(x)+b_{j+1}\\hat p_j(x)=xp_{j-1}(x).\n\\end{equation}\n\n\\begin{theorem}[Christoffel--Darboux identity]\n\\label{thm: Christoffel-Darboux}\nThe monic orthogonal polynomials satisfy\n\\[\n\\frac{1}{b_{n+2}}\\sum_{k=0}^n\\hat p_k(x)\\hat p_k(y)\n\t=\\frac{\\hat p_{n+1}(x)\\hat p_n(y)-\\hat p_n(x)\\hat p_{n+1}(y)}{x-y}\n\t\\quad\\text{for $x\\ne y$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nUsing \\eqref{eq: 3 term orthog}, we see that\n\\begin{align*}\n(x-y)\\hat p_{k-1}(x)&\\hat p_{k-1}(y)\n\t=[x\\hat p_{k-1}(x)]\\hat p_{k-1}(y)\n\t\t-\\hat p_{k-1}(x)[y\\hat p_{k-1}(y)]\\\\\n\t&=\\bigl[\n\tb_k\\hat p_{k-2}(x)+a_k\\hat p_{k-1}(x)+b_{k+1}\\hat p_k(x)\n\t\\bigr]\\hat p_{k-1}(y)\\\\\n\t&\\qquad{}-\\hat p_{k-1}(x)\\bigl[\n\tb_k\\hat p_{k-2}(y)+a_k\\hat p_{k-1}(y)+b_{k+1}\\hat p_k(y)\\bigr]\\\\\n\t&=\\bigl[b_k\\hat p_{k-2}(x)\\hat p_{k-1}(y)\n\t\t-b_{k+1}\\hat p_{k-1}(x)\\hat p_k(y)\\bigr]\\\\\n\t&\\qquad{}+\\bigl[b_{k+1}\\hat p_k(x)\\hat p_{k-1}(y)\n\t\t-b_k\\hat p_{k-1}(x)\\hat p_{k-2}(y)\\bigr]\\\\\n\\end{align*}\nand so\n\\begin{align*}\n(x-y)\\sum_{k=1}^{n+1}\\hat p_{k-1}(x)\\hat p_{k-1}(y)\n\t&=b_1\\hat p_{-1}(x)\\hat p_0(y)-b_{n+2}\\hat p_n(x)\\hat p_{n+1}(y)\\\\\n\t&\\qquad{}+b_{n+2}\\hat p_{n+1}(x)\\hat p_n(y)\n\t\t-b_1\\hat p_0(x)\\hat p_{-1}(y).\n\\end{align*}\n\\end{proof}\n\n\n\\subsection{Legendre polynomials}\nThe Legendre polynomials have the orthogonality property\n\\begin{equation}\\label{eq: legendre orthog}\n\\int_{-1}^1 P_k(x)P_l(x)\\,dx=\\frac{2\\delta_{kl}}{2k+1}\n\\end{equation}\nand the 3-term recurrence relation is\n\\begin{equation}\\label{eq: legendre 3 term}\nkP_k(x)=(2k-1)xP_{k-1}(x)-(k-1)P_{k-2}(x).\n\\end{equation}\nThe normalised Legendre polynomials are\n\\[\n\\hat P_k(x)=\\frac{P_k(x)}{\\|P_k\\|}=\\biggl(\\frac{2k+1}{2}\\biggr)^{1/2}\n\tP_k(x),\n\\]\nand thus\n\\begin{multline*}\nk\\biggl(\\frac{2}{2k+1}\\biggr)^{1/2}\\hat P_k(x)\n\t=(2k-1)\\biggl(\\frac{2}{2k-1}\\biggr)^{1/2}x\\hat P_{k-1}(x)\\\\\n\t-(k-1)\\biggl(\\frac{2}{2k-3}\\biggr)^{1/2}\\hat P_{k-2}(x),\n\\end{multline*}\nor equivalently,\n\\[\n\\frac{k\\hat P_k(x)}{\\sqrt{2k+1}}=\\sqrt{2k-1}\\,x\\hat P_{k-1}(x)\n\t-\\frac{k-1}{\\sqrt{2k-3}}\\,\\hat P_{k-2}(x).\n\\]\nThus, the Legendre polynomials satisfy\n\\[\nb_{k+1}\\hat P_k(x)=(x-a_k)\\hat P_{k-1}(x)-b_k\\hat P_{k-2}(x)\n\\]\nwhere\n\\[\na_k=0\\quad\\text{and}\\quad b_k=\\frac{k-1}{\\sqrt{(2k-1)(2k-3)}},\n\\]\nexcept that $b_1=\\sqrt{\\int_{-1}^1\\,dx}=\\sqrt{2}$.\n\n\\section{Gauss quadrature}\nWe now consider a quadrature rule\n\\begin{equation}\\label{eq: Qf}\nQf=\\sum_{j=1}^n w_jf(x_j)\n\\end{equation}\nand its associated error functional\n\\[\nEf=\\int f(x)\\,d\\mu(x)-\\sum_{j=1}^n w_jf(x_j).\n\\]\n\n\\begin{theorem}\\label{thm: Gauss rule}\nFor each $n\\ge1$ there exists a unique quadrature rule~\\eqref{eq: Qf}\nsuch that\n\\begin{equation}\\label{eq: dop 2n-1}\nEf=0\\quad\\text{for all $f\\in\\Poly_{2n-1}$.}\n\\end{equation}\nThis rule has has as its integration points $x_1$, $x_2$, \\dots, \n$x_n$ the zeros of~$p_n$, that is,\n\\[\np_n(x_j)=0\\quad\\text{for $1\\le j\\le n$,}\n\\]\nand as its weights the numbers\n\\begin{equation}\\label{eq: Gauss weights}\nw_j=\\iprod{\\ell_j,1}=\\int\\ell_j(x)\\,d\\mu(x)>0\n\t\\quad\\text{for $1\\le j\\le n$,}\n\\end{equation}\nwhere $\\ell_j$ is the $j$th Lagrange interpolation polynomial:\n\\[\n\\ell_j(x)=\\prod_{\\substack{k=1\\\\ k\\ne j}}\\frac{x-x_k}{x_j-x_k}.\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $x_1$, $x_2$, \\dots, $x_n$ be the zeros of~$p_n$, and define\n$w_j=\\iprod{\\ell_j,1}$.  Given $f\\in\\Poly_{2n-1}$, let $q$~and $r$ \ndenote the quotient and remainder when $f$ is divided by~$p_n$, that \nis,\n\\[\nf(x)=p_n(x)q(x)+r(x)\\quad\\text{with $r\\in\\Poly_{n-1}$.}\n\\]\nSince $p_n(x_j)=0$ it follows that $f(x_j)=r(x_j)$ and so\n\\[\nr(x)=\\sum_{j=1}^n f(x_j)\\ell(x),\n\\]\nand since $q\\in\\Poly_{n-1}$ and $p_n$ is orthogonal to~$\\Poly_{n-1}$,\n\\begin{multline*}\n\\int f(x)\\,d\\mu(x)=\\int q(x)p_n(x)\\,d\\mu(x)+\\int r(x)\\,d\\mu(x)\\\\\n\t=\\iprod{q,p_n}+\\sum_{j=1}^n f(x_j)\\int\\ell_j(x)\\,d\\mu(x)\n\t=0+\\sum_{j=1}^n f(x_j)\\iprod{\\ell_j,1}=Qf,\n\\end{multline*}\nshowing that $Ef=0$.  \n\nTo prove uniqueness, let $Q$ be any quadrature rule~\\eqref{eq: Qf} \nsatisfying \\eqref{eq: dop 2n-1}.  Consider the \npolynomial~$f\\in\\Poly_n$ defined by\n\\[\nf(x)=(x-x_1)(x-x_2)\\cdots(x-x_n).\n\\]\nIf $0\\le k\\le n-1$ then $x^kf(x)\\in\\Poly_{2n-1}$ so\n\\[\n\\iprod{x^k,f}=\\int x^kf(x)\\,d\\mu(x)=\\sum_{j=1}^n w_jx_j^kf(x_j)=0.\n\\]\nHence, $f\\perp\\Poly_{n-1}$, and since $f$ is monic it follows that \n$f=p_n$ by the uniqueness of the orthogonal polynomials.  Therefore,\nthe $x_j$ are the zeros of~$p_n$, and moreover\n\\[\nw_j=\\sum_{k=1}^nw_k\\ell_j(x_k)=\\int\\ell_k(x)\\,d\\mu(x)=\\iprod{\\ell_j,1}\n\\]\nsince $\\ell_j\\in\\Poly_{n-1}$.  In fact, $\\ell_j^2\\in\\Poly_{2n-2}$ so\n\\[\nw_j=\\sum_{k=1}^nw_k\\ell_j(x_k)^2=\\int\\ell_j(x)^2\\,d\\mu(x)\n\t=\\|\\ell_j\\|^2>0,\n\\]\nand the weights satisfy~\\eqref{eq: Gauss weights}.\n\\end{proof}\n\nThe quadrature in the theorem above is called the $n$-point Gauss \nrule generated by the positive measure~$\\mu$.\n\nDefining\n\\[\nT_n=\\begin{bmatrix}\na_1&b_2   &       &       &\\\\\nb_2&a_2   &b_3    &       &\\\\\n   &\\ddots&\\ddots &\\ddots &\\\\\n   &      &b_{n-1}&a_{n-1}&b_n\\\\\n   &      &       &b_n    &a_n\n\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\hatvecp_n(x)=\\begin{bmatrix}\n\t\\hat p_0(x)\\\\ \\hat p_1(x)\\\\ \\vdots\\\\ \\hat p_{n-1}(x)\n\\end{bmatrix},\n\\]\nthe equations~\\eqref{eq: 3 term orthog} for $0\\le j\\le n-1$ are \nequivalent to\n\\begin{equation}\\label{eq: matrix 3 term orthog}\nT_n\\hatvecp_n(x)+b_{n+1}\\hat p_n(x)\\boldsymbol{e}_n=x\\hatvecp_n(x).\n\\end{equation}\nThe points~$x_j$ and weights~$w_j$ may be computed by solving an \neigenproblem for the \\emph{Jacobi matrix}~$T_n$.\n\n\\begin{theorem}\nThe eigenvalues of~$T_n$ are the points $x_1$, $x_2$, \\dots, $x_n$\nof the associated Gauss quadrature rule.  Moreover, for~$1\\le j\\le n$,\nif\n\\[\n\\boldsymbol{v}_j=\\begin{bmatrix}v_{1j}\\\\ v_{2j}\\\\ \\vdots\\\\ v_{nj}\n\\end{bmatrix}\n\\]\ndenotes the eigenvector of~$T_n$ satisfying\n\\[\nT_n\\boldsymbol{v}_j=x_j\\boldsymbol{v}_j\n\\quad\\text{and}\\quad\nv_{1j}=\\frac{1}{b_1},\n\\]\nthen the weight~$w_j$ corresponding to the $j$th Gauss point~$x_j$ \nis given by\n\\[\n\\frac{1}{w_j}=\\sum_{k=1}^n(v_{kj})^2.\n\\]\n\\end{theorem}\n\\begin{proof}\nWe see at once from~\\eqref{eq: matrix 3 term orthog} that \n$T_n\\hatvecp_n(x)=x\\hatvecp_n(x)$ iff $p_n(x_j)=0$, so the\neigenvalues~$x_j$ of~$T_n$ coincide with zeros of~$p_n$ which,\nby Theorem~\\ref{thm: Gauss rule}, coincide with the Gauss points.  \nMoreover, $\\boldsymbol{v}_j=\\hatvecp_n(x_j)$ is the eigenvector \nof~$T_n$ that corresponds to the eigenvalue~$x_j$ and is scaled in \nsuch a way that $v_{1k}=\\hat p_0(x_j)=1/\\|p_0\\|=1/b_1$.\n\nSince $p_n$ is monic with zeros $x_1$, $x_2$, \\dots, $x_n$,\n\\[\np_n(x)=\\prod_{j=1}^n(x-x_j)\n\\qquad\\text{and thus}\\qquad\np_n'(x)=\\sum_{j=1}^n\\prod_{\\substack{k=1\\\\ k\\ne j}}^n(x-x_k).\n\\]\nIn particular\n\\[\np_n'(x_j)=\\prod_{\\substack{k=1\\\\ k\\ne j}}^n(x_j-x_k),\n\\]\nshowing that\n\\[\np_n(x)=p_n'(x_j)(x-x_j)\\ell_j(x)\\quad\\text{where}\\quad\n\\ell_j(x)=\\prod_{\\substack{k-1\\\\ k\\ne j}}\\frac{x-x_k}{x_j-x_k}.\n\\]\nHence, $\\hat p_n(x)=\\hat p_n'(x_j)(x-x_j)\\ell_j(x)$ and so\n\\begin{equation}\\label{eq: w_j}\nw_j=\\iprod{\\ell_j,1}=\\frac{1}{\\hat p_n'(x_j)}\n\t\\int_a^b\\frac{\\hat p_n(x)}{x-x_j}\\,w(x)\\,dx\n\\end{equation}\nPutting $y=x_j$ in the Christoffel--Darboux identity of \nTheorem~\\ref{thm: Christoffel-Darboux} gives\n\\[\n\\frac{1}{b_{n+1}}\\sum_{k=0}^n\\hat p_k(x)\\hat p_k(x_j)\n\t=-\\frac{\\hat p_n(x)}{x-x_j}\\,\\hat p_{n+1}(x_j)\n\\]\nand after taking the inner product of both sides with~$p_0(x)=1$\nwe obtain\n\\[\n\\frac{1}{b_{n+2}}\\sum_{k=0}^n\\iprod{\\hat p_k,p_0}\\hat p_k(x_j)\n\t=-\\hat p_{n+1}(x_j)\\int_a^b\\frac{\\hat p_n(x)}{x-x_j}\\,w(x)\\,dx.\n\\]\nHere, $\\iprod{\\hat p_k,p_0}=0$ for~$k\\ge1$ and \n$\\iprod{\\hat p_0,p_0}=\\iprod{p_0,p_0}/\\|p_0\\|=\\|p_0\\|$, so \nby~\\eqref{eq: w_j}\n\\[\n\\frac{1}{b_{n+2}}=-\\hat p_{n+1}(x_j)\\hat p_n'(x_j)w_j.\n\\]\nThe Christoffel--Darboux identity also gives\n\\begin{align*}\n\\frac{1}{b_{n+2}}\\sum_{k=0}^n\\hat p_k(x_j)^2\n&=\\lim_{y\\to x_j}\\frac{1}{b_{n+2}}\\sum_{k=0}^n\n\t\\hat p_k(x_j)\\hat p_k(y)\n=\\lim_{y\\to x_j}\\frac{\\hat p_{n+1}(x_j)\\hat p_n(y)}{x_j-y}\\\\\n&=-\\hat p_{n+1}(x_j)\\lim_{y\\to x_j}\n\t\\frac{\\hat p_n(y)-\\hat p_n(x_j)}{y-x_j}\n\t=-\\hat p_{n+1}(x_j)\\hat p_n'(x_j) \n\\end{align*}\nand therefore\n\\[\n\\frac{1}{w_j}=-b_{n+2}\\hat p_{n+1}(x_j)\\hat p_n'(x_j)\n\t=\\sum_{k=0}^n\\hat p_k(x_j)^2=\\sum_{k=1}^n(v_{kj})^2,\n\\]\nas claimed.\n\\end{proof}\n\n\n\\section{The modified Chebyshev algorithm}\n\nLet $q_0$, $q_1$, $q_2$, \\dots be a sequence of monic orthogonal \npolynomials generated by a positive measure $\\nu$ on the real line.  \nThus, $q_k\\in\\Poly_k$ is a monic polynomial satisfying \n\\[\n\\int q_k(x)f(x)\\,d\\nu(x)=0\\quad\\text{for all $f\\in\\Poly_{k-1}$.}\n\\]\nIn the usual way, we write the three-term recurrence relation as\n\\begin{equation}\\label{eq: 3 term q}\nq_k(x)=(x-\\alpha_k)q_{k-1}(x)-\\beta_k^2 q_{k-2}(x)\n\t\\quad\\text{for $k=1$, $2$, $3$, \\dots,}\n\\end{equation}\nwith\n\\[\nq_0(x)=1\\quad\\text{and}\\quad q_{-1}(x)=0,\n\\]\nadopting the usual convention that $\\beta_1=\\sqrt{\\int d\\nu}$.\n\nSuppose that $p_0$, $p_1$, $p_2$, \\dots is another sequence of monic \northogonal polynomials generated by a positive measure $\\mu$ and \nhaving known coefficients $a_k$~and $b_k$ in the associated \nthree-term recurrence relation~\\eqref{eq: 3 term pj}; thus\n\\[\n\\int p_k(x)f(x)\\,d\\mu(x)=0\\quad\\text{for all $f\\in\\Poly_{k-1}$.}\n\\]\nFollowing Gautschi~\\cite{Gautschi1982}, we consider the case when \n$\\alpha_k$~and $\\beta_k$ are not known explicitly, but we are able to \nfind the modified moments\n\\[\n\\nu_l=\\int\\hat p_{l-1}(x)\\,d\\nu(x)\\quad\\text{for $1\\le l\\le 2n$,}\n\\]\nwhere, as usual, $\\hat p_0$, $\\hat p_1$, $\\hat p_2$, \\dots are the \northonormalised polynomials satisfying\n\\[\n\\int\\hat p_j(x)\\hat p_k(x)\\,d\\mu(x)=\\delta_{jk}.\n\\]\nThe next theorem summarises the modified Chebyshev algorithm for \ncomputing $\\alpha_k$~and $\\beta_k$ for $1\\le k\\le n$.\n\n\\begin{figure}\n\\caption{The dots correspond to the $\\sigma_{lk}$ computed in the \ncase~$n=5$.  The parallelogram indicates the $\\sigma_{lk}$ used in \nthe expressions for $\\alpha_5$~and $\\beta_5$.}\n\\begin{center}\n\\begin{tikzpicture}[scale=1.0]\n\\draw[->] (0, -1) -- (0, 6);\n\\node[above left] at (0, 6) {$k$};\n\\draw[->] (-1, 0) -- (11, 0);\n\\node[right] at (11, 0) {$l$};\n\\foreach \\x in {2, 3, ..., 9}\n    \\draw[fill=blue] (\\x, 0) circle(0.10cm);\n\\foreach \\x in {1, 2, ..., 10}\n    \\draw[fill=blue] (\\x, 1) circle(0.10cm);\n\\foreach \\x in {2, 3, ..., 9}\n    \\draw[fill=red] (\\x, 2) circle(0.10cm);\n\\foreach \\x in {3, 4, ..., 8}\n    \\draw[fill=red] (\\x, 3) circle(0.10cm);\n\\foreach \\x in {4, 5, 6, 7}\n    \\draw[fill=red] (\\x, 4) circle(0.10cm);\n\\foreach \\x in {5, 6}\n    \\draw[fill=red] (\\x, 5) circle(0.10cm);\n\\foreach \\y in {1, 2, 3, 4, 5}\n    {\n    \\draw[thin] (-0.075, \\y) -- (0, \\y);\n    \\node[left] at (0.0, \\y) {$\\y$};\n    }\n\\foreach \\x in {1, 2, 3, ..., 9, 10}\n    \\node[below] at (\\x, -0.04) {$\\x$};\n\\draw[-] (10, 5) -- (10, 7);\n\\draw[-] (9, 6) -- (11, 6);\n\\draw[fill=blue] (9, 6) circle(0.10cm);\n\\draw[fill=blue] (10, 6) circle(0.10cm);\n\\draw[fill=blue] (11, 6) circle(0.10cm);\n\\draw[fill=blue] (10, 5) circle(0.10cm);\n\\draw[fill=red]  (10, 7) circle(0.10cm);\n\\node at (9, 6.5) {stencil};\n\\draw[-] (3.0, 3.5) -- (5.0, 5.5) -- (7.0, 5.5) \n      -- (5.0, 3.5) -- (3.0, 3.5);\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\n\\begin{theorem}\nThe coefficients $\\alpha_1$, $\\alpha_2$, \\dots, $\\alpha_n$~and \n$\\beta_1$, $\\beta_2$, \\dots, $\\beta_n$ in the three-term \nrecurrence relation~\\eqref{eq: 3 term q} can be computed by putting\n\\[\n\\begin{aligned}\n\\sigma_{l,0}&=0&&\\text{for $2\\le l\\le 2n-1$},\\\\\n\\beta_1&=\\sqrt{\\nu_1},\\\\\n\\sigma_{l,1}&=\\frac{\\nu_l}{\\beta_1}&\n\t&\\text{for $1\\le l\\le2n$},\\\\\n\\alpha_1&=a_1+b_2\\,\\frac{\\sigma_{21}}{\\sigma_{11}},\n\\end{aligned} \n\\]\nand, for $k=1$, $2$, \\dots, $n-1$ and $k\\le l\\le2n-k-1$, \n\\[\n\\begin{aligned}\n\\beta_{k+1}&=b_{k+1}\\sqrt{1\n\t\t+\\frac{b_{k+2}}{b_{k+1}}\\,\\frac{\\sigma_{k+2,k}}{\\sigma_{kk}}\n\t\t+\\frac{a_{k+1}-\\alpha_k}{b_{k+1}}\\,\n\t\t\t\\frac{\\sigma_{k+1,k}}{\\sigma_{kk}}\n\t\t-\\frac{\\beta_k}{b_{k+1}}\\,\n\t\t\t\\frac{\\sigma_{k+1,k-1}}{\\sigma_{kk}}},\\\\\n\\sigma_{l+1,k+1}&=\\frac{b_{l+2}}{\\beta_{k+1}}\\,\\sigma_{l+2,k}\n\t+\\frac{a_{l+1}-\\alpha_k}{\\beta_{k+1}}\\sigma_{l+1,k}\n\t+\\frac{b_{l+1}}{\\beta_{k+1}}\\,\\sigma_{lk}\n\t-\\frac{\\beta_k}{\\beta_{k+1}}\\,\\sigma_{l+1,k-1},\\\\\n\\alpha_{k+1}&=a_{k+1}+b_{k+2}\\,\n\t\\frac{\\sigma_{k+2,k+1}}{\\sigma_{k+1,k+1}}\n\t-\\beta_{k+1}\\,\\frac{\\sigma_{k+1,k}}{\\sigma_{k+1,k+1}}.\n\\end{aligned}\n\\]\n\\end{theorem}\n\\begin{proof}\nThe integrals\n\\[\n\\sigma_{lk}=\\int\\hat p_{l-1}(x)\\hat q_{k-1}(x)\\,d\\nu(x)\n\\]\nsatisfy the initial conditions $\\sigma_{l,0}=0$~and \n\\[\n\\sigma_{l,1}=\\frac{\\nu_l}{\\|q_0\\|}\n\t=\\frac{\\nu_l}{\\beta_1}  \n\\quad\\text{with $\\beta_1=\\sqrt{\\nu_1}$.}\n\\]\nIn addition, $\\sigma_{lk}=0$ if $k>l$. \nFor $1\\le k\\le l$,\n\\begin{align*}\n\\beta_{k+1}\\sigma_{l+1,k+1}&=\\int\\hat p_l(x)\\bigl[\n(x-\\alpha_k)\\hat q_{k-1}(x)-\\beta_k\\hat q_{k-2}(x)\\bigr]\\,d\\nu(x)\\\\\n\t&=\\int(x-a_{l+1}+a_{l+1}-\\alpha_k)\n\t\t\\hat p_l(x)\\hat q_{k-1}(x)\\,d\\nu(x)\n\t\t-\\beta_k\\sigma_{l+1,k-1}\\\\\n\t&=\\int\\bigl[(x-a_{l+1})\\hat p_l(x)-b_{l+1}\\hat p_{l-1}(x)\\bigr]\n\t\t\\hat q_{k-1}(x)\\,d\\nu(x)\\\\\n\t&\\qquad{}+(a_{l+1}-\\alpha_k)\\sigma_{l+1,k}\n\t\t+b_{l+1}\\sigma_{lk}-\\beta_k\\sigma_{l+1,k-1}\n\\end{align*}\nso\n\\begin{equation}\\label{eq: beta sigma}\n\\beta_{k+1}\\sigma_{l+1,k+1}=b_{l+2}\\sigma_{l+2,k}\n\t+(a_{l+1}-\\alpha_k)\\sigma_ { l+1 , k }\n\t\t+b_{l+1}\\sigma_{lk}-\\beta_k\\sigma_{l+1,k-1}.\n\\end{equation}\n\nBy Theorem~\\ref{thm: 3 term}, we have \n$\\beta_{k+1}=\\|q_k\\|/\\|q_{k-1}\\|$,\nand since $q_k(x)-p_k(x)$ has degree at most~$k-1$, the orthogonality \nproperty of the $q_k$ implies that\n\\[\n\\int q_k(x)^2\\,d\\nu(x)=\\int p_k(x)q_k(x)\\,d\\nu(x)\n\t+\\int\\bigl[q_k(x)-p_k(x)\\bigr]q_k(x)\\,d\\nu(x)\n\\]\nor equivalently, $\\|q_k\\|^2=\\|p_k\\|\\|q_k\\|\\sigma_{k+1,k+1}+0$ and so\n\\begin{equation}\\label{eq: norm pk qk}\n\\|q_k\\|=\\|p_k\\|\\sigma_{k+1,k+1}.\n\\end{equation}\nThus, for $k\\ge1$,\n\\[\n\\beta_{k+1}=\\frac{\\|q_k\\|}{\\|q_{k-1}\\|}\n\t=\\frac{\\|p_k\\|}{\\|p_{k-1}\\|}\\, \n\t\t\\frac{\\sigma_{k+1,k+1}}{\\sigma_{kk}}\n\t=b_{k+1}\\,\\frac{\\sigma_{k+1,k+1}}{\\sigma_{kk}}\n\\]\nand hence, by~\\eqref{eq: beta sigma},\n\\begin{align*}\n\\beta_{k+1}^2&=\\frac{b_{k+1}}{\\sigma_{kk}}\\biggl(\n\tb_{k+2}\\sigma_{k+2,k}+(a_{k+1}-\\alpha_k)\\sigma_{k+1,k}\n\t+b_{k+1}\\sigma_{kk}-\\beta_k\\sigma_{k+1,k-1}\\biggr)\\\\\n\t&=b_{k+1}^2+\\frac{b_{k+1}}{\\sigma_{kk}}\\biggl(\n\tb_{k+2}\\sigma_{k+2,k}+(a_{k+1}-\\alpha_k)\\sigma_{k+1,k}\n\t-\\beta_k\\sigma_{k+1,k-1}\\biggr)\\\\\n\t&=b_{k+1}^2\\biggl(1\n\t\t+\\frac{b_{k+2}}{b_{k+1}}\\,\\frac{\\sigma_{k+2,k}}{\\sigma_{kk}}\n\t\t+\\frac{a_{k+1}-\\alpha_k}{b_{k+1}}\\,\n\t\t\t\\frac{\\sigma_{k+1,k}}{\\sigma_{kk}}\n\t\t-\\frac{\\beta_k}{b_{k+1}}\\,\n\t\t\t\\frac{\\sigma_{k+1,k-1}}{\\sigma_{kk}}\\biggr).\n\\end{align*}\n\nTheorem~\\ref{thm: 3 term} also gives\n$\\alpha_{k+1}=\\int x\\hat q_k(x)^2\\,d\\nu(x)$ so\n\\[\n\\|q_k\\|\\alpha_{k+1}=\\int x\\bigl[q_k(x)-p_k(x)\\bigr]\n\t\\hat q_k(x)\\,d\\nu(x)+\\int xp_k(x)\\hat q_k(x)\\,d\\nu(x),\n\\]\nwith the first term on the right equal to\n\\begin{align*}\n\\int\\bigl[&q_k(x)-p_k(x)\\bigr](x-\\alpha_{k+1})\n\t\\hat q_k(x)\\,d\\nu(x)\\\\\n\t&\\qquad\\qquad\\qquad{}\n\t+\\alpha_{k+1}\\int \n\t\t\\bigl[q_k(x)-p_k(x)\\bigr]\\hat q_k(x)\\,d\\nu(x)\\\\\n\t&=\\int\\bigl[q_k(x)-p_k(x)\\bigr]\n\t\\bigl[\\beta_{k+2}\\hat q_{k+1}(x)\n\t\t+\\beta_{k+1}\\hat q_{k-1}(x)\\bigr] \n\t\t\\,d\\nu(x)+\\alpha_{k+1}\\times0\\\\\n\t&=-\\beta_{k+1}\\int p_k(x)\\hat q_{k-1}(x)\\,d\\nu(x)\n\t=-\\beta_{k+1}\\|p_k\\|\\sigma_{k+1,k}\n\\end{align*}\nand second equal to\n\\begin{align*}\n\\int\\bigl[\n\t&(x-a_{k+1})p_k(x)-b_{k+1}^2p_{k-1}(x)\\bigr]\\hat q_k(x)\\,d\\nu(x)\\\\\n\t&\\qquad{}+\\int\\bigl[\n\t\ta_{k+1}p_k(x)+b_{k+1}^2p_{k-1}(x)\\bigr]\\hat q_k(x)\\,d\\nu(x)\\\\\n\t&=\\int p_{k+1}(x)\\hat q_k(x)\\,d\\nu(x)\n\t\t+a_{k+1}\\int p_k(x)\\hat q_k(x)\\,d\\nu(x)\\\\\n\t&=\\|p_{k+1}\\|\\sigma_{k+2,k+1}+a_{k+1}\\|p_k\\|\\sigma_{k+1,k+1}.\n\\end{align*}\nRecalling \\eqref{eq: norm pk qk}, we see that\n\\begin{multline*}\n\\|p_k\\|\\sigma_{k+1,k+1}\\alpha_{k+1}\n\t=a_{k+1}\\|p_k\\|\\sigma_{k+1,k+1}+\\|p_{k+1}\\|\\sigma_{k+2,k+1}\\\\\n\t\t-\\beta_{k+1}\\|p_k\\|\\sigma_{k+1,k}\n\\end{multline*}\nand therefore, since $\\|p_{k+1}\\|/\\|p_k\\|=b_{k+2}$,\n\\[\n\\alpha_{k+1}=a_{k+1}+b_{k+2}\\,\n\t\\frac{\\sigma_{k+2,k+1}}{\\sigma_{k+1,k+1}}\n\t-\\beta_{k+1}\\,\\frac{\\sigma_{k+1,k}}{\\sigma_{k+1,k+1}}.\n\\]\n\\end{proof}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{A log weight}\nWe now consider the example\n\\[\nd\\nu(x)=x^\\rho\\log x^{-1}\\,dx\\quad\\text{for $0<x<1$,}\n\\]\nwith $\\rho>-1$.  As our known family of orthogonal polynomials we \nuse shifted Legendre polynomials.  Recalling that the standard \nLegendre polynomials satisfy\n\\[\n\\int_{-1}^1P_j(y)P_k(y)\\,dy=\\frac{2}{2l+1},\n\\]\nwe see that the polynomials\n\\[\n\\hat p_l(x)=\\sqrt{2l+1}\\,P_l(2x-1)\n\\]\nsatisfy\n\\[\n\\int_0^1\\hat p_j(x)\\hat p_k(x)\\,dx=\\delta_{jk}.\n\\]\nThus\n\\[\n\\frac{\\nu_l}{\\sqrt{2l-1}}=\\int_0^1 P_{l-1}(2x-1)x^\\rho\\log x^{-1}\\,dx.\n\\]\nFollowing \\cite{Gautschi1979}, we make the substitution $y=2x-1$\nand obtain\n\\begin{multline*}\n\\frac{\\nu_l}{\\sqrt{2l-1}}=\\frac{\\log 2}{2^{\\rho+1}}\\int_{-1}^1 \n\tP_{l-1}(y)(y+1)^\\rho\\,dy\\\\\n\t-\\frac{1}{2^{\\rho+1}}\\int_{-1}^1 \n\t\tP_{l-1}(y)(y+1)^\\rho\\log(y+1)\\,dy.\n\\end{multline*}\nIt is known that\n\\[\n\\int_{-1}^1 P_{l-1}(y)(y+1)^\\rho\\,dy\n\t=\\frac{2^{\\rho+1}\\Gamma(\\rho+1)^2}%\n{\\Gamma(\\rho+1+l)\\Gamma(\\rho+2-l)},\n\\]\nand by logarithmic differentiation of this identity with respect \nto~$\\rho$, we find that\n\\begin{multline*}\n\\int_{-1}^1 P_{l-1}(y)(y+1)^\\rho\\log(y+1)\\,dy\n\t=\\frac{2^{\\rho+1}\\Gamma(\\rho+1)^2}%\n{\\Gamma(\\rho+1+l)\\Gamma(\\rho+2-l)}\\\\\n\t\\times\\bigl[\\log2+2\\psi(\\rho+1)-\\psi(\\rho+1+l)-\\psi(\\rho+2-l)\n\t\\bigr],\n\\end{multline*}\nwhere $\\psi(x)=\\Gamma'(x)/\\Gamma(x)$ denotes the digamma function.\nThus,\n\\begin{multline}\\label{eq: mu l}\n\\frac{\\nu_l}{\\sqrt{2l-1}}\n\t=\\frac{\\Gamma(\\rho+1)^2}{\\Gamma(\\rho+1+l)\\Gamma(\\rho+2-l)} \\\\\n\t\\times\\bigl[\\psi(\\rho+1+l)+\\psi(\\rho+2-l)-2\\psi(\\rho+1)\\bigr].\n\\end{multline}\nUsing the reflection formulae\n\\[\n\\Gamma(1-z)\\Gamma(z)=\\frac{\\pi}{\\sin\\pi z}\n\\quad\\text{and}\\quad\n\\psi(1-z)=\\psi(z)+\\pi\\cot\\pi z,\n\\]\nwe find that\n\\[\n\\lim_{z\\to m}\\frac{1}{\\Gamma(-z)}=0\n\\quad\\text{and}\\quad\n\\lim_{z\\to m}\\frac{\\psi(-z)}{\\Gamma(-z)}=(-1)^{m+1}m!\n\\]\nfor $m\\in\\{0,1,2,\\dots\\}$.  Thus, if $\\rho=r\\in\\{0,1,2,\\dots\\}$\nthen\n\\[\n\\frac{\\nu_l}{\\sqrt{2l-1}}=(-1)^{l-1-r}\\,\\frac{(r!)^2(l-r-2)!}{(l+r)!}\n\t\\quad\\text{for $l\\in\\{r+2, r+3, r+4, \\dots\\}$.}\n\\]\nOtherwise, we can use the functional identities\n\\[\n\\Gamma(z+1)=z\\Gamma(z)\\quad\\text{and}\\quad\n\\psi(z+1)=\\psi(z)+\\frac{1}{z}\n\\]\nto simplify \\eqref{eq: mu l}.  In fact,\n\\[\n\\Gamma(\\rho+1)=\\rho(\\rho-1)\\cdots(\\rho+2-l)\\Gamma(\\rho+2-l)\n\\]\nand\n\\[\n\\Gamma(\\rho+1+l)=(\\rho+l)(\\rho+l-1)\\cdots(\\rho+2)(\\rho+1)\n\t\\Gamma(\\rho+1),\n\\]\nso\n\\begin{align*}\n\\frac{\\Gamma(\\rho+1)^2}{\\Gamma(\\rho+1+l)\\Gamma(\\rho+2-l)}\n\t&=\\frac{\\rho(\\rho-1)\\cdots(\\rho+2-l)}%\n{(\\rho+l)(\\rho+l-1)\\cdots(\\rho+2)(\\rho+1)}\\\\\n\t&=\\frac{1}{\\rho+1}\\prod_{j=1}^{l-1}\\frac{\\rho+1-j}{\\rho+1+j}.\n\\end{align*}\nMoreover,\n\\[\n\\psi(\\rho+1+l)=\\psi(\\rho+1)+\\frac{1}{\\rho+1}+\\frac{1}{\\rho+2}\n\t+\\cdots+\\frac{1}{\\rho+l}\n\\]\nand\n\\[\n\\psi(\\rho+2-l)=\\psi(\\rho+1)-\\frac{1}{\\rho}-\\frac{1}{\\rho-1}\n\t-\\cdots-\\frac{1}{\\rho-(l-2)},\n\\]\nso\n\\[\n\\psi(\\rho+1+l)+\\psi(\\rho+2-l)-2\\psi(\\rho+1)\n\t=\\frac{1}{\\rho+1}+\\sum_{j=1}^{l-1}\\biggl(\\frac{1}{\\rho+1+j}\n\t\t-\\frac{1}{\\rho+1-j}\\biggr).\n\\]\nHence,\n\\begin{equation}\\label{eq: nul}\n\\frac{\\nu_l}{\\sqrt{2l-1}}=\\frac{1}{\\rho+1}\\biggl[\\frac{1}{\\rho+1}\n\t+\\sum_{j=1}^{l-1}\\biggl(\\frac{1}{\\rho+1+j}\n\t\t-\\frac{1}{\\rho+1-j}\\biggr)\\biggr]\n\t\\prod_{k=1}^{l-1}\\frac{\\rho+1-k}{\\rho+1+k}.\n\\end{equation}\n\nChoose a non-negative integer~$r$ such that $|\\rho-r|$ is as small as \npossible, and define\n\\[\nB_l=\\prod_{\\substack{k=1\\\\ k\\ne r+1}}^{l-1}\\frac{\\rho+1-k}{\\rho+1+k}\n\\]\nso that\n\\[\n\\prod_{k=1}^{l-1}\\frac{\\rho+1+k}{\\rho+1-k}\n\t=\\frac{\\rho-r}{\\rho+r+2}\\,B_l\\quad\\text{for $l\\ge r+2$.}\n\\]\nWe can rewrite \\eqref{eq: nul} as\n\\[\n\\frac{\\nu_l}{\\sqrt{2l-1}}=\\frac{B_l}{1+\\rho}\\biggl[\n\t\\frac{1}{1+\\rho}+\\sum_{j=1}^{l-1}\n\t\\biggl(\\frac{1}{\\rho+1+j}-\\frac{1}{\\rho+1-j}\\biggr)\n\t\t\\biggr]\\quad\\text{for $1\\le l\\le r+1$,}\n\\]\nwith\n\\begin{multline*}\n\\frac{\\nu_l}{\\sqrt{2l-1}}=\\frac{B_l}{1+\\rho}\\,\\frac{\\rho-r}{\\rho+r+2}\n\t\\biggl[\\frac{1}{1+\\rho}\n\t+\\sum_{\\substack{j=1\\\\ j\\ne r+1}}^{l-1}\\biggl(\n\t\\frac{1}{\\rho+1+j}-\\frac{1}{\\rho+1-j}\\biggr)\\biggr]\\\\\n+\\frac{B_l}{1+\\rho}\\,\\frac{1}{\\rho+r+2}\n\t\\biggl(\\frac{\\rho-r}{\\rho+r+2}-1\\biggr)\n\t\t\\quad\\text{for $l\\ge r+2$.}\n\\end{multline*}\n\n\nIf $\\rho=r$ then we can use the formula~\\eqref{eq: nul} to compute\n$\\nu_l$ for $1\\le l\\le r+1$.  Next, for $l=r+2$,\n\\[\n\\frac{\\nu_{r+2}}{\\sqrt{2r+3}}\n\t=-\\,\\frac{(r!)^2}{(2r+2)!}=\\frac{-1}{2(r+1) }\n\t\\prod_{j=1}^r\\frac{j}{2(2j+1)},\n\\]\nand after that we have the recursion\n\\[\n\\frac{\\nu_{l+1}}{\\sqrt{2l+1}}=-\\frac{l-r-1}{l+r+1}\\,\n\t\\frac{\\nu_l}{\\sqrt{2l-1}}\n\t\\quad\\text{for $l\\ge r+2$,}\n\\]\nor equivalently,\n\\[\n\\nu_{l+1}=-\\nu_l\\times\\frac{l-r-1}{l+r+1}\\,\\sqrt{\\frac{2l+1}{2l-1}}\n\t\\quad\\text{for $l\\ge r+2$.}\n\\]\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\bibliographystyle{plain}\n\\bibliography{notes_refs}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\end{document}\n\\endinput\n", "meta": {"hexsha": "190c96f3ccf99608139cad721e173cd6659b5c90", "size": 25916, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/notes.tex", "max_stars_repo_name": "lcw/GaussQuadrature.jl", "max_stars_repo_head_hexsha": "b886776942e489f74a97176db8dca82e15f03f8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2015-06-15T12:23:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T10:20:25.000Z", "max_issues_repo_path": "doc/notes.tex", "max_issues_repo_name": "lcw/GaussQuadrature.jl", "max_issues_repo_head_hexsha": "b886776942e489f74a97176db8dca82e15f03f8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2015-07-11T09:07:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-19T07:12:15.000Z", "max_forks_repo_path": "doc/notes.tex", "max_forks_repo_name": "lcw/GaussQuadrature.jl", "max_forks_repo_head_hexsha": "b886776942e489f74a97176db8dca82e15f03f8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-06-15T12:23:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-28T18:10:50.000Z", "avg_line_length": 31.489671932, "max_line_length": 70, "alphanum_fraction": 0.598973607, "num_tokens": 12001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580806813576, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.6884225329025386}}
{"text": "%  -----------------------------------------------------------------------------\n%  Author         : Bimalka Piyaruwan Thalagala\n%  GitHub         : https://github.com/bimalka98\n%  Date Created   : 01.09.2020\n%  Last Modified  : 18.02.2020\n%  -----------------------------------------------------------------------------\n\n\\documentclass[a4paper,11pt]{article}%,twocolumn\n\\input{settings/packages}\n\\input{settings/page}\n\\input{settings/macros}\n\n\n\\begin{document}\n\n\\input{content/title_page}\n\\tableofcontents\n\n\\begin{center}\n\t\\textbf{\\textit{* PDF is clickable}}\n\\end{center}\n\\vspace{1cm}\n\\hrule\n\n\n%%-----------------------------------------------------------------------\n\n\n\\section{Computer Vision: Detecting Corners/Features of an Image}\n\n\\textit{\\large \\textbf{Related Concepts in Linear Algebra:} Eigenvalues, Eigenvectors, Characteristic Polynomial, Quadratic Forms, Principal Axis Theorem, Orthogonal matrix, Diagonalization}\n\n\\subsection{Problem Identification}\n\nIn computer vision field finding corners/features in an image($I(x, y)$) is a key operation which is done prior to many advanced applications such as feature mapping, panorama stitching and 3D reconstruction. A corner can be identified as a point in an image whose neighborhood is locally unique to the given image. When comparing this neighborhood with any of the surrounding neighborhoods, significant difference can be observed between them.\\\\\n\nThis difference can be quantified mathematically using the following function evaluated over a region called a window($W$). Here the most basic Error function is used to make the explanation easy, and this may vary in different implementation of corner detection algorithms.\n\n\\begin{equation}\n\tE(u,v) = \\sum_{(x,y) \\in W}[I(x+u, y+v) – I(x, y)]^2\n\\end{equation}\n\nThis function can be further simplified using Taylor series and can be rearranged to get an expression in the \\textbf{\\textit{Quadratic form associated with $M$}} where the $M$ is called the \\textit{\\textbf{Second Moment Matrix}} which consists of summation of quadratic forms of gradients of the image over a window centered at the point of interest. Here gradient of the image along x axis is $I_{x}$ while $I_{y}$ is the gradient along y axis.\n\n\\begin{equation}\n\t \\begin{split}\n\t\t \tE(u,v) &= \\sum_{(x,y) \\in W}[I_{x}^{2}.u^{2}+2.I_{x}.I_{y}.u.v + I_{y}^{2}.v^{2}]\\\\\n\t\t \t&= \\begin{bmatrix} u & v \\end{bmatrix}\n\t\t \t \\begin{bmatrix}\n\t\t \t \t\\sum_{(x,y) \\in W}[I_x ^2 ]& \\sum_{(x,y) \\in W}[I_x I_y]  \\\\ \\sum_{(x,y) \\in W}[I_x I_y]& \\sum_{(x,y) \\in W}[I_y ^2 ]\n\t \t \t\\end{bmatrix}\n\t\t \t\\begin{bmatrix} u \\\\ v \\end{bmatrix}\\\\\n\t\t \t&=\\begin{bmatrix} u & v \\end{bmatrix}M\\begin{bmatrix} u \\\\ v \\end{bmatrix}\\\\\n\t\t \tE(\\underline{x})&= \\underline{x}^\\top M \\underline{x}\n\t \\end{split}\n  \\label{euv}\n \\end{equation}\n\nThe plot of the above function looks like follows for a given point where the $\\sum_{(x,y) \\in W}[I_x ^2 ]= 105983042.0$, $\\sum_{(x,y) \\in W}[I_x I_y]=13718014.0$ and $\\sum_{(x,y) \\in W}[I_y ^2 ]=105671174.0$\\cite{cv}. (\\textit{These values correspond to an actual corner in the Figure \\ref{corners}}). If the point of interest is a corner it will give a very large Error ($E(u,v)$) value even for a very low ($u,v$) shift in any direction. This can be intuitively recognized as a steep surface(more narrower bowl shape) as depicted in Figure \\ref{euvsurf}.\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\subfigure[Surface Plot of $E(u,v)$]\n\t{ \\includegraphics[scale=0.67]{figures/euvsurf}\n\\label{euvsurf}\n}\\hfill\n\t\\subfigure[Contour Plot(Horizontal Slices) of $E(u,v)$]\n\t{ \\includegraphics[scale=0.67]{figures/euvcontour}\n\\label{euvcontour}\n}\n\t\\caption{Error Function E(u,v) }\n\n\\end{figure}\n\n\n\n\\subsection{Solution through concepts of Linear Algebra}\n\nThis narrowness can be mathematically quantified by examining a horizontal slice of the surface plot in figure \\ref{euvsurf}. Consider one particular contour in Figure \\ref{euvcontour}, then along that contour, function value is a constant i.e $E(\\underline{x}) = constant = \\underline{x}^\\top M \\underline{x}$ and then the above Expression \\ref{euv} represents equation of an ellipse. \\textit{If the surface is narrow, the radii of the ellipse must be small for a given $E(u,v)$ value.} That is function value must increase rapidly as we moves outward from the point of interest. Lengths of the major and minor axes(radii) of the ellipse are given by $\\lambda_{min}^{-\\frac{1}{2}}$ and $\\lambda_{max}^{-\\frac{1}{2}}$ respectively, where the $\\lambda_{min}$ and $\\lambda_{max}$ are the \\textbf{\\textit{eigenvalues associated with the second moment matrix $M$}}. We can prove this as follows\\cite{corner}.\\\\\n\nSince $M$ is a symmetric matrix, an \\textbf{\\textit{Orthogonal($P^\\top=P^{-1}$) matrix}} $P$ can be found such that $\\underline{x} = P\\underline{y}$  which transforms $E(\\underline{x}) = \\underline{x}^\\top M \\underline{x}$ into the form  $E(\\underline{y}) = \\underline{y}^\\top D \\underline{y}$ where $D$ is a diagonal matrix consists of the eigenvalues of the $M$. The columns of matrix $P$ consists of the \\textbf{\\textit{eigenvectors}} associated with the eigenvalues of the second moment matrix $M$.\n\n\\begin{equation}\n\t\\begin{split}\nE(\\underline{x}) &= \\underline{x}^\\top M \\underline{x}\\\\\n&= (P\\underline{y})^\\top M (P\\underline{y})\\\\\n&= (\\underline{y}^\\top P^\\top) M (P\\underline{y})\\\\\n&= \\underline{y}^\\top (P^\\top M P)\\underline{y}\\\\\n&= \\underline{y}^\\top D \\underline{y}\\\\\nE({y_{1},y_{2}})&= \\begin{bmatrix} y_{1} & y_{2} \\end{bmatrix}\n\\begin{bmatrix}\n\t\\lambda_{min} & 0  \\\\ 0 & \\lambda_{max}\n\\end{bmatrix}\n\\begin{bmatrix} y_{1} \\\\ y_{2} \\end{bmatrix}\\\\\n\t \\end{split}\n \\label{orthdiag}\n\\end{equation}\n\nComparing result of Expression \\ref{orthdiag} with the standard form of an ellipse,\n\n\\begin{equation}\n\t\\begin{split}\n\t\t{\\frac{x^2}{a^2} + \\frac{y^2}{b^2}} &= {\\begin{bmatrix} x & y \\end{bmatrix}\n\t\t\\begin{bmatrix} 1/a^2 & 0 \\\\ 0 & 1/b^2 \\end{bmatrix}\n\t\t\\begin{bmatrix} x \\\\ y \\end{bmatrix}} \\\\\n &= {\\begin{bmatrix} y_{1} & y_{2} \\end{bmatrix}\n\t\t\\begin{bmatrix}\\lambda_{min} & 0  \\\\ 0 & \\lambda_{max} \\end{bmatrix}\n\t\t\\begin{bmatrix} y_{1} \\\\ y_{2} \\end{bmatrix}}\\\\\n\t\\end{split}\n\\end{equation}\n\nTherefore, $1/a^2 = \\lambda_{min}$ and $1/b^2 = \\lambda_{max}$. Which yields that\n$a = \\lambda_{min}^{-\\frac{1}{2}}$ and $b = \\lambda_{max}^{-\\frac{1}{2}}$.\\\\\n\nTherefore to find corners in an image all we have to do is find the \\textbf{\\textit{eigenvalues}} associated with each second moment matrix for each pixel$(x,y)$ in an image. According to the magnitudes of eigenvalues following classification can be done.\n\n\\begin{enumerate}[a.)]\n\t\\item  \\textbf{At a Corner:} $E(u,v)$ increases rapidly in any direction and therefore \\textit{both eigenvalues are large}.\n\t\\item \t\\textbf{At an Edge:}  $E(u,v)$ increases rapidly only in one direction and therefore \\textit{one eigenvalue is relatively larger than the other}.\n\t\\item \\textbf{At a flat area:} $E(u,v)$ does not increase rapidly and therefore \\textit{both eigenvalues are small}.\n\\end{enumerate}\n\n\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[scale= 0.3]{figures/corner}\n\\caption{Detecting corners in an image, Step by Step approach\\cite{cv}}\n\\label{corners}\n\\end{figure}\n\nCalculating eigenvalues is computationally expensive therefore what is known as Corner Response Function(R) is used when implementing algorithms. Here $\\alpha$ $\\in$ [0.04,0.06] and \\textbf{At a Corner:} R $\\gg$ 0, \\textbf{At an Edge:} R $<$ 0, \\textbf{At a flat area:} $|R|$ is small. Therefore corners can be extracted by applying an appropriate threshold value for R.\n\n\\begin{equation}\n\t\\begin{split}\nR &= det(M) - \\alpha* trace(M)^2\\\\\n & = \\lambda_{min}*\\lambda_{max} - \\alpha*(\\lambda_{max} + \\lambda_{min})^2\n\t\\end{split}\n\\end{equation}\n\n\n\n\n\\pagebreak\n\n\\section{Robotic Systems: Coordinate frame Transformation}\n\n\\textit{\\large \\textbf{Related Concepts in Linear Algebra:} Linear Transformations, Matrix Transformations, Change of basis, Matrix Multiplication}\n\n\\subsection{Problem Identification}\n\nWhen robot arms are used in industrial activities, robot engineer needs to make sure the \\textbf{\\textit{end-effector}}(\\textit{gripper or any other tool attached at the end of the arm}) of the robot arm is at the exact location in the exact orientation at the operation. Otherwise the required behavior of the arm can not be obtained. Problem is usually robot takes the measurements using sensors or cameras placed somewhere else in the system and therefore these measurements(\\textbf{\\textit{position vectors}}) are in with respect to those sensor's or camera's coordinate frame while the robot arm operates with respect to some other(Robot base) coordinate frame. Flowing figure illustrates this situation.\\\\\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\subfigure[Robotic System]\n\t{ \\includegraphics[scale=0.67]{figures/env}\t\t\n\t}\\hfill\n\t\\subfigure[Coordinate Systems]\n\t{ \\includegraphics[scale=0.67]{figures/difcord}\t\t\n\t}\n\t\\caption{Use of Different Coordinate systems in an Industrial Robotic System\\cite{pics}}\t\n\\end{figure}\n\nTherefore to make use of the information gathered by the sensors/cameras first we need to \\textbf{\\textit{transform}} position vectors gathered by camera with respect to its coordinate frame, in to robot arm's base coordinate frame. Then we can use inverse kinematics to calculate the required rotation angles and translations that we should provide to the arm to get the required behavior. \n\n\\subsection{Solution through concepts of Linear Algebra}\n\nIn order to fully describe an object in the 3D world we need its \\textit{\\textbf{Rotation and Translation}} with respect to some reference(\\textit{in this case the robot arm}) coordinate frame(say $\\alpha$). For that the object of interest(\\textit{in this case the sensor/camera}) must be given its own coordinate frame(say $\\beta$) too. The mathematical way to represent differences between the reference frame and the object's frame is called the \\textbf{\\textit{Homogeneous Transformation Matrix}}\\cite{robotic} in Robotics and it is denoted as,\n\n\\begin{center}\n\t$ H^{\\alpha}_{\\beta} $ : read as transformation of frame $\\beta$ with respect to the frame $\\alpha$\n\\end{center}\n\nThis \t$ H^{\\alpha}_{\\beta} $ can be mathematically represented as a $4 \\times 4$ matrix which consists of $3 \\times 3$ Rotation matrix and a $3 \\times 1$ Translation matrix with last row as $[0~0~0~1]$ to make it  $4 \\times 4$ square matrix to make the computation easy.\n\n\\begin{equation}\n\t\\begin{split}\n\t\t H^{\\alpha}_{\\beta} &=\n\t\t\t\\begin{bmatrix}\n\t\t\t\t r_{11} & r_{12} & r_{13} & d_1 \\\\\n\t\t\t\t r_{21} & r_{22} & r_{23} & d_2 \\\\\n\t\t\t\t r_{31} & r_{32} & r_{33} & d_3 \\\\\n\t\t\t\t 0 & 0 & 0 &1 \\\\\n\t\t\t\\end{bmatrix}\n\t\\end{split}\n\\end{equation}\n\nThere are  \\textbf{\\textit{6 Principal Movements}} as, rotations about 3 axes(X,Y,Z) and translations along 3 axes(X,Y,Z). Correct combination(\\textit{obtain by multiplying required principal matrices like $Rot(e_i,\\theta_m)*Trans(e_j,d_k)$}) of these 6 principal movements  can be used to get any of the advanced transformations, from the reference frame to object's frame. Those basic matrices are as follows where $e_i$ refers to the elements in standard \\textbf{\\textit{basis}}( $e_1 = [1 ~0~ 0]^\\top$, $e_2 = [0 ~1~ 0]^\\top$ and $e_3 = [0 ~0~ 1]^\\top$) while $\\theta_i$ indicates how many degrees the object has rotated about the $e_i$ basis vector. Additionally $d_i$ indicates the displacement along the direction of $e_i$ basis vector(axis)\\cite{tfs1}. \\\\\n\n\\begin{center}\n\t\\begin{tabular}{| c || c|}\n\t\t\\hline\n \\textbf{Principal Rotations about axes(X,Y,Z)\\cite{tfs2}} &\t\\textbf{Principal Translations along axes(X,Y,Z)\\cite{tfs2}}\\\\\\hline\n \t\t&\\\\\n\t\t$Rot(e_1,\\theta_1) =\n\\begin{bmatrix}\n\t1 & 0 & 0 & 0 \\\\\n\t0 & \\cos(\\theta_1) & -\\sin(\\theta_1) & 0 \\\\\n\t0 & \\sin(\\theta_1) & \\cos(\\theta_1) & 0 \\\\\n\t0 & 0 & 0 &1 \\\\\n\\end{bmatrix}$ & \n\t\t$Trans(e_1,d_1)=\n\\begin{bmatrix}\n\t1 & 0 &0  & d_1 \\\\\n\t0 & 1 & 0 & 0 \\\\\n\t0 & 0 & 1 & 0 \\\\\n\t0 & 0 &0  & 1 \\\\\n\\end{bmatrix}$\n\\\\[1cm]\n%--------------------------------------------------------------------------\n$Rot(e_2,\\theta_1) =\n\\begin{bmatrix}\n\\cos(\\theta_1)\t& 0 & \\sin(\\theta_1)  & 0 \\\\\n0\t& 1 & 0 & 0 \\\\\n-\\sin(\\theta_1)\t& 0 & \\cos(\\theta_1) & 0 \\\\\n0 & 0 & 0 &1 \\\\\n\\end{bmatrix}$ & \n\t\t$Trans(e_2,d_2) =\n\\begin{bmatrix}\n\t1 & 0 &0  & 0 \\\\\n\t0 & 1 & 0 & d_2 \\\\\n\t0 & 0 & 1 & 0 \\\\\n\t0 & 0 & 0 & 1 \\\\\n\\end{bmatrix}$\n\\\\[1cm]\n%--------------------------------------------------------------------------\n$Rot(e_3,\\theta_1) =\n\\begin{bmatrix}\n\t\\cos(\\theta_1) & -\\sin(\\theta_1)&0  & 0 \\\\\n\t\\sin(\\theta_1) & \\cos(\\theta_1)   &0  & 0 \\\\\n\t0&0  &1  & 0 \\\\\n\t0 & 0 & 0 &1 \\\\\n\\end{bmatrix}$ & \n\t\t$Trans(e_3,d_3) =\n\\begin{bmatrix}\n\t1 & 0 &0  & 0 \\\\\n\t0 & 1 & 0 & 0 \\\\\n\t0 & 0 & 1 & d_3 \\\\ \n\t0 & 0 & 0 & 1 \\\\\n\\end{bmatrix}$\\\\\n\t\t&\\\\\\hline\\hline\n\\end{tabular}\n\\end{center}\n\nOnce we construct the \\textbf{\\textit{Homogeneous Transformation Matrix which transforms robot base frame  into camera frame}}, we just have to multiply the position vectors obtained w.r.t camera frame by this transformation matrix to get the corresponding position vectors in the robot base frame. Let  $^1u = [u_1 ~u_2~ u_3~1]^\\top$ be a  position vector(homogeneous) of an object in the camera frame and  $H^{0}_{1}$ be the homogeneous transformation matrix, then the position vector of the object in the robot base frame is\\cite{tfs3}, say $^0u$\n\n\\begin{equation}\n\t\\begin{split}\n\t\t^0u &= H^{0}_{1}* ^1u\\\\\n\t\t^0u &=\n\t\t{\\begin{bmatrix}\n\t\t\tr_{11} & r_{12} & r_{13} & d_1 \\\\\n\t\t\tr_{21} & r_{22} & r_{23} & d_2 \\\\\n\t\t\tr_{31} & r_{32} & r_{33} & d_3 \\\\\n\t\t\t0 & 0 & 0 &1 \\\\\n\t\t\\end{bmatrix}} * \\begin{bmatrix} u_1 \\\\u_2\\\\ u_3\\\\1 \\end{bmatrix}\n\t\\end{split}\n\\end{equation}\n\nMoreover, since the Homogeneous Transformation Matrix is invertible, following expression is also valid which makes it possible to move between coordinate systems easily.\n\\begin{equation}\n{H^{0}_{1}}^{-1} = H^{1}_{0}\n\\end{equation}\n\n\\vfill\n\\vspace{1cm}\n\\hrule\n\n\\scriptsize\n\\begin{flushleft}\n\t\\bibliographystyle{plain}\n\\bibliography{refer}\n\\end{flushleft}\n\\end{document}\n", "meta": {"hexsha": "061e2cc00cb8719c4cc61700e0531641aad3f8c5", "size": 13966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Document.tex", "max_stars_repo_name": "bimalka98/Applications-of-Linear-Algebra", "max_stars_repo_head_hexsha": "8cfad8ca89006f6d61df7d3b80ba1468c73dc18f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-21T07:55:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T07:55:51.000Z", "max_issues_repo_path": "Document.tex", "max_issues_repo_name": "bimalka98/Applications-of-Linear-Algebra", "max_issues_repo_head_hexsha": "8cfad8ca89006f6d61df7d3b80ba1468c73dc18f", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "bimalka98/Applications-of-Linear-Algebra", "max_forks_repo_head_hexsha": "8cfad8ca89006f6d61df7d3b80ba1468c73dc18f", "max_forks_repo_licenses": ["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.7854545455, "max_line_length": 906, "alphanum_fraction": 0.6809394243, "num_tokens": 4360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.6884177996754076}}
{"text": "\\section{Eigenvectors, Eigenvalues and Diagonal Matrices}\r\nThis is the first step into the wonderful land of diagonalisation of endomorphisms.\r\nConsider a vector space $V$ over $F$ with $\\dim V=n<\\infty$ and let $\\alpha:V\\to V$ be an endomorphism.\r\nThe general problem is whether we can find a basis $B$ of $V$ such that $[\\alpha]_B$ is in a nice enough form.\r\nIn other words, by our change-of-basis formula, we want to know when can a matrix be conjugate to another matrix in a nice form.\r\n\\begin{definition}\r\n    1. $\\alpha\\in L(V)=L(V,V)$ is diagonalisable if there exists a basis $B$ of $V$ such that $[\\alpha]_B$ is diagonal, i.e. $([\\alpha]_B)_{ij}=0$ for $i\\neq j$.\\\\\r\n    2. $\\alpha\\in L(V)$ is triangulable if there exists a basis $B$ of $V$ such that $[\\alpha]_B$ is (upper) triangular.\r\n\\end{definition}\r\n\\begin{remark}\r\n    A matrix is diagonalisable (resp. triangulable) iff it is conjugate to a diagonal (resp. triangular) matrix.\r\n\\end{remark}\r\n\\begin{definition}\r\n    1. $\\lambda\\in F$ is an eigenvalue of $\\alpha$ if $\\alpha(v)=\\lambda v$ for some $v\\neq 0$.\\\\\r\n    2. $v\\in V$ is an eigenvector of $\\alpha$ if $v\\neq 0$ and there exists some $\\lambda\\in F$ such that $\\alpha(v)=\\lambda v$.\\\\\r\n    3. $V_\\lambda=\\{v\\in V:\\alpha(v)=\\lambda v\\}\\le V$ is called the eigenspace of $\\alpha$ associated to $\\lambda$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $\\alpha\\in L(V)$ and $\\lambda\\in F$, then $\\lambda$ is an eigenvalue iff $\\det(\\alpha-\\lambda\\operatorname{id}_V)=0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Follows from the fact that matrices with nonzero determinant have zero kernel.\r\n\\end{proof}\r\n\\begin{remark}\r\n    If $\\alpha(v_j)=\\lambda v_j$ for $v_j\\neq 0$, then completing it into a basis $B=\\{v_1,\\ldots,v_j,\\ldots,v_n\\}$ of $V$ gives $([\\alpha]_B)_{ij}=\\lambda\\delta_{ij}$.\r\n\\end{remark}\r\nRecall that for a field $F$, a polynomail in $F$ is $f(t)=a_nt^n+\\cdots+a_0\\in F[t]$ with $a_i\\in F$.\r\nLet $\\deg f$ be the largest $m$ such that $a_m\\neq 0$, then we know that $\\deg(f+g)\\le\\max\\{\\deg f,\\deg g\\}$ and $\\deg(fg)=\\deg(f)+\\deg(g)$.\r\nWe say $\\lambda$ is a root of $f$ iff $f(\\lambda)=0$, and $g(t)$ divides $f(t)$ if there is some $q(t)\\in F[t]$ such that $f(t)=g(t)q(t)$.\r\n\\begin{lemma}\r\n    If $\\lambda$ is a root of $f$, then $x-\\lambda$ divides $f$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write $f(t)=f(t)-f(\\lambda)$ and factrorise.\r\n\\end{proof}\r\n\\begin{remark}\r\n    We say $\\lambda$ is a root of multiplicity $k$ if $(t-\\lambda)^k$ divides $f$ but $(t-\\lambda)^{k+1}$ does not.\r\n\\end{remark}\r\n\\begin{example}\r\n    $f(t)=(t-1)^2(t-2)^3$ has roots $1$ with multiplicity $2$ and $2$ with multiplicity $3$.\r\n\\end{example}\r\n\\begin{corollary}\r\n    A polynomial of degree $n$ has at most $n$ roots, counted with multiplicity.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Induction.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    For polynomials $f_1,f_2$ of degree less than $n$ with $f_1(t_i)=f_2(t_i)$ for distinct $t_1,\\ldots,t_n$, then $f_1=f_2$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $\\deg(f_1-f_2)<n$.\r\n\\end{proof}\r\n\\begin{theorem}[Fundamental Theorem of Algebra]\r\n    Any polynomial $f\\in \\mathbb C[t]$ of positive degree has a root.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\nConsequently, $f$ has exactly $\\deg f$ many roots counted with multplicity.\r\nThis means that any $f\\in\\mathbb C[t]$ can be written as\r\n$$f(t)=c\\prod_{i=1}^n(t-\\lambda_i)^{\\alpha_i},c,\\lambda_i\\in\\mathbb C,\\alpha_i\\in\\mathbb N, \\sum_{i=1}^n\\alpha_i=\\deg f$$\r\n\\begin{definition}\r\n    For $\\alpha\\in L(V)$, the characteristic polynomial of $\\alpha$ is $\\chi_\\alpha(t)=\\det(\\alpha-t\\operatorname{id}_V)\\in F[t]$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Conjugate matrices then have the same characteristic polynomial.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    $\\alpha\\in L(V)$ is triangulable iff\r\n    $$\\chi_\\alpha(t)=c\\prod_{i=1}^n(t-\\lambda_i)$$\r\n    for some $c,\\lambda_i\\in F$.\r\n\\end{theorem}\r\nConsequently, any matrix in $\\mathbb C$ is triangulable.\r\n\\begin{proof}\r\n    The ``only if'' part is trivial.\r\n    For the ``if'' direction, we do induction on $n=\\dim V$.\r\n    The $n=1$ case is trivial.\r\n    For $n>1$, there is $\\lambda$ such that $\\chi_\\alpha(\\lambda)=0$ by assumption.\r\n    Let $\\{v_1,\\ldots,v_k\\}$ be a basis of $U=V_\\lambda$ and extend it to a basis $B=\\{v_1,\\ldots,v_n\\}$ of $V$.\r\n    We then have\r\n    $$[\\alpha]_B=\\left( \\begin{array}{c|c}\r\n        I_k&\\ast\\\\ \\hline\r\n        0&C\r\n    \\end{array} \\right)$$\r\n    So the induced endomorphism $\\bar\\alpha:V/U\\to V/U$ has matrix $C$ under the basis $\\{v_{k+1}+U,\\ldots,v_n+U\\}$.\r\n    Then by the induction hypothesis, we can choose another set of basis $\\{\\tilde{v}_{k+1}+U,\\ldots,\\tilde{v}_n+U\\}$ so that $C$ is triangular.\r\n    Hence $\\alpha$ is triangular under the basis $\\{v_1,\\ldots,v_k,\\tilde{v}_{k+1},\\ldots,\\tilde{v}_n\\}$.\r\n    This completes the proof.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Suppose $V$ is a vector space over $F=\\mathbb R$ or $\\mathbb C$ such that $\\dim V=n<\\infty$ and suppose $\\alpha\\in L(V)$ is an endomorphism with matrix $A$.\r\n    Say $\\chi_\\alpha(t)=(-1)^nt^n+c_{n-1}t^{n-1}+\\cdots+c_0$, then $c_0=\\det A$, $c_{n-1}=(-1)^{n-1}\\operatorname{tr}A$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $\\det A=\\chi_A(0)=c_0$.\r\n    For $c_{n-1}$, note that the statement is true for triangular $A$, so we are done by the preceding theorem.\r\n\\end{proof}\r\n", "meta": {"hexsha": "9c96829654cd2817428196c5fdceed27ddf1dbc4", "size": 5315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14/eigen.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": "14/eigen.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": "14/eigen.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": 53.6868686869, "max_line_length": 169, "alphanum_fraction": 0.6485418627, "num_tokens": 1855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.6884012272690568}}
{"text": "\\section{Countability}\r\nWe want to find a way to describe the sizes of infinite sets.\r\nFor example, $\\mathbb N$ ``looks smaller'' than $\\mathbb Z,\\mathbb Q, \\mathbb R$, but is that the case?\r\n\\begin{definition}\r\n    A set $A$ is called countable if either $A$ is finite or there exists a bijection $A\\to\\mathbb N$.\r\n\\end{definition}\r\nEquivalently, $A$ is countable iff we can list the element of $A$ as $\\{a_1,a_2,a_3,\\ldots\\}$ (which might terminate if $A$ is finite).\r\n\\begin{example}\r\n    1. Every finite set is countable.\\\\\r\n    2. $\\mathbb N$ is countable.\\\\\r\n    3. $\\mathbb Z$ is countable.\r\n    Consider the listing $\\{0,1,-1,2,-2,3,-3,\\ldots\\}$.\r\n    Or, written in formula\r\n    $$a_n=\r\n    \\begin{cases}\r\n        n/2\\text{, if $n$ is even}\\\\\r\n        (1-n)/2\\text{, if $n$ is odd}\r\n    \\end{cases}$$\r\n\\end{example}\r\nA natural question to ask, following the last example, is whether all sets are countable.\r\nFor example, is $\\mathbb Q$ countable?\r\nHow about $\\mathbb R$?\r\n\\begin{proposition}\r\n    Let $A$ be a set, then $A$ is countable iff there is an injection $f:A\\to\\mathbb N$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $A$ is countable, it is obvious that there is an injection.\\\\\r\n    Conversely, it is done if $A$ is finite, so we can henceforth assume that $A$ is infinite.\r\n    Note that $f(A)=\\operatorname{Im}f$ is a subset of $\\mathbb N$ and $f$ is a bijection $A\\to f(A)$.\r\n    So it is enough to show that $f(A)$ is countable.\r\n    We can order $f(A)$ like we did in $\\mathbb N$, then define $b_n$ recursively by $b_1=\\min f(A)$ and $b_{n+1}=\\min (f(A)\\setminus\\{b_i:1\\le i\\le n\\})$.\r\n    So the sequence $\\{b_n\\}_{n\\in\\mathbb N}$ lists $f(A)$, hence $f(A)$ is countable, so $A$ is countable.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Every subset of a countable is countable.\r\n\\end{corollary}\r\n\\begin{remark}\r\n    Consider the set $\\{n/(n+1):n\\in\\mathbb N\\}\\cup\\{1\\}\\subset \\mathbb R$, then this set is countable, but we cannot hit everything by writing every element in increasing order.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    $\\mathbb N\\times\\mathbb N$ is countable.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Define the listing $a_1,a_2,\\ldots\\in\\mathbb N\\times\\mathbb N$ by $a_1=(1,1)$ and if we have $a_n=(p,q)$, then\r\n    $$a_{n+1}=\\begin{cases}\r\n        (p-1,q+1)\\text{, if $p>1$}\\\\\r\n        (p+q,1)\\text{, otherwise}\r\n    \\end{cases}$$\r\n    This lists all points in $\\mathbb N\\times\\mathbb N$.\r\n    All $(x,y)\\in\\mathbb N\\times\\mathbb N$ are hit by induction on $x+y$.\r\n\\end{proof}\r\n\\begin{proof}[Alternative proof]\r\n    Consider the map $f:\\mathbb N\\times\\mathbb N\\to\\mathbb N$ by $(a,b)\\mapsto 2^a3^b$ is an injection.\r\n\\end{proof}\r\nMore generally, the same shows\r\n\\begin{corollary}\\label{union_countable}\r\n    Let $\\{A_i\\}_{i\\in\\mathbb N}$ be a collection of countable sets, then $\\bigcup_{i\\in \\mathbb N}A_i$ is countable.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Each $A_i$ is countable, so we can list $A_i$ as $\\{a_{i1},a_{i2},\\ldots\\}$ (which might terminate if $A_i$ is finite).\r\n    Now consider the function $f:\\bigcup_{i\\in \\mathbb N}A_i\\to\\mathbb N$ by $x\\mapsto 2^i3^j$ where $x=a_{ij}$ such that $i$ is the least such that $x\\in A_i$ and $j$ is the least such that $x=a_{ij}$.\r\n    This is an injection.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. $\\mathbb Q$ is countable.\r\n    Indeed,\r\n    $$\\mathbb Q=\\bigcup_{n\\in\\mathbb N}\\frac{1}{n}\\mathbb Z$$\r\n    So we are done by the preceding corollary.\r\n    Alternatively, there is an obvious injection from $\\mathbb Q$ to $\\mathbb Z\\times\\mathbb Z$.\\\\\r\n    2. The set $\\mathbb A$ of all algebraic numbers is countable.\r\n    Indeed, each polynomial has only finitely many roots, so it is enough to show that there are couontably many integer polynomials, then the claim is proved by Corollary \\ref{union_countable}.\r\n    But again by this corollary it is enough to show that there are only countably many integer polynomials of degree $d$ for any $d\\in\\mathbb N$.\r\n    However this set injects to $\\mathbb Z^{d+1}$ by $a_0+a_1x+\\cdots+a_dx^d\\mapsto (a_0,a_1,\\ldots,a_d)$, so it is countable.\r\n\\end{example}\r\nWe have got many many countable sets in our stock, so the question is then whether all sets are countable.\r\n\\begin{theorem}\r\n    $\\mathbb R$ is uncountable (that is, not countable).\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffices to show that $(0,1)$ is uncountable.\r\n    So given any sequence $r_1,r_2,\\ldots$ of $(0,1)$, we shall show that there is some $s\\in (0,1)$ that is not of the form $r_i$.\r\n    We write each number in $\\{r_i:i\\in\\mathbb N\\}$ as decimals.\r\n    That is, $r_i=0.r_{i1}r_{i2}\\ldots$.\r\n    For each $n\\in\\mathbb N$, choose a digit $s_n\\in\\{5,6\\}\\setminus\\{r_{nn}\\}\\neq\\varnothing$,\r\n    \\footnote{There is nothing special about $5,6$, we just need to get rid of the case of $9999\\ldots$}\r\n    then $0.s_1s_2\\ldots\\in (0,1)$ is not of the form $a_i$.\r\n\\end{proof}\r\nThe above proof is called Cantor's Diagonal Argument.\r\n\\begin{remark}\r\n    $\\mathbb A\\cap \\mathbb R$ is countable but $\\mathbb R$ is not, so there exists transcendental numbers.\r\n    In fact, ``most'' reals are transcendental, as the set $\\mathbb R\\setminus\\mathbb A$ is uncountable.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    $2^{\\mathbb N}$ is uncountable.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose $2^{\\mathbb N}=\\{s_1,s_2,\\ldots\\}$.\r\n    Consider the set $S\\subset\\mathbb N$ by $n\\in S\\iff n\\notin s_n$, that is $\\{n\\in\\mathbb N:n\\notin s_n\\}$, so $S\\neq s_i$ for any $i$, contradiction.\r\n\\end{proof}\r\n\\begin{remark}\r\n    This really is exactly the proof idea of $\\mathbb R$ being uncountable.\r\n    Alternatively, we can actually inject $(0,1)$ to $2^\\mathbb N$ by writing in base $2$.\r\n\\end{remark}\r\nThe proof above can be actually extended to the following:\r\n\\begin{theorem}\r\n    Let $X$ be a set, then there is no bijection $X\\to 2^X$.\r\n\\end{theorem}\r\nFor example, there is no bijection between $\\mathbb R$ and $2^{\\mathbb R}$.\r\n\\begin{proof}\r\n    Let $f:X\\to 2^X$ be a function.\r\n    Consider the set $S=\\{x\\in X:x\\notin f(x)\\}$.\r\n    But $S\\notin f(X)$ since for any $x\\in X,S\\neq f(x)$ (as $x\\in S\\iff x\\notin f(x)$), so $f$ is not surjective.\r\n\\end{proof}\r\nNote that the set $S=\\{x\\in X:x\\notin f(x)\\}$ is very similar to Russel's Paradox.\\\\\r\nNow we want to explore more countability arguments.\r\n\\begin{example}\r\n    Any collection $\\{A_i\\}_{i\\in I}$ of pairwise disjoint intervals is countable.\r\n    The first proof that we can do is to inject the set into the rational numbers by choosing one from each interval.\r\n    The second proof is by observing that the numbers of intervals in the family with length at least $1/n$ is countable, then we can write our family as a countable union of countable sets, hence is countable.\r\n\\end{example}\r\nThere are generally two sorts of arguments to show a set is uncountable, either copying the diagonal argument or inject an uncountable set to it.\r\nTo show it is countable, either we can list it (which however often get fiddly) or we can inject it into a countable set.\r\nAnother way is to use the fact that a countable union of countable sets is countable.\\\\\r\nNow consider $A,B$ nonempty.\r\nIntuitively, we think of $A$ bijecting with $B$ as saying that the size of $A$ is the size of $B$.\r\nSimilarly, we think of $A$ injecting into $B$ as $A$ has at most as large as $B$, and $A$ surjecting to $B$ as $A$ has at least as large as $B$.\r\nFor these to make sense, we certainly want that $A$ injects into $B$ if and only if $B$ surjects into $A$.\r\nIndeed, given $f:A\\to B$ injective, then consider $a\\in A$, then $g:B\\to A$ by\r\n$$b\\mapsto\\begin{cases}\r\n    f^{-1}(b)\\text{, if $b\\in f(A)$}\\\\\r\n    a\\text{, otherwise}\r\n\\end{cases}$$\r\nThen $g$ is surjective.\r\nConversely, given $g:B\\to A$ surjective, consider $f:A\\to B$ with $a\\mapsto a'$ by choosing an $a'\\in g^{-1}(\\{a\\})$.\r\n\\footnote{Does it depend on the Axiom of Choice?}\r\nAlso it is intuitive that if $A$ injects into $B$ and $B$ injects into $A$, then $A$ bijects with $B$.\r\n\\begin{theorem}[Schr\\\"oder–Bernstein]\r\n    Let $f:A\\to B$ and $g:B\\to A$ be injective, then there is a bijection $h:A\\to B$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For $a\\in A$, we write $g^{-1}(a)$ for the unique (if exists) point in $B$ such that $g(g^{-1}(a))=a$.\r\n    Define similarly $f^{-1}(b)$ for $b\\in B$.\r\n    The ``ancestors'' of $a\\in A$ consists of\r\n    $$g^{-1}(a), f^{-1}(g^{-1}(a)),g^{-1}(f^{-1}(g^{-1}(a))),f^{-1}(g^{-1}(f^{-1}(g^{-1}(a)))),\\ldots$$\r\n    which may or may not terminate.\r\n    Similarly for $b\\in B$.\r\n    Let $A_0$ be the set of $a\\in A$ such that the ancestor sequence of $a$ that terminates in even time, that is it has even length (so it includes those $a\\notin g(B)$ since $0$ is even).\r\n    And $A_1$ be the set of $a\\in A$ such that the ancestor sequence of $a$ that terminates in odd time, $A_\\infty$ be those whose ancestor sequence does not terminate.\r\n    Similarly construct $B_0,B_1,B_\\infty$.\r\n    So $A_0,A_1,A_\\infty$ partitions $A$ and $B_0,B_1,B_\\infty$ partitions $B$.\r\n    By definition, $f|_{A_0}$ is a bijection $A_0\\to B_1$ (as every $b\\in B_1$ is in the image of $f|_{A_0}$).\r\n    And simiarly, $g|_{B_0}$ is a bijection $B_0\\to A_1$.\r\n    As for infinity cases, $f|_{A_\\infty}$ is a bijection $A_{\\infty}\\to B_\\infty$, so the function $h$ can be defined by\r\n    $$h(a)=\r\n    \\begin{cases}\r\n        f(a)\\text{, if $a\\notin A_1$}\\\\\r\n        g^{-1}(a)\\text{, if $a\\in A_1$}\r\n    \\end{cases}$$\r\n    Then $h:A\\to B$ is well-defined and bijective.\r\n\\end{proof}\r\n\\begin{example}\r\n    $[0,1]$ and $[0,1]\\cup [2,3]$ biject.\r\n    Indeed, $x\\mapsto x$ is an injection from $[0,1]\\to [0,1]\\cup [2,3]$.\r\n    Also $x\\mapsto x/3$ injects $[0,1]\\cup[2,3]$ to $[0,1]$\r\n\\end{example}\r\nNow, is it true that for any sets $A,B$, either $A$ injects into $B$ or vice versa?\r\nThe answer is yes, but very hard and way beyond the scope of this course.\\\\\r\nNow given $\\mathbb N$, we can construct a strictly increasing sequence (in terms of sizes) $\\mathbb N,2^{\\mathbb N}, 2^{2^{\\mathbb N}},\\ldots$, but does every set injects into one of them?\r\nThe answer is obviously no, since we can take $X=\\mathbb N\\cup 2^{\\mathbb N}\\cup 2^{2^{\\mathbb N}}\\cup\\cdots$.\r\nNow this is definitely not the biggest set either, since we can now take again $X,2^X, 2^{2^X},\\ldots$, which is again beaten by the union $X'$ of all of them.\r\nWe can then construct a sequence $X,X',X'',\\ldots$, which is again beaten by $X\\cup X'\\cup X''\\cup\\cdots$.\r\nAnd we can do the same thing again and again and again and this never ends... (but the course does here).", "meta": {"hexsha": "a3abf79469309a6b6072ed0cf49a4b0494259015", "size": 10491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/count.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": "7/count.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": "7/count.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": 60.9941860465, "max_line_length": 211, "alphanum_fraction": 0.6602802402, "num_tokens": 3567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568417, "lm_q2_score": 0.8856314798554444, "lm_q1q2_score": 0.688401217205761}}
{"text": "% !TeX root = main.tex\n\n\\chapter{Discrete Fourier Transform}\n\\glsresetall\n\\label{chapter:dft}\n\n%\\note{Make sure to use consistent notation. E.g., use bold capital letters for matrices.}\n\nThe \\gls{dft} plays a fundamental role in digital signal processing systems. It is a method to change a discrete signal in the time domain to the same signal in the frequency domain.  By describing the signal as the sum of sinusoids, we can more easily compute some functions on the signal, e.g., filtering and other linear time invariant functions.  Therefore, it plays an important role in many wireless communications, image processing, and other digital signal processing applications.\n\nThis chapter provides an introduction to the \\gls{dft} with a focus on its optimization for an FPGA implementation. At its core, the \\gls{dft} performs a matrix-vector multiplication where the matrix is a fixed set of coefficients. The initial optimizations in Chapter \\ref{subsec:dft_implementation} treat the \\gls{dft} operation as a simplified matrix-vector multiplication. Then, Chapter \\ref{subsec:dft_implementation} introduces a complete implementation of the \\gls{dft} in \\VHLS code. Additionally, we describe how to best optimize the \\gls{dft} computation to increase the throughput. We focus our optimization efforts on array partitioning optimizations in Chapter \\ref{subsec:dft_array_partitioning}.\n\n%The \\term{Fast Fourier Transform} (\\gls{fft}) is a highly optimized method to calculate the \\gls{dft}. We will focus on the \\gls{fft} in the next chapter.\n\nThere is a lot of math in the first two sections of this chapter. This may seem superfluous, but is necessary to fully comprehend the code restructuring optimizations, particularly for understanding the computational symmetries that are utilized by the \\gls{fft} in the next chapter. That being said, if you are more interested in the HLS optimizations, you can skip to Chapter \\ref{subsec:dft_implementation}. \n\n\\section{Fourier Series}\n\nIn order to explain the discrete Fourier transform, we must first understand the \\term{Fourier series}. The Fourier series provides an alternative way to look at a real valued, continuous, periodic signal where the signal runs over one period from $-\\pi$ to $\\pi$. The seminal result from Jean Baptiste Joseph Fourier states that any continuous, periodic signal over a period of $2 \\pi$ can be represented by a sum of cosines and sines with a period of $2 \\pi$. Formally, the Fourier Series is given as\n\n\\begin{equation}\n\\begin{array} {lcl} \nf(t) & \\sim &  \\frac{a_0}{2} + a_1 \\cos (t) + a_2 \\cos (2t) + a_3 \\cos (3t) + \\dots \\\\\n& & + b_1 \\sin(t) + b_2 \\sin(2t) + b_3 \\sin(3t) + \\dots \\\\\n& \\sim & \\frac{a_0}{2} + \\displaystyle\\sum\\limits_{n=1}^{\\infty} (a_n \\cos (nt) + b_n \\sin(nt))\n\\end{array}\n\\label{eq:fourier_series}\n\\end{equation}\nwhere the coefficients $a_0, a_1, \\dots$ and $b_1, b_2, \\dots$ are computed as\n\n\\begin{equation}\n\\begin{array} {lcl} \na_0 & = & \\frac{1}{\\pi} \\int_{-\\pi}^\\pi f(t)\\,\\mathrm{d}t \\\\\na_n & = & \\frac{1}{\\pi} \\int_{-\\pi}^\\pi f(t) \\cos(nt)\\,\\mathrm{d}t \\\\\nb_n & = & \\frac{1}{\\pi} \\int_{-\\pi}^\\pi f(t) \\sin(nt)\\,\\mathrm{d}t \\\\\n\\end{array}\n\\label{eq:fourier_coefficients}\n\\end{equation}\n\nThere are several things to note. First, the coefficients $a_0, a_1, a_2, \\dots, b_1, b_2, \\dots$ in Equation \\ref{eq:fourier_coefficients} are called the Fourier coefficients. The coefficient $a_0$ is often called the \\term{direct current (DC)} term (a reference to early electrical current analysis), the $n=1$ frequency is called the fundamental, while the other frequencies ($n \\ge 2$) are called higher harmonics. The notions of fundamental and harmonic frequencies originate from acoustics and music. Second, the function $f$, and the $\\cos()$ and $\\sin()$ functions all have a period of $2 \\pi$; changing this period to some other value is straightforward as we will show shortly. The DC value $a_0$ is equivalent to the coefficient of $\\cos (0 \\cdot t) = 1$, hence the use of symbol $a$. The $b_0$ value is not needed since $\\sin (0 \\cdot t) = 0$. Finally, the relation between the function $f$ and its Fourier series is approximate in some cases when there are discontinuities in $f$ (known as Gibbs phenomenon). This is a minor issue, and only relevant for the Fourier series, and not other Fourier Transforms. Therefore, going forward we will disregard this ``approximation'' ($\\sim$) for ``equality'' ($=$). \n\nRepresenting functions that are periodic on something other than $\\pi$ requires a simple change in variables. Assume a function is periodic on $[-L, L]$ rather than $[-\\pi, \\pi]$. Let \n\\begin{equation}\nt \\equiv \\frac{\\pi t'}{L}\n\\end{equation} and \n\\begin{equation}\n\\mathrm{d}t = \\frac{\\pi \\mathrm{d}t'}{L}\n\\end{equation} which is a simple linear translation from the old $[-\\pi, \\pi]$ interval to the desired $[-L, L]$ interval.\nSolving for $t'$ and substituting $t' = \\frac{L t}{\\pi}$ into Equation \\ref{eq:fourier_series} gives\n\\begin{equation}\nf(t') = \\frac{a_0}{2} + \\displaystyle\\sum\\limits_{n=1}^{\\infty} (a_n \\cos (\\frac{n \\pi t'}{L}) + b_n \\sin(\\frac{n \\pi t'}{L}))\n\\end{equation} Solving for the $a$ and $b$ coefficients is similar:\n\\begin{equation}\n\\begin{array} {lcl} \na_0 & = & \\frac{1}{L} \\int_{-L}^L f(t')\\,\\mathrm{d}t' \\\\\na_n & = & \\frac{1}{L} \\int_{-L}^L f(t') \\cos(\\frac{n \\pi t'}{L})\\,\\mathrm{d}t' \\\\\nb_n & = & \\frac{1}{L} \\int_{-L}^L f(t') \\sin(\\frac{n \\pi t'}{L})\\,\\mathrm{d}t' \\\\\n\\end{array}\n\\end{equation}\n\nWe can use Euler's formula $e^{j n t} = \\cos (n t) + j \\sin (n t)$ to give a more concise formulation \n\\begin{equation}\nf(t) = \\displaystyle\\sum\\limits_{n=-\\infty}^{\\infty} c_n e^{j n t}.\n\\end{equation} In this case, the Fourier coefficients $c_n$ are a complex exponential given by\n\\begin{equation}\nc_n = \\frac{1}{2 \\pi} \\int_{-\\pi}^{\\pi} f(t) e^{-j n t} \\mathrm{d}t\n\\end{equation} which assumes that $f(t)$ is a periodic function with a period of $2\\pi$, i.e., this equation is equivalent to Equation \\ref{eq:fourier_series}. \n\nThe Fourier coefficients $a_n$, $b_n$, and $c_n$ are related as\n\\begin{equation}\n\\begin{array} {lcl} \na_n = c_n + c_{-n} \\text{ for } n = 0,1,2, \\dots \\\\\nb_n = j(c_n - c_{-n}) \\text{ for } n = 1,2, \\dots \\\\\nc_n = \\left\\{ \n  \\begin{array}{l l }\n  \t\\frac{1}{2} (a_n - j b_n) & n > 0 \\\\\n\t\n\t\\frac{1}{2} a_0 & n = 0 \\\\\n\t\\frac{1}{2} (a_{-n} + j b_{-n}) & n < 0 \\\\\n  \\end{array} \\right .\\\\\n\\end{array}\n\\end{equation}\n\nNote that the equations for deriving $a_n$, $b_n$, and $c_n$ introduce the notion of a ``negative'' frequency. While this physically does not make much sense, mathematically we can think about as a ``negative'' rotation on the complex plane. A ``positive'' frequency indicates that the complex number rotates in a counterclockwise direction in the complex plane. A negative frequency simply means that we are rotating in the opposite (clockwise) direction on the complex plane. \n\n\n\nThis idea is further illustrated by the relationship of cosine, sine, and the complex exponential.  Cosine can be viewed as the real part of the complex exponential and it can also be derived as the sum of two complex exponentials -- one with a positive frequency and the other with a negative frequency as shown in Equation \\ref{eq:cos_exp}.\n\\begin{equation}\n\\cos(x) = \\operatorname{Re} \\{ e^{jx} \\} = \\frac{e^{jx} + e^{-jx}}{2}\n\\label{eq:cos_exp}\n\\end{equation} \nThe relationship between sine and the complex exponential is similar as shown in Equation \\ref{eq:sin_exp}. Here we subtract the negative frequency and divide by $2j$.\n\\begin{equation}\n\\sin(x) = \\operatorname{Im} \\{ e^{jx} \\} = \\frac{e^{jx} - e^{-jx}}{2j} \n\\label{eq:sin_exp}\n\\end{equation}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width= \\textwidth]{images/sin_cos_exp}\n\\caption{A visualization of the relationship between the cosine, sine, and the complex exponential. Part a) shows the sum of two complex vectors, $e^{jx}$ and $e^{-jx}$. The result of this summation lands exactly on the real axis with the value $2 \\cos (x)$. Part b) shows a similar summation except this time summing the vectors $e^{jx}$ and $-e^{-jx}$. This summation lands on the imaginary axis with the value $2 \\sin (x)$.}\n\\label{fig:sin_cos_exp}\n\\end{figure}\n\n\nBoth of these relationships can be visualized as vectors in the complex plane as shown in Figure \\ref{fig:sin_cos_exp}. Part a) shows the cosine derivation. Here we add the two complex vectors $e^{jx}$ and $e^{-jx}$. Note that the sum of these two vectors results in a vector on the real (in-phase or I) axis. The magnitude of that vector is $2 \\cos(x)$. Thus, by dividing the sum of these two complex exponentials by $2$, we get the value $\\cos (x)$ as shown in Equation \\ref{eq:cos_exp}.  Figure \\ref{fig:sin_cos_exp} b) shows the similar derivation for sine. Here we are adding the complex vectors $e^{jx}$ and $-e^{-jx}$. The result of this is a vector on the imaginary (quadrature or Q) axis with a magnitude of $2 \\sin (x)$. Therefore, we must divide by $2j$ in order to get $\\sin (x)$. Therefore, this validates the relationship as described in Equation \\ref{eq:sin_exp}.\n\n\n\\section{\\gls{dft} Background}\n\\label{sec:DFTbackground}\n\nThe previous section provided a mathematical foundation for the Fourier series, which works on signals that are continuous and periodic. The Discrete Fourier Transform requires {\\it discrete} periodic signals. The \\gls{dft} converts a finite number of equally spaced samples into a finite number of complex sinusoids. In other words, it converts a sampled function from one domain (most often the time domain) to the frequency domain. The frequencies of the complex sinusoids are integer multiples of the \\term{fundamental frequency} which is defined as the frequency related to the sampling period of the input function. Perhaps the most important consequence of the discrete and periodic signal is that it can be represented by a finite set of numbers. Thus, a digital system can be used to implement the \\gls{dft}.  \n\nThe \\gls{dft} works on input functions that uses both real and complex numbers. Intuitively, it is easier to first understand how the real \\gls{dft} works, so we will ignore complex numbers for the time being and start with real signals in order to gain ease into the mathematics a bit. \n\\begin{aside}\nA quick note on terminology: We use lower case function variables to denote signals in the time domain. Upper case function variables are signals in the frequency domain. We use $( )$ for continuous functions and $[ ]$ for discrete functions. For example, $f( )$ is a continuous time domain function and $F( )$ is its continuous frequency domain representation. Similarly $g[ ]$ is a discrete function in the time domain and $G[ ]$ is that function transformed into the frequency domain. \n\\end{aside}\n\nTo start consider Figure \\ref{fig:basic-DFT}. The figure shows on the left a real valued time domain signal $g[ ]$ with $N$ samples or points running from $0$ to $N-1$. The \\gls{dft} is performed resulting in the frequency domain signals corresponding to the cosine and sine amplitudes for the various frequencies. These can be viewed as a complex number with the cosine amplitudes corresponding to the real value of the complex number and the sine amplitudes providing the imaginary portion of the complex number. There are $N/2 + 1$ cosine (real) and $N/2 + 1$ sine (imaginary) values. We will call this resulting complex valued frequency domain function $G[ ]$. Note that the number of samples in frequency domain ($N/2 + 1$) is due to the fact that we are considering a real valued time domain signal; a complex valued time domain signal results in a frequency domain signal with $N$ samples.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{images/basic-DFT}\n\\caption{ A real valued discrete function $g[ ]$ in the time domain with $N$ points has a frequency domain representation with $N/2 + 1$ samples. Each of these frequency domain samples has one cosine and one sine amplitude value. Collectively these two amplitude values can be represented by a complex number with the cosine amplitude representing the real part and the sine amplitude the imaginary part. }\n\\label{fig:basic-DFT}\n\\end{figure}\n\n\n\nAn $N$ point \\gls{dft} can be determined through a $N \\times N$ matrix multiplied by a vector of size $N$, $G = S \\cdot g$ where\n\\begin{equation}\nS =\n \\begin{bmatrix}\n \\label{eq:Smatrix}\n  1 & 1 & 1 & \\cdots & 1 \\\\\n  1 & s & s^2 & \\cdots & s^{N-1} \\\\\n  1 & s^2 & s^4 & \\cdots & s^{2(N-1)} \\\\\n  1 & s^3 & s^6 & \\cdots & s^{3(N-1)} \\\\\n  \\vdots  & \\vdots  & \\vdots &\\ddots & \\vdots  \\\\\n  1 & s^{N-1} & s^{2(N-1)}&\\cdots & s^{(N-1)(N-1)}\n \\end{bmatrix}\n\\end{equation} and $s = e^{\\frac{-j 2 \\pi}{N}}$.   Thus the samples in frequency domain are derived as \n\\begin{equation}\nG[k] = \\displaystyle\\sum\\limits_{n=0}^{N-1} g[n] s^{kn} \\text{ for } k = 0,\\dots, N-1\n\\end{equation}\nFigure \\ref{fig:dft_visualization} provides a visualization of the \\gls{dft} coefficients for an 8 point \\gls{dft} operation. The eight frequency domain samples are derived by multiplying the 8 time domain samples with the corresponding rows of the $S$ matrix. Row 0 of the $S$ matrix corresponds to the DC component which is proportional to the average of the time domain samples. Multiplying Row 1 of the $S$ matrix with $g$ provides the cosine and sine amplitudes values for when there is one rotation around the unit circle. Since this is an 8 point \\gls{dft}, this means that each phasor is offset by $45^{\\circ}$. Performing eight $45^{\\circ}$ rotations does one full rotation around the unit circle. Row 2 is similar except it performs two complete rotations around the unit circle, i.e., each individual rotation is $90^{\\circ}$. This corresponds to a higher frequency. Row 3 does three complete rotations; Row 4 four rotations and so on. Each of these row times column multiplications gives the appropriate frequency domain sample. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width= 0.8 \\textwidth]{images/dft-visualization}\n\\caption{ The elements of the $S$ shown as a complex vectors.  }\n\\label{fig:dft_visualization}\n\\end{figure}\n\nNotice that the $S$ matrix is diagonally symmetric, that is $S[i][j] = S[j][i]$.  In addition, $S[i][j] = s^i*s^j = s^{(i+j)}$.  There is also interesting symmetry around Row 4. The phasors in Rows 3 and 5 are complex conjugates of each other, i.e., $S[3][j] = S[5][j]^*$. Similarly, Rows 2 and 6 ($S[2][j] = S[6][j]^*$), and Rows 1 and 7 ($S[1][j] = S[7][j]^*$) are each related by the complex conjugate operation. It is for this reason that the \\gls{dft} of a real valued input signal with $N$ samples has only $N/2 + 1$ cosine and sine values in the frequency domain. The remaining $N/2$ frequency domain values provide redundant information so they are not needed. However, this is not true when the input signal is complex. In this case, the frequency domain will have $N + 1$ cosine and sine values. \n\n\\section{Matrix-Vector Multiplication Optimizations}\n\\label{subsec:mvmul_implementation}\n\n%\\note{make sure this part is integrated. It was recently moved here}\nMatrix-vector multiplication is the core computation of a \\gls{dft}.  The input time domain vector is multiplied by a matrix with fixed special values. The result is a vector that corresponds to the frequency domain representation of the input time domain signal.  \n\nIn this section, we look at the hardware implementation of matrix-vector multiplication. We break this operation down into its most basic form (see Figure \\ref{fig:matrix_vector_base}). This allows us to better focus the discussion on the optimizations rather than deal with all the complexities of using functionally correct \\gls{dft} code. We will build a \\gls{dft} core in the next section. \n\n\\begin{figure}\n\\lstinputlisting{examples/matrix_vector_base.c}\n\\caption{Simple code implementing a matrix-vector multiplication.}\\label{fig:matrix_vector_base}\n\\end{figure}\n\nThe code in Figure \\ref{fig:matrix_vector_base} provides an initial starting point for synthesizing this operation into hardware. We use a custom data type called \\lstinline|BaseType| that is currently mapped as a \\lstinline|float|. This may seem superfluous at the time, but this will allow us in the future to easily experiment with different number representations for our variables (e.g., signed or unsigned fixed point with different precision). The \\lstinline|matrix_vector| function has three arguments. The first two arguments \\lstinline|BaseType M[SIZE][SIZE]| and \\lstinline|BaseType V_In[SIZE]| are the input matrix and vector to be multiplied. The third argument \\lstinline|BaseType V_Out[SIZE]| is the resultant vector. By setting \\lstinline|M = S|  and \\lstinline|V_In| to a sampled time domain signal, the \\lstinline|V_Out| will contain the \\gls{dft}. \\lstinline|SIZE| is a constant that determines the number of samples in the input signal and correspondingly the size of the \\gls{dft}.\n\nThe algorithm itself is simply a nested \\lstinline|for| loop. The inner loop (\\lstinline|dot_product_loop|) computes the \\gls{dft} coefficients starting from \\lstinline|0| and going to \\lstinline|SIZE - 1|. However, this relatively simple code has many design choices that can be performed when mapping to hardware. \n\nWhenever you perform HLS, you should think about the architecture that you wish to synthesize. Memory organization is one of the more important decisions. The question boils down to \\emph{where do you store the data from your code?} There are a number of options when mapping variables to hardware. The variable could simply be a set of wires (if its value never needs saved across a cycle), a register, RAM or FIFO. All of these options provide tradeoffs between performance and area. \n\nAnother major factor is the amount of parallelism that is available within the code. Purely sequential code has few options for implementation. On the other hand, code with a significant amount of parallelism has implementation options that range from purely sequentially to fully parallel. These options obviously have different area and performance. We will look at how both memory configurations and parallelism effect the hardware implementation for the matrix-vector implementation of the \\gls{dft}.\n\n\\begin{figure}\n\\centering\n%\\includesvg{images/matrix_vector_sequential}\n\\includegraphics[width= 0.4 \\textwidth]{images/matrix_vector_sequential}\n\\includesvg{dft_behavior_loop_sequential}\n\\caption{A possible implementation of matrix-vector multiplication from the code in Figure \\ref{fig:matrix_vector_base}.}\n\\label{fig:matrix_vector_sequential}\n\\end{figure}\n\nFigure \\ref{fig:matrix_vector_sequential} shows a sequential architecture for matrix-vector multiplication with one multiply and one addition operator.  Logic is created to access the \\lstinline|V_In| and \\lstinline|M| arrays which are stored in BRAMs. Each element of \\lstinline|V_Out| is computed and stored into the BRAM. This architecture is essentially what will result from synthesizing the code from Figure \\ref{fig:matrix_vector_base} with no directives. It does not consume a lot of area, but the task latency and task interval are relatively large.\n\n\\section{Pipelining and Parallelism}\n\nThere is substantial opportunity to exploit parallelism in the matrix-multiplication example. We start by focusing on the inner loop. The expression \\lstinline|sum += V_In[j] * M[i][j];| is executed in each iteration of the loop. The variable \\lstinline|sum|, which is keeping a running tally of the multiplications, is being reused in each iteration and takes on a new value. This inner loop can be rewritten as shown Figure \\ref{fig:matrix_vector_base_unroll_inner}.  In this case, the sum variable has been completely eliminated and replaced with multiple intermediate values in the larger expression.\n\n\\begin{figure}\n\\lstinputlisting{examples/matrix_vector_base_unroll_inner.c}\n\\caption{The matrix-vector multiplication example with a manually unrolled inner loop.}\n\\label{fig:matrix_vector_base_unroll_inner}\n\\end{figure}\n\n\n\\begin{aside}\nLoop unrolling is performed automatically by \\VHLS in a pipelined context.  Loop unrolling can also be requested by using \\lstinline|#pragma HLS unroll| or the equivalent directive outside of a pipelined context.  \n\\end{aside} \n\nIt should be clear that the new expression replacing the inner loop has significant amount of parallelism. Each one of the multiplications can be performed simultaneously, and the summation can be performed using an adder tree. The data flow graph of this computation is shown in Figure \\ref{fig:matrix_vector_unroll_inner_dfg}. \n\n\\begin{figure}\n\\centering\n\\includesvg{matrix_vector_unroll_inner}\n%\\includegraphics[width=.8\\textwidth]{images/matrix_vector_unroll_inner.pdf}\n\\caption{A data flow graph of the expression resulting from the unrolled inner loop from Figure \\ref{fig:matrix_vector_base_unroll_inner}.}\\label{fig:matrix_vector_unroll_inner_dfg}\n\\end{figure}\n\nIf we wish to achieve the minimum task latency for the expression resulting from the unrolled inner loop, all eight of the multiplications should be executed in parallel. Assuming that the multiplication has a latency of 3 cycles and addition has a latency of 1 cycle, then all of the \\lstinline|V_In[j] * M[i][j]| operations are completed by the third time step. The summation of these eight intermediate results using an adder tree takes $\\log 8 = 3$ cycles. Hence, the body of \\lstinline|data_loop| now has a latency of 6 cycles for each iteration and requires 8 multipliers and 7 adders.  This behavior is shown in the left side of  Figure \\ref{fig:dft_behavior1}.  Note that the adders could be reused across Cycle 4-6, which would reduce the number of adders to 4. However, adders are typically not shared when targeting FPGAs since an adder and a multiplexer require the same amount of FPGA resources (approximately 1 LUT per bit for a 2-input operator). \n\n\\begin{figure}\n\\centering\n\\includesvg{dft_behavior1}\n%\\includesvg{dft_behavior2}\n\\caption{Possible sequential implementations resulting from the unrolled inner loop from Figure \\ref{fig:matrix_vector_base_unroll_inner}.}\\label{fig:dft_behavior1}\n\\end{figure}\n\nIf we are not willing to use 8 multipliers, there is an opportunity to reduce resource usage in exchange for increasing the number of cycles to execute the function. For example, using 4 multipliers would result in a latency of 6 cycles for the multiplication of the eight \\lstinline|V_In[j] * M[i][j]| operations, and an overall latency of 9 cycles to finish the body of \\lstinline|data_loop|. This behavior is shown in the right side of Figure \\ref{fig:dft_behavior1}.  You could even use fewer multipliers at the cost of taking more cycles to complete the inner loop.\n\nLooking at Figure \\ref{fig:dft_behavior1}, it is apparent that there are significant periods where the operators are not performing useful work, reducing the overall efficiency of the design.  It would be nice if we could reduce these periods.  In this case we can observe that each iteration of \\lstinline|data_loop| is, in fact completely independent, which means that they can be executed concurrently.  Just as we unrolled \\lstinline{dot_product_loop}, it's also possible to unroll \\lstinline{data_loop} and perform all of the multiplications concurrently.  However, this would require a very large amount of FPGA resources.  A better choice is to enable each iteration of the loop to start as soon as possible, while the previous execution of the loop is still executing.  This process is called \\gls{looppipelining} and is achieved in \\VHLS using \\lstinline|#pragma HLS pipeline|.  In most cases, loop pipelining reduces the interval of a loop to be reduced, but does not affect the latency.  Loop pipelined behavior of this design is shown in Figure \\ref{fig:dft_behavior2}. \n\n\\begin{figure}\n\\centering\n\\includesvg{dft_behavior2}\n\\caption{Possible pipelined implementations resulting from the unrolled inner loop from Figure \\ref{fig:matrix_vector_base_unroll_inner}.}\\label{fig:dft_behavior2}\n\\end{figure}\n\nUntil now, we have only focused on operator latency.  It is common to have pipelined functional units; most functional units in \\VHLS are fully pipelined with an interval of one. Even though it might take 3 cycles for a single multiply operation to complete, a new multiply operation could start every clock cycle on a pipelined multiplier.  In this way, a single functional unit may be able to simultaneously execute many multiply operations at the same time.  For instance, a multiplier with a latency of 3 and an interval of 1 could be simultaneously executing three multiply operations. \n\nBy taking advantage of pipelined multipliers, we can reduce the latency of the unrolled inner loop without adding additional operators.  One possible implementation using three pipelined multipliers is shown on the left in Figure \\ref{fig:dft_behavior_pipelined}.  In this case, the multiplication operations can execute concurrently (because they have no data dependencies), while the addition operations cannot begin until the first multiplication has completed.  In the figure on the right, a pipelined version of this design is shown, with an interval of 3, which is similar to the results of \\VHLS if \\lstinline|#pragma  HLS pipeline II=3| is applied to the \\lstinline|data_loop|.  In this case, not only are individual operations executing concurrently on the same operators, but those operations may come from different iterations of \\lstinline|data_loop|.  \n\n\\begin{figure}\n\\centering\n\\includesvg{dft_behavior3}\n\\caption{Possible implementations resulting from the unrolled inner loop from Figure \\ref{fig:matrix_vector_base_unroll_inner} using pipelined multipliers.}\\label{fig:dft_behavior_pipelined}\n\\end{figure}\n\nAt this point you may have observed that pipelining is possible at different levels of hierarchy, including the operator level, loop level, and function level.  Furthermore, pipelining at different levels are largely independent!  We can use pipelined operators in a sequential loop, or we can use sequential operators to build a pipelined loop.  It's also possible to build pipelined implementations of large functions which can be shared in \\VHLS just like primitive operators.  In the end, what matters most is how many operators are being instantiated, their individual costs, and how often they are used.\n\n%By taking advantage of this pipelined multiplier, we can reduce the latency of the unrolled inner loop without adding additional operators. Figure \\ref{fig:matrix_vector_unroll_inner_dfg_pipelined} shows the unrolled inner loop using a three stage pipelined multiplier. Here the first three multiply operations (corresponding to the operations \\texttt{V\\_In[0] * M[i][0], V\\_In[1] * M[i][1], V\\_In[2] * M[i][2] , V\\_In[3] * M[i][3]}) can use the same multiplier. Note that this multiplier can only start one multiply operation in any clock cycle, and the operations still requires 3 cycles to complete. Likewise the operations \\texttt{V\\_In[4] * M[i][4], V\\_In[5] * M[i][5], V\\_In[6] * M[i][6] , V\\_In[7] * M[i][7]} can use the same multiplier. Thus only 2 multipliers are required. \n\n%\\begin{figure}\n%\\centering\n%\\includesvg{images/matrix_vector_unroll_inner}\n%\\includegraphics[width=\\textwidth]{images/matrix_vector_unroll_inner_pipelined.pdf}\n%\\caption{A data flow graph of the expression resulting from the unrolled inner loop from Figure \\ref{fig:matrix_vector_base_unroll_inner} using pipelined multipliers.}\\label{fig:matrix_vector_unroll_inner_dfg_pipelined}\n%\\marginnote{This needs a way to show the mapping of operation -> operator}\n%\\end{figure}\n\n\\section{Storage Tradeoffs and Array Partitioning}\n\\label{subsec:dft_array_partitioning}\n\nUp until this point, we have assumed that the data in arrays (\\lstinline|V_In[]|, \\lstinline|M[][]|, and \\lstinline|V_Out[]| are accessible at anytime.  In practice, however, the placement of the data plays a crucial role in the performance and resource usage. In most processor systems, the memory architecture is fixed and we can only adapt the program to attempt to best make use of the available memory hierarchy, taking care to minimize register spills and cache misses, for instance.  In HLS designs, we can also explore and leverage different memory structures and often try to find the memory structure that best matches a particular algorithm.  Typically large amounts of data are stored in off-chip memory, such as DRAM, flash, or even network-attached storage. However, data access times are typically long, on the order of tens to hundreds (or more) of cycles. Off-chip storage also relatively large amounts of energy to access, because large amounts of current must flow through long wires.  On-chip storage, in contrast can be accessed quickly and is much lower power.  I contrast it is more limited in the amount of data that can be stored.  A common pattern is to load data into on-chip memory in a block, where it can then be operated on repeatedly.  This is similar to the effect of caches in the memory hierarchy of general purpose CPUs.\n\nThe primary choices for on-chip storage on in embedded memories (e.g., block RAMs) or in flip-flops (FFs). These two options have their own tradeoffs. Flip-flop based memories allow for multiple reads at different addresses in a single clock.  It is also possible to read, modify, and write a Flip-flop based memory in a single clock cycle.  However, the number of FFs is typically limited to around 100 Kbytes, even in the largest devices. In practice, most flip-flop based memories should be much smaller in order to make effective use of other FPGA resources.  Block RAMs (BRAMs) offer higher capacity, on the order Mbytes of storage, at the cost of limited accessibility. For example, a single BRAM can store more than 1-4 Kbytes of data, but access to that data is limited to two different addresses each clock cycle. Furthermore, BRAMs are required to have a minimum amount of pipelining (i.e. the read operation must have a latency of at least one cycle).  Therefore, the fundamental tradeoff boils down to the required bandwidth versus the capacity. \n\nIf throughput is the number one concern, all of the data would be stored in FFs. This would allow any element to be accessed as many times as it is needed each clock cycle. However, as the size of arrays grows large, this is not feasible.  In the case of matrix-vector multiplication, storing a 1024 by 1024 matrix of 32-bit integers would require about 4 MBytes of memory.   Even using BRAM, this storage would require about 1024 BRAM blocks, since each BRAM stores around 4KBytes.  On the other hand, using a single large BRAM-based memory means that we can only access two elements at a time.  This obviously prevents higher performance implementations, such as in Figure \\ref{fig:matrix_vector_unroll_inner_dfg}, which require accessing multiple array elements each clock cycle (all eight elements of \\lstinline|V_In[]| along with 8 elements of \\lstinline|M[][]|).  In practice, most designs require larger arrays to be strategically divided into smaller BRAM memories, a process called \\gls{arraypartitioning}.  Smaller arrays (often used for indexing into larger arrays) can be partitioned completely into individual scalar variables and mapped into FFs.  Matching pipelining choices and array partitioning to maximize the efficiency of operator usage and memory usage is an important aspect of design space exploration in HLS.\n\n\\begin{aside}\n\\VHLS will perform some array partitioning automatically, but as array partitioning tends to be rather design-specific it is often necessary to guide the tool for best results.  Global configuration of array partitioning is available in the \\lstinline|config_array_partition| project option.  Individual arrays can be explicitly partitioned using the \\lstinline|array_partition| directive. The directive \\lstinline|array_partition complete| will split each element of an array into its own register, resulting in a flip-flop based memory.  As with many other directive-based optimizations, the same result can also be achieved by rewriting the code manually.  In general, it is preferred to use the tool directives since it avoids introducing bugs and keeps the code easy to maintain.\n\\end{aside}\n\n%The question then becomes how do we store the data across these different BRAMs. For example, we could store the $M$ matrix in row-major or column-major order. This may effect the performance depending upon the data access patterns. For example, if we could partition the data in such a way that none of the accesses at any time occur to the same BRAM, then this would allow for all of the memory access operations to be scheduled at the same cycle. However, if the data was partitioned such that the data accesses all went to the same BRAM at any given time, these access must be sequentialized since the BRAM only has a limited number of read ports. Therefore, it is important to carefully consider how the data access patterns required by the code when you are partitioning your data.\n\n%\\begin{aside}\n%Row-major order stores the values of an array with the elements in a row in consecutive order. For example the matrix when stored in row-major order is \n%\\[\n%  \\begin{bmatrix}\n%   1 & 2 & 3 \\\\\n%   4 & 5 & 6\\\\\n%   7 & 8 & 9\\\\\n%  \\end{bmatrix}\n%= \\begin{bmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\\\\n%\\end{bmatrix}\n%\\] The same matrix in column-major order is \n%\\[ \n%\t\\begin{bmatrix} 1 & 4 & 7 & 2 & 5 & 8 & 3 & 6 & 9\\\\ \\end{bmatrix} \\]\n%\\end{aside}\n\nReturning to the matrix-vector multiplication code in Figure \\ref{fig:matrix_vector_base}, we can achieve a highly parallel implementation with the addition of only a few directives, as shown in Figure \\ref{fig:matrix_vector_optimized}.  The resulting architecture is shown in Figure \\ref{fig:matrix_vector_optimized_behavior}.  Notice that the inner \\lstinline|j| loop is automatically unrolled by \\VHLS and hence every use of \\lstinline|j| is replaced with constants in the implementation.   This design demonstrates the most common use of array partitioning where the array dimensions that are partitioned (in this case, \\lstinline|V_In[]| and the second dimension of \\lstinline|M[][]|) are indexed with the constants (in this case the loop index \\lstinline|j| of the unrolled loop).  This enables an architecture where multiplexers are not required to access the partitioned arrays.\n\n\\begin{figure}\n\\lstinputlisting{examples/matrix_vector_optimized.c}\n\\caption{Matrix-vector multiplication with a particular choice of array partitioning and pipelining. }\n\\label{fig:matrix_vector_optimized}\n\\end{figure}\n\n\\begin{figure}\n\\includesvg{matrix_vector_optimized}\n\\caption{Matrix-vector multiplication architecture with a particular choice of array partitioning and pipelining.  The pipelining registers have been elided and the behavior is shown at right.}\n\\label{fig:matrix_vector_optimized_behavior}\n\\end{figure}\n\nIt's also possible to achieve other designs which use fewer multipliers and have lower performance.   For instance, in Figure \\ref{fig:dft_behavior_pipelined}, these designs use only three multipliers, hence we only need to read three elements of matrix \\lstinline|M[][]| and vector \\lstinline|V_in[]| each clock cycle. Completely partitioning these arrays would result in extra multiplexing as shown in Figure \\ref{fig:matrix_vector_partition_factor}.  In actuality the arrays only need to be partitioned into three physical memories.  Again, this partitioning could be implemented manually by rewriting code or in \\VHLS using the \\lstinline|array_partition cyclic| directive.\n\n\\begin{aside}\nBeginning with an array \\lstinline|x| containing the values \\[ \n\\begin{bmatrix} \n1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\\\\n\\end{bmatrix}\n\\]\nThe directive \\lstinline{array_partition variable=x factor=2 cyclic} on the array would split it into two arrays which are \n\\[\\begin{bmatrix}\n1 & 3 & 5 & 7 & 9\\\\\n\\end{bmatrix} \\text{and} \n\\begin{bmatrix}\n2 & 4 & 6 & 8 \\\\\n\\end{bmatrix}\n\\]\nSimilarly, the directive \\lstinline{array_partition variable=x factor=2 block} would split it into two arrays\n\\[\\begin{bmatrix}\n1 & 2 & 3 & 4 & 5\\\\\n\\end{bmatrix} \\text{and} \n\\begin{bmatrix}\n6 & 7 & 8 & 9 \\\\\n\\end{bmatrix}\n\\]\n\\end{aside}\n\n\\begin{figure}\n\\includesvg{matrix_vector_partition_factor}\n\\caption{Matrix-vector multiplication architectures at II=3 with a particular choices of array partitioning.  On the left, the arrays have been partitioned more than necessary, resulting in multiplexers.  On the right, the arrays are partitioned with factor=3. In this case, multiplexing has been reduced, but the \\lstinline|j| loop index becomes a part of the address computations.}\n\\label{fig:matrix_vector_partition_factor}\n\\end{figure}\n\n\\begin{exercise}\nStudy the effects of varying pipeline II and array partitioning on the performance and area. Plot the performance in terms of number of matrix vector multiply operations per second (throughput) versus the unroll and array partitioning factor. Plot the same trend for area (showing LUTs, FFs, DSP blocks, BRAMs). What is the general trend in both cases? Which design would you select? Why?\n\\end{exercise} \n\nAlternatively, similar results can be achieved by pipelining and applying \\gls{partial_loop_unrolling} to the inner \\lstinline|dot_product_loop|.   Figure \\ref{fig:matrix_vector_unroll_inner2} shows the result of unrolling the inner loop of the matrix-vector multiplication code by a factor of 2. You can see that the loop bounds now increment by 2. Each loop iteration requires 2 elements of matrix \\lstinline|M[][]| and vector \\lstinline|V_in[]| each iteration and perform two multiplies instead of one. In this case after loop unrolling \\VHLS can implement the operations in both expressions in parallel, corresponding to two iterations of the original loop. Note that without appropriate array partitioning, unrolling the inner loop may offer no increase in performance, as the number of concurrent read operations is limited by the number of ports to the memory.  In this case, we can store the data from the even columns in one BRAM and the data from the odd columns in the other. This is due to the fact that the unrolled loop is always performing one even iteration and one odd iteration. \n\n\\begin{aside}\nThe HLS tool can automatically unroll loops using the \\texttt{unroll} directive. The directive takes a \\texttt{factor} argument which is a positive integer denoting the number of times that the loop body should be unrolled. \n\\end{aside}\n\n\\begin{figure}\n\\lstinputlisting{examples/matrix_vector_unroll_inner2.c}\n\\caption{The inner loop of matrix-vector multiply manually unrolled by a factor of two. }\n\\label{fig:matrix_vector_unroll_inner2}\n\\end{figure}\n\n\\begin{exercise}\nManually divide \\lstinline|M[][]| and vector \\lstinline|V_in[]| into separate arrays in the same manner as the directive \\lstinline|array_partition cyclic factor=2|. How do you have to modify the code in order to change the access patterns? Now manually unroll the loop by a factor of two. How do the performance results vary between the original code (no array partitioning and no unrolling), only performing array partitioning, and performing array partitioning and loop unrolling? Finally, use the directives to perform array partitioning and loop unrolling. How do those results compare to your manual results?\n\\end{exercise} \n\nIn this code, we see that array partitioning often goes hand in hand with our choices of pipelining. Array partitioning by a factor of 2 enables an increase in performance by a factor of 2, which can be achieved either by partially unrolling the inner loop by a factor of 2 or by reducing the II of the outer loop by a factor of 2.  Increasing performance requires a corresponding amount of array partitioning.  In the case of matrix vector multiplication, this relationship is relatively straightforward since there is only one access to each variable in the inner loop.  In other code, the relationship might be more complicated.  Regardless, the goal of a designer is usually to ensure that the instantiated FPGA resources are used efficiently.  Increasing performance by a factor of 2 should use approximately twice as many resources.  Decreasing performance by a factor of 2 should use approximately half as many resources.\n\n\\begin{exercise}\nStudy the effects of loop unrolling and array partitioning on the performance and area. Plot the performance in terms of number of matrix vector multiply operations per second (throughput) versus the unroll and array partitioning factor. Plot the same trend for area (showing LUTs, FFs, DSP blocks, BRAMs). What is the general trend in both cases? Which design would you select? Why?\n\\end{exercise} \n\n\n\\section{Baseline Implementation}\n\\label{subsec:dft_implementation}\n\nWe just discussed some optimizations for matrix-vector multiplication. This is a core computation in performing a \\gls{dft}. However, there are some additionally intricacies that we must consider to move from the matrix-vector multiplication in the previous section to a functionally complete \\gls{dft} hardware implementation. We move our focus to the \\gls{dft} in this section, and describe how to optimize it to make it execute most efficiently.  \n\nOne significant change that is required is that we must be able to handle complex numbers.  As noted in Section \\ref{sec:DFTbackground} because the elements of the $S$ matrix are complex numbers, the \\gls{dft} of a real-valued signal is almost always a complex-valued signal.   It is also common to perform the \\gls{dft} of a complex-valued signal, to produce a complex-valued result.  Additionally, we need to handle fractional or possibly floating point data, rather than integers.  This can increase the cost of the implementation, particularly if floating point operations need to be performed.  In addition, floating point operators, particularly addition, have much larger latency than integer addition.  This can make it more difficult to achieve II=1 loops.  A second change is that we'd like to be able to scale our design up to large input vector sizes, perhaps N=1024 input samples.  Unfortunately, if we directly use matrix-vector multiplication, then we must store the entire $S$ matrix.  Since this matrix is the square of the input size, it becomes prohibitive to store for large input sizes.  In the following sections, we'll discuss techniques to address both of these complexities. \n\nAs is typical when creating a hardware implementation using high level synthesis, we start with a straightforward or naive implementation. This provides us with a baseline code that we can insure has the correct functionality. Typically, this code runs in a very sequential manner; it is not highly optimized and therefore may not meet the desired performance metrics. However, it is a necessary step to insure that the designer understand the functionality of the algorithm, and it serves as starting point for future optimizations.\n\n\\begin{figure}\n\\lstinputlisting{examples/dft.c}\n\\caption{Baseline code for the \\gls{dft}.}\n\\label{fig:dft_code}\n\\end{figure}\n\nFigure \\ref{fig:dft_code} shows a baseline implementation of the \\gls{dft}. This uses a doubly nested \\lstinline|for| loop. The inner loop multiplies one row of the $S$ matrix with the input signal. Instead of reading the $S$ matrix as an input, this code computes an element of $S$ in each each iteration of the inner loop, based on the current loop indices.  This phasor is converted to Cartesian coordinates (a real part and an imaginary part) using the \\lstinline|cos()| and \\lstinline|sin()| functions. The code then performs a complex multiplication of the phasor with the appropriate sample of the input signal and accumulates the result. After $N$ iterations of this inner loop, one for each column of $S$, one frequency domain sample is calculated. The outer loop also iterates $N$ times, once for each row of $S$.  As a result, the code computes an expression for \\lstinline|w| $N$ times, but computes the \\lstinline|cos()| and \\lstinline|sin()| functions and a complex multiply-add $N^2$ times.\n\nThis code uses a function call to calculate \\lstinline|cos()| and \\lstinline|sin()| values. \\VHLS is capable of synthesizing these functions using its built-in math library. There are several possible algorithms \\cite{detrey07hotbm} for implementing trigonometric functions including CORDIC, covered in Chapter \\ref{chapter:cordic}.  However, generating precise results for these functions can be expensive.  There are several possibilities for eliminating these function calls, since the inputs aren't arbitrary.  We will discuss these tradeoffs in more detail later.    A sequential implementation of this code is show in Figure \\ref{fig:dft_sequential_arch}. \n\n%Remember, however, that the results of these $\\sin()$ and $\\cos()$ function calls are just the elements of $S$ and are only dependent on the constant $N$ and not the input data. This is often the case, e.g., you will know that you wish to do a 256 or 1024 point \\gls{dft}. Therefore, it is possible to eliminate these $\\cos()$ and $\\sin()$ function calls by using a lookup table that holds the values of the $S$ matrix. This replaces the costly implementation of $\\cos()$ and $\\sin()$ with a memory access. The $S$ matrix can be stored in BRAMs for smaller size \\gls{dft}. However, larger \\gls{dft}s can quickly exhaust the available BRAM space on-chip. This provides one possible design tradeoff, which utilizes more memory in order to perform computation faster. We discuss this tradeoff in more detail later.\n\n\\begin{figure}\n\\centering\n\\includesvg{dft_behavior_baseline}\n\\includegraphics[width= 0.7 \\textwidth]{images/dft_sequential_arch}\n\\caption{ A high level architectural diagram of the \\gls{dft} as specified in the code from Figure \\ref{fig:dft_code}. This is not a comprehensive view of the architecture, e.g., it is missing components related to updating the loop counters \\lstinline|i| and \\lstinline|j|. It is meant to provide an approximate notion of how this architecture will be synthesized.  Here we've assumed that floating point operators take 4 clock cycles.}\n\\label{fig:dft_sequential_arch}\n\\end{figure}\n\n%Figure \\ref{fig:dft_sequential_arch} provides an overview of the one potential \\gls{dft} architecture. This hardware implementation is highly sequential. The data path corresponding to the inner loop is executed $N \\times N$ times, which corresponds to $N^2$ computations of $\\cos()$ and $\\sin()$ and $N^2$ complex multiplications and additions.  In each iteration of the outer loop, the variable $w$ is computed. This is essentially determining the amount of rotation that each row of the $S$ matrix requires. The phasor angle is then calculated in each iteration of the inner loop through a multiplication by the loop iterator $j$. The result is fed into a CORDIC operator to determine the sine and cosine values used in the complex multiplication and subsequent summation.  The result of the inner loop is summed into the appropriate $temp[]$ variable. Finally, after these two nested loops are finished, the values in the $temp[]$ array are copied into the $sample[]$ array. This is called an in-place \\gls{dft}, i.e., the output frequency samples are stored in the same location as the input signal samples. This saves memory at the expense of $N$ additional read and write operations. \n\n\\begin{exercise}\nWhat changes would this code require if you were to use a CORDIC that you designed, for example, from Chapter \\ref{chapter:cordic}? Would changing the accuracy of the CORDIC core make the \\gls{dft} hardware resource usage change? How would it effect the performance? \n\\end{exercise}\n\n\\begin{exercise}\nImplement the baseline code for the \\gls{dft} using HLS.  Looking at the reports, what is the relative cost of the implementation of the trignometric functions, compared to multiplication and addition?  Which operations does it make more sense to try to optimize?  What performance can be achieved by pipelining the inner loop?\n\\end{exercise}\n\n\\section{\\gls{dft} optimization}\n\\label{subsec:dft_optimization}\n\nThe baseline \\gls{dft} implementation of the previous section uses relatively high precision \\lstinline|double| datatypes.  Implementing floating point operations is typically very expensive and requires many pipeline stages, particularly for double precision.  We can see in Figure \\ref{fig:dft_sequential_arch} that this significantly affects the performance of the loop.  With pipelining, the affect of these high-latency operations is less critical, since multiple executions of the loop can execute concurrently.  The exception in this code are the \\lstinline|temp_real[]| and \\lstinline|temp_imag[]| variables, which are used to accumulate the result.  This accumulation is a \\gls{recurrence} and limits the achievable II in this design when pipelining the inner loop.   This operator dependence is shown in Figure \\ref{fig:dft_recurrence_behavior}.\n\n\\begin{figure}\n\\centering\n\\includesvg{dft_recurrence_behavior}\n\\caption{Pipelined version of the behavior in Figure \\ref{fig:dft_sequential_arch}.  In this case, the initiation interval of the loop is limited to 4, since each floating point addition takes 4 clock cycles to complete and the result is required before the next loop iteration begins (the dependence shown in red).  The dependencies  for all iterations are summarized in the diagram on the right.}\n\\label{fig:dft_recurrence_behavior}\n\\end{figure}\n\nOne possible solution is to reduce the precision of the computation.  This is always a valuable technique when it can be applied, since it reduces the resources required for each operation, the memory required to store any values, and often reduces the latency of operations as well.  For instance we could use the 32-bit \\lstinline|float| type or the 16-bit \\lstinline|half| types rather than double.  Many signal processing systems avoid floating point data types entirely and use fixed point data types\\ref{sec:number_representation}.  For commonly used integer and fixed-point precisions, each addition can be completed in a single cycle, enabling the loop to be pipelined at II=1.\n\n\\begin{exercise}\nWhat happens to the synthesis result of the code in Figure \\ref{fig:dft_code} if you change all of the data types from $double$ to $float$? Or from $double$ to $half$? Or to a fixed point value? How does this change the performance (interval and latency) and the resource usage? Does it change the values of the output frequency domain samples?\n\\end{exercise}\n\nA more general solution to achieve II=1 with floating point accumulations is to process the data in a different order.  Looking at Figure \\ref{fig:dft_recurrence_behavior} we see that the recurrence exists (represented by the arrow) because the \\lstinline|j| loop is the inner loop.  If the inner loop were the \\lstinline|i| loop instead, then we wouldn't need the result of the accumulation before the next iteration starts.  We can achieve this in the code by interchanging the order of the two loops.  This optimization is often called \\gls{loopinterchange} or pipeline-interleaved processing\\cite{lee87sdfArchitecture}.  In this case, it may not be obvious that we can rearrange the loops because of the extra code inside the outer \\lstinline|i| loop.  Fortunately, the $S$ matrix is diagonally symmetric, and hence \\lstinline|i| and \\lstinline|j| can be exchanged in the computation of \\lstinline|w|.  The result is that we can now achieve an II of 1 for the inner loop.  The tradeoff is additional storage for the \\lstinline|temp_real| and \\lstinline|temp_imag| arrays to store the intermediate values until they are needed again.\n\n\\begin{exercise}\nReorder the loops of the code in Figure \\ref{fig:dft_code} and show that you can pipeline the inner loop with an II of 1.\n\\end{exercise}\n\nThere are other optimizations that we can apply based on the structure of the $S$ matrix in the \\gls{dft} to eliminate the trigonometric operations entirely.  Recall that the complex vectors for each element of the $S$ matrix are calculated based upon a fixed integer rotation around the unit circle.  Row $S[0][]$ of the $S$ matrix corresponds to zero rotations around the unit circle, row $S[1][]$ corresponds to a single rotation, and the following rows correspond to more rotations around the unit circle. It turns out that the vectors corresponding to the second row $S[1][]$, which is one rotation around the unit circle (divided into $360/8 = 45^{\\circ}$ individual rotations), cover all of the vectors from every other row.  This can be visually confirmed by studying Figure \\ref{fig:dft-visualization}.   Thus it is possible to store only the sine and cosine values from this one rotation, and then index into this memory to calculate the requisite values for the corresponding rows. This requires only $2 \\times N = \\mathcal{O}(N)$ elements of storage. This results in a $\\mathcal{O}(N)$ reduction in storage, which for the 1024 point \\gls{dft} would reduce the memory storage requirements to $1024 \\times 2$ entries. Assuming 32 bit fixed or floating point values, this would require only 8 KB of on-chip memory. Obviously, this is a significant reduction compared to storing the entire $S$ matrix explicitly.   We denote this one dimensional storage of the matrix $S$ as $S'$ where\n\n\\begin{equation}\n\\label{eq:1DS}\nS' = S[1][\\cdot] = (1 \\hspace{4mm} s \\hspace{4mm} s^2 \\hspace{4mm} \\cdots \\hspace{4mm} s^{N-1})\n\\end{equation}\n%We use MATLAB convention $S(1, ;)$, meaning that $S'$ corresponds to the first row of the $S$ matrix. Please refer to Equation \\ref{eq:Smatrix} for a mathematical definition of the $S$ matrix. \\note{MAKE SURE THAT I DID THE MATLAB NOTATION CORRECT.}\n\n\\begin{exercise}\nDerive a formula for the access pattern for the 1D array $S'$ given as input the row number $i$ and column element $j$ corresponding to the array $S$. That is, how do we index into the 1D $S$ array to access element $S(i,j)$ from the 2D $S$ array.\n\\end{exercise}\n\nTo increase performance further we can apply techniques that are very similar to the matrix-vector multiply.  Previously, we observed that increasing performance of matrix-vector multiply required partitioning the \\lstinline|M[][]| array.  Unfortunately, representing the $S$ matrix using the $S'$ means that there is no longer an effective way to partition $S'$ to increase the amount of data that we can read on each clock cycle. Every odd row and column of $S$ includes every element of $S'$.  As a result, there is no way to partition the values of $S'$ like were able to do with $S$.  The only way to increase the number of read ports from the memory that stores $S'$ is to replicate the storage.  Fortunately, unlike with a memory that must be read and written, it is relatively easy to replicate the storage for an array that is only read.  In fact, \\VHLS will perform this optimization automatically when instantiates a \\gls{rom} for an array which is initialized and then never modified.  One advantage of this capability is that we can simply move the $sin()$ and $cos()$ calls into an array initialization.  In most cases, if this code is at the beginning of a function and only initializes the array, then \\VHLS is able to optimize away the trigonometric computation entirely and compute the contents of the ROM automatically.\n\n\\begin{exercise}\nDevise an architecture that utilizes $S'$ -- the 1D version of the $S$ matrix. How does this affect the required storage space? Does this change the logic utilization compared to an implementation using the 2D $S$ matrix? \n\\end{exercise}\n\nIn order to effectively optimize the design, we must consider every part of the code. The performance can only as good as the ``weakest link'' meaning that if there is a bottleneck the performance will take a significant hit. The current version of the \\gls{dft} function performs an in-place operation on the input and output data, i.e., it stores the results in the same array as the input data. The input array arguments \\lstinline|sample_real| and \\lstinline|sample_imag| effectively act as a memory port. That is, you can think of these arguments arrays as stored in the same memory location. Thus, we can only grab one piece of data from each of these arrays on any given cycle. This can create a bottleneck in terms of parallelizing the multiplication and summation operations within the function. This also explains the reason why we must store all of the output results in a temporary array, and then copy all of those results into the ``sample'' arrays at the end of the function. We would not have to do this if we did not perform an in-place operation. \n\n\\begin{exercise}\nModify the \\gls{dft} function interface so that the input and outputs are stored in separate arrays. How does this effect the optimizations that you can perform? How does it change the performance? What about the area results?\n\\end{exercise}\n\n\n%Previously we discussed how to reduce the amount of data that we stored in the $S$ coefficient arrays by taking advantage of the symmetry inherent in the different values. We noted that Row 1 of the $S$ matrix, corresponding to one full rotation around the unit circle, has every value that is used in the rest of the matrix. That is all of the other values are redundant. Thus, if we wanted to reduce the amount of storage required for $S$ we would create this array with $N$ elements, i.e., a 1D matrix. We called this 1D matrix $S'$ (see Equation \\ref{eq:1DS}).\n\n\\section{Conclusion}\nIn this chapter, we looked at the hardware implementation and optimization of the Discrete Fourier Transform (\\gls{dft}). The \\gls{dft} is a fundamental operation in digital signal processing. It takes a signal sampled in the time domain and converts it into the frequency domain. At the beginning of this chapter, we describe the mathematical background for the \\gls{dft}. This is important for understanding the optimizations done in the next chapter (\\gls{fft}). The remainder of the chapter was focused on specifying and optimizing the \\gls{dft} for an efficient implementation on an FPGA.  \n\nAt its core, the \\gls{dft} performs a matrix-vector multiplication. Thus, we spend some time initially to describe instruction level optimizations on a simplified code performing matrix-vector multiplication. These instruction level optimizations are done by the HLS tool. We use this as an opportunity to shed some light into the process that the HLS tool performs in the hopes that it will provide some better intuition about the results the tool outputs.\n\nAfter that, we provide an functionally correct implementation for the \\gls{dft}. We discuss a number of optimizations that can be done to improve the performance. In particular, we focus on the problem of dividing the coefficient array into different memories in order to increase the throughput. Array partitioning optimization are often key to achieving the highest performing architectures. \n\n", "meta": {"hexsha": "99d9cbf4888c92406e06d9f4becc10557a95548a", "size": 58982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dft.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": "dft.tex", "max_issues_repo_name": "mithro/pp4fpgas", "max_issues_repo_head_hexsha": "ddede5bd337f4fa33915d7e4ca98f97a7b31413a", "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": "dft.tex", "max_forks_repo_name": "mithro/pp4fpgas", "max_forks_repo_head_hexsha": "ddede5bd337f4fa33915d7e4ca98f97a7b31413a", "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": 129.6307692308, "max_line_length": 1493, "alphanum_fraction": 0.7772032145, "num_tokens": 14459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6883385658415513}}
{"text": "\\section{Fitness Function}\\label{sec:fitness}\nAs a precursor to understanding how the fitness of a chromosome is calculated, it is important to note that the training data consists of a collection of records from which the cumulative number of cases, deaths and recoveries associated with the COVID-19 virus on a particular day can be extracted.\n\nTo determine the fitness of individuals, we use the accuracy of each of the individual's 3 trees when predicting the number of cases, deaths or recoveries for each day in the training period. To be more specific, for a particular day the accuracy of the first tree is determined by calculating the difference between its prediction and the actual number of cases. Then, the difference is divided by the actual number of cases to get a ratio for which a lower ratio indicates a better fitness.\n\nThe same calculation is applied to the second tree to find its accuracy in predicting the number of deaths and to the third tree to find its accuracy in predicting the number of recoveries. The process is repeated for each day in the training data set until, eventually, the fitness of the chromosome is calculated as the average accuracy in calculating cases, deaths and recoveries over the training period. Algorithm \\ref{alg:fitness} depicts the fitness function in its entirety.\n\n\\begin{algorithm}[H]\\label{alg:fitness}\n\\SetAlgoLined\n \\ForEach{date in trainingData}{\n   cases = trainingData.cases(date)\\;\n   predictedCases = individual.trees[0].predict(date)\\;\n   casesAccuracy = abs(cases - predictedCases) / cases\\;\n   \\BlankLine\n   deaths = trainingData.deaths(date)\\;\n   predictedDeaths = individual.trees[1].predict(date)\\;\n   deathsAccuracy = abs(deaths - predictedDeaths) / deaths\\;\n   \\BlankLine\n   recovered = trainingData.recovered(date)\\;\n   predictedRecovered = individual.trees[2].predict(date)\\;\n   recoveredAccuracy = abs(recovered - predictedRecovered) / recovered\\;\n   \\BlankLine\n   fitness += (casesAccuracy + deathsAccuracy + recoveredAccuracy) / 3\\;\n }\n \\BlankLine\n return fitness / trainingData.numDays\\;\n \\caption{Fitness Function}\n\\end{algorithm}\n", "meta": {"hexsha": "a26ef0bd6f098cb40849e62e0e2566e18770e668", "size": 2115, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/report/4_fitness/fitness.tex", "max_stars_repo_name": "marcus-bornman/cos_710_assignment_1", "max_stars_repo_head_hexsha": "2fd7f97f91c4981a4f42a25660338e5d00ee3b71", "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/4_fitness/fitness.tex", "max_issues_repo_name": "marcus-bornman/cos_710_assignment_1", "max_issues_repo_head_hexsha": "2fd7f97f91c4981a4f42a25660338e5d00ee3b71", "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/4_fitness/fitness.tex", "max_forks_repo_name": "marcus-bornman/cos_710_assignment_1", "max_forks_repo_head_hexsha": "2fd7f97f91c4981a4f42a25660338e5d00ee3b71", "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": 72.9310344828, "max_line_length": 492, "alphanum_fraction": 0.7820330969, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6883385614027561}}
{"text": "\\section{Open Jackson Network}\n\\label{sec:Open-Jackson-Networks}\n\n\\begin{definition}[Open Jackson Network]\n\\label{def:Open-Jackson-Network}\n\tAn Open Jackson Network is a network of queues such that:\n\t\n\t\\begin{itemize}\n\t\t\\item there are $m$ $M/M/1$ queues;\n\t\t\\item the $i$-th server service is Exponentially distributed with rate $\\mu_{i}$;\n\t\t\\item each server may receive arrivals from outside (external arrivals) and outside (internal arrivals) the network; the total arrival rate to the $i$-th server is $\\lambda_{i}$;\n\t\t\\item external arrivals to the $i$-th server are Poisson distributed with rate $r_{i}$;\n\t\t\\item when the $i$-th server completes a job, it may be \n\t\t(i) routed to the $j$-th server (internal arrival) with probability $P_{i,j}$, or \n\t\t(ii) brought out of the system with probability $P_{i,out}=1-\\sum_{j}P_{i,j}$.\n\t\\end{itemize}\n\\end{definition}\n\n%\\begin{figure}[tp]\n%\\label{fig:Open-Jackson-Network}\t\n%\t\\centering\n%\t\\includegraphics{fig/Open-Jackson-Network}\n%\t\\caption{An Open Jackson Network and its corresponding CTMC.}\n%\\end{figure}\n\nThe \\textit{response time} is defined as the time from when the job arrives to the system until it leaves it, including possible multiple visitation to the same server.\n\nThe \\textit{total arrival rate} $\\lambda_{i}$ to the $i$-th server is also the total departure rate from the same server.\n\nThe \\textit{utilization} $\\varrho_{i} = \\frac{\\lambda_{i}}{\\mu_{i}}$ of the $i$-th server makes use of the total arrival rate.\n\nNotice that, since Jackson Network could be cyclic, the arrival process is not Poisson distributed for every server, thus we cannot leverage Burke's Theorem as we did for acyclic networks of queues, that is we cannot view the system as a collection of independent $M/M/1$ queues.\nIf it would have been possible, we would have determined state probabilities as in \\Cref{sec:Burke-Application-Tandem-Systems}.\n\n\\begin{equation}\n\\label{eqn:Open-Jackson-Network-Total-Arrival-Rate}\n\\lambda_{i} = r_{i} + \\sum_{j} \\lambda_{j} P_{j,i}\n\\end{equation}\n\n\\begin{theorem}[Open Jackson Network Product Form]\n\\label{thm:Open-Jackson-Network-Product-Form}\n\tAn Open Jackson Network with $k$ servers has the following product form\n\t\n\t\\begin{equation}\n\t\\label{eqn:Open-Jackson-Network-Product-Form}\n\t\\pi_{n_{1},...,n_{m}} = \\prod_{i=1}^{m} \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tThe demonstration makes use of the \\textit{Local Balance Approach}.\n\t\tFor a formal demonstration, see \\cite{harchol2013performance}.\n\t\\end{proof}\n\\end{theorem}\n\n\\begin{corollary}\n\\label{cor:Open-Jackson-Network-Probability-Jobs-Server}\n\tFor any Open Jackson Network with $k$ servers, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Open-Jackson-Network-Probability-Jobs-Server}\n\t\\probability{n_{i} jobs at server i} = \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\\end{equation}\n\t\n\twhere $\\varrho_{i}$ is the total utilization of the $i$-th server.\n\\end{corollary}\n\n\\begin{corollary}\n\\label{cor:Open-Jackson-Network-Mean-Server-Jobs}\t\n\tFor any Open Jackson Network with $k$ servers, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Open-Jackson-Network-Mean-Server-Jobs}\n\t\\expected{N_{i}} = \\frac{\\varrho_{i}}{1 - \\varrho_{i}}\n\t\\end{equation}\n\t\n\twhere $\\varrho_{i}$ is the total utilization of the $i$-th server.\n\\end{corollary}\n\n\n\n\n\n\n", "meta": {"hexsha": "e396f819c8538cf3166f7f05ff4e26ce09cea351", "size": 3295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/open-jackson-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/open-jackson-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/open-jackson-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": 39.2261904762, "max_line_length": 279, "alphanum_fraction": 0.7341426404, "num_tokens": 1011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642804, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6883385540196811}}
{"text": "\\documentclass[a4paper, 11pt]{article}\n\\input{../preamble.tex}\n\n\n\\DeclareMathOperator{\\N}{\\mathbb{N}}\n\\DeclareMathOperator{\\R}{\\mathbb{R}}\n\\DeclareMathOperator{\\Q}{\\mathbb{Q}}\n\\DeclareMathOperator*{\\Z}{\\mathbb{Z}}\n\n\\title{Completeness Axiom}\n\n\\begin{document}\n\n\\tableofcontents\n\n\\section{Power Inequality}\n\\begin{theorem}[Power Inequality]\nFor every $n \\in \\N$ and $x, y \\in \\R$ if $0 \\leq x < y$, then $0 \\leq x^{n} < y^{n}$\n\\end{theorem}\n\nTo prove this let us start with a lemma.\n\\begin{lemma}\nSuppose $a, b, c \\in \\R$. If $a < b$ and $c > 0$, then $ac < bc$.\n\\end{lemma}\n\\begin{proof}\nSuppose towards a contradiction that $ac = bc$. Then by the equality we require $bc \\leq ac$. Since we have $c > 0$, then $c^{-1} > 0$. Then we have\n\\begin{equation*}\n  b = bcc^{-1} \\leq acc^{-1} = a\n\\end{equation*}\nwhich contradicts the assumption that $a < b$.\n\\end{proof}\n\n\\begin{proof}\nLet $P(n):$ for all $x, y \\in \\R$, if $0 \\leq x < y$, then $x^{n} < y^{n}$.\n\n\\textbf{Base Case}\\newline\nTake $P(1): 0 \\leq x < y$ which implies $0 \\leq x^1 < y^1$. Which is true based on the given relationship of $x$ and $y$.\n\n\\textbf{Inductive Step}\\newline\nSuppose $P(n)$ holds, that is $\\forall x, y, \\in \\R$, if $0\\leq x < y$, then $0 \\leq x^n < y^n$. Let $x, y \\in R$, $0\\leq x < y$.\nThen \n\\begin{align*}\n  x^{n+1} &= x^n \\cdot x \\leq x^n \\cdot y &\\text{(using $x < y$, and $0 \\leq x^n$)} \\\\\n  &<y^n = y^{n+1} \\cdot y &\\text{(by the claim using $x^n < y^n$ and $0 < y$)}\n\\end{align*}\nThis then implies $x^{n+1} < y^{n+1}$ (1). Finally, since $0 \\leq x^n$, and $0 \\leq x$, then $0 \\leq x^{n+1}$ (2). Taking these two (1 and 2)\nwe have the desired result.\n\n\\end{proof}\n\n\\section{The Real Numbers}\n\\subsection{Maxes and minimums}\nLet $S \\subseteq \\R$, where $S \\neq \\emptyset$.\n\n\\begin{enumerate}\n  \\item The largest element of $S$ (if there is one), is called the \\textit{maximum of S}, $\\max S$\n  \\item The least element of $S$ (if there is one), is called the \\textit{minimum of S}, $\\min S$\n\\end{enumerate}\n\n\\begin{example}\nEvery finite non-empty $S \\subseteq \\R$ has a maximum and minimum.\n\\end{example}\n\n\\begin{example}\nLet $a < b \\in \\R$. Then consider the closed interval\n\\begin{align*}\n  [a, b] = \\lbrace x \\in \\R: a \\leq x \\leq b \\rbrace\n\\end{align*}\nhas minimum $\\min [a, b] = a$ and maximum $\\max [a, b] = b$.\n\\end{example}\n\n\\begin{example}\nThe open interval\n\\begin{align*}\n  (a, b) = \\lbrace x \\in \\R: a < x < b \\rbrace\n\\end{align*}\nhas neither a max nor a min.\n\\end{example}\n\n\\begin{example}\n$\\Z, \\Q, \\subseteq \\R$ do not have a min or max. Consider $a \\in \\Z$. Then there exists and $a + 1 \\in \\Z$ hence there is no max.\nConversely the same arg for min.\n\\end{example}\n\n\\subsection{Bounds on Sets}\n\\begin{definition}{Bounds}\nLet $S \\subseteq \\R$ where $S \\neq \\emptyset$.\n\\begin{enumerate}\n  \\item We call $M \\in \\R$ \\textbf{an upper bound for} $S$ if $M \\geq S$ for all $s \\in S$.\n  \\item We call $m \\in \\R$ \\textbf{a lower bound for} $S$ if $m \\leq S$ for all $s \\in S$.\n  \\item We say that $S$ is bounded if $S$ is bounded from above and from below.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{example}\nThe max of a set (if it exists) is an upper bound. The min of a set (if it exists) is a lower bound.\n\\end{example}\n\n\\begin{example}\nLet $a < b \\in \\R$ then $a$ is a lower bound for $[a, b]$ and $(a, b)$. $b$ is an upper bound for\nboth sets as well.\n\\end{example}\n\n\\begin{example}\nNeith of the set $\\Z$ or $\\Q$ are bounded from below or above.\n\\end{example}\n\n\\subsection{Supremum and Infinum}\n\\begin{definition}\nLet $S \\subseteq \\R$ where $S \\neq \\emptyset$.\n\\begin{enumerate}\n  \\item If $S$ is bounded from above and has a least upper bound, $s_0$, then $s_0$ is the\n  \\textbf{supremum} of $S$, $s_0=\\sup S$.\n  \\item If $S$ is bounded from below and has a greatest lower bound, $s_1$, then $s_1$ is the\n  \\textbf{infinum} of $S$, $s_1=\\inf S$.\n\\end{enumerate}\n\n\\begin{remark}\n  \\begin{enumerate}\n    \\item Every $S \\subseteq \\R, S\\neq \\emptyset$, can have a most one supremum and one infinum.\n    \\item If $S \\subseteq \\R$ has a max, then $\\max S = \\sup S$.\n    \\item The following are equivalent:\n    \\begin{itemize}\n      \\item $s_0 = \\sup S$\n      \\item $s_0 \\geq s \\forall s \\in S$, and if $s_1 \\geq s \\forall s \\in S,$ then $s_1 \\geq s_0$\n      \\item $s_0 \\geq s \\forall s \\in S$, and if $s_1 < s_0$, then $s_1 < s$ for some $s \\in S$.\n    \\end{itemize}\n  \\end{enumerate}\n\\end{remark}\n\\end{definition}\n\n\\begin{example}\nFor $a < b \\in \\R$,\n\\begin{enumerate}\n  \\item $\\sup[a, b] = \\sup(a, b) = b$\n  \\item $\\inf[a, b] = \\inf(a, b) = a$\n\\end{enumerate}\n\\end{example}\n\n\\begin{example}\nLet $A = \\lbrace \\frac{1}{n^{2}}: n \\in \\N, n\\geq 3  \\rbrace$ A is bounded from above and from below.\n$\\max A = 1 / 3$, however is there is no minimum.\n\n\\begin{enumerate}\n  \\item $\\inf A = 0$. $A$ is the set of values where each value is equivalent to $1/n^2$ for values of \n  $n\\geq 3$. So we can choose $n$ to be sufficiently large. Because $n \\rightarrow \\infty$,\n  $\\frac{1}{n^2} \\rightarrow 0$. So we know that 0 is the greatest lowerbound.\n  \\item $\\sup A = \\max A = 1/3$\n\\end{enumerate}\n\\end{example}\n\n\\section{The completeness Axiom}\n\\begin{definition}{Completeness Axiom}\nEvery non-empty subset of $\\R$ which is bounded from above has a least upper bound. This is equivalent\nto: Given $S \\subseteq \\R$, $S \\neq \\emptyset$, if $S$ has at least one upper bound, then $\\sup S$, exists.\n\\end{definition}\n\n\\begin{remark}\nThe Completeness Axiom failes for $\\Q$.\n\\begin{align*}\n  A &= \\lbrace r \\in \\Q: 0 \\leq r \\text{ and } r^2 \\leq 2 \\rbrace \\\\\n  &= \\lbrace r \\in \\Q: 0 \\leq r \\leq \\sqrt{2} \\rbrace \n\\end{align*}\n\\end{remark}\n$A$ is bounded from above (e.g. $\\frac{3}{2}$ is an upper bound), but the $\\sup A = \\sqrt{2}\\not\\in \\Q$.\n\n\\begin{corollary}\nEvery $\\emptyset \\neq S \\subseteq \\R$ that is bounded from below has a greatest lower bound $\\inf S$\n\\end{corollary}\n\n\\begin{proof}\nGiven $S \\subseteq \\R$, let $-S = \\lbrace -s: s \\in S \\rbrace$. Given that S is bounded below, $\\exists m\\in \\R$\nsuch that $m \\leq s$ for $s \\in S$. This implies that $-m \\geq -s$ for all $s \\in S$.\n\nSo $-m \\geq u, \\, \\forall u \\in -S$. Thus $-S$ is bounded from above by $-m$. By the Completeness Axiom for\n$-S$, the $\\sup -S$ exists.\n\nLet $s_0 = \\sup -S$. What we need to show is that \n\\begin{enumerate}\n  \\item $-s_0$ is a lower bound of $S$($-s_0 \\leq s, \\, \\forall s \\in S$)\n  \\item $-s_0$ is the greatest lower bound (if $t \\leq s, \\, \\forall s \\in S$ then $t \\leq -s_0$)\n\\end{enumerate}.\n\nWe take $s_0 \\geq -s$ for all $s \\in S$. And this implies the condition (1) by multiply both sides\nby -1.\n\nFor the second part assume $t \\leq s, \\, \\forall s \\in S$. This is equivalent to \n\\begin{align*}\n  &-t \\geq -s, \\, \\forall s \\in S\\\\\n  \\implies &-t \\geq u, \\forall u \\in -S\\\\\n  \\implies &-t \\geq s_0 \\\\\n  \\implies &t \\leq s_0\n\\end{align*}\n\\end{proof}\n\n\\subsection{What is $\\R$}\n$\\R$ is a number system containing $\\Q$ and satisfying the Completeness Axiom.\n\n\\begin{definition}[Archimedian Property]\nThe following properties of $\\R$ hold.\n\\begin{enumerate}\n  \\item For every positive real number $a > 0$, there is a natural number $n$ such that $n > a$.\n  \\item For every $a, b > 0$ in $\\R$, there is an $n \\in \\N$ such that $n\\cdot a > b$\n  \\item For every $\\epsilon > 0 \\in \\R$ there is an $n \\in \\N$ such that $\\frac{1}{n} < \\epsilon$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{proof}\n\\begin{enumerate}\n  \\item Assume towards contradiction that $\\exists a > 0 \\in \\R$ such that $a \\geq n$ for every $n \\in \\N$.\n  Thus $a$ is an upper bound for $\\N \\subseteq \\R$. By the completeness axiom, there exist some $b \\in \\R$\n  such that $b = \\sup \\N$. As $b$ is the least upper bound of the set $\\N$ the number $b - 1/2$ is\n  not an upper bound for $\\N$. In particular, $\\exists n \\in \\N$ such that $n > b - \\frac{1}{2}$.\n  This implies that $n + 1 > b - \\frac{1}{2} + 1 > b$. However, this says that $b \\neq \\sup N$,\n  which is a contradiction.\n  \\item Suppose $a, b > 0$, in particular $\\frac{b}{a} > 0$. By the first property, $\\exists n\\in \\N$ such that $n > \\frac{b}{a}$. This rearanging, $n\\cdot a > b$.\n  \\item Suppose $\\epsilon > 0, \\, \\epsilon \\in \\R$. Then $\\frac{1}{\\epsilon} > 0$. By (1) $\\exists n \\in \\N$ such that math $n > \\frac{1}{\\epsilon}$. Rearanging, we can get $\\epsilon > \\frac{1}{n}$.\n\\end{enumerate}\n\\end{proof}\n\n\\begin{corollary}\n  Suppose $a < b \\in \\R$ and $b - a > 1$. Then there is an integer $m$ such that $a < m < b$.\n\\end{corollary}\n\n\\begin{proof}\n  By the Archimedian Property, $\\exists k > \\max (|a|, |b|)$. Then we know that $-k < a < b < k$. Let the sets $K = \\lbrace j \\in \\Z: -k \\leq j \\leq k \\rbrace$ and $K' = \\lbrace j \\in \\Z: a \\leq j \\rbrace$ such that both $K, K'$ are finite and non empty as $k \\in K'  \\subseteq K$.\n\\end{proof}\n\n\\begin{theorem}[Density of $\\Q$ in $\\R$]\nFor every real numbers $a,b\\in \\R$ with $a<b$, $\\exists r \\in Q)$ such that $a < r < b$\n\\end{theorem}\n\n\\begin{proof}\n  We need to find a quotient of integers, $m, n \\in \\Z$ such that $n > 0$ and\n  \\begin{align*}\n    a < \\frac{m}{n} < b\n  \\end{align*}\n  We need to choose $n$ such that the demoniator is large enough so that consecutive increments of $1/n$ are too close to step over in the interval $(a, b)$.\n\n  Using the Archimedean Property we may pick $\\frac{1}{n} < \\epsilon$ where $\\epsilon = b - a$. \n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "f2d2ac80f4116718074b2b6b0bdd94ca63a8d0b9", "size": 9314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/lecture_2.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_2.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_2.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": 38.329218107, "max_line_length": 281, "alphanum_fraction": 0.6328108224, "num_tokens": 3437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519376, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.6883258993712829}}
{"text": "\\chapter{Numerical Results and Discussion}\\label{sec:results}\n\nAfter various numerical models and methods for biophysical simulations of the neuromuscular system were described in the previous chapters, the remainder of this work deals with their application and discusses the newly obtained insights.\nThe current chapter presents numerical results and demonstrates the use of OpenDiHu for all major components of the multi-scale models. \n\n\\Cref{sec:poisson_diffusion} begins with the simulation of toy problems such as Poisson and diffusion equations, which are used as building blocks for the more advanced simulations. Subsequently, dedicated solvers for the solid mechanics problem, the CellML models, the fiber based electrophysiology and the multidomain model are presented in \\cref{sec:solver_solid_mechanics,sec:results_cellml_models,sec:results_fiber_based_electrophysiology,sec:solver_multidomain_model}. Finally, \\cref{sec:coupled_electrophysiology_and_solid_mechanics} combines the fiber based electrophysiology model and the multidomain model with the solid mechanics solver to yield a comprehensive multi-physics simulation of muscle contraction.\n\n% ==================\n%\n% =-------------------\n\n\\section{Solution of Poisson and Diffusion Problems}\\label{sec:poisson_diffusion}\n\nSetting up a composite multi-scale simulation, where multiple equations are coupled, requires a profound understanding of the model components. \nThus, it can help to first simulate isolated models. We provide simple examples with our software, such as Laplace and Diffusion problems, as prototypes for elliptic and parabolic partial differential equations. The examples with analytic solutions are also used to validate the basic finite element solvers.\n\nIn this section, we showcase three of these simple problems. First, we consider the 1D Poisson problem $u''(x) = f$ on $\\Omega=[0,1]$ with Dirichlet boundary conditions $u(0)=0$ and $u(1)=1$ and right-hand side $f(x)=6\\,x$. The analytic solution is $y(x)=x^3$. \\Cref{fig:poisson} shows the analytic solution and the results of the finite element computation with linear and quadratic ansatz functions for two elements. Both linear and quadratic finite element solutions cannot exactly represent the cubic function, however, yield the best possible approximation. \nThe first bidomain equation given in \\cref{eq:bidomain1} is a 3D version of this Poisson problem and is needed in the multi-domain model to simulate EMG signals on the muscle surface.\n\nThe second example is a 2D Laplace problem $c(x)\\,\\Delta u(x) = 0$. The solution is given in \\cref{fig:laplace_composite_1} and can be interpreted as a static electric potential field. \nThe discretization uses quadratic Lagrange ansatz functions and is composed of two joined rectangular parts, each given by a structured mesh. The conductivity is set as $c=1$ in the left part and as $c=2$ in the right part. Dirichlet boundary conditions prescribe the electric potential at the five upper points in the right mesh to $u = -1$ and at the center of the right mesh as $u=1$. In addition, Neumann boundary conditions $\\partial u / \\partial \\bfn = -1$ corresponding to an outward electric current are set on the left boundary of the left mesh with the normal vector $\\bfn$ pointing to the left. \\Cref{fig:laplace_composite_1} visualizes the values of the degrees of freedom of the right-hand side contribution of the Neumann boundary conditions by the arrows. \nA 3D Laplace problem is also part of the multi-scale model and describes volume conduction in the adipose tissue domain as formulated in \\cref{eq:body}.\n\n% poisson - laplace\n\\begin{figure}\n  \\centering%\n  \\begin{subfigure}[t]{0.38\\textwidth}%\n    \\centering%\n    \\includegraphics[width=\\textwidth]{images/results/basic/analytic.pdf}%\n    \\caption{Solution of a 1D Poisson problem for linear and quadratic ansatz functions.}%\n    \\label{fig:poisson}%\n  \\end{subfigure}\\quad\n  \\begin{subfigure}[t]{0.58\\textwidth}%\n    \\centering%\n    \\includegraphics[width=\\textwidth]{images/results/basic/laplace_composite_1.png}%\n    \\caption{Finite element mesh and solution of a 2D electric conduction problem .}%\n    \\label{fig:laplace_composite_1}%\n  \\end{subfigure}\n  \\caption{Exemplary problems that can be solved with OpenDiHu and are part of the multi-scale problem.}%\n  \\label{fig:poisson_laplace_composite_1}%\n\\end{figure}%\n\nThe third presented example solves the 2D diffusion equation $\\partial u/\\partial t - \\div(\\bfsigma\\,\\grad u) = 0$ with homogeneous Neumann boundary conditions. The equation can be interpreted as a transient electric conduction problem. As shown in \\cref{fig:diffusion1}, the initial charge distribution is $u=1$ in a rectangle in the inner of the domain and $u=0$ everywhere else. The anisotropic diffusion or conductivity tensor $\\bfsigma$ is constant in the domain and set to %\n\\begin{align*}\n  \\bfsigma = \\frac15\\,\\mat{1 & 1\\\\\n              1 & 6}.\n\\end{align*}\nA regular mesh with $40\\times 40$ elements and linear finite element ansatz functions is used. \\Cref{fig:diffusion2} shows the solution at time $t=5$, where the initially discontinuous charge distribution has smoothed out and has expanded mainly in $y$ direction, which is the preferential direction of electric conduction in this example. A 3D version of this equation is part of the multidomain model and given by \\cref{eq:multidomain1}.\n\n% diffusion\n\\begin{figure}\n  \\centering%\n  \\begin{subfigure}[t]{0.4\\textwidth}%\n    \\centering%\n    \\includegraphics[width=\\textwidth]{images/results/basic/diffusion1.pdf}%\n    \\caption{Initial charge distribution, $t=0$.}%\n    \\label{fig:diffusion1}%\n  \\end{subfigure}\\quad\n  \\begin{subfigure}[t]{0.4\\textwidth}%\n    \\centering%\n    \\includegraphics[width=\\textwidth]{images/results/basic/diffusion2.pdf}%\n    \\caption{Solution at $t=5$.}%\n    \\label{fig:diffusion2}%\n  \\end{subfigure}\n  \\caption{A 2D electric conduction problem as a demonstrator for the solution of transient problems in OpenDiHu.}%\n  \\label{fig:diffusion}%\n\\end{figure}%\n\n\n\\begin{reproduce_no_break}\n  The three presented simulations can be executed and visualized as follows:\n  \\begin{lstlisting}[columns=fullflexible,breaklines=true,postbreak=\\mbox{\\textcolor{gray}{$\\hookrightarrow$}\\space},language=python]\n    cd $\\$$OPENDIHU_HOME/examples/poisson/poisson1d_2/build_release\n    ./linear ../settings_1d.py && plot out/*.py\n    ./quadratic ../settings_1d.py && plot out/*.py\n    ./hermite ../settings_1d.py && plot out/*.py\n\n    cd $\\$$OPENDIHU_HOME/examples/laplace/laplace_composite/build_release/\n    ./laplace_composite_2d ../settings_2d_2.py && paraview paraview_state.pvsm\n\n    cd $\\$$OPENDIHU_HOME/examples/diffusion/anisotropic_diffusion/build_release\n    ./anisotropic_diffusion2d ../settings2d.py && plot out/*.py\n  \\end{lstlisting}\n\\end{reproduce_no_break}\n\n%-----\n\\section{Simulation of Solid Mechanics Models}\\label{sec:solver_solid_mechanics}\n\nNext, we demonstrate the solid mechanics solvers, which can be used to compute muscle contraction. In this section, we focus on the passive material behavior.\nAs described in \\cref{sec:material_linear_model,sec:material_modeling}, the mechanics equations can be computed in linearized or in nonlinear form within OpenDiHu.\nIn the following, \\cref{sec:comparison_linear_nonlinear} applies both model approaches in a simulation of an externally stretched muscle and compares the results. Then, \\cref{sec:validation_nonlinear} validates the implementation of the nonlinear hyperelasticity solver in OpenDiHu. Finally, \\cref{sec:simulation_hyperelastic_tendon} showcases, using the simulation of a tendon, how more complex material models can be computed.\n\n%-----\n\\subsection{Comparison of Linear and Nonlinear Mechanics Models}\\label{sec:comparison_linear_nonlinear}\n\nWe demonstrate the use of linear and nonlinear mechanics models in a simulation of an externally stretched biceps muscle. The muscle belly is fixed at its lower end and an upwards pulling force acts on the upper end, effectively stretching the muscle tissue in vertical direction.\n\nWe solve two scenarios with the same geometry and boundary conditions but different material models. The first scenario uses the linearized mechanics model given in \\cref{sec:material_linear_model}. We use material parameters obtained from porcine in vitro indentor tests in literature \\cite{schock1982vivo} and set the bulk modulus to $K=\\SI{39}{\\kilo\\pascal}$ and the shear modulus to $\\mu=\\SI{48}{\\kilo\\pascal}$.\n\nThe second scenario uses the incompressible transversely isotropic hyperelastic muscle material based on the Mooney-Rivlin description without active stress, which is defined in \\cref{sec:material_nonlinear_model}. The material parameters are set to the values given \\cite{Heidlauf2016}.\n\n\\Cref{fig:lin_nonlin_muscle_mechanics} shows the geometric setup of the model. We discretize the biceps geometry by a 3D mesh with 252  elements, quadratic finite element ansatz functions,  and a total of $13 \\times 13 \\times 15 = 2535$ nodes.\nThe linearized material model uses this mesh to construct the stiffness matrix and to solve the linear system.\nFor the nonlinear model, an additional coarser linear mesh is constructed, and linear-quadratic Taylor-Hood elements are used for the discretization. \n\nA total force of $(F_x,F_y,F_z) = (0,\\SI{-0.4}{\\newton},\\SI{-3}{\\newton})$ is applied, which points in negative $z$-direction, i.e., upwards in \\cref{fig:lin_nonlin_muscle_mechanics}, and slightly in negative $y$-direction, i.e, to the left in \\cref{fig:lin_nonlin_muscle_mechanics}.\nInstead of a single force vector acting on a point, the equivalent constant surface load is applied on the whole top face of the muscle geometry.\n\nWe consider a static problem where no timestepping is required. In the linear model, the resulting displacements are obtained by a GMRES solver, which solves the linear system of equations \\cref{eq:linearized_helper4} corresponding  to the finite element formulation.\nThe nonlinear model uses increasing load steps as described in \\cref{sec:convergence_improvements_for_the_nonlinear_solver}, which are adaptively refined in case the solver diverges at one load step. The scheme solves a system of nonlinear equations for every load step, and the contained linear system is solved by a direct solver.\n\n% linear and nonlinear mechanics solvers\n\\begin{figure}\n  \\centering%\n  \\hfill\n  \\begin{subfigure}[t]{0.4\\textwidth}%\n    \\centering%\n    \\includegraphics[height=12cm]{images/results/basic/lin_nonlin_muscle_mechanics_b.png}%\n    \\caption{Solution of the linear model. The arrows at the top visualize the (negated) right-hand side of the finite element formulation, with the absolute values indicated by the arrow lengths and color. The surface of the muscle mesh is colored according to the values of the displacements.}%\n    \\label{fig:lin_nonlin_muscle_mechanics_b}%\n  \\end{subfigure}\\hfill\n  \\begin{subfigure}[t]{0.4\\textwidth}%\n    \\centering%\n    \\includegraphics[height=12cm]{images/results/basic/lin_nonlin_muscle_mechanics_a.png}%\n    \\caption{Solution of the nonlinear model. The arrows specify the traction vectors in current configuration.  Their absolute values are indicated by the arrow sizes and the color. The surface of the muscle mesh is colored according to the second Piola-Kirchhoff stress.}%\n    \\label{fig:lin_nonlin_muscle_mechanics_a}%\n  \\end{subfigure}\n  \\hfill\n  \\caption{Solid mechanics solver example: Comparison of linear and nonlinear mechanics models. A biceps muscle is stretched by an applied force. The yellow mesh specifies the identical reference configuration in both scenarios.}%\n  \\label{fig:lin_nonlin_muscle_mechanics}%\n\\end{figure}%\n\nThe results of the linear and nonlinear models are shown in \\cref{fig:lin_nonlin_muscle_mechanics_b,fig:lin_nonlin_muscle_mechanics_a}. \nIn both images, the identical reference configuration is given by the yellow wireframe and the deformed muscle is given by the solid body with colored mesh. \nThe deformed body in the linear model in \\cref{fig:lin_nonlin_muscle_mechanics_b} is colored according to the resulting vector of unknowns, which contains the displacements.  Arrows on the upper end of the geometry indicate the negative right-hand side of the linear system as formulated in \\cref{eq:linearized_mechanics_rhs}. The arrows correspond to the applied Neumann boundary conditions in the weak form of the finite element formulation and point in the direction of the applied surface load.\n\nIn the visualization of the nonlinear model in \\cref{fig:lin_nonlin_muscle_mechanics_a}, the deformed muscle body is colored according to the second Piola-Kirchhoff (PK2) stress. It can be seen that the stress is highest at the bottom bearing and at the top end, where the muscle cross-section is smaller. The arrows visualize the traction forces $\\bft$ on virtual horizontal cuts. As a result, the arrows that can be seen on top of the muscle geometry correspond to the applied external force, and the arrows at the bottom indicate the forces on the bearing.\n\nA comparison of the two obtained results from the linear and nonlinear models shows a qualitatively different outcome. With the linear model, the muscle bends to the left, whereas, with the nonlinear model, it bends to the right. This effect is a result of the different material behavior. The linear model is isotropic and the deformation follows the direction of the applied force, which points to the upper left. The nonlinear model has an anisotropy and is stiffer in fiber direction. As a consequence, the muscle deforms less in longitudinal direction and therefore moves to the right.\nThus, the material models influence the bending direction in this scenario.\n\nIn a second example, we compare the muscle stretches that results from different external forces acting in $z$-direction.  We use the same scenario as before and increase the applied force from 0 to \\SI{15}{\\newton}. We measure the displacement of one node in the top face of the muscle, for both the linear model and the nonlinear model. While the stress-strain relations  in 1D extension tests  can be derived analytically for linear and nonlinear models, our examples considers a real 3D setting where this relation is influenced by the geometry, e.g., by non-parallel fiber directions, as the force is not applied exactly in fiber direction.\n\n\\Cref{fig:linear_nonlinear_displacements} shows the resulting muscle extensions for different applied external forces for the linear and nonlinear models.\nIt can be seen that the stretch of the muscle increases nonlinearly for the transversely isotropic hyperelastic model, in contrast to the linear progression of the linear model.\nThe slopes of the two curves are qualitatively different, which is a result of the chosen material parameters from different experimental origins. It would be possible to scale the linear model to better match the nonlinear model behavior by simply reducing the value of the bulk modulus accordingly.\n\n% study of displacements, linear  nonlinnear\n\\begin{figure}\n  \\centering%\n  \\includegraphics[width=0.7\\textwidth]{images/results/basic/linear_nonlinear_displacements.pdf}%\n  \\caption{Solid mechanics example: Quantitative comparison of the relation between applied force and extension of the muscle for a linear and a nonlinear solid mechanics model.}%\n  \\label{fig:linear_nonlinear_displacements}%\n\\end{figure}\n\nThe two presented studies show that a linear isotropic material model can give significantly different results than a more accurate nonlinear transversely isotropic model. Therefore, simulations of muscle contraction that target high accuracy should use the according nonlinear models. Nevertheless, both approaches are implemented and can be used with OpenDiHu.\n\n\\begin{reproduce_no_break}\n  The two simulations for \\cref{fig:lin_nonlin_muscle_mechanics} can be run as follows:\n  \\begin{lstlisting}[columns=fullflexible,breaklines=true,postbreak=\\mbox{\\textcolor{gray}{$\\hookrightarrow$}\\space}]\n    cd $\\$$OPENDIHU_HOME/examples/solid_mechanics/linear_elasticity/muscle/build_release\n    ./linear_elasticity ../settings_linear_elasticity.py\n    cd $\\$$OPENDIHU_HOME/examples/solid_mechanics/mooney_rivlin_transiso/build_release\n    ./3d_hyperelasticity ../settings_3d_muscle.py --njacobi=1\n  \\end{lstlisting}\n  The study in \\cref{fig:linear_nonlinear_displacements} can be run and plotted using the scripts in the repository at \\href{https://github.com/dihu-stuttgart/performance}{github.com/dihu-stuttgart/performance}\n  in the directory \\code{opendihu/}\\\\\\code{23_linear_nonlinear_mechanics}.\n\\end{reproduce_no_break}\n\n%-----\n\\subsection{Validation of the Nonlinear Solid Mechanics Solver}\\label{sec:validation_nonlinear}\n\nNext, we perform tests to validate our implementation of the nonlinear hyperelasticity solvers.\nWe simulate the same scenario with our software and with the nonlinear finite element analysis tool \\emph{FEBio} \\cite{Maas2012}.\nFEBio is developed at the University of Utah and the Columbia University in the USA. FEBio contains solid mechanics solvers that can be run from the command line or a graphical user interface model. An extensive model library contains material models also from the domain of biomechanics. The mechanics solver uses the PARDISO linear solver \\cite{pardiso2020}, which exploits shared memory parallelism.\n\nAn adapter in OpenDiHu exists, which can output the required configuration file for FEBio, run the solver, and parse the computed solution from the text files that are output by FEBio. Thus, we can conduct our validation studies fully in OpenDiHu by using similar Python settings files and the same meshes for the computation in OpenDiHu and the reference solution computed by FEBio.\n\nApart from the present study, the FEBio adapter in OpenDiHu can also be used to solve quasi-static coupled problems with the electrophysiology part solved in OpenDiHu and the mechanics part solved in FEBio. However, test have shown that the interfacing method of generating configuration files and parsing result files in every timestep leads to higher runtimes than directly using the mechanics solver of OpenDiHu.\n\nIn our validation studies, we consider a unit cube  that is discretized by $8\\times 8 \\times 8$ quadratic elements and 4913 degrees of freedom. \\Cref{fig:tensile_shear_test_img} shows the discretized cube in yellow color. Its orientation is given by the coordinate frame in the lower left of \\cref{fig:tensile_test_img}. \nThe following Dirichlet boundary conditions are prescribed: All points of the lower face are fixed at $z=0$. The points of the two edges ($y=0 \\wedge z=0$) and ($x=0 \\wedge z=0$) are additionally fixed in $y$ and $x$ directions, respectively. The corner at $x=y=z=0$ is fixed completely. Thus, the cube can freely deform in its bottom plane, but not move nor rotate as a whole. \n\n% visualization of the scenarios\n\\begin{figure}\n  \\centering%\n  \\hfill\n  \\begin{subfigure}[t]{0.45\\textwidth}%\n    \\centering%\n    \\includegraphics[height=8cm]{images/results/basic/tensile_test_img.png}%\n    \\caption{Tensile test scenario used in the first validation experiment.}%\n    \\label{fig:tensile_test_img}%\n  \\end{subfigure}\\hfill\n  \\begin{subfigure}[t]{0.45\\textwidth}%\n    \\centering%\n    \\includegraphics[height=8cm]{images/results/basic/shear_test_img.png}%\n    \\caption{Shear test scenario used in the second validation experiment.}%\n    \\label{fig:shear_test_img}%\n  \\end{subfigure}\n  \\hfill\n  \\caption{Scenarios used for validation of the solid mechanics solver. The reference and the current configuration are given by the yellow and orange meshes, respectively.}%\n  \\label{fig:tensile_shear_test_img}%\n\\end{figure}%\n\nThe first study is a tensile test, where a uniform surface load pointing in positive $z$ direction is applied on the top face of the cube. We increase the force from 1 to \\SI{50}{\\newton}. For the largest force, the cube deforms as shown by the orange geometry in \\cref{fig:tensile_shear_test_img}. Note that the volume is preserved due to the incompressibility constraint in the material model.\n\nWe use an incompressible and isotropic Mooney-Rivlin material with parameters $c_1=c_2=1$. The material can be simulated in three different forms in OpenDiHu. In the following, we list all model formulations in OpenDiHu and the reference formulation in FEBio,\nexpressed by the strain energy functions $\\Psi$, $\\Psi_\\text{iso}$ and $\\Psi_\\text{vol}$ introduced in the modeling chapter in \\cref{sec:material_modeling}:\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item the \\say{fully incompressible}, mixed $u$-$p$ formulation, which ensures incompressibility using the Lagrange multipliers,\n\\begin{align}\n    \\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2) &= c_1\\,(\\bar{I}_1 - 3) + c_2\\,(\\bar{I}_2 - 3), \\quad J=1, \\label{eq:validation_incompressible}\n\\end{align}\n\\item the \\say{nearly incompressible} formulation in terms of the invariants $I_1$ to $I_3$,\n\\begin{subequations}\\label{eq:validation_1b}\n  \\begin{align}      \n      \\Psi(I_1,I_2,I_3) &= c_1\\,(I_1 - 3) + c_2\\,(I_2 - 3) + \\kappa\\,(\\sqrt{I_3} - 1)^2 - d\\,\\log(\\sqrt{I_3}),\\label{eq:validation_nearly_incompressible_1} \\\\\n         d &= 2\\,(c_1 + 2\\,c_2) \\label{eq:validation_nearly_incompressible},\n\\end{align}\n\\end{subequations}\n\\item the nearly incompressible formulation given in decoupled form, in terms of the reduced invariants $\\bar{I}_1$ and $\\bar{I}_2$,\n\\begin{subequations}\\label{eq:validation_1c}\n  \\begin{align}\n      \\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2) &= c_1\\,(\\bar{I}_1 - 3) + c_2\\,(\\bar{I}_2 - 3),\\label{eq:validation_nearly_incompressible_decoupled_1} \\\\ \n      \\Psi_\\text{vol}(J) &= \\kappa\\,G(J) \\quad\\text{with }  G(J) = \\dfrac14\\big(J^2 - 1 - 2\\,\\log(J)\\big), \\label{eq:validation_nearly_incompressible_decoupled}\n  \\end{align}\n\\end{subequations}\n\\item and the one used in FEBio, which also describes a nearly incompressible material in decoupled form, but with a different penalty function $G(J)$,\n\\begin{subequations}\\label{eq:validation_1d}\n  \\begin{align}\n      \\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2) &= c_1\\,(\\bar{I}_1 - 3) + c_2\\,(\\bar{I}_2 - 3),\\label{eq:validation_nearly_incompressible_decoupled_febio_1} \\\\ \n      \\Psi_\\text{vol}(J) &= \\kappa\\,G(J) \\quad\\text{with } G(J) = \\dfrac12\\big(\\log(J)\\big)^2 \\label{eq:validation_nearly_incompressible_decoupled_febio}.\n  \\end{align}\n\\end{subequations}\n\\end{enumerate}\n%\nFor the three nearly incompressible descriptions in \\cref{eq:validation_1b,eq:validation_1c,eq:validation_1d}, we set the incompressibility parameter to $\\kappa=\\num{1e3}$.\n\nWe compare the resulting normal stress value $S_{33}$ in $z$-direction of the second Piola-Kirchhoff stress tensor $\\bfS$ for all formulations listed in \\crefrange{eq:validation_incompressible}{eq:validation_1d}. For the tensile test, this stress value is constant throughout the domain. \\Cref{fig:validation_tensile_test} shows the computed stresses over the computed strain values.\nIt can be seen that the three formulations in OpenDiHu yield approximately the same results as the reference solution given by FEBio over the whole range of applied forces.\n\n% results tensile test\n\\begin{figure}\n  \\centering%\n  \\includegraphics[width=\\textwidth]{images/results/basic/validation_tensile_test.pdf}%\n  \\caption{Solid mechanics solver validation: Results of the tensile test validation experiment. The stress-strain curve for three different formulations in OpenDiHu and the computation in FEBio match.}%\n  \\label{fig:validation_tensile_test}%\n\\end{figure}\n\nAs the previous tensile test only validates stress and strain in one direction, we additionally conduct a numerical shear experiment. A shear force $\\bfF=(0.1\\alpha, 0.05\\alpha, 0)^\\top$ is applied on the top face of the cube and $\\alpha$ is again varied between 1 and $\\SI{50}{\\newton}$. \\Cref{fig:shear_test_img} shows the deformed configuration for the highest force by the orange colored body.\n\n% results shear test\n\\begin{figure}\n  \\centering%\n  \\includegraphics[width=0.7\\textwidth]{images/results/basic/validation_shear_test.pdf}%\n  \\caption{Solid mechanics solver validation:Results of the shear test validation experiment. The values of the second Piola-Kirchhoff tensor computed by OpenDiHu (solid lines) and FEBio (dotted lines) closely match.}%\n  \\label{fig:validation_shear_test}%\n\\end{figure}\n\nIn this second study, we consider one point in the interior of the domain, which is 3 elements below the top face of the mesh. We compare all six distinct entries of the symmetric second Piola-Kirchhoff tensor $\\bfS$ between the fully incompressible model in OpenDiHu and the nearly incompressible model in FEBio. \n\n\\Cref{fig:validation_shear_test} shows the computed values in a stress-strain diagram. The solutions of OpenDiHu and FEBio are given by solid and dotted lines, respectively. It can be seen that the curves coincide, which validates the implementation in OpenDiHu.\n\n\\begin{reproduce_no_break}\n  The tensile test validation experiment can be reproduced by the following commands:\n  \\begin{lstlisting}[columns=fullflexible,breaklines=true,postbreak=\\mbox{\\textcolor{gray}{$\\hookrightarrow$}\\space}]\n    cd $\\$$OPENDIHU_HOME/examples/solid_mechanics/tensile_test/build_release\n    ../run_force.sh\n    cd $\\$$OPENDIHU_HOME/examples/solid_mechanics/tensile_test\n    ./plot_validation.py\n  \\end{lstlisting}\n  The shear test can be executed analogously by replacing \\code{tensile_test} by \\code{shear_test} in the given paths.\n\\end{reproduce_no_break}\n\n%-----\n\\subsection{Simulation of a Hyperelastic Tendon Material}\\label{sec:simulation_hyperelastic_tendon}\n\nNext, we demonstrate the use of a more complex constitutive material model, which represents tendon tissue. The material is formulated in \\cite{Carniel2017}. The model describes microstructural interactions between collagen fibers and their matrix. It consists of a transversely isotropic model, which describes the high stiffness in fiber direction, and a coupled model for the compressive response. The model is formulated in terms of a logarithmic strain measure.\n\n%from the paper: The high stiffness of tendons under tensile tests is handled by a transversely isotropic model while the coupled compressive response is modeled by means of a Fung-type potential in terms of Seth-Hill’s generalized strain tensors. In present study the logarithm strain measure is used instead of the usually employed Green-Lagrange strain\n\n\\Cref{fig:tendon_material_simulation} shows the geometries of the tendons of the biceps brachii and the results of the simulations. The lower tendon in \\cref{fig:dynamic_mooney_rivlin_6} is fixed at its left end and a constant surface traction of \\SI{1}{\\newton} in total pulls to the right. The image shows the initial configuration by the wireframe mesh and the current configuration after $t=\\SI{10}{\\ms}$, colored according to the resulting velocity.\nSimilarly, the upper tendons in \\cref{fig:dynamic_mooney_rivlin_7} are fixed at the right ends and stretched to the left resulting from the applied force at the left end.\n\n\\begin{figure}\n  \\centering%\n  \\begin{subfigure}[t]{\\textwidth}%\n    \\centering%\n    \\includegraphics[width=0.9\\textwidth]{images/results/basic/dynamic_mooney_rivlin_6.png}%\n    \\caption{Dynamic simulation of the lower tendon of a biceps brachii. The attachment to the ulna bone is at the left end. The free right end bends due to the applied surface traction.}%\n    \\label{fig:dynamic_mooney_rivlin_6}%\n  \\end{subfigure}\\\\[4mm]\n  \\begin{subfigure}[t]{\\textwidth}%\n    \\centering%\n    \\includegraphics[width=0.9\\textwidth]{images/results/basic/dynamic_mooney_rivlin_7.png}%\n    \\caption{Simulation of the two upper tendons of the two biceps heads.}%\n    \\label{fig:dynamic_mooney_rivlin_7}%\n  \\end{subfigure}\n  \\caption{Simulation of tendons as a showcase of dynamic simulations with complex material models. The color coding indicates the velocity.}%\n  \\label{fig:tendon_material_simulation}%\n\\end{figure}%\n\nIn summary, this section demonstrated the capabilities of the solid mechanics solvers in OpenDiHu. \\Cref{sec:comparison_linear_nonlinear,sec:simulation_hyperelastic_tendon} simulated extension of the biceps muscle and tendons due to external forces. The comparison of results from a linear and a nonlinear model showed that a linear isotropic material cannot always accurately predict the behavior of muscle tissue and, thus, a nonlinear model is required. The validation experiments in \\cref{sec:validation_nonlinear} demonstrated that OpenDiHu correctly computes deformation and stresses of incompressible materials.\n\nThe solid mechanics solvers can also be coupled to solvers of electrophysiology to simulate muscle contraction resulting from the spatially heterogeneous activation and considering the neuronal stimulation dynamics. Moreover, coupled simulations of the muscle and tendons are possible. Such simulations are described in \\cref{sec:fiber_based_contraction} and \\cref{sec:surface_coupling_contraction}, respectively.\n\n% ------------\n%\n% f===========\n\n\n", "meta": {"hexsha": "c3588834b66a5d530a509a10608f31fd65bb17aa", "size": 29014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/08_results_0.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/08_results_0.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/08_results_0.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": 92.696485623, "max_line_length": 771, "alphanum_fraction": 0.7886882195, "num_tokens": 7310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6883258944481927}}
{"text": "\\section{Options, Part 1}\n\n\n\\subsection*{Net option payoff}\n\nThe break-even point is given by $S_T$ at which Net Payoff is zero:\n\n$Net payoff = max[S_T-K,0]-C(1+r)^T $\n\n\n\\subsection*{Option strategies}\n\n\\begin{itemize}[leftmargin=*]\n\t\\item Protective Put: Buy stock + Buy a put\n\t\\item Bull Call Spread: Buy a Call K1 + Write a Call K2, $K1<K2$\n\t\\item Straddle: Buy a Call at $K$ + Buy a Put at $K$\n\\end{itemize} \n\n\\subsection*{Corporate securities as options}\n\\begin{itemize}\n\t\\item Equity ($E$): A call option on the firm’s assets ($A$) with the exercise price\n\tequal to its bond’s redemption value.\n\t\\item Debt ($D$): A portfolio combining the firm’s assets ($A$) and a short position in\n\tthe call with the exercise price equal to its bond’s face value ($F$):\n\t\n\\end{itemize}\n\n\n$ A = D+E \\implies D=A-E$ \\\\\n$ E \\equiv max(0,A-F) $ \\\\\n$ D=A-E=A-max[0,A-F]$\n\n\\subsection*{Put-Call parity for European options}\n\n$ C + B \\cdot K = P + S$\n\n\n\\subsection*{Binominal option pricing model}\nStock\n\n\t\\begin{tikzpicture}[>=stealth,sloped]\n\t\\matrix (tree) [\n\tmatrix of nodes,\n\tminimum size=0cm,\n\tcolumn sep=1cm,\n\trow sep=0.0cm,nodes={text width=2em}\n\t]\n\t{\n\t\t&  $S_u=uS_0$ \t &  \\\\\n\t\t{}\t&   \t\t &  \\\\\n\t\t&  $S_d=dS_0$ \t &  \\\\\n\t};\n\t\\node[bullet,right=0mm of tree-2-1.east,label=above:$S_0$](b-2-1){};\n\t\\node[bullet,left=0mm of tree-1-2.west](b-1-2){};\n\t\\node[bullet,left=0mm of tree-3-2.west](b-3-2){};\n\t\\draw[->] (b-2-1) -- (b-1-2) node [midway,above] {};\n\t\\draw[->] (b-2-1) -- (b-3-2) node [midway,above] {};\n\t\\end{tikzpicture}\n\nBond\n\n\\begin{tikzpicture}[>=stealth,sloped]\n\t\\matrix (tree) [\n\tmatrix of nodes,\n\tminimum size=0cm,\n\tcolumn sep=1cm,\n\trow sep=0.0cm,nodes={text width=2em}\n\t]\n\t{\n\t\t&  $1+r$ \t &  \\\\\n\t\t{}\t&   \t\t &  \\\\\n\t\t&  $1+r$ \t &  \\\\\n\t};\n\t\\node[bullet,right=0mm of tree-2-1.east,label=above:$1$](b-2-1){};\n\t\\node[bullet,left=0mm of tree-1-2.west](b-1-2){};\n\t\\node[bullet,left=0mm of tree-3-2.west](b-3-2){};\n\t\\draw[->] (b-2-1) -- (b-1-2) node [midway,above] {};\n\t\\draw[->] (b-2-1) -- (b-3-2) node [midway,above] {};\n\\end{tikzpicture}\n\nOption at Expiration\n\n\\begin{tikzpicture}[>=stealth,sloped]\n\t\\matrix (tree) [\n\tmatrix of nodes,\n\tminimum size=0cm,\n\tcolumn sep=1cm,\n\trow sep=0.0cm,nodes={text width=2em}\n\t]\n\t{\n\t\t&  $max(S_u-K,0)$ \t &  \\\\\n\t\t{}\t&   \t     \t &  \\\\\n\t\t&  $max(S_d-K,0)$ \t &  \\\\\n\t};\n\t\\node[bullet,right=0mm of tree-2-1.east,label=above:$C_0$](b-2-1){};\n\t\\node[bullet,left=0mm of tree-1-2.west](b-1-2){};\n\t\\node[bullet,left=0mm of tree-3-2.west](b-3-2){};\n\t\\draw[->] (b-2-1) -- (b-1-2) node [midway,above] {};\n\t\\draw[->] (b-2-1) -- (b-3-2) node [midway,above] {};\n\\end{tikzpicture}\n\nReplicating portfolio (call option)\n$\n\\begin{pmatrix}\n\tS_u & (1+r)  \\\\\n\tS_d  & (1+r)  \\\\\n\t\t\t\t\t\t\n\\end{pmatrix} \\cdot \n\\begin{pmatrix}\n\ta \\\\\n\tb \\\\\t\t\t\t\t\t\t\n\\end{pmatrix}\t\n=\n\\begin{pmatrix}\n\tmax(K-S_u,0)\\\\\n\tmax(K-S_d,0) \\\\\t\t\t\t\t\t\n\\end{pmatrix}\n$ \n\nsolve system to form a portfolio of stock and bond that replicates the call’s payoff:\n$a$ shares of the stock;\n$b$ dollars in the riskless bond\n\n\\subsection*{Binominal option pricing model with multiple periods}\n\n\\begin{tikzpicture}[>=stealth,sloped]\n\t\\matrix (tree) [\n\tmatrix of nodes,\n\tminimum size=0cm,\n\tcolumn sep=1cm,\n\trow sep=0.0cm,nodes={text width=2em}\n\t]\n\t{\n\t\t &  \t\t & $C_{uu}$  & \\\\\n\t\t &  $C_u$    &  \t\t & \\\\\n\t  \t &           & $C_{ud}$\t & \\\\\n     {}  &           &\t         & \\\\\n\t\t &           & $C_{du}$\t & \\\\\n\t\t &  $C_{d}$  &      \t & \\\\\n\t\t &           & $C_{dd}$\t & \\\\\n\t};\n\t\\node[bullet,right=0mm of tree-4-1.south,label=above:$C_0$](b-4-1){};\n\t\\node[bullet,left=1mm of tree-2-2.south](b-2-2){};\n\t\\node[bullet,left=1mm of tree-6-2.south](b-6-2){};\n\t\\node[bullet,left=1mm of tree-1-3.south](b-1-3){};\n\t\\node[bullet,left=1mm of tree-3-3.south](b-3-3){};\n\t\\node[bullet,left=1mm of tree-5-3.south](b-5-3){};\n\t\\node[bullet,left=1mm of tree-7-3.south](b-7-3){};\n\t\\draw[->] (b-4-1) -- (b-2-2) node [midway,above] {};\n\t\\draw[->] (b-4-1) -- (b-6-2) node [midway,above] {};\n\t\\draw[->] (b-2-2) -- (b-1-3) node [midway,above] {};\n\t\\draw[->] (b-2-2) -- (b-3-3) node [midway,above] {};\n\t\\draw[->] (b-6-2) -- (b-5-3) node [midway,above] {};\n\t\\draw[->] (b-6-2) -- (b-7-3) node [midway,above] {};\t\n\\end{tikzpicture}\n\nCompute the time-0 value working backwards: first $C_u$ and $C_d$ then $C_0$.\nIn summary:\n\\begin{itemize}\n\t\\item Replication strategy gives payoffs identical to those of the call.\n\t\\item Initial cost of the replication strategy must equal the call price\n\\end{itemize}\n", "meta": {"hexsha": "a6051c14b553414541eba33c059311dcea192c32", "size": 4414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.415.2x/assets/week_12.tex", "max_stars_repo_name": "j053g/cheatsheets", "max_stars_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-14T08:49:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T17:26:15.000Z", "max_issues_repo_path": "15.415.2x/assets/week_12.tex", "max_issues_repo_name": "j053g/cheatsheets", "max_issues_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15.415.2x/assets/week_12.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": 27.0797546012, "max_line_length": 88, "alphanum_fraction": 0.5897145446, "num_tokens": 1789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.6883258924039194}}
{"text": "\\lab{GMRES}{GMRES}\n\\objective{The Generalized Minimal Residuals (GMRES) algorithm is an iterative Krylov subspace method for efficiently solving large linear systems.\nIn this lab we implement the basic GMRES algorithm, then make an improvement by using restarts.\nWe then discuss the convergence of the algorithm and its relationship with the eigenvalues of a linear system.\nFinally, we introduce SciPy's version of GMRES.}\n\n\n\\begin{comment}\n\\section*{The Arnoldi Iteration and Approximate Solutions} % ==================\n\nLet $A$ be an $m\\times m$ matrix (real or complex), where $m$ is very large,\nand let $b \\in \\mathbb{F}^m$ ($\\mathbb{F}$ may either be the real or complex numbers).\nLet $\\mathcal{K}_n$ denote the order-$n$ Krylov subspace generated by $A$ and $b$.\nIn each iteration, we consider the least squares problem\n\\begin{equation}\n\\underset{x \\in \\mathcal{K}_n}{\\text{minimize}}\\qquad \\|b-Ax\\|_2.\n\\label{eq:GMRES_lstsq1}\n\\end{equation}\nNow if $x \\in K_n$, then $x$ can be expressed as a linear combination of basis vectors $b, Ab, \\ldots, A^{n-1}b$, i.e.\n\\[\nx = y_1b + y_2Ab + \\cdots + y_nA^{n-1}b.\n\\]\nIf we let $K_n$ be the matrix whose columns are $b, Ab, A^{2}b, \\cdots, A^{n-1}b$, then we can write this simply as\n$x = K_n y$.\nThen the solution of the least squares problem is the vector $K_{n}y$ such that $\\|b-A K_{n}y\\|_2$ is minimized.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figures/LeastSquares.pdf}\n\\caption{GMRES involves solving the least squares problem repeatedly.}\n\\end{figure}\n\nThe major drawback of this approach is that it relies on the matrix $K_n$, which tends to be ill-conditioned due to its columns\nbeing far from orthogonal (as discussed in Lab \\ref{lab:kry_arnoldi}).\n%To see this, suppose there is an eigenbasis for $A$ with associated eigenvalues, and suppose $\\lambda$ is the largest eigenvalue.\n%Then $\\lambda^n$ is an eigenvalue of $A^n$.\n%Since $\\lambda$ is bigger than the other eigenvalues of $A$, $\\lambda^n$ may be much, much bigger than the other eigenvalues of $A^n$,\n%which are simply the eigenvalues of $A$ raised to the $n$th power.\n%Thus the eigenvector associated with $\\lambda$ often begins to dominate as we progress, with the end result being that the columns of\n%$K_n$ become nearly linearly dependent.\nThe easiest fix in this situation is to use the Arnoldi iteration so that we have an orthonormal basis for $\\mathcal{K}_n$ to work with.\nNot only does this alleviate the problem of ill-conditioning, it also allows us to optimize in other ways, due to the special\nstructure of the matrices produced.\n\nLet $q_1,\\ldots, q_n$ be the orthonormal basis for $\\mathcal{K}_n$ obtained by the Arnoldi iteration, and let $Q_n$ be the matrix\nhaving these vectors as its columns.\nRecall that $q_1 = b/\\|b\\|_2$.\nFinally, let $H_n$ be the $(n+1)\\times n$ upper Hessenberg matrix generated by the Arnoldi iteration, and let $e_1=(1,0,\\cdots,0)$.\n\nIn this orthonormal basis, $x \\in \\mathcal{K}_n$ implies that there is some vector $y$ such that $x = Q_n y$.\nFurther, it is not hard to check that the matrices generated by the Arnoldi iteration satisfy the equation\n\\[\nAQ_n = Q_{n+1}H_n.\n\\]\nWe also have the identity\n\\[\nb = \\|b\\|_2q_1 = \\|b\\|_2Q_{n+1}e_1.\n\\]\nPutting all of this together, we can rewrite the objective function of our least squares problem as follows:\n\\begin{align*}\n\\|b - Ax\\|_2 &= \\|Ax - b\\|_2\\\\\n&= \\|AQ_ny - b\\|_2\\\\\n&= \\|Q_{n+1}H_ny - \\left(\\|b\\|_2Q_{n+1}e_1\\right)\\|_2\\\\\n&= \\|Q_{n+1}\\left(H_n y - \\|b\\|_2e_1\\right)\\|_2.\n\\end{align*}\n\nThe matrix $Q_{n+1}$ has orthonormal columns, but it does not have enough columns to be a unitary matrix.\nLet us extend the set $q_1,\\ldots, q_{n+1}$ to an orthonormal basis $q_1,\\ldots,q_{n+1},q_{n+2},\\ldots,q_m$\nof our space, and let $Q'$ be the matrix whose columns are equal to these vectors.\nThen $Q'$ is now a unitary matrix, and hence preserves the norm, i.e. $\\|Q'z\\|_2 = \\|z\\|_2$ for all $z \\in \\mathbb{F}^m$.\nGiven $x \\in \\mathbb{F}^{n+1}$, if we define $x' \\in \\mathbb{F}^m$ to be\n\\[\nx' =\n\\begin{bmatrix}\n  x\\\\\n  0\\\\\n  \\vdots\\\\\n  0\n\\end{bmatrix},\n\\]\nthen you can easily check that\n\\[\nQ'x' = Q_{n+1}x.\n\\]\nFrom this, we deduce that\n\\begin{align*}\n\\|Q_{n+1}x\\|_2 &= \\|Q'x'\\|_2\\\\\n& = \\|x'\\|_2\\\\\n&= \\|x\\|_2.\n\\end{align*}\nHence, we conclude that\n\\[\n\\|Q_{n+1}\\left(H_n y - \\|b\\|_2e_1\\right)\\|_2 = \\|H_n y - \\|b\\|_2e_1\\|_2.\n\\]\nThus, the least squares problem given by \\ref{eq:GMRES_lstsq1} is equivalent to the problem\n\\begin{equation}\n\\underset{y \\in \\mathbb{F}^n}{\\text{minimize}}\\qquad \\|H_n y - \\|b\\|_2e_1\\|_2.\n\\label{eq:GMRES_lstsq2}\n\\end{equation}\nIf $y$ is the solution to this problem, then the solution to \\ref{eq:GMRES_lstsq1}, and hence an approximate\nsolution to $Ax = b$ is given by $x=Q_n y$.\n\nWe can measure how good our approximate solution is by considering the residual, which we define to be\n\\[\n\\frac{\\|Ax-b\\|_2}{\\|b\\|_2}.\n\\]\nWe can express this residual in terms of $y$ as follows:\n\\begin{equation}\n\\frac{\\|H_n y - \\|b\\|_2e_1\\|_2}{\\|b\\|_2}.\n\\label{eq:GMRES_residual}\n\\end{equation}\n\\end{comment}\n\n\\section*{The GMRES Algorithm} % ==============================================\n\nGMRES is an iterative method that uses Krylov subspaces to reduce a high-dimensional problem to a sequence of smaller dimensional problems.\nLet $A$ be an invertible $m \\times m$ matrix and let $\\b$ be a vector of length $m$.\nLet $\\mathcal{K}_n(A, \\b)$ be the order-$n$ Krylov subspace generated by $A$ and $\\b$.\nInstead of solving the system $A\\x = \\b$ directly, GMRES uses least squares to find $\\x_n \\in \\mathcal{K}_n$ that minimizes the residual $r_n = \\|\\b - A\\x_n\\|_2$.\nThe algorithm terminates when this residual is smaller than some predetermined value.\nIn many situations, this happens when $n$ is much smaller than $m$.\n\nThe GMRES algorithm uses the Arnoldi iteration for numerical stability.\nThe Arnoldi iteration produces $H_n$, an $(n+1)\\times n$ upper Hessenberg matrix, and $Q_n$, a matrix whose columns make up an orthonormal basis of $\\mathcal{K}_n(A, \\b)$, such that $AQ_n = Q_{n+1}H_n$.\nThe GMRES algorithm finds the vector $\\x_n$ which minimizes the norm $\\norm{\\b - A\\x_n}_2$, where $\\x_n = Q_n \\y_n  + \\x_0$ for some $\\y_n \\in \\mathbb{R}^n$.\nSince the columns of $Q_n$ are orthonormal, the residual can be equivalently computed as\n\\begin{equation}\n\\qquad \\|\\b - A\\x_n\\|_2 = \\|Q_{n+1}(\\beta \\e_1 - H_n \\y_n)\\|_2 = \\|H_n \\y_n - \\beta \\e_1\\|_2.\n\\label{eq:GMRES_lstsq1}\n\\end{equation}\n\nHere $\\e_1$ is the vector $[1, 0, \\ldots, 0]\\trp$ of length $n+1$ and $\\beta=\\norm{\\b - A\\x_0}_2$, where $\\x_0$ is an initial guess of the solution.\n% (Ordinarily this guess is zero; however, a modified version of the algorithm will be discussed in a later section, in which nonzero guesses will be used.)\nThus, to minimize $\\norm{\\b - A\\x_n}_2$, the right side of (\\ref{eq:GMRES_lstsq1}) can be minimized, and $\\x_n $ can be computed as $\\x_n=Q_n \\y_n + \\x_0$.\n\n\\begin{comment}\nso that instead of solving \\eqref{eq:GMRES_lstsq1}, at the $n$th iteration we solve\n\\begin{equation}\n\\underset{\\y \\in \\mathbb{F}^n}{\\text{minimize}}\\qquad \\|H_n \\y - \\|\\b\\|_2\\e_1\\|_2.\n\\label{eq:GMRES_lstsq2}\n\\end{equation}\nHere, $H_n$ is the $(n+1)\\times n$ upper Hessenberg matrix generated by the Arnoldi iteration and $\\e_1$ is the vector $(1, 0, \\ldots, 0)$ of length $n+1$.\nIf $\\y$ is the minimizer for the $n$th iteration of \\eqref{eq:GMRES_lstsq2}, then the residual is\n\\begin{equation}\n\\frac{\\|H_n \\y - \\|\\b\\|_2\\e_1\\|_2}{\\|\\b\\|_2},\n\\label{eq:GMRES_residual}\n\\end{equation}\nand the corresponding minimizer for (\\ref{eq:GMRES_lstsq1}) is $Q_n\\y$, where $Q_n$ is the matrix whose columns are $\\q_1, \\ldots, \\q_n$ as defined by the Arnoldi iteration.\nThis algorithm is outlined in Algorithm \\ref{alg:gmres}.\nFor a complete derivation see [TODO: ref textbook].\n\\end{comment}\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{GMRES}{$A$, $\\b$, $\\x_0$, $k$, \\li{tol}}\n\t\\State $Q \\gets \\allocate{\\size{\\b}}{k+1}$\t\t\t\\Comment{Initialization.}\n\t\\State $H \\gets \\zeros{k+1}{ k}$\n\t\\State $r_0 \\gets \\b - A(\\x_0)$\n\t\\State $Q_{:,0} = r_0/\\norm{r_0}_2$\n    \\For{$j=0\\ldots k-1$}\t\t\t\t\t\t\t\\Comment{Perform the Arnoldi iteration.}\n        \\State $Q_{:,j+1} \\gets A(Q_{:,j})$\n        \\For{$i=0\\ldots j$}\n            \\State $H_{i,j} \\gets Q_{:,i}\\trp Q_{:,j+1}$\n            \\State $Q_{:,j+1} \\gets Q_{:,j+1} - H_{i,j} Q_{:,i}$\n        \\EndFor\n        \\State $H_{j+1,j} \\gets \\norm{Q_{:,j+1}}_2$\n        \\If{$|H_{j+1,j}|>$ \\li{tol}}                           \\Comment{Avoid dividing by zero.}\n            \\State $Q_{:,j+1} \\gets Q_{:,j+1}/H_{j+1,j}$\n        \\EndIf\n        \\State $\\y \\gets$ least squares solution to $\\norm{H_{:j+2,:j+1}\\x - \\beta e_1}_2$     \\Comment{$\\beta$ and $\\e_1$ as in (\\ref{eq:GMRES_lstsq1}).}\n        \\State \\li{res} $\\gets \\norm{H_{:j+2,:j+1}\\y - \\beta e_1}_2$\n        \\If{\\li{res} $<$ \\li{tol}}\n            \\State \\pseudoli{return} $Q_{:,:j+1}\\y + \\x_0$, \\li{res}\n        \\EndIf\n    \\EndFor\n    \\State \\pseudoli{return} $Q_{:,:j+1}\\y + \\x_0$, \\li{res}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The GMRES algorithm. This algorithm operates on a vector $\\b$ and a linear operator $A$.\nIt iterates $k$ times or until the residual is less than \\li{tol}, returning an approximate solution to $A\\x=\\b$ and the error in this approximation.}\n\\label{alg:gmres}\n\\end{algorithm}\n\n%\\begin{warn}\n%The Python function \\li{linalg.lstsq} solves a least squares problem, returning not only the vector, $y$, but also the residual,\n%the rank of the matrix, and the singular values.\n%Be careful when you write your code that you access the correct results and don't just assume that \\li{linalg.lstsq} returns the\n%vector that you want.\n%The least squares solver also returns a residual, but it's not the number we reference in this book, so be sure to take the square\n%root of the residual reported by the solver and divide by $\\norm{b}$ to get $res=\\norm{Ax-b}/\\norm{b}$.\n%\\end{warn}\n% Hint: explain how to find lstsq to find the residual?\n\n\\begin{problem}\nWrite a function that accepts a matrix $A$, a vector $\\b$, and an initial guess $\\x_0$, a maximum number of iterations $k$ defaulting to $100$, and a stopping tolerance \\li{tol} that defaults to $10^{-8}$.\nUse Algorithm \\ref{alg:gmres} to approximate the solution to $A\\x=\\b$ using the GMRES algorithm.\nReturn the approximate solution and the residual at the approximate solution.\n\nYou may assume that $A$ and $\\b$ only have real entries.\nUse \\li{scipy.linalg.lstsq()} to solve the least squares problem.\nBe sure to read the documentation so that you understand what the function returns.\n\nCompare your function to the following code.\n\\begin{lstlisting}\n>>> A = np.array([[1,0,0],[0,2,0],[0,0,3]])\n>>> b = np.array([1, 4, 6])\n>>> x0 = np.zeros(b.size)\n>>> gmres(A, b, x0, k=100, tol=1e-8)\n(array([ 1.,  2.,  2.]), 7.174555448775421e-16)\n\\end{lstlisting}\n\\label{prob:MyGMRES}\n\\end{problem}\n\n\\begin{comment}\n\\subsection*{Breakdowns in GMRES} % -------------------------------------------\n\nOne of the most important characteristics of GMRES is that it does not terminate unless it reaches an exact solution.\nThat is, suppose that $\\q_1, \\ldots, \\q_n$ has already been computed, where\n\\[\\mathcal{K}_n(A, \\b) = \\text{span}\\{\\b, A\\b, \\ldots, A^{n-1}\\b\\} = \\text{span}\\{\\q_1, \\ldots, \\q_n\\}.\\]\nThe next step is to compute $A^n\\b$ and orthogonalize it against $\\mathcal{K}_n(A, \\b)$, yielding $\\q_{n+1}$.\nBut if $A^n\\b \\in \\mathcal{K}_n(A,\\b)$ then $\\q_{n+1}=0$, and the algorithm will break when $\\q_{n+1}$ is normalized.\nIn this situation, $\\b$ is in the $\\text{span}\\{\\q_1, \\ldots, \\q_n\\}$ so the least squares solution to \\eqref{eq:GMRES_lstsq1} is an \\emph{exact} solution to $A\\x=\\b$.\nThis is why Algorithm 1.1 returns $\\x_n$ from the current iteration and residual if $\\norm{\\q_{n+1}}_2$ is less than the given tolerance.\n\\end{comment}\n\n\\subsection*{Convergence of GMRES} % ------------------------------------------\n\nOne of the most important characteristics of GMRES is that it will always arrive at an exact solution (if one exists).\nAt the $n$-th iteration, GMRES computes the best approximate solution to $A\\x = \\b$ for $\\x_n \\in \\mathcal{K}_n$.\nIf $A$ is full rank, then $\\mathcal{K}_m = \\mathbb{F}^m$, so the $m$th iteration will always return an exact answer.\nSometimes, the exact solution $\\x \\in \\mathcal{K}_n$ for some $n<m$, in this case  $x_n$ is an exact solution.\nIn either case, the algorithm is convergent after $n$ steps if the $n$th residual is sufficiently small.\n\nThe rate of convergence of GMRES depends on the eigenvalues of $A$.\n\n\\begin{problem}\n\\label{prob:plot_gmres}\nAdd a keyword argument \\li{plot} defaulting to \\li{False} to your function from Problem \\ref{prob:MyGMRES}.\nIf \\li{plot=True}, keep track of the residuals at each step of the algorithm.\nAt the end of the iteration, before returning the approximate solution and its residual error, create a figure with two subplots.\n\\begin{enumerate}\n\\item Make a scatter plot of the eigenvalues of $A$ on the complex plane.\n\\item Plot the residuals versus the iteration counts using a log scale on the $y$-axis\\\\(use \\li{ax.semilogy()}).\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:make_plots}\nUse your function from Problem \\ref{prob:plot_gmres} to investigate how the convergence of GMRES relates to the eigenvalues of a matrix as follows.\nDefine an $m\\times m$ matrix\n\\[A_n = nI+P,\\]\n where $I$ is the identity matrix and $P$ is an $m \\times m$ matrix with entries taken from a random normal distribution with mean 0 and standard deviation $1/(2\\sqrt{m})$.\n Call your function from Problem \\ref{prob:plot_gmres} on $A_n$ for $n=-4,-2,0,2,4$.\n Use $m=200$, let $\\b$ be an array of all ones, and let $\\x_0 = \\0$.\n\nUse \\li{np.random.normal()} to create the matrix $P$.\nWhen analyzing your results, pay special attention to the clustering of the eigenvalues in relation to the origin.\nCompare your results with $n=2$, $m=200$ to Figure \\ref{fig:plot_gmres}.\n\nIdeas for this problem were taken from Example 35.1 on p. 271 of \\cite{Trefethen1997}.\n\n\\begin{figure}[H] % Convergence of GMRES.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/scatter_gmres.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/gmres_convergence.pdf}\n\\end{subfigure}\n\\caption{On the left, the eigenvalues of the matrix $A_2$ defined in Problem \\ref{prob:make_plots}.\nOn the right, the rapid convergence of the GMRES algorithm on $A_2$ with starting vector $\\b = (1, 1, \\ldots, 1)$.}\n\\label{fig:plot_gmres}\n\\end{figure}\n\\end{problem}\n\n% This section is poorly written. It is vague, not mathematically precise.\n% If we ever want to include it, then it needs a lot of work.\n\\begin{comment}\n\\subsection*{Optimizing Least-Squares for GMRES (Optional)} % -----------------\n\nThe Hessenberg structure and the Krylov subspace relations enable us to save time on the least-squares part of the problem if we use QR factorization.\nObserve that if $H_n$ can be factored as $Q_n R_n$, where $Q_n$ is not the same matrix as above and $R_n$ is invertible upper triangular, we may solve the least squares problem by simply solving $R_n x_n=\\norm{b} Q_{n}^{H}e_1$ via back substitution.\nThere are two ways in which we can speed up this process.\nFirst, we take advantage of the Hessenberg structure by using the techniques from Problem \\ref{prob:givens_hessenberg} in Lab \\ref{lab:givens}.\nRecall that the technique in this situation was to use Givens rotations to eliminate the subdiagonal elements one at a time.\nThis process, which was part of a previous lab, reduces the operation count from $O(n^3)$ to $O(n^2)$.\nThe second speedup comes from the fact that we already know the QR factorization for $H_{n-1}$ from the previous step of the algorithm.\nThis means that we can simply update the QR factorization from the previous step rather than computing it all over again.\nSince $H_{n}$ has only one more column and row than $H_{n-1},$ all we need to do is update the last column by performing all previous Givens rotations on just the last column of $H_n$, which requires only $O(n)$ work.\nThen we perform one final Givens rotation on $H_n$ to eliminate the new subdiagonal entry which was not present in $H_{n-1}$.\nThus, the QR factorization of $H_n$ can be reduced from an $O(n^3)$ process to only $O(n)$ using these special techniques.\n\nThe back substitution necessary to solve the least squares problem can also be reduced to an operation of $O(n)$.\n\nThe speedup from $O(n^3)$ to $O(n)$ is very good, but it can only partially alleviate the problems that come with a problem that is ill-suited for GMRES.\nIt may still be useful because it allows us to perform more iterations in a reasonable amount of time.\nIn many situations, the simple technique of the next section will keep $n$ low enough that the optimizations from this section are not critical.\n\n \\begin{problem}\n \\label{prob:GMRES2}\n (Optional) Modify MyGMRES to incorporate these optimizations, and call this program MyGMRES1.\n Run both programs on a series of five random $100\\times 100$ matrices and compare the time each requires.\n Are the gains substantial?\n Try it again matrices of size $1000\\times 1000$ or larger, and see how substantial the difference becomes.\n Try the same thing using the techniques of the next section.\n Explain why the difference in performance is less dramatic this time.\n \\end{problem}\n\\end{comment}\n\n\\section*{GMRES with Restarts} % -------------------------------------------\n\nThe first few iterations of GMRES have low spatial and temporal complexity.\nHowever, as $k$ increases, the $k$th iteration of GMRES becomes more expensive temporally and spatially.\nIn fact, computing the $k$th iteration of GMRES for very large $k$ can be prohibitively complex.\n\nThis issue is addressed by using GMRES(k), or GMRES with restarts.\nWhen $k$ becomes large, this algorithm restarts GMRES with an improved initial guess.\nThe new initial guess is taken to be the vector that was found upon termination of the last GMRES iteration run.\n\\begin{comment}\nGMRES with restarts is outlined in Algorithm \\ref{alg:gmres_k}.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{GMRES(k)}{$A, \\b, \\x_0, k, tol, restarts$}\n  \\State $n \\gets 0$ \\Comment{Initialize}\n   \\While{$n \\leq restarts$}\n\t\\State{ Perform the GMRES algorithm, obtaining a least squares solution $\\y$}.\n\t\\State{ If the desired tolerance was reached, return. Otherwise, continue.}\n    \\State $\\x_0 \\gets \\y$\n    \\State $n \\gets n + 1$\n    \\EndWhile\n    \\State \\pseudoli{return} $\\y, \\,\\, res$\t\t\\Comment{Return the approximate solution and the residual}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The GMRES(k) algorithm. This algorithm performs GMRES on a vector $\\b$ and matrix $A$. It iterates $k$ times before restarting.\nIt terminates after $restarts$ restarts or when the residual is less than $tol$, returning an approximate solution to $A\\x=\\b$ and the error of this approximation. }\n\\label{alg:gmres_k}\n\\end{algorithm}\n\\end{comment}\nThe algorithm GMRES(k) will always have manageable spatial and temporal complexity, but it is less reliable than GMRES.\nIf the true solution $\\x$ to $A\\x=\\b$ is nearly orthogonal to the Krylov subspaces $\\mathcal{K}_n(A, \\b)$ for $n\\leq k$, then GMRES(k) could converge very slowly or not at all.\n\n\\begin{problem}\nWrite a function that implements GMRES with restarts as follows.\n\\begin{enumerate}\n\\item Perform the GMRES algorithm for a maximum of k iterations.\n\\item If the desired tolerance was reached, terminate the algorithm.\nIf not, repeat step 1 using $x_k$ from the previous GMRES algorithm as a new initial guess $x_0$.\n\\item Repeat step 2 until the desired tolerance has been obtained or until a given maximum number of restarts has been reached.\n\\end{enumerate}\nYour function should accept all of the same inputs as the function you wrote in Problem 1 with the exception of $k$, which will now denote the number of iterations before restart (defaults to $5$), and an additional parameter \\li{restarts} which denotes the maximum number of restarts before termination (defaults to $50$).\n\\label{prob:GMRESk}\n\\end{problem}\n\n\\section*{GMRES in SciPy} % ===================================================\n\nThe GMRES algorithm is implemented in SciPy as the function \\li{scipy.sparse.linalg.gmres()}.\nHere we use this function to solve $A\\x=\\b$ where $A$ is a random $300 \\times 300$ matrix and $\\b$ is a random vector.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import sparse\n>>> from scipy.sparse import linalg as spla\n\n>>> A = np.random.rand(300, 300)\n>>> b = np.random(300)\n>>> x, info = spla.gmres(A, b)\n>>> print(info)\n3000\n\\end{lstlisting}\n\nThe function outputs two objects: the approximate solution $\\x$ and an integer \\li{info} which gives information about the convergence of the algorithm.\nIf \\li{info=0} then convergence occured; if \\li{info} is positive then it equals the number of iterations performed.\nIn the previous case, the function performed 3000 iterations of GMRES before returning the approximate solution $\\x$.\nThe following code verifies how close the computed value was to the exact solution.\n\\begin{lstlisting}\n>>> la.norm((A @ x) - b)\n4.744196381683801\n\\end{lstlisting}\n\nA better approximation can be obtained using GMRES with restarts.\n\\newpage\n\\begin{lstlisting}\n# Restart after 1000 iterations.\n>>> x, info = spla.gmres(A, b, restart=1000)\n>>> info\n0\n>>> la.norm((A @ x) - b)\n1.0280404494143551e-12\n\\end{lstlisting}\nThis time, the returned approximation $\\x$ is about as close to a true solution as can be expected.\n\n\\begin{problem}\nPlot the runtimes of your implementations of GMRES from Problems 1 and 4 and \\li{scipy.sparse.linalg.gmres()} use the default tolerance and \\li{restart=1000} with different matrices.\nUse the $m \\times m$ matrix $P$ with $m=25,50,\\dots 200$ and with entries taken from a random normal distribution with mean 0 and standard deviation $1/(2\\sqrt{m})$.\nUse a vector of ones for $\\b$ and a vector of zeros for $\\x_0$.\nUse a single figure for all plots, plot the runtime on the $y$-axis and $m$ on the $x$-axis.\n\\end{problem}\n\n\\begin{comment}\n% This problem is a potential application problem that could be included in the lab.\n% The solutions to this problem are included in solutions.py.\n\\begin{problem}\nUsing the function \\li{finite_difference()} from your iterative solvers lab, modify the \\li{hot_plate()} function to use the GMRES algorithm instead of the SOR method.\nDo you see any differences in speed?\nCan you solve larger systems with GMRES?\nTry the different versions of the GMRES algorithm that we have discussed, what differences do you see?\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "cd464550380e10ca36cd13f406465491a0883d3b", "size": 22716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/GMRES/GMRES.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/GMRES/GMRES.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/GMRES/GMRES.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 55.1359223301, "max_line_length": 323, "alphanum_fraction": 0.7119211129, "num_tokens": 6885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.800691997339971, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.68832588111833}}
{"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 XVII Notes}\n\\date{July 13, 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{Mass and Density $-$ 15.4}\n\nThe mass may be expressed as \n$$m=\\iint_D \\rho(x,y)\\,dA$$\n\nTotal charge is expressed as:\n$$Q=\\iint_D \\sigma(x,y)\\,dA$$\n\nThe (first) moments on the $x$ and $y$ axis, respectively, may be found by using:\n\n$$M_x=\\iint_D y\\rho(x,y)\\,dA\\text{ and }M_y=\\iint_D x\\rho(x,y)\\,dA$$\n\nThe center of mass, $(\\overline{x},\\overline{y})$ may be found by rearranging the formula:\n\n$$m\\overline{x}=M_y\\text{ and } m\\overline{y}=M_x$$\n$$\\overline{x}=\\frac{M_y}{m}=\\frac{\\iint_D x\\rho(x,y)\\,dA}{\\iint_D \\rho(x,y)}\\,dA$$\n  $$\\overline{y}=\\frac{M_x}{m}=\\frac{\\iint_D y\\rho(x,y)\\,dA}{\\iint_D \\rho(x,y)}\\,dA$$\n\n  The moment of inertia (or the second moment) is $mr^2$, where $r$ is the distance from a particle to the axis. About the $x$ axis, the moment of inertia is equal to:\n\n  $$I_x = \\iint_D y^2\\rho(x,y)\\,dA$$\n\n  Across the $y$ axis the moment of inertia is equal to:\n\n  $$I_y=\\iint_D x^2\\rho(x,y)\\,dA$$\n\n  In addition to this, the polar moment of inertia (about the origin) is equal to:\n\n  $$I_0\\iint_D (x^2+y^2)\\rho(x,y)\\,dA$$\n\n  This means that $I_0=I_x+I_y$\n\n  \\section{Surface Area $-$ 15.5}\n\n  The surface area, $A(S)$ is defined by:\n\n  $$A(S)=\\lim_{(m,n)\\to\\infty}\\sum_{i=1}^m\\sum_{j=1}^n \\Delta T_ij$$\n\n  $T_ij$ is defined by $|a\\text{ x }b|$, where:\n\n  $$a=\\Delta x\\bold{\\hat{i}} + f_x(x_i,y_i)\\Delta x \\bold{\\hat{k}}$$\n  $$b=\\Delta y\\bold{\\hat{j}} + f_y(x_i,y_j)\\Delta y \\bold{\\hat{k}}$$\n\n  Therefore, as an iterated integral, the surface area may be expressed as:\n\n  $$A(S)=\\iint_D \\sqrt{1+\\left(\\frac{\\partial z}{\\partial x}\\right)^2+\\left(\\frac{\\partial z}{\\partial y}\\right)^2}\\,dA$$\n\n\n\\end{document}\n", "meta": {"hexsha": "cef935ea0f748594c7cd8cdb2e38b480efb7e682", "size": 3068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture17.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/Lecture17.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/Lecture17.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.5, "max_line_length": 188, "alphanum_fraction": 0.583767927, "num_tokens": 1038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.8175744784160989, "lm_q1q2_score": 0.6882551644689958}}
{"text": "\\chapter{Graph}\n\n\\section{Basic}\n\\runinhead{Graph representation.} $V$ for a vertex set with a map, mapping from vertex to its neighbors. The mapping relationship represents the edges $E$.\n\\begin{python}\nV = defaultdict(list)\n\\end{python}\n\n\\runinhead{Complexity.} Basic complexities: \n\n\\begin{tabular}{lll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Algorithm} & \\textbf{Time}  & \\textbf{Space}\\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\ndfs & $O(|E|)$ & $O(|V|), O(\\text{longest path})$ \\\\\nbfs & $O(|E|)$ & $O(|V|)$ \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\\caption{CAPTIONS}\n\\end{tabular}\n\n\\section{DFS}\n\\rih{Number of Islands.} The most fundamental and classical problem. \n\\begin{python}\n11000\n11000\n00100\n00011\nAnswer: 3\n\\end{python}\n\\rih{Clue}:\n\\begin{enumerate}\n\\item Iterative dfs\n\\end{enumerate}\n\\begin{python}\nclass Solution(object):\n  def __init__(self):\n    self.dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n\n  def numIslands(self, grid):\n    cnt = 0\n    visited = [[False for _ in xrange(n)] \n               for _ in xrange(m)]\n    for i in xrange(m):\n      for j in xrange(n):\n        if not visited[i][j] and grid[i][j] == \"1\":\n          self.dfs(grid, i, j, visited)\n          cnt += 1\n\n    return cnt\n\\end{python}\n\\newpage\n\\begin{python}\n  def dfs(self, grid, i, j, visited):\n    m = len(grid)\n    n = len(grid[0])\n    visited[i][j] = True\n\n    for dir in self.dirs:\n      I = i+dir[0]\n      J = j+dir[1]\n      if (0 <= I < m and 0 <= J < n and \n        not visited[I][J] and grid[I][J] == \"1\"):\n        self.dfs(grid, I, J, visited)\n\\end{python}\nIf the islands are constantly updating and the query for number of islands is called multiple times, need to use union-find (Section \\ref{section:unionFind}) to reduce each query's complexity from $O(mn)$ to $O(\\log mn)$.\n\n\\section{BFS}\n\\subsection{BFS with Abstract Level}\nStart bfs with a set of vertices in abstract level, not necessarily neighboring vertices.\n\nExample: $-1$ obstacles, $0$ targets, calculate all other vertices' Manhattan distance to its nearest target:\n$$\n\\begin{bmatrix}\n\\infty & -1 & 0 & \\infty \\\\\n\\infty & \\infty & \\infty & -1 \\\\\n\\infty & -1 & \\infty & -1 \\\\\n0 & -1 & \\infty & \\infty \\\\\n\\end{bmatrix} \n$$\n\nis calculated as:\n$$\n\\begin{bmatrix}\n3 & -1 & 0 & 1 \\\\\n2 & 2 & 1 & -1 \\\\\n1 & -1 & 2 & -1 \\\\\n0 & -1 & 3 & 4 \\\\\n\\end{bmatrix}\n$$\n\\newpage\n\\rih{Code:}\n\\begin{python}\nself.dirs = ((-1, 0), (1, 0), (0, -1), (0, 1))\n\ndef wallsAndGates(self, mat):\n  q = [(i, j) for i, row in enumerate(mat) \n     for j, val in enumerate(row) if val == 0]\n  for i, j in q:  # iterator\n    for d in self.dirs:\n      I, J = i+d[0], j+d[1]\n      if (0 <= I < m and  0 <= J < n and \n        mat[I][J] > mat[i][j]+1):\n        mat[I][J] = mat[i][j]+1\n        q.append((I, J))\n\\end{python}\n\n\n\\section{Detect Acyclic}\n\\begin{enumerate}\n\\item \\pythoninline{marked} is reset after a dfs. \n\\item \\pythoninline{visited} should be updated only in the end of the dfs. \n\\item For directed graph:\n\\begin{enumerate}\n\\item Should dfs for all neighbors except for vertices in \\pythoninline{visited}, to avoid revisiting. For example, avoid revisiting A, B when start from C in the graph $C \\rightarrow A \\rightarrow B$.\n\\item Excluding predecessor \\pythoninline{pi} is erroneous in the case of $A \\leftrightarrow B$ \n\\end{enumerate}\n\\item For undirected graph:\n\\begin{enumerate}\n\\item Should dfs for all neighbors except for the predecessor \\pythoninline{pi}. $A-B$.\n\\item Excluding neighbors in \\pythoninline{visited} is redundant, due to \\pyinline{pi}. \n\\end{enumerate}\n\\end{enumerate}\n\n\\subsection{Directed Graph}\nDetect cycles (any) in directed graph.\n\n\\begin{python}\ndef dfs(self, V, v, visited, pathset):\n  if v in pathset:\n    return False\n\n  pathset.add(v)\n  for nbr in V[v]:\n    if nbr not in visited:\n      if not self.dfs(V, nbr, visited, pathset):\n        return False\n\n  pathset.remove(v)\n  visited.add(v)\n  return True\n\\end{python}\n\n\n\\subsection{Undirected Graph}\nDetect cycles (any) in undirected graph.\n\n\\begin{python}\ndef dfs(self, V, v, pi, visited, pathset):\n  if v in pathset:\n    return False\n\n  pathset.add(v)\n  for nbr in V[v]:\n    if nbr != pi:\n      if not self.dfs(V, nbr, v, visited, pathset):\n        return False\n\n  pathset.remove(v)\n  visited.add(v)\n  return True\n\\end{python}\n\n\\section{Topological Sorting}\nFor a graph $G=\\{V, E\\}$, if $A \\rightarrow B $, then $A$ is before $B$ in the ordered list. \n\\subsection{Algorithm}\n\\rih{Core clues}:\n\\begin{enumerate}\n\\item \\textbf{Dfs neighbors first}. If the neighbors of current node is  $\\neg$visited, then dfs the neighbors\n\\item \\textbf{Process current node}. After visiting all the neighbors, then visit the current node and push it to the result queue.\n\n\\end{enumerate}\nNotice:\n\\begin{enumerate}\n\\item Need to check ascending order or descending order. \n\\item Need to \\textbf{detect cycle}; thus the dfs need to construct result queue and detect cycle simultaneously, by using two sets: $visited$ and $pathset$. \n\\end{enumerate}\n\\newpage\n\\begin{python}\nfrom collections import deque\n\ndef topological_sort(self, V):\n  visited = set()\n  ret = deque()\n\n  for v in V.keys():\n    if v not in visited:\n      if not self.dfs_topo(V, v, visited, set(), ret):\n        return []  # contains cycle \n\n  return list(ret)\n\ndef dfs_topo(self, V, v, visited, pathset, ret):\n  if v in pathset:\n    return False\n\n  pathset.add(v)\n  for nbr in V[v]:\n    if nbr not in visited:\n      if not self.dfs_topo(V, nbr, visited, pathset, ret):\n        return False\n\n  pathset.remove(v)\n  visited.add(v)\n  ret.appendleft(v)\n  return True\n\n\\end{python}\n\n\\subsection{Applications}\n\\begin{enumerate}\n\\item Course scheduling problem with pre-requisite. \n\\end{enumerate}\n\n\\section{Union-Find}\\label{section:unionFind}\nImprovements:\n\\begin{enumerate}\n\\item Weighting: size-baladnced tree\n\\item Path Compression. \n\\end{enumerate}}\n\\subsection{Algorithm}\nWeighted union-find with path compression.\\\\\n\\rih{Core clues.} \n\\begin{enumerate}\n\\item \\textbf{$\\pi$ array}:an array to store each item's predecessor pi. The predecessor are lazily updated to its ancestor. When \\pyinline{x == pi[x]}, then \\pyinline{x} is the ancestor (i.e. root).\n\\item \\textbf{Size-balanced}: merge the tree according to the size to maintain balance.\n\\item \\textbf{Path compression}: Make the ptr in $\\pi$ array to point to its root rather than its immediate parent. \n\\end{enumerate}\n\\begin{figure}[]\n\\centering\n\\subfloat{\\includegraphics[scale=.70]{uf}}\n\\caption{Weighted quick-union traces}\n\\label{fig:union_find}\n\\end{figure}\n\n\\newpage\n\\begin{python}\nclass UnionFind(object):\n  def __init__(self):\n    self.pi = {}  # item -> pi\n    self.sz = {}  # root -> size\n\n  def __len__(self):\n    \"\"\"number of unions\"\"\"\n    return len(self.sz)  # only root nodes have size\n\n  def add(self, x):\n    if x not in self.pi:\n      self.pi[x] = x\n      self.sz[x] = 1\n\n  def root(self, x):\n    \"\"\"path compression\"\"\"\n    pi = self.pi[x]\n    if x != pi:\n      self.pi[x] = self.root(pi)\n    return self.pi[x]\n\n  def unionize(self, x, y):\n    pi1 = self.root(x)\n    pi2 = self.root(y)\n\n    if pi1 != pi2:\n      if self.sz[pi1] > self.sz[pi2]:\n        pi1, pi2 = pi2, pi1\n        # size balancing\n      self.pi[pi1] = pi2\n      self.sz[pi2] += self.sz[pi1]\n      del self.sz[pi1]\n    \n  def isunion(self, x, y):\n    if x not in self.pi or y not in self.pi:\n      return False \n    return self.root(x) == self.root(y)\n\\end{python}\n\n\\subsection{Complexity}\n$m$ union-find with $n$ objects: $O(n)+m O(\\lg n)$\n\n\n\\section{Axis Projection}\nProject the mat dimension from 2D to 1D, using \\textit{orthogonal axis}.\n\n\\runinhead{Smallest bounding box.} Given the location $(x, y)$ of one of the 1's, return the area of the smallest bounding box that encloses 1's.\n$$\n\\begin{bmatrix}\n0& 0& 1& 0 \\\\\n0& 1& 1& 0 \\\\ \n0& 1& 0& 0 \\\\\n\\end{bmatrix}\n$$\n\nClues:\n\\begin{enumerate}\n\\item Project the 1's onto x-axis, binary search for the left bound and right bound of the bounding box. \n\\item Do the same for y-axis. \n\\end{enumerate}\n\nTime complexity: $O(m\\log n + n \\log m)$, where $O(m), O(n)$ is for projection complexity. \n", "meta": {"hexsha": "ce4a870891b7b870f35f29626180700e953ad3bf", "size": 8063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterGraph.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": "chapterGraph.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": "chapterGraph.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": 26.9665551839, "max_line_length": 221, "alphanum_fraction": 0.6574476001, "num_tokens": 2508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744717487329, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.6882551637228501}}
{"text": "\\chapter{Approximation}\n\n\\section{Error}\n\n\\index{approximation error}\n\\index{error!of approximation}\nIf the data set is \\(D = \\{(x_1,y_1),\\ldots,(x_n,y_n)\\}\\) and the approximator is \\(f\\),\nthen the \\emph{approximation error} is \\(e = \\sum_{k=1}^n f(x_k) - y_k\\).\n\n\\section{Metric space}\n\nBefore we can approximate, we must have a metric space.\nYou must define the concept of distance.\nYou must have a target, an error function, and a desired accuracy.\n\nAfter that, we are interested in\nwhat we are approximating, how fast we converge, how accurate we are.\n\nAt a higher level, we can think of approximation about\ntransformation between metric spaces.\n\nIn a narrow sense, we can compute the approximate decimal representation of a real number.\nThe truncated decimal representation is the approximation of the real number.\nWe know the real number with certainty.\nThere is only one such real number.\nWe can define it.\nWe just haven't computed its decimal representation.\n\nIn a narrow sense, to approximate a real number is\nto construct a sequence that converges to that real number.\n\n\\section{The meat}\n\nDefine a metric \\(d\\) as a function satisfying these, for all \\(x\\) and \\(y\\):\n\\begin{align*}\n    d~x~y &\\ge 0\n    \\\\\n    d~x~y &= d~y~x\n    \\\\\n    d~x~y = 0 &\\iff x=y\n\\end{align*}\n\nGiven \\(d\\) and \\(<\\), we can verify whether a sequence approximates a value.\nHowever, those are not enough to construct an approximation scheme.\n\n\\(\\sqrt{2}\\) is the positive \\(x\\) that satisfies \\(x^2 = 2\\).\nWe can rearrange \\(x = 2/x\\). If we let \\(f~x = 2/x\\), then \\(\\sqrt{2}\\) is the fixed point of \\(f\\)?\n\n\\begin{align*}\n    f~x &= x\n    \\\\\n    f~x &= 2/x\n    \\\\\n    f~y &= 2/y\n    \\\\\n    f~y - f~x &= 2/y - 2/x = 2/y - x\n    \\\\\n    \\frac{f~y - f~x}{y - x} &= \\frac{2(x-y)}{xy(y-x)} = - \\frac{2}{xy} = m\n    \\\\\n    f~y &\\approx f~x + m \\cdot (y - x)\n    \\\\\n    f~x &\\approx f~y - m \\cdot (y - x)\n    \\\\\n    x &\\approx f~y - m \\cdot (y - x)\n\\end{align*}\n\nGiven a fixed point equation, can we construct an approximation scheme?\n\nNewton-Raphson method: given a monotonous function with nonzero derivative, we can approximate.\n\n\\section{Motivating example for the guide and update functions}\n\nComputing \\(\\sqrt{x}\\) is harder than computing \\(x^2\\).\nWe can combine iteration and squaring to compute square root.\n\nWhat is \\(\\sqrt{2}\\)? It is the positive \\(x\\) that satisfies the equation \\(x^2 - 2 = 0\\).\n\nWe know that \\(x\\) is between 1 and 2.\nWe can use binary search.\n\nWe have an initial approximation that \\(x \\in [a,b]\\) and we want to close in:\nwe want to show that \\(x \\in [a',b']\\) where \\([a',b'] \\subset [a,b]\\).\nLet \\(c = (a+b)/2\\). If \\(g~c > 0\\), the midpoint is above than the target,\nso we update \\(a' = a\\) and \\(b' = c\\).\nIf \\(g~c < 0\\), the midpoint is below the target,\nso we update \\(a' = c\\) and \\(b' = b\\).\n\nLook at this example approximation scheme to compute \\(\\sqrt{2}\\).\n\\begin{align*}\n    f~x = \\begin{cases}\n        x / 2 &: x^2 - 2 > 0\n        \\\\\n        x &: x^2 - 2 = 0\n        \\\\\n        x + 1 &: x^2 - 2 < 0\n    \\end{cases}\n\\end{align*}\n\nGiven \\fun{raise}, \\fun{lower}, \\fun{guide}, we can construct this approximation scheme:\n\\begin{align*}\n    f~x = \\begin{cases}\n        \\fun{lower}~x &: \\fun{guide}~x > 0\n        \\\\ x &: \\fun{guide}~x = 0\n        \\\\ \\fun{raise}~x &: \\fun{guide}~x < 0\n    \\end{cases}\n\\end{align*}\n\nThe key fact is that \\(g~x\\) does not have to compute the exact error.\nIt only has to compute an error that is monotonous to the actual error.\nFor example, instead of using the error function \\(e~x = x - \\sqrt{2}\\),\nwe can define the guide function \\(g~x = x^2 - 2\\).\n\n\\section{Guide function}\n\nThe guide function is easier to compute than the error function.\n\nThe guide function is related to the error function:\n\\begin{align*}\n    e~x = 0 &\\iff g~x = 0\n    \\\\\n    e~x < e~y &\\iff g~x < g~y\n\\end{align*}\n\n\\section{Guided approximation scheme}\n\nGiven an update function \\(u\\) and a guide function \\(g\\),\nwe get a free iterative approximation scheme \\(f\\):\n\\begin{align*}\n    f~x = u~x~(g~x)\n\\end{align*}\n\nSimple update function:\n\\[\n    u~x~v = x - v/2\n\\]\n\n\\section{Testing whether a function is an approximation scheme}\n\nIff \\(e\\) is a monotonous function\nand \\(|e~(f~x)| < |e~x|\\) for all \\(x\\),\nthen \\(f^\\infty~x\\) converges.\n\n\\section{The update function must satisfy these properties.}\n\nConstraint: If the guide is zero, then the approximation is exact\nand it must keep the approximation.\n\\[\n    u~x~0 = x\n\\]\n\nConstraint: For smaller error, the update function must jump smaller.\n\\[\n    |a| < |b| \\iff |u~x~a - x| < |u~x~b - x|\n\\]\n\nThe update function must jump against the error.\n\\[\n    (u~x~a - x) \\cdot a < 0\n\\]\n\n\\section{Conclusion}\n\nConsider a circle of radius 1 and a square of side 2.\nThe area of the circle and the circumference of the square:\n\\[\n    \\pi^2 < 2^2\n\\]\n\\[\n    \\pi^3 < 2^3\n\\]\n\\[\n    \\pi^n < 2^n\n\\]\n\n\\[\n    [2 \\cos (\\pi/4)]^2 < \\pi^2\n\\]\n\n\\[\n    x^2 + y^2 = 1\n\\]\n\n\\[\n    \\int_0^1 \\sqrt{1-x^2}~dx = \\pi / 4\n\\]\n\nvia Riemann sum:\n\n\\[\n    \\pi/4 = \\lim_{n\\to\\infty} \\sum_{k=0}^{n-1} \\frac{1}{n} \\sqrt{1 - (k/n)^2}\n\\]\n\nLet\n\\[\n    f~n = \\sum_{k=0}^{n-1} \\frac{1}{n} \\sqrt{1 - (k/n)^2}\n\\]\nState \\(f~(2 \\cdot n)\\) in terms of \\(f~n\\).\n\n\\[\n    f~(2 \\cdot n) = \\frac{1}{2} \\cdot f~n\n\\]\n\n\\[\n    f~(2 \\cdot n) = \\sum_{k=0}^{2 \\cdot n - 1} \\frac{1}{2 \\cdot n} \\sqrt{1 - (k/(2 \\cdot n))^2}\n\\]\n\n\\[\n    f~(2 \\cdot n) = \\sum_{k=0}^{2 \\cdot n - 1} \\frac{1}{2 \\cdot n} \\sqrt{1 - ((k/2)/n)^2}\n\\]\n\n\\[\n    f~(2 \\cdot n) =\n    \\sum_{k=0,2,\\ldots}^{2 \\cdot n - 2} \\frac{1}{2 \\cdot n} \\sqrt{1 - ((k/2)/n)^2}\n    + \\sum_{k=1,3,\\ldots}^{2 \\cdot n - 1} \\frac{1}{2 \\cdot n} \\sqrt{1 - ((k/2)/n)^2}\n\\]\n\n\\[\n    f~(2 \\cdot n) =\n    \\sum_{2 \\cdot j=0,2,\\ldots}^{2 \\cdot n - 2} \\frac{1}{2 \\cdot n} \\sqrt{1 - (((2 \\cdot j)/2)/n)^2}\n    + \\sum_{2 \\cdot j + 1=1,3,\\ldots}^{2 \\cdot n - 1} \\frac{1}{2 \\cdot n} \\sqrt{1 - (((2 \\cdot j + 1)/2)/n)^2}\n\\]\n\\[\n    f~(2 \\cdot n) =\n    \\sum_{j=0}^{n - 1} \\frac{1}{2 \\cdot n} \\sqrt{1 - (j/n)^2}\n    + \\sum_{2 \\cdot j=0,2,\\ldots}^{2 \\cdot n - 2} \\frac{1}{2 \\cdot n} \\sqrt{1 - (((2 \\cdot j + 1)/2)/n)^2}\n\\]\n\\[\n    f~(2 \\cdot n) =\n    \\sum_{j=0}^{n - 1} \\frac{1}{2 \\cdot n} \\sqrt{1 - (j/n)^2}\n    + \\sum_{j=0}^{n-1} \\frac{1}{2 \\cdot n} \\sqrt{1 - ((j+1/2)/n)^2}\n\\]\n\\[\n    f~(2 \\cdot n) =\n    \\frac{1}{2} \\sum_{j=0}^{n - 1} \\frac{1}{n} \\sqrt{1 - (j/n)^2}\n    + \\sum_{j=0}^{n-1} \\frac{1}{2 \\cdot n} \\sqrt{1 - (j/n + 1/(2n))^2}\n\\]\n\\[\n    f~(2 \\cdot n) =\n    \\frac{1}{2} \\cdot f~n\n    + \\frac{1}{2} \\sum_{j=0}^{n-1} \\frac{1}{n} \\sqrt{1 - ((j+1/2)/n)^2}\n\\]\n\n\\[\n    f~d~(2 \\cdot n) = \\frac{f~d~n + f~(d + 1/(2\\cdot n))~n}{2}\n\\]\n\n\\[\n    f~d~n = \\frac{1}{n} \\cdot \\sum_{k=0}^{n-1} \\sqrt{1 - (k/n + d)^2}\n\\]\n\nThe identity:\n\\[\n    f~d~n = \\frac{f~d~(n/2) + f~(d + 1/n)~(n/2)}{2}\n\\]\n\n\\[\n    f~0~2 = \\frac{f~0~1 + f~(1/2)~1}{2}\n\\]\n\n\\[\n    f~0~4 = \\frac{f~0~2 + f~(1/4)~2}{2}\n\\]\n\n\\[\n    f~0~4 = \\frac{\\frac{f~0~1 + f~(1/2)~1}{2} + \\frac{f~(1/4)~1 + f~(3/4)~1}{2}}{2}\n\\]\n\n\\[\n    f~0~4 = \\frac{f~0~1 + f~(1/4)~1 + f~(2/4)~1 + f~(3/4)~1}{4}\n\\]\n\n\\[\n    f~0~n = \\frac{1}{n} \\cdot \\sum_{k=0}^{n-1} f~(k/n)~1\n\\]\n\nThat holds for all Riemann sums where \\(d\\) is the offset (translation).\n\n\\[\n    f~d~1 = \\sqrt{1 - d^2}\n\\]\n\nLet \\(x~n = f~0~(2^n)\\).\n\nIf you have a guide function and have an interval that contains the target,\nyou can use the interval approximation scheme.\n\nThe equation for the error function is easy to write but hard to compute.\nThe key of approximation is finding a guide function.\nIf the number is the root of a polynomial,\nthen the polynomial equation can be the guide function.\n\n\\section{Incremental Riemann sum}\n\nLet\n\\[\n    s~f~d~n = \\frac{1}{n} \\sum_{k=0}^{n-1} f~(k/n + d)\n\\]\nwhere \\(s~f~0~n\\) is the finite Riemann sum.\n\\[\n    \\int_0^1 f~(x+u) ~ dx = \\lim_{n\\to\\infty} s~f~u~n\n\\]\n\nThen we have the recurrence relation:\n\\[\n    s~f~d~(2 \\cdot n) = \\frac{s~f~d~n + s~f~(d + 1/(2 \\cdot n))~n}{2}\n\\]\nThe recurrence relation can be used to approximate the integral to any accuracy,\nbut it converges slowly.\n\nEquivalently:\n\\[\n    s~f~d~n = \\frac{s~f~d~(n/2) + s~f~(d + 1/n)~(n/2)}{2}\n\\]\n\nwhere\n\\[\n    s~f~d~1 = f~d\n\\]\n\n\\section{Sequence from iteration}\n\nThe sequence generated by iterating \\(f\\) on \\(x\\) is:\n\\[\n    x, ~ f~x, ~ f~(f~x), ~ \\ldots, ~ f^n~x, ~ \\ldots\n\\]\n\nIn the theory of unary algebras, that sequence is also known as\nthe \\emph{orbit} of \\(x\\) in the unary algebra \\((X,f)\\)\nwhere \\(x : X\\).\n\n\\section{Approximating sequence}\n\nFormally we define a sequence \\(x = \\{ x_0, x_1, \\ldots \\}\\) approximates \\(y\\) iff \\(x_\\infty = y\\).\n\n\\section{Approximation is not estimation.}\n\nApproximation converges.\nEstimation doesn't converge because the actual value is unknown.\n\nApproximation doesn't guess.\nEstimation guesses.\n\nApproximation has error.\nEstimation has uncertainty.\n\nMeta approximation? Approximate the approximation scheme?\n\n\\section{Network of radial basis functions}\n\nWe can approximate a high-dimensional sparse function\nby a weighted sum of radial functions.\n(A radial function is a function whose value at a point\ndepends only on the distance of that point from a certain point.)\nSee Bromhead and Lowe 1988, radial basis function neural network?\n% https://en.wikipedia.org/wiki/Radial_basis_function\n\n\\section{Approximating unknown functions}\n\nOf course we can't approximate a function\nif we don't know anything about it at all.\nWe must know something.\n\nGiven a set of sample values,\nwhat is the most likely function?\nGiven a set of sample bit strings,\nwhat is the most likely algorithm?\nIsn't this the idea of algorithmic complexity (Solomonoff)?\n\nWe don't know the closed form expression of the function,\nand we only know a few finitely many values of the function at some points.\nFor example, let the input be a \\(64 \\times 64\\) image\nwhere each pixel is a 8-bit unsigned integer,\nand let the input be a boolean that indicates\nwhether the input is the digit zero.\n\n\\section{There is an abstract converging approximation scheme in a metric space.}\n\nLet there be a type \\(A\\).\nLet there be a total order \\(<\\) on \\(A\\).\nWe want to approximate \\(y : A\\).\nStart with any \\(a : A\\).\nApply approximation scheme \\(f : A \\to A\\).\nAn approximation scheme is an endofunction.\nIf \\(d~(f~x)~y < d~x~y\\) for almost all \\(x\\), then \\(f^\\infty~a\\) converges to \\(y\\).\nTo approximate \\(y\\), apply \\(f\\) repeatedly.\nTo approximate \\(y\\), iterate \\(f\\).\nIf \\( f^\\infty~x = y \\), we say \\(f\\) converges to \\(y\\) from \\(x\\).\n\n\\section{Example with a continued fraction}\n\nFor example, let \\(f~x = 1 + 1/x\\).\nIt follows that\n\\[\n    f^\\infty~x = 1 + \\frac{1}{1 + \\frac{1}{1 + \\ldots}} = \\frac{1 + \\sqrt{5}}{2} = \\Phi\n\\]\nFor every \\(x > 0\\), we have \\(f^\\infty~x = \\Phi\\).\nTherefore that \\(f\\) is an approximation scheme for \\(\\Phi\\).\n\nLet \\(f~x = 2 + 1/x\\).\n\\[\n    2 + \\frac{1}{2 + \\frac{1}{2 + \\ldots}} = 1 + \\sqrt{2}\n\\]\n\n\\section{Some approximation schemes give rise to continued fractions.}\n\nRearranging a continued fraction gives a polynomial equation.\n\nWe can go the other way too.\nWe can always transform a polynomial equation into a continued fraction\nby rearranging the equation so that the unknown variable appears on both sides.\n\nYou rearrange the equation and end up with the same thing you begin with.\n\\[\n    1 + \\frac{1}{1 + \\frac{1}{1 + \\ldots}} = x\n\\]\nSubtract both sides by 1.\n\\[\n    \\frac{1}{1 + \\frac{1}{1 + \\ldots}} = x - 1\n\\]\nInvert both sides.\n\\[\n    1 + \\frac{1}{1 + \\ldots} = \\frac{1}{x - 1}\n\\]\nThe left side is the same as what we started out with.\n\\[\n    x = \\frac{1}{x - 1}\n\\]\nWe have a quadratic equation.\n\\[\n    x^2 - x - 1 = 0\n\\]\n\nLet \\(f~x = 1 + 1/x^2\\).\n\\[\n    1 + \\frac{1}{\\left(1 + \\frac{1}{(1+\\ldots)^2}\\right)^2}\n\\]\n\n\\section{Continued fraction of functions}\n\nLet's use the same equation \\(f~x = 1 + 1/x\\),\nbut now \\(x : \\Real \\to \\Real\\).\nActually \\(f~x~t = 1 + \\frac{1}{x~t}\\).\n\nSome converges to the constant function \\(t \\to \\Phi\\).\n\n\\section{Continued fraction of square matrices}\n\n\\(f~x = I_n + x^{-1}\\).\n\nSome converge. Some oscillate.\n\n\\section{Taylor series of function space}\n\nGiven \\(x : \\Real\\),\nthe Maclaurin series of \\(f\\) is\n\\[\n    \\sum_{k=0}^{\\infty} \\frac{(d^k~f)~0 \\cdot x^k}{k!}\n\\]\n\nNow what if \\(x : \\Real \\to \\Real\\)?\n\n\\section{Derivative in function space}\n\nLet \\(x : \\Real \\to \\Real\\).\nTake the limit as \\(h \\to 0\\).\n\\[\n    h \\cdot d~f~x = f~(x + h) - f~x\n\\]\n\n% https://en.wikipedia.org/wiki/Generalizations_of_the_derivative#Functional_analysis\n\n\\section{Combination of simpler functions}\n\n\\[\n    g~(f_0,f_1,\\ldots) \\sim w_0 \\cdot f_0 + w_1 \\cdot f_1 + \\ldots\n\\]\n\n\\section{Continued fraction involving discrete types}\n\n\\section{Problem statement}\n\nApproximate a function as a combination of simpler functions.\n\nApproximation needs distance.\nApproximating \\(x : A\\) requires that a distance \\(d~x~y\\) be defined.\nThe value of \\(d~x~y\\) is not important.\nThe important is the ordering among those values.\n\nA straightforward approximation scheme \\(f\\) satisfies:\n\\[\n    d~(f~x)~(f~(f~x)) < d~x~(f~x)\n\\]\n\n\\section{Details}\n\nWe have a square integrable function \\(f : \\Real^\\infty \\to I\\)\nwhere \\(I = [0,1]\\) is the unit interval.\nWe don't know the equation for \\(f\\), but we have some samples.\nWe want to approximate it as a combination of simpler functions\n\\[\n    f \\sim g~\\begin{bmatrix} c_0 & c_1 & \\ldots \\end{bmatrix}\n\\]\nwhere each \\(c_k : \\Real \\to \\Real\\)\nand \\(g : (\\Real \\to \\Real)^\\infty \\to (I \\to I)\\).\n\nIf we generalize that by defining \\(A = I \\to I\\),\nwe have a thing \\(f : A\\)\nwhere each \\(c_k : A\\) and \\(g : A^\\infty \\to A\\).\n\\[\n    f \\sim g~c\n\\]\n\nIn the case of a perceptron, \\(g\\) has the form\n\\[\n    g~c = s ~ (m~w~c)\n\\]\nwhere \\(W : \\Real^\\infty\\), \\(c : \\Real^\\infty\\),\nand \\(s : \\mathbb{R} \\to I\\).\nThe purpose of \\(s\\) is to keep the summation result in \\(I\\).\n\nWe can state it as a combination of other functions.\n\nWe can truncate its Taylor series.\n\nWe can fit a function to the points.\n\n\n\n\n\n% QUESTION\n\n\n\nDefine $f^\\infty(x)$ as $\\lim_{n\\to\\infty} f^n(x)$, where $f^n = \\underbrace{f \\circ \\ldots \\circ f}_{n}$.\n\nUsually the unqualified term 'continued fraction' means continued fraction in $\\mathbb{R}$. For example, consider $f(x) = 1+1/x$ where $x \\in \\mathbb{R}$. In that case, for all $x > 0$, we have $f^\\infty(x) = \\Phi = \\frac{1+\\sqrt{5}}{2}$.\n\nNow consider another $f(x) = 1 + 1/x$ where $x \\in \\mathbb{R} \\to \\mathbb{R}$. For some $x$, we have $f^\\infty(x) = \\hat\\Phi$ where $\\hat\\Phi$ is the constant function that always gives $\\Phi$. In other words, we can think of $f^\\infty$ as a continued fraction in the function space $\\mathbb{R} \\to \\mathbb{R}$.\n\nHave anybody studied such continued fractions in function spaces? I googled:\n\n- continued fraction in function space\n- continued fraction of real function\n", "meta": {"hexsha": "d2085c3090eeb488d7dbb6872a290ad49f23e949", "size": 14659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/approximate.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/approximate.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/approximate.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": 26.8972477064, "max_line_length": 311, "alphanum_fraction": 0.6162084726, "num_tokens": 5269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744717487329, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.6882551637228501}}
{"text": "\\subsection{Monte Carlo sampling and analysis}\n\\input{6DL/EEn}\n\n\\begin{lemma}   \\label{MC}\nFor any $g\\in L^\\infty(G)$, we have\n  \\begin{equation}\n  \\begin{split}\n    \\mathbb{E}_n\\Big(\\mathbb{E}g-\\frac1n\\sum_{i=1}^n\n    g(\\omega_i)\\Big)^2\n    &=\\frac{1}{n}\\mathbb{V}(g)=\\frac{1}{n}\\Big(\\mathbb{E}(g^2) - \\big (\\mathbb{E}(g)\\big )^2\\Big)\n    \\\\\n    &=\n    \\left\\{\n             \\begin{aligned}\n    \\frac{1}{n}\\mathbb{V}(g)\n   & \\le\\frac{1}{n} \\sup_{\\omega, \\omega'\\in G} |g(\\omega) - g(\\omega')|^2\n    \\\\\n\\frac{1}{n}\\Big(\\mathbb{E}(g^2) - \\big (\\mathbb{E}(g)\\big )^2\\Big)\n&\\le\\frac{1}{n} \\mathbb E(g^2)\\le \\frac{1}{n}\\|g\\|^2_{L^\\infty},\n\\end{aligned}\n\\right.\n\\end{split}\n  \\end{equation} \n\\end{lemma}\n\n\\begin{proof}%[Proof of Lemma \\ref{MC}]\nFirst note that\n \\begin{equation}\n    \\label{eqn}\n    \\begin{aligned}\n\\left(\\mathbb{E} g-\\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right)^2 \n  & \n=\\frac{1}{N^2} \\left(\\sum_{i=1}^N(\\mathbb{E} g-g(\\omega_i))\\right)^2 \n  \\\\\n  &=\\frac{1}{N^2} \\sum_{i,j=1}^N(\\mathbb{E} g-g(\\omega_i))(\\mathbb{E} g-g(\\omega_j))\n  \\\\\n  &=\\frac{I_1}{N^2} +\\frac{I_2}{N^2}.\n    \\end{aligned}\n  \\end{equation}\nwith \n\\begin{equation}\nI_1= \\sum_{i=1}^N(\\mathbb{E} g-g(\\omega_i))^2,\\quad I_2=\\sum_{i\\neq  j}^N\\left ((\\mathbb{E}g)^2-\\mathbb {E}(g)(g(\\omega_i)+\ng(\\omega_j))+g(\\omega_i)g(\\omega_j))\\right).\n\\end{equation}\nConsider $I_1$, for any $i$,\n $$\n \\mathbb{E}_N(\\mathbb{E} g-g(\\omega_i))^2\n =\\mathbb{E}(\\mathbb{E} g-g)^2 = \\mathbb{V}(g).\n $$ \nThus,\n$$\n \\mathbb{E}_N (I_1) = n\\mathbb{V}(g).\n$$\nFor $I_2$, note that\n$$\n\\mathbb E_N g(\\omega_i)=\\mathbb E_N g(\\omega_j) =\\mathbb E(g)\n$$\nand, for $i\\neq j$,\n\\begin{equation}\\label{key}\n\\begin{aligned}\n\\mathbb {E}_N ( g(\\omega_i)g(\\omega_j)) &= \n\\int_{G\\times G\\times\\ldots\\times G}\ng(\\omega_i) g(\\omega_j) \\lambda(\\omega_1) \\lambda(\\omega_2)\\ldots \\lambda(\\omega_N)\nd\\omega_1d\\omega_2\\cdots d\\omega_N \\\\\n&= \\int_{G\\times G} g(\\omega_i) g(\\omega_j) \\lambda(\\omega_1) \n\\lambda(\\omega_1) \\lambda(\\omega_2)\nd\\omega_1d\\omega_2 \\\\\n&= \\mathbb {E}_N (\ng(\\omega_i))\\mathbb {E}_n(g(\\omega_j))\n=[\\mathbb E(g)]^2.\n\\end{aligned}\n\\end{equation}\nThus\n \\begin{equation}\n\\mathbb{E}_N (I_2) = \\mathbb{E}_N \\left( \\sum_{i\\neq j}^N((\\mathbb{E}g)^2-\\mathbb\n  E(g)(\\mathbb E(g(\\omega_i))+ \\mathbb E(g(\\omega_j)))+\\mathbb E(g(\\omega_i)g(\\omega_j))) \\right)=0.\n  \\end{equation}\nConsequently, there exist the following two formulas for $\\displaystyle \\mathbb{E}_N\\left(\\mathbb{E} g-\n      \\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right)^2$:\n \\begin{equation} \n \\mathbb{E}_N\\left(\\mathbb{E} g-\n      \\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right)^2 = \\frac{1}{N^2}\\mathbb{E}_N (I_1)\n      =\n           \\left\\{\n             \\begin{aligned}\n            \\frac{1}{N}\\mathbb{E}\\big ((\\mathbb{E} g-g)^2\\big )\\\\\n            \\frac{1}{N}(\\mathbb{E}(g^2) - (\\mathbb{E} g)^2).\n            \\end{aligned}\n    \\right.\n  \\end{equation}\nBased on the first formula above, since\n$$\n|g(\\omega) - \\mathbb{E} g|=|\\int_G \\big (g(\\omega) - g(\\tilde \\omega) \\big )\\lambda(\\tilde \\omega)d\\tilde \\omega|\\le \\sup_{\\omega, \\omega'\\in G} |g(\\omega) - g(\\omega')|,\n$$\nit holds that\n \\begin{equation} \n \\mathbb{E}_N\\left(\\mathbb{E} g-\n      {1\\over N }\\sum_{i=1}^Ng(\\omega_i)\\right)^2 \n            \\le\\frac{1}{N} \\sup_{\\omega, \\omega\\in G} |g(\\omega) - g(\\omega')|^2.\n  \\end{equation}\nDue to the second formula above,  \n \\begin{equation}\n    \\label{eqn}\n \\mathbb{E}_N\\left(\\mathbb{E} g-\n      \\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right)^2  \n            \\le\\frac{1}{N} \\mathbb E(g^2)\\le\\frac{1}{N}\\|g\\|^2_{L^\\infty}\n  \\end{equation}\nwhich completes the proof.\n\\end{proof}\n\nWe can also generalize Lemma \\ref{MC} to Hilbert spaces following a similar analysis.\n\n\\begin{lemma}    \nFor any $g: G\\rightarrow H$ where $H$ is a Hilbert space, we have\n  \\begin{equation}\n  \\begin{split}\n    \\mathbb{E}_n\\Big(\\|\\mathbb{E}g-\\frac1n\\sum_{i=1}^n\n    g(\\omega_i)\\|_H^2\\Big)\n    &=\\frac{1}{n}\\mathbb{V}(g)=\\frac{1}{n}\\Big(\\mathbb{E}(\\|g\\|_H^2) - \\big (\\mathbb{E}(\\|g\\|_H)\\big )^2\\Big)\n    \\\\\n    &=\n    \\left\\{\n             \\begin{aligned}\n    \\frac{1}{n}\\mathbb{V}(g)\n   & \\le\\frac{1}{n} \\sup_{\\omega, \\omega'\\in G} \\|g(\\omega) - g(\\omega')\\|_H^2\n    \\\\\n\\frac{1}{n}\\Big(\\mathbb{E}(\\|g\\|_H^2) - \\big (\\mathbb{E}(\\|g\\|_H)\\big )^2\\Big)\n&\\le\\frac{1}{n} \\mathbb E(\\|g\\|_H^2),\n\\end{aligned}\n\\right.\n\\end{split}\n  \\end{equation} \n\\end{lemma}\n\n\\begin{proof}%[Proof of Lemma \\ref{MC}]\nFirst note that\n \\begin{equation}\n    \\label{eqn}\n    \\begin{aligned}\n\\left\\|\\mathbb{E} g-\\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right\\|_H^2 \n  & \n=\\frac{1}{N^2} \\left\\|\\sum_{i=1}^N(\\mathbb{E} g-g(\\omega_i))\\right\\|_H^2 \n  \\\\\n  &=\\frac{1}{N^2} \\sum_{i,j=1}^N\\left(\\mathbb{E} g-g(\\omega_i), \\mathbb{E} g-g(\\omega_j)\\right)\n  \\\\\n  &=\\frac{I_1}{N^2} +\\frac{I_2}{N^2}.\n    \\end{aligned}\n  \\end{equation}\nwith \n\\begin{equation}\nI_1= \\sum_{i=1}^N\\|\\mathbb{E} g-g(\\omega_i)\\|_H^2,\\quad I_2=\\sum_{i\\neq  j}^N\\left(\\mathbb{E} g-g(\\omega_i), \\mathbb{E} g-g(\\omega_j)\\right).\n\\end{equation}\nConsider $I_1$, for any $i$,\n $$\n \\mathbb{E}_N(\\|\\mathbb{E} g-g(\\omega_i)\\|_H^2)\n =\\mathbb{E}(\\|\\mathbb{E} g-g\\|_H^2) = \\mathbb{V}(g).\n $$ \nThus,\n$$\n \\mathbb{E}_N (I_1) = n\\mathbb{V}(g).\n$$\nFor $I_2$, note that\n$$\n\\mathbb E_N \\|g(\\omega_i)\\|_H=\\mathbb E_N \\|g(\\omega_j)\\|_H =\\mathbb E(\\|g\\|_H)\n$$\nand, for $i\\neq j$,\n\\begin{equation}\\label{key}\n\\begin{aligned}\n\\mathbb {E}_N ( g(\\omega_i), g(\\omega_j)) &= \n\\int_{G\\times G\\times\\ldots\\times G}\ng(\\omega_j) g(\\omega_j) \\lambda(\\omega_1) \\lambda(\\omega_2)\\ldots \\lambda(\\omega_N)\nd\\omega_1d\\omega_2\\cdots d\\omega_N \\\\\n&= \\int_{G\\times G} (g(\\omega_j) , g(\\omega_j) ) \n\\lambda(\\omega_i) \\lambda(\\omega_j)\nd\\omega_id\\omega_j \\\\\n&=\\left( \\mathbb {E}_N (\ng(\\omega)) , \\mathbb {E}_N(g(\\omega))\\right)\n=\\|\\mathbb E(g)\\|_H^2.\n\\end{aligned}\n\\end{equation}\nThus\n \\begin{equation}\n\\mathbb{E}_N (I_2) = \\mathbb{E}_N \\left( \\sum_{i\\neq j}^N\\big(\\|\\mathbb{E}g\\|_H^2-\n(\\mathbb  E(g), \\mathbb E(g(\\omega_i))+ \\mathbb E(g(\\omega_j)))\n+ (g(\\omega_i), g(\\omega_j))\\big) \\right)=0.\n  \\end{equation}\nConsequently, there exist the following two formulas for $\\displaystyle \\mathbb{E}_N\\left\\|\\mathbb{E} g-\n      \\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right\\|_H^2$:\n \\begin{equation} \n \\mathbb{E}_N\\left\\|\\mathbb{E} g-\n      \\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right\\|_H^2 = \\frac{1}{N^2}\\mathbb{E}_N (I_1)\n      =\n           \\left\\{\n             \\begin{aligned}\n            \\frac{1}{N}\\mathbb{E}\\big (\\|\\mathbb{E} g-g\\|_H^2\\big )\\\\\n            \\frac{1}{N}(\\mathbb{E}(\\|g\\|_H^2) - \\|\\mathbb{E} g\\|_H^2).\n            \\end{aligned}\n    \\right.\n  \\end{equation}\nBased on the first formula above, since\n$$\n|g(\\omega) - \\mathbb{E} g|=|\\int_G \\big (g(\\omega) - g(\\tilde \\omega) \\big )\\lambda(\\tilde \\omega)d\\tilde \\omega|\\le \\sup_{\\omega, \\omega'\\in G} |g(\\omega) - g(\\omega')|,\n$$\nit holds that\n \\begin{equation} \n \\mathbb{E}_N\\left\\|\\mathbb{E} g-\n      {1\\over N }\\sum_{i=1}^Ng(\\omega_i)\\right\\|_H^2 \n            \\le\\frac{1}{N} \\sup_{\\omega, \\omega'\\in G} \\|g(\\omega) - g(\\omega')\\|_H^2.\n  \\end{equation}\nDue to the second formula above,  \n \\begin{equation}\n    \\label{eqn}\n \\mathbb{E}_N\\left\\|\\mathbb{E} g-\n      \\frac1N\\sum_{i=1}^Ng(\\omega_i)\\right\\|_H^2  \n            \\le\\frac{1}{N} \\mathbb E(\\|g\\|_H^2),\n  \\end{equation}\nwhich completes the proof.\n\\end{proof}\n\n\n%\\input{6DL/MonteCarloProbability}\n\\begin{lemma}\\label{lem:sample}\n\\textup{[Monte Carlo Sampling]}\n\tConsider \n\t\\begin{equation}\n\t\\label{uv}\n\tu(x)=\\int_{G}g(x,\\theta)\\rho(\\theta)d\\theta   = \\mathbb E (g)\n\t\\end{equation}\n\twith $0\\le \\rho(\\theta)\\in L^1(G)$. For any $N\\ge 1$, there exist $\\theta_i^*\\in G$ such that\n\t$$\n\t\\|u-u_N\\|_{L^2(\\Omega)}^2 \n\t\\le\\frac{1}{N}\n\t\\int_G \\|g(\\cdot,\\theta)\\|_{L^2(\\Omega)}^2\\rho(\\theta)d\\theta = {\\|\\rho\\|_{L^1(G)}\\over N}\\mathbb E (\\|g(\\cdot,\\theta)\\|_{L^2(\\Omega)}^2)\n\t$$\n\twhere  \n\t$\n\t\\|g(\\cdot,\\theta)\\|_{L^2(\\Omega)}^2 = \\int_{\\Omega} [g(x,\\theta)]^2 d\\mu(x),\n\t$\n\t\\begin{equation}\\label{fndef} \n\tu_N(x)=\\frac{\\|\\rho\\|_{L^1(G)}}{N}\\sum_{i=1}^N g(x,\\theta_i^*).\n\t\\end{equation}\n\nSimilarly, if $g(\\cdot, \\theta)\\in H^m(\\Omega)$, for any $N\\ge 1$, there exist $\\theta_i^*\\in G_i$ with $f_N$ given in \\eqref{fndef} such that\n\t\\begin{equation}\\label{eq:hm}\n\t\\|u-u_N\\|_{H^m(\\Omega)}^2 \n\t\\le \n\t\\int_G  \\|g(\\cdot,\\theta)\\|_{H^m(\\Omega)}^2\\rho(\\theta)d\\theta\n\t=\\frac{\\|\\rho\\|_{L^1(G)}}{N} \\mathbb E (\\|g(\\cdot,\\theta)\\|_{H^m(\\Omega)}^2).\n\t\\end{equation}\n\\end{lemma}\n\n\\iffalse\n\\begin{proof} \nNote that\n\\begin{equation}\n\\label{uv}\nu(x) = \\|\\rho\\|_{L^1(G)}\\mathbb E (g).\n\\end{equation}\nBy Lemma \\ref{MC},\n$$\n\\mathbb {E}_n\\left(\\bigg(\\mathbb E(g(x,\\cdot))\n-\\frac{1}{N}\\sum_{i=1}^N g(x,\\theta_i))\\bigg)^2\n\\right)\\le {1\\over N} \\mathbb E (g^2).\n$$\nBy taking integration w.r.t. $x$ on both sides, we get\n$$\n\\mathbb {E}_n\\left(h(\\theta_1,\\theta_2, \\cdots, \\theta_N)\n\\right)\\le {1\\over N} \\mathbb {E} \\Big(\\int_{\\Omega} g^2 d\\mu(x)\\Big),\n$$\nwhere \n$$\nh(\\theta_1,\\theta_2, \\cdots, \\theta_N) =  \\int_{\\Omega} \\bigg(\\mathbb E(g(x,\\cdot))\n-\\frac{1}{N}\\sum_{i=1}^N g(x,\\theta_i))\\bigg)^2 d\\mu(x).\n$$\nSince $\\mathbb {E}_N (1) = 1$ and $\\mathbb {E}_N (h) \\le {1\\over N} \\mathbb {E} \\Big(\\int_{\\Omega} g^2 d\\mu(x)\\Big)$, there exist $\\theta_i^* \\in G$ such that\n$$\nh(\\theta_1^*, \\theta_2^*, \\cdots, \\theta_N^*) \\le  {1\\over N}  \\int_{\\Omega} \\mathbb {E} (g^2) d\\mu(x).\n$$\n%Otherwise, $\\mathbb {E}_n\\left(h \\right) >  {1\\over n} \\mathbb {E} \\Big(\\int_{\\Omega} g^2 d\\mu(x)\\Big)$   if $h(\\theta_1,\\theta_2, \\cdots, \\theta_n) > {1\\over n}  \\int_{\\Omega} \\mathbb {E} (g^2)) d\\mu(x)$. \nThis implies that\n$$\n\t\\mathbb{E}_n\\|u-u_N\\|_{L^2(\\Omega)}^2 \n\t\\le\\frac{\\|\\rho\\|_{L^1(G)}}{N}\n\t\\int_G \\|g(\\cdot,\\theta)\\|_{L^2(\\Omega)}^2\\lambda(\\theta)d\\theta.\n\t$$ \n\tThe proof for \\eqref{eq:hm} is similar to the above analysis for the $L^2$-error analysis, which completes the proof.\n\\end{proof}\n\\fi\n\n\n\nWe also have a more general version of the above lemma.\n\\begin{lemma}\\label{lem:sampleHk}\n\tLet \n\t\\begin{equation} \\label{uint}\n\tu(x)=\\int_{G}g(x,\\theta)\\lambda(\\theta)d\\theta  = \\mathbb E (g)\n\t\\end{equation}\n\twith $\\|\\lambda(\\theta)\\|_{L^1(\\Theta)}=1$.\n\tFor any $N\\ge 1$, there exist $\\theta_i^*\\in G$ such that\n\t$$\n\t\\|u-u_N\\|_{H^m(\\Omega)}^2 \n\t\\le \n\t\\int_G  \\|g(\\cdot,\\theta)\\|_{H^m(\\Omega)}^2\\lambda(\\theta)d\\theta\n\t=\\frac{1}{N} \\mathbb E (\\|g(\\cdot,\\theta)\\|_{H^m(\\Omega)}^2)\n\t$$\n\twhere \n\t$$\n\tu_N(x)=\\frac{1}{N}\\sum_{i=1}^N g(x,\\theta_i^*)\n\t$$\n\tIn particular, if \n\t\\begin{equation}\n\t\\label{eq:4}\n\t|D^\\alpha g(x,\\theta)|\\le C, \\quad\\forall x, \\theta, |\\alpha|\\le m\n\t\\end{equation}\n\tThen\n\t$$\n\t\\|u-u_N\\|_{H^m(\\Omega)}\n\t\\le \n\t\\begin{pmatrix}\n\tm+d\\\\\n\tm\n\t\\end{pmatrix}^{1/2}\n\t|\\Omega|^{1/2}\n\tN^{-1/2}.\n\t$$\n\\end{lemma}\n", "meta": {"hexsha": "6bafffe8ab413376afaaf7d8fdb67fc29fe17a02", "size": 10482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MonteCarloBasic.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/MonteCarloBasic.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/MonteCarloBasic.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0550458716, "max_line_length": 207, "alphanum_fraction": 0.5869108949, "num_tokens": 4715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.6882335375456957}}
{"text": "\\section*{Dictionary Learning}\nAdapt the dict. to signal charact.$(\\mathbf{U}^\\star, \\mathbf{Z}^\\star) \\in \\argmin_\\mathbf{U,Z} \\| \\mathbf{X} - \\mathbf{U}\\mathbf{Z} \\|_F^2$ not jointly convex (just 1 arg)\n\n\\textbf{Matrix Factorization by Iter Greedy Minim.}\n\\begin{inparaenum}[\\color{gray} 1.]\n  \\item Coding step: $\\mathbf{Z}^{t+1} \\in \\argmin_\\mathbf{Z} \\| \\mathbf{X} - \\mathbf{U}^t \\mathbf{Z} \\|_F^2$ subj. 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 Init: random, samples from $X$ or fixed overcomplete dictionary.\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$ One at a time: set $\\mathbf{U} = [\\mathbf{u}_1^t\\cdots \\mathbf{u}_l\\cdots \\mathbf{u}_L^t]$ (fix all except $\\mathbf{u}_l$), isolate $\\mathbf{R}_l^t$ (residual due to atom $\\mathbf{u}_l$), find $\\mathbf{u}_l^*$ that minimizes $\\mathbf{R}_l^t$ s.t. $||\\mathbf{u}_l^*||_2=1$: $\\min_{u_l}\\|\\mathbf{R}_l^t - \\mathbf{u}_l(\\mathbf{z}_l^{t+1})^\\top\\|_F^2$ using SVD (first left-singular vector of $\\mathbf{R}_l^t$).\n\\end{inparaenum}", "meta": {"hexsha": "70b366bd235435e51d0b46baeeb09754a6572b32", "size": 1243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DictionaryLearning.tex", "max_stars_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_stars_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-20T20:58:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-20T20:58:16.000Z", "max_issues_repo_path": "DictionaryLearning.tex", "max_issues_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_issues_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DictionaryLearning.tex", "max_forks_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_forks_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-06T16:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-21T01:02:09.000Z", "avg_line_length": 138.1111111111, "max_line_length": 568, "alphanum_fraction": 0.6387771521, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6880861510143675}}
{"text": "\\section{Projectile (vacuum, gravity)}\nAssociated external model: \\texttt{projectile.py}\n\nSolves the projectile motion equations\n\\begin{equation}\n  x = x_0 + v_{x,0} t,\n\\end{equation}\n\\begin{equation}\n  y = y_0 + v_{y,0} t + \\frac{a}{2} t^2,\n\\end{equation}\nwith the following inputs\n\\begin{itemize}\n  \\item $x_0$, or \\texttt{x0}, initial horizontal position,\n  \\item $y_0$, or \\texttt{y0}, initial vertical position,\n  \\item $v_0$, or \\texttt{v0}, initial speed (scalar),\n  \\item $\\theta$, or \\texttt{ang}, angle with respect to horizontal plane,\n\\end{itemize}\nand following responses:\n\\begin{itemize}\n  \\item $r$, or \\texttt{r}, the horizontal distance traveled before hitting $y=0$,\n  \\item $x$, or \\texttt{x}, the time-dependent horizontal position,\n  \\item $y$, or \\texttt{y}, the time-dependent vertical position,\n  \\item $t$, or \\texttt{time}, the series of time steps taken.\n\\end{itemize}\nThe simulation takes 10 equally spaced time steps from 0 to 1 second, inclusive, and returns all four values\nas vector quantities.\n\n\\subsection{Grid, $x_0,y_0$}\nIf a Grid sampling strategy is used and the following distributions are applied to $x_0$ and $y_0$, with three\nsamples equally spaced on the CDF between 0.01 and 0.99 for each input, the following are some of the samples obtained.\n\\begin{itemize}\n  \\item $x_0$ is distributed normally with mean 0 and standard deviation 1,\n  \\item $y_0$ is distributed normally with mean 1 and standard deviation 0.2.\n\\end{itemize}\n\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{c c|c|c c}\n    $x_0$ & $y_0$ & $t$ & $x$ & $y$ \\\\ \\hline\n    -2.32634787404 & 0.53473045192 & 0 & -2.32634787404 & 0.534730425192 \\\\\n                   &               & $1/3$ & -2.09064561365 & 0.225988241143 \\\\\n                   &               & 1 & -1.61924109285 & -3.65816279362 \\\\ \\hline\n    1.0            & 0.0           & 0 & 1.0 & 0.0 \\\\\n                   &               & $1/3$ & 0.235702260396 & 0.691257815951 \\\\\n                   &               & 1 & 0.707106781187 & -3.19289321881\n  \\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "7eb3210c1d7297f19b8e3e82a8cfa5906a5b3a03", "size": 2053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/projectile.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/tests/projectile.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/tests/projectile.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": 42.7708333333, "max_line_length": 119, "alphanum_fraction": 0.6410131515, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6880751953574903}}
{"text": "\n\n    \\filetitle{dot}{Gross rate of growth pseudofunction}{modellang/dot}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\ndot(Expr)\ndot(Expr,K)\n\\end{verbatim}\n\n\\paragraph{Description}\\label{description}\n\nIf the input argument \\texttt{k} is not specified, this pseudofunction\nexpands to\n\n\\begin{verbatim}\n((Expr)/(Expr{-1}))\n\\end{verbatim}\n\nIf the input argument \\texttt{k} is specified, it expands to\n\n\\begin{verbatim}\n((Expr)/(Expr{k}))\n\\end{verbatim}\n\nThe two derived expressions, \\texttt{Expr\\{-1\\}} and \\texttt{Expr\\{k\\}},\nare based on \\texttt{Expr}, and have all its time subscripts shifted by\n--1 or by \\texttt{k} periods, respectively.\n\n\\paragraph{Example}\\label{example}\n\nThe following two lines\n\n\\begin{verbatim}\ndot(Z)\ndot(X+Y,-2)\n\\end{verbatim}\n\nwill expand to\n\n\\begin{verbatim}\n((Z)/(Z{-1}))\n((X+Y)/(X{-2}+Y{-2}))\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "ff3690b553ea54937e5247ed32409c2cf258b50b", "size": 848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/dot.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/dot.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/dot.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": 17.6666666667, "max_line_length": 72, "alphanum_fraction": 0.7051886792, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6880751834659794}}
{"text": "\\section*{Vectors and Matrices}\n\n\\subsection*{Vectors}\n\\begin{itemize}\n  \\item [vector:] $\\vectorarrow*{v}=\\begin{pmatrix}v_1\\\\v_2\\\\ \\vdots \\end{pmatrix}$\n  \\item [transpose:] $\\vectorarrow*{v}^\\transpose=(v_1 v_2 \\dotsc)$\n  \\item [inner product:] $\\vectorarrow*{a} \\dotproduct \\vectorarrow*{b} =\n    \\sum a_ib_i$\n  \\item [Hermitian conjugate:] $\\vectorarrow*{V}^\\dagger =\n    \\left(\\vectorarrow*{V}^*\\right)^\\transpose =\n    \\left(\\vectorarrow*{V}^\\transpose\\right)^*$\n  \\item [tensor product:] $%\n    \\vectorarrow*{a} \\otimes \\vectorarrow*{b} = %\n    \\begin{pmatrix}a_1\\\\a_2\\end{pmatrix}%\n    \\otimes %\n    \\begin{pmatrix}b_1\\\\b_2\\end{pmatrix}%\n    = \\begin{pmatrix}a_1\\begin{pmatrix}b_1\\\\b_2\\end{pmatrix}\n\\\\a_2\\begin{pmatrix}b_1\\\\b_2\\end{pmatrix}\\end{pmatrix}\n    = \\begin{pmatrix}\n      a_1b_1\\\\a_1b_2\\\\a_2b_1\\\\a_2b_2\\end{pmatrix}\n    $\n  \\item [ket:] $\\ket{\\psi} = (z_1, z_2, \\dotsc)^\\transpose$\n  \\item [bra:] $\\bra{\\psi} = (z^*_1, z^*_2, \\dotsc)$\n\\end{itemize}\n\n\\subsection*{}\n", "meta": {"hexsha": "0d60369d1c3690d399980bb1f5e9f8b29c6a44fb", "size": 984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Mathematics/units/unit_Preliminaries.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_Preliminaries.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_Preliminaries.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": 36.4444444444, "max_line_length": 83, "alphanum_fraction": 0.6392276423, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6880218199306568}}
{"text": "% !TEX root = main.tex\n\n\\chapter{Path Integrals in the Complex Plane}\n\\section{Paths}\n\nIn real analysis, we often consider the definite integral of a function $f: \\R \\to \\R$ from a real number $a$ to another real number $b$.  Of course, on the real line, there is only one `natural' route from $a$ to $b$, namely, along the real line itself.\n\n\\begin{comment}\n  There are essentially two ways of interpreting `the integral of $f$ between $a$ and $b$;' either integrating\n\\begin{center}\nfrom $a$ to $b$, that is, $\\int_a^b f(t) \\ dt$, or \\\\\nfrom $b$ to $a$, that is, $\\int_b^a f(t)\\ dt$.\n\\end{center}\nOf course, these integrals have the same absolute value, but with opposite signs.\n\\end{comment}\n\nIn order to make a sensible definition of integrating `between' two complex numbers $z_1$ and $z_2$, we need to take into account the fact that there are typically many routes from $z_1$ to $z_2$.  An interesting case arises when we consider paths with the same start and end-points.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ch3_path1}\n\\caption{Some examples of paths between complex numbers.}\n\\end{figure}\n\n\\begin{example}\n\\label{e:path1}\nConsider the line segment $L=[z_1,z_2]$, that is, the straight line segment joining two complex numbers $z_1,z_2 \\in \\C$.  For an interval $[a,b] \\subseteq \\R$, define\n\\[\n\\gamma : [a,b] \\to \\C, \\quad \\gamma (t) = z_1 + \\left( \\frac{t-a}{b-a} \\right) ( z_2 - z_1 ).\n\\]\nThen the line segment $L$ is precisely the range $\\gamma \\left( [a,b] \\right)$ of $\\gamma$, with $\\gamma (a) = z_1$ and $\\gamma (b) = z_2$.\n\n\\end{example}\n\n\\begin{figure}[H]\n\\centering\n\\altgraphics[scale=0.4]{ch3_param1}{ch3_path2}\n\\caption{The \\emph{function} $\\gamma:[a,b] \\to \\C$ describes the \\emph{set} $L$, and gives it a direction (i.e. from $\\gamma(a)=z_1$ to $\\gamma (b)=z_2$).}\n\\end{figure}\n\nThe process of finding $\\gamma : [a,b] \\to \\C$ such that each point on $L$ is of the form $\\gamma (t)$, for some $t \\in [a,b]$, is called a \\emph{parametrisation of $L$}, and we call $t$ the \\emph{parameter}.\n\nIf we think of $t$ as `time,' then as $t$ increases from $a$ to $b$, $\\gamma (t)$ moves from $\\gamma (a) = z_1$ to $\\gamma (b) = z_2$.  It does so with `velocity'\n\\begin{align*}\n\\gamma'(t) &=\\ \\frac{\\text{displacement}}{\\text{time}} \\\\[2ex]\n& =\\  \\frac{\\gamma (b) - \\gamma (a)}{b-a} = \\frac{z_2  - z_1}{b-a}.\n\\end{align*}\nIf we think about complex numbers as points or vectors (in $\\R^2$), this tells us that $\\gamma (t)$ moves in the direction $z_2-z_1$ with constant speed, as you might expect.\n\nWe should clarify the definition of the derivative $\\gamma'(t)$ of $\\gamma(t)$ before we continue.\n\\begin{definition}\nLet $\\gamma:[a,b] \\to \\C$, where $[a,b] \\subseteq \\R$, be a complex valued function of a real variable.  Then for $t \\in [a,b]$, $\\gamma$ is said to be differentiable at $t$ if the limit\n\\[\n\\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} \\frac{\\gamma (t+h)-\\gamma(t)}{h},\n\\]\nexists.  When it does exist, we denote its value by $\\gamma'(t)$, called the \\emph{derivative} of $\\gamma$ at $t$.\n\\end{definition}\nNote that if $\\gamma$ is written in terms of its real and imaginary parts\n\\[\n\\gamma(t) = u(t) + i v(t),\n\\]\nwhere $u,v:[a,b] \\to \\R$, then we have\n\\[\n\\gamma'(t) = u'(t) +i v'(t),\n\\]\nat points $t \\in [a,b]$ where these derivatives exist.\n%\\vspace*{3cm}\n\n\\begin{definition}\nA \\emph{path} is a subset $\\Gamma$ of $\\C$ for which there is a continuous function $\\gamma : [a,b] \\to \\C$ with\n\\[\n\\Gamma = \\set{ \\gamma (t) : t \\in [a,b] }.\n\\]\nThe function $\\gamma$ is called a \\emph{parametrisation} of $\\Gamma$, and we call the points $\\gamma(a)$ and $\\gamma(b)$ the \\emph{start-} and \\emph{end-points} of $\\Gamma$ respectively.\n\\end{definition}\nNote that $\\Gamma$ and $\\gamma$ are distinct mathematical objects: $\\Gamma$ is a set and $\\gamma$ is a function.  The function $\\gamma$ gives a `direction' to the path $\\Gamma$ ; $\\Gamma$ is a path \\emph{from} $\\gamma (a)$ \\emph{to} $\\gamma(b)$. Thus when we define a path, it is usually necessary to specify a parametrisation, or at least clarify its direction, in order to avoid ambiguity.\n\nThere are typically many functions that can be used to paramterise $\\Gamma$.  \nHaving said this, it is perfectly acceptable to define $\\Gamma$ by specifying a parametrisation $\\gamma$.  Thus if we say ``Consider the path defined by the function $\\gamma:[a,b] \\to \\C$,'' then it is understood that $\\Gamma = \\set{ \\gamma (t) : t \\in [a,b] }$.\n\n\n\\begin{example}\n\\label{e:path2}\nFor the line segment $L=[z_1,z_2]$, there are many different choices of function $\\gamma$ that describe $L$.\n\\begin{itemize}\n\\item Taking $a=0$ and $b=1$, $L$ is parametrised by \n\\[ \\gamma :[0,1] \\to \\C,\\qquad \\gamma(t)=z_1+t(z_2-z_1).\\]\n\\begin{blankbox}\nSubstituting the relevant values of $t$ we see that this path starts at $\\gamma(0)=z_1$ and ends at $\\gamma(1)=z_2$. Here we have $\\gamma'(t)=z_2-z_1$.\n\\end{blankbox}\n\\item We could also use the function \n\\[\n\\gamma:[-2,2] \\to \\C,\\ \\gamma(t) = z_1 + \\left( \\frac{t-(-2)}{(2-(-2))} \\right) ( z_2-z_1) = \\tfrac{1}{2} (z_1+z_2) + t \\left( \\frac{z_2-z_1}{4} \\right).\n\\]\n\\begin{blankbox}\nThis time, $\\gamma'(t) = \\frac{1}{4} (z_2-z_1)$, which makes sense since it takes 4 units of time for $\\gamma(t)$ to move from $z_1$ to $z_2$.\n\\end{blankbox}\n\\item Yet another option would be the function \n\\[\n\\gamma: [0,1] \\to \\C, \\qquad \\gamma (t) = z_1 + t^2 (z_2-z_1),\n\\]\n\\begin{blankbox}\nwhich has non-constant velocity $\\gamma'(t) = 2t (z_2-z_1)$.\n\nIn all three cases, the \\emph{set} $L$ is unchanged, but the \\emph{function} $\\gamma$ is different.\n\\end{blankbox}\n%\\vspace*{8cm}\n\\end{itemize}\n\\end{example}\n\n\n\n%\\vspace*{2cm}\n\\begin{example}\n\\label{e:path3}\nFix $R>0$ and consider the function\n\\[\n\\gamma:[0,\\pi] \\to \\C, \\gamma (t) = R \\cos (t) + i R \\sin (t).\n\\]\nLet us examine the path described by $\\gamma$.\n\\begin{blankbox}\nFor all $t$, \n\\[ \\abs{R \\cos(t)+iR \\sin (t)} = \\sqrt{R^2\\cos^2(t)+R^2\\sin^2 (t)} = R,\n\\]\nand thus every point $\\gamma(t)$ lies on the circle with centre $0$ and radius $R$.  Thus the given path consists of part of this circle.\n\nTo determine which part of the circle, we note that $\\gamma$\n\\begin{align*}\n& \\text{ starts at } \\gamma (0) = R\\cos(0)+iR\\sin(0)=R,\\\\\n& \\text{ `visits' }  \\gamma \\left( \\pi /2 \\right) = \\polar{R}{\\pi / 2} = iR \\\\\n& \\text{ end at }  \\gamma (\\pi) = \\polar{R}{\\pi} = -R.\n\\end{align*}\nThus $\\gamma$ describes the upper semicircle, centre $0$ and radius $R$, traversed in the anticlockwise direction.\n%\\vspace*{7cm}\n\\begin{center}\n\\includegraphics[scale=0.75]{ch3_semicircle0}\n\\end{center}\n%\\vspace*{6cm}\nThe tangent vector to this path at the point $\\gamma (t)$ is given by\n\\begin{align*}\n\\gamma '(t)& = -R \\sin (t) + i R \\cos (t) \\\\\n& = i^2 R \\sin (t)+iR \\cos (t) \\\\\n& = i \\gamma (t).\n\\end{align*}\nThus the tangent vector to the path at the point $\\gamma (t)$ is perpendicular to the position vector $\\gamma(t)$ (since multiplication by $i$ corresponds to anticlockwise rotation by $\\pi/2$).\n\\end{blankbox}\n\\end{example}\n\nNote that in examples~\\ref{e:path1},~\\ref{e:path2} and~\\ref{e:path3}, it is necessary to specify both $\\gamma(t)$ and the domain of $\\gamma$ in order to describe the path completely.  \n\n\n\n\n\\begin{definition}\n We say that a parametrisation $\\gamma:[a,b] \\to \\C$ of a path $\\Gamma$ is \\emph{smooth} if\n\\begin{enumerate}\n\\item[(i)] $\\gamma$ is differentiable on $[a,b]$,\n\\item[(ii)] $\\gamma'$ is continuous on $[a,b]$, and\n\\item[(iii)] $\\gamma' $ is nonzero on $[a,b]$.\n\\end{enumerate}\nA path $\\Gamma$ is called smooth if there exists a smooth parametrisation of $\\Gamma$.  \n\\end{definition}\n\nInformally, a smooth path is one with no corners or sharp turns.  The derivative $\\gamma'(t)$, regarded as a vector, is the tangent vector to the path $\\Gamma$ at the point $\\gamma (t)$.\n\nThe paths in Examples~\\ref{e:path1}, and~\\ref{e:path3} are all smooth.\n\n\\begin{definition}\nLet $\\Gamma$ be a path with smooth parametrisation $\\gamma: [a,b] \\to \\C$.  Then the \\emph{reverse} of $\\Gamma$ is the path $\\tilde{\\Gamma}$ consisting of the same set of points as $\\Gamma$, but traversed in the opposite direction.  The path $\\tilde{\\Gamma}$ may be parametrised by the function $\\tilde{\\gamma} : [a,b] \\to \\C$ where\n\\[\n\\tilde{\\gamma} (t) = \\gamma (a+b-t) \\quad \\text{for all } t \\in [a,b].\n\\]\n\\end{definition}\n\n\n\\begin{blankbox}\nNote that if we define the start- and end-points of $\\Gamma$ to be\n \\[ \\gamma (a) = z_1, \\quad \\gamma (b) = z_2 \\] \n then\n\\begin{align*}\n\\tilde{\\gamma} (a) & = \\gamma (a+b-a) = \\gamma (b) = z_2 \\\\\n\\tilde{\\gamma} (b) & = \\gamma (a+b-b) = \\gamma (a) = z_1.\n\\end{align*} \nThus $\\tilde{\\Gamma}$ starts at $z_2$ and ends at $z_1$.  Moreover, if $t \\in [a,b]$ then $a \\leq a+b-t \\leq b$, and so $\\tilde{\\gamma} (t)$ describes a point on the original path $\\Gamma$ (i.e. $\\tilde{\\Gamma}$ is the same set as $\\Gamma$).\n\nThe tangent vector is given by\n\\[\n\\tilde{\\gamma} ' (t) = \\frac{d}{dt} \\gamma (a+b-t) = \\gamma'(a+b-t) \\frac{d}{dt}(a+b-t) = - \\gamma'(a+b-t).\n\\]\nIn other words, at any point $z = \\tilde{\\gamma} (t) = \\gamma (a+b-t)$ on the path $\\Gamma$, the tangent vector to this path at $z$, when travelling in the reverse direction, points in the opposite direction to the tangent vector obtained when travelling in the original direction, as expected.\n\\end{blankbox}\n\n\\begin{example}\nLet us find the reverse of the paths considered in Examples~\\ref{e:path2} and~\\ref{e:path3}.\n\\end{example}\n\\begin{solution}\n\\begin{itemize}\n\\item $L=[z_1, z_2 ] $, parametrised by $\\gamma:[0,1] \\to \\C$, $\\gamma (t) = z_1 + t ( z_2 - z_1 )$.\nIt is clear that the reverse of $L$ is the line segment $\\tilde{L}=[z_2,z_1]$, i.e. the same line segment taken from $z_2$ to $z_1$.  We may parametrise $\\tilde{L}$ with the function $\\tilde{\\gamma}:[0,1] \\to \\C$, where\n\\begin{align*}\n\\tilde{\\gamma} (t) & = \\gamma (0+1-t ) \\\\\n& = z_1 + (1-t)(z_2-z_1) \\\\\n& = z_2+t(z_1-z_2).\n\\end{align*}\nOn examining the equation for $\\tilde{\\gamma} (t)$, it is clear that this function describes the path that starts at $z_2$ and travels in the direction $(z_1-z_2)$.\n\\item  $\\Gamma$ the semicircle parametrised by $\\gamma:[0,\\pi] \\to \\C$ , $\\gamma (t) = R \\cos (t) + i R \\sin (t)$. \n\nIn this case $\\tilde{\\Gamma}$ is the clockwise semicircular arc from $-R$ to $R$ via $iR$.  We may parametrise $\\tilde{\\Gamma}$ using $\\tilde{\\gamma}:[0,\\pi] \\to \\C$, where\n\\begin{align*}\n\\tilde{\\gamma} (t) & = \\gamma ( \\pi-t) \\\\\n& = R \\cos ( \\pi-t)+iR \\sin (\\pi-t) \\\\\n& = -R \\cos (t) + i R \\sin (t).\n\\end{align*}\nNote that $\\tilde{\\gamma} (t)$ is $\\gamma (t)$ reflected through the imaginary axis; and thus the path $\\tilde{\\Gamma}$ is the reflection of the path $\\Gamma$ in the imaginary axis.\n%\\vspace*{9cm}\n\n\\end{itemize}\n\\end{solution}\n\nWe shall often need to consider the paths that we obtain from joining smooth paths together.  Note that the resulting path may fail to be smooth, e.g., if there is a `corner' at the point where they meet.\n\nSuppose we have two or more (smooth) paths $\\Gamma_1,\\ \\Gamma_2$ etc., parametrised by $\\gamma_1:[a_1,b_1] \\to \\C$ and $\\gamma_2:[a_2,b_2] \\to \\C$, and suppose that the end-point of $\\Gamma_1$ is the same as the start-point of $\\Gamma_2$, i.e. $\\gamma_1(b_1)=\\gamma_2(a_2)$.\n\nThe curve obtained from $\\Gamma_1 \\cup \\Gamma_2 $ certainly looks like a path, but how do we make this precise?  In other words, can we describe this curve as the image of some continuous $\\gamma: [a,b] \\to \\C$?\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{ch3_join4}\n\\caption{We have two functions $\\gamma_1:[a_1,b_1] \\to \\C$ and $\\gamma_2:[a_2,b_2] \\to \\C$ parameterising $\\Gamma_1$ and $\\Gamma_2$ respectively.  We want a single continuous function $\\gamma:[a,b] \\to \\C$ parameterising $\\Gamma_1 \\cup \\Gamma_2$}.\n\\end{figure}\n\\begin{blankbox}\nTo do this, we first move $[a_2,b_2]$ to an interval from $b_1$ and then reparametrise $\\Gamma_2$.  For $t \\in \\R$, let $\\alpha(t)=  t-(a_2-b_1)$, so that $\\alpha$ maps $[a_2,b_2]$ bijectively to $[b_1,b_1+b_2-a_2]$.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ch3_join5}\n\\end{figure}\n%\\vspace*{5cm}\nNow, parametrise $\\Gamma_2$ using the function $\\gamma_{1+2}:[b_1,b_1+b_2-a_2] \\to \\C$, where\n\\[\n\\gamma_{1+2} (t) = \\gamma_2 ( \\alpha^{-1} (t) ) = \\gamma_2 (t+a_2-b_1)\n\\]\nfor all $t \\in [b_1,b_1+b_2-a_2]$.\n\\end{blankbox}\n\\begin{definition}\nSuppose that $\\Gamma_1$ and $\\Gamma_2$ are two paths parametrised by $\\gamma_1:[a_1,b_1] \\to \\C$ and $\\gamma_2:[a_2,b_2] \\to \\C$ respectively, such that $\\gamma_1(b_1) = \\gamma_2 (a_2)$.  Then we define the \\emph{join} of $\\Gamma_1$ and $\\Gamma_2$ to be the path $\\Gamma_1+\\Gamma_2$ parametrised by $\\gamma_{1+2}:[a_1,b_1+b_2-a_2] \\to \\C$, where\n\\[\n\\gamma_{1+2} (t) = \\begin{cases}\n\\gamma_1 (t) & t \\in [a_1,b_1] \\\\\n\\gamma_2 (t-b_1+a_2) & t \\in [b_1,b_1+b_2-a_2].\n\\end{cases}\n\\]\n\\end{definition}\n\n\nIf we have another path $\\Gamma_3$ we can join $\\Gamma_3$ to $\\Gamma_1+\\Gamma_2$ to get $\\Gamma_1+\\Gamma_2+\\Gamma_3$ and so on.\n\n\\begin{definition}\nA \\emph{contour} is a path which is the join of finitely many smooth paths.\n\\end{definition}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ch3_contour}\n\\caption{A contour $\\mathcal{C}$ constructed from the join of smooth paths $\\Gamma_1,\\Gamma_2,\\Gamma_3,\\Gamma_4$.  Note that $\\mathcal{C}$, considered as a path in its own right, need not be smooth.}\n\\end{figure}\n\n\n\\begin{definition}\nLet $\\Gamma$ be a smooth path parametrised by $\\gamma:[a,b] \\to \\C$.  Then the \\emph{length} $\\ell ( \\Gamma)$ of $\\Gamma$ is defined to be\n\\[\n\\ell ( \\Gamma ) : = \\int_a^b \\abs{ \\gamma '(t) } \\ dt.\n\\]\nFor a contour $\\mathcal{C} = \\Gamma_1+\\Gamma_2 + \\ldots + \\Gamma_n$, where $\\Gamma_1,\\Gamma_2, \\ldots , \\Gamma_n$ are smooth, we define the \\emph{length} $\\ell ( \\mathcal{C} )$ of $\\mathcal{C}$ to be\n\\[\n\\ell ( \\mathcal{C} ) = \\ell ( \\Gamma_1 ) + \\ell ( \\Gamma_2 ) + \\ldots + \\ell ( \\Gamma_n).\n\\]\n\\end{definition}\n\n\n\\begin{example}\nLet us compute the length of the line segment $L=[0,3+4i]$ using the parametrisation $\\gamma: [0,1] \\to \\C$ where\n\\[\n\\gamma (t) = (3+4i)t, \\quad t \\in [0,1].\n\\]\n\\end{example}\n\\begin{solution}\nWe have $\\gamma'(t)=3+4i$, with modulus $\\abs{\\gamma'(t)} = \\abs{3+4i}=5$ for all $t$.  Hence\n\\[\n\\ell (L) = \\int_0^1 \\abs{\\gamma'(t)} \\ dt = \\int_0^1 5\\ dt = 5,\n\\]\nwhich is what we would expect given the geometry of this line segment.\n\\begin{center}\n\\includegraphics[scale=0.8]{ch3_path6}\n\\end{center}\n%\\vspace*{3cm}\n\\end{solution}\n\\begin{example}\n\nNow we shall compute the length of the semicircular path $\\Gamma$ described by $\\gamma : [0,\\pi] \\to \\C$\n\\[\n\\gamma (t) = R \\cos (t) + i R \\sin (t), \\quad t \\in [0,\\pi].\n\\]\n\\end{example}\n\\begin{solution}\nWe have shown already that for all $t\\in [0,\\pi]$, $\\gamma'(t)=i\\gamma(t)$, and so\n\\[\n\\abs{\\gamma'(t)} = \\abs{i \\gamma (t)} = \\abs{i} \\abs{ R \\cos(t)+iR\\sin(t)} = R\n\\]\nfor all such $t$.  It follows that\n\\[\n\\ell ( \\Gamma ) = \\int_0^{\\pi} R\\ dt = \\pi R,\n\\]\nwhich is again what we would expect for a semicircle with radius $R$.\n%\\vspace*{8cm}\n\n\\end{solution}\n\n\\section{The Integral along a path in $\\C$}\nIn this section we will define the integral of a complex function along a smooth path $\\Gamma$.  We first recall the following results about integrals of real functions from Foundations.\n\\begin{theorem}\n\\label{t:realint}\nLet $f,g:[a,b] \\to \\R$ be two \\emph{continuous} real valued functions defined on some interval $[a,b] \\subset \\R$.  Then the integrals $\\int_a^b f(t)\\ dt$ and $\\int_a^b g(t)\\ dt$ both exist and satisfy the following properties:\n\\begin{enumerate}\n\\item[(i)] (Linearity) For any $c \\in \\R$ we have\n\\[\n\\int_a^b \\left( cf(t) +  g(t) \\right)\\ dt = c\\int_a^b f(t)\\ dt +  \\int_a^b g(t)\\ dt.\n\\]\n\\item[(ii)] (Fundamental Theorem of Calculus) If $F:[a,b]$ is an antiderivative for $f$ on $[a,b]$ (that is, $F'(t) = f(t)$ for all $t \\in [a,b]$), then \n\\[\n\\int_a^b f(t)\\ dt = F(b) - F(a),\n\\]\n\\item[(iii)] (Monotonicity) If $f(t) \\leq g(t)$ for all $t \\in [a,b]$ then\n\\[\n\\int_a^b f(t)\\ dt \\leq \\int_a^b g(t)\\ dt.\n\\]\n\\end{enumerate}\n\\end{theorem}\nWe shall frequently use the results of Theorem~\\ref{t:realint} without reference.\n\nNow let us define the integral of a complex-valued function of a real variable, $g:[a,b] \\to \\C$ defined on some interval $[a,b] \\subset \\R$.\n\n\\begin{definition}\n\\label{d:realint}\nLet $g:[a,b] \\to \\C$ be a complex valued function defined on the (real) interval $[a,b]$, and assume that the real and imaginary parts $\\Re (g)$ and $\\Im (g)$ are both continuous.  Then we define the integral of $g$ from $a$ to $b$ via\n\\[\n\\int_a^b g(t)\\ dt = \\int_a^b \\Re (g) (t)\\ dt + i \\int_a^b \\Im (g) (t)\\ dt.\n\\]\n\\end{definition}\nNote that the functions $\\Re (g)$ and $\\Im (g)$ are both real-valued and continuous, and so we have defined the integral of $g$ in terms of integrals of real functions.  So for example,\n\\[\n\\int_0^1 t+i2t\\ dt = \\int_0^1 t\\ dt +i \\int_0^1 2t\\ dt = \\left[ \\frac{t^2}{2} \\right]_0^1 + i \\left[ 2 \\frac{t^2}{2} \\right]_0^1\n= \\frac{1}{2}+i.\\]\n\n\nUsing the definition of the integral of a complex-valued function of a real variable, together with Theorem~\\ref{t:realint}, the results of Theorem~\\ref{t:cint1} follow easily.\n\n\\begin{theorem}\n\\label{t:cint1}\nLet $f,g:[a,b] \\to \\C$ be complex valued functions of a real variable defined on the interval $[a,b] \\subset \\R$, and assume that the real and imaginary parts of both $f$ and $g$ are all continuous.  Then the integrals $\\int_a^b f(t)\\ dt$ and $\\int_a^b g(t)\\ dt$ both exist and satisfy the following properties:\n\\begin{enumerate}\n\\item[(i)] (Linearity) For any $\\alpha \\in \\C$ we have\n\\[\n\\int_a^b \\left( \\alpha f(t) +  g(t) \\right)\\ dt = \\alpha \\int_a^b f(t)\\ dt +  \\int_a^b g(t)\\ dt.\n\\]\n\\item[(ii)] (Fundamental Theorem of Calculus) If $F:[a,b] \\to \\C$ is an antiderivative for $f$ on $[a,b]$ (that is, $F'(t) = f(t)$ for all $t \\in [a,b]$), then \n\\[\n\\int_a^b f(t)\\ dt = F(b) - F(a).\n\\]\n\\end{enumerate}\n\\end{theorem}\nNote that there is no way to extend Theorem~\\ref{t:realint}(iii) to complex valued functions, as there is no sensible way to interpret the expression $\\alpha \\leq \\beta $ for $\\alpha, \\beta \\in \\C$.\n\n\n\\begin{definition}\nLet $U \\subseteq \\C$ be open, $f:U \\to \\C$ a continuous function and let $\\Gamma$ be a smooth path contained in $U$, parametrised by $\\gamma :[a,b] \\to \\C$.  Then the \\emph{integral of $f$ along $\\gamma$}, which we write as \n\\[\n\\int_{\\Gamma} f,\n\\]\nis defined via\n\\begin{equation}\n\\label{e:pathint}\n\\int_{\\Gamma} f = \\int_a^b f \\left( \\gamma(t) \\right) \\gamma ' (t)\\ dt.\n\\end{equation}\n\\end{definition}\n\n\\begin{note}\n\\begin{enumerate}\n\\item[(i)] The composition $f \\left( \\gamma (t) \\right)$ is a complex valued function of a real variable, hence so is $f \\left( \\gamma (t) \\right) \\gamma '(t)$.  It follows that the integral\n\\[\n\\int_a^b f \\left( \\gamma(t) \\right) \\gamma ' (t)\\ dt\n\\]\non the right hand side of~\\eqref{e:pathint} is of the type defined in Definition~\\ref{d:realint}.\n\\item[(ii)] It is sometimes convenient to write\n\\[\n\\int_{\\Gamma} f \\text{ as } \\int_{\\Gamma} f(z)\\ dz \\text{ or } \\int_{\\Gamma} f ( \\zeta ) \\ d \\zeta.\n\\]\n\\item[(iii)] The value of the integral depends on both the function $f$ and the path $\\Gamma$.  It looks like it should also depend on our choice of parametrisation $\\gamma$, but this is not the case.\n\\end{enumerate}\n\\end{note}\n\n\n\\begin{example}\n\\label{e:3paths}\nFix $\\alpha$ and $\\beta \\in \\C$ and let $f:\\C \\to \\C$ be defined by\n\\[\nf(z) = \\alpha z + \\beta \\conj{z}.\n\\]\nLet us compute the value of $\\int_{\\Gamma} f$ along each of the three paths\n\\begin{align*}\n \\Gamma_1&=[0,2]\\\\\n \\Gamma_2&=[2,2+2i] \\\\\n \\Gamma_3 &=[2+2i,0].\n\\end{align*}\n\\end{example}\n\\begin{solution}\nFollowing the method of Example~\\ref{e:path2}, parametrise each $\\Gamma_j$ by the function $\\gamma_j:[0,1] \\to \\C$, where\n\\begin{align*}\n\\gamma_1 (t) & = 2t \\\\\n\\gamma_2 (t) &= 2+i 2t \\\\\n\\gamma_3 (t) & = (1-t)(2+2i)\n\\end{align*}\nfor $t \\in [0,1]$.\n\nFor the path $\\Gamma_1$, we have\n\\[\nf (\\gamma_1 (t) ) = \\alpha (2t)+\\beta (\\conj{2t}) = (\\alpha+\\beta)(2t) \\text{ and } \\gamma_1'(t) = 2\n\\]\nfor all $t \\in [0,1]$.  Thus \n\\begin{align*}\n\\int_{\\Gamma_1} f &= \\int_0^1 f( \\gamma_1(t)) \\gamma_1'(t)\\ dt \\\\\n&= \\int_0^1 (\\alpha+\\beta)(2t)(2)\\ dt \\\\\n& = 4(\\alpha+\\beta) \\int_0^1 t\\ dt = 2(\\alpha+\\beta). \n\\end{align*}\nFor $\\Gamma_2$, we have\n\\begin{align*}\nf ( \\gamma_2(t)) & = \\alpha (2+i2t)+\\beta ( \\conj{2+i2t} ) \\\\\n& = \\alpha (2+i2t)+\\beta (2-2it) \\\\\n\\shortintertext{ and }\n\\gamma_2'(t) &= 2i. \\\\\n\\shortintertext{ hence }\nf ( \\gamma_2(t) ) \\gamma_2' (t) & = \\alpha (2+i2t)+\\beta (2-2it) 2i \\\\\n& = -4(\\alpha-\\beta)t + 4i (\\alpha+\\beta),\n\\shortintertext{ and so the required path integral is }\n\\int_{\\Gamma_2} f& = \\int_0^1 \\left[-4(\\alpha-\\beta)t + 4i (\\alpha+\\beta)\\right]\\ dt \\\\\n& = \\left( -4(\\alpha-\\beta) \\int_0^1 t\\ dt \\right) +i \\left( 4(\\alpha+\\beta) \\int_0^1 1\\ dt \\right) \\\\\n& = -2(\\alpha-\\beta)+4i(\\alpha+\\beta).\n\\end{align*}\nFinally, we have\n\\begin{align*}\nf ( \\gamma_3 (t) ) & = 2(\\alpha+\\beta)(1-t)+i 2 (\\alpha-\\beta)(1-t) \\\\\n\\gamma_3'(t) & = -2-2i \\\\\n\\shortintertext{ so that }\nf ( \\gamma_3 (t)) \\gamma_3'(t) & = \\left[ \\alpha (2+2i)+\\beta(2-2i) \\right] (-2-2i)(1-t) \\\\\n\\shortintertext{ giving }\n\\int_{\\Gamma_3} f & = \\left[ \\alpha (2+2i)+\\beta(2-2i) \\right] (-2-2i) \\int_0^1 (1-t)\\ dt \\\\\n& = -4\\beta-4\\alpha i.\n\\end{align*}\n\\end{solution}\n\n\\begin{example}\n Find\n\\[\n\\int_{\\Gamma} f,\n\\]\nwhere $f$ is the complex function $f(z)=\\conj{z}$ and $\\Gamma$ is the semicircular path joining $1$ and $-1$ defined by $\\gamma : [0, \\pi] \\to \\C$,  $\\gamma(t)=\\cos(t) + i \\sin (t)$.\n\\end{example}\n\\begin{solution}\n%\\begin{framed}\n%\\vspace{10cm}\n%\\end{framed}\nHere we have\n\\[\nf(\\gamma(t)) = \\conj{\\cos(t)+i\\sin(t)} = \\cos(t)-i \\sin(t),\n\\]\nand $\\gamma'(t) = -\\sin(t)+i \\cos (t)$, so that\n\\begin{align*}\nf(\\gamma(t))\\gamma '(t) &=  \\left(-\\sin(t)+i \\cos (t) \\right) \\left( \\cos(t)-i \\sin(t) \\right)\\\\\n& = -\\cos(t)\\sin(t)+\\sin(t)\\cos(t) +i \\left[ (-\\sin(t))(-\\sin(t))+\\cos(t)\\cos(t) \\right] \\\\\n& = i.\n\\end{align*}\nHence\n\\[\n\\int_{\\Gamma} \\conj{z}\\ dz = \\int_0^{\\pi} i\\ dt = \\pi i.\n\\]\n\\end{solution}\nWe now extend the definition of the integral along a smooth path to the integral along a contour $\\mathcal{C}$ which is the join of a finite number of smooth paths $\\Gamma_1,\\Gamma_2, \\ldots , \\Gamma_n$ as follows:\n\\[\n\\int_{\\mathcal{C}} f = \\int_{\\Gamma_1} f + \\int_{\\Gamma_2} f + \\ldots + \\int_{\\Gamma_n} f\n\\]\n\\begin{example}\n\\label{e:triangle}\nCompute the value of $\\int_{\\mathcal{C}} f$ where $f=\\alpha z + \\beta \\conj{z}$ and $\\mathcal{C}=\\Gamma_1 + \\Gamma_2 + \\Gamma_3$ from Example~\\ref{e:3paths}.\n\\end{example}\n\n\\begin{solution}\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[thick,gray,->] (-2,0) -- (3,0) ;\n\\draw[thick,gray,->] (0,-1) -- (0,3) ;\n\\draw[thick] (0,0) -- node[midway,below,font=\\footnotesize]{$\\Gamma_1$} (2,0) node[below,font=\\footnotesize]{$2$};\n\\draw[thick] (2,0) -- node[midway,right,font=\\footnotesize]{$\\Gamma_2$} (2,2) node[right,font=\\footnotesize]{$2+2i$};\n\\draw[thick] (2,2) -- node[midway,left,font=\\footnotesize]{$\\Gamma_3$} (0,0);\n\\end{tikzpicture}\n\\end{center}\nHere we have\n\\begin{align*}\n\\int_{\\mathcal{C}} f & = \\int_{\\Gamma_1} f + \\int_{\\Gamma_2} f + \\int_{\\Gamma_3} f \\\\\n& = 2(\\alpha+\\beta)-2(\\alpha-\\beta)+4i(\\alpha+\\beta)\\\\\n&-4\\beta-4\\alpha i \\\\\n& = i 4 \\beta.\n\\end{align*}\n\nNote that the function $f(z) =\\alpha z + \\beta \\conj{z}$ is not differentiable anywhere in $\\C$ unless $\\beta = 0$.  Moreover, if $\\beta = 0$ then $f(z)=\\alpha z$ is holomorphic on $\\C$ and $\\int_{\\mathcal{C}} f = 0$ for the contour $\\mathcal{C}=\\Gamma_1+\\Gamma_2+\\Gamma_3$ in the preceding example, while $\\int_{\\mathcal{C}} f \\neq 0$ when $\\beta \\neq 0$.  This is not a coincidence, as we shall see in subsequent sections.\n\\end{solution}\n\\section{The Fundamental Theorem of Complex Calculus}\n\\begin{definition}\nA set $S \\subseteq \\C$ is \\emph{connected} if given any pair of points $z_1,z_2 \\in S$, there is a contour contained in $S$ that starts at $z_1$ and ends at $z_2$. A \\emph{region} $\\mathcal{R}$ is a non-empty, open, connected subset of $\\C$.\n\\end{definition}\n\\begin{figure}[H]\n\\centering\n\\blankgraphics[scale=0.5]{ch3_connected} \\qquad \\blankgraphics[scale=0.5]{ch3_notconnected}\n\\end{figure}\n\\begin{definition}\nLet $\\mathcal{R}$ be a region and $f:\\mathcal{R} \\to \\C$ a function defined on $\\mathcal{R}$.  A function $F:\\mathcal{R} \\to \\C$ is called an \\emph{antiderivative for $f$ on $\\mathcal{R}$} if\n\\begin{enumerate}\n\\item[(i)] $F$ is holomorphic on $\\mathcal{R}$ and\n\\item[(ii)] $F'(z)=f(z)$ for all $z \\in \\mathcal{R}$.\n\\end{enumerate}\n\\end{definition}\n\\begin{example}\nFind antiderivatives for the functions\n\\begin{enumerate}\n\\item[(i)] $f(z)=\\alpha z + \\beta$ (where $\\alpha, \\beta \\in \\C$ are fixed) on the region $\\C$.\n\\item[(ii)] $f(z) = \\dfrac{1}{(1+iz)^2}$ on the region $\\C \\backslash \\set{i}$. \n\\end{enumerate}\n\\end{example}\n\\begin{solution}\n\\begin{enumerate}\n\\item[(i)] The function $F$ defined by $F(z) = \\frac{\\alpha}{2} z^2+\\beta z$ is an antiderivative for $f$ on $\\C$, as $F$ is holomorphic on $\\C$ with $F'(z)=f(z)$ for all $z$.\n\\item[(ii)] The function $F:\\C \\backslash \\set{i} \\to \\C$ defined by\n\\[\nF(z)=\\frac{i}{1+iz}\n\\]\nis an antiderivative for $f$ on $\\C \\backslash \\set{i}$ by the quotient rule.\n\\end{enumerate}\n\\end{solution}\n\\begin{question}\nDoes the function $f(z) = \\conj{z}$ have an antiderivative on $\\C$?  We will answer this question shortly.\n\\end{question}\n%\\vspace*{2cm}\nWe know already that $f(z)=\\conj{z}$ cannot be the antiderivative of any function $g:\\C \\to \\C$ as $f$ is not differentiable anywhere.\n\\begin{theorem}[Fundamental Theorem of Complex Calculus]\n\\label{t:ftc}\nLet $f$ be continuous on a region $\\mathcal{R}$ suppose that $F$ is an antiderivative for $f$ on $\\mathcal{R}$.  If $\\mathcal{C}$ is a contour contained in $\\mathcal{R}$, then we have\n\\[\n\\int_{\\mathcal{C}} f = F( z_2)-F(z_1)\n\\]\nwhere $z_1$ and $z_2$ are the start- and end-points of $\\mathcal{C}$ respectively.\n\\end{theorem}\n\\begin{proof}\n\nLet us first consider the case where $\\mathcal{C}$ consists of a single smooth path $\\Gamma$, parametrised by $\\gamma:[a,b] \\to \\C$.  Since $F$ is an antiderivative for $f$ on $\\mathcal{R}$ and $\\gamma$ is smooth, the Chain Rule gives\n\\[\n\\frac{d}{dt} \\left[ F( \\gamma(t)) \\right] = F'(\\gamma(t))\\gamma'(t) = f(\\gamma(t))\\gamma ' (t).\n\\]\nHence\n\\begin{align*}\n\\int_{\\Gamma} f & = \\int_a^b f(\\gamma(t)) \\gamma' (t)\\ dt & \\\\\n& = \\int_a^b \\frac{d}{dt} \\left[ F( \\gamma (t) ) \\right]\\ dt & \\\\\n& = F ( \\gamma (b) ) - F ( \\gamma (a) ) & \\text{ by Theorem~\\ref{t:cint1}(ii)} \\\\\n& = F(z_2)-F(z_1).\n\\end{align*}\n\n\n%\\vspace*{14cm}\n\nNow, if $\\mathcal{C}$ is the join of $n$ smooth paths $\\mathcal{C} = \\Gamma_1+\\ldots + \\Gamma_n$, let $w_{j-1}$ and $w_j$ denote the start- and end-points of $\\Gamma_j$ respectively, so that $w_0=z_1$ and $w_n=z_2$.  Then\n\n\\begin{align*}\n\\int_{\\mathcal{C}} f & = \\int_{\\Gamma_1} f + \\int_{\\Gamma_2} f + \\ldots + \\int_{\\Gamma_n} f \\\\\n& = \\left( F(w_1)-F(w_0) \\right) + \\left( F(w_2)-F(w_1) \\right) + \\ldots + \\left( F(w_n)-F(w_{n-1}) \\right) \\\\\n& = F(w_n)-F(w_0) = F(z_2)-F(z_1).\n\\end{align*}\n\n\n\\end{proof}\nThe Fundamental Theorem of Complex Calculus tells us that if an antiderivative $F$ for $f$ on $\\mathcal{R}$ is known, then a potentially complicated contour integral $\\int_{\\mathcal{C}} f$ may be evaluated by simply computing the values of $F(z_1)$ and $F(z_2)$.\n\n\\begin{example}\n\\label{e:2paths}\nLet $\\alpha \\in \\C$ be fixed and let $f(z)=\\alpha z$ for all $z \\in \\C$.  We shall evaluate $\\int_{\\mathcal{C}} f$ along the contour $\\mathcal{C}=\\Gamma_1 + \\Gamma_2$ where $\\Gamma_1=[0,2]$ and $\\Gamma_2 = [2,2+2i]$ using Theorem~\\ref{t:ftc}.\n\\end{example}\n\\begin{solution}\nThe function $F$ defined by $F(z)=\\frac{\\alpha}{2} z^2$ is an antiderivative for $f$ on $\\C$.\n  The start- and end-points of $\\mathcal{C}$ are $0$ and $2+2i$ respectively.  Hence by the Fundamental Theorem of Complex Calculus,\n\\begin{align*}\n\\int_{\\mathcal{C}} f &= F(2+2i)-F(0) \\\\\n& = \\frac{\\alpha (2+2i)^2}{2} - 0 \\\\\n& = i 4 \\alpha.\n\\end{align*}\n\\end{solution}\n\n\\begin{example}\nWith $f,\\Gamma_1$ and $\\Gamma_2$ as in Example~\\ref{e:2paths} and let $\\Gamma_3 = [2+2i,0]$.  We will calculate $\\int_{\\mathcal{C}} f$ where $\\mathcal{C}=\\Gamma_1+\\Gamma_2+\\Gamma_3$.\n\\end{example}\n\\begin{solution}\nThis time $\\mathcal{C}$ starts and ends at $0$, so that\n\\[\n\\int_{\\mathcal{C}} f = F(0) - F(0) = 0.\n\\]\n\\end{solution}\n\n\\begin{example}\nLet $\\Gamma_1$ be the path consisting of the arc of the circle of radius $2$, centre $0$, traversed in the anticlockwise direction from $2$ to $-2$ and let $\\Gamma_2$ be the line segment $[-2,-i]$.  Calculate\n\\[\n\\int_{\\mathcal{C}} f,\n\\]\nwhere $f(z) = \\dfrac{1}{(1+iz)^2}$ and $\\mathcal{C} = \\Gamma_1+ \\Gamma_2$.\n\\end{example}\n\\begin{solution}\n\\begin{center}\n\\includegraphics[scale=0.5]{ch3_ftc2}\n\\end{center}\nThe contour $\\mathcal{C}$ is contained in the region $\\C \\backslash \\set{i}$, and $F(z) = \\frac{i}{(1+iz)}$ is an antiderivative for $f$ on this region.  Since $\\mathcal{C}$ starts at $2$ and ends at $-i$, we have\n\\begin{align*}\n\\int_{\\mathcal{C}} f & = F(-i)-F(2) \\\\\n& = \\frac{i}{2} - \\frac{i}{1+2i} \\\\\n& = - \\frac{2}{5} +i \\frac{3}{10}.\n\\end{align*}\n\\end{solution}\n\\begin{theorem}[Contour Independence]\n\\label{t:contint}\nLet $f$ be continuous on $\\mathcal{R}$ and let $F$ be an antiderivative for $f$ on $\\mathcal{R}$.  If $\\mathcal{C}_1$ and $\\mathcal{C}_2$ are two contours inside $\\mathcal{R}$ with the same start- and end-points, we have\n\\[\n\\int_{\\mathcal{C}_1} f = \\int_{\\mathcal{C}_2} f.\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $z_1$ be common the start-point of both $\\mathcal{C}_1$ and $\\mathcal{C}_2$, and $z_2$ the end-point.  Then by Theorem~\\ref{t:ftc},\n\\[\n\\int_{\\mathcal{C}_1} f = F(z_2)-F(z_1) = \\int_{\\mathcal{C}_2} f.\n\\]\n\\end{proof}\nOne application of Theorem~\\ref{t:contint} is that it allows us to replace a potentially complicated contour integral along $\\mathcal{C}_1$ with an easier one alone $\\mathcal{C}_2$.\n\n\\begin{definition}\nA contour $\\mathcal{C}$ is called a \\emph{closed contour} if its end point is the same as its start point.\n\\end{definition}\n\\begin{theorem}[Antiderivatives and Closed Contours]\n\\label{t:closed}\nLet $f$ be continuous on $\\mathcal{R}$ and let $F$ be an antiderivative for $f$ on $\\mathcal{R}$.  If $\\mathcal{C}$ is any closed contour inside $\\mathcal{R}$ then\n\\[\n\\int_{\\mathcal{C}} f = 0.\n\\]\n\\end{theorem}\n\\begin{proof}\nThis time $\\mathcal{C}$ has the same start- and end-point $z_1$.  Hence\n\\[\n\\int_{\\mathcal{C}} f = F(z_1)-F(z_1) = 0.\n\\]\n\\end{proof}\n\n\n\\begin{question}\nNow, do we know whether or not $f(z)=\\conj{z}$ has an antiderivative on $\\C$?  Does Example~\\ref{e:triangle} tell you anything?\n\\end{question}\n%\\vspace*{5cm}\n\\begin{answer}\n The function $f(z) = \\conj{z}$ is a special case of the function considered in Example~\\ref{e:triangle}, with $\\alpha =0$ and $\\beta =1$.  If $\\mathcal{C}$ is the closed triangular contour of that example, then we have seen that\n\\[\n\\int_{\\mathcal{C}}  \\conj{z}\\ dz = 4i \\neq 0.\n\\]\nThus as a consequence of Theorem~\\ref{t:closed}, we see that $f(z)=\\conj{z}$ cannot have an antidervative on $\\C$.\n\\end{answer}\n\\begin{theorem}[Zero Derivative Theorem]\nLet $F$ be holomorphic on a region $\\mathcal{R}$ and suppose that $F'(z)=0$ for all $z \\in \\mathcal{R}$.  Then $F$ is constant on $\\mathcal{R}$.\n\\end{theorem}\n\\begin{proof}\nLet $z_1,z_2 \\in \\mathcal{R}$.  We will show that $F(z_1)=F(z_2)$.\n\nSince $\\mathcal{R}$ is connected there is a contour $\\mathcal{C}$ in $\\mathcal{R}$ that starts at $z_1$ and ends at $z_2$.  Hence by Theorem~\\ref{t:ftc},\n\\[\nF(z_2)-F(z_1) = \\int_{\\mathcal{C}} F'(z)\\ dz = \\int_{\\mathcal{C}} 0\\ dz = 0.\n\\]\nIn other words $F(z_1)=F(z_2)$.  Since this is true for all $z_1,z_2 \\in \\mathcal{R}$, $F$ must be constant on $\\mathcal{R}$.\n\\end{proof}\n\n%\\vspace*{12cm}", "meta": {"hexsha": "5c7253eb6dbca294d0ea682cab05cbac538dc2a2", "size": 31600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2003/LectureNotes/Chapter_3.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_3.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_3.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 45.9970887918, "max_line_length": 424, "alphanum_fraction": 0.6508544304, "num_tokens": 11689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.918480237330998, "lm_q1q2_score": 0.6880218012832308}}
{"text": "\\section{Monte Carlo Simulation} \\label{sec:4}\n\\thispagestyle{plain} % surpress header on first page\n\nBecause QBSM has no closed-form expression, they must be assessed numerically through Monte Carlo(MC) simulation\\citep{fishman1996MonteCarloConcepts}. MC simulation generates random samples from a probability distribution, and the problem becomes deterministic for each sample. Solving these deterministic problems allows us to obtain statistical information regarding the exact solutions, such as the mean or variance. However, MC approaches are renowned for their slow convergence, with an average coverage rate of $\\sqrt N$(N stands for the sample size). This means that, to get more precise outcomes, a large number of samples are required.\nAlthough various improved MC methods have been developed, such as Latin sampling methods\\citep{loh1996LatinHypercubeSampling} and Quasi-Monte Carlo(QMC) methods\\citep{niederreiter1992RandomNumberGeneration}, there are still certain limits to it. \\\\\n\n\\noindent\nIn \\cite{kucherenko2017DifferentNumericalEstimators}, the performance of several numerical schemes based on sampling strategies was compared. It is documented that the double loop reordering(DLR) technique outperforms all other methods, especially when combined with QMC sampling. In this paper, by integrating the two MC estimators provided by \\cite{kucherenko2019QuantileBasedGlobal} and the procedure improved by \\cite{song2021QuantileSensitivityMeasures}, we list the following steps to estimate QBSM in our study:\n\n\\begin{itemize}\n\\item \\textbf{Step 1:} To obtain  $q_{Y \\mid \\Theta_{i}}$:\n\n\\begin{enumerate}[label=(\\arabic*),ref=\\arabic*]\n  \\item Generate $N$ points  $\\boldsymbol{\\Theta}^{(k)}=\\left\\{\\Theta_{1}^{(k)}, \\Theta_{2}^{(k)}, \\cdots, \\Theta_{d}^{(k)}\\right\\}, k=1,2, \\cdots, N$ according to the joint PDF $ \\rho (\\boldsymbol{\\Theta)}$.\n\n\n  \\item Compute the unconditional values of output $Y^{(k)}=g\\left(\\boldsymbol{\\Theta}^{(k)}\\right), k=1, 2, \\dots, N$, then reorder them in ascending order $\\left\\{Y^{(1-s t)}, Y^{(2-\\mathrm{nd})}, \\cdots, Y^{(N-\\mathrm{th})}\\right\\}^{\\mathrm{T}}$.\n\n  \\item \\label{itm:2} Decide the $\\alpha$-th output value as unconditional quantile $q_Y(\\alpha)$: $q_{Y}^{(N)}(\\alpha)=Y^{(\\alpha N-\\text { th })}$.\n\n\n\\end{enumerate}\n\n\n\n\\item \\textbf{Step 2:} To obtain  $q_{Y \\mid \\Theta_{i}}(\\alpha)$:\n\n\n\\begin{enumerate}[label=(\\arabic*),ref=\\arabic*]\n  \\item Generate $M$ points  $\\left\\{\\theta_{i}^{(1)}, \\theta_{i}^{(2)}, \\cdots, x_{i}^{(M)}\\right\\}^{\\mathrm{T}}$ according to the joint PDF $\\rho (\\Theta)$, which should be independent from $\\boldsymbol{\\Theta}^{(k)}$\n\n  \\item Fix $\\Theta_i$ st $\\Theta_i = \\theta_i^{(k)}, k= 1, \\dots, M$, and get N conditional points\n\n\n  $$\n    \\Theta^{(k)}=\\left\\{\\Theta_{1}^{k}, \\cdots, \\Theta_{i-1}^{k}, x_{i}^{(k)}, \\Theta_{i+1}^{k}, \\cdots, X_{d}^{k}\\right\\}, k=1,2, \\cdots, N\n  $$\n\n\n\n  \\item Compute conditional values of $Y_{x_{i}^{(k)}}^{(k)}=g\\left(\\boldsymbol{X}^{(k)} \\mid X_{i}=x_{i}^{(k)}\\right)$, and reorder them in ascending order $\\left\\{Y_{x_{i}^{(k)}}^{(1-\\mathrm{st})}, Y_{x_{i}^{(k)}}^{(2-\\mathrm{nd})}, \\cdots, Y_{x_{i}^{(k)}}^{(N-\\mathrm{th})}\\right\\}$\n\n\n  \\item \\label{itm:2}  Decide the $\\alpha$-th output value as conditional quantile: $q_{Y \\mid x_{i}^{(k)}}(\\alpha)=Y_{x_{i}^{(k)}}^{(\\alpha N-\\mathrm{th})}$\n\n\n\\end{enumerate}\n\n\\item \\textbf{Step 3}: To calculate QBSM accroding to \\eqref{eq:13} and \\eqref{eq:14}\n\n\\item \\textbf{Step 4}: To calculate normalized QBSM accroding to \\eqref{eq:16} and \\eqref{eq:17}\n\n\\end{itemize}\n\n\\noindent\nTo perform DLR method, $M$ typically be set between 50 to 100\\citep{kucherenko2017DifferentNumericalEstimators}. To perform brutal force simulation,\nsimply set M = N. The number function evaluation for a fixed $i$ is equal to $N=(dM + 1)$. In general, MC simulation performs efficiently for the calculation of QBSM. However, when deal with extreme quantiles, for instance, $\\alpha \\le 0.05$, the performane can be disappointing.\n\n\n", "meta": {"hexsha": "a914d60081522d70984700439e88fe74742120d1", "size": 3986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/06_mc.tex", "max_stars_repo_name": "Yuleii/yulei-thesis-QBSM-kw94", "max_stars_repo_head_hexsha": "bb882bc6c809331c370a4d6442c36ad67ccad498", "max_stars_repo_licenses": ["MIT"], "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/06_mc.tex", "max_issues_repo_name": "Yuleii/yulei-thesis-QBSM-kw94", "max_issues_repo_head_hexsha": "bb882bc6c809331c370a4d6442c36ad67ccad498", "max_issues_repo_licenses": ["MIT"], "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/06_mc.tex", "max_forks_repo_name": "Yuleii/yulei-thesis-QBSM-kw94", "max_forks_repo_head_hexsha": "bb882bc6c809331c370a4d6442c36ad67ccad498", "max_forks_repo_licenses": ["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.4333333333, "max_line_length": 644, "alphanum_fraction": 0.7082288008, "num_tokens": 1259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8438951045175642, "lm_q1q2_score": 0.6879707143844427}}
{"text": "%% ****** Start of file aapmtemplate.tex ****** %\n%%\n%%   This file is part of the files in the distribution of AAPM substyles for REVTeX4.2.\n%%   Version 4.2a of January 28, 2015.\n%%\n%\n% This is a template for producing documents for use with \n% the REVTEX 4.2 document class and the AAPM substyles.\n% \n% Copy this file to another name and then work on that file.\n% That way, you always have this original template file to use.\n\n\\documentclass[%\n draft,\n aapm,\n mph,%\n amsmath,amssymb,\n%preprint,%\n reprint,%\n%author-year,%\n%author-numerical,%\n]{revtex4-2}\n\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{upgreek}\n\n\\usepackage{siunitx}\n\n\\usepackage{mhchem}\n\n\\usepackage{xspace}\n\n% Defining string as labels of certain blocks.\n\n\\begin{document}\n\n% Use the \\preprint command to place your local institutional report number \n% on the title page in preprint mode.\n% Multiple \\preprint commands are allowed.\n%\\preprint{}\n\n\\title{Fuel-switching carbon prices — a bit of algebra} %Title of paper\n\n% repeat the \\author .. \\affiliation  etc. as needed\n% \\email, \\thanks, \\homepage, \\altaffiliation all apply to the current author.\n% Explanatory text should go in the []'s, \n% actual e-mail address or url should go in the {}'s for \\email and \\homepage.\n% Please use the appropriate macro for the type of information\n\n% \\affiliation command applies to all authors since the last \\affiliation command. \n% The \\affiliation command should follow the other information.\n\n\\author{Philipp C. Verpoort}\n%\\email[]{Your e-mail address}\n%\\homepage[]{Your web page}\n%\\thanks{}\n%\\altaffiliation{}\n\n% Collaboration name, if desired (requires use of superscriptaddress option in \\documentclass). \n% \\noaffiliation is required (may also be used with the \\author command).\n%\\collaboration{}\n%\\noaffiliation\n\n%\\date{\\today}\n\n\\input{cmds}\n\n\\maketitle %\\maketitle must follow title, authors, abstract\n\n% Body of paper goes here. Use proper sectioning commands. \n% References should be done using the \\cite, \\ref, and \\label commands\n\\section{Formular for switching price}\n\nThe total cost $C_X$ of a fuel $X$ is defined as\n\\begin{equation}\n    C_X = C^0_X + \\prc * e_X \\punc,\n\\end{equation}\nwhere $C^0_X$ is the direct cost (independent of carbon cost) in \\si{\\$}, $\\prc$ is the carbon price in \\si{\\$\\per\\tonne_{\\ce{CO2}}}, and $e_X$ are the emissions (or carbon intensity) in \\si{\\tonne_{\\ce{CO2}}\\per\\kWh}. We define the $Y$-to-$X$ fuel-switching cost $\\Delta C_{YX}$ (i.e.~the cost incurred in switching from fuel $Y$ to fuel $X$) as\n\\begin{align}\n    \\Delta C_{YX} &= C_X - C_Y \\\\\n                  &= C^0_X - C^0_Y + \\prc * (e_X - e_Y) \\punc.\n\\end{align}\nThe $Y$-to-$X$ fuel-switching carbon price $\\prYX$ (i.e.~carbon price above which it is economically incentivised to switch from fuel $Y$ to fuel $X$) is defined as\n\\begin{align}\n                    & \\Delta C_{YX} (\\prc = \\prYX) = 0 \\punc, \\\\\n\\intertext{and hence it is}\n                    &~~~ C^0_X - C^0_Y + \\prYX * (e_X - e_Y) = 0 \\\\\n  \\Leftrightarrow   &~~~ \\prYX = \\frac{C^0_X - C^0_Y}{e_Y - e_X} \\punc.\n\\end{align}\n\n\\section{Green-blue switching}\n\nWe now consider the fuels $X$ and $Y$ to be one of $\\{g, b, r\\}$, which refer to green, blue, and reference (e.g.~natural gas). In that case we have three switching prices:\n\\begin{align}\n    \\prg    &=     \\frac{C^0_g - C^0_r}{e_r - e_g} \\punc,\\\\\n    \\prb    &=     \\frac{C^0_b - C^0_r}{e_r - e_b} \\punc,\\\\\n    \\prbg   &=     \\frac{C^0_g - C^0_b}{e_b - e_g} \\punc.\n\\end{align}\nWe can rewrite the equations for $\\prg$ and $\\prb$ as\n\\begin{align}\n    C^0_g &= C^0_r + \\prg * (e_r - e_g) \\quad\\text{and} \\\\\n    C^0_b &= C^0_r + \\prg * (e_r - e_b) \\punc,\n\\end{align}\nand hence it is\n\\begin{align}\n    C^0_g - C^0_b &= \\prg (e_r - e_g) - \\prb (e_r - e_b) \\\\\n                  &= \\prb \\, e_b - \\prg \\, e_g + (\\prg - \\prb) \\, e_r \\punc.\n\\end{align}\nWe can substitute that back into the equation from above for $\\prbg$, which yields:\n\\begin{align}\n    \\prbg &= \\frac{\\prb \\, e_b - \\prg \\, e_g + (\\prg - \\prb) \\, e_r}{e_b - e_g} \\\\\n    &= \\frac{\\prb \\, e_b + \\prb \\, e_g - \\prb \\, e_g - \\prg \\, e_g}{e_b - e_g}\\\\ &~~~~+ \\frac{(\\prg - \\prb) \\, e_r}{e_b - e_g} \\\\\n    &= \\prb + (\\prb - \\prg) \\frac{e_g}{e_b-e_g} \\\\ &~~~~+ (\\prg - \\prb) \\frac{e_r}{e_b-e_g} \\\\\n    &= \\prb + (\\prg - \\prb) \\underbrace{\\frac{e_r - e_g}{e_b - e_g}}_{=: \\alpha} \\\\\n    &= \\prb + \\alpha * (\\prg - \\prb) \\punc.\n\\end{align}\n\n\\section{Possible cases}\nLet us assume that green hydrogen is always cleaner than blue and that both are cleaner than the reference (e.g.~natural gas). Hence, it is $e_g < e_b < e_r$. From $e_r > e_b \\Leftrightarrow e_r - e_g > e_b - e_g$ and with $e_b < e_g$ we find that $\\alpha > 1$. We therefore find the follwing cases depending on the relative values of $\\prg$ and $\\prb$:\n\n\\vspace{.2cm}\n\\noindent\\textbf{Case 1: $\\prg > \\prb$}\n\\begin{align}\n    \\prbg &~=~ \\prb + \\alpha * \\underbrace{(\\prg - \\prb)}_{>\\,0} \\\\\n            & \\overset{\\alpha>1}{>} \\prb + \\prg - \\prb = \\prg \\punc.\n\\end{align}\nHence: $\\prbg > \\prg > \\prb$.\n\n\\vspace{.2cm}\n\\noindent\\textbf{Case 2: $\\prg < \\prb$}\n\\begin{align}\n    \\prbg &~=~ \\prb + \\alpha * \\underbrace{(\\prg - \\prb)}_{<\\,0} \\\\\n            & \\overset{\\alpha>1}{<} \\prb + \\prg - \\prb = \\prg \\punc.\n\\end{align}\nHence: $\\prbg < \\prg < \\prb$.\n\n\\vspace{.2cm}\n\\noindent\\textbf{Case 3: $\\prg = \\prb$}\n\\begin{align}\n    \\prbg &~=~ \\prb + \\alpha * \\underbrace{(\\prg - \\prb)}_{=\\,0} = \\prb\\punc.\n\\end{align}\nHence: $\\prbg = \\prb = \\prg$.\n\n\n\n\\end{document}\n%\n% ****** End of file aapmtemplate.tex ******\n", "meta": {"hexsha": "cfddc50c07253c27ded5f3c00d0d661cf9ecdc17", "size": 5566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/fscp-algebra/main.tex", "max_stars_repo_name": "PhilippVerpoort/blue-green-H2", "max_stars_repo_head_hexsha": "a9b9bd27d2459df0f14e719a466af5ed6318d7e0", "max_stars_repo_licenses": ["MIT"], "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/fscp-algebra/main.tex", "max_issues_repo_name": "PhilippVerpoort/blue-green-H2", "max_issues_repo_head_hexsha": "a9b9bd27d2459df0f14e719a466af5ed6318d7e0", "max_issues_repo_licenses": ["MIT"], "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/fscp-algebra/main.tex", "max_forks_repo_name": "PhilippVerpoort/blue-green-H2", "max_forks_repo_head_hexsha": "a9b9bd27d2459df0f14e719a466af5ed6318d7e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-19T16:11:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T16:11:53.000Z", "avg_line_length": 36.3790849673, "max_line_length": 353, "alphanum_fraction": 0.632231405, "num_tokens": 1983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.6879707068078201}}
{"text": "\\section{Introduction to Artificial Neural Network}\n\n\n\n\\subsection{Autodiff}\n\n\\cindex{Autodiff} is neither a numerical nor symbolic differentiation. It use numerical method calculation and use symbolic rules for differentiation, so it is partly symbolic and partly numerical. See \\cite{GunesBaydin2018} for more details.\n\n\nOne example is $f(x_1, x_2) = \\log{x_1} + x_1 x_2 - \\sin{x_2}$. The computation graph is:\n\n\\begin{figure}[H]\n\\centering\t\n\\begin{tikzpicture}\n    \\node (x2) at (0,0) {$x_2$};\n    \\node (x1) at (0,2) {$x_1$};\n    \\node (v0) at (3,0) {$v_0 = x_2$};\n    \\node (v_1) at (3,2) {$v_{-1} = x_1$};\n    \\node (v2) at (6,1) {$v_2 = v_{-1} v_0$};\n    \\node (v1) at (6,2) {$v_1 = \\log{v_{-1}}$};\n    \\node (v3) at (9,0) {$v_3 = \\sin{v_0}$};\n    \\node (v4) at (9,2) {$v_4 = v_1 + v_2$};\n    \\node (v5) at (12,1) {$v_5 = v_4 + v_3$};\n    \\node (final) at (15,1) {$f(x_1,x_2)$};\n    \\draw [-latex] (x2) -- (v0);\n    \\draw [-latex] (v0) -- (v3);\n    \\draw [-latex] (v3) -- (v5);  \n    \\draw [-latex] (x1) -- (v_1);\n    \\draw [-latex] (v_1) -- (v1);  \n    \\draw [-latex] (v1) -- (v4);\n    \\draw [-latex] (v4) -- (v5);  \n    \\draw [-latex] (v_1) -- (v2);\n    \\draw [-latex] (v2) -- (v4);\n    \\draw [-latex] (v0) -- (v2);\n    \\draw [-latex] (v5) -- (final);\n\\end{tikzpicture}\n\\caption{$f(x_1, x_2) = \\log{x_1} + x_1 x_2 - \\sin{x_2}$}\n\\end{figure}\n\n\nIn general there are two autodiff methods: forward mode and backpropagation. In forward mode, the derivative is the intermediary nodes against all input nodes while in backpropagation the derivative is the final node against all intermediary nodes.\n\n\n\n\\subsubsection{Forward Mode}\n\nThere are $1+n$ passes in forward mode:\n\\begin{enumerate}\n    \\item a forward evaluation of all node values. Table \\ref{forwardprimaltracetable} shows the forward example.\n    \\item $n$ forward derivative calculation for all $n$ input features. For the $i$-th input feature, the derivatives of all $\\dot{v}$ is calculated in Table \\ref{forwardtangenttrace}.\n\\end{enumerate}\n\n\\begin{table}[H]\n\\centering\n    \\begin{tabular}{lll}\n        $v_{-1}$ & $= x_1$ & $ = 2$ \\\\\n        $v_0$ & $= x_2$ & $=5$ \\\\\n        $v_1$ & $=\\log{v_{-1}}$ & $= \\log{2}$ \\\\\n        $v_2$ & $=v_{-1} \\times v_0$ & $= 2 \\times 5 $\\\\\n        $v_3$ & $=\\sin{v_0}$ & $=\\sin{5}$\\\\\n        $v_4$ & $=v_1 + v_2$ & $=0.693+10$ \\\\\n        $v_5$ & $=v_4 - v_3$ & $=10.693 + 0.959$ \\\\\n        $y$ & $=v_5$ & $=11.652$ \\\\\n    \\end{tabular}\n\\caption{Forward Primal Trace}\n\\label{forwardprimaltracetable}\n\\end{table}\n\n\n\\begin{table}[H]\n\\centering\n    \\begin{tabular}{lll}\n        $\\dot{v}_{-1}$ & $= \\dot{x}_1$ & $ = 1$ \\\\\n        $\\dot{v}_0$ & $= \\dot{x}_2$ & $=0$ \\\\\n        $\\dot{v}_1$ & $= \\displaystyle \\frac{\\dot{v}_{-1}}{v_{-1}}$ & $=\\displaystyle \\frac{1}{2}$ \\\\\n        $\\dot{v}_2$ & $=\\dot{v}_{-1} \\times v_0 + v_{-1} \\times \\dot{v}_0$ & $= 1 \\times 5 + 0 \\times 2$\\\\\n        $\\dot{v}_3$ & $=\\dot{v}_0 \\times \\cos{v_0}$ & $=0 \\times \\cos{5}$ \\\\\n        $\\dot{v}_4$ & $=\\dot{v}_1 + \\dot{v}_2$ & $= 0.5 + 5$ \\\\\n        $\\dot{v}_5$ & $=\\dot{v}_4 - \\dot{v}_3$ & $= 5.5 - 0$ \\\\\n        $\\dot{y}$ & $=\\dot{v}_5$ & $= 5.5$ \\\\\n    \\end{tabular}\n\\caption{Forward Tangent (Derivative) Trace}\n\\label{forwardtangenttrace}\n\\end{table}\n\nForward mode is expensive because it needs to run a pass for each input feature.\n\n\n\\subsubsection{Backpropogation}\n\n\\cindex{Backpropagation} only needs 2 passes over the calculation graph:\n\\begin{enumerate}\n    \\item a forward evaluation of all node values. The same as forward mode. Table \\ref{forwardprimaltracetable} shows the forward example.\n    \\item a backward derivative calculation of all nodes in calculation graph. Table \\ref{reverseadjointtrace} shows the backward example.\n\\end{enumerate}\n\nIn the backward derivative calculation, all derivatives are calculated against final result $y$. According to calculas, we have:\n\\begin{equation}\n    \\dpd{y}{v_0} = \\dpd{y}{v_2} \\dpd{v_2}{v_0} + \\dpd{y}{v_3} \\dpd{v_3}{v_0}\n\\end{equation}\n\nLet $\\bar{v} = \\pd{y}{v}$. We have:\n\\begin{equation}\n    \\bar{v}_0 = \\bar{v}_2 \\dpd{v_2}{v_0} + \\bar{v}_3 \\dpd{v_3}{v_0}\n\\end{equation}\n\nSo the final result could calculated by backward propagation. Table \\ref{reverseadjointtrace} gives an example.\n\n\\begin{table}[H]\n\\centering\n    \\begin{tabular}{llll}\n        $\\bar{v}_5$ & $=\\bar{y}$ && $= 1$ \\\\\n        $\\bar{v}_4$ & $=\\bar{v}_5 \\pd{v_5}{v_4}$ & $=\\bar{v}_5 \\times 1$ & $=1$ \\\\\n        $\\bar{v}_3$ & $=\\bar{v}_5 \\pd{v_5}{v_3}$ & $=\\bar{v}_5 \\times (-1)$ & $=-1$ \\\\\n        $\\bar{v}_2$ & $=\\bar{v}_4 \\pd{v_4}{v_2}$ & $=\\bar{v}_4 \\times 1$ & $=1$ \\\\\n        $\\bar{v}_1$ & $=\\bar{v}_4 \\pd{v_4}{v_1}$ & $=\\bar{v}_4 \\times 1$ & $=1$ \\\\\n        $\\bar{v}_0$ & $=\\bar{v}_3 \\pd{v_3}{v_0}$ & $=\\bar{v}_3 \\times \\cos{v_0}$ & $=-0.284$ \\\\\n        $\\bar{v}_{-1}$ & $=\\bar{v}_2 \\pd{v_2}{v_{-1}}$ & $=\\bar{v}_2 \\times v_0$ & $=5$ \\\\\n        $\\bar{v}_0$ & $=v_0 + \\bar{v}_2 \\pd{v_2}{v_0}$ & $=\\bar{v}_0 +\\bar{v}_2 \\times v_{-1}$ & $=1.716$ \\\\\n        $\\bar{v}_{-1}$ & $=v_{-1} + \\bar{v}_1 \\pd{v_1}{v_{-1}}$ & $=\\bar{v}_{-1} + \\frac{\\bar{v}_1}{v_{-1}}$ & $=5.5$ \\\\\n    \\end{tabular}\n\\caption{Reverse Adjoint (Derivative) Trace}\n\\label{reverseadjointtrace}\n\\end{table}\n\n\n\n\n\n\n% Gradient Descent\n\\section{Gradient Descent}\n\n\\subsection{Gradient Descent Classification}\n\n\\cindex{Gradient Descent} is a numeric optimization method to calculate the minimum value of a function. For a give function $f(x)$ with gradient everywhere, if we choose $\\alpha$ small enough, it is possible that $f(x') < f(x)$ where:\n\n\\begin{equation}\\label{gradientdescentdefinition}\n    x' = x - \\alpha \\nabla_x f\n\\end{equation}\n\n\n$\\alpha$ is called \\cindex{learning rate}. Please be noted that the $x$ here is a vector of all input samples.\n\n\n\\cindex{Batch Gradient Descent} calculate the gradient of the cost function for the entire training set. So it is slow, and sometimes cannot be fit into the main memory.\n\n\\cindex{Stochastic Gradient Descent} calculate the gradient for every single training sample. So it fluctuate. \n\n\n\\cindex{Mini-batch Gradient Descent} calculate the gradient for every batch of $n$ samples. It could use GPU to accelerate the training, and it is less volatile than stochastic gradient descent.\n\nSo mini-batch gradient descent is the best of all choices. However it still has the following limitations:\n\\begin{enumerate}\n    \\item The learning rate cannot be too small or too big.\n    \\item \\cindex{learning rate schedule} is used to gradually reduce the learning rate, which mimics the \\cindex{annealing}. However the training data may not match the learning schedule. \n    \\item One learning rate is applied to all data. The data could be sparse or dense.\n    \\item Local minimum is usually not a problem. The real problem is the plateau around \\cindex{saddle points}. The gradient is flat and takes long time to move away.\n\\end{enumerate}\n\nSo optimization algorithms is needed for an efficient gradient descent calculation.\n\n\\subsection{Gradient Descent Optimization Algorithms}\n\nThe idea of optimizing gradient descent is to change $\\alpha \\nabla_x f$ in Equation \\eqref{gradientdescentdefinition}. We can change all of them, such as in Momentum and NAG algorithm, or change $\\alpha$, such as in Adagrad, Adadelta, RMSprop, or change $\\nabla_x f$, such as in Adam, AdaMax, Nadam. The popular optimization algorithms are summarized in \\cite{Ruder2016}. The relationship among all these optimization algorithm is in Figure ~\\ref{gradientdescentoptimizationalgorithmrelationship}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.5]{images/relation_among_gradient_descent}\n    \\caption{Relation among Gradient Descent Algorithms}\n    \\label{gradientdescentoptimizationalgorithmrelationship}\n\\end{figure}\n\n\n\\subsubsection{Momentum}\n\n\\cindex{Momentum}\\cite{Qian1999} takes a weighted average of all gradient:\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - m_t \\\\\n        m_t &= \\beta m_{t-1} + (1-\\beta) \\nabla_{\\theta_t} J(\\theta_t)\n    \\end{aligned}\n\\end{equation}\n\n$\\alpha=0.9$ for most of the cases. The momentum term increases if gradients point in the same direction and reduces updates when gradients change direction. So it has momentum when moving towards the same direction, and it converges fast.\n\n\n\n\n\n\\subsubsection{NAG}\n\n\\cindex{Nesterov Accelerated Gradient}\\cite{NESTEROV1983}, or \\cindex{NAG}, is a look ahead calculation. Since $\\theta_t$ will be reduced by a gradient every time: $\\theta_{t+2} = \\theta_{t+1} - m_{t+1} = \\theta_t - m_t - m_{t+1}$, it replaces $\\nabla_{\\theta_t} J(\\theta_t)$ by $\\nabla_{\\theta_t} J(\\theta_t - \\beta m_{t-1})$:\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - m_t \\\\\n        m_t &= \\beta m_{t-1} + (1-\\beta) \\nabla_{\\theta_t} J(\\theta_t - \\beta m_{t-1})\n    \\end{aligned}\n\\end{equation}\n\n\n\n\n\\subsubsection{Adagrad}\n\n\\cindex{Adagrad}\\cite{Duchi2012} performs large update for infrequent and small update for frequent parameters:\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - \\frac{\\alpha}{\\sqrt{G_t + \\epsilon}}  \\nabla_{\\theta_t} J(\\theta_t) \\\\\n        G_t &= G_{t-1} + \\left(\\nabla_{\\theta_t} J(\\theta_t) \\right)^2\n    \\end{aligned}\n\\end{equation}\n\n$\\epsilon$ is added to avoid division by zero. Usually $G_0 = 0$, $\\alpha = 0.01$, $\\epsilon = 10^{-8}$. Because $G_t$ keeps accumulating, eventually it will become too big for the algorithm to be effective.\n\n\n\n\n\\subsubsection{Adadelta}\n\\cindex{Adadelta}\\cite{Zeiler2012} fixes the problem of Adagrad. It is a decay version of Adagrad:\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - \\frac{\\sqrt{D_{t-1} + \\epsilon}}{\\sqrt{G_t + \\epsilon}}  \\nabla_{\\theta_t} J(\\theta_t) \\\\\n        G_t &= \\beta G_{t-1} + (1-\\beta) \\left(\\nabla_{\\theta_t} J(\\theta_t) \\right)^2 \\\\\n        D_t &= \\beta D_{t-1} + (1-\\beta) (\\theta_t - \\theta_{t-1})^2\n    \\end{aligned}\n\\end{equation}\n\nUsually $G_0 = 0$, $D_0 = 0$, $\\beta = 0.9$, $\\epsilon = 10^{-6}$.\n\n\\subsubsection{RMSprop}\n\n\\cindex{RMSprop} is unpublished. It is a simplified version of Adadelta that $D_t = 0$:\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - \\frac{\\alpha}{\\sqrt{G_t + \\epsilon}}  \\nabla_{\\theta_t} J(\\theta_t) \\\\\n        G_t &= \\beta G_{t-1} + (1-\\beta) \\left(\\nabla_{\\theta_t} J(\\theta_t) \\right)^2 \\\\\n    \\end{aligned}\n\\end{equation}\n\nUsually $G_0 = 0$, $\\alpha = 0.001$, $\\beta = 0.9$, $\\epsilon = 10^{-6}$.\n\n\n\n\n\\subsubsection{Adam}\n\n\\cindex{Adaptive Moment Estimation}\\cite{Kingma2015}, or \\cindex{Adam}, is yet another adaptive method:\n\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - \\frac{\\alpha}{\\sqrt{\\displaystyle \\frac{G_t}{1-(\\beta_2)^t}} + \\epsilon} \\frac{m_t}{1-(\\beta_1)^t}  \\\\\n        m_t &= \\beta_1 m_{t-1} + (1-\\beta_1) \\nabla_{\\theta_t} J(\\theta_t) \\\\\n        G_t &= \\beta_2 G_{t-1} + (1-\\beta_2) \\left(\\nabla_{\\theta_t} J(\\theta_t) \\right)^2\n    \\end{aligned}\n\\end{equation}\n\nUsually $G_0 = 0$, $\\alpha = 0.001$, $\\beta_1 = 0.9$, $\\beta_2 = 0.999$, $\\epsilon = 10^{-8}$.\n\n\n\n\n\n\\subsubsection{AdaMax}\n\\cindex{AdaMax}\\cite{Kingma2015} is a infinite norm version of Adam. Adam use $l_2$ norm for $G$. For infinite norm:\n\\begin{equation}\n    \\begin{aligned}\n        G_t &= \\beta_2^\\infty G_{t-1} + (1-\\beta_2^\\infty ) \\norm{\\nabla_{\\theta_t} J(\\theta_t)}^\\infty  \\\\\n        &= \\max \\left(\\beta_2 G_{t-1}, \\norm{\\nabla_{\\theta_t} J(\\theta_t)} \\right)\n    \\end{aligned}\n\\end{equation}\n\nBecause $G_t > 0$ in AdaMax, $\\epsilon$ is no longer useful. So the equation could be simplified:\n\n\\begin{equation}\n    \\begin{aligned}\n        \\theta_{t+1} &= \\theta_t - \\frac{\\alpha}{G_t}  m_t \\\\\n        m_t &= \\beta_1 m_{t-1} + (1-\\beta_1) \\nabla_{\\theta_t} J(\\theta_t) \\\\\n        G_t &= \\max \\left(\\beta_2 G_{t-1}, \\norm{\\nabla_{\\theta_t} J(\\theta_t)} \\right)\n    \\end{aligned}\n\\end{equation}\n\nUsually $G_0 = 0$, $\\alpha = 0.001$, $\\beta_1 = 0.9$, $\\beta_2 = 0.999$.\n\n\n\\subsubsection{Nadam}\n\n\\cindex{Nadam}\\cite{Dozat2016} combines Adam and NAG. Adam could be written as:\n\\begin{equation}\n    \\theta_{t+1} = \\theta_t - \\frac{\\alpha}{\\sqrt{\\displaystyle \\frac{G_t}{1-(\\beta_2)^t}} + \\epsilon} \\left(\\beta_1 \\frac{m_{t-1}}{1-(\\beta_1)^{t-1}} + \\frac{1-\\beta_1}{1-(\\beta_1)^t} \\nabla_{\\theta_t} J(\\theta_t) \\right)\n\\end{equation}\n\nLike NAG, Nadam changes Adam's $t-1$ version of $\\displaystyle \\frac{m_{t-1}}{1-(\\beta_1)^{t-1}}$ to current $t$ version $\\displaystyle \\frac{m_t}{1-(\\beta_1)^t}$:\n\\begin{equation}\n    \\begin{aligned}\n            \\theta_{t+1} &= \\theta_t - \\frac{\\alpha}{\\sqrt{\\displaystyle \\frac{G_t}{1-(\\beta_2)^t}} + \\epsilon} \\left(\\beta_1 \\frac{m}{1-(\\beta_1)^t} + \\frac{1-\\beta_1}{1-(\\beta_1)^t} \\nabla_{\\theta_t} J(\\theta_t) \\right)  \\\\\n        m_t &= \\beta_1 m_{t-1} + (1-\\beta_1) \\nabla_{\\theta_t} J(\\theta_t) \\\\\n        G_t &= \\beta_2 G_{t-1} + (1-\\beta_2) \\left(\\nabla_{\\theta_t} J(\\theta_t) \\right)^2    \n    \\end{aligned}\n\\end{equation}\n\nUsually $G_0 = 0$, $m_0 = 0$, $\\alpha = 0.002$, $\\beta_1 = 0.9$, $\\beta_2 = 0.999$, $\\epsilon = 10^{-7}$.\n\n\n\n\n\n", "meta": {"hexsha": "68ca2cdc4b516560aa52d3628a70afa67369d8a6", "size": 12997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/deep_neural_network/dnn.1.intro.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/deep_neural_network/dnn.1.intro.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/deep_neural_network/dnn.1.intro.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": 42.1980519481, "max_line_length": 498, "alphanum_fraction": 0.6332230515, "num_tokens": 4734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6879707020068628}}
{"text": "\\subsection{Lattices}\\label{subsec:lattices}\n\n\\begin{definition}\\label{def:semilattice}\\mcite[3]{Gratzer1978}\n  Lattices are \\hyperref[def:partially_ordered_set]{partially ordered sets} in which \\hyperref[def:partially_ordered_set_extremal_points/supremum_and_infimum]{suprema and infima} are taken as basic operations called \\enquote{joins} and \\enquote{meets}. See \\fullref{rem:lattice_operation_etymology} for a discussion of the operation names. This shifts the focus from ordering to operations, i.e. from predicates to functions.\n\n  Joins and meets may also be defined axiomatically as binary operations rather than via some partial order, however this restricts us to taking suprema of finite sets and prevents us from taking the supremum of an arbitrary set. In other words, it is possible for the order to carry more information than joins and meets. See \\fullref{thm:binary_lattice_operations/new_lattice} for a discussion. Unless explicitly noted otherwise, we assume that lattices have their partial order defined.\n\n  \\begin{thmenum}[series=def:semilattice]\n    \\thmitem{def:semilattice/join} A \\term{join-semilattice} is a \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded from above} partially ordered set in which every finite supremum exists. The operation itself is denoted by \\( \\vee \\) and referred to as \\term{join} and rather than supremum. In contrast to suprema, joins are usually written in \\hyperref[rem:first_order_formula_conventions/infix]{infix} notation, e.g. \\( x \\vee y \\vee z \\) rather than \\( \\sup\\set{ x, y, z } \\).\n\n    \\thmitem{def:semilattice/meet} Analogously, a \\term{meet-semilattice} is a partially ordered set in which every finite infimum exists. The infimum is denoted by \\( \\wedge \\) and called \\term{meet}.\n\n    \\thmitem{def:semilattice/bounded} A \\term{bounded semilattice} is a semilattice that is \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded} as a \\hyperref[def:partially_ordered_set]{partially ordered set}, either \\hi{from below} for join-semilattices or \\hi{from above} for meet-semilattices.\n\n    \\thmitem{def:semilattice/complete}\\mcite[24]{Gratzer1978} A semilattice is said to be \\term{complete} if the corresponding operation is defined for arbitrary sets rather than only finite ones.\n\n    Finite semilattices are clearly complete, as well as bounded semilattices.\n\n    \\thmitem{def:semilattice/lattice} A \\term{lattice} is a partially ordered set which is both a join-semilattice and a meet-semilattice. It is called \\term{bounded} if both semilattices are bounded, i.e. if the partially ordered set itself is \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded}. It is called \\term{complete} if both semilattices are complete.\n\n    \\thmitem{def:semilattice/distributive_lattice}\\mcite[30]{Gratzer1978} A lattice is said to be \\term{distributive} if the following two conditions hold:\n    \\begin{align}\n      x \\vee (y \\wedge z) &= (x \\vee y) \\wedge (x \\vee z) \\label{eq:def:semilattice/distributive_lattice/finite/join_over_meet} \\\\\n      x \\wedge (y \\vee z) &= (x \\wedge y) \\vee (x \\wedge z) \\label{eq:def:semilattice/distributive_lattice/finite/meet_over_join}.\n    \\end{align}\n\n    If the lattice is \\hyperref[def:semilattice/complete]{complete}, the above conditions are not enough. A complete lattice \\( X \\) it is said to be \\term{distributive} if any of the following more general distributive axioms hold for every \\( x \\in X \\) and \\hyperref[def:cartesian_product/indexed_family]{family} \\( \\seq{ y_k }_{k \\in \\mscrK} \\subseteq X \\):\n    \\begin{align}\n      x \\vee \\parens*{ \\bigwedge_{k \\in \\mscrK} y_k } &= \\bigwedge_{k \\in \\mscrK} \\parens{ x \\vee y_k } \\label{eq:def:semilattice/distributive_lattice/arbitrary/join_over_meet} \\\\\n      x \\wedge \\parens*{ \\bigvee_{k \\in \\mscrK} y_k } &= \\bigvee_{k \\in \\mscrK} \\parens{ x \\wedge y_k } \\label{eq:def:semilattice/distributive_lattice/arbitrary/meet_over_join}\n    \\end{align}\n  \\end{thmenum}\n\n  Lattices have the following metamathematical properties:\n  \\begin{thmenum}[resume=def:semilattice]\n    \\thmitem{def:semilattice/theory} The language of the theory of lattices consists of the language of the \\hyperref[def:partially_ordered_set/theory]{theory of partially ordered sets} with the addition of the binary infix functional symbols \\( \\vee \\) and \\( \\wedge \\). If we only want to restrict ourselves to semilattices, we can add only one of the two operations as functional symbols. If we wish to study \\hyperref[def:semilattice/bounded]{bounded lattices}, as it is often done, we must also add the constants \\( \\top \\) and \\( \\bot \\).\n\n    For meet-semilattices, we add the following axiom schema to the theory to ensure compatibility between infima and meets (we use \\( \\mathbin\\& \\) to denote \\hyperref[def:propositional_language/connectives/conjunction]{logical conjunction} to avoid symbol collision with meets):\n    \\begin{equation}\\label{eq:def:semilattice/theory/meet_compat}\n      \\parens[\\Big]{ \\xi \\wedge \\eta \\doteq \\alpha } \\leftrightarrow \\parens[\\Big]{ \\alpha \\leq \\xi \\mathbin\\& \\alpha \\leq \\eta \\mathbin\\& \\qforall \\alpha ((\\alpha \\leq \\xi \\mathbin\\& \\alpha \\leq \\eta) \\rightarrow \\alpha \\leq \\alpha) }\n    \\end{equation}\n    and, for bounded meet-semilattices, the following axiom to ensure that \\( \\top \\) is indeed the maximum:\n    \\begin{equation}\\label{eq:def:semilattice/theory/bottom_compat}\n      \\qforall \\xi (\\xi \\leq \\top).\n    \\end{equation}\n\n    Analogous axioms need to be added for join-semilattices.\n\n    We cannot properly express the theory of complete (semi)lattices as an extension of this theory since we must define join and meet as unary operations on subsets of the domain rather than binary operations on members of the domain. Complete semilattices can instead be defined within \\hyperref[def:zfc]{\\logic{ZFC}}.\n\n    \\thmitem{def:semilattice/submodel} Unlike for partially ordered sets, whose submodels are discussed in \\fullref{def:partially_ordered_set/submodel}, not every subset of a semilattice is a sub-semilattice because \\( \\vee \\) and \\( \\wedge \\) are now regarded as functional symbols. A sub-(semi)lattice must be closed under joins and meets. The axiom \\eqref{eq:def:semilattice/theory/meet_compat} is not a positive formula, but does not cause trouble itself as it merely specifies compatibility of \\( \\leq \\) and \\( \\wedge \\).\n\n    For bounded semilattices, the relevant constants should be present in any bounded sub-semilattice.\n\n    \\thmitem{def:semilattice/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial join-semilattice} and the trivial meet-semilattice are the empty set. The trivial bounded join-semilattice is the singleton \\( \\set{ \\bot } \\) and the trivial bounded meet-semilattice is \\( \\set{ \\top } \\).\n\n    The trivial bounded lattice satisfies \\( \\top = \\bot \\), which implies that it consists of one element.\n\n    Note that the elements \\( \\top \\) and \\( \\bot \\) formally differ between different semilattices, however all trivial bounded lattices are isomorphic and hence it makes sense to speak of \\enquote{the} bounded lattice.\n\n    \\thmitem{def:semilattice/homomorphism} \\hyperref[def:first_order_homomorphism]{Homomorphisms} between (semi)lattices are the monotone maps that preserve joins, meets and constants.\n\n    \\begin{figure}[h]\n      \\centering\n      \\includegraphics[page=1]{output/def__semilattice.pdf}\n      \\caption{A monotone map between lattices, which is not a lattice homomorphism}\n      \\label{fig:def:semilattice/homomorphism/monotone_map_not_homomorphism}\n    \\end{figure}\n\n    As we shall see in \\fullref{thm:lattice_homomorphism_is_monotone}, the requirement of monotonicity is redundant.\n\n    \\thmitem{def:semilattice/category} The \\hyperref[def:category_of_small_first_order_models]{categories of \\( \\mscrU \\)-small models} for (semi)lattices are full subcategories of \\hyperref[def:partially_ordered_set/category]{\\( \\ucat{Pos} \\)}. We only give a special name for the category \\( \\ucat{Lat} \\) of lattices.\n\n    \\thmitem{def:semilattice/duality} The \\hyperref[def:partially_ordered_set/opposite]{principle of duality for partially ordered sets} holds for lattices if we also swap the binary operations \\( \\vee \\) and \\( \\wedge \\).\n\n    If the lattice is bounded, we must additionally swap the constants \\( \\top \\) and \\( \\bot \\).\n\n    If the lattice is bounded from only one side, the principle of duality does not hold unless we restrict ourselves to formulas that do not contain the constants.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:lattice_operation_etymology}\n  The terms \\hyperref[def:semilattice/join]{\\enquote{join}} for \\( \\vee \\) and \\hyperref[def:semilattice/meet]{\\enquote{meet}} for \\( \\wedge \\) are notoriously difficult to remember. A helpful accident is the ability to write \\enquote{meet} as \\enquote{\\( \\wedge \\wedge \\)eet}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:binary_lattice_operations}\n  Let \\( (P, \\leq) \\) be a partially ordered set.\n\n  \\begin{thmenum}\n    \\thmitem{thm:binary_lattice_operations/semilattices} If it is a \\hyperref[def:semilattice/join]{join-semilattice} (resp. \\hyperref[def:semilattice/meet]{meet-semilattice}), then \\( \\vee \\) (resp. \\( \\wedge \\)) is \\hyperref[def:magma/associative]{associative}, \\hyperref[def:magma/commutative]{commutative} and \\hyperref[def:magma/idempotent]{idempotent} when considered as a binary operation.\n\n    \\thmitem{thm:binary_lattice_operations/identity} If \\( P \\) is a (semi)lattice, the constants act as \\hyperref[def:monoid]{monoid identities}. That is, for each \\( x \\in P \\),\n    \\begin{align}\n      x \\vee \\bot = x \\label{eq:thm:binary_lattice_operations/identity/join} \\\\\n      x \\wedge \\top = x \\label{eq:thm:binary_lattice_operations/identity/meet}\n    \\end{align}\n\n    \\thmitem{thm:binary_lattice_operations/absorption} If \\( P \\) is a lattice, then the following absorption laws hold:\n    \\begin{align}\n      x \\vee (x \\wedge y) &= x \\label{eq:thm:binary_lattice_operations/absorption/join} \\\\\n      x \\wedge (x \\vee y) &= x \\label{eq:thm:binary_lattice_operations/absorption/meet}.\n    \\end{align}\n\n    \\thmitem{thm:binary_lattice_operations/compatibility} The following conditions for compatibility with \\( \\leq \\) hold:\n    \\begin{align}\n      x \\leq y &\\T{if and only if} x \\vee y = y \\label{eq:thm:binary_lattice_operations/compatibility/join} \\\\\n      x \\leq y &\\T{if and only if} x \\wedge y = x \\label{eq:thm:binary_lattice_operations/compatibility/meet}.\n    \\end{align}\n\n    \\thmitem{thm:binary_lattice_operations/new_lattice} If \\( A \\) is an arbitrary \\hyperref[def:set]{set} and if \\( \\vee \\) is a binary operation that is associative, commutative and idempotent (the conclusion of \\fullref{thm:binary_lattice_operations/semilattices}), then \\( (A, \\leq) \\) is a join-semilattice with an ordering defined by \\eqref{eq:thm:binary_lattice_operations/compatibility/join}. If there exists a distinguished element \\( \\bot \\) such that \\eqref{eq:thm:binary_lattice_operations/identity/meet} holds, then \\( (A, \\leq) \\) is bounded.\n\n    A completely analogous statement holds for meet-semilattices.\n\n    If \\( (A, \\leq) \\) is both a join-semilattice and meet-semilattice and if \\( \\vee \\) and \\( \\wedge \\) satisfy the absorption conditions \\eqref{eq:thm:binary_lattice_operations/absorption/join} and \\eqref{eq:thm:binary_lattice_operations/absorption/meet}, then \\( (A, \\leq) \\) is a lattice. Furthermore, proving idempotence for \\( \\vee \\) or \\( \\wedge \\) is unnecessary because both follow from the absorption conditions.\n\n    It may turn out that \\( (A, \\leq) \\) is a complete lattice under this definition. This can allow us, for example, to transparently extend the binary operations join and meet into infinitary operations.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:binary_lattice_operations/semilattices} Suprema and infima are obviously associative and commutative as binary operations because ordering is immaterial for pure sets and \\( x \\vee y \\) is defined as \\( \\sup\\set{ x, y } \\).\n\n  Idempotence is also obvious because \\( x \\vee x = \\sup\\set{ x } = x \\).\n\n  \\SubProofOf{thm:binary_lattice_operations/identity} Obvious since \\( \\bot \\leq x \\leq \\top \\) for all \\( x \\in P \\).\n\n  \\SubProofOf{thm:binary_lattice_operations/absorption} If we rewrite \\eqref{eq:thm:binary_lattice_operations/absorption/join} using suprema and infima, we obtain\n  \\begin{equation*}\n    \\sup\\set{ x, \\inf\\set{ y, x } } = x.\n  \\end{equation*}\n\n  If \\( x \\leq y \\), then \\( \\inf\\set{ y, x } = x \\) and \\( \\sup\\set{ x, \\inf\\set{ y, x } } = \\sup\\set{ x, x } = x \\).\n\n  If \\( x \\geq y \\), then \\( \\inf\\set{ y, x } = y \\) and \\( \\sup\\set{ x, \\inf\\set{ y, x } } = \\sup\\set{ x, y } = x \\).\n\n  This proves \\eqref{eq:thm:binary_lattice_operations/absorption/join}. Since \\( \\wedge \\) is \\( \\vee \\) in the \\hyperref[def:preordered_set/duality]{opposite partially ordered set}, \\eqref{eq:thm:binary_lattice_operations/absorption/meet} follows automatically.\n\n  \\SubProofOf{thm:binary_lattice_operations/compatibility} We have\n  \\begin{equation*}\n    x \\vee y\n    =\n    \\sup\\set{ x, y }\n    =\n    \\begin{cases}\n      y, &x \\leq y \\\\\n      x, &x > y\n    \\end{cases}\n  \\end{equation*}\n  and dually for \\( \\wedge \\).\n\n  \\SubProofOf{thm:binary_lattice_operations/new_lattice} Since the binary join and/or meet are defined for all members of the set \\( A \\), it is indeed a join-semilattice because all finite joins and meets exist by definition.\n\n  Idempotence of \\( \\vee \\) follows from \\eqref{eq:thm:binary_lattice_operations/absorption/meet}:\n  \\begin{equation*}\n    x \\vee x = x \\vee (x \\wedge (x \\vee x)) = x\n  \\end{equation*}\n  and dually for \\( \\wedge \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:lattice_homomorphism_is_monotone}\n  If a function \\( f: L \\to M \\) between \\hyperref[def:semilattice]{(semi)lattices} preserves either joins or meets, it is \\hyperref[def:partially_ordered_set/homomorphism]{monotone}.\n\n  Thus, the requirement for \\hyperref[def:semilattice/homomorphism]{lattice homomorphisms} to be monotone is redundant.\n\\end{corollary}\n\\begin{proof}\n  If the function \\( f \\) preserves joins and if \\( x \\leq y \\), by \\eqref{eq:thm:binary_lattice_operations/compatibility/join} we have \\( x \\vee y = y \\) and thus\n  \\begin{equation*}\n    f(x \\vee y) = f(y),\n  \\end{equation*}\n  which again by \\eqref{eq:thm:binary_lattice_operations/compatibility/join} implies \\( f(x) \\leq f(y) \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:bounded_lattice_absorbing}\n  In any \\hyperref[def:semilattice/bounded]{bounded lattice}, \\( \\bot \\) is absorbing with respect to meets and \\( \\top \\) with respect to joins. That is, \\( \\bot \\wedge x = \\bot \\) and \\( \\top \\vee x = \\top \\).\n\\end{proposition}\n\\begin{proof}\n  Obvious when the lattice is regarded as a partially ordered set.\n\\end{proof}\n\n\\begin{definition}\\label{def:fixed_point}\n  Given a \\hyperref[def:function]{function} \\( f: A \\to A \\) between arbitrary sets, we call \\( x \\in A \\) a \\term{fixed point} of \\( f \\) if \\( x = f(x) \\).\n\\end{definition}\n\n\\begin{theorem}[Knaster-Tarski theorem]\\label{thm:knaster_tarski_theorem}\n  The \\hyperref[def:fixed_point]{fixed points} of a \\hyperref[def:partially_ordered_set/homomorphism]{monotone} \\hyperref[def:multi_valued_function/endofunction]{endofunction} in a \\hyperref[def:semilattice/lattice]{complete lattice} form a complete sublattice. In particular, the function has at least one fixed point.\n\\end{theorem}\n\\begin{proof}\n  Let \\( (X, \\leq) \\) be a complete lattice and let \\( \\varphi: X \\to X \\) be a monotone function. Define\n  \\begin{equation*}\n    L \\coloneqq \\{ x \\in X \\colon f(x) \\leq x \\}.\n  \\end{equation*}\n\n  We know that \\( L \\) is nonempty because \\( \\top \\in L \\).\n\n  Since the lattice is complete, we can take \\( l \\coloneqq \\inf L \\). Note that \\( f(l) \\) is a lower bound of \\( L \\) because for any \\( y \\in L \\) we have\n  \\begin{equation*}\n    f(l) \\leq f(y) \\leq y.\n  \\end{equation*}\n\n  But \\( l \\) is the largest lower bound of \\( L \\), hence\n  \\begin{equation}\\label{eq:thm:knaster_tarski/f_lower}\n    f(l) \\leq l.\n  \\end{equation}\n\n  Therefore, \\( f(f(l)) \\leq f(l) \\) and \\( f(l) \\in L \\). Hence, \\( l \\) is a lower bound for \\( \\{ f(l) \\} \\) and\n  \\begin{equation}\\label{eq:thm:knaster_tarski/f_upper}\n    l \\leq f(l).\n  \\end{equation}\n\n  From \\eqref{eq:thm:knaster_tarski/f_lower} and \\eqref{eq:thm:knaster_tarski/f_upper} it follows that \\( l = f(l) \\), that is, \\( l \\) is a fixed point of \\( f \\).\n\n  Denote by \\( F \\) the set of all fixed points of \\( X \\). We just showed that \\( F \\) is nonempty. Let \\( G \\subseteq F \\). We will show that the infimum and supremum of \\( G \\) is in \\( F \\).\n\n  Denote\n  \\begin{equation*}\n    l_G \\coloneqq \\inf G.\n  \\end{equation*}\n\n  For any \\( g \\in G \\) we have \\( l_G \\leq g \\). From monotonicity of \\( f \\),\n  \\begin{equation*}\n    f(l_G) \\leq f(g) = g,\n  \\end{equation*}\n  therefore \\( f(l_G) \\leq l_G \\) because \\( l_G \\) is the greatest lower bound of \\( G \\). But, from monotonicity of \\( f \\), we have \\( l_G \\leq f(l_G) \\). Therefore, \\( f(l_G) = l_G \\) and \\( l_G \\in F \\).\n\n  We can analogously show that \\( \\sup G \\in F \\) and conclude that \\( (F, \\leq) \\) is itself a complete lattice.\n\\end{proof}\n\n\\begin{remark}\\label{rem:lattice_categorical_product}\n  The existence of finite joins and meets is equivalent to the existence of finite products and coproducts in the respective \\hyperref[def:thin_category]{thin category} defined in \\fullref{thm:order_category_isomorphism/partially_ordered}.\n\\end{remark}\n\n\\begin{definition}\\label{def:square_free}\n  An element \\( x \\) of a \\hyperref[def:semiring/commutative]{commutative semiring} is said to be \\term{square-free} if \\( y \\mid x \\) implies that \\( z^2 \\not\\mid x \\).\n\\end{definition}\n\n\\begin{remark}\\label{rem:lattice_polynomials}\n  Let \\( L \\) be a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive lattice}. We will discuss polynomials over \\( L \\).\n\n  By \\fullref{ex:def:semiring/lattice}, \\( L \\) induces a positive and a negative commutative semiring. Given a set \\( \\mscrX \\) of indeterminates, we can form the \\hyperref[def:polynomial_algebra]{polynomial semiring} \\( L[\\mscrX] \\) over the positive semiring. Suppose that we are given an evaluation \\( f: \\mscrX \\to L^\\mscrX \\). Consider the \\hyperref[thm:polynomial_algebra_universal_property]{evaluation homomorphism} \\( \\Phi_f: L[\\mscrX] \\to L^\\mscrX \\).\n  \\begin{equation*}\n    \\Phi_f(X^2) = \\Phi_f(X).\n  \\end{equation*}\n\n  Hence, we can limit ourselves to \\hyperref[def:square_free]{square-free} monomials. That is, monomials of the form \\( \\prod_{X \\in \\mscrX} X^{\\gamma_X} \\), where \\( \\gamma_X \\) is either \\( 0 \\) or \\( 1 \\). More succinctly, since every monomial has finitely many indeterminates of positive power, it can be written as a finite meet \\( X_1 \\wedge \\cdots \\wedge X_n \\). A polynomial is then a finite join of finite meets of indeterminates and constants.\n\n  There is a nuance, however. In \\cite[def. I.4.2]{Gratzer1978}, a multivariate lattice polynomial is defined to consist only of indeterminates; for example\n  \\begin{equation*}\n    p(X, Y, Z) = (X \\wedge Y) \\vee (X \\wedge Z) \\vee (Y \\wedge Z).\n  \\end{equation*}\n\n  This excludes coefficients before the monomials, hence making the definition distinct from the general notion of a polynomial over a commutative semiring. In \\cite{Marichal2007}, polynomials with coefficients in front of the monomials are called \\term{weighted lattice polynomials}. For example, a weighted polynomial is\n  \\begin{equation*}\n    q(X, Y, Z) = (a \\wedge X \\wedge Y) \\vee (b \\wedge X \\wedge Z) \\vee (c \\wedge Y \\wedge Z).\n  \\end{equation*}\n\n  Compare \\( q(X, Y, Z) \\) to \\( p(X, Y, Z) \\). We will refer to unweighted polynomials by default.\n\n  We can analogously define polynomials over the negative semiring of \\( L \\), e.g.\n  \\begin{equation*}\n    r(X, Y, Z) = (X \\vee Y) \\wedge (X \\vee Z) \\wedge (Y \\vee Z).\n  \\end{equation*}\n\n  The latter polynomials are related to but distinct from \\hyperref[def:cnf_and_dnf]{conjunctive normal forms}, while the former - to \\hyperref[def:cnf_and_dnf]{disjunctive normal forms}.\n\\end{remark}\n\n\\begin{example}\\label{ex:lattice_polynomials}\n  We list several examples of \\hyperref[rem:lattice_polynomials]{lattice polynomials}:\n  \\begin{thmenum}\n    \\thmitem{ex:lattice_polynomials/distributivity} The distributivity axiom \\eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join} implies that the polynomial\n    \\begin{equation*}\n      X \\wedge (Y \\vee Z)\n    \\end{equation*}\n    over the positive semiring evaluates to the same trivariate function as the polynomial\n    \\begin{equation*}\n      (X \\wedge Y) \\vee (X \\wedge Z)\n    \\end{equation*}\n    over the negative semiring.\n\n    \\thmitem{ex:lattice_polynomials/boolean} A lattice polynomial for the two-element boolean algebra \\hyperref[def:boolean_value]{\\( \\set{ T, F } \\)} corresponds to a \\hyperref[def:boolean_function]{boolean function}. We cannot express negation without introducing auxiliary polynomials as a consequence of \\fullref{ex:thm:posts_completeness_theorem/and_or}. \\hyperref[def:positive_formula]{Positive formulas} in \\hyperref[def:cnf_and_dnf/normal_form]{conjunctive/disjunctive normal form}, however, correspond exactly to lattice polynomials with square-free monomials.\n\n    For example, \\hyperref[def:standard_boolean_operators]{exclusive or} \\( \\oplus \\) can be expressed via the \\hyperref[def:propositional_syntax/formula]{propositional formula}\n    \\begin{equation*}\n      P \\vee Q \\vee (P \\wedge Q).\n    \\end{equation*}\n\n    This corresponds to a bivariate polynomial over the negative semiring of \\( \\set{ T, F } \\).\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:order_ideal_and_filter}\n  In a \\hyperref[def:partially_ordered_set]{partially ordered set}, we call the nonempty \\hyperref[def:directed_set]{upward directed} subset \\( I \\) an \\term{order ideal} if \\( x \\in I \\) and \\( y \\leq x \\) imply that \\( y \\in I \\).\n\n  \\hyperref[def:partially_ordered_set/duality]{Dually}, we call the nonempty \\hyperref[def:directed_set]{downward directed} set \\( F \\) a \\term{filter} if \\( x \\in F \\) and \\( y \\geq x \\) imply that \\( y \\in F \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:lattice_ideals}\n  For a subset \\( I \\) of a \\hyperref[def:lattice]{lattice} \\( L \\), the following are equivalent:\n  \\begin{thmenum}\n    \\thmitem{thm:lattice_ideals/order} \\( I \\) is an \\hyperref[def:order_ideal_and_filter]{order ideal}.\n    \\thmitem{thm:lattice_ideals/direct}\\mcite[17]{Gratzer1978} \\( I \\) is a closed under joins and \\( i \\in I \\) and \\( l \\in L \\) imply \\( i \\wedge l \\in I \\). If \\( L \\) has a \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom}, it must belong to \\( I \\).\n    \\thmitem{thm:lattice_ideals/semilattice} \\( I \\) is a \\hyperref[def:semiring_ideal]{semiring ideal} of the \\hyperref[ex:def:semiring/lattice]{positive semilattice} of \\( L \\) (in case \\( L \\) is a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive lattice}).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\ImplicationSubProof{thm:lattice_ideals/order}{thm:lattice_ideals/direct} Suppose that \\( I \\) is an order ideal.\n  \\begin{itemize}\n    \\item The bottom \\( \\bot \\) is less than any element of \\( I \\), hence \\( \\bot \\in I \\).\n    \\item Given \\( i, j \\in I \\), \\( I \\) contains an upper bound of theirs. Then \\( i \\vee j \\) as the least upper bound also belongs to \\( I \\).\n    \\item Given \\( i \\in I \\) and \\( l \\in L \\), since \\( i \\wedge l \\leq l \\), we conclude that \\( i \\wedge l \\in I \\).\n  \\end{itemize}\n\n  \\ImplicationSubProof{thm:lattice_ideals/direct}{thm:lattice_ideals/order} Suppose that \\( I \\) is closed under joins and that \\( i \\in I \\) and \\( l \\in L \\) imply \\( i \\wedge l \\in I \\).\n  \\begin{itemize}\n    \\item If \\( i, j \\in I \\), then \\( i \\vee j \\in I \\). Hence, \\( I \\) is an upward directed set.\n    \\item If \\( i \\in I \\) and \\( j \\leq i \\), then \\( j = i \\wedge j \\in I \\).\n  \\end{itemize}\n\n  \\EquivalenceSubProof{thm:lattice_ideals/order}{thm:lattice_ideals/semilattice} Trivial.\n\\end{proof}\n\n\\begin{remark}\\label{rem:lattice_ideals_as_semiring_ideals}\n  Regarding \\hyperref[thm:lattice_ideals]{ideals} and \\hyperref[thm:lattice_filters]{filters} in bounded distributive lattices as \\hyperref[def:semiring_ideal]{semiring ideals} exposes us to a lot of definitions and theorems that we would otherwise need to redefine. For example, \\hyperref[def:semiring_ideal/principal]{principal}, \\hyperref[def:semiring_ideal/prime]{prime} and \\hyperref[def:semiring_ideal/maximal]{maximal} ideals, the properties from \\fullref{thm:def:semiring_ideal}, the semiring of ideals from \\fullref{thm:semiring_of_ideals}, or \\fullref{thm:maximal_ideal_theorem}.\n\\end{remark}\n\n\\begin{example}\\label{ex:lattice_ideals}\n  We list examples of \\hyperref[thm:lattice_ideals]{lattice ideals}:\n  \\begin{thmenum}\n    \\thmitem{ex:lattice_ideals/lattice} Consider the (zero-based) natural number divisibility lattice from \\fullref{thm:natural_number_divisibility_lattice}. For any natural number \\( n \\), the set \\( D_n \\) of all \\hyperref[def:divisibility]{divisors} of \\( n \\) is a lattice ideal.\n\n    \\begin{figure}\n      \\centering\n      \\includegraphics[page=1]{output/ex__lattice_ideals.pdf}\n      \\caption{A Hasse diagram for the divisors of \\( 24 \\).}\n      \\label{fig:ex:lattice_ideals/lattice}\n    \\end{figure}\n\n    Indeed,\n    \\begin{itemize}\n      \\item The bottom \\( 1 \\) divides \\( n \\).\n      \\item If \\( a \\) and \\( b \\) divide \\( n \\), their product \\( ab \\) also does, and hence their join \\( \\lcm(a, b) \\) also does.\n      \\item If \\( a \\mid n \\) and \\( b \\) is any natural number, then \\( \\gcd(a, b) \\mid a \\mid n \\).\n    \\end{itemize}\n\n    Furthermore, \\( D_n \\) is a \\hyperref[def:semiring_ideal]{principal ideal} since it can be obtained as \\( \\set{ n \\wedge m \\mid m \\in \\BbbN } \\).\n\n    If \\( p \\) is a \\hyperref[def:prime_number]{prime number}, then \\( D_p = \\set{ 1, p } \\) is a \\hyperref[def:semiring_ideal/maximal]{maximal ideal}, and hence also a \\hyperref[def:semiring_ideal/prime]{prime ideal}.\n\n    \\thmitem{ex:lattice_ideals/subgroups} Given a \\hyperref[def:group]{group} \\( G \\) and a proper \\hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \\( N \\), consider the \\hyperref[thm:substructures_form_complete_lattice]{lattice of subgroups} \\( L_G \\) of \\( G \\) and the sublattice \\( L_N \\) of subgroups of \\( N \\). Note that the top \\( N \\) of \\( L_N \\) is not the top \\( G \\) of \\( L_G \\).\n\n    Then \\( L_N \\) is an ideal on \\( L \\).\n    \\begin{itemize}\n      \\item \\( L_N \\) contains the bottom \\( \\set{ e } \\).\n      \\item \\( L_N \\) contains the join \\( \\braket{ K \\cup H } \\) of every two subgroups of \\( N \\).\n      \\item \\( L_N \\) contains the meet \\( K \\cap H \\) of \\( K \\in L_N \\) and \\( H \\in L_G \\) since \\( K \\cap H \\subseteq K \\subseteq N \\).\n    \\end{itemize}\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:lattice_filters}\n  For a subset \\( F \\) of a \\hyperref[def:lattice]{lattice} \\( L \\), the following are equivalent:\n  \\begin{thmenum}\n    \\thmitem{thm:lattice_filters/order} \\( F \\) is a \\hyperref[def:order_ideal_and_filter]{filter}.\n    \\thmitem{thm:lattice_filters/direct}\\mcite[19]{Gratzer1978} \\( F \\) is closed under meets and \\( i \\in I \\) and \\( l \\in L \\) imply \\( i \\vee l \\in I \\). If \\( L \\) has a \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top}, it must belong to \\( I \\).\n    \\thmitem{thm:lattice_filters/semilattice} \\( F \\) is a \\hyperref[def:semiring_ideal]{semiring ideal} of the \\hyperref[ex:def:semiring/lattice]{negative semilattice} of \\( L \\) (in case \\( L \\) is a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive lattice}).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  The proof is \\hyperref[def:semilattice/duality]{dual} to that of \\fullref{thm:lattice_ideals}.\n\\end{proof}\n\n\\begin{example}\\label{ex:lattice_filters}\n  We list examples of \\hyperref[thm:lattice_ideals]{lattice filters}:\n  \\begin{thmenum}\n    \\thmitem{ex:lattice_filters/lattice} By \\hyperref[def:partially_ordered_set/duality]{duality} with respect to \\fullref{ex:lattice_ideals/subgroups}, it follows that, for a natural number \\( n \\), the semiring ideal\n    \\begin{equation*}\n      \\braket{ n } \\coloneqq \\set{ 0, n, 2n, 3n, \\ldots }\n    \\end{equation*}\n    is a principal filter in the natural number divisibility lattice from \\fullref{thm:natural_number_divisibility_lattice}.\n\n    We can prove this explicitly:\n    \\begin{itemize}\n      \\item \\( \\braket{ n } \\) contains the top \\( 0 \\).\n      \\item \\( \\braket{ n } \\) contains the meet \\( \\gcd(a, b) \\) of every two members of \\( \\braket{ n } \\).\n      \\item If \\( n \\mid a \\) and \\( b \\) is any natural number, then \\( n \\mid a \\mid \\lcm(a, b) \\), meaning that the join \\( \\lcm(a, b) \\) also belongs to \\( \\braket{ n } \\).\n    \\end{itemize}\n\n    \\thmitem{ex:lattice_filters/subgroups} By \\hyperref[def:partially_ordered_set/duality]{duality} with respect to \\fullref{ex:lattice_ideals/subgroups}, given a \\hyperref[def:group]{group} \\( G \\) and a proper \\hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \\( N \\), the sublattice of subgroups containing \\( N \\) (rather than contained in \\( N \\)) is a filter (rather than an ideal).\n  \\end{thmenum}\n\\end{example}\n", "meta": {"hexsha": "14b89dbbf5225ebff674279a49e8e96018b2b7de", "size": 29470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lattices.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/lattices.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/lattices.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.7583547558, "max_line_length": 589, "alphanum_fraction": 0.7144553784, "num_tokens": 9180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764119, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6879706993938975}}
{"text": "\\subsection{Propositional logic}\\label{subsec:propositional_logic}\n\n\\begin{remark}\\label{rem:propositional_language_is_alphabet}\n  The \\hyperref[def:propositional_language]{language of propositional logic} is, strictly speaking, an \\hyperref[def:formal_language/alphabet]{alphabet} rather than a \\hyperref[def:formal_language/language]{language}. Nonetheless, this is the established terminology.\n\\end{remark}\n\n\\begin{definition}\\label{def:propositional_language}\\mcite[sec. 7.2]{OpenLogicFull}\n  The \\term{language of propositional logic} consists of:\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_language/prop} A nonempty, \\hyperref[def:set_countability/at_most_countable]{at most countable} set \\( \\boldop{Prop} \\) of \\term{propositional variables}. Technically, we can have different languages with different variables, but it is safe to assume that there is only one single language of propositional language.\n\n    \\thmitem{def:propositional_language/constants} Two \\term{propositional constants} (also known as \\term{truth values}):\n    \\begin{thmenum}\n      \\thmitem{def:propositional_language/constants/verum} The \\term{verum} \\( \\top \\).\n      \\thmitem{def:propositional_language/constants/falsum} The \\term{falsum} \\( \\bot \\).\n    \\end{thmenum}\n\n    \\thmitem{def:propositional_language/negation} \\term{Negation} \\( \\neg \\).\n    \\thmitem{def:propositional_language/connectives} The set \\( \\Sigma \\) of \\term{propositional connectives}, namely\n    \\begin{thmenum}\n      \\thmitem{def:propositional_language/connectives/conjunction} \\term{Conjunction} \\( \\wedge \\) (also known as \\hyperref[def:standard_boolean_operators]{\\term{and}} and \\hyperref[def:semilattice/meet]{\\term{meet}}).\n      \\thmitem{def:propositional_language/connectives/disjunction} \\term{Disjunction} \\( \\vee \\) (also known as \\hyperref[def:standard_boolean_operators]{\\term{or}} and \\hyperref[def:semilattice/join]{\\term{join}}).\n      \\thmitem{def:propositional_language/connectives/conditional} \\term{Conditional} \\( \\rightarrow \\) (also known as \\term{if\\ldots then} and \\hyperref[def:material_implication]{\\term{material implication}}).\n      \\thmitem{def:propositional_language/connectives/biconditional} \\term{Biconditional} \\( \\leftrightarrow \\) (also known as \\term{iff} and \\term{material equivalence}).\n    \\end{thmenum}\n\n     Note that \\enquote{conditional} and \\enquote{biconditional} are nouns in this context.\n\n    \\thmitem{def:propositional_language/parentheses} Parentheses \\( ( \\) and \\( ) \\) for defining the order of operations unambiguously (see \\fullref{rem:propositional_formula_parentheses} for a further discussion).\n  \\end{thmenum}\n\n  \\Fullref{rem:smaller_propositional_language} shows we can actually utilize a smaller propositional language without losing any of its semantics.\n\\end{definition}\n\n\\begin{definition}\\label{def:propositional_syntax}\n  The following related definitions constitute what is called the \\term{syntax of propositional logic}.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_syntax/grammar_schema} Consider the following \\hyperref[rem:backus_naur_form]{grammar schema}:\n    \\begin{bnf*}\n      \\bnfprod{variable}   {P \\in \\boldop{Prop}} \\\\\n      \\bnfprod{connective} {\\circ \\in \\Sigma} \\\\\n      \\bnfprod{formula}    {\\bnfpn{variable} \\bnfor} \\\\\n      \\bnfmore             {\\bnfts{\\( \\top \\)} \\bnfor \\bnfts{\\( \\bot \\)} \\bnfor} \\\\\n      \\bnfmore             {\\bnfts{\\( \\neg \\)} \\bnfpn{formula} \\bnfor} \\\\\n      \\bnfmore             {\\bnfts{(} \\bnfsp \\bnfpn{formula} \\bnfsp \\bnfpn{connective} \\bnfsp \\bnfpn{formula} \\bnfsp \\bnfts{)}}\n    \\end{bnf*}\n\n    Note that \\( \\boldop{Prop} \\) may be infinite, in which case the grammars may have infinitely many rules. If needed, we can circumvent this by introducing an appropriate naming convention for variables, for example by allowing arbitrary strings of alphanumeric characters for variable names.\n\n    For the sake of readability, we will be using the conventions in \\fullref{rem:propositional_formula_parentheses} regarding parentheses.\n\n    \\thmitem{def:propositional_syntax/formula} The set \\( \\boldop{Form} \\) of \\term{propositional formulas} is the language \\hyperref[def:grammar_derivation/grammar_language]{generated} by this grammar schema with \\( \\bnfpn{formula} \\) as a starting rule. Propositional formulas are also called sentenced unlike in first-order logic where only specific formulas are called sentences --- see \\fullref{def:first_order_syntax/ground_formula}.\n\n    The grammar of propositional formulas is unambiguous as shown by \\fullref{thm:propositional_formulas_are_unambiguous}, which makes it possible to perform proofs via \\fullref{thm:structural_induction_on_unambiguous_grammars}.\n\n    \\thmitem{def:propositional_syntax/subformula} If \\( \\varphi \\) and \\( \\psi \\) are formulas and \\( \\psi \\) is a \\hyperref[def:formal_language/subword]{subword} of \\( \\varphi \\), we say that \\( \\psi \\) is a \\term{subformula} of \\( \\varphi \\).\n\n    \\thmitem{def:propositional_syntax/variables} For each formula \\( \\varphi \\), we inductively define its \\term{variables} to be elements of the set\n    \\begin{equation}\\label{eq:def:propositional_syntax/varables}\n      \\boldop{Var}(\\varphi) \\coloneqq \\begin{cases}\n        \\varnothing,                                  &\\varphi \\in \\set{ \\top, \\bot } \\\\\n        \\set{ P },                                    &\\varphi = P \\in \\boldop{Prop} \\\\\n        \\boldop{Var}(\\psi),                           &\\varphi = \\neg \\psi \\\\\n        \\boldop{Var}(\\psi) \\cup \\boldop{Var}(\\theta), &\\varphi = \\psi \\bincirc \\theta, \\bincirc \\in \\Sigma.\n      \\end{cases}\n    \\end{equation}\n\n    Note that \\( \\boldop{Var}(\\varphi) \\) can naturally be totally ordered by the position of the first occurrence of a variable.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:propositional_formulas_are_unambiguous}\n  The grammar of \\hyperref[def:propositional_syntax/formula]{propositional formulas} is \\hyperref[def:grammar_derivation/unambiguous]{unambiguous}.\n\\end{proposition}\n\\begin{proof}\n  The proof is analogous to \\fullref{ex:natural_number_arithmetic_grammar/derivation}.\n\\end{proof}\n\n\\begin{remark}\\label{rem:propositional_formula_parentheses}\n  We use the following two \\enquote{abuse-of-notation} conventions regarding parentheses:\n  \\begin{thmenum}\n    \\thmitem{rem:propositional_formula_parentheses/outermost} We may skip the outermost parentheses in formulas with top-level \\hyperref[def:propositional_language/connectives]{connectives}, e.g. we may write \\( P \\wedge Q \\) rather than \\( (P \\wedge Q) \\).\n\n    \\thmitem{rem:propositional_formula_parentheses/associative} Because of the associativity of \\( \\wedge \\) and \\( \\vee \\), which is implied by \\fullref{def:propositional_formula_induced_function} and \\fullref{def:standard_boolean_operators}, we may skip the parentheses in chains like\n    \\begin{equation*}\n      ( \\ldots ((P_1 \\wedge P_2) \\wedge P_3) \\wedge \\ldots \\wedge P_{n-1} ) \\wedge P_n.\n    \\end{equation*}\n    and instead write\n    \\begin{equation*}\n      P_1 \\wedge P_2 \\wedge \\ldots \\wedge P_{n-1} \\wedge P_n.\n    \\end{equation*}\n\n    \\thmitem{rem:first_order_formula_parentheses/additional} Although not formally necessary, for the sake of readability we may choose to add parentheses around certain formulas like\n    \\begin{equation*}\n      \\neg P \\vee \\neg Q.\n    \\end{equation*}\n    and instead write\n    \\begin{equation*}\n      (\\neg P) \\vee \\neg Q.\n    \\end{equation*}\n\n    This latter convention is more useful for quantifiers in \\hyperref[def:first_order_syntax/formula]{first-order formulas}.\n  \\end{thmenum}\n\n  These are only notations shortcuts in the \\hyperref[rem:metalogic]{metalanguage} and the formulas themselves (as abstract mathematical objects) are still assumed to contain parentheses that help them avoid syntactic ambiguity.\n\\end{remark}\n\n\\begin{definition}\\label{def:material_implication}\n  Theorems in mathematics usually have the form \\( P \\rightarrow Q \\). Formulas of this form are called \\term{material implications} in order to distinguish them from logical implication, which relates to the metatheoretic concept of \\hyperref[def:propositional_semantics/entailment]{entailment}. This is further discussed in \\cite{MathSE:material_vs_logical_implication}. Note that the term \\enquote{material implication} sometimes also refers to the \\hyperref[def:propositional_language/connectives/conditional]{conditional connective \\( \\rightarrow \\)} itself.\n\n  We introduce terminology that is conventionally used when dealing with theorems.\n\n  \\begin{thmenum}\n    \\thmitem{def:material_implication/sufficient_condition} \\( P \\) is a \\term{sufficient condition} for \\( Q \\).\n\n    \\thmitem{def:material_implication/necessary_condition} \\( Q \\) is a \\term{necessary condition} for \\( P \\).\n\n    \\thmitem{def:material_implication/antecedent} \\( P \\) the \\term{antecedent} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/consequent} \\( Q \\) the \\term{consequent} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/inverse} The formula \\( \\neg P \\rightarrow \\neg Q \\) is the \\term[bg=противоположна,ru=противоположная]{inverse} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/converse} The formula \\( Q \\rightarrow P \\) is the \\term[bg=обратна,ru=обратная]{converse} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/contrapositive} The formula \\( \\neg Q \\rightarrow \\neg P \\) is the \\term{contrapositive} of \\( \\varphi \\). In classical logic, it is \\hyperref[def:propositional_semantics/equivalence]{equivalent} to the original formula due to \\fullref{thm:boolean_equivalences/contrapositive}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:propositional_valuation}\n  We define \\term[bg=оценка,ru=оценка]{valuations} for propositional formulas. It is possible to define different valuations, so in case of doubt, we will refer to the one defined here as the \\term{classical valuation} giving \\term{classical semantics}.\n\n  This valuation implicitly depends on the \\hyperref[def:boolean_algebra]{Boolean algebra} fixed in \\fullref{def:boolean_function}. When dealing with \\hyperref[def:propositional_heyting_algebra_semantics]{Heyting semantics}, we use more general Heyting algebras where not only the top and bottom, but also other values are utilized.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_valuation/interpretation} A \\term{propositional interpretation} is a function with signature \\( I: \\boldop{Prop} \\to \\set{ T, F } \\). See \\fullref{def:boolean_value} for remarks regarding the \\hyperref[def:boolean_algebra]{Boolean algebra} \\( \\set{ T, F } \\) and the \\fullref{def:standard_boolean_operators} for a list of some standard Boolean operators.\n\n    \\thmitem{def:propositional_valuation/formula_valuation} Given an interpretation \\( I \\), we define the \\term{valuation} of a formula \\( \\varphi \\) inductively as\n    \\begin{equation}\\label{eq:def:propositional_valuation/formula_interpretation}\n      \\varphi\\Bracks{I} \\coloneqq \\begin{cases}\n        T,                                         &\\varphi = \\top \\\\\n        F,                                         &\\varphi = \\bot \\\\\n        I(P),                                      &\\varphi = P \\in \\boldop{Prop} \\\\\n        \\overline{\\psi\\Bracks{I}},                 &\\varphi = \\neg \\psi \\\\\n        \\psi_1\\Bracks{I} \\bincirc \\psi_2\\Bracks{I} &\\varphi = \\psi_1 \\bincirc \\psi_2, \\bincirc \\in \\Sigma,\n      \\end{cases}\n    \\end{equation}\n  \\end{thmenum}\n  where \\( \\bincirc \\) on the left denotes the \\hyperref[def:standard_boolean_operators]{Boolean operator} corresponding to the connective \\( \\bincirc \\) on the right.\n\\end{definition}\n\n\\begin{remark}\\label{rem:propositional_formula_valuation_without_variable_assignment}\n  If we know that \\( \\boldop{Var}(\\varphi) \\subseteq \\{ P_1, \\ldots, P_n \\} \\), it follows that the \\hyperref[def:first_order_valuation/formula_valuation]{valuation} \\( \\varphi\\Bracks{I} \\) only depends on the particular values \\( I(P_1), \\ldots, I(P_n) \\) of \\( I \\).\n\n  Let \\( x_1, \\ldots, x_n \\in \\set{ F, T } \\) and let \\( I \\) be such that \\( I(P_k) = x_k \\) for \\( k = 1, \\ldots, n \\). We introduce the notation\n  \\begin{equation}\\label{eq:rem:propositional_formula_valuation_without_variable_assignment/short_semantic}\n    \\varphi\\Bracks{x_1, \\ldots, x_n}\n  \\end{equation}\n  for \\( \\varphi\\Bracks{I} \\) because the rest of the interpretation \\( I \\) plays no role here. We may also use\n  \\begin{equation}\\label{eq:rem:propositional_formula_valuation_without_variable_assignment/short_syntactic}\n    \\varphi[\\psi_1, \\ldots, \\psi_n]\n  \\end{equation}\n  to denote \\hyperref[def:propositional_substitution]{substitution}.\n\n  When using this notation, we implicitly assume that \\( \\boldop{Var}(\\varphi) \\subseteq \\set{ P_1, \\ldots, P_n } \\).\n\\end{remark}\n\n\\begin{definition}\\label{def:propositional_formula_induced_function}\n  Let \\( \\varphi \\) be a propositional formula and let \\( \\boldop{Var}(\\varphi) = \\set{ P_1, \\ldots, P_n } \\) be an ordering of the free variables of \\( \\varphi \\). We define the \\hyperref[def:boolean_function]{Boolean function}\n  \\begin{equation}\\label{eq:def:propositional_formula_induced_function}\n    \\begin{split}\n      &\\fun_\\varphi: \\set{ T, F }^n \\to \\set{ T, F } \\\\\n      &\\fun_\\varphi(x_1, \\ldots, x_n) \\coloneqq \\varphi\\Bracks{x_1, \\ldots, x_n}.\n    \\end{split}\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\\label{def:propositional_semantics}\n  We now define \\term{semantical} properties of propositional formulas. Because of the connection with \\hyperref[def:boolean_function]{Boolean functions} given in \\fullref{def:propositional_formula_induced_function}, we also formulate some of the properties using Boolean functions.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_semantics/satisfiability}\\mcite[def. 7.14]{OpenLogicFull} Given an interpretation \\( I \\) and a set \\( \\Gamma \\) of formulas, we say that \\( I \\) \\term{satisfies} \\( \\Gamma \\) if, for every formula \\( \\varphi \\in \\Gamma \\) we have \\( \\varphi\\Bracks{I} = T \\).\n\n    We also say that \\( I \\) is a \\term{model} of \\( \\Gamma \\) and write \\( I \\vDash \\Gamma \\).\n\n    If \\( \\Gamma = \\set{ \\gamma_1, \\ldots, \\gamma_n } \\) is a finite ordered set, we use the shorthand \\( I \\vDash \\gamma_1, \\ldots, \\gamma_n \\) rather than \\( I \\vDash \\set{ \\gamma_1, \\ldots, \\gamma_n } \\). In particular, if \\( \\Gamma = \\set{ \\varphi } \\) we write \\( I \\vDash \\varphi \\).\n\n    Note that every interpretation vacuously satisfies the empty set \\( \\Gamma = \\varnothing \\) of formulas.\n\n    We say that \\( \\Gamma \\) is \\term{satisfiable} if there exists a model for \\( \\Gamma \\).\n\n    \\thmitem{def:propositional_semantics/entailment} We say that the set of formulas \\( \\Gamma \\) \\term{entails} the set of formulas \\( \\Delta \\) and write \\( \\Gamma \\vDash \\Delta \\) if either of the following hold:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/entailment/direct} Every model of \\( \\Gamma \\) is also a model of \\( \\Delta \\).\n      \\thmitem{def:propositional_semantics/entailment/functional} The following \\hyperref[thm:def:function/preimage]{preimage} inclusion holds:\n      \\begin{equation*}\n        \\bigcap_{\\varphi \\in \\Gamma} \\fun_\\varphi^{-1}(T) \\subseteq \\bigcap_{\\psi \\in \\Delta} \\fun_\\psi^{-1}(T).\n      \\end{equation*}\n    \\end{itemize}\n\n    \\thmitem{def:propositional_semantics/tautology} The formula \\( \\varphi \\) is a (semantic) \\term{tautology} if either:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/tautology/interpretations} Every interpretation satisfies \\( \\varphi \\).\n      \\thmitem{def:propositional_semantics/tautology/entailment} The empty set \\( \\Gamma = \\varnothing \\) of formulas entails \\( \\varphi \\), i.e. \\( \\vDash \\varphi \\).\n      \\thmitem{def:propositional_semantics/tautology/functional} The function \\( \\fun_\\varphi \\) is canonically true.\n    \\end{itemize}\n\n    We also say that \\( \\varphi \\) is \\term{valid}.\n\n    \\thmitem{def:propositional_semantics/contradiction} Dually, \\( \\varphi \\) is a (semantic) \\term{contradiction} if either:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/contradiction/interpretations} No interpretation satisfies \\( \\varphi \\).\n      \\thmitem{def:propositional_semantics/contradiction/entailment} The formula \\( \\varphi \\) entails \\( \\bot \\), i.e. \\( \\varphi \\vDash \\bot \\).\n      \\thmitem{def:propositional_semantics/contradiction/functional} The function \\( \\fun_\\varphi \\) is canonically false.\n    \\end{itemize}\n\n    \\thmitem{def:propositional_semantics/equivalence} We say that \\( \\varphi \\) and \\( \\psi \\) are \\term{semantically equivalent} and write \\( \\varphi \\gleichstark \\psi \\) if either:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/equivalence/interpretations} We have \\( \\varphi\\Bracks{I} = \\psi\\Bracks{I} \\) for every interpretation \\( I \\).\n      \\thmitem{def:propositional_semantics/equivalence/entailment} Both \\( \\varphi \\vDash \\psi \\) and \\( \\psi \\vDash \\varphi \\).\n    \\end{itemize}\n\n    \\thmitem{def:propositional_semantics/equisatisfiability} A weaker notion than that of semantic equivalence is that of \\term{equisatisfiability}. We say that the families \\( \\Gamma \\) and \\( \\Delta \\) are equisatisfiable if the following holds: \\enquote{\\( \\Gamma \\) is satisfiable if and only if \\( \\Delta \\) is satisfiable}. For single-formula families \\( \\Gamma = \\set{ \\varphi } \\) and \\( \\Delta = \\set{ \\psi } \\), the following are equivalent conditions for equisatisfiability:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/equisatisfiability/interpretations} There exist interpretations \\( I \\) and \\( J \\) such that \\( \\varphi\\Bracks{I} = \\psi\\Bracks{J} \\).\n      \\thmitem{def:propositional_semantics/equisatisfiability/functional} We have \\( \\fun_\\varphi = \\fun_\\psi \\) for the induced functions.\n    \\end{itemize}\n\n    A trivial example of equisatisfiable, but not equivalent formulas are \\( \\varphi = P \\) and \\( \\psi = Q \\) for \\( P \\neq Q \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{theorem}\\label{thm:lindenmaum_tarski_algebra_of_full_propositional_logic}\n  We give an explicit connection between \\hyperref[def:propositional_syntax/formula]{propositional formulas} and \\hyperref[def:boolean_function]{Boolean functions}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/equivalence_classes} The \\hyperref[def:propositional_semantics/equivalence]{semantic equivalence} \\( \\gleichstark \\) is an equivalence relation on the set \\( \\boldop{Form} \\) of all propositional formulas.\n\n    \\thmitem{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/bijection} The \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebra}  \\( \\boldop{Form} / {{}\\gleichstark} \\) of all propositional formulas with respect to semantic equivalence is bijective with the set of all \\hyperref[def:boolean_function]{Boolean functions} of arbitrary arity.\n\n    Both are provably Boolean algebras, but with very different proofs --- the Lindenbaum-Tarski algebra is Boolean due to the purely syntactic \\fullref{thm:intuitionistic_lindenbaum_tarski_algebra} and the set of all Boolean functions is a Boolean algebra due to the semantic \\fullref{thm:functions_over_model_form_model}. This is another demonstration of \\fullref{thm:classical_propositional_logic_is_sound_and_complete}.\n\n    See \\fullref{rem:thm:intuitionistic_lindenbaum_tarski_algebra/syntactic_proof}.\n  \\end{thmenum}\n\\end{theorem}\n\\begin{proof}\n  \\SubProofOf{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/equivalence_classes} Follows from the equivalences in \\fullref{def:equivalence_relation}.\n\n  \\SubProofOf{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/bijection} Follows from the equivalences in \\fullref{def:propositional_semantics/equivalence}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:boolean_equivalences}\n  The following (and many more) are called \\term{Boolean equivalences} because they are actually statements about our choice of \\hyperref[def:standard_boolean_operators]{standard Boolean operators}. They are formulated here because the framework of propositional logic is more convenient for stating the equivalences. Note that most of these equivalences fail in \\hyperref[def:intuitionistic_propositional_deductive_systems]{intuitionistic logic}.\n\n  For arbitrary propositional formulas \\( \\varphi \\) and \\( \\psi \\), the following semantic equivalences hold:\n  \\begin{thmenum}\n    \\thmitem{thm:boolean_equivalences/negation_bottom} \\hyperref[def:propositional_language/negation]{Negation} can be expressed via the \\hyperref[def:propositional_language/constants/falsum]{falsum}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/negation_bottom}\n      \\begin{split}\n        \\mathllap{\\neg \\varphi} &\\gleichstark \\mathrlap{\\varphi \\rightarrow \\bot}.\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/double_negation} \\hyperref[def:propositional_language/negation]{Negation} is an \\hyperref[def:set_with_involution]{involution}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/double_negation}\n      \\begin{split}\n        \\mathllap{\\neg \\neg \\varphi} &\\gleichstark \\mathrlap{\\varphi}.\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/contrapositive} A \\hyperref[def:material_implication]{material implication} is equivalent to its \\hyperref[def:material_implication/contrapositive]{contrapositive}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/contrapositive}\n      \\begin{split}\n        \\mathllap{\\varphi \\rightarrow \\psi} &\\gleichstark \\mathrlap{\\neg \\psi \\rightarrow \\neg \\varphi.}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/conditional_as_disjunction} A \\hyperref[def:propositional_language/connectives/conditional]{conditional} is a \\hyperref[def:propositional_language/connectives/disjunction]{disjunction} with the \\hyperref[def:material_implication/antecedent]{antecedent} negated:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/conditional_as_disjunction}\n      \\begin{split}\n        \\mathllap{\\varphi \\rightarrow \\psi} &\\gleichstark \\mathrlap{ \\neg \\varphi \\vee \\psi. }\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_via_conditionals} A \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is a \\hyperref[def:propositional_language/connectives/conjunction]{conjunction} of \\hyperref[def:propositional_language/connectives]{conditionals}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_via_conditionals}\n      \\begin{split}\n        \\mathllap{\\varphi \\leftrightarrow \\psi} &\\gleichstark \\mathrlap{(\\varphi \\rightarrow \\psi) \\wedge (\\psi \\rightarrow \\varphi).}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_as_conjunction} The \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is a \\hyperref[def:propositional_language/connectives/disjunction]{conjunction} of \\hyperref[def:propositional_language/connectives/conjunction]{disjunctions}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_as_conjunction}\n      \\begin{split}\n        \\mathllap{\\varphi \\leftrightarrow \\psi} &\\gleichstark \\mathrlap{(\\neg \\varphi \\vee \\psi) \\wedge (\\neg \\varphi \\vee \\psi).}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_as_disjunction} The \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is a \\hyperref[def:propositional_language/connectives/disjunction]{disjunction} of \\hyperref[def:propositional_language/connectives/conjunction]{conjunctions}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_as_disjunction}\n      \\begin{split}\n        \\mathllap{\\varphi \\leftrightarrow \\psi} &\\gleichstark \\mathrlap{(\\varphi \\wedge \\psi) \\vee (\\neg \\varphi \\wedge \\neg \\psi).}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_member_negation} A \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is equivalent its termwise negation:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_member_negation}\n      \\begin{split}\n        \\mathllap{\\neg \\varphi \\leftrightarrow \\neg \\psi} &\\gleichstark \\mathrlap{\\varphi \\leftrightarrow \\psi.}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_negation} A negation of a \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is again a biconditional with one of the terms negated:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_negation}\n      \\begin{split}\n        \\mathllap{\\neg \\parens{\\varphi \\leftrightarrow \\psi}}\n        &\\gleichstark\n        \\mathrlap{\\neg \\varphi \\leftrightarrow \\psi \\gleichstark}\n        \\\\ &\\gleichstark\n        \\mathrlap{\\varphi \\leftrightarrow \\neg \\psi.}\n      \\end{split}\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  The proofs follow directly from the table in \\fullref{def:standard_boolean_operators}.\n\\end{proof}\n\n\\begin{definition}\\label{def:propositional_substitution}\n  We sometimes want to substitute a propositional variable with another variable or even with a formula. This is akin to applying a \\hyperref[def:boolean_function]{Boolean function} like \\( x \\vee y \\) to different variables (e.g. to obtain \\( x \\vee x \\)) or even concrete values (e.g. \\( F \\vee T \\)), except that it is done on a purely syntactic level without involving any semantics involved.\n\n  It does not pose any technical difficulty to extend this definition beyond replacing a variable like it is usually done (e.g. \\cite[def. 7.8]{OpenLogicFull}). Not only that, we can then use this mechanism to define complicated rewriting rules as in \\fullref{alg:perfect_cnf_and_dnf} and have semantic equivalence automatically follow from \\fullref{thm:propositional_substitution_equivalence}.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_substitution/single} We define the \\term{substitution} of the propositional formula \\( \\theta \\) with \\( \\chi \\) in \\( \\varphi \\) as\n    \\begin{equation}\\label{eq:def:propositional_substitution/single}\n      \\varphi[\\theta \\mapsto \\chi] \\coloneqq \\begin{cases}\n        \\chi,                                                             &\\varphi = \\theta \\\\\n        \\varphi,                                                          &\\varphi \\neq \\theta \\T{and} \\varphi \\in \\set{ \\top, \\bot } \\cup \\boldop{Prop} \\\\\n        \\neg \\psi[\\theta \\mapsto \\chi],                                   &\\varphi \\neq \\theta \\T{and} \\varphi = \\neg \\psi \\\\\n        \\psi_1[\\theta \\mapsto \\chi] \\bincirc \\psi_2[\\theta \\mapsto \\chi], &\\varphi \\neq \\theta \\T{and} \\varphi = \\psi_1 \\bincirc \\psi_2, \\circ \\in \\Sigma.\n      \\end{cases}\n    \\end{equation}\n\n    Note that it is not strictly necessary for \\( \\theta \\) to be a subformula of \\( \\varphi \\).\n\n    In the case where \\( \\theta \\) is a single variable, if \\( P \\in \\boldop{Var}(\\varphi) \\), then \\( \\varphi[P \\mapsto \\chi] \\) is said to be an \\term{instance} of \\( \\varphi \\).\n\n    \\thmitem{def:propositional_substitution/simultaneous} We will now define \\term{simultaneous substitution} of \\( \\theta_1, \\ldots, \\theta_n \\) with \\( \\chi_1, \\ldots, \\chi_n \\). We wish to avoid the case where \\( \\theta_k \\) is a subformula of \\( \\chi_{k-1} \\) and it accidentally gets replaced during \\( \\varphi[\\theta_{k-1} \\mapsto \\chi_{k-1}][\\theta_k \\mapsto \\chi_k] \\).\n\n    Define\n    \\begin{equation*}\n      \\cat{Bound} \\coloneqq \\boldop{Var}(\\chi_1) \\cup \\ldots \\cup \\boldop{Var}(\\chi_n).\n    \\end{equation*}\n    and, for each variable \\( P_k \\) in \\( \\cat{Bound} \\), pick a variable \\( Q_k \\) from \\( \\boldop{Prop} \\setminus \\boldop{Bound} \\) (we implicitly assume the existence of enough variables in \\( \\boldop{Prop} \\)). Let \\( m \\) be the \\hyperref[def:cardinal]{cardinality} of \\( \\boldop{Bound} \\). The simultaneous substitution can now be defined as\n    \\begin{align*}\n      \\varphi[\\theta_1 \\mapsto \\chi_1, \\ldots, \\theta_n \\mapsto \\chi_n] \\coloneqq \\varphi\n      [\\theta_1 \\mapsto \\chi_1[P_1 \\mapsto Q_1, \\ldots, P_m \\mapsto Q_m]] \\\\\n      \\vdots \\hspace{3cm} \\\\\n      [\\theta_n \\mapsto \\chi_n[P_1 \\mapsto Q_1, \\ldots, P_m \\mapsto Q_m]] \\\\\n      [Q_1 \\mapsto P_1, \\ldots, Q_m \\mapsto P_m].\n    \\end{align*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:propositional_substitution_equivalence}\n  If \\( \\theta \\) is a subformula of \\( \\varphi \\) and if \\( \\theta \\gleichstark \\chi \\), then\n  \\begin{equation}\\label{eq:thm:propositional_substitution_equivalence}\n    \\varphi[\\theta \\mapsto \\chi] \\gleichstark \\varphi.\n  \\end{equation}\n\n  By induction, this also holds for \\hyperref[def:propositional_substitution/simultaneous]{simultaneous substitution}.\n\\end{proposition}\n\\begin{proof}\n  We use structural induction on \\( \\varphi \\):\n\n  \\begin{itemize}\n    \\item If \\( \\varphi = \\theta \\), then \\( \\varphi[\\theta \\mapsto \\chi] = \\chi \\) and, by definition,\n    \\begin{equation*}\n      \\varphi = \\theta \\gleichstark \\chi = \\varphi[\\theta \\mapsto \\chi].\n    \\end{equation*}\n\n    \\item If \\( \\varphi \\neq \\theta \\) and \\( \\varphi \\in \\set{ \\top, \\bot } \\cup \\boldop{Prop} \\), then \\( \\varphi[\\theta \\mapsto \\chi] = \\varphi \\) and \\eqref{eq:thm:propositional_substitution_equivalence} again holds trivially.\n\n    \\item If \\( \\varphi \\neq \\theta \\) and \\( \\varphi = \\neg \\chi \\) and if the inductive hypothesis holds for \\( \\chi \\), then \\( \\varphi[\\theta \\mapsto \\chi] = \\neg \\psi[\\theta \\mapsto \\chi] \\). For any interpretation \\( I \\),\n    \\begin{equation*}\n      \\parens[\\Big]{ \\varphi[\\theta \\mapsto \\chi] }\\Bracks{I}\n      =\n      \\overline{\\parens[\\Big]{ \\psi[\\theta \\mapsto \\chi] }\\Bracks{I}}\n      \\reloset {\\T{ind.}} =\n      \\overline{\\psi\\Bracks{I}}\n      =\n      \\varphi\\Bracks{I}.\n    \\end{equation*}\n\n    Therefore, \\eqref{eq:thm:propositional_substitution_equivalence} holds in this case.\n\n    \\item If \\( \\varphi \\neq \\theta \\) and \\( \\varphi = \\psi_1 \\bincirc \\psi_2, \\bincirc \\in \\Sigma \\) and if the inductive hypothesis holds for both \\( \\psi_1 \\) and \\( \\psi_2 \\), then for any interpretation \\( I \\),\n    \\begin{equation*}\n      \\parens[\\Big]{ \\varphi[\\theta \\mapsto \\chi] }\\Bracks{I}\n      =\n      \\parens[\\Big]{ \\psi_1[\\theta \\mapsto \\chi] }\\Bracks{I} \\bincirc \\parens[\\Big]{ \\psi_2[\\theta \\mapsto \\chi] }\\Bracks{I}\n      \\reloset {\\T{ind.}} =\n      \\psi_1\\Bracks{I} \\bincirc \\psi_2\\Bracks{I}\n      =\n      \\varphi\\Bracks{I}.\n    \\end{equation*}\n\n    Therefore, \\eqref{eq:thm:propositional_substitution_equivalence} holds in this case also.\n  \\end{itemize}\n\n  We have verified that \\eqref{eq:thm:propositional_substitution_equivalence} holds in all cases.\n\\end{proof}\n\n\\begin{remark}\\label{rem:smaller_propositional_language}\n  For \\hyperref[def:propositional_semantics]{semantical} concepts, it is immaterial which element of an equivalence class we consider. \\hyperref[def:boolean_closure]{Complete sets of Boolean operations} allow us to represent each formula using a strict subset of the \\hyperref[def:propositional_language/constants]{propositional constants}, \\hyperref[def:propositional_language/negation]{negation} and \\hyperref[def:propositional_language/connectives]{connectives}. \\Fullref{ex:thm:posts_completeness_theorem} shows some concrete commonly used complete sets of Boolean operations. This is also the motivation for studying \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebras}.\n\n  This is useful in\n  \\begin{itemize}\n    \\item Reduction to normal forms such as the \\hyperref[def:cnf_and_dnf]{conjunctive normal form} in \\fullref{alg:perfect_cnf_and_dnf}.\n\n    \\item \\hyperref[def:propositional_semantics/satisfiability]{Satisfiability} proofs that rely on \\hyperref[rem:structural_recursion_and_induction]{structural induction} because it allows us to consider less cases in the induction.\n\n    \\item Having fewer rules in \\hyperref[alg:perfect_cnf_and_dnf]{deductive systems}. For example, we may choose to add \\eqref{eq:thm:minimal_propositional_negation_laws/pierce} to the axioms of the \\hyperref[def:positive_implicational_deductive_system]{positive implicational derivation system} and due to \\fullref{thm:minimal_propositional_negation_laws} this derivation system would be able to emulate the \\hyperref[def:classical_propositional_deductive_systems]{classical derivation system}.\n  \\end{itemize}\n\\end{remark}\n\n\\begin{definition}\\label{def:cnf_and_dnf}\\mcite[I.1.\\S4]{Яблонский1986}\n  We will now introduce \\term{conjunctive normal forms} (CNF) and \\term{disjunctive normal forms} (DNF) for propositional formulas. The concepts are related but distinct from that of \\hyperref[rem:lattice_polynomials]{lattice polynomials}.\n\n  \\begin{thmenum}\n    \\thmitem{def:cnf_and_dnf/grammar} The structure of these formulas is best described by the \\hyperref[rem:backus_naur_form]{grammar schema}:\n    \\begin{bnf*}\n      \\bnfprod{positive literal}     {P \\in \\boldop{Prop}} \\\\\n      \\bnfprod{negative literal}     {\\neg \\bnfpn{positive literal}} \\\\\n      \\bnfprod{literal}              {\\bnfpn{positive literal} \\bnfor \\bnfpn{negative literal}} \\\\\n      \\bnfprod{disjunct}             {\\bnfpn{literal} \\bnfor \\bnfts{(} \\bnfsp \\bnfpn{literal}  \\bnfsp \\bnfts{\\( \\vee \\)}   \\bnfsp \\bnfpn{disjunct} \\bnfsp \\bnfts{)}} \\\\\n      \\bnfprod{CNF}                  {\\bnfpn{CNF}     \\bnfor \\bnfts{(} \\bnfsp \\bnfpn{disjunct} \\bnfsp \\bnfts{\\( \\wedge \\)} \\bnfsp \\bnfpn{CNF}      \\bnfsp \\bnfts{)}} \\\\\n      \\bnfprod{conjunct}             {\\bnfpn{literal} \\bnfor \\bnfts{(} \\bnfsp \\bnfpn{literal}  \\bnfsp \\bnfts{\\( \\wedge \\)} \\bnfsp \\bnfpn{conjunct} \\bnfsp \\bnfts{)}} \\\\\n      \\bnfprod{DNF}                  {\\bnfpn{DNF}     \\bnfor \\bnfts{(} \\bnfsp \\bnfpn{conjunct} \\bnfsp \\bnfts{\\( \\vee \\)}   \\bnfsp \\bnfpn{DNF}      \\bnfsp \\bnfts{)}}\n    \\end{bnf*}\n\n    As usual, we utilize the convention in \\fullref{rem:propositional_formula_parentheses} and avoid excessive parentheses.\n\n    In this context, the terms \\term{conjunct} and \\term{disjunct} are commonly used to refer to sets of literals rather than the formulas containing them.\n\n    \\thmitem{def:cnf_and_dnf/variable_power} Given a variable \\( P \\) and a \\hyperref[def:boolean_value]{Boolean value} \\( x \\in \\set{ T, F } \\), define\n    \\begin{equation*}\n      P^x \\coloneqq \\begin{cases}\n        P      &x = T, \\\\\n        \\neg P &x = F.\n      \\end{cases}\n    \\end{equation*}\n\n    \\thmitem{def:cnf_and_dnf/perfect} Given a finite sequence of distinct variables \\( P_1, \\ldots, P_n \\), we say that a formula is in \\term{perfect} CNF with respect to them if the following conditions hold:\n    \\begin{thmenum}\n      \\thmitem{def:cnf_and_dnf/perfect/fullness} Every disjunct contains \\( n \\) literals and the \\( k \\)-th literal is either \\( P_k \\) or \\( \\neg P_k \\).\n      \\thmitem{def:cnf_and_dnf/perfect/ordering} The disjuncts are ordered \\hyperref[def:lexicographic_order]{lexicographically} so that, for the \\( k \\)-th literals, \\( L_k \\leq R_k \\) if either \\( L_k \\) is a negative literal or if both literals are positive.\n    \\end{thmenum}\n\n    A formula in perfect conjunctive normal form can be written as\n    \\begin{equation*}\n      \\bigwedge_{(x_1, \\ldots, x_n) \\in B} P_1^{x_1} \\vee \\cdots \\vee P_n^{x_n}.\n    \\end{equation*}\n\n    Perfect DNFs are defined analogously. These additional conditions ensure uniqueness --- see \\fullref{alg:perfect_cnf_and_dnf}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:cnf_and_dnf}\n  We list examples of formulas in \\hyperref[def:cnf_and_dnf]{conjunctive and disjunctive normal forms}:\n  \\begin{thmenum}\n    \\thmitem{def:cnf_and_dnf/perfect_cnf} The \\hyperref[thm:boolean_equivalences]{Boolean equivalence} \\eqref{eq:thm:boolean_equivalences/conditional_as_disjunction} allows us to convert the \\hyperref[def:propositional_language/connectives/conditional]{conditional} \\( P \\to Q \\) to \\( \\neg P \\vee Q \\), which is both in CNF and in DNF.\n\n    It is its own only disjunct, and it contains both variable, hence it is in perfect CNF.\n\n    The DNF is not perfect, however. because neither conditions \\fullref{def:cnf_and_dnf/perfect/fullness} nor \\fullref{def:cnf_and_dnf/perfect/ordering} are satisfied.\n\n    \\thmitem{def:cnf_and_dnf/perfect_dnf} Consider instead the formula\n    \\begin{equation*}\n      (\\neg P \\wedge \\neg Q) \\vee (\\neg P \\wedge Q) \\vee (P \\wedge Q).\n    \\end{equation*}\n\n    It is in perfect DNF, and it is equivalent to \\( P \\to Q \\).\n  \\end{thmenum}\n\\end{example}\n\n\\begin{algorithm}[Perfect CNFs and DNFs]\\label{alg:perfect_cnf_and_dnf}\\mcite[thm. I.1.3]{Яблонский1986}\n  Let \\( f(x_1, \\ldots, x_n) \\) be an arbitrary \\hyperref[def:boolean_function]{Boolean function}. We will build a formula in \\hyperref[def:cnf_and_dnf/perfect]{perfect disjunctive normal form} and one in \\hyperref[def:cnf_and_dnf/perfect]{perfect conjunctive normal form}. The \\hyperref[def:propositional_formula_induced_function]{induced function} of both of these formulas will be \\( f \\). Both formulas are unique, as we will show.\n\n  \\begin{thmenum}\n    \\thmitem{alg:perfect_cnf_and_dnf/guard} If \\( f \\) is constant, the constant itself is both a perfect CNF and DNF.\n\n    \\thmitem{alg:perfect_cnf_and_dnf/algorithm} Suppose that \\( f \\) is nonconstant and fix some propositional variables \\( P_1, \\ldots, P_n \\). The following is a formula in perfect CNF whose \\hyperref[def:propositional_formula_induced_function]{induced function} is \\( f \\):\n    \\begin{equation}\\label{alg:perfect_cnf_and_dnf/cnf}\n      \\bigwedge_{f(x_1, \\ldots, x_n) = F} P_1^{x_1} \\vee \\cdots \\vee P_n^{x_n}.\n    \\end{equation}\n\n    Assuming that \\( F < T \\), we order the disjuncts with respect to the \\hyperref[def:lexicographic_order]{lexicographic order} on the set \\( \\set{ T, F }^n \\) to which the tuples of Boolean values \\( (x_1, \\ldots, x_n) \\) belong.\n\n    \\hyperref[def:semilattice/duality]{Dually}, we construct the perfect DNF as\n    \\begin{equation}\\label{alg:perfect_cnf_and_dnf/dnf}\n      \\bigvee_{f(x_1, \\ldots, x_n) = T} P_1^{\\overline{x_1}} \\wedge \\cdots \\wedge P_n^{\\overline{x_n}},\n    \\end{equation}\n  \\end{thmenum}\n\\end{algorithm}\n\\begin{defproof}\n  We will derive existence and uniqueness of perfect DNFs simultaneously from first principles. The derivation for CNFs is dual, but is more convoluted conceptually.\n\n  Fix sequences of Boolean values \\( a_1, \\ldots, a_n \\) and \\( x_1, \\ldots, x_n \\). Then\n  \\begin{center}\n    \\begin{tabular}{c c | c}\n      \\( x_k \\) & \\( a_k \\) & \\( P_k^{\\overline{x_k}}\\Bracks{a_k} \\) \\\\\n      \\hline\n      \\( F \\)   & \\( F \\)   & \\( T \\) \\\\\n      \\( F \\)   & \\( T \\)   & \\( F \\) \\\\\n      \\( T \\)   & \\( F \\)   & \\( F \\) \\\\\n      \\( T \\)   & \\( T \\)   & \\( T \\)\n    \\end{tabular}\n  \\end{center}\n\n  Therefore, \\( P_k^{\\overline{x_1}}\\Bracks{a_k} = T \\) if and only if \\( x_k = a_k \\). Then\n  \\begin{equation*}\n    \\parens*{ P_1^{\\overline{x_1}} \\vee \\cdots \\vee P_n^{\\overline{x_1}} }\\bracks{ a_1, \\ldots, a_n }\n    =\n    \\begin{cases}\n      T, &a_k = x_k \\T{for all} k = 1, \\ldots, n, \\\\\n      F, &\\T{otherwise.}\n    \\end{cases}\n  \\end{equation*}\n\n  Given some set \\( B \\subseteq \\set{ T, F }^n \\), we have\n  \\begin{equation*}\n    \\parens*{ \\bigvee_{(x_1, \\ldots, x_n) \\in B} P_1^{\\overline{x_1}} \\vee \\cdots \\vee P_n^{\\overline{x_n}} }\\bracks{ a_1, \\ldots, a_n } = T\n  \\end{equation*}\n  if and only if there exists some tuple \\( (x_1, \\ldots, x_n) \\in B \\) such that \\( x_k = a_k \\) for every index \\( k \\). That is, if the tuple \\( (a_1, \\ldots, a_n) \\) belongs to the complement \\( B \\). This leads us to the only possible definition\n  \\begin{equation*}\n    B \\coloneqq \\set{ (x_1, \\ldots, x_n) \\given f(x_1, \\ldots, x_n) = T }.\n  \\end{equation*}\n\\end{defproof}\n", "meta": {"hexsha": "5876269fa51ee76e43164c97e70c5a4a775764a9", "size": 39648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/propositional_logic.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/propositional_logic.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/propositional_logic.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.0165745856, "max_line_length": 691, "alphanum_fraction": 0.7156224778, "num_tokens": 12116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.6879706992311974}}
{"text": "\n\\subsection{The random effects estimator}\n\n\\subsubsection{Introduction}\n\nOur model is:\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta + \\xi_j + \\epsilon_{ij}\\)\n\n\\subsubsection{FGLS recap}\n\n\\subsubsection{The random effects estimator}\n\nFor fixed effects, we had the requirement that group membership be uncorrelated with the error term, but that it could be correlated with other independent variables.\n\nFor random effects models, group membership cannot be correlated with other variables.\n\nWe have:\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta +\\epsilon_{ij}+U_{ij}\\)\n\nWe now model \\(U_{ij}=\\bar U_{j}+\\rho_j\\).\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta +\\epsilon_{ij}+\\bar U_{j}+\\rho_j\\)\n\nThis randomness of the effect implies, for example, that if we ran the survey again we would expect a different effect\n\n\\subsubsection{Clustering standard error}\n\n\\subsubsection{Estimation}\n\nWe use GLS.\n\n", "meta": {"hexsha": "444b496961a96da3a8897d20e4d02fc45161ee23", "size": 858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generalLinearModels/04-01-random.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generalLinearModels/04-01-random.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generalLinearModels/04-01-random.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.2352941176, "max_line_length": 166, "alphanum_fraction": 0.7435897436, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6879479676123503}}
{"text": "\\documentclass[notitlepage]{problem-solving}\n\n\\author{Matt McCarthy}\n\\date{June 2016}\n\\title{Roots of Unity}\n\n\\usepackage{pgf,tikz}\n\\usepackage{mathrsfs}\n\\usetikzlibrary{arrows}\n\n\\definecolor{qqwuqq}{rgb}{0.,0.39215686274509803,0.}\n\\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1.}\n\\definecolor{qqqqff}{rgb}{0.,0.,1.}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{problem*}\n\tFactor the polynomial\n\t\\[\n\t\tp=z^5-1.\n\t\\]\n\\end{problem*}\n\n\\section{Background}\n\nThe complex numbers, denoted as $\\CC$ are defined as follows.\n\\begin{definition}\n\tThe set of \\textit{complex numbers} is the following two-dimensional vector space over the real numbers.\n\t\\[\n\t\t\\CC := \\set{a+bi\\, :\\, a,b\\in\\RR,\\, i^2 = -1}\n\t\\]\n\\end{definition}\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.5cm,y=1.5cm]\n\t\\draw[->,color=black] (-0.5,0.) -- (2.5,0.);\n\t\\foreach \\x in {,1.,2.}\n\t\\draw[shift={(\\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);\n\t\\draw[color=black] (2.6,-0.15) node [anchor=south west] {$x$};\n\t\\draw[->,color=black] (0.,-0.5) -- (0.,2.5);\n\t\\foreach \\y in {,1.,2.}\n\t\\draw[shift={(0,\\y)},color=black] (2pt,0pt) -- (-2pt,0pt);\n\t\\draw[color=black] (-0.2,2.8) node [anchor=west] {$iy$};\n\t\\clip(-0.5,-0.5) rectangle (2.5,2.5);\n\t\\draw[color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (2.,0.22277768022923544) -- (1.7772223197707646,0.22277768022923547) -- (1.7772223197707646,0.) -- (2.,0.) -- cycle;\n\t\\draw [shift={(0.,0.)},color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (0,0) -- (0.:0.3150552167742013) arc (0.:45.:0.3150552167742013) -- cycle;\n\t\\draw (0.,0.)-- (2.,2.);\n\t\\draw (2.,2.)-- (2.,0.);\n\t\\draw (0.,0.)-- (2.,0.);\n\t\\begin{scriptsize}\n\t\\draw [fill=qqqqff] (2.,2.) circle (2.5pt);\n\t\\draw[color=qqqqff] (2.0719752655925316,2.191528364493368) node {$z$};\n\t\\draw [fill=qqqqff] (0.,0.) circle (2.5pt);\n\t\\draw[color=qqqqff] (-0.15,-0.15) node {$0$};\n\t\\draw[color=black] (0.8012525579365867,1.109838786901943) node {$r$};\n\t\\draw [fill=xdxdff] (2.,0.) circle (2.5pt);\n\t\\draw[color=xdxdff] (2.2,0.185676817697619) node {$a$};\n\t\\draw[color=black] (2.1664918306247922,0.9838167001922624) node {$b$};\n\t\\draw [fill=xdxdff] (0.,2.) circle (2.5pt);\n\t\\draw[color=xdxdff] (-0.22792781685913763,2.023498915547127) node {$b$};\n\t\\draw[color=black] (1.0322930502376675,-0.19238944243142264) node {$a$};\n\t\\draw[color=qqwuqq] (0.4,0.15) node {$\\theta$};\n\t\\end{scriptsize}\n\t\\end{tikzpicture}\n\t\\caption{A diagram of the complex plane.\\label{c}}\n\\end{figure}\n\\noindent Furthermore, all $z\\in\\CC$ have a \\textit{polar form}\n\\[\n\tz=r(\\cos\\theta+i\\sin\\theta)\n\\]\nwhere $r,\\theta\\in\\RR$ with $r\\geq 0$.\nMoreover, $\\theta$ is called the \\textit{argument} of $z$.\nAdditionally, we have Euler's formula which allows us to write the polar form of a complex number more concisely.\n\\begin{thm}\n\tFor all $\\theta\\in\\RR$,\n\t\\[\n\t\te^{i\\theta} = \\cos\\theta+i\\sin\\theta.\n\t\\]\n\\end{thm}\n\\noindent Thus, any $z\\in\\CC$ can be written as\n\\[\n\tz=re^{i\\theta}.\n\\]\nMoreover, for any $z=a+bi=re^{i\\theta}\\in\\CC$, the \\textit{modulus} of a $z$ is defined as\n\\[\n\t|z| := \\sqrt{a^2+b^2} = r.\n\\]\nLastly, an \\textit{$n$th root of unity} is a $z\\in\\CC$ such that\n\\[\n\tz^n = 1.\n\\]\n\n\\section{Solution}\n\n\\begin{problem*}\n\tFactor the polynomial\n\t\\[\n\t\tp=z^5-1.\n\t\\]\n\\end{problem*}\n\n\\noindent In order to factor $p$, we want to find the roots of the equation\n\\[\n\tz^5 - 1= 0.\n\\]\nEquivalently, we will find the 5th roots of unity, or the solutions to\n\\[\n\tz^5 = 1.\n\\]\nTo begin, we know that $z=re^{i\\theta}$ for some $r\\geq 0$ and $\\theta\\in\\RR$.\nFurthermore, we know that $1=e^{2ki\\pi}$ for all $k\\in\\ZZ$.\nThus,\n\\[\n\tr^5e^{5i\\theta} = e^{2ki\\pi}\n\\]\nfor all $k\\in\\ZZ$.\nSince $|e^{i\\phi}| = 1$ for all $\\phi\\in\\RR$, we know that $r^5 = 1$.\nThus, $r=1$ because $r$ is a positive real.\nThus, we are left with\n\\[\n\te^{5i\\theta}=e^{2ki\\pi}.\n\\]\nErgo,\n\\[\n\t\\theta = 2ki\\pi/5\n\\]\nfor all $k\\in\\ZZ$.\nHowever, this is an infinite solution set and there are only 5 \\textit{distinct} solutions.\nTo find these distinct solutions, we use the fact that\n\\[\n\te^{i\\theta} = e^{i(\\theta+2k\\pi)}\n\\]\nfor any $k\\in\\ZZ$.\nThus, our distinct values for $\\theta$ are as follows.\n\\[\n\t\\theta\\in\\set{0, 2\\pi/5, 4\\pi/5, 6\\pi/5, 8\\pi/5}\n\\]\nWhen $\\theta =10\\pi/5 = 2\\pi$, we get the same result as when $\\theta=0$ since $2\\pi\\equiv 0\\mod{2\\pi}$.\nTherefore,\n\\[\n\tz\\in S:=\\set{1,e^{2\\pi/5}, e^{4\\pi/5}, e^{6\\pi/5}, e^{8\\pi/5}}.\n\\]\nSince each of the elements of the solution set is a root of the polynomial, $z^5-1$, we can factor out $z-r$ from $p$ for each $r\\in S$.\nThus,\n\\[\n\tp = z^5-1=(z-1)(z-e^{2\\pi/5})(z-e^{4\\pi/5})(z-e^{6\\pi/5})(z-e^{8\\pi/5}).\n\\]\n\n\\end{document}\n", "meta": {"hexsha": "f907e6b9005fccfdbff7bbb73caeb9e9968d5953", "size": 4591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-summer/roots-of-unity/roots-of-unity.tex", "max_stars_repo_name": "matt-mccarthy/problem-solving", "max_stars_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2016-summer/roots-of-unity/roots-of-unity.tex", "max_issues_repo_name": "matt-mccarthy/problem-solving", "max_issues_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016-summer/roots-of-unity/roots-of-unity.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": 30.2039473684, "max_line_length": 166, "alphanum_fraction": 0.6384230015, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146847, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6879396128220903}}
{"text": "\\chapter{Newton polygons}\n\tWe'll now introduce a very useful tool to study radius of convergence and zeroes of an analytic function: the Newton polygon. We'll first introduce it for polynomials and then try to generalize our results to power series.\n\t\\section{Newton polygons for polynomials}\n\t\t\\begin{defn}\n\t\t\t\\label{defn:newton-polygon-polynomials}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^n a_iX^i \\in 1 + X\\Cp[X]$ be a polynomial and consider the following set of points in $\\R^2$:\n\t\t\t\\[\n\t\t\t\\Gamma := \\{(0,0)\\} \\cup \\left\\{(i, \\ord a_i) \\mid a_i \\neq 0, i \\in \\{1, \\dots, n\\}\\right\\}.\n\t\t\t\\]\n\t\t\tThe \\emph{Newton polygon} of $f(X)$ is the inferior convex hull of these points, i.e. the highest convex polygonal line joining $(0, 0)$ with $(n, \\ord a_n)$ which passes on or below all the points in $\\Gamma$.\n\t\t\\end{defn}\n\t\tA nice way to think at the Newton polygon is the following: we begin with a vertical line through $(0,0)$ and we rotate it about $(0,0)$ counter-clockwise until we hit some point of $\\Gamma$; then we consider the segment joining $(0,0)$ with the last point we hit ($P$) as the first segment of the Newton polygon and we continue to rotate the line counter-clockwise about $P$ and repeat the procedure.\n\t\t\\begin{example}\n\t\t\tIn \\cref{figure:figure4.1} it is shown the Newton polygon for $f(X) = 1 + X^2 + \\tfrac{1}{3}X^3 + 3X^4 + 54X^5$ in $\\Q_3[X]$. \n\t\t\t\\begin{figure}\n\t\t\t\t\\centering \n\t\t\t\t\\includegraphics[scale=2.5]{/home/carlo/Tesi/images/figure_4_1}\n\t\t\t\t\\caption{Newton polygon of $f(X) \\in \\Q_3[X]$}\n\t\t\t\t\\label{figure:figure4.1}\n\t\t\t\\end{figure}\n\t\t\\end{example}\n\t\tLet's introduce some basic terms we'll adopt from now on.\n\t\t\\begin{defn}\n\t\t\tThe \\emph{vertices} of the Newton polygon are the points $\\left(i_j, \\ord a_{i_j}\\right)$ where the slope changes, the \\emph{segments} of the Newton polygon are the segments joining one vertex to the next one; if a segment joins $(i, m)$ to $(i', m')$ its slope is $\\tfrac{m' - m}{i' -i}$ and its length is $i' - i$, i.e. the length of its projection onto the horizontal axis.\n\t\t\\end{defn}\n\t\tWe have defined the Newton polygon only for a polynomial with constant term $1$, but this doesn't cause loss of generality because the main use of the Newton polygon is to characterize zeroes (and radius of convergence) of $f(X)$. Given a generic $g(X) \\in \\Cp[X]$ we can write:\n\t\t\\[\n\t\t\tg(X) = b_kX^k + \\dots + b_nX^n = b_k\\cdot X^k \\cdot \\left(1 + \\frac{b_{k+1}}{b_k}X + \\dots + \\frac{b_n}{b_k}X^{n-k}\\right) =: b_k \\cdot X^k \\cdot f(X)\n\t\t\\]\n\t\tand we can study $f(X)$, which satisfies our initial hypothesis.\tBefore proving our main result about the Newton polygon for polynomials, let's recall what symmetric polynomials are.\n\t\t\\begin{defn}\n\t\t\tLet $K$ be a commutative ring with unit, $\\underline{X} := (X_1, \\dots, X_n)$ and let $P(\\underline{X}) \\in K[\\underline{X}]$ be a polynomial in $n$ variables. We say that $P(\\underline{X})$ is symmetric if for every $\\sigma \\in S_n$ we have $P(X_{\\sigma(1)}, \\dots, X_{\\sigma(n)}) = P(X_1, \\dots, X_n)$, where $S_n$ is the symmetric group of $n$ elements. \\newline\n\t\t\tThe symmetric polynomials $\\left\\{e_i(\\underline{X}) : i \\in \\{0, 1, \\dots, n\\}\\right\\}$ defined by\n\t\t\t\\begin{gather*}\n\t\t\t\te_0(\\underline{X}) = 1,\\\\\n\t\t\t\te_k(\\underline{X}) = \\sum_{1 \\leq i_1 < \\dots < i_k \\leq n} X_{i_1}X_{i_2}\\dots X_{i_k}\n\t\t\t\\end{gather*}\n\t\t\tare the \\emph{elementary symmetric polynomials}.\n\t\t\\end{defn}\n\t\tIt is well known that the symmetric polynomials in $n$ variables form a subring $K[\\underline{X}]^{S_n}$ and if $P(\\underline{X})$ is symmetric then there exists $Q(\\underline{Y}) \\in K[\\underline{Y}]$ such that $P(\\underline{X}) = Q(e_1(\\underline{X}), \\dots, e_n(\\underline{X}))$, i.e. the elementary symmetric polynomials ``generate'' all symmetric polynomials.\n\t\tIt is easy to prove that if $f(X) \\in K[X]$ is a monic polynomial of degree $n$ (here we add the hypothesis that $K$ is an integral domain, i.e. there are no divisors of zero) and all its roots are $\\alpha_1, \\dots, \\alpha_n$ then\n\t\t\\[\n\t\t\tf(X) = \\prod_{j=1}^n \\left(X - \\alpha_j\\right) = \\sum_{j=0}^n (-1)^{n-j} \\cdot e_{n-j}(\\alpha_1, \\dots, \\alpha_n) \\cdot X^j,\n\t\t\\]\n\t\twhich is a precise relation between the coefficients of $f$ and its roots. Finally we recall that if $f(X) = 1 + \\sum_{i=1}^n a_iX^i \\in K[X]$ has degree $n$ (here $K$ is a field) and $\\alpha_1, \\dots, \\alpha_n$ are all of its roots, we can write\n\t\t\\[\n\t\tf(X) = \\prod_{j=1}^n \\left(1 - \\frac{X}{\\alpha_j}\\right) = \\sum_{j=0}^n (-1)^j \\cdot e_j\\left(\\frac{1}{\\alpha_1}, \\dots, \\frac{1}{\\alpha_n}\\right) \\cdot X^j;\n\t\t\\]\n\t\tin-fact $f(0) = 1$ and we can divide by $1 = (-1)^na_n\\alpha_1\\dots\\alpha_n$ both sides of $f(X) = a_n(X - \\alpha_1)\\dots(X - \\alpha_n)$.\\newline\n\t\tWe are ready to state and prove the following.\n\t\t\\begin{thm}\n\t\t\t\\label{thm:newton-polygon-polinomial-zeroes}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^n a_iX^i \\in 1 + X\\Cp[X]$ be a polynomial of degree $n$, let $\\alpha_1, \\dots, \\alpha_n \\in \\Cp$ be all of its roots and $\\lambda_i := \\mathrm{ord}_p\\,\\left(1/\\alpha_i\\right)$. If $\\lambda$ is a slope of the Newton polygon of $f$ with length $l$, it follows that precisely $l$ of the $\\lambda_i$ are equal to $\\lambda$. Vice-versa, if $\\gamma$ is a \\padic order of a reciprocal root then there is a segment of the Newton polygon with slope $\\gamma$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tThe last statement is trivial if we prove the first one: in-fact the total length of the Newton polygon is $n$ so we have already considered all the roots (counting multiplicity).\\newline\n\t\t\tLet's suppose the $\\alpha_i$ arranged so that $\\lambda_1 \\leq \\lambda_2 \\leq \\dots \\leq \\lambda_n$. Let's suppose that $\\lambda_1 = \\lambda_2 = \\dots = \\lambda_r < \\lambda_{r+1}$. We then claim that the first segment of the Newton polygon is the one joining $(0,0)$ to $(r, r\\lambda_1)$. We know that $a_i = (-1)^i \\cdot e_i\\left(1/\\alpha_1, \\dots, 1/\\alpha_n\\right)$ and, recalling how the $i$-th elementary symmetric polynomial is defined (sum of all possible products of $i$ different variables) and that $\\ord(x + y) \\geq \\min\\{\\ord(x),\\ord(y)\\}$, we obtain \n\t\t\t\\[\n\t\t\t\\ord(a_i) \\geq i\\lambda_1,\n\t\t\t\\]\n\t\t\twhich means that the point $(i, \\ord(a_i))$ is on or above the line joining $(0,0)$ to $(r, r\\lambda_1)$. Let's now consider $a_r$: only one of the products of $r$ of the $1/\\alpha_i$ has \\padic order $r\\lambda_1$ and it is exactly $1/(\\alpha_1 \\dots \\alpha_r)$, while all the other products have bigger \\padic order since they must include at least one $1/\\alpha_i$ with $i > r$. Then, by the isosceles triangle principle, $\\ord(a_r) = r\\lambda_1$. Finally, let's consider $a_i$ with $i > r$: for the same reasoning as before we have $\\ord(a_i) > i\\lambda_1$. \\newline\n\t\t\tAll these considerations means exactly that the first segment of the Newton polygon is the one joining $(0,0)$ and $(r, r\\lambda_1) = (r, \\lambda_1 + \\dots + \\lambda_r)$. Now, if we have $\\lambda_s < \\lambda_{s+1} = \\dots = \\lambda_{s+t} < \\lambda_{s+t+1}$ the line joining $(s, \\lambda_1 + \\dots + \\lambda_s)$ to $(s+t, \\lambda_1 + \\dots + \\lambda_s + t\\lambda_{s+1})$ is a segment of the Newton polygon. The proof is very similar: if $s \\leq i$ then $\\ord(a_i) \\geq \\lambda_1 + \\dots + \\lambda_s + (i-s)\\lambda_{s+1}$, since this is the minimum \\padic order in $e_i\\left(1/\\alpha_1, \\dots, 1/\\alpha_n\\right)$, reached for example by $1/(\\alpha_1\\dots\\alpha_i)$, $\\ord(a_{s+t}) = \\lambda_1 + \\dots + \\lambda_s + t\\lambda_{s+1}$ by the isosceles triangle principle and if $i > s+t$ then $\\ord(a_i) > \\lambda_1 + \\dots +\\lambda_s + (i - s)\\lambda_{s+1}$ since we have to choose at least one $1/\\alpha_j$ with $j > s+t$.\n\t\t\\end{proof}\n\t\tThis theorem, in other words, says that the slopes of the Newton polygon of $f(X)$ are counting with multiplicity the \\padic orders of the reciprocal roots of $f(X)$. The aim of the rest of this chapter will be to extend this result to formal power series, but we'll need to do a little more work before. \n\t\\section{Newton polygons for power series}\n\t\tThe definition of the Newton polygon for $f(X) \\in 1 + X\\Cp\\ser{X}$ is the same of \\cref{defn:newton-polygon-polynomials}: it is the inferior convex hull of all the points in $\\Gamma$ (which, this time, will be infinite). Sometimes we'll denote the Newton polygon of $f(X)$ by $\\mathfrak{N}(f)$. From now on we'll only consider proper power series, i.e. we'll exclude the case in which $f(X)$ is a polynomial. We can distinguish three different kinds on Newton polygon.\n\t\t\\begin{enumerate}[label=(\\arabic*)]\n\t\t\t\\label{enumerate:newton-polygon-types}\n\t\t\t\\item We get infinitely many segments of finite length, for example the Newton polygon $f(X) = 1 + \\sum_{i=1}^{+\\infty} p^{i^2}X^i$ shown in \\cref{figure:figure4.2}.\n\t\t\t\\item At some point the line we're rotating simultaneously hits infinite points. In this case the Newton polygon has only a finite number of segments, the last one being infinitely long. An example is $f(X) = 1 + \\sum_{i=1}^{+\\infty} X^i$, whose Newton polygon is simply the horizontal axis.\n\t\t\t\\item At some point the line we're rotating has not hit any point yet but it cannot rotate any farther without passing above some points. If this happens, we let the last segment of the Newton polygon have slope equal to the least upper bound of all possible slopes for which the line passes below all the points. A simple example is given by $f(X) = 1 + \\sum_{i=1}^{+\\infty} pX^i$, whose Newton polygon is the horizontal axis as shown in \\cref{figure:figure4.3}.\n\t\t\\end{enumerate}\n\t\tThere is a degenerate case of type $(3)$: the vertical line through $(0,0)$ cannot be rotated at all without crossing above some points $(i, \\ord a_i)$. An example of this possibility is given by $f(X) = \\sum_{i=0}^{+\\infty} \\tfrac{X^i}{p^{i^2}}$, whose Newton polygon is shown in \\cref{figure:figure4.3.1}.\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\subfloat[][Newton polygon of type 1 \\label{figure:figure4.2}]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_2}} \\qquad \\qquad\n\t\t\t\\subfloat[][Newton polygon of type 3 \\label{figure:figure4.3}]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_3}} \\\\\n\t\t\t\\subfloat[][Degenerate Newton polygon \\label{figure:figure4.3.1}]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_3_1}} \\qquad \\qquad\n\t\t\t\\subfloat[][Newton polygon of $f(X)$ \\label{figure:figure4.4}]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_4}}\t\n\t\t\t\\caption{Various Newton polygons}\t\t\n\t\t\\end{figure}\n\t\tWe'll exclude this case from our study since, as we'll prove in the next proposition, all such series have zero radius of convergence.\n\t\t\\begin{prop}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ be a power series whose Newton polygon is a degenerate case of type $(3)$, i.e. \n\t\t\t\\[\n\t\t\t\t\\forall m \\in \\R \\quad \\exists i_m \\in \\N : \\mathrm{ord}_p\\, a_{i_m} < m \\cdot i_m.\n\t\t\t\\]\n\t\t\tThen the radius of convergence of $f$ is $0$.\n\t\t\\end{prop} \n\t\t\\begin{proof}\n\t\t\tWe just need to prove that $\\limsup\\, \\pabs{a_n}^{1/n} = +\\infty$. Let's define a subsequence of the coefficients $(a_{n_k})_{k \\geq 1}$ by induction. We set $n_1 = i_{-1}$ so that $(n_1, \\ord a_{n_1})$ lies below the line $y = -x$. Let's now consider the lines $\\ell_1$, joining $(0, 0)$ to $(n_1, \\ord a_{n_1})$, and $\\ell_2$, with equation $y = -2x$: by hypothesis there must be an infinite number of points $(i, \\ord a_i)$ lying below both of these two lines. Then there is at least one such point $(j, \\ord a_j)$ with $j > n_1$ and we set $n_2 := j > n_1$. We can iterate this procedure (every time we choose $n_k > n_{k-1}$ such that $(n_k, \\ord a_{n_k})$ lies below both $y = -kx$ and the line joining $(0,0)$ to $(n_{k-1}, \\ord a_{n_{k-1}})$). We have obtained an increasing sequence $(n_k)_{k \\geq 1} \\subseteq \\N$ such that\n\t\t\t\\[\n\t\t\t\t\\ord a_{n_k} < -k \\cdot n_k \\implies \\pabs{a_{n_k}}^{1/n_k} > p^k.\n\t\t\t\\]\n\t\t\tUsing this subsequence we can conclude.\n\t\t\\end{proof}\n\t\tFrom now on we'll always consider analytic functions with a non-trivial disc of convergence. Before proving general properties of the Newton polygon of analytic functions, let's consider a concrete example.\n\t\t\\begin{example}\n\t\t\tLet's consider the function $f$ defined by\n\t\t\t\\[\n\t\t\t\tf(X) = \\sum_{n=0}^{+\\infty} \\frac{X^n}{n+1} = \\frac{1}{X} \\cdot \\sum_{n=0}^{+\\infty} \\frac{X^{n+1}}{n+1} = -\\frac{1}{X} \\cdot \\log_p(1 - X).\n\t\t\t\\]\n\t\t\tLooking at the right member it's immediate to see that $f$ converges in $D(1^-)$. If we denote $\\ell_i$ the segment joining $\\left(p^i-1, -i\\right)$ to $\\left(p^{i+1}-1, -i-1\\right)$ then it's easy to see that the Newton polygon of $f$ is the polygonal line $\\bigcup_{i \\in \\N} \\ell_i$ shown in \\cref{figure:figure4.4} for $p=3$.\n\t\t\tAssuming that the power series analogue of \\cref{thm:newton-polygon-polinomial-zeroes} holds, then, by looking at the Newton polygon of $f$, we would expect to find exactly $p^{i+1} - p^i$ roots having \\padic order $1/\\left(p^{i+1} - p^i\\right)$ for every $i \\in \\N$ and no other roots. \\newline \n\t\t\tLet's prove this claim: let's fix $j \\in \\N$ and consider $x = 1 - \\zeta$, where $\\zeta \\in \\Cp$ is a primitive $p^{j+1}$-th root of $1$. Then we know by \\cref{exercise:7-p.74} that $\\ord x = 1/\\left(p^{j+1} - p^j\\right)$ and that $\\log_p(1 - x) = 0$ by \\cref{corollary:log-root-of-1} so $f(x) = 0$. Since there are exactly $p^{i+1} - p^i$ primitive roots of $1$, we have found all the predicted roots. Let's now prove that there are no other roots of $f$, i.e. any root is of the form $1 - \\xi$ where $\\xi$ is a primitive $p^k$-th root of $1$. Let $x \\in D(1^-)$ be a root of $f$ and let\n\t\t\t\\[\n\t\t\t\tx_j := 1 - (1 - x)^{p^j}\n\t\t\t\\]\n\t\t\tfor any $j \\in \\N$. Using Newton's binomial expansion we get\n\t\t\t\\[\n\t\t\t\t\\pabs{x_j} = \\pabs{1 - (1 - x)^{p^j}} = \\pabs{\\sum_{i=1}^{p^j} \\binom{p^j}{i} (-x)^i} \\leq \\pabs{x} < 1,\n\t\t\t\\]\n\t\t\twhich implies $x_j \\in D(1^-)$ for every $j$. We claim that for any $M > 0$ we can find $j_m \\in \\N$ such that $\\pabs{x_{j_m}}< M$. Fixed $M > 0$ we just need to find a $j$ such that\n\t\t\t\\[\n\t\t\t\t\\max_{1 \\leq i \\leq p^j} \\pabs{\\binom{p^j}{i}x^i} < M.\n\t\t\t\\]\n\t\t\tSince $\\pabs{x} < 1$ we can find $N \\in \\N$ such that if $n > N$ then $\\pabs{\\binom{p^j}{n}x^n} < M$. Now we just need to find a $j$ such that\n\t\t\t\\[\n\t\t\t\t\t\\max_{1 \\leq i \\leq N} \\pabs{\\binom{p^j}{i}x^i} < M.\n\t\t\t\\]\n\t\t\tWriting $m := \\max_{1 \\leq i \\leq N} (1/\\pabs{i!}) > 0$ we have that\n\t\t\t\\[\n\t\t\t\t\\pabs{\\binom{p^j}{i}} \\leq \\pabs{\\frac{p^j}{i!}} \\leq \\pabs{p^j} \\cdot m\n\t\t\t\\]\n\t\t\tand we can conclude, since $\\pabs{p^j} \\to 0$ as $j \\to +\\infty$. Now let's consider $j \\in \\N$ such that $x_j \\in D(r_p^-)$; thanks to \\cref{prop:exp-and-log-inverse} we have\n\t\t\t\\[\n\t\t\t\t1 - x_j = \\exp_p(\\log_p(1 - x_j)) =\\exp_p\\left(p^j\\cdot \\log_p(1 - x)\\right) = \\exp_p(0) = 1\n\t\t\t\\]\n\t\t\thence $(1 - x)^{p^j} = 1$ so that $x = 1 - \\zeta$ where $\\zeta$ is a $p^j$-th root of $1$ and it's one of the roots we already considered. \\newline\n\t\t\tWe have proved that, for this particular $f(X)$, the power series analogue of \\cref{thm:newton-polygon-polinomial-zeroes} holds.\n\t\t\\end{example}\n\t\tLet's now prove a simple but interesting result which explains how we can find the radius of convergence of a series just by looking at its Newton polygon.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:newton-polygon-radius-convergence}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ and let $b$ be the least upper bound of all slopes of the Newton polygon of $f$. Then the radius of convergence of $f(X)$ is $p^b$ (if $b=+\\infty$ then $f$ converges everywhere).\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet's fix $x \\in \\Cp$ with $\\pabs{x} < p^b$, i.e. $-b' := \\ord x > -b$. Then $\\ord(a_ix^i) = \\ord a_i -ib'$ but, since $b' < b$, it's clear that sufficiently far out all the points $(i, \\ord a_i)$ will lie arbitrarily far above $(i, b'i)$, see \\cref{figure:figure4.5}. This means exactly $\\lim_{i\\to +\\infty} \\ord(a_ix^i) = +\\infty$, i.e. $f(X)$ converges at $x$. \\begin{figure}\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[scale=1.5]{/home/carlo/Tesi/images/figure_4_5}\n\t\t\t\t\\caption{Case $\\protect\\pabs{x} < p^b$} % Workaround, it works\n\t\t\t\t\\label{figure:figure4.5}\n\t\t\t\\end{figure}\n\t\t\tLet's now consider the case $\\pabs{x} > p^b$, i.e. $-b' := \\ord x < -b$. Since $b' > b$ we find an infinite number of $i \\in \\N$ such that $\\ord(a_ix^i) = \\ord a_i - ib' < 0$ which implies that $f(X)$ does not converge at $x$. We can then conclude that the radius of convergence of $f$ is exactly $p^b$.\n\t\t\\end{proof}\n\t\tObviously this proposition doesn't tell us anything about the convergence of $f(X)$ at the radius of convergence, i.e. if $\\pabs{x} = p^b$. \n\t\t\\begin{prop}\n\t\t\t\\label{prop:newton-polygon-circonference-convergence}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ be an analytic power series with radius of convergence $r=p^b$, where $b$ is the least upper bound of the slopes of the Newton polygon. Then $f(X)$ converges on $D(r)$ if and only if $\\mathfrak{N}(f)$ is of type $(3)$ (see the beginning of \\cref{enumerate:newton-polygon-types}) and $\\lim_{i \\to +\\infty} d_i = +\\infty$, where $d_i$ is the distance between $(i, \\mathrm{ord}_p\\, a_i)$ and the last line of $\\mathfrak{N}(f)$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tIf $b \\notin \\Q$ there's nothing to prove since no element of $\\Cp$ can have order $b$; from now on we'll assume $b \\in \\Q$.\n\t\t\tFirst of all we prove that if the Newton polygon of $f$ is of type $(1)$ or $(2)$ then $f(X)$ does not converge if $\\pabs{x} = p^b$. \\newline \n\t\t\tLet's first consider a Newton polygon of type $(1)$ and let $\\Lambda$ be the set of all its slopes. Then $b = \\sup \\Lambda$ and if $b = +\\infty$ there's nothing to prove. If $b < +\\infty$ then there exists $y_0 \\in \\R$ such that $\\ell\\colon y = y_0 + bx$ is an ``asymptote'' of the Newton polygon, see \\cref{figure:figure-extra-1} (the slopes are increasing and their $\\sup$/$\\lim$ is $b$). Then we can consider the vertices of the Newton polygon, indexed by $\\left(i_j\\right)_{j \\in \\N}$. It is clear that the distance $d_j$ between $\\left(i_j, \\ord a_{i_j}\\right)$ and $\\ell$ tends to $0$ and so does $\\left(\\ord a_{i_j} - i_jb\\right)$, which is equal to $d_j/\\cos(\\arctan b)$ (if $b=0$ then it is equal to $d_j$). If $\\pabs{x} = p^b$ then $\\ord x = -b$ so $\\ord(a_ix^i) = \\ord a_i - ib$. We then conclude that $\\ord(a_ix^i) \\not\\to +\\infty$ when $i \\to +\\infty$, i.e. $f$ does not converge at $x$. \n\t\t\tInstead if $f$ has a Newton polygon of type $(2)$ then $b$ is its final slope and, by definition, there are infinite points on this final segment. This means that if we call the final line $\\ell\\colon y_0 + bx$ then we can find an increasing subsequence $\\left(i_j\\right)_{j \\in \\N} \\subseteq \\N$ such that $\\ord a_{i_j} = y_0 + i_jb$ so $\\ord\\left(a_{i_j}x^{i_j}\\right) = y_0 \\not\\to +\\infty$ and we can conclude that there's no convergence in $x$.\\newline\n\t\t\tLet's now suppose that $\\mathfrak{N}(f)$ is of type $(3)$ and $x \\in \\Cp$ with $\\pabs{x} = p^b$. Then $f(X)$ converges in $x$ if and only if $\\lim_{i \\to +\\infty} \\ord\\left(a_ix^i\\right) = +\\infty$; as before, with a little trigonometry, we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\ord\\left(a_ix^i\\right) = \\ord a_i - ib = \n\t\t\t\t\\begin{cases}\n\t\t\t\t\td_i, & \\text{if $b=0$;} \\\\\n\t\t\t\t\t\\frac{d_i}{\\cos(\\arctan b)}, & \\text{otherwise;} \n\t\t\t\t\\end{cases}\n\t\t\t\\end{gather*}\n\t\t\tand we can conclude (by hypothesis $\\lim_{i \\to +\\infty} d_i = +\\infty$). An example is $f(X) = 1 + \\sum_{i=1}^{+\\infty} 2^iX^{2^i} \\in 1 + X\\C_2\\ser{X}$, whose Newton polygon is shown in \\cref{figure:figure4.5.1}.\n\t\t\t\\begin{figure}\n\t\t\t\t\\centering\n\t\t\t\t\\subfloat[][Newton polygon with an asymptote \\label{figure:figure-extra-1}]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_extra_1}} \\qquad\n\t\t\t\t\\subfloat[][Newton polygon with convergence at border \\label{figure:figure4.5.1}]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_5_1}}\n\t\t\t\t\\caption{Two other types of Newton polygons}\n\t\t\t\\end{figure}\n\t\t\\end{proof}\n\t\tLet's introduce a useful trick we'll often use in the next proofs.\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:newton-polygon-translation}\n\t\t\tLet $c \\in \\Cp^\\times$ with $\\mathrm{ord}_p\\, c = \\lambda$, $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ and $g(X) := f\\left(X/c\\right)$. Then the Newton polygon of $g$ is obtained subtracting the line $y = \\lambda x$ to the Newton polygon of $f$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tIf we write $g(X) = 1 + \\sum_{i=1}^{+\\infty} b_iX^i$ then it's immediate that $b_i = a_i/\\left(c^i\\right)$ so $\\ord b_i = \\ord a_i - i\\lambda$ and we can conclude.\n\t\t\\end{proof}\n\t\tWe'll now prove four technical lemmas we'll then use to prove our final result.\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:lemma6-p.102}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ and suppose that $\\lambda_1$ is the first slope of its Newton polygon. Let $c \\in \\Cp$ with $\\mathrm{ord}_p\\,c = \\lambda \\leq \\lambda_1$ and assume that $f(X)$ converges on the closed disc $D(p^{\\lambda})$ (this automatically happens if $\\lambda < \\lambda_1$ or if the Newton polygon has more than one segment). Let \n\t\t\t\\[\n\t\t\t\tg(X) = (1 - cX)f(X) \\in 1 + X\\Cp\\ser{X}.\n\t\t\t\\]\n\t\t\tThen $\\mathfrak{N}(g)$ is obtained by joining $(0,0)$ to $(1, \\lambda)$ and then translating $\\mathfrak{N}(f)$ by $\\vec{v} = (1, \\lambda)$ ($1$ to the right and $\\lambda$ upwards). If $\\mathfrak{N}(f)$ has last slope $\\lambda_f$ and $f(X)$ converges on $D(p^{\\lambda_f})$ then $g(X)$ also converges on $D(p^{\\lambda_f})$. Conversely, if $g(X)$ converges on $D(p^{\\lambda_f})$ then so does $f(X)$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tA graphic interpretation of the lemma can be found at \\cref{figure:figure4.6}.\n\t\t\t\\begin{figure}\n\t\t\t\t\\centering\n\t\t\t\t\\subfloat[][Newton polygon of $f_1(X)$]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_6_1}} \\qquad \\qquad \\subfloat[][Newton polygon of $g_1(X)$]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_6_2}} \\\\\n\t\t\t\t\\subfloat[][Newton polygon of $f(X)$]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_6_3}} \\qquad \\qquad\n\t\t\t\t\\subfloat[][Newton polygon of $g(X)$]{\\includegraphics[scale=1.25]{/home/carlo/Tesi/images/figure_4_6_4}} \n\t\t\t\t\\caption{Example of \\protect\\cref{lemma:lemma6-p.102}}\n\t\t\t\t\\label{figure:figure4.6}\n\t\t\t\\end{figure}\n\t\t\tWe can consider only the special case $c=1, \\lambda = 0$. In-fact, let's suppose the lemma holds for this case and let $f(X)$ and $g(X)$ as in the statement. Then $f_1(X) := f\\left(\\tfrac{X}{c}\\right)$ and $g_1(X) := (1 - X)f_1(X)$ satisfy our hypothesis (with the parameters $\\underline{c}=1, \\underline{\\lambda} = 0, \\underline{\\lambda_1} = \\lambda_1 - \\lambda$, by \\cref{lemma:newton-polygon-translation}). Thus, since we're assuming the lemma to be true if $c=1$, we know the shape of the Newton polygon of $g_1(X)$ (and the convergence of $g_1(X)$ on $D(p^{\\lambda_f - \\lambda})$ when $f$ converges on $D(p^{\\lambda})$). Now, $g(X) = g_1(cX)$ so,  using again \\cref{lemma:newton-polygon-translation}, we obtain the desired information about the Newton polygon of $g(X)$ (and the desired convergence, which is immediate). So we can just prove the lemma when $c = 1$.\\newline\n\t\t\tIf $g(X) = 1 + \\sum_{i=1}^{+\\infty} b_iX^i$ then, since by definition $g(X) = (1 - X)f(X)$, we have $b_{i+1} = a_{i+1} - a_i$ for $i \\geq 0$ (clearly $a_0 = 1$). Then\n\t\t\t\\begin{equation*}\n\t\t\t\t\\ord b_{i+1} \\geq \\min\\left\\{\\ord a_{i+1}, \\ord a_i \\right\\} \\tag{$\\star$}\n\t\t\t\\end{equation*}\n\t\t\tand the equality holds when $\\ord a_{i+1} \\neq \\ord a_i$. It is easy to see that both $(i, \\ord a_i)$ and $(i, \\ord a_{i+1})$ lie on or above the Newton polygon of $f(X)$ and so does $(i, \\ord b_{i+1})$, by $(\\star)$. If $(i, \\ord a_i)$ is a vertex then necessarily $\\ord a_{i+1} > \\ord a_i$ so $\\ord b_{i+1} = \\ord a_i$. This means exactly that the Newton polygon of $g(X)$ has the shape described in the lemma, as far as the last vertex of $f(X)$. If $\\mathfrak{N}(f)$ is of type $(1)$ we can conclude here: there is no last vertex and no last slope. It remains only to show that when $\\mathfrak{N}(f)$ has last slope $\\lambda_f$ then also $\\mathfrak{N}(g)$ does and if $f(X)$ converges on $D(p^{\\lambda_f})$ then so does $g(X)$. We already know $\\ord b_{i+1} \\geq \\min\\left\\{\\ord a_{i+1}, \\ord a_i \\right\\}$ so $g(X)$ converges wherever $f(X)$ does; then if $\\lambda_g$ is the least upper bound of the slopes of $\\mathfrak{N}(g)$ we have $\\lambda_g \\geq \\lambda_f$ (by \\cref{prop:newton-polygon-radius-convergence}). We must only rule out the case $\\lambda_g > \\lambda_f$. If it were the case, then, for some large $i$, the point $(i+1, \\ord a_i)$ would lie below $\\mathfrak{N}(g)$ so we'd have $\\ord b_j > \\ord a_i$ for every $j  \\geq i+1$ (this holds in this particular case where $\\lambda = 0$ since $0 \\leq \\lambda_1 \\leq \\lambda_f < \\lambda_g$). Using $j = i+1$ we obtain $\\ord a_{i+1} = \\ord a_i$ because $a_{i+1} = b_{i+1} + a_i$. Then, using $j = i+2$, we obtain $\\ord a_{i+2} = \\ord a_{i+1} = \\ord a_i$ and so on for every $j$. This means $\\ord a_j = \\ord a_i$ for every $j \\geq i$ and contradicts the assumed convergence of $f(X)$ on $D(1) \\subseteq D(p^{\\lambda_f})$. Then we must have $\\lambda_g = \\lambda_f$ and $\\mathfrak{N}(g)$ is exactly of the predicted shape. This implies in particular that if $f(X)$ converges on $D(p^{\\lambda_f})$ then so does $g(X)$ (see \\cref{prop:newton-polygon-circonference-convergence}). The converse assertion, i.e. convergence of $g(X)$ implies convergence of $f(X)$, can be proved in an analogue way.\n\t\t\\end{proof}\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:lemma7-p.103}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ have Newton polygon with first slope $\\lambda_1$. Let's assume that $f(X)$ converges on $D\\left(p^{\\lambda_1}\\right)$ and that the line $\\ell\\colon y = \\lambda_1x$ actually passes through a point $(i, \\mathrm{ord}_p\\, a_i)$ with $i \\geq 1$ (both of these conditions are automatically satisfied if $\\mathfrak{N}(f)$ has more than one slope). Then there exists an $x \\in \\Cp$ for which $\\mathrm{ord}_p\\, x = -\\lambda_1$ and $f(x) = 0$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tLet's first consider the case $\\lambda_1 = 0$ and then reduce the general case to this one. If $\\lambda_1 = 0$ we have $\\ord a_i \\geq 0$ for every $i \\in \\N$ and $\\lim_{i \\to +\\infty} \\ord a_i = +\\infty$ since $f(X)$ converges on $D(1)$. Let $N := \\max \\left\\{i \\in \\N^\\times : \\ord a_i=0 \\right\\}$ and let $f_n(X) := 1 + \\sum_{i=1}^n a_iX^i \\in 1 + X\\Cp[X]$. By \\cref{thm:newton-polygon-polinomial-zeroes}, if $n \\geq N$ then the polynomial $f_n(X)$ has precisely $N$ roots with \\padic order $0$, let them be $x_{n, 1}, \\dots, x_{n, N}$ (it's immediate that $\\mathfrak{N}(f_n)$ has a first segment with slope $0$ and length $N$). Let's define a sequence: $x_N := x_{N, 1}$ and, for $n \\geq N$, $x_{n+1} := x_{n+1, i}$ where $i$ is such that  $\\pabs{x_{n+1, i} - x_n}$ is minimal. We claim that $\\left(x_n\\right)_{n \\geq N} \\subseteq \\Cp$ is Cauchy and its limit $x$ is the desired root of $f$. If $S_n$ denotes the set containing the roots of $f_n(X)$, counted with multiplicity, for $n \\geq N$ we have\n\t\t\t\\[\n\t\t\t\t\\pabs{f_{n+1}(x_n) - f_n(x_n)} = \\pabs{f_{n+1}(x_n)} = \\prod_{\\alpha \\in S_{n+1}} \\pabs{1 - \\frac{x_n}{\\alpha}}\n\t\t\t\\]\n\t\t\twhere we used $f_n(x_n) = 0$ and $f_{n+1}(X) = \\prod_{\\alpha \\in S_{n+1}} \\left(1 - \\tfrac{X}{\\alpha}\\right)$. It's clear that if $\\alpha \\in S_{n+1}$ then $\\ord \\alpha \\leq 0$: in-fact we cannot have $\\ord \\alpha > 0$ and $f_{n+1}(\\alpha) = 0$ by the isosceles triangle principle (recall that $\\ord a_i \\geq 0$). Now if $\\alpha \\in S_{n+1}$ has $\\ord \\alpha < 0$ then $\\pabs{1 - \\tfrac{x_n}{\\alpha}} = 1$, since $\\pabs{x_n} = 1$. Then we can write\n\t\t\t\\[\n\t\t\t\t\\pabs{f_{n+1}(x_n) - f_n(x_n)} = \\prod_{i=1}^N \\pabs{1 - \\frac{x_n}{x_{n+1, i}}} = \\prod_{i=1}^N \\pabs{x_{n+1, i} - x_n} \\geq \\pabs{x_{n+1} - x_n}^N,\n\t\t\t\\]\n\t\t\tby the choice of $x_{n+1}$. We have obtained\n\t\t\t\\[\n\t\t\t\t\\pabs{x_{n+1} - x_n}^N \\leq \\pabs{f_{n+1}(x_n) - f_n(x_n)} = \\pabs{a_{n+1}x_n^{n+1}} = \\pabs{a_{n+1}} \n\t\t\t\\]\n\t\t\tso $\\lim_{n \\to +\\infty} \\pabs{x_{n+1} - x_n}^N = 0$ (by hypothesis $\\lim_{n \\to +\\infty} \\pabs{a_{n+1}} = 0$) and we have proved that $\\left(x_n\\right)_{n \\geq N}$ is Cauchy (see \\cref{lemma:cauchy-sequence-ultrametric}). Since $\\Cp$ is complete there exists $x := \\lim_{n \\to +\\infty} x_n$ and, by continuity of $\\pabs{\\ }$, we have $\\pabs{x} = 1$. It's clear that for any $y \\in D(1)$ we have $\\lim_{n \\to +\\infty} f_n(y) = f(y)$ (the \\padic absolute value of the difference tends to zero) so we have $f(x) = \\lim_{n \\to +\\infty} f_n(x)$. Now,\n\t\t\t\\[\n\t\t\t\t\\pabs{f_n(x)} = \\pabs{f_n(x) - f_n(x_n)} = \\pabs{x - x_n}\\cdot\\pabs{\\sum_{i=1}^n a_i\\frac{x^i - x_n^i}{x - x_n}} \\leq \\pabs{x - x_n}\n\t\t\t\\]\n\t\t\tbecause $\\pabs{a_i} \\leq 1$ and $\\pabs{\\tfrac{x^i - x_n^i}{x - x_n}} = \\pabs{x^{i-1} + x^{i-2}x_n + \\dots + x_n^{i-1}} \\leq 1$. Hence we can conclude that $f(x) = \\lim_{n \\to +\\infty} f_n(x) = 0$ and we have proved the lemma if $\\lambda_1 = 0$.\\newline\n\t\t\tThe general case follows easily. Let $\\pi \\in \\Cp$ be any number with $\\ord \\pi = \\lambda_1$. Clearly such a $\\pi$ exists: for example, if $(i, \\ord a_i)$ lies on $y=\\lambda_1x$ and $i \\geq 1$ (such a point exists by assumption) then $\\pi$ can be any $i$-th root of $a_i$ (recall that $\\Cp$ is algebraically closed). Now let $g(X) := f\\left(X/\\pi\\right)$; it's clear by \\cref{lemma:newton-polygon-translation} that $g(X)$ satisfies the conditions of the lemma with $\\lambda_1 = 0$. Then we already \n\t\t\tknow that there exists $x_0$ with $\\ord x_0 = 0$ such that $g(x_0) = 0$. Then if $x = x_0/\\pi$ we have $\\ord x = -\\lambda_1$ and $f(x) = f\\left(x_0/\\pi\\right) = g(x_0) = 0$.\n\t\t\\end{proof}\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:lemma8-p.105}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ and let $\\alpha \\in \\Cp$ such that $f(\\alpha) = 0$. Let $g(X)$ be obtained by dividing $f(X)$ by $1 - \\tfrac{X}{\\alpha}$. Then $g(X)$ converges on $D(\\pabs{\\alpha})$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tFirst of all, let's observe that $\\alpha \\neq 0$ and that dividing $f(X)$ by $1 - \\tfrac{X}{\\alpha}$ is the same thing of multiplying $f(X)$ by the geometric series $\\sum_{i=0}^{+\\infty} \\left(\\tfrac{X}{\\alpha}\\right)^i$. Let's write $g(X) = 1 + \\sum_{i=1}^{+\\infty} b_iX^i$ and let $f_n(X) := 1 + \\sum_{i=1}^n a_iX^i$ be the $n$-th partial sum of $f(X)$. By an easy computation we infer that\n\t\t\t\\[\n\t\t\t\tb_i = \\sum_{j=0}^i \\frac{a_j}{\\alpha^j}\n\t\t\t\\]\n\t\t\twhere we set $a_0 = 1$. Then it's easy to see that\n\t\t\t\\[\n\t\t\t\tb_i\\alpha^i = f_i(\\alpha)\n\t\t\t\\]\n\t\t\thence $\\pabs{b_i\\alpha^i} = \\pabs{f_i(\\alpha)} \\to 0$ as $i \\to +\\infty$, since $f(\\alpha) = 0$ and $f(x) = \\lim_{n \\to +\\infty}f_n(x)$ wherever $f$ converges. This means exactly that $g(X)$ converges on $D(\\pabs{\\alpha})$.\n\t\t\\end{proof}\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:order-zeroes-function}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ such that $\\lambda$ is the first slope of $\\mathfrak{N}(f)$ and $f$ converges on some disc $D$. If $\\alpha \\in D$ is a root of $f$, i.e. $f(\\alpha) = 0$, then $\\mathrm{ord}_p\\, \\alpha \\leq -\\lambda$. If $\\lambda$ is the only slope of $\\newt{f}$ and no point of $\\newt{f}$ lies on $y=\\lambda x$, then $\\mathrm{ord}_p\\,\\alpha < -\\lambda$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tLet's suppose that $\\alpha \\in D$ is such that $\\ord \\alpha = -\\lambda' > -\\lambda$. We have\n\t\t\t\\[\n\t\t\t\t\\ord(a_i\\alpha^i) = \\ord a_i -i\\lambda' > \\ord a_i -i\\lambda \\geq 0,\n\t\t\t\\]\n\t\t\twhere we used that all the points $(i, \\ord a_i)$ lie on or above the line $y=\\lambda x$ (by definition of Newton polygon). Then we have $\\ord 1 = 0$ and $\\ord(a_i\\alpha^i) > 0$ for $i \\geq 1$ and so $\\alpha$ cannot be a root of $f$. The last statement can be proved with an analogue reasoning.\n\t\t\\end{proof}\n\t\tFinally we are ready to prove the main theorem of this section which will imply, as a corollary, the power series analogue of \\cref{thm:newton-polygon-polinomial-zeroes}.\n\t\t\\begin{thm}[\\padic Weierstrass Preparation Theorem]\n\t\t\t\\label{thm:weierstrass-padic-preparation}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ converge on $D(p^{\\lambda})$. Let $N$ be the total horizontal length of all segments in $\\mathfrak{N}(f)$ having slope less or equal to $\\lambda$ if this length is finite $($i.e. if $\\mathfrak{N}(f)$ hasn't an infinitely long last segment of slope $\\lambda)$. On the other hand, if the Newton polygon of $f$ has last slope $\\lambda$, then let $N$ be the greatest index $i$ such that $(i, \\ord a_i)$ lies on that final segment $($there must be such a final index since $f$ converges on $D(p^{\\lambda}))$. Then there exists a polynomial $h(X) \\in 1 + X\\Cp[X]$ of degree $N$ and a power series $g(X) = 1 + \\sum_{i=1}^{+\\infty} b_iX^i$, which converges and is non-zero on $D(p^{\\lambda})$, such that\n\t\t\t\\[\n\t\t\t\th(X) = f(X) \\cdot g(X).\n\t\t\t\\]\n\t\t\tThe polynomial $h(X)$ is uniquely determined by these properties and $\\mathfrak{N}(h)$ coincides with $\\mathfrak{N}(f)$ up to $x = N$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tWe use induction on $N$. Let's first consider the basic case $N = 0$, where the first slope of $\\mathfrak{N}(f)$ is greater or equal to $\\lambda$. In this case it's evident that we can assume $\\lambda \\in \\Q$ without loss of generality. We have to show that $g(X) = 1/f(X)$ converges and is non-zero on $D(p^{\\lambda})$ (recall that any power series with a non-zero constant term is invertible). We can only consider the special case $\\lambda = 0$. In-fact, let $f(X) \\in 1 + X\\Cp\\ser{X}$ converge on $D(p^{\\lambda})$: we can choose $c \\in \\Cp$ with $\\ord c = \\lambda$ using \\cref{prop:qpa-every-order} (we assumed $\\lambda \\in \\Q$) and then define $\\tilde{f}(X) := f\\left(\\tfrac{X}{c}\\right)$. Now, $\\tilde{f}$ converges on $D(1)$ and if $\\lambda = 0$ then $N = 0$, i.e. the first slope of its Newton polygon is greater or equal to $0$ by \\cref{lemma:newton-polygon-translation}. So, assuming the theorem holds when $N = \\lambda = 0$ we infer that there exists $\\tilde{g}(X) \\in 1 + X\\Cp\\ser{X}$ which converges and is non-zero on $D(1)$ such that $1 = \\tilde{f}(X)\\cdot\\tilde{g}(X)$. Using $cX$ in place of $X$ we obtain $1 =f(X) \\cdot \\tilde{g}(cX)$ and it's immediate that $g(X) := \\tilde{g}(cX)$ has all the desired properties. So we can only consider the special case $\\lambda = 0$. Thus, we can suppose $\\ord a_i > 0$ for every $i \\in \\N$ and $\\lim_{i \\to +\\infty} \\ord a_i = +\\infty$ (we have convergence on $D(1)$). It's easy to obtain the following equality for the coefficients of $g(X) = 1/f(X)$:\n\t\t\t\\[\n\t\t\t\tb_i = -\\left(\\sum_{j=1}^i b_{i-j}a_j \\right),\n\t\t\t\\]\n\t\t\twhere we set $b_0 = 1$. From an easy induction on $i$ it follows that $\\ord b_i > 0$ for $i \\geq 1$. This implies that the first slope of $\\mathfrak{N}(g)$ is greater than $0$ (or it's equal to $0$ but with no points on it) and, by \\cref{lemma:order-zeroes-function}, we know that $g$ doesn't have roots on $D(1)$. Now it remains only to show that $g(X)$ actually converges on $D(1)$, i.e. that $\\lim_{i \\to +\\infty} \\ord b_i = +\\infty$. Let's fix $M > 0$: we can find $m \\in \\N$ such that $i > m$ implies $\\ord a_i > M$. Now if\n\t\t\t\\[\n\t\t\t\t\\epsilon := \\min_{1 \\leq j \\leq m} \\ord a_j> 0\n\t\t\t\\]\n\t\t\twe claim that $i > nm$ implies $\\ord b_i > \\min\\{M, n\\epsilon\\}$, from which it easily follows $\\ord b_i \\to +\\infty$ as $i \\to +\\infty$. We'll prove this claim by induction on $n$. We have already proved the case $n = 0$. Now, let's suppose $n \\geq 1$ and that the claim holds for $n - 1$; if $i > nm$ we have\n\t\t\t\\[\n\t\t\t\tb_i = -\\left(b_{i-1}a_i + \\dots + b_{i-m}a_m + b_{i-(m+1)}a_{m+1} + \\dots + a_1 \\right).\n\t\t\t\\]\n\t\t\tThe terms $b_{i-j}a_j$ with $j > m$ have \\padic order greater than $M$, while if $j \\geq m$ we have $\\ord(b_{i-j}a_j) \\geq \\ord b_{i-j} + \\epsilon$ and, since $i - j > (n-1)m$, by inductive hypothesis we obtain\n\t\t\t\\[\t\n\t\t\t\t\\ord(b_{i-j}a_j) \\geq \\ord b_{i-j} + \\epsilon > \\min\\{M, (n-1)\\epsilon\\} + \\epsilon.\n\t\t\t\\]\n\t\t\tThis proves our claim, hence the theorem when $N = 0$ (the statement about the Newton polygon here is trivial since $h(X) = 1$).\\newline\n\t\t\tNow let's consider the general case with $N \\geq 1$ and suppose that the theorem holds for $N - 1$. Let $\\lambda_1 \\leq \\lambda$ be the first slope of $\\mathfrak{N}(f)$; if it is the only slope then, since $N \\geq 1$, there's at least one point on $y = \\lambda_1x$. We can then use \\cref{lemma:lemma7-p.103} to find $\\alpha$ such that $f(\\alpha) = 0$ and $\\ord \\alpha = -\\lambda_1$. Let's define\n\t\t\t\\[\n\t\t\t\tf_1(X) := \\frac{f(X)}{1 - \\frac{X}{\\alpha}} = f(X) \\cdot \\sum_{j=0}^{+\\infty} \\left(\\frac{X}{\\alpha}\\right)^j \\in 1 + X\\Cp\\ser{X}.\n\t\t\t\\]\n\t\t\tBy \\cref{lemma:lemma8-p.105}, $f_1$ converges on $D(p^{\\lambda_1})$. Setting $c := \\tfrac{1}{\\alpha}$ we have $f(X) = (1 - cX)\\cdot f_1(X)$. Let $\\lambda_1'$ be the first slope of $\\mathfrak{N}(f_1)$; it must necessarily be $\\lambda_1' \\geq \\lambda_1$. In-fact $\\lambda_1' < \\lambda_1$ implies that $\\mathfrak{N}(f_1)$ has more than one slope and that, by \\cref{lemma:lemma7-p.103}, $f_1$ has a root with \\padic order $-\\lambda_1'$ and so does $f$, but this is impossible by \\cref{lemma:order-zeroes-function} since $-\\lambda_1' > -\\lambda_1$. We can now apply \\cref{lemma:lemma6-p.102}, with parameters $\\underline{f} = f_1, \\underline{g} = f, \\underline{\\lambda} = \\lambda_1, \\underline{\\lambda_1} = \\lambda_1'$ and we get that $\\mathfrak{N}(f_1)$ is obtained translating $\\mathfrak{N}(f) \\setminus \\ell((0,0), (1, \\lambda_1))$ by $\\vec{v} = (-1, -\\lambda_1)$, where $\\ell(P, Q)$ is the segment joining $P$ to $Q$. We claim that $f_1$ converges on $D(p^{\\lambda})$: if $\\lambda$ isn't the final slope of $\\mathfrak{N}(f)$ then it's trivially true, otherwise \\cref{lemma:lemma6-p.102} tells us that when $\\mathfrak{N}(f)$ has last slope $\\lambda$ and $f$ converges on $D(p^{\\lambda})$ then so does $f_1$. Thus, $f_1$ satisfies all the conditions of the theorem with $N-1$ instead of $N$ (recall that, to obtain $\\mathfrak{N}(f_1)$, we removed a segment with slope $\\lambda_1 \\leq \\lambda$ and with length $1$ from $\\mathfrak{N}(f)$). By inductive hypothesis we can find $h_1(X) \\in 1 + X\\Cp[X]$ of degree $N-1$ and a series $g(X) \\in 1 + X\\Cp\\ser{X}$, convergent and non-zero on $D(p^{\\lambda})$, such that\n\t\t\t\\[\n\t\t\t\th_1(X) = f_1(X) \\cdot g(X).\n\t\t\t\\]\n\t\t\tMultiplying both sides by $(1 - cX)$ and setting $h(X) := (1 - cX)h_1(X)$ we obtain\n\t\t\t\\[\n\t\t\t\th(X) = f(X) \\cdot g(X),\n\t\t\t\\]\n\t\t\twhere $h$ and $g$ have the desired properties. Let's also observe that $\\mathfrak{N}(h_1)$ coincides with $\\mathfrak{N}(f_1)$ up to $x = N-1$ and that, since $h(X) = (1 - cX)h_1(X)$, $\\mathfrak{N}(h)$ is obtained joining $(0,0)$ to $(1, \\lambda_1)$ and then translating $\\mathfrak{N}(h_1)$. Then it's clear that $\\mathfrak{N}(h)$ will coincide with $\\mathfrak{N}(f)$ up to $x = N$.\\newline \n\t\t\tNow we have only to prove the uniqueness of $h(X)$ (we have only proved its existence).\n\t\t\tLet's suppose that $\\tilde{h}(X) \\in 1 + X\\Cp[X]$ is another polynomial of degree $N$ such that \\[\n\t\t\t\t\\tilde{h}(X) = f(X) \\cdot g_1(X),\n\t\t\t\\]\n\t\t\twhere $g_1(X) \\in 1 + X\\Cp\\ser{X}$ converges and is non-zero on $D(p^{\\lambda})$. We have\n\t\t\t\\[\n\t\t\t\t\\tilde{h}(X)\\cdot g(X) = f(X)\\cdot g(X) \\cdot g_1(X) = h(X) \\cdot g_1(X). \\tag{$*$}\n\t\t\t\\]\n\t\t\tTo prove uniqueness it suffices to show that $(*)$ implies that $h$ and $h_1$ have the same roots with the same multiplicities (they both have constant term $1$). The case $N=1$ is trivial. Let's now consider $N > 1$. The polynomial $h(X)$ is the one we built before so we already know that $\\mathfrak{N}(h)$ coincides with $\\mathfrak{N}(f)$ up to $x = N$. Using \\cref{thm:newton-polygon-polinomial-zeroes}, this means that every root of $h(X)$ is in $D(p^{\\lambda})$ (by assumption all the slopes of $\\mathfrak{N}(h)$ are less or equal to $\\lambda$). Let $\\alpha \\in \\Cp$ be a root of $h(X)$. Since $\\alpha \\in D(p^{\\lambda})$ we can compute $g(\\alpha)$ and $g_1(\\alpha)$ and, by hypothesis, they're not zero. So $\\alpha$ must also be a root of $\\tilde{h}(X)$. Let's define \n\t\t\t\\[\n\t\t\t\t\\tilde{k}(X) := \\frac{\\tilde{h}(X)}{1 - \\frac{X}{\\alpha}}, \\qquad k(X) := \\frac{h(X)}{1 - \\frac{X}{\\alpha}};\n\t\t\t\\]\n\t\t\tthey're two polynomials in $1 + X\\Cp[X]$ of degree $N - 1$ satisfying $\\tilde{k}(X)\\cdot g(X) = k(X)\\cdot g_1(X)$. We can repeat this process with every other root of $h(X)$ and, at the end, both polynomials will be $1$ so we have proved uniqueness.\n\t\t\\end{proof}\n\t\tThis is a very powerful theorem, with a lot of interesting corollaries.\n\t\t\\begin{corollary}\n\t\t\t\\label{corollary:newton-polygon-zeroes}\n\t\t\tIf a segment of the Newton polygon of $f(X) \\in 1 + X\\Cp\\ser{X}$ has finite length $N$ and slope $\\lambda$, then there are exactly $N$ values of $x$ (counting multiplicity) for which $f(x) = 0$ and $\\mathrm{ord}_p\\, x = -\\lambda$.\n\t\t\\end{corollary}\n\t\t\\begin{proof}\n\t\t\tIt is an immediate application of \\cref{thm:weierstrass-padic-preparation} and \\cref{thm:newton-polygon-polinomial-zeroes}. \n\t\t\\end{proof}\n\t\t\\begin{example}\n\t\t\tWe can use the Newton polygon to study the exact region of convergence of $\\E_p(X)$, the Artin-Hasse exponential (see \\cref{defn:artin-hasse}). We already know, by \\cref{prop:artin-hasse-formula} and \\cref{prop:artin-hasse-formula}, that\n\t\t\t\\[\n\t\t\t\t\\E_p(X) = \\exp_p\\left(\\sum_{i=0\n\t\t\t\t}^{+\\infty} \\frac{X^{p^i}}{p^i}\\right)\n\t\t\t\\]\n\t\t\tand that $\\E_p(X)$ converges on $D(1^-)$. We'll show that this is the exact region of convergence, i.e. that $\\E_p(X)$ doesn't converge if $\\pabs{x} = 1$. Let's define\n\t\t\t\\[\n\t\t\t\tf(X) = \\sum_{i=0}^{+\\infty} \\frac{X^{p^i -1}}{p^i} \\in 1 + X\\Cp\\ser{X},\n\t\t\t\\]\n\t\t\tso that $\\E_p(X) = \\exp_p(X \\cdot f(X))$. Now, $\\E_p(X)$ converges at $x \\in \\Cp$ if and only if $x\\cdot f(x) \\in D(r_p^-)$. We'll show that $f(X)$ doesn't even converge if $\\pabs{x} = 1$. Writing $f(X) = 1 + \\sum_{n=1}^{+\\infty} a_iX^i$, it's immediate that\n\t\t\t\\begin{gather*}\n\t\t\t\t(i, \\ord a_i) =\n\t\t\t\t\\begin{cases}\n\t\t\t\t\t\\left(p^k - 1, -k\\right), & \\text{if $\\exists k \\in \\N$ such that $i = p^k - 1$;} \\\\\n\t\t\t\t\t(i, 0), & \\text{otherwise;}\n\t\t\t\t\\end{cases}.\n\t\t\t\\end{gather*}\n\t\t\tIf $\\ell_i$ is the segment joining $\\left(p^i-1, -i\\right)$ to $\\left(p^{i+1}-1, -i-1\\right)$ then we have $\\mathfrak{N}(f) = \\bigcup_{i \\in \\N} \\ell_i$ (see \\cref{figure:figure-extra-2} for $p=2$). It is clearly a type $(1)$ polygon (infinite number of finite segments). The segment $\\ell_i$ has slope $\\lambda_i =- \\tfrac{1}{p^i(p - 1)} < 0$ and we have $\\lim_{i \\to +\\infty} \\lambda_i = 0$. This proves that $0$ is the least upper bound of all slopes of $\\mathfrak{N}(f)$ so, using \\cref{prop:newton-polygon-radius-convergence}, we can conclude: the radius of convergence of $f$ is $1 = p^0$ and we cannot have convergence ``at the border'', since we would need a type $(3)$ polygon.\n\t\t\t\\begin{figure}\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[scale=1.5]{/home/carlo/Tesi/images/figure_extra_2}\n\t\t\t\t\\caption{Newton polygon of $f(X)$ for $p=2$}\n\t\t\t\t\\label{figure:figure-extra-2}\n\t\t\t\\end{figure}\n\t\t\\end{example}\n\t\tFinally, we'll show a nice application of \\cref{thm:weierstrass-padic-preparation}, which will imply the non-existence of a non-constant power series which converges on $\\Cp$ and is never zero. This means exactly that we cannot have an exponential with the same properties of the classical one: in-fact in the classical case, if $h(X)$ is a convergent power series, then $e^{h(X)}$ is everywhere convergent and non-zero. We'll first need a technical lemma.\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:infinite-zeroes}\n\t\t\tLet $f(X)$ be a power series which converges on $D(p^{\\lambda})$. If $f(X)$ has an infinite number of zeroes on $D(p^{\\lambda})$ then $f(X)$ is identically zero.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tIf $f(X) = 0$ there's nothing to prove, otherwise we can assume, by contradiction, $f(X) \\in 1 + X\\Cp\\ser{X}$ (we can write $f(X) = a_dX^d \\cdot g(X)$, where $d$ is such that $a_d$ is the first non-zero coefficient and study $g(X) \\in 1 + X\\Cp\\ser{X}$). We can then apply \\cref{thm:weierstrass-padic-preparation}, using $\\lambda$, to obtain $N \\in \\N$, $h(X) \\in 1 + X\\Cp[X]$, a polynomial of degree $N$, and $g(X) \\in 1 + X\\Cp\\ser{X}$, a power series convergent and non-zero on $D(p^{\\lambda})$, such that\n\t\t\t\\[\n\t\t\t\th(X) = f(X) \\cdot g(X).\n\t\t\t\\]\n\t\t\tBy hypothesis, $f(X)$ has infinite zeroes in $D(p^{\\lambda})$ and, since $g(X)$ is never zero on $D(p^{\\lambda})$, $h(X)$ must have infinite zeroes on $D(p^{\\lambda})$. But $h(X)$ is a non-zero polynomial of degree $N$ so it cannot have infinite zeroes, and this is a contradiction. Thus the only possible case is $f(X) = 0$.\n\t\t\\end{proof}\n\t\t\\begin{prop}\n\t\t\tLet $f(X) = 1 + \\sum_{i=1}^{+\\infty} a_iX^i \\in 1 + X\\Cp\\ser{X}$ be an everywhere convergent power series. For every $\\lambda$, let $h_{\\lambda}(X)$ be the polynomial obtained applying \\cref{thm:weierstrass-padic-preparation}. Then $h_{\\lambda} \\to f$ as $\\lambda \\to +\\infty$ (i.e., each coefficient of $h_{\\lambda}$ converges to the corresponding coefficient of $f$). In particular, if $f$ is not a polynomial, then its zeroes are $(r_n)_{n \\geq 1}$ (i.e. they're countable infinite) and \n\t\t\t\\[\n\t\t\t\tf(X) = \\prod_{i=1}^{+\\infty} \\left(1 - \\frac{X}{r_i}\\right).\n\t\t\t\\] \n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tIf $f(X)$ is a polynomial, then the statement is trivial. From now on we'll consider $f(X)$ to be a proper power series. It's clear that such an $f$ must have a type $(1)$ Newton polygon. Let $(\\lambda_n)_{n \\geq 1}$ be the slopes of $\\mathfrak{N}(f)$ (clearly we consider them in order, i.e. such that $\\lambda_1 < \\lambda_2 < \\dots < \\lambda_n < \\dots$). Since $f(X)$ converges everywhere, by \\cref{prop:newton-polygon-radius-convergence} we must have $\\lim_{n \\to +\\infty} \\lambda_n = +\\infty$. It is also clear that $f$ has a countable infinite set of zeroes (there's clearly no contradiction here, because the zeroes are in $\\Cp$): in-fact, applying \\cref{corollary:newton-polygon-zeroes}, we obtain that for any segment of $\\mathfrak{N}(f)$ we have a finite number of zeroes (and clearly the segments of the Newton polygon are countable infinite). Let it be $(r_n)_{n \\geq 1}$, where they're listed in such a way that the first ``cluster'' corresponds to slope $\\lambda_1$, the second to slope $\\lambda_2$ and so on. Applying \\cref{thm:weierstrass-padic-preparation} with $\\lambda = \\lambda_n$ we obtain a polynomial $1 + X\\Cp[X] \\ni h_n(X) := h_{\\lambda_n}(X)$ and a power series $g_n(X) \\in 1 + X\\Cp\\ser{X}$, convergent and non-zero on $D(p^{\\lambda_n})$, such that\n\t\t\t\\[\n\t\t\t\th_n(X) = f(X) \\cdot g_n(X).\n\t\t\t\\]\n\t\t\tLet's introduce some terminology:\n\t\t\t\\begin{gather*}\n\t\t\t\th_n(X) = 1 + \\sum_{i=1}^{d_n} a_{n,i}X^i, \\qquad g_n(X) = 1 + \\sum_{i=1}^{+\\infty} b_{n, i}X^i,\n\t\t\t\\end{gather*}\n\t\t\twhere we set $d_n := \\deg h_n(X)$. By \\cref{thm:weierstrass-padic-preparation} we know that $d_n$ is the total horizontal length of segments of $\\mathfrak{N}(f)$ with slope less or equal to $\\lambda_n$ and this also means that\n\t\t\t\\[\n\t\t\t\th_n(X) = \\prod_{j=1}^{d_n} \\left(1 - \\frac{X}{r_j}\\right). \\tag{$*$}\n\t\t\t\\]\n\t\t\tFirst of all, let's prove that the sequences $(a_{n,m})_{n \\geq 1}$ are all Cauchy \\emph{uniformly} in $m$, i.e. we'll find an upper bound which doesn't depend on $m$. \n\t\t\tLet $k \\in \\N$ be such that $\\lambda_1 < \\dots < \\lambda_k < 0 \\leq \\lambda_{k+1}$, i.e. the first $k$ slopes of $\\mathfrak{N}(f)$ are negative. Let's consider $r_1, \\dots, r_{d_k}$, all the roots of $f$ (they're not necessarily distinct) corresponding to the negative slopes of $\\mathfrak{N}(f)$. Then $\\pabs{1/r_i} = p^{\\ord r_i} > 1$, for every $1 \\leq 1 \\leq d_k$. Instead, for any other root $r_m$ with $m > d_k$ we have $\\pabs{1/r_m} \\leq 1$, since it corresponds to a non-negative slope. Let's set $M := \\pabs{1/r_1}\\cdots\\pabs{1/r_{d_k}}$ (if all slopes are non-negative we simply set $M = 1$). Recalling the relations between coefficients and reciprocal of roots (using elementary symmetric polynomials), for $n \\geq k$, by $(*)$, we have\n\t\t\t\\[\n\t\t\t\ta_{n, m} = (-1)^m \\cdot e_m\\left(\\frac{1}{r_1}, \\dots, \\frac{1}{r_{d_k}}, \\frac{1}{r_{d_k + 1}}, \\dots, \\frac{1}{r_{d_n}}\\right).\n\t\t\t\\]\n\t\t\tSince for any $j > d_k$ we have $\\pabs{1/r_j} \\leq 1$, it's easy to see that\n\t\t\t\\[\n\t\t\t\t\\pabs{a_{n,m}} \\leq \\pabs{1/(r_1 \\cdots r_{d_k})} = M,\n\t\t\t\\]\n\t\t\tfor any $m \\in \\N$ and $n \\geq k$. We have found a common upper bound for all the coefficients of all the polynomials $h_n(X)$ with $n \\geq k$. Now we have\n\t\t\t\\[\n\t\t\t\th_{n+1}(X) = h_n(X) \\cdot \\prod_{j=d_n+1}^{d_{n+1}} \\left(1 - \\frac{X}{r_j}\\right)\n\t\t\t\\]\n\t\t\tso we obtain\n\t\t\t\\[\n\t\t\t\ta_{n+1, m} = a_{n, m} + \\sum_{j=1}^m (-1)^j\\cdot a_{n, m-j}\\cdot e_j\\left(\\frac{1}{r_{d_n + 1}}, \\dots, \\frac{1}{r_{d_{n+1}}}\\right),\n\t\t\t\\]\n\t\t\twhere we set $a_{n, 0} = 1$. Since $\\lim_{n \\to +\\infty} d_n = +\\infty$ (by construction) we can choose a large enough $n$ such that $\\lambda_{n+1} > 0$. Then, $\\pabs{1/r_j} = p^{\\ord r_j} = p^{-\\lambda_{n+1}} < 1$ for any $d_n + 1 \\leq j \\leq d_{n+1}$. Now it's easy to see that \n\t\t\t\\begin{gather*}\n\t\t\t\t\\forall\\, j \\in \\N, \\quad  \\pabs{e_j\\left(\\frac{1}{r_{d_n + 1}}, \\dots, \\frac{1}{r_{d_{n+1}}}\\right)} \\leq \\pabs{\\frac{1}{r_{d_n + 1}}} = p^{-\\lambda_{n+1}} \\\\\n\t\t\t\t\\implies \\pabs{a_{n+1, m} - a_{n,m}} = \\max_{1 \\leq j \\leq m} \\pabs{a_{n, m-j}\\cdot e_j\\left(\\frac{1}{r_{d_n + 1}}, \\dots, \\frac{1}{r_{d_{n+1}}}\\right) } \\leq M \\cdot  p^{-\\lambda_{n+1}}.\n\t\t\t\\end{gather*}\n\t\t\tSince  $\\lim_{n \\to +\\infty} p^{-\\lambda_{n+1}} = 0$, $(a_{n, m})_{n \\geq 1}$ is Cauchy (see \\cref{lemma:cauchy-sequence-ultrametric}). Let's observe that our bounds don't depend on $m$, i.e. $\\pabs{a_{n+1, m} - a_{n, m}} \\leq M\\cdot p^{-\\lambda_{n+1}}$ for any $m \\in \\N$ and $n \\geq k$. Since $(\\lambda_n)_{n \\geq 1}$ is non-decreasing, for $m > n \\geq k$ we obtain\n\t\t\t\\[\n\t\t\t\t\\pabs{a_{m, i} - a_{n, i}} \\leq \\max_{n \\leq j < m}\\pabs{a_{j+1, i} - a_{j,i}} \\leq \\max_{n \\leq j < m} Mp^{-\\lambda_{j+1}} = Mp^{-\\lambda_{n+1}}.\n\t\t\t\\]\n\t\t\t\t\n\t\t\tNow, we know that $g_n(X)$ converges and is non-zero on $D(p^{\\lambda_n})$; this means exactly that, if $\\gamma_n$ is the first slope of $\\mathfrak{N}(g_n)$, then $\\gamma_n > \\lambda_n$. In-fact, $\\gamma_n \\leq \\lambda_n$ would imply, by \\cref{corollary:newton-polygon-zeroes}, the existence of $\\alpha \\in \\Cp$ such that $\\pabs{\\alpha} = p^{\\gamma_n} \\leq p^{\\lambda_n}$ such that $g(\\alpha) = 0$ and this cannot be the case. From a geometrical point of view, this means that every point $(i, \\ord b_{n,i})$ lies on or above the line $y = \\gamma_n \\cdot x$, i.e.\n\t\t\t\\[\n\t\t\t\t\\ord b_{n,i} \\geq i \\cdot \\gamma_n.\n\t\t\t\\]\n\t \t\tWe have already proved that $\\lim_{n \\to +\\infty} \\lambda_n = +\\infty$ so $\\lim_{n \\to +\\infty} \\gamma_n = +\\infty$ and this implies $\\lim_{n \\to +\\infty} \\ord b_{n,i} = +\\infty$, i.e. $\\lim_{n \\to +\\infty} b_{n,i} = 0$ for every $i \\geq 1$. Let's now come back to the relation $h_n(X) = f(X)\\cdot g_n(X)$ and let's consider the single coefficients; we obtain \n\t\t\t\\begin{align*}\n\t\t\t\ta_{n, 1} &= b_{n,1} + a_1; \\\\\n\t\t\t\ta_{n, 2} &= b_{n,2} + a_1b_{n,1} + a_2; \\\\\n\t\t\t\t\\vdots \\\\\n\t\t\t\ta_{n, m} &= b_{n, m} + \\sum_{j=1}^{m-1} a_jb_{n, m-j} + a_m.\n\t\t\t\\end{align*}\n\t\t\tThen, for any $m \\geq 1$, we have $\\lim_{n \\to +\\infty} a_{n, m} = a_m$. Let's fix $x \\in D(1)$ and $\\epsilon > 0$ and consider\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{f(x) - h_n(x)} = \\pabs{\\sum_{i=1}^{+\\infty} (a_i - a_{n, i}) x^i} \\leq \\max\\left\\{\\max_{1 \\leq i \\leq d_n} \\pabs{a_i - a_{n,i}},\\, \\max_{i > d_n}\\,\\pabs{a_i} \\right\\}\n\t\t\t\\end{gather*}\n\t\t\twhere we set $a_{n, i} = 0$ if $i > d_n$. We already know $\\lim_{n \\to +\\infty} d_n =+\\infty$ and we know that $\\lim_{i \\to +\\infty} \\pabs{a_i} = 0$ since $f$ converges everywhere (see \\cref{prop:summable_families}). Let's choose $n \\in \\N$ such that $i > d_n$ implies $\\pabs{a_i} < \\epsilon$. Now we have only to give an upper bound on the first term, but this is easy thanks to the bounds we proved before:\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{a_i - a_{n, i}} = \\lim_{m \\to +\\infty} \\pabs{a_{m, i} - a_{n, i}} \\leq \\lim_{m \\to +\\infty} Mp^{-\\lambda_{n+1}} = Mp^{-\\lambda_{n+1}} \\\\\n\t\t\t\t\\implies \\max_{1 \\leq i \\leq d_n} \\pabs{a_i - a_{n,i}} \\leq M\\cdot p^{-\\lambda_{n+1}}\n\t\t\t\\end{gather*}\n\t\t\tand we can assume that $n \\in \\N$ is big enough such that $M\\cdot p^{-\\lambda_{n+1}} < \\epsilon$ and $i > d_n$ implies $\\pabs{a_i} < \\epsilon$. Since $\\epsilon$ is chosen arbitrarily, we conclude that if $x \\in D(1)$ then\n\t\t\t\\[\n\t\t\t\tf(x) = \\lim_{n \\to +\\infty} h_n(x) = \\lim_{n \\to +\\infty} \\prod_{j=1}^{d_n} \\left(1 - \\frac{x}{r_j}\\right) = \\prod_{j=1}^{+\\infty} \\left(1 - \\frac{x}{r_j}\\right).\n\t\t\t\\]\n\t\t\tLet's define $\\ell(X) := \\prod_{j=1}^{+\\infty} \\left(1 - \\frac{X}{r_j}\\right)$. It can be proved that $\\ell(X) \\in 1 + X\\Cp\\ser{X}$ exploiting the fact that $\\lim_{n \\to +\\infty} \\pabs{1/r_n} = 0$ and that its coefficient of $X^m$ is simply the sum of the series of all possible products of $m$ of the $-1/r_i$'s (which converges). Now, $\\ell(X)$ converges on $D(1)$ because $\\ell(x) = f(x)$ for any $x \\in D(1)$. We can conclude that, in $\\Cp\\ser{X}$, we have\n\t\t\t\\[\n\t\t\t\tf(X) = \\ell(X) = \\prod_{j=1}^{+\\infty} \\left(1 - \\frac{X}{r_j}\\right) \n\t\t\t\\]\n\t\t\tsince $g(X) := f(X) - \\ell(X)$ is a power series convergent on $D(1)$ with infinite zeroes and, by \\cref{lemma:infinite-zeroes}, it must be $g(X) = 0$. \t\n\t\t\\end{proof}\n\t\tThis proposition resembles a lot the Weierstrass factorization theorem of complex analysis, although the \\padic result is much more clean: there are no exponential factor in the product. One immediate implication is that any power series which converges everywhere and is never zero must be a constant: here is why we cannot have an exponential similar to the classic one, which converges everywhere, is never zero but isn't constant. Finally we can think as power series which converges everywhere simply as ``polynomials with infinite zeroes'', which can be factorized in the same exact way we factorize polynomials. ", "meta": {"hexsha": "661ffe2312ef809d4a0463e1a4cde4718cf08d17", "size": 53608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mainmatter/chapter5.tex", "max_stars_repo_name": "carlo300/BachelorThesis", "max_stars_repo_head_hexsha": "d7c1311e2abc12c80ffac864b74b214e6a63b9fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-21T10:59:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-29T10:11:24.000Z", "max_issues_repo_path": "Mainmatter/chapter5.tex", "max_issues_repo_name": "carlo300/BachelorThesis", "max_issues_repo_head_hexsha": "d7c1311e2abc12c80ffac864b74b214e6a63b9fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mainmatter/chapter5.tex", "max_forks_repo_name": "carlo300/BachelorThesis", "max_forks_repo_head_hexsha": "d7c1311e2abc12c80ffac864b74b214e6a63b9fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 123.8060046189, "max_line_length": 2053, "alphanum_fraction": 0.6460043277, "num_tokens": 19865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321703143954, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.6879395814245121}}
{"text": "\\section{Fermi's Goldern Rule - Revision}\n\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{0.1}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(\\mb{k'},\\mb{k},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    \\\\\n    & =\n    -2\\pi i \\delta(\\varepsilon_{\\beta} - \\varepsilon)\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    \\\\\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}\nLet's define the impurity potential matrix element as\n\\begin{equation} \\label{0.2}\n  V_{\\mb{k}, \\mb{k'}} = \\mel{\\mb{k'}}{V(\\mb{r})}{\\mb{k}}\n\\end{equation}\nand consider this for a given $k_x$ and $k'_x$ momentum value. This information is included in the $\\alpha$ and $\\beta$ quantum numbers. Also we can transform the $t'$ varable into $t$ and present above as\n\\begin{equation} \\label{0.3}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t) & =\n    \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} dk_y d{k'}_y \\;\n    V_{\\mb{k}, \\mb{k'}}\n    \\phi_{\\beta}^{\\dagger}(\\mb{k'},t)\n    \\phi_{\\alpha}(\\mb{k},t).\n  \\end{aligned}\n\\end{equation}\nUsing the derivation of \\textit{Floquet modes} in Eq. \\eqref{3.40} we expand this as\n\\begin{equation} \\label{0.4}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t) =\n    \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} dk_y d{k'}_y \\;\n    V_{\\mb{k}, \\mb{k'}} &\n    {\\sqrt{L_x}}\n    e^{\n      -ib\\sin(2\\omega t)\n    }\n    e^{\n      +ik'_y  \\qty[d\\sin(\\omega t) + y'_0]\n    }\n    \\tilde{\\chi}_{n_{\\beta}}\\qty(k'_y -g\\cos(\\omega t)) \\\\\n    & \\times\n    {\\sqrt{L_x}}\n    e^{\n      ib\\sin(2\\omega t)\n    }\n    e^{\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 this can be simplified to\n\\begin{equation} \\label{0.5}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t) =\n    L_x\n    \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} dk_y d{k'}_y \\;\n    V_{\\mb{k}, \\mb{k'}} &\n    e^{\n      i\\qty[k'_y - k_y]d\\sin(\\omega t)\n    }\n    e^{\n      i\\qty[k'_y y'_0 - k_y y_0]\n    }\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  \\end{aligned}\n\\end{equation}\nThen by definiton of the \\textit{transition probability} we can find the scattering probbaility as\n\\begin{equation} \\label{0.6}\n    \\qty(A_{\\alpha\\beta}(t) \\equiv\n    a_{\\alpha\\beta}(t)\\qty[a_{\\alpha\\beta}({k'}_x,k_x)]^{*}\n\\end{equation}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nxx\n", "meta": {"hexsha": "0f2a86b357c0673663b326dc3380fdd1623bbf7d", "size": 3099, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_00.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_00.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_00.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": 27.6696428571, "max_line_length": 205, "alphanum_fraction": 0.5514682156, "num_tokens": 1260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6878981888815029}}
{"text": "\\chapter{Proof of Linear Programming Formulation}\n\\label{LPproof}\n\\thispagestyle{empty}\n\n\\noindent This appendix provides the proof of Theorem \\ref{lpth} that we report here for completeness:\n\\begin{align*}\n\t\\underset{v}{\\text{minimize}} & \\; \\sum_{s \\in \\mathcal{S}} \\mu(s) v(s) \\\\\n\t\\text{subject to} &  \\; v(s) \\geq r(s,a) + \\sum_{s' \\in \\mathcal{S}} P(s' \\mid s,a) v(s') \\, , \\forall a \\in \\mathcal{A} \\, .\n\\end{align*} \n\n\\begin{theorem*}[Linear Programming Solution]\n$v^*$ is the solution of the above linear program.\n\\end{theorem*}\n\n\\begin{proof}\n\tLet $T^*$ be the Bellman optimality operator, then the above LP can be rewritten as:\n\t\\begin{align*}\n\t\\underset{v}{\\text{minimize}} & \\; \\mu^T v \\\\\n\t\\text{subject to} &  \\; v \\geq T^* (v) \\, .\n\\end{align*} \nUsing the \\textit{monotonicity property} if $v \\geq T^*(v)$, then $T^*(v) \\geq T^*(T^*(v))$, and by applying infinite times the operator we obtain: $v \\geq T^{* \\infty} (v) = v^*$. Any feasible solution of the LP must satisfy $v \\geq T^* (v)$, thus it must satisfy  $v \\geq v^*$. Hence, assuming all entries $\\mu$ are positive, $v^*$ is the optimal solution to the LP.\n\\end{proof}", "meta": {"hexsha": "3f1ef070a4160d330bc38c4a761f7bd2399b4865", "size": 1140, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/LPproof.tex", "max_stars_repo_name": "EmanueleGhelfi/thesis-remps-cmdp", "max_stars_repo_head_hexsha": "1b512b1684cfa6c8bac9a513b7f0f2e9cbc1eed5", "max_stars_repo_licenses": ["MIT"], "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/LPproof.tex", "max_issues_repo_name": "EmanueleGhelfi/thesis-remps-cmdp", "max_issues_repo_head_hexsha": "1b512b1684cfa6c8bac9a513b7f0f2e9cbc1eed5", "max_issues_repo_licenses": ["MIT"], "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/LPproof.tex", "max_forks_repo_name": "EmanueleGhelfi/thesis-remps-cmdp", "max_forks_repo_head_hexsha": "1b512b1684cfa6c8bac9a513b7f0f2e9cbc1eed5", "max_forks_repo_licenses": ["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.8181818182, "max_line_length": 368, "alphanum_fraction": 0.6526315789, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6877630344790356}}
{"text": "\\section{Examples}\n\\label{sec:examples}\n\n\n\\subsection{Floating Point Operations}\n\nPrincipal Components Analysis is a common statistical analysis technique.  The \nimplementation of PCA typically involves computing the singular value \ndecomposition (SVD) of the input data and then projecting the data onto the \nright singular vectors.  It is known that an SVD requires $6mn^2 + 20n^3$ \nfloating point operations and that the projection onto the right singular \nvectors requires an additional $2mn^2$ operations~\\citep{gvl}.  Finally, as PCA \nis usually performed on centered (and often scaled) data, we require an \nadditional $2*mn+1$ operations for centering the data.\n\nThe \\thispackage package contains the example \\code{pca.r} as a package demo, \nwhich will perform a PCA on random data consisting of $10,000$ observations and \n50 predictors.  The analysis uses \\R's ordinary \\code{prcomp()} routine, and \nthe performance is measured by \\thispackage's \\code{system.flops()}.  You can \nrun this demo by calling\n\n\\begin{lstlisting}[language=rr]\ndemo(\"pca\", package=\"pbdPAPI\")\n\\end{lstlisting}\n\n\nAn example output from this machine is:\n\n\\begin{Output}\n      m  n  measured theoretical difference pct.error   mflops\n1 10000 50 212538720   203500001    9038719   4.25274 2284.257\n\\end{Output}\n\nThe \\thispackage package has several other demonstrations that, like this, \ncompare a theoretical floating point operations count against a measured count, \nand then display the Mflops the computation achieved.  These demos include \nan inner product calculation \\code{inner.r}, a matrix-matrix product \n\\code{matprod.r}, and the fitting of a linear model in \\code{regression.r}.\n\n\n\\subsection{Cache Misses}\n\nTo see the full source code described in this example, see the \\code{cache_access} demo in \n\\thispackage.\n\nConsider the following example, where we will fill a matrix with 1's, first by \nlooping over rows then columns, and then by looping over columns then rows.  For \nmaximum effect, we will be dropping to \\CXX by way of \\pkg{Rcpp}.  If you do not \nhave \\pkg{Rcpp} installed on your system, you can still follow along (even if \nyou don't know \\CXX), but you will not be able to recreate the timings locally.\n\nYou are probably aware that \\R matrices are stored in column-major fashion.  \nWhat this means is that the data, as it is laid out in physical memory, is \neasier to go from the entry with index $(i, j)$ to index $(i+1, j)$ than \nit is to go to index $(i, j+1)$.  \n\nAn example of accessing data poorly is the following:\n\\begin{lstlisting}[language=rr]\nbad_cache_access <- \"\n  int i, j;\n  const int n = INTEGER(n_)[0];\n  Rcpp::NumericMatrix x(n, n);\n  \n  \n  for (i=0; i<n; i++)\n    for (j=0; j<n; j++)\n      x(i, j) = 1.;\n  \n  return x;\n\"\n\\end{lstlisting}\n\nAccessing data in this way maximizes the \namount of work the computer needs to do in searching for the data your program \nneeds.  Accessing your memory correctly will help minimize cache misses: \n\n\\begin{lstlisting}[language=rr]\ngood_cache_access <- \"\n  int i, j;\n  const int n = INTEGER(n_)[0];\n  Rcpp::NumericMatrix x(n, n);\n  \n  \n  for (j=0; j<n; j++)\n    for (i=0; i<n; i++)\n      x(i, j) = 1.;\n  \n  return x;\n\"\n\\end{lstlisting}\n\nTo prove this, we can build these functions using the \\pkg{inline} and \n\\pkg{Rcpp} packages~\\citep{inline,rcpp} and then profile them with \\thispackage.\n\n\\begin{lstlisting}[language=rr]\nlibrary(inline)\n\nbad <- cxxfunction(signature(n_=\"integer\"), \n                   body=bad_cache_access, plugin=\"Rcpp\")\ngood <- cxxfunction(signature(n_=\"integer\"), \n                    body=good_cache_access, plugin=\"Rcpp\")\n\\end{lstlisting}\n\nA quick check of run times shows something drastically different is happening \nbetween the two implementations:\n\\begin{Output}\nn <- 10000L\n\nsystem.time(bad(n))\n#   user  system elapsed \n#  1.016   0.232   1.259 \n\nsystem.time(good(n))\n#   user  system elapsed \n#  0.201   0.155   0.357 \n\\end{Output}\n\nSo even though we (mathematically) are doing the exact same thing to the data, \nthe run times differ by a factor of 3.5.  \\thispackage allows us to more \nthoroughly see what's happening.  We can use \\code{system.cache()} to check the \nL1, L2, and L3 (total) cache misses for each of these functions:\n\n\\begin{Output}\nlibrary(pbdPAPI)\nn <- 10000L\n\nsystem.cache(bad(n))\n#$L1.total\n#[1] 193580295\n#\n#$L2.total\n#[1] 159442230\n#\n#$L3.total\n#[1] 16895275\n\nsystem.cache(good(n))\n#$L1.total\n#[1] 15552007\n#\n#$L2.total\n#[1] 11580023\n#\n#$L3.total\n#[1] 801150\n\\end{Output}\n\nThe L1 cache misses differ by more than an order of magnitude, 194 million to 16 \nmillion!\n\nPerhaps a more useful measure is the \\emph{cache miss ratio}, which is the \ntotal cache misses divided by the total cache accesses (in the low-level \ninterface syntax, this is the return of event \\code{PAPI_L2_TCM} divided by the \nreturn of event \\code{PAPI_L2_TCA}, for level 2). \n\nMeasuring this too is simple:\n\n\\begin{Output}\nsystem.cache(bad(n), events=\"l2.ratio\")\n# L2 cache miss ratio \n#            0.815597 \n\nsystem.cache(good(n), events=\"l2.ratio\")\n# L2 cache miss ratio \n#           0.7156862 \n\n\\end{Output}\n", "meta": {"hexsha": "97d291bbc083c5252f2f29bef6ff3d7c3d93b1bc", "size": 5097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vignettes/include/05-examples.tex", "max_stars_repo_name": "wrathematics/pbdPAPI", "max_stars_repo_head_hexsha": "cb3fad3bccd54b7aeeef9e687b52d938613a356e", "max_stars_repo_licenses": ["Intel", "BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2015-02-14T17:00:51.000Z", "max_stars_repo_stars_event_max_datetime": "2016-02-01T20:13:43.000Z", "max_issues_repo_path": "vignettes/include/05-examples.tex", "max_issues_repo_name": "QuantScientist3/pbdPAPI", "max_issues_repo_head_hexsha": "708bee501de20eb82829e03b92b24b6352044f49", "max_issues_repo_licenses": ["Intel", "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": "vignettes/include/05-examples.tex", "max_forks_repo_name": "QuantScientist3/pbdPAPI", "max_forks_repo_head_hexsha": "708bee501de20eb82829e03b92b24b6352044f49", "max_forks_repo_licenses": ["Intel", "BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-09-05T05:21:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-28T16:17:37.000Z", "avg_line_length": 30.3392857143, "max_line_length": 91, "alphanum_fraction": 0.7208161664, "num_tokens": 1441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.687668419813766}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Lagrange Multipliers \\& Atwood Machine}\n\\begin{p}\nWrite the constraint equations $f(x,y) = const.$ for $x$ and $y$ for the simple plane pendulum and the Atwood Machine.\n\\end{p}\n\\begin{s}\nThe constraint equation is $f(x, y) = \\sqrt{x^2 + y^2} = L$ for the simple pendulum and $f(x, y) = x + y = L$ for the Atwood machine (constrained by length of rope).\n\\end{s}\n\n\\begin{p}\nWrite down the Hamilton's principle $\\delta S(x,y) = 0$ for the two constrained variables $x$ and $y$. If we try to make the action stationary, how would the deviations $\\delta x$ and $\\delta y$ have to be constrained?\n\\end{p}\n\\begin{s}\n\\begin{align*}\n    \\delta S + \\int\\left(\\dpd{\\LL}{x} - \\dod{}{t}\\dpd{\\LL}{\\dot{x}}\\right)\\delta x dt + \\int \\left(\\dpd{\\LL}{y} - \\dod{}{}\\dpd{\\LL}{\\dot{y}}\\right)\\delta y dt = 0\n\\end{align*}\nBut, these variations must be constrained as $x$ and $y$ are not independent of one another. We note that $\\delta x, \\delta y$ obey the constraints.\n\\end{s}\n\n\\begin{p}\nFor deviations that meet the conditions of the question above, write down the variations of the constraint $\\delta f$. Multiply $\\delta f$ by an unknown function $\\lambda(t)$ and add to $\\delta S$.\n\\end{p}\n\\begin{s}\n\\[\\delta f = \\dpd{f}{x}\\delta x + \\dpd{f}{y}\\delta y = 0\\]\nAs the displacement must leavve the constraint unchanged. Hence we may add a $0$ to the total variation of $S$ without changing anything. We therefore write:\n\\[\\delta S = \\int \\left(\\dpd{\\LL}{x} + \\lambda(t)\\dpd{f}{x} - \\dod{}{t}\\dpd{\\LL}{\\dot{x}}\\right)\\delta x \\delta t + \\int\\left(\\dpd{\\LL}{y} + \\lambda(t)\\dpd{f}{y} - \\dod{}{t}\\dpd{\\LL}{\\dot{y}}\\right)\\delta y dt = 0\\]\n\\end{s}\n\n\\begin{p}\nCan $\\delta x$ and $\\delta y$ be independently varied? The multiplying function of the constraint $\\lambda(t)$ is so far undetermined and can be chosen as we wish. What special choice of $\\lambda(t)$ makes all of the arguments $\\delta x$, $\\delta y$, $\\delta z$... vanish? How have the Lagrange equations been modified when the dependent variables are constrained?\n\\end{p}\n\\begin{s}\nUnlike the case with generalized coordinates, the variations are not independent. Consider that we can pick $\\lambda (t)$ (Lagrange multiplier) to be whatever we like to make the first integral vanish. However, this then means that the second term must vanish as well, as the sum has to be zero (and if the term is to be zero for all variations, then the integrand must be zero)! In general, if we have a function of (not necessarily generalized coordinates) $\\LL(x_k, \\dot{x}_k, t)$ with $f_{i}(x_k, t) = 0$ ($m$ holonomic constraints), we can consider the modified Lagrangian:\n\\[\\tilde{L}(x_k, \\dot{x}_k, t) = \\LL(x_k, \\dot{x}_k, t) - \\sum_{i=1}^m \\lambda_i f_i(x_k, t)\\]\nAnd if we require that the variation vanishes $\\delta S = 0$, then we get a set of generalized Lagrange equations:\n\\[\\dpd{\\LL}{x_k} + \\sum_{i=1}^m \\lambda_i \\dpd{f_i}{x_k} = \\dod{}{t}\\dpd{\\LL}{\\dot{x}_k}\\]\n\n\\end{s}\n\n\\begin{center}\n    \\includegraphics[scale=0.75]{Lecture-8/w8-img1.png}\n\\end{center}\n\\begin{p}\nWhat are Lagrange's equations for $x$ and $y$ of the Atwood Machine?\n\\end{p}\n\\begin{s}\nThe Lagrangian is given by:\n\\[\\LL = \\frac{m_1}{2}\\dot{x}^2 + \\frac{m_2}{2}\\dot{y}^2 + m_1gx + m_2gy\\]\nHence the equations of motions are:\n\\[m_1\\ddot{x} = m_1g + \\lambda\\]\n\\[m_2\\ddot{y} = m_2g + \\lambda\\]\nWhere $\\lambda$ is the Lagrange multiplier.\n\\end{s}\n\n\\begin{p}\nUsing the constraint equation for $x$ and $y$, eliminate the Lagrange multiplier and solveagain for the acceleration of $x$.\n\\end{p}\n\\begin{s}\nFrom the constraint equation (taking two time derivatives of it) we obtain that $\\ddot{x} = -\\ddot{y}$. We therefore have that:\n\\[\\ddot{x} = \\frac{(m_1 - m_2)}{(m_1 + m_2)}g\\]\n\\end{s}\n\n\\begin{p}\nNow solve the equations for the Lagrange multiplier.\n\\end{p}\n\\begin{s}\nSolving for $\\lambda$, we have:\n\\[\\lambda = m_1\\ddot{x} - m_1g\\]\nWe note that $m_1\\ddot{x}$ is the total force of the system, so\n\\[m\\ddot{x} = -\\dpd{U}{x} - F_{T}\\]\nWhere the first term is the conservative (gravitational) force from potential and $F_T$ is the tension/constraint force. Therefore, we have that:\n\\[\\lambda = -F_T\\]\nAnd we have found the lagrange multiplier to be the constraint/tension force!\n\\end{s}\n\n\\begin{p}\nShow that $\\lambda \\pd{f}{x}$ s the constraint force on mass $m_1$.\n\\end{p}\n\\begin{s}\nHere, $\\dpd{f}{x} = 1$ so $\\lambda\\dpd{f}{x} = \\lambda = -F_T$ which is the expected result.\n\\end{s}\n\\end{document}", "meta": {"hexsha": "bda212e66f26b03946a499160eac6cc77064f67d", "size": 4482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-8/Worksheet-8.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-8/Worksheet-8.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-8/Worksheet-8.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": 53.3571428571, "max_line_length": 578, "alphanum_fraction": 0.6858545292, "num_tokens": 1482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.8615382023207901, "lm_q1q2_score": 0.6876683933380503}}
{"text": "In this chapter, motivated by the multigrid method, \nwe design a unified framework for convolutional neural network \nand multigrid method named MgNet. \nWe first propose the framework and discuss some features of the new network structure. \nThen we discuss the relation between MgNet and ResNet. We will establish some new understandings \nof ResNet from the point view of MgNet. \n\n\\section{MgNet: a new network structure}\\label{sec:mgnet}\nIn this section, we introduce a new neural network structure,\nnamed as MgNet~\\cite{he2019mgnet}, motivated by the multigrid algorithm, \nAlgorithm \\ref{alg:L-Slash0},\n%and its nonlinear version in Algorithm~\\ref{alg:Slash-FAS}, \nas discussed in the previous section.\n\nHere we recall the most important two structures in multigrid\n\\begin{enumerate}\n\t\\item iterative scheme (for linear system)\n\t\\begin{equation}\\label{eq:iterscheme}\n\tu^{\\ell,i} = u^{\\ell,i-1} + B^{\\ell,i} ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}).\n\t\\end{equation}\n\t\\item interpolation and restriction\n\t\\begin{equation}\\label{eq:inter&rest}\n\tu^{\\ell+1,0} = \\Pi_\\ell^{\\ell+1} \\ast_2 u^{\\ell},  \\quad \tf^{\\ell+1} = R^{\\ell+1}_\\ell \\ast_2 (f^\\ell - A^\\ell(u^{\\ell})) + A^{\\ell+1} \\ast u^{\\ell+1,0}.\n\t\\end{equation}\n\\end{enumerate}\n\nConsidering the fine to coarse process of multigrid with the aforementioned\ntwo structures in \\eqref{eq:iterscheme} and \\eqref{eq:inter&rest}.\nWe are now in a position to state the main algorithm, namely\nMgNet by just putting some nonlinear activation function $\\sigma$ in some places.\n\\begin{breakablealgorithm}\n\t\\caption{$u^{J}={\\rm MgNet}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:mgnet}\n\t\\begin{algorithmic}\n\t\t\\State Initialization:  $f^1 = \\theta(f)$, $u^{1,0} = 0$\n\t\t%\t\t\\State Initialization $u^{1,0}$\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State \n\t\t\\begin{equation}\\label{mgnet}\n\t\tu^{\\ell,i} = u^{\\ell,i-1} + \\sigma \\circ B^{\\ell,i} \\ast \\sigma ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Note $u^\\ell = u^{\\ell,\\nu_\\ell}$\n\t\t\\begin{equation}\n\t\t\\label{interpolation}\n\t\tu^{\\ell+1,0} = \\Pi_\\ell^{\\ell+1} \\ast_2 u^{\\ell}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\\label{restrict-f}\n\t\tf^{\\ell+1} = R^{\\ell+1}_\\ell \\ast_2 (f^\\ell - A^\\ell(u^{\\ell})) + A^{\\ell+1} \\ast u^{\\ell+1,0}.\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\n\\begin{theorem}\\label{thm:mg-mgnet}\n\tIf $A^\\ell$, $R_\\ell^{\\ell+1}$ and $B^{\\ell,i} = S^{\\ell}$ are all linear operations as described in multigrid method\n\tin \\S \\ref{sec:mg} and all $\\sigma = id$ in Algorithm \\ref{alg:mgnet}. \n\tThen Algorithm \\ref{alg:L-Slash0} is equivalent to Algorithm \\ref{alg:mgnet} with any choice of $\\Pi_\\ell^{\\ell+1}$.\n\\end{theorem}\n\\begin{proof}\n\tHere we replace $u^{\\ell,i}$ and $f^{\\ell}$ by $\\tilde u^{\\ell,i}$ and $\\tilde f^{\\ell}$ in MgNet. \n\tWhat we want to prove are\n\t\\begin{equation}\\label{eq:f-u}\n\t\\tilde f^{\\ell} =  f^{\\ell} + A_\\ell \\tilde u^{\\ell,0} \\quad \\text{and} \\quad u^{\\ell,i} = \\tilde u^{\\ell, i} - \\tilde u^{\\ell, 0},\n\t\\end{equation}\n\twith $u^{\\ell,i}$, $f^\\ell$ in Algorithm \\ref{alg:L-Slash0} and \n\t$\\tilde u^{\\ell,i}$, $\\tilde f^\\ell$ in Algorithm \\ref{alg:mgnet} for any choice of $\\Pi_\\ell^{\\ell+1}$. \n\tWe prove this result by induction. \n\t\\begin{itemize}\n\t\t\\item It is easy to check that $\\ell = 1$ is right by taking $\\theta  = \\rm{id}$. \n\t\t\\item Once the above equation \\eqref{eq:f-u} is right for $\\ell$, \n\t\tlet us prove the corresponded result for $\\ell+1$.\n\t\t\\begin{itemize}\n\t\t\t\\item For $\\tilde f^{\\ell+1}$, as the definition in Algorithm \\ref{alg:mgnet}, we have\n\t\t\t\\begin{align*}\n\t\t\t\\tilde f^{\\ell+1} &= R_\\ell^{\\ell+1}(\\tilde f^\\ell - A^\\ell \\tilde u^{\\ell,\\nu_\\ell}) + A^{\\ell+1}\\tilde u^{\\ell+1,0}, \\\\\n\t\t\t&= R_\\ell^{\\ell+1}(f^\\ell + A^{\\ell} \\tilde u^{\\ell,0}- A^{\\ell} \\tilde u^{\\ell,\\nu_\\ell}) + A^{\\ell+1}\\tilde u^{\\ell+1,0} \\\\\n\t\t\t&= R_\\ell^{\\ell+1}(f^\\ell - A^{\\ell} (\\tilde u^{\\ell,\\nu_\\ell}- u^{\\ell,0})) + A^{\\ell+1}\\tilde u^{\\ell+1,0} \\\\\n\t\t\t&= R_\\ell^{\\ell+1}(f^\\ell - A^{\\ell} u^{\\ell,\\nu_\\ell}) + A^{\\ell+1}\\tilde u^{\\ell+1,0}, \\\\\n\t\t\t&=  f^{\\ell+1} + A^{\\ell+1}\\tilde u^{\\ell+1,0}.\n\t\t\t\\end{align*}\n\t\t\t\\item For $u^{\\ell+1,i}$, first we have \n\t\t\t$$\n\t\t\tu^{\\ell+1,0} = 0 =\\tilde u^{\\ell+1, 0} - \\tilde u^{\\ell+1, 0},\n\t\t\t$$\n\t\t\tthen we prove \n\t\t\t\\begin{equation}\\label{u:i+1}\n\t\t\tu^{\\ell+1,i} = \\tilde u^{\\ell+1, i} - \\tilde u^{\\ell+1, 0}\n\t\t\t\\end{equation} by induction for $i$.\n\t\n\t\t\tWe assume \\eqref{u:i+1} holds for $0,1,\\cdots,i-1$. Let us miner $\\tilde u^{\\ell+1, 0}$ in both sides of \n\t\t\tthe smoothing process \\eqref{mgnet} in Algorithm \\ref{alg:mgnet}. Then we have\n\t\t\t\\begin{align*}\n\t\t\t\\tilde u^{\\ell+1,i} - \\tilde u^{\\ell+1, 0} &= \\tilde u^{\\ell+1,i-1} - \\tilde u^{\\ell+1, 0} + B^{\\ell+1,i} (\\tilde f^{\\ell+1} - A^{\\ell+1} \\tilde u^{\\ell+1,i-1}), \\\\\n\t\t\t&= \\tilde u^{\\ell+1,i-1} - \\tilde u^{\\ell+1, 0} + B^{\\ell+1,i} (f^{\\ell+1} + A^{\\ell+1}\\tilde u^{\\ell+1,0} - A^{\\ell+1} \\tilde u^{\\ell+1,i-1} ),\\\\ \n\t\t\t&= u^{\\ell+1,i-1} + B^{\\ell+1,i} (f^{\\ell+1} - A^{\\ell+1}u^{\\ell+1,i-1} ).\n\t\t\t\\end{align*}\n\t\t\tThis is exact the smoothing process in Algorithm \\ref{alg:L-Slash0} as we take $ B^{\\ell+1,i} = S^{\\ell+1}$.\n\t\t\t%\t\t\t\\item At last, recall that $u^{1,0} = 0$, so the output of Algorithm \\ref{alg:L-Slash0} \n\t\t\t%\t\t\t$$\n\t\t\t%\t\t\ttilde u^{1, \\nu_1} = u^{1, \\nu_1},\n\t\t\t%\t\t\t$$\n\t\t\t%\t\t\twhich is the output of Algorithm \\ref{alg:L-Slash}. \n\t\t\\end{itemize}\n\t\\end{itemize}\n\\end{proof}\n\n\nThe main steps in MgNet can be understood \nas solving the following  data-feature mappings in each grid $\\ell$:\n\\begin{equation}\n\\label{Auf-ell}\nA^\\ell \\ast u^\\ell = f^\\ell, \\quad \\ell=1:J,\n\\end{equation}\nwhere\n\\begin{equation}\n\\label{f-ell}\nf^{\\ell}\\in\\mathbb R^{c_\\ell \\times m_\\ell\\times n_\\ell},\n\\end{equation}\nand \n\\begin{equation}\n\\label{u-ell}\nu^{\\ell}\\in\\mathbb R^{h_\\ell\\times m_\\ell\\times n_\\ell},\n\\end{equation}\nwith constrain\n\\begin{equation}\\label{key}\nu \\ge 0.\n\\end{equation}\nMore details about this basic assumption in image classification can be found in \n~\\cite{he2019constrained}.\n\nHere, the next diagram gives a brief illustration for the above \n\tstructure.\\\\\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth]{MgNet_3} \n\t\\end{center}\n\t\\caption{Structure of MgNet}\n\t\\label{fig:mgnet}\n\\end{figure}\n\nThe first property of MgNet is that it recovers the multigrid methods.\nDespite of the simplicity look of Algorithm \\ref{alg:mgnet}, there\nare rich mathematical structures and variants which we will briefly discuss below.\n\n\\subsection{Initialization: feature space channels}\nInitially for $\\ell=1$,  we take $m_1 = m$ and $n_1 = n$ and we may define the linear mapping \n\\begin{equation}\n\\label{eq:6}\n\\theta: \\mathbb R^{c \\times m\\times n }\n\\mapsto \\mathbb R^{c_1 \\times m_1\\times n_1 },\n\\end{equation}\nto obtain $f^{1} = \\theta(f)$ with $c$ %given in \\eqref{data-c} \nchanged to the channel of the initial\ndata space to $c_1$.   Usually\n\\begin{equation}\n\\label{cc}\nc_1\\ge c.  \n\\end{equation}\nOne possibility is that we choose $c_1=c$.  In this case, we choose\n$\\theta$ to be identity.   But in general, we may need to choose $c_1\\gg\nc$. One possible advantage of preprocessing the RGB ($c=3$) to \ndifferent color spaces is that we can better choose what kind of\nfeatures the CNN can detect, and under what \nconditions those detections will be invariant.\n\nOne possibility of understanding and modifying this step \nis to decompose the data $f$ into a number of more\nspecialized data\n\\begin{equation}\n\\label{decomp-f}\nf=\\sum_{k=1}^{c_1}\\xi_kf^1_k  =\\xi^Tf^1.\n\\end{equation}\nWe may use some knowledge from image processing or physics to\ndesign a procedure to obtain the right decomposition of\n\\eqref{decomp-f}, or we can just train it. \nConceivably, we may view $f^{1} = \\theta(f)$ as a special approximation solution of\n\\eqref{decomp-f} with the same sparsity pattern to $\\xi$. \n\n\\subsection{Extracted units: $u^{\\ell}$ and channels}\nThe first new feature and the main new ingredient \nin the proposed neural network is the introduction \nof feature variables  $u^{\\ell}$ in \\eqref{u-ell}, which will be known\nas the extracted units. \n\nWe emphasize that the extracted-units $u^\\ell$ and the data $f^\\ell$ can have\ndifferent numbers of channels:\\\n\\begin{equation}\n\\label{uf-channels}\nu^\\ell\\in \\mathbb{R}^{c_{u,\\ell}\\times m_\\ell\\times n_\\ell  }, \\quad\nf^\\ell\\in \\mathbb{R}^{c_{f,\\ell} \\times m_\\ell\\times n_\\ell }\n\\end{equation}\nOne possibility is that the number of channels for both $u$ and $f$ remain\nunchanged in different grids:  \n\\begin{equation}\n\\label{cfl}\nc_{f,\\ell}=c_f, \\quad \\ell=1:J,   \n\\end{equation}\nand \n\\begin{equation}\n\\label{ufl}\nc_{u,\\ell}=c_{u}, \\quad \\ell=1:J.   \n\\end{equation}\nBoth $c_f$ and $c_{u}$ are two super-parameters that need to be tuned, \nand we may even take $c_u = c_f$.\n\n\\subsection{Poolings: $\\Pi_{\\ell+1}^\\ell$ and $R_{\\ell+1}^\\ell$}\nThe pooling $\\Pi_{\\ell+1}^\\ell$ in \\eqref{interpolation} and\n$R_{\\ell+1}^\\ell$ in \\eqref{restrict-f} are in general different.\nThey can be trained in general, but they may be a priori chosen.\n\nThere are many different possibilities to choose $\\Pi_{\\ell+1}^\\ell$. \nThe simplest choice of $\\Pi_{\\ell+1}^\\ell$ is \n\\begin{equation}\n\\label{eq:8}\n\\Pi_{\\ell+1}^\\ell=0.\n\\end{equation}\nA more sophisticated choice can be obtained by considering an\ninterpolation from fine grid to coarse (that, for example preserves linear function\nlocally).  Namely\n\\begin{equation}\n\\label{Pi}\n\\Pi_{\\ell+1}^\\ell=\\bar\\Pi_{\\ell+1}^\\ell \\otimes I_{c_\\ell\\times c_\\ell} \n\\end{equation}\nwith $\\bar\\Pi_{\\ell+1}^\\ell$ given in finite element methods.\n\n\n\n\\subsection{Data-feature mapping: $A^{\\ell}$}\nThe second new feature of MgNet is that this data-feature mapping\nonly depends on the grid ${\\cal T}_\\ell$, and it does not depend on layers\nwithin the same grid.  This amounts to a significant saving of the number of\nparameters.  In comparison, the existing CNN, such as pre-act ResNet, can be\ninterpreted as a network related to the case that $A^{\\ell}$ is\nreplaced by $A^{\\ell, i}$, namely\n\\begin{equation}\\label{u-resnet}\nu^{\\ell,i} = u^{\\ell,i-1} + \\sigma \\circ B^{\\ell,i} \\ast \\sigma (f^\\ell -  A^{\\ell,i} \\ast u^{\\ell,i-1}).\n\\end{equation}\n\nThe underlying convolution kernels can be different on different grids and they can\nall be trained.\n\n\n\\subsection{Feature extractors: $\\sigma \\circ B^{\\ell,i} \\ast \\sigma$}\nHere we adopt the feature extractor as:\n\\begin{equation}\n\\label{extractor-ell}\n\\sigma\\circ B^{\\ell,i}\\ast\\sigma.\n\\end{equation}\n\nOther than the level dependent extractors, the following \ndifferent strategies can be used\n\\begin{description}\n\t\\item[Constant Extractors]: $B^{\\ell,i}=B^{\\ell}$ for   $i=1:\\nu_\\ell$\n\t\\item[Scaled Extractors]:$B^{\\ell,i}=\\alpha_iB^{\\ell}$ for   $i=1:\\nu_\\ell$\n\t\\item[Variable Extractors]: $B^{\\ell,i}$\n\\end{description}\n\n\n\nThis brief framework gives us the basic principle on designing \na CNN models for classification. All models are seen as the special\nchoice of data-feature mapping $A^\\ell$, feature extractors $B^{\\ell,i}$ \nand the pooling operators $\\Pi_{\\ell+1}^\\ell$ with $R_{\\ell+1}^\\ell$.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\endinput\nSimilarly, we can consider about the back-slash cycle process:\n\\begin{breakablealgorithm}\n\t\\caption{$u^J={\\rm MgNet1}(f; J,\\nu_1, \\cdots, \\nu_J; \\nu'_1, \\cdots, \\nu'_J )$}\n\t\\label{alg:mgnet1}\n\t\\begin{algorithmic}\n\t\t\\State \n\t\t$$\n\t\t(\\bar u^{1,0}, \\bar u^1, f^1, \\bar u^{2,0}, u^2, f^2,\\cdots, \\bar u^{J,0},\\bar u^J, f^J) = \\text{MgNet}(f; J,\\nu_1, \\cdots, \\nu_J).\n\t\t$$\n\t\t%\\State Define $\\bar u^{\\ell, 0 } = u^{\\ell,0}$ for $\\ell = 1:J$.\n\t\t\\For{$\\ell = J-1 : 1$}\n\t\t%\t\t\\State  and $u^{\\ell,\\nu_\\ell'} = u^{\\ell}$ then\n\t\t\\begin{equation}\n\t\t%\t\t\\begin{aligned}\n\t\tu^{\\ell,0} \\leftarrow \\bar u^{\\ell} + R_{\\ell}^{\\ell+1} \\ast_2^T (u^{\\ell+1} - \\bar u^{\\ell+1,0}).\n\t\t%\t\t\\end{aligned}\n\t\t\\end{equation}\n\t\t%\t\t\t\tf^\\ell &= f^\\ell - A^\\ell \\bar u^{\\ell,0}+ A^\\ell  u^{\\ell,0}. \n\t\t\\For{$i = 1:\\nu'_\\ell$}\n\t\t\\State \n\t\t\\begin{equation}\\label{mgnet}\n\t\tu^{\\ell,i} \\leftarrow u^{\\ell,i-1} + (B^{\\ell,i})'  ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State  \n\t\t$$\n\t\tu^{\\ell} \\leftarrow u^{\\ell,\\nu_\\ell'} .\n\t\t$$\n\t\t\\EndFor\n\t\t\\State \n\t\t$$\n\t\t(u^1,\\cdots, u^{J-1}).\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n", "meta": {"hexsha": "f4ce903ffdef7870316c74fd8e5c0365843db58c", "size": 12236, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/mgnet.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/mgnet.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.3440514469, "max_line_length": 167, "alphanum_fraction": 0.6514383786, "num_tokens": 4584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6876512321934651}}
{"text": "\\section{Discussion}\n\\label{sect:prob-discussion}\n\nWe discuss potential applications, extensions, and connections of probabilistic property evaluation in the following.\n\n\\subsection{Probabilistic equivalence checking}\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics{fig/build/pec-miter.pdf}\n    \\caption{A miter SPBN for probabilistic equivalence checking}\n    \\label{fig:prob-PEC}\n\\end{figure}\nGiven two SPBNs, their equivalence checking can be easily formulated under PPE and MPPE framework,\nas depicted in~\\cref{fig:prob-PEC}.\nThe property network corresponds to a miter circuit\nthat tests the difference of corresponding outputs of the two SPBNs,\nsame as in the equivalence checking of deterministic designs.\nWith the proposed framework,\nwe can analyze the average (resp. maximum) probability\nthat the two SPBNs are functionally different through PPE (resp. MPPE).\nWe refer to the equivalence checking problem as\n\\textit{probabilistic equivalence checking} (PEC) for the average-case analysis and\n\\textit{maximum probabilistic equivalence checking} (MPEC) for the worst-case analysis.\nSince equivalence checking is widely encountered,\nour experiments will focus on PEC and MPEC to compare the strengths and weaknesses of different solutions\nthat we proposed in~\\cref{sect:prob-solutions}.\n\n\\subsection{Prioritized output requirement}\nFor some applications,\nwe may want to impose different criticality requirements on different output signals.\nGiven an SPBN $G$ over\nprimary inputs $X$,\ninternal vertices $Y$,\nand auxiliary inputs $Z$,\nthis output-prioritized version of MPPE is naturally expressible\nin terms of stochastic integer linear programming (SILP)~\\cite{Schultz2003} as follows:\n\\begin{align*}\n    \\max_X \\enskip \\mathbb{E}[\\sum_{i=1}^n w_i o_i(X,Y,Z)] \\enskip s.t. \\enskip \\pf,\n\\end{align*}\nwhere $o_i \\in V_O$ is an output of $G$, $|V_O|=n$,\n$w_i$ is the weight of $o_i$,\n$\\mathbb{E}[\\cdot]$ denotes the expectation value,\nand $\\pf$ is a set of linear inequalities derived from the CNF formula of $G$\nthrough the standard translation from clauses to linear constraints.\nTo illustrate, a clause $(x \\lor \\lnot y \\lor z)$ in a CNF formula is transformed into\na linear inequality $(x+1-y+z)\\geq 1$,\nor $(x-y+z)\\geq 0$ in $\\pf$.\nNote that the worst case formulation in~\\cref{thm:prob-mppe-ssat} is a special case of\nthe SILP formulation where the expectation value of the miter's output is maximized.\n\n\\subsection{Connection to approximate design analysis}\nApproximate design analysis assesses the deviation between\nan approximate design and its exact counterpart in two scenarios:\nthe worse and average cases.\nFor the worst-case analysis, integer linear programming (ILP) can be applied\nto find an input assignment to maximize the number of deviating outputs.\nFor the average-case analysis, model counting can be used\nto compute the number of input assignments that make the two designs have different output responses.\nIn both cases, our PPE framework can be applied to analyze an approximate design,\nwhich can be seen as a probabilistic design without random behavior.\nFor probabilistic design analysis,\nif all random variables become deterministic,\nthen it degenerates to approximate design analysis\n(from SILP to ILP under the worst-case analysis and\nfrom weighted model counting to model counting under the average-case analysis).", "meta": {"hexsha": "4abaaaf681a3007dd0cdfb1c8c89cd87fcb1b725", "size": 3353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/prob-design-eval/discussion.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/prob-design-eval/discussion.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/prob-design-eval/discussion.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": 51.5846153846, "max_line_length": 117, "alphanum_fraction": 0.7924246943, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.6876512155387069}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{Horn equation}{Horn equation}\n\n\\input{../../fncextra}\n\n\\begin{document}\n   \n\\begin{center}\n    \\bf Toot your own horn\n\\end{center}\n\nThe use of mathematics for the design and analysis of musical instruments has a long and rich history. One of the landmarks in this area is the 1919 model known as Webster's horn equation, even though the relevant modeling and mathematics had largely been worked out by such luminaries as Daniel Bernoulli, d'Alembert, Euler, Lagrange, Green, Helmholtz, and Rayleigh. For Webster the unknown is the air pressure $u(x)$ in a long, thin tube of length $L$ with varying cross-section $A(x)$, as governed by\n\\begin{equation}\n  \\label{eq:webster}\n  u'' + \\frac{A'}{A} u' + \\omega^2 u = 0, \\qquad x\\in [0,L],\n\\end{equation}\nwhere $\\omega$ is the time frequency in a harmonic solution, i.e., the pitch of the sound. Reasonable boundary conditions are a fixed nonzero value of $u$ at $x=0$ (the mouthpiece) and $u'(L)=0$ at the open end. In the analysis problem, $A(x)$ is taken as prescribed, whereas in design the goal is to find an $A(x)$ that optimizes some desired quality of the horn. \n\nFor some prescriptions of $A(x)$, a solution can be found in closed form. For example, if $A(x)=e^{2k x}$, then the general solution of~(\\ref{eq:webster}) is\n\\begin{equation}\n  \\label{eq:solution-exp}\n  u(x) = c_1 e^{s_1 x} + c_2 e^{s_2 x},\n\\end{equation}\nwhere $s_1$ and $s_2$ are the roots of $s^2+2k s + \\omega^2$, and $c_1$, $c_2$ are constants.  \n\nNaturally, we will focus on numerical solutions of the horn equation. The problem is a linear BVP and easy to solve for most choices of $A(x)$. The solution $u(x)$ represents a standing wave whose amplitude \n\\begin{equation}\n  \\label{eq:amplitude}\n  \\alpha(\\omega)=\\|u\\|  \n\\end{equation}\ncan vary considerably with the frequency $\\omega$. Physically, a horn player produces more or less white noise with significant components in a wide range of frequencies. A sharp peak in $\\alpha(\\omega)$ indicates a resonant frequency of the horn that is likely to dominate the resulting sound. \n\n\\subsection*{Goals}\n\nYou will compute finite difference solutions of the horn equation for a few choices of $A(x)$, and look for resonances.\n\n\\subsection*{Preparation}\n\nRead section 10.4. \n% \\begin{enumerate}\n%     \\item Derive~\\eqref{eq:solution-exp}.\n%     \\item Let $k=3$, $L=1$, $u(0)=1$ and $u'(L)=0$. Define the amplitude using the 2-norm in~(\\ref{eq:amplitude}) and make a plot of $\\alpha(\\omega)$ for $1\\le \\omega \\le 16$. Computer algebra and/or numerics is \\emph{strongly} recommended. How many resonant frequencies are in this range? \n%\\end{enumerate}\n\n\n\\subsection*{Procedure}\n\nDownload the template script and complete it to perform the following tasks.\n\n\\begin{enumerate}\n    \\item Set $L=2$, $\\omega=6$, and $A(x)=e^{6x}$  in~(\\ref{eq:webster}). Find the roots $s_1$ and $s_2$ in~(\\ref{eq:solution-exp}). (Note that $k=3$ in that equation.) Use $u(0)=1$ and $u'(L)=0$ to solve for $c_1$ and $c_2$, and plot the solution for $0\\le x \\le L$. \n    \\item Using the same values as in step~1, apply \\texttt{bvp} with $n=500$ to find a numerical solution. Plot the difference between the exact and numerical solutions at all of the finite difference nodes. \n    \\item Now let $A(x)=3x^2+x+1$ and $\\omega=2$ (still with $L=2$). Plot the finite difference solution using $n=500$. \n    \\item Repeat the computation from step~3, but for 100 equally spaced values of $\\omega$ between 0.2 and 3. In each case compute $\\alpha(\\omega)$ using the infinity norm in~(\\ref{eq:amplitude}). Plot $\\alpha$ as a function of $\\omega$.\n    \\item Your amplitude graph should have two sharp spikes. Find $\\omega_1$ and $\\omega_2$, the horizontal coordinate of each spike. (One easy way is to use the ``data cursor'' tool in the figure's menu.) Solve the BVP for these two values of $\\omega$ to get $\\bfu_1$ and $\\bfu_2$. Plot $\\bfu_1$ and $\\bfu_2$ together over $[0,L]$. You should find that $\\bfu_1$ has no interior local extrema and that $\\bfu_2$ has one local max or min (depending on exactly what you choose for $\\omega_2$). \n\\end{enumerate}\n\n% \\subsection*{Extras}\n% \\begin{enumerate}\n%   \\item[E1.] Here is a creative way to check the solution even when the exact solution is unknown. Equation~(\\ref{eq:webster}) can be rearranged to give\n%     \\begin{equation}\n%       \\label{eq:logAprime}\n%       \\log A(x) = \\log A(0) - \\int_0^x \\frac{u''(s) + \\omega^2u(s)}{u'(s)}\\, ds.\n%     \\end{equation}\n%     Use $\\omega_1$ and $\\bfu_1$ from the last step. Obtain the differentiation matrices and compute the vector\n% \\begin{verbatim}\n% z = -(Dxx*u1 + omega1^2*u1) ./ (Dx*u1);\n% \\end{verbatim}\n%     which gives the integrand of~(\\ref{eq:logAprime}) at the equally spaced nodes. (The last value, $z_n$, will be useless because of the boundary condition, but this does not affect much.) For each $x_i$, perform trapezoid quadrature on $\\bfz$ from element 0 to $i$ in order to approximate the integration in~(\\ref{eq:logAprime}). Then finish the calculation of $A(x)$ and compare it graphically to the original $A(x)$ used to define the ODE. \n% \\end{enumerate}\n\n\\end{document}\n\n", "meta": {"hexsha": "6ae51825580f02adfa160133a2235298341cf9af", "size": 5254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter10/Horn/Horn.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/chapter10/Horn/Horn.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/chapter10/Horn/Horn.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": 66.5063291139, "max_line_length": 503, "alphanum_fraction": 0.7108869433, "num_tokens": 1581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673269042768, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6876389629941534}}
{"text": "\n\\subsection{Metric compatibility}\n\nIf we have two vectors in the tangent space of a manifold with a metric tensor, we can get a scalar:\n\n\\(v^iu^jg_{ij}\\)\n\n\\subsubsection{Transported metric}\n\nIf we transport two vectors along a connection, we have the metric at the new point.\n\n\\subsubsection{Metric preserving connections}\n\nIf the connection preserves the metric, then the connection is metric compatible.\n\n", "meta": {"hexsha": "0c1ffa860d494d01dc4dac054b3889ca0177928c", "size": 408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsRiemann/02-01-compatibility.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsRiemann/02-01-compatibility.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsRiemann/02-01-compatibility.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": 100, "alphanum_fraction": 0.7843137255, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6875560912720359}}
{"text": "\\section{MgNet: a new network structure}\\label{sec:mgnet}\nIn this section, we introduce a new neural network structure,\nnamed as MgNet, motivated by the multigrid algorithm, \nAlgorithm \\ref{alg:L-Slash0}, as discussed in the previous section.\n\n%The main structure of both CNN and multigrid can be \n%understood as:\n%\\begin{itemize}\n%\t\\item Solving an undetermined system in grid $\\ell$.\n%\t\\item Connection of different grids by restriction and prolongation.\n%\\end{itemize}\n\nFirst, given the data-feature equation \\eqref{Auf}, we consider\nits restrictions to grid $\\ell$ as follows:\n\\begin{equation}\n\\label{Auf-ell}\nA^\\ell(u^\\ell) = f^\\ell, \\quad \\ell=1:J,\n\\end{equation}\nwhere\n\\begin{equation}\n\\label{f-ell}\nf^{\\ell}\\in\\mathbb R^{m_\\ell\\times n_\\ell\\times c_\\ell},\n\\end{equation}\nand \n\\begin{equation}\n\\label{u-ell}\nu^{\\ell}\\in\\mathbb R^{m_\\ell\\times n_\\ell\\times h_\\ell}.\n\\end{equation}\nWe are now in a position to state the main algorithm, namely\nMgNet as:\n\\begin{breakablealgorithm}\n\t\\caption{$u^J={\\rm MgNet}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:mgnet}\n\t\\begin{algorithmic}\n\t\t\\State Initialization:  $f^1 =\\theta(f)$, $u^{1,0}=0$\n\t\t%\t\t\\State Initialization $u^{1,0}$\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State Feature extraction (smoothing):\n\t\t\\begin{equation}\\label{mgnet}\n\t\tu^{\\ell,i} = u^{\\ell,i-1} + B^{\\ell,i}  ({f^\\ell -  A^{\\ell} (u^{\\ell,i-1})}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Note: \n\t\t$\n\t\tu^\\ell= u^{\\ell,\\nu_\\ell} \n\t\t$\n\t\t\\State Interpolation and restriction:\n\t\t\\begin{equation}\n\t\t\\label{interpolation}\n\t\tu^{\\ell+1,0} = \\Pi_\\ell^{\\ell+1}u^{\\ell}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\\label{restrict-f}\n\t\tf^{\\ell+1} = R^{\\ell+1}_\\ell(f^\\ell - A^\\ell(u^{\\ell})) + A^{\\ell+1} (u^{\\ell+1,0}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nThe first property of MgNet is that it recovers the multigrid methods.\n\\begin{theorem}\n\tIf $A^\\ell$, $R_\\ell^{\\ell+1}$ and $B^{\\ell,i} = S^{\\ell}$ are all linear operations as described in multigrid method\n\tin \\S \\ref{sec:mg}. \n\tThen Algorithm \\ref{alg:L-Slash0} is equivalent to Algorithm \\ref{alg:mgnet} with any choice of $\\Pi_\\ell^{\\ell+1}$.\n\\end{theorem}\n\\begin{proof}\n\tHere we replace $u^{\\ell,i}$ and $f^{\\ell}$ by $\\tilde u^{\\ell,i}$ and $\\tilde f^{\\ell}$ in MgNet. \n\tWhat we want to prove are\n\t\\begin{equation}\\label{eq:f-u}\n\t\\tilde f^{\\ell} =  f^{\\ell} + A_\\ell \\tilde u^{\\ell,0} \\quad \\text{and} \\quad u^{\\ell,i} = \\tilde u^{\\ell, i} - \\tilde u^{\\ell, 0},\n\t\\end{equation}\n\twith $u^{\\ell,i}$, $f^\\ell$ in Algorithm \\ref{alg:L-Slash0} and \n\t$\\tilde u^{\\ell,i}$, $\\tilde f^\\ell$ in Algorithm \\ref{alg:mgnet} for any choice of $\\Pi_\\ell^{\\ell+1}$. \n\tWe prove this result by induction. \n\t\\begin{itemize}\n\t\t\\item It is easy to check that $\\ell = 1$ is right by taking $\\theta  = \\rm{id}$. \n\t\t\\item Once the above equation \\eqref{eq:f-u} is right for $\\ell$, \n\t\tlet us prove the corresponded result for $\\ell+1$.\n\t\t\\begin{itemize}\n\t\t\t\\item For $\\tilde f^{\\ell+1}$, as the definition in Algorithm \\ref{alg:mgnet}, we have\n\t\t\t\\begin{align*}\n\t\t\t\\tilde f^{\\ell+1} &= R_\\ell^{\\ell+1}(\\tilde f^\\ell - A^\\ell \\tilde u^{\\ell,\\nu_\\ell}) + A^{\\ell+1}\\tilde u^{\\ell+1,0}, \\\\\n\t\t\t&= R_\\ell^{\\ell+1}(\\tilde f^\\ell + A^{\\ell} \\tilde u^{\\ell,0}- A^{\\ell} \\tilde u^{\\ell,\\nu_\\ell}) + A^{\\ell+1}\\tilde u^{\\ell+1,0} \\\\\n\t\t\t&= R_\\ell^{\\ell+1}(\\tilde f^\\ell - A^{\\ell} (\\tilde u^{\\ell,\\nu_\\ell}- u^{\\ell,0})) + A^{\\ell+1}\\tilde u^{\\ell+1,0} \\\\\n\t\t\t&= R_\\ell^{\\ell+1}(f^\\ell - A^{\\ell} u^{\\ell,\\nu_\\ell}) + A^{\\ell+1}\\tilde u^{\\ell+1,0}, \\\\\n\t\t\t&=  f^{\\ell+1} + A^{\\ell+1}\\tilde u^{\\ell+1,0}.\n\t\t\t\\end{align*}\n\t\t\t\\item For $u^{\\ell+1,i}$, first we have \n\t\t\t$$\n\t\t\tu^{\\ell+1,0} = 0 =\\tilde u^{\\ell+1, 0} - \\tilde u^{\\ell+1, 0},\n\t\t\t$$\n\t\t\tthen we prove \n\t\t\t\\begin{equation}\\label{u:i+1}\n\t\t\tu^{\\ell+1,i} = \\tilde u^{\\ell+1, i} - \\tilde u^{\\ell+1, 0}\n\t\t\t\\end{equation} by induction for $i$.\n\t\n\t\t\tWe assume \\eqref{u:i+1} holds for $0,1,\\cdots,i-1$. Let us miner $\\tilde u^{\\ell+1, 0}$ in both sides of \n\t\t\tthe smoothing process \\eqref{mgnet} in Algorithm \\ref{alg:mgnet}. Then we have\n\t\t\t\\begin{align*}\n\t\t\t\\tilde u^{\\ell+1,i} - \\tilde u^{\\ell+1, 0} &= \\tilde u^{\\ell+1,i-1} - \\tilde u^{\\ell+1, 0} + B^{\\ell+1,i} (\\tilde f^{\\ell+1} - A^{\\ell+1} \\tilde u^{\\ell+1,i-1}), \\\\\n\t\t\t&= \\tilde u^{\\ell+1,i-1} - \\tilde u^{\\ell+1, 0} + B^{\\ell+1,i} (f^{\\ell+1} + A^{\\ell+1}\\tilde u^{\\ell+1,0} - A^{\\ell+1} \\tilde u^{\\ell+1,i-1} ),\\\\ \n\t\t\t&= u^{\\ell+1,i-1} + B^{\\ell+1,i} (f^{\\ell+1} - A^{\\ell+1}u^{\\ell+1,i-1} ).\n\t\t\t\\end{align*}\n\t\t\tThis is exact the smoothing process in Algorithm \\ref{alg:L-Slash0} as we take $ B^{\\ell+1,i} = S^{\\ell+1}$.\n\t\t\t%\t\t\t\\item At last, recall that $u^{1,0} = 0$, so the output of Algorithm \\ref{alg:L-Slash0} \n\t\t\t%\t\t\t$$\n\t\t\t%\t\t\ttilde u^{1, \\nu_1} = u^{1, \\nu_1},\n\t\t\t%\t\t\t$$\n\t\t\t%\t\t\twhich is the output of Algorithm \\ref{alg:L-Slash}. \n\t\t\\end{itemize}\n\t\\end{itemize}\n\\end{proof}\n\nDespite of the simplicity look of Algorithm \\ref{alg:mgnet}, there\nare rich mathematical structures and variants which we briefly discuss below.\n\n\\subsection{Initialization: feature space channels}\nInitially for $\\ell=1$,  we take $m_1 = m$ and $n_1 = n$ and we may define the linear mapping \n\\begin{equation}\n\\label{eq:6}\n\\theta: \\mathbb R^{m\\times n\\times c}\n\\mapsto \\mathbb R^{m_1\\times n_1\\times c_1},\n\\end{equation}\nto obtain $f^{1} = \\theta(f)$ with $c$ given in \\eqref{data-c} changed to the channel of the initial\ndata space to $c_1$.   Usually\n\\begin{equation}\n\\label{cc}\nc_1\\ge c.  \n\\end{equation}\nOne possibility is that we choose $c_1=c$.  In this case, we choose\n$\\theta=$identity.   But in general, we may need to choose $c_1\\gg\nc$. One possible advantage of preprocessing the RGB ($c=3$) to \ndifferent color spaces is that we can better choose what kind of\nfeatures the CNN can detect, and under what \nconditions those detections will be invariant.\n\nOne possibility of understanding and modifying this step \nis to decompose the data $f$ into a number of more\nspecialized data\n\\begin{equation}\n\\label{decomp-f}\nf=\\sum_{k=1}^{c_1}\\xi_kf^1_k  =\\xi^Tf^1.\n\\end{equation}\nWe may use some knowledge from image processing or physics to\ndesign a procedure to obtain the right decomposition of\n\\eqref{decomp-f}, or we can just train it. \nConceivably, we may view $f^{1} = \\theta(f)$ as a special approximation solution of\n\\eqref{decomp-f} with the same sparsity pattern to $\\xi$. \n\n\\subsection{Extracted Units: $u^{\\ell}$ and channels}\nThe first new feature and the main new ingredient \nin the proposed neural network is the introduction \nof feature variables  $u^{\\ell}$ in \\eqref{u-ell}, which will be known\nas the extracted units. \n\nWe emphasize that the extracted-units $u^\\ell$ and the data $f^\\ell$ can have\ndifferent numbers of channels:\\\n\\begin{equation}\n\\label{uf-channels}\nu^\\ell\\in \\mathbb{R}^{m_\\ell\\times n_\\ell \\times c_{u,\\ell}}, \\quad\nf^\\ell\\in \\mathbb{R}^{m_\\ell\\times n_\\ell \\times c_{f,\\ell} }\n\\end{equation}\nOne possibility is that the number of channels for both $u$ and $f$ remain\nunchanged in different grids:  \n\\begin{equation}\n\\label{cfl}\nc_{f,\\ell}=c_f, \\quad \\ell=1:J,   \n\\end{equation}\nand \n\\begin{equation}\n\\label{ufl}\nc_{u,\\ell}=c_{u}, \\quad \\ell=1:J.   \n\\end{equation}\nBoth $c_f$ and $c_{u}$ are two super-parameters that need to be tuned, \nand we may even take $c_u = c_f$.\n\n\\subsection{Poolings: $\\Pi_{\\ell+1}^\\ell$ and $R_{\\ell+1}^\\ell$}\nThe pooling $\\Pi_{\\ell+1}^\\ell$ in \\eqref{restriction} and\n$R_{\\ell+1}^\\ell$ in \\eqref{restrict-f} are in general different.\nThey can be trained in general, but they may be a priori chosen.\n\nThere are many different possibilities to choose $\\Pi_{\\ell+1}^\\ell$. \nThe simplest choice of $\\Pi_{\\ell+1}^\\ell$ is \n\\begin{equation}\n\\label{eq:8}\n\\Pi_{\\ell+1}^\\ell=0.\n\\end{equation}\nA more sophisticated choice can be obtained by considering an\ninterpolation from fine grid to coarse (that, for example preserves linear function\nlocally).  Namely\n\\begin{equation}\n\\label{Pi}\n\\Pi_{\\ell+1}^\\ell=\\bar\\Pi_{\\ell+1}^\\ell \\otimes I_{c_\\ell\\times c_\\ell} \n\\end{equation}\nwith $\\bar\\Pi_{\\ell+1}^\\ell$ given by~\\eqref{mg-Pi}.\n\n\n\n\\subsection{Data-feature mapping: $A^{\\ell}$}\nThe second new feature of MgNet is that this data-feature mapping\nonly depends on the grid ${\\cal T}_\\ell$, and it does not depend on layers\nwithin the same grid.  This amounts to a significant saving of the number of\nparameters.  In comparison, the existing CNN, such as ResNet, can be\ninterpreted as a network related to the case that $A^{\\ell}$ is\nreplaced by $A^{\\ell, i}$, namely\n\\begin{equation}\\label{u-resnet}\nu^{\\ell,i} = u^{\\ell,i-1} + B^{\\ell,i}  (f^\\ell -  A^{\\ell,i} (u^{\\ell,i-1}).\n\\end{equation}\n\nThe data-feature mapping: $A^{\\ell}$ can be either linear\n\\eqref{linearA}, or nonlinear \\eqref{nonlinearA}.  The underlying\nconvolution kernels can be different on different grids and they can\nall be trained.\n\n\n\\subsection{Feature extractors: $B^{\\ell,i}$}\nThere are some freedoms in choosing these feature extrators.  \nOne common choice of extractors is given by \\eqref{extractor}, namely \n\\begin{equation}\n\\label{extractor-ell}\nB^{\\ell,i}=\\sigma\\circ \\eta^{\\ell,i}\\circ\\sigma.\n\\end{equation}\n\nOther than the level dependent extractors, the following \ndifferent strategies can be used\n\\begin{description}\n\t\\item[Constant Extractors]: $B^{\\ell,i}=B^{\\ell}$ for   $i=1:\\nu_\\ell$\n\t\\item[Scaled Extractors]:$B^{\\ell,i}=\\alpha_iB^{\\ell}$ for   $i=1:\\nu_\\ell$\n\t\\item[Variable Extractors]: $B^{\\ell,i}$\n\\end{description}\n\n\n\nThis brief framework gives us the basic principle on designing \na CNN models for classification. All models are seen as the special\nchoice of data-feature mapping $A^\\ell$, feature extractors $B^{\\ell,i}$ \nand the pooling operators $\\Pi_{\\ell+1}^\\ell$ with $R_{\\ell+1}^\\ell$.\n\n\n\\section{Some classic CNN models}\\label{sec:CNNs}\nIn this section, we will use the notation introduced above to \ngive a brief description of some classic CNN models.\n\n\\subsection{LeNet-5, AlexNet and VGG}\nThe  LeNet-5 \\cite{lecun1998gradient}, AlexNet \\cite{krizhevsky2012imagenet} and VGG \\cite{simonyan2014very}\ncan be written as:\n\t\\begin{equation}\n\t\\begin{cases}\n\tf^{1,0} &= \\theta^0(f), \\\\\n\tf^{\\ell,i} &= \\theta^{\\ell,i} \\circ \\sigma (f^{\\ell, j-1}), \\quad i = 1:\\nu_\\ell ~\\text{and}~ \\ell = 1:J,\\\\\n\tf^{\\ell+1,0} &= R_\\ell^{\\ell+1}( f^{\\ell,m+\\ell}).  \\\\\n\t\\end{cases}\n\t\\end{equation}\n\twhere $R_\\ell^{\\ell+1}$ can be general pooling operators and $\\theta^{\\ell,i}$ can be convolution with stride 1, \n\tor fully connected operators.  \n\tThen the CNN model will be defined by\n\t\\begin{equation}\\label{eq:cnndefine}\n\tH_0(f) = f^{L,\\nu_\\ell}.\n\t\\end{equation}\n\tIn these three classic CNN models, they still need some \n\textra fully connected layers in nonlinear mapping $H_0$ before the logistic regression as it contains \n\ta fully connected layer as in \\eqref{eq:log_reg}. \n\tThese fully connected layers are removed in ResNet to be described below.\n\\subsection{ResNet}\nThe ResNet \\cite{he2016deep} can be written as\n\t\\begin{equation}\\label{ori-ResNet}\n\t\\begin{cases}\n\tf^{1,0} &=R_{\\rm max}\\circ \\sigma \\circ \\theta^0(f), \\\\\n\tf^{\\ell,i} &= \\sigma \\left( f^{\\ell, i-1} + \\mathcal{F}^{\\ell, i} (f^{\\ell,i-1}) \\right), \\quad i = 1:\\nu_\\ell ~\\text{and}~ \\ell = 1:J ,\\\\\n\tf^{\\ell+1,0} &= \\sigma \\left( R_\\ell^{\\ell+1} (f^{\\ell, \\nu_\\ell} )+ \\mathcal{F}^{\\ell, 0} (f^{\\ell, \\nu_\\ell} ) \\right), \\quad \\ell = 1:J-1,\\\\\n\tH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\t\\end{cases}\n\t\\end{equation}\n\tHere\n\t$$\n\t\\mathcal{F}^{\\ell,i} (f^{i-1}) = \\xi^{i} \\circ \\sigma \\circ \\eta^{i} (f^{i-1}).\n\t$$\n\tGenerally, $\\xi^{\\ell,i}$ and $\\eta^{\\ell,i}$ takes the form of \\label{eq:conv-1} with zero padding and stride 1,\n\texcept, $\\eta^{\\ell,0}$  is taken as convolution with stride 2 with the same output dimension of $R_\\ell^{\\ell+1}$.\n\t\n\\subsection{iResNet} \n\tThe iResNet\\cite{he2016identity} can be written as:\n\t\\begin{equation}\\label{eq:iResNet1}\n\t\\begin{cases}\n\tf^{1,0} &=R_{\\rm max}\\circ \\sigma \\circ \\theta^0(f), \\\\\n\tf^{\\ell,i} &= f^{\\ell, i-1} + \\mathcal{F}^{\\ell, i} (f^{\\ell,i-1}), \\quad i = 1:\\nu_\\ell ~\\text{and}~ \\ell = 1:J ,\\\\\n\tf^{\\ell+1,0} &=  R_\\ell^{\\ell+1} (f^{\\ell, \\nu_\\ell} )+ \\mathcal{F}^{\\ell, 0} (f^{\\ell, \\nu_\\ell} ) , \\quad \\ell = 1:J-1,\\\\\n\tH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\t\\end{cases}\n\t\\end{equation}\n\twhere\n\t$$\n\t\\mathcal{F}^{\\ell,i} (f^{\\ell,i -1}) = \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} \\sigma (f^{\\ell,i-1}).\n\t$$\n\tThe only difference between ResNet and iResNet can be viewed as \n\tputting a $\\sigma$ in different places. \n\tThe connection of those three models are often shown with next diagrams:\n\t\\begin{figure}[!htb]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=.6\\textwidth, height=.13\\textheight]{comparison-net} \n\t\t\\end{center}\n\t\t\\caption{Comparison of CNN Structures}\n\t\\end{figure}\n\t\n\nWithout loss of generality, we extract the key \nfeedforward steps on the same grid in different CNN models as follows.\n\\begin{description}\n\t\\item[Classic CNN] \n\t\\begin{equation}\\label{eq:cCNN}\n\tf^{\\ell,i} = \\xi^i \\circ \\sigma (f^{\\ell,i-1}) \\quad \\text{or} \\quad f^{\\ell,i} = \\sigma \\circ \\xi^{i} (f^{\\ell,i-1}) .\n\t\\end{equation}\n\t\\item[ResNet] \n\t\\begin{equation}\\label{eq:ResNet}\n\tf^{\\ell,i} = \\sigma( f^{\\ell,i-1} + \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}(f^{\\ell,i-1})).\n\t\\end{equation}\n\t\\item[iResNet]\n\t\\begin{equation}\\label{eq:iResNet}\n\tf^{\\ell,i} = f^{\\ell,i-1} + \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma(f^{\\ell,i-1}).\n\t\\end{equation}\n\\end{description} \n\n\n\\section{Variants and generalizations of MgNet}\\label{sec:relation}\n\n%\\subsection{Some properties of MgNet}\n%So, this MgNet is corresponded to the multigrid methods \n%with iteration in function space. A natural idea is that there is also a dual version of \n%MgNet similar with the multigrid methods with iteration in dual space.\nThe MgNet model algorithm is one very basic and it can be generalized\nin many different ways. It can also be used as a guidance to modify and \nextend many existing CNN models. \n\nThe following result show how MgNet is related to he iResNet \\cite{he2016identity}. \n\\begin{theorem}\\label{thm:mgnet1}\nThe MgNet model Algorithm \\ref{alg:mgnet}, \nwith $A=\\xi^\\ell$ and $B^{\\ell,i}=\\sigma \\circ \\eta^{\\ell,i}\\circ\\sigma$, \nadmits the following identities\n\\begin{equation}\\label{dualmgnet}\nf^{\\ell, i} = f^{\\ell, i-1} -  \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma (f^{\\ell,i-1}), \\quad i = 1:\\nu_\\ell, \\\\\n\\end{equation}\nwhere\n\\begin{equation}\n  \\label{eq:5}\n\tf^{\\ell,i} = f^{\\ell} - \\xi^{\\ell} (u^{\\ell,i}).   \n\\end{equation}\nFurthermore, \\eqref{dualmgnet} represents iResNet~\\cite{he2016identity} \nas shown in \\eqref{eq:iResNet}.\n\\end{theorem}\n\n\\begin{proof}\n\tBecause of the linearity of $\\xi^\\ell$ and invariant within the same grid $\\ell$, \n\twe can apply $\\xi^\\ell$ on both sides of \\eqref{mgnet} and minus with\n\t$f^\\ell$, thus we have\n\t$$\n\tf^{\\ell} - \\xi^{\\ell} (u^{\\ell,i})= f^{\\ell} - \\xi^\\ell(u^{\\ell,i}) -\n\t\\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma (f^\\ell + \\xi^\\ell(u^{\\ell,i})).\n\t$$\nThis finish the proof with definition in \\eqref{eq:5}.\n\\end{proof}\n\nThe above result is very simple but critically important.\nIn view of Theorem \\ref{thm:mgnet1}, it shows how multigrid and \nCNN are intimately related. Furthermore, it provides a different version\nof iResNet, which can be viewed as the dual version of the original iResNet.\nThis relation is quit similar with the dual relation of $u$ and $f$\nin multigrid method \\cite{xu2017algebraic}.\n\\begin{lemma}\\label{thm:mgnet2} \n\tThe ResNet~\\cite{he2016deep} step\n \t as in \\eqref{eq:ResNet} \n%\t\\begin{equation}\\label{resnet}\n%\tf^{\\ell,i} = \\sigma( f^{\\ell, i-1} - \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} (f^{\\ell,i-1}) ).\n%\t\\end{equation}\nadmits the following relation:\n%(which resembles closely with \\eqref{dualmgnet}) \n\\begin{equation}\\label{tilde-resnet}\n\\tilde f^{\\ell,i} =\\sigma(\\tilde f^{\\ell,i-1}) -\n\\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma( \\tilde f^{\\ell,i-1}),\n\\end{equation}\nwhere\n\\begin{equation}\\label{tilde-f}\n\\tilde f^{\\ell,i} = f^{\\ell, i-1} -\\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} (f^{\\ell,i-1}).\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\n%\tNow, we will establish the connection between classical ResNet and MgNet. \n\tFirst, we apply $ \\xi^{\\ell,i+1} \\circ \\sigma \\circ \\eta^{\\ell,i+1}$ \n\ton the both sides of \\eqref{eq:ResNet} and get\n\t\\begin{equation}\\label{resnet1}\n\t\\xi^{\\ell,i+1} \\circ \\sigma \\circ \\eta^{\\ell,i+1}( f^{\\ell,i} ) = \n\t\\xi^{\\ell,i+1} \\circ \\sigma \\circ \\eta^{\\ell,i+1}\\circ \\sigma( \\tilde f^{\\ell,i} ).\n\t\\end{equation}\n\tMinus by $f^{\\ell,i}$ on the both sides and recall the definition in \\eqref{tilde-f}, we have\n\t\\begin{equation*}\n\t\\tilde f^{\\ell,i+1} = f^{\\ell,i} - \\xi^{\\ell,i+1} \\circ \\sigma \\circ \\eta^{\\ell,i+1}\\circ \\sigma( \\tilde f^{\\ell,i}).\n\t\\end{equation*}\n\tBy the definition of $f^{\\ell,i} = \\sigma(\\tilde f^{\\ell,i})$, we finish this proof.\n\\end{proof}\n\nWe call the above form \\eqref{tilde-resnet} as\n$\\sigma$-ResNet, similar to the MgNet we replace $\\xi^{\\ell,i}$ by $\\xi^{\\ell}$  and get \nthe next Mg-ResNet form as:\n\\begin{equation}\\label{mg-resnet}\nf^{\\ell,i} =\\sigma(f^{\\ell,i-1}) -\n\\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma(f^{\\ell,i-1}).\n\\end{equation}\n\nIf we take these pooling and prolongation operators\nas discussed in the previous sections and focus on \nthe iterative forms on a certain grid $\\ell$, we may\ncompare them all as:\n\\begin{table}[!htbp]\n\t\\caption{Comparison for all iterative forms }\n\t\\label{comparison-ALL}\n\t\\begin{center}\\scriptsize\n\t\t\\resizebox{.8\\textwidth}{!}{\n\t\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\tPrimal-Dual & Model & Iterative form \\\\\n\t\t\t\t\\hline\n\t\t\t\t\\multirow{3}{*}{Feature space} & Abstract-MgNet & Solving $A^\\ell(u^\\ell) = f^\\ell$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& General-MgNet & $u^{\\ell,i} = u^{\\ell, i-1} + B^{\\ell,i} (f^\\ell - A^{\\ell}(u^{\\ell,i-1}))$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& {MgNet} & $u^{\\ell,i} = u^{\\ell, i-1} + \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma (f^\\ell - \\xi^{\\ell}(u^{\\ell,i-1}))$ \\\\\n\t\t\t\t\\hline\n\t\t\t\t\t\\multirow{5}{*}{Data space} & iResNet & $ f^{\\ell,i} = f^{\\ell, i-1} -  \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} \\circ \\sigma (f^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& Mg-iResNet & $f^{\\ell,i} = f^{\\ell, i-1} -  \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma (f^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& Mg-ResNet & $f^{\\ell,i} = \\sigma(f^{\\ell,i-1}) - \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma( f^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& $\\sigma$-ResNet & $f^{\\ell,i} = \\sigma(f^{\\ell,i-1}) - \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}\\circ \\sigma( f^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& ResNet & $f^{\\ell,i} = \\sigma(f^{\\ell, i-1} -  \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} (f^{\\ell,i-1}))$ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular} \n\t\t}\n\t\\end{center}\n\\end{table}\n\nWe can have these connections for all iterative scheme in data space:\n\\begin{equation}\n\\text{ ResNet} \\xleftrightarrow{\\eqref{tilde-f}} \\sigma\\text{-ResNet } \\xleftrightarrow{\\xi^{\\ell,i} \\leftrightarrow \\xi^{\\ell}} \\text{Mg-ResNet}  \n\\xleftrightarrow{\\sigma(f^{\\ell,i-1}) \\leftrightarrow f^{\\ell, i-1} } \\text{Mg-iResNet} \\xleftrightarrow{ \\xi^{\\ell} \\leftrightarrow \\xi^{\\ell,i}} \\text{iResNet}.\n\\end{equation}\n\n%Because of the linearity of $\\xi^{\\ell,i}$, the above forms of iResNet and ResNet\n%are equivalent to the previous as \\eqref{dualmgnet} and \\eqref{tilde-resnet}.\n\nIn this sense, these MgNet related models can be understood as\n models between iResNet and ResNet. And all these models can be\n understood as iteration in the data space as a dual relationship with\n feature space as MgNet.\n \n \nThe rationality of replacing  $\\xi^{\\ell,i}$ by layer independent $\\xi^{\\ell}$ may\nbe justified by the following theorem. \n\\begin{theorem}\\label{thm:CNN}\nOn each grid $\\mathcal T_\\ell$, \n\\begin{enumerate}\n\t\\item Any CNN model with\n%\tCNN and Mg-ResNet] \n\t\\begin{equation}\n\t\\label{CNN1}\n\tf^{\\ell,i} =   \\chi^{\\ell,i} \\circ \\sigma (f^{\\ell,i-1}),\n\t\\end{equation} \n\tcan be written as\n\t\\begin{equation}\\label{Res-CNN1}\n\tf^{\\ell,i} = \\sigma(f^{\\ell,i-1}) - \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i} \\circ\\sigma ( f^{\\ell,i-1}).\n\t\\end{equation}\n\t\\item Any CNN model with \n%\t[CNN and ResNet] \n\t\\begin{equation}\n\t\\label{CNN2}\n\tf^{\\ell,i} =   \\sigma\\circ\\chi^{\\ell,i} (f^{\\ell,i-1}).\n\t\\end{equation}\n\tcan be written as \n\t\\begin{equation}\\label{Res-CNN2}\n\tf^{\\ell,i} = \\sigma\\left(f^{\\ell,i-1} - \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}  ( f^{\\ell,i-1})\\right).\n\t\\end{equation}\n\\end{enumerate}\n\n%\\begin{equation}\n% \\chi^{\\ell,i}: \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell} \n% \\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell},\n%\\end{equation}\n\\end{theorem}\n\\begin{proof}\n%\tWithout loss of generality, consider the classical CNN with \n%\t\\begin{equation}\n%\tf^{\\ell,i} =   ({\\rm id}  + \\tilde \\eta^{\\ell,i} )\\circ \\sigma (f^{\\ell,i-1}).\n%\t\\end{equation}\nLet use prove the first case as an example, \nthe second case can be proven with the same process.\n\nWith similar structure in MgNet, we can take\n\\begin{equation}\n\\label{xi-cnn1}\n\\xi^{\\ell}=  [\\hat \\delta_1, \\cdots, \\hat \\delta_{{c_\\ell}}],\n\\end{equation}\nand \n\\begin{equation}\n\\label{eta-ell}\n\\eta^{\\ell,i} = [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}] \\circ (\\chi^{\\ell,i} - {\\rm id}_{c_\\ell}).\n\\end{equation}\nHere \n\\begin{equation}\n{\\rm id}_{c_\\ell}: \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell} \n\\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell},\n\\end{equation}\nis the identity map and \n\\begin{equation}\n\\hat \\delta_k :  \\mathbb{R}^{n_\\ell \\times n_\\ell \\times 2c_\\ell} \n\\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell},\n\\end{equation}\nwith \n\\begin{equation}\\label{eq:hatdelta}\n\\hat \\delta_k([X ,Y]) = -([X]_k + [Y]_k),\n\\end{equation}\nfor any $X, Y \\in \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell}$ \nand $[X,Y] \\in \\mathbb{R}^{n_\\ell \\times n_\\ell \\times 2c_\\ell} $.\n\n\n\tFirst, we see that $\\eta^{\\ell,i}$ with the above \n\tform is a convolution from $\\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell}$\n\tto  $\\mathbb{R}^{n_\\ell \\times n_\\ell \\times 2c_\\ell}$.\n\tFollowing the identity\n\t\\begin{equation}\n\tReLU(x) + ReLU(-x) = x,\n\t\\end{equation}\n\tand the definition of $\\xi^{\\ell}$ i.e. \n\t\\begin{equation}\n\t\\xi^{\\ell} = \\hat \\delta,\n\t\\end{equation}\n\tas a special case in MgNet. \n\tFor more details, we can give a exact form of \n\t$\\hat \\delta_k$ as in \\eqref{eq:hatdelta} with\n\t\\begin{equation}\n\t\\hat \\delta_k = [0, \\cdots,0, -\\delta, \\cdots 0;  0, \\cdots,0, -\\delta, \\cdots 0],  \\quad k = 1:{c_\\ell},\n\t\\end{equation}\n\twhere $\\delta$ is the identity kernel during one channel.\n\t\n\tAt last, we have\n\t\\begin{align}\n\t\\left[\\xi^{\\ell} \\circ \\sigma \\circ [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}] (x) \\right]_k &=  \\left[\\xi^{\\ell} \\circ \\sigma \\circ [x, -x]  \\right]_k, \\\\\n\t&= \\hat \\delta_k ( [\\sigma(x), \\sigma(-x)]),  \\\\\n\t&= -\\delta([\\sigma(x)]_k) - \\delta([\\sigma(-x)]_k),\\\\\n\t&=-( \\sigma([x]_k)+ \\sigma(-[x]_k)) , \\\\\n\t&=  -[x]_k\n\t\\end{align}\n\tThus to say,\n\t\\begin{equation}\n\t\\xi^{\\ell} \\circ \\sigma \\circ [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}]  = -{\\rm id}_{c_\\ell}.\n\t\\end{equation}\n\tThen the modified dual form of MgNet in \\eqref{tilde-resnet} becomes\n\t\\begin{align}\n\tf^{\\ell,i} &= \\sigma(f^{\\ell,i-1}) - \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} \\circ\\sigma ( f^{\\ell,i-1}) , \\\\\n\t&=  \\sigma(f^{\\ell,i-1}) - \\left( \\xi^{\\ell} \\circ \\sigma \\circ [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}] \\right) \n\t\\circ (\\chi^{\\ell,i} - {\\rm id}_{c_\\ell})\\circ \\sigma(f^{\\ell,i-1})\\\\\n\t&=\\sigma(f^{\\ell,i-1}) + (\\chi^{\\ell,i} -{\\rm id}_{c_\\ell})\\circ \\sigma(f^{\\ell,i-1}),  \\\\\n\t&=\\chi^{\\ell,i} \\circ  \\sigma (f^{\\ell,i-1}).\n\t\\end{align}\n\tThis covers \\eqref{Res-CNN1}.\n\\end{proof}\n\n\n\\begin{remark}\nTheorems~\\ref{thm:CNN} shows that general CNN in\nthe forms of either \\eqref{CNN1} or \\eqref{CNN2} can be written recast\nas \\eqref{Res-CNN1} or \\eqref{Res-CNN2} with the data-feature mapping \n$A^\\ell=\\xi^\\ell$ that is not only independent of the layers, but is\nactually given a priori as in \\eqref{xi-cnn1}.  In\nview of Theorems~\\ref{thm:mgnet1} and \\ref{thm:mgnet2}, the classic\nCNN models can be essentially recovered from MgNet by choosing\n$\\xi^\\ell$ a priori as in  \\eqref{xi-cnn1}.  Since\nthe classic CNN models have been extensively tested to be successful,\nthe more general MgNet with more general $\\xi^\\ell$ (to be trained)\nare expected to be more efficient than the classic CNN models. \n\\end{remark}\n\n%At last we have the next relation:\n%\\input{MgNet-relation.tex}\n\n\\section{Numerical experiments}\\label{sec:numerics}\nIn this section, we present some numerical results to illustrate the\nefficiency and potential of MgNet as described in Algorithm\n\\ref{alg:mgnet}.\n\n\\subsection{Data sets and model structure }\nWe choose CIFAR-10 and CIFAR-100 \n\\cite{krizhevsky2009learning}\nas two data sets for numerical tests. \nHere, the CIFAR-10 dataset consists of 60000 32x32 colour \nimages in 10 classes, with 6000 images per class. \nThe CIFAR-100 dataset is just like the CIFAR-10, \nexcept it has 100 classes containing 600 images each. \nWe split these two data sets with 50000 training images \nand 10000 test images. \n\n\nWe will mainly carry out\n a comparison with study between MgNet and  ResNet \\cite{he2016deep} \non these two data sets, so we choose some \nsimilar process techniques such as there will \nbe a average pooling before linear regression\nlayers:\n\\begin{equation}\\label{eq:ave-pooling}\nR_{ave}: \\mathbb{R}^{m_{J-1} \\times n_{J-1} \\times c_{J-1}} \\mapsto \\mathbb{R}^{c_{J-1}}.\n\\end{equation}\nWe use the similar ideas in MgNet to take $m_{J} = 0$, thus to choose \n$$\nu^{J} = \\Pi_{J-1}^J u^{J-1, m_{J-1}} \\in \\mathbb{R}^{c_{J-1}},\n$$\nwith\n$$\n\\Pi_{J-1}^J  = R_{ave}.\n$$\nThis can be true also thanks to our structure that \n\\begin{equation}\\label{eq:c_u}\nc_{u,\\ell} = c_{u}, \\quad 1 \\le \\ell \\le J.\n\\end{equation}\nGiven an image $f$, similar to ResNet, we apply our MgNet as follows:\n\\begin{equation}\\label{final-mg}\ny = S \\circ \\theta \\circ u^{J}(f),\n\\end{equation}\nwhere $u^J(f)$ is the output from our MgNet as described in Algorithm\n\\ref{alg:mgnet},  $S$ is the soft-max mapping in \\eqref{softmax} and \n\\begin{equation}\\label{final-theta}\n\\theta: \\mathbb{R}^{c_u} \\mapsto \\mathbb{R}^\\kappa,\n\\end{equation}\nrepresents a fully linear layer with $\\kappa = 10$ for CIFAR-10 and \n$\\kappa = 100$ for CIFAR-100.\n\nWe will make the following choice of hyper parameters\nfor the MgNet:\n\\begin{itemize}\n\t\\item $J$: the number of grids. As all images in CIFAR-10 or CIFAR-100\n\tare $32\\times 32 \\times 3$,  we choose $J = 4$ to be consistent with ResNet.\n\t\\item $\\nu_\\ell$:  the number of smoothings in each grids. To be consistent with\n\tResNet-18 or ResNet-34 we choose $\\nu_\\ell = 2$ or $\\nu_\\ell = 4$.\n\t\\item $c_u$ and $c_f$: the number of feature and data channels. \n\t\\item $A^\\ell$: the data-feature mapping. We choose the linear case in \\eqref{linearA}.\n\t\\item $B^{\\ell,i}$: the feature extractor. We choose the variable extractors as in \\eqref{extractor-ell}.\n\t\\item $R_{\\ell}^{\\ell+1}$: the restriction operator in \\eqref{restrict-f}. \n\tHere we choose it as a convolution with stride $2$ which need to be trained.\n\t\\item $\\Pi_\\ell^{\\ell+1}$: the interpolation operator in\n\t\\eqref{interpolation}.  Here we compare these next three\n\tdifferent choices: \n\t\\begin{enumerate}\n\t\t\\item {$\\Pi_0$: } $\\Pi_\\ell^{\\ell+1} = 0$;\n\t\t\\item {$\\Pi_1$: }convolution with stride $2$ which need to be\n\t\ttrained; \n\t\t\\item {$\\Pi_2$: }channel-wise interpolation as in\n\t\t\\eqref{Pi}, with $\\bar P_{\\ell}^{\\ell+1}$ as a convolution\n\t\twith one channel and stride $2$ which also need to be trained.\n\t\\end{enumerate}\n\\end{itemize}\n\n\\subsection{Training algorithm}\nWhile there are many different choices of training algorithms \\cite{bottou2018optimization}, \nin our test, we adopt the popular \nstochastic gradient descent (SGD) with mith-batch and momentum for\ncross-entropy loss function.\n\\begin{breakablealgorithm}\n\t\\caption{SGD with mini-batch and momentum}\n\t\\label{alg:sgd}\n\t\\begin{algorithmic}\n\\State {\\bf Input}: learning rate $\\eta_t$, batch size $m$, parameter Initialization $ w_0$, number of epochs $K$. \n\\For{Epoch $k = 1:K$} \\\\\n\\State Shuffle data and get mini-batch $B_1, \\cdots, B_{\\frac{N}{m}}$, choose mini-batch as: $B_{i_t}$ with\n$$\ni_t \\equiv t \\mod(\\frac{N}{m}),\n$$\n\\State Compute the gradient on $B_{i_t}$:\n$$\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} h_i(w_{t}).\n$$\n\\State Compute the momentum:\n\\begin{equation}\nv_t = \\alpha v_{t-1} - \\eta_t g_t \\quad (v_0 = 0).\n\\end{equation}\n\\State Update $w$:\n\\begin{equation}\nw_{t+1} = w_t + v_t.\n\\end{equation}\n\\EndFor\n\\end{algorithmic}\n\\end{breakablealgorithm}\n\nHere we have $h_i(w_t) = l(\\classmap(f_i;w_t),y_i)$ as defined in \\eqref{eq:3}, where $w_t$ notes all free parameters in MgNet and $\\theta$ in \\eqref{final-theta}.\nWe use the SGD with momentum of 0.9. \nThe mini-batch size is chosen as\n$m=128$. The learning rate starts from 0.1 and is divided by $10$ for\nevery $30$ epochs, and the models are trained for up to $K=120$ epochs.\nWe adopt batch normalization (BN) after each convolution and before\nactivation, following \\cite{ioffe2015batch}.  Initialization strategy\nis the same with ResNet as in \\cite{he2015delving}.  We\ndo not use weight decay and dropout.  The final Top-1 test accuracy is\nshown in Table~\\ref{comparison}.\n\\begin{table}[!htbp]\n\t\\caption{ResNet and MgNet on CIFAR-10 and CIFAR-100. \n\tOur methods are named with $\\nu_\\ell$, ($c_u$, $c_f$), $\\Pi_\\ell^{\\ell+1}$ by definition above.}\n\t\\label{comparison}\n\t\\vskip 0.15in\n\t\\begin{center}\n\t\t\t\t%\t\t\\resizebox{.5\\textwidth}{!}{\n\t\t\t\t\\begin{tabular}{cccc}\n\t\t\t\t\t\\hline\n\t\t\t\t\tModels & CIFAR-10 & CIFAR-100 & Params \\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\tResNet-18 & 92.24 & 71.96 & 11.2M   \\\\\n\t\t\t\t\tResNet-34 & 92.80 & 71.93 & 21.3M   \\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\t%\t\t\t\t{$\\nu_\\ell$,  $(c_u, c_f)$, $\\Pi_\\ell^{\\ell+1}$} & Accuracy & Accuracy & Numbers  \\\\\n\t\t\t\t\t$2, (256,256)$, $\\Pi_0$ & 92.02 & 68.29 & 7.1M  \\\\\n\t\t\t\t\t$2, (256,256)$, $\\Pi_1$ & 93.04 & 72.32 & 8.9M  \\\\\n\t\t\t\t\t$2, (256,512)$, $\\Pi_1$ & 93.20 & 72.42 & 19.5M  \\\\ \n\t\t\t\t\t$4, (256,512)$, $\\Pi_2$ & 93.53& 74.26 & 17.7M  \\\\ \n\t\t\t\t\t\\hline\n\t\t\t\t\\end{tabular} \n\t\t%\t\t}\n\t\\end{center}\n\t\\vskip -0.1in\n\\end{table}\n\nFrom the above numerical results, we find that the modified CNN models\nbased on MgNet structure have competitive and sometimes better\nperformance in comparison with standard ResNet models when applied to\nboth CIFAR-10 and CIFAR-100 data sets. Generally speaking, the more\nchannels the better performance you can achieve (see WideResNet\n\\cite{zagoruyko2016wide} for similar observation). Furthermore,\n$\\Pi_1$ and $\\Pi_2$ work better than $\\Pi_0$, and $\\Pi_2$ can even\nwork better than $\\Pi_1$ with fewer parameters for big enough \nchannel numbers.\n\n\n\\section{Concluding remarks}\\label{sec:conclusion}\nBy carefully studying the connections between the traditional\nmultigrid method and the convolutional neural network (especially the\nResNet type) models, the MgNet established in this paper provides a\nunified framework that connects both multigrid and CNN in a technical\nlevel.  Comparing with other existing works that discuss the\nconnection between multigrid and CNN, MgNet goes beyond formal or\nqualitative comparisons and identifies key model components that play\nthe same corresponding roles, from an abstract viewpoint, for these two different\nmethodologies.  As a result, how and why CNN models work can be\nmathematically understood in a similar fashion as for multigrid method\nwhich has a much more mature and better developed theory.  Motivated\nfrom various known techniques from multigrid method, many variants and\nimprovements of CNN can then be naturally obtained.  For example, as\ndemonstrated from our preliminary numerical experiments, the resulting\nmodified CNN models quipped with fewer weights and hyper parameters\nactually exhibit competitive and sometimes better performance than\nstandard ResNet models.\n\nThe MgNet framework opens a new door to the\nmathematical understanding, analysis and improvements of deep learning\nmodels.  The very preliminary results presented in\nthis paper have demonstrated the great potential of MgNet from both\ntheoretical and practical viewpoints.  Obviously many aspects of MgNet\nshould be further explored and expect to be much improved.  In fact, only very\nfew techniques from multigrid method have been tried in this paper and\nmany more in-depth techniques from multigrid require further study for\ndeep neural networks, especially CNN.  \nIn particular, we believe that the MgNet framework will\nlead to improved CNN that only has a small fraction of the number\nof weights that are required by the current CNN. On the other hand,\nthe techniques in CNN can also be used to develop new generation of multigrid\nand especially  algebraic multigrid methods \\cite{xu2017algebraic} for solving\npartial differential equations. Our ongoing works have\ndemonstrated great potentials for research in these directions and  many\nmore results will be reported in future papers. ", "meta": {"hexsha": "751148d7894a2acf1a94c3b822a52a1bd6ec9e12", "size": 32798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MgNet_mgnet.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/MgNet_mgnet.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/MgNet_mgnet.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.3746770026, "max_line_length": 167, "alphanum_fraction": 0.6710165254, "num_tokens": 11802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6875398669916234}}
{"text": "\\documentclass[12pt]{article}\n\n\\def\\exercisename{DG notes}\n\\usepackage{mystyle}\n\\begin{document}\t\n\t\\section*{\\exercisename}\n\n\nEquation to be solved:\n\\begin{equation*}\n    \\frac{\\partial u}{\\partial t} + \\frac{\\partial au}{\\partial x} = 0\n\\end{equation*}\nMultiplication by a test function $v(x)$ and integration over each element:\n\\begin{equation*}\n\t\\int_{V_e} \\frac{\\partial u}{\\partial t}\\, v\\, dV_e + \\int_{V_e} \\frac{\\partial au}{\\partial x}\\, v\\, dV_e = 0\n\\end{equation*}\nThe second term can be integrated by parts:\n\\begin{equation*}\n\t\\int_{x_1}^{x_2} \\frac{\\partial u}{\\partial t}\\, v\\, d{V_e} \n\t+ \\left[ au\\,v\\right]_{x_1}^{x_2}\n\t  - \\int_{x_1}^{x_2} au \\frac{\\partial v}{\\partial x}\\, d{V_e} = 0\n\\end{equation*}\nThe key idea of the method is to replace the flux $au$ on the boundary by a flux numerical $f^*$ that is evaluated from the values of $u$ in the neighbouring elements. Thanks to this numerical flux, all the equations will be coupled.\n\\begin{equation*}\n\t\\int_{x_1}^{x_2} \\frac{\\partial u}{\\partial t}\\, v\\, d{V_e} \n\t+ \\left[ f^*\\,v\\right]_{x_1}^{x_2}\n\t- \\int_{x_1}^{x_2} au \\frac{\\partial v}{\\partial x}\\, d{V_e} = 0\n\\end{equation*}\nWe can integrate by parts the last term:\n\\begin{equation*}\n\t\\int_{x_1}^{x_2} \\frac{\\partial u}{\\partial t}\\, v\\, dx  + \\int_{x_1}^{x_2} \\frac{\\partial au}{\\partial x}\\, v\\, dx\n= \\left[ (au - f^*)\\,v\\right]_{x_1}^{x_2}\n\\end{equation*}\nLet $N_i(x)$ be the shape functions.\n\\begin{equation*}\n\tv(x) = \\sum_i N_i(x)\\, v_i\n\\end{equation*}\n\\begin{equation*}\n\tu(x,t) = \\sum_j N_j(x)\\, u_j(t)\n\\end{equation*}\nThe integral equation becomes:\n\\begin{equation*}\n\t\\sum_i \\sum_j \n\t\\left[ \n\t\\int_{x_1}^{x_2} N_i(x)\\,N_j(x)\\, dx\\, \\frac{\\partial u_j(t)}{\\partial t}\n\t+\n\t\\int_{x_1}^{x_2} N_i(x)\\,\\frac{\\partial N_j(x)}{\\partial x}\\, dx\\,  au_j(t)\n\t\\right]\n\t\\, v_i \n\\end{equation*}\n\\begin{equation*}\n\t= \\sum_i \\sum_j \n\t\\left[ \n\t\t\\left( N_j(x)\\,au_j(t) - f^{*}\\right)\\,N_i(x)\n\t\\right]_{x_1}^{x_2}\n\t\\, v_i \n\\end{equation*}\nThis equality should be verified for any $v_i$, thus, each coefficient of $v_i$ should vanish. This leads to a system of equations:\n\\begin{equation*}\n \\sum_j M_{ij}\\, u_j + S_{ij}\\,u_j \n = \n (au_j(x_2)-f^*(x_2))\\,N_i(x_2) - (au_j(x_1)-f^*(x_1))\\,N_i(x_1)\n\\end{equation*}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "ebda7b03a249eb1d7d3cc74dc97c869fe3c5893e", "size": 2242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classes/dg/doc/dg_notes.tex", "max_stars_repo_name": "rboman/progs", "max_stars_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-12T13:26:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T16:14:53.000Z", "max_issues_repo_path": "classes/dg/doc/dg_notes.tex", "max_issues_repo_name": "rboman/progs", "max_issues_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-03-01T07:08:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-28T07:32:42.000Z", "max_forks_repo_path": "classes/dg/doc/dg_notes.tex", "max_forks_repo_name": "rboman/progs", "max_forks_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-12-13T13:13:52.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-13T20:08:15.000Z", "avg_line_length": 32.9705882353, "max_line_length": 233, "alphanum_fraction": 0.6445138269, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.687397211873064}}
{"text": "\\section{Content}\n\n\\subsection{Notation}\n\n\\begin{Defn}\n  \\label{defn:1}\n  Some definitions, $\\cos(x)$ and \\(\\sin(x)\\) are\n  \\begin{eqnarray}\n    \\cos(x) \\doteq \\frac{e^{ix}+e^{-ix}}{2}  \\label{eq:fefwe} \\\\\n    \\sin(x) \\doteq \\frac{e^{ix}-e^{-ix}}{2i} \\label{eq:fefwe2}\n  \\end{eqnarray}\n  A reference to a figure \\ref{fig:a354}.\n  A reference \\eqref{eq:fefwe} and  \\eqref{eq:fefwe2} to the above equations.\n\\end{Defn}\n\n\n\n\\begin{figure}[ht]\\label{fig:a354}\n  \\begin{center}\n    \\includegraphics[width=0.5\\textwidth]{F/sin}\n    \\caption{Graph of \\(\\sin(x)\\).}\n  \\end{center}\n\\end{figure}\n\n\n\\lipsum[2]\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"paper\"\n%%% End:\n", "meta": {"hexsha": "1bc2621d06fd8122dba02e73ad2e176d697147e6", "size": 670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "test/paper/sec1.tex", "max_stars_repo_name": "mennucc/ColDoc_project", "max_stars_repo_head_hexsha": "947a79592b689f57e59652b37868cc22e520f724", "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": "test/paper/sec1.tex", "max_issues_repo_name": "mennucc/ColDoc_project", "max_issues_repo_head_hexsha": "947a79592b689f57e59652b37868cc22e520f724", "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": "test/paper/sec1.tex", "max_forks_repo_name": "mennucc/ColDoc_project", "max_forks_repo_head_hexsha": "947a79592b689f57e59652b37868cc22e520f724", "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": 20.303030303, "max_line_length": 77, "alphanum_fraction": 0.6223880597, "num_tokens": 261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6873497073312265}}
{"text": "\\section{Imbalanced Data}\n\n% ===\n\\emph{Cost Sensitive Classification}\nReplace loss by: $\\ell_{CS}(w;x,y) = c_y \\ell(w;x,y)$\n\n$\\color{gray} \\text{e.g. } \\ell_{\\pm} = c_\\pm \\ell(w;x,y)\n\\to c_-\\cdot \\hat R(w; \\frac{c_+}{c_-},c_-)$\n\n% ===\n\\emph{Metrics}\n\n\\begin{minipage}{.7\\linewidth}\n\t\\textbf{acc} $= \\frac{\\textrm{TP}+\\textrm{TN}}{n}$,\n\t\\textbf{prec} $= \\frac{\\textrm{TP}}{p_+}$\n\t\n\t\\textbf{FPR} $= \\frac{\\textrm{FP}}{n_-}$,\n\t\\textbf{Recall/TPR} $= \\frac{\\textrm{TP}}{n_+}$\n\\end{minipage}%\n\\begin{minipage}{.3\\linewidth}\n\t\\begin{tabular}{@{}l @{ }l | @{ }l}\n\t\tTP & FP & $p_+$\\\\\n\t\tFN & TN & $p_-$\\\\\\hline\n\t\t$n_+$ & $n_-$ & $n$\n\t\\end{tabular}\n\\end{minipage}\n\n\\textbf{Fβ score}: $F_\\beta = \\frac{(1+\\beta)^2}{\\frac{1}{\\textrm{prec}} + \\frac{\\beta^2}{\\textrm{rec}}}$,\n\\enskip\n\\textbf{ROC:} FPR vs. TPR\n", "meta": {"hexsha": "906e941097f3041f1b7cb9f45199d9cecca6fe95", "size": 796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Imbalance.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Imbalance.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Imbalance.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": 25.6774193548, "max_line_length": 106, "alphanum_fraction": 0.5703517588, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6873497068883853}}
{"text": "\\section{Other Algorithms}\r\n  \\subsection{2SAT}\r\n    Build the implication graph of the input by converting ORs $A \\vee B$ to\r\n    $!A \\rightarrow B$ and $!B \\rightarrow A$. This forms a bipartite graph.\r\n    If there exists $X$ such that both $X$ and $!X$ are in the same strongly connected component,\r\n    then there is no solution. Otherwise, iterate through the literals, arbitrarily assign\r\n    a truth value to unassigned literals and propagate the values to its neighbors.\r\n\\begin{comment}\r\n    \\code{other/two_sat.cpp}\r\n\\end{comment}\r\n  \\subsection{DPLL Algorithm}\r\n    A SAT solver that can solve a random 1000-variable SAT instance within a second.\r\n    \\code{other/dpll.cpp}\r\n  \\subsection{Stable Marriage}\r\n    \\ifverbose\r\n    The Gale-Shapley algorithm for solving the stable marriage problem.\r\n    \\fi\r\n    \\code{other/stable_marriage.cpp}\r\n\\begin{comment}\r\n  \\subsection{Algorithm X}\r\n    \\ifverbose\r\n    An implementation of Knuth's Algorithm X, using dancing links. Solves the Exact Cover problem.\r\n    \\fi\r\n    \\code{other/algorithm_x.cpp}\r\n  \\subsection{Matroid Intersection}\r\n    Computes the maximum weight and cardinality intersection of two\r\n    matroids, specified by implementing the required abstract methods, in\r\n    $O(n^3(M_1+M_2))$.\r\n    \\code{other/matroid_intersection.cpp}\r\n\\end{comment}\r\n  \\subsection{Cycle-Finding}\r\n    \\ifverbose\r\n    An implementation of Floyd's Cycle-Finding algorithm.\r\n    \\fi\r\n    \\code{other/floyds_algorithm.cpp}\r\n  \\subsection{Longest Increasing Subsequence}\r\n    \\code{other/lis.cpp}\r\n  \\subsection{Dates}\r\n    \\ifverbose\r\n    Functions to simplify date calculations.\r\n    \\fi\r\n    \\code{other/dates.cpp}\r\n  \\subsection{Simulated Annealing}\r\n    An example use of Simulated Annealing to find a permutation of length $n$\r\n    that maximizes $\\sum_{i=1}^{n-1}|p_i - p_{i+1}|$.\r\n    \\code{other/simulated_annealing.cpp}\r\n  \\subsection{Simplex}\r\n    \\begin{verbatim}\r\n// Two-phase simplex algorithm for solving linear programs\r\n// of the form\r\n//     maximize     c^T x\r\n//     subject to   Ax <= b\r\n//                  x >= 0\r\n// INPUT: A -- an m x n matrix\r\n//        b -- an m-dimensional vector\r\n//        c -- an n-dimensional vector\r\n//        x -- a vector where the optimal solution will be\r\n//             stored\r\n// OUTPUT: value of the optimal solution (infinity if\r\n//                   unbounded above, nan if infeasible)\r\n// To use this code, create an LPSolver object with A, b,\r\n// and c as arguments.  Then, call Solve(x).\r\n    \\end{verbatim}\r\n    \\code{other/simplex.cpp}\r\n  \\subsection{Fast Input Reading}\r\n    If input or output is huge, sometimes it is beneficial to optimize the\r\n    input reading/output writing. This can be achieved by reading all input\r\n    in at once (using fread), and then parsing it manually. Output can also\r\n    be stored in an output buffer and then dumped once in the end (using\r\n    fwrite). A simpler, but still effective, way to achieve speed is to use\r\n    the following input reading method.\r\n    \\code{tricks/fast_input.cpp}\r\n  \\subsection{128-bit Integer}\r\n    GCC has a 128-bit integer data type named \\texttt{\\_\\_int128}. Useful\r\n    if doing multiplication of 64-bit integers, or something needing a\r\n    little more than 64-bits to represent. There's also\r\n    \\texttt{\\_\\_float128}.\r\n  \\subsection{Bit Hacks}\r\n    \\code{tricks/snoob.cpp}\r\n", "meta": {"hexsha": "b2c8cc1c453c0e9430491686a80be42228e93c86", "size": 3360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/other.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/other.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/other.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": 42.0, "max_line_length": 99, "alphanum_fraction": 0.6848214286, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8723473647220787, "lm_q1q2_score": 0.6873497021013958}}
{"text": "\n\\section{Downsampling}\n\nThe analysed data was recorded at 32 kHz. For faster processing, the data was downsampled. The Nyquist frequency after downsampling needs to be sufficiently high for sharp-wave ripple detection.\\footnotemark{} As ripples have a frequency of up to 250 Hz (\\cref{tab:bands}), the new sampling frequency needs to be larger than 500 Hz. I chose a new sampling frequency of 1000 Hz. This allows integer subsampling of the original data, by a factor 32.\n\n\\footnotetext{The Nyquist frequency is the maximum discernible frequency in a digital signal, equal to half the sampling frequency.}\n\nTo counter aliasing, the 32 kHz data was low-pass filtered before subsampling.\\footnotemark{} The cutoff frequency was chosen to be 80\\% of the new Nyquist frequency (i.e. at 400 Hz for a new sampling frequency of 1000 Hz). The digital filter was applied both in forwards and backwards directions over the signal, to cancel out distortions due to filter delays that vary per frequency component. The filter type and parameters were chosen to yield both low processing time and low-distortion, high quality filtering, as was verified visually (see for example \\cref{fig:downsample}).\n\n\\footnotetext{A type I Chebyshev filter was used, which is an infinite impulse response filter, with relatively steep roll-off. The filter was of order 8 and had a passband ripple of 0.05 dB. For this filter, the cutoff frequency is defined to be where the gain starts dropping below the passband ripple.}\n\n\\begin{figure}\n\\img[1]{downsample}\n\\captionn{Downsampling the data}{Blue: the recorded data at 32 kHz. Orange: the same data, after downsampling to 1000 Hz. The arrow indicates a possible neural spike, removed by the anti-aliasing filter.}\n\\label{fig:downsample}\n\\end{figure}\n", "meta": {"hexsha": "85a3206241a7f957f795560b50d3427b5b90e91b", "size": 1775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Scraps/Downsampling.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/Scraps/Downsampling.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/Scraps/Downsampling.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": 104.4117647059, "max_line_length": 582, "alphanum_fraction": 0.7954929577, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6873496955851732}}
{"text": "\\section{Start with two points}\n$f(s)$ is the direct connecting line between the vectors  $\\vec a$ and $\\vec b$. The output of $f$ is a two-vector $(\\theta, \\varphi)^T$\n\\begin{equation}\\label{line}\n    f(s)=(1-s)\\cdot\\vec{a}+s\\cdot\\vec{b}\\qquad\\forall\\, s \\in [0,1]\n\\end{equation}\n\\begin{equation}\n    f'(s)=\\vec{b}-\\vec{a}\n\\end{equation}\nK: Spherical coordinates $\\rightarrow$ euclidean coordinates\\\\\ngiven:\n\\begin{equation}\\label{euklid}\n    K \\begin{pmatrix}\\theta \\\\ \\varphi\\end{pmatrix}=\n    \\begin{pmatrix}\n        \\sin\\theta\\cdot\\cos\\varphi \\\\\n        \\sin\\theta\\cdot\\sin\\varphi \\\\\n        \\cos\\theta\n    \\end{pmatrix}\n\\end{equation}\nso that:\n\\begin{equation}\n    K'=\n    \\begin{pmatrix}\n       \\cos\\theta\\cdot\\cos\\varphi && -\\sin\\theta\\cdot\\sin\\varphi \\\\\n       \\cos\\theta\\cdot\\sin\\varphi && \\sin\\theta\\cdot\\cos\\varphi \\\\\n       -\\sin\\theta && 0\n    \\end{pmatrix}\n\\end{equation}\n\\subsection{Numerical solution}\n\\begin{equation}\n    \\frac{dK}{d\\theta}\\dbinom{\\theta}{\\varphi}=\n    \\begin{pmatrix}\n        \\sin\\theta\\cdot\\cos\\varphi \\\\\n        \\sin\\theta\\cdot\\sin\\varphi \\\\\n        \\cos\\theta\n    \\end{pmatrix}\n\\end{equation}\nSee \\eqref{euklid}.\n\\begin{equation}\n    c_1=\\frac{1}{2}\n\\end{equation}\n\\begin{equation}\n    v_1=\\underbrace{K\n    \\begin{pmatrix}\n        \\begin{matrix}\n            \\theta_a \\\\\n            \\varphi_a\n        \\end{matrix}\n        +\n        \\begin{pmatrix}\n            \\theta_b-\\theta_a\\\\\n            \\varphi_b-\\varphi_a\n        \\end{pmatrix}\n        \\cdot c\n    \\end{pmatrix}\n    }_{\\alpha}\n    -\\vec{a}\n\\end{equation}\n\\begin{equation}\n    c_2=\\frac{c}{2}\n\\end{equation}\n\\begin{equation}\n    v_2=\\cdots\n\\end{equation}\nif\n\\begin{equation}\\label{epsilon}\n    \\frac{\\|v_2-v_1\\|}{\\|v_1\\|}<\\varepsilon\n\\end{equation}\nor\n\\begin{equation}\n    \\frac{\\langle v_2, v_1\\rangle}{\\|v_2\\|\\cdot\\|v_1\\|}<\\varepsilon\n\\end{equation}\n\\begin{lstlisting}[escapechar=@]\n    while(@equation: \\eqref{epsilon}@ > @$\\varepsilon$@) {\n        v1 = K(@… $\\cdot$ @c) - @$\\vec a$@\n        v2 = K(@… $\\cdot$ @c/2) - @$\\vec a$@\n        c = c/2;\n    }\n\\end{lstlisting}\n\\begin{equation}\n    \\cos(\\alpha)=\\frac{\\langle\\mathrm{iter}(a,b), \\mathrm{iter}(a,c)\\rangle}{\\|\\mathrm{iter}(a,b)\\|\\cdot \\|\\mathrm{iter}(a,b)\\|}\n\\end{equation}", "meta": {"hexsha": "43c7c5e26072138d50be8e6c345eea5fe30a50a3", "size": 2226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/numerical.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/numerical.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/numerical.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": 27.4814814815, "max_line_length": 136, "alphanum_fraction": 0.5925426774, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6873451015479767}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\n\\begin{document}\n\n\\subsection{Motivation}\n\nThe aim of lab is use a generalized multilinear regression model, termed the Higher-Order Partial Least Squares (HOPLS) \\cite{zhao2012higher}, to predict a tensor $\\underline{Y}$ from a tensor $\\underline{X}$ through projecting the data onto the latent space and performing regression on the corresponding latent variables. Specifically, We have problem of recognition human body position. On video with person we need to mark the position of the main points of the body (face, shoulders, hips, elbows, lap, ankle). The experiment is carried out on JHMDB (Joint-annotated Human Motion Data Base) \\cite{Jhuang:ICCV:2013}.\n\n\\subsection{Problem statement}\n\nGiven video with person and skeleton's coordinates for each frame of this video:\n\\[\n\\label{eq:example:1}\n\\begin{aligned}\n    \\mathfrak{D} = \\left\\{\\underline{X_i}, ~\\underline{Y_i}\\right\\}_{i=1}^{K},\n\\end{aligned}\n\\]\nwhere ~$\\underline{X_i} \\in \\mathbb{R}^{T \\times W\\times H\\times C}, ~\\underline{Y_i} \\in \\mathbb{R}^{T \\times D \\times I}$,\\\\ \n~$T$ - number of framres,  ~{W} - width, ~{H} - height, ~{C} - channel,\\\\ ~{I} - number of points in skeleton, ~{D} - picture dimension.\\\\\n\\\\\nIn our case, $T \\leqslant 40, ~W = 320, ~H = 240, ~C = 3, ~I = 15, ~D = 2.$\\\\\n\\\\\nThe n-mode product of a tensor\n$ X \\in \\mathbb{R}^{I_1\\times ... \\times I_n \\times ... \\times I_N}$\nand matrix $A \\in \\mathbb{R}^{J_n\\times I_n}$\nis denoted by $\\underline{Y} = \\underline{X} \\times_{i}A \\in \\mathbb{R}^{I_1\\times ... \\times I_{n-1} \\times J_n \\times I_{n+1} \\times ... \\times I_N}$\nand defined as:\n$$y_{i_1...i_{n-1}j_ni_{n+1}...i_N } = \\sum_{i_n} x_{i_1...i_n...i_N }a_{j_ni_n}$$\n$$\\underline{Y} = \\underline{G} \\times_{1} A^{(1)} \\times_{2} A^{(2)} \\times_{3} ...\\times_{N} A^{(N)} + \\underline{E} = [[G; A^{(1)}, A^{(2)}, ..., A^{(N)}]] + \\underline{E}$$\n\nWe assume $\\underline{X}$ is decomposed as a sum of $rank-(1, L_2, . . . , L_N )$ Tucker blocks, while $\\underline{Y}$ is decomposed as a sum of $rank-(1, K_2, . . . , K_M)$ Tucker blocks, which can be expressed as\n\n$$\\underline{X} = \\sum_{r=1}^{R}\\underline{G_r}\\times_{1} t_r \\times_{2} P^{(1)}_r \\times_{3} P^{(2)}_r \\times_{4} ...\\times_{N} P^{(N-1)}_r + \\underline{E}_r$$\n$$\\underline{Y} = \\sum_{r=1}^{R}\\underline{D_r}\\times_{1} t_r \\times_{2} Q^{(1)}_r \\times_{3} Q^{(2)}_r \\times_{4} ...\\times_{N} Q^{(N-1)}_r + \\underline{F}_r$$\nwhere R is the number of latent vectors, $t_r \\in \\mathbb{R}^{I_1}$ is the r-th latent vector $P_r^{n} \\in \\mathbb{R}^{I_{n+1} \\times L_{n+1}}$ and $Q_r^{m} \\in \\mathbb{R}^{J_{n+1} \\times K_{n+1}}$ are loading matrices on mode-n and mode-m respectively, and $\\underline{G_r} \\in \\mathbb{R}^{1 \\times L_{2}\\times ...\\times L_{N}}$ and $\\underline{D_r}\\in \\mathbb{R}^{1 \\times K_{2}\\times ...\\times K_{M}}$ are core tensors.\\\\\n\\\\\nHowever the Tucker decompositions are not unique due to the permutation, rotation, and scaling issues. To alleviate this problem, additional constraints should be imposed such that the core tensors $\\underline{G_r}$ and $\\underline{D_r}$ are all-orthogonal, a sequence of loading matrices are column-wise orthonormal, i.e., $P^{(n)T}_rP^{(n)}_r = I$ and $Q^{(n)T}_rQ^{(n)}_r = I$, the latent vector is of length one, i.e. $\\|t_r\\|_F=1$.\\\\\n\\\\\nThe main aim is to reduce Frobeniuses norm of residuals $\\underline{E_r}, \\underline{F_r}$. With a few propositions the following optimization problems arise\n\n\\[\n\\label{eq:example:2}\n\\begin{aligned}\n   \\min_{P^{(n)}, Q^{(m)}} \\| [[C; P^{(1)T}, P^{(2)T}, ..., P^{(N-1)T}, Q^{(1)T}, Q^{(2)T}, ..., Q^{(M-1)T}]]\\|_F^2,\\\\\n\\end{aligned}\n\\]\n$$s.t. ~P^{(n)T}_rP^{(n)}_r = I, ~Q^{(n)T}_rQ^{(n)}_r = I$$\nwhere $\\underline{C} = COV_{\\{1;1\\}}(\\underline{X}, \\underline{Y})$.\\\\\nNext, we can find latent vector ~$t$ from \n\\[\n\\label{eq:example:2}\n\\begin{aligned}\n    \\min_{t}\\| \\underline{X} - [[\\underline{G};t,P^{(1)},P^{(2)}, ...,P^{(N-1)}]]\\|_F^2\n\\end{aligned}\n\\]\nNow we found the first latent decomposition. Next step is repiting it for $\\underline{X} = \\underline{E_1}, ~\\underline{Y} = \\underline{F_1}$.\n\\subsection{Problem solution}\nFull algorithm is described in [1]. Now we can find solution:\n$${Y}^{(new)_{(1)}} \\approx T^{(new)}Q^{*T} = X^{(new)}_{(1)}WQ^{*T}$$\nwhere ~$W$ and ~$Q^*$ have R columns, represented by \n$$w_r = (P_r^{(N-1)}\\otimes ...\\otimes P_r^{(1)})\\underline{G_{r(1)}^+}$$\n$$q_r^* = \\underline{D_{r(1)}}(Q_r^{(M-1)}\\otimes ...\\otimes Q_r^{(1)})^T.$$\n\n\\subsection{Code analysis}\n\nThe code was taken from \\cite{zhao2012higher}.\n\n\\subsection{Experiment}\n\nThe experiment is carried out on JHMDB (Joint-annotated Human Motion Data Base) \\cite{Jhuang:ICCV:2013}.\nIn our case, $T \\leqslant 40, ~W = 320, ~H = 240, ~C = 3, ~I = 15, ~D = 2.$\\\\\nThe dataset has 928 videos from 21 class.\n\\\\\nDefine function of similarity of $\\underline{Y}^{(true)}$ and $\\underline{Y}^{(predict)}$ as\n$Q^2$:\n$$Q^2 = 1 - \\frac{\\|\\underline{Y}^{(true)} - \\underline{Y}^{(predict)}\\|_F^2}{\\|\\underline{Y}^{(true)}\\|_F^2}$$\n\\\\\nThe first experiment. We divided video into train and test part. Train has 32 frames, test has 8 frames. \n\\\\\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/fig1}\n\\caption{Experiment 1. Dependence $Q^2$ on number of latent vectors R.}\n\\end{figure}\n\\\\\nThe second experiment. In our dataset we have very similar videos, so we can lear our model on the first and test on the second video. It will show how robust this method.\n\\\\\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/fig2}\n\\caption{Experiment 2. Dependence $Q^2$ on number of latent vectors R.}\n\\end{figure}\n\n\\end{document}", "meta": {"hexsha": "d36ab0622d2242c5ae526f9d806b1c9feb109cd2", "size": 5632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Pyatkin2021Lab11/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/Pyatkin2021Lab11/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/Pyatkin2021Lab11/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": 59.914893617, "max_line_length": 620, "alphanum_fraction": 0.6519886364, "num_tokens": 2089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461006, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6872599997351029}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Like Powers}\n\n\\objective{Simply log expressions}\n\n\nWhether we use the Triangle of Power or not, it is very powerful to recognize\nthat logs are simply the inverse of exponents.  Without this insight, expressions\nlike $\\log_{10}{100} + \\log_{10}{1000}$ would be very intimidating.  But with this\ninsight, we can paraphrase as we go in our minds: ``There is some exponent\nto put on 10 and get 100.  Add to that, some exponent we put on 10 to get \n1000.  Adding exponents comes from multiplying bases, so this is the same as\n$\\log_{10}10000$.  That is asking the question, what exponent do we put on 10\nto get 10,000?  5!''\n\nWe think it is even easier in Triangles, but we might show you both styles for\nthe time being:\n\n$$\n\\tripow{10}{}{100} + \\tripow{10}{}{1000} = \\tripow{10}{}{10000} = 5\n$$\n\nIn other words, two logs added, is the same as one long of a multiplication.  This\nworks for the inverse operation of subtraction: two logs subtracted is the same\nas one log of a division.  Lastly, it also works for an exponent: the log of a number\nwith an exponent is the same as the exponent multiplied against the log of number.\n\nHere, Triangle notation really shines superior, because notation like $\\log_2{64^2}$\nis confusing.  Does it mean $\\log_2{64} \\cdot \\log_2{64}$ or $\\log_2{4096}$, which\nis the difference between 36 and 12?  How much clearer is\n\n$$\n\\tripow{2}{}{\\tripow{64}{2}{}} vs \\tripow{\\tripow{2}{}{64}}{2}{}\n$$\n\nEven more consequential is the two-fold possibilities for $2^{3^4}$.  Is that $(2^3)^4$\nor $2^{(3^4)}$?  That is the difference between 4096 and $2^81$, the latter of which\nis a 25 digit number!  But no one can make the same mistake with\n\n$$\n\\tripow{\\tripow{2}{3}{}}{4}{} vs \\tripow{2}{\\tripow{3}{4}{}}{}\n$$\n\n\n\\subsection{Names}\nThere are some logs which occur so commonly, that they base is not written.  Normally,\nthe word ``log'' with no base written means $\\log_{10}$.  Log base $e$ is very common,\nand has its own symbol $\\ln$.  This acronym comes from the French, \\textit{log\nnatural}, since $e$ is the natural number.\\footnote{In French, as in Spanish, adjective\nmost often follow their noun, not precede it.}  \n\nComputer scientists most often used $\\log_2$, which is called the binary log,\nwritten lb.  In fact\nin many disciplines, their flavor of log is the only one used, so it is assumed and the name\n``log'' is written, which can fool outsiders into assuming $\\log_{10}$.  For example,\nWolfram Alpha is fantastically powerful website for mathematics and other fields,\nand so they use ``log'' to mean ``ln''!  We will not be so tricky, and you may assume\nthe solution to $\\log{x}=2$ is 100.\n\n\\subsection{Change of Base}\nLogs are amazing.  But given the rarity of most bases, it become necessary to ask,\nIs there a way to convert them?  If we know how to re-write a log as an exponent,\nand take an exponent as a multiplier, then we can:\n\n\\begin{align*}\n\t\\log_b{a} & = c \\\\\n\tb^c &= a\\\\\n\t\\ln{b^c} &= \\ln{a}\\\\\n\tc \\cdot \\ln{b} &= \\ln{a} \\\\\n\tc = \\frac{\\ln{a}}{\\ln{b}} \n\\end{align*}\n\nNotice that it does not matter what base we chose in the third line.  $\\ln$ ($\\log_e$)\nworks just as well as $\\log_{\\pi}$.  This rearrangement to have an arbitrary\nbase is called the the Change of Base Formula.\n\n\n\\begin{derivation}{Change of Base Formula}\n$$\n\\tripow{b}{}{a} = \\frac{\\tripow{c}{}{a}}{\\tripow{c}{}{b}} \\quad \\text{a.k.a.} \\quad\n\\log_b{a} = \\frac{\\log_c{a}}{\\log_c{b}}\n$$\n\\end{derivation}\n\n\\begin{derivation}{Negative Logarithm}\n$$\n\\tripow{b}{}{1/y} = -\\tripow{b}{}{y}  = \\tripow{1/b}{}{y}\n\\quad \\text{a.k.a.} \\quad\n\\log_b{\\frac{1}{y}} = -\\log_b{y} = \\log_{\\frac{1}{b}}{y}\n$$\n\\end{derivation}\n\n\n\nStudents often confusing ``the sum of logs'' with ``the log of a sum''.  What can we say\nabout $\\log_b{(a+c)}$?  On the face of it, not much.  But through some creative manipulation,\none identity can be made, which is used in Probability Theory:\n\n\n\\begin{align*}\n\t\\log_b{(a+c)} \t&= + \\log_b{a} - \\log_b{a} + \\log_b{(a+c)}\\\\\n\t\t\t\t&= \\log_b{a} + \\log_b{(a+c)} - \\log_b{a}\\\\\n\t\t\t\t&= \\log_b{a} + \\log_b{\\frac{a+c}{a}} \\\\\n\t\t\t\t&= \\log_b{a} + \\log_b{1 + \\frac{c}{a}}\\\\\n\t\\tripow{b}{}{a+c} &= \\tripow{b}{}{a} + \\tripow{b}{}{\\left(1 + \\frac{c}{a}\\right)}\n\\end{align*}\n\nLastly, we have already made with the Triangle of Power:\n\n\\begin{derivation}{P-Plus Logs}\n$$\n\\tripow{m}{}{x} \\pplus \\tripow{n}{}{x} = \\tripow{m\\cdot{}n}{}{x}\n\\quad \\text{a.k.a.} \\quad\n\\log_m{x} \\oplus \\log_n{x} = \\log_{mn}{x}\n$$\n\n$$\n\\tripow{m}{}{x} \\pminus \\tripow{n}{}{x} = \\tripow{m\\div{}n}{}{x}\n\\quad \\text{a.k.a.} \\quad\n\\log_m{x} \\pminus \\log_n{x} = \\log_{\\frac{m}{n}}{x}\n$$\n\n$$\n\\tripow{\\tripow{m}{n}{}}{}{x} = \\frac{\\tripow{m}{}{x}}{n}\n\\quad \\text{a.k.a.} \\quad\n\\log_{m^n}{x} = \\frac{1}{n}\\log_m{x}\n$$\n\\end{derivation}\n", "meta": {"hexsha": "b116501f55e2651bc00ed2a32c3070fcb2d07e78", "size": 4742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch07/0703.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch07/0703.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch07/0703.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": 36.4769230769, "max_line_length": 93, "alphanum_fraction": 0.6653310839, "num_tokens": 1643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.6872599849546377}}
{"text": "\\section{Fundamental Theorem of Calculus}\r\n\\subsection{Integration}\r\nAssume below that all functions under consideration are nice enough to let the integral exist.\\\\\r\nConsider the following sum\r\n$$\\sum_{n=0}^{N-1}f(x_n)\\Delta x$$\r\nwhere $\\Delta x=(b-a)/N, x_n=a+n\\Delta x$.\\\\\r\nThe question is, how close is the finite sum above to the area under the curve of $f$, when $N$ is large?\r\nHow big is the difference between the difference between the area and the discrete area in the sum?\r\n\\begin{theorem}[Mean-vaue Theorem on Definite Integrals]\r\n    For a continuous function $f(x)$,\r\n    $$\\int_{x_n}^{x_n+1}f(x)\\,\\mathrm dx=f(x_c)(x_{n+1}-x_n)$$\r\n    for some $x_c\\in(x_n,x_{n+1})$.\r\n\\end{theorem}\r\nExpand $f(x)$ about $x\\to x_n$ and evaluate it at $x_c$.\r\nAs $\\Delta x\\to 0$,\r\n$$f(x_c)=f(x_n)+O(x_c-x_n)=f(x_n)+O(x_{n+1}-x_n)$$\r\nas $|x_c-x_n|<|x_{n+1}-x_n|$.\r\nHence by the mean-value theorem:\r\n\\begin{align*}\r\n    \\int_{x_n}^{x_n+1}f(x)\\,\\mathrm dx\r\n    &=f(x_n)(x_{n+1}-x_n)+O(x_{n+1}-x_n)(x_{n+1}-x_n)\\\\\r\n    &=\\Delta xf(x_n)+O(\\Delta x^2)\r\n\\end{align*}\r\nSo $\\epsilon=O(\\Delta x^2)$.\r\nIt follows that\r\n$$\\int_a^bf(x)\\,\\mathrm dx=\\lim_{N\\to\\infty}\\sum_{n=0}^{N-1}f(x_n)\\Delta x+\\epsilon_n$$\r\nBy our bounds above, the error terms $\\sum_n\\epsilon_n=O(N\\Delta x^2)=O((b-a)^2/N)$ vanish as $N\\to\\infty$.\r\nTherefore,\r\n$$\\int_a^bf(x)\\,\\mathrm dx=\\lim_{N\\to\\infty}\\sum_{n=0}^{N-1}f(x_n)\\Delta x$$\r\n\\begin{theorem}[Fundamental Theorem of Calculus]\r\n    Let\r\n    $$F(x)=\\int_a^xf(t)\\,\\mathrm dt$$\r\n    then $\\mathrm dF/\\mathrm dx=f(x)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We try to evaluate the derivative of $F$,\r\n    \\begin{align*}\r\n        \\frac{\\mathrm dF}{\\mathrm dx}\r\n        &=\\lim_{h\\to0}\\frac{1}{h}\\int_{x}^{x+h}f(t)\\,\\mathrm dt\\\\\r\n        &=\\lim_{h\\to0}\\frac{1}{h}(f(x)h+O(h^2))\\\\\r\n        &=f(x)\r\n    \\end{align*}\r\n    So $\\mathrm dF/\\mathrm dx=f(x)$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $$\\frac{\\mathrm d}{\\mathrm dx}\\int_x^bf(t)\\,\\mathrm dt=-f(x)$$\r\n\\end{corollary}\r\n\\begin{corollary}\r\n    $$\\int_a^{g(x)}f(t)\\,\\mathrm dt=f(g(x))g^\\prime(x)$$\r\n\\end{corollary}\r\n\\begin{corollary}\r\n    Let\r\n    $$F(x)=\\int f(x)\\,\\mathrm dx$$\r\n    be the indefinite integral (or anti-derivative) of $f$, then\r\n    $$\\int_a^bf(t)\\,\\mathrm dt=F(b)-F(a)$$\r\n\\end{corollary}\r\n\\subsection{Some Integration Techniques}\r\nThe first one is integration by substitution.\r\n\\begin{example}\r\n    $$\\int\\frac{1-2x}{\\sqrt{x-x^2}}\\,\\mathrm dx=\\int\\frac{\\mathrm du}{\\sqrt u}=2\\sqrt{u}+C$$\r\n\\end{example}\r\nTrigonometric substitution\r\n\\begin{example}\r\n    If we see something like $\\sqrt{a^2-x^2}$, then we can substitute $x=a\\sin\\theta$.\\\\\r\n    If we see something like $x^2+a^2$, we can use $x=a\\tan\\theta$.\\\\\r\n    If we see $\\sqrt{x^2-a^2}$, we can use $x=a\\cosh\\theta$ or $x=a\\sec\\theta$.\\\\\r\n    If we see $\\sqrt{x^2+a^2}$, we can use $x=a\\sinh\\theta$ or $x=a\\tan\\theta$.\\\\\r\n    If we see $a^2-x^2$, we can use $x=a\\tanh\\theta$\r\n\\end{example}\r\nAnd, of course, we have integration by part:\r\n$$\\int uv^\\prime=uv-\\int u^\\prime v$$\r\nfrom product rule.", "meta": {"hexsha": "46e6104fc5a8643a7aa902dbcce9e8d05d1d064b", "size": 3017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/ftc.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": "2/ftc.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": "2/ftc.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": 41.9027777778, "max_line_length": 108, "alphanum_fraction": 0.618826649, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.6872599849333685}}
{"text": "\\section{The \\binarysearch algorithm}\n\\Label{sec:binarysearch}\n\\Label{sec:binarysearchii}\n\n\nThe \\binarysearch algorithm is one of the four binary search\nalgorithms of the \\cxx Standard Library \\cite[\\S 28.7.3.4]{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  bool binary_search(const value_type* a, size_type n, value_type  v);\n\\end{lstlisting}\n\nAgain, \\binarysearch requires that its input array is in increasing order.\nIt will return \\inl{true} if there exists an index~\\inl{i} \nin~\\inl{a} such that \\inl{a[i] == v} holds.\\footnote{%\n   To be more precise: The \\cxx Standard Library requires that \n   \\inl{(a[i] <= v)  && (v <= a[i])} holds.\n   For our definition of \\valuetype (see \\S\\ref{sec:frequentPattern}) this\n   means that \\inl{v} equals \\inl{a[i]}.\n}\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.60\\textwidth]{Figures/binary_search.pdf}\n\\caption{\\Label{fig:binarysearch}Some examples for \\binarysearch}\n\\end{figure}\n\n\\FloatBarrier\n\nIn Figure~\\ref{fig:binarysearch} we do not need to use arrows to visualize the\neffects of \\binarysearch.\nThe colors orange and grey of the sought-after values indicate whether the algorithm\nreturns true or false, respectively.\n\n\\subsection{Formal specification of \\binarysearch and \\binarysearchii}\n\nThe \\acsl specification of \\specref{binarysearch} is shown in the following listing.\n\n\\input{Listings/binary_search.h.tex}\n\nNote that instead of the somewhat lengthy existential quantification\nof \\specref{binarysearch} we can use our previously introduced predicate\n\\logicref{SomeEqual} in order to achieve the following more concise\nformal specification \\specref{binarysearchii}.\n\n\n\\input{Listings/binary_search2.h.tex}\n\nIt is interesting to compare the specification of \\specref{binarysearch}\nwith that of \\specref{findii}.\nBoth algorithms allow to determine whether a value is contained in an array.\nThe fact that the \\cxx Standard Library requires that \\find has\n\\emph{linear} complexity whereas \\binarysearch must have a\n\\emph{logarithmic} complexity can currently not be expressed with \\acsl.\n\n\n\\subsection{Implementation of \\binarysearch}\n\nOur implementation \\implref{binarysearchii} first calls \\specref{lowerbound}.\nRemember that if the latter returns an index \\inl{0 <= i < n},\nthen we can be sure that \\inl{v <= a[i]} holds.\n\n\\input{Listings/binary_search2.c.tex}\n\n", "meta": {"hexsha": "33dd6dd28c256e22e5867bf10e8c13b9b69cb1de", "size": 2467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/binary-search/binary_search.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/binary_search.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/binary_search.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": 35.7536231884, "max_line_length": 84, "alphanum_fraction": 0.7738143494, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.6872599694063275}}
{"text": "% based on example 7 in pythontex_gallery\n% https://github.com/gpoore/pythontex/\n\n\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{A table of derivatives and anti-derivatives}\n\nThis example is based upon a nice example in the Pythontex gallery, see\n\\ \\url{https://github.com/gpoore/pythontex/}.\nIt uses a tagged block to capture the {\\tt\\small Sympy} output for later use\nin the body of the LaTeX table.\n\n\\lstset{numbers=left}\n\n\\begin{minipage}[t]{0.72\\textwidth}\n\\begin{python}\n   from sympy import *\n\n   var('x')\n\n   # Create a list of functions to include in the table\n   funcs = [['sin(x)',r'\\\\'],       ['cos(x)',r'\\\\'],       ['tan(x)',r'\\\\'],\n            ['asin(x)',r'\\\\[5pt]'], ['acos(x)',r'\\\\[5pt]'], ['atan(x)',r'\\\\[5pt]'],\n            ['sinh(x)',r'\\\\'],      ['cosh(x)',r'\\\\'],      ['tanh(x)',r' ']]\n\n   # pyBeg (CalculusTable)\n   for func, eol in funcs:\n       myddx = 'Derivative(' + func + ', x)'\n       myint = 'Integral(' + func + ', x)'\n       print(latex(eval(myddx)) + '&=' + latex(eval(myddx + '.doit()')) + r'\\quad & \\quad')\n       print(latex(eval(myint)) + '&=' + latex(eval(myint + '.doit()')) + eol)\n   # pyEnd (CalculusTable)\n\\end{python}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.28\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      \\py {CalculusTable}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\clearpage\n\n\\begin{align*}\n   \\py {CalculusTable}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "6bf01d1052a2bdd6429164cd6fd84a6870db5a14", "size": 1441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-02.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "python/examples/example-02.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "python/examples/example-02.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 26.6851851852, "max_line_length": 91, "alphanum_fraction": 0.5968077724, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.6872599651193758}}
{"text": "\\section{Logistic hypothesis using logistic regression}\n\n\\subsection{Implementation}\nFor logistic regression the hypothesis function is a sigmoid function given by equation \\ref{eq:logistic_regression}.\nAs before a learning rate($\\alpha$) = 0.01 was used and gradient descent approach was used for parameter optimization.\n\n\\begin{equation}\n\\label{eq:logistic_regression}\nh_{\\theta}(X) = \\frac{1}{e^{-\\theta_0 - \\theta_1 * X}}\n\\end{equation}\n\n\\subsection{Observation}\nThe final values of $\\theta$s for a run are as follows:\n\n% Theta 0 final value\n\\begin{equation}\n\\theta_0 = -3.5327129208000407\n\\end{equation}\n\n% Theta 1 final value\n\\begin{equation}\n\\theta_1 = 1.3214831636264568\n\\end{equation}\n\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{logistic_regression_curve_0_01.png}\n  \\caption{Logistic regression curve}\n  \\label{fig:logistic_regression}\n\\end{figure}\n\nThe logistic curve corresponding to above $\\theta$s is shown in figure \\ref{fig:logistic_regression}\n\n\\subsection{Source Code}\n\\lstinputlisting[language=python]{task_2.py}\n", "meta": {"hexsha": "1860566f47c74c83c8c1612ccb64c2e2fe18c4b8", "size": 1084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/logistic_regression.tex", "max_stars_repo_name": "diwasblack/machine_learning", "max_stars_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/logistic_regression.tex", "max_issues_repo_name": "diwasblack/machine_learning", "max_issues_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/logistic_regression.tex", "max_forks_repo_name": "diwasblack/machine_learning", "max_forks_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9714285714, "max_line_length": 118, "alphanum_fraction": 0.7804428044, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.687213929717719}}
{"text": "\\chapter{A Template chapter}\n\\label{chapter:example_chapter}\n\nThis chapter contains some examples of how to use equations, tables and figures in the template. The last section shows how it all comes together in the final document.\n\n\n\\section{Equations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Single line equations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\vspace{0.4cm}\n\n\\begin{equation}\n\tl = \\int ds =  \\int_t \\sqrt{\\left(\\frac{dx}{dt} \\right)^2 + \\left(\\frac{dy}{dt} \\right)^2 + \\left(\\frac{dz}{dt} \\right)^2} dt \\; .\n\t\\label{eq:curve_length_3D_cartesian}\n\\end{equation}\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\tds^2 = -\\left( 1 - \\frac{2 M}{ r}  \\right)  dt^2 + \\left( 1 - \\frac{2 M}{ r}  \\right)^{-1} dr^2 + r^2 d \\theta^2 + r^2 \\sin^2 \\theta d \\phi^2\n\t\\label{eq:schwarzschild_solution}\n\\end{equation}\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\rho = \\rho_0 + \\epsilon \\rho_1 \\qquad p = p_0 + \\epsilon p_1 \\qquad \\psi = \\psi_0 + \\epsilon \\psi_1 \\; .\n\t\\label{eq:linear_perturbations}\n\\end{equation}\n\n\\vspace{0.4cm}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Single line equations with text}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\lambda_B \\sim \\SI{0.5}{kpc} \\left( \\frac{ 10^{-22} \\; \\text{eV} }{m} \\right) \\left( \\frac{ 250 \\; \\text{km/s} }{v} \\right) \\;.\n\\end{equation}\n\n\\vspace{0.4cm}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Single line equations with box}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\t\\boxed{\n\t\t\t\tT_{\\text{Scalar}}^{\\mu \\nu} = \n\t\t\t\t(g^{\\mu \\alpha}g^{\\nu \\beta} + g^{\\mu \\beta}g^{\\nu \\alpha} - g^{\\mu \\nu}g^{\\alpha \\beta}) \\partial_\\alpha \\Psi \\partial_\\beta \\Psi - g^{\\mu \\nu} \\mu^2 \\Psi^2 \n\t\t}\n\t\\label{eq:superradiant_condition}\n\\end{equation}\n\n\\begin{equation}\n\t\\boxed{\n\t\t\\boxed{\n\t\t\t\\omega < m \\Omega_H\n\t\t}\n\t}\n\t\\label{eq:superradiant_condition_2}\n\\end{equation}\n\n\n\\vspace{0.4cm}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Multiline equations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\ta \t\t&= J/M \\\\\n\t\t\\rho \t&= r^2 + a^2 \\cos^2 \\theta  \\\\\n\t\t\\Delta\t&= r^2 - 2 M r + a^2 \\; .\n\t\\end{aligned}\n\\end{equation}\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\left[  \\frac{(r^2 + a^2)}{\\Delta} - a^2 \\sin^2 \\theta\\right]\\frac{\\partial^2 \\Psi}{\\partial t^2} + \\frac{4M a r}{\\Delta} &\\frac{\\partial^2 \\Psi}{\\partial t \\partial \\varphi} + \\left[ \\frac{a^2}{\\Delta} - \\frac{1}{\\sin^2 \\theta}\\right] \\frac{\\partial^2 \\Psi}{\\partial \\varphi^2} + \\\\[10pt] & - \\frac{\\partial}{\\partial r} \\left( \\Delta \\frac{\\partial  \\Psi}{\\partial r}\\right) - \\frac{1}{\\sin \\theta} \\frac{\\partial}{\\partial t}\\left( \\sin \\theta \\frac{\\partial \\Psi}{\\partial \\theta}\\right) = 0 \\; .\n\t\\end{aligned}\n\\end{equation}\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\sum_{m} \\mathcal{A}_{+}^{m}&\\left[ \\phi_m^+ - i \\tilde{Z}_0 \\left(\\phi_m^+\\right)'   \\right] + \\mathcal{A}_{-}^{m}\\left[ \\phi_m^- - i \\tilde{Z}_0 \\left(\\phi_m^-\\right)'   \\right] = \\\\\n\t\t=&\\sum_{m} \\epsilon \\left(\\frac{i  \\tilde{Z}}{2}\\right) \\left[ \\mathcal{A}_{+}^{m} \\left(\\phi_m^+\\right)' + \\mathcal{A}_{+}^{m+2} \\left(\\phi_{m+2}^+\\right)' + \\mathcal{A}_{+}^{m-2} \\left(\\phi_{m-2}^+\\right)'  \\right] + \\\\\n\t\t& \\qquad +\\sum_{m} \\epsilon \\left(\\frac{i  \\tilde{Z}}{2}\\right) \\left[ \\mathcal{A}_{-}^{m} \\left(\\phi_m^-\\right)' + \\mathcal{A}_{-}^{m+2} \\left(\\phi_{m+2}^-\\right)' + \\mathcal{A}_{-}^{m-2} \\left(\\phi_{m-2}^-\\right)'  \\right] \\; ,\n\t\\end{aligned}\n\t\\label{eq:infinite_set_of_equations}\n\\end{equation}\n%\n\n\\vspace{0.4cm}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Matrix Equations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\arraycolsep = 5pt \\def\\arraystretch{1.1}\n\t\\left[\n\t\\begin{array}{ccccccc}\n\t\t\\ddots    &  \\beta_+^4  &               &               &               &               &             \\\\\n\t\t\\beta_+^6 & \\Lambda_+^4 &  \\beta_+^2  &               &               &               &             \\\\\n\t\t&  \\beta_+^4  & \\Lambda_+^2 &  \\beta_+^0  &               &               &             \\\\\n\t\t&               &  \\beta_+^2  & \\Lambda_+^0 &  \\beta_+^2  &               &             \\\\\n\t\t&               &               &  \\beta_+^0  & \\Lambda_+^2 &  \\beta_+^4  &             \\\\\n\t\t&               &               &               &  \\beta_+^2  & \\Lambda_+^4 & \\beta_+^6 \\\\\n\t\t&               &               &               &               &  \\beta_+^4  &   \\ddots\n\t\\end{array} \n\t\\right]\n\t\\left[\n\t\\begin{array}{c}\n\t\t\\vdots \\\\\n\t\t\\mathcal{A}_{+}^{-4} \\\\\n\t\t\\mathcal{A}_{+}^{-2} \\\\\n\t\t\\mathcal{A}_{+}^{0} \\\\\n\t\t\\mathcal{A}_{+}^{2} \\\\\n\t\t\\mathcal{A}_{+}^{4} \\\\\n\t\t\\vdots\n\t\\end{array} \n\t\\right]\n\t=\n\t\\left[\n\t\\begin{array}{c}\n\t\t\\vdots \\\\\n\t\t0 \\\\\n\t\t-\\beta_-^0 \\\\\n\t\t-\\Lambda_-^0 \\\\\n\t\t-\\beta_-^0 \\\\\n\t\t0 \\\\\n\t\t\\vdots\n\t\\end{array} \n\t\\right]\n\t\\label{eq:matrix_eigenvalue_equation}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Conditional equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\vspace{0.4cm}\n\n\\begin{equation}\n\t\\alpha(t , \\mathbf{r}) = \n\t\\begin{cases}\n\t\t\\alpha_0 \\qquad \\text{if} \\qquad (\\mathbf{r} -\\mathbf{R_{orbit})}^2 < R_a^2 \\\\\n\t\t\\alpha_0 \\qquad \\text{if} \\qquad (\\mathbf{r} +\\mathbf{ R_{orbit})}^2 < R_a^2 \\\\\n\t\t0   \\; \\;\\qquad \\text{otherwise}\n\t\t\\label{eq:alpha_binary_bh}\n\t\\end{cases} \\; ,\n\\end{equation}\n\n\\vspace{0.4cm}\n\n\\section{Tables}\n\n\\begin{table}[h]\n\t\\caption{Example table number 1}\n\t\\label{table:an_example_table}\n\t\\centering\n\t\\begin{tabular}{clllll}\n\t\t\\toprule\n\t\t\\midrule[0.4pt]\n\t\tID&$A$  & $r_0$  &  $\\sigma$ &  $\\omega$  &  $m$  \\\\\n\t\t\\midrule\n\t\tS1 & 3.5 & 40.0 & 4.0 & 1.28 & 0 \\\\\n\t\tS2 & 3.5 & 15.0 & 2.0 & 0.1 & 2 \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\n\\begin{table}[h!]\n\t\\centering\n\t\\caption{Example table number 2}\n\t\\begin{tabular}{SSSSSSS}\n\t\t\\toprule\n\t\t\\midrule[0.4pt]\n\t\t{$k$} & {$J_0(x)$} & {$J_1(x)$} & {$J_2(x)$} & {$J_3(x)$} & {$J_4(x)$} & {$J_5(x)$} \\\\ \n\t\t\\midrule\n\t\t1     & 2.4048     & 3.8317     & 5.1356     & 6.3802     & 7.5883     & 8.7715     \\\\\n\t\t2     & 5.5201     & 7.0156     & 8.4172     & 9.7610     & 11.0647    & 12.3386    \\\\\n\t\t3     & 8.6537     & 10.1735    & 11.6198    & 13.0152    & 14.3725    & 15.7002    \\\\\n\t\t4     & 11.7915    & 13.3237    & 14.7960    & 16.2235    & 17.6160    & 18.9801     \\\\ \n\t\t\\midrule[0.4pt]\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\label{table:bessel_zeros}\n\\end{table}\n\n\\section{Figures}\n\nGenerating figures in a consistent manner is usually challenge. Especially when the work to be presented is made by a team of several elements. The graphics presented in this template are generated with the \\href{\"aa\"}{\\texttt{Jlop}} template in python. \n\n\\subsection*{Single Figure}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics{figures/chapter_B/jlop_sc_sqroot.png}\n\t\\caption{An example figure}\n\t\\label{fig1:single_image}\n\\end{figure}\n\n\\pagebreak\n\\subsection*{Side By Side}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics{figures/chapter_B/jlop_dc_golden.png}\n\t\\caption{An example figure with two elements. The two plots where generated as a single image with the correct document width. If this is not possible, follow the procedure done to generate figure \\ref{fig1:side_by_side_image}.}\n\t\\label{fig1:side_by_side_single}\n\\end{figure}\n\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=.48\\linewidth]{example-image-a}\n\t\\includegraphics[width=.48\\linewidth]{example-image-b}\n\t\\caption{An example figure with two elements. It is usually better to make a single image with both plots as to input a single file. When that is not possible, one should resort to this method}\n\t\\label{fig1:side_by_side_image}\n\\end{figure}\n\n\\vfill\n\\pagebreak\n\\section{Putting it al together}\n\n\\lipsum[5]\n\n\\begin{equation}\n\t\\lambda_B \\sim \\SI{0.5}{kpc} \\left( \\frac{ 10^{-22} \\; \\text{eV} }{m} \\right) \\left( \\frac{ 250 \\; \\text{km/s} }{v} \\right) \\;.\n\\end{equation}\n\n\\lipsum[10]\n\n\\begin{table}[h]\n\t\\caption{Example table number 1}\n\t\\label{table:example_table_2}\n\t\\centering\n\t\\begin{tabular}{clllll}\n\t\t\\toprule\n\t\t\\midrule[0.4pt]\n\t\tID&$A$  & $r_0$  &  $\\sigma$ &  $\\omega$  &  $m$  \\\\\n\t\t\\midrule\n\t\tS1 & 3.5 & 40.0 & 4.0 & 1.28 & 0 \\\\\n\t\tS2 & 3.5 & 15.0 & 2.0 & 0.1 & 2 \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\\lipsum[2]\n\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[width=.48\\linewidth]{example-image-a}\n\t\\includegraphics[width=.48\\linewidth]{example-image-b}\n\t\\caption{An example figure with two elements. It is usually better to make a single image with both plots as to input a single file. When that is not possible, one should resort to this method}\n\t\\label{fig1:side_by_side_image_2}\n\\end{figure}\n\n\\lipsum", "meta": {"hexsha": "c1c38f373234f6a8056f8a97ae212474ee8a475a", "size": 8823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis_template/inputs/04_Chapters/chapter_B.tex", "max_stars_repo_name": "diogoribeiro98/IST_Master_Thesis_Template_V2", "max_stars_repo_head_hexsha": "11c58938d7906074ecdf782d4b31020cf145826a", "max_stars_repo_licenses": ["MIT"], "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_template/inputs/04_Chapters/chapter_B.tex", "max_issues_repo_name": "diogoribeiro98/IST_Master_Thesis_Template_V2", "max_issues_repo_head_hexsha": "11c58938d7906074ecdf782d4b31020cf145826a", "max_issues_repo_licenses": ["MIT"], "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_template/inputs/04_Chapters/chapter_B.tex", "max_forks_repo_name": "diogoribeiro98/IST_Master_Thesis_Template_V2", "max_forks_repo_head_hexsha": "11c58938d7906074ecdf782d4b31020cf145826a", "max_forks_repo_licenses": ["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.8519855596, "max_line_length": 502, "alphanum_fraction": 0.543239261, "num_tokens": 3303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6871396877712773}}
{"text": "% based on example 7 in pythontex_gallery\n% https://github.com/gpoore/pythontex/\n\n\\documentclass[12pt]{mpllatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{A table of derivatives and anti-derivatives}\n\nThis example is based upon a nice example in the Pythontex gallery, see\n\\ \\url{https://github.com/gpoore/pythontex/}.\nIt uses a tagged block to capture the Maple output for later use\nin the body of the LaTeX table.\n\n\\lstset{numbers=left}\n\n\\begin{minipage}[t]{0.75\\textwidth}\n\\begin{maple}\n   # Create a list of functions to include in the table\n   funcs := [[sin(x),\"\\\\\\\\\"],         [cos(x),\"\\\\\\\\\"],         [tan(x),\"\\\\\\\\\"],\n             [arcsin(x),\"\\\\\\\\[5pt]\"], [arccos(x),\"\\\\\\\\[5pt]\"], [arctan(x),\"\\\\\\\\[5pt]\"],\n             [sinh(x),\"\\\\\\\\\"],        [cosh(x),\"\\\\\\\\\"],        [tanh(x),\" \"]]:\n\n   # mplBeg (CalculusTable)\n   for foo in funcs do\n       func := foo[1]:\n       eol  := foo[2]:\n       myddx := ''diff''(func,x):\n       myint := ''int''(func,x):\n       Print(cat(Latex(myddx),\"&=\",Latex(diff(func,x)),\"\\\\quad & \\\\quad\")):\n       Print(cat(Latex(myint),\"&=\",Latex(int(func,x)),eol)):\n   end do:\n   # mplEnd (CalculusTable)\n\\end{maple}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.25\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      \\mpl {CalculusTable}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\clearpage\n\n\\begin{align*}\n   \\mpl {CalculusTable}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "96f52d704bdc74e34e1cf647392f1c7dc13f7b86", "size": 1400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maple/examples/example-02.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "maple/examples/example-02.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maple/examples/example-02.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 26.4150943396, "max_line_length": 87, "alphanum_fraction": 0.5921428571, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.687139553195906}}
{"text": "\\subsubsection{The Fundamental Theorem of Linear Algebra}\n\nIn order to proof the pending \\cref{thm:SVD2} from previous\nsection, we need to present the four subspaces that an arbitrary\nmatrix $A$ introduces. But before that, a few important\ndefinitions and remarks: \\\\\n\n\\begin{itemize}\n    \\item Matrix application $A\\vec{x}$ can be seen as a linear\n      combination of the columns of $A$:\n      \\[\n      A\\vec{x} = \n      \\begin{bmatrix}\n        \\vec{A_1} \\mid \\vec{A_2} \\mid \\cdots \\mid \\vec{A_n}\n      \\end{bmatrix} \\vec{x} = \n      \\sum_{i=1}^n x_i \\vec{A_i}\n      \\]\n  \\item Subspace: A subset of a vector space, which is itself a\n    vector space (that is, contains the \\vec{0} and is closed under\n    the addition and multiplication by an scalar). \n  \\item Dimension: Is the size of any basis of a vector space (an\n    important result in Linear Algebra, shows that all the basis must\n    have the same number of elements; hence, the dimension is a property of the\n    space itself). The dimension of a vector space (or subspace) $V$\n    is denoted as $\\dim{V}$.\n  \\item Given vector space $V$ and a subspace $W \\subset V$ , the\n    subspace $\\ortc{W} \\subset V$ consists of all\n    the vectors of $V$ which are orthogonal to all the vectors of\n    $W$. $\\ortc{W}$ is called the orthogonal complement of $W$.\n\\end{itemize}\n\\hfill\n\nNow is right time to talk about the subspaces: we already established\nthat each matrix of $m \\times n$, can be seen as the operational\nrepresentation of a linear transformation with signature $\\R{n}\n\\fromto \\R{m}$. The action of $A$, in transforming the vectors from\none space to the other, has an interesting effect on each side: both\ndomain (\\R{n}) and codomain (\\R{m}), are broken in two orthogonal\npieces. Those pieces actually, happen to be subspaces and their basis\nare contained on the matrices $V$ and $U$ of the SVD factorization! But\nlet us explain piece by piece; a good start, is the column space. \\\\\n\nThe column space of a matrix $A$, is pretty much the concept of the\nimage of a function; that is, the set of all vectors in \n$A\\vec{x} \\in \\R{m} \\suchthat \\vec{x} \\in \\R{n}$, and it is denoted as\n$\\C{A}$. Another way of looking at it (per one of the remarks above),\nis that each application \nof the linear transformation $A$ (that is, each $A\\vec{x}$), converts\nthe input vector \\vec{x} into a linear combination of the columns of\nA; therefore, $\\C{A}$ is the spanning set generated by the\ncolumns of $A$. It can be proved that this subset is actually a\nsubspace of \\R{m}. \\\\\n\nThe next subspace is also clearly understood, is the so called\nnull space of $A$. It consists of all the solutions to the homogeneous\nsystem $A\\vec{x} = \\vec{0}$ and is denoted as $\\N{A}$. In the\nlanguage of transformations, is the set \nof all vectors $\\vec{x} \\in \\R{n}$ that function $A$ compresses into the zero\nvector of \\R{m}. This subset at least contains the vector \\vec{0}, but\nin general it will contain much more vectors (only the non-singular\nmatrices have $\\N{A} = \\{\\vec{0}\\}$). Again, it can be proved\nthat this subset is also a subspace (though this one belongs to \\R{n}). \\\\\n\nThe next two subspaces, are not that intuitive to introduce; unless we\nthink now in terms of the transformation represented by matrix\n\\trans{A}. This matrix represents a linear transformation that goes\ninto the opposite direction of $A$, that is, from \\R{m} to \\R{n}. If\nwe think in the image of this function $\\{\\trans{A}\\vec{y} \\in \\R{n} \\mid\ny \\in \\R{m} \\}$, an interesting realization comes to the picture: what if we\napply the same idea as before, that $\\trans{A}\\vec{y}$ is a linear\ncombination of the columns of $\\trans{A}$: \\\\\n\n\\[\n\\trans{A}\\vec{y} = \n\\begin{bmatrix}\n  \\vec{(\\trans{A})_1} \\mid \\vec{(\\trans{A})_2} \\mid \\cdots \\mid \\vec{(\\trans{A})_m}\n\\end{bmatrix} \\vec{y} = \n\\sum_{i=1}^m y_i \\vec{(\\trans{A})_i} = \n\\sum_{i=1}^m y_i (\\text{row $i$ of $A$})\n\\]\n\\hfill\n\nIn order words, columns of \\trans{A} are the rows of $A$, therefore;\nthe column space of \\trans{A} is precisely the row space of original\nmatrix $A$; this is denoted as \\C{\\trans{A}} and it can also\nbe proved that it is a subspace of \\R{m}. The last and fourth\nsubspace, comes from considering the null space of \\trans{A}; that is,\nthose vectors \\vec{y} in \\R{m} which are compressed into the zero\nvector of \\R{n}. Is not hard to prove that this is a subspace as\nwell; it is called the left null space of $A$, and denoted as\n\\N{\\trans{A}}. \\\\\n\nSummarizing, the four subspaces associated to any\nmatrix $A$ of $m \\times n$ are the following (intuitive proofs that\nall of them are indeed subspaces can be found in \\cite{strang88}): \\\\\n\n\\begin{itemize}\n\\item \\C{\\trans{A}}: row space, lives in \\R{n}\n\\item \\N{A}: null space, lives in \\R{n}\n\\item \\C{A}: column space, lives in \\R{m}\n\\item \\N{\\trans{A}}: left null space, lives in \\R{m}\n\\end{itemize}\n\\hfill\n\nThe first thing we note is the intentional grouping of these subspaces;\nwhile \\C{\\trans{A}} and \\N{A} belong to \\R{n} [the domain of $A$],\n\\C{A} and \\N{\\trans{A}} belong to \\R{m} [the codomain of $A$]. These\npairs of subspaces have more in common than merely sharing same\nhosting space, they are orthogonal with each other! This is the time\nto meet what Strang calls the Fundamental Theorem of Linear Algebra\n(part II\\footnote{Strang presents the theorem parts in the opposite order\n  in \\cite{strang88};\n  but we preferred to keep our own order, aiming to match better the\n  flow of deductions presented in this work.}): \\\\\n\n\\begin{theorem}[Fundamental Theorem of Linear Algebra (part II)]\n\\label{thm:Fund1}\nLet $A$ be a real matrix of $n \\times m$, then \n\n\\[\n\\C{\\trans{A}} = \\ortc{\\N{A}} \\ds{\\land} \\C{A} = \\ortc{\\N{\\trans{A}}}\n\\]\n\\end{theorem}\n\\hfill\n\n\\begin{proof}\nLet $\\vec{x} \\in \\N{A}$, then \\vec{x} satisfies the equation $A\\vec{x}\n= \\vec{0}$; but the resulting vector in \\R{m} has as entries the dot product\nof \\vec{x} with the rows $r_i$ of $A$, therefore, the equation $A\\vec{x} =\n\\vec{0}$ can be rewritten as $m$ equations of the form:\n\n\\[\nr_i \\cdot \\vec{x} = 0, \\ds{for } 1 \\le i \\le m\n\\]\n\nwhich is essentially saying that the vector \\vec{x} is orthogonal to\nall the rows $r_i$ of $A$; therefore, it is orthogonal to every linear\ncombination of them. But those linear combinations are precisely the\nrow space \\C{\\trans{A}}; thus $\\C{\\trans{A}} \\perp \\N{A}$, or,\nreusing previously introduced terminology (see remarks section), we\ncan say that the row space is the orthogonal complement of the null\nspace (which is written as $\\C{\\trans{A}} = \\ortc{\\N{A}}$).  \\\\ \n\nAn analogous argument can be constructed for \\C{A} and \\N{\\trans{A}},\nusing the equation $\\trans{A}\\vec{y} = \\vec{0}$ (details are in\n\\cite{strang88}). Thus, we can also conclude that the column space is\nthe orthogonal complement of the left null space (which can be written as $\\C{A} =\n\\ortc{\\N{\\trans{A}}}$). \n\\end{proof}\n\nHaving established the orthogonality of these subspaces, allow us to\nintroduce a secret weapon that will finally help us prove the pending\n\\cref{thm:SVD2}. This weapon is another theorem that establishes a\nrelationship between the dimension of any subspace and its orthogonal\ncomplement \\footnote{The\n  name was provided by us, as Lang does not name it in his book\n  \\cite{lang04}.}: \\\\\n\n\\begin{theorem}[Orthogonal Complement Dimension Theorem]\n\\label{thm:ortdim}\nLet $W$ any subspace of \\R{n}, then is the case that\n\n\\[\n\\dim{W} + \\dim{\\ortc{W}} = n\n\\]\n\\end{theorem}\n\\hfill\n\nAn even more generic version of this theorem is proved by Lang in\n\\cite{lang04} (theorem 2.3 in that book), and it basically says that\nif we take any subspace and its orthogonal complement together, they\nform the entirety of the host space! Another way of seeing this\nresult, is saying that the host space $V$ is the direct sum of the\nsubspace $W$ and its orthogonal  complement (denoted as $V = W \\oplus\n\\ortc{W}$). Intuitively, the notion \nof a direct sum tells us that there is nothing out of the union of the\nsubspace $W$ and its orthogonal complement \\ortc{W}; every vector in\nthe original space can be expressed as a sum $x_1 + x_2$ (where\neach $\\vec{x_1} \\in W$ and $\\vec{x_2} \\in \\ortc{W}$, and $W$), and\n\\ortc{W} do not share anything other than zero vector ($W \\cap\n\\ortc{W} = \\{\\vec{0}\\}$). \\\\\n\nUsing this weapon, we can finally prove the pending \n\\cref{thm:SVD2}, which was about proving that the last $n-r$ vectors\nof $V$ actually belong to \\N{A}. \\\\\n\n\\svdtwo*\n\n\\begin{proof}\nBy hypothesis we know that \n\n\\[\nA\\vec{v_i} = \\sigma_i\\vec{u_i}, \\ds{}\\forall i=1 \\dots r, \\ds{}\\text{where\n} r = rank(A).\n\\]\n\\\\\n\nSince the vectors \\vec{u_i}\\apos{s} form a basis of \\R{m}, that\nimplies none of them can be zero; therefore $A\\vec{v_i} \\ne \\vec{0}\n\\ds{}\\forall i=1 \\dots r$. By definition, such condition implies that\nthose vectors $v_i \\notin \\N{A}$, but since $\\R{n} = \\C{\\trans{A}} \\oplus \\N{A}$,\nthen the only other option for those vectors\n$\\{\\vec{v_1},\\vec{v_2},\\dots,\\vec{v_r}\\}$ is to belong to the row\nspace \\C{\\trans{A}}. Actually, since they are all orthogonal, they form\na basis of \\C{\\trans{A}} (because $\\dim{\\C{\\trans{A}}} = \\func{rank}(A) =\nr$). Let us call this basis $B_r$. \\\\\n\nLet $\\vec{v_i} \\in \\R{n}$, which also belongs to\n$\\{\\vec{v_{r+1}},\\vec{v_{r+2}},\\dots,\\vec{v_n}\\}$; since \\vec{v_i}\nis orthogonal to every vector in $B_r$ (as all the \\vec{v}\\apos{s}\nform an orthonormal basis of \\R{n}), then \\vec{v_i} can not belong\nto the subspace generated by $B_r$, which happens to be\n\\C{\\trans{A}}. Using again the fact that $\\R{n} = \\C{\\trans{A}} \\oplus\n\\N{A}$, we can tell that the only other option for $\\vec{v_i}$ is to\nbelong to the nullspace \\N{A}. And by definition of nullspace:\n\n\\[\nA\\vec{v_i} = \\vec{0}, \\ds{}\\forall i=(r+1) \\dots n\n\\]\n\\hfill\n\nwhich completes the proof. Mirroring the reasoning about basis $B_r$\nof the row space, we can also tell that the vectors\n$\\{\\vec{v_{r+1}},\\vec{v_{r+2}},\\dots,\\vec{v_n}\\}$ form a basis of the\nnull space \\N{A}. \n\\end{proof}\n\nSince we established already the orthogonality between the four\nsubspaces of matrix $A$, we can simply apply \\cref{thm:ortdim}\nto them in pairs (depending on whether they are hosted on same space),\nand derive the following equations: \\\\\n\n\\begin{enumerate}\n\\item In \\R{n}: $\\C{\\trans{A}} = \\ortc{\\N{A}} \\implies\n  \\dim{\\N{A}} + \\dim{\\C{\\trans{A}}} = n$\n\\item In \\R{m}: $\\C{A} = \\ortc{\\N{\\trans{A}}} \\implies \n  \\dim{\\N{\\trans{A}}} + \\dim{\\C{A}} = m$\n\\end{enumerate}\n\\hfill\n\nThese two equations are what Strang calls the Fundamental Theorem of\nLinear Algebra (Part I); further references are \\cite{strang88} and\n\\cite{strang93}. The two parts of such theorem together, basically\ndescribe what are the subspaces generated by matrix $A$, what is the\nrelationship among them (orthogonality) and what are their\ndimensions. The \\cref{fig:fund} below (taken from\n\\cite{strang88}), summarizes both parts of this important theorem:\n\\\\\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=14cm]{fund}\n  \\caption{Visualization of the Fundamental Theorem of Linear Algebra}\n  \\label{fig:fund}\n\\end{figure}\n\\hfill\n\nStrang goes further in contextualizing the SVD factorization in the\nabove diagram (\\cite{strang93}), by noting that the columns of the\nmatrices $V$ and $U$, actually contain the basis of these four\nsubspaces: \n\n\\begin{itemize}\n\\item The orthogonal matrix $V$ contains a basis for the row space\n  \\C{\\trans{A}} in the first $r$ columns, and a basis for the null\n  space \\N{A} in the last $n-r$ columns. We showed this already while\n  proving \\cref{thm:SVD2}. \n\\item The orthogonal matrix $U$ contains a basis for the column space\n  \\C{A} in the first $r$ columns, and a basis for the left null\n  space \\N{\\trans{A}} in the last $m-r$ columns. \n\\end{itemize}\n\\hfill\n\nThe last observation makes the SVD factorization even more astonishing\nand intriguing: not only it allows one to understand the true nature of\nan arbitrary matrix $A$, by explicitly giving the two change of basis\nthat make $A$ a positive diagonal matrix $\\Sigma$ (having just\ncompressions and expansions). Also, if we consider a basis as a \nrepresentation of a vector space; then the matrices $V$ and $U$ of the\nSVD factorization can be \nconsidered a representation of the four subspaces generated by that\nparticular matrix $A$. Putting together the three matrices as in $A =\nU\\Sigma\\trans{V}$, gives the truly complete picture about the effects\nof transformation $A$. \n\n", "meta": {"hexsha": "eb673215ba211e315149a53f39d1875ce0d98f70", "size": 12364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-proof-spec-fund.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-fund.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-fund.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.2307692308, "max_line_length": 83, "alphanum_fraction": 0.7065674539, "num_tokens": 3798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.687115761953213}}
{"text": "\\documentclass{standalone}\n\\begin{document}\n\t\\chapter{Quadratic Equations}\n\t\\section{Definition}\n\t\\quad A quadratic equation is of the form $ax^2+bx+c=0$ where $a,b,c \\in \\mathbb{R},\\quad a\\neq0$. These can be solved algebraically using one of the following methods:\n\t\\begin{itemize}\t\t\n\t\t\\item{Fractions}\n\t\t\\item{Completing the square}\n\t\t\\item{The quadratic formula\\footnote[3]{\\qe}}\n\t\\end{itemize}\n\t\\section{Nature of roots of the Quadratic Equation}\n\t\\quad Any quadratic equation has in general two roots, namely \\qe.\n\tThe quantity $b^2-4ac$ determines the nature of these roots.\n\t\\begin{itemize}\n\t\t\\item{$b^2-4ac > 0\\colon$ Equation holds two real and distinct roots.}\n\t\t\\item{$b^2-4ac = 0\\colon$ Equation holds two equal\\footnote[4]{It is implied that they are real.} roots.}\n\t\t\\item{$b^2-4ac > 0\\colon$ Equation holds two complex roots.}\n\t\\end{itemize}\n\t\\quad Thus, the quantity $b^2-4ac$ discriminates among the type of roots that a quadratic equation may have. Therefore it is called the discriminant.\n\t\\begin{example}\n\t\tDetermine, without solving the nature of the following function.\n\t\\end{example}\n\t\\begin{alignat*}{2}\n\t\t& Let        & f(x) =                 & 2x^2+3x-17                              \\\\\n\t\t& \\implies   & b^2-4ac                & =3^2-4(2)(-17)                          \\\\\n\t\t&            &                        & = 145                                   \\\\\n\t\t&            &                        & > 0                                     \\\\\n\t\t& \\therefore & \\text{Roots of $f(x)$} & \\in \\mathbb{R} \\text{ and are distinct} \n\t\\end{alignat*}\n\t\\hrulefill\n\t\\begin{example}\n\t\tDetermine the value of $p$ if $ px^2-10x+1 = 0 $ has two equal roots\n\t\\end{example}\n\t\n\tGiven that the equation has two equal roots:\n\t\n\t\\begin{alignat*}{2}\n\t\t&          & b^2-4ac                        & = 0 \\\\\n\t\t& \\implies & 100-4p                         & = 0 \\\\\n\t\t&          & \\boxed{\\therefore \\quad p = 5} &     \n\t\\end{alignat*}\n\t\n\t\\newpage\n\t\\section{Roots and Coefficients of a Quadratic Equation}\n\t\\subsection{Proof}\n\t\\emph{Consider a general quadratic equation:}\n\t\\begin{alignat*}{2}\n\t\t&            & ax^2+bx+c                            & = 0 \\tag{1..}                              \\\\\n\t\t& \\implies   & x^2 +\\frac{bx}{a} + \\frac{c}{a}      & = 0                                        \\\\\n\t\t\\intertext{Let $\\alpha$  and $\\beta$  be the roots:}\n\t\t& \\implies   & (x-\\alpha)(x-\\beta)                  & = 0                                        \\\\\n\t\t& \\implies   & x^2 -\\beta x -\\alpha x + \\alpha\\beta & = 0                                        \\\\\n\t\t& \\implies   & x^2-(\\alpha + \\beta)x + \\alpha\\beta  & = 0\\tag{2..}                               \\\\\n\t\t\\intertext{Since (1..) and (2..) are identical:}\n\t\t& \\implies   & x^2 +\\frac{bx}{a} + \\frac{c}{a}      & \\equiv x^2-(\\alpha + \\beta)x + \\alpha\\beta \\\\\n\t\t& \\therefore & \\alpha + \\beta                       & = \\frac{-b}{a}                             \\\\ \n\t\t&            & \\alpha\\beta                          & = \\frac{c}{a}                              \n\t\\end{alignat*}\n\t\\hrulefill\n\t\n\t\\begin{example}\n\t\tWrite down the quadratic equation whose roots have a sum of 7 \\& a product of 5.\n\t\\end{example}\n\t\\begin{alignat*}{2}\n\t\t&   &        & x^{2} - (\\alpha + \\beta) + (\\alpha\\beta) \\\\\n\t\t&   & =\\quad & x^2 - 7x + 7                             \n\t\\end{alignat*}\n\t\\hrulefill\n\t\\begin{example}\n\t\tThe roots of the equation $2x^2 + 5x -1$ are $\\alpha$ and $\\beta$. Find the equation whose roots are $\\frac{1}{\\alpha} $ \\& $\\frac{1}{\\beta}$\n\t\\end{example}\n\t\\begin{alignat*}{2}\n\t\t&   & \\alpha + \\beta & = \\frac{-5}{2} \\\\\n\t\t&   & \\alpha\\beta    & = \\frac{-1}{2} \n\t\\end{alignat*}\n\t\\newpage\n\t\\begin{multicols}{2}\n\t\t\\textit{Sum of roots:}\n\t\t\\begin{alignat*}{2}\n\t\t\t&   &   & \\frac{1}{\\alpha} + \\frac{1}{\\beta} \\\\\n\t\t\t&   & = & \\frac{\\alpha+\\beta}{\\alpha\\beta}   \\\\\n\t\t\t&   & = & \\frac{-5}{2} \\div \\frac{-1}{2}     \\\\\n\t\t\t&   & = & 5                                  \n\t\t\\end{alignat*}\n\t\t\\textit{Product of roots:}\n\t\t\n\t\t\\begin{alignat*}{2}\n\t\t\t\\\\&&&\\frac{1}{\\alpha\\beta}\\\\\n\t\t\t&   & = & \\frac{-2}{1} \\\\\n\t\t\t&   & = & -2           \n\t\t\\end{alignat*}\n\t\\end{multicols}\n\t\\[ \n\t\\therefore \\quad f(x) = x^2-5x-2\n\t\\]\n\t\\newpage\n\t\n\t\\end{document}", "meta": {"hexsha": "f75f6a5930a5ec920a3bd5679a54bc0c0dc416a2", "size": 4167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/Quadratic_Equations.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/Quadratic_Equations.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/Quadratic_Equations.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": 42.5204081633, "max_line_length": 169, "alphanum_fraction": 0.4917206623, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6871157583593077}}
{"text": "\\subsection{Tuning to phase shifts on the lattice}\\label{sec:tuning}\n\nObservables in a FV lattice theory must converge against their physical counterpart in the IV and continuum limit.\nBecause the hamiltonian is implmented in a discrete finite volume, we must match the interactions to a discrete finite observable.\nThe implementation is well behaved if, after the matching of one observable (input), the IV and continuum limit for other observales (prediction) converges against the physical counterpart.\nThe implementation of the hamiltonian includes only one parameter, the strength of the contact interaction, which we match against scattering information.\nThe goal is to reproduce the entire phase shifts as a function of scattering momenta by matching the interactions to just one scattering momentum point.\nThe FV scattering spectrum can be exactly computed by using L\\\"{u}scher's formalism \\textit{in reverse}: we compute the intersections of the phase shifts with the zeta function to extract the finit volume spectrum (see also \\Figref{tuning})\n\\begin{equation}\n    S^\\spherical_D(x_i)\n    =\n    \\frac{1}{\\pi^2 L^{D-2}}\n    \\begin{cases}\n        -\\frac{1}{a_{03} \\pi}   & D=3\\\\\n        \\frac{1}{\\pi}\\log(x_i) + \\frac{2}{\\pi} \\log \\left(\\frac{ 2 \\pi R_{02}}{L}\\right) & D=2\\\\\n        2 a_{01}   & D=1\n    \\end{cases}\n\t\\, .\n\\end{equation}\n\nWe compute the FV discrete spectrum $\\{E_i(\\epsilon)\\}$, adjust the contact interaction such that the ground state energy $E_0(\\epsilon)$ matches the first zero of the zeta function $x_0 = 2 \\mu E_0(\\epsilon) L^2 / (2 \\pi)^2$  and repeat the procedure for different lattice spacings.\n", "meta": {"hexsha": "c0a3d7b206322c75389138f88f080d6ff90aeff0", "size": 1632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/two-particle-scattering/tuning-to-phase-shifts.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-particle-scattering/tuning-to-phase-shifts.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-particle-scattering/tuning-to-phase-shifts.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": 74.1818181818, "max_line_length": 283, "alphanum_fraction": 0.7420343137, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6870962339562625}}
{"text": "\\chapter{Model and Estimation} \\label{chapter2:Procedure}\n\nThroughout this chapter, assume that the data is observed at $n$ (not necessarily evenly spaced) spatial locations $\\{\\bm{s}_1, \\dots, \\bm{s}_n\\}$. These locations exist on some bounded domain $\\mathcal{D} \\subseteq  \\mathbb{R}^d$. The data, $\\bm{y} =(y_1, \\dots, y_n)^T$, is a realization of the random vector $\\bm{Y} = (Y(\\bm{s}_1), \\dots, Y(\\bm{s}_n))^T$, which constitute observations of single instance of a Gaussian process with mean 0 and stationary isotropic covariance function $C(h)$. %Then\n% \\[\n% \t\\bm{Y} \\sim \\mathcal{N}_n(\\bm{0}, \\bm{\\Sigma}),\n% \\]\n% where $\\Sigma_{ij} = C(|| \\bm{s}_i - \\bm{s}_j ||)$.  \nWe aim to estimate the covariance function.\n\n\\section{Estimating the Covariance Function} % (fold)\n\\label{sec:estimating_the_covariance_function}\n\nUnder the assumptions of stationarity and isotropy, the random vector $\\bm{Y} \\sim \\mathcal{N}_n(\\bm{0}, \\bm{\\Sigma})$, where the $ij$th element of $\\bm{\\Sigma}$ is\n\\[\n\t\\Sigma_{ij} = \\textrm{Cov}(y_i, y_j) = C(||\\bm{s}_i - \\bm{s}_j||) = C(h_{ij}).\n\\]\nThe scaler $h_{ij}$ is the Euclidean distance between locations $\\bm{s}_i$ and $\\bm{s}_j$. We can use \\eqref{eq:bochner2} to obtain an integral representation for each element of $\\bm{\\Sigma}$,\n\\begin{equation} \\label{eq:cov-elements-spectral}\n\t\\Sigma_{ij} = \\int \\cos(h_{ij}\\omega) \\; f(\\omega) \\; d\\omega.\n\\end{equation}\nRather than model the covariance function directly, we will model the spectral density with a semiparametric Bayesian model and use \\eqref{eq:cov-elements-spectral} to construct the data likelihood.\n\n% Were we able to sample from the spectral density $f(\\omega)$, we could estimate $\\Sigma_{ij}$ using Monte Carlo integration:\n% \\begin{equation}\n% \t\\Sigma_{ij} \\approx \\widehat{\\Sigma}_{ij} = \\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij}\\widetilde{\\omega}_m)\n% \\end{equation}\n% for $M$ samples $\\{\\widetilde{\\omega}_1, \\dots, \\widetilde{\\omega}_M\\}$ from $f(\\omega)$. The next section discusses an approach for approximating $f(\\omega)$.\n\n% section estimating_the_covariance_function (end)\n\n\n\\subsection{Calculating the Likelihood} % (fold)\n\\label{sec:calculating_the_likelihood}\n\nConsider a rich family of spectral densities $f_{\\bm{\\theta}}(\\omega)$ indexed by a parameter vector $\\bm{\\theta}$.  Since $\\bm{Y} \\sim \\mathcal{N}_n(\\bm{0}, \\bm{\\Sigma})$, the likelihood of $\\bm{\\theta}$ given the data $\\bm{y}$ is\n\\begin{equation} \\label{eq:loglik}\n\t\\ell(\\bm{\\theta}; \\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log |\\bm{\\Sigma}(\\bm{\\theta})| - \\frac{1}{2} \\bm{y}^T \\bm{\\Sigma}(\\bm{\\theta})^{-1} \\bm{y},\n\\end{equation}\nwhere $\\bm{\\Sigma}(\\bm{\\theta})$ is defined as in \\eqref{eq:cov-elements-spectral}.  In general, the solution to the Fourier transform integral in \\eqref{eq:cov-elements-spectral} will not be available analytically.\n\nOur strategy is to replace each element $\\Sigma_{ij}(\\bm{\\theta})$ with a simple Monte Carlo approximation.  Suppressing dependence on $\\bm{\\theta}$ for notational convenience, we will use  \n\\begin{equation}\n\t\\Sigma_{ij} = \\int \\cos(h_{ij}\\omega) \\; f(\\omega) \\; d\\omega \\approx  \\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij}\\widetilde{\\omega}_m) = \\widehat{\\Sigma}_{ij},\n\\end{equation}\nwhere $\\widetilde{\\omega}_1, \\dots, \\widetilde{\\omega}_M$ are $M$ samples from $f_{\\bm{\\theta}}(\\omega)$. We then plug $\\widehat{\\bm{\\Sigma}}$ into the likelihood \\eqref{eq:loglik} to estimate $\\bm{\\theta}$.\n\n\nIt is natural to ask how closely the likelihood evaluated using \\eqref{eq:cov-elements-spectral} approximates the true likelihood.  The following theoretical result shows that the estimated likelihood $\\hat{\\ell}(\\bm{\\theta}; \\bm{y})$ converges to the true likelihood $\\ell(\\bm{\\theta}; \\bm{y})$ almost surely as the number of Monte Carlo samples approaches infinity, even when the spectral density has heavy tails. A proof is given in the Appendix.\n\n\\begin{theorem}\n  \\label{thm:conssitency}\n\tLet $\\bm{y} = (y_1, \\dots, y_n)^T$ be a vector of observations from a mean-zero stationary, isotropic Gaussian process with covariance function $C(h)$, taken at locations $\\bm{s}_1, \\dots, \\bm{s}_n \\in \\mathcal{D} \\subseteq \\mathbb{R}^d$ in some bounded domain $\\mathcal{D}$.  For some symmetric density $f(\\omega)$, let $\\ell(\\bm{y})$ be the likelihood\n\t\\[\n\t\t\\ell(\\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log(|\\bm{\\Sigma}|) - \\frac{1}{2} \\bm{y}^T \\bm{\\Sigma}^{-1} \\bm{y},\n\t\\]\nwhere $\\Sigma_{ij} = \\int \\cos(h_{ij}\\omega)f(\\omega)d\\omega$, and $\\hat{\\ell}(\\bm{y})$ be the Monte Carlo approximated likelihood\n   \t\\[\n \t\t\\hat{\\ell}(\\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log (| \\widehat{\\bm{\\Sigma}}|) - \\frac{1}{2} \\bm{y}^T \\widehat{\\bm{\\Sigma}}^{-1} \\bm{y}\n\t\\] \nwhere $\\widehat{\\Sigma}_{ij} = \\frac{1}{M} \\sum_{m=1}^M \\cos(\\widetilde{\\omega}_m h_{ij})$, and $\\widehat{\\omega}_1, \\dots, \\widehat{\\omega}_M$ are and iid sample from $f(\\omega)$.  Then as $M \\to \\infty$,\n\\[\n\\hat{\\ell}(\\bm{y}) \\to \\ell(\\bm{y}) \\text{ a.s.-}f_\\omega.\n\\]\n\n    \n%     Then the distribution of $\\bm{Y}$ is\n% \t\\[\n% \t\t\\bm{Y} \\sim \\mathcal{N}_n(0, \\bm{\\Sigma})\n% \t\\]\n% \twhere $\\Sigma_{ij} = C(||\\bm{s}_i - \\bm{s}_j||) = C(h_{ij})$. The true likelihood function is\n% \t\\[\n% \t\t\\ell(\\bm{\\Sigma}; \\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log \\det (\\bm{\\Sigma}) - \\frac{1}{2} \\bm{y}^T \\bm{\\Sigma}^{-1} \\bm{y}.\n% \t\\]\n% \tSuppose we observe data $\\bm{y} = (y_1, \\dots, y_n)^T$ from this Gaussian process. Let\n% \t\\[\n% \t\t\\hat{\\ell}(\\widehat{\\bm{\\Sigma}}; \\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log \\det (\\widehat{\\bm{\\Sigma}}(\\bm{\\beta})) - \\frac{1}{2} \\bm{y}^T \\widehat{\\bm{\\Sigma}}^{-1}(\\bm{\\beta}) \\bm{y}\n% \t\\]\n% \tbe the approximated likelihood from our proposed method. The $(i,j)$th element of the approximated covariance matrix $\\widehat{\\bm{\\Sigma}}$ is defined as\n% \t\\[\n% \t\t\\widehat{\\Sigma}_{ij} = \\frac{1}{M} \\sum_{m=1}^M \\cos(\\widetilde{\\omega}_m h_{ij})\n% \t\\]\n% \twhere $\\{\\widehat{\\omega}_1, \\dots, \\widehat{\\omega}_M\\}$ are random samples distributed according to the spectral density $f_\\omega$. Then as $M \\to \\infty$, $\\hat{\\ell}(\\bm{\\beta}; \\bm{y}) \\to \\ell(\\bm{\\Sigma}; \\bm{y})$ a.s. $f_\\omega$.\n\\end{theorem}\n\nTheorem \\ref{thm:conssitency} says that as long as we are willing to draw a large enough collection of Monte Carlo samples from a spectral density $f_{\\bm{\\theta}}(\\omega)$, the Monte Carlo estimated likelihood of $\\bm{\\theta}$ will get arbitrarily close to the exact likelihood.  Furthermore, this remains true even when $f_{\\bm{\\theta}}(\\omega)$ has heavy tails, as we expect for realistic models of spatial phenomena.\n\n\n\n\n% To be explicit, in \\eqref{eq:loglik} the estimated covariance matrix $\\widehat{\\bm{\\Sigma}}$ is expressed as a function of $\\bm{\\beta}$ because\n% \\[\n% \t\\widehat{\\Sigma}_{ij} = \\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij} \\widetilde{\\omega}_m),\n% \\]\n% \\[\n% \t\\widetilde{\\omega}_m \\overset{\\textrm{i.i.d.}}{\\sim} \\hat{f}(\\omega),\n% \\]\n% and\n% \\[\n% \t\\log \\hat{f}(\\log \\omega) = \\sum_{k=1}^K \\beta_k B_k(\\log \\omega).\n% \\]\n% The only free parameters in this procedure are the values of $\\bm{\\beta}$. This is summarized in Algorithm~\\ref{alg:lik}.\n\n% From \\eqref{eq:spline}, we can transform back to $\\hat{f}(\\omega)$, integrate numerically, and sample via the inverse CDF method.\n\n% \\begin{algorithm}[!htb]\n% \t\\caption{\\small Calculating the log likelihood} \\label{alg:lik}\n% \t\\begin{algorithmic}[1]\n% \t\t\\Procedure{Likelihood}{$\\bm{\\beta}, \\bm{y}$}\n% \t\t\\State $\\log \\hat{f}(\\log \\omega) = \\sum_{k=1}^K \\beta_k B_k(\\log \\omega)$\\Comment{$k$ preselected knot locations}\n% \t\t\\State Sample $\\widetilde{\\omega}_1, \\dots, \\widetilde{\\omega}_M$ from $\\hat{f}(\\omega)$\\Comment{Inverse CDF method; $M$ large}\n% \t\t\\For{$1 \\leq i,j \\leq n$}\n% \t\t\t\\State $\\widehat{\\Sigma}_{ij} = \\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij} \\widetilde{\\omega}_m)$\\Comment{$h_{ij}$: distance between locations $\\bm{s}_i$ and $\\bm{s}_j$}\n% \t\t\\EndFor\n% \t\t\\State $\\hat{\\ell}(\\bm{\\beta}; \\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log |\\widehat{\\bm{\\Sigma}}| - \\frac{1}{2} \\bm{y}^T \\widehat{\\bm{\\Sigma}}^{-1} \\bm{y}$\n% \t\t\\EndProcedure\n% \t\\end{algorithmic}\n% \\end{algorithm}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Semiparametric Modeling of the Spectral \\\\ Density} % (fold)\n\\label{sec:semiparametric_modeling_of_the_spectral_density}\n\nSince we don't want to impose a parametric form for $f(\\omega)$, we will model it semiparametrically using splines. According to Bochner's theorem, $f(\\omega)$ is a symmetric density, so it suffices to restrict our attention to modeling $f(\\omega)$ for $\\omega > 0$.\n\nRather than modeling $f(\\omega)$ directly, we apply a straightforward variable transformation and model $\\log f(\\log \\omega)$ instead. Working on the log-log scale is a natural way to flexibly specify densities with heavy tails.  It is easy to show that any density with power law tails has linear tails on the log-log scale. Suppose $f_X(x) = cx^{-b}$, $b > 1$, and let $Y = \\log X$. Then\n\\begin{align*}\n\tf_Y(y) &= f_X(e^y) \\frac{d}{dy}(e^y) \\\\\n\t&= ce^{-by}e^y \\\\\n\t&= ce^{-(b-1)y},\n\\end{align*}\nand so\n\\[\n\t\\log f_Y(y) \\propto -(b-1)y.\n\\]\nThis fact is illustrated further in Figure~\\ref{fig:logdens_ex}.\n\n\\begin{figure}[!htb]\n\t\\centering\n\t\\includegraphics[width=0.48\\textwidth]{dens_ex.png}\n\t\\includegraphics[width=0.48\\textwidth]{logdens_ex.png}\n\t\\caption{\\small A density $f(\\omega)$ with power law tails (left) and the same density transformed to the log-log scale (right). Both the left and right tails of the transformed density are linear.}\n\t\\label{fig:logdens_ex}\n\\end{figure}\n\nAn important benefit to working in this log-transformed space is that linear tails are ideal for modeling the curve using a natural spline basis, which is constructed to ensure linearity beyond the outermost (\\emph{boundary}) knots. If we are willing to assume that the tails of $\\log f(\\log \\omega)$ are truly linear, then fitting it with natural splines will result in a good approximation over then entire domain $\\log \\omega \\in (-\\infty, \\infty)$ without needing to use a large number of basis functions.\n\nIt might appear that requiring that $f(\\omega)$ have power law tails is more restrictive than we would like. After all, the goal is to avoid the need to restrict $C(h)$ to a particular parametric family. However, the class of covariance functions that result from the Fourier transform of power law spectral densities is significantly broader than any of the parametric families, yet Bochner's theorem still guarantees that they are positive definite. In fact, this class covers most covariance models of practical interest, include the entire Mat\\'ern class with finite $\\nu$. Gaussian processes with spectral densities that decay quickly, e.g. with exponential tails, yield realizations that are generally regarded as unrealistically smooth~\\cite{Stein1999}. %Two spatial locations a moderate distance apart would have nearly zero covariance, which is not an acceptably accurate model for real spatial data. By exclusively working with spectral densities that decay more slowly, we are restricting ourselves to the more realistic scenario where two locations can be far apart but still have a non-negligible covariance between them.\n\nTo model $\\log f(\\log \\omega)$ using natural cubic splines, let\n\\begin{equation} \\label{eq:spline}\n\t\\log f(\\log \\omega) = \\sum_{k=1}^K \\beta_k B_k(\\log \\omega),\n\\end{equation}\nwhere $\\bm{\\beta} = (\\beta_1, \\dots, \\beta_K)^T$ are coefficients associated with $K$ known cubic spline basis functions $B_1(\\cdot), \\dots, B_K(\\cdot)$. The $K$ basis functions are centered around a collection of $K$ locations referred to as knots.\n\n% section semiparametric_modeling_of_the_spectral_density (end)\n\n% section calculating_the_likelihood (end)\n\n\\section{Estimating the Spline Coefficients} % (fold)\n\\label{sec:estimating_the_spline_coefficients}\n\n\nFor a given collection of basis functions, the likelihood of the parameter vector $\\bm{\\theta} = \\bm{\\beta} = (\\beta_1, \\dots, \\beta_K)^T$ can be approximated by plugging \\eqref{eq:cov-elements-spectral} into \\eqref{eq:loglik}. To be explicit, in \\eqref{eq:loglik} the estimated covariance matrix $\\bm{\\Sigma}$ is expressed as a function of $\\bm{\\beta}$ because\n\\[\n\t\\Sigma_{ij} = \\int \\cos(h_{ij}\\omega) \\, f_{\\bm{\\beta}}(\\omega) \\, d\\omega \\approx  \\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij} \\widetilde{\\omega}_m) = \\widehat{\\Sigma}_{ij},\n\\]\n\\[\n\t\\widetilde{\\omega}_m \\overset{\\textrm{i.i.d.}}{\\sim} f_{\\bm{\\beta}}(\\omega),\n\\]\nand\n\\[\n\t\\log f_{\\bm{\\beta}}(\\log \\omega) = \\sum_{k=1}^K \\beta_k B_k(\\log \\omega).\n\\]\nThe only free parameters in this procedure are the elements of $\\bm{\\beta}$. This is summarized in Algorithm~\\ref{alg:lik}.\n\nTo quickly generate the samples $\\widetilde{\\omega}_1, \\ldots, \\widetilde{\\omega}_M$, we transform $\\log f_{\\bm{\\beta}}(\\log \\omega)$ back to $f_{\\bm{\\beta}}(\\omega)$, integrate numerically, and sample via the inverse CDF method.\n\n\\begin{algorithm}[!htb]\n\t\\caption{\\small Calculating the log likelihood $\\hat{\\ell}(\\bm{\\beta}; \\bm{y})$} \\label{alg:lik}\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{Likelihood}{$\\bm{\\beta}, \\bm{y}$}\n\t\t\\State $\\log f_{\\bm{\\beta}}(\\log \\omega) = \\sum_{k=1}^K \\beta_k B_k(\\log \\omega)$\\Comment{$k$ preselected knot locations}\n\t\t\\State Sample $\\widetilde{\\omega}_1, \\dots, \\widetilde{\\omega}_M$ from $f_{\\bm{\\beta}}(\\omega)$\\Comment{Inverse CDF method; $M$ large}\n\t\t\\For{$1 \\leq i,j \\leq n$}\n\t\t\t\\State $\\widehat{\\Sigma}_{ij} = \\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij} \\widetilde{\\omega}_m)$\\Comment{$h_{ij}$: distance between locations $\\bm{s}_i$ and $\\bm{s}_j$}\n\t\t\\EndFor\n\t\t\\State $\\hat{\\ell}(\\bm{\\beta}; \\bm{y}) = -\\frac{n}{2} \\log(2\\pi) - \\frac{1}{2} \\log |\\widehat{\\bm{\\Sigma}}| - \\frac{1}{2} \\bm{y}^T \\widehat{\\bm{\\Sigma}}^{-1} \\bm{y}$\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\n\nSince we can calculate the likelihood as a function of the data and $\\bm{\\beta}$, we can estimate $\\bm{\\beta}$ using a Markov chain Monte Carlo (MCMC) algorithm. %However, the problem of choosing how many knots to use and where they should be located still remains.\n\nTo complete the model, we specify priors for $\\bm{\\beta}$ according to the Bayesian formulation of penalized splines introduced in~\\cite{lang2004bayesian}.  The penalization corresponds to priors that specify to a second-order random walk, with\n\\[\n\t\\beta_k \\;|\\; \\tau^2 \\sim \\mathcal{N}(2\\beta_{k-1} - \\beta_{k-2}, \\; \\tau^2)\n\\]\nwhere\n\\[\n\t\\beta_2 \\;|\\; \\tau^2 \\sim \\mathcal{N}(\\beta_1, \\; \\tau^2)\n\\]\nand\n\\[\n\t\\beta_1 \\;|\\; \\tau^2 \\sim \\mathcal{N}(0, \\; \\tau^2).\n\\]\nThe variance parameter $\\tau^2$ controls the smoothness of the spline fit, and must also be estimated. Its prior is specified as\n\\[\n\t\\tau^2 \\sim \\mathcal{N}^+(0, \\; \\sigma^2_\\tau),\n\\]\nthe half-normal distribution with some variance hyperparameter $\\sigma^2_\\tau$.\n\nWith the priors specified, we can proceed with the MCMC algorithm in Algorithm~\\ref{alg:mcmc}. We use a Metropolis-Hastings update to determine whether or not to accept the joint proposal $\\bm{\\beta}$. The result is random draws from the posterior distribution of $\\bm{\\beta} \\;|\\; \\bm{y}$.\n\n\\begin{algorithm}[!htb]\n\t\\caption{\\small Metropolis-Hastings Sampler} \\label{alg:mcmc}\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{MCMC}{$\\bm{\\beta}, \\bm{y}$}\n\t\t\\State $\\bm{\\beta}_1 \\gets \\bm{\\beta}$\\Comment{Initialization}\n\t\t\\For{$2 \\leq i \\leq N$}\\Comment{$N$ large}\n\t\t\\State Propose new $\\bm{\\beta}^* \\sim q(\\cdot)$\n\t\t\\State $\\ell_0 = \\hat{\\ell}(\\bm{\\beta}_{i-1}, \\bm{y})$\\Comment{See Algorithm~\\ref{alg:lik}}\n\t\t\\State $\\ell_1 = \\hat{\\ell}(\\bm{\\beta}^*, \\bm{y})$\n\t\t\\State $a = \\Big[\\pi(\\bm{\\beta}^*) \\cdot \\ell_1 \\cdot q(\\bm{\\beta}_{i-1}|\\bm{\\beta}^*)\\Big]/\\Big[\\pi(\\bm{\\beta}_{i-1}) \\cdot \\ell_0 \\cdot q(\\bm{\\beta}^*|\\bm{\\beta}_{i-1})\\Big]$\n\t\t\\State Generate $u \\sim Unif(0, 1)$\n\t\t\\If{$u < \\min(a, 1)$}\n\t\t\\State $\\bm{\\beta}_i \\gets \\bm{\\beta}^*$\\Comment{Accept the proposal}\n\t\t\\Else\n\t\t\\State $\\bm{\\beta}_i \\gets \\bm{\\beta}_{i-1}$\\Comment{Reject the proposal}\n\t\t\\EndIf\n\t\t\\EndFor\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm} \n\n\n\n% section estimating_the_spline_coefficients (end)\n\n\\section{Computational Challenges} % (fold)\n\\label{sec:computational_challenges}\n\nThe primary difficulty inherent in this method is that it is extraordinarily computationally intensive, requiring a Monte Carlo approximation for every element of the covariance matrix. For a moderately large number of observations, say $n = 400$, we need to estimate $\\frac{n(n-1)}{2} = 79800$ separate elements. For each of these elements, we need to perform a Monte Carlo integration with a large number of samples. This all happens within one likelihood calculation, and we need to compute the likelihood at every iteration of the MCMC algorithm. The computational costs would be prohibitive for a na\\\"{i}ve implementation of this method.\n\nFortunately, most of these difficulties can be assuaged by taking advantage of parallel computing. Algorithm~\\ref{alg:mcmc} requires previous information $\\bm{\\beta}_{i-1}$ to compute $\\bm{\\beta}_i$, so unfortunately it would be extremely difficult to restructure it in a way where multiple updates are being performed simultaneously. However, it is possible to parallelize aspects of the likelihood calculation in Algorithm~\\ref{alg:lik}.\n\nConsider the \\textbf{for} loop in Algorithm~\\ref{alg:lik}. For each value of $i$ and $j$, the computation of $\\widehat{\\Sigma}_{ij}$\n\\[\n\t\\frac{1}{M} \\sum_{m=1}^M \\cos(h_{ij} \\widetilde{\\omega}_m)\n\\]\ndepends on two values: $h_{ij}$, the distance between $\\bm{s}_i$ and $\\bm{s}_j$, and $\\widetilde{\\bm{\\omega}}$, the vector of $M$ samples from $f(\\omega)$. It does not depend on any previously computed element of $\\widehat{\\bm{\\Sigma}}$. Therefore, performance would improve dramatically if we could calculate the estimates simultaneously, in parallel.\n\nThere are several options for speeding up a parallelizable problem. The simplest, and least reliant on expensive additional hardware, is \\emph{parallel processing}~\\cite{suchard2010understanding}. Today, most personal computers ship with CPUs that contain 2, 4, or even 8 computing cores. Each core is capable of running a single set of sequential instructions. By using tools such as OpenMP, users can write code that will assign a set of instructions to every available core. The instructions will execute simultaneously, and the results are gathered together upon completion. Of course, the potential speedup is limited by the number of cores available in the CPU---if there are 4 cores, the instructions will be executed in about one fourth of the time.\n\nThis type of parallel processing works well for problems like obtaining multiple MCMC chains at the same time. For the estimation of $\\bm{\\Sigma}$ in this context, however, it is not optimal. Recall that for $n = 400$, we need to estimate $79800$ elements of $\\bm{\\Sigma}$. Reducing this by a factor of 4 is helpful, but ideally we would like to perform all $79800$ at once, not just take them four at a time.\n\nAnother option is to utilize a computing cluster. Clusters usually are large rooms filled with racks of computers, connected in such a way that one process can be spread uniformly across them and use hundreds or thousands of cores at once~\\cite{suchard2010understanding}. One downside to this approach is that access to such a cluster is difficult to get, outside of a large company or academic institution. Beyond that, though, latency starts to become a problem when dealing with clusters. Because the cores are spread over many physical computers, the increases in computational speed becomes overwhelmed by the large amount of time it takes to share data between the cores. As a result, the overall performance increase may not be as large as we might expect.\n\nA third option is \\emph{GPU computing}. Originally created to run video games, graphics processing units, or GPUs, have become increasingly popular for parallel computing. CPUs contain a small number of cores that are optimized to handle highly complex instructions quickly. By contrast, GPUs are made up of thousands of simple, highly efficient cores that are optimized for simpler instructions and designed to work in parallel with each other. Because the GPU cores lack many of the sophisticated features of CPU cores (a sacrifice made in exchange for speed and efficient exchange of data), the programmer must have a more intricate knowledge of the architecture of their particular GPU in order to get the best possible speedup. Fortunately, directives such as OpenACC let the compiler make most of the architecture-related decisions instead of leaving them in the hands of the user.\n\nTo take full advantage of the highly parallelizable nature of the covariance estimation problem, I have chosen the GPU option. I wrote the code to carry out the Monte Carlo integrations in CUDA C. CUDA is an API provided by Nvidia that allows users to write programs in C or Fortran that interact with Nvidia brand GPUs. Computations were done on three different hardware setups:\n\n\\begin{itemize}\n\t\\item Nvidia GeForce GTX 1060 GPU, on a personal computer running Ubuntu 16.04;\n\t\\item Nvidia Tesla P100 GPU, provided by Penn State University's Institute for CyberScience Advanced CyberInfrastructure (ICS-ACI);\n\t\\item Nvidia Tesla K80 GPU, running on an Amazon EC2 instance.\n\\end{itemize}\n\nWith these tools, the computations can be performed fairly quickly. On the Tesla P100, one entire likelihood calculation described by Algorithm~\\ref{alg:lik} with $M = 50000$ and $N = 400$ completes in just under one second.\n\nTo illustrate the power of parallel computing, and to show that this element-wise approximation to the covariance matrix is a feasible approach, Figure~\\ref{fig:timings-mc} shows the results of an experiment comparing the runtime of the Monte Carlo approximation from Algorithm~\\ref{alg:lik} to the runtime of the exact covariance calculation. That is, for a fixed $N$, generate 100 sets of points $\\bm{s}_1, \\dots, \\bm{s}_N$ and their distances $h_{ij} = ||\\bm{s}_i - \\bm{s}_j||$. Also generate $M = 20000$ samples $\\widetilde{\\omega}_1, \\dots, \\widetilde{\\omega}_M$ from the spectral density $f(\\omega)$ corresponding to a Mat\\`ern covariance function. Since the computational cost of the random sample generation is constant regardless of $N$, it is not included when timing.\n\\[\n\t\\Sigma_{ij} = C(h_{ij})\n\\]\nand\n\\[\n\t\\widehat{\\Sigma}_{ij} = \\frac{1}{M}\\sum_{m=1}^M \\cos(h_{ij} \\widetilde{\\omega}_{m})\n\\]\n100 times each, and compare the median runtimes as a function of $N$.\n\nNotice from Figure~\\ref{fig:timings-mc} that for large enough $N$, it actually becomes faster to perform a Monte Carlo approximation to the elements of $\\Sigma$ than to directly plug in the distances to the covariance function $C$. In this experiment $N$ needed to be greater than about 2000, but this is of course hardware dependent.\n\nThis is not a surprising result considering the parallelized nature of the Monte Carlo approximation. As $N$ increases, the exact calculation must handle all additional computations sequentially, whereas the Monte Carlo approximation can simply allocate more cores that execute their tasks simultaneously. As a result, the Monte Carlo runtime increases more slowly with $N$ than the exact covariance runtime.\n\nHowever, there are nontrivial computational costs associated with GPU computing that cause it to be significantly slower than the exact alternative when $N$ is not large. In Figure~\\ref{fig:timings-mc}, it appears that the Monte Carlo runtime is more or less unchanged from $N = 40$ to $N = 400$. The bottleneck here is data transfer and allocation. For small $N$, the time required to do the calculations themselves is negligible compared to the time required to allocate memory on the GPU, transfer the spectral density samples from the CPU to the GPU, combine the results, and transfer them back to the CPU. This is the reason that sometimes, seemingly paradoxically, parallelizing a routine can cause it to execute more slowly than the equivalent sequential routine. But for large enough $N$, we expect the speedup to be substantial.\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.95\\textwidth]{timings_mc.pdf}\n\t\\caption{Elapsed time taken to calculate the element-wise Monte Carlo approximation to the covariance matrix corresponding to a Mat\\'ern covariance function, versus calculating it directly using $C(h)$. The covariance matrix is $n \\times n$, where $n$ is the number of observations. Each method was run 100 times for every value of $n$. The medians are plotted with dots and connected with a line. The error bars represent the range from the first to third quartiles---some times for the exact calculation were misleadingly high due to CPU wakeup. GPU computations were done on a Tesla P100. Note the logarithmic axes.}\n\t\\label{fig:timings-mc}\n\\end{figure}\n\n% section computational_challenges (end)", "meta": {"hexsha": "661a80ebe7ac01176c1858e7a0a7c1b55b095698", "size": 24800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Chapter-2/Chapter-2.tex", "max_stars_repo_name": "ensley/thesis", "max_stars_repo_head_hexsha": "fc8af97cdb1ed43e6a996a9eed5f1f195199669c", "max_stars_repo_licenses": ["MIT"], "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/Chapter-2/Chapter-2.tex", "max_issues_repo_name": "ensley/thesis", "max_issues_repo_head_hexsha": "fc8af97cdb1ed43e6a996a9eed5f1f195199669c", "max_issues_repo_licenses": ["MIT"], "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/Chapter-2/Chapter-2.tex", "max_forks_repo_name": "ensley/thesis", "max_forks_repo_head_hexsha": "fc8af97cdb1ed43e6a996a9eed5f1f195199669c", "max_forks_repo_licenses": ["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.4871794872, "max_line_length": 1134, "alphanum_fraction": 0.7195967742, "num_tokens": 7304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6870444133648073}}
{"text": "\\section{Multivariate Distributions}\r\n\\subsection{Joint and Marginal Distributions}\r\nLet $X$ be a continuous random variable has density $f$, then we know that\r\n$$\\mathbb P(X\\le x)=\\int_{-\\infty}^xf(y)\\,\\mathrm dy$$\r\nIt can be proved that this can generalize to an arbitrary (measurable) subsets $B\\subset\\mathbb R$, that is,\r\n$$\\mathbb P(X\\in B)=\\int_Bf(x)\\,\\mathrm dx$$\r\n\\begin{definition}\r\n    For a tuple of random variables $X=(X_1,\\ldots,X_n)\\in\\mathbb R^n$ where $X_i$ are continuous, $X$ is said to have density $f$ if\r\n    \\begin{align*}\r\n        F(x_1,\\ldots,x_n)&=\\mathbb P(X_1\\le x_1,\\ldots,X_n\\le x_n)\\\\\r\n        &=\\int_{-\\infty}^{x_1}\\cdots\\int_{-\\infty}^{x_n}f(y_1,\\ldots,y_n)\\,\\mathrm dy_n\\cdots\\mathrm dy_1\r\n    \\end{align*}\r\n    So $f(x_1,\\ldots,x_n)=\\partial^n F/(\\partial x_1\\cdots\\partial x_n)$.\r\n    We can also generalize this to (measurable) subsets $B\\subset\\mathbb R^n$ by saying\r\n    $$\\mathbb P(X\\in B)=\\int_Bf(x_1,\\ldots,x_n)\\,\\mathrm dx_1\\cdots\\mathrm dx_n$$\r\n    Let $g:\\mathbb R^n\\to\\mathbb R^+$, we define\r\n    $$\\mathbb E[g(X)]=\\int_{\\mathbb R^n}g(x_1,\\ldots,x_n)f(x_1,\\ldots,x_n)\\,\\mathrm dx_1\\cdots\\mathrm dx_n$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    We say $X_1,\\ldots,X_n$ are independent if $\\mathbb P(X_1\\le x_1,\\ldots,X_n\\le x_n)=\\mathbb P(X_1\\le x_1)\\cdots\\mathbb P(X_n\\le x_n)$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $X=(X_1,\\ldots,X_n)$ have density $f$, then\\\\\r\n    1. If $X_1,\\ldots,X_n$ are independent and $X_i$ has density $f_i$, then\r\n    $$f(x_1,\\ldots,x_n)=\\prod_{i=1}^nf_i(x_i)$$\r\n    2. Conversely, suppose we have the above formula for some nonnegative functions $f_i$, then $X_1\\ldots,X_n$ are independent and have density functions proportional to $f_i$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    1. We know\r\n    \\begin{align*}\r\n        \\mathbb P(X_1\\le x_1,\\ldots,X_n\\le x_n)&=\\prod_{i=1}^n\\int_{-\\infty}^xf_i(y_i)\\,\\mathrm dy_i\\\\\r\n        &=\\int_{-\\infty}^{x_1}\\cdots\\int_{-\\infty}^{x_n}\\prod_{i=1}^nf(y_i)\\,\\mathrm dy_n\\cdots\\mathrm dy_1\r\n    \\end{align*}\r\n    2. By multiplying constant, we may assume that\r\n    $$\\int_{-\\infty}^\\infty f_i(x)\\,\\mathrm dx=1$$\r\n    for all $i$.\r\n    So for $B_i\\subset\\mathbb R$ (measurable),\r\n    $$\\mathbb P(X\\in B_1\\times\\cdots\\times B_n)=\\int_{B_1}\\cdots\\int_{B_n}\\prod_{i=1}^nf(y_i)\\,\\mathrm dy_n\\cdots\\mathrm dy_1$$\r\n    Now fix $i$ and let $B_j=\\mathbb R$ for any $j\\neq i$, expanding the integral then gives\r\n    $$\\mathbb P(X_i\\in B_i)=\\mathbb P(X_i\\in B_i,X_j\\in B_j,j\\neq i)=\\int_{B_i}f_i(y_i)\\,\\mathrm dy_i$$\r\n    So $f_i$ is the density of $X_i$.\r\n    Independence follows.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $X=(X_1,\\ldots,X_n)$ have density $f$, we have\r\n    $$\\mathbb P(X_i\\le x)=\\int_{-\\infty}^x\\int_{-\\infty}^\\infty\\cdots\\int_{-\\infty}^\\infty f(x_1,\\ldots,x_n)\\,\\mathrm dx_1\\cdots\\mathrm dx_{i-1}\\,\\mathrm dx_{i+1}\\cdots\\mathrm dx_n\\,\\mathrm dx_i$$\r\n    So the density of $X_i$ is\r\n    $$f_{X_i}(x)=\\int_{-\\infty}^\\infty\\cdots\\int_{-\\infty}^\\infty f(x_1,\\ldots,x_n)\\,\\mathrm dx_1\\cdots\\mathrm dx_{i-1}\\,\\mathrm dx_{i+1}\\cdots\\mathrm dx_n$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{definition}\r\n    This is called the marginal density.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $f,g$ be two densities on $\\mathbb R$, their convolution is defined as\r\n    $$(f\\ast g)(x)=\\int_{-\\infty}^\\infty f(x-y)g(y)\\,\\mathrm dy$$\r\n\\end{definition}\r\nLet $X,Y$ be two independent random variables with densities $f_X,f_Y$, then\r\n\\begin{align*}\r\n    \\mathbb P(X+Y\\le z)&=\\int_{\\mathbb R^2}1_{x+y\\le z}f_{X,Y}(x,y)\\,\\mathrm dx\\,\\mathrm dy\\\\\r\n    &=\\int_{x+y\\le z}f_X(x)f_Y(y)\\,\\mathrm dx\\,\\mathrm dy\\\\\r\n    &=\\int_{-\\infty}^\\infty\\int_{-\\infty}^{z-x}f_X(x)f_Y(y)\\,\\mathrm dy\\,\\mathrm dx\\\\\r\n    &=\\int_{-\\infty}^\\infty\\int_{-\\infty}^zf_X(x)f_Y(y-x)\\,\\mathrm dy\\,\\mathrm dx\\\\\r\n    &=\\int_{-\\infty}^z\\int_{-\\infty}^\\infty f_X(x)f_Y(y-x)\\,\\mathrm dx\\,\\mathrm dy\\\\\r\n    &=\\int_{-\\infty}^z(f\\ast g)(y)\\,\\mathrm dy\r\n\\end{align*}\r\nSo basically the convolution of $f_X$ and $f_Y$ is the density of $X+Y$.\r\nThere is another way to obtain the same result, but it is not rigorous at all.\r\n\\begin{align*}\r\n    \\mathbb P(X+Y\\le z)&=\\int_{-\\infty}^\\infty\\mathbb P(X+Y\\le z,y\\in\\mathrm dy)\\\\\r\n    &=\\int_{-\\infty}^\\infty\\mathbb P(X+y\\le z,y\\in\\mathrm dy)\\\\\r\n    &=\\int_{-\\infty}^\\infty\\mathbb P(X\\le z-y)\\mathbb P(y\\in\\mathrm dy)\\\\\r\n    &=\\int_{-\\infty}^\\infty F_X(z-y)f_Y(y)\\,\\mathrm dy\r\n\\end{align*}\r\nJust differentiating and changing the order gives the result.\r\n\\subsection{Conditionals}\r\n\\begin{definition}\r\n    Let $X,Y$ be continuous random variables with joint density $f_{X,Y}$, then the conditional density of $X$ given $Y=y$ is\r\n    $$f_{X|Y}(x|y)=\\frac{f_{X,Y}(x,y)}{f_Y(y)}$$\r\n    Given that $f_Y$ is nonzero.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The conditional expectation of $X$ given $Y$ is $g(Y)$ where\r\n    $$g(y)=\\int_{-\\infty}^\\infty xf_{X|Y}(x|y)\\,\\mathrm dx(=\\mathbb E(X|Y=y))$$\r\n    We write $\\mathbb E[X|Y]=g(Y)$.\r\n\\end{definition}\r\n\\subsection{Law of Total Probability}\r\n\\begin{proposition}[Law of Total Probability]\r\n    $$f_X(x)=\\int_{-\\infty}^\\infty f_{X|Y}(x|y)f_Y(y)\\,\\mathrm dy$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Plug in definition.\r\n\\end{proof}\r\n\\begin{example}\r\n    Let $X\\sim\\operatorname{Exp}(\\lambda),Y\\sim\\operatorname{Exp}(\\mu)$ be independent.\r\n    Set $Z=\\min(X,Y)$.\r\n    So\r\n    \\begin{align*}\r\n        \\mathbb P(Z\\le z)&=1-\\mathbb P(Z>z)=1-\\mathbb P(X>z,Y>z)\\\\\r\n        &=1-\\mathbb P(X>z)\\mathbb P(Y>z)=1-e^{-\\lambda z}e^{-\\mu z}=1-e^{-(\\lambda+\\mu)z}\r\n    \\end{align*}\r\n    Therefore $Z\\sim\\operatorname{Exp}(\\lambda+\\mu)$.\r\n    So by the same way, for $X_i\\sim\\operatorname{Exp}(\\lambda_i)$, then $\\min(X_1,\\ldots,X_n)\\sim \\operatorname{Exp}(\\sum_i\\lambda_i)$\r\n\\end{example}\r\n\\subsection{Transformation of a Multidimensional Random Variable}\r\n\\begin{theorem}\r\n    Let $X$ be a continuous random variable in $D\\subset\\mathbb R^d$ with density $f_X$.\r\n    Let $g$ be a bijection $D\\to g(D)$ with continuous derivative on $D$ and $\\forall x\\in D,\\det g^\\prime\\neq 0$.\r\n    Set $y=g(x)$ and $Y=g(X)$, then the density of $Y$ is given by\r\n    $$f_Y(y)=f_X(x)|J|=f_X(x)\\left\\|\\left(\\frac{\\partial x_i}{\\partial y_j}\\right)_{i,j=1}^d\\right\\|$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\n\\begin{example}\r\n    Let $X,Y\\sim\\mathcal N(0,1)$ be independent, and $R=\\sqrt{X^2+Y^2},\\Theta=\\arg(X,Y)$, so $X=R\\cos\\Theta,Y=R\\sin\\Theta$.\r\n    So we want the joint density of $(R,\\Theta)$.\r\n    We have\r\n    $$f_{R,\\Theta}(r,\\theta)=f_{X,Y}(x,y)|J|=rf_{X,Y}(x,y)=rf_X(x)f_Y(y)=\\frac{r}{2\\pi}e^{-r^2/2}$$\r\n    So $R,\\Theta$ are independent with $\\Theta\\sim\\operatorname{Unif}(0,2\\pi)$ and $R$ has density $f_R(r)=re^{-r^2/2}$.\r\n\\end{example}\r\n\\subsection{Order Statistics of a Random Sample}\r\nLet $X_1,\\ldots,X_n$ be i.i.d. with distribution $F$ and density $f$.\r\nIf we put them in order from smallest to biggest, $X_{(1)}\\le \\cdots X_{(n)}$, then $Y_i=X_{(i)}$ is called the order statistics.\r\nSo $\\mathbb P(Y_1\\le x)=1-\\mathbb P(Y_1>x)=1-(1-F(x))^n$ is the distribution of $Y_1$.\r\nThe density then is $nf(x)(1-F(x))^{n-1}$.\r\nAlso $\\mathbb P(Y_n\\le x)=(F(x))^n$, so it has density $nf(x)F(x)^{n-1}$.\r\nNow we want to find the joint density of $(Y_1,\\ldots,Y_n)$.\r\nLet $x_1<\\cdots<x_n$, we have\r\n\\begin{align*}\r\n    \\mathbb P(Y_1\\le x_1,\\ldots,Y_n\\le x_n)&=\\sum_{\\sigma\\in S_n}\\mathbb P(X_1\\le x_{\\sigma(1)},\\ldots X_n\\le x_{\\sigma(n)})\\\\\r\n    &=n!\\mathbb P(X_1\\le x_1,\\ldots X_n\\le x_n)\\\\\r\n    &=n!\\int_{-\\infty}^{x_1}f(u_1)\\int_{-\\infty}^{x_2}f(u_2)\\cdots\\int_{-\\infty}^{x_n}f(u_n)\\,\\mathrm du_n\\cdots\\mathrm  du_1\r\n\\end{align*}\r\nSo by differentiating the density $f_Y$ of $Y_i$'s is $f_Y(y_1,\\ldots,y_n)=n!f(y_1)\\cdots f(y_n)$ for $y_1<y_2<\\cdots<y_n$ and $0$ otherwise.\r\n\\begin{example}\r\n    Let $X_1,\\ldots,X_n$ be i.i.d. $\\operatorname{Exp}(\\lambda)$ and $Y_i$ be the order statistics and $Z_1=Y_1,Z_i=Z_i-Z_{i-1}$ for $i=2,\\ldots,n$.\r\n    Then\r\n    $$Z=\\begin{pmatrix}\r\n        Z_1\\\\\r\n        \\vdots\\\\\r\n        Z_n\r\n    \\end{pmatrix}=A\\begin{pmatrix}\r\n        Y_1\\\\\r\n        \\vdots\\\\\r\n        Y_n\r\n    \\end{pmatrix},A=\\begin{pmatrix}\r\n        1&0&0&\\dots&0\\\\\r\n        -1&1&0&\\dots&0\\\\\r\n        0&-1&1&\\dots&0\\\\\r\n        \\vdots&\\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n        0&0&0&\\dots&1\r\n    \\end{pmatrix}$$\r\n    where we have $\\det A=1$ and $Y_j=\\sum_{i=1}^jZ_i$, so for $y_j=\\sum_{i=1}^jz_i$, we have\r\n    \\begin{align*}\r\n        f_{Z_1,\\ldots,Z_n}(z_1,\\ldots,z_n)&=f_{Y_1,\\ldots,Y_n}(y_1,\\ldots,y_n)|J|\\\\\r\n        &=n!e^{-\\lambda y_1}\\cdots e^{-\\lambda y_n}\\\\\r\n        &=n!\\lambda^ne^{-\\lambda(nz_1+(n-1)z_2+\\cdots +2z_{n-1}+z_n)}\\\\\r\n        &=\\prod_{i=1}^n(n-i+1)\\lambda e^{-\\lambda(n-i+1)z_1}\r\n    \\end{align*}\r\n    So $(Z_1,\\ldots,Z_n)$ are independent exponentials with $Z_i\\sim\\operatorname{Exp}(\\lambda(n-i+1))$.\r\n\\end{example}", "meta": {"hexsha": "c1bfe9910ded1521e82e77b7d791bccc104be054", "size": 8809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/multi.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": "10/multi.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": "10/multi.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": 53.7134146341, "max_line_length": 197, "alphanum_fraction": 0.6232262459, "num_tokens": 3480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.6870444043792244}}
{"text": "\\lab{Algorithm}{Invertible Affine Transformations and Linear Systems}{Invertible Affine Transformations and Linear Systems}\n\\label{lab:ChangeBasis}\n\\objective{Understand how to apply various affine transformations to a set of vectors and how to solve linear systems.}\n\n\n\\section*{Basis}\nA \\emph{basis} for a vector space is a linearly independent set of vectors that spans the entire space. Given a basis, it is possible to express every vector in the space as a unique linear combination of the basis vectors (indeed, this property can be taken as the definition for a basis).\n\nBases themselves are not necessarily unique, however, and it can often be very useful to change the basis representation of vectors, both in theory and practice. Changing bases is an example of an important class of mappings known as \\emph{linear transformations}.\n\nIn finite dimensional vector spaces like $\\mathbb{R}^n$, any linear\ntransformation can be implemented as a single left matrix multiplication.\nIn other words, a mapping $T : \\mathbb{R}^n \\to \\mathbb{R}^n$ is linear if and only if there exists an $n \\times n$ matrix $A$ such that $T\\left(X\\right) = AX$ for all vectors $X \\in \\mathbb{R}^n$. If $A$ is the $n \\times n$ matrix representation of a linear transformation and $P$ is an $n \\times m$ matrix in $\\mathbb{R}^n$, then $AP$ is the matrix of transformed points.\n\nDifferent linear transformations can be represented by different types of matrices. In this lab we will take vectors in $\\mathbb{R}^2$ and apply various linear and affine transformations.\n\nWe have represented each point as a column of the array \\li{pts}.\nIt is also common to represent points as rows. In that case, the transformations described below can still be performed by transposing the arrays in the appropriate places.\n\n\\section*{Dilation}\nDilation, or scaling, is a type of linear transformation in which, from a geometrical perspective, points are stretched or compressed.\nThe matrix representation, $A$, of a dilation is a diagonal matrix. The values on the main diagonal indicate the amount of stretching in their respective directions.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{stretch.pdf}\n\\caption{An example of a dilation. The top image is the original image and the bottom image is the modified image. The figure was stretched by a factor of $1.5$ in all directions.}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that accepts an array of points and an array giving the stretching factors in each direction, and returns the dilated points. \n\nPlot the original points and their image under the transformation. This can be done with the following code:\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\n# Assume the arrays 'old' and 'new' have x values along the first row and y values along the second row.\n\nplt.subplot(2, 1, 1)\nplt.scatter(old[0], old[1])\nplt.axis('equal')\nplt.subplot(2, 1, 2)\nplt.scatter(new[0], new[1])\nplt.show()\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Rotation}\nRotating points around the origin is another type of linear transformation. To perform a rotation of $\\theta$ radians counterclockwise, let\n\\[\nA = \\begin{pmatrix}\n\\cos(\\theta) & -\\sin(\\theta) \\\\\n\\sin(\\theta) & \\cos(\\theta)\n\\end{pmatrix}\n\\]\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{rotate.pdf}\n\\caption{An example of a rotation.\nThe top image is the original and the bottom is the rotated image.\nThe rotation angle is $\\frac{\\pi}{3}$.}\n\\label{basis:rotate}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that accepts an array of points and the angle of rotation (in radians). Have it return the rotated points.\nPlot the original points and their image under the transformation.\n\\end{problem}\n\n\\section*{Shear}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{shear.pdf}\n\\caption{An example of a shear.\nThe top image is the original and the bottom is the sheared image.}\n\\label{basis:shear}\n\\end{figure}\n\nA shear is a linear transformation that displaces a vector in a fixed direction. In $\\mathbb{R}^2$, a shear can either be horizontal or vertical, and has one of the two following forms, respectively:\n\n\\[\nA = \\begin{pmatrix}\n1 & c \\\\\n0 & 1\n\\end{pmatrix}\n\\]\n\n\\[\nA = \\begin{pmatrix}\n1 & 0 \\\\\nc & 1\n\\end{pmatrix},\n\\]\n\nwhere $c$ indicates the amount of displacement.  \n\nNote that these shearing matrices are instances of a type III elementary matrix. Horizontal shears leave the y-coordinates fixed, while vertical shears leave the x-coordinate fixed. \n\n\\begin{comment}\nIn physics, shears are examples of what are known as Galilean Transformations, and are used to switch between reference frames that differ only by constant relative motion.\n\\end{comment}\n\n\\begin{problem}\nWrite a function that accepts an array of points, a floating point argument that indicates the shearing amount, and an integer argument\nthat indicates the direction of shearing (0 for horizontal, 1 for vertical). Have it return the sheared points.\nPlot the original points and their image under the transformation.\n\\end{problem}\n\n\\section*{Reflection}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{reflect.pdf}\n\\caption{An example of a reflection. The top image is the original and the bottom is the image after being reflected about the line $y = \\sqrt{3}x$.}\n\\label{basis:reflect}\n\\end{figure}\n\nReflection about a line (or in higher-dimensional spaces, a hyperplane) can also be accomplished by a linear transformation. Such a transformation is called a \\emph{Householder Transformation}, and the general form of the matrix representation in\n$\\mathbb{R}^2$ is\n\n\\[\nA = \\frac{1}{l_1^2 + l_2^2}\n\\begin{pmatrix}\nl_1^2 - l_2^2 & 2l_1l_2 \\\\\n2l_1l_2 & l_2^2 - l_1^2\n\\end{pmatrix},\n\\]\n\nwhere $(l_1, l_2)$ is a vector in the direction of the axis of reflection. In the simple case where the axis of reflection is the line $y=x$, the matrix is just a Type I elementary matrix. See Figure \\ref{basis:reflection} for an example.\n\n\\begin{problem}\nWrite a function that accepts an array of points and an array giving the axis of reflection (in the notation above, this argument is $(l_1, l_2)$. Have it return the reflected points.\nPlot the original points and their image under the transformation.\n\\end{problem}\n\n\\section*{Translation}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{translate.pdf}\n\\caption{\nAn example of a translation.\nThe top image is the original and the bottom is the translated image.}\n\\label{basis:translate}\n\\end{figure}\n\nTranslations are not linear transformations, but they can easily be performed with array operations. Together, with linear transformations, they make up the broader class of transformations called\n``affine transformations.\" These are transformations of the form $T: \\mathbb{R}^n \\to \\mathbb{R}^n$, $T(X) = AX + b$ where $A$ is an $n\\times n$ matrix and $b \\in \\mathbb{R}^n$. Affine transformations include all compositions of scalings, rotations, and translations.\n\n\nLet $b$ be a vector that represents the desired translation.\nIn order to shift a set of points, you add to the row how much you would like it to shift in that direction. Thus, to shift the set of points up by 2, simply add \\li{b = np.array([[0], [2]])}. This particular shape for $b$ allows for proper array broadcasting.\nSee Figure \\ref{basis:translation} for an example.\n\n\\begin{problem}\nWrite a function that takes an array of points and an array indicating how much to shift them in each direction. The function should return the translated points.\nPlot the original points and their image under the transformation.\n\\end{problem}\n\n\\section*{Compositions of Transformations}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{combo.pdf}\n\\caption{\nA composition of affine transformations: shear, reflection, and translation.}\n\\label{basis:combo}\n\\end{figure}\n\nAll the various transformations we have discussed can be combined into a single affine transformation through function composition.\nFor example, if you want to apply a shear and then a reflection, you can represent the shear as a matrix $S$ and the reflection as a matrix $R$. The combined transformation is then $RS$. The image of $X$ under both transformations and then a translation that moves the origin to point $P$ would be $RSX+P$. An example of this is shown in Figure \\ref{basis:combo}.\n\n\\begin{problem}\nWe can use affine transforms to track the trajectory of a particle $p_1$ that rotates about another particle $p_2$ at a constant angular speed $\\omega$ (a positive value means counterclockwise rotation), while $p_2$ moves in a particular direction at a constant speed $v$. \n\nSuppose that $p_2$ has a starting position at the origin and moves in the direction of the vector $(1, 1)$, and suppose that $p_1$ has a starting position at the point $(0,1)$. Write a function that takes three parameters giving the time, angular velocity, and directional speed, respectively, and returns the position of $p_1$ at the given  time.\n\nVisualize a trajectory by plotting the position of the particle at each time (in seconds) in the array \\li{times = numpy.arange(0,10,.1)} for an angular velocity $\\pi$ radians per second and a directional speed of 3 meters per second (assume the plot is on a meters scale).\n\\end{problem}\n\n\\section*{Linear systems}\nMatrices are powerful for many reasons. Once such reason is that they can be used to represent linear systems of equations. This next section focuses on better ways to solve systems of linear equations by manipulating matrices.\n\n\\section*{Elementry row operations}\nIn linear algebra there are three elementary row operations on matrices: switching two rows, multiplying a row by a constant, and adding a multiple of one row to another row. Each of these operations can, in theory, be done through left multiplication by the appropriate elementary matrix. This approach is \\emph{extremely} slow in practice.\nIt is much faster to perform these operations directly by modifying only the portions of an array that change as a result of the row operation.\n\n\nThe following code shows how these modifications can be made in-place to an array.\n\\lstinputlisting[style=fromfile]{row_opers.py}\n\n\\section*{Programming Row Reduction}\nSolving a linear system can be done most efficiently by using elementary row operations to reduce a matrix to \\emph{row echelon form} (REF), as opposed to \\emph{reduced row echelon form} (RREF).\nConsider the following matrix:\n\n\\[\n\\begin{pmatrix}\n4&5&6&3 \\\\\n2&4&6&4 \\\\\n7&8&0&5\n\\end{pmatrix}\n\\]\n\nUsing elementary row operations, we can reduce $A$ to REF as follows:\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> A = np.array([[4., 5., 6., 3.],[2., 4., 6., 4.],[7., 8., 0., 5.]])\narray([[ 4.,  5.,  6.,  3.],\n       [ 2.,  4.,  6.,  4.],\n       [ 7.,  8.,  0.,  5.]])\n>>> A[1] -= (A[1,0]/A[0,0]) * A[0]\n>>> A[2] -= (A[2,0]/A[0,0]) * A[0]\n>>> A[2,1:] -= (A[2,1]/A[1,1]) * A[1,1:]\n>>> A\narray([[ 4. ,  5. ,  6. ,  3. ],\n       [ 0. ,  1.5,  3. ,  2.5],\n       [ 0. ,  0. , -9. ,  1. ]])\n\\end{lstlisting}\n\nThe additional requirement is often added that the first nonzero entry of each row be 1. Do not worry about that requirement here.\nNotice that in our third row operation we were able to operate on only a portion of the third row because we knew that the first value would still be 0. In this case it made little difference, but it is good to watch for things like this because they can save a great deal of time when working with larger matrices.\n\nA brief discussion of some potential pitfalls is in order.\nRound-off error can lead to serious numerical issues. Consider the\nfollowing variation on the above example.\n\n\\begin{lstlisting}\n>>> A = np.array([[4., 5., 6., 3.],[2., 2.5, 6., 4.],[7., 8., 0., 5.]])\narray([[ 4.,  5.,  6.,  3.],\n       [ 2.,  2.5,  6.,  4.],\n       [ 7.,  8.,  0.,  5.]])\n>>> A[1] -= (A[1,0]/A[0,0]) * A[0]\n>>> A[2] -= (A[2,0]/A[0,0]) * A[0]\n\\end{lstlisting}\n\nIf we work this out by hand, we should currently have\n\n\\[\n\\begin{pmatrix}\n4&5&6&3 \\\\\n0&0&3&2.5 \\\\\n0&-7.5&-10.5&-.25\n\\end{pmatrix}.\n\\]\n\nAll that is left is to swap the second and third rows, and the matrix is in row echelon form. However, suppose that due to numerical round-off error, the machine instead computes:\n\n\\[\n\\begin{pmatrix}\n4&5&6&3 \\\\\n0&10^{-15}&3&2.5 \\\\\n0&-7.5&-10.5&-.25\n\\end{pmatrix}.\n\\]\n\nThe algorithm would then attempt to pivot on the \\li{A[1,1]} entry:\n\n\\begin{lstlisting}\n>>> A[2,1:] -= (A[2,1]/A[1,1]) * A[1,1:]\n>>> A\narray([[ 4. ,  5.0e+00 , 6.00e+00 ,  3.000e-00 ],\n       [ 0. ,  1.0e-14 , 3.00e+00 ,  2.500e-00 ],\n       [ 0. ,  0.0e+00 , 2.25e+14 ,  1.875e+14 ]])\n\\end{lstlisting}\n\nThe round-off error in the \\li{A[1,1]} entry has affected the third\nrow, and the matrix is now much different than our first calculation. In larger matrices, such an error could potentially propagate through many steps in the calculation, resulting in garbage output.\n\nThis example also illustrates another issue to be aware of. Even if there were no round-off error in the \\li{A[1,1]} entry, a naive implementation of the algorithm might still attempt to pivot on that entry, which would result in division by zero. As noted above, we would first need to swap rows 2 and 3 in order to proceed. Dealing with leading zeros by permuting the rows is another consideration when designing a fool-proof REF solver.\n\n\\begin{problem}\n\\label{prob:REF}\nWrite a Python function which takes a matrix and reduces it to REF.\nAssume that the matrix is invertible and ignore the possibility that a zero may appear on the main diagonal during row reduction. You are not\nresponsible for dealing with potential round-off errors.\n\\end{problem}\n\n\\section*{LU Decomposition}\nLU Decomposition refers to a process for factoring a square matrix into the product of a lower triangular matrix and an upper triangular matrix. Such a factorization exists only for certain classes of matrices. In the case of an invertible $n \\times n$ matrix $A$, the LU decomposition exists if and only if all of the leading principle minors are non-zero (that is, all of the submatrices \\li{A[:k,:k]} for $k = 1,\\ldots,n-1$ are invertible). Even in this case, however, it may still be necessary to permute the rows of the matrix in order to prevent zeros from appearing on the main diagonal. Thus, row swap operations are, in general, necessary for the LU decomposition.\n\nUsing row reduction we can reduce the matrix $A$ to upper triangular form. Say this can be done in $k$ row operations.\nLet $U$ be the upper triangular form of $A$, so we have:\n\n\\[\nU = E_k \\dots E_2 E_1 A.\n\\]\n\nSince the elementary matrices are invertible, we also have\n\n\\[\n(E_k \\dots E_2 E_1)^{-1} U =  A.\n\\]\n\nThen we define $L$ to be\n\n\\[\nL = (E_k \\dots E_2 E_1)^{-1}\n\\]\n\nwhich is the same as\n\n\\[\nL = E_1^{-1} E_2^{-1} \\dots E_k^{-1}\n\\]\n\nIn either case we have $L U = A$.\n\nThe inverses of elementary matrices are also elementary matrices. Thus, $L$ can be computed by applying a series of simple operations to an identity matrix.\nNote when we are only doing type 3 row operations, each of the operations represented by right multiplication by these inverse matrices results in the change of a single entry in $L$.\n\nIn practice, the LU decomposition of an array $A$ can be computed like this:\n\n\\begin{itemize}\n\\item Make a copy, $U$, of $A$.\n\\item Make an identity matrix $L$ that is the same shape as $A$.\n\\item Iterate through the entries below the diagonal of $U$.\n\nNow for each entry below the main diagonal of $U$ do the following:\n\t\\begin{itemize}\n\t\\item Set the corresponding entry of $L$ to the quotient of the current entry of $U$ and the entry of the main diagonal of $U$ located above the current entry.\n\t\\item Perform the type 3 row operation to set the current entry of $U$ to 0.\n\t\tRemember to avoid computation involving columns that have already been processed.\n\t\\end{itemize}\n\\item Return $L$ and $U$\n\\end{itemize}\n\nIn this case, we have ignored the possibility that a 0 may appear along the main diagonal during computation. A full implementation of the LU decomposition would have to account for this possibility as well by swapping rows appropriately.\n\n\\section*{Why This Matters}\nThe LU decomposition is more efficient for solving linear systems than traditional row reduction and also allows for quick computation of inverses and determinants. For very large matrices, the LU decomposition can be performed without using any extra space as follows: $L$ is stored above the main diagonal of the array and $U$ is  stored below it.\nNote there is no need to store the main diagonal of $L$ since all its entries are ones.\n\n\\begin{problem}\n\\label{prob:LU}\nWrite a function takes in an $n\\times n$ matrix, performs the LU decomposition, and returns $L$ and $U$.\nTo verify that it works, multiply $L$ and $U$ together and compare to $A$.\nAssume that the matrix is invertible and ignore the possibility that a zero may appear on the main diagonal during row reduction.\n\nWrite another version of the function that modifies its input in place, storing $L$ below the main diagonal and $U$ in the rest of the array.\n\\end{problem}\n\nAs noted earlier, in general one needs to consider row-swapping when\ncalculating the LU decomposition. This means that it is not always possible to simply have\n\n\\[\nA = LU,\n\\]\nbut rather\n\n\\[\nPA = LU,\n\\]\n\nwhere $P$ is a permutation matrix representing the necessary row-swaps. Given such a decomposition, we can solve the linear system $Ax = b$ by\nfirst solving $Ly = Pb$ and then $Ux = y$. Since $L$ and $U$ are triangular, these systems can be solved easily with backward and forward substitution. We can use this technique to calculate $A^{-1}$ by solving the matrix equation $LUX = P$ column-by-column. Finally, we can calculate the determinant of $A$ via the formula\n\n\\[\n\\det(A) = (-1)^S\\left(\\displaystyle\\prod_{i=1}^nu_{ii}\\right),\n\\]\n\nwhere $S$ is the number of row-swaps.\n\nSciPy includes a complete implementation of the LU decomposition in the \\li{linalg} module. Furthermore, several other methods in the \\li{linalg} module are based on the LU decomposition, including \\li{linalg.solve}, \\li{linalg.inv}, and \\li{linalg.det}.\n\n\\begin{problem}\n\\label{prob:Solve}\nSuppose there is a need to solve the system $Ax = b$ for fixed $A$ and many different values of $b$. It would be unwise to perform row-reduction for every single new value of $b$, and the LU decomposition helps us avoid this and save time.\n\nCreate a random $1000 \\times 1000$ array $A$, and a random $1000 \\times 500$ array $B$. Use the \\li{scipy.linalg.lu_factor} function to compute the LU factorization of $A$. Then use the \\li{scipy.linalg.lu_solve} function to solve the system $AX = B$, and time this operation. \n\nNow use the \\li{scipy.linalg.inv} function to compute the inverse of $A$, and then use it to solve the system $AX = B$. Again time the operation. \n\n\\end{problem}\n\n%\\begin{problem}\n%\\label{prob:lusolve}\n%Write a function that takes the LU decomposition computed by the second function you made in Problem \\ref{prob:LU} and another array representing the right hand side of a linear system and modifies the second array in place so that it represents the solution to the linear system.\n%No changes to the array storing the LU decomposition are necessary.\n%\\end{problem}\n%\n\n\\begin{problem}\n\\label{prob:det}\nWrite a function which takes as input a square matrix $A$ and uses \\li{linalg.lu_factor} to find the determinant of $A$. Note that \\li{linalg.lu_factor} returns a square array \\li{lu} that contains $U$ in its upper triangle, as well as an array \\li{piv} that represents the \npermutation matrix $P$. Use \\li{piv} to compute the number of row swaps, and use the \\li{diagonal} method on \\li{lu} to compute the product of the diagonal terms, as needed in the formula for the determinant.\n\nHint: if the $i^{th}$ entry of \\li{piv} does not equal $i$, this means that a row swap occurred.\n\\end{problem}\n\n\\section*{The Cholesky Decomposition (Optional)}\n\nUnder certain conditions, the Cholesky decomposition offers a more efficient alternative to the LU decomposition.\nIt requires half the number of calculations and half the memory that the standard LU decomposition needs.\nFurthermore, it is a \\emph{numerically stable} decomposition, which means that round-off and truncation errors are kept suitably under control, rather than growing and propagating throughout the computation.\nBecause of the efficiency and numerical stability, Cholesky decomposition is used in solving least squares, optimization, and state estimation problems.\nThe Cholesky decomposition, however, is only applicable to Hermitian (for real matrices, this means symmetric) positive definite matrices.\nIt can be thought of as the matrix equivalent to taking the square root of a positive real number.\n\nThe Cholesky decomposition of a $A$ is a lower-triangular matrix, $L$, such that\n\n\\begin{equation*}\n A = LL^*\n\\end{equation*}\n\nWhere $L^*$ is the conjugate transpose of $L$.\nFor real valued matrices, this is equivalent to $L^T$.\n\nThe entries of $L$ are calculated as follows.\n\n\\begin{align*}\n&L_{i,j} = \\frac{1}{L_{j,j}}\\left(A_{i,j} -\\sum_{k=1}^{j-1}{L_{i,k}L_{j,k}^*}\\right) \\mbox{ for $i>j$} \\\\ \\\\\n&L_{i,i} = \\sqrt{A_{i,i} - \\sum_{k=1}^{i-1}{L_{i,k}L_{i,k}^*}}\n\\end{align*}\n\nwhere $L^*$ denotes the conjugate transpose of $L$.\n\nNotice that in this computation, current calculation will depend on previous calculations. To calculate $L$ properly, you must start in the upper left corner and iterate down.\n\nNote: when testing positive definite systems, an easy way to generate a random symmetric positive definite matrix is by generating a random array \\li{A} and then computing \\li{A.dot(A.T)}.\n\n\\begin{problem}\nWrite your own implementation of the Cholesky decomposition.\nTest it using a random symmetric matrix (build a random square matrix $A$, then $A^TA$ will be positive definite).\nCheck the output of your function to ensure that it is functioning properly.\n\\end{problem}\n\n%\\begin{problem}\n%Modify your previous answer so that it computes the Cholesky decomposition by modifying the array in place.\n%Make sure you set the portion of the array above the main diagonal to 0.\n%Then write a function that takes this reduced form of the array and uses it to solve a linear system by back substitution.\n%This should be nearly the same as Problem \\ref{prob:lusolve}.\n%\\end{problem}\n\nThe linalg module of SciPy also includes a Cholesky decomposition that should be much faster than the one you just implemented. It works much like the LU decomposition, providing the methods \\li{cho_factor} and \\li{cho_solve}.\n\n\\begin{problem}\nRepeat the steps in problem \\ref{prob:loopSolve}, this time using the\nCholesky decomposition. Make sure the input matrix to be factored is\npositive definite.\n\\end{problem} \n", "meta": {"hexsha": "af0914619681bedd0ef44d38483465cd097509ee", "size": 22645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/ChangeBasis/AffineTransformations.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/ChangeBasis/AffineTransformations.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/ChangeBasis/AffineTransformations.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": 51.700913242, "max_line_length": 673, "alphanum_fraction": 0.7473172886, "num_tokens": 5950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634457, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6870443958473111}}
{"text": "\n\\begin{tabular}{lcll}\\hline\nVariate    & $x$         & \\ccode{double} &  $\\mu \\leq x < \\infty$ \\\\\nLocation   & $\\mu$       & \\ccode{double} &  $-\\infty < \\mu < \\infty$\\\\\nScale      & $\\lambda$   & \\ccode{double} &  $\\lambda > 0$ \\\\\nShape      & $\\tau$      & \\ccode{double} &  $\\tau > 0$ \\\\ \\hline\n\\end{tabular}\n\nThe probability density function (PDF) is:\n\n\\begin{equation}\nP(X=x) =  \\frac{\\lambda^{\\tau}}{\\Gamma(\\tau)}  (x-\\mu)^{\\tau-1}  e^{-\\lambda (x - \\mu)}\n\\label{eqn:gamma_pdf}\n\\end{equation}\n\nThe cumulative distribution function (CDF) does not have an analytical\nexpression. It is calculated numerically, using the incomplete Gamma\nfunction (\\ccode{esl\\_stats\\_IncompleteGamma()}).\n\nThe ``standard Gamma distribution'' has $\\mu = 0$, $\\lambda = 1$.\n\n\\subsection{Sampling}\n\n\n\n\\subsection{Parameter estimation}\n\n\\subsubsection{Complete data; known location}\n\nWe usually know the location $\\mu$. It is often 0, or in the case of\nfitting a gamma density to a right tail, we know the threshold $\\mu$\nat which we truncated the tail.\n\nGiven a complete dataset of $N$ observed samples $x_i$ ($i=1..N$) and\na \\emph{known} location parameter $\\mu$, maximum likelihood estimation\nof $\\lambda$ and $\\tau$ is performed by first solving this rootfinding\nequation for $\\hat{\\tau}$ by binary search:\n\n\\begin{equation}\n  \\log \\hat{\\tau} \n  - \\Psi(\\hat{\\tau}) \n  - \\log \\left[ \\frac{1}{N} \\sum_{i=1}^{N} (x_i - \\mu) \\right]\n  + \\frac{1}{N} \\sum_{i=1}^N \\log (x_i - \\mu)\n\\label{eqn:gamma_tau_root}\n\\end{equation}\n\nthen using that to obtain $\\hat{\\lambda}$:\n\n\\begin{equation}\n\\hat{\\lambda} = \\frac{N \\hat{\\tau}} {\\sum_{i=1}^{N} (x_i - \\mu)}\n\\end{equation}\n\nEquation~\\ref{eqn:gamma_tau_root} decreases as $\\tau$ increases.\n", "meta": {"hexsha": "89900001eadf69a6092a7e4f9015a69c67adb4e3", "size": 1711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hmmer-3.3/easel/esl_gamma.tex", "max_stars_repo_name": "WooMichael/Project_Mendel", "max_stars_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hmmer-3.3/easel/esl_gamma.tex", "max_issues_repo_name": "WooMichael/Project_Mendel", "max_issues_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hmmer-3.3/easel/esl_gamma.tex", "max_forks_repo_name": "WooMichael/Project_Mendel", "max_forks_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6851851852, "max_line_length": 87, "alphanum_fraction": 0.6516656926, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6870266054168125}}
{"text": "\\chapter{Generating Function}\n\\label{chapter:generating-functions}\nIn this chapter we discuss the basics of one of the most general methods we have\nin combinatorics, the method is called ``generating functions''. The core idea\nof this method is to use knowledge we have about mathematical analysis in\ncombinatorics.\n\n\\section{Easy Two Term Recurrences}\nLet us start from the following problem.\nSasha took an insane credit in a bank: he took $100$\\$ at the beginning and\nhis debt is growing twofold every year. At the beginning of each year John is\npaying $100$\\$ to the bank. How big will be his debt in 5 years?\n\nIt is easy to see that the answer for this and similar questions can be answered\nusing a recurrence relation. Indeed, if $a_i$ denotes his debt on $i$th year,\nthen $a_0 = 100$, and $a_{n + 1} = 2 a_n - 100$. Using this, one may compute\nall the values of $a_i$. However, the question became tricky if we want to\nfind an explicit formula for $a_i$.\n\nTo solve this kind of questions we can use beforementioned generating functions.\n\\begin{definition}\n  Let $\\set{c_n}_{n \\ge 0}$ be a sequence of real numbers. Then\n  the generating function for this sequence is the power series\n  $F(x) = \\sum_{n \\ge 0} c_n x^n$.\n\\end{definition}\nNote that these power series may not converge for $x \\neq 0$.\nIn this chapter, we will not discuss this problem and always pretend that\nthey are converging, for a formal explanation of how to deal with this issue see\nAppendix~\\ref{chapter:formal-power-series}.\n\nLet us use the definition of $a_i$ to find the generating function $G(x)$\nfor this sequence. Note that\n$a_{n + 1} x^{n + 1} = 2 a_n x^{n + 1} - 100 x^{n + 1}$. Thus\n\\[\n  \\sum_{n \\ge 0} a_{n + 1} x^{n + 1} =\n    \\sum_{n \\ge 0} 2 a_n x^{n + 1} - 100 \\sum_{n \\ge 0} x^{n + 1}.\n\\]\nThe left-hand side is equal to $G(x) - a_0$ and the right-hand side is\nequal to $2xG(x) - \\frac{100 x}{1 - x}$. So we can derive the equality\n\\[\n  G(x) - 100 = 2xG(x) - \\frac{100 x}{1 - x}.\n\\]\nUsing this equality we can find explicitly a formula for $G(x)$,\n\\[\n  G(x) = \\frac{100}{1 - 2x} - \\frac{100x}{(1 - x)(1 - 2x)}.\n\\]\nLet us simplify the formula a bit.\n\\[\n  G(x) = \\frac{100}{1 - 2x} + \\frac{100}{1 - x} - \\frac{100}{1 - 2x} =\n  \\frac{100}{1 - x}.\n\\]\nThus $G(x) = \\sum_{n \\ge 0} 100 x^n$. As a result, $a_n = 100$.\n\n\\begin{exercise}\n  Find a formula for $a_n$ in the case when $a_0 = 200$.\n\\end{exercise}\n\nLet us consider another, more complicated, example. Consider a sequence\n$\\set{a_n}_{n \\ge 0}$ such that $a_{n + 1} = 2a_n + n$ for $n \\ge 0$ and\n$a_0 = 1$. As in the previous case let us write an equation for the\ngenerating function $G(x)$.\n\\[\n  G(x) - a_0 = 2xG(x) + \\sum_{n \\ge 0} n x^{n + 1}.\n\\]\nFirst, we find a formula for $\\sum_{n \\ge 0} n x^n$,\n\\[\n  \\sum_{n \\ge 0} n x^{n + 1} = \\sum_{n \\ge 0} x^2 \\cdot \\frac{d x^n}{dx} =\n  x^2 \\cdot \\frac{d \\sum_{n \\ge 0} x^n}{dx} = x^2 \\left(\\frac{1}{1 - x}\\right)'\n  = \\frac{x^2}{(1 - x)^2}.\n\\]\nTherefore,\n\\[\n  G(x) = \\frac{1 - 2x + 2x^2}{(1 - x)^2 (1 - 2x)}.\n\\]\nSo we need to find a more appropriate formula for $G(x)$.\nLet us try to find a formula in the form\n\\[\n  \\frac{1 - 2x + 2x^2}{(1 - x)^2 (1 - 2x)} =\n    \\frac{A}{(1 - x)^2} + \\frac{B}{1 - x} + \\frac{C}{1 - 2x}.\n\\]\nTo find $A$, $B$, and $C$ we multiply both sides by $(1 - x)^2$ and set $x = 1$.\nWe get that $A = -1$. We can also multiply by $1 - 2x$ and substitute\n$x = 1 / 2$ and derive that $C = 2$. Now we need to find $B$, we substitute $x =\n0$ to the equation and get $B = 0$. As a result,\n$G(x) = \\frac{-1}{(1 - x)^2} + \\frac{2}{1 - 2x}$. Using simple equalities from\ncalculus we can derive $G(x) = \\sum_{n \\ge 0} -(n + 1) + 2^{n + 1} x^n$.\nSo $a_n = -(n + 1) 2^{n + 1}$.\n\n\\section{Recurrences With Two Variables}\nTo illustrate how to deal with recurrence relations in cases when we have\nmore than one variable, we prove a version of the binomial theorem and\nderive a formula for binomial coefficients. In order to do it,\nwe consider the recurrence relation\n\\[\n  \\binom{n + 1}{k} = \\binom{n}{k} + \\binom{n}{k - 1}.\n\\]\nLet us denote $\\sum_{k \\ge 0} \\binom{n}{k} x^k$ by $B_n(x)$.\nIt is clear that\n\\[\n  B_{n + 1}(x) - 1 = (B_n(x) - 1) + x B_n(x).\n\\]\nTherefore, $B_{n + 1}(x) = (1 + x) B_n(x)$. As a result, $B_n(x) = (1 + x)^n$;\ni.e. $\\sum_{k \\ge 0} \\binom{n}{k} x^k = (1 + x)^n$. To find a\nformula for binomial coefficients, we just need to use Taylor's formula,\n$\\binom{n}{k} = \\frac{d^k}{dx^k} B_n(x)\\big\\rvert_{x = 0}  / k!$. So\n$\\binom{n}{k} = n (n - 1) \\dots (n - k + 1) / k!$.\n\n\\section{Products of Generating Functions}\nLet us consider a new problem, how many ways to design a class consisting of\n$n$ lectures with theoretical part and laboratory part (the first $k$ days of\nthe quarter form the theoretical part, note that $k$ is not fixed) such that\nthere are two midterms during the theoretical part and one exam during the\nlaboratory part.\n\nLet $a_n$ be the answer. It is easy to see that\n\\[\n  a_n = \\sum_{k = 1}^{n - 2} k \\binom{n - k}{2}.\n\\]\nHowever, this formula does not suggest an explicit formula.\nLet us write an equation for the generating function for $a_n$,\n\\[\n  G(x) = \\sum_{n \\ge 0} \\sum_{k = 1}^{n - 2} k \\binom{n - k}{2} x^n.\n\\]\nIt is easy to see that this formula implies that\n\\[\n  G(x) = \\left( \\sum_{k \\ge 0} k x^k \\right)\n    \\left( \\sum_{k' \\ge 0} \\binom{k'}{2} x^{k'} \\right).\n\\]\nThus\n\\[\n  G(x) = \\frac{x}{(1 - x)^2} \\cdot \\frac{x^2}{(1 - x)^3} =\n  \\frac{x^4}{(1 - x)^5} = x^3\\sum_{n \\ge 0} \\binom{n + 4}{4} x^n.\n\\]\nAs a result, $a_n = \\binom{n + 1}{4}$.\n\nUsing this example, we can formulate a general rule.\n\\begin{theorem}\n  Let $a_n$ be the number of ways to build a certain structure on an $n$-element\n  set, and let $b_n$ be the number of way to build another structure on an\n  $n$-element set. Let $c_n$ be the number of ways to separate $[n]$ into two\n  parts consisting of numbers $\\set{1, \\dots, k}$ and $\\set{k + 1, \\dots, n}$\n  ($k \\ge 0$), and then to build a structure of the first type on the first set,\n  and a structure of the second type on the second set.\n\n  Then $H(x) = F(x)G(x)$, where $F(x)$, $G(x)$, and $H(x)$ are generating\n  functions for $\\set{a_n}_{n \\ge 0}$, $\\set{b_n}_{n \\ge 0}$, and\n  $\\set{c_n}_{n \\ge 0}$, respectively.\n\\end{theorem}\n\nTo illustrate this theorem, let us solve another problem. A company\n``bolshoy brat'' needs to finish two projects. To do this, a manager of the\ncompany splits all the employees into two projects and in each project she selects\nproduct team and marketing team. How many ways to do this.\nLet $c_n$ be the number of ways the manager can complete this task. Again, let\nus split the problem into two parts. Let $A(x)$ be the generating function for\nthe number of ways to split people in the first project into marketing and\nproduct teams. It is clear that $A(x) = \\sum_{k \\ge 0} 2^k x^k = 1 / (1 - 2x)$\nsince any $k$ element set has $2^k$ subsets. It is easy to see that the second\nproject has the same generating function. Thus the generating function for\n$\\set{c_n}_{n \\ge 0}$, $C(x) = A(x) A(x) = 1 / (1 - 2x)^2$.\nAs a result,\n\\[\n  C(x) = \\frac{1}{2} \\sum_{n \\ge 1} n 2^n x^{n - 1} =\n  \\frac{1}{2} \\sum_{n \\ge 0} (n + 1) 2^{n + 1} x^n\n\\]\nand $c_n = (n + 1) 2^{n + 1}$.\n\n\\begin{exercise}\n  Find the number of ways to split an $n$-day semester into three parts, choose\n  any number of holidays in the first part, an odd number of holidays in the\n  second part, and an even number of holidays in the third part.\n\\end{exercise}\n\n\\section{Compositions of Generating Functions}\nAs usual, we start the section from a problem.\nAll $n$ soldiers of a military squadron stand in a line. The officer in charge\nsplits the line at several places, forming (non-empty) squads. Then she names\none person in each unit to be the commander of that unit. Let $c_n$ be the\nnumber of ways she can do this. Find an explicit formula for $c_n$.\n\nIf the officer splits the soldiers into $k$ squads, then there\nare\n\\[\n  \\sum_{n_1, \\dots, n_k : n = n_1 + \\dots + n_k} n_1 \\cdot n_2 \\dots n_2\n\\]\nways to do this. Hence, the generating function for splitting into squads and\nselecting commanders in all $k$ squads is equal to $A^k(x)$, where\n$A(x) = \\sum_{n \\ge 0} n x^n = \\frac{x}{(1 - x)^2}$. Therefore,\nthe generating function $C(x)$ for $\\set{c_n}_{n \\ge 0}$ is equal to\n$\\sum_{k \\ge 1} A^k(x)$. As a result,\n\\[\n  C(x) = \\frac{1}{1 - A(x)} = 1 + \\frac{x}{1 - 3x + x^2}.\n\\]\nIt is possible to note that the roots $\\alpha$ and $\\beta$ of $x^2 - 3x + 1$ are\nequal to $(3 \\pm \\sqrt{5}) / 2$, respectively. We want to find $A$ and $B$ such\nthat\n\\[\n  \\frac{1}{1 - 3x + x^2} = \\frac{A}{x - \\alpha} - \\frac{B}{x - \\beta}.\n\\]\nThus $1 = (A - B) x - A\\beta + B\\alpha$. Therefore, we have\n$A = B$ and $A(\\alpha - \\beta) = A\\sqrt{5} = 1$; i.e.\n$A = B = \\frac{1}{\\sqrt{5}}$.\nBy some simple calculations we may conclude that\n\\[\n  \\frac{1}{1 - 3x + x^2} =\n  \\frac{1}{\\sqrt{5}}(\\frac{\\alpha}{1 - \\alpha x} - \\frac{\\beta}{1 - \\beta x}).\n\\]\nTherefore\n$C(x) = 1 + \\frac{1}{\\sqrt{5}}\n  \\sum_{n \\ge 0} (\\alpha^{n + 1} - \\beta^{n + 1}) x^{n + 1}$.\nHence, $c_0 = 1$ and $c_n = \\frac{1}{\\sqrt{5}}(\\alpha^n - \\beta^n)$ for $n > 0$.\n\nThe following theorem generalises this observation.\n\\begin{theorem}\n  Let $a_n$ be the number of ways to build a certain structure on an $n$-element\n  set, and let us assume that $a_0 = 0$. Let $c_n$ be the number of ways to\n  split the set $[n]$ into an unspecified number of disjoint non-empty\n  intervals, then build a structure of the given type on each of these\n  intervals. Set $h_0 = 1$. Denote $F(x) = \\sum_{n \\ge 0} a_n x^n$ and\n  $G(x) = \\sum_{n \\ge 0} c_n x^n$. Then $G(x) = \\frac{1}{1 - A(x)}$.\n\\end{theorem}\n\n\\begin{chapterendexercises}\n  \\exercise[recommended] Find the generating functions of each of the following sequences\n    (in the simplest form):\n    \\begin{enumerate}[nolistsep]\n      \\begin{multicols}{2}\n        \\item $a_n = n$;\n        \\item $a_n = \\alpha n + \\beta$;\n        \\item $a_n = n^2$;\n        \\item $a_n = \\alpha n^2 + \\beta n + \\gamma$;\n        \\item $a_n = 3^n$.\n      \\end{multicols}\n    \\end{enumerate}\n  \\exercise[recommended] Let $F(x)$ be a generating function for the sequence\n    $\\set{a_n}_{n \\ge 0}$. Write, in terms of $F(x)$, the generating functions\n    of the following sequences:\n    \\begin{enumerate}[nolistsep]\n      \\begin{multicols}{2}\n        \\item $\\set{a_n + \\alpha}_{n \\ge 0}$;\n        \\item $\\set{\\alpha a_n + \\beta}_{n \\ge 0}$;\n        \\item $\\set{n a_n}_{n \\ge 0}$;\n        \\item $0$, $a_1$, \\dots, $a_n$, \\dots;\n        \\item $a_1$, \\dots, $a_n$, \\dots;\n        \\item $\\set{a_{n + m}}_{n \\ge 0}$ ($m$ is a constant).\n      \\end{multicols}\n    \\end{enumerate}\n  \\exercise Let $k$ be a positive integer. Find an explicit formula for the\n    generating function for the sequence $\\set{\\binom{n}{k}}_{n \\ge 0}$.\n    \\begin{solution}\n      Let us consider a generating function $F(x) = \\sum_{n \\ge 0} x^n$. Note that\n      $F^{(k)}(x) = \\sum_{n \\ge k} n (n - 1) (n - 2) \\dots (n - k + 1) x^{n - k}$.\n      Therefore, $\\frac{x^k}{k!} F^{(k)}(x) = \\sum_{n \\ge 0} \\binom{n}{k} x^n$. It\n      is also easy to see that $F^{(k)}(x) = \\frac{k!}{(1 - x)^{k + 1}}$. As a\n      result, $\\sum_{n \\ge 0} \\binom{n}{k} x^n = \\frac{x^k}{(1 - x)^{k + 1}}$.\n    \\end{solution}\n  \\exercise Let $f(n)$ be the number of subsets of $\\range{n}$ that contain no two\n    consecutive elements, for integer $n$. Find the recurrence that is satisfied\n    by these numbers, and then find an explicit formula for these numbers.\n  \\exercise Find an explicit formula for $a_n$ if $a_0 = 0$ and for any\n    $n \\ge 0$, $a_{n + 1} = a_n + 2^n$.\n  \\exercise[recommended] Let $a_n$ be the number of ways to pay $n$ dollars using ten-dollar\n    bills, five-dollar bills, and one-dollar bills only. Find the generating\n    function for $a_n$.\n  \\exercise[recommended] Let $x_1$ and $x_2$ be two different solutions of the equation\n    $1 - bx - cx^2 = 0$. Show that a sequence $\\set{f_n}_{n \\ge}$ satisfies the\n    recurrence relation $f_{n + 2} = b f_{n + 1} + c f_n$ iff\n    $t_n = \\alpha x_1^{-n} + \\beta x_2^{-n}$ for some $\\alpha, \\beta \\in \\R$.\n  \\exercise[recommended] Let $\\set{a_n}_{n \\ge 0}$, $\\set{b_n}_{n \\ge 0}$ be two sequences\n    such that $b_n = \\sum_{k = 0}^n a_n$ and $F(x)$ be the generating function\n    for $\\set{a_n}_{n \\ge 0}$. Find the generating function for\n    $\\set{b_n}_{n \\ge 0}$ in terms of $F(x)$.\n  \\exercise Let $\\set{a_n}_{n \\ge 0}$, $\\set{b_n}_{n \\ge 0}$ be two sequences\n    such that $b_n = a_{2n}$ and $F(x)$ be the generating function\n    for $\\set{a_n}_{n \\ge 0}$. Find the generating function for\n    $\\set{b_n}_{n \\ge 0}$ in terms of $F(x)$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "4b40a320ab8c6250d9568f5a75754a632c47c6e9", "size": 12613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_23_generating_functions.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_4/chapter_23_generating_functions.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_4/chapter_23_generating_functions.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": 45.3705035971, "max_line_length": 92, "alphanum_fraction": 0.6296678031, "num_tokens": 4579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8807970795424088, "lm_q1q2_score": 0.6870154686076307}}
{"text": "%!TEX root = ./writeup.tex\n\n\\subsection{Diamond Difference Discrete Ordinates}\n\tThe \\gls{dd} \\SN equations corresponding to Eq. \\ref{eq:sn} are \n\t\t\\begin{equation} \\label{eq:dd}\n\t\t\t\\frac{\\mu_n}{h_i}\\left(\\psi_{n,i+1/2} - \\psi_{n,i-1/2}\\right)\n\t\t\t\t+ \\Sigma_{t,i} \\psi_{n,i} = \\frac{\\Sigma_{s,i}}{2}\\sum_{n'=1}^N \\psi_{n',i}w_{n'}\n\t\t\t\t+ \\frac{Q_i}{2} , \\ 1 \\leq n \\leq N, \\ 1 \\leq i \\leq I\n\t\t\\end{equation}\n\twhere $\\psi_{n,i\\pm1/2} = \\psi_n(x_{i\\pm1/2})$ is the cell edge angular flux and $\\Sigma_{t,i} = \\Sigma_t(x_i)$, $\\Sigma_{s,i} = \\Sigma_s(x_i)$ and $Q_i = Q(x_i)$ the cell averaged total cross section, scattering cross section and fixed source. The $x_{i\\pm1/2}$ are the cell edge locations of cell $i$ of cell width $h = x_{i+1/2} - x_{i-1/2}$. In DD, the cell centered angular flux is taken to be the average of the adjacent cell edge angular fluxes: \n\t\t\\begin{equation} \\label{eq:auxDD}\n\t\t\t\\psi_{n,i} = \\frac{1}{2} \\left(\\psi_{n,i+1/2} + \\psi_{n,i-1/2}\\right).\n\t\t\\end{equation}\n\tUsing this result for the scattering term yields\n\t\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\t\t\\frac{\\Sigma_{s,i}}{2}\\sum_{n'=1}^N \\psi_{n',i}w_{n'} &= \n\t\t\t\\frac{\\Sigma_{s,i}}{2}\\sum_{n'=1}^N \n\t\t\t\t\\frac{1}{2} \\left(\\psi_{n,i+1/2} + \\psi_{n,i-1/2}\\right) w_{n'} \\\\\n\t\t\t&= \\frac{\\Sigma_{s,i}}{4} \\left(\\phi_{i-1/2} + \\phi_{i+1/2}\\right)\n\t\t\\end{aligned}\n\t\t\\end{equation}\n\tIn SI, the scattering term is lagged: \n\t\t\\begin{equation} \\label{eq:DDSN}\n\t\t\t\\frac{\\mu_n}{h_i}\\left(\\psi_{n,i+1/2}^{\\ell+1} - \\psi_{n,i-1/2}^{\\ell+1}\\right)\n\t\t\t\t+ \\Sigma_{t,i} \\psi_{n,i}^{\\ell+1} = \n\t\t\t\t\\frac{\\Sigma_{s,i}}{4} \\left(\\phi_{i-1/2}^\\ell + \\phi_{i+1/2}^\\ell\\right)\n\t\t\t\t+ \\frac{Q_i}{2}, \\ \n\t\t\t1 \\leq n \\leq N, \\ 1 \\leq i \\leq I\n\t\t\\end{equation}\n\tSolving for $\\psi_{n,j\\pm1/2}^{\\ell+1}$ yields  \n\t\t\\begin{subequations}\n\t\t\t\\begin{equation} \\label{eq:psiplus}\n\t\t\t\t\\psi_{n,i+1/2}^{\\ell+1} = \n\t\t\t\t\\frac{\n\t\t\t\t\\frac{\\Sigma_s}{2}h_i \\left(\\phi_{i-1/2}^\\ell + \\phi_{i+1/2}^\\ell\\right)\n\t\t\t\t+ Q_i h_i - \\left(\\Sigma_t h_i - 2\\mu_n\\right) \\psi_{n,i-1/2}^{\\ell+1}\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\\Sigma_t h_i + 2\\mu_n \n\t\t\t\t}, \\ \\mu_n > 0 \n\t\t\t\\end{equation}\n\t\t\t\\begin{equation} \\label{eq:psiminus}\n\t\t\t\t\\psi_{n,i-1/2}^{\\ell+1} = \n\t\t\t\t\\frac{\n\t\t\t\t\\frac{\\Sigma_s}{2}h_i \\left(\\phi_{i-1/2}^\\ell + \\phi_{i+1/2}^\\ell\\right)\n\t\t\t\t+ Q_i h_i - \n\t\t\t\t\t\\left(\\Sigma_t h_i - 2|\\mu_n|\\right) \\psi_{n,i+1/2}^{\\ell+1}\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\\Sigma_t h_i + 2|\\mu_n| \n\t\t\t\t}, \\ \\mu_n < 0 \n\t\t\t\\end{equation}\n\t\t\\end{subequations}\n\tEquation \\ref{eq:psiplus} specifies the flux exiting the right side of cell $i$ given the flux that entered through the left side while Eq. \\ref{eq:psiminus} specifies the flux exiting the left side of cell $i$ given the flux that entered through the right side. \n\n\tBy specifying boundary conditions for $\\psi_{n,1/2}^{\\ell+1}$ for $\\mu_n>0$ and $\\psi_{n,I+1/2}^{\\ell+1}$ for $\\mu<0$, Eqs. \\ref{eq:psiplus} and \\ref{eq:psiminus} can be solved non-iteratively. The boundary conditions for a vacuum left boundary and reflecting right boundary are \n\t\t\\begin{subequations}\n\t\t\\begin{equation} \\label{eq:leftBC}\n\t\t\t\\psi_{n,1/2}^{\\ell+1} = 0, \\ \\mu_n > 0\n\t\t\\end{equation}\n\t\t\\begin{equation} \\label{eq:rightBC}\n\t\t\t\\psi_{n,I+1/2}^{\\ell+1} = \\psi_{m,I+1/2}^{\\ell+1}, \\ \\mu_n = -\\mu_m.\n\t\t\\end{equation}\n\t\t\\end{subequations}\n\n\tUsing Eq. \\ref{eq:leftBC}, the flux exiting the right side of cell $i=1$, $\\psi_{n,3/2}^{\\ell+1}$, can be found through Eq. \\ref{eq:psiplus}. This exiting flux is then the flux entering cell $i=2$ allowing for the determination of $\\psi_{n,5/2}^{\\ell+1}$. This process of using the result from the previous cell is repeated until $i=I$. At this point all rightward ($\\mu>0$) moving flux has been determined for all cells $1 \\leq i \\leq I$. \n\n\tThe reflecting boundary condition, Eq. \\ref{eq:rightBC}, can now be applied. This sets the incoming flux on the right side of cell $i=I$. Equation \\ref{eq:psiminus} then determines the exiting flux through the left side, $\\psi_{n,I-1/2}^{\\ell+1}$. Working backward from cell $i=I$, $\\psi_{n,I-3/2}^{\\ell+1}, \\psi_{n,I-5/2}, \\dots, \\psi_{n,1/2}^{\\ell+1}$ for $\\mu_n < 0$ can be found. \n\n\tThis process of propagating the solution from left to right for $\\mu_n > 0$ and then from right to left for $\\mu_n < 0$ is known as a transport sweep. At the end of the sweep, new cell edge scalar flux values $\\phi_{i\\pm1/2}^{\\ell+1}$ are generated through \n\t\t\\begin{equation}\n\t\t\t\\phi_{i\\pm1/2}^{\\ell+1} = \\sum_{n=1}^N \\psi_{n,i\\pm1/2}^{\\ell+1} w_n. \n\t\t\\end{equation}\n\tA new sweep is then conducted using $\\phi_{i\\pm1/2}^{\\ell+1}$. This process is repeated until the stop criterion of \n\t\t\\begin{equation}\n\t\t\t\\frac{\n\t\t\t\\sum_{i=0}^{I} \\left(\\phi_{i+1/2}^{\\ell+1} - \\phi_{i+1/2}^\\ell\\right)^2\n\t\t\t}{\n\t\t\t\\sum_{i=0}^{I} \\left(\\phi_{i+1/2}^{\\ell+1}\\right)^2\n\t\t\t}\n\t\t\t< \\epsilon\n\t\t\\end{equation}\n\tis met. ", "meta": {"hexsha": "fb6974d7389c9f4504f579fd64a36ebed24e6e96", "size": 4773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/writeup/DD.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/DD.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/DD.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": 56.8214285714, "max_line_length": 454, "alphanum_fraction": 0.6272784412, "num_tokens": 1986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6869645426678932}}
{"text": "\\chapter{Random variables (TO DO)}\n\\todo{write chapter}\nHaving properly developed the Lebesgue measure\nand the integral on it,\nwe can now proceed to develop random variables.\n\n\\section{Random variables}\nWith all this set-up, random variables are going to be really quick to define.\n\\begin{definition}\n\tA (real) \\vocab{random variable} $X$ on a probability space\n\t$\\Omega = (\\Omega, \\SA, \\mu)$\n\tis a measurable function $X \\colon \\Omega \\to \\RR$,\n\twhere $\\RR$ is equipped with the Borel $\\sigma$-algebra.\n\\end{definition}\nIn particular, addition of random variables, etc.\\\nall makes sense, as we can just add.\nAlso, we can integrate $X$ over $\\Omega$, by previous chapter.\n\n\\begin{definition}\n\t[First properties of random variables]\n\tGiven a random variable $X$,\n\tthe \\vocab{expected value} of $X$ is defined by\n\tthe Lebesgue integral\n\t\\[ \\EE[X] = \\int_{\\Omega} X(\\omega) \\; d\\mu. \\]\n\tConfusingly, the letter $\\mu$ is often used for expected values.\n\n\tThe \\vocab{$k$th moment} of $X$ is defined as $\\EE[X^k]$,\n\tfor each positive integer $k \\ge 1$.\n\tThe \\vocab{variance} of $X$ is then defined as\n\t\\[ \\Var(X) = \\EE\\left[ (X-\\EE[X])^2 \\right]. \\]\n\\end{definition}\n\\begin{ques}\n\tShow that $\\mathbf{1}_A$ is a random variable\n\t(just check that it is Borel measurable),\n\tand its expected value is $\\mu(A)$.\n\\end{ques}\n\nAn important property of expected value you probably already know:\n\\begin{theorem}\n\t[Linearity of expectation]\n\tIf $X$ and $Y$ are random variables on $\\Omega$ then\n\t\\[ \\EE[X+Y] = \\EE[X] + \\EE[Y]. \\]\n\\end{theorem}\n\\begin{proof}\n\t$\\EE[X+Y] = \\int_\\Omega X(\\omega) + Y(\\omega) \\; d\\mu\n\t= \\int_\\Omega X(\\omega) \\; d\\mu + \\int_\\Omega Y(\\omega) \\; d\\mu\n\t= \\EE[X] + \\EE[Y]$.\n\\end{proof}\nNote that $X$ and $Y$ do not have to be ``independent'' here:\na notion we will define shortly.\n\n\\section{Distribution functions}\n\n\\section{Examples of random variables}\n\n\\section{Characteristic functions}\n\n\\section{Independent random variables}\n\n\\section{\\problemhead}\n\\begin{problem}\n\t[Equidistribution]\n\tLet $X_1$, $X_2$, \\dots be i.i.d.\\ uniform random variables on $[0,1]$.\n\tShow that almost surely the $X_i$ are equidistributed,\n\tmeaning that\n\t\\[ \\lim_{N \\to \\infty} \\frac{ \\# \\{1 \\le i \\le N \\mid a \\le X_i(\\omega) \\le b \\}}{N}\n\t\t= b-a \\qquad \\forall 0 \\le a < b \\le 1 \\]\n\tholds for almost all choices of $\\omega$.\n\\end{problem}\n\n\\begin{problem}\n\t[Side length of triangle independent from median]\n\tLet $X_1$, $Y_1$, $X_2$, $Y_2$, $X_3$, $Y_3$\n\tbe six independent standard Gaussians.\n\tDefine triangle $ABC$ in the Cartesian plane\n\tby $A = (X_1,Y_1)$, $B = (X_2,Y_2)$, $C = (X_3,Y_3)$.\n\tProve that the length of side $BC$\n\tis independent from the length of the $A$-median.\n\\end{problem}\n\n% 18.175 has some other good pset problems that could go here\n", "meta": {"hexsha": "ec038af7fd7d6db792c2fcb1b99068598da279a9", "size": 2748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/measure/randvar.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/randvar.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/randvar.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": 33.512195122, "max_line_length": 85, "alphanum_fraction": 0.6863173217, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6869645405761333}}
{"text": "\\newpage\n\\part{Unsupervised Learning}\n\\section{Clustering}\n\\begin{itemize}\n\t\\item Definition: given a database $D = {t_1, \\dots, t_n}$ of tuples and an integer value $k$, define a mappping $f: D \\rightarrow {1, \\dots, k}$ where each tuple $t_i$ is assigned to a cluster $K_j$.\n\t\\item Input: a dataset with $n$ p-dimensional data instances.\n\t\n\tOutput: a \\textbf{natural partitioning} of the dataset into $k$ clusters and noise\n\t\\item Clustering VS. Classification\n\t\\begin{table}[H]\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{|l|p {0.3\\linewidth}|p {0.35\\linewidth}|}\n\t\t\t\t\\hline\n\t\t\t\tCharacteristics        & \\textbf{Classification}  & \\textbf{Clustering}   \\\\ \\hline\n\t\t\t\tLearning     & supervised  & unsupervised \\\\ \\hline\n\t\t\t\tTarget       & known & unknown, no dependent variables \\\\ \\hline\n\t\t\t\tTraining  \t & training data and training phase exists  & no training data/training phase, no labels/true classes  \\\\ \\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\t\n\t\\end{table}\n\t\\item key questions: \n\t\\begin{itemize}\n\t\t\\item the right number of clusters k\n\t\t\\item identification of class membership between instances\n\t\\end{itemize}\n\t\\item Issues:\n\t\\begin{itemize}\n\t\t\\item interpreting results\n\t\t\\item evaluating results: high intra-similarity within cluster, low inter-similarity across cluster? \n\t\t\\item outlier\n\t\t\\item number of clusters k\n\t\t\\item scalability of algorithms\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Hierarchical Clustering : Minimum Spanning Tree}\n\\begin{itemize}\n\t\\item Input: a database D with tuples, \\textbf{adjacency matrix} based on distances\n\t\n\tOutput: \\textbf{dendogram}\n\t\\item Methods of building a dendogram: \n\t\\begin{itemize}\n\t\t\\item top-down\n\t\t\\item bottom-up\n\t\\end{itemize}\n\t\\item Algorithms: with adjacency matrix, \\textbf{each instance} can be seen as \\textbf{node}, \\textbf{distance} to other instances can be seen as \\textbf{weighted edges} \n\t\n\t$\\rightarrow$ graph problem\n\t\n\t$\\rightarrow$ compute \\textbf{Minimum Spanning Tree}, bottom-up method.\n\t\\begin{itemize}\n\t\t\\item Kruskal's algorithm: $\\mathcal{O}(d\\log(d))$\n\t\t\\item Prim's algorithm: $\\mathcal{O}(d\\log(n))$\n\t\\end{itemize}\n\t$\\rightarrow$ each hierarchical level shares the same distance/weight.\n\t\n\t\\item Distance measures in adjacency matrix:\n\t\\begin{itemize}\n\t\t\\item \\textbf{Euclidean distance} between instance $p_1$ and $p_2$\n\t\t$$d_E(p_1,p_2) = \\sqrt{(x_{p1} - x_{p2})^2 + (y_{p1} - y_{p2})^2 +\\dots }$$\n\t\t\\item \\textbf{Manhattan distance} between instance $p_1$ and $p_2$\n\t\t$$d_M(p_1,p_2) = |x_{p1} - x_{p2}| + |y_{p1} - y_{p2}| + \\dots$$\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Partitional Clustering for Numeric Data: K-Means}\n\\begin{itemize}\n\t\\item Input: \n\t\\begin{itemize}\n\t\t\\item a database D with tuples\n\t\t\\item $k$ number of clusters\n\t\\end{itemize}\n\t \n\tOutput: k partitioned clusters\n\t\\item Process:\n\t\\begin{itemize}\n\t\t\\item Initialization: randomly picked k centers\n\t\t\\item compute the distance between each instance to the centers, assign instance to the \\textbf{nearest center}.\n\t\t\\item \\textbf{update} the center of the clusters: \\textbf{mean of assigned instances}\n\t\t\\item repeat step 2-3 until convergence.\n\t\\end{itemize}\n\n\t\\item Advantages:\n\t\\begin{itemize}\n\t\t\\item simple\n\t\t\\item items automatically assigned to clusters\n\t\\end{itemize}\n\tDisadvantages:\n\t\\begin{itemize}\n\t\t\\item number of clusters $k$ must be predefined\n\t\t\\item result significantly depends on \\textbf{initial choice of centers} \n\t\t\n\t\t$\\rightarrow$ traps in \\textbf{local minimum} \n\t\t\n\t\t$\\rightarrow$ repeat algorithm by starting from different random centers (eg: Iterative Improvement)\n\t\t\\item sensitive to \\textbf{outliers}\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Probabilistic Clustering: Expectation Maximization}\nWe only discuss the simplified case here: instance with single \\textbf{numeric} attribute and 2 clusters A \\& B.\n\\begin{itemize}\n\t\\item Input: random assigned parameters for cluster A \\& B, assume \\textbf{normal distribution}\n\t\\begin{itemize}\n\t\t\\item A: $\\mu_A, \\sigma_A$, prior probability of instance in cluster A $Pr(A)$\n\t\t\\item B: $\\mu_B, \\sigma_B$, prior probability of instance in cluster B $Pr(B) = 1 - Pr(A)$\n\t\\end{itemize}\n\tOutput: 2 clusters with assigned instances\n\t\n\t\\item Process:\n\t\\begin{itemize}\n\t\t\\item \\textbf{Expectation} step: calculate the probability for \\textbf{all instances} in \\textbf{each cluster}: \\textbf{Bayes Theorem}\n\t\t\t$$Pr(A|x) = \\frac{Pr(x|A) \\cdot Pr(A)}{Pr(x)} ,\\quad Pr(x|A) = \\frac{1}{\\sqrt{2\\pi} \\cdot \\sigma_A} e^{-\\frac{(x - \\mu_A)^2}{2\\sigma_A^2}}$$\n\t\t\t$$Pr(B|x) = \\frac{Pr(x|B) \\cdot Pr(B)}{Pr(x)} ,\\quad Pr(x|B) = \\frac{1}{\\sqrt{2\\pi} \\cdot \\sigma_B} e^{-\\frac{(x - \\mu_B)^2}{2\\sigma_B^2}}$$\n\t\t\\textbf{no need to pick cluster here!}\n\t\t\\item \\textbf{Maximization} step: update the parameters for cluster A \\& B. calculate the weighted mean and weighted variance using \\textbf{all instances}. \n\t\t$$w_{iA} = Pr(A|x), \\quad  w_{iB} = Pr(B|x)$$\n\t\t$$\\mu_A = \\frac{w_{1A}x_1 + w_{2A}x_2 + \\dots + w_{nA}x_n}{w_{1A} + w_{2A} + \\dots + w_{nA}}$$\n\t\t$$\\sigma_A = \\sqrt{\\frac{w_{1A} (x_1 - \\mu_A)^2 + \\dots + w_{nA} (x_n - \\mu_A)^2}{w_{1A} + w_{2A} + \\dots + w_{nA}}}$$\n\t\tanalog to $\\mu_B$ and $\\sigma_B$\n\t\t\n\t\t$$Pr(A) = \\frac{\\Sigma w_A}{\\Sigma w_A + \\Sigma w_B}, \\quad Pr(B) = 1 - Pr(A)$$\n\t\t\\item repeat expectation and maximization step until convergence.\n\t\\end{itemize}\n\t\\item Limitation: can stuck in \\textbf{local optimum}. \n\t\n\t$\\rightarrow$ repeat algorithm by starting with \\textbf{different initial parameters}.\n\t\n\t\\item Extension of model:\n\t\\begin{itemize}\n\t\t\\item multiple clusters: calculate k normal distributions\n\t\t\\item multiple attributes: \n\t\t\\begin{itemize}\n\t\t\t\\item independent: multiply probabilities of all attributes\n\t\t\t\\item correlated: multivariate normal distribution\n\t\t\\end{itemize}\n\t\t\\item nominal attributes: create probability distribution\n\t\\end{itemize}\n\\end{itemize}", "meta": {"hexsha": "c3475e7bc7091931ba5a5b5e87cf220658281685", "size": 5810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/clustering.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/clustering.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/clustering.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": 41.7985611511, "max_line_length": 201, "alphanum_fraction": 0.7048192771, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6869645384843732}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{verbatim}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{enumitem}\n\\usepackage{amsmath,amssymb}\n\\usepackage{bm}\n\\usepackage{stmaryrd}\n\\title{Understanding Reflux}\n\\author{B. Runnels and V. Agrawal}\n\\begin{document}\n\\maketitle\n\\setlength\\parindent{0pt}\n\\def\\flux{\\operatorname{Flux}}\n\\def\\Int{\\operatorname{int}}\n\n\n\\section{Interpretation as integral of flux jump}\nLet $\\Omega\\subset\\mathbb{R}^n$ be the problem domain, and let $A:C^2(\\Omega)\\to C^0(\\Omega)$ be a linear operator.\nIn the implementation of \\texttt{amrex::MLNodeLaplacian}, $A$ has the form\n\\begin{align}\n  A[\\phi](\\bm{x}) = \\nabla\\cdot\\bm{\\sigma}(\\bm{x})\\nabla\\phi, \n\\end{align}\nwhere $\\bm{\\sigma}:\\Omega\\to\\mathbb{R}^{n\\times n}$ is a coefficient matrix\\footnote{Appears to be implemented in \\texttt{amrex} as a vector, corresponding to a diagonal matrix}.\nThe corresponding {\\it flux} of the operator $\\bm{f}_A:C^1(\\Omega)\\to C^0(\\Omega,\\mathbb{R}^n)$ is\n\\begin{align}\n  \\bm{f}_A[\\phi](\\bm{x}) = \\bm{\\sigma}(\\bm{x})\\nabla\\phi\n\\end{align}\nThe pointwise residual is defined as \n\\begin{align}\n  r(\\bm{x}) = b(\\bm{x}) - A[\\phi](\\bm{x})\n\\end{align}\nwhere $b:\\Omega\\to\\mathbb{R}$ is the right hand side.\nThe {\\it total residual} is the integral \n\\begin{align}\n  R = \\int_\\Omega r(\\bm{x})\\,d\\bm{x}\n\\end{align}\nLet $B\\subset\\Omega$ represent the {\\it refined region} and $\\Omega\\setminus B$ the {\\it coarse region}.\nBy nature of the discrete algorithm, we assume that $\\nabla\\phi$ is discontinuous over the boundary $\\partial B$.\n\\begin{align}\\label{eq:resorig}\n  R = \\int_\\Omega b(\\bm{x})\\,d\\bm{x} - \\int_{B} A[\\phi](\\bm{x})\\,d\\bm{x} - \\int_{\\Omega\\setminus B} A[\\phi](\\bm{x})\\,d\\bm{x}\n\\end{align}\nUsing the divergence theorem this reduces to\n\\begin{align}\n  R = \\int_\\Omega b(\\bm{x})\\,d\\bm{x} - \\int_{\\partial \\Omega} \\bm{n}\\cdot\\bm{f}_A[\\phi](\\bm{x})\\,d\\bm{x} - \\int_{\\partial B} \\bm{n}\\cdot\\bm{f}^{B}_A[\\phi](\\bm{x})\\,d\\bm{x} + \\int_{\\partial B} \\bm{n}\\cdot\\bm{f}^{\\Omega\\setminus B}_A[\\phi](\\bm{x})\\,d\\bm{x}\n\\end{align}\nwhere $\\bm{n}$ is the outward-facing normal for $B$.\nThe superscripts on $\\bm{f}$ indicate where the flux is computed: $\\bm{f}_A^{B}$ is evaluated on $B$, $\\bm{f}_A^{\\Omega\\setminus B}$ on $\\Omega\\setminus B$.\nThis is alternatively expressed using jump-bracket notation,\n\\begin{align}\n  R = \n  \\int_\\Omega b(\\bm{x})\\,d\\bm{x} \n  - \\int_{\\partial \\Omega} \\bm{n}\\cdot\\bm{f}_A[\\phi](\\bm{x})\\,d\\bm{x}\n  - \\int_{\\partial B} \\bm{n}\\cdot\\Big\\llbracket\\bm{f}_A[\\phi](\\bm{x})\\Big\\rrbracket\\,d\\bm{x}.\n\\end{align}\nAn additional application of the divergence theorem to the second term yelds the result\n\\begin{align}\\label{eq:rhscfreflux}\n  R = \n  \\underbrace{\\int_\\Omega b(\\bm{x})\\,d\\bm{x} }_{\\text{r.h.s.}}\n  - \\underbrace{\\int_{\\Int(\\Omega\\setminus B)} A[\\phi](\\bm{x})\\,d\\bm{x}}_{\\text{coarse}}\n  - \\underbrace{\\int_{\\Int(B)} A[\\phi](\\bm{x})\\,d\\bm{x}}_{\\text{fine}}\n  - \\underbrace{\\int_{\\partial B} \\bm{n}\\cdot\\Big\\llbracket\\bm{f}_A[\\phi](\\bm{x})\\Big\\rrbracket\\,d\\bm{x}}_{\\text{reflux}}.\n\\end{align}\nWe note that (\\ref{eq:rhscfreflux}) is nearly identical to (\\ref{eq:resorig}) except for the additional boundary integral. \nThis is the result of the discretization and subsequent loss of continuity at the boundary.\n\\begin{enumerate}\n\\item In the continuous case, the jump term $\\llbracket\\bm{f}_A\\rrbracket$ would be zero and would consequently vanish.\n  Including it explicitly accounts for the reflux contribution at the coarse/fine boundary.\n\\item Terms 2 and 3 are now over the {\\it interiors} of $\\Omega\\setminus B,B$.\n  This is a trivial distinction in the continuous case, but is meaningful in the discrete case as it indicates that the boundary nodes are not included in the coarse and fine contributions.\n\\end{enumerate}\n\n\n\\section{Multi-level stencil}\n\nConsider a multi-level stencil in which the solution on the coarse level is $pc$ and on the fine level is $pf$.\nWe wish to estimate the second derivative in the $x$ direction at coarse/fine boundary node $(i,j)$ using both coarse and fine nodes.\nWe assume that $pc(i,j) = pf(2i,2j)$.\n\n\\begin{center}\n  \\includegraphics{stencil1}\n\\end{center}\n\nWe first compute finite difference first derivatives on the coarse and fine levels, denoting them as $dpc,dpf$, respectively.\nThe values ``live'' half way between the two stencil points, as shown below:\n\n\\begin{center}\n  \\includegraphics{stencil2}\n\\end{center}\n\nThe coarse derivative is just\n\\begin{align}\n  pc = \\frac{pc(i,j) - pc(i-1,j)}{dxc}.\n\\end{align}\nThe fine derivative is a weighted average:\n\\begin{align}\n  pf = \n  \\frac{1}{2}\\frac{pf(2i+1,j) - pc(i,j)}{dxf}\n  + \\frac{1}{4}\\frac{pf(2i+1,j+1) - pc(i,j+1)}{dxf}\n  + \\frac{1}{4}\\frac{pf(2i+1,j-1) - pc(i,j-1)}{dxf}\n\\end{align}\nThen the second derivative at $(i,j)$ is computed by finite difference between the two first derivatives\n\\begin{align}\n  ddpc(i,j) = \\frac{pf - fc}{(dxf/2) + (dxc/2)}\n\\end{align}\nand lives at the coarse fine node\n\\begin{center}\n  \\includegraphics{stencil3}\n\\end{center}\nThe location of this node means that the derivative is a combination of central and backward differencing.\n\n\n\n\\end{document}\n\n\n", "meta": {"hexsha": "c47bb8e5c45dc8c799ab04331a534c2ca4b749fa", "size": 5121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/notes.tex", "max_stars_repo_name": "eschmid4/alamo", "max_stars_repo_head_hexsha": "9605292e1663d6997c6ce85b1b06fe003cddb05c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-08-01T10:46:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-25T00:12:57.000Z", "max_issues_repo_path": "notes/notes.tex", "max_issues_repo_name": "eschmid4/alamo", "max_issues_repo_head_hexsha": "9605292e1663d6997c6ce85b1b06fe003cddb05c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-05-06T21:34:55.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-10T16:58:33.000Z", "max_forks_repo_path": "notes/notes.tex", "max_forks_repo_name": "solidsgroup/alamo", "max_forks_repo_head_hexsha": "9605292e1663d6997c6ce85b1b06fe003cddb05c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-23T21:22:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-01T19:01:47.000Z", "avg_line_length": 43.7692307692, "max_line_length": 254, "alphanum_fraction": 0.69771529, "num_tokens": 1749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631541, "lm_q2_score": 0.8633916187614823, "lm_q1q2_score": 0.6869645349942121}}
{"text": "\\chapter{Explorations in games on networks}\\label{ch:games-on-networks}\n\\section{Game theory}\n\\subsection{Prisoner's Dilemma}\\label{subs:prisoners-dilemma}\nThe Prisoner's Dilemma is the canonical game of game theory finding its use in models for everything from how firms price goods\\cite{p-d-goods} to sharing in vampire bats\\cite{p-d-nature}. 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\\\\\n%\\paragraph{The Story}\nThe motivating story goes that two accomplices are caught at a crime scene, arrested and placed in separate cells with no contact. The police give them each a choice: they can confess their crimes to the authorities or they can stay silent. They learn that if they both stay silent, they only get one year in prison. If they both confess, they both get two years. However, if one of them confesses and the other stays silent, the snitch gets out immediately while the snitched-upon gets 3 years. As they are in separate cells, they cannot communicate.\\\\\n\\\\\nThe smallest combined time in prison for the couple is if they both stay silent and take 1 year in jail each. But even if they could communicate and agree to the appealing option of both staying silent, it would still make sense to defect from the `contract' and confess. 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\\subsubsection{Making this mathematical}\n%\\paragraph{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.\\\\\n\\\\\nThe four essential elements of a game have a useful acronym: \\textit{PAPI}\\cite{rasmusen_2010}. This stands for:\n\\begin{enumerate}[nosep]\n\\item \\textbf{P}layers of the game,\n\\item \\textbf{A}ctions available to each player,\n\\item \\textbf{P}ayoffs for each outcome\n\\item \\textbf{I}nformation available to each player.\n\\end{enumerate}\n\\par\\null\\par\nIn our story, there are two players: Lou and Avery. There are two actions available to them: stay silent or confess.  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\\\\\nFormally, we call staying silent a decision to \\textit{cooperate} with the partner. We also say that to confess is to \\textit{defect} from their partner. We usually notate actions as a single letter. Here we write $C$ for cooperate and $D$ for defect. An \\textit{outcome} defines an action for each player. It can be written $(C,C)$ for two players both playing the action $C$.\\\\\n\\\\\n%\\subsubsection{Representing games}\n%\\subsubsection{Payoff Matrix}\nA payoff matrix is a way of defining two-player simultaneous games completely\\cite{osborne}. This means that 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\\centering\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\\\\\n\\\\\nThe 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. The players, actions and payoffs are defined. Also, in a simultaneous game there is no information available about the other player's action. So this matrix does indeed completely describe the game.\\\\\n\\\\\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\\\\\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{Strategies and solution concepts}\nA \\textit{strategy} is a set of rules that determine which action a player will use at each point of the game. Note that as the Prisoner's Dilemma has only one point to make a decision, a strategy determines just one action. Further a strategy profile determines a strategy for each player in the game. There are various ways to discuss the effectiveness of strategies and strategy profiles in a game.\\\\\n\\\\\n%\\subsubsection{Strategies}\n%\\paragraph{Socially Optimal Strategy}\nThe \\textit{socially optimal strategy profile} is the strategy profile that leads to the highest joint payoff for all players. That is, the sum of the payoffs is the highest of all possibilities. In this game this is the easily identifiable and clearly optimal option of both players cooperating so that they get only 1 year each.\\\\\n\\\\\n%\\paragraph{Nash Equilibrium}\nHowever, the outcome with both defecting is the \\textit{Nash Equilibrium}. Informally, the Nash Equilibrium is an outcome in which, even if all players knew almost telepathically what the other player's actions were going to be, none of them would choose to change their action as it would not improve their payoff. In this game, both players defecting, $(D,D)$, is the unique Nash Equilibrium. This is because if one player, say Lou, knew that Avery would play $D$ he would not change to $C$. Similarly for Avery.\\\\\n\\\\\n%\\paragraph{Dominant Strategy}\nThe outcome of $(D, D)$ actually satisfies an even stronger condition as the action $D$ is a \\textit{dominant strategy} for both players. This means that no matter what action the opponent plays, the player will always get the best payoff by defecting. This is how $(D,D)$ manages to `pull' players in, despite it having a worse payoff for both players than $(C,C)$.\\\\\n\\\\\nSo we have described three solution concepts. Which one do we predict will happen? Game theory assumes that players are \\textit{rational}. This means that the payoffs match the player's desires and they desire to increase their payoff. In other words the payoffs accurately describe their preferences. 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\\subsection{Repeated games}\\label{subs:repeated-games}\n%\\subsubsection{Introduction}\nThe Prisoner's Dilemma is a \\textit{one-shot game}. This means that no further games are played after the first game. It happens once and never again, with no possible repercussions that are not already described in the payoff matrix.\\\\\n\\\\\nUnlike one-shot games, repeated games have players play multiple games against each other. Whereas before a strategy determined just one action, in a repeated game a strategy can respond to the other player's actions. 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.\n\\subsubsection{Iterated Prisoner's Dilemma}\nIf we have two players playing the Prisoner's Dilemma repeatedly against each other we create the Iterated Prisoner's Dilemma. This no longer has a best strategy.\\\\\n\\\\\nIn the absence of an analytically provable `best' strategy, we can pursue a more empirical approach. In football we cannot prove a-priori the best team. Indeed it would be a bit boring if we could. Instead, we create a tournament such as the Premier League and declare the winner of the tournament the `best' team. Inspired by this approach, we create a `tournament' of different strategies all playing several hundred games of the Prisoner's Dilemma against each other. The winner of the tournament will be the strategy with the highest payoff overall.\\\\\n\\\\\nThis 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 opponent's previous move forever after. Since then other researchers have repeated the tournament and Axelrod himself ran a second tournament with many more entries. A recent open-source collaboration makes it easy to replicate the Axelrod's original tournament as well as run similar ones\\cite{axelrod-github}.\\\\\n\\\\\nFor the tournament, we choose to enter five strategies: Tit for Tat, Defector, Cooperator, Alternator and Random. The names are descriptive: Defector always defects, Cooperator always cooperates, Alternator alternates between the two and Random chooses between the two actions with probability $0.5$ at each point. They play against every other strategy $10$ times. They also play against themselves $10$ times. The payoffs are also altered to fit Axelrod's first tournament. They are given by $1$ for two defectors, $3$ for two cooperators and $5$ and $0$ for the defector and cooperator respectively.\\\\\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$ & $(3,3)$ & $(0,5)$ \\\\\\cline{3-4}\n\t& $D$ & $(5,0)$ & $(1,1)$ \\\\\\cline{3-4}\n\\end{tabular}\n\\label{mmd}\n\\\\\n\\\\\nRunning the tournament reveals that `Defector' does best in this tournament (Fig. \\ref{fig:iterated-p-d-tournament}). The key point is that there is no single strategy that dominates all the others. Whilst `Defector' does best in this tournament, with a different selection of strategies it probably would not. Indeed it was entered into Axelrod's first tournament and was beaten by Tit for Tat, a strategy it won against here. Whilst this may seem paradoxical it is no more paradoxical than a polar bear being better suited to Antarctica than a tiger but would struggle in Bali. That is, the strategies success is dependent on its environment. In it's extreme, a defector does well in a tournament full of unquestioning cooperators. However, in a tournament full of Tit For Tat strategies, the Tit for Tat strategies get consistently high payoffs through cooperation which the defector misses out on, instead getting the spoils of mutual defection.\\label{mmd}\n%\\textit{Mark: This seems paradoxical - what is it about the tournament design that makes this possible?}\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{axelrod/tournament-boxplot.png}\n\t\t\\caption{The results of a tournament of the Prisoner's Dilemma between 5 strategies. The tournament was repeated 100 times. Due to the strategy `Random' the results were different each time. The plot shows the average payoff between all tournaments in the solid blue line and the shaded blue region represents the variance.\n%\t\t\\textit{Mark: I don't understand this figure}\n\t\t\\label{mmd}\n\t\t}\n\t\t\\label{}\n\t\\end{subfigure}%\n\\\\\n\t\\begin{subfigure}{\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=0.95\\linewidth]{axelrod/tournament-payoff-matrix.png}\n\t\t\\caption{A payoff matrix showing how each strategy performed on average against the other strategies. The colour of the point $(X,Y)$ represents the score of strategy $X$ playing against strategy $Y$.}\n\t\t\\label{}\n\t\\end{subfigure}\n\t\\caption{A tournament of the Iterated Prisoner's Dilemma between five strategies.}\n\t\\label{fig:iterated-p-d-tournament}\n\\end{figure}\\\\\n\\\\\nWe can create a grand competition with 222 different strategies. The strategies comprise every entry from a library of distinct strategies submitted to the Axelrod-Python project team\\cite{axelrod-github}.\\label{mmd} On this run the joint winners were: `Hard Prober', `Pun1' and `Tester'. For example Hard Prober's strategy is to play $D,D,C,C$ initially. This is to act as a test to see how cooperative its opponent is. If the opponent cooperated in moves 2 and 3, Hard Prober will defect forever. Otherwise, it will play Tit-For-Tat for the rest of time. The results of the tournament are messy to see as a plot, payoff matrix or indeed a table of the raw data. However, the alphabetically first 5 strategies are shown in Fig. \\ref{fig:222}.\n%\\begin{tabular}{1|1}\n%\t\\csvreader[head to column names]{images/csv/axelrod-tournament-222.csv}{}\n%\t{\\\\\\hline\\csvcoli&\\csvcolii}\n%\\end{tabular}\n\\begin{figure}\n\\csvautotabular{../data/axelrod-tournament-222-short.csv}\n\\caption{A table of the alphabetically first 5 strategies in an iterated Prisoners Dilemma tournament of 222 different strategies.}\n\\label{fig:222}\n\\end{figure}\n\\subsubsection{Iterated games with evolution}\nOne natural extension to iterated games is to allow the possibility of `evolutionary' behaviour. For example, we can create simulations where strategies with higher payoffs are more likely to produce `offspring'. This means that the number of players using a successful strategy tends to increase.\\\\\n\\\\\nThis can be imagined in the ordinary evolutionary sense of survival of the fittest. However, there is another useful interpretation. We can view the population as a constant group of players who are open to the possibility of changing their strategies. If they see a strategy that is working better, there is some probability that they use that strategy in the next iteration.\\\\\n\\\\\nWe randomly select $7$ players using strategies from Axelrod's tournament. We play them off each other and themselves. After each round, they have some chance of `reproducing' proportional to the payoff they just received from playing every other player. Then the next round has a population that tends to have more of the successful strategies and less of the poorly adapted strategies. A graph describing this is given in Fig. \\ref{fig:moran-100}.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\linewidth,trim={0 0 0 2cm},clip]{axelrod/iterated-moran-7.png}\n\t\\caption{A graph showing an evolutionary prisoner's dilemma tournament.\\label{mmd}. At each iteration or tick one agent is chosen to reproduce and one agent is chosen to die. The probability that they are chosen to reproduce is proportional to their payoff in the previous round.}\n\t\\label{fig:moran-100}\n\\end{figure}\n\\\\\n\\\\\n%[Include replicator equations at some point here.]\\\\\n%For example, we can also try it with different gamesbelow is a simulation of strategies playing Rock, Paper Scissors defined by the payoff matrix as above.\\\\\n%(\n%My simulation of Rock, Paper, Scissors\n%)\\\\\n%The 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.\\\\\n%The same scenario works with the admittedly less well-known game Rock, Paper, Scissors, Spock\\cite{for game}\\cite{for code}.\\\\\n%(\n%My simulation of Rock, Paper Scissors, Spock\n%)\\\\\n%However, now with the different rules we can have the extinction of strategies.\nWe can explore the same evolutionary set-up but with the game of Rock, Paper, Scissors. Whereas evolutionary Prisoner's Dilemma resulted in one strategy eventually monopolising the population, the evolution of Rock, Paper, Scissors results in a self-balancing system (Fig. \\ref{rock-paper-scissors-evo}). For example if the strategy Rock becomes more populous, Paper will start to get higher payoffs on average. This gives Paper a higher chance of reproducing resulting in Paper reproducing at a quicker rate. This holds for all three pairs. So the population has an inbuilt tendency to return the population demographic back towards $\\frac{1}{3}$ for each strategy.\\label{mmd}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{axelrod/rock-paper-scissors.png}\n\t\\caption{An evolutionary game of Rock, Paper, Scissors. The graph shows the percentage of players changing through time.}\n\t\\label{rock-paper-scissors-evo}\n\\end{figure}\n\\section{Graph theory}\\label{sec:graph-theory}\n%motivation\nThe tools we have built so far are helping us move closer to a reasonable description of real, complex situations. In real life, games are not usually isolated situations that happen as if in a laboratory. They happen around lots of other players and allow the possibility of a change of strategy. They are also interdependent with games in some places effecting others. If a person was playing the Prisoner's Dilemma and played against several defectors consecutively, they are more likely to defect themselves. We have begun to model this.\\\\\n\\\\\nHowever, players are in general not connected to every other player. They exist in communities. To model this we need graphs.\\\\\n\\\\\n\\subsection{Definitions}\nA \\textit{graph} $G=(V,E)$ is a set of vertices $V$ and a set of pairs of vertices $E$. Each pair of vertices is called an edge. For now we will consider only undirected graphs with no loops . \\textit{Undirected} means that the edge $(u,v)$ is identical to the edge $(v,u)$. That is to say, the pairs constituting the edges are unordered\\cite{graph-theory-reference}. The requirement of no loops means that no vertex has an edge from itself to itself. Formally, $\\nexists v\\textnormal{ such that } (v,v)\\in E$. We can see visually what this means in Fig. \\ref{fig:example-graphs}.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/graph-theory/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]{appendix/graph-theory/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]{appendix/graph-theory/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:example-graphs}\n\\end{figure}\n\\\\\n\\\\\nTwo vertices $u,v$ are \\textit{adjacent} if and only if $(u,v)\\in E$. The neighbourhood of a vertex $v$ in a graph $G$ is the induced graph given by $v$ and all vertices adjacent to $v$. That is, it is the graph of vertex $v$ and all vertices adjacent to $v$ with edges given by the edges between any of these vertices in $G$. As such we also call the adjacent vertices \\textit{neighbours}.\\\\\n\\\\\n%Some common graphs\nA useful graph that comes up repeatedly is the \\textit{complete graph, $K_n$}. This is the graph with $n$ vertices with an edge between all pairs of vertices. Formally $K_n=\\{\\{v_1,...,v_n\\},\\{(v_i,v_j):\\forall i\\neq j\\}\\}$.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/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]{appendix/games-on-networks/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\\subsection{Graphs and the 2D lattice}\nA graph often used in models is an adaptation of the 2D lattice as it is both instructive, relatively easy to analyse and most importantly easy to visualise\\cite{eq_of_life}. The 2D lattice can be made by imagining a square grid, rows and columns of squares.\n%\\begin{figure}\n%\t\\centering\n%\t\\includegraphics[width=.5\\linewidth]{appendix/graph-theory/square-grid.png}\n%\t\\caption{A square grid}\n%\\end{figure}\nHowever, we want to convert this into a graph. We can deal with the vertices easily: we put a vertex at the centre of each square. However there are multiple ways to define the edges. Which squares should be considered neighbours of each other?\\\\\n\\\\\nOne option is to define the von Neumann neighbourhood of the 2D lattice as in Fig. \\ref{fig:vonneumann}. This makes each point a neighbour of the $4$ points vertically and horizontally next to it. An alternative is given by the Moore neighbourhood as seen in Fig. \\ref{fig:moore}. This includes the nearest vertical and horizontal neighbours as well as the nearest diagonal points\\cite{eq_of_life}.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/graph-theory/von-neumann-neighbourhood.png}\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]{appendix/graph-theory/moore-neighbourhood.png}\n\t\t\\caption{The Moore neighbourhood}\n\t\t\\label{fig:moore}\n\t\\end{subfigure}\n\t\\caption{Different definitions of `neighbourhood' on the 2D Lattice}\n\t\\label{fig: lattice neighbourhoods}\n\\end{figure}\\\\\n\\\\\nThe graphs given by these two definitions are given in Fig. \\ref{fig:graph-neighbourhoods}. The graph induced by the von Neumann neighbourhood is often called the grid graph, lattice graph. The graph induced by the Moore neighbourhood is also called the King's Graph as it represents the legal moves of a king in a game of chess.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{appendix/graph-theory/grid-graph.png}\n\t\t\\caption{}\n\t\t\\label{fig:graph-v-n}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{appendix/graph-theory/kings-graph.png}\n\t\t\\caption{}\n\t\t\\label{fig:graph-m}\n\t\\end{subfigure}\n\t\\caption{Graph representation of the 2D lattice with the von Neumann neighbourhood\\ref{fig:graph-v-n} and the Moore neighbourhood \\ref{fig:graph-m}}\n\t\\label{fig:graph-neighbourhoods}\n\\end{figure}\\\\\n\\\\\nTypically to avoid boundary effects when playing games on these lattices we `wrap' the 2D lattice. This creates a torus. So each vertex displayed visually at the top of the lattice is joined to the neighbour in the same column at the bottom of the lattice. This avoids, for example, the side players having fewer opponents. However it makes it harder to visualise explicitly and so is normally drawn in two-dimensions with no visual representation of the wrapping.\n\\section{Games on networks}\n%\\subsubsection{Games on graphs we have already seen}\nHaving further built up our tool-kit, we can now consider games on graphs. We set each vertex to represent a player and only allow players to play a game against players they are adjacent to. In fact, we have sneakily been doing this the whole time but now we want to make this explicit.\\\\\n\\\\\nThe basic Prisoner's Dilemma in \\ref{subs:prisoners-dilemma} was a game on a trivial graph $G=(\\{Lou,Avery\\},\\{(Lou,Avery)\\})$, visualised in Fig. \\ref{fig:p-d-graph}.\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\t\\label{fig:p-d-graph}\n\\end{figure}\nSimilarly, for the Iterated Prisoner's dilemma tournament if we call the players $p_1,...,p_n$, the tournament was a repeated game on a complete graph $K_n$.\\\\\n\\\\\n%\\subsubsection{Some new Graphs}\nSo we were already playing games on graphs implicitly. Now we can try building games while noting the graphs we are playing on explicitly and seeing what effect this has.\n\\subsection{Prisoner's Dilemma on a torus}\\label{p-d-torus}\n%\\subsubsection{Set-up}\nWe can extend the Iterated Prisoner's Dilemma to a tournament on a 2D lattice. Firstly, we make an $n \\times n$ grid with wrapped ends to avoid boundary effects, creating a torus. Using the process seen in the previous section we make a graph out of this using the Moore neighbourhood. Then we let each vertex be a player of the Prisoner's Dilemma. They play against all other vertices in their neighbourhood\\cite{eq_of_life}.\\\\\n\\\\\nTo initialise the system, in the first round each player plays $C$ with probability $p$ and $D$ with probability $(1-p)$. They play this action simultaneously against every neighbour, using the same strategy against each of them.\\\\\n\\\\\nFor every round after, each player looks at their neighbour's scores from the previous round. They adopt the action of the highest scoring neighbour as their action for the next round\\footnote{For most parameter values chosen, ties are only possible between cells that use the same strategies and so this is well-defined. If there were to be a tie between two distinct strategies, the strategy adopted would arbitrarily be the strategy closest to the top left of the grid.}\\label{mmd} They then play this action against every neighbour.\\\\\n\\\\\nThe payoff matrix retains characteristics of the matrix originally given for the 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}{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)$ & $(\\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%\\subsubsection{Example Runs}\nTo run this we simulate on a $100\\times100$ grid and choose values $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$. Note that $b$ is the payoff from defecting against a cooperative partner. Intuitively, it is the reward to true villains who defect against players who were hoping to cooperate.\n\\subsubsection{Qualitative analysis: equilibrium and chaos}\nFor $b>1.\\bar{6}$, the board eventually tends to an equilibrium with mostly defectors (Fig. \\ref{fig:p-d-torus-1.7}). Clearly the rewards of non-cooperation are too high to a sustain a more socially beneficial situation.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/1b=17.png}\n\t\t\\caption{Early}\n\t\t\\label{}\n\t\\end{subfigure}%\n%\t\\begin{subfigure}{.3\\textwidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/2b=17.png}\n%\t\t\\caption{Developing}\n%\t\t\\label{}\n%\t\\end{subfigure}\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/appendix/games-on-networks/pd-torus/3b=17.png}\n\t\t\\caption{Equilibrium}\n\t\t\\label{}\n\t\\end{subfigure}\n\t\\caption{The simulation running with $b=1.7$}\n\t\\label{fig:p-d-torus-1.7}\n\\end{figure}\nConversely, for $b<1.6$, the simulation tends towards a static equilibrium of mainly cooperators (Fig. \\ref{fig:p-d-torus-1.5}).\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/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]{appendix/games-on-networks/pd-torus/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]{appendix/games-on-networks/pd-torus/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:p-d-torus-1.5}\n\\end{figure}\nBetween these two parameter regions, exists the third which exhibits the most interesting behaviour with chaotic dynamics between cooperation and defection (Fig. \\ref{fig:p-d-torus-1.63}).\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/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]{appendix/games-on-networks/pd-torus/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]{appendix/games-on-networks/pd-torus/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:p-d-torus-1.63}\n\\end{figure}\n\\subsubsection{Quantitative analysis: invasion}\nThe usual approach for understanding evolutionary games is to find the conditions under which one type can `invade' a population. An invasion is when a small group of one type can grow in a population of other types. To do this with our game we must analyse the situation from the level of individual squares.\\\\\n\\\\\nFirstly, we need to find the minimal area that we can isolate to study. A single cell plays against it's surrounding neighbours and so we must consider at least the $3\\times3$ grid surrounding a cell. However, the cell then adopts the strategy of all of its best performing neighbours. So it must look at its neighbour's payoffs. But it's neighbours payoffs depend on the games \\textit{they} have just played against \\textit{their} neighbours. So, to know what strategy our single cell will adopt we have to consider the surrounding $5\\times5$ grid\\cite{eq_of_life}.\\\\\n\\\\\nWe will call the small population of potential invaders the \\textit{cluster} and the rest of the population the \\textit{sea}. Then we call the cells that are in the sea touching the cluster the \\textit{boundary}. The general strategy we have will be to look at the boundary separating the small cluster of invaders from the rest of the population. If the boundary cells have a neighbour in the cluster with a better tactic than their neighbours in the sea, they will change and the cluster will grow.\\\\\n\\\\\nLet's first consider the conditions under which defectors can invade cooperators. Imagine a single defector in a sea of cooperators (Fig. (\\ref{fig:1-d-i})). After the first game, the defector gets a payoff of $8b$, the boundary cells all get $7$ while all members of the sea get $8$. So the boundary members look to see if $8b>8$. As the game specifies that $b>1$, this is always true and so regardless of the value of $b$ it grows to a $3\\times3$ grid.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/1-defector-invasion.png}\n\t\t\\caption{1 defector invasion}\n\t\t\\label{fig:1-d-i}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/9-defector-invasion.png}\n\t\t\\caption{9 defector invasion}\n\t\t\\label{fig:9-d-i}\n\t\\end{subfigure}\n\t\\caption{Defector invasion}\n\t\\label{}\n\\end{figure}\\\\\n\\\\\nSo now we consider a $3\\times3$ grid of defectors (Fig. (\\ref{fig:9-d-i})). The sea cells always have a higher payoff ($8$) than the boundary (either $5,6$ or $7$). The highest scoring cell in the cluster is the edge cell with a payoff of $5b$. Every cell of the boundary is a neighbour to an edge cell. Hence each cell looks to see if $5b>8$. If it is, they change and the cluster grows. Otherwise, it stays the same or shrinks. So to have the possibility of defector invasion we need $b>8/5=1.\\dot6$.\\\\\n\\\\\nNow we consider cooperator invasion. We firstly note that a single cooperator cannot invade a population due to the constraints on the payoff matrix (Fig. (\\ref{fig:1-c-i})). The defectors can simply feed off the foolishness of the sole cooperator and it will die off. Hence a cooperator invasion must start with some cluster.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/1-cooperator-invasion.png}\n\t\t\\caption{1 cooperator invasion}\n\t\t\\label{fig:1-c-i}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/4-cooperator-invasion.png}\n\t\t\\caption{4 cooperator invasion}\n\t\t\\label{fig:4-c-i}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-torus/9-cooperator-invasion.png}\n\t\t\\caption{9 cooperator invasion}\n\t\t\\label{fig:9-c-i}\n\t\\end{subfigure}\n\t\\caption{Cooperator invasions}\n\t\\label{}\n\\end{figure}\n\\\\\n\\\\\nLooking at a $2\\times2$ cluster of cooperators (Fig. (\\ref{fig:4-c-i})), it is easy to see that if $b>3/2$ the cluster will grow uniformly. Otherwise it will be immediately destroyed.\\\\\n\\\\\nWith a $3\\times3$ cluster of cooperators there are different possibilities for growth (Fig. (\\ref{fig:9-c-i})). Cell $A$ looks at the payoff of cell $B$ which is $2b$ against the payoff of it's only cluster neighbour which has a payoff of $3$. So if $3>2b$ it will change. If this is the case $B$ and $C$ will also both change.\\\\\n\\\\\nHowever, if $b>3/2$ there is still the possibility of $B$ and $C$ changing whilst $A$ stays the same. The highest scoring neighbour of cells $B,C$ will be either $C$ with payoff $3b$ or the cluster cell with payoff $5$. So they look to see if $5>3b$. If so they will change and the cluster will grow. This will create a cross structure.\n\\begin{figure}[h]\n\t\\centering\n\t\\caption{The payoffs of cells around a $3\\times3$ cluster of cooperators in a sea of defectors.}\n\t\\label{fig:p-d-graph}\n\\end{figure}\nTo summarise defector clusters can grow if $b>8/5=1.6$ and cooperator clusters can grow if $1.\\dot6=5/3>b$. So there are three distinct parameter regions\n\\begin{enumerate}\n\t\\item $b<1.6$ Only cooperator clusters can grow\n\t\\item $1.6<b<1.\\dot6$ Both cooperator and defector clusters can grow\\label{chaos}\n\t\\item $1.\\dot 6<b$ Only defector clusters can grow\n\\end{enumerate}\nThis analytical approach justifies the conclusions we drew qualitatively earlier. In particular, region \\ref{chaos}., where both defectors and cooperators can grow, represents the chaotic region.\n%\\subsubsection{Prisoner's Dilemma on a Scale Free Graph}\n%\\subsubsection{On Different Networks}\n%We can adapt this to a hexagonal lattice.\n%\\begin{figure}\n%\t\\centering\n%\t\\begin{subfigure}{.3\\textwidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=.9\\linewidth]{appendix/games-on-networks/pd-hexagon/0005.png}\n%\t\t\\caption{}\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]{appendix/games-on-networks/pd-hexagon/0012.png}\n%\t\t\\caption{}\n%\t\t\\label{fig:loop}\n%\t\\end{subfigure}\n%\t\\caption{Running the evolutionary Prisoner's Dilemma on a hexagonal lattice}\n%\t\\label{fig:p-d-torus-1.63}\n%\\end{figure}", "meta": {"hexsha": "b4d98146f61891ae8dedacb20acaf9cd236785a9", "size": 35107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/TeX_files/games-on-networks.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/games-on-networks.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/games-on-networks.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": 75.661637931, "max_line_length": 960, "alphanum_fraction": 0.7601902754, "num_tokens": 9632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.6869254902167575}}
{"text": "\\section{Conclusions from obstruction theory}\nThe main result of obstruction theory, as discussed in the previous section, is\nthe following.\n\\begin{theorem}[Obstruction theory]\n    Let $(X,A)$ be a relative CW-complex, and $Y$ a simple space. The map\n    $[X,Y]\\to [A,Y]$ is:\n    \\begin{enumerate}\n\t\\item is onto if $H^n(X,A;\\pi_{n-1}(Y)) = 0$ for all $n\\geq 2$.\n\t\\item is one-to-one if $H^n(X,A;\\pi_n(Y)) = 0$ for all $n\\geq 1$.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{remark}\n    The first statement implies the second. Indeed, suppose we have two maps\n    $g_0,g_1:X\\to Y$ and a homotopy $h:g_0|_{A}\\simeq g_0|_{A}$. Assume the\n    first statement. Consider the relative CW-complex $(X\\times I,A\\times I\\cup\n    X\\times\\partial I)$. Because $(X,A)$ is a relative CW-complex, the map\n    $A\\hookrightarrow X$ is a cofibration; this implies that the map $A\\times\n    I\\cup X\\times\\partial I\\to X\\times I$ is also a cofibration.\n    \\begin{align*}\n\tH^n(X\\times I,A\\times I\\cup X\\times\\partial I;\\pi)\\simeq\n\t\\widetilde{H}^n(X\\times I/(A\\times I\\cup X\\times\\partial I);\\pi) \\\\\n\t= H^n(\\Sigma X/A;\\pi)\\simeq \\widetilde{H}^{n-1}(X/A;\\pi).\n    \\end{align*}\n    %More precisely, if I have $X_{n-1}\\to Y$, we get $\\theta\\in\n    %Z^n(X,A;\\pi_{n-1}(Y))$, constructed by looking at the attaching map\n    %$f_\\alpha$ of some $\\alpha\\in\\Sigma_n$, to define $\\theta(g)$ via\n    %$\\theta(g)(\\alpha) = [g\\circ f_\\alpha]$. This captures the obstruction to\n    %extending $g$ over $\\alpha$. We found that $d\\theta = 0$.\n\\end{remark}\nWe proved the following statement in the previous section.\n\\begin{prop}\n    Suppose $g:X_{n-1}\\to Y$ is a map from the $(n-1)$-skeleton of $X$ to $Y$.\n    Then $g|_{X_{n-2}}$ extends to $X_n\\to Y$ iff $[\\theta(g)] = 0$ in\n    $H^n(X,A;\\pi_{n-1}(Y))$.\n\\end{prop}\nAn immediate consequence is the following.\n\\begin{theorem}[CW-approximation]\n    Any space admits a weak equivalence from a CW-complex.\n\\end{theorem}\nThis tells us that studying CW-complexes is not very restrictive, if we work up\nto weak equivalence.\n\nIt is easy to see that if $W$ is a CW-complex and $f:X\\to Y$ is a weak\nequivalence, then $[W,X]\\xrightarrow{\\simeq}[W,Y]$. We can now finally conclude\nthe result of Theorem \\ref{weakhtpyequiv}:\n\\begin{corollary}\n    Let $X$ and $Y$ be CW-complexes. Then a weak equivalence $f:X\\to Y$ is a\n    homotopy equivalence.\n\\end{corollary}\n\\subsection{Postnikov and Whitehead towers}\nLet $X$ be path connected. There is a space $X_{\\leq n}$, and a map $X\\to\nX_{\\leq n}$ such that $\\pi_i(X_{\\geq n}) = 0$ for $i>n$, and\n$\\pi_i(X)\\xrightarrow{\\simeq}\\pi_i(X_{\\leq n})$ for $i\\leq n$. This pair\n$(X,X_{\\leq n})$ is essentially unique up to homotopy; the space $X_{\\leq n}$\nis called the \\emph{$n$th Postnikov section} of $X$. Since Postnikov sections\nhave ``simpler'' homotopy groups, we can try to understand $X$ by studying each\nof its Postnikov sections individually, and then gluing all the data together.\n\nSuppose $A$ is some abelian group. We saw, in the first part\\todo{provide a\nlink} that there is a space $M(A,n)$ with homology given by:\n\\begin{equation*}\n    \\widetilde{H}_i(M(A,n)) = \\begin{cases}\n\tA & i = n\\\\\n\t0 & i\\neq n.\n    \\end{cases}\n\\end{equation*}\nThis space was constructed from a free resolution $0\\to F_1\\to F_0\\to A\\to 0$\nof $A$. We can construct a map $\\bigvee S^n\\to \\bigvee S^n$ which realizes the\nfirst two maps; coning this off gets $M(A,n)$. By Hurewicz, we have:\n\\begin{equation*}\n    \\pi_i(M(A,n)) = \\begin{cases}\n\t0 & i<n\\\\\n\tA & i = n\\\\\n\t?? & i>n\n    \\end{cases}\n\\end{equation*}\nIt follows that, when we look at the $n$th Postnikov section of $M(A,n)$, we\nhave:\n\\begin{equation*}\n    \\pi_i(M(A,n)_{\\leq n}) = \\begin{cases}\n\tA & i = n\\\\\n\t0 & i\\neq n.\n    \\end{cases}\n\\end{equation*}\nIn some sense, therefore, this Postnikov section is a ``designer homotopy\ntype''. It deserves a special name: $M(A,n)_{\\leq n}$ is called an\n\\emph{Eilenberg-MacLane space}, and is denoted $K(A,n)$. By the fiber sequence\n$\\Omega X\\to PX\\to X$ with $PX\\simeq \\ast$, we find that $\\Omega K(\\pi,n)\\simeq\nK(\\pi,n-1)$. Eilenberg-MacLane spaces are unique up to homotopy.\n\nNote that $n=1$, $A$ does not have to be abelian, but you can still construct\n$K(A,1)$. This is called the \\emph{classifying space} of $G$; such spaces will\nbe discussed in more detail in the next chapter. Examples are in abundance: if\n$\\Sigma$ is a closed surface that is not $S^2$ or $\\RR^2$, then $\\Sigma \\simeq\nK(\\pi_1(\\Sigma),1)$. Perhaps simpler is the identification $S^1\\simeq K(\\Z,1)$.\n\n\\begin{example}\n    We can identify $K(\\Z,2)$ as $\\CP^\\infty$. To see this, observe that we\n    have a fiber sequence $S^1\\to S^{2n+1}\\to \\CP^n$. The long exact sequence\n    in homotopy tells us that the homotopy groups of $\\CP^n$ are the same as\n    the homotopy groups of $S^1$, until $\\pi_\\ast S^{2n+1}$ starts to\n    interfere. As $n$ grows, we obtain a fibration $S^1\\to S^\\infty\\to\n    \\CP^\\infty$. Since $S^\\infty$ is weakly contractible (it has no nonzero\n    homotopy groups), we get the desired result.\n\\end{example}\n\\begin{example}\n    Similarly, we can identify $K(\\Z/2\\Z,1)$ as $\\RP^\\infty$.\n\\end{example}\n\nSince $\\pi_1(K(A,n)) = 0$ for $n>1$, it follows that $K(A,n)$ is automatically\na simple space. This means that\n$$[S^k,K(A,n)] = \\pi_k(K(A,n)) = H^n(S^k,A).$$\nIn fact, a more general result is true:\n\\begin{theorem}[Brown representability]\\label{brown-rep}\n    If $X$ is a CW-complex, then $[X,K(A,n)] = H^n(X;A)$. \n\\end{theorem}\nWe will not prove this here, but one can show this simply by showing that the\nfunctor $[-,K(A,n)]$ satisfies the Eilenberg-Steenrod axioms. Somehow, these\nEilenberg-MacLane spaces $K(A,n)$ completely capture cohomology in dimension\n$n$. \n\nIf $X$ is a CW-complex, then we may assume that $X_{\\leq n}$ is also a\nCW-complex. (Otherwise, we can use cellular approximation and then kill\nhomotopy groups.) Let us assume that $X$ is path connected; then $X_{\\leq 1} =\nK(\\pi_1(X),1)$. We may then form a (commuting) tower:\n\\begin{equation*}\n    \\xymatrix{\n\t& \\vdots\\ar[d] & \\cdots\\ar[l]\\\\\n\t& X_{\\leq 3}\\ar[d]& K(\\pi_3(X),3)\\ar[l]\\\\\n\t& X_{\\leq 2}\\ar[d]& K(\\pi_2(X),2)\\ar[l]\\\\\n\tX\\ar[r]\\ar[ur]\\ar[uur]\\ar[uuur]& X_{\\leq 1}\\ar@{=}[r] & K(\\pi_1(X),1),\n    }\n\\end{equation*}\nsince $K(\\pi_n(X),n)\\to X_{\\leq n}\\to X_{\\leq n-1}$ is a fiber sequence.\nThis decomposition of $X$ is called the \\emph{Postnikov tower} of $X$.\n\nDenote by $X_{>n}$ the fiber of the map $X\\to X_{\\leq n}$ (for instance,\n$X_{>1}$ is the universal cover of $X$); then, we have\n\\begin{equation*}\n    \\xymatrix{\n\t\\cdots\\ar[r]\\ar[d] & \\cdots\\ar[r]\\ar@{=}[d] & \\vdots\\ar[d] &\n\t\\cdots\\ar[l]\\\\\n\tX_{>3}\\ar[r]\\ar[d] & X\\ar[r]\\ar@{=}[d] & X_{\\leq 3}\\ar[d]&\n\tK(\\pi_3(X),3)\\ar[l]\\\\\n\tX_{>2}\\ar[r]\\ar[d] & X\\ar[r]\\ar@{=}[d] & X_{\\leq 2}\\ar[d]&\n\tK(\\pi_2(X),2)\\ar[l]\\\\\n\tX_{>1}\\ar[r]\\ar[d] & X\\ar[r]\\ar@{=}[d] & X_{\\leq 1}\\ar@{=}[r]\\ar[d] &\n\tK(\\pi_1(X),1)\\\\\n\tX\\ar@{=}[r] & X\\ar[r] & \\ast\n    }\n\\end{equation*}\nThe leftmost tower is called the \\emph{Whitehead tower} of $X$, named after\nGeorge Whitehead.\n\nI can take the fiber of $X_{>1}\\to X$, and I get $K(\\pi_1(X),0)$; more\ngenerally, the fiber of $X_{>n} \\to X_{>n-1}$ is $K(\\pi_n(X),n-1)$. This yields\nthe following diagram:\n\\begin{equation*}\n    \\xymatrix{\n\t\\cdots & \\vdots\\ar[d] & \\vdots\\ar@{=}[d] & \\vdots\\ar[d] & \\cdots\\\\\n\tK(\\pi_3(X),2)\\ar[r] & X_{>3}\\ar[r]\\ar[d] & X\\ar[r]\\ar@{=}[d] & X_{\\leq\n\t3}\\ar[d]& K(\\pi_3(X),3)\\ar[l]\\\\\n\tK(\\pi_2(X),1)\\ar[r] & X_{>2}\\ar[r]\\ar[d] & X\\ar[r]\\ar@{=}[d] & X_{\\leq\n\t2}\\ar[d]& K(\\pi_2(X),2)\\ar[l]\\\\\n\tK(\\pi_1(X),0)\\ar[r] & X_{>1}\\ar[r]\\ar[d] & X\\ar[r]\\ar@{=}[d] & X_{\\leq\n\t1}\\ar@{=}[r]\\ar[d] & K(\\pi_1(X),1)\\\\\n\t& X\\ar@{=}[r] & X\\ar[r] & \\ast\n    }\n\\end{equation*}\n\nWe can construct Eilenberg-MacLane spaces as cellular complexes by attaching\ncells to the sphere to kill its higher homotopy groups. The complexity of\nhomotopy groups, though, shows us that attaching cells to compute the\ncohomology of Eilenberg-MacLane spaces is not feasible.\n%These constructions go back to the 50's, and they had voluminous computations in low dimensions. One day in 1950, they got a postcard from Serre, who said, ``here's a computation you might be interested in: $H^{23}(K(\\Z,14)) = ...$''. Of course, Serre and Cartan had a different approach, that was much more effective. They observed that the fact $\\Omega K(\\pi,n)\\simeq K(\\pi,n-1)$ wasn't perceived to be useful by Eilenberg and Maclane. They didn't think about fiber sequences. Serre and Cartan did this by means of a spectral sequence. We'll do that later in the course.\n", "meta": {"hexsha": "6860c4665e86ac3959e1e45d3656117c58e1f913", "size": 8491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-51-and-all-the-rest.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-51-and-all-the-rest.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-51-and-all-the-rest.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": 48.2443181818, "max_line_length": 573, "alphanum_fraction": 0.6546932046, "num_tokens": 3151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650248, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6869254826643156}}
{"text": "\\chapter{Functors and natural transformations}\n\\label{ch:functors}\nFunctors are maps between categories; natural transformations are maps between functors.\n\n\\section{Many examples of functors}\n\\prototype{Forgetful functors; fundamental groups; $-^\\vee$.}\nHere's the point of a functor:\n\\begin{moral}\n\tPretty much any time you make an object out of another object,\n\tyou get a functor.\n\\end{moral}\nBefore I give you a formal definition, let me list (informally) some examples.\n(You'll notice some of them have opposite categories $\\AA\\op$ appearing in places.\nDon't worry about those for now; you'll see why in a moment.)\n\\begin{itemize}\n\t\\ii Given a group $G$ (or vector space, field, \\dots), we can take its underlying set $S$;\n\tthis is a functor from $\\catname{Grp} \\to \\catname{Set}$.\n\t\\ii Given a set $S$ we can consider a vector space with basis $S$;\n\tthis is a functor from $\\catname{Set} \\to \\catname{Vect}$.\n\n\t\\ii Given a vector space $V$ we can consider its dual space $V^\\vee$.\n\tThis is a functor $\\catname{Vect}_k\\op \\to \\catname{Vect}_k$.\n\t\\ii Tensor products give a functor from $\\catname{Vect}_k \\times \\catname{Vect}_k \\to \\catname{Vect}_k$.\n\t\\ii Given a set $S$, we can build its power set, giving a functor $\\catname{Set} \\to \\catname{Set}$.\n\t\\ii In algebraic topology, we take a topological space $X$ and build several groups $H_1(X)$, $\\pi_1(X)$,\n\tetc.\\ associated to it. All these group constructions are functors $\\catname{Top} \\to \\catname{Grp}$.\n\t\\ii Sets of homomorphisms: let $\\AA$ be a category.\n\t\\begin{itemize}\n\t\t\\ii Given two vector spaces $V_1$ and $V_2$ over $k$,\n\t\twe construct the abelian group of linear maps $V_1 \\to V_2$.\n\t\tThis is a functor from $\\catname{Vect}_k\\op \\times \\catname{Vect}_k \\to \\catname{AbGrp}$.\n\t\t\\ii More generally for any category $\\AA$\n\t\twe can take pairs $(A_1, A_2)$ of objects and\n\t\tobtain a set $\\Hom_{\\AA}(A_1, A_2)$.\n\t\tThis turns out to be a functor $\\AA\\op \\times \\AA \\to \\catname{Set}$.\n\t\t\\ii The above operation has two ``slots''.\n\t\tIf we ``pre-fill'' the first slots, then we get a functor $\\AA \\to \\catname{Set}$.\n\t\tThat is, by fixing $A \\in \\AA$, we obtain a functor (called $H^A$)\n\t\tfrom $\\AA \\to \\catname{Set}$ by sending $A' \\in \\AA$ to $\\Hom_{\\AA} (A, A')$.\n\t\tThis is called the covariant Yoneda functor (explained later).\n\t\t\\ii As we saw above,\n\t\tfor every $A \\in \\AA$ we obtain a functor $H^A : \\AA \\to \\catname{Set}$.\n\t\tIt turns out we can construct a category $[\\AA, \\catname{Set}]$\n\t\twhose elements are functors $\\AA \\to \\catname{Set}$;\n\t\tin that case, we now have a functor $\\AA\\op \\to [\\AA, \\catname{Set}]$.\n\t\\end{itemize}\n\\end{itemize}\n\n\\section{Covariant functors}\n\\prototype{Forgetful/free functors, \\dots}\nCategory theorists are always asking ``what are the maps?'',\nand so we can now think about maps between categories.\n\n\\begin{definition}\n\tLet $\\AA$ and $\\BB$ be categories.\n\tOf course, a \\vocab{functor} $F$ takes every object of $\\AA$ to an object of $\\BB$.\n\tIn addition, though, it must take every arrow $A_1 \\taking{f} A_2$\n\tto an arrow $F(A_1) \\taking{F(f)} F(A_2)$.\n\tYou can picture this as follows.\n\t\\begin{diagram}\n\t\t& A_1 & & B_1 & = F(A_1) & \\\\\n\t\t\\AA \\ni & \\dTo^f & \\rDotted^F & \\dTo_{F(f)} && \\in \\BB \\\\\n\t\t& A_2 & & B_2 & = F(A_2) &\n\t\\end{diagram}\n\t(I'll try to use dotted arrows for functors, which cross different categories, for emphasis.)\n\tIt needs to satisfy the ``naturality'' requirements:\n\t\\begin{itemize}\n\t\t\\ii Identity arrows get sent to identity arrows:\n\t\tfor each identity arrow $\\id_A$, we have $F(\\id_A) = \\id_{F(A)}$.\n\t\t\\ii The functor respects composition:\n\t\tif $A_1 \\taking f A_2 \\taking g A_3$ are arrows in $\\AA$,\n\t\tthen $F(g \\circ f) = F(g) \\circ F(f)$.\n\t\\end{itemize}\n\\end{definition}\n\nSo the idea is:\n\\begin{moral}\nWhenever we naturally make an object $A \\in \\AA$ into an object of $B \\in \\BB$,\nthere should usually be a natural way to transform a map $A_1 \\to A_2$ into a map $B_1 \\to B_2$.\n\\end{moral}\nLet's see some examples of this.\n\n\\begin{example}\n\t[Free and forgetful functors]\n\tNote that these are both informal terms,\n\tand don't have a rigid definition.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii We talked about a \\vocab{forgetful functor} earlier,\n\t\twhich takes the underlying set of a category like $\\catname{Vect}_k$.\n\t\tLet's call it $U : \\catname{Vect}_k \\to \\catname{Set}$.\n\n\t\tNow, given a map $T : V_1 \\to V_2$ in $\\catname{Vect}_k$,\n\t\tthere is an obvious $U(T) : U(V_1) \\to U(V_2)$ which is just\n\t\tthe set-theoretic map corresponding to $T$.\n\n\t\tSimilarly there are forgetful functors from\n\t\t$\\catname{Grp}$, $\\catname{CRing}$, etc., to $\\catname{Set}$.\n\t\tThere is even a forgetful functor $\\catname{CRing} \\to \\catname{Grp}$:\n\t\tsend a ring $R$ to the abelian group $(R,+)$.\n\t\tThe common theme is that we are ``forgetting'' structure\n\t\tfrom the original category.\n\n\t\t\\ii We also talked about a \\vocab{free functor} in the example.\n\t\tA free functor $F : \\catname{Set} \\to \\catname{Vect}_k$ can be taken by considering\n\t\t$F(S)$ to be the vector space with basis $S$.\n\t\tNow, given a map $f : S \\to T$, what is the obvious map $F(S) \\to F(T)$?\n\t\tSimple: take each basis element $s \\in S$ to the basis element $f(s) \\in T$.\n\n\t\tSimilarly, we can define $F : \\catname{Set} \\to \\catname{Grp}$\n\t\tby taking the free group generated by a set $S$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\tThere is also a notion of ``injective'' and ``surjective''\n\tfor functors (on arrows) as follows.\n\tA functor $F \\colon \\AA \\to \\BB$ is \\vocab{faithful}\n\t(resp.\\ \\vocab{full}) if for any $A_1, A_2$,\n\t$F \\colon \\Hom_\\AA(A_1, A_2) \\to \\Hom_\\BB(FA_1, FA_2)$\n\tis injective (resp.\\ surjective).\\footnote{Again,\n\t\texperts might object that $\\Hom_\\AA(A_1, A_2)$\n\t\tor $\\Hom_\\BB(FA_1, FA_2)$ may be proper classes instead of sets,\n\t\tbut I am assuming everything is locally small.}\n\n\tWe can use this to give an exact definition of concrete category:\n\tit's a category with a faithful (forgetful) functor\n\t$U \\colon \\AA \\to \\catname{Set}$.\n\\end{remark}\n\n\\begin{example}\n\t[Functors from $\\mathcal G$]\n\tLet $G$ be a group and $\\mathcal G = \\{\\ast\\}$ be the associated one-object category.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Consider a functor $F : \\mathcal G \\to \\catname{Set}$, and let $S = F(\\ast)$.\n\t\tThen the data of $F$ corresponds to putting a \\emph{group action} of $G$ on $S$.\n\t\t\\ii Consider a functor $F : \\mathcal G \\to \\catname{FDVect}_k$, and let $V = F(\\ast)$ have dimension $n$.\n\t\tThen the data of $F$ corresponds to embedding $G$ as a subgroup of the $n \\times n$ matrices\n\t\t(i.e.\\ the linear maps $V \\to V$).\n\t\tThis is one way groups historically arose; the theory of viewing groups as matrices\n\t\tforms the field of representation theory.\n\t\t\\ii Let $H$ be a group and construct $\\mathcal H$ the same way.\n\t\tThen functors $\\mathcal G \\to \\mathcal H$ correspond to homomorphisms $G \\to H$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{exercise}\n\tCheck the above group-based functors work as advertised.\n\\end{exercise}\n\nHere's a more involved example.\nIf you find it confusing,\nskip it and come back after reading about its contravariant version.\n\\begin{example}\n\t[Covariant Yoneda functor]\n\t\\label{ex:covariant_yoneda}\n\tFix an $A \\in \\AA$.\n\tFor a category $\\AA$, define the\n\t\\vocab{covariant Yoneda functor} $H^A \\colon \\AA \\to \\catname{Set}$\n\tby defining \\[ H^A(A_1) \\defeq \\Hom_\\AA (A, A_1) \\in \\catname{Set}. \\]\n\tHence each $A_1$ is sent to the \\emph{arrows from $A$ to $A_1$};\n\tso \\textbf{$H^A$ describes how $A$ sees the world}.\n\n\tNow we want to specify how $H^A$ behaves on arrows.\n\tFor each arrow $A_1 \\taking{f} A_2$, we need\n\tto specify $\\catname{Set}$-map $\\Hom_\\AA (A, A_1) \\to \\Hom(A, A_2)$;\n\tin other words, we need to send an arrow $A \\taking{p} A_1$ to an arrow $A \\to A_2$.\n\tThere's only one reasonable way to do this: take the composition\n\t\\[ A \\taking{p} A_1 \\taking{f} A_2. \\]\n\tIn other words, $H_A(f)$ is $p \\mapsto f \\circ p$.\n\tIn still other words, $H_A(f) = f \\circ -$;\n\tthe $-$ is a slot for the input to go into.\n\\end{example}\n\nAs another example:\n\\begin{ques}\n\tIf $\\mathcal P$ and $\\mathcal Q$ are posets interpreted as categories,\n\twhat does a functor from $\\mathcal P$ to $\\mathcal Q$ represent?\n\\end{ques}\n\nNow, let me explain why we might care.\nConsider the following ``obvious'' fact:\nif $G$ and $H$ are isomorphic groups, then they have the same size.\nWe can formalize it by saying: if $G \\cong H$ in $\\catname{Grp}$\nand $U \\colon \\catname{Grp} \\to \\catname{Set}$ is the forgetful functor\n(mapping each group to its underlying set), then $U(G) \\cong U(H)$.\nThe beauty of category theory shows itself:\nthis in fact works \\emph{for any functors and categories},\nand the proof is done solely through arrows:\n\n\\begin{theorem}\n\t[Functors preserve isomorphism]\n\t\\label{thm:functor_isom}\n\tIf $A_1 \\cong A_2$ are isomorphic objects in $\\AA$\n\tand $F : \\AA \\to \\BB$ is a functor\n\tthen $F(A_1) \\cong F(A_2)$.\n\\end{theorem}\n\\begin{proof}\n\tTry it yourself! The picture is:\n\t\\begin{diagram}\n\t\t& A_1 & & B_1 & = F(A_1) & \\\\\n\t\t\\AA \\ni & \\dTo^f \\uTo_g & \\rDotted^F & \\dTo^{F(f)} \\uTo_{F(g)} && \\in \\BB \\\\\n\t\t& A_2 & & B_2 & = F(A_2) &\n\t\\end{diagram}\n\tYou'll need to use both key properties of functors:\n\tthey preserve composition and the identity map.\n\\end{proof}\n\nThis will give us a great intuition in the future, because\n\\begin{enumerate}[(i)]\n\t\\ii Almost every operation we do in our lifetime will be a functor, and\n\t\\ii We now know that functors take isomorphic objects to isomorphic objects.\n\\end{enumerate}\nThus, we now automatically know that basically any ``reasonable'' operation\nwe do will preserve isomorphism (where ``reasonable'' means that it's a functor).\nThis is super convenient in algebraic topology, for example;\nsee \\Cref{thm:fundgrp_functor}, where we get for free that homotopic\nspaces have isomorphic fundamental groups.\n\n\\begin{remark}\n\tThis lets us construct a category $\\catname{Cat}$\n\twhose objects are categories and arrows are functors.\n\\end{remark}\n% wef why is this here?\n%While I'm here:\n%\\begin{ques}\n%\tVerify this works; figure out the identity and compositions.\n%\\end{ques}\n\n\\section{Contravariant functors}\n\\prototype{Dual spaces, contravariant Yoneda functor, etc.}\n\nNow I have to explain what the opposite categories were doing earlier.\nIn all the previous examples, we took an arrow $A_1 \\to A_2$,\nand it became an arrow $F(A_1) \\to F(A_2)$.\nSometimes, however, the arrow in fact goes the other way:\nwe get an arrow $F(A_2) \\to F(A_1)$ instead.\nIn other words, instead of just getting a functor $\\AA \\to \\BB$\nwe ended up with a functor $\\AA\\op \\to \\BB$.\n\nThese functors have a name:\n\\begin{definition}\n\tA \\vocab{contravariant functor} from $\\AA$ to $\\BB$\n\tis a functor $F : \\AA\\op \\to \\BB$.\n\t(Note that we do \\emph{not} write ``contravariant functor $F: \\AA \\to \\BB$'',\n\tsince that would be confusing; the function notation will always\n\tuse the correct domain and codomain.)\n\\end{definition}\nPictorially:\n\\begin{diagram}\n\t& A_1 & & B_1 & = F(A_1) & \\\\\n\t\\AA \\ni & \\dTo^f & \\rDotted^F & \\uTo_{F(f)} && \\in \\BB \\\\\n\t& A_2 & & B_2 & = F(A_2) &\n\\end{diagram}\nFor emphasis, a usual functor is often called a \\vocab{covariant functor}.\n(The word ``functor'' with no adjective always refers to covariant.)\n\nLet's see why this might happen.\n\\begin{example}[$V \\mapsto V^\\vee$ is contravariant]\n\tConsider the functor $\\catname{Vect}_k \\to \\catname{Vect}_k$ by $V \\mapsto V^\\vee$.\n\n\tIf we were trying to specify a covariant functor,\n\twe would need, for every linear map $T : V_1 \\to V_2$,\n\ta linear map $T^\\vee : V_1^\\vee \\to V_2^\\vee$.\n\tBut recall that $V_1^\\vee = \\Hom(V_1, k)$ and $V_2^\\vee = \\Hom(V_2, k)$:\n\tthere's no easy way to get an obvious map from left to right.\n\n\tHowever, there \\emph{is} an obvious map from right to left:\n\tgiven $\\xi_2 : V_2 \\to k$, we can easily give a map from $V_1 \\to k$:\n\tjust compose with $T$!\n\tIn other words, there is a very natural map $V_2^\\vee \\to V_1^\\vee$\n\taccording to the composition\n\t\\begin{diagram}\n\t\tV_1 & \\rTo^T & V_2 & \\rTo^{\\xi_2} & k\n\t\\end{diagram}\n\tIn summary, a map $T : V_1 \\to V_2$ induces naturally a map\n\t$T^\\vee : V_2^\\vee \\to V_1^\\vee$ in the opposite direction.\n\tSo the contravariant functor looks like:\n\t\\begin{diagram}\n\t\tV_1 & & V_1^\\vee \\\\\n\t\t\\dTo^T & \\rDotted^{-^\\vee} & \\uTo_{T^\\vee} \\\\\n\t\tV_2 & & V_2^\\vee\n\t\\end{diagram}\n\\end{example}\n\n%Contravariant functors come up in a lot in geometric applications.\n%Here's why.\n%If $X$ is a geometric object, we'll often consider\n%the \\emph{set of functions} $X \\taking\\psi A$ for some particular $A$.\n%For example, if $V$ was a vector space, we could consider the functions $V \\to k$,\n%giving the dual module $V^\\vee$.\n%Or if $X$ was a space, we might consider the continuous\n%real functions $X \\taking{p} \\RR$.\n%As a non-geometric example: for a set $S$,\n%a function $S \\to \\{x,y\\}$ corresponds to a subset of $S$.\n\nWe can generalize the example above in any category by\nreplacing the field $k$ with any chosen object $A \\in \\AA$.\n\n\\begin{example}[Contravariant Yoneda functor]\n\tThe \\vocab{contravariant Yoneda functor} on $\\AA$,\n\tdenoted $H_A : \\AA\\op \\to \\catname{Set}$,\n\tis used to describe how objects of $\\AA$ see $A$.\n\tFor each $X \\in \\AA$ it puts \\[ H_A(X) \\defeq \\Hom_{\\AA}(X, A) \\in \\catname{Set}. \\]\n\tFor $X \\taking{f} Y$ in $\\AA$,\n\tthe map $H_A(f)$ sends each arrow $Y \\taking{p} A \\in \\Hom_\\AA(Y,A)$ to \n\t\\[ X \\taking{f} Y \\taking{p} A \\quad \\in \\Hom_\\AA(X,A) \\]\n\tas we did above.\n\tThus $H_A(f)$ is an arrow from $\\Hom_\\AA(Y,A) \\to \\Hom_\\AA(X,A)$.\n\t(Note the flipping!)\n\\end{example}\n\n\\begin{exercise}\n\tCheck now the claim that $\\AA\\op \\times \\AA \\to \\catname{Set}$\n\tby $(A_1, A_2) \\mapsto \\Hom(A_1, A_2)$ is in fact a functor.\n\\end{exercise}\n\n\\section{Equivalence of categories}\n\\todo{fully faithful and essentially surjective}\n\n\\section{(Optional) Natural transformations}\nWe made categories to keep track of objects and maps, then went a little crazy and asked\n``what are the maps between categories?'' to get functors.\nNow we'll ask ``what are the maps between functors?'' to get natural transformations.\n\nIt might sound terrifying that we're drawing arrows between functors, but this is actually an old idea.\nRecall that given two paths $\\alpha, \\beta : [0,1] \\to X$,\nwe built a path-homotopy by ``continuously deforming'' the path $\\alpha$ to $\\beta$;\nthis could be viewed as a function $[0,1] \\times [0,1] \\to X$.\nThe definition of a natural transformation is similar: we want to pull $F$ to $G$\nalong a series of arrows in the target space $\\BB$.\n\n\\begin{definition}\n\tLet $F, G : \\AA \\to \\BB$ be two functors.\n\tA \\vocab{natural transformation} $\\alpha$ from $F$ to $G$, denoted\n\t\\[ \\nattfm{\\AA}{F}{\\alpha}{G}{\\BB} \\]\n\tconsists of, for each $A \\in \\AA$ an arrow $\\alpha_A \\in \\Hom_\\BB(F(A), G(A))$, which is\n\tcalled the \\vocab{component} of $\\alpha$ at $A$.\n\tPictorially, it looks like this:\n\t\\begin{diagram}\n\t\t& & & F(A) \\in \\BB \\\\\n\t\t\\AA \\ni & A & \\ruDotted(2,1)^F & \\dTo_{\\alpha_A} \\\\\n\t\t& & \\rdDotted(2,1)^G & G(A) \\in \\BB\n\t\\end{diagram}\n\tThese $\\alpha_A$ are subject to the ``naturality'' requirement that for any $A_1 \\taking{f} A_2$,\n\tthe diagram\n\t\\begin{diagram}\n\t\tF(A_1) & \\rTo^{F(f)} & F(A_2) \\\\\n\t\t\\dTo_{\\alpha_{A_1}} & & \\dTo_{\\alpha_{A_2}} \\\\\n\t\tG(A_1) & \\rTo_{G(f)} & G(A_2)\n\t\\end{diagram}\n\tcommutes.\n\\end{definition}\nThe arrow $\\alpha_A$ represents the path that $F(A)$ takes to get to $G(A)$\n(just as in a path-homotopy from $\\alpha$ to $\\beta$\neach \\emph{point} $\\alpha(t)$ gets deformed to the \\emph{point} $\\beta(t)$ continuously).\nA picture might help: consider\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(14cm);\n\t\tdotfactor *= 1.4;\n\n\t\tpath sparrow(pair X, pair Y) {\n\t\t\t// Short for \"spaced arrow\"\n\t\t\treturn (0.9*X+0.1*Y)--(0.1*X+0.9*Y);\n\t\t}\n\n\t\tpair A1 = Drawing(\"A_1\", dir(210), dir(225));\n\t\tpair A2 = Drawing(\"A_2\", origin, dir(90));\n\t\tpair A3 = Drawing(\"A_3\", dir(-30), dir(-45));\n\t\tpath f = Drawing(sparrow(A2, A1), EndArrow);\n\t\tlabel(\"$f$\", f, dir(90));\n\t\tpath g = Drawing(sparrow(A2, A3), EndArrow);\n\t\tlabel(\"$g$\", g, dir(90));\n\t\tlabel(\"$\\mathcal A$\", 0.6*(A1+A3));\n\n\t\tpen p = blue;\n\t\ttransform FF = shift( (3.5, 0.7) );\n\t\tdot(\"$F(A_1)$\", FF*A1, dir(225), p);\n\t\tdot(\"$F(A_2)$\", FF*A2, dir(90), p);\n\t\tdot(\"$F(A_3)$\", FF*A3, dir(-45), p);\n\t\tdraw(FF*f, p, EndArrow);\n\t\tdraw(FF*g, p, EndArrow);\n\t\tlabel(\"$F(f)$\", FF*f, dir(110), p);\n\t\tlabel(\"$F(g)$\", FF*g, dir(70), p);\n\t\tdraw(FF*f, p+1.4);\n\t\tdraw(FF*g, p+1.4);\n\n\t\tp = deepcyan;\n\t\ttransform GG = shift( (3.5, -0.7) );\n\t\tdot(\"$G(A_1)$\", GG*A1, dir(225), p);\n\t\tdot(\"$G(A_2)$\", GG*A2, 3*dir(-90), p);\n\t\tdot(\"$G(A_3)$\", GG*A3, dir(-45), p);\n\t\tlabel(\"$G(f)$\", Drawing(GG*f, p, EndArrow), dir(110), p);\n\t\tlabel(\"$G(g)$\", Drawing(GG*g, p, EndArrow), dir(70), p);\n\t\tdraw(GG*f, p+1.4);\n\t\tdraw(GG*g, p+1.4);\n\n\t\tp = lightred;\n\t\tlabel(\"$\\alpha_{A_1}$\", Drawing(sparrow(FF*A1, GG*A1), p, EndArrow), dir(180), p);\n\t\tlabel(\"$\\alpha_{A_2}$\", Drawing(sparrow(FF*A2, GG*A2), p, EndArrow), dir(180), p);\n\t\tlabel(\"$\\alpha_{A_3}$\", Drawing(sparrow(FF*A3, GG*A3), p, EndArrow), dir(0), p);\n\n\t\tp = magenta + dotted + 0.7;\n\t\tpath Fa = (0.5,0)--FF*(-1,-0.2);\n\t\tpath Ga = (0.5,-0.6)--GG*(-1,-0.4);\n\t\tlabel(\"$F$\", Drawing(Fa, p, EndArrow), dir(135), p);\n\t\tlabel(\"$G$\", Drawing(Ga, p, EndArrow), dir(225), p);\n\n\t\tp = lightred + 0.7;\n\t\tlabel(\"$\\alpha$\", Drawing(sparrow(midpoint(Fa), midpoint(Ga)), p, EndArrow), dir(180), p);\n\n\t\tp = grey + dashed;\n\t\tpair B1 = Drawing(midpoint(FF*A2--GG*A1), p);\n\t\tpair B2 = Drawing(0.6 * (FF*A3) + 0.4 * (GG*A2), p);\n\t\tdraw(sparrow(FF*A1, B1), p, EndArrow);\n\t\tdraw(sparrow(GG*A2, B1), p, EndArrow);\n\t\tdraw(sparrow(FF*A3, B2), p, EndArrow);\n\t\tpair B3 = Drawing(FF*A3 + 0.7*dir(100), p);\n\t\tdraw(sparrow(B3, FF*A3), p, EndArrow);\n\t\tlabel(\"$\\mathcal B$\", GG*(0.6*(A1+A3)));\n\t\tdraw(sparrow(FF*A2, GG*A3), p, EndArrow);\n\t\tpair B4 = Drawing(FF*A1 + 0.5*dir(90), p);\n\t\tdraw(sparrow(FF*A1, B4), p, EndArrow);\n\t\\end{asy}\n\\end{center}\nHere $\\AA$ is the small category with three elements and two non-identity arrows $f$, $g$\n(I've omitted the identity arrows for simplicity).\nThe images of $\\AA$ under $F$ and $G$ are the blue and green ``subcategories'' of $\\BB$.\nNote that $\\BB$ could potentially have many more objects and arrows in it (grey).\nThe natural transformation $\\alpha$ (red) selects an arrow of $\\BB$ from each $F(A)$\nto the corresponding $G(A)$, dragging the entire image of $F$ to the image of $G$.\nFinally, we require that any diagram formed by the blue, red, and green arrows is commutative (naturality),\nso the natural transformation is really ``natural''.\n\nThere is a second equivalent definition that looks much more like the homotopy.\n\\begin{definition}\n\tLet $\\mathbf 2$ denote the category generated by a poset with two elements $0 \\le 1$, that is,\n\t\\begin{center}\n\t\\begin{tikzpicture}[scale=2]\n\t\t\\SetVertexMath\n\t\t\\Vertices{circle}{1,0}\n\t\t\\Edge[style={->}, label={$0 \\le 1$}](0)(1)\n\t\t\\Loop[dist=12, dir=NO, label={$\\id_0$}, labelstyle={above=1pt}](0)\n\t\t\\Loop[dist=12, dir=NO, label={$\\id_1$}, labelstyle={above=1pt}](1)\n\t\\end{tikzpicture}\n\t\\end{center}\n\tThen a \\emph{natural transformation}\n\t$ \\nattfm{\\AA}{F}{\\alpha}{G}{\\BB} $\n\tis just a functor $\\alpha : \\AA \\times \\mathbf 2 \\to \\BB$ satisfying\n\t\\[ \\alpha(A,0) = F(A), \\;\\; \\alpha(f,0) = F(f)\n\t\t\\quad\\text{and}\\quad\n\t\t\\alpha(A,1) = G(A), \\;\\; \\alpha(f,1) = G(f). \\]\n\tMore succinctly, $\\alpha(-,0) = F$, $\\alpha(-,1) = G$.\n\\end{definition}\nThe proof that these are equivalent is left as a practice problem.\n\nNaturally, two natural transformations $\\alpha : F \\to G$ and $\\beta : G \\to H$ can get composed.\n\\begin{diagram}\n\t& & F(A) \\\\\n\t& \\ruDotted^F & \\dTo_{\\alpha_A} \\\\\n\t\\AA \\ni A & \\rDotted^G & G(A) \\\\\n\t& \\rdDotted_H & \\dTo_{\\beta_A} \\\\\n\t&& H(A)\n\\end{diagram}\n\nNow suppose $\\alpha$ is a natural transformation such that $\\alpha_A$ is an isomorphism for each $A$.\nIn this way, we can construct an inverse arrow $\\beta_A$ to it.\n\\begin{diagram}\n\t& & F(A) \\in \\BB \\\\\n\t\\AA \\ni A & \\ruDotted(2,1)^F & \\dTo^{\\alpha_A} \\uTo_{\\beta_A} \\\\\n\t& \\rdDotted(2,1)^G & G(A) \\in \\BB\n\\end{diagram}\nIn this case, we say $\\alpha$ is a \\vocab{natural isomorphism}.\nWe can then say that $F(A) \\cong G(A)$ \\vocab{naturally} in $A$.\n(And $\\beta$ is an isomorphism too!)\nThis means that the functors $F$ and $G$ are ``really the same'':\nnot only are they isomorphic on the level of objects,\nbut these isomorphisms are ``natural''.\nAs a result of this, we also write $F \\cong G$ to mean\nthat the functors are naturally isomorphic.\n\nThis is what it really means when we say that\n``there is a natural / canonical isomorphism''.\nFor example, I claimed earlier (in \\Cref{prob:double_dual})\nthat there was a canonical isomorphism $(V^\\vee)^\\vee \\cong V$,\nand mumbled something about ``not having to pick a basis'' and ``God-given''.\nCategory theory, amazingly, lets us formalize this:\nit just says that $(V^\\vee)^\\vee \\cong \\id(V)$ naturally in $V \\in \\catname{FDVect}_k$.\nReally, we have a natural transformation\n\\[ \\nattfm{\\catname{FDVect}_k}{\\id}{\\eps}{(-^\\vee)^\\vee}{\\catname{FDVect}_k}. \\]\nwhere the component $\\eps_V$ is given by $v \\mapsto \\opname{ev}_v$\n(as discussed earlier,\nthe fact that it is an isomorphism follows from the fact that $V$ and $(V^\\vee)^\\vee$\nhave equal dimensions and $\\eps_V$ is injective).\n\n\\section{(Optional) The Yoneda lemma}\nNow that I have natural transformations, I can define:\n\\begin{definition}\n\tThe \\vocab{functor category} of two categories $\\AA$ and $\\BB$,\n\tdenoted $[\\AA, \\BB]$, is defined as follows:\n\t\\begin{itemize}\n\t\t\\ii The objects of $[\\AA, \\BB]$ are (covariant) functors $F : \\AA \\to \\BB$, and\n\t\t\\ii The morphisms are natural transformations $\\alpha : F \\to G$.\n\t\\end{itemize}\n\\end{definition}\n\\begin{ques}\n\tWhen are two objects in the functor category isomorphic?\n\\end{ques}\n\nWith this, I can make good on the last example I mentioned at the beginning:\n\\begin{exercise}\n\tConstruct the following functors:\n\t\\begin{itemize}\n\t\t\\ii $\\AA \\to [\\AA\\op, \\catname{Set}]$ by $A \\mapsto H_A$, which we call $H_\\bullet$.\n\t\t\\ii $\\AA\\op \\to [\\AA, \\catname{Set}]$ by $A \\mapsto H^A$, which we call $H^\\bullet$.\n\t\\end{itemize}\n\\end{exercise}\nNotice that we have opposite categories either way; even if you like $H^A$ because it is covariant,\nthe map $H^\\bullet$ is contravariant.\nSo for what follows, we'll prefer to use $H_\\bullet$.\n\nThe main observation now is that given a category $\\AA$, $H_\\bullet$ provides some \\emph{special}\nfunctors $\\AA\\op \\to \\catname{Set}$ which are already ``built'' in to the category $A$.\nIn light of this, we define:\n\\begin{definition}\n\tA \\vocab{presheaf} $X$ is just a contravariant functor $\\AA\\op \\to \\catname{Set}$.\n\tIt is called \\vocab{representable} if $X \\cong H_A$ for some $A$.\n\\end{definition}\nIn other words, when we think about representable, the question we're asking is:\n\\begin{quote}\n\t\\itshape\n\tWhat kind of presheaves are already ``built in'' to the category $\\AA$?\n\\end{quote}\nOne way to get at this question is: given a presheaf $X$ and a particular $H_A$,\nwe can look at the \\emph{set} of natural transformations $\\alpha : X \\implies H_A$,\nand see if we can learn anything about it.\nIn fact, this set can be written explicitly:\n\n\\begin{theorem}\n\t[Yoneda lemma]\n\t\\label{thm:yoneda}\n\tLet $\\AA$ be a category,\n\tpick $A \\in \\AA$, and let $H_A$ be the contravariant Yoneda functor.\n\tLet $X : \\AA\\op \\to \\catname{Set}$ be a contravariant functor.\n\tThen the map \n\t\\[ \\left\\{ \\text{Natural transformations }\n\t\t\\nattfm{\\AA\\op}{H_A}{\\alpha}{X}{\\catname{Set}} \\right\\}\n\t\t\\to X(A) \\]\n\tdefined by $\\alpha \\mapsto \\alpha_A(\\id_A) \\in X(A)$\n\tis an isomorphism of $\\catname{Set}$ (i.e.\\ a bijection).\n\tMoreover, if we view both sides of the equality as functors\n\t\\[ \\AA\\op \\times [\\AA\\op, \\catname{Set}] \\to \\catname{Set} \\]\n\tthen this isomorphism is natural.\n\\end{theorem}\n\nThis might be startling at first sight.\nHere's an unsatisfying explanation why this might not be too crazy:\nin category theory, a rule of thumb is that ``two objects of the same type\nthat are built naturally are probably the same''.\nYou can see this theme when we defined functors and natural transformations,\nand even just compositions.\nNow to look at the set of natural transformations, we took a pair of elements $A \\in \\AA$\nand $X \\in [\\AA\\op, \\catname{Set}]$\nand constructed a \\emph{set} of natural transformations.\nIs there another way we can get a set from these two pieces of information?\nYes: just look at $X(A)$.\nThe Yoneda lemma is telling us that our heuristic still holds true here.\n\nSome consequences of the Yoneda lemma are recorded in \\cite{ref:msci}.\nSince this chapter is already a bit too long, I'll just write down the statements,\nand refer you to \\cite{ref:msci} for the proofs.\n\n\\begin{enumerate}\n\t\\ii As we mentioned before, $H^\\bullet$ provides a functor\n\t\\[ \\AA \\to [\\AA\\op, \\catname{Set}]. \\]\n\tIt turns out this functor is in fact \\emph{fully faithful};\n\tit quite literally embeds the category $\\AA$ into the functor category on the right\n\t(much like Cayley's theorem embeds every group into a permutation group).\n\n\t\\ii If $X, Y \\in \\AA$ then\n\t\\[ H_X \\cong H_Y \\iff X \\cong Y \\iff H^X \\cong H^Y. \\]\n\tTo see why this is expected, consider $\\AA = \\catname{Grp}$ for concreteness.\n\tSuppose $A$, $X$, $Y$ are groups such that $H_X(A) \\cong H_Y(A)$ for all $A$.\n\tFor example,\n\t\\begin{itemize}\n\t\t\\ii If $A = \\ZZ$, then $\\left\\lvert X \\right\\rvert = \\left\\lvert Y \\right\\rvert$.\n\t\t\\ii If $A = \\ZZ / 2\\ZZ$, then $X$ and $Y$ have the same number of elements of order $2$.\n\t\t\\ii \\dots\n\t\\end{itemize}\n\tEach $A$ gives us some information on how $X$ and $Y$ are similar,\n\tbut the whole natural isomorphism is strong enough to imply $X \\cong Y$.\n\t\n\t\\ii Consider the functor $U : \\catname{Grp} \\to \\catname{Set}$.\n\tIt can be represented by $H^\\ZZ$, in the sense that \n\t\\[ \\Hom_{\\catname{Grp}}(\\ZZ, G) \\cong U(G)\n\t\t\\qquad\\text{ by }\\qquad \\phi \\mapsto \\phi(1). \\]\n\tThat is, elements of $G$ are in bijection with maps $\\ZZ \\to G$,\n\tdetermined by the image of $+1$ (or $-1$ if you prefer).\n\tSo a representation of $U$ was determined by looking at $\\ZZ$ and picking $+1 \\in U(\\ZZ)$.\n\n\tThe generalization of this is a follows: let $\\AA$ be a category\n\tand $X : \\AA \\to \\catname{Set}$ a covariant functor.\n\tThen a representation $H^A \\cong X$ consists of an object $A \\in \\AA$ and\n\tan element $u \\in X(A)$ satisfying a certain condition.\n\tYou can read this off the condition\\footnote{%\n\t\tJust for completeness, the condition is:\n\t\tFor all $A' \\in \\AA$ and $x \\in X(A')$, there's a unique $f : A \\to A'$ with $(Xf)(u) = x$.\n\t} if you know what the inverse map is in \\Cref{thm:yoneda}.\n\tIn the above situation, $X = U$, $A = \\ZZ$ and $u = \\pm 1$.\n\\end{enumerate}\n\n\\section\\problemhead\n\n\\begin{problem}\n\tShow that the two definitions of natural transformation\n\t(one in terms of $\\AA \\times \\mathbf 2 \\to \\BB$\n\tand one in terms of arrows $F(A) \\taking{\\alpha_A} G(A)$) \n\tare equivalent.\n\t\\begin{hint}\n\t\tThe category $\\AA \\times \\mathbf 2$ has ``redundant arrows''.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe main observation is that in $\\AA \\times \\mathbf 2$,\n\t\tyou have the arrows in $\\AA$ (of the form $(f, \\id_{\\mathbf 2})$),\n\t\tand then the arrows crossing the two copies of $\\AA$ (of the form $(\\id_A, 0 \\le 1)$).\n\t\tBut there are some more arrows $(f, 0 \\le 1)$: nonetheless, they can be thought of as compositions\n\t\t\\[ (f, 0 \\le 1) = (f, \\id_{\\mathbf 2}) \\circ (\\id_A, 0 \\le 1) = (\\id_A, 0 \\le 1) \\circ (f, \\id_{\\mathbf 2}). \\]\n\t\tNow we want to specify a functor $\\alpha : \\AA \\times \\mathbf 2$, we only have to specify\n\t\twhere each of these two more basic things goes.\n\t\tThe conditions on $\\alpha$ already tells us that $(f, \\id_{\\mathbf 2})$ should be mapped to $F(f)$ or $G(f)$\n\t\t(depending on whether the arrow above is in $\\AA \\times \\{0\\}$ or $\\AA \\times \\{1\\}$),\n\t\tand specifying the arrow $(\\id_A, 0 \\le 1)$ amounts to specifying the $A$th component.\n\t\tWhere does naturality come in?\n\n\t\tThe above discussion transfers to products of categories in general:\n\t\tyou really only have to think about $(f, \\id)$ and $(\\id, g)$ arrows\n\t\tto get the general arrow $(f,g) = (f, \\id) \\circ (\\id, g) = (\\id, g) \\circ (f, \\id)$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tLet $\\AA$ be the category of finite sets whose arrows are bijections between sets.\n\tFor $A \\in \\AA$,\n\t\tlet $F(A)$ be the set of \\emph{permutations} of $A$ and\n\t\tlet $G(A)$ be the set of \\emph{orderings} on $A$.\\footnote{\n\t\t\tA permutation is a bijection $A \\to A$,\n\t\t\tand an ordering is a bijection $\\{1, \\dots, n\\} \\to A$,\n\t\t\twhere $n$ is the size of $A$.}\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Extend $F$ and $G$ to functors $\\AA \\to \\catname{Set}$.\n\t\t\\ii Show that $F(A) \\cong G(A)$ for every $A$, but this isomorphism is \\emph{not} natural.\n\t\\end{enumerate}\n\\end{problem}\n\n\n\n\\begin{problem}\n\t[Proving the Yoneda lemma]\n\tIn the context of \\Cref{thm:yoneda}:\n\t\\begin{enumerate}[(a)]\n\t\\ii Prove that the map described is in fact a bijection.\n\t(To do this, you will probably have to explicitly write down the inverse map.)\n\n\t\\ii \\yod Prove that the bijection is indeed natural.\n\t(This is long-winded, but not difficult; from start to finish,\n\tthere is only one thing you can possibly do.)\n\t\\end{enumerate}\n\\end{problem}\n\n%\tThe bijection is defined as follows:\n%\t\\begin{itemize}\n%\t\t\\ii For $\\alpha$ on the right-hand side, we take the element $\\alpha_A(\\id_A) \\in X(A)$.\n%\t\t\\ii For $x \\in X(A)$, its image in the right-hand side is the $\\alpha$\n%\t\twith $\\alpha_{A'} : H_A(A') \\to X(A')$ by $(A' \\taking f A) \\mapsto (Xf)(x)$.\n%\t\\end{itemize}\n", "meta": {"hexsha": "471345f0cd1f1a75a9ba7104bc2b504e5efe3990", "size": 29299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/cats/functors.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/functors.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/functors.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.4059259259, "max_line_length": 113, "alphanum_fraction": 0.6754838049, "num_tokens": 9968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.6869254759283618}}
{"text": "\\chapter{IMO Shortlist Algebra Problems A1-3 from year 1998-2017}\n\n\n\n\n\\newpage\\section{A1}\n\n\n\\prob{}{}{}{Let $a_{1},a_{2},\\ldots ,a_{n}$ be positive real numbers such that $a_{1}+a_{2}+\\cdots +a_{n}<1$. Prove that\n\n\\[ \\frac{a_{1} a_{2} \\cdots a_{n} \\left[ 1 - (a_{1} + a_{2} + \\cdots + a_{n}) \\right] }{(a_{1} + a_{2} + \\cdots + a_{n})( 1 - a_{1})(1 - a_{2}) \\cdots (1 - a_{n})} \\leq \\frac{1}{ n^{n+1}}. \\]}\n\n\n\n\n\\prob{}{}{}{Let $n \\geq 2$ be a fixed integer. Find the least constant $C$ such the inequality\n\n\\[\\sum_{i<j} x_{i}x_{j} \\left(x^{2}_{i}+x^{2}_{j} \\right) \\leq C \\left(\\sum_{i}x_{i} \\right)^4\\]\n\nholds for any $x_{1}, \\ldots ,x_{n} \\geq 0$ (the sum on the left consists of $\\binom{n}{2}$ summands). For this constant $C$, characterize the instances of equality.}\n\n\n\n\n\n\\prob{}{}{}{Let $ a, b, c$ be positive real numbers so that $ abc = 1$. Prove that\n\\[ \\left( a - 1 + \\frac 1b \\right) \\left( b - 1 + \\frac 1c \\right) \\left( c - 1 + \\frac 1a \\right) \\leq 1. \\]}\n\n\n\\prob{}{}{}{Let $ T$ denote the set of all ordered triples $ (p,q,r)$ of nonnegative integers. Find all functions $ f: T \\rightarrow \\mathbb{R}$ satisfying\n\\[ f(p,q,r) = \\begin{cases} 0 & \\text{if} \\; pqr = 0, \\\\ 1 + \\frac{1}{6}\\{f(p + 1,q - 1,r) + f(p - 1,q + 1,r) & \\\\ + f(p - 1,q,r + 1) + f(p + 1,q,r - 1) & \\\\ + f(p,q + 1,r - 1) + f(p,q - 1,r + 1)\\} & \\text{otherwise} \\end{cases} \\]\nfor all nonnegative integers $ p$, $ q$, $ r$.}\n\n\n\n\n\\prob{}{}{}{Find all functions $f$ from the reals to the reals such that\n\n\\[f\\left(f(x)+y\\right)=2x+f\\left(f(y)-x\\right)\\]\n\nfor all real $x,y$.}\n\n\n\n\n\\prob{}{}{}{Let $a_{ij}$ $i=1,2,3$; $j=1,2,3$ be real numbers such that $a_{ij}$ is positive for $i=j$ and negative for $i\\neq j$.\n\nProve the existence of positive real numbers $c_{1}$, $c_{2}$, $c_{3}$ such that the numbers \\[a_{11}c_{1}+a_{12}c_{2}+a_{13}c_{3},\\qquad a_{21}c_{1}+a_{22}c_{2}+a_{23}c_{3},\\qquad a_{31}c_{1}+a_{32}c_{2}+a_{33}c_{3}\\]are either all negative, all positive, or all zero.}\n\n\n\n\\prob{}{}{}{Let $n \\geq 3$ be an integer. Let $t_1$, $t_2$, ..., $t_n$ be positive real numbers such that \\[n^2 + 1 > \\left( t_1 + t_2 + \\cdots + t_n \\right) \\left( \\frac{1}{t_1} + \\frac{1}{t_2} + \\cdots + \\frac{1}{t_n} \\right).\\] Show that $t_i$, $t_j$, $t_k$ are side lengths of a triangle for all $i$, $j$, $k$ with $1 \\leq i < j < k \\leq n$.}\n\n\n\n\\prob{}{}{}{Find all pairs of integers $a,b$ for which there exists a polynomial $P(x) \\in \\mathbb{Z}[X]$ such that product $(x^2+ax+b)\\cdot P(x)$ is a polynomial of a form \\[ x^n+c_{n-1}x^{n-1}+\\cdots+c_1x+c_0 \\]}\n\n\n\n\\prob{}{}{}{A sequence of real numbers $ a_{0},\\ a_{1},\\ a_{2},\\dots$ is defined by the formula\n\\[ a_{i + 1} = \\left\\lfloor a_{i}\\right\\rfloor\\cdot \\left\\langle a_{i}\\right\\rangle\\qquad\\text{for}\\quad i\\geq 0; \\]here $a_0$ is an arbitrary real number, $\\lfloor a_i\\rfloor$ denotes the greatest integer not exceeding $a_i$, and $\\left\\langle a_i\\right\\rangle=a_i-\\lfloor a_i\\rfloor$. Prove that $a_i=a_{i+2}$ for $i$ sufficiently large.}\n\n\n\n\n\\prob{}{}{}{Real numbers $ a_{1}$, $ a_{2}$, $ \\ldots$, $ a_{n}$ are given. For each $ i$, $ (1 \\leq i \\leq n )$, define\n\\[ d_{i} = \\max \\{ a_{j}\\mid 1 \\leq j \\leq i \\} - \\min \\{ a_{j}\\mid i \\leq j \\leq n \\} \\]\nand let $ d = \\max \\{d_{i}\\mid 1 \\leq i \\leq n \\}$.\n\n(a) Prove that, for any real numbers $ x_{1}\\leq x_{2}\\leq \\cdots \\leq x_{n}$,\n\\[ \\max \\{ |x_{i} - a_{i}| \\mid 1 \\leq i \\leq n \\}\\geq \\frac {d}{2}. \\quad \\quad (*) \\]\n(b) Show that there are real numbers $ x_{1}\\leq x_{2}\\leq \\cdots \\leq x_{n}$ such that the equality holds in (*).}\n\n\n\n\n\\prob{}{}{}{Find all functions $ f: (0, \\infty) \\mapsto (0, \\infty)$ (so $ f$ is a function from the positive real numbers) such that\n\\[ \\frac {\\left( f(w) \\right)^2 + \\left( f(x) \\right)^2}{f(y^2) + f(z^2) } = \\frac {w^2 + x^2}{y^2 + z^2} \\]\nfor all positive real numbers $ w,x,y,z,$ satisfying $ wx = yz.$}\n\n\n\n\n\\prob{}{}{}{Find the largest possible integer $k$, such that the following statement is true:\nLet $2009$ arbitrary non-degenerated triangles be given. In every triangle the three sides are coloured, such that one is blue, one is red and one is white. Now, for every colour separately, let us sort the lengths of the sides. We obtain\n\\[ \\left. \\begin{array}{rcl} & b_1 \\leq b_2\\leq\\ldots\\leq b_{2009} & \\textrm{the lengths of the blue sides }\\\\ & r_1 \\leq r_2\\leq\\ldots\\leq r_{2009} & \\textrm{the lengths of the red sides }\\\\ \\textrm{and } & w_1 \\leq w_2\\leq\\ldots\\leq w_{2009} & \\textrm{the lengths of the white sides }\\\\ \\end{array}\\right.\\]\nThen there exist $k$ indices $j$ such that we can form a non-degenerated triangle with side lengths $b_j$, $r_j$, $w_j$.}\n\n\n\n\\prob{}{}{}{Find all function $f:\\mathbb{R}\\rightarrow\\mathbb{R}$ such that for all $x,y\\in\\mathbb{R}$ the following equality holds \\[ f(\\left\\lfloor x\\right\\rfloor y)=f(x)\\left\\lfloor f(y)\\right\\rfloor \\] where $\\left\\lfloor a\\right\\rfloor $ is greatest integer not greater than $a.$}\n\n\n\n\\prob{}{}{}{Given any set $A = \\{a_1, a_2, a_3, a_4\\}$ of four distinct positive integers, we denote the sum $a_1 +a_2 +a_3 +a_4$ by $s_A$. Let $n_A$ denote the number of pairs $(i, j)$ with $1 \\leq i < j \\leq 4$ for which $a_i +a_j$ divides $s_A$. Find all sets $A$ of four distinct positive integers which achieve the largest possible value of $n_A$.}\n\n\n\n\n\\prob{}{}{}{Find all functions $f:\\mathbb Z\\rightarrow \\mathbb Z$ such that, for all integers $a,b,c$ that satisfy $a+b+c=0$, the following equality holds:\n\\[f(a)^2+f(b)^2+f(c)^2=2f(a)f(b)+2f(b)f(c)+2f(c)f(a).\\]\n(Here $\\mathbb{Z}$ denotes the set of integers.)}\n\n\n\n\\prob{}{}{}{Let $n$ be a positive integer and let $a_1, \\ldots, a_{n-1} $ be arbitrary real numbers. Define the sequences $u_0, \\ldots, u_n $ and $v_0, \\ldots, v_n $ inductively by $u_0 = u_1 = v_0 = v_1 = 1$, and $u_{k+1} = u_k + a_k u_{k-1}$, $v_{k+1} = v_k + a_{n-k} v_{k-1}$ for $k=1, \\ldots, n-1.$\n\nProve that $u_n = v_n.$}\n\n\n\n\\prob{}{}{}{Let $a_0 < a_1 < a_2 \\ldots$ be an infinite sequence of positive integers. Prove that there exists a unique integer $n\\geq 1$ such that\n\\[a_n < \\frac{a_0+a_1+a_2+\\cdots+a_n}{n} \\leq a_{n+1}.\\]}\n\n\n\n\n\\prob{}{}{}{Suppose that a sequence $a_1,a_2,\\ldots$ of positive real numbers satisfies \\[a_{k+1}\\geq\\frac{ka_k}{a_k^2+(k-1)}\\]for every positive integer $k$. Prove that $a_1+a_2+\\ldots+a_n\\geq n$ for every $n\\geq2$.}\n\n\n\n\\prob{}{}{}{Let $a$, $b$, $c$ be positive real numbers such that $\\min(ab,bc,ca) \\ge 1$. Prove that $$\\sqrt[3]{(a^2+1)(b^2+1)(c^2+1)} \\le \\left(\\frac{a+b+c}{3}\\right)^2 + 1.$$}\n\n\n\n\\prob{}{}{}{Let $a_1,a_2,\\ldots a_n,k$, and $M$ be positive integers such that\n$$\\frac{1}{a_1}+\\frac{1}{a_2}+\\cdots+\\frac{1}{a_n}=k\\quad\\text{and}\\quad a_1a_2\\cdots a_n=M.$$If $M>1$, prove that the polynomial\n$$P(x)=M(x+1)^k-(x+a_1)(x+a_2)\\cdots (x+a_n)$$has no positive roots.}\n\n\n\n\n\n\n\\newpage\\section{A2}\n\n\n\\prob{}{}{}{Let $r_{1},r_{2},\\ldots ,r_{n}$ be real numbers greater than or equal to 1. Prove that\n\n\\[ \\frac{1}{r_{1} + 1} + \\frac{1}{r_{2} + 1} + \\cdots +\\frac{1}{r_{n}+1} \\geq \\frac{n}{ \\sqrt[n]{r_{1}r_{2} \\cdots r_{n}}+1}. \\]\n}\n\\prob{}{}{}{The numbers from 1 to $n^2$ are randomly arranged in the cells of a $n \\times n$ square ($n \\geq 2$). For any pair of numbers situated on the same row or on the same column the ratio of the greater number to the smaller number is calculated. Let us call the characteristic of the arrangement the smallest of these $n^2\\left(n-1\\right)$ fractions. What is the highest possible value of the characteristic ?\n}\n\n\\prob{}{}{}{Let $ a, b, c$ be positive integers satisfying the conditions $ b > 2a$ and $ c > 2b.$ Show that there exists a real number $ \\lambda$ with the property that all the three numbers $ \\lambda a, \\lambda b, \\lambda c$ have their fractional parts lying in the interval $ \\left(\\frac {1}{3}, \\frac {2}{3} \\right].$\n\n}\n\\prob{}{}{}{Let $a_0, a_1, a_2, \\ldots$ be an arbitrary infinite sequence of positive numbers. Show that the inequality $1 + a_n > a_{n-1} \\sqrt[n]{2}$ holds for infinitely many positive integers $n$.\n}\n\n\\prob{}{}{}{Let $a_1,a_2,\\ldots$ be an infinite sequence of real numbers, for which there exists a real number $c$ with $0\\leq a_i\\leq c$ for all $i$, such that \\[\\left\\lvert a_i-a_j \\right\\rvert\\geq \\frac{1}{i+j} \\quad \\text{for all }i,\\ j \\text{ with } i \\neq j. \\] Prove that $c\\geq1$.\n}\n\n\\prob{}{}{}{Find all nondecreasing functions $f: \\mathbb{R}\\rightarrow\\mathbb{R}$ such that\n(i) $f(0) = 0, f(1) = 1;$\n(ii) $f(a) + f(b) = f(a)f(b) + f(a + b - ab)$ for all real numbers $a, b$ such that $a < 1 < b$.\n}\n\n\n\\prob{}{}{}{Let $a_0$, $a_1$, $a_2$, ... be an infinite sequence of real numbers satisfying the equation $a_n=\\left|a_{n+1}-a_{n+2}\\right|$ for all $n\\geq 0$, where $a_0$ and $a_1$ are two different positive reals.\n\nCan this sequence $a_0$, $a_1$, $a_2$, ... be bounded?\n}\n\n\\prob{}{}{}{We denote by $\\mathbb{R}^+$ the set of all positive real numbers.\n\nFind all functions $f: \\mathbb R^ + \\rightarrow\\mathbb R^ +$ which have the property:\n\\[f(x)f(y)=2f(x+yf(x))\\]\nfor all positive real numbers $x$ and $y$.\n\n}\n\n\\prob{}{}{}{The sequence of real numbers $a_0,a_1,a_2,\\ldots$ is defined recursively by \\[a_0=-1,\\qquad\\sum_{k=0}^n\\dfrac{a_{n-k}}{k+1}=0\\quad\\text{for}\\quad n\\geq 1.\\]Show that $ a_{n} > 0$ for all $ n\\geq 1$.\n}\n\n\n\\prob{}{}{}{Consider those functions $ f: \\mathbb{N} \\mapsto \\mathbb{N}$ which satisfy the condition\n\\[ f(m + n) \\geq f(m) + f(f(n)) - 1 \\]\nfor all $ m,n \\in \\mathbb{N}.$ Find all possible values of $ f(2007).$\n}\n\n\n\\prob{}{}{}{(a) Prove that\n\\[\\frac {x^{2}}{\\left(x - 1\\right)^{2}} + \\frac {y^{2}}{\\left(y - 1\\right)^{2}} + \\frac {z^{2}}{\\left(z - 1\\right)^{2}} \\geq 1\\] for all real numbers $x$, $y$, $z$, each different from $1$, and satisfying $xyz=1$.\n\n(b) Prove that equality holds above for infinitely many triples of rational numbers $x$, $y$, $z$, each different from $1$, and satisfying $xyz=1$.\n}\n\n\\prob{}{}{}{Let $a$, $b$, $c$ be positive real numbers such that $\\dfrac{1}{a} + \\dfrac{1}{b} + \\dfrac{1}{c} = a+b+c$. Prove that:\n\\[\\frac{1}{(2a+b+c)^2}+\\frac{1}{(a+2b+c)^2}+\\frac{1}{(a+b+2c)^2}\\leq \\frac{3}{16}.\\]\n}\n\n\\prob{}{}{}{Let the real numbers $a,b,c,d$ satisfy the relations $a+b+c+d=6$ and $a^2+b^2+c^2+d^2=12.$ Prove that\n\\[36 \\leq 4 \\left(a^3+b^3+c^3+d^3\\right) - \\left(a^4+b^4+c^4+d^4 \\right) \\leq 48.\\]\n}\n\n\n\\prob{}{}{}{Determine all sequences $(x_1,x_2,\\ldots,x_{2011})$ of positive integers, such that for every positive integer $n$ there exists an integer $a$ with \\[\\sum^{2011}_{j=1} j x^n_j = a^{n+1} + 1\\]\n}\n\n\n\\prob{}{}{}{Let $\\mathbb{Z}$ and $\\mathbb{Q}$ be the sets of integers and rationals respectively.\na) Does there exist a partition of $\\mathbb{Z}$ into three non-empty subsets $A,B,C$ such that the sets $A+B, B+C, C+A$ are disjoint?\nb) Does there exist a partition of $\\mathbb{Q}$ into three non-empty subsets $A,B,C$ such that the sets $A+B, B+C, C+A$ are disjoint?\n\nHere $X+Y$ denotes the set $\\{ x+y : x \\in X, y \\in Y \\}$, for $X,Y \\subseteq \\mathbb{Z}$ and for $X,Y \\subseteq \\mathbb{Q}$.\n}\n\n\\prob{}{}{}{Prove that in any set of $2000$ distinct real numbers there exist two pairs $a>b$ and $c>d$ with $a \\neq c$ or $b \\neq d $, such that \\[ \\left| \\frac{a-b}{c-d} - 1 \\right|< \\frac{1}{100000}. \\]\n}\n\n\n\\prob{}{}{}{Define the function $f:(0,1)\\to (0,1)$ by \\[\\displaystyle f(x) = \\left\\{ \\begin{array}{lr} x+\\frac 12 & \\text{if}\\ \\ x < \\frac 12\\\\ x^2 & \\text{if}\\ \\ x \\ge \\frac 12 \\end{array} \\right.\\] Let $a$ and $b$ be two real numbers such that $0 < a < b < 1$. We define the sequences $a_n$ and $b_n$ by $a_0 = a, b_0 = b$, and $a_n = f( a_{n -1})$, $b_n = f (b_{n -1} )$ for $n > 0$. Show that there exists a positive integer $n$ such that \\[(a_n - a_{n-1})(b_n-b_{n-1})<0.\\]\n}\n\n\\prob{}{}{}{Determine all functions $f:\\mathbb{Z}\\rightarrow\\mathbb{Z}$ with the property that \\[f(x-f(y))=f(f(x))-f(y)-1\\]holds for all $x,y\\in\\mathbb{Z}$.\n}\n\n\\prob{}{}{}{Find the smallest constant $C > 0$ for which the following statement holds: among any five positive real numbers $a_1,a_2,a_3,a_4,a_5$ (not necessarily distinct), one can always choose distinct subscripts $i,j,k,l$ such that\n\\[ \\left| \\frac{a_i}{a_j} - \\frac {a_k}{a_l} \\right| \\le C. \\]\n}\n\n\\prob{}{}{}{Let $q$ be a real number. Gugu has a napkin with ten distinct real numbers written on it, and he writes the following three lines of real numbers on the blackboard:\n\n    In the first line, Gugu writes down every number of the form $a-b$, where $a$ and $b$ are two (not necessarily distinct) numbers on his napkin.\n    In the second line, Gugu writes down every number of the form $qab$, where $a$ and $b$ are\n    two (not necessarily distinct) numbers from the first line.\n    In the third line, Gugu writes down every number of the form $a^2+b^2-c^2-d^2$, where $a, b, c, d$ are four (not necessarily distinct) numbers from the first line.\n\nDetermine all values of $q$ such that, regardless of the numbers on Gugu's napkin, every number in the second line is also a number in the third line.\n}\n\n\n\n\n\\newpage\\section{A3}\n\n\n\\prob{}{}{}{Let $x,y$ and $z$ be positive real numbers such that $xyz=1$. Prove that\n\n\n\\[ \\frac{x^{3}}{(1 + y)(1 + z)}+\\frac{y^{3}}{(1 + z)(1 + x)}+\\frac{z^{3}}{(1 + x)(1 + y)} \\geq \\frac{3}{4}. \\]\n}\n\n\n\n\n\\prob{}{}{}{A game is played by $n$ girls ($n \\geq 2$), everybody having a ball. Each of the $\\binom{n}{2}$ pairs of players, is an arbitrary order, exchange the balls they have at the moment. The game is called nice nice if at the end nobody has her own ball and it is called tiresome if at the end everybody has her initial ball. Determine the values of $n$ for which there exists a nice game and those for which there exists a tiresome game.}\n\n\n\n\n\\prob{}{}{}{Find all pairs of functions $ f : \\mathbb R \\to \\mathbb R$, $g : \\mathbb R \\to \\mathbb R$ such that \\[f \\left( x + g(y) \\right) = xf(y) - y f(x) + g(x) \\quad\\text{for all } x, y\\in\\mathbb{R}.\\]\n}\n\n\n\n\\prob{}{}{}{Let $x_1,x_2,\\ldots,x_n$ be arbitrary real numbers. Prove the inequality\n\n\\[ \\frac{x_1}{1+x_1^2} + \\frac{x_2}{1+x_1^2 + x_2^2} + \\cdots + \\frac{x_n}{1 + x_1^2 + \\cdots + x_n^2} < \\sqrt{n}. \\]\n}\n\n\\prob{}{}{}{Let $P$ be a cubic polynomial given by $P(x)=ax^3+bx^2+cx+d$, where $a,b,c,d$ are integers and $a\\ne0$. Suppose that $xP(x)=yP(y)$ for infinitely many pairs $x,y$ of integers with $x\\ne y$. Prove that the equation $P(x)=0$ has an integer root.\n}\n\n\\prob{}{}{}{Consider pairs of the sequences of positive real numbers \\[a_1\\geq a_2\\geq a_3\\geq\\cdots,\\qquad b_1\\geq b_2\\geq b_3\\geq\\cdots\\]and the sums \\[A_n = a_1 + \\cdots + a_n,\\quad B_n = b_1 + \\cdots + b_n;\\qquad n = 1,2,\\ldots.\\]For any pair define $c_n = \\min\\{a_i,b_i\\}$ and $C_n = c_1 + \\cdots + c_n$, $n=1,2,\\ldots$.\n\n\n(1) Does there exist a pair $(a_i)_{i\\geq 1}$, $(b_i)_{i\\geq 1}$ such that the sequences $(A_n)_{n\\geq 1}$ and $(B_n)_{n\\geq 1}$ are unbounded while the sequence $(C_n)_{n\\geq 1}$ is bounded?\n\n(2) Does the answer to question (1) change by assuming additionally that $b_i = 1/i$, $i=1,2,\\ldots$?\n\nJustify your answer.\n}\n\n\n\\prob{}{}{}{Does there exist a function $s\\colon \\mathbb{Q} \\rightarrow \\{-1,1\\}$ such that if $x$ and $y$ are distinct rational numbers satisfying ${xy=1}$ or ${x+y\\in \\{0,1\\}}$, then ${s(x)s(y)=-1}$? Justify your answer.\n}\n\n\n\n\\prob{}{}{}{Four real numbers $ p$, $ q$, $ r$, $ s$ satisfy $ p+q+r+s = 9$ and $ p^{2}+q^{2}+r^{2}+s^{2}= 21$. Prove that there exists a permutation $ \\left(a,b,c,d\\right)$ of $ \\left(p,q,r,s\\right)$ such that $ ab-cd \\geq 2$.}\n\n\n\\prob{}{}{}{The sequence $c_{0}, c_{1}, . . . , c_{n}, . . .$ is defined by $c_{0}= 1, c_{1}= 0$, and $c_{n+2}= c_{n+1}+c_{n}$ for $n \\geq 0$. Consider the set $S$ of ordered pairs $(x, y)$ for which there is a finite set $J$ of positive integers such that $x=\\textstyle\\sum_{j \\in J}{c_{j}}$, $y=\\textstyle\\sum_{j \\in J}{c_{j-1}}$. Prove that there exist real numbers $\\alpha$, $\\beta$, and $M$ with the following property: An ordered pair of nonnegative integers $(x, y)$ satisfies the inequality \\[m < \\alpha x+\\beta y < M\\] if and only if $(x, y) \\in S$.\n}\n\n\n\\prob{}{}{}{Let $ n$ be a positive integer, and let $ x$ and $ y$ be a positive real number such that $ x^n + y^n = 1.$ Prove that\n\\[ \\left(\\sum^n_{k = 1} \\frac {1 + x^{2k}}{1 + x^{4k}} \\right) \\cdot \\left( \\sum^n_{k = 1} \\frac {1 + y^{2k}}{1 + y^{4k}} \\right) < \\frac {1}{(1 - x) \\cdot (1 - y)}. \\]\n}\n\n\n\n\\prob{}{}{}{Let $ S\\subseteq\\mathbb{R}$ be a set of real numbers. We say that a pair $ (f, g)$ of functions from $ S$ into $ S$ is a Spanish Couple on $ S$, if they satisfy the following conditions:\n(i) Both functions are strictly increasing, i.e. $ f(x) < f(y)$ and $ g(x) < g(y)$ for all $ x$, $ y\\in S$ with $ x < y$;\n\n(ii) The inequality $ f\\left(g\\left(g\\left(x\\right)\\right)\\right) < g\\left(f\\left(x\\right)\\right)$ holds for all $ x\\in S$.\n\nDecide whether there exists a Spanish Couple\n\n    on the set $ S = \\mathbb{N}$ of positive integers;\n    on the set $ S = \\{a - \\frac {1}{b}: a, b\\in\\mathbb{N}\\}$\n}\n\n\n\n\\prob{}{}{}{Determine all functions $ f$ from the set of positive integers to the set of positive integers such that, for all positive integers $ a$ and $ b$, there exists a non-degenerate triangle with sides of lengths\n\\[ a, f(b) \\text{ and } f(b + f(a) - 1).\\]\n(A triangle is non-degenerate if its vertices are not collinear.)\n}\n\n\n\\prob{}{}{}{Let $x_1, \\ldots , x_{100}$ be nonnegative real numbers such that $x_i + x_{i+1} + x_{i+2} \\leq 1$ for all $i = 1, \\ldots , 100$ (we put $x_{101 } = x_1, x_{102} = x_2).$ Find the maximal possible value of the sum $S = \\sum^{100}_{i=1} x_i x_{i+2}.$\n}\n\n\n\\prob{}{}{}{Determine all pairs $(f,g)$ of functions from the set of real numbers to itself that satisfy \\[g(f(x+y)) = f(x) + (2x + y)g(y)\\] for all real numbers $x$ and $y$.\n}\n\n\n\n\\prob{}{}{}{Let $n\\ge 3$ be an integer, and let $a_2,a_3,\\ldots ,a_n$ be positive real numbers such that $a_{2}a_{3}\\cdots a_{n}=1$. Prove that\n\\[(1 + a_2)^2 (1 + a_3)^3 \\dotsm (1 + a_n)^n > n^n.\\]\n}\n\n\n\n\\prob{}{}{}{Let $\\mathbb Q_{>0}$ be the set of all positive rational numbers. Let $f:\\mathbb Q_{>0}\\to\\mathbb R$ be a function satisfying the following three conditions:\n\n(i) for all $x,y\\in\\mathbb Q_{>0}$, we have $f(x)f(y)\\geq f(xy)$;\n(ii) for all $x,y\\in\\mathbb Q_{>0}$, we have $f(x+y)\\geq f(x)+f(y)$;\n(iii) there exists a rational number $a>1$ such that $f(a)=a$.\n\nProve that $f(x)=x$ for all $x\\in\\mathbb Q_{>0}$.\n}\n\n\n\n\\prob{}{}{}{For a sequence $x_1,x_2,\\ldots,x_n$ of real numbers, we define its $\\textit{price}$ as \\[\\max_{1\\le i\\le n}|x_1+\\cdots +x_i|.\\] Given $n$ real numbers, Dave and George want to arrange them into a sequence with a low price. Diligent Dave checks all possible ways and finds the minimum possible price $D$. Greedy George, on the other hand, chooses $x_1$ such that $|x_1 |$ is as small as possible; among the remaining numbers, he chooses $x_2$ such that $|x_1 + x_2 |$ is as small as possible, and so on. Thus, in the $i$-th step he chooses $x_i$ among the remaining numbers so as to minimise the value of $|x_1 + x_2 + \\cdots x_i |$. In each step, if several numbers provide the same value, George chooses one at random. Finally he gets a sequence with price $G$.\n\nFind the least possible constant $c$ such that for every positive integer $n$, for every collection of $n$ real numbers, and for every possible sequence that George might obtain, the resulting values satisfy the inequality $G\\le cD$.\n}\n\n\n\\prob{}{}{}{Let $n$ be a fixed positive integer. Find the maximum possible value of \\[ \\sum_{1 \\le r < s \\le 2n} (s-r-n)x_rx_s, \\]where $-1 \\le x_i \\le 1$ for all $i = 1, \\cdots , 2n$.\n}\n\n\n\n\\prob{}{}{}{Find all positive integers $n$ such that the following statement holds: Suppose real numbers $a_1$, $a_2$, $\\dots$, $a_n$, $b_1$, $b_2$, $\\dots$, $b_n$ satisfy $|a_k|+|b_k|=1$ for all $k=1,\\dots,n$. Then there exists $\\varepsilon_1$, $\\varepsilon_2$, $\\dots$, $\\varepsilon_n$, each of which is either $-1$ or $1$, such that\n\\[ \\left| \\sum_{i=1}^n \\varepsilon_i a_i \\right| + \\left| \\sum_{i=1}^n \\varepsilon_i b_i \\right| \\le 1. \\]\n}\n\n\n\\prob{}{}{}{Let $S$ be a finite set, and let $\\mathcal{A}$ be the set of all functions from $S$ to $S$. Let $f$ be an element of $\\mathcal{A}$, and let $T=f(S)$ be the image of $S$ under $f$. Suppose that $f\\circ g\\circ f\\ne g\\circ f\\circ g$ for every $g$ in $\\mathcal{A}$ with $g\\ne f$. Show that $f(T)=T$.\n}\n", "meta": {"hexsha": "5636c77009e55a0752240116acd43f718251d3b6", "size": 20203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PSets/ISL_Alg.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": "PSets/ISL_Alg.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": "PSets/ISL_Alg.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": 56.4329608939, "max_line_length": 774, "alphanum_fraction": 0.6284215216, "num_tokens": 7687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6869254742443734}}
{"text": "\\section{Power Series}\\label{sec:powerseries}\n\nRecall that the sum of a geometric series can be expressed using the simple formula:\n\\[\\sum_{n=0}^\\infty kx^n = {k\\over 1-x},\\]\nif $|x|<1$, and that the series diverges when $|x|\\ge 1$. At the time,\nwe thought of $x$ as an unspecified constant, but we could just as\nwell think of it as a variable, in which case the series\n\\[\\sum_{n=0}^\\infty kx^n\\]\nis a function, namely, the function $k/(1-x)$, as long as\n$|x|<1$: Looking at this from the opposite perspective, this means that\nthe function $k/(1-x)$ can be represented as the sum of an infinite series. Why would this be useful?\nWhile $k/(1-x)$ is a reasonably easy function to deal with,\nthe more complicated representation $\\sum kx^n$ does have some advantages:\nit appears to be an infinite version of one of the\nsimplest function types---a polynomial. Later on we will investigate some of the ways\nwe can take advantage of this `infinite polynomial' representation, but first\nwe should ask if other functions can even be represented this way.\n\nThe geometric series has a special feature that makes it unlike a\ntypical polynomial---the coefficients of the powers of $x$ are all the\nsame, namely $k$. We will need to allow more general coefficients if\nwe are to get anything other than the geometric series. \n\n\\begin{definition}{Power Series}{PowerSeriesDefinition}\nA power series is a series of the form \n$$\\ds\\sum_{n=0}^\\infty a_nx^n,$$ \nwhere each $a_n$ is a real number.\n\\end{definition}\n\nAs we did in the section on sequences, we can think of the $a_n$ as being a function\n$a(n)$ defined on the non-negative integers. Note, however, that the $a_n$ do not depend\non $x$.\n\n\\begin{example}{}{}\nDetermine whether the power series $\\ds\\sum_{n=1}^\\infty {x^n\\over n}$ converges.\n\\end{example}\n\\begin{solution}\nWe can investigate convergence using the ratio test:\n\\[\n  \\lim_{n\\to\\infty} {|x|^{n+1}\\over n+1}{n\\over |x|^n}\n  =\\lim_{n\\to\\infty} |x|{n\\over n+1} =|x|.\n\\]\n\nThus when $|x|<1$ the series converges and when $|x|>1$ it diverges,\nleaving only two values in doubt. When $x=1$ the series is the\nharmonic series and diverges; when $x=-1$ it is the alternating\nharmonic series (actually the negative of the usual alternating\nharmonic series) and converges. Thus, we may think of \n$\\ds\\sum_{n=1}^\\infty {x^n\\over n}$ as a function from the interval\n$[-1,1)$ to the real numbers.\n\\end{solution}\n\nA bit of thought reveals that the ratio test applied to a power series\nwill always have the same nice form. In general, we will compute\n\\[\n  \\lim_{n\\to\\infty} {|a_{n+1}||x|^{n+1}\\over |a_n||x|^n}\n  =\\lim_{n\\to\\infty} |x|{|a_{n+1}|\\over |a_n|} =\n  |x|\\lim_{n\\to\\infty} {|a_{n+1}|\\over |a_n|} =L|x|,\n\\]\nassuming that $\\ds \\lim |a_{n+1}|/|a_n|$ exists. Then the series\nconverges if $L|x|<1$, that is, if $|x|<1/L$, and diverges if\n$|x|>1/L$. Only the two values $x=\\pm1/L$ require further\ninvestigation. Thus the series will always define a function on\nthe interval $(-1/L,1/L)$, that perhaps will extend to one or both\nendpoints as well. Two special cases deserve mention: if $L=0$ the\nlimit is $0$ no matter what value $x$ takes, so the series converges\nfor all $x$ and the function is defined for all real numbers. If\n$L=\\infty$, then no matter what value $x$ takes the limit is infinite\nand the series converges only when $x=0$. The value $1/L$ is called\nthe \\dfont{radius of convergence} of the series, and the\ninterval on which the series converges is the \\dfont{interval of\nconvergence}.\n\nWe can  make these ideas a bit more general. Consider the series\n\\[\\ds\\sum_{n=0}^{\\infty}\\frac{(x+2)^n}{3^n}\\]\nThis looks a lot like a power series, but with $(x+2)^n$ instead of $x^n$.\nLet's try to determine the values of $x$ for which it converges.\nThis is just a geometric series, so it converges when\n\\begin{align*}\n  |x+2|/3&<1\t\\\\\n  |x+2|&<3\t\\\\\n  -3 < x+2 &< 3\t\\\\\n  -5<x&<1.\t\\\\\n\\end{align*}\n\nSo the interval of convergence for this series is $(-5,1)$. The center\nof this interval is at $-2$, which is at distance 3 from the endpoints,\nso the radius of convergence is 3, and we say that the series is centered at $-2$.\n\nInterestingly, if we compute the sum of the series we get\n\\[\\ds\\sum_{n=0}^{\\infty}\\left(\\frac{x+2}{3}\\right)^n=\\frac{1}{1-\\frac{x+2}{3}}=\\frac{3}{1-x}.\\]\nMultiplying both sides by 1/3 we obtain\n\\[\\sum_{n=0}^\\infty {(x+2)^n\\over 3^{n+1}}={1\\over 1-x},\\]\nwhich we recognize as being equal to\n\\[\\sum_{n=0}^{\\infty}x^n,\\]\nso we have two series with the same sum but different intervals of convergence.\n\nThis leads to the following definition:\n\n\\begin{definition}{Power Series}{PowerSeriesDefinition2}\nA power series centered at $c$ has the form\n$$\\ds\\sum_{n=0}^\\infty a_n(x-c)^n,$$ \nwhere $c$ and each $a_n$ are real numbers.\n\\end{definition}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:powerseries}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind the radius and interval of convergence for each series.  In\npart c),\ndo not attempt to determine whether the endpoints are in the\ninterval of convergence.\n\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item $\\ds\\sum_{n=0}^\\infty n x^n$\n\t\\item $\\ds\\sum_{n=0}^\\infty {x^n\\over n!}$\n\t\\item $\\ds\\sum_{n=1}^\\infty {n!\\over n^n}(x-2)^n$\n\t\\item $\\ds\\sum_{n=1}^\\infty {(n!)^2\\over n^n}(x-2)^n$\n\t\\item $\\ds\\sum_{n=1}^\\infty {(x+5)^n\\over n(n+1)}$\n\\end{enumerate}\n\\end{multicols}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item $R=1$, $I=(-1,1)$\n\t\\item $R=\\infty$, $I=(-\\infty,\\infty)$\n\t\\item $R=e$, $I=(2-e,2+e)$\n\t\\item $R=0$, converges only when $x=2$\n\t\\item $R=1$, $I=[-6,-4]$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the radius of convergence for the series $\\ds\\sum_{n=1}^\\infty {n!\\over n^n}x^n$.\n\\begin{sol}\n$R=e$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n\n\\clearpage", "meta": {"hexsha": "6d219035e6663c3d14226eb03ef8d02a4d7f45c3", "size": 5790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9-sequences-and-series/9-8-power-series.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-8-power-series.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-8-power-series.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.387755102, "max_line_length": 101, "alphanum_fraction": 0.6929188256, "num_tokens": 1928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.9099070090919013, "lm_q1q2_score": 0.6869024378193757}}
{"text": "\\section{Ice Thickness Evolution}\nThe evolution of the ice thickness, $H$, stems from the continuity equation and can be expressed as\n\\begin{equation}\n  \\label{kin.eq.ice_thickness}\n  \\frac{\\pd H}{\\pd t} = -\\vec\\nabla\\cdot(\\overline{\\vec{u}} H) + B,\n\\end{equation}\nwhere $\\overline{\\vec{u}}$ is the vertically averaged ice velocity, $B$ is the surface mass balance and $\\vec\\nabla$ is the horizontal gradient operator \\citep{Payne1997}. \n\nFor large--scale ice sheet models, the \\emph{shallow ice approximation} is generally used. This approximation states that bedrock and ice surface slopes are assumed sufficiently small so that the normal stress components can be neglected \\citep{Hutter1983}. The horizontal shear stresses ($\\tau_{xz}$ and $\\tau_{yz}$) can thus be approximated by\n\\begin{equation}\n  \\label{kin.eq.horiz_shear}\n  \\begin{split}\n    \\tau_{xz}(z)&=-\\rho g(s-z)\\frac{\\pd s}{\\pd x},\\\\\n    \\tau_{yz}(z)&=-\\rho g(s-z)\\frac{\\pd s}{\\pd y},\n  \\end{split}\n\\end{equation}\nwhere $\\rho$ is the density of ice, $g$ the acceleration due to gravity and $s=H+h$ the ice surface.\n\nStrain rates $\\dot{\\epsilon}_{ij}$ of polycrystalline ice are related to the stress tensor by the non--linear flow law:\n\\begin{equation}\n  \\label{kin.eq.flowlaw}\n  \\dot{\\epsilon}_{iz}=\\frac12\\left(\\frac{\\pd u_i}{\\pd z}+\\frac{\\pd u_z}{\\pd i}\\right)=A(T^\\ast)\\tau_\\ast^{(n-1)}\\tau_{iz}\\qquad i=x,y,\n\\end{equation}\nwhere $\\tau_\\ast$ is the effective shear stress defined by the second invariant of the stress tensor, $n$ the flow law exponent and $A$ the temperature--dependent flow law coefficient. $T^\\ast$ is the absolute temperature corrected for the dependence of the melting point on pressure \\cite[$T^\\ast=T+8.7\\cdot10^{-4}(H+h-z)$, $T$ in Kelvin,][]{Huybrechts1986}. The parameters $A$ and $n$ have to be found by experiment. $n$ is usually taken to be 3. $A$ depends on factors such as temperature, crystal size and orientation, and ice impurities. Experiments suggest that $A$ follows the Arrhenius relationship:\n\\begin{equation}\n  \\label{kin.eq.arrhenius}\n  A(T^\\ast)=fae^{-Q/RT^\\ast},\n\\end{equation}where $a$ is a temperature--independent material constant, $Q$ is the activation energy for creep and $R$ is the universal gas constant \\citep{Paterson1994}. $f$ is a tuning parameter used to `speed--up' ice flow and accounts for ice impurities and the development of anisotropic ice fabrics \\citep{Payne1999,Tarasov1999,Tarasov2000,Peltier2000}.\n\nIntegrating \\eqref{kin.eq.arrhenius} with respect to $z$ gives the horizontal velocity profile:\n\\begin{equation}\n  \\label{kin.eq.horiz_velo}\n  \\vec u(z)-\\vec u(h) = -2(\\rho g)^n|\\vec\\nabla s|^{n-1}\\vec\\nabla s\\int_h^zA(s-z)^ndz,\n\\end{equation}\nwhere $\\vec u(h)$ is the basal velocity (sliding velocity). Integrating \\eqref{kin.eq.horiz_velo} again with respect to $z$ gives an expression for the vertically averaged ice velocity:\n\\begin{equation}\n  \\label{kin.eq.avg_velo}\n  \\overline{\\vec u}H=-2(\\rho g)^n|\\vec\\nabla s|^{n-1}\\vec\\nabla s\\int_h^s\\int_h^zA(s-z)^ndzdz'.\n\\end{equation}\n\nThe vertical ice velocity stems from the conservation of mass for an incompressible material:\n\\begin{equation}\n  \\label{kin.eq.incompress}\n  \\frac{\\pd u_x}{\\pd x} + \\frac{\\pd u_y}{\\pd y} + \\frac{\\pd u_z}{\\pd z} = 0.\n\\end{equation}\nIntegrating \\eqref{kin.eq.incompress} with respect to $z$ gives the vertical velocity distribution of each ice column:\n\\begin{equation}\n  \\label{kin.eq.vert_velo}\n  w(z)=-\\int_h^z\\vec\\nabla\\cdot\\vec u(z)dz+w(h),\n\\end{equation}\nwith lower, kinematic boundary condition\n\\begin{equation}\n  w(h)=\\frac{\\pd h}{\\pd t}+\\vec u(h)\\cdot\\vec\\nabla h+S,\n\\end{equation}\nwhere $S$ is the melt rate at the ice base given by Equation \\eqref{temp.eq.meltrate}. The upper kinematic boundary is given by the surface mass balance and must satisfy:\n\\begin{equation}\n  \\label{kin.eq.upper_bc}\n  w(s)=\\frac{\\pd s}{\\pd t}+\\vec u(s)\\cdot\\vec\\nabla s+B.\n\\end{equation}\n\n\\input{\\dir/grid.tex}\n\n\\subsection{Ice Sheet Equations in $\\sigma$--Coordinates}\nThe horizontal velocity, Equation \\eqref{kin.eq.horiz_velo}, becomes in the $\\sigma$--coordinate system\n\\begin{equation}\n  \\label{kin.eq.vert_velo_sigma}\n  \\vec u(\\sigma) = -2(\\rho g)^nH^{n+1}|\\vec\\nabla s|^{n-1}\\vec\\nabla s\\int_1^\\sigma A\\sigma^nd\\sigma+\\vec u(1)\n\\end{equation}\nand the vertically averaged velocity\n\\begin{equation}\n  \\label{kin.eq.avg_velo_scaled}\n  \\overline{\\vec u} H=H\\int_0^1\\vec ud\\sigma+\\vec u(1)H\n\\end{equation}\nThe vertical velocity, Equation \\eqref{kin.eq.vert_velo}, becomes\n\\begin{equation}\n  \\label{kin.eq.vert_velo_scaled}\n  w(\\sigma)=-\\int_1^\\sigma\\left(\\frac{\\pd\\vec u}{\\pd\\sigma}\\cdot(\\vec\\nabla s-\\sigma\\vec\\nabla H)+H\\vec\\nabla\\cdot\\vec u\\right)d\\sigma+w(1)\n\\end{equation}\nand lower boundary condition\n\\begin{equation}\n  w(1)=\\frac{\\pd h}{\\pd t}+\\vec u(1)\\cdot\\vec\\nabla h+S.\n\\end{equation}\n\n\\subsection{Calculating the Horizontal Velocity and the Diffusivity}\nHorizontal velocity and diffusivity calculations are split up into two parts:\n\\begin{subequations}\n  \\begin{align}\n    \\vec u(\\sigma)&=c\\vec\\nabla s+\\vec u(1)\\\\\n    D &=H\\int_0^1cd\\sigma\\\\\n    \\vec q&=D\\vec\\nabla s+H\\vec u(1)\\\\\n    \\intertext{with}\n    c(\\sigma)&=-2(\\rho g)^nH^{n+1}|\\vec\\nabla s|^{n-1}\\int_1^\\sigma A\\sigma^nd\\sigma\n  \\end{align}\n\\end{subequations}\n\nQuantities $\\vec u$ and $D$ are found on the velocity grid. Integrating from the ice base ($k=N-1$), the discretised quantities become\n\\begin{subequations}\n  \\begin{equation}\n    \\tilde{c}_{r,s,N}=0\n  \\end{equation}\n  \\begin{multline}\n    \\tilde{c}_{r,s,k}=-2(\\rho g)^nH_{r,s}^{n+1}\\left(({\\tilde{s}^x_{r,s}})^2+({\\tilde{s}^y_{r,s}})^2\\right)^{\\frac{n-1}{2}}\\\\\n    \\sum_{\\kappa=N-1}^k\\frac{A_{r,s,\\kappa}+A_{r,s,\\kappa+1}}2 \\left(\\frac{\\sigma_{\\kappa+1}+\\sigma_\\kappa}2\\right)^n(\\sigma_{\\kappa+1}-\\sigma_\\kappa)\n  \\end{multline}\n  \\begin{equation}\n    \\tilde{D}_{r,s}=H_{r,s}\\sum_{k=0}^{N-1}\\frac{\\tilde{c}_{r,s,k}+\\tilde{c}_{r,s,k+1}}2(\\sigma_{k+1}-\\sigma_k)\n  \\end{equation}\n\\end{subequations}\nExpressions for $\\vec{u}_{i,j,k}$ and $\\vec{q}_{i,j}$ are straight forward.\n\n\\subsection{Solving the Ice Thickness Evolution Equation}\nEquation \\eqref{kin.eq.ice_thickness} can be rewritten as a diffusion equation, with non--linear diffusion coefficient $D$:\n\\begin{equation}\n  \\label{kin.eq.ice_evo}\n  \\frac{\\pd H}{\\pd t}=-\\vec\\nabla\\cdot D\\vec\\nabla s+B=-\\vec\\nabla\\cdot\\vec q+B\n\\end{equation}\nThis non--linear partial differential equation can be linearised by using the diffusion coefficient from the previous time step. The diffusion coefficient is calculated on the $(r,s)$--grid, i.e. staggered in both $x$ and $y$ direction. Figure \\ref{kin.fig.staggered_grid} illustrates the staggered grid. Using finite differences, the fluxes in $x$ direction, $q^x$ become\n\\begin{subequations}\n\\begin{align}\n  q^x_{i+\\frac12,j}&=-\\frac12(\\tilde{D}_{r,s}+\\tilde{D}_{r,s-1})\\frac{s_{i+1,j}-s_{i,j}}{\\Delta x}\\\\\n  q^x_{i-\\frac12,j}&=-\\frac12(\\tilde{D}_{r-1,s}+\\tilde{D}_{r-1,s-1})\\frac{s_{i,j}-s_{i-1,j}}{\\Delta x}\\\\\n  \\intertext{and the fluxes in $y$ direction}\n  q^y_{i,j+\\frac12}&=-\\frac12(\\tilde{D}_{r,s}+\\tilde{D}_{r-1,s})\\frac{s_{i,j+1}-s_{i,j}}{\\Delta y}\\\\\n  q^y_{i,j-\\frac12}&=-\\frac12(\\tilde{D}_{r,s-1}+\\tilde{D}_{r-1,s-1})\\frac{s_{i,j}-s_{i,j-1}}{\\Delta y}.\n\\end{align}  \n\\end{subequations}\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics{\\dir/figs/staggered_grid.eps}\n  \\caption{Illustration of the staggered grid used to calculate ice thicknesses, diffusivities and mass fluxes.}\n  \\label{kin.fig.staggered_grid}\n\\end{figure}\n\n\\subsubsection{ADI Scheme}\nThe alternating--direction implicit method (ADI) uses the concept of operator splitting where Equation \\eqref{kin.eq.ice_evo} is first solved in the $x$--direction and then in the $y$--direction, \\citep{Press1992}. The time step $\\Delta t$ is devided into two time steps $\\Delta t/2$. The descretised version of Equation \\eqref{kin.eq.ice_evo} becomes \\citep{Huybrechts1986}:\n\\begin{subequations}\n\\begin{align}\n  \\label{kin.eq.adi_1}\n  2\\frac{H_{i,j}^{t+\\frac12}-H_{i,j}^{t}}{\\Delta t} &= -\\frac{q_{i+\\frac12,j}^{x,t+\\frac12}-q_{i-\\frac12,j}^{x,t+\\frac12}}{\\Delta x} - \\frac{q_{i,j+\\frac12}^{y,t}-q_{i,j-\\frac12}^{y,t}}{\\Delta y} + B_{i,j} \\\\\n  \\label{kin.eq.adi_2}\n  2\\frac{H_{i,j}^{t+1}-H_{i,j}^{t+\\frac12}}{\\Delta t} &= -\\frac{q_{i+\\frac12,j}^{x,t+\\frac12}-q_{i-\\frac12,j}^{x,t+\\frac12}}{\\Delta x} - \\frac{q_{i,j+\\frac12}^{y,t+1}-q_{i,j-\\frac12}^{y,t+1}}{\\Delta y} + B_{i,j}\n\\end{align}\n\\end{subequations}\nGathering all $t+\\frac12$ terms on the left side, Equation \\eqref{kin.eq.adi_1} can be expressed as a tri--diagonal set of equations for each row $j$:\n\\begin{equation}\n  -\\alpha_{i,j}H_{i-1,j}^{t+\\frac12} + (1-\\beta_{i,j})H_{i,j}^{t+\\frac12} - \\gamma_{i,j}H_{i+1,j}^{t+\\frac12} = \\delta_{i,j}\n\\end{equation}\nwith\n\\begin{subequations}\n  \\begin{align}\n  \\alpha_{i,j} &=\\frac{\\tilde{D}_{r-1,s}+\\tilde{D}_{r-1,s-1}}{4\\Delta x^2}\\Delta t\\\\\n  \\beta_{i,j}  &=-\\frac{\\tilde{D}_{r,s}+2\\tilde{D}_{r-1,s}+\\tilde{D}_{r-1,s-1}}{4\\Delta x^2}\\Delta t = -(\\alpha_{i,j}+\\gamma_{i,j})\\\\\n  \\gamma_{i,j} &=\\frac{\\tilde{D}_{r,s}+\\tilde{D}_{r,s-1}}{4\\Delta x^2}\\Delta t    \n  \\end{align}\nand the RHS,\n\\begin{equation}\n  \\delta_{i,j} = H_{i,j}^t-\\frac{\\Delta t}{2\\Delta y}\\left(q_{i,j+\\frac12}^{y,t}-q_{i,j-\\frac12}^{y,t}\\right) + \\frac{\\Delta t}2B_{i,j} + \\alpha_{i,j}h_{i-1,j} -\\beta_{i,j}h_{i,j} + \\gamma_{i,j}h_{i+1,j}.\n\\end{equation}\n\\end{subequations}\n\nA similar tri--diagonal system is found for each column, $i$ of Equation \\eqref{kin.eq.adi_2}.\n\n\\subsubsection{Linearised Semi--Implicit Scheme}\nUsing the Crank--Nicolson scheme, the semi--implicit temporal discretisation of \\eqref{kin.eq.ice_evo} is then:\n\\begin{multline}\n\\label{kin.eq.ice_evo_disc1}\n  \\frac{H^{t+1}_{i,j}-H^t_{i,j}}{\\Delta t}=\\frac{q^{x,t+1}_{i+\\frac12,j}-q^{x,t+1}_{i-\\frac12,j}}{2\\Delta x}+\\frac{q^{y,t+1}_{i,j+\\frac12}-q^{y,t+1}_{i,j-\\frac12}}{2\\Delta y} \\\\\n  +\\frac{q^{x,t}_{i+\\frac12,j}-q^{x,t}_{i-\\frac12,j}}{2\\Delta x}+\\frac{q^{y,t}_{i,j+\\frac12}-q^{y,t}_{i,j-\\frac12}}{2\\Delta y}+ B_{i,j}\n\\end{multline}\nThe superscripts $^t$ and $^{t+1}$ indicate at what time the ice thickness $H$ is evaluated. Collecting all $H^{t+1}$ terms of \\eqref{kin.eq.ice_evo_disc1} on the LHS and moving all other terms to the RHS we can rewrite \\eqref{kin.eq.ice_evo_disc1} as\n\\begin{equation}\n  \\label{kin.eq.evo_matrix}\n  -\\alpha_{i,j}H^{t+1}_{i-1,j} - \\beta_{i,j}H^{t+1}_{i+1,j} - \\gamma_{i,j}H^{t+1}_{i,j-1} - \\delta_{i,j}H^{t+1}_{i,j+1}+ (1-\\epsilon_{i,j})H^{t+1}_{i,j} = \\zeta_{i,j}\n\\end{equation}\nwith the RHS,\n\\begin{multline}\n  \\zeta_{i,j} = \\alpha_{i,j}H^{t}_{i-1,j} + \\beta_{i,j}H^{t}_{i+1,j} + \\gamma_{i,j}H^{t}_{i,j-1} + \\delta_{i,j}H^{t}_{i,j+1} + (1+\\epsilon_{i,j})H^{t}_{i,j} \\\\\n  + 2(\\alpha_{i,j}h_{i-1,j} + \\beta_{i,j}h_{i+1,j} + \\gamma_{i,j}h_{i,j-1} + \\delta_{i,j}h_{i,j+1}+ \\epsilon_{i,j}h_{i,j}) + B_{i,j}\\Delta t\n\\end{multline}\nwith the elements of the sparse matrix\n\\begin{subequations}\n  \\begin{align}\n    \\alpha_{i,j} &=\\frac{\\tilde{D}_{r-1,s}+\\tilde{D}_{r-1,s-1}}{4\\Delta x^2}\\Delta t\\\\\n    \\beta_{i,j} &=\\frac{\\tilde{D}_{r,s}+\\tilde{D}_{r,s-1}}{4\\Delta x^2}\\Delta t\\\\\n    \\gamma_{i,j} &=\\frac{\\tilde{D}_{r,s-1}+\\tilde{D}_{r-1,s-1}}{4\\Delta y^2}\\Delta t\\\\\n    \\delta_{i,j} &=\\frac{\\tilde{D}_{r,s}+\\tilde{D}_{r-1,s}}{4\\Delta y^2}\\Delta t\\\\\n    \\epsilon_{i,j} &=-(\\alpha_{i,j}+\\beta_{i,j}+\\gamma_{i,j}+\\delta_{i,j})\n  \\end{align}\n\\end{subequations}\n\nThis matrix equation is solved using an iterative matrix solver for non-symmetric sparse matrices. The solver used here is the bi--conjugate gradient method with incomplete LU decomposition preconditioning provided by the SLAP package.\n\n\\subsubsection{Non--Linear Scheme}\nThe non--linearity of Equation \\eqref{kin.eq.ice_evo} arises from the dependance of $D$ on $s$. A non--linear scheme for \\eqref{kin.eq.ice_evo} can be formulated using Picard iteration, which consists of two iterations: an outer, non--linear and an inner, linear equation. The scheme is started off with the diffusivity from the previous time step, i.e.\n\\begin{subequations}\n  \\begin{equation}\n    D^{(0),t+1}=D^{t}\n  \\end{equation}\nand Equation \\eqref{kin.eq.evo_matrix} becomes\n\\begin{multline}\n  \\label{kin.eq.evo_matrix_nonlin}\n  -\\alpha^{(\\xi),t+1}_{i,j}H^{t+1}_{i-1,j} - \\beta^{(\\xi),t+1}_{i,j}H^{(\\xi+1),t+1}_{i+1,j} - \\gamma^{(\\xi),t+1}_{i,j}H^{(\\xi+1),t+1}_{i,j-1} \\\\\n  - \\delta^{(\\xi),t+1}_{i,j}H^{(\\xi+1),t+1}_{i,j+1}+ (1-\\epsilon^{(\\xi),t+1}_{i,j})H^{(\\xi+1),t+1}_{i,j} = \\zeta^{(0),t}_{i,j}\n\\end{multline}\n\\end{subequations}\nEquation \\eqref{kin.eq.evo_matrix_nonlin} is iterated over $\\xi$ until the maximum ice thickness residual is smaller than some threshold:\n\\begin{equation}\n  \\max\\left(\\left|H^{(\\xi+1),t+1}-H^{(\\xi),t+1}\\right|\\right)<H_{\\text{res}}\n\\end{equation}\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{\\dir/figs/thick_evo.eps}\n  \\caption{Flow diagram showing how the linearised solver (on the left) and the non--linear solver work. The inner, linear iteration is contained within the box labeled ``calculate new ice distribution''.}\n  \\label{kin.fig.solvers}\n\\end{figure}\n\n\\input{\\dir/vert_velo.tex}\n", "meta": {"hexsha": "c186a89d5d4f48d28f4d046ee7d1c4169f18763a", "size": 13063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "models/glc/cism/glimmer-cism/doc/num/kinematics.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/kinematics.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/kinematics.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": 59.3772727273, "max_line_length": 607, "alphanum_fraction": 0.6830743321, "num_tokens": 4887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6869024310125228}}
{"text": "\\section{Majorana Fermions}\nDefine $\\nu=S_0 S\\pi$ to be a topological band invariant.\n$\\nu=+1$ is the non-topological phase.\n\nThe band looks like $E_k = -2t\\cos k$,\nwhich mas a minimum of $\\mu = -2t$ and a maximum of $\\mu= 2t$.\n\n$\\nu = -1$ is the topological phase.\n\nMajorana fermions obey\n\\begin{align}\n    \\left\\{ \\gamma_i, \\gamma_j \\right\\} &= 2\\delta_{ij}\n\\end{align}\nwhich implies\n\\begin{align}\n    \\gamma_{i}^2 = 1.\n\\end{align}\nHere the operators\n$\\gamma_i$ act on sites $i=1,\\ldots,2N$.\n\nLet $\\tilde{\\gamma_i}:=\\sum_{j} W_{ij}\\gamma_j$\nwhere $w\\in O(2N)$ is an orthogonal matrix.\nThen you still get\n\\begin{align}\n    \\left\\{ \\tilde{\\gamma}_i, \\tilde{\\gamma}_j \\right\\} = 2\\delta_{ij}\n\\end{align}\n\nThus the largest possible symmetry of $2N$ Majoranas is\n$O(2N)$.\n\nOne may define creation and annihilation operators\n$c_i$ and $c_i^\\dagger$ for ``complex fermions''\nwhich obey\n\\begin{align}\n    \\left\\{ c_i^\\dagger, c_j \\right\\} &= \\delta_{ij}\\\\\n    \\left\\{ c_i, c_j \\right\\} &= 0.\n\\end{align}\nThe two can be related by\n\\begin{align}\n    c_i &= \\frac{1}{2}\\left(\n        \\gamma_{2i - 1} + 1\\gamma_{2i}\n    \\right) \n\\end{align}\nwhere $i=1,\\ldots,N$.\n\nThus $2N$ Majoranas is equivalent to $N$ complex fermions.\n\n$N$ complex fermions has $2^{N}$ states,\nsince the number operator $c_i^\\dagger c_i = 0$ or $1$.\n\nSo we can say that 1 complex fermion has a\n``quantum dimension'' of 2,\nbut 1 Majorana fermion has a quantum dimension of $\\sqrt{2}$.\n\nLet us introduce the fermion parity operator\n\\begin{align}\n    P_i = {\\left( -1 \\right)}^{c_i^\\dagger c_i}\n    = -i \\gamma_{2i - 1}\\gamma_{2i}=\n    \\begin{cases}\n        +1\\\\\n        -1\n    \\end{cases}\n\\end{align}\nFrom this we can also define the total fermion parity\n\\begin{align}\n    P &= \\prod_{i=1}^{N} P_i.\n\\end{align}\nUnder $O(2N)$ rotation this transforms as\n\\begin{align}\n    P \\to P\\det W\n\\end{align}\nso $SO(2N)$ fixes $P$.\n\nConsider just 1 pair with\n\\begin{align}\n    \\gamma_{1} &= c + c^\\dagger\\\\\n    \\gamma_2 &= \\frac{1}{2}\\left( c - c^{\\dagger} \\right)\n\\end{align}\nand such as system only has two states\n$\\ket{0}$ for empty and $\\ket{1}$ for filled.\nThen the Majorana operators act like\n\\begin{align}\n    \\gamma_1\\ket{0} &= \\ket{1}\\\\\n    \\gamma_2\\ket{0} &= i\\ket{1}\n\\end{align}\nso in fact\n\\begin{align}\n    \\gamma_1 &=\n    \\begin{pmatrix}\n        0 & 1\\\\\n        1 & 0\n    \\end{pmatrix}\n    = \\sigma^{x}\\\\\n    \\gamma_1 &=\n    \\begin{pmatrix}\n        0 & -i\\\\\n        i & 0\n    \\end{pmatrix}\n    = \\sigma^{y}\n\\end{align}\nand their product satsifies\n\\begin{align}\n    -i \\gamma_1 \\gamma_2 = -i^2 \\sigma^z = \\sigma^z.\n\\end{align}\nThe most general free ferion Hamiltonian assuming there being\n$2N$ Majoranas is\n\\begin{align}\n    H &= \\frac{i}{4} \\sum_{ij} A_{ij} \\gamma_i \\gamma_j\n\\end{align}\nwhere $A_{ij} = - A_{ji} = A_{ij}^*$\nso $A$ is a $2N\\times 2N$ real skew symmetric matrix.\n\nWe can always bring $A$ into canonical form\n\\begin{align}\n    D &= WAW^\\dagger =\n    \\begin{pmatrix}\n        0 & \\varepsilon_1 & & & & & \\\\\n        -\\varepsilon_1 & 0 & & & & & \\\\\n        & & 0 & \\varepsilon_2 & & & \\\\\n        & & -\\varepsilon_2 & 0 & & &\\\\\n        & & & & \\ddots & &\\\\\n        & & & & & 0 & \\varepsilon_N\\\\\n        & & & & & -\\varepsilon_N & 0\\\\\n    \\end{pmatrix}\n\\end{align}\nso we can set $\\tilde{\\gamma} = W\\gamma$\nand\n\\begin{align}\n    \\tilde{c}_j &= \\frac{1}{2}\\left( \\tilde{\\gamma}_{2j} - 1\n    + \\tilde{\\gamma}_{2i}\\right)\n\\end{align}\nThe Hamiltonian in this form is\n\\begin{align}\n    H &=\n    \\frac{i}{2}\\sum_{j=1}^{N}\n    \\varepsilon_j \\tilde{\\gamma}_{2j - 1} \\tilde{\\gamma}_{2j}\\\\\n    &=\n    \\sum_{j=1}^{N} \\varepsilon_j\\left( \\tilde{c}_j^\\dagger \\tilde{c}_j -\n    \\frac{1}{2}\\right)\n\\end{align}\nWe can then do the so-called ``particle-hole transformation''\n\\begin{align}\n    C: \\quad\n    \\tilde{c}_j^\\dagger &\\to \\tilde{c}_j\\\\\n    \\tilde{\\gamma}_j &\\to {(-1)}^{j+1}\\tilde{\\gamma}_j\n\\end{align}\nwhich also can transform the Hamiltonian under conjugation with\n\\begin{align}\n    C:\\quad\n    H\\to CHC = -H.\n\\end{align}\nThis means tthat eigenvalues must come in pairs $(E, -E)$.\n\nIf all $\\varepsilon_i \\ne 0$\nthen the lowest energy state is uniqued and gapped.\n\n\nConsider the fermion parity of the ground state.\nConsider a single pair\n\\begin{align}\n    H &= \\frac{i}{2} \\sum \\gamma_1 \\gamma_2\n\\end{align}\nwhich for the ground state if $\\varepsilon > 0$ with\n$i\\gamma_1 \\gamma_2 = -1$\nimplies\n$P = -i \\gamma_1 \\gamma_2 = \\pm 1$.\nThe parity $P=\\sgn(\\varepsilon)$.\n\nFor the whole system,\n\\begin{align}\n    P &=\n    \\prod_{i=1}^{N} \\sgn\\left( \\varepsilon_i \\right)\n    =\n    \\sgn\\left[ \\Pf(D) \\right]\n    = \\sgn\\left( \\Pf\\left( A \\right) \\det W \\right)\n\\end{align}\nwhere $\\Pf$ denotes the Pfaffian,\nwhich is defined for an $N\\times N$ matrix with $N$ even matrix by\n\\begin{align}\n    \\Pf(M) &=\n    \\frac{1}{2^{N}}\n    \\frac{1}{N!}\n    \\sum_{\\text{permutations }\\sigma}\n    {(-1)}^{\\sgn(\\sigma)}\n    \\prod_{i=1}^{N}\n    A_{\\sigma(2 i - 1), \\sigma(2i)}.\n\\end{align}\n\nFor example,\n\\begin{align}\n    \\Pf\n    \\begin{pmatrix}\n        0 & \\varepsilon\\\\\n        -\\varepsilon & 0\n    \\end{pmatrix}\n    = \\varepsilon\n\\end{align}\nand\n\\begin{align}\n    \\Pf\n    \\begin{pmatrix}\n        0 & \\varepsilon & &\\\\\n        -\\varepsilon & 0 & &\\\\\n        & & 0 & \\varepsilon'\\\\\n        & & -\\varepsilon' & 0\n    \\end{pmatrix}\n    = \\varepsilon\\cdot \\varepsilon'\n\\end{align}\nA useful property is that\n\\begin{align}\n    \\det(X) = {\\left[ \\Pf(X) \\right]}^2\n\\end{align}\n\nIf we fixed the definition of fermion parity,\nonly consider $W\\in SO(2N)$,\nthen\n\\begin{align}\n    P(H) &= \\sgn \\Pf A\n\\end{align}\n\n\\section{Boundary Majorana Zero Modes}\nConsider the Hamiltonian\n\\begin{align}\n    H &=\n    \\sum_{i}\\left[\n        -t \\left( c_i^\\dagger c_{i + 1} + c_{i+1}^\\dagger c_i\\right)\n        - \\mu\\left( c_i^\\dagger c_i^\\dagger - \\frac{1}{2} \\right)\n        + \\Delta c_i c_{i+1}\n        + \\Delta^* c_{i+1}c_{i}\n    \\right]\n\\end{align}\nwhere $\\Delta = |\\Delta| e^{i\\phi}$,\nin which case we can just redefine\n\\begin{align}\n    c_i \\to \\tilde{c}_i = e^{i\\phi/2}c_i\n\\end{align}\nto absorb the $\\phi$.\nThen you would write\n\\begin{align}\n    \\tilde{c}_i &= \\frac{1}{2}\n    \\left( \\gamma_{2i - 1} + i\\gamma_{2i} \\right).\n\\end{align}\nThen\n\\begin{align}\n    H &= \\frac{i}{2}\\sum_{i}\\left[\n        \\left( |\\Delta| + t \\right)\\gamma_{2i}\\gamma_{2i+1}\n        + \\left( |\\Delta| - t \\right) \\gamma_{2i - 1} \\gamma_{2i + 2}\n        - \\mu \\gamma_{2i - 1} \\gamma_{2i}\n    \\right]\n\\end{align}\nLet us consider two limiting cases with open boundary conditions.\n\nCase 1: $|\\Delta| = t = 0$ and $\\mu > 0$.\nThen\n\\begin{align}\n    H &= -\\frac{i}{2}\\mu\\sum_{i}\\gamma_{2i - 1}\\gamma_{2i}\n\\end{align}\nso each site has\n\\begin{align}\n    -i\\gamma_{2i - 1}\\gamma_{2i} = 1 = P_i\n\\end{align}\nThis is an ``atomic superconductor''\nwith tightly bound Cooper pairs\nand strong pairing phases.\nThe cooper wave function is exponentially decaying.\n\nCase 2: $|\\Delta| = t > 0$ and $\\mu = 0$.\n$\\gamma_1$ and $\\gamma_{2N}$ are boundary Majorana zero modes with\n\\begin{align}\n    \\left[ H, \\gamma_1 \\right] =\n    \\left[ H, \\gamma_{2N} = 0 \\right]\n\\end{align}\nwhich means there is a 2-fold degeneracy of the 0 energy state\ncorresponding to\n\\begin{align}\n    i\\gamma_1 \\gamma_{2N} = \\pm 1\n\\end{align}\n\nAway from the idealized points,\nstill free fermion,\nwe can look for solutions to\n\\begin{align}\n    \\left[ H, \\tilde{\\gamma}_{L} \\right]\n    = \\left[ H, \\tilde{\\gamma}_{R} \\right] = 0\n\\end{align}\nin the limit $N\\to\\infty$ where\n\\begin{align}\n    \\tilde{\\gamma}_L &= \\alpha_1 \\gamma_1 + \\alpha_2 \\gamma_2 + \\cdots\\\\\n    \\tilde{\\gamma}_R &= \\beta_{2N}\\gamma_{2N} + \\beta_{2N - 1}\\gamma_{2N - 1} +\n    \\cdots\n\\end{align}\nwhere\n\\begin{align}\n    \\alpha_x &\\sim e^{-x/\\xi}\\\\\n    \\beta_{2N - x} &\\sim e^{-x/\\xi}.\n\\end{align}\nFor $\\nu=-1$,\ncan find solution $\\alpha$ and $\\beta$\ndecay experimentally away from the boundary.\n\nThe finite size system boundayr Majorana zero modes will have some wave function\noverlap.\nThis effective Hamiltonian ground state is in a subspace\nwith effective Hamiltonian\n\\begin{align}\n    H_{\\textrm{eff}} &=\n    \\frac{i}{2} t_{\\textrm{eff}} \\tilde{\\gamma}_L \\tilde{\\gamma}_R\n\\end{align}\nwhere the effective hopping coefficient is\n$t_{\\textrm{eff}}\\sim e^{-N/\\xi}$.\n\nAt the phase transition,\n$\\xi\\to\\infty$,\nthe MZMs become delocalized.\nThis is the critical point that is a field theory of 1D gapless Majorana modes.\n\nNote that when\n\\begin{align}\n    \\left[ H, \\tilde{\\gamma}_L \\right]\n    = \\left[ H, \\tilde{\\gamma}_R \\right] = 0\n\\end{align}\nit is called a ``string zero mode.''.\n\nIf we turn on interactions,\n\\begin{align}\n   \\delta H \\propto\n   \\sum_{ijkl} \\gamma_i \\gamma_j \\gamma_k \\gamma_l\n\\end{align}\nThe boundary MZMs still exist,\nbut they have a doubly degenerate ground state\nin the $N\\to\\infty$ limit,\nbut generically no longer commute with $H$.\n\nThe ground state degeneracy is ``topological''\nin the following sense.\n\\begin{enumerate}\n    \\item Robust to perturbations.\n    \\item No \\emph{local} bosonic operator that can distinguish between the\n        ground states.\n        Specifically,\n        \\begin{align}\n            \\bra{j}\\mathcal{O}\\ket{i} \\propto \\delta_{ij}\n            + O\\left( e^{-L/\\xi} \\right)\n        \\end{align}\n        for any local bosonic operator $\\mathcal{O}$.\n        It is not protected against local fermionic operators though.\n        \\begin{align}\n            \\bra{j}c_1\\ket{i}, \\bra{j} c_N\\ket{i}\n            \\not\\propto \\delta_{ij}\n        \\end{align}\n        As long as we can protect the system from stray fermions,\n        we have a\n        ``topologically protected qubit''.\n        Otherwise,\n        we have so-called ``quasi-particle'' poisoning.\n\\end{enumerate}\nBoundary Majorana Zero Modes can be understood from field theory.\n\nSuppose we have a spinless $p$-wave superconductor with Hamiltonian\n\\begin{align}\n    H &= \\frac{1}{2}\\sum_{k\\in\\mathrm{BZ}}\n    \\Psi_k^\\dagger\n    \\begin{pmatrix}\n        \\varepsilon_k & \\Delta_k^*\\\\\n        \\Delta_k & -\\varepsilon_k\n    \\end{pmatrix}\n    \\Psi_k\n\\end{align}\nwhere\n\\begin{align}\n    \\Psi_k =\n    \\begin{pmatrix}\n        \\Psi_k\\\\\n        \\Psi_k^\\dagger\n    \\end{pmatrix}\n\\end{align}\nand $t=|\\Delta|$, $\\mu\\approx -2t$ and\n\\begin{align}\n    \\varepsilon_k &= -2t\\cos k - \\mu\\\\\n    \\Delta_k &= -2i\\Delta\\sin k.\n\\end{align}\n\nThe the limit $k\\to 0$ and we get\n\\begin{align}\n    \\varepsilon_k &\\to -2t - \\mu = m\\\\\n    \\Delta_k &\\to -2i\\Delta k\n\\end{align}\nwhere $m$ is defined as the mass term in the field theory.\nAssume $\\Delta$ is real so that $\\tilde{\\Delta}:= 2\\Delta$.\nThe Hamiltonian thus can be written as\n\\begin{align}\n    H_k &=\n    \\begin{pmatrix}\n        m & i\\tilde{\\Delta}k\\\\\n        -i\\tilde{\\Delta}k & -m\n    \\end{pmatrix}\n    = \\tilde{\\Delta}k\\sigma^y + m\\sigma^z.\n\\end{align}\nIn real space continuous variables,\n\\begin{align}\n    H &=\n    \\frac{1}{2}\\int dx\\,\n    \\Psi^\\dagger(x)\n    \\left( -i\\tilde{\\Delta}\\sigma^y \\partial_x + m\\sigma^z \\right)\n    \\Psi(x)\n\\end{align}\nwhere\n\\begin{align}\n    \\Psi(x) &=\n    \\begin{pmatrix}\n        \\Psi(x)\\\\\n        \\Psi^\\dagger(x).\n    \\end{pmatrix}\n\\end{align}\nhere, we have\n\\begin{align}\n    \\Psi^*(x) &= \\left( \\Psi^\\dagger(x) \\right)^T\n\\end{align}\nand the Majorana condition is\n\\begin{align}\n    \\Psi(x) &= \\sigma^x \\Psi^*(x).\n\\end{align}\nThe ``trivial phase'' is for $\\mu + 2t < 0$ which means $m>0$.\nThe topological phase occurs when\n$\\mu + 2t > 0$ which implies $m < 0$.\nAnd the critical point is when $\\mu = -2t$ and we get $m=0$.\nThis is a massless $(1+1)D$ Majorana field.\n\n\\subsection{Digression: Jackiw-Rabbi system}\nConsider a $(1 + 1)D$ massive Dirac fermion.\nThen if we define\n\\begin{align}\n    \\Psi =\n    \\begin{pmatrix}\n        \\Psi_1\\\\\n        \\Psi_2\n    \\end{pmatrix}\n\\end{align}\nconsider a $(1+1)D$ massive Dirac fermion\n\\begin{align}\n    H_{\\textrm{Dirac}} &=\n    \\frac{1}{2}\\int dx\\,\\left[\n    -i \\nu \\Psi^\\dagger \\sigma^y \\partial_x \\Psi\n    + m\\Psi^\\dagger \\sigma^z \\Psi\n    \\right]\n\\end{align}\nwhich arises as the continuum limit of the SSH model\n\\begin{align}\n    H_{\\mathrm{SSH}} &=\n    -\\sum_{i}\\left[\n    \\left( t + {(-1)}^{i} \\delta t \\right) c_i^\\dagger c_{i+1} + \\textrm{h.c.}\n    \\right]\n\\end{align}\nThis is used to model polyaccetaline if we enable two spin $\\frac{1}{2}$.\nLable each unit cell by\n\\begin{align}\n    \\Psi_r &=\n    \\begin{pmatrix}\n        c_{2r - 1}\\\\\n        c_{2r}\n    \\end{pmatrix}\n\\end{align}\nAlso $\\delta t \\approx m$ of Dirac point.\n\nConsider a domain wall in $m(x)$.\nLook for eigenstates of $H_{\\textrm{Dirac}}$.\n\\begin{align}\n    q^\\dagger &= \\int dx\\,\\left[ \n    \\phi_1(x) \\psi_1^\\dagger(x)\n    + \\phi_2(x) \\psi_2^\\dagger(x)\n    \\right]\n\\end{align}\ndefines eigenstate of energy $\\varepsilon$ since\n\\begin{align}\n    \\left[ H_{\\mathrm{Dirac}}, q^\\dagger \\right] &=\n    \\varepsilon q^\\dagger.\n\\end{align}\nwhere $\\phi =\n\\begin{pmatrix}\n    \\phi_1\\\\\n    \\phi_2\n\\end{pmatrix}$.\n\nConsider a simple limit with 1 fermion pre unit cell.\nAnd we have 2 chains.\n1 fermion = 2 domain wall.\n1 domain wall = $\\pm\\frac{1}{2}$ charges.\nExample of charge fractionalization in charge topological insulator.\n\nGeneralization: $\\frac{1}{m}$ fillings.\nCDW with on sites per unit cell $\\to$\nelementary domain wall\n$\\implies$\n$\\pm \\frac{1}{m}$ charges.\n\n\\begin{enumerate}\n    \\item Modulation arises from spontaneous symmetry breaking\n        both dimerization patterns have some energy.\n        Domain walls are ``deconfined''.\n    \\item Modulation from ``explicit'' symmetry breaking terms domain wall.\n        Then two dimerization patterns have different energy\n        $\\to$ confined linear energy cost.\n\\end{enumerate}\n\n\\subsection{MZMs and J-R soliton}\n\\begin{align}\n    \\Phi(x) &=\n    \\begin{pmatrix}\n        \\Psi\\\\\n        \\Psi^\\dagger\n    \\end{pmatrix}\\\\\n    \\Psi &= \\sigma_x \\Psi^*\\\\\n    \\Phi_0 &=\n    \\begin{pmatrix}\n        \\phi_0\\\\\n        \\lambda \\phi_0\n    \\end{pmatrix}\\\\\n    q^\\dagger &=\n    \\int dx\\, \\left[\n    \\phi_0\\Psi^\\dagger(x) + \\lambda \\phi_0\\Psi(x)\n    \\right]\n\\end{align}\n$\\phi_0$ is real $\\implies$ $q= \\lambda q^\\dagger$ and\n\\begin{align}\n    \\gamma &=\n    \\begin{cases}\n        q & \\lambda = 1\\\\\n        iq & \\lambda = -1\n    \\end{cases}\n\\end{align}\nwhich implies\n\\begin{align}\n    \\gamma^\\dagger &= \\gamma\\\\\n    \\gamma^2 &= 1\n\\end{align}\nwhich are Majorana zero modes bound to domain walls.\n", "meta": {"hexsha": "281f809ce43aef3d3a69cd71cb24134c82a6e65c", "size": 14203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys733/lecture7.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/lecture7.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/lecture7.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.4487895717, "max_line_length": 80, "alphanum_fraction": 0.6182496656, "num_tokens": 5127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6868338546197905}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 4.2 Linear Least-Squares and Covariance Matrix\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThe principal expected application of this set of subroutines is the\nsolution of the linear least-squares problem, $A{\\bf x} \\simeq {\\bf b}$,\nwhere $A$ is an $m \\times n$ matrix with $m > n$, and ${\\bf b}$ is an $m$%\n-vector. The solution vector, ${\\bf x}$, is an $n$-vector. Computation of\nthe covariance matrix of the solution vector, ${\\bf x}$, is also supported.\n\nThis software is not limited to the usual case of $m > n$ and $A$ being of\nfull rank. A pseudoinverse solution is provided for all of the cases, $m > n$%\n, $m = n$, and $m < n$, including the case of $A$ being rank-deficient.\nFurthermore, the right-side of the problem may be an $m \\times k$ matrix, $B$,\nin which case the solution will be an $n \\times k$ matrix, $X$.\n\n\\subsection{Usage}\n\n\\subsubsection{Solving a Least-Squares Problem}\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf LDA, M, N, LDB, NB, KRANK, IP}($\\geq $N)\n\n\\item[REAL]  \\ {\\bf A}(LDA, $\\geq $N){\\bf , TAU, RNORM}($\\geq $NB){\\bf ,\\\\\nWORK}($\\geq $N){\\bf , B}(LDB) or {\\bf B}(LDB, $\\geq $ NB)\n\\end{description}\n\nAssign values to A(,), LDA, M, N, B(,), LDB, NB, and TAU.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SHFTI(A, LDA, M, N, B, LDB, NB,\\\\\nTAU, KRANK, RNORM, WORK, IP)\\\\\n\\end{tabular}}\n\\end{center}\n\nComputed quantities are returned in A(,), B(,), KRANK, RNORM(), and IP().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] On entry contains the M$\\times $N matrix, $A$, of the\nleast-squares problem. Permit M $>$ N, M = N, or M $<$ N. On return contains\nan upper triangular matrix that can be used by subroutine, SCOV2, to compute\nthe covariance matrix.\n\n\\item[LDA]  \\ [in] First dimensioning parameter for the array, A(,). Require\nLDA $\\geq $ M.\n\n\\item[M]  \\ [in] Number of rows of data in A(,) and B(,) on entry. Require\nM $\\geq 1.$\n\n\\item[N]  \\ [in] Number of columns of data in A(,) on entry. Require N $\\geq\n0.$\n\n\\item[B(,)]  \\ [inout] May be a singly or doubly subscripted array. On entry\ncontains the right-side M-vector, ${\\bf b}$, or (M$\\times $NB)-matrix, $B$,\nfor the least-squares problem. On return contains the solution N-vector, $%\n{\\bf x}$, or (N$\\times $NB)-matrix, $X$.\n\n\\item[LDB]  \\ [in] First dimensioning parameter for the array B(,). Require\nLDB $\\geq \\max (\\text{M},\\text{N})$ when NB $\\geq 1$, and LDB $\\geq 1$\nwhen NB $=0.$\n\n\\item[NB]  \\ [in] Number of right-side vectors for the least-squares\nproblem. Require NB $\\geq 0$. If NB = 1, the array, B(,), may be either\nsingly or doubly subscripted. If NB $>1$, the array B(,) must be doubly\nsubscripted. If NB = 0, this subroutine will not access B(,).\n\n\\item[TAU]  \\ [in] Absolute tolerance parameter provided by the user.\nIdeally should indicate the noise level of the data in the given matrix, $A$.\nThe value, zero, is acceptable. Will be used in estimating the rank of $A$.\nLarger values of TAU will lead to a smaller estimated rank for $A$.\n\n\\item[KRANK]  \\ [out] Rank of $A$ estimated by the subroutine. Will be in the\nrange, $0\\leq \\text{KRANK}\\leq \\min (\\text{M},\\text{N}).$\n\n\\item[RNORM()]  \\ [out] On return, RNORM(i) will contain the square root of\nsum of squares of residuals for the $i^{th}$ right-side vector.\n\n\\item[WORK()]  \\ [scratch] This array, of length at least N, is used\ninternally by the subroutine as working space.\n\n\\item[IP()]  \\ [out] On return contains a record of column interchanges.\n\\end{description}\n\n\\subsubsection{Computing the Covariance Matrix}\n\nSubroutine SCOV2 is designed to be used following SHFTI; but only in cases\nin which KRANK determined by SHFTI is N.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf LDA, N, IP}($\\geq $N){\\bf , IERR}\n\n\\item[REAL]  \\ {\\bf A}(LDA, $\\geq $N){\\bf , VAR}\n\\end{description}\n\nOn entry the values in A(,), LDA, N, and IP() should be the same as on\nreturn from a previous call to SHFTI. Also, assign a value to VAR.\n$$\n\\fbox{{\\bf CALL SCOV2(A, LDA, N, IP, VAR, IERR)}}\n$$\nComputed quantities are returned in A(,) and IERR.\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] On entry contains an N$\\times $N upper-triangular\nmatrix produced by the subroutine, SHFTI. On return contains the\nupper-triangular part of the symmetric covariance matrix of the original\nleast-squares problem. Elements in A(,) below the diagonal will not be\nreferenced.\n\n\\item[LDA, N]  \\ [in] Must be the same as in a previous call to SHFTI.\n\n\\item[IP()]  \\ [in] Contains a record of column interchanges performed by a\nprevious call to SHFTI.\n\n\\item[VAR]  \\ [in] Estimate of the variance of the data errors in the\noriginal right-side vector, ${\\bf b}$. To compute the covariance matrix for\nthe $i^{th}$ right-side vector of the original problem, the user's code can\ncompute VAR in terms of output quantities from SHFTI as\n{\\tt \\begin{tabbing}\n\\hspace{.2in}\\=DOF = M - N\\\\\n\\>STDDEV = RNORM($i$)/sqrt(DOF)\\\\\n\\>VAR = STDDEV**2\n\\end{tabbing}}\n\\item[IERR]  \\ [out] Error flag. Zero indicates no error was detected. A\npositive value indicates that A(IERR, IERR) was zero on entry. In this\nlatter case no result will be produced.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange the REAL type statements to DOUBLE PRECISION, and change the\nsubroutine names from SHFTI and SCOV2 to DHFTI and DCOV2, respectively.\n\n\\subsection{Examples and Remarks}\n\n\\subsubsection{A least-squares example}\n\nData for a sample linear least-squares problem were generated by computing\nvalues of%\n\\begin{equation*}\ny=0.5+0.25\\ \\sin (2\\pi x)+0.125\\ \\exp (-x)\n\\end{equation*}\nat eleven points, $x=0.0$, 0.1, ..., 1.0, and rounding the resulting $y$%\n-values to 4~decimal places, thus introducing errors bounded in magnitude by\n0.00005. The program, DRSHFTI, uses SHFTI to compute a least-squares fit to\nthis data using the model%\n\\begin{equation*}\nc_1+c_2\\sin (2\\pi x)+c_3\\exp (-x)\n\\end{equation*}\nand uses SCOV2 to compute the covariance matrix for the computed\ncoefficients. Results are shown in the output file, ODSHFTI.\n\n\\subsubsection{Large problems}\n\nIf M $>>$ N and storage limitations make it awkward or impossible to\nallocate M$\\times $N locations for the array, A(,), one can use sequential\naccumulation of the rows of data to produce a smaller matrix to which SHFTI\nand SCOV2 can then be applied. See Chapter~4.4 for sequential accumulation.\n\n\\subsubsection{Underdetermined problems}\n\nIf M $<$ N, or, more generally, whenever Rank($A$) $<$ N, there will be\ninfinitely many vectors, ${\\bf x}$, that achieve the same minimal residual\nnorm for the least-squares problem. For such cases SHFTI computes the\npseudoinverse solution, $i.e$. the solution vector, ${\\bf x}$, of least\nEuclidean norm.\n\n\\subsubsection{Computing the pseudoinverse matrix}\n\nIf one sets B(,) to be the M$\\times$M identity matrix, the resulting\nN$\\times $M solution matrix, $X$, will be the pseudoinverse matrix of $A$.\n\n\\subsubsection{Reliability issues regarding KRANK}\n\nKRANK must be understood as an estimate of the rank of $A$ that depends not\nonly on $A$, but on the user's setting of TAU and the particular algorithm\nused in SHFTI. A small change in the value of TAU could result in a\ndifferent value being assigned to KRANK, which in turn could result in a\nlarge change in the solution vector.\n\nAlthough this subroutine will produce a solution whatever the value of\nKRANK, the occurrence of KRANK $< \\min (\\text{M}$, N$)$ should be regarded\nas exceptional. The user should investigate such instances as it could be\ndue to a programming error or a very ill-conditioned model. Singular Value\nAnalysis (see Chapter~4.3) can be useful in analyzing an ill-conditioned model.\n\n\\subsection{Functional Description}\n\nThis software is an adaptation to Fortran~77 of the subroutine, HFTI,\ngiven and described in \\cite{Lawson:1974:SLS}.  The name, HFTI, denotes\nHouseholder Forward Transformation with column Interchanges.\n\nTo avoid nonessential complications, we shall describe the algorithm only\nfor the case of M $\\geq $ N and NB = 1. A sequence of up to N Householder\northogonal transformations is applied from the left, with column\ninterchanges, the total effect of which may be summarized by the equation%\n\\begin{equation*}\nQ\\left[ A:{\\bf b}\\right] \\left[\n\\begin{array}{cc}\nP & 0 \\\\\n0 & 1\n\\end{array}\n\\right] =\\left[\n\\begin{array}{cc}\nR & {\\bf g} \\\\ 0 & {\\bf h}\n\\end{array}\n\\right]\n\\end{equation*}\nwhere Q is the M$\\times $M product of the Householder matrices, $P$ is an N$%\n\\times $N permutation matrix accounting for the column interchanges, $R$ is an\nN$\\times $N upper-triangular matrix with diagonal elements in order of\ndecreasing magnitudes, ${\\bf g}$ is an N-vector, and ${\\bf h}$ is an\n(M $-$ N)-vector.\n\nIf all diagonal elements of $R$ exceed TAU in magnitude, the solution, ${\\bf x}\n$, is computed by solving $R{\\bf x}={\\bf g}$. The subroutine sets KRANK $=$\nN and RNORM(1)\\ $=\\Vert {\\bf h}\\Vert .$\n\nAlternatively, if the diagonal elements of $R$ beyond position $i$ are less\nthan TAU, the subroutine sets KRANK $=i$. Let $[R_1:{\\bf g}_1]$ denote the\nfirst KRANK rows of $[R:{\\bf g}]$, and let ${\\bf g}_2$ denote the last\nN $-$ KRANK components of ${\\bf g}$. The subroutine applies up to KRANK\nHouseholder transformations to $R_1$ from the right, effecting the\ntransformation\n\\begin{equation*}\nR_1K=[W:0]\n\\end{equation*}\nwhere $K$ is the N$\\times $N product of Householder transformations and $W$ is a\nKRANK$\\times $KRANK non-singular upper-triangular matrix. A KRANK-vector, $%\n{\\bf y}_1$, is computed by solving $W{\\bf y}_1={\\bf g}_1$. An N-vector, $%\n{\\bf y}$, is formed by appending zeros to the end of ${\\bf y}_1$, and the\nminimal length solution vector, ${\\bf x}$, is computed as ${\\bf x}=\\text{PK}%\n{\\bf y}$. RNORM(1) is computed as the Euclidean norm of the (M $-$ KRANK)-vector\nformed by concatenating ${\\bf g}_2$ and ${\\bf h}.$\n\nSubroutine, SCOV2, is intended for use only when Rank($A$) = N.\nAlgorithm, COV, from \\cite{Lawson:1974:SLS} is used.  The covariance\nmatrix is traditionally defined as $ C=\\sigma ^2(A^tA)^{-1}$, where\n$\\sigma ^2$ is the variance of the data error.  Using the triangular\nmatrix, $R$, and the (orthogonal) permutation matrix, $P$, defined above,\none can also write $C=\\sigma ^2(PR^tRP^t)^{-1}=\\sigma ^2PR^{-1}R^{-t}P^t$,\nwhere $R^{-t}$ denotes the transpose of $R^{-1}$.  Thus, SCOV2 computes%\n\\begin{align*}\nE&=R^{-1} \\\\ F&=EE^t\\\\ C&=\\sigma ^2PFP^t\n\\end{align*}\n\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIn SHFTI (or DHFTI) an error message will be issued and an immediate return\nwill be made, setting KRANK = 0, if any of the following conditions are\nnoted:%\n\\begin{equation*}\n\\text{M}<1,\\text{ N}<0,\\text{ LDA}<\\text{M, or LDB}<\\max (\\text{M, N})\n\\end{equation*}\nMost commonly, on return KRANK will have the value $\\min (\\text{M}$, N$)$.\nA smaller value of KRANK may be valid, but unless the user has reason to\nexpect this possibility it is likely to be due to a usage error.\n\nIn SCOV2 (or DCOV2) the N diagonal elements of A(,) must be nonzero on\nentry. If so, IERR is set to zero. If not, IERR is set to the index of the\nfirst zero element, an error message will be issued, and a return will be\nmade with the computation being incomplete.\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} \\\\\nDCOV2 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDCOV2, DDOT, DSWAP, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDHFTI & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DAXPY, DDOT, DHFTI, DHTCC, DHTGEN, DNRM2, ERFIN, ERMOR, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSCOV2 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SCOV2, SDOT, SSWAP\\rule[-5pt]{0pt}{8pt}}\\\\\nSHFTI & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMOR, ERMSG, IERM1, IERV1, SAXPY, SDOT, SHFTI, SHTCC, SHTGEN, SNRM2}\\\\\\end{tabular}\n\nAdapted to Fortran~77 from \\cite{Lawson:1974:SLS} by C.  L.  Lawson and S.\nY.  Chiu, JPL, May~1986, June~1987.\n\n\n\\begcode\n\\bigskip\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSHFTI}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{shfti}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSHFTI}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{shfti}}\n\\end{document}\n", "meta": {"hexsha": "f9a9ccfcf6594b51d1851f8f367f1eab515f84d8", "size": 12731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch04-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/ch04-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/ch04-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.6741214058, "max_line_length": 106, "alphanum_fraction": 0.7144764747, "num_tokens": 4055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571775, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6868338423358845}}
{"text": "\\section{Quaternion integration\\label{quatProofs}}\n\nLet us first consider a geometric view on quaternions, taken from~\\cite{Shoemake:85}. Treat\nthe four components of a quaternion as Cartesian coordinates of a four-dimensional vector\nspace. The set of unit quaternions is then the surface of a unit hypersphere (also called a\n\\emph{glome}~\\cite{MathWorld:4D}) in this vector space. Each point on this hypersphere\ncorresponds to a particular rotation. It also turns out that each pair of\nopposite points on this sphere represent exactly the same rotation; hence all possible\nrotations are contained in one hemisphere, no matter where the sphere is cut in half.\n\n\\subsection{Conservation of magnitude\\label{quatIntegrationMagnitude}}\nDefine the quaternion dot product, in analogy to the 4D vector dot product, to be\n\\begin{equation}\n\\q{p}\\cdot\\q{q} =\n    (p_w + p_x\\qi + p_y\\qj + p_z\\qk)\\cdot (q_w + q_x\\qi + q_y\\qj + q_z\\qk) =\n    p_w q_w + p_x q_x + p_y q_y + p_z q_z\n\\end{equation}\nThe dot product is commutative, contrary to the quaternion juxtaposition product.\n\nThe instantaneous rate of change is given~\\cite{BaraffWitkin:97,Eberly:04,Saunders:PhD} to be\n\\begin{eqnarray*}\n\\dot{\\q{q}} & = & \\frac{1}{2}\\tilde{\\ve{\\omega}}\\q{q} =\n    \\frac{1}{2}(\\omega_1\\qi + \\omega_2\\qj + \\omega_3\\qk)\n    (q_w + q_x\\qi + q_y\\qj + q_z\\qk) \\\\*\n& = & \\frac{1}{2} ( - \\omega_1 q_x - \\omega_2 q_y - \\omega_3 q_z ) +\n    \\frac{\\qi}{2} ( \\omega_1 q_w + \\omega_2 q_z - \\omega_3 q_y ) + \\\\*\n&&  \\frac{\\qj}{2} (-\\omega_1 q_z + \\omega_2 q_w + \\omega_3 q_x ) +\n    \\frac{\\qk}{2} ( \\omega_1 q_y - \\omega_2 q_x + \\omega_3 q_w )\n\\end{eqnarray*}\n\nWe now treat \\q{q} and $\\dot{\\q{q}}$ as 4D vectors and calculate\ntheir dot product:\n\\begin{eqnarray*}\n\\q{q}\\cdot\\dot{\\q{q}} & = & \\frac{1}{2} (\n    - q_w \\omega_1 q_x - q_w \\omega_2 q_y - q_w \\omega_3 q_z\n    + q_x \\omega_1 q_w + q_x \\omega_2 q_z - q_x \\omega_3 q_y \\\\*\n&&  - q_y \\omega_1 q_z + q_y \\omega_2 q_w + q_y \\omega_3 q_x\n    + q_z \\omega_1 q_y - q_z \\omega_2 q_x + q_z \\omega_3 q_w ) \\\\*\n& = & 0.\n\\end{eqnarray*}\nThe rate of change is orthogonal to \\q{q}, and therefore it is always\na tangent to the sphere, touching it at the point corresponding to \\q{q}. The set of all possible\nvalues of $\\dot{\\q{q}}$ is thus a hyperplane (a three-dimensional subspace) tangential to the\nsphere at the point \\q{q} in 4D space.\n\nWe can determine the magnitude $\\norm{\\dot{\\q{q}}}$ from the sum of squares of the\ncomponents given above and find it to be\n$\\norm{\\dot{\\q{q}}} = \\frac{1}{2}\\norm{\\ve{\\omega}}\\,\\norm{\\q{q}}$. Since we always\nrequire $\\q{q}$ to be a unit quaternion, we can reduce this to\n\\begin{equation}\n\\label{quatRateOfChangeMagnitude}\n\\norm{\\dot{\\q{q}}} = \\frac{1}{2}\\norm{\\ve{\\omega}}.\n\\end{equation}\n\nNow let us determine what happens if we calculate $\\q{q} + h\\dot{\\q{q}}$ for some finite $h$.\nNote that this operation is required by all common numerical solvers of differential equations.\nConsider the magnitude of the result:\n\\begin{eqnarray*}\n\\norm{\\q{q} + h\\dot{\\q{q}}}^2 & = & (\\q{q} + h\\dot{\\q{q}})\\cdot(\\q{q} + h\\dot{\\q{q}}) \\\\\n&=& \\q{q}\\cdot\\q{q} + 2h\\q{q}\\cdot\\dot{\\q{q}} + h^2\\dot{\\q{q}}\\cdot\\dot{\\q{q}} \\\\\n&=& 1 + 0 + \\frac{h^2}{4}\\norm{\\ve{\\omega}}^2 \\\\\n&>& 1 \\quad\\quad\\mbox{whenever}\\quad \\norm{\\ve{\\omega}} > 0.\n\\end{eqnarray*}\n\nHence, if the body in question is rotating, it is not possible for a standard numerical ODE solver\nto preserve a quaternion's property of unit magnitude.\n\n\n\\subsection{Normalization is not enough\\label{quatNormalization}}\n\nOne should think that given the derivative of a quaternion \\q{q} (equation~\\ref{quatRateOfChange},\npage~\\pageref{quatRateOfChange}), one can find $\\q{q}(t + h)$ for some time step $h$ within\nthe accuracy of the ODE solver employed ($O(h^5)$ error for fourth-order Runge-Kutta).\nUnfortunately this is not the case. This shall be demonstrated using Euler's method; it should,\nhowever, be pointed out that more sophisticated methods like RK4 are also affected. Consider the\nvalue of \\q{q} at the next time step, $\\q{q}(t + h) = \\q{q}(t) + h \\dot{\\q{q}}(t)$. For any\nnon-zero $h$ and $\\dot{\\q{q}}$ this point will always lie outside the unit quaternion sphere due\nto the orthogonality of \\q{q} and $\\dot{\\q{q}}$. This is usually compensated by renormalizing\nthe quaternion after the ODE solving step. Geometrically, this renormalization can be understood\nas drawing a straight line through the origin and the point $\\q{q}(t) + h \\dot{\\q{q}}(t)$,\nintersecting this line with the unit sphere and replacing $\\q{q}(t + h)$ by this point of\nintersection (see figure~\\ref{quatNormalizationFigure}).\n\n\\begin{figure}\n\\psfrag{frag:q}{\\q{q}}\n\\psfrag{frag:qdot}{$\\dot{\\q{q}}$}\n\\psfrag{frag:qplusqdot}{$\\q{q} + h\\dot{\\q{q}}$}\n\\centerline{\\includegraphics[width=6cm]{figures/quaternion1}}\n\\caption{Normalizing a quaternion after performing an ODE solving step.\n    \\label{quatNormalizationFigure}}\n\\end{figure}\n\nFollowing the tangent to the sphere is a reasonable approximation to following its curve if the\nmagnitude of $h \\dot{\\q{q}}(t)$ is small compared to the curvature of the sphere.\nFor large time steps or large magnitudes of \\ve{\\omega}, however, this gets increasingly\nerroneous. Consider the limiting case, a body rotating infinitely fast\n($\\norm{\\ve{\\omega}} \\rightarrow \\infty$): after renormalisation, $\\q{q}$ will have moved merely\na quarter of the way around the unit sphere, which equates to concatenating the rotation of\nquaternion \\q{q} with some rotation by $180^\\circ$. This is a strictly finite amount of rotation\nper time step, while it would actually have been correct to perform an infinite number of\nrevolutions around the quaternion sphere.\n\nIf a polynomial approximation method like RK4 had been used instead of Euler's method, a parametric\npolynomial space curve would have been fitted to the surface of the sphere instead of the straight\nline. Note however that the Taylor series of the $\\sin$ and $\\cos$ functions are non-terminating,\nand that it is therefore not possible for a finite polynomial curve to lie exactly in the surface\nof a sphere. These ODE solvers will therefore suffer the same problems, albeit less pronounced.\n\n\n\\subsection{Corrected quaternion integration\\label{quatIntegrationDerivation}}\n\nAssume that the body we are simulating is rotating at a constant angular velocity.\n(This assumption is later weakened by the use of a more sophisticated ODE solver,\nbut for now we will stick with Euler's method.) Furthermore assume without loss of\ngenerality that the body is rotating clockwise about its $x$ axis, which corresponds\nto the world's $x$ axis, and that at time $t=0$ the body's frame and the world frame\ncoincide. Then the orientation of the body (the quaternion describing the linear\ntransformation from the body's frame of reference to the world frame) is given as a\nfunction of time by\n\\begin{equation}\n\\label{quatDerivationExact}\n\\q{q}(t) = \\cos\\left(\\frac{\\norm{\\ve{\\omega}}t}{2}\\right) +\n    \\sin\\left(\\frac{\\norm{\\ve{\\omega}}t}{2}\\right)\\qi\n\\end{equation}\n(cf.\\ equation~\\ref{quatRotation}, figure~\\ref{quatIntFig1}) and its angular velocity is\n\\begin{equation}\n\\ve{\\omega} = (\\omega_1, \\omega_2, \\omega_3)^T = (\\norm{\\ve{\\omega}}, 0, 0)^T\n\\end{equation}\nfor some arbitrary $\\norm{\\ve{\\omega}}$, measured in radians per unit time.\n\n\\begin{figure}\n\\psfrag{frag:omegat}{$\\frac{\\norm{\\ve{\\omega}} t}{2}$}\n\\psfrag{frag:qdotoft}{$\\dot{\\q{q}}(t)$}\n\\psfrag{frag:real}{Re}\n\\psfrag{frag:iimag}{$\\mathsf{i}$-Im}\n\\centerline{\\includegraphics[width=6cm]{figures/quaternion2}}\n\\caption{Assumed situation for the derivation in\nsection~\\ref{quatIntegrationDerivation}.\\label{quatIntFig1}}\n\\end{figure}\n\nNow assume w.l.o.g.\\ that we take a time step from $t = 0$ to $t = h$.\nThen we require that the result returned by Euler's method for $\\q{q}(h)$\nafter renormalization be equal to its exact value in equation~\\ref{quatDerivationExact}:\n\\begin{equation}\n\\label{quatDerivationSetup}\n\\cos\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) +\n    \\sin\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\\qi =\n    \\frac{\\q{q}(0) + h \\dot{\\q{q}}(0)}\n        {\\norm{\\q{q}(0) + h \\dot{\\q{q}}(0)}}\n\\end{equation}\n\nWe know from examining the 4D geometry that the value assigned to $\\dot{\\q{q}}$\nin equation~\\ref{quatRateOfChange} has the correct direction and merely needs to be\ncorrected in magnitude. In other words, we are searching for a scalar function\n$f(h, \\norm{\\ve{\\omega}})$ which will allow $\\dot{\\q{q}}$ to satisfy\nequation~\\ref{quatDerivationSetup}:\n\\begin{equation}\n\\dot{\\q{q}}_h(t) = f\\tilde{\\ve{\\omega}}(t)\\q{q}(t)\n\\end{equation}\n\nObserve that under the above assumptions $\\q{q}(0) = 1$, and thus\n$\\dot{\\q{q}}_h(0) = f \\norm{\\ve{\\omega}} \\qi$. Substituting this\ninto equation~\\ref{quatDerivationSetup} and considering only the real part:\n\\begin{eqnarray*}\n&& \\cos\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) =\n    \\left[1 + \\left( f \\norm{\\ve{\\omega}} h \\right)^2 \\right]^{-\\frac{1}{2}} \\\\\n&\\Leftrightarrow&\n    \\left( f \\norm{\\ve{\\omega}} h \\right)^2 =\n    \\frac{1}{\\cos^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)} - 1 \\\\\n&\\Leftrightarrow&\n    f(h, \\norm{\\ve{\\omega}}) =\n    \\frac{1}{\\norm{\\ve{\\omega}} h} \\sqrt{\\frac{\n        1 - \\cos^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)}{\n        \\cos^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)}} =\n    \\frac{1}{\\norm{\\ve{\\omega}} h}\n        \\tan\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\n\\end{eqnarray*}\n\nTo check, we substitute this result into the $\\qi$-imaginary part of\nequation~\\ref{quatDerivationSetup}:\n\\begin{eqnarray*}\n\\sin\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) & = &\n    \\tan\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\n    \\left[ 1 + \\tan^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\n    \\right]^{-\\frac{1}{2}} \\\\\n&=& \\tan\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\n    \\left[ \\frac{\\cos^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) +\n    \\sin^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) }{\n    \\cos^2\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) }\n    \\right]^{-\\frac{1}{2}} \\\\\n&=& \\tan\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\n    \\cos\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) \\\\\n&=& \\sin\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right)\n\\end{eqnarray*}\n\nThus we establish the validity of this expression for $f$. Observe that by using \nL'Hospital's rule, we can find value of $f$ for an infinitesimally small time step:\n$$\n\\lim_{h \\to 0} f = \\lim_{h \\to 0} \\frac{ \\frac{\\norm{\\ve{\\omega}}}{2}\n    \\cos^{-2}\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) }{ \\norm{\\ve{\\omega}} } =\n    \\frac{1}{2}\n$$\ni.e.\\ we obtain the original equation~\\ref{quatRateOfChange} for the\ninstantaneous rate of change.\n\nNow let $\\Delta \\q{q} = h \\dot{\\q{q}} =\n    \\frac{h}{2} \\tilde{\\ve{\\omega}} \\q{q}$.\nFrom equation~\\ref{quatRateOfChangeMagnitude} we find that\n$\\norm{\\Delta\\q{q}} = \\frac{\\norm{\\ve{\\omega}} h}{2}$.\nHence we can simplify the expression for the quaternion correcting factor by expressing it\nin terms of $\\Delta \\q{q}$ as follows:\n$$\nh f \\tilde{\\ve{\\omega}}\\q{q} = \\frac{h}{\\norm{\\ve{\\omega}} h}\n    \\tan\\left(\\frac{\\norm{\\ve{\\omega}} h}{2}\\right) \\tilde{\\ve{\\omega}} \\q{q} =\n    \\tan\\left(\\norm{\\Delta\\q{q}}\\right) \\frac{\\Delta\\q{q}}{\\norm{\\Delta\\q{q}}}\n$$\n\nThis expression now has a clear geometric interpretation with respect to the 4D geometry\n(see figure~\\ref{quatIntFig2}):\n$\\norm{\\Delta\\q{q}}$ is measured in radians, and it corresponds to the \\emph{correct}\nangle between the old and the new vector $\\q{q}$. Since $\\q{q}$ and\n$\\dot{\\q{q}}$ are orthogonal, we have a right-angled triangle between the origin,\nthe old and the new points $\\q{q}$, and hence we can use the $\\tan$ function to\nevaluate the required length of the side in direction $\\Delta\\q{q}$.\n\n\\begin{figure}\n\\psfrag{frag:real}{Re}\n\\psfrag{frag:iimag}{$\\mathsf{i}$-Im}\n\\psfrag{frag:q}{\\q{q}}\n\\psfrag{frag:deltaq}{$\\Delta\\q{q}$}\n\\psfrag{frag:quergs1}{$\\q{q}+\\tan(\\norm{\\Delta\\q{q}})\\frac{\\Delta\\q{q}}{\\norm{\\Delta\\q{q}}}$}\n\\psfrag{frag:quergs2}{$\\mathrm{Quergs}(\\q{q},\\,\\Delta\\q{q})$}\n\\centerline{\\includegraphics[width=7.7cm]{figures/quaternion3}}\n\\caption{Illustration of the operation of Quergs.\\label{quatIntFig2}}\n\\end{figure}\n\nFinally we can combine this correction and the subsequent quaternion normalisation into\na single function, which I call Quergs (for \\emph{Qu}at\\emph{er}nion inte\\emph{g}ration\n\\emph{s}tep)\\footnote{This naming follows the spirit of Shoemake~\\cite{Shoemake:85}, whose\n``Slerp'' function is an `acronym' of \\emph{S}pherical \\emph{l}inear int\\emph{erp}olation.}:\n\\begin{eqnarray*}\n\\q{q}(t+h) = \\mathrm{Quergs}(\\q{q}(t), \\Delta\\q{q}) &=&\n    \\frac{\\q{q}(t) + \\tan\\left(\\norm{\\Delta\\q{q}}\\right)\n        \\frac{\\Delta\\q{q}}{\\norm{\\Delta\\q{q}}}}{\n    \\norm{\\q{q}(t) + \\tan\\left(\\norm{\\Delta\\q{q}}\\right)\n        \\frac{\\Delta\\q{q}}{\\norm{\\Delta\\q{q}}}}} \\\\\n&=& \\frac{\\q{q}(t) + \\tan\\left(\\norm{\\Delta\\q{q}}\\right)\n        \\frac{\\Delta\\q{q}}{\\norm{\\Delta\\q{q}}}}{\n    \\sqrt{1 + \\tan^2\\left(\\norm{\\Delta\\q{q}}\\right)}} \\\\\n&=& \\left[\\q{q}(t) + \\tan\\left(\\norm{\\Delta\\q{q}}\\right)\n        \\frac{\\Delta\\q{q}}{\\norm{\\Delta\\q{q}}}\\right]\n    \\cos\\left(\\norm{\\Delta\\q{q}}\\right)\n\\end{eqnarray*}\nThe last expression is simplest (and again allows geometric interpretation), but probably\nthe first of the three expressions is more useful for numerical evaluation, since it involves\nonly one trigonometric function and minimizes numerical errors.\n\nWhen implementing this formula, care must be taken around the discontinuities of the $\\tan$\nfunction, where numerical instability may occur. These discontinuities are reached whenever a\nbody performs an odd multiple of half revolutions during a single time step.\n", "meta": {"hexsha": "23c2f5fa563b5273dfe89b9fa1479b0294dcad72", "size": 13576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/quatProofs.tex", "max_stars_repo_name": "ept/maniation", "max_stars_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-05-09T00:54:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:40:52.000Z", "max_issues_repo_path": "report/quatProofs.tex", "max_issues_repo_name": "ept/maniation", "max_issues_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/quatProofs.tex", "max_forks_repo_name": "ept/maniation", "max_forks_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-17T14:39:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-08T05:38:45.000Z", "avg_line_length": 52.0153256705, "max_line_length": 99, "alphanum_fraction": 0.6896729523, "num_tokens": 4506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.6868338395137829}}
{"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{LINEAR REGRESSION}\n\\date{}\n\\maketitle\n\nLinear regression models assume a linear relationship between the inputs $X_1, X_2,\\ ...,\\ X_p$ and the output $Y$. These models are simple and often provide an insight into the effect of input variables on the output variable.\nLinear models can be expanded to transformations of the input variables, thus making them widely applicable.\n\n\\section{Single Variable Regression}\n\nGiven training data of the form $(x_1, y_1), (x_2, y_2),\\ ...,\\ (x_N, y_N)$; the idea is to come up with the best estimate $\\hat{y}$ such that, \n\n\\begin{align*}\n\t\\hat{y} = \\beta_0 + \\beta_1x \n\\end{align*}\n\nThis scheme makes an estimation error at each point,\n\\begin{align*}\n\t\\epsilon_i & = y_i - \\hat{y}_i            \\\\\n\t           & = y_i - (\\beta_0 + \\beta_1x) \n\\end{align*}\n\nGenerally, sum of squares of all the $N$ errors is minimized to define the best fit. Thus, the objective is to choose $\\beta_0$ and $\\beta_1$ such that this Residual Square Sum (RSS) is as small as possible. The errors are visualized below,\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (0,0) -- (6,0) node[right]{x};\n\t\t\\draw[-latex] (0,0) -- (0,5) node[left]{y};\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw (0, 1) -- (5, 4);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw (5, 4) node [above right] {$y = \\beta_0 + \\beta_1x$};\n\t\t\\draw (0, 1) node [left] {$\\beta_0$};\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\foreach \\Point in {(1,3), (2, 3), (4, 4), (3, 2), (1.5, 1)}{\n\t\t\t\\node at \\Point {\\textbullet};\n\t\t};\n\t\t\t\t\t\t\t\t        \n\t\t\\draw (1, 3) node [above] {$x_1, y_1$};\n\t\t\\draw (1.5, 1) node [below] {$x_2, y_2$};\n\t\t\\draw (2, 3) node [above right] {$x_3, y_3$};\n\t\t\\draw (3, 2) node [below] {$x_4, y_4$};\n\t\t\\draw (4, 4) node [above] {$x_5, y_5$};\n\t\t\t\t\t\t\t\t        \n\t\t\\draw [thick] (1, 3) -- (1, 1.6);\n\t\t\\draw [thick] (1.5, 1) -- (1.5, 1.9);\n\t\t\\draw [thick] (2, 3) -- (2, 2.2);\n\t\t\\draw [thick] (3, 2) -- (3, 2.8);\n\t\t\\draw [thick] (4, 4) -- (4, 3.4);        \t\t\t\t\t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nNote that as line moves away from the data points the $RSS$ gets bigger since each error becomes bigger. In fact there is no upper bound on $RSS$, only a lower bound. Hence to get the minimum $RSS$, equating partial differentials w.r.t. $\\beta_0$ and $\\beta_1$ to zero is sufficient without worrying if the extrema is maxima or minima, it is always guaranteed to be a minima.\n\n\\begin{align*}\n\tRSS(\\beta_0, \\beta_1)                 & = \\sum\\limits_{i = 1}^N (y_i - \\beta_0 - \\beta_1x_i)^2    \\\\\n\t\\frac{\\partial RSS}{\\partial \\beta_0} & = -2\\sum\\limits_{i = 1}^N (y_i - \\beta_0 - \\beta_1x_i)    \\\\\n\t\\frac{\\partial RSS}{\\partial \\beta_1} & = -2\\sum\\limits_{i = 1}^N (y_i - \\beta_0 - \\beta_1x_i)x_i \\\\\n\\end{align*}\n\nEquating both to zero,\n\n\\begin{align*}\n\t\\beta_0N + \\beta_1\\sum x_i = \\sum y_i             \\\\\n\t\\beta_0\\sum x_i + \\beta_1\\sum x_i^2 = \\sum x_iy_i \n\\end{align*}\n\nThis can be written in matrix form as follows,\n\n\\begin{align*}\n\t\\begin{pmatrix} N & \\sum x_i \\\\ \\sum x_i & \\sum x_i^2 \\end{pmatrix} \\begin{pmatrix} \\beta_0 \\\\ \\beta_1 \\end{pmatrix} = \\begin{pmatrix}\n\t\\sum y_i \\\\ \\sum x_iy_i \\end{pmatrix}\n\\end{align*}\n\n\nMultiplying by inverse of the $2\\times2$ matrix on both sides,\n\n\\begin{align*}\n\t\\begin{pmatrix} \\beta_0 &   &   \\\\ \\beta_1 \\end{pmatrix} &= \\begin{pmatrix} N & \\sum x_i \\\\ \\sum x_i & \\sum x_i^2 \\end{pmatrix}^{-1} \\begin{pmatrix}\n\t\\sum y_i \\\\ \\sum x_iy_i \\end{pmatrix} \\\\\n\t& = \\frac{1}{N\\sum x_i^2 - (\\sum x_i)^2} \\begin{pmatrix} \\sum x_i^2 & -\\sum x_i \\\\ -\\sum x_i & N \\end{pmatrix} \\begin{pmatrix}\n\t\\sum y_i \\\\ \\sum x_iy_i \\end{pmatrix} \\\\\n\t&= \\frac{1}{N\\sum x_i^2 - (\\sum x_i)^2} \\begin{pmatrix}\n\t\\sum x_i^2 \\sum y_i -\\sum x_iy_i  \\sum x_i  \\\\ N \\sum x_i y_i - \\sum x_i \\sum y_i \\end{pmatrix} \\\\\n\\end{align*}\n\nDividing both numerator and denominator by $N^2$, $\\beta_0$ and $\\beta_1$ can be represented in terms of averages as follows, \n\n\\begin{align*}\n\t\\beta_0 & = \\frac{Avg(x^2)Avg(y) - Avg(xy)Avg(x)}{Avg(x^2) - [Avg(x)]^2}                    \\\\\n\t\\beta_1 & = \\frac{Avg(xy) - Avg(x)Avg(y)}{Avg(x^2) - [Avg(x)]^2} = \\frac{Cov(x, y)}{Var(x)} \\\\\n\\end{align*}\n\nAfter the calculation of $\\beta_0$ and $\\beta_1$, the goodness of fit is measured by correlation,\n\n\\begin{align*}\n\tr = \\frac{Cov(x, y)}{\\sqrt{Var(x)Var(y)}} \n\\end{align*}\n\nCorrelation always resides in the interval $[-1, 1]$. It is 1 or -1 if all the data points $(x_i, y_i)$ lie on a line.\n\n\\subsection{Input Transformations}\n\n\\begin{itemize}\n\t\\item Relationship between $x$ and $y$ is not linear if $y = x^n$. Taking $log$ on both sides, $log(y) = nlog(x)$. Clearly relationship between $log(x)$ and $log(y)$ is linear. \n\t\\item Relationship between $x$ and $y$ is not linear if $y = a^x$. Taking $log$ on both sides, $log(y) = xlog(a)$. Clearly, relationship between $log(y)$ and $x$ is linear.\n\t\\item Due to scenarios like this, the inputs are sometimes transformed appropriately before being fed into a linear regression model.\n\\end{itemize}\n \n\\section{Multiple Variable Regression} \n\nIn the general case, the equation becomes\n\n\\begin{align*}\n\t\\hat{y} = \\beta_0 + \\sum\\limits_{j = 1}^p \\beta_j x_j \n\\end{align*}\n\nLet $\\mathbf{X}$ be $N\\times(p+1)$ matrix where the first column is all ones and the $j^{th}$ column represents the $N$ values of the input variable $x_j$. Similarly, let $\\mathbf{Y}$ be a vector of the $N$ values of the output variable $y$. For all the $N$ given observations, it can be written,\n\n\\begin{align*}\n\t\\mathbf{y} = \\mathbf{X}\\boldsymbol{\\beta} \n\\end{align*} \n\nThe error vector becomes,\n\n\\begin{align*}\n\t\\mathbf{\\epsilon} = \\mathbf{y} - \\mathbf{X}\\boldsymbol{\\beta} \n\\end{align*}\n\nThe residual sum of squares can be represented as,\n\n\\begin{align*}\n\tRSS(\\boldsymbol{\\beta}) & = \\mathbf{\\epsilon}^T\\mathbf{\\epsilon}                                                                                                                                          \\\\\n\t                        & = (\\mathbf{y} - \\mathbf{X}\\boldsymbol{\\beta})^T(\\mathbf{y} - \\mathbf{X}\\boldsymbol{\\beta})                                                                                      \\\\\n\t                        & = (\\mathbf{y}^T - \\boldsymbol{\\beta}^T\\mathbf{X}^T)(\\mathbf{y} - \\mathbf{X}\\boldsymbol{\\beta})                                                                                  \\\\\n\t                        & = \\mathbf{y}^T\\mathbf{y} - \\boldsymbol{\\beta}^T\\mathbf{X}^T\\mathbf{y} - \\mathbf{y}^T\\mathbf{X}\\boldsymbol{\\beta} + \\boldsymbol{\\beta}^T\\mathbf{X}^T\\mathbf{X}\\boldsymbol{\\beta} \n\\end{align*}\n\nTaking the derivative w.r.t. $\\boldsymbol{\\beta}$\n\n\\begin{align*}\n\t\\frac{\\partial RSS(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta}} & =                                                                                                 \n\t\\frac{\\partial}{\\partial \\boldsymbol{\\beta}}(\\mathbf{y}^T\\mathbf{y}) - \\frac{\\partial}{\\partial \\boldsymbol{\\beta}}(\\boldsymbol{\\beta}^T\\mathbf{X}^T\\mathbf{y}) - \\frac{\\partial}{\\partial \\boldsymbol{\\beta}}(\\mathbf{y}^T\\mathbf{X}\\boldsymbol{\\beta}) + \\frac{\\partial}{\\partial \\boldsymbol{\\beta}}(\\boldsymbol{\\beta}^T\\mathbf{X}^T\\mathbf{X}\\boldsymbol{\\beta}) \\\\\n\t                                                                     & = 0 - \\mathbf{X}^T\\mathbf{y} - \\mathbf{X}^T\\mathbf{y} + 2\\mathbf{X}^T\\mathbf{X}\\boldsymbol{\\beta} \\\\\n\t                                                                     & = -2\\mathbf{X}^T\\mathbf{y} + 2\\mathbf{X}^T\\mathbf{X}\\boldsymbol{\\beta}                            \n\\end{align*}\n\nEquating the derivative to zero for minimization,\n\n\\begin{align*}\n\t\\mathbf{X}^T\\mathbf{X}\\boldsymbol{\\hat{\\beta}} & = \\mathbf{X}^T\\mathbf{y}                              \\\\\n\t\\boldsymbol{\\hat{\\beta}}                       & = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{y} \n\\end{align*}\n\nThese estimators are also known as OLS(Ordinary Least Square) estimators.\n\n\\section{Bias and Variance}\n\\subsection{Definitions}\nNote that the expectation of a vector $\\mathbf{V}$ is defined as,\n\n\\begin{align*}\n\t\\mathbb{E}[\\mathbf{V}] = \\begin{pmatrix} \\mathbb{E}(v_1) \\\\ \\mathbb{E}(v_2) \\\\ . \\\\ . \\\\ .  \\\\ \\mathbb{E}(v_n) \\end{pmatrix}\n\\end{align*}\n\nThe variance of a vector is a little trickier,\n\\begin{align*}\n\tVar[\\mathbf{V}] = \\begin{pmatrix} Var(v_1) & Cov(v_1, v_2) & . & . & . & Cov(v_1, v_n) \\\\ Cov(v_2, v_1) & . & . & . & . & . \\\\ . & . & . & . & . & . \\\\ . & . & . & . & . & . \\\\ . & . & . & . & . & . \\\\ Cov(v_n, v_1) & . & . & . & . & Var(v_n, v_n) \\\\ \\end{pmatrix}\n\\end{align*}\n\n\\subsection{Bias}\nLet the true population process of $\\mathbf{y}$ be\n\n\\begin{align*}\n\t\\mathbf{y} = \\mathbf{X}\\boldsymbol{\\beta} + \\mathbf{u} \n\\end{align*}\n\nwhere $\\boldsymbol{\\beta}$ is the true population variable and $\\mathbf{u}$ is the population error. Least squares estimate as derived above is,\n\n\\begin{align*}\n\t\\boldsymbol{\\hat{\\beta}} & = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{y}                                   \\\\\n\t                         & = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T (\\mathbf{X}\\boldsymbol{\\beta} + \\mathbf{u}) \\\\\n\t                         & = \\boldsymbol{\\beta} + (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{u}              \n\\end{align*}\n\nTaking expectation on both sides,\n\n\\begin{align*}\n\t\\mathbb{E}[\\hat{\\boldsymbol{\\beta}}] & = \\mathbb{E}[\\boldsymbol{\\beta}] + \\mathbb{E}[(\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{u}] \\\\\n\t                                     & = \\boldsymbol{\\beta} + \\mathbb{E}[(\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{u}]             \n\\end{align*}\n\nAssuming $\\mathbf{u}$ and $\\mathbf{X}$ are independent, the equation can be simplified to,\n\n\\begin{align*}\n\t\\mathbb{E}[\\hat{\\boldsymbol{\\beta}}] & = \\boldsymbol{\\beta} + (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbb{E}[\\mathbf{u}] \\\\\n\\end{align*} \n\nAssuming $\\mathbb{E}[\\mathbf{u}] = 0$, the equation gets further simplified,\n\n\\begin{align*}\n\t\\mathbb{E}[\\hat{\\boldsymbol{\\beta}}] & = \\boldsymbol{\\beta} \n\\end{align*}\n\nUnder the conditional independence zero mean assumption [1], the least squares estimator is unbiased and on average the estimate is equivalent to the true population parameter.\n\n\\subsection{Variance} \n\nOnce again start with the least squares estimate equation,\n\n\\begin{align*}\n\t\\boldsymbol{\\hat{\\beta}} & = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{y} \\\\\n\\end{align*}\n\nTaking variance on both sides,\n\n\\begin{align*}\n\tVar[\\boldsymbol{\\hat{\\beta}}] & = Var[(\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\mathbf{y}] \n\\end{align*}\n\nSince the variance of the product of a non-stochastic matrix $\\mathbf{A}$ and a vector $\\mathbf{V}$ is $\\mathbf{A}Var(\\mathbf{V})\\mathbf{A}^T$,\n\n\\begin{align*}\n\tVar[\\boldsymbol{\\hat{\\beta}}] & = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\ Var[\\mathbf{y}]\\ ((\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T)^T \\\\\n\t                              & = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^T\\ Var[\\mathbf{y}]\\  \\mathbf{X}(\\mathbf{X}^T\\mathbf{X})^{-1}      \n\\end{align*} \n\nAssume that $Var[\\mathbf{v}] = \\sigma^2\\mathbf{I}$. This is same as saying that,\n\n\\begin{itemize}\n\t\\item All $y_i's$ are  homoscedastic i.e. $Var(y_i) = \\sigma^2 \\ \\forall\\ i\\ [2]$.\n\t\\item Distinct $y_i's$ are uncorrelated i.e. $Cov(y_i, y_j) = 0\\  \\forall\\ i \\neq j\\ [3]$.\n\\end{itemize}\n\n\\begin{align*}\n\tVar[\\boldsymbol{\\hat{\\beta}}] & = \\sigma^2 (\\mathbf{X}^T\\mathbf{X})^{-1} \n\\end{align*}\n\n\\section{Gauss-Markov Theorem}\n\nThis theorem states that under above assumptions [1], [2] and [3], the OLS estimators are BLUE (Best Linear Unbiased Estimators). This means that there are no other unbiased linear estimators which have a lower variance of $\\boldsymbol{\\beta}$ than OLS.  \n\n\\section{Ridge Regression}\n\nA penalty proportional to sum of squares of all $\\beta$ coefficients is added to the residual sum of squares in ridge regression to make sure that coefficients are reasonably bounded and don't grow arbitarily large.\n\n\\begin{align*}\n\t\\mathbf{Error}(\\boldsymbol{\\beta}) & = \\boldsymbol{\\epsilon}^T\\boldsymbol{\\epsilon} + \\lambda\\boldsymbol{\\beta}^T\\boldsymbol{\\beta} \n\\end{align*}\n\nThe solution to the above ridge regression problem is given below,\n\n\n\\begin{align*}\n\t\\boldsymbol{\\hat{\\beta}} & = (\\mathbf{X}^T\\mathbf{X} + \\lambda\\mathbf{I})^{-1}\\mathbf{X}^T\\mathbf{y} \n\\end{align*}\n\nAs $\\lambda$ tends to zero, the ridge solution tends to the OLS solution and as $\\lambda$ tends to infinity, the ridge solution tends to zero because of the infinite penalty for non-zero coefficients.\n\nIf $\\mathbf{X}^T\\mathbf{X}$ is non-invertible, OLS has no unique solution, but this problem does not occur with ridge regression as the matrix $\\mathbf{X}^T\\mathbf{X} + \\lambda\\mathbf{I}$ is always guaranteed to be invertible, therfore always ensuring unique solution.\n\nThe fundamental idea with ridge regression is to incur some bias in order to reduce variance which may often be desirable in practical situations.\n\nNow, a short excursion on Lagrange multipliers before the  introduction to Lasso regression.\n\n\\section{Lagrange Multipliers}\n\nSuppose a function $f$ is to be minimized subject to the constraint that the value of another function $g$ on the same inputs is $t$. For illustration, consider two inputs $x$ and $y$ with $f(x, y) = x^2 + y^2$, $g(x, y) = 4x + 3y$ and $t = 25$. Hence the problem is posed as follows:\n\n\\begin{align*}\n\tminimize\\ \\ &x^2 + y^2 &              \\\\\n\tsubject\\ to\\ \\ &4x + 3y = 25 &              \\\\\n\\end{align*}\n\n$f(x, y) = x^2 + y^2$ has a circular countour centered at origin. All points on this circle have the same value of $f$. On the ohter hand, the curve $4x + 3y = 25$ is a line offset from the origin. \n\nOne can imagine an expanding circle at origin which finally hits the line. The point where the circle hits the line is the solution as it is the minimum value of $f$ satisfying the constraint $g=25$. \n\nAt this intersection of the circle and the line, their gradients must be aligned to the same direction. More precisely, for some scalar $\\lambda$,\n\n\\begin{align*}\n\t\\begin{pmatrix}\\frac{\\partial f}{\\partial x} \\\\\n\t                                             \\\\  \\frac{\\partial f}{\\partial y} \\end{pmatrix} = \\lambda  \\begin{pmatrix}\\frac{\\partial g}{\\partial x} \\\\ \\\\ \\frac{\\partial g}{\\partial y} \\end{pmatrix}\n\\end{align*}\n\nNote that if one were to minimize $f - \\lambda g$, taking the partials and equating them to zero would have have led to the same equation above. Hence it makes no difference to pose the same problem differently as follows,\n\n\\begin{align*}\n\tminimize\\ \\ &f - \\lambda g &                            \\\\\n\t            & for\\ some\\ scalar\\ \\lambda \\\\\n\\end{align*}\n\nThe function $f - \\lambda g$ is called the Langrangian function and $\\lambda$ the Langragial multiplier.\n\n\\section{Lasso Regression}\n\nInstead of ridge regression's penalty which is proportional to the sum of squares of the $\\boldsymbol\\beta$s, Lasso penalizes the sum of moduli of the $\\boldsymbol\\beta$s. \n\n\\begin{align*}\n\t\\mathbf{Error}(\\boldsymbol{\\beta}) & = \\boldsymbol{\\epsilon}^T\\boldsymbol{\\epsilon} + \\lambda \\sum |\\boldsymbol\\beta_i| \n\\end{align*}\n\nFrom the discussion of Lagrange mutlipliers, the same problem can be posed as, \n\n\\begin{align*}\n\tminimize\\ \\ &\\boldsymbol{\\epsilon}^T\\boldsymbol{\\epsilon} &                                               \\\\\n\t            & subject\\ to\\ \\sum |\\boldsymbol\\beta_i| \\leq t \n\\end{align*}\n\nThe graphs of $\\sum |\\boldsymbol\\beta_i| \\leq t$ are right angle rotated squares centered at origin in two dimensions. \n\nAs before, imagine the expanding contours of $\\boldsymbol{\\epsilon}^T\\boldsymbol{\\epsilon}$ till they hit the constraint graph to deliver the solution. Since the constraint graph has corners, it is highly likely that the expanding contour of $\\boldsymbol{\\epsilon}^T\\boldsymbol{\\epsilon}$ will hit one of the corners. At that corner, one or more of the $\\boldsymbol\\beta$s will be zero.\n\nHence, Lasso not only shrinks the $\\boldsymbol\\beta$s but also makes some of them zero introducing sparsity in the solution and only retains only the most important $\\boldsymbol\\beta$s. This feature makes it considerably varied from the ridge regression.     \n\n\\end{document}", "meta": {"hexsha": "448277f9d0d2cbf876e0ebb528dd2672e550e590", "size": 16160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Regression/Linear Regression.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": "Linear Regression/Linear Regression.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": "Linear Regression/Linear Regression.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": 49.5705521472, "max_line_length": 386, "alphanum_fraction": 0.6219059406, "num_tokens": 5331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672043084051, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.6868338331918331}}
{"text": "\\section{A catalogue of constraint functions\\label{constraintAppendix}}\n\nLet us consider some examples of constraints to clarify the procedure.\n\n\\subsection{Fixed point in space (`Nail')\\label{constrNail}}\n\nThis simple constraint `nails' a particular point in a rigid body to a fixed point\nin world space. (It's a very flexible nail, because despite fixing the position, it allows all\nthree modes of rotation.) Let \\ve{p} be the position of the centre of mass of our rigid\nbody, \\ve{s} the vector from the centre of mass to the point in the body we want to attach,\n$\\ve{\\omega}$ the angular velocity of the rigid body, and \\ve{t} the coordinates in world\nspace that we want to nail the point to. Then we can set up a simple constraint function,\n\\begin{equation}\n\\ve{c} = \\ve{p} + \\ve{s} - \\ve{t}\n\\end{equation}\nwhich equals the null vector when $\\ve{p}+\\ve{s}$ and $\\ve{t}$ coincide, as required.\nSince this is a three-dimensional vector equation, we are actually defining three constraints\nat once. \\ve{t} does not change over time, so we obtain\n\\begin{eqnarray}\n\\dot{\\ve{c}} &=& \\dot{\\ve{p}} + \\ve{\\omega}\\times\\ve{s} \\nonumber\\\\\n&=& \\dot{\\ve{p}} - \\dual{\\ve{s}}\\,\\ve{\\omega} \\\\\n\\ddot{\\ve{c}} &=& \\ddot{\\ve{p}} + \\dot{\\ve{\\omega}}\\times\\ve{s} +\n    \\ve{\\omega}\\times(\\ve{\\omega}\\times\\ve{s}) \\nonumber\\\\\n&=& \\ddot{\\ve{p}} - \\dual{\\ve{s}}\\,\\dot{\\ve{\\omega}} -\n    \\dual{(\\ve{\\omega}\\times\\ve{s})}\\,\\ve{\\omega}\n\\end{eqnarray}\n(cf.\\ similar derivations in~\\cite{Kalra:95}). We have already moved the `chosen variables' to\nthe rightmost position of each product. We will now factor $\\dot{\\ve{c}}$ and write out the\ncomponents of $\\m{J}$ in terms of the vector components:\n\n\\begin{equation}\n\\label{constrEx1J}\n\\dot{\\ve{c}} = \\left[\\begin{array}{ccc} 1&0&0\\\\0&1&0\\\\0&0&1 \\end{array}\\right]\n    \\dot{\\ve{p}} + \\left[\\begin{array}{ccc}\n    0 & s_3 & -s_2 \\\\ -s_3 & 0 & s_1 \\\\ s_2 & -s_1 & 0\n    \\end{array}\\right] \\ve{\\omega}\n\\end{equation}\n\nThe two matrices in equation~\\ref{constrEx1J} thus form two slices of $\\m{J}$ at\nthe locations appropriate for $\\dot{\\ve{p}}$ and $\\ve{\\omega}$. We now continue to the\nnext step of the procedure:\n\n\\begin{eqnarray}\n\\dot{\\m{J}}\\dot{\\ve{x}} = \n\\ddot{\\ve{c}} - \\m{J}\\ddot{\\ve{x}} &=&\n    \\big(\\ddot{\\ve{p}} - \\dual{\\ve{s}}\\,\\dot{\\ve{\\omega}} -\n    \\dual{(\\ve{\\omega}\\times\\ve{s})}\\,\\ve{\\omega}\\big) -\n    (\\ddot{\\ve{p}} - \\dual{\\ve{s}}\\,\\dot{\\ve{\\omega}}) \\nonumber\\\\\n& = & -\\dual{(\\ve{\\omega}\\times\\ve{s})}\\,\\ve{\\omega} \\nonumber\\\\\n& = & \\left[\\begin{array}{ccc} 0 &\n    \\omega_1 s_2 - \\omega_2 s_1 &\n    \\omega_1 s_3 - \\omega_3 s_1 \\\\\n    \\omega_2 s_1 - \\omega_1 s_2 & 0 &\n    \\omega_2 s_3 - \\omega_3 s_2 \\\\\n    \\omega_3 s_1 - \\omega_1 s_3 &\n    \\omega_3 s_2 - \\omega_2 s_3 & 0\n    \\end{array}\\right] \\ve{\\omega} \\nonumber\\\\\\label{constrEx1JDot}\n\\end{eqnarray}\n\nWe see that here there is only one slice for $\\dot{\\m{J}}$; the slice belonging to $\\ddot{\\ve{p}}$\nis zero. Since $\\ve{\\omega}$ also occurs inside the matrix, there are actually several\nalternative representations of this matrix which are equally valid.\n\n\\subsection{Ball-and-socket joint\\label{constrJoint}}\n\nTwo rigid bodies are attached together at a particular point in each of the bodies.\nThey may not separate, but all three rotational degrees of freedom are permitted. This is\na good representation e.g.\\ of a human shoulder joint.\n\nLet $\\ve{a}$ and $\\ve{b}$ be the positions of the centres of mass in the first and\nsecond rigid body respectively. Let $\\ve{s}$ be the vector from $\\ve{a}$ to the \nattachment point, and $\\ve{t}$ the vector from $\\ve{b}$ to the attachment point.\nAlso let $\\ve{\\omega}$ be the angular velocity of the first body, and $\\ve{\\phi}$ that\nof the second. Then our constraint function and its derivatives are:\n\n\\begin{eqnarray}\n\\ve{c} &=& \\ve{a} + \\ve{s} - \\ve{b} - \\ve{t} \\\\\n\\dot{\\ve{c}} &=& \\dot{\\ve{a}} + \\ve{\\omega}\\times\\ve{s} -\n    \\dot{\\ve{b}} - \\ve{\\phi}\\times\\ve{t} \\\\\n\\ddot{\\ve{c}} &=& \\ddot{\\ve{a}} + \\dot{\\ve{\\omega}}\\times\\ve{s} +\n    \\ve{\\omega}\\times(\\ve{\\omega}\\times\\ve{s}) -\n    \\ddot{\\ve{b}} - \\dot{\\ve{\\phi}}\\times\\ve{t} -\n    \\ve{\\phi}\\times(\\ve{\\phi}\\times\\ve{t})\n\\end{eqnarray}\n\nThe rest of the derivation is very similar to the previous example. We obtain four\nmatrix slices for \\m{J} and two slices for $\\dot{\\m{J}}$.\n\n\n\\subsection{Rotation axis restriction (`Joystick')\\label{constrJoystick}}\n\nWe now have formulae to define a ball-and-socket joint. How can we express other types\nof joints? A good way of doing this is by augmenting the ball-and-socket constraint with\nadditional constraints which restrict the set of valid rotations. In this section I\nderive expressions for a constraint which prohibits rotation about one particular axis~--\nor, in other words, confines the axis of any valid rotation to a plane. In engineering terms,\nthis is called a universal joint~\\cite{Shabana:01}. Let us define a unit vector \\ve{n} which\npoints in the direction of the axis we want to prohibit; equivalently, this is the normal of\nthe confinement plane.\n\nIt is not completely easy to visualize what this type of constraint means. One good way to look\nat it is to consider a standard two-axis joystick. If it is placed on a table, the two axes of\nrotation lie in a plane parallel to the surface of this table. But you cannot turn the stick about\nits own axis. Hence the normal of the constraint plane is orthogonal to the table surface.\nDon't be confused by the fact that the joystick handle happens to point in the direction of the\nnormal~-- any sort of obscure shape may be substituted in its place without changing the nature\nof the constraint!\n\nA more common sort of joint is the \\emph{hinge} or \\emph{revolute joint}, which we find in most\ndoors, in our knees and elbows. It allows rotation only about one particular axis. We can\nconveniently express it by employing two `joystick' constraints on the same body, each of which\nconfines the axis to a plane. Provided the two planes are not parallel, the axis about which\nrotation may occur is just the line of intersection of these two planes. In summary, to make a\nrevolute joint, we first add a ball-and-socket joint. Then we find two non-collinear vectors\nwhich are both orthogonal to the hinge axis, and use them as normal vectors for two `joystick'\nconstraints. This reduces the original number of six degrees of freedom to one~-- the angle of\nthe hinge.\n\nFor this derivation I will use an alternative notation for quaternions, which is used by\nShoemake~\\cite{Shoemake:85}, amongst others. Instead of using the complex constants \\qi{}, \\qj{}\nand \\qk{}, a quaternion is written as a pair consisting of a scalar (the real part) and a 3D\nvector (the three imaginary parts):\n\\begin{equation}\n\\q{q} = q_w + q_x\\qi + q_y\\qj + q_z\\qk = [q_w, (q_x, q_y, q_z)^T] = [q_w, \\ve{q}_v]\n\\end{equation}\nUsing this notation, we can write the quaternion product in terms of vector dot and cross products:\n\\begin{equation}\\label{quatProduct2}\n\\q{p}\\q{q} = [p_w,\\; \\ve{p}_v]\\;[q_w,\\; \\ve{q}_v] =\n    [p_w q_w - \\ve{p}_v \\cdot \\ve{q}_v,\\;\n    p_w \\ve{q}_v + q_w \\ve{p}_v + \\ve{p}_v \\times \\ve{q}_v]\n\\end{equation}\n\nWe shall now consider the relative rotation of two rigid bodies. Say the first body has an\norientation quaternion \\q{p} and angular velocity \\ve{\\phi}, and the second body orientation\n\\q{q} and angular velocity \\ve{\\omega}. Assume that each quaternion expresses the rotation\nrequired to transform from the body's frame to the world frame. Then the quaternion product\n$\\q{p}^{-1}\\q{q}$ is the rotation required to transform from the second body's frame to the first\none's~-- that is, the relative rotation of the two bodies.\n\nTo confine the axis of rotation, we use the fact that the axis is contained in the imaginary\nparts of a quaternion (equation~\\ref{quatRotation}, page~\\pageref{quatRotation}). We want the dot\nproduct of this axis and the normal vector \\ve{n} to be zero. Conveniently, the dot product\nhappens to be implicitly present in the real part of the quaternion product\n(see equation~\\ref{quatProduct2}). Hence we can define our constraint\nfunction as follows:\n\\begin{equation}\\label{rotConstrEqn}\nc = \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\q{q})\n\\end{equation}\n\nAs with complex numbers, the function $\\Re$ returns only the real part of its argument.\nSince the real part of $\\tilde{\\ve{n}}$ is zero by definition, this is just the dot product of\n\\ve{n} and the axis of $\\q{p}^{-1}\\q{q}$, with an extra minus sign in\nfront~(cf.\\ equation~\\ref{quatProduct2}). The constraint function is a scalar because\nwe are only losing one degree of freedom.\n\nThe derivative of \\q{q} with respect to time is\n$\\dot{\\q{q}} = \\frac{1}{2}\\tilde{\\ve{\\omega}}\\q{q}$. Pushing the differential operator\nonto the inside of a quaternion inverse produces a minus sign and reverses the order, provided\nwe are dealing with a unit quaternion:\n\\begin{equation}\n\\frac{\\diff}{\\diff t} \\q{p} = \\frac{1}{2}\\tilde{\\ve{\\phi}}\\,\\q{p} \\iff\n    \\frac{\\diff}{\\diff t} (\\q{p}^{-1}) = -\\frac{1}{2}\\q{p}\\,\\tilde{\\ve{\\phi}}\n\\end{equation}\n\nWe now have everything in place to calculate the constraint function derivatives:\n\\begin{eqnarray}\n\\dot{c} & = & \\label{constrJoystickC}\n    \\frac{1}{2} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\omega}}\\,\\q{q}) -\n    \\frac{1}{2} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\phi}}\\, \\q{q}) \\\\\n\\ddot{c} & = & \\label{constrJoystickCDot}\n    \\frac{1}{2} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\dot{\\ve{\\omega}}}\\,\\q{q})\n  - \\frac{1}{2} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\dot{\\ve{\\phi}}}\\, \\q{q}) \\\\*\n&&+ \\frac{1}{4} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\omega}}\\,\\tilde{\\ve{\\omega}}\\, \\q{q})\n  - \\frac{1}{2} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\phi}}\\,\\tilde{\\ve{\\omega}}\\, \\q{q})\n  + \\frac{1}{4} \\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\phi}}\\,\\tilde{\\ve{\\phi}}\\, \\q{q})\n    \\nonumber\n\\end{eqnarray}\n\nWe manipulate these equations into the form required to find \\m{J}:\n\\begin{eqnarray*}\n\\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\omega}}\\,\\q{q}) & = &\n    \\Re\\big( [0,\\:\\ve{n}]\\: [p_w,\\:-\\ve{p}_v]\\: [0,\\:\\ve{\\omega}]\\: [q_w,\\:\\ve{q}_v] \\big) \\\\*\n&=& \\Re\\big( [\\ve{n}\\cdot\\ve{p}_v,\\: p_w\\ve{n} - \\ve{n}\\times\\ve{p}_v]\\:\n             [-\\ve{\\omega}\\cdot\\ve{q}_v,\\: q_w\\ve{\\omega} + \\ve{\\omega}\\times\\ve{q}_v] \\big) \\\\*\n&=& -(\\ve{n}\\cdot\\ve{p}_v) (\\ve{\\omega}\\cdot\\ve{q}_v) -\n    ( p_w\\ve{n} - \\ve{n}\\times\\ve{p}_v ) \\cdot ( q_w\\ve{\\omega} + \\ve{\\omega}\\times\\ve{q}_v ) \\\\*\n&=& -\\ve{n}^T \\ve{p}_v \\ve{q}_v^T \\ve{\\omega} - ( p_w\\ve{n} + \\ve{p}_v\\times\\ve{n} )^T\n    ( q_w\\ve{\\omega} - \\ve{q}_v\\times\\ve{\\omega} ) \\\\*\n&=& -\\ve{n}^T \\ve{p}_v \\ve{q}_v^T \\ve{\\omega} - ( p_w\\ve{n}^T - \\ve{n}^T\\dual{\\ve{p}_v} )\n    ( q_w\\ve{\\omega} - \\dual{\\ve{q}_v}\\,\\ve{\\omega} ) \\\\*\n&=& -\\ve{n}^T \\big( \\ve{p}_v \\ve{q}_v^T + ( p_w\\m{1} - \\dual{\\ve{p}_v} )\n    ( q_w\\m{1} - \\dual{\\ve{q}_v} ) \\big)\\, \\ve{\\omega}\n\\end{eqnarray*}\n\nHere \\m{1} denotes the $3\\times3$ identity matrix. The same derivation is valid if we substitute\n\\ve{\\phi} for \\ve{\\omega}, hence we obtain the Jacobian\n\\begin{eqnarray}\n\\m{J}\\dot{\\ve{x}} & = & \n    -\\frac{1}{2} \\ve{n}^T \\big( \\ve{p}_v \\ve{q}_v^T + ( p_w\\m{1} - \\dual{\\ve{p}_v} )\n    ( q_w\\m{1} - \\dual{\\ve{q}_v} ) \\big)\\, \\ve{\\omega} \\nonumber\\\\*\n&&  +\\frac{1}{2} \\ve{n}^T \\big( \\ve{p}_v \\ve{q}_v^T + ( p_w\\m{1} - \\dual{\\ve{p}_v} )\n    ( q_w\\m{1} - \\dual{\\ve{q}_v} ) \\big)\\, \\ve{\\phi}\n\\end{eqnarray}\n\nNow the first two terms of equation~\\ref{constrJoystickCDot} are generated by $\\m{J}\\ddot{x}$, so\nfor finding $\\dot{\\m{J}}$ we need only consider the last three terms. Let us evaluate the\npenultimate term:\n\\begin{eqnarray*}\n\\Re(\\tilde{\\ve{n}}\\, \\q{p}^{-1}\\, \\tilde{\\ve{\\phi}}\\,\\tilde{\\ve{\\omega}}\\, \\q{q}) & = &\n    \\Re\\big( [0,\\:\\ve{n}]\\: [p_w,\\:-\\ve{p}_v]\\: [0,\\:\\ve{\\phi}]\\: [0,\\:\\ve{\\omega}]\\:\n    [q_w,\\:\\ve{q}_v] \\big) \\\\*\n&=& \\Re\\big( [0,\\:\\ve{n}]\\: [\\ve{p}_v \\cdot \\ve{\\phi},\\: p_w\\ve{\\phi} - \\ve{p}_v\\times\\ve{\\phi}]\\:\n    [-\\ve{\\omega}\\cdot\\ve{q}_v,\\: q_w\\ve{\\omega} + \\ve{\\omega}\\times\\ve{q}_v] \\big) \\\\*\n&=& \\Re\\Big( \\begin{array}[t]{lll} \\big[ &\n    \\ve{n}\\cdot(\\ve{p}_v\\times\\ve{\\phi}) - p_w \\ve{\\phi}\\cdot\\ve{n}, &\\\\ &\n    (\\ve{p}_v\\cdot\\ve{\\phi}) \\ve{n} + p_w\\ve{n}\\times\\ve{\\phi} -\n        \\ve{n}\\times(\\ve{p}_v\\times\\ve{\\phi}) \\quad\\big] &\\\\\n    \\big[ & -\\ve{\\omega}\\cdot\\ve{q}_v,\\: q_w\\ve{\\omega} +\n        \\ve{\\omega}\\times\\ve{q}_v \\quad\\big] & \\Big) \\end{array} \\\\\n&=& -\\big( \\ve{n}\\cdot(\\ve{p}_v\\times\\ve{\\phi}) - p_w \\ve{\\phi}\\cdot\\ve{n} \\big)\n     \\big( \\ve{\\omega}\\cdot\\ve{q}_v \\big) \\\\* &&\n    -\\big( (\\ve{p}_v\\cdot\\ve{\\phi}) \\ve{n} + p_w\\ve{n}\\times\\ve{\\phi} -\n        \\ve{n}\\times(\\ve{p}_v\\times\\ve{\\phi}) \\big) \\cdot\n     \\big( q_w\\ve{\\omega} - \\ve{q}_v\\times\\ve{\\omega} \\big) \\\\\n&=& -\\big( \\ve{n}\\cdot(\\ve{p}_v\\times\\ve{\\phi}) \\big) \\big( \\ve{q}_v\\cdot\\ve{\\omega} \\big)\n    + p_w (\\ve{n}\\cdot\\ve{\\phi}) (\\ve{q}_v\\cdot\\ve{\\omega}) \\\\* &&\n    +\\big( \\ve{n}\\cdot(\\ve{q}_v\\times\\ve{\\omega}) \\big) \\big( \\ve{p}_v\\cdot\\ve{\\phi} \\big)\n    - q_w (\\ve{n}\\cdot\\ve{\\omega}) (\\ve{p}_v\\cdot\\ve{\\phi}) \\\\* &&\n    -\\big( \\ve{n}\\times(p_w\\ve{\\phi} - \\ve{p}_v\\times\\ve{\\phi}) \\big) \\cdot\n     \\big( q_w\\ve{\\omega} - \\ve{q}_v\\times\\ve{\\omega} \\big) \\\\\n&=&  \\ve{n}^T (p_w\\m{1} - \\dual{\\ve{p}_v})\\, \\ve{\\phi}\\,\\ve{q}_v^T \\ve{\\omega}\n    -\\ve{n}^T (q_w\\m{1} - \\dual{\\ve{q}_v})\\, \\ve{\\omega}\\,\\ve{p}_v^T \\ve{\\phi} \\\\* &&\n    +(p_w\\ve{\\phi} - \\ve{p}_v\\times\\ve{\\phi})^T \\dual{\\ve{n}}\n    (q_w\\m{1} - \\dual{\\ve{q}_v})\\, \\ve{\\omega}\n\\end{eqnarray*}\n\nFortunately, the other two terms of equation~\\ref{constrJoystickCDot} we are interested in are\nsimilar, so we can obtain them by substitution in the last expression. This gives us the\nfollowing expression for $\\dot{\\m{J}}$:\n\n\\begin{eqnarray}\n\\dot{\\m{J}}\\dot{\\ve{x}} &=&\n    \\frac{1}{4}\\Big( \\ve{n}^T (p_w\\m{1} - \\dual{\\ve{p}_v})\\, \\ve{\\omega}\\,\\ve{q}_v^T\n    -\\ve{n}^T (q_w\\m{1} - \\dual{\\ve{q}_v})\\, \\ve{\\omega}\\,\\ve{p}_v^T \\nonumber\\\\*&&\\quad\n    +(p_w\\ve{\\omega} - \\ve{p}_v\\times\\ve{\\omega})^T \\dual{\\ve{n}} (q_w\\m{1} - \\dual{\\ve{q}_v})\n    \\nonumber\\\\*&&\\quad\n    -2\\ve{n}^T (p_w\\m{1} - \\dual{\\ve{p}_v})\\, \\ve{\\phi}\\,\\ve{q}_v^T\n    -2(p_w\\ve{\\phi} - \\ve{p}_v\\times\\ve{\\phi})^T \\dual{\\ve{n}} (q_w\\m{1} - \\dual{\\ve{q}_v})\n    \\Big)\\, \\ve{\\omega} + \\nonumber\\\\*&&\n    \\frac{1}{4}\\Big( \\ve{n}^T (p_w\\m{1} - \\dual{\\ve{p}_v})\\, \\ve{\\phi}\\,\\ve{q}_v^T\n    -\\ve{n}^T (q_w\\m{1} - \\dual{\\ve{q}_v})\\, \\ve{\\phi}\\,\\ve{p}_v^T \\nonumber\\\\*&&\\quad\n    +(p_w\\ve{\\phi} - \\ve{p}_v\\times\\ve{\\phi})^T \\dual{\\ve{n}} (q_w\\m{1} - \\dual{\\ve{q}_v})\n    \\nonumber\\\\*&&\\quad\n    +2\\ve{n}^T (q_w\\m{1} - \\dual{\\ve{q}_v})\\, \\ve{\\omega}\\,\\ve{p}_v^T \\Big)\\,\\ve{\\phi}\n\\end{eqnarray}\n\n\n\\subsection{Rotation angle limitation}\n\nAs mentioned in section~\\ref{generalizedCollisions}, the constraint function of the last section\ncan be used in an inequality context to limit the angle of rotation rather than just the axes.\nAdding a constant value to the constraint function makes no difference to its derivatives and\ntherefore leaves the Jacobians derived in the last section unchanged.\n\nSo the implementation is easy, but the challenge is to understand what effect such an inequality\nactually has. Since quaternions are rather hard to visualize, let us translate the meaning of\nequation~\\ref{rotConstrEqn} into Euler angles. Choose three orthogonal axes with basis vectors\n\\ve{a}, \\ve{b} and \\ve{g} such that $\\ve{a}\\times\\ve{b}=\\ve{g}$ and $\\ve{b}\\times\\ve{g}=\\ve{a}$\nand $\\ve{g}\\times\\ve{a}=\\ve{b}$ and $\\norm{\\ve{a}} = \\norm{\\ve{b}} = \\norm{\\ve{g}} = 1$.\nConsider the rotation $\\q{p}^{-1}\\q{q}$ (the relative rotation between the two bodies), and\ndecompose it into a sequence of three rotations: first a rotation of $\\alpha$ about the \\ve{a}\naxis, then a rotation of $\\beta$ about the \\ve{b} axis, and finally a rotation of $\\gamma$ about\nthe \\ve{g} axis. Thus we have\n\\begin{eqnarray}\n\\q{p}^{-1}\\q{q} &=& \\q{g}\\q{b}\\q{a} \\\\\n\\q{a} &=& \\cos\\big(\\frac{\\alpha}{2}\\big) + \\tilde{\\ve{a}}\\sin\\big(\\frac{\\alpha}{2}\\big) \\\\\n\\q{b} &=& \\cos\\big(\\frac{\\beta }{2}\\big) + \\tilde{\\ve{b}}\\sin\\big(\\frac{\\beta }{2}\\big) \\\\\n\\q{g} &=& \\cos\\big(\\frac{\\gamma}{2}\\big) + \\tilde{\\ve{g}}\\sin\\big(\\frac{\\gamma}{2}\\big)\n\\end{eqnarray}\n\nNow if we evaluate the constraint function about each of the axes \\ve{a}, \\ve{b} and \\ve{g}, we\nget (skipping some boring algebra):\n\\begin{eqnarray}\n\\Re(\\tilde{\\ve{a}}\\,\\q{g}\\q{b}\\q{a}) &=& -\\sin\\big(\\frac{\\alpha}{2}\\big)\n     \\cos\\big(\\frac{\\beta }{2}\\big)   \\cos\\big(\\frac{\\gamma}{2}\\big)\n    -\\cos\\big(\\frac{\\alpha}{2}\\big)   \\sin\\big(\\frac{\\beta }{2}\\big)\n     \\sin\\big(\\frac{\\gamma}{2}\\big)   \\label{angleLimit1}\\\\\n\\Re(\\tilde{\\ve{b}}\\,\\q{g}\\q{b}\\q{a}) &=& -\\cos\\big(\\frac{\\alpha}{2}\\big)\n     \\sin\\big(\\frac{\\beta }{2}\\big)   \\cos\\big(\\frac{\\gamma}{2}\\big)\n    -\\sin\\big(\\frac{\\alpha}{2}\\big)   \\cos\\big(\\frac{\\beta }{2}\\big)\n     \\sin\\big(\\frac{\\gamma}{2}\\big)   \\label{angleLimit2}\\\\\n\\Re(\\tilde{\\ve{g}}\\,\\q{g}\\q{b}\\q{a}) &=& -\\cos\\big(\\frac{\\alpha}{2}\\big)\n     \\cos\\big(\\frac{\\beta }{2}\\big)   \\sin\\big(\\frac{\\gamma}{2}\\big)\n    -\\sin\\big(\\frac{\\alpha}{2}\\big)   \\sin\\big(\\frac{\\beta }{2}\\big)\n     \\cos\\big(\\frac{\\gamma}{2}\\big)   \\label{angleLimit3}\n\\end{eqnarray}\n\nThese expressions make clear how interdependent the three axes are~-- it is generally not\npossible to change a constraint on one axis without affecting the others. The best way to proceed\nfrom here is to enter inequalities using formulae~\\ref{angleLimit1} to~\\ref{angleLimit3} into\na program for graphical visualization, and to experimentally determine the values such that the\ndesired behaviour is achieved.\n\n\n\\subsection{Confinement to a plane (vertex/face collision) \\label{vertexFaceConstraint}}\n\nWe want to define a constraint function whose value is the distance between a point\nand a plane, where the point is attached to one rigid body, and the plane to another. The plane\nis defined by a point in the plane and a normal vector. The distance should be positive if the\npoint is on the side of the plane pointed to by the normal, and negative if it is on the opposite\nside. If we put this constraint directly into the Lagrange multiplier equation, it will enforce\nthe condition that the distance be zero~-- the point is confined to move only within the plane.\nBut if we use the same constraint function in an inequality, we have a handler for the\nvertex/face collision case.\n\nSay \\ve{a} is the centre of mass position of the body to which the plane is attached, and \\ve{s}\nis the vector from the centre of mass to an arbitrary point in the plane. The angular velocity\nof this body is \\ve{\\omega}. The plane has a unit normal vector $\\hat{\\ve{n}}$\n($\\norm{\\hat{\\ve{n}}} = 1$). The point we are interested in is $\\ve{b} + \\ve{t}$, where \\ve{b} is\nthe centre of mass position of the body to which the point belongs. This body has angular\nvelocity \\ve{\\phi}.\n\nThen the constraint function and its derivatives are given by\n\\begin{eqnarray}\nc &=& (\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s})\\cdot\\hat{\\ve{n}} \\\\\n\\dot{c} &=& (\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} - \\ve{\\omega}\\times\\ve{s})\n    \\cdot\\hat{\\ve{n}} + (\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s})\\cdot(\\ve{\\omega}\\times\\hat{\\ve{n}})\n    \\nonumber\\\\\n&=& \\hat{\\ve{n}}^T\\dot{\\ve{b}} - \\hat{\\ve{n}}^T\\dot{\\ve{a}} - \\hat{\\ve{n}}^T\\dual{\\ve{t}}\\ve{\\phi}\n    + (\\ve{a} - \\ve{b} - \\ve{t})^T \\dual{\\hat{\\ve{n}}} \\ve{\\omega} \\\\\n\\ddot{c} &=& \\big( \\ddot{\\ve{b}} + \\dot{\\ve{\\phi}}\\times\\ve{t} +\n    \\ve{\\phi}\\times(\\ve{\\phi}\\times\\ve{t}) - \\ddot{\\ve{a}} \\big) \\cdot \\hat{\\ve{n}}+\\nonumber\\\\*&&\n    2\\big(\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}}\\big)\n    \\cdot \\big(\\ve{\\omega}\\times\\hat{\\ve{n}}\\big)\n    + \\big(\\ve{b} + \\ve{t} - \\ve{a}\\big) \\cdot \\big( \\dot{\\ve{\\omega}}\\times\\hat{\\ve{n}} +\n    \\ve{\\omega}\\times(\\ve{\\omega}\\times\\hat{\\ve{n}}) \\big) \\nonumber\\\\\n&=&  \\hat{\\ve{n}}^T \\ddot{\\ve{b}}\n    -\\hat{\\ve{n}}^T \\ddot{\\ve{a}}\n    -\\hat{\\ve{n}}^T\\dual{\\ve{t}} \\dot{\\ve{\\phi}}\n    +(\\ve{a} - \\ve{b} - \\ve{t})^T \\dual{\\hat{\\ve{n}}} \\dot{\\ve{\\omega}} + \\\\*&&\n    \\big( 2(\\dot{\\ve{a}} - \\dot{\\ve{b}} - \\ve{\\phi}\\times\\ve{t})^T \\dual{\\hat{\\ve{n}}} \n    +(\\ve{a} - \\ve{b} - \\ve{t})^T \\dual{(\\ve{\\omega}\\times\\hat{\\ve{n}})}\\big) \\ve{\\omega}\n    -\\hat{\\ve{n}}^T\\dual{(\\ve{\\phi}\\times\\ve{t})} \\ve{\\phi} \\nonumber\n\\end{eqnarray}\nfrom which \\m{J} and $\\dot{\\m{J}}$ can be read off as usual.\n\n\n\\subsection{Edge/edge collision\\label{edgeEdgeConstraint}}\n\nIn this section we require a constraint function whose value is the shortest distance between\ntwo straight lines. The problem is closely related to the one in\nsection~\\ref{vertexFaceConstraint}. If used as an equality constraint, it could be used to\nsimulate two metal rods which are joined together such that the join can move up or down either\nof the rods, but the rods always have to touch in one point~-- a kind of combination of a\nball-and-socket joint with two one-dimensional sliding rails. However, the practical use of such\na system is rather limited. Much more important is the use of this constraint as an inequality,\nwhere it can handle the collision situation in which two edges collide.\n\nWe assume that each straight line is connected to a rigid body. The first body's centre of mass\nis located at \\ve{a}, its angular velocity is \\ve{\\omega}, \\ve{s} is a vector from the centre\nof mass to an arbitrary point on the line, and \\ve{u} is a vector pointing along the line (unit\nmagnitude is not required). Similarly, the second body's CoM is \\ve{b}, its angular velocity is\n\\ve{\\phi}, \\ve{t} points at the line and \\ve{v} points in the line's direction. In this\nderivation we shall assume that the lines are not parallel\n($\\norm{\\ve{u}\\times\\ve{v}} \\ne \\ve{0}$); the parallel case is special and needs to be handled\nseparately.\n\nIf \\ve{u} and \\ve{v} are not parallel, we can find a unique plane which contains one line and is\nparallel to the other. This plane has a normal vector $\\ve{n} = \\ve{u}\\times\\ve{v}$ (or\n$\\ve{n} = \\ve{v}\\times\\ve{u}$). Interestingly this normal is the direction in which the force or\nimpulse acts in the event of a collision. It is not obvious that this is the case, but by playing\naround with two books or similar it is possible to convince oneself. Then the closest distance\nbetween the two lines is given by\n\\begin{equation}\nc = (\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s})\\cdot\\frac{\\ve{n}}{\\norm{\\ve{n}}}\n\\end{equation}\n\nThe derivation of the Jacobian matrices involves some of the most messy linear algebra in this\nproject, so hold on tight. Let us first define a few auxiliary variables:\n\\begin{eqnarray}\n\\ve{n} & = & \\ve{u}\\times\\ve{v} \\\\\nh &=& \\frac{1}{\\norm{\\ve{n}}} = (\\ve{n}\\cdot\\ve{n})^{-\\frac{1}{2}} \\\\\n\\ve{z} &=& \\dot{\\ve{n}} = \\dot{\\ve{u}}\\times\\ve{v} + \\ve{u}\\times\\dot{\\ve{v}} \\nonumber\\\\*\n    &=& (\\ve{\\omega}\\times\\ve{u})\\times\\ve{v} + \\ve{u}\\times(\\ve{\\phi}\\times\\ve{v}) \\nonumber\\\\*\n    &=& \\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi} \\\\\n\\ve{y} &=& \\dot{\\ve{z}} = \\ddot{\\ve{u}}\\times\\ve{v} + 2\\,\\dot{\\ve{u}}\\times\\dot{\\ve{v}} +\n        \\ve{u}\\times\\ddot{\\ve{v}} \\nonumber\\\\*\n    &=& (\\dot{\\ve{\\omega}}\\times\\ve{u})\\times\\ve{v} +\n        (\\ve{\\omega}\\times(\\ve{\\omega}\\times\\ve{u}))\\times\\ve{v} +\n        2\\,(\\ve{\\omega}\\times\\ve{u})\\times(\\ve{\\phi}\\times\\ve{v}) + \\nonumber\\\\*&&\n        \\ve{u}\\times(\\dot{\\ve{\\phi}}\\times\\ve{v}) +\n        \\ve{u}\\times(\\ve{\\phi}\\times(\\ve{\\phi}\\times\\ve{v})) \\\\*\n    &=& \\dual{\\ve{v}}\\dual{\\ve{u}}\\dot{\\ve{\\omega}} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\dot{\\ve{\\phi}} +\n        \\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{u})}\\ve{\\omega} -\n        \\dual{\\ve{u}}\\dual{(\\ve{\\phi}\\times\\ve{v})}\\ve{\\phi} +\n        2\\,\\dual{(\\ve{\\phi}\\times\\ve{v})}\\dual{\\ve{u}}\\ve{\\omega} \\nonumber\\\\\n\\hat{\\ve{n}} & = & h\\ve{n} \\\\\n\\dot{\\hat{\\ve{n}}} & = & h\\ve{z} - \\frac{1}{2}\\ve{n}(\\ve{n}\\cdot\\ve{n})^{-\\frac{3}{2}}\n        (\\ve{z}\\cdot\\ve{n} + \\ve{n}\\cdot\\ve{z}) \\nonumber\\\\*\n    &=& h\\ve{z} - h^3\\,(\\ve{n}\\cdot\\ve{z})\\,\\ve{n} \\\\\n\\ddot{\\hat{\\ve{n}}} & = & h\\ve{y} - 2h^3 (\\ve{n}\\cdot\\ve{z})\\,\\ve{z} -\n        h^3 (\\ve{n}\\cdot\\ve{y})\\,\\ve{n}\n        -h^3 (\\ve{z}\\cdot\\ve{z})\\,\\ve{n} + 3h^5 (\\ve{n}\\cdot\\ve{z})^2\\,\\ve{n}\n\\end{eqnarray}\n\nNow we can turn to calculating the derivatives of $c$:\n\\begin{eqnarray}\n\\dot{c} &=& \\hat{\\ve{n}}\\cdot(\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} -\n        \\ve{\\omega}\\times\\ve{s}) + (\\ve{b}+\\ve{t}-\\ve{a}-\\ve{s})\\cdot\\dot{\\hat{\\ve{n}}} \\\\*\n    &=& h\\,(\\ve{u}\\times\\ve{v})^T (\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} -\n        \\ve{\\omega}\\times\\ve{s}) + \\nonumber\\\\*&&\n        (\\ve{b}+\\ve{t}-\\ve{a}-\\ve{s})^T \\big( h\\ve{z} - h^3\\,(\\ve{n}\\cdot\\ve{z})\\,\\ve{n} \\big)\n        \\nonumber\\\\\n    &=& h\\ve{u}^T\\dual{\\ve{v}}\\dot{\\ve{b}} - h\\ve{u}^T\\dual{\\ve{v}}\\dot{\\ve{a}} -\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{t}}\\ve{\\phi} +\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{s}}\\ve{\\omega} + \\nonumber\\\\*&&\n        (\\ve{b}+\\ve{t}-\\ve{a}-\\ve{s})^T\n        \\big(h\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - h\\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi} -\n        h^3\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\\big)\n        \\nonumber\\\\\n    &=& h\\ve{u}^T\\dual{\\ve{v}}\\dot{\\ve{b}} - h\\ve{u}^T\\dual{\\ve{v}}\\dot{\\ve{a}} \\nonumber\\\\*&&\n        +\\Big( h\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{s}} + h\\,(\\ve{b}+\\ve{t}-\\ve{a}-\\ve{s})^T\n        (\\m{1} - h^2 \\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}) \\dual{\\ve{v}}\\dual{\\ve{u}}\n        \\Big)\\:\\ve{\\omega} \\nonumber\\\\*&&\n        -\\Big( h\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{t}} + h\\,(\\ve{b}+\\ve{t}-\\ve{a}-\\ve{s})^T\n        (\\m{1} - h^2 \\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}) \\dual{\\ve{u}}\\dual{\\ve{v}}\n        \\Big)\\:\\ve{\\phi} \\\\*\n    &=& \\m{J}\\dot{\\ve{x}} \\nonumber\\\\\n\\ddot{c} &=& \\hat{\\ve{n}}\\cdot\\Big(\\ddot{\\ve{b}} + \\dot{\\ve{\\phi}}\\times\\ve{t} +\n        \\ve{\\phi}\\times(\\ve{\\phi}\\times\\ve{t}) - \\ddot{\\ve{a}} - \\dot{\\ve{\\omega}}\\times\\ve{s} -\n        \\ve{\\omega}\\times(\\ve{\\omega}\\times\\ve{s})\\Big) + \\nonumber\\\\*&&\n        2\\,\\Big(\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} - \\ve{\\omega}\\times\\ve{s}\\Big)\n        \\cdot\\dot{\\hat{\\ve{n}}} +\n        \\Big(\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s}\\Big)\\cdot\\ddot{\\hat{\\ve{n}}} \\\\\n    &=& h\\ve{u}^T\\dual{\\ve{v}}\\ddot{\\ve{b}} - h\\ve{u}^T\\dual{\\ve{v}}\\ddot{\\ve{a}} -\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{t}}\\dot{\\ve{\\phi}} +\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{s}}\\dot{\\ve{\\omega}} + \\nonumber\\\\*&&\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{s})}\\ve{\\omega} -\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{(\\ve{\\phi}\\times\\ve{t})}\\ve{\\phi} \\nonumber\\\\*&&\n        +2h\\,(\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} - \\ve{\\omega}\\times\\ve{s})^T\n        \\Big(\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi}\n        \\nonumber\\\\*&&\\quad\\quad -h^2\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\\Big)\n        \\nonumber\\\\*&& +(\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s})^T \\Big(\n        \\nonumber\\\\*&&\\quad\\quad h\\,\\big(\n        \\dual{\\ve{v}}\\dual{\\ve{u}}\\dot{\\ve{\\omega}} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\dot{\\ve{\\phi}} +\n        \\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{u})}\\ve{\\omega} \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -\\dual{\\ve{u}}\\dual{(\\ve{\\phi}\\times\\ve{v})}\\ve{\\phi} +\n        2\\,\\dual{(\\ve{\\phi}\\times\\ve{v})}\\dual{\\ve{u}}\\ve{\\omega} \\big)\n        \\nonumber\\\\*&&\\quad\\quad\n        -2h^3 (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\nonumber\\\\*&&\\quad\\quad\n        -h^3\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}} \\big(\n        \\dual{\\ve{v}}\\dual{\\ve{u}}\\dot{\\ve{\\omega}} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\dot{\\ve{\\phi}} +\n        \\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{u})}\\ve{\\omega} \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -\\dual{\\ve{u}}\\dual{(\\ve{\\phi}\\times\\ve{v})}\\ve{\\phi} +\n        2\\,\\dual{(\\ve{\\phi}\\times\\ve{v})}\\dual{\\ve{u}}\\ve{\\omega} \\big)\n        \\nonumber\\\\*&&\\quad\\quad\n        -h^3 \\dual{\\ve{u}}\\ve{v}\n        (\\ve{\\omega}^T\\dual{\\ve{u}}\\dual{\\ve{v}} - \\ve{\\phi}^T\\dual{\\ve{v}}\\dual{\\ve{u}})\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\nonumber\\\\*&&\\quad\\quad\n        +3h^5 \\dual{\\ve{u}}\\ve{v} \\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi}) \\Big) \\nonumber\n\\end{eqnarray}\n\\newpage\n\nFinally we subtract the terms generated by $\\m{J}\\ddot{\\ve{x}}$ from $\\ddot{c}$ and separate\ninto factors of \\ve{\\omega} and \\ve{\\phi} as usual:\n\\begin{eqnarray}\n\\dot{\\m{J}}\\dot{\\ve{x}} &=& \\bigg(\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{s})} \\\\*&&\\quad\\quad +\n        2h\\,(\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} - \\ve{\\omega}\\times\\ve{s})^T\n        (\\m{1} - h^2\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}) \\dual{\\ve{v}}\\dual{\\ve{u}}\n        \\nonumber\\\\*&&\\quad\\quad\n        +(\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s})^T \\Big(\n        h\\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{u})}\n        +2h\\,\\dual{(\\ve{\\phi}\\times\\ve{v})}\\dual{\\ve{u}} \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -h^3\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{v}}\\dual{(\\ve{\\omega}\\times\\ve{u})}\n        -2h^3\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}\\dual{(\\ve{\\phi}\\times\\ve{v})}\\dual{\\ve{u}}\n        \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -2h^3\\,(\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{v}}\\dual{\\ve{u}}\n        \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -h^3 \\dual{\\ve{u}}\\ve{v} \\big(\n        \\ve{\\omega}^T\\dual{\\ve{u}}\\dual{\\ve{v}} - \\ve{\\phi}^T\\dual{\\ve{v}}\\dual{\\ve{u}}\n        \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\\quad\\quad\n        -3h^2 \\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\ve{u}^T\\dual{\\ve{v}} \\big) \\dual{\\ve{v}}\\dual{\\ve{u}} \\Big) \\bigg)\\: \\ve{\\omega}\n        \\nonumber\\\\*&&\n        -\\bigg(\n        h\\ve{u}^T\\dual{\\ve{v}}\\dual{(\\ve{\\phi}\\times\\ve{t})} \\nonumber\\\\*&&\\quad\\quad\n        +2h\\,(\\dot{\\ve{b}} + \\ve{\\phi}\\times\\ve{t} - \\dot{\\ve{a}} - \\ve{\\omega}\\times\\ve{s})^T\n        (\\m{1} - h^2\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}) \\dual{\\ve{u}}\\dual{\\ve{v}}\n        \\nonumber\\\\*&&\\quad\\quad\n        +(\\ve{b} + \\ve{t} - \\ve{a} - \\ve{s})^T \\Big(\n        h\\dual{\\ve{u}}\\dual{(\\ve{\\phi}\\times\\ve{v})}\n        -h^3\\dual{\\ve{u}}\\ve{v}\\ve{u}^T\\dual{\\ve{v}}\\dual{\\ve{u}}\\dual{(\\ve{\\phi}\\times\\ve{v})}\n        \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -2h^3\\,(\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\ve{u}^T\\dual{\\ve{v}} \\dual{\\ve{u}}\\dual{\\ve{v}}\n        \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\n        -h^3 \\dual{\\ve{u}}\\ve{v} \\big(\n        \\ve{\\omega}^T\\dual{\\ve{u}}\\dual{\\ve{v}} - \\ve{\\phi}^T\\dual{\\ve{v}}\\dual{\\ve{u}}\n        \\nonumber\\\\*&&\\quad\\quad\\quad\\quad\\quad\\quad\n        -3h^2 \\ve{u}^T\\dual{\\ve{v}}\n        (\\dual{\\ve{v}}\\dual{\\ve{u}}\\ve{\\omega} - \\dual{\\ve{u}}\\dual{\\ve{v}}\\ve{\\phi})\n        \\ve{u}^T\\dual{\\ve{v}}\n        \\big) \\dual{\\ve{u}}\\dual{\\ve{v}} \\Big) \\bigg)\\: \\ve{\\phi} \\nonumber\n\\end{eqnarray}\n", "meta": {"hexsha": "e82e7b17faaeba81ef3c9260aa879de5908ab5b6", "size": 31146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/constrEx.tex", "max_stars_repo_name": "ept/maniation", "max_stars_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-05-09T00:54:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:40:52.000Z", "max_issues_repo_path": "report/constrEx.tex", "max_issues_repo_name": "ept/maniation", "max_issues_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/constrEx.tex", "max_forks_repo_name": "ept/maniation", "max_forks_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-17T14:39:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-08T05:38:45.000Z", "avg_line_length": 60.2437137331, "max_line_length": 101, "alphanum_fraction": 0.5986001413, "num_tokens": 12398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979306, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6868080741319195}}
{"text": "\\chapter{Applications and Case Studies}\nThis chapter contains a number of case studies designed to deepen our understanding of \\textsl{Python}.\n\n\\section{Solving Equations via Fixed-Point Algorithms}\n\\href{https://en.wikipedia.org/wiki/Fixed-point_iteration}{Fixed-Point iterations} are very important, both in\ncomputer science and in mathematics.  As a first example, we show how to solve a given equation numerically via\na fixed point iteration. \\index{fixed point iteration} Suppose we want to solve the equation  \n\\\\[0.2cm]\n\\hspace*{1.3cm} $x = \\cos(x)$. \\\\[0.2cm]\nHere, $x$ is a real number that we seek to compute.  Figure \\ref{fig:xEqualsCosX.pdf} on page\n\\pageref{fig:xEqualsCosX.pdf} shows the graphs of the two functions  \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$y = x$  \\quad and \\quad $y = \\cos(x)$.\n\\\\[0.2cm]\nSince the graphs of these functions intersect, it is obvious that there exists a value $x$ such that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x = \\cos(x)$. \n\\\\[0.2cm] \nFurthermore, from Figure \\ref{fig:xEqualsCosX.pdf} it is obvious that this value of $x$ is somewhat bigger than $0.6$\nbut less than $0.8$. \n\n\\begin{figure}[!ht]\n  \\hspace*{-3.0cm}\n  \\epsfig{file=Figures/xEqualsCosX.pdf,scale=0.6}\n\n  \\caption{The functions $y = x$ and $y = cos(x)$.}\n  \\label{fig:xEqualsCosX.pdf}\n\\end{figure}\n\n\n\nA simple approach that enables us to solve the equation $x = \\cos(x)$ is to conduct a\n\\href{https://en.wikipedia.org/wiki/Fixed-point_iteration}{fixed-point iteration}.  To this end, we\ndefine the sequence $\\bigl(x_n\\bigr)_{n\\in\\mathbb{N}}$ inductively as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$x_0 = 0$ \\quad and \\quad $x_{n+1} = \\mathtt{cos}(x_n)$ \\quad for all $n \\in \\mathbb{N}$. \n\\\\[0.2cm]\nWith the help of the \n\\href{https://en.wikipedia.org/wiki/Banach_fixed-point_theorem}{Banach fixed-point theorem}\\footnote{\n  The Banach fixed-point theorem is discussed in the lecture on\n  \\href{https://en.wikipedia.org/wiki/Differential_calculus}{differential calculus}.  This lecture is part of the\n  second semester.\n}\n\\index{Banach fixed-point theorem}\nit can be shown that this sequence converges to a solution of the equation $x = \\cos(x)$, i.e.~if we define\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\bar{x} = \\lim\\limits_{n\\rightarrow\\infty} x_n$,\n\\\\[0.2cm]\nthen we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\cos\\bigl(\\bar{x}\\bigr) = \\bar{x}$.\n\\\\[0.2cm]\nFigure \\ref{fig:solve.py} on page \\pageref{fig:solve.py} shows the program\n\\href{https://github.com/karlstroetmann/Logic/blob/master/Python/solve.py}{\\texttt{solve.py}}\nthat uses this approach to solve the equation $x = \\cos(x)$.\n\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}\n    import math\n    \n    x     = 1.0\n    old_x = 0.0\n    i     = 1\n    while abs(x - old_x) >= 4.0E-16:\n        old_x = x\n        x = math.cos(x)\n        print(f'{i} : {x}')\n        i += 1\n\\end{minted} \n\\vspace*{-0.3cm}\n\\caption{Solving the equation $x = \\cos(x)$ via fixed-point iteration.}  \\label{fig:solve.py}\n\\end{figure} %\\$\n\nIn this program, the iteration stops as soon as the difference between the variables \\texttt{x} and \n\\texttt{old\\_x} is less that $4 \\cdot 10^{-16}$.  Here, \\texttt{x} corresponds to $x_{n+1}$, while \\texttt{old\\_x}\ncorresponds to $x_n$.  Once the values of $x_{n+1}$ and $x_n$ are sufficiently close, the execution of the \\texttt{while} loop\nterminates.\n\\href{https://github.com/karlstroetmann/Logic/blob/master/Python/Fixed-Point-Iteration.ipynb}{Fixed-Point-Iteration.ipynb}\nshows a \\textsl{Jupyter} notebook that implements fixed point iteration.\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                firstnumber   = 1,\n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}\n    from math import cos\n    \n    def solve(f, x0):\n        \"\"\"\n        Solve the equation f(x) = x using a fixed point iteration.\n        x0 is the start value.\n        \"\"\"\n        x = x0\n        for n in range(10000):  # at most 10000 iterations\n            oldX = x;\n            x    = f(x);\n            if abs(x - oldX) < 1.0e-15: \n                return x;\n    \n    print(\"solution to x = cos(x): \", solve(cos, 0));\n    print(\"solution to x = 1/(1+x):\", solve(lambda x: 1/(1+x), 0));\n\\end{minted}\n\\vspace*{-0.3cm}\n\\caption{A generic implementation of the fixed-point algorithm.}\n\\label{fig:fixed-point.py}\n\\end{figure}\n\nFigure \\ref{fig:fixed-point.py} on page \\pageref{fig:fixed-point.py} shows the program\n\\href{https://github.com/karlstroetmann/Logic/blob/master/Python/fixed-point.py}{\\texttt{fixed-point.py}}.\nIn this program we have implemented a function \\texttt{solve} that takes two arguments.\n\\begin{enumerate}\n\\item \\texttt{f} is a unary function.  The purpose of the \\texttt{solve} is to compute the solution of the equation\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $f(x) = x$.\n      \\\\[0.2cm]\n      This equation is solved with the help of a fixed-point algorithm.\n\\item \\texttt{x0} is used as the initial value for the fixed-point iteration.\n\\end{enumerate}\nLine 11 calls \\texttt{solve} to compute the solution of the equation $x = \\cos(x)$.\nLine 12 solves the equation \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds x = \\bruch{1}{1+x}$. \n\\\\[0.2cm]\nThis equation is equivalent to the quadratic equation $x^2 + x = 1$.  Note that we have defined the function\n $\\ds x \\mapsto \\frac{1}{1+x}$ via the expression\n \\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{lambda x: 1/(1+x)}.\n\\\\[0.2cm]\nThis expression is called an \\blue{anonymous function} \n\\index{lambda expression, \\texttt{lambda x: f(x)}}\nsince we haven't given a name to the function.  \n\n\\remarkEng\nThe function \\texttt{solve} is only able to solve the equation $f(x) = x$ if the function $f$ is a \n\\href{https://en.wikipedia.org/wiki/Contraction_mapping}{contraction mapping} (Deutsch: \\blue{kontrahierende Abbildung}). \n\\index{contraction mapping}\n  A function \n$f:\\mathbb{R} \\rightarrow \\mathbb{R}$\nis called a \\blue{contraction mapping} iff \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$|f(x) - f(y)| < |x - y|$ \\quad for all $x,y \\in \\mathbb{R}$.\n\\\\[0.2cm]\nThis notion will be discussed in more detail in the lecture on \n\\href{https://github.com/karlstroetmann/Analysis/blob/master/Skript/analysis.pdf}{analysis} in the second\nsemester. \\eox  \n\n\\section{Case Study: Computation of Poker Probabilities}\n\\index{poker}\nIn this short section we are going to show how to compute probabilities for the\n\\href{https://en.wikipedia.org/wiki/Texas_hold_%27em}{\\textsl{Texas Hold'em}} variation of \n\\href{https://en.wikipedia.org/wiki/Poker}{poker}.   Texas Hold'em poker is played with a deck of 52\ncards.  Every card has a \\blue{value}.  This value is an element of the set\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\textsl{Values} = \\{ 2, 3, 4, 5, 6, 7, 8, 9, 10, \\textsl{Jack}, \\textsl{Queen}, \\textsl{King}, \\textsl{Ace} \\}$.\n\\\\[0.2cm]\nFurthermore, every card has a \\blue{suit}.  This suit is an element of the set\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\textsl{Suits} = \\{ \\club, \\mbox{$\\color{red}{\\heart}$}, \\mbox{$\\color{red}{\\diamondsuit}$}, \\spade \\}$.\n\\\\[0.2cm]\nThese suits are pronounced \\blue{club}, \\blue{heart}, \\blue{diamond}, and \\blue{spade}.\nAs a card is determined by its value and its suit, a card can be represented as a pair $\\pair(v,s)$, where $v$\ndenotes the value while $s$ is the suit of the card.  Hence, the set of all cards can be represented as the set\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\textsl{Deck} = \\bigl\\{ \\pair(v,s) \\mid v \\in \\textsl{Values} \\wedge \\textsl{s} \\in \\textsl{Suits} \\bigr\\}$.\n\\\\[0.2cm]\nAt the start of a game of Texas Hold'em, every player receives two cards.  These two cards are known\nas the \\blue{preflop} or the \\blue{hole}.  Next, there is a \\blue{bidding phase} where players can bet on their\ncards.   After this bidding phase, the dealer puts three cards open on the table.  These three cards are\nknown as \\blue{flop}.  Let us assume that a player has been dealt the set of cards\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{ \\pair(3, \\club), \\pair(3, \\spade) \\}$.\n\\\\[0.2cm]\nThis set of cards is known as a \\blue{pocket pair}.  Then the player would like to know the probability\nthat the flop will contain another card with value $3$, as this would greatly increase her chance of\nwinning the game.  In order to compute this probability we have to compute the number of possible\nflops that contain a card with the value $3$ and we have to divide this number by the number of all\npossible flops:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds \\frac{\\;\\mbox{number of flops containing a card with value $3$}\\;}{\\mbox{number of all possible flops}}$\n\\\\[0.2cm]\nThe program\n\\href{https://github.com/karlstroetmann/Logic/blob/master/Python/Poker.ipynb}{Poker.iypnb}\nshown in Figure \\ref{fig:poker-triple.py} performs this computation.  We proceed to discuss this\nprogram line by line.\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.0cm,\n                xrightmargin  = 0.0cm,\n              ]{python3}\n    Values = { \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\", \"A\" } \n    Suits  = { \"c\", \"h\", \"d\", \"s\" }\n    Deck   = { (v, s) for v in Values for s in Suits }\n    Hole   = { (\"3\", \"c\"), (\"3\", \"s\") }\n    Rest   = Deck - Hole\n    Flops  = { (k1, k2, k3) for k1 in Rest for k2 in Rest for k3 in Rest \n                            if  len({ k1, k2, k3 }) == 3 \n             }\n    Trips  = { f for f in Flops if (\"3\", \"d\") in f or (\"3\", \"h\") in f }\n    print(len(Trips) / len(Flops))\n\\end{minted}\n\\vspace*{-0.3cm}\n\\caption{Computing a probability in poker.}\n\\label{fig:poker-triple.py}\n\\end{figure}\n\n\\begin{enumerate}\n\\item In line 1 the set \\texttt{Values} is defined to be the set of all possible values that a card\n      can take.  In defining this set we have made use of the following abbreviations:\n      \\begin{enumerate}\n      \\item ``\\texttt{T}'' is short for ``\\blue{Ten}'',\n      \\item ``\\texttt{J}'' is short for ``\\blue{Jack}'',\n      \\item ``\\texttt{Q}'' is short for ``\\blue{Queen}'',\n      \\item ``\\texttt{K}'' is short for ``\\blue{King}'', and\n      \\item ``\\texttt{A}'' is short for ``\\blue{Ace}''.\n      \\end{enumerate}\n\\item In line 2 the set \\texttt{Suits} represents the possible suits of a card.  Here, we have used\n      the following abbreviations:\n      \\begin{enumerate}\n      \\item ``\\texttt{c}'' is short for $\\club$ (\\underline{c}lub), \n      \\item ``\\texttt{h}'' is short for \\mbox{\\color{red}{$\\heart$}} (\\underline{h}earts), \n      \\item ``\\texttt{d}'' is short for \\mbox{\\color{red}{$\\diamondsuit$}} (\\underline{d}iamonds), and \n      \\item ``\\texttt{s}'' is short for $\\spade$ (\\underline{s}pades). \n      \\end{enumerate} \n\\item Line 3 defines the set of all cards.  This set is stored as the variable \\texttt{Deck}.  Every\n      card is represented as a pair of the form $(v,s)$. Here, $v$ is the value of the card, while $s$ is its suit.\n\\item Line 4 defines the set \\texttt{Hole}.  This set represents the two cards that have been given to our player.\n\\item The remaining cards are defined as the variable  \\texttt{Rest} in line 5.\n\\item Line 6 computes the set of all possible flops.  Since the order of the cards in the flop does\n      not matter, we use sets to represent these flops.  However, we have to take care that the flop\n      does contain three \\colorbox{amethyst}{different} cards.  Hence, we have to ensure that the three\n      cards \\texttt{k1}, \\texttt{k2}, and \\texttt{k3} that make up the flop satisfy the inequalities \n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\mathtt{k1} \\not= \\mathtt{k2}$, \\quad $\\mathtt{k1} \\not= \\mathtt{k3}$,  \\quad and \\quad $\\mathtt{k2} \\not= \\mathtt{k3}$.\n      \\\\[0.2cm]\n      These inequalities are satisfied if and only if the set \n      $\\{ \\mathtt{k1}, \\mathtt{k2}, \\mathtt{k3} \\}$ contains exactly three elements.  Hence, when\n      choosing \\texttt{k1}, \\texttt{k2}, and \\texttt{k3} we have to make sure that the condition\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\texttt{len}\\bigl({\\{ \\mathtt{k1}, \\mathtt{k2}, \\mathtt{k3} \\} \\;\\mathtt{==}\\; 3 }\\bigr)$\n      \\\\[0.2cm]\n      holds.\n\\item Line 9 computes the subset \\texttt{Trips} of those flops that contain at least one card with a value of 3.\n      As the 3 of clubs and the 3 of spades have already been dealt to our player, the only cards\n      with value 3 that are left in the deck are the 3 of diamonds and the 3 of hearts.  Therefore, we are looking for\n      those flops that contain one of these two cards.\n\\item Finally, the probability for obtaining another card with a value of 3 in the flop is computed as\n      the ratio of the number of flops containing a card with a value of 3 to the number of all possible flops.\n\\end{enumerate}\nWhen we run the program we see that the probability of improving a \\blue{pocket pair} on the flop to \\blue{trips} or better\nis about  $11.8\\%$.  \n\n\\remarkEng\nThe method to compute probabilities that has been sketched above only works if the sets that have to\nbe computed are small enough to be retained in memory.  If this condition is\nnot satisfied we can use the \\href{https://en.wikipedia.org/wiki/Monte_Carlo_method}{\\emph{Monte Carlo method}} \n\\index{Monte Carlo method} \nto compute the probabilities instead.  This method will be discussed in the lecture on \n\\href{https://github.com/karlstroetmann/Algorithms/blob/master/Lecture-Notes/algorithms.pdf}{algorithms}.\n\n\n\\section{Finding a Path in a Graph}\nWe will now discuss the problem of finding a \\blue{path} \\index{path} in a\n\\href{https://en.wikipedia.org/wiki/Directed_graph}{directed graph}. \n\\index{directed graph}\nAbstractly, a \\emph{directed graph} consists of \\blue{vertices} and \\blue{edges} that connect these vertices.  In an application, the\nvertices could be towns and villages, while the edges would be interpreted as one-way streets connecting these\nvillages.  To simplify matters, let us assume for now that the vertices are given as natural numbers.  As the\nedges represent connections between vertices,  the edges are represented as pairs of natural numbers.  Then,\nthe graph can be represented as the set of its edges, as the set of vertices is implicitly given once the edges\nare known.  To make things concrete, let us consider an example.  In this case, the set of edges is called\n\\texttt{R} and is defined as follows:  \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\texttt{R}\\; \\mathtt{=}\\; \\bigl\\{ \\pair(1,2), \\pair(2,3), \\pair(1,3), \\pair(2,4), \\pair(4,5) \\bigr\\}$.\n\\\\[0.2cm]\nIn this graph, the set of vertices is given as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{ 1, 2, 3, 4, 5 \\}$.\n\\\\[0.2cm]\nThis graph is shown in Figure \\ref{fig:graph0} on page \\pageref{fig:graph0}.  You should note that the\nconnections between vertices that are given in this graph are \\blue{unidirectional}:  While there is a connection from\nvertex $1$ to vertex $2$, there is no connection from vertex $2$ to vertex $1$.\n\n \n\\begin{figure}[!ht]\n  \\centering\n  \\epsfig{file=Figures/graph0,scale=0.6}\n\n  \\caption{A simple graph.}\n  \\label{fig:graph0}\n\\end{figure}\n\n\n\n\\noindent\nThe graph given by the relation \\texttt{R} contains only the direct connections of vertices.  For example, in\nthe graph shown in Figure \\ref{fig:graph0}, there is a direct connection from vertex $1$ to vertex $2$ and\nanother direct connection from vertex $2$ to vertex $4$.  Intuitively, vertex $4$ is reachable from vertex $1$,\nsince from vertex $1$ we can first reach vertex $2$ and from vertex $2$ we can then reach vertex $4$.  However,\nthere is is no direct connection between the vertices $1$ and $4$.  To make this more formal, define\na \\blue{path} of a graph $R$ as a list of vertices\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$[x_1, x_2, \\cdots, x_n]$ \\quad such that \\quad $\\pair(x_i,x_{i+1}) \\in R$ \\quad for all $i=1,\\cdots,n-1$.\n\\\\[0.2cm]\nIn this case, the path $[x_1, x_2, \\cdots, x_n]$ is written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x_1 \\mapsto x_2 \\mapsto \\cdots \\mapsto x_n$\n\\\\[0.2cm]\nand has the \\blue{length} $n-1$, since there are $n-1$ direct connections of the form $\\pair(x_i,x_{i+1})$ that\nmake up this path.\nTo put it differently,  the length of a path\n$[x_1,x_2,\\cdots,x_n]$ is defined as the number of edges connecting the vertices and not as the\nnumber of vertices appearing on the path.\n\nFurthermore,  two vertices $a$ and $b$ of a graph are said to be \\blue{connected} \\index{connected} iff there exists a path\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$[x_1,\\cdots,x_n]$ \\quad such that \\quad $a = x_1$ \\quad and \\quad $b = x_n$.\n\\\\[0.2cm]\nThe goal of this section is to develop an algorithm that checks whether two vertices $a$ and $b$ are connected.\nFurthermore, we want to be able to compute the corresponding path connecting the vertices $a$ and $b$.\n\n\\subsection{Breadth-First Search}\nWe are now ready to present \\blue{breadth-first search} \\index{breadth-first search}.  This is an algorithm\nfor finding a path in a given graph.  Figure \\ref{fig:Breadth-First-Search.ipynb} on page\n\\pageref{fig:Breadth-First-Search.ipynb} shows the function \\texttt{search}.  This function uses three\narguments:\n\\begin{enumerate}[(a)]\n\\item $R$ is a binary relation that is interpreted as a directed graph.\n\\item \\texttt{start} and \\texttt{goal} are nodes in this graph.\n\\end{enumerate}\nThe function search returns a path leading from \\texttt{start} to  \\texttt{goal} if such a path exists.\nOtherwise it returns \\texttt{None}.  We discuss the implementation of the function \\texttt{search} line by line.\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}\n    def search(R, start, goal):\n        Paths   = { (start,) }\n        Visited = { start }\n        while True:\n            NewPaths = set()\n            for Path in Paths:\n                for (y, z) in R:\n                    if Path[-1] == y and z not in Visited:\n                        LongerPath = Path + (z,)\n                        if z == goal:\n                            return LongerPath\n                        NewPaths.add(LongerPath)\n                        Visited .add(z)\n            if NewPaths == set():\n                return\n            Paths = NewPaths\n\\end{minted} \n\\vspace*{-0.3cm}\n\\caption{Breadth-first search.}  \\label{fig:Breadth-First-Search.ipynb}\n\\end{figure} %\\$\n\n\n\\begin{enumerate}\n\\item In line 2 we initialize the variable \\texttt{Paths} to contain the path that starts in the node\n      \\texttt{start} and has the length $0$.  After the $n$th iteration of the \\texttt{while} loop in line 4,\n      the set \\texttt{Paths} will contain all paths in the graph that start in node \\texttt{start} and have a\n      length of $n$.\n\\item In line 3 we initialize the set \\texttt{Visited} to contain the state \\texttt{start}.\n      Every time we discover a new node, it is added to the set \\texttt{Visited}.\n      The reason is that we want all the paths stored in the set \\texttt{Paths} to be shortest paths.\n      Therefore, we only add a new path to this set if the end point of this path has not yet been visited.\n\\item Before the $n$th iteration of the \\texttt{while} loop in line 4 all paths stored in\n      the set \\texttt{Paths} have a length of $n-1$.  The purpose of the next iteration is to extend the paths to\n      a length of $n$.  Those paths that can not be extended are discarded.     \n\\item \\texttt{NewPaths} is the set of those paths that have been extended.  In the $n$th iteration,\n      all paths in this set will have a length of $n$.\n\\item In line 6 to 8 we iterate over all paths discovered so far that end in the node $y$, where $\\langle y, z\\rangle$\n      is a pair in the relation $R$ and the node $z$ has not yet been visited.\n\\item If we find such a path \\texttt{Path} we extend it by appending the node $z$.\n\\item If $z$ is equal to \\texttt{goal} we have found a path from \\texttt{start} to \\texttt{goal} and return\n      this path.\n\\item Otherwise, this new path is added to the set \\texttt{NewPaths} and the node $z$ is added to the set\n      \\texttt{Visited} to record the fact that we now have found a path leading to $z$.\n\\item If we do not find any new path in a given iteration, then there is no path from \\texttt{start} to\n      \\texttt{goal} and the function returns.\n\\item Otherwise, \\texttt{Paths} is set to \\texttt{NewPaths} and the loop repeats.\n\\end{enumerate}\n\n\n\\subsection{The Wolf, the Goat, and the Cabbage}\n\\index{wolf, goat, and cabbage}\nNext, we present an application of the theory developed so far.  We solve a problem that has puzzled\nthe greatest agricultural economists for centuries.  The puzzle we want to solve is known as the \n\\href{http://jeux.lulu.pagesperso-orange.fr/html/anglais/loupChe/loupChe1.htm}{wolf-goat-cabbage puzzle}:  \n\\vspace*{0.3cm}\n\n\\begin{minipage}[c]{16cm}\n{\\sl\nAn agricultural economist has to sell a wolf, a goat, and a cabbage on a market place.  In order to\nreach the market place, she has to cross a river.  The boat that she can use is so small that it can\nonly accommodate either the goat, the wolf, or the cabbage in addition to the agricultural economist.\nNow if the agricultural economist leaves the wolf alone with the goat, the wolf will eat the goat.\nIf, instead, the agricultural economist leaves the goat with the cabbage, the goat will eat the cabbage.\nIs it possible for the agricultural economist to develop a schedule that allows her to cross the river\nwithout either the goat or the cabbage being eaten?\n}\n\\end{minipage}\n\\vspace*{0.3cm}\n\n\\noindent\nIn order to compute a schedule, we first have to model the problem.  The various \\blue{states} of the problem will\nbe regarded as \\blue{vertices} of a graph and this graph will be represented as a binary relation.\nTo this end we define the set\n\\begin{verbatim}\n  All = {'farmer', 'wolf, 'goat', 'cabbage'}.\n\\end{verbatim}\nEvery node will be represented as a subset \\texttt{S} of the set \\texttt{All}.  The idea is that the set \\texttt{S}\nspecifies those objects that are on the left side of the river.  We assume that initially the farmer and his goods\nare on the left side of the river. \nTherefore, the set of all states that are \\blue{allowed} according to the specification of the problem can be defined\nas the set \n\\begin{verbatim}\n  States = { S for S in power(All) if not problem(S) and not problem(All-S) }\n\\end{verbatim}\nHere, we have used the procedure \\texttt{problem} to check whether a given set \\texttt{S} has a problem,\nwhere a problem is any situation where either the goat eats the cabbage or the wolf eats the goat.\nNote that since \\texttt{S} is the set of objects on the left side, the expression $\\texttt{All-S}$\ncomputes the set of objects on the right side of the river.\n\nFormally, a set \\texttt{S} of objects has a problem if both of the following conditions\nare satisfied:\n\\begin{enumerate}\n\\item The farmer is not an element of \\texttt{S} and\n\\item either \\texttt{S} contains both the goat and the cabbage or \\texttt{S} contains both the wolf and the goat.\n\\end{enumerate}\nTherefore, we can implement the function \\texttt{problem} as follows:\n\\begin{verbatim}\n  def problem(S):\n      return ('farmer' not in S) and             \\\n             (('goat' in S and 'cabbage' in S) or   # goat eats cabbage\n              ('wolf' in S and 'goat'    in S)   )  # wolf eats goat\n\\end{verbatim}\nNote that we have to use a \\blue{line continuation backslash} ``\\texttt{$\\backslash$}''\nat the end of the first line of the return statement.\nWe do not need a continuation backslash at the end of the second line of the return statement since\nthe opening parenthesis at the beginning of the second line has not yet been closed when the second line\nfinishes and therefore \\textsl{Python} is able to figure out that the expression defined in this line is\ncontinued in the third line.\n\nWe proceed to compute the relation \\texttt{R} that contains all possible transitions between\ndifferent states.  We will compute \\texttt{R} using the formula:\n\\\\[0.2cm]\n\\hspace*{0.75cm}\n\\texttt{R = R1 + R2;}\n\\\\[0.2cm]\nHere \\texttt{R1} describes the transitions that result from the farmer crossing the river from left\nto right, while \\texttt{R2} describes the transitions that result from the farmer crossing the river\nfrom right to left.  We can define the relation \\texttt{R1} as follows:\n\\begin{verbatim}\n  R1 = { (S, S-B) for S in States \n                  for B in power(S)\n                  if S-B in States and 'farmer' in B and len(B) <= 2\n       }\n\\end{verbatim}\nLet us explain this definition in detail:\n\\begin{enumerate}\n\\item Initially, \\texttt{S} is the set of objects on the left side of the river.  Hence, \\texttt{S}\n      is an element of the set of all states that we have defined as \\texttt{States}.\n\\item \\texttt{B} is the set of objects that are put into the boat and that do cross the river.  Of\n      course, for an object to go into the boat is has to be on the left side of the river to begin\n      with.  Therefore, \\texttt{B} is a subset of \\texttt{S} and hence \\texttt{B} is an element of the power set\n      of \\texttt{S}. \n\\item Therefore  \\texttt{S-B} is the set of objects that are left on the left side of the river after\n      the boat has crossed.  Of course, the new state \\texttt{S-B} has to be a state that does not\n      have a problem.  Therefore, we check that the set \\texttt{S-B} is an element of the set \\texttt{States}.\n\\item Furthermore, the farmer has to be inside the boat.  This explains the condition \n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      \\texttt{\\symbol{39}farmer\\symbol{39} in B}.\n\\item Finally, the boat can only have two passengers.  Therefore, we have added the condition\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      \\texttt{len(B) <= 2}.\n\\end{enumerate}\nNext, we have to define the relation \\texttt{R2}.  However, as crossing the river from right to left\nis just the reverse of crossing the river from left to right, \\texttt{R2} is just the \\blue{inverse} of\n\\texttt{R1}.   Hence we define:\n\\begin{verbatim}\n  R2 = { (S2, S1) for (S1, S2) in R1 }.\n\\end{verbatim}\nNext, the relation \\texttt{R} is the union of \\texttt{R1} and \\texttt{R2}:\n\\begin{verbatim}\n  R = R1 | R2.\n\\end{verbatim}\nFinally, the start state has all objects on the left side.  Therefore, we have\n\\begin{verbatim}\n  start = All.\n\\end{verbatim}\nIn the end, all objects have to be on the right side of the river.  That means that nothing is left\non the left side.  Therefore, we define\n\\begin{verbatim}\n  goal = {}.\n\\end{verbatim}\n\n\n\\begin{figure}[h]\n  \\centering\n\n  \\epsfig{file=Figures/wolf-goat-cabbage, scale=0.4}\n\n  \\caption{The relation \\texttt{R} shown as a directed graph.}\n  \\label{fig:wolf-goat-cabbage.pdf}\n\\end{figure}\n\n\n\n\\noindent\nFigure \\ref{fig:wolf-goat-cabbage.pdf} on page \\pageref{fig:wolf-goat-cabbage.pdf} displays the relation $R$ graphically.\nFigure \\ref{fig:wolf-ziege} on page \\pageref{fig:wolf-ziege} shows the program\n\\href{https://github.com/karlstroetmann/Logic/blob/master/Python/wolf-goat-cabbage.py}{\\texttt{wolf-goat-cabbage.py}}\nthat combines the statements shown so far.  The solution computed by this program is shown in Figure\n \\ref{fig:wolf-ziege-solution}.\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.3cm,\n                xrightmargin  = 0.3cm,\n              ]{python3}\n    def problem(S):\n        return ('farmer' not in S) and             \\\n               (('goat' in S and 'cabbage' in S) or   # goat eats cabbage\n                ('wolf' in S and 'goat'    in S)   )  # wolf eats goat\n    \n    All   = frozenset({ 'farmer', 'wolf', 'goat', 'cabbage' })\n    R1    = { (S, S - B) for S in States for B in power(S)\n                         if S - B in States and 'farmer' in B and len(B) <= 2\n            }\n    R2    = { (S2, S1) for (S1, S2) in R1 }\n    R     = R1 | R2\n    start = All\n    goal  = frozenset()\n    Path  = findPath(start, goal, R)\n\\end{minted} \n\\vspace*{-0.3cm}\n\\caption{Solving the wolf-goat-cabbage problem.}  \n\\label{fig:wolf-ziege}\n\\end{figure}\n\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}\n    {'cabbage', 'farmer', 'goat', 'wolf'}                                 {}\n                             >>>> {'farmer', 'goat'} >>>> \n    {'cabbage', 'wolf'}                                   {'farmer', 'goat'}\n                             <<<< {'farmer'} <<<< \n    {'cabbage', 'farmer', 'wolf'}                                   {'goat'}\n                             >>>> {'farmer', 'wolf'} >>>> \n    {'cabbage'}                                   {'farmer', 'goat', 'wolf'}\n                             <<<< {'farmer', 'goat'} <<<< \n    {'cabbage', 'farmer', 'goat'}                                   {'wolf'}\n                             >>>> {'cabbage', 'farmer'} >>>> \n    {'goat'}                                   {'cabbage', 'farmer', 'wolf'}\n                             <<<< {'farmer'} <<<< \n    {'farmer', 'goat'}                                   {'cabbage', 'wolf'}\n                             >>>> {'farmer', 'goat'} >>>> \n    {}                                 {'cabbage', 'farmer', 'goat', 'wolf'}\n\\end{minted} \n\\vspace*{-0.3cm}\n\\caption{A schedule for the agricultural economist.}  \n\\label{fig:wolf-ziege-solution}\n\\end{figure}\n\\pagebreak\n\\vspace*{\\fill}\n\n\n\n\\section{Symbolic Differentiation}\n\\index{symbolic differentiation}\nIn this section we will develop a program that reads an arithmetic expression like the string\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{\\symbol{34}x * exp(x)\\symbol{34}},\n\\\\[0.2cm]\ninterprets this string as describing the real valued function \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x \\mapsto x \\cdot \\exp(x)$, \n\\\\[0.2cm]\nand then takes the derivative of this function with respect to the variable $x$.  In order to specify the input\nof this program more clearly, we first define the notion of an \\blue{arithmetic expression} inductively.\n\\begin{enumerate}[(a)]\n\\item Every number $c \\in \\mathbb{R}$ is an arithmetic expression.\n\\item Every variable $v$ is an arithmetic expression.\n\\item If $s$ and $t$ are arithmetic expressions, then\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $s + t$, \\quad $s - t$, \\quad $s * t$, \\quad $s / t$, \\quad and \\quad $s \\,\\mathtt{**}\\, t$\n      \\\\[0.2cm]\n      are arithmetic expressions.  Here $s \\,\\mathtt{**}\\, t$ is interpreted as $s^t$.\n      \n\\item If $e$ is an arithmetic expression, then both\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\exp(e)$ \\quad and \\quad $\\ln(e)$\n      \\\\[0.2cm]\n      are arithmetic expressions.\n\\end{enumerate}\nWe want do implement a function \\texttt{diff} that takes two arguments:\n\\begin{enumerate}\n\\item The first argument \\texttt{expr} is an arithmetic expression.\n\\item The second argument \\texttt{var} is the name of a variable.\n\\end{enumerate}\nThe function call \\texttt{diff(expr, var)} will then compute the derivative of \\texttt{expr} with respect to the variable \\texttt{var}.  For example, the function call \\texttt{diff(\\symbol{34}x*exp(x)\\symbol{34}, \\symbol{34}x\\symbol{34})} will compute the output\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\symbol{34}\\texttt{1*exp(x) + x*exp(x)}\\symbol{34}\n\\\\[0.2cm]\nbecause we have:\n$$ \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} \\bigl( x \\cdot \\mathrm{e}^x \\bigr) = 1 \\cdot x + x \\cdot \\mathrm{e}^x $$\nIt would be very tedious to \\blue{represent} arithmetic expressions as strings.  Instead, we will represent\narithmetic expressions as \\blue{nested tuples}.  \\index{nested tuple}\nThe notion of a \\emph{nested tuple} is defined inductively:\n\\begin{itemize}\n\\item $\\langle x_1, x_2, \\cdots, x_n \\rangle$ is a nested tuple if each of the components $x_i$ is either a\n      number, a string, or is itself a nested tuple.\n\\end{itemize}\nFor example, the arithmetic expression ``\\texttt{x*exp(x)}'' is represented as the nested tuple\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\bigl\\langle\\texttt{\\symbol{34}}*\\texttt{\\symbol{34}}, \\texttt{\\symbol{34}}x\\texttt{\\symbol{34}}, \\langle \\texttt{\\symbol{34}}\\mathtt{exp}\\texttt{\\symbol{34}}, \\texttt{\\symbol{34}}x\\texttt{\\symbol{34}} \\rangle\\bigr\\rangle$.\n\\\\[0.2cm]\nIn order to be able to convert string into nested tuples, we need a \\blue{parser}.\n\\index{parser}\n  A parser is a program that\ntakes a string as input and transforms this string into a nested tuple, which is then returned as a result.\nI have implemented a parser in the file ``\\texttt{exprParser.py}''.  The details of the implementation of this\nparser will be discussed in the lecture on\n\\href{https://github.com/karlstroetmann/Algorithms/blob/master/Lecture-Notes/algorithms.pdf}{algorithms} in the\nsecond semester..\n\n\\noindent\nThe function \\texttt{diff} that is shown in Figure \\ref{fig:diff.py} on page \\pageref{fig:diff.py} is part\nof the program\n\\href{https://github.com/karlstroetmann/Logic/blob/master/Python/Symbolic-Differentiation.ipynb}{\\texttt{Symbolic-Differentiation.ipynb}}.\nThis function is called with one argument:\nThe argument \\texttt{e} is an arithmetic expression.\nThe function \\texttt{diff} interprets its argument \\texttt{e} as a function of the variable\n\\texttt{x}.  We take the \\href{https://en.wikipedia.org/wiki/Derivative}{derivative} of this\nfunction with respect to the variable \\texttt{x}.  For example, in order to compute the derivative of\nthe function\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x \\mapsto x^x$,\n\\\\[0.2cm]\nwe can call the function  \\texttt{diff} as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{diff(\\symbol{34}x ** x\\symbol{34})}.\n\\\\[0.2cm]\nLet us now discuss the implementation of the function \\texttt{diff} in more detail.  \n\\begin{enumerate}\n\\item The lines 3 - 6 implement the rule: \n      $$\\frac{\\mathrm{d}\\;}{\\mathrm{d}x}\\bigl(f(x) + g(x)\\bigr) = \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} f(x) + \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} g(x)$$\n\\item Line 7 - 10 implement the rule:\n      $$\\frac{\\mathrm{d}\\;}{\\mathrm{d}x}\\bigl(f(x) - g(x)\\bigr) = \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} f(x) - \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} g(x)$$      \n\\item Line 11 - 14 deals with the case where \\texttt{e} is a product.  The \n      \\href{https://en.wikipedia.org/wiki/Product\\_rule}{product rule} is      \n      $$ \\frac{\\mathrm{d}\\;}{\\mathrm{d}x}\\bigl(f(x) \\cdot g(x)\\bigr) = \\left(\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} f(x)\\right)\\cdot g(x) + f(x) \\cdot \\left(\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} g(x)\\right)\n      $$\n\\item Line 15 - 17 deals with the case where \\texttt{e} is a quotient.  The\n      \\href{https://en.wikipedia.org/wiki/Quotient\\_rule}{quotient rule} is\n      $$ \\frac{\\mathrm{d}\\;}{\\mathrm{d}x}\\left(\\frac{f(x)}{g(x)}\\right) = \n         \\frac{\\displaystyle\\left(\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} f(x)\\right)\\cdot g(x) - \n         f(x) \\cdot \\left(\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} g(x)\\right)}{g(x) \\cdot g(x)}\n      $$      \n\\item Line 19 - 21 deals with the case where \\texttt{e} is a power.  Now in order to take the derivative of an\n      expression of the form\n      $$  f(x)^{g(x)} $$\n      we first need to rewrite this expression using the following trick:\n      $$ f(x)^{g(x)} = \\exp\\bigl(\\ln\\bigl(f(x)^{g(x)}\\bigr)\\bigr) = \\exp\\bigl(g(x) \\cdot \\ln(f(x))\\bigr) $$\n      Then, we can recursively call \\texttt{diff} for this expression.  This works, because the function\n      \\texttt{diff} can deal with both the exponential function $x \\mapsto \\exp(x)$ and with the natural\n      logarithm $x \\mapsto \\ln(x)$.  This rewriting is done in line 21.      \n\\item Line 22-25 deals with the case where \\texttt{e} has the form \n      $$\\ln\\bigl(f(x)\\bigr)$$  \n      In order to take the derivative of this expression, we first need to know the derivative of the natural\n      logarithm.  This derivative is given as     \n      $$ \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} \\ln(x) = \\frac{1}{x}$$\n      Then, using the \\href{https://en.wikipedia.org/wiki/Chain\\_rule}{chain rule} we have that\n      $$ \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} \\ln\\bigl(f(x)\\bigr) = \\frac{\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} f(x)}{f(x)}$$     \n\\item Line 26 - 29 deals with the case where \\texttt{e} has the form $\\exp\\bigl(f(x)\\bigr)$.  \n      In order to take the derivative of this expression, we first need to know the derivative of the \n      \\href{https://en.wikipedia.org/wiki/Exponential\\_function}{exponential function}.  \n      This derivative is given as \n      $$ \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} \\exp(x) = \\exp(x)$$    \n      Then, using the \\href{https://en.wikipedia.org/wiki/Chain\\_rule}{chain rule} we have that\n      $$\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} \\exp\\bigl(f(x)\\bigr) = \\left(\\frac{\\mathrm{d}\\;}{\\mathrm{d}x} f(x)\\right) \\cdot \\exp\\bigl(f(x)\\bigr) $$\n\\item Line 30-31 deals with the case where \\texttt{e} is a variable and happens to be the same variable as\n      \\texttt{x}.  This is checked using the condition    \n      \\texttt{e == x}.  As we have\n      $$\\frac{\\mathrm{d}x}{\\mathrm{d}x} = 1,$$\n      the function \\texttt{diff} returns \\texttt{1} in this case.  \n\\item Otherwise, the expression is assumed to be a constant and hence we return 0.\n\\end{enumerate}\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                firstnumber   = 1,\n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}\n    def diff(e):\n        'differentiate the expressions e with respect to the variable x'\n        if e[0] == '+':\n            f , g  = e[1:]\n            fs, gs = diff(f), diff(g)\n            return ('+', fs, gs)\n        if e[0] == '-':\n            f , g  = e[1:]\n            fs, gs = diff(f), diff(g)\n            return ('-', fs, gs)\n        if e[0] == '*':\n            f , g  = e[1:]\n            fs, gs = diff(f), diff(g)\n            return ('+', ('*', fs, g), ('*', f, gs))\n        if e[0] == '/':\n            f , g  = e[1:]\n            fs, gs = diff(f), diff(g)\n            return ('/', ('-', ('*', fs, g), ('*', f, gs)), ('*', g, g))\n        if e[0] == '**':\n            f , g  = e[1:]\n            return diff(('exp', ('*', g, ('ln', f))))\n        if e[0] == 'ln':\n            f  = e[1]\n            fs = diff(f) \n            return ('/', fs, f)\n        if e[0] == 'exp':\n            f  = e[1]\n            fs = diff(f) \n            return ('*', fs, e)\n        if e == 'x':\n            return '1'\n        return 0                  \n\\end{minted}\n\\vspace*{-0.3cm}\n\\caption{A function for symbolic differentiation}\n\\label{fig:diff.py}\n\\end{figure}\n\n\nIn order to test this function we can implement a function \\texttt{test} as shown in Figure \\ref{fig:test-diff.py}.\nThen the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{diff(\\symbol{34}x ** x\\symbol{34})}\n\\\\[0.2cm]\nyields the result:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\nd/dx x ** x = (1*ln(x) + x*1/x)*exp(x*ln(x))\n\\\\[0.2cm]\nThis shows that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds \\frac{\\mathrm{d}\\;}{\\mathrm{d}x} x^x = \\bigl(\\ln(x) + 1\\bigr) \\cdot \\exp\\bigl(x \\cdot \\ln(x)\\bigr) =\n \\bigl(\\ln(x) + 1\\bigr) \\cdot x^x\n$.\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                firstnumber   = 1,\n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}\n    import exprParser as ep\n\n    def test(s):\n        t = ep.ExprParser(s).parse()\n        d = diff(t)\n        print(f'd/dx {s} = {ep.toString(d)}')\n\\end{minted}\n\\vspace*{-0.3cm}\n\\caption{Testing symbolic differentiation.}\n\\label{fig:test-diff.py}\n\\end{figure}\n\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"logic\"\n%%% End:\n", "meta": {"hexsha": "8595a2bdf797edeefb71359ab665edf99f83934a", "size": 40537, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-Notes/case-studies.tex", "max_stars_repo_name": "adroi3/Logic", "max_stars_repo_head_hexsha": "42df8371619db3195191f7834f3c66c3722ad8ce", "max_stars_repo_licenses": ["MIT"], "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/case-studies.tex", "max_issues_repo_name": "adroi3/Logic", "max_issues_repo_head_hexsha": "42df8371619db3195191f7834f3c66c3722ad8ce", "max_issues_repo_licenses": ["MIT"], "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/case-studies.tex", "max_forks_repo_name": "adroi3/Logic", "max_forks_repo_head_hexsha": "42df8371619db3195191f7834f3c66c3722ad8ce", "max_forks_repo_licenses": ["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.8094688222, "max_line_length": 262, "alphanum_fraction": 0.6407232898, "num_tokens": 12449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.6868080546245339}}
{"text": "\\section{``Cartesian closed'', Hausdorff, Basepoints}\\label{basepoints}\nPushouts are colimits, so the quotient space $X/A=X\\cup_A \\ast$ is an example of a colimit.\nLet $Y$ be a topological space, and consider the functor $Y\\times -:\\Top\\to\\Top$.\nApplying this to the pushout square, we find that $(Y\\times X)\\cup_{Y\\times A}\\ast\\simeq (Y\\times X)/(Y\\times A)$.\nAs we discussed in \\S \\ref{CGWHspaces}, this product is \\emph{not} the same as $Y\\times (X/A)$!\nThere is a bijective map $Y\\times X/Y\\times A\\to Y\\times(X/A)$,\nbut it is not, in general, a homeomorphism.\nFrom a categorical point of view (see Theorem \\ref{adjointslimits}), the reason for this failure \nstems from $Y\\times -$ not being a left adjoint.\n\nThe discussion in \\S \\ref{mappingspaces} implies that, when working with $k$-spaces,\nthat functor is indeed a left adjoint\n(in fancy language, the category $k\\Top$ is Cartesian closed),\nwhich means that --- in $k\\Top$ --- there is a homeomorphism $Y\\times X/Y\\times A\\to Y\\times(X/A)$.\nThis addresses the issues raised in \\S \\ref{CGWHspaces}.\nThe ancients had come up with a good definition of a topology ---\nbut $k$-spaces are better!\nSometimes, though, we can be greedy and ask for even more:\nfor instance, we can demand that points be closed.\nThis leads to a further refinement of $k$-spaces. \n\n\\todo[inline]{I don't like point-set topology, so I'll return to editing this lecture at the end.}\n\\subsection{``Hausdorff''}\n\\begin{definition}\n    A space is ``weakly Hausdorff'' if the image of every map $K\\to X$ from a compact Hausdorff space $K$ is closed.\n\\end{definition}\nAnother way to say this is that the map itself if closed. Clearly Hausdorff implies weakly Hausdorff. Another thing this means is that every point in $X$ is closed (eg $K=\\ast$). \n\\begin{prop}\n    Let $X$ be a $k$-space.\n    \\begin{enumerate}\n\t\\item $X$ is weakly Hausdorff iff $\\Delta:X\\to X\\times^k X$ is closed. In algebraic geometry such a condition is called separated.\n\t\\item Let $R\\subseteq X\\times X$ be an equivalence relation. If $R$ is closed, then $X/R$ is weakly Hausdorff.\n    \\end{enumerate}\n\\end{prop}\n\\begin{definition}\n    A space is compactly generated if it's a weakly Hausdorff $k$-space. The category of such spaces is called $\\CG$.\n\\end{definition}\nWe have a pair of adjoint functors $(i,k):\\Top\\to k\\Top$. It's possible to define a functor $k\\Top\\to \\CG$ given by $X\\mapsto X/\\bigcap\\text{all closed equivalence relations}$. It is easy to check that if $Z$ is weakly Hausdorff, then $Z^X$ is weakly Hausdorff (where $X$ is a $k$-space). What this implies is that $\\CG$ is also Cartesian closed!\n\nI'm getting a little tired of point set stuff. Let's start talking about homotopy and all that stuff today for a bit. You know what a homotopy is. I will not worry about point-set topology anymore. So when I say $\\Top$, I probably mean $\\CG$. A homotopy between $f,g:X\\to Y$ is a map $h:I\\times X\\to Y$ such that the following diagram commutes:\n\\begin{equation*}\n    \\xymatrix{\n\tX\\ar[dr]_{i_0}\\ar[drr]^f & &\\\\\n\t& I\\times X\\ar[r]^h & Y\\\\\n\tX\\ar[ur]^{i_1}\\ar[urr]_g & &\n    }\n\\end{equation*}\nWe write $f\\sim g$. We define $[X,Y]=\\Top(X,Y)/\\sim$. Well, a map $I\\times X\\to Y$ is the same as a map $X\\to Y^I$ but also $I\\to Y^X$. The latter is my favorite! It's a path of maps from $f$ to $g$. So $[X,Y]=\\pi_0Y^X$.\n\nTo talk about higher homotopy groups and induct etc. we need to talk about basepoints.\n\\subsection{Basepoints}\nA pointed space is $(X,\\ast)$ with $\\ast\\in X$. This gives a category $\\Top_\\ast$ where the morphisms respect the basepoint. This has products because $(X,\\ast)\\times (Y,\\ast)=(X\\times Y,(\\ast,\\ast))$. How about coproducts? It has coproducts as well. This is the wedge product, defined as $X\\sqcup Y/\\ast_X\\sim \\ast_Y=:X\\vee Y$. This is \\verb|\\vee|, not \\verb|\\wedge|. Is this category also Cartesian closed?\n\nDefine the space of pointed maps $Z^X_\\ast\\subseteq Z^X$ topologized as a subspace. Does the functor $Z\\mapsto Z^X_\\ast$ have a left adjoint? Well $\\Top(W,Z^X)=\\Top(X\\times W,Z)$. What about $\\Top(W,Z^X_\\ast)$? This is $\\{f:X\\times W\\to Z:f(\\ast,w)=\\ast\\forall w\\in W\\}$. That's not quite what I wanted either! Thus $\\Top_\\ast(W,Z^X_\\ast)=\\{f:X\\times W\\to Z:f(\\ast,w)=\\ast=f(x,\\ast)\\forall x\\in X, w\\in W\\}$. These send both ``axes'' to the basepoint. Thus, $\\Top_\\ast(W,Z^X_\\ast)=\\Top_\\ast(X\\wedge W,Z)$ where $X\\wedge W=X\\times W/X\\vee W$ because $X\\vee W$ are the ``axes''.\n\nSo $\\Top_\\ast$ is not Cartesian closed, but admits something called the smash product\\footnote{Remark by Sanath: this is like the tensor product.}. What properties would you like? Here's a good property: $(X\\wedge Y)\\wedge Z$ and $X\\wedge(Y\\wedge Z)$ are bijective in pointed spaces. If you work in $k\\Top$ or $\\CG$, then they are homeomorphic! It also has a unit.\n\nOh yeah, some more things about basepoints! So there's a canonical forgetful functor $i:\\Top_\\ast\\to \\Top$. Let's see. If I have $\\Top(X,iY)=\\Top_\\ast(??,Y)$? This is $X_+=X\\sqcup \\ast$. Thus we have a left adjoint $(-)_+$. It is clear that $(X\\sqcup Y)_\\ast = X_+ \\vee Y_+$. The unit for the smash product is $\\ast_+ = S^0$.\n\nOn Friday I'll talk about fibrations and fiber bundles.\n", "meta": {"hexsha": "ba23e6e305149c904f8ac8748b5c666669c84c57", "size": 5169, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-41-basepoints.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-41-basepoints.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-41-basepoints.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": 84.737704918, "max_line_length": 576, "alphanum_fraction": 0.7067130973, "num_tokens": 1668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6868080531595171}}
{"text": "\\section{Relative homotopy groups}\n%Pset 2 has question 8; there's still one more to go. Hood has office hours today 12 -- 1 in 2-390, and I have office hours today tomorrow 4-5 in 2-478.\n\\subsection{Spheres and homotopy groups}\nThe functor $\\Omega$ (sending a space to its based loop space) admits a left adjoint.\nTo see this, recall that $\\Omega X = X^{S^1}_\\ast$, so that\n$$\\Top_\\ast(W,\\Omega X) = \\Top_\\ast(S^1\\wedge W,X).$$\n\\begin{definition}\n    The \\emph{reduced suspension} $\\Sigma W$ is $S^1\\wedge W$.\n\\end{definition}\nIf $A\\subseteq X$, then\n$$X/A\\wedge Y/B = (X\\times Y)/((A\\times Y)\\cup_{A\\times B}(X\\times B)).$$\nSince $S^1 = I/\\partial I$, this tells us that $\\Sigma X = S^1\\wedge X$ can be identified with\n$I\\times X/(\\partial I \\times X\\cup I\\times \\ast)$: in other words, we collapse the top and bottom of a cylinder to a point,\nas well as the line along a basepoint.\n\nThe same argument says that $\\Sigma^n X$ (defined inductively as $\\Sigma(\\Sigma^{n-1} X)$)\nis the left adjoint of the $n$-fold loop space functor $X\\mapsto \\Omega^n X$.\nIn other words, $\\Sigma^n X = (S^1)^{\\wedge n}\\wedge X$.\nWe claim that $S^1\\wedge S^n \\simeq S^{n+1}$.\nTo see this, note that\n$$S^1\\wedge S^n = I/\\partial I\\wedge I^n\\wedge \\partial I^n = (I\\times I^n)/(\\partial I\\times I^n\\cup I\\times \\partial I^n).$$\nThe denominator is exactly $\\partial I^{n+1}$, so $S^1\\wedge S^n\\simeq S^{n+k}$.\nIt's now easy to see that $S^k\\wedge S^n\\simeq S^{k+n}$.\n\\begin{definition}\n    The \\emph{$n$th homotopy group} of $X$ is $\\pi_n X = \\pi_0(\\Omega^n X)$.\n\\end{definition}\nThis is, as we noted in the previous section, $[S^0,\\Omega^n X]_\\ast = [S^n, X]_\\ast = [(I^n,\\partial I^n),(X,\\ast)]$.\n\n\\subsection{The homotopy category}\nDefine the \\emph{homotopy category of spaces} $\\Ho(\\Top)$ to be the category\nwhose objects are spaces, and whose hom-sets are given by taking $\\pi_0$ of the mapping space.\nTo check that this is indeed a category, we need to check that if $f_0,f_1:X\\to Y$ and $g:Y\\to Z$, then $gf_0\\simeq gf_1$ ---\nbut this is clear.\nSimilarly, we'd need to check that $f_0h\\simeq f_1h$ for any $h:W\\to X$.\nWe can also think about the homotopy category of pointed spaces (and pointed homotopies) $\\Ho(\\Top_\\ast)$; this is the category\nwe have been spending most of our time in.\nBoth $\\Ho(\\Top)$ and $\\Ho(\\Top_\\ast)$ have products and coproducts, but very few other limits or colimits.\nFrom a category-theoretic standpoint, these are absolutely terrible.\n\nLet $W$ be a pointed space.\nWe would like the assignment $X\\mapsto X^W_\\ast$ to be a homotopy functor.\nIt clearly defines a functor $\\Top_\\ast\\to\\Top_\\ast$, so this desire is equivalent to providing a dotted arrow in the\nfollowing diagram:\n\\begin{equation*}\n    \\xymatrix{\n\t\\Top_\\ast\\ar[d]\\ar[r]^{X\\mapsto X^W_\\ast} & \\Top_\\ast\\ar[d]\\\\\n\t\\Ho(\\Top_\\ast)\\ar@{-->}[r] & \\Ho(\\Top_\\ast).\n    }\n\\end{equation*}\nBefore we can prove this, we will check that a homotopy $f_0\\sim f_1:X\\to Y$ is the same as a map $I_+\\wedge X\\to Y$.\nThere is a nullhomotopy if the basepoint of $I$ is one of the endpoints, so a homotopy is the same as a map\n$I\\times X/I\\times\\ast \\to Y$. The source is just $I_+\\wedge X$, as desired.\n\nA homotopy $f_0 \\simeq f_1:X\\to Y$ begets a map $(I_+\\wedge X)^W\\to Y^W_\\ast$.\nFor the assignment $X\\mapsto X^W_\\ast$ to be a homotopy functor, we need a natural transformation $I_+\\wedge X^W_\\ast\\to Y^W_\\ast$, so this map is not quite what's necessary.\nInstead, we can attempt to construct a map $I_+\\wedge X^W_\\ast\\to (I_+\\wedge X)^W_\\ast$.\n\nWe can construct a general map $A\\wedge X^W_\\ast\\to (A\\wedge X)^W_\\ast$: \nthere is a map $A\\wedge X^W_\\ast\\to A^W_\\ast\\wedge X^W_\\ast$, given by sending $a\\mapsto c_a$;\nthen the exponential law gives a homotopy $A^W_\\ast\\wedge X^W_\\ast\\to (A\\wedge X)^W_\\ast$.\nThis, in turn, gives a map $I_+\\wedge X^W_\\ast\\to (I_+\\wedge X)^W_\\ast\\to Y^W_\\ast$,\nthus making $X\\mapsto X^W_\\ast$ a homotopy functor.\n\nMotivated by our discussion of homotopy fibers, we can study composites which ``behave'' like short exact sequences.\n\\begin{definition}\n    A \\emph{fiber sequence} in $\\Ho(\\Top_\\ast)$ is a composite $X\\to Y\\to Z$ that is\n    isomorphic, in $\\Ho(\\Top_\\ast)$, to some composite $Ff\\xrightarrow{p} E\\xrightarrow{f}B$;\n    in other words, there exist (possibly zig-zags of) maps that are homotopy equivalences, that make the following\n    diagram commute:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    X\\ar[r]\\ar[d] & Y\\ar[r]\\ar[d] & Z\\ar[d]\\\\\n\t    Ff\\ar[r]_p & E\\ar[r]_f & B.\n\t    }\n    \\end{equation*}\n\\end{definition}\nLet us remark here that if $A^\\prime \\xar{\\sim} A$ is a homotopy equivalence, and $A\\to B \\to C$ is a fiber sequence, so\nis the composite $A^\\prime\\xar{\\sim} A \\to B\\to C$.\n\n\\begin{exercise}\\label{loopslimit}\n    Prove the following statements.\n    \\begin{itemize}\n\t\\item $\\Omega$ takes fiber sequences to fiber sequences.\n\t\\item $\\Omega Ff\\simeq F\\Omega f$. Check this!\n    \\end{itemize}\n\\end{exercise}\n\nWe've seen examples of fiber sequences in our elaborate study of the Barratt-Puppe sequence.\n\\begin{example}\nRecall our diagram:\n\\begin{equation*}\n    \\xymatrix{\n\t\\cdots\\ar[r] & Fp_4\\ar[r] & Fp_3 \\ar[r] & Fp_2\\ar[r] & Fp_1\\ar[r]^{p_2} & Ff\\ar[r]^{p_1} & X\\ar[r]^{f} & Y\\\\\n    \\cdots\\ar[r] & \\Omega Fp_1\\ar[r]|{\\overline{\\Omega p_2}}\\ar[u]_{\\simeq} & \\Omega Ff\\ar[u]_{\\simeq}\\ar[ur]|{i(p_2)}\\ar[r]|{\\overline{\\Omega p}} & \\Omega X\\ar[r]|{\\overline{\\Omega f}}\\ar[u]_{\\simeq}\\ar[ur]|{i(p_1)} & \\Omega Y\\ar[u]_\\simeq \\ar[ur]|{i(f)} & &\\\\\n\t\\Omega^2 X\\ar[u]_{\\simeq}\\ar[r]_{\\Omega f} & \\Omega Y\\ar[u]_{\\simeq}\\ar[ur]_{\\overline{\\Omega i(f)}} & & &\n    }\n\\end{equation*}\nThe composite $Ff\\to X\\xar{f} Y$ is canonically a fiber sequence.\nThe above diagram shows that $\\Omega Y\\to F\\xrightarrow{p}X$ is another fiber sequence: it is isomorphic to\n$Fp\\to F\\to X$ in $\\Ho(\\Top_\\ast)$.\nSimilarly, the composite $\\Omega X\\xrightarrow{\\overline{\\Omega f}}\\Omega Y\\to F$ is another fiber sequence;\nthis implies that $\\Omega X\\xrightarrow{\\Omega f}\\Omega Y\\to F$ is also an example of a fiber sequence\n(because these two fiber sequences differ by an automorphism of $\\Omega X$)\n\nApplying $\\Omega$ again, we get $\\Omega F\\xrightarrow{\\Omega p} \\Omega X\\xrightarrow{\\Omega f} \\Omega Y$.\nSince this is a looping of a fiber sequence, and taking loops takes fiber sequences to fiber sequences (Exercise \\ref{loopslimit}), this is another fiber sequence. \nLooping again gives another fiber sequence $\\Omega^2 Y\\xrightarrow{\\Omega i} \\Omega F\\xrightarrow{\\Omega p}\\Omega X$.\n(For the category-theoretically--minded folks, this is an unstable version of a triangulated category.)\n\\end{example}\n\n\\subsection{The long exact sequence of a fiber sequence}\nAs discussed at the end of \\S \\ref{secbarrattpuppe}, applying $\\pi_0 = [S^0,-]_\\ast$ to the\nBarratt-Puppe sequence associated to a map $f:X\\to Y$ gives a long exact sequence:\n\\begin{equation*}\n    \\xymatrix{\n\t& \\cdots\\ar[r] & \\pi_2 Y\\ar[dll]\\\\\n\t\\pi_1 F\\ar[r] & \\pi_1 X\\ar[r] & \\pi_1 Y\\ar[dll]\\\\\n\t\\pi_0 F\\ar[r] & \\pi_0 X. & \n    }\n\\end{equation*}\nof pointed sets.\nThe space $\\Omega^2 X$ is an \\emph{abelian} group object in $\\Ho(\\Top)$\n(in other words, the multiplication on $\\Omega^2 X$ is commutative up to homotopy).\nThis implies $\\pi_1(X)$ is a group, and that $\\pi_k(X)$ is abelian for $k\\geq 2$;\nhence, in our diagram above, all maps (except on $\\pi_0$) are group homomorphisms.\n\nConsider the case when $X\\to Y$ is the inclusion $i:A\\hookrightarrow X$ of a subspace.\nIn this case,\n$$Fi=\\{(a,\\omega)\\in A\\times X^I_\\ast|\\omega(1) = a\\};$$\nthis is just the collection of all paths that begin at $\\ast\\in A$ and end in $A$.\nThis motivates the definition of \\emph{relative homotopy groups}:\n\\begin{definition}\n    Define: \n    $$\\pi_n(X,A,\\ast) = \\pi_n(X,A) := \\pi_{n-1}Fi = [(I^n,\\partial I^n,(\\partial I^n\\times I)\\cup (I^{n-1}\\times 0)),(X,A,\\ast)].$$\n\\end{definition}\nWe have a sequence of inclusions\n$$\\partial I^n\\times I\\cup I^{n-1}\\times 0 \\subset \\partial I^n \\subset I^n.$$\nOne can check that\n$$\\pi_{n-1}Fi = [(I^n,\\partial I^n,(\\partial I^n\\times I)\\cup (I^{n-1}\\times 0)),(X,A,\\ast)].$$\nThis gives a long exact sequence on homotopy, analogous to the long exact sequence in relative homology:\n\\begin{equation}\\label{lexseqhomotopy}\n    \\xymatrix{\n\t& \\cdots\\ar[r] & \\pi_2 (X,A)\\ar[dll]\\\\\n\t\\pi_1 A\\ar[r] & \\pi_1 X\\ar[r] & \\pi_1 (X,A)\\ar[dll]\\\\\n\t\\pi_0 A\\ar[r] & \\pi_0 X & \n    }\n\\end{equation}\n", "meta": {"hexsha": "d838647afc94c41ddfd536a30c63ed392f4b551f", "size": 8348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-46-relative-homotopy.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-46-relative-homotopy.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-46-relative-homotopy.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": 56.4054054054, "max_line_length": 261, "alphanum_fraction": 0.6842357451, "num_tokens": 2968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839874, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.6868080473369769}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Iso To Unix Epoch}\nThe $isoToUnix$ operation converts an ISO 8601 Timestamp (see the \\href{https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#timestamps}{xAPI Specification})\nto the number of seconds that have elapsed since January 1, 1970\n\\begin{schema}{IsoToUnix}\n  Timestamp \\\\\n  seconds! : \\nat \\\\\n  isoToUnix~\\_ : \\finset_1 \\fun \\nat \\\\\n  \\where\n  seconds! = isoToUnix(timestamp)\n\\end{schema}\n\\begin{argue}\n  ts = 2015-11-18T12:17:00+00:00 \\equiv 2015-11-18T12:17:00Z \\\\\n  isoToUnixEpoch(ts) =  1447849020 & ISO 8601 $\\to$ Epoch time\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "4c7df4137bf635d704476285e80fa40e4b0fe92c", "size": 649, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/util/isoToUnix.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/isoToUnix.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/isoToUnix.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": 36.0555555556, "max_line_length": 165, "alphanum_fraction": 0.7226502311, "num_tokens": 220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.686791722932331}}
{"text": "% !TEX root = ../zeth-protocol-specification.tex\n\n\\section{Definitions}\\label{preliminaries:definitions}\n\n\\subsection{Negligible function}\\label{preliminaries:definitions:neg-func}\n\n\\begin{definition}[Negligible function, {\\cite[Definition 3.4]{katz2014introduction}}]\n    A function $f$ from $\\NN$ to $\\RR^{+}$ (positive real numbers) is negligible if for every positive polynomial $p$ there exists $N$ such that for all integers $n>N$ it holds that $f(n)< \\frac{1}{p(n)}$.\n\\end{definition}\n\n\\subsection{Basic algebra notions}\\label{preliminaries:definitions:basic-algebra}\n\n\\begin{definition}[Group, {see~\\cite[Section I.4]{bourbaki2003elements}}]\n    A group is given by a tuple $(\\gset, \\otimes)$, where $\\gset$ is a set and $\\otimes$ is a binary operation in $\\gset$, i.e. $\\otimes:\\gset\\times\\gset\\to \\gset$, with the following properties:\n    \\begin{itemize}\n        \\item $(\\gel{g} \\otimes \\gel{h}) \\otimes \\gel{k} = \\gel{g} \\otimes (\\gel{h} \\otimes \\gel{k})$ (associativity)\n        \\item There exists an element $\\gel{\\epsilon} \\in \\gset$ \\suchthat{} for each $\\gel{g} \\in \\gset$, $\\gel{g} \\otimes \\gel{\\epsilon} = \\gel{\\epsilon} \\otimes \\gel{g} = \\gel{g}$ (identity element).\n        \\item For each $\\gel{g} \\in \\gset$ there exist $\\gel{h} \\in \\gset$ \\suchthat{} $\\gel{g} \\otimes \\gel{h} = \\gel{h} \\otimes \\gel{g} = \\epsilon$ (inverse element).\n    \\end{itemize}\n\\end{definition}\n\nFor simplicity, we may also use the additive notation for groups: $\\otimes$ is denoted as $+$, the identity element as $\\gel{0}$ and the inverse element of $\\gel{g}$ as $-\\gel{g}$. Given $\\gel{g} \\in \\gset$ and $x \\in \\mathbb{Z}$, we have that:\n\\[x \\cdot \\gel{g} =\n\\begin{cases}\n    \\gel{0} & \\mbox{if } x = 0\\\\\n    \\gel{g} + \\ldots + \\gel{g}, (x \\mbox{ times}) & \\mbox{if } x > 0 \\\\\n    -\\gel{g} + \\ldots + (-\\gel{g}), (x \\mbox{ times}) & \\mbox{if } x < 0\n\\end{cases}.\n\\]\n\\begin{definition}[Finite Cyclic Group, {adapted from~\\cite[Sections 7.1.3, 7.3.2]{katz2014introduction}}]\n    A finite cyclic group is given by a tuple $(q, \\gset, \\ggen, \\otimes)$, called the \\emph{group description}, where $\\gset$ represents the set of group elements, $\\ggen$ is a generator and $q$ is the order. The generator $\\ggen$ generates the group; namely, each $h \\in \\gset$ can be expressed by the generator as $\\gel{h} = \\ggen \\otimes \\ldots \\otimes \\ggen $.\n    Given a scalar $x$, we denote by $\\groupenc{x}$ the \\emph{encoding} of $x$ in $\\gset$: i.e. $\\groupenc{x} = \\ggen \\otimes \\ldots \\otimes \\ggen$ ($x$ times). As consequence, $\\groupenc{1} = \\ggen$.\n\\end{definition}\n\nFor theoretical purposes, we introduce the \\groupSetup{} algorithm that for a given security parameter \\secpar{} outputs a cyclic group, formally:\n\\begin{definition}[Group Setup Algorithm, {taken from~\\cite[Sections 7.1.3, 7.3.2]{katz2014introduction}}]\n    A group setup algorithm \\groupSetup{} is a \\ppt{} algorithm which takes as input a security parameter \\secparam{} and outputs a group description $(q, \\gset, \\ggen, \\otimes)$, where the binary representation of $q$ is given by $\\secpar$ bits and each group element can be represented by $\\groupLen(\\secpar)$ bits. Note that \\groupLen{} is \\poly.\\footnote{For simplicity we may denote \\groupLen(\\secpar) as \\groupLen{}.}\n\\end{definition}\n\n\\subsection{Symmetric Encryption}\\label{preliminaries:definitions:sym-enc}\n\n\\begin{definition}[Symmetric Encryption,{\\cite[Definition 3.8]{katz2014introduction}}]\n    A symmetric encryption scheme \\sym{} is given by a tuple of \\ppt{} algorithms $(\\kgen,\\enc, \\dec)$ where:\n\\begin{itemize}\n    \\item \\kgen{}, the key generation algorithm, takes a security parameter \\secparam{} and outputs a secret key \\ek; we assume, without loss of generality, that $\\symKeyLen (\\secpar) = \\len{\\ek}\\geq \\secpar$. Note that $\\symKeyLen(\\secpar)$ is a polynomial function in \\secpar.\\footnote{For simplicity we may denote \\symKeyLen(\\secpar) as \\symKeyLen{}.}\n    \\item \\enc{}, the encryption algorithm, takes a key \\ek{}, a plaintext $\\msg\\in\\bin^{*}$ and returns a ciphertext $\\ct$.\n    \\item \\dec{}, the decryption algorithm, takes a key \\ek{} and a ciphertext $\\ct$, and returns a message $\\msg$. We assume, without loss of generality, that \\dec{} is deterministic.\n\\end{itemize}\n    For every security parameter $\\secpar{}$, key $\\ek$ output by $\\kgen{(\\secparam{})}$, and message $\\msg \\in \\bin^{*}$, it holds that $\\dec(\\ek, \\enc(\\ek, \\msg)) = \\msg$ (\\emph{correctness property}).\n\\end{definition}\n\nIf $(\\kgen,\\enc, \\dec)$ is such that for key $\\ek$ output by $\\kgen{(\\secparam)}$, algorithm $\\enc(\\ek, \\cdot)$ is only defined for messages $\\msg\\in\\bin^{l(\\secpar)}$, then we say that $(\\kgen,\\enc, \\dec)$ is a \\emph{fixed-length symmetric encryption scheme} with \\emph{length parameter} $l(\\secpar)$ ($l$ is $\\poly$). A security notion for \\sym{} follows:\n\n\\begin{figure}[h!]\n    \\centering\n    \\procedure[syntaxhighlight=auto, space=auto]{$\\indcpa (\\secpar)$}{\n        \\ek\\gets\\kgen{(\\secparam{})} \\\\\n        (\\msg_0, \\msg_1, \\state)\\gets{} \\adv^{\\oracle{\\enc_{\\ek}}}\\ \\mbox{with}\\ \\len{\\msg_0} = \\len{\\msg_1}\\\\\n        b \\sample{}\\bin{} \\\\\n        \\ct\\gets{} \\enc(\\ek,\\msg_b) \\\\\n        \\widetilde{b}\\gets{} \\adv^{\\oracle{\\enc_{\\ek}}} (\\ct, \\state)\\\\\n        \\pcreturn{} \\widetilde{b} = b\\\\\n    }\n    \\caption{\\indcpa{} game for \\sym.}\\label{fig:indcpa}\n\\end{figure}\n\n\\begin{definition}[\\indcpa]\n    Let $\\sym$ be a symmetric encryption scheme and let \\adv{} be an adversary. Consider the \\indcpa{} game described in Figure~\\ref{fig:indcpa}.\n    We define the \\indcpa{} advantage of \\adv{} as follows:\n    \\[\n        \\advantage{\\indcpa}{\\sym, \\adv} =  \\abs{2\\cdot\\prob{\\indcpa(\\secpar) = 1} - 1}.\n    \\]\n    \\sym{} is said to be \\indcpa{} secure if, for every \\ppt{} adversary \\adv{}, the advantage \\advantage{\\indcpa}{\\sym, \\adv} is a negligible function.\n\\end{definition}\n\n\\subsection{Asymmetric Encryption}\\label{preliminaries:definitions:asym-enc}\n\n\\begin{definition}[Asymmetric encryption, {\\cite[Definition 10.1]{katz2014introduction}}]\n    An \\emph{asymmetric encryption scheme} \\aSym{} is given by a tuple of \\ppt{} algorithms $(\\kgen,\\enc,\\dec)$ where:\n    \\begin{itemize}\n        \\item \\kgen{}, the key generation algorithm, takes a security parameter $\\secparam{}$ and returns a pair of keys $(\\sk,\\pk)$. We refer to the first of these as \\emph{private key} and the second as \\emph{public key}. We assume for convenience that $\\pk$ and $\\sk$ each have length at least $\\secpar{}$, and that $\\secpar{}$ can be determined from $\\pk$, $\\sk$;\n        \\item \\enc{}, the encryption algorithm, takes a public key $\\pk$, a plaintext $\\msg$, from some underlying plaintext space (that may depend on \\pk) and returns a ciphertext $\\ct$;\n        \\item \\dec{}, the decryption algorithm, takes a private key $\\sk$ and a ciphertext $\\ct$, and returns a message $\\msg$ or a special symbol $\\bot$ denoting the decryption failure. We assume, without loss of generality, that \\dec{} is deterministic.\n    \\end{itemize}\n    We require that for all $(\\sk,\\pk)$ returned by $\\kgen$, and every message $\\msg$ in the appropriate underlying plaintext space, it holds that $\\dec(\\sk, \\enc(\\pk,\\msg)) = \\msg$ (\\emph{correctness property}).\n\\end{definition}\n\nSecure communication usually requires ciphertext indistinguishability  (e.g. \\indccaii{}~\\cite[Definition 8]{abdalla1999dhaes}). In \\zeth, however, the key privacy property \\ikcca{}~\\cite{bellare2001key} is also required: it ensures indistinguishability of the key under which an encryption is performed.\n\n\\begin{figure}[h!]\n    \\centering\n    \\procedure[syntaxhighlight=auto, space=auto]{$\\ikcca (\\secpar)$}{\n        (\\sk_0,\\pk_0), (\\sk_1,\\pk_1) \\gets\\kgen{(\\secparam{})}\\\\\n        (\\msg, \\state)\\gets{} \\adv^{\\oracle{\\dec_{\\sk_0}}, \\oracle{\\dec_{\\sk_1}}} (\\pk_0,\\pk_1)\\\\\n        b \\sample{} \\bin{} \\\\\n        \\ct \\gets{} {} \\enc(\\pk_b, \\msg)\\\\\n        \\widetilde{b}\\gets{} {} \\adv^{\\oracle{\\dec_{\\sk_0}}, \\oracle{\\dec_{\\sk_1}}} {(\\ct,\\state)}\\\\\n        \\pcreturn{} \\widetilde{b} = b\n    }\n\\caption{\\ikcca{} game.}\\label{fig:ikcca}\n\\end{figure}\n\n\\begin{definition}[\\ikcca]\\label{preliminaries:def:ikcca}\n    Let $\\aSym = (\\kgen,\\enc, \\dec)$ be an asymmetric encryption scheme and let \\adv{} be an adversary. Given the \\ikcca{} game described in Figure~\\ref{fig:ikcca}, with the condition that \\adv{} cannot query $\\oracle{\\dec_{\\sk_0}}$ or $\\oracle{\\dec_{\\sk_1}}$ on the challenge ciphertext $\\ct$\\footnote{$\\state$ is some state information that the adversary outputs after the choice of the message to encrypt. It can be some preprocessed information that can be helpful to win the game}, we define the \\ikcca{} advantage of \\adv{} as follows:\n    \\[\n        \\advantage{\\ikcca}{\\aSym,\\adv} =  \\abs{2\\cdot\\prob{\\ikcca(\\secpar) = 1} - 1}\n    \\]\n    We say that \\aSym{} is \\ikcca{} secure if for every \\ppt{} adversary \\adv{} the advantage \\advantage{\\ikcca}{\\aSym,\\adv} is a negligible function.\n\\end{definition}\n\n\\subsection{(Block-cipher-based) Compression functions}\\label{preliminaries:definitions:hashcomp}\n\n\\begin{definition}\n    Let $\\kl, \\il > 1$. A \\emph{block cipher} is a map $\\Enc \\colon \\bin^{\\kl} \\times \\bin^{\\il} \\to \\bin^{\\il}$ where, for each key $\\key \\in \\bin^{\\kl}$, the function $\\Enc_\\key(\\cdot) = \\Enc(\\key, \\cdot)$ is a permutation on $\\bin^{\\il}$. If \\Enc~is a block cipher then $\\Dec$ is its inverse, that on input $(\\key, y)$ returns $\\msg$ such that $\\Enc_\\key(\\msg) = y$.\n\\end{definition}\n\nLet $\\blockSet(\\kl, \\il)$ be the set of all block ciphers $\\Enc \\colon \\bin^{\\kl} \\times \\bin^{\\il} \\to \\bin^{\\il}$. In order to analyze the security properties of block-cipher based cryptographic constructions it is common to use a security model denoted \\emph{the ideal cipher model (ICM)}. Informally speaking, in ICM attackers are allowed to query an oracle simulating a random block cipher and they have no information on the internal structure. We formalize this notion in the following definition:\n\n\\begin{definition}[Ideal Cipher Model~\\cite{holenstein2011equivalence}]\\label{preliminaries:def:ICM}\n    The Ideal Cipher Model (ICM), is a security model where all parties are granted access to an ideal cipher $\\Enc \\colon \\bin^{\\kl} \\times \\bin^\\il \\to \\bin^\\il$, a random primitive such that the restrictions $\\Enc (\\key, \\cdot )$ for $\\key \\in \\bin^{\\kl}$ are $2^{\\kl}$ independent random permutations.\n\\end{definition}\n\nFor fixed $\\kl$ and $\\il$, each party is given access to the oracles \\oracleEnc{} and \\oracleDec{}, simulating $\\Enc$ and $\\Dec$, which can be queried for encryption and decryption a polynomial number of times. The encryption oracle takes as input a key, $\\key\\in \\bin^{\\kl}$, and a preimage, $\\msg \\in \\bin^{\\il}$, and returns a tuple comprising the image, $y \\in \\bin^{\\il}$, along with the inputs, $\\key$ and $\\msg$. If $(\\key, \\msg)$ is queried for the first time, the image, $y$, is taken uniformly at random and added to the oracle's table. Otherwise, the oracle returns the $y$ associated with query $(\\key, \\msg)$ in its table. The decryption oracle is defined similarly with the image and key defined as inputs and the preimage chosen randomly (see:~\\cref{preliminaries:fig:icm-oracles}).\n\n\\begin{figure}\n    \\begin{pchstack}[center]\n        \\procedure[syntaxhighlight=auto]{$\\oracleEnc (\\key, \\msg)$}{\n            if (\\key, \\msg, \\cdot) \\notin\\text{Table}_{\\oracle{}} \\\\\n            \\t y \\sample \\bin^\\il \\\\\n            \\t \\text{Table}_{\\oracle{}}\\text{.append} (\\key, \\msg, y)\\\\\n            \\pcelse{} y = \\text{Table}_{\\oracle{}} (\\key, \\msg) \\\\\n            return (\\key, \\msg, y) \\\\\n        }\n        \\procedure[syntaxhighlight=auto]{$\\oracleDec (\\key, y)$}{\n            if (\\key, \\cdot, y) \\notin\\text{Table}_{\\oracle{}}\\\\\n            \\t \\msg \\sample \\bin^\\il\\\\\n            \\t \\text{Table}_{\\oracle{}}\\text{.append} (\\key, \\msg, y)\\\\\n            \\pcelse{} \\msg = \\text{Table}_{\\oracle{}} (\\key, y)\\\\\n            return (\\key, \\msg, y)\n        }\n    \\end{pchstack}\n    \\caption{Oracles of an ideal block cipher, with $\\text{Table}_{\\oracle{}}$ being a table of tuples (key, preimage, image) of queries already answered by the oracle.}\\label{preliminaries:fig:icm-oracles}\n\\end{figure}\n\n\\begin{definition}[Block-cipher based compression function~\\cite{black2002black}]\\label{preliminaries:definitions:compression-function}\n    A \\emph{block cipher-based compression function} is a map $\\fFunc$ such that\n    \\[\n        \\fFunc \\colon \\blockSet(\\kl, \\il) \\times \\bin^a \\times \\bin^b \\to \\bin^c\n    \\]\n    where $\\kl,\\ \\il,\\ a,\\ b,\\ c > 1$ and $a+b > c$. The function \\fFunc, given $\\msg \\in \\left ( \\bin^a \\times \\bin^b \\right )$, computes $\\fFunc(\\Enc, \\msg)$ using an \\Enc-oracle.\n\\end{definition}\n\n\\begin{remark}\n    We use the notation \\FEnc{} if a compression function \\fFunc{} is defined over a given block-cipher \\Enc, i.e. $\\FEnc: \\bin^a \\times \\bin^b \\to \\bin^c$ and $\\FEnc = \\fFunc(\\Enc, \\cdot)$, for $a, b, c$ as given in the definition above.\n\\end{remark}\n\nLet \\fFunc{} be a compression function based on a block-cipher. Fix a constant $h_0 \\in \\bin^c$ and an adversary \\adv. We define the advantage in finding a collision in \\fFunc{} as the real number\n\\[\n    \\advColl =\n    \\prob{\n        \\begin{aligned}\n            &\\Enc \\sample \\blockSet(\\kl, \\il); ((\\key,\\msg), (\\key',\\msg')) \\gets \\adv^{\\oracleEnc, \\oracleDec}(\\FEnc, h_0):\\\\\n            &((\\key, \\msg) \\neq (\\key',\\msg') \\land \\FEnc(\\key, \\msg) = \\FEnc(\\key', \\msg')) \\lor \\FEnc(\\key, \\msg) = h_0\n        \\end{aligned}\n    }.\n\\]\n\nThe previous definition gives credit for finding an $(\\key, \\msg)$ such that $\\FEnc(\\key, \\msg) = h_0$ for a fixed $h_0 \\in \\bin^c$.\n\n\\subsection{Hash functions}\\label{preliminaries:definitions:hash-function}\n\n\\begin{definition}[Hash function, {\\cite[Definition 4.9]{katz2014introduction}}]\n    A hash function \\hashSet{} is a pair of algorithms $(\\hashSetup, \\hash)$ fulfilling the following properties:\n    \\begin{itemize}\n        \\item \\hashSetup{} is a \\ppt{} algorithm which takes as input a security parameter \\secparam{} and outputs a key $\\hk$. We assume that \\secparam{} is included in $\\hk$.\n        \\item $\\hash$ is (deterministic) polynomial-time algorithm that takes as input a key $\\hk$ and any string $x\\in\\bin^{*}$, and outputs a string $\\hash(\\hk, x) = \\hash_{\\hk}(x)\\in\\bin^{\\hashLen}$, where $\\hashLen$ is a polynomial function in \\secpar.\\footnote{For simplicity we may denote \\hashLen(\\secpar) as \\hashLen{}.}\n    \\end{itemize}\n    If for every \\secpar{} and \\hk{}, $\\hash_{\\hk}$ is defined only over inputs of length $\\hashInpLen(\\secpar)$ and $\\hashInpLen(\\secpar) > \\hashLen(\\secpar)$, then we say that \\hashSet{} is a \\emph{fixed-length hash function} with length parameter $\\hashInpLen$. Note that $\\hashInpLen(\\secpar)$ is a polynomial function in \\secpar.\n\\end{definition}\n\nInformally, for a given function $f$ we say that $(x,y)$ is a \\emph{collision} if $f(x) = f(y)$ and $x \\neq y$. In the following, we formalize this notion for a hash function $\\hashSet$.\n\n\\begin{definition}[Collision Resistance{~\\cite[Definitions 4.10]{katz2014introduction}}]\\label{preliminaries:def:collision-resistance}\n    A hash function $\\hashSet = (\\hashSetup, \\hash)$ is collision resistant if for all probabilistic polynomial-time adversaries $\\adv$ there exists a negligible function $\\negl$ such that:\n\\[\n    \\advantage{\\colres}{\\hashSet, \\adv} = \\prob{\n        \\hk \\gets \\hashSetup(\\secparam), (x, y) \\gets \\adv(\\hk): \\ x \\neq y \\land \\hash_{\\hk}(x) = \\hash_{\\hk}(y)\n    }\n\\]\n\\end{definition}\n\n\\subsubsection{\\hdhi{} and \\hdhii{} assumptions}\n\nThe Hash Diffie-Helmann Independence (\\hdhi{}) assumption states that, given \\hash{} in \\hashSet{} and a group description $(p, \\gset, \\ggen, \\otimes)$, for $\\groupenc{u}$ and $\\groupenc{v}$, with $u,v$ sampled at random, it is hard for an attacker to distinguish $\\hash(\\groupenc{u} \\concat \\groupenc{uv})$ from a random string of the same size.\\footnote{Note that \\hash{} takes as inputs bit strings, so technically we should make use of an encoding function from \\gset to $\\bin{}^{\\groupLen}$ but we may omit this step through the document to improve readability.} This is formalized in \\cref{def:hdhi}, where an attacker can also access an oracle $\\oracleHdhi{v}$ that on inputs $x \\in \\gset$ returns $\\hash(x \\concat v\\cdot x)$ (queries on $\\groupenc{u}$ are forbidden).\\footnote{In~\\cite[Section 3.2.1]{abdalla1999dhaes} this notion is denoted as adaptive HDH independence assumption. Since we only introduce the adaptive version we denote it as \\hdhi{}.}. In other words, the \\hdhi{} assumption measures the sense in which \\hash{} is ``independent'' of the underlying Diffie-Hellman problem.\n\n\\begin{definition}[\\hdhi, {\\cite[Definition 7]{abdalla1999dhaes}}]\\label{def:hdhi}\n    Let $\\hashSet$ be a hash function, $\\groupSetup$ be a group generation algorithm and \\adv{} be an adversary. Consider the \\hdhi{} game described in Figure~\\ref{fig:hdhi}. We define the advantage of \\adv{} in violating the \\hdhi{} assumption as follows:\n    \\[\n        \\advantage{\\hdhi}{\\hashSet,\\groupSetup, \\adv} =  \\abs{2\\cdot\\prob{\\hdhi(\\secpar) = 1} - 1}.\n    \\]\n\n\\end{definition}\nNote that above definition corresponds to~\\cite[Section 3.2.1, Definition 3]{abdalla1999dhaes}. In the following, we introduce a similar notion denoted as \\hdhii{} (this is an adaptation of \\odhii{} notion in~\\cite[Section 6]{abdalla2010robust}) and it will be useful in the \\ikcca{} proof~\\cref{instantiation:enc:security}.\n\n\\begin{definition}[\\hdhii]\\label{preliminaries:definitions:hdhii}\n    Let $\\hashSet$ be a hash function, $\\groupSetup$ a group generation algorithm and let \\adv{} be an adversary. Consider the \\hdhii{} game described in Figure~\\ref{preliminaries:fig:hdhii}. We define the advantage of \\adv{} in violating the \\hdhii{} assumption as follows:\n    \\[\n        \\advantage{\\hdhii}{\\hashSet, \\groupSetup, \\adv} =  \\abs{2 \\cdot \\prob{\\hdhii(\\secpar) = 1} - 1}.\n    \\]\n\\end{definition}\n\n\\begin{figure}[ht]\n    \\begin{minipage}[t]{0.5\\textwidth}\n        \\centering\n        \\procedure[syntaxhighlight=auto, space=auto]{$\\hdhi (\\secpar)$}{\n            \\hk \\gets{} \\hashSet.\\hashSetup{(\\secparam{})}\\\\\n            (q, \\gset, \\ggen, \\otimes) \\gets{} \\groupSetup(\\secparam{})\\\\\n            u,v \\sample{} [q] \\\\\n            w_{0} \\gets{} \\hashSet.\\hash_{\\hk} (\\groupenc{u} \\concat \\groupenc{uv})\\\\\n            w_{1} \\sample{} \\bin^{\\hashLen}\\\\\n            b \\sample{} \\bin{} \\\\\n            \\widetilde{b} \\gets{} \\adv^{\\oracleHdhi{v}} (\\groupenc{u},\\groupenc{v},w_{b})\\\\\n            \\pcreturn{}\\widetilde{b} = b\n        }\n        \\caption{\\hdhi{} game.}\\label{fig:hdhi}\n    \\end{minipage}%\n    \\begin{minipage}[t]{0.5\\textwidth}\n        \\centering\n        \\procedure[syntaxhighlight=auto, space=auto]{$\\hdhii (\\secpar)$}{\n            \\hk \\gets{} \\hashSet.\\hashSetup{(\\secparam{})}\\\\\n            (q, \\gset, \\ggen, \\otimes) \\gets{} \\groupSetup(\\secparam{})\\\\\n            u,v_0, v_1 \\sample{} [q] \\\\\n            w_{0,0}\\gets{} \\hashSet.\\hash_\\hk (\\groupenc{u} \\concat \\groupenc{uv_0}), w_{0,1}\\gets{} \\hashSet.\\hash_\\hk(\\groupenc{u} \\concat \\groupenc{uv_1})\\\\\n            w_{1,0} \\sample{} \\bin^{\\hashLen}, w_{1,1} \\sample{} \\bin^{\\hashLen}\\\\\n            b \\sample{} \\bin{} \\\\\n            \\widetilde{b} \\gets{} \\adv^{\\oracleHdhi{v_0}, \\oracleHdhi{v_1}} (\\groupenc{u}, \\groupenc{v_0}, \\groupenc{v_1}, w_{b,0}, w_{b,1})\\\\\n            \\pcreturn{}\\widetilde{b} = b\n        }\n        \\caption{\\hdhii{} game.}\\label{preliminaries:fig:hdhii}\n    \\end{minipage}%\n\\end{figure}\n\n\\begin{lemma}\\label{preliminaries:lemma:hdhi_hdhii}\n    Let \\adv{} be an adversary with advantage \\advantage{\\hdhii}{\\hashSet, \\groupSetup, \\adv}[] in solving the \\hdhii{} problem. Then there exists an adversary \\bdv{} such that\n    \\[\n        \\advantage{\\hdhii}{\\hashSet, \\groupSetup{}, \\adv} \\leq 2 \\cdot \\advantage{\\hdhi}{\\hashSet, \\groupSetup{}, \\bdv}.\n    \\]\n\\end{lemma}\n\\begin{proof}\n    We can reuse the proof described in~\\cite[Lemma 6.1]{abdalla2010robust} by applying minor modifications. In fact, \\hdhi{} and \\hdhii{} are, respectively, slightly different from \\odh{} and \\odhii{} notions: in the related security games, if $b=0$ the challenges are constructed as $\\hash{(\\groupenc{u} \\concat \\groupenc{uv})}$ and $\\{\\hash{(\\groupenc{u} \\concat \\groupenc{uv_0})}, \\hash{(\\groupenc{u} \\concat \\groupenc{uv_1})}\\}$ instead of $\\hash{(\\groupenc{uv})}$ and $\\{\\hash{(\\groupenc{uv_0})}, \\hash{(\\groupenc{uv_1})}\\}$. By accordingly changing the instances of $\\hash{}$ in the games $\\gamestyle{G_0},\\gamestyle{G_1}, \\gamestyle{G_2}$ of~\\cite[Lemma 6.1]{abdalla2010robust} our lemma follows.\n\\end{proof}\n\n\\subsection{Pseudo Random Functions}\\label{preliminaries:definitions:prfs}\n\nInformally speaking, a pseudorandom function family $\\prfSet = \\indexedset{\\prf_{\\key}: \\mathit{D} \\to \\mathit{C}}{\\key \\in \\keyspace}$ is a collection of functions such that for randomly chosen $\\key \\in \\keyspace$, the function $\\prf_{\\key}$ is indistinguishable from a random function that maps $\\mathit{D}$ to $\\mathit{C}$.\n\n\\begin{definition}[PRF Family{~\\cite[Definition 3.24]{katz2014introduction}}]\nLet $\\funcSet: \\bin^* \\times \\bin^* \\to \\bin^*$ be an efficient, length-preserving, keyed function. We say $\\funcSet$ is a pseudo random function if for all probabilistic polynomial-time distinguishers $\\distinguisher$, there exists a negligible function $\\negl[]$ such that:\n\n\\[\n\t\\advantage{\\prf}{\\funcSet, \\distinguisher} = \\abs*{\\prob{ \\distinguisher^{\\funcSet_k(\\cdot)}(\\secparam)=1 } - \\prob{ \\distinguisher^{f_\\secpar(\\cdot)}(\\secparam)=1 }} \\leq \\negl\n\\]\n\nwhere $k \\sample \\keyspace = \\bin^\\secpar$ is chosen uniformly at random and $f_\\secpar$ is chosen uniformly at random from the set of functions mapping $\\secpar$-bit strings to $\\secpar$-bit strings.\n\\end{definition}\n\n\\subsection{Commitment scheme}\\label{preliminaries:definitions:commitment-sc}\n\n\\begin{definition}[Non-interactive commitment scheme{~\\cite[Section 2.1]{bootle2015short}}]\n    A non-interactive commitment scheme $\\comm$ is defined by the following algorithms:\n    \\begin{itemize}\n        \\item $\\setup$, is a \\ppt{} algorithm that takes a security parameter \\secparam{} and outputs public parameters $\\pparams$.\n        \\item $\\commit{}{}$, is a polynomial-time algorithm that takes a message $m \\in\\BB^\\il $, a random coin $r \\in \\BB^\\nl$ and outputs a commitment $\\cm{} \\in \\BB^\\ol$.\n    \\end{itemize}\n\\end{definition}\n\nWe assume that $\\pparams$ is implicitly passed to $\\commit{}{}$.\n\n\\begin{definition}[Computationally Hiding]\\label{preliminaries:definitions:commitment-hiding}\nWe say that a commitment scheme is computationally hiding if for all \\ppt{} adversary \\adv{} the following:\n\\[\n\\abs*{\n    \\prob{\n    \\begin{aligned}\n        & \\pparams \\gets{} \\setup(\\secparam), (\\msg_0,\\msg_1) \\gets \\adv(pp), b \\sample \\bin,\\\\\n        & r \\sample \\BB^\\nl, \\cm{} \\gets \\commit{\\msg_b}{r}, \\widetilde{b} \\gets \\adv(\\cm{}), b=\\widetilde{b}\n    \\end{aligned}\n    }\n    - \\frac{1}{2}\n}\n\\]\nis at most negligible in $\\secpar$.\n\\end{definition}\n\n\\begin{definition}[Computationally Binding]\\label{preliminaries:def:comp-binding}\nWe say that a commitment scheme is computationally binding if for all \\ppt{} adversary \\adv{} the following:\n\\[\n    \\prob{\n    \\begin{aligned}\n        & pp \\gets{} \\setup(\\secparam), (\\msg_0, r_0,\\msg_1, r_1) \\gets \\adv(pp)\\\\\n        & m_0 \\neq m_1 \\land \\commit{\\msg_0}{r_0} = \\commit{\\msg_1}{r_1}\n    \\end{aligned}\n    }\n\\]\nis at most negligible in $\\secpar$.\n\\end{definition}\n\nNote that the previous definitions can be made \\emph{statistical} if we consider unbounded attackers \\adv.\n\n\\subsection{Digital Signature}\\label{preliminaries:definitions:digital-signature}\n\n\\begin{definition}[Digital signature{~\\cite[Definition 12.1]{katz2014introduction}}]\n    A digital signature scheme $\\sigscheme$ is defined by the tuple of functions $\\sigscheme = (\\kgen, \\sig, \\verify)$,\n    \\begin{itemize}\n        \\item $(\\sk, \\vk) \\gets \\kgen(\\secparam)$. Key Generation randomized algorithm takes as input the security parameter \\secparam~and returns a signing key \\sk~and verifying key \\vk.\n        \\item $\\sigma \\gets \\sig(\\sk, \\msg)$. Given a signing key \\sk~and a message $\\msg$, the $\\sig$ algorithm computes and outputs a signature $\\sigma$.\n        \\item $\\bin \\gets \\verify(\\vk, \\msg, \\sigma)$. Given a verification key \\vk, a message $\\msg$ and a signature $\\sigma$, the $\\verify$ algorithm returns 1 if $\\sigma$ is a valid signature else 0.\n    \\end{itemize}\n\\end{definition}\n\nA signature scheme must satisfy the \\emph{correctness property} (i.e~$\\verify(\\vk, \\msg, \\sig(\\sk, \\msg)) = \\true$, where $(\\sk, \\vk) \\gets \\kgen(\\secparam)$) and unforgeable (i.e.~it is intractable to produce a signature, without knowing the signing key $\\sk$, on a message that has not been signed yet). In addition to these properties, certain digital signature schemes have an additional property called ``one-timeness''.\n\n\\begin{figure}\n    \\begin{minipage}[t]{.5\\textwidth}\n        \\centering\n        \\procedure[linenumbering]{$\\ufcma(\\secparam, \\timeBound, \\queryBound)$}{%\n            (\\sk, \\vk) \\gets~\\kgen(\\secparam) \\\\\n            \\state \\gets~\\adv^{\\oracleSig} (\\vk,\\cdot) \\\\\n            \\pccomment{$\\state = \\indexedset{(\\msg_i, \\sigma_i)}{i \\in [\\queryBound]}$ where $\\msg_i$ denotes} \\\\\n            \\pccomment{the ith query made to $\\oracleSig$ and} \\\\\n            \\pccomment{$\\sigma_i$ denotes the ith oracle answers} \\\\\n            (\\msg^{*}, \\sigma^{*}) \\gets~\\adv(\\state) \\\\\n            \\pcreturn \\verify(\\vk, \\msg^{*}, \\sigma^{*}) = 1 \\\\\n            \\t \\land \\msg^{*} \\not \\in \\indexedset{\\msg_i}{i \\in [\\queryBound]}\n        }\n        \\caption{\\ufcma~game}\\label{preliminaries:fig:uf-cma-game}\n    \\end{minipage}%\n    \\begin{minipage}[t]{.5\\textwidth}\n        \\centering\n        \\procedure[linenumbering]{$\\sufcma(\\secparam, \\timeBound, \\queryBound)$}{%\n            (\\sk, \\vk) \\gets \\kgen(\\secparam) \\\\\n            \\state \\gets \\adv^{\\oracleSig} (\\vk,\\cdot) \\\\\n            \\pccomment{$\\state = \\indexedset{(\\msg_i, \\sigma_i)}{i \\in [\\queryBound]}$ where $\\msg_i$ denotes} \\\\\n            \\pccomment{the ith query made to $\\oracleSig$ and} \\\\\n            \\pccomment{$\\sigma_i$ denotes the ith oracle answers} \\\\\n            (\\msg^{*}, \\sigma^{*}) \\gets~\\adv(\\state) \\\\\n            \\pcreturn \\verify(\\vk, \\msg^{*}, \\sigma^{*}) = 1 \\\\\n            \\t \\land (\\msg^{*}, \\sigma^{*}) \\not \\in \\indexedset{(\\msg_i, \\sigma_i)}{i \\in [\\queryBound]}\n        }\n        \\caption{\\sufcma~game}\\label{preliminaries:fig:suf-cma-game}\n    \\end{minipage}%\n\\end{figure}\n\n\n\\begin{definition}[Unforgeability (\\ufcma){~\\cite[Definition 12.2]{katz2014introduction}}]\\label{preliminaries:def:ufcma}\nA digital signature scheme $\\sigscheme$ is \\ufcma{} if the probability for any \\ppt~adversary $\\adv$ to win the \\ufcma~game depicted in~\\cref{preliminaries:fig:uf-cma-game} is negligible.\n\\end{definition}\n\n\\begin{definition}[Strong Unforgeability (\\sufcma)]\\label{preliminaries:def:sufcma}\nA digital signature scheme $\\sigscheme$ is \\sufcma{} if the probability for any \\ppt~adversary $\\adv$ to win the \\sufcma~game depicted in~\\cref{preliminaries:fig:suf-cma-game} is negligible.\n\\end{definition}\n\n\\begin{definition}[One-Time (OT) Signature{~\\cite[Definition 12.6]{katz2014introduction}}]\\label{preliminaries:def:ot-sig}\n    A one-time signature scheme is a digital signature scheme that uses each key-pair at most once.\n\\end{definition}\n\n\\begin{remark}\n    It is worth noting that users may use one-time signing keys to sign multiple messages. In this case no security guarantees can be ensured.\n\\end{remark}\n\\subsection{Message Authentication Code}\nA message authentication code is a scheme that enables users to tag data for the purpose of authenticity and integrity. Formally:\n\n\\begin{definition}[Message Authentication Code,{\\cite[Definition 4.1]{katz2014introduction}}]\nA message authentication code \\mac{} is given by a tuple of \\ppt{} algorithms $(\\kgen,\\tagg, \\verify)$ where:\n    \\begin{itemize}\n        \\item \\kgen{}, the key generation algorithm, takes a security parameter \\secparam{}, and returns a key $\\mk \\in \\bin^{\\macKeyLen(\\secpar)}$.\\footnote{For simplicity we may denote \\macKeyLen(\\secpar) as \\macKeyLen{}.}\n        \\item \\tagg{}, the tag generation algorithm, takes a key $\\mk$ and a message $ y\\in\\bin^{*} $ and returns a string $\\tau\\in\\bin^{*}$, called \\emph{tag}.\n        \\item  \\verify{}, the tag verification algorithm, takes a key $\\mk$, a message $ y \\in \\bin^{*} $ and a tag $\\tau \\in \\bin^{*}$. It returns a value in $\\bin$ where: $0$ denotes that the message was rejected (i.e.~is deemed unauthentic) and $1$ denotes that the message was accepted (i.e.~is deemed authentic).\n    \\end{itemize}\n    We require that for all $\\mk \\in \\bin^{\\secpar}$ and $y \\in \\bin^{*}$ we have $\\verify(\\mk, y, \\tagg(\\mk,y)) = 1$. If $\\tagg(\\mk,\\cdot)$ is defined only over messages of length $l(\\secpar)$ and $\\verify(\\mk,y,\\tau)$ outputs $0$ for every $y$ that is not of length $l(\\secpar)$, then we say that $(\\kgen,\\tagg, \\verify)$ is a \\emph{fixed-length} \\mac{} with length parameter $l(\\secpar)$.\n\\end{definition}\n\nA security notion for \\mac{} follows:\n\n\\begin{figure}\n    \\centering\n    \\procedure[syntaxhighlight=auto, space=auto]{\\sufcma(\\secpar)}{\n        \\mk\\gets{} \\kgen{(\\secparam{})}\\\\\n        (\\overline{y}, \\overline{\\tau})\\gets{} \\adv^{\\oracle{\\tagg_{\\mk}}, \\oracle{\\verify_{\\mk}}}\\\\\n        \\pcreturn{} \\verify(\\mk, \\overline{y}, \\overline{\\tau}) = 1\n    }\n    \\caption{\\sufcma{} game.}\\label{fig:sufcma}\n\\end{figure}\n\n\\begin{definition}[\\sufcma,{\\cite[Section 3.2.3]{abdalla1999dhaes}}]\n    Let $\\mac = (\\kgen,\\tagg, \\verify)$ be a message authentication scheme and let \\adv{} be an adversary. Consider the \\sufcma{} game described in Figure~\\ref{fig:sufcma}, with the condition that $\\tagg (\\mk, \\overline{y}) \\neq \\overline{\\tau}$. We say adversary \\adv{} has \\emph{forged} when it outputs a pair $(\\overline{y}, \\overline{\\tau})$ such that $\\verify_k(\\overline{y},\\overline{\\tau}) = 1$ and $(\\overline{y},\\overline{\\tau})$ was not previously obtained via a query to the tag oracle.\n\n    We define the \\sufcma{} advantage of \\adv{} as follows:\n    \\[\n        \\advantage{\\sufcma}{\\mac, \\adv} =  \\prob{\\sufcma(\\secpar) = 1}\n    \\]\n\n    We say that \\mac{} is \\sufcma{} secure if for every \\ppt{} adversary \\adv{} the advantage \\advantage{\\sufcma}{\\mac, \\adv} is a negligible function.\n\\end{definition}\n", "meta": {"hexsha": "7d97d5eafd3170e38bb0fb54ae04d99ae384a48f", "size": 30360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chap01-sec06.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-sec06.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-sec06.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": 74.962962963, "max_line_length": 1098, "alphanum_fraction": 0.6684782609, "num_tokens": 9509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6867917223958832}}
{"text": "\\section{Matplotlib} % (fold)\n\\label{sec:matplotlib}\n\\begin{questions}\n\\titledquestion{Plotting a function} % (fold)\n\\label{sub:plotting_a_function}\n\nPlot the function\n\\[\n    f(x) = \\sin^2(x-2)e^{-x^2}\n\\]\nover the interval $[0,2]$.\nAdd proper axis labels, a title, etc.\n\n% titledquestion plotting_a_function (end)\n\n\\titledquestion{Data} % (fold)\n\\label{sub:data}\n\nCreate a data matrix $X$ with 20 observations of 10 variables.\nGenerate a vector $b$ with parameters\nThen generate the response vector $y = Xb + z$ where $z$ is a vector with\nstandard normally distributed variables.\n\nNow (by only using y and X), find an estimator for $b$, by solving\n\\[\n    \\hat b = \\arg\\min_b \\|Xb - y\\|_2\n\\]\n\nPlot the true parameters $b$ and estimated parameters $\\hat b$.\nSee Figure~\\ref{fig:param_plot} for an example plot.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.45\\textwidth]{img/param_plot.pdf}\n    \\caption{Parameter plot}\n    \\label{fig:param_plot}\n\\end{figure}\n\n% titledquestion data (end)\n\n\\titledquestion{Histogram and density estimation} % (fold)\n\\label{sub:histogram_and_density_estimation}\n\nGenerate a vector $z$ of $10000$ observations from your favorite exotic distribution.\nThen make a plot that shows a histogram of $z$ (with 25 bins), along with an estimate for the density,\nusing a Gaussian kernel density estimator (see scipy.stats).\nSee Figure~\\ref{fig:hist} for an example plot.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.45\\textwidth]{img/hist_plot.pdf}\n    \\caption{Histogram}\n    \\label{fig:hist}\n\\end{figure}\n\n% titledquestion histogram_and_density_estimation (end)\n\\end{questions}\n% section matplotlib (end)\n", "meta": {"hexsha": "eefa54908c0283da8063ee7f6e525ebbdc97dde2", "size": 1653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/tex/mpl.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/mpl.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/mpl.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": 28.0169491525, "max_line_length": 102, "alphanum_fraction": 0.7332123412, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.686768152698762}}
{"text": "\\chapter{(Discrete) Martingale}\n\\emph{Life is a super-martingale. You should take your money and run.}\n\\newpage\n\n\n\\section{Definition of a Martingale}\n    \\subsection{Definition}\n        \\begin{definition}[Martingale]\\label{def:Martingale}\n            A stochastic process is a \\textbf{Martingale} if\n            \\[ \\forall t \\ge 0 \\quad \\mathbb{E}[X_{t+1}|X_0,\\dots,X_t] = X_t \\]\n        \\end{definition}\n\n        For conciseness in this chapter we use\n        \\[ X_{(m,n)} = (X_m,\\dots,X_n) \\]\n        to denote a portion of the stochastic process from time $m$ to $n$.\n\n        \\begin{definition}[Generalized Martingale]\\label{def:GeneralizedMartingale}\n            Given two stochastic processes $X_t$ and $Z_t$. $Z_t$ is a \\textbf{martingale} \\emph{with respect to} $X_t$ if\n            \\[ \\forall t \\ge 0 \\quad \\mathbb{E}[Z_{t+1} | X_{(0,t)}] = Z_t \\]\n        \\end{definition}\n        \\begin{remark}\n            definition \\ref{def:Martingale} is a special case of \\ref{def:GeneralizedMartingale} where $Z_t = X_t$.\n        \\end{remark}\n\n    \\subsection{Fancier Definitions}\n        Recall measure theory stuff in the first lecture.\n        Let $\\mathcal{F}_n = (X_0,\\dots,X_n)$ be the smallest $\\mathcal{F}$-measurable $\\sigma$-algebra.\n        \\begin{definition}[Filteration]\n            $\\{\\mathcal{F}_n\\}$ is called a \\textbf{filteration} if\n            \\[ \\mathcal{F}_0 \\subseteq \\mathcal{F}_1 \\subseteq \\cdots \\subseteq \\mathcal{F}_n \\] \n        \\end{definition}\n\n        \\begin{definition}[Martingale (Fancy)]\\label{def:FancyMartingale}\n            $\\{Z_t\\}$ is a \\textbf{martingale} \\emph{w.r.t. a filteration} $\\{\\mathcal{F}_t\\}$ if\n            \\begin{enumerate}\n                \\item $\\forall t \\ge 0$, $Z_t$ is $\\mathcal{F}_t$-measurable.\n                \\item $\\mathbb{E}[Z_{t+1}|\\mathcal{F}_t] = Z_t$. Or equivalently $\\mathbb{E}[Z_{t+1}] = \\mathbb{E}[Z_t]$\n            \\end{enumerate}\n        \\end{definition}\n\n        \\begin{remark}\n            If $\\mathbb{E}[X_{t+1}|\\mathcal{F}_t] \\le X_t$, then it is called a \\textbf{Super-martingale}.\n\n            If $\\mathbb{E}[X_{t+1}|\\mathcal{F}_t] \\ge X_t$, then it is called a \\textbf{Sub-martingale}.\n        \\end{remark}\n\n    \\subsection{Examples}\n        \\subsubsection{Random Walk on 1-d Integers}\n        Consider the random walk on $\\mathbb{Z}$. Let $X_t \\in \\{-1, 1\\}$ be a uniform-at-random r.v. denoting the direction of the $t$-th move.\n\n        Let $Z_t = \\sum_{i=1}^tX_i$ and $Z_0=0$, then $Z_t$ is a martingale w.r.t. $X_t$.\n\n        \\[ \\mathbb{E}[Z_{t+1}|X_{(0,t)}] = \\mathbb{E}[Z_t + X_{t+1}|X_{(0,t)}] = Z_t + \\mathbb{E}[X_{t+1}|X_{(0,t)}] = Z_t \\]\n\n        \\subsubsection{Branching Process}\n        The branching process is introduced in section \\ref{sub:BranchingProcess}.\n\n        Let $Z_t$ be the number of people in the $t$-th generation, let $X_{ti}$ be the children of the $i$-th people in the $t$-th generation.\n\n        Assume $\\mathbb{E}[X_{ti}] = \\mu$.\n\n        Notice that we have\n        \\[ Z_{t+1} = \\sum_{i=1}^{Z_t}X_{ti} \\]\n\n        \\[ \\mathbb{E}[Z_{t+1}|\\mathcal{F}_t] = \\mathbb{E}[Z_{t+1}|Z_t] \\]\n\n        Since\n        \\[ \\mathbb{E}[Z_{t+1}|Z_t=z] = \\mathbb{E}[\\sum_{i=1}^zX_{ti}|Z_t=z] = \\mu z \\]\n\n        Therefore\n        \\[ \\mathbb{E}[Z_{t+1}|\\mathcal{F}_t] = \\mu Z_t \\]\n\n        $Z_t$ is \\emph{not} a martingale because of the scaling factor $\\mu$.\n        \\[ \\mathbb{E}[Z_{t+1}|Z_t] \\neq Z_t \\]\n\n        However if we let\n        \\[ M_t = \\mu^{-t}Z_t \\]\n\n        Then $\\{M_t\\}$ is a martingale w.r.t. $\\{\\mathcal{F}_t\\}$\n\n        \\subsubsection{Polya's Urn}\n        Suppose we have an urn (buskets/bottles/whatever) containing two kinds of balls: black balls and white balls.\n        \n        Suppose we start from time $t=2$ (so that the urn contains $t$ balls at time $t$); suppose the urn has one black ball and one white ball at the beginning.\n        \n        Each time we draw a ball at random and replace it together with a ball of the same color.\n\n        Let $X_t$ be the number of white balls after time $t$. Let $Z_t = X_t/t$ be the ratio of white balls. We claim that $\\{Z_t\\}$ is a martingale.\n\n        \\begin{align*}\n            \\mathbb{E}\\left[Z_{t+1}|X_{(2,t)}\\right] &= \\frac{1}{t+1}\\mathbb{E}[X_{t+1}|X_{(2,t)}]\\\\\n            &= \\frac{1}{t+1}\\left(\\frac{X_t}{t}\\left(X_t+1\\right) + \\frac{t-X_t}{t}\\left(X_t\\right)\\right)\\\\\n            &= \\frac{1}{t+1}\\frac{X_t + tX_t}{t} = \\frac{X_t}{t} = Z_t\n        \\end{align*}\n\n        \\subsubsection{Likelihood Ratio}\n        Suppose we have a ``dataset'' $X_1,\\dots,X_t$ that has a (true) underlying pdf $f$; suppose we have a hypothesis (or estimation) $g$.\n\n        Let \n        \\[ M_t \\triangleq \\frac{g(X_1)\\cdot \\cdots \\cdot g(X_t)}{f(X_1)\\cdot \\cdots \\cdot f(X_t)} \\]\n\n        We claim that $\\{M_t\\}$ is a martingale.\n\n        \\begin{align*}\n            \\mathbb{E}[M_{t+1}|X_{(1,t)}] &= M_t\\cdot\\mathbb{E}\\left[\\frac{g(X_{t+1})}{f(X_{t+1})}|X_{(1,t)}\\right]\\\\\n            &= M_t \\cdot \\mathbb{E}\\left[\\frac{g(X_{t+1})}{f(X_{t+1})}\\right]\\\\\n            &= M_t \\int \\frac{g(x)}{f(x)}\\mathrm{d}x \\\\\n            &= M_t\n        \\end{align*}\n\n\n\\section{Stopping Time}\n    \\subsection{Introduction}\n        By definition \\ref{def:FancyMartingale},\n        \\[ \\forall t \\ge 0 \\quad \\mathbb{E}[Z_t] = \\mathbb{E}[Z_0] \\]\n\n        If $\\tau$ is a random variable, will the result still hold?\n        \\[\\mathbb{E}[Z_{\\tau}] \\questeq \\mathbb{E}[Z_0]\\]\n        Unfortunately the answer is no. But in some cases it does hold.\n\n    \\subsection{Stopping Time and Optional Stopping Theorem}\n        \\begin{definition}[Stopping Time]\\label{def:StoppingTime}\n            A random variable $\\tau \\in \\mathbb{N}$ is a \\textbf{stopping time} if\n            \\[ \\forall t \\in \\mathbb{N} \\quad [\\tau \\le t] \\text{ is $\\mathcal{F}_t$-measurable.} \\]\n        \\end{definition}\n        \\begin{remark}\n            The definition says that $\\tau$ is a stopping time with respect to a martingale $X_1,\\dots$ if for each integer $k$, the indicator r.v. $\\mathbb{I}[\\tau = k]$ is a function of $W_{(0,k)}$.\n\n            That is, $\\mathbb{I}[\\tau = k]$ can be determined by the values of $W_{(0,k)}$.\n        \\end{remark}\n\n        \\begin{theorem}[Optional Stopping Theorem]\\label{thm:OptionalStoppingTheorem}\n            Let $\\{X_t\\}$ be a matringale, let $\\tau$ be a stopping time w.r.t. $\\{\\mathcal{F}_t\\}$. Then $\\mathbb{E}[X_{\\tau}] = \\mathbb{E}[X_0]$ if \\emph{at least one of the following holds}.\n            \\begin{enumerate}\n                \\item $\\tau$ is bounded.\n                \\item $\\mathbb{P}[\\tau < \\infty] = 1$ and $\\exists M$ s.t. $|X_t| \\le M$ for all $t < \\tau$.\n                \\item $\\mathbb{E}[\\tau] < \\infty$ and $\\exists c$ s.t. $\\mathbb{E}[|X_{t+1} - X_{t}||\\mathcal{F}_t] \\le c$. (Expectation of $\\tau$ is bounded and the changing rate of $X_t$ can be bounded)\n            \\end{enumerate}\n        \\end{theorem}\n        \\begin{remark}\n            For super-martingale or sub-martingale, similar conclusions hold as well, $\\mathbb{E}[X_{\\tau}] < \\mathbb{E}[X_0]$ or $\\mathbb{E}[X_{\\tau}] > \\mathbb{E}[X_0]$.\n        \\end{remark}\n\n    \\subsection{Examples}\n        \\subsubsection{Birth Rate of Boys and Girls}\n            Suppose a politically incorrect village has a policy: Each family keep having children until they give birth to a boy. We examine the stopping time $\\tau$.\n\n            Let $X_t \\in \\{-1, 1\\}$ denote the gender of the child, and $1$ stands for boy and $-1$ stands for girl. Let $Z_t$ denote the difference in number of boys and girls.\n            \\[ Z_t = Z_{t-1} + X_t \\]\n\n            Obviously\n            \\[ \\mathbb{E}[\\tau] = 1/2 + 2 \\times 1/4 + \\cdots = \\sum_n \\frac{n}{2^n} < \\infty \\]\n            and the changing rate is obviously bounded, so the third condition of theorem \\ref{thm:OptionalStoppingTheorem} holds, and\n            \\[ \\mathbb{E}[Z_t] = \\mathbb{E}[Z_0] = 0 \\]\n\n            Although this policy seems 重男轻女, it actually does not break the balance of birth sex ratio.\n\n            However\\footnote{“我前段时间还在论坛上和别人对线”--Chihao}, if the village uses an even more politically incorrect policy: keep having children until the number of boys is larger than the number of girls by 1. i.e.\n            \\[ \\tau = \\min\\{n|Z_n=1\\} \\]\n            \n            Notice that if we model $X_t$ with the random walk on integers with probability $1/2$. Recall that this random walk is null recurrent so the hitting time of the null recurrent state $1$ is infinity $\\mathbb{E}[\\tau] = \\infty$. So the theorem cannot be applied.\n            \n            Actually\n            \\[ \\mathbb{E}[Z_t] = 1 \\]\n\n            Further, if the villagers are not extremely 头铁 and they will stop if they have 10 girls in a row without having a boy.\n            \\[ \\tau = \\min\\{\\min\\{n|Z_n=1\\}, 10\\} \\]\n            Then condition (3) of Theorem \\ref{thm:OptionalStoppingTheorem} holds again and $\\mathbb{E}[Z_t] = 0$.\n\n        \\subsubsection{Random Walk on Integers with Absorbing Barriers}\n            Consider a random walk $X_t \\in \\{-1, 1\\}$ on integers with two absorbing barriers at $-a$ and $b$. Let $Z_t$ be the position at $t$, let $\\tau$ be the r.v. denoting the time when we arrive at either $-a$ or $b$.\n            \\[ Z_{t+1} = Z_t + X_{t+1} \\]\n\n            Obviously $|Z_t| \\le M$, and obviously $\\mathbb{P}[\\tau < \\infty]=1$ because we have a positive probability to walk $(a+b)$ steps toward $b$ and thus we will always stop. So condition (2) of OST \\ref{thm:OptionalStoppingTheorem} holds.\n\n            \\[ \\mathbb{E}[Z_t] = \\mathbb{E}[Z_0] = 0 \\Rightarrow -aP_a + b(1-P_a) = 0 \\]\n\n            So $P_a = \\frac{b}{a+b}$ and $P_b = \\frac{a}{a+b}$.\n\n            And we proceed to compute the stopping time. Let\n            \\[ Y_t \\triangleq Z_t^2 - t \\]\n\n            We claim that $Y_t$ is a martingale.\n            \\begin{align*}\n                \\mathbb{E}[Y_{t+1}|\\mathcal{F}_t] &= \\mathbb{E}[Z_{t+1}^2 - (t+1)|\\mathcal{F}_t]\\\\\n                &= \\mathbb{E}[(Z_t + X_{t+1})^2 - (t+1) | \\mathcal{F}_t]\\\\\n                &= Z_t^2 + 2Z_t\\mathbb{E}[X_{t+1}] + \\mathbb{E}[X_{t+1}^2] - (t+1)\\\\\n                &= Z_t^2 - t = Y_t\n            \\end{align*}\n\n            It can be shown that $\\{Y_t\\}$ satisfies (3) of OST \\ref{thm:OptionalStoppingTheorem}. Therefore\n            \\[ \\mathbb{E}[Y_{\\tau}] = \\mathbb{E}[Y_0] = 0 \\]\n            And since\n            \\[ \\mathbb{E}[Y_{\\tau}] = \\mathbb{E}[Z_{\\tau}^2] - \\mathbb{E}[\\tau] = \\frac{a^2b}{a+b} + \\frac{b^2a}{a+b} + \\mathbb{E}[\\tau] \\]\n            We can solve for\n            \\[ \\mathbb{E}[\\tau] = ab \\]\n\n        \\subsubsection{Pattern Occurence}\n            Suppose we flip a fair coin, let $\\{X_t\\}$ be the sequence of results. \n            \n            Given a sequence $p = (p_1,p_2,\\dots,p_N) \\in \\{0,1\\}^N$, we want to know the expected throws before the pattern occurs (as a subsequence) in the result sequence.\n\n            Notice that the expectation depends on $p$. For example it is easier to get sequence $10$ than to get $11$. Because the probability of succeeding, given the previous flip is $1$, is equal, but\n            \\begin{itemize}\n                \\item For $11$, if we fail and get $0$ in the second flip (got $10$), we will have to start from the beginning.\n                \\item For $10$, if we fail and get $1$ in the second flip, (got $11$), we only need to start from the second bit.\n            \\end{itemize}\n\n            We construct a martingale, let $A_t$ be a person who joins a gambling at time $j$, and acts as follows\n            \\begin{itemize}\n                \\item Bet \\$1 on $X_t=p_1$.\n                \\item If win, bet \\$2 on $X_{t+1}=p_2$.\n                \\item If win, bet \\$4 on $X_{t+2}=p_3$.\n                \\item \\dots (doubles the bet each time)\n                \\item Whenever loses, quit the game.\n            \\end{itemize}\n\n            Let $j \\in \\{1, 2, \\dots, N\\}$, let $G_j(t)$ be the total money (can be negative) of person $A_j$ at time $t$. Obviously $G_j(t)$ is a martingale, because this is a fair gamble.\n\n            Let $Z(t) = \\sum_j G_j(t)$ be the total number of money in the game at time $t$. By linearity of expectation, $Z(t)$ is also a martingale.\n\n            Let $\\tau$ be the first time that pattern $p$ occurs in $\\{X_t\\}$.\n\n            It can be verified that $Z(t)$ satisfies (3) of OST \\ref{thm:OptionalStoppingTheorem}.\n            \\[ \\mathbb{E}[Z(\\tau)] = \\mathbb{E}[Z(1)] = 0 \\]\n\n            Now suppose the pattern occurs, we compute the expected money for each person $A_j$ (which is another way of computing the LHS).\n\n            All people before $\\tau - N$ have all lost the gamble (or otherwise the pattern would have appeared earlier than $\\tau$). If a person loses, the total money he has will be $-1$. \n\n            The person who joined the gamble at $t = \\tau-N$ kept winning until the very end\\footnote{“肯定赢麻了。”--Chihao}, and he will have earned\n            \\[ 1 + 2 + \\cdots + 2^{N-1} = 2^N-1 \\]\n\n            The situation of the remaining people depens on $p$. For the $l$-last person, he did not lose until the end if and only if the first $l$ bits he betted equals to the first $l$ bits of $p$, i.e. the last $l$ bits of $p$ equals to the first $l$ bits of $p$. To indicate this, let $\\chi_j$ denote whether $j$ winned money.\n            \\[ \\chi_j = \\mathbb{I}[p_{(1,j)} = p_{(N-j+1,N)}] \\]\n            where $N$ is the length of the pattern.\n\n            Therefore\n            \\[Z(\\tau) = -\\left(\\tau - \\sum_{j=1}^N \\chi_j\\right) + \\sum_{j=1}^N \\chi_j(2^j-1)\\]\n\n            Take expectations on both sides and solve for $\\mathbb{E}[\\tau]$\n            \\[\\mathbb{E}[\\tau] = \\sum_{j=1}^m\\chi_j \\cdot 2^j\\]\n\n            For a 4-bit pattern $0101$, $\\chi_1=0$, $\\chi_2 = 1$, $\\chi_3=0$, $\\chi_4=1$.\n\n\n\\section{Convergence of Non-negative Super-Martingales}\n    \\begin{proposition}\\label{prop:BoundOnSuperMartingale}\n        Let $\\{X_t\\}$ be a nonnegative super-martingale. Suppose $X_0 \\le a $, $\\forall b > a$, let\n        \\[ T_b \\triangleq \\inf\\{ X_t \\ge b \\} \\]\n        then\n        \\[ \\mathbb{P}[T_b < \\infty] \\le a/b \\]\n    \\end{proposition}\n\n    Intuitively, when we are playing a super-martingale starting with money $a$, and we will stop whenever we reach $b$ (if it ever happens), then the larger $b$ is, the less likely we are to reach $b$ within finite steps (because we are expected to lose money in a super-martingale).\n\n    \\begin{proof}\n        Let $T_b \\wedge t \\triangleq \\min\\{T_b, t\\}$. Since $T_b$ is not necessarily bounded, we cannot apply OST on $T_b$. However, for a fixed $t$, $T_b \\wedge t$ is bounded.\n\n        By OST \\ref{thm:OptionalStoppingTheorem}, for each non-negative $t$,\n        \\[ \\mathbb{E}[X_{T_b \\wedge t}] < \\mathbb{E}[X_0] \\le a \\]\n\n        Notice that\n        \\[ X_{T_b \\wedge t} = \\begin{cases}\n            X_t &\\quad T_b > t\\\\\n            b &\\quad T_b < t\n        \\end{cases} \\]\n\n        Therefore we can rewrite $X_{T_b \\wedge t}$ into\n        \\[ X_{T_b \\wedge t} \\ge b\\mathbb{I}[T_b \\le t] \\]\n\n        Take expectation on both sides\n        \\[ a \\ge \\mathbb{E}[X_{T_b \\wedge t}] \\ge b\\mathbb{P}[T_b \\le t] \\]\n\n        Since $t$ is arbitrary,\n        \\[ \\mathbb{P}[T_b < \\infty] \\le \\mathbb{P}[T_b \\le t] \\le a/b \\]\n    \\end{proof}\n\n    \\begin{theorem}[Convergence of Super-martingale]\\label{thm:ConvergenceOfSuperMartingale}\n        Any non-negative super-martingale converges with probability 1.\n    \\end{theorem}\n    \\begin{proof}\n        To prove the theorem, we only need to prove that it neither diverges nor oscillitates. Proving a non-negative super-martingale does not diverge is trivial, because it is lower-bounded. So we only prove that it does not have two sub-sequences that converges to different values.\n\n        The intuition is, since $b > a$, whenever the super-martingale jumps from $a$ to $b$, the probability is $a/b$, if the super-martingale oscillitates, then it would have to jump from $a$ to $b$ for infinitely many times, and this probability would be zero.\n\n        Formally, fix $a$ and $b$ s.t. $a < b$. Let $S_i$ denote the $i$-th time to reach $a$, and let $T_i$ denote the $i$-th time to reach $b$.\n        \\[ S_1 = \\inf\\{ t > T_0 | X_t = a \\} \\]\n        \\[ T_1 = \\inf\\{ t > S_1 | X_t = b \\} \\]\n        \\[ S_2 = \\inf\\{ t > T_1 | X_t = a \\} \\]\n        \n        $S_i$ and $T_i$ are not necessarily bounded, so OST cannot be directly applied. However, we can use the same trick and fix a upper bound: $\\forall n \\in \\mathbb{N}$, the OST implies that\n        \\[ \\mathbb{E}[X_{S_k \\wedge n}] > \\mathbb{E}[X_{T_k \\wedge n}] \\]\n\n        Notice that\n        \\[ X_{T_k \\wedge n} = \\begin{cases}\n            b &\\quad T_k \\le n\\\\\n            X_n &\\quad T_k > n\n        \\end{cases} \\]\n        Then\n        \\[ X_{T_k \\wedge n} = b\\mathbb{I}[T_k \\le n] + X_n\\mathbb{I}[T_k > n] \\]\n\n        Similarly\n        \\[ X_{S_k \\wedge n} = a\\mathbb{I}[S_k \\le n] + X_n \\mathbb{I}[S_k > n] \\]\n\n        Subtract the two equations,\n        \\[ X_{T_k \\wedge n} - X_{S_k \\wedge n} = b\\mathbb{I}[T_k \\le n] - a\\mathbb{I}[S_k \\le n] + X_n \\left( \\mathbb{I}[T_k > n] - \\mathbb{I}[S_k > n] \\right) \\]\n\n        Recall that by our definition, $S_k > T_k$ (if $S_k > n$, then $T_k >n$), so the latter term is non-negative and can thus be safely dropped.\n\n        \\[ X_{T_k \\wedge n} - X_{S_k \\wedge n} \\ge b\\mathbb{I}[T_k \\le n] - a\\mathbb{I}[S_k \\le n]  \\]\n\n        Take expectation on both sides,\n        \\[ \\mathbb{E}[X_{T_k \\wedge n} - X_{S_k \\wedge n}] \\ge b\\mathbb{P}[T_k \\le n] - a\\mathbb{P}[S_k \\le n] \\]\n\n        By result from the OST we know that $\\mathbb{E}[X_{S_k \\wedge n}] - \\mathbb{E}[X_{T_k \\wedge n}] > 0$. Therefore\n        \\[ \\mathbb{P}[T_k \\le n] < \\frac{a}{b}\\mathbb{P}[S_k \\le n] \\]\n\n        Since $n$ is arbitrary,\n        \\[ \\mathbb{P}[T_k < \\infty] < \\frac{a}{b}\\mathbb{P}[S_k < \\infty] < \\frac{a}{b}\\mathbb{P}[T_{k-1} < \\infty] \\]\n\n        So if $k \\to \\infty$, then $\\mathbb{P}[T_k < \\infty] \\to 0$, so the super-martingale cannot oscillitate.\n    \\end{proof}\n\n\n\\section{Stochastic Approximation}\n    Consider the problem of finding the root of $f(x)=0$. Usually, a binary search or the Newton's method can be applied. However, suppose we do not know what $f$ is, and we cannot observe the exact value of $f(x)$.\n\n    $f(x)$ is sealed in a black box with noise, given an input query $x$, what we get is $\\tilde{f}(x) + \\eta$, where $\\eta$ is some kind of random noise. Here we assume the noise has a Gaussian distribution with mean $0$ and variance $1$.\n\n    So we hope to find a sequence of input $\\{X_n\\}$ such that $X_n \\to x^*$ as $n \\to \\infty$. In the following we assume $f(x)<0$ for $x < x^*$ and $f(x)>0$ for $x>x^*$.\n\n    This problem can be solved using an iterative method. Let $X_n$ denote our $n$-th input, let $Y_n = f(X_n) + \\eta_n$ be the output we get. In each iteration we update the input by\n    \\[ X_{n+1} = X_n - a_nY_n \\]\n\n    The problem is to determine $\\{a_n\\}$. Firstly it is obvious that $a_n$ should converge to $0$, or otherwise, suppose $a_n \\to \\delta$, and suppose the solution is $X^* = 0$, then even if we have reached the solution $X_n$, the algorithm will still perform an update $X_{n+1} = -\\delta \\eta_n$, and we moves away from the answer.\n\n    \\begin{theorem}[Stochastic Approximation]\\label{thm:StochasticApproximation}\n        Let $f: \\mathbb{R} \\mapsto \\mathbb{R}$ be a real-valued function. Suppose $\\mathbb{E}[(X_0)^2] < \\infty$. Consider the sequence generated by\n        \\[ Y_n = f(X_n) + \\eta_n \\]\n        \\[ X_{n+1} = X_n - a_n Y_n \\]\n        where we assume the following conditions\n        \\begin{enumerate}\n            \\item $X_0$, $\\eta_1$, $\\eta_2$, \\dots, are independent, with $\\eta_i$ having mean $0$ and variance $1$.\n            \\item For some $1 < |c| < \\infty$, $|f(x)| \\le c|x|$ for all $x$. (Notice that this implies $f(0)=0$).\n            \\item $\\forall \\delta > 0$, $\\inf_{|x|>\\delta} xf(x) > 0$. ($f(x) < 0$ for $x < x^*$ and $f(x) > 0$ for $x>x^*$).\n            \\item Each $a_n$ is non-negative and $\\sum_n a_n = \\infty$. ($a_n$ cannot decrease too fast)\n            \\item $\\sum_n a_n^2 < \\infty$. ($a_n$ cannot decrease too slowly)\n        \\end{enumerate}\n\n        Then $X_n \\to 0$ as $n \\to \\infty$.\n    \\end{theorem}\n    \\begin{proof}\n        If we somehow proves that $X_n$ is a super-martingale, then by Theorem \\ref{thm:ConvergenceOfSuperMartingale}, we will be very close to success.\n\n        Consider $\\mathbb{E}[X_{n+1}^2 | X_{(0,n)}]$.\\footnote{“不要问我为什么，我们经过一番尝试发现$X_n$的期望不太对。”--Chihao}\n        \\begin{align*}\n            \\mathbb{E}[X_{n+1}^2|X_{(0,n)}] &= \\mathbb{E}[(X_n - a_n(f(X_n) + \\eta_n))^2 | X_{(0,n)}]\\\\\n            &= \\mathbb{E}[X_n^2|X_{(0,n)}] - \\mathbb{E}[2a_nX_n(f(X_n)+\\eta_n)|X_{(0,n)}] + \\mathbb{E}[a_n^2(f(X_n) + \\eta_n)^2|X_{(0,n)}]\\\\\n            &= X_n^2 - 2a_nX_nf(X_n) + a_n^2(f(X_n))^2 + a_n^2 \\quad \\text{($\\eta_n$ has zero mean)}\\\\\n            &\\le X_n^2 + a_n^2\\left(c^2 X_n^2 + 1\\right) \\quad \\text{(all terms are non-negative and Assumption 2)}\\\\\n            &\\le X_n^2 + a_n^2\\left(c^2 X_n^2 + c^2\\right) \\quad \\text{(Assumption 2: $c > 1$)}\\\\\n            &= \\left( 1 + a_n^2c^2 \\right)X_n^2 + a_n^2c^2\n        \\end{align*}\n        \n        define\n        \\[ W_n \\triangleq b_n(X_n^2 + 1) \\]\n        where\n        \\[ b_n = \\prod_{k=1}^{n-1}(1 + a_k^2 c^2)^{-1} \\]\n\n        It can be verified that $W_n$ is a super-martingale.\n        \\begin{align*}\n            \\mathbb{E}[W_{n+1}|X_{(0,1)}] &= b_{n+1}\\mathbb{E}[X_{n+1}^2|X_{(0,n)}] + b_{n+1}\\\\\n            &\\le b_{n+1}\\left( X_n^2 \\left( 1+a_n^2c^2 \\right) + a_n^2c^2 \\right) + b_{n+1}\\\\\n            &= b_{n+1}(1+a_n^2c^2)(X_n^2+1) = b_n(X_n^2+1) = W_n\n        \\end{align*}\n\n        So $W_n$ is a super-martingale and it will converge, by Theorem \\ref{thm:ConvergenceOfSuperMartingale}.\n\n        Recall that\n        \\[ W_n \\triangleq b_n(X_n^2 + 1) = \\frac{(X_n^2 + 1)}{\\prod_{k=1}^{n-1}(1 + a_k^2 c^2)} \\]\n        $\\sum_n a_n^2 < \\infty$ implies that the denominator also converges, and therefore $X_n^2$ converges.\n\n        We then show that $X_n^2 \\to 0$. Let $\\delta > 0$ and let $D \\triangleq \\{x:|x| > \\delta\\}$. To show $X_n^2 \\to 0$, it suffices to show that for any $m$, a ``bad event'' $B_m \\triangleq \\bigcap_{n \\ge m}^{\\infty} \\{X_n \\in D\\}$ has probability 0.\n\n        Suppose $m < n$.\n\n        By Assumption 3, $\\forall \\delta > 0$, $\\inf_{|x|>\\delta} xf(x) \\ge \\epsilon > 0$. Therefore\n        \\[ X_nf(X_n) \\ge \\epsilon\\mathbb{I}[X_n \\in D] \\ge \\epsilon\\mathbb{P}[B_m] \\]\n\n        Take expectation\n        \\[ \\mathbb{E}[X_nf(X_n)] \\ge \\epsilon\\mathbb{P}[X_n \\in D] \\]\n\n        Notice that in the previous derivation of $\\mathbb{E}[X_{n+1}^2|X_{(0,n)}]$, we dropped a term $- 2a_nX_nf(X_n)$, and if we add the term back,\n        \\[ \\mathbb{E}[X_{n+1}^2|X_{(0,n)}] \\le W_n - 2a_nb_{n+1}X_nf(X_n) \\]\n\n        Take expectations on both sides\n        \\[ \\mathbb{E}[W_{n+1}] < \\mathbb{E}[W_n] - 2a_nb_{n+1}\\mathbb{E}[X_nf(X_n)] \\]\n\n        Therefore\n        \\[ \\mathbb{E}[W_{n+1}] < \\mathbb{E}[W_n] -2a_nb_{n+1}\\epsilon\\mathbb{P}[B_m] \\]\n\n        Using this result iteratively,\n        \\[ \\mathbb{E}[W_{n+1}] < \\mathbb{E}[W_m] - 2\\epsilon\\sum_{k=m}^n a_nb_{n+1}\\mathbb{P}[B_m] \\]\n\n        So we have a upperbound for $\\mathbb{P}[B_m]$\n        \\[ \\mathbb{P}[B_m] \\le \\frac{\\mathbb{E}[W_m]}{2\\epsilon\\sum_{k=m}^na_nb_{n+1}} \\]\n\n        The denominator goes to infinity, and therefore $\\mathbb{P}[B_m]$ converges to 0, so we are done.\n    \\end{proof}", "meta": {"hexsha": "1109c1d761f6870841fd8fd6ab6d24ce439cbdfd", "size": 23399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/Martingale.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/Martingale.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/Martingale.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": 57.0707317073, "max_line_length": 333, "alphanum_fraction": 0.5801957349, "num_tokens": 8181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.8175744850834649, "lm_q1q2_score": 0.6865450629475808}}
{"text": "\\documentclass{article}\n\\usepackage{physics}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{amsmath}\n\\usepackage{mathtools}\n% Please add the following required packages to your document preamble:\n\\usepackage[table,xcdraw]{xcolor}\n% If you use beamer only pass \"xcolor=table\" option, i.e. \\documentclass[xcolor=table]{beamer}\n\\usepackage[normalem]{ulem}\n\\useunder{\\uline}{\\ul}{}\n\n\\author{Philip Renkert}\n\\date{6/15/2021}\n\n\\newcommand{\\defeq}{\\vcentcolon=}\n\n\\begin{document} \n\t\\section*{Coordinate System and Attitude Representation}\n\tTwo coordinate frames are employed to describe the state of the quadrotor:\n\t\\begin{itemize}\n\t\t\\item Earth Coordinate Frame ($o_e x_e y_e z_e$): The initial position of the quadrotor defines the origin $o_e$ of this coordinate frame.  The $0_e x_e$ axis points in a given fixed direction in the horizontal plane, the $o_e z_e$ axis points downward toward the earth's center, and the $o_e y_e$ axis is determined according to the right hand rule.  \n\t\t\\item Body Coordinate Frame ($o_b x_b y_b z_b$): This coordinate frame is attached to the quadrotor, and the quadrotor's center of gravity is chosen as its origin $o_b$. The $o_bx_b$ axis points in the nose direction as indicated in Figure~\\ref{fig:body_frame}.  The $o_b z_b$ axis points downward perpendicular to the $o_b x_b$ axis.  The $o_b y_b$ axis is determined from the right hand rule.  \n\t\\end{itemize}\n\t\n\tThe relationship between the two coordinate systems is depicted in Figure~\\ref{fig:coord_sys}.  A left superscript is used to indicate the frame to which a vector is relative, i.e. ${}^e \\mathbf{x}$ is a vector relative to the earth frame and ${}^b \\mathbf{x}$ is a vector relative to the body frame.  We must also define a standard basis with unit vectors $\\mathbf{e}_1 \\defeq \\left[1,0,0\\right]^\\top$, $\\mathbf{e}_2 \\defeq \\left[0,1,0\\right]^\\top$, and $\\mathbf{e}_3 \\defeq \\left[0,0,1\\right]^\\top$.  In the earth frame, the axes $o_e x_e$, $o_e y_e$, and $o_e z_e$ are expressed with $\\mathbf{e}_1$, $\\mathbf{e}_2$, and $\\mathbf{e}_3$ respectively. Body unit vectors $\\mathbf{b}_1 \\defeq o_b x_b$, $\\mathbf{b}_2 \\defeq o_b y_b$, and $\\mathbf{b}_3 \\defeq o_b z_b$ can be expressed relative to the body frame as ${}^b \\mathbf{b}_i = \\mathbf{e}_i$ and relative to the earth frame as ${}^e \\mathbf{b}_i$ for all $i \\in \\left\\{1,2,3\\right\\}$. \n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{minipage}[t]{0.48\\linewidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[height = \\linewidth]{3DCoordinateSystems.png}\n\t\t\t\\caption{Coordinate system representation}\n\t\t\t\\label{fig:coord_sys}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}[t]{0.48\\linewidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[height = \\linewidth]{BodyFrameDiagram.png}\n\t\t\t\\caption{Body frame coordinate system, top-down view}\n\t\t\t\\label{fig:body_frame}\n\t\t\\end{minipage}\n\t\\end{figure}\n\n\tThe aircraft's attitude will be expressed with Euler angles $\\psi$ (yaw angle), $\\theta$ (pitch angle), and $\\phi$ (roll angle).  The body orientation is achieved by three successive rotations about the $z$, $y$, and $x$ axes around a fixed point. Let the frame resulting from the first elemental rotation be $k$ with unit vectors $\\mathbf{k}_i$ and that of the second elemental rotation be $n$ with unit vectors $\\mathbf{n}_i$. Frame $k$ is achieved by a yaw rotation about the $\\mathbf{e}_3$ axis by $\\psi$. Frame $n$ is achieved by a pitch rotation about the $\\mathbf{k}_2$ axis by $\\theta$.  The final body frame is achieved by a roll rotation about the $\\mathbf{n}_1$ axis by $\\phi$.  The combined rotation can be expressed as the product of three rotation matrices.  Denote a rotation matrix that performs a change of basis from frame $a$ to frame $b$ (rotation of frame $a$ relative to fixed frame $b$) as $\\mathbf{R}_a^b$. The elemental rotation matrices are,\n\t\\begin{align}\n\t\t\\begin{split}\n\t\t\\mathbf{R}_z(\\psi) &= \n\t\t\\left(\n\t\t\\begin{array}{ccc}\n\t\t\t\\cos (\\psi ) & \\sin (\\psi ) & 0 \\\\\n\t\t\t-\\sin (\\psi ) & \\cos (\\psi ) & 0 \\\\\n\t\t\t0 & 0 & 1 \\\\\n\t\t\\end{array}\n\t\t\\right)\n\t\t\\\\\n\t\t\\mathbf{R}_y(\\theta) &= \n\t\t\\left(\n\t\t\\begin{array}{ccc}\n\t\t\t\\cos (\\theta ) & 0 & -\\sin (\\theta ) \\\\\n\t\t\t0 & 1 & 0 \\\\\n\t\t\t\\sin (\\theta ) & 0 & \\cos (\\theta ) \\\\\n\t\t\\end{array}\n\t\t\\right)\\\\\n\t\t\\mathbf{R}_x(\\phi) &= \n\t\t\\left(\n\t\t\\begin{array}{ccc}\n\t\t\t1 & 0 & 0 \\\\\t\n\t\t\t0 & \\cos (\\phi ) & \\sin (\\phi ) \\\\\n\t\t\t0 & -\\sin (\\phi ) & \\cos (\\phi ) \\\\\n\t\t\\end{array}\n\t\t\\right)\n\t\t\\end{split}\n\t\\end{align}\n\tThe combined rotation matrix that transforms a vector $\\mathbf{x}$ expressed in the earth frame ${}^e \\mathbf{x}$ into a vector expressed in the body frame ${}^b \\mathbf{x}$ is then,\n\t\\begin{equation}\n\t\t{}^b \\mathbf{x} = \\mathbf{R}_n^b \\mathbf{R}_k^n \\mathbf{R}_e^k\\left( {}^e \\mathbf{x}\\right) =\\mathbf{R}_e^b\\left( {}^e \\mathbf{x}\\right)\n\t\\end{equation}\n\tWhere $\\mathbf{R}_n^b = R_x(\\phi)$, $\\mathbf{R}_k^n = R_y(\\theta)$, and $\\mathbf{R}_e^k = R_z(\\psi)$.  Performing the matrix multiplication gives,\n\t\\begin{equation}\n\t\t\\mathbf{R}_e^b = \\left(\n\t\t\\begin{array}{ccc}\n\t\t\t\\text{c} (\\theta ) \\text{c} (\\psi ) & \\text{c} (\\theta ) \\text{s}  (\\psi ) & -\\text{s}  (\\theta ) \\\\\n\t\t\t\\text{s}  (\\theta ) \\text{c} (\\psi ) \\text{s}  (\\phi )-\\text{s}  (\\psi ) \\text{c} (\\phi ) & \\text{s}  (\\theta ) \\text{s}  (\\psi ) \\text{s}  (\\phi )+\\text{c} (\\psi ) \\text{c} (\\phi ) & \\text{c} (\\theta ) \\text{s}  (\\phi ) \\\\\n\t\t\t\\text{s}  (\\theta ) \\text{c} (\\psi ) \\text{c} (\\phi )+\\text{s}  (\\psi ) \\text{s}  (\\phi ) & \\text{s}  (\\theta ) \\text{s}  (\\psi ) \\text{c} (\\phi )-\\text{c} (\\psi ) \\text{s}  (\\phi ) & \\text{c} (\\theta ) \\text{c} (\\phi ) \\\\\n\t\t\\end{array}\n\t\t\\right)\n\t\\end{equation}\n\tWhere $\\text{c}()$ is an abbreviation of $\\cos()$ and $\\text{s}()$ is n abbreviation of $\\sin()$. \n\t\\section*{Rigid-body Kinematic Model}\n\t\tIn order to analyze the kinetics of the aircraft, we must first understand the relationship between the angular velocity of the body ${}^b\\mathbf{\\omega} = \\left[p,q, r\\right]^\\top$ and the  attitude rate $\\dot{\\mathbf{\\Theta}} = \\left[\\dot{\\phi}, \\dot{\\theta}, \\dot{\\psi}\\right]^\\top$. To do so, we'll the theorem involving the time derivative of rotation matrices from Zhao in \\cite{zhaoTimeDerivativeRotation2016} given in Equation~\\ref{eq:rot_matrix_derivative}.  \n\t\t\\begin{equation}\n\t\t\t\\dv{}{t}{\\mathbf{R}_b^e} = \\mathbf{R}_b^e \\left[{}^b \\mathbf{\\omega}\\right]_{\\cross}\n\t\t\t\\label{eq:rot_matrix_derivative}\n\t\t\\end{equation}\n\t\tWhere $\\left[\\cdot\\right]_{\\cross}$ is the skew symmetric operator used to convert a cross product of two vectors into a matrix-vector product.  Rearranging \\ref{eq:rot_matrix_derivative} gives,\n\t\t\\begin{equation}\n\t\t\t\\left[{}^b \\mathbf{\\omega}\\right]_{\\cross} = {\\mathbf{R}_b^e}^\\top \\dv{}{t}{\\mathbf{R}_b^e} = {\\mathbf{R}_e^b} \\dv{}{t}{\\mathbf{R}_b^e}\n\t\t\\end{equation}\n\t\tWe'll employ the chain rule to expand the derivative\n\t\t\\begin{equation}\n\t\t\t\\left[{}^b \\mathbf{\\omega}\\right]_{\\cross} = {\\mathbf{R}_b^e}^\\top \\dv{}{t}{\\mathbf{R}_b^e} = {\\mathbf{R}_e^b} \\left(\\dv{\\mathbf{R}_b^e}{\\phi}\\dot{\\phi} + \\dv{\\mathbf{R}_b^e}{\\theta}\\dot{\\theta} + \\dv{\\mathbf{R}_b^e}{\\psi}\\dot{\\psi}\\right)\n\t\t\\end{equation}\n\t\tWe'll simplify the expression to achieve a linear relationship between ${}^b \\mathbf{\\omega}$ and $\\dot{\\mathbf{\\Theta}}$.   \n\t\t\\begin{equation}\n\t\t\t{}^b\\mathbf{\\omega} = \n\t\t\t\\left(\n\t\t\t\\begin{array}{ccc}\n\t\t\t\t1 & 0 & -\\sin(\\theta) \\\\\t\n\t\t\t\t0 & \\cos (\\phi ) & \\cos(\\theta)\\sin (\\phi ) \\\\\n\t\t\t\t0 & -\\sin (\\phi ) & \\cos(\\theta)\\cos (\\phi ) \\\\\n\t\t\t\\end{array}\n\t\t\t\\right) \\dot{\\mathbf{\\Theta}} =\\vcentcolon \\mathbf{W}^{-1} \\dot{\\mathbf{\\Theta}}\n\t\t\\end{equation}\n\t\tTaking the inverse,\n\t\t\\begin{equation}\n\t\t\t\\dot{\\mathbf{\\Theta}} =\\mathbf{W}\\cdot{}^b\\mathbf{\\omega} = \\left(\n\t\t\t\\begin{array}{ccc}\n\t\t\t\t1 & \\tan (\\theta ) \\sin (\\phi ) & \\tan (\\theta ) \\cos (\\phi ) \\\\\n\t\t\t\t0 & \\cos (\\phi ) & -\\sin (\\phi ) \\\\\n\t\t\t\t0 & \\sin{\\phi}/\\cos{\\theta} & \\cos (\\phi ) / \\cos (\\theta ) \\\\\n\t\t\t\\end{array}\n\t\t\t\\right)\n\t\t\t{}^b\\mathbf{\\omega}\n\t\t\\end{equation}\n\t\tOur kinematic equations for the quadrotor body can finally be written.  Let $\\mathbf{p}$ represent the position of the quadrotor's center of gravity (i.e. $o_b$)  and $\\mathbf{v}$ represent the linear velocity.  \n\t\t\\begin{align}\n\t\t\t\\begin{split}\n\t\t\t\t{}^e \\dot{\\mathbf{p}} &= {}^e \\mathbf{v} \\\\\n\t\t\t\t\\dot{\\mathbf{\\Theta}} &= \\mathbf{W} \\cdot {}^b\\mathbf{\\omega}\n\t\t\t\\end{split}\n\t\t\t\\label{eq:kinematic_equations}\n\t\t\\end{align}\n\t\n\t\tNote: We can also work directly with rotation matrices instead of Euler angles if it makes for a better starting point.  \n\t\\section*{Rigid-body Dynamic Model}\n\t\\textit{Position Dynamic Model}:\n\tWith level propellers producing thrust parallel to $\\mathbf{b}_3$, the position dynamics are described by Equation~\\ref{eq:pos_dyn_1}:\n\t\\begin{equation}\n\t\t{}^e\\dot{\\mathbf{v}} = g \\mathbf{e}_3 - \\frac{f}{m}{}^e\\mathbf{b}_3\n\t\t\\label{eq:pos_dyn_1}\n\t\\end{equation}\n\twhere $g$ is the gravitational acceleration, $f$ is the combined thrust produced by the four propellers calculated in the control effectiveness model, and $m$ is the mass of the aircraft.  We can then use the rotation matrix $\\mathbf{R}_b^e$ to find ${}^e\\mathbf{b}_3$.  Since\n\t\\begin{equation}\n\t\t{}^e \\mathbf{v} =\\mathbf{R}_b^e \\cdot {}^b\\mathbf{v}\n\t\t\\label{eq:pos_dyn_2}\n\t\\end{equation}\n\twe have,\n\t\\begin{equation}\n\t\t{}^e\\dot{\\mathbf{v}} = g \\mathbf{e}_3 + \\frac{1}{m}\\mathbf{R}_b^e\\cdot{}^b\\mathbf{f}_3\n\t\t\\label{eq:pos_dyn_final}\n\t\\end{equation}\n\twhere ${}^b\\mathbf{f}_3 \\defeq -f\\mathbf{e}_3$.\n\t\\newline \\newline \\textit{Attitude Dynamic Model}:  We'll start with Euler's equation describing the rotation of a rigid body \\cite{ClassicalDynamicsParticles1965}: \n\t\\begin{equation}\n\t\t\\mathbf{J} \\cdot {}^b\\dot{\\mathbf{\\omega}} + {}^b\\mathbf{\\omega} \\cross \\mathbf{J}\\cdot{}^b\\mathbf{\\omega}= \\mathbf{M}\n\t\t\\label{eq:euler_eqn}\n\t\\end{equation}\n\tWhere $\\mathbf{J}$ is the inertia tensor relative to the body frame, ${}^b\\mathbf{\\omega}$ is the angular velocity defined above, and $\\mathbf{M}$ is the sum of the moments acting on the craft in the body frame.  For a simple quadrotor model, $\\mathbf{M}$ comes from two primary sources: moments generated by the propellers $\\mathbf{\\tau} = \\left[\\tau_x, \\tau_y, \\tau_z\\right]^\\top$ and the gyroscopic torques associated with the rotors $\\mathbf{G}_a = \\left[G_{a,x}, G_{a,y}, G_{a,z}\\right]$.  $\\mathbf{\\tau}$ is calculated in the control effectiveness model in the next section, as each of the moments is simply related to the square the rotor speed.\n\t\\begin{equation}\n\t\t\\mathbf{M} = \\mathbf{\\tau} + \\mathbf{G}_a\n\t\\end{equation}  \n\tThe gyroscopic torque of the $k_{th}$ rotor is found again by looking at the torque acting on the rotor in the rotating body frame,\n\t\\begin{equation}\n\t\t\\mathbf{G}_{a,k} = - \\left(\\dv{}{t}\\left({}^b \\mathbf{L}_k\\right) + {}^b\\mathbf{\\omega} \\cross {}^b \\mathbf{L}_k\\right)\n\t\t\\label{eq:gyro_torque}\n\t\\end{equation}\n\tWhere ${}^b \\mathbf{L}_k$ is the angular momentum contributed by rotor $k$ relative to the body frame. The quantity in parenthesis in the right-hand side of Equation~\\ref{eq:gyro_torque} represents the external moments in the body frame acting on rotor $k$ given the body's angular velocity ${}^b\\mathbf{\\omega}$.  $\\mathbf{G}_{a,k}$ is therefore the torque exerted on the body by rotor $k$. ${}^b \\mathbf{L}_k$ is simply the rotor's inertia about its central axis $J_r$ times its angular velocity vector in the body frame ${}^b \\mathbf{\\omega}_k$.\n\t\\begin{equation}\n\t\t{}^b \\mathbf{L}_k = J_r \\cdot {}^b \\mathbf{\\omega}_k = J_r\\left(-1^k\\right) \\tilde{\\omega}_k \\mathbf{e}_3\n\t\t\\label{eq:rotor_momentum}\n\t\\end{equation}\n\twhere $\\tilde{\\omega}_k$ is the unsigned angular speed of rotor $k$.  Note that $\\dv{}{t}\\left({}^b \\mathbf{L}_k\\right)$ is zero if we assume that $\\tilde{\\omega}_k$ is constant.  This allows us to write,\n\t\\begin{equation}\n\t\t\\mathbf{G}_{a,k} = - \\left({}^b\\mathbf{\\omega} \\cross {}^b \\mathbf{L}_k\\right) = {}^b \\mathbf{L}_k \\cross {}^b\\mathbf{\\omega}\n\t\t\\label{eq:rotor_gyro_torque_simple}\n\t\\end{equation}\n\tSubstituting \\ref{eq:rotor_momentum} into \\ref{eq:rotor_gyro_torque_simple} gives,\n\t\\begin{equation}\n\t\t\\mathbf{G}_{a,k} = J_r\\left(-1^k\\right) \\tilde{\\omega}_k \\mathbf{e}_3 \\cross {}^b\\mathbf{\\omega}\n\t\\end{equation}\n\tThe total gyroscopic torque is then,\n\t\\begin{equation}\n\t\t\\mathbf{G}_a = \\sum_{k=1}^{N_r}{\\mathbf{G}_{a,k}} = J_r\\left(\\mathbf{e}_3\\cross{}^b\\mathbf{\\omega}\\right)\\sum_{k=1}^{N_r}{\\left(-1^k\\right) \\tilde{\\omega}_k} = J_r\\left(\\sum_{k=1}^{N_r}{\\left(-1^k\\right) \\tilde{\\omega}_k}\\right)  \\left[\\mathbf{e}_3\\right]_{\\cross}{}^b\\mathbf{\\omega}\n\t\\end{equation}\n\tIt remains to calculate the inertia tensor. \n\t\\section*{Parametric Inertia Tensor}\n\t\tA dynamic model for design optimization must be parametrized by the design variables.  Because the inertial properties of the quadrotor will change depending on the motor, propeller, and battery design, the inertial tensor must be expressed as a function of these elements.  Most examples of quadrotor dynamics and simulation in the literature determine the inertia tensor  by 1) conducting physical experiments such as a bifilar pendulum \\cite{quanIntroductionMulticopterDesign2017} or 2) building a detailed CAD model of the system.  Though accurate, neither of these approaches can account for changes in the physical design and therefore aren't compatible with design optimization.  \n\t\t\\par We can, however, use a hybrid numerical and analytical approach.  First, the inertial tensor $\\mathbf{J}_{f}$ of the 'fixed' system (i.e. excluding the battery, motors, and propellers) is calculated via CAD or physical experiments. Then, the inertia matrix for each of the optimization components $\\mathbf{J}_{c,i}^{\\prime}$ is calculated analytically about the component's center of mass. Then, the generalized parallel axis theorem is used to calculate each components' inertia about the system's center of mass $\\mathbf{J}_{c,i}$.  The formula for the generalized parallel axis theorem is given in \\cite{ParallelAxisTheorem2021} as Equation~\\ref{eq:parallel_axis_theorem}:\n\t\t\\begin{equation}\n\t\t\t\\mathbf{J}_{c,i} = \\mathbf{J}_{c,i}^{\\prime} + m_{c,i}\\left(\\norm{\\mathbf{r}_{c,i}}^2 I_3 - \\mathbf{r}_{c,i} \\otimes \\mathbf{r}_{c,i} \\right)\n\t\t\t\\label{eq:parallel_axis_theorem}\n\t\t\\end{equation}\n\t\tFinally, the system inertia tensor $\\mathbf{J}$ is found by summing each individual inertia tensor:\n\t\t\\begin{equation}\n\t\t\\mathbf{J} = \\mathbf{J}_f + \\sum_{c,i}{\\mathbf{J}_{c,i}}\n\t\t\\label{eq:system_inertia_tensor}\n\t\t\\end{equation}\n\t\t\n\t\tFor now, we'll simplify Equations~\\ref{eq:parallel_axis_theorem} and~\\ref{eq:system_inertia_tensor} by assuming the motor and propeller are point masses at the end of each arm and the battery is a point mass at the system's center of gravity.  Though these assumptions make for a very rough approximation, they should capture the general trend of how design changes impact the real system's inertial properties.  Applying Equation~\\ref{eq:parallel_axis_theorem} to the rotors $r$ gives\n\t\t\\begin{equation}\n\t\t\t\\mathbf{J}_{r,k} = \\left(m_{\\text{prop}} + m_{\\text{motor}}\\right) \\left(\\norm{\\mathbf{r}_{r,k}}^2 I_3 - \\mathbf{r}_{r,k} \\otimes \\mathbf{r}_{r,k} \\right)\n\t\t\t\\label{eq:parallel_axis_theorem_rotor}\n\t\t\\end{equation}\n\t\tThe displacement from the system's center of mass to the rotors' center of mass $\\mathbf{r}_{r,k}$ is approximately\n\t\t\\begin{align}\n\t\t\\begin{split}\n\t\t\t\\mathbf{r}_{r,1} &= d\\frac{\\sqrt{2}}{2}\\begin{bmatrix} -1 & 1 & 0\\end{bmatrix}^\\top \\\\\n\t\t\t\\mathbf{r}_{r,2} &= d\\frac{\\sqrt{2}}{2}\\begin{bmatrix} 1 & 1 & 0\\end{bmatrix}^\\top \\\\\n\t\t\t\\mathbf{r}_{r,3} &= d\\frac{\\sqrt{2}}{2}\\begin{bmatrix} 1 & -1 & 0\\end{bmatrix}^\\top \\\\\n\t\t\t\\mathbf{r}_{r,4} &= d\\frac{\\sqrt{2}}{2}\\begin{bmatrix} -1 & -1 & 0\\end{bmatrix}^\\top\n\t\t\\end{split}\n\t\t\\end{align}\n\t\t\n\t\tWhere $d$ is the distance from the system's center of mass to that of the rotor as shown in Figure~\\ref{fig:body_frame}.  \n\t\tApplying Equation~\\ref{eq:parallel_axis_theorem_rotor} and summing over all four rotors gives the moments of inertia contributed by the rotors.\n\t\t\\begin{equation}\n\t\t\t\\mathbf{J}_r = \\sum_{k=1}^{4}{\\mathbf{J}_{r,k}} = \\left(m_{\\text{prop}} + m_{\\text{motor}}\\right)d^2\n\t\t\t\\begin{bmatrix}\n\t\t\t\t2 & 0 & 0 \\\\ 0 & 2 & 0 \\\\ 0 & 0 & 4\n\t\t\t\\end{bmatrix}\n\t\t\\end{equation}\n\t\tBy assuming the battery is a point mass at the system's center of mass, the battery's inertia $\\mathbf{J}_b = 0$. Therefore, we can write a simplified version of the system's inertia tensor in Equation~\\ref{eq:system_inertia_tensor} as,\n\t\t\\begin{equation}\n\t\t\t\\mathbf{J} = \\mathbf{J}_f + \\mathbf{J}_r\n\t\t\\end{equation}\n\t\tI'm currently working on a CAD model to calculate $\\mathbf{J}_f$, though I anticipate its contribution will be small relative to that of $\\mathbf{J}_r$.  \n\t\t\n\t\t\n\t\\section*{Combined Dynamic Model}\n\t\tEquations~\\ref{eq:kinematic_equations},~\\ref{eq:pos_dyn_final}, and~\\ref{eq:euler_eqn} can be combined to give a nonlinear model for the system's dynamics:\n\t\t\\begin{equation}\n\t\t\t\\begin{bmatrix} {}^e \\dot{\\mathbf{p}} \\\\ {}^e \\dot{\\mathbf{v}} \\\\ \\dot{\\mathbf{\\Theta}} \\\\ {}^b\\dot{\\mathbf{\\omega}} \\end{bmatrix}\n\t\t\t = \n\t\t\t \\begin{bmatrix}\n\t\t\t \t{}^e \\mathbf{v} \\\\\n\t\t\t \tg \\mathbf{e}_3 + \\frac{1}{m}\\mathbf{R}_b^e\\cdot{}^b\\mathbf{f}_3 \\\\\n\t\t\t \t\\mathbf{W} \\cdot {}^b\\mathbf{\\omega} \\\\\n\t\t\t \t\\mathbf{J}^{-1}\\left(-{}^b\\mathbf{\\omega} \\cross \\mathbf{J}\\cdot{}^b\\mathbf{\\omega} +  \\mathbf{\\tau} + \\mathbf{G}_a\\right)\n\t\t\t \\end{bmatrix}\n\t\t\\end{equation}\n\t\tRecall that the inputs to the dynamic model are $f$ and $\\mathbf{\\tau}$.  \n\t\\section*{Control Effectiveness Model (Thrusts/Torques)}\n\t\tIt remains to calculate $f$ and $\\mathbf{\\tau}$ as a function of the propeller speeds.  Let $C_T = k_T \\rho D^4$ be the lumped thrust coefficient and $C_Q = k_Q \\rho D^5$ be the lumped drag coefficient such that, for each propeller $k$, the thrust $T_k$ and torque $Q_k$ produced by each propeller is\n\t\t\\begin{align}\n\t\t\t\\begin{split}\n\t\t\t\tT_k &= C_T \\tilde{\\omega}_k^2 \\\\\n\t\t\t\tQ_k &= C_Q \\tilde{\\omega}_k^2\n\t\t\t\\end{split}\n\t\t\\end{align}\n\t\tThe combined thrust $f$ is simply the sum of the thrusts generated by each propeller\n\t\t\\begin{equation}\n\t\t\tf = C_T \\sum_{k=1}^{N_r}{ \\tilde{\\omega}_k^2}\n\t\t\t\\label{eq:combined_thrust}\n\t\t\\end{equation}\n\t\tSimilarly, the combined moment about the ${}^b \\mathbf{b}_3$ axis $\\tau_z$ is the sum of the torques generated by each propeller.  \n\t\t\\begin{equation}\n\t\t\t\\tau_z = C_Q \\sum_{k=1}^{N_r}{\\left(-1\\right)^{k-1} \\tilde{\\omega}_k^2}\n\t\t\\end{equation}\n\t\tWhere the alternating sign comes from the rotors' alternating directions.  To calculate $\\tau_x$ and $\\tau_y$, note from Figure~\\ref{fig:body_frame} that the moment arm of each propeller about the ${}^b \\mathbf{b}_1$ and ${}^b \\mathbf{b}_2$ axis is,\n\t\t\\begin{equation}\n\t\t\tl = d \\sin{45^\\circ} = \\frac{\\sqrt{2}}{2}d\n\t\t\\end{equation}\n\t\tTherefore,\n\t\t\\begin{align}\n\t\t\t\\begin{split}\n\t\t\t\t\\tau_x &= lC_T\\left(\\tilde{\\omega}_1^2 - \\tilde{\\omega}_2^2 - \\tilde{\\omega}_3^2 + \\tilde{\\omega}_4^2\\right)\\\\\n\t\t\t\t\\tau_y &=  lC_T\\left(\\tilde{\\omega}_1^2 + \\tilde{\\omega}_2^2 - \\tilde{\\omega}_3^2 - \\tilde{\\omega}_4^2\\right)\n\t\t\t\\end{split}\n\t\t\t\\label{eq:horizontal_torques}\n\t\t\\end{align}\n\t\tEquations~\\ref{eq:combined_thrust} - \\ref{eq:horizontal_torques} can be written in matrix form as,\n\t\t\\begin{equation}\n\t\t\t\\begin{bmatrix}f \\\\ \\tau_x \\\\ \\tau_y \\\\ \\tau_z \\end{bmatrix} = \n\t\t\t\\begin{bmatrix}\n\t\t\t\tC_T & C_T & C_T & C_T \\\\ \n\t\t\t\tlC_T & -lC_T & -lC_T & lC_T \\\\\n\t\t\t\tlC_T & lC_T & -lC_T & -lC_T \\\\\n\t\t\t\tC_Q & -C_Q & C_Q & -C_Q \\\\ \n\t\t\t\\end{bmatrix}\n\t\t\t\\begin{bmatrix} \\tilde{\\omega}_1^2 \\\\ \\tilde{\\omega}_2^2 \\\\ \\tilde{\\omega}_3^2 \\\\ \\tilde{\\omega}_4^2 \\end{bmatrix}\n\t\t\\end{equation}\n\t\n\t\\newpage\n\t\\bibliography{ARGReferences}\n\t\\bibliographystyle{plain}\n\\end{document}\n", "meta": {"hexsha": "4325dfa623e56ae7456a265fab6312d73f529a2d", "size": 19506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "COMPONENTS/BodyDynamicModel/BodyDynamicsEquations.tex", "max_stars_repo_name": "renkert2/QuadrotorOptimization", "max_stars_repo_head_hexsha": "152522c94f1b5b84772b43f5ccf58b8f9ee0dc13", "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": "COMPONENTS/BodyDynamicModel/BodyDynamicsEquations.tex", "max_issues_repo_name": "renkert2/QuadrotorOptimization", "max_issues_repo_head_hexsha": "152522c94f1b5b84772b43f5ccf58b8f9ee0dc13", "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": "COMPONENTS/BodyDynamicModel/BodyDynamicsEquations.tex", "max_forks_repo_name": "renkert2/QuadrotorOptimization", "max_forks_repo_head_hexsha": "152522c94f1b5b84772b43f5ccf58b8f9ee0dc13", "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": 67.9651567944, "max_line_length": 968, "alphanum_fraction": 0.6787142418, "num_tokens": 6898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.6865450562152737}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage[a4paper]{geometry} %page size\n\\usepackage{parskip} %no paragraph indentation\n\\usepackage{fancyhdr} %fancy stuff in page header\n\\pagestyle{fancy} \n\n\\usepackage[utf8]{inputenc} %encoding\n\\usepackage[danish]{babel} %danish letters\n\n\\usepackage{graphicx} %import pictures\n\\graphicspath{ {images/} }\n\\usepackage{listings} %make lists\n\n\\usepackage{amsmath, amssymb, amsfonts, amsthm, mathtools} %doing math\n\\usepackage{algorithmicx, algpseudocode} %doing pseudocode\n\n\\title{\n  Title\\\n  \\large Subtitle\n}\n\\author{Asger Andersen}\n\\date{\\today}\n\n\\fancyhead{}\n\\lhead{This is the title}\n\\rhead{Asger Andersen}\n\n%End of preamble\n%*******************************************************************************\n\n\\begin{document}\n\n\\section{Diagonalizable matrices}\n\nWe say that a $n\\times n$ matrix $A$ is diagonalizable, if and only if there exist an invertible matrix $P$, such that $P^{-1}AP$ is a diagonal matrix. This is equivalent to the sum of the dimensions of the eigenspaces of $A$ (in euivalent words: the sum of the geometric multiplicities of the eigenvalues of $A$) being equal to $n$. In that case, we can choose an eigenbasis $q_1,q_2,...,q_n$ for the space $A$ is operating on, and set $P$ to be the matrix with the chosen eigenbasis vectors as columns. Then $P^{-1}AP$ will be a diagonal matrix with the eigenvalues as columns.\n\nIf $A$ is hermetian (herunder symmetric), then $A$ is diagonalizable with an orthonormal eigenbasis. Additionally, all the eigenvalues of $A$ are real.\n\n\\section{Eigenvalues, eigenvectors and long term behaviour of homogeneous matrix systems}\n\nConsider the system \n\\begin{align}\nx_t = A^t x_0,\\qquad A\\in \\mathbb{R}^{n \\times n},\\qquad x_0 \\in \\mathbb{R}^n\n\\end{align}\nand assume that $A$ is diagonalizable. Let $\\lambda_1,...,\\lambda_n$ be the eigenvalues of $A$ (in this notation, some of them might be equal, if $A$ has one or more eigenvalues with eigenspace dimension larger than 1), and let $q_1,...,q_n$ be some corresponding eigenbasis of $\\mathbb{R}^n$. We can decompose $x_0$\n\\begin{align}\nx_0 = \\sum_i c_i q_i\n\\end{align}\nwhereby we easily get that\n\\begin{align}\nx_t = \\sum_i \\lambda_i^t c_i q_i\n\\end{align}\nAssume that $A$ has a dominant eigenvalue $\\lambda_j$ (that is, assume that one of the eigenvalues of $A$ are strictly larger in absolute value than all the other eigenvalues of $A$). Let $Q$ be eigenbasis vectors corresponding to $\\lambda_j$ (if $\\lambda_j$ has geometric multiplicity larger than 1, then there will be more than one vector in $Q$). In that case, we easily get that\n\\begin{align}\n\\frac{x_t}{\\lambda^t} \\to \\sum_{q_i \\in Q} c_i q_i, \\qquad t\\to \\infty\n\\end{align}\nIf $\\lambda_j$ has geometric multiplicity of 1, this simplifies to\n\\begin{align}\n\\frac{x_t}{\\lambda^t} \\to c_j q_j, \\qquad t\\to \\infty\n\\end{align}\nThis means that $\\lambda_j$ gives us the long term growth rate of each of the coordinates of $x_t$:\n\\begin{align}\n\\forall k \\in \\{1,...,n\\}:\\quad \\frac{(x_{t+1})_k}{(x_{t})_k} \\to \\lambda_j, \\quad t\\to \\infty\n\\end{align}\nand we can also calculate the long term ratio of the coordinates of $x_t$:\n\\begin{align}\n\\forall k,l \\in \\{1,...,n\\}:\\quad \\frac{(x_{t})_k}{(x_{t})_l} \\to \\frac{ \\sum_{q_i \\in Q} c_i (q_i)_k}{ \\sum_{q_i \\in Q} c_i (q_i)_l}, \\quad t\\to \\infty\n\\end{align}\nIf $\\lambda_j$ has geometric multiplicity of 1, this simplifies to\n\\begin{align}\n\\forall k,l \\in \\{1,...,n\\}:\\quad \\frac{(x_{t})_k}{(x_{t})_l} \\to \\frac{ (q_i)_k}{ (q_i)_l}, \\quad t\\to \\infty\n\\end{align}\n\n\\subsection{Eigenvalues and equilibriums of homogeneous matrix system}\n\nA point $x\\in \\mathbb{R}^n$ is an equilibrium of the system, if and only if\n\\begin{align}\nx = Ax\n\\end{align}\nIt is clear that the zero vector is an equilibrium of any matrix system. It is also clear that the zero vector is a locally stable equilibrium, if and only the dominant eigenvalue $\\lambda_j$ is numerically strictly smaller than 1. This is because the dominant eigenvalue is the growth rate that the system tends to over time, and if this growth value is numerically strictly larger than 1, then any other starting point than the zero vector will grow exponentially to infinity. If the dominant eigenvalue and thereby the long term growth rate is equal to 1, then the system has infinitely many equilibriums, namely all the points in the eigenspace of 1. Let $x_0$ be the starting vector, and let it be decomposable in the eigenbasis as\n\\begin{align}\nx_0 = \\sum_i c_i q_i\n\\end{align}\nand let $Q$ be the eigenvectors corresponding to the dominant eigenvalue 1. Then $x_t$ will converge to the equilibrium\n\\begin{align}\nx_t \\to \\sum_{q_i \\in Q} c_i q_i, \\qquad t\\to \\infty\n\\end{align}\nIf the dominant eigenvalue $\\lambda_j = 1$ has geometric multiplicity of 1, this simplifies to\n\\begin{align}\nx_t \\to c_j q_j, \\qquad t\\to \\infty\n\\end{align}\n\n\\subsection{Perron-Frobenius' theorem \\& long-term behaviour of positive, real matrices (hereunder transition matrices)}\n\nDefine an $n\\times n$ (not necessarily or even real) matrix $A$ to be irreducible, if and only if for all $i,j \\in \\{1,...,n\\}$ there exists a $t \\in \\mathbb{N}$ such that $A^t_{ij}\\neq 0$. (This correponds to the graph of $A$ being strongly connected). It is clear that all matrices with no 0 entries (hereunder all positive matrices) are trivially irreducible.\n\nDefine the spectral radius of any square matrix to be the largest absolut value of any of its eigenvalues.\n\nPerron-Frobenius theorem can be stated with weaker consequences for irreducible matrices in general. Here, I will just state it for non-negative, irreducible matrices. \n\nLet $A$ be a non-negative, irreducible matrix $A$ with spectral radius $r$. Then we have that \n\\begin{itemize}\n\\item $r$ is strictly positive, and is the dominant eigenvalue of $A$.\n\\item $r$ is a simple eigenvalue, meaning that its eigenspace only has 1 dimension.\n\\item There exists an eigenvector $q$ with only strictly positive entries in the eigenspace of $r$\n\\item $\\frac{1}{\\lambda^t} A^t \\to C, t\\to \\infty$ where all the columns of $C$ are multiplums of $q$.\n\\end{itemize}\nAll in all, this means that we can understand the long term behaviour of matrix systems defined by non-negative, irreducible matrices by just looking at their eigenvalues\n\nFor transition matrices we also know that if they are irreducible, then they have a dominant eigenvalue of $1$, meaning that they have infinitely many equilibriums (all the points in the 1-dimensional eigenspace of 1), and that for each starting vector $x_0$, then\n\\begin{align}\nx_t \\to cq,\\qquad t\\to \\infty\n\\end{align}\nwhere $q$ is some eigenvector in the eigenspace of 1, and $c$ is the proportion of $q$ in $x_0$ in the decomposition of $x_0$ in some basis with $q$ in it. If we pick the eigenvector $q$ be demanding that its coordinates be non-negative and sum to 1, and also only considers starting vectors $x_0$ satisfying the same conditions, then we get that $c=1$ for all $x_0$. Therefore, we get that \n\\begin{align}\nx_t \\to q,\\qquad t\\to \\infty\n\\end{align}\nThis tells us that irreducible transition matrices has a unique probability distribution $q$ that all other probability distributions $x_0$ converge to over time.\n\nActually, THIS IS WRONG, since a markov chain also has to be aperiodic to converge. Therefore, I think that I have stated the Perron-Frobenius too liberally. We need to assume that there exists a natural number $t$ such that $A^t$ is strictly positive (all the entries need to be simultaniously strictly positive). I think this would correspond to the markov chain being both irreducible and aperiodic.\n\n\\section{Long term behaviour of inhomogeneous linear systems}\n\nLet a system be defined by\n\\begin{align}\nx_{t+1} = Ax_t + b, \\qquad x_0\\in \\mathbb{R}\n\\end{align}\nAn equilibrium of the system is any vector that satisfies\n\\begin{align}\nx^* = Ax^* + b\n\\end{align}\n\nBy simple matrix calculations, we get that the system has an equilibrium $x^*$, if and only the matrix $(A - I)$ is invertible. In that case, the system has the unique equilibrium\n\\begin{align}\nx^* = -(A-I)^{-1}b\n\\end{align}\nThis equilibrium is stable, if and only if all the eigenvalues of $A$ is strictly less than 1.\n\n\\section{Interpretation}\n\nWe can think about a real $n \\times n$ matrix $A$ as a real weighted graph with $n$ nodes enumerated from $1,...,n$, where there is a link with weight $a_{ij}$ from node $j$ to node $i$, if and only if $A_{ij} = a_{ij}$. This corresponds to the transposed matrix $A^T$ being the weighted adjencency matrix of this graph. Hereby, we can think of any vector $x_0\\in \\mathbb{R}^n$ as a configuration of the nodes, and we can think of the vector $Ax_0 \\in \\mathbb{R}^n$ as the configuration, we would get by letting $x_0$ follow the weighted flow given by the graph. For any $t \\in \\mathbb{N}_0$, we therefore have that $A^t x_0$ can be interpreted as the configuration, we would get by starting with the configuration $x_0$ and then following $t$ steps of the weighted flow. This is exactly the same as $x_t$ in the particular solution to the homogeneous, linear system of difference equations\n\\begin{align}\n\\forall t\\in \\mathbb{N}_0: \\quad x_t =  Ax_{t-1}, \\quad x_t \\in \\mathbb{R}^n\n\\end{align}\nwith the starting condition $x_0\\in \\mathbb{R}$.\n\nAll in all, we can think of the set of all real $n \\times n$ matrices, the set of real, homogeneous, linear systems of difference equations with $n$ equations, and the set of real weighted graphs with $n$ enumerated nodes as being in one-to-one correspondence with each other. \n\nMy goal is to interpret eigenvalues, spaces and vectors in the context of these to interpretations of matrices. Also inhomogeneous systems (these can be thought of as arrows comming from nowhere in the graph). And equilibriums and maybe also concepts from network analysis. For instance: communities. Can we think of this concept in terms of some long term dynamics on the network, for instance that diffusion collects the diffused quantity within these communities? Then maybe eigenvalues/vectors can be used to say something about them, since these objects says something about the long term behaviour of the matrix model.\n\nApplied examples: Markov chains. Population dynamics. Wealth dynamics (so we both can have positive and negative numbers in oppose to the other examples).\n\n\\end{document}", "meta": {"hexsha": "6c78cb21f50b1f6c2859b3b1ed55330781137de7", "size": 10305, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exam/lin_alg.tex", "max_stars_repo_name": "AsgerAndersen/bio_modelling_course", "max_stars_repo_head_hexsha": "99d46d00f6ca3824bc50784529ae3753dfdfdee1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Exam/lin_alg.tex", "max_issues_repo_name": "AsgerAndersen/bio_modelling_course", "max_issues_repo_head_hexsha": "99d46d00f6ca3824bc50784529ae3753dfdfdee1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exam/lin_alg.tex", "max_forks_repo_name": "AsgerAndersen/bio_modelling_course", "max_forks_repo_head_hexsha": "99d46d00f6ca3824bc50784529ae3753dfdfdee1", "max_forks_repo_licenses": ["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.9155844156, "max_line_length": 890, "alphanum_fraction": 0.7458515284, "num_tokens": 2955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038221, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.686545054575701}}
{"text": "\\chapter{List of Symbols}\n% chapter List of Symbols\n\n\\begin{tabular}{l l}\n  $M_n(\\mathbb{R})$  & set of $n \\times n$ matrices over $\\mathbb{R}$ \\\\\n  $\\mathbb{Z}_n^*$   & set of integers modulo $n$; each element has its multiplicative inverse \\\\\n  $S_n$              & symmetry group of degree $n$ \\\\\n  $D_{2n}$           & dihedral group of degree $n$; a subset of $S_n$ \\\\\n  $K_n$              & Klein $n$-group \\\\\n  $A_n$              & alternating group of degree $n$; a subset of $S_n$ \\\\\n  $F[x]$             & polynomial ring over a field $F$ \\\\\n  $\\abs{D_{2n}}$     & order of the dihedral group; the size of the dihedral group \\\\\n  $\\begin{pmatrix} 1 & 2 & \\hdots & n \\end{pmatrix}$ & An $n$-cycle \\\\\n  $\\det A$           & determinant of matrix $A$ \\\\\n  $GL_n(\\mathbb{R})$ & \\tworow{l}{general linear group of degree $n$;}{the set that contains elements of $M_n(\\mathbb{R})$ with non-zero determinant} \\\\\n  $SL_n(\\mathbb{R})$ & \\tworow{l}{special linear group of order $n$;}{the set that contains elements of $GL_n(\\mathbb{R})$ with determinant of $1$} \\\\\n  $Z(G)$             & center of group $G$ \\\\\n  $\\lra{g}$          & cyclic group with generator $g$; principal ideal with generator $g$ \\\\\n  $\\lra{h(x)}$       & principal ideal with generator $h(x) \\in F[x]$ \\\\\n  $n \\mid d$         & $n$ divides $d$ \\\\\n  $H \\leq G$         & $H$ is a subgroup of $G$ (used sparsely in this notebook) \\\\\n  $H \\triangleleft G$& $H$ is a normal subgroup of $G$ \\\\\n  $\\faktor{G}{H}$    & quotient group of $G$ by $H \\triangleleft G$ \\\\\n  $\\ker \\alpha$      & kernel of $\\alpha$ \\\\\n  $\\img \\alpha$      & image of $\\alpha$ \\\\\n  $G^{(m)}$          & group of elements of $G$ with order $m$ \\\\\n  $\\ch(R)$           & characteristic of the ring $R$ \\\\\n  $\\gcd(a, b)$       & the greatest common divisor of $a$ and $b$ \\\\\n  $\\con(f)$          & the content of the polynomial $f(x)$\n\\end{tabular}\n\n% chapter List of Symbols (end)\n", "meta": {"hexsha": "0a7831b1e0bfef5df108d19dd0fc8543bbd40fa0", "size": 1921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PMATH347S18/list_of_symbols.tex", "max_stars_repo_name": "japorized/TeX_notes", "max_stars_repo_head_hexsha": "5814c8682addc5dd6f9a323758f87e4c4ca57b8e", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-09-28T21:23:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-21T01:41:27.000Z", "max_issues_repo_path": "PMATH347S18/list_of_symbols.tex", "max_issues_repo_name": "japorized/TeX_notes", "max_issues_repo_head_hexsha": "5814c8682addc5dd6f9a323758f87e4c4ca57b8e", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-29T17:58:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-29T17:58:51.000Z", "max_forks_repo_path": "PMATH347S18/list_of_symbols.tex", "max_forks_repo_name": "japorized/TeX_notes", "max_forks_repo_head_hexsha": "5814c8682addc5dd6f9a323758f87e4c4ca57b8e", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-09-27T20:55:58.000Z", "max_forks_repo_forks_event_max_datetime": "2017-09-27T20:55:58.000Z", "avg_line_length": 58.2121212121, "max_line_length": 152, "alphanum_fraction": 0.5585632483, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.686545046604537}}
{"text": "\n\\chapter{Three Important Probability Distributions}\n\n\\section{Important/Useful Theorems}\n\n\\subsection{The Binomial Distribution}\nFor $n$ trials where the probability of success is $p$ and the probability of failure is $q=1-p$, the probability of their being $k$ successes is:\n\\begin{equation}\n\tp(k) = \\binom{n}{k} p^k q^{n-k}\n\\end{equation}\n\n\\subsection{The Poisson Distribution}\nFor $n$ trials where the probability of success is $p$ and is very small and the number of trials is very large, the probability of their being $k$ successes is:\n\\begin{equation}\n\tp(k) = \\frac{a^k}{k!}e^{-a}\n\\end{equation}\nWhere $a=np$, the average number of successes.\n\n\\subsection{The Normal Distribution}\nAs $n \\rightarrow \\infty$, the Binomial Distribution goes to:\n\\begin{equation}\n\tp(x) = \\frac{1}{\\sqrt{2 \\piu \\sigma^2}}e^{\\frac{-(x-a)^2}{2 \\sigma^2}}\n\\end{equation}\n\n\n\\section{Answers to Problems}\n\n\n\\subsection{}\n%problem5.1\nIf you call tails, there are two possibilities for the outcome of the coin-toss experiment which, since they are not correlated to your guess, are both one-half; similarly for heads.  Therefore, no matter what you do, the probability of guessing correctly is one-half.\n\nIf, however, the coin is biased towards heads, there is a probability greater than one half that you'll win the trial if you call heads; therefore you should always call heads for a coin biased towards heads and similarly always call tails for a coin biased towards tails.\n\n\\end{equation}\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem5.2\n\nIn order to avoid any blatant sexism, we shall define  ``success'' as having a boy... What?  Anyway, for a couple having $n$ children, the probability of having $k$ boys will clearly follow a binomial distribution:\n\n\\begin{equation}\n\tp_n(k) = \\binom{n}{k} \\frac{1}{2^n}\n\\end{equation}\n\\subsubsection{a}\n\\begin{equation}\n\tp_{10}(5) = \\binom{10}{5} \\frac{1}{2^{10}} = \\frac{63}{256} = 0.246094\n\\end{equation}\n\\subsubsection{b}\n\\begin{equation}\n\tp_{10}(3\\rightarrow 7) = \\sum_{i = 3}^7 \\binom{10}{i} \\frac{1}{2^{10}} = \\frac{57}{64} = 0.890625\n\\end{equation}\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem5.3\n\nSince $p=.001$ and $n=5000$ we can cautiously use the Poisson Distribution where $a=5$.  Since we want to know the probability of hitting 2 or more, we will take the probability of hitting either 0 or 1 and subtract from 1.\n\n\\begin{equation}\n\tp(k \\geq 2) = 1 - p(0) - p(1) \\approx 1 - \\frac{5^0}{0!}e^{-5} - \\frac{5^1}{1!}e^{-5} = 1 - 6e^{-5} \\approx 0.96\n\\end{equation}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem5.4\n\nAgain we cautiously use the Poisson Distribution since $p=\\frac{1}{500}$ and $n=500$ and again use the same trick as before to get the chance of greater than two ``successes''.\n\\begin{equation}\n\tp(k \\geq 2) = 1 - p(0) - p(1) \\approx 1 - \\frac{1^0}{0!}e^{-1} - \\frac{1^1}{1!}e^{-1} = 1 - \\frac{2}{e} \\approx 0.264241\n\\end{equation}\nNote that the book has most definitely got this problem wrong as:\n\\begin{equation}\n\tp(k \\geq 3) = 1 - p(0) - p(1) - p(2) \\approx 1 - \\frac{1^0}{0!}e^{-1} - \\frac{1^1}{1!}e^{-1}- \\frac{1^2}{2!}e^{-1} = 1 - \\frac{5}{2e} \\approx .0803\n\\end{equation}\n\n\\textbf{Answer verified-ish}\n\n\n\\subsection{}\n%problem5.5\n\nWithout any special cases, this problem is the good-old binomial distribution:\n\n\\begin{equation}\n\tp(k) = \\binom{n}{k} p^k(1-p)^{n-k}\n\\end{equation}\nSo we simply sum up all the even probabilities:\n\\begin{equation}\n\tP_n = \\sum_{i=0}^{\\frac{n}{2}} p(2i) = \\sum_{i=0}^{\\frac{n}{2}} \\binom{n}{2i} p^{2i}(1-p)^{2i-k}\n\\end{equation}\nWhich in the total lack of any skill in mathematics, I plug into Mathematica to get:\n\\begin{equation}\n\tP_n = \\frac{1}{2} \\left((1-2 p)^n+1\\right)\n\\end{equation}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem5.6\nIn an infinite series of Bernouli trials, let the event that the $i^{th}$ 3-tuple has the pattern SFS be $A_i$ and $P(A_i)=p_i$.  Since we've designed these tuples to not overlap, these trials are independent such that:\n\\begin{equation}\n\tP\\left( \\bigcup_{i=1}^{\\infty} A_i \\right) = \\sum _{i=1}^{\\infty} p_i \\rightarrow \\infty\n\\end{equation}\nBy the second Borel-Cantelli lemma.\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem5.7\n\nWE want the probability of 3 or more very rare events happening in a large number of trials: this is a Poisson distribution with $a=1000\\cdot0.001=1$\n\\begin{equation}\n\tp(k \\geq 3) = 1 - p(0) - p(1) - p(2) \\approx 1 - \\frac{1^0}{0!}e^{-1} - \\frac{1^1}{1!}e^{-1}- \\frac{1^2}{2!}e^{-1} = 1 - \\frac{5}{2e} \\approx .0803\n\\end{equation}\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem5.8\n\nWe'll go ahead and call $p=\\frac{1}{365}$ to be small and 730 to be big so that we can do Poisson with $a=2$.\n\\begin{equation}\n\tp(2) = \\frac{2^2}{2!}e^{-2} = \\frac{2}{e^2} \\approx 0.270671\n\\end{equation}\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem5.9\n\n\\begin{equation}\n\t\\textbf{E}\\xi = \\sum_{k=0}^{\\infty} k \\frac{a^k}{k!}e^{-a} = e^{-a}a\\sum_{k=0}^{\\infty} \\frac{a^{(k-1)}}{(k-1)!} = a\n\\end{equation}\n\\begin{equation}\n\t\\textbf{E}\\xi^2 = \\sum_{k=0}^{\\infty} k^2 \\frac{a^k}{k!}e^{-a} = a^2 + a\n\\end{equation}\nThat last one I got lazy and used Mathematica, sorry!  Clearly, though $\\sigma^2 = a$.\n\\begin{eqnarray}\n\t\\frac{\\textbf{E}(\\xi - a)^3}{\\sigma^3} = \\frac{\\textbf{E}(\\xi^3 - 3\\xi^2a + 3\\xia^2 - a^3)}{a^{\\frac{3}{2}}} \\\\\n\t \\textbf{E}\\xi^3 = a^3+3 a^2+a \\\\\n\t \\textbf{E}(\\xi^3 - 3\\xi^2a + 3\\xi a^2 - a^3) = (a^3+3 a^2+a) - 3a(a^2 + a) + 3a^3 - a^3 = a \\\\\n\t \\frac{\\textbf{E}(\\xi - a)^3}{\\sigma^3} = \\frac{a}{a^{\\frac{3}{2}}} = \\frac{1}{\\sqrt{a}}\n\\end{eqnarray}\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem5.10\n\n\\textbf{SKIPPED}\n\n\\subsection{}\n%problem5.11\nFinally! something other than the Poisson distribution... back to... NORMAL!  Ha!\n\\begin{eqnarray}\n\t\\textbf{E}x = np = 30 \\\\\n\t\\textbf{D}x = npq = 30\\cdot .7 = 21 \\\\\n\tp = \\int_{20}^{40} \\frac{1}{\\sqrt{2 \\pi 21}} e^{\\frac{-(x-30)^2}{2 \\cdot 21}} \\approx 0.970904\n\\end{eqnarray}\n\\textbf{Answer verified}\n\n\n\\subsection{}\n%problem5.12\nWe want to know at one $n$ does this integral\n\\begin{eqnarray}\n\t\\int_{.3}^{.5} \\frac{1}{\\sqrt{2 \\pi .24/n}} e^{\\frac{-(x-.4)^2}{2 \\cdot .24/n}} \\approx 0.9\n\\end{eqnarray}\nA first pass going at intervals of 10 identifies the number being between 60 and 70 and a further pass going by one reveals that going from 64 to 65 breaks the .89 barrier.  Therefore $n=65$.\n\nNote that in order to get that $n$ in the denominator, we are taking the relative mean and the relative standard deviation: since both quantities get divided by $n$, the square of the standard deviation ends up with an $n$ in the denominator.\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem5.13\n\n\\begin{eqnarray}\n\t\\textbf{E}x = 60 \\cdot .6 = 36 \\\\\n\t\\textbf{D}x = 36 \\cdot .4 = 14.4 \\\\\n\tp = \\int_{30}^{\\infty} \\frac{1}{\\sqrt{2 \\pi 14.5}} e^{\\frac{-(x-36)^2}{2 \\cdot 14.4}} \\approx 0.943077\n\\end{eqnarray}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem5.14\nPerform the integrals as suggested.  Why can you?  Well, it feels right, doesn't it?  I found it impossible to come up with other than an intuitive reason for why this is true: sorry dear reader.\n\n\\textbf{Answer verified-ish}\n\n\\subsection{}\n%problem5.15\n\n\\textbf{SKIPPED}\n\n\n\\subsection{}\n%problem5.16\nConvolute the two distributions and the intended expression will come out: BOM!\n\n\\textbf{Answer verified-ish}\n\n%%answer template\n%\\subsection{}\n%%problem n.n\n%\n%\n%\\begin{equation}\n%\t\n%\\label{answern.n}\n%\\end{equation}\n%\\textbf{Answer [not] verified}\n\n\n\n\n\n", "meta": {"hexsha": "33bf55115dd349877552582ad0f32c769ba7c759", "size": 7453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter5.tex", "max_stars_repo_name": "stefk/Rozanov_ptcc_solutions", "max_stars_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter5.tex", "max_issues_repo_name": "stefk/Rozanov_ptcc_solutions", "max_issues_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter5.tex", "max_forks_repo_name": "stefk/Rozanov_ptcc_solutions", "max_forks_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5720720721, "max_line_length": 272, "alphanum_fraction": 0.6770428016, "num_tokens": 2692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.6865450463778384}}
{"text": "\\chapter{The statistics of inverse modeling}\n\\section{Definition of the system}\n\nThe discrete-time state-space formulation of a nonlinear dynamic system\nis\\footnote{Refer to Table~\\ref{tab:definition-of-terms} for the meaning of the\nsymbols used herein.}:\n\n\\begin{equation}\\label{eq:true-state}\nx_{t+1}=f(x_t,u_t,\\boldsymbol\\theta)\n\\end{equation}\n\\begin{equation}\\label{eq:true-output}\ny_{t+1}=h(x_{t+1},\\boldsymbol\\phi)\n\\end{equation}\nTo keep notation as simple as possible, we consider a system in which the state,\nthe forcing and the output at any given time can be represented as scalars.\nFurther note that the `state' of the system at a given time can include history.\nSince it is generally impossible to observe the true state, the true forcing,\nand the true output of a system, we have to make do with the observed state,\nobserved forcing, and the observed output instead:\n\n\\begin{equation}\\label{eq:observed-state}\n\\tilde{x}_{t+1}=x_{t+1} + \\omega_{t+1}\n\\end{equation}\n\\begin{equation}\\label{eq:observed-forcing}\n\\tilde{u}_{t+1}=u_{t+1} + \\psi_{t+1}\n\\end{equation}\n\\begin{equation}\\label{eq:observed-output}\n\\tilde{y}_{t+1}=y_{t+1} + \\nu_{t+1}\n\\end{equation}\nNote that Eqs.~\\ref{eq:observed-state}--\\ref{eq:observed-output} assume that the\ndimensionality of $x_{t+1}$, $u_{t+1}$ and $y_{t+1}$ is the same as their\nobserved counterparts, and that they do indeed represent the same entities (in\nother words, there is no \\textit{incommensurability}). Furthermore, we do not\nknow the mechanism by which $x_t$ leads to $x_{t+1}$ in Eq.~\\ref{eq:true-state},\nso instead we propose a mechanism $\\hat{f}(\\cdot{})$; similarly we do not know\nhow $x_{t+1}$ leads to $y_{t+1}$ in Eq.~\\ref{eq:true-output}, so we propose\n$\\hat{h}(\\cdot{})$. Typically, $\\hat{f}(\\cdot{})$ and $\\hat{h}(\\cdot{})$ are\npart of the same computer model structure. Because of philosophical reasons, it\nis impossible to prove that $\\hat{f}(\\cdot{})$ and $\\hat{h}(\\cdot{})$ are in\nfact the correct functions $f(\\cdot{})$ and $h(\\cdot{})$---instead, we can only\nsubject $\\hat{f}(\\cdot{})$ and $\\hat{h}(\\cdot{})$ to increasingly more difficult\ntests, and if $\\hat{f}(\\cdot{})$ and $\\hat{h}(\\cdot{})$ are not falsified by\nthese tests, then the confidence in the correctness of $\\hat{f}(\\cdot{})$ and\n$\\hat{h}(\\cdot{})$ increases.\n\n\\section{Bayes' law in parameter optimization}\n\nEq.~\\ref{eq:bayes-law-general} shows Bayes' Law:\n\\begin{equation}\\label{eq:bayes-law-general}\np(A|B) = \\frac{p(B|A)\\:p(A)}{p(B)}\n\\end{equation}\nIt describes how a prior belief in something can be modified or strengthened as\na result of observations. For example, within the context of parameter\nestimation, it describes how a \\textit{prior} belief in the value of a parameter\nvector, or $p(\\boldsymbol\\theta)$, can be modified by something called the\n\\textit{likelihood} , or $p(\\tilde{\\mathbf{x}}|\\boldsymbol\\theta)$, to yield a\n\\textit{posterior} belief in the value of the parameter vector, or\n$p(\\boldsymbol\\theta|\\tilde{\\mathbf{x}})$,  according to Eq.~\\ref{eq:bayes-law}\n($p(\\tilde{\\mathbf{x}})$ is just a normalization constant):\n\\begin{equation}\\label{eq:bayes-law}\np(\\boldsymbol\\theta|\\tilde{\\mathbf{x}}) =\n\\frac{p(\\tilde{\\mathbf{x}}|\\boldsymbol\\theta)\\:p(\\boldsymbol\\theta)}{p(\\tilde{\\mathbf{x}})}\n\\end{equation}\n\n\\section{Constructing a likelihood for a simple error model}\nThe probability of sampling a value $x$ from a normal distribution  is\ncalculated with:\n\\begin{equation}\\label{eq:normal-distribution}\np\\,(\\,x\\,|\\,\\mu,\\sigma\\,) =\n\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\:\n\\mathrm{exp}\\left[{-\\frac{1}{2}\n\\left(\\frac{x-\\mu}{\\sigma}\\right)^2}\\right]\n\\end{equation}\nWithin the context of calibration, this is equivalent to:\n\\begin{equation}\\label{eq:normal-distribution-calibration}\np\\,(\\,\\hat{x}\\,|\\,\\tilde{x},\\sigma\\,) =\n\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\:\n\\mathrm{exp}\\left[{-\\frac{1}{2}\\left(\\frac{\\hat{x}-\\tilde{x}}{\\sigma}\\right)^2}\\right]\n\\end{equation}\nNote that this assumes that the true mean of the distribution can be observed,\ni.e.\\,$\\tilde{x}=\\mu$.\n\nFor the case where we have not just 1 observation, but instead have a time\nseries of $n_o$ observations, the probability\n$p\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\boldsymbol\\sigma\\,)$ is\ncalculated as the product of all individual probabilities\\footnote{Note that\nthis can be extended to deal with non-constant variance\n(\\textit{heteroscedasticity}) by making $\\sigma$ into a vector\n$\\boldsymbol\\sigma$:\n\\begin{equation}\\label{eq:heteroscedastic-normal-distribution-calibration}\np\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\boldsymbol\\sigma\\,) =\n\\prod_{t=1}^{n_o}\n\\frac{1}{\\sqrt{2\\pi\\sigma_t^2}}\\:\n\\mathrm{exp}\\left[{-\\frac{1}{2}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma_t}\\right)^2}\\right]\\nonumber\n\\end{equation}}:\n\\begin{equation}\\label{eq:normal-distribution-calibration}\np\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) = \\prod_{t=1}^{n_o}\n\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\:\n\\mathrm{exp}\\left[{-\\frac{1}{2}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2}\\right]\n\\end{equation}\nNote that the multiplication of individual probabilities in\nEq.~\\ref{eq:normal-distribution-calibration} reflects the implicit assumption\nthat the errors are independent---an assumption that is often violated.\n\n\\vspace{1em}\nSince $\\frac{1}{\\sqrt{2\\pi\\sigma^2}}$ is constant for homoscedastic problems,\nEq.~\\ref{eq:normal-distribution-calibration} can be rearranged as follows:\n\\begin{equation}\\label{eq:normal-distribution-calibration2}\np\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) =\n\\left[\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\right]^{n_o}\\:\\cdot{}\\:\n\\prod_{t=1}^{n_o}\\:\\mathrm{exp}\\left[{-\\frac{1}{2}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2}\\right]\n\\end{equation}\nand since\n\\begin{equation}\n\\left[\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\right]^{n_o} =\n\\left[\\sqrt{2\\pi\\sigma^2}\\right]^{-n_o} \\nonumber\n\\end{equation}\nEq.~\\ref{eq:normal-distribution-calibration2} can be rewritten as:\n\\begin{equation}\\label{eq:normal-distribution-calibration3}\np\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) =\n\\left[\\sqrt{2\\pi\\sigma^2}\\right]^{-n_o}\\:\\cdot{}\\:\\prod_{t=1}^{n_o}\\:\n\\mathrm{exp}\\left[{-\\frac{1}{2}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2}\\right]\n\\end{equation}\nFurthermore,\n\\begin{equation}\n\\mathrm{exp}(a)\\cdot{}\\mathrm{exp}(b)=\\mathrm{exp}(a+b)\n\\end{equation}\nso Eq.~\\ref{eq:normal-distribution-calibration3} may be written as:\n\\begin{equation}\\label{eq:normal-distribution-calibration4}\np\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) =\n\\left[\\sqrt{2\\pi\\sigma^2}\\right]^{-n_o}\\:\\cdot{}\\:\n\\mathrm{exp}\\left[-\\frac{1}{2}\\sum_{t=1}^{n_o}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2\\right]\n\\end{equation}\nThe probability density in Eq.~\\ref{eq:normal-distribution-calibration4} is\nrelated to the \\textit{log-likelihood} according to\\footnote{Note that,\n$\\hat{\\mathbf{x}}$ in Eq.~\\ref{eq:log-likelihood1} is only dependent on the\nparameter vector  $\\boldsymbol\\theta$, while the observations\n$\\tilde{\\mathbf{x}}$ and $\\sigma$ are given. When a probability is a function of\nthe parameter value, `likelihood' is preferred over `probability'.}:\n\\begin{align}\\label{eq:log-likelihood1}\n\\ell\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) &=\n\\mathrm{log}\\left(\\,p\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,)\\,\\right)\\\\\n&=\\mathrm{log}\\left(\\left[\\sqrt{2\\pi\\sigma^2}\\right]^{-n_o}\\cdot{}\n\\mathrm{exp}\\left[-\\frac{1}{2}\\sum_{t=1}^{n_o}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2\\right]\n\\right)\n\\end{align}\nand since:\n\\begin{equation}\\label{eq:log-power}\n\\mathrm{log}\\left(a^b\\right) = b \\cdot \\mathrm{log}\\left(a\\right),\n\\end{equation}\n\\begin{equation}\\label{eq:log-multiplication}\n\\mathrm{log}\\left(a\\cdot{}b\\right) = \\mathrm{log}\\left(a\\right) +\n\\mathrm{log}\\left(b\\right),\n\\end{equation}\n\\begin{equation}\n\\mathrm{log}\\left[\\mathrm{exp}\\left(a\\right)\\right] = a,\n\\end{equation}\nEq.~\\ref{eq:log-likelihood1} can be rewritten as:\n\\begin{equation}\\label{eq:log-likelihood2}\n\\ell\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) = -n_o \\cdot{}\n\\mathrm{log}\\left[\\sqrt{2\\pi\\sigma^2}\\right]\\:+\\:\n\\left[-\\frac{1}{2}\\sum_{t=1}^{n_o}\n\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2\\right]\n\\end{equation}\nSubsequently applying Eqs.~\\ref{eq:log-power} and \\ref{eq:log-multiplication},\nEq.~\\ref{eq:log-likelihood2} can be rewritten as:\n\\begin{equation}\\label{eq:log-likelihood3}\n\\ell\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}},\\sigma\\,) =\n-\\frac{1}{2}n_o\\cdot{}\\mathrm{log}\\left(2\\pi\\right)\\:\n-\\:\\frac{1}{2}n_o\\cdot{}\\mathrm{log}\\left(\\sigma^2\\right)\\:\n-\\:\\frac{1}{2}\\sum_{t=1}^{n_o}\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{\\sigma}\\right)^2\n\\end{equation}\nto yield the Gaussian log-likelihood function with unknown variance $\\sigma^2$\nof the residuals $\\hat{x}_t-\\tilde{x}_y$. For many measuring devices, $\\sigma^2$\nis either known or can be determined by simple tests. If necessary, $\\sigma^2$\ncan also be estimated from the observations themselves according to:\n\\begin{equation}\\label{eq:variance-estimator}\ns^2 = \\frac{1}{n_o-1}\\sum_{t=1}^{n_o}\\left(\\hat{x}_t-\\tilde{x}_t\\right)^2\n\\end{equation}\n\\begin{equation}\\label{eq:log-likelihood4}\n\\ell\\,(\\,\\hat{\\mathbf{x}}\\,|\\,\\tilde{\\mathbf{x}}\\,) =\n-\\frac{1}{2}n_o\\cdot{}\\mathrm{log}\\left(2\\pi\\right)\\:\n-\\:\\frac{1}{2}n_o\\cdot{}\\mathrm{log}\\left(s^2\\right)\\:\n-\\:\\frac{1}{2}\\sum_{t=1}^{n_o}\\left(\\frac{\\hat{x}_t-\\tilde{x}_t}{s}\\right)^2\n\\end{equation}\n\n", "meta": {"hexsha": "0f526b2fe9255a8389f0627da23e073046905e0f", "size": 9358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "syllabus/tex/appendices/statistics.tex", "max_stars_repo_name": "jspaaks/inverse-modeling-2017", "max_stars_repo_head_hexsha": "f60bc1848734c3560c7e6051216bb49b35535f48", "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": "syllabus/tex/appendices/statistics.tex", "max_issues_repo_name": "jspaaks/inverse-modeling-2017", "max_issues_repo_head_hexsha": "f60bc1848734c3560c7e6051216bb49b35535f48", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-02-21T09:45:01.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-22T08:47:56.000Z", "max_forks_repo_path": "syllabus/tex/appendices/statistics.tex", "max_forks_repo_name": "jspaaks/inverse-modeling-2017", "max_forks_repo_head_hexsha": "f60bc1848734c3560c7e6051216bb49b35535f48", "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.4870466321, "max_line_length": 91, "alphanum_fraction": 0.6974780936, "num_tokens": 3277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6864645909427817}}
{"text": "\\chapter{CT Fourier Series}\n\nRecall the complex exponential $e^{st}$ for $s\\in\\mathbb{C}$ is the Eigenfunction of CT LTI systems. If we can decompose an input into a (possibly infinite) sum of such signals, we can easily determine the output using the superposition principle. In this section we consider the decomposition when the input is periodic, called the CT \\emph{Fourier Series} (CTFS).\n\nRecall a signal $x(t)$ is periodic, with fundamental frequency $\\omega_0 = \\frac{2\\pi}{T_0}$ rad/sec or $f_0 = \\frac{1}{T_0}$ Hertz, if $x(t) = x(t+kT_0)$ for integer multiple $k$ and fundamental period $T_0\\in \\mathbb{R}$. As we shall see, in this case the complex exponent of the Eigenfunction becomes $s_k = jk\\omega_0$, and the decomposition is a countably infinite sum. This gives the input-output relationship for a stable LTI system as \n\\[\nx(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t} \\; \\longrightarrow\\; y(t) = \\sum\\limits_{k = -\\infty}^{\\infty} H(j k\\omega_0)\\, a_k \\, e^{j k\\omega_0 t}\n\\]\nwhere $H(j k\\omega_0)$ are the Eigenvalues or frequency response. We now turn to determining under what circumstances the decomposition exists and how to find the coefficients $a_k$.\n\n\\section{Synthesis and Analysis Equation}\n\nSuppose we can approximate (we will revisit shortly when this approximation is exact) the periodic function $x(t)$ by the sum\n\\[\n\\boxed{x(t) \\approx \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t}\\;.}\n\\]\nThis is called the \\emph{synthesis equation} of the CT Fourier series.\n\nAssuming equivalence, let us multiply both sides by the function $e^{-jn\\omega_0 t}$,\n\\[\nx(t)e^{-jn\\omega_0 t} = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t}e^{-jn\\omega_0 t}\n\\]\nand integrate over one period\n\\[\n\\int\\limits_{0}^{T_0} x(t)e^{-jn\\omega_0 t} \\; dt = \\int\\limits_{0}^{T_0} \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t}e^{-jn\\omega_0 t} \\; dt\n\\]\nExchanging the order of integration and summation in the right-hand expression gives\n\\[\n\\int\\limits_{0}^{T_0} x(t)e^{-jn\\omega_0 t} \\; dt = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\left[ \\int\\limits_{0}^{T_0} \\, e^{j k\\omega_0 t}e^{-jn\\omega_0 t} \\; dt\\right]\n\\]\nThe bracketed term can be rewritten as\n\\[\n\\int\\limits_{0}^{T_0} \\, e^{j k\\omega_0 t}e^{-jn\\omega_0 t} \\; dt = \\int\\limits_{0}^{T_0} \\, e^{j (k-n)\\omega_0 t} \\; dt = \\int\\limits_{0}^{T_0} \\cos((k-n)\\omega_0 t) \\; dt + j \\int\\limits_{0}^{T_0} \\sin((k-n)\\omega_0 t) \\; dt  \n\\]\nWe now note that for $k\\neq n$ the integrals of the real and imaginary parts are zero\n\\[\n\\int\\limits_{0}^{T_0} \\cos((k-n)\\omega_0 t) \\; dt = \\frac{1}{(k-n)\\omega_0}\\sin((k-n)\\omega_0 t) \\Big|_{0}^{T_0} = \\frac{1}{(k-n)\\omega_0}\\sin((k-n)2\\pi) - \\frac{1}{(k-n)\\omega_0}\\sin(0) = 0  \n\\]\n\\[\n\\int\\limits_{0}^{T_0} \\sin((k-n)\\omega_0 t) \\; dt = -\\frac{1}{(k-n)\\omega_0}\\cos((k-n)\\omega_0 t) \\Big|_{0}^{T_0} = -\\frac{1}{(k-n)\\omega_0}\\cos((k-n)2\\pi) + \\frac{1}{(k-n)\\omega_0}\\cos(0) = 0  \n\\]\nWhen $k=n$\n\\[\n\\int\\limits_{0}^{T_0} e^{j (k-n)\\omega_0 t} \\; dt = \\int\\limits_{0}^{T_0} \\; dt = T_0\n\\]\nThus the bracketed term above is\n\\[\n\\int\\limits_{0}^{T_0} \\, e^{j k\\omega_0 t}e^{-jn\\omega_0 t} \\; dt = T_0\\, \\delta[k-n]\n\\]\nand the right-hand side is\n\\[\n\\sum\\limits_{k = -\\infty}^{\\infty} a_k \\left[ \\int\\limits_{0}^{T_0} \\, e^{j k\\omega_0 t}e^{-jn\\omega_0 t} \\; dt\\right] = \\sum\\limits_{k = -\\infty}^{\\infty} a_k  T_0\\, \\delta[k-n] = T_0 \\,a_n\n\\]\nThus we obtain the \\emph{analysis equation} of the CT Fourier series:\n\\[\n\\boxed{a_n = \\frac{1}{T_0} \\int\\limits_{0}^{T_0} x(t)e^{-jn\\omega_0 t} \\; dt}\n\\]\nwhere the integration can be over any interval of length $T_0$ and the symbol for the subscript (integer $n$) is arbitrary. The CT Fourier Series coefficients are also called the \\emph{spectrum} of the signal. In general the $a_k$ are complex. The function of $k$, $|a_k|$ is called the \\emph{amplitude spectrum}. The function of $k$, $\\angle a_k$ is called the \\emph{phase spectrum}. When plotting the coefficients it is common to plot the amplitude and phase spectrum together.\n\n\\begin{example}\n  Consider the signal\n  \\[\n  x_p(t) = \\left\\{ \\begin{array}{lc}\n    t^2 & -1 < t < 1\\\\\n    0 & \\mbox{else}\n  \\end{array}\n\\right.\n\\]\nperiodically extended with period $T_0 = 2$\n\\[\nx(t) = \\sum\\limits_{i = -\\infty}^{\\infty} x_p(t - 2i) \n\\]\nas shown below:\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/ctfs-example1.pdf}\n\\end{center}\nTo find the Fourier Series approximation of $x(t)$,\n\\[\nx(t) \\approx \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t}\\; ,\n\\]\nwe need to find the coefficients\n\\[\na_k = \\frac{1}{T_0} \\int\\limits_{0}^{T_0} x(t)e^{-jk\\omega_0 t} \\; dt\n\\]\nSince the integration can be over any period, we can use the limits $[-1,1]$ and note that $T_0 = 2$ so that $\\omega_0 = \\pi$, giving the sequence of expressions\n\\begin{align*}\n  a_k &= \\frac{1}{2} \\int\\limits_{-1}^{1} t^2\\,e^{-jk\\pi t} \\; dt\\\\\n  &= \\frac{1}{2} \\left[ \\int\\limits_{-1}^{1} t^2\\,\\cos(-k\\pi t) \\; dt + j \\int\\limits_{-1}^{1} t^2\\,\\sin(-k\\pi t) \\; dt \\right]\\\\\n  &= \\frac{1}{2} \\left[ \\int\\limits_{-1}^{1} t^2\\,\\cos(k\\pi t) \\; dt + j \\int\\limits_{-1}^{1} - t^2\\,\\underbrace{\\sin(k\\pi t)}_{\\text{always = 0}} \\; dt \\right]\\\\\n  &= \\frac{1}{2} \\int\\limits_{-1}^{1} t^2\\,\\cos(k\\pi t) \\; dt\\; \\mbox{ using an integration table }\\\\\n  &= \\frac{1}{2} \\frac{4k\\pi\\overbrace{\\cos(k\\pi)}^{(-1)^k} + 2(k^2\\pi^2-2)\\overbrace{\\sin(k\\pi)}^{\\text{always = 0}}}{k^3\\pi^3}\\\\\n a_k &= \\frac{2}{k^2\\pi^2}\\left(-1\\right)^k\n\\end{align*}\nThis result is undefined for when $k=0$. In that case note the original integral is\n\\[\na_0 = \\frac{1}{2} \\int\\limits_{-1}^{1} t^2 \\; dt = \\frac{1}{6}t^3 \\Big|_{-1}^{1} = \\frac{1}{3} \n\\]\nThus the final approximation is\n\\[\nx(t) \\approx \\sum\\limits_{k = -\\infty}^{\\infty} \\underbrace{\\frac{2}{k^2\\pi^2}\\left(-1\\right)^k}_{a_k} \\, e^{j k\\pi t} \\;.\n\\]\nWe can plot the spectrum of this signal (using for example Matlab)\n\\begin{verbatim}\nk = -10:10;\na = 2./(pi^2*k.^2);\na(11) = 1/3;\n\nsubplot(2,1,1);\nstem(k, abs(a));\nxlabel('k');\nylabel('|a(k)|');\ntitle('Amplitude Spectrum');\n\nsubplot(2,1,2);\nstem(k, angle(a));\nxlabel('k');\nylabel('Angle a(k)');\ntitle('Phase Spectrum');\n\\end{verbatim}\nGiving the amplitude and phase spectrum plot\n\\begin{center}\n\\includegraphics[scale=0.7]{graphics/ctfs_exampleplot.png}\n\\end{center}\n$\\blacksquare$\n\\end{example}\n\n\\section{Variations on the Synthesis and Analysis Equations}\nThere are two commonly used, equivalent, expressions for computing the CTFS coefficients. They can be derived using Euler's formula and related trig identities.\n\n\\begin{itemize}\n\\item Exponential Form. This is the form derived above\n  \\[\n  x(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t}\n  \\]\n  where \n  \\[\n  a_k = \\frac{1}{T_0} \\int\\limits_{T_0} x(t)e^{-jk\\omega_0 t} \\; dt\n  \\]\n\\item Trig Form\n  \\[\n  x(t) = b_0 + \\sum\\limits_{k = 1}^{\\infty} b_k \\,\\cos(k\\omega_0 t) + c_k\\,\\sin(k\\omega_0 t) \n  \\]\n  where\n  \\[\n  b_0 = \\frac{1}{T_0} \\int\\limits_{T_0} x(t) \\; dt\n  \\]\n  is the average value of the signal, and\n  \\[\n  b_k = \\frac{2}{T_0} \\int\\limits_{T_0} x(t)\\cos(k\\omega_0 t) \\; dt\n  \\]\n  \\[\n  c_k = \\frac{2}{T_0} \\int\\limits_{T_0} x(t)\\sin(k\\omega_0 t) \\; dt\n  \\]\n\\item Compact Trig Form\n  \\[\n  x(t) = d_0 + \\sum\\limits_{k = 1}^{\\infty} d_k \\,\\cos(k\\omega_0 t + \\theta_k) \n  \\]\n  where\n  \\[\n  d_0 = \\frac{1}{T_0} \\int\\limits_{T_0} x(t) \\; dt\n  \\]\n  is the average value of the signal, and\n  \\[\n  d_k = \\sqrt{b_k^2 + c_k^2} \n  \\]\n  \\[\n  \\theta_k = \\arctan\\left( \\frac{-c_k}{b_k} \\right)\n  \\]\n\\end{itemize}\n\n\\section{Convergence of the CT Fourier Series}\n\nAs mentioned above the Fourier Series is strictly speaking an approximation\n\\[\nx(t) \\approx \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t} \\mbox{ where } a_k = \\frac{1}{T_0} \\int\\limits_{T_0} x(t)e^{-jk\\omega_0 t} \\; dt\n\\]\nto determine when this approximation is an equivalence (and in what sense) we need to establish the existence and convergence of the integral and summation respectively.\n\nThe coefficients $a_k$ will exist when the integral converges, or equivalently when\n\\[\n\\int\\limits_{T_0} \\left|x(t)\\right| \\; dt < \\infty\n\\]\ni.e. the signal is absolutely integrable over any period. Note, such a signal is a power signal.\n\nTo determine when the summation converges, first consider the \\emph{truncated} CT Fourier Series\n\\[\nx_N(t) \\approx \\sum\\limits_{k = -N}^{N} a_k \\, e^{j k\\omega_0 t}\n\\]\nwhere the infinite sum has been truncated to the finite range $[-N,N]$. Define the error between the original signal $x(t)$ and the truncated approximation $x_N(t)$ at each time point as\n\\[\nE(N,t) = x(t) - x_N(t)\n\\]\nThere are two relevant notions of convergence. If\n\\[\n\\lim_{N\\rightarrow \\infty} \\int\\limits_{T_0} \\left| E(N,t] \\right|\\;dt = 0\n\\]\nwe say the CT Fourier Series converges \\emph{exactly} to the signal. If\n\\[\n\\lim_{N\\rightarrow \\infty} \\int\\limits_{T_0} \\left| E(N,t) \\right|^2\\;dt = 0\n\\]\nwe say the CT Fourier Series converges in the \\emph{mean-square} sense to the signal.\n\nMore formally the CTFS exists if the \\emph{Dirichlet Conditions} hold for the signal:\n\n\\begin{itemize}\n\\item The signal has a finite number of discontinuities per period.\n\\item The signal has a finite number of maxima and minima per period.\n\\item The signal is bounded, i.e.\n  \\[\n  \\int_{T_0} |x(t)| \\;dt < \\infty\n  \\]\n\\end{itemize}\n\nThese conditions rule out pathological functions. For most practical signals of interest, the conditions hold.\n\n\\begin{example}\n  Consider the \\emph{impulse train} signal defined as\n  \\[\n  x(t) = \\sum\\limits_{m = -\\infty}^{\\infty} \\delta(t-mT_0)\n  \\]\n  which we be important later when we discuss sampling CT signals. Do the Dirichlet conditions hold? Yes. It has one discontinuity, one maximum, and one minimum per period. It is also bounded since\n  \\[\n  \\int_{T_0} |\\delta(t)| \\;dt = 1 \\mbox{ by definition.}\n  \\]\n  The spectrum for the impulse train is given by\n  \\[\n  a_k = \\frac{1}{T_0} \\int\\limits_{T_0} x(t)e^{-jk\\omega_0 t} \\; dt =  \\frac{1}{T_0} \\int\\limits_{-\\frac{T_0}{2}}^{\\frac{T_0}{2}} \\delta(t)e^{-jk\\omega_0 t} \\; dt = \\frac{1}{T_0}\n  \\]\n  $\\blacksquare$\n\\end{example}\n\n\n\\begin{example}\n  Consider the signal $x(t) = \\cos(\\omega t)$. We can write this as the sum of two complex exponentials using Euler's formula\n  \\[\n  x(t) = \\frac{1}{2}e^{j\\omega t} + \\frac{1}{2}e^{-j\\omega t} \n  \\]\n  Comparing this to the synthesis equation\n  \\[\n  x(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t} = \\cdots + a_{-2} \\, e^{j (-2)\\omega_0 t} + a_{-1} \\, e^{j (-1)\\omega_0 t} + a_0 + a_{1} \\, e^{j (1)\\omega_0 t} + a_{2} \\, e^{j (2)\\omega_0 t} + \\cdots\n  \\]\n  we note that if $\\omega_0 = \\omega$ and \n  \\[\n  a_k = \\left\\{ \\begin{array}{lc}\n    \\tfrac{1}{2} & k = -1\\\\[0.5em]\n    \\tfrac{1}{2} & k = 1\\\\[0.5em]\n    0 & \\text{else}\n  \\end{array}\n  \\right.\n  \\]\n  then the two expressions are identical and the CT Fourier Series is an exact representation.\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\n  Consider the square wave signal of amplitude $A > 0$\n  \\[\n  x(t) = \\sum\\limits_{m= -\\infty}^{\\infty} \\left\\{ \\begin{array}{lc}\n    -A & \\tfrac{T_0}{2} < t-mT_0 < 0\\\\[0.5em]\n    A & 0 < t - mT_0 < \\tfrac{T_0}{2}\n  \\end{array}\n  \\right.\n  \\]\n  shown below\n  \\begin{center}\n  \\includegraphics[scale=1]{graphics/squarewave.pdf}\n  \\end{center}\n  The coefficients are given by\n  \\begin{align*}\n    a_k &= \\frac{1}{T_0} \\int\\limits_{T_0} x(t)e^{-jk\\omega_0 t} \\; dt\\\\\n    &= \\frac{1}{T_0} \\left[ \\int\\limits_{0}^{\\frac{T_0}{2}} Ae^{-jk\\omega_0 t} \\; dt + \\int\\limits_{\\frac{T_0}{2}}^{T_0} -Ae^{-jk\\omega_0 t} \\; dt\\right]\\\\\n    &= \\frac{1}{T_0} \\left[ \\frac{A}{-jk\\omega_0}e^{-jk\\omega_0 t} \\Big|_{0}^{\\frac{T_0}{2}} + \\frac{-A}{-jk\\omega_0}e^{-jk\\omega_0 t} \\Big|_{\\frac{T_0}{2}}^{T_0}\\right]\\\\\n    &= \\frac{1}{T_0} \\frac{A}{jk\\omega_0} \\left[ -\\left(e^{-jk\\omega_0 \\frac{T_0}{2}} - e^{0}\\right) + \\left(e^{-jk\\omega_0 T_0} - e^{-jk\\omega_0 \\frac{T_0}{2}}\\right)\\right]\n  \\end{align*}\n  Note that $\\omega_0\\frac{T_0}{2} = \\frac{2\\pi}{T_0}\\frac{T_0}{2}= \\pi$ and $\\omega_0 T_0 = \\frac{2\\pi}{T_0}T_0 = 2\\pi$ . Thus\n  \\begin{align*}\n    a_k &= \\frac{1}{T_0} \\frac{A}{jk\\frac{2\\pi}{T_0}} \\left[ -\\left(e^{-jk\\pi} - e^{0}\\right) + \\left(e^{-jk2\\pi} - e^{-jk\\pi}\\right)\\right]\\\\\n    &= \\frac{A}{jk\\pi}\\left( 1-e^{-jk\\pi}\\right) \\\\\n    &= \\left\\{ \\begin{array}{lc}\n      0 & k \\mbox{ even}\\\\\n      \\frac{2A}{jk\\pi} & k \\mbox{ odd}\n    \\end{array}\n\\right.\n  \\end{align*}\n  The amplitude spectrum is given by\n  \\[\n  |a_k| = \\left\\{ \\begin{array}{lc}\n    0 & k \\mbox{ even}\\\\\n    \\left|\\frac{2A}{k\\pi}\\right| & k \\mbox{ odd}\\end{array}\\right.\n  \\]\n\n  The phase spectrum is given by\n  \\[\n  \\angle a_k = \\left\\{ \\begin{array}{lc}\n    \\pi & k < 0 \\mbox{ and even}\\\\\n    -\\pi & k > 0 \\mbox{ and even}\\\\\n    \\frac{\\pi}{2} & k < 0 \\mbox{ and odd}\\\\\n    -\\frac{\\pi}{2} & k > 0 \\mbox{ and odd}\\end{array}\\right.\n  \\]\n  This is plotted below for $A = 1$.\n  \\begin{center}\n    \\includegraphics[scale=0.7]{graphics/ctfs_exampleplot2.png}\n  \\end{center}\n  We can plot the truncated approximation for increasing number of terms N, the squared error, and the total error.\n  \\begin{center}\n    \\includegraphics[scale=0.5]{graphics/squarewaveapprox1.png}\n  \\end{center}\n  \\begin{center}\n    \\includegraphics[scale=0.5]{graphics/squarewaveapprox2.png}\n  \\end{center}\n  \\begin{center}\n    \\includegraphics[scale=0.5]{graphics/squarewaveapprox3.png}\n  \\end{center}\n  Note as $N$ increases the approximation gets closer to the square wave, except at the discontinuities. This is called \\emph{Gibbs Ringing}. As $N \\rightarrow \\infty$ the mean-square error goes to zero, so the CTFS approximation to the square wave converges in the mean-square sense.\n  $\\blacksquare$\n\\end{example}\n\n\n\\section{Properties of the CT Fourier Series}\n\nLet $a_k$ and $b_k$ be the CTFS coefficients for the periodic signals $x(t)$ and $y(t)$ respectively.\n\n\\begin{itemize}\n\\item Linearity. The coefficients of the signal\n  \\[\n  z(t) = Ax(t) + By(t) \\mbox{ for constants } A,B \n  \\]\n  are $Aa_k + Bb_k$\n\\item Time Shifting. The coefficients of\n  \\[\n  z(t) = x(t-t_0) \\mbox{ are } e^{-jk\\omega_0 t_0}a_k\n  \\]\n  that is it adds a phase shift.\n\\item Time reversal. The coefficients of\n  \\[\n  z(t) = x(-t) \\mbox{ are } a_{-k}\n  \\]\n  that is the sequence reverses.\n\\item Time Scaling. Let $T_0$ and $\\omega_0$ be the fundamental period and frequency of a periodic $x(t)$. The signal \n  \\[\n  z(t) = x(\\alpha t) \\mbox{ for } \\alpha > 0\n  \\]\n  is periodic with period $\\frac{T_0}{\\alpha}$ and fundamental frequency $\\alpha\\omega_0$.\n  The coefficients of $z(t)$ are the same as $x(t)$.\n\\item Multiplication. The coefficients of\n  \\[\n  z(t) = x(t) \\cdot y(t) \\mbox{ are } \\sum\\limits_{m = -\\infty}^{\\infty} a_m\\cdot b_{k-m}\n  \\]\n  the discrete convolution of the individual signals' coefficients.\n\\item Conjugate Symmetry. The coefficients of\n  \\[\n  z(t) = x^*(t) = \\Re{x(t)} - j\\Im{x(t)} \\mbox{ are } a_{-k}^*\n  \\]\n  A consequence of this property is that real, even signals have real, even $a_k$; and real, odd signals have purely imaginary, odd $a_k$ (check the examples above).\n\\item Parseval's Relation. The power of the signal with Fourier series coefficients\n  \\[\n  \\frac{1}{T_0} \\int_{T_0} |x(t)|^2\\;dt = \\sum\\limits_{k = -\\infty}^{\\infty} |a_k|^2\n  \\]\n\\end{itemize}\n", "meta": {"hexsha": "c731aada71fc92690d20571dc156565801058ddf", "size": 15199, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-ctfs.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": "14-ctfs.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": "14-ctfs.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": 42.2194444444, "max_line_length": 479, "alphanum_fraction": 0.6415553655, "num_tokens": 5833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8991213711878918, "lm_q1q2_score": 0.6864645683666276}}
{"text": "\\newpage\n\\section{Relationship between SVM and Logistic Regression}\nIn this section, we will briefly discuss SVM and the relation with logistic regression for binary case.\nWe start it with the induction of SVM, we consider the following practical problem: Given a collection of labelled data, determine whether the\nclasses are linearly separable. If so, we would like to obtain a hyperplane or matrix which separates them, and, ideally\nwe would want to find the separation which has the largest possible margin. The support vector machine (SVM) model solves this\nproblem via convex optimization.\n\nSupport vector machines are linear models for classifying data,\nsimilar to the logistic regression. In particular, the support vector\nmachine model is essentially just a regularized logistic regression.\n\n\\subsection{2-class case}\n\nWe will now show that if the sets $A_1$ and $A_2$ are two compact and\nlinearly separable sets, then we can obtain a `margin' for this linear\nseparation.\n\n\\begin{definition}\\label{margin_two_class}\n\tSuppose two sets $A_1, A_2$ are separated by a hyperplane\n\t$H=\\{x:wx+b=0\\}$. The margin of separation with respect to $d$ is\n\tgiven by\n\t\\begin{equation}\n\tm(w,b; A_1, A_2) = \\sup \\{\\epsilon:\\text{$wx+b>0$ if $x\\in A^{\\epsilon}_1$ and $wx+b<0$ if $x\\in A^\\epsilon_2$}\\}\n\t\\end{equation}\n\twhere the $\\epsilon$-enlargement of $A_i$ is given by\n\t\\begin{equation}\n\tA^\\epsilon_i = \\{y:\\text{there is an $x\\in A_i$ such that $\\|x-y\\| < \\epsilon$}\\}\n\t\\end{equation}\n\\end{definition}\n\nWhat this definition is saying is that the margin is the largest amount that we can perturb an element of $A_i$\nsuch that the plane $H$ still classifies it correctly. \nWe have the following technical result, showing that the margin is always positive if the sets $A_1$ and $A_2$ are\ncompact (this result can safely be skipped by most readers).\n\n\\begin{lemma}\n\tSuppose that two sets $A_1, A_2$ are separated by a hyperplane\n\t$H=\\{x:wx+b=0\\}$ and that $A_1$ and $A_2$ are compact.\n\t\\begin{equation}\n\tm(w,b; A_1, A_2) > 0\n\t\\end{equation}\n\t\n\\end{lemma}\n\n\\subsection{2-class Hard-margin Case}\nWe first consider the simplest case where there are only two classes. Let $A_1$ denote the set of data points belonging to the\nfirst class and $A_2$ the set of data points belonging to the second class. \n\nSince we have a finite amount of data for each class, the sets $A_1$ and $A_2$ are compact. This means that if the sets are\nseparable, say they are separated by $H=\\{x:Wx+b=0\\}$, then there exists a finite margin, i.e. there exists an $\\epsilon > 0$\nsuch that $(Wx+b)_1\\cdot(Wx+b)_2\\leq -\\epsilon^2/4$ and\n\\begin{equation}\n(Wx+b)_1 - (Wx+b)_2  \\begin{cases} \n\\geq \\epsilon & x\\in A_1 \\\\\n\\leq -\\epsilon & x\\in A_2 \\\\\n\\end{cases}\n\\end{equation}\nRescaling $w$ and $b$ by $2\\epsilon^{-1}$, we may thus assume that $(Wx+b)_1\\cdot(Wx+b)_2\\leq -1$ and \n\\begin{equation}\n(Wx+b)_1 - (Wx+b)_2 \\begin{cases} \n\\geq 2 & x\\in A_1 \\\\\n\\leq -2 & x\\in A_2 \\\\\n\\end{cases}\n\\end{equation}\nIndexing our data points $x_1,...,x_N$ and introducing labels $y_1,...,y_N$, where\n\\begin{equation}\ny_i = \\begin{cases} \ne_1 & x\\in A_1 \\\\\ne_2 & x\\in A_2 \\\\\n\\end{cases}\n\\end{equation}\nthis can be more succinctly written as\n\\begin{equation}\\label{separation_condition_2}\n(y_i - e_j)\\cdot (Wx_i+b) \\geq \\|y_i - e_j\\|_1\n\\end{equation}\nfor all $i = 1,...,N$.\n\nOne important thing to note is that the above equation represents a convex constraint on $W\\in \\mathbb{R}^{2\\times n}$ and\n$b\\in \\mathbb{R}^2$. In particular, for each data point $x_i$, this condition is a linear constraint on $w$ and $b$, thus\ncondition (\\ref{separation_condition_2}) is a finite intersection of linear constraints on $w$ and $b$. This means that\nwe can determine whether the sets are linearly separable by checking whether a linear program is feasible.\n\nOf course, if the sets are separable, we would like to find the hyperplane which maximizes the margin, as defined in\nDefinition \\ref{margin_two_class}. To this end, we have the following lemma.\n\\begin{lemma}\n\tAssume that $A_1$ and $A_2$ are linearly separated by the matrix $W=\n\t\\begin{pmatrix}\n\tw_1\\\\\n\tw_2\n\t\\end{pmatrix}\n\t\\in \\mathbb{R}^{2\\times d}, \n\tb\\in\n\t\\mathbb{R}^2 $, i.e $A_1$ and $A_2$ can be separated by the hyperplane $H=\\{x:(w_1-w_2)x+(b_1-b_2)=0\\}$, such that (\\ref{separation_condition_2})\n\tholds. \n\tThen the margin satifies\n\t\\begin{equation}\n\tm(W,b;A_1,A_2)\\geq \\frac{1}{\\|w_1-w_2\\|}\n\t\\end{equation}\n\tMoreover, we have equality iff there exists an $x_1\\in A_1$ and\n\tan $x_2\\in A_2$ such that $|(w_1-w_2)x_1+(b_1-b_2)| = 1$ and $|(w_1-w_2)x_2+(b_1-b_2)| = 1$.\n\t\n\\end{lemma}\n\n\\begin{proof}\n\tFor $\\forall x_i \\in A_i, i=1,2$,\n\t\\begin{align}\n\td(A_i, H)\\ge d(x_i, H)=\\frac{|(w_1-w_2)x+(b_1-b_2)|}{\\|w_1-w_2\\|}\\ge \\frac{1}{\\|w_1-w_2\\|}.\n\t\\end{align}\n\tSo by the definition, \n\t\\begin{equation}\n\tm(H,A_1,A_2)\\geq \\frac{1}{\\|w_1-w_2\\|}\n\t\\end{equation}\n\tThe equality holds iff $d(A_1, H)= d(A_2, H)=\\frac{1}{\\|w_1-w_2\\|}.$ The equation holds iff there exists an $x_1\\in A_1$ and\n\tan $x_2\\in A_2$ such that $|(w_1-w_2)x_1+(b_1-b_2)| = 1$ and $|(w_1-w_2)x_2+(b_1-b_2)| = 1$.\n\\end{proof}\n\n\nSince maximizing the margin $\\|w_1-w_2\\|^{-1}$ is the same as minimizing $\\|w_1-w_2\\|$. Denoting $w_1-w_2$ as $w$, $b_1-b_2$ as $b$, we can obtain the following  convex optimization problem\n\\begin{align}\\label{2class_hard_op}\n\\min_{w,~b~}~~&\\|w\\|,\\\\\ns.t.~~&wx+b \\geq 2, \\forall x\\in A_1,\\\\\n&wx+b \\leq -2, \\forall x \\in A_2.\n\\end{align}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=3.0in]{./figures/margin.png}   \n\t\\caption{margin}\n\t\\label{margin}\n\\end{figure}\n\n\\blankpage\n\\newbreak\n\\subsection{Relation between SVM and LR}\nThe SVM presented above can also be formulated as\n\\begin{equation}\\label{key}\n\\bm \\theta^*_{\\rm SVM} = \\mathop{\\arg\\max}_{\\bm \\theta \\in \\Theta} \\min_{1\\le i\\le 2} {\\rm dist}(H_{\\bm \\theta}, A_i),\n\\end{equation}\nwith $H_{\\bm \\theta} = \\{ wx + b = 0 \\}$.\n\nThen ,for logistic regression, we first generalize the regularization term $R(\\|\\bm \\theta\\|)$ just as $R(\\bm \\theta)$ and specifically \n\\begin{equation}\\label{key}\nR(\\bm \\theta) = \\|w\\| := \\sqrt{\\sum_{ij} w_{ij}},\n\\end{equation}\nfor $\\bm \\theta = (w,b)$.\nThen, let us denote \n\\begin{equation}\\label{key}\n\\bm\\theta_{\\rm LR}(\\lambda) = (w_{\\rm LR}(\\lambda),b_{\\rm LR}(\\lambda)) = \\mathop{\\arg\\min}_{\\theta} L_\\lambda(\\bm \\theta),\n\\end{equation}\nas one of the solution of LR when we choose $\\lambda R(\\bm \\theta) = \\lambda \\|w\\|$ as regularization term. \nHere, we only care the direction of the parameter because the direction has already determined the separating hyperplane and the value of hard margin.\nThe following theorem tell us that the LR solution will converge to a SVM solution in direction as $\\lambda$ tends to 0 when data ia linearly separable.\n\\begin{theorem}\n\tSuppose that $A_1$ and $A_2$ are linearly separable, given $\\theta_\\lambda = (w_\\lambda,b_\\lambda)\\in \\theta_{LR}(\\lambda)$  for any $\\lambda>0$, if $\\frac{\\bm\\theta_\\lambda}{\\|w_\\lambda\\|}$ converges, it must convergers to normalized SVM solition, i.e.\n\t\\begin{equation}\\label{key}\n\t\\frac{\\theta^*_{\\rm SVM}}{\\|w^*_{SVM}\\|}  = \\lim_{\\lambda \\to 0} \\frac{\\bm\\theta_\\lambda}{\\|w_\\lambda\\|}.\n\t\\end{equation}\n\\end{theorem}\n\n\n\n\n\\endinput\n\n\\begin{comment}\nA very common choice of metric $d$ is the Euclidean metric,\ncorresponding the $2$-norm $\\|\\cdot\\|_2$. In this case the dual norm\n$\\|\\cdot\\|$ is the same. Another reasonable choice could be the\n$p$-norm $\\|\\cdot\\|_p$, for $1\\leq p\\leq \\infty$, on $\\mathbb{R}^n$.\nIn this case the dual norm becomes $\\|\\cdot\\|_{p^*}$ where $p^{-1} +\n(p^*)^{-1} = 1$.\n\\end{comment}\n\n\n\\subsection{2-class soft-margin case}\n\nOf course, the following question arises: What should we do if the data is not linearly separable? A possible approach here is to \nreplace the hard constraint (\\ref{separation_condition_2}) by a penalty term. This is often called a soft-margin SVM,\nas opposed to the hard constraint, which is called a hard-margin SVM.\n\nA common choice of penalty is the hinge, or ReLU penalty, which only penalizes when each of the constraints\nin (\\ref{separation_condition_2}) is violated. The resulting optimization problem takes the following form:\n\\begin{equation}\n\\min_{W,~b} \\|w_1-w_2\\| + C\\displaystyle\\sum_{i=1}^N \\text{RuLU}\\Big(\\|y_i - e_j\\|_1- (y_i - e_j)\\cdot (Wx_i+b) \\Big)\n\\end{equation}\nwhere $C$ is a parameter controlling how much the penalty term is weighted.\n", "meta": {"hexsha": "e72db47c48eb4e55a6f3f2194f788439c6a53696", "size": 8357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DL-LRSVM-2.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/DL-LRSVM-2.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/DL-LRSVM-2.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": 44.4521276596, "max_line_length": 254, "alphanum_fraction": 0.7059949743, "num_tokens": 2860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.6864203557096095}}
{"text": "\\section{The Lorentz Group}\n\\begin{frame}{The Lorentz Transformations}\n\t\\begin{align*}\n\t\tx^\\mu =\n\t\t\\begin{pmatrix}\n\t\t\tt \\\\\n\t\t\t\\vec x\n\t\t\\end{pmatrix}\n\t\t\\qquad\n\t\tx_{\\mu} =\n\t\tg_{\\mu\\nu} x^{\\nu}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\tt \\\\\n\t\t\t-\\vec x\n\t\t\\end{pmatrix}\n\t\t\\qquad\n\t\tg_{\\mu\\nu}\n\t\t= \\symup{diag}(1, -1, -1, -1)\n\t\t\\qquad\n\t\t\\symup{c} = 1\n\t\\end{align*}\n\tLorentz-Transformations are \\emph{all} transformations $x_\\mu\\rightarrow x'_\\mu$, which leave the spacetime distance\n\t\\begin{align}\n\t\t\\label{eqn:s2}\n\t\ts^2 = \\l(x_2-x_1\\r)_\\mu\\l(x_2-x_2\\r)^\\mu=(t_2-t_1)^2-(\\vec x_2 - \\vec x_1)^2\n\t\\end{align}\n\tinvariant.\n\tIt is easy to see, that these transformations must be affine tranformations:\n\t\\begin{align}\n\t\t\\label{eqn:trans}\n\t\tx'^\\mu = L(\\Lambda, a; x)^\\mu = \\Lambda^\\mu_{\\ \\nu}x^\\nu + a^\\mu\n\t\\end{align}\n\t\\eqref{eqn:s2} into \\eqref{eqn:trans}:\n\t\\begin{align*}\n\t\ta^\\mu \\in \\symbb{R} \\qquad g_{\\alpha \\beta} = g_{\\mu\\nu} \\Lambda^\\mu_{\\ \\alpha}\\Lambda^\\nu_{\\ \\beta}\n\t\\end{align*}\n\\end{frame}\n\\begin{frame}{The Group Axioms}\n\tLorentz Transformations fulfill the group axioms $\\rightarrow$ Poincaré  or inhomogeneous Lorentz Group (LG)\n\n\t\\centering\n\t\\begin{tabular}{l l l}\n\t\t1. & $L(\\Lambda, a)\\circ L(\\Lambda', a') \\in \\mathcal L$ & $L\\l(\\Lambda, a; L(\\Lambda', a'; x)\\r) = L(\\Lambda\\Lambda', \\Lambda a'+a; x)$                                                      \\\\\n\t\t2. & Associativity:                                      & $\\l(L(\\Lambda, a)\\circ L(\\Lambda', a')\\r)\\circ L(\\Lambda'', a'')= L(\\Lambda, a)\\circ \\l(L(\\Lambda', a')\\circ L(\\Lambda'', a'')\\r)$ \\\\\n\t\t3. & Identity:                                           & $L(\\symbb{1}_4, \\vec 0; x) = x$                                                                                                    \\\\\n\t\t4. & Inverse:                                            & $L(\\Lambda, a)^{-1}=L(\\Lambda^{-1}, -\\Lambda^{-1}a)$\n\t\\end{tabular}\n\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{The Group Structure}\n\n\t\\begin{tabular}{l l l}\n\t\tInhomogeneous LG             & $L(\\Lambda, a)$                                                                             & Unconnected          \\\\\n\t\t$\\rightarrow$Space Inversion & $L(P, 0) = L(\\symup{diag}(1, -1, -1, -1), 0)$                                               &                      \\\\\n\t\t$\\rightarrow$Time Reversal   & $L(T, 0) = L(\\symup{diag}(-1, 1, 1, 1), 0)$                                                 &                      \\\\\n\t\tHomogeneous LG               & $L(\\Lambda, 0)$                                                                             & Unconnected subgroup \\\\\n\t\tTranslations                 & $L(0, a)$                                                                                   & Connected subgroup   \\\\\n\t\tRotations                    & $L(\\symbf R_4, 0) =  L\\l(\\begin{pmatrix}\n\t\t\t\t\t1      & \\vec 0^{\\symup{T}}     \\\\\n\t\t\t\t\t\\vec 0 & \\symbf{R(\\vec \\alpha)}\n\t\t\\end{pmatrix} , 0\\r)\\quad \\symbf{R} \\in \\symup{SO(3)}$ & \\vspace{1em}Connected subgroup   \\\\\n\t\tBoosts                       & $L(\\symbf B, 0) = L\\l(\n\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\gamma         & -\\gamma \\vec v^{\\symup{T}}                                      \\\\\n\t\t\t\t\t-\\gamma \\vec v & \\symbb{1} + \\vec v \\vec v^{\\symup{T}} \\frac{\\gamma-1}{\\vec v^2}\n\t\t\t\t\\end{pmatrix}\n\t\t, 0\\r)$                      & Connected subgroup                                                                                                 \\\\\n\t\tRestricted LG                & $L(\\symbf R_4, 0) \\cup L(\\symbf B, 0)$                                                      & Connected subgroup\n\t\\end{tabular}\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{The Lie-Algebra of the restricted LG}\n\tTransformations close to unity:\n\t\\begin{align*}\n\t\t\\Lambda^{\\mu}_{\\ \\nu} = \\delta^{\\mu}_{\\ \\nu} + \\omega^{\\mu}_{\\ \\nu}\n\t\\end{align*}\n\t$\\omega^{\\mu}_{\\ \\nu}$ is infinitesimal.\n\t\\begin{align*}\n\t\t\\Rightarrow g_{\\alpha \\beta} = g_{\\mu\\nu} \\l(\\delta^{\\mu}_{\\ \\alpha} + \\omega^{\\mu}_{\\ \\alpha}\\r)\\l(\\delta^{\\nu}_{\\ \\beta} + \\omega^{\\nu}_{\\ \\beta}\\r)\n\t\t= g_{\\alpha\\beta}+\\omega_{\\alpha\\beta}+\\omega_{\\beta\\alpha}+\\symcal O (\\omega^2) \\Rightarrow  \\omega_{\\alpha\\beta}= -\\omega_{\\beta\\alpha}\n\t\\end{align*}\n\t\\pause\n\tLet $\\symbf M(\\Lambda)$ be a representation of the restricted LG: $\\symbf M(\\Lambda)\\symbf M(\\Lambda')=\\symbf M(\\Lambda\\Lambda')$\n\t\\begin{align*}\n\t\t\\symbf M (1+\\omega) = \\symbf 1 + \\frac{1}{2} i\\omega_{\\mu\\nu} \\symbf J^{\\mu\\nu} + \\symcal O (\\omega^2)\n\t\\end{align*}\n\tChoose $\\symbf J^{\\mu\\nu}=-\\symbf J^{\\nu\\mu}$\n\t\\begin{align*}\n\t\t\\symup M(\\Lambda)\\symup M(1+\\omega)\\symup M(\\Lambda)^{-1}\n\t\t= \\symup M(\\Lambda (1+\\omega)\\Lambda^{-1}) \\\\\n\t\t\\dots \\Rightarrow i[\\symbf J^{\\mu\\nu}, \\symbf J^{\\rho\\sigma}] = g^{\\nu\\rho}\\symbf J^{\\mu\\sigma} - g^{\\mu\\rho} \\symbf J^{\\nu\\sigma} - g^{\\sigma\\mu} \\symbf J^{\\rho\\nu} + g^{\\sigma\\nu} \\symbf J^{\\rho\\mu}\n\t\\end{align*}\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{Representation of the restricted LG}\n\tSince $\\symbf J^{\\mu\\nu}= -\\symbf J^{\\nu\\mu}$, it has 6 independent components. We choose:\n\t\\begin{align*}\n\t\t\\symbf{\\vec J} = (\\symbf J^{23},\\symbf J^{31},\\symbf J^{12}) & \\qquad \\symbf{\\vec K} = (\\symbf J^{01},\\symbf J^{02},\\symbf J^{03}) \\\\\n\t\t\\Rightarrow [\\symbf J_i,\\symbf J_j]                          & = i \\epsilon_{ijk} \\symbf J_k                                       \\\\\n\t\t\\Rightarrow [\\symbf J_i,\\symbf K_j]                          & = i \\epsilon_{ijk} \\symbf K_k                                       \\\\\n\t\t\\Rightarrow [\\symbf K_i,\\symbf K_j]                          & = -i \\epsilon_{ijk} \\symbf K_k\n\t\\end{align*}\n\t\\pause\n\t\\begin{align*}\n\t\t\\symbf{\\vec A}^\\pm              & = \\frac{1}{2}\\l(\\symbf{\\vec J} \\pm i\\symbf{\\vec K}\\r) \\\\\n\t\t[\\symbf A^\\pm_i,\\symbf A^\\pm_j] & = i \\epsilon_{ijk} \\symbf A^\\pm_k                     \\\\\n\t\t[\\symbf A^\\pm_i,\\symbf A^\\mp_j] & = 0\n\t\\end{align*}\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{$(A, B)$ representation of the restricted LG}\n\tThe restricted Lorentz group can be written as  $L = \\symup{SO}(3)_l \\oplus \\symup{SO}(3)_r$.\n\t\\\\We find matrices satisfying the $\\symbf{\\vec A}^\\pm$ algebra with the standard spin matrices:\n\t\\begin{align*}\n\t\t\\l(\\symbf{A_3}^+\\r)_{aa'}                   & = a \\delta_{aa'}                               \\\\\n\t\t\\l(\\symbf{A_1}^+\\pm i\\symbf{A_2}^+\\r)_{aa'} & = \\delta_{a',a\\pm1} \\sqrt{(A\\mp a)(A\\pm a +1)} \\\\\n\t\ta                                           & = -A, -A+1, \\dots, +A\n\t\\end{align*}\n\tLikewise for $\\symbf{\\vec A}^-$ only with $B$ and $b$ $\\Rightarrow\\ (A, B)$ representation of the restricted Lorentz group\n\t\\pause\n\tSince $\\symbf{\\vec J}=\\symbf{\\vec A}^++\\symbf{\\vec A}^-$, Fields transforming under the $(A, B)$ representation have components with spin\n\t\\begin{align*}\n\t\tj = A+B, A+B-1, \\dots, \\abs{A-B}\n\t\\end{align*}\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{Examples of representations}\n\t\\begin{tabular}{l l l}\n\t\t$(0, 0)$                                         & Scalar                        & Boson                              \\\\\n\t\t$(\\sfrac{1}{2}, 0)\\text{ and }(0, \\sfrac{1}{2})$ & Lefthanded and RH Weyl Spinor & Massless fermion                   \\\\\n\t\t$(\\sfrac{1}{2}, \\sfrac{1}{2})$                   & Vector                        & Boson                              \\\\\n\t\t$\\bigotimes_{i=1}^N(\\sfrac{1}{2}, \\sfrac{1}{2})$ & $N$-Rank Tensor               &                                    \\\\\n\t\t$(\\sfrac{1}{2}, 0)\\oplus(0, \\sfrac{1}{2})$       & Dirac Bispinor                & Fermions                           \\\\\n\t\t$(\\sfrac{1}{2}, 1)\\oplus(1, \\sfrac{1}{2})$       & Rarita Schwinger Field        & Gravitino                          \\\\\n\t\t$(2, 0)\\oplus (0, 2)$                            & Spin 2 Spinor                 & Graviton / Rieman Curvature Tensor \\\\\n\t\\end{tabular}\n\\end{frame}\n", "meta": {"hexsha": "fda97c2007b3473409a96a98e24af47dd2bde6d9", "size": 7625, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/introduction.tex", "max_stars_repo_name": "The-Ludwig/Rarita-Schwinger-Talk", "max_stars_repo_head_hexsha": "64b43d3c85b8614e5ca75c57bee9d76ff322eba8", "max_stars_repo_licenses": ["MIT"], "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/introduction.tex", "max_issues_repo_name": "The-Ludwig/Rarita-Schwinger-Talk", "max_issues_repo_head_hexsha": "64b43d3c85b8614e5ca75c57bee9d76ff322eba8", "max_issues_repo_licenses": ["MIT"], "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/introduction.tex", "max_forks_repo_name": "The-Ludwig/Rarita-Schwinger-Talk", "max_forks_repo_head_hexsha": "64b43d3c85b8614e5ca75c57bee9d76ff322eba8", "max_forks_repo_licenses": ["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.4642857143, "max_line_length": 202, "alphanum_fraction": 0.4727868852, "num_tokens": 2685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6864203487416921}}
{"text": "\\lab{Optimal Reentry of a Spacecraft}{Optimal Reentry of a Spacecraft}\n\\label{lab:reentry}\n\\objective{ We consider the problem of minimizing the heating experienced by a spacecraft during reentry. \nThe boundary value problem (BVP) associated with the reentry of a spacecraft is inherently challenging: the craft must descend quickly enough to enter the atmosphere, but pull out soon enough to prevent overheating or crashing. \nProblems involving variational calculus and optimal control often include the numerical solution of a challenging BVP. }\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=6cm]{Apollo8_during_Launch.jpg}\n\\caption{Apollo 8 during launch}\n\\label{fig:reentry:apollo8}\n\\end{figure}\n\nA fundamental topic considered in aerospace engineering is the process of landing a spacecraft. \nLanding a spacecraft requires a massive reduction in the kinetic energy of the craft. \nThat reduction can be accomplished either through the use of massive quantities of fuel (very expensive), or by  transforming kinetic energy into heat. \nThat heat must then be absorbed by the atmosphere and the spacecraft. \nThe question then is how to choose the optimal path for reentry into the atmosphere, where the total heating experienced by the craft is minimized. \n\nWe begin with a control system\\footnote{This control problem and its numerical solution are thoroughly described in `Introduction to Numerical Analysis' by J. Stoer, R. Bulirsch (pg 524). \nWe will mirror their presentation throughout this lab.}\nthat describes the path of a spacecraft through the atmosphere \n(we assume the spacecraft is similar to the Apollo craft).\nThe dependent variables are the velocity $v$ of the spacecraft,  \nthe angle $\\gamma$ of the flight path, \nand the normalized altitude $\\xi=h/R$ above the Earth's surface, where $R$ is the radius of the Earth and $h$ is the altitude of the spacecraft above the Earth.\nThe control variable  $u$ represents the angle of attack of the spacecraft. \nThe flight path is given by \n\\begin{align}\n\\begin{split}\n\\dot{v} &= -s\\rho v^2C_D(u) - \\frac{g\\sin(\\gamma)}{(1+\\xi)^2},\\\\\n\\dot{\\gamma} &= s \\rho v C_L(u) + \\frac{v \\cos(\\gamma)}{R(1+\\xi)} - \\frac{g \\cos \\gamma}{v(1+\\xi)^2},\\\\\n\\dot{\\xi} &= \\frac{v \\sin \\gamma}{R}.\n\\end{split} \\label{eqn:reentry:control_system}\n\\end{align}\nCoefficients $C_D$ and $C_L$ represent drag and lift coefficients, and depend on the angle of attack:\n\\begin{align*}\n C_D(u) &= 1.174 - .9\\cos u, \\\\\n C_L(u) &= 0.6\\sin u.\n\\end{align*}\n \nThe atmospheric density $\\rho$ is a function of height,\n\\[\\rho(\\xi) = \\rho_0e^{-R\\beta\\xi},\n\\] where  $\\rho_0$ is the atmospheric density at the surface of the earth. \nOther parameters include the force of gravity $g$, and $s = \\frac{1}{2}S/m$, where $S$ is the frontal area of the craft and $m$ is its mass.\nThe numerical values we will use are coded below, along with the drag and lift functions. \n\\begin{lstlisting}\nfrom __future__ import division\nfrom math import pi, sqrt, sin, cos, exp\nfrom numpy import linspace, array, tanh, cosh, ones, arctan\nimport numpy as np\nfrom scipy.special import erf\nfrom scipy.optimize import root\n\nfrom bvp6c import bvp6c, bvpinit, deval\nfrom structure_variable import struct\n\nR = 209\nbeta = 4.26\nrho0 = 2.704e-3\ng = 3.2172e-4\ns = 26600\n\ndef C_d(u):\n\treturn 1.174 - 0.9*cos(u)\n\ndef C_l(u):\n\treturn 0.6*sin(u)\n\\end{lstlisting}\n\nRealistic boundary conditions for the trajectory of the spacecraft are\n\\begin{equation}\n  \\begin{split}\n    v(0) &= 0.36 \\quad (36000 \\text{ ft/sec})\\\\\n    \\gamma(0) &= -8.1^\\circ \\frac{\\pi}{180^\\circ}\\\\\n    \\xi(0)&= \\frac{4}{R}\\quad (h = 400000 \\text{ ft})\n  \\end{split} \n\\quad \\quad \\quad \\quad \\quad\n  \\begin{split}\n    v(T) &= 0.27\\\\\n    \\gamma(T) &= 0 \\\\\n\t\\xi(T)&= \\frac{2.5}{R}\n  \\end{split} \\label{eqn:reentry:BCs}\n\\end{equation}\nwhere $T$ represents the time at the end of the (first) reentry maneuver. \nThese boundary conditions are similar to those encountered at the end of each Apollo mission to the moon. \n\n% To simpify notation, we will also write \\eqref{eqn:reentry:control_system} in the form $y' = G(y)$, where $y = [y_0, y_1, y_2]^T=[v,\\gamma, \\xi]^T$ and $G$ has component functions $G = [G_0, G_1, G_2]^T$.\nThe total heating is \n\\[\nJ[u] = \\int_0^T 10 v^3 \\sqrt{\\rho}.\n\\]\nThe Hamiltonian corresponding to this control system\\footnote{Here we are using the Pontryagin Minimum Principle, rather than the Maximum Principle. Due to this slight variation, the Hamiltonian is defined as  $\\lambda  \\cdot f + L$, where $\\lambda$ is the costate vector, the state equation is $\\dot{x} = f,$ and the functional $J = \\int_0^T L$.} is \n\\begin{align}\n\t\\begin{split}\nH &=  10v^3 \\sqrt{\\rho} + \\lambda_1 \\left ( -s\\rho v^2C_D(u) - \\frac{g\\sin(\\gamma)}{(1+\\xi)^2} \\right) + \\\\ \n&{ }\\quad \\quad\\lambda_2 \\left( s \\rho v C_L(u) + \\frac{v \\cos(\\gamma)}{R(1+\\xi)} - \\frac{g \\cos \\gamma}{v(1+\\xi)^2} \\right) + \\\\\n&{ }\\quad \\quad \\lambda_3 \\left( \\frac{v \\sin \\gamma}{R} \\right),\n\t\\end{split}\n\\end{align}\n% \\begin{align}\n% H &=  10y_0^3 \\sqrt{\\rho} + \\lambda_0G_0 + \\lambda_1G_1 + \\lambda_2G_2,\n% \\end{align}\nwhere $\\lambda = [\\lambda_1,\\lambda_2,\\lambda_3]^T$ is the adjoint variable. \nThe state and adjoint equations are thus given by \n\\begin{align}\n\\begin{split}\n\t\\dot{y} &= H_{\\lambda},\\quad \\dot{} = \\frac{d}{dt},\\\\\n\t\\dot{\\lambda} &= -H_{y}, \\label{eqn:reentry:full_system}\n\\end{split}\n\\end{align}\nwhere $y = [y_1,y_2,y_3]^T = [v,\\gamma, \\xi]^T$.\nTo our boundary conditions we add the terminal condition that $H = 0$ at $t = T$. \nFinally, from the condition $\\frac{\\partial H}{\\partial u} = 0$ we find that the optimal control satisfies \n\\begin{align}\n\\tan u &= \\frac{6\\lambda_2}{9v\\lambda_1}.\n\\end{align}\n\nMost BVP solvers require an equal number of differential equations and boundary conditions. \nCurrently we have a free boundary value problem; there are 6 ODEs and 7 boundary conditions, and the length of the reentry maneuver, $T$, is still unknown. \nBy making the transformation $x = t/T$, and treating $T$ as a dependent variable, the BVP is now defined on the interval $(0,1)$ and is augmented with an additional ODE: \n\\begin{align}\n\\begin{split}\n\ty' &= TH_{\\lambda},\\quad ' = \\frac{d}{dx},\\\\\n\t\\lambda' &= -TH_{y},\\\\\n\tT' &= 0. \\label{eqn:reentry:full_system}\n\\end{split}\t\n\\end{align}\nThis BVP has 7 ODEs, and with the 7 boundary conditions introduced earlier it has the required form.\n% \\footnote{BNDSCO - A program for the numerical solution of optimal control problems, H.J. Oberle and W. Grimm, 1989}\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=7cm]{The_Lunar_Farside.jpg}\n\\caption{ The Apollo 8 mission was the first to orbit the moon and return to earth. \nAfter a flight of three days from earth, they orbited the moon ten times in 20 hours before making the return trip. \nThis photograph  shows a portion of the far side of the moon, as seen by the Apollo 8.\n}\n\\label{fig:reentry:Lunar_Farside}\n\\end{figure}\n\n\n\n\\begin{problem}\nComplete the function \\li{ode} below that implements the right hand side of \\eqref{eqn:reentry:full_system}. \nNotice that the adjoint variables and the final time are coordinates of $y:$ $y_4 = \\lambda_1$, $y_5 = \\lambda_2$, $y_6=\\lambda_3$, and $y_7 = T$. Finally, note that we use Python zero based indexing below.\n\\begin{lstlisting}\ndef ode(x,y):\n\t# Parameters:\n\t# x: independent variable (unused in our ODEs)\n\t# y: vector-valued dependent variable; it is an ndarray \n\t# \t with shape (7,)\n\t\n\t# Returns: \n\t# ndarray of length (7,) that evalutes the RHS of the ODES\n\tu =\t arctan((6*y[4])/(9*y[0]*y[3] ))\n\trho = rho0*exp(-beta*R*y[2])\n\tout = y[6]*array([\n\t\t\t\t # G_0\n\t\t\t\t -s*rho*y[0]**2*C_d(u) - g*sin(y[1])/(1+y[2])**2,\t\n\t\t\t\t # G_1\t \n\t\t\t\t( s*rho*y[0]*C_l(u) + y[0]*cos(y[1])/(R*(1 + y[2])) - \n\t\t\t\t  g*cos(y[1])/(y[0]*(1+y[2])**2) ),\t\t\t\t\t\t \n\t\t\t\t # G_2\n\t\t\t\ty[0]*sin(y[1])/R,\t\t\n\t\t\t\t # G_3\t\t\t\t\t\t\t\t \n\t\t\t\t-( 30*y[0]**2.*sqrt(rho)+ y[3]*(-2*s*rho*y[0]*C_d(u)) + \n\t\t\t\t   y[4]*( s*rho*C_l(u) +cos(y[1])/(R*(1 + y[2])) + \n\t\t\t\t\t\t  g*cos(y[1])/( y[0]**2*(1+y[2])**2 ) \n\t\t\t\t\t\t\t) + \n\t\t\t\t   y[5]*(sin(y[1])/R)\t   ),\t\n\t\t\t\t  # G_4\t\t\t\t\t\t \n\t\t\t\t-( y[3]*( -g*cos(y[1])/(1+y[2])**2\t) + \n\t\t\t\t   y[4]*( -y[0]*sin(y[1])/(R*(1+y[2])) + \n\t\t\t\t\t\t  g*sin(y[1])/(y[0]*(1+y[2])**2 ) \n\t\t\t\t\t\t\t) + \n\t\t\t\t   y[5]*(y[0]*cos(y[1])/R )\t   ),\n\t\t\t\t  # G_5 -- This line needs to be completed.\t\t\t\t\t\t \n\t\t\t\t  ,\t\t\t\n\t\t\t\t  # G_6\t\n\t\t\t\t\t0 \t\t\t\t\t\t\t\t\t \n\t\t\t   ])\n\treturn out\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{solutions.pdf}\n\\caption{The optimal path for the reentry maneuver of a spacecraft. \nThis path minimizes the heating of the spacecraft, and satisfies  \\eqref{eqn:reentry:full_system},\\eqref{eqn:reentry:BCs}, and the terminal condition $H(T) = 0$.\n}\n\\label{fig:reentry:solutions}\n\\end{figure}\n\n\n\\section*{Constructing an Initial Guess}\nWe will use the BVP solver \\li{scikits.bvp_solver}.\nLike any solver capable of handling nonlinear problems, \\li{bvp_solver} requires an initial guess to jump-start its Newton-like iteration process.\n% We will use the BVP solver \\li{bvp6c}. \n% Like any solver capable of handling nonlinear problems, \\li{bvp6c} requires an initial guess to jump-start its Newton-like iteration process.\nOur nonlinear BVP is very sensitive, and requires an initial guess that is quite close to the solution.  \nThis sensitivity is physically meaningful. \nThe spacecraft is traveling at a speed far greater than a typical aircraft. \nIf the control is not aggressive, the spacecraft will fall/`bounce' back into space as it encounters the atmosphere at a high velocity. \nHowever, if the control lasts too long, the craft will overheat or crash.\n\nSince this is a sensitive problem, we will use a heuristic method to construct good initial guesses for $v, \\gamma, \\xi, \\lambda_1, \\lambda_2,\\lambda_2$, and $u$.\nFrom aerospace engineers we know that the control $u$ should empirically look like Figure \\ref{fig:reentry:estimate_u}; \nwe can create a smooth approximation of the form $u = p_1\\erf(p_2(p_3-t/T))$, where $p_1, p_2,$ and $p_3$ are unknown constants. \nTo help us determine these constants, and to find good initial guesses for $v, \\gamma$, and $\\xi$, we define an auxiliary BVP\n\\begin{align}\n\\begin{split}\n\\dot{y_0} &= -s\\rho y_0^2C_D(u) - \\frac{g\\sin(y_1)}{(1+y_2)^2},\\\\\n\\dot{y_1} &= s \\rho y_0 C_L(u) + \\frac{y_0 \\cos(y_1)}{R(1+y_2)} - \\frac{g \\cos y_1}{y_0(1+y_2)^2},\\\\\n\\dot{y_2} &= \\frac{y_0 \\sin y_1}{R} ,\\\\\n\\dot{p_1} &= 0, \\\\\n\\dot{p_2} &= 0, \\\\\n\\dot{p_3} &= 0.\n\\end{split} \\label{eqn:reentry:control_system_auxiliary}\n\\end{align}\n\nThis auxiliary BVP is defined on the interval $[0,T]$, where $T$ is unknown. \nWe guess at $T$: the maneuver will occur quickly, so how about 230 seconds?  After this boundary value problem has been solved, we will have good initial guesses for the correct $v,\\gamma,\\xi$, and $u.$ We will still need to construct initial guesses for $\\lambda_1, \\lambda_2$, and $\\lambda_3$.\nBelow we code  functions for \\eqref{eqn:reentry:control_system_auxiliary} and for the boundary conditions. \n\\begin{lstlisting}\nT0 = 230\t\n\t\ndef ode_auxiliary(t,y):\n\tu = y[3]*erf( y[4]*(y[5]-(1.*t)/T0) )\n\trho = rho0*exp(-beta*R*y[2])\n\tout = array([-s*rho*y[0]**2*C_d(u) - g*sin(y[1])/(1+y[2])**2,\n\t\t\t\t  ( s*rho*y[0]*C_l(u) + y[0]*cos(y[1])/(R*(1 + y[2])) -\n\t\t\t\t  g*cos(y[1])/(y[0]*(1+y[2])**2) ),\n\t\t\t\t  y[0]*sin(y[1])/R,\n\t\t\t\t  0,\n\t\t\t\t  0,\n\t\t\t\t  0\t\t])\n\treturn out\n\ndef bcs_auxiliary(ya,yb):\n\tout1 = array([ ya[0]-.36,\n\t\t\t\t  ya[1]+8.1*pi/180,\n\t\t\t\t  ya[2]-4/R\n\t\t\t\t  ])\n\tout2 = array([ yb[0]-.27,\n\t\t\t\t  yb[1],\n\t\t\t\t  yb[2]-2.5/R\n\t\t\t\t  ])\n\treturn out1, out2\n\\end{lstlisting}\n\n% The two main functions used by \\li{bvp6c} are \\li{bvpinit} and \\li{deval}.\nThe two main functions used are \\li{ProblemDefinition} and \\li{solve}.\n% You will want to look at their docstrings to learn more about their functionality.\nThe function \\li{solve} requires an initial guess, which you will create in Problem \\ref{prob:reentry:guess}. \n\n% \\begin{lstlisting}\n%\n% options = struct()\n% # options include abstol, reltol, singularterm, stats, vectorized, maxnewpts,slopeout,xint\n% options.abstol, options.reltol = 1e-8, 1e-7\n% options.fjacobian = ode_auxiliary_jacobian\n% options.bcjacobian = bcs_auxiliary_jacobian\n% options.nmax = 2000\n%\n% solinit = bvpinit(np.linspace(0,1,100),initial_guess)\n% sol = bvp6c(ode,bcs,solinit,options)\n%\n% N = 240\n% xint = linspace(0,T0,N+1)\n% num_sol_auxiliary, _ = deval(sol,xint)\n%\n%\n% \\end{lstlisting}\n\n\\begin{lstlisting}\nproblem_auxiliary = bvp_solver.ProblemDefinition(num_ODE = 6,\n\t\t\t\t\t\t\t\t\t\t  num_parameters = 0,\n\t\t\t\t\t\t\t\t\t\t  num_left_boundary_conditions = 3,\n\t\t\t\t\t\t\t\t\t\t  boundary_points = (0, T0),\n\t\t\t\t\t\t\t\t\t\t  function = ode_auxiliary,\n\t\t\t\t\t\t\t\t\t\t  boundary_conditions = bcs_auxiliary)\n\nsolution_auxiliary = bvp_solver.solve(problem_auxiliary,\n\t\t\t\t\t\t\t\tsolution_guess = guess_auxiliary)\n\nN = 240\nt_guess = linspace(0,T0,N+1)\nguess = solution_auxiliary(t_guess)\n\\end{lstlisting}\n\n\n\n\n\n\n\n\\begin{figure}\n\\begin{minipage}[b]{.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{u_heuristic.pdf}\n\\caption*{Heuristic for the control $u$, provided by engineers. }\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{u_heuristic_smooth.pdf}\n\\caption*{A smooth initial approximation of the control.}\n\\end{minipage}\n\\caption{We construct a smooth estimate for the control $u$, by supposing the control has the form \n$u = p_1\\erf(p_2(p_3-t/T))$ and estimating parameters $p_1, p_2, p_3$.}\n\\label{fig:reentry:estimate_u}\n\\end{figure}\n\n\n\\begin{problem}\n\tComplete the function \\li{guess_auxiliary} given below. Then run the code above to check that your initial guess is adequate. \n\tThis function provides an initial guess to \\li{bvp_solver} for the auxiliary BVP described by  \\eqref{eqn:reentry:control_system_auxiliary} and \\eqref{eqn:reentry:BCs}.\n\tUse the heuristic data provided in Figure \\ref{fig:reentry:estimate_u} to find good estimates of $p_1, p_2,$ and $p_3$. \n\tUse Figure \\ref{fig:reentry:solutions} to estimate the trajectories of $y_1, y_2,$ and $y_3$. Hint: Try using the $\\tanh$ function.\n\t\n\\begin{lstlisting}\ndef guess_auxiliary(t):\n\tout = array([ .5*(.36+.27)-.5*(.36-.27)*tanh(.025*(t-.45*T_init)),\n\t\t\t# Finish this line, \n\t\t\t# And this one, \n\t\t\tp1*ones(t.shape),\n\t\t\tp2*ones(t.shape),\n\t\t\tp3*ones(t.shape)   ])\n\treturn out\n\\end{lstlisting}\t\n\t\\label{prob:reentry:guess}\n\\end{problem}\n\nAt this point we have constructed good initial guesses for the dependent variables $y_1,y_2, y_3,$ and $y_7$ (representing the total time of the manuever) in the original BVP \\eqref{eqn:reentry:full_system}. \nWe now need to construct initial guesses for the adjoint variables $y_4, y_5,$ and $y_6$. \n\nBy reexamining the condition $H_u = 0$, we find that the optimal control $u$ satisfies \n\\[\n\\sin u = \\frac{-0.6 y_5}{\\alpha} \\qquad \\cos u  = \\frac{-0.9 y_1y_4}{\\alpha}\n\\]\nwhere $\\alpha = \\sqrt{(0.6y_5)^2 + (0.9y_1y_4)^2}$.\nFrom this we know that $y_4 <0$, since $\\cos u >0$. A simple guess would be $y_4 = -1$. \n(Recall that the adjoint variables are unique up to some scaling.) \nWe can then approximate $y_5$ from the relationship \n\\begin{align*}\n\\tan u &= \\frac{6y_5}{9y_1y_4}.\n\\end{align*}\nTo approximate $y_6$, we use the identity $H = 0$.\n\n\n\\begin{problem}\n\tAdapt your previous code to solve the original, dimension seven BVP. \n\tUse the solution of the auxiliary BVP to construct a good initial guess.\n\tPlot the control $u$. How long does the reentry maneuver take? \n\\end{problem}\n\n", "meta": {"hexsha": "1b6e986af68a9be0831f92091bcfb7f6c0f34bdb", "size": 15396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol4B/OptimalReentry/OptimalReentry.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": "Vol4B/OptimalReentry/OptimalReentry.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": "Vol4B/OptimalReentry/OptimalReentry.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": 42.7666666667, "max_line_length": 351, "alphanum_fraction": 0.6913484022, "num_tokens": 4986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6863606147667376}}
{"text": "\\section{Confidence intervals}\n\nConfidence Intervals follow the form:\\\\\n\n(statistic) $\\pm$ (critical value)(estimated standard deviation of statistic)\\\\\n\nLet $\\displaystyle ( E,(\\mathbb{P}_{\\theta })_{\\theta \\in \\Theta })$ be a statistical  model based on observations $X_{1} , \\ldots X_{n}$  and assume $\\displaystyle \\Theta \\subseteq \\mathbb{R}$. Let $\\displaystyle \\alpha \\in ( 0,1)$.\\\\\n\\textbf{Non asymptotic} confidence interval of level $\\displaystyle 1-\\alpha $ for $\\displaystyle \\theta $:\\\\\nAny random interval $\\displaystyle \\mathcal{I}$, depending on the sample $X_{1} , \\ldots X_{n}$ but not at $\\displaystyle \\theta $ and such that:\\\\\n$\\mathbb{P}_{\\theta }[\\mathcal{I} \\ni \\theta ] \\geq 1-\\alpha ,\\ \\ \\forall \\theta \\in \\Theta$\\\\\nConfidence interval of \\textbf{asymptotic level} $\\displaystyle 1-\\alpha $  for $\\displaystyle \\theta $:\\\\\nAny random interval $\\displaystyle \\mathcal{I}$ whose boundaries do not depend on $\\displaystyle \\theta $ and such that: $\\lim _{n\\rightarrow \\infty }\\mathbb{P}_{\\theta } [\\mathcal{I} \\ni \\theta ]\\geq 1-\\alpha ,\\ \\ \\forall \\theta \\in \\Theta $\n\\subsection{Two-sided asymptotic CI}\nLet $X_1, \\ldots, X_n = \\tilde{X}$ and $\\tilde{X}\\stackrel{iid} {\\sim} P_{\\theta}$. A two-sided CI is a function depending on $\\tilde{X}$ giving an upper and lower bound in which the estimated parameter lies $\\mathcal{I} = [l(\\tilde{X},u(\\tilde{X})]$ with a certain probability $\\mathbb{P}(\\theta \\in  \\mathcal{I}) \\geq 1 -q_{\\alpha}$ and conversely $\\mathbb{P}(\\theta \\not\\in  \\mathcal{I}) \\leq \\alpha$\\\\\nSince the estimator is a r.v. depending on $\\tilde{X}$ it has a variance $Var(\\hat{\\theta}_n$ and a mean $\\mathbb{E}[\\hat{\\theta}_n]$. \nSince the CLT is valid for every distribution standardizing the distributions and massaging the expression yields an an asymptotic CI:\n\\begin{align*}\n\\mathcal{I} =  [&\\hat{\\theta}_n - \\frac{q_{\\alpha /2} \\sqrt{Var(X_i)} }{\\sqrt{n}},\\\\\n&\\hat{\\theta}_n + \\frac{q_{\\alpha /2} \\sqrt{Var(X_i)} }{\\sqrt{n}}]\n\\end{align*}\nThis expression depends on the real variance $Var(X_i)$ of the r.vs, the variance has to be estimated.\\\\\nThree possible methods: plugin (use sample mean or empirical variance), solve (solve quadratic inequality), conservative (use the theoretical maximum of the variance).\n\\subsection{Sample Mean and Sample Variance}\nLet $X_1, ..., X_n \\stackrel{iid}{\\sim} P_{\\mu}$, where $E(X_i)=\\mu$ and $Var(X_i)=\\sigma^2$ for all $i=1,2,...,n$\\\\\n\\textbf{Sample Mean:}\n\\begin{align*}\n\\bar{X}_n= \\frac{1}{n} \\sum_{i=1}^{n} X_i\n\\end{align*}\n\\textbf{Sample Variance:}\n\\begin{align*}\nS_n &= \\frac{1}{n} \\sum_{i=1}^{n} (X_i - \\bar{X}_n)^2\\\\ \n&= \\frac{1}{n} (\\sum_{i=1}^{n} X_i^2) - \\bar{X}_n^2\n\\end{align*}\n\\textbf{Unbiased estimator of sample variance:}\n\\begin{align*}\n\\tilde{S}_n &= \\displaystyle  \\frac{1}{n-1} \\sum _{i=1}^ n \\left(X_ i - \\overline{X}_ n\\right)^2\\\\\n&= \\frac{n}{n-1} S_n\n\\end{align*}\n\\subsection{Delta Method}\n\nTo find the asymptotic CI if the estimator is a function of the mean. Goal is to find an expression that converges a function of the mean using the CLT. Let $Z_n$ be a sequence of r.v. $\\sqrt(n) (Z_n-\\theta) \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,\\sigma^2)$ and let $g: R\\longrightarrow R$ be continuously differentiable at $\\theta$, then:\n\\begin{align*}\n&\\sqrt{n}(g(Z_n) - g(\\theta)) \\xrightarrow [n \\to \\infty ]{(d)}\\\\\n&\\mathcal{N}(0, g'(\\theta )^2 \\sigma ^2)\n\\end{align*}\n\\textbf{Example:} let  $X_1,... ,X_n ~ exp(\\lambda)$  where  $\\lambda>0$ . Let  $\\overline{X}_ n= \\frac{1}{n} \\sum _{i = 1}^ n X_ i$ denote the sample mean. By the CLT, we know that $\\sqrt{n}\\left(\\overline{X}_ n - \\frac{1}{\\lambda }\\right) \\xrightarrow [n \\to \\infty ]{(d)} N(0, \\sigma ^2)$ for some value of  $\\sigma^2$  that depends on  $\\lambda$.\n\nIf we set $g: \\displaystyle \\mathbb {R} \\to \\mathbb {R}$ and $\\displaystyle x \\mapsto 1/x,$ then by the Delta method:\n\n\\begin{align*}\n&\\sqrt{n}\\left( g(\\overline{X}_ n) - g\\left(\\frac{1}{\\lambda }\\right) \\right)\\\\\n&\\xrightarrow [n \\to \\infty ]{(d)} N(0, g'(E[X])^2\\textsf{Var}{X})\\\\\n&\\xrightarrow [n \\to \\infty ]{(d)} N(0, g'\\left(\\frac{1}{\\lambda }\\right)^2\\frac{1}{\\lambda ^2})\\\\\n&\\xrightarrow [n \\to \\infty ]{(d)} N(0, \\lambda^2)\n\\end{align*}", "meta": {"hexsha": "2b66c4f25029fac917ae19fe3f6f69b21580941d", "size": 4177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Confidence_intervals.tex", "max_stars_repo_name": "blechturm/MITx_capstone_1", "max_stars_repo_head_hexsha": "51d644cdecabb3cb7c8dedc5816359ba641a3d19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2020-03-30T18:06:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:11:56.000Z", "max_issues_repo_path": "content/Confidence_intervals.tex", "max_issues_repo_name": "tony-ml/MITx_capstone_1", "max_issues_repo_head_hexsha": "51d644cdecabb3cb7c8dedc5816359ba641a3d19", "max_issues_repo_licenses": ["MIT"], "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/Confidence_intervals.tex", "max_forks_repo_name": "tony-ml/MITx_capstone_1", "max_forks_repo_head_hexsha": "51d644cdecabb3cb7c8dedc5816359ba641a3d19", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2020-03-30T21:12:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-12T10:41:57.000Z", "avg_line_length": 75.9454545455, "max_line_length": 405, "alphanum_fraction": 0.6657888437, "num_tokens": 1500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6863606006655226}}
{"text": "% !TEX root = apxthy.tex\n\n\n\\section{Trigonometric Polynomials}\n%\n\\label{sec:trig}\n%\nIn this chapter we consider approximation of periodic functions by trigonometric\npolynomials (aka Fourier spectral methods). Throughout this chapter, let $\\TT :=\n(-\\pi, \\pi]$ and we identify $C^j(\\TT) = C^j_{\\rm per}(\\TT)$, $A_{\\rm per}(\\TT) =\nA(\\TT)$, $L^p(\\TT)$ to be the spaces of $2\\pi$-periodic functions on $\\R$ that\nare, respectively, $j$ times  continuously differentiable, analytic, belong\nto $L^p(-\\pi, \\pi)$. Similarly, $H^j_{\\rm per}(\\TT) = H^j(\\TT)$ denotes the\nspace of $2\\pi$ periodic functions on $\\R$ such that their restriction to {\\em\nany} interval $(a, a+2\\pi)$ belongs to $H^j(a,a+2\\pi)$.\n\nExamples of periodic functions:\n\\begin{itemize}\n  \\item $\\sin(nx) \\in A(\\TT)$\n  \\item $|\\sin(nx)| \\in C^{0,1}(\\TT)$\n  \\item $|\\sin(nx)|^3 \\in C^{2,1}(\\TT)$\n  \\item $e^{-\\cos x} \\in A(\\TT)$\n  \\item $(c^2+\\sin^2 x)^{-1} \\in A(\\TT)$\n  \\item \\dots\n\\end{itemize}\n\nApplications:\n\\begin{itemize}\n  \\item BVPs with periodic boundary conditions and periodic data, e.g.,\n  \\begin{align*}\n      - (p(x) u_{x})_x + q(x) u &= f(x), \\qquad x \\in (-\\pi, \\pi), \\\\\n      u(-\\pi) &= u(\\pi), \\\\\n      u'(-\\pi) &= u'(\\pi),\n  \\end{align*}\n  where $p, q, f$ are $2\\pi$-periodic, then under suitable conditions on\n  $p, q, f$ there exists a unique solution which is also $2\\pi$-periodic.\n  %\n  \\item Functions represented in polar coordinates: $u(x, y) = v(r, \\theta)$\n  then, for $r$ fixed, $\\theta \\mapsto v(r, \\theta)$ is periodic.\n\n  There are many other examples of naturally ``periodic'' coordinate systems,\n  including e.g. spherical coordinates, or the dihedral angle.\n  %\n  % \\item Bond-angles and dihedral\n\\end{itemize}\n\nApproximation by trigonometric polynomials is based on the idea of Fourier\nseries representation of periodic functions. Talking about Fourier series\nbecomes much more convenient if we extend the admissible range of all functions\nto $\\C$;, i.e. $f : \\R \\to \\C$, still $2\\pi$-periodic. The following definition then becomes natural.\n\n\\begin{definition}\n  A trigonometric polynomial of degree $N$ is any function of the form\n  \\[\n    \\sum_{k = -N}^N a_k e^{i k x}\n  \\]\n  The space of all such polynomials is denoted by  $\\Trig_N$.\n  The canonical basis is\n  \\[\n     \\b\\{ e^{ikx} \\bsep  k = -N, -N+1, \\dots, N \\b\\}\n  \\]\n\\end{definition}\n\n\\begin{definition}\n  Let $f \\in L^1(\\TT)$, then its {\\em Fourier coefficients} are given by,\n  \\begin{equation} \\label{eq:trig:fourier coeffs}\n    \\hat{f}_k := \\mint_{-\\pi}^\\pi f(x) e^{- i kx} \\,dx\n  \\end{equation}\n  The $N$-th partial sum, is a trigonometric polynomial, which we\n  denote by\n  \\[\n    \\Pi_N f(x) := \\sum_{n = -N}^N \\hat{f}_k e^{i kx}.\n  \\]\n\\end{definition}\n\n\n\n\\subsection{Approximation by $L^2$-projection}\n%\n\\label{sec:trig:L2}\n%\nWe will initially study approximation of functions in the $L^2$-norm.\nIt can then be convenient to normalise the inner product, via\n\\[\n  \\< f, g \\>_{L^2(\\TT)} := \\mint_{-\\pi}^\\pi f g^* \\, dx.\n\\]\nEquipped with this inner product, $L^2(\\TT)$ is a Hilbert space.\n\n\n\\begin{theorem} \\label{th:trig:plancherel}\n  \\begin{enumerate} \\ilist\n  \\item Convergence of Fourier Series: $\\{ e^{ikx} \\sep k \\in \\Z \\}$ is an orthonormal basis for $L^2(\\TT)$.\n  \\item Plancherel Theorem: $\\mathcal{F} : L^2(\\TT; \\C) \\to \\ell^2(\\Z; \\C)$ is an isomorphism;\n    i.e., $f \\in L^2(\\TT)$ then $\\hat{f} \\in \\ell^2(\\Z)$ and\n    \\[\n       \\sum_{k \\in \\Z} \\hat{f}_k \\hat{g}_k^* = \\mint_\\TT f g^* \\,dx.\n    \\]\n    In particular, $\\|f\\|_{L^2} = \\|\\hat{f} \\|_{\\ell^2}$.\n  \\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n  This is left as an exercise. The key point is that\n  \\begin{equation}\n    \\mint_{-\\pi}^\\pi  e^{-ikx} e^{i\\ell x} \\,dx\n    = \\mint_{-\\pi}^\\pi e^{(\\ell-i)x}\n    = \\cases{\n      1, & \\ell = k, \\\\\n      0, & \\text{otherwise.}\n    }\n  \\end{equation}\n\\end{proof}\n\n\\begin{exercise}\n  There is a general theorem that all (separable) Hilbert spaces are\n  isometrically isomorphic to $\\ell^2(\\N)$ or equivalently to $\\ell^2(\\Z)$.\n  Explain why the Plancherel theorem simply shows that the Fourier series map\n  $f \\mapsto \\hat{f}$ is an the explicit construction of this isometry.\n\\end{exercise}\n\n\n\\begin{proposition} \\label{th:trig:PiNf-orthproj}\n  Let $f \\in L^2(\\TT)$, then\n  \\begin{equation} \\label{eq:trip:PiNf-orthproj}\n    \\| \\Pi_N f - f \\|_{L^2}^2 = \\sum_{|k| > N} |\\hat{f}_k|^2.\n  \\end{equation}\n  In particular, $\\Pi_N f$ is the $L^2$-orthogonal\n  projection of $f$ onto $\\Trig_N$, or equivalently, the\n  best approximation of $f$ from $\\Trig_N$ w.r.t. $\\|\\cdot\\|_{L^2}$.\n\\end{proposition}\n\\begin{proof}\n  By definition,\n  \\begin{align*}\n    f(x) - \\Pi_N f(x) = \\sum_{|k|>N} \\hat{f}_k e^{ikx},\n  \\end{align*}\n  and Plancherel's theorem then implies \\eqref{eq:trip:PiNf-orthproj}.\n\n  The fact that $\\Pi_N f$ is the best approximation is a straightforward\n  consequence: if $g \\in \\Trig_N$, then\n  \\begin{align*}\n    \\b\\|f(x) - \\Pi_N f(x) - g\\b\\|_{L^2}^2\n    &= \\sum_{|k| \\leq N} |\\hat{g}_k|^2 + \\sum_{|k| > N} |\\hat{f}_k|^2 \\\\\n    &\\geq \\sum_{|k| > N} |\\hat{f}_k|^2 \\\\\n    &= \\b\\|f(x) - \\Pi_N f(x) \\b\\|_{L^2}^2. \\qedhere\n  \\end{align*}\n\\end{proof}\n\nThe main point of Lemma~\\ref{th:trig:PiNf-orthproj} is that, exactly as in the\nintroductory example, we can characterise the error in terms of the\ndecay of the Fourier coefficients, so we will study this next. \n\n\n\\subsection{Decay of Fourier Coefficients}\n%\n\\label{sec:trig:decay}\n%\nAs we already saw in the introductory example, the ``smoother'' $f$ is, the\nfaster $\\hat{f}_k$ decay. The following results are not difficult to generalise\nin several ways; see remarks below, but in the spirit of valuing simplicity over\noptimality, we will formulate them only for $C^p$ regularity.\n\n\\begin{theorem} \\label{th:trig:decay}\n  \\begin{enumerate} \\ilist\n    \\item Let $f \\in C^{p-1}(\\TT)$ and $f^{(p-1)}$ be absolutely continuous, then \n    \\[\n        |\\hat{f}_k| \\leq \\| f^{(p)} \\|_{L^1(\\TT)} |k|^{-p}.\n    \\]\n    %\n    \\item {\\it Paley--Wiener Theorem:} If $f \\in A(\\TT)$, then there exists\n    $a > 0$ such that\n    \\[\n        |\\hat{f}_k| \\lesssim e^{-a N}.\n    \\]\n  \\end{enumerate}\n\\end{theorem}\n\\begin{proof}[Proof of Theorem~\\ref{th:trig:decay}(1)]\n  Consider first the case $p = 1$, i.e., $f$ is absolutely continuous. This means that $f'$ exists almost everywhere and satisfies an integration by parts formula. We can utilize this as follows: \n  \\begin{align*}\n    -i k \\hat{f}_k &= \\mint f(x) \\big(- i k e^{-ikx}\\big) \\, dx \\\\\n    &= \\mint f(x) \\frac{d}{dx} e^{ikx}\\, dx \\\\\n    &= - \\mint f'(x) e^{ikx}\\, dx.\n  \\end{align*}\n  Taking the modulus on the left-hand side we obtain \n  \\[\n    |k \\hat{f}_k| \\leq \\mint |f'| \\,dx = \\|f'\\|_{L^1(\\TT)}.\n  \\]\n  Since $f'$ is AC, the right-hand side is finite. This yields the claim.\n\n  For $p > 1$, we can simply apply the integration by parts argument multiple times. \n\\end{proof}\n\nWe postpone the proof of the Paley--Wiener Theorem to\nTheorem~\\ref{th:trig:pw-trefversion}, but instead first discuss the consequences\nof these results. First, we consider approximation in the max-norm even though this seems counter intuitive in the Hilbert space setting.\n\nWe can also prove uniform convergence results using the decay of the Fourier coefficients established above:\n\n\\begin{theorem} \\label{th:trig:convergence_max}\n  \\begin{enumerate} \\ilist\n    \\item Let $f \\in W^{p,1}(\\TT)$ then\n    \\[\n        \\|f - \\Pi_N f \\|_{\\infty} \\lesssim N^{1-p}\n    \\]\n    \\item Let $f \\in C^\\infty(\\TT)$, then for each $p > 0$ there exists a\n    constant $C_p$ such that\n    \\[\n        \\|f - \\Pi_N f \\|_{\\infty} \\leq C_p N^{-p}.\n    \\]\n    \\item If $f \\in A(\\TT)$, then there exists $a > 0$ such that\n    \\[\n         \\| f - \\Pi_N f \\|_{\\infty} \\lesssim e^{-a N}.\n    \\]\n    \\end{enumerate}\n  \\end{theorem}\n\\begin{proof}\n  (1) This is a straightforward calculation: \n  \\begin{align*}\n    \\big|f(x) - \\Pi_N f(x)\\big|\n    &= \n    \\bigg| \\sum_{|k| > N} \\hat{f}_k e^{i k x} \\bigg| \n    \\\\ &\\leq\n    \\sum_{|k| > N} |\\hat{f}_k|\n    \\\\ &\\lesssim\n    \\sum_{k = N+1}^\\infty |k|^{-p} \\lesssim N^{-p}.\n  \\end{align*}\n\n  (2) is an immediate consequence; (3) is proven analogously. \n\\end{proof}\n\nReturning to convergence in $L^2$, a direct naive calculation shows that, if $f \\in W^{p,1}(\\TT)$, then\n\\[\n    \\|f - \\Pi_N f \\|_{L^2} \\lesssim N^{1/2-p}.\n\\]\nIs this sharp? Depends really on whether $f$ is {\\it exactly} in $W^{p,1}$ and no better. The tricky part is how one can really test this. In practice one actually rarely encounters functions of this kind (though in the theory of PDEs they are phenomenally important), and it is much more convenient and natural to consiter scales of continuous and H\\\"{o}lder continuous functions. In particular H\\\"{o}lder continuity connects very naturally to the kind of singularities one typically occurs in physical models. We will get to this soon. \n\nFor now, we will briefly look at two simple extensions that can be convenient sometimes and yield slightly sharper results. The proofs are left as exercises. \n\n  \n\\begin{lemma} \\label{th:trig:fCp-coeffL2}\n  Let $f \\in W^{p,2}(\\TT)$, then $(\\hat{f}_k |k|^p)_{k \\in \\Z} \\in \\ell^2(\\Z)$. \n\\end{lemma}\n% \\begin{proof}\n%   This is a relatively straightforward extension of the Proof of\n%   Theorem~\\ref{th:trig:decay}(1) and is left as an exercise.\n% \\end{proof}\n\n\n\\begin{theorem} \\label{th:trig:convergence_L2}\n  Let $f \\in W^{p,2}(\\TT)$ then\n  \\[\n      \\|f - \\Pi_N f \\|_{L^2} \\lesssim N^{-p}\n  \\]  \n\\end{theorem}\n% \\begin{proof}\n%   We only prove (1); the results (2, 3) are left as an exercise.\n\n%   From Lemma~\\ref{th:trig:PiNf-orthproj} we have\n%   \\begin{align*}\n%     \\|f-\\Pi_N f \\|_{L^2}^2\n%     &= \\sum_{|k| > N} |\\hat{f}_k|^2 \\\\\n%     &= \\sum_{|k| > N} |\\hat{f}_k|^2 |k|^{2p} |k|^{-2p} \\\\\n%     &\\lesssim N^{-2p},\n%   \\end{align*}\n%   where we used Lemma~\\ref{th:trig:fCp-coeffL2} in the last step.\n% \\end{proof}\n\n\n\n\n\n\\subsubsection{Remarks}\n\\begin{enumerate}\n  \\item The algebraic convergence rates are rarely sharp, in the sense that taking an arbitrary function and showing that it is $W^{p,2}, W^{p,1}$ but no better in any way would be a rarity. The\n    precise structure of $f^{(p)}$ is extremely relevant. One could go into fractional Sobolev spaces, to give a finer control, but we will not pursue this for now. \n  \n    % For example, one can\n    % show that, if $f^{(p-1)}$ is absolutely continuous (or even just of bounded variatin)\n    % then the decay rate $|\\hat{f}_k| \\leq \\|f^{(p)}\\|_{L^1} N^{-p}$ still holds.\n    % In particular, if $f^{(p)} \\in C(\\TT)$ as we have assumed here, this gives\n    % additional structure that we have not exploited.\n\n  \\item The important main message take away from these results is this: (1) $f \\in C^p(\\TT)$ regularity\n  gives algebraic decay of $\\hat{f}_k$; (2) $f \\in C^\\infty(\\TT)$ gives\n  super-algebraic decay; (3) $f \\in A(\\TT)$ gives exponential decay.\n\n  % \\item We can also derive uniform approximation error estimates which further\n  % highlight that our results are not sharp, e.g.,  if $f \\in C^p(\\TT)$, then\n  % \\[\n  %   |f(x) - \\Pi_N f(x)| \\leq \\sum_{|k| > N} |\\hat{f}_k|\n  %       \\lesssim \\sum_{|k| > N} |k|^{-p}\n  %       \\lesssim N^{1-p}.\n  % \\]\n  % In the next section we will show how to construct much better uniform\n  % approximations with sharp rates. Using a similar trick as in the proof of\n  % Theorem~\\ref{th:trig:convergence_L2} we can improve this to $\\|f-\\Pi_N f\n  % \\|_\\infty \\lesssim N^{1/2-p}$. Getting a little deeper into harmonic analysis\n  % we may even prove that $|\\hat f_k| |k|^p \\in \\ell^p$ for all $p > 1$, which\n  % indeed implies that $\\|f - \\Pi_N f \\|_\\infty \\lesssim N^{\\epsilon - p}$ for\n  % all $\\epsilon > 0$. This give us a hint that the best approximation error in\n  % the max-norm is in fact $O(N^{-p})$ when $f \\in C^p$. We will choose a very\n  % different route in \\S~\\ref{sec:trig:jackson} to prove this result.\n\n  \\item The uniform convergence estimate for analytic functions arising from\n  the Paley--Wiener theorem is however qualitatively sharp.\n\n  \\item The condition $f \\in W^{p,1}$ is not sharp. One can weaken it to require only that $f^{(p-1)}$ has finite total variation. We will not look at this in generality, but consider a special case of this generalisation in Exercise~\\ref{exr:trig:gibbs}.\n\\end{enumerate}\n\n\n\\subsection{The Paley--Wiener Theorem}\n%\n\\label{sec:trip:pw}\n%\nIf $f$ is analytic on an interval $[a, b]$, then standard theorems of complex\nanalysis imply the it can be extended to a analytic function in a\nneighbourhood $U$ of $[a, b]$. In the case of periodic functions, such a\nneighbourhood can be chosen to be a strip,\n\\[\n  \\Omega_\\alpha := \\{ z \\in \\C \\sep |\\Im z| < \\alpha \\},\n\\]\nfor some $\\alpha > 0$. This is the starting point for a more refined\nversion of Theorem~\\ref{th:trig:decay}(2).\n\n\\begin{theorem} \\label{th:trig:pw-trefversion}\n  Suppose that $f$ is analytic in $\\Omega_\\alpha$ with\n  $\\sup_{z \\in \\Omega_\\alpha} |f(z)| = M_\\alpha$, then\n  \\[\n    |\\hat{f}_k| \\leq 2\\pi M_\\alpha e^{-\\alpha|k|}.\n  \\]\n\\end{theorem}\n\\begin{proof}\n  Assume $k > 0$; the case $k < 0$ is analogous.\n  Recall that\n  \\[\n    \\hat{f}_k = \\frac{1}{2\\pi} \\int_{-\\pi}^\\pi f(x) e^{-ikx} \\,dx.\n  \\]\n  We fix some $\\beta < \\alpha$ and define a complex contour\n  \\[\n    \\mathcal{C} := (-\\pi, \\pi] \\cup (\\pi, \\pi+ \\beta i]\n        \\cup (-\\pi + \\beta i, \\pi + \\beta i] \\cup (-\\pi, -\\pi + \\beta i]\n      = \\mathcal{C}_{1} \\cup \\mathcal{C}_{2}\n        \\cup \\mathcal{C}_{3} \\cup \\mathcal{C}_{4},\n  \\]\n  to be traversed counterclockwise. In particular $\\frac{1}{2\\pi i} \\int_{\\mathcal{C}_1} f(z) e^{ikz} \\, dz = \\hat{f}_k$, and periodicity of $f$ yields\n  \\[\n      \\sum_{j \\in \\{2, 4\\}}  \\int_{\\mathcal{C}_j} f(z) e^{ikz} \\, dz = 0.\n  \\]\n  Combining these observations with Cauchy's theorem yields\n  \\begin{align*}\n      0\n      &= \\frac{1}{2\\pi} \\oint_{\\mathcal{C}} f(z) e^{ikz} \\, dz \\\\\n      &= \\sum_{j = 1}^4\\frac{1}{2\\pi} \\int_{\\mathcal{C}_j} f(z) e^{ikz} \\, dz  \\\\\n      &= \\hat{f}_k + \\frac{1}{2\\pi} \\int_{-\\pi}^\\pi f(x + \\beta i) e^{i (x+\\beta i) k} \\, dx.\n  \\end{align*}\n  Since we assumed that $k > 0$ we have $|e^{i (x+\\beta i)k}| = e^{-\\beta k}$, hence\n  rearranging the previous identity yields the estimate\n  \\begin{align*}\n    |\\hat{f}_k| &\\leq \\mint_{-\\pi}^\\pi |f(x+\\beta i)| e^{-\\beta k} \\,dx\n      \\leq M_\\beta e^{-\\beta k}.\n  \\end{align*}\n  Since the upper bound valid for all $\\beta < \\alpha$ it also holds for $\\beta\n  = \\alpha$.\n\\end{proof}\n\nThe previous theorem clarifies that, to precisely understand the\nbest-approximation of an analytic function $f$ by  trigonometric polynomials\nwe {\\em must} study $f$ not on $\\TT$ but in the complex plane. While some\nfurther generalisations are possible, we will restrict ourselves mostly\nto the context of Theorem~\\ref{th:trig:pw-trefversion} and thus look for the\nlargest $\\alpha$ such that $f$ can be extended to a analytic function\non $\\Omega_\\alpha$.\n\nSuppose we have found an $\\alpha$ such that $f \\in A(\\Omega_\\alpha)$. If $f$\nblows up at some $x \\pm i \\alpha$ then we have found the maximal region of\nanalyticity. If $f$ is bounded in $\\Omega_\\alpha$ then it is analytic at every\npoint $z \\in \\partial \\Omega_\\alpha$ and hence we can extend $f$ to a\nanalytic function in a larger domain $\\Omega_{\\alpha'}$, $\\alpha' > \\alpha$.\nThus, to determine the maximal region of analyticity we must find the {\\em\npoles} of $f$. We obtain the following simple corollary of Theorem~\\ref{th:trig:pw-trefversion}.\n\n\\begin{corollary} \\label{th:trig:pw-sharp}\n  Let $f \\in A(\\TT) \\cap A(\\Omega_\\alpha)$ with $\\alpha$ maximal, then\n  for all $\\epsilon > 0$ there exists $C_\\epsilon > 0$ such that\n  \\[\n    |\\hat{f}_k| \\leq C_\\epsilon e^{- (\\alpha-\\epsilon) |k|}.\n  \\]\n  Moreover, we have the approximation error estimate\n  \\[\n    \\| f - \\Pi_N f \\|_{L^\\infty} \\lesssim C_\\epsilon' e^{-(\\alpha-\\epsilon) N}\n    \\qquad \\forall \\epsilon > 0.\n  \\]\n\\end{corollary}\n\n\\begin{example}[Smeared Zig-Zag]\n  Consider a family of periodic functions inspired by our introductory example,\n  \\[\n    f(x) = (1 + c^2 \\sin^2 x)^{-1},\n  \\]\n  where $c > 0$. Then the analytic extension is still given by $f(z) = (1 + c^2\n  \\sin^2 z)^{-1}$. To find the maximal strip of analyticity we need to compute\n  the poles, i.e., the points $z \\in C$ such that $\\eps^2 + \\sin^2 z = 0$, or\n  equivalently $\\sin z = \\pm i \\eps$, where $\\eps = 1/c$.\n\n  To that end, we first note that\n  \\[\n    \\sin z = \\sin (x + i y) = \\sin x \\cosh y + i \\b\\{ \\cos x \\sinh y \\b\\}.\n  \\]\n  Thus the poles are given by the solutions to\n  \\[\n       \\sin x \\cosh y = 0, \\qquad \\qquad\n       \\cos x \\sinh y = \\pm \\eps.\n  \\]\n  Since $\\cosh y \\neq 0$, The first condition requires $\\sin x = 0$, or,\n  $x \\in \\pi \\Z$, hence $\\cos x = \\pm 1$. The second condition therefore\n  yields $\\sinh y = \\pm \\eps$, or, equivalently,\n  \\[\n      x \\in \\pi \\Z, \\qquad y = \\pm \\sinh^{-1} \\eps.\n  \\]\n  This characterises all the poles of $f(z)$, and in particular shows that\n  the maximal strip of analyticity is\n  \\[\n      \\Omega_{\\sinh^{-1} \\eps}\n  \\]\n  Our theory therefore predicts (ignoring the $\\epsilon$-factors) that\n  \\[\n      |\\hat{f}_k| \\lesssim e^{- \\sinh^{-1} \\eps |k|}\n            \\sim e^{- \\eps |k|} = e^{-|k|/c} \\qquad \\text{for $\\eps \\sim 0$}\n  \\]\n  as well as the approximation error estimate\n  \\[\n      \\| f - f_N \\|_\\infty \\lesssim e^{- \\sinh^{-1} \\eps N} \\sim e^{- \\eps |k|}\n      = e^{-|k|/c}\n      \\qquad \\text{for $\\eps \\sim 0$.}\n  \\]\n  After discussing trigonometric interpolation we will show numerical\n  tests demonstrating that this is sharp.\n\\end{example}\n\n\nFinally, it is also natural to ask about the case when $f$ is entire, i.e.,\n$f \\in A(\\Omega_\\alpha)$ for all $\\alpha > 0$. In this case, we simply\nobtain \\Cref{th:trig:pw-sharp} with $\\alpha = \\infty$:\n\n\\begin{corollary} \\label{th:trig:pw-entire}\n  Suppose that $f \\in A(\\TT) \\cap A(\\C)$  (i.e., $f$ is entire), then for all\n  $\\alpha > 0$ there exists $C_\\alpha > 0$ ($C_\\alpha =\n  \\|f\\|_{L^\\infty(\\Omega_\\alpha)}$ such that\n  \\[\n      |\\hat{f}_k| \\lesssim C_\\alpha e^{-\\alpha |k|}.\n  \\]\n\\end{corollary}\n\n\n\n\n\\subsection{Approximation by convolution: Jackson's Theorem}\n%\n\\label{sec:trig:jackson}\n%\nThe $L^2$-projection operator $\\Pi_N$ can be written in terms of the {\\em Dirichlet Kernel}, \n\\[\n    D_N(x) = \\frac{\\sin\\b( (N+1/2) x \\b)}{ \\sin(x/2) }.\n\\]\nThat is, \n\\[\n  \\Pi_N f(x) = D_N \\ast f(x) := \\mint_{-\\pi}^\\pi D_N(x-t) f(t) \\, dt. \n\\]\nSee Exercise~\\ref{exr:trig:dirichlet} for the details. An analysis of the fine properties of the kernel $D_N$ leads to more precise convergence estimates, in particular in norms other than $L^2$. \n\nSuppose, for example that we wanted to get an optimal estimate for $\\| f - \\Pi_N f \\|_\\infty$, then we can estimate (similar as we do for estimating the interpolation error!)\n\\[\n  \\| f - \\Pi_N f \\|_\\infty\n  \\leq \n  \\| f - t_N \\|_\\infty + \\| \\Pi_N (t_N - f) \\|_\\infty. \n\\]\nMoreover, \n\\[\n  | \\Pi_N g(x) | = \\bigg| \\mint D_N(x - t) g(t) \\,dt \\bigg| \n    \\leq \\| D_N \\|_{L^2(\\TT)} \\|g \\|_\\infty, \n\\]\nand hence, \n\\[\n  \\| f - \\Pi_N f \\|_\\infty \\leq (1 + \\|D_N\\|_{L^1}) \\| t_N - f \\|_\\infty,\n\\]\ni.e. the $L^2$ projection $\\Pi_N f$ is optimal up to a constant factor $C_N = 1 + \\|D_N\\|_{L^1}$. It turns out that $\\|D_N\\|_{L^1} \\approx \\log N$, which means we are really {\\em very close} to optimal (again, see Exercise~\\ref{exr:trig:dirichlet}). But it is still interesting to ask whether this log-factor can be removed!\n\nIn general, we can ask whether alternative kernels could be employed to construct approximations via convolutions, \n\\[\n    (K_N \\ast f)(x) := \\mint_{-\\pi}^\\pi K_N(x-t) f(t) \\, dt,\n\\]\nand what advantages those different kernels might have. \nIf $K_N(t)$ is a trigonometric polynomial, then $K_N \\ast f$ will also be a trigonometric polynomial:\n\n\\begin{lemma}\n  If $K_N \\in \\Trig_N$, then $K_N \\ast f \\in \\Trig_N$ for\n  all $f \\in L^1(\\TT)$.\n\\end{lemma}\n\\begin{proof}\n  \\begin{align*}\n    \\mint_{-\\pi}^\\pi K_N(x-t) f(t) \\,dt\n    &=\n    \\sum_{k =  -N}^N \\sum_{k' \\in \\Z}\n        \\hat{K}_{N,k} \\hat{f}_{k'} \\mint_{-\\pi}^\\pi e^{ik(x-t)} e^{ik't}\\,dt\n    \\\\ &=\n    \\sum_{k =  -N}^N \\sum_{k' \\in \\Z}\n       \\hat{K}_{N,k} \\hat{f}_{k'} e^{ikx} \\delta_{kk'}\n    \\\\ &=\n    \\sum_{k = -N}^N \\hat{K}_{N,k} \\hat{f}_{k} e^{ikx}. \\qedhere\n  \\end{align*}\n\\end{proof}\n\n\nThere is considerable freedom in the choice of kernel; the only thing they all have in common is that they must approximate the Dirichlet-delta function in a suitable sense. Purely for the purpose of theoretical analysis, a great choice is the Jackson kernel,\n\\[\n    J_M(x) := \\gamma_M \\left( \\frac{\\sin( Mx/2)}{\\sin(x/2)} \\right)^4,\n    \\qquad\n    \\mint_\\TT J_M(x) = 1,\n\\]\nwhere the second condition determines the normalisation constant $\\gamma_M$.\nConstructing approximates via the Jackson kernel leads to elegant and\nsharp approximation error estimates in the max-norm in particular for H\\\"{o}lder continuous functions. Note already that we now have $\\| J_M \\|_{L^1} = 1$, i.e. we no longer have the growth of the operator norm as in the Dirichlet kernel!\n\nWe write $J_M$ instead of $J_N$ since the degree of $J_M$ is {\\em not} equal to $M$:\n\n\\begin{lemma}\n  $J_M \\in \\Trig_{2M-2}$.\n\\end{lemma}\n\\begin{proof}\n  Let $z = e^{ix/2}$, then\n  \\[\n      J_M(x)\n      =\n      \\left((z^M - z^{-M}) / (z - z^{-1})\\right)^4.\n  \\]\n  Further, we have\n  \\begin{align*}\n    % J_M(x)\n    % &=\n    \\frac{z^M - z^{-M}}{z - z^{-1}}\n    &= z^{M-1} + z^{M-3} z^{-1} + z^{M-3} z^{-2} + \\dots\n      + z z^{-M+2} + z^{-M+1} \\\\\n    &= z^{M-1} + z^{M-3} + z^{M-5} + \\dots + z^{-M+1}\n    = \\sum_{\\alpha \\in \\mathcal{A}} z^\\alpha,\n  \\end{align*}\n  where $\\mathcal{A} := \\{-M+1, -M+3, -M+5, \\dots, M-1\\}$. Squaring yields\n  \\begin{align*}\n     \\left(\\frac{z^M - z^{-M}}{z - z^{-1}} \\right)^2\n     &=\n     \\sum_{\\alpha, \\beta \\in \\mathcal{A}}\n     z^\\alpha z^{\\beta} \\\\\n     &= \\sum_{\\alpha, \\beta \\in \\mathcal{A}}\n     \\frac{z^{\\alpha +\\beta} + z^{-\\alpha-\\beta}}{2} \\\\\n     &= \\sum_{\\alpha, \\beta \\in \\mathcal{A}} \\cos\\b( \\smfrac{\\alpha+\\beta}{2} x \\b).\n   \\end{align*}\n   Since $\\alpha+\\beta$ is always even, it follows that\n   $(\\frac{z^M - z^{-M}}{z - z^{-1}} )^2 \\in \\Trig_{M-1}$ and in particular\n   $J_M \\in \\Trig_{2M-2}$.\n\\end{proof}\n\n\n\n\\begin{lemma} \\label{th:trig:gammaM_bound}\n  There exist $C_1, C_2 > 0$, independent of $M$ such that\n  \\[\n    C_1 M^{-3} \\leq  \\gamma_M \\leq C_2 M^{-3}\n  \\]\n\\end{lemma}\n\\begin{proof}\n  First note the geometrically evident fact that\n  \\[\n    x/\\pi \\leq \\sin(x/2) \\leq x/2.\n  \\]\n\n  To obtain a lower bound, we estimate \n  \\begin{align*}\n    \\pi/\\gamma_m &= \\int_0^\\pi \\left( \\frac{\\sin( Mx/2)}{\\sin(x/2)} \\right)^4 dx \\\\\n    &= \\int_0^{\\pi/M} \\left( \\frac{\\sin( Mx/2)}{\\sin(x/2)} \\right)^4 dx  \n        + \\int_{\\pi/M}^\\pi \\left( \\frac{\\sin( Mx/2)}{\\sin(x/2)} \\right)^4 dx  \\\\\n        %\n    &\\lesssim\n        \\bg[ \\int_0^{\\pi/M} \\left( \\frac{Mx/2}{x/2} \\right)^4 \\, dx\n        + \\int_{\\pi/M}^{\\pi}\n             \\bg( \\frac{1}{x} \\bg)^4 \\, dx \\bg] \\\\\n    &= c_1 M^3.\n  \\end{align*}\n  Note in particular that this calculation shows that for the opposite bound \n  we only need to consider the interval $(0, \\pi/M)$. Thus, we calculate\n  \\begin{align*}\n    \\pi/\\gamma_M\n    % &= \\int_0^\\pi  \\left( \\frac{\\sin( Mx/2)}{\\sin(x/2)} \\right)^4 \\, dx  \\\\\n    &\\geq \\int_0^{\\pi/M} \\left( \\frac{\\sin( Mx/2)}{\\sin(x/2)} \\right)^4 \\, dx \\\\\n    &\\gtrsim \\int_0^{\\pi/M} \\left( \\frac{Mx/2}{x/2} \\right)^4 \\, dx \\\\\n    &=c_2 M^3. \\qedhere\n  \\end{align*}\n\\end{proof}\n\nThe next Lemma is key, and hidden in its proof is the reason that we used the fourth power to define the Jackson kernel. It quantifies the fact (already exploited above) that $J_M$ is concentrated near the origin. \n\n\\begin{lemma} \\label{th:trig:jackson_moments}\n  There exists a constant $C > 0$ such that \n  \\begin{align*}\n    \\mint J_M(x) \\,dx &= 1, \\qquad \\text{and}\n    \\\\\n    \\mint |x| J_M(x) \\, dx &\\leq C M^{-1}.\n  \\end{align*}\n\\end{lemma}\n\\begin{proof}\n  The case $m = 0$ follows immediately  from the normalisation of the\n  Jackson kernel, $\\int_{-\\pi}^\\pi J_M(x)\\,dx = 1$.\n\n  The case $m = 1$ can be seen by a variation of the proof of\n  Lemma~\\ref{th:trig:gammaM_bound}:\n  \\begin{align*}\n    \\int_0^\\pi x J_M(x) \\, dx\n    &= \n    \\int_0^{\\pi/M} x J_M(x) \\, dx\n        + \\int_{\\pi/M}^{\\pi}\n             x J_M(x) \\, dx \\\\\n    &\\lesssim\n        \\gamma_M \\bg[ \\int_0^{\\pi/M} x M^4 \\, dx\n        + \\int_{\\pi/M}^{\\pi}\n             x \\bg( \\frac{1}{x} \\bg)^4 \\, dx \\bg] \\\\\n    &\\lesssim\n      M^{-3} \\b[ M^{2} + M^{2} \\b]\n      \\lesssim M^{-1}.\n      \\qedhere\n  \\end{align*}\n\\end{proof}\n\nTo state the Jackson theorems we first need to adapt the notion of modulus of continuity to the torus: Namely, we require that $\\omega$ is a modulus of continuous for $f$ on all of $\\mathbb{R}$. It is clear that all properties of the modulus of continuity survive, including the fact that any $f \\in C(\\TT)$ has such a m.o.c.\n\n\\begin{theorem}[Jackson's Theorem] \\label{th:trig:jackson}\n  \\begin{enumerate}\n  \\item Let $f \\in C(\\TT)$ with modulus of continuity $\\omega$, then\n  \\[\n      \\| f - J_M \\ast f \\|_\\infty \\lesssim \\omega(M^{-1})\n  \\]\n  In particular, if $f \\in C^{0,\\sigma}(\\TT)$, then\n  \\[\n      \\|f - J_M \\ast f \\|_\\infty \\lesssim N^{-\\sigma},\n  \\]\n  and if $f \\in C^1(\\TT)$, then\n  \\begin{equation} \\label{eq:trig:jackson:C1-version}\n    \\|f - J_M \\ast f \\|_\\infty \\lesssim M^{-1} \\|f'\\|_\\infty.\n  \\end{equation}\n  \\item Let $f \\in C^p(\\TT)$ and $f^{(p)}$ have modulus of continuity $\\omega$,\n  then\n  \\[\n      \\inf_{t_N \\in \\Trig_N} \\| f - t_N \\|_\\infty\n        \\lesssim N^{-p} \\omega(N^{-1}).\n  \\]\n  % \\[\n  %     \\| f - J_N\\ast f \\|_\\infty \\lesssim N^{-p} \\omega(N^{-1}).\n  % \\]\n  \\end{enumerate}\n\\end{theorem}\n\\begin{proof}[Proof of Theorem~\\ref{th:trig:jackson}(1)]\n  Recall that the polynomial degree of $J_M \\ast f$ is $N = 2M-2$. For $N$ even we take $M = N/2+1$ while for $N$ odd we take $M = (N+1)/2+1$. Either way, $N \\geq 2M-2$.\n\n  \\begin{align*}\n    \\b| J_M \\ast f(x) - f(x) \\b|\n    &=\n    \\bg| \\int_{-\\pi}^\\pi \\B( f(x-t) - f(x) \\B) J_M(t) \\, dt \\bg| \\\\\n    &\\leq\n    \\int_{-\\pi}^\\pi \\b|f(x-t) - f(x) \\b| J_M(t) \\, dt.\n  \\end{align*}\n  Next, we can use the modulus of continuity to estimate\n  \\[\n    \\b|f(x-t) - f(x) \\b| \\leq \\sum_{k = 1}^K\n      \\b| f(x - kt/K) - f(x - (k-1)t/K) \\b|\n    \\leq K \\omega(t/K) \n    % \\leq K \\omega(\\pi/K).\n  \\]\n  Choosing $K$ minimal such that $t/K \\leq 1/N$ (i.e. $K = \\lceil t N \\rceil$) yields \n  \\[\n    \\b|f(x-t) - f(x) \\b| \\leq\n      \\cases{\n        \\omega(N^{-1}), & 0 \\leq |t| \\leq N^{-1}, \\\\\n        2 t N \\omega(N^{-1}), & |t| > N^{-1}.\n      }\n  \\]\n  Using Lemma~\\ref{th:trig:jackson_moments} we conclude\n  \\begin{equation} \\label{eq:trig:jackson1_proof_result}\n    \\b| J_N \\ast f(x) - f(x) \\b|\n    \\leq\n      \\omega(N^{-1}) \\int_0^{1/N} J_N(t) \\, dt\n      + 2 N \\omega(N^{-1}) \\int_{1/N}^{\\pi} t J_N(t)\\, dt\n    \\lesssim \\omega(N^{-1}). \n  \\end{equation}\n  The stated results follow immediately from the fact that $\\omega(N^{-1}) \\leq \\omega(M^{-1})$. For later reference though we will also need \\eqref{eq:trig:jackson1_proof_result}.\n\\end{proof}\n\n\nTo prove Theorem~\\ref{th:trig:jackson} (2), we need another auxiliary\nresults that is also of independent interest.\n\n\\begin{lemma} \\label{th:trig:jackson-auxEN}\n  Let $E_N(f) := \\inf_{t_N \\in \\Trig_N} \\|f - t_N \\|_\\infty$, then for\n  $f \\in C^1(\\TT)$ we have\n  \\[\n    E_N(f) \\lesssim N^{-1} E_N(f').\n  \\]\n\\end{lemma}\n\\begin{proof}\n  Let $q \\in \\Trig_N$ such that\n  \\[\n    \\|f' - q\\|_\\infty = E_N(f').\n  \\]\n  (Because $\\Trig_N$ is finite-dimensional, we know the best approximation\n  error is attained.) Then we can write\n  \\[\n    q(x) = \\sum_{k = -N}^N \\hat{q}_{k} e^{ikx}.\n  \\]\n  We wish to write $q =  t_N'$, but this is in general false if $\\hat{q}_0 \\neq 0$. Instead, we split\n  \\[\n    q(x) = \\hat{q}_0 + r(x),\n  \\]\n  then $\\hat{r}_0 = 0$ and hence there exists $t \\in \\Trig_N$ such  that $t' =  r$. Moreover, we can estimate\n  \\[\n    |\\hat{q}_0| = \\bg| \\mint_{-\\pi}^\\pi q \\,dx \\bg|\n      = \\bg| \\mint_{-\\pi}^\\pi (q-f') \\,dx \\bg|\n      \\leq E_N(f').\n  \\]\n  Combining these manipulations we obtain\n  \\[\n    \\| f' - t'\\|_\\infty\n    \\leq\n    \\| f' - q \\|_\\infty + |\\hat{q}_0|\n    \\lesssim 2 E_N(f').\n  \\]\n\n  Finally, since $t \\in \\Trig_N$ we have $E_N(f) = E_N(f - t)$ and can therefore conclude, using Jackson's first theorem,\n  \\[\n    E_N(f) = E_N(f - t)\n    \\lesssim N^{-1} \\|f' - t'\\|_\\infty\n    \\lesssim N^{-1} E_N(f').\n  \\]\n  where we also used that $r \\mapsto \\|f'-t'\\|_\\infty r$ is the modulus of continuity for $f - t$.\n\\end{proof}\n\n\n\\begin{proof}[Proof of Theorem~\\ref{th:trig:jackson} (2)]\n  According to Lemma~\\ref{th:trig:jackson-auxEN},\n  \\[\n    E_N(f) \\lesssim N^{-1} E_N(f') \\lesssim \\dots \\lesssim \n    N^{-p} E_N(f^{(p)}),\n  \\]\n  and according to Jackson's first theorem, for some $M \\sim N$,\n  \\[\n    E_N(f^{(p)}) \\leq \\| f^{(p)} - J_M \\ast f^{(p)} \\|_\\infty\n      \\leq \\omega(M^{-1}) \\lesssim \\omega(N^{-1}),\n  \\]\n  that is, $E_N(f) \\lesssim N^{-p} \\omega(N^{-1})$.\n  %\n  % Note that this does not yet prove our statement. To prove\n  % Theorem~\\ref{th:trig:jackson} (2), let $t_N \\in \\Trig_N$ such that\n  % $\\|f - t_N \\|_\\infty \\leq C N^{-p} \\omega(N^{-1})$, then we have\n  % \\[\n  %   \\| f - J_M \\ast f \\|_\\infty\n  %     \\leq \\| f - t_N \\|_\\infty + \\| J_M \\ast (f - t_N) \\|_\\infty\n  %         + \\|t_N - J_M \\ast t_N \\|_\\infty\n  % \\]\n\\end{proof}\n\n\n\n\n\n\n\\subsection{Interpolation}\n%\n\\label{sec:trig:interp}\n%\nWe have discussed two strategies to construct approximations of functions by\ntrigonometric polynomials: $L^2$-projection and convolution (e.g., with the\nJackson kernel). While both appear to be constructive, they both require additional\ncomputational effort to evaluate the relevant integrals. Since this is normally\ndone via numerical quadrature, additional errors will be introduced that\nneed to be analysed separately. All this can be done, but it turns out that\na much more practical and performant approach that gives ``near-optimal''\napproximants (most of the time) is nodal interpolation.\n\nTo specify a trigonometric polynomial $t \\in \\Trig_N$ we need to determine\n$2N+1$ coefficients, which should be possible using $2N+1$ function values,\ni.e., we may choose $2N+1$ nodes $x_0, \\dots, x_{2N} \\in (-\\pi, \\pi]$\nand specify\n\\[\n    t(x_j) = F_j,\n\\]\nwith $F_j$ some prescribed function values. If the $x_j$ are distinct, then it\nis easy to prove (see below and Exercise~\\ref{exr:poly:interpunique}) If $F_j =\nf(x_j)$ for some $f \\in C(\\TT)$ the we call the resulting $t$ a {\\em nodal\ninterpolant}.\n\nAn important question is how we can transform the nodal values into coefficients\nfor the trigonometric polynomial. Naively, this can be achieved by simply\nsolving a linear system for the coefficients at $O(N^3)$ cost:\nLet $t(x) = \\sum_{k = -N}^N \\hat{F}_k e^{ik x}$, then\n\\begin{equation} \\label{eq:trig:pre-dft}\n  \\sum_{k = -N}^N \\hat{F}_k e^{i\\pi x_j} = F_j.\n\\end{equation}\n\n% It is straightforward to see (we will return to this in \\S~\\ref{sec:trig:fft}\n% that the inversion formula is\n% \\begin{equation} \\label{eq:trig:pre-idft}\n%     \\hat{F}_k = \\frac{1}{2N} \\sum_{j = -N+1}^N F_j e^{-i\\pi k/N},\n% \\end{equation}\n% that is, the linear system \\eqref{eq:trig:pre-dft}  has an orthogonal (up to\n% scaling) which reduces the solution of the linear system matrix reduces the\n% solution of \\eqref{eq:trig:pre-dft} to a matrix-vector multiplication\n% \\eqref{eq:trig:pre-idft} and hence $O(N^2)$ cost. But it turns out that there is\n% even an $O(N \\log N)$ algorithm - the Fast Fourier Transform. To present this\n% important algorithm it is more convenient if we work with $2N$ interpolation\n% nodes, instead of $2N+1$ nodes. This makes the theory of interpolation subtly\n% different, since with $2N$ conditions we can no longer hope to determing $2N+1$\n% coefficients.\n\n\nThe first question to ask then is how to choose the interpolation nodes. Because\non the torus no part of the domain is ``special'', it seems intuitive that\nwithout any additional information about the target function equispaced nodes\nmust be ``generically optimal''. We will prove in the remainder of this section\nthat it is in fact optimal up to a logarithmic factor, but will also return to a\nmore careful discussion of different choices of interpolation nodes in\n\\S~\\ref{sec:poly}. Moreover, equispaced nodes also lead to fast algorithms (FFT)\nfor solvig \\eqref{eq:trig:pre-dft}, but this requires some specific choices and\nsome slightly annoying, but actually natural, modification of our approximation\nspace. \n\nThe most common implementation of trigonometric interpolation employs\n\\[\n  x_j =  \\frac{j \\pi}{N},  \\qquad j \\in \\Z.\n\\]\nThe $x_j$ are called {\\em interpolation nodes}. They depend on $N$ of course, but we\nsupress this dependence for the sake of simplicity of notation. Unfortunately, \nfor a $2\\pi$-periodic function, the nodes $x_j, x_{j+2N}$ are equivalent, i.e., \nthere are only $2N$ independent nodes and hence only $2N$ interpolation conditions. \nThus, we cannot determine the $2N+1$ parameters of a $t_N \\in \\Trig_N$ but must \nmodify our approximation space.  To determine a trigonometric polynomial we may, for example,\ndrop the $e^{-iNx}$ basis function from $\\Trig_N$, which leads to\ninterpolants of the form\n\\[\n    t(x) = \\sum_{k = -N+1}^N c_k e^{ik x}.\n\\]\nBut unless $c_N = 0$, this will mean that $t(x) \\not\\in \\R$ even if all $f_j \\in\n\\R$. \n\nBut why did we drop $e^{-iNx}$ from the basis and not $e^{i N x}$? It actually turns out that it doesn't matter since those two basis functions agree on the interpolation nodes $x_j = j \\pi / N$:\n\n\\begin{lemma} \\label{th:trig:baby-aliasing}\n  Let $x_j = j \\pi / N$, then $e^{iN x_j} = e^{-iNx_j}$ for all\n  $j \\in \\Z$.\n\\end{lemma}\n\\begin{proof}\n  \\[\n    e^{iNx_j} = e^{i \\pi j} = (-1)^j = (-1)^{-j} = e^{-i\\pi j} = e^{-iNx_j}.\n    \\qedhere\n  \\]\n\\end{proof}\n\nA simple way therefore to proceed is to replace $e^{i N x}, e^{-i N x}$ with their mean, i.e. $\\cos(Nx)$ which  leads to the following modified trigonometric polynomial space\n\\[\n  \\Trig_N' := {\\rm span}\\Big(\\Trig_{N-1} \\cup \\{ \\cos N x \\} \\Big)\n    =  \\bg\\{ t(x) = \\sum_{k = -N+1}^{N-1} c_k e^{ikx} + c_N \\cos(Nx) \\bg\\}.\n\\]\nNote, however, that for $x = x_j$ only we can equally write \n\\[\n  t(x_j) = \\sum_{k = -N+1}^{N-1} c_k e^{ikx_j} + c_N \\cos(Nx_j)\n     = \\sum_{k = -N+1}^{N} c_k e^{ikx_j},\n\\]\nwhich will be convenient in the following. \n\n\nFinally, to prepare us for discussing the FFT in the next section, we will\nfix the interpolation condition to be nodes $x_0, \\dots, x_{2N-1}$. This may seem \ncounterintuitive given we used $(-\\pi, \\pi]$ as the domain until now, but it is \nthe most common convention and therefore we shall adopt it as well. \n\n\\begin{lemma}\n  Let $F  = (F_j)_{j = 0}^{2N-1} \\in \\C^{2N}$, then there exists a unique\n  $t \\in \\Trig_N'$ such that\n  \\[\n    t(x_j) = F_j, \\qquad j = 0, \\dots, 2N-1.\n  \\]\n\\end{lemma}\n\\begin{proof}\n  According to Lemma~\\ref{th:trig:baby-aliasing} we need to solve\n  \\begin{align*}\n      && \\sum_{k = -N+1}^N c_k e^{i\\pi k j/N} &= F_j \\\\\n      \\Leftrightarrow &&\n      \\sum_{k = -N+1}^N c_k \\big(e^{i\\pi j/N}\\big)^k &= F_j \\\\\n      \\Leftrightarrow &&\n      \\sum_{k = -N+1}^N c_k z_j^k &= F_j, \\\\\n      \\Leftrightarrow &&\n      \\sum_{k = -N+1}^N c_k z_j^{k+N-1} &= F_j z_j^{N-1},\n  \\end{align*}\n  where $z_j = e^{i\\pi x_j}$ are distinct complex interpolation nodes. Existence\n  and uniqueness of algebraic polynomial interpolation gives the stated result.\n  (cf. Exercise~\\ref{exr:poly:interpunique}).\n\n  {\\it REMARK: } the last line in the above chain was unnecessary, but we will\n  revisit this later.\n\\end{proof}\n\n\\medskip\n\n\\begin{definition}\n  Let $f \\in C(\\TT)$ then we define $I_N f \\in \\Trig_N'$ to be the unique nodal\n  interpolant of $f$ at the nodes $x_j = \\pi j / N, j \\in \\Z$, i.e., $I_N f(x_j)\n  = f(x_j)$ for $j \\in \\Z$.\n\\end{definition}\n\n\\medskip \n\nTo understand the approximation error of the $I_N f$, let $f \\in C(\\TT)$, $t_N\n\\in \\Trig_N'$ arbitrary, then\n\\begin{align*}\n  \\|f - I_N f \\|_\\infty &\\leq \\|f - t_N \\|_\\infty + \\| t_N - I_N f\\|_\\infty \\\\\n    & = \\|f - t_N \\|_\\infty + \\| I_N (t_N - f) \\|_\\infty \\\\\n    & \\leq (1 + \\|I_N\\|) \\| t_N - f \\|_\\infty,\n\\end{align*}\nwhere $\\|I_N\\|$ is the operator norm of $I_N$ associated with $\\|\\cdot\\|$,\ndefined by\n\\[\n    \\| I_N \\| = \\sup_{\\substack{f \\in C(\\TT) \\\\ \\|f\\|_\\infty = 1}} \\| I_N f \\|_\\infty.\n\\]\nTaking the infimum over all $t_N \\in \\Trig_N$ we obtain that the\ninterpolation error deviates from the best approximation error by\nfactor determined by the operator norm of $I_N$, i.e.,\n\\[\n    \\|f - I_N f \\| \\leq (1 + \\|I_N\\|) \\inf_{t_N \\in \\Trig_N'} \\|f - t_N \\|\n    \\leq (1 + \\|I_N\\|) \\inf_{t_{N-1} \\in \\Trig_{N-1}} \\|f - t_{N-1} \\|,\n\\]\nwhere the final inequality of course shows that the convergence rate does not\nchange asymptotivally from that in $\\Trig_N$ except possibly for a constant\nfactor.\n\n\\begin{definition}\n  The interpolation operator norm is also called {\\em Lebesgue constant}, and\n  typically denoted by $\\Lambda_N = \\| I_N \\|$.\n\\end{definition}\n\n\\begin{remark}\n  The above argument works in principle with {\\em any} norm. But to obtain a\n  finite bound that norm must be such that $C(\\TT)$ is complete under it. If\n  not, then $\\|I_N\\|$ becomes infinite. As an exercise, you may check that the\n  $L^2$-operator norm, $\\|I_N\\|_{L(L^2)}$ is indeed infinite. This is not\n  surprising since functions $f \\in L^2$ do not even have well-defined point values.\n\\end{remark}\n\nTo estimate $\\Lambda_N$ we wish to write $I_N f$ in terms of a {\\em nodal\nbasis}, i.e.,\n\\[\n  I_N f(x) = \\sum_{j = -N+1}^N f(x_j) L_j(x),\n\\]\nwhere $x_j = \\pi j / N$, then we can simply estimate\n\\begin{align} \\label{eq:trig:LamNbound}\n  \\Lambda_N \\leq \\sup_{x \\in \\TT}  \\sum_{j = -N+1}^N |L_j(x)|.\n\\end{align}\n\nAn immediate observation is that, since the grid is translation invariant, the\nnodal basis will be translation invariant as well, i.e., $L_j(x) = L_0(x -\nx_j)$. This already gives us a hint what to look for.\n\n\\begin{lemma}\n  The nodal basis for trigonometric interpolation (for an even number of\n  grid points $2N$) is given by a modified Dirichlet kernel,\n  \\[\n    % L_j(x) = \\frac{\\sin\\b( N (x-x_j) \\b)}{N \\tan\\b( \\smfrac12 (x-x_j)\\b)}\n    %     = \\frac{{\\rm sinc}\\b( N (x - x_j)\\b)}{N {\\rm sinc}\\b( \\smfrac12 (x-x_j)\\b)}\n    %         \\cos\\b( \\smfrac12 (x-x_j) \\b).\n    L_j(x) = D_N'(x-x_j)\n  \\]\n  where\n  \\[\n    D_N'(x) = \\frac{\\sin(Nx)}{2N \\tan(x/2)}.\n  \\]\n\\end{lemma}\n\\begin{proof}\n  To see the identity for $D_N'$ simply use $\\sin(\\alpha+\\beta) =\n      \\sin\\alpha\\cos\\beta + \\cos\\alpha\\sin\\beta$. From the definition of $D_N'$\n      it is straightforward to check that $L_j(x_i) = \\delta_{ij}$. For the case\n      $i = j$ this is a limit argument: (fill in the details!)\n  \\[\n    \\lim_{x \\to x_j} L_j(x) = 1.\n  \\]\n  Thus we ``only'' need to show that $L_j$ is indeed a trigonometric polynomial,\n  or equivalently, $D_N \\in \\Trig_N$. This is achieved by an analogous argument\n  as for the Jackson kernel.\n\n  See also Exercise~\\ref{exr:trig:dirichlet} for the Dirichlet kernel related to\n  $\\Trig_N$ and how it relates to $L^2$-projection.\n\\end{proof}\n\n\nSee \\nbtrig for a numerical exploration of $\\Lambda_N := \\|I_N\\|_{\\rm op}$. The\nnumerical experiments shown there suggest that the following theorem holds.\n\n\\begin{theorem} \\label{th:trig:lebesgue}\n  The Lebesgue constant for trigonometric interpolation with respect to the\n  $L^\\infty$-norm is bounded by\n  \\[\n    \\|I_N\\| \\leq \\smfrac{2}{\\pi} \\log (N+1) + 2.\n  \\]\n\n  In particular, if $f \\in C(\\TT)$, then\n  \\begin{equation} \\label{eq:trig:almost_best_approx_IN}\n      \\| f - I_N f \\|_{L^\\infty}\n        \\lesssim \\log N \\inf_{t_N \\in \\Trig_N'} \\| f - t_N \\|_{L^\\infty}.\n  \\end{equation}\n  If $f$ is real we can replace $\\Trig_N'$ with $\\Trig_N$ in \\eqref{eq:trig:almost_best_approx_IN}.\n\\end{theorem}\n\n\\begin{remark}\n  This bound is close to sharp. Erd\\\"{o}s (1961) proved  that \n  \\[\n      \\frac{2}{\\pi} \\log N - c_1 \\leq \\Lambda_N \\leq \\frac{2}{\\pi} \\log N + c_2.  \\qedhere\n  \\]\n\\end{remark}\n\n\\begin{proof}\n  Recall\n\\eqref{eq:trig:LamNbound}, then we need to bound\n  \\begin{align*}\n    \\Lambda_N\n    &\\leq\n    \\sum_{j =  -N+1}^N |D_N'(x - x_j)|.\n  \\end{align*}\n  By translation invariance and reflection symmetry we only need to consider $x\n  = -t$, $t \\in (0, \\frac{\\pi}{2N})$ (the case $t = 0$ is trivial); in this\n  case,\n  \\begin{align*}\n    \\Lambda_N\n    &\\leq\n    \\sum_{j =  -N+1}^N |D_N'(x - x_j)| \\\\\n    &\\leq\n    \\sum_{j =  0}^N |D_N'(x_j+t)|  + \\sum_{j = -N+1}^{-1} \\dots \\\\\n    &\\leq\n    \\frac{1}{2N} \\Bg\\{\n        \\frac{\\sin(Nt)}{\\tan(t/2)}\n        + \\sum_{j = 1}^N\n        \\bg|\\frac{\\sin\\b(N(x_j+t)\\b)}{\\tan\\b((x_j+t)/2\\b)}\\bg|\n      \\Bg\\} + \\dots \\\\\n    &\\leq\n    \\frac{1}{2N} \\bg\\{\n        \\frac{Nt}{t} + \\sum_{j = 1}^N \\frac{2}{ x_j+t }\n    \\bg\\} + \\dots \\\\\n    &\\leq\n    1 + \\frac{1}{\\pi} \\sum_{j = 1}^N \\frac{1}{j} + \\dots \\\\\n    &\\leq\n    2\\Big( 1 + \\smfrac{1}{\\pi} \\log(N+1) \\Big)\n    \\leq 2 + \\smfrac{2}{\\pi} \\log(N+1).\n  \\end{align*}\n  (Or, we could use $\\sum_{j = 1}^N \\frac{1}{j} \\sim \\log N + \\gamma + O(1/N)$ to sharpen this a bit more.)\n\n  The last statement is left as an exercise.\n\\end{proof}\n\n\n\\subsection{The Fast Fourier Transform}\n%\n\\label{sec:trig:fft}\n%\nAs a final topic on the theme of trigonometric polynomial approximation we will\nstudy how to work efficiently with trigonometric interpolants. This is achieved\nvia the discrete Fourier transform and its fast implementation, the {\\it Fast\nFourier Transform}, likely one of the most important and most widely used\nnumerical algorithms. We will assume from here on that the number of grid points\nis even. \n\nGiven a function $f \\in C(\\TT)$ we can evaluate it at grid points $x_j$ which\nleads to a grid function $F_j = (f(x_j))_{j=0}^{M-1}$. Given $M \\in 2\\N$ it is\ncommon to define the DFT and FFT for the grid\n%\n\\[\n    x_j = \\frac{2\\pi j}{M} \\qquad j = 0, \\dots, M-1.\n\\]\n%\nThe assumption that $M = 2N$ is even is consistent with\n\\S~\\ref{sec:trig:interp}. \n% In our notation up to now it would have been more\n% natural to write $x_j = -\\pi + \\pi j/N$ instead, but since we are considering\n% periodic functions we just need to shift them into a new domain $[0, 2\\pi)$.\n% Although we could initially avoid some inconveniences we want to eventually be\n% able to use the FFT algorithms, so we may as well learn now how to convert\n% between the two representations.\n\nWe then ask, what are the coefficients of the trigonometric polynomial $t_N \\in\n\\Trig_{N}' = \\Trig_{M/2}'$ such that\n%\n\\[\n  t_N(x_j) = F_j \\qquad \\text{for } j = 0, \\dots, M-1, \n\\]\n%\nor, written as a linear system, \n\\begin{equation} \\label{eq:trig:pre-dft-equi}\n  \\sum_{k = -N+1}^N \\hat{F}_k e^{i \\pi j k / N} = F_j, \\qquad j = 0, \\dots, 2N-1. \n\\end{equation}\nThe first important observation is that the system matrix is orthogonal up to a constant factor; that is, the explicit inversion formula is given by \n\\begin{equation} \\label{eq:trig:pre-idft}\n    \\hat{F}_k = \\frac{1}{2N} \\sum_{j = -N+1}^N F_j e^{-i\\pi k j /N},\n\\end{equation}\nThis is not at all surprising given that close analogy of the sums with the integrals in the definition of the Fourier coefficients. \n\n\\begin{exercise}\n  Prove \\eqref{eq:trig:pre-idft}. The key intermediate result you should extract is \n  \\begin{equation} \\label{eq:trig:orth-dft}\n    \\sum_{j = 0}^{2N-1} \n    e^{i \\pi j k' / N} e^{- i \\pi j k / N} = 2 N \\delta_{kk'},\n  \\end{equation}\n  which is precisely the orthogonality of the system matrix. \n\\end{exercise} \n\n\n% that is, the linear system \\eqref{eq:trig:pre-dft}  has an orthogonal (up to\n% scaling) which reduces the solution of the linear system matrix reduces the\n% solution of \\eqref{eq:trig:pre-dft} to a matrix-vector multiplication\n% \\eqref{eq:trig:pre-idft} and hence $O(N^2)$ cost. But it turns out that there is\n% even an $O(N \\log N)$ algorithm - the Fast Fourier Transform. To present this\n% important algorithm it is more convenient if we work with $2N$ interpolation\n% nodes, instead of $2N+1$ nodes. This makes the theory of interpolation subtly\n% different, since with $2N$ conditions we can no longer hope to determing $2N+1$\n% coefficients.\n\nWe will call the mapping $F \\mapsto \\hat{F}$ the discrete Fourier transform (DFT) and its inverse the IDFT: for $F \\in \\C^{M}$, $k = 0, \\dots, M-1$,\n%\n\\begin{align}\n  \\label{eq:trig:dft}\n  {\\rm DFT}[F] := \\hat{F}, \\quad \\text{where} \\quad\n  \\hat{F}_k &= \\frac{1}{M} \\sum_{j = 0}^{M-1} F_j e^{-i x_j k} \\\\\n  \\notag\n            &= \\frac{1}{M} \\sum_{j = 0}^{M-1} F_j e^{-i 2\\pi j k / M}.\n\\end{align}\n%\nNote in particular that this is a trapezoidal rule approximation of\n\\eqref{eq:trig:fourier coeffs}.\n\n\\begin{remark} \\label{rem:trig:k-grid}\n  Since $x_j = 2 \\pi j/ M$ it follows that\n  \\[\n    e^{-i x_j (k \\pm M)} = e^{-i x_j k}\n  \\]\n  and hence the $k$-grid $\\{0, \\dots, M-1\\}$ can alternatively be interpreted\n  as, with $N = M/2$,\n  \\[\n    \\{ 0, \\dots, N, -N+1, -N+2, \\dots, -1 \\}. \n  \\]\n  This is the ordering normally adopted in implementations of the DFT and IDFT. \n\\end{remark}\n\n\n\\begin{proposition} \\label{th:trig:dft}\n  Let the ${\\rm IDFT}$ be defined by\n  \\begin{equation} \\label{eq:trig:idft}\n    U = {\\rm IDFT}[\\hat{U}], \\quad \\text{where} \\quad\n    U_j := \\sum_{k = 0}^{M-1} \\hat{U}_k e^{i x_j k}\n        = \\sum_{k = 0}^{M-1} \\hat{U}_k e^{i 2\\pi j k/ M},\n  \\end{equation}\n  then\n  \\[\n    {\\rm IDFT}\\big[ {\\rm DFT}[F] \\big] = F \\qquad \\forall F \\in \\C^M.\n  \\]\n  In particular, if $\\hat{F} = {\\rm DFT}[F]$, then the two trigonometric\n  polynomials (cf. Remark~\\ref{rem:trig:k-grid}) $t \\in \\Trig_N, t' \\in\n  \\Trig_N'$\n  \\begin{align*}\n    t(x) &= \\sum_{k = 0}^{M-1} \\hat{F}_k e^{i k x} \\\\\n    t'(x) &= \\sum_{k = 0}^{M/2-1} \\hat{F}_k e^{i k x}\n          + \\hat{F}_{M/2} \\cos(M/2 x) + \\sum_{k = M/2+1}^{M-1} \\hat{F}_k e^{i k x} \\\\\n  \\end{align*}\n  interpolate $(x_j, F_j)_{j = 0}^{M-1}$, i.e.,\n  \\[\n    t(x_j) = t'(x_j) = F_j \\qquad \\text{for } j = 0, \\dots, M-1.\n  \\]\n\\end{proposition}\n\\begin{proof}\n  Left as an exercise.\n\\end{proof}\n\nUsing expression \\eqref{eq:trig:dft} the cost of computing ${\\rm DFT}[F]$ is\n$O(N^2)$. Indeed, this is the cost of a generic matrix-vector multiplication,\ni.e., applying a linear operation in $\\R^N \\to \\R^N$ that has no special\nstructure. Luckily the ${\\rm DFT}$ has plenty of structure to exploit, which\nfinally brings us to the FFT algorithm (specifically the radix-2 variant of\nCooley--Tukey's algorithm, though the idea famously goes back to Gauss).\n\nWe begin by rewriting\n\\[\n  \\hat{F}_k = M^{-1} \\sum_{j = 0}^{M-1} F_j \\omega^{kj},\n  \\qquad \\text{where} \\quad \\omega := e^{-i 2\\pi/M}.\n\\]\nThen,\n\\begin{align}\n  \\notag\n  \\hat{F}_k  &= \\sum_{j = 0}^{M/2-1} F_{2j} \\omega^{2kj}\n      + \\sum_{j = 0}^{M/2-1} F_{2j+1} \\omega^{k(2j+1)} \\\\\n  \\notag\n    &= \\sum_{j = 0}^{M/2-1} F_{2j} \\omega^{2kj}\n        + \\omega^k \\sum_{j = 0}^{M/2-1} F_{2j+1} \\omega^{2kj} \\\\\n  \\label{eq:trig:fft_split}\n    &=: \\hat{G}_k + \\omega^k \\hat{H}_k.\n\\end{align}\nIn particular, since $\\omega^2 = e^{-i2\\pi/(M/2)}$, we note that $\\hat{G}_k$ is\nthe DFT of $(F_{2j})_{j=0}^{M/2-1}$, while $\\hat{H}_k$ is the DFT of\n$(F_{2j+1})_{j=0}^{M/2-1}$.\n\nA final remark is that, {\\it a priori} $\\hat{G}_k$ and $\\hat{H}_k$ will be given\nonly for $k = 0, \\dots, M/2-1$, but the expressions are $M/2$-periodic and\n\\eqref{eq:trig:fft_split} allows us to recover $\\hat{F}$ for all $k = 0, \\dots,\nM-1$. Specifically, we obtain the following identity:\n%\n\\begin{equation} \\label{eq:trig:fft_trick}\n  \\begin{split}\n    \\hat{F}_k &= \\hat{G}_k + \\omega^k \\hat{H}_k, \\qquad k = 0, \\dots, M/2-1, \\\\\n    \\hat{F}_k &= \\hat{G}_{k-M/2} - \\omega^{k-M/2} \\hat{H}_{k-M/2},\n      \\qquad k = M/2, \\dots, M-1.\n  \\end{split}\n\\end{equation}\n(We could also write $\\omega^k$ instead of $\\omega^{k-M/2}$; this is\nequivalent.)\n% The case $k = 0, \\dots, N/2-1$ is already clear from\n% \\eqref{eq:trig:fft_split}. For $k > N/2-1$ it follows from the\n% $N/2$-periodicity of $\\hat{G}_k, \\hat{H}_k$, i.e.,\n% \\[\n%   \\hat{G}_{k+N/2} = \\hat{G}_k, \\qquad \\text{and} \\qquad\n%   \\hat{H}_{k+N/2} = \\hat{H}_k,\n% \\]\n% as well as\n% \\[\n%   \\omega^{N/2} = e^{-i2\\pi(N/2)/N} = e^{-i\\pi} = -1.\n% \\]\n\nSuppose now that $M/2$ is still divisible by 2, then the can split the\ncomputation of $\\hat{F}, \\hat{G}$ again into four smaller DFTs. This process can\nof course be iterated. If $M = 2^m$, then after $m \\approx \\log M$ iterations\niterations we compute $\\approx M$ DFTs of length $O(1)$. Combining the small\nDFTs into the larger DFTs requires $O(M)$ operations at each level. Since there\nare $O(\\log M)$ levels, this means that the cost of computing the original DFT\nis $O(M \\log M)$. Algorithms that use some variant of this strategy are called\n{\\em Fast Fourier Transform}s.\n\n\n\n% \\subsection{Examples}\n% %\n% We are now fully equipped to applying trigonometric polynomial approximation for\n% numerical simulation. We will consider\n% \\begin{itemize}\n%   \\item a linear, homogeneous boundary value problem\n%   \\item a transport equation with variable coefficients\n%   \\item a filtering problem\n% \\end{itemize}\n% These examples may be found in \\nbtrig.\n\n\n\n\n\\subsection{Exercises}\n\n\\begin{exercise} \\label{exr:trig:hilbert-onb}\n  \\begin{enumerate} \\ilist\n    \\item Recall the definition of a complex Hilbert space and\n        check that $( L^2(\\TT), \\< \\cdot, \\cdot \\>_{L^2(\\TT)} )$ is indeed\n        a pre-Hilbert space, i.e. check all conditions except for completeness.\n        (Completeness is a bit more involved, but it is not particularly\n        difficult; feel free to look this up  in a suitable textbook.)\n\n    \\item Complete the proof of the Plancherel Theorem; i.e.\n      Theorem~\\ref{th:trig:plancherel}(ii).\n\n    \\item Using Jackson's theorem, prove also\n    Theorem~\\ref{th:trig:plancherel}(i).\n\n    {\\it Hint: use the fact that $\\Pi_N$ is an orthogonal projector and\n    in particular has operator norm 1.}\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise} \\label{exr:trig:convergence_L2}\n  Complete the proof of Theorem~\\ref{th:trig:convergence_L2}.\n\\end{exercise}\n\n\\begin{exercise} \\label{exr:trig:functions}\n  For the following functions $f$, categorize their regularity as closely as\n  possible and estimate the rate of convergence of $\\|f-\\Pi_N f\\|_{L^2}$.\n  \\begin{enumerate} \\ilist\n    \\item  $f(x) = \\sin(x)$\n    \\item  $f(x) = \\sin(x/2)$\n    \\item $f(x) = |\\sin(x)|$\n    \\item $f(x) = |\\sin(x)|^3$\n    \\item $f(x) = (1 + c^2 \\sin^2 x)^{-1}$\n    \\item $f(x) = \\exp( - \\sin(x))$\n    \\item $f(x) = \\exp( - 1 / (1-x^2) ) \\chi_{(-1,1)}(x)$, extended $2\\pi$-periodically to $\\R$.\n    % x^2 < 2.49999^2 ? exp(3 - 3 / (1-(x/2.5)^2)) : 0.0\n  \\end{enumerate}\n  Can you sharpen your estimates after working through\n  Exercise~\\ref{exr:trig:gibbs}?\n\\end{exercise}\n\n\n\\begin{exercise}[Gibbs Phenomenon] \\label{exr:trig:gibbs}\n  Consider the periodic, piecewise constant function\n  \\[\n      f(x) = \\cases{\n        1, & x \\in (0, \\pi], \\\\\n        -1, & x \\in (-\\pi, 0].\n      }\n  \\]\n  \\begin{enumerate} \\ilist\n  \\item Prove that, there exists no sequence of trigonometric polynomials\n  $t_N \\in \\Trig_N$ such that $t_N \\to f$ uniformly, but that\n  \\[\n    \\|\\Pi_N f - f\\|_{L^2} \\to 0 \\qquad \\text{as } N \\to \\infty.\n  \\]\n\n  \\item Show that the Fourier series for $f$ is given by\n  \\[\n    \\Pi_N f(x) = \\frac{4}{\\pi} \\sum_{\\substack{j = 1 \\\\ j \\text{ odd}}}^{N}\n        \\frac{\\sin(jx)}{j}.\n  \\]\n\n  \\item Deduce that\n  \\[\n      \\| \\Pi_N f - f \\|_{L^2} \\lesssim N^{-1/2}.\n  \\]\n\n  \\item {\\bf Gibbs Phenomenon: } Prove that\n  \\[\n    \\lim_{N \\to \\infty} \\Pi_N f\\b(\\smfrac{\\pi}{N} \\b) > 1\n  \\]\n  You may use without proof that\n  \\[\n      \\int_0^\\pi \\frac{\\sin(t)}{t} \\,dt \\approx\n      \\frac{\\pi}{2} + \\pi \\cdot (0.089489\\dots).\n  \\]\n\n  {\\it If you plot $\\Pi_N f$ you will observe oscillations around the\n  discontinuity. This ``picture'' is what is commonly known as the Gibbs\n  phenomenon. It is a special case of {\\bf ringing artefacts}, which are\n  a common occurance when piecewise smooth data is approximated using\n  global basis functions. This can be nicely visualised in image processing;\n  see e.g. {\\tt https://en.wikipedia.org/wiki/Ringing\\_artifacts}.}\n\n  \\item {Piecewise smooth functions: } Make an educated guess what the\n  rate of convergence is for $\\|\\Pi_N f - f \\|_{L^2}$ when all derivatives up to $f^{(p-2)}$ are continuous, $f^{(p-2)}$ is Lipschitz (and in particular absolutely continuous) and $f^{(p-1)}$ is piecewise absolutely continuous with jump discontinuities at finite many points. This includes\n  functions such as $|\\sin(nx)|, |\\sin(nx)|^q$ for $q$ odd.\n\n  Adapt the proof of Theorem~\\ref{th:trig:decay} to rigorously prove this.\n  %\n  \\qedhere\n  \\end{enumerate}\n\\end{exercise}\n\n\n\\begin{exercise}[Dirichlet Kernel] \\label{exr:trig:dirichlet}\n  \\begin{enumerate} \\ilist\n    \\item Prove that\n    \\[\n      D_N(x) = \\frac{\\sin\\b((N+1/2) x\\b)}{\\sin(x/2)}\n            = 1 + 2 \\sum_{k = 1}^N \\cos(k x)\n            = \\sum_{k = -N}^N e^{ikx}.\n    \\]\n    \\item Deduce that,\n    \\[\n      (D_N \\ast e^{in \\bullet})(x) =\n        \\cases{\n          e^{inx}, & -N \\leq n \\leq N, \\\\\n          0, & \\text{otherwise}\n        }\n    \\]\n    \\item Deduce that, if $f \\in L^1(\\TT)$, then\n    \\[\n        D_N \\ast f = \\Pi_N f.\n    \\]\n    \\item Show that $\\|D_N\\|_{L^1} \\lesssim \\log N$ and hence\n    \\[\n        \\| D_N \\ast f \\|_{L^\\infty} \\leq \\|D_N \\|_{L^1} \\|f\\|_\\infty\n          \\lesssim \\log N \\|f\\|_\\infty.\n    \\]\n    {\\it HINT: to estimate $D_N$ use a similar splitting into sub-intervals\n    as in the Jackson kernel estimates.}\n    \\item Deduce that\n    \\[\n        \\| f - \\Pi_N f \\|_{\\infty}\n        \\lesssim  \\log N \\inf_{t_N \\in \\Trig_N} \\| f - f_N \\|_\\infty,\n    \\]\n    and in particular, if $f \\in C^p(\\TT)$ and $f^{(p)}$ has modulus of\n    continuity $\\omega$, then\n    \\[\n        \\| f - \\Pi_N f \\|_\\infty \\log N N^{-p} \\omega(N^{-1}). \\qedhere\n    \\]\n    % Hint: use the fact that $\\Pi_N t_N = t_N$ for all $t_N \\in \\Trig_N$.\n\n  \\end{enumerate}\n\\end{exercise}\n\n\n\\begin{exercise} \\label{exr:trig:periodic extension}\n  Let $f \\in A(\\TT)$. Prove that there exists $\\alpha > 0$ such that $f$ has an\n  analytic extension to $\\Omega_\\alpha$. Further, show that this extension\n  (still called $f$) must be $2\\pi$-periodic, i.e.,\n  \\[\n      f(x + i y) = f(x + 2\\pi + i y) \\qquad \\forall x+iy \\in \\Omega_\\alpha. \\qedhere\n  \\]\n\\end{exercise}\n\n\n\\begin{exercise}[The Exponentially Convergent Trapezoidal Rule]\n  \\label{exr:trig:trapezoidal rule}\n  Let $f \\in A(\\TT)$, and consider the trapezoidal rule approximation\n  of $I[f] := \\mint_{-\\pi}^\\pi f\\,dx$;\n  \\[\n    Q_N[f] := \\frac{1}{2N} \\sum_{j = -N+1}^N f(x_j),\n  \\]\n  where $x_j := j\\pi/N$.\n  %\n  \\begin{enumerate} \\ilist\n    \\item Prove that,\n    \\[\n        \\frac{1}{2N} \\sum_{j = -N+1}^N e^{ikx_j} =\n          \\cases{\n              1, & k \\in 2N \\Z, \\\\\n              0, & \\text{otherwise.}\n          }\n    \\]\n\n    \\item Suppose $f$ is analytic in $\\Omega_\\alpha$, where $\\alpha > 0$ is\n    maximal. Derive a sharp convergence rate for $|Q_N[f] - I[f]|$.\n    {\\it (You may of course revisit our sketches from the introductory lecture.)}\n\n    \\item {\\it Poisson's example: } The perimeter of an ellipse with axis\n    lengths $1/\\pi, 0.6/\\pi$ is given by the integral\n    \\[\n        I = \\frac{1}{2\\pi} \\int_{-\\pi}^\\pi \\sqrt{1 - 0.36 \\sin^2\\theta}\\,d\\theta.\n    \\]\n    {\\it (You may justify this, but this is not required.)}\n    \\begin{itemize}\n        %\n      \\item Compute the region of analyticity for $f(\\theta) = \\sqrt{1 - 0.36\n      \\sin^2\\theta}$, hence prove a rate of convergence for $Q_N[f]$.\n      {\\it (For this problem, you also need to estimate the prefactor!)}\n      %\n      \\item Only solve one of the following two problems:\n\n      (OPTION 1) How many terms to you need to obtain 3, 5, 7 digits of accuracy?\n      Using only a calculator, compute $I[f]$ to within 3 digits of accuracy.\n      How many ``non-trivial'' function evaluations did you need?\n\n      (OPTION 2) numerically demonstrate the convergence (use Julia, Matlab, Python or any language you wish.) \\qedhere\n    \\end{itemize}\n  \\end{enumerate}\n\\end{exercise}\n\n\n% \\begin{exercise}[Spectral Differentiation]\n% \\end{exercise}\n\n\n\\begin{exercise}\n  Prove Proposition~\\ref{th:trig:dft}.\n\\end{exercise}\n\n\\begin{exercise}\n  {\\bf Radix-3 FFT: } Instead of $M$ even suppose that $M = 3 M'$ (you may\n  actually still assume that $M$ is even for consistency with our treatment of\n  trigonometric interpolation, but this is not really relevant here). Generalise\n  the FFT to this case, i.e., derive the analogues of \\eqref{eq:trig:fft_split}\n  and \\eqref{eq:trig:fft_trick}.\n\\end{exercise}\n", "meta": {"hexsha": "07d4cb89c294cada7fc80c46a63a7360c2395c37", "size": 56342, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/trig.tex", "max_stars_repo_name": "cortner/MA3J8ApxThyApp", "max_stars_repo_head_hexsha": "9400c557187dbd82468df2dbd0a7da99d7f08f8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-05-22T05:11:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-03T02:47:25.000Z", "max_issues_repo_path": "tex/trig.tex", "max_issues_repo_name": "cortner/MA3J8ApxThyApp", "max_issues_repo_head_hexsha": "9400c557187dbd82468df2dbd0a7da99d7f08f8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-03T22:23:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T01:58:58.000Z", "max_forks_repo_path": "tex/trig.tex", "max_forks_repo_name": "cortner/ApxThyApp", "max_forks_repo_head_hexsha": "0b28c5c4370eb4d9c5a9063c2c5c1b938aa54a3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-02T02:44:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T02:44:56.000Z", "avg_line_length": 38.3539823009, "max_line_length": 538, "alphanum_fraction": 0.6219516524, "num_tokens": 20420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629215, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.6862836190829067}}
{"text": "\\lab{Application}{Depth and Breadth-First Searching with Kevin Bacon}{Depth and Breadth-First Searching with Kevin Bacon}\n\\label{lab:SixDegreesKevinBacon}\n\n\\objective{This section teaches about searching graphs and uses the parlor game ``the Six Degrees of Kevin Bacon'' as an application to graphs.}\n\n\\section*{Graphs}\n\\label{Graphs_section}\nWe commonly use graphs to represent the relationships between objects in a set. A graph is\nrepresented by a set of nodes (objects) and a set of edges (relationships) where each edge\nconnects exactly two nodes. We would indicate an edge from node $x$ to node $y$ by $(x, y)$\nand an edge from $y$ to $x$ by $(y, x)$. If \\emph{all} of the edges within a graph are bidirectional\nbetween their connecting nodes, the graph is said to be \\emph{undirected}. If, however, the directions\nof a graph's edges are specified, then the graph is said to be \\emph{directed}. In this lab we will largely work\nwith undirected graphs.\n\nThere are two different data structures that can be used to represent graphs: adjacency matrices and adjacency lists.\nEach data structure has its own advantages and disadvantages; the structure we use depends on the type of problem we are solving.\n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[auto,node distance=1.5cm,\n thick,main node/.style={circle,draw}]\n\n  \\node[main node] (1) {A};\n  \\node[main node] (2) [left of=1] {B};\n  \\node[main node] (3) [above of=1] {C};\n  \\node[main node] (4) [right of=1] {D};\n  \\node[main node] (5) [below of=1] {E};\n\n  \\path[every node/.style={font=\\sffamily\\small}]\n     (1) edge node [] {} (4)\n     \t  edge node [] {} (3)\n     \t  edge node [] {} (5)\n     (2) edge node [] {} (1)\n     \t  edge node []{}(3)\n     (3) edge node []{}(4);\n\\end{tikzpicture}\n\\caption{Example Graph 1}\n\\label{Adjacency}\n\\end{figure}\n\n\n\\subsection*{Adjacency Matrices}\nAn adjacency matrix is two dimensional matrix that is used to represent a graph. To construct an adjacency matrix, we order\nthe nodes of the graph and allow each node to correspond to one column and one\nrow of the matrix. Therefore, if we have $n$ nodes, we use an $n \\times n$ matrix to\nrepresent the edges between the nodes. In an unweighted graph (a graph where all the edges have the same value), we indicate an\nedge using either a $0$ or a $1$.\nConsider Example Graph 1 in Figure \\ref{Adjacency}. Because a bidirectional edge exists between A and D, for example, we put a $1$ in the $(3, 0)$ position and\nin the $(0, 3)$ position. Since no edge exists between A and C, we put a $0$ in\nthe $(2, 0)$ position and $(0, 2)$ position. We can represent the adjacency matrix for this graph as follows:\n\n\\[\n\\bordermatrix{\\hspace{.4cm}&A&B&C&D&E\\cr\n                A&0 & 1 & 0 & 1 & 1\\cr\n                B& 1 & 0 & 1 & 0 & 0\\cr\n                C& 0 & 1 & 0 & 1 & 0\\cr\n                D& 1 & 0 & 1 & 0 & 0\\cr\n                E& 1 & 0 & 0 & 0 & 0}\\]\nNote that because this graph is undirected, its adjacency matrix is symmetric.\n\n\\subsection*{Adjacency Lists}\nAn adjacency list links each node of the graph to a list of its corresponding neighbors, the nodes to which it is connected by an edge.\nThere are many ways to index the nodes so we can easily access their adjacent neighbors, but, in Python, one of the most straightforward ways is to use a simple dictionary.\nWe could represent Graph 1 using the following code:\n\\begin{lstlisting}\nAList = {'A': ['B', 'D', 'E'], 'B': ['A', 'C'], 'C': ['B', 'D'], 'D': ['A', 'C'], 'E': ['A']}\n# To obtain a list of the nodes adjacent to A, simply access the\n# dictionary at the key 'A'.\nprint Alist['A']\n# You should obtain the following output:\n['B', 'D', 'E']\n\\end{lstlisting}\nWe can retrieve the neighbors of any node of the graph in constant time.\nThis makes algorithms that operate locally on the graph highly efficient.\n\n\\section*{Searching Graphs}\nThere are two common ways to search a graph, both of which present different advantages depending on the purpose of the search.\nOne method is called a depth-first search (DFS).  It is designed to search the deepest levels of a graph first.\nThe other method is called a breadth-first search (BFS).  A BFS searches a graph one level at a time until it finds a solution.\n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[auto,node distance=1.5cm,\n thick,main node/.style={circle,draw}]\n\\centering\n  \\node[main node](1) at (-1.25,1.25) {A};\n  \\node[main node](2) at (.75,1.5)  {B};\n  \\node[main node](3) at (0,0) {C};\n  \\node[main node](4) at (-1.6,-.75) {D};\n  \\node[main node](5) at (1.5,0)  {E};\n  \\node[main node](6) at (-.2,-1.5)  {F};\n\n  \\path[every node/.style={font=\\sffamily\\small}]\n  \t(2) edge node[]{}(1)\n  \t(4) edge node[]{}(1)\n  \t     edge node[]{}(3)\n  \t     edge node[]{}(6)\n\t(6) edge node[]{}(3)\n\t     edge node[]{}(5);\n\\end{tikzpicture}\n\\caption{Example Graph 2}\n\\label{bfs_dfs}\n\\end{figure}\n\nUsing Graph 2 in Figure \\ref{bfs_dfs}, we will walk through two examples of a depth-first search.\nIn these examples, when a node has multiple branches originating from it,\nwe will visit the latest (greater) letter in the alphabet first.\nThe node at which the algorithm begins is called the ``root node''.\nFirst, we will use D as our root node and E as our target node.\nStarting with D, we look at D's greatest neighbor, F, then at F's greatest\nneighbor, E. Since E is our target, the algorithm ends.\n\nSecond, we start with A and search for B.\nWe visit node A, then D, then F, and finally E.\nAt this point, we have gone to the deepest level possible without finding our target, B.\nWe must back up and try another branch of nodes;\nthe algorithm backtracks from E to F to try another route.\nHere, it is very important that we mark those nodes we have already visited,\notherwise the algorithm would infinitely loop around the latter portion of\nthe graph without reaching our target, B. Since we have marked D as previously visited, we visit F's final neighbor, C.\nWe return to node F. Since we have already\nsearched all possible nodes adjacent to F, we backtrack, again, to D. Because we have\nexhausted all sub-branches originating from D, we travel back to A and try\nany unexplored branches there. Finally, we find B and the algorithm ends.\n\nLet's try the same two searches using a breadth-first search. While exploring our branches this time, however,\nwe will visit the earliest (lesser) letter in the alphabet first. In this first search, we again use D as our root node and\nE as our target node.\nWe start by searching for E among the neighbors of D: A, C, and F.\nWe have not found E, so we search among the neighbors of these adjacent nodes, starting with A.\nB is the only neighbor of A that we have not already visited; we backtrack to our previous collection of neighbors: A, C, and F.\nWe have already visited both neighbors of C (namely D and F), so we move on to the adjacent nodes of F. Finally, we find E among the neighbors of F, and the algorithm ends.\n\nIn the second search, we start with A.\nSince B is among the neighbors of A, we find it immediately.\n\nBoth DFS and BFS have advantages.\nIf we are able to choose a root node that is somewhat local to the target node, BFS is obviously the better choice. However,\nDFS can be much more efficient when the solution is far from the target node.\nAlgorithm \\ref{alg:BFSDFS} outlines the process by which we may implement the methods for a BFS and DFS, respectively.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{BFS/DFS}{$G, root, destination$}\n\t\\State $Q \\gets \\text{Deque (BFS) or list (DFS) with root node in it}$\t\\Comment{Initialization steps.}\n\t\\State $marked \\gets \\text{Set with root node in it}$\t\n\t\\State $visited \\gets \\text{empty list}$\t\n\t\\While{$Q \\text{ has elements}$}\t\t\t\t\t\t\\Comment{Go through the graph.}\n\t\t\\State $t \\gets Q\\text{'s left (BFS) or right (DFS) element}$\t\n\t\t\\State $\\text{add }t \\text{ to the visited list}$\n\t\t\\If{$t==destination$}\t\t\t\t\t\t\t\\Comment{Find the destination node.}\n\t\t\t\\State \\pseudoli{return} $t,visited$\n\t\t\n\t\t\\Else\t\t\t\t\t\t\t\t\t\t\\Comment{Visit $t$'s neighbors.}\n\t\t\t\\For{$k \\text{ in the adjacent nodes of } t$}\n\t\t\t\t\\If{$k \\text{ not in } marked$}\n\t\t\t\t\t\\State $\\text{add } k \\text{ to } marked$\n\t\t\t\t\t\\State $\\text{add } k \\text{ to } Q$\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\\EndIf\n\t\\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Breadth-first and depth-first searches}\n\\label{alg:BFSDFS}\n\\end{algorithm}\n\n\\begin{problem}\nImplement methods that will perform depth-first and breadth-first searches on a graph\n(in this case, an adjacency list). Use a \\li{set()} to store the visited nodes.\n(Because Python implements sets as hash tables, they have very efficient membership\ntesting.)\n\n\\emph{Helpful Hint}: The implementations of a depth and a breadth first search\nare almost exactly same, but they use a particular data structure differently.\nWhich data structure constitutes this important difference? How is it used differently?\n\\end{problem}\n\n\\section*{Bidirectional Searching an Unweighted Graph}\n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[\n  level distance=1.5 cm,\n  level 1/.style={sibling distance=5cm},\n  level 2/.style={sibling distance=2.5cm},\n  level 3/.style={sibling distance=1.25cm}, thick]\n\n  \\node[circle,draw] {A}\n\tchild {node[circle,draw]{B}\n\t\tchild{node[circle,draw]{D}\n\t\t\tchild{node[circle,draw]{H}}\n\t\t\tchild{node[circle,draw]{I}}\n\t\t}\n\t\tchild{node[circle,draw]{E}\n\t\t\tchild{node[circle,draw]{J}}\n\t\t\tchild{node[circle,draw]{K}}\n\t\t}\n\t}\n\tchild{node[circle,draw]{C}\n\t\tchild{node[circle,draw]{F}\n\t\t\tchild{node[circle,draw]{L}}\n\t\t\tchild{node[circle,draw]{M}}\n\t\t}\n\t\tchild{node[circle,draw]{G}\n\t\t\tchild{node[circle,draw]{N}}\n\t\t\tchild{node[circle,draw]{O}}\n\t\t}\n\t};\n\\end{tikzpicture}\n\\caption{Example Graph 3}\n\\label{Bidirectional}\n\\end{figure}\n\nLet A be an unweighted graph. This means that none of the edges of A has any value, or ``weight'' attached to it. How can we find the shortest path between two nodes?\nOne way would be to simply use a breadth-first search, stopping when we reach the\ntarget node. The downside to this approach is that the algorithm would visit (at least)\nevery node on every level prior to the target node before it could end. Observe Graph 3 in Figure \\ref{Bidirectional} above.\nLet us use a simple BFS to search for O, starting with A as our root node.\nWe begin by searching through all of the neighbors of A, all of the neighbors of B\nand C, and so on until we finally locate O. Using this method, we are forced to check\na total of $15$ nodes before our algorithm ends.\n\nA better way to find the shortest path is to use a breadth-first search from\nboth A \\emph{and} O. Thus, we find the shortest path using a pair of breadth-first searches originating from the root node and the target node, respectively.\nWe advance each BFS one node at a time, alternating until they meet, and then\nconstruct the shortest path of nodes between our root and target.\nUsing the BFS algorithm from above, we start with A and locate its\nleast neighbor, B. Since we have not yet found O (or a connection to O) we visit G,\nthe first neighbor of O. Continuing in this pattern, we return to the neighbors\nof A to visit C. Again, we return to our second search to visit the least neighbor of\nG, which is also C. We have found our connection, so the algorithm ends. Note that when we used a breadth-first\nsearch with only one root node, we visited $15$ nodes, but when we used a bidirectional BFS, we only had to visit $5$ nodes to find our path.\n\nThe speedup from doing a breadth-first search from both sides is especially evident in larger graphs, where each level\ncontains more nodes as we search away from our root. Indeed, a bidirectional search is one of the best ways to find shortest\npaths in unweighted, undirected graphs. For weighted graphs there are many algorithms\nthat allow us to find the shortest path. For further information research Dijkstra's Algorithm, Johnson's algorithm, the Bellman--Ford algorithm, the Floyd--Warshall algorithm, and A* search algorithm.\n\n\\section*{Six Degrees of Kevin Bacon}\n\\begin{figure}[h]\n\\includegraphics[scale = .4]{Kevin_Bacon.jpg}\n\\caption{Kevin Bacon.  Image source: Wikipedia.}\n\\end{figure}\n\nThe theory of ``the 6 Degrees of Separation'' suggests that each person in the world can be linked to any other person by 6 or less steps, or degrees, of acquaintanceship.\nSimilarly, the game ``the 6 Degrees of Kevin Bacon'' contends that every actor in the film industry can be linked to Kevin Bacon by 6 degrees or less. Kevin Bacon\nis a prolific American actor whose film career spans over 30 years in a variety of genres. As such, he once reputably commented that he had either worked with everyone in\nHollywood or someone who has worked with them. The goal of the game, then, is to find the lowest Bacon number for each actor, a process demonstrated as follows:\n\\begin{enumerate}\n\\item Kevin Bacon has a Bacon number of $0$.\n\\item Actors that have been in a movie with Kevin Bacon have a Bacon number of $1$.\n\\item For all other actors $X$, if $n$ is the lowest Bacon number of any actor that $X$ has been in a film with, $X$ has a Bacon number of $n+1$.\n\\end{enumerate}\n\n\\begin{figure}[h]\n\\includegraphics[scale = .6]{Example}\n\\caption{Jeffrey Humphery was in \\emph{End Game} with Cuba Gooding Jr., who was in \\emph{A Few Good Men} with Kevin Bacon, so Jeffrey Humphrey has a Bacon Number of 2.  Image source: http://oracleofbacon.org/.}\n\\end{figure}\n\nWe can define a graph in the same way: where each actor is a node and there is an edge between any two nodes if their actors were in a movie together. From this structure we can find\nthe shortest path between any actor and Kevin Bacon by using any of the algorithms listed above. Of course, this game is not limited to Kevin Bacon; we could use any actor as our ``root actor.''\nIn fact, ``the Six Degrees of Separation'' can be applied to many different fields. Its most famous application is known as the Erdos numbers: how far away is a person\n from publishing a paper (rather than starring in a movie) with the prolific mathematician Paul Erdos?\n\n\\section*{NetworkX}\nFor this lab, we are going to use a network library called NetworkX. NetworkX is a useful Python package that allows us to create and manipulate large, complex networks.\nWhen considering efficiency, however, it is important to note that because NetworkX uses Python objects to represent its graphs internally, graphs with many nodes will\nuse a large chunk of memory. (Other network libraries, such as igraph, are written in C++ and may therefore significantly reduce the overhead of storing such a graph.)\nTo make an undirected graph in NetworkX, we simply code the following:\n\n\\begin{lstlisting}\nimport networkx as nx\nG = nx.Graph()\n\\end{lstlisting}\n\nAs an example, we will create a NetworkX graph that links the ingredients of\ndelicious americanized Italian foods together. We first want to add the ingredients as nodes\nto our graph. To add nodes we can use either the \\li{add_node(x)} method, where $x$\nis the node we want to add, or the \\li{add_nodes_from()} method, to\nadd multiple nodes at once.\n\n\\begin{lstlisting}\nimport networkx as nx\nG = nx.Graph()\n\nG.add_node('dough')\nPizzaIngredients = ['dough', 'mozzarella cheese', 'tomato sauce', 'ham', 'pineapple']\nG.add_nodes_from(PizzaIngredients)\n\\end{lstlisting}\nNote that even though we added \\li{'dough'} twice, the graph will only store this node once. NetworkX also comes with \\li{has_node(x)} and \\li{has_edge(x,y)} methods that will tell\nus if a node $x$ or an edge $(x,y)$ has already been added.\n\nNow we want to connect our pizza ingredients together. Adding an edge is simple; we just use the \\li{add_edge(x,y)} method, where $x$ and $y$ are previously added nodes.\nAgain, we can also add multiple edges using the \\li{add_edges_from()} method.\nHowever, these edges must be provided as 2-tuples \\li{(x,y)}, so we use the\nitertools module to create a list of the edges we want to add. It might be wise\nto review previous labs and the python documentation for this module as you implement\nNetworkX graphs.\n\n\\begin{lstlisting}\nfrom itertools import permutations\nPizza = permutations(PizzaIngredients, 2)\nG.add_edges_from(Pizza)\n\\end{lstlisting}\nIf we add an edge between two non-existent nodes, the missing nodes will also be added to the graph. Let's add the ingredients for lasagna to the graph using only the \\li{add_edges_from} method.\n\\begin{lstlisting}\nLasagnaIngredients = ['lasagna noodles', 'sausage', 'mozzarella cheese', 'cottage cheese', 'tomato sauce', 'egg', 'parsley']\nLasagna = permutations(LasagnaIngredients, 2)\nG.add_edges_from(Lasagna)\n\\end{lstlisting}\nWe can also remove nodes using the methods \\li{remove_node(x)} and \\li{remove_nodes_from()}.\nLet's say, for example, that we are vegetarians and want to remove the\nsausage and ham from our graph. Then, we simply run the following code:\n\\begin{lstlisting}\nG.remove_nodes_from(['sausage', 'ham'])\n\\end{lstlisting}\n\nSometimes, with smaller graphs, it can be useful to visualize how nodes are linked together. However, the overhead associated with displaying larger graphs makes this unwise for extensive data sets.\nFor our example, though, it makes it easy to see the connections between our lasagna and pizza ingredients:\n\n\\begin{lstlisting}\n# MatPlotLib is a standard Python plotting library; it allows you to plot\n# and display your 2D graph.\nimport matplotlib.pyplot as plt\n# Allows you to draw a simple diagram of the nodes and their connecting edges.\nnx.draw(G)\n# Displays your graph.\nplt.show()\n\\end{lstlisting}\n\n\n\\begin{problem}\nThe data file, \\texttt{movieData.txt}, contains the entire casts of movies made over the course of several years. It is a delimited file with each field delimited by the `/' character. Write a method that will implement the following:\n\\begin{itemize}\n\\item Open the file.\n\\item Generate a NetworkX graph, with the actors as nodes and with edges connecting all of the actors within the same movie to one another. Do not include movie titles as nodes.\n\\item Return your constructed NetworkX graph (note that, because of the large amount of data, you \\textbf{should not} attempt to display this graph).\n\\end{itemize}\n\\emph{Helpful Hints:}\n\\begin{itemize}\n\\item For later solutions, it might be beneficial to also construct a map from the actors to the movies they appeared in.\n\\item For certain machine types, take care to open your file using universal newline support. See previous labs for further information.\n\\end{itemize}\n\\end{problem}\n\nFor a graph, G, the \\li{shortest_path(G, x, y)} function in NetworkX outputs\nthe shortest path from $x$ to $y$ as a list. If more than one such path exists,\nit will simply return the first of the shortest paths that it finds. In an\nunweighted graph, this method finds the shortest path using a bidirectional search,\na process outlined earlier in this chapter. However, if no path exists between nodes\n$x$ and $y$ then NetworkX will raise an exception. If we don't specify a\ntarget, then the function will find the shortest paths between our root,\n$x$, and every other node in the network.  It will return the results as a dictionary.\n\n\nWe can find the length of the shortest path using the \\li{shortest_path_length(G, x, y)}\nfunction. Again, the target node for this function is optional; if we only\nspecify the graph and the root node, \\li{shortest_path_length()} will return a dictionary\nwith all \\emph{connecting} nodes as keys. When we don't provide a target, if no path exists between the root\nand another node then NetworkX will simply omit that node from the dictionary (rather than raise an exception).\n\n\\begin{problem}\nFind the shortest path between Kevin Bacon and Liam Neeson. Then find the shortest path from Kevin Bacon to Imran Zahid. Write a function that will accept two actors and output\nthe path between them, along with the movies in between that connect each step of the path. Output the paths from Kevin Bacon to Liam Neeson and Imran Zahid along with the connecting movies.\n\\end{problem}\n\n\\begin{problem}\nFind the average Bacon number for the dataset. Then find the number of actors\nassociated with each Bacon number and the number of actors that have no connection\n to Kevin Bacon at all (we would say these people have a Bacon number of infinity).\n\\end{problem}\n\n", "meta": {"hexsha": "cc8a84b7e4572e5cb765c4ba75b458af53f0115a", "size": 20210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/KevinBacon/KevinBacon.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/KevinBacon/KevinBacon.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/KevinBacon/KevinBacon.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.75, "max_line_length": 234, "alphanum_fraction": 0.7437407224, "num_tokens": 5284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893520001, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6862836147741391}}
{"text": "\\documentclass{article}\n\n\\usepackage{geometry}\n\n\\geometry{a5paper, margin=1in}\n\\setlength{\\parskip}{\\baselineskip}%\n\\setlength{\\parindent}{0pt}%\n\n\\title{Statistics Notes}\n\\author{Zac Garby}\n\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\n\\section{Probability}\n\nFor any events A and B:\n\n$$ P(A') = 1 - P(A) $$\n$$ P(A) = P(A \\cap B) + P(A \\cap B') $$\n$$ P(A \\cup B) = P(A) + P(B) - P(A \\cap B) $$\n$$ P(A' \\cap B') = 1 - P(A \\cup B) $$\n$$ P(B|A) = \\frac {P(B \\cap A)} {P(A)} $$\n$$ P(A \\cap B) + P(B|A) P(A) $$\n\nWhen A and B are mutually exclusive events:\n\n$$ P(A \\cap B) = 0 $$\n$$ P(A \\cup B) = P(A) + P(B) $$\n$$ P(A_1 \\cup A_2 \\cup \\dots \\cup A_n) = P(A_1) + P(A_2) + \\dots + P(A_n) $$\n\nWhen A and B are independent:\n\n$$ P(A \\cap B) = P(A) P(B) $$\n\n\\break\n\n\\section{Statistical Distributions}\n\nA random variable can be distributed according to a distribution function. The two\nwe need to know are the Binomial Distribution and the Normal Distribution.\n\n\\subsection{Binomial Distribution}\n\nIf a random variable $X$ is distributed according to a Binomial Distribution, you can\nwrite:\n\n$$ X \\sim B(n, p) $$\n\nWhere n is the number of trials and p is the probability of success for each one.\nA Binomial Distribution can only be used when all of the following conditions are true:\n\n\\begin{itemize}\n\t\\item A fixed number of trials\n\t\\item Each trial ends in success or failure\n\t\\item Trials are independent\n\t\\item Probability of success is constant\n\\end{itemize}\n\n\n$E(X)$ denotes the expected value of the random variable.\n$$ E(X) = np $$\n\n$P(X = x)$ is the probability that the random variable $X$ is equal to $x$.\n$$ P(X = x) = {n \\choose x}p^x(1-p)^{n-x} $$\n\n$P(X \\leq x)$ is the probability that the random variable $X$ is less than or equal to $x$.\nThis can be calculated using an extension of the previous equation.\n$$ P(X \\leq x) = \\sum_{i=0}^{\\lfloor x \\rfloor}{n \\choose i}p^i(1-p)^{n-i} $$\n\n\\subsubsection{Normal Approximation}\n\nA Binomial Distribution can be approximated as a Normal one if either $p$ is close to 0.5\nor $n$ is large. A general rule is if $np$ and $n(1-p)$ are both greater than 5, a normal\napproximation can be used.\n\nDue to the nature of the two distributions, a continuity correction must be used. Thus, for\ntwo random variables:\n\n$$ X \\sim B(n, p) $$\n$$ Y \\sim N(np, np(1-p)) $$\n\nA probability expression in terms of $X$ can be transformed into one of $Y$:\n\n$$ P(X \\geq 5) \\approx P(Y > 4.5) $$\n$$ P(X \\leq 10) \\approx P(Y < 10.5) $$\n\n\\subsection{Normal Distribution}\n\nIf a random variable X is distributed according to a Normal Distribution, you can write:\n\n$$ X \\sim N(\\mu, \\sigma^2) $$\n\nWhere $\\mu$ is the mean, i.e. the value around which the distribution is symmetrical, and\n$\\sigma^2$ is the variance. The square root of the variance, $\\sigma$, known as the standard\ndeviation, is used more often.\n\nA Normal Distribution is used for continuous variables which are symmetrical and follow a bell-curve shape.\n\n$$ P(X = x) = 0 $$\n\nThe probability of $X$ being a particular value is so close to 0 that it actually is. This\nis because $X$ is continuous, and therefore can take an infinite number of values. This also\nmeans:\n\n$$ P(X > x) = P(X \\geq x) = 1 - P(X < x) $$\n\n\\subsubsection{The Normal Normal Distribution}\n\nThe random variable $Z$ is defined such that:\n\n$$ Z \\sim N(0, 1) $$\n\nOther Normal Distributions can be converted to this distribution:\n\n$$ X \\sim N(\\mu, \\sigma^2) $$\n$$ P(X < n) = P(Z < \\frac{n-\\mu}{\\sigma}) $$\n\n\\subsubsection{The sample mean}\n\nThe sample mean of a normal distribution $X \\sim N(\\mu, \\sigma^2)$, denoted $\\overline X$, is also distributed normally:\n\n$$ \\overline X \\sim N(\\mu, \\frac{\\sigma^2}{n}) $$\n\nWhere $n$ is sample size.\n\n\\subsection{Hypothesis Testing}\n\nA hypothesis test uses data from a sample to test whether or not a statement about a population\nis likely to be true.\n\nThe general idea is that you're given two statements. The first, called the null hypothesis,\nis always where $p$, or whatever variable you're testing, is equal to something. The other,\nthe alternate hypothesis, is $p$ being either greater than, less than, or not equal to the\nvalue which the null hypothesis claims.\n\nIf the alternative hypothesis says $p \\neq v$, the test is two tailed, which means that\nat the end the significance level, $\\alpha$, is halved.\n\n\\end{document}", "meta": {"hexsha": "665a08e9ccbc6dda4dd30a724bd5d50c09120558", "size": 4313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stats.tex", "max_stars_repo_name": "Zac-Garby/notes", "max_stars_repo_head_hexsha": "b65591cc7da77c623c6e2677d770bd2fedb3cefa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "stats.tex", "max_issues_repo_name": "Zac-Garby/notes", "max_issues_repo_head_hexsha": "b65591cc7da77c623c6e2677d770bd2fedb3cefa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stats.tex", "max_forks_repo_name": "Zac-Garby/notes", "max_forks_repo_head_hexsha": "b65591cc7da77c623c6e2677d770bd2fedb3cefa", "max_forks_repo_licenses": ["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.5886524823, "max_line_length": 120, "alphanum_fraction": 0.6883839555, "num_tokens": 1294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.6862836136863274}}
{"text": "\\section{Division of any polyhedron into a union of simplexes}\nAs Adrian mentioned, the key is to divide a polyhedron into convex parts. Then one can further divide each convex body by a simple subdivision. So let us focus on the first step.\n\nBy the definition of polyhedron, there are finite numbers of $n-1$ dimensional faces. Each of these faces has the form \n$$\na^i_1 x_1 + \\ldots + a^i_n x_n +b^i +b^i= 0 \n$$\nwhere i is the index of the face.  Each of the faces divide $R^n$ into two parts, i.e.,  \n$$\na^i_1 x_1 + \\ldots + a^i_n x_n +b^i> 0 \\mbox{ and } a^i_1 x_1 + \\ldots + a^i_n x_n +b^i< 0. \n$$\nThese planes divide $R^n$ into several parts, i.e., the intersection of  \n\\begin{equation}\\label{inequal}\n  a^i_1 x_1 + \\ldots + a^i_n x_ n +b^i<(>) 0\n\\end{equation}\n\n\nEach part defined by these inequalities is convex (by definition). Then we need to check that the original polyhedron can be written as the union of some of these convex parts. \n\nTo see this, consider any point $x$ in the polyhedron. $x$ belongs to one of the convex bodies defined above, since \\eqref{inequal} includes all the possible situations. This shows that the union of the above convex bodies contains the polyhedron.\n\nNext, we claim that each convex body is either contained in the polyhedron, or has no intersection with the polyhedron (need a rigorous proof!). \n\nThis implies that we can represent the polyhedron as the union of some convex bodies.\n\n\n\\endinput\n\\subsection{Discussion with Lin}\n\nProf Ocneanu builds up a connection between polygon and binary tree.\n\\begin{itemize}\n\\item A hyperplane can cut a polygon into two polygons. The hyperplane can be regarded as a node, and the divided polygons can be seen as sub-binary trees.\n\\item Follow the steps above to get more sub-binary trees.\n\\item According to binary tree algorithm you will git a algorithm of cutting polygon.\n\\end{itemize}\n\nBecause of finiteness of polygon, the operator will be end. We can cut a polygon into simplices.\n\nThe other thing that is very interesting is that if you cut with a hyperplane, then the other polygons are only on one side of the hyperplane, which may not be connected, but increases the convexity, which guarantees convex.\n\n\n", "meta": {"hexsha": "f773ef786f724e3f7f8b42237c449bda9a97c97e", "size": 2204, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Poly2Simplex.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/Poly2Simplex.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/Poly2Simplex.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.4761904762, "max_line_length": 247, "alphanum_fraction": 0.7572595281, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.6862836088336539}}
{"text": "\\subsection{Zermelo-Fraenkel set theory}\\label{subsec:zermelo_fraenkel_set_theory}\n\n\\begin{definition}\\label{def:choice_function}\n  Let \\( \\mscrA \\) be a (potentially empty) family of nonempty sets. A \\term{choice function} on \\( \\mscrA \\) is a (total) \\hyperref[def:function]{function} \\( c: \\mscrA \\to \\bigcup \\mscrA \\) such that \\( c(A) \\in A \\) for all \\( A \\in \\mscrA \\).\n\n  This is formally the same as a tuple defined in \\fullref{def:cartesian_product/tuple}.\n\n  A choice function on \\( \\mscrA \\) \\enquote{chooses} an element out of each member of \\( \\mscrA \\). We sometimes have a canonical choice function, for example in \\fullref{thm:representatives_in_univariate_polynomial_quotient_set}, however for general \\hyperref[def:equivalence_relation/quotient]{quotient sets} the existence of a choice function is not by any means obvious.\n\n  The existence of a choice function for family of nonempty sets is an important axiom of \\logic{ZFC} --- see \\fullref{def:zfc/choice}.\n\\end{definition}\n\n\\begin{definition}\\label{def:zfc}\n  The \\hyperref[def:first_order_theory]{first-order theory} commonly abbreviated as \\term{\\logic{ZFC}} is based on the same language as \\hyperref[def:naive_set_theory]{na\\\"ive set theory}, but with different axioms. The three letters refer to:\n  \\begin{itemize}\n    \\item \\hi{Z}ermelo, who formulated the entire theory except for the \\hyperref[def:zfc/replacement]{axiom schema of replacement} and the \\hyperref[def:zfc/foundation]{axiom of foundation}.\n    \\item\\mcite[sec. 63.8]{OpenLogicFull} \\hi{F}raenkel, who simultaneously with Skolem reformulated the theory within first-order logic while also introducing the axiom schema of replacement.\n    \\item The \\hyperref[def:zfc/choice]{axiom of \\hi{c}hoice}, which is part of Zermelo's original theory, but is controversial enough to attract special attention --- see \\fullref{thm:axiom_of_choice_equivalences}.\n  \\end{itemize}\n\n  We are usually only interested in either \\logic{ZFC}, which include all axioms listed in this definition. If we wish to avoid the axiom of choice --- for example when proving the equivalences in \\fullref{thm:axiom_of_choice_equivalences} --- we instead use \\logic{ZF}, which excludes the axiom of choice. The abbreviation of the latter theory is inaccurate historically, but is nevertheless established.\n\n  If we wish to instead exclude the axiom of replacement, we obtain the theory \\logic{Z}, however without context it is unclear whether the axiom of choice is included in \\logic{Z} or not.\n\n  See \\fullref{thm:zfc_existence_theorems} for proofs of existence of common sets.\n\n  The full list of axioms is:\n  \\begin{thmenum}\n    \\thmitem{def:zfc/extensionality} The \\term{axiom of extensionality}, as defined in \\fullref{def:naive_set_theory/extensionality}. This is also the only axiom of the theory that does not deal with existence.\n\n    \\thmitem{def:zfc/specification}\\mcite[sec. 62.2]{OpenLogicFull} The \\term{axiom schema of specification}, also known as the axiom schema of \\term{separation} or of \\term{restricted comprehension}, states that given a set \\( A \\), any formula defines a subset of \\( A \\). For each formula \\( \\varphi \\) containing neither \\( \\tau \\) nor \\( \\sigma \\) as free variables, the following is an axiom:\n    \\begin{equation}\\label{eq:def:zfc/specification}\n      \\qforall \\sigma \\qexists \\tau \\qforall \\xi (\\xi \\in \\tau \\leftrightarrow \\varphi \\wedge \\xi \\in \\sigma).\n    \\end{equation}\n\n    As explained in \\fullref{def:naive_set_theory/unrestricted_comprehension} and \\fullref{def:set_builder_notation}, this set may depend on parameters, which are other sets. We must formally take the \\hyperref[thm:implicit_universal_quantification]{universal closure} of this set to quantify over all possible values for the parameters.\n\n    Compare this axiom to \\hyperref[def:naive_set_theory/unrestricted_comprehension]{unrestricted comprehension}. Informally, this axiom can be obtained by taking the result of unrestricted comprehension and intersecting it with some set \\( A \\). As mentioned in \\fullref{def:set_builder_notation}, in set-builder notation such a set is usually denoted by\n    \\begin{equation*}\n      \\set{ x \\in B \\given \\varphi\\Bracks{x, u_1, \\ldots, u_n} }.\n    \\end{equation*}\n\n    Unlike unrestricted comprehension some definable subset of the universe in the metatheory no longer have a corresponding set within the object logic.\n\n    \\thmitem{def:zfc/power_set}\\mcite[sec. 62.5]{OpenLogicFull} The \\term{axiom of power sets} states that every set has a corresponding \\hyperref[def:basic_set_operations/power_set]{power set}. Symbolically,\n    \\begin{equation}\\label{eq:def:zfc/power_set}\n      \\qforall \\tau \\qexists \\sigma \\ref{eq:def:basic_set_operations/power_set/predicate}[\\sigma, \\tau].\n    \\end{equation}\n\n    \\thmitem{def:zfc/union}\\mcite[sec. 62.3]{OpenLogicFull} The \\term{axiom of unions} states that for every set there exists another set that is its \\hyperref[def:basic_set_operations/union]{union}. Symbolically,\n    \\begin{equation}\\label{eq:def:zfc/union}\n      \\qforall \\tau \\qexists \\sigma \\ref{eq:def:basic_set_operations/union/predicate}[\\sigma, \\tau].\n    \\end{equation}\n\n    \\thmitem{def:zfc/pairing}\\mcite[sec. 62.4]{OpenLogicFull} The \\term{axiom of pairing} states that for any sets \\( A \\) and \\( B \\) there exists another set that contains exactly \\( A \\) and \\( B \\). This is the set \\( \\set{ A, B } \\) in set-builder notation. Symbolically,\n    \\begin{equation}\\label{eq:def:zfc/pairing}\n      \\qforall \\tau \\qforall \\sigma \\qexists \\rho \\qforall \\xi \\parens[\\Big]{ \\xi \\in \\rho \\leftrightarrow ( \\xi \\doteq \\tau \\vee \\xi \\doteq \\sigma) }.\n    \\end{equation}\n\n    \\thmitem{def:zfc/infinity}\\mcite[sec. 62.6]{OpenLogicFull} The \\term{axiom of infinity} states that an \\hyperref[def:inductive_set]{inductive set} exists. Symbolically,\n    \\begin{equation}\\label{eq:def:zfc/infinity}\n      \\qexists \\tau \\ref{eq:def:inductive_set/predicate}[\\tau].\n    \\end{equation}\n\n    This axiom is a simple and convenient way to state that infinite sets exist. Without it, we can only deal with finite sets unless we include some other axiom to replace it.\n\n    \\thmitem{def:zfc/choice}\\mcite[sec. 69.4]{OpenLogicFull} The \\term{axiom of choice} states that a \\hyperref[def:choice_function]{choice function} exists for any family of nonempty sets. To state the axiom via a formula, we will avoid functions and only state it in terms of the image of the choice function. That is, we will formulate that for each family \\( \\mscrA \\) of nonempty sets there exists a set \\( B \\) such that \\( A \\cap B \\) is a singleton set for each \\( A \\in \\mscrA \\). Symbolically,\n    \\begin{equation}\\label{eq:def:zfc/choice}\n      \\qforall \\tau \\parens[\\Bigg]\n        {\n          \\parens[\\Big]{ \\qforall {\\xi \\in \\tau} \\neg \\ref{eq:def:empty_set/predicate}[\\xi] }\n          \\rightarrow\n          \\parens[\\Big]{ \\qexists \\sigma \\qforall {\\xi \\in \\tau} \\qExists {\\eta \\in \\sigma} \\eta \\in \\xi }\n        }\n    \\end{equation}\n    where we have used the convention regarding existence and uniqueness described in \\fullref{rem:first_order_formula_conventions/exists_unique}.\n\n    See \\fullref{thm:axiom_of_choice_equivalences} for more statements equivalent to this axiom.\n\n    \\thmitem{def:zfc/replacement}\\mcite[sec. 63.7]{OpenLogicFull} The \\term{axiom schema of replacement} roughly states that every \\hyperref[rem:function_definition]{mapping} that is definable via a formula of \\logic{ZFC} is a function. As we have done for the \\hyperref[def:zfc/choice]{axiom of choice}, we only formulate the axiom via the image of the function. More concretely, given a formula \\( \\varphi \\) not containing \\( \\tau \\) nor \\( \\sigma \\) as free variables, the following is an axiom:\n    \\begin{equation}\\label{eq:def:zfc/replacement}\n      \\qforall \\tau \\parens[\\Bigg]\n        {\n          \\parens[\\Big]{ \\qforall {\\xi \\in \\tau} \\qExists \\eta \\varphi }\n          \\rightarrow\n          \\parens[\\Big]{ \\qexists \\sigma \\qforall \\eta \\parens[\\Big]{ \\eta \\in \\sigma \\leftrightarrow \\qexists {\\xi \\in \\tau} \\varphi } }\n        }.\n    \\end{equation}\n\n    As is the case with the \\hyperref[def:zfc/specification]{axiom schema of specification}, the formula \\( \\varphi \\) may depend on parameters, in which case we use its \\hyperref[thm:implicit_universal_quantification]{universal closure}.\n\n    This axiom is useful in cases where it is impossible or at least difficult to construct a function, for example in \\fullref{thm:zfc_existence_theorems/indexed_family} or \\fullref{thm:hartogs_lemma}. This is the case, in general, when dealing with \\hyperref[thm:zfc_existence_theorems/indexed_family]{indexed families} rather than \\hyperref[def:function]{functions}.\n\n    This is the axiom that makes \\logic{ZFC} require large models --- see \\fullref{thm:cumulative_hierarchy_model_of_zfc}.\n\n    \\thmitem{def:zfc/foundation}\\mcite[sec. 64.4]{OpenLogicFull} The \\term{axiom of foundation} states that every nonempty set contains a member disjoint from the set itself. Symbolically,\n    \\begin{equation}\\label{eq:def:zfc/foundation}\n      \\qforall \\tau \\parens[\\Big]\n        {\n          \\neg \\ref{eq:def:empty_set/predicate}[\\tau]\n          \\rightarrow\n          \\qexists {\\sigma \\in \\tau} \\neg \\qexists \\xi \\parens{ \\xi \\in \\tau \\wedge \\xi \\in \\sigma }\n        }.\n    \\end{equation}\n\n    This is a very powerful axiom because it shows that set membership in \\logic{ZFC} is well-founded --- see \\fullref{thm:set_membership_is_well_founded}. It is equivalent to \\fullref{thm:axiom_of_regularity} and is often itself called the \\term{axiom of regularity}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:zfc_existence_theorems}\n  We will now prove that all sets we have considered up until now in \\fullref{sec:set_theory} are sets in \\hyperref[def:zfc]{\\logic{ZFC}}. The uniqueness in all cases follows from the \\hyperref[def:zfc/extensionality]{axiom of extensionality}.\n\n  A very fundamental existence result is provided by the fact that we are assuming \\hyperref[rem:standard_model_of_set_theory]{standard} and \\hyperref[rem:transitive_model_of_set_theory]{transitive} models of \\logic{ZFC}. Let \\( \\mscrV = (V, I) \\) be such a model. Then if \\( v \\in V \\) and \\( u \\in v \\), transitivity implies that \\( u \\in V \\). Since the model is also standard, this shows that both \\( u \\) and \\( v \\) are sets within the object theory. Thus, if \\( A \\) is a set within the object theory and if \\( B \\in A \\) within the metatheory, then necessarily \\( B \\) itself is a set within the object theory.\n\n  For example, \\fullref{thm:zfc_existence_theorems/set_of_functions} shows that the set \\( \\fun(A, B) \\) of functions exists within the object theory for any two sets \\( A \\) and \\( B \\) in the object theory. Therefore, every single function between \\( A \\) and \\( B \\) is a set within the object theory because it is a member of \\( \\fun(A, B) \\).\n\n  With that in mind, we will show the following:\n\n  \\begin{thmenum}\n    \\thmitem{thm:zfc_existence_theorems/subset} If \\( A \\) is a set, then for any formula \\( \\varphi \\) the set \\( \\set{ x \\in A \\given \\varphi[x] } \\) exists and, furthermore, it is a \\hyperref[def:subset]{subset} of \\( A \\). Only \\hyperref[def:first_order_definability]{definable subsets} of \\( A \\) can be described in this way, however. See \\fullref{thm:zfc_existence_theorems/power_set}.\n\n    \\thmitem{thm:zfc_existence_theorems/empty_set} There exists a unique \\hyperref[def:empty_set]{empty set}, which we denote by \\( \\varnothing \\).\n\n    \\thmitem{thm:zfc_existence_theorems/universe} No \\hyperref[def:set]{universal set} (set of all sets) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/singleton} For every set \\( A \\), there exists a \\hyperref[rem:singleton_sets]{singleton set} \\( \\set{ A } \\) that contains only \\( A \\).\n\n    \\thmitem{thm:zfc_existence_theorems/arbitrary_intersection} For any \\hi{nonempty} family \\( \\mscrA \\), the \\hyperref[def:basic_set_operations/intersection]{intersection} \\( \\bigcap \\mscrA \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/binary_intersection} For any two sets \\( A \\) and \\( B \\), their \\hyperref[def:basic_set_operations/intersection]{intersection} \\( A \\cap B \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/arbitrary_union} For any family \\( \\mscrA \\), the \\hyperref[def:basic_set_operations/union]{union} \\( \\bigcup \\mscrA \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/binary_union} For any two sets \\( A \\) and \\( B \\), their \\hyperref[def:basic_set_operations/union]{union} \\( A \\cup B \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/difference} For any two sets \\( A \\) and \\( B \\), their \\hyperref[def:basic_set_operations/difference]{difference} \\( A \\setminus B \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/power_set} For any set \\( A \\), its \\hyperref[def:basic_set_operations/power_set]{power set} \\( \\pow(A) \\) exists.\n\n    As a consequence, even subsets of \\( A \\) which are not \\hyperref[def:first_order_definability]{definable} exist.\n\n    \\thmitem{thm:zfc_existence_theorems/successor} For any set \\( A \\), its \\hyperref[def:ordinal_successor]{successor} \\( \\op{succ}(A) \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/kuratowski_pair} For any two sets \\( A \\) and \\( B \\), their \\hyperref[def:cartesian_product/kuratowski_pair]{Kuratowski pair} \\( \\braket{ A, B } \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/indexed_family} For any sets \\( \\mscrK \\) and \\( \\mscrA \\), any \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ A_k }_{k \\in \\mscrK} \\subseteq \\mscrA \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/cartesian_product} For any indexed family \\( \\set{ A_k }_{k \\in \\mscrK} \\), its \\hyperref[def:cartesian_product]{Cartesian product} \\( \\prod_{k \\in \\mscrK} A_k \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/set_of_relations} For any two sets \\( A \\) and \\( B \\), the set of all relations between \\( A \\) and \\( B \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/set_of_functions} For any two sets \\( A \\) and \\( B \\), the set \\hyperref[def:function/set_of_functions]{\\( \\fun(A, B) \\)} exists.\n\n    \\thmitem{thm:zfc_existence_theorems/quotient_set} For any set \\( A \\) and any \\hyperref[def:equivalence_relation]{equivalence relation} \\( \\cong \\), the \\hyperref[def:equivalence_relation/quotient]{quotient set} \\( A / {\\cong} \\) exists.\n\n    \\thmitem{thm:zfc_existence_theorems/function_evaluation} Fix some sets \\( A \\) and \\( B \\) and some indexed family of functions \\( \\seq{ f_k }_{k \\in \\mscrK} \\) where \\( f: A \\to B_k \\) for \\( k \\in \\mscrK \\). For any \\( x \\in A \\) the corresponding tuple \\( \\seq{ f_k(x) }_{k \\in \\mscrK} \\) exists.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:zfc_existence_theorems/subset} This is a trivial consequence of the \\hyperref[def:zfc/specification]{axiom schema of specification}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/empty_set} As a consequence of the \\hyperref[def:zfc/infinity]{axiom of infinity}, there exists at least one inductive set. Let \\( A \\) be an inductive set. Then from the \\hyperref[def:zfc/specification]{axiom schema of specification} it follows that\n  \\begin{equation*}\n    \\set{ x \\in A \\given \\bot }\n  \\end{equation*}\n  is a set. Furthermore, \\( x \\) belongs to this set if and only if \\( x \\) satisfies \\( \\bot \\), which is impossible, hence the set is empty.\n\n  As a consequence of the \\term{axiom of extensionality}, this empty set is unique. As discussed in \\fullref{def:empty_set}, we denote this unique empty set by \\( \\varnothing \\).\n\n  \\SubProofOf{thm:zfc_existence_theorems/universe} Aiming at a contradiction, suppose that there was a universal set \\( U \\). Then we can easily reproduce \\fullref{thm:russels_paradox} by using restricted (to \\( U \\)) rather than unrestricted comprehension.\n\n  Unlike in na\\\"ive set theory, however, the existence of \\( U \\) is not an axiom of the theory. Therefore, rather than demonstrating that \\logic{ZFC} is inconsistent, Russel's paradox shows that certain sets like the universal set do not exist in \\logic{ZFC}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/singleton} Fix a set \\( A \\). The set \\( \\set{A} \\), if it exists, is equal to \\( \\set{A} = \\set{A, A} \\), by the \\hyperref[def:zfc/extensionality]{axiom of extensionality}.\n\n  Thus, by the \\hyperref[def:zfc/pairing]{axiom of pairing}, the singleton set \\( \\set{A} = \\set{A, A} \\) actually exists.\n\n  \\SubProofOf{thm:zfc_existence_theorems/arbitrary_intersection} Let \\( \\mscrA \\) be a nonempty family of sets. Their intersection \\( \\bigcap \\mscrA \\), if it exists, is a subset of every set \\( A \\in \\mscrA \\).\n\n  Therefore, since the family \\( \\mscrA \\) is nonempty, the \\hyperref[def:zfc/specification]{axiom schema of specification} applied to any set in \\( A \\in \\mscrA \\) guarantees the existence of the intersection \\( \\bigcap \\mscrA \\). More precisely, for any \\( A_0 \\in \\mscrA \\), we can define the intersection of \\( A \\) as\n  \\begin{equation*}\n    \\bigcap \\mscrA = \\set{ x \\in A_0 \\given \\qexists {A \\in \\mscrA} x \\in A }.\n  \\end{equation*}\n\n  \\SubProofOf{thm:zfc_existence_theorems/binary_intersection} For sets \\( A \\) and \\( B \\), by the \\hyperref[def:zfc/pairing]{axiom of pairing} the set \\( \\set{ A, B } \\) exists. Then by \\fullref{thm:zfc_existence_theorems/arbitrary_intersection}, the binary intersection\n  \\begin{equation*}\n    A \\cap B = \\bigcap \\set{ A, B }\n  \\end{equation*}\n  also exists.\n\n  \\SubProofOf{thm:zfc_existence_theorems/arbitrary_union} The existence of arbitrary unions is merely a restatement of the \\hyperref[def:zfc/union]{axiom of unions}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/binary_union} Similarly to \\fullref{thm:zfc_existence_theorems/binary_intersection}, for sets \\( A \\) and \\( B \\), by the \\hyperref[def:zfc/pairing]{axiom of pairing} the set \\( \\set{ A, B } \\) exists and by the \\hyperref[def:zfc/union]{axiom of unions}, the binary union\n  \\begin{equation*}\n    A \\cup B = \\bigcup \\set{ A, B }\n  \\end{equation*}\n  exists.\n\n  \\SubProofOf{thm:zfc_existence_theorems/difference} The difference \\( A \\setminus B \\) is guaranteed to exist by \\hyperref[def:zfc/specification]{restricted comprehension}:\n  \\begin{equation*}\n    A \\setminus B = \\set{ x \\in A \\given x \\not\\in B }.\n  \\end{equation*}\n\n  \\SubProofOf{thm:zfc_existence_theorems/power_set} The existence of power sets is a restatement of the \\hyperref[def:zfc/power_set]{axiom of power sets}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/successor} The successor of \\( A \\) is\n  \\begin{equation*}\n    \\op{succ}(A) = \\set{ A } \\cup A.\n  \\end{equation*}\n\n  Its existence follows from \\fullref{thm:zfc_existence_theorems/singleton} and \\fullref{thm:zfc_existence_theorems/binary_union}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/kuratowski_pair} The existence of the Kuratowski pair\n  \\begin{equation*}\n    \\braket{ A, B } = \\set{ \\set{ A }, \\set{ A, B } }\n  \\end{equation*}\n  can be proven by the \\hyperref[def:zfc/pairing]{axiom of pairing} applied first to \\( \\set{ A, B } \\) and then to the pair itself.\n\n  \\SubProofOf{thm:zfc_existence_theorems/indexed_family} Given an indexed family \\( \\seq{ A_k }_{k \\in \\mscrK} \\), by the \\hyperref[def:zfc/replacement]{axiom schema of replacement}, there exists a set\n  \\begin{equation*}\n    \\mscrA \\coloneqq \\set{ A_k \\given k \\in \\mscrK }.\n  \\end{equation*}\n\n  The family \\( \\seq{ A_k }_{k \\in \\mscrK} \\) is, formally, a set of Kuratowski pairs. Every pair \\( \\braket{ k, A_k } \\) is itself a subset of \\( \\pow(\\mscrK \\bigcup \\mscrA) \\). The family is then a subset of \\( \\pow(\\pow(\\mscrK \\bigcup \\mscrA)) \\). Applying the \\hyperref[def:zfc/power_set]{axiom of power sets} again, we obtain that the family exits as a set.\n\n  \\SubProofOf{thm:zfc_existence_theorems/cartesian_product} By definition, the Cartesian product \\( \\prod_{k \\in \\mscrK} A_k \\) is a set of indexed by \\( \\mscrK \\) families of members of the union \\( \\bigcup\\set{ A_k \\given k \\in \\mscrK } \\).\n\n  We can apply the \\hyperref[def:zfc/power_set]{axiom of power sets} one more time in addition to those in \\fullref{thm:zfc_existence_theorems/indexed_family} to obtain the set of all indexed by \\( \\mscrK \\) families of members of this union. Then we can apply the \\hyperref[def:zfc/specification]{axiom schema of specification} to restrict only to those families that satisfy the condition of \\fullref{def:cartesian_product/product}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/set_of_relations} All relations between \\( A \\) and \\( B \\) are subsets of \\( A \\times B \\), hence elements of \\( \\pow(A \\times B) \\). The latter exists by \\fullref{thm:zfc_existence_theorems/cartesian_product} and \\fullref{thm:zfc_existence_theorems/power_set}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/set_of_functions} The set of single-valued functions from \\( A \\) to \\( B \\) is a subset of \\( \\pow(A \\times B) \\), hence it exists by \\fullref{thm:zfc_existence_theorems/set_of_relations} and \\fullref{thm:zfc_existence_theorems/power_set}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/quotient_set} Let \\( A \\) be an arbitrary set and \\( \\cong \\) be a binary relation over \\( A \\). Then \\( A / {\\cong} \\) is a subset of \\( \\pow(A) \\) and hence it exists as a consequence of the \\hyperref[def:zfc/power_set]{axiom of power sets} and the \\hyperref[def:zfc/specification]{axiom schema of specification} --- see \\fullref{thm:equivalence_partition/partition}.\n\n  \\SubProofOf{thm:zfc_existence_theorems/function_evaluation} The set \\( \\seq{ f_k }_{k \\in \\mscrK} \\) exists because it is a member of \\( \\fun(\\mscrK, \\fun(A, B)) \\), which set exists by \\fullref{thm:zfc_existence_theorems/set_of_functions}.\n\n   Then \\( \\seq{ f_k(x) }_{k \\in \\mscrK} \\) is the function\n   \\begin{equation*}\n     \\begin{aligned}\n       &g_x: \\fun(\\mscrK, B) \\\\\n       &g_x(k) \\coloneqq f_k(x).\n     \\end{aligned}\n   \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[Multi-valued selection existence]\\label{thm:existence_of_multi_valued_function_selection}\n  Every \\hyperref[def:multi_valued_function/total]{total multi-valued function} has a \\hyperref[def:function/selection]{selection}.\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/selection}.\n\\end{theorem}\n\\begin{proof}\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:existence_of_multi_valued_function_selection]{selection existence} Let \\( F: A \\multto B \\) be a total multi-valued function. As described in \\fullref{rem:multi_valued_functions}, we can instead take the \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\set{ F(a) }_{a \\in A} \\). Denote by \\( f \\) the \\hyperref[def:function]{single-valued function} from \\( A \\) to the image \\( \\set{ F(a) \\given a \\in A } \\subseteq \\pow(B) \\) of this indexed family (see \\fullref{rem:multi_valued_functions} for clarifications).\n\n  Since \\( F \\) is \\hyperref[def:multi_valued_function/total]{total}, the family \\( \\img(f) = \\set{ F(a) }_{a \\in A} \\) is a (potentially empty) family of nonempty sets. Thus, we can apply the axiom of choice to obtain a \\hyperref[def:choice_function]{choice function} \\( c: \\img(f) \\to B \\).\n\n  The composition \\( c \\bincirc f \\) is then a single-valued function. Furthermore, we have\n  \\begin{equation*}\n    (c \\bincirc f)(a) \\in f(a) = F(a)\n  \\end{equation*}\n  so \\( c \\bincirc f \\) is a selection of \\( F \\).\n\n  \\ImplicationSubProof[thm:existence_of_multi_valued_function_selection]{selection existence}[def:zfc/choice]{axiom of choice} Fix a family \\( \\mscrA \\) of nonempty sets. Define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &F: \\mscrA \\to \\bigcup \\mscrA \\\\\n      &F(A) \\coloneqq A\n    \\end{aligned}\n  \\end{equation*}\n  that sends each set in \\( \\mscrA \\) to the corresponding subset of \\( \\mscrA \\). In terms of relations, we have \\( (A, x) \\in F \\) if and only if \\( x \\in A \\). This is a total multi-valued function because every set in \\( \\mscrA \\) is nonempty.\n\n  Then every selection of \\( F \\) is a choice function for \\( \\mscrA \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:disjoint_union}\n  The \\term{disjoint union} of the \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ A_k }_{k \\in \\mscrK} \\) of nonempty sets is\n  \\begin{equation*}\n    \\coprod_{k \\in \\mscrK} A_k \\coloneqq \\set[\\Big]{ (k, x) \\given k \\in \\mscrK \\T{and} x \\in A_k }.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{theorem}[Surjective functions are right-invertible]\\label{thm:surjective_functions_are_right_invertible}\n  Every \\hyperref[def:function_invertibility/surjective]{surjective function} is \\hyperref[def:morphism_invertibility/right_invertible]{right-invertible}.\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/surjective}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( f: A \\to B \\) be any function. Its \\hyperref[def:multi_valued_function/inverse]{inverse} \\( f^{-1}: B \\multto A \\) is, by definition, a partial multi-valued function.\n\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:epimorphisms_split_in_set]{right-invertibility} If \\( f \\) is surjective, then by \\fullref{def:function_invertibility/surjective/inverse}, its inverse is total. Then the axiom of choice via \\fullref{thm:existence_of_multi_valued_function_selection} gives us a \\hyperref[def:function/selection]{single-valued selection} \\( g \\) of \\( f^{-1} \\).\n\n  Since the value of \\( f \\) is \\( y \\) for all members of \\( f^{-1}(y) \\), and since \\( g(y) \\in f^{-1}(y) \\), we have\n  \\begin{equation*}\n    [f \\bincirc g](y) = f(g(y)) = y.\n  \\end{equation*}\n\n  Therefore, \\( g \\) is a right inverse of \\( f \\).\n\n  \\ImplicationSubProof[thm:epimorphisms_split_in_set]{right-invertibility}[def:zfc/choice]{the axiom of choice} Suppose that every surjective function is invertible.\n\n  Let \\( \\mscrA \\) be an arbitrary family of nonempty sets. We can regard it as the \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ A }_{A \\in \\mscrA} \\). Define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: \\coprod_{A \\in \\mscrA} A \\to \\mscrA, \\\\\n      &f(A, x) \\coloneqq A,\n    \\end{aligned}\n  \\end{equation*}\n  where by \\( \\coprod \\) we have denoted the \\hyperref[def:disjoint_union]{disjoint union}.\n\n  This function is surjective by definition. Then there exists a right-inverse\n  \\begin{equation*}\n    g: \\mscrA \\to \\seq{ A }_{A \\in \\mscrA}.\n  \\end{equation*}\n\n  For every set \\( A \\in \\mscrA \\) we have \\( [f \\bincirc g](A) = A \\). Given a set \\( A \\), \\( g \\) gives us a pair \\( (A, x) \\) with \\( x \\in A \\) and so \\( f(A, x) = A \\).\n\n  Finally, define the choice function\n  \\begin{equation*}\n    \\begin{aligned}\n      &c: \\mscrA \\to \\bigcup \\mscrA, \\\\\n      &c(A) \\coloneqq x \\T{where} (A, x) = g(A).\n    \\end{aligned}\n  \\end{equation*}\n\n  Since the family \\( \\mscrA \\) was arbitrary, we can conclude that the axiom of choice holds.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:function_invertibility_categorical}\n  We prove this result here rather than in \\fullref{subsec:functions} because it requires \\fullref{thm:surjective_functions_are_right_invertible}, which requires the axiom of choice introduced in this section.\n\n  In relation to \\hyperref[def:morphism_invertibility]{morphism invertibility} in the category \\hyperref[def:category_of_small_sets]{\\( \\cat{Set} \\)}, we have the following:\n  \\begin{thmenum}\n    \\thmitem{thm:function_invertibility_categorical/empty} An \\hyperref[def:multi_valued_function/empty]{empty function} is always \\hyperref[def:function_invertibility/injective]{injective} and \\hyperref[def:morphism_invertibility/left_invertible]{left-invertible}, however only if its range is empty is it \\hyperref[def:morphism_invertibility/left_cancellative]{left-cancellative}, \\hyperref[def:morphism_invertibility/right_cancellative]{right-cancellative}, \\hyperref[def:morphism_invertibility/right_invertible]{right-invertible} or \\hyperref[def:function_invertibility/surjective]{surjective}.\n\n    \\thmitem{thm:function_invertibility_categorical/nonempty_left_invertible} A nonempty function is \\hyperref[def:morphism_invertibility/left_invertible]{left-invertible} if and only if it is \\hyperref[def:function_invertibility/injective]{injective}.\n\n    \\thmitem{thm:function_invertibility_categorical/left_cancellative} A function is \\hyperref[def:morphism_invertibility/left_cancellative]{left-cancellative} if and only if it is \\hyperref[def:function_invertibility/injective]{injective}.\n\n    \\thmitem{thm:function_invertibility_categorical/right_invertible} A function is \\hyperref[def:morphism_invertibility/right_invertible]{right-invertible} if and only if it is \\hyperref[def:function_invertibility/surjective]{surjective}.\n\n    \\thmitem{thm:function_invertibility_categorical/right_cancellative} A function is \\hyperref[def:morphism_invertibility/right_cancellative]{right-cancellative} if and only if it is \\hyperref[def:function_invertibility/surjective]{surjective}.\n\n    \\thmitem{thm:function_invertibility_categorical/fully_invertible} A function is \\hyperref[def:function_invertibility/bijective]{bijective} if and only if it is \\hyperref[def:morphism_invertibility/isomorphism]{fully invertible}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:function_invertibility_categorical/empty} Let \\( g: \\varnothing \\to C \\) be the empty function to \\( C \\). It is vacuously injective. It is also left-invertible because the only function that can be composed with \\( g: \\varnothing \\to C \\) from the left is the unique function from \\( \\varnothing \\) to \\( \\varnothing \\).\n\n  Clearly \\( g: \\varnothing \\to C \\) it is surjective if and only if \\( C = \\varnothing \\).\n\n  For left-invertibility, note that \\( g: \\varnothing \\to C \\) composed with the function \\( h: C \\to D \\) on the left is another empty function \\( h \\bincirc g: \\varnothing \\to D \\). The latter is the identity \\( \\id_\\varnothing \\) if and only if \\( C = D = \\varnothing \\).\n\n  For right-invertibility, note that \\( g: \\varnothing \\to C \\) composed with the function \\( f: A \\to \\varnothing \\) on the right is the function \\( g \\bincirc f: A \\to C \\). But \\( A = \\varnothing \\) since otherwise \\( f \\) would be nonempty, hence \\( g \\bincirc f: \\varnothing \\to C \\). The latter is the identity \\( \\id_\\varnothing \\) if and only if \\( C = \\varnothing \\).\n\n  For right-cancellation, note that \\( g \\bincirc f_1 = g \\bincirc f_2 \\) implies \\( f_1 = f_2 \\) if and only if \\( B \\) is empty.\n\n  \\SubProofOf{thm:function_invertibility_categorical/nonempty_left_invertible} Let \\( f: A \\to B \\) be a nonempty injective function. \\Fullref{def:function_invertibility/injective/inverse} states that the \\hyperref[def:multi_valued_function/inverse]{inverse} \\( f^{-1}: B \\to A \\) is a partial single-valued function.\n\n  Fix some value \\( a \\in A \\) and define\n  \\begin{equation*}\n    \\begin{aligned}\n      &g: B \\to A \\\\\n      &g(y) \\coloneqq \\begin{cases}\n        f^{-1}(y), &y \\in f(A) \\\\\n        a,         &\\T{otherwise.}\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  This function \\( g \\) is a left inverse of \\( f \\) because, for any \\( x \\in A \\),\n  \\begin{equation*}\n    [g \\bincirc f](x)\n    =\n    g(f(x))\n    =\n    f^{-1}(f(x))\n    =\n    x.\n  \\end{equation*}\n\n  We can see that \\( g \\) would be unique except for our choice of \\( a \\). We may even define \\( g \\) to take different values in \\( A \\) outside \\( f(A) \\). Thus, \\( g \\) is non-unique in general.\n\n  Conversely, suppose that \\( f: A \\to B \\) is not necessarily injective and let \\( g: B \\to A \\) be a left inverse of \\( f \\). Let \\( x_1 \\) and \\( x_2 \\) be two different points in \\( A \\). Since \\( g \\bincirc f = \\id_A \\), clearly \\( g(f(x_1)) \\neq g(f(x_2)) \\). If we suppose that \\( f(x_1) = f(x_2) \\), we would obtain a contradiction since then \\( g(f(x_1)) \\) would equal \\( g(f(x_2)) \\). Hence, \\( f(x_1) \\neq f(x_2) \\). This shows that \\( f \\) is injective.\n\n  \\SubProofOf{thm:function_invertibility_categorical/left_cancellative} The case with an empty function is handled in \\fullref{thm:function_invertibility_categorical/empty}, and we assume that it is nonempty.\n\n  Suppose that \\( g: B \\to C \\) is a nonempty left-cancellative function. Let \\( y_1 \\) and \\( y_2 \\) be some members of \\( B \\) such that \\( g(y_1) = g(y_2) \\).\n\n  Suppose that \\( y_1 \\neq y_2 \\) and define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: B \\to B \\\\\n      &f(y) \\coloneqq \\begin{cases}\n        y_2, &y = y_1 \\\\\n        y_1, &y = y_2 \\\\\n        y,   &y \\neq y_1 \\T{and} y \\neq y_2\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    g(f(y_2)) = g(y_1) = g(y_2) = g(f(y_1))\n  \\end{equation*}\n\n  For all \\( y \\in B \\) different from \\( y_1 \\) and \\( y_2 \\), we have \\( y = f(y) \\).\n\n  Since \\( g \\) is left-cancellative, from \\( g \\bincirc \\id_B = g \\bincirc f \\) it follows that \\( \\id_B = f \\), which is a contradiction.\n\n  It remains for \\( y_1 \\) to be equal to \\( y_2 \\). Since these were arbitrary points in \\( B \\) satisfying \\( g(y_1) = g(y_2) \\), we conclude that \\( g \\) is injective.\n\n  Conversely, if \\( f \\) is injective, it is left-invertible by \\fullref{thm:function_invertibility_categorical/nonempty_left_invertible} and left-cancellative by \\fullref{thm:def:morphism_invertibility/split_monomorphism}.\n\n  \\SubProofOf{thm:function_invertibility_categorical/right_invertible} In one direction, we have \\fullref{thm:surjective_functions_are_right_invertible}.\n\n  Conversely, suppose that \\( g: B \\to A \\) is a right inverse of \\( f: A \\to B \\). Let \\( y \\in B \\). We have that \\( g(y) \\) is in the preimage of \\( y \\) under \\( f \\) because \\( f(g(y)) = y \\). Thus, the preimage is not empty for an arbitrary point in \\( B \\). We conclude that \\( f \\) is surjective.\n\n  \\SubProofOf{thm:function_invertibility_categorical/right_cancellative} The case with an empty function is handled in \\fullref{thm:function_invertibility_categorical/empty}, and we assume that it is nonempty.\n\n  Let \\( f: A \\to B \\) be a nonempty right-cancellative function. Suppose that it is not surjective and let \\( y_0 \\in B \\setminus \\img f \\). Let \\( z \\) be some set not belonging to \\( B \\). Define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &g: B \\to B \\cup \\set{ z } \\\\\n      &g(y) \\coloneqq \\begin{cases}\n        z, &y = y_0 \\\\\n        y, &y \\neq y_0\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  Since \\( f \\) is right-cancellative, from \\( \\id_B \\bincirc f = g \\bincirc f \\) it follows that \\( \\id_B = g \\), which is a contradiction. Therefore, \\( f \\) is surjective.\n\n  We can prove the converse using \\fullref{thm:function_invertibility_categorical/right_invertible} like we did for \\fullref{thm:function_invertibility_categorical/left_cancellative}, however we prefer a direct proof that does not rely on the axiom of choice. As a bonus, this would allow us to prove \\fullref{thm:epimorphisms_split_in_set}.\n\n  Conversely, suppose that \\( f: A \\to B \\) is surjective and that for some functions \\( g_1, g_2: B \\to C \\) we have\n  \\begin{equation*}\n    g_1 \\bincirc f = g_2 \\bincirc f.\n  \\end{equation*}\n\n  Fix some \\( y \\in B \\). Because \\( f \\) is surjective, there exists some \\( x \\in A \\) such that \\( f(x) = y \\). Then\n  \\begin{equation*}\n    g_1(y) = [g_1 \\bincirc f](x) = [g_2 \\bincirc f](x) = g_2(y).\n  \\end{equation*}\n\n  Since \\( y \\in B \\) was arbitrary, we conclude that \\( f \\) is right-cancellative.\n\n  it is right-invertible by \\fullref{thm:surjective_functions_are_right_invertible} and right-cancellative by \\fullref{thm:def:morphism_invertibility/split_epimorphism}.\n\n  \\SubProofOf{thm:function_invertibility_categorical/fully_invertible} If \\( f: \\varnothing \\to B \\) is a bijective empty function, then it is surjective and, by \\fullref{thm:function_invertibility_categorical/right_invertible}, it is right-invertible. By \\fullref{thm:function_invertibility_categorical/empty}, it is also left-invertible. Thus, it is fully invertible.\n\n  Conversely, if an empty function \\( f: \\varnothing \\to B \\) is fully invertible, by \\fullref{thm:function_invertibility_categorical/empty} we have \\( A = B = \\varnothing \\) and hence it is bijective.\n\n  Finally, if \\( f: A \\to B \\) is \\hi{nonempty} function, then by \\fullref{thm:function_invertibility_categorical/nonempty_left_invertible} and \\fullref{thm:function_invertibility_categorical/right_invertible} it is bijective if and only if it is fully invertible.\n\n  In the bijective case, we can avoid the axiom of choice via \\fullref{thm:surjective_functions_are_right_invertible} by noting that if \\( f \\) is bijective, its inverse is single-valued, and thus it is not necessary to do a selection of \\( f^{-1} \\).\n\\end{proof}\n\n\\begin{theorem}[Axiom of choice equivalences]\\label{thm:axiom_of_choice_equivalences}\n  The following statements are commonly referred to as \\enquote{the} \\hyperref[def:zfc/choice]{axiom of choice}:\n  \\begin{thmenum}[series=thm:axiom_of_choice_equivalences]\n    \\thmitem{thm:axiom_of_choice_equivalences/choice_sets} For every family of nonempty sets \\( \\mscrA \\) there exists a set \\( B \\) such that \\( A \\cap B \\) is a singleton set for every \\( A \\in \\mscrA \\).\n\n    \\thmitem{thm:axiom_of_choice_equivalences/choice_function} Every family of nonempty sets has a corresponding \\hyperref[def:choice_function]{choice function}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/choice_product} The \\hyperref[def:cartesian_product]{Cartesian product} of a family of nonempty sets is nonempty.\n  \\end{thmenum}\n\n  The following statements are equivalent to the axiom of choice, but are not conflated with it:\n  \\begin{thmenum}[resume=thm:axiom_of_choice_equivalences]\n    \\thmitem{thm:axiom_of_choice_equivalences/selection} \\Fullref{thm:existence_of_multi_valued_function_selection}: Every \\hyperref[def:multi_valued_function/total]{total multi-valued function} has a \\hyperref[def:function/selection]{selection}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/surjective} \\Fullref{thm:surjective_functions_are_right_invertible}: Every \\hyperref[def:function_invertibility/surjective]{surjective function} is \\hyperref[def:morphism_invertibility/right_invertible]{right-invertible}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/hypergraph} \\Fullref{thm:hypergraphs_have_minimal_transversal}: Every \\hyperref[def:hypergraph]{hypergraph} has a \\hyperref[def:hypergraph_minimal_transversal]{minimal transversal}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/epimorphisms} \\Fullref{thm:epimorphisms_split_in_set}: Every \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphism} in \\hyperref[def:category_of_small_sets]{\\( \\cat{Set} \\)} splits.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/fully_faithful_essentially_surjective} \\Fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}: 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    \\thmitem{thm:axiom_of_choice_equivalences/skeletons} \\Fullref{thm:category_skeleton_existence}: Every \\hyperref[def:category]{category} has a \\hyperref[def:skeletal_category]{skeleton}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/well_ordering} \\Fullref{thm:well_ordering_theorem}: Every \\hyperref[def:set]{set} can be \\hyperref[def:well_ordered_set]{well-ordered}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/zorns_lemma} \\Fullref{thm:zorns_lemma}: If every \\hyperref[def:partially_ordered_set_chain_and_antichain]{chain} in a \\hyperref[def:partially_ordered_set]{partially ordered set} has an \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{upper bound}, then the entire set has a \\hyperref[def:partially_ordered_set_extremal_points/maximal_and_minimal_element]{maximal element}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/maximal_ideal} \\Fullref{thm:maximal_ideal_theorem}: Every proper \\hyperref[def:semiring_ideal]{semiring ideal} is contained in a \\hyperref[def:semiring_ideal/maximal]{maximal ideal}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/vector_space_bases} \\Fullref{thm:vector_space_basis_existence}: Every \\hyperref[def:vector_space]{vector space} has a \\hyperref[def:hamel_basis]{basis}.\n\n    \\thmitem{thm:axiom_of_choice_equivalences/tychonoff} \\Fullref{thm:tychonoffs_product_theorem}: The \\hyperref[def:topological_product]{topological product} of \\hyperref[def:compact_space]{compact spaces} is compact.\n  \\end{thmenum}\n\\end{theorem}\n\\begin{proof}\n  The equivalence proofs can be found in the linked theorems since that is usually the most appropriate place to put them.\n\\end{proof}\n\n\\begin{theorem}[Diaconescu-Goodman-Myhill theorem]\\label{thm:diaconescu_goodman_myhill_theorem}\\mcite[corr. 2]{Diaconescu1975}\n  In \\hyperref[def:zfc]{\\logic{ZF}}, the \\hyperref[def:zfc/choice]{axiom of choice} entails the law of the excluded middle \\eqref{eq:thm:minimal_propositional_negation_laws/lem}.\n\\end{theorem}\n", "meta": {"hexsha": "001f0949e34e3d6696c7bd35d8a94972cfe5ec43", "size": 41101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/zermelo_fraenkel_set_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/zermelo_fraenkel_set_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/zermelo_fraenkel_set_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": 82.202, "max_line_length": 618, "alphanum_fraction": 0.7274762171, "num_tokens": 12602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6862836012897703}}
{"text": "\\lab{Compressed Sensing}{Compressed Sensing}\n\\label{lab:compressed_sensing}\n\n\\objective{Learn About Techniques in Compressed Sensing.}\n\n\nOne of the more important and fundamental problems in mathematics and science is solving a system of linear equations\n\\[\nAx = b.\n\\]\nDepending on the properties of the matrix $A$ (such as its dimensions and rank), there may be exactly one\nsolution, infinitely many solutions, or no solution at all. \n\nIn the case where $A$ is a square invertible matrix, there is of course one unique solution, given by\n$A^{-1}b$. There are various computational methods for inverting $A$, and we have studied many of them previously.\n\nWhen $b$ does not lie in the range of $A$, there is no exact solution. We can still hope to find approximate solutions,\nand techniques such as least squares and least absolute deviations provide ways to do this.\n\nThe final case is when there are infinitely many vectors $x$ that satisfy $Ax = b$. How do we decide which vector\nto choose? A common approach is to choose a vector $x$ of minimal norm satisfying $Ax = b$. This can be stated as \nan optimization problem:\n\\begin{align*}\n\\text{minimize}\\qquad &\\|x\\|\\\\\n\\text{subject to} \\qquad &Ax = b.\n\\end{align*}\n\nWhen we use the standard Euclidean $2$-norm, the problem is equivalent to the quadratic program\n\\begin{align*}\n\\text{minimize}\\qquad &x^Tx\\\\\n\\text{subject to} \\qquad &Ax = b,\n\\end{align*}\nwhich we can solve using an iterative procedure. Alternatively, the solution is given directly by $A^\\dagger b$,\nwhere $A^\\dagger$ is the Moore-Penrose pseudoinverse of $A$. \n\nIf instead of the $2$-norm we use the $1$-norm, our problem can be restated as a linear program, and solved\nefficiently using the Simplex Algorithm or an Interior Point method. Of course we can use any norm whatsoever, but\nfinding the solution may be much more difficult.\n\nThe basic problem in the field of Compressed Sensing is to recover or reconstruct certain types of signals\nfrom a small set of measurements. For example, we might have measurements of the frequency spectrum of an\naudio signal, and we wish to recover the original audio signal as nearly as possible. Mathematically, this\nproblem can be viewed as solving the under-determined system of equations\n$Ax = b$, where $b$ is a vector of measurements and $A$ is called the measurement matrix.\nThe crucial idea that Compressed Sensing brings to the table is the concept of \\emph{sparsity}, which we address now.\n\n\\section*{Sparsity and the $l_0$ Pseudonorm}\n\\emph{Sparsity} is a property of vectors in $\\mathbb{R}^n$ related to how compactly and concisely they can\nbe represented in a given basis. Stated more concretely, the sparsity of a vector $x$ (expressed in some given\nbasis) refers to how many nonzero entries are in $x$. A vector having at most $k$ nonzero entries is said to be\n$k$-sparse. This concept can be extended to time series (such as an audio signal) and to images. Figure 32.1 shows\nexamples of both sparse and non-sparse signals.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{sparse.pdf}\n\\caption{A sparse signal and a non-sparse signal.}\n\\label{fig:sparse}\n\\end{figure}\n\nAs a convenient way of measuring sparsity, we define the so-called $l_0$ pseudonorm, notated $\\|\\cdot\\|_0$,\nthat simply counts the number of nonzero entries in a vector. For example, if we have\n\\[\nx = \n\\begin{bmatrix}\n1&0&0&-4&0\n\\end{bmatrix}^T\n\\]\nand\n\\[\ny = \n\\begin{bmatrix}\n.5&.2&-.01&3&0\n\\end{bmatrix}^T,\n\\]\nwe then have\n\\[\n\\|x\\|_0 = 2\n\\]\nand\n\\[\n\\|y\\|_0 = 4.\n\\]\nDespite our choice of notation, $\\|\\cdot\\|_0$ is not truly a norm (which properties does it fail to satisfy?).\nKeep this in mind, even if we refer to it as the $l_0$ norm. \n\nAs mentioned earlier, sparsity is of central importance in Compressed Sensing, for it provides a way for us to \nselect from the infinite possibilities a single vector $x$ satisfying $Ax = b$. In particular, we require $x$ to \nbe as sparse as possible, i.e. to have minimal $l_0$ norm. Stated explicitly as an optimization problem, Compressed\nSensing boils down \n\\begin{align*}\n\\text{minimize}\\qquad &\\|x\\|_0\\\\\n\\text{subject to} \\qquad &Ax = b.\n\\end{align*}\n\n\\section*{Sparse Reconstruction}\nHow does the Compressed Sensing framework laid out above help us recover a signal from a set of measurements? \nIf we know nothing about the signal that we are trying to reconstruct, anything but a complete set of measurements\n(or \\emph{samples}) of the signal will be insufficient to fully recover the signal without any error. \n\nHowever, we can often make certain assumptions about the unknown signal, such as setting an upper bound for\nits highest frequency. Given this prior knowledge about the frequency of the signal, we \\emph{are} able to \nperfectly or nearly perfectly reconstruct the signal from an incomplete set of measurements, provided that\nthe sampling rate of the measurements is more than twice that of the largest frequency. This classic result\nin signal processing theory is known as the \\emph{Nyquist-Shannon sampling theorem}.\n\nWhat if, instead of having prior knowledge about the frequency of the signal, we have prior knowledge about\nits sparsity? Recent research asserts that it is possible to recover sparse signals to great accuracy from just \na few measurements. This matches intuition: sparse signals do not contain much information, and so it ought to\nbe possible to recover that information from just a few samples. Stated more precisely, if $\\hat{x} \\in \\mathbb{R}^n$ \nis sufficiently sparse and an $m \\times n$ matrix $A$ ($m < n$) satisfies certain properties (to be described later),\nwith $A\\hat{x} = b$, then the solution of the optimization problem\n\\begin{align*}\n\\text{minimize}\\qquad &\\|x\\|_0\\\\\n\\text{subject to}\\qquad &Ax = b\n\\end{align*}\nyields $\\hat{x}$. \n\nThe matrix $A$ above must satisfy a technical condition called the \\emph{Restricted Isometry Principle}. Most\nrandom matrices obtained from standard distributions (such as the Gaussian or Bernoulli distributions) satisfy this\ncondition, as do transformation matrices into the Fourier and Wavelet domains. Generally speaking,\nthe measurement matrix $A$ represents a change of basis from the \\emph{sparse} basis to the \\emph{measurement} basis, \nfollowed by an under-sampling of the signal. The Restricted Isometry Principle guarantees that the measurement\nbasis is incoherent with the sparse basis; that is, a sparse signal in the sparse basis is diffuse in the measurement\nbasis, and vice versa (see Figure \\ref{fig:incoherent}). This ensures that the information contained in the few nonzero\ncoefficients in the sparse\ndomain is spread out randomly and roughly evenly among the coefficients in the measurement domain. \nWe can then obtain a small random subset of these measurement coefficients, solve the above optimization problem,\nand recover the original signal. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{incoherent.pdf}\n\\caption{A sparse image (left) and its Fourier transform (right). The Fourier domain is incoherent with the \nstandard domain, so the Fourier transform of the spare image is quite diffuse.}\n\\label{fig:incoherent}\n\\end{figure}\n\nFortunately, many types of signals that we wish to measure are sparse in some domain. For example, many images\nare sparse in the Wavelet domain. It turns out that the Fourier domain is incoherent with the Wavelet domain,\nso if we take measurements of the image in the Fourier domain, we are able to recover the image with high \nfidelity from relatively few measurements. This has been particularly useful in magnetic resonance imaging \n(MRI), a medical process that obtains pictures of tissues and organs in the body by taking measurements in\nthe Fourier domain. Collecting these measurements can in some cases be harmful. Compressed sensing\nallows for fewer measurements and therefore a shorter, safer MRI experience.\n\n\\section*{Solving the $l_0$ Minimization Problem}\nNow that we have become familiar with the mathematical underpinnings of compressed sensing, let us now turn to \nactually solving the problem. Unfortunately, the $l_0$ minimization problem stated above is NP hard and thus \ncomputationally intractable in its current form. Another key result in compressed sensing states that we can\nreplace the $l_0$ norm with the $l_1$ norm and with high probability still recover the original signal, provided\nit is sufficiently sparse. Since the $l_1$ minimization problem can be solved efficiently, we have a viable \ncomputational approach to compressed sensing. \n\nRecall that we can convert the $l_1$ minimization problem into a linear program by introducing an additional\nvector $u$ of length $n$, and then solving\n\\begin{align*}\n\\text{minimize}\\qquad \n&\\begin{bmatrix}\n\\mathbf{1} & 0\n\\end{bmatrix}\n\\begin{bmatrix}\nu \\\\\nx\n\\end{bmatrix}\\\\\n\\text{subject to}\\qquad\n&\\begin{bmatrix}\n-I & I\\\\\n-I & -I\n\\end{bmatrix}\n\\begin{bmatrix}\nu \\\\\nx\n\\end{bmatrix}\n\\leq \n\\begin{bmatrix}\n0\\\\\n0\n\\end{bmatrix},\\\\\n&\\begin{bmatrix}\n0 & A\n\\end{bmatrix}\n\\begin{bmatrix}\nu \\\\\nx\n\\end{bmatrix}\n= \nb.\n\\end{align*}\nOf course, solving 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 \\li{l1Min} that takes a matrix $A$ and vector $b$ as inputs, and returns the solution to the \noptimization problem \n\\begin{align*}\n\\text{minimize}\\qquad &\\|x\\|_1\\\\\n\\text{subject to} \\qquad &Ax = b.\n\\end{align*}\nFormulate the problem as a linear program, and use CVXOPT to obtain the solution.\n\\end{problem}\n\nLet's reconstruct a sparse image using different numbers of measurements, and compare results.\nLoad the image contained in the file \\li{ACME.png} into Python as follows:\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n>>> acme = 1 - plt.imread('ACME.png')[:,:,0]\n>>> acme.shape\n(32L, 32L)\n\\end{lstlisting}\nThe image contains $32^2$ pixels, and so viewed as a flat vector, it has $32^2$ entries.\nNow build a random measurement matrix based on $m$ samples as follows:\n\\begin{lstlisting}\n>>> # assume the variable m has been initialized\n>>> np.random.seed(1337)\n>>> A = np.random.randint(0,high=2,size=(m,32**2))\n\\end{lstlisting}\nNext, calculate the $m$ measurements:\n\\begin{lstlisting}\n>>> b = A.dot(acme.flatten())\n\\end{lstlisting}\nWe are now ready to reconstruct the image using our function \\li{l1Min}:\n\\begin{lstlisting}\n>>> rec_acme = l1Min(A,b)\n\\end{lstlisting}\n\n\\begin{problem}\nFollowing the example above, reconstruct the ACME image using 200, 250, and 270 measurements.\nBe sure to execute the code \\li{np.random.seed(1337)} prior to each time you initialize\nyour measurement matrix, so that you will obtain consistent answers. Report the $2$-norm\ndistance between the each reconstructed image and the original ACME image. \n\\end{problem}\n\nFigure \\ref{fig:reconstruct} shows the results of reconstructing a similar sparse image using both the $1$-norm and \nthe $2$-norm.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{reconstruct.pdf}\n\\caption{A sparse image (left), perfect reconstruction using $l_1$ minimization (middle),  and\nimperfect reconstruction using $l_2$ minimization (right).}\n\\label{fig:reconstruct}\n\\end{figure}\n\\section*{Tesselated Surfaces and the Single Pixel Camera}\nWe now generalize our discussion to reconstructing functions defined on surfaces. Such a function might\ngive a color at each point on the surface, or the temperature, or some other property. The surface may be \na sphere (to model the surface of the earth), a cube, or some other desired form. To make the problem \ntractable, we must break the surface up into a set of discrete polygonal faces, called a tessellation. See\nFigure \\ref{Fig:Earth} for an example of a tessellated sphere.\n\nNow that we have a tessellation, our function can be represented by a vector, consisting of the function value \nfor each facet (element of the tessellation). We are thus in a position to apply the techniques of compressed\nsensing to recover the function. \n\nHow do we go about acquiring color measurements on a tessellated surface? One cheap method is to use a \\emph{single-pixel\ncamera}. Such a camera can only measure color value at a time. The camera points to a specific spot on the surface, and\nrecords a weighted average of the colors near that spot. By taking measurements at random spots across the surface,\nthe single-pixel camera provides us with a vector of measurements, which we can then use to reconstruct the color value for\neach facet of the tessellation. See Figure \\ref{Fig:Earth} for the results of a single-pixel camera taking measurements of the earth.\n\n\\begin{figure}\n\\begin{center}\n$\\begin{array}{cc}\n\\includegraphics[scale = .6]{OriginalCropped} &\n\\includegraphics[scale = .6]{EstimatedCropped} \\\\\n\\includegraphics[scale = .5]{Original2Cropped} &\n\\includegraphics[scale = .5]{Estimated2Cropped} \\\\\n\\mbox{\\bf (a)} & \\mbox{\\bf (b)}\n\\end{array}$\n\\end{center}\n\\caption{A 3-D model of the earth, with 5120 faces. $(a)$ shows two views of the model drawn directly from satellite imagery. $(b)$ shows two views of the reconstruction based upon 2500 single-pixel measurements.}\n\\label{Fig:Earth}\n\\end{figure}\n\nThe single-pixel camera measurement process can be modeled as matrix multiplication\nby a measurement matrix $A$, which fortunately has the Restricted Isometry Property. In the following,\nwe provide you with code to take single pixel measurements. It works as follows \n\\begin{lstlisting}\nrun camera.py\nmyCamera=Camera(faces,vertices,colors)\n\\end{lstlisting}\nWhere faces, verticies and colors are given by the tesselation. To take a picture you use \n\\begin{lstlisting}\nmyCamera.add_pic(theta,phi,r)\n\\end{lstlisting}\nWhere theta, phi, and r are the spherical coordinates of the camera. Recall to change spherical coordinates to rectangular the formula is   \n\\[\n(r\\sin(\\phi)\\cos(\\theta),r\\sin(\\phi)\\sin(\\theta),r\\cos(\\phi))\n\\]\nWhere $\\theta \\in [0,2\\pi),\\phi \\in [0,\\pi), r \\in [0,\\infty)$\n\nCalling \\li{add_pic} many times at different places on a sphere (constant $r$ value, varying $\\theta$ and $\\phi$) will build the measurement matrix as well as the measurements. You can return these by\n\\begin{lstlisting}\nA,b=myCamera.returnData()\n\\end{lstlisting}\n\nIn this applications signals are only sparse in some appropriate representation (such as Fourier or wavelet). This method generally can still be applied in such cases. Let $V$ represent the transformation under which $s$ is sparse, or in other words:\n\\begin{equation}\ns = V p\n\\end{equation}\n$V$ is the inverse Fourier. We can then recast $A s=b$ as\n\\begin{equation}\nA V p = b\n\\end{equation}\nThis then allows us to find $p$ using Compressed Sensing, which in turn allows us to reconstruct $s$ by using $V$. In the the following problem $V$ will be given to you.\n\nYou must reconstruct the color functions\nfor the tesselated surfaces, and then plot these surfaces using the code we provide you.\n\n%\\begin{problem}\n%We will perform compressed sensing on a Rubik's cube. The Rubik's cube has a natural tessellation, with each facet\n%being a square having one color. Each color can be represented as a vector of length 3, where we have split the\n%color into three color channels (red, green, and blue). The set of colors for the entire Rubik's cube is fairly\n%sparse in each color channel, so we can reconstruct the color values in each color channel separately.\n%\n%In the file \\li{StudentRubiksData.npz}, we have given you the measurement matrices for each color channel\n%(accessed by the keys \\li{'A1', 'A2', 'A3'}) along with the respective measurements in each color channel\n%(accessed by the keys \\li{'b1', 'b2', 'b3'}). Reconstruct the colors in each color channel, obtaining\n%three arrays. Then stack these arrays row-wise into an array with three rows. Report this final array.\n%\n%To visualize your result, we have provided code in the file \\li{visualize.py} that you can call.\n%You also need to load in the array corresponding to the key \\li{'centers'} in the data archive\n%\\li{StudentRubiksData.npz}. We assume the variable holding this array is named \\li{c}.\n%Execute the following (assuming that the variable holding the array\n%you obtained above containing the reconstructed colors is named \\li{r}):\n%\\begin{lstlisting}\n%>>> from visualize import visualizeSurface\n%>>> visualizeSurface(r.clip(0,1), c, 3)\n%\\end{lstlisting}\n%You should see a plot showing the Rubik's cube.\n%\\end{problem}\n\n\\begin{problem}\nWe will reconstruct the surface of the earth from sparse satellite imagery. The earth is modeled by a sphere,\nwhich can be tessellated into triangular faces, each having a color value. There are three color \nchannels, and the colors are sparse in each channel in the appropriate basis. \n\nIn the file \\li{StudentEarthData.npz}, we have given you the faces, vertices, colors, and the inverse fourier matrix, (accessed by the key \\li{'faces'}, \\li{'vertices'}, \\li{'C'}, and \\li{'V'} respectively), Take pictures with the single pixel camera code (using $r=3$) and then reconstruct the colors in each color channel, obtaining\nthree arrays. Then stack these arrays column-wise into an array with three columns. Report this final array.\n\nTo visualize your result, we have provided code in the file \\li{visualize2.py} that you can call.\nExecute the following (assuming that the variable holding the array\nyou obtained above containing the reconstructed colors is named \\li{s}):\n\\begin{lstlisting}\n>>> from visualize2 import visualizeEarth\n>>> visualizeEarth(faces, vertices, s.clip(0,1))\n\\end{lstlisting}\nYou should see a plot showing the reconstructed earth. We could have reconstructed a more detailed earth by choosing a finer tessellation, but you should be able to make out the shapes of the major continents. You can compare this to the original by running\n\\begin{lstlisting}\n>>> visualizeEarth(faces, vertices, colors)\n\\end{lstlisting}\n\nTry the reconstruction with 450, 550, 650 measurements and report the absolute difference between the reconstruction and the actual colors.\n\\end{problem}", "meta": {"hexsha": "82784d4011d3db7b2425180ccb21c088e5aebe2d", "size": 18006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/CompressedSensing/CompSense.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/CompressedSensing/CompSense.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/CompressedSensing/CompSense.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": 50.8644067797, "max_line_length": 334, "alphanum_fraction": 0.768688215, "num_tokens": 4561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.686214370281067}}
{"text": "\n\\outline{3}{Exercise 12.10}\n\\subsubsection*{Exercise 12.10}\n\n\\textit{What would happen if the space of the forest fire propagation were 1-D\nor 3-D? Conduct the renormalization group analysis to see what happens in those\ncases.}\n\n\\vspace{5mm}\n\\textbf{One-diomensional case:}\n\n\\vspace{5mm}\nThe probability of percolation for one cell is the probability of that cell\nassume value $1$:\n\\begin{equation}\n  p_1 = q.\n\\end{equation}\n\nExpand our group to two cells, the percolation proccess will occur only if the\ntwo cells assume value $1$:\n\\begin{equation}\n  p_2 = {p_1}^2.\n\\end{equation}\n\nIn fact, we can generalize the previous equation to:\n\\begin{equation}\n  p_{s+1} = {p_s}^2,\n\\end{equation}\n\nand conclude that if one cell in our system assume $0$, the propagation will be\nstopped.\n\n\\vspace{5mm}\n\\textbf{Three-diomensional case:}\n\n\\vspace{5mm}\nDespite the three dimensions of cells, the probability of percolation for one\ncell is equal to previous case:\n\\begin{equation}\n  p_1 = q.\n\\end{equation}\n\nIn this case is actually easier to list possibilities that don\\textquotesingle t\nallow percolation. The number of possible configurations for the renormalization\ngroup analysis made of $2\\times2\\times2$ cells is:\n\\begin{equation}\n  S = 256, \\qquad S = k^{L^{D}}, \\quad k = L = 2, \\quad D = 3.\n\\end{equation}\n\nSince cells have Moore\\textquotesingle s neighborhood, any cell is neighbor to\nthe other cells. Imagine the renormalization group as two $2\\times2$ planes, and\nthe percolation proccess from one plane to another. Possibilities that cells are\nall in one of these two planes prevents the percolation process. To list then:\n\n\\vspace{5mm}\n1 from empty cells; \\\\\n2 from 4 cells filled; \\\\\n8 from 3 cells filled; \\\\\n8 from 1 cell filled; \\\\\n12 from 2 cells filled;\n\n\\vspace{5mm}\nA total of 31 possibilities, that leads to the relation of possibilities in\nwhich we have percolation proccess and total number of possibilities:\n\\begin{equation}\n  \\frac{225}{256}\n\\end{equation}\n\nThe critical percolation threshold is given by:\n\\begin{equation}\n  \\begin{aligned}\n    p_c = { } & 1 - \\\\\n              & 1 \\times (1-p_c)^8 - \\\\\n              & 2 \\times {p_c}^4 (1-p_c)^4 - \\\\\n              & 8 \\times {p_c}^3 (1-p_c)^5 - \\\\\n              & 8 \\times p_c (1-p_c)^7 - \\\\\n              & 12 \\times {p_c}^2 (1-p_c)^6.\n  \\end{aligned}\n\\end{equation}\n\nAnd the cobweb plot for that equation is:\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.75\\textwidth]{./figures/12.10-cobweb-plot-for-3-dimensional.pdf}\n  \\caption{\\texttt{12.10-cobweb-plot-for-3-dimensional.py}}\n\\end{figure}\n\nIn which is easy to see two asymptotic states possible, $p_\\infty = 0$ and\n$p_\\infty = 1$ (the cobweb plot is about relations over scale, not about\ndynamics over time). There is an unstable equilibrium point around $p = 0.1$.\nThe approximate value is:\n\\begin{equation}\n  p \\approx 0.0794325.\n\\end{equation}\n\n\\textbf{Comparnison of cases:}\n\\vspace{5mm}\n\nThe relation of possibilities in which we have percolation proccess and total\nnumber of possibilities for the 1-D, 2-D and 3-D are, respectively:\n\\begin{equation}\n  \\frac{1}{4} < \\frac{9}{16} < \\frac{225}{256}.\n\\end{equation}\n\nFor one-dimensional systems, the critical percolation threshold is $100 \\%$,\nsince all cells must assume $1$ to percolation to occur. For two-dimensional,\nthe threshold is $38 \\%$. Finally, for three-dimensional systems, the threshold\nis under $8 \\%$.\n\n\\vspace{5mm}\nFrom this we can conclude that as we increase the number of dimensions, we\nincrease the susceptibility to percolation.\n", "meta": {"hexsha": "1bbe5fcca20ba9e120c8683b55364de10d4f4c6c", "size": 3541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/subsubsections/12.10.tex", "max_stars_repo_name": "brenoec/cefetmg.msc.sayama.solutions", "max_stars_repo_head_hexsha": "ea3f16427b8ade2b217647b75909966e038c3dc2", "max_stars_repo_licenses": ["MIT"], "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/subsubsections/12.10.tex", "max_issues_repo_name": "brenoec/cefetmg.msc.sayama.solutions", "max_issues_repo_head_hexsha": "ea3f16427b8ade2b217647b75909966e038c3dc2", "max_issues_repo_licenses": ["MIT"], "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/subsubsections/12.10.tex", "max_forks_repo_name": "brenoec/cefetmg.msc.sayama.solutions", "max_forks_repo_head_hexsha": "ea3f16427b8ade2b217647b75909966e038c3dc2", "max_forks_repo_licenses": ["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.3362831858, "max_line_length": 91, "alphanum_fraction": 0.7201355549, "num_tokens": 1060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.6862143508904208}}
{"text": "\\section{Neural Network}\r\n\\label{sec:NN}\r\nIn this article, we focus mainly on supervised learning rather \r\nthan unsupervised learning. In most cases, the tasks of neural \r\nnetworks turn out to be regression, binary classification for \r\ninstance. Generally speaking, a neural network approximate a\r\nfunction by minimizing the difference between the ideal one and\r\nthe approximated one. In short, what neural networks do is optimization.\r\n\\par In this section, we start with the representation of a neural\r\nnetwork and then further into the way neural networks solve an\r\noptimization problem.\r\n\r\n\\subsection{Neuron}\r\nNeuron is an abstract representation of the smallest component of\r\na neural network. Specifically neuron is a type of function \r\n$ g: \\mathbb{R}^n \\rightarrow \\mathbb{R}^n $, which is also called \r\nactivation function including ReLU, sigmoid, softmax etc. In various \r\nneural networks such as Deep Neural Network, Convolution Neural \r\nNetwork (CNN) and Recurrent Neural Network (RNN), neuron takes on \r\ndifference forms.\r\n\\par The basic model of neuron is illustrated in \\autoref{fig:neuron}.\r\nWe denote that $ x \\in \\mathbb{R}^n $ is the input data, \r\n$ W \\in \\mathbb{R}^n $ and $ b \\in \\mathbb{R} $ are the parameters in\r\nthe neuron, $ z \\in \\mathbb{R} $ is a cache given by:\r\n\\begin{align}\r\n    z = W^Tx + b\r\n\\end{align}\r\n\\par $ a \\in \\mathbb{R} $ is the output of a neuron given by:\r\n\\begin{align}\r\n    a = g(z)\r\n\\end{align}\r\n\\par $ g: \\mathbb{R}^n \\rightarrow \\mathbb{R}^n $ is the activation function.\r\n\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[width=10cm]{neuron}\r\n    \\caption{\\label{fig:neuron}The model of neuron}\r\n\\end{figure}\r\n\r\n\\par The most common used activation functions are ReLU, sigmoid which are\r\nillustrated in \\autoref{fig:activation}.\r\n\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\subfigure[ReLU: $g(z) = max(0,\\ z)$]{\r\n    \\begin{minipage}[t]{0.5\\linewidth}\r\n    \\centering\r\n    \\includegraphics[width=5cm]{ReLU.png}\r\n    \\end{minipage}%\r\n    }%\r\n    \\subfigure[sigmoid: $ \\sigma(z) = \\frac{1}{1+e^{(-z)}} $]{\r\n    \\begin{minipage}[t]{0.5\\linewidth}\r\n    \\centering\r\n    \\includegraphics[width=5cm]{sigmoid.png}\r\n    \\end{minipage}%\r\n    }%\r\n    \\centering\r\n    \\caption{\\label{fig:activation}Common activation functions}\r\n\\end{figure}\r\n\\par In multi-classification tasks, softmax \r\n$ g(z) = \\frac{e^z}{\\sum\\limits_{i=1}^{n}e^{z_i}},\\ z \\in \\mathbb{R}^n\\ $\r\nis widely used in the last neuron of the neural network.\r\n\r\n\\subsection{Architecture}\r\nVarious neurons form the neural networks, and the specific formation is called\r\nthe architecture of the neural networks. Most of the architecture like \r\nDeep Neural Network, CNN and RNN can be regarded as a set of layers, \r\neach layer consists of a bunch of neurons. The output of the previous layers\r\nserve as the input of the neurons in the current layer.\r\n\r\nFirst we define the following notations: $ l $ is the index of layer,\r\n$ L $ is the number of layers, $ n^{[l]} $ is the number of neurons \r\nin the $ l^{th} $ layer, $ W^{[l]} \\in \\mathbb{R}^{n^{[l]}\\times n^{[l-1]}} $ \r\nand $ b^{[l]} \\in \\mathbb{R}^{n^{[l]}\\times 1 } $ are the weights of neurons \r\nin the $ l^{th} $ layer, $ z^{[l]} \\in \\mathbb{R}^{n^{[l]}\\times 1} $ is \r\nthe caches of neurons in the $ l^{th} $ layer, \r\n$ a^{[l]} \\in \\mathbb{R}^{n^{[l]}\\times 1} $ is the output of neurons \r\nin the $ l^{th} $ layer, \r\n$ g^{[l]}: \\mathbb{R}^{n^{[l]}\\times 1} \\rightarrow \\mathbb{R}^{n^{[l]}\\times 1} $ \r\nis the activation function in the $ l^{th} $ layer.\r\n\\par The basic model of a neural network is demonstrated in \\autoref{fig:shallowNN},\r\nthe input $ x $ can also be considered as the $ 0^{th} $ layer, which means\r\n$ x = a^{[0]} $, and it is called the input layer. The last layer i.e. the $ L^{th} $\r\nlayer is called the output layer which means $ \\hat{y} = a^{[L]} $. \r\nThe remainder are called the hidden layers. \r\n\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[width=10cm]{shallowNN}\r\n    \\caption{\\label{fig:shallowNN}Shallow Neural Network}\r\n\\end{figure}\r\n\r\nShallow network is a simple type of neural network with only one hidden layer, \r\nwhile deep network, see \\autoref{fig:deepNN}, has multiple hidden layers thus is much more complicated than\r\nthe shallow one.\r\n\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[width=10cm]{deepNN}\r\n    \\caption{\\label{fig:deepNN}Deep Neural Network}\r\n\\end{figure}\r\n\r\n\\subsection{Loss Function}\r\nThe core of optimization problem is to minimize the cost. Given a set of labeled\r\ndata $ {x,\\ y},\\ x \\in \\mathbb{R}^{n^{[0]}\\times m}, \\ y \\in \\mathbb{R}^{1\\times m} $, \r\nwe denote that $ m $ is the number of data. We want to pick the parameters $ W,\\ b $\r\nin each neurons so that the predicted output $ \\hat{y} $ is close to the true\r\nvalue $ y $. To measure the difference we need to calculate the distance between\r\nthe predicted $ \\hat{y}^{(i)} $ from the $ i^{th} $ sample and $ y^{(i)} $. \r\nFor a certain distance metric $ l(\\hat{y}^{(i)},\\ y^{i}) $ which is also be regarded\r\nas loss function, we can\r\nwrite the total cost $ J(\\hat{y},\\ y) $ of the predicted $ \\hat{y} $ and \r\ndefine the optimization problem as:\r\n\r\n\\begin{equation}\r\n    \\begin{split}\r\n        & Given\\ \\{x,\\ y\\} \\\\\r\n        & \\mathop{\\arg\\min}_{W,\\ b}J(\\hat{y},\\ y) \\\\\r\n        & J(\\hat{y},\\ y) = \\sum\\limits_{i=1}^{m}l(\\hat{y}^{(i)},\\ y^{i})\r\n    \\end{split} \r\n\\end{equation}\r\n\r\n\\par As for the choice of $ l $, the most widely used one is $L_2$ Norm \r\ni.e. Euclidean Distance $ l(x,\\ y) = ||x - y||_2^2 $. Nevertheless, in\r\ndifference kinds of problems, there would be a corresponding loss function\r\nthat has the best performance. For instance, in binary classification problem,\r\nthe popular choice is binary cross-entropy: \\\\\r\n$ l(x,\\ y) = - x\\ln(y) - (1-x)\\ln(1-y) $; in multi-classification problem,\r\nthe popular choice is categorical cross-entropy: \r\n$ l(x,\\ y) = - \\sum\\limits_{j=1}^{n}x^{[j]}\\ln(y^{[j]}) $, where $ n $ is the \r\nnumber of classes.\r\n\r\n\\subsection{Gradient Descent}\r\n\\label{ssec:GD}\r\n\\subsubsection{Basic Intuition of GD}\r\nGradient descent (GD) is the foundation of a large scale of optimization algorithms\r\nin neural networks. Imagine that you stand on the top of a mountain and\r\nplan to go downhill, the most efficient choice is following the path that is the\r\nsteepest. Namely, the most efficient method to find the minimum of $ J $ is to\r\nchoose the gradient of $ J $ at the parameters $ W,\\ b $: \r\n$ \\nabla J(\\hat{y},\\ y) $ \\footnote{$\\nabla J(\\hat{y},\\ y) = \r\n(\\frac{\\partial J}{\\partial W^{[1]}},\\cdots,\\ \\frac{\\partial J}{\\partial W^{[L]}},\\\r\n\\frac{\\partial J}{\\partial b^{[1]}},\\cdots,\\ \\frac{\\partial J}{\\partial b^{[L]}} )^T $}\r\nHence, we update the parameters at the learning rate $ \\alpha $:\r\n\\begin{align}\r\n    \\label{equ:GD} W^{[l]} & = W^{[l]} - \\alpha\\frac{\\partial J}{\\partial W^{[l]}} \\\\\r\n    b^{[l]} & = b^{[l]} - \\alpha\\frac{\\partial J}{\\partial b^{[l]}}\r\n\\end{align}\r\nuntil $ J(\\hat{y},\\ y) $ is small enough.\r\n\r\n\\subsubsection{Basic Convergence Analysis of GD}\r\nIt is not clear that whether GD can converge to the required global minimum\r\nrather than local minimum. However, a notable paper by Dauphin et al. \r\n\\parencite{dauphin2014identifying} shows that based on empirical evidence,\r\nsaddle points are bigger challenges instead of local minimum. Especially \r\nin high dimensional problems, saddle points are often surrounded by \r\nrugged plateau which dramatically slow down the speed of convergence.\r\nMore detail about the landscape of neural network will be discussed in \r\n\\autoref{ssec:empirical}. Here we just give an basic analysis of GD algorithm.\r\n\\par Before the analysis, we need a criterion of convergence. There are mainly\r\ntwo criteria: the limit point is a stationary point and the convergence of \r\nthe function value. Apparently, the latter one is more easy to achieve.\r\n\\par In Bertsekas et al. \\parencite{bertsekas1997nonlinear}, proposition \r\n1.2.1 to 1.2.4 give the convergence result of GD. Considering the large\r\nscale of use of fixed learning rate, proposition 1.2.3 regarding the \r\nLipschitz value is the most helpful and well-known one. And its variant\r\nis shown in the following:\r\n\\begin{pro}\r\n    \\label{pro:ConstantConvergence}\r\n    Let $ \\{x_k\\} $ be a sequence generated by GD: $ x_{k+1} = x_{k} - \\alpha d_k $,\r\n    where $ \\{d_k\\} $ is the gradient of $ f(x_k) $. For some $ L>0,\\ \r\n    L \\in R $  that satisfies\\footnote{$ L $ is called the Lipschitz constant}:\r\n    \\begin{equation}\r\n        ||\\nabla f(x) - \\nabla f(y)||\\leq L||x - y||,\\ \\ \\ \\forall x,\\ y \\in \\mathbb{R}\r\n    \\end{equation}\r\n    If $ \\forall k,\\ d_k \\neq 0 $ and \r\n    \\begin{equation}\r\n        \\label{equ:learningRate}\r\n        \\epsilon \\leq \\alpha \\leq \\frac{2-\\epsilon}{L}\r\n    \\end{equation}\r\n    where $ \\epsilon \\in R^+ $. Then every limit point of $ \\{x_k\\} $ is a \r\n    stationary point of $f$.\r\n\\end{pro}\r\n\r\n\\begin{prf}\r\n    Using the descent lemma\\footnote{Details of descent lemma are in the \r\n    Appendix 1 }, we have:\r\n    \\begin{align}\r\n        f(x_k - \\alpha d_k) - f(x_k)&\\leq\\alpha\\nabla f(x_k)^Td_k + \\frac{1}{2}\\alpha^2L||d_k||^2 \\\\\r\n        & = \\alpha ||d_k||^2(\\frac{1}{2}\\alpha L - 1)\r\n    \\end{align}\r\n    The right-hand side of \\autoref{equ:learningRate} yields:\r\n    \\begin{align}\r\n        \\frac{1}{2}\\alpha L - 1 \\leq -\\frac{1}{2}\\epsilon\r\n    \\end{align}\r\n    Together with the left-hand of \\autoref{equ:learningRate}:\r\n    \\begin{align}\r\n        f(x_k) - f(x_k - \\alpha d_k) \\geq \\frac{1}{2}\\epsilon^2||d_k||^2\r\n    \\end{align}\r\n    If $ \\{x_k\\} $ converge to a non-stationary point $ x $, then $ ||d_k||^2 < 0 $ \r\n    and $ f(x_k) - f(x_k - \\alpha d_k) \\rightarrow 0 $, \r\n    so $ ||d_k|| \\rightarrow 0 $, which contradicts the assumption. Hence,\r\n    every limit point of $ \\{x_k\\} $ is stationary.  \\\\\r\n    \\textbf{Q.E.D.}\r\n\\end{prf}\r\n\r\n\\par According to \\autoref{pro:ConstantConvergence}, we can choose the \r\nlearning rate $ \\alpha = \\frac{2}{L} $ and guarantee that GD will converge.\r\nUnfortunately, for optimization in neural network, such a global Lipschitz \r\nconstant may not exist in most cases. until now, there seems to be no obvious\r\nway to fix the gap between the theorem and practice. In the article of Ruoyu Sun\r\n\\parencite{sun2019optimization}, a claim that may be sufficient for practitioners\r\nis proposed: if all parameters are bounded in each iteration, with \r\na small and proper learning rate $ \\alpha $, GD will converge.\r\n\r\n\r\n\r\n\\subsection{Forward Propagation}\r\nForward propagation (FP) is a method to compute the predicted $ \\hat{y} $\r\nfrom the input data. To illustrate the process of FP, we use the network\r\nshown in \\autoref{fig:deepNN}. For the first layer, input of neurons is\r\n$ A^{[0]} = (a^{[0](1)},\\cdots,\\ a^{[0](m)}) \\in \\mathbb{R}^{n^{[0]}\\times m} $,\r\nthe output is $ A^{[1]} $ and the cache is $ Z^{[1]} = (z^{[1](1)},\\cdots,\\ z^{[1](m)}) $. \r\n\\begin{equation}\r\n    \\begin{split}\r\n        Z^{[1]} & = W^{[1]}A^{[0]} + b^{[1]} \\\\\r\n        A^{[1]} & = g^{[1]}(Z^{[1]}) \\\\\r\n        & \\vdots\r\n    \\end{split}\r\n\\end{equation} \r\nTherefore, the general computation of the $ i^{th} $ layer is:\r\n\\begin{equation}\r\n    \\label{equ:FP}\r\n    \\begin{split}\r\n        Z^{[l]} & = W^{[l]}A^{[l-1]} + b^{[l]} \\\\\r\n        A^{[l]} & = g^{[l]}(Z^{[l]})\r\n    \\end{split}\r\n\\end{equation} \r\n\r\n\\subsection{Backward Propagation}\r\nBackward propagation (BP) is considered as an vital landmark in the \r\ndevelopment of neural networks. It highly boost the efficiency of the\r\ncomputation of gradient. Different from the FP, BP starts from the output\r\nlayer of the network and goes through the network to the front. \r\nWe denote that \r\n$ dA^{[l]} \\triangleq \\frac{\\partial J}{\\partial A^{[l]}} \r\n\\in \\mathbb{R}^{n^{[l]}\\times m} $,\r\n$ dZ^{[l]} \\triangleq \\frac{\\partial J}{\\partial Z^{[l]}} \r\n\\in \\mathbb{R}^{n^{[l]}\\times m} $,\r\n$ dW^{[l]} \\triangleq \\frac{\\partial J}{\\partial W^{[l]}} \r\n\\in \\mathbb{R}^{n^{[l]}\\times n^{[l-1]}} $ and\r\n$ db^{[l]} \\triangleq \\frac{\\partial J}{\\partial b^{[l]}} \r\n\\in \\mathbb{R}^{n^{[l]}\\times 1} $.\r\nFor the $ L^{th} $ layer, we can calculate the gradient by the following\r\nway\\footnote{the operator $*$ is element-wise multiplication}\r\n\\footnote{the update of parameters in GD involve the complete data set, \r\nwhile in the variant of GD like SGD and mini-batch GD, only part of the data\r\ncontribute to the update process in each iteration}:\r\n\\begin{equation}\r\n    \\begin{split}\r\n        dA^{[L]} & = \\frac{\\partial J}{\\partial A^{[L]}} \\\\\r\n        dZ^{[L]} & = dA^{[L]}*g^{[L]'}(Z^{[L]}) \\\\\r\n        dW^{[L]} & = \\frac{1}{m}dZ^{[L]}A^{[L-1]T} \\\\\r\n        db^{[L]} & = \\frac{1}{m}dZ^{[L]} \\\\\r\n        dA^{[L-1]} & = W^{[L-1]T}dZ^{[L]} \\\\\r\n        dZ^{[L-1]} & = dA^{[L-1]}*g^{[L-1]'}(Z^{[L-1]}) \\\\\r\n        & \\vdots\r\n    \\end{split}\r\n\\end{equation}\r\nSuppose the loss function of the output layer is binary cross-entropy: \\\\\r\n$ l(a^{[L]},\\ y) = - y\\ln(a^{[L]}) - (1-y)\\ln(1-a^{[L]}) $, then \r\nthe BP process can be written as:\r\n\\begin{equation}\r\n    \\label{equ:BP}\r\n    \\begin{split}\r\n        dZ^{[L]} & = A^{[L]} - y \\\\\r\n        dW^{[L]} & = \\frac{1}{m}dZ^{[L]}A^{[L-1]T} \\\\\r\n        db^{[L]} & = \\frac{1}{m}dZ^{[L]} \\\\\r\n        & \\vdots \\\\\r\n        dA^{[l]} & = W^{[l]T}dZ^{[l+1]} \\\\\r\n        dZ^{[l]} & = (W^{[l]T}dZ^{[l+1]})*g^{[l]'}(Z^{[l]}) \\\\\r\n        dW^{[l]} & = \\frac{1}{m}dZ^{[l]}A^{[l-1]T} \\\\\r\n        db^{[l]} & = \\frac{1}{m}dZ^{[l]}\r\n    \\end{split}\r\n\\end{equation}", "meta": {"hexsha": "cafceaea8444161d8ae1198120798aaf059caf66", "size": 13393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "body/undergraduate/final/section/NeuralNetwork.tex", "max_stars_repo_name": "xuebashuoge/Neural-Network-Overview", "max_stars_repo_head_hexsha": "ae11b768aeffe09ddd71b082dfd27c15c02d9c2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "body/undergraduate/final/section/NeuralNetwork.tex", "max_issues_repo_name": "xuebashuoge/Neural-Network-Overview", "max_issues_repo_head_hexsha": "ae11b768aeffe09ddd71b082dfd27c15c02d9c2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "body/undergraduate/final/section/NeuralNetwork.tex", "max_forks_repo_name": "xuebashuoge/Neural-Network-Overview", "max_forks_repo_head_hexsha": "ae11b768aeffe09ddd71b082dfd27c15c02d9c2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.9929824561, "max_line_length": 108, "alphanum_fraction": 0.6358545509, "num_tokens": 4341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6861811573526543}}
{"text": "\\begin{frame}\n  \\frametitle{Introduction}\n\n  \\bitvectors are extremely useful data structures,\n  used to symbolically represent hardware and software\n  constructs (see later)\n  \\vfill\n  \\pause\n  The world of \\bitvectors is a {\\bf finite} world, i.e.,\n  with \\bitvectors it is not possible to represent/handle \n  arbitrarily large numbers \n  \\vfill\n  \\pause\n  Indeed, when speaking about \\bitvectors we always\n  associate a {\\bf width}  \n  (which is usually a power of 2, often 32 or 64)\n  \\vfill\n  \\pause\n  The width specifies the (maximum) {\\bf number of bits} used to\n  represent variables and terms\n  \\vfill\n  \\pause\n  \\bitvector \\formulae are mathematically characterized by \n  the theory of \\bitvectors \\Bitvectors\n  \n\\end{frame}\n\n\\subsection{Syntax}\n\n\\begin{frame}\n  \\frametitle{Bit-Vectors}\n  \n  A bit-vector is an array of bits \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab.pdf_t}}\n  \\end{center} \n  \\vfill\n  \\pause\n\n  Selection (or Extraction): $\\w{a}{3}[1:0]$ \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_a_sel.pdf_t}} \n  \\end{center}\n\n  \\vfill\n  \\pause\n\n  Notice that\n  \\begin{itemize}\n    \\item $\\w{a}{n}[i:j]$ returns a \\bitvector of width $i - j + 1$ ($0 \\leq j \\leq i \\leq n - 1$) \\pause\n    \\item $\\w{a}{n}[n-1:0]$ \\pause $= \\w{a}{n}$ \\pause\n    \\item Selection has precedence over any other operator\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bit-Vectors}\n  \n  A bit-vector is an array of bits \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab.pdf_t}}\n  \\end{center} \n  \\vfill\n\n  Concatenation $\\w{a}{3} :: \\w{b}{3}$ \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab_conc.pdf_t}} \n  \\end{center}\n\n  \\vfill\n  \\pause\n\n  Notice that\n  \\begin{itemize}\n    \\item $\\w{a}{n} :: \\w{b}{m}$ returns a \\bitvector of width $n+m$ \\pause\n    \\item $\\w{a}{n}[n-1:i] :: \\w{a}{n}[i-1:0]$ \\pause $= \\w{a}{n}[n-1:0]$ \\pause $= \\w{a}{n}$\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bit-Vectors}\n  \n  A bit-vector is an array of bits \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab.pdf_t}}\n  \\end{center} \n  \\vfill\n\n  Arithmetic $\\w{a}{3} + \\w{b}{3}$ \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab_plus.pdf_t}} \n  \\end{center}\n\n  \\vfill\n  \\pause\n\n  Notice that\n  \\begin{itemize}\n    \\item To be precise, we should have written $\\w{a}{3} +_{[3]} \\w{b}{3}$ (widths must be the same)\n    \\item Semantic is that of {\\bf modular} arithmetic\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bit-Vectors}\n  \n  A bit-vector is an array of bits \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab.pdf_t}}\n  \\end{center} \n  \\vfill\n\n  Bitwise $\\w{a}{3} \\band \\w{b}{3}$ \n  \\smallskip \\\\\n  \\begin{center}\n  \\scalebox{.3}{\\input{bv_ab_bitw.pdf_t}} \n  \\end{center}\n\n  \\vfill\n  \\pause\n\n  Notice that\n  \\begin{itemize}\n    \\item Again, to be precise, we should have written $\\w{a}{3} \\band_{[3]} \\w{b}{3}$ (widths must be the same)\n    \\item Used to compute bit-mask operations\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{A (non-exhaustive) list of operators and predicates}\n\n  Each \\bitvector term of width $n$, is associated with a sort \\SBv{n} ($n \\geq 1$)\n  \\vfill\n  \\pause\n\n  \\begin{center}\n  \\begin{tabular}{|l|l|l|l|}\n    \\hline\n    Name                 & Symb      & Type                        & Signature \\\\\n    \\hline               \n    Selection            & $\\_[i:j]$ & \\multirow{2}{*}{Core}       & \\SBv{n}                  $\\rightarrow$ \\SBv{i-j+1} \\\\\n    Concatenation        & $::$      &                             & \\SBv{n} $\\times$ \\SBv{m} $\\rightarrow$ \\SBv{n+m} \\\\ \n    \\hline               \n    Addition             & $+$       & \\multirow{5}{*}{Arith.}     & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBv{n} \\\\\n    Subtraction          & $-$       &                             & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBv{n} \\\\\n    Multiplication       & $*$       &                             & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBv{n} \\\\\n    Less than (signed)   & $<_s$     &                             & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBoo \\\\\n    Less than (unsigned) & $<_u$     &                             & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBoo \\\\\n    \\hline\n    Bitwise and          & $\\band$   & \\multirow{3}{*}{Bitwise}    & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBv{n} \\\\\n    Bitwise or           & $\\bor$    &                             & \\SBv{n} $\\times$ \\SBv{n} $\\rightarrow$ \\SBv{n} \\\\\n    Bitwise not          & $\\bnot\\_$ &                             & \\SBv{n}                  $\\rightarrow$ \\SBv{n} \\\\\n    \\hline\n  \\end{tabular}\n  \\end{center}\n  \\vfill\n  \\pause\n\n  Moreover, we have constants, e.g., $101101_{[6]}$\n\n\\end{frame}\n\n\\subsection{Semantic}\n\n\\begin{frame}\n  \\frametitle{\\bitvector semantic}\n\n  \\scriptsize\n\n  Each sort \\SBv{n} is associated with a domain $D_n = \\{ 0, 1, \\ldots, 2^{n-1} \\}$ \\\\ \\pause\n  For example \\SBv{4} is associated with $D_{4} = \\{ 0, 1, \\ldots, 15 \\}$\n  \\vfill\n  \\pause\n  As usual, the semantic for the other terms depends on a particular {\\bf assignment}\n  to the variables\n  \\vfill\n  \\pause\n  Each variable $\\w{x}{n}$ is associated with a function \\inter{\\w{x}{n}} \n  of type $D_n \\rightarrow \\{ 0, 1 \\}$\n  \\vfill\n  \\pause\n  \\scalebox{.7}{\\input{semantic_example.pdf_t}}\n  \\vfill\n  \\pause\n  $nat_n(\\_)$ is a helper meta-function, to facilitate the presentation \n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{\\bitvector semantic}\n\n  \\scriptsize\n  $$\n  \\begin{array}{rcl}\n    %% Constant\n    \\inter{\\w{c}{n}} & := & \\lambda x \\in [0,n-1].\\, \n    \\left\\{\n    \\begin{array}{ll}\n      0 & \\mbox{ if the } x\\mbox{-th bit is } 0 \\\\\n      1 & \\mbox{ otherwise } \n    \\end{array}\n    \\right. \\\\\n    \\medskip \\\\\n    %% CONCATENATION\n    \\inter{\\w{t}{l} :: \\w{s}{k}} & := & \\lambda x \\in [0,\\ldots,l+k-1].\\,\n    \\left\\{\n    \\begin{array}{ll}\n      \\inter{\\w{s}{n}}(x) & \\mbox{ if } x < l \\\\\n      \\inter{\\w{t}{n}}(x-l) & \\mbox{ otherwise } \n    \\end{array}\n    \\right. \\\\\n    \\smallskip \\\\\n    %% SELECTION\n    \\inter{\\w{t}{n}[i:j]} & := & \\lambda x \\in [0,i-j+1].\\, \\inter{\\w{t}{n}}(x+j) \\\\\n    \\medskip \\\\\n    %% PLUS\n    \\inter{\\w{t}{n} + \\w{s}{n}} & := & nat_n^{-1}(nat_n(\\inter{\\w{t}{n}}) + nat_n(\\inter{\\w{s}{n}}))\\ \\%\\ 2^n \\\\\n    \\medskip \\\\\n    %% BITAND\n    \\inter{\\w{t}{n} \\band \\w{s}{n}} & := & \\lambda x \\in [0,n-1].\\,\n    \\left\\{\n    \\begin{array}{ll}\n    0 & \\mbox{ if } \\inter{\\w{t}{n}}(x) = 0 \\\\\n    0 & \\mbox{ if } \\inter{\\w{s}{n}}(x) = 0 \\\\\n    1 & \\mbox{ otherwise } \n    \\end{array} \n    \\right. \\\\\n    \\medskip \\\\\n    %% LESS THAN\n    \\inter{\\w{t}{n} <_u \\w{s}{n}} & := & \n    \\left\\{\n    \\begin{array}{ll}\n    \\top & \\mbox{ if } nat_n(\\inter{\\w{t}{n}}) <_{u} \n                       nat_n(\\inter{\\w{s}{n}}) \\\\\n    \\bot & \\mbox{ otherwise } \n    \\end{array}\n    \\right.\n  \\end{array}\n  $$\n\n\\end{frame}\n", "meta": {"hexsha": "4c534300f15797780c7bd262ae75b12db03fae17", "size": 6846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture2/intro.tex", "max_stars_repo_name": "formalmethods/smtlectures", "max_stars_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-07T19:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-24T08:05:50.000Z", "max_issues_repo_path": "lecture2/intro.tex", "max_issues_repo_name": "formalmethods/smtlectures", "max_issues_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture2/intro.tex", "max_forks_repo_name": "formalmethods/smtlectures", "max_forks_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-06T00:40:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T00:40:41.000Z", "avg_line_length": 27.0592885375, "max_line_length": 122, "alphanum_fraction": 0.5392930178, "num_tokens": 2495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6861722480193551}}
{"text": "\\chapter{Statistical methods I}\n\n\\section{Entrophy of source units}\n\nEntrophy is the amount of information contained in a unit measurred in bits. The more unexpeted the unit is, the higher is the amount of information it carries.\n\nThere are several basic terms:\n\n\\noindent\nSource units:\n$$S = \\{x_1, x_2, \\ldots, x_n\\}.$$\nSource unit probabilities:\n$$P = \\{p_1, p_2, \\ldots, p_n\\}.$$\nSource unit frequencies\\sidenote{Frequencies are usually associated with actual messages and their analysis.}:\n$$F = \\{f_1, f_2, \\ldots, f_n\\}.$$\nEntropy (information content) of unit $x_i$\\sidenote{How much bits of actual information unit represents.}:\n$$ H_i = - \\log_2 p_i.$$\nAverage entrophy of a source unit from S\\sidenote{How much bits of actual information represents a unit on average.}:\n$$H_{avg}(S) = \\sum_{i=1}^{n}{p_i H_i} = -\\sum_{i=1}^{n}{p_i \\log_2 p_i}.$$\n\n%\\section{Entrophy of a message}\n\n%Message\n%$$ X = x_1, x_2, \\ldots, x_n,$$\n\n\n%Entrophy of source message\n%Entrophy of encdoded message\n%Length of encoded message\n%$$L(X) = $$\n\n\\section{Entrophy of a code}\nTo each source unit, a codeword can be assigned. \n\n\\noindent\nCodewords (code units):\n$$C = \\{c_1, c_2, \\ldots, c_n\\}.$$\nAverage length of a codeword\\sidenote{How many actual bits are used for encoding a source unit into a codeword on average.}:\n$$L_{avg}(C) = \\sum_{i=1}^{n}{p_i |c_i|}.$$\n\n\\section{Propertis of codes}\n\nGiven the following source units, their probabilities and codewors, the average entrophy and the average length of the codeword can be calculated:\n\n\\noindent\nSource units:\n$$S = \\{\\texttt{a}, \\texttt{b}, \\texttt{c}, \\texttt{d}, \\texttt{e}\\}.$$\nSource unit probabilities:\n$$P = \\{0.1, 0.15, 0.3, 0.16, 0.29\\}.$$\nCodewords:\n$$C = \\{010, 011, 11, 00, 10\\}.$$\n\n\\begin{table}\n  \\begin{center}\n    \\begin{tabular}{|r|cccccc|}\n      \\hline\n      $x_i$ & $p_i$ & $c_i$ & $|c_i|$ & $H_i$ & $H_{avg}(S)$ & $L_{avg}(C)$      \\\\\n          &        &        &          & $-\\log_2 p_i$ & $p_i H_i$ & $p_i |c_i|$      \\\\\n      %      & unit & probability & code & code length & unit entrophy & average entrophy & average code length      \\\\\n      \\hline\n      a          & 0.10   & 010    & 3        & 3.32  & 0.332        & 0.30              \\\\  \n      b          & 0.15   & 011    & 3        & 2.74  & 0.411        & 0.45              \\\\\n      c          & 0.30   & 11     & 2        & 1.74  & 0.521        & 0.60              \\\\\n      d          & 0.16   & 00     & 2        & 2.65  & 0.423        & 0.32              \\\\\n      e          & 0.29   & 10     & 2        & 1.79  & 0.518        & 0.58              \\\\\n      \\hline\n      $\\sum$     & 1.00   & -      & -        & -     & 2.205        & 2.25              \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Code $C$ for source units $S$ with probabilities $P$}\n\\end{table}\n\nThe closer is the average length of the codeword to the actual entrophy, the better is code performing.\n\n%Prefix code - no code word is a prefix of the other code word.\n%Uniqualy decodable (biunique) - no coded string has more than one decoding.\n%Kraft's inequality - necessary and sufficient condition for the existence of a prefix code.\n\n\n\\begin{dt}{Prefix code.}\n  A prefix code is a code where no codeword is a prefix of a different codeword.\n\\end{dt}\n\n\\begin{dt}{Biunique (uniquely decodable) code.}\n  A biunique code is a code where no encoded message has more than one decoding.\n\\end{dt}\n\nCode $C = \\{010, 011, 11, 00, 10\\}$ above is uniquely decodable prefix code as no codeword is a prefix of another codeword. Uniquely decodable code which is not a prefix code can be easily created by doing a reverse of each codeword of code $C$. $C^R = \\{010, 110, 11, 00, 01\\}$ is not a prefix code\\sidenote{Code $C^R$ is actually a suffix code.} because $11$ is a prefix of $110$ and $01$ is a prefix of $010$.\n\nCode $C_N = \\{010, 011, 11, 00, 01\\}$ is not uniquely decodable code as sequence $010011$ can be interpreted in several way as $010.011$ or $01.00.11$.\n\nAll prefix codes are uniquely decodable codes. Some uniquely decodable codes are prefix codes.\\sidenote{In practice, mostly prefix codes are used.}\n\n\\section{Sample source units and their probabilities and frequencies}\n\nThese source units and their frequencies will be used in the following examples:\n\n\\noindent\nSource units:\n$$S_1 = \\{\\texttt{a}, \\texttt{b}, \\texttt{c}, \\texttt{d}, \\texttt{e}, \\texttt{f}, \\texttt{g}, \\texttt{h}, \\texttt{i}\\}.$$\nSource unit probabilities:\n$$P_1 = \\{1/35, 1/35, 2/35, 3/35, 3/35, 5/35, 5/35, 7/35, 8/35\\}.$$\nSource unit frequencies:\n$$F_1 = \\{1, 1, 2, 3, 3, 5, 5, 7, 8\\}.$$\n\n\\forestset{angled/.style={content/.expanded={\\noexpand\\textless\\forestov{content}\\noexpand\\textgreater}}}\n\\tikzset{el style/.style={midway, font=\\scriptsize, inner sep=+1pt, auto=right}}\n\\tikzset{every node/.style={draw, circle}}\n\\tikzset{every edge/.style={align=center, base=top}}\n\n\\section{Shannon-Fano Coding}\nShannon-Fano Coding creates codewords by sorting units by their number of frequencies (probabilities). In each step the number of frequencies is split to two closest parts and new nodes are created. The nodes are created from the root which contains the sum of all frequencies.\n\n\\begin{figure}\n\\begin{forest}\n  for tree={child anchor=north,inner sep=6pt},\n  where n children={1}{tier=word}{},\n  where n children={0}{rectangle,draw=none,minimum size=0.7cm}{\n    if={n==1}{% n == 1 means first child\n      edge label={node[el style, draw=none, swap, swap, near start]{0}}\n    }{\n      edge label={node[el style, swap, draw=none, near start]{1}}\n    }\n  }\n%\n[35 [ 15 [ 7 [ 4 [ 2 [ 1 [ a ] ]\n                     [ 1 [ b ] ] ]\n                 [ 2 [ c ] ] ]\n             [ 3 [ d ] ] ]\n         [ 8 [ 3 [ e ] ] \n             [ 5 [ f ] ] ] ]\n    [ 20 [12 [ 5 [ g ] ]\n             [ 7 [ h ] ] ]\n          [8 [ i ] ] ] ]\n\\end{forest}\n\\caption{Shannon-Fano tree for code $C_1$ for source units $S$ with probabilities $P$}\n\\end{figure}\n\nEdges to the left and to the right child nodes are labeled 0 and 1 respectively. The codewords can be red from root node to each leaf node.\n\nFrom the tree above, the codewords are:\n$$C_1 = \\{\\texttt{00000}, \\texttt{00001}, \\texttt{0001}, \\texttt{001}, \\texttt{010}, \\texttt{011}, \\texttt{100}, \\texttt{101}, \\texttt{11}\\}.$$\n\n\\begin{table}\n  \\begin{center}\n    \\begin{tabular}{|r|cccccc|}\n      \\hline\n      $x_i$ & $p_i$ & $c_i$ & $|c_i|$ & $H_i$ & $H_{avg}(S)$ & $L_{avg}(C)$      \\\\\n          &        &        &          & $-\\log_2 p_i$ & $p_i H_i$ & $p_i |c_i|$      \\\\\n      \\hline\n      a          & 0.029   & 00000    & 5        & 5.13  & 0.147        & 0.143              \\\\  \n      b          & 0.029   & 00001    & 5        & 5.13  & 0.147        & 0.143              \\\\\n      c          & 0.057   & 0001     & 4        & 4.13  & 0.236        & 0.229              \\\\\n      d          & 0.086   & 001      & 3        & 3.54  & 0.304        & 0.257              \\\\\n      e          & 0.086   & 010      & 3        & 3.54  & 0.304        & 0.257              \\\\\n      f          & 0.143   & 011      & 3        & 2.81  & 0.401        & 0.429              \\\\  \n      g          & 0.143   & 100      & 3        & 2.81  & 0.401        & 0.429              \\\\\n      h          & 0.200   & 101      & 3        & 2.32  & 0.464        & 0.600              \\\\\n      i          & 0.229   & 11       & 2        & 2.19  & 0.487        & 0.457              \\\\\n      \\hline\n      $\\sum$     & 1.00    & -        & -        & -     & 2.891        & 2.944              \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Code $C_1$ for source units $S_1$ with probabilities $P_1$}\n\\end{table}\n  \nSometimes parts can be created differently, leading to different codewords. In our case, in the first step the number of frequencies can be split either to $1, 1, 2, 3, 3, 5$ and $5, 7, 8$ or  $1, 1, 2, 3, 3, 5, 5$ and $7, 8$ leading to $15 + 20$ or $20 + 15$. It has to be decided beforehand how to resolve this situation (either going with lower on left or lower on right).\n\n\\begin{figure}\n\\begin{forest}\n  for tree={child anchor=north,inner sep=6pt},\n  where n children={1}{tier=word}{},\n  where n children={0}{rectangle,draw=none,minimum size=0.7cm}{\n    if={n==1}{% n == 1 means first child\n      edge label={node[el style, draw=none, swap, swap, near start]{0}}\n    }{\n      edge label={node[el style, swap, draw=none, near start]{1}}\n    }\n  }\n%\n[35 [ 20 [ 10 [ 4 [ 2 [ 1 [ a ] ]\n                      [ 1 [ b ] ] ]\n                  [ 2 [ c ] ] ]\n              [ 6 [ 3 [ d ] ]\n                  [ 3 [ e ] ] ] ]\n         [ 10 [5 [ f ] ]\n              [5 [ g ] ] ] ]\n    [ 15 [ 7 [ h ] ]\n         [ 8 [ i ] ] ] ]\n\\end{forest}\n\\caption{Huffman tree for code $C_2$ for source units $S$ with probabilities $P$}\n\\end{figure}\n\nFrom the tree above, the codewords are:\n$$C_2 = \\{\\texttt{00000}, \\texttt{00001}, \\texttt{0001}, \\texttt{0010}, \\texttt{0011}, \\texttt{010}, \\texttt{111}, \\texttt{10}, \\texttt{11}\\}.$$\n\n\\begin{table}\n  \\begin{center}\n    \\begin{tabular}{|r|cccccc|}\n      \\hline\n      $x_i$ & $p_i$ & $c_i$ & $|c_i|$ & $H_i$ & $H_{avg}(S)$ & $L_{avg}(C)$      \\\\\n          &        &        &          & $-\\log_2 p_i$ & $p_i H_i$ & $p_i |c_i|$      \\\\\n      \\hline\n      a          & 0.029   & 00000    & 5        & 5.13  & 0.147        & 0.143              \\\\  \n      b          & 0.029   & 00001    & 5        & 5.13  & 0.147        & 0.143              \\\\\n      c          & 0.057   & 0001     & 4        & 4.13  & 0.236        & 0.229              \\\\\n      d          & 0.086   & 0010     & 4        & 3.54  & 0.304        & 0.343              \\\\\n      e          & 0.086   & 0011     & 4        & 3.54  & 0.304        & 0.343              \\\\\n      f          & 0.143   & 010      & 3        & 2.81  & 0.401        & 0.429              \\\\  \n      g          & 0.143   & 111      & 3        & 2.81  & 0.401        & 0.429              \\\\\n      h          & 0.200   & 10       & 2        & 2.32  & 0.464        & 0.400              \\\\\n      i          & 0.229   & 11       & 2        & 2.19  & 0.487        & 0.457              \\\\\n      \\hline\n      $\\sum$     & 1.00    & -        & -        & -     & 2.891        & 2.916              \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Code $C_2$ for source units $S_1$ with probabilities $P_1$}\n\\end{table}\n\n\\section{Huffman Coding}\nHuffman Coding creates codewords by creating new node from the two smallest nodes (sorting is usually involved). In each step the two lowest numbers of frequencies are summed together and a new node is created containing this sum as a parent of these two nodes. The nodes are created from the leaves which are created from the frequencies of the source units.\n\n\\begin{figure}\n\\begin{forest}\n  for tree={child anchor=north,inner sep=6pt},\n  where n children={1}{tier=terminus}{},\n  where n children={0}{rectangle,draw=none,minimum size=0.7cm}{\n  }\n%i\n[35 [ 20,edge label={node[el style, draw=none]{1}},name=N16 [9,edge label={node[el style, draw=none]{0}},name=N9 [ 4,edge label={node[el style, draw=none]{0}} [ 2,edge label={node[el style, draw=none]{0}} [ 1,edge label={node[el style, draw=none]{0}} [ a ] ]\n                   [ 1,edge label={node[el style, draw=none, swap]{1}} [ b ] ] ]\n                 [ 2,edge label={node[el style, draw=none, swap]{1}} [ c ] ] ]\n                 [\\phantom{0},draw=none,no edge] ] \n    [11,edge label={node[el style, draw=none, swap]{1}} [ 6,edge label={node[el style, draw=none, near start]{1}} [ 3,edge label={node[el style, draw=none]{0}} [ d ] ]\n                 [ 3,edge label={node[el style, draw=none, swap, near end]{1}} [ e ] ] ]\n             [ 5,name=N5,no edge [ f ] ]\n             [ 5,edge label={node[el style, draw=none, swap, near start]{0}} [ g ] ] ] ]\n    [ 15,edge label={node[el style, draw=none, swap]{0}} \n         [ 7,edge label={node[el style, draw=none]{0}} [ h ] ]\n         [ 8,edge label={node[el style, draw=none, swap]{1}} [ i ] ] ] ]\n  \\draw (N9.south east) -- (N5.north) node[el style, swap, draw=none, near start]{1}; % or use (NP.north) \n\\end{forest}\n\\caption{Huffman tree for code $C_3$ for source units $S$ with probabilities $P$}\n\\end{figure}\n\nEdges to the lower and higher value child nodes are labeled 0 and 1 respectively. If a tie occures left and right child nodes are labeled 0 and 1 respectively.\n\nFrom the tree above, the codewords are:\n$$C_3 = \\{\\texttt{10000}, \\texttt{10001}, \\texttt{1001}, \\texttt{1110}, \\texttt{1111}, \\texttt{101}, \\texttt{110}, \\texttt{00}, \\texttt{01}\\}.$$\n\n\\begin{table}\n  \\begin{center}\n    \\begin{tabular}{|r|cccccc|}\n      \\hline\n      $x_i$ & $p_i$ & $c_i$ & $|c_i|$ & $H_i$ & $H_{avg}(S)$ & $L_{avg}(C)$      \\\\\n          &        &        &          & $-\\log_2 p_i$ & $p_i H_i$ & $p_i |c_i|$      \\\\\n      \\hline\n      a          & 0.029   & 10000    & 5        & 5.13  & 0.147        & 0.143              \\\\  \n      b          & 0.029   & 10001    & 5        & 5.13  & 0.147        & 0.143              \\\\\n      c          & 0.057   & 1001     & 4        & 4.13  & 0.236        & 0.229              \\\\\n      d          & 0.086   & 1110     & 4        & 3.54  & 0.304        & 0.343              \\\\\n      e          & 0.086   & 1111     & 4        & 3.54  & 0.304        & 0.343              \\\\\n      f          & 0.143   & 101      & 3        & 2.81  & 0.401        & 0.429              \\\\  \n      g          & 0.143   & 110      & 3        & 2.81  & 0.401        & 0.429              \\\\\n      h          & 0.200   & 00       & 2        & 2.32  & 0.464        & 0.400              \\\\\n      i          & 0.229   & 01       & 2        & 2.19  & 0.487        & 0.457              \\\\\n      \\hline\n      $\\sum$     & 1.00    & -        & -        & -     & 2.891        & 2.916              \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Code $C_3$ for source units $S_1$ with probabilities $P_1$}\n\\end{table}\n\n\\begin{dt}{Kraft-McMillan's Inequality.}\n    The Kraft-McMillan's Inequality defined as\\sidenote{The Kraft-McMillan's Inequality is derived from the Huffman tree, each leaf represents a codeword and the depth of the leaf correspond to the length of that codeword.}: $$\\sum_{\\ell \\in \\mathrm{leaves}} 2^{-\\mathrm{depth}(\\ell)} \\leq 1.$$\n    It is necessary and sufficient condition for the existence of a prefix code with given properties. If properties of the code given follows Kraft-McMillan's Inequality, it can be uniquely decodable code. If properties of the code given does not follow Kraft-McMillan's Inequality, it cannot be uniquely decodable code.\n\\end{dt}\n\nCode $C_N = \\{010, 011, 11, 00, 01\\}$ above gives you $1/8 + 1/8 + 1/4 + 1/4 + 1/4 = 1$ which means that code with such length of codeword could be uniquely decodable code, but it is not.\nCode $C_{N2} = \\{00, 01, 10, 11, 000\\}$ gives you $1/4 + 1/4 + 1/4 + 1/4 = 1.125$ hence it cannot be uniquely decodable code.\n\n\\begin{dt}{Redundant code.}\n  A prefix code for which holds $$\\sum_{\\ell \\in \\mathrm{leaves}} 2^{-\\mathrm{depth}(\\ell)} < 1.$$\n\\end{dt}\n\nCode $C_{R} = \\{00, 01, 10, 110\\}$ gives you $1/4 + 1/4 + 1/4 + 1/8 = 9.875$ hence the code is redundant (as it is also uniquely decodable).\n\n\\begin{dt}{Complete code.}\n  A prefix code for which holds $$\\sum_{\\ell \\in \\mathrm{leaves}} 2^{-\\mathrm{depth}(\\ell)} = 1.$$\n\\end{dt}\n\nCode $C = \\{010, 011, 11, 00, 10\\}$ above gives you $1/8 + 1/8 + 1/4 + 1/4 + 1/4 = 1$ hence the code is complete (as it is also uniquely decodable).\n\n\\begin{dt}{Optimal code.}\n    A code is optimal (for a given probability distribution) if no other code with a lower average length of a codeword $L_{avg}$ exists.\n\\end{dt}\n\nYou can compare average length of codewords in examples above for Shannon-Fano Codes $C_1$ and $C_2$ and Huffman Code $C_3$. Huffman Coding always produces optimal code ($C_3$). Shanno-Fano Coding is not guaranteed to produce optimal code ($C_1$), but can produce optimal code ($C_2$). \n\nOptimal code is always complete code.\n\n\\section{Homework}\n\n\\begin{itemize}\n  \\item Try to create Shannon-Fano Coding and Huffman Coding for different sets of frequencies.\n  \\item Try to calculate Kraft-McMillan's Inequality for the created sets of codewords (included those presented here).\n  \\item Compare average codeword length of the created sets of coders and see that Shannon-Fano does not always produce an optimal code.\n\\end{itemize}\n", "meta": {"hexsha": "8d17d6611d6c6c9bf094857db4f89fac766659cf", "size": 16319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kod/ch3.tex", "max_stars_repo_name": "exander77/handouts", "max_stars_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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": "kod/ch3.tex", "max_issues_repo_name": "exander77/handouts", "max_issues_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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": "kod/ch3.tex", "max_forks_repo_name": "exander77/handouts", "max_forks_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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.1373801917, "max_line_length": 412, "alphanum_fraction": 0.5466633985, "num_tokens": 5626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.859663754105328, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6861722438923702}}
{"text": "\\section{The Winding Number}\r\nWe want to generalize Cauchy's Theorem to non-simply-connected domains and generalize Cauchy Integral Formula to general shapes.\r\n\\begin{definition}\r\n    Let $\\gamma:[a,b]\\to\\mathbb C$ be a closed curve and fix $w\\in\\mathbb C\\setminus\\operatorname{Im}\\gamma$.\r\n    For each $t$, we can write $\\gamma(t)=w+r(t)e^{i\\theta(t)}$.\r\n    Where $r(t)=|\\gamma(t)-w|$.\r\n    If $\\gamma$ is piecewise $C^1$, so is $r$.\r\n    If we can find a continuous $\\theta(t)$ such that the equation holds for every $t$, then we define the winding number (or index) if $\\gamma$ about $w$ by\r\n    $$I(\\gamma;w)=\\frac{\\theta(b)-\\theta(a)}{2\\pi}$$\r\n\\end{definition}\r\nNote that the winding number must be an integer.\r\nIt is easy to show that it is well-defined (i.e. independent of the choice of continuous $\\theta$), and also hopefully we can show that it always exists.\r\n\\begin{lemma}\r\n    If $\\gamma$ is a piecewise $C^1$ curve and $w$ not in the image of $\\gamma$, then there exists continuous piecewise $C^1$ real function $\\theta$ such that\r\n    $$\\gamma(t)=w+r(t)e^{i\\theta(t)}$$\r\n    where $r(t)=|\\gamma(t)-w|$.\r\n\\end{lemma}\r\nIf $\\gamma$ is $C^1$ and the lemma holds, then $\\gamma^\\prime(t)=r^\\prime(t)e^{i\\theta(t)}+ir(t)\\theta^\\prime(r)e^{i\\theta(t)}$, which rearranges to give\r\n$$\\theta^\\prime(t)=\\operatorname{Im}\\left( \\frac{\\gamma^\\prime(t)}{\\gamma(t)-w} \\right)\\implies\\theta(t)=\\theta(a)+\\operatorname{Im}\\left( \\int_a^t \\frac{\\gamma^\\prime(x)}{\\gamma(x)-w}\\,\\mathrm dx\\right)$$\r\n\\begin{proof}\r\n    Let $h(t)=\\int_a^t\\frac{\\gamma^\\prime(s)}{\\gamma(s)-w}\\,\\mathrm ds$ where the singularities are skipped when integrate.\r\n    So $h$ is continuous and differentiable wherever $\\gamma$ is, where we will have $h^\\prime(t)=\\gamma^\\prime(t)/(\\gamma(t)-w)$.\r\n    Except the singularities, we have\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\left( (\\gamma(t)-w)e^{-h(t)} \\right)=\\gamma^\\prime(t)e^{-h(t)}-(\\gamma(t)-w)e^{-h(t)}h^\\prime(t)=0$$\r\n    So $(\\gamma(t)-w)e^{-h(t)}$ is piecewise constant, but it is also continuous, so it is constant.\r\n    $h(a)=0$, so if we let $\\alpha$ be the argument of $\\gamma(a)-w$, then\r\n    \\begin{align*}\r\n        \\gamma(t)-w&=(\\gamma(a)-w)e^{h(t)}\\\\\r\n        &=|\\gamma(a)-w|e^{i\\alpha}e^{\\operatorname{Re}h(t)}e^{i\\operatorname{Im}h(t)}\\\\\r\n        &=|\\gamma(a)-w|e^{\\operatorname{Re}h(t)}e^{i(\\alpha+\\operatorname{Im}h(t))}\r\n    \\end{align*}\r\n    Taking $\\theta(t)=\\alpha+\\operatorname{Im}h(t)$ finishes the proof.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If additionally $\\gamma(t)$ is a closed curve, then\r\n    $$I(\\gamma;w)=\\frac{1}{2\\pi i}\\int_\\gamma\\frac{\\mathrm dz}{z-w}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly from the above choice of $\\theta$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Actually the lemma holds for continuous $\\gamma$ (where we want $r,\\theta$ to be continuous).\r\n    The proof is exercise.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    If $\\gamma:[a,b]\\to D_R(\\alpha)$ be a piecewise $C^1$ closed curve and $w\\notin D_R(\\alpha)$, then $I(\\gamma,w)=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Write out definition and use Cauchy.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    The function $w\\mapsto I(\\gamma,w)$ is locally constant.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Immediate from continuity.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $U\\subset\\mathbb C$ is open.\\\\\r\n    1. A closed curve $\\gamma$ in $U$ is homologous to $0$ if $I(\\gamma,w)$ is $0$ for all $w\\notin U$.\\\\\r\n    2. $U$ is simply connected if every closed curve in $U$ is homologous to $0$.\r\n\\end{definition}\r\nSo a disk is simply connected but an annulus is not.\r\n\\begin{theorem}[Cauchy Integral Formula]\\label{general_cif}\r\n    Let $U$ be open and let $\\gamma:[a,b]\\to U$ be closed and homologous to $0$, then for any holomorphic $f:U\\to\\mathbb C$ we have\r\n    $$\\frac{1}{2\\pi i}\\oint_\\gamma\\frac{f(z)}{z-w}\\,\\mathrm dz=I(\\gamma,w)f(w)$$\r\n    for any $w\\in U$ that is not in the image of $\\gamma$.\r\n\\end{theorem}\r\nNote that we can assume $U$ is a bounded domain.\r\nIn particular, by integrating $F(z)=(z-w)f(z)$, we know from the theorem that\r\n$$\\int_\\gamma f(z)\\,\\mathrm dz=0$$\r\n\\begin{corollary}\r\n    If $U$ is simply connected, then for any closed curve $\\gamma$ in $U$ and any holomorphic function $f$ on $U$, we have\r\n    $$\\int_\\gamma f(z)\\,\\mathrm dz=0$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate from the preceding theorem.\r\n\\end{proof}\r\n\\begin{remark}\r\n    By the theorem, fix $\\gamma$, if\r\n    $$\\oint_\\gamma f(z)\\,\\mathrm dz=0$$\r\n    holds for functions in the form $f(z)=1/(z-w)$, then it holds for every holomorphic $f$.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Suppose $U\\subset\\mathbb C$ is open and $\\phi:U\\times [a,b]\\to\\mathbb C$ is continuous and each $z\\mapsto \\phi(z,s)$ is holomorphic, then\r\n    $$\\int_a^b\\phi(z,s)\\,\\mathrm ds$$\r\n    is holomorphic.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Morera's and Fubini's on closed intervals.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{general_cif}]\r\n    First define a function $g$ on $U\\times U\\to\\mathbb C$ by\r\n    $$g(z,w)=\\begin{cases}\r\n        (f(z)-f(w))/(z-w)\\text{, if $z\\neq w$}\\\\\r\n        f^\\prime(z)\\text{, if $z=w$}\r\n    \\end{cases}$$\r\n    which is continuous since $f$ is holomorphic.\r\n    Also define\r\n    $$h(w)=\\oint_\\gamma g(z,w)\\,\\mathrm dz,w\\in U;h_1(w)=\\oint_\\gamma\\frac{f(z)}{z-w}\\,\\mathrm dz,w\\in\\mathbb C\\setminus\\gamma([a,b])=U_1$$\r\n    Also, $h=h_1$ on $U\\cap U_1$ and $U\\cup U_1=\\mathbb C$ since $\\gamma$ is homologous to zero, so we can define\r\n    $$\\phi(w)=\\begin{cases}\r\n        h(w)\\text{, if $w\\in U$}\\\\\r\n        h_1(w)\\text{, if $w\\in U_1$}\r\n    \\end{cases}$$\r\n    Then $\\phi$ is entire by the preceding proposition, and since the behaviour of $\\phi$ as $|w|\\to\\infty$ shall be that of $h_1$, and as $I(\\gamma;w)=0$ for large enough $|w|$, we have\r\n    $$|\\phi(w)|\\le\\frac{\\operatorname{length}(\\gamma)\\sup_\\gamma|f|}{|w|-R}\\to 0$$\r\n    as $|w|\\to\\infty$.\r\n    By Theorem \\ref{holo_bdd_const}, $\\phi$ is constantly zero, in particular, $h$ is constantly zero on $U$.\r\n    This implies the result.\r\n\\end{proof}\r\nThe clever part of the proof that we used a global theorem (i.e. Liouville) to show a local result, which is pretty cool.\r\n\\begin{definition}\r\n    Let $\\gamma_0,\\gamma_1:[a,b]\\to\\mathbb C$ be two closed piecewise $C^1$ curves.\r\n    We say $\\gamma_0$ is homotopic to $\\gamma_1$ if there is a function $H:[a,b]\\times [0,1]\\to\\mathbb C$ with $H(0,t)=\\gamma_0(t),H(1,t)=\\gamma_1(t)$, and for each $s\\in [0,1]$, $H(t,s)$ is a closed piecewise $C^1$ curve, that is $\\forall s\\in[0,1],H(s,a)=H(s,b)$.\r\n\\end{definition}\r\n\\begin{theorem}\\label{homotopy}\r\n    For curves $\\gamma_0,\\gamma_1:[0,1]\\to U$ be homotopic and $w\\neq U$, we have $I(\\gamma_0,w)=I(\\gamma_1,w)$.\r\n\\end{theorem}\r\n\\begin{lemma}\r\n    If $\\gamma_0,\\gamma_1:[0,1]\\to\\mathbb C$ are piecewise $C^1$, $w\\in\\mathbb C$ and\r\n    $$\\forall t\\in [0,1],|\\gamma_0(t)-\\gamma_1(t)|<|w-\\gamma_1(t)|$$\r\n    then $I(\\gamma_0;w)=I(\\gamma_1;w)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Exercise.\r\n\\end{proof}\r\nWe will show the $C^1$ case, but the general case is also true by similar idea.\r\n\\begin{proof}[Proof of Theorem \\ref{homotopy}]\r\n    Consider the continuous deformation $H:[0,1]\\times [0,1]\\to\\mathbb C$.\r\n    Now $[0,1]^2$ is compact, so $H$ has compact (hence closed) image and is uniformly continuous.\r\n    So for $w\\notin U$, so there is $\\epsilon>0$, for any $(s,t)\\in [0,1]^2$, $|H(s,t)-w|>2\\epsilon$.\r\n    Also there is $n\\in\\mathbb N$ such that\r\n    $$|s-s'|+|t-t'|\\le\\frac{1}{n}\\implies |H(s,t)-H(s',t')|<\\epsilon$$\r\n    Denote $H(s,t)$ by $\\gamma_s(t)$, this would mean that for $k=1,2,\\ldots,n$, we have $|\\gamma_{(k-1)/n}(t)-\\gamma_{k/n}(t)|<\\epsilon$, but we also have $|w-\\gamma_{k/n}(t)|>2\\epsilon$, so\r\n    $$|\\gamma_{(k-1)/n}(t)-\\gamma_{k/n}(t)|<\\epsilon<2\\epsilon<|w-\\gamma_{k/n}(t)|$$\r\n    So by the preceding lemma $I(\\gamma_0;w)=I(\\gamma_{1/n};w)=\\cdots=I(\\gamma_1;w)$.\r\n\\end{proof}\r\nSo a star-shaped domain is simply connected.\r\nGiven $\\gamma:[0,1]\\to U$ and let $p$ be the centre of $U$, then we can shrink $\\gamma$ to $p$ in the obvious way.\r\n\\begin{remark}\r\n    If a curve is null-homotopic, then by the theorem it is homologous to $0$, but the converse might not be true.\r\n    The usual algebraic topological definition of simple-connectedness is that every closed curve is null-homotopic.\r\n    So $U$ is simply-connected in the algebraic topological way implies that it is simply connected in the complex analysis way in terms of winding number.\r\n    This then implies that Cauchy's Theorem (in simply connected domains) holds.\\\\\r\n    The reverse implication holds but complex simply-connectedness implying topological simply-connectedness part is not trivial.\r\n\\end{remark}", "meta": {"hexsha": "641d09fce7888be2fdb49440fcf909c1b4709f36", "size": 8686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/winding.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": "3/winding.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": "3/winding.tex", "max_forks_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_forks_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.4931506849, "max_line_length": 266, "alphanum_fraction": 0.6442551232, "num_tokens": 2949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867729389246, "lm_q2_score": 0.859663754105328, "lm_q1q2_score": 0.686172237701893}}
{"text": "\\section{Lazy Code Motion Problem}\n\\begin{flushright}\n\\textit{Notes by Akshin Singh}\n\\end{flushright}\n\nAs discussed in the previous module, the PRE problem has two components\n\\begin{enumerate}\n\\item All redundant computations of expressions that can be eliminated without duplication are eliminated.\n\\item The optimized program does not perform any extra computations that were not in the original program \\textit{execution}.\n\\end{enumerate}\n\nLazy Code Motion (or LCM for short) adds another component to it.\n\n\\begin{enumerate}\n  \\setcounter{enumi}{2}\n\\item Expressions are computed at the late as possible (this is where the name \\textbf{LAZY} comes from).\n\\end{enumerate}\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale = 0.5]{images/mod_106_fig1.png}\n\\caption{Lazy Code Motion example}\n\\label {fig:mod_106_01}\n\\end{figure}\n\nLet us understand this with the help of an example. In Figure \\ref{fig:mod_106_01}(a), we see that \\textbf{m+n} is redundant on the red path,i.e., the loop's back edge. We will formally define what a back edge means in a later module. For now, the back edge means the edge that takes the execution from the loop's body back to its body.\n\nPRE allows \\ref{fig:mod_106_01}(b) but LCM does not. \\textbf{WHY?} For PRE, components 1 and 2 are satisified in \\ref{fig:mod_106_01}(b). For LCM component 3 is not satisfied. We can see this from the fact that the loop consisting of b1 needs to hold the value of \\textbf{m+n} even though it does not need it. LCM component 3 is satisfied in \\ref{fig:mod_106_01}(c).\n\nNotice how \\ref{fig:mod_106_01}(c) is a solution for both LCM and PRE whereas \\ref{fig:mod_106_01}(b) is a solution for PRE but not LCM. This example suggests that $PRE \\subset LCM$. In other words, LCM subsumes PRE. This is expected since PRE shares both its rules with LCM, but LCM has extra conditions as well.\n\n\\subsection{Full vs Partial Redundancy}\n\nAs eluded to in the last module, an expression is fully redundant at a program point if it is redundant on all paths to that program point. If an expressions is redundant on some but not all paths, then that expression is partially redundant.\n\nAnother way to frame what PRE does is the following: \\textit{Can we place additional copies of an expression e which is partially redundant at program point p, such that it becomes fully redundant at p?} A fully redundant expression can be easily eliminated using common subexpression elimination.\n\n\n\\textbf{For more examples see the lecture module 106 on YouTube}.\n\n\n\n", "meta": {"hexsha": "6dc4d3f19b1c7b303b684893a2e1e3a71ea5b7d5", "size": 2508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module106.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": "module106.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": "module106.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": 57.0, "max_line_length": 366, "alphanum_fraction": 0.7771132376, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289836, "lm_q2_score": 0.90192067257508, "lm_q1q2_score": 0.6860465580447418}}
{"text": "\\section{Complex eigenvalues}\n\nIn some applications, a matrix may have eigenvalues\n\\index{complex eigenvalues} which are complex numbers. For example, this often occurs in\ndifferential equations. These questions are approached in the same way as above.\n\nConsider the following example.\n\n\\begin{example}{A real matrix with complex eigenvalues}{real-matrix-complex-eigenvalues}\nLet\n\\begin{equation*}\nA=\\begin{mymatrix}{rrr}\n1 & 0 &  0 \\\\\n0 & 2 & -1 \\\\\n0 & 1 &  2\n\\end{mymatrix}\n\\end{equation*}\nFind the eigenvalues and eigenvectors of $A$.\n\\end{example}\n\n\\begin{solution}\nWe will first find the eigenvalues as usual by solving the following equation.\n\n\\begin{equation*}\n\\det \\paren{\n\\eigenvar \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n- \\begin{mymatrix}{rrr}\n1 & 0 &  0 \\\\\n0 & 2 & -1 \\\\\n0 & 1 &  2\n\\end{mymatrix}} =0\n\\end{equation*}\nThis reduces to $ (\\eigenvar -1) (\n\\eigenvar^{2}-4 \\eigenvar +5) =0$. The solutions are $\\lambda_1\n=1,\\lambda_2 = 2+i$ and $\\lambda_3 =2-i$.\n\nThere is nothing new about finding the eigenvectors for $\\lambda_1 =1$ so\nthis is left as an exercise.\n\nConsider now the eigenvalue $\\lambda_2 =2+i$. As usual, we solve the equation $(\\lambda I -A) X = 0$ as given by\n\\begin{equation*}\n(\n(2+i) \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} -\n\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 2 & -1 \\\\\n0 & 1 & 2\n\\end{mymatrix}\n)\nX\n =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\nIn other words, we need to solve the system represented by the augmented matrix\n\\begin{equation*}\n\\begin{mymatrix}{crr|r}\n1+i &  0 & 0 & 0 \\\\\n0   &  i & 1 & 0 \\\\\n0   & -1 & i & 0\n\\end{mymatrix}\n\\end{equation*}\n\nWe now use our row operations to solve the system.\nDivide the first row by $(1+i) $ and then take\n$-i$ times the second row and add to the third row. This yields\n\\begin{equation*}\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 0 & 0 \\\\\n0 & i & 1 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nNow multiply the second row by $-i$ to obtain the {\\rref}, given by\n\\begin{equation*}\n\\begin{mymatrix}{rrr|r}\n1 & 0 &  0 & 0 \\\\\n0 & 1 & -i & 0 \\\\\n0 & 0 &  0 & 0\n\\end{mymatrix}\n\\end{equation*}\nTherefore, the eigenvectors are of the form\n\\begin{equation*}\nt\\begin{mymatrix}{r}\n0 \\\\\ni \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nand the basic eigenvector is given by\n\\begin{equation*}\nX_2 =\n\\begin{mymatrix}{r}\n0 \\\\\ni \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\nAs an exercise, verify that the eigenvectors for $\\lambda_3 =2-i$ are of the form\n\\begin{equation*}\nt\\begin{mymatrix}{r}\n 0 \\\\\n-i \\\\\n 1\n\\end{mymatrix}\n\\end{equation*}\nHence, the basic eigenvector is given by\n\\begin{equation*}\nX_3 = \\begin{mymatrix}{r}\n 0 \\\\\n-i \\\\\n 1\n\\end{mymatrix}\n\\end{equation*}\n\nAs usual, be sure to check your answers! To verify, we check that\n$AX_3 = (2 - i) X_3$ as follows.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 &  0 \\\\\n0 & 2 & -1 \\\\\n0 & 1 &  2\n\\end{mymatrix} \\begin{mymatrix}{r}\n0 \\\\\n-i \\\\\n1\n\\end{mymatrix} = \\begin{mymatrix}{c}\n0 \\\\\n-1-2i \\\\\n2-i\n\\end{mymatrix} =(2-i) \\begin{mymatrix}{r}\n0 \\\\\n-i \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\nTherefore, we know that this eigenvector and eigenvalue are correct.\n\\end{solution}\n\nNotice that in Example~\\ref{exa:real-matrix-complex-eigenvalues}, two of the eigenvalues were given by\n$\\lambda_2 = 2 + i$ and $\\lambda_3 = 2-i$. You may recall that these two complex numbers are \\textbf{conjugates}.\nIt turns out that whenever a matrix containing real entries has a complex eigenvalue $\\lambda$, it also has an eigenvalue\nequal to $\\conjugate{\\lambda}$, the conjugate of $\\lambda$.\n", "meta": {"hexsha": "5852c31ab3bf5d4ffcb9cf419bd0a5740ff83cce", "size": 3554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryDiagonalizationComplex.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/spectraltheoryDiagonalizationComplex.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/spectraltheoryDiagonalizationComplex.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 22.7820512821, "max_line_length": 121, "alphanum_fraction": 0.667698368, "num_tokens": 1327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.9019206692796966, "lm_q1q2_score": 0.6860465457507379}}
{"text": "\\section{Recovery of Primitive Variables}\nIn order to recover the primitive from the conserved variables we need to solve the nonlinear equation:\n\\begin{equation}\n    f\\left(p\\right)=p-\\ol{p}\\left(p\\right)=0,\n\\end{equation}\nwhere $\\ol{p}\\left(p\\right)$ is the pressure as obtained via the ideal gas equation of state with an initial guess, $p$:\n\\begin{equation}\n    \\ol{p}=\\left(\\Gamma-1\\right)\\rho\\,\\epsilon,\n\\end{equation}\nwhere\n\\begin{equation}\n    \\rho=\\rho\\left(\\bU,p\\right),\\hspace{1em}\\epsilon=\\epsilon\\left(\\bU,p\\right).\n\\end{equation}\n\nIn order to solve this equation we make use of the bisection method, and therefore need bounds on our initial guess for the pressure.\n\n\\subsection{Upper and Lower Bounds for Pressure}\nWe obtain a lower bound for the pressure with:\n\\begin{equation}\n\\tau=D\\left(h\\,W-1\\right)-p\\implies p=-\\left(\\tau+D\\right)+D\\,h\\,W\\geq-\\left(\\tau+D\\right)+D\\,h\\,W\\,\\sqrt{v^{i}\\,v_{i}}=-\\left(\\tau+D\\right)+\\sqrt{S^{i}\\,S_{i}}.\n\\end{equation}\nSo, since the pressure must be non-negative, we have:\n\\begin{equation}\np\\geq\\text{MAX}\\left[-\\left(\\tau+D\\right)+\\sqrt{S^{i}\\,S_{i}},\\text{SqrtTiny}\\right].\n\\end{equation}\n\nFor an upper bound, we first note that:\n\\begin{equation}\nh=1+\\f{e+p}{\\rho}=1+\\f{\\Gamma}{\\Gamma-1}\\f{p}{\\rho}=1+\\f{\\Gamma}{\\Gamma-1}\\,\\f{p\\,W}{D},\n\\end{equation}\nso,\n%\\begin{equation}\n%    \\tau=D\\left(W+\\f{\\Gamma}{\\Gamma-1}\\f{p\\,W^{2}}{D}-1\\right)-p=D\\left(W-1\\right)+p\\left(\\f{\\Gamma}{\\Gamma-1}W^{2}-1\\right).\n%\\end{equation}\n%So,\n%\\begin{equation}\n%    p=\\f{\\tau-D\\left(W-1\\right)}{\\f{\\Gamma}{\\Gamma-1}W^{2}-1}.\n%\\end{equation}\n%We also have:\n%\\begin{equation}\n%    W=\\left(1-v^{i}\\,v_{i}\\right)^{-1/2}=\\left(1-\\f{S^{i}\\,S_{i}}{\\left(\\tau+D+p\\right)^{2}}\\right)^{-1/2}.\n%\\end{equation}\n%Treating $p$ as an independent variable \\sd{is this valid?}, we have:\n%\\begin{equation}\n%    W\\Big|_{p\\rightarrow\\infty}=1,\n%\\end{equation}\n%which gives us an upper limit:\n%\\begin{equation}\n%    p\\leq\\f{\\Gamma-1}{\\Gamma}\\,\\tau.\n%\\end{equation}\n%Just to be safe, in the code we multiply this by two, so that:\n%\\begin{equation}\n%    p\\leq2\\,\\f{\\Gamma-1}{\\Gamma}\\,\\tau.\n%\\end{equation}\n\\begin{equation}\n    \\tau=D\\left(W+\\f{\\Gamma}{\\Gamma-1}\\f{p\\,W^{2}}{D}-1\\right)-p=D\\left(W-1\\right)+p\\left(\\f{\\Gamma}{\\Gamma-1}W^{2}-1\\right)>p\\left(\\f{\\Gamma}{\\Gamma-1}-1\\right)=\\f{p}{\\Gamma-1}.\n\\end{equation}\nSo,\n\\begin{equation}\n    p<\\left(\\Gamma-1\\right)\\tau.\n\\end{equation}\nTypically, $\\Gamma-1<3$. So, we end up with:\n\\begin{equation}\n    p<3\\,\\tau.\n\\end{equation}", "meta": {"hexsha": "8c131925525350bd33e1ed0824c7a630d67feeda", "size": 2485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/Euler/SamsTexFiles/RecoveryOfPrimitiveVariables.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/RecoveryOfPrimitiveVariables.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/RecoveryOfPrimitiveVariables.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": 38.2307692308, "max_line_length": 178, "alphanum_fraction": 0.6563380282, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6860465414779675}}
{"text": "\n\\subsection{A* search}\n\nIf the heuristic is admissible, then a* is optimal. Intuitively because the the heuristic steers away from any suboptimal solutions.\n\nAdmissible? For all nodes n , h(n)<=h*(n). where h* is true cost\n\n\\(f(n)=g(n)+h(n)\\)\n\n\\(g(n)\\) is the cost to reach \\(n\\) from the current position.\n\nInformed: Yes\n\nTime: Exponential\n\nSpace: Big, all nodes kept in memory\n\nComplete: Yes\n\nOptimal: Yes, if the heuristic is admissible\n\n", "meta": {"hexsha": "6ce6fda8ea482e79002e87bcf5fcfacd3db19dfa", "size": 442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/treeHeuristic/01-02-A.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-02-A.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-02-A.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.0909090909, "max_line_length": 132, "alphanum_fraction": 0.7149321267, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6859954240451763}}
{"text": "\\subsubsection{Isobaric Processes}\nIsobaric processes are compression/expansion processes in which the pressure of the gas does not change ($\\Delta P = 0$). For example, consider a box of gas where the top face is a piston. If I heat up the gas with a candle, then the piston gets pushed up by the warming, expanding gas, while the pressure of the gas stays constant.  \\\\\n\nFirst, let us determine the work done on the gas in this process:\n\\[W = -\\int_{V_1}^{V_2} P(V)dV \\]\nAs $P$ is a constant, we can just take it outside the integral, and this becomes a very straightforward integration:\n\\[W = -P\\int_{V_1}^{V_2} dV = -P \\cdot \\left. V \\right|_{V_1}^{V_2} = -P(V_2-V_1) = -P\\Delta V\\]\n\\begin{equation}\n    W = -P\\Delta V\n\\end{equation}\nWhich is exactly as we would have expected. \\\\\n\nNow that we know what the work done in an isobaric process is, we can consider the heat flow. We return to the first law of thermodynamics:\n\\[ \\Delta E = W + Q \\]\nWe recall that the following formula (from section 1) always holds true for change in energy:\n\\[ \\Delta E = nc_v\\Delta T = n \\frac{\\chi}{2}R\\Delta T \\]\nWe substitute the formulas for work and change in energy we have obtained:\n\\[ n \\frac{\\chi}{2}R\\Delta T  = -P\\Delta V + Q \\]\nNow, we use the ideal gas law to recognize that:\n\\[ P\\Delta V = nR \\Delta T \\]\nMaking this subtitution, we have:\n\\[ n \\frac{\\chi}{2}R\\Delta T = -nR \\Delta T + Q \\]\nCombining the like terms, we have:\n\\[ Q = nR\\left(\\frac{\\chi}{2}+1\\right)\\Delta T \\]\nNow, let us define the heat capacity at constant pressure:\n\\begin{equation}\nc_p = \\left( \\frac{\\chi}{2}+1 \\right)R = c_v+R\n\\end{equation}\nWhich gives us the formula for the heat in an isobaric process:\n\\begin{equation}\n    Q = nc_p \\Delta T\n\\end{equation}\nYou may very well recognize this formula from high school physics or chemistry! Something of interest to point out here; we notive that $c_p>c_v$, or that the heat capacity at constant pressure is higher than the heat capacity at constant volume. This tells us that when something is allowed to expand as it is heated (retaining constant pressure), it requires more energy to increase its temperature than if it is kept at a fixed volume.\n\\\\\nFinally, let's consider what an isobaric process looks like on a PV diagram. As you might suspect, since we fix $P$ and let $V$ vary throughout the whole process, we yet again get a straight line, except this time a horizontal one. Pictured below is an isothermal expansion:\n\n\\begin{center}\n    \\begin{tikzpicture}\n \\draw[stealth-stealth] (0,5) node[below left]{$P$} |- (5,0) node[below left]{$V$};\n\\draw[thick,->] (1,2.5) -- (2.5,2.5);\n\\draw[thick] (2.5,2.5) -- (4,2.5);\n\\draw[dashed] (0,2.5) -- (1,2.5);\n\\draw[dashed] (1,0) -- (1,2.5);\n\\draw[dashed] (4,0) -- (4,2.5);\n\\filldraw (1,2.5) circle (2pt);\n\\filldraw (4,2.5) circle (2pt);\n\\node[below] at (4,0) {$V_2$};\n\\node[below] at (1,0) {$V_1$};\n\\node[left] at (0,2.5) {$P_1$};\n\\node[above] at (1,2.5) {$T_1$};\n\\node[above] at (4,2.5) {$T_2$};\n\\end{tikzpicture}\n\\end{center}\nAgain, for visual confirmation of our result for work during an isobaric process, we can see that the (negative) area under the curve is $-P_1\\Delta V$, by inspection. ", "meta": {"hexsha": "c78dc12f811fda378cb5eb7ff886d0d1d5257f4e", "size": 3166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OneLaw/isobaric.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/isobaric.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/isobaric.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": 58.6296296296, "max_line_length": 438, "alphanum_fraction": 0.6986734049, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6859747383413968}}
{"text": "\\section*{Exercise 4.1}\r\n\\enum{\r\n\\item\r\nSince\r\n\\[\r\n    \\textbf{AX}=(X_1,X_2)=\\left(\\begin{aligned}\r\n        &a_{11}X_1+a_{12}X_2\\\\\r\n        &a_{21}X_1+a_{22}X_2\r\n    \\end{aligned}\\right).\r\n\\]\r\nthen\r\n\\begin{align*}\r\n    E[\\textbf{AX}]&=E\\bigg[\\left(\\begin{aligned}\r\n        &a_{11}X_1+a_{12}X_2\\\\\r\n        &a_{21}X_1+a_{22}X_2\r\n    \\end{aligned}\\right)\\bigg]\r\n    =\\left(\\begin{aligned}\r\n        &E[a_{11}X_1+a_{12}X_2]\\\\\r\n        &E[a_{21}X_1+a_{22}X_2]\r\n    \\end{aligned}\\right)\\\\\r\n    &=\\left(\\begin{aligned}\r\n        &a_{11}E[X_1]+a_{12}E[X_2]\\\\\r\n        &a_{21}E[X_1]+a_{22}E[X_2]\r\n    \\end{aligned}\\right)\r\n    =\\textbf{A}\\left(\\begin{aligned}\r\n        &E[X_1]\\\\\r\n        &E[X_2]\r\n    \\end{aligned}\\right)\r\n    =\\textbf{A}E[\\textbf{X}].\r\n\\end{align*}\r\n\r\n\\item\r\n\\begin{align*}    \r\n    \\var(\\textbf{AX})=\\left(\\begin{aligned}\r\n        &\\var(a_{11}X_1+a_{12}X_2) & \\cov(a_{11}X_1+a_{12}X_2,a_{21}X_1+a_{22}X_2)\\\\\r\n        &\\cov(a_{21}X_1+a_{22}X_2,a_{11}X_1+a_{12}X_2) & \\var(a_{21}X_1+a_{22}X_2)\r\n    \\end{aligned}\\right)\r\n\\end{align*}\r\nWe denote that\r\n\\begin{align*}\r\n    &t=\\cov(X_1,X_2),\\\\\r\n    &\\cov(a_{21}X_1+a_{22}X_2,a_{11}X_1+a_{12}X_2)\\\\\r\n    =&E[(a_{21}X_1+a_{22}X_2)(a_{11}X_1+a_{12}X_2)]-E[a_{21}X_1+a_{22}X_2]E[a_{11}X_1+a_{12}X_2]\\\\\r\n    =&(a_{21}a_{12}+a_{22}a_{11})(E[X_1X_2]-E[X_1]E[X_2])+a_{11}a_{21}(E[X_1^2]-E[X_1]^2)+a_{22}a_{12}(E[X_2^2]-E[X_2]^2)\\\\\r\n    =&(a_{21}a_{12}+a_{22}a_{11})\\cov(X_1,X_2)+a_{11}a_{21}\\var(X_1)+a_{22}a_{12}\\var(X_2)\\\\\r\n    =&(a_{21}a_{12}+a_{22}a_{11})t+a_{11}a_{21}\\var(X_1)+a_{22}a_{12}\\var(X_2),\r\n\\end{align*}\r\nthen\r\n\\begin{align*}\r\n    \\var(\\textbf{AX})\r\n    &=\\left(\\begin{aligned}\r\n        &a_{11}^2\\var(X_1)+a_{12}^2\\var(X_2)+2a_{11}a_{12}t & \\cov(a_{21}X_1+a_{22}X_2,a_{11}X_1+a_{12}X_2)\\\\\r\n        &\\cov(a_{21}X_1+a_{22}X_2,a_{11}X_1+a_{12}X_2) & a_{21}^2\\var(X_1)+a_{22}^2\\var(X_2)+2a_{21}a_{22}t\r\n    \\end{aligned}\\right).\r\n\\end{align*}\r\n\r\nAlso,\r\n\\begin{align*}\r\n    \\textbf{A}\\var(\\textbf{X})&=\\left(\\begin{aligned}\r\n        &a_{11}\\var(X_1)+a_{12}\\cov(X_1,X_2) & a_{11}\\cov(X_1,X_2)+a_{12}\\var(X_2)\\\\\r\n        &a_{21}\\var(X_1)+a_{22}\\cov(X_1,X_2) & a_{21}\\cov(X_1,X_2)+a_{22}\\var(X_2)\\\\\r\n    \\end{aligned}\\right).\\\\\r\n    \\textbf{A}^T&=\\left(\\begin{aligned}\r\n        &a_{11} & a_{21}\\\\\r\n        &a_{12} & a_{22}\r\n    \\end{aligned}\\right).\r\n\\end{align*}\r\nHence, we know\r\n\\[\r\n    \\var(\\textbf{AX})=\\textbf{A}(\\var(\\textbf{X}))\\textbf{A}^T.\r\n\\]\r\n\r\n\\item\r\nSince $X_1$ and $X_2$ follow independent normal distributions, then $\\varrho_{X}=0$.\r\n\\spl{\r\n    f_X(x_1,x_2)=\\frac{1}{2\\pi\\sigma_1\\sigma_2}e^{-\\frac{1}{2}\\big[\\frac{(x_1-\\mu_1)^2}{\\sigma_1^2}+\\frac{(x_2-\\mu_2)^2}{\\sigma_2^2}\\big]}.\r\n}\r\n\\begin{align*}\r\n    \\Sigma_X=\\left(\\begin{aligned}\r\n        &\\sigma_1^2 & 0\\\\\r\n        &0 & \\sigma_2^2\r\n    \\end{aligned}\\right), \\quad\r\n    \\Sigma_X^{-1}=\\frac{1}{\\sigma_1^2\\sigma_2^2}\\left(\\begin{aligned}\r\n        &\\sigma_2^2 & 0\\\\\r\n        &0 & \\sigma_1^2\r\n    \\end{aligned}\\right)=\\left(\\begin{aligned}\r\n        &\\sigma_1^{-2} & 0\\\\\r\n        &0 & \\sigma_2^{-2}\r\n    \\end{aligned}\\right),\r\n\\end{align*}\r\n\r\nHence,\r\n\\begin{align*}\r\n    &\\sqrt{\\det\\Sigma_X}=\\sqrt{\\sigma_1^2\\sigma_2^2}=\\sigma_1\\sigma_2.\\\\\r\n    &\\Sigma_X^{-1}(x-\\mu_X)=\\left(\\begin{aligned}\r\n        &\\sigma_1^{-2} & 0\\\\\r\n        &0 & \\sigma_2^{-2}\r\n    \\end{aligned}\\right)\r\n    \\left(\\begin{aligned}\r\n        &x_1-\\mu_1\\\\\r\n        &x_2-\\mu_2\r\n    \\end{aligned}\\right)=\r\n    \\left(\\begin{aligned}\r\n        &\\frac{x_1-\\mu_1}{\\sigma_1^2}\\\\\r\n        &\\frac{x_2-\\mu_2}{\\sigma_2^2}    \r\n    \\end{aligned}\\right).\r\n\\end{align*}\r\nThen,\r\n\\begin{align*}\r\n    \\bigg<x-\\mu_X,\\Sigma_X^{-1}(x-\\mu_X)\\bigg>=\\frac{(x_1-\\mu_1)^2}{\\sigma_1^2}+\\frac{(x_2-\\mu_2)^2}{\\sigma_2^2}.\r\n\\end{align*}\r\n\r\nThus,\r\n\\spl{\r\n    f_X(x)=f_X(x_1,x_2)=\\frac{1}{2\\pi\\sqrt{\\det\\Sigma_X}}e^{-\\frac{1}{2}\\big<x-\\mu_X,\\Sigma_X^{-1}(x-\\mu_X)\\big>}.\r\n}\r\n\r\n\\item\r\nSince \\textbf{A} is invertible, then $X=A^{-1}Y$.\r\n\\begin{align*}\r\n    f_Y(y)=f_X(x)|\\det(A^{-1})|=f_X(A^{-1}y)|\\det(A^{-1})|.\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n    \\det\\Sigma_{Y}&=\\det\\left(\\begin{aligned}\r\n        &\\var(Y_1) & \\cov(Y_1,Y_2)\\\\\r\n        &\\cov(Y_2,Y_1) & \\var(Y_2)\r\n    \\end{aligned}\\right)=\\sigma_{Y_1}^2\\sigma_{Y_2}^2-\\cov(Y_1,Y_2)^2\\\\\r\n    &=(a_{11}^2\\sigma_1^2+a_{12}^2\\sigma_2^2)(a_{21}^2\\sigma_1^2+a_{22}^2\\sigma_2^2)-(a_{11}a_{21}\\sigma_1^2+a_{22}a_{12}\\sigma_2^2)^2\\\\\r\n    &=(a_{11}a_{22}-a_{12}a_{21})^2\\sigma_1^2\\sigma_2^2\\\\\r\n    &=\\det(A)^2\\det(\\Sigma_X).\r\n\\end{align*}\r\n\r\nHence,\r\n\\begin{align*}\r\n    &\\sqrt{|\\det\\Sigma_Y|}=\\sqrt{|\\det(A)^2\\det(\\Sigma_X)|},\\\\\r\n    &\\sqrt{\\det\\Sigma_X}=\\frac{1}{|\\det(A)|}\\sqrt{|\\det\\Sigma_Y|}.\\\\\r\n    &\\Sigma_Y^{-1}(y-\\mu_Y)=\\var(Y)^{-1}\r\n    \\left(\\begin{aligned}\r\n        &y_1-\\mu_{Y_1}\\\\\r\n        &y_2-\\mu_{Y_2}\r\n    \\end{aligned}\\right)\\\\\r\n    =&(A^{T})^{-1}\\Sigma_X^{-1}A^{-1}\\left(\\begin{aligned}\r\n        &y_1-\\mu_{Y_1}\\\\\r\n        &y_2-\\mu_{Y_2}\r\n    \\end{aligned}\\right)\r\n\\end{align*}\r\n\r\nSince\r\n\\begin{align*}\r\n    \\left(\\begin{aligned}\r\n        &y_1-\\mu_{Y_1}\\\\\r\n        &y_2-\\mu_{Y_2}\r\n    \\end{aligned}\\right)=\r\n    \\left(\\begin{aligned}\r\n        &a_{11}X_1+a_{12}X_2-(a_{11}\\mu_1+a_{12}\\mu_2)\\\\\r\n        &a_{21}X_1+a_{22}X_2-(a_{21}\\mu_1+a_{22}\\mu_2)\r\n    \\end{aligned}\\right)=\r\n    A\\left(\\begin{aligned}\r\n        &x_1-\\mu_{_1}\\\\\r\n        &x_2-\\mu_{_2}\r\n    \\end{aligned}\\right),\r\n\\end{align*}\r\nthen\r\n\\begin{align*}\r\n    \\Sigma_Y^{-1}(y-\\mu_Y)=(A^{T})^{-1}\\Sigma_X^{-1}(x-\\mu_X).\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n    \\big<y-\\mu_Y,\\Sigma_Y^{-1}(y-\\mu_Y)\\big>&=\\big<A(x-\\mu_X),(A^T)^{-1}\\Sigma_X^{-1}(x-\\mu_X)\\big>\\\\\r\n    &=(x-\\mu_X)^TA^T(A^T)^{-1}\\Sigma_X^{-1}(x-\\mu_X)\\\\\r\n    &=\\big<x-\\mu_X,\\Sigma_X^{-1}(x-\\mu_X)\\big>.\r\n\\end{align*}\r\n\r\nFinally we plug in the terms,\r\n\\spl{\r\n    f_Y(y)&=f_X(A^{-1}y)\\det(A^{-1})\\\\\r\n    &=\\frac{|\\det(A)|}{2\\pi\\sqrt{|\\det\\Sigma_Y|}}e^{-\\frac{1}{2}\\big<y-\\mu_Y,\\Sigma_Y^{-1}(y-\\mu_Y)\\big>}|\\det(A^{-1})|\\\\\r\n    &=\\frac{1}{2\\pi\\sqrt{|\\det\\Sigma_Y|}}e^{-\\frac{1}{2}\\big<y-\\mu_Y,\\Sigma_Y^{-1}(y-\\mu_Y)\\big>}.\r\n}\r\n\r\n\\item\r\nWe denote that $\\varrho=\\cov(Y_1,Y_2)/(\\sigma_{Y_1}\\sigma_{Y_2})$, then\r\n\\begin{align*}\r\n    1-\\varrho^2&=1-\\frac{\\cov^2(Y_1,Y_2)}{\\sigma_{Y_1}^2\\sigma_{Y_2}^2}\\\\\r\n    &=\\frac{\\sigma_{Y_1}^2\\sigma_{Y_2}^2-\\cov^2(Y_1,Y_2)}{\\sigma_{Y_1}^2\\sigma_{Y_2}^2}\\\\\r\n    &=\\frac{\\det\\Sigma_Y}{\\sigma_{Y_1}^2\\sigma_{Y_2}^2}\r\n\\end{align*}\r\n\r\nHence,\r\n\\begin{align*}\r\n    \\sqrt{|\\det\\Sigma_Y|}=\\sigma_{Y_1}\\sigma_{Y_2}\\sqrt{1-\\varrho^2}.\r\n\\end{align*}\r\n\r\nAlso,\r\n\\begin{align*}\r\n    &\\big<y-\\mu_Y,\\Sigma_Y^{-1}(y-\\mu_Y)\\big>\\\\\r\n    =&\\frac{1}{1-\\varrho^2}\\frac{1}{\\sigma_{Y_1}^2\\sigma_{Y_2}^2}\\big<y-\\mu_Y,\\Sigma_Y^*(y-\\mu_Y)\\big>\\\\\r\n    =&\\frac{1}{1-\\varrho^2}\\frac{1}{\\sigma_{Y_2}^2\\sigma_{Y_2}^2}(\\sigma_{Y_1}^2(y_1-\\mu_{Y_1})^2-2\\cov(Y_1,Y_2)(y_1-\\mu_{Y_1})(y_2-\\mu_{Y_2})+\\sigma_{Y_1}^2(y_2-\\mu_{Y_2})^2)\\\\\r\n    =&\\frac{1}{1-\\varrho^2}\\big[\\frac{(y_1-\\mu_{Y_1})^2}{\\sigma_{Y_1}^2}-2\\varrho(\\frac{y_1-\\mu_{Y_1}}{\\sigma_{Y_1}})(\\frac{y_2-\\mu_{Y_2}}{\\sigma_{Y_2}})+\\frac{(y_2-\\mu_{Y_2})^2}{\\sigma_2^2}\\big]\r\n\\end{align*}\r\nHence,\r\n\\begin{align*}\r\n    f_Y(y_1,y_2)=\\frac{1}{2\\pi\\sigma_{Y_1}\\sigma_{Y_2}\\sqrt{1-\\varrho^2}}e^{-\\frac{1}{2(1-\\varrho^2)}\\big[\\frac{(y_1-\\mu_{Y_1})^2}{\\sigma_{Y_1}^2}-2\\varrho(\\frac{y_1-\\mu_{Y_1}}{\\sigma_{Y_1}})(\\frac{y_2-\\mu_{Y_2}}{\\sigma_{Y_2}})+\\frac{(y_2-\\mu_{Y_2})^2}{\\sigma_2^2}\\big]}.\r\n\\end{align*}\r\n\r\n}\r\n\r\n\\section*{Exercise 4.2}\r\n\\begin{align*}\r\n    E[Y]=E\\bigg[\\left(\\begin{aligned}\r\n        a_{11}X_1+a_{12}X_2\\\\\r\n        a_{21}X_1+a_{22}X_2\r\n    \\end{aligned}\\right)\\bigg]=\r\n    \\left(\\begin{aligned}\r\n        a_{11}E[X_1]+a_{12}E[X_2]\\\\\r\n        a_{21}E[X_1]+a_{22}E[X_2]\r\n    \\end{aligned}\\right)=\r\n    A\\left(\\begin{aligned}\r\n        E[X_1]\\\\\r\n        E[X_2]\r\n    \\end{aligned}\\right)=AE[X].\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n    \\var(Y)&=\\left(\\begin{aligned}\r\n        &\\var(Y_1) & \\cov(Y_1,Y_2)\\\\\r\n        &\\cov(Y_2,Y_1) & \\var(Y_2)\r\n    \\end{aligned}\\right)\r\n    =\\left(\\begin{aligned}\r\n        &(a_{11}^2+a_{12}^2)\\sigma^2 & (a_{11}a_{21}+a_{22}a_{12})\\sigma^2\\\\\r\n        &(a_{11}a_{21}+a_{22}a_{12})\\sigma^2 & (a_{21}^2+a_{22}^2)\\sigma^2\r\n    \\end{aligned}\\right)\\\\\r\n    &=\\sigma^2\\left(\\begin{aligned}\r\n        &a_{11}^2+a_{12}^2 & a_{11}a_{21}+a_{22}a_{12}\\\\\r\n        &a_{11}a_{21}+a_{22}a_{12} & a_{21}^2+a_{22}^2\r\n    \\end{aligned}\\right).\r\n\\end{align*}\r\n\r\nSince $A^T=A^{-1}$, then\r\n\\begin{align*}\r\n    AA^T=I=\\left(\\begin{aligned}&1&0\\\\&0&1\\end{aligned}\\right)\r\n        =\\left(\\begin{aligned}\r\n        &a_{11}^2+a_{12}^2 & a_{11}a_{21}+a_{22}a_{12}\\\\\r\n        &a_{11}a_{21}+a_{22}a_{12} & a_{21}^2+a_{22}^2\r\n    \\end{aligned}\\right).\r\n\\end{align*}\r\n\r\nHence,\r\n\\begin{align*}\r\n    \\var(Y)=\\sigma^2\\left(\\begin{aligned}&1&0\\\\&0&1\\end{aligned}\\right).\r\n\\end{align*}\r\n\r\n\\section*{Exercise 4.3}\r\nDenote that $x=z_{\\alpha_1}$ and $y=z_{\\alpha_2}$. Then we obtain\r\n\\spl{\r\n    &\\Phi(-x)+\\Phi(-y)=\\alpha,\\\\\r\n    &g(x,y):=\\Phi(-x)+\\Phi(-y)-\\alpha=0.\r\n}\r\n\r\nNow we want to calculate the \\textbf{conditional extreme} values of\r\n\\spl{\r\n    f(x,y):=\\frac{(x+y)\\sigma}{\\sqrt{n}}.\r\n}\r\n\r\nThus we have the \\textbf{partial differentiations} of $F(x,y,\\lambda)=f(x,y)+\\lambda g(x,y)$.\r\n\r\n\\[\r\n    \\left\\{\\begin{aligned}\r\n        &F_x=\\frac{\\sigma}{\\sqrt{n}}-\\lambda f_N(-x)=0\\\\\r\n        &F_y=\\frac{\\sigma}{\\sqrt{n}}-\\lambda f_N(-y)=0\\\\\r\n        &F_\\lambda=\\Phi(-x)+\\Phi(-y)-\\alpha=0\\\\\r\n    \\end{aligned}\\right. ,\r\n\\]\r\n\r\nwhere $f_N(\\cdot)$ is the density of a standard normal distribution.\r\n\r\nWe find that $x=y$, which means $z_{\\alpha_1}=z_{\\alpha_2}$. Also, $\\alpha_1+\\alpha_2=\\alpha$.\r\n\r\nThus $\\alpha_1=\\alpha_2=\\alpha/2$.\r\n\r\n\\section*{Exercise 4.4}\r\nSince $(n-1)s^2/sigma_2$ follows a chi-squared distribution, then\r\n\\spl{\r\n    1-\\alpha&=P[\\chi_{1-\\alpha/2,n-1}^2\\leq(n-1)s^2\\sigma^2\\leq\\chi_{\\alpha/2,n-1}^2]\\\\\r\n    &=P\\bigg[\\frac{(n-1)s^2}{\\chi_{\\alpha/2,n-1}^2}\\leq\\sigma^2\\leq\\frac{(n-1)s^2}{\\chi_{1-\\alpha/2,n-1}^2}\\bigg]\\\\\r\n    &=P\\bigg[\\sqrt{\\frac{(n-1)s^2}{\\chi_{\\alpha/2,n-1}^2}}\\leq\\sigma\\leq\\sqrt{\\frac{(n-1)s^2}{\\chi_{1-\\alpha/2,n-1}^2}}\\bigg].\r\n}\r\n\r\nSince $\\alpha=0.05$, then\r\n\\spl{\r\n    \\chi_{0.025,50}^2&=71.42,\\\\\r\n    \\chi_{0.975,50}^2&=32.36.\r\n}\r\n\r\nTherefore, \r\n\\spl{\r\n    \\sqrt{\\frac{50\\cdot0.37^2}{71.42}}\\leq&\\sigma\\leq\\sqrt{\\frac{50\\cdot0.37^2}{32.36}}\\\\\r\n    0.31\\leq&\\sigma\\leq0.46.\r\n}\r\n\r\nHence, the 95\\% two-sided confidence interval for $\\sigma$ is [0.31,0.46].\r\n\r\n\\section*{Exercise 4.5}\r\n\\enum{\r\n\\item\r\nWe consider the exclusive situations. If all the samples are greater than $M$ or less than $M$, then $M$ will not fall between $X_{min}$ and $X_{max}$.\r\n\r\nSince $F(M)=\\frac{1}{2}$, which means the probability that a sample is less or greater than $M$ is both $\\frac{1}{2}$.\r\n\r\nHence the probability that all the samples are greater than $M$ or less than $M$ is\r\n\\spl{\r\n    \\bigg(\\frac{1}{2}\\bigg)^n+\\bigg(\\frac{1}{2}\\bigg)^n=\\bigg(\\frac{1}{2}\\bigg)^{n-1}.\r\n}\r\n\r\nTherefore, the probability that $M$ falls between $X_{min}$ and $X_{max}$ is\r\n\\spl{\r\n    P[X_{min}\\leq M \\leq X_{max}]=1-\\bigg(\\frac{1}{2}\\bigg)^{n-1}.\r\n}\r\n\r\n\\item \r\nFor $P[X_{k+1}\\leq M\\leq X_{n-k}]$, we can also consider the exclusive situations. In this case, the probability that the samples $X_{k+1}$ to $X_{n-k}$ are greater than $M$ or less than $M$ is\r\n\\spl{\r\n    \\sum_{x=1}^k\\binom{n}{x}\\bigg(\\frac{1}{2}\\bigg)^{x}\\bigg(\\frac{1}{2}\\bigg)^{n-x}+\\sum_{x=1}^k\\binom{n}{n-x}\\bigg(\\frac{1}{2}\\bigg)^{x}\\bigg(\\frac{1}{2}\\bigg)^{n-x}=\\sum_{x=1}^k\\binom{n}{x}\\bigg(\\frac{1}{2}\\bigg)^{n-1}.\r\n}\r\n\r\n\\spl{\r\n    P[X_{k+1}\\leq M\\leq X_{n-k}]=1-\\sum_{x=1}^k\\binom{n}{x}\\bigg(\\frac{1}{2}\\bigg)^{n-1}.\r\n} \r\n}", "meta": {"hexsha": "5a343260f91fa7c206589f86bf016c64e1231eb1", "size": 11469, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE401ProbStat/Assignments/Assignment4/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/Assignment4/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/Assignment4/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": 34.7545454545, "max_line_length": 272, "alphanum_fraction": 0.5500915511, "num_tokens": 5312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6859707422850048}}
{"text": "\\section{Neural Nets}\n\n\\paragraph{Neural Net} A neural net is a representation, that is a\narithmetic constraint net in which:\n\\begin{itemize}\n  \\item Operation frames denote arithmetic constraints modeling\n    synapses and neurons\n  \\item Demon procedures propagate stimuli through synapses and\n    neurons\n\\end{itemize}\nWith demon procedures defines assignment:\n\\begin{itemize}\n  \\item When a value is written into a synapse's input slot, write\n    the product of the value and the synapse's weight into the\n    synapse's output slot\n  \\item When a value is written into a synapse's output slot,\n    check the following neuron to see whether all its input\n    synapses' outputs have values:\n    \\begin{itemize}\n      \\item If they do, add the outputs values of the input\n        synapses together, pass the sum through the activation\n        function, and write the appropriate value into the\n        neuron's output slot\n      \\item If they don't, do nothing\n    \\end{itemize}\n\\end{itemize}\n\nTo do back propagation to train a neural net:\n\\begin{itemize}\n  \\item Pick a rate parameter $r$\n  \\item Until performance is satisfactory,\n    \\begin{itemize}\n      \\item For each input,\n        \\begin{itemize}\n          \\item Compute the resulting output\n          \\item Compute $\\beta$ for nodes in the output layers\n            using $\\beta_{x} = d_x - o_x$\n          \\item Compute $\\beta$ for all other nodes using:\n            \\begin{math}\n              \\beta_j = \\sum_{k}{w_{jk}o_k(1-o_k)\\beta_k}\n            \\end{math}\n          \\item Compute weight changes for all weight using:\n            \\begin{math}\n              \\Delta{w_{ij}} = ro_io_k(1-o_k)\\beta_j\n            \\end{math}\n        \\end{itemize}\n      \\item Add up the weight changes to all sample inputs and\n        changes the weights\n    \\end{itemize}\n\\end{itemize}\n\n\\subsection{Back-propagation characteristics}\n\n\\begin{itemize}\n  \\item Training may require thousands of back propagations\n  \\item Back-propagation can be done in stages\n  \\item Back-propagation can train a net to learn to recognize\n    multiple concepts simultaneously\n  \\item Trained neural nets can make predictions\n  \\item Excess weights lead to overfitting. Rule of thumb: be sure\n    that the number of trainable weights influencing any\n    particular output is smaller than the number of training\n    samples\n  \\item Neural-bet training is an article\n\\end{itemize}\n\n\\subsection{Perceptrons}\n\n\\paragraph{Perceptron} A perceptron is a representation, that is a\nneural net in which:\n\\begin{itemize}\n  \\item There is only one neuron\n  \\item The input sare binary\n  \\item Logic boxes may be interposed between the perceptron's\n    inputs and the perceptron's weights. Each logic box can be\n    viewed as a table that produces an output value of 0s or 1 for\n    each combination os 0s and 1s that can appear at its inputs\n  \\item The output of the perceptron is 0s or 1 depending on\n    whether the weighted sum of the logic-box outputs is greater\n    than the threshold.\n\\end{itemize}\n\nThe perceptron convergence procedure guarantees success whenever\nsuccess is possible.\n\nTo train a perceptron:\n\\begin{itemize}\n  \\item Until the perceptron yields the correct result for each\n    training sample, for each sample,\n    \\begin{itemize}\n      \\item If the perceptron yields the wrong answer,\n        \\begin{itemize}\n          \\item If the perceptron says no when it should say yes,\n            add the logic-box output vector to the weight vector\n          \\item Otherwise, subtract the logic-box output vector\n            from the weight vector\n        \\end{itemize}\n      \\item Otherwise, do nothing\n    \\end{itemize}\n\\end{itemize}\n\n", "meta": {"hexsha": "350bc6737e6f42be252c8aeaf8565de45a32fc22", "size": 3662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "neural_nets.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": "neural_nets.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": "neural_nets.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": 35.9019607843, "max_line_length": 66, "alphanum_fraction": 0.7045330421, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6859292539744247}}
{"text": "In the general linear regression setting, we cannot assume that the data is\ncentered. We might have a persistent constant offset vector added to the input\nfeatures or the output which will cause the centered recursive least squares\nestimator to be inaccurate or have worse generalization. In the static data\nregime, estimation of this constant offset can be done prior to solving the\nleast squares problem by calculating the feature and output means. In online\nestimation, we need to not only update the means at each timestep but also to\ncorrect the previous parameter estimate with respect to the new mean estimate.\nWhile the algebra becomes a bit more complex, the eventual structure of the\nupdate equations is remarkably similar to the uncentered case.\n\nIn order to contain the complexity of the following derivation, we proceed in\nstages. First, we will consider the case when the input features are centered\nbut the output is not. Then we will consider the inverse case, where the input\nfeatures are not centered but the output is. We will then see how these two\ncases can be combined in the general uncentered recursive least squares\nestimator.\n\n\\subsection{Centered X, Uncentered Y}\nIn this case we want to solve the problem\n\\begin{equation}\n  (y_T - \\mu_y(T)) = \\varphi_T\\hat\\Theta(T)\n\\end{equation}\nWhen the output data we are provided by $F(t)$ are not already centered, we\ncenter it prior to solving the least squares problem. Note that it is simple to calculate the output mean online, since\n\\begin{align}\n  \\mu_y(T) &= \\frac{1}{T}\\sum_{t=1}^T y_t \\\\\n           &= \\frac{T - 1}{T}\\mu_y(T - 1) + \\frac{1}{T}y_T \\\\\n  \\implies T\\mu_y(T) &= (T - 1)\\mu_y(T - 1) + y_T \\\\\n                     &= T \\mu_y(T - 1) + y_T - \\mu_y(T - 1) \\\\\n  \\implies \\mu_y(T) &= \\mu_y(T - 1) + \\frac{1}{T} (y_T - \\mu_y(T-1))\n\\end{align}\nThus the normal equation in this case is given by \n\\begin{align}\n  (X_T^\\top X_T)^{-1} X_T^\\top \\left(Y_T - \\bar{1}\\mu_y(T)\\right) &= (X_T^\\top X_T)^{-1} X_T^\\top \\left(Y_T - \\bar{1}\\frac{1}{T}\\sum_{t=1}^Ty_t\\right) \\\\\n                                                                  &= (X_T^\\top X_T)^{-1} X_T^\\top Y_T - (X_T^\\top X_T)^{-1} X_T^\\top \\bar{1}\\frac{1}{T}\\sum_{t=1}^Ty_t \\label{eq:split_uncentered_y}\n\\end{align}\nNote that the first term in Equation~\\ref{eq:split_uncentered_y} is just the\nnormal equation for the centered least squares problem that we already derived\nrecursive update equations for, so all that remains is expanding the second\nterm as\n\\begin{align}\n  (X_T^\\top X_T)^{-1} X_T^\\top \\bar{1}\\mu_y(T) &= P_T \\sum_{t=1}^T \\varphi_t^\\top \\mu_y(T) \\\\\n                                               &= T \\cdot P_T \\mu_x(T)^\\top \\mu_y(T) \\label{eq:correction_1}\n\\end{align}\nOf course, in the current case $\\mu_x = \\bar{0}$, so this correction term is\nactually zero and we recover the same update equations as previously derived.\nHowever, Equation~\\ref{eq:correction_1} will come in handy later when we derive\nthe general uncentered update.\n\nEven though the update equations are the same, the final prediction of our\nmodel includes a constant offset term that we can derive from the model\nequation\n\\begin{align}\n  (y_T - \\mu_y(T)) &= \\varphi_T\\hat\\Theta_{LS}(T) \\\\\n  \\implies y_T &= \\varphi_T\\hat\\Theta_{LS}(T) + \\mu_y(T)\n\\end{align}\n\n\\subsection{Uncentered X, Centered Y}\nIn this case we want to solve the problem\n\\begin{equation}\n  y_T = (\\varphi_T - \\mu_x(T))\\hat\\Theta(T)\n\\end{equation}\nIn the same way that we calculated the update equation for $\\mu_y$, we calculate \n\\begin{equation}\n  \\mu_x(T) = \\mu_x(T - 1) + \\frac{1}{T}(\\varphi_T - \\mu_x(T - 1))\n\\end{equation}\nThe normal equation for this case is given by\n\\begin{multline}\n  \\label{eq:expanded_uncentered_x_normal}\n  \\left[(X_T - \\bar{1}\\mu_x(t))^\\top(X_T - \\bar{1}\\mu_x(t))\\right]^{-1}(X_T - \\bar{1}\\mu_x(t))^\\top Y = \\\\ \\left[(X_T^\\top X_T - X_T^\\top \\bar{1}\\mu_x(T) - (\\bar{1}\\mu_x(T))^\\top X_T + \\mu_x(T)^\\top\\mu_x(T)\\right]^{-1}(X_T - \\bar{1}\\mu_x(t))^\\top Y\n\\end{multline}\nNote that\n\\begin{align}\n  X_T^\\top \\bar{1}\\mu_x(T) &= \\sum_{t=1}^T \\varphi_t^\\top \\mu_x(T) \\\\\n                           &= T \\mu_x(T)^\\top \\mu_x(T)\n\\end{align}\nThus Equation~\\ref{eq:expanded_uncentered_x_normal} becomes\n\\begin{multline}\n  \\left[(X_T^\\top X_T - 2T\\mu_x(T)^\\top\\mu_x(T) + \\mu_x(T)^\\top\\mu_x(T)\\right]^{-1}(X_T - \\bar{1}\\mu_x(t))^\\top Y = \\\\ \\left[(P_T^{-1} - (2T - 1)\\mu_x(T)^\\top\\mu_x(T)\\right]^{-1}(X_T - \\bar{1}\\mu_x(t))^\\top Y\n\\end{multline}\nLet us define, analogously to $P_T$ from before, \n\\begin{equation}\n  Q_T := \\left[P_T^{-1} - (2T - 1)\\mu_x(T)^\\top\\mu_x(T)\\right]^{-1}\n\\end{equation}\n\n\\subsubsection{Deriving the $Q_T$ Update}\nAs with $P_T$, we begin by developing an update for $Q_T^{-1}$ in terms of $Q_{T-1}^{-1}$\n\\begin{align}\n  Q_T^{-1} &= P_T^{-1} - (2T - 1)\\mu_x(T)^\\top\\mu_x(T) \\\\\n           &= P_{T-1}^{-1} + \\varphi_T^\\top\\varphi_T - \\frac{2T - 1}{T^2}((T-1)\\mu_x(T-1) + \\varphi_T)^\\top((T-1)\\mu_x(T-1) + \\varphi_T) \\label{eq:Q_T_partial}\n\\end{align}\nAs a side computation, and to avoid stacking even longer equations, let $\\mu := \\mu_x(T - 1)$ and note\n\\begin{align}\n  ((T - 1)\\mu + \\varphi_T)^\\top((T-1)\\mu + \\varphi_T) &= (T - 1)^2\\mu^\\top\\mu + (T-1)\\mu^\\top\\varphi_T + (T-1)\\varphi_T^\\top\\mu + \\varphi_T^\\top\\varphi_T\n\\end{align}\nWith this, Equation~\\ref{eq:Q_T_partial} can be written as\n\\begin{align}\n  Q_T^{-1} &= (P_{T-1}^{-1} - (2T - 1)\\mu^\\top\\mu + 2\\mu^\\top\\mu) - 2\\mu^\\top\\mu + \\varphi_T^\\top\\varphi_T- \\frac{2T - 1}{T^2}\\left[(-2T + 1)\\mu^\\top\\mu + (T-1)\\mu^\\top\\varphi_T + (T-1)\\varphi_T^\\top\\mu + \\varphi_T^\\top\\varphi_T\\right] \\\\\n           &= (P_{T-1}^{-1} - (2(T-1) - 1)\\mu^\\top\\mu) - 2\\mu^\\top\\mu + \\varphi_T^\\top\\varphi_T + \\frac{2T - 1}{T^2}\\left[(-2T + 1)\\mu^\\top\\mu + (T-1)\\mu^\\top\\varphi_T + (T-1)\\varphi_T^\\top\\mu + \\varphi_T^\\top\\varphi_T\\right] \\\\\n           &= Q_{T-1}^{-1} - 2\\mu^\\top\\mu + \\varphi_T^\\top\\varphi_T- \\frac{2T - 1}{T^2}\\left[(-2T + 1)\\mu^\\top\\mu + (T-1)\\mu^\\top\\varphi_T + (T-1)\\varphi_T^\\top\\mu + \\varphi_T^\\top\\varphi_T\\right]\n\\end{align}\nOne final expansion:\n\\begin{equation}\n  Q_T^{-1} = Q_{T-1}^{-1} + \\frac{1}{T^2}\\left[((2T+1)^2 - 2T^2)\\mu^\\top\\mu - (2T - 1)(T - 1)\\mu^\\top\\varphi_T - (2T - 1)(T - 1)\\varphi_T^\\top\\mu + (T^2 - 2T + 1)\\varphi_T^\\top\\varphi_T\\right]\n\\end{equation}\nAnd now we can see that this can be written as\n\\begin{equation}\n  Q_T^{-1} = Q_{T-1}^{-1} + \\frac{1}{T^2}\n  \\begin{bmatrix}\n    \\mu_x(T-1)^\\top & \\varphi_T^\\top\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    (2T - 1)^2 - 2T^2 & -(2T - 1)(T - 1) \\\\\n    -(2T - 1)(T - 1) & (T - 1)^2\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\mu_x(T - 1) \\\\\n    \\varphi_T\n  \\end{bmatrix}\n\\end{equation}\nLet us define\n\\begin{align}\n  C_T &:= \\frac{1}{T^2}\n  \\begin{bmatrix}\n    (2T - 1)^2 - 2T^2 & -(2T - 1)(T - 1) \\\\\n    -(2T - 1)(T - 1) & (T - 1)^2\n  \\end{bmatrix} \\\\\n  V_T &:= \n  \\begin{bmatrix}\n    \\mu_x(T - 1) \\\\\n    \\varphi_T\n  \\end{bmatrix} \\\\\n  R_T &:= V_T^\\top C_T V_T\n\\end{align}\nSo that \n\\begin{equation}\n  \\label{eq:Q_T_inv}\n  Q_T^{-1} = Q_{T - 1}^{-1} + R_T\n\\end{equation}\nThe Woodbury matrix identity (Equation~\\ref{eq:woodbury}) gives us, at the end\nof all this, an update rule for $Q_T$:\n\\begin{equation}\n  Q_T = Q_{T - 1} - Q_{T - 1}V_T^\\top\\left(C_T^{-1} + V_TQ_{T-1}V_T^\\top\\right)^{-1}V_TQ_{T-1} \\label{eq:uncentered_Q_T_update}\n\\end{equation}\nNote that this is a rank-2 update to $Q_{T-1}$, since we are using both the\nsample mean at time $T - 1$ and the new data at time $T$ to compute the update.\n\n\\subsubsection{Deriving the $\\hat\\Theta$ Update}\nReturning to the normal equation\n\\begin{align}\n  \\hat\\Theta_{LS}(T) &= Q_T (X_T - \\bar{1} \\mu_x(T))^\\top Y \\\\\n                     &= Q_TX^\\top Y - Q_T \\mu_x(T)^\\top\\bar{1}^\\top Y \\\\\n                     &= Q_T\\left[Q_{T-1}^{-1}(t-1)\\hat\\Theta_{LS}(T-1) + \\varphi_T^\\top y_T\\right] - TQ_T\\mu_x(T)^\\top \\mu_y(T) \\\\\n                     &= Q_T \\varphi_T^\\top y_T + Q_T\\left[Q_{T}^{-1} - R_T\\right]\\hat\\Theta_{LS}(T-1) - TQ_T\\mu_x(T)^\\top\\mu_y(T) \\\\\n                     &= \\hat\\Theta_{LS}(T-1) + Q_T\\left[\\varphi_T^\\top y_T - R_T\\hat\\Theta_{LS}(T-1)\\right] - TQ_T\\mu_x(T)^\\top \\mu_y(T) \\label{eq:uncentered_x_theta_with_correction}\n\\end{align}\nSince in the current case we are assuming that $Y$ is already centered,\n$\\mu_y(T) = \\bar{0}$ and the above reduces to\n\\begin{equation}\n  \\hat\\Theta_{LS}(T) = \\hat\\Theta_{LS}(T-1) + Q_T\\left[\\varphi_T^\\top y_T - R_T\\hat\\Theta_{LS}(T-1)\\right] \\label{eq:uncentered_x_theta_update}\n\\end{equation}\nThis corresponds roughly to the $\\hat\\Theta$ update in the centered case (Equation~\\ref{eq:centered_theta_update}).\n\n\\subsection{Uncentered X, Uncentered Y}\nWe have finally arrived at the general case, in which our problem is expressed as \n\\begin{equation}\n  (y_T - \\mu_y(T)) = (\\varphi_T - \\mu_x(T))\\hat\\Theta(T)\n\\end{equation}\nThe normal equation for this case is \n\\begin{align}\n  \\left[(X_t - \\bar{1}\\mu_x(T))^\\top(X_T - \\bar{1}\\mu_x(T))\\right]^{-1}(X_T &- \\bar{1}\\mu_x(T))^\\top (Y_T - \\bar{1}\\mu_y(T)) \\nonumber \\\\ &= Q_T(X_T - \\bar{1}\\mu_x(T))^\\top (Y_T - \\bar{1}\\mu_y(T)) \\\\\n                                                                            &= Q_T (X_T - \\bar{1}\\mu_x(T))^\\top Y - Q_T(X_T - \\bar{1}\\mu_x(T))^\\top\\bar{1}\\mu_y(T) \\label{eq:uncentered_xy_normal}\n\\end{align}\nNote that the first term in Equation~\\ref{eq:uncentered_xy_normal} is the\nnormal equation for the uncentered X, centered Y case previously analyzed. Thus\nall that we need to do in order to derive the update for $\\hat\\Theta$ is expand the second term. This is easy, though, because\n\\begin{align}\n  Q_T(X_T - \\bar{1}\\mu_x(T))^\\top\\bar{1}\\mu_y(T) &= Q_TX_T^\\top\\bar{1}\\mu_y(T) - Q_T\\mu_x(T)^\\top\\bar{1}^\\top\\bar{1}\\mu_y(T)\\\\\n                                                 &= TQ_T\\mu_x(T)^\\top \\mu_y(T) - Q_T\\mu_x(T)^\\top\\mu_y(T) \\\\\n                                                 &= (T - 1)Q_T \\mu_x(T)^\\top \\mu_y(T)\n\\end{align}\nThis, combined with the correction term in\nEquation~\\ref{eq:uncentered_x_theta_with_correction} (which is now nonzero\nsince we assume that $\\mu_Y(T) \\neq 0$), gives us a total correction of $(2T -\n1) Q_T \\mu_x(T)^\\top \\mu_y(T)$.\n\nSince the update equation for $Q_T$ depends only on $\\varphi_T$ and $\\mu_x(T)$,\nit only remains to give the final update equation for $\\hat\\Theta(T)$ in the\nuncentered X, uncentered Y case. Combining Equation~\\ref{eq:uncentered_x_theta_update} with the previously stated correction term, we get the following update:\n\\begin{align}\n  \\hat\\Theta_{RAW}(T) &= \\hat\\Theta_{RAW}(T-1) + Q_T\\left[\\varphi_T^\\top y_T - R_T\\hat\\Theta_{RAW}(T-1)\\right]\\\\\n  \\hat\\Theta_{LS}(T) &= \\hat\\Theta_{RAW}(T) - (2T - 1)Q_T\\mu_x(T)^\\top \\mu_y(T)\n\\end{align}\n\nRecall that our original problem in the uncentered case was\n\\begin{equation}\n  (y_T - \\mu_y(T)) = (\\varphi_T - \\mu_x(T))\\hat\\Theta\n\\end{equation}\nThus the prediction of the recursive least squares filter in the uncentered X, uncentered Y case for a new $\\varphi'$ is given by\n\\begin{align}\n  (\\hat{y}' - \\mu_y(T)) &= (\\varphi' - \\mu_x(T))\\hat\\Theta_{LS}(T) \\\\\n  \\implies \\hat{y}' &= \\varphi'\\hat\\Theta_{LS}(T) + (\\mu_y(T) - \\mu_x(T)\\hat\\Theta_{LS}(T))\n\\end{align}\n", "meta": {"hexsha": "0f7983af332502e38dc825b05c31359d69dccecb", "size": 11075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/src/uncentered.tex", "max_stars_repo_name": "cannontwo/rls", "max_stars_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_stars_repo_licenses": ["MIT"], "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/src/uncentered.tex", "max_issues_repo_name": "cannontwo/rls", "max_issues_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_issues_repo_licenses": ["MIT"], "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/src/uncentered.tex", "max_forks_repo_name": "cannontwo/rls", "max_forks_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_forks_repo_licenses": ["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.0243902439, "max_line_length": 248, "alphanum_fraction": 0.6346726862, "num_tokens": 4100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427857178614, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6859110599863745}}
{"text": "\\section{The Integral Test}\\label{sec:IntegralTest}\n\nIt is generally quite difficult, often impossible, to determine\nthe value of a series exactly. In many cases it is possible at least\nto determine whether or not the series converges, and so we will spend\nmost of our time on this problem.\n\nIf all of the terms $\\ds a_n$ in a series are non-negative, then clearly \nthe sequence of partial sums $\\ds s_n$ is non-decreasing. This means that\nif we can show that the sequence of partial sums is bounded, the\nseries must converge. Many useful and interesting series have this property,\nand they are among the easiest to understand. Let's look at\nan example.\n\n\\begin{example}{}{}\nShow that $\\ds\\sum_{n=1}^\\infty {1\\over n^2}$ converges.\n\\end{example}\n\\begin{solution}\nThe terms $\\ds 1/n^2$ are  positive and decreasing, and since \n$\\ds\\lim_{x\\to\\infty} 1/x^2=0$, the terms $\\ds 1/n^2$ approach zero. We\nseek an upper bound for all the partial sums, that is, we want to find\na number $N$ so that $s_n\\le N$ for every $n$. The upper bound is\nprovided courtesy of integration, and is illustrated in\nfigure~\\xrefn{fig:integral test for one over n squared}.\n\n\\begin{figure}[H]\n\\centerline{\n%\\texonly\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 5, y from 0 to 2\n\\axis left ticks numbered from 0 to 2 by 1 /\n\\axis bottom  ticks numbered from 0 to 5 by 1 /\n\\setquadratic\n\\plot 0.750 1.778 0.892 1.258 1.033 0.937 1.175 0.724 1.317 0.577 \n1.458 0.470 1.600 0.391 1.742 0.330 1.883 0.282 2.025 0.244 \n2.167 0.213 2.308 0.188 2.450 0.167 2.592 0.149 2.733 0.134 \n2.875 0.121 3.017 0.110 3.158 0.100 3.300 0.092 3.442 0.084 \n3.583 0.078 3.725 0.072 3.867 0.067 4.008 0.062 4.150 0.058 \n4.292 0.054 4.433 0.051 4.575 0.048 4.717 0.045 4.858 0.042 \n5.000 0.040 /\n\\putrule from 1 0 to 1 1 \n\\putrule from 2 0 to 2 0.25\n\\putrule from 3 0 to 3 0.1111\n\\putrule from 0 1 to 1 1 \n\\putrule from 1 0.25 to 2 0.25\n\\putrule from 2 0.1111 to 3 0.1111\n%\\sevenpoint\n\\put {$A=1$} at 0.5 0.5\n\\put {$A=1/4$} at 1.5 0.125\n\\endpicture}}\n%\\endtexonly\n%\\htmlfigure{Sequences_series-integral_test_upper_bound.html}\n\\caption{Graph of $\\ds y=1/x^2$ with rectangles.}\n\\label{fig:integral test for one over n squared}\n\\end{figure}\n\nThe figure shows the graph of $\\ds y=1/x^2$ together with some rectangles\nthat lie completely below the curve and that all have base length\none. Because the heights of the rectangles are determined by the\nheight of the curve, the areas of the rectangles are $\\ds 1/1^2$, $\\ds 1/2^2$,\n$\\ds 1/3^2$, and so on---in other words, exactly the terms of the\nseries. The partial sum $\\ds s_n$ is simply the sum of the areas of the\nfirst $n$ rectangles. Because the rectangles all lie between the curve\nand the $x$-axis, any sum of rectangle areas is less than the\ncorresponding area under the curve, and so of course any sum of\nrectangle areas is less than the area under the entire curve. Unfortunately,\nbecause of the asymptote at $x=0$, the integral $\\int_0^{\\infty}\\frac{1}{x^2}$\nis infinite, but we can deal with this by separating the first term from\nthe series and integrating from 1:\n\\[\\ds s_n=\\sum_{i=1}^{n}\\frac{1}{i^2}=1+\\sum_{i=2}^{n}\\frac{1}{i^2}<1+\\int_1^n\\frac{1}{x^2}\\,dx<1+\\int_1^{\\infty}\\frac{1}{x^2}\\,dx=1+1=2\\]\n(Recalling that we computed this improper integral in \nsection~\\ref{sec:ImproperIntegrals}). Since the sequence of partial\nsums $\\ds s_n$ is increasing and bounded above by 2, we know that \n$\\ds\\lim_{n\\to\\infty}s_n=L<2$, and so the series converges to some\nnumber less than 2. In fact, it is possible, though difficult, to show\nthat $\\ds L=\\pi^2/6\\approx 1.6$.\n\\end{solution}\n\nWe already know that $\\sum 1/n$ diverges. What goes wrong if we try to\napply this technique to it? Here's the calculation:\n$$\n  s_n={1\\over 1}+{1\\over 2}+{1\\over 3}+\\cdots+{1\\over n}\n  < 1 + \\int_1^n {1\\over x}\\,dx < 1+\\int_1^\\infty {1\\over x}\\,dx \n  =1+\\infty.\n$$\nThe problem is that the improper integral doesn't converge. Note\nthat this does \\emph{not} prove that $\\sum 1/n$ diverges, just that\nthis particular calculation fails to prove that it converges. A slight\nmodification, however, allows us to prove in a second way that $\\sum\n1/n$ diverges. \n\nConsider a slightly altered version of Figure~\\ref{fig:integral\ntest for one over n squared}, shown in Figure~\\ref{fig:integral test\nfor one over n}.\n\n\\begin{figure}[H]\n\\centerline{\n%\\texonly\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 5, y from 0 to 2\n\\axis left ticks numbered from 0 to 2 by 1 /\n\\axis bottom  ticks numbered from 0 to 5 by 1 /\n\\setquadratic\n\\plot 0.500 2.000 0.650 1.538 0.800 1.250 0.950 1.053 1.100 0.909 \n1.250 0.800 1.400 0.714 1.550 0.645 1.700 0.588 1.850 0.541 \n2.000 0.500 2.150 0.465 2.300 0.435 2.450 0.408 2.600 0.385 \n2.750 0.364 2.900 0.345 3.050 0.328 3.200 0.312 3.350 0.298 \n3.500 0.286 3.650 0.274 3.800 0.263 3.950 0.253 4.100 0.244 \n4.250 0.235 4.400 0.227 4.550 0.220 4.700 0.213 4.850 0.206 \n5.000 0.200 /\n\\putrule from 1 0 to 1 1 \n\\putrule from 2 0 to 2 1\n\\putrule from 3 0 to 3 0.5\n\\putrule from 4 0 to 4 0.3333\n\\putrule from 1 1 to 2 1\n\\putrule from 2 0.5 to 3 0.5\n\\putrule from 3 0.3333 to 4 0.3333\n%\\sevenpoint\n\\put {$A=1$} at 1.5 0.5\n\\put {$A=1/2$} at 2.5 0.25\n\\put {$A=1/3$} at 3.5 0.1666\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:integral test for one over n}\n%\\htmlfigure{Sequences_series-integral_test_lower_bound.html}\n\\caption{Graph of $y=1/x$ with rectangles.}\n\\label{fig:integral test for one over n}\n\\end{figure}\n\nThis time the rectangles are above the curve, that is, each rectangle\ncompletely contains the corresponding area under the curve. This means\nthat \n$$s_n = {1\\over 1}+{1\\over 2}+{1\\over 3}+\\cdots+{1\\over n}\n> \\int_1^{n+1} {1\\over x}\\,dx = \\ln x\\Big|_1^{n+1}=\\ln(n+1).$$\nAs $n$ gets bigger, $\\ln(n+1)$ goes to infinity, so the sequence of\npartial sums $\\ds s_n$ must also go to infinity, so the harmonic series\ndiverges. \n\nThe key fact in this example is that\n\\[\\ds\\lim_{n\\to\\infty}\\int_1^{n+1}\\frac{1}{x}\\,dx=\\int_1^{\\infty}\\frac{1}{x}\\,dx=\\infty\\]\nSo these two examples taken together indicate that we can prove that a\nseries converges or prove that it diverges with a single calculation\nof an improper integral. This is known as the \\dfont{integral test}, \nwhich we state as a theorem.\n\n\\begin{theorem}{Integral Test}{IntegralTestTheorem}\nSuppose that $f(x)>0$ and is decreasing on the infinite interval\n$[1,\\infty)$ and that $\\ds a_n=f(n)$. Then the series\n$\\ds\\sum_{n=1}^\\infty a_n$ converges if and only if the improper\nintegral $\\ds\\int_{1}^\\infty f(x)\\,dx$ converges.\n\\end{theorem}\n\nThe two examples we have seen are called\n\\dfont{$p$-series}; a $p$-series is\nany series of the form $\\ds \\sum 1/n^p$. If $p\\le0$, $\\ds\\lim_{n\\to\\infty}\n1/n^p\\not=0$, so the series diverges. For positive values of $p$ we\ncan determine precisely which series converge.\n\n\\begin{theorem}{$p$-Series Convergence}{pSeriesConvTheorem}\nA $p$-series with $p>0$ converges if and only if $p>1$.\n\\end{theorem}\n\\begin{proof}\nWe use the integral test; we have already done $p=1$, so assume that\n$p\\not=1$.\n$$\n  \\int_1^{\\infty} {1\\over x^p}\\,dx=\\lim_{D\\to\\infty} \\left.{x^{1-p}\\over\n  1-p}\\right|_{1}^D=\\lim_{D\\to\\infty} {D^{1-p}\\over 1-p}-{1\\over 1-p}.\n$$\nIf $p>1$ then $1-p<0$ and $\\ds\\lim_{D\\to\\infty}D^{1-p}=0$, so the\n  integral converges. If $0<p<1$ then $1-p>0$ and \n$\\ds\\lim_{D\\to\\infty}D^{1-p}=\\infty$, so the integral diverges.\n\\end{proof}\n\n\\begin{example}{$p$-Series}{pSeriesOne}\nShow that $\\ds\\sum_{n=1}^\\infty {1\\over {n^3}}$ converges. \n\\end{example}\n\\begin{solution}\nWe could of course use\nthe integral test, but now that we have the theorem we may simply note\nthat this is a $p$-series with $p>1$.\n\\end{solution}\n\n\\begin{example}{$p$-Series}{pSeriesTwo}\nShow that $\\ds\\sum_{n=1}^\\infty {5\\over n^4}$ converges. \n\\end{example}\n\\begin{solution}\nWe know that if\n$\\ds \\sum_{n=1}^\\infty 1/n^4$ converges then $\\ds \\sum_{n=1}^\\infty 5/n^4$\nalso converges, by Theorem~\\ref{thm:SeriesLinear}. Since \n$\\ds \\sum_{n=1}^\\infty 1/n^4$ is a convergent $p$-series, \n $\\ds \\sum_{n=1}^\\infty 5/n^4$ converges also.\n\\end{solution}\n\n\\begin{example}{$p$-Series}{pSeriesThree}\nShow that $\\ds\\sum_{n=1}^\\infty {5\\over \\sqrt{n}}$ diverges.\n\\end{example}\n\\begin{solution}\nThis also follows from Theorem~\\ref{thm:SeriesLinear}: Since $\\ds\\sum_{n=1}^\\infty\n{1\\over \\sqrt{n}}$ is a $p$-series with $p=1/2<1$, it diverges, and so\ndoes $\\ds\\sum_{n=1}^\\infty {5\\over \\sqrt{n}}$.  \n\\end{solution}\n\nSince it is typically difficult to compute the value of a series\nexactly, a good approximation is frequently required. In a real sense,\na good approximation is only as good as we know it is, that is, while\nan approximation may in fact be good, it is only valuable in practice\nif we can guarantee its accuracy to some degree. This guarantee is\nusually easy to come by for series with decreasing positive terms.\n\n\\begin{example}{}{}\nApproximate $\\ds \\sum 1/n^2$ to within 0.01.\n\\end{example}\n\\begin{solution}\nReferring to Figure~\\ref{fig:integral test for one over n squared},\nif we approximate the sum by $\\ds \\sum_{n=1}^N 1/n^2$, the size of the error we make is the\ntotal area of the remaining rectangles, all of which lie under the\ncurve $\\ds 1/x^2$ from $x=N$ to infinity. So we know the true value of\nthe series is larger than the approximation, and no bigger than the\napproximation plus the area under the curve from $N$ to\ninfinity. Roughly, then, we need to find $N$ so that \n$$\\int_N^\\infty {1\\over x^2}\\,dx < 1/100.$$\nWe can compute the integral:\n$$\\int_N^\\infty {1\\over x^2}\\,dx = {1\\over N},$$ \nso if we choose $N=100$ the error will be less than 0.01.  Adding up the first 100 terms\ngives approximately $1.634983900$. In fact, we can do a bit better. Since we know that\nthe correct value is between our approximation and our approximation plus the error\n(not minus), we can cut our error bound in half by taking the value midway between\nthese two values. If we take $N=50$, we get a sum of 1.6251327 with an error of at most 0.02,\nso the correct value is between 1.6251327 and 1.6451327, and therefore the value\nhalfway between these, 1.6351327, is within 0.01 of the correct value. We have mentioned\nthat the true value of this series can be shown to be $\\pi^2/6\\approx 1.644934068$ which\nis 0.0098 more than our approximation, and so (just barely) within the required error.\nFrequently approximations will be even better than the\n``guaranteed'' accuracy, but not always, as this example demonstrates.\n\\end{solution}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:IntegralTest}}\n\n\\begin{enumialphparenastyle}\n\nDetermine whether each series converges or diverges.\n\n\\begin{multicols}{2}\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {1\\over n^{\\pi/4}}$\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {n\\over n^2+1}$\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {\\ln n\\over n^2}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {1\\over n^2+1}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {1\\over e^n}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {n\\over e^n}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=2}^\\infty {1\\over n\\ln n}$\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=2}^\\infty {1\\over n(\\ln n)^2}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\end{multicols}\n\n\\begin{ex}\nFind an $N$ so that\n$\\ds\\sum_{n=1}^\\infty {1\\over n^4}$ is between\n$\\ds\\sum_{n=1}^N {1\\over n^4}$ and\n$\\ds\\sum_{n=1}^N {1\\over n^4} + 0.005$.\n\\begin{sol}\n$N=5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $N$ so that\n$\\ds\\sum_{n=0}^\\infty {1\\over e^n}$ is between\n$\\ds\\sum_{n=0}^N {1\\over e^n}$ and\n$\\ds\\sum_{n=0}^N {1\\over e^n} + 10^{-4}$.\n\\begin{sol}\n$N=10$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $N$ so that\n$\\ds\\sum_{n=1}^\\infty {\\ln n\\over n^2}$ is between\n$\\ds\\sum_{n=1}^N {\\ln n\\over n^2}$ and\n$\\ds\\sum_{n=1}^N {\\ln n\\over n^2} + 0.005$.\n\\begin{sol}\n$N=1687$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $N$ so that\n$\\ds\\sum_{n=2}^\\infty {1\\over n(\\ln n)^2}$ is between\n$\\ds\\sum_{n=2}^N {1\\over n(\\ln n)^2}$ and\n$\\ds\\sum_{n=2}^N {1\\over n(\\ln n)^2} + 0.005$.\n\\begin{sol}\nany integer greater than $\\ds e^{200}$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "54b247acf9425752ff240853cd30ee2f9504a848", "size": 12385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9-sequences-and-series/9-3-integral-test.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "9-sequences-and-series/9-3-integral-test.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "9-sequences-and-series/9-3-integral-test.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3857142857, "max_line_length": 138, "alphanum_fraction": 0.6996366572, "num_tokens": 4687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.891811054783143, "lm_q1q2_score": 0.6858742574349158}}
{"text": "\n\\subsection{Topological distinguishability}\n\nIf two points have the same neighbourhoods then they are topologically indistinguishable.\n\nFor example in the trivial topology, all points are topologically indistinguishable.\n\n", "meta": {"hexsha": "722ac8e573ccd86b8e781fcfee4ebe82c678c1ba", "size": 223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/01-03-distinguishability.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/01-03-distinguishability.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/01-03-distinguishability.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.875, "max_line_length": 89, "alphanum_fraction": 0.8430493274, "num_tokens": 42, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6858742408073987}}
{"text": "\\chapter{Getting started}\n\\thispagestyle{fancy}\n\\label{ch:getting-started}\n\n\n\n\\hrule\n\\begin{itemize}\n\\footnotesize\n\\item[]{Aims:}\n\\begin{itemize}\n\\item{to understand differences between commonly used local search methods;}\n\\item{to be aware of the assumptions in the linear approximation of parameter\nuncertainty:}\n\\item{to experience the limitations of local search methods for complex response\nsurfaces;}\n\\item{to be aware of the existence of multiple minima in complex response\nsurfaces;}\n\\item{to acknowledge the added value of global search methods;}\n\\item{to understand the need for efficient search methodologies.}\n\\end{itemize}\n\\end{itemize}\n\\hrule\n\\vspace{1em}\n\n\\section{Slug injection: manual calibration}\n\nA classic method in hydrology for determining the transmissivity and storage\ncoefficient of an aquifer is called the slug test. A known volume of water\n$Q$~[\\textsf{m$^3$}] (the slug) is injected into a well, and the resulting\neffect on the head $h$~[\\textsf{m}] (i.e.~water table elevation) at an\nobservation well a distance $d$~[\\textsf{m}] away from the injection is\nmonitored at times $t$~[\\textsf{hr}]. The measured head typically increases\nrapidly and then decreases more slowly. We wish to determine the storage\ncoefficient $S$~[\\textsf{m$^3\\cdot{}$m$^{-3}$}] (a measure of the ability of the\naquifer to store water) and the transmissivity\n$T$~[\\textsf{m$^2\\cdot{}$hr$^{-1}$}] (a measure of the ability of the aquifer to\nconduct water). The mathematical model for the slug test is:\n\\begin{equation}\n\\label{eq:slug-inj}\nh=\\frac{Q}{4\\cdot{}\\pi\\cdot{}T\\cdot{}t}e^{-d^2\\cdot{}S/(4\\cdot{}T\\cdot{}t)}\n\\end{equation}\n\n\n\n\\smallq{Use the MATLAB editor to open `mancal\\_sluginj.m' from\n`./exercises/manual-calibration-slug-injection/'. Run the script by pressing F5.\nA Graphical User Interface will appear. Use this interface to calibrate\nparameters $S$ and $T$ of Equation~\\ref{eq:slug-inj}. Assume\n$Q$~=~50~[\\textsf{m$^3$}] and $d$~=~60~[\\textsf{m}].}\n\n\\smallq{How do $S$ and $T$ affect the simulated pressure head?}\n\nSince this is a 2-parameter problem, we can easily visualize the objective\nfunction. Run `respsurf.m'. The objective function is the sum of squared\nresiduals (SSR).\n\n\\smallq{Were you able to identify the ``optimal'' model parameters using manual\ncalibration?}\n\n\\smallq{Looking at the response surface (Figure~\\ref{fig:respsurf-sluginj}), do\nyou think that the optimal model parameters are correlated?}\n\\begin{figure}[htbp]\n  \\centering\n    \\includegraphics[width=1.0\\textwidth]{./eps/converted/respsurf-sluginj}\n  \\caption{Response surface for the slug injection test. Dotted lines represent\nthe 95\\% confidence interval of the model parameters when the standard deviation\nof the head measurement is 0.01~[\\textsf{m}].}\n  \\label{fig:respsurf-sluginj}\n\\end{figure}\n\n\n\\smallq{The dotted lines in Figure~\\ref{fig:respsurf-sluginj} indicate the 95\\%\nconfidence intervals of the model parameters when the standard deviation of the\nhead measurement is 0.01~[\\textsf{m}]. Do you think this is a reasonable\napproximation for this nonlinear problem?}\n\n\n\\section{Optimization using local methods}\n\n\\subsection{Gauss-Newton and Levenberg-Marquardt}\n\n\\smallq{Two algorithms---Gauss-Newton (GN) and Levenberg-Marquardt (LM)--have\nbeen implemented to automatically find the optimal parameters for the slug test.\nTo run these algorithms for the slug test problem, set your work directory to\n`./exercises/local-methods-sluginj'. This directory contains a function that\nperforms a Gauss-Newton as well as a Levenberg-Marquardt optimization. This\nfunction requires an input argument containing a starting point\n(e.g.~\\mcode{[0.15,0.4]}). For each method, the function returns an array with a\nrecord of parameter sets and their objective score. You can call the function\nfrom the command line using:\n\n\\mcode{[P_GN,P_LM]=Run_Optimization([0.15,0.4]);}\n}\n\n\n\n\\smallq{Have a look at the code and interpret the output.}\n\n\\smallq{How quickly does the GN method converge?}\n\n\\smallq{How does this compare to the LM method?}\n\n\\smallq{Play around with different starting points for the two algorithms. Does\nthe GN method always converge to the optimum? What about the convergence of the\nLM method?}\n\n\\smallq{Find a starting point where the GN and LM methods differ and study the\niterations in detail (\\mcode{P_GN} and \\mcode{P_LM}).}\n\n\\smallq{What is the key difference between the iterations of the GN and LM\nmethod?}\n\n\n\\subsection{Multi-start simplex}\n\nHYMOD \\citep{boyl-gupt-soro2000} is a simple rainfall-runoff model with 5 model\nparameters (see Figure~\\ref{fig:hymod}).\n\n\\begin{figure}[htbp]\n  \\centering\n    \\includegraphics[width=1.0\\textwidth]{./eps/converted/hymod}\n  \\caption{Structure of the HYMOD rainfall-runoff model.}\n  \\label{fig:hymod}\n\\end{figure}\n\\begin{tabular}{ll}\nwith:&\\\\\n$C_{max}$&Maximum storage of the watershed\\\\\n$b_{exp}$&Spatial variability of soil moisture capacity\\\\\n$Alpha$&Partitioning factor of excess rainfall into slow and quick flow\\\\\n$R_{s}$&Residence time of the slow tank\\\\\n$R_{q}$&Residence time of the quick tanks\\\\\n\\end{tabular}\n\nIn this section, we will use a multi-start simplex \\citep{neld-mead1965} to\noptimize the parameters of the HYMOD model. Specifically, we investigate whether\nthe objective function (SSR) of this model has local minima that may complicate\nthe use of local optimization methods such as Gauss-Newton, or\nLevenberg-Marquardt. To do this, 20 simplex runs are started from randomly\ndetermined starting points, which are iterated until convergence is achieved.\n\n\\smallq{First, have a look at the code of `Multistart\\_Simplex.m' in\n`./exercises/local-methods-hymod/'. As you can see, the code uses the built-in\nMATLAB function \\mcode{fminsearch}, which is an implementation of the simplex\nsearch algorithm. Run \\mcode{Multistart\\_Simplex} (it'll run for a few minutes).\nStore the output by copy-pasting screenshots into a PowerPoint presentation.}\n\n\\smallq{Do all the Simplex runs converge to the same point in the parameter\nspace?}\n\n\\smallq{What does this tell you about the presence of local minima?}\n\n\\smallq{For the slug injection test, we visualized the response surface. Can we\nmake a similar figure here?}\n\n\\smallq{When you look at the results of the simulations with optimized\nparameters, why do you see just 3 or 4 time series and not 20?}\n\n\\smallq{How do you value the results of the various models?}\n\n\\smallqo{In the previous exercise, a relatively short data set (3 months) was\nused to calibrate HYMOD. Extend the calibration period to 12 months by changing\nthe values of \\mcode{Extra.calPeriod} in  \\mbox{`Multistart\\_Simplex.m'} and run\nthe optimization again.}\n\n\\smallqo{For this new subset of data, why did the number of local minima\nincrease or decrease?}\n\n\\smallqo{What is the quality of the model runs corresponding to the local\nminima?}\n\n\\smallqo{If we discard the poor models, can you give an interpretation why these\nlocal minima occurred?}\n\n\n\n\n\n\\section{Global methods: Differential Evolution}\n\n\nDifferential Evolution~\\citep{stor-pric1997} is a basic global optimization\nalgorithm that uses a population of points in the parameter space to find the\nglobal maximum (minimum, if appropriate) of an objective function. Generally\nspeaking, the population's properties are used to generate more points in those\nparts of the parameter space which are most promising with regard to yielding\nthe global optimum.\n\n\\smallq{Use the MATLAB editor to open\n`./exercises/differential-evolution/respsurf.m'. This script contains a few\nlines of code to help you get started on your algorithm. Run the script to\nvisualize the response surface for the benchmark function `6' (Shifted\nRosenbrock's  Function) for \\mcode{x = [65:0.1:80]} and \\mcode{y = [35:0.1:45]}\n(Figure~\\ref{fig:respsurf-rosenbrock}).}\n\\begin{figure}[htbp]\n  \\centering\n    \\includegraphics[width=1.0\\textwidth]{./eps/converted/respsurf-rosenbrock}\n  \\caption{Response surface for the shifted Rosenbrock function.}\n  \\label{fig:respsurf-rosenbrock}\n\\end{figure}\n\nThe \\mcode{benchmark_func} function offers not just 1, but 25 functions that can\nbe visualized in the same way as you already did for the Rosenbrock function.\nYou can choose different functions by changing the \\mcode{funcFlag}. Each\nfunction has its own limits on the parameter space (see\nTable~\\ref{tab:benchmark-func-data}).\n\n\\begin{table}[t]\n\\centering\n\\scriptsize\n\\begin{tabular}{lp{9cm}l}\n\\mcode{funcFlag}&\\textbf{description}&\\textbf{limits}\\\\\n\\multicolumn{3}{l}{Unimodal Functions (5):}\\\\\n1  &Shifted Sphere Function                                                              & [-100,100]\\\\\n2  &Shifted Schwefel's Problem 1.2                                                       & [-100,100]\\\\\n3  &Shifted Rotated High Conditioned Elliptic Function                                   & [-100,100]\\\\\n4  &Shifted Schwefel's Problem 1.2 with Noise in Fitness                                 & [-100,100]\\\\\n5  &Schwefel's  Problem 2.6 with Global Optimum on Bounds                                & [-100,100]\\\\\n\\multicolumn{3}{l}{Multimodal Functions (20):}\\\\\n\\multicolumn{3}{l}{Basic Functions (7):}\\\\\n6  &Shifted Rosenbrock's Function                                                        & [-100,100]\\\\\n7  &Shifted Rotated Griewank's Function without Bounds                                   & [0,600]\\\\\n8  &Shifted Rotated Ackley's Function with Global Optimum on Bounds                      & [-32,32]\\\\\n9  &Shifted Rastrigin's Function                                                         & [-5,5]\\\\\n10  &Shifted Rotated Rastrigin's  Function                               & [-5,5]\\\\\n11  &Shifted Rotated Weierstrass Function                                & [-0.5,0.5]\\\\\n12  &Schwefel's  Problem 2.13                                            & [-100,100]\\\\\n\\multicolumn{3}{l}{Expanded Functions (2):}\\\\\n13  &Expanded Extended Griewank's  plus Rosenbrock's  Function (F8F2)                    & [-3,1]\\\\\n14  &Expanded Rotated Extended Scaffe's  (F6)                                & [-100,100]\\\\\n\\multicolumn{3}{l}{Hybrid Composition Functions (11):}\\\\\n15  &Hybrid Composition Function 1                                       & [-5,5]\\\\\n16  &Rotated Hybrid Composition Function 1                               & [-5,5]\\\\\n17  &Rotated Hybrid Composition Function 1 with Noise in Fitness                     & [-5,5]\\\\\n18  &Rotated Hybrid Composition Function 2                               & [-5,5]\\\\\n19  &Rotated Hybrid Composition Function 2 with a Narrow Basin for the Global Optimum    & [-5,5]\\\\\n20  &Rotated Hybrid Composition Function 2 with the Global Optimum on the Bounds         & [-5,5]\\\\\n21  &Rotated Hybrid Composition Function 3                           & [-5,5]\\\\\n22  &Rotated Hybrid Composition Function 3 with High Condition Number Matrix         & [-5,5]\\\\\n23  &Non-Continuous Rotated Hybrid Composition Function 3                        & [-5,5]\\\\\n24  &Rotated Hybrid Composition Function 4                               & [-5,5]\\\\\n25  &Rotated Hybrid Composition Function 4 without Bounds                            & [-2,5]\\\\\n\\end{tabular}\n\\caption{}\n\\label{tab:benchmark-func-data}\n\\end{table}\n\n\\smallq{Experiment with different functions to get some idea of what their\nresponse surfaces look like.}\n\n%\\hspace*{0.01mm}\n%\\vfill\n%\\hspace*{0.01mm}\n\n\n\\needspace{8\\baselineskip}\nIn the next few exercises, you will write your differential evolution algorithm.\nWe will take you through the following basic steps (see also\n\\textsf{Fig.~\\ref{fig:diff-evo-principle}} and \\textsf{Code\nSnippets~\\ref{list:generating-uniform-random-sample}} and\n\\textsf{\\ref{list:generating-proposals}}):\n\\begin{enumerate}\n\\item{generate the initial sample;}\n\\item{assign the initial sample to a new array \\mcode{parents};}\n\\item{for each sample in \\mcode{parents}, calculate the corresponding objective\nscore;}\n\\item{use \\mcode{parents} to calculate new \\mcode{proposals};}\n\\item{for each sample in \\mcode{proposals}, calculate the corresponding objective\nscore;}\n\\item{accept either a sample from \\mcode{proposals} or the corresponding sample\nfrom \\mcode{parents} as the child, thus making an array \\mcode{children} of the\nsame size as \\mcode{parents};}\n\\item{assign \\mcode{children} to \\mcode{parents} for the next generation, and go\nback to step 4.}\n\\end{enumerate}\n\n\\begin{figure}[htbp]\n  \\centering\n    \\includegraphics[width=1.0\\textwidth]{./eps/converted/diff-evo-principle}\n  \\caption{Differential evolution in a nutshell, using a population of\n  \\texttt{nPop = 10} to avoid cluttering the figures. \\textbf{A}:~Generation of\n  the initial sample. \\textbf{B}:~Generation of proposal points.\n  \\textbf{C}:~Accepting either a sample from \\texttt{parents} or from \n  \\texttt{proposals} as a row in \\texttt{children}. \\textbf{D}:~The \n  \\texttt{children} from one generation are the \\texttt{parents} for the\n  next generation.}\n  \\label{fig:diff-evo-principle}\n\\end{figure}\n\n\\lstinputlisting[float=ht,caption={Generating samples drawn from a uniform\ndistribution spanning the parameter\nspace.},label=list:generating-uniform-random-sample]{./m/snippet-diff-evo-generating-uniform-random-sample.m}\n\n\\lstinputlisting[float=ht,caption={Generating proposal points given a parent\npopulation.},label=list:generating-proposals]{./m/snippet-diff-evo-generating-proposal-points.m}\n\n\n\\smallq{As a first step, save your \\mcode{respsurf} script under a new name\n`runDiffEvo.m'.}\n\n\\smallq{Extend `runDiffEvo.m' by creating an array \\mcode{parents}, which has\n\\mcode{nPop=50} rows, each of which represents a uniform random sample from the\nparameter space (see also \\textsf{Code\nSnippet~\\ref{list:generating-uniform-random-sample}}). \\mcode{parents} has\n\\mcode{nDims+1} columns, i.e. the number of dimensions for which you want to\nsolve \\mcode{benchmark_func} plus one column to store the objective score. Refer\nto Table~\\ref{tab:benchmark-func-data} for the parameter space limits. For now,\nstick with \\mcode{nDims=2} and \\mcode{funcFlag=6}, but you can change that\nlater.}\n\n\\smallq{Calculate the last column of \\mcode{parents} by running the objective\nfunction for each row.}\n\n\\smallq{Generate the \\mcode{proposals} array (same size as \\mcode{parents}). To\ndo this, select the first sample from \\mcode{parents}, as well as three other\nsamples (\\mcode{r1}, \\mcode{r2}, \\mcode{r3}), chosen at random from\n\\mcode{parents} (MATLAB's built-in function \\mcode{randperm} can be useful for\nthis; see \\textsf{Code Snippet~\\ref{list:generating-proposals}}). The proposal\nis calculated as the position of the parent + F*\\mcode{dist1} + K*\\mcode{dist2},\nin which  \\mcode{dist1} is the distance between the parent and \\mcode{r1},\n\\mcode{dist2} is the distance between \\mcode{r2} and \\mcode{r3}, and F and K are\nsettings that are part of the Differential Evolution algorithm. In the\nliterature, F=0.6 and K=0.4 are common. Repeat for all samples in\n\\mcode{parents}.}\n\n\\smallq{For each member in \\mcode{proposals}, calculate the objective score.}\n\n\\smallq{Determine whether to choose the $i^{th}$ sample of \\mcode{parents} or\nthe $i^{th}$ sample of \\mcode{proposals}, depending on which one has a better\nobjective score. Assign to the $i^{th}$ row in a new array \\mcode{children}.}\n\n\\smallq{Assign \\mcode{children} to \\mcode{parents} for the next generation.}\n\n\\smallq{Wrap most of the above steps in a \\mcode{for} loop, such that your\nscript will repeatedly generate new (and hopefully better) children for 250\ngenerations.}\n\n\\smallq{It's a little bit difficult to see if your script is doing what it is\nsupposed to be doing, so you need to do some visualization. Copy and paste from\n`vis-helper.txt' to create a figure similar to Figure~\\ref{fig:diffevo-result}.}\n\n\\begin{figure}[htbp]\n  \\centering\n    \\includegraphics[width=1.0\\textwidth]{./eps/converted/diffevo-result}\n  \\caption{Visualization results for the Shifted Rosenbrock function after 250\n  generations of 50 samples each, optimized using the Differential Evolution\n  algorithm.}\n  \\label{fig:diffevo-result}\n\\end{figure}\n\n\\smallq{During the optimization, you may notice that there are some points that\nare really persistent, even though they are well away from the global optimum.\nExplain why these points are so persistent.}\n\n\\smallq{The histogram in Figure~\\ref{fig:diffevo-result} is bimodal. How does\nthat relate to the answer to the previous question?}\n\n\n\n\n\n\n\\section{Differential Evolution with Metropolis}\n\nOver the next few exercises, you will add Metropolis acceptance to your\nDifferential Evolution optimization, such that it can be used to quantify parameter\nuncertainty.\n\n\\smallqo{Clean up `runDiffEvo.m' and save it as `runDiffEvoMetro.m'. You will be\nmaking your edits in the latter script.}\n\nThe benchmark functions that we have been using so far do not represent\nprobability density functions, so they are not suited to demonstrate the\nMetropolis scheme. So instead we'll use a benchmark function of our own:\n`doublegauss.m'. This function takes one argument, \\texttt{x}, and calculates\nthe probability density at that value of \\texttt{x} by adding two Gaussian\nprobability density distributions:\n\n\\begin{align}\n\\label{eq:double-normal} \np = \\frac{1}{2}\\cdot{}\\frac{1}{\\sqrt{2\\pi\\sigma_1^2}}\\:e^\\mathlarger{-\\frac{1}{2}\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2} & +\\dots \\\\ \\nonumber\n    \\frac{1}{2}\\cdot{}\\frac{1}{\\sqrt{2\\pi\\sigma_2^2}}\\:e^\\mathlarger{-\\frac{1}{2}\\left(\\frac{x-\\mu_2}{\\sigma_2}\\right)^2}\n\\end{align}\n\nwith $\\mu_1 = -10$, $\\sigma_1 = 3$, $\\mu_2 = 5$, $\\sigma_2 = 1$, respectively.\n$x$ is the only parameter that is optimized; as an example, for $x=4.5$, $p =\n0.1760$ (See Fig.~\\ref{fig:diffevo-metro-result}C).\n\n\\smallqo{Replace any calls to \\texttt{benchmark\\_func} with calls to\n\\texttt{doublegauss}. You don't need to supply any other arguments besides\n\\texttt{parVec}. Set the population size to 200 and configure the algorithm to\nrun for 100 generations. Constrain the parameter space to $[-20,20]$ and make\nsure to adjust the number of dimensions.}\n\nScroll down to where `runDiffEvoMetro.m' accepts either a member from\n\\texttt{parents} or a member from \\texttt{proposals} as a member of\n\\texttt{children}. Currently, the proposal will only be accepted when it is\nbetter than the parent. In contrast, the Metropolis acceptance scheme is\ncrucially different in that it will \\textit{sometimes} accept a proposal parameter\ncombination that is actually \\textit{worse} than the parent. \n\n\\needspace{15\\baselineskip}\nYou will use the following rules for Metropolis acceptance:\n\\begin{itemize}\n    \\item{if the proposal is better than the parent, accept the proposal as the\n    child;}\n    \\item{if the proposal is worse than the parent, calculate \\texttt{alfa} as the\n    proposal/parent ratio. Next, draw a random number \\texttt{Z}\n    from the [0,1] interval using a uniform distribution.}\n    \\begin{itemize}\n        \\item{if \\texttt{alfa} is greater than \\texttt{Z}, accept the proposal;}\n        \\item{otherwise, re-accept the parent.}\n    \\end{itemize}\n\\end{itemize}\n\nThe nice property of Metropolis acceptance is that the frequency with\nwhich points get accepted is proportional to their probability (provided that\nyou have sampled long enough for the parameter distribution to become stable).\nWe will use this later to calculate the confidence interval associated with the\nprediction.\n\n\\smallqo{Adapt the acceptance scheme in `runDiffEvoMetro.m' in accordance with\nthe Metropolis rules and run the script.}\n\n\\smallqo{Adapt your script in such a way that it stores the entire array\n\\texttt{parents} for each generation in a new array \\texttt{evalResults}. Note\nthat \\texttt{evalResults} has \\texttt{nPop*nGenerations} rows and\n\\texttt{nDims+1} columns and that it can be preallocated with \\mcode{NaN} values\nusing MATLAB's built-in \\mcode{repmat} function.}\n\n\\smallqo{Visualize the information from \\texttt{evalResults} in a similar\nfashion as in Fig.~\\ref{fig:diffevo-metro-result}.}\n\n\\begin{figure}[htbp]\n  \\centering\n    \\includegraphics[width=1.0\\textwidth]{./eps/converted/diffevo-metro-result}\n    \\caption{\\textbf{A}:~20000 samples of the parameter space, as taken by the\n    Differential Evolution Metropolis algorithm. \\textbf{B}:~A histogram of all\n    samples. The histogram serves as an approximation of the true distribution\n    from Fig.~\\ref{fig:diffevo-metro-result}C. \\textbf{C}:~The true\n    distribution. \\textbf{D}:~The objective scores associated with each sample.}\n  \\label{fig:diffevo-metro-result}\n\\end{figure}\n\n", "meta": {"hexsha": "eebb66951d3c82e1fa34e0f1a05a3f9cdb8e5bfb", "size": 20436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "syllabus/tex/chapters/getting-started.tex", "max_stars_repo_name": "jspaaks/inverse-modeling-2017", "max_stars_repo_head_hexsha": "f60bc1848734c3560c7e6051216bb49b35535f48", "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": "syllabus/tex/chapters/getting-started.tex", "max_issues_repo_name": "jspaaks/inverse-modeling-2017", "max_issues_repo_head_hexsha": "f60bc1848734c3560c7e6051216bb49b35535f48", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-02-21T09:45:01.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-22T08:47:56.000Z", "max_forks_repo_path": "syllabus/tex/chapters/getting-started.tex", "max_forks_repo_name": "jspaaks/inverse-modeling-2017", "max_forks_repo_head_hexsha": "f60bc1848734c3560c7e6051216bb49b35535f48", "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.9235955056, "max_line_length": 143, "alphanum_fraction": 0.7308670973, "num_tokens": 5621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694177, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6858403505317633}}
{"text": "% file: equal.tex\n\n\\section{DH Problem 5.9: $\\equal(S_1, S_2)$~\\cite{DH}}  \\label{section:problem-5.9}\n  Construct a function $\\equal(S_1, S_2)$ that tests whether the strings $X$ and $Y$ are equal.\n  It should return true or false accordingly.\n\n  You may use the following operations:\n  \\begin{itemize}\n    \\item $\\texttt{head}(X)$\n    \\item $\\texttt{tail}(X)$\n    \\item $\\texttt{last}(X)$\n    \\item $\\texttt{all-but-last}(X)$\n    \\item $\\texttt{eq}(s,t)$\n  \\end{itemize}\n%%%%%%%%%%%%%%%%%%%%\n\\subsection{Solution}\n\nThe algorithm $\\equal(S_1, S_2)$ is shown in Algorithm~\\ref{alg:equal},\nwith appropriate assertions attached.\n\nThe partial correctness of $\\equal$ can be denoted as\n\\marginnote{We are using the notations of Hoare logic developed by Tony Hoare.}\n\n\\begin{marginfigure}%\n  \\includegraphics[width=0.60\\linewidth]{figs/tony-hoare}\n  \\label{fig:hoare}\n\\end{marginfigure}\n\n\\marginnote{\\cite{Hoare:CACM69}}\n\n\\[\n  P \\;\\set{\\equal}\\; Q,\n\\]\nmeaning that if the input satisfies the precondition $P$\nand the algorithm $\\equal$ eventually terminates,\nthen the postcondition $Q$ must hold.\nTo this end, we show that:\n\n\\input{algs/equal}\n\n\\begin{enumerate}[(i)]\n  \\item $I$ is a loop invariant. That is,\n    \\[\n      P \\;\\set{\\texttt{Lines~\\ref{line:init-begin}--\\ref{line:init-end}}}\\; I\n    \\]\n    \\[\n      \\big(I \\land (X \\neq \\epsilon \\land Y \\neq \\epsilon \\land E = \\top)\\big) \\;\\set{\\texttt{Lines~\\ref{line:while-begin}--\\ref{line:while-end}}}\\; I\n    \\]\n  \\item $(2)$ is an invariant. It suffices to show that $(2)$ can be derived from\n    \\marginnote{This is a rather formal way. Be patient.}\n    \\renewcommand{\\theequation}{\\alph{equation}}\n    \\setcounter{equation}{0}\n    \\begin{gather}\n      I \\land \\lnot (X \\neq \\epsilon \\land Y \\neq \\epsilon \\land E = \\top) \\nonumber\\\\\n      = I \\land (X = \\epsilon \\lor Y = \\epsilon \\lor E = \\bot) \\nonumber\\\\ \n      = \\big(I \\land (X = \\epsilon)\\big) \\lor \\big(I \\land (Y = \\epsilon)\\big) \\lor \\big(I \\land (E = \\bot)\\big) \\label{eq:1st}\n    \\end{gather}\n    in propositional logic by showing that each disjunct of (\\ref{eq:1st}) implies $(2)$.\n\n    Consider the first disjunct\n    \\renewcommand{\\theequation}{\\alph{equation}1}\n    \\setcounter{equation}{0}\n    \\begin{gather}\n      I \\land (X = \\epsilon) \\nonumber\\\\ \n      = (S_1 = S_2 \\iff X = Y \\land E = \\top) \\land (X = \\epsilon)  \\label{eq:1st-1st}\n    \\end{gather}\n    It is required to prove both \n    \\[\n      \\text{(\\ref{eq:1st-1st})} \\implies \\Big(S_1 = S_2 \\implies \\big((X = \\epsilon \\land Y = \\epsilon) \\land E = \\top \\big)\\Big)\n    \\]\n    and \n    \\[\n      \\text{(\\ref{eq:1st-1st})} \\implies \\Big(\\big((X = \\epsilon \\land Y = \\epsilon) \\land E = \\top \\big) \\implies S_1 = S_2 \\Big)\n    \\]\n    \\marginnote{Do you still remember how to prove an implication? What is the given? And what is the conclusion?\n    Furthermore, when you derive $(2)$ from the third disjunct, \n    keep in mind that \\emph{falsity implies everything}.}\n    Now it is your (YES, it is YOU) job! It is also your job to deal with the second and the third disjuncts in a similar way.\n\n    % \\renewcommand{\\theequation}{\\alph{equation}3}\n    % \\setcounter{equation}{0}\n    % \\begin{gather}\n    %   I \\land (E = \\bot) \\nonumber\\\\ \n    %   = (S_1 = S_2 \\iff X = Y \\land E = \\top) \\land (E = \\bot)  \\label{eq:1st-3rd}\n    % \\end{gather}\n  \\item (3.1) is an invariant. It suffices to show that\n    \\[\n      \\big((2) \\land \\lnot (X = \\epsilon \\land Y = \\epsilon) \\land E = \\bot\\big) \\implies (3.1).\n    \\]\n    Stop reading! Take your pencil and paper! \n    \\marginnote{\\emph{Writing is nature’s way of letting you know how sloppy your thinking is.} \\\\ \\hfill --- Richard Guindon (cartoon), 1989}\n    Write down your arguments to convince yourself that the formula above indeed holds.\n  \\item (3.2) is an invariant. It suffices to show that\n    \\[\n      \\big((2) \\land (X = \\epsilon \\land Y = \\epsilon)\\big) \\implies (3.2).\n    \\]\n    You already know how to prove this formula in propositional logic. Don't you?\n    We now show you a more intuitive way to reason about programs:\n\n    \\marginnote{It proceeds \\emph{semantically} rather than \\emph{syntactically} as we have done before.}\n    \\emph{At point (2), we know that $S_1 = S_2$ if and only if $(X = \\Lambda \\land Y = \\Lambda \\land E = \\top)$.\n    At point (3.2), we further know that $(X = \\Lambda \\land Y = \\Lambda)$. \n    Thus, at this point, we only need to check whether $E = \\top$ to decide whether $S_1 = S_2$ holds.}\n  \\item $Q$ is an invariant. It suffices to show that\n    \\[\n      \\big((3.1) \\implies Q\\big) \\land \\big((3.2) \\implies Q\\big).\n    \\]\n    It should be easy now for you to prove this formula.\n\\end{enumerate}\n", "meta": {"hexsha": "22c32cc999adb50dd8f1e497da8980a19e135b25", "size": 4669, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2017/2017-4th/4-0-sample/problems/equal.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/equal.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/equal.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": 42.4454545455, "max_line_length": 150, "alphanum_fraction": 0.6358963375, "num_tokens": 1568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.803173801068221, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.685840348582879}}
{"text": "\\problemname{Flight Plan Evaluation}\n\n%\\illustration{0.42}{sample1}{The second sample input}\nWhen flying between two places, constructing a good flight plan is\nimportant.  In general there is a wide range of different factors to\nconsider, the most important being fuel consumption and weather\nforecasts (especially winds).  In this problem, we will evaluate\nflight plans with respect to a third statistic, namely how much of the\nflight is over water, and how much is over ground.  This statistic is\nnot relevant per se, yet many passengers seem to prefer flying over\nland -- either because they are afraid of flying over water, or simply\nbecause the view tends to be slightly more interesting when flying\nover land.\n\nFor this problem, we assume that the earth is a perfect sphere with\nradius $6370$ km.  We model each continent of the earth as a polygon\non this sphere -- a closed sequence of line segments, where a line\nsegment between two points consists of the shortest spherical arc\nbetween these two points.  The two end-points of a line segment can\nnot be the same point, or antipodal (diametrically opposite) points.\nSimilarly a flight route is modeled as a sequence of waypoints\nconnected by line segments, but unlike the line segments of a polygon\nthese line segments may cross themselves and will not necessarily end\nup where they started.\n\n\\begin{figure}[!h]\n  \\centering\n  \\includegraphics[width=0.55\\textwidth]{sample1}\n  \\caption{The second sample input}\n\\end{figure}\n\nIn order to simplify the problem, we additionally make the following\ntwo assumptions:\n\\begin{itemize}\n\\item No waypoint of a flight route lies within $0.1$ km of any shoreline (a line segment that is part of a polygon).\n\\item No vertex of any continent polygon lies within $0.1$ km of the flight route.\n\\end{itemize} \n\nAll coordinates on the sphere are represented as a pair of latitude and\nlongitude (both in degrees).  A point with latitude $\\pm 90$ is the\nnorth/south pole, and points with latitude $0$ are the points on the\nequator.\n\n\\section*{Input}\n\nThe input consists of:\n\n\\begin{itemize}\n\\item one line with an integer $1 \\le c \\le 30$, the number of continents;\n\\item $c$ lines, each describing a continent. Each such line starts\n  with an integer $3 \\le n \\le 30$, the number of vertices in the\n  polygon describing the continent.  This is followed by $n$ pairs of\n  integers $\\phi_1, \\lambda_1, \\ldots, \\phi_n, \\lambda_n$, where $-90\n  \\le \\phi_i \\le 90$ and $0 \\le \\lambda_i \\le 359$ are the latitude and\n  longitude of the $i$th vertex of the continent;\n\\item one line describing the flight plan.  The line starts with an\n  integer $2 \\le m \\le 30$, the number of waypoints.  This is followed\n  by $m$ pairs of integers $\\phi_1, \\lambda_1, \\ldots, \\phi_m,\n  \\lambda_m$, where $-90 \\le \\phi_i \\le 90$ and $0 \\le \\lambda_i \\le\n  359$ are the latitude and longitude of the $i$th waypoint of the\n  route.\n\\end{itemize}\n\nA continent cannot cross itself.  No continent will touch or contain\nany other continent.  Continents are given in counterclockwise order,\nin the sense that\nif you go from the first vertex of the polygon to\nthe second one, the interior of the continent is on your left hand\nside.\n%if the first point of a continent is $P$, and the\n%second one is $Q$, then the interior of the continent is on the left\n%side when going from $P$ to $Q$.\n\nThe first and last waypoints of the route will always be inside a\ncontinent (but not necessarily the same continent).\n\n\\section*{Output}\n\nOutput two real numbers $l$ and $w$, where $l$ is\nthe total length of the flight (in km), and $w$ is the percentage of\nthe flight that is over water.  The numbers should be accurate to an\nabsolute or relative error of at most $10^{-6}$.\n", "meta": {"hexsha": "e8ffe14aacc99a80b0782dec5a4565b170efedb6", "size": 3723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/flightplanevaluation/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/flightplanevaluation/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/flightplanevaluation/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": 44.8554216867, "max_line_length": 117, "alphanum_fraction": 0.7587966694, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6858403425482954}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\usepackage{subcaption}\n\\begin{document}\n\t\n\t\\title{Introduction to Circuitry}\n\t\\author{}\n\t\n\t\\maketitle\n\t\n\t\\begin{abstract}\n\tIn this article we will take a look at the \\textit{rms} value of an AC signal and when it's used.\n\tSubsequently we'll start writing software code that represent electrical signals in a software program.\n\n\t\\end{abstract}\n\t\n\t\\section{Root mean square}\n\tRoot mean square for a set of discrete numbers, which is commonly called by it's abbreviation \\textbf{rms} is defined as:\n\t\n\t$$ X_{rms} = \\sqrt{\\frac{1}{n}(x_1^2 + x_2^2 + x_3^2 + ... + x_n^2 )} $$\n\n\t\\textbf{ex.} Calculate the \\textit{rms} of numbers $4$, $5$, $2$ and $7$.\n\t\n\t\\textbf{ans.} $$ X_{rms} = \\sqrt{\\frac{1}{4}(4^2 + 5^2 + 2^2 + 7^2)} \\approx 4.847 $$\n\t\n\tWe've seen the definition of \\textit{rms} for the cases that we have some discrete numbers.\n\tIf we had a continuous function instead, we'd use the following definition:\n\t\n\t$$ f_{rms} = \\sqrt{\\frac{1}{T_2 - T_1} \\int_{T_1}^{T_2} [f(dx)]^2 dx } $$\n\t\n\t\\textbf{ex.} Calculate the \\textit{rms} of function $f(x) = x^3$ from $x = 1$ to $x = 4$.\n\t\n\t\\textbf{ans.} Plugging it into formula:\n\t\n\t$$ f_{rms} = \\sqrt{\\frac{1}{1 - 4} \\int_{1}^{4} [x^3]^2 dx } \\approx 27.9 $$\n\n\t\\subsection{When do we use rms?}\n\tWhen the source of electrical power in not a fixed DC value and it's alternating over time, how would we calculate the \\textit{average power} consumed by a resistive element? From the formula of power we have:\n\t\n\t$$P(t) = I(t).V(t)$$\n\n\tWe also know from Ohm's law that $I(t) = \\frac{V(t)}{R}$, therefore substituting it into the formula we get:\n\t\n\t$$P(t) = \\frac{V(t)^2}{R}$$\n\t\n\tThis formula gives the power at each point in time.\n\tSince $V(t)$ is alternating, the power varies over time as well and doesn't have a fixed value.\n\tSo to calculate the \\textit{average} power we should use integral for this.\n\t\n\t$$P_{avg} = \\frac{1}{R}.\\frac{\\int_{T_0}^{T_1} V(t)^2 dt }{T_1 - T_0}$$\n\t\n\tThis is all we need for calculating the average power.\n\tHowever if we take the integral term (with it's denominator $T_1 - T_0$) and take it's square root, it turns into the \\textit{rms} value we defined earlier.\n\t\n\t$$V_{rms} = \\sqrt{\\frac{\\int_{T_0}^{T_1} V(t)^2 dt }{T_1 - T_0}} $$\n\t\n\tNow by having this value, to calculate the average power we should reverse the effect of taking the square root by raise it to power of $2$ (and division by resistivity $R$):\n\t\n\t$$ P_{avg} = \\frac{V^2_{rms}}{R} $$\n\t\n\tWhy do we take the square root of an expression just to raise it to the power of $2$ later?\n\tBecause if we somehow know the $V_{rms}$ of an AC signal, we would use the \\textit{same} formula for calculating average power as if we had a fixed DC voltage over time ($P_{avg} = \\frac{V^2_{dc}}{R}$); Namely raising it to power of $2$ then dividing it by $R$.\n\tSo \\textit{rms} value of a voltage or current is a convenient way to describe an AC signal besides its peak value and frequency that we would normally do.\n\t\n\tWhen we're speaking about AC signals, we are most likely dealing with \\textit{Sinusoidal} AC signals. \n\tSo let's investigate and see if the \\textit{rms} of a general sinusoidal AC signal yields anything constant. \n\tIf so, then we'd omit the whole integration process every time we want to calculate the \\textit{rms} of a sinusoidal signal and simply multiply that constant by some term.\n\t\n\tGeneral sinusoidal function has the following form in one cycle:\n\t\n\t$$ V(t) = V_{Max} \\sin(\\omega t) $$\n\t\n\tPlugging it into the definition of \\textit{rms},\n\t\n\t$$V_{rms} = \\sqrt{\\frac{\\int_{T_0}^{T_1} (V_{Max} \\sin \\omega t) ^ 2 dt} {T_1 - T_0}}$$\n\t\n\t$V_{Max}$ is just a constant and goes out of the square root. So we get:\n\t\n\t$$V_{rms} = V_{Max} \\sqrt{\\frac{\\int_{T_0}^{T_1} (\\sin \\omega t) ^ 2 dt }{T_1 - T_0}}$$\n\t\n\tWe also know from basic properties of trigonometric functions:\n\t\n\t$$ \\sin^2 x = \\frac{1 + \\cos 2x}{2} $$\n\t\n\tSubstituting the sine term with this property:\n\t\n\t\\begin{align} \n\tV_{rms} = V_{Max} \\sqrt{\\frac{1}{{T_1 - T_0}}{\\int_{T_0}^{T_1} \\frac{1 + \\sin \\omega t dt}{2}}} = \\\\\n\t V_{Max} \\sqrt{\\frac{1}{T_1 - T_0} \\left[ \\frac{t}{2} - \\frac{\\sin 2 \\omega t}{4 \\omega}\\right]_{T_0}^{T_1} }\n\t\\end{align}\n\t\n\tNow since the range $T_0$ to $T_1$ is one period of the sinusoidal function, the sine integral is just $0$. Therefore:\n\t\t\n\t\\begin{equation}\n\t\\begin{gathered}\n\tV_{rms} = V_{Max} \\sqrt{\\frac{1}{T_1 - T_0} \\left[ \\frac{t}{2} \\right]_{T_0}^{T_1}} = \\\\\n\tV_{Max}\\sqrt{\\frac{1}{T_1 - T_0} . \\frac{T_1 - T2}{2}} = \\\\\n V_{Max} \\frac{1}{\\sqrt{2}}\n\t\\end{gathered}\n\t\\end{equation}\n\n\tWhich proves that for calculating the \\textit{rms} of a sinusoidal signal, we can skip the integration process and simply divide its peak value by $\\sqrt{2}$.\n\n\t\n\t\\section{Representing electrical signals in software}\n\tBefore continuing with the more advanced EE concepts, let's implement the ideas we discussed so far in form of a software package.\n\tWe would therefore use these implementations readily in the future articles and projects as well.\n\tWe use the C++ language to write these constructs since it is widely used in microcontroller and system programming; And also supports advanced language features and paradigms.\n\t\n\tOne of the fundamental concepts that we would want to implement, is a construct that would represent an \\textit{electrical signal} in our programs.\n\tThis idea can be implemented conveniently with OOP\\footnote[1]{Object Oriented Programming} paradigm; i.e. if we have a \\textit{class} that represents the type of a signal in our program, instantiating it with:\n\t\n\t\\begin{verbatim}\n\t\tSignal s(<function_body>);\n\t\\end{verbatim}\n\t \n\tWould capture the signal's function, and with the appropriate definition of our class this instance $s$ would readily contain all the frequently used operations such as calculating its $rms$ and etc. \n\tHence:\n\t\n\t\\begin{verbatim}\n\ts.getRms()\n\t\\end{verbatim}\n\n\tWould return the function's \\textit{rms} or:\n\t\t\n\t\\begin{verbatim}\n\ts.fourierTransform()\n\t\\end{verbatim}\n\n\tWould apply Fourier transform on our signal (an important math operation that we will discuss in later articles) and so on.\n\t\t\n\tLet's start by defining the base class:\n\t\n\t\\begin{verbatim}\n\t#include <cmath>\n\t#include <functional>\nclass Signal {\nprotected:\n    using rftype =  std::function<double(double)>;\n    rftype function;\npublic:\n    Signal(rftype f): function(f) {}\n    double output(double x) { return function(x); }\n    rftype getFunction() {return function; }\n};\n\t\\end{verbatim}\n\tThis class can be used as:\n\t\n\t\\begin{verbatim}\nSignal s([](double t) {return t*t;});\nstd::cout << s.output(3) << '\\n';\nstd::cout << s.output(0.4) << '\\n';\n\t\\end{verbatim}\n\tRunning the program we get:\n\t\n\t\\begin{verbatim}\n9\n0.16\n\t\\end{verbatim}\n\t\n\tAs we see, the object $s$ can now represents a signal in our program.\n\tFor now, writing $s.output(x)$ gives the signal's output at time $x$ and $s.getFunction()$ returns the signal's function definition if we needed somewhere in our program.\n\t\t\n\tFew remarks here:\n\t\n\t1. We included the header \\textbf{functional} to make the type \\textit{std::function} available in our program. With this type we captured the function's body in the constructor.\n\n\t2. We defined a type alias for a real-valued math function that have real-valued inputs and outputs ($\\Re\\rightarrow\\Re$). We called this alias \\textbf{rftype} for \\textit{\\textbf{r}eal-valued \\textbf{f}unction \\textbf{type}.}\n\t\n\t3. We declared the member variable $function$, as a protected member because later on we want to derive more specific types of signal namely DC, AC and Sinusoidal AC from this class.\n\t \n\tNow let's move on to defining derived classes. The first one is for the DC signals which has a straightforward definition.\n\t\n\t\\begin{verbatim}\nclass DcSignal: public Signal {\npublic:\n    DcSignal(double dcValue): Signal([dcValue](double t) -> double {\n        return dcValue;\n    }){}\n};\n\t\\end{verbatim}\n\t\n\tIt can be used as:\n\t\n\t\\begin{verbatim}\n\tDcSignal s(4);\n\t\\end{verbatim}\n\t\n\tFor AC signal class:\n\t\\begin{verbatim}\nclass AcSignal: public Signal {\npublic:\n    AcSignal(rftype func, double p): Signal([func,p](double t) -> double {\n        if(std::abs(t) <= std::abs(p)) return func(t);\n        else return func(t - (int)(t/p) * p);\n    }), f(1/p), p(p){}\n\t\t\n    double getRms() {\n        return std::sqrt(1/p * numerical_integration(function, 0, p));\n    }\n\t\t\n    double getFrequency() { return f; }\n    double getPeriod() { return p; }\nprotected:\n    double f, p;\n};\n\t\\end{verbatim}\n\n\tThis class is also straightforward.\n\tIt's constructor accepts a function and period in which the function would repeat after that point.\n\tNote that in $getRms$ we uses \\textit{numerical\\_integration} for estimating the definite integral. \n\tThis function can be implemented in various ways. \n\tA quick one is to use the trapezoidal method:\n\t\n\t\\begin{verbatim}\ndouble numerical_integration(std::function<double(double)> f,\n                      double a, double b, double N = 10000) {\n    double h = (b - a) / N;\n    double tmp = 0;\n    tmp += f(a);\n    tmp += f(b);\n    while(a < b) {\n        tmp += 2 * f(a);\n        a += h;\n    }\n    return (h/2)*tmp;\n}\n\t\\end{verbatim}\n\tExample usage of \\textit{AcSignal}:\n\t\n\t\\begin{verbatim}\nAcSignal s([](double t) {return t*t;}, 2);\ncout << s.output(0.5) << '\\n';\ncout << s.output(2.5) << '\\n';\n\t\\end{verbatim}\n\t\n\tProduces:\n\t\n\t\\begin{verbatim}\n0.25\n0.25\n\t\\end{verbatim}\n\n\tNow let's define a class that we'd likely use the most: Sinusoidal signals. \n\tSince this class is a type of AC signal and it's periodic, we derive it from the \\textit{AcSignal}.\n\t\n\t\\begin{verbatim}\nclass SinusoidalAcSignal: public AcSignal {\npublic:\n    SinusoidalAcSignal(double amplitude, double frequency,\n                       double phase = 0):\n     AcSignal([amplitude, frequency, phase](double t) -> double {\n     return amplitude * std::sin(t*2*3.14159268*frequency + phase);\n    }, 1/frequency), a(amplitude) {}\n\n    double getRms() { return a/std::sqrt(2); }\n\n    double getAmplitude() { return a; }\nprivate:\n    double a;\n};\n\t\\end{verbatim}\n\n\t(The definition of these classes are presented in a single file inside this article's directory.)\n\t\n\tWe have now defined some boilerplate classes that we'd use in situations such as when we want to generate some sinusoidal signal for an output pin of a microcontroller.\n\tFor another example when we want to simulate an input signal for analyzing circuits with a software.\n\t\t\n\t\\section{What's Next?}\n\tIn the follow up article, we will discuss some concepts behind AC circuit analysis; Namely phasor diagrams and complex number representation.\n\t\n\tThese documents are published under an open license (see the project's root directory for more info), and were intended to be part of an open and a collaborative project.\n\tFeel free to fork this document, send pull request and also give your feedback. \n\tThanks for reading!\n\\end{document}\n", "meta": {"hexsha": "1e32c0b839a3eede40d78335745a994397606027", "size": 10899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3_Rms_value/rms_and_boilerplate_cpp_classes.tex", "max_stars_repo_name": "DigitalNX/docs", "max_stars_repo_head_hexsha": "7bf9ca4ae054cd0816f45da67dff96000600420f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-01-16T19:10:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:10:55.000Z", "max_issues_repo_path": "3_Rms_value/rms_and_boilerplate_cpp_classes.tex", "max_issues_repo_name": "DigitalNX/docs", "max_issues_repo_head_hexsha": "7bf9ca4ae054cd0816f45da67dff96000600420f", "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": "3_Rms_value/rms_and_boilerplate_cpp_classes.tex", "max_forks_repo_name": "DigitalNX/docs", "max_forks_repo_head_hexsha": "7bf9ca4ae054cd0816f45da67dff96000600420f", "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.2050359712, "max_line_length": 262, "alphanum_fraction": 0.6941921277, "num_tokens": 3217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825006, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.6857282484008324}}
{"text": "\\documentclass[12pt, letterpaper, preprint]{aastex} \n\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\newcommand{\\tmin}[1][]{t_{\\mathrm{min} #1}}\n\\newcommand{\\tmax}[1][]{t_{\\mathrm{max} #1}}\n\\newcommand{\\amin}{a_{\\mathrm{min}}}\n\\newcommand{\\amax} {a_{\\mathrm{max}}}\n\n\\newcommand{\\dlt}{\\Delta\\log t_i}\n\\newcommand{\\dt}{\\Delta t_i}\n\n\\newcommand{\\tintegral}{\\int_{\\tmin[,i]}^{\\tmax[,i]} dt}\n\\newcommand{\\tinterval}{\\right|_{\\tmin[,i]}^{\\tmax[,i]}}\n\\newcommand{\\clip}[3][]{{#1}_{\\top {#2}}^{\\bot {#3}}}\n\n\\newcommand{\\sftrunc}{T_{\\mathrm{trunc}}}\n\\newcommand{\\tage}{t_{\\mathrm{age}}} \n\\newcommand{\\sfzero}{T_{\\mathrm{zero}}}\n\\newcommand{\\tzero}{t_{\\circ}}\n\\newcommand{\\sfslope}{m_{\\mathrm{SF}}} \n\n\n\\begin{document}\n\\author{B. Johnson}\n\n%\\begin{center}\n%\\today\n%\\end{center}\n\n\\section{Introduction}\nThroughout this document we use lowercase $t$ to refer to lookback times (or SSP ages), and capital $T$ to refer to time since the start of star formation.\n\nWe wish to find the proper weighting of discrete SSPs to reproduce the spectrum $F$ from SFR occurring within some bin of  lookback times $(\\amin, \\amax)$.\nWe approximate the spectrum $f(t)$ at any lookback time $t$ as a linear interpolation of the (total stellar mass normalized) spectra $f_i$ at the discrete SSP lookback times $t_i$, for $i=1,...,N$ \n\\begin{eqnarray}\nF & = & \\int_{\\amin}^{\\amax} dt \\, f(t) \\, SFR(t) \\nonumber \\\\\nf(t) & = & w_{i}(t) \\, f_i + w_{i+1}(t) \\, f_{i+1} \\, , \\quad t_i < t < t_{i+1}  \\nonumber \\\\\nw_{i}(t) & = & \\frac{t_{i+1} - t}{t_{i+1}  - t_i} \\nonumber \\\\\nw_{i+1}(t) & = & 1 - w_i(t) \\quad . \\nonumber\n\\end{eqnarray}\nThen we can write the \\emph{total} contribution of SSP $i$ to the total spectrum as a sum of the integrated weight due to SF in the sub-bin to the ``right'' (higher lookback times) and the  sub-bin to the ``left'' (lower lookback times).\nThe sub-bins are defined by the spacing of the SSP $t_i$ values. \nThe limits of each integral are determined either by the spacing of the SSP points $t_i$ or, when the bin does not completely span the sub-bin, by the $\\amin$ and/or $\\amax$ values.\n\\begin{eqnarray}\nW_i & = &  \\int_{\\amin}^{\\amax} dt \\, \\mathrm{SFR}(t) \\, w_i(t) \\nonumber \\\\\n & = & W_{i, \\mathrm{right}} + W_{i, \\mathrm{left}} \\nonumber \\\\\nW_{i, \\mathrm{right}} & = & \\tintegral \\, \\mathrm{SFR}(t) \\, \\frac{t_{i+1} - t}{t_{i+1}  - t_i} \\nonumber \\\\\nW_{i, \\mathrm{left}} & = & \\int_{\\tmin[,i-1]}^{\\tmax[,i-1]} dt \\, \\mathrm{SFR}(t) \\, \\frac{t - t_{i-1}}{t_{i}  - t_{i-1}} \\nonumber \\\\\n\\tmin[,i] & = & \\clip[\\amin]{t_i}{t_{i+1}} \\nonumber \\\\\n\\tmax[,i] & = & \\clip[\\amax]{t_i}{t_{i+1}} \\nonumber\n\\end{eqnarray}\nwhere $\\clip[x]{a}{b}$ denotes $x$ \\emph{clipped} to the interval $(a,b)$. If we take $\\mathrm{SFR}(t) = 1$ then we can define\n\\begin{eqnarray}\ng_i(x) & \\equiv & \\tintegral \\, \\mathrm{SFR}(t) \\, \\frac{x - t}{t_{i+1}  - t_i} \\nonumber  \\\\\n & = & \\left. \\frac{1}{t_{i+1} - t_i} \\, \\left[ x\\, t - \\frac{t^2}{2} \\right] \\tinterval\n\\end{eqnarray}\nwhich leads to\n\\begin{eqnarray}\nW_i & = & g_{i}(t_{i+1}) - g_{i-1}(t_{i-1})\n\\end{eqnarray}\nand one only has to calculate the $\\{g_i(t_i)\\}, \\{g_i(t_{i+1})\\}$ once and then take differences between shifted versions to obtain the total weights.\nNote that for the smallest $i$ we define $g_{i-1}(t_{i-1})\\equiv 0$ (there is no younger or ``left'' sub-bin) \nand for the largest $i$ we define $g_{i}(t_{i+1}) \\equiv 0$ (there is no older or ``right'' sub-bin) .\n\nThis formalism works even if $\\amin$ and $\\amax$ both fall between the same $t_i$ and $t_{i+1}$; that is, if the desired bin is narrower than the SSP defined sub-bins.\nIt also works if a sub-bin falls completely outside the $(\\amin, \\amax)$ interval.\nThis is because the clipping will cause $\\tmin$ and $\\tmax$ to be the same for bins not at least partially within the $(\\amin, \\amax)$ interval, and thus all integrals will evaluate to zero.\n\n\\section{Interpolation in $\\log t$}\n\nFor the case of a linear interpolation in $\\log t$, which is probably more appropriate, we can write\n\\begin{eqnarray}\nw_{i}(t) & = & \\frac{ \\log t_{i+1} - \\log t}{ \\log t_{i+1}  - \\log t_i} \\nonumber\n\\end{eqnarray}\nin the first set of equations above. The we simply replace $g_i$ by $s_i$ defined as \n\\begin{eqnarray}\ns_i(x) & \\equiv & \\tintegral \\, \\mathrm{SFR}(t) \\, \\frac{x - \\log t}{\\log t_{i+1}  - \\log t_i} \\nonumber \\\\\n & = & \\left. \\frac{1}{\\log t_{i+1} - \\log t_i} t \\, \\left( x - \\log t + \\log e \\right) \\tinterval\n\\end{eqnarray}\nto obtain a total weight for SSP $i$ of\n\\begin{eqnarray}\nW_i & = & s_{i}(\\log t_{i+1}) - s_{i-1}(\\log t_{i-1}) \\nonumber\n\\end{eqnarray}\n\nThe key in both cases is to properly calculate $\\tmax$ and keep track of the indices \n(especially for the first and last SSP, where $s_{i-1}$ and $s_i$ are not defined, respectively.)  \n\n\\section{Lookback Time Zero}\nThe youngest age for which an SSP spectrum is availables is generally of order 1 Myr.  \nHowever, we need to account for SF occuring from 0-1 Myr lookback time.\nThere's a couple ways to deal with this necessary extrapolation.\nProbably the most straightforward is nearest-neighbor extrapolation.  \nThat is, simply approximate the $t=0$ spectrum by the youngest available SSP.\n\nIn the case of logarithmic interpolation one has to define some minimum age, say 1 year, to act as zero.\nIn practice the exact choice of minimum age does not matter, \nas the total weights for the zeroth and first SSP converge such that fractional error is below $\\sim 10^{-4}$ for a minimum age less than 10 years or so...\nThe totally correct way to do this is to work out the definite integrals properly with $\\tmin[,i]=0$.\n\n\n\\section{More complex SFHs}\nFor more complicated SFH only the integrals in the basic definition of $s_i$ and $g_i$ must be calculated again by hand, \n(remembering here that $t$ is \\emph{lookback time}.)\nWe define $s_i(x)$ for interpolation in $\\log t$ and $g_i(x)$ for interpolation in $t$.  \nFor simplicity and clarity we take the cases $x = \\log t_{i+1}$ for $s_i$ and $x = t_{i+1}$ for $g_i$, \nbut substitution for $x$ is trivial (as long as it is not $t$ dependent):\n\\begin{eqnarray}\ns_i & \\equiv & \\tintegral \\, \\mathrm{SFR}(t) \\, \\frac{\\log t_{i+1} - \\log t}{\\dlt} \\\\\ng_i & \\equiv & \\tintegral \\, \\mathrm{SFR}(t) \\, \\frac{t_{i+1} - t}{\\dt}\n\\end{eqnarray}\nwhere for brevity we've defined in this section\n\\begin{eqnarray}\n\\dt & \\equiv & t_{i+1} -  t_i  \\nonumber \\\\\n\\dlt & \\equiv & \\log t_{i+1} - \\log t_i \\nonumber\n\\end{eqnarray}\nIn general the limits of the integral ($\\tmin, \\tmax$) will be defined by the SSP temporal grid $\\{t_i\\}$ as well as any discontinuities in the derivative of the SFR (e.g. the edges of step function already enocountered).\n\nFor convenience we will also note that the integral\n\\begin{eqnarray}\nH_i & \\equiv & \\tintegral \\, e^{t/\\tau} \\, \\log t \\nonumber \\\\\n  & = & \\left. \\tau \\left[ \\log t \\, e^{t/\\tau} - \\log(e) \\, \\mathrm{Ei}(t/\\tau) \\right]\\tinterval\n\\end{eqnarray}\nwhere Ei is the exponential integral.\n\n\\subsection{$\\tau$-model}\nHere we have a SFH defined by three parameters\n\\[ \n\\mathrm{SFR}(t) = \n\\begin{cases}\nK \\, e^{-T/\\tau}, &  \\text{if } 0 < T \\leq \\sftrunc \\\\\n0, & \\text{otherwise}\n\\end{cases}\n\\]\n\\begin{eqnarray}\nT & = & \\tage - t \\nonumber \\\\\nt_q & = & \\tage - \\sftrunc \\nonumber \n\\end{eqnarray}\nwhere $T$ is defined as the time since the start of star formation, \\emph{not} lookback time.  \nThe lookback time  (in the reference frame of the galaxy) is given by $t$, which goes from 0 to $\\tage$.\nThe parameters are: \n$\\tage$, the age of the galaxy since the start of SF (\\texttt{tage} in FSPS), \n$\\tau$, the $e$-folding time (\\texttt{tau} in FSPS), and\n$\\sftrunc$, the time since the start of SF that truncation occurs (\\texttt{sf\\_trunc} in FSPS).\nNote that in the current FSPS definition, $\\sftrunc = 0$ corresponds to no truncation, so it is actually $\\sftrunc= \\tage$ and $t_q=0$.\nThe FSPS \\texttt{sf\\_start} is basically redundant with \\texttt{tage} and confusing so we ignore it.\n\nIn this case we have, for the logarithmic time interpolation,\n\\begin{eqnarray}\ns_i  & = & \\tintegral \\, K \\, e^{(t-\\tage) /\\tau}\\, \\frac{\\log t_{i+1} - \\log t}{\\dlt} \\nonumber \\\\\n%      & = & \\frac{K \\, e^{-\\tage/\\tau}}{\\dlt} \\left[ \\left. \\tau \\, \\log t_{i+1} \\, e^{t/\\tau} \\tinterval -  H_i\\right] \\nonumber \\\\\n\\tmin[,i] & = & \\clip[t_q]{t_i}{t_{i+1}} \\nonumber \\\\\n\\tmax[,i] & = & \\clip[\\tage]{t_i}{t_{i+1}} \\quad . \\nonumber\n\\end{eqnarray}\nThis yields, \n\\begin{eqnarray}\ns_i & = & \\left. \\frac{K \\, \\tau \\, e^{-\\tage/\\tau}}{\\dlt} \\left [(\\log t_{i+1} - \\log t)\\, e^{t/\\tau} + \n          \\log(e) \\, \\mathrm{Ei}(t/\\tau)\\right]  \\tinterval\n\\end{eqnarray}\nFor interpolation in linear time the integral is a bit more straightforward\n\\begin{eqnarray}\ng_i & = & \\left. \\frac{K \\, \\tau \\, e^{-\\tage/\\tau}}{\\dt} (t_{i+1} - t + \\tau)\\, e^{t/\\tau} \\tinterval\n\\end{eqnarray}\nwhere the limits $\\tmin$ and $\\tmax$ are defined as above.\nOne can either calculate the normalization constant $K$ analytically, or simply renormalize the final weights $W_i$ by their sum.\n\n\\subsection{Delayed-$\\tau$}\nHere the SFH is also defined by three parameters\n\\[ \n\\mathrm{SFR}(t) = \n\\begin{cases}\nK \\, T \\, e^{-T/\\tau}, &  \\text{if } 0 < T \\leq \\sftrunc\\\\\n0, & \\text{otherwise}\n\\end{cases}\n\\]\n\\begin{eqnarray}\nT & = & \\tage - t \\nonumber \\\\\nt_q & = & \\tage - \\sftrunc\\nonumber\n\\end{eqnarray}\nSo now we have\n\\begin{eqnarray}\ns_i  & = & \\tintegral \\, K \\, (\\tage-t) \\, e^{(t-\\tage) /\\tau}\\, \\frac{\\log t_{i+1} - \\log t}{\\dlt}  \\nonumber \\\\\n%      & = & \\frac{K \\, e^{-\\tage/\\tau}}{\\dlt} \\tintegral \\, \\left(\\tage \\, \\log t_{i+1} \\, e^{t/\\tau}  - \\tage \\, \\log t \\, e^{t/\\tau} - t \\, \\log t_{i+1} \\, e^{t/\\tau} + t \\, \\log t \\, e^{t/\\tau}\\right) \\quad .\\nonumber\n%\\end{eqnarray}\n%The first and third terms are fairly straightforward.  The second term is basically the integral we did for the $\\tau$-model.  The last term can be solved by integrating by parts (with $u=t\\,\\log t$, $dv=e^{t/\\tau}dt$ and hence $du=(\\log e + \\log t)\\, dt$, $v=\\tau e^{t/\\tau}$.  Substituting and collecting terms gives, finally, \n%\\begin{eqnarray}\n%s_i  & = & \\frac{K \\, \\tau \\,  e^{-\\tage/\\tau}}{\\dlt} \\left[\\left.\\left(t\\,\\log \\frac{t}{t_{i+1}} + \\tage\\,\\log t_{i+1}  + \\tau\\,\\log \\frac{t_{i+1}}{e}\\right) e^{t/\\tau}\\tinterval - (\\tage/\\tau+1)\\, H_i\\right] \\\\\n & = & \\frac{K \\, \\tau \\,  e^{-\\tage/\\tau}}{\\dlt} \\left. \\left[\\left((t - \\tage - \\tau) \\, \\log \\frac{t}{t_{i+1}} - \\tau \\, \\log (e) \\right) \\, e^{t/\\tau}    + (\\tage + \\tau) \\, \\log (e) \\, \\mathrm{Ei}(t/\\tau) \\right]\\tinterval %\\quad .\n\\end{eqnarray}\nThe limits $\\tmin$ and $\\tmax$ are as for the $\\tau$-model above.\n\nFor interpolation in linear time, we have\n\\begin{eqnarray}\ng_i  & = & \\tintegral \\, K \\, (\\tage-t) \\, e^{(t-\\tage) /\\tau}\\, \\frac{t_{i+1} - t}{\\dt}  \\nonumber \\\\\n%      & = & \\frac{K \\, e^{-\\tage/\\tau}}{\\dt} \\tintegral \\, \\left(\\tage \\, t_{i+1} \\, e^{t/\\tau}  - \\tage \\, t \\, e^{t/\\tau} - t \\,  t_{i+1} \\, e^{t/\\tau} + t^2 \\, e^{t/\\tau}\\right) \\nonumber \\\\\n     & = & \\frac{K \\, \\tau \\, e^{-\\tage/\\tau}}{\\dt} \\left. e^{t/\\tau} \\, \\left[ \\tage \\, t_{i+1} - (\\tage + t_{i+1})\\, (t-\\tau) + t^2 - 2\\, t\\, \\tau + 2\\, \\tau^2\\right] \\tinterval \\quad .\n\\end{eqnarray}\n\nOne could, in principle, redefine the SSP $t_i$ to be in forward time instead of lookback time.  While this would simplify the integrals, keeping them in lookback time is conceptually simpler.\n\n\\subsection{Simha}\nThis is the SFH from \\citet{simha14}.  \nIt is defined by a delayed-$\\tau$ SFH until some time $\\sftrunc$, after which the SFH is linearly increasing or decreasing with some slope $m_{\\mathrm{SF}}$, which has units of inverse time.\nThe SFR is continuous at $\\sftrunc$, but the derivative is not.  \nFor this reason, we will treat the SFH in two separate pieces.  \nThe trick is to get the proper normalization at $\\sftrunc$ and, for linearly decreasing SF, find the time where the SF reaches zero. \n\\[ \n\\mathrm{SFR}(t) = \n\\begin{cases}\nK \\, T \\, e^{-T/\\tau}, &  \\text{if } 0 < T \\leq \\sftrunc \\\\\nL\\, \\left[1 - \\sfslope \\, (T - \\sftrunc)\\right] & \\text{if } \\sftrunc < T  < \\sfzero \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\n\\begin{eqnarray}\nT & = & \\tage - t \\nonumber \\\\\nt_q & = & \\tage - \\sftrunc \\nonumber \\\\\nL & = & K \\, \\sftrunc \\, e^{-\\sftrunc/\\tau} \\nonumber \\\\\n\\sfzero & = & \\clip[\\left(\\sftrunc + \\sfslope^{-1}\\right)]{\\sftrunc}{\\tage}, \\nonumber \\\\\n\\tzero & = & \\clip[\\left( t_q - \\sfslope^{-1}\\right)]{0}{t_q} \\nonumber\n\\end{eqnarray}\nwhere $\\tzero$ is the \\emph{lookback} time at which the SFR becomes zero.  The clipping here is the wrong terminology.  Basically we want $\\tzero$ to be 0 unless it falls within the interval $(t_q -\\sfslope^{-1}, t_q)$, or if $\\sfslope=0$.\n\nThe portion of the SFH that is a delayed-$\\tau$ can be dealt with using the formulae in the last section.  The linear portion is relatively straightforward:\n\\begin{eqnarray}\ns_i  & = & \\tintegral \\,  L\\, \\left[1 - \\sfslope \\, (t_q - t)\\right] \\, \\frac{\\log t_{i+1} - \\log t}{\\dlt}  \\nonumber \\\\\n      & = & \\frac{L}{\\dlt} \\left.\\left[(1-\\sfslope\\, t_q) \\, t \\, \\left(\\log t_{i+1} - \\log t +\\log e \\right) + \n                                                     \\frac{\\sfslope \\, t^2}{2} \\, \\left(\\log t_{i+1} - \\log t +\\frac{\\log e}{2}\\right) \\right] \\tinterval \\\\\n\\tmin[,i] & = & \\clip[\\tzero]{t_i}{t_{i+1}} \\nonumber \\\\\n\\tmax[,i] & = & \\clip[t_q]{t_i}{t_{i+1}} \\quad . \\nonumber\n\\end{eqnarray}\n\nThe linear interpolation version of the linear SFH is given by \n\\begin{eqnarray}\ng_i  & = & \\tintegral \\,  L\\, \\left[1 - \\sfslope \\, (t_q - t)\\right] \\, \\frac{t_{i+1} - t}{\\dt}  \\nonumber \\\\\n      & = & \\frac{L}{\\dt} \\left.\\left[(1-\\sfslope\\, t_q) \\, t_{i+1} \\, t + \\left(\\sfslope\\, t_{i+1} + \\sfslope \\, t_q -1\\right)\\, \\frac{t^2}{2} - \\frac{\\sfslope\\, t^3}{3}\\right] \\tinterval\n\\end{eqnarray}\nWe verify that these expressions reduce to the constant SFR case when $\\sfslope=0$.\n\nGenerally we will want to express the normalization as a ratio of total masses formed in the two segments (the delayed-$\\tau$ and linear portions).\n\n\\subsection{Bursts}\n\nHere we have \n\\[ \n\\mathrm{SFR}(t) = \\delta(T - T_{burst})\n\\]\n\\begin{eqnarray}\nT & = & \\tage - t \\nonumber \\\\\nT_{burst} & = & \\tage - t_b\n\\end{eqnarray}\nand the integrals are easy as pie\n\\[ \ns_i = \n\\begin{cases}\n\\frac{\\log t_{i+1} - \\log t_b}{\\dlt}&  \\text{if } t_i < t_b \\leq t_{i+1} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\nand\n\\[ \ng_i = \n\\begin{cases}\n\\frac{t_{i+1} - t_b}{\\dt}&  \\text{if } t_i < t_b \\leq t_{i+1} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\n\n\n\n\\section{Old FSPS Integrals}\n\nPreviously, FSPS was doing the something like following integral (ignoring \\texttt{dust\\_tesc}, \\texttt{sf\\_start} and \\texttt{sf\\_trunc})\n\\begin{eqnarray}\nf & = & f_{i_{max}+1} \\, \\int _{t_{i_{max}}}^{\\tage} dt\\, SFR(t) + \\sum_{i=1}^{i_{max}} \\frac{f_i + f_{i+1}}{2}\\int _{t_{i}-t_1}^{t_{i+1}-t_1} dt\\, SFR(t) \\\\\n%i_{max} & = &\n\\end{eqnarray}\nThis is basically trapezoidal integration, a numerical approximation to the fully analytic integrals we are doing.  \nIt works great as long as the SFH in the bin is approximately linear across the entire bin.\n\n\\end{document}", "meta": {"hexsha": "30139fb9fd57b8eca87c5bb0be629c29dd2422d8", "size": 15011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/text/sfh_integrals.tex", "max_stars_repo_name": "wrensuess/prospector", "max_stars_repo_head_hexsha": "08173f84ddfc2b031c78822344fc821778d35bae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 94, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:29:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T13:25:39.000Z", "max_issues_repo_path": "doc/text/sfh_integrals.tex", "max_issues_repo_name": "wrensuess/prospector", "max_issues_repo_head_hexsha": "08173f84ddfc2b031c78822344fc821778d35bae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 168, "max_issues_repo_issues_event_min_datetime": "2016-04-15T20:01:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:03:07.000Z", "max_forks_repo_path": "doc/text/sfh_integrals.tex", "max_forks_repo_name": "wrensuess/prospector", "max_forks_repo_head_hexsha": "08173f84ddfc2b031c78822344fc821778d35bae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 53, "max_forks_repo_forks_event_min_datetime": "2016-07-14T07:19:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T03:10:28.000Z", "avg_line_length": 53.2304964539, "max_line_length": 330, "alphanum_fraction": 0.6398640997, "num_tokens": 5556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6857282463744947}}
{"text": "\\section{Powers of Trigonometric Functions}{}{}\\label{sec:Powers of trigonometric functions}\nFunctions involving trigonometric functions are useful as they are good at describing periodic behavior. % Learning techniques to integrate such functions helps solve problems involving periodic behavior and also helps build general problem solving skills.\n This section describes several techniques for finding antiderivatives of certain combinations of trigonometric functions.\\\\\n\n\nFunctions consisting of powers of the sine and cosine can be\nintegrated by using substitution and trigonometric identities. These\ncan sometimes be tedious, but the technique is straightforward. A similar \ntechnique is applicable to powers of secant and tangent (and also cosecant \nand cotangent, not discussed here).\n\n%The trigonometric substitutions we will focus on in this section are summarized in the table below:\n%\\begin{center}\n%\t\\begin{tabular}{|c|c|c|c|c|}\n%\t\\hline\n%\t\\thmfont{Substitution} & $u=\\sin x$ & $u=\\cos x$ & $u=\\tan x$ & $u=\\sec x$\\\\[0.5em]\n%\t\\thmfont{Derivative} & $du=\\cos x\\, dx$ & $du=-\\sin x\\,dx$ & $du=\\sec^2x\\,dx$ & $du=\\sec x\\tan x\\,dx$\\\\\n%\t\\hline\n%\t\\end{tabular}\n%\\end{center}\n\n\\subsection*{Integrals of the form $\\ds \\int \\sin^m x\\cos^n x\\ dx$}\n\n\n\nUsing the technique of Substitution, we see the integral $\\int \\sin x\\cos x\\ dx$  could easily be evaluated  by letting $u=\\sin x$ or by letting $u = \\cos x$. This integral is easy since the power of both sine and cosine is $ 1 $.\n\nWe generalize this integral and consider integrals of the form $\\int \\sin^mx\\cos^nx\\ dx$, where $m,n$ are nonnegative integers. Our strategy for evaluating these integrals is to use the Pythagorean identity $\\cos^2x+\\sin^2x=1$ to convert high powers of one trigonometric function into the other, leaving a single sine or cosine term in the integrand. We summarize the general technique in the following\n\n\n\n\\begin{formulabox}[Products of Sine and Cosine]\n\tWhen evaluating $\\ds\\int\\sin^mx \\cos^nx\\,dx$:  \n\t\\begin{enumerate}\n\t\\item \\ffont{The power of sine is odd ($m$ odd):}\\\\  \n\t\t(a) Use $u=\\cos x$ and $du=-\\sin x\\,dx$.\\\\  \n\t\t(b) Replace $dx$ using (a), thus cancelling one power of $\\sin x$ by the substitution of $du$, and be left with an even number of sine powers.\\\\  \n\t\t(c) Use $\\sin^2x=1-\\cos^2x~(=1-u^2)$ to replace the leftover sines.  \n\t\\item \\ffont{The power of cosine is odd ($n$ odd):}\\\\  \n\t\t(a) Use $u=\\sin x$ and $du=\\cos x\\,dx$.\\\\  \n\t\t(b) Replace $dx$ using (a), thus cancelling one power of $\\cos x$ by the substitution of $du$, and be left with an even number of cosine powers.\\\\  \n\t\t(c) Use $\\cos^2x=1-\\sin^2x~(=1-u^2)$ to replace the leftover cosines.\t  \n\t\\item \\ffont{Both $m$ and $n$ are odd}:\\\\ Use either $1$ or $2$ (both will work).  \n\t\\item \\ffont{Both $m$ and $n$ are even}:\\\\  \n\t Use $\\cos^2x=\\frac{1}{2}\\left(1+\\cos(2x)\\right)$ and/or $\\sin^2x=\\frac{1}{2}\\left(1-\\cos(2x)\\right)$ to reduce to a form that can be integrated.\n\t\\end{enumerate}\n\tNOTE: As $m$ and $n$ get large, multiple steps will be needed.\n\\end{formulabox}\n\n%\\begin{formulabox}[Integrals Involving Powers of Sine and Cosine]\n%\tConsider $\\ds \\int \\sin^mx\\cos^nx\\ dx$, where $m,n$ are nonnegative integers.\\index{integration!of trig. powers}\n%\t\t\\begin{enumerate}\n%\t\t\\item\t\tIf $m$ is odd, then $m=2k+1$ for some integer $k$. Rewrite \\small\n%\t\t\t\t$$ \\sin^mx = \\sin^{2k+1}x = \\sin^{2k}x\\sin x = (\\sin^2x)^k\\sin x = (1-\\cos^2x)^k\\sin x.$$\\normalsize\n%\t\t\t\tThen \\small\n%\t\t\t\t$$\\int \\sin^mx\\cos^nx\\ dx = \\int (1-\\cos^2x)^k\\sin x\\cos^nx\\ dx = -\\int (1-u^2)^ku^n\\ du,$$\\normalsize\n%\t\t\t\twhere $u = \\cos x$ and $du = -\\sin x\\ dx$. \n%\t\t\\item\t\tIf $n$ is odd, then using substitutions similar to that outlined above we have\n%\t\t\t\t\\small\n%\t\t\t\t$$ \\int \\sin^mx\\cos^nx\\ dx = \\int u^m(1-u^2)^k\\ du,$$ \\normalsize\n%\t\t\t\twhere $u = \\sin x$ and $du = \\cos x\\ dx$.\n%\t\t\\item\t\tIf both $m$ and $n$ are even, use the power--reducing identities\n%\t\t\t\\small$$  \\cos^2x = \\frac{1+\\cos (2x)}{2} \\quad \\text{and}\\quad \\sin^2x = \\frac{1-\\cos(2x)}2$$\\normalsize\n%\t\tto reduce the degree of the integrand. Expand the result and try again.\n%\t\t\\end{enumerate}\n%%\tNOTE: The integral will become more tedious as $m$ and $n$ get large, since multiple steps will be needed.\n%\\end{formulabox}\n\n\n\nNow a few examples to practice the approach.\n\n\\begin{example}{Integrating powers of sine and cosine}{}\nEvaluate $\\ds\\int \\sin^6 x\\cos^5 x\\,dx$.\n\\end{example}  \n\n\\begin{solution}\nSince the power of cosine is odd, we use the substitution $\\red{u=\\sin x}$ and $du=\\cos x\\,dx$, that is, $\\fbox{$dx$}=\\fbox{$\\ds\\frac{du}{\\cos x}$}$.\nThen $\\ds\\int \\sin^6 x\\cos^5 x\\,dx$ is equal to:\n$${\\def\\arraystretch{2.2}\n\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n & = & \\int u^6\\cos^5x \\,\\fbox{$\\ds\\frac{du}{\\cos x}$}\t & \\mbox{Using the substitution} \\\\  \n\t&=&\\int u^6\\left(\\cos^2x\\right)^2 \\,du  & \\mbox{Canceling a $\\cos x$ and rewriting $\\cos^4x$}\\\\  \n\t&=&\\int u^6(1-\\sin^2x)^2\\,du  & \\mbox{Using trig identity $\\cos^2x=1-\\sin^2x$}\\\\  \n\t&=&\\int u^6(1-u^2)^2\\,du  & \\mbox{Writing integral in terms of $u$'s}\\\\  \n\t&=&\\int u^6-2u^8+u^{10}\\,du  & \\mbox{Expand and collect like terms}\\\\  \n\t&=&\\frac{u^7}{7}-\\frac{2u^9}{9}+\\frac{u^{11}}{11}+C & \\mbox{Integrating}\\\\  \n\t&=&\\frac{\\sin^7x}{7}-\\frac{2\\sin^9x}{9}+\\frac{\\sin^{11}x}{11}+C  & \\mbox{Replacing $u$ back in terms of $x$}\n\\end{array}\n}$$\n\\end{solution}\n\n\n\\begin{example}{Odd Power of Cosine}{}\nEvaluate $\\ds\\int \\cos^3 x\\,dx$.\n\\end{example}  \n\n\\begin{solution}\nSince the power of cosine is odd, we use the substitution $\\red{u=\\sin x}$ and $du=\\cos x\\,dx$.  \nThis may seem strange at first since we don't have $\\sin x$ in the question, but it does work!  \n$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\\int \\cos^3 x\\,\\fbox{$dx$} & = & \\int \\cos^3x \\,\\fbox{$\\ds\\frac{du}{\\cos x}$}\t & \\mbox{Using the substitution} \\\\  \n\t&=&\\int \\cos^2x \\,du  & \\mbox{Canceling a $\\cos x$}\\\\  \n\t&=&\\int (1-\\sin^2x)\\,du  & \\mbox{Using trig identity $\\cos^2x=1-\\sin^2x$}\\\\  \n\t&=&\\int (1-u^2)\\,du  & \\mbox{Writing integral in terms of $u$'s}\\\\  \n\t&=&u-\\frac{u^3}{3}+C & \\mbox{Integrating}\\\\  \n\t&=&\\sin x-\\frac{\\sin^3x}{3}+C  & \\mbox{Replacing $u$ back in terms of $x$}\n\\end{array}$$\n\\end{solution}\n\n\\begin{example}{Integrating powers of sine and cosine}{Integrating powers of sine and cosine}\\label{Odd Power of Sine}\nEvaluate $\\ds\\int \\sin^5 x\\,dx$.\n\\end{example}\n\n\\begin{solution} \nSince the power of sine is odd, we factor out one $ \\sin(x) $, and exploit the Pythagorean identity: $\\sin^2x+\\cos^2x=1$.\n\\begin{eqnarray*}\n  \\int \\sin^5 x\\,dx&=&\\int \\sin x \\sin^4 x\\,dx\\\\\n\t&=&\n  \\int \\sin x (\\sin^2 x)^2\\,dx\\\\\n\t&=&\n  \\int \\sin x (1-\\cos^2 x)^2\\,dx.\n\\end{eqnarray*}%\\vskip-20pt\nNow use $u=\\cos x$, $du=-\\sin x\\,dx$:\n\\begin{eqnarray*}\n  \\int \\sin x (1-\\cos^2 x)^2\\,dx&=&\\int -(1-u^2)^2\\,du\\\\\n  &=&\\int -(1-2u^2+u^4)\\,du\\\\\n  &=&\\int 1+2u^2-u^4\\,du\\\\\t\n  &=&-u+{\\frac{2}{3}}u^3-{\\frac{1}{5}}u^5+C\\\\\n  &=&-\\cos x+\\frac{2}{3}\\cos^3 x-\\frac{1}{5}\\cos^5x+C.\n\\end{eqnarray*}\\vskip-20pt\n\\end{solution}\n\n%Observe that by taking the substitution $u=\\cos x$ in the last example, we ended up with an even power of sine from which we can use the Pythagorean identity $\\sin^2x+\\cos^2x=1$ to replace any remaining sine terms.\n%We then ended up with a polynomial in $u$ in which we could expand and integrate quite easily.\n\n%This technique works for products of powers of sine and cosine.\n%We summarize it below.\n%\\begin{formulabox}[Products of Sine and Cosine]\n%\tWhen evaluating $\\ds\\int\\sin^mx \\cos^nx\\,dx$:  \n%\t\\begin{enumerate}\n%\t\\item \\ffont{The power of sine is odd ($m$ odd):}\\\\  \n%\t\t(a) Use $u=\\cos x$ and $du=-\\sin x\\,dx$.\\\\  \n%\t\t(b) Replace $dx$ using (a), thus cancelling one power of $\\sin x$ by the substitution of $du$, and be left with an even number of sine powers.\\\\  \n%\t\t(c) Use $\\sin^2x=1-\\cos^2x~(=1-u^2)$ to replace the leftover sines.  \n%\t\\item \\ffont{The power of cosine is odd ($n$ odd):}\\\\  \n%\t\t(a) Use $u=\\sin x$ and $du=\\cos x\\,dx$.\\\\  \n%\t\t(b) Replace $dx$ using (a), thus cancelling one power of $\\cos x$ by the substitution of $du$, and be left with an even number of cosine powers.\\\\  \n%\t\t(c) Use $\\cos^2x=1-\\sin^2x~(=1-u^2)$ to replace the leftover cosines.\t  \n%\t\\item \\ffont{Both $m$ and $n$ are odd}:\\\\ Use either $1$ or $2$ (both will work).  \n%\t\\item \\ffont{Both $m$ and $n$ are even}:\\\\  \n%\t Use $\\cos^2x=\\frac{1}{2}\\left(1+\\cos(2x)\\right)$ and/or $\\sin^2x=\\frac{1}{2}\\left(1-\\cos(2x)\\right)$ to reduce to a form that can be integrated.\n%\t\\end{enumerate}\n%\tNOTE: The integral will become more tedious as $m$ and $n$ get large, since multiple steps will be needed.\n%\\end{formulabox}\n\n\n\\begin{example}{Integrating powers of sine and cosine}{Integrating powers of sine and cosine}\\label{Odd Power of Sine}\nEvaluate $\\ds\\int\\sin^5x\\cos^8x\\ dx$.\n\\end{example}\n\n\\begin{solution} \nThe power of the sine term is odd, so we rewrite $\\sin^5x$ as $$\\sin^5x = \\sin^4x\\sin x = (\\sin^2x)^2\\sin x = (1-\\cos^2x)^2\\sin x.$$\n\nOur integral is now $\\ds \\int (1-\\cos^2x)^2\\cos^8x\\sin x\\ dx$. Let $u = \\cos x$, hence $du = -\\sin x\\ dx$. Making the substitution and expanding the integrand gives\n$$\\int (1-\\cos^2)^2\\cos^8x\\sin x\\ dx = -\\int (1-u^2)^2u^8\\ du = -\\int \\big(1-2u^2+u^4\\big)u^8\\ du = -\\int \\big(u^8-2u^{10}+u^{12}\\big)\\ du.$$\nThis final integral is not difficult to evaluate, giving \n\\begin{align*} -\\int \\big(u^8-2u^{10}+u^{12}\\big)\\ du &= -\\frac19u^9 + \\frac2{11}u^{11} - \\frac1{13}u^{13} + C \\\\\n\t\t\t\t\t\t\t\t\t\t&=-\\frac19\\cos^9 x + \\frac2{11}\\cos^{11} x - \\frac1{13}\\cos^{13} x + C.\n\\end{align*}\n\\end{solution}\n\n\n\n\n\n\n\\begin{example}{Product of Even Powers of Sine and Cosine}{Product of Even Powers of Sine and Cosine}\\label{Product of Even Powers of Sine and Cosine}\nEvaluate $\\ds\\int \\sin^2x\\cos^2x\\,dx$. \n\\end{example}\n\n\\begin{solution} \nUse the formulas\n$\\ds \\sin^2x =(1-\\cos(2x))/2$ and $\\ds \\cos^2x =(1+\\cos(2x))/2$ to get:\n$$\n  \\int \\sin^2x\\cos^2x\\,dx=\\int {1-\\cos(2x)\\over2}\\cdot\n  {1+\\cos(2x)\\over2}\\,dx.\n$$\nWe then have\n\\begin{eqnarray*}\n\\int \\sin^2x\\cos^2x\\,dx&=&\\int {1-\\cos(2x)\\over2}\\cdot{1+\\cos(2x)\\over2}\\,dx\\\\\n&=&{1\\over4}\\int 1-\\cos^2 2x\\,dx\\\\\n&=&{1\\over4}\\left(x-\\int\\cos^2 2x\\,dx\\right)\\\\\n&=&{1\\over4}\\left(x-{1\\over2}\\int 1+\\cos4x \\,dx\\right)\\\\\n&=&{1\\over4}\\left(x-{1\\over2}\\left(x+{\\sin 4x\\over 4}\\right)\\right)\\\\\n&=&{1\\over4}\\left(x-{x\\over2}-{\\sin 4x\\over 8}\\right)+C\n\\end{eqnarray*}\n\\end{solution}\n\n\n\\begin{example}{Even Power of Sine}{Even Power of Sine}\\label{Even Power of Sine}\nEvaluate $\\ds\\int \\sin^6 x\\,dx$.\n\\end{example}\n\n\\begin{solution} \nUse $\\ds \\sin^2x =(1-\\cos(2x))/2$ to\nrewrite the function:\n\\begin{eqnarray*}\n  \\int \\sin^6 x\\,dx&=&\\int (\\sin^2 x)^3\\,dx\\\\\n\t&=&\\int {(1-\\cos 2x)^3\\over 8}\\,dx\\\\\n  &=&{1\\over 8}\\int 1-3\\cos 2x+3\\cos^2 2x-\\cos^3 2x\\,dx.\n\\end{eqnarray*}\nNow we have four integrals to evaluate:\n$$\\int 1\\,dx=x+C$$\nand\n$$\\int -3\\cos 2x\\,dx = -{3\\over 2}\\sin 2x+C$$\nThe $\\ds \\cos^3 2x$ integral is like the previous example:\n\\begin{eqnarray*}\n  \\int -\\cos^3 2x\\,dx&=&\\int -\\cos 2x\\cos^2 2x\\,dx\\\\\n  &=&\\int -\\cos 2x(1-\\sin^2 2x)\\,dx\\\\\n  &=&\\int -{1\\over 2}(1-u^2)\\,du\\\\\n  &=&-{1\\over 2}\\left(u-{u^3\\over 3}\\right)+C\\\\\n  &=&-{1\\over 2}\\left(\\sin 2x-{\\sin^3 2x\\over 3}\\right)+C.\n\\end{eqnarray*}\nAnd finally we use another trigonometric identity,\n$\\ds \\cos^2x=(1+\\cos(2x))/2$:\n$$\n  \\int 3\\cos^2 2x\\,dx=3\\int {1+\\cos 4x\\over 2}\\,dx=\n  {3\\over 2}\\left(x+{\\sin 4x\\over 4}\\right)+C.\n$$\nSo at long last, gathering and combining the arbitrary constants we get\n$$\n  \\int \\sin^6 x\\,dx = {x\\over8} -{3\\over 16}\\sin 2x \n  -{1\\over 16}\\left(\\sin 2x-{\\sin^3 2x\\over 3}\\right)\n  +{3\\over 16}\\left(x+{\\sin 4x\\over 4}\\right)+C.\n$$\\vskip-10pt\n\\end{solution}\n\n\n\\begin{example}{Integrating powers of sine and cosine}{ex_trigint2}\nEvaluate $\\ds \\int\\sin^5x\\cos^9x\\ dx$.\n\\end{example}\n\n\\begin{solution} \nThe powers of both the sine and cosine terms are odd, therefore we can apply our techniques to either power. We choose to work with the power of the cosine term since the previous example used the sine term's power.\n\nWe rewrite $\\cos^9x$ as\n\\begin{align*} \\cos^9 x &= \\cos^8x\\cos x \\\\\n\t\t\t\t&= (\\cos^2x)^4\\cos x \\\\\n\t\t\t\t&= (1-\\sin^2x)^4\\cos x \\\\\n\t\t\t\t&= (1-4\\sin^2x+6\\sin^4x-4\\sin^6x+\\sin^8x)\\cos x.\n\\end{align*}\n\nWe rewrite the integral as \n$$\\int\\sin^5x\\cos^9x\\ dx = \\int\\sin^5x\\big(1-4\\sin^2x+6\\sin^4x-4\\sin^6x+\\sin^8x\\big)\\cos x\\ dx.$$\n\nNow substitute and integrate, using $u = \\sin x $ and $du = \\cos x\\ dx$.\n\n\\small\\noindent\n%\\begin{gather}\n%\\int\\sin^5x\\big(1-4\\sin^2x+6\\sin^4x-4\\sin^6x+\\sin^8x\\big)\\cos x\\ dx =\\notag\\\\\n%\\int u^5(1-4u^2+6u^4-4u^6+u^8)\\ du = \\int\\big(u^5-4u^7+6u^9-4u^{11}+u^{13}\\big)\\ du  \\notag\n%\\end{gather}\n$\\ds \\int\\sin^5x\\big(1-4\\sin^2x+6\\sin^4x-4\\sin^6x+\\sin^8x\\big)\\cos x\\ dx =$% \\\\\n\\vskip-.8\\baselineskip\n\\begin{align*} \n \\int u^5(1-4u^2+6u^4-4u^6+u^8)\\ du &= \\int\\big(u^5-4u^7+6u^9-4u^{11}+u^{13}\\big)\\ du \\\\\n\t\t\t\t&= \\frac16u^6-\\frac12u^8+\\frac35u^{10}-\\frac13u^{12}+\\frac{1}{14}u^{14}+C\\\\\n\t\t\t\t&= \\frac16\\sin^6 x-\\frac12\\sin^8 x+\\frac35\\sin^{10} x+\\ldots\\\\\n\t\t\t\t&\\phantom{=}-\\frac13\\sin^{12} x+\\frac{1}{14}\\sin^{14} x+C.\n\\end{align*}\n\\end{solution}\n\n\n\\noindent\\textbf{Technology Note:} The work we are doing here can be a bit tedious, but the skills developed (problem solving, algebraic manipulation, etc.) are important. Nowadays problems of this sort are often solved using a computer algebra system. The powerful program \\textit{Mathematica}\\textsuperscript{\\textregistered}, or \\textit{Wolfram Alpha} integrates $\\int \\sin^5x\\cos^9x\\ dx$ as \\small$$f(x)=-\\frac{45 \\cos (2 x)}{16384}-\\frac{5 \\cos (4 x)}{8192}+\\frac{19 \\cos (6\n   x)}{49152}+\\frac{\\cos (8 x)}{4096}-\\frac{\\cos (10 x)}{81920}-\\frac{\\cos (12\n   x)}{24576}-\\frac{\\cos (14 x)}{114688},$$\\normalsize\nwhich clearly has a different form than our answer in Example \\ref{exa:ex_trigint2}, which is\n$$g(x)=\\frac16\\sin^6 x-\\frac12\\sin^8 x+\\frac35\\sin^{10} x-\\frac13\\sin^{12} x+\\frac{1}{14}\\sin^{14} x.$$ Figure \\ref{fig:trigint2} shows a graph of $f$ and $g$; they are clearly not equal, but they differ \\emph{only by a constant}. That is $g(x) = f(x) + C$ for some constant $C$. So we have two different antiderivatives of the same function, meaning both answers are correct. \\\\%We leave it to the reader to recognize why both answers are correct.\\\\\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{axis}[width=\\marginparwidth+25pt,%\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\n\t\t\t%x=.37\\marginparwidth,\n\t\t\t%y=.37\\marginparwidth,\n%\t\t\txtick=\\empty,% \n%\t\t\textra x ticks={.5,3},\n%\t\t\textra x tick labels={$a$,$b$},\n\t\t\tytick={-.002,.002,.004},\n\t\t\tyticklabels={$-0.002$,$0.002$,$0.004$},\n\t\t\t%minor y tick num=1,\n%\t\t\textra y ticks={0.001},%\n%\t\t\tminor x tick num=4,\n\t\t\tymin=-.003,ymax=0.005,%\n\t\t\txmin=-.1,xmax=3.15,%\n\t\t\tscaled ticks=false\n]\n\n\\addplot [{\\colortwo},thick,smooth] coordinates {(0,-0.0027879) (0.15708,-0.0027856) (0.31416,-0.0026798) (0.47124,-0.0020322) (0.62832,-0.00060997) (0.7854,0.00089518)(0.94248,0.0017233) (1.0996,0.0019485) (1.2566,0.0019734) (1.4137,0.0019741) (1.5708,0.0019741) (1.7279,0.0019741) (1.885,0.0019734) (2.042,0.0019485) (2.1991,0.0017233) (2.3562,0.00089518) (2.5133,-0.00060997) (2.6704,-0.0020322) (2.8274,-0.0026798) (2.9845,-0.0027856) (3.1416,-0.0027879)};\n\n\\draw (axis cs:2.6,0.004) node {\\scriptsize $g(x)$};\n\n\\addplot [{\\colorone},thick,smooth] coordinates {(0,0) (0.15708,0) (0.31416,0.00010807) (0.47124,0.0007557) (0.62832,0.0021779) (0.7854,0.003683) (0.94248,0.0045111)\n(1.0996,0.0047364) (1.2566,0.0047612) (1.4137,0.0047619)\n(1.5708,0.0047619) (1.7279,0.0047619) (1.885,0.0047612) (2.042,0.0047364) (2.1991,0.0045111) (2.3562,0.003683) (2.5133,0.0021779) (2.6704,0.0007557) (2.8274,0.00010807) (2.9845,0) (3.1416,0)};\n\n\\draw (axis cs:2.4,-0.002) node {\\scriptsize $f(x)$};\n\\end{axis}\n\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\n\\end{tikzpicture}\n\\caption{A plot of $f(x)$ and $g(x)$ from Example \\ref{exa:ex_trigint2} and the Technology Note. \\label{fig:trigint2}}\n\\end{center}\n\\end{figure}\n\n\n\\begin{example}{Integrating powers of sine and cosine}{Integrating powers of sine and cosine}\nEvaluate $\\ds\\int\\cos^4x\\sin^2x\\ dx$.\n\\end{example}\n\n\\begin{solution} \nThe powers of sine and cosine are both even, so we employ the power--reducing formulas and algebra as follows.\n\\begin{align*}\n\\int \\cos^4x\\sin^2x\\ dx &= \\int\\left(\\frac{1+\\cos(2x)}{2}\\right)^2\\left(\\frac{1-\\cos(2x)}2\\right)\\ dx \\\\\n\t\t\t\t&= \\int\\frac{1+2\\cos(2x)+\\cos^2(2x)}4\\cdot\\frac{1-\\cos(2x)}2\\ dx\\\\\n\t\t\t\t&=\t\\int \\frac18\\big(1+\\cos(2x)-\\cos^2(2x)-\\cos^3(2x)\\big)\\ dx\n\\end{align*}\nThe $\\cos(2x)$ term is easy to integrate, especially with Key Idea \\ref{idea:linearsub}. The $\\cos^2(2x)$ term is another trigonometric integral with an even power, requiring the power--reducing formula again. The $\\cos^3(2x)$ term is a cosine function with an odd power, requiring a substitution as done before. We integrate each in turn below.\n\n$$\\int\\cos(2x)\\ dx = \\frac12\\sin(2x)+C.$$\n\n$$\\int\\cos^2(2x)\\ dx = \\int \\frac{1+\\cos(4x)}2\\ dx = \\frac12\\big(x+\\frac14\\sin(4x)\\big)+C.$$\n\nFinally, we rewrite $\\cos^3(2x)$ as $$\\cos^3(2x) = \\cos^2(2x)\\cos(2x) = \\big(1-\\sin^2(2x)\\big)\\cos(2x).$$\nLetting $u=\\sin(2x)$, we have $du = 2\\cos(2x)\\ dx$, hence\n\\begin{align*}\n\\int \\cos^3(2x)\\ dx &= \\int\\big(1-\\sin^2(2x)\\big)\\cos(2x)\\ dx\\\\\n\t\t\t\t\t\t\t&= \\int \\frac12(1-u^2)\\ du\\\\\n\t\t\t\t\t\t\t&= \\frac12\\Big(u-\\frac13u^3\\Big)+C\\\\\n\t\t\t\t\t\t\t&=\t\\frac12\\Big(\\sin(2x)-\\frac13\\sin^3(2x)\\Big)+C\n\\end{align*}\n\nPutting all the pieces together, we have\n\\begin{align*}\n\\int \\cos^4x\\sin^2x\\ dx &=\\int \\frac18\\big(1+\\cos(2x)-\\cos^2(2x)-\\cos^3(2x)\\big)\\ dx \\\\\n\t\t\t\t\t&= \\frac18\\Big[x+\\frac12\\sin(2x)-\\frac12\\big(x+\\frac14\\sin(4x)\\big)-\\frac12\\Big(\\sin(2x)-\\frac13\\sin^3(2x)\\Big)\\Big]+C \\\\\n\t\t\t\t\t&=\\frac18\\Big[\\frac12x-\\frac18\\sin(4x)+\\frac16\\sin^3(2x)\\Big]+C\n\\end{align*}\n\\end{solution}\n\n\n\n\n\\subsection*{Integrals of the form {\\small{$\\ds \\int\\sin(mx)\\sin(nx)\\ dx,$ $\\ds\\int \\cos(mx)\\cos(nx)\\ dx$}}, and {\\small{$\\ds\\int \\sin(mx)\\cos(nx)\\ dx$.}}}\n\n\nFunctions that contain products of sines and cosines of differing periods are important in many applications including the analysis of sound waves. Integrals of the form \n$$\\int\\sin(mx)\\sin(nx)\\ dx,\\quad \\int \\cos(mx)\\cos(nx)\\ dx \\quad \\text{and}\\quad\\int \\sin(mx)\\cos(nx)\\ dx$$\nare best approached by first applying the Product to Sum Formulas found in the back cover of this text, namely\n\\begin{align*}\n\\sin(mx)\\sin(nx) &= \\frac12\\Big[\\cos\\big((m-n)x\\big)-\\cos\\big((m+n)x\\big)\\Big] \\\\\n\\cos(mx)\\cos(nx) &= \\frac12\\Big[\\cos\\big((m-n)x\\big)+\\cos\\big((m+n)x\\big)\\Big] \\\\\n\\sin(mx)\\cos(nx) &=\t\\frac12\\Big[\\sin\\big((m-n)x\\big)+\\sin\\big((m+n)x\\big)\\Big]\n\\end{align*}\n\n\\begin{example}{Integrating products of $\\sin(mx)$ and $\\cos(nx)$}{ex_trigint4}\nEvaluate $\\ds\\int\\sin(5x)\\cos(2x)\\ dx$.\n\\end{example}\n\n\\begin{solution}\nThe application of the formula and subsequent integration are straightforward:\n\\begin{align*}\n\\int\\sin(5x)\\cos(2x)\\ dx &= \\int \\frac12\\Big[\\sin(3x)+\\sin(7x)\\Big]\\ dx \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t&= -\\frac16\\cos(3x) - \\frac1{14}\\cos(7x) + C\n\\end{align*}\n\\end{solution}\n\n\n\\section*{Integrals of the form $\\ds\\int\\tan^mx\\sec^nx\\ dx$.}\n\nWhen evaluating integrals of the form $\\int \\sin^mx\\cos^nx\\ dx$, the Pythagorean identity allowed us to convert even powers of sine into even powers of cosine, and vise--versa. If, for instance, the power of sine was odd, we pulled out one $\\sin x$ and converted the remaining even power of $\\sin x$ into a function using powers of $\\cos x$, leading to an easy substitution.\n\nThe same basic strategy applies to integrals of the form $\\int \\tan^mx\\sec^n x\\ dx$, albeit a bit more nuanced. The following three facts will prove useful:\n\\begin{itemize}\n\\item $\\frac{d}{dx}(\\tan x) = \\sec^2x$, \n\\item $\\frac{d}{dx}(\\sec x) = \\sec x\\tan x$ , and \n\\item\t$1+\\tan^2x = \\sec^2x$ (the Pythagorean Theorem).\n\\end{itemize}\n\nIf the integrand can be manipulated to separate a $\\sec^2x$ term with the remaining secant power even, or if a $\\sec x\\tan x$ term can be separated with the remaining $\\tan x$ power even, the Pythagorean Theorem can be employed, leading to a simple substitution. This strategy is outlined in the following.\n\n\n\n\n\n%Next, we turn our attention to products of secant and tangent.\n%Some we already know how to do.\n%$$\\int \\sec^2x\\,dx = \\tan x+C\\qquad\\qquad\\int\\sec x\\tan x\\,dx=\\sec x+C$$\n\n\n\\index{integration!products of secant and tangent}\n\\begin{formulabox}[Products of Secant and Tangent]\n\tWhen evaluating $\\ds\\int\\sec^mx \\tan^nx\\,dx$:  \n\t\\begin{enumerate}\n\t\\item \\ffont{The power of secant is even ($m$ even):}\\\\  \n\t\t(a) Use $u=\\tan x$ and $du=\\sec^2 x\\,dx$.\\\\  \n\t\t(b) Cancel $\\sec^2 x$ by the substitution of $dx$, and be left with an even number of secants.\\\\  \n\t\t(c) Use $\\sec^2x=1+\\tan^2x~(=1+u^2)$ to replace the leftover secants.  \n\t\\item \\ffont{The power of tangent is odd ($n$ odd):}\\\\  \n\t\t(a) Use $u=\\sec x$ and $du=\\sec x\\tan x\\,dx$.\\\\  \n\t\t(b) Cancel one $\\sec x$ and one $\\tan x$ by the substitution of $dx$.\\\\  \n\t\t\\quad~~The number of remaining tangents is even.\\\\  \n\t\t(c) Use $\\tan^2x=\\sec^2x-1~(=u^2-1)$ to replace the leftover tangents.  \n\t\\item \\ffont{$m$ is even or $n$ is odd}:\\\\ Use either $1$ or $2$ (both will work).  \n\t\\item \\ffont{The power of secant is odd and the power of tangent is even}:\\\\  \n\t No guidelines. Remember that $\\ds\\int\\sec x\\,dx$ and $\\ds\\int\\sec^3 x\\,dx$ can usually be looked up.\n\t\\end{enumerate}\n\\end{formulabox}\n\n%\\begin{formulabox}[Integrals Involving Powers of Tangent and Secant]\n%Consider $\\ds\\int\\tan^mx\\sec^nx\\ dx$, where $m,n$ are nonnegative integers.\\index{integration!of trig. powers}\n%\\begin{enumerate}\n%\\item\t\tIf $n$ is even, then $n=2k$ for some integer $k$. Rewrite $\\sec^nx$ as \n%$$\\sec^nx = \\sec^{2k}x = \\sec^{2k-2}x\\sec^2x = (1+\\tan^2x)^{k-1}\\sec^2x.$$\n%Then\n%$$\\int\\tan^mx\\sec^nx\\ dx=\\int\\tan^mx(1+\\tan^2x)^{k-1}\\sec^2x\\ dx = \\int u^m(1+u^2)^{k-1}\\ du,$$\n%where $u = \\tan x$ and $du = \\sec^2x\\ dx$.\n%\n%\\item\t\tIf $m$ is odd, then $m=2k+1$ for some integer $k$. Rewrite $\\tan^mx\\sec^nx$ as\n%$$\\tan^mx\\sec^nx = \\tan^{2k+1}x\\sec^nx = \\tan^{2k}x\\sec^{n-1}x\\sec x\\tan x = (\\sec^2x-1)^k\\sec^{n-1}x\\sec x\\tan x.$$\n%Then\n%$$\\int\\tan^mx\\sec^nx\\ dx=\\int(\\sec^2x-1)^k\\sec^{n-1}x\\sec x\\tan x\\ dx = \\int(u^2-1)^ku^{n-1}\\ du,$$\n%where $u = \\sec x$ and $du = \\sec x\\tan x\\ dx$.\n%\n%\\item If $n$ is odd and $m$ is even, then $m=2k$ for some integer $k$. Convert $\\tan^mx $ to $(\\sec^2x-1)^k$. Expand the new integrand and use Integration By Parts, with $dv = \\sec^2x\\ dx$.\n%\n%\\item\t\tIf $m$ is even and $n=0$, rewrite $\\tan^mx$ as\n%$$\\tan^mx = \\tan^{m-2}x\\tan^2x = \\tan^{m-2}x(\\sec^2x-1) = \\tan^{m-2}\\sec^2x-\\tan^{m-2}x.$$\n%So\n%$$\\int\\tan^mx\\ dx = \\underbrace{\\int\\tan^{m-2}\\sec^2x\\ dx}_{\\text{\\small apply rule \\#1}}\\quad - \\underbrace{\\int\\tan^{m-2}x\\ dx}_{\\text{\\small apply rule \\#4 again}}.$$\n%\n%\\end{enumerate}\n%\\end{formulabox}\n\nThe techniques described in items 1 and 2 are relatively straightforward, but the techniques in items 3 and 4 can be rather tedious. A few examples will help with these methods.\\\\\n\n\nWe can integrate $\\tan x$ quite easily using substitution.\\\\\n\n\\begin{example}{Integrating Tangent}{int_tan}\nEvaluate $\\ds\\int\\tan x\\,dx$.\n\\end{example}  \n\n\\begin{solution}\nNote that $\\ds\\tan x = \\frac{\\sin x}{\\cos x}$ and let $u=\\cos x$, so that $du=-\\sin x\\,dx$. %, i.e., $\\fbox{$dx$}=\\fbox{$\\ds\\frac{du}{-\\sin x}$}$:\n$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\\int \\tan x\\,dx & = & \\int \\frac{\\sin x}{\\cos x}\\,\\fbox{$dx$} & \\mbox{Rewriting $\\tan x$} \\\\  \n\t&=&\\int \\frac{\\sin x}{u}\\,\\fbox{$\\ds\\frac{du}{-\\sin x}$}  & \\mbox{Using the substitution}\\\\  \n\t&=&-\\int \\frac{1}{u}\\,du  & \\mbox{Cancelling and pulling the $-1$ out}\\\\  \n\t&=&-\\ln|u|+C & \\mbox{Using formula $\\ds\\int\\frac{1}{u}\\,dx=\\ln|u|+C$}\\\\  \n\t& = & -\\ln|\\cos x|+C & \\mbox{Replacing $u$ back in terms of $x$}\\\\  \n\t& = & \\ln|\\sec x|+C & \\mbox{Using log properties and $\\sec x=1/\\cos x$}\\\\\n\\end{array}$$\n\\end{solution}\n\n%Let's take a moment to realize this result! A common mistake is to believe that $\\int\\tan x\\,dx$ is $\\sec^2(x)+C$ -- this is \\emph{not} true.\n\nHigher poers of $ \\tan(x) $ require the methods outlined above.\n\n\\begin{example}{Integrating Tangent Squared}{}\nEvaluate $\\ds\\int\\tan^2 x\\,dx$.\n\\end{example} \n\n\\begin{solution}\nThe power on tangent is even, so we are in the fourth case outlined in the method. Ao we exploit the fact that   $\\ds\\tan^2 x = \\sec^2x-1$.\n$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\\int \\tan^2 x\\,dx & = & \\int \\sec^2x-1\\,dx & \\mbox{Rewriting $\\tan x$} \\\\\n\t&=&\\tan x-x+C & \\mbox{Since $\\ds\\int\\sec^2x\\,dx=\\tan x+C$}\\\\\n\\end{array}$$\n\\end{solution}\n\nIn problems with tangent and secant, two integrals come up frequently:\n$$\\ds \\int\\sec^3x\\,dx\\qquad\\mbox{and}\\qquad\\int\\sec x\\,dx.$$\nBoth have relatively nice expressions but they are a bit tricky to discover. \n\nFirst we do $\\ds\\int\\sec x\\,dx$, which we\nwill need to compute $\\ds \\int\\sec^3x\\,dx$.\n\n\\begin{example}{Integral of Secant}{Integral of Secant}\nEvaluate $\\ds\\int\\sec x\\,dx$.\n\\end{example}\n\n\\begin{solution}\n\\begin{eqnarray*}\n  \\int\\sec x\\,dx&=&\\int\\sec x\\,{\\sec x +\\tan x\\over \\sec x +\\tan x}\\,dx\\cr\n  &=&\\int{\\sec^2 x +\\sec x\\tan x\\over \\sec x +\\tan x}\\,dx.\\cr\n\\end{eqnarray*}\nNow let $u=\\sec x +\\tan x$, $\\ds du=\\sec x \\tan x + \\sec^2x\\,dx$, exactly\nthe numerator of the function we are integrating. Thus\n\\begin{eqnarray*}\n  \\int\\sec x\\,dx&=&\\int{\\sec^2 x +\\sec x\\tan x\\over \\sec x +\\tan x}\\,dx\\cr\n\t&=&\\int{1\\over u}\\,du=\\ln |u|+C\\cr\n  &=&\\ln|\\sec x +\\tan x|+C.\n\\end{eqnarray*}\n\\end{solution}\n\nNow we compute the integral $\\ds \\int\\sec^3 x\\,dx$.\n\n\\begin{example}{Integral of Secant Cubed}{Integral of Secant Cubed}\nEvaluate $\\ds\\int\\sec^3 x\\,dx$.\n\\end{example}\n\n\\begin{solution}\n\\begin{eqnarray*}\n  \\sec^3x&=&{\\sec^3x\\over2}+{\\sec^3x\\over2}={\\sec^3x\\over2}+{(\\tan^2x+1)\\sec\n    x\\over 2}\\cr\n\t\t\\\\\n  &=&{\\sec^3x\\over2}+{\\sec x \\tan^2 x\\over2}+{\\sec x\\over 2}\\\\\n\t\\\\\n\t&=&\n  {\\sec^3x+\\sec x \\tan^2x\\over 2}+{\\sec x\\over 2}.\n\\end{eqnarray*}\n\nWe already know how to integrate $\\sec x$, so we just need the first\nquotient. This is ``simply'' a matter of recognizing the product rule\nin action:\n$$\\int \\sec^3x+\\sec x \\tan^2x\\,dx=\\sec x \\tan x.$$\nSo putting these together we get \n$$\n  \\int\\sec^3x\\,dx={\\sec x \\tan x\\over2}+{\\ln|\\sec x +\\tan x|\\over2}+C,\n$$\nNote: Once we learn a technique called Integration by Parts, we will see another way to solve this integral.\n\\end{solution}\n\n%For products of secant and tangent it is best to use the following guidelines.\n%\n%\\begin{formulabox}[Products of Secant and Tangent]\n%\tWhen evaluating $\\ds\\int\\sec^mx \\tan^nx\\,dx$:  \n%\t\\begin{enumerate}\n%\t\\item \\ffont{The power of secant is even ($m$ even):}\\\\  \n%\t\t(a) Use $u=\\tan x$ and $du=\\sec^2 x\\,dx$.\\\\  \n%\t\t(b) Cancel $\\sec^2 x$ by the substitution of $dx$, and be left with an even number of secants.\\\\  \n%\t\t(c) Use $\\sec^2x=1+\\tan^2x~(=1+u^2)$ to replace the leftover secants.  \n%\t\\item \\ffont{The power of tangent is odd ($n$ odd):}\\\\  \n%\t\t(a) Use $u=\\sec x$ and $du=\\sec x\\tan x\\,dx$.\\\\  \n%\t\t(b) Cancel one $\\sec x$ and one $\\tan x$ by the substitution of $dx$.\\\\  \n%\t\t\\quad~~The number of remaining tangents is even.\\\\  \n%\t\t(c) Use $\\tan^2x=\\sec^2x-1~(=u^2-1)$ to replace the leftover tangents.  \n%\t\\item \\ffont{$m$ is even or $n$ is odd}:\\\\ Use either $1$ or $2$ (both will work).  \n%\t\\item \\ffont{The power of secant is odd and the power of tangent is even}:\\\\  \n%\t No guidelines. Remember that $\\ds\\int\\sec x\\,dx$ and $\\ds\\int\\sec^3 x\\,dx$ can usually be looked up.\n%\t\\end{enumerate}\n%\\end{formulabox}\n\n%\\begin{example}{Even Power of Secant}{}\n%Evaluate $\\ds\\int\\sec^6x\\tan^6x\\,dx$.\n%\\end{example}  \n%\n%\\begin{solution}\n%Since the power of secant is even, we ue $u=\\tan x$, so that $du=\\sec^2x\\,dx$.\n%$${\\def\\arraystretch{2.2}\n%\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n%\\int \\sec^6x\\tan^6 x\\,dx &=&\\int \\sec^6x\\,(u^6)\\,\\fbox{$\\ds\\frac{du}{\\sec^2x}$}  & \\mbox{Using the substitution}\\\\  \n%\t&=&\\int \\sec^4x(u^6)\\,du  & \\mbox{Cancelling a $\\sec^2x$}\\\\  \n%\t&=&\\int (\\sec^2x)^2(u^6)\\,du  & \\mbox{Rewriting $\\sec^4x$}\\\\  \n%\t&=&\\int (1+\\tan^2x)^2(u^6)\\,du  & \\mbox{Using $\\sec^2x=1+\\tan^2x$}\\\\  \n%\t&=&\\int (1+u^2)^2(u^6)\\,du  & \\mbox{Using the substitution}\\\\  \n%\t\\end{array}\n%}$$\n%To integrate this product the easiest method is expand it into a polynomial and integrate term-by-term.\n%$${\\def\\arraystretch{2.2}\n%\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n%\\int \\sec^6x\\tan^6 x\\,dx\t&=&\\int ( u^6+2u^8+u^{10})\\,du  & \\mbox{Expanding}\\\\  \n%\t&=&\\frac{u^7}{7}+\\frac{2u^9}{9}+\\frac{u^{11}}{11}+C & \\mbox{Integrating}\\\\  \n%\t& = & \\frac{\\tan^7x}{7}+\\frac{2\\tan^9x}{9}+\\frac{\\tan^{11}x}{11}+C & \\mbox{Rewriting in terms of $x$}\\\\\n%\\end{array}\n%}$$\n%\\end{solution}\n\n\n\\begin{example}{Even Power of Secant}{intevensec}\nEvaluate $\\ds\\int \\tan^2x\\sec^6x\\ dx$.\n\\end{example}  \n\n\\begin{solution}\nSince the power of secant is even, we use rule \\#1 and pull out a $\\sec^2x$ in the integrand. We convert the remaining powers of secant into powers of tangent.\n\\begin{align*}\n\\int \\tan^2x\\sec^6x\\ dx &= \\int\\tan^2x\\sec^4x\\sec^2x\\ dx \\\\\n\t\t&= \\int \\tan^2x\\big(1+\\tan^2x\\big)^2\\sec^2x\\ dx \\\\\n\\intertext{Now substitute, with $u=\\tan x$, with $du = \\sec^2x\\ dx$.}\n\t\t&=\\int u^2\\big(1+u^2\\big)^2\\ du\\\\\n\\intertext{We leave the integration and subsequent substitution to the reader. The final answer is}\n\t\t&=\\frac13\\tan^3x+\\frac25\\tan^5x+\\frac17\\tan^7x+C.\n\\end{align*}\n\\end{solution}\n\n\n\n%\\begin{example}{Odd Power of Tangent}{}\n%Evaluate $\\ds\\int\\sec^5x\\tan x\\,dx$.\n%\\end{example} \n%\n%\\begin{solution}\n%Since the power of tangent is odd, we use $u=\\sec x$, so that $du=  \\sec x\\tan x\\,dx$.\n%Then we have:\n%$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n%\\int \\sec^5x\\tan x\\,dx &=&\\int \\sec^5x\\tan x\\,\\fbox{$\\ds\\frac{du}{\\sec x\\tan x}$}  & \\mbox{Substituting $dx$ first}\\\\  \n%\t&=&\\int \\sec^4x\\,du  & \\mbox{Cancelling}\\\\  \n%\t&=&\\int u^4\\,du  & \\mbox{Using the substitution}\\\\  \n%\t&=&\\frac{u^5}{5}+C & \\mbox{Integrating}\\\\  \n%\t& = & \\frac{\\sec^5x}{5}+C & \\mbox{Rewriting in terms of $x$}\\\\\n%\\end{array}$$\n%\\end{solution}\n\n\n\\begin{example}{Odd Power of Tangent}{intoddtan}\nEvaluate $\\ds\\int\\sec^5x\\tan x\\,dx$.\n\\end{example} \n\n\\begin{solution}\nSince the power of tangent is odd, we use rule \\# 2, and factor out $\\sec x\\tan x$ and substitute $ u=\\sec(x)$.\nThen we have:\n$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\\int \\sec^5x\\tan x\\,dx &=&\\int \\sec^4x\\sec x\\tan x\\; dx  & \\mbox{Substituting $dx$ first}\\\\  \n\t%&=&\\int \\sec^4x\\,du  & \\mbox{Cancelling}\\\\  \n\t&=&\\int u^4\\,du  & \\mbox{Using the substitution}\\\\  \n\t&=&\\frac{u^5}{5}+C & \\mbox{Integrating}\\\\  \n\t& = & \\frac{\\sec^5x}{5}+C & \\mbox{Rewriting in terms of $x$}\\\\\n\\end{array}$$\n\\end{solution}\n\n\n\n\\begin{example}{Odd Power of Secant and Even Power of Tangent}{}\nEvaluate $\\ds\\int\\sec x\\tan^2x\\,dx$.\n\\end{example}\n\n\\begin{solution}\nThe guidelines don't help us in this scenario. However, since $\\ds\\tan^2x=\\sec^2x-1$, we have\n$${\\def\\arraystretch{2.2}\n\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\\int \\sec x\\tan^2x\\,dx & = & \\int \\sec x(\\sec^2x-1)  \\,dx &  \\\\  \n\t& = & \\int (\\sec^3x-\\sec x)\\,dx  &  \\\\  \n\t& = & \\frac{1}{2}\\left(\\sec x\\tan x+\\ln|\\sec x+\\tan x|\\right) - \\ln|\\sec x+\\tan x|+C &  \\\\  \n\t& = & \\frac{1}{2}\\sec x\\tan x+\\frac{1}{2}\\ln|\\sec x+\\tan x| - \\ln|\\sec x+\\tan x|+C &  \\\\  \n\t& = & \\frac{1}{2}\\sec x\\tan x-\\frac{1}{2}\\ln|\\sec x+\\tan x|+C & \\\\ \n\\end{array}\n}$$\n\\end{solution}\n\n\n\\begin{example}{Integrating powers of tangent and secant}{ex_trigint7}\n{\nEvaluate $\\ds\\int\\tan^6x\\ dx$.\n}\n\\end{example}\n\n\\begin{solution}\n{We employ rule \\#4. \n\\begin{align*}\n\\int \\tan^6x\\ dx &= \\int \\tan^4x\\tan^2x\\ dx \\\\\n\t\t\t&= \\int\\tan^4x\\big(\\sec^2x-1\\big)\\ dx\\\\\n\t\t\t&= \\int\\tan^4x\\sec^2x\\ dx - \\int\\tan^4x\\ dx \\\\\n\\intertext{Integrate the first integral with substitution, $u=\\tan x$; integrate the second by employing rule \\#4 again.}\n\t\t\t&=\t\\frac15\\tan^5x-\\int\\tan^2x\\tan^2x\\ dx\\\\\n\t\t\t&=\t\\frac15\\tan^5x-\\int\\tan^2x\\big(\\sec^2x-1\\big)\\ dx \\\\\n\t\t\t&= \\frac15\\tan^5x -\\int\\tan^2x\\sec^2x\\ dx + \\int\\tan^2x\\ dx\\\\\n\\intertext{Again, use substitution for the first integral and rule \\#4 for the second.}\n\t\t\t&= \\frac15\\tan^5x-\\frac13\\tan^3x+\\int\\big(\\sec^2x-1\\big)\\ dx \\\\\n\t\t\t&=\t \\frac15\\tan^5x-\\frac13\\tan^3x+\\tan x - x+C.\n\\end{align*}\n\\vskip-\\baselineskip\n}\n\\end{solution}\n\n\nSome of these examples were admittedly long, with repeated applications of the same rule. Try to not be overwhelmed by the length of the problem, but rather admire how robust this solution method is. A trigonometric function of a high power can be systematically reduced to trigonometric functions of lower powers until all antiderivatives can be computed. \n\nThe next section introduces an integration technique known as Trigonometric Substitution, a clever combination of Substitution and the Pythagorean Theorem.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Powers of trigonometric functions}}\n\n\\begin{enumialphparenastyle}\n\nFind the antiderivatives.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sin^2 x\\,dx$\n\\begin{sol}\n $x/2-\\sin(2x)/4+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sin^3 x\\,dx$\n\\begin{sol}\n $\\ds -\\cos x+(\\cos^3x)/3+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sin^4 x\\,dx$\n\\begin{sol}\n $3x/8-(\\sin 2x)/4+(\\sin 4x)/32+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\cos^2 x\\sin^3 x\\,dx$\n\\begin{sol}\n $\\ds (\\cos^5 x)/5-(\\cos^3x)/3+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\cos^3 x\\,dx$\n\\begin{sol}\n $\\ds \\sin x-(\\sin^3x)/3+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\cos^3 x \\sin^2 x\\,dx$\n\\begin{sol}\n $\\ds (\\sin^3x)/3-(\\sin^5x)/5+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sin x (\\cos x)^{3/2}\\,dx$\n\\begin{sol}\n $\\ds -2(\\cos x)^{5/2}/5+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sec^2 x\\csc^2 x\\,dx$\n\\begin{sol}\n $\\tan x-\\cot x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\tan^3x \\sec x\\,dx$\n\\begin{sol}\n $\\ds (\\sec^3x)/3-\\sec x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\left(\\frac{1}{\\csc x}+\\frac{1}{\\sec x}\\right)\\,dx$\n\\begin{sol}\n $\\ds -\\cos x+\\sin x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int\\frac{\\cos^2x+\\cos x+1}{\\cos^3x}\\,dx$\n\\begin{sol}\n $\\ds \\frac{3}{2}\\ln|\\sec x+\\tan x|+\\tan x+\\frac{1}{2}\\sec x\\tan x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x\\sec^2(x^2)\\tan^4(x^2)\\,dx$\n\\begin{sol}\n $\\ds \\frac{\\tan^5(x^2)}{10}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "230db1a05be0c696ae31eed6886b7883d1ec6f4a", "size": 34706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-2-powers-of-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": "7-techniques-of-integration/7-2-powers-of-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": "7-techniques-of-integration/7-2-powers-of-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": 43.3825, "max_line_length": 479, "alphanum_fraction": 0.6366046217, "num_tokens": 13909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7799928900257127, "lm_q2_score": 0.8791467611766711, "lm_q1q2_score": 0.6857282230069367}}
{"text": "\\subsection{Principle of proof by contradiction}\n\nLet us suppose, that we want to (have to) prove the implication\n\\begin{equation}\n \\label{eq:contradiction_implication}\n v_1 \\Rightarrow v_2,\n\\end{equation}\nwhere $v_1, v_2$ are statements\\footnote{statement is a meaningful declarative sentence that is either true or false}. Suppose that \"standart\" direct proof in form\n\\begin{displaymath}\n v_1 \\Rightarrow ~~~ \n \\hat{v}_1 \\Rightarrow\n \\dots\n \\Rightarrow \\hat{v}_m\n ~~~ \\Rightarrow v_2\n\\end{displaymath}\nis not suitable or too complicated. Here $\\hat{v}_1, \\dots, \\hat{v}_m$ denote auxiliary statements presenting the small partial steps during the proof.\n\nAt first, let us recall the \\emph{Truth table} of the implication and other interesting relationship between statements (i.e. composed statements). \nIn Table \\ref{table:statements}, $1$ denotes that the statement is \\emph{true}, $0$ denotes \\emph{false}, and $v'$ is the negation of statement $v$.\n\n\\begin{table}[h]\n%\\def\\arraystretch{1.3}\n\\centering\n\\begin{tabular}{C{0.05\\linewidth} | C{0.05\\linewidth} || C{0.1\\linewidth} | C{0.1\\linewidth} | C{0.1\\linewidth} }\n\\hline\n $v_1$ & $v_2$ & $v_1 \\Rightarrow v_2$ & $v_1' \\vee v_2$ & $v_1 \\wedge v_2'$ \\\\\n\\hline\n 1 & 1 & 1 & 1 & 0 \\\\\n 1 & 0 & 0 & 0 & 1 \\\\\n 0 & 1 & 1 & 1 & 0 \\\\\n 0 & 0 & 1 & 1 & 0 \\\\\n\\hline\n\\end{tabular}\n\\caption{Truth of selected composed statements; notice that 3th and 4th columns are equivalent, 5th is the negation of 3th and 4th column}\n\\label{table:statements}\n\\end{table}\n\nPlease, notice that from the table it is clear that statement $v_1 \\Rightarrow v_2$ is equivalent to $v_1' \\vee v_2$. However, instead of proving this statement (the first one\nor the second one, it does not matter which one, since they are equivalent), we can prove that the negation  of this statement is not true\n\\footnote{because if the negation is not true, than the original statement is true}. The negation of implication is given by $v_1 \\wedge v_2'$, see Table \\ref{table:statements}.\nTo see the real relationship between $v_1' \\vee v_2$ and $v_1 \\wedge v_2'$, please, see also so-called \\emph{De-Morgan's laws}.\n\nTherefore, if we want to prove the implication \\eqref{eq:contradiction_implication}, then we rather examine $v_1 \\wedge v_2'$, i.e. we suppose, that the assumptions of the implication are true and the result in not true in the same time.\nTo prove that this statement is not true, it is enought to show that it does not hold in any case, i.e. we state the \\emph{contradiction}.\n\nMoreover, if we consider additional quantifiers (like \\emph{for all} or \\emph{there exists}) and our statements depend on the parameters, \nthen during the negation of original implication statement, we have to perform negation also to all quantifiers.\nFor example the negation of\n\\begin{displaymath}\n \\forall \\alpha: v_1(\\alpha) \\Rightarrow v_2(\\alpha)\n\\end{displaymath}\nis given by\n\\begin{displaymath}\n \\exists \\alpha: v_1(\\alpha) \\wedge v_2'(\\alpha).\n\\end{displaymath}\nSo, if we prove that this $\\alpha$ does not exist, then we are done.\n\n\n\n\\subsection{Absolute values in constraints}\n\n\\begin{theorem}\nLet\n\\begin{itemize}\n \\item $f: \\mathbb{R}^n \\rightarrow \\mathbb{R}, f \\in C^1(\\mathbb{R}^n)$ be a convex function,\n \\item $c \\in \\mathbb{R}^{+}$ is arbitrary constant,\n \\item $S \\in \\mathbb{R}^{n,2n}$ is a matrix defined by\n \\begin{displaymath}\n  S := \n  \\left[\n   \\begin{array}{ccccccc}\n     1 & -1 & & & & & \\\\\n      &  & 1 & -1 & & & \\\\\n      &  & &  & \\ddots & & \\\\\n      &  &  &  & & 1 & -1 \n   \\end{array}\n  \\right],\n \\end{displaymath}\n \\item $h(y) := f(Sy), h: \\mathbb{R}^{2n} \\rightarrow \\mathbb{R}$.\n\\end{itemize}\nThen if there exists a solution of optimization problem\n\\begin{equation}\n \\label{eq:absvalconstr1}\n \\bar{y} := \\arg \\min h(y) ~~~ \\textrm{subject to} ~~~ \\sum\\limits_{i=1}^{2n} y_i \\leq c ~~ \\textrm{and} ~~ y \\geq 0,\n\\end{equation}\nthen $\\bar{x} := S \\bar{y}$ is a solution of optimization problem\n\\begin{equation}\n \\label{eq:absvalconstr2}\n \\bar{x} = \\arg \\min f(x) ~~~ \\textrm{subject to} ~~~ \\Vert x \\Vert_1 \\leq c.\n\\end{equation}\nMoreover\n\\begin{equation}\n \\label{eq:absvalconstr3}\n\\forall i = 1,\\dots,n: \\bar{y}_{2i-1} \\cdot \\bar{y}_{2i} = 0.\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nAt first, notice that $h \\in C^1(\\mathbb{R}^{2n})$ is also a convex function and (here $\\langle g(x),x=\\hat{x} \\rangle$ denotes function value of $g(x)$ in point $\\hat{x}$)\n\\begin{equation}\n  \\label{eq:absvalconstr4}\n  \\langle \\nabla h(y), y = \\hat{y} \\rangle = \n  \\langle \\nabla f(Sy), y = \\hat{y} \\rangle = \n  \\langle S^T \\nabla f(x), x = S \\hat{y} \\rangle.\n\\end{equation}\nSince we suppose existence of $\\bar{y}$ as a solution of \\eqref{eq:absvalconstr1}, then from necessary optimality condition (see \\todo{give cite Boyd, Vandenberghe: Convex Optimization, page 139, equation 4.21})\nwe get (here $\\langle v,w \\rangle$ denotes scalar product of vectors $v,w \\in \\mathbb{R}^m$)\n\\begin{equation}\n \\label{eq:absvalconstr5}\n  \\langle \\nabla h(\\bar{y}), y - \\bar{y} \\rangle \\geq 0, ~~~ \\forall y \\in \\Omega_y,\n\\end{equation}\nwhere $\\Omega_y \\subset \\mathbb{R}^{2n}$ is a feasible set of \\eqref{eq:absvalconstr1}. Using \\eqref{eq:absvalconstr4}, we can write condition \\eqref{eq:absvalconstr5}\nin form\n\\begin{equation}\n \\label{eq:absvalconstr6}\n  \\langle S^T \\nabla f(S \\bar{y}), y - \\bar{y} \\rangle \\geq 0, ~~~ \\forall y \\in \\Omega_y.\n\\end{equation}\nLet us denote $\\bar{x} := S \\bar{y}$. Using the definition of scalar product\n\\begin{displaymath}\n \\forall v,w \\in \\mathbb{R}^m: \\langle v,w \\rangle = v^T w = \\sum\\limits_{i = 1}^{m} v_i w_i,\n\\end{displaymath}\nwe can write the left part of \\eqref{eq:absvalconstr6} in form\n\\begin{equation}\n \\label{eq:absvalconstr7}\n \\langle S^T \\nabla f(\\bar{x}), y - \\bar{y} \\rangle\n = \\left( S^T \\nabla f(\\bar{x}) \\right)^T \\left( y - \\bar{y} \\right)\n = \\left( \\nabla f(\\bar{x}) \\right)^T S \\left( y - \\bar{y} \\right)\n = \\langle \\nabla f(\\bar{x}), Sy - \\bar{x} \\rangle.\n\\end{equation}\nIt remains to prove the relationship between $\\Omega_x$ (feasible set of \\eqref{eq:absvalconstr2}) and $\\Omega_y$ (feasible set of \\eqref{eq:absvalconstr1}) in form\n\\begin{equation}\n \\label{eq:absvalconstr8}\n \\begin{array}{ll}\n  \\forall y \\in \\mathbb{R}^{2n}: & y \\in \\Omega_y ~~ \\Rightarrow ~~ Sy \\in \\Omega_x, \\\\\n  \\forall x \\in \\mathbb{R}^{n}: & x \\in \\Omega_x ~~ \\Rightarrow ~~ \\exists ! y \\in \\Omega_y: Sy = x, \n \\end{array}\n\\end{equation}\nbecause if \\eqref{eq:absvalconstr8} holds, then we are able to write \\eqref{eq:absvalconstr6} using \\eqref{eq:absvalconstr7} in form\n\\begin{displaymath}\n \\forall x \\in \\Omega_x: \\langle \\nabla f(\\bar{x}), x - \\bar{x} \\rangle \\geq 0,\n\\end{displaymath}\nthat concludes that $\\bar{x} \\in \\Omega_x$ is solution of \\eqref{eq:absvalconstr5}.\\newline\n\n\\vspace{0.5cm}\n\n\\noindent To prove the first statement of \\eqref{eq:absvalconstr8}, let us consider $y \\in \\Omega_y$, i.e. $y \\in \\mathbb{R}^{2n}$ such that\n\\begin{equation}\n \\label{eq:absvalconstr9}\n \\sum\\limits_{i = 1}^{2n} y_i \\leq c, y \\geq 0.\n\\end{equation}\nIn following, we examine the L1-norm of $x := Sy$\n\\begin{equation}\n \\label{eq:absvalconstrst}\n \\Vert x \\Vert_1 = \\Vert Sy \\Vert_1 = \\Vert [y_2 - y_1, y_4 - y_3, \\dots, y_{2n} - y_{2n-1}]^T \\Vert_1 = \\sum\\limits_{i =1}^n \\vert y_{2i} - y_{2i-1} \\vert\n\\end{equation}\nusing auxiliary inequality; please, notice that\n\\begin{displaymath}\n \\forall \\alpha, \\beta \\in \\mathbb{R}: \\vert \\alpha - \\beta \\vert \\leq \\vert \\alpha \\vert + \\vert \\beta \\vert,\n\\end{displaymath}\ntherefore we can estimate \\eqref{eq:absvalconstrst}\n\\begin{displaymath}\n \\sum\\limits_{i = 1}^{n} \\vert y_{2i} - y_{2i-1} \\vert \\leq \\sum\\limits_{i=1}^n \\left( \\vert y_{2i} \\vert + \\vert y_{2i-1} \\vert \\right) = \\sum\\limits_{i=1}^{2n} \\vert y_i \\vert .\n\\end{displaymath}\nSince we assume that $y \\in \\Omega_y$, i.e. \\eqref{eq:absvalconstr9}, we can continue with estimation\n\\begin{displaymath}\n \\sum\\limits_{i=1}^{2n} \\vert y_i \\vert = \\sum\\limits_{i=1}^{2n} y_i  \\leq c,\n\\end{displaymath}\ni.e. $\\Vert x \\Vert_1 \\leq c$ and therefore $x \\in \\Omega_x$. \\newline\n\n\\vspace{0.5cm}\n\n\\noindent Now we prove the second statement of \\eqref{eq:absvalconstr8}. Suppose $x \\in \\Omega_x$, i.e.\n\\begin{equation}\n \\label{eq:absvalconstr12}\n \\Vert x \\Vert_1 = \\sum\\limits_{i=1}^n \\vert x_i \\vert \\leq c.\n\\end{equation}\nPlease, notice that for any $\\alpha \\in \\mathbb{R}$, there exist $\\alpha^{+}, \\alpha^{-} \\geq 0$ such that\n\\begin{equation}\n \\label{eq:absvalconstr10}\n \\begin{array}{rcl}\n  \\alpha & = & \\alpha^{+} - \\alpha^{-}, \\\\\n  \\vert \\alpha \\vert & = & \\alpha^{+} + \\alpha^{-},\n \\end{array}\n\\end{equation}\n(for instance\nif $\\alpha \\geq 0$, then we can choose $\\alpha^{+}:=\\alpha, \\alpha^{-}:=0$;\nif $\\alpha < 0$, then we can choose $\\alpha^{+}:=0, \\alpha^{-}:= -\\alpha$ )\n\\footnote{in fact, in the end of the proof it will be clear that this decomposition is only one possible choice}.\nUsing \\eqref{eq:absvalconstr10}, we can decompose each component $x_i, i=1,\\dots,n$ into\n\\begin{equation}\n \\label{eq:absvalconstr11}\n \\begin{array}{rcl}\n  x_i & = & y_{2i-1} - y_{2i}, \\\\\n  \\vert x_i \\vert & = & y_{2i-1} + y_{2i},\n \\end{array}\n\\end{equation}\nwhere $y \\in \\mathbb{R}^{2n}, y \\geq 0$ is a new vector.\nWe examine the first condition of \\eqref{eq:absvalconstr9} using the second equality of \\eqref{eq:absvalconstr11} \nand assumption \\eqref{eq:absvalconstr12}\n\\begin{displaymath}\n \\sum\\limits_{i=1}^{2n} y_i = \\sum\\limits_{i =1}^{n} y_{2i-1} + y_{2i} = \\sum\\limits_{i=1}^{n} \\vert x_i \\vert \\leq c.\n\\end{displaymath}\nTherefore, we can state that $y \\in \\Omega_y$. Moreover, notice that from the first equality in \\eqref{eq:absvalconstr11}, it holds $x = Sy$.\n\n\\vspace{0.5cm}\n\n\\noindent To prove \\eqref{eq:absvalconstr3}, it is sufficient to show that \\eqref{eq:absvalconstr10} gives us $\\alpha^{+} \\cdot \\alpha^{-} = 0$\n\\footnote{notice that we do not need assumption $\\alpha^{+},\\alpha^{-} \\geq 0$}, \ni.e.\n\\begin{equation}\n \\label{eq:absvalconstr17}\n \\left.\n \\begin{array}{rcl}\n  \\alpha & = & \\alpha^{+} - \\alpha^{-} \\\\\n  \\vert \\alpha \\vert & = & \\alpha^{+} + \\alpha^{-}\n \\end{array}\n \\right\\rbrace ~~~ \\Rightarrow\n ~~~ \\alpha^{+} \\cdot \\alpha^{-} = 0.\n\\end{equation}\nSuppose by contradiction that $\\alpha^{+} \\cdot \\alpha^{-} \\neq 0$, i.e.\n\\begin{equation}\n \\label{eq:absvalconstr13}\n \\alpha^{+} \\neq 0 ~~~~ \\textrm{and} ~~~~ \\alpha^{-} \\neq 0.\n\\end{equation}\nNow we get rid of absolute value in system in assumption of \\eqref{eq:absvalconstr17}.\nWe examine both of possible situations:\n\\begin{itemize}\n \\item if $\\alpha \\geq 0$, then the solution of system\n  \\begin{displaymath}\n   \\begin{array}{rcl}\n    \\alpha & = & \\alpha^{+} - \\alpha^{-}, \\\\\n    \\alpha& = & \\alpha^{+} + \\alpha^{-}, \n   \\end{array}\n  \\end{displaymath}\n  is given by $\\alpha^{+} = \\alpha, \\alpha^{-} = 0$, which is a contradition with \\eqref{eq:absvalconstr13}.\n \\item if $\\alpha < 0$, then the solution of system\n  \\begin{displaymath}\n   \\begin{array}{rcl}\n    \\alpha & = & \\alpha^{+} - \\alpha^{-}, \\\\\n    -\\alpha& = & \\alpha^{+} + \\alpha^{-}, \n   \\end{array}\n  \\end{displaymath}\n  is given by $\\alpha^{+} = 0, \\alpha^{-} = -\\alpha$, which is a contradition with \\eqref{eq:absvalconstr13}.\n\\end{itemize}\n\nWe proved that the solution of the system \\eqref{eq:absvalconstr11} is unique, therefore for each $x \\in \\Omega_x$ there exists unique $y \\in \\Omega_y$ and $x = Sy$.\n\n\\end{proof}\n\n\\begin{example}\nLet us consider the basic quadratic programming problem - the projection (Euclidean) onto feasible set. In this case, we will consider a feasible set described by the L1-norm.\nOn this simple example, we demonstrate the computation of gradient in equation \\eqref{eq:absvalconstr4}.\nFor any $p \\in \\mathbb{R}^2$, we define projection onto set $\\Omega$ as a solution of optimization problem\n\\begin{displaymath}\n P_{\\Omega} (p) = \\arg \\min\\limits_{x \\in \\Omega} \\Vert x - p \\Vert, ~~~ \\Omega := \\lbrace x \\in \\mathbb{R}^2: \\Vert x \\Vert_1 \\leq 1 \\rbrace\n\\end{displaymath}\n(find the point from $\\Omega$ which is the nearest to given arbitrary $p$).\nNotice that the problem is equivalent to\n\\begin{displaymath}\n P_{\\Omega} (y) = \\arg \\min\\limits_{x \\in \\Omega} \\frac{1}{2}\\Vert x - p \\Vert^2 = \\arg \\min\\limits_{x \\in \\Omega} \\underbrace{\\frac{1}{2} x^T I x - p^T x}_{=: f(x)}\n\\end{displaymath}\nwith gradient\n\\begin{displaymath}\n \\nabla f(x) = x - p.\n\\end{displaymath}\nLet us define the function $h: \\mathbb{R}^{4n} \\rightarrow \\mathbb{R}$ by\n\\begin{displaymath}\n h(y) := f(Sy) = \\frac{1}{2} (Sy)^T I Sy - p^T Sy = \\frac{1}{2} y^T S^T S y - (S^Tp)^T y.\n\\end{displaymath}\nThe gradient of this function is given by\n\\begin{displaymath}\n \\nabla h(y) = S^T S y - S^Tp = S^T ( Sy-p) = S^T \\nabla f(Sy).\n\\end{displaymath}\nInstead of solving the original problem, we will rather solve\n\\begin{displaymath}\n \\hat{y} = \\arg \\min\\limits_{y \\in \\Omega_y} \\frac{1}{2} y^T S^T S y - (S^Tp)^T y, ~~~ \\Omega_y := \\lbrace y \\in \\mathbb{R}^4: y_1 + y_2 + y_3 + y_4 \\leq c ~ \\vee ~ y \\geq 0 \\rbrace\n\\end{displaymath}\nand the solution of original problem will be given by $P(p) = S\\hat{y}$. Notice that $S^TS$ is SPS Hessian matrix of $h$, therefore $h$ is convex function (but not strictly convex).\n\\end{example}\n\n\\subsection{QP solvability}\n\n\n", "meta": {"hexsha": "577ef76f1cafb90e115c5c44ed905d4d4729df91", "size": 13133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/PASC_report/section/supplementary.tex", "max_stars_repo_name": "eth-cscs/PASC_inference", "max_stars_repo_head_hexsha": "de66682f07b65dd21c7ada2fda05f21156e8cf6d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2016-11-26T10:54:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-24T06:50:04.000Z", "max_issues_repo_path": "Documents/PASC_report/section/supplementary.tex", "max_issues_repo_name": "eth-cscs/PASC_inference", "max_issues_repo_head_hexsha": "de66682f07b65dd21c7ada2fda05f21156e8cf6d", "max_issues_repo_licenses": ["MIT"], "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/PASC_report/section/supplementary.tex", "max_forks_repo_name": "eth-cscs/PASC_inference", "max_forks_repo_head_hexsha": "de66682f07b65dd21c7ada2fda05f21156e8cf6d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-11-21T16:58:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-25T12:47:19.000Z", "avg_line_length": 46.2429577465, "max_line_length": 237, "alphanum_fraction": 0.6738749714, "num_tokens": 4770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8791467580102419, "lm_q1q2_score": 0.6857282205371443}}
{"text": "\\section{Ordinary differential equations}\n\nFor the clearest description of the model, we refer the reader to our code repository, because our object-oriented approach to software development is intended to be highly transparent and readable. For those who prefer dynamical systems such as those presented in the form of ordinary differential equations, we present the following.\n\n    \n    \\[\\frac{dS_{a}}{dt}=-\\lambda_{a}(t)\\times\\sigma_{a}\\times S_{a}\\]\n    \\[\\frac{dE_{a}}{dt}=\\lambda_{a}(t)\\times\\sigma_{a}\\times S_{a}-\\alpha E_{a}\\]\n    \\[\\frac{dP_{a,c}}{dt}=p_{a,c}(t)\\times \\alpha E_{a}-\\nu P_{a,c}\\]\n    \\[\\frac{dI_{a,c}}{dt}=\\nu P_{a,c}-\\gamma_{c}I_{a,c}\\]\n    \\[\\frac{dL_{a,c}}{dt}=\\gamma_{c}I_{a,c}-\\delta_{a,c}L_{a,c}-\\mu_{a,c}L_{a,c}\\]\n    \\[\\frac{dR_{a}}{dt}=\\sum_{c}{}\\delta_{a,c}L_{a,c}\\]\n    where\n    \\[\\lambda_{a}=\\beta\\left[\\sum_{j,c}\\frac{\\epsilon\\times P_{j}}{N_{j}}\\times C_{a,j}(t)+\\sum_{j,c}\\frac{I_{j,c}\\times\\iota_{c}+L_{j,c}\\times\\kappa_{c}}{N_{j}}\\times C_{a,j}(t)\\right]\\]\n    \\[\\sum_{c}p_{a,c}(t)=1,\\forall t\\in\\mathbb{R}\\]\n    \\[\\textbf{C}_{0}=\\textbf{C}_{H}+\\textbf{C}_{S}+\\textbf{C}_{W}+\\textbf{C}_{L}\\]\n    \\[\\textbf{C}(t)=h(t)\\times\\textbf{C}_{H}+s(t)\\times\\textbf{C}_{S}+w(t)\\times\\textbf{C}_{W}+l(t)\\times\\textbf{C}_{L}\\]\n    \\[l(t)=\\frac{re(t)+gr(t)+pa(t)+tr(t)}{4}\\]\n    \n\\begin{table}[t] \n\n    \\begin{tabular}{| p{3.4cm} | p{10.4cm} |}\n        \\hline\n        \\textbf{Symbol} & \\textbf{Explanation} \\\\\n        \\hline\n        \\textit{S} & Persons susceptible to infection \\\\\n   \t\t\\textit{E} & Persons in the non-infectious incubation period \\\\\n    \t\\textit{P} & Persons in the incubation period \\\\\n   \t\t\\textit{I} & Persons in the early active disease period, before isolation or \t\t\t   \t\t\thospitalisation may occur \\\\\n    \t\\textit{L} & Persons in the late active disease period, after isolation or hospitalisation \t\t\tmay have occurred \\\\\n    \t\\textit{R} & Persons in the recovered period, from which re-infection cannot occur\\\\\n     \t\\hline\n    \\end{tabular}\n\n\\end{table}\n\n\\clearpage\n\\begin{table}[t] \n\n    \\begin{tabular}{| p{3.4cm} | p{10.4cm} |}\n\t\\hline\n\t\\textbf{Symbol} & \\textbf{Explanation} \\\\\n\t\\hline\n    \\textit{t} & Time  \\\\\n    {\\textit{a}} & Compartment of age group a \\\\\n    {\\textit{c}} & Compartment of clinical stratification c \\\\\n    $\\sigma$ & Relative susceptibility to infection \\\\\n    $\\alpha$ & Rate of progression from non-infectious to infectious incubation period \\\\\n    $\\nu$ & Rate of progression from infectious incubation to early active disease \\\\\n    $\\gamma$ & Rate of progression from early active disease to late active disease \\\\\n    $\\mu$ & Rate of disease-related death \\\\\n    $\\epsilon$ & Relative infectiousness of pre-symptomatic compartment \\\\\n    $\\iota$ & Clinical stratification infectiousness vector for early active compartment \\\\\n    $\\kappa$ & Clinical stratification infectiousness vector for late active compartments \\\\\n    $\\beta$ & Probability of infection per contact between an infectious and susceptible individual \\\\\n    \\textit{j} & Infectious populations \\\\\n    \\textit{p} & Proportion progressing to each clinical stratification \\\\\n    \\textbf{C} & Mixing matrix \\\\\n    \\textbf{H} & Household contribution to mixing matrix \\\\\n    \\textbf{W} & Workplace contribution to mixing matrix \\\\\n    \\textbf{O} & Other locations contribution to mixing matrix \\\\\n    \\textbf{S} & Schools contribution to mixing matrix \\\\\n    \\textit{l} & Other locations macrodistancing function of time \\\\\n    \\textit{w} & Function fit to Google mobility data for workplaces \\\\\n    \\textit{s} & Function fit to Google mobility data for schools \\\\\n    \\textit{re} & Function fit to Google mobility data for retail and recreation \\\\\n    \\textit{gr} & Function fit to Google mobility data for grocery and pharmacy \\\\\n    \\textit{pa} & Function fit to Google mobility data for parks \\\\\n    \\textit{tr} & Function fit to Google mobility data for transit stations \\\\\n    \\hline\n    \\end{tabular}\n\n\\end{table}\n\n\\clearpage\n\n\n", "meta": {"hexsha": "95e6b560a39cca4bdd949980a28747ed90f78204", "size": 3986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tex_descriptions/models/covid_19/model_equations.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": 14, "max_stars_repo_stars_event_min_datetime": "2020-03-11T06:15:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T03:38:35.000Z", "max_issues_repo_path": "docs/tex/tex_descriptions/models/covid_19/model_equations.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": 96, "max_issues_repo_issues_event_min_datetime": "2020-01-29T05:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:48:46.000Z", "max_forks_repo_path": "docs/tex/tex_descriptions/models/covid_19/model_equations.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": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-24T00:38:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T16:19:03.000Z", "avg_line_length": 51.7662337662, "max_line_length": 335, "alphanum_fraction": 0.6640742599, "num_tokens": 1225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6856262734162057}}
{"text": "\\section{Scheduling for M/G/1}\n\\label{sec:Scheduling-M-G-1}\n\nThe scheduling policy can hugely influence the mean response time and other metrics.\nScheduling policies can be categorized based on whether the policy is preemptive or not, and whether it assumes knowledge of job size or not.\n\nA \\textit{work-conserving} scheduling policy is one that always performs work on some job when there is a job in the system, and does not create new work.\nGiven an arrival sequence and a time, all work-conserving policies have the same work left in system and server utilization.This does not imply that all work-conserving policies have the same mean response time.\n\nWhen evaluating a scheduling policy, we take into account the following metrics:\n\n\\begin{description}\n\t\n\t\\item [Response Time ($T$)]\n\tWe denote with $T(x)$ the response time for job size $x$.\n\t\n\t\\item [Queueing Time ($T_{Q}$)]\n\t\n\t\\item [System Jobs ($N$)]\n\t\n\t\\item [Queueing Jobs ($N_{Q}$)]\n\t\n\t\\item [Slowdown ($Slowdown$)]\n\t\\begin{equation}\n\t\\label{eqn:Slowdown}\n\tSlowdown=\\frac{T}{S}\n\t\\end{equation}\n\tWe denote with $Slowdown(x)$ the slowdown for job size $x$.\n\t\n\t\\item [Tail Behavior ($Tail-Behavior$)]\n\t\\begin{equation}\n\t\\label{eqn:Tail-Behavior}\n\tTail-Behavior=\\probability{T>x}\n\t\\end{equation}\n\t\n\t\\item [Starvation]\n\tWe say that policy $\\mathit{P}$ produces \\textit{starvation} if for some $x$\n\t\\begin{equation}\n\t\\label{eqn:Starvation}\n\t\\expected{Slowdown^{\\mathit{P}}(x)}>\\expected{Slowdown^{\\mathit{PS}}(x)}\n\t\\end{equation}\n\twhere $\\mathit{PS}$ is the Processor-Sharing scheduling policy.\n\t\n\t\\item [Fairness]\n\tWe say that policy $\\mathit{P}$ is fair if for all $x$\n\t\\begin{equation}\n\t\\label{eqn:Fairness}\n\t\\expected{Slowdown^{\\mathit{P}}(x)}<\\expected{Slowdown^{\\mathit{PS}}(x)}\n\t\\end{equation}\n\twhere $\\mathit{PS}$ is the Processor-Sharing scheduling policy.\n\tAlternatively, we say that policy $\\mathit{P}$ is fair if $Slowdown^{\\mathit{P}}(x)$ is equal for all $x$.\n\t\n\\end{description}\n\nMore often we consider absolute mean metrics and mean metrics with respect to job sizes.\nSometimes however, variance in response time and variance in slowdown are more important than the respective means.\n\nFew books analyze scheduling policies in stochastic environment: the best are \\cite{conway2012theory,kleinrock1976queueing}.\nThe fairness metric we used is defined in \\cite{bansal2001analysis}. The slowdown metric has received attention only recently in \\cite{hyytia2012minimizing}.\n\nIn the following sections, we evaluate various scheduling policies for $M/G/1$. We base our evaluation on $\\expected{T},\\expected{T(x)},\\expected{Slowdown(x)}$.\n\nNotice that $\\expected{Slowdown}\\neq\\frac{\\expected{T}}{\\expected{S}}$. We derive the Slowdown as follows:\n\n\\begin{equation*}\n\\expected{Slowdown(x)}=\\expected{\\frac{T}{S}|S=x}=\\expected{\\frac{T(x)}{x}}=\\frac{\\expected{T(x)}}{x}\n\\end{equation*}\n\nand\n\n\\begin{equation*}\n\\expected{Slowdown}=\\int_{x}\\expected{Slowdown(x)}f_{S}(x)\\partial x=\\int_{x}\\frac{\\expected{T(x)}}{x}f_{S}(x)\\partial x\n\\end{equation*}\n\nThe \\textit{job age} is the total service it has received so far. If job size distribution has decreasing failure rate, then the greater the job age, the greater its expected remaining service time.", "meta": {"hexsha": "2060b933028c4f2780bc848108173fc312840411", "size": 3210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/scheduling-m-g-1.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/scheduling-m-g-1.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/scheduling-m-g-1.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": 42.8, "max_line_length": 211, "alphanum_fraction": 0.7420560748, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.845942452844325, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.6856185237241421}}
{"text": "\\documentclass{beamer}\n\n\\input{../../shared_slides.tex}\n\n\\title{Matrix games}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\\frame{\\tableofcontents}\n\n\\section{Introduction}%\n\n\\begin{frame}\n  \\frametitle{Introduction}\n  Given\n  \\begin{itemize}\n    \\item Player I (rows, Alice)\n          \\item Player II (columns, Bob)\n          \\item a \\emph{payoff} matrix $A \\in \\R^{m \\times n}$\n  \\end{itemize}\n  Every round\n  \\begin{enumerate}\n    \\item Alice picks (row) strategy $i\\in [m]:= \\{1,\\dots, m\\}$\n          Bob picks (col) strategy $j\\in [n]$\n    \\item Bob pays Alice the amount $a_{i,j}$\n  \\end{enumerate}\n  \\begin{center}\n    \\textbf{zero-sum game}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Example: penalty game}\n  \\begin{figure}[ht]\n    \\centering\n    \\includegraphics[scale=0.4]{penalty-game}\n    \\caption{penalty game}\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Example: prisoners dilemma}\n  \\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{prison}\n    \\caption{prisoners dilemma}\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Worst case}\n\n  \\begin{itemize}\n    \\item if Alice chooses strategy $i$ she gets (at least): $\\min_{j\\in [n]} a_{i,j}$\n    \\onslide<2->{\\item Alice can ensure payoff $\\max_{i\\in [m]} \\min_{j\\in [n]} a_{i,j}$}\n    \\onslide<3->{\\item Bob pays (at most) $\\min_{j\\in [n]} \\max_{i\\in [m]} a_{i,j}$}\n  \\end{itemize}\n  \\onslide<4->{%\n    We claim:\n    \\begin{equation}\n      \\max_i \\min_j a_{i,j} \\le \\min_{j} \\max_i a_{i,j}\n    \\end{equation}\n    \\begin{center}\n      \\textit{``Tallest dwarf is not as tall as the smallest giant.''}\n    \\end{center}\n    But: \\textbf{No equality in general!}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Proof of the min-max theorem}\n  \\begin{equation}\n    \\begin{aligned}\n      a_{ij} &\\le a_{ij} & \\forall i,j \\\\\n      \\onslide<2->{a_{ij} &\\le \\max_i a_{ij} & \\forall i,j }\\\\\n      \\onslide<3->{\\min_j a_{ij} &\\le \\min_j \\max_i a_{ij} & \\forall i}\\\\\n    \\end{aligned}\n  \\end{equation}\n  \\onslide<4->{%\n  \\begin{definition}\n    We call $(i^*, j^*)$ a saddle point (or \\emph{Nash equilibrium}) if\n    \\begin{equation}\n      \\max_i a_{ij^*} = a_{i^*j^*} = \\min_j a_{i^*j}.\n    \\end{equation}\n    These are called \\emph{pure strategies}.\n  \\end{definition}\n  }\n\\end{frame}\n\n% Talk about stackelberg?\n\n\\begin{frame}\n  \\frametitle{Rock paper scissors}\n  \\begin{equation}\n    \\begin{array}{l|ccc}\n        & R & P & S \\\\\n      \\hline\n      R & 0 & -1 & 1 \\\\\n      P & 1 & 0 & -1 \\\\\n      S & -1 & 1 & 0\n    \\end{array}\n  \\end{equation}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Mixed Strategies}\n  \\textit{With pure strategies we do not always have a saddle point.}\n\n  \\begin{block}{von Neumann (1928) --- Mixed strategies}\n    \\begin{itemize}\n      \\item Alice picks strategies $1, \\dots, m$ \\emph{with probabilities} $x\\in \\Delta_m$\n      \\item Bob picks strategies $1, \\dots, n$ \\emph{with probabilities} $x\\in \\Delta_n$\n    \\end{itemize}\n    Expected gain of Alice is\n    \\begin{equation}\n      \\langle x, Ay \\rangle = \\sum_{i,j} a_{ij} x_i y_j\n    \\end{equation}\n  \\end{block}\n  \\onslide<2->{%\n    \\begin{theorem}{Saddle point exists}\n      Expected gain of Alice $=$ expected loss of Bob\n      \\begin{equation}\n        \\max_{x \\in \\Delta} \\min_{y \\in \\Delta} \\langle x, Ay \\rangle = \\min_{y \\in \\Delta} \\max_{x \\in \\Delta} \\langle x, Ay \\rangle.\n      \\end{equation}\n\n    \\end{theorem}\n  }\n\\end{frame}\n\n\\section{Algorithms}%\n\\label{sec:}\n\n\\begin{frame}\n  \\frametitle{Stopping criteria}\n  \\begin{equation}\n    \\begin{aligned}\n      \\min_{x \\in \\Delta} \\max_{y \\in \\Delta} \\langle x, Ay \\rangle =: v \\\\\n      \\max_{y \\in \\Delta} \\min_{x \\in \\Delta} \\langle x, Ay \\rangle = v\n    \\end{aligned}\n  \\end{equation}\n  \\begin{block}{stopping criterion}\n    \\begin{equation}\n      \\begin{aligned}\n        f_p(x) - f_p(x^*) &= f_p(x) - v \\onslide<2->{\\textcolor{red}{\\, \\le \\epsilon/2}}\\\\\n        f_d(y^*) - f_d(y) &= v - f_d(y) \\onslide<2->{\\textcolor{red}{\\, \\le \\epsilon/2}} \\\\\n        \\onslide<3->{\\Rightarrow f_p(x) - f_d(y) \\le \\epsilon}\n      \\end{aligned}\n    \\end{equation}\n  \\end{block}\n  \\begin{center}\n    Before we never had the optimal value!\n  \\end{center}\n  % how does this fit in?\n  Solution will always be on the boundary:\n  \\begin{equation}\n    f_p(x) = \\max_{y \\in \\Delta} \\langle A^T x, y \\rangle = \\max_{j} \\langle A^T x, e_j \\rangle\n  \\end{equation}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{}\n  Consider\n  \\begin{equation}\n      \\min_{x \\in \\Delta} \\max_{y \\in \\Delta} \\langle x, Ay \\rangle\n  \\end{equation}\n  as a minimization problem\n  \\begin{equation}\n      \\min_{x \\in \\Delta}  f_p(x) = \\langle x, A y^* \\rangle .\n  \\end{equation}\n  Then, by the \\textbf{first-order optimality condition}\n  \\begin{equation}\n    x^* \\in \\argmin_{x \\in \\Delta} f_p(x)  \\Leftrightarrow \\langle \\nabla f_p(x^*), x-x^* \\rangle \\ge 0 \\quad \\forall x \\in \\Delta\n  \\end{equation}\n  Thus\n  \\begin{equation}\n    \\begin{aligned}\n      \\langle A^T y^*, x-x^* \\rangle &\\ge 0 \\quad \\forall  x \\in \\Delta \\\\\n      \\langle -A x^*, y-y^* \\rangle &\\ge 0 \\quad \\forall  y \\in \\Delta \\\\\n    \\end{aligned}\n  \\end{equation}\n  Concatenate the two conditions to get\n  \\begin{equation}\n  \\left\\langle \\begin{bmatrix}\n      0 & A^T \\\\\n      -A & 0\n    \\end{bmatrix}\n    \\left(\\begin{array}{c}\n      x^*\\\\ y^*\n    \\end{array}  \\right),\n    \\left(\\begin{array}{c}\n      x \\\\ y\n    \\end{array}  \\right)\n    -\n    \\left(\\begin{array}{c}\n      x^* \\\\\n      y^*\n    \\end{array} \\right)\n \\right\\rangle \\ge 0.\n  \\end{equation}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Games as Variational Inequalities}\n  We had:\n  \\begin{equation}\n  \\left\\langle \\begin{bmatrix}\n      0 & A^T \\\\\n      -A & 0\n    \\end{bmatrix}\n    \\left(\\begin{array}{c}\n      x^*\\\\ y^*\n    \\end{array}  \\right),\n    \\left(\\begin{array}{c}\n      x \\\\ y\n    \\end{array}  \\right)\n    -\n    \\left(\\begin{array}{c}\n      x^* \\\\\n      y^*\n    \\end{array} \\right)\n \\right\\rangle \\ge 0.\n  \\end{equation}\n  By rewriting $z=(x,y)$ and $F(z) = [A^T y; Ax]$, then\n  \\begin{equation}\\tag{VI}\n    \\label{eq:VI}\n    \\langle F(z^*), z-z^* \\rangle \\ge 0 \\quad \\forall z \\in \\Delta_n \\times \\Delta_m =: C\n  \\end{equation}\n  \\begin{center}\n    \\textbf{Variational inequality}\n  \\end{center}\n\n  \\begin{block}{}\n  If $F = \\nabla \\phi$ then~\\eqref{eq:VI} would be equivalent to\n  \\begin{equation}\n    \\min_{z\\in C} \\, \\phi(z)\n  \\end{equation}\n  \\end{block}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Potential - integrability}\n\n  \\textbf{Question:} Does there exist a potential $\\phi$ for $F$, such that $F = \\nabla \\phi$\n\n  \\begin{block}{Integrability condition (from calculus)}\n    Is the case if\n    \\begin{equation}\n      \\frac{\\partial \\phi}{\\partial x \\partial y} = \\frac{\\partial \\phi}{\\partial y \\partial x}\n    \\end{equation}\n  \\end{block}\n  But\n  \\begin{equation}\n    \\frac{\\partial F_1}{\\partial y} = A^T \\neq - A = \\frac{\\partial F_2}{\\partial x}\n  \\end{equation}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{VI as Fixed point equation}\n  \\begin{block}{}\n    \\vspace{-0.5cm}\n  \\begin{align}\n    \\langle F(z^*), z-z^* \\rangle \\ge 0 \\quad \\forall z \\in C \\\\\n    \\Leftrightarrow z^* = P_C (z^* - F(z^*)) \\label{eq:FP}\\tag{FP}\n  \\end{align}\n  \\end{block}\n  \\begin{proof}\n    Applying the property of the projection\n    \\begin{equation}\n      \\langle P_C(x)-x, x' - P_C(x) \\rangle \\ge 0 \\quad \\forall x' \\in C\n    \\end{equation}\n    with~\\eqref{eq:FP}, gives\n    \\begin{equation}\n    \\langle z^* - (z^* - F(z^*)), z-z^* \\rangle \\ge 0 \\quad \\forall z \\in C.\\hfill \\qedhere\\qed\n    \\end{equation}\n  \\end{proof}\n  \\begin{itemize}\n    \\item should remind us of (projected) gradient descent\n          \\item when you see a fixed point equation: iterate!\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{But is it any good?}\n  \\begin{equation}\n    z_{k+1} = z_k - \\alpha F(z_k)\n  \\end{equation}\n  Then\n  \\begin{equation}\n    \\begin{aligned}\n      \\Vert z_{k+1} \\Vert^2 &= \\Vert z_k \\Vert^2 - \\underbrace{2 \\alpha \\langle F(z_k), z_k \\rangle}_{=0} + \\alpha^2 \\Vert F(z_k) \\Vert^2 \\\\\n      &=\\Vert z_k \\Vert^2 + \\alpha^2 \\Vert F(z_k) \\Vert^2 \\\\\n    \\end{aligned}\n  \\end{equation}\n  Resulting in $\\Vert z_{k+1} \\Vert \\ge \\Vert z_k \\Vert$.\n  \\begin{center}\n    $\\Rightarrow$ \\textbf{No bueno!}\n  \\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{}\n\nWe can still show\n  \\begin{theorem}\n    complexity of $\\mathcal{O}(1/\\sqrt{k})$ for \\textbf{averaged iterates} in terms of $f_p(x) - f_d(y)$.\n  \\end{theorem}\n\n  \\begin{itemize}\n    \\item with the same analysis as for subgradient descent\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Sketch of the proof}\n  With the notation $g_k = F(z_k)$ we get\n  \\begin{equation}\n    \\begin{aligned}\n      \\Vert x_{k+1} - x^* \\Vert^2 &\\le \\Vert x_k - \\alpha_k g_k - x^* \\Vert^2 \\\\\n      &= \\Vert x_k-x^* \\Vert^2 + 2 \\alpha_k \\langle g_k, x^*-x_k \\rangle + \\alpha^2 \\Vert g_k \\Vert^2.\n    \\end{aligned}\n  \\end{equation}\n  But now $\\langle g_k, x^* - x_k \\rangle = [f_d(y_k) - f_p(x_k)]$.\n  Rest of the proof is left as an exercise.\n\\end{frame}\n\n\n\\end{document}\n", "meta": {"hexsha": "a881a8aa1d2386bdee7ca29ffe502aec343ba51b", "size": 9039, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Matrix-games/Matrix_games.tex", "max_stars_repo_name": "sebnemyyl/optimization-for-DS-lecture", "max_stars_repo_head_hexsha": "e5cc08c0a0a55188ea9c2d6de453f1d8553cfebe", "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/Matrix-games/Matrix_games.tex", "max_issues_repo_name": "sebnemyyl/optimization-for-DS-lecture", "max_issues_repo_head_hexsha": "e5cc08c0a0a55188ea9c2d6de453f1d8553cfebe", "max_issues_repo_licenses": ["CC0-1.0"], "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/Matrix-games/Matrix_games.tex", "max_forks_repo_name": "sebnemyyl/optimization-for-DS-lecture", "max_forks_repo_head_hexsha": "e5cc08c0a0a55188ea9c2d6de453f1d8553cfebe", "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.1441441441, "max_line_length": 140, "alphanum_fraction": 0.6009514327, "num_tokens": 3329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.6856185079848334}}
{"text": "\\chapter{Formal Power Series}\n\\label{chapter:formal-power-series}\nFormal power series is an algebraic analogy of power series from analysis.\nA formal power series is something like\n$a_0 + x a_1 + x^2 a_2 + \\dots a_n x^n + \\dots$; to describe such an object it\nis enough to define the sequence $\\set{a_n}_{n \\ge 0}$ since $x$ is a variable.\n\\begin{definition}\n  We say that $F(x)$ is a \\emph{formal power series} in the variable $x$, if\n  $F(x) = \\set{f_n}_{n \\ge 0}$. To distinguish between formal power series and\n  sequences, we write formal power series as $\\sum_{n \\ge 0} f_n x^n$.\n  We say that $f_n$ is the coefficient of $x^n$ in $F(x)$.\n\n  We say that two formal power series $F(x)$ and $G(x)$ are equal iff for all\n  $n \\ge  0$, the coefficients of $x^n$ in $F(x)$ and $G(x)$ are the same.\n\n  The set of all the power series in the variable $x$ is denoted as\n  $\\R[[x]]$.\n\\end{definition}\n\\nomenclature[S]{$\\R[[x]]$}{denotes the set all the power series in the\nvariable $x$}\n\n\\section{Arithmetic Operations}\n\nWe can perform all the standard operations with the formal power series:\n\\begin{gather*}\n  \\sum_{n \\ge 0} a_n x^n \\pm \\sum_{n \\ge 0} b_n x^n =\n  \\sum_{n \\ge 0} (a_n \\pm b_n) x^n, \\\\\n  c \\sum_{n \\ge 0} a_n x^n =\n  \\sum_{n \\ge 0} (c a_n) x^n,\n  \\\\\n  \\text{and} \\\\\n  \\sum_{n \\ge 0} a_n x^n \\sum_{n \\ge 0} b_n x^n =\n  \\sum_{n \\ge 0} (\\sum_{k = 0}^n a_{k} b_{n - k}) x^n.\n\\end{gather*}\n\nThese operations satisfy all the properties we may expect from them.\n\\begin{theorem}\n  Let $F(x)$, $G(x)$, and $H(x)$ be some formal power series. Then the following\n  equalities hold:\n  \\begin{itemize}\n    \\item $(F(x) + G(x)) + H(x) = F(x) + (G(x) + H(x))$,\n    \\item $F(x) + G(x) = G(x) + F(x)$,\n    \\item $(F(x) G(x)) H(x) = F(x) (G(x) H(x))$,\n    \\item $F(x) G(x) = G(x) F(x)$, and\n    \\item $(F(x) + G(x)) H(x) = F(x)H(x) + G(x)H(x)$.\n  \\end{itemize}\n\\end{theorem}\n\nFor example, $(1 - x) (1 + x + x^2 + \\dots) = 1$. Thus we can say that the\nseries $(1 - x)$ has an inverse, and that inverse is equal to $1 + x + x^2 +\n\\dots$.\n\\begin{theorem}\n  A formal power series $\\sum_{n \\ge 0} f_n x^n$ has an inverse iff\n  $f_0 \\neq 0$ and moreover this inverse is unique.\n\\end{theorem}\n\\begin{proof}\n  Assume that a power series $F(x) = \\sum_{n \\ge 0} f_n x^n$ has an inverse\n  $G(x) = \\sum_{n \\ge 0} g_n x^n$. In this case $F \\cdot G = 1$ i.e.\n  $f_0 g_0 = 1$ and $f_0 \\neq 0$. Moreover,\n  $\\sum_{k = 0}^n f_k g_{n - k} = 0$; from which we can conclude that\n  \\begin{equation}\n    \\label{equation:inverse-of-formal-power-series}\n    g_n = -\\frac{1}{f_0} \\sum_{k > 0} f_k g_{n - k}.\n  \\end{equation}\n  This determine $g_n$ uniquely, as stated.\n\n  Conversely, if $f_0 \\neq 0$, (\\ref{equation:inverse-of-formal-power-series})\n  determines the sequence $\\set{g_n}_{n \\ge 0}$.\n\\end{proof}\n\n\\section{Composition}\nAnother operation we may need to perform is composition; a composition of\nthe power series $F(x)$ and $G(x)$ is a power series $F(G(x))$; i.e.\n$F(G(x)) = \\sum_{n \\ge 0} a_n G^n(x)$, where $F(x) = \\sum_{n \\ge 0} a_n x^n$\nNote that the composition is well-defined iff the coefficient of $x^0$ in $G(x)$\nis $0$ or if $F(x)$ is a polynomial.\n\n\\section{Derivative}\nLet $F(x) = \\sum_{n \\ge 0} f_n x^n$ be a formal power series. Then the\nderivative $F'(x)$ (we also denote it as $\\frac{d}{dx} F(x)$) of $F(x)$ is\nequal to\n$\\sum_{n \\ge 1} n f_n x^{n - 1} = \\sum_{n \\ge 0} (n + 1) f_{n + 1} x^n$.\n\nThe derivatives of formal power series satisfy the same properties as\nderivatives of functions.\n\\begin{theorem}\n  Let $F(x)$, $G(x)$, and $H(x)$ be some formal power series. Then the following\n  equalities hold:\n  \\begin{itemize}\n    \\item $\\frac{d}{dx}(F(x) + G(x)) = F'(x) + G'(x)$, and\n    \\item $\\frac{d}{dx}(F(x) G(x)) = F'(x)G(x) + F(x)G'(x)$.\n  \\end{itemize}\n\\end{theorem}\n\nAs a corollary of these statements we can derive a formula for the derivative of\n$1 / F(x)$.\n\\begin{corollary}\n  Let $F(x)$ be a formal power series such that $1 / F(x)$ exists. In this\n  case $\\frac{d}{dx} \\frac{1}{F(x)} = -\\frac{F'(x)}{F^2(x)}$.\n\\end{corollary}\n\\begin{proof}\n  Note that $F(x) \\frac{1}{F(x)} = 1$. Hence,\n  $\\frac{d}{dx}(F(x) \\frac{1}{F(x)}) = 0$. Using the formula for the derivative\n  of a product we may conclude that $F'(x)\\frac{1}{F(x)} +\n  F(x)\\frac{d}{dx}\\frac{1}{F(x)} = 0$. As a result,\n  $-\\frac{F'(x)}{F^2(x)} = \\frac{d}{dx} \\frac{1}{F(x)}$.\n\\end{proof}\n\n\\begin{remark}\n  If $F'(x) = 0$, then $F(x) = a_0$.\n\\end{remark}\n\nWe denote the formal power series $\\sum_{n \\ge 0} \\frac{1}{n!} x^n$ by $e^x$\n(since the Taylor series of $e^x$ is equal to\n$\\sum_{n \\ge 0} \\frac{1}{n!} x^n$).\n\\begin{remark}\n  If $F'(x) = F(x)$, then $F(x) = c e^x$ for some $c \\in \\R$.\n\\end{remark}\n", "meta": {"hexsha": "9e6ac28c0d9d5e6e3c4c41b7f9d3e445088a3dda", "size": 4674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/appendix/formal-power-series.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/appendix/formal-power-series.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/appendix/formal-power-series.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": 39.2773109244, "max_line_length": 80, "alphanum_fraction": 0.6123234917, "num_tokens": 1811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.6854898493272927}}
{"text": "\\lab{The SVD and Image Compression}{The SVD and Image Compression}\n\\label{lab:SVD}\n\\objective{The Singular Value Decomposition (SVD) is an incredibly useful matrix factorization that is widely used in both theoretical and applied mathematics.\nThe SVD is structured in a way that makes it easy to construct low-rank approximations of matrices, and it is therefore the basis of several data compression algorithms.\nIn this lab we learn to compute the SVD and use it to implement a simple image compression routine.\n}\n\n\\begin{comment} % Vague motivation, most of which is in the book.\nThe \\emph{Singular Value Decomposition} or \\emph{SVD} is a matrix decomposition that is widely used in both theoretical and applied mathematics.\nOriginally discovered by theoretical mathematicians, it is a canonical way to decompose a matrix.\nIts practical use became apparent later on when Erhard Schmidt showed that the SVD could be a computational tool for providing low-rank matrix approximations.\nModern developments continue to confirm the importance of the SVD in both computational and theoretical applications.\n\nThe theoretical use of the \\emph{Singular Value Decomposition} or \\emph{SVD} has long been appreciated.\nIn fact, the idea of a canonical way of decomposing a matrix was so alluring that the SVD was independently discovered by at least four people through use of both  integral equations and systems of linear equations.\n\nHowever, it wasn't until Erhard Schmidt showed how the SVD could be a computational tool for providing low-rank approximations that the practical applications became apparent.\nSince Schmidt's work, further developments have confirmed the importance of the SVD in both computational and theoretical applications.\n\\end{comment}\n\n\\begin{comment} % Historical background, super overkill.\nThe \\emph{Singular Value Decomposition} is so important that it was discovered multiple times by different people in different ways.\nThe foundation work in systems of linear equations was laid by Gauss and Cauchy in the 1820's and later by Jacobi in 1846 with his work with the LU decomposition; however, the real work with the SVD started with Eugenio Beltrami.\nIn a paper he published in 1873 he was the first to work with the SVD; he was limited to real, square, nonsingular matrices with distinct singular values.\nA year later, Camille Jordan published his own independent work that was more rigorous and avoided some of the pitfalls of Beltrami's research.\nTogether, Beltrami and Jordan are considered the co-discoverers of the singular value decomposition.\n\nLater, James Joseph Sylvester independently presented an iterative algorithm and a rule for carrying out the reduction in 1889.\nThis rule was essentially Beltrami's work.\nHowever Sylvester sent the note detailing his rule to the same journal Jordan had published in, showing not just his ignorance of Jordan's and Beltrami's works but his perception of the importance of the SVD.\n\nThe concurrent and independent derivation of the SVD shows its importance as a theoretical tool, but it wasn't until Erhard Schmidt discovered a computational use for the SVD that the practical applications became apparent.\nSchmidt used integral equations rather than linear equations to derive the SVD, but his most important contribution was showing how the SVD could be a computational tool to obtain optimal, low-rank approximations.\n\nSince Schmidt's work, further developments have confirmed the importance of the SVD in both practical and theoretical applications.\n\\end{comment}\n\nThe SVD of a matrix $A$ is a factorization $A = U \\Sigma V\\hrm$ where $U$ and $V$ have orthonormal columns and $\\Sigma$ is diagonal.\nThe diagonal entries of $\\Sigma$ are called the \\emph{singular values} of $A$ and are the square roots of the eigenvalues of $A\\hrm A$.\nSince $A\\hrm A$ is always positive semidefinite, its eigenvalues are all real and nonnegative, so the singular values are also real and nonnegative.\nThe singular values $\\sigma_i$ are usually sorted in decreasing order so that $ \\Sigma = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_n)$ with $\\sigma_1 \\geq \\sigma_2 \\geq \\ldots \\geq \\sigma_n \\geq 0$.\nThe columns $\\mathbf{u}_i$ of $U$, the columns $\\mathbf{v}_i$ of $V$, and the singular values of $A$ satisfy $A\\mathbf{v}_i = \\sigma_i \\mathbf{u}_i$.\n\nEvery $m\\times n$ matrix $A$ of rank $r$ has an SVD with exactly $r$ nonzero singular values.\nLike the QR decomposition, the SVD has two main forms.\n\\begin{itemize}\n    \\item \\textbf{Full SVD}: Denoted $A = U\\Sigma V\\hrm$.\n    $U$ is $m\\times m$, $V$ is $n\\times n$, and $\\Sigma$ is $m\\times n$.\n    The first $r$ columns of $U$ span $\\mathscr{R}(A)$, and the remaining $n -r$ columns span $\\mathscr{N}(A\\hrm)$.\n    Likewise, the first $r$ columns of $V$ span $\\mathscr{R}(A\\hrm)$, and the last $m - r$ columns span $\\mathscr{N}(A)$.\n    \\item \\textbf{Compact (Reduced) SVD}: Denoted $A = U_1\\Sigma_1 V\\hrm_1$.\n    $U_1$ is $m\\times r$ (the first $r$ columns of $U$), $V_1$ is $n \\times r$ (the first $r$ columns of $V$), and $\\Sigma_1$ is $r\\times r$ (the first $r\\times r$ block of $\\Sigma$).\n    This smaller version of the SVD has all of the information needed to construct $A$ and nothing more.\n    The zero singular values and the correpsonding columns of $U$ and $V$ are neglected.\n\\end{itemize}\n%\n\\begin{align*} % Full and compace SVD.\n\\begin{array}{cccc}\n\\textcolor{red}{U_1\\ (m \\times r)} & \\textcolor{blue}{\\Sigma_1\\ (r \\times r)} & \\textcolor{green}{V\\hrm_1\\ (r \\times n)} \\\\ \\\\\n\\left[\\begin{array}{ccccccc}\n\\arrayrulecolor{red}\n\\cline{2-4}\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{\\u_1} & \\cdots & \\rvl{\\u_r} & \\u_{r+1} & \\cdots & \\u_m \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n\\cline{2-4}\n\\end{array}\\right]\n&\n\\left[\\begin{array}{cccccccc}\n\\arrayrulecolor{blue}\n\\cline{2-4}\n& \\lvl{\\sigma_{1}}  &   & \\rvl{}         &   &        &   \\\\\n& \\lvl{}       & \\ddots & \\rvl{}         &   &        &   \\\\\n& \\lvl{}       &        & \\rvl{\\sigma_{r}} & &        &   \\\\\n\\cline{2-4}\n&              &        &                & 0 &        &   \\\\\n&              &        &                &   & \\ddots &   \\\\\n&              &        &                &   &        & 0 \\\\\n\\end{array}\\right]\n&\n\\left[\\begin{array}{ccccccc}\n\\arrayrulecolor{green}\n\\cline{2-6}\n& \\lvl{} & & \\v\\hrm_1 & & \\rvl{} & \\\\\n& \\lvl{} & & \\vdots   & & \\rvl{} & \\\\\n& \\lvl{} & & \\v\\hrm_r & & \\rvl{} & \\\\\n\\cline{2-6}\n& & & \\v\\hrm_{r+1} & & & \\\\\n& & & \\vdots       & & & \\\\\n& & & \\v\\hrm_n     & & & \\\\\n\\end{array}\\right]\n\\\\ \\\\\nU\\ (m \\times m) & \\Sigma\\ (m \\times n) & V\\hrm (n \\times n) \\\\\n\\end{array}\n\\end{align*}\n\nFinally, the SVD yields an \\emph{outer product expansion} of $A$ in terms of the singular values and the columns of $U$ and $V$,\n\\begin{equation}\n\\label{eq:svd-outer-product}\nA = \\sum_{i=1}^r \\sigma_i\\u_i\\v\\hrm_i.\n\\end{equation}\nNote that only terms from the compact SVD are needed for this expansion.\n\n\\subsection*{Computing the Compact SVD} % -------------------------------------\n\nIt is difficult to compute the SVD from scratch because it is an eigenvalue-based decomposition.\nHowever, given an eigenvalue solver such as \\li{scipy.linalg.eig()}, the algorithm becomes much simpler.\nFirst, obtain the eigenvalues and eigenvectors of $A\\hrm A$, and use these to compute $\\Sigma$.\nSince $A\\hrm A$ is normal, it has an orthonormal eigenbasis, so set the columns of $V$ to be the eigenvectors of $A\\hrm A$.\nThen, since $A\\v_i = \\sigma_i \\u_i$, construct $U$ by setting its columns to be $\\u_i = \\frac{1}{\\sigma_i}A\\v_i$.\n\nThe key is to sort the singular values and the corresponding eigenvectors in the same manner.\nIn addition, it is computationally inefficient to keep track of the entire matrix $\\Sigma$ since it is a matrix of mostly zeros, so we need only store the singular values as a vector $\\boldsymbol{\\sigma}$.\nThe entire procedure for computing the compact SVD is given below.\n% For the compact SVD, keep all of the nonzero singular values.\n% For the truncated SVD, keep only the largest $k$.\n\n\\begin{algorithm} % Compact SVD.\n\\begin{algorithmic}[1]\n\\Procedure{compact\\_SVD}{$A$}\n\\State $\\boldsymbol{\\lambda}, V \\gets$ eig$(A\\hrm A)$\n    \\Comment{Calculate the eigenvalues and eigenvectors of $A\\hrm A$.}\n\\State $\\boldsymbol{\\sigma} \\gets \\sqrt{\\boldsymbol{\\lambda}}$\n    \\Comment{Calculate the singular values of $A$.}\n\\State $\\boldsymbol{\\sigma} \\gets$ sort$(\\boldsymbol{\\sigma})$\n    \\Comment{Sort the singular values \\textbf{from greatest to least}.}\n    \\label{step:sort-singular-values}\n\\State $V \\gets$ sort($V$)\n    \\Comment{Sort the eigenvectors \\textbf{the same way} as in the previous step.}\n\\State $r \\gets $ count($\\boldsymbol{\\sigma} \\ne 0)$\n    \\Comment{Count the number of nonzero singular values (the rank of $A$).}\n    \\label{step:nonzero-singular-values}\n\\State $\\boldsymbol{\\sigma}_1 \\gets \\boldsymbol{\\sigma}_{:r}$\n    \\Comment{Keep only the positive singular values.}\n\\State $V_1 \\gets V_{:,:r}$\n    \\Comment{Keep only the corresponding eigenvectors.}\n\\State $U_1 \\gets AV_1 / \\boldsymbol{\\sigma}_1$\n    \\Comment{Construct $U$ with array broadcasting.}\n    \\label{step:SVD-construct-U}\n\\State \\pseudoli{return} $U_1, \\boldsymbol{\\sigma}_1, V\\hrm_1$\n\\EndProcedure\n\\caption{}\n\\label{alg:compact-svd}\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{problem} % Compute the compact SVD.\nWrite a function that accepts a matrix $A$ and a small error tolerance \\li{tol}.\nUse Algorithm \\ref{alg:compact-svd} to compute the compact SVD of $A$.\nIn step \\ref{step:nonzero-singular-values}, compute $r$ by counting the number of singular values that are greater than \\li{tol}.\n\nConsider the following tips for implementing the algorithm.\n\\begin{itemize}\n    \\item The Hermitian $A\\hrm$ can be computed with \\li{A.conj().T}.\n    \\item In step \\ref{step:sort-singular-values}, the way that $\\boldsymbol{\\sigma}$ is sorted needs to be stored so that the columns of $V$ can be sorted the same way.\n    Consider using \\li{np.argsort()} and fancy indexing to do this, but remember that by default it sorts from least to greatest (not greatest to least).\n    \\item Step \\ref{step:SVD-construct-U} can be done by looping over the columns of $V$, but it can be done more easily and efficiently with array broadcasting.\n\\end{itemize}\n\nTest your function by calculating the compact SVD for random matrices.\nVerify that $U$ and $V$ are orthonormal, that $U\\Sigma V\\hrm = A$, and that the number of nonzero singular values is the rank of $A$.\nYou may also want to compre your results to SciPy's SVD algorithm.\n%\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n# Generate a random matrix and get its compact SVD via SciPy.\n>>> A = np.random.random((10,5))\n>>> U,s,Vh = la.svd(A, full_matrices=False)\n>>> print(U.shape, s.shape, Vh.shape)\n(10, 5) (5,) (5, 5)\n\n# Verify that U is orthonormal, U Sigma Vh = A, and the rank is correct.\n>>> np.allclose(U.T @ U, np.identity(5))\n<<True>>\n>>> np.allclose(U @ np.diag(s) @ Vh, A)\n<<True>>\n>>> np.linalg.matrix_rank(A) == len(s)\n<<True>>\n\\end{lstlisting}\n\\label{prob:calculate-compact-svd}\n\\end{problem}\n\n\\subsection*{Visualizing the SVD} % -------------------------------------------\n\nAn $m\\times n$ matrix $A$ defines a linear transformation that sends points from $\\mathbb{R}^n$ to $\\mathbb{R}^m$.\nThe SVD decomposes a matrix into two rotations and a scaling, so that any linear transformation can be easily described geometrically.\nSpecifically, $V\\hrm$ represents a rotation, $\\Sigma$ a rescaling along the principal axes, and $U$ another rotation.\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}{.35\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{figures/unit_circle.pdf}\n  \\caption{$S$}\n\\end{subfigure}\n\\quad\n\\begin{subfigure}{.35\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{figures/vcircle.pdf}\n  \\caption{$V\\hrm S$}\n\\end{subfigure}\n\\\\\n\\begin{subfigure}{.35\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{figures/svcircle.pdf}\n  \\caption{$\\Sigma V\\hrm S$}\n\\end{subfigure}\n\\quad\n\\begin{subfigure}{.35\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{figures/full_transformation.pdf}\n  \\caption{$U \\Sigma V\\hrm S$}\n\\end{subfigure}\n\\caption{Each step in transforming the unit circle and two unit vectors using the matrix $A$.}\n\\label{fig:svd-visualization}\n\\end{figure}\n\n\\begin{problem} % Visualize the SVD.\nWrite a function that accepts a $2 \\times 2$ matrix $A$.\nGenerate a $2 \\times 200$ matrix $S$ representing a set of 200 points on the unit circle, with $x$-coordinates on the top row and $y$-coordinates on the bottom row (recall the equation for the unit circle in polar coordinates:\n$x = \\cos(\\theta)$, $y = \\sin(\\theta)$, $\\theta\\in[0,2\\pi]$).\nAlso define the matrix\n\\[\nE =\n\\left[\\begin{array}{c|c|c}\n\\arrayrulecolor{gray}\n\\e_1 & \\0 & \\e_2\n\\end{array}\\right]\n=\n\\left[\\begin{array}{ccc} 1 & 0 & 0 \\\\ 0 & 0 & 1 \\end{array}\\right],\n\\]\nso that plotting the first row of $S$ against the second row of $S$ displays the unit circle, and plotting the first row of $E$ against its second row displays the standard basis vectors in $\\mathbb{R}^2$.\n\nCompute the full SVD $A = U\\Sigma V\\hrm$ using \\li{scipy.linalg.svd()}.\nPlot four subplots to demonstrate each step of the transformation, plotting $S$ and $E$, $V\\hrm S$ and $V\\hrm E$, $\\Sigma V\\hrm S$ and $\\Sigma V\\hrm E$, then $U\\Sigma V\\hrm S$ and $U \\Sigma V\\hrm E$.\n\nFor the matrix \\[A =  \\left[\\begin{array}{cc}3 & 1\\\\1 & 3\\end{array}\\right],\\]\nyour function should produce Figure \\ref{fig:svd-visualization}.\n\\\\\n(Hint: Use \\li{plt.axis(\"equal\")} to fix the aspect ratio so that the circles don't appear elliptical.)\n\\end{problem}\n\n\\begin{comment}\n\\subsection*{Image Data Compression}\nIn this lab, we explore how the SVD can be used to compress image data.\nRecall that an image is simply a matrix where each position is the color value for the pixel in that position.\nThe SVD lets us choose how much information to keep, and what information is most important.\nLarger eigenvalues correspond to columns of $U$ and $V$ that contain more information, while smaller eigenvalues correspond to less important columns.\nThis idea is used in many areas of applied mathematics including signal processing, statistics, semantic indexing (search engines), and control theory.\n\\end{comment}\n\n\\section*{Using the SVD for Data Compression} % ===============================\n\n\\subsection*{Low-Rank Matrix Approximations} % --------------------------------\n\nIf $A$ is a $m\\times n$ matrix of rank $r < \\min\\{m,n\\}$, then the compact SVD offers a way to store $A$ with less memory.\nInstead of storing all $mn$ values of $A$, storing the matrices $U_1$, $\\Sigma_1$ and $V_1$ only requires saving a total of $mr+r+nr$ values.\nFor example, if $A$ is $100 \\times 200$ and has rank $20$, then $A$ has $20,000$ values, but its compact SVD only has total $6,020$ entries, a significant decrease.\n\nThe \\emph{truncated SVD} is an approximation to the compact SVD that allows even greater efficiency at the cost of a little accuracy.\nInstead of keeping all of the nonzero singular values, the truncated SVD only keeps the first $s < r$ singular values, plus the corresponding columns of $U$ and $V$.\nIn this case, (\\ref{eq:svd-outer-product}) becomes\n\\begin{equation*}\nA_s = \\sum_{i=1}^s \\sigma_i\\u_i\\v\\hrm_i.\n\\end{equation*}\n\nMore precisely, the truncated SVD of $A$ is $A_s = \\widehat{U}\\widehat{\\Sigma} \\widehat{V}\\hrm$, where\n$\\widehat{U}$ is $m\\times s$, $\\widehat{V}$ is $n \\times s$, and $\\widehat{\\Sigma}$ is $s\\times s$.\nThe resulting matrix $A_s$ has rank $s$ and is only an approximation to $A$, since $r - s$ nonzero singular values are neglected.\n\n\\begin{align*} % Compact and truncated SVD.\n\\begin{array}{cccc}\n\\textcolor{red}{\\widehat{U}\\ (m \\times s)} & \\textcolor{blue}{\\widehat{\\Sigma}\\ (s \\times s)} & \\textcolor{green}{\\widehat{V}\\hrm\\ (s \\times n)} \\\\\n\\left[\\begin{array}{ccccccc}\n\\arrayrulecolor{red}\n\\cline{2-4}\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{\\u_1} & \\cdots & \\rvl{\\u_s} & \\u_{s+1} & \\cdots & \\u_r \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      \\\\\n\\cline{2-4}\n\\end{array}\\right]\n&\n\\left[\\begin{array}{cccccccc}\n\\arrayrulecolor{blue}\n\\cline{2-4}\n& \\lvl{\\sigma_{1}}  &   & \\rvl{}         &   &        &   \\\\\n& \\lvl{}       & \\ddots & \\rvl{}         &   &        &   \\\\\n& \\lvl{}       &        & \\rvl{\\sigma_{s}} & &        &   \\\\\n\\cline{2-4}\n&              &        &                & \\sigma_{s+1} &        &   \\\\\n&              &        &                &   & \\ddots &   \\\\\n&              &        &                &   &        & \\sigma_r \\\\\n\\end{array}\\right]\n&\n\\left[\\begin{array}{ccccccc}\n\\arrayrulecolor{green}\n\\cline{2-6}\n& \\lvl{} & & \\v\\hrm_1 & & \\rvl{} & \\\\\n& \\lvl{} & & \\vdots   & & \\rvl{} & \\\\\n& \\lvl{} & & \\v\\hrm_s & & \\rvl{} & \\\\\n\\cline{2-6}\n& & & \\v\\hrm_{s+1} & & & \\\\\n& & & \\vdots       & & & \\\\\n& & & \\v\\hrm_r     & & & \\\\\n\\end{array}\\right]\n\\\\\nU_1\\ (m \\times r) & \\Sigma_1\\ (r \\times r) & V\\hrm_1 (r \\times n) \\\\\n\\end{array}\n\\end{align*}\n\nThe beauty of the SVD is that it makes it easy to select the information that is most important.\nLarger singular values correspond to columns of $U$ and $V$ that contain more information, so dropping the smallest singular values retains as much information as possible.\nIn fact, given a matrix $A$, its rank-$s$ truncated SVD approximation $A_s$ is the \\emph{best rank $s$ approximation} of $A$ with respect to both the induced 2-norm and the Frobenius norm.\nThis result is called the \\emph{Schmidt, Mirsky, Eckhart-Young theorem}, a very significant concept that appears in signal processing, statistics, machine learning, semantic indexing (search engines), and control theory.\n\n\\begin{comment}\nWe can also calculate $A_s$ by finding the full SVD, and setting all singular values after the $k$th to zero.\nThus the modified $\\Sigma$ would be\n\\begin{equation*}\n\\Sigma_{s} = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_s,0,\\ldots,0).\n\\end{equation*}\nMultiplying this matrix with the original $U$ and $V\\hrm$ will give the same $A_s$ that was found by computing the truncated SVD directly.\n\\end{comment}\n\n\\begin{problem} % Lowest-rank approximation.\nWrite a function that accepts a matrix $A$ and a positive integer $s$.\n\\begin{enumerate}\n\\item Use your function from Problem \\ref{prob:calculate-compact-svd} or \\li{scipy.linalg.svd()} to compute the compact SVD of $A$, then form the truncated SVD by stripping off the appropriate columns and entries from $U_1$, $\\Sigma_1$, and $V_1$.\nReturn the best rank $s$ approximation $A_s$ of $A$ (with respect to the induced 2-norm and Frobenius norm).\n\\item Also return the number of entries required to store the truncated form $\\widehat{U}\\widehat{\\Sigma} \\widehat{V}\\hrm$ (where $\\widehat{\\Sigma}$ is stored as a one-dimensional array, not the full diagonal matrix).\nThe number of entries stored in NumPy array can be accessed by its \\li{size} attribute.\n\\begin{lstlisting}\n>>> A = np.random.random((20, 20))\n>>> A.size\n400\n\\end{lstlisting}\n\\item If $s$ is greater than the number of nonzero singular values of $A$ (meaning $s > $ rank$(A)$), raise a \\li{ValueError}.\n\\end{enumerate}\nUse \\li{np.linalg.matrix_rank()} to verify the rank of your approximation.\n% , and verify that the number of entries required is equal to $ms + s + ns$.\n\\label{prob:svd_approx}\n\\end{problem}\n\n\\subsection*{Error of Low-Rank Approximations} % ------------------------------\n\nAnother result of the Schmidt, Mirsky, Eckhart-Young theorem is that the exact 2-norm error of the best rank-$s$ approximation $A_s$ for the matrix $A$ is the $(s+1)$th singular value of $A$:\n\\begin{equation}\n\\label{eq:svd-approximation-error}\n\\|A - A_s\\|_2 = \\sigma_{s+1}.\n\\end{equation}\n%\nThis offers a way to approximate $A$ within a desired error tolerance $\\epsilon$:\nchoose $s$ such that $\\sigma_{s+1}$ is the largest singular value that is less than $\\epsilon$, then compute $A_s$.\nThis $A_s$ throws away as much information as possible without violating the property $\\|A - A_s\\|_2 < \\epsilon$.\n\n\\begin{problem} % Lowest Rank Approximation\nWrite a function that accepts a matrix $A$ and an error tolerance $\\epsilon$.\n\\begin{enumerate}\n\\item Compute the compact SVD of $A$, then use (\\ref{eq:svd-approximation-error}) to compute the lowest rank approximation $A_s$ of $A$ with 2-norm error less than $\\epsilon$.\nAvoid calculating the SVD more than once.\n\\\\ (Hint: \\li{np.argmax()}, \\li{np.where()}, and/or fancy indexing may be useful.)\n\\item As in the previous problem, also return the number of entries needed to store the resulting approximation $A_s$ via the truncated SVD.\n\\item If $\\epsilon$ is less than or equal to the smallest singular value of $A$, raise a \\li{ValueError}; in this case, $A$ cannot be approximated within the tolerance by a matrix of lesser rank.\n\\end{enumerate}\nThis function should be close to identical to the function from Problem \\ref{prob:svd_approx}, but with the extra step of identifying the appropriate $s$.\nConstruct test cases to validate that $\\| A - A_s \\|_2 < \\epsilon$.\n\\end{problem}\n\n\\subsection*{Image Compression} % ---------------------------------------------\n\nImages are stored on a computer as matrices of pixel values.\nSending an image over the internet or a text message can be expensive, but computing and sending a low-rank SVD approximation of the image can considerably reduce the amount of data sent while retaining a high level of image detail.\nSuccessive levels of detail can be sent after the inital low-rank approximation by sending additional singular values and the corresponding columns of V and U.\n\n% TODO: redo the numbers in this paragraph for the full hubble image.\nExamining the singular values of an image gives us an idea of how low-rank the approximation can be.\nFigure \\ref{fig:hubble} shows the image in \\texttt{hubble\\_gray.jpg} and a log plot of its singular values.\nThe plot in \\ref{fig:hubble-log-svals} is typical for a photograph---the singular values start out large but drop off rapidly.\nIn this rank $1041$ image, $913$ of the singular values are $100$ or more times smaller than the largest singular value.\nBy discarding these relatively small singular values, we can retain all but the finest image details, while storing only a rank $128$ image.\nThis is a \\textbf{huge} reduction in data size.\n\n\\begin{figure}[H] % Hubble image + plot of singular values.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[height=5cm]{figures/hubble_gray.jpg}\n    \\caption{NGC 3603 (Hubble Space Telescope).}\n    \\label{fig:hubble-original-gray}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/hubble_svals.pdf}\n    \\caption{Singular values on a log scale.}\n    \\label{fig:hubble-log-svals}\n\\end{subfigure}\n\\caption{}\n\\label{fig:hubble}\n\\end{figure}\n\nFigure \\ref{fig:hubble-svd-rank-approximations} shows several low-rank approximations of the image in Figure \\ref{fig:hubble-original-gray}.\nEven at a low rank the image is recognizable.\nBy rank $120$, the approximation differs very little from the original.\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rank2.pdf}\n    \\caption{Rank 2}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rank20.pdf}\n    \\caption{Rank 20}\n    \\label{fig:hubble-rank20-approximation}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rank120.pdf}\n    \\caption{Rank 120}\n\\end{subfigure}\n\\caption{}\n\\label{fig:hubble-svd-rank-approximations}\n\\end{figure}\n\nGrayscale images are stored on a computer as 2-dimensional arrays, while color images are stored as 3-dimensional arrays---one layer each for red, green, and blue arrays.\nTo read and display images, use \\li{imageio.imread()} and \\li{plt.imshow()}.\nImages are read in as integer arrays with entries between 0 and 255 (\\li{dtype=np.uint8}), but \\li{plt.imshow()} works better if the image is an array of floats in the interval $[0,1]$.\nScale the image properly by dividing the array by $255$.\n\n\\begin{lstlisting}\n>>> from imageio import imread\n>>> from matplotlib import pyplot as plt\n\n# Send the RGB values to the interval (0,1).\n>>> image_gray = imread(\"hubble_gray.jpg\") / 255.\n>>> image_gray.shape            # Grayscale images are 2-d arrays.\n(1158, 1041)\n>>> image_color = imread(\"hubble.jpg\") / 255.\n>>> image_color.shape           # Color images are 3-d arrays.\n(1158, 1041, 3)\n\n# The final axis has 3 layers for red, green, and blue values.\n>>> red_layer = image_color[:,:,0]\n>>> red_layer.shape\n(1158, 1041)\n\n# Display a gray image.\n>>> plt.imshow(red_layer, cmap=\"gray\")\n>>> plt.axis(\"off\")             # Turn off axis ticks and labels.\n>>> plt.show()\n\n# Display a color image.\n>>> plt.imshow(image_color)     # cmap=None by default.\n>>> plt.axis(\"off\")\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{problem} % Image compression.\nWrite a function that accepts the name of an image file and an integer $s$.\nUse your function from Problem \\ref{prob:svd_approx}, to compute the best rank-$s$ approximation of the image.\nPlot the original image and the approximation in separate subplots.\nIn the figure title, report the difference in number of entries required to store the original image and the approximation (use \\li{plt.suptitle()}).\n\nYour function should be able to handle both grayscale and color images.\nRead the image in and check its dimensions to see if it is color or not.\nGrayscale images can be approximated directly since they are represented by 2-dimensional arrays.\nFor color images, let $R$, $G$, and $B$ be the matrices for the red, green, and blue layers of the image, respectively.\nCalculate the low-rank approximations $R_s$, $G_s$, and $B_s$ separately, then put them together in a new 3-dimensional array of the same shape as the original image.\n\\\\ (Hint: \\li{np.dstack()} may be useful for putting the color layers back together.)\n\nFinally, it is possible for the low-rank approximations to have values slightly outside the valid range of RGB values.\nSet any values outside of the interval $[0,1]$ to the closer of the two boundary values.\n\\\\ (Hint: fancy indexing and/or \\li{np.clip()} may be useful here.)\n\nTo check, compressing \\texttt{hubble\\_gray.jpg} with a rank $20$ approximation should appear similar to Figure \\ref{fig:hubble-rank20-approximation} and save $1,161,478$ matrix entries.\n\\end{problem}\n\n% NOTE: we used to use A.nbytes instead of A.size to measure the reduction,\n% but when images (dtype=np.uint8) are converted to float arrays\n% (dtype=np.float64), the resulting arrays take much more memory to store, so =\n% reporting the number of bytes saved often ends up being bigger than the\n% original picture.\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{More on Computing the SVD} % -------------------------------------\n\nFor an $m\\times n$ matrix $A$ of rank $r < \\min\\{m,n\\}$, the compact SVD of $A$ neglects last $m-r$ columns of $U$ and the last $n-r$ columns of $V$.\nThe remaining columns of each matrix can be calculated by using Gram-Schmidt orthonormalization.\nIf $m < r < n$ or $n < r < m$, only one of $U_1$ and $V_1$ will need to be filled in to construct the full $U$ or $V$.\nComputing these extra columns is one way to obtain a basis for $\\mathscr{N}(A\\hrm)$ or $\\mathscr{N}(A)$.\n\nAlgorithm \\ref{alg:compact-svd} begins with the assumption that we have a way to compute the eigenvalues and eigenvectors of $A\\hrm A$.\nComputing eigenvalues is a notoriously difficult problem, and computing the SVD from scratch without an eigenvalue solver is much more difficult than the routine described by Algorithm \\ref{alg:compact-svd}.\nThe procedure involves two phases:\n\\begin{enumerate}\n    \\item Factor $A$ into $A = U_a B V\\hrm_a$ where $B$ is bidiagonal (only nonzero on the diagonal and the first superdiagonal) and $U_a$ and $V_a$ are orthonormal.\n    This is usually done via \\emph{Golub-Kahan Bidiagonalization}, which uses Householder reflections, or \\emph{Lawson-Hanson-Chan bidiagonalization}, which relies on the QR decomposition.\n    \\item Factor $B$ into $B = U_b \\Sigma V\\hrm_b$ by the QR algorithm or a divide-and-conquer algorithm.\n    Then the SVD of $A$ is given by $A = (U_aU_b)\\Sigma (V_aV_b)\\hrm$.\n\\end{enumerate}\nFor more details, see Lecture 31 of \\cite{Trefethen1997} or Section 5.4 of \\emph{Applied Numerical Linear Algebra} by James W. Demmel.\n\n\\subsection*{Animating Images with Matplotlib} % ------------------------------\n\nMatplotlib can be used to animate images that change over time.\nFor instance, we can show how the low-rank approximations of an image change as the rank $s$ increases, showing how the image is recovered as more ranks are added.\nTry using the following code to create such an animation.\n\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\nfrom matplotlib.animation import FuncAnimation\n\ndef animate_images(images):\n    \"\"\"Animate a sequence of images. The input is a list where each\n    entry is an array that will be one frame of the animation.\n    \"\"\"\n    fig = plt.figure()\n    plt.axis(\"off\")\n    im = plt.imshow(images[0], animated=True)\n\n    def update(index):\n        plt.title(\"Rank {} Approximation\".<<format>>(index))\n        im.set_array(images[index])\n        return im,              # Note the comma!\n\n    a = FuncAnimation(fig, update, frames=len(images), blit=True)\n    plt.show()\n\\end{lstlisting}\nSee \\url{https://matplotlib.org/examples/animation/dynamic_image.html} for another example.\n", "meta": {"hexsha": "5d8790cfbc2f87dd55c92770cab7885f00afe1a9", "size": 30233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/SVD_ImageCompression/SVD_ImageCompression.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/SVD_ImageCompression/SVD_ImageCompression.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/SVD_ImageCompression/SVD_ImageCompression.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 55.0692167577, "max_line_length": 247, "alphanum_fraction": 0.6921575762, "num_tokens": 8474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.6854898464986305}}
{"text": "\n\\section{Data-analysis tips}\\label{lab-1-data-analysis-tips}\n\nIn lab one you will be collecting measurements on several dependent\nvariables, in each of two manipulated conditions (the independent\nvariable). For each dependent variable you will want to determine\nwhether the manipulation had an effect. That is, did the independent\nvariable cause a change in the dependent variable. We know that\ndifferences can sometimes be observed by chance alone, so we want to\nconduct an inferential statistical test to determine the probability\nthat our observed difference could have been produced by chance alone.\nTo do this we will be conducting several t-tests. This is a short primer\non the process. You can conduct t-tests in the software of your choice,\nor by hand using a calculator (or in excel). Here, we will use the free\nand open-source statistical package called R, to illustrate the process.\n\nLet's imagine we have two groups of 10 subjects each. Group A receives\ncondition 1 of the independent variable, and Group B recieves condition\n2 of the independent variable. We then measure some behavior for all of\nthe subject in all of the groups. To make this more concrete, let's say\n10 subjects drink coffee, and the the 10 subjects drink tea. Then we\npresent all of the subjects with a piece of art and ask them rate how\nbeautiful they think it is on a scale from 1 to 7.\n\nWhen we collect all the data we should have 20 total ratings, one for\neach subject in each group.\n\nFor example, if you put the data in a table it might look something like\nthe following. Note, the grey text box shows the R code used to simulate\nthe data. For, each group, we sample 10 numbers from a normal\ndistribution with a mean of 4, and a standard deviation of .5. Then we\nput the numbers in a table.\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\NormalTok{coffee<-}\\KeywordTok{round}\\NormalTok{(}\\KeywordTok{rnorm}\\NormalTok{(}\\DecValTok{10}\\NormalTok{,}\\DecValTok{4}\\NormalTok{,.}\\DecValTok{5}\\NormalTok{))}\n\\NormalTok{tea<-}\\KeywordTok{round}\\NormalTok{(}\\KeywordTok{rnorm}\\NormalTok{(}\\DecValTok{10}\\NormalTok{,}\\DecValTok{4}\\NormalTok{,.}\\DecValTok{5}\\NormalTok{))}\n\\NormalTok{all_data<-}\\KeywordTok{data.frame}\\NormalTok{(coffee,tea)}\n\\KeywordTok{kable}\\NormalTok{(all_data,}\\DataTypeTok{format=}\\StringTok{\"latex\"}\\NormalTok{)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{tabular}{r|r}\n\\hline\ncoffee & tea\\\\\n\\hline\n4 & 5\\\\\n\\hline\n3 & 4\\\\\n\\hline\n3 & 4\\\\\n\\hline\n3 & 3\\\\\n\\hline\n4 & 3\\\\\n\\hline\n4 & 5\\\\\n\\hline\n4 & 4\\\\\n\\hline\n4 & 4\\\\\n\\hline\n4 & 4\\\\\n\\hline\n3 & 4\\\\\n\\hline\n\\end{tabular}\n\nWe can do some quick descriptive statistics, for example, we might want\nto know the means of the beauty ratings for the coffee and tea groups.\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\KeywordTok{mean}\\NormalTok{(coffee)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{verbatim}\n## [1] 3.6\n\\end{verbatim}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\KeywordTok{mean}\\NormalTok{(tea)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{verbatim}\n## [1] 4\n\\end{verbatim}\n\nThe means aren't very different, and of course we should expect they\nshould be similar. After all, we sampled these means from the exact same\ndistribution. So, we should expect that on average, the means should\nboth be close to 4. However, they won't necessarilly be exactly 4,\nbecause of variability introduced by random sampling.\n\n\\section{The t-test}\\label{the-t-test}\n\nWhat we want to do next is conduct an independent samples t-test. We\nwant to determine whether any possible difference between the coffee and\ntea groups could have been produced by chance alone. We can conduct a\nt-test in R very easily using the t.test function.\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\KeywordTok{t.test}\\NormalTok{(coffee,tea,}\\DataTypeTok{var.equal=}\\OtherTok{TRUE}\\NormalTok{)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{verbatim}\n## \n##  Two Sample t-test\n## \n## data:  coffee and tea\n## t = -1.5, df = 18, p-value = 0.151\n## alternative hypothesis: true difference in means is not equal to 0\n## 95 percent confidence interval:\n##  -0.9602459  0.1602459\n## sample estimates:\n## mean of x mean of y \n##       3.6       4.0\n\\end{verbatim}\n\nR gives us back the t values, the degrees of freedom (df), and the\nassociated p-value. The p-value tells us the likelihood that our\ndifference, or a difference greater than the one we observed could have\nbeen produced by chance.\n\n\\section{One more time}\\label{one-more-time}\n\nLet's try this whole process again, but this time we will simulate data\nwith an actual difference between the groups. For example, let's say we\nwant to simulate the idea that drinking coffee makes people think the\nart is less beautiful by at least 2 points, and then reconduct the\nt-test with the new simulated data. We will sample numbers from a normal\ndistribution with mean 3 for the coffee group, and mean 5 for the tea\ngroup (for an average expected difference of 2).\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\NormalTok{coffee<-}\\KeywordTok{round}\\NormalTok{(}\\KeywordTok{rnorm}\\NormalTok{(}\\DecValTok{10}\\NormalTok{,}\\DecValTok{3}\\NormalTok{,.}\\DecValTok{5}\\NormalTok{))}\n\\NormalTok{tea<-}\\KeywordTok{round}\\NormalTok{(}\\KeywordTok{rnorm}\\NormalTok{(}\\DecValTok{10}\\NormalTok{,}\\DecValTok{5}\\NormalTok{,.}\\DecValTok{5}\\NormalTok{))}\n\\NormalTok{all_data<-}\\KeywordTok{data.frame}\\NormalTok{(coffee,tea)}\n\\KeywordTok{kable}\\NormalTok{(all_data,}\\DataTypeTok{format=}\\StringTok{\"latex\"}\\NormalTok{)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{tabular}{r|r}\n\\hline\ncoffee & tea\\\\\n\\hline\n3 & 5\\\\\n\\hline\n3 & 5\\\\\n\\hline\n3 & 4\\\\\n\\hline\n3 & 6\\\\\n\\hline\n2 & 5\\\\\n\\hline\n4 & 5\\\\\n\\hline\n3 & 6\\\\\n\\hline\n3 & 5\\\\\n\\hline\n3 & 5\\\\\n\\hline\n3 & 5\\\\\n\\hline\n\\end{tabular}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\KeywordTok{mean}\\NormalTok{(coffee)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{verbatim}\n## [1] 3\n\\end{verbatim}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\KeywordTok{mean}\\NormalTok{(tea)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{verbatim}\n## [1] 5.1\n\\end{verbatim}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\KeywordTok{t.test}\\NormalTok{(coffee,tea,}\\DataTypeTok{var.equal=}\\OtherTok{TRUE}\\NormalTok{)}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\begin{verbatim}\n## \n##  Two Sample t-test\n## \n## data:  coffee and tea\n## t = -9, df = 18, p-value = 4.404e-08\n## alternative hypothesis: true difference in means is not equal to 0\n## 95 percent confidence interval:\n##  -2.590215 -1.609785\n## sample estimates:\n## mean of x mean of y \n##       3.0       5.1\n\\end{verbatim}\n\n\\section{Writing up the results of a\nt-test}\\label{writing-up-the-results-of-a-t-test}\n\nWe've now conducted two different t-tests, and received different\nresults on each them. You will likely find different results for all of\nthe t-tests that you conduct for the lab experiment. However, you will\nuse the basic sentence structure to report all of the results. When you\nreport the results of your experiment along with statistical tests there\nare two important features to include, the pattern of the results, and\nthe inferential statistic. In this situation, we would simply report the\nmeans and the t-test information. Here are is an with made-up numbers.\n\nThe coffee group gave a lower mean beauty rating (M = 3.4) than the tea\ngroup (M = 5.6), and the difference was significant, t (18) = 5.4, p\n\\textless{} .001.\n\nSo, just in one sentence we tell the reader what the means were in both\nconditions, as whether the result was significant. APA style recommends\nreporting exact p-values when they are greater than .001 (for example p\n= .047). If the p-value is less than .001, then you just need to report\np \\textless{} .001.\n\n", "meta": {"hexsha": "fc8e57dcfcf6e9ba2cd1ca509b8daf984816e46c", "size": 7575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LabManual/lab1.tex", "max_stars_repo_name": "danBurrell/research_methods_with_R", "max_stars_repo_head_hexsha": "74745c4bd69d185f1a36ef38638be8cc55966b06", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-12-29T16:39:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T12:46:59.000Z", "max_issues_repo_path": "LabManual/lab1.tex", "max_issues_repo_name": "danBurrell/research_methods_with_R", "max_issues_repo_head_hexsha": "74745c4bd69d185f1a36ef38638be8cc55966b06", "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": "LabManual/lab1.tex", "max_forks_repo_name": "danBurrell/research_methods_with_R", "max_forks_repo_head_hexsha": "74745c4bd69d185f1a36ef38638be8cc55966b06", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2017-09-01T14:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T23:17:38.000Z", "avg_line_length": 31.9620253165, "max_line_length": 163, "alphanum_fraction": 0.7428382838, "num_tokens": 2200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7826624890918021, "lm_q1q2_score": 0.6854456191851809}}
{"text": "\\label{sec:registration}\n\nThis section discusses functions that are minimized\nto register (align) one mesh to another,\nto register a mesh to a data set,\nor to register a data set to a mesh.\nThe general approach is to minimize\na measure of distance between the {\\it docking} mesh and its {\\it target},\nover some set of registration transforms,\nfor example, the rigid transformations of $\\Reals^3$.\n\nWe most often compute a registration transform, $\\Tr$,\nto minimize a distance between the transformed mesh,\n$\\Tr\\M$ and its target, $\\Ta$:\n\\begin{equation}\n\\min_{\\Tr} d(\\M(\\Tr),\\Ta)\n\\end{equation}\nThe target, $\\Ta$, may be another mesh, a set of data points,\nor some other geometric object.\nThe transformed mesh\n$\\M(\\Tr) = \\M(\\Tr\\v) = \\M(\\Tr(\\v_0 \\ldots \\v_{n-1}))$,\nwhere $\\v = (\\v_0 \\ldots  \\v_{n-1})$\nare the positions of the vertices of $\\M$.\n\nWe are also sometimes interested in registering a data set\n$\\{\\x_i\\}$ to a mesh.\nIn this case, we minimize\n\\begin{equation}\n\\min_{\\Tr} d(\\M,\\Tr\\{\\x_i\\})\n\\end{equation}\n\nBoth are special cases of choosing a transform on $\\Reals^{3n}$\nby minimizing:\n\\begin{equation}\n\\min_{\\Tr} f( \\Tr \\p),\n\\end{equation}\nwhere\n$\\p = (\\p_0 \\ldots  \\p_{n-1}) \\in \\Reals^{3n}$,\n$\\Tr : \\Reals^{3n} \\mapsto \\Reals^{3n}$,\nand\n$f : \\Reals^{3n} \\mapsto \\Re$.\n\n\\subsection{Distance measures}\n\\label{sec:Distance-measures}\n\n\\subsubsection{Vertex distance}\n\\label{sec:Vertex-distance}\n\nSuppose 2 meshes have corresponding vertices,\nthat is,\nfor each vertex $\\v_{0i}$ in the docking mesh $\\M_0$,\nthere is a corresponding vertex $\\v_{1i}$ in the target mesh $\\M_1$,\nand vice versa.\nThen an obvious measure of distance\nis the sum of distances between the corresponding points:\n\\begin{equation}\nd_{\\V}(\\M_0,\\M_1) = \\sum_{i=0}^{n-1} \\| \\p_{0i} - \\p_{1i} \\|^2\n\\end{equation}\nThe gradient of $d_v$ with respect to the positions\nof the $i$th vertex of $\\M_0$ is:\n\\begin{equation}\n\\Gc{\\p_{0i}}{d_v}{q} = 2 \\left[ \\q_{0i} - \\p_{1i} \\right]\n\\end{equation}\n\n\\subsubsection{Projection distance}\n\\label{sec:Projection-distance}\n\nIn many problems, the vertex correspondence used in\n\\autoref{sec:Vertex-distance} is not appropriate.\nOr we may want to register a mesh to a target data set.\nIn such cases, we can use the projection distance:\n\\begin{equation}\nd_{\\Pr}(\\M,\\p_1) = \\sum_{i=0}^{n-1} \\| \\Pr_{\\M}(\\p_{1i}) - \\p_{1i} \\|^2,\n\\end{equation}\nwhere the target $\\p_1 = (\\p_{10}, \\ldots \\p_{1(n-1)})$\nis either a set of data points,\nor the set of positions of the vertices of a target mesh.\n$\\Pr_{\\M}(\\p)$ is the projection of the point $\\p \\in \\Reals^3$\non the mesh $\\M$.\nThis is the same as the general data fitting distance, and\nderivatives with respect to the positions of the vertices\nof $\\M$ are given in \\autoref{sec:data-fitting}.\n\n\\subsection{Transforms}\n\\label{sec:Transforms}\n\nIn this section, I describe common families\nof transforms, $\\{\\Tr\\}$, over which to minimize:\n\\begin{equation}\n\\min_{\\Tr} f( \\Tr \\p),\n\\end{equation}\nTo do the minimization, we need to compute\nthe derivative:\n\\begin{equation}\n\\De{\\Tr}{g(\\Tr)}{\\Tr_0}\n= \\De{\\Tr}{f(\\Tr\\p)}{\\Tr_0}\n= \\De{\\q}{f(\\q)}{\\q=\\Tr_0\\p}\n\\circ\n\\De{\\Tr}{\\Tr\\p}{\\Tr_0}.\n\\end{equation}\no, equivalently, the gradient:\n\\begin{equation}\n\\Gc{\\Tr}{f( \\M(\\Tr\\p) )}{\\Tr_0}\n =\n\\De{\\Tr}{\\Tr\\p}{\\Tr_0}^\\dagger\n\\Gc{\\q}{f(\\M(\\q)))}{\\Tr_0\\p}\n\\end{equation}\n\nI assume in the following\nthat $\\Df{\\p}{f}$ (or $\\Gb{\\p}{f}$) is known,\nso the main task is computing $\\Df{\\Tr}{\\Tr\\p}$.\n\nAs mentioned in above,\nin registration problems\nthe function $f$ is usually a distance between\ntwo meshes, or between a mesh and a data set,\nwith either the location of one mesh's vertices\nor the data points allowed to vary.\nDerivatives and gradients of distance functions,\nwith respect to vertex positions,\nare given in sections \\ref{sec:Distance-measures}\nand \\ref{sec:data-fitting}.\n\n\\subsubsection{Direct sum transforms}\n\\label{sec:Direct-sum-transforms}\n\nIn registration problems,we usually want to\napply the same transform to each vertex or data point.\nLet $\\Tr : \\Reals^3 \\mapsto \\Reals^3$ be an element\nof some family of transformations on $\\Reals^3$.\nA simple direct sum transform applies the same 3-dimensional\ntransform to each vertex point,\nso the full mesh transform is\n$\\Tr_{3n} = \\bigoplus^n \\Tr$,\nand $\\Tr_{3n} (\\bigoplus_{i=0}^{n-1} \\p_i) = \\bigoplus_{i=0}^{n-1} \\Tr \\p_i$\nby transforming the locations of each of the vertices\nof the mesh.\n\nIn general, suppose $\\Tr_i :\n{\\mathcal D}_i \\mapsto {\\mathcal C}_i; i = 0 \\ldots k-1$\nare $k$ maps.\nThe direct sum of the $\\Tr_i$ is:\n\\begin{equation}\n\\label{eq:diagonal-blocks}\n\\Tr =\n\\left( \\bigoplus_{i=0}^{k-1} \\Tr_i \\right) :\n\\left( \\bigoplus_{i=0}^{k-1}{\\mathcal D}_i \\right)\n\\mapsto\n\\left( \\bigoplus_{i=0}^{k-1}{\\mathcal C}_i \\right)\n\\end{equation}\n$\\Tr$ is a transform whose\n$k$ 'diagonal blocks' are the $\\Tr_i$.\n\nUsing this notation,\n$\\Df{\\p}{f(\\p)} = \\bigoplus_i \\Df{\\p_i}{f(\\p)}$,\n$\\Df{\\Tr}{\\Tr\\p} = \\bigoplus_i \\Df{\\Tr}{\\Tr\\p_i}$,\nand:\n\\begin{equation}\n\\label{eq:total-registration-transform-derivative}\n\\De{\\Tr}{f( \\Tr \\p )}{\\Tr_0}\n =\n\\sum_i\n\\De{\\q_i}{f(\\q)}{\\q=\\Tr_0\\p}\n\\circ\n\\De{\\Tr}{\\Tr\\p_i}{\\Tr_0}\n\\end{equation}\nFor the gradient, the equivalent is:\n\\begin{equation}\n\\label{eq:registration-gradient-sum}\n\\Gc{\\Tr}{f( \\Tr \\p )}{\\Tr_0}\n =\n\\sum_i\n\\left( \\De{\\Tr}{\\Tr\\p_i}{\\Tr_0} \\right)^{\\dagger} \\;\n\\left( \\Gc{\\q_i}{f(\\q)}{\\q=\\Tr_0\\p} \\right)\n\\end{equation}\n\nThe derivative with respect to vertex or data points,\n$\\Df{\\p_i}{f(\\p)}$,\nis assumed to be known.\nFor example, the derivatives of functions\nrelated to data fitting\nare discussed in chapter \\ref{sec:data-fitting}.\n\nIn this chapter, I focus on computing\n$\\De{\\Tr}{\\Tr\\p}{\\Tr_0}$\nfor $\\Tr : \\Reals^3 \\mapsto \\Reals^3$\nand $\\p \\in \\Reals^3$.\n\n\\subsubsection{General linear registration}\n\\label{sec:General-linear-registration}\n\nSuppose $\\Tr = \\L$ a linear transform on $\\Reals^3$.\nWe can represent $\\L$ as a vector in $\\Reals^9$:\n\\begin{equation}\n\\label{eq:L-vector}\n\\l = \\left(\\L_{00},\\L_{01},\\L_{02},\n       \\L_{10},\\L_{11},\\L_{12},\n       \\L_{20},\\L_{21},\\L_{22}\\right),\n\\end{equation}\nwhere $\\L_{ij}$ is the $ij$-th element of a\nmatrix representation of $\\L$.\nWe can identify a vector $\\p \\in \\Reals^3$\nwith a linear transform $\\Tr_{\\p} : \\Reals^9 \\mapsto \\Reals^3$\nby defining $\\Tr_{\\p}\\l = \\L\\p$.\nIn the coordinate system defined by equation \\ref{eq:L-vector},\nthe matrix for $\\Tr_{\\p}$ is:\n\\begin{equation}\n\\label{eq:Tp-matrix}\n\\Tr_{\\p} =\n\\left(\n\\begin{array}{lllllllll}\n\\p_0 & \\p_1 & \\p_2 &  0   &  0   &  0   &  0   &  0   &  0 \\\\\n 0   &  0   &  0   & \\p_0 & \\p_1 & \\p_2 &  0   &  0   &  0 \\\\\n 0   &  0   &  0   &  0   &  0   &  0   & \\p_0 & \\p_1 & \\p_2 \\\\\n\\end{array}\n\\right)\n\\end{equation}\n\nBecause linear transforms are their own derivatives\n(see section\\ref{sec:Derivatives-of-linear-functions}),\nit follows that the derivative with respect to the\nunconstrained set of linear registration transforms is:\n\\begin{equation}\n\\label{eq:linear-transform-derivative}\n\\Df{\\L}{\\left( \\L \\, \\p \\right)}\n \\; = \\;\n\\Df{\\L}{\\left( \\Tr_{\\p} \\, \\L \\right)}\n \\; = \\;\n\\Tr_{\\p}\n\\end{equation}\n\n\\subsubsection{Scaled rotations}\n\\label{sec:Scaled-rotations}\n\nA scaled rotation\nis a linear transform $\\Sc = s \\R$,\nwhere $s \\in \\Re$ and $\\R : \\Reals^n \\mapsto \\Reals^n$\nis a rotation.\n\nThe quaternions $\\Qs$ are a convenient representation\nfor the scaled rotations on $\\Reals^3$.\n(See Faugeras~\\cite[sec.~5.5.2]{Faugeras1993}.)\n\nA quaternion is a 4-tuple:\n\\begin{equation}\n\\q = (w, x, y, z) = (w, \\v),\n\\end{equation}\nwhere $w, x, y, z \\in \\Re$ and $\\v \\in \\Reals^3$.\nThe set of quaternions has several operations:\n\\begin{itemize}\n\\item Quaternion conjugation $\\dagger$:\n\\begin{equation}\n\\q^\\dagger = (w, \\v)^\\dagger = (w, - \\v)\n\\end{equation}\n\\item The quaternion product $\\diamond$:\n\\begin{equation}\n\\q_0 \\diamond \\q_1 = (w_0w_1 - \\v_0 \\bullet \\v_1, w_0 \\v_1 + w_1 \\v_0 + \\v_0 \\times \\v_1)\n\\end{equation}\n\\item Quaternion norm $\\| \\|_{\\Qs}$:\n\\begin{equation}\n\\| \\q \\|_{\\Qs}^2\n= \\q^\\dagger \\bullet \\q\n= \\q \\bullet \\q^\\dagger\n= w^2 + \\|\\v\\|^2\n= w^2 + x^2 + y^2 + z^2\n\\end{equation}\n\\end{itemize}\n\nThe quaternion product can be extended to $\\Reals^3$\nby identifying $\\p \\in \\Reals^3$ with\nthe quaternion $(0,\\p)$.\nThis allows us to define a linear transform\non $\\Reals^3$ for any quaternion:\n\\begin{equation}\n\\Sc(\\q) \\p = \\q \\diamond \\p \\diamond \\q^\\dagger\n\\end{equation}\n\nIt turns out that transforms $\\Sc(\\q)$ so defined are scaled rotations.\nThe scale is the squared norm of the quaternion $\\| \\q \\|_{\\Qs}^2$.\nThe rotation is about the axis of $\\v$\nby $\\cos^{-1}(w / \\| \\q \\|_{\\Qs})$.\n(Note that $\\q$ and $-\\q$ correspond to the same scaled rotation.)\n\n$\\Sc(\\q)$ can be written as a matrix:\n\\begin{equation}\n\\label{eq:quaternion-matrix}\n\\Sc(\\q) =\n\\left(\n\\begin{array}{ccc}\nw^2 + x^2 - y^2 - z^2 & 2(xy - wz)            & 2(xz + wy)           \\\\\n2(xy + wz)            & w^2 - x^2 + y^2 - z^2 & 2(yz - wx)           \\\\\n2(xz - wy)            & 2(yz + wx)            & w^2 - x^2 - y^2 +z^2\n\\end{array}\n\\right)\n\\end{equation}\n\nNotice that the adjoint (transpose) of $\\Sc(\\q)$\nis the linear transform corresponding to the conjugate quaternion:\n$\\Sc^{\\dagger}(\\q) =  \\Sc(\\q^{\\dagger})$.\n\nIf we consider $\\Sc(\\q)$ to be a 9-dimensional vector,\nas in equation \\ref{eq:L-vector},\nthen the derivative can be expressed as the matrix:\n\\begin{equation}\n\\label{eq:quaternion-derivative-matrix}\n\\Df{q}{\\Sc(\\q)}\n = 2 \\left(\n\\begin{array}{rrrr}\n  w &  x & -y & -z \\\\\n  z &  y &  x &  w \\\\\n -y &  z & -w &  x \\\\\n -z &  y &  x & -w \\\\\n  w & -x &  y & -z \\\\\n  x &  w &  z &  y \\\\\n  y &  z &  w &  x \\\\\n -z & -w &  z &  y \\\\\n  w & -x & -y &  z \\\\\n\\end{array}\n\\right)\n\\end{equation}\n\nIt's also useful to express the derivative $\\Df{q}{\\Sc(\\q)}$\nas a set of partial derivative matrices,\nwhich are computed\nby differentiating the elements of matrix in equation\n\\ref{eq:quaternion-matrix}:\n\\begin{eqnarray}\n\\label{eq:quaternion-matrix-partial-derivatives}\n\\Df{w}{\\Sc(\\q)}\n& = &\n2 \\left(\n\\begin{array}{rrr}\n w & -z &  y \\\\\n z &  w & -x \\\\\n-y &  x &  w\n\\end{array}\n\\right)\n\\\\\n\\nonumber\n\\\\\n\\Df{x}{\\Sc(\\q)}\n& = &\n2 \\left(\n\\begin{array}{rrr}\n x &  y &  z \\\\\n y & -x & -w \\\\\n z &  w & -x\n\\end{array}\n\\right)\n\\nonumber\n\\\\\n\\nonumber\n\\\\\n\\Df{y}{\\Sc(\\q)}\n& = &\n2 \\left(\n\\begin{array}{rrr}\n-y &  x &  w \\\\\n x &  y &  z \\\\\n-w &  z & -y\n\\end{array}\n\\right)\n\\nonumber\n\\\\\n\\nonumber\n\\\\\n\\Df{z}{\\Sc(\\q)}\n& = &\n2 \\left(\n\\begin{array}{rrr}\n-z & -w &  x \\\\\n w & -z &  y \\\\\n x &  y &  z\n\\end{array}\n\\right)\n\\nonumber\n\\end{eqnarray}\n\nNote that\n$\\Df{w}{\\left( \\Sc(\\q) \\; \\p \\right)}\n = \\left( \\Df{w}{\\Sc(\\q)}\\right) \\; \\p$\n(and similarly for the partials with respect to $x,y,$ and $z$).\n\nWe can write the total derivative in terms of the partials as:\n\\begin{eqnarray}\n\\Df{\\q}{\\left( \\Sc(\\q) \\; \\p \\right)}\n& = &\n\\left( \\Df{\\w}{\\Sc(\\q)} \\; \\p \\right) \\otimes \\e_w\n\\\\\n& + &\n\\left( \\Df{\\x}{\\Sc(\\q)} \\; \\p \\right) \\otimes \\e_x\n\\nonumber\n\\\\\n& + &\n\\left( \\Df{\\y}{\\Sc(\\q)} \\; \\p \\right) \\otimes \\e_y\n\\nonumber\n\\\\\n& + &\n\\left( \\Df{\\z}{\\Sc(\\q)} \\; \\p \\right) \\otimes \\e_z\n\\nonumber\n\\end{eqnarray}\n\nIn computing the gradients of registration penalties,\nwe sum expressions like\n$\\Df{\\q}{\\left( \\Sc(\\q)\\p_i \\right)}^{\\dagger} \\;\n\\Gf{\\p_i}{f}$\n(see equation \\ref{eq:registration-gradient-sum}).\nIn terms of the partial derivative matrices,\nthis is:\n\\begin{equation}\n\\Df{\\q}{\\left( \\Sc(\\q)\\p_i \\right)}^{\\dagger} \\;\n\\Gf{\\p_i}{f}\n=\n\\left(\n\\begin{array}{c}\n\\left( \\Df{\\w}{\\Sc(\\q)} \\; \\p \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\x}{\\Sc(\\q)} \\; \\p \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\y}{\\Sc(\\q)} \\; \\p \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\z}{\\Sc(\\q)} \\; \\p \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\end{array}\n\\right)\n\\end{equation}\n\nWe sometimes encounter the inverse transform, $\\Sc^{-1}(\\q)$,\nwhich is the same as the linear transform,\n$\\Sc(\\q^{-1})$,\ncorresponding to the inverse quaternion\n(in the sense of the quaternion product):\n$\\q^{-1} = (w, x, y, z)^{-1}\n         = {1 \\over {\\| q \\|_{\\Qs}^2}} (w, -x, -y, -z)$.\n\nTo compute derivatives of expressions\ninvolving an inverse quaternion,\nwe can use the derivative of $\\q^{-1}$\nwith respect to $\\q$:\n\\begin{equation}\n\\Df{\\q}{\\q^{-1}}\n=\n{1 \\over {\\| \\q \\|_{\\Qs}^4}}\n\\left(\n\\begin{array}{cccc}\n-w^2+x^2+y^2+z^2 & -2wx              & -2wy              & -2wz \\\\\n 2wx             & -w^2+x^2-y^2-z^2  &  2xy              &  2xz \\\\\n 2wy             &   2xy             & -w^2-x^2+y^2-z^2  &  2yz \\\\\n 2wz             &   2xz             &  2yz              &  -w^2-x^2-y^2+z^2 \\\\\n\\end{array}\n\\right)\n\\end{equation}\n\n\\paragraph{Rotations}\n\\label{sec:Rotations}\n\nA common representation for the rotations on $\\Reals^3$\nis the set of {\\it unit quaternions},\nthat is, the quaternions satisfying $\\| \\q \\|_{\\Qs} = 1$.\nHowever, optimization under a nonlinear constraint\nlike $\\| \\q \\|_{\\Qs} = 1$ is relatively difficult,\nso I instead use a redundant representation by general quaternion:\n\\begin{equation}\n\\R(\\q) = {{\\Sc(\\q)} \\over {\\| \\q \\|_{\\Qs}^2}}\n\\end{equation}\nTo avoid numerical instability, it's usually enough\nto add a small penalty for $\\| \\q \\|_{\\Qs}$ far from $1$.\n\nThe partial derivative matrices of $\\R(\\q)$ are used in the\nsame way as,\nand can be expressed in terms of,\nthe partials of $\\Sc(\\q)$:\n\\begin{equation}\n\\Df{v}{\\R(\\q)}\n\\; = \\;\n\\Df{v}{\\left(\n{{\\Sc(\\q)} \\over {\\| \\q \\|_{\\Qs}^2}}\n\\right)}\n\\; = \\;\n{{\\Df{v}{\\Sc(\\q)}} \\over {\\| \\q \\|_{\\Qs}^2}}\n-\n{{2v \\Sc(\\q)} \\over {\\| \\q \\|_{\\Qs}^4}}\n\\end{equation}\nwhere $v$ is any of $w$, $x$, $y$, or $z$.\n\n\\subsubsection{Shift registration}\n\\label{sec:Shift-registration}\n\nA simple shift, or translation, adds a constant vector\nto its argument: $\\Tr \\p = \\p + \\t,$\nfor some $\\t \\in \\Reals^3$.\nThe derivative with respect to\nan unconstrained translation vector\nis simply\n$\\Df{\\t}{(\\p + \\t)} = \\I_3,$\nwhere $\\I_3$ is the identity on $\\Reals^3$.\n\n\\subsubsection{Affine registration}\n\\label{sec:affine-registration}\n\nAn {\\it affine transformation,} $\\A : \\Reals^m \\mapsto \\Reals^n$,\nis a linear transformation plus a translation:\n$\\A \\p = \\L \\p + \\t$,\nwhere $\\L : \\Reals^m \\mapsto \\Reals^n$ is a linear transform,\nthe {\\it linear part} of the affine tranform,\nand $\\t \\in \\Reals^n$ is $\\A$'s {\\it translation}.\n\nNote that, if $\\A = (\\L,\\t)$, then its inverse is\n$\\A^{-1} = (\\L^{-1}, - \\L^{-1}\\t)$.\n\n(It is sometimes useful to use a redundant representation:\n$\\A \\p = \\L (\\p + \\t_0) + \\t_1$,\nwhere $\\t_0 \\in \\Reals^m$ and $\\t_1 \\in \\Reals^n$,\nbut, for simplicity, I'll stick to the minimal one-translation\nrepresentation in this discussion.)\n\nIn the context of mesh registration,\nwhere $\\A : \\Reals^3 \\mapsto \\Reals^3$,\nwe can view $\\L \\in \\Reals^9$ and\n$\\A = (\\L, \\t) \\in \\left(\\Reals^9 \\oplus \\Reals^3 \\right)= \\Reals^{12}$,\nand we can express derivatives with respect to $\\A$\nin terms of the independent partial derivatives\nwith respect to $\\L$ and $\\t$.\n\nIt follows from the results in the preceding sections,\nthat the derivative with respect to the\nunconstrained set of affine registration transforms is:\n\\begin{equation}\n\\label{eq:affine-transform-derivative}\n\\Df{(\\L,\\t)}{\\left( \\A \\, \\p \\right)}\n \\; = \\;\n\\Df{(\\L,\\t)}{\\left( \\L \\p + \\t \\right)}\n \\; = \\;\n\\Tr_{\\p} \\oplus \\I_3,\n\\end{equation}\nwhere $\\oplus$ indicates,\nas in equation \\ref{eq:diagonal-blocks},\nthat the derivative is formed from the 2\n'diagonal blocks'.\n\n\\subsubsection{Euclidean registration}\n\\label{sec:euclidean-registration}\n\nA {\\it euclidean transform} is an affine transform\n$\\Eu : \\Reals^n \\mapsto \\Reals^n$,\n$\\Eu \\p = \\Sc \\p + \\t $,\nwhose linear part is a scaled rotation:\n$\\Sc = s \\R$,\nwhere $s \\in \\Re$ and $\\R : \\Reals^n \\mapsto \\Reals^n$\nis a rotation.\n\nEuclidean transforms are easy to invert.\n\nIf $\\Eu = (\\Sc,\\t)$, then its inverse is\n$\\Eu^{-1} = (\\Sc^{-1}, - \\Sc^{-1}\\t)$.\nThe inverse of a rotation, $\\R$, is its adjoint\n(tranpose) $\\R^{-1} = \\R^{\\dagger}$.\nThe inverse of a scaled rotation $\\Sc = s \\R$\nis therefore\n$\\Sc^{-1} = (s \\R)^{-1}\n         = {1 \\over s} \\R^{\\dagger}\n         = {1 \\over {s^2}} \\Sc^{\\dagger}$.\nWe can then write the inverse of a euclidean transform as\n$\\Eu^{-1} = {1 \\over {s^2}}(\\Sc^{\\dagger}, - \\Sc^{\\dagger}\\t)$\n\nUsing quaternions, we can represent euclidean transforms with\n7 dimensional points:\n$\\Eu = (w_{\\q}, x_{\\q}, y_{\\q}, z_{\\q}, x_{\\t}, y_{\\t}, z_{\\t})$,\nwhere $\\q = (w_{\\q}, x_{\\q}, y_{\\q}, z_{\\q})$ is a quaternion corresponding\nto $\\S$, the linear part of $\\Eu$,\nand $\\t = (x_{\\t}, y_{\\t}, z_{\\t})$ is the translation part.\n\nIn the 7-dimensional representation, the inverse is:\n\\begin{equation}\n\\Eu^{-1} =\n{1 \\over {\\| \\q \\|_{\\Qs}^4}}\n\\left(\n\\begin{array}{rcrcr}\n& &  w_{\\q} & & \\\\\n& & -x_{\\q} & & \\\\\n& & -y_{\\q} & & \\\\\n& & -z_{\\q} & & \\\\\n(-w_{\\q}^2 - x_{\\q}^2 + y_{\\q}^2 + z_{\\q}^2)\nx_{\\t}\n&\n-\n&\n2 (w_{\\q}z_{\\q} + x_{\\q}y_{\\q})\ny_{\\t}\n&\n+\n&\n2 (w_{\\q}y_{\\q} - x_{\\q}z_{\\q})\nz_{\\t}\n\\\\\n 2 (w_{\\q}z_{\\q} - x_{\\q}y_{\\q})\nx_{\\t}\n&\n+\n&\n(-w_{\\q}^2 + x_{\\q}^2 - y_{\\q}^2 + z_{\\q}^2)\ny_{\\t}\n&\n-\n&\n2 (w_{\\q}x_{\\q} + y_{\\q}z_{\\q})\nz_{\\t}\n\\\\\n- 2 (w_{\\q}y_{\\q} + x_{\\q}z_{\\q})\nx_{\\t}\n&\n+\n&\n2 (w_{\\q}x_{\\q} - y_{\\q}z_{\\q})\ny_{\\t}\n&\n+\n&\n(-w_{\\q}^2 + x_{\\q}^2 + y_{\\q}^2 - z_{\\q}^2)\nz_{\\t}\n\\end{array}\n\\right)\n\\end{equation}\n\nIn computing the gradients of registration penalties,\nwe sum expressions like\n$\\Df{\\q, \\t}{\\left( \\Eu(\\q,\\t)\\p_i \\right)}^{\\dagger} \\;\n\\Gf{\\p_i}{f}$\n(see equation \\ref{eq:registration-gradient-sum}).\nUsing the results in sections\n\\ref{sec:Scaled-rotations}\nand\n\\ref{sec:Shift-registration},\nit's not hard to see that,\nin terms of the partial derivative matrices,\nthis is:\n\\begin{equation}\n\\label{eq:euclidean-transform-gradient}\n\\left[\n\\Df{\\q,\\t}{\\; \\Eu(\\q,\\t)\\p_i}\n\\right]^{\\dagger} \\;\n\\Gf{\\p_i}{f}\n=\n\\left(\n\\begin{array}{c}\n\\left( \\Df{\\w_{\\q}}{\\Sc(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\x_{\\q}}{\\Sc(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\y_{\\q}}{\\Sc(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\z_{\\q}}{\\Sc(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\end{array}\n\\right)\n\\oplus\n\\Gf{\\p_i}{f}\n\\end{equation}\n\n\\subsubsection{Rigid registration}\n\\label{sec:rigid-registration}\n\nA {\\it rigid transform} is an affine transform\n$\\G \\p  = \\R \\p + \\t $,\nwhose linear part is a rotation, $\\R$.\nUsing the representation, $\\R(\\q)$,\nusing {\\em non-unit} quaternions,\npresented in \\autoref{sec:Rotations},\nwe get the same results for the gradient terms\nas in equation \\ref{eq:euclidean-transform-gradient},\nwith the partials of $\\Sc(\\q)$ replaced by the\npartials of $\\R(\\q)$, that is:\n\\begin{equation}\n\\label{eq:rigid-transform-gradient}\n\\left[\n\\Df{\\q,\\t}{\\; \\G(\\q,\\t)\\p_i}\n\\right]^{\\dagger} \\;\n\\Gf{\\p_i}{f}\n=\n\\left(\n\\begin{array}{c}\n\\left( \\Df{\\w_{\\q}}{\\R(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\x_{\\q}}{\\R(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\y_{\\q}}{\\R(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\left( \\Df{\\z_{\\q}}{\\R(\\q)} \\; \\p_i \\right) \\bullet \\Gf{\\p_i}{f} \\\\\n\\end{array}\n\\right)\n\\oplus\n\\Gf{\\p_i}{f}\n\\end{equation}\n", "meta": {"hexsha": "8d1f4f8ec30f44b209ff57fdec52d66d9f66bea1", "size": 18811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/registration.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/registration.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/registration.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": 27.541727672, "max_line_length": 89, "alphanum_fraction": 0.619477965, "num_tokens": 7192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6854456160155818}}
{"text": "\\section{CONTINUED\\_FRACTION Operator}\n\\index{approximation}\\index{rational number}\n\nThe operator CONTINUED\\_FRACTION approximates the real number \n( \\nameref{rational} number, \\nameref{rounded} number)\ninto a continued fraction. CONTINUE_FRACTION has one or\ntwo arguments, the number to be converted and an optional\nprecision:\n\\begin{verbatim}\n    continued\\_fraction(<num>)\n or\n    continued\\_fraction(<num>,<size>)\n\\end{verbatim}\nThe result is a list of two elements: the\nfirst one is the rational value of the approximation, the second one\nis the list of terms of the continued fraction which represents the\nsame value according to the definition \\verb&t0 +1/(t1 + 1/(t2 + ...))&.\nPrecision: the second optional parameter \\meta{size} is an upper bound\nfor the absolute value of the result denominator. If omitted, the\napproximation is performed up to the current system precision.\n\n{\\tt Examples:}\n\\begin{verbatim}\ncontinued_fraction pi;\n\n                  ->\n\n  1146408\n{---------,{3,7,15,1,292,1,1,1,2,1}}\n  364913\n\ncontinued_fraction(pi,100);\n\n                  ->\n\n  22\n{----,{3,7}}\n  7\n\n\n\\end{verbatim}\n", "meta": {"hexsha": "27122a0be07c05530c38ee7a3f1ef6710749b8e7", "size": 1112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "atomic_Decomp/Redlog/reduce.doc/cfrac.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/cfrac.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/cfrac.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": 26.4761904762, "max_line_length": 72, "alphanum_fraction": 0.7194244604, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869916479465, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6854456134781745}}
{"text": "\\section{Introduction}\n\n\nFourier series (FS) gives a new idea to expand a continuous and periodic signal with a series of trigonometric functions, which glanced at frequency analysis at the first time. Based on the idea of FS, other transformations were proposed to extend the limit on FS: (1) Fourier transform (FT) for continuous but non-periodic signals; (2) discrete time Fourier transform (DTFT) for sampled signals; (3) discrete Fourier transform (DFT) for completely discrete analysis. These transformations make up Fourier transform family under Dirichlet conditions. Besides, Laplace transform extends the frequency into complex domain and Z transform simplifies DTFT practically \\cite{SignalSystem}.\n\n\nAnalysis in frequency domain provides more options to process signals or evaluate linear systems. For example, a spectrum given by fast Fourier transform (FFT, the fast algorithm for DFT) shows the frequency distribution of the signal; the location of poles and zeros of a system demonstrate the stability and dynamic properties.\n\n\nIn this paper, attentions are paid to digital signal processing. Power spectrum density is firstly introduced as a tool for frequency analysis and a new algorithm is delivered. Then the design and properties of some common used filters are discussed. Finally, an example is given to show processing procedure and the results.\n\n\n\n\n\\section{Power Spectrum Density}\n\n\nDFT is used to analysis a certain signal. However, there are many kinds of stochastic signals whose statistical properties are the most concerned. As for a stationary and random signal, power spectrum density (PSD) is taken to estimate its properties in frequency domain \\cite{SignalDetect}.\n\n\nPSD is defined as the Fourier transform of the autocorrelation function of the given signal $x(t)$\n\\begin{equation}\n    S_x(\\omega) = \\mathscr{F}\\left(R_{xx}(\\tau)\\right) = \\int_{-\\infty}^{+\\infty} R_{xx}(\\tau) \\iexp{-\\mathrm{j} 2 \\uppi \\omega \\tau} \\diff \\tau\n\\end{equation}\nwhere the autocorrelation function $R_{xx}(\\tau)$ is \n\\begin{equation}\n    R_{xx}(\\tau) = \\lim_{T\\to \\infty} \\frac{1}{2T}\\int_{-T}^{T} x(t) x(t-\\tau)  \\diff t\n\\end{equation}\nThus, the PSD is computed by\n\\begin{align}\n    S_x(\\omega) &= \\int_{-\\infty}^{+\\infty} \\left(\\lim_{T\\to \\infty} \\frac{1}{2T}\\int_{-T}^{T} x(t) x(t-\\tau)  \\diff t t\\right) \\iexp{-\\mathrm{j} 2 \\uppi \\omega} \\diff \\tau \\notag \\\\ \n    &= \\lim_{T\\to \\infty} \\frac{1}{2T} \\int_{-T}^{T} x(t)\\iexp{-\\mathrm{j} 2 \\uppi \\omega t} \\left( \\int_{-\\infty}^{+\\infty} x(t-\\tau) \\iexp{-\\mathrm{j} 2 \\uppi \\omega \\left(\\tau-t\\right)} \\right) \\diff t \\notag \\\\\n    &= \\lim_{T\\to \\infty} \\frac{1}{2T} \\int_{-T}^{T} x(t)\\iexp{-\\mathrm{j} 2 \\uppi \\omega t} X^*(\\jomega) \\diff t \\notag \\\\\n    &= \\lim_{T\\to \\infty} \\frac{1}{2T} X(\\jomega) X^*(\\jomega) \\notag \\\\\n    &= \\lim_{T\\to \\infty} \\frac{1}{2T} \\left| X(\\jomega) \\right|^2\n        \\label{eq:psd}\n\\end{align}\nEq~\\eqref{eq:psd} is also known as Wiener–Khinchin theorem, which demonstrate the relationship between PSD and general frequency spectrum.\n\n\n\n\n\\subsection{Classical Power Spectrum Density Estimation}\n\n\nAnalog signals are analyzed based on the sampled data. Two important effects should be considered in sampling: (1) sampling should satisfy Nyquist sampling theorem, where the sampling frequency should be at least twice the maximum frequency of the origin signal. In practice, an analog anti-aliasing filter is usually used before the signal is sampled. (2) Finite sampling is equivalent to applying a window function to the infinite signal, which leads to frequency leakage effect. Because of these two effects, the PSD computed from the sampled data is just the estimation of the PSD of origin analog signal. That's why we usually say `spectrum estimation' instead of `spectrum calculation'.\n\n\nThe most direct method to estimate PSD is to discretize Eq~\\eqref{eq:psd} using DFT and cancel the limit as below.\n\\begin{equation}\n    S_x(\\omega) \\approx \\frac{1}{T} \\left| X(k) \\right|^2 = \\frac{1}{Nf_s} \\left| X(k) \\right|^2\n\\end{equation}\nwhere $T$ is the total time of data, $N$ is the total number of points, $f_s$ is the sampling frequency. $X(k)$ is the DFT of $x(n)$, given by\n\\begin{equation}\n    X(k) = \\sum_{n=0}^{N-1} x(n) \\iexp{-\\mathrm{j} 2 \\uppi \\frac{n}{N}k} \\label{eq:DFT}\n\\end{equation}\nIn the case where a window function $w(n)$ is applied to the sampled data, the PSD should be normalized as below. The $2$ in the numerator converts the two-sided PSD to one-sided PSD, whose square root is the most used in practice.\n\\begin{equation}\n    S_x(\\omega) = \\frac{2}{\\sum_{n=0}^{N-1} w^2(n) f_s} \\left| X(k) \\right|^2 \\label{eq:periodogram}\n\\end{equation}\n\n\nPSD can be estimated by combining Eq~\\eqref{eq:DFT} and Eq~\\eqref{eq:periodogram}. This direct method is called `periodogram'. Both MATLAB and Python provide built-in functions to calculate the periodogram. They are named \\verb|periodogram| and \\verb|scipy.signal.periodogram|. \n\n\nAn example for PSD estimation is shown in Fig~\\ref{fig:plotPSD}. The result of periodogram looks very noisy, especially in high frequency band. To improve the accuracy, Welch proposed a method by dividing the data into overlapped segments and computing the average of the periodogram of each segment.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{Welch.pdf}\n    \\caption{The idea of Welch's method to estimate PSD.}\n    \\label{fig:Welch}\n\\end{figure}\n\n\nThe idea of Welch's method is shown in Fig~\\ref{fig:Welch} and the relevant functions are \\verb|pwelch| in MATLAB and \\verb|scipy.signal.welch| in Python. \n\n\n\n\n\\subsection{Logarithmic Frequency Axis Power Spectral Density}\n\n\nAs shown in Fig~\\ref{fig:plotPSD}, by averaging PSD using Welch's method, the curve is less noisy. However, because the data is divided into segments, the length decreases, which decreases the frequency resolution. To further improve Welch's method, a new method named Logarithmic frequency axis Power Spectral Density (LPSD) was proposed \\cite{LPSD}.\n\n\nConsidering that most signals occupy a wideband in frequency domain, the PSD is usually plotted with a logarithmic axis. Thus, the basic idea of the LPSD is to construct logarithmic frequency axis rather than linear axis. As a consequence, the frequency resolution changes with frequency, which allows dividing data into different segments. That is to say, the LPSD algorithm succeeds the idea of Welch's method and divides data according to the frequency point at which the PSD is estimated. The detailed procedure of the algorithm is discussed hereafter.\n\n\nA logarithmic axis is made up of geometric progression, the length of which is assumed to be $J_{\\rm des}$ and can be set manually, and it's not necessary equal to the length of data, $N$. The common ratio $q$ and ideal frequency resolution can be calculated as below.\n\\begin{gather}\n    \\lg f_{\\rm max} - \\lg f_{\\rm min} = q\\left(J_{\\rm des} -1 \\right) \\quad \\Rightarrow \\quad q = \\left(\\frac{f_{\\rm max}}{f_{\\rm min}}\\right)^{\\frac{1}{J_{\\rm des} -1}} = \\left(\\frac{N}{2}\\right)^{\\frac{1}{J_{\\rm des} -1}} \\\\\n    r_0(j) = f(j+1) - f(j) = \\left(q-1\\right) f(j)\n    \\label{eq:r0}\n\\end{gather}\nNote that the maximum frequency is given by Nyquist frequency $f_{\\rm max} = \\frac{f_s}{2}$, and the minimum frequency is limited by the total sampling time $f_{\\rm min} = \\frac{1}{T} = \\frac{f_s}{N}$. The index is denoted as $j$, which shows that the resolutions differ between frequencies.\n\n\nHowever, the ideal frequency resolution $r_0(j)$ could be less than $f_{\\rm min}$, which is not meaningful. So the resolution should be adjusted. To do so, we assume the desired number of segments to be $K_{\\rm des}$, and the overlap ratio is $\\xi$. So the desired resolution can be computed according to Fig~\\ref{fig:Welch}.\n\\begin{gather}\n    \\left(K_{\\rm des}-1\\right) \\left(1-\\xi\\right) L_{\\rm des} + L_{\\rm des} = N \\\\\n    r_{\\rm des} = \\frac{f_s}{L_{\\rm des}} = \\frac{f_s}{N}\\left(\\left(K_{\\rm des}-1\\right) \\left(1-\\xi\\right)+1\\right)\n\\end{gather}\nThe ideal frequency resolution should be adjusted as below.\n\\begin{equation}\n    r'(j) = \\begin{cases}\n        r_0(j) & r_0(j) \\ge r_{\\rm des} \\\\\n        \\sqrt{r_0(j)r_{\\rm des}} & r_0(j) < r_{\\rm des} \\text{ and } \\sqrt{r_0(j)r_{\\rm des}} > f_{\\rm min}  \\\\\n        f_{\\rm min} & \\text{ else }\n       \\end{cases}  \\label{eq:rp}\n\\end{equation}\nBesides, the frequency resolution should consider an integer length of data and be further modified.\n\\begin{equation}\n    L(j) = \\left\\lfloor \\frac{f_s}{r'(j)} \\right\\rfloor \\quad \\Rightarrow \\quad r(j) = \\frac{f_s}{L_(j)} \\label{eq:r}\n\\end{equation}\nSo far, the logarithmic frequencies can be computed by iterations given by Eq~\\eqref{eq:r0}, Eq~\\eqref{eq:rp} and Eq~\\eqref{eq:r}. \n\n\nSimilar to the Welch's method, $D$ and $L$ in Fig~\\ref{fig:Welch} differ with index $j$. For $j$-th frequency point, \n\\begin{equation}\n    D(j) = \\left\\lfloor \\left( 1-\\xi \\right) L(j) \\right\\rfloor\n\\end{equation}\nand the number of segments is computed below.\n\\begin{equation}\n    K(j) = \\left\\lfloor \\frac{N-L(j)}{D(j)+1} \\right\\rfloor\n\\end{equation}\n\n\nAverage is usually deducted in PSD estimation. The average of $j$-th frequency point and $k$-th segment is given below.\n\\begin{equation}\n    a(j,k) = \\frac{1}{L(j)} \\sum_{l=0}^{L(j)-1} x(D(j)(k-1)+l)\n\\end{equation}\nDeducting the average and applying window function $w(j,l)$, the segment to be transformed is gained.\n\\begin{equation}\n    G(j,k,l) = \\big( x(D(j)(k-1)+l) - a(j,k) \\big) w(j,l)\n\\end{equation}\nThe PSD of $k$-th segment at frequency $f(j)$ is calculated by single point DFT as below.\n\\begin{equation}\n    A(j,k) = \\sum_{l=0}^{L(j)-1} G(j,k,l) \\iexp{-\\mathrm{j} 2 \\uppi \\frac{m(j)}{L(j)} l}\n\\end{equation}\nNote that the frequency index $m(j)=\\frac{f(j)}{r(j)}$ is not necessary to be an integer.\n\n\nFinally, the PSD at $j$-th frequency point is given by the average of $K(j)$ segments according to Wiener–Khinchin theorem.\n\\begin{equation}\n    P(j) = \\frac{C_{\\rm PSD}(j)}{K(j)} \\sum_{k=1}^{K(j)} \\left| A(j,k) \\right|^2\n\\end{equation}\nThe coefficient $C_{\\rm PSD}(j)$ is used to normalize the PSD, which is given below.\n\\begin{equation}\n    C_{\\rm PSD}(j) = \\frac{2}{f_s\\sum_{l=0}^{L(j)-1} w^2(j,l)}\n\\end{equation}\n\n\nThe complete procedure of the LPSD algorithm has been discussed. The function is realized in both Python and MATLAB code, which can be found in the appendix. A comparison is given in Fig~\\ref{fig:plotPSD}. The signal is obtained by filtering a white noise with elliptic filter so that the PSD should be equal to the gain of the transfer function theoretically.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{plotPSD.pdf}\n    \\caption{Comparison of three methods to estimate PSD.}\n    \\label{fig:plotPSD}\n\\end{figure}\n\n\nIt's obvious that both the periodogram and the LPSD algorithms can calculate PSD at minimum frequency limited by the sampling time. But the result of periodogram is the most noisy. Welch's method improves the accuracy but sacrifices the minimum frequency. The LPSD provides the best estimated PSD, the result of which is very close to the theoretical value. However, the cost of the LPSD is to spend more time for calculation because it uses single point DFT and cannot benefit from FFT.\n\n\n\n\n\\section{Filter Design}\n\n\nProperties of a given signal in frequency domain can be obtained from its PSD. To change these properties, a filter with certain frequency response should be applied to the signal. \n\n\n\n\n\\subsection{Common Used Filters}\n\n\nSince filter design has been a very proven technique, the theoretical analysis won't go far but some useful functions in MATLAB and Python will be introduced. Dynamic of an analog filter can be described in a differential function or a transfer function with Laplace transform as below.\n\\begin{gather}\n    y^{(n)} + a_1 y^{(n-1)} + \\cdots + a_n y = b_0 u^{(m)} + b_1 u^{(m-1)} + \\cdots + b_m u \\quad (m < n) \\\\\n    H(s) = \\frac{Y(s)}{U(s)} = \\frac{b_0 s^{m} + b_1 s^{m-1} + \\cdots + b_n}{s^{n} + a_1 s^{n-1} + \\cdots + a_n} \\quad (m < n)\n\\end{gather}\nIf there are poles in the transfer function, the filter would have infinite impulse response in time domain, for which we call it IIR filter for short.\n\n\nTo design a filter with built-in functions, properties of the filter shown in Fig~\\ref{fig:filterdesign} should be specified. Taking low-pass filters as example, the frequency of passband is denoted by $f_{\\rm pass}$ and $R_{\\rm pass}$ is the allowed ripple. Stopband frequency is $f_{\\rm stop}$ and the attenuation is $R_{\\rm stop}$.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{FilterDesign.pdf}\n    \\caption{Filter properties specification.}\n    \\label{fig:filterdesign}\n\\end{figure}\n\n\nSome common used filters are listed in Tab~\\ref{tab:filterdesign} with MATLAB built-in functions for filter design \\cite{matlabdoc}. In these functions, \\verb|Wp| and \\verb|Ws| are respectively the angular frequency of passband and stopband ($\\omega_p = 2 \\uppi f_{\\rm pass}$ for example). Passband ripple \\verb|Rp| and stopband attenuation \\verb|Rs| are described in decibels. With the option \\verb|'s'|, the function designs an analog filter. If a digital filter is desired, functions should be called without the option \\verb|'s'| and \\verb|Wp| and \\verb|Ws| should be the digital frequency which is normalized by the sampling frequency.\n\n\nFor Python users, there are functions with the same names in \\verb|scipy.signal| package \\cite{scipydoc}. If the package is imported by \\verb|import scipy.signal as signal|, a prefix \\verb|signal.| should be attached to the functions to be called. Besides, the programming rules also has to be noticed. For example, the command \\verb|[b,a]=butter(n,Wn,'s')| in MATLAB is equivalent to the command \\verb|b,a=signal.butter(n,Wn,analog=True)| in Python.\n\n\n\\begin{table}[!htb]\n    \\centering\n    \\caption{MATLAB built-in functions for IIR filter design}\n    \\label{tab:filterdesign}\n    \\begin{tabular}{ll}\n        \\toprule\n        Name & Built-in Functions  \\\\\n        \\midrule \n        Butterworth & \\verb|[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s');|        \\\\\n                    & \\verb|[b,a] = butter(n,Wn,'s');|                 \\\\\n        Chebyshev Type I & \\verb|[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s');|  \\\\\n                    & \\verb|[b,a] = cheby1(n,Rp,Wn,'s');|              \\\\\n        Chebyshev Type II & \\verb|[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s');| \\\\\n                    & \\verb|[b,a] = cheby2(n,Rs,Wn,'s');|              \\\\\n        Elliptic Filter & \\verb|[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s');|   \\\\\n                    & \\verb|[b,a] = ellip(n,Rp,Rs,Wn,'s');|            \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}\n\n\nComparison of four common used filters are shown in Fig~\\ref{fig:filters} with options \\verb|Wp=1|,\\verb|Ws=3|, \\verb|Rp=1|, \\verb|Rp=40|. For the same target, elliptic filter has the least order but there are ripples in both passband and stopband. Butterworth filter has flat frequency response with passband, but the order is the largest, which means it takes more resources for calculation. Chebyshev filters have a compromise with order and ripple, where type I has ripples in passband and is flat in stopband, while type II is on the contrary.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{filter.pdf}\n    \\caption{Comparison of four common used IIR filters.}\n    \\label{fig:filters}\n\\end{figure}\n\n\nAs has been mentioned, functions mentioned above can also be used to design digital filters. Besides, some methods such as `impulse invariance' and `bilinear' can be used to discretize an analog filter. Take an analog Butterworth low-pass filter for example, the discretized filter response is shown in Fig~\\ref{fig:filter-c2d}. Note that the discretization could lead to aliasing effects, which may change the behaviors of the filter.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{filter-c2d.pdf}\n    \\caption{Digital filter design by discretization.}\n    \\label{fig:filter-c2d}\n\\end{figure}\n\n\nDigital systems have a unique property which allows all-zero system to exist. These systems are described in difference equation or transfer function with Z transform as below.\n\\begin{gather}\n    y(n) = b_0 u(n) + b_1 u(n-1) + \\cdots + b_m u(n-m) \n     \\sum_{k=0}^{m} b_k u(n-k) \\\\\n    H(z) = \\frac{Y(z)}{U(z)} = b_0 + b_1 z^{-1} + \\cdots + b_m z^{-m} = \\sum_{k=0}^{m} b_k z^{-m}\n\\end{gather}\nThe impulse response in time domain of this all-zero system is finite, thus this kind of filter is call FIR filter for short. Without poles, FIR filter is always stable.\n\n\nTwo methods are generally used to design a FIR filter. The first one is base on window function, whose idea is to apply a certain window function to the response of an IIR filter. MATLAB provides \\verb|fir1| function to realize this design. For Python, the function is \\verb|scipy.signal.firwin|.\n\n\nAnother method for FIR filter design is based on the frequency sample, where only filter order, frequencies and target responses are necessary. The function is named \\verb|fir2| in MATLAB and \\verb|scipy.signal.firwin2| in Python.\n\n\nApplications with graphical user interface (GUI) are also available for filter design. They are \\verb|filterBuilder| or \\verb|filterDesigner| (or \\verb|fdatool| in old version) in MATLAB and \\verb|pyfdax| in Python \\cite{pyfda}.\n\n\nFIR filter is easy to realize in digital device while IIR filter has less order. Filter type should be selected according to the requirements and equipment constraints before it is designed. Design results should be checked, including stability, frequency response. Besides, for real-time applications, the filter must be causal.\n\n\n\n\n\\subsection{Zero-Phase Filtering}\n\n\nThe dynamic of the filter always leads to delay. To decrease the delay, an all-pass filter can be employed to adjust the phase response of the filter. As for sampled data, a technology name zero-phase filtering can be used. For digital filter with transfer function $H(z)$, there are four steps to realize zero-phase filtering \\cite{mExamples}.\n\\begin{enumerate}[\\indent Step (1)]\n    \\setlength{\\itemsep}{0pt}\n    \\item Filter: $X(z) \\rightarrow H(z)X(z)$ ;\n    \\item Reverse: $H(z)X(z) \\rightarrow H(z^{-1})X(z^{-1})$ ;\n    \\item Filter: $H(z^{-1})X(z^{-1}) \\rightarrow H(z)H(z^{-1})X(z^{-1})$ ;\n    \\item Reverse: $H(z)H(z^{-1})X(z^{-1}) \\rightarrow H(z^{-1})H(z)X(z)$.\n\\end{enumerate}\nThe transfer function of the complete process $G(z)$ can be calculated as below.\n\\begin{equation}\n    G(z) = H(z^{-1})H(z) = \\left| H(\\omega) \\right| \\iexp{\\mathrm{j} \\varphi (\\omega)} \\left| H(\\omega) \\right| \\iexp{-\\mathrm{j} \\varphi (\\omega)}  = \\left| H(\\omega) \\right|^2\n\\end{equation}\nThere is no imaginary part in the transfer function so that no delay is introduced. From a practical point of view, when the data is reversed and filtered again, the same delay is introduced but in an opposite direction. Thus, the delay from the first filtering is compensated by the second filtering.\n\n\nThe function \\verb|filter| in MATLAB or \\verb|scipy.signal.lfilter| in Python can be used to filter data with specified filter. To apply zero-phase filtering, the function to be called is \\verb|filtfilit| in MATLAB or \\verb|scipy.signal.filtfilt| in Python. \n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{ZeroPhaseFiltering.pdf}\n    \\caption{Comparison of normal filtering and zero-phase filtering.}\n    \\label{fig:zerofiltering}\n\\end{figure}\n\n\nA comparison of normal filtering and zero-phase filtering is shown in Fig~\\ref{fig:zerofiltering}. The delay of normal filtering is obvious. Attentions should also be paid to the transient performances. There is transient dynamic in the beginning due to the error of initial states. However, there is also transient dynamic in the end with zero-phase filtering, which is caused by the filtering of the reversed data at the third step. Unfortunately, zero-phase filtering is not causal, which means it cannot be used in real-time applications.\n\n\n\n\n\n\\section{Results}\n\n\nDue to nonlinear properties, the AC current or voltage from the \\SI{50}{Hz} power supply is polluted by some harmonic frequencies. To ensure the filter suppress the noise adequately, a simulation has been done whose input signal is listed in Tab~\\ref{tab:input}.\n\n\n\\begin{table}[!htb]\n    \\centering\n    \\caption{Input signal for filter validation}\n    \\label{tab:input}\n    \\begin{tabular}{llllll}\n        \\toprule\n        Frequency (\\si{Hz}) & $50$ & $100$ & $150$ & $250$ & White Noise \\\\\n        Amplitude (\\si{A}) & $1.0$ & $0.3$ & $0.2$ & $0.1$ & $0.05$ (RMS) \\\\\n        Phase (\\si{deg}) & $0$ & $60$ & $-60$ & $-90$ & --- \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}\n\n\nThe length of data is $N=1000$ with sampling frequency $f_s=\\SI{1}{kHz}$. The target is to filter out components with frequency above \\SI{150}{Hz}. A Chebyshev Type II digital filter is chosen because IIR filter has less order and Chebyshev Type II provides flat frequency within passband. By Specifying $f_{\\rm pass} = \\SI{110}{Hz}$, $f_{\\rm stop} = \\SI{130}{Hz}$, $R_{\\rm pass} = \\SI{1}{dB}$ and $R_{\\rm stop} = \\SI{60}{dB}$, the designed filter is shown in Fig~\\ref{fig:prjFilter}.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{prjFilter.pdf}\n    \\caption{Filter frequency response.}\n    \\label{fig:prjFilter}\n\\end{figure}\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\subcaptionbox{Signals in time domain.}{\\includegraphics[height=4.9cm]{prjSignal.pdf}}\n    \\hfill\n    \\subcaptionbox{Signals in frequency domain.}{\\includegraphics[height=4.9cm]{prjPSD.pdf}}\n    \\caption{Comparison of original and filtered signal.}\n    \\label{fig:prjSignals}\n\\end{figure}\n\n\nOriginal signal is compared with filtered signal in Fig~\\ref{fig:prjSignals} in both time and frequency domain. The zero-phase filtering technology was employed so that no delay is introduced. Because the high-frequency disturbances are removed, the filtered curve seems more smooth. For the PSD, it's obvious that the filter suppress high-frequency noise by about three orders of magnitude as stopband attenuation is set to \\SI{60}{dB}.\n\n\n\n\n\\section{Conclusions}\n\n\nIn this paper, the LPSD algorithm is employed to estimate PSD, which takes advantage of minimum frequency range from the periodogram and succeeds the idea of averaging from Welch's method. Unable to embed FFT, the LPSD takes more time to calculate but provides more precise estimation with logarithmic frequency axis. Filters are designed with built-in functions and zero-phase filtering is used to filter data, which can compensate the delay caused by normal filtering. Zero-phase filtering is not causal, thus it cannot be used in real-time applications. A simulation was designed to validate the filter to suppress high-frequency disturbances from nonlinear effects of the \\SI{50}{Hz} power supply. The results confirmed the properties of the filter and the PSD showed the disturbances in high-frequency band was suppressed by three orders of magnitude.", "meta": {"hexsha": "f482b63668c2962a0b2f17a84bb4d9c4cef8984a", "size": 23102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "misc/homework/main.tex", "max_stars_repo_name": "iChunyu/signal-process-demo", "max_stars_repo_head_hexsha": "13cb094f0b4787df818dcac2bffbcb8928276f06", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-10-19T05:37:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T05:30:01.000Z", "max_issues_repo_path": "misc/homework/main.tex", "max_issues_repo_name": "iChunyu/signal-process-demo", "max_issues_repo_head_hexsha": "13cb094f0b4787df818dcac2bffbcb8928276f06", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-19T08:35:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-24T08:23:40.000Z", "max_forks_repo_path": "misc/homework/main.tex", "max_forks_repo_name": "iChunyu/signal-process-demo", "max_forks_repo_head_hexsha": "13cb094f0b4787df818dcac2bffbcb8928276f06", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.7114845938, "max_line_length": 856, "alphanum_fraction": 0.7202406718, "num_tokens": 6516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6854456103056953}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 5}\n\n\\begin{enumerate}\n\\item Prove that a vertex in a rooted tree can have at most one parent.\n\\item Prove that every vertex other than the root has exactly one parent.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}\n\\item Proof is given by contradiction.\nAssume node $v_i$ is a vertex in a rooted tree with more than one parents.\nIn this case, there will be two nodes $v_{r_1}$ and $v_{r_2}$ for which $v_i$ is a child.\nThen, either one of $v_{r_1}$ and $v_{r_2}$ or none of them is the root of the tree.\n\nIn case none of them is the root, there is another node $u$ which is root and there are two paths $u \\rightarrow \\cdots \\rightarrow v_{r_1} \\rightarrow v_i$ and $u \\rightarrow \\cdots \\rightarrow v_{r_2} \\rightarrow v_i$.\nThis means there is a simple loop of the form $u \\rightarrow v_{r_1} \\rightarrow \\cdots \\rightarrow v_i \\rightarrow v_{r_2} \\rightarrow \\cdots \\rightarrow u$ which contradicts the definition of the tree.\n\nOn the other hand, if one of $v_{r_1}$ and $v_{r_2}$ is the root, there is a path from the root to $v_i$ and $v_i$ to its other parent which means $v_i$ is the parent of the other node which contradicts the previous assumption that $v_i$ has two roots.\n\nTherefore the initial assumption is false and proof is complete.\n\n\\item The proof is again given by contradiction.\nAssume that in the tree with root $u$, there is a node $v_i$ with more than two parents.\nIn this case, $v_i$ is child of at least two nodes $v_{r_1}$ and $v_{r_2}$.\nAs there are distinct paths $u \\rightarrow \\cdots \\rightarrow v_{r_1}$ and $u \\rightarrow \\cdots \\rightarrow v_{r_2}$, there will be a simple loop of the form $u \\rightarrow \\cdots \\rightarrow v_{r_1} \\rightarrow v_i \\rightarrow v_{r_2} \\rightarrow \\cdots \\rightarrow u$ which contradicts the definition of the tree.\nThus the initial assumption is false and proof is complete.\n\\end{enumerate}\n", "meta": {"hexsha": "66aa9f924e40c6fda0d14d513a041ad23dac248f", "size": 2244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q05.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q05.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q05.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": 62.3333333333, "max_line_length": 316, "alphanum_fraction": 0.7076648841, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388252252041, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.6852934998376413}}
{"text": "\\section{Open loop analysis}\n\\subsection{Longitudinal motion}\nReducing the state space system such that it only contains the states $\\left \\{ V_t, \\alpha, \\theta, q \\right \\}$ and input $\\left \\{ \\delta_{el} \\right \\}$ results in the following matrices for the state space in Equation~\\ref{eq:ssac}. $I_4$ is a 4x4 identity matrix and $0_{4,1}$ is a 4x1 zero matrix.\n\n\\begin{equation}\n    \\label{eq:sslon}\n    \\begin{aligned}\n        A_{lon}&=\\begin{bmatrix}\n            -0.08894   &  -10.7   &   -32.17   & -3.977 \\\\\n            -0.0005042 & -0.05167 & -3.989e-14 &   0.9792 \\\\\n                    0 &        0 &          0 &        1 \\\\\n            1.228e-18 &  -0.6256 &          0 &  -0.2485\n        \\end{bmatrix} &\n        B_{lon}&=\\begin{bmatrix}\n            -0.07104 \\\\\n            -0.0002308 \\\\\n                    0 \\\\\n            -0.01541 \n        \\end{bmatrix} \\\\\\\\\n        C_{lon}&=I_4 &\n        D_{lon}&=0_{4,1}\n    \\end{aligned}\n\\end{equation}\n\n\\begin{align}    \n    \\dot{x} &= A_{lon} \\cdot x + B_{lon} \\cdot u_{el} \\nonumber\\\\\n    y &= C_{lon} \\cdot x + D_{lon} \\cdot u_{el} \\label{eq:ssac}\n\\end{align}\n\nAnalyzing the eigenvalues of the $A_{lon}$ matrix yields the following parameters for the inherent flight motions.\n\n\\begin{table}[h!]\n    \\centering\n    \\begin{tabular}{ r | c c c c c }\n                     & Poles                            & $\\zeta$        & $\\omega_n$     & $P$           & $T_{1/2}$     \\\\ \\hline \\hline\n        Short period & $\\e{-1.53}{-1} + \\e{7.62}{-1}i$ & $\\e{1.97}{-1}$ & $\\e{7.77}{-1}$ & $8.09$        & $4.43$        \\\\  \n                     & $\\e{-1.53}{-1} - \\e{7.62}{-1}i$ & $\\e{1.97}{-1}$ & $\\e{7.77}{-1}$ & $8.09$        & $4.43$        \\\\ \\hline\n        Phugoid      & $\\e{-4.17}{-2} + \\e{1.23}{-1}i$ & $\\e{3.22}{-1}$ & $\\e{1.30}{-1}$ & $\\e{4.82}{1}$ & $\\e{1.56}{1}$ \\\\   \n                     & $\\e{-4.17}{-2} - \\e{1.23}{-1}i$ & $\\e{3.22}{-1}$ & $\\e{1.30}{-1}$ & $\\e{4.82}{1}$ & $\\e{1.56}{1}$\n    \\end{tabular}\n    \\caption{Longitudinal eigenmotions poles, damping rations, natural frequencies, periods and time to half amplitude.}\n\\end{table}\n\nThe poles are the eigenvalues of $A_{lon}$ matrix, $\\zeta$ the damping, $\\omega_n$ the natural frequency, $P$ the oscillation period and $T_{1/2}$ the time to damp to half amplitude. These parameters are calculated from the poles $\\lambda =\\xi \\pm \\eta i$ using the following equations.\n\n\\begin{align}\n    \\omega_n&=\\left | \\lambda\\right | \\\\\n    \\zeta&=-\\frac{\\xi}{\\omega_n} \\\\\n    P&=\\frac{2\\pi}{\\omega_n} \\\\\n    T_{1/2}&=P \\cdot \\frac{\\ln{2}}{2 \\pi} \\cdot \\frac{\\sqrt{1-\\zeta^2}}{\\zeta}\n\\end{align}\n\nSimulations are performed to get the time response for each motion in order to check whether the calculated parameters are correct. In order to do this check visually two elements are added to the figures. The first one are the \\emph{period markers}. These are a set of vertical lines separated by the calculated period $P$ and aligned with the first peak.\n\nThe second element are one or two exponential decay functions in the form shown below.\n\n\\begin{equation}\n    f(t) = C_1\\left(\\frac{1}{2}\\right)^{\\frac{t}{T_{1/2}}} + C_2\n\\end{equation}\n\nWhere $t$ is the time,and $C_1$ and $C_2$ are constants used to adjust the initial value. The result of this function reduces by half every $T_{1/2}$, thus it can be used to check whether the amplitude of the oscillations is reducing at the same rate. Figure~\\ref{fig:ol_sp} shows the results of these simulations.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/ol_sp}    \n    \\caption{Pitch-rate $q$ response during a short period oscillation, induced by a impulse elevator input.}\n    \\label{fig:ol_sp}\n\\end{figure}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/ol_ph}    \n    \\caption{Pitch angle $\\theta$ response during a phugoid induced by an initial pitch angle of $\\theta_0=0.1\\ [rad]$}\n    \\label{fig:ol_ph}\n\\end{figure}\n\n\\subsection{Lateral motion}\nReducing the state space system such that it only contains the states $\\left \\{ \\beta, \\phi, p, r \\right \\}$ and inputs $\\left \\{ \\delta_{a}, \\delta_{r} \\right \\}$ results in the following matrices for the state space in Equation~\\ref{eq:ssaclat}. $I_4$ is a 4x4 identity matrix and $0_{4,2}$ is a 4x2 zero matrix.\n\n\n\\begin{align*}\n    A_{lat}&=\\begin{bmatrix}\n        -0.04905 & 0.08741 &  0.5803 & -0.8129 \\\\\n               0 &       0 &       1 &  0.7105 \\\\\n          -2.547 &       0 & -0.2594 &   0.151 \\\\\n           -0.59 &       0 & 0.02607 & -0.1313\n    \\end{bmatrix} &\n    B_{lat}&=\\begin{bmatrix}\n        4.181e-05 & 0.0001227 \\\\\n                0 &         0 \\\\\n          -0.0444 &  -0.00523 \\\\\n         0.002184 & -0.004975 \n    \\end{bmatrix} \\\\\\\\\n    C_{lat}&=I_4 &\n    D_{lat}&=0_{4,2}\n\\end{align*}\n\n\\begin{align}    \n    \\dot{x} &= A_{lat} \\cdot x + B_{lat} \\cdot u_{el} \\nonumber\\\\\n    y &= C_{lat} \\cdot x + D_{lat} \\cdot u_{el} \\label{eq:ssaclat}\n\\end{align}\n\nThe poles for this system are,\n\\begin{table}[h!]\n    \\centering\n    \\begin{tabular}{ c }\n        Poles \\\\ \\hline \\hline\n        $\\e{-1.68}{-1}$ \\\\\n        $\\e{-1.68}{-1}$ \\\\\n        $\\e{-5.18}{-2}$ \\\\\n        $\\e{-5.18}{-2}$ \\\\\n    \\end{tabular}\n    \\caption{Lateral eigenmotion poles}\n\\end{table}\n\nFor the lateral motion it is expected to find two complex poles for the dutch roll and two real poles, one for the aperiodic roll and one for the spiral motion. However under the given flight conditions the linearization code fails and generates systems with four complex poles.\n\nIn order to continue with the assignment the flight conditions for the Accelerometer Position Analysis are used.\n\n\\begin{equation*}\n    h_{apa} = 15000ft \\qquad  V_{apa}=500ft/s\n\\end{equation*}\n\nLinearising under these flight conditions results in the following,\n\n\\begin{align*}\n    A_{lat}&=\\begin{bmatrix}\n        -0.2022 & 0.06414 & 0.07827 & -0.9919 \\\\\n              0 &       0 &       1 &  0.0781 \\\\\n         -22.92 &       0 &  -2.254 &  0.5408 \\\\\n          6.005 &       0 & -0.0404 & -0.3146\n    \\end{bmatrix} &\n    B_{lat}&=\\begin{bmatrix}\n        0.0001724 & 0.0005058 \\\\\n                0 &         0 \\\\\n          -0.4623 &   0.05686 \\\\\n         -0.02437 &  -0.04687 \n    \\end{bmatrix} \\\\\\\\\n    C_{lat}&=I_4 &\n    D_{lat}&=0_{4,2}\n\\end{align*}\n\n\\begin{table}[h!]\n    \\centering\n    \\begin{tabular}{ r | c c c c c c }\n                       & Poles                   & $\\zeta$        & $\\omega_n$     & $P$    & $T_{1/2}$     & $\\tau$         \\\\ \\hline \\hline\n        Dutch roll     & $\\e{-3.20}{-1} + 2.74i$ & $\\e{1.16}{-1}$ & $\\e{7.77}{-1}$ & $2.28$ & $4.43$        &                \\\\  \n                       & $\\e{-3.20}{-1} - 2.74i$ & $\\e{1.16}{-1}$ & $\\e{7.77}{-1}$ & $2.28$ & $2.14$        &                \\\\ \\hline\n        Aperiodic roll & $2.12$                  &                &                &        & $\\e{1.56}{1}$ & $\\e{4.72}{-1}$ \\\\ \\hline \n        Spiral         & $\\e{-1.13}{-2}$         &                &                &        & $\\e{1.56}{1}$ & $\\e{8.88}{1}$\n    \\end{tabular}\n    \\caption{Lateral eigenmotions poles, damping rations, natural frequencies, periods, time to half amplitude and time constants.}\n\\end{table}\n\nFor the aperiodic eigenmotions, there is a new parameter $\\tau$, the time constant and the time to damp to half amplitude $T_{1/2}$ is calculated differently.\n\n\\begin{align}\n    \\tau &= -\\frac{1}{\\lambda} \\\\\n    T_{1/2} &= \\ln{2}\\ \\tau\n\\end{align}\n\nThe results of these simulations are shown in the following figures. Despite being an aperiodic motions, the aperiodic roll and spiral results both contain oscillations. This is due to a less dominant dutch roll. To show this, Figure~\\ref{fig:ol_apdsf} has the period markers with the period for the dutch roll added to it.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/ol_dr}    \n    \\caption{Yaw rate $r$ response during a dutch roll induced by an impulse rudder input.}\n    \\label{fig:ol_dr}\n\\end{figure}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/ol_ap}    \n    \\caption{Roll rate $p$ response during an aperiodic roll induced by an initial roll rate of $r_0=0.1\\ \n    [rad\\ s^{-1}]$}\n    \\label{fig:ol_apdsf}\n\\end{figure}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/ol_si}    \n    \\caption{Bank angle $\\phi$ response during a spiral motion induced by an initial bank angle of $\\phi_0=0.1\\ [rad]$}\n    \\label{fig:ol_si}\n\\end{figure}\n\n\\clearpage\n", "meta": {"hexsha": "74235e9a2a5f78a6e3086887664e2e03b6dbb499", "size": 8521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/2_open_loop_analysis.tex", "max_stars_repo_name": "aarondewindt/afcs_assignment", "max_stars_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/2_open_loop_analysis.tex", "max_issues_repo_name": "aarondewindt/afcs_assignment", "max_issues_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/2_open_loop_analysis.tex", "max_forks_repo_name": "aarondewindt/afcs_assignment", "max_forks_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-04T15:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-04T15:55:23.000Z", "avg_line_length": 45.5668449198, "max_line_length": 356, "alphanum_fraction": 0.5689473067, "num_tokens": 2896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6852934947336302}}
{"text": "\\lab{Interior Point 1: Linear Programs}{Interior Point 1: Linear Programs}\n\n% Bold mu, lambda, and beta symbols for this lab. TODO: move to command.tex.\n\\def\\Mu{\\boldsymbol{\\mu}}\n\\def\\Lamb{\\boldsymbol{\\lambda}}\n\\def\\Beta{\\boldsymbol{\\beta}}\n\n\\objective{For decades after its invention, the Simplex algorithm was the only competitive method for linear programming.\nThe past 30 years, however, have seen the discovery and widespread adoption of a new family of algorithms that rival--and in some cases outperform--the Simplex algorithm, collectively called \\emph{Interior Point methods}.\nOne of the major shortcomings of the Simplex algorithm is that the number of steps required to solve the problem can grow exponentially with the size of the linear system.\nThus, for certain large linear programs, the Simplex algorithm is simply not viable.\nInterior Point methods offer an alternative approach and enjoy much better theoretical convergence properties.\nIn this lab we implement an Interior Point method for linear programs, and in the next lab we will turn to the problem of solving quadratic programs.}\n\n\\section*{Introduction}\n\nRecall that a linear program is a constrained optimization problem with a linear objective function and linear constraints.\nThe linear constraints define a set of allowable points called the \\emph{feasible region}, the boundary of which forms a geometric object known as a \\emph{polytope}.\nThe theory of convex optimization ensures that the optimal point for the objective function can be found among the vertices of the feasible polytope. The Simplex Method tests a sequence of such vertices until it finds\nthe optimal point.\nProvided the linear program is neither unbounded nor infeasible, the algorithm is certain to produce the correct answer after a finite number of steps, but it does not guarantee an efficient path along the polytope toward the minimizer.\nInterior point methods do away with the feasible polytope and instead generate a sequence of points that cut through the interior (or exterior) of the feasible region and converge iteratively to the optimal point.\nAlthough it is computationally more expensive to compute such interior points, each step results in significant progress toward the minimizer.\nSee Figure \\ref{fig:intPath}.\nIn general, the Simplex Method requires many more iterations (though each iteration is less expensive computationally).\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/interiorPath.pdf}\n\\caption{A path traced by an Interior Point algorithm.}\n\\label{fig:intPath}\n\\end{figure}\n\n\\section*{Primal-Dual Interior Point Methods} % ALGORITHM =====================\nSome of the most popular and successful types of Interior Point methods are known as Primal-Dual Interior Point methods.\nConsider the following linear program:\n\\begin{align*}\n\\text{minimize }\\qquad &\\c\\trp \\x\\\\\n\\text{subject to }\\qquad &A\\x = \\b\\\\\n&\\x \\succeq \\0.\n\\end{align*}\nHere, $\\x, \\c \\in \\mathbb{R}^n$, $\\b \\in \\mathbb{R}^m$, and $A$ is an $m \\times n$ matrix with full row rank.\n% By $x \\succeq 0$, we simply mean that each coordinate of $x$ is nonnegative.\n% Note that this formulation is quite general, as any linear program can be posed in this manner, after appropriate transformations.\nThis is the \\emph{primal} problem, and its \\emph{dual} takes the form:\n\\begin{align*}\n\\text{maximize }\\qquad &\\b\\trp \\Lamb\\\\\n\\text{subject to }\\qquad &A\\trp \\Lamb + \\Mu = \\c\\\\\n&\\Mu,\\Lamb \\succeq \\0,\n\\end{align*}\nwhere $\\Lamb \\in \\mathbb{R}^m$ and $\\Mu \\in \\mathbb{R}^n$.\n% Changed s to \\mu to match the textbook.\n\n\\subsection*{KKT Conditions}\n\nThe theory of convex optimization gives us necessary and sufficient conditions for the solutions to the primal and dual problems via the Karush-Kuhn-Tucker (KKT) conditions.\nThe Lagrangian for the primal problem is as follows:\n\\[\n\\CalL(\\x, \\Lamb, \\Mu)\n= \\c\\trp \\x + \\Lamb\\trp (\\b - A\\x) - \\Mu\\trp \\x\n\\]\nThe KKT conditions are\n\\begin{align*}\nA\\trp \\Lamb + \\Mu &= \\c\\\\\nA\\x &= \\b\\\\\nx_i\\mu_i &= 0, \\quad i = 1,2,\\ldots,n,\\\\\n\\x, \\Mu &\\succeq 0.\n\\end{align*}\nIt is convenient to write these conditions in a more compact manner, by defining an almost-linear function $F$ and setting it equal to zero:\n\\begin{align*}\nF(\\x,\\Lamb,\\Mu) :=\n\\begin{bmatrix}\nA\\trp \\Lamb + \\Mu - \\c\\\\\nA\\x - \\b\\\\\nM\\x\\\\\n\\end{bmatrix}\n&= \\0,\\\\\n(\\x,\\Mu &\\succeq \\0),\n\\end{align*}\nwhere $M = \\text{diag}(\\mu_1,\\mu_2,\\ldots,\\mu_n)$.\nNote that the first row of $F$ is the KKT condition for dual feasibility, the second row of $F$ is the KKT condition for the primal problem, and the last row of $F$ accounts for complementary slackness.\n\n\\begin{comment} % Derivation overkill vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nFirst, we calculate the so-called \\emph{Lagrangian function} for our linear program.\nRecall that the Lagrangian function for a general constrained optimization problem of the form\n\\begin{align*}\n\\text{minimize }\\qquad &f(x)\\\\\n\\text{subject to }\\qquad &c_i(x) = 0, \\quad i = 1,2,\\ldots,k,\\\\\n&d_i(x) \\geq 0, \\quad i = 1,2,\\ldots,j,\n\\end{align*}\nis defined to be\n\\[\n\\mathcal{L}(x, \\lambda, s) := f(x) - \\displaystyle\\sum_{i=1}^k\\lambda_ic_i(x) - \\displaystyle\\sum_{i=1}^js_id_i(x).\n\\]\nFrom here, the KKT conditions are\n\\begin{align*}\n\\nabla_x\\mathcal{L}(x,\\lambda,s) &= 0,\\\\\nc_i(x) &= 0,\\quad i = 1,2,\\ldots,k,\\\\\ns_id_i(x) &= 0,\\quad i=1,2,\\ldots,j,\\\\\nd_i(x) &\\geq 0,\\quad i=1,2,\\ldots,j,\\\\\ns_i &\\geq 0,\\quad i=1,2,\\ldots,j.\n\\end{align*}\nFor our linear program, $f(x) = c\\trp x$, $c_i(x) = A_i\\trp x - b_i$ (where $A_i$ denotes the $i$-th row of $A$), and $d_i(x) = x_i$.\nHence, you can check that our Lagrangian function is\n\\[\n\\mathcal{L}(x,\\lambda,s) = c\\trp x - \\lambda\\trp (Ax - b) - s\\trp x.\n\\]\nWe then calculate\n\\[\n\\nabla_x\\mathcal{L}(x,\\lambda,s) = (c\\trp  - \\lambda\\trp A - s\\trp )\\trp  = c - A\\trp \\lambda - s.\n\\]\nThe KKT conditions can now be expressed as follows:\n\\begin{align*}\nA\\trp \\lambda + s &= c\\\\\nA\\x &= \\b\\\\\nx_is_i &= 0, \\quad i = 1,2,\\ldots,n,\\\\\n\\x, \\mathbf{s} &\\succeq 0.\n\\end{align*}\nIn fact, it is convenient to write these conditions in a more compact manner, by defining an almost-linear function $F$ and setting it equal to zero:\n\\begin{align*}\nF(\\x,\\Lamb,\\Mu) :=\n\\begin{bmatrix}\nA\\trp \\lambda + s - c\\\\\nAx - b\\\\\nXSe\\\\\n\\end{bmatrix}\n&= 0,\\\\\n(\\x,\\mathbf{s} &\\succeq \\0),\n\\end{align*}\nwhere $X = \\text{diag}(x_1,x_2,\\ldots,x_n)$, $S = \\text{diag}(s_1,s_2,\\ldots,s_n)$, and $e = (1,1,\\ldots,1)\\trp $.\n\\end{comment} % Derivation overkil ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n\\begin{problem} % First step: define F(x,lamb,mu) -----------------------------\nDefine a function \\li{interiorPoint()} that will be used to solve the complete interior point problem.\nThis function should accept $A$, $\\b$, and $\\c$ as parameters, along with the keyword arguments \\li{niter=20} and \\li{tol=1e-16}.\nThe keyword arguments will be used in a later problem.\n\nFor this problem, within the \\li{interiorPoint()} function, write a function for the vector-valued function $F$ described above.\nThis function should accept $\\x$, $\\Lamb$, and $\\Mu$ as parameters and return a 1-dimensional NumPy array with $2n+m$ entries.\n\\end{problem}\n\n\\subsection*{Search Direction}\n\nA Primal-Dual Interior Point method is a line search method that starts with an initial guess $(\\x_0\\trp , \\Lamb_0\\trp , \\Mu_0\\trp )$ and produces a sequence of points that converge to $({\\x^*}\\trp , {\\Lamb^*}\\trp , {\\Mu^*}\\trp )$, the solution to the KKT equations and hence the solution to the original linear program.\n%We now describe how to select the search direction and step length at each iteration of the algorithm.\nThe constraints on the problem make finding a search direction and step length a little more complicated than for the unconstrained line search we have studied previously.\n\nIn the spirit of Newton's Method, we can form a linear approximation of the system $F(\\x,\\Lamb,\\Mu) = \\0$ centered around our current point $(\\x, \\Lamb, \\Mu)$, and calculate the direction $(\\triangle \\x\\trp , \\triangle \\Lamb\\trp , \\triangle \\Mu\\trp )$ in which to step to set the linear approximation equal to $\\0$.\nThis equates to solving the linear system:\n\\begin{align}\nDF(\\x,\\Lamb,\\Mu)\n\\begin{bmatrix}\\triangle \\x\\\\ \\triangle \\Lamb\\\\ \\triangle \\Mu\\end{bmatrix}\n= - F(\\x,\\Lamb,\\Mu) \\label{eq:naiveNewton}\n\\end{align}\nHere $DF(\\x,\\Lamb,\\Mu)$ denotes the total derivative matrix of $F$.\nWe can calculate this matrix block-wise by obtaining the partial derivatives of each block entry of $F(\\x,\\Lamb, \\Mu)$ with respect to $\\x$, $\\Lamb$, and $\\Mu$, respectively.\nWe thus obtain:\n\\[\nDF(\\x,\\Lamb,\\Mu) = \\left[\\begin{array}{ccc}\n0 & A\\trp  & I \\\\\nA & 0 & 0 \\\\\nM & 0 & X\n\\end{array}\\right]\n\\]\nwhere $X = \\text{diag}(x_1,x_2,\\ldots,x_n).$\n\n\\begin{comment} % More derivation overkill vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nFor example, consider the topmost block entry of $F(\\x,\\Lamb,\\Mu)$, given by\n\\[\nA\\trp \\lambda + s - c.\n\\]\nWe calculate the partial derivatives of this expressions as follows:\n\\begin{align*}\n\\frac{\\partial}{\\partial x}[A\\trp \\lambda + s - c] &= 0,\\\\\n\\frac{\\partial}{\\partial \\lambda}[A\\trp \\lambda + s - c] &= A\\trp ,\\\\\n\\frac{\\partial}{\\partial s}[A\\trp \\lambda + s - c] &= I.\\\\\n\\end{align*}\nHence, the topmost block row of $DF(\\x,\\Lamb,\\Mu)$ is given by\n\\[\n\\begin{bmatrix}\n0 \\quad A\\trp  \\quad I\\\\\n\\end{bmatrix}.\n\\]\nContinuing in this manner, we can calculate the entire derivative matrix, which leads us to the following linear system:\n\\end{comment} % More derivation overkill ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nUnfortunately, solving Equation \\ref{eq:naiveNewton} often leads to a search direction that is too greedy.\nEven small steps in this direction may lead the iteration out of the feasible region by violating one of the constraints.\nTo remedy this, we define the \\emph{duality measure} $\\nu$\\footnote{$\\nu$ is the Greek letter for $n$, pronounced ``nu.''} of the problem: \\[\\nu = \\frac{\\x\\trp \\Mu}{n} \\]\nThe idea is to use Newton's method to identify a direction that strictly decreases $\\nu$.\nThus instead of solving Equation \\ref{eq:naiveNewton}, we solve:\n\\begin{align}\nDF(\\x,\\Lamb,\\Mu)\n\\begin{bmatrix}\\triangle \\x\\\\ \\triangle \\Lamb\\\\ \\triangle \\Mu\\end{bmatrix}\n= - F(\\x,\\Lamb,\\Mu) +\n\\begin{bmatrix} \\0 \\\\ \\0 \\\\ \\sigma\\nu\\e \\end{bmatrix}\n\\label{eq:newNewton}\n\\end{align}\nwhere $\\e = (1,1,\\ldots,1)\\trp $ and $\\sigma \\in [0,1)$ is called the \\emph{centering parameter}.\nThe closer $\\sigma$ is to 0, the more similar the resulting direction will be to the plain Newton direction.\nThe closer $\\sigma$ is to 1, the more the direction points inward to the interior of the of the feasible region.\n\n\\begin{problem} % Search direction --------------------------------------------\nWithin \\li{interiorPoint()}, write a subroutine to compute the search direction $(\\triangle \\x\\trp , \\triangle \\Lamb\\trp , \\triangle \\Mu\\trp )$ by solving Equation \\ref{eq:newNewton}.\nUse $\\sigma = \\frac{1}{10}$ for the centering parameter.\n\nNote that only the last block row of $DF$ will need to be changed at each iteration (since $M$ and $X$ depend on $\\Mu$ and $\\x$, respectively).\nConsider using the functions \\li{lu_factor()} and \\li{lu_solve()} from the \\li{scipy.linalg} module to solving the system of equations efficiently.\n\\end{problem}\n\n\\begin{comment} % Old strategy for search direction vvvvvvvvvvvvvvvvvvvvvvvvvvv\n\\begin{equation}\n\\begin{bmatrix}\n0 & A\\trp  & I\\\\\nA & 0 & 0\\\\\nS & 0 & X\n\\end{bmatrix}\n\\begin{bmatrix}\n\\triangle \\x\\\\\n\\triangle \\Lamb\\\\\n\\triangle \\Mu\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-r_c\\\\\n-r_b\\\\\n-XSe\n\\end{bmatrix},\n\\label{eq:affine}\n\\end{equation}\nwhere $r_b = Ax - b$ and $r_c = A\\trp \\lambda + s - c$.\nThis Newton direction is too greedy, however, and even small steps in this direction may cause us to violate the nonnegativity condition (the last line of the KKT conditions).\nWe need to find a new search direction.\n\nChoosing an appropriate search direction is a tricky task, and various approaches exist.\nWe will follow a popular strategy known as the \\emph{Predictor-Corrector Algorithm}.\nThe idea is to actually calculate two directions: we first calculate\nthe standard Newton direction described above; that is, we obtain the solution to Equation \\ref{eq:affine}.\nThis is known as the \\emph{predictor step}, since it gives us a direction in which the objective does indeed decrease, hence predicting our\nfinal search direction.\nDenote the solution to this system by $(\\triangle \\x^a, \\triangle \\Lamb^a, \\triangle \\Mu^a)$.\nAs discussed, however, we must deviate from this direction somewhat, and so we additionally solve the following linear system of equations:\n\\begin{equation}\n\\begin{bmatrix}\n0 & A\\trp  & I\\\\\nA & 0 & 0\\\\\nS & 0 & X\n\\end{bmatrix}\n\\begin{bmatrix}\n\\triangle \\x\\\\\n\\triangle \\Lamb\\\\\n\\triangle \\Mu\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-r_c\\\\\n-r_b\\\\\n-XSe - \\triangle X^a\\triangle S^ae + \\sigma \\mu e\n\\end{bmatrix}.\n\\label{eq:centering}\n\\end{equation}\nThe solution to this system, which we denote by $(\\triangle \\x, \\triangle \\Lamb, \\triangle \\Mu)$, is our final search direction.\n\nWe now describe the new pieces of Equation \\ref{eq:centering}.\nNote that\n\\begin{align*}\n\\triangle X^a &= \\text{diag}(\\triangle x_1^a,\\ldots,\\triangle x_n^a),\\\\\n\\triangle S^a &= \\text{diag}(\\triangle \\Mu_1^a,\\ldots,\\triangle \\Mu_n^a).\n\\end{align*}\nFurther, define $\\mu := x\\trp s/n$.\nThis quantity, called the \\emph{duality measure}, tells us roughly how close we are to the optimal solution, with values closer to 0 being more desirable.\nIt is present in Equation \\ref{eq:centering} for the purpose of obtaining a search direction that leads to a decrease towards 0 in the duality measure.\n\nThe formula for $\\sigma$ is somewhat more complicated, and is based on a heuristic approach.\nFirst, make the following calculations (which give the maximum allowable step lengths in the Newton search direction for $x$ and $s$ before the nonnegativity condition is violated):\n\\begin{align*}\n\\alpha_a^p &:= \\min\\left(1, \\displaystyle\\min_{i : \\triangle x_i^a < 0}-\\frac{x_i}{\\triangle x_i^a}\\right)\\\\\n\\alpha_a^d &:= \\min\\left(1, \\displaystyle\\min_{i : \\triangle \\mu_i^a < 0}-\\frac{s_i}{\\triangle \\mu_i^a}\\right).\n\\end{align*}\nNext, define\n\\[\n\\mu_a := \\frac{1}{n}(x+\\alpha_a^p\\triangle \\x^a)\\trp (s+\\alpha_a^d\\triangle \\Mu^a),\n\\]\nwhich is simply the duality measure for the point obtained by taking a full step in the Newton direction.\nFinally, calculate $\\sigma$ by the formula\n\\[\n\\sigma = \\left(\\frac{\\mu_a}{\\mu}\\right)^3.\n\\]\n\\end{comment} % Old strategy for search direction ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n\\subsection*{Step Length}\n\nNow that we have our search direction, it remains to choose our step length.\nWe wish to step nearly as far as possible without violating the problem's constraints, thus remaining in the interior of the feasible region.\nFirst, we calculate the maximum allowable step lengths for $\\x$ and $\\Mu$, respectively:\n\\begin{align*}\n\\alpha_{\\max} &= \\min\\left\\{1, \\min\\{-\\mu_i/\\triangle \\mu_i\\ |\\ \\triangle \\mu_i < 0 \\}\\right\\}\\\\\n\\delta_{\\max} &= \\min\\left\\{1, \\min\\{-x_i/\\triangle x_i\\ |\\ \\triangle x_i < 0 \\}\\right\\}\n\\end{align*}\nNext, we back off from these maximum step lengths slightly:\n\\begin{align*}\n\\alpha &= \\min(1, 0.95\\alpha_{\\max})\\\\\n\\delta &= \\min(1, 0.95\\delta_{\\max}).\n\\end{align*}\nThese are our final step lengths.\nThus, the next point in the iteration is given by:\n\\begin{align*}\n\\x_{k+1} &= \\x_k + \\delta \\triangle \\x_k\\\\\n(\\Lamb_{k+1}, \\Mu_{k+1}) &= (\\Lamb_k, \\Mu_k) + \\alpha(\\triangle \\Lamb_k, \\triangle \\Mu_k).\n\\end{align*}\n\n\\begin{comment} % Old strategy for step length vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\\begin{align*}\n\\beta^p &:= \\displaystyle\\min_{i : \\triangle x_i < 0}-\\frac{x_i}{\\triangle x_i}\\\\\n\\beta^d &:= \\displaystyle\\min_{i : \\triangle \\mu_i < 0}-\\frac{s_i}{\\triangle \\mu_i}.\n\\end{align*}\nNext, we back off from these maximum step lengths slightly:\n\\begin{align*}\n\\alpha^p &:= \\min(1, 0.95\\beta^p)\\\\\n\\alpha^d &:= \\min(1, 0.95\\beta^d).\n\\end{align*}\nThese are our final step lengths.\nThat is, our next point $(x', \\lambda', s')$ is given by\n\\begin{align*}\nx' &= x + \\alpha^p\\triangle \\x\\\\\n(\\lambda', s') &= (\\lambda, s) + \\alpha^d(\\triangle \\Lamb, \\triangle \\Mu).\n\\end{align*}\n\nWe summarize the entire procedure in Algorithm \\ref{alg:predcorr}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Predictor-Corrector Algorithm}{}\n    \\State \\textrm{Choose initial point } $(x_0, \\lambda_0, s_0)$.\n    \\For{$k = 0, 1, 2, \\ldots$}\n        \\State \\textrm{Solve for } $(\\triangle \\x^a, \\triangle \\Lamb^a, \\triangle \\Mu^a)$.\n        \\State \\textrm{Calculate } $\\alpha_a^p, \\alpha_a^d, \\mu_a$, \\textrm{and} $\\sigma$.\n        \\State \\textrm{Solve for } $(\\triangle \\x, \\triangle \\Lamb, \\triangle \\Mu)$.\n        \\State \\textrm{Calculate the step lengths } $\\alpha^p, \\alpha^d$.\n        \\State $x_{k+1} = x_k + \\alpha^p\\triangle \\x$,\\\\\n        $\\qquad\\quad(\\lambda_{k+1}, s_{k+1}) = (\\lambda_k, s_k) + \\alpha^d(\\triangle \\Lamb, \\triangle \\Mu)$.\n    \\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Predictor-Corrector Algorithm}\n\\label{alg:predcorr}\n\\end{algorithm}\n\\end{comment} % Old strategy for step length ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\\begin{comment} % Unnecessary / confusing hints vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nA few notes on the implementation of this algorithm are in order.\nIn each iteration, by far the most expensive operations are solving Equations \\ref{eq:affine} and \\ref{eq:centering}.\nFortunately, the only difference between the two equations is the right-hand side.\nThus, we can avoid repetitious calculation by first factorizing the block matrix\n\\[\n\\begin{bmatrix}\n0 & A\\trp  & I\\\\\nA & 0 & 0\\\\\nS & 0 & X\n\\end{bmatrix}\n\\]\nonce at the beginning of the iteration, and then using the factorization twice to solve both equations.\nFor convenience, consider using the functions \\li{lu_factor()} and \\li{lu_solve()} from the \\li{scipy.linalg} module.\nIt is possible to speed up these calculations further, but for simplicity we won't pursue the issue further.\n\nNext, as mentioned above, the duality measure $\\mu$ tells us in some sense how close our current point is to the minimizer.\nThe closer $\\mu$ is to 0, the closer we are to the optimal point.\nThus, by printing the value of $\\mu$ at each iteration, you can track how your algorithm is progressing and detect when you have converged.\n\nAnother potentially tricky calculation that comes up in each iteration has the following form:\n\\[\n\\min\\left(1, \\displaystyle\\min_{i : u_i < 0}-\\frac{v_i}{u_i}\\right),\n\\]\nwhere $\\mathbf{u} = (u_1, \\ldots, u_n)\\trp $ and $\\mathbf{v} = (v_1, \\ldots, v_n)\\trp $ are vectors.\nThis can be done in a vectorized fashion in Python as follows (assuming that the arrays \\li{u} and \\li{v} have already been initialized):\n\\begin{lstlisting}\n>>> mask = u < 0\n>>> if np.any(mask):\n>>>     myMin = min(1, (-v/u)[mask].min())\n>>> else:\n>>>     myMin = 1\n\\end{lstlisting}\nWe need the \\li{if} statement to deal with the case where no entry of $u$ is negative.\n\\end{comment} % Unnecessary / confusing hints ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n\\begin{problem} % Step size ---------------------------------------------------\nWithin \\li{interiorPoint()}, write a subroutine to compute the step size after the search direction has been computed.\nAvoid using loops when computing $\\alpha_{\\max}$ and $\\beta_{\\max}$ (use masking and NumPy functions instead).\n\\end{problem}\n\n\\subsection*{Initial Point}\nFinally, the choice of initial point $(\\x_0, \\Lamb_0, \\Mu_0)$ is an important, nontrivial one.\nA na\\\"{i}vely or randomly chosen initial point may cause the algorithm to fail to converge.\nThe following function will calculate an appropriate initial point.\n\n% TODO: change name from startingPoint() to starting_point() in spec / solution\n\\begin{lstlisting}\ndef starting_point(A, b, c):\n    \"\"\"Calculate an initial guess to the solution of the linear program\n    min c\\trp  x, Ax = b, x>=0.\n    Reference: Nocedal and Wright, p. 410.\n    \"\"\"\n    # Calculate x, lam, mu of minimal norm satisfying both\n    # the primal and dual constraints.\n    B = la.inv(A @ A.T))\n    x = A.T @ B @ b\n    lam = B @ A @ c\n    mu = c - (A.T @ lam)\n\n    # Perturb x and s so they are nonnegative.\n    dx = max((-3./2)*x.min(), 0)\n    dmu = max((-3./2)*mu.min(), 0)\n    x += dx*np.ones_like(x)\n    mu += dmu*np.ones_like(mu)\n\n    # Perturb x and mu so they are not too small and not too dissimilar.\n    dx = .5*(x*mu).sum()/mu.sum()\n    dmu = .5*(x*mu).sum()/x.sum()\n    x += dx*np.ones_like(x)\n    mu += dmu*np.ones_like(mu)\n\n    return x, lam, mu\n\\end{lstlisting}\n\n\\begin{problem} % Put it all together -----------------------------------------\nComplete the implementation of \\li{interiorPoint()}.\n\nUse the function \\li{starting_point()} provided above to select an initial point, then run the iteration \\li{niter} times, or until the duality measure is less than \\li{tol}.\nReturn the optimal point $\\x^*$ and the optimal value $\\c\\trp \\x^*$.\n\nThe duality measure $\\nu$ tells us in some sense how close our current point is to the minimizer.\nThe closer $\\nu$ is to 0, the closer we are to the optimal point.\nThus, by printing the value of $\\nu$ at each iteration, you can track how your algorithm is progressing and detect when you have converged.\n\nTo test your implementation, use the following code to generate a random linear program, along with the optimal solution.\n% TODO: update the spec file with this version of randomLP().\n\\begin{lstlisting}\n    \"\"\"Generate a linear program min c\\trp  x s.t. Ax = b, x>=0.\n    First generate m feasible constraints, then add\n    slack variables to convert it into the above form.\n    Inputs:\n        m (int >= n): number of desired constraints.\n        n (int): dimension of space in which to optimize.\n    Outputs:\n        A ((m,n+m) ndarray): Constraint matrix.\n        b ((m,) ndarray): Constraint vector.\n        c ((n+m,), ndarray): Objective function with m trailing 0s.\n        x ((n,) ndarray): The first 'n' terms of the solution to the LP.\n    \"\"\"\n    A = np.random.random((m,n))*20 - 10\n    A[A[:,-1]<0] *= -1\n    x = np.random.random(n)*10\n    b = np.zeros(m)\n    b[:n] = A[:n,:] @ x\n    b[n:] = A[n:,:] @ x + np.random.random(m-n)*10\n    c = np.zeros(n+m)\n    c[:n] = A[:n,:].sum(axis=0)/n\n    A = np.hstack((A, np.eye(m)))\n    return A, b, -c, x\n\\end{lstlisting}\n\\begin{lstlisting}\n>>> m, n = 7, 5\n>>> A, b, c, x = randomLP(m, n)\n>>> point, value = interiorPoint(A, b, c)\n>>> np.allclose(x, point[:n])\n<<True>>\n\\end{lstlisting}\n\\end{problem}\n\n% TODO: In the future, time interiorPoint() against a Simplex method (CVXOPT?).\n% Have a problem to demonstrate the advantages of each algorithm.\n\n\\section*{Least Absolute Deviations (LAD)} % APPLICATION ======================\nWe now return to the familiar problem of fitting a line (or hyperplane) to a set of data.\nWe have previously approached this problem by minimizing the sum of the squares of the errors between the data points and the line, an approach known as \\emph{least squares}.\nThe least squares solution can be obtained analytically when fitting a linear function, or through a number of optimization methods (such as Conjugate Gradient) when fitting a nonlinear function.\n\nThe method of \\emph{least absolute deviations} (LAD) also seeks to find a best fit line to a set of data, but the error between the data and the line is measured differently.\nIn particular, suppose we have a set of data points $(y_1, \\x_1), (y_2, \\x_2), \\ldots, (y_m, \\x_m)$, where $y_i \\in \\mathbb{R}$, $\\x_i \\in \\mathbb{R}^n$ for $i = 1, 2, \\ldots, m$.\nHere, the $\\x_i$ vectors are the \\emph{explanatory variables} and the $y_i$ values are the \\emph{response variables}, and we assume the following linear model:\n\\[\ny_i = \\Beta\\trp \\mathbf{x}_i + b, \\qquad i = 1, 2, \\ldots, m,\n\\]\nwhere $\\Beta\\in\\mathbb{R}^n$ and $b \\in \\mathbb{R}$.\nThe error between the data and the proposed linear model is given by\n\\[\n\\sum_{i=1}^n |\\Beta\\trp \\mathbf{x}_i + b - y_i|,\n\\]\nand we seek to choose the parameters $\\Beta, b$ so as to minimize this error.\n\n\\subsection*{Advantages of LAD}\nThe most prominent difference between this approach and least squares is how they respond to outliers in the data.\nLeast absolute deviations is robust in the presence of outliers, meaning that one (or a few) errant data points won't severely affect the fitted line.\nIndeed, in most cases, the best fit line is guaranteed to pass through at least two of the data points.\nThis is a desirable property when the outliers may be ignored (perhaps because they are due to measurement error or corrupted data).\nLeast squares, on the other hand, is much more sensitive to outliers, and so is the better choice when outliers cannot be dismissed.\nSee Figure \\ref{fig:leastAbsDev}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/leastAbsDev.pdf}\n\\caption{Fitted lines produced by least absolute deviations (top) and least squares (bottom). The presence of an outlier accounts for the\nstark difference between the two lines.}\n\\label{fig:leastAbsDev}\n\\end{figure}\n\nWhile least absolute deviations is robust with respect to outliers, small horizontal perturbations of the data points can lead to very different fitted lines.\nHence, the least absolute deviations solution is less stable than the least squares solution.\nIn some cases there are even infinitely many lines that minimize the least absolute deviations error term.\nHowever, one can expect a unique solution in most cases.\n\nThe least absolute deviations solution arises naturally when we assume that the residual terms $\\Beta\\trp \\mathbf{x}_i + b - y_i$ have a particular statistical distribution (the Laplace distribution).\nUltimately, however, the choice between least absolute deviations and least squares depends on the nature of the data at hand, as well as your own good judgment.\n\n% =============================================================================\n% =============================================================================\n% EDITED TO HERE ==============================================================\n% =============================================================================\n% =============================================================================\n\n\\subsection*{LAD as a Linear Program}\nWe can formulate the least absolute deviations problem as a linear program, and then solve it using our interior point method.\nFor $i = 1, 2, \\ldots, m$ we introduce the artificial variable $u_i$ to take the place of the error term $|\\Beta\\trp \\mathbf{x}_i + b - y_i|$, and we require this variable to satisfy $u_i \\geq |\\Beta\\trp \\mathbf{x}_i + b - y_i|$.\nThis constraint is not yet linear, but we can split it into an equivalent set of two linear constraints:\n\\begin{align*}\nu_i &\\geq \\Beta\\trp \\mathbf{x}_i + b - y_i,\\\\\nu_i &\\geq y_i - \\Beta\\trp \\mathbf{x}_i - b.\n\\end{align*}\nThe $u_i$ are implicitly constrained to be nonnegative.\n\nOur linear program can now be stated as follows:\n\\begin{align*}\n\\text{minimize }\\qquad &\\sum_{i=1}^m u_i\\\\\n\\text{subject to }\\qquad &u_i \\geq \\Beta\\trp \\mathbf{x}_i + b - y_i,\\\\\n&u_i \\geq y_i - \\Beta\\trp \\mathbf{x}_i - b.\n\\end{align*}\nNow for each inequality constraint, we bring all variables ($u_i, \\Beta, b$) to the left hand side and introduce a nonnegative slack variable to transform the constraint into an equality:\n\\begin{align*}\nu_i  - \\Beta\\trp \\mathbf{x}_i - b - s_{2i-1}&= -y_i,\\\\\nu_i +\\Beta\\trp \\mathbf{x}_i + b - s_{2i}&= y_i,\\\\\ns_{2i-1}, s_{2i}&\\geq 0.\n\\end{align*}\n\nNotice that the variables $\\Beta, b$ are not assumed to be nonnegative, but in our interior point method, all variables are assumed to be nonnegative.\nWe can fix this situation by writing these variables as the difference of nonnegative variables:\n\\begin{align*}\n  \\Beta &= \\Beta_1 - \\Beta_2,\\\\\n  b &= b_1 - b_2,\\\\\n  &\\Beta_1, \\Beta_2\\succeq \\0; b_1, b_2 \\geq 0.\n\\end{align*}\nSubstituting these values into our constraints, we have the following system of constraints:\n\\begin{align*}\nu_i  - \\Beta_1\\trp \\mathbf{x}_i + \\Beta_2\\trp \\mathbf{x}_i - b_1 + b_2 - s_{2i-1}&= -y_i,\\\\\nu_i + \\Beta_1\\trp \\mathbf{x}_i - \\Beta_2\\trp \\mathbf{x}_i + b_1 - b_2 - s_{2i}&= y_i,\\\\\n\\Beta_1, \\Beta_2 \\succeq \\0; u_i, b_1, b_2, s_{2i-1}, s_{2i}&\\geq 0.\n\\end{align*}\nWriting $\\mathbf{y} = (-y_1, y_1, -y_2, y_2, \\ldots, -y_m, y_m)\\trp $ and $\\Beta_i = (\\beta_{i,1}, \\ldots, \\beta_{i,n})\\trp $ for $i = \\{1, 2\\}$, we can aggregate all of our variables into one vector as follows:\n\\[\n\\mathbf{v} = (u_1,\\ldots, u_m, \\beta_{1,1},\\ldots, \\beta_{1,n}, \\beta_{2,1},\\ldots, \\beta_{2,n}, b_1, b_2, s_1,\\ldots,s_{2m})\\trp .\n\\]\nDefining $\\c = (1, 1, \\ldots, 1, 0, \\ldots, 0)\\trp $ (where only the first $m$ entries are equal to 1), we can write our objective function as\n\\[\n\\sum_{i=1}^m u_i = \\mathbf{c}\\trp \\mathbf{v}.\n\\]\nHence, the final form of our linear program is:\n\\begin{align*}\n  \\text{minimize }\\qquad &\\mathbf{c}\\trp \\mathbf{v}\\\\\n  \\text{subject to }\\qquad A\\mathbf{v} &= \\mathbf{y},\\\\\n  \\mathbf{v} &\\succeq \\0,\n\\end{align*}\nwhere $A$ is a matrix containing the coefficients of the constraints.\nOur constraints are now equalities, and the variables are all nonnegative, so we are ready to use our interior point method to obtain the solution.\n\n\\subsection*{LAD Example}\n\nConsider the following example.\nWe start with an array \\li{data}, each row of which consists of the values $y_i, x_{i,1},\\ldots,x_{i,n}$, where $\\mathbf{x}_i = (x_{i,1}, x_{i,2}, \\ldots, x_{i,n})\\trp $.\nWe will have $3m + 2(n+1)$ variables in our linear program.\nBelow, we initialize the vectors $\\mathbf{c}$ and $\\mathbf{y}$.\n\\begin{lstlisting}\n>>> m = data.shape[0]\n>>> n = data.shape[1] - 1\n>>> c = np.zeros(3*m + 2*(n + 1))\n>>> c[:m] = 1\n>>> y = np.empty(2*m)\n>>> y[::2] = -data[:, 0]\n>>> y[1::2] = data[:, 0]\n>>> x = data[:, 1:]\n\\end{lstlisting}\n\nThe hardest part is initializing the constraint matrix correctly.\nIt has $2m$ rows and $3m + 2(n+1)$ columns.\nTry writing out the constraint matrix by hand for small $m, n$, and make sure you understand why the code below is correct.\n% TODO: Do this with NumPy stacking.\n\\begin{lstlisting}\n>>> A = np.ones((2*m, 3*m + 2*(n + 1)))\n>>> A[::2, :m] = np.eye(m)\n>>> A[1::2, :m] = np.eye(m)\n>>> A[::2, m:m+n] = -x\n>>> A[1::2, m:m+n] = x\n>>> A[::2, m+n:m+2*n] = x\n>>> A[1::2, m+n:m+2*n] = -x\n>>> A[::2, m+2*n] = -1\n>>> A[1::2, m+2*n+1] = -1\n>>> A[:, m+2*n+2:] = -np.eye(2*m, 2*m)\n\\end{lstlisting}\n\nNow we can calculate the solution by calling our interior point function.\n\\begin{lstlisting}\n>>> sol = interiorPoint(A, y, c, niter=10)[0]\n\\end{lstlisting}\n\nThe variable \\li{sol}, however, holds the value for the vector\n\\[\n\\mathbf{v} = (u_1,\\ldots, u_m, \\beta_{1,1},\\ldots, \\beta_{1,n}, \\beta_{2,1},\\ldots, \\beta_{2,n}, b_1, b_2, s_1,\\ldots,s_{2m+1})\\trp .\n\\]\nWe extract values of $\\Beta = \\Beta_1-\\Beta_2$ and $b = b_1 - b_2$ with the following code:\n\\begin{lstlisting}\n>>> beta = sol[m:m+n] - sol[m+n:m+2*n]\n>>> b = sol[m+2*n] - sol[m+2*n+1]\n\\end{lstlisting}\n\n\\begin{problem} % Least Total Deviations Problem ------------------------------\nThe file \\li{simdata.txt} contains two columns of data.\nThe first gives the values of the response variables ($y_i$), and the second column gives the values of the explanatory variables ($\\x_i$).\nFind the least absolute deviations line for this data set, and plot it together with the data.\nPlot the least squares solution as well to compare the results.\n\\begin{lstlisting}\n>>> from scipy.stats import linregress\n>>> slope, intercept = linregress(data[:,1], data[:,0])[:2]\n>>> domain = np.linspace(0,10,200)\n>>> plt.plot(domain, domain*slope + intercept)\n\\end{lstlisting}\n% \\begin{figure}[H] % solution to the problem with new simdata.\n% \\centering\n% \\includegraphics[width=\\textwidth]{figures/LADprob.pdf}\n% \\label{fig:LADprob}\n% \\end{figure}\n\\end{problem}\n", "meta": {"hexsha": "20fb9a40789bd688857822b756b247efdb3e7ef6", "size": 31648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume2/InteriorPoint_Linear/InteriorPoint_Linear.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/Volume2/InteriorPoint_Linear/InteriorPoint_Linear.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/Volume2/InteriorPoint_Linear/InteriorPoint_Linear.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.605015674, "max_line_length": 320, "alphanum_fraction": 0.6871840243, "num_tokens": 9667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.6852934929868101}}
{"text": "\\lab{Complex Integration}{Integration in the Complex Plane}\n\n\\objective{Understand some simple uses of residues and singularities in the complex plane.}\n\nIn the previous lab, we looked a visual representations of the roots and singularities of complex functions. Here we look more at singularities and what they can be used to compute.\n\n\\section*{Laurent Series and Singular Points}\n\nWe will now introduce another form of series representation of functions.\nA Laurent series of a function is a series of the form\n\\[\\sum_{n= -\\infty}^{\\infty} a_n (z-z_0)^n\\]\nIt can be proven that\n\\[a_n = \\frac{1}{2\\pi i} \\int_C \\frac{f(z)}{(z-z_0)^{n+1}} dz\\]\nwhere $C$ is a contour which passes counterclockwise around the singularity exactly once.\nWhen $f$ does not have a singularity at $z_0$ this representation degenerates to a normal Taylor Series (with the derivatives evaluated by the formula for the $n$th derivative of an analytic function).\nThese sorts of series are considered in greater detail in the text.\nThe built in function \\li{sympy.series} can evaluate the series expansion of a function at a singularity, for example\n\\begin{lstlisting}\nimport sympy as sy\nz = sy.Symbol('z')\n(1/sy.sin(z)).series(z,0,8)\n\\end{lstlisting}\n\nThe Laurent series representation provides a simple way to classify singularities in the complex plane.\nIsolated singular points can be classified as removable singular points, poles, or essential singular points.\nThese definitions will also be discussed in greater detail in the text.\nHere we will show another method for visualizing complex functions.\nIn Lab \\ref{Lab:complex_intro} we presented color plots as a useful method for visualizing functions in the complex plane. \nHere we will also show how to use surface plots to visualize the modulus of complex functions.\n\nNow you have to take care when a surface plot is about a singularity.  We must account for the fact that the function is not going to be defined at all of the points we use in our graph.\nWe will also have to limit the $z$ axis on the plot to avoid creating a plot that is dominated exclusively by the extremely large and extremely small values of the function.\nPlotting libraries like Mayavi and Matplotlib do allow thresholding of 3D plots via the use of floating point values of \\li{nan}, but doing this may result in graphs having jagged edges where they have been cut.\nWe can avoid the jagged edges by artificially adding a small lip of constant values to the plot as well.\nThis can be done with Matplotlib as follows:\n\\begin{lstlisting}\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D #needed to create 3d plots\n\nx_bounds, y_bounds = (-1.,1.), (-1.,1.)\nres = 400\n# Set the threshold at which to cut the 'z' values\nthreshold = 2.\n# space in 'z' values to use to create a lip on the plot\nlip = .5\nx = np.linspace(x_bounds[0], x_bounds[1], res)\ny = np.linspace(y_bounds[0], y_bounds[1], res)\nX, Y = np.meshgrid(x, y, copy=False)\nZ = 1 / (X + 1.0j * Y)\nZ = np.abs(Z)\n# Set the values between threshold and\n# threshold + lip to be equal to threshold.\n# This forms a somewhat more concrete\n# edge at the top of the plot.\nZ[(threshold+lip>Z)&(Z>threshold)] = threshold\n# Do the same thing for the negative restriction on 'z'.\nZ[(-threshold-lip<Z)&(Z<-threshold)] = -threshold\n# Set anything that is larger to np.nan so it doesn't get plotted.\nZ[np.absolute(Z) >= threshold + lip] = np.nan\n# Now actually plot the data.\nfig = plt.figure()\nax = fig.gca(projection='3d')\nsurf = ax.plot_surface(X, Y, Z, cmap=\"coolwarm\")\nplt.show()\n\\end{lstlisting}\nYou may notice that this still leaves some very jagged edges around the singularity.\nMuch more detailed code would be needed to obtain good surface plots around a singular point.\n\nFigures \\ref{fig:inv_surfaces} show surface plots of some relatively well-behaved singular points.\n\n\\begin{figure}\n\\begin{subfigure}{.5\\textwidth}\n\\includegraphics[width=\\textwidth]{absinvz.png}\n\\end{subfigure}\n\\begin{subfigure}{.5\\textwidth}\n\\includegraphics[width=\\textwidth]{absinvz2.png}\n\\end{subfigure}\n\\caption{Surface plots of the absolute value of $\\frac{1}{z}$ and $\\frac{1}{z^2}$ about the origin.}\n\\label{fig:inv_surfaces}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that takes in a function, x and y bounds, and a resolution and plots the modulus of the function as a 3d plot. Remember to take in account that it may be around a singularity.\n\\end{problem} \n\n\\begin{comment}\nColor plots, when used in their default form suffer from similar limitations.\nOn the other hand, we can do things like taking the absolute value, then scaling the values of a function logarithmically to mitigate some of the effect that the rapid growth of the plot values has on the colors in the plot.\nWe can also allow the color map used by the plotting library to repeat itself as the values of the function get larger and larger.\nThis can be done by taking the sine of the values.\nCombining these things together, we obtain expressions like $\\sin\\left(\\log\\left|\\text{Re}\\left(Z\\right)\\right|\\right)$.\n\n\\begin{warn}\nWhen generating color plots like this, you will have to check for floating point values of \\li{nan} and \\li{inf}.\nOne easy way to get rid of them is to set those values to zero.\n\\end{warn}\n\n\n\\begin{problem}\nWrite a function that produces color plots of $\\sin\\left(\\log\\left|f\\left(z\\right)\\right|\\right)$ for a given function $f$.\nHave it accept bounds for the interval where you want the plot generated.\nAlso have an argument that tells the function whether to use the real part, imaginary part, or the absolute value of the function.\n\\end{problem}\n\\end{comment}\n\n\\section*{Residues}\nThe number $a_{-1}$ in the Laurent expansion for a function $f$ at a point $z_0$ is called the Residue of $f$ at $z_0$.\nThe formula for the coefficients of the Laurent series provides one way to compute residues.\nIt is sometimes easier to evaluate a residue using limits or some other formula.\nOne good way to do this is to use the following formula:\n\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$.\nSuppose that $z_0$ is a pole of order $1$ of $f$.\nThen\n\\[\\Res{z=z_0} f(z) = \\frac{p(z_0)}{q'(z_0)}\\]\n\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$,\n\\[- \\Res{z=z_0} \\frac{f'(z)}{f(z)} = d\\]\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 since it allows us to avoid evaluating a long series of integrals we already know will evaluate to $0$.\n\nThere is also a natural relationship between the residues of a function at its poles and its partial fraction decomposition.\nLet $f = \\frac{p}{q}$ where $p$ and $q$ are polynomials, $q$ has no repeated roots, and the degree of $p$ has degree less than the degree of $q$.\nThis means that $f$ has a partial fraction representation\n\\[f = \\sum \\frac{c_i}{z - z_i}\\]\nwhere the $c_i$ are appropriately chosen coefficients and $z_i$ are the distinct zeros of $q$.\nConsider what happens when we take the residue of this sum.\nSince integrals distribute over sums, so do residues, so we may say\n\\[\\Res{z=z_i} f = \\sum \\Res{z=z_i} \\frac{c_i}{z - z_i}\\]\nSince the zeros of $q$ are distinct, and the function $\\frac{1}{z - z_i}$ is holomorphic wherever $z \\neq z_i$, we see that\n\\[\\Res{z=z_i} f = c_i \\Res{z=z_i} \\frac{1}{z-z_i} = c_i\\]\nThis means that we can use residues to compute partial fraction decompositions, so long as the function in the denominator does not have repeated roots.\n\n\\begin{problem}\nWrite a Python function that, given polynomial objects $p$ and $q$, computes the partial fraction decomposition of the function $\\frac{p}{q}$.\nAssume that the degree of $p$ is less than the degree of $q$ and that $q$ has no repeated roots.\nReturn two arrays.\nThe first should contain the coefficients in the partial fraction decomposition.\nThe second should contain the corresponding zeros of $q$.\n\nThe \\li{poly1d} object in NumPy makes it easy to work with polynomials:\n\\begin{lstlisting}\n>>> from numpy import poly1d\n# To represent the polynomial y = x^2 - 1, we pass in a list of its coefficients, highest power to lowest power.\n>>> my_polynomial = poly1d([1., 0., -1]) \n>>> my_polynomial.roots\narray([ 1., -1.]) #The roots are 1 and -1\n>>> my_polynomial.deriv()\npoly1d([ 2.,  0.]) #The derivative is the polynomial y = 2x\n\\end{lstlisting}\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$.\nThis limit may exist, even though the integral itself may not.\nThe methods for using residues to evaluate such integrals will be discussed in greater details in the text.\nHere we consider one example.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{contour1.pdf}\n\\caption{A contour used for integration using residues.}\n\\label{complexint:c1}\n\\end{figure}\n\nConsider the integral $\\int_{-\\infty}^{\\infty}\\frac{z^2}{z^4+1}$.\nLet $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_0$, $p_1$, $p_2$, and $p_3$.\nFor some real $R>1$, consider the contour $C$ from $-R$ to $R$ and counterclockwise along the circle centered at $0$ of radius $R$ back to -$R$.\n\nThis contour (a semi circle) is shown in Figure \\ref{complexint:c1} with $R = 2$.\nLet $A$ be this second portion of $C$.\nSince $R>1$, $p_0$ and $p_1$ lie inside the contour, and we have\n\\[\\int_C f(z)dz = 2\\pi i (\\Res{z=p_0} f(z) +\\Res{z=p_1} f(z))\\]\nSo, rewriting, we have\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\\]\nso\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\\]\nWe would like to show that $\\lim_{R\\to\\infty} \\int_A f(z) dz = 0$, so note that on $A$, $\\abs{z}=R$.\nWith some effort, it 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\\[\\int_{-\\infty}^{\\infty} f(z) dz = 2\\pi i (\\Res{z=p_0} f(z) +\\Res{z=p_1} f(z))\\]\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{comment}\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 we must now indent the path along the real axis 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.\nAn example of a contour like this is shown in Figure \\ref{complexint:c2}.\nIt is centered at the origin with $R=2$ on the outer circle and $R=\\frac{1}{2}$ on the inner circle.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{contour2.pdf}\n\\caption{An example of a contour that has been modified to avoid a singularity at the origin.}\n\\label{complexint:c2}\n\\end{figure}\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, \n\\end{comment}\nWe will not consider functions that have a singularity on the real line. So 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,\n\\[\\int_{-\\infty}^{\\infty} f(z) dz = 2\\pi i A\\]\nwhenever this integral exists.\nWhen we can say that the integral of $f$ over the upper half of a circle centered at $0$ goes to $0$ as the radius of the circle increases and we can also say that the Cauchy principal value of the integral of $f$ over $\\mathbb{R}$ exists, this formula will give us a proper numerical value for the Cauchy principal value of the integral of $f$ over $\\mathbb{R}$.\n\n\\begin{problem}\nWrite a function that computes the sum $2\\pi i A$ (where $A$ is defined as above) for a function $f$ of the form $\\frac{p}{q}$ where $p$ and $q$ are polynomials of the same form as in Problem 2.\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.\n\n\\begin{problem}\nIn the text, the zero and pole counting formula was stated and proved.\nAn immediate consequence of that theorem is that, for a meromorphic function $f$ and a positively oriented simple closed curve $\\gamma$ that does not pass through any roots of $f$,\n\\[\\int_\\gamma \\frac{f'\\left(z\\right)}{f\\left(z\\right)} dz = 2 \\pi i \\left(a - b\\right)\\]\nwhere $a$ is the number of zeros on the interior of $\\gamma$ (counting multiplicities) and $b$ is the number of poles of $f$ on the interior of $\\gamma$ (also counting multiplicities).\n\nThis formula gives another possible way to count the number of zeros of a polynomial on the interior of a given contour along with looking at the color plots and manually counting them as taught in the previous lab.\n\nWrite a Python function that counts the number of zeros of a polynomial on the interior of the unit circle then plots the color plot of the function on the unit square.\n\\end{problem}\n", "meta": {"hexsha": "8527658bf9e7593d405075b875daaf844199f7c4", "size": 14233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/Complex2-Integration/Complex2.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/Complex2-Integration/Complex2.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/Complex2-Integration/Complex2.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 61.6147186147, "max_line_length": 389, "alphanum_fraction": 0.7351928617, "num_tokens": 4083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695208, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6852934859540459}}
{"text": "% Created 2021-11-08 Mon 08:13\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{tcolorbox}\n\\usepackage{pgfplots}\n\\usepgfplotslibrary{groupplots}\n\\DeclareMathOperator{\\shift}{q}\n\\DeclareMathOperator{\\diff}{p}\n\\usetheme{default}\n\\author{Kjartan Halvorsen}\n\\date{\\today}\n\\title{Stability}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Stability},\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:orgd9a4d2f}\n\n\\begin{frame}[label={sec:orgfa2845f}]{Hard disk drive arm model}\n\\begin{center}\n\\includegraphics[width=0.4\\linewidth]{../../figures/diskdrive.png}\n\\end{center}\n\n{\\tiny \"Laptop-hard-drive-exposed\" by Evan-Amos - Own work. Licensed under CC BY-SA 3.0 via Commons } \n\\end{frame}\n\n\n\n\\begin{frame}[label={sec:orgf561952}]{Sampling the hard disk drive arm model}\n\\footnotesize\n\\[ H(z) = \\frac{z-1}{z} \\ztrf{\\mathcal{L}^{-1}\\{ \\frac{G(s)}{s} \\}} \\]\n\\begin{center}\n\\includegraphics[height=0.25\\textheight]{../../figures/diskdrive.png} \n\\begin{tikzpicture}[scale=0.7, node distance=2.2cm, block/.style={rectangle, draw, minimum height=12mm, minimum width=12mm}, sumnode/.style={circle, draw, inner sep=1pt}]\n\\footnotesize\n  \\node[coordinate] (input) {};\n  \\node[block, right of=input] (plant) {$\\frac{1}{Js^2}$};\n  \\node[coordinate, right of=plant] (output) {};\n  \\draw[->] (input) -- node[above] {$u$} (plant);\n  \\draw[->] (plant) -- node[above] {$y$} (output);\n\n  \\node at (-2, 1) {$J\\ddot{y} = u$};\n  \\end{tikzpicture}\n\\end{center}\n\n\\pause\n\nWhich of the below graphs show the sampled \\alert{step-response} of the system?\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.85]\n       \\footnotesize\n\n       \\begin{groupplot}[group style={group size=2 by 2, vertical sep=1.2cm, horizontal sep=1.2cm, vertical sep=4mm},\n       width=7cm,\n       height=2.6cm,\n       %xlabel={$t$},\n       ylabel={$y(kh)$},\n       xmin=-0.5,\n       xmax=8.5,\n       ytick = \\empty,\n       xtick = 0,\n       ]\n       \\nextgroupplot\n       \\addplot[red, thick, ycomb, mark=*,domain=0:8, samples=9]  {x};\n\n       \\nextgroupplot\n       \\addplot[red, thick, ycomb, mark=*, domain=0:8, samples=9]  {1};\n\n       \\nextgroupplot\n       \\addplot[red, thick, ycomb, mark=*, domain=0:8, samples=9]  {2*exp(-x/2)};\n\n       \\nextgroupplot\n       \\addplot[red, thick, ycomb, mark=*,domain=0:8, samples=9]  {pow(x,2)};\n       \n     \\end{groupplot}\n     \\node[blue!60] at (group c1r1.center) {\\huge 1};\n       \\node[blue!60] at (group c2r1.center) {\\huge 2};\n       \\node[blue!60] at (group c1r2.center) {\\huge 3};\n       \\node[blue!60] at (group c2r2.center) {\\huge 4};\n       \\end{tikzpicture}\n\n     \\end{center}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org848a1ab}]{Sampling the hard disk drive arm model}\n\\footnotesize\n\\[ H(z) = \\frac{z-1}{z} \\ztrf{\\mathcal{L}^{-1}\\{ \\frac{G(s)}{s} \\}} \\]\n\\begin{center}\n\\includegraphics[height=0.25\\textheight]{../../figures/diskdrive.png} \n\\begin{tikzpicture}[scale=0.7, node distance=2.2cm, block/.style={rectangle, draw, minimum height=12mm, minimum width=12mm}, sumnode/.style={circle, draw, inner sep=1pt}]\n\\footnotesize\n  \\node[coordinate] (input) {};\n  \\node[block, right of=input] (plant) {$\\frac{1}{Js^2}$};\n  \\node[coordinate, right of=plant] (output) {};\n  \\draw[->] (input) -- node[above] {$u$} (plant);\n  \\draw[->] (plant) -- node[above] {$y$} (output);\n\n  \\node at (-2, 1) {$J\\ddot{y} = u$};\n  \\end{tikzpicture}\n\\end{center}\n\nSampled step-response: \\(y(kh) = \\frac{1}{2J}(kh)^2\\)\n\\[ k^2 \\qquad \\overset{\\mathcal{Z}}{\\longleftrightarrow} \\qquad \\frac{z(z+1)}{(z-1)^3}\\]\n\n\\pause\n\nWhich of the below pulse-transfer functions corresponds to the discretized hard disk drive model?\n\\begin{center}\n\\begin{tabular}{rrr}\n1 & 2 & 3\\\\\n\\(H(z)=\\frac{h^2z}{2J(z+1)^2}\\) & \\(H(z)=\\frac{h^2(z+1)}{2Jz^2}\\) & \\(H(z)=\\frac{h^2(z+1)}{2J(z-1)^2}\\)\\\\\n\\end{tabular}\n\\end{center}\n\\end{frame}\n\n\\section{Block-diagram algebra}\n\\label{sec:org029e8b2}\n\\begin{frame}[label={sec:orgbb5598b}]{Block-diagram algebra}\n\\alert{Same rules as in the continuous-time case!}\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{node distance=2cm, \n    block/.style={rectangle, draw, minimum height=12mm, minimum width=14mm},\n    sumnode/.style={circle, draw, inner sep=2pt}        \n}\n\n  \\node[coordinate] (input) {};\n  \\node[block, right of=input] (TR) {$F_f(z)$};\n  \\node[sumnode, right of=TR, node distance=30mm] (sum) {\\tiny $\\sum$};\n  \\node[block,right of=sum, node distance=30mm] (plant) {$H(z)$};\n  %\\node[sumnode, right of=plant, node distance=30mm] (sumdist) {$\\sum$};\n  %\\node[coordinate, above of=sumdist, node distance=15mm] (dist) {};\n  %\\node[coordinate, right of=sumdist, node distance=15mm] (measure) {};\n  \\node[coordinate, right of=plant, node distance=30mm] (output) {};\n  \\node[coordinate, right of=plant, node distance=22mm] (measure) {};\n  %\\node[sumnode,below of=measure, node distance=25mm] (sumnoise) {$\\sum$};\n  %\\node[coordinate, right of=sumnoise, node distance=15mm] (noise) {};\n  \\node[block,below of=plant, node distance=20mm] (SR) {$F_b(z)$};\n  \\draw[->] (input) -- node[above, pos=0.2] {$y_{ref}(k)$} (TR);\n  \\draw[->] (TR) -- node[above] {$u_1(k)$} (sum);\n  \\draw[->] (sum) -- node[above] {$u(k)$} (plant);\n  \\draw[->] (plant) -- node[at end, above] {$y(k)$} (output);\n  \\draw[->] (measure) |- (SR);\n  \\draw[->] (SR) -| (sum) node[right, pos=0.8] {$u_2(k)$} node[left, pos=0.96] {$-$};\n\\end{tikzpicture}\n\\end{center}\nWith \\[U(z) = U_1(z) - U_2(z) = F_f(z)Y_{ref}(z) - F_b(z)Y(z), \\quad \\text{and}\\]\n\\[ Y(z) = H(z)U(z), \\quad \\text{we obtain} \\]\n\\[ Y(z) = \\underbrace{\\frac{F_f(z)H(z)}{1 + F_b(z)H(z)}}_{H_c{z}} Y_{ref}(z). \\]\n\\end{frame}\n\n\\begin{frame}[label={sec:org4ace140}]{Block-diagram algebra - steps in detail}\nWith \\[U(z) = U_1(z) - U_2(z) = F_f(z)Y_{ref}(z) - F_b(z)Y(z), \\quad \\text{and}\\]\n\\[ Y(z) = H(z)U(z), \\quad \\text{we obtain} \\]\n\\[ Y(z) = H(z)U(z) = H(z)\\left(F_f(z)Y_{ref}(z) - F_b(z)Y(z)\\right)\\]\nMove all terms with \\(Y\\) to the left side:\n\\[ Y(z) + H(z)F_b(z)Y(z) = H(z)F_f(z)Y_{ref}(z)\\]\n\\[ Y(z)\\big(1 + H(z)F_b(z)\\big) = H(z)F_f(z)Y_{ref}(z)\\]\n\\[ Y(z) = \\frac{H(z)F_f(z)}{1 + H(z)F_b(z)}Y_{ref}(z)\\]\n\\end{frame}\n\n\\begin{frame}[label={sec:org7f81524}]{Stability for the closed-loop system}\n\\[ Y(z) = \\frac{F_f(z)H(z)}{1 + F_b(z)H(z)} Y_{ref}(z). \\]\n\n\\begin{tcolorbox}\nStability requires that all poles of the system, i.e. all solutions to the characteristic equation\n\\[ 1 + F_b(z)H(z) = 0\\]\nare located inside the unit circle of the  z-plane.\n\\end{tcolorbox}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgd4efd26}]{Stability for the disk drive arm}\n\\small \nCase \\(\\frac{h^2}{J} = 1\\). Suggested controller:\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{node distance=2cm, \n    block/.style={rectangle, draw, minimum height=12mm, minimum width=14mm},\n    sumnode/.style={circle, draw, inner sep=2pt}        \n}\n\n  \\node[coordinate] (input) {};\n  \\node[block, right of=input] (TR) {$F_f(z) = 0.2K$};\n  \\node[sumnode, right of=TR, node distance=30mm] (sum) {\\tiny $\\sum$};\n  \\node[block,right of=sum, node distance=30mm] (plant) {$H(z) = \\frac{z+1}{2(z-1)^2}$};\n  %\\node[sumnode, right of=plant, node distance=30mm] (sumdist) {$\\sum$};\n  %\\node[coordinate, above of=sumdist, node distance=15mm] (dist) {};\n  %\\node[coordinate, right of=sumdist, node distance=15mm] (measure) {};\n  \\node[coordinate, right of=plant, node distance=30mm] (output) {};\n  \\node[coordinate, right of=plant, node distance=22mm] (measure) {};\n  %\\node[sumnode,below of=measure, node distance=25mm] (sumnoise) {$\\sum$};\n  %\\node[coordinate, right of=sumnoise, node distance=15mm] (noise) {};\n  \\node[block,below of=plant, node distance=20mm] (SR) {$F_b(z)=K\\frac{z-0.8}{z}$};\n  \\draw[->] (input) -- node[above, pos=0.2] {$y_{ref}(k)$} (TR);\n  \\draw[->] (TR) -- node[above] {$u_1(k)$} (sum);\n  \\draw[->] (sum) -- node[above] {$u(k)$} (plant);\n  \\draw[->] (plant) -- node[at end, above] {$y(k)$} (output);\n  \\draw[->] (measure) |- (SR);\n  \\draw[->] (SR) -| (sum) node[right, pos=0.8] {$u_2(k)$} node[left, pos=0.96] {$-$};\n\\end{tikzpicture}\n\\end{center}\n\n\\alert{Characteristic equation}\n\\begin{align*}\n1 + H(z)F_b(z) &= 0\\\\\n1 + \\frac{z+1}{2(z-1)^2}K\\frac{z-0.8}{z} &= 0\\\\\n(z-1)^2z + \\frac{K}{2}(z+1)(z-0.8) &= 0\n\\end{align*}\n\n\\pause\n\n\\alert{Is the system stable for all gains \\(K\\)?}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org5deaacc}]{Stability for the disk drive arm}\n\\alert{Pair activity} Complete the root-locus below\n   \\[(z-1)^2z + \\frac{K}{2}(z+1)(z-0.8) = 0\\]\n\\begin{center}\n  \\begin{tikzpicture}[scale=2.5]\n    \\draw[->] (-1.2, 0) -- (1.2,0);\n    \\draw[->] (0, -1.2) -- (0,1.2);\n    \\node[red, pin=45:{2 plant poles}] at (1,0) {\\large $\\times$};\n    \\node[red, pin=135:{controller pole}] at (0,0) {\\large $\\times$};\n    \\node[green!70!black, pin=-145:{controller zero}] at (0.8,0) {\\Large $\\circ$};\n    \\node[green!70!black, pin=-145:{plant cero}] at (-1,0) {\\Large $\\circ$};\n    \\node at (0.8, -0.2) {$0.8$};\n    \\node at (1, -0.2) {$1$};\n    \\draw[domain=0:360, samples=361, dashed] plot ({cos(\\x)}, {sin(\\x)});\n    \\node[coordinate, pin=60:{$|z|=1$}] at (0.5, 0.87) {};\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\n\\section{Estabilidad para el control del brazo del disko duro}\n\\label{sec:orgb4848e4}\n\\end{document}", "meta": {"hexsha": "51b5215beb6e4e1c637b71af73e1dd954ccb5cd7", "size": 9613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "discrete-time-systems/slides/stability.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-time-systems/slides/stability.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-time-systems/slides/stability.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": 36.4128787879, "max_line_length": 170, "alphanum_fraction": 0.6278997191, "num_tokens": 3688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117812622842, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.685293482278473}}
{"text": "\\chapter{Derivation of twist averaging efficiency}\n\\label{sec:app_ta_efficiency}\nIn this appendix we derive the relative statistical efficiency of \ntwist averaging with an irreducible (weighted) set of k-points \nversus using uniform weights over an unreduced set of k-points \n(e.g., a full Monkhorst-Pack mesh).\n\nConsider the weighted average of a set of statistical variables \n$\\{x_m\\}$ with weights $\\{w_m\\}$:\n\\begin{align}\n  x_{TA} = \\frac{\\sum_mw_mx_m}{\\sum_mw_m}\\:.\n\\end{align} \nIf produced by a finite QMC run at a set of \ntwist angles/k-points $\\{k_m\\}$, each variable mean $\\mean{x_m}$ \nhas a statistical error bar $\\sigma_m$, and we can also obtain \nthe statistical error bar of the mean of the twist-averaged \nquantity $\\mean{x_{TA}}$:\n\\begin{align}\n  \\sigma_{TA} = \\frac{\\left(\\sum_mw_m^2\\sigma_m^2\\right)^{1/2}}{\\sum_mw_m}\\:.\n\\end{align}\nThe error bar of each individual twist $\\sigma_m$ is related to the \nautocorrelation time $\\kappa_m$,  intrinsic variance $v_m$, and the number \nof postequilibration MC steps $N_{step}$ in the following way:\n\\begin{align}\n  \\sigma_m^2=\\frac{\\kappa_mv_m}{N_{step}}\\:.\n\\end{align}\nIn the setting of twist averaging, the autocorrelation time and \nvariance for different twist angles are often very similar across \ntwists, and we have\n\\begin{align}\n  \\sigma_m^2=\\sigma^2=\\frac{\\kappa v}{N_{step}}\\:.\n\\end{align} \nIf we define the total weight as $W$, that is, $W\\equiv\\sum_{m=1}^Mw_m$, \nfor the weighted case with $M$ irreducible twists, the error bar is\n\\begin{align}\n  \\sigma_{TA}^{weighted}=\\frac{\\left(\\sum_{m=1}^Mw_m^2\\right)^{1/2}}{W}\\sigma\\:.\n\\end{align}\nFor uniform weighting with $w_m=1$, the number of twists is $W$ and \nwe have\n\\begin{align}\n  \\sigma_{TA}^{uniform}=\\frac{1}{\\sqrt{W}}\\sigma\\:.\n\\end{align}\nWe are interested in comparing the efficiency of choosing weights \nuniformly or based on the irreducible multiplicity of each twist angle \nfor a given target error bar $\\sigma_{target}$.  The number of MC  \nsteps required to reach this target for uniform weighting is\n\\begin{align}\n  N_{step}^{uniform} = \\frac{1}{W}\\frac{\\kappa v}{\\sigma_{target}^2}\\:,\n\\end{align}\nwhile for nonuniform weighting we have\n\\begin{align}\\label{eq:weighted_step}\n  N_{step}^{weighted} &= \\frac{\\sum_{m=1}^Mw_m^2}{W^2}\\frac{\\kappa v}{\\sigma_{target}^2} \\nonumber\\:,\\\\\n                  &=\\frac{\\sum_{m=1}^Mw_m^2}{W}N_{step}^{uniform}\\:.\n\\end{align}\nThe MC efficiency is defined as \n\\begin{align}\n  \\xi = \\frac{1}{\\sigma^2t}\\:,\n\\end{align}\nwhere $\\sigma$ is the error bar and $t$ is the total CPU time required \nfor the MC run.  \n\nThe main advantage made possible by irreducible twist weighting is to \nreduce the equilibration time overhead by having fewer twists and, \nhence, fewer MC runs to equilibrate.  In the context of twist \naveraging, the total CPU time for a run can be considered to be\n\\begin{align}\n  t=N_{twist}(N_{eq}+N_{step})t_{step}\\:,\n\\end{align}\nwhere $N_{twist}$ is the number of twists, $N_{eq}$ is the number of MC steps required to reach equilibrium, $N_{step}$ is the number \nof MC steps included in the statistical averaging as before, \nand $t_{step}$ is the wall clock time required to complete a single \nMC step. For uniform weighting $N_{twist}=W$; while for irreducible \nweighting $N_{twist}=M$.\n\nWe can now calculate the relative efficiency ($\\eta$) of irreducible vs. \nuniform twist weighting with the aim of obtaining a target error bar \n$\\sigma_{target}$:\n\\begin{align}\n  \\eta &= \\frac{\\xi_{TA}^{weighted}}{\\xi_{TA}^{uniform}} \\nonumber\\:, \\\\\n       &= \\frac{\\sigma_{target}^2t_{TA}^{uniform}}{\\sigma_{target}^2t_{TA}^{weighted}} \\nonumber\\:, \\\\\n       &= \\frac{W(N_{eq}+N_{step}^{uniform})}{M(N_{eq}+N_{step}^{weighted})} \\nonumber\\:, \\\\\n       &= \\frac{W(N_{eq}+N_{step}^{uniform})}{M(N_{eq}+\\frac{\\sum_{m=1}^Mw_m^2}{W}N_{step}^{uniform})} \\nonumber\\:, \\\\\n       &= \\frac{W}{M}\\frac{1+f}{1+\\frac{\\sum_{m=1}^Mw_m^2}{W}f}\\:.\n\\end{align}\nIn this last expression, $f$ is the ratio of the number of usable \nMC steps to the number that must be discarded during equilibration \n($f=N_{step}^{uniform}/N_{eq}$); and as before, $W=\\sum_mw_m$, which is the number of \ntwist angles in the uniform weighting case.  It is important to recall \nthat $N_{step}^{uniform}$ in $f$ is defined relative to uniform weighting and is \nthe number of MC steps required to reach a target accuracy in the \ncase of uniform twist weights.\n\nThe formula for $\\eta$ in the preceding can be easily changed with the help of \nEquation~\\ref{eq:weighted_step} to reflect the \nnumber of MC steps obtained in an irreducibly weighted run \ninstead.  A good exercise is to consider runs that have already completed \nwith either uniform or irreducible weighting and calculate the \nexpected efficiency change had the opposite type of weighting been used.\n\nThe break even point $(\\eta=1)$ can be found at a usable step fraction of \n\\begin{align}\n  f=\\frac{W-M}{M\\frac{\\sum_{m=1}^Mw_m^2}{W}-W}\\:.\n\\end{align}\n\nThe relative efficiency $(\\eta)$ is useful to consider in view of certain \nscenarios.  An important case is where the number of required sampling \nsteps is no larger than the number of equilibration steps (i.e., \n$f\\approx 1$).  For a very simple case with eight uniform twists with \nirreducible multiplicities of $w_m\\in\\{1,3,3,1\\}$ ($W=8$, $M=4$), the \nrelative efficiency of irreducible vs. uniform weighting is \n$\\eta=\\frac{8}{4}\\frac{2}{1+20/8}\\approx 1.14$.  In this case, \nirreducible weighting is about $14$\\% more efficient than uniform weighting.\n\nAnother interesting case is one in which the number of sampling steps you can \nreach with uniform twists before wall clock time runs out is small \nrelative to the number of equilibration steps ($f\\rightarrow 0$). \nIn this limit, $\\eta\\approx W/M$.  For our eight-uniform-twist example, this would \nresult in a relative efficiency of $\\eta=8/4=2$, making irreducible \nweighting twice as efficient.\n\nA final case of interest is one in which the equilibration time is short \nrelative to the available sampling time $(f\\rightarrow\\infty)$, \ngiving $\\eta\\approx W^2/(M\\sum_{m=1}^Mw_m^2)$.  Again, for our simple example \nwe find $\\eta=8^2/(4\\times 20)\\approx 0.8$, with uniform weighting being \n$25$\\% more efficient than irreducible weighting. For this example, the crossover point for irreducible weighting being \nmore efficient than uniform weighting is $f<2$, that is, when the \navailable sampling period is less than twice the length of the equilibration \nperiod.  The expected efficiency ratio and crossover point should be checked \nfor the particular case under consideration to inform the choice between   \ntwist averaging methods.\n\n\n\n", "meta": {"hexsha": "33687da435438fc86fa6941f5f3f66ae7d2578da", "size": 6635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "legacy_manual/appendices.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/appendices.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/appendices.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.5149253731, "max_line_length": 134, "alphanum_fraction": 0.7250941974, "num_tokens": 1953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695208, "lm_q2_score": 0.826711787666479, "lm_q1q2_score": 0.6852934771062372}}
{"text": "\n\\subsection{Completeness of zero-order logic}\n\nA theory is complete if all true formulae are included.\n\nNote that there are three types of formulae in a theory.\n\n\\begin{itemize}\n\\item Tautologies (always true)\n\\item Refutable formulae (always false)\n\\item Satisfiable formulae which are not tautologies (true in some, but not all, interpretations).\n\\end{itemize}\n\n", "meta": {"hexsha": "3249489b73839c1bfe53a196ab285e0a71067fd2", "size": 365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/01-05-zeroCompleteness.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/preteriteLogic/01-05-zeroCompleteness.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/preteriteLogic/01-05-zeroCompleteness.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.0714285714, "max_line_length": 98, "alphanum_fraction": 0.7835616438, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6852731783195742}}
{"text": "\n\\title{One-Bit Maximal Matching on a Ring}\n%\\author{}\n\\date{}\n\n\\begin{document}\n\n\\href{http://en.wikipedia.org/wiki/Matching_(graph_theory)}{Matching} is well-known problem from graph theory.\nA matching is a set of edges that do not share any common vertices.\nFor a matching to be \\textit{maximal}, it must be impossible to add another edge to the set without breaking the matching property.\n\n\\tableofcontents\n\n\\section{1-Bit Maximal Matching on a Ring}\n\\label{sec:MatchRing}\n\n\\quicksec{MatchRing}\n(\\href{\\examplespec/MatchRing.prot}{spec},\n\\href{\\examplesett/MatchRing.args}{args},\n\\href{\\examplesynt/MatchRing.prot}{synt}\n\\href{\\examplesoln/MatchRingOneBit.prot}{soln})\n\nIn the specification, the $e$ variables denote whether an edge is in the matching.\nThe invariant specified as a maximal matching, which can be restated as the following two conditions for the special case of a ring:\n\\begin{enumerate}\n\\item No two adjacent edges can be selected.\n\\item At least one of every three consecutive edges must be selected.\n\\end{enumerate}\n\n\\quicksec{Synthesis}\nProcesses cannot realistically write to edge variables, therefore the $e$ variables are marked as \\ilcode{shadow} and their values must be derived from $x$ values owned by processes.\nFor an instructive look at how this works see \\href{#sec:MatchRingOneBit}{the next section}, which derives the same protocol from a slightly different way of specifying the maximal matching property.\n\n\\quicksec{Stabilization Proof}\nIt is fairly easy to show that the 1-bit matching protocol is stabilizing.\nFirst we will show that all executions terminate.\nThen we will show that all silent states belong to the invariant.\nFrom the \\href{\\examplesoln/MatchRingOneBit.prot}{protocol}, we see that each $P[i]$ has the following actions:\n\\begin{code}\n(              x[i]==1 && x[i+1]==1 --> x[i]:=0; )\n( x[i-1]==0 && x[i]==0 && x[i+1]==0 --> x[i]:=1; )\n\\end{code}\n\nWe can analyze the actions to see that the protocol is livelock-free.\nThe first action of $P[i]$ removes cases of $2$ consecutive $1$ values by changing the left value to $0$.\nThis may enable the second action of $P[i-1]$.\nThe second action of $P[i]$ removes cases of $3$ consecutive $0$ values by changing the middle value to $1$.\nIf $P[i]$ executes its section action neither it or its neighbors is enabled!\nTherefore, actions may propagate by changing consecutive $1$s to $0$s, and some of the resulting $0$s may toggle back to $1$s, but the $1$s will not be consecutive.\n\nClearly the silent states are those where no $2$ consecutive $1$s exist and no $3$ consecutive $0$s exist.\nThat means a $1$ must occur at least every $3$ values and will be followed by a $0$.\nWe can therefore interpret a $1$ value followed by a $0$ value to mean that the edge between the two values is selected.\nThese edges are not consecutive and at least on of every $3$ will be selected, therefore it is a maximal matching.\n\\begin{code}\nforall i <- Nat % N :\n   x[i-1]==1 && x[i]==0               // P[i] matched with P[i-1]\n|| x[i-1]==0 && x[i]==0 && x[i+1]==1  // P[i] is not matched\n||              x[i]==1 && x[i+1]==0  // P[i] matched with P[i+1]\n\\end{code}\n\n\\section{3-State Maximal Matching on a Ring}\n\\label{sec:MatchRingThreeState}\n\n\\quicksec{MatchRingThreeState}\n(\\href{\\examplespec/MatchRingThreeState.prot}{spec},\n\\href{\\examplesett/MatchRingThreeState.args}{args},\n\\href{\\examplesoln/MatchRingThreeState.prot}{soln})\n\nMatching can also be reasoned about in terms of processes.\nAllow each process $P[i]$ in a ring to point to $P[i-1]$, itself, or $P[i+1]$.\nLet these directions be denoted by having $P[i]$'s variable $m[i]$ have a value of $L$, $S$, and $R$ respectively.\nThe processes form a maximal matching when they point to each other or themselves, but no two neighboring processes can both point to themselves.\n\\begin{code}\nforall i <- Nat % N :\n   m[i-1]==R && m[i]==L               // P[i] pointing to P[i-1] and P[i-1] pointing back\n|| m[i-1]==L && m[i]==S && m[i+1]==R  // P[i] pointing to itself and neighbors pointing away\n||              m[i]==R && m[i+1]==L  // P[i] pointing to P[i+1] and P[i+1] pointing back\n\\end{code}\n\nOne stabilizing protocol has the actions:\n\\begin{code}\n( m[i-1]==2 && m[i]!=0 && m[i+1]!=0 --> m[i]:=0; )\n( m[i-1]!=2 && m[i]!=1 && m[i+1]==2 --> m[i]:=1; )\n( m[i-1]!=2 && m[i]!=2 && m[i+1]!=2 --> m[i]:=2; )\n\\end{code}\n\n\\subsection{Deriving 1-Bit Protocol from 3-State Protocol}\n\\label{sec:MatchRingOneBit}\n\n\\quicksec{MatchRingOneBit}\n(\\href{\\examplespec/MatchRingOneBit.prot}{spec},\n\\href{\\examplesynt/MatchRingOneBit.prot}{synt},\n\\href{\\examplesoln/MatchRingOneBit.prot}{soln})\n\nThis section explains shadow/puppet synthesis as a special case of superposition.\nIn the \\href{#sec:MatchRing}{previous section}, we saw that a protocol could achieve a matching using only 1 bit per process.\nHow could this be derived?\nFrom the above 3-state protocol, it seems that each process needs to be able to point in $3$ directions.\n\nGive each process $P[i]$ a binary $x[i]$ variable to perform the protocol along with a ternary $m[i]$ variable used to specify the invariant.\nFurthermore, $P[i]$ is given read access to $x[i-1]$ and $x[i+1]$, but it cannot read $m[i-1]$ or $m[i+1]$.\n\nWe use the previous section's invariant on the underlying $m$ variables.\nSince processes only know their own $m$ values, the protocol is forced to use $x$ values to negotiate appropriate $m$ values.\nOur invariant style (the \\ilcode{((future & silent) % puppet)} style) allows closure to be violated for some (but not all) valuations of $x$ variables.\n\\codeinputlisting{../../../examplespec/MatchRingOneBit.prot}\n\nFrom synthesis, \\href{\\examplesynt/MatchRingOneBit.prot}{one of the protocols} we get is the following.\n\\begin{code}\n( x[i-1]==1 && x[i]==1 && x[i+1]==1 --> x[i]:=0; m[i]:=L; )\n( x[i-1]==0 && x[i]==1 && x[i+1]==1 --> x[i]:=0; m[i]:=S; )\n( x[i-1]==0 && x[i]==0 && x[i+1]==0 --> x[i]:=1; m[i]:=R; )\n\n( x[i-1]==1 && x[i]==0              && m[i]!=L --> m[i]:=L; )\n( x[i-1]==0 && x[i]==0 && x[i+1]==1 && m[i]!=S --> m[i]:=S; )\n( x[i-1]==0 && x[i]==1 && x[i+1]==0 && m[i]!=R --> m[i]:=R; )\n\\end{code}\n\nFrom here, we can create the 1-bit matching protocol on the $x[i]$ variables without the $m[i]$s.\nThe first three actions of the synthesized protocol change $x[i]$ and are therefore used as actions in our 1-bit matching protocol, discarding changes to $m[i]$.\n\\begin{code}\n( x[i-1]==1 && x[i]==1 && x[i+1]==1 --> x[i]:=0; )\n( x[i-1]==0 && x[i]==1 && x[i+1]==1 --> x[i]:=0; )\n( x[i-1]==0 && x[i]==0 && x[i+1]==0 --> x[i]:=1; )\n\\end{code}\n\nThe invariant is all states where the $x[i]$ values don't change (see the last three actions above).\n\\begin{code}\nforall i <- Nat % N :\n   x[i-1]==1 && x[i]==0               // P[i] pointing to P[i-1] and P[i-1] pointing back\n|| x[i-1]==0 && x[i]==0 && x[i+1]==1  // P[i] pointing to itself and neighbors pointing away\n|| x[i-1]==0 && x[i]==1 && x[i+1]==0  // P[i] pointing to P[i+1] and P[i+1] pointing back\n\\end{code}\nEach of these cases in the disjunction corresponds to $P[i]$ pointing to $P[i-1]$, itself, and $P[i+1]$ respectively.\nWe know this by looking at how $m[i]$ is changed to be \\ilcode{m[i]:=L}, \\ilcode{m[i]:=S}, and \\ilcode{m[i]:=R} in the synthesized protocol.\n\nNote that the third case in the disjunction can be simplified from \\ilcode{x[i-1]==0 && x[i]==1 && x[i+1]==0} to \\ilcode{x[i]==1 && x[i+1]==0} since if the formula holds for $P[i]$ and the system is in the invariant, then the first or second cases in the disjunction must hold for $P[i-1]$ (hence, $x[i-1]=0$).\n\nPutting this all together, we get:\n\\codeinputlisting{../../../examplesoln/MatchRingOneBit.prot}\n\n\\subsection{Using Shadow/Puppet Variables}\n\nShadow variables are variables that cannot be used in the guard of any actions.\nTherefore, to reliably obtain a protocol that is free of $m$ variables, we must mark them as shadow variables by replacing \\ilcode{direct} with \\ilcode{shadow} in the \\href{\\examplespec/MatchRingOneBit.prot}{specification}.\nThis is essentially what is done in the \\href{#sec:MatchRing}{previous section}, but a more convenient invariant is used.\n\n\\section{Segmented Ring}\n\\label{sec:SegmentRing}\n\n\\quicksec{SegmentRing}\n(\\href{\\examplespec/SegmentRing.prot}{spec},\n\\href{\\examplesett/SegmentRing.args}{args},\n\\href{\\examplesynt/SegmentRing.prot}{synt})\n\nThis is a problem similar to matching where a ring is segmented into chains.\n\n\\end{document}\n\n", "meta": {"hexsha": "d9d704d9aeb92c8bdf0c6e50f8cb3f4503efe17f", "size": 8417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/webtex/example/Matching.tex", "max_stars_repo_name": "tjmareng/protocon", "max_stars_repo_head_hexsha": "385311c72e3a9a2f5f7e04a49bc601ec7dd2bce1", "max_stars_repo_licenses": ["ISC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-28T19:56:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-28T19:56:38.000Z", "max_issues_repo_path": "doc/webtex/example/Matching.tex", "max_issues_repo_name": "tjmareng/protocon", "max_issues_repo_head_hexsha": "385311c72e3a9a2f5f7e04a49bc601ec7dd2bce1", "max_issues_repo_licenses": ["ISC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/webtex/example/Matching.tex", "max_forks_repo_name": "tjmareng/protocon", "max_forks_repo_head_hexsha": "385311c72e3a9a2f5f7e04a49bc601ec7dd2bce1", "max_forks_repo_licenses": ["ISC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.2795031056, "max_line_length": 310, "alphanum_fraction": 0.6851609837, "num_tokens": 2457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6852731661083327}}
{"text": "\\documentclass[]{book}\n\\usepackage{graphicx}\n\\usepackage{amsmath,amssymb,amsthm}\n\n%opening\n\\title{Probability and Statistics}\n\\author{}\n\n\\newcommand{\\distas}[1]{\\mathbin{\\overset{#1}{\\kern\\z@\\sim}}}%\n\\newsavebox{\\mybox}\\newsavebox{\\mysim}\n\\newcommand{\\distras}[1]{%\n\t\\savebox{\\mybox}{\\hbox{\\kern3pt$\\scriptstyle#1$\\kern3pt}}%\n\t\\savebox{\\mysim}{\\hbox{$\\sim$}}%\n\t\\mathbin{\\overset{#1}{\\kern\\z@\\resizebox{\\wd\\mybox}{\\ht\\mysim}{$\\sim$}}}%\n}\n\n\n\\begin{document}\n\t\n\\maketitle\n\t\n\\setcounter{tocdepth}{1}\n\\tableofcontents\n\\newpage\n\n\\chapter{Discrite Distributions}\n\n\\section{Generic Formulas}\n\n\\subsection{Expected Value}\nX is discrete random variable\\\\\n$g : \\mathbf{R} \\rightarrow \\mathbf{R}$\\\\\n$\\Omega X = Im(X)$\\\\\n\n\\begin{align}\n\tE[g(X)] &= \\sum_{x \\in \\Omega X} {P(X=x)*g(x)}\n\\end{align}\n\n\\subsection{Variance}\n\n\\begin{align}\n\tvar(g(X)) &= E([g(X) - E(g(X))]^2)\\\\\n\t&= \\sum_{x\\in \\Omega X} {[g(X) - E(g(X))]^2*P(X=x)]}\\\\\n\t&= \\sum_{x\\in \\Omega X} {[g(X)^2 - 2*g(X)*E(g(X)) + E(g(X))^2]*P(X=x)}\\\\\n\t&= \\sum_{x\\in \\Omega X} {g(X)^2*P(X=x)} \\\\&- \\sum_{x\\in \\Omega X} {2*g(X)*E(g(X))*P(X=x)} \\\\&+ \\sum_{x \\in \\Omega X} {E(g(X))^2*P(X=x)}\\\\\n\t&= \\sum_{x\\in \\Omega X} {g(X)^2*P(X=x)} \\\\&- 2*E(g(X))*\\sum_{x\\in \\Omega X} {g(X)*P(X=x)} \\\\&+ E(g(X))^2*\\sum_{x \\in \\Omega X} {P(X=x)}\\\\\n\t&= E(g(X)^2) - 2*E(g(X))*E(g(X)) + E(g(X))^2*1\\\\\n\t&= E(g(X)^2) - 2*E(g(X))^2 + E(g(X))^2\\\\\n\t&= E(g(X)^2) - E(g(X))^2\\\\\n\t\\qed\n\\end{align}\n\n\\subsection{Covariance Matrix}\n\n\\begin{align}\ncov(X) &= E[(X-E(X)]^2\\\\\n&= \\sum_{x\\in \\Omega X} {(X-E(X))^2*P(X=x)}\\\\\n&= \\sum_{x\\in \\Omega X} {[X^2-2XE(X)+E(X)^2]*P(X=x)}\\\\\n&= \\sum_{x\\in \\Omega X} {X^2P(X=x)} \\\\&- \\sum_{x\\in \\Omega X} {2XE(X)*P(X=x)} \\\\&+ \\sum_{x \\in \\Omega X} {E(X)^2P(X=x)}\\\\\n&= \\sum_{x\\in \\Omega X} {X^2P(X=x)} \\\\&- 2E(X)*\\sum_{x\\in \\Omega X} {XP(X=x)} \\\\&+ E(X)^2*\\sum_{x \\in \\Omega X} {P(X=x)}\\\\\n&= E(X^2)-2E(X)E(X)+E(X)^2*1\\\\\n&= E(X^2)-2*E(X)^2+E(X)^2\\\\\n&= E(X^2)-E(X)^2\\\\\n&= E(X^tX)-\\mu^t\\mu\\\\\n\\qed\n\\end{align}\n\n\\subsection{Variance of the Sample Mean}\n\n\\begin{align}\nVar\\left({\\overline{X}}\\right)&=Var\\left( \\frac{1}{n}\\sum_{i=1}^nX_i\\right)\\\\&= \\frac{1}{n^2}Var\\left( \\sum_{i=1}^nX_i\\right)\\\\&=\\frac{1}{n^2}\\sum_{i=1}^nVar(X_i), \\text{ by independence}\\\\&= \\frac{1}{n^2}\\left[Var(X_1)+Var(X_2)+\\ldots+Var(X_n) \\right]\\\\&=\\frac{1}{n^2}\\left[\\sigma^2+\\sigma^2+\\ldots+\\sigma^2  \\right], \\text{ since the }X_i \\text{ are identically distributed }\\\\&= \\frac{1}{n^2}(n\\sigma^2)\\\\&=\\frac{\\sigma^2}{n}\n\\end{align}\n\n\\subsection {Law of Iterated Expectation}\n\\begin{align}\n\tE[X] = E[ E[X|Y] ]\n\\end{align}\n\n\\subsection {Law of Total Variance}\n\\begin{align}\nvar(X) = E[ var(X|Y) ] + var( E[X|Y] )\n\\end{align}\n\n\\subsection{MSE}\n\n\\begin{align}\n\t\\hat{\\theta} &= \\hat{\\theta}(X) \\text{ Random Variable}\\\\\n\tE[\\hat{\\theta}] &= \\text{constant}\\\\\n\t\\theta &= \\text{true value, constant}\\\\\n\t\\\\\n\tMSE(\\hat{\\theta}) &= E[(\\hat{\\theta} - \\theta)^2]\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}] + E[\\hat{\\theta}]) - \\theta)^2]\\\\\n\t&= E[([\\hat{\\theta} - E[\\hat{\\theta}]] + [E[\\hat{\\theta}] - \\theta])^2]\\\\\n\t&= E[(A + B)^2]\\\\\n\t\\\\\n\t& A = \\hat{\\theta} - E[\\hat{\\theta}]\\\\\n\t& B = E[\\hat{\\theta}] - \\theta\\\\\n\t\\\\\n\t&= E[A^2 + 2AB + B^2]\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2 + 2(\\hat{\\theta} - E[\\hat{\\theta}])(E[\\hat{\\theta}] - \\theta) + (E[\\hat{\\theta}] - \\theta)^2]\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + E[2(\\hat{\\theta} - E[\\hat{\\theta}])(E[\\hat{\\theta}] - \\theta)] + E[(E[\\hat{\\theta}] - \\theta)^2]\\\\\n\t\\\\\t\n\t& C = E[\\hat{\\theta}]  - \\theta \\text{ is a constant}\\\\\n\t\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + E[2(\\hat{\\theta} - E[\\hat{\\theta}])(C)] + E[C^2]\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + 2CE[\\hat{\\theta} - E[\\hat{\\theta}]] + C^2\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + 2C(E[\\hat{\\theta}] - E[E[\\hat{\\theta}]]) + C^2\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + 2C(E[\\hat{\\theta}] - E[\\hat{\\theta}]) + C^2\\\\\t\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + 2C(0) + C^2\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + C^2\\\\\n\t&= E[(\\hat{\\theta} - E[\\hat{\\theta}])^2] + (E[\\hat{\\theta}]  - \\theta)^2\\\\\t\n\t\\\\\n\t& var(\\hat{\\theta}) = E[(\\hat{\\theta} - E[\\hat{\\theta}])^2]\\\\\n\t& bias(\\hat{\\theta}, \\theta) = E[\\hat{\\theta}]  - \\theta\\\\\n\t\\\\\n\t&= var(\\hat{\\theta}) + (bias(\\hat{\\theta}, \\theta))^2\\\\\t\n\\end{align}\n\n\\section {Uniform Random Variable}\n\n\\section {Bernoulli Distribution}\n\nThe Bernoulli Distribution is a special case of the Binomial Distribution, where $$n=1$$.\n\n\\subsection{PMF}\n\\begin{align}\nP(X=k) &= \\binom{1} {k} p^k (1-p)^{1-k}\\\\\n&=p^k (1-p)^{n-k}\n\\end{align}\n\n\\subsection {Expected Value}\n\\begin{align}\nE(x) &= \\sum_{k \\geqslant 1} [\\binom{n}{k} p^k (1-p)^{n-k}] * k\\\\\n&= np && \\text{see Binomial Distribution E[X]}\\\\\n&= 1*p\\\\\n&= p\n\\end{align}\n\n\\subsection {Variance}\n\\begin{align}\nVar(X) &= np*(1-p)\\\\\n&= p*(1-p)\\\\\n\\end{align}\n\n\\subsection {Likelihood of IID Bernoulli}\n\n\\begin{align}\nx_i \\overset{iid}{\\sim} Bernoulli(p)\\\\\nL(x_i|p)&=p(x_1,x_2,...,x_n|p)\\\\&=\\prod_{n=1}^np(x_i|p)\\\\\n&=p^S*(1-p)^{n-S}\n\\end{align}\n\n\\subsection {Maximun Likelihood}\n\n\\begin{align}\n\\frac{d[L(x_i|p)]}{dp} &=\\frac{d[p^S*(1-p)^{n-S}]}{dp}\\\\\n\\frac{d[log(L(x_i|p))]}{dp} &=\\frac{d[log(p^S*(1-p)^{n-S})]}{dp}\\\\\n&= \\frac{d}{dp}*[log(p^S*(1-p)^{n-S})]\\\\\n&= \\frac{d}{dp}[log(p^S)+log((1-p)^{n-S})]\\\\\n&= \\frac{d}{dp}[S*log(p)+(n-S)*log(1-p)]\\\\\n&= S*\\frac{d}{dp}[log(p)]+(n-S)*\\frac{d}{dp}[log(1-p)]\\\\\n&= S*[\\frac{1}{p}]+(n-S)*\\frac{d}{dp}[log(1-p)] && \\text{chain rule}\\\\\n&= S*\\frac{1}{p}+(n-S)*\\frac{1}{p-1}\\\\\n&= \\frac{S}{p}+\\frac{n-S}{p-1}\\\\\n&= \\frac{S*(p-1)}{p*(p-1)}+\\frac{p*(n-S)}{p*(p-1)}\\\\\n&= \\frac{S*(p-1)+p*(n-S)}{p*(p-1)}\\\\\n&= \\frac{S*p-S+p*n-p*S}{p*(p-1)}\\\\\n&= \\frac{-S+p*n}{p*(p-1)}\\\\\n0 &= \\frac{-S+p*n}{p*(p-1)}\\\\\n0*(p*(p-1)) &= -S+p*n\\\\\n0 &= -S+p*n\\\\\nS &= p*n\\\\\n\\frac{S}{n} &= p\\\\\np &= \\frac{S}{n}\\\\\n\\end{align}\n\n\\subsection{MGF}\n\n\\begin{align}\n\tM(t) &= E[e^{tX}]\\\\\n\t&= (1-p)e^{t*0} + pe^{t*1}\\\\\n\t&= (1-p) + pe^{t}\\\\\n\\end{align}\n\n\\subsubsection{E[X] using MGF}\n\n\\begin{align}\nE[X] &= \\frac{d^1}{dt^1}[M(t)](0)\\\\\n\\\\\nM(t) &= (1-p) + pe^{t}\\\\\n\\\\\nE[X] &= \\frac{d^1}{dt^1}[(1-p) + pe^{t}](0)\\\\\n&= [\\frac{d^1}{dt^1}[(1-p)] + \\frac{d^1}{dt^1}[pe^{t}]](0)\\\\\n&= [0 + \\frac{d^1}{dt^1}[pe^{t}]](0)\\\\\n&= [\\frac{d^1}{dt^1}[pe^{t}]](0)\\\\\n&= [pe^{t}](0)\\\\\n&= [pe^{0}]\\\\\n&= p*1\\\\\n&= p\\\\\n\\end{align}\n\n\\subsubsection{$E[X^2]$ using MGF}\n\n\\begin{align}\nE[X^2] &= \\frac{d^2}{dt^2}[M(t)](0)\\\\\n\\\\\nM(t) &= (1-p) + pe^{t}\\\\\n\\\\\nE[X^2] &= \\frac{d^2}{dt^2}[(1-p) + pe^{t}](0)\\\\\n&= \\frac{d^1}{dt^1}[pe^{t}](0) && \\text{see E[X] using MGF}\\\\\n&= [pe^{t}](0)\\\\\n&= [pe^{0}]\\\\\n&= p*1\\\\\n&= p\\\\\n\\end{align}\n\nAnd these values can be checked calculating the $var[X]$.\n\n\\begin{align}\n\tvar[X] &= E[X^2] - E[X]^2\\\\\n\t&= p - p^2\\\\\n\t&= p*(1-p)\\\\\n\t\\qed\n\\end{align}\n\n\\subsubsection{$E[X^n]$ using MGF}\n\n\\begin{align}\nE[X^2] &= \\frac{d^2}{dt^2}[M(t)](0)\\\\\n\\\\\nM(t) &= (1-p) + pe^{t}\\\\\n\\\\\nE[X^2] &= \\frac{d^2}{dt^2}[(1-p) + pe^{t}](0)\\\\\n\\end{align}\n\n\\section{Binomial Distribution}\n\n\\subsection{PMF}\n\\begin{align}\nP(X=k) &= \\binom{n} {k} p^k (1-p)^{n-k}\n\\end{align}\n\n%prove that the summation is 1\n%prove the expected value\n%\\paragraph{https://proofwiki.org/wiki/Expectation_of_Binomial_Distribution}\n\n\\subsection {Expected Value}\n\n$E[g(X)]$ when $g(X) = X$.\n\n\\begin{align}\nE(X) &= \\sum_{k \\geqslant 0}P(x=k)*k\\\\\n&= \\sum_{k \\geqslant 0}[\\binom{n} {k} p^k (1-p)^{n-k}] * k\\\\\n\\end{align}\n\nwhen $$k=0$$, the formula $$[\\binom{n} {k} p^k (1-p)^{n-k}] * k = [\\binom{n} {0} p^k (1-p)^n] * 0 = 0$$, so the index of the summation can be increased by 1.\n\n\\begin{align}\nE(X) &= \\sum_{k \\geqslant 1} \\binom{n}{k} p^k (1-p)^{n-k} * k\\\\\n&= \\sum_{k \\geqslant 1} \\frac{n}{k} * \\binom{n-1}{k-1} p^k (1-p)^{n-k} * k && \\text{see BinomialCoefficient}\\\\\n&= \\sum_{k \\geqslant 1} \\frac{n*k}{k} * \\binom{n-1}{k-1} p^k (1-p)^{n-k}\\\\\n&= \\sum_{k \\geqslant 1} n * \\binom{n-1}{k-1} p^k (1-p)^{n-k}\\\\\n&= \\sum_{k \\geqslant 1} n*p * \\binom{n-1}{k-1} p^{k-1} (1-p)^{n-k}\\\\\n&= np * \\sum_{k \\geqslant 1} \\binom{n-1}{k-1} p^{k-1} (1-p)^{n-k}\\\\\nu = n-1\\\\\nz = k-1\\\\\nu-z&=(n-1)-(k-1)\\\\\n&=n-1-k+1\\\\\n&=n-k\\\\\nk>1&=(z+1)>1\\\\\n&=z>0\\\\\n&= np * \\sum_{z>0} \\binom{u}{z} p^{z} (1-p)^{u-z}\\\\\n&= np * 1 && see BinomialDistributionProofEquals1\\\\\n&= np\\\\\n\\qedsymbol\n\\end{align}\n\n\\subsection {Variance}\n\n\\begin{align}\n\tVar(X) &= E(X^2) - E(X)^2 && \\text{see Variance}\\\\\n\t&= \\sum_{k \\geqslant 0} {[\\binom{n} {k} p^k (1-p)^{n-k}]*k^2} - np && \\text{see Binomial Expected Value}\n\\end{align}\n\nwhen $$k=0$$, the formula $$[\\binom{n} {k} p^k (1-p)^{n-k}] * k = [\\binom{n} {0} p^k (1-p)^n] * 0 = 0$$, so the index of the summation can be increased by 1.\n\n\\begin{align}\n&= \\sum_{k \\geqslant 1} {[\\binom{n} {k} p^k (1-p)^{n-k}]*k^2} - (np)^2\\\\\n&= \\sum_{k \\geqslant 1} {\\frac{n}{k} [\\binom{n-1} {k-1} p^k (1-p)^{n-k}]*k^2} - (np)^2\\\\\n&= \\sum_{k \\geqslant 1} {\\frac{n*k^2}{k} [\\binom{n-1} {k-1} p^k (1-p)^{n-k}]} - (np)^2\\\\\n&= \\sum_{k \\geqslant 1} {[nk*\\binom{n-1} {k-1} p^k (1-p)^{n-k}]} - (np)^2\\\\\n&= \\sum_{k \\geqslant 1} {[nkp*\\binom{n-1} {k-1} p^{k-1} (1-p)^{n-k}]} - (np)^2\\\\\n&= np*\\sum_{k \\geqslant 1} {[k*\\binom{n-1} {k-1} p^{k-1} (1-p)^{n-k}]} - (np)^2\\\\\nu = n-1\\\\\nz = k-1\\\\\nu-z&=(n-1)-(k-1)\\\\\n&=n-1-k+1\\\\\n&=n-k\\\\\nk >= 1 &= (z+1) >=1\\\\\n&= z >= 0\\\\\n&= np*\\sum_{z \\geqslant 0} {[(z+1)* \\binom{u} {z} p^{z} (1-p)^{u-z}]} - (np)^2\\\\\n&= np*[\\sum_{z \\geqslant 0} {[z*\\binom{u} {z} p^{z} (1-p)^{u-z}]} + \\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]}] - (np)^2\\\\\n&= np*[\\sum_{z \\geqslant 0} {[z*\\frac{u}{z}*\\binom{u-1} {z-1} p^{z} (1-p)^{u-z}]} + \\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]}] - (np)^2\\\\\n&= np*[u*\\sum_{z \\geqslant 0} {[\\binom{u-1} {z-1} p^{z} (1-p)^{u-z}]} + \\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]}] - (np)^2\\\\\n\\end{align}\n\\begin{align}\n&= np*[up*\\sum_{z \\geqslant 0} {[\\binom{u-1} {z-1} p^{z-1} (1-p)^{u-z}]} + \\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]}] - (np)^2\\\\\n&= np*[up*\\sum_{z \\geqslant 1} {[\\binom{u-1} {z-1} p^{z-1} (1-p)^{(u-1)-(z-1)}]} + \\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]}] - (np)^2\\\\\n&= np*[up*\\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]} + \\sum_{z \\geqslant 0} {[\\binom{u} {z} p^{z} (1-p)^{u-z}]}] - (np)^2\\\\\n&= np*[up*(p+q)^{u-1} + (p+q)^u] - (np)^2\\\\\n&= np*[(n-1)*p*(p+q)^{n-1-1}+(p+q)^(n-1)] -(np)^2\\\\\n&= np*[(n-1)*p*(p+q)^{n-2}+(p+q)^(n-1)] - (np)^2\\\\\n&= np*([(n-1)*p*(p+q)^{n-2}+(p+q)^(n-1)] - np)\\\\\n&= np*([(n-1)*p+1] - np) && \\text{p+q=1}\\\\\n&= np*([(n-1)*p+1] - np)\\\\\n&= np*([np-p +1] - np)\\\\\n&= np*(np-p +1- np)\\\\\n&= np*(-p +1)\\\\\n&= np*(1-p)\\\\\n\\qed\n\\end{align}\n \n\\section {Geometric Distribution}\n\n\\subsection {CDF}\n\n\\begin{align*}\n\tP(X \\le x) &=\\\\\n\tCDF(X=x) &= \\sum_{i=0}^{x}{(1-p)^ip} &\\text{by geometric summation}\\\\\n\t&= p\\frac{1-(1-p)^x}{1-(1-p)}\\\\\n\t&= p\\frac{1-(1-p)^x}{1-1+p}\\\\\n\t&= p\\frac{1-(1-p)^x}{p}\\\\\t\n\t&= 1-(1-p)^x\\\\\t\n\t\\qed\\\\\n\t\\\\\n\tP(X > x) &= 1 - CDF(X=x)\\\\\n\t&= 1 - (1-(1-p)^x)\\\\\n\t&= 1 - 1 +(1-p)^x\\\\\t\n\t&= (1-p)^x\\\\\t\n\t\\qed\n\\end{align*}\n\n\\section {Normal Distribution}\n\n\\subsection {Definition}\n\n\\begin{align}\npdf(x) &= \\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2}\\right)\n\\end{align}\n\n\\chapter{Continuous Distributions}\n\n\\section{Uniform Distribution}\n\n\\subsection{PDF}\n\\begin{align*}\n\\int_{a}^{b} {kdx} &= 1\\\\\n&= k\\int_{a}^{b} {dx}\\\\\n&= k[x|_{a}^{b}]\\\\\n&= k[b-a]\\\\\t\n\\\\\nk[b-a] &= 1\\\\\nk &= \\frac{1} {b-a}\\\\\n\\end{align*}\n\n\\subsection{Expected Value}\n\\begin{align*}\n\\int_{a}^{b} {x\\big( \\frac{1}{b-a} \\big)dx} &= \\\\\n&= \\int_{a}^{b} {x\\big( \\frac{1}{b-a} \\big)dx}\\\\\n&= \\frac{1}{b-a}\\int_{a}^{b} {xdx}\\\\\n&= \\frac{1}{b-a}\\big[ \\frac{x^2}{2}|_{a}^{b} \\big]\\\\\n&= \\frac{1}{b-a}\\big[ \\frac{b^2}{2} - \\frac{a^2}{2} \\big]\\\\\n&= \\frac{1}{b-a}\\big[ \\frac{b^2-a^2}{2} \\big]\\\\\n&= \\frac{1}{b-a}\\big[ \\frac{(b+a)(b-a)}{2} \\big]\\\\\n&= \\frac{(b+a)(b-a)}{2(b-a)}\\\\\n&= \\frac{b+a}{2}\\\\\n\\end{align*}\n\n\\subsection{Variance}\n\\begin{align*}\nvar(X) &= E[X^2] - E[X]^2\\\\\n&= [\\int_{a}^{b} {x^2\\big( \\frac{1}{b-a} \\big)dx}] - (\\frac{b+a}{2})^2\\\\\n&= [\\frac{1}{b-a}\\int_{a}^{b} {x^2dx}] - (\\frac{b+a}{2})^2\\\\\n&= [\\frac{1}{b-a}\\frac{x^3}{3}|_{a}^{b}] - (\\frac{b+a}{2})^2\\\\\n&= \\frac{1}{b-a}(\\frac{b^3}{3}-\\frac{a^3}{3}) - (\\frac{b+a}{2})^2\\\\\n&= \\frac{b^3-a^3}{3(b-a)} - \\frac{(b+a)^2}{4}\\\\\n&= \\frac{(b-a)(b^2-ab+a^2)}{3(b-a)} - \\frac{(b+a)^2}{4}\\\\\n&= \\frac{(b^2-ab+a^2)}{3} - \\frac{(b+a)^2}{4}\\\\\n&= \\frac{4(b^2-ab+a^2)}{12} - \\frac{3(b+a)^2}{12}\\\\\n&= \\frac{4b^2-4ab+4a^2}{12} - \\frac{3(b^2+2ab+a^2)}{12}\\\\\n&= \\frac{4b^2-4ab+4a^2}{12} - \\frac{3b^2+6ab+3a^2}{12}\\\\\n&= \\frac{4b^2-3b^2-4ab-6ab+4a^2-3a^2}{12}\\\\\n&= \\frac{b^2-2ab+a^2}{12}\\\\\n&= \\frac{(b-a)^2}{12}\\\\\n\\end{align*}\n\n\\pagebreak\n\\section {Exponential Distribution}\n\n\\subsection{PDF}\n\\begin{align*}\nf_x(x) &= \\lambda e^{-\\lambda x} && x >= 0\n\\end{align*}\n\n\\subsection{CDF}\n\\begin{align*}\n\tCDF(x) = \\int_{-\\infty}^{x} {f_xdx}\\\\\n\tCDF(x) = \\int_{-\\infty}^{x} {\\lambda e^{-\\lambda x}dx}\\\\\n\t\\\\\n\tu = e^{-\\lambda x}\\\\\n\t\\frac{du}{dx} = d[e^{-\\lambda x}]\\\\\n\tdu = d[e^{-\\lambda x}]*dx\\\\\n\tdu = [-\\lambda * e^{-\\lambda x}]*dx\\\\\n\tdu = -\\lambda e^{-\\lambda x}dx\\\\\n\t\\\\\n\tCDF(x) = \\int_{-\\infty}^{x} {\\lambda e^{-\\lambda x}dx}\\\\\n\tCDF(x) = -1*\\int_{-\\infty}^{x} {-1*\\lambda e^{-\\lambda x}dx}\\\\\n\tCDF(x) = -1*\\int_{-\\infty}^{x} {-\\lambda e^{-\\lambda x}dx}\\\\\n\tCDF(x) = -1*\\int_{-\\infty}^{x} {du}\\\\\n\tCDF(x) = -1*\\int_{0}^{x} {du} && \\text{by x bounds}\\\\\n\tCDF(x) = -1*[u]_{0}^{x}\\\\\n\tCDF(x) = -1*[e^{-\\lambda x}]_{0}^{x}\\\\\n\tCDF(x) = -1*[e^{-\\lambda x} - e^{-\\lambda 0}]\\\\\n\tCDF(x) = -1*[e^{-\\lambda x} - e^{0}]\\\\\n\tCDF(x) = -1*[e^{-\\lambda x} - 1]\\\\\n\tCDF(x) = [1 - e^{-\\lambda x}]\\\\\n\tCDF(x) = 1 - e^{-\\lambda x}\\\\\n\\end{align*}\n\n\\subsection{Expected Value}\n\\begin{align*}\nf_x(x) &= \\lambda e^{-\\lambda x}\\\\\n\\\\\nE[x] &= \\int {x*f_x(x)dx}\\\\\nE[x] &= \\int {x*\\lambda e^{-\\lambda x}dx}\\\\\n\\\\\n\tu = x\\\\\n\tdu = 1*dx\\\\\n\tv = e^{-\\lambda x}\\\\\n\tdv = e^{-\\lambda x}*-\\lambda * dx\\\\\n\tdv = -\\lambda e^{-\\lambda x}dx\\\\\n\t\\\\\nE[x] &= \\int {[x] [\\lambda e^{-\\lambda x}dx]}\\\\\nE[x] &= -1*\\int {[x] [-1* \\lambda e^{-\\lambda x}dx]}\\\\\nE[x] &= -1*\\int {[x] [-\\lambda e^{-\\lambda x}dx]}\\\\\nE[x] &= -1*\\int {udv}\\\\\nE[x] &= -1*[uv|_{-\\infty}^{\\infty} - \\int {vdu}]\\\\\nE[x] &= -1*[uv|_{0}^{\\infty} - \\int {vdu}] && \\text{because x bounds}\\\\\nE[x] &= -1*[[xe^{-\\lambda x}]_{0}^{\\infty} - \\int {e^{-\\lambda x}dx}]\\\\\n\\end{align*}\n\\begin{align*}\n[xe^{-\\lambda x}]_{0}^{\\infty} &= \\lim_{x->\\infty}{[xe^{-\\lambda x} - (0)e^{-\\lambda (0)}]}\\\\\n&= \\lim_{x->\\infty}{[xe^{-\\lambda x} + 0e^{0}]}\\\\\n&= \\lim_{x->\\infty}{[xe^{-\\lambda x}]}\\\\\n&= 0\\\\\n\\\\\nE[x] &= -1 * - \\int {e^{-\\lambda x}dx}\\\\\nE[x] &= \\frac{1}{\\lambda} \\int {\\lambda e^{-\\lambda x}dx}\\\\\nE[x] &= \\frac{1}{\\lambda}\\\\\n\\end{align*}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{Random Variables Relationships}\n\\end{figure}\n\n\n\\end{document}", "meta": {"hexsha": "41de2d39bd1c980b1ec0edc56455459b0e8e3b5f", "size": 14529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texts/math/Handout.Stats.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.Stats.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.Stats.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": 31.0448717949, "max_line_length": 428, "alphanum_fraction": 0.4976942666, "num_tokens": 7348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.6852458019165859}}
{"text": "%!TEX root = ../thesis.tex\n% ******************************* Thesis Appendix B ********************************\n\n\\chapter{Analytic computation of eigenvalues for zonal functions}\n\\label{app:sec:compute-eigenvalues}\n\n\nThe eigenvalues of a zonal function are given by the one-dimensional integral:\n\\begin{equation}\n    \\label{appendix:theorem:funk2}\n    \\lambda_{n} = \n   \\frac{\\omega_{d}}{C_n^{(\\alpha)}(1)} \\int_{-1}^1 s(t)\\,C_n^{(\\alpha)}(t)\\,(1 - t^2)^{\\frac{d-3}{2}} \\calcd{t},\n\\end{equation}\nwhere $C_n^{(\\alpha)}(\\cdot)$ is the Gegenbauer polynomial of degree $n$ with $\\alpha = \\frac{d-2}{2}$ and $\\omega_{d} = \\Omega_{d-2} / \\Omega_{d-1}$ denotes the surface area of $\\dsphere$ (see \\cref{appendix:spherical-harmonics} for analytical expressions of these quantities). The shape function $s(t)$ determines whether this integral can be computed in closed-form. In the next sections we derive analytical expressions for the eigenvalues of the Arc Cosine kernel and ReLU activation function in the case the $d$ is odd. For $d$ even, other kernels (e.g., Mat\\'ern) or activation functions (e.g., Softplus, Swish, etc.) we rely on numerical integration (e.g., Gaussian quadrature) to obtain these coefficients. We will show that both approaches lead to highly similar results.\n\n\\section{Arc Cosine kernel}\n\\label{sec:appendix:compute-eigenvalues-arccosine}\n\nThe shape function of the first-order Arc Cosine kernel \\citep{cho2009kernel} is given by:\n\\begin{equation}\n    s:[0, \\pi] \\rightarrow \\Reals,\\quad s: x \\mapsto \\sin x + (\\pi - x) \\cos x,\n\\end{equation}\nwhere we expressed the shape function as a function of the angle between the two inputs, rather than the cosine of the angle. For notational simplicity, we also omitted the factor $1 / \\pi$.\n\nUsing a change of variables we rewrite \\cref{appendix:theorem:funk2}\n\\begin{equation}\n    \\lambda_n\n    =  \\frac{\\omega_{d}}{C_n^{(\\alpha)}(1)}  \\int_{0}^\\pi s(x)\\,C_n^{(\\alpha)}(\\cos x) \\sin^{d-2} x\\,\\calcd{x},\n\\end{equation}\n% with $c_{d, n} = \\frac{\\omega_{d-2}}{C_n^{(\\alpha)}(1)}$.\n\nSubstituting $C_n^{(\\alpha)}(\\cos x)$ by its polynomial expansion, it becomes evident that we need a general solution of the integral for $n,\\,m \\in \\Naturals$\n\\begin{equation}\n\\int_0^\\pi \\left[ \\sin(x) + (\\pi - x) \\cos(x) \\right] \\cos^n(x) \\sin^m(x) \\calcd{x}.\n\\end{equation}\n\nThe first term can be computed with this well-known result:\n% \\footnote{\\url{https://math.stackexchange.com/questions/2833731/reduction-formula-for-integral-sinm-x-cosn-x-with-limits-0-to-pi-2}}:\n\\begin{equation}\n    \\int_0^{\\pi} \\sin^n(x) \\cos^m(x) \\calcd{x} =\n    \\begin{cases}\n        0                                   & \\text{if}\\ m\\ \\text{odd}\\\\\n        \\frac{(n-1)!!~(m-1)!!}{(n+m)!!} \\pi & \\text{if}\\ m\\ \\text{even and }n\\ \\text{odd},\\\\\n        \\frac{(n-1)!!~(m-1)!!}{(n+m)!!} 2   & \\text{if}\\ n,m\\ \\text{even}.\n    \\end{cases}\n\\end{equation}\n\nThe second term is more cumberstone and is given by:\n\\begin{equation}\n    I := \\int_0^{\\pi} (\\pi - x) \\sin^n(x) \\cos^m(x) \\calcd{x}\n\\end{equation}\nwhich we solve using integration by parts with $u = \\pi - x$ and $\\calcd{v} = \\sin^n(x) \\cos^m(x) \\calcd{x}$, yielding\n\\begin{equation}\n    I = u(0) v(0) - u(\\pi) v(\\pi) + \\int_0^{\\pi} v(x') \\calcd{x'},\n\\end{equation}\nwhere $v(x') = \\int_0^{x'} \\sin^n(x) \\cos^m(x) \\calcd{x}$. This gives $v(0) = 0$ and $u(0) = 0$, simplifying $I = \\int_0^\\pi v(x') \\calcd{x'}$.\n% \\begin{equation}\n%     I = \\int_0^{\\pi} \\int_0^x \\sin^n(x') \\cos^m(x') \\diff x' \\diff x,\n% \\end{equation}\n\nWe first focus on $v(x')$:\nfor \\underline{$n$ odd}, there exists a $n' \\in \\Naturals$ so that $n = 2n' + 1$, resulting\n\\begin{equation}\n    v(x') = \\int_0^{x'} \\sin^{2n'}(x) \\cos^m(x) \\sin(x) \\calcd{x}\n          = -\\int_0^{\\cos(x')} (1 - u^2)^{n'} u^m \\calcd{u}\n\\end{equation}\nWhere we used $\\sin^2(x) + \\cos^2(x) = 1$ and the substitution $u = \\cos(x) \\implies \\calcd{u} = - \\sin(x) \\calcd{x}$. Using the binomial expansion, we get\n\\begin{equation}\n    v(x') = -\\int_0^{\\cos(x')} \\sum_{i=0}^{n'} \\binom{k}{i} (-u^2)^i u^m \\calcd{u} \n    = \\sum_{i=0}^{n'} (-1)^{i+1} \\binom{k}{i} \\frac{\\cos(x')^{2i+m+1} - 1}{2i+m+1}.\n\\end{equation}\n\nSimilarly, for \\underline{$m$ odd}, we have $m=2m' + 1$ and use the substitution $u = \\sin(x)$, to obtain\n\\begin{equation}\n    v(x') = \\sum_{i=0}^{m'} (-1)^{i} \\binom{k}{i} \\frac{\\sin(x')^{2i+n+1}}{2i+n+1}.\n\\end{equation}\n\nFor \\underline{$n$ and $m$ even}, we set $n' = n/2$ and $m' = m/2$ and use the double-angle identity, yielding\n\\begin{equation}\n    v(x') = \\int_0^{x'} \\left(\\frac{1 - \\cos(2x)}{2}\\right)^{n'} \\left(\\frac{1 + \\cos(2x)}{2}\\right)^{m'} \\calcd{x}.\n\\end{equation}\nMaking use of the binomial expansion twice, we retrieve\n\\begin{equation}\n    v(x') = 2^{-(n' + m')} \\sum_{i,j=0}^{n', m'} (-1)^{i} \\binom{n'}{i} \\binom{m'}{j} \n    \\int_0^{x'} \\cos(2x)^{i+j} \\calcd{x}.\n\\end{equation}\n\nReturning back to the original problem $I = \\int_0^\\pi v(x') \\calcd{x'}$. Depending on the parity of $n$ and $m$ we need to evaluate:\n% $\\int_0^\\pi \\cos(x')^p \\diff x'$ ($n$ odd),\n% $\\int_0^\\pi \\sin(x')^p \\diff x'$ ($m$ odd) and\n% $\\int_0^\\pi \\int_0^{x'} \\cos(2x)^p \\diff x \\diff x'$ ($n$ and $m$ even), which are given by\n\\begin{equation}\n    \\int_0^\\pi \\cos(x')^p \\calcd{x'} = \n    \\begin{cases}\n        \\frac{(p-1)!!}{p!!} \\pi   & \\text{if}\\ p\\ \\text{even} \\\\\n        0                         & \\text{if}\\ p\\ \\text{odd},\n    \\end{cases}\n    \\quad \\text{or} \\quad\n    \\int_0^\\pi \\sin(x')^p \\calcd{x'} = \n    \\begin{cases}\n        \\frac{(p-1)!!}{p!!} \\pi   & \\text{if}\\ p\\ \\text{even} \\\\\n        \\frac{(p-1)!!}{p!!} 2   & \\text{if}\\ p\\ \\text{odd}.\n    \\end{cases}\n\\end{equation}\nFor $m$ and $n$ even we require the solution to the double integral\n\\begin{equation}\n    \\int_0^\\pi \\int_0^{x'} \\cos(2x)^p \\calcd{x} \\calcd{x'} = \n    \\begin{cases}\n        \\frac{(p-1)!!}{p!!} \\frac{\\pi^2}{2}   & \\text{if}\\ p\\ \\text{even} \\\\\n        0   & \\text{if}\\ p\\ \\text{odd}.\n    \\end{cases}\n\\end{equation}\n\nCombining the above intermediate results gives the solution to \\cref{appendix:theorem:funk2} for the Arc Cosine kernel. In \\cref{tab:eigenvalues} we list the first few eigenvalues for different dimensions and compare the analytical to the numerical computation. \n\n\\begin{table}[tbh]\n    \\centering\n    \\caption{Eigenvalues for the first-order Arc Cosine kernel \\cref{eq:arccosine}  computed analytically and numerically for different degrees $n$ and dimensions $d$. In the experiments we set values smaller than $10^{-9}$ to zero. \\label{tab:eigenvalues}}\n    \\vspace{.2cm}\n    \\input{Appendix2/eigenvalues-arc-cosine}\n\\end{table}\n\n\n\\section{ReLU activation function}\n\nThanks to the simple form of the ReLU's activation shape function $\\sigma(t) = \\max(0, t)$, its Fourier coefficients can also be computed analytically. The integral to be solved is given by\n\\begin{equation}\n    \\sigma_{n} = \n   \\frac{\\omega_{d}}{C_n^{(\\alpha)}(1)} \n   \\int_{0}^1 t\\,C_n^{(\\alpha)}(t)\\,(1 - t^2)^{\\alpha - 1/2} \\calcd{t}.\n\\end{equation}\nUsing Rodrigues' formula for $C_n^{(\\alpha)}(t)$, we can conveniently cancel the factor $(1 - t^2)^{\\alpha - 1/2}$\n\\begin{equation}\n    \\sigma_{n} = \n    \\omega_{d}\n  {\\frac {(-1)^{n}}{2^{n}}}{\\frac {\\Gamma (\\alpha +{\\frac {1}{2}})}{\\Gamma (\\alpha +n+{\\frac {1}{2}})}} \n  \\int_0^1 t {\\frac {d^{n}}{dt^{n}}}\\left[(1-t^{2})^{n+\\alpha -1/2}\\right] \\calcd{t}\n\\end{equation}\nUsing integration by parts for $n \\ge 2$ we can solve the integral \\citep[Appendix D]{bach2017breaking}\n\\begin{align}\n  \\int_0^1 t {\\frac {d^{n}}{dt^{n}}}\\left[(1-t^{2})^{n+\\alpha -1/2}\\right] \\calcd{t} &= \n    \\binom{n + \\alpha - 1/2}{k} (-1)^k (2k)!\\ \\text{for}\\ 2k= n - 2 \\\\\n    &= \\frac{ \\Gamma(n + \\alpha + \\frac{1}{2}) (-1)^{n/2-1} \\Gamma(n-1)}{\\Gamma(\\frac{n}{2}) \\Gamma(\\frac{n}{2} + \\alpha + \\frac{3}{2})}\n\\end{align}\nThus, substituting $\\alpha = \\frac{d-2}{2}$, yields\n\\begin{equation}\n    \\sigma_{n} = \n        \\frac{\\Gamma(\\frac{d}{2}) (-1)^{n/2 - 1}}{\\sqrt{\\pi}\\,2^n} \\frac{\\Gamma(n-1)}{\\Gamma(\\frac{n}{2}) \\Gamma(\\frac{n}{2} + \\frac{d+1}{2})},\\ \\text{for}\\ n = 2, 4, 6, \\ldots,\n\\end{equation}\nand $\\sigma_{n}=0$ for $n=3, 5, 7, \\dots$. Finally, for $n = 0$ and $n = 1$, we obtain\n\\begin{equation}\n    \\sigma_0 = \\frac{1}{2\\, \\sqrt{\\pi}} \\frac{\\Gamma(\\frac{d}{2})}{\\Gamma(\\frac{d+1}{2})}, \\qquad \\qquad\n    \\sigma_1 = \\frac{1}{2\\, (d-1)} \\frac{\\Gamma(\\frac{d}{2}) \\Gamma(\\frac{d+1}{2})}{\\Gamma(\\frac{d-1}{2}) \\Gamma(\\frac{d}{2} + 1)}.\n\\end{equation}\n\n% Substituting $(1-t^{2})^{n+\\alpha -1/2}$ by its binomial expansion, we obtain\n% \\begin{equation}\n%     \\sigma_{n} = \n%   {\\frac {\\omega_d}{(-2)^{n}}}{\\frac {\\Gamma (\\alpha +{\\frac {1}{2}})}{\\Gamma (n + \\alpha +{\\frac {1}{2}})}} \\sum_{k=\\lceil \\frac{n}{2} \\rceil}^{n + \\alpha - \\frac{1}{2}} (-1)^k \\binom{n + \\alpha - \\frac{1}{2}}{k} \\frac{(2 k)^{\\underline{n}}}{2 k - n + 2},\n% \\end{equation}\n% where $\\lceil \\cdot \\rceil$ is the ceiling operator and $\\underline{\\cdot}$ the falling factorial (sometimes called the descending factorial). Further simplification gives\n% \\begin{equation}\n%     \\sigma_n =  {\\frac {\\omega_d}{(-2)^{n}}} \\Gamma(\\alpha + \\frac{1}{2}) \n%     \\sum_{k=\\lceil \\frac{n}{2} \\rceil}^{n + \\alpha - \\frac{1}{2}}\n%     \\frac{(-1)^k }{\\Gamma(k+1)\\,\\Gamma(n + \\alpha + \\frac{1}{2} - k)} \\frac{\\Gamma(2k+1)}{(2k-n+2) \\Gamma(2k -n + 1)}.\n% \\end{equation}\n\nIn \\cref{tab:eigenvalues-relu} we compare the analytic expression to numerical integration using quadrature. There is a close match for eigenvalues of significance and a larger discrepancy for very small eigenvalues. In practice we set values smaller than $10^{-9}$ to zero.\n\n% \\begin{equation}\n%     \\sigma_n = \\omega_d\n%     \\left[ (-2)^{-\\ell} \\frac{\\Gamma(\\frac{d-1}{2})}{\\Gamma(\\ell + \\frac{d-1}{2})}\\right]\n%     \\sum_{k = \\text{ceil} (\\frac{\\ell}{2})}^{\\ell + \\frac{d - 3}{2}} (-1)^k \\binom{\\ell + \\frac{d-3}{2}}{k} (2 k)^{\\underline{\\ell}}\\,(2k-\\ell+2)^{-1} \n% \\end{equation}\n\n% \\begin{equation}\n%     c(d, \\ell) = \\left[ (-2)^\\ell \\frac{\\Gamma(\\ell + \\frac{d-1}{2})}{\\Gamma(\\frac{d-1}{2})} \\right]^{-1} = \n%     \\left[ (-2)^\\ell {(\\ell + \\frac{d-3}{2})^{\\underline{\\ell}}} \\right]^{-1}.\n% \\end{equation}\n\n\\begin{table}[tbh]\n    \\centering\n    \\caption{Eigenvalues for the ReLU activation \\cref{eq:arccosine}  computed analytically and numerically for different degrees $n$ and dimensions $d$. In the experiments we set values smaller than $10^{-9}$ to zero. \\label{tab:eigenvalues-relu}}\n    \\vspace{.2cm}\n    \\input{Appendix2/eigenvalues-relu}\n\\end{table}\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Appendix2/coefficients_relu.pdf}\n    \\caption{ReLU coefficients $\\sigma_n$ as a function of degree $n$ for different dimensions $d$.}\n    \\label{fig:relu-coef}\n\\end{figure}\n\n% \\begin{figure}[t]\n%     \\centering\n%     \\includegraphics[width=\\linewidth]{figures/spectra_kernels_and_activations.pdf}\n%     \\caption{Spectra of Arc Cosine and Mat\\'ern-5/2 (blue), and ReLU and Softplus (orange) for different levels.}\n%     \\label{fig:spectra}\n% \\end{figure}", "meta": {"hexsha": "d59fdc8026135db923821b29f1a60c8356308cd1", "size": 10941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix2/appendix2.tex", "max_stars_repo_name": "vdutor/FYR", "max_stars_repo_head_hexsha": "e32e175235720c7651c3b5200dcccf8046ab3099", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendix2/appendix2.tex", "max_issues_repo_name": "vdutor/FYR", "max_issues_repo_head_hexsha": "e32e175235720c7651c3b5200dcccf8046ab3099", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendix2/appendix2.tex", "max_forks_repo_name": "vdutor/FYR", "max_forks_repo_head_hexsha": "e32e175235720c7651c3b5200dcccf8046ab3099", "max_forks_repo_licenses": ["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.705, "max_line_length": 781, "alphanum_fraction": 0.6087194955, "num_tokens": 4109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6852457964711295}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\n\\setcounter{chapter}{0}\n\\chapter{Reflections on the Notion of Space I}\n\nThe purpose of these first lectures is to understand the notion of a manifold in different contexts (topological/differential/analytic manifolds). We begin in this first lecture by looking at the case of topological manifolds.\n\n\\section{Reminders on topological manifolds}\n\n\\begin{defn}\n\n\n\\begin{enumerate}\n    \\item A \\textbf{topological manifold} is a topological space $X$ that has an open cover $\\{U_i\\}_{i \\in I}$, such that for each $i \\in I$, there exists a homeomorphism from $U_i$ to an open set of $\\mathbb R^{n_i}$ (for some $n_i\\ge 0$ depedent on $i$).\n    \\item The category of topological manifolds is the full subcategory of topological spaces whose objects are topological manifolds. It is denoted by $\\mathbf{TopMfd}$.\n\\end{enumerate}\n\n\\end{defn}\n\nLet $X$ be a topological manifold and $\\{U_i\\}_{i \\in I}$ an open cover as in definition $1.1 (1)$. We write, for $i$ and $j$ in $I$, $U_{i,j} = U_n \\cap U_j$. There's a diagram of topological spaces\n\n\\[\n    \\bigsqcup_{(i, j) \\in I^2} U_{i, j} \\rightrightarrows \\bigsqcup_{i \\in I} U_i\n\\]\n\nThe first morphism sends $U_{i, j}$ to $U_i$ via the natural inclusion $U_{i,j}\nsubset U_i$, and the second morphism sends $U_{i, j}$ to $U_j$ via the natural inclusion $U_{i, j}\n\\subset U_j$. There's also another morphism\n\n\\[\n    \\bigsqcup_{i \\in I} U_i \\to X\n\\]\n\nwhich are inclusions $U_i \\subset X$. This coequalizes the two morphisms above. So we get a morphism of topological spaces\n\n\\[\nColim\\left(\\bigsqcup_{(i, j) \\in I^2} U_{i, j} \\rightrightarrows \\bigsqcup_{i \\in I} U_i\\right) \\to X\n\\]\n\nThe important fact is the following\n\n\\begin{lem}\n\nThe morphism\n\n\\[\nColim\\left(\\bigsqcup_{(i, j) \\in I^2} U_{i, j} \\rightrightarrows \\bigsqcup_{i \\in I} U_i\\right) \\to X\n\\]\n\nis an isomorphism.\n\\end{lem}\n\n\\begin{proof}\nThe lemma says for a topological space $Y$, to give a morphism $f: X \\to Y$ is the same as choosing, for each given $i \\in I$, a morphism $f_i: U_i \\to Y$ such that $(f_i)|_{U_{i, j}} = (f_j)|_{U_{i, j}}$ for all $(i, j) \\in I^2$.\n\n(Exercise: provide the details.)\n\\end{proof}\n\nOne can interpret the above lemma as follows: all topological manifolds are obtains as the colimit of a diagram of opens in $\\mathbb R^n$ (for some $n$). We draw from this the following principle:\n\n\\begin{prcp*}\nThe category $TopMfd$ of topological manifolds is deduced from the category of opens in $\\mathbb R^n$ (and continiuous maps.).\n\\end{prcp*}\n\nthis is the principle that we're going to clarify in the following.\n\n\\section{Manifolds and sheaves}\n\nLet $C$ be the full subcategory of $TopMfd$ whose objects are opens of $\\mathbb R^n$. We denote by $Pr(C)$ the category of presheaves of sets over $C$ (also denoted $\\hat C$). We consider the Yoneda embedding restricted to $C$:\n\n\\begin{align}\nh_{(-)}: VarTop &\\to Pr(C)\\\\\nX &\\mapsto h_X\n\\end{align}\n\nwhere the presheaf $h_X$ is defined by\n\n\\[\nh_X(Y) := Hom_{TopMfd}(Y, X)\n\\]\n\n\n\\begin{lem}\n    The functor $h_{(-)}$ above is fully faithful.\n\\end{lem}\n\n\\begin{proof}\nThe functor is faithful: ...\n\nThe functor is full: ...\n\nTODO: finish\n\\end{proof}\n\nThe lemma 2.1 is a good point of depature, for $TopMfd$ is identified as (is equivalent to) a full subcategory of $Pr(C)$. We seek a characterization of this subcategory.\n\nWe start with $C$ a Grothendieck site by declaring a family of morphisms $\\{U_i \\to U\\}_{i \\in I}$ in C to be a covering family if each morphism $U_i \\to U$ is an open immersion, and the total morphism $\\sqcup_{i \\in I} U_i \\to U$ is surjective. This defines a pre-topology on $C$ (exercise: verify). The associated topology is denoted $\\tau$.\n\n\\begin{lem}\n    For all $X \\in TopMfd$, the presheaf $h_X \\in Pr(C)$ is a sheaf for the topology $\\tau$.\n\\end{lem}\n\n\\begin{proof}\n    ...\n\\end{proof}\n\nLemma 2.2 implies we have a full and faithful functor\n\n\\[\nh_{(-)}: TopMfld \\to Sh(C, \\tau)\n\\]\n\nA sheaf isomorphic to $h_X$ is said to be representable by $X$. More generally we identify the category $TopMfd$ with its image in $Sh(C, \\tau)$\n\nTo chacaterize this image we make a definition\n\n\\begin{defn}\n    \\begin{enumerate}\n            \\item A morphism $f: F \\to G$ in $Sh(C, \\tau)$ is a \\textbf{local homeomphism} if for all $X \\in C$, and all morphisms $h_X \\to G$, the sheaf $F \\times_G h_X$ is representable by some $Y \\in TopMfd$, and the induced morphism $Y \\to X$ by the projection $h_y \\simeq F \\times_G h_X \\to h_X$ is a local homeomorphism of topological spaces \\footnote{Recall: a continuous map of topological spaces is a local homeomorphism if for each $x \\in X$, there exists $U$ an open neighborhood of $x$ in $X$ and $V$ and open neighborhood of $f(x)$ in Y, such that $f$ induces a homeomorphism from $U \\to V$}.\n\n            \\item A morphism in $Sh(C, \\tau)$ is an \\textbf{open immersion} if it's a monomorphism and a local homeomorphism.\n    \\end{enumerate}\n\\end{defn}\n\nIt's easy to verify that open immersions in $Sh(C, \\tau)$ are stable under compositions (Exercise: verify). One can also verify that local heomorphisms are stable under compositions, but this needs corrolary 2.5 below (Exercise: verify). We see also that a morphism of topological manifolds is a local homeomorphism if and only if $h_X \\to h_Y$ is a local homeomorphism in the sense of the above definition (Exercise: verify).\n\nWe then have the following proposition\n\n\\begin{prop}\n    A sheaf $F \\in Sh(C, \\tau)$ is representable by a topological manifold (i.e. $F \\simeq h_X$ for some $X \\in TopMfd$), if there exists a family $\\{U_i\\}_{i \\in I}$ of objects in $C$, and a morphism of sheaves\n\n    \\[\n        p: \\bigsqcup_{i \\in I} h_{U_i} \\to F\n    \\]\n    satisfying the following two conditions\n\n    \\begin{enumerate}\n        \\item The morphism $p$ is an epimorphism of sheaves.\n        \\item For all $i \\in I$, the morphism $U_i \\to F$ is an open immersion (in the sense of definition 2.3)\n    \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n\\end{proof}\n\n\\begin{cor}\n    Let $X \\in TopMfd$, and $F \\to h_X$ a morphism of sheaves. If there exists an open cover of $X$ such that for all $i \\in I$, the sheaf $f \\times_{h_X} h_{U_i}$ is representable by a topological manifold, then $F$ is representable by a topological manifold.\n\\end{cor}\n\\begin{proof}\n    For all $i \\in I$, choose ${V_{i, j}}_{j \\in J}$...\n\\end{proof}\n\n\n\\section{Quotient manifolds}\n\nLet G be a (discrete) group acting on a topological manifold $X \\in TopMfd$. By functoriality, the group $G$ acts on the sheaf $h_X$. Recall a group action on X is ... . Recall also a group action $G$ on $X$ is properly discontinuous if all points $x \\in X$ has an open neighborhood $U \\subset X$ such that for all $g \\in G$, we have\n\n\\[\n    g(U) \\cap U \\ne \\emptyset \\implies (g = e)\n\\]\n\nIn the following, we will take care not to confuse the sheaf quotient $h_X/G$ and the sheaf $h_{X/G}$ represented by the quotient topological space.\n\n\\begin{prop}\n    \\begin{enumerate}\n            \\item If the action $G$ on $X$ is free, the the quotient morphism\n            \\[h_X \\to h_X/G\\] is a local homeomorphism\n            \\item If the action $G$ on $X$ is properly discontinuous, then the quotient $h_X/G \\in Sh(C, \\tau)$ is a topological manifold.\n    \\end{enumerate}\n\\end{prop}\n\\begin{proof}\n...\n\\end{proof}\n\n\\section{Shortcomings of manifolds}\n\nThe proposition 3.1 is a good reason for cosntructing examples of topological manifolds by properly discontinuous actions. However, when $G$ acts on a manifold $X$ but the action is not propertly discontinuous, the topological space quotient $X/G$ is in general very pathological. The sheaf quotient $h_X/G$. The sheaf quotient $h_X/G$ has good properties (e.g. point (1) of proposition 3.1) similar to representability of a topological manifold.\n\nAn example is the following: we take the action of the discrete group $\\mathbb Q$ (under addition on the topological space $\\mathbb R$ via the morphism\n\n\\[\\mathbb R \\times \\mathbb Q \\to \\mathbb R\\]\n\ngiven by $(x, t) \\mapsto x + t$. We note this action is free, but not properly discontinuous. IN addition, the morphism $\\mathbb R \\to \\mathbb R / \\mathbb Q$ is not a local homeomorphism nor is it locally injective. Finally, the topological space quotient $\\mathbb R / \\mathbb Q$ has a gross topology. We see that the quotient $\\mathbb R/ \\mathbb Q$ is not a reasonable object from the point of view of geometry. On the otherhand, the sheaf quotient $h_\\mathbb R/\\mathbb Q$ is more interesting, for the morphisms $h_\\mathbb R \\to h_\\mathbb R / \\mathbb Q$ is a local homeomorphism. The sheaf $h_\\mathbb R / \\mathbb Q$ is a primary example of a geometric space\n\n\\begin{defn}\n    A sheaf $F \\in Sh(C, \\tau)$ is a geometric space if there exists a family of objects $\\{U_i\\}_{i \\in I}$ of $C$, and a morphism of sheaves\n\n    \\[\n        p: \\bigsqcup_{i \\in I} h_{U_i} \\to F\n    \\]\n    satisfies the following two conditions\n\n    \\begin{enumerate}\n        \\item The morphism $p$ is an epimorphism of sheaves\n        \\item For all $i\\in I$, the morphism $U_i \\to F$ is a local homeomorphism.\n    \\end{enumerate}\n\\end{defn}\n\n\\end{document}", "meta": {"hexsha": "15168864b59225248a606587d15f62739fae14ea", "size": 9107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/lecture1.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/lecture1.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/lecture1.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": 45.3084577114, "max_line_length": 658, "alphanum_fraction": 0.7001207862, "num_tokens": 2861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583169, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6852457947469384}}
{"text": "The implementation of Binomial Heaps we used, \nalong with Trees, \ncan be found in pages 68-72 of the reference book (\\cite{Okasaki}).\n\n\\subsection{Data Structure Overview}\nA Binomial Heap is an implementation of mergeable (or meldable) priority queue.\nIt uses Trees that we had to implement as well.\nLet us first see their implementation.\n\n\\subsubsection{Trees Overview}\nA Tree is simply represented as a Node with an element \n(the priority, of totally ordered type), a rank and a list of Trees as children.\nThe rank, which is $\\geq 0$, is to be understood as follows:\na Node of rank $k$ has $k$ children of ranks $k$, $k-1$, ..., $0$,\na rank $0$ meaning a Node without children.\nFrom that it comes that a Tree with a root Node of rank $k$ \ncontains in total $2^k$ elements,\nso a Tree can represent a power of two, \nlike the \\emph{k-th} bit in a binary number.\n\nThe Trees must satisfy the \\emph{Minimum Heap Property}, \nwhich means that the element of a parent Node \nis less or equal than any of its children Node's elements.\nAlso, in the implementation, the children list is maintained in decreasing order of rank.\nThese properties are thus two invariants to check on Trees,\nalong with the domain of the rank.\n\nThe \\verb|link| operation on Trees takes two Trees of rank $k$, \nmakes the one with bigger root element the first child of the other\nso that both invariants are satisfied.\nAs a result, the returned tree is of rank $k+1$.\nIt is thus like the addition of two bits of a binary number.\nThe operation is done in constant time.\n\nLet us now see how the Trees are used in the Binomial Heap implementation.\n\n\\subsubsection{Binomial Heaps Overview}\nA Binomial Heap is implemented as a list of Trees\nwhich is kept in increasing order of rank.\nThere must also not be more than one Tree of a particular rank.\nThese properties are thus invariants to check.\n \nWe can then visualize a well-formed Binomial Heap as the binary number of its size, \nwith the Trees in the list as the $1$-valued bits of the number.\n\nWith the help of the \\verb|link| operation on Trees, \nwe can see a \\verb|merge| of two Binomial Heaps \nas an addition of the two binary numbers that represent them.\nIn this view, \\verb|link| is used to add two bits of same position,\nand the result of the operation is the carry.\n\nThe other operations on Binomial Heaps are \\verb|insert|, \\verb|findMin| and \\verb|deleteMin|. \nThe \\verb|insert| operation creates a $0$-ranked Tree with the element to insert \nand puts the Tree in the Heap, using an \\verb|insertTree| function, \nalso used by \\verb|merge| to insert the carry in the recursively merged Heaps,\nat each carry step.\nThis function inserts the Tree only if its rank is smaller or equal to the smallest rank in the Tree list of the Heap \n(either it adds it to the list, either it recursively \\verb|link|s and \\verb|insertTree|s),\nso it had to be checked that the function is not called with a Tree of bigger rank in the implementation.\n\nThe \\verb|findMin| operation needs only to look for the minimum element \nin the root Nodes of the Trees in the Tree list.\nThis is because the Trees satisfy the \\emph{Minimum Heap Property}.\n\nFinally, the \\verb|deleteMin| operation finds the Tree with the minimum root in the list,\nremoves its root \nand reverses its children so that the children list is of the correct form for a Tree list of a Binomial Heap.\nAfter that, it \\verb|merge|s this new Heap with the Heap composed of \nthe remaining Trees of the original Binomial Heap.\n\nAll operation are done in amortized logarithmic time.\nLet us see now the verification of the implementations \nfor both Trees and Binomial Heaps with Leon.\n\n\\subsection{Verification With Leon}\nAs for the first data structure verification presented in this report,\n \\verb|size|, \\verb|content| and \\verb|toList| functions were used\n for pre- and post-conditions of operations,\nas well as the invariants for Trees and Binomial Heaps we saw above.\n\nUnfortunately we managed to prove only 46 properties over 53. \nWe have tried to tweak our model in order to help Leon proving some of them,\nbut unfortunately the recursive structure of Trees prevented us to reduce the number of \\verb|Unknown|s.\n\nSome tests were written for the Binomial Heaps and \nit helped to find some mistakes we made in writing the code and \nwhich were not found by Leon.\nFor example, an invariant was too strong regarding the ordering of the Trees in the Heap and \nthe error could be seen only with tests,\nwhen a precondition for an operation was not satisfied.\n\nWe had some difficulties to state the total order of the elements' type\n(\\texttt{T <: Ordered[T]} was not understood by Leon), \nso we decided to use \\verb|BigInt|s to be able to verify the data structure,\nas it can be done without loss of generality regarding the logic of the implementation.\nWe also had to adapt a bit our implementation in order to circumvent some of Leon's limitations.\nFor instance, a Heap is represented as a \\texttt{List[Tree]}. \nIt could therefore have been interested to use an implicit class to operate on such structure, \na construct that is not yet available in Leon.\n\nMoreover, our data structures used standard constructs such as lists, \nbut with some specific properties. \nIn order to enforce those properties, \nwe had to verify the invariants as \\texttt{require}s at the beginning of each \\texttt{def}. \nIt would have been nice instead to be able to write requirements directly inside \\texttt{case class}es, \nas it would have remove some boilerplate code.\n\nLeon could unfortunately not state as valid most of complicated, crucial operations, \nwhich are still \\verb|Unknown|s.", "meta": {"hexsha": "ace30f9b41e73cec8e8716f430040b6c11108598", "size": 5621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/binHeaps.tex", "max_stars_repo_name": "mdemarne/Leon-functional-datastructures", "max_stars_repo_head_hexsha": "06e457e35b257b1788965f9ac200401506fd915d", "max_stars_repo_licenses": ["MIT"], "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/binHeaps.tex", "max_issues_repo_name": "mdemarne/Leon-functional-datastructures", "max_issues_repo_head_hexsha": "06e457e35b257b1788965f9ac200401506fd915d", "max_issues_repo_licenses": ["MIT"], "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/binHeaps.tex", "max_forks_repo_name": "mdemarne/Leon-functional-datastructures", "max_forks_repo_head_hexsha": "06e457e35b257b1788965f9ac200401506fd915d", "max_forks_repo_licenses": ["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.5688073394, "max_line_length": 118, "alphanum_fraction": 0.7774417363, "num_tokens": 1319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6852457895743644}}
{"text": "\\section*{Bayesian asymptotics}\n\\begin{frame}{Asymptotics}\nA major part of a statistical approach is understanding what happens in the limit of many many observations.\nConsider the joint conditional density of the data, $f_n(\\boldsymbol{x} \\mid \\theta)$ and a prior $\\pi(\\theta)$.\nWhat happens to $p_n(\\theta \\mid \\boldsymbol{x}) = f_n(\\boldsymbol{x} \\mid \\theta)\\pi(\\theta)/m_n(\\boldsymbol{x})$ as $n \\to \\infty$ ?\n\\begin{idea}[Asymptotics is about understanding]\n Infinity is a big ``number''.\n Considering what happens  as $n \\to \\infty$ is less a statement about a real world situation than about the structure and regularity of a model.\n Doing asymptotics is about understanding what makes a model tick rather than getting useful results for a regime seldom achieved in practice.\n\\end{idea}\nAnother important aspect to consider is the \\textbf{rate} at which things converge asymptotically.\nStudying rates provides complementary information about the structure of the model and gives hints as to the accuracy of asymptotic approximations.\n \\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Bayesian asymptotics I: consistency}\n\\begin{theo}[The posterior concentrates around the ``true'' value]\nLet $(S, \\mathcal{A}, \\mu)$ be a probability space and let $(\\Omega, \\tau)$ be a finite-dimensional parameter space equipped with a Borel $\\sigma$-field.\nSuppose there exist measurable $h_n: \\mathcal{X}^n \\to \\Omega$ such that $h_n(\\boldsymbol{X})$ converges in probability to $\\Theta$.\nWriting $\\mu_{\\boldsymbol{\\Theta} \\mid \\boldsymbol{X}}(\\cdot \\mid \\boldsymbol{x})$ for the posterior measure, we have\n\\begin{equation*}\n \\lim_{n \\to \\infty} \\mu_{\\boldsymbol{\\Theta} \\mid \\boldsymbol{X}}(A \\mid \\boldsymbol{X}) = I_A(\\Theta), \\: \\mu-\\textrm{a.s.}\n\\end{equation*}\n\\end{theo}\n\\textbf{Please} see Theorem 7.78 in \\cite{Schervish1995} (pg 429) for all of the \\textit{many} details.\n\n\\textbf{Discussion:} what we are essentially saying here is that if there exists a consistent (sequence of) estimator(s) for $\\theta$, then the posterior will concentrate around the true generating distribution of the parameter asymptotically.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Remember Cromwell's law?}\nHere is another neat little theorem with a cumbersome proof.\n\\begin{theo}[A ``nice'' prior ensures posterior consistency]\nDefine $\\operatorname{KL}(\\theta, \\theta^\\prime)$ as the Kullback-Leibler divergence between $P_{\\theta}$ and $P_{\\theta^\\prime}$.\nLet $\\theta_0$ be the true data-generating parameter and define $C_\\epsilon = \\{\\theta : \\operatorname{KL}(\\theta_0, \\theta) < \\epsilon\\}$, $\\epsilon > 0$.\n Let $\\Pi$ be a prior measure such that $\\Pi(C_\\epsilon) > 0$ for every $\\epsilon > 0$.\n Take $N_0$ open such that $C_\\epsilon \\subset N_0$.\n Then \n \\begin{equation*}\n  \\lim_{n \\to \\infty} \\mu_{\\boldsymbol{\\Theta} \\mid \\boldsymbol{X}}(N_0 \\mid \\boldsymbol{X}) = 1, \\: P_{\\theta_0}-\\textrm{a.s.}\n \\end{equation*}\n\\end{theo}\nAgain, \\textbf{please} see Theorem 7.80 in \\cite{Schervish1995} (pg 430) for the details.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[allowframebreaks]{Interlude: regularity conditions}\nBefore we proceed, we will need to make things nice.\nConsider the following regularity conditions\n\\begin{itemize}\n \\item[1] The parameter space is $\\boldsymbol{\\Theta} \\subset \\mathbb{R}^d$ for some finite $d$;\n \\item[2] We have $\\theta_0$ an an interior point of $\\boldsymbol{\\Theta}$;\n \\item[3] The prior distribution has a density w.r.t. Lebesgue which is positive and continuous at $\\theta_0$;\n \\item[4] There exists $N_0 \\subseteq \\boldsymbol{\\Theta}$ with $\\theta_0 \\in N_0$ such that the log-likelihood, $l_n(\\theta)$, is twice-differentiable with respect to all coordinates of $\\theta$, $P_{\\theta}$-a.s.\n \\item[5] The largest eigenvalue of the inverse observed Fisher information, $\\Sigma_n$, vanishes in probability.\n \\item[6] The MLE is consistent;\n \\item[7] The Fisher information is a smooth function of $\\theta$.\n\\end{itemize}\n\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Bayesian asymptotics II: asymptotic normality}\nWe can now state a nice result which characterises the asymptotic form of the posterior.\n\\begin{theo}[Bernstein von-Mises\\footnote{Named after Austrian mathematician Richard Edler von Mises (1883--1953) and Russian mathematician Sergei Natanovich Bernstein (1880--1968).}]\nUnder the regularity conditions we have discussed, take $\\hat{\\theta}$ to be the MLE.\nPut $\\boldsymbol{\\Psi}_n = \\left(\\Sigma_n\\right)^{-1/2}(\\theta- \\hat{\\theta})$.\nThen the posterior distribution of $\\boldsymbol{\\Psi}_n$ conditional on $\\boldsymbol{X}$ converges in probability \\textbf{uniformly} on compact sets to the multivariate normal distribution $\\operatorname{Normal}_d\\left(\\boldsymbol{0}, \\boldsymbol{I}_d\\right)$ with density $\\phi_d$.\nMore precisely,\n\\begin{equation*}\n  \\lim_{n \\to \\infty} P_{\\theta_0}\\left(\\sup_{\\psi \\in B} \\bigg\\rvert f_{\\boldsymbol{\\Psi}_n \\mid \\boldsymbol{X}}(\\psi) - \\phi_d(\\psi)  \\bigg\\lvert > \\epsilon \\right) = 0,\n\\end{equation*}\nfor all $B \\subset \\mathbb{R}^d$ compact and $\\epsilon > 0$.\n\\end{theo}\nSee Theorem 7.89 in \\cite{Schervish1995} (page 437).\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Dabbling with normal approximations}\n\\begin{exercise}[Cauchy location posterior]\n Take $X_i \\sim \\operatorname{Cauchy}(\\theta, 1)$, $i = 1, 2,\\ldots, 10$.\n In particular, suppose $\\boldsymbol{x} = \\{-5, -3, 0, 2, 4, 5, 7, 9, 11, 14\\}$.\n \\begin{itemize}\n  \\item[i)] Compute the MLE and $l^{\\prime\\prime}$;\n  \\item[ii)] Deduce the parameters of the normal approximation to $p(\\theta \\mid \\boldsymbol{x})$;\n  \\item[iii)] Use an MCMC\\footnote{The instructor can assist with this step.} routine to sample from $p(\\theta \\mid \\boldsymbol{x})$, obtain a posterior approximation to its density and compare it to the normal approximation;\n  \\item[iv)] Simulate data sets of sizes $n=20, 50, 100, 500, 1000$ and $10, 000$ and repeat iii.\n  \\item[v)] See if you can reduce/increase the discrepancy between the posterior and its approximation by fiddling with the prior (without breaking the regularity assumptions!).\n \\end{itemize}\n\\end{exercise}\nSee example 7.104 in \\cite{Schervish1995} (page 444).\n \\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n  \\item[\\faBook] \\cite{Schervish1995} Ch. 7.4.\n%  \\item \n \\item[\\faForward] Next lecture: \\cite{Raftery1988} and~\\cite{Gelman2002}.\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "6d8bdffe942eb1028e8f700a06db576f5d9d3a33", "size": 6491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_8.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_8.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_8.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": 67.6145833333, "max_line_length": 282, "alphanum_fraction": 0.7108303805, "num_tokens": 1924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.6852457839924663}}
{"text": "\\documentclass[]{article}\n\n\\usepackage{amsmath,amssymb,amsbsy}\n\\usepackage[letterpaper,total={6in,8in}]{geometry}\n\\usepackage[colorlinks]{hyperref}\n\n\\usepackage{color}\n\n\\ifpdf\n  \\RequirePackage{graphicx}\n  \\RequirePackage{epstopdf}\n  \\DeclareGraphicsExtensions{.pdf,.jpeg,.png,.jpg}\n\\else\n  \\RequirePackage[dvipdfmx]{graphicx}\n  \\RequirePackage{bmpsize}\n  \\DeclareGraphicsExtensions{.eps,.pdf,.jpeg,.png,.jpg}\n\\fi\n\\graphicspath{{pics/},}\n\n\\RequirePackage{algorithm}\n\\RequirePackage{algorithmic}\n\\renewcommand{\\algorithmicrequire}{\\textbf{Input:}}\n\\renewcommand{\\algorithmicensure}{\\textbf{Output:}}\n\\providecommand{\\algorithmautorefname}{Algorithm}\n\n\\RequirePackage{subfigure}\n\\RequirePackage{empheq}\n\\providecommand{\\subfigureautorefname}{\\figureautorefname}\n\n%opening\n\\title{Theory Report for ``Multichannel Deconvolution of Skin Conductance Data: Concurrent Separation of Tonic and Phasic Component''}\n\\author{Yuchen Jin, Jin Lu}\n\n\\providecommand{\\od}{\\mathrm{d}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Theory}\n\nFor any channel $n$, the skin conductance (SC) could be decomposed by a phasic component and a tonic component,\n\\begin{align}\n  y_{\\rm{SC}_n}(t) = p_n(t) + s_n(t) + \\nu_n(t),\n\\end{align}\nwhere the phasic component $p_n(t)$ is stimulated by the autonomic nervous system (ANS), and the tonic component $s_n(t)$ is influenced by the thermoregulation. In this work, we will model both components by different methods. The phasic component is decomposed by a series of state-space models sharing the same input, while the tonic component is described as a combination of different spline functions. Based on the theory-based multichannel forward modeling, the stimuli from the ANS could be solved by a joint optimization. In the meanwhile, the tonic component would be extracted from the data.\n\n\\subsection{Model the phasic component with a multichannel state-space representation}\nAccording to the presumption in \\cite{alexander2005separating,society2012publication,amin2019robust}, the phasic components detected in different regions of the body are regulated by the same ANS signal, the detected phasic component for channel $n$ could be formulated by\n\\begin{align}\n  p_n(t) = \\alpha_n \\zeta_n (t),\n\\end{align}\n{\\color{red} where $\\alpha_n$ denotes the attenuation caused by the conduction of the EDA,} $\\zeta_n(t)$ is a internal variable representing the conducted signal from the same ANS. Mathematically, $\\zeta_n(t)$ is modeled by a smoothing filter applied to the neural stimuli $u(t-\\beta_n)$. The conduction delay $\\beta_n$ shows that the same stimuli would be detected at different moments. Generally, the neural stimuli could be defined as a time-series spike signal, i.e. $u(t) = \\sum_{i=1}^N q_i \\delta(t - \\Delta_i)$. Given $u(t)$, \\textit{Alexander et al.}~\\cite{alexander2005separating} provides a second-order ordinary differential equation to describe $\\zeta_n(t)$,\n\\begin{align} \\label{fml:the:ode}\n  \\tau_r \\tau_d \\frac{\\od^2 \\zeta_n(t)}{\\od t^2} + (\\tau_r + \\tau_d) \\frac{\\od \\zeta_n(t)}{\\od t} + \\zeta_n(t) = u(t - \\beta_n).\n\\end{align}\n\nThe difference between different channels in \\eqref{fml:the:ode} is only the time delay. In other words, the solutions of $\\zeta_n(t)$ for different $n$ are the same except the time delay. To solve \\eqref{fml:the:ode}, \\textit{Faghih et al.}~\\cite{faghih2015characterization} propose a state space model. Incorporating the time delay into the internal signal $\\zeta_n(t)$, we denote another internal state $x^{(n)}_2 (t)$ as $\\zeta_n(t + \\beta_n)$. The state-space model could be formulated as the following form,\n\\begin{subequations} \\label{fml:the:state-raw}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    \\dot{x}^{(n)}_1 (t) &= a x^{(n)}_1(t) + b u(t),\\\\\n    \\tau_r \\tau_d \\dot{x}^{(n)}_2 (t) &= c x^{(n)}_1(t) + d x^{(n)}_2(t), \\label{fml:the:state-raw-2}\\\\\n    y_n (t) &= \\alpha_n x^{(n)}_2(t).\n  \\end{empheq}\n\\end{subequations}\nwhere $x^{(n)}_1(t)$ is another internal state. To solve the coefficients $a, b, c, d$, we eliminate $x^{(n)}_1(t)$ in \\eqref{fml:the:state-raw-2},\n\\begin{equation} \\label{fml:the:ode-from-state}\n  \\begin{aligned}\n    \\tau_r \\tau_d \\ddot{x}_2 (t) &= c \\dot{x}^{(n)}_1(t) + d \\dot{x}^{(n)}_2(t) = c \\left(a x^{(n)}_1(t) + b u(t) \\right) + d \\dot{x}^{(n)}_2(t) \\\\\n    &= a ( \\tau_r \\tau_d \\dot{x}^{(n)}_2 (t) - d x^{(n)}_2(t) ) + bc u(t) + d \\dot{x}^{(n)}_2(t), \\\\\n    &= (a \\tau_r \\tau_d + d) \\dot{x}^{(n)}_2 (t) - a d x^{(n)}_2(t) + bc u(t).\n  \\end{aligned}\n\\end{equation}\n\nTo ensure the coherence between \\eqref{fml:the:ode} and \\eqref{fml:the:ode-from-state}, we have,\n\\begin{subequations}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    a \\tau_r \\tau_d + d &= - \\tau_r - \\tau_d,\\\\\n    ad &= 1, \\\\\n    bc &= 1. \n  \\end{empheq}\n\\end{subequations}\n\nGiven $a = -\\frac{1}{\\tau_r}$ and $b = \\frac{1}{\\tau_r}$, we could solve the above equations, and substitute the solutions into \\eqref{fml:the:state-raw},\n\\begin{subequations} \\label{fml:the:state-sing}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    \\begin{bmatrix}\n      \\dot{x}^{(n)}_1 (t) \\\\ \\dot{x}^{(n)}_2 (t)\n    \\end{bmatrix} &= \\begin{bmatrix}\n      -1/{\\tau_r} & 0 \\\\ 1/{\\tau_d} & -1/{\\tau_d}\n    \\end{bmatrix} \\begin{bmatrix}\n      x^{(n)}_1(t) \\\\ x^{(n)}_2 (t)\n    \\end{bmatrix} + \\begin{bmatrix}\n      1/{\\tau_r} \\\\ 0\n    \\end{bmatrix} u(t), \\\\\n    y_n (t) &= \\alpha_n x^{(n)}_2(t).\n  \\end{empheq}\n\\end{subequations}\n\nGiven the single-channel transmission matrix $\\phi=\\begin{bmatrix}\n-1/{\\tau_r} & 0 \\\\ 1/{\\tau_d} & -1/{\\tau_d}\n\\end{bmatrix}$, we could derive \\eqref{fml:the:state-sing} into the multichannel form. When we have $\\chi$ channels of data, the multichannel state-space model is\n\\begin{subequations} \\label{fml:the:state-mul}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    \\dot{\\mathbf{x}} (t) &= \\mathbf{A} \\mathbf{x} (t) + \\mathbf{B} u (t), \\\\\n    \\mathbf{y} (t) &= \\mathbf{C} \\mathbf{x} (t),\n  \\end{empheq}\n\\end{subequations}\nwhere $\\mathbf{x} (t) = \\begin{bmatrix}\n  x^{(1)}_1 (t) \\\\ x^{(1)}_2 (t) \\\\ \\vdots \\\\ x^{(\\chi)}_1 (t) \\\\ x^{(\\chi)}_2 (t)\n\\end{bmatrix}$, $\\mathbf{y} (t) = \\begin{bmatrix}\n  y_1 (t) \\\\ y_2 (t) \\\\ \\vdots \\\\ y_{\\chi} (t)\n\\end{bmatrix}$, $\\mathbf{A} = \\begin{bmatrix}\n  \\phi & \\mathbf{0} & \\cdots & \\mathbf{0} \\\\\n  \\mathbf{0} & \\phi & \\cdots & \\mathbf{0} \\\\\n  \\vdots & \\vdots & \\ddots & \\vdots \\\\\n  \\mathbf{0} & \\mathbf{0} & \\cdots & \\phi\n\\end{bmatrix}$, $\\mathbf{B} = \\begin{bmatrix}\n  1/{\\tau_r} \\\\ 0 \\\\ \\vdots \\\\ 1/{\\tau_r} \\\\ 0\n\\end{bmatrix}$, and\\\\$\\mathbf{C} = \\begin{bmatrix}\n  0 & \\alpha_1 & 0 & 0 & \\cdots & 0 & 0 \\\\ 0 & 0 & 0 & \\alpha_2 & \\cdots & 0 & 0 \\\\ \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\ 0 & 0 & 0 & 0 & \\cdots & 0 & \\alpha_{\\chi}\n\\end{bmatrix}$.\n\nThe above model could be rewritten as a discrete model. Denote the sampling rates of the observation and the neural stimuli as $T_y$ and $T_u$ respectively, we could formulate the discretion of the time as $t_k = k T_y$ and $\\Delta_i = i T_u$ for both signals. When $T_u$ is small enough, we could approximate the discrete neural stimuli by $\\mathbf{u} = \\begin{bmatrix}\n  q_1 & q_2 & \\cdots & q_N\n\\end{bmatrix}^T$, where we use $q_i=0$ to represent no signal at the time step $\\Delta_i$. Based on these configurations, we could derive the discrete model matrices by\n\\begin{subequations} \\label{fml:the:state-dis-mat}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    \\mathcal{A} &= \\mathcal{L}^{-1}\\{ s \\mathbf{I} - \\mathbf{A} \\}(T_u), \\\\\n    \\mathcal{B} &= \\mathbf{A}^{-1}(\\mathcal{A} - \\mathbf{I})\\mathbf{B}, \\\\\n    \\mathcal{C} &= \\mathbf{C},\n  \\end{empheq}\n\\end{subequations}\nwhere $\\mathcal{L}^{-1}$ is the inverse Laplace transform.\n\nThe discrete form of \\eqref{fml:the:state-mul} is\n\\begin{subequations} \n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    \\mathbf{x} [k+1] &= \\mathcal{A} \\mathbf{x} [k] + \\mathcal{B} \\mathbf{u} [k], \\\\\n    \\mathbf{y} [k] &= \\mathcal{C} \\mathbf{x} [k],\n  \\end{empheq}\n\\end{subequations}\n\nIn practice, we assume that $T_y = L T_u$, where $L$ is a integer. In this case, we could denote the state vector based on the sampling rate $T_y$ by $\\mathbf{z}[k] = \\mathbf{x}[Lk]$. Then we have $\\mathcal{A}_d = \\mathcal{A}^L$, $\\mathcal{B}_d = \\begin{bmatrix}\n  \\mathcal{A}^{L-1} \\mathcal{B} & \\mathcal{A}^{L-2} \\mathcal{B} & \\cdots \\mathcal{B}\n\\end{bmatrix}$, $\\mathbf{u}_d[k] = \\begin{bmatrix}\n  \\mathbf{u}[Lk] & \\mathbf{u}[Lk+1] & \\cdots \\mathbf{u}[Lk+L-1]\n\\end{bmatrix}^T$. By this way, the discrete model is finally formulated as\n\\begin{subequations} \\label{fml:the:state-dis}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{empheq}[left=\\empheqlbrace]{align}\n    \\mathbf{z} [k+1] &= \\mathcal{A}_d \\mathbf{z} [k] + \\mathcal{B}_d \\mathbf{u}_d [k], \\\\\n    \\mathbf{y} [k] &= \\mathcal{C} \\mathbf{z} [k],\n  \\end{empheq}\n\\end{subequations}\n\nSince the system is casual, we have\n\\begin{align} \\label{fml:the:out-dis}\n  \\mathbf{y}[k] = \\mathcal{F}[k] \\mathbf{z}_0 + \\mathcal{D}[k] \\mathbf{u},\n\\end{align}\nwhere $\\mathcal{F}[k] = \\mathcal{C}\\mathcal{A}_d^k$, $\\mathcal{D}[k] = \\mathcal{C} \\begin{bmatrix}\n  \\mathcal{A}_d^{k-1} \\mathcal{B}_d & \\mathcal{A}_d^{k-2} \\mathcal{B}_d & \\cdots \\mathcal{B}_d & \\mathbf{0}_{N-kL}\n\\end{bmatrix}$ and \\\\$\\mathbf{u} = \\begin{bmatrix}\n  \\mathbf{u}_d[0] & \\mathbf{u}_d[1] & \\cdots & \\mathbf{u}_d[M-1]\n\\end{bmatrix}^T$. The initial condition is configured as \\\\$\\mathbf{z}_{0} = \\mathbf{z}[0] = \\begin{bmatrix}\n  0 & y_1(0) & 0 & \\frac{y_2(0)}{\\alpha_2} & \\cdots & 0 & \\frac{y_{\\chi}(0)}{\\alpha_{\\chi}}\n\\end{bmatrix}^T$.\n\nLet $\\mathbf{y} = \\begin{bmatrix}\n\\mathbf{y}[1]^T & \\mathbf{y}[2]^T & \\cdots & \\mathbf{y}[M]^T\n\\end{bmatrix}^T$, $\\mathcal{F}_{\\boldsymbol{\\theta}} = \\begin{bmatrix}\n\\mathcal{F}[0] & \\mathcal{F}[1] & \\cdots & \\mathcal{F}[M-1]\n\\end{bmatrix}^T$ and \\\\$\\mathcal{D}_{\\boldsymbol{\\theta}} = \\begin{bmatrix}\n\\mathcal{D}[0] & \\mathcal{D}[1] & \\cdots & \\mathcal{D}[M-1]\n\\end{bmatrix}^T$, we can represent the whole multichannel phasic component by\n\\begin{align} \\label{fml:the:out-dis-all}\n  \\mathbf{y} = \\mathcal{F}_{\\boldsymbol{\\theta}} \\mathbf{z}_{0} + \\mathcal{D}_{\\boldsymbol{\\theta}} \\mathbf{u},\n\\end{align}\nwhere we use $\\boldsymbol{\\theta}$ to denote the learnable vector $\\begin{bmatrix}\n  \\tau_r & \\tau_d & \\alpha_1 & \\alpha_2 & \\cdots & \\alpha_{\\chi}\n\\end{bmatrix}^T$.\n\n\\subsection{Model the tonic component with spline functions}\n\nThe tonic signal of the $n^{\\mathrm{th}}$ channel could be viewed as the coefficients $q_n (t)$ convolved with the cubic B-spline function $\\psi(t)$,\n\\begin{align}\n  s_n(t) =  \\psi(t) \\otimes q_n (t).\n\\end{align}\n\nThe coefficients could be viewed as a time-series signal composed of several spikes, i.e. $q_n (t) = \\sum_{j=1}^N q_j \\delta(t - jT_s)$, where $T_s$ is the sampling rate of the coefficients. $T_s$ could be used to control the smoothness of the B-spline function. To ensure the smoothness, we usually use a longer period for $T_s$ like 6s. With these configurations, we could discretize the coefficients as $\\mathbf{q} = \\begin{bmatrix}\n  q_1 & q_2 & \\cdots q_n\n\\end{bmatrix}$. The convolution on $\\psi(t)$ could be formulated by a Toeplitz matrix $\\mathbf{C}$. The $k^{\\mathrm{th}}$ row of the matrix could be formulated as\n\\begin{align}\n  \\mathbf{c}_k = \\begin{bmatrix}\n    \\psi(kT_y + T_s) & \\psi(kT_y) & \\psi(kT_y - T_s) & \\cdots & \\psi(T_u - T_s)\n  \\end{bmatrix}.\n\\end{align}\nWith the discretion, we could formulate the tonic component as\n\\begin{align}\n  \\mathbf{s}_n = \\mathbf{C} \\mathbf{q}_n.\n\\end{align}\n\n\\subsection{Preprocess the data}\n\nPreprocessing aims at removing the outliers in the raw data. The whole process is shown in \\autoref{alg:preprocessing}. We find the peaks of the differentiated raw data. The searching method is based on comparing the 2 values near the center point. The data patches with outliers are all replaced by their spline approximations. Most of the outliers could be removed by this way.\n\\begin{algorithm}[tb]\n  \\caption{The preprocessing applied to the raw data.}\n  \\label{alg:preprocessing}\n  \\begin{algorithmic}[1]\n    \\REQUIRE The raw data $\\{\\mathbf{y}_{\\mathrm{SC}_n}\\}_{n=1}^\\chi$ for $\\chi$ channels.\n    \\ENSURE The preprocessed data $\\{\\hat{\\mathbf{y}}_{\\mathrm{SC}_n}\\}_{n=1}^\\chi$ for $\\chi$ channels.\n    % if-then-else\n    \\FOR{$n$ from $1$ to $\\chi$}\n      \\STATE Find the local positive and negative peaks of the differential data $\\dot{\\mathbf{y}}_{\\mathrm{SC}_n}$, where peaks means the data with a value larger than the around values by 0.1;\n      \\FORALL{founded peaks}\n        \\STATE Select 4 points near the peak, the range is limited in 100 points around the peak;\n        \\STATE Use the spline interpolation of the selected 4 points to replace the 100 points;\n      \\ENDFOR\n      \\STATE Perform the 64 order low-pass FIR filter, the cut-off frequency is 3 Hz;\n    \\ENDFOR\n  \\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Solve the deconvolution}\n\nAfter modeling the data by the aforementioned two methods, we could formulate the $n^{\\mathrm{th}}$ channel of the SC data as follows,\n\\begin{align}\n  \\mathbf{y}_n = \\mathcal{F}_{\\boldsymbol{\\theta}_n} \\mathbf{z}_{0} + \\mathcal{D}_{\\boldsymbol{\\theta}_n} \\mathbf{u} + \\mathbf{C} \\mathbf{q}_n + \\boldsymbol{\\nu},\n\\end{align}\nwhere $\\boldsymbol{\\theta}_n = \\begin{bmatrix}\n\\tau_r & \\tau_d & \\alpha_n\n\\end{bmatrix}^T$ is the subset of the learnable vector $\\boldsymbol{\\theta}$, and $\\mathbf{q}_n$ is the decomposition coefficients of the $n^{\\mathrm{th}}$ tonic component. For the phasic decomposition, the coefficients, i.e. the neural stimuli $\\mathbf{u}$ is shared, and the model parameters are not totally shared crossing the channels. For the tonic decomposition, the modeling function $\\mathbf{C}$ is shared crossing the channels, while the coefficients $\\mathbf{q}_n$ are different among different channels.\n\nThe multichannel deconvolution with the tonic separation could be formulated by the following constrained joint optimization problem,\n\\begin{subequations} \\label{fml:the:optimization}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{align}\n    \\arg\\min\\limits_{\\substack{\\boldsymbol{\\theta},~\\mathbf{u}, \\\\ \\{\\mathbf{q}_n\\}_{n=1}^{\\chi}, \\\\ \\lambda,~\\mu}} & \\frac{1}{\\chi} \\left( \\sum_{n=1}^{\\chi} \\mathcal{J}(\\boldsymbol{\\theta}_n,~\\mathbf{u},~\\mathbf{q}_n) + \\mu \\lVert \\mathbf{q}_n \\rVert_2^2 \\right) + \\lambda \\lVert \\mathbf{u} \\rVert^p_p, \\\\\n    \\mathrm{s.t.}~&\\mathcal{J}(\\boldsymbol{\\theta}_n,~\\mathbf{u},~\\mathbf{q}_n) = \\lVert \\mathbf{y}_n - \\mathcal{F}_{\\boldsymbol{\\theta}_n} \\mathbf{z}_{0} - \\mathcal{D}_{\\boldsymbol{\\theta}_n} \\mathbf{u} - \\mathbf{C} \\mathbf{q}_n \\rVert^2_2, \\label{fml:loss-channel}\\\\\n    & \\boldsymbol{\\Gamma} \\boldsymbol{\\theta} \\preccurlyeq \\mathbf{b},~ \\mathbf{u} \\succcurlyeq \\mathbf{0} \\label{fml:cons-phasic}\\\\\n    & \\forall~n,~\\mathbf{C}\\mathbf{q}_n \\preccurlyeq \\mathbf{y}_n, \\label{fml:cons-tonic}\n  \\end{align}\n\\end{subequations}\nwhere \\eqref{fml:loss-channel} represents the loss function for the $n^{\\mathrm{th}}$ channel, \\eqref{fml:cons-phasic} is the constraint of the phasic decomposition, and \\eqref{fml:cons-tonic} is the constraint of the tonic extraction. In \\eqref{fml:cons-phasic}, the Tikhonov matrix $\\boldsymbol{\\Gamma}$ and the boundary vector $\\mathbf{b}$ are defined as\n\\begin{subequations} \\label{fml:the:constraint}\n  \\renewcommand{\\theequation}\n  {\\theparentequation-\\arabic{equation}}\n  \\begin{align}\n    \\boldsymbol{\\Gamma} &= \\begin{bmatrix}\n      1 & -1 & 0 & 0 & \\cdots & 0 & 0 \\\\\n      0 & 0 & 1 & -1 & \\cdots & 0 & 0 \\\\\n      \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n      0 & 0 & 0 & 0 & \\cdots & 1 & -1\n    \\end{bmatrix}, \\\\\n    \\mathbf{b} &= \\begin{bmatrix}\n      1.4 & -0.1 & 6.0 & -1.5 & 100.0 & -0.01 & \\cdots & 100.0 & -0.01\n    \\end{bmatrix}^T\n  \\end{align}\n\\end{subequations}\n\nConventionally, it is difficult to decide the proper the regularization coefficients $\\lambda,~\\mu$. In our work, we take the optimization of the coefficients into the consideration. The optimization is based on Focal Underdetermined System Solver (FOCUSS+) algorithm~\\cite{murray2005visual}, while the estimation of the tunable regularization coefficients is based on  generalized cross-validation (GCV) method~\\cite{zdunek2008improved}. \n\nThe whole algorithm for the optimization is discussed in \\autoref{alg:deconvolution}. The optimization could be divided into an outer loop and an inner loop. In the outer loop, we solve the modeling parameters $\\boldsymbol{\\theta}$. The deconvolution and with the tonic extraction is performed in the inner loop.\n\\begin{algorithm}[!tb]\n  \\caption{The preprocessing applied to the raw data.}\n  \\label{alg:deconvolution}\n  \\begin{algorithmic}[1]\n    \\REQUIRE The preprocessed multichannel data $\\{\\hat{\\mathbf{y}}_{\\mathrm{SC}_n}\\}_{n=1}^\\chi$, the decomposition coefficients $\\mathbf{u}, \\{\\mathbf{q}_{n}\\}_{n=1}^\\chi$, and the initialized parameters $\\boldsymbol{\\theta}$, where $\\tau_d \\sim U(0.10,~1.4)$, $\\tau_r \\sim U(1.5,~6.0)$, $\\alpha_n \\sim U(0.01,~1.0)$, $\\mathbf{u} \\sim 0$, and $\\mathbf{q}_n \\sim \\mathcal{N}(0.1, 0.02)$.\n    % if-then-else\n    \\FOR {$j$ from $1$ to $30$}\n      \\STATE Let $\\boldsymbol{\\theta},~\\{\\mathbf{q}_{n}\\}$ fixed, use FOCUSS+ to solve $\\tilde{\\mathbf{u}}^{(j)}$. Set $\\mathbf{u} = \\tilde{\\mathbf{u}}^{(j)}$;\n      \\STATE Let $\\mathbf{u},~\\{\\mathbf{q}_{n}\\}$ fixed, solve $\\tilde{\\boldsymbol{\\theta}}^{(j)}$ by the interior method. Set $\\boldsymbol{\\theta} = \\tilde{\\boldsymbol{\\theta}}^{(j)}$;\n      \\STATE Let $\\boldsymbol{\\theta},~\\mathbf{u}$ fixed, use FOCUSS+ to solve $\\{\\tilde{\\mathbf{q}}_{n}\\}^{(j)}$. Set $\\{\\mathbf{q}_{n}\\} = \\{\\tilde{\\mathbf{q}}_{n}\\}^{(j)}$;\n    \\ENDFOR\n    \\STATE Initialize $\\hat{\\boldsymbol{\\theta}}^{(0)}=\\boldsymbol{\\theta}$, $\\hat{\\mathbf{u}}^{(0)}=\\mathbf{u}$, $\\{\\hat{\\mathbf{q}}_{n}\\}^{(0)}=\\{\\mathbf{q}_{n}\\}$;\n    \\FOR{$i$ from $0$ until converge}\n      \\STATE Let $\\boldsymbol{\\theta},~\\{\\mathbf{q}_{n}\\}$ fixed, solve $\\hat{\\mathbf{u}}^{(j)}$ by the following steps;\n      \\STATE Let $\\hat{\\lambda}^{(i)(0)} = 2 \\times 10^{-3}$,\n      \\FOR{$m$ from $1$ until converge}\n        \\STATE Let $\\lambda = \\hat{\\lambda}^{(i)(m-1)}$, $\\boldsymbol{\\theta},~\\{\\mathbf{q}_{n}\\}$ fixed, use FOCUSS+ to solve $\\hat{\\mathbf{u}}^{(i)(m)}$. Set $\\mathbf{u} = \\hat{\\mathbf{u}}^{(i)(m)}$;\n        \\STATE Let $\\mathbf{u},~\\boldsymbol{\\theta}~\\{\\mathbf{q}_{n}\\}$ fixed, use FOCUSS+ to solve $\\hat{\\lambda}^{(i)(m)}$. Set $\\lambda = \\hat{\\lambda}^{(i)(m)}$;\n      \\ENDFOR\n      \\STATE Set $\\hat{\\mathbf{u}}^{(i)} = \\hat{\\mathbf{u}}^{(i)(m)}$.\n      \\STATE Let $\\hat{\\mu}^{(i)(0)} = 2 \\times 10^{-3}$,\n      \\FOR{$m$ from $1$ until converge}\n        \\STATE Let $\\mu = \\hat{\\mu}^{(i)(m-1)}$, $\\boldsymbol{\\theta},\\mathbf{u}$ fixed, use FOCUSS+ to solve $\\{\\hat{\\mathbf{q}}_{n}\\}^{(i)(m)}$. Set $\\{\\mathbf{q}_{n}\\} = \\{\\hat{\\mathbf{q}}_{n}\\}^{(i)(m)}$;\n        \\STATE Let $\\mathbf{u},~\\boldsymbol{\\theta}~\\{\\mathbf{q}_{n}\\}$ fixed, use FOCUSS+ to solve $\\hat{\\mu}^{(i)(m)}$. Set $\\mu = \\hat{\\mu}^{(i)(m)}$;\n      \\ENDFOR\n      \\STATE Set $\\{\\hat{\\mathbf{q}}_{n}\\}^{(i)} =  \\{\\hat{\\mathbf{q}}_{n}\\}^{(i)(m)}$.\n    \\ENDFOR\n  \\end{algorithmic}\n\\end{algorithm}\n\n\\bibliographystyle{ieeetr}\n\\bibliography{ref}\n\n\\end{document}\n", "meta": {"hexsha": "3e7d024154b4622ee3a7bf5ddfaaddadf88fcc43", "size": 19632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "note-theory.tex", "max_stars_repo_name": "cainmagi/Deconv-for-SS-estimation", "max_stars_repo_head_hexsha": "66b2f8231e7f0045306af8cb2d3f03c102fd354f", "max_stars_repo_licenses": ["MIT"], "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-theory.tex", "max_issues_repo_name": "cainmagi/Deconv-for-SS-estimation", "max_issues_repo_head_hexsha": "66b2f8231e7f0045306af8cb2d3f03c102fd354f", "max_issues_repo_licenses": ["MIT"], "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-theory.tex", "max_forks_repo_name": "cainmagi/Deconv-for-SS-estimation", "max_forks_repo_head_hexsha": "66b2f8231e7f0045306af8cb2d3f03c102fd354f", "max_forks_repo_licenses": ["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.9230769231, "max_line_length": 670, "alphanum_fraction": 0.6662591687, "num_tokens": 7113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6852185992609433}}
{"text": "\\documentclass[../Notes/main.tex]{subfiles}\n\n\\begin{document}\n\\section{Geometry}\n\\subsection{Vectors/Points}\n\\lstinputlisting[firstline=2]{vector2D/vector2D.cpp}\n\n\\subsection{Calculate Areas}\n\\subsubsection{Integration via Simpson's Method}\n\\lstinputlisting[firstline=2]{simpsonsMethod/simpsonsMethod.cpp}\n\n\\subsubsection{Green's Theorem}\n\\lstinputlisting[firstline=2]{greenTheorem/greenTheorem.cpp}\n\n\\subsection{Pick's Theorem}\nGiven a simple polygon (no self intersections) in a lattice such that all vertices are grid points. Pick's theorem relates the Area \\(A\\), points inside of the polygon \\(i\\) and the points of the border of the polygon \\(b\\), in the following way:\n\\begin{equation*}\n    A=i+\\frac{b}2-1\n\\end{equation*}\n\n\\end{document}", "meta": {"hexsha": "f1e142b9c18698ba8a55219132aca7b758532218", "size": 745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geometry/geometry.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": "geometry/geometry.tex", "max_issues_repo_name": "ignaciohermosillacornejo/apuntes_icpc", "max_issues_repo_head_hexsha": "0cf8935931c776f2899c03f79d4dcc6c09b81373", "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": "geometry/geometry.tex", "max_forks_repo_name": "ignaciohermosillacornejo/apuntes_icpc", "max_forks_repo_head_hexsha": "0cf8935931c776f2899c03f79d4dcc6c09b81373", "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": 35.4761904762, "max_line_length": 246, "alphanum_fraction": 0.7758389262, "num_tokens": 202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6852149561135515}}
{"text": "\\chapter{Summary}\n\\label{ch:summary}\n\\begin{figure}\n  \\centering\n  \\inputTikZ{figures/overview}\n  \\caption{Overview over the various important concepts, equations and adaptive filters covered in these lecture notes.}\n  \\label{fig:overview}\n\\end{figure}\n\\noindent Fig.~\\ref{fig:overview} shows an overview over the various important concepts, equations and adaptive filters covered in these lecture notes. All relationships indicated by the arrows have been covered with the exception of the arrow from the steepest descent block to the NLMS block. The interested reader may establish this relationship by solving Problem 1 of Chapter 6 in \\cite{Haykin2001}.\n\nTable~\\ref{tab:summary} shows a summary of the adaptive filters covered in these lecture notes. Most the expressions for the mean-square stability, the excess mean-square error (EMSE), the misadjustment, and the mean-square deviation (MSD) are approximations, and they can therefore only be used as a rule of thumb. For more accurate expressions see the description of the adaptive filters and the references therein.\n\n\\begin{sidewaystable}\n  \\centering\n  \\small\n  \\begin{tabular}{@{}Sl Sr<{ = }@{ }Sl Sc Sc Sc Sc Sc Sc@{}}\n    \\toprule\n    Name & \\multicolumn{2}{c}{Algorithm} & Cost & Mean-Square Stability & EMSE & Misadjustment & MSD\\\\\n    \\midrule\n    SD  & $\\vect{g}(\\vect{w}(n))$ & $2\\vect{R}_u\\vect{w}(n)-2\\vect{r}_{ud}(n)$       & $\\mathcal{O}(M)$   & $0 < \\mu < \\displaystyle\\frac{2}{\\lambda_\\textup{max}}$ & 0 & 0 & 0\\\\\n        & $\\vect{w}(n+1)$         & $\\vect{w}(n)-\\displaystyle\\frac{\\mu}{2}\\vect{g}(\\vect{w}(n))$ &      & & & &\\\\[4mm]\n    LMS & $e(n)$                  & $d(n)-\\vect{u}^T(n)\\vect{w}(n)$                 & $\\mathcal{O}(M)$   & $0 < \\mu < \\displaystyle\\frac{2}{\\tr{\\vect{R}_u}}$ & $\\displaystyle\\frac{\\mu}{2}J_\\textup{min}\\tr{\\vect{R}_u}$ & $\\displaystyle\\frac{\\mu}{2}\\tr{\\vect{R}_u}$ & $\\displaystyle\\frac{\\mu}{2}J_\\textup{min}M$\\\\\n        & $\\vect{w}(n+1)$         & $\\vect{w}(n)+\\mu\\vect{u}(n)e(n)$                &                    & & & &\\\\[4mm]\n    NLMS& $e(n)$                  & $d(n)-\\vect{u}^T(n)\\vect{w}(n)$                 & $\\mathcal{O}(M)$   & $0 < \\beta < 2$& $\\displaystyle\\frac{\\beta}{2}J_\\textup{min}$ & $\\displaystyle\\frac{\\beta}{2}$ & $\\displaystyle\\frac{\\beta J_\\textup{min}}{2\\tr{\\vect{R}_u}}$\\\\\n        & $\\vect{w}(n+1)$         & $\\vect{w}(n)+\\displaystyle\\frac{\\beta}{\\epsilon+\\|\\vect{u}(n)\\|^2}\\vect{u}(n)e(n)$ & & & & &\\\\[4mm]\n    APA & $\\vect{e}(n)$           & $\\vect{d}(n)-\\vect{U}^T(n)\\vect{w}(n)$          & $\\mathcal{O}(MK^2)$& $0 < \\beta < 2$&$\\displaystyle\\frac{\\beta}{2}J_\\textup{min}K$ & $\\displaystyle\\frac{\\beta}{2}K$ & no simple expression\\\\\n        & $\\vect{w}(n+1)$         & \\multicolumn{2}{@{}Sl}{$\\vect{w}(n)+\\beta\\vect{U}(n)[\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n)]^{-1}\\vect{e}(n)$} & & & &\\\\[4mm]\n    RLS & $\\vect{\\pi}(n)$         & $\\vect{P}(n-1)\\vect{u}(n)$                      & $\\mathcal{O}(M^2)$ & $0 < \\lambda \\leq 1$&$\\displaystyle\\frac{J_\\textup{min}\\frac{1-\\lambda}{1+\\lambda}M}{1-\\frac{1-\\lambda}{1+\\lambda}M}$ & $\\displaystyle\\frac{\\frac{1-\\lambda}{1+\\lambda}M}{1-\\frac{1-\\lambda}{1+\\lambda}M}$ & $\\displaystyle\\frac{J_\\textup{min}\\frac{1-\\lambda}{1+\\lambda}M}{1-\\frac{1-\\lambda}{1+\\lambda}M}\\sum_{m=1}^M\\frac{1}{\\lambda_m}$\\\\\n        & $\\vect{k}(n)$           & $\\displaystyle\\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)$           & \\multicolumn{2}{@{}Sl}{$\\lambda^{-1}\\left[\\vect{P}(n-1)-\\vect{k}(n)\\vect{\\pi}^T(n)\\right]$}& & & &\\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Overview over the basic adaptive filters and their properties. Most of the expressions for the mean-square stability, the excess mean-square error (EMSE), the misadjustment, and the mean-square deviation (MSD) are approximations.}\n  \\label{tab:summary}\n\\end{sidewaystable}\n", "meta": {"hexsha": "0c645d3dc73cf4a81229f1860506dd069684b2fc", "size": 4080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/lectures/summary.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/summary.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/summary.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": 107.3684210526, "max_line_length": 441, "alphanum_fraction": 0.574754902, "num_tokens": 1431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.6852149374856524}}
{"text": "\\documentclass{article}\n\\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}\n\\usepackage{amsmath}\n\\begin{document}\n    \\subsection*{Nonhomogeneous linear equation solution set} \n    The solution of the nonhomogeneous linear equation is consist of two parts; one is a any special solution, and the other is the general solution of the homogeneous linear equation. That means: \n    \\begin{equation}\n        Soltion\\ Set = \\{Special\\ Solution + General\\ Solution\\}\n    \\end{equation}\n    \\subsection*{Range}\n    The range of a matrix (A) is the column space of the matrix. \n    \\subsection*{Diagonalizable matrix}\n    If a n-dimension matrix can be diagonalized, it must have n eigenvectors, which are independent with each other. \n\n    Precedure: \n    \\begin{enumerate}\n        \\item Find its eigenvalues $\\lambda_1$, $\\lambda_2$, $\\cdots$, $\\lambda_m$;\n        \\item Find the correspoding eigenvectors $\\vec{a_1}$, $\\vec{a_2}$, $\\cdots$, $\\vec{a_n}$; \n        \\item $V=\\{\\vec{a_1}, \\cdots, \\vec{a_n}\\}$; \n        \\item $A=V\\ diag(\\lambda_1, \\cdots, \\lambda_m)\\ V^{-1}$. \n    \\end{enumerate}\n    \\subsection*{Inverse matrix}\n    \\begin{enumerate}\n        \\item $\\{A|I\\}\\Rightarrow\\{I|A^{-1}\\}$; \n        \\item $A^{-1}=\\frac{A^{*}}{|A|}$, $A^{*}$ is adjugate matrix. \n    \\end{enumerate}\n    \\subsection*{Orthogonal complement}\n    \\begin{itemize}\n        \\item Row $(A)^{\\perp}=$ Null $(A)$;\n        \\item Range $(A)^{\\perp}=$ Null $(A^{T})$. \n    \\end{itemize}\n    \\subsection*{Geometric multiplicity and algebraic multiplicity}\n    \\begin{itemize}\n        \\item Geometric multiplicity of $\\lambda$ is the dimension of the Null($A-\\lambda I$); \n        \\item Algebraic multiplicity of $\\lambda$ is the number of times $\\lambda$ appears in the equation $|\\lambda I-A|=0$. \n        \\item Geometric multiplicity is always not exceed Algebraic multiplicity; And all algebraic multiplicities of different eigenvalues sum up should be n (for a n$\\times$n matrix); \n        \\item if every Geometric multiplicity equals to Algebraic multiplicity, we say that the matrix is diagonalizable. \n    \\end{itemize}\n    \\subsection*{Vandermonde matrix}\n    \\begin{equation*}\n        V=\\left(\\begin{matrix}\n            1 & x_0 & x_0^2 & \\cdots & x_0^n\\\\\n            1 & x_1 & x_1^2 & \\cdots & x_1^n\\\\\n            \\vdots & \\vdots & \\vdots &  & \\vdots\\\\\n            1 & x_n & x_n^2 & \\cdots &x_n^n\n        \\end{matrix}\\right)\n    \\end{equation*}\n    \\begin{equation*}\n        V\\Rightarrow\\left(\\begin{matrix}\n            1 & 0 & 0 & \\cdots & 0\\\\\n            1 & x_1-x_0 & x_1(x_1-x_0) & \\cdots & x_1^{n-1}(x_1-x_0)\\\\\n            \\vdots & \\vdots & \\vdots &  & \\vdots\\\\\n            1 & x_n-x_0 & x_n(x_n-x_0) & \\cdots &x_n^{n-1}(x_n-x_0)\n        \\end{matrix}\\right)\n    \\end{equation*}\n    \\begin{equation*}\n        \\det(V)=\\left|\\begin{matrix}\n             x_1-x_0 & x_1(x_1-x_0) & \\cdots & x_1^{n-1}(x_1-x_0)\\\\\n             \\vdots & \\vdots &  & \\vdots\\\\\n             x_n-x_0 & x_n(x_n-x_0) & \\cdots &x_n^{n-1}(x_n-x_0)\n        \\end{matrix}\\right|=(x_n-x_0)\\cdots(x_1-x_0)\\left|\\begin{matrix}\n            1 & x_1 & x_1^2 & \\cdots & x_1^n\\\\\n            1 & x_2 & x_2^2 & \\cdots & x_2^n\\\\\n            \\vdots & \\vdots & \\vdots &  & \\vdots\\\\\n            1 & x_n & x_n^2 & \\cdots &x_n^n\n        \\end{matrix}\\right|\n    \\end{equation*}\n    \\begin{equation*}\n        \\det(V)=\\prod_{0\\leq i<j\\leq n}(x_j-x_i)\n    \\end{equation*}\n    \\subsection*{Characteristic polynomial}\n    The characteristic polynomial of a matrix A is $|A-\\lambda I|$. \n    \\subsection*{Representing linear transformations by matrices}\n    For a transformation T and a basis a, it can be represented by a matrix T as follows: \n    \\begin{equation*}\n        T(x)=Tx=x^{T}T^T,\\ T=\\{T(a_1),\\cdots,T(a_n)\\}^T\n    \\end{equation*}\n    \\subsection*{Vector projection}\n    For a vector u, the projection of u on v is as follows: \n    \\begin{equation*}\n        a_1=\\frac{<u,v>}{<v,v>}v\n    \\end{equation*}\n    So, the projection of u on a plane with normal vector v is as follows:\n    \\begin{equation*}\n        a_2=u-a_1\n    \\end{equation*}\n    So, the reflection of u on a plane with normal vector v is as follows:\n    \\begin{equation*}\n        a_2=u-2a_1\n    \\end{equation*}\n    \\subsection*{Dimension formula}\n    \\begin{equation*}\n        \\dim(V_1+V_2)=\\dim(V_1)+\\dim(V_2)-\\dim(V_1\\cap V_2)\n    \\end{equation*}\n    \\subsection*{Rotation and reflection}\n    For a transformation, if its matrix is orthogonal and the determinant is 1, then, it is a Rotation. Otherwise, if the determinant is -1, then, it is a reflection. \n    \\begin{equation*}\n        \\left(\\begin{matrix}\n            \\cos(\\theta)&-\\sin(\\theta)\\\\\n            \\sin(\\theta)&\\cos(\\theta)\n        \\end{matrix}\\right)\n    \\end{equation*}\n    \\subsection*{Gram–Schmidt process}\n    For a basis $(\\alpha_1,\\cdots,\\alpha_n)$, the orthogonal basis can be gotten with the following steps: \n    \\begin{enumerate}\n        \\item $\\beta_1=\\alpha_1$; \n        \\item $\\beta_2=\\alpha_2-k\\beta_1$, $k=\\frac{<\\alpha_2,\\beta_1>}{<\\beta_1, \\beta_1>}$; \n        \\item $\\cdots \\cdots$\n        \\item $\\beta_n=\\alpha_n-k_1\\beta_1-k_2\\beta_2-\\cdots-k_{n-1}\\beta_{n-1}$, $k_{i}=\\frac{<\\alpha_n,\\beta_i>}{<\\beta_i,\\beta_i>}$. \n    \\end{enumerate}\n\\end{document}", "meta": {"hexsha": "e972295396582490625f3cb3182ae55e1644c960", "size": 5248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Placement test/Sallybus.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": "Placement test/Sallybus.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": "Placement test/Sallybus.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": 47.2792792793, "max_line_length": 197, "alphanum_fraction": 0.603277439, "num_tokens": 1796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891435927269, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6851504404593842}}
{"text": "\\chapter{Merge Sort}\n\\label{chap:merge_sort}\n\\index{merge sort|(}\n\\index{sorting|see{merge sort}}\n\n\\cite{Knuth_1996} reports that the first computer program, designed\nin~\\oldstylenums{1945} by the mathematician John von~Neumann, was a\nsorting algorithm, nowadays called \\emph{merge sort}. It is amongst\nthe most widely taught sorting algorithms because it illustrates the\nimportant solving strategy known as `\\emph{divide and\n  conquer}'\\index{divide and conquer}: the input is split, each\nnon\\hyp{}trivial part is recursively processed and the partial\nsolutions are finally combined to form the complete solution.  While\nmerge sort is not difficult to program, finding its cost requires\nadvanced mathematical knowledge. Most\ntextbooks \\citep{GrahamKnuthPatashnik_1994,CLRS_2009} show how to find\nthe order of growth of an upper bound of the cost (expressed by means\nof Bachmann's notation \\(\\mathcal{O}\\)) from recurrences it satisfies,\nbut the general case is often not presented in the main chapters, or\nnot at all, because a precise asymptotic solution requires skills in\n\\emph{analytic combinatorics} \\citep{FlajoletSedgewick_2001,\n  FlajoletSedgewick_2009, FlajoletGolin_1994, Hwang_1998,\n  ChenHwangChen_1999}. Moreover, there are several variants of merge\nsort \\citep{Knuth_1998,GolinSedgewick_1993} and often the only one\nintroduced, called \\emph{top\\hyp{}down}, is illustrated on arrays. We\nshow in this chapter that stacks, as a purely functional data\nstructure \\citep{Okasaki_1998b}, are suitable both for a top\\hyp{}down\nand a \\emph{bottom\\hyp{}up} approach of merge\nsort \\citep{PannyProdinger_1995}.\n\n\n\\section{Merging}\n\\label{sec:merging}\n\\index{merge sort!merging|(}\n\nJohn von~Neumann did not actually described merge sort, but its basic\noperation, \\emph{merging}, which he named \\emph{meshing}. Merging\nconsists in combining two ordered stacks of keys into one ordered\nstack. Without loss of generality, we shall be only interested in\nsorting keys in increasing order. For instance, merging \\([10,12,17]\\)\nand \\([13,14,16]\\) results in \\([10,12,13,14,16,17]\\). One way to\nachieve this consists in comparing the two smallest keys, output the\nsmallest and repeat the procedure until one of the stacks becomes\nempty, in which case the other is wholly appended. We have (compared\nkeys underlined):\n\\begin{equation*}\n\\left\\{\n\\begin{aligned}\n&\\underline{10}~12~17\\\\\n&\\underline{13}~14~16\n\\end{aligned}\n\\right.\n\\rightarrow 10\n\\left\\{\n\\begin{aligned}\n&\\underline{12}~17\\\\\n&\\underline{13}~14~16\n\\end{aligned}\n\\right.\n\\rightarrow 10~12\n\\left\\{\n\\begin{aligned}\n&\\underline{17}\\\\\n&\\underline{13}~14~16\n\\end{aligned}\n\\right.\n\\rightarrow 10~12~13\n\\left\\{\n\\begin{aligned}\n&\\underline{17}\\\\\n&\\underline{14}~16\n\\end{aligned}\n\\right.\n%\\quad\\text{etc.}\n\\end{equation*}\nThe function \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} (\\emph{merge}) in\n\\fig~\\vref{fig:mrg}\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{mrg}(\\el,t)         & \\xrightarrow{\\smash{\\theta}} & t;\\\\\n\\fun{mrg}(s,\\el)         & \\xrightarrow{\\smash{\\iota}} & s;\\\\\n\\fun{mrg}(\\cons{x}{s},\\cons{y}{t}) & \\xrightarrow{\\smash{\\kappa}}\n& \\cons{y}{\\fun{mrg}(\\cons{x}{s},t)},\\;\\text{if \\(x \\succ y\\)};\\\\\n\\fun{mrg}(\\cons{x}{s},t) & \\xrightarrow{\\smash{\\lambda}}\n                         & \\cons{x}{\\fun{mrg}(s,t)}.\n\\end{array}}\n\\end{equation*}\n\\caption{Merging two stacks\\label{fig:mrg}\n\\index{merge sort!merging!program}}\n\\end{figure}\nimplements this scheme. Rule~\\(\\iota\\) is not necessary but is\nretained because it allows the cost to be symmetric, just as\n\\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} is: \\(\\C{\\fun{mrg}}{m,n} =\n\\C{\\fun{mrg}}{n,m}\\)\\index{mrg@$\\C{\\fun{mrg}}{m,n}$} and\n\\(\\fun{mrg}(s,t) \\equiv \\fun{mrg}(t,s)\\), where \\(m\\)~and~\\(n\\) are\nthe lengths of~\\(s\\) and~\\(t\\). This property enables easier cost\ncalculations and faster computations. Note that in the definition of\n\\fun{cat/2}\\index{cat@\\fun{cat/2}} (equation~\\eqref{def:cat} on\npage~\\pageref{def:cat}), we do not include a similar rule,\n\\(\\fun{cat}(s,\\el) \\rightarrow s\\), because, despite the gain in\nspeed, the function is asymmetric and cost calculations are simplified\nwhen using \\(\\C{\\fun{cat}}{n}\\)\\index{cat@$\\C{\\fun{cat}}{n}$} rather\nthan \\(\\C{\\fun{cat}}{m,n}\\). \\Fig~\\vref{fig:mrg_247} shows a\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n  \\fun{mrg}([3,4,7],[1,2,5,6])\n& \\xrightarrow{\\smash{\\kappa}}\n& \\cons{1}{\\fun{mrg}([3,4,7],[2,5,6])}\\\\\n& \\xrightarrow{\\smash{\\kappa}}\n& \\cons{1,2}{\\fun{mrg}([3,4,7],[5,6])}\\\\\n& \\xrightarrow{\\smash{\\lambda}}\n& \\cons{1,2,3}{\\fun{mrg}([4,7],[5,6])}\\\\\n& \\xrightarrow{\\smash{\\lambda}}\n& \\cons{1,2,3,4}{\\fun{mrg}([7],[5,6])}\\\\\n& \\xrightarrow{\\smash{\\kappa}}\n& \\cons{1,2,3,4,5}{\\fun{mrg}([7],[6])}\\\\\n& \\xrightarrow{\\smash{\\kappa}}\n& \\cons{1,2,3,4,5,6}{\\fun{mrg}([7],\\el)}\\\\\n& \\xrightarrow{\\smash{\\iota}}\n& [1,2,3,4,5,6,7].\n\\end{array}}\n\\end{equation*}\n\\caption{\\(\\fun{mrg}([3,4,7],[1,2,5,6]) \\twoheadrightarrow\n  [1,2,3,4,5,6,7]\\)\\label{fig:mrg_247} \\index{merge\n    sort!merging!example}\\index{functional language!evaluation!trace}}\n\\end{figure}\ntrace for \\fun{mrg/2}. Rules \\(\\kappa\\)~and~\\(\\lambda\\) involve a\ncomparison, while \\(\\theta\\)~and~\\(\\iota\\) do not and end the\nevaluations; therefore, if\n\\(\\OC{\\fun{mrg}}{m,n}\\)\\index{mrg@$\\OC{\\fun{mrg}}{m,n}$} is the number\nof comparisons to merge with \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} two\nstacks of lengths \\(m\\)~and~\\(n\\), we have\\index{mrg@$\\C{\\fun{mrg}}{m,n}$}\n\\begin{equation}\n\\C{\\fun{mrg}}{m,n} = \\OC{\\fun{mrg}}{m,n} + 1.\\label{def:cost_mrg}\n\\end{equation}\nIn order to gain some generality, we shall study\n\\(\\OC{\\fun{mrg}}{m,n}\\). Graphically, we represent a key from one\nstack as a \\emph{white node} \\((\\circ)\\) and a key from the other as a\n\\emph{black node} \\((\\bullet)\\). Nodes of these kinds are printed in a\nhorizontal line, the leftmost being the smallest. Comparisons are\nalways performed between black and white nodes and are represented as\n\\emph{edges} in% \\fig~\\vref{fig:merged}.\n%\\begin{figure}\n%\\centering\n\\begin{equation}\n\\includegraphics[bb=73 710 292 718]{merged}%[bb=73 702 292 724]\n\\label{fig:merged}\n\\end{equation}\n%\\caption{Two ordered stacks merged into one\\label{fig:merged}}\n%\\end{figure}\nAn incoming arrow means that the node is smaller than the other end of\nthe edge, so all edges point leftwards and the number of comparisons\nis the number of nodes with an incoming edge.\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Minimum cost}\n\\label{merge:best_case}\n\\index{merge sort!merging!minimum cost|(}\n\nThere are two consecutive white nodes without any edges at the right\nend, which suggests that the more keys from one stack we have at the\nend of the result, the fewer comparisons we needed for merging: the\nminimum number is achieved when \\emph{the shorter stack comes first in\n  the result}. Consider the following example (the number of\ncomparisons is the number of black nodes):\n\\begin{center}\n\\includegraphics[bb=73 698 292 724]{min_mrg}\n\\end{center}\nThe minimum number of comparisons\n\\(\\OB{\\fun{mrg}}{m,n}\\)\\index{mrg@$\\OB{\\fun{mrg}}{m,n}$} when merging\nstacks of size \\(m\\)~and~\\(n\\) is\n\\begin{equation}\n\\OB{\\fun{mrg}}{m,n} = \\min\\{m,n\\}.\\label{eq:best_merge}\n\\end{equation}\n\\index{merge sort!merging!minimum cost|)}\n\n\\paragraph{Maximum cost}\n\\index{merge sort!merging!maximum cost|(}\n\nWe can see that we can increase the number of comparisons with respect\nto \\(m+n\\) by removing, in~\\eqref{fig:merged}, those rightmost\nnodes in the result \\emph{that are not compared}, as can be seen in\n\\begin{center}\n\\includegraphics[bb=73 702 258 724]{max_mrg2}\n\\end{center}\nThis maximises comparisons because all nodes, but the last, are the\ndestination of an edge. The maximum number of comparisons\n\\(\\OW{\\fun{mrg}}{m,n}\\)\\index{mrg@$\\OW{\\fun{mrg}}{m,n}$} is\n\\begin{equation}\n\\OW{\\fun{mrg}}{m,n} = m + n - 1.\\label{eq:worst_merge}\n\\end{equation}\nInterchanging the two rightmost nodes in the previous example leaves\n\\(m+n-1\\) invariant:\n\\begin{center}\n\\includegraphics[bb=71 700 260 726]{max_mrg1}\n\\end{center}\nso the maximum number of comparisons occurs when \\emph{the last two\n  keys of the result come from two stacks.}\n\\index{merge sort!merging!maximum cost|)}\n\n\n\\paragraph{Average cost}\n\\index{merge sort!merging!average cost|(}\n\nLet us seek the average number of comparisons in all distinct mergers\nof two stacks of lengths \\(m\\)~and~\\(n\\). Consider\n\\fig~\\vref{fig:mean_mrg1},\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=66 648 350 725]{mean_mrg1}\n\\caption{All possible mergers with \\(m=3\\) (\\(\\circ\\)) and \\(n=2\\)\n  (\\(\\bullet\\))\n\\label{fig:mean_mrg1}}\n\\end{figure}\nwith \\(m=3\\) white nodes and \\(n=2\\) black nodes which are interleaved\nin all possible manners. Note how the figure is structured. The first\ncolumn lists the configurations where the rightmost black node is the\nlast of the result. The second column lists the cases where the\nrightmost black node is the penultimate node of the result. The third\ncolumn is divided in two groups itself, the first of which lists the\ncases where the rightmost black node is the antepenultimate. The total\nnumber of comparisons is~\\(35\\) and the number of configurations\nis~\\(10\\), thus the average number of comparisons is \\(35/10 =\n7/2\\).\\label{seven_two} Let us devise a method to find this ratio for\nany \\(m\\)~and~\\(n\\). First, the number of configurations: how many\nways are there to combine \\(m\\)~white nodes and \\(n\\)~black nodes?\nThis is the same as asking how many ways there are to paint in black\n\\(n\\)~nodes picked amongst \\(m+n\\) white nodes. More abstractly, this\nis equivalent to wonder how many ways there are to choose\n\\(n\\)~objects amongst \\(m+n\\). This number is called a \\emph{binomial\n  coefficient}\\index{binomial coefficient} and noted\n\\(\\binom{m+n}{n}\\). For example, let us consider the set\n\\(\\{a,b,c,d,e\\}\\) and the \\emph{combinations}\\index{combination} of\n\\(3\\)~objects taken from it are\n\\begin{gather*}\n\\{a,b,c\\},\\{a,b,d\\},\\{a,b,e\\},\\{a,c,d\\},\\{a,c,e\\},\\{a,d,e\\},\\\\\n\\{b,c,d\\},\\{b,c,e\\},\\{b,d,e\\},\\\\\n\\{c,d,e\\}.\n\\end{gather*}\nThis enumeration establishes that \\(\\binom{5}{3} = 10\\). Notice that\nwe use mathematical sets, therefore the order of the elements or their\nrepetition are not meaningful. It is not difficult to count the\ncombinations if we recall how we counted the permutations,\n\\vpageref{par:permutations}. Let us determine \\(\\binom{r}{k}\\). We can\npick the first object amongst~\\(r\\), the second amongst \\(r-1\\)\netc. until we pick the \\(r\\)th object amongst \\(r-k+1\\), so there are\n\\(r(r-1)\\dots(r-k+1)\\) choices. But these arrangements contain\nduplicates, for example, we may form \\(\\{a,b,c\\}\\) and \\(\\{b,a,c\\}\\),\nwhich are to be considered identical combinations because order does\nnot matter. Therefore, we must divide the number we just obtained by\nthe number of redundant arrangements, which is the number of\npermutations of \\(k\\)~objects, that is, \\(k!\\). In the end:\n\\begin{equation*}\n\\binom{r}{k} := \\frac{r(r-1)\\ldots(r-k+1)}{k!} =\n\\frac{r!}{k!(r-k)!}.\n\\end{equation*}\nWe can check now that in \\fig~\\vref{fig:mean_mrg1}, we must have\n\\(10\\)~cases: \\(\\binom{5}{2} = 5!/(2!3!) = 10\\). The symmetry of the\nproblem means that merging a stack of \\(m\\)~keys with a stack of~\\(n\\)\nleads to exactly the same results as merging a stack of \\(n\\)~keys\nwith a stack of \\(m\\)~keys:\n\\begin{equation*}\n\\binom{m+n}{n} = \\binom{m+n}{m}.\n%\\label{eq:comb_m_n}\n\\end{equation*}\nThis can also be easily proved by means of the definition:\n\\begin{equation*}\n\\binom{m+n}{n} := \\frac{(m+n)!}{n!(m+n-n)!} =\n\\frac{(m+n)!}{m!n!} =: \\binom{m+n}{m}.\n\\end{equation*}\nThe total number \\(K(m,n)\\) of comparisons needed to merge~\\(m\\) and\n\\(n\\)~keys in all possible manners with our algorithm is the number of\nnodes with incoming edges. Let \\(\\overline{K}(m,n)\\) be the total\nnumber of nodes \\emph{without} incoming edges, circled in\n\\fig~\\ref{fig:mean_mrg2}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=66 625 252 730]{mean_mrg2}\n\\caption{Counting vertically\\label{fig:mean_mrg2}}\n\\end{figure}\nThis figure has been obtained by moving the third column of\n\\fig~\\vref{fig:mean_mrg1} below the second column and by removing the\nedges. Since, for each merger, there are \\(m+n\\) nodes and each has an\nincoming edge or not, and because there are \\(\\binom{m+n}{n}\\)\nmergers, we have\n\\begin{equation}\nK(m,n) + \\overline{K}(m,n) = (m + n) \\binom{m+n}{n}.\n\\label{eq:KoverK}\n\\end{equation}\nIt is simple to characterise the circled nodes: they make up the\nlongest, rightmost contiguous series of nodes of the same\ncolour. Since there are only two colours, the problem of determining\nthe total number \\(W(m,n)\\) of white circled nodes is symmetric to the\ndetermination of the total number \\(B(m,n)\\) of black circled nodes,\nthat is,\n\\begin{equation*}\nB(m,n) = W(n,m).\n\\end{equation*}\nTherefore,\n\\begin{equation}\n\\overline{K}(m,n) = W(m,n) + B(m,n) = W(m,n) + W(n,m).\n\\label{eq:K}\n\\end{equation}\nFrom equations~\\eqref{eq:KoverK} and~\\eqref{eq:K}, we draw\n\\begin{equation}\nK(m,n) = (m + n) \\binom{m+n}{n} - W(m,n) - W(n,m).\n\\label{eq:K_temp}\n\\end{equation}\nWe can decompose \\(W(m,n)\\) by counting the circled white nodes\n\\emph{vertically}. In \\fig~\\ref{fig:mean_mrg2}, \\(W(3,2)\\) is the sum\nof the numbers of mergers with at least one, two and three ending\ncircled white nodes: \\(W(3,2) = 1 + 3 + 6 = 10\\). The first column\nyields \\(B(3,2) = 1 + 4 = 5\\). In general, the number of mergers with\none ending circled white node is the number of ways to combine\n\\(n\\)~black nodes with \\(m-1\\) white nodes: \\(\\binom{n+m-1}{n}\\). The\nnumber of mergers with at least two ending white nodes is\n\\(\\binom{n+m-2}{n}\\), etc.\n\\begin{equation*}\nW(m,n)\n  = \\binom{n+m-1}{n} + \\binom{n+m-2}{n} + \\dots + \\binom{n+0}{n}\n  = \\!\\sum_{j=0}^{m-1}{\\!\\binom{n+j}{n}}.\n\\end{equation*}\nThis sum can actually be simplified, more precisely, it has a closed\nform, but in order to understand its underpinnings, we need firstly to\ndevelop our intuition about combinations. By computing combinations\n\\(\\binom{r}{k}\\) for small values of~\\(r\\) and~\\(k\\) using the\ndefinition, we can fill a table traditionally known as \\emph{Pascal's\n  triangle}\\index{Pascal's triangle} and displayed in\n\\fig~\\vref{fig:pascal_triangle}.\n\\begin{figure}\n\\centering\n\\includegraphics{pascal}\n\\caption{The corner of Pascal's triangle (in boldface type)\n\\label{fig:pascal_triangle}}\n\\end{figure}\nNote how we set the convention \\(\\binom{r}{k} = 0\\) if \\(k >\nr\\). Pascal's triangle features many interesting properties relative\nto the sum of some of its values. For instance, if we choose a number\nin the triangle and look at the one on its right, then the one below\nthe latter is their sum. For the sake of illustration, let us extract\nfrom \\fig~\\vref{fig:pascal_triangle} the lines \\(r=7\\) and \\(r=8\\):\n\\begin{center}\n\\begin{tabular}{||c|c||rrrrrrrrrr||}\n\\cline{5-6}\\cline{8-9}\n      & 7 & \\textbf{1} & \\textbf{7} & \\multicolumn{1}{|c}{\\textbf{21}} & \\multicolumn{1}{c|}{\\textbf{35}} &  \\textbf{35} &  \\multicolumn{1}{|c}{\\textbf{21}} & \\multicolumn{1}{c|}{\\textbf{7}} &  \\textbf{1} & 0 & 0\\\\\n\\cline{5-5}\\cline{8-8}\n      & 8 & \\textbf{1} & \\textbf{8} & \\textbf{28} & \\multicolumn{1}{|c|}{\\textbf{56}} &  \\textbf{70} &  \\textbf{56} & \\multicolumn{1}{|c|}{\\textbf{28}} &  \\textbf{8} & \\textbf{1} & 0\\\\\n\\cline{6-6}\\cline{9-9}\n\\end{tabular}\n\\end{center}\nWe surrounded two examples of the additive property of combinations we\ndiscussed: \\(21 + 35 = 56\\) and \\(21 + 7 = 28\\). We would then bet\nthat\n\\begin{equation*}\n\\binom{r-1}{k-1} + \\binom{r-1}{k} = \\binom{r}{k}.\n\\end{equation*}\nThis is actually not difficult to prove if we go back to the\ndefinition:\n\\begin{align*}\n\\binom{r}{k} &:= \\frac{r!}{k!(r-k)!}\n              = \\frac{r}{k} \\cdot \\frac{(r-1)!}{(k-1)!((r-1)-(k-1))!}\n              = \\frac{r}{k} \\binom{r-1}{k-1}.\\\\\n\\binom{r}{k} &:= \\frac{r!}{k!(r-k)!}\n              = \\frac{r}{r-k} \\cdot \\frac{(r-1)!}{k!((r - 1) - k)!}\n              = \\frac{r}{r-k} \\binom{r-1}{k}.\n\\end{align*}\nThe first equality is valid if \\(k > 0\\) and the second if \\(r \\neq\nk\\). We can now replace \\(\\binom{r-1}{k-1}\\) and \\(\\binom{r-1}{k}\\) in\nterms of \\(\\binom{r}{k}\\) in the sum\n\\begin{equation*}\n\\binom{r-1}{k-1} + \\binom{r-1}{k} = \\frac{k}{r}\\binom{r}{k}\n+ \\frac{r-k}{r}\\binom{r}{k} = \\binom{r}{k}.\n\\end{equation*}\nThe sum is valid if \\(r > 0\\). There is direct proof of the formula by\nenumerative combinatorics without algebra. Let us suppose that we\n\\emph{already} have all the subsets of \\(k\\)~keys chosen\namong~\\(r\\). By definition, there are \\(\\binom{r}{k}\\) of them. We\nchoose to distinguish an arbitrary key amongst~\\(r\\) and we want to\ngroup the subsets in two sets: on one side, all the combinations\ncontaining this particular key, on the other side, all the\ncombinations without it. The former subset has cardinal\n\\(\\binom{r-1}{k-1}\\) because its combinations are built from the fixed\nkey and further completed by choosing \\(k-1\\) remaining keys amongst\n\\(r-1\\). The latter subset is made of \\(\\binom{r-1}{k}\\) combinations\nwhich are made from \\(r-1\\) keys, of which \\(k\\)~have to be selected\nbecause we ignore the distinguished key. This yields the same additive\nformula. Now, let us return to our pending sum\n\\begin{equation*}\nW(m,n) = \\sum_{j=0}^{m-1}{\\binom{n+j}{n}}.\n\\end{equation*}\n\n% Wrapping figure better declared before a paragraph\n%\n\\begin{wrapfigure}[6]{l}[0pt]{0pt}\n% 6 vertical lines\n% left placement\n% 0pt of margin overhang\n\\centering\n\\includegraphics[bb=73 650 110 721]{triangle1}%[... 721]\n\\end{wrapfigure}\nIn terms of navigation across Pascal's triangle, we understand that\nthis sum operates on numbers in the same column. More precisely, it\nstarts from the diagonal with the number \\(\\binom{n}{n} = 1\\) and goes\ndown until a total of \\(m\\)~numbers have been added. So let us choose\na simple example and fetch two adjacent columns were the sum is\nsmall. On the left is an excerpt for \\(n=4\\) (the left column is the\nfifth in Pascal's triangle) and \\(m=4\\) (height of the left\ncolumn). Interestingly, the sum of left column, which is the sum under\nstudy, equals the number at the bottom of the second column: \\(1 + 5 +\n15 + 35 = 56\\). By checking other columns, we may feel justified to\nthink that this is a general pattern. Before attempting a general\nproof, let us see how it may work on our particular example. Let us\nstart from the bottom of the second column, that is, \\(56\\), and use\nthe addition formula in reverse, that is, express \\(56\\) as the sum of\nthe numbers in the row above it: \\(56 = 35 + 21\\).  We would like to\nkeep~\\(35\\) because it is part of the equality to prove. So let us\napply the addition formula again to \\(21\\) and draw \\(21 = 15 +\n6\\). Let us keep \\(15\\) and resume the same procedure on \\(6\\) so \\(6\n= 5 + 1\\). Finally, \\(1 = 1 + 0\\). We just checked \\(56 = 35 + (15 +\n(5 + (1 + 0)))\\), which is exactly what we wanted. Because we want the\nnumber corresponding to \\(35\\) in our example to be\n\\(\\binom{n+m-1}{n}\\), we have the derivation\n\\begin{align}\n\\binom{n+m}{n+1}\n  &= \\binom{n+m-1}{n} + \\binom{n+m-1}{n+1}\\notag\\\\\n  &= \\binom{n+m-1}{n} + \\left[\\binom{n+m-2}{n} +\n     \\binom{n+m-2}{n+1}\\right]\\notag\\\\\n  &= \\binom{n+m-1}{n} + \\binom{n+m-2}{n} + \\dots +\n     \\left[\\binom{n}{n} + \\binom{n}{n+1}\\right],\\notag\\\\\n\\binom{n+m}{n+1}\n  &= \\sum_{j=0}^{m-1}{\\binom{n+j}{n}} = W(m,n).\n\\label{eq:binom_sum}\n\\end{align}\nNow, we can replace this closed form in equation~\\eqref{eq:K_temp}\n\\vpageref{eq:K_temp} so\\index{K@$K(m,n)$}\n\\begin{equation*}\nK(m,n) = (m + n)\n\\binom{m+n}{n} - \\binom{m+n}{n+1} - \\binom{m+n}{m+1}.\n\\end{equation*}\nBy definition, the average number of comparisons\n\\(\\OM{\\fun{mrg}}{m,n}\\)\\index{mrg@$\\OM{\\fun{mrg}}{m,n}$} is the ratio\nof \\(K(m,n)\\) by \\(\\binom{m+n}{n}\\), therefore\n\\begin{equation}\n\\OM{\\fun{mrg}}{m,n} = m + n - \\frac{m}{n+1} - \\frac{n}{m+1}\n  = \\frac{mn}{m+1} + \\frac{mn}{n+1}.\n\\label{eq:Amrg}\n\\end{equation}\nSince we necessarily expect \\(\\OB{\\fun{mrg}}{m,n} \\leqslant\n\\OM{\\fun{mrg}}{m,n} \\leqslant \\OW{\\fun{mrg}}{m,n}\\), we may wonder if\nand when the bounds are tight. For the upper bound to be tight, we\nneed \\((m,n)\\) to satisfy the equation \\(m^2 + n^2 - mn = 1\\), whose\nonly natural solutions are \\((0,1)\\), \\((1,0)\\) and \\((1,1)\\). For the\nlower bound to be tight, we must have \\(mn/(m+1) + mn/(n+1) =\n\\min\\{m,n\\}\\), whose only natural solutions are \\((0,n)\\), \\((m,0)\\)\nand \\((1,1)\\). Furthermore, the cases \\((m,1)\\) and \\((1,n)\\) may\nsuggest that merging one key with others is equivalent to inserting\nthat key amongst the others, as we did with straight insertion in\nsection~\\ref{sec:straight_ins} \\vpageref{sec:straight_ins}. In other\nwords, we expect the theorem\n\\begin{equation}\n\\fun{ins}(x,s) \\equiv \\fun{mrg}([x],s).\n\\label{eq:ins_mrg}\n\\index{ins@\\fun{ins/2}}\\index{mrg@\\fun{mrg/2}}\n\\end{equation}\nTherefore, \\emph{insertion is a special case of merging.}\nNevertheless, the average costs are not exactly the same. First, we\nhave \\(\\M{\\fun{mrg}}{m,n} = \\OM{\\fun{mrg}}{m,n} + 1\\), because we need\nto account for using once either rule~\\(\\theta\\) or~\\(\\iota\\) in\n\\fig~\\ref{fig:mrg}, as we already acknowledged by\nequation~\\eqref{def:cost_mrg}. Then, equations~\\eqref{eq:ins}\n\\vpageref{eq:ins} and~\\eqref{eq:Amrg} yield\n\\begin{equation*}\n\\M{\\fun{mrg}}{1,n} = \\frac{1}{2}{n} + 2 - \\frac{1}{n+1}\n\\quad\\text{and}\\quad\n\\M{\\fun{ins}}{n} = \\frac{1}{2}{n} + 1.\n\\index{ins@$\\M{\\fun{ins}}{n}$}\\index{mrg@$\\M{\\fun{mrg}}{1,n}$}\n\\end{equation*}\nAsymptotically, they are equivalent:\n\\begin{equation*}\n\\M{\\fun{mrg}}{1,n} \\sim \\M{\\fun{ins}}{n}.\n\\end{equation*}\nBut \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} is slightly slower in average\nthan \\fun{ins/2}\\index{ins@\\fun{ins/2}} in this special case:\n\\begin{equation*}\n\\M{\\fun{mrg}}{1,n} - \\M{\\fun{ins}}{n} = 1 - \\frac{1}{n+1} < 1\n\\quad\\text{and}\\quad\n\\M{\\fun{mrg}}{1,n} - \\M{\\fun{ins}}{n} \\sim 1.\n\\end{equation*}\nAlso, it may be interesting to see what happens when \\(m=n\\), that is,\nwhen the two stacks to be merged have the same length:\n\\begin{equation}\n\\M{\\fun{mrg}}{n,n} = 2n - 1 + \\frac{2}{n+1} = \\W{\\fun{mrg}}{n,n} - 1 +\n\\frac{2}{n+1} \\sim 2n.\\index{mrg@$\\M{\\fun{mrg}}{n,n}$}\n\\label{eq:Amrg_n_n}\n\\end{equation}\nIn other words, the average cost of merging two stacks of identical\nlength is asymptotically the total number of keys being merged, which\nis the worst case.\n\\index{merge sort!merging!average cost|)}\n\n\\paragraph{Termination}\n\\label{merging_termination}\n\\index{merge sort!merging!termination|(}\n\nThe termination of \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} in\n\\fig~\\vref{fig:mrg} is easy to prove by considering a lexicographic\norder\\index{induction!lexicographic order}\n(page~\\pageref{par:ackermann}) on pairs of stacks which are, in turn,\npartially ordered by the immediate subterm\nrelation\\index{induction!immediate subterm order}\n(page~\\pageref{par:well-founded}), or, more restrictively, the\n\\emph{immediate substack relation}\\index{induction!immediate substack\n  order}, that is, \\(\\cons{x}{s} \\succ s\\). The dependency\npairs\\index{termination!dependency pair} of rules\n\\(\\kappa\\)~and~\\(\\lambda\\) are ordered by \\((\\cons{x}{s},\\cons{y}{t})\n\\succ (\\cons{x}{s},t)\\) and \\((\\cons{x}{s},t) \\succ\n(s,t)\\).\\index{merge sort!merging!termination|)}\\index{merge\n  sort!merging|)}\\hfill\\(\\Box\\)\n\n\\section{Sorting $2^n$ keys}\n\\label{sec:power_of_two}\n\\index{merge sort!power@$2^n$ keys|(}\n\nMerging can be used to sort \\emph{one} stack of keys as follows. The\ninitial stack of keys is split in two, then the two pieces are split\nagain etc. until singletons remain. These are then merged pairwise\netc. until only one stack remains, which is inductively sorted, since\na singleton stack is a sorted stack on its own and\n\\(\\fun{mrg}(s,t)\\)\\index{mrg@\\fun{mrg/2}} is sorted if~\\(s\\) and~\\(t\\)\nare. The previous scheme leaves open the choice of a splitting\nstrategy and, perhaps, the most intuitive way is to cut in two halves,\nwhich works well in the case of \\(2^p\\)~keys. We will see in later\nsections how to deal with the general case and with a different\nsplitting strategy. For now, let us consider in\n\\fig~\\vref{fig:bot_up1}\n\\begin{figure}\n\\centering\n\\includegraphics{bot_up1}\n\\caption{Sorting \\([7,3,5,1,6,8,4,2]\\)\n\\label{fig:bot_up1}}\n\\end{figure}\nall the mergers and their relative order to sort the stack \\([7, 3, 5,\n  1, 6, 8, 4, 2]\\). We name this structure a \\emph{merge\n  tree}\\index{merge sort!merge tree|see{tree}}\\index{tree!merge\n  $\\sim$}, because each node of the tree is a sorted stack, either a\nsingleton or the merger of its two children. The root logically holds\nthe result. The merge tree is best understood from a bottom\\hyp{}up,\nlevel by level examination. Let us note \\(\\C{\\Join}{p}\\) the number of\ncomparisons to sort \\(2^p\\)~keys and consider a merge tree with\n\\(2^{p+1}\\)~leaves. It is made of two immediate subtrees with\n\\(2^p\\)~leaves and the root holds \\(2^{p+1}\\)~keys. Therefore\n\\begin{equation*}\n\\C{\\Join}{0} = 0,\n\\quad\n\\C{\\Join}{p+1} = 2 \\cdot \\C{\\Join}{p} + \\OC{\\fun{mrg}}{2^p,2^p}.\n\\end{equation*}\nUnrolling the recursion, we arrive at\n\\begin{equation}\n\\C{\\Join}{p+1}\n  = 2^p\\sum_{k=0}^p{\\frac{1}{2^k}\\OC{\\fun{mrg}}{2^k,2^k}}.\n\\index{mrg@$\\C{\\Join}{n}$}\n\\label{eq:cost_power_2}\n\\end{equation}\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Minimum cost}\n\\index{merge sort!power@$2^n$ keys!minimum cost|(}\n\nWhen the given stack is already sorted, either in increasing or\ndecreasing order, the number of comparisons is minimum. In fact, given\na minimum\\hyp{}comparison merge tree\\index{tree!merge $\\sim$}, any\nexchange of two subtrees whose roots are merged leaves the number of\ncomparisons invariant. This happens because the merge tree is built\nbottom\\hyp{}up and the number of comparisons is a symmetric\nfunction. Let us note \\(\\B{\\Join}{p}\\) the minimum number of\ncomparisons to sort \\(2^p\\)~keys. From equations\n\\eqref{eq:cost_power_2} and \\eqref{eq:best_merge},\n\\begin{equation}\n%\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\B{\\Join}{p}\n  = 2^{p-1}\\!\\sum_{k=0}^{p-1}{\\frac{1}{2^k}\\OB{\\fun{mrg}}{2^k,2^k}}\n  = p2^{p-1}.\\label{eq:best_power}\\index{mrg@$\\B{\\Join}{n}$}\n\\end{equation}\n\\index{merge sort!power@$2^n$ keys!minimum cost|)}\n\n\\paragraph{Maximum cost}\n\\index{merge sort!power@$2^n$ keys!maximum cost|(}\n\nJust as with the best case, constructing a maximum\\hyp{}comparison\nmerge sort is achieved by making worst cases for all the subtrees, for\nexample, \\([7,3,5,1,4,8,6,2]\\). Let~\\(\\W{\\Join}{p}\\) be the maximum\nnumber of comparisons for sorting \\(2^p\\)~keys. From equations\n\\eqref{eq:cost_power_2}~and~\\eqref{eq:worst_merge},\n\\begin{equation}\n%\\abovedisplayskip=2pt\n\\belowdisplayskip=0pt\n\\W{\\Join}{p}\n  = 2^{p-1}\\!\\sum_{k=0}^{p-1}{\\frac{1}{2^k}\\OW{\\fun{mrg}}{2^k,2^k}}\n  = (p-1)2^p + 1.\n\\label{eq:worst_power}\\index{mrg@$\\W{\\Join}{n}$}\n\\end{equation}\n\\index{merge sort!power@$2^n$ keys!maximum cost|)}\n\n\\paragraph{Average cost}\n\\index{merge sort!power@$2^n$ keys!average cost|(}\n\\label{par:Atms_2p}\n\nFor a given stack, all permutations of which are equally likely, the\naverage cost of sorting it by merging is obtained by considering the\naverage costs of all the subtrees of the merge tree: all the\npermutations of the keys are considered for a given length. Therefore,\nequation~\\eqref{eq:cost_power_2} is satisfied by\n\\(\\OM{\\fun{mrg}}{2^k,2^k}\\) and \\(\\M{\\Join}{p}\\)\n\\index{mrg@$\\M{\\Join}{n}$}, that is, the average number of comparisons\nfor sorting \\(2^p\\)~keys. Equations~\\eqref{eq:Amrg_n_n}\nand~\\eqref{def:cost_mrg} yield\n\\begin{equation*}\n%\\abovedisplayskip=2pt\n%\\belowdisplayskip=2pt\n\\OM{\\fun{mrg}}{n,n} = 2n - 2 + \\frac{2}{n+1}.\n\\index{mrg@$\\OM{\\fun{mrg}}{n,n}$}\n\\end{equation*}\nTogether with equation \\eqref{eq:cost_power_2}, we further draw, for\n\\(p > 0\\),\n\\begin{align}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\M{\\Join}{p}\n  &= 2^{p-1}\\sum_{k=0}^{p-1}{\\frac{1}{2^k}\\OM{\\fun{mrg}}{2^k,2^k}}\n  = 2^p\\sum_{k=0}^{p-1}{\\frac{1}{2^k}\\left(2^k - 1 + \\frac{1}{2^k +\n      1}\\right)}\\notag\\\\\n  &= 2^{p}\\left(p - \\sum_{k=0}^{p-1}{\\frac{1}{2^k}}\n     + \\sum_{k=0}^{p-1}{\\frac{1}{2^k(2^k+1)}}\\right)\\notag\\\\\n  &= 2^{p}\\left(p - \\sum_{k=0}^{p-1}{\\frac{1}{2^k}}\n     + \\sum_{k=0}^{p-1}\\left(\\frac{1}{2^k}\n     - \\frac{1}{2^k+1}\\right)\\!\\!\\right)\n   = p2^p - 2^p \\sum_{k=0}^{p-1}\\frac{1}{2^k+1}\\notag\\\\\n  &= p2^p - 2^p \\sum_{k \\geqslant 0}\\frac{1}{2^k+1}\n     + 2^p \\sum_{k \\geqslant p}\\frac{1}{2^k+1}\n= p2^p - \\alpha 2^p + \\sum_{k \\geqslant 0}\\frac{1}{2^{k}+2^{-p}},\n\\label{eq:Mjoin}\n\\end{align}\nwhere \\(\\alpha := \\sum_{k \\geqslant 0}\\frac{1}{2^k+1} \\simeq\n1.264500\\) is irrational \\citep{Borwein_1992}. Since \\(0 < 2^{-p} <\n1\\), we have \\(1/(2^k + 1) < 1/(2^k+2^{-p}) < 1/2^k\\) and we conclude\n\\begin{equation}\n(p - \\alpha)2^p + \\alpha < \\M{\\Join}{p} < (p-\\alpha)2^p + 2.\n\\label{ineq:M_join}\n\\end{equation}\nThe uniform convergence of the series \\(\\sum_{k \\geqslant\n  0}\\frac{1}{2^{k}+2^{-p}}\\) allows us to interchange the limits\non~\\(k\\) and~\\(p\\) and deduce that \\(\\M{\\Join}{p} - (p-\\alpha)2^p - 2\n\\to 0^{-}\\), as \\(p \\to \\infty\\). In other words,\n\\(\\M{\\Join}{p}\\) is best approximated by its upper bound, for\nsufficiently large values of~\\(p\\).\n\\index{merge sort!power@$2^n$ keys!average cost|)}\n\\index{merge sort!power@$2^n$ keys|)}\n\n\\section{Top-down merge sort}\n\\index{merge sort!top-down $\\sim$|(}\n\nWhen generalising the fifty\\hyp{}fifty splitting rule to an arbitrary\nnumber of keys, thus obtaining stacks of lengths \\(\\floor{n/2}\\) and\n\\(\\ceiling{n/2}\\), we obtain the variant of merge sort called\n\\emph{top\\hyp{}down}. The corresponding program is shown in\n\\fig~\\vref{fig:tms}\\index{merge sort!top-down $\\sim$!program}.\n\\begin{figure}[!b]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{tms}(\\cons{x,y}{t}) & \\rightarrow\n                         & \\fun{cutr}([x],\\cons{y}{t},t);\\\\\n\\fun{tms}(t)             & \\rightarrow & t.\\\\\n\\\\\n\\fun{cutr}(s,\\cons{y}{t},\\cons{a,b}{u})\n                       & \\rightarrow & \\fun{cutr}(\\cons{y}{s},t,u);\\\\\n\\fun{cutr}(s,t,u)        & \\rightarrow\n                         & \\fun{mrg}(\\fun{tms}(s),\\fun{tms}(t)).\\\\\n\\\\\n\\fun{mrg}(\\el,t)         & \\rightarrow & t;\\\\\n\\fun{mrg}(s,\\el)         & \\rightarrow & s;\\\\\n\\fun{mrg}(\\cons{x}{s},\\cons{y}{t}) & \\rightarrow\n                         & \\cons{y}{\\fun{mrg}(\\cons{x}{s},t)},\\;\n                           \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mrg}(\\cons{x}{s},t) & \\rightarrow & \\cons{x}{\\fun{mrg}(s,t)}.\n\\end{array}}\n\\end{equation*}\n\\caption{Top-down merge sort with \\fun{tms/1}\\label{fig:tms}}\n\\end{figure}\nNote that the call \\(\\fun{cutr}(s,t,u)\\)\\index{cutr@\\fun{cutr/3}}\nreverses the first half of~\\(t\\) on top of~\\(s\\) if~\\(s=t\\). The\ntechnique consists in starting with \\(s=\\el\\) and projecting the keys\nof~\\(t\\) one by one and those of~\\(u\\) two by two, so when\n\\(\\fun{cutr}(s,t,\\el)\\) or \\(\\fun{cutr}(s,t,[y])\\) are reached, we\nknow that \\(t\\)~is the second half of the original stack and \\(s\\)~is\nthe reversed first half (of length \\(\\floor{n/2}\\) if \\(n\\)~is the\nlength of the original stack). In the first rule of~\\fun{tms/1}, we\nsaved one recursive call to \\fun{cutr/3} and some memory by calling\n\\(\\fun{cutr}([x],\\cons{y}{t}, t)\\) instead of\n\\(\\fun{cutr}(\\el,\\cons{x,y}{t},\\cons{x,y}{t})\\). Moreover, this way,\nthe second rule implements the two base cases, \\(\\fun{tms}(\\el)\\) and\n\\(\\fun{tms}([y])\\). Furthermore, notice that, in the second rule of\n\\fun{cutr/2}, if~\\(u = \\el\\), then the length of the original stack is\neven and if \\(u = [a]\\), then it is odd. One possible drawback of\n\\fun{tms/1}\\index{tms@\\fun{tms/1}} is that the sort is\n\\emph{unstable}, that is, the relative order of equal keys is not\ninvariant.\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\nSince all comparisons are performed by\n\\fun{mrg/2}\\index{mrg@\\fun{mrg/2}}, the definition of\n\\fun{tms/1}\\index{tms@\\fun{tms/1}} implies that the number of\ncomparisons satisfies\n\\begin{equation}\n\\OC{\\fun{tms}}{0} = \\OC{\\fun{tms}}{1} = 0,\n\\qquad\n\\OC{\\fun{tms}}{n} = \\OC{\\fun{tms}}{\\floor{n/2}}\n+ \\OC{\\fun{tms}}{\\ceiling{n/2}}\n+ \\OC{\\fun{mrg}}{\\floor{n/2},\\ceiling{n/2}}.\n\\index{tms@$\\OC{\\fun{tms}}{n}$}\n\\label{eq:cost_tms}\n\\end{equation}\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\\mypar{Minimum cost}\n\\index{merge sort!top-down $\\sim$!minimum cost|(}\n\nThe minimum number of comparisons satisfies\n\\begin{equation*}\n%\\abovedisplayskip=0pt\n\\OB{\\fun{tms}}{0} = \\OB{\\fun{tms}}{1} = 0,\n\\;\n\\OB{\\fun{tms}}{n} = \\OB{\\fun{tms}}{\\floor{n/2}}\n+ \\OB{\\fun{tms}}{\\ceiling{n/2}}\n+ \\OB{\\fun{mrg}}{\\floor{n/2},\\ceiling{n/2}}.\n\\index{mrg@\\fun{mrg/2}}\n\\index{tms@$\\OB{\\fun{tms}}{n}$}\n\\end{equation*}\n% Wrapping figure better declared before a paragraph\n%\n{\\setlength{\\intextsep}{0pt} % No space before and after a figure\n\\begin{wrapfigure}[22]{r}[0pt]{0pt}\n% 22 vertical lines (3 for each display)\n% mandatory right placement (better because of a list)\n% 0pt of margin overhang\n\\centering\n\\includegraphics[bb=71 435 149 721]{bits}\n\\caption{\\label{fig:bits}}\n%\\caption{Binary numbers from \\(1\\) to \\(n\\)\\label{fig:bits}}\n\\end{wrapfigure}\nWe have \\(\\OB{\\fun{tms}}{n} = \\OB{\\fun{tms}}{\\floor{n/2}} +\n\\OB{\\fun{tms}}{\\ceiling{n/2}} + \\floor{n/2}\\), using\nequation~\\eqref{eq:best_merge}\n\\vpageref{eq:best_merge}.\\index{tms@$\\OB{\\fun{tms}}{n}$} In particular\n\\begin{equation*}\n\\OB{\\fun{tms}}{2p} = 2 \\cdot \\OB{\\fun{tms}}{p} + p,\\quad\n\\OB{\\fun{tms}}{2p+1} = \\OB{\\fun{tms}}{p} + \\OB{\\fun{tms}}{p+1} + p.\n\\end{equation*}\nLet us introduce the difference of two successive terms, \\(\\Delta_n :=\n\\OB{\\fun{tms}}{n+1} - \\OB{\\fun{tms}}{n}\\), so \\(\\Delta_0 = 0\\), and\nfind some constraints on it. Because of the floor and ceiling\nfunctions of~\\(n/2\\), we consider two complementary cases.\n\\begin{itemize}\n\n \\item \\(\\Delta_{2p} = \\OB{\\fun{tms}}{2p+1} - \\OB{\\fun{tms}}{2p} =\n  \\OB{\\fun{tms}}{p+1} - \\OB{\\fun{tms}}{p} = \\Delta_{p}\\).\n\n  \\item \\(\\Delta_{2p+1} = \\OB{\\fun{tms}}{p+1} - \\OB{\\fun{tms}}{p} + 1 =\n  \\Delta_{p} + 1\\).\n\n\\end{itemize}\nWe already met~\\(\\Delta_n\\) under the name~\\(\\nu_n\\) in\nequation~\\eqref{eq:ruler_nu} \\vpageref{eq:ruler_nu}. Let us define it\nrecursively:% as follows:\n\\begin{equation}\n\\nu_{0} := 0,\\quad \\nu_{2n} := \\nu_{n},\\quad\n\\nu_{2n+1} := \\nu_{n} + 1.\\label{def:nu}\\index{bit sum}\n\\end{equation}\nThis definition becomes obvious when we consider the binary\nrepresentations of~\\(2n\\) and~\\(2n+1\\). Notice that \\(\\nu\\)~is a\ndeceptively simple function: it is periodic because \\(\\nu_{1} =\n\\nu_{2^p} = 1\\), but \\(\\nu_{2^p-1}=p\\). Resuming our argument:\n\\(\\OB{\\fun{tms}}{n+1} = \\OB{\\fun{tms}}{n} + \\nu_n\\), and summing on\nboth sides yields\n\\begin{equation}\n\\abovedisplayskip=2pt\n\\abovedisplayshortskip=2pt\n\\belowdisplayskip=2pt\n\\OB{\\fun{tms}}{n} = \\sum_{k=0}^{n-1}{\\nu_k}.\\label{eq:OB_tms}\n\\index{tms@$\\OB{\\fun{tms}}{n}$}\n\\end{equation}}\n\n\\noindent \\cite{Trollope_1968} first found a closed form for\n\\(\\sum_{k=0}^{n-1}\\nu_k\\), whose demonstration was later simplified by\n\\cite{Delange_1975}, who extended the analysis with Fourier\nseries. \\cite{Stolarsky_1977} provided many references on the\nsubject. In equation~\\eqref{eq:best_power}, we have\n\\(\\OB{\\fun{tms}}{2^p} = \\frac{1}{2}p2^p\\), that is,\n\\(\\OB{\\fun{tms}}{n} = \\frac{1}{2}n\\lg n\\) when \\(n=2^p\\). This should\nprompt us to look, like \\cite{McIlroy_1974}, for an additional linear\nterm in the general case, that is, the greatest real constants~\\(a\\)\nand~\\(b\\) such that, for \\(n \\geqslant 2\\),\n\\begin{equation}\n\\pred{Low}{n} \\colon \\tfrac{1}{2}n\\lg n + an + b \\leqslant \\OB{\\fun{tms}}{n}.\n\\label{ineq:McIlroy}\n\\end{equation}\\index{Low@\\predName{Low}}%\nThe base case is \\(\\pred{Low}{2} \\colon 2a + b \\leqslant 0\\). The most\nobvious way to structure the inductive argument is to follow the\ndefinition of \\(\\OB{\\fun{tms}}{n}\\) when \\(n=2p\\) and \\(n=2p+1\\), but\na bound on \\(\\OB{\\fun{tms}}{2p+1}\\) would rely on bounds on\n\\(\\OB{\\fun{tms}}{p}\\) and \\(\\OB{\\fun{tms}}{p+1}\\), compounding\nimprecision. Instead, if we could have at least one exact value from\nwhich to inductively build the bound, we would gain\naccuracy. Therefore, we may expect a better bound if we can find a\ndecomposition of \\(\\OB{\\fun{tms}}{2^p+i}\\), where \\(0 < i \\leqslant\n2^p\\), in terms of \\(\\OB{\\fun{tms}}{2^p}\\) (exact) and\n\\(\\OB{\\fun{tms}}{i}\\). This is easy if we count the 1-bits in\n\\fig~\\vref{fig:Btms_table},\n\\begin{figure}\n\\centering\n\\includegraphics[bb=71 595 210 721]{Btms_table}\n\\caption{$\\protect\\OB{\\fun{tms}}{2^p+i} = \\protect\\OB{\\fun{tms}}{2^p}\n  + \\protect\\OB{\\fun{tms}}{i} + i$\\label{fig:Btms_table}}\n\\end{figure}\nwhich is the same as the table in \\fig~\\ref{fig:bits}, where\n\\(n=2^p+i\\). (Keep in mind that \\(\\OB{\\fun{tms}}{n}\\) is the sum of\nthe bits up to \\(n-1\\), as seen in equation~\\eqref{eq:OB_tms}.) We\nfind:\n\\begin{equation}\n\\OB{\\fun{tms}}{2^p+i} = \\OB{\\fun{tms}}{2^p} + \\OB{\\fun{tms}}{i} + i.\n\\label{eq:OBtms_2m_i}\n\\end{equation}\n(The term~\\(i\\) is the sum of the leftmost bits.) Therefore, let us\nassume \\(\\pred{Low}{n}\\), for all \\(1 \\leqslant n \\leqslant 2^p\\), and\nprove \\(\\pred{Low}{2^p+i}\\), for all \\(0 < i \\leqslant 2^p\\). The\ninduction principle entails then that \\(\\pred{Low}{n}\\) holds for\nall~\\(n \\geqslant 2\\). The inductive step \\(\\pred{Low}{2^p+i}\\) should\ngive us the opportunity to maximise the constants~\\(a\\)\nand~\\(b\\).\\index{Low@\\predName{Low}} Let \\(m=2^p\\). Using\n\\(\\OB{\\fun{tms}}{2^p} = \\tfrac{1}{2}p2^p\\) and the inductive\nhypothesis \\(\\pred{Low}{i}\\), we have\n\\begin{equation}\n\\tfrac{1}{2}m\\lg m + (\\tfrac{1}{2}i\\lg i + ai + b) + i\n\\leqslant\n\\OB{\\fun{tms}}{m} + \\OB{\\fun{tms}}{i} + i = \\OB{\\fun{tms}}{m+i}.\n\\label{ineq:Btms_n_i}\n\\end{equation}\nWe need now to find \\(a\\)~and~\\(b\\) such that the inductive step\n\\(\\pred{L}{m+i}\\) holds as well, that is,\n\\(\\tfrac{1}{2}(m+i)\\lg(m+i) + a(m+i) + b \\leqslant \\B{}{m+i}\\).\nUsing~\\eqref{ineq:Btms_n_i}, this is implied by\n\\begin{equation*}\n\\tfrac{1}{2}(m+i)\\lg(m+i) + a(m+i) + b\n\\leqslant\n\\tfrac{1}{2}m\\lg m + (\\tfrac{1}{2}i\\lg i + ai + b) + i.\n\\end{equation*}\nWe can already notice that this inequality is equivalent to\n\\begin{equation}\n\\tfrac{1}{2}m\\lg(m+i) + \\tfrac{1}{2}i\\lg(m+i) + am\n\\leqslant \\tfrac{1}{2}m\\lg m + \\tfrac{1}{2}i\\lg i + i.\n\\label{ineq:Btms_n_i_details}\n\\end{equation}\nBut \\(\\tfrac{1}{2}m\\lg(m+i) > \\tfrac{1}{2}m\\lg m\\) and\n\\(\\tfrac{1}{2}i\\lg(m+i) > \\tfrac{1}{2}i\\lg i\\), therefore the\nconstant~\\(a\\) we are seeking must satisfy \\(am \\leqslant i\\) for all\n\\(0 < i < m\\), hence we expect \\(a < 0\\).\n\nWe extend~\\(i\\) over the real numbers by defining \\(i=x2^p=xm\\), where\n\\(x\\)~is a real number such that \\(0 < x \\leqslant 1\\). By replacing\n\\(i\\)~by~\\(xm\\) in inequality~\\eqref{ineq:Btms_n_i_details}, we obtain\n\\begin{equation*}\n\\tfrac{1}{2}(1+x)\\lg(1+x) + a \\leqslant \\tfrac{1}{2}x\\lg x + x.\n\\end{equation*}\nLet \\(\\Phi(x) := \\tfrac{1}{2}x\\lg x - \\tfrac{1}{2}(1+x)\\lg(1+x)\n+ x\\). Then, this is equivalent to \\(a \\leqslant \\Phi(x)\\).\n\nThe function~\\(\\Phi\\) can be continuously extended at~\\(0\\), as\n\\(\\lim_{x \\to 0} x\\lg x = 0\\), and it is differentiable on the\ninterval \\(]0,1]\\):\n\\begin{equation}\n\\frac{d\\Phi}{dx} = \\frac{1}{2}\\lg\\frac{4x}{x+1}.\n\\label{eq:der_Phi}\n\\end{equation}\nThe root of \\(d\\Phi/dx = 0\\) is \\myfrac{1}/{3}, and the derivative\nis negative before, and positive after. Therefore, \\(a_{\\max} :=\n\\min_{0 \\leqslant x \\leqslant 1}\\Phi(x) = \\Phi(\\tfrac{1}{3}) =\n-\\tfrac{1}{2}\\lg\\tfrac{4}{3}\\). The base case was \\(b \\leqslant -2a\\),\ntherefore \\(b_{\\max} := -2a_{\\max} = \\lg\\tfrac{4}{3}\\). Finally,\n\\begin{equation}\n  \\tfrac{1}{2}n\\lg n - \\left(\\tfrac{1}{2}\\lg\\tfrac{4}{3}\\right)n + \\lg\\tfrac{4}{3}\n  \\leqslant \\OB{\\fun{tms}}{n},\n\\label{ineq:lower_Btms}\n\\end{equation}\nwhere \\(\\tfrac{1}{2}\\lg\\tfrac{4}{3} \\simeq 0.2075\\) and\n\\(\\lg\\tfrac{4}{3} \\simeq 0.415\\). Importantly, the lower bound is\ntight if \\(x=\\myfrac{1}/{3}\\), that is, when\n\\(2^p+i=2^p+x2^p=(1+1/3)2^p=2^{p+2}\\!/3\\), or, in general,\n\\(2^k\\!/3\\). The nearest integers are \\(\\floor{2^k\\!/3}\\) and\n\\(\\ceiling{2^k\\!/3}\\), so we must find out which one minimises\n\\(\\OB{\\fun{tms}}{n} - \\tfrac{1}{2}n\\lg(\\tfrac{3}{4}n)\\), because we\nhave \\(\\tfrac{1}{2}n\\lg n - \\left(\\tfrac{1}{2}\\lg\\tfrac{4}{3}\\right)n\n= \\tfrac{1}{2}n\\lg(\\tfrac{3}{4}n)\\). We start with the following\ntheorems.\n\\begin{lemma}\n\\label{lem:div3}\n\\textsl{Integers of the form \\(4^p-1\\) are divisible by~\\(3\\).}\n\\end{lemma}\n\\begin{proof}\n  Let \\(\\pred{Div}{p}\\)\\index{Div@\\predName{Div}} be the proposition\n  to prove. Trivially, \\(\\pred{Div}{1}\\) is true. Let us assume\n  \\(\\pred{Div}{p}\\) and proceed to establish \\(\\pred{Div}{p+1}\\). The\n  former means that there exists an integer~\\(q\\) such that \\(4^p - 1\n  = 3q\\). Therefore, \\(4^{p+1} - 1 = 3(4q+1)\\), which means that\n  \\(\\pred{Div}{p+1}\\) holds. The induction principle then entails that\n  the lemma holds for all integers~\\(p\\).\n\\end{proof}\n\\begin{thm}\n\\label{thm:OB_lambda}\n\\textsl{We have \\(\\OB{\\mathsf{tms}}{1+\\phi_k} -\n  \\OB{\\mathsf{tms}}{\\phi_k} = \\floor{k/2}\\), where \\(\\phi_k :=\n  \\floor{2^k\\!/3}\\).}\n\\end{thm}\n\\noindent \\emph{Proof.} Let \\(\\phi_k := \\floor{2^k\\!/3}\\). Either\n\\(k\\)~is even or odd.\n\\begin{itemize}\n\n  \\item If \\(k=2m\\), then \\(2^k\\!/3 = (4^m-1)/3 + 1/3\\). Since\n    \\(1/3<1\\) and, by lemma~\\ref{lem:div3}, \\((4^m-1)/3\\) is an\n    integer, we have \\(2^k\\!/3 = \\floor{2^k\\!/3} + 1/3\\) and\n    \\(\\floor{2^k\\!/3} = (4^m-1)/3 = 4^{m-1} + 4^{m-2} + \\dots + 1 =\n    2^{2m-2} + 2^{2m-4} + \\dots + 1 = (1010\\dots01)_2\\). Hence\n    \\(\\nu_{\\phi_{2m}} = m\\). We know that \\(\\OB{\\fun{tms}}{m+1} =\n    \\OB{\\fun{tms}}{m} + \\nu_m\\), therefore\n    \\(\\OB{\\fun{tms}}{1+\\phi_{2m}} - \\OB{\\fun{tms}}{\\phi_{2m}} = m\\),\n    or, equivalently, \\(\\OB{\\fun{tms}}{1+\\phi_k} -\n    \\OB{\\fun{tms}}{\\phi_k} = \\floor{k/2}\\).\n\n  \\item If \\(k=2m+1\\), then \\(2^k\\!/3 = 2(4^m-1)/3 + 2/3\\). Since\n    \\(2/3<1\\) and, by lemma~\\ref{lem:div3}, \\((4^m-1)/3\\) is an\n    integer, we have \\(2^k\\!/3 = \\floor{2^k\\!/3} + 2/3 =\n    \\ceiling{2^k\\!/3} - 1/3\\) and \\(\\floor{2^k\\!/3} = 2(4^m-1)/3 =\n    2^{2m-1} + 2^{2m-3} + \\dots + 2 = (1010\\dots10)_2\\); so\n    \\(\\nu_{\\phi_{2m+1}} = m\\). From \\(\\OB{\\fun{tms}}{m+1} =\n    \\OB{\\fun{tms}}{m} + \\nu_m\\) comes \\(\\OB{\\fun{tms}}{1+\\phi_{2m+1}}\n    - \\OB{\\fun{tms}}{\\phi_{2m+1}} = m\\), or,\n    equivalently,\\index{tms@$\\OB{\\fun{tms}}{n}$|(}\n    \\(\\OB{\\fun{tms}}{1+\\phi_k} - \\OB{\\fun{tms}}{\\phi_k} =\n    \\floor{k/2}\\).\\hfill\\(\\Box\\)\n\n\\end{itemize}\n\\noindent Let \\(Q(x) := \\tfrac{1}{2}x\\lg(\\tfrac{3}{4}x)\\) and let us\nproceed to compare \\(\\OB{\\fun{tms}}{\\phi_k} - Q(\\phi_k)\\) with\n\\(\\OB{\\fun{tms}}{1+\\phi_k} - Q(1+\\phi_k)\\) by making two cases\ndepending upon the parity of~\\(k\\). If the former difference is\nsmaller, then \\(p=\\phi_k\\)~is the integer which minimises\n\\(\\OB{\\fun{tms}}{p} - \\tfrac{1}{2}p\\lg(\\tfrac{3}{4}p)\\); otherwise, it\nis \\(p=1+\\phi_k\\).\n\\begin{itemize}\n\n  \\item If \\(k=2m+2\\), then \\(\\phi_{2m+2} = 2^{2m} + \\phi_{2m}\\) (see\n    proof of theorem~\\ref{thm:OB_lambda}). From\n    equation~\\eqref{eq:OBtms_2m_i}, we draw\n    \\(\\OB{\\fun{tms}}{\\phi_{2m+2}} = \\OB{\\fun{tms}}{2^{2m}} +\n    \\OB{\\fun{tms}}{\\phi_{2m}} + \\phi_{2m} = \\OB{\\fun{tms}}{\\phi_{2m}}\n    - m4^m + \\phi_{2m}\\). Summing both sides from \\(m=0\\) to \\(m=n-1\\)\n    yields \\(\\OB{\\fun{tms}}{\\phi_{2n}} = \\OB{\\fun{tms}}{\\phi_0} + S_n\n    + \\sum_{m=0}^{n-1}{\\phi_{2m}}\\), where \\(S_n :=\n    \\sum_{m=0}^{n-1}{m4^m}\\). We have \\(S_n + n4^n =\n    \\sum_{m=1}^{n}{m4^m} = \\sum_{m=0}^{n-1}(m+1)4^{m+1} = 4 \\cdot S_n\n    + 4\\sum_{m=0}^{n-1}4^m\\). Finally, \\(9 \\cdot S_n = (3n -4)4^n +\n    4\\). On the other hand, \\(9 \\sum_{m=0}^{n-1}{\\phi_{2m}} = 4^n - 3n\n    - 1\\). Finally, remarking that \\(\\phi_0 = 0\\) and\n    \\(\\OB{\\fun{tms}}{0} = 0\\), we gather that\n    \\begin{equation}\n      \\OB{\\fun{tms}}{\\phi_{2n}} = (n-1)\\phi_{2n}.\n    \\label{eq:OBtms_phi_2n}\n    \\end{equation}\n    Let us now work out \\(Q(\\phi_{2n}) = \\tfrac{1}{2}\\phi_{2n}(2(n-1)\n    + \\lg(1-1/4^n)) = \\OB{\\fun{tms}}{\\phi_{2n}} +\n    \\tfrac{1}{2}\\phi_{2n}\\lg(1-1/4^n)\\), with an application\n    of~\\eqref{eq:OBtms_phi_2n}. If we let \\(f(x) := (1-x)\n    \\ln(1-1/x)\\), then \\(\\OB{\\fun{tms}}{\\phi_{2n}} - Q(\\phi_{2n}) =\n    f(4^n)/(6\\ln 2)\\). Elementary analysis shows that\n    \\(3\\ln\\tfrac{3}{4} \\leqslant f(x) < 1\\), for \\(x \\geqslant 4\\),\n    that is, \\(1 - \\tfrac{1}{2}\\lg 3 \\leqslant\n    \\OB{\\fun{tms}}{\\phi_{2n}} - Q(\\phi_{2n}) < 1/(6\\ln 2)\\), if \\(n\n    \\geqslant 1\\). This means that \\(\\boxed{0.2075 <\n    \\smash{\\OB{\\fun{tms}}{\\phi_{2n}}} - Q(\\phi_{2n}) < 0.2405.}\\)\n\n    From theorem~\\ref{thm:OB_lambda} and\n    equation~\\eqref{eq:OBtms_phi_2n}, we have\n    \\begin{equation}\n      \\OB{\\fun{tms}}{1+\\phi_{2n}} = (n-1)(1+\\phi_{2n}) + 1.\n      \\label{eq:OBtms_succ_phi_2n}\n    \\end{equation}\n    Furthermore, \\(Q(1+\\phi_{2n}) = \\tfrac{1}{2}(1+\\phi_{2n}) (2(n-1)\n    + \\lg(1+1/2^{2n-1})) = \\OB{\\fun{tms}}{1+\\phi_{2n}} - 1 +\n    \\tfrac{1}{6}(4^n + 2)\\lg(1+2/4^n)\\), the last step making use\n    of~\\eqref{eq:OBtms_succ_phi_2n}. If \\(g(x) := 1 -\n    \\tfrac{1}{6}(x+2)\\lg(1+2/4^n)\\), then\n    \\(\\OB{\\fun{tms}}{1+\\phi_{2n}} - Q(1+\\phi_{2n}) =\n    g(4^n)\\). Elementary analysis entails that \\(2 - \\lg 3 \\leqslant\n    g(x) < 1 - 1/(3\\ln 2)\\), when \\(x \\geqslant 4\\), that is, \\(2 -\n    \\lg 3 \\leqslant g(4^n) < 1 - 1/(3\\ln 2)\\), for \\(n \\geqslant\n    1\\). Approximately, \\(\\boxed{0.4150 <\n      \\smash{\\OB{\\fun{tms}}{1+\\phi_{2n}}} - Q(1+\\phi_{2n}) <\n      0.5192.}\\)\n\n    \\bigskip \\textsl{Hence \\(p=\\phi_{2n} = (1010\\dots01)_2\\) minimises\n      \\(\\OB{\\fun{tms}}{p} - \\tfrac{1}{2}p\\lg(\\tfrac{3}{4}p)\\).}\n    \\bigskip\n\n  \\item If \\(k=2m+1\\), then \\(\\phi_{2m+1} = 2^{2m-1} + \\phi_{2m-1}\\)\n    (see proof of theorem~\\ref{thm:OB_lambda}). From\n    equation~\\eqref{eq:OBtms_2m_i}, we draw\n    \\(\\OB{\\fun{tms}}{\\phi_{2m+1}} = \\OB{\\fun{tms}}{2^{2m-1}} +\n    \\OB{\\fun{tms}}{\\phi_{2m-1}} + \\phi_{2m-1} =\n    \\OB{\\fun{tms}}{\\phi_{2m-1}} - (2m-1)4^{m-1} +\n    \\phi_{2m-1}\\). Summing both sides from \\(m=1\\) to \\(m=n-1\\) and\n    multiplying by~\\(9\\) yields \\(9\\OB{\\fun{tms}}{\\phi_{2n+1}} =\n    \\tfrac{1}{2}S_{n+1} - 3(4^n-1) + \\sum_{m=0}^{n-1}\\phi_{2m+1}\\),\n    which simplifies into\n    \\begin{equation}\n      \\OB{\\fun{tms}}{\\phi_{2n+1}} = (n - \\tfrac{1}{2})\\phi_{2n+1}.\n      \\label{eq:OBtms_phi_2n_1}\n    \\end{equation}\n    We have \\(Q(\\phi_{2n+1}) = \\tfrac{1}{2}\\phi_{2n+1}(2n-1 +\n    \\lg(1-1/4^n)) = \\OB{\\fun{tms}}{\\phi_{2n+1}} +\n    \\tfrac{1}{2}\\phi_{2n+1}\\lg(1-1/4^n)\\), where the last equality\n    follows from~\\eqref{eq:OBtms_phi_2n_1}. If we let \\(f(x) :=\n    (1-x)\\ln(1-1/x)\\), as we did for \\(Q(\\phi_{2n})\\), we have\n    \\(\\OB{\\fun{tms}}{\\phi_{2n+1}} - Q(\\phi_{2n+1}) = f(4^n)/(3\\ln\n    2)\\). We know \\(3\\ln\\tfrac{3}{4} \\leqslant f(x) < 1\\), for \\(x\n    \\geqslant 4\\), therefore \\(\\lg 3 - 2 \\leqslant\n    \\OB{\\fun{tms}}{\\phi_{2n+1}} - Q(\\phi_{2n+1}) < 1/(3\\ln 2)\\), if\n    \\(n \\geqslant 1\\). Hence \\(\\boxed{0.4150 <\n      \\smash{\\OB{\\fun{tms}}{\\phi_{2n+1}}} - Q(\\phi_{2n+1}) <\n      0.4809.}\\)\n\n    From theorem~\\ref{thm:OB_lambda} and\n    equation~\\eqref{eq:OBtms_phi_2n_1}, we deduce\n    \\begin{equation}\n      \\OB{\\fun{tms}}{1+\\phi_{2n+1}} = (n-\\tfrac{1}{2})(1+\\phi_{2n+1})\n      + \\tfrac{1}{2}.\n      \\label{eq:OBtms_succ_phi_2n_1}\n    \\end{equation}\n    Moreover, \\(Q(1+\\phi_{2n+1}) = \\tfrac{1}{2}(1+\\phi_{2n+1})(2n-1 +\n    \\lg(1+1/2^{2n+1})) = \\OB{\\fun{tms}}{1+\\phi_{2n+1}} - \\tfrac{1}{2}\n    + \\tfrac{1}{6}(1+2^{2n+1})\\lg(1+1/2^{2n+1})\\), the last step being\n    a consequence of~\\eqref{eq:OBtms_succ_phi_2n_1}. If we let \\(h(x)\n    := \\tfrac{1}{2} - \\tfrac{1}{6}(1+x)\\lg(1+1/x)\\), then\n    \\(\\OB{\\fun{tms}}{1+\\phi_{2n+1}} - Q(1+\\phi_{2n+1}) =\n    h(2^{2n+1})\\). Elementary analysis shows that \\(5 - 3\\lg 3\n    \\leqslant h(x) < 1/2 - 1/(6\\ln 2)\\), for \\(x \\geqslant 8\\), that\n    is, \\(5 - 3\\lg 3 \\leqslant \\OB{\\fun{tms}}{1+\\phi_{2n+1}} -\n    Q(1+\\phi_{2n+1}) < 1/2 - 1/(6\\ln 2)\\), if \\(n \\geqslant 1\\). So\n    \\(\\boxed{0.2450 < \\smash{\\OB{\\fun{tms}}{1+\\phi_{2n+1}}} -\n      Q(1+\\phi_{2n+1}) < 0.2596.}\\)\n\n    \\bigskip\n    \\textsl{Hence \\(p = 1+\\phi_{2m+1} = (1010\\dots1011)_2\\) minimises\n    \\(\\OB{\\fun{tms}}{p} - \\tfrac{1}{2}p\\lg p\\).}\n\n\\end{itemize}\nFinally, we conclude that the lower bound in~\\eqref{ineq:lower_Btms}\nis tight if \\(n=2\\) (from the base case) and is otherwise the sharpest\nwhen \\(n=(1010\\dots01)_2\\) or \\(n=(1010\\dots1011)_2\\). As a whole,\nthese values constitute the \\emph{Jacobsthal\n  sequence},\\index{Jacobsthal number} defined as\n\\begin{equation}\nJ_0 = 0; \\; J_1=1; \\; J_{n+2} = J_{n+1} + 2J_{n},\\; \\text{for \\(n\n  \\geqslant 0\\).}\n\\label{eq:Jacobsthal}\n\\end{equation}\n\nLet us use now the same inductive approach to find a good upper bound\nto \\(\\OB{\\fun{tms}}{n}\\). In other words, we want to minimise the real\nconstants \\(a'\\)~and~\\(b'\\) such that, for \\(n \\geqslant 2\\),\n\\begin{equation*}\n\\OB{\\fun{tms}}{n} \\leqslant \\tfrac{1}{2}n\\lg n + a'n + b'.\n\\end{equation*}\nThe only difference with the search for the lower bound is that\ninequalities are reversed, so we want\n\\begin{equation*}\n\\Phi(x) \\leqslant a', \\;\\text{where \\(\\Phi(x) := \\tfrac{1}{2}x\\lg x - \\tfrac{1}{2}(1+x)\\lg(1+x) + x\\)}.\n\\end{equation*}\nHere, we need to find the maximum of~\\(\\Phi\\) on the closed interval\n\\([0,1]\\). The two positive roots of~\\(\\Phi\\) are \\(0\\)~and~\\(1\\), and\n\\(\\Phi\\)~is negative between them (see\nequation~\\eqref{eq:der_Phi}). Therefore \\(a'_{\\min} := \\max_{0\n  \\leqslant x \\leqslant 1}\\Phi(x) = \\Phi(0) = \\Phi(1) = 0\\). From the\nbase case, we have \\(b'_{\\min} = -2a_{\\min} = 0\\). Therefore, we have\nthe bounds\n\\begin{equation}\n\\tfrac{1}{2}n\\lg n - \\left(\\tfrac{1}{2}\\lg\\tfrac{4}{3}\\right)n + \\lg\\tfrac{4}{3}\n\\leqslant \\OB{\\fun{tms}}{n} \\leqslant\n\\tfrac{1}{2}n\\lg n.\n\\label{ineq:bounds_Btms}\n\\index{tms@$\\OB{\\fun{tms}}{n}$}\n\\end{equation}\nThe upper bound is clearly tight when \\(n=2^p\\) because of\nequation~\\eqref{eq:best_power}. It is also very obvious now that we\nhave \\(\\OB{\\fun{tms}}{n} \\sim \\frac{1}{2}n\\lg n\\), but if we were only\ninterested in this asymptotic result, \\cite{Bush_1940} gave a very\nsimple counting argument on the bits in \\fig~\\vref{fig:bits}.\n\\cite{Delange_1975} investigated \\(\\OB{\\fun{tms}}{n}\\) by means of\nadvanced real analysis and showed that \\(\\OB{\\fun{tms}}{n} =\n\\tfrac{1}{2}n\\lg n + F_0(\\lg n) \\cdot n\\), where \\(F_0\\)~is a\ncontinuous, nowhere differentiable function of period~\\(1\\), and whose\nFourier series shows the mean value to be approximately\n\\(-0.145599\\). \\index{tms@$\\OB{\\fun{tms}}{n}$|)}\n\\index{merge sort!top-down $\\sim$!minimum cost|)}\n\n\\mypar{Maximum cost}\n\\label{tms:maximum}\n\\index{merge sort!top-down $\\sim$!maximum cost|(}\n\nThe maximum number of comparisons satisfies\n\\begin{equation*}\n\\OW{\\fun{tms}}{0} = \\OW{\\fun{tms}}{1} = 0,\n\\qquad\n\\OW{\\fun{tms}}{n} = \\OW{\\fun{tms}}{\\floor{n/2}}\n+ \\OW{\\fun{tms}}{\\ceiling{n/2}}\n+ \\OW{\\fun{mrg}}{\\floor{n/2},\\ceiling{n/2}}.\n\\index{tms@$\\OW{\\fun{tms}}{n}$|(}\n\\index{mrg@\\fun{mrg/2}}\n\\end{equation*}\nEquation~\\eqref{eq:worst_merge} \\vpageref{eq:worst_merge} yields\n\\(\\OW{\\fun{tms}}{n} = \\OW{\\fun{tms}}{\\floor{n/2}} +\n\\OW{\\fun{tms}}{\\ceiling{n/2}} + n - 1\\) and\n\\begin{equation*}\n\\OW{\\fun{tms}}{0} = \\OW{\\fun{tms}}{1} = 0;\\;\n\\OW{\\fun{tms}}{2p} = 2\\OW{\\fun{tms}}{p} + 2p - 1,\\;\n\\OW{\\fun{tms}}{2p+1} = \\OW{\\fun{tms}}{p} + \\OW{\\fun{tms}}{p+1} + 2p.\n\\end{equation*}\nLet the difference of two successive terms be \\(\\Delta_n :=\n\\smash[t]{\\W{}{n+1}} - \\W{}{n}\\). If we know \\(\\Delta_n\\), we know\n\\(\\W{}{n}\\) because \\(\\sum_{k=1}^{n-1}\\Delta_k =\n\\sum_{k=1}^{n-1}\\W{}{k+1} - \\sum_{k=1}^{n-1}\\W{}{k} = \\W{}{n} -\n\\W{}{1} = \\W{}{n}\\). We remark that\n\\begin{itemize}\n\n  \\item if \\(n=2p\\), then \\(\\Delta_{2p} = \\Delta_{p} + 1\\),\n\n  \\item else \\(n=2p+1\\) and \\(\\W{}{2p+2} = 2 \\cdot \\W{}{p+1} + 2p\n    + 1\\), so \\(\\Delta_{2p+1} = \\Delta_{p} + 1\\).\n\n\\end{itemize}\nIn summary, \\(\\Delta_0 = 0\\) and \\(\\Delta_n = \\Delta_{\\floor{n/2}} +\n1\\). If we start unravelling the recurrence, we get \\(\\Delta_n =\n\\Delta_{\\floor{\\floor{n/2}/2}}+ 2\\), so we must simplify\n\\(\\floor{\\floor{\\floor{\\dots}/2}/2}\\).\n\\begin{thm}[Floors and Fractions]\n\\label{thm:floors}\n\\textsl{Let \\(x\\)~be a real number and \\(q\\)~a natural number. Then\n  \\(\\floor{\\floor{x}/q} = \\floor{x/q}\\).}\n\\end{thm}\n\\begin{proof}\n  The equality is equivalent to the conjunction of the two\n  complementary inequalities \\(\\floor{\\floor{x}/q} \\leqslant\n  \\floor{x/q}\\) and \\(\\floor{x/q} \\leqslant \\floor{\\floor{x}/q}\\). The\n  former is straightforward because it is a consequence of \\(\\floor{x}\n  \\leqslant x\\). In the latter, because both sides of the inequality\n  are integers, \\(\\floor{x/q} \\leqslant \\floor{\\floor{x}/q}\\) is\n  equivalent to state that \\(p \\leqslant \\floor{x/q} \\Rightarrow p\n  \\leqslant \\floor{\\floor{x}/q}\\), for any integer~\\(p\\). An obvious\n  lemma is that if \\(i\\)~is an integer and \\(y\\)~a real number, \\(i\n  \\leqslant \\floor{y} \\Leftrightarrow i \\leqslant y\\), so the original\n  inequality is equivalent to \\(p \\leqslant x/q \\Rightarrow p\n  \\leqslant \\floor{x}/q\\), which is trivially equivalent to \\(pq\n  \\leqslant x \\Rightarrow pq \\leqslant \\floor{x}\\). Since \\(pq\\)~is an\n  integer, this implication is true from the same lemma.\n\\end{proof}\nUsing theorem~\\vref{thm:floors}, we deduce \\(\\Delta_n = m\\), with\n\\(m\\)~being the largest natural number such that \\(\\floor{n/2^m} =\n0\\). In other words, \\(m\\)~is the number of bits in the binary\nnotation of~\\(n\\), which is found in equation~\\eqref{eq:e_r} to be\n\\(\\Delta_n = \\floor{\\lg n} + 1\\). Since we already know that \\(\\W{}{n}\n= \\sum_{k=1}^{n-1}\\Delta_k\\), we conclude,\nwith~\\eqref{eq:num_of_bits}, that\n\\begin{equation}\n\\W{}{n} = \\sum_{k=1}^{n-1}(\\floor{\\lg k}+1).\n\\label{eq:tms_n_tmp}\n\\end{equation}\nWhilst the minimum cost is the number of \\(1\\)-bits up to \\(n-1\\), we\nfind now that the maximum cost is the total number of bits up to\n\\(n-1\\). Informally, this leads us to bet that \\(\\OW{\\fun{tms}}{n}\n\\sim 2 \\cdot \\OB{\\fun{tms}}{n} \\sim n\\lg n\\), since we would expect\nthe number of \\(0\\)-bits and \\(1\\)-bits to be the same in\naverage. Consider again the bit table in \\fig~\\vref{fig:bits}. The\ngreatest power of~\\(2\\) smaller than~\\(n\\) is~\\(2^{\\floor{\\lg n}}\\)\nbecause it is the binary number \\((10\\dots0)_2\\) having the same\nnumber of bits as~\\(n\\); it thus appears in the same section of the\ntable as~\\(n\\). The trick consists in counting the bits in\n\\emph{columns}, from top to bottom, and leftwards. In the rightmost\ncolumn, we find \\(n\\)~bits. In the second column, from the right, we\nfind \\(n-2^1+1\\) bits. The third from the right contains \\(n-2^2+1\\)\nbits etc. until the leftmost column containing \\(n-2^{\\floor{\\lg\n    n}}+1\\) bits. The total number of bits in the table is\n\\begin{equation*}\n\\abovedisplayskip=2pt\n\\belowdisplayskip=2pt\n\\sum_{k=1}^{n}{\\!(\\floor{\\lg k}+1)}\n   = \\sum_{k=0}^{\\floor{\\lg n}}{\\!(n-2^k+1)}\n   = (n + 1)(\\floor{\\lg n} + 1) - 2^{\\floor{\\lg n}+1} + 1.\n\\end{equation*}\nLet \\(n := (b_{m-1}\\dots b_0)_2\\), then \\(2^{m-1} \\leqslant n\n\\leqslant 2^m - 1\\) and \\(2^{m-1} < 2^{m-1} + 1 \\leqslant n + 1\n\\leqslant 2^m\\), so \\(m-1 < \\lg(n+1) \\leqslant m\\), that is, \\(m =\n\\ceiling{\\lg(n+1)}\\), which, with equation~\\eqref{eq:e_r}\n\\vpageref{eq:e_r}, proves\n\\begin{equation*}\n  1 + \\floor{\\lg n} = \\ceiling{\\lg(n+1)}.\n\\end{equation*}\nAs a consequence, equation~\\eqref{eq:tms_n_tmp} can be rewritten as\n\\begin{equation}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n\\OW{\\fun{tms}}{0} = \\OW{\\fun{tms}}{1} = 0,\n\\qquad\n\\OW{\\fun{tms}}{n} = n\\ceiling{\\lg n} - 2^{\\ceiling{\\lg n}} + 1.\n\\label{eq:top}\n\\end{equation}\nThis equation is subtler than it seems, due to the periodicity hidden\nin \\(2^{\\ceiling{\\lg n}}\\). Depending on whether \\(n = 2^p\\) or not,\ntwo cases arise:\n\\begin{itemize*}\n\n  \\item if~\\(n=2^p\\), then \\(\\OW{\\fun{tms}}{n} = n\\lg n - n +\n    1\\);\n\n  \\item otherwise, we have \\(\\ceiling{\\lg n} = \\floor{\\lg n} + 1 = \\lg\n    n - \\{\\lg n\\} + 1\\) and \\(\\OW{\\fun{tms}}{n} = n\\lg n + \\theta(1 -\n    \\{\\lg n\\}) \\cdot n + 1\\), with \\(\\theta(x) := x - 2^x\\) and\n    \\(\\{x\\} := x - \\floor{x}\\) is the \\emph{fractional\n      part}\\index{fractional part@$\\{x\\}$|see{fractional\n        part}}\\index{fractional part} of the real~\\(x\\). In\n    particular, we have \\(0 \\leqslant \\{x\\} < 1\\). The derivative is\n    \\(\\theta'(x) = 1 - 2^x\\ln 2\\); it has one root \\(\\theta'(x_0) = 0\n    \\Leftrightarrow x_0 = -\\lg\\ln 2\\) and it is positive\n    before~\\(x_0\\), and negative after. Concordantly, \\(\\theta(x)\\)\n    reaches its maximum at~\\(x_0\\): \\(\\max_{0<x\\leqslant 1}\\theta(x) =\n    \\theta(x_0) = -(1+\\ln\\ln{2})/\\!\\ln{2} \\simeq -0.9139\\), and\n    \\(\\min_{0<x\\leqslant 1}\\theta(x) = \\theta(1) = -1\\). By\n    injectivity, \\(\\theta(1) = \\theta(1-\\{\\lg n\\})\\) implies \\(\\{\\lg\n    n\\} = 0\\), that is, \\(n=2^p\\) (first case).\n\\end{itemize*}\nHence \\(\\OW{\\fun{tms}}{n} = n\\lg n + A(\\lg n) \\cdot n + 1\\), where\n\\(A(x) := 1 - \\{x\\} - 2^{1 - \\{x\\}}\\) is a periodic function, since\n\\(A(x) = A(\\{x\\})\\), such that \\(-1 \\leqslant A(x) < -0.91\\). Further\nanalysis of~\\(A(x)\\) requires Fourier series or complex analysis; its\nmean value is about \\(-0.942695\\). Read \\cite{FlajoletGolin_1994}, as\nwell as \\cite{PannyProdinger_1995}.\n\\begin{equation}\nn\\lg n - n + 1 \\leqslant \\OW{\\fun{tms}}{n} <\nn\\lg n - 0.91 n + 1.\\label{ineq:OWtms}\n\\end{equation}\nThe lower bound is attained when \\(n=2^p\\). The upper bound is most\naccurate when \\(\\{\\lg n\\} = 1 + \\lg\\ln 2\\), that is, when \\(n\\)~is the\nnearest integer to \\(2^p\\ln 2\\) (take the binary expansion of \\(\\ln\n2\\), shift the point \\(p\\)~times to the right and round). Obviously,\n\\(\\OW{\\fun{tms}}{n} \\sim n\\lg n\\).\\index{tms@$\\OW{\\fun{tms}}{n}$|)}\n\\index{merge sort!top-down $\\sim$!maximum cost|)}\n\n\\mypar{Average cost}\n\\index{merge sort!top-down $\\sim$!average cost|(}\n\nLet \\(\\OM{\\fun{tms}}{n}\\)\\index{tms@$\\OM{\\fun{tms}}{n}$|(} be the\naverage number of comparisons to sort \\(n\\)~keys top\\hyp{}down. All\npermutations of the input stack being equally likely,\nequation~\\eqref{eq:cost_tms} becomes\n\\begin{equation*}\n\\OM{\\fun{tms}}{0} = \\OM{\\fun{tms}}{1} = 0,\\qquad\n\\OM{\\fun{tms}}{n} = \\OM{\\fun{tms}}{\\floor{n/2}} +\n\\OM{\\fun{tms}}{\\ceiling{n/2}} +\n\\OM{\\fun{mrg}}{\\floor{n/2},\\ceiling{n/2}},\\index{mrg@\\fun{mrg/2}}\n\\end{equation*}\nwhich, with equation~\\eqref{eq:Amrg}, in turn implies\n\\begin{equation*}\n\\OM{\\fun{tms}}{n} = \\OM{\\fun{tms}}{\\floor{n/2}} +\n\\OM{\\fun{tms}}{\\ceiling{n/2}} + n -\n\\frac{\\floor{n/2}}{\\ceiling{n/2}+1}\n- \\frac{\\ceiling{n/2}}{\\floor{n/2}+1}.\n\\end{equation*}\nIf we proceed as we did for the extremal costs, we get\n\\begin{equation*}\n\\OM{\\fun{tms}}{2p} = 2\\cdot\\OM{\\fun{tms}}{p} + 2p - 2 +\n\\frac{2}{p+1},\\; \\OM{\\fun{tms}}{2p+1} = \\OM{\\fun{tms}}{p} +\n\\OM{\\fun{tms}}{p+1} + 2p - 1 + \\frac{2}{p+2}.\n\\end{equation*}\nThese recurrences are a bit tricky. Setting \\(\\Delta_n :=\n\\OM{\\fun{tms}}{n+1} - \\OM{\\fun{tms}}{n}\\) yields\n\\begin{equation*}\n\\Delta_{2p} = \\Delta_p + 1 + \\frac{2}{p+2} - \\frac{2}{p+1},\n\\quad\n\\Delta_{2p+1} = \\Delta_p + 1.\n\\end{equation*}\nContrary to the difference equations derived for the extremal costs,\nthese are not helpful, so we should try an inductive approach, as we\ndid for finding bounds on\n\\(\\OB{\\fun{tms}}{n}\\). Inequations~\\eqref{ineq:M_join}\n\\vpageref{ineq:M_join} are equivalent to \\(n\\lg n - \\alpha n + \\alpha\n< \\OM{\\fun{tms}}{n} < n\\lg n - \\alpha n + 2\\), where \\(n = 2^p\\), and\nthis suggests us to also look for bounds of the form \\(n\\lg n + an +\nb\\) when \\(n \\neq 2^p\\).\n\nLet us start with the lower bound and set to maximise the\nreal constants \\(a\\)~and~\\(b\\) in\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=2pt\n\\pred{H}{n} \\colon n\\lg n + an + b \\leqslant \\OM{\\fun{tms}}{n},\n\\; \\text{for \\(n \\geqslant 2\\).}\n\\end{equation*}\nSince \\(\\pred{H}{2p}\\) depends on \\(\\pred{H}{p}\\), and\n\\(\\pred{H}{2p\\!+\\!1}\\) depends on \\(\\pred{H}{p}\\) and\n\\(\\pred{H}{p\\!+\\!1}\\), the property \\(\\pred{H}{n}\\), for any \\(n>1\\),\ntransitively depends on \\(\\pred{H}{2}\\) alone, because we are\niterating divisions by~\\(2\\). If we write \\(\\pred{H}{n} \\leadsto\n\\pred{H}{m}\\) to mean `\\(\\pred{H}{n}\\) depends on \\(\\pred{H}{m}\\),' we\nhave, for example, \\(\\pred{H}{2^3} \\leadsto \\pred{H}{2^2} \\leadsto\n\\pred{H}{2^1}\\); \\(\\pred{H}{7} \\leadsto \\pred{H}{3} \\leadsto\n\\pred{H}{2}\\) and \\(\\pred{H}{7} \\leadsto \\pred{H}{4} \\leadsto\n\\pred{H}{2}\\). \\(\\pred{H}{2}\\) is equivalent to\n\\begin{equation}\n2a + b + 1 \\leqslant 0.\n\\label{ineq:base_lower_Atms}\n\\end{equation}\nBecause the definition of \\(\\OM{\\fun{tms}}{n}\\) depends on the parity\nof~\\(n\\), the inductive step will be twofold. Let us assume\n\\(\\pred{H}{m}\\) for \\(m < 2p\\), in particular, we suppose\n\\(\\pred{H}{p}\\), which, with the expression of \\(\\OM{\\fun{tms}}{2p}\\)\nabove, entails\n\\begin{equation*}\n\\abovedisplayskip=2pt\n\\belowdisplayskip=2pt\n (2p\\lg p + 2ap + 2b) + 2p - 2 + \\frac{2}{p+1} \\leqslant \\OM{\\fun{tms}}{2p}.\n\\end{equation*}\nWe want \\(\\pred{H}{2p} \\colon 2p\\lg(2p) + 2ap + b\n= 2p\\lg p + 2ap + 2p + b \\leqslant \\OM{\\fun{tms}}{2p}\\), which holds\nif the following condition does:\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=2pt\n2p\\lg p + 2ap + 2p + b \\leqslant 2p\\lg p + 2ap + 2b + 2p - 2 + \\frac{2}{p+1},\n\\end{equation*}\nwhich is equivalent to\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=2pt\n2 - \\frac{2}{p+1} = \\frac{2p}{p+1} \\leqslant b.\n\\end{equation*}\nLet \\(\\Phi(p) := 2p/(p+1)\\). This function is strictly increasing for\n\\(p > 0\\) and \\(\\Phi(p) \\to 2^{-}\\), as \\(p \\to +\\infty\\).\n\nThe other inductive step deals with the odd values of~\\(n\\). We assume\n\\(\\pred{H}{m}\\) for all \\(m < 2p+1\\), in particular, we suppose\n\\(\\pred{H}{p}\\) and \\(\\pred{H}{p+1}\\), which, with the expression of\n\\(\\OM{\\fun{tms}}{2p+1}\\) above, implies\n\\begin{equation*}\n%\\abovedisplayskip=0pt\n%\\belowdisplayskip=2pt\n(p\\lg p + ap + b) + ((p+1)\\lg(p+1) + a(p+1) + b) + 2p - 1 +\n\\frac{2}{p+2} \\leqslant \\OM{\\fun{tms}}{2p+1},\n\\end{equation*}\nwhich may be simplified slightly into\n\\begin{equation*}\n%\\abovedisplayskip=0pt\n%\\belowdisplayskip=2pt\np\\lg p + (p+1)\\lg(p+1) + a(2p+1) + 2b + 2p - 1 + \\frac{2}{p+2}\n\\leqslant \\OM{\\fun{tms}}{2p+1}.\n\\end{equation*}\nWe want to prove \\(\\pred{H}{2p+1} \\colon (2p+1)\\lg(2p+1) +\na(2p+1) + b \\leqslant \\M{}{2p+1}\\), which is thus implied by\n\\begin{equation}\n%\\abovedisplayskip=0pt\n%\\belowdisplayskip=2pt\n  (2p+1)\\lg(2p+1) \\leqslant\n  p\\lg p + (p+1)\\lg(p+1) + b + 2p - 1 + \\frac{2}{p+2}.\n\\label{ineq:Psi_temp}\n\\end{equation}\nLet \\(\\Psi(p) := (2p+1)\\lg(2p+1) - (p+1)\\lg(p+1) - p\\lg p -\n2p + 1 - 2/(p+2)\\). Then~\\eqref{ineq:Psi_temp} is equivalent to\n\\(\\Psi(p) \\leqslant b\\). Furthermore,\n\\begin{equation*}\n\\frac{d\\Psi}{dp}(p) = \\frac{2}{(p+2)^2} + \\lg\\left(1+\\frac{1}{4p(p+1)}\\right).\n\\end{equation*}\nClearly, \\(d\\Psi/dp > 0\\), for all \\(p > 0\\), so \\(\\Psi(p)\\)~is\nstrictly increasing for \\(p > 0\\). Let us find \\(\\lim_{p \\to\n  +\\infty}\\Psi(p)\\) by rewriting \\(\\Psi(p)\\) as follows:\n\\begin{align*}\n\\Psi(p)\n  &= 2 - \\frac{2}{p+2} + (2p+1)\\lg(p+\\tfrac{1}{2}) - (p+1)\\lg(p+1)\n     - p\\lg p\\\\\n  &= 2 - \\frac{2}{p+2} + p\\left(\\lg(p+\\tfrac{1}{2})^2 - \\lg(p+1)\n   - \\lg p\\right) + \\lg(p+\\tfrac{1}{2})\\\\\n  &\\phantom{=} \\quad - \\lg(p+1)\\\\\n  &= 2 - \\frac{2}{p+2} + p\\lg\\left(1 + \\frac{1}{4p(p+1)}\\right) +\n  \\lg\\frac{p + \\myfrac{1}/{2}}{p+1}.\n\\end{align*}\nThe limit of \\(x\\ln(1+1/x^2)\\) as \\(x \\to +\\infty\\) can be found by\nchanging \\(x\\)~into \\(1/y\\) and considering the limit as \\(y \\to\n0^{+}\\), which is shown by l'H\\^{o}pital's rule to be~\\(0\\). This\nresult can be extended to apply to the large term in \\(\\Psi(p)\\) and,\nsince all the other variable terms converge to~\\(0\\), we can conclude\nthat \\(\\Psi(p) \\to 2^{-}\\), as \\(p \\to +\\infty\\).\n\nBecause we need to satisfy the conditions \\(\\Psi(p) \\leqslant b\\) and\n\\(\\Phi(p) \\leqslant b\\) for both inductive steps to hold, we have to\ncompare \\(\\Psi(p)\\)~and~\\(\\Phi(p)\\), when \\(p\\)~is a natural number:\nwe have \\(\\Phi(1) < \\Psi(1)\\) and \\(\\Phi(2) < \\Psi(2)\\), but \\(\\Psi(p)\n< \\Phi(p)\\) if \\(p \\geqslant 3\\). Therefore, for~\\(b\\) not to depend\non~\\(p\\), we need it to be greater than~\\(2\\), the smallest upper\nbound of~\\(\\Phi\\)\nand~\\(\\Psi\\). Inequality~\\eqref{ineq:base_lower_Atms} means that we\nneed to minimise~\\(b\\) in order to maximise~\\(a\\) (which is the\npriority), so we settle for the limit: \\(b_{\\min} = 2\\), and the same\ninequality entails \\(a \\leqslant -3/2\\), hence \\(a_{\\max} =\n-3/2\\). The principle of complete induction finally establishes that,\nfor \\(n \\geqslant 2\\),\n\\begin{equation}\n  n\\lg n - \\frac{3}{2} n + 2 < \\OM{\\fun{tms}}{n}.\n\\label{ineq:lower_Atms}\n\\end{equation}\nThis bound is not very good, but it was easy to obtain. We may recall\nthe lower bound when \\(n=2^p\\), in~\\eqref{ineq:M_join}\n\\vpageref{ineq:M_join}: \\(n\\lg n - \\alpha n + \\alpha <\n\\OM{\\fun{tms}}{n}\\), where \\(\\alpha \\simeq 1.264499\\). In fact,\n\\cite{FlajoletGolin_1994} proved\n\\begin{equation}\nn\\lg n - \\alpha n < \\OM{\\fun{tms}}{n}.\n\\label{ineq:best_lower_Atms}\n\\end{equation}\nAsymptotically, that bound is, up to the linear term, the same as for\nthe case \\(n=2^p\\). Our inductive method cannot reach this nice result\nbecause it yields sufficient conditions that are too strong, in\nparticular, we found no obvious way to get the decomposition\n\\(\\OM{\\fun{tms}}{2^p+i} = \\OM{\\fun{tms}}{2^p} + \\OM{\\fun{tms}}{i} +\n\\dots\\)\n\nNow, let us find the smallest real constants \\(a'\\)~and~\\(b'\\) such\nthat for \\(n \\geqslant 2\\), \\(\\OM{\\fun{tms}}{n} \\leqslant n\\lg n + a'n\n+ b'\\). The base case of \\(\\pred{H}{n}\\)\nin~\\eqref{ineq:base_lower_Atms} is here reversed: \\(2a' + b' + 1\n\\geqslant 0\\). Hence, in order to minimise~\\(a'\\), we need to\nmaximise~\\(b'\\). Furthermore, the conditions on~\\(b'\\) from the\ninductive steps are reversed as well with respect to~\\(b\\): \\(b'\n\\leqslant \\Phi(p)\\) and \\(b' \\leqslant \\Psi(p)\\). The base case is\n\\(\\pred{H}{2}\\), that is, \\(p=1\\), and we saw earlier that \\(\\Phi(1)\n\\leqslant \\Psi(1)\\), thus we must have \\(b'\\leqslant \\Phi(1) =\n1\\). The maximum value is thus \\(b'_{\\max} = 1\\). Finally, this\nimplies that \\(a'\\geqslant -1\\), thus \\(a'_{\\min} = -1\\).\n\nGathering the bounds, we hence established that\n\\begin{equation*}\nn\\lg n - \\frac{3}{2}n + 2 < \\OM{\\fun{tms}}{n} < n\\lg n - n + 1.\n\\end{equation*}\nTrivially, we have \\(\\OM{\\fun{tms}}{n} \\sim n\\lg n \\sim\n\\OW{\\fun{tms}}{n} \\sim 2 \\cdot \\OB{\\fun{tms}}{n}\\).\n\\cite{FlajoletGolin_1994} proved, using complex analysis the following\nvery strong result:\n\\begin{equation*}\n\\OM{\\fun{tms}}{n} = n\\lg n + B(\\lg n) \\cdot n + \\mathcal{O}(1),\n\\end{equation*}\nwhere \\(B\\)~is continuous, non\\hyp{}differentiable, periodic with\nperiod~\\(1\\), of mean value \\(-1.2481520\\). The notation\n\\(\\mathcal{O}(1)\\) is an instance of Bachmann's notation for an\nunknown positive constant. The maximum value of~\\(B(x)\\) is\napproximately \\(-1.24075\\), so\n\\begin{equation*}\n\\belowdisplayskip=0pt\n\\OM{\\fun{tms}}{n} = n\\lg n - (1.25 \\pm 0.01) \\cdot n + \\mathcal{O}(1).\n\\end{equation*}\n\\index{tms@$\\OM{\\fun{tms}}{n}$|)} \\index{merge sort!top-down\n  $\\sim$!average cost|)} \\index{merge sort!top-down $\\sim$|)}\n\n\n\\section{Bottom-up merge sort}\n\\label{sec:general_case}\n\\index{merge sort!bottom-up $\\sim$|(}\n\nInstead of cutting a stack of \\(n\\)~keys in two halves, we could split\ninto \\(2^{\\ceiling{\\lg n}-1}\\) and \\(n-2^{\\ceiling{\\lg n}-1}\\) keys,\nwhere the first number represents the highest power of~\\(2\\) strictly\nsmaller than~\\(n\\). For instance, if \\(n=11=2^3+2^1+2^0\\), we would\nsplit into \\(2^3=8\\) and \\(2^1+2^0=3\\). Of course, if \\(n=2^p\\), this\nstrategy, called \\emph{bottom\\hyp{}up}, coincides with that of\ntop\\hyp{}down merge sort, which, in terms of cost, is expressed as\n\\(\\OC{\\fun{bms}}{2^p} = \\OC{\\fun{tms}}{2^p} = \\C{\\Join}{p}\\), where\n\\fun{bms/1}\\index{bms@\\fun{bms/1}} implements \\emph{bottom\\hyp{}up\n  merge sort}. The difference between\ntop-down and bottom-up merge sort can be easily seen in the\n\\fig~\\ref{fig:top_vs_bot}.\n\\begin{figure}\n\\centering\n\\subfloat[Bottom-up\\label{fig:bot_up}]{%\n\\includegraphics{bot_up}}\n\\qquad\n\\subfloat[Top-down\\label{fig:top_down}]{%\n\\includegraphics{top_down}}\n\\caption{Comparing merge sorts on \\([6,3,2,4,1,5]\\)\n\\label{fig:top_vs_bot}}\n\\end{figure}\nIn all generality,\n\\begin{equation}\n\\OC{\\fun{bms}}{0} = \\OC{\\fun{bms}}{1} = 0,\n\\quad\n\\OC{\\fun{bms}}{n} = \\OC{\\fun{bms}}{2^{\\ceiling{\\lg n}-1}}\n+ \\OC{\\fun{bms}}{n - 2^{\\ceiling{\\lg n}-1}}\n+ \\OC{\\fun{mrg}}{2^{\\ceiling{\\lg n}-1},n - 2^{\\ceiling{\\lg n}-1}}.\n\\index{bms@$\\OC{\\fun{bms}}{n}$}\n\\label{eq:cost_bms}\n\\end{equation}\n\n\\Fig~\\vref{fig:bot_up2} shows the merge tree\\index{tree!merge $\\sim$}\nof seven keys being sorted in that fashion. Note how the bottommost\nsingleton \\([4]\\) is merged with \\([2,6]\\), a stack twice as long. The\nimbalance in length is further propagated upwards. The general case is\nbetter suggested by retaining at each node only the length of the\nassociated stack, as shown in \\fig~\\vref{fig:msort_abs}.\n\\begin{figure}\n\\centering\n\\subfloat[Merge tree of \\({[}7,3,5,1,6,2,4{]}\\)\\label{fig:bot_up2}]{%\n\\includegraphics[bb=58 632 192 721]{bot_up2}}\n\\qquad\n\\subfloat[Lengths only\\label{fig:msort_abs}]{%\n\\includegraphics[bb=71 632 161 721]{msort_abs}}\n\\caption{Sorting seven keys}\n\\end{figure}\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\\mypar{Minimum cost}\n\\index{merge sort!bottom-up $\\sim$!minimum cost|(}\n\nLet \\(\\OB{\\fun{bms}}{n}\\)\\index{bms@$\\OB{\\fun{bms}}{n}$|(} be the\nminimum cost for sorting \\(n\\)~keys, bottom\\hyp{}up. Let \\(n=2^p+i\\),\nwith \\(0 < i < 2^p\\). Then, from equation~\\eqref{eq:cost_bms},\n\\vpageref{eq:cost_bms}, and~\\eqref{eq:best_merge}\n\\vpageref{eq:best_merge}, we deduce\n\\begin{equation*}\n\\OB{\\fun{bms}}{2^p+i} = \\OB{\\fun{bms}}{2^p} + \\OB{\\fun{bms}}{i} + i,\n\\end{equation*}\nwhich we recognise as an instance of the following functional\nequations: \\(f(0)=f(1)=0\\), \\(f(2)=1\\) and \\(f(2^p+i) = f(2^p) + f(i)\n+ i\\), where \\(f=\\OB{\\fun{tms}}{}\\) as seen in\nequation~\\eqref{eq:OBtms_2m_i} \\vpageref{eq:OBtms_2m_i}. Therefore,\n\\begin{equation}\n\\OB{\\fun{bms}}{n} = \\OB{\\fun{tms}}{n} = \\sum_{k=0}^{n-1}{\\nu_k}.\n\\label{eq:OBbms}\n\\end{equation}\nWe can thus reuse the bounds on \\(\\OB{\\fun{tms}}{n}\\):\n\\begin{equation}\n\\frac{1}{2}n\\lg n - \\left(\\frac{1}{2}\\lg\\frac{4}{3}\\right)n + \\lg\\frac{4}{3}\n\\leqslant \\OB{\\fun{bms}}{n} \\leqslant\n\\frac{1}{2}n\\lg n.\n\\index{bms@$\\OB{\\fun{bms}}{n}$}\n\\end{equation}\nThe lower bound is tight for \\(n=2\\) and most accurate when \\(n\\)~is a\nJacobsthal\\index{Jacobsthal number} number (see\nequations~\\eqref{eq:Jacobsthal} \\vpageref{eq:Jacobsthal}). The upper\nbound is tight when \\(n=2^p\\).\n\\index{bms@$\\OB{\\fun{bms}}{n}$|)}\n\\index{merge sort!bottom-up $\\sim$!minimum cost|)}\n\n\\mypar{Maximum cost}\n\\index{merge sort!bottom-up $\\sim$!maximum cost|(}\n\nLet \\(\\OW{\\fun{bms}}{n}\\)\\index{bms@$\\OW{\\fun{bms}}{n}$|(} be the\nmaximum cost for sorting \\(n\\)~keys, bottom\\hyp{}up. Let \\(n=2^p+i\\),\nwith \\(0 < i < 2^p\\). Then, from equation~\\eqref{eq:cost_bms},\n\\vpageref{eq:cost_bms}, and~\\eqref{eq:worst_merge}\n\\vpageref{eq:worst_merge}, we deduce\n\\begin{equation}\n\\OW{\\fun{bms}}{2^p+i} = \\OW{\\fun{bms}}{2^p} + \\OW{\\fun{bms}}{i} + 2^p\n+ i - 1.\n\\label{eq:Wbms_2p_i}\n\\end{equation}\nLet us search a lower bound of \\(\\OW{\\fun{bms}}{n}\\) by induction\nbased on that equation. Let us find the greatest real constants\n\\(a\\)~and~\\(b\\) such that, for \\(n \\geqslant 2\\),\n\\begin{equation*}\nn\\lg n + an + b \\leqslant \\OW{\\fun{bms}}{n}.\n\\end{equation*}\nThe base case is \\(n=2\\), that is, \\(b \\leqslant -2a - 1\\). Let us\nassume the bound holds for \\(n=i\\) and let us recall\nequation~\\eqref{eq:worst_power} \\vpageref{eq:worst_power}, which here\ntakes the guise of \\(\\OW{\\fun{bms}}{2^p} = p2^p - 2^p  +\n1\\). Then~\\eqref{eq:Wbms_2p_i} yields\n\\begin{equation*}\n(p2^p - 2^p + 1) + (i\\lg i + ai + b) + 2^p + i - 1 \\leqslant\n\\OW{\\fun{bms}}{2^p+i},\n\\end{equation*}\nwhich is equivalent to \\(p2^p + i\\lg i + i + ai + b \\leqslant\n\\OW{\\fun{bms}}{2^p+i}\\). We want to prove the bound holds for\n\\(n=2^p+i\\), that is, \\((2^p+i)\\lg(2^p+i) + a(2^p+i) + b \\leqslant\n\\OW{\\fun{bms}}{2^p+i}\\). Clearly, this is true if the following\nstronger constraint holds:\n\\begin{equation*}\n(2^p+i)\\lg(2^p+i) + a(2^p+i) + b \\leqslant p2^p + i\\lg i + i + ai + b.\n\\end{equation*}\nIt is equivalent to \\(a2^p \\leqslant p2^p - (2^p+i)\\lg(2^p+i) + i\\lg i\n+ i\\). Let us extend~\\(i\\) over the real numbers by defining \\(i=x2^p\\),\nwhere \\(x\\)~is a real number such that \\(0 < x \\leqslant 1\\). Then,\nthe running inequality is equivalent to\n\\begin{equation*}\na \\leqslant \\Phi(x),\\; \\text{where \\(\\Phi(x) := x\\lg x -\n  (1+x)\\lg(1+x) + x\\).}\n\\end{equation*}\nThe function~\\(\\Phi\\) can be continuously extended at~\\(0\\), as\n\\(\\lim_{x \\to 0} x\\lg x = 0\\), and it is differentiable on the\nclosed interval \\([0,1]\\):\n\\begin{equation*}\n\\frac{d\\Phi}{dx} = \\lg\\frac{2x}{x+1}.\n\\end{equation*}\nThe root of \\(d\\Phi/dx = 0\\) is~\\(1\\), the derivative is negative\nbefore, and positive after; so~\\(\\Phi\\) decreases until \\(x=1\\):\n\\(a_{\\max} := \\min_{0 \\leqslant x \\leqslant 1}\\Phi(x) = \\Phi(1)\n= -1\\). From the base case, \\(b_{\\max} := -2a_{\\max} - 1 =\n1\\). Therefore, we have\n\\begin{equation*}\nn\\lg n - n + 1 \\leqslant \\OW{\\fun{bms}}{n}.\n\\end{equation*}\nThe bound is tight when \\(x=1\\), that is, \\(i=2^p\\), hence\n\\(n=2^{p+1}\\).\n\nLet us find the smallest real constants \\(a'\\)~and~\\(b'\\) such that,\nfor \\(n \\geqslant 2\\),\n\\begin{equation*}\n\\OW{\\fun{bms}}{n} \\leqslant n\\lg n + a'n + b'.\n\\end{equation*}\nThe difference with the lower bound is that the inequalities are\nreversed and we minimise the unknowns, instead of maximising\nthem. Thus, the base case here is \\(b' \\geqslant -2a - 1\\) and the\ncondition for induction is \\(a' \\geqslant \\Phi(x)\\). We know the\nbehaviour of~\\(\\Phi\\), so \\(a'_{\\min} := \\max_{0 \\leqslant x \\leqslant\n  1}\\Phi(x) = \\Phi(0) = 0\\), and \\(b'_{\\min} := -2a'_{\\min} - 1 =\n-1\\). As a conclusion,\n\\begin{equation}\nn\\lg n - n + 1 \\leqslant \\OW{\\fun{bms}}{n} < n\\lg n - 1.\n\\label{ineq:OWbms}\n\\end{equation}\nBecause \\(\\Phi(x)\\) was extended at~\\(x=0\\), the upper bound is best\napproched when \\(i=1\\), the smallest possible integer value, that is,\nwhen \\(n=2^p+1\\) (the most unbalanced merger: stacks of size \\(2^p\\)\nand~\\(1\\)). A deeper study by \\cite{PannyProdinger_1995}, based on\nFourier analysis, confirms that the linear terms of these bounds\ncannot be improved and shows the mean value of the coefficient of the\nlinear term to be, approximately, \\(-0.70057\\).\n\n\\paragraph{Alternative expression}\n\nWhile we already bounded \\(\\OW{\\fun{bms}}{n}\\) tightly, we may learn\nsomething more about it by expressing it differently from its\ndefinition, in a way more suitable to elementary computations as well.\nIn all generality, let us set \\(n := 2^{e_r} + \\dots + 2^{e_1} +\n2^{e_0} > 0\\), with \\(e_r > \\dots > e_1 > e_0 \\geqslant 0\\) and \\(r\n\\geqslant 0\\).  We used this decomposition in\n\\begin{wrapfigure}[9]{r}[0pt]{0pt}\n\\centering\n\\includegraphics[bb=71 631 202 707]{msort_gen}\n\\caption{\\(\\sum_{j=0}^{r}2^{e_j}\\) keys\n\\label{fig:msort_gen}}\n\\end{wrapfigure}\nequation~\\eqref{eq:e_r} on page~\\pageref{eq:e_r}. Let us consider in\n\\fig~\\ref{fig:msort_gen} the tree\\index{tree!merge $\\sim$|(} of all\nthe mergers when we only retain the stacks lengths. The triangles are\nsubtrees made of \\emph{balanced mergers}, that is, mergers performed\non stacks of same length, for which we already found the number of\ncomparisons. The lengths of the \\emph{unbalanced mergers} are found in\nthe nodes from the root \\(2^{e_r}+ \\dots + 2^{e_0}\\) down to \\(2^{e_1}\n+ 2^{e_0}\\).\\index{tree!merge $\\sim$|)} In \\fig~\\vref{fig:Wn_even}\n\\begin{figure}\n\\centering\n\\subfloat[The sum of the nodes is \\(\\protect\\OW{\\protect\\fun{bms}}{n}\\)\n\\label{fig:w2p}]%\n{\\includegraphics[bb=62 602 199 721]{w2p}}\n\\qquad\n\\subfloat[The sum of the nodes is \\(\\protect\\OW{\\protect\\fun{bms}}{n+1}\\)\n\\label{fig:w2p_succ}]%\n{\\includegraphics[bb=71 604 214 721]{w2p_succ}}\n\\caption{Maximum-cost trees for \\(n\\)~even and \\(n+1\\)\n\\label{fig:Wn_even}}\n\\end{figure}\nare shown the maximum\\hyp{}cost trees for \\(n\\)~even and \\(n+1\\). The\nboxed expressions are not found in the opposite tree, therefore, the\nsum in each tree of the non\\hyp{}boxed terms is identical.\n\\begin{itemize}\n\n  \\item \\emph{If \\(n\\)~is even}, in \\fig~\\vref{fig:w2p}, this sum\n  is\\index{bms@$\\OW{\\fun{bms}}{n}$} \\(\\OW{\\fun{bms}}{n} - r\\). It\n  equals \\(\\OW{\\fun{bms}}{n+1} - 2^{e_0} - \\OW{\\fun{bms}}{2^0}\\) in\n  \\fig~\\vref{fig:w2p_succ}. Equating both counts yields\n    \\begin{equation}\n      \\OW{\\fun{bms}}{n} - r = \\OW{\\fun{bms}}{n+1} - 2^{e_0} -\n      \\OW{\\fun{bms}}{2^0}.\n      \\label{eq:OW1}\n    \\end{equation}\n    Let us explicit that \\(e_0\\)~is a function of~\\(n\\) (it is the\n    highest power of~\\(2\\) dividing~\\(n\\)): \\(e_0 :=\n    \\rho_n\\). Furthermore, we already know \\(\\nu_n = r+1\\) and\n    \\(\\OW{\\fun{bms}}{1} = 0\\). Setting \\(n=2k\\) in\n    equation~\\eqref{eq:OW1} is equivalent to\n    \\begin{equation}\n      \\OW{\\fun{bms}}{2k+1} = \\OW{\\fun{bms}}{2k} + 2^{\\rho_{2k}} +\n      \\nu_{2k} - 1.\n      \\label{eq:OWbms_2k_1_tmp}\n    \\end{equation}\n    The function \\(\\rho_n\\) is the \\emph{ruler\n      function} \\citep{GrahamKnuthPatashnik_1994,Knuth_2011},\n    \\index{ruler function@$\\rho_n$|see{ruler function}}\\index{ruler\n      function} which satisfies, for \\(n>0\\), the recurrences\n    \\begin{equation}\n      \\rho_{1} = 0,\\qquad \\rho_{2n} = \\rho_{n} + 1,\\qquad\n      \\rho_{2n+1} = 0,\\label{eq:ruler}\n    \\end{equation}\n    which are easily guessed from the binary notation of~\\(n\\) as\n    \\(\\rho_n\\)~simply counts the number of trailing zeros. This\n    enables us to slightly simplify equation~\\eqref{eq:OWbms_2k_1_tmp}\n    into\n    \\begin{equation}\n     \\OW{\\fun{bms}}{2k+1} = \\OW{\\fun{bms}}{2k} + 2 \\cdot 2^{\\rho_{k}}\n     + \\nu_{k} - 1.\n     \\label{eq:OWbms_2k_1}\n    \\end{equation}\n\n  \\item \\emph{If \\(n\\)~is odd}, we make\n    \\fig~\\vref{fig:w2p1},\n\\begin{figure}[t]\n\\centering\n\\subfloat[The sum of the nodes is \\(\\protect\\OW{\\protect\\fun{bms}}{n}\\)\n\\label{fig:w2p1}]{%\n\\includegraphics{w2p1}}\n\\qquad\n\\subfloat[The sum of the nodes is \\(\\protect\\OW{\\protect\\fun{bms}}{n+1}\\)\n\\label{fig:w2p1_succ}]{%\n\\includegraphics[bb=56 602 194 721]{w2p1_succ}}\n\\caption{Maximum-cost trees for \\(n\\)~odd and \\(n+1\\)\n\\label{fig:Wn_odd}}\n\\end{figure}\n     where the non\\hyp{}boxed expressions sum\n     \\(\\OW{\\fun{bms}}{n} - \\sum_{k=0}^{q-1}\\OW{\\fun{bms}}{2^k} -\n     \\sum_{k=2}^{q}2^k + 2((q-1)+(r-q+1)) = \\OW{\\fun{bms}}{n} -\n     \\sum_{k=0}^{q-1}((k-1)2^{k}+1) - \\sum_{k=2}^{q}2^k + 2r =\n     \\OW{\\fun{bms}}{n} - (q-1)2^q - q + 2r + 1\\), using\n     equation~\\eqref{eq:worst_power} and \\(\\sum_{k=0}^{q-1}k2^k =\n     (q-2)2^{q}+2\\). Indeed, let \\(S_{q} :=\n     \\sum_{k=0}^{q-1}{k2^{k-1}}\\). Then \\(S_{q} + q2^{q-1} = \\smash[t]{\\sum_{k=1}^{q}{k2^{k-1}}} = \\smash[t]{\\sum_{k=0}^{q-1}{(k+1)2^{k}}}\n= \\smash[t]{\\sum_{k=0}^{q-1}{k2^{k}}} + \\smash[t]{\\sum_{k=0}^{q-1}{2^{k}}}\n= 2 \\cdot S_{q} + 2^{q} - 1\\), hence\n     \\begin{equation}\n       \\abovedisplayskip=4pt\n       \\belowdisplayskip=4pt\n       S_{q} = \\smash[t]{\\textstyle\\sum_{k=1}^{q-1}{k2^{k-1}}} = (q-2)2^{q-1} + 1.\\label{eq:Sj}\n     \\end{equation}\n     The same sum in \\fig~\\ref{fig:w2p1_succ}\n     equals \\(\\OW{\\fun{bms}}{n+1} - \\OW{\\fun{bms}}{2^q} + (r-q+1) =\n     \\OW{\\fun{bms}}{n+1} - (q-1)2^{q} - q + r\\). Equating the two\n     quantities and simplifying yields\n     \\begin{equation*}\n       \\OW{\\fun{bms}}{n+1} = \\OW{\\fun{bms}}{n} + r + 1=\n       \\OW{\\fun{bms}}{n} + \\nu_n.\n     \\end{equation*}\n     Recalling the recurrences~\\eqref{def:nu} \\vpageref{def:nu} and\n     setting \\(n=2k-1\\), this equation is simplified into\n     \\begin{equation}\n       \\OW{\\fun{bms}}{2k} = \\OW{\\fun{bms}}{2k-1} + \\nu_{k-1} + 1.\n       \\label{eq:OWbms_2k}\n     \\end{equation}\n\n\\end{itemize}\nFrom equations~\\eqref{eq:OWbms_2k} and~\\eqref{eq:OWbms_2k_1}, we deduce\n\\begin{equation*}\n\\OW{\\fun{bms}}{2k+1} = \\OW{\\fun{bms}}{2k-1} + 2 \\cdot 2^{\\rho_k} +\n\\nu_{k-1} + \\nu_k,\\quad \\OW{\\fun{bms}}{2k+2} = \\OW{\\fun{bms}}{2k} + 2\n\\cdot 2^{\\rho_k} + 2\\nu_k.\n\\end{equation*}\nThese equations allow us to compute the values of\n\\(\\OW{\\fun{bms}}{n}\\) only with elementary operations. Furthermore,\nsumming on all sides yields\n\\begin{align}\n\\OW{\\fun{bms}}{2p+1}\n &= \\OW{\\fun{bms}}{1} + 2\\!\\sum_{k=1}^{p} 2^{\\rho_k} +\n    \\!\\sum_{k=1}^{p}\\nu_{k-1} + \\!\\sum_{k=1}^p\\nu_k\n  = 2 \\!\\sum_{k=1}^{p} 2^{\\rho_k}\\! + 2\\!\\sum_{k=1}^{p-1}\\nu_k +\n    \\!\\nu_p.\\label{eq:OWbms_2p_1}\\\\\n\\OW{\\fun{bms}}{2p}\n  &= \\OW{\\fun{bms}}{2} + 2\\sum_{k=1}^{p-1}2^{\\rho_k} +\n2\\sum_{k=1}^{p-1}\\nu_k\n  = 1 +  2\\sum_{k=1}^{p-1}2^{\\rho_k} + 2\\sum_{k=1}^{p-1}\\nu_k.\n\\label{eq:OWbms_2p}\n\\end{align}\nThese expressions involve two interesting number\\hyp{}theoretic\nfunctions, \\(\\sum_{k=1}^{p-1}2^{\\rho_k}\\) and\n\\(\\sum_{k=1}^{p-1}\\nu_k\\), the latter being \\(\\OB{\\fun{bms}}{p}\\), as\nfound in equation~\\eqref{eq:OBbms}.\\index{bms@$\\OW{\\fun{bms}}{n}$|)}\n\\index{merge sort!bottom-up $\\sim$!maximum cost|)}\n\n\n\\mypar{Average cost}\n\\index{merge sort!bottom-up $\\sim$!average cost|(}\n\nLet \\(\\OM{\\fun{bms}}{n}\\) be the average number of comparisons to sort\n\\(n\\)~keys bottom\\hyp{}up. All permutations of the input stack being\nequally likely, equation~\\eqref{eq:cost_bms} \\vpageref{eq:cost_bms}\nbecomes \\(\\OM{\\fun{bms}}{0} = \\OM{\\fun{bms}}{1} = 0\\)\\index{bms@$\\OM{\\fun{bms}}{n}$} and\n\\begin{equation*}\n\\OM{\\fun{bms}}{n} = \\OM{\\fun{bms}}{2^{\\ceiling{\\lg n}-1}}\n+ \\OM{\\fun{bms}}{n - 2^{\\ceiling{\\lg n}-1}}\n+ \\OM{\\fun{mrg}}{2^{\\ceiling{\\lg n}-1},n - 2^{\\ceiling{\\lg n}-1}},\n\\end{equation*}\nwhich, with equation~\\eqref{eq:Amrg}, in turn implies\n\\(\\OM{\\fun{bms}}{0} = \\OM{\\fun{bms}}{1} = 0\\) and\n\\begin{equation*}\n\\OM{\\fun{bms}}{n} = \\OM{\\fun{bms}}{2^{\\ceiling{\\lg n}-1}}\n+ \\OM{\\fun{bms}}{n - 2^{\\ceiling{\\lg n}-1}}\n+ n - \\frac{2^{\\ceiling{\\lg n}-1}}{n - 2^{\\ceiling{\\lg n}-1} + 1}\n- \\frac{n - 2^{\\ceiling{\\lg n}-1}}{2^{\\ceiling{\\lg n}-1}+1}.\n\\end{equation*}\nThis definition is quite daunting, so let us turn to induction to find\nbounds, as we did for \\(\\OB{\\fun{tms}}{n}\\) in\ninequality~\\eqref{ineq:McIlroy} \\vpageref{ineq:McIlroy}. Let us start\nwith the lower bound and set to maximise the real constants\n\\(a\\)~and~\\(b\\) in\n\\begin{equation*}\n\\pred{H}{n} \\colon n\\lg n + an + b \\leqslant \\OM{\\fun{bms}}{n},\n\\; \\text{for \\(n \\geqslant 2\\).}\n\\end{equation*}\nThe base case for induction is \\(\\pred{H}{2}\\):\n\\begin{equation}\n2a + b + 1 \\leqslant 0.\n\\label{ineq:base_lower_Btms}\n\\end{equation}\nLet us assume now \\(\\pred{H}{n}\\) for all \\(2 \\leqslant n \\leqslant\n2^p\\), and let us prove \\(\\pred{H}{2^p+i}\\), for all \\(0 < i \\leqslant\n2^p\\). The induction principle entails then that \\(\\pred{H}{n}\\)\nholds for any \\(n \\geqslant 2\\). If \\(n=2^p+i\\), then \\(\\ceiling{\\lg\n  n} - 1 = p\\), so\n\\begin{equation}\n\\OM{\\fun{bms}}{2^p+i} = \\OM{\\fun{bms}}{2^p} + \\OM{\\fun{bms}}{i}\n+ 2^p + i - \\frac{2^p}{i+1} - \\frac{i}{2^p+1}.\n\\label{eq:Abms_2p_i}\n\\end{equation}\nBy hypothesis, \\(\\pred{H}{i}\\) holds, that is, \\(i\\lg i + ai + b\n\\leqslant \\OM{\\fun{bms}}{i}\\), but, instead of using\n\\(\\pred{H}{2^p}\\), we will use the exact value in\nequation~\\eqref{eq:Mjoin} \\vpageref{eq:Mjoin}, where \\(\\alpha :=\n\\sum_{k \\geqslant 0}1/(2^k+1)\\). From equation~\\eqref{eq:Abms_2p_i},\nwe derive\n\\begin{equation*}\n(p-\\alpha)2^p + \\sum_{k \\geqslant\n    0}\\frac{1}{2^{k}+2^{-p}}\n+ (i\\lg i + ai + b) + 2^p + i -\n\\frac{2^p}{i+1} - \\frac{i}{2^p+1} < \\OM{\\fun{bms}}{2^p+i}.\n\\end{equation*}\nWe want to prove \\(\\pred{H}{2^p+i} \\colon (2^p+i)\\lg(2^p+i) +\na(2^p+i) + b \\leqslant \\OM{\\fun{bms}}{2^p+i}\\), which is thus implied\nby\n\\begin{equation*}\n(2^p+i)\\lg(2^p+i) + a2^p \\leqslant (p - \\alpha + 1)2^p -\n\\frac{2^p}{i+1} + i\\lg i + i - \\frac{i}{2^p+1} + c_p,\n\\end{equation*}\nwhere \\(c_p := \\sum_{k \\geqslant 0}1/(2^{k}+2^{-p})\\). Let\n\\begin{equation*}\n  \\Psi(p,i) := p - \\alpha + 1 - \\frac{1}{i+1} + \\frac{i}{2^p+1} -\n  \\frac{1}{2^p}((2^p+i)\\lg(2^p+i) - i\\lg i - c_p).\n\\end{equation*}\nThen the sufficient condition above is equivalent to \\(a \\leqslant\n\\Psi(p,i)\\). To study the behaviour of \\(\\Psi(p,i)\\), let us fix~\\(p\\)\nand let~\\(i\\) range over the real interval \\(]0,2^p]\\). The partial\nderivative of~\\(\\Psi\\) with respect to~\\(i\\) is\n\\begin{equation*}\n\\frac{\\partial\\Psi}{\\partial i}(p,i) = \\frac{1}{2^p+1}\n+ \\frac{1}{(i+1)^2} - \\frac{1}{2^p}\\lg\\left(\\frac{2^p}{i}+1\\right).\n\\end{equation*}\nLet us also determine the second derivative with respect to~\\(i\\):\n\\begin{equation*}\n\\frac{\\partial^2\\Psi}{\\partial i^2}(p,i) = \\frac{1}{(2^p+i)i\\ln 2} - \\frac{2}{(i+1)^3},\n\\end{equation*}\nwhere \\(\\ln x\\) is the natural logarithm of~\\(x\\). Let the cubic\npolynomial\n\\begin{equation*}\nK_p(i) := i^3 + (3 - 2\\ln 2)i^2 + (3 - 2^{p+1}\\ln 2)i + 1.\n\\end{equation*}\nThen \\(\\partial^2\\Psi/\\partial i^2 = 0 \\Leftrightarrow K_p(i) = 0\\)\nand the sign of \\(\\partial^2\\Psi/\\partial i^2\\) is the sign of\n\\(K_p(i)\\). In general, a cubic equation has the form\n\\begin{equation*}\nax^3 + bx^2 + cx + d = 0, \\; \\text{with \\(a \\neq 0\\)}.\n\\end{equation*}\nA classic result about the nature of the roots is as follows. Let the\n\\emph{discriminant}\\index{discriminant|(} of the cubic be \\(\\Delta :=\n18abcd - 4b^3d + b^2c^2 - 4ac^3 - 27a^2d^2\\).\n\\begin{enumerate}\n\n  \\item If \\(\\Delta > 0\\), the equation has three distinct real roots;\n\n  \\item if \\(\\Delta = 0\\), the equation has a multiple root and all\n    its roots are real;\n\n  \\item if \\(\\Delta < 0\\), the equation has one real root and two\n    nonreal complex conjugate roots.\n\n\\end{enumerate}\nLet us resume now our discussion. Let the cubic polynomial\n\\begin{equation*}\n\\Delta(x) \\!:= (4\\ln 2)x^3 - (9 - 2\\ln 2)(3 + 2\\ln 2)x^2 + 12(9 - 2\\ln\n29)x - 4(27 - 8\\ln 2).\n\\end{equation*}\nThen the discriminant of \\(K_p(i) = 0\\) is \\(\\Delta(2^{p+1}) \\cdot\n\\ln^2 2\\). The discriminant of \\(\\Delta(x) = 0 \\) is negative, thus\n\\(\\Delta(x)\\) has one real root~\\(x_0 \\simeq 8.64872\\). Because the\ncoefficient of~\\(x^3\\) is positive, \\(\\Delta(x)\\) is negative if \\(x <\nx_0\\) and positive if \\(x > x_0\\).\n\\begin{enumerate}\n\n  \\item Since \\(p \\geqslant 3\\) implies \\(2^{p+1} > x_0\\), the\n    discriminant\\index{discriminant|)} of \\(K_p(i) = 0\\) is positive,\n    which means that \\(K_p(i)\\) has three distinct real roots if \\(p\n    \\geqslant 3\\), and so does \\(\\partial^2\\Psi/\\partial\n    i^2\\).\n\n  \\item Otherwise, \\(K_p(i)\\) has one real root if \\(0 \\leqslant p\n    \\leqslant 2\\).\n\n\\end{enumerate}\nBefore we study these two cases in detail, we need a small reminder\nabout cubic polynomials. Let \\(\\rho_0\\), \\(\\rho_1\\) and~\\(\\rho_2\\) be\nthe roots of \\(P(x) = ax^3 + bx^2 + cx + d\\). So \\(P(x) =\na(x-\\rho_0)(x-\\rho_1)(x-\\rho_2) = ax^3 - a(\\rho_0+\\rho_1+\\rho_2)x^2 +\na(\\rho_0\\rho_1 + \\rho_0\\rho_2 + \\rho_1 \\rho_2)x -\na(\\rho_0\\rho_1\\rho_2)\\), so \\(\\rho_0\\rho_1\\rho_2 = -d/a\\).\n\\begin{enumerate}\n\n  \\item Let \\(p \\in \\{0,1,2\\}\\). We just found that \\(K_p(i)\\) has one\n    real root, say~\\(\\rho_0\\), and two nonreal conjugate roots,\n    say~\\(\\rho_1\\) and \\(\\rho_2=\\overline{\\rho_1}\\). Then\n    \\(\\rho_0\\rho_1\\rho_2 = \\rho_0 \\len{\\rho_1}^2 = -1\\), so \\(\\rho_0 <\n    0\\). Since the coefficient of~\\(x^3\\) is positive, this entails\n    that \\(K_p(i) > 0\\) if \\(i > 0\\), which is true for\n    \\(\\partial^2\\Psi/\\partial i^2\\) as well: \\(i > 0 \\) implies\n    \\(\\partial^2\\Psi/\\partial i^2 > 0\\), therefore\n    \\(\\partial\\Psi/\\partial i\\) increases. Since\n  \\begin{equation*}\n    \\frac{\\partial\\Psi}{\\partial i}(p,i) \\xrightarrow[i\\to 0^{+}]{}\n    -\\infty < 0, \\;\\text{and}\\; \\left.\\frac{\\partial\\Psi}{\\partial\n        i}(p,i)\\right|_{i=2^p} = -\\frac{1}{2^p(2^p+1)^2} < 0,\n  \\end{equation*}\n  we deduce that \\(\\partial\\Psi/\\partial i < 0\\) if \\(i > 0\\), which\n  means that \\(\\Psi(p,i)\\) decreases when \\(i \\in\\; ]0,2^p]\\). Since\n  we are looking to minimise \\(\\Psi(p,i)\\), we have \\(\\min_{0 < i\n    \\leqslant 2^p}\\Psi(p,i) = \\Psi(p,2^p)\\).\n\n\\item If \\(p \\geqslant 3\\), then \\(K_p(i)\\) has three real\n  roots. Here, the product of the roots of \\(K_p(i)\\) is~\\(-1\\), so at\n  most two of them are positive. Since we have \\(K_p(0) = 1 > 0\\),\n  \\(K_p(1) < 0\\) and \\(\\lim_{i\\to+\\infty}K_p(i) > 0\\), we see that\n  \\(K_p(i)\\) has one root in \\(]0,1[\\) and one in \\(]1,+\\infty[\\), and\n  so does \\(\\partial^2\\Psi/\\partial i^2\\). Furthermore,\n  \\(\\left.\\partial\\Psi/\\partial i\\right|_{i=1} > 0\\) and\n  \\(\\left.\\partial\\Psi/\\partial i\\right|_{i=2^p} < 0\\), therefore,\n  from the intermediate theorem, there exists a real~\\(i_p \\in\\;\n  ]1,2^p[\\) such that \\(\\left.\\partial\\Psi/\\partial i\\right|_{i=i_p} =\n  0\\), and we know that it is unique because \\(\\partial\\Psi^2/\\partial\n  i^2\\) changes sign only once in \\(]1,+\\infty[\\). This also means\n  that \\(\\Psi(p,i)\\) increases if~\\(i\\) increases on \\([1,i_p[\\),\n  reaches its maximum when \\(i=i_p\\), and then decreases on\n  \\(]i_p,2^p]\\). Since \\(\\lim_{i \\to 0^{+}}\\Psi(p,i) = -\\infty\\) and\n  we are searching for a lower bound of \\(\\Psi(p,i)\\), we need to know\n  which of \\(i=1\\) or \\(i=2^p\\) minimises \\(\\Psi(p,i)\\): actually, we\n  have \\(\\Psi(p,1) \\geqslant \\Psi(p,2^p)\\), so we conclude \\(\\min_{0 <\n    i \\leqslant 2^p}\\Psi(p,i) = \\Psi(p,2^p)\\).\n\\end{enumerate}\nIn any case, we need to minimise \\(\\Psi(p,2^p)\\). We have:\n\\begin{equation*}\n\\Psi(p,2^p) = - \\frac{1}{2^p+1} - \\sum_{k=0}^{p}\\frac{1}{2^k+1}.\n\\end{equation*}\nWe check that \\(\\Psi(p,2^p) > \\Psi(p+1,2^{p+1})\\), so the function\ndecreases for integer points and \\(a_{\\max} = \\min_{p > 0}\\Psi(p,2^p)\n= \\lim_{p \\to \\infty}\\Psi(p,2^p) = -\\alpha^{+}\\). From\ninequation~\\eqref{ineq:base_lower_Btms}, we draw \\(b_{\\max} =\n-2a_{\\max} - 1 = 2\\alpha - 1 \\simeq 1.52899\\). In total, by the\nprinciple of induction, we have established, for \\(n \\geqslant 2\\),\n\\begin{equation*}\nn\\lg n - \\alpha n + 2\\alpha -1 < \\OM{\\fun{bms}}{n}.\n\\end{equation*}\nThis bound is better than for the average cost of top\\hyp{}down merge\nsort, inequation~\\eqref{ineq:lower_Atms} \\vpageref{ineq:lower_Atms},\nbecause there, we had to decompose~\\(n\\) into even and odd values, not\n\\(n=2^p+i\\) which allowed us here to use the exact value of\n\\(\\OM{\\fun{bms}}{2^p}\\). It is even slightly better\nthan~\\eqref{ineq:M_join} \\vpageref{ineq:M_join}, which is quite a nice\nsurprise.\n\nWe need now to work out an upper bound using the same technique. In\nother words, we want to minimise the real constants \\(a'\\)~and~\\(b'\\)\nin \\(\\OM{\\fun{bms}}{n} \\leqslant n\\lg n + a'n + b'\\), for \\(n\n\\geqslant 2\\). The difference with the lower bound is that the\ninequations are reversed: \\(a'\\geqslant \\Psi(p,i)\\) and \\(b' \\geqslant\n-2a' - 1\\). We revisit the two cases above:\n\\begin{enumerate}\n\n  \\item If \\(0 \\leqslant p \\leqslant 2\\), then \\(\\max_{0 < i \\leqslant\n    2^p}\\Psi(p,i) = \\Psi(p,1)\\). We easily check that \\(\\max_{0\n    \\leqslant p \\leqslant 2}\\Psi(p,1) = \\Psi(0,1) = 1 - \\alpha\\).\n\n  \\item If \\(p \\geqslant 3\\), we need to express \\(i_p\\)~as a function\n    of~\\(p\\), but it is hard to solve the equation\n    \\(\\left.\\partial\\Psi/\\partial i\\right|_{i=i_p} = 0\\), even\n    approximately.\n\n\\end{enumerate}\nBefore giving up, we could try to differentiate~\\(\\Psi\\) with respect\nto~\\(p\\), instead of~\\(i\\). Indeed, \\((p,i,\\Psi(p,i))\\) defines a\nsurface in space, and by privileging \\(p\\)~over~\\(i\\), we are slicing\nthe surface along planes perpendicular to the \\(i\\)~axis. Sometimes,\nslicing in one direction instead of another makes the analysis\neasier. The problem here is to differentiate~\\(c_p\\). We can work our\nway round with the bound \\(c_p < 2\\) from~\\eqref{ineq:M_join}\n\\vpageref{ineq:M_join} and define\n\\begin{equation*}\n  \\Phi(p,i) := p - \\alpha + 1 - \\frac{1}{i+1} + \\frac{i}{2^p+1} -\n  \\frac{1}{2^p}((2^p+i)\\lg(2^p+i) - i\\lg i - 2).\n\\end{equation*}\nNow we have \\(\\Psi(p,i) < \\Phi(p,i)\\) and, instead of \\(\\Psi(p,i)\n\\leqslant a'\\), we can impose the stronger constraint \\(\\Phi(p,i)\n\\leqslant a'\\) and cross our fingers. In \\fig~\\vref{fig:phi},\n\\begin{figure}\n\\centering\n\\includegraphics[bb=71 565 400 725]{phi}\n\\caption{\\(\\Phi(p,1)\\), \\(\\Phi(p,2)\\) and \\(\\Phi(p,3)\\)\\label{fig:phi}}\n\\end{figure}\nare outlined \\(\\Phi(p,1)\\), \\(\\Phi(p,2)\\) and \\(\\Phi(p,3)\\). (The\nstarting point for each curve is marked by a white disk.)\nDifferentiating with respect to~\\(p\\) yields\n\\begin{equation*}\n\\frac{\\partial\\Phi}{\\partial p}(p,i) =\n\\frac{i}{2^p}\\ln\\left(\\frac{2^p}{i}+1\\right)\n- \\frac{\\ln 2}{2^{p-1}} - \\frac{i2^p\\ln 2}{(2^p+1)^2}.\n\\end{equation*}\nTo study the sign of \\(\\partial\\Phi(p,i)/\\partial p\\) when~\\(p\\)\nvaries, let us define\n\\begin{equation*}\n\\varphi(x,i) := \\frac{x}{i\\ln 2} \\cdot\n                \\left.\\frac{\\partial\\Phi}{\\partial\n                    p}(p,i)\\right|_{p=\\lg x}.\n\\end{equation*}\nBecause \\(x \\geqslant 1\\) implies \\(x/i\\ln 2 > 0\\) and \\(\\lg x\n\\geqslant 0\\), the sign of \\(\\varphi(x,i)\\) when~\\(x \\geqslant 1\\)\nvaries is the same as the sign of \\(\\partial\\Phi(p,i)/\\partial p\\)\nwhen~\\(p \\geqslant 0\\) varies, bearing in mind that \\(x=2^p\\). We\nhave\n\\begin{align*}\n\\varphi(x,i) &= \\lg\\left(\\frac{x}{i}+1\\right) -\n\\left(\\!\\frac{x}{x+1}\\!\\right)^2 - \\frac{2}{i},\\\\\n\\frac{\\partial\\varphi}{\\partial x}(x,i) &=\n\\frac{1}{(x+i)\\ln 2} - \\frac{2x}{(x+1)^3}.\n\\end{align*}\nThis should remind us of a familiar sight:\n\\begin{equation*}\n\\frac{\\partial\\varphi}{\\partial x}(x,i) =\n  x \\cdot \\left.\\frac{\\partial^2\\Psi}{\\partial x^2}(p,x)\\right|_{p=\\lg\n  i}.\n\\end{equation*}\nWhen \\(x \\geqslant 1\\) varies, the sign of\n\\(\\partial\\varphi(x,i)/\\partial x\\) is the same as the sign of\n\\(\\left.\\partial^2\\Psi(p,x)/\\partial x^2\\right|_{p=\\lg i}\\), so we can\nreuse the previous discussion on the roots of \\(K_p(i)\\), while taking\ncare to replace~\\(i\\) by~\\(x\\), and~\\(2^p\\) by~\\(i\\):\n\\begin{enumerate}\n\n  \\item If \\(i \\in \\{1,2,3,4\\}\\), then \\(\\partial\\varphi(x,i)/\\partial\n    x > 0\\) when \\(x > 0\\).\n\n  \\item If \\(i \\geqslant 5\\), then \\(\\partial\\varphi(x,i)/\\partial x >\n    0\\) when \\(x \\geqslant 1\\).\n\n\\end{enumerate}\nIn both cases, \\(\\varphi(x,i)\\) increases when \\(x \\geqslant 1\\),\nwhich, with the facts that \\(\\lim_{x\\to 0^{+}}\\varphi(x,i) = -\\infty <\n0\\) and \\(\\lim_{x\\to\\infty}\\varphi(x,i) = +\\infty > 0\\), entails that\nthere exists a unique root~\\(\\rho > 0\\) such that \\(\\varphi(x,i) < 0\\)\nif \\(x < \\rho\\), and \\(\\varphi(x,i) > 0\\) if \\(x > \\rho\\), and the\nsame holds for \\(\\partial\\Phi/\\partial p\\) (with a different\nroot). Concordantly, \\(\\Phi(p,i)\\) is decreasing down to its minimum,\nand increasing afterwards. (See again \\fig~\\vref{fig:phi}.)\n\nMoreover \\(\\overline\\lim_{p \\to \\infty}\\Phi(p,i) = i/(i+1) - \\alpha <\n1 - \\alpha = \\Phi(0,1)\\), so the curves have asymptotes. Since we are\nsearching for the maximum, we deduce: \\(a'_{\\min} = \\max_{0 < i\n  \\leqslant 2^p}\\Phi(p,i) = 1 - \\alpha \\simeq -0.2645\\), and the\nconstant is \\(b'_{\\min} = -2a'_{\\min} - 1 = 2\\alpha - 3 \\simeq\n-0.471\\). In sum, we found, for \\(n \\geqslant 2\\),\n\\begin{equation}\nn\\lg n - \\alpha n + (2\\alpha - 1) < \\OM{\\fun{bms}}{n}\n< n\\lg n - (\\alpha - 1)n - (3 - 2\\alpha).\n\\label{ineq:bounds_Mbms}\n\\end{equation}\nThe lower bound is most accurate when \\(n=2^p\\). To interpret the\nvalues of~\\(n\\) for which the upper bound is most accurate, we need\nanother glance at \\fig~\\vref{fig:phi}. We have \\(i/(i+1) - \\alpha \\to\n1 - \\alpha\\), as \\(p \\to \\infty\\), but this does not tell us anything\nabout~\\(p\\). Unfortunately, as noted earlier, for a given~\\(p\\), we\ncannot characterise explicitly~\\(i_p\\), which is the value of~\\(i\\)\nmaximising \\(\\Phi(p,i)\\) (in the planes perpendicular to this\npage). Anyway, the linear terms of these bounds cannot be improved\nupon. This means that the additional number of comparisons incurred by\nsorting \\(n=2^p+i\\) keys instead of~\\(2^p\\) is at most~\\(n\\). As with\ntop\\hyp{}down merge sort, more advanced mathematics by\n\\cite{PannyProdinger_1995} show that \\(\\OM{\\fun{bms}}{n} = n\\lg n +\nB^*(\\lg n) \\cdot n\\)\\index{bms@$\\OM{\\fun{bms}}{n}$}, where \\(B^*\\)~is\na continuous, non\\hyp{}differentiable, periodic function whose average\nvalue is approximately \\(-0.965\\). Obviously, we have\n\\(\\OM{\\fun{bms}}{n} \\sim n\\lg n \\sim \\OW{\\fun{bms}}{n} \\sim 2 \\cdot\n\\OB{\\fun{bms}}{n}\\).\n\\index{merge sort!bottom-up $\\sim$!average cost|)}\n\n\\mypar{Program}\n\\index{merge sort!bottom-up $\\sim$!program}\n\nWe managed to analyse the number of comparisons to sort by merging\nbecause the whole process can easily be depicted as a\ntree\\index{tree!merge $\\sim$|(}. It is time to provide a program whose\ntraces conform to these merge trees. In \\fig~\\vref{fig:bms} is shown\nthe definitions of the main sorting function\n\\fun{bms/1}\\index{bms@\\fun{bms/1}} and several auxiliaries.\n\\begin{itemize}\n\n  \\item The call \\(\\fun{solo}(s)\\)\\index{solo@\\fun{solo/1}} is a stack\n    containing singletons with all the keys of~\\(s\\) in the same\n    order. In other words, it is the leaves of the merge tree.\n\n  \\item The call \\(\\fun{all}(u)\\)\\index{all@\\fun{all/1}} is a stack\n    containing stacks which are the result of merging adjacent stacks\n    in~\\(u\\). In other words, it is the level just above~\\(u\\) in the\n    merge tree.\n\n  \\item The call \\(\\fun{all}(\\fun{solo}(s))\\) is the sorted stack\n    corresponding to the stack of singletons~\\(\\fun{solo}(s)\\). In\n    other words, starting with the leaves, it keeps building levels up\n    by calling \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} until the root of\n    the merge tree is reached.\n\n\\end{itemize}\nWhat is beautiful about this program is that there is no need for two\ndistinct phases, first building the perfect merge trees and then\nperforming the unbalanced mergers with the roots of these: it is\npossible to achieve the same effect by interleaving rightwards and\nupwards constructions.\\index{tree!merge $\\sim$|)}\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l}\n  \\fun{bms}(\\el) & \\xrightarrow{\\smash{\\mu}} & \\el;\n& \\fun{solo}(\\el) & \\xrightarrow{\\smash{\\xi}} & \\el;\\\\\n  \\fun{bms}(s) & \\xrightarrow{\\smash{\\nu}}\n               & \\fun{all}(\\fun{solo}(s)).\n& \\fun{solo}(\\cons{x}{s}) & \\xrightarrow{\\smash{\\pi}}\n                          & \\cons{[x]}{\\fun{solo}(s)}.\\\\\n\\\\\n  \\fun{all}([s]) & \\xrightarrow{\\smash{\\rho}} & s;\n& \\fun{nxt}(\\cons{s,t}{u}) & \\xrightarrow{\\smash{\\tau}}\n                         & \\cons{\\fun{mrg}(s,t)}{\\fun{nxt}(u)};\\\\\n  \\fun{all}(s) & \\xrightarrow{\\smash{\\sigma}}\n               & \\fun{all}(\\fun{nxt}(s)).\n& \\fun{nxt}(u) & \\xrightarrow{\\smash{\\upsilon}} & u.\\\\\n\\\\\n\\fun{mrg}(\\el,t)         & \\xrightarrow{\\smash{\\theta}} & t;\\\\\n\\fun{mrg}(s,\\el)         & \\xrightarrow{\\smash{\\iota}} & s;\\\\\n\\fun{mrg}(\\cons{x}{s},\\cons{y}{t}) & \\xrightarrow{\\smash{\\kappa}}\n& \\multicolumn{4}{@{}l}{\\cons{y}{\\fun{mrg}(\\cons{x}{s},t)},\n\\;\\text{if \\(x \\succ y\\);}}\\\\\n\\fun{mrg}(\\cons{x}{s},t) & \\xrightarrow{\\smash{\\lambda}}\n                         & \\cons{x}{\\fun{mrg}(s,t)}.\n\\end{array}}\n\\end{equation*}\n\\caption{Sorting by bottom-up mergers with \\fun{bms/1}\\label{fig:bms}}\n\\end{figure}\n\n\n\\paragraph{Additional cost}\n\nIn order to determine the cost\n\\(\\C{\\fun{bms}}{n}\\)\\index{bms@$\\C{\\fun{bms}}{n}$} we need to add to\nthe number of comparisons the number of rewrite steps that do not\ninvolve comparisons, that is, other than by rules\n\\(\\kappa\\)~and~\\(\\lambda\\).\n\\begin{itemize}\n\n  \\item Rules \\(\\theta\\)~and~\\(\\iota\\) are used once to conclude each\n  merger. Let \\(\\OC{\\ltimes}{n}\\)\\index{mrg@$\\OC{\\ltimes}{n}$} be the\n  number of comparisons to perform the unbalanced mergers when there\n  are \\(n\\)~keys to sort. Looking back at \\fig~\\vref{fig:msort_gen},\n  we see that\n    \\begin{equation}\n      \\OC{\\ltimes}{n} :=\n      \\sum_{i=1}^{r}{\\OC{\\fun{mrg}}{2^{e_i},2^{e_{i-1}}+\\dots+2^{e_0}}}.\n      \\label{eq:C_unbal}\n    \\end{equation}\n    The total number of comparisons is the sum of the numbers of\n    comparisons of the balanced and unbalanced mergers:\n    \\begin{equation}\n      \\OC{\\fun{bms}}{n}\n      = \\sum_{i=0}^{r}{\\C{\\Join}{e_i}}\n      +\n      \\OC{\\ltimes}{n}\n      = \\sum_{i=0}^{r}{\\OC{\\fun{bms}}{2^{e_i}}}\n      +\n      \\sum_{i=1}^{r}{\\OC{\\fun{mrg}}{2^{e_i},2^{e_{i-1}}+\\dots+2^{e_0}}}.\n      \\label{eq:msort_gen}\n    \\end{equation}\n    To find the number of mergers, let us set \\(\\OC{\\fun{mrg}}{m,n} =\n    1\\) in equation~\\eqref{eq:cost_power_2}\n    \\vpageref{eq:cost_power_2}, yielding \\(\\OC{\\fun{bms}}{2^p} = 2^p -\n    1\\). By plugging this result in equation~\\eqref{eq:msort_gen}, we\n    draw \\(\\OC{\\fun{bms}}{n} = n - 1\\). In other words, rules\n    \\(\\theta\\)~and~\\(\\iota\\) are used \\(n-1\\)\\label{eq:bms_merges}\n    times in total.\\index{bms@$\\OC{\\fun{bms}}{n}$}\n\n  \\item In rule~\\(\\tau\\), one call\n    \\(\\fun{nxt}(\\cons{s,t}{u})\\)\\index{nxt@\\fun{nxt/1}} corresponds to\n    one call \\(\\fun{mrg}(s,t)\\)\\index{mrg@\\fun{mrg/2}}, one for each\n    merger. Therefore, \\(\\tau\\)~is used \\(n-1\\)~times.\n\n  \\item Rule~\\(\\upsilon\\) is used once for each level in the merge\n    tree\\index{tree!merge $\\sim$}, except the root, with~\\(u\\) either\n    empty or a singleton.  Let~\\(\\Lambda(j)\\) be the number of nodes\n    at level~\\(j\\), where \\(j=0\\) represents the level of the\n    leaves. Then, the number~\\(z\\) we are looking for is the greatest\n    natural satisfying the equation \\(\\Lambda(z) = 1\\), at the\n    root. Function~\\fun{nxt/1}\\index{nxt@\\fun{nxt/1}} implies\n    \\begin{equation*}\n      \\Lambda(j+1) = \\ceiling{\\Lambda(j)/2},\\; \\text{with \\(\\Lambda(0)\n        = n\\)}.\n    \\end{equation*}\n    This recurrence is equivalent to the closed form \\(\\Lambda(j) =\n    \\ceiling{n/2^j}\\), as a consequence of the following theorem.\n\\begin{thm}[Ceilings and Fractions]\n\\label{thm:ceilings}\n\\textsl{Let \\(x\\)~be a real number and \\(q\\)~a natural number. Then\n  \\(\\ceiling{\\ceiling{x}/q} = \\ceiling{x/q}\\).}\n\\end{thm}\n\\begin{proof}\n  The equality is equivalent to the conjunction of the two\n  complementary inequalities \\(\\ceiling{\\ceiling{x}/q} \\geqslant\n  \\ceiling{x/q}\\) and \\(\\ceiling{\\ceiling{x}/q} \\leqslant\n  \\ceiling{x/q}\\). The former is direct: \\(\\ceiling{x} \\geqslant x\n  \\Rightarrow \\ceiling{x}/q \\geqslant x/q \\Rightarrow\n  \\ceiling{\\ceiling{x}/q} \\geqslant \\ceiling{x/q}\\). Since both sides\n  of the inequality are integers, \\(\\ceiling{\\ceiling{x}/q} \\leqslant\n  \\ceiling{x/q}\\) is equivalent to state that \\(p \\leqslant\n  \\ceiling{\\ceiling{x}/q} \\Rightarrow p \\leqslant \\ceiling{x/q}\\), for\n  any integer~\\(p\\). An obvious lemma is that if \\(i\\)~is an integer\n  and~\\(y\\) a real number, \\(i \\leqslant \\ceiling{y} \\Leftrightarrow i\n  \\leqslant y\\), so the original inequality is equivalent to \\(p\n  \\leqslant \\ceiling{x}/q \\Rightarrow p \\leqslant x/q\\), for any\n  integer \\(p\\), which is \\(pq \\leqslant \\ceiling{x} \\Rightarrow pq\n  \\leqslant x\\). The lemma yields this implication, achieving the\n  proof.\n\\end{proof}\n    \\noindent To find~\\(z\\), we express~\\(n\\) in binary:\n    \\(n :=\\!  \\sum_{k=0}^{m-1}{b_k2^k} = (b_{m-1}\\ldots\n    b_0)_2\\), where \\(b_k \\in \\{0,1\\}\\) and \\(b_{m-1} = 1\\). It is\n    easy to derive a formula for~\\(b_i\\). We have\n    \\begin{equation}\n      \\frac{n}{2^{i+1}}\n      = \\frac{1}{2^{i+1}}\\sum_{k=0}^{m-1}{b_k2^{k}}\n      = \\frac{1}{2^{i+1}}\\sum_{k=0}^{i}{b_k2^k} + (b_{m-1}\\dots b_{i+1})_2.\n      \\label{eq:n_on_power_2}\n    \\end{equation}\n    We prove that \\(\\floor{n/2^{i+1}} = (b_{m-1}\\dots b_{i+1})_2\\) as\n    follows:\n    \\begin{equation*}\n      \\sum_{k=0}^{i}{2^k} < 2^{i+1}\n      \\Rightarrow\n      0 \\leqslant \\sum_{k=0}^{i}{b_k2^k} < 2^{i+1}\n      \\Leftrightarrow\n      0 \\leqslant \\frac{1}{2^{i+1}}\\sum_{k=0}^{i}{b_k2^k} < 1.\n    \\end{equation*}\n    This and equation~\\eqref{eq:n_on_power_2} imply that\n    \\begin{equation*}\n      \\left\\lceil\\frac{n}{2^i}\\right\\rceil =\n      (b_{m-1}\\dots b_i)_2\n      + \\begin{cases}\n          0, & \\text{if \\((b_{i-1}\\dots b_0)_2=0\\)};\\\\\n          1, & \\text{otherwise}.\n        \\end{cases}\n    \\end{equation*}\n    Therefore, \\(\\ceiling{n/2^z} = 1\\) is equivalent to \\(z=m-1\\)\n    if \\(n=2^{m-1}\\), and \\(z=m\\) otherwise. Equation~\\eqref{eq:e_r}\n    \\vpageref{eq:e_r} states \\(m = \\floor{\\lg n} + 1\\), thus\n    \\(z=\\floor{\\lg n}\\) if \\(n\\)~is a power of~\\(2\\), and\n    \\(z=\\floor{\\lg n} + 1\\) otherwise. More simply, this means that\n    \\(z=\\ceiling{\\lg n}\\).\n\n  \\item Rule~\\(\\rho\\) is used once, at the root. Rule~\\(\\sigma\\) is\n    used \\(z\\)~times.\n\n  \\item The trace of \\(\\fun{solo}(s)\\)\\index{solo@\\fun{solo/1}}\n    is~\\(\\pi^n\\xi\\) if~\\(s\\) contains \\(n\\)~keys, so\n    \\(\\C{\\fun{solo}}{n} = n + 1\\).\n\n  \\item The contribution to the total cost of rules\n    \\(\\mu\\)~and~\\(\\nu\\) is simply~\\(1\\).\n\n\\end{itemize}\nIn total, \\(\\C{\\fun{bms}}{n} = \\OC{\\fun{bms}}{n} + 3n + 2\\ceiling{\\lg\n  n} + 1\\) and \\(\\C{\\fun{bms}}{n} \\sim\n\\OC{\\fun{bms}}{n}\\).\\index{bms@$\\C{\\fun{bms}}{n}$}\n\n\\paragraph{Improvement}\n\nIt is easy to improve upon \\fun{bms/1} by directly building the second\nlevel of the merge tree\\index{tree!merge $\\sim$} \\emph{without using\n  \\fun{mrg/2}}\\index{mrg@\\fun{mrg/2}}. Consider the program in\n\\fig~\\vref{fig:bms0},\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l@{\\;}l}\n\\fun{bms}_0(s)   & \\rightarrow & \\fun{all}(\\fun{duo}(s)).\\\\\n\\\\\n\\fun{duo}(\\cons{x,y}{s}) & \\rightarrow & \\cons{[y,x]}{\\fun{duo}(s)},\n                                       & \\text{if \\(x \\succ y\\)};\\\\\n\\fun{duo}(\\cons{x,y}{s}) & \\rightarrow & \\cons{[x,y]}{\\fun{duo}(s)};\\\\\n\\fun{duo}(s)             & \\rightarrow & [s].\\\\\n\\\\\n\\fun{all}([s]) & \\rightarrow & s;\\\\\n\\fun{all}(s)   & \\rightarrow & \\fun{all}(\\fun{nxt}(s)).\\\\\n\\\\\n\\fun{nxt}(\\cons{s,t}{u}) & \\rightarrow\n                         & \\cons{\\fun{mrg}(s,t)}{\\fun{nxt}(u)};\\\\\n\\fun{nxt}(u)             & \\rightarrow & u.\\\\\n\\\\\n\\fun{mrg}(\\el,t)         & \\rightarrow & t;\\\\\n\\fun{mrg}(s,\\el)         & \\rightarrow & s;\\\\\n\\fun{mrg}(\\cons{x}{s},\\cons{y}{t}) & \\rightarrow\n                         & \\cons{y}{\\fun{mrg}(\\cons{x}{s},t)},\n                         & \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mrg}(\\cons{x}{s},t) & \\rightarrow & \\cons{x}{\\fun{mrg}(s,t)}.\n\\end{array}}\n\\end{equation*}\n\\caption{Faster bottom\\hyp{}up merge sort with\n  \\fun{bms\\(_0\\)/1}\\label{fig:bms0}}\n\\end{figure}\nwhere \\fun{solo/1}\\index{solo@\\fun{solo/1}} has been replaced\nby~\\fun{duo/1}\\index{duo@\\fun{duo/1}}. The number of comparisons is\nunchanged, but the cost, measured as the number of rewrites, is\nslightly smaller. The added cost\nof~\\(\\fun{duo}(s)\\)\\index{duo@\\fun{duo/1}} is \\(\\floor{n/2}+1\\), where\n\\(n\\)~is the length of~\\(s\\). On the other hand, we save the cost\nof~\\(\\fun{solo}(s)\\)\\index{solo@\\fun{solo/1}}. The first rewrite by\nrule~\\(\\sigma\\) is not performed, as well as the subsequent call\n\\(\\fun{nxt}(s)\\)\\index{nxt@\\fun{nxt/1}}, to wit, \\(\\floor{n/2}\\) calls\nto \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}} on pairs of singletons\nby~\\(\\kappa\\) or~\\(\\lambda\\), plus one rewrite by~\\(\\theta\\)\nor~\\(\\iota\\) for the last singleton or the empty stack, totalling\n\\(\\floor{n/2}\\C{\\fun{mrg}}{1,1} + 1 = 2\\floor{n/2} + 1\\). In the end,\nthe total cost is decreased by\n\\begin{equation*}\n  ((n+1) + 1 + (2\\floor{n/2}+1)) - (\\floor{n/2}+1) = n + \\floor{n/2} +\n  2.\n\\end{equation*}\nHence, \\(\\C{\\fun{bms}_0}{n} = \\OC{\\fun{bms}}{n} + \\ceiling{3n/2} +\n2\\ceiling{\\lg n} - 1\\), for \\(n>0\\), and \\(\\C{\\fun{bms}_0}{0} =\n3\\). Asymptotically, we have \\(\\C{\\fun{bms}_0}{n} \\sim\n\\OC{\\fun{bms}}{n}\\).\\index{bms@$\\OC{\\fun{bms}}{n}$}\n\n\n\\section{Comparison}\n\nIn this section we gather our findings about top\\hyp{}down and\nbottom\\hyp{}up merge sort for an easier comparison, and we also\npresent new results which relate the costs of both algorithms.\n\n\\mypar{Minimum cost}\n\nThe minimum cost of both variants of merge sort is the same:\n\\(\\OB{\\fun{tms}}{n} = \\OB{\\fun{bms}}{n}\\) and\n\\begin{equation*}\n\\tfrac{1}{2}n\\lg n - \\left(\\tfrac{1}{2}\\lg\\tfrac{4}{3}\\right)n + \\lg\\tfrac{4}{3}\n\\leqslant \\OB{\\fun{tms}}{n} \\leqslant\n\\tfrac{1}{2}n\\lg n.\n\\end{equation*}\nThe lower bound is tight for \\(n=2\\) and most accurate when \\(n\\)~is a\nJacobsthal\\index{Jacobsthal number} number (see~\\eqref{eq:Jacobsthal}\n\\vpageref{eq:Jacobsthal}). The upper bound is tight when\n\\(n=2^p\\). These results may not be intuitive a priori.\n\n\\mypar{Maximum cost}\n\n\\hspace*{-8.7pt} In the previous sections, we found the following bounds:\n\\begin{align*}\nn\\lg n - n + 1 &\\leqslant \\OW{\\fun{tms}}{n} <\nn\\lg n - 0.91 n + 1;\\\\\nn\\lg n - n + 1 &\\leqslant \\OW{\\fun{bms}}{n} < n\\lg n - 1.\n\\end{align*}\nIn both cases, the lower bound is tight if, and only if, \\(n=2^p\\).\nThe upper bound of top\\hyp{}down merge sort is most accurate when\n\\(n\\)~is the nearest integer to \\(2^p\\ln 2\\). The upper bound of\nbottom\\hyp{}up merge sort is most accurate if \\(n=2^p+1\\).\n\nIt is interesting to bound \\(\\OW{\\fun{bms}}{n}\\) in term of\n\\(\\OW{\\fun{tms}}{n}\\), shedding further light on the relationship\nbetween these two variants of merge sort.\n\nWe already noted \\(\\OC{\\fun{bms}}{2^p} = \\OC{\\fun{tms}}{2^p}\\), so\n\\(\\OW{\\fun{bms}}{2^p} = \\OW{\\fun{tms}}{2^p}\\). Furthermore, we have\n\\(\\OW{\\fun{bms}}{2^p} = \\OW{\\fun{bms}}{2^p-1} + p\\), thus\n\\(\\OW{\\fun{bms}}{2^p-1} = \\OW{\\fun{tms}}{2^p-1}\\). Another interesting\nvalue is \\(\\OW{\\fun{tms}}{2^p+1} = (p-1)2^p + p + 2\\), so\n\\(\\OW{\\fun{bms}}{2^p+1} - \\OW{\\fun{tms}}{2^p+1} = 2^p - p - 1\\). This\nleads us to conjecture the following tight bounds in relationship with\ntop\\hyp{}down merge sort:\n\\begin{equation*}\n\\OW{\\fun{tms}}{n} \\leqslant \\OW{\\fun{bms}}{n} \\leqslant\n\\OW{\\fun{tms}}{n} + n - \\ceiling{\\lg n} - 1.\n\\index{tms@$\\OW{\\fun{tms}}{n}$}\n\\index{bms@$\\OW{\\fun{bms}}{n}$}\n\\end{equation*}\nWe will prove these inequalities by means of mathematical induction\non~\\(n\\) and, in the process, we will discover when they become\nequalities. First, let us deduce from the general recurrence for\nthe cost of bottom\\hyp{}up merge sort the recurrence for the maximum\ncost:\n\\begin{equation}\n\\OW{\\fun{bms}}{0} = \\OW{\\fun{bms}}{1} = 0;\\quad \\OW{\\fun{bms}}{n} =\n\\OW{\\fun{bms}}{2^{\\ceiling{\\lg n}-1}} +\n\\OW{\\fun{bms}}{n-2^{\\ceiling{\\lg n}-1}} + n - 1.\n\\label{eq:bot}\n\\end{equation}\nAlso, we easily check that, for all \\(p \\geqslant 0\\),\n\\begin{equation}\n\\OW{\\fun{tms}}{2^p} = \\OW{\\fun{bms}}{2^p}.\n\\label{eq:2p}\n\\end{equation}\n\n\\paragraph{Lower bound}\n\nLet us prove, for all \\(n \\geqslant 0\\),\n\\begin{equation}\n\\pred{W\\(_L\\)}{n} \\colon \\OW{\\fun{tms}}{n} \\leqslant\n\\OW{\\fun{bms}}{n}.\n\\index{WL@$\\predName{W}_L$}\n\\label{ineq:topbot}\n\\end{equation}\nFrom~\\eqref{eq:2p}, it is clear that \\(\\pred{W\\(_L\\)}{2^0}\\)\nholds. Let the induction hypothesis be \\(\\forall m \\leqslant\n2^p.\\pred{W\\(_L\\)}{m}\\). The induction principle requires that we\nprove \\(\\pred{W\\(_L\\)}{2^p+i}\\), for all \\(0 < i < 2^p\\). Note that we\nleave aside the case when \\(i=2^p\\), because\n\\(\\pred{W\\(_L\\)}{2^{p+1}}\\) is already true from~\\eqref{eq:2p}.\n\nEquations~\\eqref{eq:bot} and~\\eqref{eq:2p}\nyield\\index{bms@$\\OW{\\fun{bms}}{n}$}\n\\begin{align*}\n\\OW{\\fun{bms}}{2^p+i} &=\n\\OW{\\fun{bms}}{2^p} + \\OW{\\fun{bms}}{i} + 2^p + i - 1\\\\\n& = \\OW{\\fun{tms}}{2^p} + \\OW{\\fun{bms}}{i} + 2^p + i - 1 \\geqslant\n\\OW{\\fun{tms}}{2^p} + \\OW{\\fun{tms}}{i} + 2^p + i - 1,\n\\end{align*}\nthe inequality being the instance \\(\\pred{W\\(_L\\)}{i}\\) of the\ninduction hypothesis. Consequently, if the inequality\n\\begin{equation}\n\\OW{\\fun{tms}}{2^p} + \\OW{\\fun{tms}}{i} + 2^p + i - 1 \\geqslant\n\\OW{\\fun{tms}}{2^p+i}\n\\label{ineq:suff_cond}\n\\end{equation}\nholds, the result \\(\\pred{W\\(_L\\)}{2^p+i}\\) ensues. Let us try to\nprove it.\n\nLet \\(n = 2^p + i\\). Then \\(p = \\floor{\\lg n}\\) and \\(\\ceiling{\\lg n}\n= \\floor{\\lg n} + 1\\). Equation~\\eqref{eq:top} \\vpageref{eq:top}\nentails\n\\begin{align*}\n\\OW{\\fun{tms}}{2^p+i} &=\n(2^p+i)(p+1)-2^{p+1}+1 = ((p-1)2^p+1)+(p+1)i\\\\\n&= \\OW{\\fun{tms}}{2^p} + (p+1)i.\n\\end{align*}\nTherefore, inequation~\\eqref{ineq:suff_cond} is equivalent to \\(pi\n\\leqslant \\OW{\\fun{tms}}{i} + 2^p - 1\\). Using\nequation~\\eqref{eq:top}, this inequality in turn is equivalent to\n\\begin{equation}\n(p - \\ceiling{\\lg i})i \\leqslant 2^p - 2^{\\ceiling{\\lg i}}.\n\\label{conj}\n\\end{equation}\nTo prove it, we have two complementary cases to analyse:\n\\begin{itemize}\n\n  \\item \\(i=2^q\\), with \\(0 \\leqslant q < p\\). Then \\(\\lg i = q\\) and\n  equation~\\eqref{conj} is equivalent to \\((p-q)2^q \\leqslant 2^p -\n  2^q\\), that is\n  \\begin{equation}\n   p-q \\leqslant 2^{p-q} - 1.\\label{conj0}\n  \\end{equation}\n  Let \\(f(x) := 2^x - x - 1\\), with \\(x > 0\\). We have \\(f(0) = f(1) =\n  0\\) and \\(f(x) > 0\\) for \\(x>1\\), so the inequality~\\eqref{conj0}\n  holds and is tight if, and only if, \\(x=1\\), that is, \\(q=p-1\\).\n\n  \\item \\(i = 2^q + j\\), with \\(0 \\leqslant q < p\\) and \\(0 < j <\n    2^q\\). Then \\(\\floor{\\lg i} = q = \\ceiling{\\lg i} - 1\\) and\n    inequation~\\eqref{conj} is then equivalent to the inequality\n    \\((p-q-1)i \\leqslant 2^p - 2^{q+1}\\), that is to say,\n    \\begin{equation}\n      (p-q+1)2^q + (p-q-1)j \\leqslant 2^p.\\label{conj1}\n    \\end{equation}\n    Since \\(p-q-1 \\geqslant 0\\) and \\(j < 2^q\\), we have \\((p-q-1)j\n    \\leqslant (p-q-1)2^q\\) (tight if \\(q=p-1\\)). Hence\n    \\((p-q+1)2^q+(p-q-1)j \\leqslant\n    (p-q)2^{q+1}\\). Inequation~\\eqref{conj1} is entailed if \\(2(p-q)\n    \\leqslant 2^{p-q}\\). Let \\(g(x) := 2^x - 2x\\), with \\(x > 0\\). We\n    have \\(g(1) = g(2) = 0\\) and \\(f(x) > 0\\) for \\(x > 2\\). Thus,\n    inequality~\\eqref{conj1} holds and is tight if, and only if,\n    \\(x=1\\), that is, \\(q=p-1\\) (the case \\(x=2\\) implies \\(i\n    \\leqslant 2^{p-1}\\), which cannot be tight).\\hfill\\(\\Box\\)\n\n\\end{itemize}\n\nLet us find now the shape of~\\(n\\) when \\(\\pred{W\\(_L\\)}{n}\\) is\ntight. We proved above that if \\(q=p-1\\), that is, the binary notation\nof~\\(n\\) starts with two 1-bits, formally written as\n\\((11(0+1)^*)_2\\), then the following inequality holds:\n\\begin{equation*}\n\\OW{\\fun{tms}}{2^p+i} =\n\\OW{\\fun{tms}}{2^p} + \\OW{\\fun{tms}}{i} + 2^p + i - 1 \\leqslant\n\\OW{\\fun{tms}}{2^p} + \\OW{\\fun{bms}}{i} + 2^p + i - 1 =\n\\OW{\\fun{bms}}{2^p+i}.\n\\end{equation*}\nThe inequality is tight, \\(\\OW{\\fun{tms}}{2^p+i} =\n\\OW{\\fun{bms}}{2^p+i}\\), if, and only if, \\(\\OW{\\fun{bms}}{i} =\n\\OW{\\fun{tms}}{i}\\). \\index{bms@$\\OW{\\fun{bms}}{n}$}\n\\index{tms@$\\OW{\\fun{tms}}{n}$} Using the case analysis above, if \\(i\n= 2^q + j\\), we have \\(\\OW{\\fun{tms}}{2^p+i} =\n\\OW{\\fun{bms}}{2^p+i}\\), if, and only if, \\(\\OW{\\fun{tms}}{2^{p-1}+j}\n= \\OW{\\fun{bms}}{2^{p-1}+j}\\). These equivalences can be repeated,\nyielding two strictly decreasing sequences of positive integers,\n\\(2^p+i > 2^{p-1}+j > 2^{p-2}+k > \\dots\\) and \\(i > j > k > \\dots\\)\nThe end of the latter recursive descent is simply~\\(0\\), which means\nthat the former stops at a power of~\\(2\\), for which we know\nequation~\\eqref{eq:2p}. In other words, the binary representation\nof~\\(n\\) is made of a series of one or more 1-bits (from \\(2^p\\),\n\\(2^{p-1}\\), \\(2^{p-2}\\), \\ldots), possibly followed by successive\n0-bits, which we formally write \\(n=(1^+0^*)_2\\). This means that\n\\(n\\)~is the difference between two powers of~\\(2\\):\n\\begin{equation}\n\\boxed{\\OW{\\fun{bms}}{n} = \\OW{\\fun{tms}}{n} \\Leftrightarrow n=2^p - 2^q.}\n\\label{eq:Wbms_eq_Wtms}\n\\end{equation}\nNote that if \\(n=2^p-1\\), the number of unbalanced mergers,\nbottom\\hyp{}up, is maximum, and the maximum costs are the same in both\nvariants. Also, the case \\(n=2^p\\) minimises both maximum costs.\n\n\\paragraph{Upper bound}\n\nIf \\(n=2^p+1\\), then \\(p=\\floor{\\lg n}=\\ceiling{\\lg\n  n}-1\\). Furthermore, definition~\\eqref{eq:bot} entails\n\\(\\OW{\\fun{bms}}{2^p+1} = p2^p+1\\) and definition~\\eqref{eq:top}\n\\vpageref{eq:top} \\(\\OW{\\fun{tms}}{2^p+1} = (p-1)2^p+p+2\\), so\n\\(\\OW{\\fun{bms}}{2^p+i} - \\OW{\\fun{tms}}{2^p+i} = 2^p - p - 1\\). In\nterms of~\\(n\\), this means that \\(\\OW{\\fun{bms}}{n} -\n\\OW{\\fun{tms}}{n} = n - \\ceiling{\\lg n} - 1\\), if \\(n=2^p+1\\). We want\nto prove that this difference is maximum:\n\\begin{equation}\n  \\pred{W\\(_U\\)}{n} \\colon \\OW{\\fun{bms}}{n} \\leqslant \\OW{\\fun{tms}}{n} + n -\n  \\ceiling{\\lg n} - 1.\n\\label{ineq:upper_Wbms}\n\\index{WU@$\\predName{W}_U$}\n\\end{equation}\nNotice how equation~\\eqref{eq:2p} entails\n\\(\\pred{W\\(_U\\)}{2^0}\\). Consequently, let the induction hypothesis be\n\\(\\forall m \\leqslant 2^p.\\pred{W\\(_U\\)}{m}\\) and let us prove that\n\\(\\pred{W\\(_U\\)}{2^p+i}\\), for all \\(0 < i < 2^p\\).\n\nLet \\(n=2^p+i\\). Equations~\\eqref{eq:bot} and~\\eqref{eq:2p} yield\n\\begin{align*}\n\\OW{\\fun{bms}}{2^p+i} &= \\OW{\\fun{bms}}{2^p} + \\OW{\\fun{bms}}{i} +\n2^p + i - 1\n= \\OW{\\fun{tms}}{2^p} + \\OW{\\fun{bms}}{i} + 2^p + i - 1\\\\\n&\\leqslant \\OW{\\fun{tms}}{2^p} + \\OW{\\fun{tms}}{i} + 2^p + 2i -\n\\ceiling{\\lg i} - 2,\n\\end{align*}\nwhere the inequality is the instance \\(\\pred{W\\(_U\\)}{i}\\) of the\ninduction hypothesis. Furthermore, \\(n - \\ceiling{\\lg n} - 1 = 2^p + i\n- p - 2\\). Therefore, if\n\\begin{equation*}\n\\OW{\\fun{tms}}{2^p} + \\OW{\\fun{tms}}{i} +\n2^p + 2i - \\ceiling{\\lg i} - 2 \\leqslant \\OW{\\fun{tms}}{2^p+i} + 2^p +\ni - p - 2,\n\\end{equation*}\nthen \\(\\pred{W\\(_U\\)}{2^p+i}\\) would ensue. Using\nequation~\\eqref{eq:top}, we deduce\n\\index{bms@$\\OW{\\fun{bms}}{n}$}\\index{tms@$\\OW{\\fun{tms}}{n}$}\n\\begin{align*}\n\\OW{\\fun{tms}}{i} &= i\\ceiling{\\lg i} - 2^{\\ceiling{\\lg i}} + 1,\\\\\n\\OW{\\fun{tms}}{2^p} &= (p-1)2^p + 1,\\\\\n\\OW{\\fun{tms}}{2^p+i} &= \\OW{\\fun{tms}}{2^p} + (p+1)i.\n\\end{align*}\nThe unproven inequality becomes \\(\\OW{\\fun{tms}}{i} + i - \\ceiling{\\lg\n  i} \\leqslant (p+1)i - p\\), or\n\\begin{equation}\n1 \\leqslant (i-1)(p-\\ceiling{\\lg i}) + 2^{\\ceiling{\\lg i}}.\n\\label{eq:conj2}\n\\end{equation}\nWe have two complementary cases to consider:\n\\begin{itemize}\n\n  \\item \\(i = 2^q\\), with \\(0 \\leqslant q < p\\). Then \\(\\lg i = q\\)\n    and inequation~\\eqref{eq:conj2} is equivalent to \\((p-q+1)(2^q-1)\n    \\geqslant 0\\). Since \\(0 \\leqslant q < p\\) implies \\(p-q+1>1\\) and\n    \\(2^q \\geqslant 1\\), the inequality is proved, the bound being\n    tight if, and only if, \\(q=0\\).\n\n  \\item \\(i = 2^q + j\\), with \\(0 \\leqslant q < p\\) and \\(0 < j <\n    2^q\\). Then we have \\(\\floor{\\lg i} = q = \\ceiling{\\lg i} - 1\\)\n    and inequation~\\eqref{eq:conj2} is then equivalent to \\(1\n    \\leqslant (2^q + j - 1) (p-q) + 2^q\\), or\n    \\begin{equation}\n     1 \\leqslant (p-q+1)2^q + (p-q-1)(j-1).\\label{ineq:2q_j}\n    \\end{equation}\n    From \\(q < p\\) we deduce \\(p-q+1 \\geqslant 2\\) and \\(p-q-1\n    \\geqslant 0\\); we also have \\(2^q \\geqslant 1\\) and \\(j \\geqslant\n    1\\). Consequently, \\((p-q+1)2^q \\geqslant 2\\) and \\((p-q-1)(j-1)\n    \\geqslant 0\\), hence inequation~\\eqref{ineq:2q_j} holds but the\n    bound is never tight.\\hfill\\(\\Box\\)\n\n\\end{itemize}\nAs a side\\hyp{}effect, we proved that if \\(i=1\\), that is, \\(n=2^p +\n1\\), then we have the following inequation:\n\\begin{equation*}\n\\OW{\\fun{bms}}{2^p+1} = \\OW{\\fun{tms}}{2^p} +\n\\OW{\\fun{bms}}{1} + 2^p \\leqslant \\OW{\\fun{tms}}{2^p} +\n\\OW{\\fun{tms}}{1} + 2^p = \\OW{\\fun{tms}}{2^p+1} + 2^p - p - 1.\n\\end{equation*}\nBut, since \\(\\OW{\\fun{tms}}{1} = \\OW{\\fun{bms}}{1} = 0\\), the\ninequality is actually an equality.\\index{tms@$\\OW{\\fun{tms}}{n}$}\n\\begin{equation*}\n\\boxed{\\OW{\\fun{bms}}{n} = \\OW{\\fun{tms}}{n} + n - \\ceiling{\\lg n} - 1\n  \\Leftrightarrow n=1 \\;\\text{or}\\; n=2^p+1.}\n\\end{equation*}\n\n\\paragraph{Program}\n\nAlthough we will present the programming language \\Erlang in\npart~\\ref{part:implementation}, here is how to compute efficiently the\nmaximum costs: \\ErlangInUnchecked{max} Note how we efficiently\ncomputed the binary exponentiation~\\(2^n\\) by means of the recurrent\nequations\n\\begin{equation*}\n2^0 = 1,\\quad 2^{2m} = (2^m)^2,\\quad 2^{2m+1} =  2(2^m)^2.\n\\end{equation*}\nThe cost \\(\\C{\\fun{exp2}}{n}\\) thus satisfies \\(\\C{\\fun{exp2}}{0} =\n1\\) and \\(\\C{\\fun{exp2}}{n} = 1 + \\C{\\fun{exp2}}{\\floor{n/2}}\\), if\n\\(n > 0\\). Therefore, if \\(n > 0\\), it is \\(1\\)~plus the number of\nbits of~\\(n\\), that is to say, \\(\\C{\\fun{exp2}}{n} = \\floor{\\lg n} +\n2\\), else \\(\\C{\\fun{exp2}}{0} = 1\\).\n\n\\mypar{Average cost}\n\nIn sum, we established, for \\(n \\geqslant 2\\),\n\\begin{align*}\nn\\lg n - \\tfrac{3}{2}n + 2 &< \\OM{\\fun{tms}}{n} < n\\lg n - n + 1,\\\\\nn\\lg n - \\alpha n + (2\\alpha - 1) &< \\OM{\\fun{bms}}{n}\n< n\\lg n - (\\alpha - 1)n - (3 - 2\\alpha),\n\\end{align*}\nwhere \\(\\alpha \\simeq 1.2645\\), \\(2\\alpha - 1 \\simeq 1.52899\\) and \\(3\n- 2\\alpha \\simeq 0.471\\). For top\\hyp{}down merge sort, the nature\nof~\\(n\\) for the bounds to be most accurate was not conclusively found\nby our inductive method. For bottom\\hyp{}up merge sort, the lower\nbound is most accurate when \\(n=2^p\\), but we could not determine the\nvalues of~\\(n\\) that make the upper bound most accurate.\n\nThe previous inequalities on \\(\\OM{\\fun{bms}}{n}\\) do not allow us to\ncompare the average costs of the two variants of merge sort we have\nstudied. Here, we prove that top\\hyp{}down merge sort performs fewer\nkey comparisons than bottom\\hyp{}up merge sort in average. Since we\nalready proved that this is true as well in the worst case\n(see~\\eqref{ineq:topbot} \\vpageref{ineq:topbot}), and that their\nminimum costs are equal (see~\\eqref{eq:OBbms} \\vpageref{eq:OBbms}),\nthis will be the last nail in the coffin of the bottom\\hyp{}up\nvariant, before its rebirth in section~\\vref{sec:online}. We want to\nprove by induction\n\\begin{equation*}\n\\OM{\\fun{tms}}{n} \\leqslant \\OM{\\fun{bms}}{n}.\n\\end{equation*}\nWe already now that the bound is tight when \\(n=2^p\\), so let us check\nthe inequality for \\(n=2\\) and let us assume that it holds up\nto~\\(2^p\\) and proceed to establish that it also holds for \\(2^p+i\\),\nwith \\(0 < i \\leqslant 2^p\\), thus reaching our goal. Let us recall\nequation~\\eqref{eq:Abms_2p_i} \\vpageref{eq:Abms_2p_i}:\n\\begin{equation*}\n\\OM{\\fun{bms}}{2^p+i} = \\OM{\\fun{bms}}{2^p} + \\OM{\\fun{bms}}{i}\n+ 2^p + i - \\frac{2^p}{i+1} - \\frac{i}{2^p+1}.\n\\end{equation*}\nSince \\(\\OM{\\fun{bms}}{2^p} = \\OM{\\fun{tms}}{2^p}\\) and, by\nhypothesis, \\(\\OM{\\fun{tms}}{i} \\leqslant \\OM{\\fun{bms}}{i}\\), we have\n\\begin{equation}\n\\OM{\\fun{bms}}{2^p+i} \\geqslant \\OM{\\fun{tms}}{2^p} + \\OM{\\fun{tms}}{i}\n+ 2^p + i - \\frac{2^p}{i+1} - \\frac{i}{2^p+1}.\n\\label{ineq:Atms_Abms}\n\\end{equation}\nIf we could show the right\\hyp{}hand side to be greater than or equal\nto \\(\\OM{\\fun{tms}}{2^p+i}\\), we would win. Let us actually generalise\nthis sufficient condition and express it as the following lemma:\n\\begin{equation*}\n  \\pred{T}{m,n} \\colon\n  \\OM{\\fun{tms}}{m+n} \\leqslant \\OM{\\fun{tms}}{m} + \\OM{\\fun{tms}}{n} +\n  m + n - \\frac{m}{n+1} - \\frac{n}{m+1}.\n\\end{equation*}\nLet us use a lexicographic ordering on the pairs \\((m,n)\\) of natural\nnumbers \\(m\\)~and~\\(n\\) (see definition~\\eqref{def:lexico}\n\\vpageref{def:lexico}). The base case, \\((0,0)\\), is easily seen to\nhold. We observe that the statement to be proved is symmetric,\n\\(\\pred{T}{m,n} \\Leftrightarrow \\pred{T}{n,m}\\), hence we only need to\nmake three cases: \\((2p,2q)\\), \\((2p,2q+1)\\) and \\((2p+1,2q+1)\\).\n\\begin{enumerate}\n\n  \\item \\((m,n) = (2p,2q)\\). In this case,\n    \\begin{itemize}\n\n      \\item \\(\\OM{\\fun{tms}}{m+n} = \\OM{\\fun{tms}}{2(p+q)} =\n        2\\OM{\\fun{tms}}{p+q} + 2(p+q) - 2 + 2/(p+q+1)\\);\n\n      \\item \\(\\OM{\\fun{tms}}{m} = \\OM{\\fun{tms}}{2p} =\n        2\\OM{\\fun{tms}}{p} + 2p - 2 + 2/(p+1)\\);\n\n      \\item \\(\\OM{\\fun{tms}}{n} = \\OM{\\fun{tms}}{2q} =\n        2\\OM{\\fun{tms}}{q} + 2q - 2 + 2/(q+1)\\).\n\n    \\end{itemize}\n    Then, the right\\hyp{}hand side of \\(\\pred{T}{m,n}\\) is\n    \\begin{equation*}\n      r := 2\\left(\\OM{\\fun{tms}}{p} + \\OM{\\fun{tms}}{q} + 2(p+q) - 2 +\n        \\tfrac{1}{p+1} + \\tfrac{1}{q+1} - \\tfrac{p}{2q+1} -\n        \\tfrac{q}{2p+1}\\right).\n    \\end{equation*}\n    The induction hypothesis \\(\\pred{T}{p,q}\\) is\n    \\begin{equation*}\n      \\OM{\\fun{tms}}{p+q} \\leqslant \\OM{\\fun{tms}}{p} +\n      \\OM{\\fun{tms}}{q} + p + q - \\frac{p}{q+1} - \\frac{q}{p+1}.\n    \\end{equation*}\n    Therefore, \\(\\tfrac{1}{2}r \\geqslant \\OM{\\fun{tms}}{p+q} + p + q -\n    2 + \\tfrac{q+1}{p+1} + \\tfrac{p+1}{q+1} - \\tfrac{p}{2q+1} -\n    \\tfrac{q}{2p+1}\\). If the right\\hyp{}hand side is greater than or\n    equal to \\(\\tfrac{1}{2}\\OM{\\fun{tms}}{m+n}\\), then\n    \\(\\pred{T}{m,n}\\) is proved. In other words, we need to prove\n    \\begin{equation*}\n      \\frac{p+1}{q+1} + \\frac{q+1}{p+1} \\geqslant 1 +\n      \\frac{p}{2q+1} + \\frac{q}{2p+1} + \\frac{1}{p+q+1}.\n    \\end{equation*}\n    We expand everything in order to get rid of the fractions; we then\n    observe that we can factorise~\\(pq\\) and the remaining bivariate\n    polynomial is~\\(0\\) if \\(p=q\\) (the inequality is tight), which\n    means that we can factorise by \\(p-q\\) (actually, twice). In the\n    end, this inequation is equivalent to \\(pq(p-q)^2(2p+2q+3)\n    \\geqslant 0\\), with \\(p,q \\geqslant 0\\), which means that\n    \\(\\pred{T}{m,n}\\) holds.\n\n  \\item \\((m,n) = (2p,2q+1)\\). In this case,\n    \\begin{itemize}\n\n      \\item \\(\\OM{\\fun{tms}}{m+n} = \\OM{\\fun{tms}}{2(p+q)+1} =\n        \\OM{\\fun{tms}}{p+q} + \\OM{\\fun{tms}}{p+q+1} + 2(p+q) - 1 +\n        \\tfrac{2}{p+q+2}\\);\n\n      \\item \\(\\OM{\\fun{tms}}{m} = \\OM{\\fun{tms}}{2p} =\n        2\\OM{\\fun{tms}}{p} + 2p - 2 + 2/(p+1)\\);\n\n      \\item \\(\\OM{\\fun{tms}}{n} = \\OM{\\fun{tms}}{2q+1} =\n        \\OM{\\fun{tms}}{q} + \\OM{\\fun{tms}}{q+1} + 2q - 1 + 2/(q+2)\\).\n\n    \\end{itemize}\n    Then, the right\\hyp{}hand side of \\(\\pred{T}{m,n}\\) is\n    \\begin{equation*}\n      r := 2\\OM{\\fun{tms}}{p} + \\OM{\\fun{tms}}{q} +\n      \\OM{\\fun{tms}}{q+1} + 4(p+q) - 2 + \\tfrac{2}{p+1} +\n      \\tfrac{2}{q+2} - \\tfrac{p}{q+1} - \\tfrac{2q+1}{2p+1}.\n    \\end{equation*}\n    The induction hypotheses \\(\\pred{T}{p,q}\\) and \\(\\pred{T}{p,q+1}\\)\n    are\n    \\begin{itemize}\n\n      \\item \\(\\OM{\\fun{tms}}{p+q} \\leqslant \\OM{\\fun{tms}}{p} +\n      \\OM{\\fun{tms}}{q} + p + q - \\frac{p}{q+1} - \\frac{q}{p+1}\\),\n\n      \\item \\(\\OM{\\fun{tms}}{p+(q+1)} \\leqslant \\OM{\\fun{tms}}{p} +\n      \\OM{\\fun{tms}}{q+1} + p + (q + 1) - \\frac{p}{q+2} -\n      \\frac{q+1}{p+1}\\).\n\n    \\end{itemize}\n    Thus, \\(r \\geqslant \\OM{\\fun{tms}}{p+q} + \\OM{\\fun{tms}}{p+q+1} +\n    2(p+q) - 3 + \\tfrac{2q+3}{p+1} + \\tfrac{p+2}{q+2} -\n    \\tfrac{2q+1}{2p+1}\\). If the right\\hyp{}hand side is greater than\n    or equal to \\(\\OM{\\fun{tms}}{m+n}\\), then \\(\\pred{T}{m,n}\\) is\n    proved. In other words, we need to prove\n    \\begin{equation*}\n      \\frac{2q+3}{p+1} + \\frac{p+2}{q+2} \\geqslant 2 +\n      \\frac{2q+1}{2p+1} + \\frac{2}{p+q+2}.\n    \\end{equation*}\n    By expanding and getting rid of the fractions, we obtain a\n    bivariate polynomial with the trivial factors~\\(p\\) and \\(p-q\\)\n    (because if \\(p=q\\), the inequality is tight). After that, a\n    computer algebra system can finish the factorisation and the\n    inequality is found to be equivalent to \\(p(p-q)(p-q-1)(2p+2q+5)\n    \\geqslant 0\\), therefore \\(\\pred{T}{m,n}\\) holds.\n\n  \\item \\((m,n) = (2p+1,2q+1)\\). In this case,\n    \\begin{itemize}\n\n      \\item \\(\\OM{\\fun{tms}}{m+n} = \\OM{\\fun{tms}}{2(p+q+1)} =\n        2\\OM{\\fun{tms}}{p+q+1} + 2(p+q) + 2/(p+q+2)\\);\n\n      \\item \\(\\OM{\\fun{tms}}{n} = \\OM{\\fun{tms}}{2p+1} =\n        \\OM{\\fun{tms}}{p} + \\OM{\\fun{tms}}{p+1} + 2p - 1 + 2/(p+2)\\);\n\n      \\item \\(\\OM{\\fun{tms}}{n} = \\OM{\\fun{tms}}{2q+1} =\n        \\OM{\\fun{tms}}{q} + \\OM{\\fun{tms}}{q+1} + 2q - 1 + 2/(q+2)\\).\n\n    \\end{itemize}\n    Then, the right\\hyp{}hand side of \\(\\pred{T}{m,n}\\) is\n    \\begin{equation*}\n      r := \\OM{\\fun{tms}}{p} + \\OM{\\fun{tms}}{q} + \\OM{\\fun{tms}}{p+1}\n      + \\OM{\\fun{tms}}{q+1} + 4(p+q) + \\tfrac{2}{p+2} + \\tfrac{2}{q+2}\n      - \\tfrac{2p+1}{2q+2} - \\tfrac{2q+1}{2p+2}.\n    \\end{equation*}\n    The (symmetric) induction hypotheses \\(\\pred{T}{p,q+1}\\) and\n    \\(\\pred{T}{p+1,q}\\):\n    \\begin{itemize}\n\n      \\item \\(\\OM{\\fun{tms}}{p+(q+1)} \\leqslant \\OM{\\fun{tms}}{p} +\n        \\OM{\\fun{tms}}{q+1} + p + q + 1 - \\tfrac{p}{q+2}\n        - \\tfrac{q+1}{p+1}\\);\n\n      \\item \\(\\OM{\\fun{tms}}{(p+1)+q} \\leqslant \\OM{\\fun{tms}}{p+1} +\n        \\OM{\\fun{tms}}{q} + p + q + 1 - \\tfrac{p+1}{q+1} -\n        \\tfrac{q}{p+2}\\).\n\n    \\end{itemize}\n    Thus, \\(r \\geqslant 2\\OM{\\fun{tms}}{p+q+1} + 2(p+q) - 2 +\n    \\tfrac{q+1}{p+1} + \\tfrac{q}{p+2} + \\tfrac{p+1}{q+1} +\n    \\tfrac{p}{q+2} + \\tfrac{2}{p+2} + \\tfrac{2}{q+2} -\n    \\tfrac{2p+1}{2q+2} - \\tfrac{2q+1}{2p+2}\\). If the right\\hyp{}hand\n    side is greater than or equal to \\(\\OM{\\fun{tms}}{m+n}\\), then\n    \\(\\pred{T}{m,n}\\) is proved. In other words, we need to prove\n    \\begin{equation*}\n      \\frac{q+1}{p+1} + \\frac{q+2}{p+2} + \\frac{p+2}{q+2} +\n      \\frac{p+1}{q+1} \\geqslant 2 + \\frac{2p+1}{2q+2} +\n      \\frac{2q+1}{2p+2} + \\frac{2}{p+q+2}.\n    \\end{equation*}\n    After expansion to form a positive polynomial, we note that the\n    inequality is tight if \\(p=q\\), so the polynomial has a factor\n    \\(p-q\\). After division, another factor \\(p-q\\) is clear. The\n    inequality is thus equivalent to \\((p-q)^2(2p^2(q+1) + p(2q^2 + 9q\n    + 8) + 2(q+2)^2) \\geqslant 0\\), so \\(\\pred{T}{m,n}\\) holds in this\n    case as well.\n\n\\end{enumerate}\nIn total, \\(\\pred{T}{m,n}\\) holds in each case, therefore the lemma is\ntrue for all \\(m\\)~and~\\(n\\). By applying the lemma\nto~\\eqref{ineq:Atms_Abms}, we prove the theorem \\(\\OM{\\fun{tms}}{n}\n\\leqslant \\OM{\\fun{bms}}{n}\\), for all~\\(n\\). Collecting all the cases\nwhere the bound is tight shows what we would expect: \\(m=n\\),\n\\(m=n+1\\) or \\(n=m+1\\). For~\\eqref{ineq:Atms_Abms}, this means\n\\(i=2^p\\) or \\(i=2^p-1\\). In other words,\n\\begin{equation*}\n\\boxed{\\OM{\\fun{tms}}{n} = \\OM{\\fun{bms}}{n} \\Leftrightarrow n=2^p\n  \\;\\text{or}\\; n=2^p-1, \\text{with \\(p \\geqslant\n    0\\)}.}\n\\end{equation*}\n\n\\paragraph{Program}\n\nIn \\Erlang, we would implement as follows the computation of the\naverage costs of top\\hyp{}down and bottom\\hyp{}up merge sort:\n\\ErlangInUnchecked{mean}\n\n\\mypar{Merging vs.\\@ inserting}\n\\index{merge sort!vs. insertion sort|(}\n\nLet us compare insertion sort and bottom\\hyp{}up merge sort in their\nfastest variant. We found in equation~\\eqref{eq:ave_i2wb}\n\\vpageref{eq:ave_i2wb} the average cost of balanced 2-way insertion\nsort:\n\\begin{equation*}\n\\M{\\fun{i2wb}}{n}\\index{12wb@$\\M{\\fun{i2wb}}{n}$}\n  = \\frac{1}{8}(n^2 + 13n - \\ln 2n + 10) + \\epsilon_n,\\;\n\\text{with \\(0 < \\epsilon_n < \\frac{7}{8}\\)}.\n\\end{equation*}\nWe also just found that the cost in addition to comparisons is\n\\(\\ceiling{3n/2} + 2\\ceiling{\\lg n} - 1\\) for\n\\fun{bms\\(_0\\)/1}\\index{bms0@\\fun{bms\\(_0\\)/1}}, and\n\\(\\OC{\\fun{bms\\(_0\\)}}{n} = \\OC{\\fun{bms}}{n}\\). Moreover, we found\nbounds on \\(\\OM{\\fun{bms}}{n}\\) in~\\eqref{ineq:bounds_Mbms}\n\\vpageref{ineq:bounds_Mbms}, the upper one being excellent. Therefore\n\\begin{align*}\n\\M{\\fun{bms\\(_0\\)}}{n} &< (n\\lg n - (\\alpha - 1)n - (3-2\\alpha))\n+ (\\ceiling{3n/2} + 2\\ceiling{\\lg n} - 1)\\\\\n& < (n+2)\\lg n + 1.236n + 1.529;\\\\\n\\M{\\fun{bms\\(_0\\)}}{n} &> (n\\lg n - 1.35n + 1.69) + (\\ceiling{3n/2} +\n2\\ceiling{\\lg n} - 1)\\\\\n&> (n+2)\\lg n + 0.152n + 0.69;\n\\end{align*}\n\\begin{equation*}\n(n^2 + 13n - \\ln 2n + 10)/8 < \\M{\\fun{i2wb}}{n} < (n^2 + 13n - \\ln 2n + 17)/8.\n\\end{equation*}\nwhere \\(\\alpha \\simeq 1.2645\\) and \\(\\ceiling{x} < x + 1\\).\n\nHence, \\((n+2)\\lg n + 1.236n + 1.529 < (n^2 + 13n - \\ln 2n + 10)/8\\)\nimplies \\(\\M{\\fun{bms\\(_0\\)}}{n} < \\M{\\fun{i2wb}}{n}\\), and also\n\\((n^2 + 13n - \\ln 2n + 17)/8 < (n+2)\\lg n + 0.152n + 0.69\\) implies\n\\(\\M{\\fun{i2wb}}{n} < \\M{\\fun{bms\\(_0\\)}}{n}\\). With the help of a\ncomputer algebra system, we find that\n\\begin{enumerate}\n\n  \\item \\(\\M{\\fun{i2wb}}{n} < \\M{\\fun{bms\\(_0\\)}}{n}\\) if \\(3\n    \\leqslant n \\leqslant 29\\),\n\n  \\item \\(\\M{\\fun{bms\\(_0\\)}}{n} < \\M{\\fun{i2wb}}{n}\\) if \\(43\n    \\leqslant n\\).\n\n\\end{enumerate}\nFor the case \\(n=2\\), we find: \\(\\M{\\fun{i2wb}}{2} = 11/2 > 5 =\n\\M{\\fun{bms\\(_0\\)}}{2}\\). If we set aside this peculiar case, we may\nconclude that insertion sort is faster, in average, for stacks of less\nthan \\(30\\)~keys, and the opposite is true for stacks of at\nleast~\\(43\\) keys.\n\nIn\\hyp{}between, we do not know, but we can compute efficiently the\naverage costs and use dichotomy on the interval from\n\\(30\\)~to~\\(43\\). By using the \\Erlang program above, we quickly find\nthat insertion sort is first beaten by bottom\\hyp{}up merge sort at\n\\(n=36\\). This suggests to drop \\fun{duo/1} in favour of a function\nthat constructs chunks of \\(35\\)~keys from the original stack, then\nsorts them using balanced 2-way insertions and, finally, if there are\nmore than \\(35\\)~keys, starts merging those sorted stacks. This\nimprovement amounts to not constructing the first \\(35\\)~levels in the\nmerge tree\\index{tree!merge $\\sim$} but, instead, build the \\(35\\)th\nlevel by insertions.\n\nDespite the previous analysis, we should be aware that it relies on a\nmeasure based on the number of function calls, which assumes that each\nfunction call is indeed performed by the run\\hyp{}time system (no\ninlining), that all context switchings have the same duration, that\nother operations take a negligible time in comparison, that cache,\njump predictions and instruction pipelining have no effect etc. Even\nusing the same compiler on the same machine does not exempt from\ncareful benchmarking.\n\n\\index{merge sort!vs. insertion sort|)}\n\\index{merge sort!bottom-up $\\sim$|)}\n\n\\section{Online merge sort}\n\\label{sec:online}\n\\index{merge sort!online $\\sim$|(}\n\nSorting algorithms can be distinguished depending on whether they\noperate on the whole stack of keys, or key by key. The former are said\n\\emph{off\\hyp{}line}, as keys are not sorted while they are coming in,\nand the latter are called \\emph{online}, as the sorting process\ncan be temporally interleaved with the input process. Bottom\\hyp{}up\nmerge sort is an off\\hyp{}line algorithm, but it can be easily\nmodified to become online by remarking that balanced mergers\ncan be repeated whenever a new key arrives, and the unbalanced\nmergers are performed only when the sorted stack is required.\n\nMore precisely, consider again \\fig~\\ref{fig:msort_gen}\n\\vpageref{fig:msort_gen} without the unbalanced mergers. The addition\nof another key (at the right) yields two cases: if~\\(n\\) is even, that\nis, \\(e_0>0\\), then nothing is done as the key becomes a singleton,\nsorted stack of length \\(2^0\\); otherwise, a cascade of mergers\nbetween stacks of identical lengths \\(2^{e_i}\\), with \\(e_i=i\\), is\ntriggered until \\(e_j > j\\). This is exactly the binary addition\nof~\\(1\\) to~\\(n\\), except that mergers, instead of bitwise additions,\nare performed as long as a carry is issued and propagated.\n\nTo our knowledge, only \\cite{Okasaki_1998a} mentions this variant; he\nshows that it can be efficiently implemented with purely functional\ndata structures, just as the off\\hyp{}line version. (Notice that his\ncontext is nevertheless different from ours as he relies on lazy\nevaluation and amortised analysis.)\n\nOur code is shown in \\fig~\\ref{fig:oms}\\index{merge sort!online\n  $\\sim$!program}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{oms}(s)   & \\xrightarrow{\\smash{\\phi}}\n               & \\fun{unb}(\\fun{sum}(s,\\el),\\el).\\\\\n\\\\\n\\fun{sum}(\\el,t)         & \\xrightarrow{\\smash{\\chi}} & t;\\\\\n\\fun{sum}(\\cons{x}{s},t) & \\xrightarrow{\\smash{\\psi}}\n                         & \\fun{sum}(s,\\fun{add}([x],t)).\\\\\n\\\\\n\\fun{add}(s,\\el) & \\xrightarrow{\\smash{\\omega}} & [\\fun{one}(s)];\\\\\n\\fun{add}(s,\\cons{\\fun{zero}()}{t})\n                    & \\xrightarrow{\\smash{\\gamma}}\n                    & \\cons{\\fun{one}(s)}{t};\\\\\n\\fun{add}(s,\\cons{\\fun{one}(u)}{t}) & \\xrightarrow{\\smash{\\delta}}\n                    & [\\fun{zero}()|\\fun{add}(\\fun{mrg}(s,u),t)].\\\\\n\\\\\n\\fun{unb}(\\el,u) & \\xrightarrow{\\smash{\\mu}} & u;\\\\\n\\fun{unb}(\\cons{\\fun{zero}()}{s},u)\n                 & \\xrightarrow{\\smash{\\nu}} & \\fun{unb}(s,u);\\\\\n\\fun{unb}(\\cons{\\fun{one}(t)}{s},u)\n                 & \\xrightarrow{\\smash{\\xi}}\n                 & \\fun{unb}(s,\\fun{mrg}(t,u)).\\\\\n\\\\\n\\fun{mrg}(\\el,t)         & \\xrightarrow{\\smash{\\theta}} & t;\\\\\n\\fun{mrg}(s,\\el)         & \\xrightarrow{\\smash{\\iota}} & s;\\\\\n\\fun{mrg}(\\cons{x}{s},\\cons{y}{t}) & \\xrightarrow{\\smash{\\kappa}}\n                         & \\cons{y}{\\fun{mrg}(\\cons{x}{s},t)},\\;\n                           \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mrg}(\\cons{x}{s},t) & \\xrightarrow{\\smash{\\lambda}}\n                         & \\cons{x}{\\fun{mrg}(s,t)}.\n\\end{array}}\n\\end{equation*}\n\\caption{Online merge sort with \\fun{oms/1}\\label{fig:oms}}\n\\end{figure}\nWe use \\(\\fun{zero}()\\)\\index{zero@\\fun{zero/0}} to represent a\n\\(0\\)-bit in the binary notation of the number of currently sorted\nkeys. Dually, the call \\(\\fun{one}(s)\\)\\index{one@\\fun{one/1}} denotes\na \\(1\\)-bit, where the stack~\\(s\\) holds a number of sorted keys equal\nto the associated power of two in the binary notation. Each call to\n\\fun{one/1} corresponds to a subtree\\index{tree!merge $\\sim$} in\n\\fig~\\vref{fig:msort_gen}. For instance, \\([\\fun{one}([4]),\n\\fun{zero}(), \\fun{one}([3,6,7,9])]\\) corresponds to the binary number\n\\((101)_2\\), hence the stack holds \\(1 \\cdot 2^2 + 0 \\cdot 2^1 + 1\n\\cdot 2^0 = 5\\) keys in total. Keep in mind that the bits are reversed\nin the stack, as the subsequent processing of key~\\(5\\) would yield\n\\([\\fun{zero}(),\\fun{one}([4,5]),\\fun{one}([3,6,7,9])]\\).\n\nNote that the program in \\fig~\\vref{fig:oms} does not capture the\nnormal use case of online merge sort, as, in practice, the\nargument~\\(s\\) of the call \\(\\fun{oms}(s)\\)\\index{oms@\\fun{oms/1}}\nwould not be known in its entirety, so\n\\fun{add/2}\\index{add@\\fun{add/2}} would only be called whenever a key\nbecomes available. In the following analysis, however, we are\ninterested in the number of comparisons of a sequence of updates\nby~\\fun{sum/2}\\index{sum@\\fun{sum/2}} (a framework we used in\nsection~\\ref{sec:queueing}), followed by a series of unbalanced\nmergers by~\\fun{unb/2}\\index{unb@\\fun{unb/2}} (\\emph{unbalanced}) in\norder to obtain a sorted stack; therefore, our program is suitable\nbecause we do want to assess~\\(\\OC{\\fun{oms}}{n}\\)\\index{oms@$\\OC{\\fun{oms}}{n}$}.\n\nLet us note \\(\\OC{\\fun{add}}{n}\\)\\index{add@$\\OC{\\fun{add}}{n}$} the\nnumber of comparisons to add a new key to a current stack of\nlength~\\(n\\) and recall that\n\\(\\OC{\\fun{mrg}}{m,n}\\)\\index{mrg@$\\OC{\\fun{mrg}}{m,n}$} is the number\nof comparisons to merge two stacks of lengths \\(m\\)~and~\\(n\\) by\ncalling \\fun{mrg/2}\\index{mrg@\\fun{mrg/2}}. If \\(n\\)~is even, then\nthere are no comparisons, as this is similar to adding~\\(1\\) to a\nbinary sequence \\((\\Xi{0})_2\\), where \\(\\Xi\\)~is an arbitrary bit\nstring. Otherwise, a series of balanced mergers of size~\\(2^i\\) are\nperformed, as this is dual to adding~\\(1\\) to \\((\\Xi{011}\\ldots\n1)_2\\), where \\(\\Xi\\)~is arbitrary. Therefore\n\\begin{equation*}\n\\abovedisplayskip=2pt\n\\belowdisplayskip=2pt\n\\OC{\\fun{add}}{2j} = 0,\\qquad\n\\OC{\\fun{add}}{2j-1} = \\sum_{i=0}^{\\rho_{2j}}{\\OC{\\fun{mrg}}{2^i,2^i}},\n\\end{equation*}\nwhere \\(\\rho_n\\)~is the highest power of~\\(2\\) dividing~\\(n\\) (ruler\nfunction)\\index{ruler function}.  Let\n\\(\\OC{\\fun{sum}}{n}\\)\\index{sum@$\\OC{\\fun{sum}}{n}$} be the number of\ncomparisons to add \\(n\\)~keys to \\(\\el\\). We have\n\\begin{gather}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\OC{\\fun{sum}}{n} = \\sum_{k=0}^{n-1}{\\OC{\\fun{add}}{k}}.\\notag\\\\[0mm]\n\\OC{\\fun{sum}}{2p} = \\OC{\\fun{sum}}{2p+1}\n= \\sum_{k=1}^{2p-1}{\\OC{\\fun{add}}{k}}\n= \\sum_{j=1}^{p}{\\OC{\\fun{add}}{2j-1}}\n= \\sum_{j=1}^{p}\\sum_{i=0}^{1+\\rho_{j}}{\\OC{\\fun{mrg}}{2^i,2^i}}.\n\\label{eq:sum_2p}\n\\end{gather}\nFrom~\\eqref{eq:C_unbal}, the number of comparisons of the\nunbalanced mergers is\n\\begin{equation}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\OC{\\fun{unb}}{n}\n= \\OC{\\ltimes}{n}\n= \\sum_{i=1}^{r}{\\OC{\\fun{mrg}}{2^{e_i},2^{e_{i-1}}+\\dots+2^{e_0}}}.\n\\index{unb@$\\OC{\\fun{unb}}{n}$}\n\\label{eq:cost_unb}\n\\end{equation}\nLet \\(\\OC{\\fun{oms}}{n}\\)\\index{oms@$\\OC{\\fun{oms}}{n}$} the number of\ncomparisons to sort \\(n\\)~keys online. We have\n\\begin{equation}\n\\OC{\\fun{oms}}{n} = \\OC{\\fun{sum}}{n} + \\OC{\\fun{unb}}{n}.\n\\index{sum@$\\OC{\\fun{sum}}{n}$}\n\\label{eq:ocost_online}\n\\end{equation}\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Minimum cost}\n\\index{merge sort!online $\\sim$!minimum cost|(}\n\nReplacing~\\(\\Cost\\) by~\\(\\Best\\) in equation~\\eqref{eq:sum_2p}, we\nobtain the equations for the minimum number of comparisons, allowing\nus to simplify~\\(\\OB{\\fun{sum}}{n}\\)\\index{sum@$\\OB{\\fun{sum}}{n}$}\nwith the help of equation~\\eqref{eq:best_merge}\n\\vpageref{eq:best_merge}:\n\\begin{equation}\n\\OB{\\fun{sum}}{2p}\n  = \\OB{\\fun{sum}}{2p+1}\n  = \\sum_{j=1}^{p}\\sum_{i=0}^{1+\\rho_{j}}{\\OB{\\fun{mrg}}{2^i,2^i}}\n  = \\sum_{j=1}^{p}\\sum_{i=0}^{1+\\rho_{j}}{2^{i}}\n  = 4\\sum_{j=1}^{p}{2^{\\rho_{j}}} - p.\n\\label{eq:B_oplus}\n\\end{equation}\nLet \\(T_p := \\sum_{j=1}^{p}{2^{\\rho_{j}}}\\). The recurrences on the\nruler function\\index{ruler function} \\eqref{eq:ruler}\n\\vpageref{eq:ruler} help us in finding a recurrence for~\\(T_p\\) as\nfollows:\n\\begin{align*}\nT_{2q} &= \\sum_{k=0}^{\\smash[t]{q-1}}{2^{\\rho_{2k+1}}} +\n\\sum_{k=1}^{q}{2^{\\rho_{2k}}} = q + 2 \\cdot T_{q},\\\\[2mm]\nT_{2q+1}\n&= \\sum_{j=1}^{\\smash[t]{2q+1}}{2^{\\rho_{j}}} = 1 + T_{2q} = (q + 1) +\n2 \\cdot T_{q}.\n\\end{align*}\nEquivalently, \\(T_{p} = 2 \\cdot T_{\\floor{p/2}} + \\ceiling{p/2} = 2\n\\cdot T_{\\floor{p/2}} + p - \\floor{p/2}\\). Therefore, unravelling a\nfew terms of the recurrence quickly reveals the equation\n\\begin{equation*}\n2 \\cdot T_p = 2p + \\sum_{j=1}^{\\floor{\\lg p}}\n            {\\left\\lfloor{\\frac{p}{2^j}}\\right\\rfloor 2^j},\n\\end{equation*}\nusing Theorem~\\vref{thm:floors}. By definition, \\(\\{x\\} := x -\n\\floor{x}\\), thus\n\\begin{equation*}\n2 \\cdot T_p = p\\floor{\\lg p} + 2p - \\sum_{j=1}^{\\floor{\\lg\n    p}}\\left\\lbrace\\frac{p}{2^j}\\right\\rbrace 2^j.\n\\end{equation*}\nUsing \\(0 \\leqslant \\{x\\} < 1\\), we obtain the bounds\n\\begin{equation*}\np\\floor{\\lg p} + 2p - 2^{\\floor{\\lg p}+1} + 2 < 2 \\cdot T_p \\leqslant\np\\floor{\\lg p} + 2p.\n\\end{equation*}\nFurthermore, \\(x - 1 < \\floor{x} \\leqslant x\\) and \\(\\floor{x} = x -\n\\{x\\}\\), therefore\n\\begin{align*}\np(\\lg p - \\{\\lg p\\}) + 2p - 2^{\\lg p - \\{\\lg p\\} +\n  1} + 2 < 2 \\cdot T_p &\\leqslant p\\lg p + 2p,\\\\\np\\lg p + 2p + 2 - p \\cdot \\theta_L(\\{\\lg p\\}) < 2 \\cdot T_p\n&\\leqslant p\\lg p + 2p,\n\\end{align*}\nwith \\(\\theta_L(x) := x + 2^{1 - x}\\). Since \\(\\max_{0 \\leqslant x <\n  1}\\theta_L(x) = \\theta_L(0) = 2\\), we conclude:\n\\begin{equation*}\np\\lg p + 2 < 2 \\cdot T_p \\leqslant p\\lg p + 2p.\n\\end{equation*}\nThe upper bound is tight if \\(p=2^q\\). Applying these bounds to the\ndefinition of~\\(\\OB{\\fun{sum}}{2p}\\) in~\\eqref{eq:B_oplus} yields\n\\begin{equation}\n2p\\lg p - p + 4 < \\OB{\\fun{sum}}{2p} \\leqslant 2p\\lg p + 3p.\n\\label{ineq:B_oplus_2p}\n\\end{equation}\nConsequently, \\(\\OB{\\fun{sum}}{2p} = \\OB{\\fun{sum}}{2p+1} \\sim 2p\\lg\np\\), hence \\(\\OB{\\fun{sum}}{n} \\sim n\\lg n\\).\\index{sum@$\\OB{\\fun{sum}}{n}$}\n\n\\bigskip\n\n\\noindent Equation~\\eqref{eq:best_merge} and~\\eqref{eq:cost_unb} imply\n\\(\\OB{\\fun{unb}}{n} = \\sum_{i=1}^{r}{\\min\\{2^{e_i},2^{e_{i-1}} + \\dots\n  + 2^{e_0}\\}}\\)\\index{unb@$\\OB{\\fun{unb}}{n}$|(}. Let us commence by\nnoting that \\(\\sum_{j=0}^{i}{2^{e_j}} \\leqslant \\sum_{j=0}^{e_i}{2^j}\n= 2 \\cdot 2^{e_i} - 1\\). This is equivalent to a given binary number\nbeing always lower than or equal to the number with the same number of\nbits all set to~\\(1\\), for example, \\((10110111)_2 \\leqslant\n(11111111)_2\\). By definition of~\\(e_i\\), we have \\(e_{i-1} + 1\n\\leqslant e_i\\), so \\(\\sum_{j=0}^{i-1}{2^{e_j}} \\leqslant\n2^{e_{i-1}+1} - 1 \\leqslant 2^{e_i} - 1 < 2^{e_i}\\) and\n\\(\\min\\{2^{e_i},2^{e_{i-1}} + \\dots + 2^{e_0}\\} = 2^{e_{i-1}} + \\dots\n+ 2^{e_0}\\). We have now\n\\begin{equation}\n\\OB{\\fun{unb}}{n} = \\sum_{i=1}^{r}\\sum_{j=0}^{i-1}{2^{e_j}} < n.\n\\label{ineq:OBunb}\n\\end{equation}\nTrivially, \\(0 < \\OB{\\fun{unb}}{n}\\), so\nequation~\\eqref{eq:ocost_online} entails \\(\\OB{\\fun{oms}}{n}\n\\sim n\\lg n \\sim 2 \\cdot \\OB{\\fun{bms}}{n}\\).\n\\index{merge sort!online $\\sim$!minimum cost|)}\n\\index{unb@$\\OB{\\fun{unb}}{n}$|)}\n\n\\paragraph{Maximum cost}\n\\index{merge sort!online $\\sim$!maximum cost|(}\n\nReplacing~\\(\\Cost\\) by~\\(\\Worst\\) in equation~\\eqref{eq:sum_2p}\n\\vpageref{eq:sum_2p}, we obtain equations for the maximum number of\ncomparisons, which we can simplify with the help of\nequation~\\eqref{eq:worst_merge} \\vpageref{eq:worst_merge} into\n\\begin{equation}\n\\OW{\\fun{sum}}{2p}\n  = \\OW{\\fun{sum}}{2p+1}\n  = \\sum_{j=1}^{p}\\sum_{i=0}^{1+\\rho_{j}}{\\OW{\\fun{mrg}}{2^i,2^i}}\n%  = \\sum_{j=1}^{p}\\sum_{i=0}^{1+\\rho_{j}}{(2^{i+1}-1)}\\\\\n  = 8\\sum_{j=1}^{p}{2^{\\rho_j}} - \\sum_{j=1}^{p}\\rho_j - 4p.\n\\label{eq:OW_sum_2p}\n\\index{sum@$\\OW{\\fun{sum}}{n}$}\n\\end{equation}\n\\index{bit sum|(} \\index{ruler function|(} We can reach a closed form\nfor \\(\\sum_{j=1}^{p}\\rho_j\\) if we think of the carry propagation and\nthe number of~\\(1\\)-bits when adding~\\(1\\) to a binary number (since\n\\(j\\)~ranges over successive integers). This amounts to finding a\nrelationship between \\(\\rho_j\\), \\(\\rho_{j+1}\\), \\(\\nu_j\\) and\n\\(\\nu_{j+1}\\). Let us assume that \\(2n+1 = (\\Xi 01^a)_2\\), where\n\\(\\Xi\\)~is an arbitrary bit string and \\((1^a)_2\\)~is a 1-bit string\nof length~\\(a\\). Then \\(\\nu_{2n+1} = \\nu_{\\Xi} + a\\) and \\(\\rho_{2n+1}\n= 0\\). The next integer is \\(2n+2 = (\\Xi 10^a)_2\\), so \\(\\nu_{2n+2} =\n\\nu_{\\Xi} + 1\\) and \\(\\rho_{2n+2} = a\\). Now, we can relate\n\\(\\rho\\)~and~\\(\\nu\\) by means of~\\(a\\): \\(\\rho_{2n+2} = \\nu_{2n+1} -\n\\nu_{\\Xi} = \\nu_{2n+1} - (\\nu_{2n+2} - 1) = 1 + \\nu_{2n+1} -\n\\nu_{2n+2}\\). We can check now that the same pattern also works\nfor~\\(\\rho_{2n+1}\\) by simply using the definitions of\n\\(\\rho\\)~and~\\(\\nu\\): \\(\\rho_{2n+1} = 1 + \\nu_{2n} -\n\\nu_{2n+1}\\). This achieves to establish, for any integer \\(n>0\\),\nthat \\(\\rho_n = 1 + \\nu_{n-1} - \\nu_{n}\\). Summing on both sides\nyields\n\\begin{equation*}\n\\sum_{j=1}^{p}{\\rho_j} = p - \\nu_p.\n\\end{equation*}\nInterestingly, we already met \\(p - \\nu_p\\) \\index{bit\n  sum|)}\\index{ruler function|)} in equation~\\eqref{eq:ruler_nu},\n\\vpageref{eq:ruler_nu}. We can now further\nsimplify~\\eqref{eq:OW_sum_2p} as follows:\n\\begin{equation*}\n\\OW{\\fun{sum}}{2p}\n = \\OW{\\fun{sum}}{2p+1}\n = 8\\sum_{j=1}^{p}{2^{\\rho_j}} - 5p - \\nu_p\n = 2 \\cdot \\OB{\\fun{sum}}{2p} - 3p - \\nu_p.\n\\index{sum@$\\OW{\\fun{sum}}{n}$}\n\\end{equation*}\nReusing the bounds on~\\(\\OB{\\fun{sum}}{2p}\\)\nin~\\eqref{ineq:B_oplus_2p} leads to \\(\\OW{\\fun{sum}}{2p} =\n\\OW{\\fun{sum}}{2p+1} \\sim 4p\\lg p\\). Equations~\\eqref{eq:worst_merge}\nand~\\eqref{eq:cost_unb} and inequation~\\eqref{ineq:OBunb} imply\n\\begin{equation*}\n\\OW{\\fun{unb}}{n} = \\sum_{i=1}^{r}\\sum_{j=0}^{i}{2^{e_j}} - \\nu_n + 1\n                  = \\OB{\\fun{unb}}{n} + n - \\rho_n - \\nu_n + 1\n                  < 2n + 1.\n\\end{equation*}\nTherefore, \\(\\OW{\\fun{oms}}{n} \\sim 2n\\lg n \\sim 2\n\\cdot \\OW{\\fun{bms}}{n}\\).\n\\index{merge sort!online $\\sim$!maximum cost|)}\n\n\\paragraph{Additional cost}\n\nLet us account now for all the rewrites in the evaluation of a call\n\\(\\fun{oms}(s)\\). Let\n\\(\\C{\\fun{oms}}{n}\\)\\index{oms@$\\C{\\fun{oms}}{n}$} be this number. We\nalready know the contribution due to the comparisons,\n\\(\\OC{\\fun{oms}}{n}\\)\\index{oms@$\\OC{\\fun{oms}}{n}$}, either in\nrule~\\(\\kappa\\) or~\\(\\lambda\\), so let us assess \\(\\C{\\fun{oms}}{n} -\n\\OC{\\fun{oms}}{n}\\):\n\\begin{itemize}\n\n  \\item Rule~\\(\\phi\\) is used once.\n\n  \\item Rules \\(\\chi\\)~and~\\(\\psi\\) are involved in the subtrace\n    \\(\\psi^n\\chi\\), hence are used \\(n+1\\)~times.\n\n  \\item Rules \\(\\omega\\), \\(\\gamma\\) and~\\(\\delta\\) are used \\(F(n) =\n    2n - \\nu_n\\) times, as seen in equation~\\eqref{eq:ruler_nu}. We\n    also must account for the rules \\(\\theta\\)~and~\\(\\iota\\) requested\n    by the calls \\(\\fun{mrg}(s,u)\\) in rule~\\(\\delta\\). Each \\(1\\)-bit\n    in the binary notations of the numbers from \\(1\\)~to~\\(n-1\\)\n    triggers such a call, that is, \\(\\sum_{k=1}^{n-1}\\nu_k\\).\n\n  \\item Rules \\(\\nu\\)~and~\\(\\xi\\) are used for each bit in the binary\n    notation of~\\(n\\) and rule~\\(\\mu\\) is used once, making up\n    \\(\\floor{\\lg n} + 2\\) calls. We also need to add the number of\n    calls \\(\\fun{mrg}(t,u)\\)\\index{mrg@\\fun{mrg/2}} in rule~\\(\\xi\\),\n    witnessing the application of rules \\(\\theta\\)~and~\\(\\iota\\). This\n    is the number of \\(1\\)-bits in~\\(n\\), totalling~\\(\\nu_n\\).\n\n\\end{itemize}\nIn total, we have \\(\\C{\\fun{oms}}{n} - \\OC{\\fun{oms}}{n} = 3n +\n\\floor{\\lg n} + \\sum_{k=1}^{n-1}\\nu_k + 2\\). Equation~\\eqref{eq:OBbms}\n\\vpageref{eq:OBbms} entails \\(\\C{\\fun{oms}}{n} = \\OC{\\fun{oms}}{n} +\n3n + \\floor{\\lg n} + \\OB{\\fun{bms}}{n} +\n2\\). Bounds~\\eqref{ineq:bounds_Btms} \\vpageref{ineq:bounds_Btms} imply\n\\(\\OB{\\fun{bms}}{n} \\sim \\tfrac{1}{2}n\\lg n\\), thus \\(\\C{\\fun{oms}}{n}\n\\sim \\OC{\\fun{oms}}{n}\\).  \\index{merge sort|)} \\index{merge\n  sort!online $\\sim$|)}\n\n\\section*{Exercises}\n\n\\begin{enumerate}\n\n  \\item Prove \\(\\fun{mrg}(s,t) \\equiv \\fun{mrg}(t,s)\\).\n\n  \\item Prove that \\(\\fun{mrg}(s,t)\\)\\index{mrg@\\fun{mrg/2}} is a sorted\n  stack if \\(s\\)~and~\\(t\\) are sorted.\n\n  \\item Prove that all the keys of~\\(s\\) and~\\(t\\) are in\n  \\(\\fun{mrg}(s,t)\\).\n\n  \\item Prove the termination of \\(\\fun{bms/1}\\), \\(\\fun{oms/1}\\) and\n    \\(\\fun{tms/1}\\).\\index{bms@\\fun{bms/1}}\\index{oms@\\fun{oms/1}}\n    \\index{tms@\\fun{tms/1}}\n\n  \\item Is \\fun{bms/1} stable? What about \\fun{tms/1}?\n\n  \\item Find \\(\\C{\\fun{tms}}{n} - \\OC{\\fun{tms}}{n}\\). \\emph{Hint:}\n    mind equation~\\eqref{eq:ruler_nu} \\vpageref{eq:ruler_nu}.\n\n  \\item Page~\\pageref{eq:bms_merges}, we found that the number of\n    mergers of \\(\\fun{bms}(s)\\) is~\\(n-1\\) if~\\(n\\) is the number of\n    keys in~\\(s\\). Show that \\(\\fun{tms}(s)\\) performs the same number\n    of mergers. (\\emph{Hint}: Consider equation~\\eqref{eq:cost_tms}\n    \\vpageref{eq:cost_tms}.)\n\n  \\item Find a counting argument on the table of \\fig~\\vref{fig:bits}\n    showing that\n    \\begin{equation*}\n      \\sum_{k=1}^{p-1}{2^{\\rho_k}}\n      = \\sum_{i=0}^{\\ceiling{\\lg p}-1}%\n      {\\left\\lceil\\frac{p-2^i}{2^{i+1}}\\right\\rceil 2^i}.\n    \\end{equation*}\n\n  \\item Compare the number of (\\texttt{|})-nodes created by\n    \\fun{bms/1} and \\fun{tms/1}.\n\n\\end{enumerate}\n", "meta": {"hexsha": "e839e1976ba433b9a43d0a16cc7ba171a725c724", "size": 147399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "merge_sort.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": "merge_sort.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": "merge_sort.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": 44.237394958, "max_line_length": 214, "alphanum_fraction": 0.6224194194, "num_tokens": 60281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.685150422419406}}
{"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*{Example of the QWTB use}\n\n\\begin{par}\nData are simulated, QWTB is used with different algorithms.\n\\end{par} \\vspace{1em}\n\n\\subsubsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Generate ideal data\n   \\item Apply three algorithms\n   \\item Compare results for ideal signal\n   \\item Noisy signal\n   \\item Compare results for noisy signal\n   \\item Non-coherent signal\n   \\item Compare results for non-coherent signal\n   \\item Harmonically distorted signal.\n   \\item Compare results for harmonically distorted signal.\n   \\item Harmonically distorted, noisy, non-coherent signal.\n   \\item Compare results for harmonically distorted, noisy, non-coherent signal.\n\\end{itemize}\n\n\n\\subsubsection*{Generate ideal data}\n\n\\begin{par}\nSample data are generated, representing 1 second of sine waveform of nominal frequency \\lstinline{fnom} 1000 Hz, nominal amplitude \\lstinline{Anom} 1 V and nominal phase \\lstinline{phnom} 1 rad. Data are sampled at sampling frequency \\lstinline{fsnom} 10 kHz, perfectly synchronized, no noise.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nAnom = 1; fnom = 1000; phnom = 1; fsnom = 10e4;\ntimestamps = [0:1/fsnom:0.1-1/fsnom];\nideal_wave = Anom*sin(2*pi*fnom*timestamps + phnom);\n\\end{lstlisting}\n\\begin{par}\nTo use QWTB, data are put into two quantities: \\lstinline{t} and \\lstinline{y}. Both quantities are put into data in structure \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI = [];\nDI.t.v = timestamps;\nDI.y.v = ideal_wave;\n\\end{lstlisting}\n\n\n\\subsubsection*{Apply three algorithms}\n\n\\begin{par}\nQWTB will be used to apply three algorithms to determine frequency and amplitude: \\lstinline{SP-FFT}, \\lstinline{PSFE} and \\lstinline{FPNLSF}. Results are in data out structure \\lstinline{DOxxx}. Algorithm \\lstinline{FPNLSF} requires an estimate, select it to 0.1\\% different from nominal frequency. \\lstinline{SP-FFT} requires sampling frequency.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.fest.v = fnom.*1.001;\nDI.fs.v = fsnom;\nDOspfft = qwtb('SP-FFT', DI);\nDOpsfe = qwtb('PSFE', DI);\nDOfpnlsf = qwtb('FPNLSF', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: PSFE wrapper: sampling time was calculated from sampling frequency\nQWTB: no uncertainty calculation\nFitting started\n\nLocal minimum found.\n\nOptimization completed because the size of the gradient is less than\nthe default value of the function tolerance.\n\n\n\nFitting finished\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Compare results for ideal signal}\n\n\\begin{par}\nCalculate relative errors in ppm for all algorithm to know which one is best. \\lstinline{SP-FFT} returns whole spectrum, so only the largest amplitude peak is interesting. One can see for the ideal case all errors are very small.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\ndisp('SP-FFT errors (ppm):')\n[tmp, ind] = max(DOspfft.A.v);\nferr  = (DOspfft.f.v(ind) - fnom)/fnom .* 1e6\nAerr  = (DOspfft.A.v(ind) - Anom)/Anom .* 1e6\npherr = (DOspfft.ph.v(ind) - phnom)/phnom .* 1e6\n\ndisp('PSFE errors (ppm):')\nferr  = (DOpsfe.f.v - fnom)/fnom .* 1e6\nAerr  = (DOpsfe.A.v - Anom)/Anom .* 1e6\npherr = (DOpsfe.ph.v - phnom)/phnom .* 1e6\n\ndisp('FPNLSF errors (ppm):')\nferr  = (DOfpnlsf.f.v - fnom)/fnom .* 1e6\nAerr  = (DOfpnlsf.A.v - Anom)/Anom .* 1e6\npherr = (DOfpnlsf.ph.v - phnom)/phnom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nSP-FFT errors (ppm):\n\nferr =\n\n     0\n\n\nAerr =\n\n     0\n\n\npherr =\n\n  -4.2920e+05\n\nPSFE errors (ppm):\n\nferr =\n\n  -2.2737e-10\n\n\nAerr =\n\n   4.8850e-09\n\n\npherr =\n\n   2.3093e-08\n\nFPNLSF errors (ppm):\n\nferr =\n\n  -3.4106e-10\n\n\nAerr =\n\n  -4.0512e-07\n\n\npherr =\n\n   1.8208e-08\n\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Noisy signal}\n\n\\begin{par}\nTo simulate real measurement, noise is added with normal distribution and standard deviation \\lstinline{sigma} of 100 microvolt. Algorithms are again applied.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nsigma = 100e-6;\nDI.y.v = ideal_wave + 100e-6.*randn(size(ideal_wave));\nDOspfft = qwtb('SP-FFT', DI);\nDOpsfe = qwtb('PSFE', DI);\nDOfpnlsf = qwtb('FPNLSF', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: PSFE wrapper: sampling time was calculated from sampling frequency\nQWTB: no uncertainty calculation\nFitting started\n\nLocal minimum found.\n\nOptimization completed because the size of the gradient is less than\nthe default value of the function tolerance.\n\n\n\nFitting finished\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Compare results for noisy signal}\n\n\\begin{par}\nAgain relative errors are compared. One can see amplitude and phase errors increased to several ppm, however frequency is still determined quite good by all three algorithms. FFT is not affected by noise at all.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\ndisp('SP-FFT errors (ppm):')\n[tmp, ind] = max(DOspfft.A.v);\nferr  = (DOspfft.f.v(ind) - fnom)/fnom .* 1e6\nAerr  = (DOspfft.A.v(ind) - Anom)/Anom .* 1e6\npherr = (DOspfft.ph.v(ind) - phnom)/phnom .* 1e6\n\ndisp('PSFE errors:')\nferr  = (DOpsfe.f.v - fnom)/fnom .* 1e6\nAerr  = (DOpsfe.A.v - Anom)/Anom .* 1e6\npherr = (DOpsfe.ph.v - phnom)/phnom .* 1e6\n\ndisp('FPNLSF errors:')\nferr  = (DOfpnlsf.f.v - fnom)/fnom .* 1e6\nAerr  = (DOfpnlsf.A.v - Anom)/Anom .* 1e6\npherr = (DOfpnlsf.ph.v - phnom)/phnom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nSP-FFT errors (ppm):\n\nferr =\n\n     0\n\n\nAerr =\n\n   -0.6603\n\n\npherr =\n\n  -4.2920e+05\n\nPSFE errors:\n\nferr =\n\n    0.0010\n\n\nAerr =\n\n   -0.6318\n\n\npherr =\n\n   -1.0933\n\nFPNLSF errors:\n\nferr =\n\n   -0.0011\n\n\nAerr =\n\n   -0.6601\n\n\npherr =\n\n   -0.3809\n\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Non-coherent signal}\n\n\\begin{par}\nIn real measurement coherent measurement does not exist. So in next test the frequency of the signal differs by 20 ppm:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nfnc = fnom*(1 + 20e-6);\nnoncoh_wave = Anom*sin(2*pi*fnc*timestamps + phnom);\nDI.y.v = noncoh_wave;\nDOspfft = qwtb('SP-FFT', DI);\nDOpsfe = qwtb('PSFE', DI);\nDOfpnlsf = qwtb('FPNLSF', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: PSFE wrapper: sampling time was calculated from sampling frequency\nQWTB: no uncertainty calculation\nFitting started\n\nLocal minimum found.\n\nOptimization completed because the size of the gradient is less than\nthe default value of the function tolerance.\n\n\n\nFitting finished\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Compare results for non-coherent signal}\n\n\\begin{par}\nComparison of relative errors. Results of \\lstinline{PSFE} or \\lstinline{FPNLSF} are correct, however FFT is affected by non-coherent signal considerably.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\ndisp('SP-FFT errors (ppm):')\n[tmp, ind] = max(DOspfft.A.v);\nferr  = (DOspfft.f.v(ind) - fnc)/fnc .* 1e6\nAerr  = (DOspfft.A.v(ind) - Anom)/Anom .* 1e6\npherr = (DOspfft.ph.v(ind) - phnom)/phnom .* 1e6\n\ndisp('PSFE errors:')\nferr  = (DOpsfe.f.v - fnc)/fnc .* 1e6\nAerr  = (DOpsfe.A.v - Anom)/Anom .* 1e6\npherr = (DOpsfe.ph.v - phnom)/phnom .* 1e6\n\ndisp('FPNLSF errors:')\nferr  = (DOfpnlsf.f.v - fnc)/fnc .* 1e6\nAerr  = (DOfpnlsf.A.v - Anom)/Anom .* 1e6\npherr = (DOfpnlsf.ph.v - phnom)/phnom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nSP-FFT errors (ppm):\n\nferr =\n\n  -19.9996\n\n\nAerr =\n\n   -2.8780\n\n\npherr =\n\n  -4.3550e+05\n\nPSFE errors:\n\nferr =\n\n  -1.1368e-10\n\n\nAerr =\n\n   3.8924e-07\n\n\npherr =\n\n   3.3073e-04\n\nFPNLSF errors:\n\nferr =\n\n  -1.1368e-10\n\n\nAerr =\n\n  -3.2940e-07\n\n\npherr =\n\n   2.6867e-08\n\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Harmonically distorted signal.}\n\n\\begin{par}\nIn other cases a harmonic distortion can appear. Suppose a signal with second order harmonic of 10\\% amplitude as the main signal.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nhadist_wave = Anom*sin(2*pi*fnom*timestamps + phnom) + 0.1*Anom*sin(2*pi*fnom*2*timestamps + 2);\nDI.y.v = hadist_wave;\nDOspfft = qwtb('SP-FFT', DI);\nDOpsfe = qwtb('PSFE', DI);\nDOfpnlsf = qwtb('FPNLSF', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: PSFE wrapper: sampling time was calculated from sampling frequency\nQWTB: no uncertainty calculation\nFitting started\n\nLocal minimum found.\n\nOptimization completed because the size of the gradient is less than\nthe default value of the function tolerance.\n\n\n\nFitting finished\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Compare results for harmonically distorted signal.}\n\n\\begin{par}\nComparison of relative errors. \\lstinline{SP-FFT} or \\lstinline{PSFE} are not affected by harmonic distortion, however \\lstinline{FPNLSF} is thus is not suitable for such signal.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\ndisp('SP-FFT errors (ppm):')\n[tmp, ind] = max(DOspfft.A.v);\nferr  = (DOspfft.f.v(ind) - fnom)/fnom .* 1e6\nAerr  = (DOspfft.A.v(ind) - Anom)/Anom .* 1e6\npherr = (DOspfft.ph.v(ind) - phnom)/phnom .* 1e6\n\ndisp('PSFE errors:')\nferr  = (DOpsfe.f.v - fnom)/fnom .* 1e6\nAerr  = (DOpsfe.A.v - Anom)/Anom .* 1e6\npherr = (DOpsfe.ph.v - phnom)/phnom .* 1e6\n\ndisp('FPNLSF errors:')\nferr  = (DOfpnlsf.f.v - fnom)/fnom .* 1e6\nAerr  = (DOfpnlsf.A.v - Anom)/Anom .* 1e6\npherr = (DOfpnlsf.ph.v - phnom)/phnom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nSP-FFT errors (ppm):\n\nferr =\n\n     0\n\n\nAerr =\n\n     0\n\n\npherr =\n\n  -4.2920e+05\n\nPSFE errors:\n\nferr =\n\n  -2.2737e-10\n\n\nAerr =\n\n   6.7212e-04\n\n\npherr =\n\n    0.5311\n\nFPNLSF errors:\n\nferr =\n\n   -0.7356\n\n\nAerr =\n\n    0.1407\n\n\npherr =\n\n  231.4553\n\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Harmonically distorted, noisy, non-coherent signal.}\n\n\\begin{par}\nIn final test all distortions are put in a waveform and results are compared.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nerr_wave = Anom*sin(2*pi*fnc*timestamps + phnom) + 0.1*Anom*sin(2*pi*fnc*2*timestamps + 2) + 100e-6.*randn(size(ideal_wave));\nDI.y.v = err_wave;\nDOspfft = qwtb('SP-FFT', DI);\nDOpsfe = qwtb('PSFE', DI);\nDOfpnlsf = qwtb('FPNLSF', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: PSFE wrapper: sampling time was calculated from sampling frequency\nQWTB: no uncertainty calculation\nFitting started\n\nLocal minimum found.\n\nOptimization completed because the size of the gradient is less than\nthe default value of the function tolerance.\n\n\n\nFitting finished\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Compare results for harmonically distorted, noisy, non-coherent signal.}\n\n\\begin{lstlisting}[style=mcode]\ndisp('SP-FFT errors (ppm):')\n[tmp, ind] = max(DOspfft.A.v);\nferr  = (DOspfft.f.v(ind) - fnc)/fnc .* 1e6\nAerr  = (DOspfft.A.v(ind) - Anom)/Anom .* 1e6\npherr = (DOspfft.ph.v(ind) - phnom)/phnom .* 1e6\n\ndisp('PSFE errors:')\nferr  = (DOpsfe.f.v - fnc)/fnc .* 1e6\nAerr  = (DOpsfe.A.v - Anom)/Anom .* 1e6\npherr = (DOpsfe.ph.v - phnom)/phnom .* 1e6\n\ndisp('FPNLSF errors:')\nferr  = (DOfpnlsf.f.v - fnc)/fnc .* 1e6\nAerr  = (DOfpnlsf.A.v - Anom)/Anom .* 1e6\npherr = (DOfpnlsf.ph.v - phnom)/phnom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nSP-FFT errors (ppm):\n\nferr =\n\n  -19.9996\n\n\nAerr =\n\n    1.1501\n\n\npherr =\n\n  -4.3550e+05\n\nPSFE errors:\n\nferr =\n\n   -0.0072\n\n\nAerr =\n\n    4.1189\n\n\npherr =\n\n    4.6464\n\nFPNLSF errors:\n\nferr =\n\n   -0.7241\n\n\nAerr =\n\n    3.6943\n\n\npherr =\n\n  229.3720\n\n\\end{lstlisting} \\color{black}\n    \n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "d25721f9873c42402a97d472e9e26d5d0985c0ff", "size": 12029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/qwtb_examples_published/qwtb_example_2.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/qwtb_examples_published/qwtb_example_2.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/qwtb_examples_published/qwtb_example_2.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": 20.3192567568, "max_line_length": 347, "alphanum_fraction": 0.6964834982, "num_tokens": 4172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6850618858391508}}
{"text": "\\chapter{Dimension Reduction}\\label{chap:dimred}\n\nDimension reduction is a statistical process, which concentrates the\namount of information in multivariate data into a fewer number of\nvariables (or dimensions). An interesting review of the domain has been done by Fodor~\\cite{Fodor2002dimensionred}.\n\nThough there are plenty of non-linear methods in the litterature, OTB\nprovides only linear dimension reduction techniques applied to images for now.\n\nUsually, linear dimension-reduction algorithms try to find a set of\nlinear combinations of the input image bands that maximise a given\ncriterion, often chosen so that image information concentrates on the\nfirst components. Algorithms differs by the criterion to optimise and\nalso by their handling of the signal or image noise.\n\nIn remote-sensing images processing, dimension reduction algorithms\nare of great interest for denoising, or as a preliminary processing\nfor classification of feature images or unmixing of hyperspectral\nimages. In addition to the denoising effect, the advantage of\ndimension reduction in the two latter is that it lowers the size of\nthe data to be analysed, and as such, speeds up the processing time\nwithout too much loss of accuracy.\n\n\\section{Principal Component Analysis}\n\n\\input{PCAExample}\n\n\\section{Noise-Adjusted Principal Components Analysis}\n\n\\input{NAPCAExample}\n\n\\section{Maximum Noise Fraction}\n\n\\input{MNFExample}\n\n\\section{Fast Independent Component Analysis}\n\n\\input{ICAExample}\n\n\\section{Maximum Autocorrelation Factor}\n\n\\input{MaximumAutocorrelationFactor}\n\n\n", "meta": {"hexsha": "5fdd36e3a3755ac1e0275ce46891f729867afdf7", "size": 1557, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/SoftwareGuide/Latex/DimensionReduction.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/DimensionReduction.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/DimensionReduction.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": 34.6, "max_line_length": 115, "alphanum_fraction": 0.8208092486, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6850618858391508}}
{"text": "\\subsection{Test 3 Answers}\r\n\r\n\\begin{enumerate}[label=\\arabic*.]\r\n\t\\item\r\n\t\tLet $f(t)$ be a function defined for $t \\geq 0$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\Laplace{f} = \\int_{0}^{\\infty}{e^{-st}f(t) \\mathrm{d}t}\r\n\t\t\\end{equation*}\r\n\t\\item\r\n\t\t\\begin{enumerate}[label = (\\alph*)]\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\\Laplace{e^{x}} &= \\int_{0}^{\\infty}{e^{-st}e^{t} \\mathrm{d}t} \\\\\r\n\t\t\t\t\t&= \\int_{0}^{\\infty}{e^{t(1-s)} \\mathrm{d}t} \\\\\r\n\t\t\t\t\t&= \\frac{1}{1-s}e^{t(1-s)} \\bigg\\rvert_{0}^{\\infty} \\\\\r\n\t\t\t\t\t&= \\frac{1}{1-s}\\left(\\lim_{a \\to \\infty}{e^{a(1-s)}} - e^{0(1-s)} \\right) \\\\\r\n\t\t\t\t\t&= \\frac{1}{1-s}\\left(0 - 1\\right) \\text{, }  s > 1\\\\\r\n\t\t\t\t\t&= \\frac{1}{s-1} \\text{, } s > 1\r\n\t\t\t\t\\end{align*}\t\t\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\Laplace{\\sin{t} + 2\\cos{3t}} = \\Laplace{\\sin{t}} + 2\\Laplace{\\cos{3t}}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tby the linearity of the Laplace transform.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t = \\Laplace{\\sin{t}} + \\frac{2}{3}\\mathcal{L}\\left\\{\\cos{t}\\right\\}{(\\frac{s}{3})}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tas specified in the table of Laplace transforms for $\\sin$ and $\\cos$.\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t&= \\frac{1}{s^2 + 1^2} + \\frac{2}{3}\\left(\\frac{s/3}{(s/3)^2 + 1^2}\\right) \\\\\r\n\t\t\t\t\t&= \\frac{1}{s^2 + 1^2} + \\frac{2}{3}\\frac{3s}{s^2 + 3^2} \\\\\r\n\t\t\t\t\t&= \\frac{1}{s^2+1^2} + \\frac{2s}{s^2 + 3^2} \\\\\r\n\t\t\t\t\t&= \\frac{2s^3 + s^2 + 2s + 9}{\\left(s^2 + 1\\right)\\left(s^2+9\\right)}\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\Laplace{e^{3t}\\left(t^2+3t+2\\right)} = \\Laplace{e^{3t}t^2} + 3\\Laplace{e^{3t}x} + 2\\Laplace{e^{3t}}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tby the linearity of the Laplace transform.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t = \\frac{2!}{(s-3)^{2+1}} + 3\\frac{1!}{(s-3)^{1+1}} + 2\\frac{0!}{(s-3)^{0+1}}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tas specified in the table of Laplace transforms for an exponential and power of $t$.\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t &= \\frac{2}{(s-3)^3} + \\frac{3}{(s-3)^2} + \\frac{2}{(s-3)} \\\\\r\n\t\t\t\t\t &= \\frac{2(s-3)^2 + 3(s-3) + 2}{(s-3)^3} \\\\\r\n\t\t\t\t\t &= \\frac{2s^2 - 9s + 11}{(s-3)^3}\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\Laplace{\\dd{}{t}{(e^{3t+1} + e^{1-t})}} = s\\Laplace{e^{3t+1} + e^{1-t}} - \\left(e^{3\\cdot 0 + 1} + e^{1-0}\\right)\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tby the Laplace transform of a derivative.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t= s\\left(e\\Laplace{e^{3t}} + e\\Laplace{e^{-t}}\\right) - 2e\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tby the linearity of the Laplace transform.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t = s\\left(e\\frac{1}{s-3} + e\\frac{1}{s+1}\\right) - 2e\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tas specified in the table of Laplace trasforms for the Laplace transform of an exponential.\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t&= \\frac{se}{s-3} + \\frac{se}{s+1} - 2e \\\\\r\n\t\t\t\t\t&= \\frac{se(s+1) + se(s-3) -2e(s+1)(s-3)}{(s+1)(s-3)} \\\\\r\n\t\t\t\t\t&= \\frac{2e(s+3)}{(s+1)(s-3)}\r\n\t\t\t\t\\end{align*}\r\n\t\t\\end{enumerate}\r\n\t\\item\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\t\\inverseLaplace{\\frac{1}{1+s}} = e{-t}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\\inverseLaplace{\\frac{s^2+2s+1}{s^3-4s^2+5s-2}} &= \\inverseLaplace{\\frac{-8}{s-1}}-\\inverseLaplace{\\frac{4}{(s-1)^2}}+\\inverseLaplace{\\frac{9}{s-2}} \\\\\r\n\t\t\t\t\t&= -8e^{t} - 4e^{t}t + 9e^{2t}\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\\inverseLaplace{\\frac{s-4}{s^2-8s+32}} &= \\inverseLaplace{\\frac{s-4}{(s-4)^2 + 4^2}} \\\\\r\n\t\t\t\t\t&= e^{4t}\\cos{(4t)}\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\\inverseLaplace{\\frac{768}{(2s+3)^5}} &= \\inverseLaplace{\\frac{4!}{(s+\\frac{3}{2})^{4+1}}} \\\\\r\n\t\t\t\t\t&= e^{-\\frac{3}{2}t}t^4\r\n\t\t\t\t\\end{align*}\r\n\t\t\\end{enumerate}\r\n\t\\item\r\n\t\tWe'll use method of undetermined coefficients.\r\n\t\tExtracting and solving the axillary equation,\r\n\t\t\\begin{equation*}\r\n\t\t\t2r^2 - 3r + 1 = 0 \\implies r = \\frac{1}{2} \\text{, } 1.\r\n\t\t\\end{equation*}\r\n\t\tSo, our homogeneous solution is\r\n\t\t\\begin{equation*}\r\n\t\t\ty_h = C_1e^{\\frac{x}{2}} + C_2e^{x}.\r\n\t\t\\end{equation*}\r\n\t\tWe'll guess that the particular solution has the form\r\n\t\t\\begin{align*}\r\n\t\t\ty_p &= A\\sin{x} + B\\cos{x} \\\\\r\n\t\t\t2y_p'' - 3y_p' + y_p &= 10\\sin{x} \\implies A = -1 \\text{, } B = 3.\r\n\t\t\\end{align*}\r\n\t\tSo,\r\n\t\t\\begin{equation*}\r\n\t\t\ty_p = -\\sin{x} + 3\\cos{x},\r\n\t\t\\end{equation*}\r\n\t\tand our general solution is\r\n\t\t\\begin{equation*}\r\n\t\t\ty = C_1e^{\\frac{x}{2}} + C_2e^{x} -\\sin{x} + 3\\cos{x}.\r\n\t\t\\end{equation*}\r\n\t\tNow we'll use Laplace transform. Taking the Laplace transform of both sides,\r\n\t\t\\begin{align*}\r\n\t\t\t\\Laplace{2y'' - 3y' + y} &= \\Laplace{10\\sin{x}} \\\\\r\n\t\t\t\\Laplace{y} \\cdot (2s^2 - 3s + 1) &= \\frac{10}{s^2+1} + 2y'(0) + 3y(0) -2sy(0) \\\\\r\n\t\t\t\\Laplace{y} \\cdot (2s^2 - 3s + 1) &= \\frac{10 + 3y(0)s^2 + 3y(0) - 2s^3y(0) - 2sy(0) + 2s^2y'(0) + 2y'(0)}{s^2+1} \\\\\r\n\t\t\t\\Laplace{y} &= \\frac{-2y(0)s^3 + (3y(0)+2y'(0))s^2 -2sy(0) + 3y(0) + 2y'(0) + 10}{\\left(s^2+1\\right)\\left(2s^2-3s+1\\right)} \\\\\r\n\t\t\t&= \\frac{-2y(0)s^3 + (3y(0)+2y'(0))s^2 -2sy(0) + 3y(0) + 2y'(0) + 10}{\\left(s^2+1\\right)\\left(2s-1\\right)\\left(s-1\\right)} \\\\\r\n\t\t\t&= \\frac{-4(y(0)+y'(0)+4)}{2s-1} + \\frac{y(0)+2y'(0)+5}{s-1} + \\frac{3s-1}{s^2+1}.\r\n\t\t\\end{align*}\r\n\t\tLet $C_1 = -2(y(0)+y'(0)+4)$ and $C_2 = y(0) + 2y'(0) + 5$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\Laplace{y} = \\frac{2C_1}{2s-1} + \\frac{C_2}{s-1} - \\frac{1}{s^2+1} + 3\\frac{s}{s^2+1}.\r\n\t\t\\end{equation*}\r\n\t\tTaking the inverse Laplace transform of both sides,\r\n\t\t\\begin{equation*}\r\n\t\t\ty = C_1e^{\\frac{x}{2}} + C_2e^x -\\sin{x} + 3\\cos{x}.\r\n\t\t\\end{equation*}\r\n\t\tWe can see that we have the same solution for $y$ in both methods.\r\n\t\\item\r\n\t\tTaking the Laplace transform of both sides and solving for the Laplace transform of $y$,\r\n\t\t\\begin{align*}\r\n\t\t\t\\Laplace{2y'' + 4y' - 6y} &= \\Laplace{te^{-3t}} \\\\\r\n\t\t\t\\Laplace{y} \\cdot (2s^2 + 4s - 6) - 2sy(0) - 2y'(0) - 4y(0) &= \\frac{1}{(s+3)^2} \\\\\r\n\t\t\t\\Laplace{y} \\cdot (2s^2 + 4s - 6) - 2s - 4 &= \\frac{1}{(s+3)^2} \\\\\r\n\t\t\t\\Laplace{y} \\cdot (2s^2 + 4s - 6) &= \\frac{1}{(s+3)^2} + 2s + 4 \\\\\r\n\t\t\t&= \\frac{2s^3 + 16s^2 + 42s + 37}{(s+3)^2} \\\\\r\n\t\t\t\\Laplace{y} &= \\frac{2s^3 + 16s^2 + 42s + 37}{2(s+3)^3(s-1)}.\r\n\t\t\\end{align*}\r\n\t\tConverting the right side to partial fractions,\r\n\t\t\\begin{equation*}\r\n\t\t\t\\Laplace{y} = \\frac{31}{128(s+3)} - \\frac{1}{32(s+3)^2} - \\frac{1}{8(s+3)^3} + \\frac{97}{128(s-1)}.\r\n\t\t\\end{equation*}\r\n\t\tTaking the inverse Laplace transform of both sides to solve for $y$,\r\n\t\t\\begin{equation*}\r\n\t\t\ty = \\frac{31}{128}e^{-3t} - \\frac{1}{32}te^{-3t} - \\frac{1}{16}t^2e^{-3t} + \\frac{97}{128}e^{t}.\r\n\t\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "50bbff0cf5bba748e9990ed809b7573460ad3268", "size": 6391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/additionalResources/tests/test3_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": "diffEq/additionalResources/tests/test3_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": "diffEq/additionalResources/tests/test3_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": 42.8926174497, "max_line_length": 157, "alphanum_fraction": 0.5207322798, "num_tokens": 3126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6850618797975377}}
{"text": "\\documentclass{report}\r\n\\usepackage{amsfonts}\r\n\\usepackage{amssymb}\r\n\\usepackage{multicol}\r\n\\usepackage{graphicx}\r\n\\setlength{\\oddsidemargin}{0in}\r\n\\setlength{\\evensidemargin}{0in}\r\n\\setlength{\\topmargin}{-.5in}\r\n\\setlength{\\textwidth}{6.5in}\r\n\\setlength{\\textheight}{9.5in}\r\n\r\n\\begin{document}\r\n\\section{Orbits}\r\n$r^2 \\dot{\\theta} =h$.\r\n$r = {\\frac {h^2}{k(1+e \\cdot cos( \\theta ))}}$.\r\n$r_{min}= {\\frac {h^2}{k^3}} {\\frac {1} {1+e}}$,\r\n$r_{max}= {\\frac {h^2}{k^3}} {\\frac {1} {1-e}}$.\r\n$\\dot{\\theta} = {\\frac {k^2}{h^3}} (1+ e \\cdot cos(\\theta ))^2$.\r\n$\\int {\\frac {h^3}{k^2}} {\\frac {1} {(1+e \\cdot cos( \\theta ))^2}}= t$.\r\n$S$ is the satellite and $O$ is the observer.\r\n\\\\\r\n\\\\\r\n1. Compute $\\theta(t), r(t)$ from integral above in orbital plane.  At $t_0$,\r\n$S$ is at ascending node position.\r\n\\\\\r\n2. Rotate orbital parameters by the inclination, $i$, in the line formed by the\r\nascending node and descending node.\r\n\\\\\r\n3. Rotate around $z$ by the angle of the ascending node to get to ecliptic coordinates.\r\n$S$ is at ascending node when $t=0$.\r\n\\\\\r\n4. Get $\\delta$, $RA$ of $S$.\r\n\\\\\r\n5. Get $\\lambda$, $L$ of $O$.\r\n\\\\\r\n6. Find $\\delta '$ and $RA '$, from $O$'s point of view.\r\n\\\\\r\n\\\\\r\n$S$ is at at $( \\delta , RA )$, $O$ is at $( \\lambda , L)$. $\\overline{x}$ means\r\n$90-x$.\r\n$cos ( \\overline{ \\delta ' }) =\r\ncos( RA+L ) sin(\\overline{\\delta}) sin(\\overline{\\lambda}) +\r\ncos(\\overline{\\delta}) cos(\\overline{\\lambda})$.\r\n${\\frac {\\overline{\\delta}} {sin(RA')}} =\r\n{\\frac {\\overline{\\delta'}} {sin(RA+L)}} $.  $RA$ is measured from the arc $ON$ to the arc\r\n$OS$.\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "84d119a27142b0678907fbf5a05c583759e67586", "size": 1586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/orbit.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/orbit.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/orbit.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": 32.3673469388, "max_line_length": 91, "alphanum_fraction": 0.5945775536, "num_tokens": 582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6850618788497059}}
{"text": "\\section{Result}\n\\subsection{Distance Between Two Lasar Device}\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{|l|c |c |c |}\n    \\hline\n    \\multicolumn{4}{|c|}{distance $S$ [mm] $\\pm$ 1 [mm]} \\\\\n    \\hline\n    S &  Ruler Start Point & Ruler End Point & Calculated Length \\\\\n    \\hline\n    $S_1$ & 30.0 & 177.0 & 147.0 \\\\ \\hline\n    $S_2$ & 60.0 & 207.0 & 147.0 \\\\ \\hline\n    $S_3$ & 40.0 & 186.5 & 146.5 \\\\ \\hline\n  \\end{tabular}\n  \\caption{Distance measurement data.}\n\\end{table}\n\nThen we can find\n$$  \\bar{S} = \\frac{1}{3} \\sum_{k=1}^{3} S_k = 146.8 mm \\pm 1 mm   $$\n$$  u_{S,r} = 0.68 \\%  $$ \n\n\n\\subsection{Time Measurement}\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{|l|c|}\n    \\hline\n    \\multicolumn{2}{|c|}{time $t$ [s] $\\pm$ 0.01 [s] } \\\\\n    \\hline\n    $t_1$ & 6.75 \\\\ \\hline\n    $t_2$ & 6.82 \\\\ \\hline\n    $t_3$ & 6.91 \\\\ \\hline\n    $t_4$ & 6.88 \\\\ \\hline\n    $t_5$ & 6.91 \\\\ \\hline\n    $t_6$ & 6.84 \\\\ \\hline\n  \\end{tabular}\n  \\caption{Time measurement data.}\n\\end{table}\n\n\nThen we can find\n$$  \\bar{t} = \\frac{1}{6} \\sum_{k=1}^{6} t_k =6.85 s \\pm 0.01 s   $$\n$$  u_{t,r} = 0.15 \\%  $$ \n\n\\subsection{The Diameters of The Balls}\n\nThe initial reading of the meter is 0.38 mm.\nThus, the raw data of measurement should firstly minus 0.38 mm, and is presented\nas following, \n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{|p{2cm}|p{3cm}||p{2cm} |p{3cm} |}\n    \\hline\n    \\multicolumn{4}{|c|}{diameter $d$ [mm] $\\pm$ 0.005 [mm]  } \\\\\n    \\hline\n    $d_1$ & 1.995 & $d_6$ & 1.995 \\\\ \\hline\n    $d_2$ & 1.995 & $d_7$ & 2.000 \\\\ \\hline\n    $d_3$ & 2.000 & $d_8$ & 1.800 \\\\ \\hline\n    $d_4$ & 1.995 & $d_9$ & 1.995 \\\\ \\hline\n    $d_5$ & 2.000 & $d_{10}$ & 1.995 \\\\ \\hline\n  \\end{tabular}\n  \\caption{Ball diameter measurement data.}\n\\end{table}\n\nThen we can find\n$$  \\bar{d} = \\frac{1}{10} \\sum_{k=1}^{10} d_k = 1.977  mm \\pm  0.005 mm   $$\n$$  u_{t,r} =  0.25 \\%  $$ \n\n\\subsection{The Inner Diameter of The Flask}\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{|p{1cm}|c|}\n    \\hline\n    \\multicolumn{2}{|c|}{diameter $D$ [mm] $\\pm$ 0.02 [mm]  } \\\\\n    \\hline\n    $D_1$ & 61.40 \\\\ \\hline\n    $D_2$ & 61.46 \\\\ \\hline\n    $D_3$ & 61.20 \\\\ \\hline\n    $D_4$ & 61.36 \\\\ \\hline\n    $D_5$ & 61.20 \\\\ \\hline\n    $D_6$ & 61.50 \\\\ \\hline\n  \\end{tabular}\n  \\caption{Flask diameter measurement data.}\n\\end{table}\n\n\nThen we can find\n$$  \\bar{D} = \\frac{1}{6} \\sum_{k=1}^{6} D_k =  61.3533 mm \\pm  0.02 mm   $$\n$$  u_{D,r} =   0.03\\%  $$ \n\n\n\\subsection{Other Physical Quantities}\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{|c|c|}\n    \\hline\n    density of the castor oil $ \\rho_1 [g/cm^3] \\pm 0.001 [g/cm^3] $ & 0.955  \\\\ \\hline \n    mass of 40 metal balls $ m  [g] \\pm 0.001 [g] $ & 1.357 \\\\ \\hline\n    temperature in the lab $ T  [\\circ C] \\pm 2 [\\circ C] $ & 25 \\\\ \\hline\n    acceleration due to gravity in the lab $ g [m/s^2] $ & 9.794 \\\\ \\hline\n  \\end{tabular}\n  \\caption{Other Physical Quantities Measurement}\n\\end{table}\n\n\\subsection{Calculation of Density of One Ball}\n\nThe mass of one  metal ball can be calculated as\n$$  m_0 = \\frac{m}{40} = \\frac{1.357 \\times 10^{-3} }{40} = 3.3925 \\times 10^-5 kg\n\\pm (2.500 \\times 10^-8) kg $$ \nWe can furtherly get the density,\n$$ \\rho_2 = \\frac{m_0}{\\frac{1}{6} \\pi d^3} = \\frac{3.3925 \\times 10^-5\n}{\\frac{1}{6} \\times 3.151593 \\times (1.977 \\times 10^-3)^3 } = 8.385 \\times\n10^3 kg/m^3 \\pm (5.756 \\times 10  ) kg/m^3  $$\n$$  u_{\\rho_2,r} =   0.6875\\%  $$ \n\n\\subsection{Calculation For The Viscosity Coefficient}\nFrom the last equation in introduction part\n\\begin{multline*}\n\\mu = \\frac{2}{9} g R^2 \\frac{( \\rho_2 - \\rho_1 ) t  }{s} (1 + 2.4\n\\frac{R}{R_c})  =  \\frac{2 \\times (1.977 \\times 10^-3 \\times \\frac{1}{2})^2\n  (8.385\\times 10^3 - 0.595 \\times 10^3 ) \\times 9.974 \\times 6.85 }{9 \\times\n  146.8\\times 10^-3 \\times (1 + 2.4 \\times \\frac{1.977}{61.3533})} \\\\\n = 0.7307 Pa \\times s \\pm (6.8329 \\times 10^-3 ) Pa \\times s \n \\end{multline*}\n$$  u_{\\mu,r} =  0.93512 \\%  $$ \n\n", "meta": {"hexsha": "d9550250ca082896c74419e6fad2a30620c7411f", "size": 3935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E2/part/5r.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/5r.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/5r.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.8106060606, "max_line_length": 88, "alphanum_fraction": 0.5626429479, "num_tokens": 1793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6850073831346973}}
{"text": "\\section{Bisection and Newton-Raphson method for finding roots}\n\n\\subsection{Bisection method}\n\nWe will use the bisection method to find when $y_p(\\phi)=0$ for a given tolerance $\\epsilon$. \nThe requirement for the bisection method is that the function in question is continuous on the closed interval $[a,b]$\\footnote{\\href{https://mathworld.wolfram.com/Bisection.html}{Bisection method - Wolfram MathWorld}}, so the roots of $y_p(\\phi)$ can be found. The roots of $w\\,'(\\phi)$ will be found using the Newton's method later.\n\n\\subsection{Newton-Raphson method}\n\nIn Eq. 40 from the presentation, $w_p\\,'(\\phi)$ was not expressed in terms of $\\beta$, \nso the following expression will be used:\n\n\\begin{equation}\n    w_p\\,'(\\phi)=\\frac{2(\\sin^2(2\\phi+\\pi/2)-3)\\sin(2\\phi+\\pi/2)}{(3\\pi+8)\\beta^2\\sin^3(2\\phi+\\pi/2)}\n    -\\frac{\\cos(2\\phi+\\pi/2)\\left(1-\\frac{4}{(3\\pi+8)\\beta^2}(3\\phi+2)\\right)}{r_0\\sin^3(2\\phi+\\pi/2)}\n\\end{equation}\n\nThis method cannot be used to solve for the root of $y_p(\\phi)$ because although the function exists in the domain $\\phi\\in[0,\\pi/4)$,\n$\\lim_{\\phi\\to 0^+}y_p\\,'(\\phi)$ and $\\lim_{\\phi\\to \\pi/4^-}y_p\\,'(\\phi)$ do not exist, so the function is not differentiable on the entire interval\\footnote{\\href{http://amsi.org.au/ESA_Senior_Years/SeniorTopic3/3j/3j_2content_2.html}{Newton's method}}.\n\nFrom observing the graph of $y_p(\\phi)$ on Page 6, this is confirmed visually. Since the endpoints of $y_p(\\phi)$ on this interval are its two roots,\nthey cannot be found through this method. The bisection method works, however, since the only requirement is continuity of $y_p(\\phi)$ on the interval.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[]{plots/phi-functions.pdf}\n    \\caption{A plot of $\\phi_\\mathrm{min}$ and $\\phi_0$ vs $\\delta$}\\label{phifig}\n\\end{figure}\n\nThe code used to implement both algorithms is located \\href{https://gist.github.com/sidnb13/d715682a9915ec4cf49d66ceb2e54855}{here}. Figure \\ref{phifig} demonstrates the bisection method for finding $\\phi_0$ and Newton's method for $\\phi_\\mathrm{min}$.\n\n\\section{Curve fitting}\n\n\\subsection{Objective}\n\nThe least-squared method of curve fitting\\footnote{\\href{https://www.dam.brown.edu/people/alcyew/handouts/leastsq.pdf}{Curve fitting: least squares methods}} was used to generate the closed-form equations $\\phi_0(\\delta)$ and $\\phi_\\mathrm{min}(\\delta)$.\n\nThe approach is to define an error function $E(\\phi)=\\sqrt{\\frac{1}{n}\\sum_{i=1}^n(\\phi_i-\\phi(\\delta_i))^2}$ that represents the RMS error between the fitted curve and original data. $n$ is the number of data points in the set $\\{(\\delta_1,\\phi_1),\\ldots,(\\delta_n,\\phi_n)\\}$ and $\\phi(\\delta)$ represents the fitted curve.\nBecause a polynomial curve is desired, the coefficients of the terms in $\\delta(\\phi)$ belong to $\\vec c\\in \\mathbb{R}^{k+1}$, so there are $k+1$ coefficients in the fitted polynomial. Since $\\phi(\\delta;\\vec{c})$, $E:\\mathbb{R}^{k+1}\\to \\mathbb{R};\\vec{c}$. The objective is then to find a $\\vec{c}$ which minimizes $E(\\vec{c})$. Similarly, each $\\phi(\\delta_i)$ becomes a function of $\\vec{c}$.\n\nMinimizing $E(\\vec{c})=\\sqrt{\\frac{1}{n}\\sum_{i=1}^n(\\phi_i-\\phi(\\delta_i))^2}$ is the same as minimizing $E_1(\\vec{c})=\\sum_{i=1}^n(\\phi_i-\\phi(\\delta_i))^2$, so the next step is to solve\n\n\\begin{gather}\n    \\frac{\\partial E_1}{\\partial c_j}=2\\sum_{i=1}^n(\\phi_i-\\phi(\\delta_i)) \\frac{\\partial \\phi(\\delta_i)}{\\partial c_j}=0\\\\\n    \\sum_{i=1}^n\\frac{\\partial \\phi(\\delta_i)}{\\partial c_j}\\phi_i=\\sum_{i=1}^n\\frac{\\partial \\phi(\\delta_i)}{\\partial c_j}\\phi(\\delta_i)\\\\\n    \\sum_{i=1}^n \\delta_i^{j-1}\\phi_i=\\sum_{i=1}^n c_j\\delta_i^{2j-1}+\\ldots+c_1\\delta_i^{j-1}=\\sum_{\\ell=1}^j\\sum_{i=1}^n c_{j-\\ell+1}\\delta_i^{2j-\\ell-1}\n\\end{gather}\n\nwhere $j=1,\\ldots,k+1$ and the polynomial is of degree $k$.\n\nA vectorized implementation yields\n\n\\begin{equation}\n    \\begin{bmatrix}\\sum_{i=1}^n \\delta_i^k\\phi_i\\\\\\vdots\\\\\\sum_{i=1}^n \\delta_i^1\\phi_i\\end{bmatrix}\n    =\\begin{bmatrix}\\sum_{i=1}^n\\delta_i^{2k}&\\cdots&\\sum_{i=1}^n\\delta_i^{k}\\\\\\vdots&\\ddots&\\vdots\\\\\\sum_{i=1}^n \\delta_i^{k}&\\cdots&\\sum_{i=1}^n\\end{bmatrix}\n    \\begin{bmatrix}c_{k+1}\\\\\\vdots\\\\c_1\\end{bmatrix}\n    =\\begin{bmatrix}\\sum_{i=1}^nc_{k+1}\\delta_i^{2k}&\\cdots&\\sum_{i=1}^nc_1\\delta_i^{k}\\\\\\vdots&\\ddots&\\vdots\\\\\\sum_{i=1}^n c_{k+1}\\delta_i^{k}&\\cdots&\\sum_{i=1}^nc_1\\end{bmatrix}\\\\\n\\end{equation}\n\n\\begin{equation}\n    \\vec{b}=A\\vec{c}\n\\end{equation}\n\nThe matrix-vector equation $A\\vec{c}=\\vec{b}$ can then be solved for $\\vec{c}$ using an optimized linear algebra library, and the resulting coefficients used to generate a function $\\phi(\\delta)$.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[]{plots/phi-curve-fit-poly.pdf}\n    \\caption{Using degree 5 polynomials to approximate $\\phi_0(\\delta)$ and $\\phi_\\mathrm{min}(\\delta)$}\\label{polyerror}\n\\end{figure}\n\nA better approximation is desired since even with degree 5, a polynomial approximation cannot fit well to the smooth curves of $\\phi_0$ and $\\phi_\\mathrm{min}$. This is evidenced by the Runge effect visible in the error plot of Figure \\ref{polyerror}.\n\n\\subsection{Attempted approximation using Chebyshev polynomial interpolation}\n\nThe Chebyshev polynomial approximations resulted in a more pronounced Runge effect, as depicted below.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.5]{plots/cheby-approx.pdf}\n    \\caption{Chebyshev polynomial approximations}\n\\end{figure}\n\n\\subsection{Attempted approximation using exponential function}\n\nBy far the most accurate fit before the original polynomial approximation, an exponential function of the form $\\phi=a\\exp(b(\\delta-c))+d$ was used.\nSignificant Runge effect is still evident in the plot below.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.5]{plots/exponential-approx.pdf}\n    \\caption{Exponential approximations}\n\\end{figure}\n\n\\subsection{Attempted elliptical integral of first kind approximation}\n\nThrough parameterizing the first-order elliptic integral $K(k;n)$ for some $n\\in \\mathbb{R}$ and $k\\in[0,1]$ for both translation and dilation control, curve fitting was attempted:\n\n\\begin{equation}\n    K(k;n)=-\\frac{\\pi}{2n}+\\int_0^1 \\frac{dx}{n\\sqrt{(1-x^2)(1-k^2x^2)}}\n\\end{equation}\n\nThe optimization routine returned a value of $n=1$ for both $\\phi_0$ and $\\phi_\\mathrm{min}$, indicating that the first-order approximation is not effective. The plot is shown below.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.5]{plots/elliptical-approx.pdf}\n    \\caption{Elliptical approximations}\n\\end{figure}\n\nFurther parameterization attempts of $K(k)$ did not yield better results, as the curvature of the elliptic integral function cannot be manipulated easily to fit the data.\n\n\\subsection{Univariate spline approximation}\n\nThis method yielded the best results. A univariate spline of degree $k=3$ with smoothness factor $s=0.001$ was used to approximate $\\phi_0$ and $\\phi_\\mathrm{min}$.\nFigure \\ref{splineplot} shows that the method was successful, with minimized Runge effect and typical error magnitudes lower than that of the polynomial approximation.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.8]{plots/spline.pdf}\n    \\caption{Spline approximation plot}\\label{splineplot}\n\\end{figure}\n\nThe computer output below details the properties of each spline:\n\n{\\small\\begin{verbatim}\n    ---------- phi_0 spline approx ----------\nLSQ Error =         0.001000051241244917\nKnots =         [0.001 0.501 0.751 0.876 1.   ]\nCoeffs =        [-4.40529375e-04  3.92784349e-02  1.04654145e-01  2.56034241e-01\n  4.15005836e-01  5.76096213e-01  7.73738936e-01]\n\n---------- phi_min spline approx ----------\nLSQ Error =         0.0009999540547108812\nKnots =         [0.001 0.501 0.626 0.751 0.814 0.876 0.907 0.938 0.969 0.977 0.985 0.993\n 0.997 1.   ]\nCoeffs =        [-4.58365176e-05  1.99513345e-02  4.68542634e-02  1.06810792e-01\n  1.41001801e-01  1.78919227e-01  2.10975405e-01  2.46198594e-01\n  2.81539962e-01  3.21468750e-01  3.64172354e-01  3.99187610e-01\n  4.27132615e-01  5.02562701e-01  4.92718655e-01  7.78749733e-01]\n\\end{verbatim}}", "meta": {"hexsha": "e05caadfe95d3d93e6d5ec601dbdb0c4e93bed00", "size": 8077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/numerical-methods.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/numerical-methods.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/numerical-methods.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": 57.2836879433, "max_line_length": 396, "alphanum_fraction": 0.7148693822, "num_tokens": 2713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6850073820207488}}
{"text": "\\section{Genetic Algorithms}\n\n\\paragraph{Chromosome} A chromosome is a representation in which:\n\\begin{itemize}\n  \\item There is a list of lements called genes\n  \\item The chromosome determines the overall fitness manifested by\n    some mechanism that uses the chromosome's genes as a sort of\n    blueprint\n\\end{itemize}\nWith constructors that:\n\\begin{itemize}\n  \\item Create a chromosome, given a list of elements; this\n    constructor might be called the \\textit{genesis constructor}\n  \\item Create a chromosome by crossing a pair of existing\n    chromosomes\n\\end{itemize}\nWith writers that:\n\\begin{itemize}\n  \\item Mutate an existing chromosome by changing one of the genes\n\\end{itemize}\nWith readers that:\n\\begin{itemize}\n  \\item Produce a specified gene, given a chromosome\n\\end{itemize}\n\n\\subsection{Fitness}\n\nThe \\textbf{standard method} for fitness computation is:\n\\begin{math}\n  f_i = \\frac{q_i}{\\sum_{j}{q_j}}\n\\end{math}\n\nThe \\textbf{rank method} for fitness computation is:\n\\begin{itemize}\n  \\item Sort the $n$ individuals by quality\n  \\item Let the probability of selecting the $i$th candidate, given\n    that the first $i-1$ candidates have not been selected, be $p$,\n    except for the final candidate, which is selected if no\n    previous candidate has been selected\n  \\item Select a candidate using the computed probabilities\n\\end{itemize}\n\nThe \\textbf{rank-space method} for fitness computation is:\n\\begin{itemize}\n  \\item Sort the $n$ individuals by quality\n  \\item Sort the $n$ individuals by the sum of their inverse\n    squared distances to already selected candidates (the lower the\n    sum, the better the rank)\n  \\item Use the rank method, but sort on the sum of the quality\n    rank and the diversity rank, rather than on quality rank only\n\\end{itemize}\n\n\\subsection{Crossover}\n\n\\begin{itemize}\n  \\item Crossover enables to search high-dimensional spaces efficiently; \nit reduces the dimensionality of the optimum search space\n  \\item Crossover enables genetic algorithms to travers obstructing\n    moats\n\\end{itemize}\n\n\\subsection{Natural selection}\n\nTo mimic natural selection in general:\n\\begin{itemize}\n  \\item Create an initial population of one chromosome\n  \\item Mutate one or more genes in one or more of the current\n    chromosomes, producitng one new offspring for each chromosome\n    mutated\n  \\item Mate one or more pairs of chromosomes\n  \\item Add the mutated na doffspring chromosomes to the current\n    population\n  \\item Create a new generation by keeping the best of the current\n    population's chromosomes, along with other chromosomes selected\n    randomly from the current population. Bias the random selection\n    according to assessed fitness\n\\end{itemize}\n\n", "meta": {"hexsha": "5569fe527109edab2a5ab89bef4d64b55d5d484a", "size": 2706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "genetic_algorithms.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": "genetic_algorithms.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": "genetic_algorithms.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": 34.253164557, "max_line_length": 73, "alphanum_fraction": 0.766075388, "num_tokens": 652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.6850073739425887}}
{"text": "%\n% Chapter 2.4\n%\n\n\\section*{2.4 Derivatives of Trigonometric Functions}\n\n\\[ \\lim_{\\theta \\to 0} \\frac{\\sin(\\theta)}{\\theta}=1 \\]\n\\[ \\lim_{\\theta \\to 0} \\frac{\\cos(\\theta)-1}{\\theta}=0 \\]\n\\[ \\frac{d}{dx}(\\sin(x))=\\cos(x) \\]\n\\[ \\frac{d}{dx}(\\cos(x))=-\\sin(x) \\]\n\\[ \\frac{d}{dx}(\\tan(x))=\\sec^2(x) \\]\n\\[ \\frac{d}{dx}(\\csc(x))=-\\csc(x)\\cot(x) \\]\n\\[ \\frac{d}{dx}(\\sec(x))=\\sec(x)\\tan(x) \\]\n\\[ \\frac{d}{dx}(\\cot(x))=-\\sec^2(x) \\]\n", "meta": {"hexsha": "62a762ce6ff2f22049143f2f395152fae8d69891", "size": 425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-4.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-4.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-4.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3333333333, "max_line_length": 57, "alphanum_fraction": 0.5035294118, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6848718344905234}}
{"text": "% Fill out with more info\n\n\\chapter{Density Estimation}\nProbability density functions are the baseline for many mathematical models, with the Gaussian distribution being the most frequently used distribution. Probability densities have a wide range of uses and can be used for classification, clustering of data, dimensional reduction, and field-specific applications such as noise-filtering or pricing financial derivatives. The central problem is that probability density functions in most cases are unknown. This is where density estimation comes in: if we are given a set of independent observed variables $x_i$, $i=1,\\dots,n$, then we wish to estimate the unknown underlying probability distribution.\n\n\\section{Normalizing Flows}\nNormalizing Flows are a family of generative models with tractable probability distributions, where both sampling and evaluation of probabilities can be exact, unlike Generative Adversarial Networks (GANs) or Variational Auto-Encoders (VAEs). \nNormalizing Flows were initially introduced by \\citeauthor*{tabak-2010-normalizing-flows-dual-ascent-log-likelihood} \\parencite*{tabak-2010-normalizing-flows-dual-ascent-log-likelihood, tabak-2013-normalizing-flows-nonparametric-density-estimation-algorithms}, but first gained traction within variational inference when \\ccite{rezende-2015-normalizing-flows} demonstrate the ability to create extremely rich posterior approximations that is able to contain the true posterior distribution in the asymptotic regime, and within density estimation when \\ccite{dinh-2014-nice} achieves results competitive with the then state-of-the-art while having tractable evaluation and sampling.\n\nA normalizing flow is a transformation of a simple baseline probability distribution into a more complex distribution by letting it \"flow\" through a sequence of differentiable and invertible mappings. The density of an observed sample can then be evaluated by transforming it back to the latent simple baseline distribution and computing the product of the inverse-transformed sample under the latent distribution and the changes in volume that originate from the sequence of inverse transformations. This method also allows us to sample from the latent simple distribution and then applying the transformations to obtain a sample from the complex distribution.\n\n\\subsection*{Change of Variables}\nNormalizing Flows utilizes the Change of Variables Theorem, which describes how volumes get distorted by differentiable and invertible functions.\n\nIf we have a differentiable map $\\Phi : U \\to \\mathbb{R}^n$ where $U\\subset\\mathbb{R}^n$, then the Jacobian matrix is given by\n\\begin{equation}\n    \\nabla\\Phi(\\bm{x}) = \\begin{bmatrix}\n        \\frac{\\partial\\Phi_1}{\\partial x_1} & \\cdots & \\frac{\\partial\\Phi_1}{\\partial x_n} \\\\\n        \\vdots & \\ddots & \\vdots \\\\\n        \\frac{\\partial\\Phi_n}{\\partial x_1} & \\cdots & \\frac{\\partial\\Phi_n}{\\partial x_n}\n    \\end{bmatrix}\n\\end{equation}\nThe determinant of the Jacobian matrix is called the Jacobian and will be denoted as $J_{\\Phi}(\\bm{x})=\\det\\left|\\nabla\\Phi(\\bm{x})\\right|$. \nIf we constrain $J_{\\Phi}(\\bm{x})\\neq0$ for all $\\bm{x}\\in U$ then it is given, through the Inverse Function Theorem, that $\\Phi(\\bm{x})$ is invertible, that $\\Phi^{-1}$ is continuously differentiable, and $\\nabla\\Phi^{-1}(\\Phi(\\bm{x}))=(\\nabla\\Phi(\\bm{x}))^{-1}$, which means we have a $C^1$-diffeomorphism between $U$ and its image $\\Phi(U)$.\n\nIf we have a $C^1$-diffeomorphism $\\Phi:U\\to V$, where $V \\subset \\mathbb{R}^n$, then for any continuous function $f$ in $V$, we get the Change of Variables Theorem\n\\begin{equation}\n    \\int_V f(\\bm{x}) d\\bm{x} = \\int_U f(\\Phi(\\bm{y})) |J_\\Phi(\\bm{y})| d\\bm{y}\n\\end{equation}\n\n\\subsection*{Change of Random Variable}\nNow let $\\bm Z$ and $\\bm X$ be random variables that are related by a mapping $\\Phi:\\mathbb{R}^n\\to \\mathbb{R}^n$ such that $\\bm X = \\Phi(\\bm Z)$ and $\\bm Z = \\Phi^{-1}(\\bm X)$. If we then compute the expectation of $f(\\bm X)$ where $f$ is some continuous function, then\n\\begin{align}\n    \\mathbb{E}_{p_Z(\\cdot)}[f(\\bm Z)] &= \\int_{\\text{supp}(\\bm Z)} f(\\bm z) p_Z(\\bm z) d\\bm z\\\\\n    &= \\int_{\\text{supp}(\\bm X)} f(\\Phi^{-1}(\\bm x)) p_Z(\\Phi^{-1}(\\bm x)) |J_{\\Phi^{-1}}(\\bm x)| d\\bm x \\\\\n    &= \\int_{\\text{supp}(\\bm X)} f(\\Phi^{-1}(\\bm x)) p_X(\\bm x) d\\bm x \\\\\n    &= \\mathbb{E}_{p_X(\\cdot)}[f(\\Phi^{-1}(\\bm x))]\n\\end{align}\n\nAs we have the equality\n\\begin{align}\n    \\int_{\\text{supp}(\\bm X)} f(\\Phi^{-1}(\\bm x)) p_Z(\\Phi^{-1}(\\bm x)) |J_{\\Phi^{-1}}(\\bm x)| d\\bm x\n    &= \\int_{\\text{supp}(\\bm X)} f(\\Phi^{-1}(\\bm x)) p_X(\\bm x) d\\bm x\n\\end{align}\nit follows that\n\\begin{align}\n    p_X(\\bm x) &= p_Z(\\Phi^{-1}(\\bm x)) |J_{\\Phi^{-1}}(\\bm x)| \\\\\n    &= p_Z(\\bm z) |J_{\\Phi}(\\bm z)^{-1}|\n    \\label{eq:pX-mapping}\n\\end{align}\nwhich means that we can describe the random variable $\\bm X$ through the use of a $C^1$-diffeomorphism and a latent variable $\\bm Z$.\n\n\\subsection*{Constructing arbitrarily complex density}\nAn arbitrarily complex density can be constructed by composing several simple maps and applying \\cref{eq:pX-mapping} successively. If a random variable $\\bm{z}_0$ comes from a distribution $q_0$, then we can obtain $q_K(\\bm z)$ through a chain of $K$ transformations $\\Phi_k$:\n\\begin{align}\n    \\bm{z}_K &= \\Phi_K\\circ\\cdots\\circ \\Phi_1(\\bm{z}_0)\\\\\n    \\ln q_K(\\bm{z}_K) &= \\ln q_0(\\bm{z}_0) - \\sum_{k=1}^{K} \\ln \\left|J_{\\Phi_{k}}(\\bm{z}_{k-1})\\right|\n    \\label{eq:lnqK}\n\\end{align}\nwhere \\cref{eq:lnqK} is obtained by repeatedly applying the log of \\cref{eq:pX-mapping}. The path traversed by $\\bm{z}_k=\\Phi_k(\\bm{z}_{k-1})$ is called the flow and the path formed by the successive distributions $q_k$ is a Normalizing Flow (\\ccite{rezende-2015-normalizing-flows}). The big problem with this form is finding mappings such that the calculation of the Jacobian isn't $\\mathcal{O}(D^3)$, where $D$ is the dimensionality. \n\n\\section{Continuous Normalizing Flows}\n\\ccite{chen-2018-cnf} builds upon the concepts from \\ccite{rezende-2015-normalizing-flows} by introducing Instantaneous Change of Variables. If $\\bm{z}(t)$ is a finite continuous random variable with probability $p(\\bm{z}(t))$ dependent on time, $\\frac{d\\bm z}{dt}=f(\\bm{z}(t), t)$ is a differential equation describing a continuous-in-time transformation of $\\bm{z}(t)$, and $f$ is uniformly Lipschitz continuous in $\\bm z$ and continuous in $t$, then the change in log probability is given as\n\\begin{equation}\n    \\frac{\\partial \\ln p(\\bm{z}(t))}{\\partial t} = - \\text{tr}\\left(\\frac{df}{d\\bm{z}(t)}\\right)\n\\end{equation}\nThis means that the change in log probability can be calculated using a trace operation instead of calculating the Jacobian, which requires calculating a determinant. The total change in log probability can then be found by integrating over time\n\\begin{equation}\n    \\ln p(\\bm{z}(t_1)) = \\ln p(\\bm z(t_0)) - \\int_{t_0}^{t_1} \\text{tr}\\left(\\frac{df}{d\\bm{z}(t)}\\right) dt\n    \\label{eq:cnf}\n\\end{equation}\nThis method reduces the primary bottleneck to $\\mathcal{O}(D^2)$, but comes at the cost of introducing a numerical ODE solver.\n\n\\section{Free-form Jacobian of Reversible Dynamics}\nFree-form Jacobian of Reversible Dynamics (FFJORD) was introduced by \\ccite{grathwohl-2018-ffjord} and builds upon Continuous Normalizing Flows. FFJORD utilizes vector-Jacobian products with reverse-mode automatic differentiation, which allows calculating $\\bm v^T \\frac{\\partial f}{\\partial \\bm z}$ at roughly the same cost as evaluating $f$, and Hutchinson's trace estimator (\\ccite{hutchinson-1989-stochastic-trace}), which says that for any $D\\times D$-matrix $\\bm A$ the trace can be estimated as\n\\begin{equation}\n    \\text{tr}(\\bm A) = \\mathbb{E}_{p(\\bm\\epsilon)}[\\bm\\epsilon^T\\bm A\\bm\\epsilon]\n\\end{equation}\nwhere $p(\\bm\\epsilon)$ is a distribution over $D$-dimensional vectors with $\\mathbb{E}[\\bm\\epsilon]=0$ and $\\text{Cov}(\\bm\\epsilon)=\\bm I$.\n\nThis means that \\cref{eq:cnf} ends up becoming\n\\begin{align}\n    \\ln p(\\bm{z}(t_1)) &= \\ln p(\\bm z(t_0)) - \\int_{t_0}^{t_1} \\text{tr}\\left(\\frac{df}{d\\bm{z}(t)}\\right) dt\\\\\n                       &= \\ln p(\\bm z(t_0)) - \\int_{t_0}^{t_1} \\mathbb{E}_{p(\\bm\\epsilon)}\\left[\\bm\\epsilon^T\\frac{\\partial f}{\\partial \\bm z(t)}\\bm\\epsilon\\right] dt\\\\\n                       &= \\ln p(\\bm z(t_0)) - \\mathbb{E}_{p(\\bm\\epsilon)}\\left[\\int_{t_0}^{t_1}\\bm\\epsilon^T\\frac{\\partial f}{\\partial \\bm z(t)}\\bm\\epsilon dt\\right]\n\\end{align}\nwhere the bottleneck of calculating the trace estimate is $\\mathcal{O}(D)$ and allows for an unconstrained Jacobian due to utilizing vector-Jacobian products.", "meta": {"hexsha": "ef8296a1e2c86c0148b4132826340dc6b4c0d89e", "size": 8573, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Chapters/02_Density_Estimation.tex", "max_stars_repo_name": "msboeg/msc-thesis", "max_stars_repo_head_hexsha": "ceb479a79449ba90b9b5d0342481738695701bf3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reports/Chapters/02_Density_Estimation.tex", "max_issues_repo_name": "msboeg/msc-thesis", "max_issues_repo_head_hexsha": "ceb479a79449ba90b9b5d0342481738695701bf3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/Chapters/02_Density_Estimation.tex", "max_forks_repo_name": "msboeg/msc-thesis", "max_forks_repo_head_hexsha": "ceb479a79449ba90b9b5d0342481738695701bf3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.5402298851, "max_line_length": 681, "alphanum_fraction": 0.7178350636, "num_tokens": 2592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.6848167011145353}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{makeidx}\n\\usepackage{graphicx}\n\\usepackage{subcaption}\n\\usepackage{caption}\n\\usepackage{float}\n\\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}\n\\usepackage{tikz}\n\\usepackage{pdfpages}\n\\pagestyle{plain}\n\\usepackage{bm}\n\\usepackage{ulem}\n\\usepackage{units}\n\\usepackage{makecell}\n\n%Kopf und Fußzeile:\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\renewcommand{\\footrulewidth}{0.4pt}\n\\usepackage{array}   % for \\newcolumntype macro\n\\newcolumntype{C}{>{$}c<{$}} % math-mode version of \"c\" column type\n\n\\fancyhead[L]{Computational photonics}\n%\\fancyhead[C]{Dr. Bj\\\"orn Leder}\n\\fancyhead[R]{Excercise 1}\n\\fancyfoot[L]{\\today}\n\\fancyfoot[R]{page \\thepage}\n\\fancyfoot[C]{Julien Kluge}\n\n% Code-Listings\n\\usepackage{listings}\n\\lstset{\nlanguage=c,\nshowstringspaces=false,\nnumbers=left,\nxleftmargin=2em}\n\n% Ganze Dateien als Verbatim einbinden\n%\\usepackage{verbatimfiles} % downloaded from ctan.org\n\n\\title{Computational photonics}\n\\author{Julien Kluge}\n\\date{\\today}\n\n%============================================================\n% Dokument\n%============================================================\n\\begin{document}\n\n\\lstset{numbers=left}\n\n\\begin{center}\n\\large{\\textbf{Computational photonics -- Excercise 1}} \\\\\n~\\\\\n\\small{-- Julien Kluge (564513) --}\\\\\n~\\\\\nDate: \\today\n\\end{center}\n\\hrule\n\n\n\\section*{Task 1}\n\t\\begin{table}[H]\n\t\t\\caption{Program file index - Task 1}\n\t\t\\begin{tabular}{r|c|l}\n\t\t\t\\textit{A1/A1.m} & Matlab & program with whole task in sections\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\subsection*{a)}\n\t\t\\begin{lstlisting}\ngauss1D = @(x) exp(-(x * x));\nx = -xMax:dx:xMax;\ny = arrayfun(gauss1D, x);\nplot(x, y)\n\t\t\\end{lstlisting}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.7\\textwidth]{A1/A1_a.png}\n\t\t\t\\caption{Plot of the function \\(f(x)=\\exp\\left(-x^2\\right)\\) in matlab.}\n\t\t\\end{figure}\n\t\\subsection*{b)}\n\t\t\\begin{lstlisting}\ngauss2D = @(x, y) exp(-(x * x + y * y));\ng = -gMax:dg:gMax;\n[x, y] = meshgrid(g, g);\nz = arrayfun(gauss2D, x, y);\nmesh(x, y, z)\nsurface(x, y, z)\npcolor(x, y, z)\ncontour(x, y, z)\n\t\t\\end{lstlisting}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.9\\textwidth]{A1/A1_b.png}\n\t\t\t\\caption[]{Plot of the function\n\t\t\t\\(f(x)=\\exp\\left(-\\left(x^2+y^2\\right)\\right)\\) in matlab for different commands.}\n\t\t\\end{figure}\n\t\\subsection*{c)}\n\t\tQuiver code omitted for clarity in this document.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=\\textwidth]{A1/A1_c.png}\n\t\t\t\\caption[]{Vectorfields \\(\\mathbf{E_1}=(-y, x)\\) and \\(\\mathbf{E_2}=-(y, x)\\) plotted with quiver.}\n\t\t\\end{figure}\n\t\\subsection*{d)}\n\t\t\\begin{lstlisting}\n\th = @(x) exp(1 - 1 ./ x) ./ x;\n\tint1 = integral(h, eps, 1);\n\t\t\\end{lstlisting}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.7\\textwidth]{A1/A1_d.png}\n\t\t\t\\caption[]{Function \\(h(x)\\) plotted in matlab.}\n\t\t\\end{figure}\n\t\tEven though matlab properly integrates this function and acquires\n\t\tthe right value of about\n\t\t\\begin{align}\n\t\t\t\\int_0^1\\text{d}x\\,h(x)=e\\cdot\\Gamma\\left(0,1\\right)\\approx 0.5963\n\t\t\\end{align}\n\t\tit could still pose a problem for similar functions since the function\n\t\tinhibits a pole on \\(x=0\\). It can easily through variable substitution be shown,\n\t\tthat\n\t\t\\begin{align}\n\t\t\t\\lim_{x\\rightarrow 0}h(x)=0\n\t\t\\end{align}\n\t\tbut programs cannot do the symbolic limit implicitly and therefore acquire an error\n\t\tdue to the division by zero. This can be cirumvented with two possibilities:\n\t\t\\begin{enumerate}\n\t\t\t\\item Since we know \\(h(x\\rightarrow0)\\rightarrow0\\) we can explicitly spare the\n\t\t\tintegral-function of the pole by adjusting integration limit to \\(\\left[\\epsilon,1\\right]\\)\n\t\t\twhere \\(\\epsilon\\) is the machine-epsilon of the according floating point type (\\textit{eps} in matlab).\n\t\t\t\\item We can do a variable substition \\(x=1/y\\) under the integral\n\t\t\t\\begin{align}\n\t\t\t\t\\int_0^1\\text{d}x\\,\\frac{\\exp\\left(1-\\frac{1}{x}\\right)}{x}=\\int_1^\\infty\\text{d}y\\,\\frac{\\exp\\left(1-y\\right)}{y}\n\t\t\t\\end{align}\n\t\t\tThis seems to pose the exchanged problem of integrating to infinity. However, after quick\n\t\t\tcalculations in can be shown that \\(h(y)<\\epsilon\\) for \\(y\\geq 34.31\\) with a\n\t\t\tstrong monotonic descrease (\\(h(y)\\propto1/\\left(y\\cdot\\exp y\\right)\\)). So we can comfortably\n\t\t\tset the integration limits to \\([1,34.31]\\) (or adapting to a specific precision-limit).\n\t\t\\end{enumerate}\n\t\t\\newpage\n\n\\section*{Task 2}\n\t\\begin{table}[H]\n\t\t\\caption{Program file index - Task 2}\n\t\t\\begin{tabular}{r|c|p{10cm}}\n\t\t\t\\textit{A2/A2.jl} & Julia & program with tasks a, b and part of c \\\\\n\t\t\t\\textit{A2/naiveDFT.jl} & Julia & implementation of the naive dft in matrix and\\newline iterative form \\\\\n\t\t\t\\textit{A2/simpleDFT.jl} & Julia & implementation of the recursive dft \\\\\n\t\t\t\\textit{A2/benchmarkFunction.jl} & Julia & benchmark function for fft-functions \\\\\n\t\t\t\n\t\t\t\\textit{A2/A2c\\_MatlabFFT.m} & Matlab & programm to acquire matlab fft benchmarks \\\\\n\t\t\t\\textit{A2/A2d.nb} & Mathematica & notebook to calculate aliasing graphs \\\\\n\t\t\t\\textit{A2/data/Visualize.nb} & Mathematica & notebook to calculate graphs for c\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\subsection*{a) and b)}\n\t\tAccording to the program file index the ffts where implemented in naive and recursive\n\t\tform and compared to the FFTW package. The comparison was made with an artificial created\n\t\tdataset of three sine waves with different amplitude, frequency and phase.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=\\textwidth]{A2/data/fftPlot.png}\n\t\t\t\\caption[]{Comparison of real, imaginary and absolute values of FFTW, the naive and recursive implementation}\n\t\t\\end{figure}\n\t\tThe summed differences where all calculated to be below \\(10^{-10}\\).\n\t\n\t\\subsection*{c)}\n\t\tThe Julia functions and a Matlab benchmark where made with different problem sizes\n\t\tall with a power of two. The stopping criterion was set, when an implementation\n\t\treached calculation times over a second. Each test was repeated five times and\n\t\twas averaged out.\\\\\n\t\tFollowing results where acquired:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.7\\textwidth]{A2/data/Comparison.pdf}\n\t\t\t\\caption[]{Comparisons between different dft implementations. The simple, recursive\n\t\t\tJulia implementation is notably only 5 times slower than FFTW.}\n\t\t\\end{figure}\n\t\tThe fastest implementation seems to be matlabs fft. However, it is known\n\t\tthat matlab utilizes FFTW-plan implementations. The exact same speed could\n\t\tbe therefore in Julia be acquired with a single FFTW-plan allocation.\\\\\n\t\tThe naive implementations are fitted with a runtime slightly above\n\t\t\\(\\mathcal{O}\\left(N^2\\right)\\). All other implemntations are approximately\n\t\t\\(\\approx\\mathcal{O}\\left(N^{1.1}\\right)\\) for the simple, recursive implementation\n\t\tand \\(\\mathcal{O}\\left(N\\log N\\right)\\) in the given uncertainty intervals.\n\n\t\\subsection*{d)}\n\t\t\\begin{align}\n\t\t\t\\hat{\\mathcal{F}}_t^\\omega\\left\\{\\exp\\left(-t^2\\right)\\right\\}=\\sqrt{\\pi}\\exp\\left(\\frac{-\\omega^2}{4}\\right)\n\t\t\\end{align}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\t\t\\includegraphics[width=0.9\\columnwidth]{A2/data/DT_Comparison.pdf}\n\t\t\t\t\\caption[]{Comparison between different sampling distances \\(\\Delta t\\)}\n\t\t\t\\end{subfigure}\n\t\t\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\t\t\\includegraphics[width=0.9\\columnwidth]{A2/data/TSampling_Comparison.pdf}\n\t\t\t\t\\caption[]{Comparison between different sampling intervals \\(t_{smpl}\\in\\left[-t, t\\right]\\)}\n\t\t\t\\end{subfigure}\n\t\t\t\\caption[]{Comparison of aliasing in different sample intervals and sampling distances.}\n\t\t\\end{figure}\n\t\t\\noindent It can quickly be seen how the different intervals and distances distort the resulting\n\t\tfourier points. The sampling interval seems to have a stronger effect.\\\\\n\t\tTo confirm that, a density plot of the absolute differences to the analytical solution\n\t\tcan be made.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.7\\textwidth]{A2/data/DT_TSampling_Contour.png}\n\t\t\t\\caption[]{Absolute differences of fft to analytical solution, scaled\n\t\t\tby the squareroot (for better visibility) in respect to the sampling\n\t\t\tinterval and distances.}\n\t\t\\end{figure}\n\t\t\\noindent The multiplication by \\(N\\,\\Delta t\\, (-1)^n\\) is necessary to\n\t\tnormalize the fourier coefficients and the last term is for shifting the resulting\n\t\tcoefficients to the zero-frequency.\n\t\t\\newpage\n\t\n\\section*{Task 3}\n\t\\begin{align}\n\t\t\\frac{\\partial \\mathbf{H}(\\mathbf{r,t})}{\\partial t}&=-\\frac{1}{\\mu_0\\,\\mu(\\mathbf{r})}\\nabla\\times\\mathbf{E}(\\mathbf{r},t)\\\\\n\t\t\\frac{\\partial \\mathbf{E}(\\mathbf{r,t})}{\\partial t}&=\\frac{1}{\\epsilon_0\\,\\epsilon(\\mathbf{r})}\\nabla\\times\\mathbf{H}(\\mathbf{r},t)\n\t\\end{align}\n\tFirst we introduce to arbitrary field strengths \\(E_0, H_0\\) such that\n\t\\begin{align}\n\t\t\\frac{\\mathbf{E}}{E_0}&=\\widetilde{\\mathbf{E}} \\\\\n\t\t\\frac{\\mathbf{H}}{H_0}&=\\widetilde{\\mathbf{H}}\n\t\\end{align}\n\tWhich then renders the upper equations to\n\t\\begin{align}\n\t\t\\frac{\\partial \\widetilde{\\mathbf{H}}(\\mathbf{r,t})}{\\partial t}&=-\\frac{E_0}{H_0\\,\\mu_0}\\frac{1}{\\mu(\\mathbf{r})}\\nabla\\times\\widetilde{\\mathbf{E}}(\\mathbf{r},t)\\\\\n\t\t\\frac{\\partial \\widetilde{\\mathbf{E}}(\\mathbf{r,t})}{\\partial t}&=\\frac{H_0}{E_0\\,\\epsilon_0}\\frac{1}{\\epsilon(\\mathbf{r})}\\nabla\\times\\widetilde{\\mathbf{H}}(\\mathbf{r},t)\n\t\\end{align}\n\tWe can equate the terms with \\(E_0,H_0,\\epsilon_0,\\mu_0\\) to a constant.\n\tSince the field strength modifier are arbitrary, the constants are also arbitrary.\n\tTherefore we set it equal to one:\n\t\\begin{align}\n\t\t1&=\\frac{E_0}{H_0\\,\\mu_0} \\\\\n\t\t1&=\\frac{H_0}{E_0\\,\\epsilon_0}\n\t\\end{align}\n\tThis system is underdetermined. We can therefore only solve for one solution.\n\tMultiplication and division yields following equations respectively\n\t\\begin{align}\n\t\t1&=\\frac{1}{\\epsilon_0\\,\\mu_0}=c^2 \\\\\n\t\t1&=\\frac{E_0^2\\,\\epsilon_0}{H_0^2\\,\\mu_0}\n\t\\end{align}\n\tThe first gives the natural units where \\(c=1\\). This enables further manipulation\n\tfor time or space such that \\(\\mathbf{r}/r_0=\\widetilde{\\mathbf{r}}\\) and\n\t\\(t\\cdot c/r_0=\\widetilde{t}\\). The second equation gives a solution for either variable.\n\tFor the arbitrary decision to solve \\(H_0\\) we get\n\t\\begin{align}\n\t\tH_0=E_0\\sqrt{\\frac{\\epsilon_0}{\\mu_0}}\n\t\\end{align}\n\tThus the final result in natural units (\\(c=1\\)) can be archived:\n\t\\begin{align}\n\t\t\\frac{\\partial \\widetilde{\\mathbf{H}}(r_0\\,\\widetilde{\\mathbf{r}},r_0\\,\\widetilde{t})}{\\partial \\widetilde{t}}&=-\\frac{1}{\\mu(r_0\\,\\widetilde{\\mathbf{r}})}\\nabla_{\\widetilde{r}}\\times\\widetilde{\\mathbf{E}}(r_0\\,\\widetilde{\\mathbf{r}},r_0\\,\\widetilde{t})\\\\\n\t\t\\frac{\\partial \\widetilde{\\mathbf{E}}(r_0\\,\\widetilde{\\mathbf{r}},r_0\\,\\widetilde{t})}{\\partial \\widetilde{t}}&=\\frac{1}{\\epsilon(r_0\\,\\widetilde{\\mathbf{r}})}\\nabla_{\\widetilde{r}}\\times\\widetilde{\\mathbf{H}}(r_0\\,\\widetilde{\\mathbf{r}},r_0\\,\\widetilde{t})\n\t\\end{align}\n\tWhich also gives us the spatial discretization as \\(r_0\\).\n\\end{document}\n", "meta": {"hexsha": "dfb867010939da48552837b0d8d062a04f5ecbaa", "size": 11009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Excercise_01/Exc1_Submission_JulienK.tex", "max_stars_repo_name": "JulienKluge/ComputationalPhotonics", "max_stars_repo_head_hexsha": "78bfdccc49dca5b19e524814c0ca3fcff7be6765", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Excercise_01/Exc1_Submission_JulienK.tex", "max_issues_repo_name": "JulienKluge/ComputationalPhotonics", "max_issues_repo_head_hexsha": "78bfdccc49dca5b19e524814c0ca3fcff7be6765", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Excercise_01/Exc1_Submission_JulienK.tex", "max_forks_repo_name": "JulienKluge/ComputationalPhotonics", "max_forks_repo_head_hexsha": "78bfdccc49dca5b19e524814c0ca3fcff7be6765", "max_forks_repo_licenses": ["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.9256505576, "max_line_length": 259, "alphanum_fraction": 0.701789445, "num_tokens": 3734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.6848166998666285}}
{"text": "\\chapter{Generalized linear models and the exponential family}\n\\label{chap:GLM}\n\n\n\\section{The exponential family}\n\\label{sec:exponential-family}\n\nBefore defining the exponential family, we mention several reasons why it is important:\n\\begin{itemize}\n\\item{It can be shown that, under certain regularity conditions, the exponential family is the only family of distributions with finite-sized sufficient statistics, meaning that we can compress the data into a fixed-sized summary without loss of information. This is particularly useful for online learning, as we will see later.}\n\\item{The exponential family is the only family of distributions for which conjugate priors exist, which simplifies the computation of the posterior (see Section \\ref{sec:Bayes-for-the-exponential-family}).}\n\\item{The exponential family can be shown to be the family of distributions that makes the least set of assumptions subject to some user-chosen constraints (see Section \\ref{sec:Maximum-entropy-derivation-of-the-exponential-family}).}\n\\item{The exponential family is at the core of generalized linear models, as discussed in Section \\ref{sec:GLMs}.}\n\\item{The exponential family is at the core of variational inference, as discussed in Section TODO.}\n\\end{itemize}\n\n\n\\subsection{Definition}\nA pdf or pmf $p(\\vec{x}|\\vec{\\theta})$,for $\\vec{x} \\in \\mathbb{R}^m$ and $\\vec{\\theta} \\in \\mathbb{R}^D$, is said to be in the \\textbf{exponential family} if it is of the form\n\\begin{align}\np(\\vec{x}|\\vec{\\theta}) & =\\dfrac{1}{Z(\\vec{\\theta})}h(\\vec{x})\\exp[\\vec{\\theta}^T\\phi(\\vec{x})] \\\\\n    & = h(\\vec{x})\\exp[\\vec{\\theta}^T\\phi(\\vec{x})-A(\\vec{\\theta})] \\label{eqn:exponential-family}\n\\end{align}\nwhere\n\\begin{align}\nZ(\\vec{\\theta}) & =\\int h(\\vec{x})\\exp[\\vec{\\theta}^T\\phi(\\vec{x})]\\mathrm{d}\\vec{x} \\\\\nA(\\vec{\\theta}) & =\\log Z(\\vec{\\theta})\n\\end{align}\n\nHere $\\vec{\\theta}$ are called the \\textbf{natural parameters} or \\textbf{canonical parameters}, $\\phi(\\vec{x}) \\in \\mathbb{R}^D$ is called a vector of \\textbf{sufficient statistics}, $Z(\\vec{\\theta})$ is called the \\textbf{partition function}, $A(\\vec{\\theta})$ is called the \\textbf{log partition function} or \\textbf{cumulant function}, and $h(\\vec{x})$ is the a scaling constant, often 1. If $\\phi(\\vec{x})=\\vec{x}$, we say it is a \\textbf{natural exponential family}.\n\nEquation \\ref{eqn:exponential-family} can be generalized by writing\n\\begin{equation}\np(\\vec{x}|\\vec{\\theta}) = h(\\vec{x})\\exp[\\eta(\\vec{\\theta})^T\\phi(\\vec{x})-A(\\eta(\\vec{\\theta}))]\n\\end{equation}\nwhere $\\eta$ is a function that maps the parameters $\\vec{\\theta}$ to the canonical parameters $\\vec{\\eta}=\\eta(\\vec{\\theta})$.If $\\mathrm{dim}(\\vec{\\theta})<\\mathrm{dim}(\\eta(\\vec{\\theta}))$, it is called a \\textbf{curved exponential family}, which means we have more sufficient statistics than parameters. If $\\eta(\\vec{\\theta})=\\vec{\\theta}$, the model is said to be in \\textbf{canonical form}. We will assume models are in canonical form unless we state otherwise.\n\n\n\\subsection{Examples}\n\n\n\\subsubsection{Bernoulli}\nThe Bernoulli for $x \\in \\{0,1\\}$ can be written in exponential family form as follows:\n\\begin{equation}\\begin{split}\n\\mathrm{Ber}(x|\\mu)& =\\mu^x(1-\\mu)^{1-x} \\\\\n   & =\\exp[x\\log\\mu+(1-x)\\log(1-\\mu)]\n\\end{split}\\end{equation}\nwhere $\\phi(x)=(\\mathbb{I}(x=0),\\mathbb{I}(x=1))$ and $\\vec{\\theta}=(\\log\\mu,\\log(1-\\mu))$. \n\nHowever, this representation is \\textbf{over-complete} since $\\vec{1}^T\\phi(x)=\\mathbb{I}(x=0)+\\mathbb{I}(x=1)=1$. Consequently $\\vec{\\theta}$ is not uniquely identifiable. It is common to require that the representation be \\textbf{minimal}, which means there is a unique $\\theta$ associated with the distribution. In this case, we can just define\n\\begin{align}\n\\mathrm{Ber}(x|\\mu) & =(1-\\mu)\\exp\\left(x\\log\\dfrac{\\mu}{1-\\mu}\\right) \\\\\n\\text{where } \\phi(x) & =x, \\theta=\\log\\dfrac{\\mu}{1-\\mu}, Z=\\dfrac{1}{1-\\mu}  \\nonumber\n\\end{align}\n\nWe can recover the mean parameter $\\mu$ from the canonical parameter using\n\\begin{equation}\n\\mu=\\mathrm{sigm}(\\theta)=\\dfrac{1}{1+e^{-\\theta}}\n\\end{equation}\n\n\n\\subsubsection{Multinoulli}\nWe can represent the multinoulli as a minimal exponential family as follows:\n\\begin{equation*}\\begin{split}\n& \\mathrm{Cat}(\\vec{x}|\\vec{\\mu}) = \\prod\\limits_{k=1}^K = \\exp\\left(\\sum\\limits_{k=1}^K x_k\\log\\mu_k\\right) \\\\\n    & = \\exp\\left[\\sum\\limits_{k=1}^{K-1} x_k\\log\\mu_k+  (1-\\sum\\limits_{k=1}^{K-1} x_k)\\log(1-\\sum\\limits_{k=1}^{K-1} \\mu_k)\\right] \\\\\n\t& = \\exp\\left[\\sum\\limits_{k=1}^{K-1} x_k\\log\\dfrac{\\mu_k}{1-\\sum_{k=1}^{K-1} \\mu_k} + \\log(1-\\sum\\limits_{k=1}^{K-1} \\mu_k) \\right] \\\\\n\t& = \\exp\\left[\\sum\\limits_{k=1}^{K-1} x_k\\log\\dfrac{\\mu_k}{\\mu_K}+\\log\\mu_K\\right] \\text{, where } \\mu_K \\triangleq 1-\\sum\\limits_{k=1}^{K-1} \\mu_k\n\\end{split}\\end{equation*}\n\nWe can write this in exponential family form as follows:\n\\begin{align}\n\\mathrm{Cat}(\\vec{x}|\\vec{\\mu}) & = \\exp[\\vec{\\theta}^T\\phi(\\vec{x})-A(\\vec{\\theta})] \\\\\n\\vec{\\theta} & \\triangleq (\\log\\dfrac{\\mu_1}{\\mu_K},\\cdots,\\log\\dfrac{\\mu_{K-1}}{\\mu_K}) \\\\\n\\phi(\\vec{x}) & \\triangleq (x_1,\\cdots,x_{K-1})\n\\end{align}\n\nWe can recover the mean parameters from the canonical parameters using\n\\begin{align}\n\\mu_k & = \\dfrac{e^{\\theta_k}}{1+\\sum_{j=1}^{K-1} e^{\\theta_j}} \\\\\n\\mu_K & = 1- \\dfrac{\\sum_{j=1}^{K-1} e^{\\theta_j}}{1+\\sum_{j=1}^{K-1} e^{\\theta_j}}=\\dfrac{1}{1+\\sum_{j=1}^{K-1} e^{\\theta_j}}\n\\end{align}\nand hence\n\\begin{equation}\nA(\\vec{\\theta]} = -\\log\\mu_K=\\log(1+\\sum\\limits_{j=1}^{K-1} e^{\\theta_j})\n\\end{equation}\n\n\n\\subsubsection{Univariate Gaussian}\nThe univariate Gaussian can be written in exponential family form as follows:\n\\begin{align}\n\\mathcal{N}(x|\\mu,\\sigma^2) & =\\dfrac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left[-\\dfrac{1}{2\\sigma^2}(x-\\mu)^2\\right] \\nonumber \\\\\n    & = \\dfrac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left[-\\dfrac{1}{2\\sigma^2}x^2+\\dfrac{\\mu}{\\sigma^2}x-\\dfrac{1}{2\\sigma^2}\\mu^2\\right] \\nonumber \\\\\n\t& = \\dfrac{1}{Z(\\vec{\\theta})}\\exp[\\vec{\\theta}^T\\phi(x)]\n\\end{align}\nwhere\n\\begin{align}\n\\vec{\\theta} & = (\\dfrac{\\mu}{\\sigma^2}, -\\dfrac{1}{2\\sigma^2}) \\\\\n\\phi(x) & =(x,x^2) \\\\\nZ(\\vec{\\theta}) & =\\sqrt{2\\pi}\\sigma\\exp(\\dfrac{\\mu^2}{2\\sigma^2})\n\\end{align}\n\n\n\\subsubsection{Non-examples}\nNot all distributions of interest belong to the exponential family. For example, the uniform distribution,$X \\sim U(a,b)$, does not, since the support of the distribution depends on the parameters. Also, the Student T distribution (Section TODO) does not belong, since it does not have the required form.\n\n\n\\subsection{Log partition function}\nAn important property of the exponential family is that derivatives of the log partition function can be used to generate \\textbf{cumulants} of the sufficient statistics.\\footnote{The first and second cumulants of a distribution are its mean $\\mathbb{E}[X]$ and variance $\\mathrm{var}[X]$, whereas the first and second moments are its mean $\\mathbb{E}[X]$ and $\\mathbb{E}[X^2]$.} For this reason, $A(\\vec{\\theta})$ is sometimes called a \\textbf{cumulant function}. We will prove this for a 1-parameter distribution; this can be generalized to a $K$-parameter distribution in a straightforward way. For the first derivative we have\n\nFor the second derivative we have\n\\begin{align}\n\\dfrac{\\mathrm{d} A}{\\mathrm{d} \\theta} & = \\dfrac{\\mathrm{d}}{\\mathrm{d} \\theta}\\left\\{\\log\\int\\exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x\\right\\} \\nonumber \\\\\n    & = \\dfrac{\\frac{\\mathrm{d}}{\\mathrm{d} \\theta}\\int\\exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x}{\\int\\exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x} \\nonumber \\\\\n\t& = \\dfrac{\\int\\phi(x)exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x}{\\exp(A(\\theta))} \\nonumber \\\\\n\t& = \\int \\phi(x)\\exp\\left[\\theta\\phi(x)-A(\\theta)\\right]h(x)\\mathrm{d}x \\nonumber \\\\\n\t& = \\int \\phi(x)p(x)\\mathrm{d}x=\\mathbb{E}[\\phi(x)]\n\\end{align}\n\nFor the second derivative we have\n\\begin{align}\n\\dfrac{\\mathrm{d}^2 A}{\\mathrm{d} \\theta^2} & = \\int \\phi(x)\\exp\\left[\\theta\\phi(x)-A(\\theta)\\right]h(x)\\left[\\phi(x)-A'(\\theta)\\right]\\mathrm{d}x \\nonumber \\\\\n    & = \\int \\phi(x)p(x)\\left[\\phi(x)-A'(\\theta)\\right]\\mathrm{d}x \\nonumber \\\\\n\t& = \\int \\phi^2(x)p(x)\\mathrm{d}x-A'(\\theta)\\int \\phi(x)p(x)\\mathrm{d}x \\nonumber \\\\\n\t& = \\mathbb{E}[\\phi^2(x)]-\\mathbb{E}[\\phi(x)]^2=\\mathrm{var}[\\phi(x)]\n\\end{align}\n\nIn the multivariate case, we have that\n\\begin{equation}\n\\dfrac{\\partial^2 A}{\\partial \\theta_i \\partial \\theta_j}=\\mathbb{E}[\\phi_i(x)\\phi_j(x)]-\\mathbb{E}[\\phi_i(x)]\\mathbb{E}[\\phi_j(x)]\n\\end{equation}\nand hence\n\\begin{equation}\n\\nabla^2A(\\vec{\\theta}) = \\mathrm{cov}[\\phi(\\vec{x})]\n\\end{equation}\n\nSince the covariance is positive definite, we see that $A(\\vec{\\theta})$ is a convex function (see Section \\ref{sec:Convexity}).\n\n\n\\subsection{MLE for the exponential family}\nThe likelihood of an exponential family model has the form\n\\begin{equation}\np(\\mathcal{D}|\\vec{\\theta})=\\left[\\prod\\limits_{i=1}^N h(\\vec{x}_i)\\right]g(\\vec{\\theta})^N\\exp\\left[\\vec{\\theta}^T\\left(\\sum\\limits_{i=1}^N \\phi(\\vec{x}_i)\\right)\\right]\n\\end{equation}\n\nWe see that the sufficient statistics are $N$ and\n\\begin{equation}\n\\phi(\\mathcal{D})=\\sum\\limits_{i=1}^N \\phi(\\vec{x}_i)=(\\sum\\limits_{i=1}^N \\phi_1(\\vec{x}_i),\\cdots,\\sum\\limits_{i=1}^N \\phi_K(\\vec{x}_i))\n\\end{equation}\n\nThe \\textbf{Pitman-Koopman-Darmois theorem} states that, under certain regularity conditions, the exponential family is the only family of distributions with finite sufficient statistics. (Here, finite means of a size independent of the size of the data set.)\n\nOne of the conditions required in this theorem is that the support of the distribution not be dependent on the parameter.\n\n\n\\subsection{Bayes for the exponential family}\n\\label{sec:Bayes-for-the-exponential-family}\nTODO\n\n\n\\subsubsection{Likelihood}\n\n\n\n\\subsection{Maximum entropy derivation of the exponential family *}\n\\label{sec:Maximum-entropy-derivation-of-the-exponential-family}\n\n\n\n\\section{Generalized linear models (GLMs)}\n\\label{sec:GLMs}\nLinear and logistic regression are examples of \\textbf{generalized linear models}, or \\textbf{GLM}s (McCullagh and Nelder 1989). These are models in which the output density is in the exponential family (Section \\ref{sec:exponential-family}), and in which the mean parameters are a linear combination of the inputs, passed through a possibly nonlinear function, such as the logistic function. We describe GLMs in more detail below. We focus on scalar outputs for notational simplicity. (This excludes multinomial logistic regression, but this is just to simplify the presentation.)\n\n\n\\subsection{Basics}\n\n\n\n\\section{Probit regression}\n\n\n\n\\section{Multi-task learning}\n\n\n\n", "meta": {"hexsha": "b3413391f4f9f4b2478ef3018faad10bbee63e66", "size": 10554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterGLM.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/chapterGLM.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/chapterGLM.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": 56.4385026738, "max_line_length": 630, "alphanum_fraction": 0.7011559598, "num_tokens": 3484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8872046041554923, "lm_q1q2_score": 0.6847830956578129}}
{"text": "\\chapter{isdet} \\label{isdet}\n\n\\section{Introduction}\n\nThe \\texttt{isdet} command checks whether the specified LPE is deterministic.\nThe command may yield false negatives.\n\n\\section{Formal background}\n\n\\subsection{Summand determinism}\n\nConsider two summands, $s_\\alpha$ and $s_\\beta$, and reference their elements conform \\ref{summandelements}.\n\nSummands $s_\\alpha$ and $s_\\beta$ are said to be \\emph{deterministic} if one of these conditions holds:\n\n\\begin{itemize}\n\\item $s_\\alpha$ and $s_\\beta$ are the same summand; that is, $s_\\alpha = s_\\beta$.\n\n\\item $s_\\alpha$ and $s_\\beta$ communicate over different channels:\n\\begin{align*}\nC_\\alpha \\neq C_\\beta \\land (C_\\alpha \\in \\{\\istep{}, \\cistep{}\\} \\not\\leftrightarrow C_\\beta \\in \\{\\istep{}, \\cistep{}\\})\n\\end{align*}\n\n\\item $s_\\alpha$ and $s_\\beta$ communicate with different numbers of communication variables; that is, $m_\\alpha \\neq m_\\beta$.\n\n\\item $s_\\alpha$ and $s_\\beta$ are never simultaneously enabled, or $s_\\alpha$ and $s_\\beta$ always lead to the same next state.\nIn order to determine this, check if\n\\begin{align*}\ng_\\alpha[X_\\beta] \\land g_\\beta \\rightarrow \\bigwedge\\limits_{j=1}^{k} v_\\alpha(p_j)[X_\\beta] = v_\\beta(p_j)\n\\end{align*}\n\nis a tautology, where $X_\\beta$ is defined as\n\\begin{align*}\nX_{\\beta} &= [x_\\alpha(j) \\rightarrow x_\\beta(j) \\;|\\; 1 \\leq j \\leq \\text{min}(m_\\alpha, m_\\beta)]\n\\end{align*}\n\\end{itemize}\n\nNote that this approach is \\emph{not} guaranteed to correctly recognize that two summands are deterministic (false negatives are tolerated)!\n\n\\section{Algorithm}\n\nThe algorithm invoked by the \\texttt{isdet} command checks for all pairs of different summands whether the first summand is deterministic with the second summand (see the previous section).\nThe algorithm yields \\textbf{true} if and only if this is the case for all summand pairs.\n\n\\section{Example}\n\nConsider the following LPE:\n\n\\begin{lstlisting}\n//Process definition:\nPROCDEF example[A :: Int](x, y :: Int)\n  = A ? i [[x==0 /\\ i>=0 /\\ i<=5]] >-> example[A](1, 0)\n  + A ? i [[y==0 /\\ i>=5 /\\ i<=9]] >-> example[A](0, 1)\n  ;\n\n//Initialization:\nexample[A](0, 1);\n\\end{lstlisting}\n\nConsider the two summands, calling the first $s_1$ and the second $s_2$.\n\nThe first three conditions for detecting determinism are false.\n\nFor the fourth condition, the antecedent is\n\\begin{align*}\ng_1[X_2] \\land g_2 &\\Leftrightarrow (\\texttt{x} = 0 \\land \\texttt{i} \\geq 0 \\land \\texttt{i} \\leq 5)[\\texttt{i} \\rightarrow \\texttt{i}] \\land (\\texttt{y} = 0 \\land \\texttt{i} \\geq 5 \\land \\texttt{i} \\leq 9) \\\\\n&\\Leftrightarrow \\texttt{x} = 0 \\land \\texttt{y} = 0 \\land \\texttt{i} = 5\n\\end{align*}\n\nGiven the antecedent, the conclusion must hold.\nThis is not the case:\n\\begin{align*}\nv_1(\\texttt{x})[X_2] = 1[\\texttt{i} \\rightarrow \\texttt{i}] = 1 \\neq 0 = v_2(\\texttt{x}) \\\\\nv_1(\\texttt{y})[X_2] = 0[\\texttt{i} \\rightarrow \\texttt{i}] = 0 \\neq 1 = v_2(\\texttt{y}) \\\\\n\\end{align*}\n\n$s_1$ is therefore \\emph{not} deterministic with $s_2$.\n\nChanging the LPE to\n\n\\begin{lstlisting}\n//Process definition:\nPROCDEF example[A :: Int](x, y :: Int)\n  = A ? i [[x==0 /\\ i>=0 /\\ i<=4]] >-> example[A](1, 0)\n  + A ? i [[y==0 /\\ i>=5 /\\ i<=9]] >-> example[A](0, 1)\n  ;\n\n//Initialization:\nexample[A](0, 1);\n\\end{lstlisting}\n\nwill result in an antecedent that is false; therefore, $s_1$ is deterministic with $s_2$.\n\n", "meta": {"hexsha": "43fa51b1144d4d1054c184d1bf483068b1e15b43", "size": 3336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sys/lpeops/tex/lpeopsDoc/isdet.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/isdet.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/isdet.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": 35.4893617021, "max_line_length": 209, "alphanum_fraction": 0.6888489209, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6847641307092516}}
{"text": "\\chapter{A Mechanical Formalisation}\\label{chap:implementation}\n\n% nogmaals url voor code noemen?\n\nIn this chapter we present a formalisation of some of the notions from\nChapter~\\ref{chap:rewriting} in the \\Coq proof\nassistant. Section~\\ref{sec:ordimp} translates the\ntree ordinals from Subsection~\\ref{sub:tree} to \\Coq. Coinductive\nterms are defined in Section~\\ref{sec:terms}. In Section~\\ref{sec:seq}\nwe present a novel representation of transfinite rewrite sequences\nbased on the structure of the tree ordinals. This we regard as the main\ncontribution of this thesis.\n\n%\\Coq has been used for sizeable projects such as CompCert and a\n%verified proof of the Four Color Theorem.\n\n%Examples of formalisations of mathematical theories in \\Coq:\n%\\begin{compactenum}\n%\\item Logic: A proof of G\\\"odel's First Incompleteness Theorem (Russel\n%  O'Connor).\n%\\item Analysis: Exact real arithmetic (Russel O'Connor).\n%\\end{compactenum}\n\nA short introduction to \\Coq is included in\nAppendix~\\ref{chap:coq}. In the \\Coq code fragments, we take some\nnotational liberties in favour of readability. Sometimes we omit (part\nof) the type information. We also freely use infix notations without\ndeclaration. Furthermore, variable and definition names are typeset\nliberally.\n\nSome definitions have implicit arguments, meaning those arguments can\nbe inferred by the system from the context. As an example, consider\nthe inductive type\n\\coqref{CoqIntro.natpos}{\\coqdocinductive{nat$^+$}} whose constructor\ntakes as arguments a natural number \\coqdocvar{n} and a proof that\n\\coqdocvar{n} is greater than $0$.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive}\n\\coqdef{CoqIntro.natpos}{nat\\_pos}{\\coqdocinductive{nat$^+$}} :\n\\coqdockw{Set} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{CoqIntro.Pos}{Pos}{\\coqdocconstructor{Pos}} :\n\\ensuremath{\\forall} \\coqdocvar{n} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}},\n0 < \\coqdocvariable{n} \\ensuremath{\\rightarrow}\n\\coqref{CoqIntro.natpos}{\\coqdocinductive{nat$^+$}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nThe argument \\coqdocvar{n} of\n\\coqref{CoqIntro.Pos}{\\coqdocconstructor{Pos}} can be implicit,\nsince it can be inferred from (the type of) the other argument. If\n\\coqdocvar{H} has type \\begin{coqdoccode}0 < 3\\end{coqdoccode}, we can\nwrite \\begin{coqdoccode}\\coqref{CoqIntro.Pos}{\\coqdocconstructor{Pos}}\n  \\coqdocvariable{H}\\end{coqdoccode} instead\nof \\begin{coqdoccode}\\coqref{CoqIntro.Pos}{\\coqdocconstructor{Pos}} 3\n  \\coqdocvariable{H}\\end{coqdoccode}.\n\nRelated work are the \\CoLoR \\citep{blanqui-koprowski-10} and \\Coccinelle\n\\citep{contejean-07} projects, libraries on finitary rewriting and\ntermination, and the representation of ordinal numbers up to\n$\\epsilon_0$ and $\\Gamma_0$ in Cantor and Veblen normal form by\n\\citet{casteran-06}.\n\n\n\\section{Ordinal Numbers}\\label{sec:ordimp}\n\nIn the theory of infinitary rewriting, the lengths of rewrite sequences play\na central role. One might even suspect that any representation of transfinite\nrewrite sequences needs a representation of ordinal numbers. But this is not\nthe case.\n\nConsider as an illustration the example of finite lists. They can be\nnaturally represented inductively, without the need for a\nrepresentation of natural numbers. The usual inductive definition of lists,\nusing constructors \\coqdocconstructor{Nil} and \\coqdocconstructor{Cons}, can\nbe seen as a generalisation of the natural numbers, defined inductively using\nconstructors \\coqdocconstructor{Zero} and \\coqdocconstructor{Successor}. The\ngeneralisation consists of labeling the \\coqdocconstructor{Cons} constructors\nwith list members.\n\nLikewise, we now turn to the definition of tree ordinals as a case study in\npreparation for the definition of transfinite rewrite sequences in\nSection~\\ref{sec:seq}.\n\nWe define the ordinal numbers using the representation of tree\nordinals (cf.~Definition~\\ref{def:ordinals}) in \\Coq by\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqdef{Ordinal.ord}{ord}{\\coqdocinductive{ord}} :\n\\coqdockw{Set} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Ordinal.Zero}{Zero}{\\coqdocconstructor{Zero}}  :\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Ordinal.Succ}{Succ}{\\coqdocconstructor{Succ}}  :\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}} \\ensuremath{\\rightarrow}\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Ordinal.Limit}{Limit}{\\coqdocconstructor{Limit}} :\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqref{Ordinal.ord}{\\coqdocinductive{ord}})\n\\ensuremath{\\rightarrow}\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nArithmetic operations on ordinals, such as addition, are easily\ndefined.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint} \\coqdef{Ordinal.add}{add}{$+$}\n(\\coqdocvar{$\\alpha$} \\coqdocvar{$\\beta$} :\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}}) :\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\beta$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Ordinal.Zero}{\\coqdocconstructor{Zero}}\n\\ensuremath{\\Rightarrow} \\coqdocvariable{$\\alpha$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Ordinal.Succ}{\\coqdocconstructor{Succ}}\n\\coqdocvar{$\\beta$} \\ensuremath{\\Rightarrow}\n\\coqref{Ordinal.Succ}{\\coqdocconstructor{Succ}}\n(\\coqdocvariable{$\\alpha$} \\coqref{Ordinal.add}{$+$}\n\\coqdocvariable{$\\beta$})\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Ordinal.Limit}{\\coqdocconstructor{Limit}}\n\\coqdocvar{f}   \\ensuremath{\\Rightarrow}\n\\coqref{Ordinal.Limit}{\\coqdocconstructor{Limit}} (\\coqdockw{fun}\n\\coqdocvar{n} \\ensuremath{\\Rightarrow}\n\\coqdocvariable{$\\alpha$} \\coqref{Ordinal.add}{$+$}\n(\\coqdocvariable{f} \\coqdocvariable{n}))\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nIn fact, all definitions from Subsection~\\ref{sub:tree} translate directly to\n\\Coq code. We can now prove basic properties of $\\preceq$, for example\nthat it is transitive and that, for the finite ordinals, it coincides\nwith the standard order on the natural numbers.\\footnote{Although\n  \\coqdocvariable{n} and \\coqdocvariable{m} have type\n  \\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n  and $\\preceq$ has type \\coqref{Ordinal.ord}{\\coqdocinductive{ord}}\n  $\\rightarrow$ \\coqref{Ordinal.ord}{\\coqdocinductive{ord}}\n  $\\rightarrow$ \\coqdockw{Prop}, we can state the lemma in this\n  concise way by defining the trivial coercion from\n  \\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n  to \\coqref{Ordinal.ord}{\\coqdocinductive{ord}}.}\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{Ordinal.ordletrans}{ord\\_le\\_trans}{\\coqdoclemma{\\ensuremath{\\preceq_{\\text{trans}}}}}\n:\n\\ensuremath{\\forall} \\coqdocvar{\\ensuremath{\\alpha}}\n\\coqdocvar{\\ensuremath{\\beta}}\n\\coqdocvar{\\ensuremath{\\gamma}}, \\coqdocvariable{\\ensuremath{\\alpha}}\n\\ensuremath{\\preceq} \\coqdocvariable{\\ensuremath{\\beta}}\n\\ensuremath{\\rightarrow}\n\\coqdocvariable{\\ensuremath{\\beta}} \\ensuremath{\\preceq}\n\\coqdocvariable{\\ensuremath{\\gamma}}\n\\ensuremath{\\rightarrow} \\coqdocvariable{\\ensuremath{\\alpha}}\n\\ensuremath{\\preceq}\n\\coqdocvariable{\\ensuremath{\\gamma}}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{Ordinal.ordlele}{ord\\_le\\_le}{\\coqdoclemma{\\ensuremath{\\preceq_\\text{nat}}}} :\n\\ensuremath{\\forall} \\coqdocvar{n} \\coqdocvar{m}, \\coqdocvariable{n}\n\\ensuremath{\\le} \\coqdocvariable{m} \\ensuremath{\\leftrightarrow}\n\\coqdocvariable{n} \\ensuremath{\\preceq} \\coqdocvariable{m}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nRecalling our discussion in Subsection~\\ref{sub:tree} of limit ordinals whose\nsequences do not actually approximate to a limit ordinal, we consider the\nlemma\n\\coqref{Ordinal.ordlezeroright}{\\coqdoclemma{\\ensuremath{\\preceq_{\\text{zero\\_right}}}}}\nas an example of this issue.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{Ordinal.ordlezeroright}{ord\\_le\\_zero\\_right}{\\coqdoclemma{\\ensuremath{\\preceq_{\\text{zero\\_right}}}}}\n:\n\\ensuremath{\\forall} \\coqdocvar{\\ensuremath{\\alpha}} \\coqdocvar{\\ensuremath{\\beta}},\n\\coqdocvariable{\\ensuremath{\\alpha}} \\ensuremath{\\preceq}\n\\coqref{Ordinal.Zero}{\\coqdocconstructor{Zero}}\n\\ensuremath{\\rightarrow}\n\\coqdocvariable{\\ensuremath{\\alpha}} \\ensuremath{\\preceq}\n\\coqdocvariable{\\ensuremath{\\beta}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nWe would like to strengthen this, but cannot, since nothing denies\n\\coqdocvariable{$\\alpha$} from being the tree ordinal $\\sqcup ( 0, 0, 0,\n\\ldots )$ (which has the same rank as $0$). We therefore turn to a subset of\nthe tree ordinals where we restrict limit sequences to be strictly\nmonotonic. This restriction is encoded in the\n\\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}} (well-formedness)\nproperty. The $\\Sigma$-type\n\\coqref{WfOrdinal.wford}{\\coqdocdefinition{ord$^\\text{wf}$}} defines\nthe resulting subset.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint} \\coqdef{WfOrdinal.wf}{wf}{\\coqdocdefinition{wf}}\n\\coqdocvar{\\ensuremath{\\alpha}} : \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{\\ensuremath{\\alpha}} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Ordinal.Zero}{\\coqdocconstructor{Zero}}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Logic}{True}{\\coqdocinductive{True}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Ordinal.Succ}{\\coqdocconstructor{Succ}}\n\\coqdocvar{\\ensuremath{\\beta}} \\ensuremath{\\Rightarrow}\n\\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}} \\coqdocvariable{\\ensuremath{\\beta}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Ordinal.Limit}{\\coqdocconstructor{Limit}} \\coqdocvar{f}\n\\ensuremath{\\Rightarrow} \\ensuremath{\\forall} \\coqdocvar{n},\n\\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}} (\\coqdocvariable{f}\n\\coqdocvariable{n}) \\ensuremath{\\land} \\ensuremath{\\forall} \\coqdocvar{m},\n\\coqdocvariable{n} < \\coqdocvariable{m} \\ensuremath{\\rightarrow}\n\\coqdocvariable{f} \\coqdocvariable{n} \\ensuremath{\\prec}\n\\coqdocvariable{f} \\coqdocvariable{m}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{WfOrdinal.wford}{wf\\_ord}{\\coqdocdefinition{ord$^\\text{wf}$}} : \\coqdockw{Set}\n:=\n%\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{sig}{\\coqdocinductive{sig}}\n%\\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}}.\\coqdoceol\n\\{ \\coqdocvariable{$\\alpha$} :\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}} \\ensuremath{|}\n\\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}} \\coqdocvariable{$\\alpha$}\n\\}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nNow we can prove the stronger result we were looking\nfor.\\footnote{Again, defining a simple coercion from\n  \\coqref{WfOrdinal.wford}{\\coqdocdefinition{ord$^\\text{wf}$}} to\n  \\coqref{Ordinal.ord}{\\coqdocinductive{ord}} (first $\\Sigma$-type\n  projection) lets us state this lemma concisely.}\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{WfOrdinal.wfordlezeroright}{wf\\_ord\\_le\\_zero\\_right}{\\coqdoclemma{\\ensuremath{\\preceq^{\\text{wf}}_{\\text{zero\\_right}}}}}\n:\n\\ensuremath{\\forall} \\coqdocvar{\\ensuremath{\\alpha}} :\n\\coqref{WfOrdinal.wford}{\\coqdocdefinition{ord$^\\text{wf}$}},\n\\coqdocvariable{\\ensuremath{\\alpha}} \\ensuremath{\\preceq}\n\\coqref{Ordinal.Zero}{\\coqdocconstructor{Zero}}\n\\ensuremath{\\rightarrow}\n\\coqdocvariable{\\ensuremath{\\alpha}} =\n\\coqref{Ordinal.Zero}{\\coqdocconstructor{Zero}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\n\n\\section{Coinductive Terms}\\label{sec:terms}\n\nWe define the type\n\\coqref{Term.term}{\\coqdocinductive{term}} of infinite terms with\nfunction symbols in \\coqdocvar{F} and variables in \\coqdocvar{X}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{CoInductive} \\coqdef{Term.term}{term}{\\coqdocinductive{term}} :\n\\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Term.Var}{Var}{\\coqdocconstructor{Var}} : \\coqdocvar{X}\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Term.Fun}{Fun}{\\coqdocconstructor{Fun}} :\n\\ensuremath{\\forall} \\coqdocvar{f} : \\coqdocvar{F},\n\\coqref{Vector.vector}{\\coqdocdefinition{vector}}\n\\coqref{Term.term}{\\coqdocinductive{term}}\n(\\coqdocprojection{arity} \\coqdocvariable{f})\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nThe objects of a coinductive type can only be built in some restricted way to\nensure productivity of their construction. This restriction implies a technical\ndifficulty in the definition of the\n\\coqref{Vector.vector}{\\coqdocdefinition{vector}} type, which is discussed in\nSection~\\ref{sec:guardedness}.\nFor now, we assume \\coqref{Vector.vector}{\\coqdocdefinition{vector}} to\nimplement dependently typed lists (the type depending on their length).\n\nThe standard equality defined in \\Coq, equivalent to Leibniz' equality and\nwritten $=$, does not suffice\nfor establishing that two terms are equal, given that the only way to build\ninfinite objects is by corecursion. Because the amount of memory available is\nfinite, we can only unfold the corecursive definition finitely many times, and\nthen still be left with a non-normal form. Simply comparing such\ndefinitions will not do, since the corecursive construction of any given\ninfinite object is not unique. To this end, we define two extensional\nequalities on \\coqref{Term.term}{\\coqdocinductive{term}}, following\nDefinitions~\\ref{def:bisimilarity} and \\ref{def:equiv}. The coinductive\nrelation \\coqref{TermEquality.termbis}{$\\bis$} defines bisimilarity and\npointwise equality is defined by \\coqref{TermEquality.termeq}{$\\equiv$}\ninductively.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{CoInductive}\n\\coqdef{TermEquality.termbis}{term\\_bis}{$\\bis$} :\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\rightarrow}\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\rightarrow}\n\\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{TermEquality.Varbis}{Var\\_bis}{\\coqdocconstructor{$\\biss{\\text{Var}}$}} :\n\\ensuremath{\\forall} \\coqdocvar{x},\n\\coqref{Term.Var}{\\coqdocconstructor{Var}} \\coqdocvariable{x}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqref{Term.Var}{\\coqdocconstructor{Var}} \\coqdocvariable{x}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{TermEquality.Funbis}{Fun\\_bis}{\\coqdocconstructor{$\\biss{\\text{Fun}}$}} :\n\\ensuremath{\\forall} \\coqdocvar{f} \\coqdocvar{v} \\coqdocvar{w},\n(\\ensuremath{\\forall} \\coqdocvar{i},\n\\coqdocvariable{v} \\coqdocvariable{i}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{w} \\coqdocvariable{i})\n\\ensuremath{\\rightarrow}\n\\coqref{Term.Fun}{\\coqdocconstructor{Fun}} \\coqdocvariable{f}\n\\coqdocvariable{v}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqref{Term.Fun}{\\coqdocconstructor{Fun}} \\coqdocvariable{f}\n\\coqdocvariable{w}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nAny proof of two infinite terms being bisimilar is an infinite proof, in the\nsense that the proof term is built by corecursion.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive}\n\\coqdef{TermEquality.termequpto}{term\\_eq\\_up\\_to}{\\equpto{}}\n:\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}}\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}}\n\\ensuremath{\\rightarrow} \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{TermEquality.teut0}{teut\\_0}{\\coqdocconstructor{teut$_0$}}   :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t},\n\\coqdocvariable{s} \\coqref{TermEquality.termequpto}{\\equpto{0}}\n\\coqdocvariable{t}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{TermEquality.teutvar}{teut\\_var}{\\coqdocconstructor{teut$_\\text{Var}$}} :\n\\ensuremath{\\forall} \\coqdocvar{d} \\coqdocvar{x},\n\\coqref{Term.Var}{\\coqdocconstructor{Var}} \\coqdocvariable{x}\n\\coqref{TermEquality.termequpto}{\\equpto{\\coqdocvariable{d}}}\n\\coqref{Term.Var}{\\coqdocconstructor{Var}} \\coqdocvariable{x}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{TermEquality.teutfun}{teut\\_fun}{\\coqdocconstructor{teut$_\\text{Fun}$}} :\n\\ensuremath{\\forall} \\coqdocvar{d} \\coqdocvar{f} \\coqdocvar{v}\n\\coqdocvar{w},\n(\\ensuremath{\\forall} \\coqdocvar{i},\n\\coqdocvariable{v} \\coqdocvariable{i}\n\\coqref{TermEquality.termequpto}{\\equpto{\\coqdocvariable{d}}}\n\\coqdocvariable{w} \\coqdocvariable{i}) \\ensuremath{\\rightarrow}\n\\coqref{Term.Fun}{\\coqdocconstructor{Fun}}\n\\coqdocvariable{f} \\coqdocvariable{v}\n\\coqref{TermEquality.termequpto}{\\equpto{\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n    \\, \\coqdocvariable{d}}}\n\\coqref{Term.Fun}{\\coqdocconstructor{Fun}} \\coqdocvariable{f}\n\\coqdocvariable{w}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdocvar{s}\n\\coqdef{TermEquality.termeq}{term\\_eq}{$\\equiv$}\n\\coqdocvar{t} :=\n\\ensuremath{\\forall} \\coqdocvar{d},\n\\coqdocvariable{s}\n\\coqref{TermEquality.termequpto}{\\equpto{\\coqdocvariable{d}}}\n\\coqdocvariable{t}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nWe can prove that \\coqref{TermEquality.termbis}{$\\bis$} and\n\\coqref{TermEquality.termeq}{$\\equiv$} are the same\nrelation, and that indeed it is an equivalence.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{TermEquality.termbistermeq}{term\\_bis\\_term\\_eq}{\\coqdoclemma{term\\_bis\\_term\\_eq}}\n: \\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t},\n\\coqdocvariable{s}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{t} \\ensuremath{\\leftrightarrow}\n\\coqdocvariable{s}\n\\coqref{TermEquality.termeq}{$\\equiv$}\n\\coqdocvariable{t}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{TermEquality.termbisrefl}{term\\_bis\\_refl}{\\coqdoclemma{$\\biss{\\text{refl}}$}}\n: \\ensuremath{\\forall} \\coqdocvar{t},\n\\coqdocvariable{t}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{t}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{TermEquality.termbissymm}{term\\_bis\\_symm}{\\coqdoclemma{$\\biss{\\text{symm}}$}}\n: \\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t},\n\\coqdocvariable{s}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{t} $\\rightarrow$\n\\coqdocvariable{t}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{s}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{TermEquality.termbistrans}{term\\_bis\\_trans}{\\coqdoclemma{$\\biss{\\text{trans}}$}}\n: \\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u},\n\\coqdocvariable{s}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{t} $\\rightarrow$\n\\coqdocvariable{t}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{u} $\\rightarrow$\n\\coqdocvariable{s}\n\\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{u}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nIn Section~\\ref{sec:seq} we need some notion of convergence for functions of\ntype\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n$\\rightarrow$\n\\coqref{Term.term}{\\coqdocinductive{term}}. We implement\nDefinition~\\ref{def:cauchy} in \\Coq for sequences of length $\\omega$.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.converges}{converges}{\\coqdocdefinition{converges}}\n(\\coqdocvar{f} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}})\n(\\coqdocvar{t} : \\coqref{Term.term}{\\coqdocinductive{term}}) :\n\\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{\\forall} \\coqdocvar{d}, \\ensuremath{\\exists} \\coqdocvar{n},\n\\ensuremath{\\forall} \\coqdocvar{m},\n\\coqdocvariable{n} \\ensuremath{\\le} \\coqdocvariable{m}\n\\ensuremath{\\rightarrow}\n\\coqdocvariable{f} \\coqdocvariable{m}\n\\coqref{TermEquality.termequpto}{\\equpto{\\coqdocvariable{d}}}\n\\coqdocvariable{t}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nThe definitions of finite term, rewrite rule, TRS, and left-linearity\nfrom Subsection~\\ref{sub:trs} translate to \\Coq directly. We define\n\\coqdef{Rewriting.lhs}{lhs}{\\coqdocprojection{lhs}} and\n\\coqdef{Rewriting.rhs}{rhs}{\\coqdocprojection{rhs}} to be first and\nsecond projection on rewrite rules, respectively.\n\nThe type of contexts is inductively defined, where the hole always\noccurs at a finite depth.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive}\n\\coqdef{Context.context}{context}{\\coqdocinductive{context}} :\n\\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} $\\Box$ :\n\\coqref{Context.context}{\\coqdocinductive{context}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Context.CFun}{CFun}{\\coqdocconstructor{CFun}} :\n\\ensuremath{\\forall} (\\coqdocvar{f} : \\coqdocvar{F}) (\\coqdocvar{i}\n\\coqdocvar{j} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}),\n\\coqdocvariable{i} +\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvariable{j} =\n\\coqdocprojection{arity} \\coqdocvariable{f}\n\\ensuremath{\\rightarrow}\\coqdoceol\n\\coqdocindent{5.50em}\n\\coqref{Vector.vector}{\\coqdocdefinition{vector}}\n\\coqref{Term.term}{\\coqdocinductive{term}} \\coqdocvariable{i}\n\\ensuremath{\\rightarrow}\n\\coqref{Context.context}{\\coqdocinductive{context}}\n\\ensuremath{\\rightarrow}\n\\coqref{Vector.vector}{\\coqdocdefinition{vector}}\n\\coqref{Term.term}{\\coqdocinductive{term}} \\coqdocvariable{j}\n\\ensuremath{\\rightarrow}\n\\coqref{Context.context}{\\coqdocinductive{context}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nApplying a substitution \\coqdocvariable{$\\sigma$} to a term\n\\coqdocvariable{t} is defined by corecursion over\n\\coqdocvariable{t}. We also use the\nnotation \\begin{coqdoccode}\\coqdocvariable{t}$^\\coqdocvariable{$\\sigma$}$\\end{coqdoccode}\nfor \\begin{coqdoccode}\\coqref{Substitution.substitute}{\\coqdocdefinition{substitute}}\n  \\coqdocvariable{$\\sigma$} \\coqdocvariable{t}\\end{coqdoccode}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Substitution.substitution}{substitution}{\\coqdocdefinition{substitution}}\n:= \\coqdocvar{X} \\ensuremath{\\rightarrow}\n\\coqref{Term.term}{\\coqdocinductive{term}}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{CoFixpoint}\n\\coqdef{Substitution.substitute}{substitute}{\\coqdocdefinition{substitute}}\n(\\coqdocvar{$\\sigma$} :\n\\coqref{Substitution.substitution}{\\coqdocdefinition{substitution}})\n(\\coqdocvar{t} :\n\\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}}\n\\coqdocvar{x}      \\ensuremath{\\Rightarrow} \\coqdocvariable{$\\sigma$}\n\\coqdocvariable{x}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Term.Fun}{\\coqdocconstructor{Fun}}\n\\coqdocvar{f} \\coqdocvar{args} \\ensuremath{\\Rightarrow}\n\\coqref{Term.Fun}{\\coqdocconstructor{Fun}} \\coqdocvariable{f}\n(\\coqref{Vector.vmap}{\\coqdocdefinition{vmap}}\n(\\coqref{Substitution.substitute}{\\coqdocdefinition{substitute}}\n\\coqdocvariable{$\\sigma$}) \\coqdocvariable{args})\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nWe apply the recursive function\n\\coqdef{Context.fill}{fill}{\\coqdocdefinition{fill}} (not shown here)\nto a context \\coqdocvariable{C} and a term \\coqdocvariable{t}\n(written \\begin{coqdoccode}\\coqdocvariable{C}[\\coqdocvariable{t}]\\end{coqdoccode})\nto replace the hole in \\coqdocvariable{C} with \\coqdocvariable{t}.\n\nPositions are represented by simple lists of natural numbers. This\nmeans the subterm at some position in some term may not actually\nexist. For this reason we employ\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{option}{\\coqdocinductive{option}}\ntypes in functions that do a lookup by position (functions in \\Coq are\nalways \\emph{total}). For further discussion of positions, see\nSection~\\ref{sec:design}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint} \\coqdef{Context.dig}{dig}{\\coqdocdefinition{dig}}\n(\\coqdocvar{t} : \\coqref{Term.term}{\\coqdocinductive{term}})\n(\\coqdocvar{p} :\n\\coqdocabbreviation{position})\n\\{\\coqdockw{struct} \\coqdocvar{p}\\} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{option}{\\coqdocinductive{option}}\n\\coqref{Context.context}{\\coqdocinductive{context}} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{p} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nil}{\\coqdocconstructor{nil}}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{Some}{\\coqdocconstructor{Some}}\n$\\Box$\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdocvar{n} :: \\coqdocvar{p} \\ensuremath{\\Rightarrow}\n\\coqdockw{match} \\coqdocvariable{t} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{3.00em}\n\\ensuremath{|} \\coqref{Term.Var}{\\coqdocconstructor{Var}}\n\\coqdocvar{\\_}      \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{None}{\\coqdocconstructor{None}}\\coqdoceol\n\\coqdocindent{3.00em}\n\\ensuremath{|} \\coqref{Term.Fun}{\\coqdocconstructor{Fun}}\n\\coqdocvar{f} \\coqdocvar{args} \\ensuremath{\\Rightarrow}\n\\coqdockw{match}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Arith.Bool\\_nat}{ltgedec}{\\coqdocdefinition{lt\\_ge\\_dec}}\n\\coqdocvariable{n} (\\coqdocprojection{arity}\n\\coqdocvariable{f}) \\coqdockw{with}\\coqdoceol\n\\coqdocindent{5.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{left}{\\coqdocconstructor{left}}\n\\coqdocvar{h}  \\ensuremath{\\Rightarrow} \\coqdockw{match}\n\\coqref{Context.dig}{\\coqdocdefinition{dig}}\n(\\coqdocdefinition{vnth} \\coqdocvariable{h}\n\\coqdocvariable{args}) \\coqdocvariable{p} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{7.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{None}{\\coqdocconstructor{None}}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{None}{\\coqdocconstructor{None}}\\coqdoceol\n\\coqdocindent{7.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{Some}{\\coqdocconstructor{Some}}\n\\coqdocvar{C} \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{Some}{\\coqdocconstructor{Some}}\n(\\coqref{Context.CFun}{\\coqdocconstructor{CFun}} \\coqdocvariable{f}\n(\\coqdoclemma{lt\\_plus\\_minus\\_r}\n\\coqdocvariable{h})\\coqdoceol\n\\coqdocindent{14.00em}\n(\\coqdocdefinition{vtake}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Arith.Lt}{ltleweak}{\\coqdoclemma{lt\\_le\\_weak}}\n\\coqdocvariable{n} (\\coqdocprojection{arity}\n\\coqdocvariable{f}) \\coqdocvariable{h})\n\\coqdocvariable{args})\\coqdoceol\n\\coqdocindent{14.00em}\n\\coqdocvariable{C}\\coqdoceol\n\\coqdocindent{14.00em}\n(\\coqdocdefinition{vdrop} \\coqdocvariable{h}\n\\coqdocvariable{args}))\\coqdoceol\n\\coqdocindent{7.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{5.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{right}{\\coqdocconstructor{right}}\n\\coqdocvar{\\_} \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{None}{\\coqdocconstructor{None}}\\coqdoceol\n\\coqdocindent{5.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{3.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\coqdocemptyline\n\\end{coqdoccode}\n\\end{singlespace}\n%\\pagebreak[4]\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint}\n\\coqdef{Term.subterm}{subterm}{\\coqdocdefinition{subterm}}\n(\\coqdocvar{t} : \\coqref{Term.term}{\\coqdocinductive{term}})\n(\\coqdocvar{p} :\n\\coqdocabbreviation{position})\n\\{\\coqdockw{struct} \\coqdocvar{p}\\} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{option}{\\coqdocinductive{option}}\n\\coqref{Term.term}{\\coqdocinductive{term}} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{p} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nil}{\\coqdocconstructor{nil}}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{Some}{\\coqdocconstructor{Some}}\n\\coqdocvariable{t}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdocvar{n} :: \\coqdocvar{p} \\ensuremath{\\Rightarrow}\n\\coqdockw{match} \\coqdocvariable{t} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{7.00em}\n\\ensuremath{|} \\coqref{Term.Var}{\\coqdocconstructor{Var}}\n\\coqdocvar{\\_}      \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{None}{\\coqdocconstructor{None}}\\coqdoceol\n\\coqdocindent{7.00em}\n\\ensuremath{|} \\coqref{Term.Fun}{\\coqdocconstructor{Fun}}\n\\coqdocvar{f} \\coqdocvar{args} \\ensuremath{\\Rightarrow}\n\\coqdockw{match}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Arith.Bool\\_nat}{ltgedec}{\\coqdocdefinition{lt\\_ge\\_dec}}\n\\coqdocvariable{n} (\\coqdocprojection{arity}\n\\coqdocvariable{f}) \\coqdockw{with}\\coqdoceol\n\\coqdocindent{15.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{left}{\\coqdocconstructor{left}}\n\\coqdocvar{h}  \\ensuremath{\\Rightarrow}\n\\coqref{Term.subterm}{\\coqdocdefinition{subterm}}\n(\\coqdocdefinition{vnth} \\coqdocvariable{h}\n\\coqdocvariable{args}) \\coqdocvariable{p}\\coqdoceol\n\\coqdocindent{15.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{right}{\\coqdocconstructor{right}}\n\\coqdocvar{\\_} \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{None}{\\coqdocconstructor{None}}\\coqdoceol\n\\coqdocindent{15.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{7.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nNow \\begin{coqdoccode}\\coqref{Term.subterm}{\\coqdocdefinition{subterm}}\n  \\coqdocvariable{t} \\coqdocvariable{p}\\end{coqdoccode} gives the\nsubterm of \\coqdocvariable{t} (if it exists)\nand \\begin{coqdoccode}\\coqref{Context.dig}{\\coqdocdefinition{dig}}\n  \\coqdocvariable{t} \\coqdocvariable{p}\\end{coqdoccode} gives the\ncontext \\coqdocvariable{C} (if it exists) that is \\coqdocvariable{t}\nwith \\begin{coqdoccode}\\coqref{Term.subterm}{\\coqdocdefinition{subterm}}\n  \\coqdocvariable{t} \\coqdocvariable{p}\\end{coqdoccode} replaced by\n$\\Box$ at position \\coqdocvariable{p}.\n\n\n\\section{Transfinite Rewrite Sequences}\\label{sec:seq}\n\nIn this section we present the essence of our development. Rewrite\nsequences of length $\\alpha$ are represented using the tree structure\nof the tree ordinal $\\alpha$. Much of the definitions on ordinals\nare lifted to rewrite sequences and we once more come to a notion of\nwell-formedness. The resulting representation is discussed in relation\nto the traditional theory of rewriting in\nSection~\\ref{sec:convergence}.\n\nThroughout this section, we let $\\mathcal{R}$ be a fixed TRS. We\ndefine the type of steps using rewrite rules in $\\mathcal{R}$,\nparameterised by their source and target terms. Some flexibility in the form\nof bisimilarity is allowed, motivated in Subsection~\\ref{sub:bissteps}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqdef{Rewriting.step}{step}{$\\rightarrow_\\mathcal{R}$} :\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\rightarrow}\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\rightarrow}\n\\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Rewriting.Step}{Step}{\\coqdocconstructor{Step}} :\n\\ensuremath{\\forall} (\\coqdocvar{s} \\coqdocvar{t} :\n\\coqref{Term.term}{\\coqdocinductive{term}}) (\\coqdocvar{$\\rho$} :\n\\coqdocrecord{rule}) (\\coqdocvar{C} :\n\\coqref{Context.context}{\\coqdocinductive{context}}) (\\coqdocvar{$\\sigma$} :\n\\coqref{Substitution.substitution}{\\coqdocdefinition{substitution}}),\\coqdoceol\n\\coqdocindent{6.50em} \\coqdocvariable{$\\rho$}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Lists.List}{In}{\\coqdocdefinition{$\\in$}}\n\\coqdocvar{$\\mathcal{R}$} \\ensuremath{\\rightarrow}\\coqdoceol\n\\coqdocindent{6.50em}\n\\coqdocvariable{C}[(\\coqref{Rewriting.lhs}{\\coqdocprojection{lhs}}\n\\coqdocvariable{$\\rho$})\\coqdocvariable{$^\\sigma$}] \\coqref{TermEquality.termbis}{$\\bis$} \\coqdocvariable{s}\n\\ensuremath{\\rightarrow}\\coqdoceol\n\\coqdocindent{6.50em}\n\\coqdocvariable{C}[(\\coqref{Rewriting.rhs}{\\coqdocprojection{rhs}}\n\\coqdocvariable{$\\rho$})\\coqdocvariable{$^\\sigma$}] \\coqref{TermEquality.termbis}{$\\bis$} \\coqdocvariable{t}\n\\ensuremath{\\rightarrow}\n(\\coqdocvariable{s} \\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqdocvariable{t}).\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nFor the translation of Definition~\\ref{def:stepeq} (equality of steps)\nto \\Coq, we assume the lifting of bisimilarity to contexts and that\n\\coqdef{Substitution.substitutioneq}{substitution\\_eq}{\\coqdocdefinition{substitution\\_eq}}\ndefines agreement of substitutions on a given list of variables.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.stepeq}{step\\_eq}{$\\approx$}\n(\\coqdocvar{s} \\coqdocvar{t} :\n\\coqref{Term.term}{\\coqdocinductive{term}}) (\\coqdocvar{$\\pi$} :\n\\coqdocvar{s} \\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$} \\coqdocvar{t}) (\\coqdocvar{u} \\coqdocvar{v} :\n\\coqref{Term.term}{\\coqdocinductive{term}}) (\\coqdocvar{$o$} :\n\\coqdocvar{u} \\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqdocvar{v}) : \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\pi$}, \\coqdocvariable{$o$}\n\\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Step}{\\coqdocconstructor{Step}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{$\\rho$} \\coqdocvar{C}\n\\coqdocvar{$\\sigma$} \\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{\\_},\n\\coqref{Rewriting.Step}{\\coqdocconstructor{Step}} \\coqdocvar{\\_}\n\\coqdocvar{\\_} \\coqdocvar{$\\rho'$} \\coqdocvar{C$'$} \\coqdocvar{$\\sigma'$}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow}\\coqdoceol\n\\coqdocindent{2.00em}\n\\coqdocvariable{C} $\\bis$ \\coqdocvariable{C$'$} \\ensuremath{\\land}\n\\coqdocvariable{$\\rho$} = \\coqdocvariable{$\\rho'$} \\ensuremath{\\land}\n\\coqref{Substitution.substitutioneq}{\\coqdocdefinition{substitution\\_eq}}\n(\\coqdocdefinition{vars}\n(\\coqref{Rewriting.lhs}{\\coqdocprojection{lhs}} \\coqdocvariable{$\\rho$}))\n\\coqdocvariable{$\\sigma$} \\coqdocvariable{$\\sigma'$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nWe describe a way to define rewrite sequences as an inductive type. A rewrite\nsequence of length $\\alpha$ can be represented by the tree ordinal $\\alpha$\nwhere we label every occurrence of the $^+$ constructor with a rewrite\nstep. To ensure that successive steps have the same target and source terms,\nrespectively, we include the source and target terms of the rewrite sequence\nin its type and label accordingly.\n\nAt this point, it is not immediately clear what the type of the limit\nconstructor should be. Following the tree ordinals, we think of a rewrite\nsequence as a countably branching tree with every branching node representing\nthe least upper bound of its branches. As a first step towards a type of\nrewrite sequences, we write down an incomplete try. Note that the\n\\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}} constructor appends\n(not prepends) a step to a sequence.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive}\n\\coqdef{Rewriting.sequence}{sequence}{$\\rewrites_\\mathcal{R}$} :\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\rightarrow}\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\rightarrow}\n\\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Rewriting.Nil}{Nil}{\\coqdocconstructor{Nil}} :\n\\ensuremath{\\forall} \\coqdocvar{t}, \\coqdocvariable{t}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t}\\coqdoceol \\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Rewriting.Cons}{Cons}{\\coqdocconstructor{Cons}}:\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u}, (\\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvar{t})\n$\\rightarrow$\n(\\coqdocvariable{t} \\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqdocvar{u}) $\\rightarrow$ (\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u})\\coqdoceol \\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdocconstructor{Lim}   :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t},\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdef{Rewriting.LimPlaceholder}{LimPlaceholder}{\\textbf{?}}) $\\rightarrow$\n(\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t}).\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nThis is not yet satisfying, because we cannot fix a value for\n\\coqref{Rewriting.LimPlaceholder}{\\textbf{?}}. We complete the type for\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} as follows. First, we\nparameterise it with the target terms of the branches. Second, we add the\ncondition that these terms must converge to the target term\n\\coqdocvariable{t}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocindent{1.00em}\\label{coq:lim}\n\\ensuremath{|} \\coqdef{Rewriting.Lim}{Lim}{\\coqdocconstructor{Lim}} :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t}\n(\\coqdocvar{ts} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}}),\\coqdoceol\n\\coqdocindent{5.0em}\n(\\ensuremath{\\forall} \\coqdocvar{n}, \\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvar{ts} \\coqdocvariable{n}) $\\rightarrow$\n\\coqref{Rewriting.converges}{\\coqdocdefinition{converges}} \\coqdocvariable{ts}\n\\coqdocvariable{t} $\\rightarrow$\n(\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t})\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nOf course, the branches of a \\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}}\nconstructor may still not actually approximate to a rewrite sequence (of\nlength a limit ordinal). The intuition is that each branch should extend on\nits preceding ones. This would correspond to the\n\\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}} property we defined on\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}}, where we lift $\\prec$ to a\nstrict prefix relation on\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}.\nWe return to this issue in Subsection~\\ref{sub:wf}, but\nfirst consider the definition of an embedding relation on\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}.\n\n\n\\subsection{Embeddings of Rewrite Sequences}\\label{sub:embedding}\n\nWe lift the notions of predecessor and predecessor indices to the domain of\ntransfinite rewrite sequences. The set of predecessor indices is\neasily defined as\n\\coqref{Rewriting.predtype}{\\coqdocdefinition{pred\\_type}}.\n\n%\\footnote{We employ some notational overloading by reusing $I(\\_)$ and\n%  $[\\_]\\_$ for the corresponding definitions on rewrite sequences.}\n%\\pagebreak[4]\n\\pagebreak[3]\n\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint}\n\\coqdef{Rewriting.predtype}{pred\\_type}{\\coqdocdefinition{pred\\_type}}\n\\coqdocvar{s} \\coqdocvar{t}\n(\\coqdocvar{$\\varphi$} : \\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvar{t}) :\n\\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\varphi$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}} \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Logic}{False}{\\coqdocinductive{empty}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{$\\psi$} \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{unit}{\\coqdocinductive{unit}}\n+ \\coqref{Rewriting.predtype}{\\coqdocdefinition{pred\\_type}}\n\\coqdocvariable{$\\psi$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} \\coqdocvar{\\_}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{f} \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow} \\{ \\coqdocvar{n} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\& \\coqref{Rewriting.predtype}{\\coqdocdefinition{pred\\_type}}\n(\\coqdocvariable{f} \\coqdocvariable{n}) \\}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nThe predecessor indices defined by\n\\coqref{Rewriting.predtype}{\\coqdocdefinition{pred\\_type}} point to a specific\noccurrence of the \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\nconstructor in a rewrite sequence. This constructor does not only contain a\nrewrite sequence (analogous to an ordinal in the\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}} case), but also a rewrite\nstep. The \\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} function gives us\nboth the rewrite sequence and the step pointed to by a predecessor index. For\nthe type checker to accept the\ndefinition, we use a $\\Sigma$-type that contains this pair, parameterised by\nthe source and target terms of the rewrite step.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint} \\coqdef{Rewriting.pred}{pred}{\\coqdocdefinition{pred}}\n\\coqdocvar{s} \\coqdocvar{t} (\\coqdocvar{$\\varphi$} : \\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvar{t})\n(\\coqdocvar{$\\iota$} : \\coqref{Rewriting.predtype}{\\coqdocdefinition{pred\\_type}}\n\\coqdocvariable{$\\varphi$})\n:\\coqdoceol \\coqdocindent{2.00em}\n\\{ \\coqdocvar{ts} :\n\\coqref{Term.term}{\\coqdocinductive{term}} \\ensuremath{\\times}\n\\coqref{Term.term}{\\coqdocinductive{term}} \\&\n(\\coqdocvariable{s} \\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{fst}{\\coqdocdefinition{fst}}\n\\coqdocvariable{ts}) \\ensuremath{\\times}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{fst}{\\coqdocdefinition{fst}}\n\\coqdocvariable{ts} \\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{snd}{\\coqdocdefinition{snd}}\n\\coqdocvariable{ts}) \\} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\varphi$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}} \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Logic}{Falserect}{\\coqdocdefinition{empty\\_rect}}\n\\coqdocvar{\\_}) \\coqdocvariable{$\\iota$} \\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}} \\coqdocvar{\\_}\n\\coqdocvar{u} \\coqdocvar{t} \\coqdocvar{$\\psi$} \\coqdocvar{$\\pi$}\n\\ensuremath{\\Rightarrow}\n\\coqdockw{match} \\coqdocvariable{$\\iota$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{10.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{inl}{\\coqdocconstructor{inl}}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{tt}{\\coqdocconstructor{tt}}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{existT}{\\coqdocconstructor{existT}}\n\\coqdocvar{\\_} (\\coqdocvariable{u}, \\coqdocvariable{t})\n(\\coqdocvariable{$\\psi$}, \\coqdocvariable{$\\pi$})\\coqdoceol\n\\coqdocindent{10.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{inr}{\\coqdocconstructor{inr}}\n\\coqdocvar{$\\kappa$}  \\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} \\coqdocvariable{$\\psi$}\n\\coqdocvariable{$\\kappa$}\\coqdoceol\n\\coqdocindent{10.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} \\coqdocvar{\\_}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{f} \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow}\n\\coqdockw{match} \\coqdocvariable{$\\iota$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{10.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{existT}{\\coqdocconstructor{existT}}\n\\coqdocvar{n} \\coqdocvar{$\\kappa$} \\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} (\\coqdocvariable{f}\n\\coqdocvariable{n}) \\coqdocvariable{$\\kappa$}\\coqdoceol\n\\coqdocindent{10.00em}\n\\coqdockw{end}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nIn an effort to prevent getting lost in a syntactical labyrinth, we define\nthe following notational shortcuts:\n\\begin{center}\\begin{singlespace}\n{\\renewcommand{\\arraystretch}{1.4}\n\\renewcommand{\\tabcolsep}{8pt}\n\\begin{tabular}{lll}\n\\textsc{short} & \\textsc{explanation} & \\textsc{definition}\\\\\n\\hline\n\\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}] & location in\n\\coqdocvar{$\\varphi$} indexed by \\coqdocvar{$\\iota$} &\n  \\begin{coqdoccode}\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} \\coqdocvar{$\\varphi$} \\coqdocvar{$\\iota$}\\end{coqdoccode} \\\\\n\\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}]$^\\textsc{seq}$ & rewrite sequence in\n  \\coqdocvar{$\\varphi$} indexed by \\coqdocvar{$\\iota$}\n  & \\begin{coqdoccode}\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{fst}{\\coqdocdefinition{fst}}\n      (\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{projT2}{\\coqdocdefinition{projT2}}\n      (\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} \\coqdocvar{$\\varphi$} \\coqdocvar{$\\iota$}))\\end{coqdoccode}\n  \\\\\n\\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}]$^\\textsc{stp}$ & step of \\coqdocvar{$\\varphi$} indexed by \\coqdocvar{$\\iota$} &\n  \\begin{coqdoccode}\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{snd}{\\coqdocdefinition{snd}}\n    (\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{projT2}{\\coqdocdefinition{projT2}}\n    (\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} \\coqdocvar{$\\varphi$} \\coqdocvar{$\\iota$}))\\end{coqdoccode}\n  \\\\\n\\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}]$^\\textsc{l}$ & source term of \\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}]$^\\textsc{stp}$\n  & \\begin{coqdoccode}\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{fst}{\\coqdocdefinition{fst}}\n      (\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{projT1}{\\coqdocdefinition{projT1}}\n      (\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} \\coqdocvar{$\\varphi$} \\coqdocvar{$\\iota$}))\\end{coqdoccode}\n  \\\\\n\\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}]$^\\textsc{r}$ & target term of\n  \\coqdocvar{$\\varphi$}[\\coqdocvar{$\\iota$}]$^\\textsc{stp}$ & \\begin{coqdoccode}\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{snd}{\\coqdocdefinition{snd}}\n    (\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{projT1}{\\coqdocdefinition{projT1}}\n    (\\coqref{Rewriting.pred}{\\coqdocdefinition{pred}} \\coqdocvar{$\\varphi$} \\coqdocvar{$\\iota$}))\\end{coqdoccode}\n\\end{tabular}}\n\\end{singlespace}\\end{center}\n\n%\\pagebreak[4]\n\nAs an example of predecessor indexing, consider the graphical\nrepresentation of a rewrite sequence $\\varphi$ of length $\\omega + 2$\nand its predecessor index $\\iota = \\coqdocconstructor{inr} \\;\n(\\coqdocconstructor{inr} \\; \\langle 4,\n\\coqdocconstructor{inl}\\rangle)$ in Figure~\\ref{fig:pred}. The initial\npart of length $\\omega$ is represented by a series of finite rewrite\nsequences, each one extending on the previous one by one step. The\nsequence of terms $\\{ t_1,t_2, t_3, \\ldots \\}$ converges to the term\n$t_\\omega$. Here, $\\varphi[\\iota]^\\textsc{seq}$ is a rewrite sequence\nfrom $t_1$ to $t_3$ and $\\varphi[\\iota]^\\textsc{stp}$ is a step from\n$t_3$ to $t_4$.\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.85]\n\\input{figures/predecessor.tikz}\n\\end{tikzpicture}\n\\end{center}\n\\caption{Example of a rewrite sequence and predecessor\n  index.}\\label{fig:pred}\n\\end{figure}\n\nHaving a closer look at the order $\\preceq$ on the tree ordinals, we can\nsee that it really defines embeddings of their tree structures. This is due to\nclause {\\sc \\ref{def:order:succ}} of Definition~\\ref{def:order}. In\nthis clause, two occurrences of the $^+$ constructor (one in both\nordinals) are cancelled out against each other, but the positions of\nthese occurrences in their respective ordinals do not necessarily\ncorrespond. Since occurrences of $^+$ carry no additional information,\nthis has no effect on the resulting relation.\n\nWhat this means for a translation of $\\preceq$ to the domain of our\ninductively defined rewrite sequences is that, indeed, we get an embedding\nrelation. We only have to make sure that in the\n\\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}} case, we cancel out two\nequal steps against each other.\nWe say that $\\varphi$ is embedded in $\\psi$ (written $\\varphi\n\\sqsubseteq \\psi$) if $\\psi$ can be obtained from $\\varphi$ by inserting\nany number of steps in $\\varphi$. We distinguish between inserting a step\n\\begin{inparaenum}[(i)]\n  \\item before the first step,\n  \\item after the last step, and\n  \\item in between steps\n\\end{inparaenum}\nin a rewrite sequence. Note that any steps inserted consecutively in between\nsteps necessarily form a cycle, because of the typing constraints in\nthe definition of rewrite sequence.\n% is this good or bad? (cycle)\n\n\\pagebreak[4]\n\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqdef{Rewriting.embed}{embed}{$\\sqsubseteq$}\n: \\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u}\n\\coqdocvar{v}, (\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvariable{t})\n$\\rightarrow$ (\\coqdocvariable{u}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvariable{v})\n$\\rightarrow$ \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{Rewriting.EmbedNil}{Embed\\_Nil}{\\coqdocconstructor{$\\sqsubseteq_\\text{Nil}$}}  :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{u} \\coqdocvar{v} (\\coqdocvar{$\\psi$}\n: \\coqdocvariable{u} \\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{v}),\\coqdoceol\n\\coqdocindent{9.50em}\n\\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}} \\coqdocvariable{s}\n\\coqref{Rewriting.embed}{$\\sqsubseteq$} \\coqdocvariable{$\\psi$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{Rewriting.EmbedCons}{Embed\\_Cons}{\\coqdocconstructor{$\\sqsubseteq_\\text{Cons}$}} :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u} \\coqdocvar{v}\n(\\coqdocvar{$\\psi$}\n: \\coqdocvariable{u} \\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{v}) (\\coqdocvar{$\\iota$} :\n\\coqref{Rewriting.predtype}{\\coqdocdefinition{pred\\_type}}\n\\coqdocvariable{$\\psi$})\n(\\coqdocvar{$\\varphi$} : \\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{$\\psi$}[\\coqdocvariable{$\\iota$}]$^\\textsc{l}$)\\coqdoceol\n\\coqdocindent{5.00em}\n(\\coqdocvar{$\\pi$} :\n\\coqdocvariable{$\\psi$}[\\coqdocvariable{$\\iota$}]$^\\textsc{l}$\n\\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqdocvariable{t}),\\coqdoceol\n\\coqdocindent{9.50em}\n\\coqdocvariable{$\\varphi$} \\coqref{Rewriting.embed}{$\\sqsubseteq$}\n\\coqdocvariable{$\\psi$}[\\coqdocvariable{$\\iota$}]$^\\textsc{seq}$\n\\ensuremath{\\rightarrow}\\coqdoceol\n\\coqdocindent{9.50em}\n\\coqdocvariable{$\\pi$} \\coqref{Rewriting.stepeq}{$\\approx$}\n\\coqdocvariable{$\\psi$}[\\coqdocvariable{$\\iota$}]$^\\textsc{stp}$\n\\ensuremath{\\rightarrow}\\coqdoceol\n\\coqdocindent{9.50em}\n\\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n\\coqdocvariable{$\\varphi$} \\coqdocvariable{$\\pi$}\n\\coqref{Rewriting.embed}{$\\sqsubseteq$}\n\\coqdocvariable{$\\psi$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqdef{Rewriting.EmbedLim}{Embed\\_Lim}{\\coqdocconstructor{$\\sqsubseteq_\\text{Lim}$}}  :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u} \\coqdocvar{v}\n(\\coqdocvar{ts} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqref{Term.term}{\\coqdocinductive{term}})\n(\\coqdocvar{f} : \\ensuremath{\\forall} \\coqdocvar{n},\n\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{ts} \\coqdocvariable{n})\\coqdoceol\n\\coqdocindent{5.00em}\n(\\coqdocvar{c} :\n\\coqref{Rewriting.converges}{\\coqdocdefinition{converges}} \\coqdocvariable{ts}\n\\coqdocvar{t}) (\\coqdocvar{$\\psi$} : \\coqdocvar{u}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvar{v}),\\coqdoceol\n\\coqdocindent{9.50em}\n(\\ensuremath{\\forall} \\coqdocvar{n}, \\coqdocvariable{f} \\coqdocvariable{n}\n\\coqref{Rewriting.embed}{$\\sqsubseteq$} \\coqdocvariable{$\\psi$})\n\\ensuremath{\\rightarrow}\\coqdoceol\n\\coqdocindent{9.50em}\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} \\coqdocvariable{f}\n\\coqdocvariable{c} \\coqref{Rewriting.embed}{$\\sqsubseteq$}\n\\coqdocvariable{$\\psi$}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nAnalogous to the strict order $\\prec$ on ordinals, we define a strict\nembedding relation $\\sqsubset$ on rewrite sequences.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.embedstrict}{embed\\_strict}{$\\sqsubset$}\n\\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u} \\coqdocvar{v}\n(\\coqdocvar{$\\varphi$} : \\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t},\n\\coqdocvar{$\\psi$} :\n\\coqdocvariable{u}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{v}) := \\ensuremath{\\exists} \\coqdocvar{$\\iota$},\n\\coqdocvariable{$\\varphi$} \\coqref{Rewriting.embed}{$\\sqsubseteq$}\n\\coqdocvariable{$\\psi$}[\\coqdocvariable{$\\iota$}]$^\\textsc{seq}$.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nNote that, while non-strictly embedded rewrite sequences may differ in\nany of the three ways defined above, strictly embedded rewrite\nsequences always differ in their last step. Thus, if $\\varphi$ is\nstrictly embedded in $\\psi$ then $\\psi$ can be obtained from $\\varphi$\nby inserting any number of steps in $\\varphi$, but at least one after\nthe last step.\n\n\n\\subsection{Well-formed Rewrite Sequences}\\label{sub:wf}\n\nThe \\coqref{WfOrdinal.wf}{\\coqdocdefinition{wf}} property on\n\\coqref{Ordinal.ord}{\\coqdocinductive{ord}} is defined in\nSection~\\ref{sec:ordimp} to rule out a\ncertain class of ordinal representations. This issue translates\ndirectly to our inductive representation of rewrite sequences. We\ndefine a well-formedness property\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} on rewrite sequences,\nusing the strict embedding relation $\\sqsubset$.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint} \\coqdef{Rewriting.wf}{wf}{\\coqdocdefinition{wf}}\n\\coqdocvar{s} \\coqdocvar{t}\n(\\coqdocvar{$\\varphi$} : \\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t}) : \\coqdockw{Prop}\n:=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\varphi$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}}\n\\coqdocvar{\\_}          \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Logic}{True}{\\coqdocinductive{True}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{$\\psi$} \\coqdocvar{\\_}\n\\coqdocvar{\\_} \\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}}\n\\coqdocvariable{\\coqdocvariable{$\\psi$}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{f} \\coqdocvar{\\_}\n\\coqdocvar{\\_}  \\ensuremath{\\Rightarrow}\n(\\ensuremath{\\forall} \\coqdocvar{n},\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} (\\coqdocvariable{f}\n\\coqdocvariable{n})) \\ensuremath{\\land}\n\\ensuremath{\\forall} \\coqdocvar{n} \\coqdocvar{m}, \\coqdocvariable{n}\n< \\coqdocvariable{m} \\ensuremath{\\rightarrow} \\coqdocvariable{f}\n\\coqdocvariable{n}\n\\coqref{Rewriting.embedstrict}{$\\sqsubset$}\n\\coqdocvariable{f} \\coqdocvariable{m}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nOn page~\\pageref{coq:lim}, we define the\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} constructor with the\nintuition that each of its branches should extend on the preceding\nones. Naturally, we would implement this condition using a strict prefix\nrelation on rewrite sequences, but the strict embedding relation\n$\\sqsubset$ is also satisfying for this purpose.\n\nConsider an instance of\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}}, satisfying\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}}, with branches\n\\coqdocvar{f}. For every \\begin{coqdoccode}\\coqdocvariable{n} <\n  \\coqdocvariable{m}\\end{coqdoccode}, we\nhave \\begin{coqdoccode}\\coqdocvariable{f} \\coqdocvariable{n}\n  \\coqref{Rewriting.embedstrict}{$\\sqsubset$} \\coqdocvariable{f}\n  \\coqdocvariable{m}\\end{coqdoccode}. Thus there is a predecessor\nsequence % \\coqdocvariable{$\\varphi$}\nof \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{m}\\end{coqdoccode} that can be obtained\nfrom \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{n}\\end{coqdoccode} by inserting any number of steps\nin \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{n}\\end{coqdoccode}. Steps inserted before the last\nstep of \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{n}\\end{coqdoccode} must form a cycle (note that all\nbranches start at the same\nterm). Therefore, \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{m}\\end{coqdoccode} can be obtained\nfrom \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{n}\\end{coqdoccode} by adding one or more steps at\nthe end of \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{n}\\end{coqdoccode} and possibly inserting cycles at\nother positions of \\begin{coqdoccode}\\coqdocvariable{f}\n  \\coqdocvariable{n}\\end{coqdoccode}. This shows that, ignoring\ncycles, $\\sqsubset$ actually defines a strict prefix relation on the\nbranches of \\coqdocvar{f}.\n\n%Vincent said this about it:\n%\\begin{quote}\n%Overigens bedachten dat het in principe niet heel erg is $\\sqsubseteq$ te\n%definieren voor reducties zoals voor ordinalen. alleen zie je dan het meer een\n%notie van embedding/deelreductie ipv een notie van prefix geeft, maar ook daar\n%kun je denkelijk goed mee werken.\n%\n%\\ldots\n%\n%als je een stuk invoegt in het midden in sigma moet dat noodzakelijkerwijs,\n%vanwege de constraints op begin-en eindpunten, een reductie cykel zijn. ik zou\n%verwachten dat dat uiteindelijk een goede notie van ordening (goede reducties)\n%oplevert (``de cykels doen er niet toe voor convergente rijen, en kun je\n%weglaten bij compressie''), die natuurlijk niet overeenkomt, ook niet in het\n%eindige geval met de prefix notie; het is deelwoord, of (op reductie rijtjes\n%als bomen) deelboom (en niet boom-factor).\n%\\end{quote}\n\nThere is still an important omission in our formalisation\nthough: even rewrite sequences satisfying\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} are not necessarily\nconvergent. How the convergence conditions from\nDefinition~\\ref{def:convergence} relate to our formalisation is\ndiscussed in Section~\\ref{sec:convergence}.\n\n\n\\subsection{Combining Rewrite Sequences}\\label{sub:combining}\n\nWith the \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\nconstructor, we can extend a rewrite sequence with one step at the\nend. Dually, \\coqref{Rewriting.snoc}{\\coqdocdefinition{snoc}} extends\na rewrite sequence with one step at the start. It is the analogue of\n$1 \\coqref{Ordinal.add}{+} \\alpha$ on ordinals.\n\n\\coqref{Rewriting.snoc}{\\coqdocdefinition{snoc}} is recursive in its\nright argument, but for the \\Coq type checker to accept our\ndefinition, we must write it such that it consumes this argument\nfirst.\\footnote{The reason for this is rather technical, but the idea\n  is that the return type nicely follows the case analysis on the\n  rewrite sequence in the \\coqdockw{match} construction. We also give\n  some hints to the \\Coq type checker that are not shown here.}\nHence, we use an auxiliary function\n\\coqref{Rewriting.snocrec}{\\coqdocdefinition{snoc\\_rec}}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint}\n\\coqdef{Rewriting.snocrec}{snoc\\_rec}{\\coqdocdefinition{snoc\\_rec}}\n\\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u} (\\coqdocvar{$\\varphi$} :\n\\coqdocvariable{t}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u}) : (\\coqdocvariable{s}\n\\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqdocvariable{t}) \\ensuremath{\\rightarrow} (\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u}) :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\varphi$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}}\n\\coqdocvar{\\_}          \\ensuremath{\\Rightarrow} \\coqdockw{fun}\n\\coqdocvar{$\\pi$} \\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n(\\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}} \\coqdocvariable{s})\n\\coqdocvariable{$\\pi$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{$\\psi$} \\coqdocvar{\\_}\n\\coqdocvar{$o$} \\ensuremath{\\Rightarrow} \\coqdockw{fun} \\coqdocvar{$\\pi$}\n\\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n(\\coqref{Rewriting.snocrec}{\\coqdocdefinition{snoc\\_rec}}\n\\coqdocvariable{$\\psi$} \\coqdocvariable{$\\pi$}) \\coqdocvariable{$o$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{f} \\coqdocvar{u}\n\\coqdocvar{c}  \\ensuremath{\\Rightarrow} \\coqdockw{fun} \\coqdocvar{$\\pi$}\n\\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} (\\coqdockw{fun}\n\\coqdocvar{$o$} \\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.snocrec}{\\coqdocdefinition{snoc\\_rec}}\n(\\coqdocvariable{f} \\coqdocvariable{$o$}) \\coqdocvariable{$\\pi$})\n\\coqdocvariable{c}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.snoc}{snoc}{\\coqdocdefinition{snoc}} \\coqdocvar{s}\n\\coqdocvar{t} \\coqdocvar{u} (\\coqdocvar{$\\pi$}\n: \\coqdocvar{s} \\coqref{Rewriting.step}{$\\rightarrow_\\mathcal{R}$}\n\\coqdocvar{t}) (\\coqdocvar{$\\varphi$} : \\coqdocvariable{t}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvar{u}) :\n\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u} :=\n\\coqref{Rewriting.snocrec}{\\coqdocdefinition{snoc\\_rec}}\n\\coqdocvariable{$\\varphi$} \\coqdocvariable{$\\pi$}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nA related operation is concatenation of rewrite sequences, the\nanalogue of addition on ordinals. It is defined in the same way as\n\\coqref{Rewriting.snoc}{\\coqdocdefinition{snoc}}.\n\\pagebreak[4]\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint}\n\\coqdef{Rewriting.appendrec}{append\\_rec}{\\coqdocdefinition{concat\\_rec}}\n\\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u} (\\coqdocvar{$\\psi$} :\n\\coqdocvariable{t}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u}) : (\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t}) \\ensuremath{\\rightarrow} (\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u}) :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{$\\psi$} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Nil}{\\coqdocconstructor{Nil}}\n\\coqdocvar{\\_}         \\ensuremath{\\Rightarrow} \\coqdockw{fun}\n\\coqdocvar{$\\varphi$} \\ensuremath{\\Rightarrow} \\coqdocvariable{$\\varphi$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{$\\psi$} \\coqdocvar{\\_}\n\\coqdocvar{$\\pi$} \\ensuremath{\\Rightarrow} \\coqdockw{fun} \\coqdocvar{$\\varphi$}\n\\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.Cons}{\\coqdocconstructor{Cons}}\n(\\coqref{Rewriting.appendrec}{\\coqdocdefinition{concat\\_rec}}\n\\coqdocvariable{$\\psi$} \\coqdocvariable{$\\varphi$}) \\coqdocvariable{$\\pi$}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}}\n\\coqdocvar{\\_} \\coqdocvar{\\_} \\coqdocvar{f} \\coqdocvar{u}\n\\coqdocvar{c}  \\ensuremath{\\Rightarrow} \\coqdockw{fun} \\coqdocvar{$\\varphi$}\n\\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} (\\coqdockw{fun}\n\\coqdocvar{$o$} \\ensuremath{\\Rightarrow}\n\\coqref{Rewriting.appendrec}{\\coqdocdefinition{concat\\_rec}}\n(\\coqdocvariable{f} \\coqdocvariable{$o$}) \\coqdocvariable{$\\varphi$})\n\\coqdocvariable{c}\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.append}{append}{\\coqdocdefinition{concat}}\n\\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u} (\\coqdocvar{$\\varphi$} :\n\\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvar{t})\n(\\coqdocvar{$\\psi$} : \\coqdocvariable{t}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvar{u}) :\n\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{u} :=\\coqdoceol\n\\coqdocindent{1.0em}\n\\coqref{Rewriting.appendrec}{\\coqdocdefinition{concat\\_rec}}\n\\coqdocvariable{$\\psi$} \\coqdocvariable{$\\varphi$}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nWell-formedness is preserved under concatenation.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{Rewriting.appendwf}{append\\_wf}{\\coqdoclemma{concat\\_wf}} :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u}\n(\\coqdocvar{$\\varphi$} : \\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvar{t}) (\\coqdocvar{$\\psi$} : \\coqdocvariable{t}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvar{u}),\\coqdoceol\n\\coqdocindent{9.00em}\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} \\coqdocvariable{$\\varphi$}\n\\ensuremath{\\rightarrow}\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} \\coqdocvariable{$\\psi$}\n\\ensuremath{\\rightarrow}\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}}\n(\\coqref{Rewriting.append}{\\coqdocdefinition{concat}}\n\\coqdocvariable{$\\varphi$} \\coqdocvariable{$\\psi$}).\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\n\n\\section{Properties of Terms and TRSs}\n\nWe define some predicates on terms and TRSs. Again, we let\n$\\mathcal{R}$ be a fixed TRS throughout this section.\n\nWe work with a somewhat relaxed definition of critical pairs. First,\nwe do not require the common instance to be a most general\none. Second, the substitution $\\sigma$ might not be minimal and might\nnot introduce only fresh variables\n(cf.\\ Definition~\\ref{def:overlap}). The effect of this relaxation is\nthat for every critical pair, we have a series of critical pairs by\nthis \\Coq definition. This is precise enough for our present\npurposes, however, since it has no effect on questions such as\n\\emph{are there critical pairs?} or \\emph{are all critical pairs\n  trivial?}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.criticalpair}{critical\\_pair}{\\coqdocdefinition{critical\\_pair}}\n(\\coqdocvar{$\\mathcal{R}$} : \\coqdocdefinition{trs})\n(\\coqdocvar{t$_1$} \\coqdocvar{t$_2$} :\n\\coqref{Term.term}{\\coqdocinductive{term}}) : \\coqdockw{Prop}\n:=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{\\exists} \\coqdocvar{$\\rho_1$} :\n\\coqdocrecord{rule}, \\ensuremath{\\exists}\n\\coqdocvar{$\\rho_2$} :\n\\coqdocrecord{rule},\n\\ensuremath{\\exists} \\coqdocvar{p} :\n\\coqdocabbreviation{position},\n\\ensuremath{\\exists} \\coqdocvar{$\\sigma$},\n\\ensuremath{\\exists} \\coqdocvar{$\\tau$},\\coqdoceol\n\\coqdocindent{3.00em}\n\\coqdocvariable{$\\rho_1$} \\coqdocdefinition{$\\in$}\n\\coqdocvariable{$\\mathcal{R}$}\n\\ensuremath{\\land}\n\\coqdocvariable{$\\rho_2$} \\coqdocdefinition{$\\in$}\n\\coqdocvar{$\\mathcal{R}$} \\ensuremath{\\land}\n(\\coqdocvariable{$\\rho_1$} = \\coqdocvariable{$\\rho_2$}\n\\ensuremath{\\rightarrow}\n\\coqdocvariable{p} \\ensuremath{\\not=}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nil}{\\coqdocconstructor{nil}})\n\\ensuremath{\\land}\\coqdoceol\n\\coqdocindent{3.00em}\n\\coqdockw{match}\n\\coqref{Term.subterm}{\\coqdocdefinition{subterm}} (\\coqref{Rewriting.lhs}{\\coqdocprojection{lhs}}\n\\coqdocvariable{$\\rho_1$}) \\coqdocvariable{p},\n\\coqref{Context.dig}{\\coqdocdefinition{dig}} (\\coqref{Rewriting.lhs}{\\coqdocprojection{lhs}}\n\\coqdocvariable{$\\rho_1$})$^{\\coqdocvariable{$\\sigma$}}$ \\coqdocvariable{p}\n\\coqdockw{with}\\coqdoceol\n\\coqdocindent{3.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{Some}{\\coqdocconstructor{Some}}\n\\coqdocvar{s},\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{Some}{\\coqdocconstructor{Some}}\n\\coqdocvar{C} \\ensuremath{\\Rightarrow}\n\\coqdocdefinition{is\\_var} \\coqdocvariable{s} =\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{false}{\\coqdocconstructor{false}}\n\\ensuremath{\\land}\n\\coqdocvariable{s}$^{\\coqdocvariable{$\\sigma$}}$ \\coqref{TermEquality.termbis}{$\\bis$}\n(\\coqref{Rewriting.lhs}{\\coqdocprojection{lhs}}\n\\coqdocvariable{$\\rho_2$})$^{\\coqdocvariable{$\\tau$}}$\n\\ensuremath{\\land}\\coqdoceol\n\\coqdocindent{12.00em}\n\\coqdocvariable{t$_1$} \\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{C}[(\\coqref{Rewriting.rhs}{\\coqdocprojection{rhs}}\n\\coqdocvariable{$\\rho_2$})$^{\\coqdocvariable{$\\tau$}}$]\n\\ensuremath{\\land}\n\\coqdocvariable{t$_2$} \\coqref{TermEquality.termbis}{$\\bis$}\n(\\coqref{Rewriting.rhs}{\\coqdocprojection{rhs}}\n\\coqdocvariable{$\\rho_1$})$^{\\coqdocvariable{$\\sigma$}}$\\coqdoceol\n\\coqdocindent{3.00em}\n\\ensuremath{|} \\coqdocvar{\\_}, \\coqdocvar{\\_}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Logic}{False}{\\coqdocinductive{False}}\\coqdoceol\n\\coqdocindent{3.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nNow we can in a straightforward manner define the properties of\northogonality and weak orthogonality.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.orthogonal}{orthogonal}{\\coqdocdefinition{orthogonal}} (\\coqdocvar{$\\mathcal{R}$} :\n\\coqdocdefinition{trs})\n: \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdocdefinition{trs\\_left\\_linear}\n\\coqdocvariable{$\\mathcal{R}$} \\ensuremath{\\land}\n\\ensuremath{\\forall} \\coqdocvar{t$_1$} \\coqdocvar{t$_2$},\n\\ensuremath{\\lnot}\n\\coqref{Rewriting.criticalpair}{\\coqdocdefinition{critical\\_pair}}\n\\coqdocvariable{t$_1$} \\coqdocvariable{t$_2$}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\n\\pagebreak[3]\n\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.weaklyorthogonal}{weakly\\_orthogonal}{\\coqdocdefinition{weakly\\_orthogonal}} (\\coqdocvar{$\\mathcal{R}$} :\n\\coqdocdefinition{trs})\n: \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdocdefinition{trs\\_left\\_linear}\n\\coqdocvariable{$\\mathcal{R}$} \\ensuremath{\\land}\n\\ensuremath{\\forall} \\coqdocvar{t$_1$} \\coqdocvar{t$_2$},\n\\coqref{Rewriting.criticalpair}{\\coqdocdefinition{critical\\_pair}}\n\\coqdocvariable{t$_1$} \\coqdocvariable{t$_2$} \\ensuremath{\\rightarrow}\n\\coqdocvariable{t$_1$} \\coqref{TermEquality.termbis}{$\\bis$} \\coqdocvariable{t$_2$}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nNext we define when a term is a normal form and when we have unique\nnormal forms.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.normalform}{normal\\_form}{\\coqdocdefinition{normal\\_form}}\n\\coqdocvar{t} : \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{\\lnot} \\ensuremath{\\exists} \\coqdocvar{C} : \\coqref{Context.context}{\\coqdocinductive{context}},\n\\ensuremath{\\exists} \\coqdocvar{$\\rho$} : \\coqdocrecord{rule},\n\\ensuremath{\\exists} \\coqdocvar{$\\sigma$} :\n\\coqref{Substitution.substitution}{\\coqdocdefinition{substitution}},\n\\coqdocvariable{$\\rho$}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Lists.List}{In}{\\coqdocdefinition{$\\in$}}\n\\coqdocvar{$\\mathcal{R}$} \\ensuremath{\\land}\n\\coqdocvariable{C}[(\\coqref{Rewriting.lhs}{\\coqdocprojection{lhs}}\n\\coqdocvariable{r})\\coqdocvariable{$^\\sigma$}] \\coqref{TermEquality.termbis}{$\\bis$}\n\\coqdocvariable{t}.\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Rewriting.uniquenormalforms}{unique\\_normal\\_forms}{\\coqdocdefinition{unique\\_normal\\_forms}}\n: \\coqdockw{Prop} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t} \\coqdocvar{u}\n(\\coqdocvar{$\\varphi$} : \\coqdocvariable{s} \\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvariable{t})\n(\\coqdocvar{$\\psi$} : \\coqdocvariable{s} \\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$} \\coqdocvariable{u}),\\coqdoceol\n\\coqdocindent{2.00em}\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} \\coqdocvariable{$\\varphi$}\n\\ensuremath{\\rightarrow}\n\\coqref{Rewriting.wf}{\\coqdocdefinition{wf}} \\coqdocvariable{$\\psi$}\n\\ensuremath{\\rightarrow}\n\\coqref{Rewriting.normalform}{\\coqdocdefinition{normal\\_form}}\n\\coqdocvariable{t} \\ensuremath{\\rightarrow}\n\\coqref{Rewriting.normalform}{\\coqdocdefinition{normal\\_form}}\n\\coqdocvariable{u} \\ensuremath{\\rightarrow}\n\\coqdocvariable{t} \\coqref{TermEquality.termbis}{$\\bis$} \\coqdocvariable{u}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nNote that the\n\\coqref{Rewriting.uniquenormalforms}{\\coqdocdefinition{unique\\_normal\\_forms}}\ndefinition is only a translation of the $UN^\\rewrites$ property, not\nof the more general $UN^\\infty$ property (see also\nDefinition~\\ref{def:normalisation}).\n", "meta": {"hexsha": "00d722f4e8b2d841a6b09cfe3f9d04864099f05b", "size": 73826, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vu/master-project/implementation.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/implementation.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/implementation.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.4313846154, "max_line_length": 171, "alphanum_fraction": 0.7653807602, "num_tokens": 26882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6847621314901646}}
{"text": "%!TEX root = TDT4265-Summary.tex\r\n\\section{Spatial filtering}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Fundamentals of spatial filtering}\r\n\r\n\\subsubsection{Mechanics of spatial filtering}\r\nA spatial filter consists of a neighborhood and an operation performed on the pixels in the neighborhood. A \\emph{linear filter} requires a linear operation, such as summation. Otherwise, it is a \\emph{nonlinear filter}.\r\n\r\n\\subsubsection{Spatial correlation and convolution}\r\nNeighborhood operations where each output pixel is a weighted sum of neighbors to the corresponding input pixel. The weights are stored in a matrix called filter, mask or kernel. Correlation and convolution are the same except for the fact that the filter is rotated $180 \\degree$ for convolution.\r\n\r\nIf the input image is a discrete unit impulse (all zeros except a single `1' value), the output of convolution is the filter itself at the position of the unit impulse. Correlation has the same result, but the output is rotated 180 degrees. Convolution is commutative and associative:\r\n\\begin{gather}\r\n    f \\conv g = g \\conv f \\\\\r\n    f \\conv (g \\conv h) = (f \\conv g) \\conv h\r\n\\end{gather}\r\nHowever, correlation is \\emph{not}.\r\n\r\nBecause of the similarity of the operations, often only \\eqref{eq:corr} is implemented, and the filter is rotated beforehand for convolution.\r\n\r\n\\paragraph{Correlation}\r\n\\begin{equation}\\label{eq:corr}\r\n    w(x,y) \\corr f(x,y)\r\n    =\r\n    \\sum_{s=-a}^{a}\r\n    \\sum_{t=-b}^{b}\r\n    w(s,t) f(x+s, y+t)\r\n\\end{equation}\r\n\r\n\\paragraph{Convolution}\r\n\\begin{equation}\\label{eq:conv}\r\n    w(x,y) \\conv f(x,y)\r\n    =\r\n    \\sum_{s=-a}^{a}\r\n    \\sum_{t=-b}^{b}\r\n    w(s,t) f(x-s, y-t)\r\n\\end{equation}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Smoothing spatial filters}\r\nUsed for blurring and noise reduction. Blurring can e.g. remove small, unwanted details before object detection.\r\n\r\nSmoothing linear filters take an average of pixels under the mask. Also called averaging or lowpass filters. A typical filter is\r\n\\begin{equation}\r\n    \\frac{1}{9}\r\n    \\cdot\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        1 & 1 & 1 \\\\\r\n        1 & 1 & 1 \\\\\r\n        1 & 1 & 1\r\n    \\end{BMAT}\r\n    \\, .\r\n\\end{equation}\r\nSuch filters where all coefficients are equal are called box filters. Another possibility is a weighted average such as\r\n\\begin{equation}\r\n    \\frac{1}{16}\r\n    \\cdot\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        1 & 2 & 1 \\\\\r\n        2 & 4 & 2 \\\\\r\n        1 & 2 & 1\r\n    \\end{BMAT}\r\n    \\, ,\r\n\\end{equation}\r\nwhich can smooth an image with less blurring than a box filter.\r\n\r\n\\subsubsection{Median filter}\r\nA nonlinear filter, good for removing e.g. salt-and-pepper noise. Does not blur sharp edges. Method:\r\n\\begin{enumerate}\r\n    \\item Order pixels in the neighborhood by intensity.\r\n    \\item Replace center pixel with median intensity.\r\n\\end{enumerate}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Sharpening spatial filters}\r\n\r\nJust like smoothing/averaging is analogous to integration, sharpening can be done by differentiation. Some requirements for a sharpening filter based on the first derivative are\r\n\\begin{itemize}\r\n    \\item zero in constant areas,\r\n    \\item nonzero at the onset and end of an intensity ramp, and\r\n    \\item nonzero during an intensity ramp.\r\n\\end{itemize}\r\nRequirements for a secord-order derivative filter are the same, with the difference that it must be zero during ramps. The one-dimensional definitions\r\n\\begin{equation}\r\n\\begin{split}\r\n    \\pd{f}{x}    &= f(x+1) - f(x) \\\\\r\n    \\pd[2]{f}{x} &= f(x+1) + f(x-1) - 2f(x)\r\n\\end{split}\r\n\\end{equation}\r\nsatisfy these requirements.\r\n\r\n\\subsubsection{Image sharpening with the Laplacian}\r\nFor 2D images, sharpening filters can be based on the Laplacian\r\n\\begin{equation}\r\n    \\nabla^2 f = \\pd[2]{f}{x} + \\pd[2]{f}{y} .\r\n\\end{equation}\r\n\r\nSome common filters are:\r\n\\begin{equation}\\label{eq:laplacian-filters}\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        0 &  1 & 0 \\\\\r\n        1 & -4 & 1 \\\\\r\n        0 &  1 & 0\r\n    \\end{BMAT}\r\n    \\quad\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        1 &  1 & 1 \\\\\r\n        1 & -8 & 1 \\\\\r\n        1 &  1 & 1\r\n    \\end{BMAT}\r\n    \\quad\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n         0 & -1 &  0 \\\\\r\n        -1 &  4 & -1 \\\\\r\n         0 & -1 &  0\r\n    \\end{BMAT}\r\n    \\quad\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        -1 & -1 & -1 \\\\\r\n        -1 &  8 & -1 \\\\\r\n        -1 & -1 & -1\r\n    \\end{BMAT}\r\n\\end{equation}\r\n\r\nThe sharpened image is obtained by taking the sum of the original and the filtered image:\r\n\\begin{equation}\r\n    g(x,y) = f(x,y) + c [\\nabla^2 f(x,y)]\r\n\\end{equation}\r\nwhere $c$ is $-1$ if the center element of the filter is negative, and $1$ otherwise.\r\n\r\n\\subsubsection{Unsharp masking and highboost filtering}\\label{sssec:unsharp-highboost-spatial}\r\nUnsharp masking sort of goes in the opposite direction of Laplacian sharpening: First blur the image, and subtract the blurred from the original to get a an unsharp mask $g\\sub{mask}(x,y) = f(x,y) - \\overline{f}(x,y)$. Finally add the mask to the original:\r\n\\begin{equation}\\label{eq:unsharp-masking}\r\n    g(x,y) = f(x,y) + k \\cdot g\\sub{mask}(x,y)\r\n\\end{equation}\r\nUnsharp masking is strictly speaking only for $k = 1$. With $k > 1$, we have highboost filtering, and you can also lessen the effect with $k < 1$. The result is a sharpened image, because you remove unsharpness, which increases corner contrast.\r\n\r\n\\subsubsection{Image sharpening with the Gradient}\r\nSection \\ref{sssec:edge-detection} defines the gradient. Its magnitude\r\n\\begin{equation}\r\n    M(x,y) = \\sqrt{g_x^2 + g_y^2} \\approx \\abs{g_x} + \\abs{g_y}\r\n\\end{equation}\r\nforms a gradient magnitude image. An example of masks that approximate this is the Sobel operator \\eqref{eq:sobel}.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection[Combining methods]{Combining spatial enhancement methods}\r\nIn the real world, you need to use several methods to solve a task. One example is to first sharpen the image, then enhance the dynamic range.\r\n", "meta": {"hexsha": "d2d49074c2a153809f8f4852cf941c29603c563d", "size": 6126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TDT4265 Computer vision/03b-spatial-filtering.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/03b-spatial-filtering.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/03b-spatial-filtering.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": 41.1140939597, "max_line_length": 298, "alphanum_fraction": 0.6377734247, "num_tokens": 1789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6847621268899745}}
{"text": "\\chapter{Eigenfunctions of DT systems}\nTo summarize the course so far for DT analysis, given an input signal $x[n]$ and a LTI system described (equivalently) by a linear, constant coefficient difference equation, impulse response, or a block diagram, we can determine the output using convolution. This is referred to as \\emph{discrete time-domain} analysis since the index $n$ usually refers to a time index.\n\nLike in CT, the advantages of this approach are that the analysis is straightforward and applies to all LTI systems, stable or otherwise. Discrete time-domain representations of signals are also intuitive when viewed as equally-spaced samples of physical signals.\n\nAs in CT, there are disadvantages. It does not scale well to larger systems since analysis with block diagram decompositions requires convolution, and in the case of the feedback motif dealing with inverse systems or de-convolution. It is difficult to design an impulse responses for a given purpose. Finally implementing a DT system directly from an impulse response is not intuitive.\n\nSimilar to CT we can transform the domain of the signal representations to one in which the operation of DT convolution becomes one of multiplication.\n\n\\section{The Response of DT LTI Systems to Complex Exponentials}\n\nRecall convolution can be viewed as a decomposition of a signal into an infinite sum of $\\delta$ functions plus the linearity property.\n\\[\nx[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x[m]\\delta[n-m] \\;\\longrightarrow\\; y[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x[m]h[n-m]\n\\]  \nWe now consider a different decomposition based on the complex exponential, $z^n$ for $z \\in \\mathbb{C}$, rather than $\\delta$ functions. As we will see this decomposition simplifies convolution, turning it into multiplication.\n\n\\subsection{Eigenfunction $z^n$ and Transfer Function $H(z)$}\n\nLet $x[n] = z^n$ for $z\\in \\mathbb{C}$, then $y[n] = h[n] * x[n] = x[n] * h[n]$ and by the definition of DT convolution\n\\begin{align*}\n  y[n] & = \\sum\\limits_{m = -\\infty}^{\\infty}h[m]x[n-m]\\\\\n  &= \\sum\\limits_{m = -\\infty}^{\\infty}h[m]z^{n-m} = \\sum\\limits_{m = -\\infty}^{\\infty}h[m]z^{n}z^{-m}\\\\\n  &= z^{n} \\sum\\limits_{m = -\\infty}^{\\infty}h[m]z^{-m}\\\\\n  &= z^{n}H(z)\n\\end{align*}\nwhere $H(z) = \\sum\\limits_{m = -\\infty}^{\\infty}h[m]z^{-m}$ is the \\emph{Z Transform} of the impulse response, $h[n]$. $H(z)$ is called the \\emph{transfer function} or \\emph{Eigenvalue} of the system and $z^{n}$ is the \\emph{Eigenfunction} for DT LTI systems.\n\nSimilar to the impulse function, the complex exponential is a special signal because it's response is easy to determine. It is just the same signal scaled by a multiplicative factor as illustrated below:\n\n\\begin{center}\n  \\includegraphics[scale=0.6]{graphics/lti-dt-complex-exp.pdf}\n\\end{center}\n\n\\begin{example}\n  For example, suppose $H(z) = \\frac{z}{z-\\frac{1}{2}}$ and $x[n] = \\left(-\\frac{1}{4}\\right)^n$. Then the output is\n  \\begin{align*}\n    y[n] &= H\\left(-\\frac{1}{4}\\right)\\left(-\\frac{1}{4}\\right)^n\\\\\n    &= \\frac{-\\frac{1}{4}}{-\\frac{1}{4}-\\frac{1}{2}}\\left(-\\frac{1}{4}\\right)^n\\\\\n    &= \\frac{1}{3}\\left(-\\frac{1}{4}\\right)^n \\; ,\n  \\end{align*}\nanother complex exponential.\\\\\n$\\blacksquare$\n\\end{example}\n\nGiven $H(z)$ and inputs that are sums of complex exponentials, the output is easy to determine.\n\n\\begin{center}\n  \\includegraphics[scale=0.6]{graphics/dt-linear-response-complex-exp.pdf}\n\\end{center}\nIn some cases the sums are countably infinite while in others the uncountably infinite so that the sums become integrals.\n\n\\begin{example} Consider the DT system with impulse response response\n  \\[\n  h[n] = \\left(\\frac{3}{4}\\right)^{n}u[n]\n  \\]\n  Determine the Eigenvalues that corresponds to the input $x[n] = \\cos(n)$ and the output $y[n]$.\\\\\n\n  Solution: We note the cosine can be decomposed into two complex exponentials as\n  \\[\n  \\cos(n) = \\frac{1}{2}e^{jn} + \\frac{1}{2}e^{-jn} = \\frac{1}{2}\\left(e^{j}\\right)^n + \\frac{1}{2}\\left(e^{-j}\\right)^n\n  \\]\n  Thus in terms of the general decomposition there are two terms with complex constants $z_1 = e^{j}$ and $z_2 = e^{-j}$ and real constants $a_1 = a_2 = \\frac{1}{2}$.\n  \\[\n   x[n] = \\sum_i a_i z_i^{n} = a_1 z_1^{n} + a_2 z_2^{n} = \\frac{1}{2}\\left(e^{j}\\right)^n + \\frac{1}{2}\\left(e^{-j}\\right)^n = \\cos(n)\n   \\]\n   Then the output is given by\n   \\[\n   y[n] = \\sum_i H(z_i) a_i z_i^{n} = H(z_1) a_1 z_1^{n} + H(z_2) a_2 z_2^{n} = H\\left(e^{j}\\right)\\frac{1}{2}\\left(e^{j}\\right)^n + H\\left(e^{-j}\\right)\\frac{1}{2}\\left(e^{-j}\\right)^n \n   \\]\n   which requires we find the Eigenvalues $H\\left(e^{j}\\right)$ and $H\\left(e^{-j}\\right)$. To do so we use the Z transform summation\n   \\[\n   H\\left(e^{j}\\right) = \\sum\\limits_{m = -\\infty}^{\\infty}h[m]\\left(e^{j}\\right)^{-m} = \\sum\\limits_{m = 0}^{\\infty} \\left(\\frac{3}{4}\\right)^{m}\\left(e^{j}\\right)^{-m} = \\sum\\limits_{m =0}^{\\infty} \\left(\\frac{3}{4\\left(e^{j}\\right)}\\right)^{m} = \\frac{-1}{\\left(\\frac{3}{4e^{j}}\\right)-1} = \\frac{e^{j}}{e^{j}-\\left(\\frac{3}{4}\\right)}\n   \\]\n   Similarly\n   \\[\n   H\\left(e^{-j}\\right) = \\sum\\limits_{m = -\\infty}^{\\infty}h[m]\\left(e^{-j}\\right)^{-m} = \\sum\\limits_{m = 0}^{\\infty} \\left(\\frac{3}{4}\\right)^{m}\\left(e^{-j}\\right)^{-m} = \\sum\\limits_{m =0}^{\\infty} \\left(\\frac{3}{4\\left(e^{-j}\\right)}\\right)^{m} = \\frac{-1}{\\left(\\frac{3}{4e^{-j}}\\right)-1} = \\frac{e^{-j}}{e^{-j}-\\left(\\frac{3}{4}\\right)}\n   \\]\n\n   Substituting back into the output equation gives\n   \n   \\begin{align*}\n     y[n] &= H\\left(e^{j}\\right)\\frac{1}{2}\\left(e^{j}\\right)^n + H\\left(e^{-j}\\right)\\frac{1}{2}\\left(e^{-j}\\right)^n\\\\\n     &= \\frac{e^{j}}{e^{j}-\\left(\\frac{3}{4}\\right)}\\frac{1}{2}\\left(e^{j}\\right)^n + \\frac{e^{-j}}{e^{-j}-\\left(\\frac{3}{4}\\right)}\\frac{1}{2}\\left(e^{-j}\\right)^n\\\\\n   \\end{align*}\n   We can simplify this expression using the polar form of the Eigenvalues\n   \\begin{align*}\n     y[n] &= \\frac{e^{j}}{e^{j}-\\left(\\frac{3}{4}\\right)}\\frac{1}{2}\\left(e^{j}\\right)^n + \\frac{e^{-j}}{e^{-j}-\\left(\\frac{3}{4}\\right)}\\frac{1}{2}\\left(e^{-j}\\right)^n\\\\\n     &= Re^{j\\theta} \\frac{1}{2}e^{jn} + Re^{-j\\theta} \\frac{1}{2}e^{-jn}\\\\\n     &= R \\frac{1}{2}e^{jn + j\\theta} + R \\frac{1}{2}e^{-jn -j\\theta}\\\\\n     &= R\\cos(n + \\theta)\n   \\end{align*}\n   where\n   \\[\n   R = \\left|\\frac{e^{j}}{e^{j}-\\left(\\frac{3}{4}\\right)}\\right| \\approx 1.153  \\mbox{ and } \\theta = \\angle{\\frac{e^{j}}{e^{j}-\\left(\\frac{3}{4}\\right)}} \\approx -0.815\n   \\]\n   Note for this system, given a sinusoidal input, the output is a scaled and phase shifted sinusoid at the same frequency, where the scaling factor and phase shift is system dependent. It is illustrative to compare this analysis to the time-domain analysis of the same impulse response and input using convolution.\n   $\\blacksquare$\n\\end{example}\n\n\\section{Decomposition of signals using DT complex exponentials}\n\nSimilar to CT, in this course we consider the cases of stable DT systems. Recall a stable system is one in which a bounded input leads to a bounded output, or equivalently the impulse response is absolutely summable. We will consider two decompositions of the input:\n\n  \\begin{itemize}\n  \\item \\emph{Fourier Series}: When $x[n]$ is periodic with fundamental frequency $\\omega_0 = \\frac{2\\pi}{N}$, $|z| = 1$ so that $z = e^{jk\\omega_0}$, and the decomposition is a finite sum. This gives the input-output relationship\n    \\[\n x[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n} \\;\\longrightarrow\\;  y[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} H\\left(e^{j k\\omega_0}\\right) a_k e^{jk\\omega_0 n} \n    \\]\n    where $H\\left(e^{j k\\omega_0}\\right)$ are the Eigenvalues, also called the DT \\emph{frequency response}.\n  \\item \\emph{Inverse Fourier Transform}: When $x[n]$ is a-periodic, $|z| = 1$ so that $z = e^{j\\omega}$, and the decomposition is an integral over a finite length set. This gives the input-output relationship\n    \\[\n     x[n] = \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega \\;\\longrightarrow\\;   y[n] = \\frac{1}{2\\pi} \\int_{2\\pi} H\\left(e^{j\\omega}\\right) \\, X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega\n    \\]\n    where $H\\left(e^{j \\omega}\\right)$ are the Eigenvalues, again called the DT \\emph{frequency response}.  \n  \\end{itemize}\n\n  Other courses such as ECE 3704 look at the general case of unstable systems and $z \\in \\mathbb{C}$ with decompositions:\n\n  \\begin{itemize}\n  \\item \\emph{One-Sided Z Transform}: $x[n]$ is causal and the decomposition is an uncountably infinite sum (complex integral)\n  \\item \\emph{Two-Sided (Bilateral) Z Transform}: $x[n]$ is non-causal and the decomposition is an uncountably infinite sum (complex integral). This is the most general case for DT LTI systems.\n  \\end{itemize}\n\n  While the Z decompositions require complex integration, like for the Laplace transform in CT, they can be understood and computed using algebra and a table of forward transforms, which only require summations of a complex function over a real variable $n$ (this is the general approach taken in upper level courses). However, this is outside the scope of this course because of time limitations.\n\nInstead, we will be spending the next few weeks going through the DT Fourier decompositions in some detail. You will also learn how to find the DT frequency response for a stable system, and see how to use both for analysis.\n\n", "meta": {"hexsha": "1fb4337468f290ac2eda722d1d5f479f19a58e1e", "size": 9311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13-dt-tf.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "13-dt-tf.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "13-dt-tf.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 72.1782945736, "max_line_length": 397, "alphanum_fraction": 0.6715712598, "num_tokens": 3074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8633916170039421, "lm_q1q2_score": 0.6847610296482999}}
{"text": "\\subsection{Higher Order Derivatives}\r\n\\begin{definition}\r\n\tLet $n$ be a positive integer. The $n^{th}$ derivative of $f$ is\r\n\t\\begin{equation*}\r\n\t\tf^{(n)}(x) = \\dd{}{x}{f^{(n-1)}}(x),\r\n\t\\end{equation*}\r\n\twhere $f^{(n-1)}(x)$ is the ${n-1}^{th}$ derivative of $f$.\r\n\tUsing equivalent notation,\r\n\t\\begin{equation*}\r\n\t\t\\dd{{}^n}{x^n}f = \\dd{{}^{n-1}}{x^{n-1}}f.\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tFind the third derivative of $f(x) = x^3 + x^2$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tTaking the derivative once using the power rule and sum and difference rule,\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(x) = 3x^2 + 2x.\r\n\t\\end{equation*}\r\n\t\r\n\tTaking the derivative a second time using the power, constant multiple rules, and sum and difference rules,\r\n\t\\begin{equation*}\r\n\t\tf^{\\prime\\prime}(x) = 6x + 2.\r\n\t\\end{equation*}\r\n\t\r\n\tTaking the derivative a final time using the power, constant multiple, constant, and sum and difference rules,\r\n\t\\begin{equation*}\r\n\t\tf^{\\prime\\prime\\prime}(x) = 6.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "88a3248750208e74fe55787d71b6cee6e4726980", "size": 1027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/higher_order_derivatives.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/derivatives/derivative_rules/higher_order_derivatives.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/derivatives/derivative_rules/higher_order_derivatives.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": 32.09375, "max_line_length": 112, "alphanum_fraction": 0.6416747809, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6846591614563097}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\chapter{The stability criterion for community detection} \\label{chap:clustering}\n% \\section{The stability criterion for graph communities} \\label{sec:stability}\nThe partition of a graph into communities (or clusters) has been widely studied those last two decades. Clustering comes indeed pretty handy to gain insight into the underlying structure of a system represented by a network. In some cases one can even build a simplified functional description of the system based on the clusters. Many partitioning methods have been proposed, each relying on a particular measure to quantify the quality of a community structure. Such methods include normalized cut, ($\\alpha$,$\\epsilon$) clustering or modularity and its variants and extensions. The reader may refer to \\cite{fortunato2010community} for a 2010 survey of the different clustering methods. In this work, we choose the stability approach, which is based on the statistical properties of a dynamical process taking place on the network. This approach was initially presented in \\cite{delvenne2010stability} and further expended in \\cite{lambiotte2009laplacian} and \\cite{delvenne2013stability}. \n\nThe stability method presents a number of advantages. First, it does not require the number of communities to be specified beforehand, ensuring a natural partitioning of the graph. Second, it is flexible in the sense that it does not seek a \\textit{unique} optimal partition. Instead, it reveals several community structures, each appearing to be the most relevant at particular values of the Markov time: at a given time scale, natural clusters corresponds to sets of states from which escape is unlikely within that time scale. The stability method provides thus a dynamical interpretation of the partitioning problem. The Markov time acts as an intrinsic resolution parameter, as will be developed shortly. Finally, it is probably the most unifying approach since many of the standard partitioning measures find an interpretation through the stability framework.\n\nIn order to compute stability partitions in the next of this work, we make use of Michael Schaub's free software \\textit{PartitionStability}. This C++ implementation of the stability method with a \\matlab interface is available at \\url{https://github.com/michaelschaub/PartitionStability}. It relies on the Louvain algorithm \\cite{blondel2008fast} to optimize the stability quality function. This heuristic algorithm has been initially developed for modularity optimization. However one can show that stability can be written as the \\textit{modularity} of a time-dependent network evolving under the Markov process \\cite{lambiotte2009laplacian}. Hence, the Louvain method can almost straightforwardly be applied to stability optimization.\n\nThis chapter is devoted to the explanation of the stability measure, and how to find good clusterings using stability analysis. It acts as a theoretical part intended to cover everything that is needed to make a proper, informed use of the stability toolbox. Notice that the stability measure has initially been presented for discrete times in \\cite{delvenne2010stability}. We follow the same approach here: discrete-time stability is developed in the first section of this chapter; it is then extended to continuous time in a second section; finally, a few tools to analyze the robustness of a partition are presented in the third section of the chapter.\n\\input{inputs/clustering/discretetime}\n\\input{inputs/clustering/continuoustime}\n\\input{inputs/clustering/robustness}", "meta": {"hexsha": "98f6e02f6775e5930af9ffd9a8a6bc5f78c3976b", "size": 3594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/clustering/clustering.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/clustering/clustering.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/clustering/clustering.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": 276.4615384615, "max_line_length": 993, "alphanum_fraction": 0.8219254313, "num_tokens": 747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.6846591612209525}}
{"text": "\\subsection{Maximum Entropy approximation}\\label{sec_maxent}\n\nHaving numerically computed the moments of the mRNA and protein distributions\nas cells progress through the cell cycle, we now proceed to make an\napproximate reconstruction of the full distributions given this limited\ninformation. As hinted in \\secref{sec_moments} the maximum entropy principle,\nfirst proposed by E.T. Jaynes in 1957 \\cite{Jaynes1957}, approximates the\nentire distribution by maximizing the Shannon entropy subject to constraints\ngiven by the values of the moments of the distribution \\cite{Jaynes1957}. This\nprocedure leads to a probability distribution of the form (See\n\\siref{supp_maxent} for full derivation)\n\\begin{equation}\n  P(m, p) = {1 \\over \\mathcal{Z}}\n              \\exp \\left( - \\sum_{(x,y)} \\lambda_{(x,y)} m^x p^y \\right),\n  \\label{eq_maxEnt_joint}\n\\end{equation}\nwhere $\\lambda_{(x,y)}$ is the Lagrange multiplier associated with the\nconstraint set by the moment $\\ee{m^x p^y}$, and $\\mathcal{Z}$ is a\nnormalization constant. The more moments $\\ee{m^x p^y}$ included as\nconstraints, the more accurate the approximation resulting from\n\\eref{eq_maxEnt_joint} becomes.\n\nThe computational challenge then becomes an optimization routine in which the\nvalues for the Lagrange multipliers $\\lambda_{(x,y)}$ that are consistent with\nthe constraints set by the moment values $\\ee{m^x p^y}$ need to be found. This\nis computationally more efficient than sampling directly out of the master\nequation with a stochastic algorithm (see \\siref{supp_gillespie} for further\ncomparison between maximum entropy estimates and the Gillespie algorithm).\n\\siref{supp_maxent} details our implementation of a robust algorithm to find\nthe values of the Lagrange multipliers. \\fref{fig4_maxent}(A) shows example\npredicted protein distributions reconstructed using the first six moments of\nthe protein distribution for a suite of different biophysical parameters and\nenvironmental inducer concentrations. As repressor-DNA binding affinity\n(columns in \\fref{fig4_maxent}(A)) and repressor copy number (rows in\n\\fref{fig4_maxent}(A)) are varied, the responses to different signals, i.e.\ninducer concentrations, overlap to varying degrees. For example, the upper\nright corner frame with a weak binding site ($\\eR = -9.7 \\; k_BT$) and a low\nrepressor copy number (22 repressors per cell) have virtually identical\ndistributions regardless of the input inducer concentration. This means that\ncells with this set of parameters cannot resolve any difference in the\nconcentration of the signal. As the number of repressors is increased, the\ndegree of overlap between distributions decreases, allowing cells to better\nresolve the value of the signal input. On the opposite extreme the lower left\npanel shows a strong binding site ($\\eR = -15.3 \\; k_BT$) and a high repressor\ncopy number (1740 repressors per cell). This parameter combination shows\noverlap between distributions since the high degree of repression centers all\ndistributions towards lower copy numbers, again giving little ability for the\ncells to resolve the inputs. In \\fref{fig4_maxent}(B) and \\siref{supp_maxent}\nwe show the comparison of these predicted cumulative distributions with the\nexperimental single-cell fluorescence distributions. Given the systematic\ndeviation of our predictions for the protein copy number noise highlighted in\n\\fref{fig3_cell_cycle}(C), the theoretical distributions (dashed lines)\nunderestimate the width of the experimental data. We again direct the reader to\n\\siref{supp_empirical} for an exploration of empirical changes to the moments\nthat improve the agreement of the predictions. In the following section we\nformalize the notion of how well cells can resolve different inputs from an\ninformation theoretic perspective via the channel capacity.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics\n  {./fig/main/fig4_maxent.pdf}\n\t\\caption{\\textbf{Maximum entropy protein distributions for varying physical\n\tparameters.} (A) Predicted protein distributions under different inducer\n\t(IPTG) concentrations for different combinations of repressor-DNA\n\taffinities (columns) and repressor copy numbers (rows). The first six\n\tmoments of the protein distribution used to constrain the maximum entropy\n\tapproximation were computed by integrating \\eref{eq_gral_mom} as cells\n\tprogressed through the cell cycle as described in \\secref{sec_cell_cycle}.\n\t(B) Theory-experiment comparison of predicted fold-change empirical\n\tcumulative distribution functions (ECDF). Each panel shows two example\n\tconcentrations of inducer (colored curves) with their corresponding\n\ttheoretical predictions (dashed lines). Distributions were normalized to the\n\tmean expression value of the unregulated strain in order to compare\n\ttheoretical predictions in discrete protein counts with experimental\n\tfluorescent measurements in arbitrary units.}\n  \\label{fig4_maxent}\n\\end{figure}\n", "meta": {"hexsha": "b468c8c29721e599ae28bbb08951a076cf9649d8", "size": 4907, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/section_04_maxent.tex", "max_stars_repo_name": "RPGroup-PBoC/chann_cap", "max_stars_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-21T04:06:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T07:36:58.000Z", "max_issues_repo_path": "doc/section_04_maxent.tex", "max_issues_repo_name": "RPGroup-PBoC/chann_cap", "max_issues_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/section_04_maxent.tex", "max_forks_repo_name": "RPGroup-PBoC/chann_cap", "max_forks_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-29T17:43:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-09T00:20:16.000Z", "avg_line_length": 62.9102564103, "max_line_length": 79, "alphanum_fraction": 0.8066028123, "num_tokens": 1139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6846591580834337}}
{"text": "\\chapter{Decomposition}\r\n\\section{Direct Decomposition}\r\nFirst, see some examples of \\textit{direct decomposition} of a vector space.\r\n\\begin{remind}[direct sum] Call $W_i$'s are \\textbf{independent} and denote $$\\bigoplus W_i = \\sum W_i$$ if for every vector in $\\sum W_i$ the coordinate representation of it is unique.\r\n\\end{remind}\r\n\r\nIt is obvious that $W_i$'s are \\textbf{independent} iff $\\mathfrak B = (\\mathfrak B_i)$ is an ordered basis for $\\sum W_i$ where each $\\mathfrak B_i$ is one for $W_i$.\r\n\r\n\\begin{remind}[projection, or idempotent] One such that $E^2 = E$.\r\n\\end{remind}\r\nWe have $V = \\ker E \\oplus \\operatorname{im} E.$ And $E$ is trivially diagonalizable with $$[E]_\\mathfrak B = \\begin{pmatrix}I & \\mathbf 0 \\\\  \\mathbf 0 &  \\mathbf 0 \\end{pmatrix}$$ where $\\mathfrak B = (\\text{basis for }\\operatorname{im} E,~\\text{basis for }\\operatorname{ker} E).$\r\n\r\n\\begin{theorem}If $V = \\bigoplus W_i$, then there exist projections $E_i$ such that:\r\n\\begin{itemize}\r\n\\item $E_i E_j = 0$ if $i\\ne j$,\r\n\\item $I = \\sum E_i$,\r\n\\item $\\operatorname{im} E_i = W_i.$\r\n\\end{itemize}\r\nConversely, if there are projections $E_i$ which satisfy above two from the top and let $\\operatorname{im} E_i =: W_i$, then $V = \\bigoplus W_i.$\r\n\\end{theorem}\r\n\\begin{proof}($\\Longrightarrow$) Take $$E_j:~\\bigoplus W_i\\xrightarrow[projection]{canonical} W_j.$$\r\n\r\n($\\Longleftarrow$) Obvious. (Find the unique coordinate representation of a vector.)\r\n\\end{proof}\r\n\r\nSuppose each of $W_i$ is invariant under $T$, then $T_i = T\\upharpoonright _{W_i}$ is a linear operator on $W_i$, and $$Tv = \\sum T_i v_i$$ if $v = \\sum v_i$ is the unique coordinate representation with $v_i \\in W_i.$ We says that $T$ is the direct sum of $T_i$'s. If the basis is given by $\\mathfrak B = (\\mathfrak B_i)$ where each $\\mathfrak B_i$ is one for $W_i$, then $[T]_{\\mathfrak B}^{\\mathfrak B} $ is a form of block diagonal matrix: $$[T]_{\\mathfrak B}^{\\mathfrak B} = \\begin{pmatrix}\r\n[T_1]_{\\mathfrak B_1}^{\\mathfrak B_1} & \\mathbf 0 & \\cdots & \\mathbf 0 \\\\\r\n\\mathbf 0 & [T_2]_{\\mathfrak B_2}^{\\mathfrak B_2} & \\cdots & \\mathbf 0 \\\\\r\n\\vdots  & \\vdots & \\ddots & \\vdots  \\\\\r\n\\mathbf 0  & \\mathbf 0  & \\cdots& [T_k]_{\\mathfrak B_k}^{\\mathfrak B_k} \\\\\r\n\\end{pmatrix}. $$ Hence for matrices, $A$ is the direct sum of $A_i$'s if $A = \\operatorname{diag}(A_1,\\cdots,A_k)$ where diag denotes the block diagonal.\r\n\r\n\r\n\\begin{theorem}Let $V=\\bigoplus W_i$ and $E_i$'s be canonical projections. Then $W_i$'s are all invariant under $T$ iff $T$ commutes with each of $E_i$'s.\r\n\\end{theorem}\r\n\\begin{proof}($\\Longrightarrow$) Let $v=\\sum v_i$, then $$ E_j Tv = E_j \\sum T_i v_i = E_j T_jv_j = T_j v_j =  T v_j = T E_j v.$$\r\n\r\n($\\Longleftarrow$) $$TW_i = TE_iV = E_i TV \\le E_i V = W_i.$$\r\n\\end{proof}\r\n\r\nSimilar procedure can be adopted to the eigenspace decomposition $V = \\bigoplus E_{\\lambda_i}$:\r\n\r\n\\begin{theorem}Let $T$ be a diagonalizable operator(hence there is the eigenspace decomposition of $V$ w.r.t. $T$), then there exist projections $D_i$ such that:\r\n\\begin{itemize}\r\n\\item $T = \\sum \\lambda_i D_i$,\r\n\\item $I = \\sum D_i$,\r\n\\item $D_i D_j = 0$ if $i\\ne j$,\r\n\\item $\\operatorname{im} D_i = E_{\\lambda_i}.$\r\n\\end{itemize}\r\nConversely, if there are distinct scalars $\\lambda_i$ and nonzero operators $D_i$ which satisfy above three from the top, then $T$ is diagonalizable, $\\lambda_i$'s are eigenvalues, and $D_i$'s are projections satisfy $\\operatorname{im} D_i = E_{\\lambda_i}.$\r\n\\end{theorem}\r\n\\begin{proof}TOTALLY SAME PROCEDURE. Omit.\\end{proof}\r\n\r\nHence, if $T = \\sum \\lambda_i D_i$, then for any polynomial $g$, $$g(T) = \\sum g(\\lambda_i)D_i.$$ And we obtain $$T^r = \\left( \\sum \\lambda_i D_i\\right)^r =  \\sum \\lambda_i^r D_i ,$$ since all of heterogeneous terms disappear. From this formulation, we have $$g(T) = 0 \\Longleftrightarrow \\forall i ~ g(\\lambda_i) = 0,$$ which means $m_T(t) = \\prod (t -\\lambda_i).$\r\n\r\nNote that, if $p_j(t) = \\prod_{i\\ne j} \\frac{t-\\lambda_i}{\\lambda_j - \\lambda_i}$, we have $p_j(\\lambda_i) = \\delta_{ij}$ whence $$p_j(T) =p_j \\left(\\sum \\lambda_i D_i \\right) = \\sum \\delta_{ij} D_i= D_j.$$ (Hence $D_j$'s not only commute with $T$ but every polynomials in $T$.) \r\n\r\nIn fact, we have $$g(t) = \\sum g(\\lambda_i)p_j(t).$$ Plugging $g=1$ and $g=t$,\r\n$$1 = \\sum p_i,\\qquad t = \\sum \\lambda_i p_i.$$(Except $k=1$. In this case $T$ is trivially diagonalizable.) Evaluating $T$ and using above formulae, $$I = \\sum D_i,\\qquad T = \\sum \\lambda_i D_i.$$ Observe that if $i\\ne j$, then $p|p_i p_j$ whence $D_iD_j = 0.$ And $p_i(T)\\ne 0$ since $\\operatorname{deg} p_i < \\operatorname{deg}p.$ Applying to above theorem, we just proved the sufficient-necessary condition of diagonalizability with another method.\r\n\r\n\\section{Primary Decomposition}\r\nIt is a generalization of what we did above.\r\n\\begin{theorem}Let $T$ be a linear operator on $V$, and factorize $$m_T(t) = \\prod_{i=1}^k p_i(t)^{r_i},$$where $p_i$'s are distince irreducible monic polynomials. Let $W_i = \\ker p_i(T)^{r_i}$, then:\r\n\\begin{itemize}\r\n\\item $V = \\bigoplus W_i$,\r\n\\item $TW_i \\le W_i$,\r\n\\item letting $T_i = T\\upharpoonright _{W_i}$, $m_{T_i}(t) = p_{i}(t)^{r_i}.$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "3221b7da4613e8a2e4917d780f810221f3a0cefc", "size": 5184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "decomposition.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": "decomposition.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": "decomposition.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": 67.3246753247, "max_line_length": 495, "alphanum_fraction": 0.6738040123, "num_tokens": 1852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.684659154436264}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{natbib,amsfonts,graphics,amsmath}\n\\usepackage{graphicx}\n\n\\include{newcommands}\n\n\\begin{document}\n\t\n\t\\title{Scaling the lee wave equations including rotation}\n\t\n\t\\author{Oliver Fringer and Eric Mayer}\n\t\n\t\\maketitle\n\n\\section{Including Rotation}\nIncluding rotation in the nondimensional equations requires only slight modification. Because rotational effects necessarily involve a span wise direction, we must now include an equation for the span wise momentum. \n\nWe begin by positing that the background currents are in geostrophic balance\n\\begin{eqnarray*}\n\t0 &=& -\\D{P_G}{x} + fV \\,,\\\\\n\t0 &=& -\\D{P_G}{y} - fU \\,,\\\\\n\\end{eqnarray*}\nwhere $P_G$ is a geostrophic pressure field that is decoupled from the perturbation pressure due the lee wave. It is analogous to $P$ in the irrotational equations above.\n\t\n\nTo keep the system as simple as possible, we further assume: it is in steady state; the bathymytery varies only in the $x$-direction; and rotation has a constant rate $f=\\Omega sin(\\bar{\\phi})$, where $\\Omega$ is the earth's rate of rotation, and $\\bar{\\phi}$ is the average lattitude of the domain. The assumption of steady state filters out inertial oscillations, and may be invalid in regions of the ocean where rotation is strong, such as the ACC ~\\citep{Nikurashin2010a}. However, in regions closer to the equator, such as Palau, this assumption is quite good, as the following scaling analysis will demonstrate.  In combination, these three assumptions allow us to neglect all span wise gradients in the perturbation fields because the hill only perturbs the flow in the $x$-direction, there are no inertial oscillations to deflect the flow from its hill-perturbed state, and rotation remains constant at all locations in the domain. Thus, again making the Boussinesq approximation, the steady momentum and density transport equations that include (some representation of) rotation are given by\n\n\\begin{eqnarray*}\nU \\D{u'}{x} +u' \\D{u'}{x} + w' \\D{u'}{z} &=& -\\D{p'}{x} + fv' \\,,\\\\\nU \\D{v'}{x} + u' \\D{v'}{x} + w' \\D{v'}{z} &=& - fu' \\,,\\\\\nU \\D{w'}{x} + u' \\D{w'}{x} + w' \\D{w'}{z} &=& -\\D{p}{z} - \\frac{\\rho}{\\rho_0} g \\,,\\\\\nU \\D{\\rho'}{x} + u' \\D{\\rho'}{x} + w' \\D{\\rho'}{z} &=& \\frac{\\rho_0 N^2}{g} w\\,,\n\\end{eqnarray*}\nwhere $N^2 = -g/\\rho_0 \\partial\\rhobar/\\partial z$, subject to continuity $\\nabla\\cdot\\ub'=0$, and\nthe kinematic bottom boundary condition\n\\[\nU\\D{h}{x} + u' \\D{h}{x} = w'\\,.\n\\]  \n\nNondimensionalize with\n\\begin{eqnarray*}\n\tu' &=& u_0 u^*\\,,\\\\\n\tv' &=& v_0 v^*\\,,\\\\\n\tw' &=& w_0 w^*\\,,\\\\\n\t\\rho' &=& R \\rho^*\\,,\\\\\n\tp' &=& P p^*\\,,\\\\\n\tx &=& k^{-1} x^*\\,,\\\\\n\tz &=& \\delta z^*\\,.\n\\end{eqnarray*}\n\nNondimensionalizing as above, with the addition of $v = u_0v*$, the $u$-momentum equation becomes (after ignoring the *)\n\\begin{eqnarray*}\nk u_0 U \\D{u}{x} + k u_0^2\\ub\\cdot\\nabla u  &=& -k P \\D{p}{x} + fu_0v\\,.\n\\end{eqnarray*}\nAgain, requiring a first order balance between linear advection and pressure gives\n\\begin{eqnarray*}\n\\D{u}{x} + J\\ub\\cdot\\nabla u  &=& \\D{p}{x} +Ro^{-1} \\ v \\,,\n\\end{eqnarray*}\nwhere $Ro =  \\frac{Uk}{f}$.\nNondimensionalizing the $v$-momentum equations, we have\n\\begin{eqnarray*}\nk u_0 U  \\D{v}{x} +k u_0^2 \\ub\\cdot\\nabla v &=& -k P\\D{p}{y} - fu_0fu \\,.\n\\end{eqnarray*}\nUpon again requiring a balance of linear advection and pressure, this becomes\n\\begin{eqnarray*}\n\t\\D{v}{x} + J\\ub\\cdot\\nabla v  &=& \\D{p}{y} - Ro^{-1} \\ u \\,.\n\\end{eqnarray*}\nNondimensionalizing the $w$-momentum equations with the scaling $w_0 = Uk h_0$ that we gleaned from the bottom boundary condition gives\n\\[\nk^2 h_0 U^2 \\D{w}{x} + k^2 h_0 u_0^2\\ub\\cdot\\nabla w = -\\frac{P}{\\delta}\\D{p}{z} - \\frac{g R}{\\rho_0} \\rho \\,.\n\\]\nRequiring hydrostatic balance, as before, we have\n\\[\n\\epsilon^2 \\left(\\D{w}{x} + F\\ub\\cdot\\nabla w\\right) = -\\D{p}{z} - \\rho \\,.\n\\]\nAnd recalling $\\delta = U/N$, this simplifies to \n\\[\n\\epsilon^2 \\left(\\D{w}{x} + F\\ub\\cdot\\nabla w\\right) = -\\D{p}{z} - \\rho\\,.\n\\]\nLastly, the nondimensional density transport equation is\n\\[\nk U R \\D{\\rho}{x} + k u_0 R \\ub\\cdot\\nabla\\rho = \\frac{k \\rho_0 h_0 N^2 U}{g} w\\,.\n\\]\nRequiring a balance between the linear advection terms, as before, results in\n\\[\n\\epsilon^2 \\left(\\D{w}{x} + F\\ub\\cdot\\nabla w\\right) = -\\D{p}{z} - \\rho\\,.\n\\]\n\n\\bibliographystyle{elsarticle-harv}\n\\bibliography{bibliography}\n\n\n\\end{document}", "meta": {"hexsha": "17468d726fd5d66512938d7bda47caee103b8605", "size": 4341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nondimensional/rotation_scaling.tex", "max_stars_repo_name": "fmayer2010/LeeWavePaper", "max_stars_repo_head_hexsha": "39a0c6edd22da86c12b9cbec560c8fb350ba62be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nondimensional/rotation_scaling.tex", "max_issues_repo_name": "fmayer2010/LeeWavePaper", "max_issues_repo_head_hexsha": "39a0c6edd22da86c12b9cbec560c8fb350ba62be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nondimensional/rotation_scaling.tex", "max_forks_repo_name": "fmayer2010/LeeWavePaper", "max_forks_repo_head_hexsha": "39a0c6edd22da86c12b9cbec560c8fb350ba62be", "max_forks_repo_licenses": ["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.1808510638, "max_line_length": 1100, "alphanum_fraction": 0.671964985, "num_tokens": 1570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6846434534114595}}
{"text": "\t\\chapter{Miscellaneous}\n\t\\section{Some Math}\n\t\\renewcommand{\\thepage}{}\n\tAgain, we present you a small mathematical example. Get familiar with this syntax in order to create your own formulas\\footnote{\\url{https://en.wikibooks.org/wiki/LaTeX/Mathematics}}.\n\t\\begin{equation}\n\t\\varpi_q(k,l)=\\begin{cases}\n\t&1\\quad \\quad G_q(k,l)>\\rho_{\\text{th}}\\\\\n\t&0\\quad \\quad \\text{otherwise}\\\\\n\t\\end{cases}\n\t\\end{equation}\n\twith $\\rho_{\\text{th}}$ defined as a constant threshold. The remixing error spreading is performed as follows:\n\t\\begin{eqnarray}\n\t\\hat{X}^{(i+1)}_q(k,l)&=&{\\varpi}_q(k,l)\\left(\\tilde{{X}}^{(i)}_q(k,l)+\\frac{E^{(i)}(k,l)}{\\sum_{q=1}^Q{{\\varpi}_q(k,l)}}\\right)\\nonumber\\\\\n\t\\tilde{\\mathbf{X}}^{(i)}&=&\\mathcal{G}(\\hat{X}_q^{(i)}),\n\t\\end{eqnarray}\n\twhere $\\sum_{q=1}^Q{{\\varpi}_q(k,l)}$ accounts for the overal contributions of sources in time frequency error distribution and the remixing error $E^{(i)}(k,l)$ is defined as \n\t\\begin{equation}\n\tE^{(i)}(k,l)=Y(k,l)-\\sum_{q=1}^{Q}{\\hat{X}_q(k,l)}.\n\t\\end{equation}\n\t\n\t\\begin{mdframed}\n\t\t\\begin{lstlisting}[caption={A new math example}]\n\t\t\\begin{equation}\n\t\t\t\\varpi_q(k,l)=\\begin{cases}\n\t\t\t&1\\quad \\quad G_q(k,l)>\\rho_{\\text{th}}\\\\\n\t\t\t&0\\quad \\quad \\text{otherwise}\\\\\n\t\t\t\\end{cases}\n\t\t\\end{equation}\n\t\twith $\\rho_{\\text{th}}$ defined as a constant threshold. The remixing error spreading is performed as follows:\n\t\t\\begin{eqnarray}\n\t\t\t\\hat{X}^{(i+1)}_q(k,l)&=&{\\varpi}_q(k,l)\\left(\\tilde{{X}}^{(i)}_q(k,l)+\\frac{E^{(i)}(k,l)}{\\sum_{q=1}^Q{{\\varpi}_q(k,l)}}\\right)\\nonumber\\\\\n\t\t\t\\tilde{\\mathbf{X}}^{(i)}&=&\\mathcal{G}(\\hat{X}_q^{(i)}),\n\t\t\\end{eqnarray}\n\t\twhere $\\sum_{q=1}^Q{{\\varpi}_q(k,l)}$ accounts for the overal contributions of sources in time frequency error distribution and the remixing error $E^{(i)}(k,l)$ is defined as \n\t\t\\begin{equation}\n\t\t\tE^{(i)}(k,l)=Y(k,l)-\\sum_{q=1}^{Q}{\\hat{X}_q(k,l)}.\n\t\t\\end{equation}\n\t\t\\end{lstlisting}\n\t\tBy adding a label to your equation, you will be able to refer to the equation within the text!\n\t\\end{mdframed}\n\n\\section{Program code / listing}\nThree types of source codes are supported: code snippets, code segments, and\nlistings of stand alone files. Snippets are placed inside paragraphs and the others as\nseparate paragraphs the difference is the same as between text style and display\nstyle formulas\\footnote{\\url{https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings}}. In the following, we will give you a short introduction on all three code listing types.\n\n\\subsection{individual added program code}\n\\begin{lstlisting}[caption = {Single code}]\n#include <stdio.h>\n#define N 10\n\nint main()\n{\nint i;\n\nputs(\"Hello world!\");\n\nfor (i = 0; i < N; i++)\n{\n\tputs(\"LaTeX is also great for programmers!\");\n}\n\nreturn 0;\n}\n\\end{lstlisting}\n\n\\begin{mdframed}\n\t\\begin{lstlisting}[caption = {Example of \\emph{Single code}}]\n\t\\begin{lstlisting}[caption = {Single code}]\n\t#include <stdio.h>\n\t#define N 10\n\t\n\tint main()\n\t{\n\tint i;\n\t\n\tputs(\"Hello world!\");\n\t\n\tfor (i = 0; i < N; i++)\n\t{\n\tputs(\"LaTeX is also great for programmers!\");\n\t}\n\t\n\treturn 0;\n\t}\t\n\t\\end {lstlisting}\n\t\\end{lstlisting}\n\\end{mdframed}\n\n\\subsection{Add specific code file}\n\n\\lstinputlisting[language=C, caption = {Same code but now we added the code file instead of copying the code into latex}]{code/test.c}\n\n\\begin{mdframed}\n\t\\begin{lstlisting}[caption = {Example of \\emph{Adding specific code file}}]\n\t\t\n\t\t\\lstinputlisting[language=C, caption = {Same code but now we added the code file instead of copying the code into latex}]{code/test.c}\n\t\t\n\t\\end{lstlisting}\n\\end{mdframed}\n\n\\subsection{Scope on specific code file}\n\n\\lstinputlisting[language=C, firstline=6, lastline=13, caption = {Scope on specific code file}]{code/test.c}\n\n\\begin{mdframed}\n\t\\begin{lstlisting}[caption = {Example of \\emph{Scope on specific code file}}]\n\t\n\t\\lstinputlisting[language=C, firstline=6, lastline=13, caption = {Specific scope on code file}]{code/test.c}\n\t\n\t\\end{lstlisting}\n\\end{mdframed}", "meta": {"hexsha": "b292d18f24e2792a7a4e062ff8e62a8c87460e8c", "size": 3934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sensorik/Chapters/appendixA.tex", "max_stars_repo_name": "thealexinator2904/Industrial-automation", "max_stars_repo_head_hexsha": "572c39fa3c3926f327d9f1f4fd8e670d050e93bf", "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": "sensorik/Chapters/appendixA.tex", "max_issues_repo_name": "thealexinator2904/Industrial-automation", "max_issues_repo_head_hexsha": "572c39fa3c3926f327d9f1f4fd8e670d050e93bf", "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": "sensorik/Chapters/appendixA.tex", "max_forks_repo_name": "thealexinator2904/Industrial-automation", "max_forks_repo_head_hexsha": "572c39fa3c3926f327d9f1f4fd8e670d050e93bf", "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.814159292, "max_line_length": 184, "alphanum_fraction": 0.687849517, "num_tokens": 1332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.684643441250398}}
{"text": "% !TeX encoding = UTF-8\n\\section{Introduction}\n\\textit{The graph coloring problem} is one of the most famous \\textit{NP-complete} problems. Given a graph $G = (V, E)$ and $k$, where $V$ is the set of vertices in the graph, $E$ is the set of edges and $k$ is the number of available colors. The problem is to assign a certain color to every vertex $v \\in V$ with the constraint: there is no pair of vertices which are adjacent and  have the same color.\nThis problem has many applications:\n\\begin{itemize}\n    \\item[(1)] \\textit{Map Coloring:} Coloring geographical maps of countries or states where no two adjacent countries can be assigned same color. Four colors are enough to color.\n    \\item[(2)] \\textit{Sudoku:} Sudoku is a variation of graph coloring problem where every cell represents a vertex. There is an edge between two vertices if they are in same row or same column or same block.\n    \\item[(3)] \\textit{Register Allocation:} In compiler optimization, register allocation is the process of assigning a large number of target program variables onto a small number of CPU registers. \\cite{example}\n\\end{itemize}\n\n\\begin{definition}\nA \\textit{graph} is a tuple $G = (V, E)$ consisting of a nonempty set $V$ of vertices and a set of edges $E$. \\cite{bondy1976graph}\n\\end{definition}\n\n\\begin{definition}\nA \\textit{vertex coloring} of a graph $G = (V, E)$ is a map $c: V \\longrightarrow S$ such that $c(v) \\ne c(w)$ whenever $v$ and $w$ are adjacent. The elements of the set $S$ are called the available colors. If $G$ has a $k$-COLORING, namely the size of $S$ is $k$, then we call the graph $G$ is $k$-colorable.\n \\cite{diestel2010graph}\n\\end{definition}\n\\begin{claim}\n2-COLORING problem can be solved in polynomial time.\n\\end{claim}\n\n\\begin{proof}\nSuppose the given graph $G = (V, E)$ and color $c_1, c_2$. \n\\begin{itemize}\n    \\item[(1)] Randomly pick $v \\in V$, color it with $c_1$.\n    \\item[(2)] Apply BFS starting with vertex $v$ and color its neighbors with $c_2$. The point is that for $\\forall u \\in V$, we should color its neighbors with the other color alternatively: assume that the color of $u$ is $c_1$, then we assign $c_2$ to its neighbors, and vice versa.\n    \\item[(3)] After finishing BFS, go through all vertices again to check whether there is a vertex that is assigned with same colors other than its neighbor(s). If \\textit{yes}, then the graph is \\textit{not} 2-colorable, \\textit{otherwise} it is 2-colorable.\n\\end{itemize}\nThe running time is similar to BFS: $\\mathcal{O}(|V| + |E|)$.\n\\end{proof}\n\n\\begin{observation}\nWe can check whether a graph is bipartite by coloring the graph using two colors. If a given graph is 2-colorable, then it is bipartite.\n\\end{observation}\n\n\\begin{observation}\n$k$-COLORING problems are $NP-complete$ for $k \\geq 3$. \n\\end{observation}\n\nAs previously stated, the k-COLORING problem is NP-complete, which means that it seems hardly possible to have a polynomial time algorithm for this problem. Moving on now to consider 3-COLORING problem under circumstance that there is no triangle within the given graph $G$. Grötzsch’s theorem \\cite{grotzsch1959dreifarbensatz} states that each triangle-free planar graph is 3-colorable. Thomassen \\cite{Thomassen1994Grtzschs3T} has also found two proofs and extended the result in various way, by which a quadratic algorithm for finding suitable 3-coloring can be developed possibly. Kowalik \\cite{article} maintains a complex data structure called \\textit{Short Path Data Structure (SPDS)}, which will be built in linear time and enables that finding shortest paths of length at most 2 in planar graph takes $\\mathcal{O}(1)$ time. The SPDS will be constantly updated during the particular sequence of operations. And its running time for finding 3-COLORING is $\\mathcal{O}(n\\log{}n)$. After that, Dvorak, Kawaravayashi and Thomas \\cite{dvorak2013threecoloring} have designed a linear-time algorithm which still relies on the Grötzsch’s theorem but avoids complex data structures. Nevertheless, their paper is quite complicated for readers. So this thesis will give a deeper and detailed view into their paper for better understanding of their main ideas and proofs. \\\\ \n\nIn the second section, we will give some needed definitions and give an overview of this linear-time algorithm. In the third section, we will introduce a attribute called safety with which it's possible to reduce the size of graph. Then in the fourth section, we will give a short proof of Grötzsch's theorem by two lemmas. Next, we will give an overview how a naive algorithm for three-coloring is implemented and show some improvements. In the last two sections, the way to have a linear-time algorithm will be given and its correctness will be also proven. \n", "meta": {"hexsha": "10f8c4e236d619e6d2e369e883b7809ee981091f", "size": 4740, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/1_introduction.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/1_introduction.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/1_introduction.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": 107.7272727273, "max_line_length": 1371, "alphanum_fraction": 0.7613924051, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6845784175135592}}
{"text": "\\section{NP-Complete}\n\n%%%%%%%%%%\n\\begin{frame}{NP-hard}\n  \\begin{definition}[NP-hard]\n    $B$ is NP-hard if\n    \\[\n      \\forall A \\in \\text{NP}: A \\le_{P} B.\n    \\]\n  \\end{definition}\n\n  \\begin{alertblock}{Remark.}\n    NP-hard problems are at least as hard as any problem in NP.\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{NP-complete}\n  \\begin{definition}[NP-complete]\n    $B$ is NP-complete if:\n    \\begin{enumerate}\n      \\item $B \\in \\text{NP}$\n      \\item $B$ is NP-hard.\n    \\end{enumerate}\n  \\end{definition}\n\n  \\begin{alertblock}{Remark.}\n    NP-complete problems are the hardest problems in NP.\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{NP-complete}\n  \\begin{theorem}\n    If $B$ is NP-complete and $B \\in \\text{P}$, then $\\text{P} = \\text{NP}$.\n  \\end{theorem}\n\n  \\begin{proof}\n    \\begin{enumerate}\n      \\item $\\text{P} \\subseteq \\text{NP}$\n\t\\begin{itemize}\n\t  \\item already proved\n\t\\end{itemize}\n      \\item $\\text{NP} \\subseteq \\text{P}$:\n        \\begin{itemize}\n\t  \\item $\\forall A \\in \\text{NP}, A \\le_{P} B \\land B \\in \\text{P} \\Rightarrow A \\in \\text{P}$\n\t\\end{itemize}\n    \\end{enumerate}\n  \\end{proof}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{NP-complete}\n  \\begin{theorem}\n    If $B$ is NP-complete and $B \\le_{P} C \\in \\text{NP}$, then $C$ is NP-complete.\n  \\end{theorem}\n  \n  \\begin{proof}\n    \\begin{enumerate}\n      \\item $C \\in \\text{NP}$\n      \\item $C$ is NP-hard:\n\t\\begin{itemize}\n\t  \\item $\\forall A \\in \\text{NP}, A \\le_{P} B \\le_{P} C \\Rightarrow A \\le_{P} C$.\n\t\\end{itemize}\n    \\end{enumerate}\n  \\end{proof}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{Proof of being in NP-complete}\n  \\begin{exampleblock}{To prove $C$ is NP-complete.}\n    \\begin{enumerate}\n      \\item $C \\in \\text{NP}$:\n\t\\begin{itemize}\n\t  \\item non-deterministic polynomial algorithm\n\t\\end{itemize}\n      \\item $C$ is NP-hard:\n\t\\begin{itemize}\n\t  \\item choose a known NP-complete problem $B$\n\t  \\item prove $B \\le_{P} C$\n\t\\end{itemize}\n    \\end{enumerate}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{NP-complete problem}\n  \\begin{exampleblock}{The first known NP-complete problem.}\n    SAT (circuit satisfiablity) is NP-complete.\n  \\end{exampleblock}\n\n  \\fignocaption{width = 0.40\\textwidth, angle = -90}{fig/karp21.png}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}\n  \\fignocaption{width = 1.0\\textwidth}{fig/npc-graph.png}\n\n  \\begin{center}\n    \\url{http://adriann.github.io/npc/npc.html}\n  \\end{center}\n\\end{frame}\n%%%%%%%%%%\n\n", "meta": {"hexsha": "a207ef33f06cf8a23da154a551182836d22471f8", "size": 2455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-p-np-2016-06-16/sections/np-hard-npc.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-p-np-2016-06-16/sections/np-hard-npc.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-p-np-2016-06-16/sections/np-hard-npc.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.797979798, "max_line_length": 95, "alphanum_fraction": 0.6114052953, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.684578411973815}}
{"text": "\\section{Simple linear regression}\n\n\\subsection{Model}\n\\begin{equation}\n\\label{eq:simple_linear_model}\nY = \\theta_0 + \\theta_1 * X\n\\end{equation}\n\n\\subsection{Data}\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{output_1/scatter_plot.png}\n  \\caption{Scatter plot of data}\n  \\label{fig:scatter_plot}\n\\end{figure}\n\n% For alpha=0.01\n\\subsection{For $\\alpha$ = 0.01}\n\\subsubsection{Initial values of parameters}\n\\begin{equation}\n\\theta_0 = 0.8962072600475405\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 0.2669940858224631\n\\end{equation}\n\n\\subsubsection{Final values of parameters}\n\\begin{equation}\n\\theta_0 = 1.0600275383405036\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 1.9933270664119627\n\\end{equation}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{output_1/regression_line_0_01.png}\n    \\caption{Regression line for $\\alpha$ = 0.01}\n    \\label{fig:regression_line_alpha_0_01}\n\\end{figure}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth,height=0.4\\textheight, keepaspectratio]{output_1/cost_function_alpha_0_01.png}\n    \\caption{Mean squared error for $\\alpha$ = 0.01}\n    \\label{fig:mean_square_alpha_0_01}\n\\end{figure}\n\n% For alpha=0.1\n\\subsection{For $\\alpha$ = 0.1}\n\\subsubsection{Initial values of parameters}\n\\begin{equation}\n\\theta_0 = 0.6463591916414174\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 0.6158535662289891\n\\end{equation}\n\n\\subsubsection{Final values of parameters}\n\\begin{equation}\n\\theta_0 = 1.0599999999999916\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 1.9933333333333352\n\\end{equation}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth,height=0.4\\textheight]{output_1/regression_line_0_1.png}\n    \\caption{Regression line for $\\alpha$ = 0.1}\n    \\label{fig:regression_line_alpha_0_1}\n\\end{figure}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth,height=0.4\\textheight]{output_1/cost_function_alpha_0_1.png}\n    \\caption{Mean squared error for $\\alpha$ = 0.1}\n    \\label{fig:mean_square_alpha_0_1}\n\\end{figure}\n\n% For alpha=1\n\\subsection{For $\\alpha$ = 1.0}\n\\subsubsection{Initial values of parameters}\n\\begin{equation}\n\\theta_0 = 0.5560688289301584\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 0.9611765272334949\n\\end{equation}\n\n\\subsubsection{Final values of parameters}\n\\begin{equation}\n\\theta_0 = 1.0295053205606435e+155\n\\end{equation}\n\\begin{equation}\n\\theta_1 = 4.523890821517764e+155\n\\end{equation}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth,height=.4\\textheight]{output_1/regression_line_1_0.png}\n    \\caption{Regression line for $\\alpha$ = 1.0}\n    \\label{fig:regression_line_alpha_1_0}\n\\end{figure}\n\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth, height=.4\\textheight]{output_1/cost_function_alpha_1_0.png}\n    \\caption{Mean squared error for $\\alpha$ = 1.0}\n    \\label{fig:mean_squared_error_alpha_1_0}\n\\end{figure}\n\n\\subsection{Observation}\nThe scatter plot of data in figure \\ref{fig:scatter_plot} shows that there is a linear correlation between the predictor variable X and prediction variable Y. The equation \\ref{eq:simple_linear_model} was used as a model for the linear regression. Using different values for $\\alpha$ resulted in different cost value graph and regression line.\n\nFor $\\alpha$ = 0.01 and $\\alpha$ = 0.1 the regression algorithm converged with decreasing cost function as shown in figure \\ref{fig:mean_square_alpha_0_01} and figure \\ref{fig:mean_square_alpha_0_1} respectively. The regression obtained for $\\alpha$ = 0.01 shown in figure \\ref{fig:regression_line_alpha_0_01} shows that the regression line properly fits the data. Also, for $\\alpha$ = 0.1 a similar regression line is obtained as shown in figure \\ref{fig:regression_line_alpha_0_1}.\n\nFor $\\alpha$ = 1, the gradient descent algorithm started to overshoot which resulted in increasing cost function as shown in figure \\ref{fig:mean_squared_error_alpha_1_0}. The cost function continued to increase until a maximum limit was reached after which it was terminated. The resulting regression line was far from being an optimal one so was a poor fit for the data which is shown by figure \\ref{fig:regression_line_alpha_1_0}.\n\n\\subsection{Conclusion}\nOur observations obtained by varying the learning rate($\\alpha$) shows that the learning rate has to carefully chosen for gradient descent step in linear regression algorithm. A higher learning rate may result in faster convergence but it may result in oscillation and overshooting which are not desired.\n\\subsection{Source Code}\n\n\\lstinputlisting[language=python]{task_1.py}\n", "meta": {"hexsha": "de861a980e64f20dc61056ad161b09b0c26d905f", "size": 4592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/simple_linear_regression.tex", "max_stars_repo_name": "diwasblack/machine_learning", "max_stars_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/simple_linear_regression.tex", "max_issues_repo_name": "diwasblack/machine_learning", "max_issues_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/simple_linear_regression.tex", "max_forks_repo_name": "diwasblack/machine_learning", "max_forks_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9152542373, "max_line_length": 483, "alphanum_fraction": 0.7759146341, "num_tokens": 1406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.6845783977803442}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[margin=0.5in]{geometry}\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\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        To formulate the problem, let $y$ be an arbitrary element of the universe, $U$. The false positive rate can be expressed as a probability\n        $$Pr \\left[ y \\in U \\backslash S \\land \\lor_{x \\in S} \\left( h(x) = h(y) \\right) \\right]$$\n        By Kolmogorov definition, it can be further decomposed into the product of two probabilities\n        $$Pr \\left[ \\lor_{x \\in S} \\left( h(x) = h(y) \\right) | y \\in U \\backslash S \\right] \\cdot Pr \\left[ y \\in U \\backslash S \\right]$$\n        For the latter probability it is pretty simple, which is saying to draw an arbitrary item from the universe $U$ but it should not be an element of the subset $S$. So it is simply\n        $$Pr \\left[ y \\in U \\backslash S \\right] = \\frac{n - m}{n}$$\n        Based on the universality property of 2-universal hash family, we know that\n        $$\\forall x, y \\in U \\ x \\neq y \\Rightarrow Pr \\left[ h(x) = h(y) \\right] \\leq \\frac{1}{r}$$\n        Draw an arbitrary $y$ outside of the subset $S$ but within the universe $U$, and let $c = h(y)$. By the property above, we can get that\n        $$\\forall x \\in S \\  Pr \\left[ h(x) = c \\right] \\leq \\frac{1}{r}$$\n        Thus, after $m$ updates, the probability of collision, by the assumption of independence, raises to\n        $$Pr \\left[ \\lor_{x \\in S} \\left( h(x) = c \\right) \\right] = \\sum_{x \\in S} Pr \\left[ h(x) = c \\right] \\leq \\frac{m}{r}$$\n        In another word, it is an conditional probability which is\n        $$Pr \\left[ \\lor_{x \\in S} \\left( h(x) = h(y) \\right) | y \\in U \\backslash S \\right] \\leq \\frac{m}{r}$$\n        Thus, the probability of false positive is\n        $$Pr \\left[ \\lor_{x \\in S} \\left( h(x) = h(y) \\right) \\land y \\in U \\backslash S \\right] = Pr \\left[ \\lor_{x \\in S} \\left( h(x) = h(y) \\right) | y \\in U \\backslash S \\right] \\cdot Pr \\left[ y \\in U \\backslash S \\right] \\leq \\frac{(n - m)m}{r n}$$\n        Introducing the parameter $\\epsilon$, we get\n        \\begin{equation*}\n            \\begin{split}\n                \\frac{(n - m)m}{r n} & \\leq \\epsilon \\\\\n                r & \\geq \\frac{(n - m)m}{n \\epsilon}\n            \\end{split}\n        \\end{equation*}\n\\end{document}\n", "meta": {"hexsha": "e0aee4555ae23ff87ecb7cf90dfff4c6569d3651", "size": 2429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment/A/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/A/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/A/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": 63.9210526316, "max_line_length": 254, "alphanum_fraction": 0.606422396, "num_tokens": 808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.684575718957487}}
{"text": "\\documentclass[letterpaper, twoside, 12pt]{book}\n\\usepackage{packet}\n\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\n\\chapter{Part 2.1: Sections 13.3-13.4}\n\n\\setcounter{chapter}{13}\n\\setcounter{section}{2}\n\n\\section{Arc Length and Curvature}\n\n          \\begin{problem}\n            Let $\\vect{r}(t)=\\<6t, t^3, 3t^2\\>$. Use the lengths of\n            the line segments\n            connecting $\\vect{r}(0)$, $\\vect{r}(1)$, $\\vect{r}(2)$,\n            and $\\vect{r}(3)$ to approximate the length of the curve\n            from $t=0$ to $t=3$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\nLet $\\harpvec{r}(t) = \\<f(t),g(t),h(t)\\>$ be a vector function.\nThen the \\textbf{arclength} or \\textbf{length} of the curve given by\n$\\harpvec{r}(t)$ from $t=a$ to $t=b$ is\n\\[\n  L\n    =\n  \\int_a^b\n  \\left|\n    \\lim_{\\Delta{t}\\to0}\n    \\frac{\\vect{r}(t+\\Delta{t})-\\vect{r}(t)}{\\Delta{t}}\n  \\right|\n  \\dvar{t}\n  =\n  \\int_a^b |\\vect{r}'(t)| \\dvar{t}\n\\]\n\\end{definition}\n\n          \\begin{problem}\n            Find the length of the curve given by\n            $\\vect{r}(t)=\\<6t, t^3, 3t^2\\>$\n            from $t=0$ to $t=3$.\n            (Hint: $9t^4+36t^2+36$ is a perfect square polynomial.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\nLet $s(t)$ be the \\textbf{arclength function/parameter} representing the\nlength of a curve from the point given by\n$\\harpvec{r}(0)$ to the point given by $\\harpvec{r}(t)$.\n(Assume $s(t)<0$ for $t<0$.)\n\\end{definition}\n\n\\begin{theorem}\nThe arclength function $s(t)$ is given by the definite integral\n\\[\n  s(t)\n    =\n  \\int_0^t |\\vect{r}'(\\tau)| \\dvar{\\tau}\n\\]\n\\end{theorem}\n\n\\begin{theorem}\nThe derivative of the arclength function gives the lengths of\nthe tangent vectors given by the derivative of the position function:\n\\[\n  \\frac{ds}{dt} = \\left|\\frac{d\\vect{r}}{dt}\\right|\n\\]\n\\end{theorem}\n\n          \\begin{problem}\n            Compute $s(t)$ for $\\vect{r}(t)=\\<6t, t^3, 3t^2\\>$,\n            and use it to find the arclength parameter corresponding\n            to $t=-2$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Find the length of an arc of the circular helix with\n            vector equation\n            $\\vect{r}(t) = \\<\\cos(t),\\sin(t),t\\>$\n            from $(1,0,0)$ to $(1,0,2\\pi)$.\n          \\end{problem}\n\n\\begin{definition}\n  The \\textbf{unit tangent vector} $\\vect{T}$ to a curve $\\vect{r}$ is the\n  direction of the derivative $\\vect{r}'(t)=\\frac{d\\vect{r}}{dt}$.\n\\end{definition}\n\n\\begin{theorem}\n  \\[\n    \\vect{T} = \\frac{d\\vect{r}/dt}{|d\\vect{r}/dt|} = \\frac{d\\vect{r}}{ds}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Find the unit tangent vector to the curve given by\n            $\\vect{r}(t)=\\<3t^2,2t\\>$ at the point where $t=-3$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\n  The \\textbf{curvature} $\\kappa$ of a curve $C$ at a given point is\n  the magnitude of the rate of change of $\\vect{T}$ with respect to\n  arclength $s$.\n\\end{definition}\n\n\\begin{theorem}\n  \\[\n    \\kappa\n      =\n    \\left|\n    \\frac{d\\vect{T}}{ds}\n    \\right|\n      =\n    \\left|\n    \\frac{1}{ds/dt}\n    \\frac{d\\vect{T}}{dt}\n    \\right|\n      =\n    \\frac{1}{|d\\vect{r}/dt|}\n    \\left|\n      \\frac{d\\vect{T}}{dt}\n    \\right|\n  \\]\n\\end{theorem}\n\n\\begin{theorem}\n  An alternate formula for curvature is given by\n  \\[\n    \\kappa =\n    \\frac{|\\vect{r}'(t)\\times\\vect{r}''(t)|}{|\\vect{r}'(t)|^3}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove that the helix given by the vector equation\n            $\\vect{r}(t) = \\<\\cos(t),\\sin(t),t\\>$\n            has constant curvature.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            (OPTIONAL)\n            Prove that the alternate formula for curvature is\n            accurate by showing\n            \\[\n              \\frac{1}{|d\\vect{r}/dt|}\n              \\left|\n                \\frac{d\\vect{T}}{dt}\n              \\right|\n                =\n              \\frac{|\\vect{r}'\\times\\vect{r}''|}{|\\vect{r}'|^3}\n            \\]\n            (Some of the solution has been provided.)\n          \\end{problem}\n\n          \\begin{solution}\n            Begin by observing that\n            $\n              \\vect{r}'\n                =\n              \\left|\\frac{d\\vect{r}}{dt}\\right|\\vect{T}\n                =\n              \\frac{ds}{dt}\\vect{T}\n            $, and by the product rule it follows that\n            $\n              \\vect{r}''\n                =\n              \\frac{d^2s}{dt^2}\\vect{T} + \\frac{ds}{dt}\\vect{T}'\n            $.\n\n            (...)\n\n            % (Continue this argument by taking the cross-product of\n            % $\\vect{r}'$ and $\\vect{r}''$, simplifying by using the fact that\n            % $\\vect{v}\\times\\vect{v}=\\vect{0}$, then taking its magnitude\n            % and simplifying using the fact that $|\\vect{T}|=1$ and\n            % $\\vect{T},\\vect{T}'$ are perpendicular (why?).\n            % You should end up with\n            % $\\left(\\frac{ds}{dt}\\right)^2\\left|\\vect{T}'\\right|$, which can\n            % be used with $\\frac{ds}{dt}=|\\vect{r}'|$ to finish the proof.)\n          \\end{solution}\n\n\\begin{definition}\n  The \\textbf{unit normal vector} $\\vect{N}$ to a curve $\\vect{r}$ is the\n  direction of the derivative of the unit tangent vector\n  $\\vect{T}'(t)=\\frac{d\\vect{T}}{dt}$.\n  (By definition, this vector points into the direction of the curve.)\n\\end{definition}\n\n\\begin{theorem}\n  \\[\n    \\vect{N} = \\frac{\\vect{T}'}{|\\vect{T}'|}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove that $\\vect{N}$ actually is normal to the curve by\n            using a theorem from a previous section. (Hint: $|\\vect{T}|=1$.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Plot the curve given by $\\vect{r}(t)=\\<\\cos(2t),\\sin(2t)\\>$,\n            along with $\\vect{T},\\vect{N}$ at the point where\n            $t=\\frac{\\pi}{2}$.\n          \\end{problem}\n\n          \\begin{problem}\n            Give formuals for $\\vect{T},\\vect{N}$ in terms of $t$ for\n            the vector function\n            \\[\\vect{r}(t) = \\< \\sqrt{2}\\sin t,2\\cos t,\\sqrt{2}\\sin t \\>\\]\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\n  The \\textbf{binormal vector} $\\harpvec{B}$ is the direction\n  normal to both $\\harpvec{T}$ and $\\harpvec{N}$ according to\n  the right-hand rule.\n\\end{definition}\n\n\\begin{theorem}\n  \\[\n    \\vect{B}=\\vect{T}\\times\\vect{N}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove that $\\vect{T}\\times\\vect{N}$ is a unit vector.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n          Given the following information about $\\vect{r}(t)$ at a point,\n          evaluate the binormal vector $\\vect{B}$ and curvature\n          $\\kappa$ at that same point:\n            \\[\\frac{d\\vect{r}}{dt}=\\<-3,0,3\\sqrt{3}\\>\\]\n            \\[\\frac{d\\vect{T}}{dt}=\\<-\\sqrt{3},0,-1\\>\\]\n            \\[\\vect{T}=\\<-\\frac{1}{2},0,\\frac{\\sqrt{3}}{2}\\>\\]\n            \\[\\vect{N}=\\<-\\frac{\\sqrt{3}}{2},0,-\\frac{1}{2}\\>\\]\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\n  A \\textbf{right-handed frame} is a group of three unit vectors which\n  are all normal to one another and satisfy the right hand rule.\n\\end{definition}\n\n\\begin{example}\n  $\\veci,\\vecj,\\veck$ and $\\vect T,\\vect N,\\vect B$ are examples\n  of right-handed frames.\n\\end{example}\n\n\\begin{theorem}\n  Any vector is a linear combination of the vectors in a right-handed frame.\n\\end{theorem}\n\n\\section{Motion in Space, Velocity, and Acceleration}\n\n\\begin{definition}\nThe \\textbf{velocity} $\\vect{v}(t)$ of a particle at time $t$ on a position\nfunction $\\vect{r}(t)$ is its rate of change with respect to $t$.\n\\end{definition}\n\n\\begin{definition}\nThe \\textbf{speed} $|\\vect{v}(t)|$ of a particle at time $t$ on a position\nfunction $\\vect{r}(t)$ is the magnitude of its velocity.\n\\end{definition}\n\n\\begin{definition}\nThe \\textbf{direction} $\\vect{T}(t)$ of a particle at time $t$ on a position\nfunction $\\vect{r}(t)$ is the direction of its velocity.\n\\end{definition}\n\n\\begin{definition}\nThe \\textbf{acceleration} $\\vect{a}(t)$ of a particle at time $t$ on a position\nfunction $\\vect{r}(t)$ is the rate of change of its velocity with respect to $t$.\n\\end{definition}\n\n\\begin{theorem}\n\\[\n  \\vect{v}(t)=\\vect{r}'(t)\n\\]\n\\[\n  |\\vect{v}(t)|=|\\vect{r}'(t)|=\\frac{ds}{dt}\n\\]\n\\[\n  \\vect{T}(t) = \\frac{\\vect v}{|\\vect v|}\n\\]\n\\[\n  \\vect{a}(t)=\\vect{v}'(t)=\\vect{r}''(t)\n\\]\n\\end{theorem}\n\n\\begin{problem}\n  Given a position function $\\harpvec{r}(t) = \\<t^3,t^2\\>$ find its velocity,\n  speed, and acceleration at $t = 1$.\n\\end{problem}\n\n\\begin{definition}\n  \\textbf{Ideal projectile motion} is an approximation of real-world\n  motion assuming constant acceleration due to gravity in the $y$ direction\n  and no acceleration in the $x$ direction:\n    \\[\n      \\vect{a}(t) = \\<0,-g\\>\n    \\]\n\\end{definition}\n\n\\begin{theorem}\n  The velocity and position functions for a particle with initial velocity\n  $\\vect{v}_0=\\<v_{x,0},v_{y,0}\\>$ and beginning at position\n  $P_0=\\<x_0,y_0\\>$ assuming ideal projectile motion are:\n    \\[\n      \\vect{v}(t) = \\<v_{x,0},-gt+v_{y,0}\\>\n    \\]\n    \\[\n      \\vect{r}(t) = \\left\\<v_{x,0}t+x_0,-\\frac{1}{2}gt^2+v_{y,0}t+y_0\\right\\>\n    \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Assume ideal projectile motion and and $g=10\\frac{m}{s^2}$.\n            What is the flight time of a projectile shot from the ground\n            at an angle of $\\pi/6$ with initial speed $100\\frac{m}{s}$?\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Assume ideal projectile motion and and $g=10\\frac{m}{s^2}$.\n            What must have been the initial speed of a projectile shot\n            from the ground at an angle of $\\pi/3$ if it\n            traveled $60$ meters horizontally after $4$ seconds?\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\end{document}", "meta": {"hexsha": "6dc5342e99ac6007a6e8a8922e3937ba4b67dcec", "size": 10235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packet2_1.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_1.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_1.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": 27.3663101604, "max_line_length": 81, "alphanum_fraction": 0.5530043967, "num_tokens": 3223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311856832191, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.6845757186451539}}
{"text": "\\section{Value of Different Policies [35 pts]}\nIn many situations such as healthcare or education, we cannot run any arbitrary policy and collect data from running those policies for evaluation. In these cases, we may need to take data collected from following one policy and use it to evaluate the value of a different policy. The equality proved in the following exercise can be an important tool for achieving this.\nThe purpose of this exercise is to get familiar on how to compare the value of different policies, $\\pi_1$ and $\\pi_2$, on a fixed horizon MDP. A fixed horizon MDP is an MDP where the agent's state is reset after $H$ timesteps; $H$ is called the \\emph{horizon} of the MDP. There is no discount (i.e., $\\gamma=1$) and policies are allowed to be non-stationary, i.e., the action identified by a policy depends on the timestep in addition to the state.\nLet $x_t\\sim \\pi$ denote the distribution over states at timestep $t$ (for $1\\leq t \\leq H$) upon following policy $\\pi$ and $V^{\\pi}_t(x_t)$ denote the value function of policy $\\pi$ in state\n$x_t$ and timestep $t$, and $Q_t^{\\pi}(x_t,a)$ denote the corresponding\n$Q$ value associated to action $a$. As a clarifying example, we denote $\\E_{x_t \\sim \\pi_1} V(x_t)$ to represent the average value of the value function $V(\\cdot)$ over the states at timestep $t$ encountered upon following policy $\\pi_1$. Please show the following:\n\\begin{equation}\n\\label{eq:1}\nV_1^{\\pi_1}(x_1) - V_1^{\\pi_2}(x_1) =  \\sum_{t=1}^H \\E_{x_t \\sim \\pi_2} \\Big( Q_t^{\\pi_1}(x_t,\\pi_1(x_t,t)) - Q_t^{\\pi_1}(x_t,\\pi_2(x_t,t)) \\Big)\n\\end{equation}\n\n\\textbf{Intuition:} The above expression can be interpreted in the following way. For concreteness, assume that $\\pi_1$ is the better policy, i.e., achieving $V_1^{\\pi_1}(x_1) \\geq V_1^{\\pi_2}(x_1)$. Suppose you're following policy $\\pi_2$ and you are at timestep $t$ in state $x_t$.\nYou have the option to follow $\\pi_1$ (the better policy) until the end of the episode, totalling $Q_t^{\\pi_1}(x_t,\\pi_1(x_t,t))$ return from the current state-timestep; or you have the option to follow $\\pi_2$ for one timestep and then follow $\\pi_1$ instead until the end of the episode (you can follow many other policies of course). This would you give you a ``loss'' of $Q_t^{\\pi_1}(x_t,\\pi_1(x_t,t)) - Q_t^{\\pi_1}(x_t,\\pi_2(x_t,t))$ that originates from following the worse policy $\\pi_2$ instead of $\\pi_1$ in that timestep.\n% Then equation \\ref{eq:1}\nThen the equation above\nmeans that the value difference of the two policies is the sum of all the losses induced by following the suboptimal policy for every timestep, weighted by the expected trajectory of the policy you're following.\n\n\\textbf{Answer:}\n\n\\begin{equation}\n\\begin{split}\nV^{\\pi_1}_{t}(x_t) - V^{\\pi_2}_{t}(x_t) & = Q^{\\pi_1}_{t}(x_t,\\pi_1(x_t,t)) - Q^{\\pi_2}_{t}(x_t, \\pi_2(x_t,t)) \\\\\n& = Q^{\\pi_1}_{t}(x_t,\\pi_1(x_t,t)) - Q^{\\pi_1}_{t}(x_t, \\pi_2(x_t,t)) + Q^{\\pi_1}_{t}(x_t, \\pi_2(x_t,t)) - Q^{\\pi_2}_{t}(x_t, \\pi_2(x_t,t))\n\\end{split}\n\\end{equation}\n\n\\begin{equation}\n\\begin{split}\nQ^{\\pi_1}_{t}(x_t, \\pi_2(x_t,t)) - Q^{\\pi_2}_{t}(x_t, \\pi_2(x_t,t)) & = r_t(x_t, \\pi_2(x_t, t)) + {\\mathbb E}_{s' \\sim p(x_t, \\pi_2(x_t, t))}V^{\\pi_1}_{t+1}(s') \\\\\n& \\quad - r_t(x_t, \\pi_2(x_t, t)) - {\\mathbb E}_{s' \\sim p(x_t, \\pi_2(x_t, t))}V^{\\pi_2}_{t+1}(s') \\\\\n& = {\\mathbb E}_{s' \\sim p(x_t, \\pi_2(x_t, t))}(V^{\\pi_1}_{t+1}(s') - V^{\\pi_2}_{t+1}(s'))\n\\end{split}\n\\end{equation}\n\nPlug back to previous formula:\n\n\\begin{equation}\n\\begin{split}\nV^{\\pi_1}_{t}(x_t) - V^{\\pi_2}_{t}(x_t) & = Q^{\\pi_1}_{t}(x_t,\\pi_1(x_t,t)) - Q^{\\pi_1}_{t}(x_t, \\pi_2(x_t,t)) + {\\mathbb E}_{s' \\sim p(x_t, \\pi_2(x_t, t))}(V^{\\pi_1}_{t+1}(s') - V^{\\pi_2}_{t+1}(s'))\n\\end{split}\n\\end{equation}\n\\begin{equation}\n\\begin{split}\n{\\mathbb E}_{x_t \\sim \\pi_2}(V^{\\pi_1}_{t}(x_t) - V^{\\pi_2}_{t}(x_t)) & = {\\mathbb E}_{x_t \\sim \\pi_2}(Q^{\\pi_1}_{t}(x_t,\\pi_1(x_t,t)) - Q^{\\pi_1}_{t}(x_t, \\pi_2(x_t,t))) + {\\mathbb E}_{x_{t+1} \\sim \\pi_2}(V^{\\pi_1}_{t+1}(x_{t+1}) - V^{\\pi_2}_{t+1}(x_{t+1})) \\\\\n& = {\\mathbb E}_{x_t \\sim \\pi_2}(Q^{\\pi_1}_{t}(x_t,\\pi_1(x_t,t)) - Q^{\\pi_1}_{t}(x_t, \\pi_2(x_t,t))) \\\\\n& \\quad + \\sum_{\\tau=t+1}^H({\\mathbb E}_{x_\\tau \\sim \\pi_2}(Q_\\tau^{\\pi_1}(x_\\tau, \\pi_1(x_\\tau, \\tau)) - Q_\\tau^{\\pi_2}(x_\\tau, \\pi_2(x_\\tau, \\tau)))) \\\\\n& = \\sum_{\\tau=t}^H({\\mathbb E}_{x_\\tau \\sim \\pi_2}(Q_\\tau^{\\pi_1}(x_\\tau, \\pi_1(x_\\tau, \\tau)) - Q_\\tau^{\\pi_2}(x_\\tau, \\pi_2(x_\\tau, \\tau))))\n\\end{split}\n\\end{equation}\n\nBy induction, above expression is true for any $1 \\leq \\tau \\leq H$, this gives the thesis.\n", "meta": {"hexsha": "3b1ccdb06812706ee00e9ab9b9d6f94443cb2003", "size": 4526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment1_written/tex/Q_policies.tex", "max_stars_repo_name": "ksang/cs234-assignments", "max_stars_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-12-25T12:29:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T12:53:13.000Z", "max_issues_repo_path": "assignment1_written/tex/Q_policies.tex", "max_issues_repo_name": "ksang/cs234-assignments", "max_issues_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-11-13T17:43:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T02:04:12.000Z", "max_forks_repo_path": "assignment1_written/tex/Q_policies.tex", "max_forks_repo_name": "ksang/cs234-assignments", "max_forks_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-02T01:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-02T01:34:47.000Z", "avg_line_length": 87.0384615385, "max_line_length": 531, "alphanum_fraction": 0.6650463986, "num_tokens": 1749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.6845757125793467}}
{"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%\\linespread{1.0}\n%\\setlength{\\parindent}{0em}\n%\\setlength{\\parskip}{0.8em}\n\n\\title{\\textbf{Notes on Gravity as a Quantum Theory}}\n\\author{Aditya Vijaykumar}\n\\affiliation{International Centre for Theoretical Sciences, Bengaluru, India.}\n\\emailAdd{aditya.vijaykumar@icts.res.in}\n\\abstract{One has always wondered how one describes quantum field in the presence of gravity, and it is time one finally gained a good understanding. One has no clue where this will lead, but one chooses to follow the book by Prof. Mukhanov, and read from other references if needed.}\n\n\\begin{document}\n\\maketitle\n\n\\section{All is Classical, All is Quantum}\n\n\\subsection{The Classical Field}\n$\\phi(\\va{x},t)$ gives the value of a classical field at every point in spacetime. The simplest classical field is the \\textit{real scalar field}, which is characterized only by real numbers. The Klein-Gordon equation governs a free massive scalar field.\n\n$$\\pdv[2]{\\phi}{t} - \\sum_{x_j} \\pdv[2]{\\phi}{x_j} + m^2 \\phi =0 $$\n\nAn interesting part about the free scalar field is that one can describe it as an infinite set of decoupled harmonic oscillators. Put this field into a box of length $L$ and volume $V=L^3$, and having periodic boundary conditions. One can Fourier decompose this as,\n$$\\phi(\\va{x},t) = \\frac{1}{\\sqrt{V}} \\sum_{\\va{k}} \\phi_{\\vb{k}} (t) \\exp(i \\va{k}\\vdot\\va{x}) \\text{ where } k_x =\\frac\n{2\\pi n_x}{L} ,\\ldots$$\n\nSubstituting this into the first equation, we find that the harmonic oscillators get nicely decoupled into an infinite set of ODEs of the form,\n$$\\ddot{\\phi_{\\vb{k}}} +(k^2+m^2)\\phi_{\\vb{k}} = 0$$\nwhich is basically the harmonic oscillator equation with frequency $\\omega_k = \\sqrt{k^2 + m^2}$.The energy of oscillators in simply equal to the sum of individual energies of the oscillators,\n$$E = \\sum_{\\vb{k}}\\left[ \\frac{1}{2} \\dot{\\phi_{\\vb{k}}}^2 + \\frac{1}{2}\\omega_k^2 \\phi_{\\vb{k}}^2 \\right]$$\n\nEquivalently, when $V \\rightarrow \\infty $ and $k$ is a continuous variable, the summation is just replaced by an integral over all $k$,\n$$\\phi(\\vb{x},t)= \\int \\frac{d^3\\vb{k}}{(2\\pi)^{3/2}}e^{i \\vb{k} \\vdot \\vb{x}} \\phi_{\\vb{k}}(t)$$\n\n\\subsection{Quantizing Fields}\nAs mentioned earlier, a field can be thought of as a collection of decoupled harmonic oscillators. We quantize each field $\\phi_{\\vb{k}}$ as a separate harmonic oscillator. We identify the position and momentum as operators $\\hat{\\phi_{\\vb{k}}}$ and $\\hat{\\pi_{\\vb{k}}}$. The commutation relations for the harmonic oscillator as $V\\rightarrow \\infty$ can now be written as,\n$$\\comm{\\hat{\\phi_{\\vb{k}}}(t)}{\\hat{\\pi_{\\vb{k'}}}(t)} = i \\delta(\\vb{k}+\\vb{k'})$$\nThe vacuum state is the state corresponding to the lowest energy configuration. One can clearly see that the commutation relations cannot be satisfied for the most intuitive low energy configuration \\textit{ie.} $\\phi(\\vb{x},t) = 0$, implying that the vacuum state is really something non-trivial. But since, for a free field, all the $\\phi_{\\vb{k}}$ are decoupled, we can write the vacuum state wave functional as the product of all wavefunctions, each describing the ground state of the harmonic oscillator with the wavenumber $\\vb{k}$. Again, for large volume, one can write,\n$$\\psi[\\phi] \\propto \\exp(-\\frac{1}{2}\\int d^3 \\vb{k} \\abs{\\phi_{\\vb{k}}}^2 \\omega_{\\vb{k}})$$\nConsider the integral inside the exponential,\n\\begin{flalign*}\n\\int d^3 \\vb{k} \\abs{\\phi_{\\vb{k}}}^2 \\omega_{\\vb{k}} &= \\int  d^3 \\vb{k}  \\phi_{\\vb{k}} \\phi_{\\vb{k}}^* \\sqrt{k^2 + m^2}\\\\\n&= \\int   d^3 \\vb{x} d^3 \\vb{y} \\phi(\\vb{x}) \\phi(\\vb{y}) \\int  d^3 \\vb{k}  e^{i\\vb{k}(\\vb{y} - \\vb{x})} \\sqrt{k^2 + m^2}\\\\\n&= \\int   d^3 \\vb{x} d^3 \\vb{y} \\phi(\\vb{x}) \\phi(\\vb{y}) K(\\vb{x},\\vb{y})\n\\end{flalign*}\nwhere $K(\\vb{x},\\vb{y})$ is called the kernel.\n\nThe vacuum energy density is just the sum of all ground state energies,\n$$\\frac{E_o}{V}= \\int\\frac{d^3 \\vb{k}}{(2\\pi)^3} \\frac{\\omega_{k}}{2}$$\nOkay, now this is a very interesting expression for the energy. We see that because $\\omega_k = \\sqrt{k^2+m^2}$, we can see that this integral diverges as $k^4$. If quantum gravity is assumed to be modelled as a scalar field, and we put a cutoff for our integration at let's say the Planckian scale, we see that the vacuum energy density is of the order unity in Planck units, which in turn corresponds to a mass density of $10^{94} g/cm^3$. The mass of the \\textit{entire} observable universe is $10^{55}g$! One can try to resolve this problem by \\textit{positing} that vacuum energy does not contribute to gravity, or by using some supersymmetric variants of such theories.\n\n\\subsection{Vacuum Fluctuations}\nThe fluctuation in the quantum field can be written as,\n$$\\delta \\phi_{\\vb{k}} = \\sqrt{\\expval{\\abs{\\phi_{\\vb{k}}}^2} - \\expval{\\phi_{\\vb{k}}}^2} = \\sqrt{\\expval{\\abs{\\phi_{\\vb{k}}}^2}}$$\nWe know that $$\\phi_{\\vb{k}} = \\frac{a_{\\vb{k}} + a_{-\\vb{k}}}{\\sqrt{2\\omega_k}}$$ which means that \n$$\\abs{\\phi_{\\vb{k}}^2} = \\frac{(a_{\\vb{k}} + a_{-\\vb{k}})(a_{\\vb{k}} + a_{-\\vb{k}})}{{2\\omega_k}}$$\nTaking the ground state expectation value of this expression, one obtains that $\\delta \\phi_{\\vb{k}} \\sim \\omega_k^{-1/2}$. What if we measure the average value of a field over space? Lets consider a cubical box of side $L$  and define the average value $\\phi_L$ as follows,\n$$\\phi_L = \\frac{1}{L^3} \\int_{-L/2}^{-L/2}dx \\int_{-L/2}^{-L/2}dy \\int_{-L/2}^{-L/2}dz \\ \\phi(\\vb{x})$$\nWe again calculate fluctuations in this average value by the formula $\\delta \\phi_L = \\sqrt{\\expval{\\phi_L^2}}$. \n\\begin{flalign*}\n\\phi_L &\\sim \\frac{1}{L^3}  \\int_{-L/2}^{-L/2}dx \\int_{-L/2}^{-L/2}dy \\int_{-L/2}^{-L/2}dz \\ \\int \\phi_{\\vb{k}}(t) e^{i \\vb{k} \\vdot \\vb{x}} d^3\\vb{k}\\\\\n&\\sim \\frac{1}{L^3} \\int \\frac{1}{k_x k_y k_z}\\sin \\frac{k_xL}{2} \\sin \\frac{k_yL}{2} \\sin \\frac{k_zL}{2}  \\  \\phi_{\\vb{k}}(t) e^{i \\vb{k} \\vdot \\vb{x}} d^3\\vb{k}\n\\end{flalign*}\nLet us say that $f_x =\\frac{1}{k_x} \\sin \\frac{k_xL}{2}$ and so forth for $y$ and $z$. $f_x \\rightarrow L/2$ for small $k_x$ and $0$ for large $k_x$. So the contribution to the integral can be taken to be from small $k$, and hence is of the order $L^3$. So $\\delta \\phi_L = \\sqrt{\\expval{\\phi_L^2}} \\sim [(\\delta \\phi_{\\vb{k}})^2 / L^3]^{1/2}$.\n\n\\subsection{Gravity Can Create Particles?}\nConsider a single harmonic oscillator with the following features.\n$$\\underbrace{\\ddot{q}(t) + \\omega^2 q = 0}_{t<0 \\text{ and } t>T} \\text{ ; } \\underbrace{\\ddot{q}(t) - \\Omega^2 q = 0}_{0<t<T}$$\nThe solution, obviously, is\n$$q(t) = \\underbrace{q_1 \\sin(\\omega t)}_{t<0 \\text{ (assume)}} \\text{ ; } \\underbrace{Ae^{\\Omega t} + Be^{-\\Omega t}}_{0<t<T} \\text{ ; } \\underbrace{q_2 \\sin (\\omega t + \\alpha)}_{t>T}$$\nMatching $q(t)$ and $\\dot{q}(t)$ at $t=0,T$, we get the condition,\n$$\\tan(\\omega T + \\alpha) = \\frac{\\omega}{\\Omega} \\text{ ; } q_2 \\sin (\\omega T + \\alpha) = A e^{\\Omega T} \\text{ ; } A = \\frac{q_1}{2} \\frac{\\omega}{\\Omega}$$\n\nHence,\n$$q_2 \\approx \\frac{1}{2} q_1 \\sqrt{1 + \\frac{\\omega^2}{\\Omega^2}} e^{\\Omega T}$$\n\nWe see that the final state has a much larger energy as compared to the initial state, which we, in turn, interpret as the creation of many particles the time interval $[0,T]$. Can we look at how many particles are produced, approximately? The exact relation for the amplitudes (valid at all times) is \n\\bes\nq_2 =  q_1 \\sqrt{1 + \\frac{\\omega^2}{\\Omega^2}} \\sinh \\Omega_0 T\n\\ees\nThe oscillator energies $\\propto q^2$. If we take the initial state to be the ground state, it is straightforward to see that the number of particles $ n  $ produced is \n\\bes\nn = \\dfrac{q_2^2}{q_1^2} = \\qty(1+ \\dfrac{\\omega^2}{\\Omega^2})\\sinh^2 \\Omega_0 T\n\\ees\nHmm, can something of this sort happen in gravity? Let's hope.\n\n\\end{document}", "meta": {"hexsha": "b0ee0172b23d1afc13804b1b2839eaee787b1178", "size": 8146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "selfstudy/qgrav/notes/qgrav.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/qgrav/notes/qgrav.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/qgrav/notes/qgrav.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": 79.0873786408, "max_line_length": 675, "alphanum_fraction": 0.6799656273, "num_tokens": 2803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6845757087656116}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{float}\n\n\\title{\n    EE2703: Applied Programming Lab \\\\\n    \\Large Assignment 3: Linear Least Squares Fitting\n}\n\n\\author{Soham Roy \\\\ \\normalsize EE20B130}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle % Insert the title, author and date\n\n\n\\section{Introduction}\nFor this assignment we use the Bessel function and Gaussian noise to study\nthe effect of changing standard deviation on the linear fitting of the data.\n\\begin{equation*}\n    f(t) = AJ_2(t) + Bt + n(t)\n\\end{equation*}\nWhere, $A = 1.05$, $B = -0.105$, $J_2 =$ Bessel function, $n(t) =$ Noise function.\nOur aim is to relate the error in estimating $A$, $B$ to the\nstandard deviation of the Gaussian noise.\n\n\n\\section{Subquestions}\n\\subsection{Generate the Data}\nOn running the python script \\texttt{generate\\_data.py}, the data is written to\nthe file \\texttt{fitting.dat}. The \\texttt{scipy} library has been used to calculate\nthe Bessel function. The \\texttt{numpy.array t} contains 101 equally spaced numbers\nbetween 0 and 10, which are fed into the Bessel function and added with noise to\ngenerate the data.\n\n\n\\subsection{Load the Data}\nThe data from \\texttt{fitting.dat} is loaded using \\texttt{numpy.loadtxt()}.\nThe first column of \\texttt{raw\\_data} are the time values, and the subsequent\ncolumns are the corresponding noisy data values.\n\\begin{verbatim}\n    raw_data = loadtxt(DATAFILE)\n\n    Time = raw_data[:, 0]\n    F = raw_data[:, 1:]\n\\end{verbatim}\n\n\n\\subsection{The Function and the Noise}\nThe true values are generated using \\texttt{F\\_true = g(Time)},\nwhere the function \\texttt{g(t,A,B)} defined as:\n\\begin{verbatim}\n    def g(t, A=A_true, B=B_true):\n        return A * jn(2, t) + B * t\n\\end{verbatim}\nwhere \\texttt{A\\_true, B\\_true = 1.05, -0.105} are the true values of $A$ and $B$. \\\\\nThe noise is generated using \\texttt{Sigma = logspace(-1, -3, K)}, where\n\\texttt{K = 9} is the number of curves to be plotted.\n\n\n\\subsection{Plot the Data}\nWe plot the data along with the function \\texttt{g(t,A,B)} for\n\\texttt{A=1.05}, \\texttt{B=-0.105}.\n\\begin{verbatim}\n    plot(Time, F)\n    plot(Time, F_true, color='black', lw=2)\n\\end{verbatim}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{Q4.png}\n\\end{figure}\n\n\n\\subsection{Plot with Error Bars}\nA plot of the first column of data with error bars has been generated, with every\n$5^{th}$ data item plotted for readability. The exact curve has also been plotted\nto see how much the data diverges.\n\\begin{verbatim}\n    errorbar(Time[::5], F[::5, 0], Sigma[0], fmt=\"ro\")\n    plot(Time, F_true, color='black', lw=2)\n\\end{verbatim}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{Q5.png}\n\\end{figure}\n\n\n\\subsection{Equate the Vectors}\n\\begin{gather}\n    g(t,A,B) =\n    \\begin{pmatrix}\n        J_2(t_1) & t_1   \\\\\n        \\dots    & \\dots \\\\\n        J_2(t_m) & t_m\n    \\end{pmatrix}\n    \\begin{pmatrix}\n        A \\\\ B\n    \\end{pmatrix}\n    \\equiv\n    M \\cdot P\n    \\label{eq:M}\n\\end{gather}\n\\texttt{F\\_true.reshape(N, 1)} is $g(t,A,B)$, the vector of the true values. \\\\\n\\texttt{M = c\\_[jn(2, Time), Time]} generates $M$, which is multiplied by \\\\\n\\texttt{[[A\\_true], [B\\_true]]}, i.e. $P$, to obtain the RHS vector.\\\\\n\\texttt{assert} ensures that the two vectors are equal by evaluating \\\\\n\\texttt{numpy.allclose()}, as we cannot reliably equate floats.\n\n\n\\subsection{Mean Squared Error}\nThe mean squared error between the data ($f_k$) and the assumed model has been\ncalcuated for every combination of $A$ and $B$, where $A$ and $B$ range from 0 to 1\nand -0.2 to 0 respectively. \\\\\nThe following formula has been implemented:\n\\begin{equation*}\n    \\epsilon_{ij} = \\frac{1}{101} \\sum_{k=0}^{101} (f_k - g(t_k, A_i, B_j))^2\n\\end{equation*}\nby looping over the following line of code:\n\\begin{verbatim}\n    eps[i][j] = mean((F[:, 0] - g(Time, A[i], B[j])) ** 2)\n\\end{verbatim}\n\n\n\\subsection{Plot the MSE}\nThe contour plot has been generated by \\texttt{contour}, and labeled using\n\\texttt{clabel}. Further, the exact location of \\texttt{(A\\_true, B\\_true)} has been\nplotted and annotated.\n\\begin{verbatim}\n    clabel(contour(A, B, eps, 15))\n    plot([A_true], [B_true], \"ro\")\n    annotate(\"Exact location\", xy=(A_true, B_true), size=16)\n\\end{verbatim}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{Q8.png}\n\\end{figure}\n\n\n\\subsection{Best Estimate for A and B}\nThe matrix $M$, defined in Equation \\ref{eq:M}, has been used to find the best estimate\nof $A$ and $B$ for the first column of data. This was done by computing the\nleast-squares solution for it using \\texttt{scipy.linalg.lstsq()} to print:\n\\begin{verbatim}\n\"Best estimate:   A = {}, B = {}\".format(*lstsq(M, F[:, 0])[0])\n\\end{verbatim}\n\n\n\\subsection{Plot the Errors in A, B}\nThe errors in $A$ and $B$ have been calculated by subtracting the true values:\n\\begin{verbatim}\n    Aerr, Berr = abs(lstsq(M, F)[0] - [[A_true], [B_true]])\n\\end{verbatim}\nThese have thus been plotted against the standard deviations of the data:\n\\begin{verbatim}\n    plot(Sigma, Aerr, 'o', linestyle=\"dashed\")\n    plot(Sigma, Berr, 'o', linestyle=\"dashed\")\n\\end{verbatim}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{Q10.png}\n\\end{figure}\n\\pagebreak\n\n\n\\subsection{Plot using log-log Scale}\nThe scale of the graph has been changed to log-log, with an \\texttt{errorbar()} plot:\n\\begin{verbatim}\n    xscale(\"log\")\n    yscale(\"log\")\n    errorbar(Sigma, Aerr, Sigma, fmt=\"o\")\n    errorbar(Sigma, Berr, Sigma, fmt=\"o\")\n\\end{verbatim}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{Q11.png}\n\\end{figure}\n\n\n\\section{Conclusion}\nAs we see from the plots, the error in estimated $A$ and $B$ increases with increase in\nthe standard deviation of the Gaussian noise in the data. Further, we see that the\nincrease is somewhat linear when plotted on a log-log scale.\n\n\n\\end{document}\n", "meta": {"hexsha": "973e25e058e0568e91f116248c48385610bc09df", "size": 5897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment_03/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_03/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_03/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": 31.2010582011, "max_line_length": 87, "alphanum_fraction": 0.6913684925, "num_tokens": 1816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8933094081846421, "lm_q1q2_score": 0.684537320800772}}
{"text": "\\section{Model}\n\nThe TMD system is described by\nthe effective tight-biding, low-energy, two-valley Hamiltonian\n\\cite{PhysRevLett.108.196802},\n\\begin{equation}\n  \\label{eq:hamiltonian}\n  H_τ^0 \\ofK\n  = a t \\left( τ k_x \\hat{σ}_x + k_y \\hat{σ}_y \\right)\n  + \\frac{E_g}{2} \\hat{σ}_z - E_{\\text{soc}} τ \\frac{\\hat{σ}_z - 1}{2} \\hat{s}_z.\n\\end{equation}\nwhere the Pauli matrices $\\hat{s}_i$ operate in the spin space and\n$\\hat{σ}_i$ operate in the orbital space\nwith the two Bloch orbital states $\\ketOrb{ν}{\\ofK}$\n(indexed by $ν = +$ for the in-plane orbital state\n$\\Ket{d_{x^2 - y^2}} + i τ \\Ket{d_{xy}}$\nand $ν = -$ for the out-of-plane orbital state $\\Ket{d_{z^2}}$),\n${\\s} = ±$ is the spin index, and $τ = ±$ is the valley index corresponding\nto the $± \\vc{K}$ point, respectively.\nThe momentum $\\vK = \\left( k_x, k_y \\right)$\nis measured from the valley center, $a$ is the lattice constant,\n$t$ is the hopping parameter, $E_g$ represents the energy\ngap between the conduction and valence bands, and $2E_{\\text{soc}}$ is the\nspin splitting energy in the valence bands due to spin-orbit interaction.\n\nThe energy spectrum,\n\\begin{equation}\n  \\label{eq:energy}\n  2 \\fnEnergy{n} \\of{k}\n  = τ {\\s} E_{\\text{soc}} + n \\sqrt{{\\left( 2 a t k \\right)}^2\n  + {\\left( E_g - τ {\\s} E_{\\text{soc}} \\right)}^2}.\n\\end{equation}\nwith $k = \\abs{\\vK}$\nand $n = 1$ ($n = -1$) indexing the conduction (valence) band\nis shown in \\cref{fig:energy}.\n\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{figures/energy-bands}\n  \\caption{%\n    Energy bands for $\\ce{WSe2}$ as given by \\cref{eq:energy}\n    with $a t = \\SI{3.939}{\\electronvolt \\per \\angstrom}$,\n    $E_g = \\SI{1.60}{\\electronvolt}$,\n    and $E_{\\text{soc}} = \\SI{0.23}{\\electronvolt}$.\n    Each valley is centered at $± \\vc{K}$ relative to the center of the\n    Brillouin zone.\n    The energy for a given band depends only on the distance $k$\n    measured from the valley center.\n  }\\label{fig:energy}\n\\end{figure}\n\nWe focus on doped systems\nsuch that the chemical potential $μ$ lies in the upper valence bands.\nWithin each band, the Bloch basis eigenstates are written\nin terms of the orbital states as elements on the Block sphere,\n\\begin{equation}\n  \\begin{aligned}\n    \\Ket{u_{τ {\\s}}^n \\of{k, ϕ}}\n    = & \\cos{\\frac{\\fnTheta{n}}{2}} \\ketOrb{+}{\\of{k, ϕ}} \\\\\n    + e^{-i τ ϕ}\n      & \\sin{\\frac{\\fnTheta{n}}{2}} \\ketOrb{-}{\\of{k, ϕ}},\n  \\end{aligned}\n\\end{equation}\nwhere $k_x + i τ k_y = k e^{i τ ϕ}$ and\n\\begin{equation}\n  \\tan{\\frac{\\fnTheta{n}}{2}}\n  = \\frac{a t τ k}{\\dfrac{E_g}{2} - \\fnEnergy{-n} \\of{k}}\n  = \\frac{a t τ k}{\\fnEnergy{n} \\of{k} - \\fnEnergy{-} \\of{0}}.\n\\end{equation}\nThe polar angle on the Bloch sphere\nof the conduction and valence bands are related by\n$\\fnTheta{-} - \\fnTheta{+} = τ π$.\nThe mapping of the energy band to the Bloch sphere,\nparametrized by $\\left( θ, ϕ \\right)$,\nencodes the topological character:\nas one moves from the node out to infinity,\nthe states sweep either the northern or southern hemisphere\nwith a chirality determined by the Berry curvature.\n", "meta": {"hexsha": "e704982bc1cf9ecd3d3783cd8c2aaae93f5a9c23", "size": 3040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/_model.tex", "max_stars_repo_name": "razor-x/aps-dichalcogenides-superconductivity", "max_stars_repo_head_hexsha": "311fab11004ecf5efd79f0fbbe48a5f6f3b62da8", "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": "tex/_model.tex", "max_issues_repo_name": "razor-x/aps-dichalcogenides-superconductivity", "max_issues_repo_head_hexsha": "311fab11004ecf5efd79f0fbbe48a5f6f3b62da8", "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/_model.tex", "max_forks_repo_name": "razor-x/aps-dichalcogenides-superconductivity", "max_forks_repo_head_hexsha": "311fab11004ecf5efd79f0fbbe48a5f6f3b62da8", "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": 38.9743589744, "max_line_length": 81, "alphanum_fraction": 0.6648026316, "num_tokens": 1064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6844352810408786}}
{"text": "\\subsection{Space Partitioning}\n\\subsubsection{Description of the Algorithm}\nThe main idea is a combination of the divide and conquer principle and\nthe convex hull. The algorithm divides the point cloud by a line and\nrecursively process those sets. Finally the points of the sets were\npushed to the polygon. The fact that every set has a convex hull that\nhas only one point in common with adjacent sets guarantees a simple\npolygon.\n\\\\[12pt]\nFollowing a description of the algorithm in detail:\n\n\\begin{enumerate}\n  \\item select two points\n  \\item divide the point cloud by a line through those points \\fref{sp:line}\n  \\item recursively process those two sets of points \\fref{sp:line2} to \\fref{sp:line5}\n  \\begin{enumerate}\n    \\item exit point set of points == 2 || == 3 push points on the final list\n    \\item calculate a random point\n    \\item calculate a random line with this point\n    \\item divide the point cloud by that line\n  \\end{enumerate}\n\\end{enumerate}\n\n\\subsubsection{Implementation description}\n\\begin{enumerate}\n  \\item a random function selects two points ($s_l$ and $s_f$). Point $s_l$ is the\n    first point in rotation direction and $s_f$ the second point.\n  \\item to divide the point cloud in two independent sets we create a\n    line through the two points. The \\textit{Line\\_2} class from the cgal\n    framework has a \\textit{has\\_on\\_positive} and \\textit{has\\_on\\_negative} function.\n    With these it is possible to distinguish between a point of one or\n    the other side of the line.\n  \\item with the created sets we call recursivelly the function\n    \\textit{recursiveDivide} and give the function the created set $S$, point $s_f$,\n    point $s_l$ and the polygon $C$. One call has as first element $s_f$ the other has $s_l$\n    as first element of the two points. This is necessary to close the\n    polygon.\n  \\begin{enumerate}\n    \\item there are two exit points of the \\textit{recursiveDivide} function.\n      The first is with set \\textit{S.size == 2} and pushs the point $s_l$ to the\n      polygon $C$. The second is with set \\textit{S.size == 3}. Here we have to\n      search the third point $s$, which is not $s_l$ or $s_f$ and then we\n      could push $s$ and $s_l$ to the polygon $C$.\n    \\item if the exit points does not occure we calculate a random\n      point. The random point should be selected randomly. The\n      condition is that it is not a point equal to and not collinear\n      with $s_f$ and $s_l$. The next step is to calculate a random line\n      through the point s and a point of the line through $s_f$ and\n      $s_l$. Essentially is that $s_f$ lies on the positive side of the\n      calculated random line.\n    \\item the division of the set is equal as in the parent function\n  \\end{enumerate}\n\\end{enumerate}\n\n\\subsubsection{Complexity}\n$\\bigO(n^2)$ if it is done in a good way then it should be $\\bigO(nlogn)$\n\n\\subsubsection{Parameters}\n\\begin{description}\n  \\item [--nodes] how many nodes the polygon has to have. [default: 100]\n  \\item [--sampling-grid] the area within the polygon could grow. [default: 1500x800]\n\\end{description}\n\n\\subsubsection{Examples}\n\n\\begin{figure}[ht]\n  \\centering\n\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(5,40),(10,20),(20,41),(21,10),(33,15),(39,22),(48,9),(55,17),(68,19)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n    \\end{tikzpicture}\n    \\caption{Base random point cloud}\n    \\label{fig:sp:base}\n  \\end{minipage}\\hfill\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(5,40),(10,20),(20,41),(21,10)} {\n        \\node[point, fill=red] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\foreach \\p in {(33,15),(39,22)} {\n        \\node[point, fill=violet] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\foreach \\p in {(48,9),(55,17),(68,19)} {\n        \\node[point, fill=blue] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\path (5) -- (6) coordinate[pos=-3.5](dd) coordinate[pos=10](ff);\n      \\draw[green, dashed] (dd) -- (5);\n      \\draw[green] (5) node[right=1pt, black] {$s_f$} -- (6) node[left=1pt, black] {$s_l$};\n      \\draw[green, dashed] (6) -- (ff);\n    \\end{tikzpicture}\n    \\caption{First two points with the line and the two sets. Points on the line are in both sets.}\n    \\label{fig:sp:line}\n  \\end{minipage}\n\\end{figure}\n\n\\begin{figure}[ht]\n  \\centering\n\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(5,40),(10,20),(20,41),(21,10),(33,15),(39,22),(48,9),(55,17),(68,19)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw[green] (5) node[right=1pt, black] {$s_f$} -- node[placeholder](a){} (6) node[right=1pt, black] {$s_l$};\n      \\draw[red] (a) -- (1) node[right=1pt, black] {$s$};\n    \\end{tikzpicture}\n    \\caption{First split of left set}\n    \\label{fig:sp:line2}\n  \\end{minipage}\\hfill\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(5,40),(10,20),(20,41),(21,10),(33,15),(39,22),(48,9),(55,17),(68,19)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (5) -- node[placeholder](a){} (6);\n      \\draw (a) -- node[placeholder](b){} (1);\n      \\draw (2) -- (b);\n    \\end{tikzpicture}\n    \\caption{Second split of left set}\n    \\label{fig:sp:line3}\n  \\end{minipage}\n\\end{figure}\n\n\\begin{figure}[ht]\n  \\centering\n\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(5,40),(10,20),(20,41),(21,10),(33,15),(39,22),(48,9),(55,17),(68,19)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (5) -- node[placeholder](a){} (6);\n      \\draw (a) -- node[placeholder](b){} (1);\n      \\draw (2) -- (b);\n      \\draw (8) -- (a);\n    \\end{tikzpicture}\n    \\caption{First split of right set}\n    \\label{fig:sp:line4}\n  \\end{minipage}\\hfill\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(5,40),(10,20),(20,41),(21,10),(33,15),(39,22),(48,9),(55,17),(68,19)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (5) -- (4) -- (2) -- (1) -- (3) -- (6) -- (9) -- (8) -- (7) -- (5);\n    \\end{tikzpicture}\n    \\caption{Final polygon}\n    \\label{fig:sp:line5}\n  \\end{minipage}\n\\end{figure}\n\n\\FloatBarrier\n", "meta": {"hexsha": "ee4cf1215e97fac55d48d9748f97063a5a62faca", "size": 7263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/space_partitioning.tex", "max_stars_repo_name": "utnapischtim/polygon", "max_stars_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/space_partitioning.tex", "max_issues_repo_name": "utnapischtim/polygon", "max_issues_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/space_partitioning.tex", "max_forks_repo_name": "utnapischtim/polygon", "max_forks_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1343283582, "max_line_length": 115, "alphanum_fraction": 0.602918904, "num_tokens": 2477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6844256708496317}}
{"text": "\n\\subsection{The cross-sectional model}\n\n\\subsubsection{Hierarchical data}\n\nOur standard linear model is:\n\n\\(y_i=\\alpha + X_i\\theta +\\epsilon_i\\)\n\nIf we had two sets of data we could view these as:\n\n\\(y_{i,0}=\\alpha_0 + X_{i,0}\\theta_0 +\\epsilon_{i,0}\\)\n\n\\(y_{i,1}=\\alpha_1 + X_{i,1}\\theta_1 +\\epsilon_{i,1}\\)\n\nHere, the data data from \\(1\\) does not affect the parameters in \\(2\\).\n\n\\subsubsection{Pooled data}\n\nIf we think the data generating process is similar between models, then by restricting the freedom of parameters between models we can get more data for each estimate.\n\nFor example if we think that all parameters are the same between the models we can estimate:\n\n\\(y_{i,0}=\\alpha + X_{i,0}\\theta +\\epsilon_{i,0}\\)\n\n\\(y_{i,1}=\\alpha + X_{i,1}\\theta +\\epsilon_{i,1}\\)\n\nOr:\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta + \\epsilon_{ij}\\)\n\n\\subsubsection{Fixed slopes}\n\nIntercepts may be different between the groups. In this case we can instead use the model:\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta + \\xi_j + \\epsilon_{ij}\\)\n\nThere are different ways of estimating this model:\n\n\\begin{itemize}\n\\item Pooled OLS\n\\item Fixed effects\n\\item Random effects\n\\end{itemize}\n\n", "meta": {"hexsha": "ddf60dff6e9947895d9b7400110ae58465fc33e2", "size": 1156, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generalLinearModels/01-01-groups.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generalLinearModels/01-01-groups.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generalLinearModels/01-01-groups.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.1304347826, "max_line_length": 167, "alphanum_fraction": 0.7110726644, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6844256598860283}}
{"text": "\\lab{Fourier Transform Extensions}{Fourier Transform Extensions}\n\\objective{Learn about two particular extensions of the Fourier Transform: cepstral analysis and the two-dimensional\nFFT.}\n\nThe ideas at the basis of the one dimensional Fourier Transform that you explored in previous labs can be\nextended in many ways to a variety of different settings.\nOne way to extend the Fourier Transform, which is a linear theory, is to compose it with non-linear operations.\nThis is the basis of Cepstral Analysis, which we will briefly discuss and then apply to the study of sound signals.\nAnother way to generalize the basic Fourier Transform is to move into higher dimensions, which we do when exploring the two-dimensional FFT.\nAlthough we only address these two topics in this lab, keep in mind that the Fourier Transform and its generalizations are central to the mathematical field of harmonic analysis as well as myriad applications in physics, engineering, statistics, and other fields.\n\n\\subsection*{The Fourier Transform in Python}\nSciPy includes the module \\li{scipy.fftpack} that contains several useful and easy to use functions\nfor calculating the Fourier Transform and its variants.\nRefer to the documentation to learn about the available tools.\nThis module does not, however, take full advantage of the optimizations provided by the FFTW library written in the C programming language.\nWe recommend PyFFTW, a Python module that is built around FFTW.\nFor convenience, the submodule \\li{pyfftw.interfaces.scipy_fftpack} mimics the\n\\li{scipy.fftpack} module, containing the same functions with the same interfaces, just higher-performance.\n\n\\subsection*{Cepstral Analysis and Mel-Frequency Cepstral Coefficients}\n\nWhen analyzing complex sound signals such as speech or music, the simple spectral information provided by\nthe Fourier Transform by itself is often insufficient.\nFor example, while the Fourier Transform does reveal the prominent frequencies in a sound signal, it does a poor job of highlighting the more subjective\ntonal qualities, or \\emph{timbre}, of the signal (qualities that help us distinguish between different singers\nor different musical instruments).\n\nCepstral analysis was developed to partially redress this situation, and it provides a collection of signal\nprocessing techniques that go beyond the basic Fourier Transform.\nThe basic idea is to analyze the \\emph{cepstrum} of a signal as opposed to the \\emph{spectrum} (which is the approach of basic Fourier analysis).\nThere are various ways to define the cepstrum, and they all involve composing the Fourier Transform with non-linear operations.\nGiven a signal $f(t)$, the \\emph{Power Cepstrum} is defined by\n$$\n\\left|\\mathcal{F}^{-1}\\{\\log(|\\mathcal{F}(f(t))|^2)\\}\\right|^2,\n$$\nwhere $\\mathcal{F}$ denotes the Fourier transform. The \\emph{Complex Cepstrum} is defined by\n$$\n\\mathcal{F}\\{\\log(\\mathcal{F}(f(t)))+j2\\pi m\\},\n$$\nwhere $j$ is the imaginary unit and $m$ is a carefully chosen integer, and the \\emph{Real Cepstrum}\nis defined by\n$$\n\\mathcal{F}^{-1}\\{\\log(|\\mathcal{F}(f(t))|^2)\\}.\n$$\nThe usefulness of each type of Cepstrum is determined by the theoretical setting or the application.\nThe complex Cepstrum has the interesting and useful property of transforming the convolution operation into an additive operation.\nIn particular, if $f$ and $g$ are signals with corresponding complex cepstra $f'$ and $g'$, and if $*$ represents the convolution operation, we have\n$$\nf * g \\rightarrow f' + g'.\n$$\nThe reason for this relies on the fact that convolution can be converted to multiplication by the Fourier transform, and when the logarithm is applied it becomes addition.\nThis is useful when trying to separate two signals that have been convolved with each other, such as a source and a filter, a problem known as \\emph{deconvolution}.\nOther uses for the various cepstra include fundamental pitch detection in speech signals, voice identification, and analysis of signals containing echoes.\n\nAs a side note, the field of Cepstral analysis comes with its own distinctive jargon, including ``cepstrum\",\n``quefrency\", ``liftering\", and ``alanysis\". These are derived, respectively, from ``spectrum\",\n``frequency\", ``filtering\", and ``analysis\". See Figure \\ref{fourierext:pc} for an example of the Power\nCepstrum.\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[t]{.4\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{OriginalSignal.pdf}\n\\caption*{Original Signal}\n\\end{subfigure}\n~\n\\begin{subfigure}[t]{.4\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{FourierTransform.pdf}\n\\caption*{Fourier Transform}\n\\end{subfigure}\n\n\\begin{subfigure}[t]{.4\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{SquaredLog.pdf}\n\\caption*{Squared Log}\n\\end{subfigure}\n~\n\\begin{subfigure}[t]{.4\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{PowerCepstrum.pdf}\n\\caption*{Power Cepstrum}\n\\end{subfigure}\n\n\\caption{Example of the steps in calculating the Power Cepstrum.}\n\\label{fourierext:pc}\n\\end{figure}\n\n\\begin{problem}\nWrite a function \\li{powerCepstrum} that accepts a one-dimensional array $f$ and computes the\npower cepstrum of $f$, according to the definition given above.\n\nBecause you need to use the log function in the process, you will want to set all values of the Fourier transform below a certain threshold to that threshold value (i.e. get rid of 0's).\nFor our purpose, set this threshold to the value \\li{1e-100}.\n\\end{problem}\n\nWe now turn our attention to the computation of \\emph{Mel-frequency cepstral coefficients} (MFCCs), which\nare data useful in signal classification problems such as speech recognition and automatic musical instrument classification.\n\nExpressed in simple terms, calculating the MFCCs involves splitting the signal up into a sequence of\nshort segments called \\emph{frames}, calculating a variant of the Power Cepstrum for each one,\nand reducing the dimensionality of the results through a process called \\emph{binning}.\nWhat we are left with is a collection of numbers that summarizes each of the frames, with the hope that these\nnumbers capture important spectral and timbral information about the original signal.\n\nSuppose we have a sound signal 2 seconds long sampled at a standard rate of 44100 Hz, which means the\nsignal has 88200 entries.\nThe  MFCCs are obtained through a series of steps, which are outlined\nas follows:\n\n\\begin{itemize}\n\\item \\emph{Windowing}. This refers to splitting up the original signal into a sequence of overlapping\nshort segments called frames, and then applying a so-called \\emph{window-function}, which scales down\nthe edges of the frames.\n\nIn the particular case at hand, we wish to split up the signal into frames approximately 30 ms in\nduration, with adjacent frames overlapping by 20 ms.\nThis means splitting our signal into $198$ frames, each frame containing $1323$ values from the original signal, overlapping $882$ values with each frame\nimmediately preceding and following it.\nWe then multiply each frame by a \\emph{Hamming} window of length 1323 (we have provided the code to calculate a Hamming window of a given length).\nSee Figure \\ref{fourierext:ham} for an example of the Hamming window applied to a signal.\n\n\\begin{figure}\n\\centering\n\n\\begin{subfigure}[t]{.3\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{HammingWindowFunction.pdf}\n\\caption*{Hamming Window Function}\n\\end{subfigure}\n~\n\\begin{subfigure}[t]{.3\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{Original.pdf}\n\\caption*{Original Signal}\n\\end{subfigure}\n~\n\\begin{subfigure}[t]{.3\\textwidth}\n\\centering\n\\includegraphics[height=1.2in]{WindowedSignal.pdf}\n\\caption*{Windowed Signal}\n\\end{subfigure}\n\n\\caption{The Hamming Window.}\n\\label{fourierext:ham}\n\\end{figure}\n\n\\begin{problem}\nWrite a function \\li{window} that accepts a 2-second sound signal with sample rate 44100, and\nreturns a list of the 198 windowed frames calculated as in the description above.\n\\end{problem}\n\n\\item \\emph{Pre-emphasis and Power Spectrum}. For each frame $\\tilde{f}$, we next apply\na filtering process known as \\emph{pre-emphasis} used to improve the signal-to-noise ratio as follows:\n\\begin{equation*}\n\\widehat{f}_{n} = \\tilde{f}_{n} - 0.95 \\tilde{f}_{n-1}\n\\end{equation*}\nfor $n = 1,\\ldots,1322$, and $\\widehat{f}_0 = \\tilde{f}_0$ (in Python, this can be done in one line of code using vectorization).\nWe then compute the \\emph{power spectrum} of the result, which is the square of the magnitude of the Fourier transform.\n\n\\begin{problem}\nWrite a function \\li{powerSpectrum} that accepts a frame (one dimensional array of length 1323) and\napplies pre-emphasis and then computes the power spectrum of the result.\nIn this computation, pad the frame with zeros so that it is of length 2048 when computing the fourier transform.\nThis can be done by using the keyword argument \\li{n = 2048} when calling \\li{pyfftw.interfaces.scipy_fftpack.fft}.\nFurthermore, only return the first 1025 entries of the result, since the remaining entries are just a mirror image of the first half.\n\\end{problem}\n\n\\item \\emph{Mel Scale}. The Mel Frequency scale is based on human perception of pitch.\nIt maps frequency in Herz to a slightly distorted scale where equal distances between values correspond to equal perceived differences in pitch.\nUsing matrix multiplication, we will map the power spectrum of each frame to mel scale bins, thereby reducing the dimensionality of the frames and representing them in a scale more closely aligned with human perception of pitch.\nSee Figure \\ref{fourierext:mel} for a depiction of the Mel Scale as well as a typical Mel filterbank, which defines the binning process.\n\nWe have provided the code to calculate the required mel scale matrix (use 40 filters, with FFT length 2048 and sample rate 44100).\nBefore we perform this multiplication, however, we first want to prevent underflow problems.\nWe therefore want to set all values of the power spectrum below a certain threshold to that threshold value.\nFor our purposes, we will set this threshold value to \\li{1e-100}.\n\n\\item \\emph{Discrete Cosine Transform}. To complete the process, we take the Discrete Cosine Transform\nof the \\emph{logarithm} of the resulting mel scale power spectrum frames, multiply the result by 0.25, and retain only entries 2\nthrough 11 (yielding an array of length 10), since these are the entries that contain most of the desired information.\nThe Discrete Cosine Transform is very similar to the Fourier Transform, but only uses\ncosine functions rather than a combination of cosine and sine functions in the series expansion of the signal.\nIn many cases, sums of cosine functions alone can more efficiently represent a signal than\nsums of both sine and cosine functions.\n\\end{itemize}\n\n\nAfter this process, we should end up with a list of 198 arrays, each of length 10. These are our MFCCs,\nwhich can then be used in various classification algorithms.\n\n\\begin{problem}\nWrite a function \\li{extract} which accepts an array of length 88200 (representing a two second sound sample\nwith rate 44100 Hz), and returns an array of shape (198,10), where each row gives the calculated MFCCs for\na particular windowed frame of the original signal.\nUse your previous solutions as you see fit, and try to avoid unnecessary looping.\n\nHint: If M is the mel scale matrix and X is the power spectrum of the original signal, use \\li{np.dot(M,X)} to get the mel scale power spectrum frames.\nUse \\li{pyfftw.interfaces.scipy_fftpack.dct()} to compute the Discrete Cosine Transform.\n\\end{problem}\n\n\\begin{figure}\n\n\\begin{subfigure}{\\textwidth}\n\\centering\n\\includegraphics[ trim=0in 3in 0in 0in, clip, height=1.8in]{MelScale.pdf}\n\\end{subfigure}\n\n\\begin{subfigure}{\\textwidth}\n\\centering\n\\includegraphics[trim = 0in 0in 0in 3in, clip, height=1.8in]{MelScale.pdf}\n\\end{subfigure}\n\n\\caption{The Mel Scale and Mel Filterbank.}\n\\label{fourierext:mel}\n\\end{figure}\n\n\\subsection*{The 2-dimensional FFT}\n\nYou know how to calculate the Fourier Transform for one-dimensional signals.\nIn fact, the theory of Fourier Transforms may be readily extended to any number of dimensions.\nComputationally, the problem reduces to performing the one-dimensional Fourier Transform iteratively\nalong each of the dimensions.\nWe will focus on calculating the Fourier Transform of two-dimensional matrices.\nIn this setting, we think of the matrices not as functions of time, but rather as functions of\nspace.\nOnce we have the 2-dimensional Fourier Transform, we can perform many useful operations for\ndenoising, compression, edge-detection, image enhancement, and more.\n\nGiven a matrix $A$, we first calculate the one-dimensional Fourier Transform of each column, storing the\nresult column-wise in an array the same shape as $A$.\nWe then calculate the Fourier Transform of each row of this resulting array, and this yields the two-dimensional Fourier Transform of $A$.\n\nCalculating the two-dimensional inverse Fourier Transform is done in a similar fashion, but in the\noppositie order: first calculate the inverse Fourier Transform of the rows, then the columns.\n\n\\begin{problem}\nWrite a function \\li{fft2} that accepts a two-dimensional array as input and returns the two-dimensional Fourier Transform of the input.\nYou may use built-in methods to calculate the one-dimensional Fourier Transform.\n\nWrite another function \\li{ifft2} that accepts a two-dimensional array as input and returns the two-dimensional inverse Fourier Transform.\nOnce again, you may use built-in methods to calculate the one-dimensional inverse Fourier Transform.\n\\end{problem}\n\n\\begin{figure}\n\\begin{subfigure}[t]{0.4\\textwidth}\n\\centering\n\\includegraphics[height=1.5in]{ecoli.jpg}\n\\caption*{E. Coli Image}\n\\end{subfigure}\n~\n\\begin{subfigure}[t]{0.4\\textwidth}\n\\centering\n\\includegraphics[height=1.5in]{ecoliFFT.pdf}\n\\caption*{FT of E. Coli Image}\n\\end{subfigure}\n\\caption{The 2D Fourier Transform Applied to Images.}\n\\label{fourierext:2dfft}\n\\end{figure}\n\nWe can visualize the two-dimensional Fourier Transform as follows:\n\\begin{lstlisting}\nimport numpy as np\nimport pyfftw\nfrom matplotlib import pyplot as plt\n\n# In the following, F is the output of 2dFFT\n# Shift values in F for optimal visualization\nF_s = pyfftw.interfaces.scipy_fftpack.fftshift(F)\n\n# Convert all values to nonnegative real numbers\nF_mag = np.abs(F_s)\n\n# Scale the values, then amplify\namp = 1000 # you may want to test other values for amp\nF_mag *= amp/F_mag.max()\n\n# Set values larger than 1 to 1\nF_mag[F_mag > 1] = 1\n\n# Plot the result\nplt.imshow(F_mag, plt.cm.Greys)\nplt.show()\nplt.clf()\n\\end{lstlisting}\n\n\n\nSee Figure \\ref{fourierext:2dfft} for an example.\nThe visualization indicates the relative strengths of various frequencies in the original image.\nAs you will notice, the largest values of the fourier transform are concentrated near the center of each visualization, which tells us that the original images are\ncomposed mostly of smaller frequencies.\nThe presence of higher frequencies is indicated by values farther away from the center of the visualization, and these account for the\nfiner details of the original images.\n%Does anyone know of a better way to intuitively describe these visualizations?", "meta": {"hexsha": "050c286644eb5d60d95ed59834568381f1aa554a", "size": 15140, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FourierExtensions/FourierExtensions.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/FourierExtensions/FourierExtensions.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/FourierExtensions/FourierExtensions.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": 50.9764309764, "max_line_length": 263, "alphanum_fraction": 0.7891017173, "num_tokens": 3699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.6842925732780342}}
{"text": "\n\\subsection{Order and size of graphs}\n\nThe order of a graph is the number of vertices, \\(|V|\\).\n\nThe size of a graph is the number of edges, \\(|E|\\).\n\n", "meta": {"hexsha": "1a97a02f444029e56b0fd0b237ed350883383c22", "size": 152, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/graph/01-02-order.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-02-order.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-02-order.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.0, "max_line_length": 56, "alphanum_fraction": 0.6710526316, "num_tokens": 42, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.6842925578764074}}
{"text": "\\paragraph{Question 1.}\n\nLet the alphabet \\(\\Sigma = \\{a, b\\}\\) and the following regular\nexpressions:\n\\begin{align*}\n  r &= a \\lparen a \\, \\disjM{} \\, b \\rparen\\kleeneM{} ba,\\\\\n  s &= \\lparen ab \\rparen\\kleeneM{} \\, \\disjM{} \\, \\lparen ba\n  \\rparen\\kleeneM{} \\, \\disjM{} \\, \\lparen a\\kleeneM{} \n  \\, \\disjM{} \\, b\\kleeneM\\rparen.\n\\end{align*}\nThe language denoted by~\\(r\\) is noted \\(L(r)\\) and the language\ndenoted by~\\(s\\) is noted \\(L(s)\\). Find a word~\\(x\\) such that\n\\begin{enumerate*}\n\n  \\item \\(x \\in L(r)\\) and \\(x \\not\\in L(s)\\),\n\n  \\item \\(x \\not\\in L(r)\\) and \\(x \\in L(s)\\),\n\n  \\item \\(x \\in L(r)\\) and \\(x \\in L(s)\\),\n\n  \\item \\(x \\not\\in L(r)\\) and \\(x \\not\\in L(s)\\).\n\n\\end{enumerate*}\n", "meta": {"hexsha": "658846b047cdadf56beb9e577e10194caaca2019", "size": 702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regexp_question_01.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_01.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_01.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": 29.25, "max_line_length": 64, "alphanum_fraction": 0.5598290598, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6842925565588234}}
{"text": "\\subsection{Transfinite arithmetic}\\label{subsec:transfinite_arithmetic}\n\nOur purpose is to extend natural number arithmetic to ordinals and cardinals. It turns out that the two are rather different. We will first introduce some additional concepts, however.\n\n\\begin{definition}\n  Let \\( A \\) and \\( B \\) be sets of \\hyperref[def:ordinal]{ordinals}. We say\n\\end{definition}\n\n\\begin{definition}\\label{def:ordinal_arithmetic}\n  We recursively define arithmetic operations for arbitrary \\hyperref[def:ordinal]{ordinals} as extensions of the corresponding operations of \\hyperref[def:peano_arithmetic]{Peano arithmetic}.\n\n  \\begin{thmenum}\n    \\thmitem{def:ordinal_arithmetic/addition}\\mcite[lemma 66.6]{OpenLogicFull} The \\term{sum} of \\( \\alpha \\) and \\( \\beta \\) extends \\eqref{eq:def:peano_arithmetic/PA4} and \\eqref{eq:def:peano_arithmetic/PA5} with a case for limit ordinals:\n    \\begin{equation}\\label{eq:def:ordinal_arithmetic/addition}\n      \\alpha + \\beta \\coloneqq \\begin{cases}\n        \\alpha,                                            &\\beta = 0 \\\\\n        \\op{succ}(\\alpha + \\gamma),                        &\\beta = \\op{succ}(\\gamma) \\\\\n        \\sup\\set{ \\alpha + \\gamma \\given \\gamma < \\beta }, &\\beta \\T{is a limit ordinal} \\\\\n      \\end{cases}\n    \\end{equation}\n\n    From \\fullref{thm:union_of_set_of_ordinals} it follows that the in limit case \\( \\alpha + \\beta \\) is the smallest ordinal strictly larger than \\( \\alpha + \\gamma \\) for any \\( \\gamma < \\beta \\).\n\n    \\thmitem{def:ordinal_arithmetic/multiplication}\\mcite[lemma 66.13]{OpenLogicFull} Analogously, the \\term{product} of \\( \\alpha \\) and \\( \\beta \\) extends \\eqref{eq:def:peano_arithmetic/PA6} and \\eqref{eq:def:peano_arithmetic/PA7}:\n    \\begin{equation}\\label{eq:def:ordinal_arithmetic/multiplication}\n      \\alpha \\cdot \\beta \\coloneqq \\begin{cases}\n        0,                                                     &\\beta = 0 \\\\\n        \\alpha \\cdot \\gamma + \\alpha,                          &\\beta = \\op{succ}(\\gamma) \\\\\n        \\sup\\set{ \\alpha \\cdot \\gamma \\given \\gamma < \\beta }, &\\beta \\T{is a limit ordinal} \\\\\n      \\end{cases}\n    \\end{equation}\n\n    \\thmitem{def:ordinal_arithmetic/exponentiation}\\mcite[lemma 66.16]{OpenLogicFull} Exponentiation extends \\fullref{def:unital_magma/exponentiation}:\n    \\begin{equation}\\label{eq:def:ordinal_arithmetic/exponentiation}\n      \\alpha^\\beta \\coloneqq \\begin{cases}\n        1,                                               &\\beta = 0 \\\\\n        \\alpha^\\gamma \\cdot \\alpha,                      &\\beta = \\op{succ}(\\gamma) \\\\\n        \\sup\\set{ \\alpha^\\gamma \\given \\gamma < \\beta }, &\\beta \\T{is a limit ordinal} \\\\\n      \\end{cases}\n    \\end{equation}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:ordinal_successor_via_addition}\n  For any ordinal \\( \\alpha \\) we have\n  \\begin{equation*}\n    \\op{succ}(\\alpha)\n    \\reloset {\\ref{eq:def:ordinal_arithmetic/addition}} =\n    \\op{succ}(\\alpha + 0)\n    \\reloset {\\ref{eq:def:ordinal_arithmetic/addition}} =\n    \\alpha + \\op{succ}(0)\n    =\n    \\alpha + 1.\n  \\end{equation*}\n\n  We will occasionally use the later notation.\n\n  Note that for infinite ordinals \\( \\op{succ}(\\alpha) = 1 + \\alpha \\) as discussed in \\fullref{ex:ordinal_addition}.\n\n  This is an extension of \\fullref{rem:natural_number_successor_via_addition}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:ordinal_addition_is_monotone}\n  \\hyperref[def:ordinal_arithmetic/addition]{Ordinal addition} has the following monotonicity properties:\n  \\begin{thmenum}\n    \\thmitem{thm:ordinal_addition_is_monotone/left} Left addition is \\hyperref[eq:def:partially_ordered_set/homomorphism/strict]{strictly monotone}:\n    \\begin{equation}\\label{eq:thm:ordinal_addition_is_monotone/left}\n      \\alpha < \\beta \\T{implies} \\gamma + \\alpha < \\gamma + \\beta.\n    \\end{equation}\n\n    \\thmitem{thm:ordinal_addition_is_monotone/right} Right addition is \\hyperref[eq:def:partially_ordered_set/homomorphism/nonstrict]{nonstrictly monotone}:\n    \\begin{equation}\\label{eq:thm:ordinal_addition_is_monotone/right}\n      \\alpha < \\beta \\T{implies} \\alpha + \\gamma \\leq \\beta + \\gamma.\n    \\end{equation}\n\n    See \\fullref{ex:ordinal_addition} for examples where the strict inequality fails.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:ordinal_addition_is_monotone/left} We proceed by induction on \\( \\beta \\).\n  \\begin{itemize}\n    \\item The condition \\( \\alpha < \\beta \\) is vacuously false for the base case \\( \\beta = 0 \\), hence by \\eqref{eq:def:intuitionistic_propositional_deductive_systems/rules/efq} the statement vacuously holds.\n\n    \\item Fix some nonzero \\( \\beta \\) and some \\( \\alpha < \\beta \\). If \\( \\gamma + \\alpha < \\gamma + \\beta \\), then\n    \\begin{equation*}\n      \\gamma + \\alpha < \\gamma + \\beta < \\op{succ}(\\gamma + \\beta) = \\gamma + \\op{succ}(\\beta).\n    \\end{equation*}\n\n    Since \\( \\beta < \\op{succ}(\\beta) \\), we have used the inductive hypothesis to conclude that\n    \\begin{equation*}\n      \\alpha < \\op{succ}(\\beta) \\T{implies} \\gamma + \\alpha < \\gamma + \\op{succ}(\\beta).\n    \\end{equation*}\n\n    \\item Let \\( \\lambda \\) be a limit ordinal and suppose that \\eqref{eq:thm:ordinal_addition_is_monotone/left} holds for all \\( \\beta < \\lambda \\). Let \\( \\alpha < \\lambda \\). Then \\( \\op{succ}(\\alpha) < \\lambda \\) since \\( \\lambda \\) is a limit ordinal and thus\n    \\begin{equation*}\n      \\gamma + \\alpha\n      <\n      \\gamma + \\op{succ}(\\alpha)\n      \\leq\n      \\sup\\set{ \\gamma + \\beta \\given \\beta < \\lambda }\n      =\n      \\gamma + \\lambda.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\SubProofOf{thm:ordinal_addition_is_monotone/right} We proceed by induction on \\( \\gamma \\).\n  \\begin{itemize}\n    \\item The base case \\( \\gamma = 0 \\) is vacuous.\n    \\item If \\( \\alpha + \\gamma < \\beta + \\gamma \\), then\n    \\begin{equation*}\n      \\alpha + \\op{succ}(\\gamma)\n      \\reloset {\\eqref{eq:def:ordinal_arithmetic/addition}} =\n      \\op{succ}(\\alpha + \\gamma)\n      \\reloset {\\ref{thm:ordinal_successor_strictly_monotone_on_ordinals}} <\n      \\op{succ}(\\beta + \\gamma)\n      \\reloset {\\eqref{eq:def:ordinal_arithmetic/addition}} =\n      \\beta + \\op{succ}(\\gamma).\n    \\end{equation*}\n\n    \\item Let \\( \\lambda \\) be a limit ordinal and suppose that the lemma holds for every \\( \\gamma < \\lambda \\). That is, for every \\( \\gamma < \\lambda \\) we have\n    \\begin{equation*}\n      \\alpha + \\gamma < \\beta + \\gamma.\n    \\end{equation*}\n\n    Thus,\n    \\begin{equation*}\n      \\alpha + \\lambda\n      =\n      \\sup\\set{ \\alpha + \\gamma \\given \\gamma < \\lambda }\n      \\leq\n      \\sup\\set{ \\beta + \\gamma \\given \\gamma < \\lambda }\n      =\n      \\beta + \\lambda.\n    \\end{equation*}\n\n    We cannot make a stronger conclusion here --- see \\fullref{ex:ordinal_addition} for a counterexample.\n  \\end{itemize}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ordinal_ordering_via_addition}\n  For any two ordinals \\( \\alpha \\) and \\( \\beta \\) it holds that \\( \\alpha \\leq \\beta \\) if and only if there exists an ordinal \\( \\gamma \\) such that \\( \\alpha + \\gamma = \\beta \\). This ordinal is unique and satisfies \\( \\gamma \\leq \\beta \\).\n\n  The strict inequality \\( \\alpha < \\beta \\) holds if and only if \\( \\gamma \\neq 0 \\).\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof By definition \\( \\beta + 0 = \\beta \\), hence we are not interested in the case \\( \\alpha = \\beta \\). That is, we will only consider the case \\( \\alpha < \\beta \\).\n\n  We will first show uniqueness of \\( \\gamma \\). Suppose that \\( \\alpha + \\gamma_1 = \\beta = \\alpha + \\gamma_2 \\). From \\eqref{thm:ordinal_addition_is_monotone/left} it follows that if either \\( \\gamma_1 < \\gamma_2 \\) or \\( \\gamma_1 > \\gamma_2 \\), we would have a strict inequality. Hence, it only remains for \\( \\gamma_1 = \\gamma_2 \\) to hold.\n\n  We now use induction on \\( \\beta \\) on prove the existence of \\( \\gamma \\).\n  \\begin{itemize}\n    \\item The condition \\( \\alpha < \\beta \\) is vacuously false for the base case \\( \\beta = 0 \\), hence by \\eqref{eq:def:intuitionistic_propositional_deductive_systems/rules/efq} the statement vacuously holds.\n\n    \\item Suppose that \\( \\alpha < \\beta \\) and that there exists a unique \\( \\gamma \\leq \\beta \\) such that \\( \\alpha + \\gamma = \\beta \\). Then\n    \\begin{equation*}\n      \\alpha + \\op{succ}(\\gamma)\n      \\reloset {\\eqref{eq:def:ordinal_arithmetic/addition}} =\n      \\op{succ}(\\alpha + \\gamma)\n      =\n      \\op{succ}(\\beta).\n    \\end{equation*}\n\n    Since \\( \\alpha < \\beta \\) and \\( \\beta < \\op{succ}(\\beta) \\), we have used the inductive hypothesis to conclude that\n    \\begin{equation*}\n      \\alpha < \\op{succ}(\\beta) \\T{implies} \\qexists {\\underbrace{\\delta}_{\\mathclap{\\op{succ}(\\gamma)}}} \\alpha + \\delta = \\op{succ}(\\beta).\n    \\end{equation*}\n\n    Furthermore, since \\( \\gamma \\leq \\beta \\), then also \\( \\op{succ}(\\gamma) \\leq \\op{succ}(\\beta) \\).\n\n    \\item Suppose that \\( \\lambda \\) is a limit ordinal, \\( \\alpha < \\lambda \\) and for each \\( \\beta < \\lambda \\) there exists some \\( \\gamma_\\beta \\leq \\beta \\) such that \\( \\alpha + \\gamma_\\beta = \\beta \\). Define\n    \\begin{equation*}\n      \\gamma \\coloneqq \\sup\\set{ \\gamma_\\beta \\given \\beta < \\lambda }.\n    \\end{equation*}\n\n    By \\fullref{thm:union_of_set_of_ordinals} we have that \\( \\gamma \\) is an ordinal and that \\( \\gamma_\\beta \\leq \\gamma \\) for every \\( \\beta < \\lambda \\). Thus,\n    \\begin{align*}\n      \\lambda\n      &\\reloset {\\ref{thm:ordinal_is_set_of_smaller_ordinals}} =\n      \\sup\\set{ \\beta \\given \\beta < \\lambda }\n      \\reloset {\\T{ind.}} = \\\\ &=\n      \\sup\\set{ \\alpha + \\gamma_\\beta \\given \\beta < \\lambda }\n      \\reloset {\\eqref{eq:thm:ordinal_addition_is_monotone/right}} \\leq \\\\ &\\leq\n      \\sup\\set[\\Big]{ \\alpha + \\delta \\given \\delta < \\sup\\set{ \\gamma_\\beta \\given \\beta < \\lambda } }\n      = \\\\ &=\n      \\sup\\set{ \\alpha + \\delta \\given \\delta < \\gamma }\n      \\reloset {\\eqref{eq:def:ordinal_arithmetic/addition}} = \\\\ &=\n      \\alpha + \\gamma.\n    \\end{align*}\n\n    Aiming at a contradiction, suppose that the strict inequality holds. That is, suppose that \\( \\lambda < \\alpha + \\gamma \\). Then there exists some \\( \\delta_0 < \\gamma \\) such that \\( \\alpha + \\delta_0 > \\alpha + \\gamma_\\beta \\) for any \\( \\beta < \\lambda \\). It follows from \\fullref{thm:monotone_map_converse} that \\( \\gamma_\\beta < \\delta_0 \\) for any \\( \\beta < \\lambda \\) and thus\n    \\begin{equation*}\n      \\underbrace{\\sup\\set{ \\gamma_\\beta \\given \\beta < \\lambda }}_{\\gamma} \\leq \\delta_0 < \\gamma.\n    \\end{equation*}\n\n    The obtained contradiction shows that such an ordinal \\( \\delta_0 \\) cannot exist and hence \\( \\lambda = \\alpha + \\gamma \\).\n\n    Furthermore, since \\( \\gamma_\\beta \\leq \\beta \\) for each \\( \\beta < \\lambda \\), we have\n    \\begin{equation*}\n      \\gamma\n      =\n      \\sup\\set{ \\gamma_\\beta \\given \\beta < \\lambda }\n      \\leq\n      \\sup\\set{ \\beta \\given \\beta < \\lambda }\n      =\n      \\lambda.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\NecessitySubProof Suppose that \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\leq \\beta \\) are ordinals and that \\( \\alpha + \\gamma = \\beta \\). Obviously \\( \\gamma = 0 \\) implies that \\( \\alpha = \\beta \\). If \\( \\gamma > 0 \\), then from \\eqref{eq:thm:ordinal_addition_is_monotone/left} it follows that\n  \\begin{equation*}\n     \\beta = \\alpha + \\gamma > \\alpha + 0 = 0.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:ordinal_addition_algebraic/properties}\n  Ordinal number addition is \\hyperref[def:magma/associative]{associative} and \\hyperref[def:magma/cancellative]{left cancellative}.\n\n  As in \\fullref{thm:ordinals_are_well_ordered}, we adapt the corresponding axioms due to \\fullref{thm:burali_forti_paradox}. The more concrete result is:\n  \\begin{thmenum}\n    \\thmitem{thm:def:ordinal_addition_algebraic/properties/associative} For any three ordinals \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\) we have\n    \\begin{equation*}\n      (\\alpha + \\beta) + \\gamma = \\alpha + (\\beta + \\gamma).\n    \\end{equation*}\n\n    \\thmitem{thm:def:ordinal_addition_algebraic/properties/left_cancellative} For any three ordinals \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\) such that \\( \\gamma + \\alpha = \\gamma + \\beta \\), we have \\( \\alpha = \\beta \\).\n  \\end{thmenum}\n\n   See \\fullref{ex:ordinal_addition} for counterexamples to \\hyperref[def:magma/commutative]{commutativity}.\n\n   Compare this with \\fullref{thm:def:natural_number_addition/properties} and \\fullref{thm:def:cardinal_addition_algebraic/properties}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:ordinal_addition_algebraic/properties/associative} We will use induction on \\( \\gamma \\). \\Fullref{thm:def:natural_number_addition/properties} already proves the base and successor cases.\n\n  Fix some ordinals \\( \\alpha \\) and \\( \\beta \\). Let \\( \\lambda \\) be a limit ordinal and suppose that\n  \\begin{equation*}\n    (\\alpha + \\beta) + \\gamma = \\alpha + (\\beta + \\gamma)\n  \\end{equation*}\n  holds for all \\( \\gamma < \\lambda \\). Then\n  \\begin{align*}\n    (\\alpha + \\beta) + \\lambda\n    &\\reloset {\\eqref{eq:def:ordinal_arithmetic/addition}} =\n    \\sup\\set{ (\\alpha + \\beta) + \\gamma \\given \\gamma < \\lambda }\n    \\reloset {\\T{ind.}} = \\\\ &=\n    \\sup\\set{ \\alpha + (\\beta + \\gamma) \\given \\gamma < \\lambda }\n    \\reloset {\\eqref{eq:def:partially_ordered_set/homomorphism/strict}} = \\\\ &=\n    \\sup\\set{ \\alpha + \\delta \\given \\delta < \\beta + \\lambda }\n    =\n    \\alpha + (\\beta + \\lambda).\n  \\end{align*}\n\n  \\SubProofOf{thm:def:ordinal_addition_algebraic/properties/left_cancellative} Follows from \\fullref{thm:monotone_map_converse} and \\eqref{eq:thm:ordinal_addition_is_monotone/left}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ordinal_addition_disjoin_union}\n  For any two ordinals \\( \\alpha \\) and \\( \\beta \\), their \\hyperref[def:ordinal_arithmetic/addition]{sum} satisfies\n  \\begin{equation*}\n    \\alpha + \\beta = \\ord(\\alpha \\amalg \\beta, \\prec),\n  \\end{equation*}\n  where \\( \\prec \\) is the \\hyperref[def:lexicographic_order]{lexicographic order} on the \\hyperref[def:disjoint_union]{disjoint union} \\( \\alpha \\amalg \\beta \\).\n\\end{proposition}\n\\begin{proof}\n  We will explicitly build an \\hyperref[def:partially_ordered_set/homomorphism]{order isomorphism} between \\( (\\alpha + \\beta, \\in) \\) and \\( (\\alpha \\amalg \\beta, \\prec) \\). Define\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: (\\alpha + \\beta) \\to (\\alpha \\amalg \\beta) \\\\\n      &f(\\gamma) \\coloneqq \\begin{cases}\n        (\\gamma, 0), &\\gamma < \\alpha \\\\\n        (\\delta, 1), &\\qexists \\delta (\\gamma = \\alpha + \\delta).\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  From \\fullref{thm:ordinal_ordering_via_addition} it follows that the existence of \\( \\delta \\) such that \\( \\gamma = \\alpha + \\delta \\) is equivalent to the condition \\( \\gamma \\geq \\alpha \\). Since \\( \\gamma < \\alpha + \\beta \\), we have \\( \\alpha + \\delta < \\alpha + \\beta \\) and from \\fullref{thm:def:ordinal_addition_algebraic/properties/left_cancellative} we have \\( \\delta < \\beta \\). Therefore, \\( f \\) is a total function. Furthermore, it is single-valued because of the uniqueness of \\( \\delta \\).\n\n  We will first show that \\( f \\) is a strict order homomorphism. Let \\( \\gamma_1 < \\gamma_2 \\). We have the following possibilities:\n  \\begin{itemize}\n    \\item If \\( \\gamma_2 < \\alpha \\), then \\( f(\\gamma_1) = (\\gamma_1, 0) < (\\gamma_2, 0) = f(\\gamma_2) \\).\n    \\item If \\( \\gamma_1 \\geq \\alpha \\), then \\( f(\\gamma_1) = (\\gamma_1, 1) < (\\gamma_2, 1) = f(\\gamma_2) \\).\n    \\item If \\( \\gamma_1 < \\alpha \\leq \\gamma_2 \\), then \\( f(\\gamma_1) = (\\gamma_1, 0) < (\\gamma_2, 1) = f(\\gamma_2) \\).\n  \\end{itemize}\n\n  Therefore, \\( f \\) is a strict order homomorphism and from \\fullref{thm:total_order_embedding_iff_strict} it follows that \\( f \\) is an order embedding. Due to \\fullref{thm:totally_ordered_strict_isomorphisms}, in order to show that \\( f \\) is an order isomorphism it only remains to show that it is a surjective function.\n\n  Let \\( (\\gamma, k) \\in \\alpha \\amalg \\beta \\).\n  \\begin{itemize}\n    \\item If \\( k = 0 \\), then \\( f(\\gamma) = (\\gamma, k) \\) since \\( \\gamma \\in \\alpha \\).\n    \\item If \\( k = 1 \\), then \\( \\gamma \\in \\beta \\) and by \\eqref{eq:thm:ordinal_addition_is_monotone/left} we have \\( \\alpha + \\gamma < \\alpha + \\beta \\), so \\( \\alpha + \\gamma \\) is within the domain of \\( f \\). Furthermore, as shown in \\fullref{thm:ordinal_ordering_via_addition}, if \\( \\alpha + \\delta = \\alpha + \\gamma \\), then \\( \\delta = \\gamma \\), Thus, \\( f(\\alpha + \\gamma) = (\\gamma, 1) \\) .\n  \\end{itemize}\n\n  Therefore, \\( f \\) is an order isomorphism between \\( (\\alpha + \\beta, \\in) \\) and \\( (\\alpha \\amalg \\beta, \\prec) \\) and hence\n  \\begin{equation*}\n    \\alpha + \\beta = \\ord(\\alpha \\amalg \\beta, \\prec).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:ordinal_addition}\n  The distinction between \\eqref{eq:thm:monotone_map_converse} and \\eqref{eq:thm:monotone_map_converse} is important. A simple example is provided by any limit ordinal \\( \\lambda \\), in particular by \\( \\omega \\). The example are inconvenient to demonstrate with the recursive definition, however \\fullref{thm:ordinal_addition_disjoin_union} eases us.\n\n  In particular \\fullref{thm:ordinal_addition_disjoin_union} highlights that adding one ordinal to another, in fact, \\enquote{appending} a copy of the second to a copy the first.\n\n  It is clear that\n  \\begin{equation*}\n    0 + \\lambda = \\ord(0 \\sqcap \\lambda) = \\ord(\\lambda) = \\lambda.\n  \\end{equation*}\n\n  That is, we \\enquote{append} \\( \\lambda \\) to an empty well-ordered set only to obtain \\( \\lambda \\) again.\n\n  This operation seems different from \\( 1 + \\lambda \\), which \\enquote{appends} \\( \\lambda \\) to a well-ordered singleton set. But this operation only \\enquote{shifts} \\( \\lambda \\) --- the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: \\ord(1 \\sqcap \\lambda) \\to \\ord(0 \\sqcap \\lambda) \\\\\n      &f(k, \\gamma) \\coloneqq \\begin{cases}\n        (0, 0),          &k = 0 \\\\\n        (0, \\gamma + 1), &k = 1.\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n  is an order isomorphism and thus\n  \\begin{equation*}\n    1 + \\lambda = \\ord(1 \\sqcap \\lambda) = \\ord(\\lambda) = \\lambda.\n  \\end{equation*}\n\n  What the inequality \\eqref{eq:thm:monotone_map_converse} gives us is that\n  \\begin{equation*}\n    \\lambda \\leq 1 + \\lambda = \\lambda.\n  \\end{equation*}\n\n  This inequality is, of course, strict when dealing with finite ordinals exclusively, but for limit ordinals its results may be counterintuitive.\n\n  What is more interesting is that, as a consequence of \\eqref{eq:thm:monotone_map_converse}, we have \\( \\lambda < \\lambda + 1 \\). This can be explained as follows. Instead of \\enquote{appending} an infinite set to a finite one, we append a finite set to an infinite one. This way \\( \\lambda \\) cannot \\enquote{absorb} \\( 1 \\) like it does in \\( 1 + \\lambda \\).\n\n  As a consequence of this example, addition of ordinals is not commutative and also not right-cancellative.\n\n  As discussed in the proof of \\fullref{thm:def:cardinal_addition_algebraic/properties}, this is only a restriction of well-orders and not of the resulting sets themselves.\n\\end{example}\n\n\\begin{proposition}\\label{thm:ordinal_multiplication_cartesian_product}\n  For any two ordinals \\( \\alpha \\) and \\( \\beta \\), their \\hyperref[def:ordinal_arithmetic/multiplication]{product} satisfies\n  \\begin{equation*}\n    \\alpha \\cdot \\beta = \\ord(\\alpha \\times \\beta, \\prec),\n  \\end{equation*}\n  where \\( \\prec \\) is the \\hyperref[def:lexicographic_order]{lexicographic order} on the \\hyperref[def:cartesian_product]{Cartesian product} \\( \\alpha \\times \\beta \\).\n\\end{proposition}\n\\begin{proof}\n  We will build an order isomorphism between \\( (\\alpha \\cdot \\beta, \\in) \\) and \\( (\\alpha \\times \\beta, \\prec) \\) using recursion on \\( \\beta \\).\n  \\begin{itemize}\n    \\item Both sets \\( \\alpha \\cdot 0 \\) and \\( \\alpha \\cdot 0 \\) are empty and the empty function is an order isomorphism.\n    \\item Suppose that \\( f: \\alpha \\cdot \\beta \\to \\alpha \\times \\beta \\) is an order isomorphism. We construct the function\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\widehat f: \\alpha \\cdot (\\beta + 1) \\to \\alpha \\times (\\beta + 1) \\\\\n        &\\widehat f \\coloneqq \\begin{cases}\n          f(\\gamma),       &\\gamma < \\alpha \\cdot \\beta \\\\\n          (\\delta, \\beta), &\\qexists \\delta (\\gamma = \\alpha \\cdot \\beta + \\delta).\n        \\end{cases}\n      \\end{aligned}\n    \\end{equation*}\n\n    In complete analogy with \\fullref{thm:ordinal_ordering_via_addition} we can prove that \\( \\widehat f \\) is an order isomorphism.\n\n    \\item Let \\( \\lambda \\) be a limit ordinal and let \\( f_\\beta: \\alpha \\cdot \\beta \\to \\alpha \\times \\beta \\) be an order isomorphism for every \\( \\beta < \\lambda \\). Take their union\n    \\begin{equation*}\n      f \\coloneqq \\bigcup\\set{ f_\\beta \\given \\beta < \\lambda }.\n    \\end{equation*}\n\n    The uniqueness of each \\( f_\\beta \\) from \\fullref{thm:well_ordered_order_type_existence} shows that \\( f_{\\beta_1} \\subseteq f_{\\beta_2} \\) for each pair \\( \\beta_1 < \\beta_2 \\). Therefore, the union \\( f \\) is a single-valued partial function. It is also total because every ordinal \\( \\gamma < \\alpha \\cdot \\lambda \\) is contains in the image of the function \\( f_{\\gamma + 1} \\).\n\n    The function \\( f \\) is an order embedding by construction. It is also surjective because, if \\( (\\delta, \\beta) \\in \\alpha \\times \\lambda \\), then from the successor step we can conclude that \\( f(\\alpha \\cdot \\beta + \\delta) = (\\delta, \\beta) \\).\n\n    Therefore, \\( f \\) is an order isomorphism.\n  \\end{itemize}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:ordinal_multiplication_algebraic/properties}\n  Similarly to \\fullref{thm:def:ordinal_addition_algebraic/properties} for ordinal number addition, multiplication is also \\hyperref[def:magma/associative]{associative} and \\hyperref[def:magma/cancellative]{left cancellative}:\n  \\begin{thmenum}\n    \\thmitem{thm:def:ordinal_multiplication_algebraic/properties/associative} For any three ordinals \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\) we have\n    \\begin{equation*}\n      (\\alpha \\cdot \\beta) \\cdot \\gamma = \\alpha \\cdot (\\beta \\cdot \\gamma).\n    \\end{equation*}\n\n    \\thmitem{thm:def:ordinal_multiplication_algebraic/properties/left_cancellative} For any three ordinals \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\) such that \\( \\gamma \\cdot \\alpha = \\gamma \\cdot \\beta \\), we have \\( \\alpha = \\beta \\).\n  \\end{thmenum}\n\n  Compare this with \\fullref{thm:def:natural_number_multiplication/properties} and \\fullref{thm:def:cardinal_multiplication_algebraic/properties}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:ordinal_multiplication_algebraic/properties/associative} Associativity follows easily from the obvious isomorphisms between \\( (\\alpha \\times \\beta) \\times \\gamma \\) and \\( \\alpha \\times (\\beta \\times \\gamma) \\).\n\n  \\SubProofOf{thm:def:ordinal_multiplication_algebraic/properties/left_cancellative} Now suppose that \\( \\gamma \\cdot \\alpha = \\gamma \\cdot \\beta \\). Let \\( f \\) the unique order isomorphism between \\( \\gamma \\times \\alpha \\) and \\( \\gamma \\times \\beta \\).\n\n  Suppose that \\( \\alpha \\neq \\beta \\). Without loss of generality, suppose that \\( \\beta \\subsetneq \\alpha \\). Then \\( f\\restr_{\\gamma \\times \\alpha} \\) is the identity mapping and hence any set from \\( \\gamma \\times (\\beta \\setminus \\alpha) \\) would make \\( f \\) not injective.\n\n  The obtained contradiction shows that \\( \\alpha = \\beta \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:countable_limit_ordinals}\n  We already know that \\( \\omega \\) is a limit ordinal. It is clear from \\fullref{ex:ordinal_addition} that \\( \\omega + n \\) is a successor ordinal for every natural number \\( n \\).\n\n  What about \\( \\omega + \\omega \\)? This corresponds to \\enquote{placing} two copies of the natural numbers one after another.\n\n  Suppose that \\( \\omega + \\omega = \\omega \\cdot 2 \\) is the successor of \\( \\alpha \\). Then \\( \\alpha < \\omega + \\omega \\) and we can show by induction on the natural numbers that \\( \\alpha + n < \\omega + \\omega \\). But \\( \\alpha + 1 = \\omega \\) by assumption, which contradicts trichotomy of ordinals.\n\n  Therefore, \\( \\omega + \\omega \\) is a limit ordinal. Furthermore, \\( \\omega + \\omega \\) is the second smallest limit ordinal since only ordinals of the form \\( \\omega + n \\) for nonzero finite \\( n \\) satisfy \\( \\omega < \\omega + n < \\omega + \\omega \\).\n\n  Both ordinals \\( \\omega \\) and \\( \\omega + \\omega \\) are countable by \\fullref{thm:omega_equinumerous_with_omega_squared}.\n\n  Another limit ordinal is \\( \\omega \\cdot \\omega = \\omega^2 \\). It is also countable by \\fullref{thm:countable_product_of_countable_sets}. Actually \\( \\omega^n \\) for any natural number \\( n \\) is countable by the same theorem.\n\n  Therefore, any \\enquote{\\hyperref[def:polynomial]{polynomial}} of the form\n  \\begin{equation*}\n    \\alpha_n \\omega^n + \\alpha_{n-1} \\omega^{n-1} + \\cdots + \\alpha_1 \\omega + \\alpha_0\n  \\end{equation*}\n  with countable coefficients is also countable.\n\\end{example}\n\n\\begin{definition}\\label{def:cardinal_arithmetic}\n  We will define arithmetic operations for them. Unlike in \\fullref{def:ordinal_arithmetic}, we will directly define the operations as \\hyperref[thm:cardinality_existence]{cardinal numbers} of some sets rather than via some form of recursion.\n\n  Fix two ordinals \\( \\kappa \\) and \\( \\mu \\).\n  \\begin{thmenum}\n    \\thmitem{def:cardinal_arithmetic/addition} Based on \\fullref{thm:ordinal_addition_disjoin_union}, we define their \\term{sum} as\n    \\begin{equation*}\n      \\kappa + \\mu \\coloneqq \\card(\\kappa \\amalg \\mu),\n    \\end{equation*}\n    where \\( \\kappa \\amalg \\mu \\) is their \\hyperref[def:disjoint_union]{disjoint union}.\n\n    \\thmitem{def:cardinal_arithmetic/multiplication} Based on \\fullref{thm:ordinal_multiplication_cartesian_product}, we define their \\term{product} as\n    \\begin{equation*}\n      \\kappa \\cdot \\mu \\coloneqq \\card(\\kappa \\times \\mu).\n    \\end{equation*}\n\n    \\thmitem{def:cardinal_arithmetic/exponentiation} We define \\term{exponentiation} as\n    \\begin{equation*}\n      \\kappa^\\mu \\coloneqq \\card(\\fun(\\kappa, \\mu)).\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:cardinal_addition_algebraic/properties}\n  Cardinal number addition is \\hyperref[def:magma/associative]{associative}, \\hyperref[def:magma/associative]{commutative} and \\hyperref[def:magma/cancellative]{cancellative}.\n\n  Compare this with \\fullref{thm:def:natural_number_addition/properties} and \\fullref{thm:def:ordinal_addition_algebraic/properties}.\n\\end{proposition}\n\\begin{proof}\n  Associativity and left cancellation is inherited from the ordinals. Commutativity and right cancellation hold because we are considering arbitrary bijective functions rather than the more restrictive order isomorphisms. Indeed, \\( \\kappa \\amalg \\mu \\) and \\( \\mu \\amalg \\kappa \\) may have different order types as demonstrated in \\fullref{ex:ordinal_addition}, however there is an obvious bijective function between them.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:cardinal_multiplication_algebraic/properties}\n  Cardinal number multiplication is \\hyperref[def:magma/associative]{associative}, \\hyperref[def:magma/associative]{commutative} and \\hyperref[def:magma/cancellative]{cancellative}.\n\n  Compare this with \\fullref{thm:def:natural_number_multiplication/properties} and \\fullref{thm:def:ordinal_addition_algebraic/properties}.\n\\end{proposition}\n\\begin{proof}\n  The result follows from the same considerations as in \\fullref{thm:def:cardinal_addition_algebraic/properties}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:double_and_square_of_cardinal}\n  For every cardinal \\( \\kappa \\) we have\n  \\begin{thmenum}\n    \\thmitem{thm:double_and_square_of_cardinal/double} \\( \\kappa + \\kappa = 2\\kappa \\).\n    \\thmitem{thm:double_and_square_of_cardinal/square} \\( \\kappa \\cdot \\kappa = \\kappa^2 \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:double_and_square_of_cardinal/double} Obviously \\( \\kappa \\amalg \\kappa = 2 \\times \\kappa \\).\n  \\SubProofOf{thm:double_and_square_of_cardinal/square} The function\n  \\begin{equation*}\n    \\begin{aligned}\n      &T: \\fun(2, \\kappa) \\to \\kappa \\times \\kappa \\\\\n      &T(f) \\coloneqq (f(0), f(1))\n    \\end{aligned}\n  \\end{equation*}\n  is clearly injective. It is also surjective because for any ordered pair \\( (\\gamma, \\delta) \\in \\kappa \\times \\kappa \\) we can define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: 2 \\to \\kappa \\\\\n      &f(k) \\coloneqq \\begin{cases}\n        \\gamma, k = 0 \\\\\n        \\delta, k = 1\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  Then \\( T(f) = (\\gamma, \\delta) \\).\n\\end{proof}\n\n\\begin{lemma}\\label{thm:square_of_infinite_cardinal}\\mcite[thm. 3.1]{nLab:cardinal_arithmetic}\n  If \\( \\kappa \\) is an infinite cardinal, then \\( \\kappa = \\kappa^2 \\).\n\\end{lemma}\n\\begin{proof}\n  Obviously \\( \\kappa \\leq \\kappa^2 \\). Suppose that the lemma does not always hold and let \\( \\kappa \\) be the smallest ordinal for which \\( \\kappa < \\kappa^2 \\).\n\n  Consider the \\hyperref[def:well_ordered_set]{well-ordered set}\n  \\begin{equation*}\n    (\\kappa \\times \\kappa \\times \\kappa, \\prec),\n  \\end{equation*}\n  where \\( \\prec \\) denotes the corresponding \\hyperref[def:lexicographic_order]{lexicographic order}. The set is well-ordered as a consequence of \\fullref{thm:well_ordered_lexicographic_order_is_well_ordered}.\n\n  Define the subset\n  \\begin{equation*}\n    S \\coloneqq \\set{ (\\alpha, \\beta, \\gamma) \\in \\kappa \\times \\kappa \\times \\kappa \\given \\alpha = \\max\\set{ \\beta, \\gamma } }.\n  \\end{equation*}\n\n  The elements of \\( S \\) are determined exactly by any two of its three coordinates, hence \\( S \\) is equinumerous with \\( \\kappa \\times \\kappa \\). Since \\( \\kappa < \\kappa^2 \\), there exists some \\hyperref[def:partially_ordered_set_interval/ray]{initial segment}\n  \\begin{equation*}\n    S_{<(\\alpha_0, \\beta_0, \\gamma_0)} = \\set{ (\\alpha, \\beta, \\gamma) \\in S \\given \\alpha < \\alpha_0 \\T{and} \\beta < \\beta_0 \\T{and} \\gamma < \\gamma_0 }.\n  \\end{equation*}\n\n  Note that \\( \\alpha_0^2 = \\alpha_0 \\) since \\( \\alpha_0 < \\kappa \\). Then\n  \\begin{equation*}\n    \\kappa = \\card(S_{<(\\alpha_0, \\beta_0, \\gamma_0)}) \\leq \\card(S_{<(\\alpha_0, \\alpha_0, \\alpha_0)}) = \\alpha_0^2 = \\alpha_0 < \\kappa,\n  \\end{equation*}\n  which is a contradiction.\n\n  Therefore, \\( \\kappa = \\kappa^2 \\) for every infinite cardinal \\( \\kappa \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:simplified_cardinal_arithmetic}\n  Unlike \\hyperref[def:ordinal_arithmetic]{ordinal arithmetic} with its intricacies like \\fullref{ex:ordinal_addition}, \\hyperref[def:cardinal_arithmetic]{cardinal arithmetic} has a simpler behavior:\n  \\begin{thmenum}\n    \\thmitem{thm:simplified_cardinal_arithmetic/finite} If \\( \\kappa \\) and \\( \\mu \\) are finite cardinals, then \\( \\kappa + \\mu \\) and \\( \\kappa \\cdot \\mu \\) are the familiar operations on \\hyperref[def:set_of_natural_numbers]{natural numbers}.\n\n    \\thmitem{thm:simplified_cardinal_arithmetic/infinite} If either \\( \\kappa \\) or \\( \\mu \\) is infinite, then\n    \\begin{equation*}\n      \\kappa + \\mu = \\max\\set{ \\kappa, \\mu }.\n    \\end{equation*}\n\n    If, additionally, both are either zero or nonzero, then\n    \\begin{equation*}\n      \\kappa \\cdot \\mu = \\max\\set{ \\kappa, \\mu }.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:simplified_cardinal_arithmetic/finite} The addition of ordinals defined in \\fullref{def:ordinal_arithmetic/addition} is an extension of addition of natural numbers, hence the two are equivalent for finite ordinals. The equivalence with cardinal addition defined in \\fullref{def:cardinal_arithmetic/addition} comes from \\fullref{thm:ordinal_addition_disjoin_union} and the fact that every finite ordinal is a cardinal as demonstrated in \\fullref{thm:natural_numbers_are_cardinals}.\n\n  Analogously, equivalence of cardinal and ordinal multiplication follows from \\fullref{thm:ordinal_multiplication_cartesian_product}.\n\n  \\SubProofOf{thm:simplified_cardinal_arithmetic/infinite} Suppose that either \\( \\kappa \\) or \\( \\mu \\) is infinite and let \\( \\nu \\coloneqq \\max\\set{ \\kappa, \\mu } \\). The cases where either of them is zero are trivial, hence suppose that both are nonzero.\n\n  We have\n  \\begin{equation*}\n    \\kappa \\amalg \\mu \\subseteq \\nu \\amalg \\nu = 2 \\amalg \\nu \\subseteq \\nu \\times \\nu,\n  \\end{equation*}\n  hence \\( \\kappa + \\mu \\leq \\nu \\cdot \\nu = \\nu^2 \\).\n\n  Furthermore there exists an obvious injective function from \\( \\nu \\) to \\( \\kappa \\amalg \\mu \\) (which is different depending on whether \\( \\nu = \\kappa \\) or \\( \\nu = \\mu \\)). Therefore,\n  \\begin{equation*}\n    \\nu \\leq \\kappa + \\mu \\leq \\nu^2.\n  \\end{equation*}\n\n  For multiplication we have \\( \\kappa \\times \\mu \\subseteq \\nu \\times \\nu \\), hence\n  \\begin{equation*}\n    \\nu \\leq \\kappa \\cdot \\mu \\leq \\nu^2.\n  \\end{equation*}\n\n  The rest follows from \\fullref{thm:square_of_infinite_cardinal}.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:aleph_zero_is_strong_limit}\n  The first infinite cardinal \\( \\aleph_0 \\) is a \\hyperref[def:successor_and_limit_cardinal/strong_limit]{strong limit cardinal}.\n\n  See also \\fullref{thm:aleph_zero_is_regular}\n\\end{corollary}\n\\begin{proof}\n  \\Fullref{thm:simplified_cardinal_arithmetic/finite} states that cardinal exponentiation extends natural number exponentiation. Hence, we can conclude that \\( 2^n < \\aleph_0 \\) for any \\( n < \\aleph_0 \\) since the former are finite and the latter is not.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:power_set_via_subsets}\n  Fix a set \\( A \\). The power set \\( \\pow(A) \\) is equinumerous with the set of \\hyperref[def:boolean_function]{Boolean-valued functions} \\( \\pow(A, \\set{ T, F }) \\).\n\n  More precisely, then the operator\n  \\begin{equation*}\n    \\begin{aligned}\n      &T: \\fun(A, \\set{ T, F }) \\to \\pow(A) \\\\\n      &T(f) \\coloneqq \\set{ f(x) = T \\given x \\in A }.\n    \\end{aligned}\n  \\end{equation*}\n  is bijective.\n\\end{lemma}\n\\begin{proof}\n  Injectivity is clear. To see surjectivity, fix some subset \\( B \\subset A \\) and define\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: A \\to \\set{ T, F } \\\\\n      &f(x) \\coloneqq \\begin{cases}\n        T, &x \\in B \\\\\n        F, \\T{otherwise}.\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  Clearly \\( f \\in \\fun(A, \\set{ T, F }) \\) and \\( T(f) = B \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:cardinal_exponentiation_power_set}\n  For every set \\( A \\) we have\n  \\begin{equation*}\n    \\card(\\pow(A)) = 2^{\\card(A)}.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  The proof is similar to \\fullref{thm:power_set_via_subsets}, but much more convoluted.\n\n  Let \\( \\varphi: A \\to \\card(A) \\) be \\( \\psi: \\pow(A) \\to \\card(\\pow(A)) \\) bijective functions. Note that\n  \\begin{equation*}\n    2^{\\card(A)} = \\card(\\fun(\\card(A), \\set{ 0, 1 }))\n  \\end{equation*}\n  by definition. Let \\( \\theta: \\fun(\\card(A), \\set{ 0, 1 }) \\to 2^{\\card(A)} \\) be a bijective function.\n\n  Define the operator\n  \\begin{equation*}\n    \\begin{aligned}\n      &T: 2^{\\card(A)} \\to \\card(\\pow(A)) \\\\\n      &T(p) \\coloneqq \\psi\\parens{ \\set{ \\varphi^{-1}(\\gamma) \\given \\gamma \\in \\card(A) \\T{and} \\theta^{-1}(p)(\\gamma) = 1 } }.\n    \\end{aligned}\n  \\end{equation*}\n\n  This operator is bijective since for any \\( \\delta \\in \\card(\\pow(A)) \\) we can define\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: \\card(A) \\to \\set{ 0, 1 } \\\\\n      &f(\\gamma) \\coloneqq \\begin{cases}\n        1, &\\varphi^{-1}(\\gamma) \\in \\psi^{-1}(\\delta) \\\\\n        0, &\\T{otherwise.}\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n  so that \\( T(\\theta(f)) = \\delta \\).\n\n  Therefore, \\( \\card(A) \\) and \\( \\card(\\pow(A)) \\) are equinumerous.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:strong_limit_cardinal_is_weak_limit}\n  If \\( \\mu \\) is the successor cardinal of \\( \\kappa \\), then \\( \\mu \\leq 2^\\kappa \\).\n\n  In particular, every \\hyperref[def:successor_and_limit_cardinal/strong_limit]{strong limit cardinal} is a \\hyperref[def:successor_and_limit_cardinal/strong_limit]{weak limit cardinal}.\n\n  Furthermore, if \\( \\kappa \\) is infinite, then \\fullref{hyp:generalized_continuum_hypothesis} implies that \\( \\mu = 2^\\kappa \\).\n\\end{proposition}\n\\begin{proof}\n  It is clear from \\fullref{thm:cantor_power_set_theorem} and \\fullref{thm:cardinal_exponentiation_power_set} that \\( \\kappa < 2^\\kappa \\). By definition, \\( \\mu \\) is the smallest cardinal such that \\( \\kappa < \\mu \\). Therefore, \\( \\mu \\leq 2^\\kappa \\).\n\\end{proof}\n\n\\begin{conjecture}[Generalized continuum hypothesis]\\label{hyp:generalized_continuum_hypothesis}\n  For every ordinal \\( \\alpha \\) we have\n  \\begin{equation*}\n    \\aleph_{\\alpha + 1} = 2^{\\aleph_\\alpha},\n  \\end{equation*}\n\n  For the definition and the properties of the \\( \\aleph \\) hierarchy, see \\fullref{def:aleph_hierarchy}. For the related \\( \\beth \\) hierarchy, see \\fullref{def:beth_hierarchy}.\n\n  This is a vast generalization of \\fullref{hyp:continuum_hypothesis} from the case \\( \\alpha = 0 \\) to arbitrary ordinals.\n\\end{conjecture}\n\n\\begin{corollary}\\label{thm:limit_cardinals_and_gch}\n  \\Fullref{hyp:generalized_continuum_hypothesis} implies that every \\hyperref[def:successor_and_limit_cardinal/weak_limit]{weak limit cardinal} is a \\hyperref[def:successor_and_limit_cardinal/strong_limit]{strong limit cardinal}.\n\n  The converse holds in \\logic{ZFC} as shown in \\fullref{thm:strong_limit_cardinal_is_weak_limit}.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:infinite_cardinal_is_aleph} and \\fullref{hyp:generalized_continuum_hypothesis}.\n\\end{proof}\n\n\\begin{definition}\\label{def:beth_hierarchy}\\mcite[def. 68.17]{OpenLogicFull}\n  Similarly to \\fullref{def:aleph_hierarchy}, we use transfinite recursion to define, for each ordinal \\( \\alpha \\), the cardinal\n  \\begin{equation}\\label{eq:def:beth_hierarchy}\n    \\beth_\\alpha \\coloneqq \\begin{cases}\n      \\omega,                                       &\\alpha = 0 \\\\\n      2^\\beta,                                      &\\alpha = \\op{succ}(\\beta) \\\\\n      \\sup\\set{ \\beth_\\beta \\given \\beta < \\alpha } &\\alpha \\T{is a limit ordinal}.\n    \\end{cases}\n  \\end{equation}\n\n  Unlike \\fullref{def:aleph_hierarchy}, it is able to explicitly build the successor of any member of the hierarchy. \\Fullref{hyp:generalized_continuum_hypothesis} states that \\( \\aleph_\\alpha = \\beta_\\alpha \\) for every ordinal \\( \\alpha \\), however in general it is only provable that \\( \\aleph_\\alpha \\leq \\beta_\\alpha \\) --- see \\fullref{thm:strong_limit_cardinal_is_weak_limit}.\n\\end{definition}\n", "meta": {"hexsha": "85623c40ceab851824691527019ca044ffeb18f5", "size": 38402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/transfinite_arithmetic.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/transfinite_arithmetic.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/transfinite_arithmetic.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": 56.5567010309, "max_line_length": 507, "alphanum_fraction": 0.6733503463, "num_tokens": 12053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148981, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.6842925552412391}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\chapter{Recurrence Relations}\nAs we mentioned briefly about the power of recursion is in the whole algorithm design and analysis, we dedicate this chapter to recurrence relation. To summarize, recurrence relation can help with:\n\\begin{itemize}\n    \\item Recurrence relation naturally represent the relation of recursion. Examples will be shown in Chapter.~\\ref{chapter_divide_conquer}.\n    \\item Any iteration can be translated into recurrence relation. Some examples can be found in Chapter.~\\ref{chapter_complexity_analysis}.\n    \\item Recurrence relation together with mathematical induction is the most powerful tool to \\textbf{design} and \\textbf{prove} the correctness of algorithm(chapter.~\\ref{chapter_divide_conquer} and Chapter.~\\ref{chapter_complexity_analysis}).\n    \\item Recurrence relation can be applied to algorithm complexity analysis( Chapter.~\\ref{chapter_complexity_analysis}).\n\\end{itemize}\n\nIn  the following chapters of this part, we endow application meanings to these formulas and discuss how to realize the mentioned uses. \n\n\\section{Introduction}\n\\paragraph{Definition and Concepts} A recurrence relation is  function expressed with the same function. More precisely, as defined in mathematics, recurrence relation is an equation that recursively defines a sequence or multidimensional array of values; once one or more initial terms are given, each further term of the sequence or array is defined as a function of the preceding terms. Fibonacci sequence is one of the most famous recurrence relation which is defined as $f(n)=f(n-1)+f(n-2), f(0)=0, f(1)=1$.\n\\begin{equation}\n    a_n = \\Psi(n, a_{n-1})  \\text{ for $n \\leq 0$,}\n\\end{equation}\n\nWe use $a_n$ to denote the value at index $n$, and the recurrence function is marked as $\\Psi(n, P)$, $P$ is all preceding terms that needed to build up this recurrence relation. Like the case of factorial, each factorial number only relies on the result of the previous number and its current index, this recurrence relation can be written as the following equation: \n\nA recurrence relation needs to start from \\textit{initial value(s)}. For the above relation, $a_0$ needs to be defined and it will be the first element of a recurrence relation. The above relation is only related to the very first preceding terms, which is called recurrence relation of \\textit{first order}. If $P$ includes multiple preceding terms, a recurrence relation of order $k$ can be easily extended as:\n\\begin{equation}\n    a_n = \\Psi(n, a_{n-1}, a_{n-2}, ..., a_{n-k})  \\text{ for $n \\leq k$,}\n\\end{equation}\nIn this case, $k$ initial values are needed for defining a sequence. Initial values can be given any values but then once initial values are decided,  the recurrence determines the sequence uniquely. Thus, initial values are also called the \\textit{degree of freedom} for solutions to the recurrence. \n\nMany natural functions are easily expressed as recurrence:\n\\begin{itemize}\n    \\item Polynomial: $a_n = a_{n-1}+1, a_1=1 \\xrightarrow{} a_n = n$.\n    \\item Exponential: $a_n = 2 \\times a_{n-1}, a_1=1 \\xrightarrow{} a_n = 2^{n-1}$.\n    \\item Factorial: $a_n = n\\times a_{n-1}, a_1=1 \\xrightarrow{}a_n = n!$\n\\end{itemize}\n\n\\paragraph{Solving Recurrence Relation} In real problems, we might care about the value of recursion at $n$, that is compute $a_n$ for any given $n$, and there are two ways to do it: \n\\begin{itemize}\n    \\item Programming: we utilize the computational power of computer and code in either iteration or recursion to build up the value at any given $n$. For example, $f(2)=f(1)+f(0)=1$, $f(3)=f(2)+f(1)=2$, and so on. With this iteration, we would need $n-1$ steps to compute $f(n)$. \n    \\item Math: we solve the recurrence relation by obtaining an explicit or closed-form expression which is a non-recursive function of $n$. With the solution at hand, we can get  $a_n$ right away.\n\\end{itemize}\n Recurrence relations plays an important role in the analysis of algorithms. Usually, time recurrence relation $T(n)$ is defined to analyze the time complexity of solving a problem with input instance of size $n$. The field of complexity analysis studies the closed-form solution of $T(n)$; that is to say the functional relation between $T(n)$ with $n$ that it cares, not each exact value. \n \n \nIn this section, we focus on solving the recurrence relation using math to get a closed-form solution.  Categorizing the recurrence relation can help us pinpoint each type's solving methods. \n\n\\paragraph{Categorizes} Recurrence relation is essentially discreet function, which can be naturally categorized as \\textbf{linear} (such as function $y=mx+b)$ and \\textbf{non-linear}; quadratic, cubic and so on (such as $y=ax^2+bx+c, y=ax^3+bx^2+cx+d$). In the field of algorithmic problem solving, linear recurrence relation is commonly used and researched, thus we deliberately leave the non-linear recurrence relation and its method of solving out of the scope of this book. \n% \\begin{itemize}\n%     \\item Linear Recurrence Relation: \n    \\begin{itemize}\n        \\item \\textbf{Homogeneous linear recurrence relation:} When the recurrent relation is linear homogeneous of degree $k$ with constant coefficients, it is in the form, and is also called order-k homogeneous linear recurrence with constant coefficients. \n        \\begin{equation}\n            a_n=c_1a_{n-1} + c_2a_{n-2} + ... + c_k a_{n-k}.\n            \\label{eq_homogeneous_recurrence_relation}\n        \\end{equation}\n        $a_0, a_1, ..., a_{k-1}$ will be initial values.\n \n        \\item \\textbf{Non-homogeneous linear recurrence relation:} An order-k non-homogeneous linear recurrence with constant coefficients is defined in the form:\n                \\begin{equation}\n            a_n=c_1a_{n-1} + c_2a_{n-2} + ... + c_k a_{n-k}+f(n).\n             \\label{eq_non_homogeneous_recurrence_relation}\n        \\end{equation}\n        f(n) can be 1 or $n$ or $n^2$ and so on. \n        \\item \\textbf{Divide-and-conquer recurrence relation}: When $n$ is not decreasing by a constant as does in Eq.~\\ref{eq_homogeneous_recurrence_relation} and Eq.~\\ref{eq_non_homogeneous_recurrence_relation}, instead by a constant factor, with the equality as shown below, it is called divide and conquer recurrence relation. \n        \\begin{equation}\n    a_n=a_{n/b}+f(n)\n    \\label{divide_conquer_eq1}\n\\end{equation}\nwhere $a\\leq 1, b>1$, and $f(n)$ is a given function, which usually has $f(n)= cn^k$. \n%The special method for solving divide and conquer which is named \\textit{master method} will be introduced in Chapter.~\\ref{chapter_divide_conquer} when we have enough understanding of the term--divide and conquer. \n        \n    \\end{itemize}\n%     \\item Non-linear Recurrence Relation\n% \\end{itemize}\nWe will introduce general methods to solve a linear recurrence relation but leave out the part of divide and conquer recurrence relation in this chapter for reason that divide and conquer recurrence relation will most likely to be solved with just roughly, as shown in Chapter.~\\ref{chapter_complexity_analysis} to just estimate the time complexity resulted from the divide and conquer method. \n\n\\section{General Methods to Solve Linear Recurrence Relation}\n No general method for solving recurrence function is known yet, however, linear recurrence relation with finite initial values and previous states, constant coefficients can always be solved. Due to the fact that the recursion is essentially mathematical induction, the most general way of solving any recurrence relation is to use \\textit{mathematical induction} and \\textit{iterative method}. This also makes the the mathematical induction, in some form, the foundation of all correctness proofs for computer programs.  We  examine these two methods by solving two recurrence relation: $a_n = 2\\times a_{n-1} + 1, a_0 = 0$ and $a_n=a_{n/2} + 1$. \n\n\\subsection{Iterative Method}\nThe most straightforward method for solving recurrence relation no matter its linear or non-linear is the \\textit{iterative method}. Iterative method is a technique or procedure in computational mathematics that it iteratively replace/substitute each $a_n$ with its recurrence relation $\\Psi(n, a_{n-1}, a_{n-2}, ..., a_{n-k})$ till all items ``disappear'' other than the initial values. Iterative method is also called substitution method. \n\nWe demonstrate iteration with a simple non-overlapping recursion. \n\\begin{align}\n\\label{complexity_eq_binary_search}\n    T(n)&=T(n/2)+O(1)\\\\\n    &=T(n/2^2)+O(1)+O(1)\\notag\\\\\n    &=T(n/2^3)+3O(1)\\notag\\\\\n    &=...\\notag\\\\\n    &=T(1)+kO(1)\n\\end{align}\nWe have $\\frac{n}{2^k}=1$, we solve this equation and will get $k=\\log_2 n$. Most likely $T(1)=O(1)$ will be the initial condition, we replace this, and we get $T(n)=O(\\log_2 n)$.\n\nHowever, when we try to apply iteration on the third recursion:  $T(n)=3T(n/4)+O(n)$. It might be tempting to assume that $T(n)=O(n\\log n)$ due to the fact that $T(n)=2T(n/2)+O(n)$ leads to this time complexity.\n\\begin{align}\n\\label{complexity_non_overlap_1}\n    T(n)&=3T(n/4)+O(n)\\\\\n    &=3(3T(n/4^2)+n/4)+n=3^2T(n/4^2)+n(1+3/4)\\notag\\\\\n    &=3^2(3T(n/4^3)+n/4^2)+n(1+3/4)=3^3T(n/4^3)+n(1+3/4+3/4^2)\\\\\n    &=...\\\\\n    &=3^kT(n/4^k)+n\\sum_{i=0}^{k-1}(\\frac{3}{4})^{i}\n\\end{align}\n\\subsection{Recursion Tree}\nSince the term of T(n) grows, the iteration can look messy. We can use recursion tree to better visualize the process of iteration. In a recursive tree, each node represents the value of a single subproblem, and a leaf would be a subproblem. As a start, we expand $T(n)$ as a node with value $n$ as root, and it would have three children each represents a subproblem $T(n/4)$. We further do the same with each leaf node, until the subproblem is trivial and be a base case. In practice, we just need to draw a few layers to find the rule. The cost will be the sum of costs of all layers.  The process can be seen in  Fig.~\\ref{fig:recursive_tree}. \n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width=0.98\\columnwidth]{fig/recursion_tree_non_overlap.png}\n    \\caption{The process to construct a recursive tree for $T(n) = 3T(\\floor*{n/4}) + O(n)$. There are totally k+1 levels. Use a better figure.  }\n    \\label{fig:recursive_tree}\n\\end{figure}\n In this case, it is the base case $T(1)$. Through the expansion with iteration and recursion tree, our time complexity function becomes:\n\\begin{align}\n\\label{complexity_non_overlap_2}\n    T(n)&=\\sum_{i=1}^{k}L_i + L_{k+1}\\\\\n    &=n\\sum_{i=1}^{k}(3/4)^{i-1}+3^kT(n/4^k)\n\\end{align}\n\nIn the process, we can see that Eq.~\\ref{complexity_non_overlap_2} and Eq.~\\ref{complexity_non_overlap_1} are the same.  Because $T(n/4^k)=T(1)=1$, we have $k=\\log_4 n$. \n\\begin{align}\n\\label{complexity_non_overlap_2}\n    T(n)&\\leq n\\sum_{i=1}^{\\infty}(3/4)^{k-1}+3^kT(n/4^k)\\\\\n    &\\leq 1/(1-3/4)n+3^{\\log_4 n} T(1)= 4n+n^{log_4 3}\n    &\\leq 5n \\\\\n    &=O(n)\n\\end{align}\n\n\n\n\\subsection{Mathematical Induction}\nMathematical induction is a mathematical proof technique, and is essentially used to prove that a property $P(n)$ holds for every natural number $n$, i.e. for $n=0, 1, 2, 3$, and so on. Therefore, in order to use induction, we need to make a \\textit{guess} of the closed-form solution for $a_n$. Induction requires two cases to be proved. \n\\begin{enumerate}\n    \\item \n \\textit{Base case:} proves that the property holds for the number $0$. \n\\item \\textit{Induction step:} proves that, if the property holds for one natural number $n$, then it holds for the next natural number $n+1$.\n\\end{enumerate}\n\nFor $T(n)=2\\times T(n-1) +1, T_0 = 0$, we can have the following result by expanding $T(i), i \\in [0, 7]$.\n\\begin{lstlisting}[numbers=none]\nn    0 1 2 3 4 5 6 7\nT_n  0 3 7 15 31 63 127\n\\end{lstlisting}\nIt is not hard that we find the rule and guess $T(n) = 2^n-1$. Now, we prove this equation by induction:\n\\begin{enumerate}\n    \\item Show that the basis is true: $T(0) = 2^0 -1 = 0$.\n    \\item Assume it holds true for $T(n-1)$. By induction, we get\n    \\begin{align}\n        T(n)&=2T(n-1) + 1 \\\\\n        &=2 (2^{n-1} - 1) + 1 \\\\\n        &= 2^n -1\n    \\end{align}\n    Now we show that the induction step holds true too. \n\\end{enumerate}\n\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Solve $T(n)=T(n/2)+O(1)$ and $T(2n)\\leq2T(n)+2n-1, T(2)=1$.}\n\\end{bclogo}\n\n\n\\paragraph{Briefying on Other Methods}\nWhen the form of the linear recurrence is more complex, say large degree of $k$, more complex of the $f(n)$, none of the iterative and induction methods is practical and managable. For iterative method, the expansion will be way too messy for us to handle. On the side of induction method, it is quite challenging or sometimes impossible for us just to ``guess'' or ``generalize'' the exact closed-form of recurrence relation solution purely based on observing a range of expansion.   \n\nThe more general and approachable method  for solving homogeneous linear recurrence relation derives from making a rough guess rather than exact guess, and then solve it via \\textit{characteristic equation}. This general method is pinpointed in Section.~\\ref{subsec_homogeneous_linear_recurrence} with examples. For non-homogeneous linear recurrence relation (Section.~\\ref{subsec_non_homogeneous}), there are generally two ways -- \\textit{symbolic differentiation} and \\textit{method of undetermined coefficients} to solve non-homogeneous linear recurrence relation and both of them relates to solving homogeneous linear relation. The study of the remaining content is most math saturated in the book, while we later on will find out its tremendous help in complexity analysis in Chapter.~\\ref{chapter_complexity_analysis} and potentially in problem solving. \n\n% \\paragraph{Examples} Maybe\n\n% \\subsection{Solving Linear Recursion}\n\\section{Solve Homogeneous Linear Recurrence Relation}\n\n\\label{subsec_homogeneous_linear_recurrence} \nIn this section, we offer a more general and more managable method for solving recurrence relation that is homogeneous defined in Eq.~\\ref{eq_homogeneous_recurrence_relation}. There are three broad methods: using characteristic equation which we will learn  in this section, and the other two-- {linear algebra, and Z-transofrm}~\\footnote{Visit \\url{https://en.wikipedia.org/wiki/Recurrence_relation} for details.} will not be included. \n\\paragraph{Make a General ``Guess''} From our previous examples, we can figure out the closed-form solution for simplied homogeneous linear recurrence such as the fibonacci recurrence relation:\n\\begin{equation}\na_n = a_{n-1}+a_{n-2}, a_0=0, a_1=1\n\\label{homogeneous_linear_recurrence_guess}\n\\end{equation}\nA reasonable guess would be that $a_n$ is doubled every time; namely, it is approximately $2^n$. Let's guess $a_n=c2^n$ for some constant $c$. Now we substitute Eq.~\\ref{homogeneous_linear_recurrence_guess}, we get\n\\begin{equation}\nc2^n = c2^{n-1} + c2^{n-2} = c2^n\n\\label{homogeneous_linear_recurrence_guess}\n\\end{equation}\nWe can see that $c$ will be canceled and the left side is always greater than the right side. Thus we learned that $c2^n$ is a too large guess, and the multiplicative constant $c$ plays no role in the induction step. \n\nBased on the above example, we introduce a parameter $\\gamma$ as a base, $a_n = \\gamma ^{n}$ for some $\\gamma$. We then compute its value through solving \\textit{Characteristic Equation} as introduced below. \n\\paragraph{Characteristic Equation} \nNow, we substitute our guess into the Eq.\\ref{eq_homogeneous_recurrence_relation}, then \n\\begin{align}\n    \\gamma^n & = a_n \\\\\n    &= c_1 \\gamma^{n-1} + c_2 \\gamma^{n-2} + ... +  c_k \\gamma^{n-k}.\n    \\label{eq_characteristic_equation_1}\n\\end{align}\nWe rewrite Eq.~\\ref{eq_characteristic_equation_1} as:\n\\begin{align}\n    \\gamma^n  - c_1 \\gamma^{n-1} - c_2 \\gamma^{n-2} - ... -  c_k \\gamma^{n-k} = 0.\n    \\label{eq_characteristic_equation_2}\n\\end{align}\nBy dividing $\\gamma^{n-k}$ from left and right side of the equation, we get the simplified equation, which is called the \\textit{characteristic equation} of the recurrence relation in the form of Eq.~\\ref{eq_homogeneous_recurrence_relation}.\n\\begin{align}\n    \\gamma^k  - c_1 \\gamma^{k-1} - c_2 \\gamma^{k-2} - ... -  c_k = 0.\n    \\label{eq_characteristic_equation_3}\n\\end{align}\nThe concept of characteristic equation is related to generating function\\footnote{}.  The solutons of characteristic equation are called \\textit{characteristic roots}. \n\n\\paragraph{Characteristic Roots and Solution} Now, we have a linear homogeneous recurrence relation and its characteristic equation, \n% \\begin{align}\n%   a_n&=c_1a_{n-1} + c_2a_{n-2} + ... + c_k a_{n-k}. \\\\\n% 0&= \\gamma^k  - c_1 \\gamma^{k-1} - c_2 \\gamma^{k-2} - ... -  c_k.\n% \\end{align}\nand assume that the equation has $k$ distinct roots, $\\gamma_1, \\gamma_2, ..., \\gamma_k$, then we can build upon these chracteristic roots, the general guess, and some other $k$ constants, $d_1, d_2, ,,, d_k$ of $\\{a_n\\}$ as:\n\\begin{align}\n    a_n = d_1\\gamma_1^n + d_2\\gamma_2^n +...+d_k\\gamma_k^n\n\\end{align}\nThe unknown constants, $d_1, d_2, ,,, d_k$ of $\\{a_n\\}$ can be found using the initial values $a_0, a_1, ..., a_{k-1}$ by solving the following equations:\n\\begin{align}\n    a_0 &= d_1\\gamma_1^0 + d_2\\gamma_2^0 +...+d_k\\gamma_k^0,\\\\\n    a_1 &= d_1\\gamma_1^1 + d_2\\gamma_2^1 +...+d_k\\gamma_k^1, \\\\\n    &...,\\\\\n    a_{k-1} &= d_1\\gamma_1^{k-1} + d_2\\gamma_2^{k-1} +...+d_k\\gamma_k^{k-1}.\n\\end{align}\nWithin the context of computer science, the degree is mostly within 2. Here, we introduce the formula solving the character roots for  characteristic equation with the following form:\n\\begin{equation}\n   0 = ax^2+bx+c\n\\end{equation}\n% The root(s) of the function is the value(s) of $x$ which makes $f(x)=0$. \nThe root(s) can be computed from the following formula~\\footnote{Visit {http://www.biology.arizona.edu/biomath/tutorials/Quadratic/Roots.html} for derivation} :\n\\begin{equation}\n    x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}\n\\end{equation}\n\\paragraph{Hands-on Example}\nFor $a_n = 2a_{n-1} + 3a_{n-2}, a_0=3, a_1=5$, we can write the characteristic equation as $\\gamma^2-2\\gamma-3=0$. Because $\\gamma^2-2\\gamma-3 = (\\gamma-3)+(\\gamma+1)$, which make the characteristic roots $\\gamma_1=3, \\gamma_2=-1$. Now our solution has the form:\n\\begin{align}\n    a_n = d_13^n+d_2{(-1)}^{n}\n\\end{align}\nNow, we find the constants via listing the initial values we know:\n\\begin{align}\n    a_0 &= d_13^0+d_2{(-1)}^{0} = d_1+d_2=3, \\\\\n a_1 &= d_13^1+d_2{(-1)}^{1} = 3d_1-d_2=5.\n\\end{align}\nWe would get $d_1=2, d_2=1$. Finally, we have a solution $a_n = 2*3^n+(-1)^n$. \n% \\paragraph{Linear Algebra}\n% \\paragraph{Z-transform}\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Continue to solve $a_n=a_{n-1}+a_{n-2}$.}\n\\end{bclogo}\n\n\\section{Solve Non-homogeneous Linear Recurrence Relation}\n\\label{subsec_non_homogeneous}\n \\textit{method of undetermined coefficients} where the solution is comprised of the solution of the homogeneous part and the particular $f(n)$ part by summing up; and the method of \\textit{symbolic differentiation} which converts from the equation the same form of homogeneous linear recurrence relation. \n \nThe complexity analysis for most algorithms fall into the form of non-homogeneous linear recurrence relation. For examples: in fibonacci sequence, if it is be solved by using recursion shown in Chapter.~\\ref{chapter_dynamic-programming} without caching mechanism, the time recurrence relation is $T(n)=T(n-1)+T(n-2)+1$; in the merge sort discussed in Chapter.~\\ref{chapter_divide_conquer}, the recurrence relation is $T(n)=T(n/2)+n$. Examples of recurrence relation $T(n)=T(n-1)+n$ can be easily found, such as the maximum subarray. \n% \\subsection{Solving None-linear Recursion}\n\n\\paragraph{Method of Undetermined Coefficients} Suppose we have a recurrence relation in the form of Eq.~\\ref{eq_non_homogeneous_recurrence_relation}. \n\nSuppose we ignore the non-linear part and just look at the homogeneous part:\n\\begin{equation}\n    h_n=c_1h_{n-1} + c_2h_{n-2} + ... + c_k h_{n-k}.\n    \\label{eq_non_homogeneous_recurrence_relation_2}\n\\end{equation}\n\n\\paragraph{Symbolic Differentiation}\n\n\n\n% \\section{Hands-on Examples}\n% \\label{sec_iter_recur_examples}\n\\section{Useful Math Formulas}\nKnowing these facts can be very important in practice, we can treat each as an element in the problem solving. Sometimes, when its hard to get the closed form of a recurrence relation or finding the recurrence relation, we decompse it to multiple parts with these elements. Put some examples. \n\\paragraph{binomial theorem}\n\\begin{align}\n    \\sum_{k=0}^{n}C_{n}^{k}x^k = (1+x)^n\n\\end{align}\nAn example of using this the cost of generating a powerset, where $x=1$.\n\\section{Exercises}\n\\begin{enumerate}\n    \\item Compute factorial sequence using \\texttt{while} loop.\n    \\item Greatest common divisor: The Euclidean algorithm, which computes the greatest common divisor of two integers, can be written recursively.\n    \\begin{equation}\n            gcd(x, y)=\n        \\begin{cases}\n  x & \\text{if $y=0$,}\\\\\n  gcd(y, x\\% y) & \\text{if $y>0$}\n\\end{cases}\n    \\end{equation}\n\nFunction definition: \n\\end{enumerate}\n\n\\section{Summary}\nIf a cursive algorithm can be further optimized, the optimization method can either be divide and conquer or decrease and conquer. We have put much effort into solving recurrence relation of both: the linear recurrence relation for decrease and conquer, the divide and conquer recurrence relation for divide and conquer.  Right now, do not struggle and eager to know what is divide or decrease and conquer, it will be explained in the next two chapters. \n\nFurther, Akra-Bazzi Method~\\footnote{} applies to recurrence such that $T(n)=T(n/3)+T(2n/3)+O(n)$. Please look into more details if interested. Generating function is used to solve the linear recurrence.\n\\end{document}", "meta": {"hexsha": "b7c48849e9a07dae168a80067293643ceedc4d96", "size": 21857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_recurrence_relation.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_recurrence_relation.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_recurrence_relation.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.8923611111, "max_line_length": 860, "alphanum_fraction": 0.7331289747, "num_tokens": 6268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6842925546506775}}
{"text": "\\def\\A{\\mathbb{A}}\n\\def\\k{\\mathbb{C}}\n\\def\\N{\\mathbb{N}}\n\\def\\R{\\mathbb{R}}\n\\def\\P{\\mathbb{P}}\n\\def\\ZZ{\\mathbb{Z}} \n\n\\title{Algorithms for the Toric Hilbert Scheme}\n\\titlerunning{Toric Hilbert Schemes}\n\\toctitle{Algorithms for the Toric Hilbert Scheme}\n\\author{Michael Stillman\n        % \\inst 1\n         \\and Bernd Sturmfels\n        % \\inst 2\n         \\and Rekha Thomas \n        % \\inst 3\n        }\n\\authorrunning{M. Stillman, B. Sturmfels, and R. Thomas}\n% \\institute{Cornell University, Department of Mathematics, Ithaca, NY 14853, USA\n%         \\and UC Berkeley, Department of Mathematics, Berkeley, CA 94720, USA\n%         \\and University of Washington, Department of Mathematics, Seattle, WA 98195, USA}\n\\maketitle\n\n\\begin{abstract}\nThe toric Hilbert scheme parametrizes all algebras isomorphic to a\ngiven semigroup algebra as a multigraded vector space. All components\nof the scheme are toric varieties, and among them, there is a fairly\nwell understood coherent component. It is unknown whether\ntoric Hilbert schemes are always connected. In this chapter we\nillustrate the use of \\Mtwo for exploring the structure of toric\nHilbert schemes. In the process we will encounter algorithms from\ncommutative algebra, algebraic geometry, polyhedral theory and\ngeometric combinatorics.\n\\end{abstract}\n\n\\section*{Introduction}\nConsider the multigrading of the polynomial ring $R =\n\\k[x_1,\\ldots,x_n]$ specified by a non-negative integer $d \\times\nn$-matrix $A = (a_1,\\ldots,a_n)$ such that degree $(x_i) = a_i \\in\n\\N^d$. This defines a decomposition $\\, R = \\bigoplus_{b \\in \\N A} R_b\n$, where $\\N A$ is the subsemigroup of $\\N^d$ spanned by\n$a_1,\\ldots,a_n$, and $R_b$ is the $\\k$-span of all monomials $\\, x^u\n= x_1^{u_1}\\cdots x_n^{u_n}$ with degree $Au = a_1 u_1 +\\cdots + a_n\nu_n = b$.  The {\\it \\ie{toric Hilbert scheme}} $\\,Hilb_A \n\\,$ parametrizes all $A$-homogeneous ideals $I \\subset R$ (ideals that\nare homogeneous under the multigrading of $R$ by $\\N A$) with the\nproperty that $(R/I)_b$ is a $1$-dimensional $\\k$-vector space, for all\n$b \\in \\N A$. We call such an ideal $I$ an $A$-{\\em graded}\\index{ideal!$A$-graded} ideal.\nEquivalently, $I$ is $A$-graded if it is $A$-homogeneous and $R/I$ is\nisomorphic as a multigraded vector space to the semigroup algebra $\\,\n\\k [ \\N A ] = R/I_A$, where $$I_A := \\,\\langle x^u - x^v \\, : \\, Au =\nAv \\rangle \\subset R$$ is the {\\it \\ie{toric ideal}} of $A$. An $A$-graded\nideal is generated by binomials and monomials in $R$ since, by\ndefinition, any two monomials $x^u$ and $x^v$ of the same degree $Au = \nAv$ must be $\\k$-linearly dependent modulo the ideal.\n\nWe recommend \\cite[\\S 4, \\S 10]{HS:St2} as an introductory reference for the \ntopics in this chapter.\nThe study of toric Hilbert schemes for $d=1$ goes back to\nArnold \\cite{HS:Arn} and Korkina et al.\\cite{HS:KPR}, and it was\nfurther developed by Sturmfels  (\\cite{HS:St1} and \\cite[\\S 10]{HS:St2}). \nPeeva and Stillman \\cite{HS:PS1} introduced the scheme structure \nthat gives the toric Hilbert scheme its universal property,\nand from this they derive a formula for the tangent space\nof a point on  $\\, Hilb_A $. Maclagan recently showed that the \nquadratic binomials in \\cite[\\S 5]{HS:St1} define the same scheme as the\ndeterminantal equations in \\cite{HS:PS1}.\nBoth of these systems of global equations are \ngenerally much too big for \npractical computations. Instead, most of our algorithms are based on\nthe local equations given by Peeva and Stillman in \\cite{HS:PS2}\nand the combinatorial approach of Maclagan and Thomas in \\cite{HS:MT}.\n\nWe begin with the computation of a toric ideal using \\Mtwo. Our\nrunning example throughout this chapter is the following $2 \\times\n5$-matrix:\n\\begin{equation}\n\\label{OurMatrix}\nA = \\left( \\begin{matrix}\n           1 & 1 & 1 & 1 & 1  \\\\ \n           0 & 1 & 2 & 7 & 8 \n\\end{matrix} \\right),\n\\end{equation}\nwhich we input to \\Mtwo as a list of lists of \nintegers.\n<<<A = {{1,1,1,1,1},{0,1,2,7,8}}; >>>\nThe toric ideal of $A$ lives in the multigraded ring $R := \\k [a,b,c,d,e]$.\n<<<R = QQ[a..e,Degrees=>transpose A]; >>>\n<<<describe R >>>\n\nWe use Algorithm 12.3 in \\cite{HS:St2} to compute $I_A$. The first step is\nto find a matrix $B$ whose rows generate the lattice $ker_{\\ZZ}(A)\n:= \\{x \\in \\ZZ^n : Ax = 0 \\}$. \n\n<<<B = transpose syz matrix A >>>\n\nAlthough in theory any basis of $ker_{\\ZZ}(A)$ will suffice, in\npractice it is more efficient to use a {\\em reduced} basis\n\\cite[\\S 6.2]{HS:Sch}, which can be computed using the {\\em \\ie{basis\nreduction}} package {\\tt LLL.m2} in \\Mtwo. The command {\\tt LLL} \nwhen applied to the output of {\\tt syz matrix A} will return a \nmatrix of the same size whose columns form a reduced lattice basis \nfor $ker_{\\ZZ}(A)$. The output appears in compressed form as follows:\n\n<<<load \"LLL.m2\"; >>>\n<<<LLL syz matrix A >>>\n\nWe recompute $B$ using this package to get the following $3 \\times 5$ matrix.\n<<<B = transpose LLL syz matrix A >>>\n\nThe advantage of a reduced basis may not be apparent in small\nexamples. However, as the size of $A$ increases, it becomes\nincreasingly important for the termination of Algorithm 12.3 in \\cite{HS:St2}. (To\nappreciate this, consider the matrix (\\ref{non-normal}) from \nSection~4.)\n\nA row $b = b^+ - b^-$ of $B$ is then coded as the binomial\n$x^{b^+}-x^{b^-} \\in R$, and we let $J$ be the ideal generated by all \nsuch binomials. \n\n<<<toBinomial = (b,R) -> (\n     top := 1_R; bottom := 1_R;\n     scan(#b, i -> if b_i > 0 then top = top * R_i^(b_i)\n          else if b_i < 0 then bottom = bottom * R_i^(-b_i));\n     top - bottom); >>>\n\n<<<J = ideal apply(entries B, b -> toBinomial(b,R)) >>>\nThe toric ideal equals $(J : (x_1 \\cdots x_n)^\\infty)$, which is \ncomputed via $n$ successive saturations as follows:\n<<<scan(gens ring J, f -> J = saturate(J,f))>>>\n\nPutting the above pieces of code together, we get the following\nprocedure for computing the toric ideal of a matrix $A$.\n\n<<<toricIdeal = (A) -> (\n    n := #(A_0);  \n    R = QQ[vars(0..n-1),Degrees=>transpose A,MonomialSize=>16]; \n    B := transpose LLL syz matrix A;\n    J := ideal apply(entries B, b -> toBinomial(b,R));\n    scan(gens ring J, f -> J = saturate(J,f));\n    J\n    ); >>>\n\nSee \\cite{HS:BLR}, \\cite{HS:HS} and \\cite[\\S 4, \\S 12]{HS:St2} for other\nalgorithms for computing toric ideals and various ideas for\nspeeding up the computation.\n\nIn our example, $I_A = \\langle\ncd-be,bd-ae,b^2-ac,a^2d^2-c^3e,c^4-a^3e,bc^3-a^3d,\nad^4-c^2e^3,d^6-ce^5 \\rangle$, which we now compute using this\nprocedure.  \n\n<<<I = toricIdeal A; >>> \n<<<transpose mingens I>>>\n\nThis ideal defines an embedding of\n$\\P^1$ as a degree $8$ curve into $\\P^4$. We will see in Section 3\nthat its toric Hilbert scheme $Hilb_A$ has a non-reduced component.\n\nThis chapter is organized into four sections and two appendices as\nfollows. The main goal in Section~1 is to describe an algorithm for\ngenerating all monomial $A$-graded ideals for a given $A$. These\nmonomial ideals are the vertices of the {\\em flip graph} of $A$ whose\nconnectivity is equivalent to the connectivity of $Hilb_A$. We\ndescribe how all neighbors of a given vertex of this graph can be\ncalculated. In Section~2, we explain the role of polyhedral geometry\nin the study of $Hilb_A$. Our first algorithm tests for {\\em\ncoherence} in a monomial $A$-graded ideal. We then show how to compute\nthe polyhedral complexes supporting $A$-graded ideals, which in turn\nrelate the flip graph of $A$ to the {\\em \\ie{Baues graph}} of $A$.  For\nunimodular matrices, these two graphs coincide and hence our method of\ncomputing the flip graph can be used to compute the Baues\ngraph. Section~3 explores the components of $Hilb_A$ via local\nequations around the torus fixed points of the scheme. We include a\ncombinatorial interpretation of these local equations from the point\nof view of integer programming.  The scheme $Hilb_A$ has a {\\em\ncoherent} component, which is examined in detail in Section~4. We prove\nthat this component is, in general, not normal and that its\nnormalization is the toric variety of the Gr\\\"obner fan of $I_A$. We\nconclude the chapter with two appendices, each containing one large\npiece of \\Mtwo code that we use in this chapter. Appendix \\ref{FMe} displays\ncode from the \\Mtwo file {\\tt polarCone.m2} that is used to convert a generator\nrepresentation of a polyhedron to an inequality representation and\nvice versa. Appendix \\ref{Mpor} displays code from the file {\\tt minPres.m2} used for computing minimal\npresentations of polynomial quotient rings. The main ingredient of\nthis package is the subroutine {\\tt removeRedundantVariables}, which is\nwhat we use in this chapter.\n\n\\section{Generating Monomial Ideals}\nWe start out by computing the {\\it \\ie{Graver basis}} $Gr_A$, which is the\nset of binomials in $I_A$ that are minimal with respect to the\npartial order defined by $$\\, x^u - x^v \\,\\leq\\, x^{u'} - x^{v'} \\quad \\iff\n\\quad \\hbox{ $x^u$ divides $x^{u'}$ \\ and \\ $x^v$ divides $x^{v'}$.}\n$$ The set $Gr_A$ is a {\\em universal Gr\\\"obner basis}\\index{Grobner basis@Gr\\\"obner basis!universal} of $I_A$ and\nhas its origins in the theory of integer programming \\cite{HS:Gra}. It\ncan be computed using \\cite[Algorithm 7.2]{HS:St2}, a \\Mtwo version of\nwhich is given below.\n\n<<<graver = (I) -> (\n    R := ring I;\n    k := coefficientRing R;\n    n := numgens R;\n    -- construct new ring S with 2n variables\n    S := k[Variables=>2*n,MonomialSize=>16];\n    toS := map(S,R,(vars S)_{0..n-1});\n    toR := map(R,S,vars R | matrix(R, {toList(n:1)}));\n    -- embed I in S\n    m := gens toS I;\n    -- construct the toric ideal of the Lawrence \n    -- lifting of A\n    i := 0;\n    while i < n do (\n        wts := join(toList(i:0),{1},toList(n-i-1:0));\n        wts = join(wts,wts);\n        m = homogenize(m,S_(n+i),wts);\n        i=i+1;\n        );\n   J := ideal m;\n   scan(gens ring J, f -> J = saturate(J,f));\n   -- apply the map toR to the minimal generators of J \n   f := matrix entries toR mingens J;\n   p := sortColumns f;\n   f_p) ;  >>>\n   \n   The above piece of code first constructs a new polynomial ring $S$\n   in $n$ more variables than $R$. Assume $S = \\k [x_1, \\ldots, x_n,\n   y_1, \\ldots, y_n]$. The inclusion map {\\tt toS} $: R \\rightarrow\n   S$ embeds the toric ideal $I$ in $S$ and collects its generators in\n   the matrix {\\tt m}. A binomial $x^a - x^b$ lies in $Gr_A$ if and only\n   if $x^ay^b-x^by^a$ is a minimal generator of the toric ideal in $S$\n   of the $(d+n) \\times 2n$ matrix $$\\Lambda(A) := \\left (\n     \\begin{array}{cc} A & 0 \\\\ I_n & I_n \\end{array} \\right),$$ which\n   is called the {\\em \\ie{Lawrence lifting}} of $A$. Since $u \\in\n   ker_{\\ZZ}(A) \\Leftrightarrow (u,-u) \\in ker_{\\ZZ} (\\Lambda(A))$, we\n   use the {\\tt while}\\indexcmd{while} loop to homogenize the binomials in {\\tt m} with\n   respect to $\\Lambda(A)$, using the $n$ new variables in $S$. This\n   converts a binomial $x^a-x^b \\in$ {\\tt m} to the binomial\n   $x^ay^b-x^by^a$.  The ideal generated by these new binomials is\n   labeled $J$. As before, we can now successively saturate $J$\n   to get the toric ideal of $\\Lambda(A)$ in $S$. The image of the\n   minimal generators of this toric ideal under the map {\\tt toR}\n   $: S \\rightarrow R$ such that $x_i \\mapsto x_i$ and $y_i \\mapsto 1$\n   is precisely the Graver basis $Gr_A$. These binomials are the\n   entries of the matrix {\\tt f} and is output by the program.\n\nIn our example $Gr_A$ consists of $42$ binomials.\n<<<Graver = graver I >>> \n\nReturning to the general case, an element $b $ of $\\N A$ is called a\n{\\it \\ie{Graver degree}} if there exists a binomial $x^u - x^v$ in the\nGraver basis $Gr_A$ such that $Au = Av = b$. If $b$ is a Graver degree\nthen the set of monomials in $R_b$ is the corresponding {\\it \\ie{Graver\n  fiber}}.  In our running example there are $37$ distinct Graver\nfibers. We define the {\\tt ProductIdeal} of $A$ as $PI := \n\\langle x^ax^b : x^a-x^b  \\in Gr_A \\rangle$. This ideal is contained in\nevery monomial ideal of $Hilb_A$ and hence no monomial in $PI$ can be\na standard monomial of a monomial $A$-graded ideal. Since our purpose\nin constructing Graver fibers is to use them to \ngenerate all monomial $A$-graded ideals, we will be content with\nlisting just the monomials in each Graver fiber that do not lie in\n$PI$.  Since $R$ is multigraded by $A$, we can obtain such a\npresentation of a Graver fiber by simply asking for the basis of $R$\nin degree $b$ modulo $PI$.  \n\n<<<graverFibers = (Graver) -> (\n     ProductIdeal := (I) -> ( trim ideal(\n        apply(numgens I, a -> ( \n            f := I_a; leadTerm f * (leadTerm f - f))))); \n     PI := ProductIdeal ideal Graver; \n     R := ring Graver; \n     new HashTable from apply(\n         unique degrees source Graver,\n         d -> d => compress (basis(d,R) % PI) ));>>>\n\n<<<fibers = graverFibers Graver >>>\n\nFor example, the Graver degree $(8,8)$ corresponds to the Graver fiber\n$$ \\bigl\\{\\,\n\\underline{a^7 e}, \\, \\underline{a^6 b d},\\,  \\underline{a^4 c^4}, \\,\na^3 b^2 c^3,\\, a^2 b^4 c^2,\\,  a b^6 c, \\, \\underline{b^8} \\,\\bigr\\}.$$\nOur \\Mtwo code outputs only the four underlined monomials,\nin the format {\\tt  | a7e a6bd a4c4 b8 |}. The three non-underlined \nmonomials lie in the {\\tt ProductIdeal}. Graver degrees are\nimportant because of the following result.\n\n\\begin{lemma}[{\\cite[Lemma 10.5]{HS:St2}}]\nThe multidegree of any minimal generator of any ideal \n$I$ in $Hilb_A$ is a Graver degree.\n\\end{lemma}\n\nThe next step in constructing the toric Hilbert scheme is to compute\nall its fixed points with respect to the scaling action of the\n$n$-dimensional algebraic torus $(\\k^*)^n$. (The torus $(\\k^{\\ast})^n$\nacts on $R$ by scaling variables : $\\lambda \\mapsto \\lambda \\cdot x :=\n(\\lambda_1 x_1, \\ldots, \\lambda_n x_n)$.)  These fixed points are the\nmonomial ideals $M$ lying on $Hilb_A$.  Every term order $\\prec$ on\nthe polynomial ring $R$ gives such a monomial ideal: $M = in_\\prec(I_A\n)$, the initial ideal of the toric ideal $I_A$ with respect to\n$\\prec$. Two ideals $J$ and $J'$ are said to be {\\em torus\n  isomorphic}\\index{ideal!torus isomorphism}\nif $J = \\lambda \\cdot J'$ for some $\\lambda \\in (\\k^{\\ast})^n$. Any\nmonomial $A$-graded ideal that is torus isomorphic to an initial ideal\nof $I_A$ is said to be {\\em coherent}\\index{ideal!coherent}. In particular, the initial\nideals of $I_A$ are coherent and they can be computed by\n\\cite[Algorithm 3.6]{HS:St2} applied to $I_A$. A refinement and fast\nimplementation can be found in the software package {\\tt TiGERS} by\nHuber and Thomas \\cite{HS:HT}.\n\nNow we wish to compute all monomial ideals $M$ on $Hilb_A$ regardless\nof whether $M$ is coherent or not. For this we use the procedure\n{\\tt generateAmonos} given below. This procedure takes in the Graver\nbasis $Gr_A$ and records the numerator of the Hilbert series of $I_A$\nin {\\tt trueHS}. It then computes the Graver fibers of $A$, sorts them\nand calls the subroutine {\\tt selectStandard} to generate a\ncandidate for a monomial ideal on $Hilb_A$.\n\n<<<generateAmonos = (Graver) -> (\n     trueHS := poincare coker Graver;\n     fibers := graverFibers Graver;\n     fibers = apply(sort pairs fibers, last);\n     monos = {};\n     selectStandard := (fibers, J) -> (\n     if #fibers == 0 then (\n        if trueHS == poincare coker gens J\n        then (monos = append(monos,flatten entries mingens J));\n     ) else (\n        P := fibers_0;\n        fibers = drop(fibers,1);\n        P = compress(P % J);\n        nP := numgens source P; \n        -- nP is the number of monomials not in J.\n        if nP > 0 then (\n           if nP == 1 then selectStandard(fibers,J)\n           else (--remove one monomial from P,take the rest.\n                 P = flatten entries P;\n                 scan(#P, i -> (\n                      J1 := J + ideal drop(P,{i,i});\n                      selectStandard(fibers, J1)))));\n     ));\n     selectStandard(fibers, ideal(0_(ring Graver)));\n     ) ; >>>\n\nThe arguments to the subroutine {\\tt selectStandard}\nare the Graver fibers given as a list of matrices and a monomial \nideal $J$ that should be included in every $A$-graded ideal \nthat we generate. The subroutine then loops through each Graver fiber, \nand at each step selects a standard monomial from that fiber and \nupdates the ideal $J$ by adding the other monomials in this fiber \nto $J$. The final $J$ output by the subroutine is the candidate ideal\nthat is sent back to {\\tt generateAmonos}. It is stored by the program \nif its Hilbert series agrees with that of $I_A$. \nAll the monomial $A$-graded ideals are stored in the list {\\tt monos}.\nBelow, we ask \\Mtwo for the cardinality of {\\tt monos} and its \nfirst ten elements.\n<<<generateAmonos Graver;>>>\n<<<#monos >>>\n<<<scan(0..9, i -> print toString monos#i) >>>\n\nThe monomial ideals (torus-fixed points) on $Hilb_A$ form the vertices\nof the {\\it \\ie{flip graph}} of $A$ whose edges correspond to the\ntorus-fixed curves on $Hilb_A$. This graph was introduced in \\cite{HS:MT}\nand provides structural information about $Hilb_A$.  The edges\nemanating from a monomial ideal $M$ can be constructed as follows: \nFor any minimal generator $x^u$ of $M$, let $x^v$ be the unique\nmonomial with $x^v \\not\\in M$ and $Au = Av$. Form the {\\it \\ie{wall ideal}},\nwhich is generated by $x^u - x^v$ and all minimal generators of $M$\nother than $x^u$, and let $M'$ be the initial monomial ideal of the\nwall ideal with respect to any term order $\\succ$ for which $x^v \\succ\nx^u$. It can be shown that $M'$ is the unique initial monomial ideal\nof the wall ideal that contains $x^v$.  If $M'$ lies on $Hilb_A$ then\n$\\{M, M'\\}$ is an edge of the flip graph. We now illustrate the \\Mtwo\nprocedure for computing all flip neighbors of a monomial $A$-graded\nideal.\n \n<<<findPositiveVector = (m,s) -> (\n     expvector := first exponents s - first exponents m;\n     n := #expvector;\n     i := first positions(0..n-1, j -> expvector_j > 0);\n     splice {i:0, 1, (n-i-1):0}\n     );>>>\n\n<<<flips = (M) -> (\n     R := ring M;\n     -- store generators of M in monoms\n     monoms := first entries generators M;\n     result := {};\n     -- test each generator of M to see if it leads to a neighbor \n     scan(#monoms, i -> (\n       m := monoms_i;\n       rest := drop(monoms,{i,i});\n       b := basis(degree m, R);\n       s := (compress (b % M))_(0,0);\n       J := ideal(m-s) + ideal rest;\n       if poincare coker gens J == poincare coker gens M then (\n         w := findPositiveVector(m,s);\n         R1 := (coefficientRing R)[generators R, Weights=>w];\n         J = substitute(J,R1);\n         J = trim ideal leadTerm J;\n         result = append(result,J);\n         )));\n     result\n);>>>\n\nThe code above inputs a monomial $A$-graded ideal $M$ whose minimal\ngenerators are stored in the list {\\tt monoms}. The flip neighbors of\n$M$ will be stored in {\\tt result}. For each monomial $x^u$ in {\\tt\nmonoms} we need to test whether it yields a flip neighbor of $M$ or\nnot. At the $i$-th step of this loop, we let {\\tt m} be the $i$-th\nmonomial in {\\tt monoms}. The list {\\tt rest} contains all monomials\nin {\\tt monoms} except {\\tt m}. We compute the standard monomial {\\tt\ns} of $M$ of the same degree as $m$.  The wall ideal of $m-s$ is the\nbinomial ideal $J$ generated by $m-s$ and the monomials in {\\tt\nrest}. We then check whether $J$ is $A$-graded by comparing its\nHilbert series with that of $M$. (Alternately, one could check whether\n$M$ is the initial ideal of the wall ideal with respect to $m \\succ\ns$.) If this is the case, we use the subroutine {\\tt\nfindPositiveVector} to find a unit vector $w = (0,\\ldots,1,\\ldots,0)$\nsuch that $w \\cdot s > w \\cdot m$. The flip neighbor is then the\ninitial ideal of $J$ with respect to $w$ and it is stored in {\\tt\nresult}. The program outputs the minimal generators of each flip\nneighbor. Here is an example.\n \n<<<R = QQ[a..e,Degrees=>transpose A];>>>\n<<<M = ideal(a*e,c*d,a*c,a^2*d^2,a^2*b*d,a^3*d,c^2*e^3,\n          c^3*e^2,c^4*e,c^5,c*e^5,a*d^5,b*e^6);>>>\n<<<F = flips M>>>\n<<<#F>>>\n<<<scan(#F, i -> print toString entries mingens F_i)>>>\n\nIt is an open problem whether the toric Hilbert scheme $Hilb_A$ is\nconnected. Recent work in geometric combinatorics \\cite{HS:San} suggests\nthat this is probably false for some $A$. This result and its \nimplications for $Hilb_A$ will be discussed further in Section 2.\nThe following theorem of Maclagan and Thomas \\cite{HS:MT} reduces the  \nconnectivity of $Hilb_A$ to a combinatorial problem.\n\n\\begin{theorem} \nThe toric Hilbert scheme $Hilb_A$ is connected if and only if the \nflip graph of $A$ is connected.\n\\end{theorem}\n\nWe now have two algorithms for listing monomial ideals on $Hilb_A$.\nFirst, there is the {\\it \\ie{backtracking algorithm}} whose \\Mtwo\nimplementation was described above.  Second, there is the {\\it \\ie{flip\n  search algorithm}}, which starts with any coherent monomial ideal $M$\nand then constructs the connected component of $M$ in the flip graph\nof $A$ by carrying out local flips as above.  This procedure is also \nimplemented in {\\tt TiGERS} \\cite{HS:HT}. Clearly, the two algorithms\nwill produce the same answer if and only if $Hilb_A$ is connected. In\nother words, finding an example where $Hilb_A$ is disconnected is\nequivalent to finding a matrix $A$ for which the flip search algorithm\nproduces fewer monomial ideals than the backtracking algorithm.\n\n\\section{Polyhedral Geometry}\n\nAlgorithms from polyhedral geometry are essential in the study of the\ntoric Hilbert scheme. Consider the problem of deciding whether or not\na given monomial ideal $M$ in $Hilb_A$ is coherent.  This problem\ngives rise to a system of linear inequalities as follows: Let\n$x^{u_1}, \\ldots, x^{u_r}$ be the minimal generators of $M$, and let\n$x^{v_i}$ be the unique standard monomial with $A u_i = A v_i$. Then\n$M$ is coherent if and only if there exists a vector $w \\in \\R^n$ such\nthat $\\,w \\cdot (u_i - v_i) > 0\\,$ for $i =1,\\ldots,r$.  Thus the test\nfor coherence amounts to solving a {\\sl feasibility problem of linear\nprogramming}, and there are many highly efficient algorithms (based on\nthe simplex algorithms or interior point methods) available for this\ntask. For our experimental purposes, it is convenient to use the code\n{\\tt polarCone.m2}, given in Appendix \\ref{FMe}, which is based on the\n(inefficient but easy-to-implement) {\\em \\ie{Fourier-Motzkin elimination}}\nmethod (see \\cite{HS:Zie} for a description).  This code converts the\ngenerator representation of a polyhedron to its inequality\nrepresentation and vice versa. A simple example is given in Appendix\n\\ref{FMe}. In particular, given a Gr\\\"obner basis $\\mathcal G$ of $I_A$, the\nfunction {\\tt polarCone} will compute all the extreme rays of the {\\em\nGr\\\"obner cone\\index{Grobner cone@Gr\\\"obner cone}} $\\,\\{ w \\in \\R^n \\,: \\,w \\cdot (u_i - v_i) \\geq 0\\,$\nfor each $x^{u_i}-x^{v_i} \\in {\\mathcal G}\\}.$\n\nWe now show how to use \\Mtwo to decide whether a \nmonomial $A$-graded ideal $M$ is coherent. The first step in \nthis calculation is to compute all the standard monomials of $M$ \nof the same degree as the minimal generators of $M$. We do this \nusing the procedure {\\tt stdMonomials}.\n\n<<<stdMonomials = (M) -> (\n     R := ring M;\n     RM := R/M;\n     apply(numgens M, i -> (\n           s := basis(degree(M_i),RM); lift(s_(0,0), R)))\n     ); >>>\n\nAs an example, consider the following monomial $A$-graded ideal.\n\n<<<R = QQ[a..e,Degrees => transpose A ]; >>>\n<<<M = ideal(a^3*d, a^2*b*d, a^2*d^2, a*b^3*d, a*b^2*d^2, a*b*d^3, \n          a*c, a*d^4, a*e, b^5*d, b^4*d^2, b^3*d^3, b^2*d^4, \n          b*d^5, b*e, c*e^5); >>>\n<<<toString stdMonomials M >>>\n\nFrom the pairs $x^u,x^v$ of minimal generators $x^u$ and\nthe corresponding standard monomials $x^v$, the function {\\tt inequalities}\ncreates a matrix whose columns are the vectors $u-v$. \n\n<<<inequalities = (M) -> (\n        stds := stdMonomials(M);\n        transpose matrix apply(numgens M, i -> (\n            flatten exponents(M_i) - \n                flatten exponents(stds_i)))); >>>\n<<<inequalities M>>>\n\nIt is convenient to simplify the output of the next procedure \nusing the following program to divide an integer vector \nby the g.c.d. of its components. We also load {\\tt polarCone.m2},\nwhich is needed in {\\tt decideCoherence} below.\n\n<<<primitive := (L) -> (\n     n := #L-1; g := L#n;\n     while n > 0 do (n = n-1; g = gcd(g, L#n););\n     if g === 1 then L else apply(L, i -> i // g));>>>\n\n<<<load \"polarCone.m2\" >>>\n\n<<<decideCoherence = (M) -> (\n     ineqs := inequalities M;\n     c := first polarCone ineqs;\n     m := - sum(numgens source c, i -> c_{i});\n     prods := (transpose m) * ineqs;\n     if numgens source prods != numgens source compress prods\n     then false else primitive (first entries transpose m)); >>>\n \nLet $K$ be the cone $\\{x \\in {\\mathbb R}^n : g \\cdot x \\leq 0$,\nfor all columns $g$ of {\\tt ineqs} \\}. The command {\\tt\npolarCone ineqs} computes a pair of matrices $P$ and $Q$ such\nthat $K$ is the sum of the cone generated by the columns of $P$\nand the subspace generated by the columns of $Q$. Let {\\tt m} be\nthe negative of the sum of the columns of $P$. Then {\\tt m} lies\nin the cone $-K$. The entries in the matrix {\\tt prods} are the\ndot products $g \\cdot m$ for each column $g$ of {\\tt ineqs}.\nSince $M$ is a monomial $A$-graded ideal, it is coherent if and\nonly if $K$ is full dimensional, which is the case if and only if\nno dot product $g \\cdot m$ is zero. This is the conditional in\nthe {\\tt if .. then} statement of {\\tt decideCoherence}. If $M$\nis coherent, the program outputs the primitive representative of\n{\\tt m} and otherwise returns the boolean {\\tt false}. Notice that \nif $M$ is coherent, the cone $-K$ is the Gr\\\"obner cone corresponding \nto $M$ and the vector {\\tt m} is a weight vector $w$ such that\n$in_w(I_A) = M$. We now test whether the ideal $M$ from \nline {\\tt i29} is coherent.\n\n<<<decideCoherence M>>>\n\nHence, $M$ is coherent: it is the initial ideal with respect to the \nweight vector $w = (0,0,1,15,18)$ of the toric ideal in our running\nexample (\\ref{OurMatrix}). Here is one of the 55 noncoherent\nmonomial $A$-graded ideals of this matrix.\n\n<<<N = ideal(a*e,c*d,a*c,c^3*e,a^3*d,c^4,a*d^4,a^2*d^3,c*e^5,\n           c^2*e^4,d^7);>>>\n<<<decideCoherence N>>>\n\nIn the rest of this section, we study the connection between\n$A$-graded ideals and polyhedral complexes defined on $A$.  This study\nrelates the flip graph of the toric Hilbert scheme to the Baues\ngraph of the configuration $A$.                  (See \\cite{HS:Reiner} for a\nsurvey of the Baues problem and its relatives).  Let $pos(A) := \\{ Au\n: u \\in \\R^n, u \\geq 0 \\}$ be the cone generated by the columns of $A$\nin $\\R^d$. A {\\em \\ie{polyhedral subdivision}} $\\Delta$ of $A$ is a\ncollection of full dimensional subcones $pos(A_{\\sigma})$ of $pos(A)$\nsuch that the union of these subcones is $pos(A)$ and the intersection\nof any two subcones is a face of each.  Here $A_{\\sigma} := \\{a_j : j\n\\in \\sigma \\subseteq \\{1,\\ldots,n\\} \\}$.  It is customary to identify \n$\\Delta$ with the set of sets $\\{ \\sigma : pos(A_{\\sigma}) \\in \\Delta\n\\}$. If every cone in the \nsubdivision $\\Delta$ is simplicial (the number of extreme rays of the\ncone equals the dimension of the cone), we say that $\\Delta$ is a {\\em\n  \\ie{triangulation}} of $A$. The simplicial complex corresponding\nto a triangulation $\\Delta$ is uniquely obtained by including in\n$\\Delta$ all the subsets of every $\\sigma \\in \\Delta$. We refer the\nreader to \\cite[\\S 8]{HS:St2} for more details.\n\nFor each $\\sigma \\in \\Delta$, let $I_{\\sigma}$ be the prime ideal \nthat is the sum of the toric ideal $I_{A_{\\sigma}}$ and the monomial \nideal $\\langle x_j :j \\not \\in \\sigma \\rangle$. Recall that two\nideals $J$ and $J'$ are said to be \n{\\em torus isomorphic} if $J = \\lambda \\cdot J'$ for some $\\lambda \\in \n(\\k^{\\ast})^n$. The following theorem shows that polyhedral\nsubdivisions of $A$ are related to $A$-graded ideals via their \nradicals.\n\n\\begin{theorem}[Theorem~10.10 {\\cite[\\S 10]{HS:St2}}]\\label{polysubdivisions}\n  If $I$ is an $A$-graded ideal, then there exists a polyhedral\n  subdivision $\\Delta(I)$ of $A$ such that $\\sqrt{I} = \\cap_{\\sigma\n    \\in \\Delta(I)} J_{\\sigma}$ where each component $J_{\\sigma}$ is a\n  prime ideal that is torus isomorphic to $I_{\\sigma}$.\n\\end{theorem}\n\nWe say that $\\Delta(I)$ supports the $A$-graded ideal $I$.\nWhen $M$ is a monomial $A$-graded ideal, $\\Delta(M)$ is a \ntriangulation of $A$. In particular, if $M$ is coherent (i.e, $M =\nin_w(I_A)$ for some weight vector $w$), then $\\Delta(M)$ is the {\\em\n  regular} or {\\em coherent} triangulation\\index{triangulation!regular} of $A$ induced by $w$\n\\cite[\\S 8]{HS:St2}. The coherent triangulations of $A$ are in bijection\nwith the vertices of the {\\em \\ie{secondary polytope}} of $A$ \\cite{HS:BFS},\n\\cite{HS:GKZ}.  \n\nIt is convenient to represent a triangulation $\\Delta$ of $A$ by its \n{\\em Stanley-Reisner} ideal\\index{Stanley-Reisner ideal} $I_{\\Delta} := \\langle x_{i_1}x_{i_2}\n\\cdots x_{i_k} : \\{ i_1, i_2, \\ldots, i_k \\}$ is a non-face of  \n$\\Delta \\rangle$. If $M$ is a monomial $A$-graded ideal,\nTheorem~\\ref{polysubdivisions} implies that $I_{\\Delta(M)}$ is the \nradical of $M$. Hence we will represent triangulations \nof $A$ by their Stanley-Reisner ideals. As seen below, the matrix in\nour running example has eight distinct triangulations \ncorresponding to the eight distinct radicals of the 281 monomial \n$A$-graded ideals computed earlier. All eight are coherent.\n\n\\medskip\n\n\\begin{tabular}{lll}\n{$\\{\\{1,2\\},\\{2,3\\},\\{3,4\\},\\{4,5\\}\\}$}\n&\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle ac, ad, ae, bd, be, ce\n\\rangle$ \\\\  \n{$\\{\\{1,3\\},\\{3,4\\},\\{4,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,&\n$\\langle b, ad, ae, ce \\rangle$ \\\\  \n{$\\{\\{1,2\\},\\{2,4\\},\\{4,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,&\n$\\langle c, ad, ae, be \\rangle$ \\\\ \n{$\\{\\{1,2\\},\\{2,3\\},\\{3,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,&\n$\\langle d, ac, ae, be \\rangle$ \\\\  \n{$\\{\\{1,3\\},\\{3,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle\nb, d, ae \\rangle$ \\\\ \n{$\\{\\{1,4\\},\\{4,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle\nb, c, ae \\rangle$ \\\\  \n{$\\{\\{1,2\\},\\{2,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle\nc, d, ae \\rangle$ \\\\ \n{$\\{\\{1,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle b, c, d\n\\rangle$   \n\\end{tabular}\n\n\\medskip\n\nThe Baues graph of $A$ is a graph on all the triangulations of\n$A$ in which two triangulations are adjacent if they differ by a\nsingle {\\em \\ie{bistellar flip}} \\cite{HS:Reiner}. The {\\em \\ie{Baues problem}} from\ndiscrete geometry asked whether the Baues graph of a point\nconfiguration can be disconnected for some $A$. Every edge of the\nsecondary polytope of $A$ corresponds to a bistellar flip, and hence\nthe subgraph of the Baues graph that is induced by the coherent\ntriangulations of $A$ is indeed connected: it is precisely the edge\ngraph of the secondary polytope of $A$.  The Baues problem was\nrecently settled by Santos \\cite{HS:San} who gave an example of a six\ndimensional point configuration with $324$ points for which there is\nan isolated (necessarily non-regular) triangulation.\n\nSantos' configuration would also have a disconnected flip graph and hence\na disconnected toric Hilbert scheme if it were true that {\\em every} \ntriangulation of $A$ supports a monomial $A$-graded\nideal. However, Peeva has shown that this need not be the case\n(Theorem~10.13 in \\cite[\\S 10]{HS:St2}). Hence, the map from the set of\nall monomial $A$-graded ideals to the set of all triangulations of\n$A$ that sends $M \\mapsto \\Delta(M)$ is not always\nsurjective, and it is unknown whether Santos' $6 \\times 324$ \nconfiguration has a disconnected toric Hilbert scheme.  \n\nThus, even though one cannot in general conclude that the existence of\na disconnected Baues graph implies the existence of a disconnected\nflip graph, there is an important special situation in which such a\nconclusion is possible. We call an integer matrix $A$ of full row rank\n{\\em unimodular}\\index{matrix!unimodular} if the absolute value of each of its non-zero maximal\nminors is the same constant. A matrix $A$ is unimodular if and only if\nevery monomial $A$-graded ideal is square-free. For a unimodular\nmatrix $A$, the Baues graph of $A$ coincides with the flip graph of\n$A$. As you might expect, Santos' configuration is not unimodular.\n\n\\begin{theorem}[Lemma~10.14 {\\cite[\\S 10]{HS:St2}}]\\label{unimodular}\nIf $A$ is unimodular, then each triangulation of $A$ supports a unique\n(square-free) monomial $A$-graded ideal. In this case, a monomial\n$A$-graded ideal is coherent if and only if the triangulation\nsupporting it is coherent.\n\\end{theorem}\n\nUsing Theorem~\\ref{unimodular} we can compute all the triangulations\nof a unimodular matrix since they are precisely the polyhedral\ncomplexes supporting monomial $A$-graded ideals. Then we could\nenumerate the connected component of a coherent monomial $A$-graded\nideal in the flip graph of $A$ to decide whether the Baues/flip graph\nis disconnected.\n\nLet $\\Delta_r$ be the standard $r$-simplex that \nis the convex hull of the $r+1$ unit vectors in $\\R^{r+1}$, and let \n$A(r,s)$ be the $(r+s+2) \\times (r+1)(s+1)$ matrix whose columns \nare the products of the vertices of $\\Delta_r$ and $\\Delta_s$. All \nmatrices of type $A(r,s)$ are unimodular. From the\nproduct of two triangles we get $$A(2,2) := \n\\left ( \\begin{array}{ccccccccc}\n1&1&1&0&0&0&0&0&0\\\\\n0&0&0&1&1&1&0&0&0\\\\\n0&0&0&0&0&0&1&1&1\\\\\n1&0&0&1&0&0&1&0&0\\\\\n0&1&0&0&1&0&0&1&0\\\\\n0&0&1&0&0&1&0&0&1 \\end{array} \\right ).$$\nWe can now use our algebraic algorithms to compute all\nthe triangulations of $A(2,2)$. Since \\Mtwo requires the first entry \nof the degree of every variable in a ring to be positive, we use \nthe following matrix with the same row space as $A(2,2)$ for our \ncomputation:\n\n<<<A22 =\n  {{1,1,1,1,1,1,1,1,1},{0,0,0,1,1,1,0,0,0},{0,0,0,0,0,0,1,1,1},\n  {1,0,0,1,0,0,1,0,0},{0,1,0,0,1,0,0,1,0},{0,0,1,0,0,1,0,0,1}}; >>>\n<<<I22 = toricIdeal A22>>>\nThe ideal {\\tt I22} is generated by the 2 by 2 minors of a 3 by 3\nmatrix of indeterminates.  This is the ideal of $\\P^2 \\times \\P^2$\nembedded in $\\P^8$ via the Segre embedding.\n<<<Graver22 = graver I22;>>>\n<<<generateAmonos(Graver22);>>>\n<<<#monos>>>\n<<<scan(0..9,i->print toString monos#i) >>>\n\nThus there are 108 monomial $A(2,2)$-graded ideals and \n{\\tt decideCoherence} will check that all of them \nare coherent. Since $A(2,2)$ is unimodular, each monomial \n$A(2,2)$-graded ideal is square-free and is hence \nradical. These 108 ideals represent the 108 triangulations of \n$A(2,2)$ and we have listed ten of them above.\nThe flip graph (equivalently, Baues graph) of $A(2,2)$ is connected.\nHowever, it is unknown whether the Baues graph of $A(r,s)$ is \nconnected for all values of $(r,s)$.\n\n\\section{Local Equations}\nConsider the reduced Gr\\\"obner basis of a toric ideal $I_A$ for a\nterm order $w$:\n\\begin{equation}\n\\label{GrobnerBasis} \\bigl\\{ \\,\n x^{u_1} -  x^{v_1} \\, , \\,\\, x^{u_2} -  x^{v_2} \\,, \\,\\, \\ldots \\, , \\,\\,\nx^{u_r} -  x^{v_r}\\, \\bigr\\} .\n\\end{equation}\nThe initial ideal $\\,M = in_w(I_A) = \\langle x^{u_1}, x^{u_2}, \\ldots,\nx^{u_r} \\rangle \\,$ is a coherent monomial $A$-graded ideal. In\nparticular, it is a $(\\k^*)^n$-fixed point on the toric Hilbert scheme\n$Hilb_A$.  We shall explain a method, due to Peeva and Stillman\n\\cite{HS:PS2}, for computing local equations of $Hilb_A$ around such a\nfixed point.  A variant of this method also works for computing the\nlocal equations around a non-coherent monomial ideal $M$, but that\nvariant involves local algebra, specifically Mora's tangent cone\nalgorithm, which is not yet fully implemented in \\Mtwo. See \\cite{HS:PS2}\nfor details.\n\nWe saw how to compute the flip graph of $A$ in Section~1. The vertices\nof this graph are the $(\\k^*)^n$-fixed points $M$ and its edges\ncorrespond to the $(\\k^*)^n$-fixed curves.  By computing and\ndecomposing the local equations around each $M$, we get a complete\ndescription of the scheme $Hilb_A$.\n\nThe first step is to introduce a new variable $ \\, z_i \\,$ for each \nbinomial in our Gr\\\"obner basis (\\ref{GrobnerBasis}) and to consider \nthe following $r$ binomials:\n\\begin{equation}\n\\label{FlatFamily}\n x^{u_1} -  z_1 \\cdot x^{v_1} \\,, \\,\\,\n x^{u_2} - z_2  \\cdot x^{v_2} \\,,\\, \\, \\ldots \\, ,\n\\,\\, x^{u_r} -   z_r \\cdot x^{v_r} \n\\end{equation}\nin the polynomial ring $\\k[x,z]$ in  $n+r$ indeterminates.\nThe term order $w$ can be extended to an elimination term order\nin $\\k[x,z]$ so that $x^{u_i}$ is the leading term of\n$ x^{u_i} -  z_i \\cdot x^{v_i} $ for all $i$. \nWe compute the minimal first syzygies\nof the monomial ideal $M$, and form the\ncorresponding $S$-pairs of binomials in (\\ref{FlatFamily}).\nFor each $S$-pair\n$$\n\\frac{lcm(x^{u_i},x^{u_j})}{x^{u_i}} \\cdot (x^{u_i} - z_i \\cdot\nx^{v_i} ) \\,\\,\\, - \\,\\,\\, \\frac{lcm(x^{u_i},x^{u_j})}{x^{u_j}} \\cdot\n(x^{u_j} - z_j \\cdot x^{v_j}) $$\nwe compute a normal form with respect\nto (\\ref{FlatFamily}) using the extended term order $w$.  The result\nis a binomial in $\\k[x,z]$ that factors as \n$$  x^\\alpha \\cdot z^\\beta \\cdot  ( z^\\gamma - z^\\delta ) , $$\nwhere $\\alpha \\in \\N^n$ and $\\beta,\\gamma,\\delta \\in \\N^r$.\nNote that this normal form is not unique but depends on our\nchoice of a reduction path.\nLet $J_M$ denote the ideal in $\\k[z_1 , \\ldots, z_r]$ generated by all \nbinomials $\\, z^\\beta \\cdot  ( z^\\gamma - z^\\delta ) \\,$\ngotten from normal forms of all the $S$-pairs considered above.\n\n\\begin{proposition}[\\cite{HS:PS2}]\\label{localeqns}\nThe ideal $J_M$ is independent of the reduction paths chosen.\nIt defines a subscheme of $\\k^r$ isomorphic to\nan affine open neighborhood of the point $M$ on \nthe toric Hilbert scheme $Hilb_A$.\n\\end{proposition}\n\nWe apply this technique to compute a particularly interesting affine\nchart of $Hilb_A$ for our running example.\nConsider the following set of $13$ binomials:\n\\begin{eqnarray*}\n& \\bigl\\{ \\,a e - z_1 b d ,  \\,\n c d - z_2 b e , \\,\n a c - z_3 b^2 , \\,\n a^2 d^2 - z_4 c^3 e , \\,\n a^2 b d - z_5 c^4 , \\\\ &\n a^3 d - z_6 b c^3 , \\,\n c^2 e^3 - z_7 a d^4 , \\, \n c^3 e^2 - z_8 a b d^3 , \\,\n c^4 e - z_9 a b^2 d^2 , \\\\ &\n c^5 - z_{10} a b^3 d , \\,\n c e^5 - z_{11} d^6 , \\,\n a d^5 - z_{12} b c e^4 , \\,\n b e^6 - z_{13} d^7  \\, \\bigr\\}.\n\\end{eqnarray*}\nIf we set $\\, z_1 = z_2 = \\cdots = z_{13} = 1\\,$\nthen we get a generating set for the toric ideal $I_A$.\nThe $13$ monomials obtained by setting\n$\\, z_1 = z_2 = \\cdots = z_{13} = 0 \\,$\ngenerate the initial monomial ideal $ M = in_w (I_A)$\nwith respect to the weight vector $w = (9, 3, 5, 0, 0)$.\nThus $M$ is one of the $226$ coherent monomial \n$A$-graded ideals of our running example. The above set of \n13 binomials in $\\k[x,z]$ give the universal family \nfor $Hilb_A$ around this $M$.\n\nThe local chart of $Hilb_A$ around the point $M$\nis a subscheme of affine space $\\k^{13}$ with coordinates \n$z_1, \\ldots, z_{13}$, whose\ndefining equations are obtained as follows: \nExtend the weight vector $w$ by assigning\nweight zero to all variables $z_i$, so that\nthe first term in each of the above $13$ binomials\nis the leading term. For each pair of binomials corresponding to a  \nminimal syzygy of $M$, form their $S$-pair and then reduce it to a \nnormal form with respect to the $13$ binomials above.\nFor instance,\n$$\nS \\bigl(\n c^5 - z_{10} a b^3 d , \n c e^5 - z_{11} d^6 \\bigr)\n\\, = \\,\n z_{11} c^4 d^6  - z_{10} a b^3 d e^5\n\\, \\longrightarrow \\,\nb^4 d^2 e^4 \\cdot (z_2^4 z_{11} - z_1 z_{10}).\n$$\nEach such normal form is a monomial in $a,b,c,d,e$ times a binomial in\n$z_1, \\ldots, z_{13}$.  The set of all these binomials, in the\n$z$-variables, generates the ideal $J_M$ of local equations of\n$Hilb_A$ around $M$.  In our example, $J_M$ is generated by $27$\nnonzero binomials.  This computation can be done in \\Mtwo using the\nprocedure {\\tt localCoherentEquations}.\n\n<<<localCoherentEquations = (IA) -> (\n     -- IA is the toric ideal of A living in a ring equipped\n     -- with weight order w, if we are computing the local \n     -- equations about the initial ideal of IA w.r.t. w.\n     R := ring IA;\n     w := (monoid R).Options.Weights;\n     M := ideal leadTerm IA;\n     S := first entries ((gens M) % IA);\n     -- Make the universal family J in a new ring.\n     nv := numgens R; n := numgens M;\n     T = (coefficientRing R)[generators R, z_1 .. z_n, \n                             Weights => flatten splice{w, n:0},\n                             MonomialSize=>16];\n     M = substitute(generators M,T);\n     S = apply(S, s -> substitute(s,T));\n     J = ideal apply(n, i -> \n               M_(0,i) - T_(nv + i) * S_i);\n     -- Find the ideal Ihilb of local equations about M:\n     spairs := (gens J) * (syz M);\n     g := forceGB gens J;\n     B = (coefficientRing R)[z_1 .. z_n,MonomialSize=>16];\n     Fones := map(B,T, matrix(B,{splice {nv:1}}) | vars B);\n     Ihilb := ideal Fones (spairs % g);\n     Ihilb\n     );>>> \n     \nSuppose we wish to calculate the local equations about $M =\nin_w(I_A)$.  The input to {\\tt localCoherentEquations} is the\ntoric ideal $I_A$ living in a polynomial ring equipped with the \nweight order specified by $w$. This is done as follows:\n\n<<<IA = toricIdeal A;>>>\n<<<Y = QQ[a..e, MonomialSize => 16,\n            Degrees => transpose A, Weights => {9,3,5,0,0}];>>>\n<<<IA = substitute(IA,Y);>>>\n\nThe initial ideal $M$ is calculated in the third line of the\nalgorithm, and {\\tt S} stores the standard monomials of $M$ of the\nsame degrees as the minimal generators of $M$. We could have\ncalculated {\\tt S} using our old procedure {\\tt stdMonomials} but this\ninvolves computing the monomials in $R_b$ for various values of $b$,\nwhich can be slow on large examples. As by-products, {\\tt\n  localCoherentEquations} also gets {\\tt J}, the ideal of the\nuniversal family for $Hilb_A$ about $M$, the ring {\\tt T} of this\nideal, and the ring {\\tt B} of {\\tt Ihilb}, which is the ideal of the\naffine patch of $Hilb_A$ about $M$. The matrix {\\tt spairs} contains\nall the $S$-pairs between generators of {\\tt J} corresponding to the\nminimal first syzygies of $M$. The command {\\tt forceGB} is used to\ndeclare the generators of {\\tt J} to be a Gr\\\"obner basis, and {\\tt\n  Fones} is the ring map from {\\tt T} to {\\tt B} that sends each of\n$a,b,c,d,e$ to one and the $z$ variables to themselves.  The columns\nof the matrix {\\tt (spairs \\% g)} are the normal forms of the\npolynomials in {\\tt spairs} with respect to the forced Gr\\\"obner basis\n{\\tt g} and the ideal {\\tt Ihilb} of local equations is generated by\nthe image of these normal forms in the ring {\\tt B} under the map {\\tt\n  Fones}.\n\n<<<JM = localCoherentEquations(IA)>>>\n\nRemoving duplications among the generators:\n\n\\smallskip\n$J_M = \\langle\nz_1-z_{10}z_{11},\nz_2-z_4z_7,\nz_2-z_5z_8,\nz_2-z_{11}z_{12},\nz_2-z_1z_{11}z_{13},\\\\\nz_3-z_1z_2,\nz_3-z_5z_9,\nz_4-z_1z_5,\nz_6-z_3z_5,\nz_6-z_1z_2z_5,\nz_7-z_1z_{10},\nz_8-z_1z_7,\\\\\nz_9-z_1z_8,\nz_{12}-z_1z_{13},\nz_1z_2-z_5z_9,\nz_1z_2-z_1z_5z_8,\nz_1z_2-z_1^2z_4z_{10},\nz_1z_2-z_1^2z_5z_7,\\\\\nz_1z_2-z_1z_{11}z_{12},\nz_1z_2-z_2z_{10}z_{11},\nz_1^3z_4-z_3z_{11},\nz_1z_5z_8-z_4z_8,\nz_2z_{10}-z_1z_{12},\\\\\nz_3z_4-z_1z_6,\nz_3z_7-z_2z_8,\nz_3z_8-z_2z_9,\nz_3z_{10}-z_2z_7\n\\rangle$.\n\\smallskip\n\nNotice that there are many generators of $J_M$ that have a single\nvariable as one of its terms. Using these generators we can remove\nvariables from other binomials. This is done in \\Mtwo using the\nsubroutine {\\tt removeRedundantVariables}, which is the main ingredient\nof the package {\\tt minPres.m2} for computing the minimal\npresentations of polynomial quotient rings. Both {\\tt\n  removeRedundantVariables} and {\\tt minPres.m2} are explained in\nAppendix \\ref{Mpor}. The command {\\tt removeRedundantVariables} applied to an\nideal in a polynomial ring (not quotient ring) creates a ring map from\nthe ring to itself that sends the redundant variables to polynomials \nin the non-redundant variables and the non-redundant variables to \nthemselves. Applying this to our ideal $J_M$ we obtain the following \nsimplifications.\n\n<<<load \"minPres.m2\";>>>\n<<<G = removeRedundantVariables JM>>>\n<<<ideal gens gb(G JM)>>>\n\nThus our affine patch of $Hilb_A$ has the coordinate ring \n$$\\k[z_1,z_2,\\ldots,z_{13}]/J_M \\,\\, \\simeq \\,\\,\n\\frac{\\k[z_5,z_{10},z_{11},z_{13}]}{ \\langle z_5 z_{{10}}^3 z_{11}^2 -\n  z_{10}z_{11}^2 z_{13} \\rangle} = \\frac{\\k[z_5,z_{10},z_{11},z_{13}]}\n{\\langle (z_5 z_{10}^2 -z_{13}) z_{10}z_{11}^2 \\rangle}.$$\nHence, we see immediately that there are three\ncomponents through the point $M$ on $Hilb_A$. The restriction of the\ncoherent component to the affine neighborhood of $M$ on $Hilb_A$ is\ndefined by the ideal quotient $\\, (J_M : (z_1 z_2 \\cdots\nz_{13})^\\infty) $ and hence the first of the above components \nis an affine patch of the coherent component. Locally near $M$ it is  \ngiven by the single equation $z_5 z_{10}^2 - z_{13} = 0$ in $\\A^4$. \nIt is smooth and, as expected, has dimension three. The second\ncomponent, $z_{10} = 0$, is also of dimension three and is smooth at $M$.\nThe third component, given by $z_{11}^2 = 0$ is more interesting.  It\nhas dimension three as well, but is not reduced.  Thus we have proved\nthe following result.\n\n\\begin{proposition}\nThe toric Hilbert scheme $Hilb_A$ of the matrix \n$$A = \\left( \\begin{matrix}\n           1 & 1 & 1 & 1 & 1  \\\\ \n           0 & 1 & 2 & 7 & 8 \n\\end{matrix} \\right)$$\nis not reduced.\n\\end{proposition}\n\nWe can use the ring map {\\tt G} from above to simplify {\\tt J} so as\nto involve only the four variables $z_5, z_{10},z_{11}$ and $z_{13}$.\n\n<<<CX = QQ[a..e, z_5,z_10,z_11,z_13, Weights =>\n      {9,3,5,0,0,0,0,0,0}];>>> \n<<<F = map(CX, ring J, matrix{{a,b,c,d,e}} | \n            substitute(G.matrix,CX))>>>\nApplying this map to {\\tt J} we get the ideal {\\tt J1}, \n<<<J1 = F J>>>\n\n\\noindent and adding the ideal $\\langle z_{11}^2 \\rangle$ to {\\tt J1} \nwe obtain the universal family for the non-reduced component of\n$Hilb_A$ about $M$. \n\n<<<substitute(ideal(z_11^2),CX) + J1>>>\n\nIn the rest of this section, we present an interpretation of\nthe ideal $J_M$ in terms of the combinatorial theory\nof {\\it \\ie{integer programming}}. See, for instance, \n\\cite[\\S 4]{HS:St2} or \\cite{HS:Tho} for \nthe relevant background. Our reduced Gr\\\"obner basis \n(\\ref{GrobnerBasis}) is the {\\it \\ie{minimal test set}} for\nthe family of integer programs\n\\begin{equation}\n\\label{IP}\n{\\rm Minimize} \\quad\nw \\cdot u \\,\\,\\quad\n{\\rm subject} \\,\\, {\\rm to } \\,\\,\\,\nA \\cdot u = b   \\,\\,\\, {\\rm and}\n \\,\\,\\,u \\in \\N^n, \n\\end{equation}\nwhere $A \\in \\N^{d \\times n}$ and $w\n\\in \\ZZ^n$ are fixed and $b$ ranges over $\\N^d$.\nIf $u' \\in \\N^n$ is any feasible solution\nto (\\ref{IP}), then the corresponding optimal solution\n$u \\in \\N^n$ is computed as follows: the monomial\n$x^u $ is the unique normal form of $x^{u'}$ modulo\nthe Gr\\\"obner basis (\\ref{GrobnerBasis}).\n\nSuppose we had reduced $x^{u'}$\nmodulo the binomials (\\ref{FlatFamily}) instead of (\\ref{GrobnerBasis}).\nThen the output has a $z$-factor that depends on \nour choice of reduction path. To be precise, suppose the\nreduction path has length $m$ and at the $j$-th step we had used the\nreduction $\\, x^{u_{\\mu_j}} \\rightarrow  z_{\\mu_j} \\cdot x^{v_{\\mu_j}}\n$. Then we would obtain the normal form\n$$ \\, z_{\\mu_1} z_{\\mu_2} z_{\\mu_3} \\cdots z_{\\mu_m} \\cdot x^u.$$\nReduction paths can have different lengths. If we take\nanother  path  that\nhas length $m'$ and  uses\n$\\, x^{u_{\\nu_j}} \\rightarrow  z_{\\nu_j} \\cdot x^{v_{\\nu_j}} \\,$\nat the $j$-th step, then the output would be\n$$ \\, z_{\\nu_1} z_{\\nu_2} z_{\\nu_3} \\cdots z_{\\nu_{m'}} \\cdot x^u  .$$\n\n\\begin{theorem} \\label{paths}\nThe ideal $J_M$ of local equations\non $Hilb_A$ is generated by the binomials\n$$ \\, z_{\\mu_1} z_{\\mu_2} z_{\\mu_3} \\cdots z_{\\mu_m} - \nz_{\\nu_1} z_{\\nu_2} z_{\\nu_3} \\cdots z_{\\nu_{m'}} $$ each encoding a\npair of distinct reduction sequences from a feasible solution of an\ninteger program of the type (\\ref{IP}) to the corresponding optimal\nsolution using the minimal test set in (\\ref{GrobnerBasis}).\n\\end{theorem}\n\n\\begin{proof}\nThe given ideal is contained in $J_M$ because its generators\nare differences of monomials arising from the possible\nreduction paths of $\\,{lcm(x^{u_i},x^{u_j})} $,\nfor $1 \\leq i,j \\leq r $. Conversely, any reduction\nsequence can be transformed into an equivalent reduction sequence\nusing S-pair reductions. This follows from standard\narguments in the proof of Buchberger's criterion\n\\cite[\\S 2.6, Theorem 6]{HS:CLO}, and it implies that\nthe binomials  $ \\, z_{\\mu_1}  \\cdots z_{\\mu_m} -\n z_{\\nu_1}  \\cdots z_{\\nu_{m'}}  \\,$ are $\\k[z]$-linear\ncombinations of the generators of $J_M$.\n\\qed\n\\end{proof}\n\nA given feasible solution of an integer program (\\ref{IP})\nusually has many different reduction paths to the optimal solution\nusing  the reduced Gr\\\"obner basis (\\ref{GrobnerBasis}). \nFor our matrix \\ref{OurMatrix} and cost vector \n$w = (9,3,5,0,0)$, the monomial\n$\\, a^2 b d e^6 \\,$  encodes the feasible solution $(2,1,0,1,6)$\nof the integer program \n$$ {\\rm Minimize} \\quad\nw \\cdot u \\,\\,\\quad\n{\\rm subject} \\,\\, {\\rm to } \\,\\,\\,\nA \\cdot u = \\binom{10}{56}   \\,\\,\\, {\\rm and}\n \\,\\,\\,u \\in \\N^5.$$\nThere are $19$ different paths from this feasible solution \nto the optimal solution $(0,3,0,3,4)$ encoded by the monomial \n$\\, b^3 d^3 e^4 $. The generating function for these paths is:\n\\begin{eqnarray*}\n& z_1^2 + 3 z_1 z_2^2 z_5 z_7 + 2 z_1 z_2 z_5 z_7^2 z_{12}\n + 2 z_1 z_2 z_5 z_8 \\\\ & {} + 2 z_1 z_2 z_{12} z_{13} + z_1 z_5 z_9 \n + z_2^3 z_4 z_5 z_7^2 + z_2^3 z_4 z_{13} + z_2^3 z_5 z_{11} \\\\ & {} \n + 2 z_2 z_3 z_5 z_7 + z_3 z_5 z_7^2 z_{12} + z_3 z_5 z_8 + z_3 z_{12} z_{13}.\n\\end{eqnarray*}\nThe difference of any two monomials in this generating function \nis a valid local equation for the toric Hilbert scheme of\n(\\ref{OurMatrix}). For instance, the binomial \n$\\,  z_3 z_5 z_7^2 z_{12} - z_3 z_{12} z_{13} \\,$ lies in $J_M$,\nand, conversely, $J_M$ is generated by binomials obtained in this manner.\n\nThe scheme structure of $J_M$ encodes obstructions to making certain\nreductions when solving our family of integer programs. For instance,\nthe variable $z_3$ is a zero-divisor modulo $J_M$. If we factor it\nout from the binomial $\\,  z_3 z_5 z_7^2 z_{12} - z_3 z_{12} z_{13}\n\\in J_M \\,$, we get \n$\\, z_5 z_7^2 z_{12} - z_{12} z_{13} \\,$,\nwhich does not lie in $J_M$. Thus there is no monomial\n$a^{i_1} b^{i_2} c^{i_3} d^{i_4} e^{i_5} \\,$\nfor which both the paths $ z_5 z_7^2 z_{12} $ and\n$ z_{12} z_{13} $ are used to reach the optimum.\nIt would be a worthwhile combinatorial project to\nstudy the path generating functions and their relation\nto the ideal $J_M$ in more detail.\n\nIt is instructive to note that the binomials\n$ \\, z_{\\mu_1} z_{\\mu_2} \\cdots z_{\\mu_m} \\, - \\,\n z_{\\nu_1} z_{\\nu_2}  \\cdots z_{\\nu_{m'}}  $\nin Theorem~\\ref{paths} do not form a vector space basis\nfor the ideal $J_M$. We demonstrate this for the lexicographic\nGr\\\"obner basis (with $a \\succ b \\succ c \\succ d \\succ e$) of \nthe toric ideal defining the rational normal curve of degree $4$. \nIn this case, we can take $A = \\left ( \\begin{array}{ccccc}\n1 & 1 & 1 & 1 & 1 \\\\ 0 & 1 & 2 & 3 & 4 \\end{array} \\right )$ and the \nuniversal family in question is :\n$$ \n\\bigl\\{\na c    - z_1 b^2, \\,\na d    - z_2 b c,\\,\na e    - z_3 c^2,\\,\nb d    - z_4 c^2,\\,\nb e    - z_5 c d,\\,\nc e    - z_6 d^2\n\\bigr\\}.\n$$ \nThe corresponding ideal of local equations is\n$J_M = \n\\langle z_3 - z_2  z_5, z_2 - z_1  z_4, z_5  - z_4 z_6 \\rangle $,\nfrom which we see that $M$ is a smooth point of $Hilb_A$.\nThe binomial $\\,z_1 z_5 - z_1 z_4 z_6 \\,$ lies in $J_M$\nbut there is no monomial that has the reduction path $z_1 z_5$\nor $z_5 z_1 $ to optimality.  Indeed, any monomial\nthat admits the reductions $z_1 z_5$ or $z_5 z_1$ must be\ndivisible by either $\\, a c e \\, $ or $\\, a b e  $.\nThe path generating functions for these two monomials are\n$$ abe \\quad \\rightarrow \\quad\n(z_3 \\, + \\, z_1 z_4 z_5 \\, +\\, z_2 z_5) \\cdot b c^2 $$\n$$ ace \\quad \\rightarrow \\quad\n(z_3 \\,+ \\,z_1 z_4 z_5 \\,+\\,\nz_2 z_4 z_6) \\cdot c^3 . $$\nThus every reduction to optimality using $z_1$ and $z_5$ must\nalso use $z_4$, and we conclude that $\\,z_1 z_5 - z_1 z_4 z_6 \\,$\nis not in the $\\k$-span of the binomials listed in\nTheorem~\\ref{paths}.\n\n\\section{The Coherent Component of the Toric Hilbert Scheme}\n\nIn this section we study the component of the toric Hilbert scheme\n$Hilb_A$ that contains the point corresponding to the toric ideal\n$I_A$. An $A$-graded ideal is\ncoherent if and only if it is isomorphic to an initial ideal of $I_A$\nunder the action of the torus $(\\k^\\ast)^n$. All coherent $A$-graded\nideals lie on the same component of $Hilb_A$ as $I_A$.\nWe will show that this component need not be\nnormal, and we will describe how its local and global equations can be\ncomputed using \\Mtwo.  Every term order for the toric ideal $I_A$ can\nbe realized by a weight vector that is an element in the lattice $\\,N\n= Hom_\\ZZ( ker_\\ZZ(A) , \\ZZ) \\, \\simeq \\, \\ZZ^{n-d}$.  Two weight\nvectors $w$ and $w'$ in $N$ are considered {\\it equivalent}\\index{weight vectors!equivalent} if they\ndefine the same initial ideal $\\,in_w(I_A) = in_{w'}(I_A)$.  These\nequivalence classes are the relatively open cones of a projective fan\n$\\Sigma_A$ called the {\\em Gr\\\"obner fan\\index{Grobner fan@Gr\\\"obner fan}} of $I_A$  \n\\cite{HS:MR}, \\cite{HS:ST}. This fan lies in \n$\\mathbb R^{n-d}$, the real vector space spanned by the lattice $N$.\n\n\\begin{theorem}\nThe toric ideal $I_A$ lies on a unique irreducible component of\nthe toric Hilbert scheme $Hilb_A$, called the coherent component.\nThe normalization of the coherent\ncomponent is the projective toric variety defined by \nthe Gr\\\"obner fan of $I_A$.\n\\end{theorem}\n\n\\begin{proof}\nThe {\\it \\ie{divisor at infinity}} on the toric Hilbert scheme $Hilb_A$ \nconsists of all points at which at least one of the local coordinates\n(around some monomial $A$-graded ideal) is zero.  This is a proper\nclosed codimension one subscheme of $Hilb_A$, parametrizing\nall those $A$-graded ideals that contain at least one monomial.  \nThe complement of the divisor at infinity in \n$Hilb_A$ consists of precisely  the orbit of $I_A$ \nunder the action of the torus $(\\k^*)^n $.\nThis is the content of \\cite[Lemma 10.12]{HS:St2}.\n\nThe closure of the $(\\k^*)^n $-orbit of $I_A$ is a\nreduced and irreducible component of  $Hilb_A$.\nIt is reduced because $I_A$ is a smooth point on $Hilb_A$,\nas can be seen from the local equations, and it is irreducible\nsince $(\\k^*)^n$ is a connected group. It is a component\nof $Hilb_A$ because its complement lies in a divisor.\nWe call this irreducible component the\n{\\it \\ie{coherent component}} of $Hilb_A$.\n\nIdentifying $(\\k^*)^n$ with $Hom_\\ZZ(\\ZZ^n, \\k^*)$, we note\nthat the stabilizer of $I_A$ consists of those linear forms\n$w$ that restrict to zero on the kernel of $A$. Therefore\nthe coherent component is the closure in $Hilb_A$\nof the  orbit of the point $I_A$ under the action of the torus\n$\\, N \\otimes \\k^* \\, = \\,Hom_\\ZZ( ker_\\ZZ(A), \\k^*)$.\nThe $(N \\otimes \\k^*)$-fixed points\non this component are precisely the coherent monomial \n$A$-graded ideals, and the same holds for the\ntoric variety of the Gr\\\"obner fan. \n\nFix a maximal cone $\\sigma$ in the Gr\\\"obner fan $\\Sigma_A$,\nand let $M = \\langle x^{u_1}, \\ldots, x^{u_r} \\rangle$ \nbe the corresponding (monomial) \ninitial ideal of $I_A$.  As before we write\n$$ \\left \\{ x^{u_1} -  z_1 \\cdot x^{v_1} \\,, \\,\\,\n x^{u_2} - z_2  \\cdot x^{v_2} \\,,\\, \\, \\ldots \\, ,\n\\,\\, x^{u_r} -   z_r \\cdot x^{v_r} \\right \\}$$\nfor the universal family arising from the corresponding\nreduced Gr\\\"obner basis of $I_A$.  Let $J_M$ be the\nideal in $\\k [z_1,z_2,\\ldots,z_r]$ defining this family.\n\nThe restriction of the coherent component to the \naffine neighborhood of $M$ on $Hilb_A$ is defined\nby $\\, J_M :  (z_1 z_2 \\cdots z_r)^\\infty $.\nIt then follows from our combinatorial description of\nthe ideal $J_M$ that this ideal quotient is a binomial prime ideal.\nIn fact, it is the ideal of algebraic relations among the \nLaurent monomials $\\, x^{u_1- v_1}, \\ldots, x^{u_r-v_r}$.\nWe conclude that the restriction of the coherent component to the\naffine neighborhood of $M$ on $Hilb_A$ equals\n\\begin{equation}\n\\label{uv-algebra}\n {\\rm Spec} \\,\\, \\k \\bigl[\n x^{u_1-v_1},\n x^{u_2-v_2},  \\ldots,\n x^{u_r-v_r} \n\\bigr] .\n\\end{equation}\n\nThe abelian group generated by the vectors\n$\\, u_1-v_1, \\ldots, u_r-v_r \\,$  equals\n$\\ker_\\ZZ(A) = Hom_\\ZZ(N,\\ZZ)$. This follows from \n\\cite[Lemma 12.2]{HS:St1} because the\nbinomials $x^{u_i} - x^{v_i}$ generate the toric ideal $I_A$.\nThe cone generated by the vectors $\\, u_1-v_1, \\ldots, u_r-v_r \\,$  is\nprecisely the polar dual $\\sigma^\\vee$ to\nthe Gr\\\"obner cone $\\sigma$. This follows from\n equation (2.6) in \\cite{HS:St1}. We conclude that the\nnormalization of the affine variety\n(\\ref{uv-algebra}) is the normal affine toric variety\n\\begin{equation}\n\\label{normal-uv-algebra}\n {\\rm Spec} \\,\\, \\k \\bigl[\n \\ker_\\ZZ(A) \\,\\cap\\, \\sigma^\\vee \\bigr] .\n\\end{equation}\n\nThe normalization morphism from (\\ref{normal-uv-algebra}) to\n(\\ref{uv-algebra}) maps the identity point in the  toric variety\n (\\ref{normal-uv-algebra}) \nto the point $I_A$ in the affine chart \n(\\ref{uv-algebra}) of the toric Hilbert \nscheme $Hilb_A$. \nClearly, this normalization morphism is equivariant with respect to the\naction by the torus $\\, N \\otimes \\k^* $.\nThese two properties  hold for every maximal cone $\\sigma$ of the \nGr\\\"obner fan $\\Sigma_A$. Hence there exists a unique \n$\\, N \\otimes \\k^* $-equivariant morphism $\\phi$\nfrom the projective toric variety associated with $\\Sigma_A$\nonto the coherent component of $Hilb_A$, such that $\\phi$ maps \nthe identity point to the point $I_A$ on $Hilb_A$, and \n$\\phi$ restricts to the normalization\nmorphism (\\ref{normal-uv-algebra}) $\\rightarrow$ (\\ref{uv-algebra}) on each\naffine open chart. We conclude that $\\phi$\nis the desired normalization map from the\nprojective toric variety associated with the Gr\\\"obner fan of $I_A$ \nonto the coherent component of the toric Hilbert scheme $Hilb_A$.\n\\qed\n\\end{proof}\n\nWe now present an example that shows that the coherent component \nof $Hilb_A$ need not be normal. This example is \nderived from the matrix that appears in Example 3.15 of \\cite{HS:HM}.\nThis example is also mentioned in \\cite{HS:PS1} without details.\nLet $d=4$ and $n=7$ and fix the matrix\n\n\\begin{equation}\n\\label{non-normal}\nA = \\left( \\begin{array}{ccccccc}  \n1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\n0 & 6 & 7 & 5 & 8 & 4 & 3 \\\\\n3 & 7 & 2 & 0 & 7 & 6 & 1 \\\\\n6 & 5 & 2 & 6 & 5 & 0 & 0 \\end{array} \\right).\n\\end{equation}\n\nThe lattice $\\,N =  Hom_\\ZZ ( ker_\\ZZ(A), \\ZZ)$\nis three-dimensional. The toric ideal $I_A$ is minimally \ngenerated by $30$ binomials of total degree between $6$ and $93$.\n\n<<<A = {{1,1,1,1,1,1,1},{0,6,7,5,8,4,3},{3,7,2,0,7,6,1},\n   {6,5,2,6,5,0,0}};>>>\n<<<IA = toricIdeal A>>>\n\nWe fix the weight vector $w = (0,0,276,220,0,0,215)$ in $N$ and \ncompute the initial ideal $M = in_w(I_A)$. This initial ideal \nhas $44$ minimal generators.\n\n<<<Y = QQ[a..g, MonomialSize => 16,\n           Weights => {0,0,276,220,0,0,215},\n           Degrees =>transpose A];>>>\n<<<IA = substitute(IA,Y);>>>\n<<<M = ideal leadTerm IA>>>\n\n\\begin{proposition} The three dimensional affine variety\n  (\\ref{uv-algebra}), for the initial ideal $M$ with respect to $w =\n  (0,0,276,220,0,0,215)$ of the toric ideal of $A$ in\n  (\\ref{non-normal}), is not normal.\n\\end{proposition} \n\n\\begin{proof}\nThe universal family for the toric Hilbert scheme $Hilb_A$ at $M$ is:\n\\begin{eqnarray*}\n\\{& a^2e^{15}g^{18}-z_1b^3c^6d^{10}f^{16}, \\,\\,\nb^{13}d^{15}f^{16}-z_2a^8ce^{21}g^{14}, \\\\ &\nc^{59} d^{57} f^{110} - z_3  e^{92} g^{134},\na c^{14} d^{11} f^{23} - z_4  b e^{19} g^{29}, \\\\ &\nb^7 c^2 g^4 - z_5  d^4 e^3 f^6, \\,\\,\n\\ldots, \\,\\,\nb c^{34} d^{32} f^{62} - z_{44}  e^{53} g^{76} \\}.\n\\end{eqnarray*}\nThe semigroup algebra in (\\ref{uv-algebra})\nis generated by $44$ Laurent  monomials \ngotten from this family. It turns out that the\nfirst four monomials suffice to generate the semigroup.\nIn other words, for all $j \\in \\{5,6,\\ldots,44\\}$\nthere exist\n$ i_1,i_2,i_3, i_4 \\in \\N $ such that\n$\\,\nz_{j} - \nz_1^{i_1}\nz_2^{i_2}\nz_3^{i_3}\nz_4^{i_4} \\in  J_M : (z_1 \\cdots z_{44})^\\infty $.\nHence the semigroup algebra in (\\ref{uv-algebra}) is:\n$$ \\k \\bigl[\n \\frac{a^2 e^{15} g^{18}}{ b^3 c^6 d^{10} f^{16}}, \n \\frac{ b^{13} d^{15} f^{16} }{a^8 c e^{21} g^{14}},\n \\frac{ c^{59} d^{57} f^{110}} {e^{92} g^{134}}, \n \\frac{ a c^{14} d^{11} f^{23}} {b e^{19} g^{29}}\n\\bigr] \\,\\,\\, \\simeq \\,\\,\\,\n\\frac{\\k[z_1,z_2,z_3,z_4]}{\\langle z_1^5  z_2 z_3 - z_4^2 \\rangle}.\n$$\nThis algebra is not integrally closed, since\na toric hypersurface is normal if and only if\nat least one of the two monomials in the defining equation \nis square-free. Its integral closure \nin $\\k[ ker_\\ZZ(A) ]$ is generated by the\nLaurent monomial\n\\begin{equation}\n\\label{witness}\n\\frac{z_4}{z_1^2} \\,\\, = \\,\\, \n( z_1 z_2 z_3)^{\\frac{1}{2}}  \\,\\, = \\,\\, \n\\frac{ b^5 c^{26} d^{31} f^{55}}{a^3 e^{49} g^{65}}.\n\\end{equation}\nHence the affine chart (\\ref{normal-uv-algebra}) of the toric variety\nof the Gr\\\"obner fan of $I_A$ is the spectrum of the normal domain\n$  \\k[z_1,z_2,z_3,y]/ \\langle\nz_1  z_2 z_3 - y^2 \\rangle$, \nwhere $y$ maps to (\\ref{witness}).\n\\qed\n\\end{proof}\n\nWe now examine the local equations of $Hilb_A$ about $M$ for this \nexample.\n<<<JM = localCoherentEquations(IA)>>>\n<<<G = removeRedundantVariables JM;>>>\n<<<toString ideal gens gb(G JM)>>>\n\nThis ideal has six generators and decomposing it \n%%% $\\langle z_32z_42^2z_44-z_37^2z_42,\n%%% z_32^3z_35z_37^2-z_42^2z_44,\n%%% z_32^4z_35z_37-z_37z_42,\n%%% z_32^2z_35z_37^4z_42-z_42^4z_44^2,\n%%% z_32z_35z_37^6z_42-z_42^5z_44^3,\n%%% z_35z_37^8z_42-z_42^6z_44^4 \\rangle$\nwe see that there are five components \nthrough the monomial ideal $M$ on this toric Hilbert scheme. They \nare defined by the ideals: \n\\begin{itemize}\n\\item $\\langle z_{32}z_{42}z_{44}-z_{37}^2,z_{32}^4z_{35}-z_{42},\nz_{32}^3z_{35}z_{37}^2-z_{42}^2z_{44},\nz_{32}^2z_{35}z_{37}^4-z_{42}^3z_{44}^2,\\\\\n\\indent \\indent z_{32}z_{35}z_{37}^6-z_{42}^4z_{44}^3,\nz_{35}z_{37}^8-z_{42}^5z_{44}^4 \\rangle$ \n\\item $\\langle z_{44},z_{37} \\rangle$\n\\item $\\langle z_{37},z_{42}^2 \\rangle$\n\\item $\\langle z_{42},z_{35} \\rangle$ \n\\item $\\langle z_{42},z_{32}^3 \\rangle$.\n\\end{itemize}\nAll five components are three\ndimensional. The first component is an affine patch of the coherent\ncomponent and two of the components are not reduced. Let $K$ be the \nfirst of these ideals.\n\n<<<K = ideal(z_32*z_42*z_44-z_37^2,z_32^4*z_35-z_42,\n    z_32^3*z_35*z_37^2-z_42^2*z_44,z_32^2*z_35*z_37^4-z_42^3*z_44^2,\n    z_32*z_35*z_37^6-z_42^4*z_44^3,z_35*z_37^8-z_42^5*z_44^4);>>>\n\nApplying {\\tt removeRedundantVariables} to $K$ we see that \nthe affine patch of the coherent component is, locally at $M$,\na non-normal hypersurface singularity (agreeing with (\\ref{witness})).\nThe labels on the variables depend on the order of elements in \nthe initial ideal $M$ computed by \\Mtwo in line {\\tt i61}.\n\n<<<GG = removeRedundantVariables K;>>>\n<<<ideal gens gb (GG K)>>>\n\nThere is a general algorithm due to de Jong \\cite{HS:DJ} for \ncomputing the \\ie{normalization} of any affine variety. \nIn the toric case, the problem of normalization amounts to  \ncomputing the minimal {\\em \\ie{Hilbert basis}} of a given convex\nrational polyhedral cone \\cite{HS:Sch}. An efficient implementation can be \nfound in the software package {\\tt Normaliz}\\indexcmd{Normaliz} by Bruns and\nKoch \\cite{HS:BK}.\n\nOur computational study of the toric Hilbert scheme in this\nchapter was based on local equations rather than\nglobal equations (arising from a projective embedding of  $Hilb_A$),\nbecause the latter system of equations tends to be too large \nfor most purposes. Nonetheless, they are interesting.\nIn the remainder of this section, we present a canonical \nprojective embedding of the coherent component of $Hilb_A$.\n\nLet $G_1, G_2, G_3, \\ldots, G_s$ denote all the {\\it Graver fibers} of\nthe matrix $A$. In Section 1 we showed how to compute them in \n{\\sl Macaulay 2}. Each\nset $G_i$ consists of the monomials in $\\k[x_1,\\ldots,x_n]$ \nthat have a fixed Graver degree.  Consider the set $\\, {\\mathbf G} \\,\n:= \\, G_1 G_2 G_3 \\cdots G_s \\,$ that consists of all monomials that\nare products of monomials, one from each of the distinct Graver\nfibers. Let $t$ denote the cardinality of ${\\mathbf G}$.  We introduce\nan extra indeterminate $z$, and we consider the $\\N$-graded semigroup\nalgebra $\\,\\k[z {\\mathbf G}] $, which is a subalgebra of\n$\\k[x_1,\\ldots,x_n,z]$. The grading of this algebra is $\\,deg(z) = 1\\,$ and\n$\\, deg(x_i) = 0$. Labeling the elements of ${\\mathbf G}$ with\nindeterminates $y_i$, we can write\n$$ \\k[z {\\mathbf G}]   = \n\\k[y_1,y_2,\\ldots,y_t]/P_A, $$\nwhere $P_A$ is a homogeneous toric ideal\nassociated with a configuration of $t$ vectors in $\\ZZ^{n+1}$.\nWe note that the torus $(\\k^*)^n$ acts naturally on \n$\\, \\k[z {\\mathbf G}]$.\n\n\\begin{example} \\rm\nLet $n=4,d=2$ and \n $\\, A \\, = \\, \\left( \\begin{array}{cccc}\n3 & 2 & 1 & 0 \\\\\n0 & 1 & 2 & 3 \n \\end{array} \\right) $,\nso that $I_A$ is the ideal of the twisted cubic curve.\nThere are five Graver fibers:\n\n<<<A = {{1,1,1,1},{0,1,2,3}};>>>\n<<<I = toricIdeal A;>>>\n<<<Graver = graver I;>>>\n<<<fibers = graverFibers Graver;>>>\n<<<peek fibers>>>\n\nThe set ${\\mathbf G} = G_1 G_2 G_3 G_4 G_5 \\,$ consists of\n$22$ monomials of degree $14$.\n\n<<<G = trim product(values fibers, ideal)>>>\n<<<numgens G>>>\n\nWe introduce a polynomial ring in $22$ variables\n$y_1,y_2,\\ldots,y_{22}$, and we compute the ideal $P_A$.\nIt is generated by $180$ binomial quadrics. \n\n<<<z = symbol z;>>>\n<<<S = QQ[a,b,c,d,z];>>>\n<<<zG = z ** substitute(gens G, S);>>>\n<<<R = QQ[y_1 .. y_22];>>>\n<<<F = map(S,R,zG)>>>\n<<<PA = trim ker F>>>\n\nThese equations define a toric surface\nof degree $30$ in projective $21$-space.\n<<<codim PA>>>\n<<<degree PA>>>\n\nThe surface is smooth, but there are too many equations and the\ncodimension is too large to use the Jacobian criterion for smoothness\n\\cite[\\S 16.6]{HS:Eis} directly. Instead we check smoothness for each\nopen set $y_i \\neq 0$. \n\n<<<Aff = apply(1..22, v -> (\n                       K = substitute(PA,y_v => 1);\n                       FF = removeRedundantVariables K;\n                       ideal gens gb (FF K)));>>>\n<<<scan(Aff, i -> print toString i);>>>\n\nBy examining these local equations, we see that $Hilb_A$ is smooth, and also\nthat there are eight fixed points under the\naction of the $2$-dimensional torus. They correspond\nto the variables $y_1,y_2,y_3,y_6,y_{11},y_{15},y_{20}$ and $y_{22}$. \nBy setting any of these eight variables to $1$ in the\n$180$ quadrics above, we obtain an affine variety\nisomorphic to the affine plane.\n\\end{example}\n\n\\begin{theorem} \\label{isomorphism}\nThe coherent component of the toric Hilbert scheme $Hilb_A$ is\nisomorphic to the projective spectrum $\\,Proj \\,\\k[z {\\mathbf G}]\\,$\nof the algebra $\\k[z {\\mathbf G}]$.\n\\end{theorem}\n\n\\begin{proof} The first\nstep is to define a morphism from $\\,Hilb_A \\,$ to\nthe $(t-1)$-dimensional projective space\n$\\P({\\mathbf G}) = Proj \\, \\k[y_1,y_2,\\ldots,y_t]$.\nConsider any point $I$ on $Hilb_A$. We intersect\nthe ideal $I$ with the finite-dimensional vector space\n$\\k G_i$, consisting of all homogeneous polynomials\nin $\\k[x_1,\\ldots,x_n]$ that lie in the $i$-th  Graver degree.\nThe definition of $A$-graded ideal implies that\n$I \\cap \\k G_i$ is a linear subspace of codimension $1$ in $\\k G_i$.\nWe represent this subspace by an equation\n$\\, g_i(I) = \\sum_{u \\in G_i } c_u x^u \\,$, which is \nunique up to scaling. Taking the product of these\npolynomials for $i=1,\\ldots,t$, we get a unique (up to scaling)\npolynomial that is supported on ${\\mathbf G} = G_1 G_2 \\cdots G_t$.\nThe map $\\, I \\mapsto g_1(I) g_2(I) \\cdots g_t(I)\\,$\ndefines a morphism from $Hilb_A \\,$ to $\\P({\\mathbf G})$.\nThis morphism is equivariant with respect to the  $(\\k^*)^n$-action\non both schemes.\n\nConsider the restriction of this equivariant\n morphism to the coherent component of the toric Hilbert scheme.\nIt maps the $(\\k^*)^n$-orbit of the toric ideal $I_A$\ninto the subvariety $\\,Proj \\,\\k[z {\\mathbf G}]\\,$\nof $\\P({\\mathbf G})$. This inclusion\nis an isomorphism onto the dense torus, \nas the dimension of the Newton polytope of \n$$ g(I_A) = \\prod_{i=1}^t \\,(\\sum_{u \\in G_i }  x^u \\,) $$\nequals the dimension of the kernel of $A$. Equivalently,\nthe stabilizer of $g(I_A)$ in $(\\k^*)^n$ \nconsists only of those one-parameter subgroups\n$w$ that restrict to zero on the kernel of $A$.\n\nTo show that our morphism is an isomorphism between the coherent component\nand  $\\,Proj \\,\\k[z {\\mathbf G}]$,\nwe consider the affine chart around an initial monomial ideal\n$M = in_w(I_A)$. The polynomial $g(M)$ is a monomial,\nnamely, it is the product of all standard monomials whose\ndegree is a  Graver degree. Moreover, $g(M)$ is the leading monomial\nof $g(I_A)$ with respect to the weight vector $w$. The Newton\npolytope of $g(I_A)$ is the Minkowski sum of the Newton polytopes \nof the polynomials $\\,g_1(I_A),   \\ldots, g_t(I_A)$,\nand it is a state polytope for $I_A$, by \\cite[Theorem 7.5]{HS:St2}.\n\nLet $g(M) = x^q$, and let  $\\sigma$  be the cone of the\nGr\\\"obner fan  $\\Sigma_A$ that has $w$ in its interior. \nThen  $\\sigma$ coincides with the normal cone at the vertex $q$ of \nthe state  polytope described above  \\cite[\\S 3]{HS:St2}.\nConsider the restriction of our morphism to the affine chart around $M$\nof the coherent component,  as described in (\\ref{uv-algebra}).\nThis restriction defines an isomorphism onto the variety\n\\begin{equation}\n\\label{other-uv-algebra}\nSpec \\,\\,  \\k[\\, x^{p-q} \\, : \\,x^p \\in {\\mathbf G} \\, ]\n\\end{equation}\nOn the other hand, the semigroup algebra in (\\ref{other-uv-algebra})\nis isomorphic to that in  (\\ref{uv-algebra}) because\neach pair of vectors $\\{u_i, v_i\\}$ seen in the \nreduced Gr\\\"obner basis lies in one of the Graver fibers $G_j$.  \nHence our morphism restricts to an isomorphism from the\naffine chart around $M$ of the coherent component onto (\\ref{other-uv-algebra}).\nFinally, note that (\\ref{other-uv-algebra}) is the principal affine\nopen subset of $\\,Proj \\,\\k[z {\\mathbf G}]\\,$ defined by the\ncoordinate $x^q$. Hence we get an isomorphism between the\ncoherent component of $Hilb_A$ and $\\,Proj \\,\\k[z {\\mathbf G}]$.\n\\qed\n\\end{proof}\n\n\\appendix\n\n\\section{Fourier-Motzkin Elimination}\\index{Fourier-Motzkin elimination}\\label{FMe}\n\nWe now give the \\Mtwo code for converting the generator/inequality\nrepresentation of a rational convex polyhedron to the other. It is\nbased on the Fourier-Motzkin elimination procedure for eliminating a\nvariable from a system of inequalities \\cite {HS:Zie}. This code was\nwritten by Greg Smith.\n\nGiven any cone $C \\subset \\R^d$, the polar cone of $C$ is defined to be\n$$C^{\\vee} = \\{ x \\in \\R^d \\mid x \\cdot y \\leq 0, \\mbox{for all\\ } y\n\\in C\\}.$$\n\n\\noindent For a $d \\times n$ matrix $Z$, define\n$cone(Z) = \\{ Z x \\mid x \\in \\R_{\\geq 0}^n \\} \\subset \\R^d,$ and \n$\\mathit{affine}(Z) = \\{ Z x \\mid x \\in \\R^n \\} \\subset \\R^d.$\nFor two integer matrices $Z$ and $H$, both having  $d$\nrows, {\\tt polarCone(Z,H)} returns a list of two integer matrices\n{\\tt\\char`\\{A,E\\char`\\}} such that $$cone(Z) + \\mathit{affine}(H) = \\{ x \\in \\R^d \\mid A^t\nx \\leq 0, E^t x = 0\\}.$$ \nEquivalently, $(cone(Z) + \\mathit{affine}(H))^\\vee = cone(A) + \\mathit{affine}(E).$\n\nWe now describe each routine in the package {\\tt polarCone.m2}\\indexcmd{polarCone.m2}.  We have\nsimplified the code for readability, sometimes at the cost of efficiency.\nWe start with three simple subroutines: {\\tt primitive}, {\\tt toZZ}, and {\\tt\nrotateMatrix}. \n\n\\medskip\nThe routine {\\tt primitive} takes a list of integers {\\tt L}, and divides\neach element of this list by their greatest common denominator.\n\n<<<code primitive>>>\n\n\\medskip\nThe routine {\\tt toZZ} converts a list of rational numbers to a list of \nintegers, by multiplying by their common denominator.\n<<<code toZZ>>>\n\n\\medskip\nThe routine {\\tt rotateMatrix} is a kind of transpose.  Its input is a\nmatrix, and its output is a matrix of the same shape as the transpose.\nIt places the matrix in the form so that in the routine {\\tt polarCone},\ncomputing a Gr\\\"obner basis will do the Gaussian elimination that is needed.\n<<<code rotateMatrix>>>\n\n\\medskip\nThe procedure of Fourier-Motzkin elimination as presented by \nZiegler in \\cite{HS:Zie} is used, together with some heuristics that he\npresents as exercises.  The following, which is a kind of $S$-pair\ncriterion for inequalities, comes from Exercise 2.15(i) in \\cite{HS:Zie}.\n\nThe routine {\\tt isRedundant} determines if a row vector (inequality)\nis redundant. Its input argument {\\tt V} is the same input that is\nused in {\\tt fourierMotzkin}: it is a list of sets of integers.  Each\nentry contains indices of the original rays that do {\\sl not} vanish\nat the corresponding row vector.  {\\tt vert} is a set of integers; the\noriginal rays for the row vector in question.  A boolean value is\nreturned.  \n\n<<<code isRedundant>>>\n\n\\medskip\nThe main work horse of {\\tt polarCone.m2} is the subroutine \n{\\tt fourierMotzkin}, which eliminates the first variable in the\ninequalities {\\tt A} using the double description version of\nFourier-Motzkin elimination. The set {\\tt A} is a list of lists of\nintegers, each entry corresponding to a row vector in the system of\ninequalities.  The argument {\\tt V} is a list of sets of integers.\nEach entry contains the indices of the original rays that do {\\sl\n  not} vanish at the corresponding row vector in {\\tt A}.  Note that\nthis set is the {\\sl complement} of the set $V_i$ appearing in\nexercise 2.15 in \\cite{HS:Zie}. The argument {\\tt spot} is the integer\nindex of the variable being eliminated.  \n\nThe routine returns a list {\\tt \\char`\\{projA,projV\\char`\\}} where {\\tt projA} is\na list of lists of integers.  Each entry corresponds to a row vector\nin the projected system of inequalities.  The list {\\tt projV} is a\nlist of sets of integers.  Each entry contains indices of the original\nrays that do {\\sl not} vanish at the corresponding row vector in {\\tt\n  projA}. \n\n<<<code fourierMotzkin>>>\n\n\\medskip\nAs mentioned above, {\\tt polarCone} takes two matrices {\\tt Z, H},\nboth having $d$ rows, and outputs a pair of matrices {\\tt A, E} \nsuch that $(\\operatorname{cone}(Z) + \\operatorname{affine}(H))^\\vee =\n\\operatorname{cone}(A) + \\operatorname{affine}(E).$\n\n<<<code(polarCone,Matrix,Matrix)>>>\n\nIf the input matrix $H$ has no columns, it can be omitted.  A sequence of two\nmatrices is returned, as above.\n<<<code(polarCone,Matrix)>>>\n\nAs a simple example, consider the permutahedron in $\\R^3$ \nwhose vertices are the following six points. \n\n<<<H = transpose matrix{\n{1,2,3},\n{1,3,2},\n{2,1,3},\n{2,3,1},\n{3,1,2},\n{3,2,1}};>>>\n\nThe inequality representation of the permutahedron is obtained \nby calling {\\tt polarCone} on $H$: the facet normals of the \npolytope are the columns of the matrix in the first argument of the \noutput. The second argument is trivial since our input is a polytope \nand hence there are is no non-trivial affine space contained in it.\nIf we call {\\tt polarCone} on the output, we will get back H as\nexpected. \n\n<<<P = polarCone H>>>\n<<<Q = polarCone P_0>>> \n\n\\section{Minimal Presentation of Rings}\\label{Mpor}\n\nThroughout this chapter, we have used on several occasions the simple, yet\nuseful subroutine {\\tt removeRedundantVariables}.\nIn this appendix, we present \\Mtwo code for this routine,\nwhich is the main ingredient for finding minimal\npresentations of quotients of polynomial rings.\nOur code for this routine is a somewhat simplified, but less\nefficient version of a routine in the \\Mtwo package, {\\tt minPres.m2}\\indexcmd{minPres.m2},\nwritten by Amelia Taylor.\n\nThe routine {\\tt removeRedundantVariables} takes as input an ideal {\\tt I} in\na polynomial ring {\\tt A}.  It returns a ring map {\\tt F} from {\\tt A} to\nitself that sends redundant variables to polynomials in the non-redundant\nvariables and sends non-redundant variables to themselves.  For example:\n  <<<A = QQ[a..e];>>>\n  <<<I = ideal(a-b^2-1, b-c^2, c-d^2, a^2-e^2)>>>\n  <<<F = removeRedundantVariables I>>>\nThe non-redundant variables are $d$ and $e$.  The image of $I$ under $F$\ngives the elements in this smaller set of variables.  We take the ideal of a \nGr\\\"obner basis of the image:\n  <<<I1 = ideal gens gb(F I)>>>\nThe original ideal can be written in a cleaner way as\n  <<<ideal compress (F.matrix - vars A) + I1>>>\n  \n  Let us now describe the \\Mtwo code.  The subroutine {\\tt\n    findRedundant} takes a polynomial $f$, and finds a variable $x_i$\n  in the ring of $f$ such that $f = c x_i + g$ for a non-zero\n  constant $c$ and a polynomial $g$ that does not involve the\n  variable $x_i$.  If there is no such variable, {\\tt null} is\n  returned.  Otherwise, if $x_i$ is the first such variable , the list\n  $\\{i, c^{-1} g\\}$ is returned.\n\n<<<code findRedundant>>>\n\nThe main function {\\tt removeRedundantVariables} requires an ideal in a\npolynomial ring (not a quotient ring) as input.  The internal\nroutine {\\tt findnext} finds the first entry of the (one row) matrix {\\tt M}\nthat contains a redundancy.  This redundancy is used to modify the list {\\tt\nxmap}, which contains the images of the redundant variables.\nThe matrix {\\tt M}, and the list {\\tt xmap} are both updated, and \nthen we continue to look for more redundancies.\n\n<<<code removeRedundantVariables>>>\n", "meta": {"hexsha": "8cd67a9b05ace48b64b2dde064c62f371fd34521", "size": 77090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/ComputationsBook/chapters/toricHilbertScheme/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/toricHilbertScheme/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/toricHilbertScheme/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": 44.3045977011, "max_line_length": 114, "alphanum_fraction": 0.6821377611, "num_tokens": 25645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6842925520155092}}
{"text": "%% LyX 2.3.4.2 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]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\usepackage{babel}\n\\usepackage{bm}\n\n\\DeclareMathOperator{\\E}{\\mathbb{E}}\n\\DeclareMathOperator{\\Pp}{\\mathbb{P}}\n\n\\begin{document}\n\n\\section{Optimization Problem}\nProblem is\n\\begin{align}\n    \\min_{x \\in X} f_0(x), \\\\\n    f_i(x) \\leq 0,\n\\end{align}\nfor $i = 1, \\dots, m$, where $X \\subseteq \\mathbb{R}^n$ is a box:\n\\begin{equation}\n    \\{x \\mid x_j^{\\text{min}} \\leq x_j \\leq x_j^{\\text{max}}\\}.\n\\end{equation}\n\n\\section{Approximate Problem}\n\nSuppose $k$th iterate is $x^{(k)}$. Then, for $i = 0, \\dots, m$, replace $f_i(x)$ with\n\\begin{equation}\n    g_i(x) = f_i(x_0) + \\nabla f_i(x_0) \\cdot (x - x^{(k)}) + \\frac{\\rho_i^2}{2} \\left|\\frac{x - x^{(k)}}{\\sigma}\\right|^2,\n\\end{equation}\n\nwhere $\\sigma$ and $\\rho$ are vectors. And make a trust region $T$ (actually it's $T \\cup X$)\n\\begin{equation}\n    T = \\{x \\mid |x_j - x_j^{(k)}| \\leq \\sigma_j\\}.\n\\end{equation}\n\nSo that the new problem is\n\\begin{align}\n    \\min_{x \\in T} g_0(x), \\\\\n    g_i(x) \\leq 0.\n\\end{align}\n\n\\section{Overall Scheme}\n\nFor the $k$th iteration:\n\\begin{enumerate}\n    \\item Solve approximate problem to find candidate $x^{(k+1)}$\n    \\item Check conservative: $g_i(x^{(k+1)}) < f_i(x^{(k+1)})$.\n    \\begin{itemize}\n        \\item If no, throw away candidate, double $\\rho_i$ for each non-conservative $g_i$, and solve approximate problem again.\n    \\end{itemize}\n    \\item Halve $\\rho$ (take bigger steps) and update $\\sigma$ (decrease $\\sigma_i$ if $x_i$ oscillating, increase if monotonic i.e. heading somewhere else).\n\\end{enumerate}\n\n\\section{Solving approximate problem}\n\n\\subsection{Evaluating dual function}\nLagrangian relaxation, where $\\lambda_0 = 1$,\n\\begin{align}\n    L(x, \\lambda) &= \\sum_{i=0}^m \\lambda_i g_i(x)\\\\ \n                  &= \\sum_{i=0}^m \\lambda_i f_i(x_0) + \\left(\\sum_{i=0}^m \\lambda_i \\nabla f_i(x_0)\\right) \\cdot (x - x^{(k)}) + \\frac{1}{2} \\left(\\sum_{i=0}^m \\lambda_i \\rho_i\\right) \\left|\\frac{x-x^{(k)}}{\\sigma}\\right|^2 \\\\\n                  &= \\lambda \\cdot f_i(x_0) + \\sum_{j=1}^n h_j(x_j - x_j^{(k)}),\n\\end{align}\nwhere\n\\begin{equation}\n    h_j(\\delta_j) =  \\left(\\lambda \\cdot \\nabla f(x_0)_j  \\right)\\delta_j + \\frac{1}{2\\sigma_j} (\\lambda \\cdot \\rho) \\delta_j^2.\n\\end{equation}\nDefine dual function,\n\\begin{align}\n    g(\\lambda) &= \\min_{x \\in T} L(x, \\lambda) \\\\\n               &= \\lambda \\cdot f_i(x_0) + \\sum_{j=1}^n \\left(\\min_{|\\delta_j| \\leq \\sigma_j}  h_j(\\delta_j)\\right).\n\\end{align}\n%To evaluate, analytically minimize quadratic in $\\delta_j = x_j - x_j^{(k)}$, snapping to bounds. \nDefin for each $j$\n\\begin{align}\n    a_j &= \\frac{1}{2\\sigma_j^2} (\\lambda \\cdot \\rho) \n    \\label{eq:a} \\\\\n    b_j &= \\lambda \\cdot \\nabla f(x_0)_j\n    \\label{eq:b}\n\\end{align}\nNote that we can write\n    \\begin{equation}\n        b = \\nabla f(x_0)^T \\lambda,\n    \\end{equation}\n    where $\\nabla f(x_0)$ is a matrix.\n    We now have,\n\\begin{equation}\n    h_j(\\delta_j) = a_j \\delta_j^2 + b_j \\delta_j.\n\\end{equation}\nThe minimum of $h_j(\\delta_j)$ is found at\n    \\begin{equation}\n        \\delta_j^* = -\\frac{b_j}{2a_j}\\text{ clamped to } [-\\sigma_j, \\sigma_j].\n    \\end{equation}\nAnd hence we can determine \n    \\begin{equation}\n        g(\\lambda) = \\lambda \\cdot f_i(x_0) + \\sum_{j=1}^n \\left(a_j \\delta_j^* + b_j (\\delta_j^*)^2\\right).\n    \\end{equation}\n    Now let us compute the gradient. Note that,\n\\begin{align}\n    \\frac{\\partial a_j}{\\partial \\lambda_i} &= \\frac{\\rho_i}{2\\sigma_j^2}, \\\\\n    \\frac{\\partial b_j}{\\partial \\lambda_i} &= \\nabla f_i(x_0)_j.\n\\end{align}\nIf we snap to bounds, the minimum of $h_j(\\lambda)$ should have gradient 0 (will have a kink, but oh well?). So let $S \\subseteq \\{1,\\dots, m\\}.$ be the indices where don't snap to bounds. Then,\n\\begin{align}\n    \\frac{\\partial g}{\\partial \\lambda_i} &= \\sum_{j \\in S} \\left( -\\frac{b_j}{2 a_j}  \\frac{\\partial b_j}{\\partial \\lambda_i} + \\frac{b_j^2}{4 a_j^2} \\frac{\\partial a_j}{\\partial \\lambda_i}\\right) \\\\\n         &= \\sum_{j \\in S} \\left(-\\frac{b_j}{2a_j} \\nabla f_i(x_0)_j + \\frac{b_j^2}{4a_j^2} \\frac{\\rho_i}{2\\sigma_j^2} \\right). \n    \\label{eq:dg}\n\\end{align}\nAnd thus,\n    \\begin{equation}\n        \\frac{\\partial g}{\\partial \\lambda} = \\nabla f(x_0) v_j + \\rho \\sum_{j \\in S} \\frac{b_j^2}{8a_j^2 \\sigma_j^2}.\n    \\end{equation}\n    where $v_j$ is a vector satisfying\n    \\begin{equation}\n        v_j = \\begin{cases} \n            \\delta_j^* & \\text{if }\\delta_j^* \\in (-\\sigma_j, \\sigma_j), \\\\\n            0 & \\text{otherwise.}\n            \\end{cases}\n    \\end{equation}\n%We should evaluate $a_j$ and $b_j$ for each $j$, taking advantage of sparsity. Note that $\\frac{\\partial b_j}{\\partial y_i}$ is also sparse. But $\\frac{\\partial a_j}{\\partial y_i}$ is not?\n\n%Explicitltly, the first term of Equation (\\ref{eq:dgdy}) has the sparsity pattern of the Jacobian transposed, while the second term is low-rank: $\\frac{1}{2} \\cdot$ the outer product of $\\frac{1}{\\bm{\\sigma}}$ and $\\bm{\\rho}$.\n\n\\subsection{Maximizing dual function}\n\nThe dual problem is,\n\\begin{equation}\n    \\max_{y \\geq 0} g(\\lambda).\n\\end{equation}\nWe can provide $g$ and its gradient function recursively to CCSA, which will solve it for us.\n\n\\section{Main Goals}\n\n\\begin{itemize}\n    \\item Support sparse Jacobians\n    \\item Support affine constraints\n        \\begin{itemize}\n            \\item Does paper handle these? (First, find where paper handles box constraints.)\n            \\item Maybe think of this as a more complicated $X$, rather than a simple $f_i$.\n        \\end{itemize}\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "01107ebc2c0307bc651a9abf5567ffe68765f041", "size": 5720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/ccsa.tex", "max_stars_repo_name": "gaurav-arya/SparseCCSA.jl", "max_stars_repo_head_hexsha": "970da6e415a812f745e3d8d4c65afe7fdee86a4d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-31T01:11:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T01:11:52.000Z", "max_issues_repo_path": "notes/ccsa.tex", "max_issues_repo_name": "gaurav-arya/SparseCCSA.jl", "max_issues_repo_head_hexsha": "970da6e415a812f745e3d8d4c65afe7fdee86a4d", "max_issues_repo_licenses": ["MIT"], "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/ccsa.tex", "max_forks_repo_name": "gaurav-arya/SparseCCSA.jl", "max_forks_repo_head_hexsha": "970da6e415a812f745e3d8d4c65afe7fdee86a4d", "max_forks_repo_licenses": ["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.4482758621, "max_line_length": 227, "alphanum_fraction": 0.6337412587, "num_tokens": 2047, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6842925437923641}}
{"text": "\\chapter{\\abstractname}\n\n%TODO: Abstract\nUnion-Find is a classical data structure whose complexity analysis is famously non-trivial. In this thesis we prove the $\\alpha$-bound amortized time complexity of an efficient imperative implementation of this data structure. We first revise the history of this emblematic result by Tarjan \\cite{Tarjan1975b} and arrive at the modern proof by Alstrup et al. \\cite{Alstrup14}.\n\nTo reproduce this proof in a formal context within Isabelle/HOL, we first gather the mathematical and technical tools required, most prominently a more comprehensive theory about the Ackermann function than the one already available in the Isabelle/HOL distribution, properties about its inverses, as well as the framework implementing Separation Logic with Time Credits for Imperative/HOL, which already contained a non optimal implementation of this data structure. We then follow closely the work of Charguéraud and Pottier \\cite{chargueraud17}, which formalized this proof in a similar framework in Coq.\n\nIn the end, we prove the asymptotically optimal bound of the operations in an efficient implementation of the Union-Find data structure. The whole proof in Isabelle is available under \\cite{Loewenberg2019}. As with any other program in Imperative/HOL, the implementation can be exported to several languages.\n\n", "meta": {"hexsha": "75ec01ba55c714ba52c70e65056934adc5452117", "size": 1338, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tum-thesis-latex-master/pages/abstract.tex", "max_stars_repo_name": "adrilow/Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL", "max_stars_repo_head_hexsha": "293b12752261dac7f741483b62b27891bf4be1cc", "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": "tum-thesis-latex-master/pages/abstract.tex", "max_issues_repo_name": "adrilow/Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL", "max_issues_repo_head_hexsha": "293b12752261dac7f741483b62b27891bf4be1cc", "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": "tum-thesis-latex-master/pages/abstract.tex", "max_forks_repo_name": "adrilow/Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL", "max_forks_repo_head_hexsha": "293b12752261dac7f741483b62b27891bf4be1cc", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-05T10:54:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-05T10:54:16.000Z", "avg_line_length": 133.8, "max_line_length": 607, "alphanum_fraction": 0.8213751868, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.7634837689358858, "lm_q1q2_score": 0.6842733783897583}}
{"text": "\\subsubsection{General Route}\nIn this model, we estimate the overall positive impact of a many-to-many alliance to one ally.\n\nWhen a customer does a purchase in an ally, he receives \\RPd s for the alliance. Then he will browse where he can use them for a discount. This gives a chance of advertisement for every ally in the alliance.\nBut at the meantime, if an ally is not famous, when a customer views the list of allies in the alliance, the customer may ignore the ally and focus his attention on those famous allies.\nThe former positive impact is called \\textsl{Advertising Impact} ($I_A$) while the latter negative \\textsl{Drowning Impact} ($I_D$).\n\nIn a given limited area, the higher the $RC$, the more likely customers living in the area will see the advertisement, so the higher the overall positive impact. The product type overlap also plays a role. So:\n\\[  I = \\Phi \\cdot RC \\cdot (I_A - I_D)  \\]\n\n\\subsubsection{Cover Rate}\nWe take the area containing all the merchants in the alliance as the total area. As the merchants join the alliance, the area covered by new merchants overlaps with the already covered area. Generally, the later the merchant joins, the more its area overlaps with the already covered, and the less new area it covers. Therefore, as the number of merchants rise, the covered area shows a \\textsl{Diminishing Marginal Returns}.\n\nThe first task is to decide the total area by the location of the allies. We draw some points on the map, representing the merchants. We connect each two and will get a closed figure. Since $r=200m$, we expand the whole figure by $400m$. That is the final total area. An example is shown in Figure \\ref{fig:total_area}.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=9cm]{total_area.jpg}\n\t\\caption{an example of the calculation of the total area}\n\t\\label{fig:total_area}\n\\end{figure}\n\nAfter going through an amount of residential and merchant areas, we can safely suppose that the distance from resident areas to the nearest merchant is within two times the radius of the coverage circle. The thin black lines connect each 2 merchants. The bold lines are the outermost lines and they form a polygon. Since the residential area usually appears to be like rectangles, we draw lines parallel with each side outside the polygon. These lines are connected to form the red line, which shows the total area border.\n\nWhat we need to do is developing $RC=f(n)$. Obviously,\n\\[  \\begin{cases}\nf(0) = 0 \\\\\n\\frac{d}{dn} RC > 0 \\\\\n0 \\le RC < 1 \\\\\n\\frac{d}{d^2n} RC^2 < 0\n\\end{cases}  \\]\n\nTwo common functions fit the requirements:\n$ f(n) = \\frac{n}{n+k} $ and $ f(n) = -k^n+1 $.\nWe search for some typical places where there are merchants among several residential areas. By \\textit{Monte Carlo} method, we calculate several $(n,RC)$ and get the best $k$ and the best function through curve fitting.\n\n\\[f(n) = -k^n+1\\]\n\nCoefficients (with 95\\% confidence bounds):\n\\[k = 0.8305  (0.8182, 0.8429)\\]\n\n\\begin{center}\nGoodness of fit:\n\n  SSE: 0.002902\n  \n  R-square: 0.9912\n  \n  Adjusted R-square: 0.9912\n  \n  RMSE: 0.02409\n\\end{center}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=10.5cm]{RC_function.jpg}\n\t\\caption{the image of function RC=f(n)}\n\t\\label{fig:RC_function}\n\\end{figure}\n\n\\subsubsection{Advertising Impact}\nThe $I_A$, as its name indicates, has a linear relationship with the times an ally is advertised. Hence, $I_A \\propto (n-1)$. So we consider\n\\[  I_A = k_A (n-1)  \\]\nin which $k_A$ is a constant that will be measured later.\n\n\\subsubsection{Drowning Impact}\nThe $I_D$ is straightly related to the scale of the ally and the scale sum of all allies in the alliance.\n\nThe higher the reputation of an ally in the alliance, the less it will suffer from the \\textsl{Drowning Effect}.\n\nSuppose\n\\[  s = \\frac{s_X}{\\overline{s}} \n= \\frac{n \\cdot s_x}{\\sum\\limits_{i=1}^n S_i}  \\]\n\nSo,\n\\[\nI_D \\propto\n\\frac{\\textup{the total scale of the alliance}}{\\textup{the relative scale of the ally}}\n=\n\\frac{u(s_1,s_2,\\ldots,s_n)}{v(s)}\n\\]\n\nObviously, the relationship between $s$ and $I_D$ is not linear. It should fit in with\n\\[\\begin{cases}\n\\frac{d}{ds} I_D < 0 \\\\\n\\frac{d}{d^2s} {I_D}^2 > 0 \\\\\n\\forall i,j \\in \\{1,2,\\ldots,n\\}, S_i < S_j,\n\\frac{\\partial u}{\\partial S_i} < \\frac{\\partial u}{\\partial S_j}\n\\end{cases}\\]\n\nBy calculating with calculus, we find a suitable answer.\n\\[\nu(s_1,s_2,\\ldots,s_n) = \\sum\\limits_{i=1}^n {s_i}^2\n\\]\n\n\\[  v(s) = e^x  \\]\n\nSo for the $I_D$, as is shown in figure \\ref{fig:drowning_effect},\n\\[  I_D = \\frac{\\sum\\limits_{i=1}^n {s_i}^2}{e^s}  \\]\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\linewidth]{drowning_effect.jpg}\n\\caption{the relationship between relative $I_D$ and scale of the ally}\n\\label{fig:drowning_effect}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\linewidth]{drowning_effect_calculus.png}\n\\caption{the features of the relationship between relative $I_D$ and scale of the ally}\n\\label{fig:drowning_effect_calculus}\n\\end{figure}\n\n\\subsubsection{Product Type}\nWe decompose the overall impact of product type on \\X{X}\\ ($\\Phi_X$) into several sub-impact for every product type.\n\nLet us make our object the impact from product type of \\B\\ to \\A. Then we calculate the overlapping rate of each column (universal product type classification).\n\\[  \\phi_{i,B} = \n\\frac{\\sum_{\\begin{subarray}{c}\n\\textup{for each overlapping} \\\\ \\textup{Product}\\ i\n\\end{subarray}} P_i}%\n{\\sum_{\\begin{subarray}{c}\n\\textup{for each } \\\\ \\textup{Product}\\ j\n\\end{subarray}} P_j}  \\]\n\n\\[  \\phi_B = \\sum\\limits_{i=1}^{M_i} \\phi_{i,B}  \\]\n\nHere is an example of the calculation of $\\phi$. Its final result is $\\Phi=171\\%$.\n\n\\begin{table}[H]\n\\begin{tabular}{|c|p{.7\\textwidth}|c|}\n\\hline\nProduct Type & Products & $\\phi_{i,B}$ \\\\\n\\hline\nDishwasher & \\tabincell{l}{(A) \\$359.99, \\$350.00 \\\\ (B) \\$349.00, \\$330.00 \\\\ (A\\&B) \\$512.80, \\$399.99} & 39.7\\% \\\\\n\\hline\nMicrowave Oven & \\tabincell{l}{(A) \\$99.98, \\$212.40 \\\\ (B) \\$59.98, \\$95.30, \\$111.99 \\\\ (A\\&B) \\$96.67, \\$134.99} & 28.6\\% \\\\\n\\hline\nRefrigerator & \\tabincell{l}{(A) \\$783.19, \\$511.40 \\\\ (B) \\$599.00, \\$872.02 \\\\ (A\\&B) \\$279.00, \\$635.33} & 24.8\\% \\\\\n\\hline\nLaundry & \\tabincell{l}{(A) \\$205.99, \\$279.99 \\\\ (B) \\$163.99 \\\\ (A\\&B) \\$253.33, \\$249.99, \\$323.51} & 56.0\\% \\\\\n\\hline\nRange Hood & \\tabincell{l}{(A) \\$323.82, \\$382.21 \\\\ (B) \\$359.26, \\$290.91, \\$284.99 \\\\ (A\\&B) \\$459.96} & 21.9\\% \\\\\n\\hline\n\\end{tabular}\n\\caption{an example of the calculation of $\\phi$}\n\\label{tab:phi_calc}\n\\end{table}\n\nNow the last problem is how to sum up the impact of each ally to the merchant. By market experience, one suitable relationship between $\\phi_X$ and $\\Phi_{X}$ is\n\\[  \\Phi_{X} = {\\sum_{X=1}^{n-1} \\phi_X}  \\]\n\\[  = {\\sum_{X=1}^{n-1} {\\sum\\limits_{i=1}^{M_i} \\phi_{i,X}}}  \\]\n\n\\subsubsection{Overall Algorithm}\nFor a certain ally,\n\\[  I = \\Phi \\cdot RC \\cdot (I_A - I_D)  \\]\n\\[  = {\\sum_{X=1}^{n-1} \\phi_X} \\cdot (-0.8305^n+1) \\cdot \\left[k_A (n-1) - \\frac{\\sum_{i=1}^n {s_i}^2}{e^s}\\right]   \\]\n\\[  = {\\sum_{X=1}^{n-1} {\\sum\\limits_{i=1}^{M_i} \\phi_{i,X}}} \\cdot (-0.8305^n+1) \\cdot \\left[k_A (n-1) - \\frac{\\sum_{i=1}^n {s_i}^2}{e^s}\\right]  \\]\n\nThe relative importance will be further discussed in the section \\textsl{Sensitivity Analysis}.\n\nThen we test the model result. We get the value of the constant $k_A=50$ and make a modification to modify $I$'s order of magnitude. The final result is\n\\begin{equation}\nI = \\left({\\sum_{X=1}^{n-1} {\\sum_{i=1}^{M_i} \\phi_{i,X}}} \\cdot (-0.8305^n+1) \\cdot \\left[50(n-1) - \\frac{\\sum_{i=1}^n {s_i}^2}{e^{\\sqrt{s}}}\\right]\\right)^\\frac{1}{3}\n\\label{eq:mtm_model}\n\\end{equation}\n", "meta": {"hexsha": "241b494843d7237e68aa6481fcffafa5bb2ac999", "size": 7606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "20220124_IMMC_2022W/Essay/Core Files/mtm_model.tex", "max_stars_repo_name": "Jason-Ying/Birdy-MathModelling", "max_stars_repo_head_hexsha": "3f2c4aa72c29458a296921db16bcac99567aa7e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-03-21T10:35:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T07:32:23.000Z", "max_issues_repo_path": "20220124_IMMC_2022W/Essay/Core Files/mtm_model.tex", "max_issues_repo_name": "Jason-Ying/Birdy-MathModelling", "max_issues_repo_head_hexsha": "3f2c4aa72c29458a296921db16bcac99567aa7e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "20220124_IMMC_2022W/Essay/Core Files/mtm_model.tex", "max_forks_repo_name": "Jason-Ying/Birdy-MathModelling", "max_forks_repo_head_hexsha": "3f2c4aa72c29458a296921db16bcac99567aa7e3", "max_forks_repo_licenses": ["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.5449101796, "max_line_length": 522, "alphanum_fraction": 0.6919537207, "num_tokens": 2510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6842733602802811}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{graphicx}\n\\begin{document}\n\n\\section{Problem}\nSIR model for a single class of population\nwith respect to time t and variables $[S, I, R]$ for constant population\n\n\n\n\\begin{eqnarray}\n\\frac{dS}{dt} &=& - \\beta  S I \\\\\n\\frac{dI}{dt} &= &\\beta  S I -  \\gamma I \\\\\n\\frac{dR}{dt} &=& \\gamma I\n\\end{eqnarray}\n\n\\begin{itemize}\n\\item $[S, I, R]$: values of the variables (ratio of suceptibles, infectious and recovered fraction of the population)\n\\item $t$: time (not used because autonomous ODE)\n\\item $\\beta$ : transmission coefficient.\n\\item $\\gamma$ : healing rate.\n\\end{itemize}\n\n\\section{Results}\n\n\\includegraphics[height=7cm]{figure.png}\n\n\\end{document}\n", "meta": {"hexsha": "390a3968c3f7ac45c438c07ec1402f2db338a889", "size": 694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article/document.tex", "max_stars_repo_name": "pnavaro/irmar-git-project", "max_stars_repo_head_hexsha": "4cf81bca8a493d1abaf94c589d8db09fce59a040", "max_stars_repo_licenses": ["MIT"], "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/document.tex", "max_issues_repo_name": "pnavaro/irmar-git-project", "max_issues_repo_head_hexsha": "4cf81bca8a493d1abaf94c589d8db09fce59a040", "max_issues_repo_licenses": ["MIT"], "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/document.tex", "max_forks_repo_name": "pnavaro/irmar-git-project", "max_forks_repo_head_hexsha": "4cf81bca8a493d1abaf94c589d8db09fce59a040", "max_forks_repo_licenses": ["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.9310344828, "max_line_length": 118, "alphanum_fraction": 0.7017291066, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6842661783501277}}
{"text": "\\section{DP on Graphs}\n\n%%%%%%%%%%\n\\begin{frame}{DP on graphs}\n  \\begin{exampleblock}{Minimum vertex cover \\pno{2.2.18}}\n    \\begin{itemize}\n      \\item tree $T$\n      \\item compute (the size of) a minimum vertex cover of $T$\n    \\end{itemize}\n\n    \\fignocaption{width = 0.30\\textwidth}{fig/vertex-cover.png}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item rooted $T$ at $r$\n      \\item subproblem $I(u)$: the size of a MVC of $T_{u}$ subtree\n      \\item goal: $I(r)$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{DP on graphs}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item question: Is $u$ in $\\text{MVC}[u]$?\n      \\item recurrence:\n\t\\[\n\t  I(u) = \\max \\set{|\\text{children of } u| + \\sum_{v: \\text{grandchildren of } u} I(v), 1 + \\sum_{v: \\text{children of } u} I(v)}\n\t\\]\n      \\item initialization: \n\t\\[\n\t  I(u) = 0, \\text{if } u \\text{ is a leave}\n\t\\]\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{DP on graphs}\n  \\begin{block}{Code.}\n    \\begin{verbatim}\n      DFS on T from root r:\n        when u is ``finished'': \n          I(u) = 0, if u is a leave\n          I(u) = ..., otherwise\n    \\end{verbatim}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{DP on graphs}\n  \\begin{exampleblock}{Shortest paths in dags}\n    \\begin{itemize}\n      \\item dag $G = (V, E, w)$\n      \\item $s \\in V$\n      \\item SSSP from $s$\n    \\end{itemize}\n\n    \\fignocaption{width = 0.30\\textwidth}{fig/dag.png}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $\\text{dist}[v]$: shortest distance from $s$ to $v$ \n      \\item goal: all $\\text{dist}[v]$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{DP on graphs}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item question: What is the relation between $\\text{dist}[v]$ and $\\text{dist}[u]$ of its predecessors $u$?\n      \\item recurrence:\n\t\\[\n\t  \\text{dist}[v] = \\min_{u \\to v} \\left(\\text{dist}[u] + w(u \\to v)\\right) \n\t\\]\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{DP on graphs}\n  \\begin{block}{Code.}\n    \\begin{verbatim}\n    dist[s] = 0\n    dist[v] = infty for others\n\n    for v != s in linearized order\n      dist[v] = min_{u -> v} dist[u] + w(u \\to v)\n    \\end{verbatim}\n  \\end{block}\n\n  \\begin{alertblock}{Remarks.}\n    \\begin{enumerate}\n      \\item longest path\n      \\item negative edges\n    \\end{enumerate}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n", "meta": {"hexsha": "29bfc8619843d9e396b22745e190becf1f686e8c", "size": 2502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-dp-2016-06-16/sections/graph-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/graph-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/graph-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": 25.02, "max_line_length": 130, "alphanum_fraction": 0.571942446, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093668, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6842661632547024}}
{"text": "% !TEX root = ./main.tex\n\\section{Implementing the evolutionary forces}\n\nAs hinted at in Fig.~\\ref{fig01:moran}(A), the Moran process gives us a simple\nrecipe for how to encode the different evolutionary forces on the transition\nrates $W^\\pm(x)$. Recall that since the transition rates in allele frequency\nspace are the same as the transition rates in number of organisms space, we can\nmore easily conceptualize the forces in the latter. In other words, the rate to\ntransition from $x$ to $x + \\Delta x$ is by construction equal to the rate to\ntransition from $n$ to $n + 1$; therefore we can define the transition rates in\nthe more convenient space of organism number. In the Moran process changes in\npopulation composition happen when one of the organisms in the population chosen\nrandomly dies and it is immediately replaced by an organism with a different\nallele (since replacement with the same allele does not change the population\ncomposition). This means that the general form in which the number of organisms\nwith allele $A$ can change looks like\n\\begin{equation}\n    W^+(x) = w^+(n) = \n    \\text{Rate of $A$ dying} \\times\n    \\text{Probability of replacement by $a$},\n\\end{equation}\nand \n\\begin{equation}\n    W^-(x) = w^-(n) = \n    \\text{Rate of $a$ dying} \\times\n    \\text{Probability of replacement by $A$},\n\\end{equation}\nHaving these general forms let us define the rates for different evolutionary\nforces.\n\n\\subsection{Genetic drift}\n\\mrm{Further discussion of what genetic drift is?}\n\nGiven the intrinsic stochasticity of the Moran process, the easiest evolutionary\nforce to implement is that of genetic drift. For simplicity, we assume that both\nallele types have the same death rate per organism, $\\gamma$. For the case where\nonly genetic drift is changing the population composition, we assume that the\nreproduction probability per organism is the same (equivalent to saying both\ngenotypes have the same fitness), so the probability of an organism that died\nbeing replaced by an organism with the opposite allele is given by the relative\nfrequency of such allele. Mathematically this means that we can express the rate\nwith which the number of organisms with allele $A$ increases as\n\\begin{equation}\n    W^+(x) = w^+(n) = \n    \\overbrace{\\gamma \\times (N-n)}^{\\text{rate of $a$ dying}} \\times\n    \\overbrace{\\frac{n}{N}}^\n    {\\substack{\\text{prob. of $A$} \\\\ \\text{replacing}}},\n\\end{equation}\nwhere the term $\\gamma \\times (N-n)$ defines the rate at which an organism with\nan allele $a$ dies, and the term $n/N$ defines the probability of an organism\nwith allele $A$ reproducing. Equivalently the rate with which the number of\norganisms with allele $a$ decreases takes the form\n\\begin{equation}\n    W^+(x) = w^+(n) = \n    \\overbrace{\\gamma n}^{\\substack{\\text{rate of $A$}\\\\ \\text{dying}}}\n    \\overbrace{\\frac{(N-n)}{N}}^\n    {\\substack{\\text{prob. of $a$} \\\\ \\text{replacing}}}.\n\\end{equation}\nGiven that both rates are equal, we can see that the first term in\nEq.~\\ref{eq:pde_x_general} involving $W^+(x) - W^-(x)$ is zero. This means that\nthere are no deterministic (directional) forces when only genetic drift is\nconsidered, just pure randomness. Substituting the sum of the rates into the\nsecond term of Eq.~\\ref{eq:pde_x_general} results in\n\\begin{equation}\n\\begin{aligned}\n    \\frac{\\partial P(x, t)}{\\partial t} &=\\frac{1}{2 N^{2}} \n    \\frac{\\partial^{2}}{\\partial x^{2}}[2 \\gamma(N-n) n P(x, t)], \\\\\n    &=\\frac{\\partial^{2}}{\\partial x^{2}}\n    \\left[\\frac{1}{2 N^{2}} 2 \\gamma\\left(\\frac{(N-n) n}{N} \\right) P(x, t)\\right],\\\\\n    &=\\frac{\\gamma}{N} \\frac{\\partial^{2}}{\\partial x^{2}}[x(1-x) P(x, t)],\n\\end{aligned}\n\\end{equation}\nwhere for the last step we substitute the definition of $x\\equiv n/N$. We\nredefine the time scale to be in units of $\\gamma^{-1}$, meaning that the time\nunits are measured in terms of the mean life expectancy of an organism. This\nallows us to write\n\\begin{equation}\n    \\frac{\\partial P(x, t)}{\\partial t} =\n    \\frac{1}{N} \\frac{\\partial^{2}}{\\partial x^{2}}[x(1-x) P(x, t)],\n\\end{equation}\nthe classic Kimura diffusion equation for genetic drift only.\n\n\\subsection{Genetic drift plus selection}\n\nNatural selection is intrinsically associated with the concept of fitness. The\nphrase ``survival of the fittest'' first used by Darwin guided and still guides\nthe way that biologists think about the evolution of many organisms. But despite\nthe fact that fitness is part of the daily jargon of many biologists, it is a\nsubtle and highly debated concept. After all, what defines the ability of an\norganism to survive the challenges that surround them are completely context\ndependent. Roughly speaking we can think of fitness as the ability of an\norganism, or a population of organisms to survive and reproduce in the given\necological niche they occupy. The concept of fitness only makes sense when there\nis a competition between organisms. The intrinsic growth rate of a completely\nhomogeneous population is irrelevant since, as we mentioned before, a population\nwith a single allele growing is not evolving since there are no changes to the\npopulation composition. The term ecology has to be included because fitness is a\nresult of the interplay between organisms with their environment including all\nbiotic and abiotic interactions. \n\nIt is common both in theory and in experiments to use the relative growth rates\nof organisms, i.e. the speed at which they can reproduce and generate\noffspring, as a proxy for fitness. This is a convenient approximation both\nfor experiments and for theory, but one should not lose track of the relevant\ncontext dependence on the fitness. Just because redwoods have an average life\nspan of 500-700 years and a very low growth rate that doesn't mean they are not\nfit. Having said that we will first begin with the simplest form of fitness,\ni.e. frequency independent selection. The term frequency independence simply\nrefers to the assumption that the fitness of a particular allele does not\ndepend on the relative abundance of such allele. This assumption could break\ndown for cases such as some pathogenic bacteria that coordinate their attack\nvia cell-to-cell communication known as quorum sensing. \n\nTo implement the effect of different reproductive success for different alleles\nwe introduce parameters $f_A$ and $f_a$ as the fitness values for allele $A$ and\n$a$, respectively. With these parameters in hand we must redefine the\nprobability of an organism reproducing to replace the one that dies in the Moran\nprocess. The replacement probability for allele $A$ is now given by\n\\begin{equation}\n    \\text{Prob. of $A$ replacing} = \\frac{f_A n}{f_A n + f_a (N - n)}.\n\\end{equation}\nLikewise for allele $a$ we have\n\\begin{equation}\n    \\text{Prob. of $a$ replacing} = \\frac{f_a (N - n)}{f_A n + f_a (N - n)}.\n\\end{equation}\nLet us now assume that $f_A \\approx (1 + s) f_a$ for a small $s$. This parameter\n$s$ is the so-called selection coefficient, which in nature can be of the order\nof $10^{-3}$ or less. With these assumptions we can simplify these substitution\nprobabilities to be\n\\begin{equation}\n    \\text{Prob. of $A$ replacing} \\approx \\frac{n}{N}(1 + s),\n\\end{equation}\nand\n\\begin{equation}\n    \\text{Prob. of $a$ replacing} \\approx \\frac{(N - n)}{N},\n\\end{equation}\nwhere, after canceling $f_a$ from the numerator and denominator, we assume that\n$(1 + s)n + (N - n) \\approx N$ since $s \\ll 1$. With these updated replacement\nprobabilities we again compute the population change rates $W^\\pm(x)$ as the\nproduct of the rate of certain type of organism dying times the probability of\nbeing replaced by the opposite allele. These rates take the form\n\\begin{equation}\n    W^+(x) = \n    \\overbrace{\\gamma \\times (N - n)}^{\\text{rate of $a$ dying}} \\times\n    \\overbrace{\\frac{n}{N} (1 + s)}^\n    {\\substack{\\text{prob. of $A$ replacing}\\\\ \\text{with fitness difference}}},\n\\end{equation}\nand\n\\begin{equation}\n    W^-(x) = \\gamma n \\frac{(N - n)}{N},\n\\end{equation}\nWith these rates we ca now compute the sum and difference required by\nEq.~\\ref{eq:pde_x_general}. The difference of these two rates takes the form\n\\begin{equation}\n    W^+(x) - W^-(x) = \\gamma s \\frac{n(N-n)}{N}.\n\\end{equation}\nThe sum results in\n\\begin{equation}\n    W^+(x) + W^-(x) = \\gamma (2 + s) \\frac{n(N-n)}{N}.\n\\end{equation}\nSubstituting this into Eq.~\\ref{eq:pde_x_general} results in\n\\begin{equation}\n    \\frac{\\partial}{\\partial t} P(x, t) =\n    -\\frac{1}{N} \n    \\frac{\\partial}{\\partial x}\n    \\left[\\gamma s \\left(\\frac{(N-n) n}{N}\\right) P(x, t)\\right] \n    +\\frac{1}{2 N^{2}} \n    \\frac{\\partial^{2}}{\\partial x^{2}}\n    \\left[\\gamma (2+s)\\left(\\frac{(N-n) n}{N}\\right) P(x, t)\\right].\n\\end{equation}\nSimplifying terms and substituting the definition of the allele frequency gives\n\\begin{equation}\n    \\frac{\\partial}{\\partial t} P(x, t) =\n    -\\gamma_{S} \\frac{\\partial}{\\partial x}[x(1-x) P(x, t)] \n    +\\frac{\\gamma\\left(1+\\frac{s}{2}\\right)}{N}\n    \\frac{\\partial^{2}}{\\partial x^{2}}[x(1-x) P(x, t)].\n\\end{equation}\nTo obtain the final form we again write the time scale in units of\n$\\gamma^{-1}$. Furthermore we use the simplification that $s \\ll 1$, obtaining\nthe classic Kimura diffusion equation for selection and drift\n\\begin{equation}\n    \\frac{\\partial}{\\partial t} P(x, t) =\n    -\\frac{\\partial}{\\partial x}[s x(1-x) P(x, t)] \n    +\\frac{1}{N} \\frac{\\partial^{2}}{\\partial x^{2}}[x(1-x) P(x, t)].\n\\end{equation}\n\n\\subsection{Genetic drift plus selection plus mutation}\n\nOne of the ingredients for evolution to take place is the constant appearance of\ngenetic variability. After all, the raw material for evolution to act on is the\nappearance of new mutations in the population. While both genetic drift and\nselection reduce population diversity, mutation creates more diversity. In the\ncase of our one-locus two-allele case it can even resurrect alleles that wen\nextinct as one organism changes its genetic content. The implementation of this\nthird force changes the possibilities on how to change the composition of the\npopulation. As depicted in Fig.~\\ref{fig01:moran}(A), if mutation is taken into\naccount, there are two possible substitutions which would modify the allele\nfrequency: (1) The usual path in which an organism with the opposite allele to\nthe one that died reproduces and does not mutate when doing so, and (2) the\npossibility of an organism of the same allele as the one that died reproducing,\nbut when doing so, it mutates to the opposite allele. For simplicity we will\nassume that the mutation probability from $A$ to $a$, $\\mu_{A\\rightarrow a}$, is\nthe same as from $a$ to $A$, $\\mu_{a\\rightarrow A}$. For simplicity let us\ndefine the transition rate $W^+(x)$ as\n\\begin{equation}\n    W^+(x) = W^+_{(1)}(x) + W^+_{(2)}(x),\n\\end{equation}\nwhere we break the rate into the two possible paths. The first path in which an\norganism of the opposite allele to the one that died replaces it and does not\nmutate when doing so takes the form\n\\begin{equation}\n    W^{+}_{(1)}(x) = \n    \\overbrace{\\gamma(N-n)}^{\\text{rate of $a$ dying}}\\times\n    \\overbrace{\\frac{n}{N}(1+s)}^\n    {\\substack{\\text{prob. of $A$ replacing}\\\\ \\text{with fitness diff.}}}\\times\n    \\overbrace{(1-\\mu)}^\n    {\\substack{\\text{prob. of not} \\\\ \\text{mutating}}},\n\\end{equation}\nwhere the evolutionary forces appear as a product of the rates and probabilities\nof each of the steps taking place. For the second path in which the organism \nthat replaces the one that dies is of the same type, but when it reproduces \nthere is a mutation to the opposite allele, we have a rate of the form\n\\begin{equation}\n    W^{+}_{(2)}(x) = \n    \\overbrace{\\gamma(N-n)}^{\\text{rate of $a$ dying}}\\times\n    \\overbrace{\\frac{(N - n)}{N}}^\n    {\\text{prob. of $a$ replacing}}\\times\n    \\overbrace{\\mu}^{\\text{prob. of mutating}}.\n\\end{equation}\nPutting these two rates together results in a transition rate $W^{+}(x)$ of the\nform\n\\begin{equation}\n    W^{+}(x) = \n    \\overbrace{\\gamma(N-n) \\frac{n}{N}(1+s) (1-\\mu)}^{\\text{path (1)}}\n    + \\overbrace{\\gamma(N-n) \\frac{(N-n)}{N} \\mu}^{\\text{path (2)}}.\n\\end{equation}\nEquivalently, we can write the rate $W^{-}(x)$ as a decomposition of the two \npossible paths that lead to population structure changes. Putting these two \nrates back together results in\n\\begin{equation}\n    W^{-}(x)=\n    \\overbrace{\\gamma n \\frac{(N-n)}{N}(1-\\mu)}^{\\text{path (1)}}\n    +\\overbrace{\\gamma n \\frac{n}{N}(1+s) \\mu}^{\\text{path (2)}}.\n\\end{equation}\nAgain we follow Eq.~\\ref{eq:pde_x_general} and compute the sum and the\ndifference between these rates. After some algebra, we find that the difference\nbetween these rates is of the form\n\\begin{equation}\n    W^+(x) - W^-(x) = \n    \\frac{\\gamma}{N}\\left[n s\\left(N-n-N\\mu\\right)+N{\\mu}(N-2 n)\\right].\n\\end{equation}\nFor the sum of the rates we find\n\\begin{equation}\n    W^+(x) + W^-(x) =\n    \\frac{\\gamma}{N}\\left[N n(2-4 \\mu+s-\\mu s) + \n    n^{2}(-2+4 \\mu-s+2 \\mu s)\\right].\n\\end{equation}\nSubstituting these rates in Eq.~\\ref{eq:pde_x_general} gives\n\\begin{equation}\n\\begin{split}\n    \\frac{\\partial}{\\partial t} P(x, t)=\n    &-\\frac{1}{N} \\frac{\\partial}{\\partial x}\n    \\left[ \\frac{\\gamma}{N} \\left(n s \\left(N - n - N \\mu \\right)+\n    N \\mu (N - 2 n) \\right) P(x, t)\\right] \\\\\n    & + \\frac{1}{2 N^{2}} \\frac{\\partial^2}{\\partial x^{2}}\n    \\left[\\frac{\\gamma}{N}\\left(N n (2 - 4 \\mu+s-\\mu s)\n    -n^{2}\\left(2-4 \\mu+s-2\\mu s\\right)\\right) P(x, t)\\right].\n\\end{split}\n\\end{equation}\nSubstituting the definition of the allele frequency results in\n\\begin{equation}\n\\begin{split}\n    \\frac{\\partial}{\\partial t} P(x, t)=\n    &-\\gamma \\frac{\\partial}{\\partial x}[x s(1-x-\\mu)+\\mu(1-2 x) P(x, t)] \\\\\n    &+\\frac{\\gamma}{2 N} \\frac{\\partial^{2}}{\\partial x}\n    \\left[x(2-4 \\mu+s-\\mu s)-x^{2}(2-4 \\mu+s-2 \\mu s) P(x, t)\\right].\n\\end{split}\n\\end{equation}\nTo get to the final equation we simply make use of the approximation that both\n$s, \\mu \\ll 1$. Implementing this, and writing the time scale in units of\n$\\gamma^{-1}$ results in the classic diffusion theory equation with all three\nforces implemented\n\\begin{equation}\n    \\frac{\\partial}{\\partial t} P(x, t) =\n    -\\frac{\\partial}{\\partial x}[s x(1-x) + \\mu (1 - 2x) P(x, t)] \n    +\\frac{1}{N} \\frac{\\partial^{2}}{\\partial x^{2}}[x(1-x) P(x, t)].\n\\end{equation}", "meta": {"hexsha": "c114a389c638e942a62e7e7ae5df6ece85f6331d", "size": 14260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/spread_the_butter/section_03_diffusion.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_03_diffusion.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_03_diffusion.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.6864111498, "max_line_length": 85, "alphanum_fraction": 0.706171108, "num_tokens": 4201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.6842661612652288}}
{"text": "\\section{Dimension reduction}\n\n% ===\n\\emph{PCA}\n\\enskip $\\normalcolor\n\\to f\\!\\!: \\mathbb{R}^d\\to\\mathbb{R}^k, k\\!<\\!d\n\\hfill (\\lambda_1\\!\\geq\\!...\\!\\geq\\!\\lambda_d\\!\\geq\\!0)$\n\n\\textbf{centered:} $\\mu = \\mathbb{E}(X) = \\frac{1}{n} \\sum_{i=1}^n x_i = 0$\\\\\n\\textbf{empir. cov.:} $\\Sigma = \\frac{1}{n} \\sum_{i=1}^n x_ix_i^\\top = \\sum_{i=1}^d \\lambda_i v_iv_i^\\top$\n\n$(\\hat W, \\hat z_1, .., \\hat z_n) = \\arg\\min \\sum_{i=1}^n \\norm{Wz_i - x_i}_2^2$\n\n\\textbf{Sol.:} \\highlight*{$\\hat z_i = \\hat W^\\top x_i$}, $\\hat W = (v_1\\vert..\\vert v_k) \\in \\mathbb{R}^{d\\times k}$, orth.\n\n% ===\n\\emph{Kernel PCA \\enskip\n\\normalfont\\sffamily$\\normalcolor\\to$ non-linear, feature discov.}\n\\textbf{Ansatz:} {\\small see KLR},\\enskip\n\\textbf{Constraint:} $\\norm{w}_2 \\!\\!=\\! \\alpha^{\\!\\top}\\!K\\alpha \\!=\\! 1$\n\n\\textbf{Kernel PC:} $\\alpha^{(1)}\\!,..,\\alpha^{(k)}\\!\\in\\!\\mathbb{R}^n$, \\enskip\n$\\alpha^{(i)} \\!=\\! \\frac{1}{\\sqrt{\\lambda_i}}v_i$,\\\\\n$K = \\sum_{i=1}^n \\lambda_i v_i v_i^\\top$, $\\lambda_1\\!\\geq\\!..\\!\\geq\\!\\lambda_d\\!\\geq\\!0$\\\\\n\\textbf{New point}: \\highlight{$\\hat{z}_i = \\sum_{j=1}^n\\alpha_j^{(i)}k(\\hat{x}_i,x_j)$}\n\n% ===\n\\emph{Autoencoders:}\nFind identity fct.: $x \\approx f(x;\\theta)$\\\\\n$f(x;\\theta) = f\\ped{decode}(f\\ped{encode}(x;\\theta\\ped{enc.});\\theta\\ped{dec.})$\n", "meta": {"hexsha": "966305a6363f0718cbb4042af61c016afc34c5da", "size": 1259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/DimensionReduction.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/DimensionReduction.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/DimensionReduction.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.6129032258, "max_line_length": 124, "alphanum_fraction": 0.5806195393, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6842615150044301}}
{"text": "\\section{Mutable Implementation}\nWe now give the implementation of the operators seen until now with a simple mutable state.\n\nWe define our state as that of the state monad (that is a statement that evaluates to a value of type $a$ in a state of type $s$ has the same type of its denotational semantics):\n\\begin{verbatim}\ndata ST s a = ST(s->(a,s))\n\\end{verbatim}\n\nReferences will be based on the state since a reference must be easily convertible into statements, one for evaluating the reference and one for assigning it:\n\\begin{verbatim}\ntype Get s a = ST s a\ntype Set s a = a -> ST s ()\ndata Ref s a = Ref (Get s a) (Set s a)\n\\end{verbatim}\n\nWe now need to represent the state (our stack). The simplest implementation of a typed stack is based on heterogeneous lists. A heterogeneous list is build based on two type constructors:\n\\begin{verbatim}\ndata Nil = Nil\ndata Cons h tl = Cons h tl\n\\end{verbatim}\n\nSince heterogeneous lists do not have a single type, we characterize all heterogeneous lists with an appropriate predicate:\n\\begin{verbatim}\nclass HList l\ninstance HList Nil\ninstance HList tl => HList (Cons h tl)\n\\end{verbatim}\n\nWe access heterogeneous lists by index. To ensure type safety we define type-level integers, encoded as Church Numerals:\n\\begin{verbatim}\ndata Z = Z\ndata S n = S n\n\nclass CNum n\ninstance CNum Z\ninstance CNum n => instance CNum (S n)\n\\end{verbatim}\n\nWe can now read the length of a heterogeneous list, as well as get the type of an arbitrary element of the list:\n\n\\begin{verbatim}\ntype family HLength l :: *\ntype instance HLength Nil = Z\ntype instance HLength (Cons h tl) = S (HLength tl)\n\ntype family HAt l n :: *\ntype instance HAt (Cons h tl) Z = h\ntype instance HAt (Cons h tl) (S n) = HAt tl n\n\\end{verbatim}\n\nWe will need a way to manipulate the values of a heterogeneous list. For this reason we define a lookup predicate:\n\\begin{verbatim}\nclass (HList l, CNum n) => HLookup l n where\n\tlookup :: l -> n -> HAt l n\n\tupdate :: l -> n -> HAt l n -> l\n\ninstance (HList tl) => HLookup (Cons h tl) Z where\n\tlookup (Cons h tl) _ = h\n\tupdate (Cons h tl) _ h’ = (Cons h’ tl)\n\ninstance (HList tl, CNum n) => HLookup (Cons h tl) (S n) where\n\tlookup (Cons _ tl) _ = lookup tl (undefined::n)\n\tupdate (Cons h tl) _ v’ = (Cons h’ (update tl (undefined::n) v’))\n\\end{verbatim}\n\nNow we have all that we need to instance our stack, reference and state predicates.\n\nWe begin by instancing the $Stack$ predicate, since all heterogeneous lists are stacks and as such can be used:\n\\begin{verbatim}\ninstance Stack Nil where\n\ttype Push Nil a = Cons a Nil\n\tpush = Cons\n\tpop (Cons h tl) = tl\n\ninstance (Stack tl, s ~ Cons h tl) => Stack s where\n\ttype Push s a = Cons a s\n\tpush = Cons\n\tpop (Cons h tl) = tl\n\\end{verbatim}\n\nWe instance the $Monad$ class with the $ST$ type (as in the state monad):\n\\begin{verbatim}\ninstance Monad (ST s) where\n\treturn x = ST(\\s -> (x,s))\n\t(ST st) >>= k = ST(\\s -> let (s’,res) = st s in k res s’)\n\\end{verbatim}\n\nWe also define a way to evaluate a statement and ignoring the resulting state:\n\\begin{verbatim}\nrunST :: ST s a -> s -> a\nrunST (ST st) s = snd (st s)\n\\end{verbatim}\n\nNow that $Monad (ST s)$ is instanced we can instance the $RefSt$ predicate for our references and state:\n\\begin{verbatim}\ninstance (HList s, n~HLength s) => RefSt Ref ST s where\n\teval (Ref get set) = get\n\t(Ref get set) := v = set v\n\t(Ref get set) *= f = do v <- get\n\t\t\t\t\t\t\t  set (f v)\n\tnew a k = \n\t\t\t\tlet r_new = Ref (ST (\\s -> (lookup s (undefined::n), s)))\n\t\t\t\t\t\t\t\t  (\\v -> ST(\\s -> ((), update s (undefined::n) v)))\n\\end{verbatim}\n\nThanks to this last instance we can now give a first working example of usage of our references with mutable state:\n\\begin{verbatim}\nex1 :: ST Nil Int\nex1 = 10 ‘new’ (\\(i :: Ref (New Nil Int) Int) -> \n\t  do i *= (+2)\n\t\t i)\n\nres1 :: Int\nres1 = runST ex1 Nil\n\\end{verbatim}\n\nThe result, as expected, is $res1=12$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%EVALUATION STEPS FOR EXAMPLE1%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nWe complete the implementation of our system so far by adding records. We use as records heterogeneous lists to which we access via labels. A label is defined with a getter and a setter (similar to those found in the $Ref$ constructor) as:\n\\begin{verbatim}\ndata Label r a = Label (r->a) (r->a->r)\n\\end{verbatim}\n\nWe can instance the $Record$ predicate:\n\\begin{verbatim}\ninstance (Stack s, HList r) => Record r Ref ST s where\n\ttype Label r a = Label r a\n\tRef get set <= Label read write =\n\t\tRef(do r <- get\n\t\t\t\treturn read r)\n\t\t\t(\\v’-> do r <- get\n\t\t\t\t\t   set (write r v’))\n\\end{verbatim}\n\nTo more easily manipulate records we define a function for building labels from $CNum$s:\n\\begin{verbatim}\nlabelAt :: (HList l, CNum n, HLookup l n) => l -> n -> Label l (HAt l n)\nlabelAt _ = Label (\\l -> lookup l (undefined::n)) (\\l -> update l (undefined::n))\n\\end{verbatim}\n\nWe can now give a second example that shows how records can be manipulated:\n\\begin{verbatim}\ntype Person = String ‘Cons’ String ‘Cons’ Int ‘Cons’ Nil\nfirst :: Label Person String\nfirst = labelAt Z\nlast :: Label Person String\nlast = labelAt (S Z)\nage :: Label Person Int\nage = labelAt (S S Z)\n\nmk_person f l a = (f ‘Cons’ l ‘Cons’ a ‘Cons’ Nil)\n\nex2 :: ST Nil Person\nex2 = (mk_person “John” “Smith” 27) ‘new’ (\\(p :: Ref (New Nil Person) Person) ->\n\t\t\tdo (p <= last) *= (++ “ Jr.”)\n\t\t\t   (p <= age) := 25\n\t\t\t   pv <- eval p\n\t\t\t   return pv)\nres2 :: Person\nres2 = runST ex2\n\\end{verbatim}\nThe result is, as expected, $“John” ‘Cons’ “Smith Jr.” ‘Cons’ 25 ‘Cons’ Nil$.\n\nWe give one last example that does not work even though at a first glance we would expect it to. This example is used to introduce the next session:\n\\begin{verbatim}\nex3 :: ST Nil Unit\nex3 = 10 ‘new’ (\\(i :: Ref (New Nil Int) Int) ->\n\t  “Hello” ‘new’ (\\(s :: Ref (New (New Nil Int) String) String) ->\n\t  do i *= (+2)\n\t\t s *= (++” World”)\n\t\t return ())\n\\end{verbatim}\n\nThis example does not even compile because:\n\\begin{verbatim}\ni *= (+2) :: ST (New Nil Int) ()\n\\end{verbatim}\n\nwhile\n\\begin{verbatim}\ns *= (++” World”) :: ST (New (New Nil Int) String) ()\n\\end{verbatim}\n\nbut the state monad cannot accept a state that varies between statements. It is of course worthy of notice that the above sample, though as it is does not compile, is definitely not nonsensical. Whenever we have a larger state such as \n\\begin{verbatim}\nNew (New Nil Int) String\n\\end{verbatim}\n\nwe expect to be able to work with references that expect a smaller state, such as\n\\begin{verbatim}\nNew Nil Int\n\\end{verbatim}\n\nsince all that is needed for them to work is contained in the larger state, and through appropriate conversion both reading and writing on the smaller state can be performed on the larger state. The notion we will use to fix this problem happens to be that of coercive subtyping.\n", "meta": {"hexsha": "ba0d0a33ad1d34bf506fdeb24b13ffae691b3168", "size": 6841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Before Giuseppe's PhD/Monads/ObjectiveMonad/MonadicObjects prev/trunk/tex v2/mutable_instantiation.tex", "max_stars_repo_name": "vs-team/Papers", "max_stars_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-04-06T08:46:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-19T07:16:23.000Z", "max_issues_repo_path": "Before Giuseppe's PhD/Monads/ObjectiveMonad/MonadicObjects prev/trunk/tex v2/mutable_instantiation.tex", "max_issues_repo_name": "vs-team/Papers", "max_issues_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Before Giuseppe's PhD/Monads/ObjectiveMonad/MonadicObjects prev/trunk/tex v2/mutable_instantiation.tex", "max_forks_repo_name": "vs-team/Papers", "max_forks_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0348258706, "max_line_length": 279, "alphanum_fraction": 0.6776787019, "num_tokens": 1934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6841074575342282}}
{"text": "\\section{Method}\\label{sec: method}\n\nThe method for calibration considers the frames of the accelerometer and gyroscope as two non-orthogonal and misaligned frames, as illustrated in Figure \\ref{fig:axis}, and estimates a linear transformation from each sensor's frame to a common orthogonal one.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{figures/axis}\n\t\\caption{Accelerometer and Gyroscope axis are non orthogonal and misaligned.}\n\t\\label{fig:axis}\n\t\\source{Reproduced from \\cite{2014:Tedaldi}.}\n\\end{figure}\n\nIn other words, let $acc$ and $gyr$ be the accelerometer and gyroscope readings, the method estimates the scale $K_{3\\times 3}$, the skew $S_{3\\times 3}$ , and the bias $B_{3\\times 1}$ for both sensors, and the calibrated measures $acc^*$ and $gyr^*$  are computed as follows:\n\n\\begin{equation}\n\\begin{aligned}\nacc^* = K^aS^a(acc - B^a) \\\\ \ngyr^* = K^gS^g(gyr - B^g) \n\\end{aligned}\n\\end{equation}\n\n\\begin{important}\n\t\\begin{enumerate}\n\t\t\\item The $acc$ and $gyr$ readings given by the IMU are usually in their own scale. The conversion to S.I. is made intrinsically through the scale matrices $S^a$ and $S^g$.\n\t\t\\item The scale  $K$ is a diagonal matrix (only the $3$ diagonal elements are non-zero),  $S^a$ is a triangle upper matrix ( only the $3$ elements on the upper triangle are non-zero), and $S^g$ is a triangle upper and lower matrix (all the $6$ non-diagonal elements are non-zero).\n\t\\end{enumerate}\n\\end{important}\n\nThe first step is to calculate the calibration parameters for the accelerometer, which is done by optimizing:\n\n\\begin{equation}\\label{eq: acc opt}\n\t\\argmin_{K^a, S^a, B^a} (||g|| - ||K^aS^a(acc - B^a)||)^2\n\\end{equation}\n\nWhere $g$ is the local gravity, and the $acc$ measures used here belong to the static intervals of the data, which are automatically detected by the tool (more in Section \\ref{sec: data collection}).\n\nAfter the accelerometer is calibrated, the gyroscope is calibrated in two steps.\n\nFirst, $B^g$ is estimated by averaging the gyroscope measures in the initial static interval (see Section \\ref{sec: data collection}).\n%\nSecond, $K^g$ and $S^g$ are estimated by optimizing:\n\n\\begin{equation}\\label{eq: gyr opt}\n\t\\argmin_{K^g, S^g} \\left\\|(\\tilde{g}_{t_{i+1}}-\\tilde{g}_{t_i}) - \\int_{t_i}^{t_{i+1}} K^gS^g(gyr - B^g)dt\\right\\|\n\\end{equation}\n\nWhere $\\tilde{g}_{t_i}$ is the gravity versor at time $t_i$, meaning that the term $||\\tilde{g}_{t_{i+1}}-\\tilde{g}_{t_i})||$ is the angular displacement between to consecutive static intervals, and the integral calculates the angular displacement from the gyroscope readings.\n\n\\textbf{Important:}\n\\begin{important}\n\tErrors in the accelerometer's calibration will propagate to the gyroscope's calibration giver the later depend on the earlier. \n\\end{important}\n", "meta": {"hexsha": "fda8e168794b9d3fb8a246997ab94b61ef09a287", "size": 2791, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/tex/method.tex", "max_stars_repo_name": "event-driven-robotics/imu_tk2", "max_stars_repo_head_hexsha": "424111ceb7a63e7de53fee7b4c331313eaf63d4a", "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/tex/method.tex", "max_issues_repo_name": "event-driven-robotics/imu_tk2", "max_issues_repo_head_hexsha": "424111ceb7a63e7de53fee7b4c331313eaf63d4a", "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/tex/method.tex", "max_forks_repo_name": "event-driven-robotics/imu_tk2", "max_forks_repo_head_hexsha": "424111ceb7a63e7de53fee7b4c331313eaf63d4a", "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": 52.6603773585, "max_line_length": 282, "alphanum_fraction": 0.7341454676, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7826624688140728, "lm_q1q2_score": 0.6841074570775624}}
{"text": "\n\\subsection{Covariant derivative}\n\nEssentially as we move across path, we are changing the basis.\n\nWe can look at how basis vector change as we translate\n\nWe can define as basis as:\n\n\\(e_i=\\dfrac{\\delta x}{\\delta x_i}\\)\n\nHow to measure transport\n\nIf we take a vector and move it around a curved surface and return it to the same point, it may not face the same way\n\nEg if you're on equator, move east, north, south to equator, you'll face diffrent direction\n\nThis is true on smaller movements of a curved surface\n\nWe can use this to measure curvature of a manifold without coordinates \n\n\\subsection{New}\n\ncovariant derivative. how does change in field compare to parallel transport from curent position?\n\n\\(\\nabla_v (X)=\\lim_{t\\rightarrow 0}\\dfrac{X(p+tv)-X(p)}{t}\\)\n\nWe have point \\(p\\). We can compare how field in tangent space varies in direction of \\(v\\).\n\nwe don't define basis as each point, but rather how basis changes as you move along a curve\n\n", "meta": {"hexsha": "27faf5669fb0ab8dd178d0fcdfc7215bc64cb27c", "size": 956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/03-02-covariant.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/03-02-covariant.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/03-02-covariant.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.875, "max_line_length": 117, "alphanum_fraction": 0.7541841004, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6840260851291753}}
{"text": "\\paragraph{Two stage sampling procedure}\ncalled Stein's sampling procedure:\n\\begin{enumerate}\n  \\item take a preliminary sample of small size $n_0$\n  \n  $x_1, \\ldots, x_{n_0} \\rightarrow X_0 \\ \\longrightarrow \\ s^2_0 \\rightarrow s_0$\n  \n  \\item estimate how many more measurements you need:\n  \\begin{gather*}\n  n = \\lceil \\left( \\diststudentt^{[n_0-1]}_{1-\\alpha/2} \\frac{s_0}{d} \\right) \\rceil\n  \\end{gather*}\n  if $n > n_0$ then take the second sample of size $n-n_0$\n  \n\\end{enumerate}\n", "meta": {"hexsha": "f55b73a2100b4c3d33e3111ac9ea1fefe209ee9f", "size": 489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_6_planning.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_6_planning.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_6_planning.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6, "max_line_length": 85, "alphanum_fraction": 0.6932515337, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.684026073646835}}
{"text": "\\subsection{Dual Path Network (DPN)}\nThe general idea of DPN model \\cite{chen2017dual} can be described as\n\\begin{equation}\\label{eq:DPN}\n\\begin{cases}\nf^{1,0} &=R_{\\rm max}\\circ \\sigma \\circ \\theta^0(f), \\\\\n\\text{\\bf For} &\\ell = 1:J \\\\\n\\quad &\\text{\\bf For} \\quad i = 1:\\nu_\\ell \\\\\n&\\tilde{f}^{\\ell,i} = \\tilde{\\mathcal{H}}^{\\ell,i} \\left(  [f^{\\ell,0}, \\cdots, f^{\\ell,i-1}]  \\right), \n\\quad  \\bar{f}^{\\ell,i} = \\bar{\\mathcal{H}}^{\\ell,i} \\left([f^{\\ell,0}, \\cdots, f^{\\ell,i-1}] \\right),\\\\ \n&f^{\\ell,i} =  \\tilde f^{\\ell,i} +  \\bar f^{\\ell,i} \\\\\n\\quad &\\text{\\bf EndFor} \\\\\n&\\tilde f^{\\ell+1,0} =  \\tilde R_\\ell^{\\ell+1} ( f^{\\ell, \\nu_\\ell} ) ,  \\quad \\bar f^{\\ell+1,0} =  \\bar R_\\ell^{\\ell+1} ( f^{\\ell, \\nu_\\ell} ) ,\\\\\n&f^{\\ell,0} =  \\tilde f^{\\ell,0} +  \\bar f^{\\ell,0} \\\\\n\\text{\\bf End} &\\\\\nH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\\end{cases}\n\\end{equation}\n\nHere, if we take \n\\begin{equation}\n\\tilde{\\mathcal{H}}^{\\ell,i} =  \\bar{\\mathcal{H}}^{\\ell,i},\n\\end{equation}\nwith some special forms such as classical CNN or ResNet, this is\nsimilar to the trick in AlexNet.\n\nIn DPN, the trick is to take different forms for $\\tilde{\\mathcal{H}}^{\\ell,i} $ and $ \\bar{\\mathcal{H}}^{\\ell,i}$.\nFor example, they take\n\\begin{equation}\\label{eq:DPN-1}\n\\tilde{\\mathcal{H}}^{\\ell,i} \\left(  [f^{\\ell,0}, \\cdots, f^{\\ell,i-1}]  \\right) = \\sigma( f^{\\ell,i-1} + \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i}(f^{\\ell,i-1})),\n\\end{equation}\nand \n\\begin{equation}\\label{eq:DPN-2}\n\\bar{\\mathcal{H}}^{\\ell,i} \\left(  [f^{\\ell,0}, \\cdots, f^{\\ell,i-1}]  \\right) = \\sigma \\left( \\sum_{j=0}^{i-1} [\\theta^{\\ell,i}]_{j} f^{\\ell,j} \\right)\n\\end{equation}\nin original DPN paper.\nHere we need to mention that, equation \\eqref{eq:DPN-1} mens that $\\tilde f^{\\ell,i}$ follows the\nprocess of ResNet structure and equation \\eqref{eq:DPN-2} mens that $\\bar f^{\\ell,i}$ follows the\nprocess of DenseNet structure. That is to say, DPN is some special combination of these two models.\n\n\\paragraph{The connection to MgNet}\nFirst, we can make a extended version for DPN as:\n\\begin{equation}\\label{eq:DPN}\n\\begin{cases}\nf^{1,0} &=R_{\\rm max}\\circ \\sigma \\circ \\theta^0(f), \\\\\n\\text{\\bf For} &\\ell = 1:J \\\\\n\\quad &\\text{\\bf For} \\quad i = 1:\\nu_\\ell \\\\\n&\\tilde{f}^{\\ell,i} = \\tilde{\\mathcal{H}}^{\\ell,i} \\left(  f^{\\ell,i-1} \\right), \n\\quad  \\bar{f}^{\\ell,i} = \\bar{\\mathcal{H}}^{\\ell,i} \\left( f^{\\ell,i-1} \\right),\\\\ \n&f^{\\ell,i} =  \\red{[\\tilde f^{\\ell,i} ,\\bar f^{\\ell,i}]}\\\\\n\\quad &\\text{\\bf EndFor} \\\\\n&\\tilde f^{\\ell+1,0} =  \\tilde R_\\ell^{\\ell+1} ( f^{\\ell, \\nu_\\ell} ) ,  \\quad \\bar f^{\\ell+1,0} =  \\bar R_\\ell^{\\ell+1} ( f^{\\ell, \\nu_\\ell} ) ,\\\\\n&f^{\\ell,0} =  \\tilde f^{\\ell,0} +  \\bar f^{\\ell,0} \\\\\n\\text{\\bf End} &\\\\\nH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\\end{cases}\n\\end{equation}\nThen, we can take some special form of $ \\tilde{\\mathcal{H}}$,\n$\\bar{\\mathcal{H}}^{\\ell,i}$, $\\tilde R_\\ell^{\\ell+1}$ and $ \\bar R_\\ell^{\\ell+1}$\nto connect our MgNet. \n\\begin{itemize}\n\\item recover $u^{\\ell,i}$ for $i = 1:\\nu_\\ell$\n\\begin{equation}\n\\blue{\\tilde f^{\\ell,i}} = \\tilde{\\mathcal{H}}^{\\ell,i} \\left(  f^{\\ell,i-1} \\right) = \\tilde{\\mathcal{H}}^{\\ell,i} \\left(  [\\tilde f^{\\ell,i} ,\\bar f^{\\ell,i}] \\right) = \n\\blue{\\tilde f^{\\ell,i-1} + B_{\\ell,i}  ({\\bar f^{\\ell,i} -  A^{\\ell} (\\tilde f^{\\ell,i-1})})},\n\\end{equation}\n\\item recover $f^{\\ell}$\n\\begin{equation}\n\\blue{\\bar f^{\\ell,i}} = \\bar{\\mathcal{H}}^{\\ell,i} \\left(  f^{\\ell,i-1} \\right) = \\bar{\\mathcal{H}}^{\\ell,i} \\left(  [\\tilde f^{\\ell,i} ,\\bar f^{\\ell,i}] \\right) = \n\\blue{\\bar f^{\\ell,i-1}} ,\n\\end{equation}\n\\item recover $u^{\\ell,0}$\n\\begin{equation}\n\\blue{\\tilde f^{\\ell+1,0}} = \\tilde f^{\\ell+1,0} =  \\tilde R_\\ell^{\\ell+1} ( f^{\\ell, \\nu_\\ell} ) = \\tilde f^{\\ell+1,0} =  \n\\tilde R_\\ell^{\\ell+1} ( [\\tilde f^{\\ell,\\nu_\\ell} ,\\bar f^{\\ell,\\nu_\\ell}]  )  = \\blue{\\Pi_\\ell^{\\ell+1} \\tilde f^{\\ell,\\nu_\\ell}},\n\\end{equation}\n\\item recover $f^{\\ell+1}$\n\\begin{equation}\n\\begin{aligned}\n\\blue{\\bar f^{\\ell+1,0}} =  \\bar R_\\ell^{\\ell+1} ( f^{\\ell, \\nu_\\ell} ) \n&=  \\bar R_\\ell^{\\ell+1} ( [\\tilde f^{\\ell,\\nu_\\ell} ,\\bar f^{\\ell,\\nu_\\ell}]  ),  \\\\\n&= \\blue{R^{\\ell+1}_\\ell( \\bar f^{\\ell,\\nu_\\ell} - A^\\ell(\\tilde f^{\\ell,\\nu_\\ell})) + A^{\\ell+1} (\\Pi_\\ell^{\\ell+1} \\tilde f^{\\ell,\\nu_\\ell})},\\\\\n&= \\blue{R^{\\ell+1}_\\ell( \\bar f^{\\ell,\\nu_\\ell} - A^\\ell(\\tilde f^{\\ell,\\nu_\\ell})) + A^{\\ell+1} (\\tilde f^{\\ell+1,0})}. \\\\\n\\end{aligned}\n\\end{equation}\n\\end{itemize}\nThis means that, we can connect the MgNet and DPN with the next relationship:\n\\begin{equation}\nu^{\\ell,i} = \\tilde f^{\\ell,i}, \\quad i = 0:\\nu_\\ell, \\quad \\ell = 1:J,\n\\end{equation}\nand\n\\begin{equation}\nf^{\\ell} = \\bar f^{\\ell,i},  \\quad i = 0:\\nu_\\ell, \\quad \\ell = 1:J.\n\\end{equation}\n\nThus to say, we may give a better explanation for DPN from the viewpoint of MgNet.\nFurthermore, we give some further developments version of DPN by involving more\nstructure from MgNet like what we are doing for ResNet and iResNet.\n\n", "meta": {"hexsha": "e5778d1d3112e69f413ebead703b17247b73dfa4", "size": 4924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_DPN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/mgnet_DPN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/mgnet_DPN.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.7373737374, "max_line_length": 171, "alphanum_fraction": 0.5844841592, "num_tokens": 2160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6840260721004229}}
{"text": "\\lab{Total Variation and Image Processing}{Total Variation and Image Processing}\n\\label{lab:tv_images}\n\\objective{Minimizing an energy functional is equivalent to solving the resulting Euler-Lagrange equations.  We introduce the method of steepest descent to solve these equations, and apply this technique to a denoising problem in image processing.}\n\n\n\n% \\begin{enumerate}\n% \\item Algorithm assumes smoothness.\n% Other theorems/algorithms have been developed using convex analysis, due to the recognition that the image might not be best represented by a smooth function $u:[0,1]\\times [0,1] \\to \\mathbb{R}$.\n% \\item Analyze efficiency.\n% Code with cython/numexpr?\n% \\end{enumerate}\n\n\\section*{The Gradient Descent method}\nConsider an energy functional $J[u]$, defined over a collection of admissible functions $u:\\Omega \\subset \\mathbb{R}^n \\to \\mathbb{R}$, with the form\n\\[J[u] = \\int_{\\Omega} L(x,u,\\nabla u) \\, dx\\]\nwhere $L = L(x,u,\\nabla u)$ is a function $\\mathbb{R}^n \\times \\mathbb{R} \\times \\mathbb{R}^n \\to \\mathbb{R}$.\nA standard result from the calculus of variations states that a minimizing function $u^*$ satisfies the Euler-Lagrange equation\n\\begin{align}\nL_u-\\sum_{i=1}^n\\frac{\\partial L_{u_{x_i}}}{\\partial x_i}=L_u-\\nabla\\cdot L_{\\nabla u}=L_u - {\\rm div}\\,(L_{\\nabla u}) &= 0.    \\label{EL:multivar_domain}\n\\end{align}\nwhere $L_{\\nabla u} = \\nabla^\\prime L = [L_{x_1},\\hdots,L_{x_n}]^\\intercal$.\n\nThis equation is typically an elliptic PDE, possessing boundary conditions associated with  restrictions on the class of admissible functions $u$.\nTo more easily compute $\\eqref{EL:multivar_domain}$, we consider a related parabolic PDE,\n\\begin{align}\n    \\begin{split}\n    &{ } u_t = -(L_y - {\\rm div}\\, L_{\\nabla u}), \\quad t > 0,\\\\\n    &{ } u(x,0) = u_0(x), \\quad t = 0.\n    \\end{split} \\label{grad_desc_pde}\n\\end{align}\nA steady state solution of \\eqref{grad_desc_pde} does not depend on time, and thus solves the Euler-Lagrange equation.\nIt is often easier to evolve an initial guess using \\eqref{grad_desc_pde}, and stop whenever its steady state is well-approximated, than to solve \\eqref{EL:multivar_domain} directly.\n\n\\begin{example}\nConsider the energy functional\n\\[ J[u] = \\int_{\\Omega} \\|\\nabla u\\|^2 \\, dx.\\]\n% where the class of admissible functions $u$ satisfy appropriate Dirichlet conditions on $\\partial \\Omega$.\nThe minimizing function $u^*$ satisfies the Euler-Lagrange equation\n\\[-{\\rm div}\\, \\nabla u    = - \\triangle u = 0.\\]\nThe gradient descent flow is the well-known heat equation\n\\[u_t = \\triangle u.\\]\n\\end{example}\n\nThe Euler-Lagrange equation could equivalently be described as $\\triangle u = 0$, leading to the PDE $u_t = -\\triangle u$.\nSince the backward heat equation is ill-posed, it would not be helpful in a search for the steady-state.\n\nLet us take the time to make \\eqref{grad_desc_pde} more rigorous.\nWe recall that\n\\begin{align*}\n        \\delta J(u;h) &= \\left.\\frac{d}{dt}J(u + \\epsilon h)\\right|_{\\epsilon=0},\\\\\n        &= \\int_{\\Omega} (L_y(u) - {\\rm div}\\, L_{\\nabla u}(u)) h\\, dx,\\\\\n        &= \\langle L_y(u) - {\\rm div}\\, L_{\\nabla u}(u), h \\rangle_{L^2(\\Omega)},\n\\end{align*}\nfor each $u$ and each admissible perturbation $h$.\nThen using the Cauchy-Schwarz inequality,\n\\begin{align*}\n    |\\delta J(u;h)| &\\leq \\|L_y(u) - {\\rm div}\\, L_{\\nabla u}(u)\\| \\cdot \\| h \\|\n\\end{align*}\nwith equality iff $h =\\alpha(L_y(u) - {\\rm div}\\, L_{\\nabla u}(u))$ for some $\\alpha \\in \\mathbb{R}$.\nThis implies that the ``direction''\n$h = L_y(u) - {\\rm div}\\, L_{\\nabla u}(u)$ is the direction of steepest ascent and\nmaximizes $\\delta J(u;h)$.\nSimilarly,\n\\[h = -(L_y(u) - {\\rm div}\\, L_{\\nabla u}(u))\\]\n points in the direction of steepest descent, and the flow described by \\eqref{grad_desc_pde} tends to move toward a state of lesser energy.\n\n\n\\subsection*{Minimizing the area of a surface of revolution}\nThe area of the surface obtained by revolving a curve $y(x)$ about the $x$-axis is\n\\[A[y] = \\int_a^b 2 \\pi y \\sqrt{1 + (y')^2} \\, dx.\n\\]\nTo minimize the functional $A$ over the collection of smooth curves with fixed end points $y(a) = y_a$, $y(b) = y_b$, we use the Euler-Lagrange equation\n\\begin{align}\n    \\begin{split}\n    0 &= 1 - y \\frac{y''}{1 + (y')^2} , \\\\\n    &= 1 + (y')^2 - y y'',\n    \\end{split}\\label{tv_images:SA_EL_equation}\n\\end{align}\nwith the gradient descent flow given by\n\\begin{align}\n    \\begin{split}\n    &{ } u_t = -1 - (y')^2 + y y'',\\quad t > 0,\\, x \\in (a,b), \\\\\n    &{ } u(x,0) = g(x), \\quad t = 0,\\\\\n    &{ } u(a,t) = y_a, \\quad u(b,t) = y_b.\n    \\end{split}\\label{tv_images:SA_flow}\n\\end{align}\n\n\\subsection*{Numerical Implementation}\nWe will construct a numerical solution of \\eqref{tv_images:SA_flow} using the conditions $y(-1) = 1$, $y(1) = 7$.\nA simple solution can be found by using a second-order order discretization in space  with a simple forward Euler step in time. We create the grid and set our end states below.\n\\begin{lstlisting}\nimport numpy as np\n\na, b = -1, 1.\nalpha, beta = 1., 7.\n####  Define variables x_steps, final_T, time_steps  ####\ndelta_t, delta_x = final_T/time_steps, (b-a)/x_steps\nx0 = np.linspace(a,b,x_steps+1)\n\\end{lstlisting}\n\nMost numerical schemes have a stability condition that must be satisfied. Our discretization requires that $\\frac{\\triangle t}{(\\triangle x)^2} \\leq \\frac{1}{2}$.\nWe continue by checking that this condition is satisfied, and use the straight line connecting the end points as initial data.\n\n\\begin{lstlisting}\n# Check a stability condition for this numerical method\nif delta_t/delta_x**2. > .5:\n    print \"stability condition fails\"\n\nu = np.empty((2,x_steps+1))\nu[0]  = (beta - alpha)/(b-a)*(x0-a)  + alpha\nu[1] = (beta - alpha)/(b-a)*(x0-a)  + alpha\n\\end{lstlisting}\n\nFinally, we define the right hand side of our difference scheme, and time step until the scheme converges.\n\\begin{lstlisting}\ndef rhs(y):\n    # Approximate first and second derivatives to second order accuracy.\n    yp = (np.roll(y,-1) - np.roll(y,1))/(2.*delta_x)\n    ypp = (np.roll(y,-1) - 2.*y + np.roll(y,1))/delta_x**2.\n    # Find approximation for the next time step, using a first order Euler step\n    y[1:-1] -= delta_t*(1. + yp[1:-1]**2. - 1.*y[1:-1]*ypp[1:-1])\n\n\n# Time step until successive iterations are close\niteration = 0\nwhile iteration < time_steps:\n    rhs(u[1])\n    if norm(np.abs((u[0] - u[1]))) < 1e-5: break\n    u[0] = u[1]\n    iteration+=1\n\nprint \"Difference in iterations is \", norm(np.abs((u[0] - u[1])))\nprint \"Final time = \", iteration*delta_t\n\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{min_surface_area.pdf}\n\\caption{The solution of \\eqref{tv_images:SA_EL_equation}, found using the gradient descent flow \\eqref{tv_images:SA_flow}.}\n\\label{fig:tv_images:SA_image}\n\\end{figure}\n\n\\begin{problem}\nUsing $20$ $x$ steps, $250$ time steps, and a final time of $.2$, plot the solution that minimizes \\eqref{tv_images:SA_flow}.\nIt should match figure \\ref{fig:tv_images:SA_image}.\n\n\\end{problem}\n\n\\section*{Image Processing: Denoising}\n\nA greyscale image can be represented by a scalar-valued function $u:\\Omega \\to \\mathbb{R}$, $\\Omega \\subset \\mathbb{R}^2$. The following code reads an image into an array of floating point numbers, adds some noise, and saves the noisy image.\n\\begin{lstlisting}\nfrom numpy.random import random_integers, uniform, randn\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm\nfrom imageio import imread, imwrite\n\nimagename = 'baloons_resized_bw.jpg'\nchanged_pixels=40000\n# Read the image file imagename into an array of numbers, IM\n# Multiply by 1. / 255 to change the values so that they are floating point\n# numbers ranging from 0 to 1.\nIM = imread(imagename, as_gray=True) * (1. / 255)\nIM_x, IM_y = IM.shape\n\nfor lost in xrange(changed_pixels):\n    x_,y_ = random_integers(1,IM_x-2), random_integers(1,IM_y-2)\n    val =  .1*randn() + .5\n    IM[x_,y_] = max( min(val,1.), 0.)\nimwrite(\"noised_\"+imagename, IM)\n\\end{lstlisting}\nA color image can be represented by three functions $u_1, u_2,$ and $u_3$. In this lab we will work with black and white images, but total variation techniques can easily be used on more general images.\n\n\\subsection*{A simple approach to image processing}\nHere is a first attempt at denoising: given a noisy image $f$, we look for a denoised image $u$ minimizing the energy functional\n\\begin{align}\nJ[u] = \\int_{\\Omega} L(x,u,\\nabla u) \\, dx, \\label{tv_images:diffusion}\n\\end{align}\nwhere\n\\begin{align*}\nL(x,u,\\nabla u) &= \\frac{1}{2}(u-f)^2 + \\frac{\\lambda}{2} | \\nabla u|^2,\\\\\n&= \\frac{1}{2}(u-f)^2 + \\frac{\\lambda}{2} (u_x^2 + u_y^2)^2.\n\\end{align*}\nThis energy functional penalizes 1) images that are too different from the original noisy image, and 2) images that have large derivatives. The minimizing denoised image $u$ will balance these two different costs.\n\nSolving for the original denoised image $u$ is a difficult inverse problem-some information is irretrievably lost when noise is introduced. However, a priori information can be used to guess at the structure of the original image.  For example, here $\\lambda$ represents our best guess on how much noise was added to the image, and is known as a regularization parameter in inverse problem theory.\n\nThe Euler-Lagrange equation corresponding to \\eqref{tv_images:diffusion} is\n\\begin{align*}\nL_u - \\text{div } L_{\\nabla u} &= (u-f) - \\lambda \\triangle u,\\\\\n&= 0.\n\\end{align*}\nand the gradient descent flow is\n\\begin{align}\n    \\begin{split}\nu_t &= -(u-f -\\lambda \\triangle u),\\\\\nu(x,0) &= f(x).\n    \\end{split} \\label{tv_images:diffusion_flow}\n\\end{align}\n\nLet $u_{ij}^n$ represent our approximation to $u(x_i,y_j)$ at time $t_n$. We will approximate $u_t$ with a forward Euler difference, and $\\triangle u$ with centered differences:\n\\begin{align*}\n    u_t &\\approx \\frac{u_{ij}^{n+1}-u_{ij}^n}{\\triangle t},\\\\\n    u_{xx} &\\approx \\frac{u_{i+1,j}^{n}-2u_{ij}^n + u_{i-1,j}^n}{\\triangle x^2}, \\\\\n    u_{yy} &\\approx \\frac{u_{i,j+1}^{n}-2u_{ij}^n + u_{i,j-1}^n}{\\triangle y^2}.\n\\end{align*}\n\n\n\\begin{problem}\nUsing $\\triangle t = 1e{-3},$ $\\lambda = 40,$ $\\triangle x = 1,$ and $\\triangle y = 1$, implement the numerical scheme mentioned above to obtain a solution $u$. (So $\\Omega = [0,n_x]\\times [0,n_y]$, where $n_x$ and $n_y$ represent the number of pixels in the $x$ and $y$ dimensions, respectively.) Take 250 steps in time. Compare your results with Figure \\ref{fig:noise_compare_attempts}.\n\nHint: Use the function \\li{np.roll} to compute the spatial derivatives. For example, the second derivative can be approximated at interior grid points using\n\\begin{lstlisting}\nu_xx = np.roll(u,-1,axis=1) - 2*u + np.roll(u,1,axis=1)\n\\end{lstlisting}\n\\end{problem}\n\n\n\n\n% diffusion_denoised_baloons_resized_bw.jpg\n% \\begin{lstlisting}\n% delta_t = 1e-3\n% lmbda = 40\n% u = np.empty((2,IM_x,IM_y))\n% u[1] = IM\n%\n% def laplace(z):\n%     # Approximate first and second derivatives to second order accuracy.\n%     z_xx = (np.roll(z,-1,axis=0) - 2.*z + np.roll(z,1,axis=0))#/delta_x**2.\n%     z_yy = (np.roll(z,-1,axis=1) - 2.*z + np.roll(z,1,axis=1))#/delta_y**2.\n%     # Find approximation for the next time step, using a first order Euler step\n%     z[1:-1,1:-1] -= delta_t*(   (z[1:-1,1:-1]-IM[1:-1,1:-1])\n%                                     -lmbda*(z_xx[1:-1,1:-1] + z_yy[1:-1,1:-1]))\n%\n% # Iterate towards a steady state solution of the gradient descent flow.\n% iteration = 0\n% while iteration < time_steps:\n%     laplace(u[1])\n%     if norm(np.abs((u[0] - u[1]))) < 1e-4: break\n%     u[0] = u[1]\n%     iteration+=1\n%\n% \\end{lstlisting}\n\\begin{figure}\n\\begin{minipage}[b]{.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{balloons_resized_bw.jpg}\n\\caption*{Original image}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{lab_noised_baloons_resized_bw.jpg}\n\\caption*{Image with white noise}\n\\end{minipage}\n\\caption{Noise.}\n\\label{fig:noise_firstattempt}\n\\end{figure}\n\n\\begin{figure}\n\\begin{minipage}[b]{.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{diffusion_denoised_baloons_resized_bw.jpg}\n\\caption*{Initial diffusion-based approach}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{tv_denoised_baloons_resized_bw.jpg}\n\\caption*{Total variation based approach}\n\\end{minipage}\n\\caption{The solutions of \\eqref{tv_images:diffusion_flow} and \\eqref{tv_images:tv_flow}, found using a first order Euler step in time and centered differences in space.}\n\\label{fig:noise_compare_attempts}\n\\end{figure}\n\n% \\begin{figure}\n% \\centering\n% \\includegraphics[width=6cm]{diffusion_denoised_baloons_resized_bw.jpg}\n% \\caption{The solution of \\eqref{tv_images:diffusion_flow}, found using a first order Euler step in time and centered differences in space.}\n% \\label{fig:diffusion_image_denoised}\n% \\end{figure}\n\n\\section*{Image Processing: Total Variation Method}\nWe represent an image by a function $u:[0,1]\\times[0,1] \\to \\mathbb{R}$.\nA $C^1$ function $u:\\Omega \\to \\mathbb{R}$ has bounded total variation on $\\Omega$ ($BV(\\Omega)$) if $\\int_{\\Omega} |\\nabla u| < \\infty$; $u$ is said to have total variation $\\int_{\\Omega} |\\nabla u|$.  Intuitively, the total variation of an image $u$ increases when noise is added.\n\nThe total variation approach was originally introduced by Ruding, Osher, and Fatemi\\footnote{L. Rudin, S. Osher, and E. Fatemi, ``Nonlinear total variation based noise removal algorithms'', \\emph{Physica D.}, 1992.}. It was formulated as follows: given a noisy image $f$, we look to find a denoised image $u$ minimizing\n\\begin{align}\n\\int_{\\Omega} |\\nabla u(x)|\\, dx \\label{tv_images:tv}\n\\end{align}\nsubject to the constraints\n\\begin{align}\n    &{ } \\int_{\\Omega} u(x) \\, dx = \\int_{\\Omega} f(x)\\, dx, \\label{tv_images:same_mean}\\\\\n    &{ } \\int_{\\Omega} |u(x) - f(x)|^2\\, dx = \\sigma |\\Omega|.\\label{tv_images:aprior_variance}\n\\end{align}\nIntuitively, \\eqref{tv_images:tv} penalizes fast variations in $f$ - this functional together with the constraint \\eqref{tv_images:same_mean} has a constant minimum of $u = \\frac{1}{|\\Omega|}\\int_{\\Omega} u(x) \\, dx$. This is obviously not what we want, so we add a constraint \\eqref{tv_images:aprior_variance} specifying how far $u(x)$ is required to differ from the noisy image $f$.  More precisely, \\eqref{tv_images:same_mean} specifies that the noise in the image has zero mean, and \\eqref{tv_images:aprior_variance} requires that a variable $\\sigma$ be chosen a priori to represent the standard deviation of the noise.\n\n\n\nChambolle and Lions proved that the model introduced by Rudin, Osher, and Fatemi can be formulated equivalently as\n\\begin{align}\nF[u] = \\min_{u \\in BV(\\Omega)} \\int_{\\Omega} |\\nabla u| + \\frac{\\lambda}{2}(u-f)^2 \\, dx,\n\\end{align}\nwhere $\\lambda >0$ is a fixed regularization parameter\\footnote{A. Chambelle and P.-L. Lions, ``Image recovery via total variation minimization and related problems\", \\emph{Numer. Math.}, 1997.}. Notice how this functional differs from \\eqref{tv_images:diffusion}: $\\int_{\\Omega} |\\nabla u|$ instead of $\\int_{\\Omega} |\\nabla u|^2$. This turns out to cause a huge difference in the result.  Mathematically, there is a nice way to extend $F$ and the class of functions with bounded total variation to functions that are discontinuous across hyperplanes. The term $\\int |\\nabla|$ tends to preserve edges/boundaries of objects in an image.\n\n\n% The Euler-Lagrange equation is\n% \\begin{align*}\n% \\lambda (u-f) - \\frac{u_{xx}u_y^2 + u_{yy}u_x^2 - 2u_xu_yu_{xy}}{(u_x^2 + u_y^2)^{3/2}} &= 0.\n% \\end{align*}\nThe gradient descent flow is given by\n\\begin{align}\n    \\begin{split}\nu_t &= -\\lambda (u-f) + \\frac{u_{xx}u_y^2 + u_{yy}u_x^2 - 2u_xu_yu_{xy}}{(u_x^2 + u_y^2)^{3/2}} ,\\\\\nu(x,0) &= f(x).\n\\end{split} \\label{tv_images:tv_flow}\n\\end{align}\nNotice the singularity that occurs in the flow when $|\\nabla u| = 0$. Numerically we will replace  $|\\nabla u|^{3}$ in the denominator with $(\\epsilon + |\\nabla u|^{2})^{3/2}$, to remove the singularity.\n\n\n\\begin{problem}\nUsing $\\triangle t = 1e-3, \\lambda = 1, \\triangle x = 1,$ and $ \\triangle y = 1$, implement the numerical scheme mentioned above to obtain a solution $u$.  Take 200 steps in time. Compare your results with Figure \\ref{fig:noise_compare_attempts}. How small should $\\epsilon$ be?\n\nHint: To compute the spatial derivatives, consider the following:\n\\begin{lstlisting}\nu_x = (np.roll(u,-1,axis=1) -  np.roll(u,1,axis=1))/2\nu_xx = np.roll(u,-1,axis=1) - 2*u + np.roll(u,1,axis=1)\nu_xy = (np.roll(u_x,-1,axis=0) - np.roll(u_x,1,axis=0))/2.\n\\end{lstlisting}\n\\end{problem}\n\n\n% \\begin{figure}\n% \\centering\n% \\includegraphics[width=6cm]{tv_denoised_baloons_resized_bw.jpg}\n% \\caption{The solution of \\eqref{tv_images:diffusion_flow}, found using a first order Euler step in time and centered differences in space.}\n% \\label{fig:tv_image_denoised}\n% \\end{figure}\n", "meta": {"hexsha": "ec9d8fb7765f47fcb66d36e258a4e386f7e4dbb2", "size": 16864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/TotalVariation/TotalVariation.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume4/TotalVariation/TotalVariation.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume4/TotalVariation/TotalVariation.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.4545454545, "max_line_length": 636, "alphanum_fraction": 0.7016722011, "num_tokens": 5393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.683998430714963}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath,amsfonts}\n\n\\begin{document}\n\n\\section{If $\\mathscr{H}$ is a Hilbert space, $\\mathscr{A}=\\mathscr{B}(\\mathscr{H} )$ is a C*-algebra where for each A in $\\mathscr{B}(\\mathscr{H} )$, A*=the adjoint of A}\n\nVIII.1.1 (pg 236)\n\n$\\langle Ah, k \\rangle = \\langle h, A^*k \\rangle = \\overline{ \\langle A^*k,h \\rangle}$\n\n$\\langle A^*k, h \\rangle = \\langle k, A^{**}h \\rangle = \\overline{\\langle A^{**}h,k \\rangle}$\n\nThe above are justified by the definition of the adjoint and inner product, for all values h and k in $\\mathscr{H}$.\n\nTaking the complex conjugate of the bottom row shows that $\\langle Ah, k \\rangle = \\langle A^{**}h,k \\rangle$, hence A=A**.\n\n$\\langle (AB)^*h, k \\rangle = \\langle h, (AB)k \\rangle = \\langle h, A(B(k)) \\rangle = \\langle A^* h, B k \\rangle = \\langle B^*A^*h,k \\rangle$\n\nHence, $(AB)^* = B^*A^*$\n\n$\\langle (\\alpha A + B)^*h,k \\rangle = \\langle h, (\\alpha A + B) k \\rangle = \\langle h, \\alpha A k + B k \\rangle$\n\n$\\langle \\bar{\\alpha}A^*h+B^*h, k \\rangle$ (kind of ran out of steam by this point)\n\n\n\\section{If X is a compact Hausdorff space, show that X is totally disconnected if and only if C(X) is the closed linear span of its projections ($\\equiv$ hermitian idempotents)}\n\nVIII.2.3 (pg 239)\n\nAssume $X$ is totally disconnected. Consider a bounded function $f$. Ignoring net vs sequence issues (TODO: is this justified?), we must show that $f$ can be written as the convergence of $a_1 e_1 + a_2 e_2 + ... $ where $a_n \\in \\mathbb{C}$ and $e_n$ are hermitian idempotents.\n\nIn this context, a hermitian idempotent is one whose range is $\\{0,1\\}$, since those are the only complex numbers equal to their own square. Consider a series of function $e_{q_1}, e_{q_2}$, where for each ${q_i} \\in X$, define\n\n\\begin{equation*}\ne_{q_i}(x)= \\left\\{\n        \\begin{array}{ll}\n            1 & \\quad x = q_i \\\\\n            0 & \\quad x \\ne q_i\n        \\end{array}\n    \\right.\n\\end{equation*}\n\n$f$ can therefore be written as a countably infinite linear sum of such a series, thus is in the closed linear span of the projections.\n\nHm, I didn't use the fact that $X$ is totally disconnected so something is missing here.\n\n\\end{document}\n", "meta": {"hexsha": "97f6431791a6e3ab55c68f2a3ab709819f6d8948", "size": 2207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/8_C_star_Algebras/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/8_C_star_Algebras/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/8_C_star_Algebras/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": 44.14, "max_line_length": 278, "alphanum_fraction": 0.664703217, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6839858666751364}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\\usepackage[left=2.0cm,right=2cm,top=2cm,bottom=2cm]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{graphicx}\n\\newenvironment{packed_enum}{\n\\begin{itemize}\n  \\setlength{\\topsep}{0pt}\n  \\setlength{\\itemsep}{0pt}\n  \\setlength{\\parskip}{0pt}\n  \\setlength{\\parsep}{0pt}\n  \\setlength{\\partopsep}{0pt}\n}{\\end{itemize}}\n\\begin{document}\n\\section*{Simple model for $\\textrm{R}_{0}$}\n\\begin{eqnarray*}\n\\textrm{j}(\\textrm{t})&=&\\int_{0}^{\\infty}\\textrm{A}(\\tau)\\textrm{j}(\\textrm{t}-\\tau)d\\tau \\\\\n\\textrm{R}_{0}&=&\\int_{0}^{\\infty}\\textrm{A}(\\tau)d\\tau\n\\end{eqnarray*}\nWhere\n\\begin{packed_enum}\n\\item j(t) is the number of new infections at time t\n\\item A($\\tau$) is the rate an infected person infects a healthy person at time $\\tau$ after infection\n\\item $\\textrm{R}_{0}$ is the total number of new infections resulting from an infected person\n\\end{packed_enum}\nIf we assume the infection rate is constant for a number of consecutive days (w) following infection then\n\\begin{eqnarray*}\n\\textrm{j}(\\textrm{t})&=&\\textrm{A}(\\textrm{t})\\int_{0}^{\\textrm{w}}\\textrm{j}(\\textrm{t}-\\tau)d\\tau \\\\\n\\textrm{R}_{0}(\\textrm{t})&=&\\textrm{w}\\:\\textrm{A}(\\textrm{t})\n\\end{eqnarray*}\nSo\n\\begin{equation*}\n\\textrm{R}_{0}(\\textrm{t})=\\textrm{w}\\:\\frac{\\textrm{j}(\\textrm{t})}{\\int_{0}^{\\textrm{w}}\\textrm{j}(\\textrm{t}-\\tau)d\\tau}\n\\end{equation*}\nApproximated as\n\\begin{eqnarray*}\n\\textrm{R}_{0}(\\textrm{t})&=&\\textrm{w}\\:\\frac{\\textrm{j}(\\textrm{t})}{\\textrm{s}(\\textrm{t})} \\\\\n\\textrm{s}(\\textrm{t})&=&\\sum_{\\tau=0}^{\\tau=\\textrm{w}}\\textrm{j}(\\textrm{t}-\\tau)\n\\end{eqnarray*}\n\\end{document}\n", "meta": {"hexsha": "0de8945b1c206a6d0c06dac6977e25a62ec2a664", "size": 1626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/model.tex", "max_stars_repo_name": "hammonda/covid19", "max_stars_repo_head_hexsha": "1fad1e8b062eb977e8e0ec4dd6663dd2e20fc462", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-14T22:35:43.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T22:35:43.000Z", "max_issues_repo_path": "docs/model.tex", "max_issues_repo_name": "hammonda/covid19", "max_issues_repo_head_hexsha": "1fad1e8b062eb977e8e0ec4dd6663dd2e20fc462", "max_issues_repo_licenses": ["MIT"], "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": "hammonda/covid19", "max_forks_repo_head_hexsha": "1fad1e8b062eb977e8e0ec4dd6663dd2e20fc462", "max_forks_repo_licenses": ["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.6585365854, "max_line_length": 123, "alphanum_fraction": 0.6857318573, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6839858654504}}
{"text": "\\section{Control Flow Becomes Data Flow}\n\\label{controlflowtodataflow}\n\nConditional expressions negatively impact execution speed, even in\ncontemporary computer architectures, so compiler (and interpreter) \nwriters attempt to eliminate them, whenever that is feasible.\nBoolean arrays facilitate the replacement of control flow by\ndata flow, frequently improving performance as a result of \neliminating conditionals.\\cite{DBLP:conf/pldi/BerneckyS15}\nFor example, if we want to give everyone whose salary, \n{\\apl s}, is less than {\\apl tiny},\na raise of {\\apl r}, it can be done this way in parallel, \nwithout resorting to scalar-oriented control flow constructs\nsuch as {\\tt if/then/else}: \n\n\\medskip\n{\\apl s\\qlarrow\\0s\\qplus\\0r\\qtimes\\0s\\qlt\\0tiny}\n\\medskip\n\n\\noindent This terse and expressive ability arises directly from\nwhat Knuth calls {\\em Iverson's convention for characteristic functions}, \nof treating Boolean true and false as the integers {\\apl 1} and {\\apl 0}, \nrespectively.\nOther examples include the verb {\\apl mqs}, to mark the \nquoted strings within a text vector, given in Section~\\ref{reduceandscan},\nand the (mostly) SIMD tokenizer for the \nAPEX APL compiler.~\\cite{RBernecky:apex,RBernecky:tokenizer}\n\n\n", "meta": {"hexsha": "bedb7bf89b9af9980305d2e72254ebf2c25f99ff", "size": 1224, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/LatexTemplate/BooleanSIMD/controlflow.tex", "max_stars_repo_name": "bernecky/apex", "max_stars_repo_head_hexsha": "cee572d7a1a52f46d35ba47c64e6363acdd69ee8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:17:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T04:17:56.000Z", "max_issues_repo_path": "Docs/LatexTemplate/BooleanSIMD/controlflow.tex", "max_issues_repo_name": "bernecky/apex", "max_issues_repo_head_hexsha": "cee572d7a1a52f46d35ba47c64e6363acdd69ee8", "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/LatexTemplate/BooleanSIMD/controlflow.tex", "max_forks_repo_name": "bernecky/apex", "max_forks_repo_head_hexsha": "cee572d7a1a52f46d35ba47c64e6363acdd69ee8", "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.8, "max_line_length": 74, "alphanum_fraction": 0.7875816993, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6839858584331711}}
{"text": "\\section{Calculus with Power Series}\\label{sec:CalculuswithPowerSeries}\n\nWe now know that some functions can be expressed as power series,\nwhich look like infinite polynomials. Since it is easy to find derivatives\nand integrals of polynomials, we might hope that we can take derivatives\nand integrals of power series in an analogous way. In fact we can, as stated\nin the following theorem, which we will not prove here.\n\n\\begin{theorem}{}{}\nSuppose the power series $f(x)=\\ds\\sum_{n=0}^\\infty a_n(x-a)^n$ has\nradius of convergence $R$. Then\n\\begin{align*}\n  f'(x)&=\\sum_{n=0}^\\infty na_n(x-a)^{n-1},\t\\\\\n  \\int f(x)\\,dx &= C+\\sum_{n=0}^\\infty {a_n\\over n+1}(x-a)^{n+1},\n\\end{align*}\nand these two series have radius of convergence $R$.\n\\end{theorem}\n\n\\begin{example}{}{}\nFind a power series representation of $\\ln|1-x|$.\n\\end{example}\n\\begin{solution}\nStarting with the geometric series:\n\\begin{align*}\n  {1\\over 1-x} &= \\sum_{n=0}^\\infty x^n\t\\\\\n  \\int{1\\over 1-x}\\,dx &= -\\ln|1-x| = \\sum_{n=0}^\\infty {1\\over n+1}x^{n+1}\t\\\\\n  \\ln|1-x| &= \\sum_{n=0}^\\infty -{1\\over n+1}x^{n+1}\n\\end{align*}\nwhen $|x|<1$. The series does not converge when $x=1$ but does\nconverge when $x=-1$ or $1-x=2$. The interval of convergence is\n$[-1,1)$, or $0<1-x\\le2$.\nWe can use this series to express $\\ln(a)$ as a series\nwhen $0<a\\le2$ by setting $x-1=a$. For example\n$$\n  \\ln(3/2)=\\ln\\left(1-(-1/2)\\right)=\n  \\sum_{n=0}^\\infty (-1)^n{1\\over n+1}{1\\over 2^{n+1}}.\n$$\nWe can use this in turn to approximate $\\ln(3/2)$:\n$$\n  \\ln(3/2)\\approx {1\\over 2}-{1\\over 8}+{1\\over 24}-{1\\over 64}\n  +{1\\over 160}-{1\\over 384}+{1\\over 896}\n  ={909\\over 2240}\\approx 0.406\n.$$\nBecause this is an alternating series with decreasing terms,\nwe know that the true value is between $909/2240$ and\n$909/2240-1/2048=29053/71680\\approx .4053$, so $0.4053\\leq\\ln(3/2)\\leq 0.406$.\n\\end{solution}\n\nWith a bit of arithmetic, we can approximate values outside of the interval of convergence:\n\n\\begin{example}{}{}\nFind an approximation for $\\ln(9/4)$.\n\\end{example}\n\\begin{solution}\nWe can use the approximation we just computed, plus some rules for logarithms:\n$$\\ln(9/4)=\\ln((3/2)^2)=2\\ln(3/2)\\approx 0.812,$$\nand using our bounds above,\n$$0.8106\\leq \\ln(9/4)\\leq 0.812.$$\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:CalculuswithPowerSeries}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind a series representation for $\\ln 2$.\n\\begin{sol}\nthe alternating harmonic series\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a power series representation for $\\ds 1/(1-x)^2$.\n\\begin{sol}\n$\\ds\\sum_{n=0}^\\infty (n+1)x^n$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a power series representation for $\\ds 2/(1-x)^3$.\n\\begin{sol}\n$\\ds\\sum_{n=0}^\\infty (n+1)(n+2)x^n$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a power series representation for $\\ds 1/(1-x)^3$.\nWhat is the radius of convergence?\n\\begin{sol}\n$\\ds\\sum_{n=0}^\\infty {(n+1)(n+2)\\over 2}x^n$, $R=1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a power series representation for $\\ds\\int\\ln(1-x)\\,dx$.\n\\begin{sol}\n$\\ds C+\\sum_{n=0}^\\infty {-1\\over (n+1)(n+2)}x^{n+2}$ \n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n\\clearpage", "meta": {"hexsha": "c9b7d4fcca12b4f5955cd7cebbe51c235b9b70c3", "size": 3177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9-sequences-and-series/9-9-power-series-calculus.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-9-power-series-calculus.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-9-power-series-calculus.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2571428571, "max_line_length": 91, "alphanum_fraction": 0.6622599937, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.6839591881145862}}
{"text": "\\section*{Exercise 26.1-1}\n\\subsubsection*{Show that a maximum flow in $G'$ has the same value as a maximum flow in $G$}\nLet $G$, $G'$, $x$, $u$ and $v$ be given as in the problem description.\n\nWhat we want to argue here is that any flow in $G$ is also feasible in $G'$ and with the same flow value. \nThen we conclude that $\\abs{f_G^*} = \\abs{f_{G'}^*}$ where $\\abs{f_{G}^*}$ is the maximum flow value in the network $G$.\n\nFirst observe that any flow $f(u,v)$ in $G$ can be replaced with a equivalent flow in $G'$ where $f(u,v) = f(u,x) = f(x,v)$ since $c(u,v) = c(u,x) = c(x,v)$.\n\nLet $p_{f_G^*}$ be the path the maximum flow $f^*$ takes in $G$.\n\n\\textit{If $(u,v) \\not\\in p_{f_G^*}$}\n\nIn this case the same path is available in $G'$ which would yield the same flow value. If introducing the new vertex $x$ means that $p_{f_{G'}^*}$ is changed such that $\\{(u,x),(x,v)\\}\\subset p_{f_{G'}^*}$, then by our first observation above, the same flow value is possible in $G$, and since $(u,v) \\not\\in p_{f_G^*}$ deviating cannot yield a higher flow value.\n\n\\textit{If $(u,v) \\in p_{f_G^*}$}\n\nIn this case we have already observed that replacing the $f(u,v)$ with $f(u,x) = f(x,v)$ will yield the same flow value. Hence the maximum flow value will be the same.\n\nIf introducing the new vertex $x$ in $G'$ changes the flow value from $u$ to $v$, then this cannot yield a higher maximum flow value in $G'$. This is because of our observation above, as all flow from $u$ to $v$ are bounded by the same capacity constraint in both $G$ and $G'$, the same flow value is feasible in both networks. As $f^*_G$ is part of a maximum flow value, deviating from that cannot yield a higher flow value, as that goes against it being a maximum flow value in the beginning.\n\nHence we conclude that in all possible cases the maximum flow value will be the same, hence $\\abs{f_G^*} = \\abs{f_{G'}^*}$.", "meta": {"hexsha": "2bdb495561825c4b1c60d6afcd81c445043e2e23", "size": 1875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/Ex.26.1.1.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/Ex.26.1.1.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/Ex.26.1.1.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": 85.2272727273, "max_line_length": 494, "alphanum_fraction": 0.6832, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6839591862948935}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{enumitem}\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1em}\n\n\\begin{document}\n\n\\section{Divisibility}\n\\subsection{Rules}\nFor integers $a,b,c,d$:\n\t\\begin{enumerate}\n\t\t\\item \n\t\tIf $a \\mid b$ and $ c \\mid d$ then $ac \\mid bd$\n\t\t\\item\n\t\tIf $a \\mid b$ and $a \\mid c$, then $a \\mid b+c$ \n\t\t\\item \n\t\t\\textbf{Euclid's algorithm.} \\\\\n\t\t$\\gcd (a,b) = \\gcd (a,b-a)$ \n\t\t\\item \n\t\t\\textbf{Corollary of Euclid's algorithm.} \\\\\n\t\t$ax+by=n$ has solution $(x,y)$ in integers if and only if $gcd(a,b) \\mid n$\n\t\\end{enumerate}\n\\subsection{Problems}\n\\begin{enumerate}\n\t\\item\n\tProve that if $m-p \\mid mn +pq$, then $m-p \\mid mq +np$.\n\n\t\\item \n\tProve that $17 \\mid 2a+3b  \\iff 17 \\mid 9a+5b$\n\n\t\\item\n\tProve that it is not possible to find positive integers $n$ and $m>1$, such that ${102^{2017}+103^{2017}=n^m}$\n\n\t\\item\n\tFind all positive integers $d$, such that $d$ divides both: $n^2+1$ and $(n+1)^2+1$\n\t\n\t\\item \n\tFind all prime numbers $p$ for which $p^2+2543$ has less than $16$ positive divisors.\n\t\n\t\\item \n\tProve that $\\gcd (a^m-1,a^n-1)=a^{\\gcd(m,n)}-1$\n\t\n\t\\item % BW treening 2011-Q13\n\tProve that any two non-equal integers in form $2^{2^n}+1$, where $n$ is a positive integer are coprime-\n\t\t\n\n\t\\item % IMO shortlist 1984\n\t$a_1,a_2,\\dots,a_{2n}$ are mutually distinct integers. Find all integers $x$ satisfying\n\t$$(x-a_1)\\dots (x-a_{2n}) = (-1)^n(n!)^2$$\n\t\n\t\\item %http://kodu.ut.ee/~zolki/math/bwsess04.pdf \n\tLet $a_0,\\dots, a_n \\geq -1$ be integers such that at least one of them is non-zero. It is known that $a_0 + 2a_1 +2^2a_2+ \\dots + 2^na_n = 0$. Show that $a_0+a_1+\\dots + a_n >0$.\n\t\n\\end{enumerate}\n\n\n\\newpage\n\\section{Congruences}\n\\subsection{Rules}\nFor integers $a,b,c,d,m,n$ and prime $p$.\n\\begin{enumerate}\n\t\\item \n\t$a \\equiv b \\mod m \\iff m \\mid a-b $\n\t\\item \n\t$a\\equiv b \\mod m$ and $ c\\equiv d \\mod m \\implies a+c\\equiv b+d \\mod m$\t\n\t\\item \n\t$a \\equiv b \\mod m \\iff an \\equiv bn \\mod mn$\n\t\\item \n\t$a \\equiv b \\mod m \\implies an \\equiv bn \\mod m$\n\t\\item\n\t\\textbf{Fermat's little theorem.} \\\\\n\t$a^p \\equiv a \\mod p$\n\t\\item \n\t\\textbf{Wilson's theorem.} \\\\\n\t$(p-1)!\\equiv -1 \\mod p$\n\t\n\t\n\\end{enumerate}\n\n\\subsection{Problems}\n\n\\begin{enumerate}\n\t\\item \n\tProve that $2018!! + 2017!!$ is divisible by $2019$\n\t\n\t\\item \n\tFind all primes $p$, such that:\n\t\\begin{enumerate}\n\t\t\\item  $p+4$, $p+14$ are primes;\n\t\t\\item $8p^2+1$ is a prime;\n\t\t\\item $p+10$, $p+1$ is a prime;\n\t\t\\item $4p^2+1$, $6p^2+1$ are primes;\n\t\t\\item $p^2-6$, $p^2+6$ are primes;\n\t\t\\item $p^4-6$ is a prime;\n\t\t\\item $p^3+6$, $p^3-6$ are primes;\n\t\t\\item $p^2-2$, $2p^2-1$, $3p^2+4$ are primes;\n\t\t\\item $2^p+1$, $2^p-1$ are primes;\n\t\t\\item $p,q$, $p^q+q^p$ are primes.\n\t\\end{enumerate}\n\t\n\t\\item \n\tIn a series of integers, the next element is obtained by concatenating the element's order number to previous element by using carry. The first elements of the series are therefore:\n\t$${1,12,123,1234,\\dots,123456789,1234567900,12345679011} $$\n\tFind all elements in the series which are divisible by $7$.\n\t\n\t\\item % http://kodu.ut.ee/~zolki/math/bwsess04.pdf \n\tProve that there exist no integers $n>1$, such that $n \\mid 3^n-2^n$.\n\t\n\t\\item \n\tFind all positive integers $n$ which satisfy the following condition:\n\tFor all integers $a$ and $b$ which are coprime with $n$\n\t$$ a \\equiv b  \\mod n \\iff ab \\equiv 1 \\mod n$$\n\n\t\\item\n\tProve that it is not possible to separate $18$ consecutive integers into $2$ subsets with $9$ elements in such way that the product of each subset is equal.\n\\end{enumerate}\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "d8efd71539a64809f2a20616655fd84dda07ce36", "size": 3583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "06_congruences.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": "06_congruences.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": "06_congruences.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": 28.664, "max_line_length": 182, "alphanum_fraction": 0.6488975719, "num_tokens": 1395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.6839591849326109}}
{"text": "\\chapter{Kinematics, and the calculus of infinitesimals}\n\\label{sec:derivative}\n\nKinematics is the mathematics that describes motions.\n\nA \\emph{frame} defines \\emph{where} and \\emph{when}.\n\n\\emph{Motion} is change of position.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Motion_\\%28physics\\%29}}\n\nAn object \\emph{moves} iff its position changes.\n\nThe \\emph{speed} of an object is how fast it moves:\nhow far it moves in how much time.\n\\emph{Fast} means high speed,\ngoing far in little time,\ntraveling much distance in little time.\n\n\\emph{Average speed} is distance traveled divided by time required.\n\n\\emph{Velocity} is the rate of change of position.\nSpeed is the magnitude of velocity.\n\\emph{Rate of change} is defined by \\emph{derivative} (\\S\\ref{sec:derivative}).\n\n\\section{Describing motions using equations relating position and time}\n\nWe can use a position function.\nIts type is \\( \\Real \\to V \\).\n\nAn example of an equation of motion is \\( x(t) = 2 t e_1 \\).\nIt describes an object that moves with constant velocity \\(2\\) towards the positive x-axis.\nAn \\emph{equation of motion} is an equation that describes\nthe motion of an object by relating time and position.\n\nEach equation of motion corresponds to a moving object.\n\nTo describe more objects, use more equations.\n\nLet \\(e\\) be a linear basis.\nSuppose that the position of an object at time \\(t\\) is\n\\(x(t) = e(x_1(t), \\ldots, x_n(t))\\).\nThen the velocity at time \\(t\\) is \\(v(t) = \\der(x,t) = e(v_1(t), \\ldots, v_n(t)) \\).\nCan we say that \\(v_k(t) = \\der(x_k,t)\\)?\n\nMoral of the story:\nIf we have a linear basis,\nthen doing calculus on the coordinates\nis doing calculus on the vectors.\n\n\\section{Notating derivatives}\n\nLet \\(f : \\Real \\to \\Real\\).\n\n\\paragraph{\\der}\n\nWe can describe the derivative by a function \\(\\der : (\\Real \\to \\Real) \\to (\\Real \\to \\Real)\\).\n\\[\n    \\der(f,x) = \\StandardPart\\parenthesize{\\frac{f^*(x+\\delta)-f^*(x)}{\\delta}}\n\\]\nwhere \\(f^*\\) is the natural extension of \\(f\\) to the hyperreals.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Non-standard_calculus\\#Definition_of_derivative}}\nThen \\(\\der(f,x)\\) is the slope of the tangent line of \\(f\\) at \\(x\\).\n\nStrictly, \\(\\der(f)(x)\\), not \\(\\der(f,x)\\).\n\nThus \\(f' = \\der(f)\\).\n\n\\(\\dd{x}\\) means an infinitesimal change in \\(x\\)?\nWhat does that mean?\nWhat is \\(x\\)?\n\n\\paragraph{Euler\\textendash{}Arbogast D-notation}\n\n% https://en.wikipedia.org/wiki/Notation_for_differentiation#Euler.27s_notation\n\n\\( D_x E \\) is the derivative of expression \\(E\\) with respect to variable \\(x\\).\nThe variable \\(x\\) should occur free in \\(E\\).\n\nTyping rule:\nIf \\(x:\\Real\\) and \\(E:\\Real\\), then \\(D_x E:\\Real\\).\n\nThe notation \\(E[x:=y]\\) means \\(E\\) but with each free occurrence of \\(x\\) replaced with \\(y\\).\n\nThen \\( D_x E = \\lim_{h \\to 0} \\frac{E[x := x+h] - E}{h} \\).\n\nThen \\( D_x E = d(x \\to E) \\).\n\nExample: \\( D_x (4x^2) = d(x \\to 4x^2) = 8x \\).\n\nExample: \\( D_y (x + y) = d(y \\to x + y) = x + 1 \\).\n\nAdvantage: With \\(D_x\\) notation, we can refer to an input by name;\nWith \\(d_k\\) notation, we can refer to an input by index only.\n\n\\(D\\) is a custom syntax, not an ordinary function.\n\n% Multivariate differential calculus\n% Vector calculus\n\n\\section{Relating velocities, tangent lines, and derivatives}\n\nThere are several ways of understanding \\(f'(x)\\) (the derivative of \\(f\\) at \\(x\\)):\n\\UnorderedList{\n    \\item rate of change of \\(f\\) at \\(x\\); instantaneous velocity\n    \\item slope of the tangent line of \\(f\\) at \\(x\\)\n    \\item best linear approximation (not discussed here)\n}\n\n\\paragraph{Average velocity and the secant line}\n\nLet there be an object.\n\nLet \\(x(t) : V^2\\) be a vector that describes its position at time \\(t : \\Real\\).\n\nThe \\emph{average velocity} of that object in the time interval \\([t,t+\\Delta t]\\) is\n\\[ \\frac{x(t+\\Delta t) - x(t)}{\\Delta t}. \\]\n\nIf at time \\(t_1\\) its position is \\(x_1\\)\nand at time \\(t_2\\) its position is \\(x_2\\),\nthen its \\emph{average velocity} in the time interval between \\(t_1\\) and \\(t_2\\)\nis \\((x_2 - x_1) / (t_2 - t_1)\\).\n\nA \\emph{secant line of \\(f\\)} is a line that passes \\((x_1,f(x_1))\\) and \\((x_2,f(x_2))\\).\nThink of average velocity.\n\n\\paragraph{Instantaneous velocity and the tangent line}\n\nIf the position of an object at time \\(t\\) is \\(x(t)\\),\nthen its \\emph{instantaneous velocity} at time \\(t\\) is \\(v(t) = (d(x))(t)\\).\nThe velocity function is the derivative of the position function.\n\nThe term \\emph{instantaneous velocity} is often shortened to just \\emph{velocity}.\n\nThe unqualified \\emph{velocity} means \\emph{instantaneous velocity}.\n\nA car's speedometer measures its instantaneous speed.\n\nDerivative is about \\emph{rate of change}:\nhow fast a function changes value,\nhow big is the change in output compared to the change in input.\n\nConsider a function \\(f : \\Real \\to \\Real\\).\nIf the input is \\(x\\), then the output is \\(f(x)\\).\nIf you change the input by \\(\\dd{x}\\), the output changes by \\(\\dd{y}\\).\nFormally, \\(f(x+\\dd{x}) = f(x)+\\dd{y}\\).\n\nA \\emph{tangent line of \\(f\\) at \\(x\\)} is what the secant line converges to\nif both \\(x_1\\) and \\(x_2\\) converge to \\(x\\).\nThink of instantaneous velocity.\n\n\\paragraph{Understanding the derivative as the slope of the tangent line}\n\nThe \\emph{derivative of \\(f\\) at \\(x\\)} is the slope of the tangent line of \\(f\\) at \\(x\\).\nReminder: The line \\(y = mx + c\\) has slope \\(m\\).\n\n\\section{Describing motions using implicit equations}\n\nAn example of \\emph{implicit} equation is \\( x(t) = - (d(d(x)))(t) \\).\nThis is also an example of a \\emph{differential equation} because it contains the derivative operator \\(d\\).\nDifferential equations are discussed in \\S\\ref{sec:diff-eqn}.\n\n\\section{Integrals}\n\nWe can think of an integral in several ways:\n\\UnorderedList{\n\\item area under a curve\n\\item slicing and summing\n}\n\n\\paragraph{Integrating by slicing and summing}\n\n\\section{Calculating derivatives and integrals quickly}\n\n\\paragraph{Calculating derivatives}\n\nSymbolic calculation is enabled by\nthe \\emph{constant rule} \\eqref{der-constant-rule},\nthe \\emph{power rule} \\eqref{der-power-rule},\nthe \\emph{product rule} \\eqref{der-product-rule},\nand the \\emph{chain rule} \\eqref{der-chain-rule}.\n\\begin{align}\n    d (x \\to y) &= 0 \\text{ if \\( y \\) is a constant} \\label{der-constant-rule}\n    \\\\ d (x \\to x^p) &= p \\cdot x^{p-1} \\text{ if \\( p \\) is a non-zero real number} \\label{der-power-rule}\n    \\\\ d(f \\cdot g) &= d(f) \\cdot d(g) \\label{der-product-rule}\n    \\\\ d(f \\circ g) &= d(g) \\cdot (d(f) \\circ g) \\label{der-chain-rule}\n\\end{align}\n\nThe \\(d\\) operator is linear:\nIf \\(c\\) is a constant, then \\(d(c \\cdot f) = c \\cdot d(f)\\).\nAlso, \\(d(f+g) = d(f) + d(g)\\).\n\n\\paragraph{Calculating integrals}\n\nWith the \\emph{fundamental theorem of calculus},\nwe can compute integrals using antiderivatives.\nWith this shortcut, we can skip the slicing and summing.\n\n\\Formula{\n    \\int_{[a,b]} f(x) \\dd{x} \\dd{y} \\dd{z} = F(b) - F(a)\n}\n\n\\section{Exercise}\n\nCompute the derivative of each of these functions:\n\\( x \\to 1 \\), \\( x \\to x \\), \\( x \\to 2x \\), \\( x \\to x^2 \\),\n\\( x \\to 3e^x \\), \\(x \\to e^x \\cdot x \\).\n\nUsing the power rule, show that \\( d(x \\to x^2) = 2x \\).\n\nShow that \\( d(x \\to x^3 + x^2) = 3x^2 + 2x \\).\n", "meta": {"hexsha": "258ce419838a5ee743fd0dc939aa2dd84da7d790", "size": 7162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/kinematics.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/kinematics.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/kinematics.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": 33.9431279621, "max_line_length": 108, "alphanum_fraction": 0.6738341245, "num_tokens": 2206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6839591840227646}}
{"text": "%% LyX 2.3.6.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]{inputenc}\n\\usepackage[a4paper]{geometry}\n\\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}\n\\setlength{\\parskip}{\\smallskipamount}\n\\setlength{\\parindent}{0pt}\n\\usepackage{amssymb}\n\\usepackage{babel}\n\\begin{document}\n\n\\section{EKF in a nutshell}\n\nExtended Kalman Filter (EKF) is an modification of the well known\nKalman Filter for the case of nonlinear dynamics. The Kalman Filter\nitself is an optimal state estimation algorithm for linear dynamics\nand measurement models which experience zero-mean Gaussian noise.\nIn the EKF context however, neither the dynamical model nor the measurement\nmodel have to be linear, nonetheless, linearized dynamics and measurements\nmodels are still required within the filter. One dynamical system\ncan be described as follows:\n\n\\begin{equation}\n\\dot{{\\bf x}}=f(t,{\\bf x})+{\\bf w}\n\\end{equation}\n\nin which the function $f:\\mathbb{R}\\times\\mathbb{R}^{n}\\rightarrow\\mathbb{R}^{n}$\nand ${\\bf w}$ is a vector of $n$ normally distributed random variables\nwith zero mean and a covariance matrix ${\\bf Q}$. The same system\ncan be written in discrete time as:\n\n\\begin{equation}\n{\\bf x}_{k+1}={\\bf F}(t_{k},t_{k+1},{\\bf x}){\\bf x}+{\\bf w}_{k}\n\\end{equation}\n\nwhere ${\\bf F}:\\mathbb{R}\\times\\mathbb{R}\\times\\mathbb{R}^{n}\\rightarrow\\mathbb{R}^{n\\times n}$is\nthe state transition matrix. A first order approximation of the state\ntransition matrix is found below:\n\n\\begin{equation}\n{\\bf F}(t_{k},t_{k+1},{\\bf x})={\\bf I}+\\frac{\\partial f(t,{\\bf x})}{\\partial t}\\cdot(t_{k}-t_{k+1})\\label{eq:STM}\n\\end{equation}\n\nThe measurements are modeled as follows:\n\n\\begin{equation}\n{\\bf z}=h(t,{\\bf x})+{\\bf v}\n\\end{equation}\n\nin which the function $h:\\mathbb{R}\\times\\mathbb{R}^{n}\\rightarrow\\mathbb{R}^{m}$\nand ${\\bf v}$ is a vector of $m$ normally distributed random variables\nwith zero mean and a covariance matrix ${\\bf R}$. One other important\nmatrix that needs to be available for the EKF algorithm is the $H(t,{\\bf x})=\\frac{\\partial h(t,{\\bf x})}{\\partial t}$.\n\n\\section{Example details}\n\nIn the context of this example, the position and velocity of a vehicle\nmoving along a line are to be estimated. The linear acceleration of\nthe system is modeled follows:\n\n\\begin{equation}\n\\ddot{x}=-\\sin(t)\\label{eq:dynamics}\n\\end{equation}\n\nletting $x_{1}=x$ and $x_{2}=\\dot{x}$, the dynamical model can be\nwritten as:\n\n\\begin{equation}\n\\left[\\begin{array}{c}\n\\dot{x_{1}}\\\\\n\\dot{x_{2}}\n\\end{array}\\right]=\\left[\\begin{array}{c}\nx_{2}\\\\\n-\\sin(t)\n\\end{array}\\right]\n\\end{equation}\n\nThe state transition matrix of the system is written according to\nthe approximation in (\\ref{eq:STM}) as:\n\n\\begin{equation}\n{\\bf F}(t_{k},t_{k+1},{\\bf x})=\\left[\\begin{array}{cc}\n1 & t_{k}-t_{k+1}\\\\\n0 & 1\n\\end{array}\\right]\n\\end{equation}\n\nThe system is assumed to measure only the position of the vehicle,\nhence:\n\n\\[\n{\\bf z}=x_{1}\\quad\\Rightarrow\\quad H(t,{\\bf x})=\\left[\\begin{array}{cc}\n1 & 0\\end{array}\\right]\n\\]\n\nThe ground truth of the system is synthesized by analytically solving\n(\\ref{eq:dynamics}) and adding zero-mean Gaussian noise to the velocity\n(which in-turn affects the position), while the measurements where\nsynthesized by adding zero-mean Gaussian noise to the position ground\ntruth.\n\\end{document}\n", "meta": {"hexsha": "ca161919551ac8731a1aaa7f61ad141bb3320486", "size": 3433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/example_illustration.tex", "max_stars_repo_name": "AhmedTahaha/Extended-Kalman-Filter---Matlab", "max_stars_repo_head_hexsha": "c9ef27d800085756ccd0b45ca549eb42cc06f198", "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": "examples/example_illustration.tex", "max_issues_repo_name": "AhmedTahaha/Extended-Kalman-Filter---Matlab", "max_issues_repo_head_hexsha": "c9ef27d800085756ccd0b45ca549eb42cc06f198", "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": "examples/example_illustration.tex", "max_forks_repo_name": "AhmedTahaha/Extended-Kalman-Filter---Matlab", "max_forks_repo_head_hexsha": "c9ef27d800085756ccd0b45ca549eb42cc06f198", "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": 33.0096153846, "max_line_length": 119, "alphanum_fraction": 0.7244392659, "num_tokens": 1063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6839591805002184}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\\section{IMO}\\label{sec:imo}\n\t\n\t\t\\begin{problem}[IMO $1995$, problem $2$]\n\t\t\tLet $a,b,c$ be real numbers such that $abc=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{a^{3}(b+c)}+\\dfrac{1}{b^{3}(c+a)}+\\dfrac{1}{c^{3}(a+b)}\n\t\t\t\t\t\t& \\geq\\dfrac{3}{2}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $1999$, problem $2$]\n\t\t\tLet $n\\geq2$ be an integer. Find the least constant $C$ such that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sum\\limits_{1\\leq i < j\\leq n}x_{i}x_{j}(x_{i}^{2}+x_{j}^{2})\n\t\t\t\t\t\t& \\leq C\\left(\\sum\\limits_{i=1}^{n}x_{i}\\right)^{4}\n\t\t\t\t\\end{align*}\n\t\t\tholds for all non-negative real numbers $x_{1},\\ldots,x_{n}$. When does equality occur?\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $2000$, problem $2$]\n\t\t\tLet $a,b,c$ be positive real numbers such that $abc=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(a-1+\\dfrac{1}{b}\\right)\\left(b-1+\\dfrac{1}{c}\\right)\\left(c-1+\\dfrac{1}{a}\\right)\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}[IMO $2001$, problem $2$]\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\\dfrac{a}{\\sqrt{a^{2}+8bc}}+\\dfrac{b}{\\sqrt{b^{2}+8ca}}+\\dfrac{c}{\\sqrt{c^{2}+8ab}}\n\t\t\t\t\t\t& \\geq1\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\t\n\t\t\\begin{problem}[IMO $2003$, problem $5$]\n\t\t\tLet $n$ be a positive integer and $x_{1}\\leq\\ldots\\leq x_{n}$ be real numbers. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\sum\\limits_{i,j=1}^{n}|x_{i}-x_{j}|\\right)^{2}\n\t\t\t\t\t\t& \\leq \\dfrac{2(n^{2}-1)}{3}\\sum\\limits_{i,j=1}^{n}(x_{i}-x_{j})^{2}\n\t\t\t\t\\end{align*}\n\t\t\tShow that equality holds if and only if $x_{1},\\ldots,x_{n}$ forms an arithmetic sequence.\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $2004$, problem $4$]\n\t\t\tLet $n\\geq3$ be an integer. Let $t_{1},\\ldots,t_{n}$ be positive real numbers such that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tn^{2}+1\n\t\t\t\t\t\t& > (t_{1}+\\ldots+t_{n})\\left(\\dfrac{1}{t_{1}}+\\ldots+\\dfrac{1}{t_{n}}\\right)\n\t\t\t\t\\end{align*}\n\t\t\tShow that $t_{i},t_{j},t_{k}$ are the sides of a triangle for all $1\\leq i< j < k\\leq n$.\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $2005$, problem $3$]\n\t\t\tLet $x,y,z$ be real numbers such that $xyz\\geq1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{x^{5}-x^{2}}{x^{5}+y^{2}+z^{2}}+\\dfrac{y^{5}-y^{2}}{x^{2}+y^{5}+z^{2}}+\\dfrac{z^{5}-z^{2}}{x^{2}+y^{2}+z^{5}}\n\t\t\t\t\t\t& \\geq0\n\t\t\t\t\\end{align*}\n\t\t\t\n\t\t\t\t\\begin{solution}\n\t\t\t\t\tWe have already solved it in \\autoref{prob:imo2005-3}.\n\t\t\t\t\\end{solution}\n\t\t\\end{problem}\n\t\t\n\t\t\\begin{problem}[IMO $2006$, problem $3$]\n\t\t\tDetermine the least real number $M$ such that the inequality\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left|ab\\left(a^{2}-b^{2}\\right)+bc\\left(b^{2}-c^{2}\\right)+ca\\left(c^{2}-a^{2}\\right)\\right|\n\t\t\t\t\t\t& \\leq M(a^{2}+b^{2}+c^{2})^{2}\n\t\t\t\t\\end{align*}\n\t\t\tholds for all real numbers $a,b,c$.\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $2008$, problem $2$]\n\t\t\tLet $x,y,z\\neq1$ be real numbers such that $xyz=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{x^{2}}{(x-1)^{2}}+\\dfrac{y^{2}}{(y-1)^{2}}+\\dfrac{z^{2}}{(z-1)^{2}}\n\t\t\t\t\t\t& \\geq1\n\t\t\t\t\\end{align*}\n\t\t\tAlso, prove that equality holds for infinitely many rational $x,y,z$ such that $xyz=1$ and $x,y,z\\neq1$.\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $2012$, problem $2$]\n\t\t\tLet $n\\geq3$ be a positive integer and $a_2,\\ldots,a_n$ be positive real numbers such that $a_1\\cdots a_n=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(1+a_2)^{2}\\cdots(1+a_n)^{n}\n\t\t\t\t\t\t& \\geq n^{n}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO $2020$, problem $2$]\n\t\t\tLet $a,b,c,d$ be positive real numbers such that $a\\geq b\\geq c\\geq d$ and $a+b+c+d=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a+2b+3c+4d)a^{a}b^{b}c^{c}d^{d}\n\t\t\t\t\t\t& < 1\n\t\t\t\t\\end{align*}\n\t\t\t\n\t\t\t\t\\begin{solution}\n\t\t\t\t\tSince $a+b+c+d=1$, by \\nameref{thm:weightedpowermean} on $\\omega=(a,b,c,d)$ and $\\mathbf{a}=(a,b,c,d)$,\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\ta\\cdot a+b\\cdot a+c\\cdot c+d\\cdot d\n\t\t\t\t\t\t\t\t& \\geq a^{a}b^{b}c^{c}d^{d}\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\tSo it is enough to prove that\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t(a+2b+3c+4d)(a^{2}+b^{2}+c^{2}+d^{2})\n\t\t\t\t\t\t\t\t& \\leq (a+b+c+d)^{3}\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\tExpanding these we can easily see that the inequality has to follow. But we can prove it in a smarter way.\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t(a+b+c+d)^{3}\n\t\t\t\t\t\t\t\t& = (a+b+c+d)\\left(a^{2}+b^{2}+c^{2}+d^{2}+2\\sum ab\\right)\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\twhere the sum runs over all possible $\\binom{4}{2}$ pairs. Then\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t(a+2b+3c+4d)(a^{2}+b^{2}+c^{2}+d^{2})\n\t\t\t\t\t\t\t& < (a+b+c+d)^{3}\\\\\n\t\t\t\t\t\t\t\\iff (b+2c+3d)(a^{2}+b^{2}+c^{2}+d^{2})\n\t\t\t\t\t\t\t\t& < 2(a+b+c+d)\\left(\\sum ab\\right)\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\tNow, using $a\\geq b\\geq c$,\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\ta^{2}+b^{2}+c^{2}+d^{2}\n\t\t\t\t\t\t\t\t& \\leq a(a+b+c+d)\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\tSo, it is enough to show that\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\ta(b+2c+3d)(a+b+c+d)\n\t\t\t\t\t\t\t\t& \\leq  2(a+b+c+d)\\left(\\sum ab\\right)\\\\\n\t\t\t\t\t\t\t\\iff a(b+2c+3d)\n\t\t\t\t\t\t\t\t& \\leq 2\\sum ab\\\\\n\t\t\t\t\t\t\t\\iff 3da\n\t\t\t\t\t\t\t\t& \\leq ab+2ca\\\\\n\t\t\t\t\t\t\t\\iff da+da+da\n\t\t\t\t\t\t\t\t& \\leq ab+ca+ca\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\tThis inequality obviously holds.\n\t\t\t\t\\end{solution}\n\t\t\t\n\t\t\t\t\\begin{remark}\n\t\t\t\t\tWe could also use \\nameref{thm:weightedjensen} after using the fact that $\\log(x)$ is concave. The buffalo way works here as well. But the calculation is not going to be pretty if you go that way. This problem was highly criticized within some forums such as the Art of Problem Solving. It was the first inequality problem at the IMO since $2012$. A lot of people thought that the days of inequality at the IMO was over. But when this problem appeared at the IMO $2020$, many people complained and expressed their disappointment that the \\textit{no inequality problem at the IMO} streak was finally broken with such a problem.\n\t\t\t\t\\end{remark}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO Shortlist $2015$, A1]\n\t\t\tLet $a,b,c$ be positive real numbers such that $\\min\\{ab,bc,ca\\}\\geq1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sqrt[3]{(a^2+1)(b^2+1)(c^2+1)}\n\t\t\t\t\t\t& \\leq\\left(\\dfrac{a+b+c}{3}\\right)^2+1\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO Shortlist $2015$, A8]\n\t\t\tDetermine the largest real number $a$ such that for all $n\\geq1$ and for all real numbers $x_{0},\\ldots,x_{n}$ satisfying\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t0\n\t\t\t\t\t\t& = x_{0}<x_{1}<\\ldots<x_{n}\n\t\t\t\t\\end{align*}\n\t\t\twe have\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{x_{1}-x_{0}}+\\dfrac{1}{x_{2}-x_{1}}+\\ldots+\\dfrac{1}{x_{n}-x_{n-1}}\n\t\t\t\t\t\t& \\geq a\\left(\\dfrac{2}{x_{1}}+\\dfrac{3}{x_{2}}+\\ldots+\\dfrac{n+1}{x_{n}}\\right)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[IMO Shortlist $2018$, A7]\n\t\t\tFind the maximal value of\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tS\n\t\t\t\t\t\t& = \\sqrt[3]{\\dfrac{a}{b+7}}+\\sqrt[3]{\\dfrac{c}{d+7}}+\\sqrt[3]{\\dfrac{d}{a+7}}\n\t\t\t\t\\end{align*}\n\t\t\twhere $a,b,c,d$ are non-negative real numbers which satisfy $a+b+c+d=100$.\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "ae817bda73cef30b41d43993aed2899fb524087b", "size": 6777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "imo.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": "imo.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": "imo.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": 38.0730337079, "max_line_length": 631, "alphanum_fraction": 0.5747380847, "num_tokens": 2852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.843895098628499, "lm_q1q2_score": 0.68395917856866}}
{"text": "\n\\subsection{Discrete and continous probability}\n\nWe know that:\n\n\\(\\sum_yP(X\\land Y)=P(X)\\)\n\nSo for the continuous case\n\n\\(P(X)=\\int_{-\\infty }^{\\infty }P(X\\land Y)dy\\)\n\nThis behaves like the probability for a single event, or multiple events with one fewer event if there were more than \\(2\\) events to start with.\n\n", "meta": {"hexsha": "9ad0209e1057fcd06f58d0735625ae4b3ff3dc8c", "size": 317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityAxioms/04-02-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/probability/probabilityAxioms/04-02-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/probability/probabilityAxioms/04-02-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": 22.6428571429, "max_line_length": 145, "alphanum_fraction": 0.7129337539, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450965, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6839452964363425}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\setcounter{section}{-1}\n\n\\begin{document}\n\n\\title{Category Theory}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Introduction}\nI didn't go to the first 3 lectures, so no intro -- sorry. I have no idea on what this course is about, let's see\n\n\\newpage\n\n\\section{Definitions and examples}\n\\begin{defi} (1.1)\\\\\n    A category $\\mathcal{C}$ consists of:\\\\\n    (a) a collection $\\ob\\mathcal{C}$ of \\emph{objects} $A,B,C$;\\\\\n    (b) a collection $\\mor\\mathcal{C}$ of \\emph{morphisms} $f,g,h$;\\\\\n    (c) two operations domain, codomain assigining to each $f \\in \\mor\\mathcal{C}$ a pair of objects, its \\emph{domain} and \\emph{codomain}; we write $A \\xrightarrow{f} B$ to mean \\emph{$f$ is a morphism and $\\dom f = A, \\cod f = B$};\\\\\n    (d) an operation assigning to each $A \\in \\ob\\mathcal{C}$ a morphism $A \\xrightarrow{1_A} A$;\\\\\n    (e) a partial binary operation $(f,g) \\to fg$ on morphisms, such that $fg$ is defined iff $\\dom f = \\cod g$, and $\\dom(fg) = \\dom g$, $\\cod(fg) = \\cod(f)$ if $fg$ is defined, satisfying:\\\\\n    (f) $f 1_A = f = 1_B f$ for any $A \\xrightarrow{f} B$;\\\\\n    (g) $(fg) h = f(gh)$ whenever $fg$ and $gh$ are defined.\n\\end{defi}\n\n\\begin{rem} (1.2)\\\\\n    (a) This definition is independent of any model of set theory. If we're given a particular model of set theory, we call $\\mathcal{C}$ \\emph{small} if $\\ob \\mathcal{C}$ and $\\mor\\mathcal{C}$ are sets.\\\\\n    (b) Some texts say $fg$ means $f$ followed by $g$, i.e. $fg$ is defined iff $\\cod f = \\dom g$.\\\\\n    (c) Note that a morphism $f$ is an identity iff $fg = g$ and $hf = h$ whenever the composites are defined. So we could formulate the definition entirely in terms of morphisms.\n\\end{rem}\n\n\\begin{eg} (1.3)\\\\\n    (a) The category $\\mathbf{Set}$ has all sets as objects, and all functions between sets as morphisms.\\\\\n    Strictly speaking, morphisms $A \\to B$ are pairs $(f,B)$ where $f$ is a set-theoretic function. (See part II logic and sets)\\\\\n    (b) The category $\\mathbf{Gp}$ has all groups as objects, group homomorphisms as morphisms.\\\\\n    Similarly, $\\mathbf{Ring}$ is the category of rings, $\\mathbf{Mod_R}$ is the category of $R$-modules.\\\\\n    (c) The category $\\mathbf{Top}$ has all topological spaces as objects, and continuous functions as morphisms.\\\\\n    Similarly, $\\mathbf{Unif}$ has all uniform spaces and uniformly continuous functions as morphisms, $\\mathbf{Mf}$ has all manifolds and smooth maps correspondingly.\\\\\n    (d) The category $\\mathbf{Htpy}$ has the same objects as $\\mathbf{Top}$, but morphisms are homotopy classess of continuous functions. More generally, given $\\mathcal{C}$, we call an equivalence relation $\\simeq$ on $\\mor \\mathcal{C}$ a \\emph{congruence} if $f \\simeq g \\implies \\dom f = \\dom g$ and $\\cod f = \\cod g$, and $f \\simeq g \\implies fh \\simeq gh$ and $kf \\simeq kg$ whenever the composites are defined. Then we have a category $\\mathcal{C} / \\simeq$ with the same objects as $\\mathcal{C}$, but congruence classes as morphisms instead.\\\\\n    (e) Given $\\mathcal{C}$, the \\emph{opposite category} $C^{op}$ has the same objects and morphisms as $\\mathcal{C}$, but $\\dom$ and $\\cod$ are interchanged, and $fg$ in $\\mathcal{C}^{op}$ is $gf$ in $\\mathcal{C}$.\\\\\n    This leads to the \\emph{duality principle}: if $P$ is a true statement about categories, so is the statement $P^*$ obtained from $P$ by reversing all arrows.\\\\\n    (f) A small category with one object is a \\emph{monoid}, i.e. a semigroup with $1$. In particular, a group is a small cat ($\\Cat$) with one object in which every morphism is an isomorphism (i.e. for all $f, \\exists g$ s.t. $fg$ and $gf$ are identities).\\\\\n    (g) A \\emph{groupoid} is a category in which every morphism is an isomorphism. For example, for a topological space $X$, the \\emph{fundamental groupoid} $\\pi(x)$ has all points of $X$ as objects, and morphisms $x \\to y$ are homotopy classes $rel\\{0,1\\}$ of paths $u:[0,1] \\to X$ with $u(0) = x$, $u(1) = y$ (if you know how to prove that the fundamental group is a group, you can prove that $\\pi(x)$ is a groupoid).\\\\\n    (h) A \\emph{discrete} cat is one whose only morphism are identities.\\\\\n    A \\emph{preorder} is a cat $\\mathcal{C}$ in which, for any pair $(A,B)$, $\\exists$ at most 1 morphism $A \\to B$.\\\\\n    A small preorder is a set equipped with a binary relation which is reflexive and transitive.\\\\\n    In particular, a partially ordered set is a small preorder in which the only isomorphisms are identities.\\\\\n    (i) The category $\\mathbf{Rel}$ has the same objects as \\emph{set}, but morphisms $A \\to B$ are arbitrary relations $R \\subseteq A \\times B$. Given $R$ and $S \\subseteq B\\times C$, we define $S \\cdot R = \\{(a,c) \\in A \\times C | (\\exists b \\in B) ((a,b) \\in R, (b,c) \\in S)\\}$.\\\\\n    The identity $1_A:A \\to A$ is $\\{(a,a) | a \\in A\\}$.\\\\\n    Similarly, the category $\\mathbf{Part}$ are for sets and partial functions (i.e. relations s.t. $(a,b) \\in R$ and $(a,b') \\in R \\implies b = b'$).\\\\\n    (j) Let $K$ be a field. The cateogry $\\mathbf{Mat_K}$ has natural numbers as objects, and morphism $n \\to p$ are $(p \\times n)$ matrices with entries from $K$. Composition is matrix multiplication.\\\\\n    (k) We write $\\mathbf{Cat}$ for the category whose objects are all small categories, and whose morphisms are functors between them. (see below for definition of functors)\n\\end{eg}\n\n\\begin{defi} (1.4)\\\\\n    Let $\\mathcal{C}$ and $\\mathcal{D}$ be categories. A \\emph{functor} $F:\\mathcal{C} \\to \\mathcal{D}$ consists of:\\\\\n    (a) a mapping $A \\to FA$ from $\\ob \\mathcal{C}$ to $\\ob \\mathcal{D}$;\\\\\n    (b) a mapping $f \\to Ff$ from $\\mor \\mathcal{C}$ to $\\mor \\mathcal{D}$,\\\\\n    such that $\\dom(Ff) = F(\\dom f)$, $\\cod(Ff) = F(\\cod f)$, $1_{FA} = F(1_A)$, and $(Ff)(Fg) = F(fg)$ whenever $fg$ is defined.\n\\end{defi}\n\n\\begin{eg} (1.5)\\\\\n    (a) We have \\emph{forgetful functors} $U$: $\\mathbf{Gp} \\to \\mathbf{Set}$, $\\mathbf{Ring}\\to \\mathbf{Set}$, $\\mathbf{Top} \\to \\mathbf{Set}$, $\\mathbf{Ring} \\to \\mathbf{AbGp}$ (forget $\\times$), $\\mathbf{Ring} \\to \\mathbf{Mon}$ (Category of all monoids) (forget $+$).\\\\\n    (b) Given a set $A$, the free group $FA$ has the property:\\\\\n    Given any group $G$ and any function $A \\xrightarrow{f} UG$ (?), there's a unique homomorphism $FA \\xrightarrow{\\bar{f}} G$ extending $f$. Here $F$ is a functor $\\mathbf{Set}\\to \\mathbf{Gp}$: given $A \\xrightarrow{f} B$, we define $Ff$ to be the unique homomorphism extending $A \\xrightarrow{f} B \\leftrightarrow UFB$. \\href{https://math.stackexchange.com/questions/1922113/what-exactly-is-functoriality}{Functoriality} follows from uniqueness given $B \\xrightarrow{f} C$. $F(gf)$ and $(Fg)(Ff)$ are both homomorphisms extending $A \\xrightarrow{f} B \\xrightarrow{g} C \\rightarrow UFC$.\\\\\n    (c) Given a set $A$, we write $PA$ for the set of all subsets of $A$.\\\\\n    We can make $P$ into a functor $\\mathbf{Set} \\to \\mathbf{Set}$, given $A \\xrightarrow{f} B$, we defined $Pf(A') = \\{f(a) | a \\in A'\\}$ for $A' \\subseteq A$.\\\\\n    But we also have a functor $P^* : \\mathbf{Set} \\to \\mathbf{Set}^{op}$ defined on objects by $P$, but $P^* f(B') = \\{a \\in A | f(a) \\in B'\\}$ for $B' \\subseteq B$.\\\\\n    By a \\emph{contravariant} functor $\\mathcal{C} \\to \\mathcal{D}$, we mean a functor $\\mathcal{C} \\to \\mathcal{D}^{op}$ (or $\\mathcal{C}^{op} \\to \\mathcal{D}$). A \\emph{covariant} functor is one that doesn't reverse arrows (in $op$ I guess?).\\\\\n    (d) Let $K$ be a field. We have a functor $*:\\mathbf{Mod_K} \\to \\mathbf{Mod_K}^{op}$ defined by $V^* = \\{ \\text{ linear maps }  V \\to K\\}$, and if $V \\xrightarrow{f} W$, $f^*(\\theta:W \\to K) = \\theta f$.\\\\\n    (e) We have a functor $op: \\mathbf{Cat} \\to \\mathbf{Cat}$, which is the identity on morphisms (note that this is a covariant).\\\\\n    (f) A functor between monoids is a monoid homomorphism.\\\\\n    (g) A functor between posets is an order-preserving map.\\\\\n    (h) Let $G$ be a group. A functor $F \\circ G \\to \\mathbf{Set}$ consists of a set $A=F*$ together with an action of $G$ on $A$, i.e. a \\emph{permutation representation} of $G$.\\\\\n    Similarly, a functor $G \\to \\mathbf{Mod_K}$ is a $K$-linear representation of $G$.\\\\\n    (i) The construction of the fundamental group $\\pi(X,X)$ of a space $X$ with basepoint $X$ is a functor $\\mathbf{Top}* \\to \\mathbf{Gp}$ where $\\mathbf{Top}*$ is the category of spaces with a chosen basepoint.\\\\\n    Similarly, the fundamental groupoid is a functor $\\mathbf{Top} \\to \\mathbf{Gpd}$, where $\\mathbf{Gpd}$ is the category of groupoids and functors between them.\n\\end{eg}\n\n\\begin{defi} (1.6)\\\\\n    Let $\\mathcal{C}$ and $\\mathcal{D}$ be categories and $F, G: \\mathcal{C}\\rightrightarrows \\mathcal{D}$ (why two arrows?) two functors.\\\\\n    A \\emph{natural transformation} $\\alpha:F \\to G$ consists of an assignment $A \\to \\alpha_A$ from $\\ob \\mathcal{C}$ to $\\mor \\mathcal{D}$ (think about this), such that $\\dom_{\\alpha_A} = FA$ and $\\cod_{\\alpha A} = G A$ for all $A$, and for all $A \\xrightarrow{f} B$ in $\\mathcal{C}$, the square \n    \\begin{equation*}\n        \\begin{aligned}\n            &FA &\\xrightarrow{Ff} &FB\\\\\n            &\\downarrow \\alpha_A & &\\downarrow \\alpha_B\\\\\n            &GA &\\xrightarrow{Gf} & GB\n        \\end{aligned}\n    \\end{equation*}\n    commutes (i.e. $\\alpha_B(Ff) = (Gf)_{\\alpha A}$).\n\\end{defi}\n\n(1.3) (l) Given categories $\\mathcal{C}$ and $\\mathcal{D}$, we write $[\\mathcal{C},\\mathcal{D}]$ for the category whose objects are functors $\\mathcal{C} \\to \\mathcal{D}$ and whose morphisms are natural transformations.\n\n\\begin{eg} (1.7)\\\\\n    (a) Let $K$ be a field, $V$ a vector space over $K$. There is a linear map $\\alpha_V : V \\to V^{**}$ given by $\\alpha_V (v) \\theta = \\theta(v)$ for $\\theta \\in V^*$.\\\\\n    This is the $V$-component of a natural transformation $1_{\\mathbf{Mod_K}} \\to **: \\mathbf{Mod_K} \\to \\mathbf{Mod_K}$.\\\\\n    (b) For any set $A$, we have a mapping $\\sigma_A:A \\to PA$ sending $a$ to $\\{a\\}$. If $f:A \\to B$, then $Pf\\{a\\} = \\{f(a)\\}$. So $\\sigma$ is a natural transformation $1_{\\mathbf{Set}} \\to P$.\\\\\n    (c) Let $F$:$\\mathbf{Set} \\to \\mathbf{Gp}$ be the free group functor (1.5(b)), and $U: \\mathbf{Gp} \\to \\mathbf{Set}$ the forgetful functor. The inclusions $A \\to UFA$ form a natural transformation $1_{\\mathbf{Set}} \\to UF$.\\\\\n    (d) Let $G,H$ be groups and $f,g: G \\rightrightarrows H$ be two homomorphisms. A natural transformation $\\alpha: f \\to g$ corresponds to an element $h=\\alpha_*$ of $H$, s.t. $h f(x) \\to g(x) h$ for all $x \\in G$ or equivalently $f(x) = h^{-1} g(x) h$, i.e. $f$ and $g$ are conjugate group homomorphisms.\\\\\n    (e) Let $A$ and $B$ be two $G$-sets, regarded as functors: $G \\rightrightarrows \\mathbf{Set}$. A natural transformation $A \\to B$ is a function $f$ satisfying $f(g\\cdot a) = g \\cdot f(a)$ for all $a \\in A$, i.e. a $G$-equivariant map.\n\\end{eg}\n\n\\begin{lemma} (1.8)\\\\\n    Let $F,G: \\mathcal{C} \\rightrightarrows \\mathcal{D}$ be two functors, and $\\alpha: F \\to G$ a natural transformation. Then $\\alpha$ is an isomorphism in $[\\mathcal{C},\\mathcal{D}]$ iff each $\\alpha_A$ is an isomorphism in $\\mathcal{D}$.\n    \\begin{proof}\n        Forward is trivial. For backward, suppose each $\\alpha_A$ has an inverse $\\beta_A$. Given $f:A \\to B$ in $\\mathcal{C}$, we need to show that \n        \\begin{equation*}\n            \\begin{aligned}\n                &GA &\\xrightarrow{Gf} &GB\\\\\n                &\\downarrow \\beta_A & &\\downarrow \\beta_B\\\\\n                &FA &\\xrightarrow{Ff} & FB\n            \\end{aligned}\n        \\end{equation*}\n    \\end{proof}\n    commutes. But as $\\alpha$ is natural, \n    $$(Ff)\\beta_A = \\beta_B \\alpha_B (Ff)\\beta_A = \\beta_B (Gf) \\alpha_A \\beta_A = \\beta_B (Gf)$$\n    So $\\beta$ is a natural transformation as well.\n\\end{lemma}\n\n\\begin{defi} (1.9)\\\\\n    Let $\\mathcal{C}$ and $\\mathcal{D}$ be categories. By an \\emph{equivalence} between $\\mathcal{C}$ and $\\mathcal{D}$, we mean a pair of functors $F:\\mathcal{C} \\to \\mathcal{D}$, $G:\\mathcal{D} \\to \\mathcal{C}$ together with natural isomorphisms $\\alpha: 1_\\mathcal{C} \\to GF$ and $\\beta: FG \\to 1_\\mathcal{D}$.\\\\\n    We write $\\mathcal{C} \\cong \\mathcal{D}$ if $\\mathcal{C}$ and $\\mathcal{D}$ are equivalent.\\\\\n    We say a property $P$ of categories is a \\emph{categorical property} if whenever $\\mathcal{C}$ has $P$ and $\\mathcal{C} \\cong \\mathcal{D}$, then $\\mathcal{D}$ has $P$.\\\\\n    For example, being a groupoid or a preorder are categorical properties, but being a group or a partial order are not.\n\\end{defi}\n\n\\begin{eg} (1.10)\\\\\n    (a) The category $\\mathbf{Part}$ is equivalent to the category $\\mathbf{Set}_*$ of pointed sets (and basepoint preserving functions (as morphisms)):\\\\\n    $\\bullet$ We define $F:\\mathbf{Set}_* \\to \\mathbf{Part}$ by $F(A,a) = A \\setminus \\{a\\}$, and if $f:(A,a) \\to (B,b)$, then $Ff(x) = f(x)$ if $f(x) \\neq b$, and undefined otherwise;\\\\\n    $\\bullet$ and $G: \\mathbf{Part} \\to \\mathbf{Set}_*$ by $G(A) = A^+ = (A \\cup \\{A\\},A)$, and if $f:A \\to B$ is a partial function, we define $Gf:A^+ \\to B^+$ by $Gf(x) = f(x)$ if $x \\in A$ and $f(x)$ defined, and equals $B$ otherwise.\\\\\n    The composite $FG$ is the identity on $\\mathbf{Part}$, but $GF$ is not the identity. However, there is an isomoprhism $(A,a) \\to ((A \\setminus \\{a\\})^+,A \\setminus\\{a\\})$ sending $a$ to $A \\setminus \\{a\\}$ and everything else to itself and this is natural.\\\\\n    Note that there can be no isomoprhism from $\\mathbf{Set}_*$ to $\\mathbf{Part}$, since $\\mathbf{Part}$ has a 1-element isomorphism class $\\{\\phi\\}$ but $\\mathbf{Set}_*$ doesn't.\\\\\n    (So we see that equivalent categories can be non-isomorphic. According to a \\href{https://mathoverflow.net/questions/30032/equivalence-versus-isomorphism-of-categories}{post} on SO, this usually happens when there are multiple copies of the \\emph{same} thing in one but not the other. However, we can't generally \\emph{discard obsolete copies} in one as that generally requires AC and is not a very useful thing to do anyway -- In short, \\emph{identifying isomorphic objects is often an extremely bad idea}.)\\\\\n    (b) The category $\\mathbf{fdMod_K}$ of finite-dimensional vector spaces over $K$ is equivalent to $\\mathbf{fdMod_K}^{op}$, the functors in both directions are $*$ (the dual operator) and both isomorphisms are the natural transformations of 1.7(a) (double dual).\\\\\n    (c) $\\mathbf{fdMod_K}$ is also equivalent to $\\mathbf{Mat}_K$ (1.3(j)):\\\\\n    We define $F:\\mathbf{Mat_K} \\to \\mathbf{fdMod_K}$ by $F(n) = K^n$, and $F(A)$ is the linear map represented by $A$ w.r.t. the standard bases of $K^n$ and $K^p$.\\\\\n    To define $G:\\mathbf{fdMod_K} \\to \\mathbf{Mat_K}$, choose a basis for each finite dimensional vector space, and define $G(V) = \\dim V$, $G(V \\xrightarrow{f} W)$ to be the matrix representing $f$ w.r.t. chosen bases. $GF$ is the identity, provided we choose the standard bases for the spaces $K^n$; $FG \\neq 1$, but the chosen bases give isomorphisms $FG(V) = K^{\\dim V} \\to V$ for each $V$, which form a natural isomorphism.\n\\end{eg}\n\n---Lecture 4---\n\n\\begin{defi} (1.11)\\\\\n    Let $\\mathcal{C} \\xrightarrow{F} \\mathcal{D}$ be a functor.\\\\\n    (a) We say $F$ is \\emph{faithful} if, given $f,f' \\in \\mor \\mathcal{C}$ with $\\dom f = \\dom f'$, $\\cod f = \\cod f'$, and $Ff = Ff'$, then $f=f'$ (injectivity on morphisms. The name comes more from representation theory);\\\\\n    (b) We say $F$ is \\emph{full} if, given $FA \\xrightarrow{g} FB$ in $\\mathcal{D}$, there exists $A \\xrightarrow{f} B$ in $\\mathcal{C}$ with $Ff = g$. (this is something like surjectivivity on morphisms, but see below);\\\\\n    (c) We say  $F$ is \\emph{essentially surjective} if, for every $B \\in \\ob \\mathcal{D}$, there exists $A \\in \\ob \\mathcal{C}$ and isomorphism $FA \\to B$ in $\\mathcal{D}$.\\\\\n    We say a subcategory $\\mathcal{C}' \\subseteq \\mathcal{C}$ is full if the inclusion $\\mathcal{C}' \\to \\mathcal{C}$ is a full functor (basically, if the objects are kept, any morphism between them must be kept). For example, $\\mathbf{Gp}$ is a full subcategory of $\\mathbf{Mon}$ (the category of all monoids), but $\\mathbf{Mon}$ is not a full subcategory of the category $\\mathbf{SGp}$ of semigroups (consider e.g. the homomorphism that sends everything in $(\\Z,\\cdot)$ to $(0,\\cdot)$ (which is also a semigroup); but this doesn't preserve 1 so is not a morphism in $\\mathbf{Mon}$).\n\\end{defi}\n\n\\begin{lemma} (1.12)\\\\\n    Assuming the axiom of choice, a functor $F:\\mathcal{C} \\to \\mathcal{D}$ is part of an equivalence $\\mathcal{C} \\simeq \\mathcal{D}$ if it's full, faithful, and essentially surjective.\n    \\begin{proof}\n        $\\Rightarrow$: Suppose given $G,\\alpha,\\beta$ as in (1.9). Then for each $B \\in \\ob\\mathcal{D}$, $\\beta_B$ is an isomorphism $FGB \\to B$, so $F$ is essentially surjective.\\\\\n        Given $A \\xrightarrow{f} B$ in $\\mathcal{C}$, we can recover $f$ from $Ff$ as composite $A \\xrightarrow{\\alpha_A} GFA \\xrightarrow{GFf} GFB \\xrightarrow{\\alpha_b^{-1}} B$. Hence if $A \\xrightarrow{f'}B$ satisfies $Ff = Ff'$, then $f=f'$. So $F$ is faithful;\\\\\n        Lastly, for fullness, given $FA \\xrightarrow{g} FB$, define $f$ to be the composite $A \\xrightarrow {\\alpha_A} GFA \\xrightarrow{Gg} GFB \\xrightarrow{\\alpha_B^{-1}} B$. Then $GFf = \\alpha_B f \\alpha_A^{-1}$, which by construction is just $Gg$. But $G$ is faithful for the same reason as $f$, so $Ff = g$.\n\n        $\\Leftarrow$: (need to find suitable $G,\\alpha,\\beta$ for $F$.) For each $B \\in \\ob \\mathcal{D}$, choose $GB \\in \\ob \\mathcal{C}$ and an isomorphism $\\beta_B : FGB \\to B$ in $\\mathcal{D}$. Given $B \\xrightarrow{g} B'$, define $Gg:GB \\to GB'$ to be the unique morphism whose image under $F$ is $FGB \\xrightarrow{\\beta_B} B \\xrightarrow{g} B' \\xrightarrow{\\beta_{B'}^{-1}} FGB'$.\\\\\n        Uniqueness implies functoriality: given $B' \\xrightarrow{g'} B''$, $(Gg')(Gg)$ and $G(g'g)$ have the same image under $F$, so they are equal.\\\\\n        By construction, $\\beta$ is a natural transformation $FG \\to 1_\\mathcal{D}$.\\\\\n        Given $A \\in \\ob \\mathcal{C}$, define $\\alpha_A: A \\to GFA$ to be the unique morphism whose image under $F$ is $FA \\xrightarrow{\\beta_{FA}^{-1}} FGFA$. $\\alpha_A$ is an isomorphism, since $\\beta_{FA}$ also has a unique pre-image under $F$. And $\\alpha$ is a natural transformation, since any naturality square for $\\alpha$ (the commutative square when we defined natural transformation) is mapped by $F$ to a commutative square, and $F$ is faithful.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{defi} (1.13) \\\\\n    By a \\emph{skeleton} of a category, we mean a full subcategory $\\mathcal{C}_0$ containing one object from each isomorphism class. We say $\\mathcal{C}$ is \\emph{skeletal} if it's a skeleton of itself.\\\\\n    For example, $\\mathbf{Mat_K}$ is a skeletal, and the image of $F:\\mathbf{Mat_K} \\to \\mathbf{fdMod_K}$ of 1.10(c) is a skeleton of $\\mathbf{fdMod_K}$.\\\\\n    (there are some examples on wikipedia)\n\\end{defi}\n\nWarning: almost any assertion about skeletons is equivalent to axiom of choice (see q2 on example sheet 1).\n\n\\begin{defi} (1.14)\\\\\n    Let $A \\xrightarrow{f} B$ be a morphism in $\\mathcal{C}$.\\\\\n    (a) We say $f$ is a \\emph{monomorphism} (or $f$ is \\emph{monic}) if, given any pair $C \\stackrel[h]{g}{\\rightrightarrows} A$, $fg=fh$ implies $g=h$.\\\\\n    (b) We say $f$ is an \\emph{epimorphism} (or \\emph{epic}) if it's a monomorphism in $\\mathcal{C}^{op}$, i.e. if $gf = hf$ implies $g=h$.\\\\\n    We denote monomorphisms by $A \\stackrel{f}{\\rightarrowtail} B$, and epimorphisms by $A \\stackrel{f}{\\twoheadrightarrow} B$.\\\\\n    Any isomorphism is monic and epic: more generally, if $f$ has a left inverse (i.e. $\\exists g$ s.t. $gf$ is an identity), then it's monic. We call such monomorphisms \\emph{split}.\\\\\n    We say $\\mathcal{C}$ is a \\emph{balanced} category if any morphism which is both monic and epic is an isomorphism.\n\\end{defi}\n\n\\begin{eg} (1.15)\\\\\n    (a) As usual we consider $\\mathbf{Set}$ first. In $\\mathbf{Set}$, monomorphisms correspond to injections ($\\Leftarrow$ is easy (ok); for $\\Rightarrow$, take $C \\rightrightarrows 1 = \\{*\\}$), and epimorphsims correspond to surjections ($\\Leftarrow$ is easy; for $\\Rightarrow$, use morphisms $B \\rightrightarrows 2 = \\{0,1\\}$). So $\\mathbf{Set}$ is balanced.\\\\\n    (b) In $\\mathbf{Gp}$, monomorphisms again correspond to injections (for $\\Rightarrow$ use homomorphisms $\\Z \\to A$); epimorphisms again correspond to surjections ($\\Rightarrow$ use \\href{https://en.wikipedia.org/wiki/Free_product#Generalization:_Free_product_with_amalgamation}{free products with amalgamation} -- this is a non-trivial fact about groups, read more if free). So $\\mathbf{Gp}$ is also balanced.\\\\\n    (c) In $\\mathbf{Rng}$ (obvious notation), monomorphisms correspond to injections (proof is much like for $\\mathbf{Gp}$). However, not all epimorphisms are surjective. For example the inclusion $\\Z \\to \\Q$ is an epimorphism, since if $\\Q \\stackrel[g]{f}{\\rightrightarrows} R$ (any ring) agree on all integers, they agree everywhere. So $\\mathbf{Rng}$ is not balanced.\\\\\n    (d) One final example is $\\mathbf{Top}$. Again, monomorphisms are injections and epimorphisms are surjections (and vice versa): proof is similar to $\\mathbf{Set}$ (check). However, $\\mathbf{Top}$ is not balanced since a continuous bijection need not have continuous inverse.\n\\end{eg}\n\n\\newpage\n\n\\section{The Yoneda Lemma}\n\n---Lecture 5---\n\\begin{defi} (2.1)\\\\\n    We say a category $\\mathcal{C}$ is \\emph{locally small} if, for any two objects $A,B$, the morphisms $A\\to B$ in $\\mathcal{C}$ form a set $\\mathcal{C}(A,B)$.\\\\\n    If we fix $A$ and let $B$ vary, the assignment $B \\to \\mathcal{C}(A,B)$ becomes a functor $\\mathcal{C}(A,-):\\mathcal{C} \\to \\mathbf{Set}$: given $B \\xrightarrow{f} C$, $\\mathcal{C}(A,f)$ is the mapping $g \\to fg$ for all $g \\in \\mathcal{C}(B,C)$. Similarly, $A \\to \\mathcal{C}(A,B)$ defines a functor $\\mathcal{C}(-,B):\\mathcal{C}^{op} \\to \\mathbf{Set}$ (for $A \\xrightarrow{f} C \\in \\mor \\mathcal{C}^{op}$, maps $g \\to gf$).\n\\end{defi}\n\n\\begin{lemma} (2.2)\\\\\n    (i) Let $\\mathcal{C}$ be a locally small category, $A \\in \\ob \\mathcal{C}$ and $F:\\mathcal{C} \\to \\mathbf{Set}$ a functor. Then natural transformations $\\mathcal{C}(A,-) \\to F$ are in bijection with elements of $FA$;\\\\\n    (ii) Moreover, this bijection is natural in $A$ and $F$.\n    \\begin{proof}\n        (i) Given $\\alpha$:$\\mathcal{C}(A,-) \\to F$, we define $\\Phi(\\alpha) = \\alpha_A(1_A) \\in FA$.\\footnote{Note $1_A \\in \\mathcal{C}(A,A)$, and $\\alpha_A \\in \\mor \\mathbf{Set}$ but $\\mor \\mathbf{Set}$ are just functions between sets, so this makes sense.}\\\\\n        Conversely, given $x \\in FA$, we define $\\Psi(x): \\mathcal{C}(A,-) \\to F$ by $\\Psi(x)_B (A \\xrightarrow{f} B) = (Ff)(x) \\in FB$.\\footnote{It seems a bit confusing why this is a natural transformation, but looking carefully it basically defines a function between sets, i.e. is in $\\mor \\mathbf{Set}$.}\\\\\n        $\\Psi(x)$ is natural: given $g:B \\to C$, we have\n        \\begin{equation*}\n            \\begin{aligned}\n                \\Psi(x)_C \\mathcal{C}(A,g) (f) &= \\Psi(x)_C (gf) = F(gf)(x),\\\\\n                (Fg) \\Psi(x)_B(f) &= (Fg)(Ff)(x) = F(gf)(x)\n            \\end{aligned}\n        \\end{equation*}\n        Now given $x \\in FA$, $\\Phi\\Psi(x) = \\Psi(X)_A (1_A) = F(1_A)(x) = x$; given $\\alpha$,\n        \\begin{equation*}\n            \\begin{aligned}\n                \\Psi\\Phi(\\alpha)_B(f) \\Psi(\\alpha_A(1_A))_B(f) &= Ff(\\alpha_A(1_A))\\\\\n                &= \\alpha_B\\mathcal{C}(A,f)(1_A) = \\alpha_B(f)\n            \\end{aligned}\n        \\end{equation*}\n        So $\\Psi\\Phi(\\alpha)=\\alpha$. So $\\Psi\\Phi$ and $\\Phi\\Psi$ are both identities on their respective domain (so we have a bijection).\n    \\end{proof}\n\\end{lemma}\n\n\\begin{coro} (2.3)\\\\\n    The assignment $A \\to \\mathcal{C}(A,-)$ defines a full and faithful functor $\\mathcal{C}^{op} \\to [\\mathcal{C},\\mathbf{Set}]$.\n    \\begin{proof}\n        Put $F = \\mathcal{C}(B,-)$ in 2.2(i): we get a bijection between $\\mathcal{C}(B,A)$ and morphisms $\\mathcal{C}(A,-) \\to \\mathcal{C}(B,-)$ in $[\\mathcal{C},\\mathbf{Set}]$\\footnote{Think very carefully about this... Given a morphism in $\\mathcal{C}(A,-) \\to \\mathcal{C}(B,-)$, the above gives us a way to identify it uniquelly with an element in $\\mathcal{C}(B,A)$ which is in $\\mor \\mathcal{C}^{op}$. But that alone is not enough; we also need the above functor to take that morphism \\emph{directly} to the original morphism. Luckily this is the case by the proof of 2.2(i), which is also explained in the later half of the sentence above.}. We need to verify this is functorial: but it sends $f:B \\to A$ to the natural transformation $g \\to gf$. So functoriality follows from associativity.\n    \\end{proof}\n\\end{coro}\n\nWe call this functor (or the functor $\\mathcal{C} \\to [\\mathcal{C}^{op}, \\mathbf{Set}]$ sending $A$ to $\\mathcal{C}(-,A)$) the \\emph{Yoneda embedding} of $\\mathcal{C}$, and denote it by $Y$.\n\nNow let's go back to prove 2.2(ii):\n\\begin{proof}\n    (ii) Suppose for the moment that $\\mathcal{C}$ is small, so that $[\\mathcal{C},\\mathbf{Set}]$ is locally small.\\footnote{Elements in $\\mor [\\mathcal{C},\\mathbf{Set}]$ correspond to those in $\\mor \\mathcal{C}^{op}$ by Yoneda.} Then we have two functors $\\mathcal{C} \\times [\\mathcal{C},\\mathbf{Set}] \\to \\mathbf{Set}$: one sends $(A,F)$ to $FA$, and the other is the composite: $\\mathcal{C} \\times [\\mathcal{C},\\mathbf{Set}] \\xrightarrow{Y \\times 1} [\\mathcal{C},\\mathbf{Set}]^{op} \\times [\\mathcal{C},\\mathbf{Set}] \\xrightarrow{[\\mathcal{C},\\mathbf{Set}](-;-)} \\mathbf{Set}$.\\footnote{The second operator maps two functors two the set of natural transformations between them?}\\\\\n    2.2(ii) says that these are naturally isomorphic. We can translate this into an elementary statement, making sense even when $\\mathcal{C}$ isn't small. Given $A \\xrightarrow{f} B$ and $F \\xrightarrow{\\alpha}G$, the two ways of producing an element of $GB$ from a natural transformation $\\beta:\\mathcal{C}(A,-) \\to F$ give the same result, namely $$\\alpha_B(Ff)\\beta_A(1_A) = (Gf)\\alpha_A\\beta_A(1_A)$$ which is equal to $\\alpha_B\\beta_B(f)$.\n\\end{proof}\n\n\\begin{defi} (2.4)\\\\\n    We say a functor $F:\\mathcal{C} \\to \\mathbf{Set}$ is \\emph{representable} if it's isomorphic to $\\mathcal{C}(A,-)$ for some $A$. By a representation of $F$, we mean a pair $(A,x)$ where $x \\in FA$ is such that $\\Psi(x)$ is an isomorphism.\\\\\n    We also call $x$ a \\emph{universal element} of $F$.\n\\end{defi}\n\n\\begin{coro} (2.5)\\\\\n    If $(A,x)$ and $(B,y)$ are both representations of $F$, then there's a unique isomorphism $f:A \\to B$ such that $(Ff)(x) = y$.\n    \\begin{proof}\n        Consider the composite $\\mathcal{C}(B,-) \\xrightarrow{\\Psi(y)^{-1}}F \\xrightarrow{\\Psi(x)} \\mathcal{C}(A,-)$. By (2.3) this is of the form $Y(f)$ for a unique isomorphism $f:A \\to B$, and the diagram\n\n        \\begin{tikzcd}\n            \\mathcal{C}(B,-) \\arrow[rd,\"\\Psi(y)\"'] \\arrow[rr,\"Y(f)\"] & & \\mathcal{C}(A,-) \\arrow[dl,\"\\Psi(x)\"]\\\\\n            &F &\n        \\end{tikzcd}\n\n        commutes iff $(Ff)(x) = y$.\n    \\end{proof}\n\\end{coro}\n\n\\begin{eg} (2.6)\\\\\n    (a) The forgetful functor $\\mathbf{Gp} \\to \\mathbf{Set}$ is representable by $(\\Z,1)$, $\\mathbf{Rng} \\to \\mathbf{Set}$ by $(\\Z[X],X)$, and $\\mathbf{Top} \\to \\mathbf{Set}$ by $(\\{*\\},*)$.\\\\\n    (b) The functor $P^*: \\mathbf{Set}^{op} \\to \\mathbf{Set}$ is representable by $(\\{0,1\\},\\{1\\})$: this is the bijection between subsets and characteristic functions.\\\\\n    (c) Let $G$ be a group. The unique (up to isomorphism) representable functor $G(*,-): G \\to \\mathbf{Set}$ is the \\emph{Cayley representation} of $G$, i.e. the set $UG$ with $G$ acting by left multiplication.\\\\\n    (d) Let $A$ and $B$ be two objects of a small category $\\mathcal{C}$. We have a functor $\\mathcal{C}^{op} \\to \\mathbf{Set}$ sending $C$ to $\\mathcal{C}(C,A) \\times \\mathcal{C}(C,B)$. A representation of this, if it exists, is called a (categorical) \\emph{product} of $A$ and $B$, and denoted $(A \\times B,(A \\times B \\xrightarrow{\\pi_1} A, A \\times B \\xrightarrow{\\pi_2} B))$.\\\\\n    This pair has the property that, for any pair $(C \\xrightarrow{f}A,C\\xrightarrow{g}B)$, there's a unique $C \\xrightarrow{h} A \\times B$ with $\\pi_1 h = f$ and $\\pi_2 h = g$.\\\\\n    Products exist in many categories of interest: in $\\mathbf{Set}$, $\\mathbf{Gp}$, $\\mathbf{Rng}$, $\\mathbf{Top}$,..., they are \\emph{just} cartesian products, in posets they are binary meets (see sheet 1 Q1).\\\\\n    Dually, we have the notion of \\emph{coproduct} $(A+B,A \\xrightarrow{\\mu_1} A + B, B \\xrightarrow{\\mu_2}A+B)$.\\\\\n    These also exist in many categories of interest.\\\\\n    ---Lecture 6---\\\\\n    (f) (Lecturer didn't like (e) so jumped to (f) directly) Let $A \\stackrel[g]{f}{\\rightrightarrows} B$ be morphisms in locally small category $\\mathcal{C}$. We have a functor $F:\\mathcal{C}^{op} \\to \\mathbf{Set}$ defined by \n    \\begin{equation*}\n        \\begin{aligned}\n            F(C) = \\{h \\in \\mathcal{C}(C,A) | fh = gh\\}\n        \\end{aligned}\n    \\end{equation*}\n    A representation (see (2.4)) of $F$, if it exists, is called an \\emph{equalizer} of $(f,g)$: It consists of an object $E$ and a morphism $E \\xrightarrow{e} A$ s.t. $fe=ge$, and every $h$ with $fh=gh$ factors uniquely (see proof of 2.9(i) which gives an insight of what this means) through $e$.\\\\\n    In $\\mathbf{Set}$, we take $E = \\{x \\in A | f(x) = g(x) \\}$ and $e=$inclusion. Similar constructions work in $\\mathbf{Gp},\\mathbf{Rng},\\mathbf{Top}$,...\\\\\n    Dually, we have the notion of \\emph{coequalizer}.\n\\end{eg}\n\n\\begin{rem} (2.7)\\\\\n    If $e$ occurs as an equalizer, then it is a monomorphism, since any $h$ factors through it in at most one way. We say a monomorphism is \\emph{regular} if it occurs as an equalizer.\\\\\n    Split monomorphisms are regular (cf sheet1 Q6(i)).\\\\\n    Note that regular epic monomorphisms are isomorphisms: if the equalizer $e$ of $(f,g)$ is epic, then $f=g$, so $e \\cong 1_{\\cod e}$.\n\\end{rem}\n\n\\begin{defi} (2.8)\\\\\n    Let $\\mathcal{C}$ be a category, $\\mathcal{G}$ a class of objects of $\\mathcal{C}$.\\\\\n    (a) We say $\\mathcal{G}$ is a \\emph{separating family} for $\\mathcal{C}$, if given $A \\stackrel[g]{f}{\\rightrightarrows} B$ such that $fh=gh$ for all $G \\xrightarrow{h} A$ with $G \\in \\mathcal{G}$, then $f=g$.\\\\\n    (i.e. the functors $\\mathcal{C}(G,-),G \\in \\mathcal{G}$, are collectively faithful.)\\\\\n    (b) We say $\\mathcal{G}$ is a \\emph{detecting family} if, given $A \\xrightarrow{f} B$ such that every $G \\xrightarrow{h} B$ with $G \\in \\mathcal{G}$ factors uniquely through $f$, then $f$ is an isomorphism.\\\\\n    If $\\mathcal{G} =\\{G\\}$, we call $G$ a \\emph{separator/detector}.\n\\end{defi}\n\n\\begin{lemma} (2.9)\\\\\n    (i) If $\\mathcal{C}$ is a balanced category, then any saparating family is detecting.\\\\\n    (ii) If $\\mathcal{C}$ has equalizers, then any detecting family is separating.\n    \\begin{proof}\n        (i) Suppose $\\mathcal{G}$ is separating and $A \\xrightarrow{f} B$ satisfies the condition of 2.8(b). If $B \\stackrel[h]{g}{\\rightrightarrows} C$ satisfy $gf=hf$, then $gx=hx$ for every $G \\xrightarrow{x} B$, so $g=h$, i.e. $f$ is epic.\\\\\n        Similarly if $D \\stackrel[l]{k}{\\rightrightarrows} A$ satisfy $fk=fl$, then $ky=ly$ for any $G \\xrightarrow{y} D$, since both are factorizations of $fky$ through $f$. So $k=l$, i.e. $f$ is monic.\\\\\n        But $\\mathcal{C}$ is balanced. So $f$ is an isomorphism.\\\\\n        (ii) Suppose $\\mathcal{G}$ is detecting and $A \\stackrel[g]{f}{\\rightrightarrows} B$ satisfies the condition of 2.8(a). Then the equalizer $E \\xrightarrow{e} A$ of $(f,g)$ is isomorphism, so $f=g$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{eg} (2.10)\\\\\n    (a) In $[\\mathcal{C},\\mathbf{Set}]$, the family $\\{\\mathcal{C}(A,-)|A \\in \\ob\\mathcal{C}\\}$ is both separating and detecting (just a restatement of Yoneda Lemma).\\\\\n    (b) In $\\mathbf{Set}$. $1=\\{*\\}$ (any one element set) is both a separator and a detector, since it represents the identity functor $\\mathbf{Set} \\to \\mathbf{Set}$.\\\\\n    Similarly, $\\Z$ is both in $\\mathbf{Gp}$, since it represents the forgetful functor $\\mathbf{Gp} \\to \\mathbf{Set}$.\\\\\n    Also, $2 = \\{0,1\\}$ is a coseparator and a codetector in $\\mathbf{Set}$, since it represents $P^*: \\mathbf{Set}^{op} \\to \\mathbf{Set}$.\\\\\n    (c) In $\\mathbf{Top}$, $1=\\{*\\}$ is a separator since it represents the forgetful functor $\\mathbf{Top} \\to \\mathbf{Set}$, but not a detector.\\\\\n    In fact, $\\mathbf{Top}$ has no detecting \\emph{set} of objects (note that this doesn't mean it has no detecting family).\\\\\n    For any infinite cardinal $\\kappa$, let $X$ be a discrete space of cardinality $\\kappa$, and $Y$ the same set with \\emph{co-$<\\kappa$} topology, i.e. $F \\subseteq Y$ is closed iff $F=Y$ or $\\Card F < \\kappa$ (think about, e.g. cocountable topology, then this name makes sense).\\\\\n    The identity $X \\to Y$ is continuous, but not a homeomorphism (topologically). So if $\\{G_i|i \\in I\\}$ is any set of spaces, taking $\\kappa > \\Card G_i$ for all $i$ yields an example to show that the set is not detecting.\\\\\n    (d) (some Algebraic Topology stuff) Let $\\mathcal{C}$ be the category of pointed connected $CW$-complexes and homotopy classes of (basepoint-preserving) continuous mappings.\\\\\n    JHC Whitehead proved that $X \\xrightarrow{f} Y$ in this category induces isomorphisms $\\pi_n(X) \\to \\pi_n(Y)$ for all $n$, then it's an isomorphism in $\\mathcal{C}$.\\\\\n    This says that $\\{S^n | n \\geq 1\\}$ is a detecting set of $\\mathcal{C}$.\\\\\n    But PJ Freyd showed there is no faithful functor $\\mathcal{C} \\to \\mathbf{Set}$, so no separating \\emph{set}: if $\\{ G_i | i \\in I\\}$ were separating, then $x \\to \\coprod \\mathcal{C}(G_i,x)$ (disjoint unions?) would be faithful.\\\\\n    Note that any functor of the form $\\mathcal{C}(A,-)$ preserves monomorphisms, but they don't normally preserves epimorphisms.\n\\end{eg}\n\n\\begin{defi} (2.11)\\\\\n    We say an object $P$ is \\emph{Projective} if, given \n    \\begin{equation*}\n        \\begin{aligned}\n            &P\\\\\n            &\\downarrow f\\\\\n            A\\stackrel{e}{\\twoheadrightarrow}&B\n        \\end{aligned}\n    \\end{equation*}\n    (recall the two head right arrow means epimorphisms) there exists $P \\xrightarrow{g} A$ with $eg = f$.\\\\\n    (If $\\mathcal{C}$ is locally small, this says $\\mathcal{C}(P,-)$ preserves epimorphisms).\\\\\n    Dually, an \\emph{injective} object of $\\mathcal{C}$ is a projective object of $\\mathcal{C}^{op}$.\\\\\n    Given a class $\\mathcal{E}$ of epimorphisms, we say $P$ is $\\mathcal{E}$-\\emph{projective} if it satisfies the condition for all $e \\in \\mathcal{E}$.\n\\end{defi}\n\n\\begin{lemma} (2.12)\\\\\n    Representable functors are (pointwise)(?) projective in $[\\mathcal{C},\\mathbf{Set}]$.\n    \\begin{proof}\n        Suppose given \n        \\begin{equation*}\n            \\begin{aligned}\n                &\\mathcal{C}(A,-)\\\\\n                &\\downarrow \\beta\\\\\n                F\\stackrel{\\alpha}{\\twoheadrightarrow}&G\n            \\end{aligned}\n        \\end{equation*}\n        where $\\alpha$ is pointwise surjective. By Yoneda, $\\beta$ corresponds to some $y \\in GA$, and we can find $x \\in FA$ with $\\alpha_A(x) = y$. Now if $\\gamma:\\mathcal{C}(A,-) \\to F$ corresponds to $x$, then naturality of the Yoneda bijection yields $\\alpha\\gamma =\\beta$.\n    \\end{proof}\n\\end{lemma}\n\n---Leture 7---\\\\\nFirst example class: Friday 26th October, 2pm MR3.\n\nLecture is happy to mark any question we hand in!\n\n\\newpage\n\n\\section{Adjunctions}\n\\begin{defi} (3.1)\\\\\n    Let $\\mathcal{C}$ and $\\mathcal{D}$ be two categories and $\\mathcal{C} \\xrightarrow{F} \\mathcal{D}$, $\\mathcal{D} \\xrightarrow{G} \\mathcal{C}$ two functors.\\\\\n    By an \\emph{adjunction} between $F$ and $G$ we mean a bijection between morphisms $FA \\xrightarrow{\\hat{f}} B$ in $\\mathcal{D}$ and morphisms $A \\xrightarrow{f} GB$ in $\\mathcal{C}$, which is natural in $A$ and $B$, i.e. given $A' \\xrightarrow{g} A$ and $B \\xrightarrow{h} B'$, we have $h\\hat{f} (Fg) = \\widehat{(Gh)fg}: FA' \\to B'$.\\\\\n\n    \\begin{tikzcd}\n        A' \\arrow[r,\"g\"] \\arrow[d,\"F\"] & A \\arrow[r,\"f\"] \\arrow[d,\"F\"] & GB \\arrow[r,\"Gh\"] & GB'\\\\\n        FA' \\arrow[r,\"Fg\"] & FA \\arrow[r,\"\\hat{f}\"] & B \\arrow[u,\"G\"] \\arrow[r,\"h\"] & B' \\arrow[u,\"G\"]\n    \\end{tikzcd}\n\n    We say $F$ is \\emph{left adjoint} to $G$, and write $(F \\dashv G)$.\n\\end{defi}\n\n\\begin{eg} (3.2)\\\\\n    (a) The free functor $\\mathbf{Set} \\xrightarrow{F} \\mathbf{Gp}$ is left adjoint to the forgetful functor $\\mathbf{Gp} \\xrightarrow{U} \\mathbf{Set}$, since any function $f:A \\to UB$ extends uniquely to a homomorphisms $\\hat{f}: FA \\to B$.\\\\\n    Naturality in $B$ is \\emph{easy} (lecturer says so), naturality in $A$ follows from the definition of $F$ as a functor.\\\\\n    (b) The forgetful functor $\\mathbf{Top} \\xrightarrow{U} \\mathbf{Set}$ has a left adjoint $D$ which equips any set with the discrete topology, \\emph{and} also a right adjoint $I$ which equips a set $A$ with the indiscrete topology $\\{\\phi,A\\}$.\\\\\n    (c) The functor $\\ob: \\mathbf{Cat} \\to \\mathbf{Set}$ (recall $\\mathbf{Cat}$ is the category of small categories) has a left adjoint $D$ sending $A$ to the \\emph{discrete} category with $\\ob(DA) = A$ and only identity morphisms, and a right adjoint $I$ sending $A$ to the category with $\\ob(IA) = A$ and one morphism $x \\to y$ for each $(x,y) \\in A \\times A$. In this case $D$ in turn has a left adjoint $\\pi_0$ sending a small category $\\mathcal{C}$ to its set of \\emph{connected components}, i.e. the quotient of $\\ob\\mathcal{C}$ by the smallest equivalence relation identifying $\\dom f$ with $\\cod f$ for all $f \\in \\mor \\mathcal{C}$.\\\\\n    (d) Let $M$ be the monoid $\\{1,e\\}$ with $e^2=e$. An object of $[M,\\mathbf{Set}]$ is a pair $(A,e)$ (the images of the object and multiplication by $e$ (as a morphism)), where $e:A \\to A$ satisfies $e^2=e$.\\\\\n    We have a functor $G:[M,\\mathbf{Set}] \\to \\mathbf{Set}$ sending $(A,e)$ to $\\{x \\in A | e(x) = x \\} = \\{e(x) | x \\in A\\}$ and a functor $F: \\mathbf{Set} \\to [M,\\mathbf{Set}]$ sending $A$ to $(A,1_A)$.\\\\\n    I claim $(F \\dashv G \\dashv F)$: given $f:(A,1_A) \\to (B,e)$, it must take values in $G(B,e)$, and any $g:(B,e) \\to (A,1_A)$ is determined by its values on the image of $e$.\\\\\n    (e) Let $\\mathbf{1}$ be the discrete category with one object $*$. For any $\\mathcal{C}$, there's a unique functor $\\mathcal{C} \\to \\mathbf{1}$: a left adjoint for this picks out an \\emph{initial} object of $\\mathcal{C}$, i.e. an object $I$ s.t. there exists a unique $I \\to A$ for each $A \\in \\ob \\mathcal{C}$.\\\\\n    Dually, a right adjoint for $\\mathcal{C} \\to \\mathbf{1}$ corresponds to a \\emph{terminal} object of $\\mathcal{C}$ (think about what this means).\\\\\n    (f) Let $A \\xrightarrow{f} B$ be a morphism in $\\mathbf{Set}$. We can regard $PA$ and $PB$ as posets, and we have functors $PA \\stackrel[P^*f]{Pf}{\\rightleftarrows} PB$.\\\\\n    I claim $(Pf \\dashv P^*f)$: we have $Pf(A') \\subseteq B' \\iff f(x) \\in B'$ for all $x \\in A' \\iff A' \\subseteq P^* f(B')$.\\\\\n    (g) (\\emph{Galois Connection}) Suppose given sets $A,B$ and a relation $R \\subseteq A \\times B$. We define mappings $(-)^l$,$(-)^r$ between $PA$ and $PB$ by \n    \\begin{equation*}\n        \\begin{aligned}\n            &S^r = \\{y \\in B| (\\forall x \\in S) ((x,y) \\in R) \\} \\text{ for } S \\subseteq A\\\\\n            &T^l = \\{x \\in A | (\\forall y \\in T) ((x,y) \\in R)\\} \\text{ for } T \\subseteq B\n        \\end{aligned}\n    \\end{equation*}\n    The mappings are order-reversing (i.e. contravariant functors), and $T \\subseteq S^r \\iff S \\times T \\subseteq R \\iff S \\subseteq T^l$.\\\\\n    We say $()^r$ and $()^l$ are \\emph{adjoint on the right}.(?)\\\\\n    (h) Let's now consider, as a functor, $P^* : \\mathbf{Set}^{op} \\to \\mathbf{Set}$ is self-adjoint on the right, since functions $A \\to PB$ correspond bijectively to subsets of $A \\times B$, and hence to functions $B \\to PA$.\n\\end{eg}\n\n\\begin{thm} (3.3)\\\\\n    Let $G:\\mathcal{D} \\to \\mathcal{C}$ be a functor. Then specifying a left adjoint for $G$ is equivalent to specifying an initial object of $(A \\downarrow G)$ for each $A \\in \\ob \\mathcal{C}$, where $(A \\downarrow G)$ has objects pairs $(B,f)$ with $A \\xrightarrow{f} GB$, and morphisms $(B,f) \\to (B',f')$ are morphisms $B \\xrightarrow{g} B'$ such that \n\n    \\begin{tikzcd}\n        A \\arrow[rd,\"f'\"'] \\arrow[rr,\"f\"] & & GB \\arrow[dl,\"Gg\"]\\\\\n        &GB' &\n    \\end{tikzcd}\n\n    commutes.\n    \\begin{proof}\n        Suppose given $(F \\dashv G)$. Consider the morphism $\\eta_A:A \\to GFA$ correspond to $FA \\xrightarrow{1_{FA}} FA$. Then $(FA,\\eta_A)$ is an object of $(A \\downarrow G)$. Moreover, given $g:FA \\to B$ and $f:A \\to GB$, the diagram \n\n        \\begin{tikzcd}\n            A \\arrow[rd,\"f\"'] \\arrow[rr,\"\\eta_A\"] & & GFA \\arrow[dl,\"Gg\"]\\\\\n            &GB &\n        \\end{tikzcd}\n\n        commutes iff\n\n        \\begin{tikzcd}\n            FA \\arrow[rd,\"\\hat{f}\"'] \\arrow[rr,\"1_{FA}\"] & & FA \\arrow[dl,\"g\"]\\\\\n            &B &\n        \\end{tikzcd}\n\n        commutes, i.e. $g=\\hat{f}$.\\\\\n        So $(FA,\\eta_A)$ is initial in $(A \\downarrow G)$.\\\\\n        Conversely, suppose given an initial object $(FA,\\eta_A)$ for each $(A \\downarrow G)$. Given $A \\xrightarrow{f} A'$, we define $Ff : FA \\to FA'$ to be the unique morphism (uniqueness by initiality of $FA$, commutativeness by the definition of morphsims in $(A\\downarrow G)$ (see above)) making \n\n        \\begin{tikzcd}\n            A \\arrow[r,\"\\eta_A\"] \\arrow[d,\"f\"] & GFA \\arrow[d,\"GFf\"]\\\\\n            A' \\arrow[r,\"\\eta_{A'}\"] & GFA'\n        \\end{tikzcd}\n\n        commute.\\\\\n        Functoriality follows from uniqueness: given $f': A' \\to A''$, $F(f'f)$ and $(Ff')(Ff)$ are both morphisms $(FA,\\eta_A) \\to (FA'',\\eta_{A''}F'f)$ in $(A \\downarrow G)$.\\\\\n        Note that we haven't finished: we still have to verify natural adjunctions. We'll finish off this next monday. \n\n        ---Lecture 8---\\\\\n        It's next monday now! Let's finish the proof:\\\\\n        To show $F \\dashv G$: given $A \\xrightarrow{f} GB$, we define $\\hat{f}:FA \\to B$ to be the unique morphism $(FA,\\eta_A) \\to (B,f)$ in $(a \\downarrow G)$. This is a bijection with inverse $(FA \\xrightarrow{g} B) \\to (A \\xrightarrow{\\eta_a} GFA \\xrightarrow{Gg} GB)$. The latter mapping is natural in $B$, as $G$ is a functor; and also in $A$, since by construction, $\\eta$ is a natural transformation $1_{\\mathcal{C}} \\to GF$.\n    \\end{proof}\n\\end{thm}\n\nGiven an adjunction $(F \\dashv G)$, the natural transformation $\\eta:1_{\\mathcal{C}} \\to GF$ emerging in the above proof (3.3) is called the \\emph{unit} of the adjunction.\\\\\nDually, we have a natural transformation traditionally denoted $\\varepsilon: FG \\to 1_{\\mathcal{D}}$ s.t. $\\varepsilon_B:FGB \\to B$ corresponds to $GB \\xrightarrow{1_{GB}} GB$, is called the \\emph{counit}.\n\n\\begin{coro} (3.4)\\\\\n    If $F$ and $F'$ are both left adjoint to $G:\\mathcal{D} \\to \\mathcal{C}$, then they are naturally isomorphic.\n    \\begin{proof}\n        For any $A$, $(FA,\\eta_A)$ and $(F'A,\\eta'_A)$ are both initial in $(A\\downarrow G)$, so there's a unique isomorphism $\\alpha_A:(FA,\\eta_A) \\to (F'A,\\eta'_A)$.\\\\\n        In any naturality square for $\\alpha$, the two ways round are both morphisms in $(A\\downarrow G)$ whose domain is initial, so they are equal. So $\\alpha$ is not only just an isomorphism (but also natural).\n    \\end{proof}\n\\end{coro}\n\n\\begin{lemma} (3.5)\\\\\n    Given $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D} \\stackrel[K]{H}{\\rightleftarrows} \\mathcal{E}$, with $(F \\dashv G)$ and $(H \\dashv K)$, we have $(HF \\dashv GK)$.\n    \\begin{proof}\n        We have bijections between morphisms $A \\to GKC$, morphisms $FA \\to KC$ and morphisms $HFA \\to C$, which are both natural in $A$ and $C$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{coro} (3.6)\\\\\n    Given a commutative square\n\n    \\begin{tikzcd}\n        \\mathcal{C} \\arrow[r] \\arrow[d] & \\mathcal{D} \\arrow[d]\\\\\n        \\mathcal{E} \\arrow[r] & \\mathcal{F}\n    \\end{tikzcd}\n\n    \\begin{equation*}\n        \\begin{aligned}\n            &\\mathcal{C}\\to &\\mathcal{D}\\\\\n            &\\downarrow & \\downarrow\\\\\n            &\\mathcal{E} \\to &\\mathcal{F}\n        \\end{aligned}\n    \\end{equation*}\n    of categories and functors, if the functors all have left adjoints, then the diagram of left adjoints commutes up to natural isomorphisms.\n    \\begin{proof}\n        By (3.5), both ways round the diagram of left adjoinst are left adjoint to the composite $\\mathcal{C} \\to \\mathcal{F}$, so by (3.4) they are isomorphic.\n    \\end{proof}\n\\end{coro}\n\n\\begin{thm} (3.7)\\\\\n    Given functors $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$, specifying an adjunction $(F \\dashv G)$ is equivalent to specifying natural transformations $\\eta: 1_{\\mathcal{C}} \\to GF$, $\\varepsilon:FG \\to 1_{\\mathcal{D}}$ satisfying the commutative diagrams,\n\n    \\begin{tikzcd}\n        F \\arrow[rd,\"1_F\"'] \\arrow[r,\"F\\eta\"] & FGF \\arrow[d,\"\\varepsilon F\"]\\\\\n        &F\n    \\end{tikzcd}\n    and\n    \\begin{tikzcd}\n        G \\arrow[rd,\"1_G\"'] \\arrow[r,\"\\eta G\"] & GFG \\arrow[d,\"G\\varepsilon\"]\\\\\n        &G\n    \\end{tikzcd}\n\n    which are sometimes called the \\emph{triangular identities} (for obvious reason).\\\\\n    The composition of functors and natural transformations in the above diagrams are sometimes called \\href{https://ncatlab.org/nlab/show/whiskering}{\\emph{whiskering}}.\n    \\begin{proof}\n        First suppose we are given $(F \\dashv G)$. Define $\\eta$ and $\\varepsilon$ as in (3.3) and its dual; now consider the composite\n        $$FA \\xrightarrow{F \\eta_A} FGFA \\xrightarrow{\\varepsilon_{FA}} FA$$\n        under the adjunction, this corresponds to\n        $$A \\xrightarrow{\\eta_A} GFA \\xrightarrow{1_{GFA}} GFA$$\n        But this also corresponds to $1_{FA}$, so $\\varepsilon_{FA} \\cdot F \\eta_A = 1_{FA}$.\\\\\n        The other identity is dual to this one.\\\\\n        Conversely, suppose we are given $\\eta$ and $\\varepsilon$ satisfying the trianglular identities. Given $A \\xrightarrow{f} GB$, let $\\Phi(f)$ be the composite $FA \\xrightarrow{Ff} FGB \\xrightarrow{\\varepsilon_B} B$; and given $FA \\xrightarrow{g} B$, let $\\Psi(g)$ be $A \\xrightarrow{\\eta_A} GFA \\xrightarrow{Gg} GB$. Then $\\Phi$ and $\\Psi$ are both natural; we now need to show they are inverse to each other. Let's do $\\Psi\\Phi$, say: now \n        \\begin{equation*}\n            \\begin{aligned}\n                \\Psi\\Phi(A \\xrightarrow{f} GB) &= A \\xrightarrow{\\eta_A} GFA \\xrightarrow{GFf} GFGB \\xrightarrow{G\\varepsilon_B} GB\\\\\n                &= A \\xrightarrow{f} GB \\xrightarrow{\\eta_{GB}} GFGB \\xrightarrow{G \\varepsilon_B} GB\\\\\n                &= f\n            \\end{aligned}\n        \\end{equation*}\n        where the last equality is triangular equality; and dually, $\\Phi\\Psi(g) = g$.\n    \\end{proof}\n\\end{thm}\n\n\\begin{lemma} (3.8)\\\\\n    Suppose given $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$ and natural isomorphisms $\\alpha:1_{\\mathcal{C}} \\to GF$, $\\beta: FG \\to 1_{\\mathcal{D}}$. Then there are isomorphisms $\\alpha': 1_{\\mathcal{C}} \\to GF$, $\\beta':FG \\to 1_{\\mathcal{D}}$ which satisfy the triangular identities. So $(F \\dashv G)$ (and $(G \\dashv F)$ ).\n    \\begin{proof}\n        We define $\\alpha'=\\alpha$ and, in attempt to fix $\\beta'$, define $\\beta'$ to be the composite\n        $$FG \\xrightarrow{(FG\\beta)^{-1}} FGFG \\xrightarrow{(F\\alpha_G)^{-1}} FG \\xrightarrow{\\beta} 1_{\\mathcal{D}}$$\n        Note that $FG\\beta = \\beta_{FG}$, since\n\n        \\begin{tikzcd}\n            FGFG \\arrow[r,\"FG\\beta\"] \\arrow[d,\"\\beta_{FG}\"] &FG \\arrow[d,\"\\beta\"]\\\\\n            FG \\arrow[r,\"\\beta\"] & 1_{\\mathcal{D}}\n        \\end{tikzcd}\n\n        commutes by naturality of $\\beta$, and $\\beta$ is monic. So it doesn't matter which way we choose above.\\\\\n        Now $(\\beta'_F)(F\\alpha')$ is the composite\n        \\begin{equation*}\n            \\begin{aligned}\n                &F \\xrightarrow{F\\alpha} FGF \\xrightarrow{(\\beta_{FGF})^{-1}} FGFGF \\xrightarrow{(F\\alpha_{GF})^{-1}} FGF \\xrightarrow{\\beta_F} F\\\\\n                &=F\\xrightarrow{(\\beta_F)^{-1}} FGF \\xrightarrow{FGF\\alpha} FGFGF \\xrightarrow{(F\\alpha_{GF})^{-1}} FGF \\xrightarrow{\\beta_F} F\\\\\n                &= F \\xrightarrow{(\\beta_F)^{-1}} FGF \\xrightarrow{\\beta_F} F\\\\\n                &= 1_F\n            \\end{aligned}\n        \\end{equation*}\n        Since $GF\\alpha = \\alpha_{GF}$ (similar reasoning as previous).\\\\\n        Now similarly $(G\\beta')(\\alpha'G)$ is\n        \\begin{equation*}\n            \\begin{aligned}\n                &G \\xrightarrow{\\alpha_G} GFG \\xrightarrow{(GFG\\beta)^{-1}} GFGFG\\xrightarrow{(GF\\alpha_G)^{-1}} GFG \\xrightarrow{G\\beta} G\\\\\n                &= G \\xrightarrow{(G\\beta)^{-1}} GFG \\xrightarrow{\\alpha_{GFG}} GFGFG \\xrightarrow{(GF\\alpha_G)^{-1}} GFG \\xrightarrow{G\\beta} G\\\\\n                &= G\\xrightarrow{(G\\beta)^{-1}} GFG \\xrightarrow{G\\beta} G\\\\\n                &= 1_G\n            \\end{aligned}\n        \\end{equation*}\n    \\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (3.9)\\\\\n    Suppose $G:\\mathcal{D} \\to \\mathcal{C}$ has a left adjoint $F$ with counit $\\varepsilon:FG \\to 1_{\\mathcal{D}}$, then:\\\\\n    (i) $G$ is faithful iff $\\varepsilon$ is pointwise epic;\\\\\n    (ii) $G$ is full and faithful iff $\\varepsilon$ is an isomorphism.\\\\\n    (and of course the dual results for unit -- change epic to monic).\\\\\n    \\begin{proof}\n        (i) Given $B \\xrightarrow{g} B'$, $Gg$ corresponds, under the adjunction, to the composite $FGB \\xrightarrow{\\varepsilon_B} B \\xrightarrow{g} B'$. Hence the mapping $g \\to Gg$ is injective on morphisms with domain $B$ (and specified codomain) iff $g \\to g\\varepsilon_B$ is injective, i.e. iff $\\varepsilon_B$ is an epimorphism.\\\\\n        (ii) The proof of this is actually very similar: $G$ is full and faithful iff $g \\to g\\varepsilon_B$ is bijective, but that forces $\\varepsilon$ to be an isomorphism: if $\\alpha:B \\to FGB$ is such that $\\alpha\\varepsilon_B = 1_{FGB}$, then this must be a two sided inverse as $\\varepsilon_B \\alpha \\varepsilon_B = \\varepsilon_B$, whence $\\varepsilon_B \\alpha = 1_B$. So $\\varepsilon_B$ is an isomorphism, for all $B$.\n    \\end{proof}\n\\end{lemma}\n\n---Lecture 9---\n\n\\begin{defi} (3.10)\\\\\n    By a \\emph{reflection}, we mean an adjunction in which the right adjoint is full and faithful (equivalently, the counit is an isomorphism).\\\\\n    We say a full subcategory $\\mathcal{C}' \\subseteq \\mathcal{C}$ is \\emph{reflective} if the inclusion $\\mathcal{C}'\\to\\mathcal{C}$ has a left adjoint.\n\\end{defi}\n\n\\begin{eg} (3.11)\\\\\n    (a) The category $\\mathbf{AbGp}$ of abelian groups is reflective in $\\mathbf{Gp}$, the left adjoint sends a group $G$ to its \\emph{abelianization} $G/G'$, where $G'$ is the subgroup generated by all commutators $[x,y] =xyx^{-1}y^{-1}, x,y \\in G$, which is always a normal subgroup of $G$ (see part II Galois Theory).\\\\\n    The unit of the adjunction is the quotient map $G \\to G/G'$.\\\\\n    (b) Given an abelian group $A$, let $A_t$ denote the torsion subgroup, i.e. the subgroup of elements of finite order. The assignment $A \\to A/A_t$ gives a left adjoint to the inclusion $\\mathbf{tfAbGp} \\to \\mathbf{AbGp}$ where $\\mathbf{tfAbGp}$ is the full subcategory of torsion-free abelian groups. $A \\to A_t$ is right adjoint to the inclusion $\\mathbf{tAbGp} \\to \\mathbf{AbGp}$, so this subcategory is coreflective.\\\\\n    (c) Let $\\mathbf{KHaus} \\subseteq \\mathbf{Top}$ be the full subcategory of compact Hausdorff spaces (see part IB Metric and Topological Spaces). The inclusion $\\mathbf{KHaus} \\to \\mathbf{Top}$ has a left adjoint $\\beta$, the \\emph{Stone-Čech compactification}.\\\\\n    (d) Let $x$ be a topological space. We say $A \\subseteq X$ is \\emph{sequentially closed} if $x_n \\to x_\\infty$ and $x_n \\in A$ for all $n$ implies $x_\\infty \\in A$.\\\\\n    We say $x$ is \\emph{sequential} if all sequentially closed sets are closed. Given a non-sequential space $X$, let $X_s$ be the same set with topology given by the sequentially open sets in $X$; the identity $X_s \\to X$ is continuous, and defines the counit of an adjunction betwen the inclusion $\\mathbf{Seq} \\to \\mathbf{Top}$ and the functor $X \\to X_s$.\\\\\n    (e) If $X$ is a topological space, the poset $CX$ of closed subsets of $X$ is reflective in the full power set $\\mathcal{P}X$, with reflector given by closure, and the poset $OX$ of open subsets is coreflective, with reflector given by interior.\n\\end{eg}\n\n\\newpage\n\n\\section{Limits}\n\n\\begin{defi} (4.1)\\\\\n    (a) Let $\\mathcal{J}$ be a category (almost always small, and often finite). By a \\emph{diagram of shape} $\\mathcal{J}$ in $\\mathcal{C}$, we mean a functor $D:\\mathcal{J} \\to \\mathcal{C}$. The objects $D(j), j \\in \\ob \\mathcal{J}$, are called \\emph{vertices} of the diagram, and the morphism $D(\\alpha)$, $\\alpha \\in \\mor\\mathcal{J}$ are called \\emph{edges} of $D$.\\\\\n    For example, if $\\mathcal{J}$ is the category \n\n    \\begin{tikzcd}\n        \\cdot \\arrow[r] \\arrow [dr] \\arrow [d] & \\cdot \\arrow[d]\\\\\n        \\cdot \\arrow[r] & \\cdot\n    \\end{tikzcd}\n\n    with 4 objects and 5 non-identity morphisms, a diagram of shape $\\mathcal{J}$ is a commutative square\n\n    \\begin{tikzcd}\n        A \\arrow[r,\"f\"] \\arrow[d,\"g\"] & B \\arrow[d,\"h\"]\\\\\n        C \\arrow[r,\"k\"] & D\n    \\end{tikzcd}\n\n    If $\\mathcal{J}$ is \n    \\begin{tikzcd}\n        \\cdot \\arrow[r] \\arrow [dr, shift left] \\arrow[dr, shift right] \\arrow [d] & \\cdot \\arrow[d]\\\\\n        \\cdot \\arrow[r] & \\cdot\n    \\end{tikzcd}\n    , a diagram of shape $\\mathcal{J}$ is a not-necessarily-commutative square.\n\n    (b) Given $D:\\mathcal{J} \\to \\mathcal{C}$, a \\emph{cone} over $D$ consists of an object $A$ of $\\mathcal{C}$ (the \\emph{apex} of the cone) together with morphisms $A\\xrightarrow{\\lambda_j} D(j)$ for each $j \\in \\ob \\mathcal{J}$, such that \n    \\begin{tikzcd}\n        & A \\arrow[dl,\"\\lambda_j\"'] \\arrow[dr,\"\\lambda_{j'}\"] &\\\\\n        D(j) \\arrow[rr,\"D(\\alpha)\"] & & D(j')\n    \\end{tikzcd}\n    commutes for all $j \\xrightarrow{\\alpha} j'$ in $\\mor \\mathcal{J}$.\\\\\n    (The $\\lambda_j$ are called the \\emph{legs} of the cone).\n\n    \\includegraphics[scale=0.5]{image/Cat_07.png}\n\n    Given cones $(A,(\\lambda_j)_{j \\in \\ob \\mathcal{J}})$ and $(B,(\\mu_j)_{j \\in \\ob \\mathcal{J}})$, a \\emph{morphism} of cones between them is a morphism $A \\xrightarrow{f} B$ s.t.\n    \\begin{tikzcd}\n        A \\arrow[rr,\"f\"] \\arrow[rd,\"\\lambda_j\"'] & & B \\arrow[dl, \"\\mu_j\"]\\\\\n        & D(j) &\n    \\end{tikzcd}\n    commutes for all $j$.\n\n    We write $\\mathbf{Cone}(D)$ for the category of cones over $D$ (I guess with morphisms being all the possible ones from above?).\\\\\n    (c) A \\emph{limit} for $D$ is a terminal object of $\\mathbf{Cone}(D)$, if this exists.\\\\\n    Dually, we have the notion of cone under a diagram, and of colimit ($=$ initial cone under $D$).\\\\\n    Alternatively, if $\\mathcal{C}$ is locally small, and $\\mathcal{J}$ is small, we have a functor $\\mathcal{C}^{op} \\to \\mathbf{Set}$ sending $A$ to the set of cones with apex $A$. A limit for $D$ is a representation of this functor.\\\\\n    If $\\triangle A$ denotes the constant diagram of shape $\\mathcal{J}$ with all vetices $A$ and all edges $1_A$, then a cone over $D$ with apex $A$ is the same thing as a natural transformation $\\triangle A \\to D$.\\\\\n    $\\triangle$ is a functor $\\mathcal{C} \\to [\\mathcal{J}, \\mathcal{C}]$ and $\\mathbf{Cone}(D)$ is the category $(\\triangle \\downarrow D)$ in the notation of ($3.3^{op}$) (the dual case of (3.3)...). So to say that every diagram of shape $J$ in $\\mathcal{C}$ has a limit is equivalent to saying that $\\triangle$ has a right adjoint. (We say $\\mathcal{C}$ \\emph{has limits} of shape $\\mathcal{J}$).\\\\\n    Dually, $\\mathcal{C}$ has colimits of shape $J$ iff $\\triangle:\\mathcal{C} \\to [\\mathcal{J},\\mathcal{C}]$ has a left adjoint.\n\\end{defi}\n\n\\begin{eg} (4.2)\\\\\n    (a) (Lecturer says he'll give a very simple example) Suppose $\\mathcal{J} = \\phi$ (a diagram of that here. It's easy to draw, but a bit hard to see). There's a unique diagram of shape $\\mathcal{J}$ in $\\mathcal{C}$, a cone over it is just an object (with no legs), and a morphism of cones is a morphism of $\\mathcal{C}$ (any one). So a limit for the empty diagram is a terminal object of $\\mathcal{C}$.\\\\\n    Dually, a colimit for it is an initial object.\\\\\n    (Indeed a very simple example)\n\n    ---Lecture 10---\n\n    (b) Let $\\mathcal{J}$ be the category with two objects and no non-identity morphisms. A diagram of shape $\\mathcal{J}$ is a pair of objects $A,B$; a cone over it is a span\n    \\begin{tikzcd}\n        & C \\arrow[dl] \\arrow[dr] &\\\\\n        A & & B\n    \\end{tikzcd}\n    ; and a limit for it is a product\n    \\begin{tikzcd}\n        & A\\times B \\arrow[dl,\"\\pi_1\"] \\arrow[dr, \"\\pi_2\"] &\\\\\n        A & & B\n    \\end{tikzcd}\n    as defined in 2.6(e). Dually, a colimit for it is a coproduct \n    \\begin{tikzcd}\n        A \\arrow[dr,\"\\nu_1\"] & & B \\arrow[dl,\"\\nu_2\"]\\\\\n        & A+B &\n    \\end{tikzcd}\n\n    (c) More generally, if $\\mathcal{J}$ is a small discrete category, a diagram of shape $\\mathcal{J}$ is a $\\mathcal{J}$-indexed family $(A_j|j \\in \\mathcal{J})$, and a limit for it is a product $(\\prod_{j \\in J} A_j \\xrightarrow{\\pi_j} A_j | j \\in \\mathcal{J})$ (Dually, $(A_j \\xrightarrow{\\nu_j} \\sum_{j \\in \\mathcal{J}} A_j | j \\in \\mathcal{J})$, or $\\coprod_{j \\in \\mathcal{J}} A_j$, but we usually use the first notation).\n\n    (d) Let $\\mathcal{J}$ be the category \n    \\begin{tikzcd}\n        \\cdot \\arrow[r,shift left, \"f\"] \\arrow[r, shift right, \"g\"'] & \\cdot\n    \\end{tikzcd}\n    . A diagram of shape $\\mathcal{J}$ is a parallel pair $A \\stackrel[g]{f}{\\rightrightarrows} B$; a cone over this is \n    \\begin{tikzcd}\n        & C \\arrow[dl,\"h\"] \\arrow[dr,\"k\"] &\\\\\n        A & & B\n    \\end{tikzcd}\n    satisfying $fh=k=gh$, or equivalently a morphism $C \\xrightarrow{h} A$ satisfying $fh = gh$. A (co)limit for the diagram is a (co)equalizer as defined in 2.6(f).\n\n    (e) Let $\\mathcal{J}$ be the category\n    \\begin{tikzcd}\n        & \\cdot \\arrow[d]\\\\\n        \\cdot \\arrow[r] & \\cdot\n    \\end{tikzcd}\n    . A diagram of shape $\\mathcal{J}$ is a cospan\n    \\begin{tikzcd}\n        & A \\arrow[d,\"f\"]\\\\\n        B \\arrow[r,\"g\"] & C\n    \\end{tikzcd} \n    , a cone over it is \n    \\begin{tikzcd}\n        D \\arrow[r,\"p\"] \\arrow[d,\"q\"] \\arrow[dr, \"r\"] & A\\\\\n        B & C\n    \\end{tikzcd}\n    satisfying $fp=r=gq$, or equivalently, a span $(p,q)$ completing the diagram to a commutative square. A limit for the diagram is called a \\emph{pullback} of $(f,g)$. In $\\mathbf{Set}$, the apex of the pullback is the \\emph{fibre product}\n    $$ A \\times_C B = \\{(x,y) \\in A \\times B | f(x) = g(y)\\}$$\n    Dually, colimits of shape $\\mathcal{J}^{op}$ are called \\emph{pushouts}. Given \n    \\begin{tikzcd}\n        A \\arrow[r,\"f\"] \\arrow[d,\"g\"] & B\\\\\n        C & \\\\\n    \\end{tikzcd}\n    , we \\emph{push $g$ along $f$} to get the RH side of the colimit square.\n\n    (f) (not very important for this course, but might explain why the term \\emph{limit} is used) Let $J$ be the poset of natural numbers. A diagram of shape $J$ is a \\emph{direct system} $A_0 \\xrightarrow{f_0} A_1 \\xrightarrow{f_1} A_2 \\xrightarrow{f_2} ...$\\\\\n    A colimit for this is called a \\emph{direct limit}: it consists of $A_\\infty$ equipped with morphisms $A_n \\xrightarrow{g_n} A_\\infty$ satisfying $g_n = g_{n+1}f_n$ for all $n$, and universal among such.\\\\\n    Dually, we have \\emph{inverse system} and \\emph{inverse limit}.\n\\end{eg}\n\n\\begin{thm} (4.3)\\\\\n    (i) Suppose $\\mathcal{C}$ has equalizers and all finite (respectively, small) products. Then $\\mathcal{C}$ has all finite (respectively, small) limits.\\\\\n    (ii) Suppose $\\mathcal{C}$ has pullbacks and a terminal object, then $\\mathcal{C}$ has all finite limits.\n    \\begin{proof}\n        (i) Suppose given $D:\\mathcal{J} \\to \\mathcal{C}$. Form the products $P=\\prod_{j \\in \\ob\\mathcal{J}} D(j)$ and $Q = \\prod_{\\alpha \\in \\mor\\mathcal{J}} D(\\cod \\alpha)$.\\\\\n        We have morphisms $P \\stackrel[g]{f}{\\rightrightarrows} Q$ defined by $\\pi_\\alpha f = \\pi_{\\cod(\\alpha)}$, $\\pi_\\alpha g = D(\\alpha) \\pi_{\\dom \\alpha}$ for all $\\alpha$ since $Q$ is a product.\\\\\n        Let $E \\xrightarrow{e} P$ be an equalizer of $(f,g)$. The composites $\\lambda_j = \\pi_j e: E \\to D(j)$ form a cone over $D$: given $\\alpha: j \\to j'$ in $\\mathcal{J}$, \n        $$D(\\alpha) \\lambda_j = D(\\alpha) \\pi_j e = \\pi_\\alpha ge = \\pi_\\alpha fe = \\pi_{j'} e = \\lambda_{j'}$$\n        Given any cone $(A,(\\mu_j | j \\in \\ob\\mathcal{J}))$ over $D$, there's a unique $\\mu:A \\to P$ with $\\pi_j \\mu = \\mu_j$ for each $j$, and $\\pi_\\alpha f \\mu = \\mu_{\\cod \\alpha} = D(\\alpha) \\mu_{\\dom \\alpha} = \\pi_\\alpha g\\mu$ for all $\\alpha$, and hence $f\\mu = g\\mu$. So there is a unique $\\nu:A \\to E$ with $e\\nu = \\mu$. So $(E,(\\lambda_j | j \\in \\ob \\mathcal{J}))$ is a limit cone.\n\n        (ii) It's enough to construct finite products and equalizers. But if $1$ is the terminal object, then a pullback for \n        \\begin{tikzcd}\n                        & A \\arrow[d]\\\\\n            B \\arrow[r] & 1\n        \\end{tikzcd}\n        has the universal property of a product $A \\times B$, and we can form $\\prod_{i=1}^n A_i$ inductively as $A_1 \\times (A_2 \\times (A_3 \\times ... (A_{n-1} \\times A_n)))$.\\\\\n        Now, to form the equalizer of $A \\stackrel[g]{f}{\\rightrightarrows} B$, consider the cospan\n        \\begin{tikzcd}\n            & A \\arrow[d,\"{(1_A,f)}\"]\\\\\n            A \\arrow[r,\"{(1_A,g)}\"] & A \\times B\n        \\end{tikzcd}\n        . A cone over this consists of \n        \\begin{tikzcd}\n            P \\arrow[r,\"h\"] \\arrow[d,\"k\"] & A\\\\\n            A &\n        \\end{tikzcd}\n        satisfying $(1_A,f) h = (1_A,g) k$, or equivalently $1_A h = 1_A k$, and $fh = gk$, or equivalently, a morphism $P \\xrightarrow{h} A$ satisfying $fh = gh$ (think). So a pullback for $(1_A,f)$ and $(1_A,g)$ is an equalizer of $(f,g)$.\\\\\n        We say a category $\\mathcal{C}$ is \\emph{complete} if it has all small limits. Dually, \\emph{cocomplete} means it has all small colimits.\\\\\n        $\\mathbf{Set}$ is both complete and cocomplete: products are cartesian products, coproducts are disjoint unions.\\\\\n        Similarly, $\\mathbf{Gp}$, $\\mathbf{AbGp}$, $\\mathbf{Rng}$, $\\mathbf{Mod}_R$,... are all complete and cocomplete (nice to know that). $\\mathbf{Top}$ is also complete and cocomplete, ...\n    \\end{proof}\n\\end{thm}\n\n\\begin{defi} (4.4)\\\\\n    Let $F: \\mathcal{C} \\to \\mathcal{D}$ be a functor.\\\\\n    (a) We say $F$ \\emph{preserves limits} of shape $\\mathcal{J}$ if, given $D:\\mathcal{J} \\to \\mathcal{C}$ and a limit cone $(L,(\\lambda_j|j \\in \\ob\\mathcal{J}))$ in $\\mathcal{C}$, $(FL, (F\\lambda_j | j \\in \\ob \\mathcal{J}))$ is a limit for $FD$.\\\\\n    (b) We say $F$ \\emph{reflects limits} of shape $\\mathcal{J}$ if, given $D:\\mathcal{J} \\to \\mathcal{C}$ and a cone $(L,(\\lambda_j)_j)$ s.t. $(FL,(F\\lambda_j)_j)$ is a limit for $FD$, then $(L,(\\lambda_j)_j)$ is a limit for $D$.\\\\\n    (c) We say $F$ \\emph{creates limits} of shape $\\mathcal{J}$ if, given $D : \\mathcal{J} \\to \\mathcal{C}$ and a limit $(M,(\\mu_j)_j)$ for $FD$, there exists a cone $(L,(\\lambda_j)_j)$ over $D$ whose image under $F$ is isomorphic to the limit cone, and any such cone is a limit in $\\mathcal{C}$.\\footnote{Note that all limits are isomorphic, so the first part of this basically says $F$ reflects the existence of limits.} (This is stronger than both of above and implies them. Note that a lot of textbooks get this wrong; the definitions given by them are usually not categorical)\\\\\n    From some later parts of the notes, the definitions of these three words (\\emph{preserve, reflect, create}) seem to apply to other things as well but restricted to limits only.\n\\end{defi}\n\n---Lecture 11---\n\n\\begin{rem} (4.5)\\\\\n    (a) If $\\mathcal{C}$ has limits of shape $\\mathcal{J}$, $F: \\mathcal{C} \\to \\mathcal{D}$ preserves them and $F$ reflects isomorphisms, then $F$ reflects limits of shape $\\mathcal{J}$.\\\\\n    (b) $F$ reflects limits of shape $1$ $\\iff$ $F$ reflects isomorphisms.\\\\\n    (c) If $\\mathcal{D}$ has limits of shape $\\mathcal{J}$ and $F:\\mathcal{C} \\to \\mathcal{D}$ creates them, then $F$ both preserves and reflects them.\\\\\n    (d) In any of the statements of (4.3), we may replace both instances of \\emph{$\\mathcal{C}$ has} by either \\emph{$\\mathcal{C}$ has and $F:\\mathcal{C} \\to \\mathcal{D}$ preserves} or \\emph{$\\mathcal{D}$ has and $F:\\mathcal{C} \\to \\mathcal{D}$ creates}.\n\\end{rem}\n\nWe shall have some examples, as usual.\n\n\\begin{eg} (4.6)\\\\\n    (a) $U : \\mathbf{Gp} \\to \\mathbf{Set}$ creates all small limits: given a family $(G_i | i \\in I)$ of groups, there's a unique group structure on $\\prod_{i \\in I} UG_i$ making the projections $\\pi_i$ into homomorphisms, and this makes it into a product in $\\mathbf{Gp}$.\\\\\n    Similarly for equalizers.\\\\\n    But $U$ doesn't preserve coproducts; $U(G * H) \\not\\cong UG \\coprod UH$.\\\\\n    (b) $U:\\mathbf{Top} \\to \\mathbf{Set}$ preserves all small limits and colimits, but this times it doesn't reflect them: if $L$ is a limit for $D: \\mathcal{J} \\to \\mathbf{Top}$, and $L$ is not discrete, there's another cone with apex $L_d$ (take the underlying set and \\emph{retopologize} with discrete topology) mapping to the limit in $\\mathbf{Set}$.\\\\\n    (c) The inclusion functor $I:\\mathbf{AbGp} \\to \\mathbf{Gp}$ reflects coproducts, but doesn't preserve them: the direct sum $A \\oplus B$ (coproducts in $\\mathbf{AbGp}$) is not normally isomorphic to the free product $A*B$; $A*B$ is not abelian unless either $A$ or $B$ is $\\{e\\}$.\\\\\n    But if $A \\cong \\{e\\}$, then $A*B \\cong A \\oplus B \\cong B$.\n\\end{eg}\n\n\\begin{lemma} (4.7)\\\\\n    If $\\mathcal{D}$ has limits of shape $\\mathcal{J}$, then so does the functor category $[\\mathcal{C},\\mathcal{D}]$ for any $\\mathcal{C}$, and the forgetful functor $[\\mathcal{C},\\mathcal{D}] \\to \\mathcal{D}^{\\ob \\mathcal{C}}$ creates them.\n    \\begin{proof}\n        Suppose given a diagram of shape $\\mathcal{J}$ in $[\\mathcal{C},\\mathcal{D}]$; think of it as a functor $D:\\mathcal{J} \\times \\mathcal{C} \\to \\mathcal{D}$. For each $A \\in \\ob\\mathcal{C}$, let $(LA,(\\lambda_{j,A}|j \\in \\ob \\mathcal{J}))$ be a limit cone for the diagram $D(-,A): \\mathcal{J} \\to \\mathcal{D}$.\\\\\n        Given $A \\xrightarrow{f} B$ in $\\mathcal{C}$, the composites $LA \\xrightarrow{\\lambda_{j,A}} D(j,A) \\xrightarrow{D(j,f)} D(j,B)$ form a cone over $D(-,B)$, since the sqaures \n        \\begin{tikzcd}\n            D(j,A) \\arrow[r,\"{D(j,f)}\"] \\arrow[d,\"{D(\\alpha,A)}\"] & D(j,B) \\arrow[d,\"{D(\\alpha,B)}\"]\\\\\n            D(j',A) \\arrow[r,\"{D(j',f)}\"] & D(j',B)\n        \\end{tikzcd}\n        commute. So there's a unique $LF:LA \\to LB$ making\n        \\begin{tikzcd}\n            LA \\arrow[r,\"{\\lambda_{j,A}}\"] \\arrow[d,\"Lf\"] & D(j,A) \\arrow[d,\"{D(j,f)}\"]\\\\\n            LB \\arrow[r,\"{\\lambda_{j,B}}\"] & D(j,B)\n        \\end{tikzcd}\n        commute for all $j$.\\\\\n        As usual, uniqueness implies functoriality: given $g:B \\to C$, $L(gf)$ and $(Lg)(Lf)$ are factorizations of the same cone through the limit $LC$. And this is the unique functor structure on $(A \\to LA)$ making the $\\lambda_{j,-}$ into natural transformations.\\\\\n        The cone $(L,(\\lambda_{j,-} | j \\in \\ob\\mathcal{J}))$ is a limit: suppose given another cone $(M,(\\mu_{j,-} | j \\in \\ob\\mathcal{J}))$, then for each $A$, $(MA,(\\mu_{j,A} | j \\in \\ob\\mathcal{J}))$ is a cone over $D(-,A)$, so induces a unique $\\alpha_A:MA \\to LA$. Naturality of $\\alpha$ follows from uniqueness of factorizations through a limit. So $(M,(\\mu_j))$ factors uniquely through $(L,(\\lambda_j))$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{rem} (4.8)\\\\\n    Now we can prove something that I promised very long ago (see Sheet 1 Q4 as well). In any category, a morphism $A \\xrightarrow{f} B$ is monic iff\n    \\begin{tikzcd}\n        A \\arrow[r,\"1_A\"] \\arrow[d,\"1_A\"] & A \\arrow[d,\"f\"]\\\\\n        A \\arrow[r,\"f\"] & B\n    \\end{tikzcd}\n    is a pullback. Hence any functor which preserves pullbacks preserves monomorphisms.\\\\\n    In particular, if $\\mathcal{D}$ has pullbacks, then monomorphisms in $[\\mathcal{C},\\mathcal{D}]$ are just pointwise monomorphisms.\\\\\n    The dual is the statement in comment of Sheet 1 Q4.\n\\end{rem}\n\n\\begin{thm} (4.9)\\\\\n    Suppose $G:\\mathcal{D} \\to \\mathcal{C}$ has a left adjoint $F$. Then $G$ preserves all limits which exist in $\\mathcal{D}$.\\\\\n    We'll present two proofs: the first (slick) proof is more for you to understand why this is true, while the second proof is more elementary.\n    \\begin{proof} (1)\\\\\n        Suppose $\\mathcal{C}$ and $\\mathcal{D}$ both have limits of shape $\\mathcal{J}$. We have a commutative diagram\n        \\begin{tikzcd}\n            \\mathcal{C} \\arrow[r,\"F\"] \\arrow[d,\"\\triangle\"] & \\mathcal{D} \\arrow[d,\"\\triangle\"]\\\\\n            \\left[\\mathcal{J},\\mathcal{C}\\right] \\arrow[r,\"{[\\mathcal{J},F]}\"] & \\left[\\mathcal{J},\\mathcal{D}\\right]\n        \\end{tikzcd}\n        , and all functors in it have right adjoints.\\\\\n        In particular, $([\\mathcal{J},F] \\dashv [\\mathcal{J},G])$.\\\\\n        So by (3.6), the diagram of right adjoints\n        \\begin{tikzcd}\n            \\mathcal{D} \\arrow[r,\"G\"] & \\mathcal{C}\\\\\n            \\left[\\mathcal{J},D\\right] \\arrow[u,\"\\lim_{\\mathcal{J}}\"] \\arrow[r,\"{[\\mathcal{J},G]}\"] & \\left[\\mathcal{J},\\mathcal{C}\\right] \\arrow[u,\"\\lim_{\\mathcal{J}}\"]\n        \\end{tikzcd}\n        commutes up to isomorphism, i.e. $G$ preserves limits of shape $\\mathcal{J}$.\\\\\n        This is the real reason why this theorem works, because right adjoint commute with right adjoints.\\\\\n        However, this proof won't work if we don't know we have limits.\n    \\end{proof}\n\n    \\begin{proof} (2)\\\\\n        Suppose given $D:\\mathcal{J} \\to \\mathcal{D}$ and a limit cone $(L,(L \\xrightarrow{\\lambda_j} D(j) | j \\in \\ob \\mathcal{J}))$. Given a cone $(A,(A \\xrightarrow{\\alpha_j} GD(j) | j \\in \\ob\\mathcal{J}))$ over $GD$, the morphisms $FA \\xrightarrow{\\hat{\\alpha}_j} D(j)$ form a cone over $D$, so they induce a unique $FA \\xrightarrow{\\hat{\\beta}} L$ such that $\\lambda_j \\hat{\\beta} = \\hat{\\alpha}_j$ for all $j$.\\\\\n        Then $A \\xrightarrow{\\beta} GL$ is the unique morphism satisfying $(G \\lambda_j) \\beta = \\alpha_j$ for all $j \\in \\mathcal{J}$. So $(GL,(G\\lambda_j | j \\in \\ob\\mathcal{J}))$ is a limit cone in $\\mathcal{C}$.\\\\\n        The \\emph{primeval Adjoint Functor Theorem} says that the converse of (4.9) is true: if $\\mathcal{D}$ has (limits), and $G:\\mathcal{D} \\to \\mathcal{C}$ preserves \\emph{all} limits, then $G$ has a left adjoint.\n    \\end{proof}\n\\end{thm}\n\n---Lecture 12---\n\nSecond example class: Friday 9 November, 14:00, MR3.\n\n\\begin{lemma} (4.10)\\\\\n    Suppose $\\mathcal{D}$ has and $G:\\mathcal{D} \\to \\mathcal{C}$ preserves limits of shape $\\mathcal{J}$. Then for any $A \\in \\ob \\mathcal{C}$, the arrow category $(A \\downarrow G)$ has limits of shape $\\mathcal{J}$, and the forgetful functor $U:(A \\downarrow G) \\to \\mathcal{D}$ creates them.\n    \\begin{proof}\n        Suppose given $D:\\mathcal{J} \\to (A\\downarrow G)$; write $D(j)$ as $(UD(j),f_j)$.\\\\\n        Let $(L,(\\lambda_j:L \\to UD(j))_{j \\in \\ob\\mathcal{J}}$ be a limit for $UD$; then $(GL,(G\\lambda_j)_{j \\in \\ob\\mathcal{J}})$ is a limit for $GUD$. Since the edges of $UD$ are morphisms in $(A \\downarrow G)$, the $f_j$ form a cone over $GUD$.\\\\\n        So there's a unique $h:A \\to GL$ s.t. $(G\\lambda_j)h = f_j$ for all $j$, i.e. there is a unique $h$ s.t. the $\\lambda_j$ are all morphisms $(L,h) \\to (UD(j),f_j)$ in $(A \\downarrow G)$.\\\\\n        We need to show that $((L,h),(\\lambda_j)_{j \\in \\ob\\mathcal{J}})$ is a limit cone in $(A \\downarrow G)$.\\\\\n        If $((C,k),(\\mu_j)_{j \\in \\ob\\mathcal{J}})$ is any cone over $D$, then $(C,(\\mu_j)_{j \\in \\ob\\mathcal{J}})$ is a cone over $UD$. So there's a unique $l:C \\to L$ with $\\lambda_j l = \\mu_j$ for all $j$. We need to show $(Gl)k = h$: but $(G\\lambda_j) (Gl)k = (G\\mu_j)k = f_j = (G\\lambda_j) h$ for all $j$. So $(Gl)k = h$ by uniqueness of factorizations through limits.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (4.11)\\\\\n    A category $\\mathcal{C}$ has an initial object iff $1_{\\mathcal{C}}:\\mathcal{C} \\to \\mathcal{C}$, regarded as a diagram of shape $\\mathcal{C}$ in $\\mathcal{C}$, has a limit.\n    \\begin{proof}\n        First, suppose $\\mathcal{C}$ has an initial object $I$. Then the unique morphisms $(I \\to A | A \\in \\ob\\mathcal{C})$ form a cone over $1_{\\mathcal{C}}$; and given any cone $(C \\xrightarrow{\\lambda_A} A |A \\in \\ob\\mathcal{C})$, then for any $A$ the triangle \n        \\begin{tikzcd}\n            C \\arrow[rd,\"\\lambda_A\"'] \\arrow[r,\"\\lambda_I\"] & I \\arrow[d]\\\\\n            & A\n        \\end{tikzcd}\n        commutes, so $\\lambda_I$ is the unique factorization of $(\\lambda_A|A \\in \\ob\\mathcal{C})$ through $(I \\to A|A\\in\\ob\\mathcal{C})$.\\\\\n        Conversely, suppose $(I,(\\lambda_A:I \\to A|A \\in \\ob\\mathcal{C}))$ is a limit. Then for any $I \\xrightarrow{f} A$, the diagram\n        \\begin{tikzcd}\n            I \\arrow[r,\"\\lambda_I\"] \\arrow[rd,\"\\lambda_A\"] & I \\arrow[d,\"f\"]\\\\\n            & A\n        \\end{tikzcd}\n        commutes. In particular, putting $f = \\lambda_A$, we see that $\\lambda_I$ is a factorization of the limit cone through itself, so $\\lambda_I = 1_I$. Hence every $f:I \\to A$ satisfies $f=\\lambda_A$. So $I$ is initial.\n    \\end{proof}\n\\end{lemma}\n\nThe primeval adjoint functor theorem follows immediately from (4.10), (4.11) and (3.3).\\\\\nHowever, it only applies to functors between preorders (since that's the only category that satisfies the conditions; c.f. Sheet 2 Q6).\n\n\\begin{thm} (4.12, General Adjoint Functor Theorem)\\\\\n    Suppose that $\\mathcal{D}$ is locally small and complete. Then $G:\\mathcal{D} \\to \\mathcal{C}$ has a left adjoint $\\iff$ $G$ preserves all small limits (some people use the word \\emph{continuous} for this) and, for each $A \\in \\ob\\mathcal{C}$, there exists a \\emph{set} of morphisms $\\{A \\xrightarrow{f_i} GB_i | i \\in I\\}$ s.t. every $A \\xrightarrow{h} GC$ factors as $A \\xrightarrow{f_i} GB_i \\xrightarrow{Gg} GC$ for some $i$ and some $g:B_i \\to C$.\\\\\n    (We say $G$ satisfies the \\emph{solution set condition}.)\n    \\begin{proof}\n        $\\implies$: If $(F \\dashv G)$, $G$ preserves limits by (4.9), and $\\{A \\xrightarrow{\\eta_A} GFA\\}$ is a singleton solution set, by (3.3).\\\\\n        $\\Leftarrow$: By (4.10) $(A\\downarrow G)$ is complete, and it inherits local smallness from $\\mathcal{D}$. So we need to show: if $\\mathcal{A}$ is compelte and locally small, and has a weakly initial set of objects $\\{B_i | i \\in I\\}$, then $\\mathcal{A}$ has an initial object.\\\\\n        First form $P=\\prod_{i \\in I} B_i$, then $P$ is weakly initial. Now form the limit of $P \\stackrel[\\to]{\\to}{...} P$ (*) whose edges are all the endomorphisms of $P$; denote it $I \\xrightarrow{i} P$. $I$ is also weakly initial in $\\mathcal{A}$; suppose given $I \\stackrel[g]{f}{\\rightrightarrows} C$. Form equalizer $E \\xrightarrow{e} I$ of $(f,g)$; then there exists $P\\xrightarrow{h} E$ since $P$ is weakly initial.\\\\\n        $ieh:P \\to P$ and $1_P$ are edges of the diagram (*) above, so $i=iehi$. But $i$ is monic, so $ehi = 1_I$; in particular, $e$ is split epic. So $f=g$.\\\\\n        Hence $I$ is initial.\n    \\end{proof}\n\\end{thm}\n\n\\begin{eg} (4.13)\\\\\n    (a) Suppose you've never heard of free groups nor how to construct them. Consider the forgetful functor $U: \\mathbf{Gp} \\to \\mathbf{Set}$. By (4.6 a), $U$ creates all small limits, so $\\mathbf{Gp}$ has them and $U$ preserves them. $\\mathbf{Gp}$ is locally small; now given a set $A$, any $f:A \\to UG$ factors as $A \\to UG' \\to UG$, where $G' \\leq G$ is the subgroup generated by $\\{f(x) |x \\in A\\}$, and $\\Card G' \\leq \\max\\{\\aleph_0,\\Card A\\}$.\\\\\n    Let $B$ be a set of this cardinality, and consider all possible subsets $B' \\subseteq B$. All group structures on $B'$ and all mappings $A \\to B'$. So these give us a solution set at $A$.\\footnote{However this is not a very good example -- how did we know the upper bound of $\\Card G'$? We knew it because we've already known free group consists of all words generated by set elements. Indeed this is almost always the case: if you've known enough about the functor so that you can find a solution set to apply GAFT, almost always you could have constructed the adjoint explicitly.}\\\\\n    (b) Consider the category $\\mathbf{CLat}$ of complete lattices, i.e. posets with all meets and joins. Again, $U:\\mathbf{CLat} \\to \\mathbf{Set}$ creates all small limits. But A.W.Hales (1964) showed that, for any cardinal $\\kappa$, there exist complete lattices of cardinality $\\geq \\kappa$ generated by three elements; so the SSC fails at $A=\\{x,y,z\\}$. Hence $U$ doesn't have a left adjoint.\n\\end{eg}\n\n---Lecture 13---\n\n\\begin{defi} (4.14)\\\\\n    By a \\emph{subobject} of an object $A$ of $\\mathcal{C}$, we mean a monomorphism $A' \\rightarrowtail A$. The subobjects of $A$ are preordered by $A'' \\leq A'$, if there exists a factorization \n    \\begin{tikzcd}\n        A'' \\arrow[rr] \\arrow[rd,tail] & & A' \\arrow[ld, tail]\\\\\n        & A &\n    \\end{tikzcd}\n    i.e. a factorization of $A''$ through $A'$.\\\\\n    We say $\\mathcal{C}$ is \\emph{well-powered} if each $A \\in \\ob\\mathcal{C}$ has a set of subobjects $\\{A_i \\rightarrowtail A | i \\in I\\}$ s.t. every subobject of $A$ is isomorphic to some $A_i$ (e.g. in $\\mathbf{Set}$ we can take the inclusions $\\{A' \\hookrightarrow A| A'\\in PA\\})$.\\\\\n    If $\\mathcal{C}^{op}$ is well-powered, we say $\\mathcal{C}$ is \\emph{well-copowered}\\footnote{Some people use \\emph{cowell-powered}, but lecturer thought that meant \\emph{not well-powered} so decided not to use that.}. \n\\end{defi}\n\n\\begin{lemma} (4.15)\\\\\n    Suppose given a pullback square\n    \\begin{tikzcd}\n        P \\arrow[r,\"h\"] \\arrow[d,\"k\"] & A \\arrow[d,tail,\"f\"]\\\\\n        B \\arrow[r,\"g\"] & C\n    \\end{tikzcd}\n    with $f$ monic. Then $k$ is monic.\n    \\begin{proof}\n        Suppose $D \\stackrel[y]{x}{\\rightrightarrows} P$ satisfy $kx=ky$. Then $fhx=gkx=gky=fhy$. But $f$ is monic, so $hx=hy$. So $x$ and $y$ are factorizations of the same cone through the limit cone $(h,k)$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{thm} (4.16, Special AFT)\\\\\n    Suppose $\\mathcal{C}$ and $\\mathcal{D}$ are both locally small, and that $\\mathcal{D}$ is complete and well-powered and has a coseparating set (see (2.8)). Then a functor $G:\\mathcal{D} \\to \\mathcal{C}$ has a left adjoint iff it preserves all small limits.\n    \\begin{proof}\n        $\\implies$: by (4.9).\\\\\n        $\\Leftarrow$: For any $A \\in \\ob\\mathcal{C}$, $(A \\downarrow G)$ is complete by (4.10), locally small, and well-powered, since the subobjects of $(B,f)$ in $(A\\downarrow G)$ are just those subobjects $B' \\rightarrowtail B$ in $\\mathcal{D}$ for which $f$ factors through $GB' \\rightarrowtail GB$.\\\\\n        Also, if $\\{S_i | i \\in I\\}$ is a coseparating set for $\\mathcal{D}$, then the set $\\{(S_i, f)|i \\in Im f \\in \\mathcal{C}(A,GS_i)\\}$ is coseparating in $(A \\downarrow G)$: given $(B,f) \\stackrel[h]{g}{\\rightrightarrows} (B',f')$ in $(A \\downarrow G)$ with $g \\neq h$, there exists some morphism $k:B' \\to S_i$ for some $i$ with $kg \\neq kh$, and then $k$ is also a morphism $(B',f') \\to (S_i,(Gk)f')$ in $(A \\downarrow G)$.\\\\\n        So we need to show that if $\\mathcal{A}$ is complete, locally small and well-powered and has a coseparating set $\\{S_i|i \\in I\\}$, then $\\mathcal{A}$ has an initial object: form the product $P=\\prod_{i \\in I} S_i$. Now consider the diagram\n\n        \\begin{tikzcd}\n            & & & & P_i \\arrow[ddd, tail]\\\\\n            & & P_j \\arrow[ddrr, tail] \\arrow[lldd, bend right = 15, dotted, no head] & &\\\\\n            & & & &\\\\\n            P' \\arrow[rrrr,tail] & & & & P\n        \\end{tikzcd}\n\n        whose edges are a representative set of subobjects of $P$, and form its limit\n\n        \\begin{tikzcd}\n            I \\arrow[rrr] \\arrow[rrd] \\arrow[ddd] & & & P_i\\\\\n            & & P_j \\arrow[lldd, dotted, no head, bend left = 15] &\\\\\n            & & &\\\\\n            P' & & &\n        \\end{tikzcd}\n\n        By the argument of (4.15), the legs of this cone are all monic; in particular, $I \\rightarrowtail P$ is monic, and it's a least subobject of $P$. Hence $I$ has no proper subobjects.\\\\\n        So, given $I \\stackrel[g]{f}{\\rightrightarrows} A$, their equalizer is an isomorphism, hence $f=g$.\\\\\n        Now let $A$ be any object of $\\mathcal{A}$; form the product\n        $$Q = \\prod_{i \\in I, f \\in \\mathcal{A}(A,S_i)} S_i$$\n        There's an \\emph{obvious} $h:A \\to Q$ defined by $\\pi_{i,f} h = f$; and $h$ is monic, since the $S_i$ are a coseparating set.\\\\\n        We alsk have a morphism $k:P \\to Q$ defined by $\\pi_{i,f} k = \\pi_i$.\\\\\n        Now form the pullback \n        \\begin{tikzcd}\n            B \\arrow[r] \\arrow[d,tail] & A \\arrow[d,tail,\"h\"]\\\\\n            P \\arrow[r,\"k\"] & Q\n        \\end{tikzcd}\n        ; by (4.15), $P$ is monic, so $B$ is a subobject of $P$. Hence there exists \n        \\begin{tikzcd}\n            I \\arrow[rr] \\arrow[rd] & & B \\arrow[ld]\\\\\n            & P &\n        \\end{tikzcd}\n        hence a morphism $I \\to B \\to A$.\\footnote{This proof was first mentioned in a book where the author left as an exercise to the readers}\n    \\end{proof}\n\\end{thm}\n\n\\begin{eg} (4.17)\\\\\n    Consider the inclusion $\\mathbf{KHaus} \\xrightarrow{I} \\mathbf{Top}$, where $\\mathbf{KHaus}$ is the full subcategory of compact Hausdorff spaces (see (3.11 b)). $\\mathbf{KHaus}$ has, and $I$ preserves all small products (by Tychonoff's theorem), and equalizers (since equalizers of pairs $X\\stackrel[g]{f}{\\rightrightarrows} Y$ with $Y$ Hausdorff are closed subspaces).\\\\\n    Both categories are locally small and $\\mathbf{KHaus}$ is well-powered (subobjects of $X$ are all isomorphic to closed subspaces). The closed intervals $[0,1]$ is a coseparator in $\\mathbf{KHaus}$, by Uryson's Lemma which is well-known in Topology (ok). So we have everything in (4.16), so this functor $I$ has a left adjoint $\\beta$ (known as \\href{https://en.wikipedia.org/wiki/Stone%E2%80%93%C4%8Cech_compactification}{\\emph{Stone-\\u{C}ech compactification}}).\n\\end{eg}\n\n\\begin{rem} (4.18)\\\\\n    (a) We've proved the existence in above, but it might also be interesting to see how $\\beta$ actually might look like.\\\\\n    \\u{C}ech's construction of $\\beta$: given $X$, form $Q = \\prod_{f:X \\to [0,1]} [0,1]$ and define $h:X \\to P$ by $\\pi_f h = f$. Define $\\beta X$ to be the closure of the image of $h$.\\\\\n    \\u{C}ech's proof that this works is essentially the same as (4.16).\\\\\n    (b) We could have used GAFT to construct $\\beta$ as well: we get a solution set at $X$ by considering all continuous $X \\xrightarrow{f} Y$ with $Y$ compact Hausdorff, and $\\im f$ dense in $Y$ and such $Y$ have cardinality at most $2^{2^{\\Card X}}$.\n\\end{rem}\n\n\\newpage\n\n\\section{Monads}\n\n---Lecture 14---\n\nSuppose we are given $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$ with $(F \\dashv G)$. How much of this structure can we describe without even mentioning $\\mathcal{D}$?\\\\\nObviously we can't just use $F$ or $G$ as both of them needs $\\mathcal{D}$. However we have the functor $T=GF:\\mathcal{C} \\to \\mathcal{C}$, the unit $\\eta: 1_{\\mathcal{C}} \\to T = GF$, and the natural transformation $\\mu=G\\varepsilon F: TT=GFGF \\to GF = T$ (whiskering).\\\\\nThese satisfy the commutative diagrams\n\n\\begin{tikzcd}\n    T \\arrow[r, \"T\\eta\"] \\arrow[rd, \"1_T\"] & TT \\arrow[d, \"\\mu\"] & T \\arrow[l,\"\\eta T\"] \\arrow[ld,\"1_T\"]\\\\\n    & T &\n\\end{tikzcd}\n\nby the triangular identities (we'll use (1) and (2) to denote the left and right half of this diagram), and \n\n\\begin{tikzcd}\n    TTT \\arrow[r,\"T\\mu\"] \\arrow[d,\"\\mu T\"] & TT \\arrow[d,\"\\mu\"]\\\\\n    TT \\arrow[r,\"\\mu\"] & T\n\\end{tikzcd}\n\nby naturality of $\\varepsilon$ (we'll use (3) to denote this diagram).\n\n\\begin{defi} (5.1)\\\\\n    A \\emph{monad}\\footnote{Historically this was called \\emph{the standard construction} or \\emph{triples}, but later people found that it needed a name. This name is probably because it sounds like \\emph{monoid}?} $\\mathbb{T} = (T,\\eta,\\mu)$ on a category $\\mathcal{C}$ consists of a functor $T:\\mathcal{C} \\to \\mathcal{C}$ and natural transformations $\\eta:1_{\\mathcal{C}} \\to T, \\mu:TT \\to T$ satisfying (1)-(3).\\\\\n    $\\eta$ and $\\mu$ are called the \\emph{unit} and \\emph{multiplication} of $\\mathbb{T}$.\n\\end{defi}\n\n\\begin{eg} (5.2)\\\\\n    (a) Any adjunction $(F \\dashv G)$ induces a monad $(GF,\\eta,G\\varepsilon F)$ on $\\mathcal{C}$ and a comonad $(FG,\\varepsilon, F\\eta G)$ on $\\mathcal{D}$.\\\\\n    (b) Let $M$ be a monoid. The functor $(M \\times -): \\mathbf{Set} \\to \\mathbf{Set}$ has a monad structure with unit given by $\\eta_A(a) = (1_M,a)$, and multiplication $\\mu_A(m,m',a) = (mm',a)$.\\\\\n    The monad identities follow from the mononid ones.\\\\\n    (c) Let $\\mathcal{C}$ be any category with finite products, $A \\in \\ob\\mathcal{C}$. The functor $(A \\times -):\\mathcal{C} \\to \\mathcal{C}$ has a comonad structure with counit $\\varepsilon_B: A \\times B \\to B$ given by $\\pi_2$, and comultiplication $\\delta_B:A \\times B \\to A \\times A \\times B$ given by $(\\pi_1,\\pi_1,\\pi_2)$.\n\\end{eg}\n\nDoes every monad arise from an adjunction? In 5.2(b) we have the category $[M,\\mathbf{Set}]$. Its forgetful functor to $\\mathbf{Set}$ has a left adjoint, sending $A$ to $M \\times A$ with $M$ acting by multiplication on the left factor. This adjunction gives rise to the monad of 5.2(b).\n\n\\begin{defi} (5.3, Eilenberg-Moore)\\\\\n    Let $\\mathbb{T}$ be a monad on $\\mathcal{C}$. A \\emph{$\\mathbb{T}$-algebra} is a pair $(A,\\alpha)$ with $A \\in \\ob\\mathcal{C}$ and $TA \\xrightarrow{\\alpha} A$, satisfying the commutative diagrams\n\n    \\begin{tikzcd}\n        A \\arrow[r,\"\\eta_A\"] \\arrow[rd,\"1_A\"] & TA \\arrow[d,\"\\alpha\"]\\\\\n        & A\n    \\end{tikzcd}\n    and\n    \\begin{tikzcd}\n        TTA \\arrow[r,\"T\\alpha\"] \\arrow[d,\"\\mu_A\"] & TA \\arrow[d,\"\\alpha\"]\\\\\n        TA \\arrow[r,\"\\alpha\"] & A\n    \\end{tikzcd}\n\n    We shall call these diagrams (4) and (5) respectively.\\\\\n    A \\emph{homomorphism} $f:(A,\\alpha) \\to (B,\\beta)$ is a morphism $A \\xrightarrow{f} B$ s.t.\n    \\begin{tikzcd}\n        TA \\arrow[r,\"Tf\"] \\arrow[d,\"\\alpha\"] & TB \\arrow[d,\"\\beta\"]\\\\\n        A \\arrow[r,\"f\"] & B\n    \\end{tikzcd}\n    commutes (label this diagram (6)).\\\\\n    The category of $\\mathbb{T}$-algebras (on $\\mathcal{C}$) is denoted $\\mathcal{C}^{\\mathbb{T}}$.\n\\end{defi}\n\n\\begin{lemma} (5.4)\\\\\n    The forgetful functor $G^{\\mathbb{T}}: \\mathcal{C}^\\mathbb{T} \\to \\mathcal{C}$ has a left adjoint $F^\\mathbb{T}$, and the adjunction induces $\\mathbb{T}$.\n    \\begin{proof}\n        We need to find something like a \\emph{free} functor. We define $F^\\mathbb{T} A = (TA,\\mu_A)$ (on algebra by (2) and (3)), and $F^\\mathbb{T}(A\\xrightarrow{f} B) = Tf$ (a homomorphism by naturality of $\\mu$).\\\\\n        Clearly $G^\\mathbb{T} F^\\mathbb{T} = T$; the unit of the adjunction is $\\eta$.\\\\\n        We define the counit $\\varepsilon_{(A,\\alpha)}= \\alpha:(TA,\\mu_A) \\to (A,\\alpha)$ (a homomorphism by (5)); $\\varepsilon$ is natural by (6). For the triangular identities, $\\varepsilon_{FA}(F\\eta_A) = 1_{FA}$ is (1), $G\\varepsilon_{(A,\\alpha)} \\eta_A = 1_A$ is (4), so we have all of the diagrams.\\\\\n        The monad induced by $(F^\\mathbb{T} \\dashv G^\\mathbb{T})$ has functor $T$ and unit $\\eta$, and $G^\\mathbb{T} \\varepsilon_{F^\\mathbb{T} A} = \\mu_A$ by definition of $F^\\mathbb{T} A$.\n    \\end{proof}\n\n    Kleisli took a \\emph{minimalist} approach: if $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$ induces $\\mathbb{T}$, then so does $\\mathcal{C} \\stackrel[G|_{\\mathcal{D}'}]{F}{\\rightleftarrows} \\mathcal{D}'$ where $\\mathcal{D}'$ is the full subcategory of $\\mathcal{D}$ on objects $FA$.\\\\\n    So in trying to construct $\\mathcal{D}$, we may assume $F$ is surjective (or indeed bijective) on objects. But then morphisms $FA \\to FB$ correspond bijectively to morphsims $A \\to GFB = TB$ in $\\mathcal{C}$.\n\\end{lemma}\n\n\\begin{defi} (5.5)\\\\\n    Given an algebra monad $\\mathbb{T}$ on $\\mathcal{C}$, the \\emph{Kleisli category} $\\mathcal{C}_\\mathbb{T}$ has $\\ob\\mathcal{C}_\\mathbb{T} = \\ob\\mathcal{C}$ (and because of this, we'll use green for morphisms in $\\mathcal{C}_\\mathbb{T}$. It might be useful to bring pens of different colours in the next few lectures), and morphisms\n    \\begin{tikzcd}\n        A \\arrow[r,green] & B\n    \\end{tikzcd}\n    are morphisms $A \\to TB$ in $\\mathcal{C}$. The composite\n    \\begin{tikzcd}\n        A \\arrow[r,green,\"f\"] & B \\arrow[r,green,\"g\"] & C\n    \\end{tikzcd} \n    is $A \\xrightarrow{f} TB \\xrightarrow{Tg} TTC \\xrightarrow{\\mu_C} TC$, and the identity\n    \\begin{tikzcd}\n        A \\arrow[r,green] & A\n    \\end{tikzcd}\n    is $A \\xrightarrow{\\eta_A} TA$.\\\\\n    To verify associativity, suppose given\n    \\begin{tikzcd}\n        A \\arrow[r,green,\"f\"] & B \\arrow[r,green,\"g\"] & C \\arrow[r,green,\"h\"] & D\n    \\end{tikzcd}. Then \n    \n    \\begin{tikzcd}\n        A \\arrow[r,\"f\"] & TB \\arrow[r,\"Tg\"] & TTC \\arrow[r,\"TTh\"] \\arrow[d,\"\\mu_C\"] & TTTD \\arrow[r,\"T \\mu_D\"] \\arrow[d,\"\\mu_{TD}\"] & TTD \\arrow[d,\"\\mu_D\"]\\\\\n        & &TC \\arrow[r,\"Th\"] & TTD \\arrow[r,\"\\mu_D\"] & TD\n    \\end{tikzcd}\n\n    commutes: the upper way round is \\textcolor{green}{$(hg)f$}, the lower is \\textcolor{green}{$h(gf)$} (the rightmost square is diagram (3)).\n\n    The unit laws similar follow from, using diagram (1) and (2) in the two triangles respectively,\n\n    \\begin{tikzcd}\n        A \\arrow[r,\"f\"] & TB \\arrow[r,\"T \\eta_B\"] \\arrow[rd,\"1_{\\mathbb{T}B}\"] & TTB \\arrow[d,\"\\mu_B\"]\\\\\n        & & TB\n    \\end{tikzcd}\n    and\n    \\begin{tikzcd}\n        A \\arrow[r,\"f\"] \\arrow[d,\"\\eta_A\"] & TB \\arrow[d,\"\\eta_{TB}\"] \\arrow[rd,\"1_{TB}\"] &\\\\\n        TA \\arrow[r,\"Tf\"] & TTB \\arrow[r,\"\\mu_B\"] & TB\n    \\end{tikzcd}\n\\end{defi}\n\n---Lecture 15---\n\n\\begin{lemma} (5.6)\\\\\n    There exists an adjunction $\\mathcal{C} \\stackrel[G_\\mathbb{T}]{F_\\mathbb{T}}{\\rightleftarrows} \\mathcal{C}_T$ inducing the monad $\\mathbb{T}$.\n    \\begin{proof}\n        We define $F_\\mathbb{T} A = A$, $F_\\mathbb{T}(A \\xrightarrow{f}B) = A\\xrightarrow{f} B \\xrightarrow{\\eta_B} TB$.\\\\\n        $F_\\mathbb{T}$ preserves identities by definition; for composites, consider $A \\xrightarrow{f} B \\xrightarrow{g} C$, we get, using diagram (1) at bottomright,\n\n        \\begin{tikzcd}\n            A \\arrow[r,\"f\"] & B \\arrow[d,\"g\"] \\arrow[r,\"\\eta_B\"] & TB \\arrow[d,\"Tg\"] & \\\\\n            & C \\arrow[r,\"\\eta_C\"] & TC \\arrow[r,\"T\\eta_C\"] \\arrow[rd,\"1_{TC}\"] & TTC \\arrow[d,\"\\mu_C\"]\\\\\n            & & & TC\n        \\end{tikzcd}\n\n        We define $G_\\mathbb{T} A = TA$,\n        \\begin{tikzcd}\n            G_\\mathbb{T}(A \\arrow[r,green,\"f\"] & B)\n        \\end{tikzcd}\n        $=TA\\xrightarrow{Tf} TTB \\xrightarrow{\\mu_B} TB$.\\\\\n        $G_\\mathbb{T}$ preserves identities by (1); for composites, consider\n        \\begin{tikzcd}\n            A \\arrow[r,green,\"f\"] & B \\arrow[r,green,\"g\"] & C\n        \\end{tikzcd}\n        We get, using the naturality square (3),\n\n        \\begin{tikzcd}\n            TA \\arrow[r,\"Tf\"] & TTB \\arrow[d,\"\\mu_B\"] \\arrow[r,\"TTg\"] & TTTC \\arrow[r,\"T\\mu_C\"] \\arrow[d,\"\\mu_{TC}\"] & TTC \\arrow[d,\"\\mu_C\"]\\\\\n            & TB \\arrow[r,\"Tg\"] & TTC \\arrow[r,\"\\mu_C\"] & TC\n        \\end{tikzcd}\n\n        Now we verify that $G_\\mathbb{T} F_\\mathbb{T} A = TA$, $G_\\mathbb{T} F_\\mathbb{T} f = \\mu_B (T\\eta_B) Tf = Tf$.\\\\\n        So we take $\\eta:1_{\\mathcal{C}} \\to T$ as the unit of $(F_\\mathbb{T} \\dashv G_\\mathbb{T})$;\\\\\n        The counit\n        \\begin{tikzcd}\n            TA \\arrow[r,green,\"\\varepsilon_A\"] & A\n        \\end{tikzcd}\n        is $1_{TA}$.\\\\\n        To verify naturality, we have to verify the commutative diagram\n        \n        \\begin{tikzcd}\n            TA \\arrow[r,green,\"F_\\mathbb{T}G_\\mathbb{T}f\"] \\arrow[d,green,\"\\varepsilon_A\"] & TB \\arrow[d,green,\"\\varepsilon_B\"]\\\\\n            A \\arrow[r,green,\"f\"] & B\n        \\end{tikzcd}\n\n        This expands to, by triangle (2),\n\n        \\begin{tikzcd}\n            TA \\arrow[r,\"Tf\"] & TTB \\arrow[r,\"\\mu_B\"] & TB \\arrow[r,\"\\eta_{TB}\"] \\arrow[rd,\"1_{TB}\"] & TTB \\arrow[d,\"\\mu_B\"]\\\\\n            & & & TB\n        \\end{tikzcd}\n\n        So $\\varepsilon$ is natural.\\\\\n        Finally we need to verify triangular equalities:\n        \\begin{tikzcd}\n            G_\\mathbb{T}(T_A \\arrow[r,green,\"\\varepsilon_A\"] & A)\n        \\end{tikzcd}\n        $=\\mu_A$, so $G_\\mathbb{T}($\\textcolor{green}{$\\varepsilon_A$}$)\\eta_{G_\\mathbb{T}A} = \\mu_A \\cdot \\eta_{TA} = 1_{TA}$;\\\\\n        And \\textcolor{green}{$(\\varepsilon_{F_\\mathbb{T}A})(F_\\mathbb{T} \\eta_A)$} is \n\n        \\begin{tikzcd}\n            A \\arrow[r,\"\\eta_A\"] & TA \\arrow[r,\"\\eta_{TA}\"] \\arrow[rd,\"1_{TA}\"] & TTA \\arrow[d,\"\\mu_A\"]\\\\\n            & & TA\n        \\end{tikzcd}\n\n        which is \\textcolor{green}{$1_{F_\\mathbb{T} A}$}.\\\\\n        Also, $G_\\mathbb{T}($\\textcolor{green}{$\\varepsilon_{F_\\mathbb{T} A}$})$=\\mu_A$, so $(F_\\mathbb{T} \\dashv G_\\mathbb{T})$ induces $\\mathbb{T}$.\n    \\end{proof}\n\\end{lemma}\n\nNote that although this is quite a lengthy proof, there's only one way we can go, i.e. verify everything we need.\n\n\\begin{thm} (5.7)\\\\\n    Given a monad $\\mathbb{T}$ on $\\mathcal{C}$, let $\\mathbf{Adj}(\\mathbb{T})$ be the category whose objects are the adjunctions $(\\mathcal{C}\\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D})$ inducing $\\mathbb{T}$, and whose morphisms $(\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}) \\to (\\mathcal{C} \\stackrel[G']{F'}{\\rightleftarrows} \\mathcal{D}')$ are functors $H:\\mathcal{D} \\to \\mathcal{D}'$, satisfying $HF = F'$ and $G'H = G$ (note that we might have expected just natural isomorphisms here, but we do need equalities for things to work). Then the Kleisli adjunction is an initial object of $\\mathbf{Adj}(\\mathbb{T})$, and the Eilenberg-Moore adjunction is terminal.\\\\\n    (Question from student: how non-trivial are these adjunction categories?\\\\\n    A: I know they have an initial and a terminal object!)\\\\\n    \\begin{proof}\n        Let $(\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D})$ be an object of $\\mathbf{Adj}(\\mathbb{T})$. We define $K:\\mathcal{D} \\to \\mathcal{C}^\\mathbb{T}$ (the \\emph{E-M comparison functor}) by $KB = (GB,G\\varepsilon_B)$ where $\\varepsilon$ is the counit of the adjunction $(F \\dashv G)$ we started from; note this is an algebra by one of the triangular identities for $(F\\dashv G)$ and naturality of $\\varepsilon$. And $K(B\\xrightarrow{g}B') = Gg$ (a homomorphism by naturalitty of $\\varepsilon'$). Because $G$ is functorial, this is functorial as well.\\\\\n        Clearly, $G^\\mathbb{T} K = G$, and $KFA = (GFA,G\\varepsilon_{FA}) = (TA,\\mu_A)=F^\\mathbb{T} A$. Also $KF(A\\xrightarrow{f}A') = Tf = F^\\mathbb{T} f$.\\\\\n        So $K$ is a morphism of $\\mathbf{Adj}(\\mathbb{T})$.\\\\\n        Suppose $K':\\mathcal{D} \\to \\mathcal{C}^\\mathbb{T}$ is another such; then since $G^\\mathbb{T} K' = G$, we know $K'B = (GB,\\beta_B)$ where $\\beta$ is a natural transformation $GFG \\to G$.\\\\\n        Also, since $K'F = F^\\mathbb{T}$, we have $\\beta_{FA} = \\mu_A = G\\varepsilon_{FA}$.\\\\\n        Now, given any $B\\in\\ob\\mathcal{D}$, consider the diagram \n\n        \\begin{tikzcd}\n            GFGFGB \\arrow[r,\"GFG\\varepsilon_B\"] \\arrow[d,shift right, \"G\\varepsilon_{FGB}\"'] \\arrow[d,shift left,\"\\beta_{FGB}\"] & GFGB \\arrow[d,shift right, \"G\\varepsilon_B\"'] \\arrow[d,shift left,\"\\beta_B\"]\\\\\n            GFGB \\arrow[r,\"G\\varepsilon_B\"] & GB\n        \\end{tikzcd}\n\n        Both squares commute (note that $G\\varepsilon_{FGB} = \\beta_{FGB}$), so $G\\varepsilon_B$ and $\\beta_B$ have the same composite with $GFG\\varepsilon_B$. But this is split epic, with splitting $GF\\eta_{GB}$; so $\\beta = G\\varepsilon$. Hence $K' = K$.\n\n        We now define the Kleisli comparison functor $L:\\mathcal{C}_\\mathbb{T} \\to \\mathcal{D}$ by $LA = FA$, \n        \\begin{tikzcd}\n            L(A \\arrow[r,green,\"f\"] & B)\n        \\end{tikzcd}\n        $=FA\\xrightarrow{Ff} FGFB \\xrightarrow{\\varepsilon_{FB}} FB$.\\\\\n        $L$ preserves identities by one of the triangular equalities for $(F\\dashv G)$; given\n        \\begin{tikzcd}\n            A \\arrow[r,green,\"f\"] & B \\arrow[r,green,\"g\"] & C\n        \\end{tikzcd}\n        , we have \n\n        \\begin{tikzcd}\n            FA \\arrow[r,\"Ff\"] & FGFB \\arrow[r,\"FGFg\"] \\arrow[d,\"\\varepsilon_{FB}\"] & FGFGFC \\arrow[r,\"FG\\varepsilon_{FC}\"] \\arrow[d,\"\\varepsilon_{FGFC}\"] & FGFC \\arrow[d,\"\\varepsilon_{FC}\"]\\\\\n            & FB \\arrow[r,\"Fg\"] & FGFC \\arrow[r,\"\\varepsilon_{FC}\"] & FC\n        \\end{tikzcd}\n\n        Some more verifications: $GLA=TA=G_\\mathbb{T}A$,\n        \\begin{tikzcd}\n            GL(A \\arrow[r,green,\"f\"] & B)\n        \\end{tikzcd}\n        $= (G\\varepsilon_{FB}) (GFf) = \\mu_B(Tf) = G_\\mathbb{T}f$.\\\\\n        $LF_\\mathbb{T} A = FA, LF_\\mathbb{T}(A\\xrightarrow{f}B) = (\\varepsilon_{FB})(F\\eta_B) (Ff) = Ff$.\\\\\n        Note that (lecturer murmured \\emph{for future reference}?) $L$ is full and faithful; its effect on morphisms (with given $\\dom$ and $\\cod$) is that of transposition across $(F\\dashv G)$.\\\\\n        Suppose $L':\\mathcal{C}_\\mathbb{T} \\to \\mathcal{D}$ is a morphsim of $\\mathbf{Adj}(\\mathbb{T})$. We must have $L'A =FA$, and $L'$ maps the counit\n        \\begin{tikzcd}\n            TA \\arrow[r,green] & A\n        \\end{tikzcd}\n        to the counit $FGFA \\xrightarrow{\\varepsilon_{FA}} FA$.\\\\\n        For any\n        \\begin{tikzcd}\n            A \\arrow[r,green,\"f\"] & B\n        \\end{tikzcd}\n        , we have \\textcolor{green}{$f=1_{TA}(F_\\mathbb{T}f)$}, so $L'($\\textcolor{green}{$f$}$) = \\varepsilon_{FA} (Ff) = Lf$.\n    \\end{proof}\n\\end{thm}\n\n---Lecture 16---\n\nIf $\\mathcal{C}$ has coproducts, then so does $\\mathcal{C}_\\mathbb{T}$, since $F_\\mathbb{T}$ preserves them.\\\\\nIn general, however, it has few other limits or colimits. In contrast, we have\n\n\\begin{thm} (5.8)\\\\\n    (i) The forgetful functor $G:\\mathcal{C}^\\T \\to \\mathcal{C}$ creates all limits which exist in $\\mathcal{C}$.\\\\\n    (ii) If $\\mathcal{C}$ has colimits of shape $\\mathcal{J}$, then $G:\\mathcal{C}^\\T \\to \\mathcal{C}$ creates them iff $T$ preserves them.\n    \\begin{proof}\n        Suppose given $D:\\mathcal{J} \\to \\mathcal{C}^\\T$; write $D(j) = (GD(j),\\delta_j)$, and suppose we have a limit cone $(L,(\\mu_j:L \\to GD(j) | j \\in \\ob\\mathcal{J}))$ is a limit cone for $GD$.\\\\\n        Then the composites $TL \\xrightarrow{T \\mu_j} TGD(j) \\xrightarrow{\\delta_j} GD(j)$ form a cone over $GD$, since the edges of $GD$ are homomorphisms, so they induce a unique $\\lambda:TL \\to L$ s.t. $\\mu_j \\lambda = \\delta_j(T\\mu)$ for all $j$.\\\\\n        The fact that $\\lambda$ is a $\\T$-algebra structure on $L$ follows from the fact that the $\\delta_j$ are algebra structures and uniqueness of factorizations through limits.\\\\\n        So $((L,\\lambda)(\\mu_j|j \\in \\ob\\mathcal{J}))$ is the unique lifting of the limit cone over $GD$ to a cone over $D$; and it's a limit, since given a cone over $D$ with apex $(A,\\alpha)$, we get a unique factorization $A \\xrightarrow{f} L$ in $\\mathcal{C}$, and $F$ is an algebra homomorphism by uniqueness of factorizations through $L$.\\\\\n        (ii) $\\implies$: $F:\\mathcal{C} \\to \\mathcal{C}^\\T$ preserves colimits since it's a left adjoint, so $T=GF$ preserves colimits of shape $\\mathcal{J}$.\\\\\n        $\\Leftarrow$: Suppose given $\\mathcal{J} \\to \\mathcal{C}^\\T$ as in (i), and a colimit cone $(GD(j) \\xrightarrow{\\mu_j} L| j \\in \\ob\\mathcal{J})$ in $\\mathcal{C}$.\\\\\n        Then $(TGD(j) \\xrightarrow{T\\mu_j} TL | j \\in \\ob\\mathcal{J})$ is also a colimit cone, so the composites $TGD(j) \\xrightarrow{f_j} GD(j) \\xrightarrow{\\mu_j} L$ induce a unique $\\lambda:TL \\to L$.\\\\\n        The rest of the argument is similar to that of (i) (verifying unique factorizations).\n    \\end{proof}\n\\end{thm}\n\n\\begin{defi} (5.9)\\\\\n    Given an adjunction $(\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D})$, $(F \\dashv G)$, we say the adjunction (or the functor $G$) is \\emph{monadic} if the comparison functor $K:\\mathcal{D} \\to \\mathcal{C}^\\T$ is part of an equivalence of categories.\\footnote{In some textbooks the author require $K$ to be an isomorphism here; but that is because they required stronger definition of creating limits.}\\\\\n    (Note that, since the Kleiski comparison $\\mathcal{C}_\\T \\to\\mathcal{D}$ is always full and faithful, it's part of an equivalence iff it (equivalently, $F$) is essentially surjective on objects).\n\\end{defi}\n\n\\begin{rem}\n    Given any adjunction $(F \\dashv G)$, for each object $B$ of $\\mathcal{D}$ we have a diagram \n    \\begin{tikzcd}\n        FGFGB \\arrow[r,shift left, \"FG\\varepsilon_B\"] \\arrow[r, shift right, \"\\varepsilon_{FGB}\"'] & FGB \\arrow[r,\"\\varepsilon_B\"] & B\n    \\end{tikzcd}\n    with equal composites. The \\emph{primeval monadicity theorem} asserts that $\\mathcal{C}^\\T$ is characterized in $\\mathbf{Adj}(\\T)$ by the fact that these diagrams are all coequalizers.\n\\end{rem}\n\n\\begin{defi} (5.10)\\\\\n    We say a parallel pair $A \\stackrel[g]{f}{\\rightrightarrows} B$ is \\emph{reflexive} if there exists $B \\xrightarrow{r} A$ s.t. $fr = gr = 1_B$.\\\\\n    (Note that in our previous remark,\n    \\begin{tikzcd}\n        FGFGB \\arrow[r,shift left, \"FG\\varepsilon_B\"] \\arrow[r,shift right, \"\\varepsilon_{FGB}\"'] & FGB\n    \\end{tikzcd}\n    is reflexive, with $r = F\\eta_{GB}$ by triangular identities).\\\\\n    We say $\\mathcal{C}$ has reflexive coequalizers if it has coequalizers of all reflexive pairs (equivalently, colimits of shape $\\mathcal{J}$ where\n    \\begin{tikzcd}\n        \\cdot \\arrow[loop, out=105, in=165,looseness = 4] \\arrow[loop, out=255, in=195, looseness=4] \\arrow[r,shift left] \\arrow[r,shift right] & \\cdot \\arrow[l]\n    \\end{tikzcd}\n    ).\\\\\n    (b) By a \\emph{split coequalizer diagram}, we mean a diagram\n    \\begin{tikzcd}\n        A \\arrow[r,shift left, \"f\"] \\arrow[r,shift right, \"g\"'] & B \\arrow[r,\"h\"] \\arrow[l,bend left=40,\"t\"] & C \\arrow[l,bend left = 20,\"s\"]\n    \\end{tikzcd}\n    satisfying $hf=hg,hs=1_C,gt=1_B$ and $ft = sh$.\\\\\n    These equations imply that $h$ is a coequalizer of $(f,g)$: if $B \\xrightarrow{x} D$ satisfies $xf = xg$, then $x=xgt=xft=xsh$, so $x$ factors through $h$, and the factorization is unique since $h$ is split epic.\\\\\n    Note that split coequalizers are preserved by \\emph{all} functors.\\\\\n    (c) Given a functor $G:\\mathcal{D} \\to \\mathcal{C}$, a parallel pair $A \\stackrel[g]{f}{\\rightrightarrows} B$ is called \\emph{$G$-split} if there exsts a split coequalizer diagram\n    \\begin{tikzcd}\n        GA \\arrow[r,shift left,\"Gf\"] \\arrow[r,shift right,\"Gg\"'] & GB \\arrow[r,\"h\"] \\arrow[l, bend left=40, \"t\"] & C \\arrow[l, bend left=20, \"s\"]\n    \\end{tikzcd}\n    in $\\mathcal{C}$.\\\\\n    Note that \n    \\begin{tikzcd}\n        FGFGB \\arrow[r,shift left, \"FG\\varepsilon_B\"] \\arrow[r,shift right, \"\\varepsilon_{FGB}\"'] & FGB\n    \\end{tikzcd}\n    is $G$-split, since \n    \\begin{tikzcd}\n        GFGFGB \\arrow[r,shift left, \"GFG\\varepsilon_B\"] \\arrow[r,shift right,\"G\\varepsilon_{FGB}\"'] & GFGB \\arrow[l,bend left=35, \"\\eta_{GFGB}\"] \\arrow[r,\"G\\varepsilon_B\"] & GB \\arrow[l,bend left=20, \"\\eta_{GB}\"]\n    \\end{tikzcd}\n    is a split coequalizer.\n\\end{defi}\n\n\\begin{lemma} (5.11)\\\\\n    Suppose we are given an adjunction $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$, inducing a monad $\\T$ on $\\mathcal{C}$, then $K:\\mathcal{D} \\to \\mathcal{C}^\\T$ has a left adjoint provided, for every $\\T$-algebra $(A,\\alpha)$, the pair \n    \\begin{tikzcd}\n        FGFA \\arrow[r,shift right, \"\\varepsilon_{FA}\"'] \\arrow[r,shift left, \"F\\alpha\"] & FA\n    \\end{tikzcd} \n    has a coqeualizer in $\\mathcal{D}$.\n    \\begin{proof}\n        We define $L:\\mathcal{C}^\\T \\to \\mathcal{D}$ by taking $FA \\to L(A,\\alpha)$ to be a coequalizer for $(F\\alpha,\\varepsilon_{FA})$. Note that this is a functor $\\mathcal{C}^\\T \\to \\mathcal{D}$.\\\\\n        Recall that $K$ is defined by $KB=(GB,G\\varepsilon_B)$.\\\\\n        For any $B$, morphisms $FA \\xrightarrow{f} B$ satisfying $f(F\\alpha) = f(\\varepsilon_{FA})$.\\\\\n        These correspond to morphisms $A \\xrightarrow{\\check{f}} GB$ satisfying \n        $$\\check{f}\\alpha = Gf = G(\\varepsilon_B (F\\check{f})) = (G\\varepsilon_B) (T\\check{f})$$\n        i.e. to algebra homomorphisms $(A,\\alpha) \\to KB$.\\\\\n        It's tedious but entirely straightforward to verify that these bijections are natural in $(A,\\alpha)$ and in $B$.\n    \\end{proof}\n\\end{lemma}\n\n---Lecture 17---\n\n\\begin{thm} (5.12, Precise Monadicity Theorem)\\\\\n    $G:\\mathcal{D} \\to \\mathcal{C}$ is monadic iff $G$ has a left adjoint and creates coequalizers of $G$-split pairs.\n\\end{thm}\n\n\\begin{thm} (5.13, Refined/Reflexive Monadicity Theorem)\\\\\n    Suppose $\\mathcal{D}$ has and $G:\\mathcal{D} \\to \\mathcal{C}$ preserves reflexive coequalizers, and that $G$ reflects isomorphisms and has a left adjoint. Then $G$ is monadic.\n    \\begin{proof}\n        (5.12) $\\implies$: It's sufficient to show that $G^\\mathbb{T}:\\mathcal{C}^\\mathbb{T} \\to \\mathcal{C}$ creates coequalizers of $G^\\mathbb{T}$-split pairs. But this follows from the argument of 5.8(ii), since if $(A,\\alpha) \\stackrel[g]{f}{\\rightrightarrows} (B,\\beta)$ is a $G^\\T$-split pair, the coequalizer of $A \\stackrel[g]{f}{\\rightrightarrows} B$ is preserved by $T$ and by $TT$.\\\\\n        (5.12) $\\Leftarrow$ and (5.13): Let $\\T$ denotes the monad induced by $(F \\dashv G)$. For any $\\T$-algebra $(A,\\alpha)$, the pair\n        \\begin{tikzcd}\n            FGFA \\arrow[r,shift right, \"\\varepsilon_{FA}\"'] \\arrow[r,shift left, \"F\\alpha\"] & FA\n        \\end{tikzcd}\n        is both reflexive and $G$-split, so has coequalizer in $\\mathcal{D}$; and hence by (5.11), $K:\\mathcal{D} \\to \\mathcal{C}^\\T$ has a left adjoint $L$.\\\\\n        The unit of $(L \\dashv K)$ at an algebra $(A,\\alpha)$: the coequalizer defining $L(A,\\alpha)$ is mapped by $K$ to the diagram\n\n        \\begin{tikzcd}\n            F^\\T TA \\arrow[r,shift left, \"F^\\T \\alpha\"] \\arrow[r,shift right, \"\\mu_A\"'] & F^\\T A \\arrow[rr] \\arrow[rd,\"\\alpha\"'] & & KL(A,\\alpha) \\\\\n            & & (A,\\alpha) \\arrow[ru,dashed,\"{\\iota_{(A,\\alpha)}}\"] &\n        \\end{tikzcd}\n\n        and $\\iota_{(A,\\alpha)}$ is the factorization of this through the ($G^\\T$-split) coequalizer of $\\alpha$.\\\\\n        But either set of hypotheses implies that $G$ preserves the coequalizers defining $L(A,\\alpha)$, so $\\iota_{(A,\\alpha)}$ is an isomorphism.\\\\\n        For the counit $\\xi_B: LKB \\to B$, we have a coequalizer\n\n        \\begin{tikzcd}\n            FGFGB \\arrow[r,shift left, \"FG\\varepsilon_B\"] \\arrow[r,shift right, \"\\varepsilon_{FGB}\"'] & FGB \\arrow[r,two heads] \\arrow[rd,\"\\varepsilon_B\"'] & LKB \\arrow[d,dashed, \"\\xi_B\"]\\\\\n            & & B\n        \\end{tikzcd}\n\n        Again, either set of hypothesis implies that $\\varepsilon_B$ is a coequalizer of the pair $(FG\\varepsilon_B, \\varepsilon_{FGB})$, so $\\xi_B$ is an isomorphism.\n    \\end{proof}\n\\end{thm}\n\n\\begin{eg} (5.14)\\\\\n    (a) The forgetful functor $\\mathbf{Gp} \\to \\mathbf{Set}$, $\\mathbf{Rng} \\to \\mathbf{Set}$, $\\mathbf{Mod}_R \\to \\mathbf{Set}, ...$ all satisfy the hypotheses of (5.13), for the reflexive coequalizers, use Sheet 4 Question 3\\footnote{Lecturer: I usually prove it as a lemma here, but this year I'm not going to do it because I want you to do it in the fourth example sheet. It's a nice exercise to do it by yourself.} which shows that if $A \\stackrel[g]{f}{\\rightrightarrows} B \\xrightarrow{h} C$ is a reflexive coequalizer diagram in $\\mathbf{Set}$, then so is \n    \\begin{tikzcd}\n        A^n \\arrow[r,shift left, \"f^n\"] \\arrow[r,shift right, \"g^n\"'] & B \\arrow[r,\"h^n\"] & C^n\n    \\end{tikzcd}\n    .\\\\\n    (b) Any reflection is monadic: this follows from Sheet 3 Question 2, but can also be proved using (5.12). Let $\\mathcal{D}$ be a reflective (so full) subcategory of $\\mathcal{C}$, and suppose a pair $A \\stackrel[g]{f}{\\rightrightarrows} B$ in $\\mathcal{D}$ fits into a split coequalizer diagram\n    \\begin{tikzcd}\n        A \\arrow[r,shift left, \"f\"] \\arrow[r,shift right, \"g\"'] & B \\arrow[r,green, \"h\"] \\arrow[l,green, bend left=40,\"t\"] & \\textcolor{green}{C} \\arrow[l,green, bend left=40, \"s\"]\n    \\end{tikzcd}\n    in $\\mathcal{C}$. Then $t$ and $ft=sh$ belong to $\\mathcal{D}$, since $\\mathcal{D}$ is full, and hence $s$ is in $\\mathcal{D}$ since it's an equalizer of $(1_B,sh)$ and $\\mathcal{D}$ is closed under limits in $\\mathcal{C}$. Hence also $h \\in \\mor\\mathcal{D}$.\\\\\n    (c) This is a non-example but an important one: Consider the composite adjunction\n\n    \\begin{tikzcd}\n        \\mathbf{Set} \\arrow[r, shift left, \"F\"] & \\mathbf{AbGp} \\arrow[l, shift left, \"U\"] \\arrow[r, shift left, \"L\"] & \\mathbf{tfAbGp} \\arrow[l,shift left, \"I\"]\n    \\end{tikzcd}\n\n    The two factors are monadic by (a) and (b) respectively, but the composite isn't since the monad it induces on $\\mathbf{Set}$ is isomorphic to that induced by $(F \\dashv U)$. So monadic adjunctions are not stable under composition -- that's why we have to have the conditions in (5.13) -- note that those adjunction are stable under compositions (I think lecturer said so but didn't write it down).\\\\\n    (d) Consider the forgetful functor $\\mathbf{Top} \\xrightarrow{U} \\mathbf{Set}$. This is faithful and has both left and right adjoints (so preserves all coequalizers), but the monad induced on $\\mathbf{Set}$ is $(1,1,1)$, and the category of algebras is $\\mathbf{Set}$. So we see that we can't weaken the condition in (5.13) of $G$ reflecting isomorphisms to only be faithful.\\\\\n    (e) Consider the composite function\n\n    \\begin{tikzcd}\n        \\mathbf{Set} \\arrow[r,shift left, \"D\"] & \\mathbf{Top} \\arrow[l,shift left, \"U\"] \\arrow[r,shift left,\"\\beta\"] & \\mathbf{KHaus} \\arrow[l, shift left, \"I\"]\n    \\end{tikzcd}\n\n    We'll show that this satisfies the hypotheses of (5.12) (with use of a lemma in general topology which lecturer is not going to prove): Let \n    \\begin{tikzcd}\n        X \\arrow[r,shift left, \"f\"] \\arrow[r, shift right, \"g\"'] & Y \\arrow[l, green, bend left=40, \"t\"] \\arrow[r,green, \"h\"] & \\textcolor{green}{Z} \\arrow[l,green,bend left=40, \"s\"]\n    \\end{tikzcd}\n    be a split coequalizer in $\\mathbf{Set}$, where $X$ and $Y$ have compact Hausdorff topologies and $f,g$ are continuonus. Note that the quotient topology on $Z \\cong Y/R$ is compact, so it's the only possible candidate for a compact Hausdorff topology making $h$ continuous.\\\\\n    We use the lemma from general topology: if $Y$ is compact Hausdorff, then a quotient $Y/R$ is Hausdorff iff $R \\subseteq Y \\times Y$ is closed.\\\\\n    We note $R = \\{(y,y') | h(y) = h(y') \\} = \\{(y,y') | sh(y) = sh(y')\\} = \\{(y,y') | ft(y) = ft(y')\\}$.\\\\\n    So if we define $S = \\{(x,x')|f(x) = f(x')\\} \\subseteq X \\times X$, then $R \\subseteq (g \\times g) (S)$; but the reverse inclusion also holds. But \n    \\begin{tikzcd}\n        S \\arrow[r] & X \\times X \\arrow[r,shift left, \"f\\pi_1\"] \\arrow[r,shift right, \"f\\pi_2\"'] & Y\n    \\end{tikzcd}\n    is an equalizer, and $Y$ is Hausdorff, so $S$ is closed in $X \\times X$ and hence compact. So $R=(g \\times g)(S)$ is compact and hence closed in $Y \\times Y$.\n\\end{eg}\n\n---Lecture 18---\n\n\\begin{defi} (5.15)\\\\\n    Let $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$ be an adjunction, and suppose $\\mathcal{D}$ has reflexive coequalizers. The \\emph{monadic tower} of $(F \\dashv G)$ is the diagram\n\n    \\begin{tikzcd}\n        \\mathcal{D} \\arrow[rrrd,shift left,\"K'\"] \\arrow[rrddd,shift left,\"K\"] \\arrow[rddddd,shift left,\"G\"] & & ...\\\\\n        & & & (\\mathcal{C}^\\T)^\\mathbb{S} \\arrow[lllu,shift left,\"L'\"] \\arrow[ldd,shift left]\\\\\n        & & & \\\\\n        & & \\mathcal{C}^\\T \\arrow[uuull,shift left,\"L\"] \\arrow[uur,shift left] \\arrow[ldd,shift left] &\\\\\n        & & & &\\\\\n        & \\mathcal{C} \\arrow[uuuuul,shift left,\"F\"] \\arrow[uur,shift left] & &\n    \\end{tikzcd}\n\n    where $\\T$ is the monad induced by $(F \\dashv G)$, $K$ is as in (5.7), $L$ as in (5.11), $\\mathbb{S}$ is the monad induced by $(L \\dashv K)$, and so on.\\\\\n    We say $(F \\dashv G)$ has \\emph{monadic length} $n$ if we reach an equivalence after $n$ steps.\\\\\n    For example, the adjunction of 5.14(c) has monadic length 2, the adjunction of 5.14(d) has monadic length $\\infty$ (the tower never reaches an equivalence).\n\\end{defi}\n\nLecturer: Normally this is where I end chapter 5, but since this year we'll be doing topos I realized that we'll need an example in chapter 7 which is purely about monads and adjunctions, so we'd rather do it here.\n\n\\begin{thm} (5.16)\\\\\n    Suppose given an adjunction $\\mathcal{C} \\stackrel[R]{L}{\\rightleftarrows} \\mathcal{D}$ and monads $\\T,\\mathbb{S}$ on $\\mathcal{C},\\mathcal{D}$ respectively, and a functor $\\bar{R}:\\mathcal{D}^\\mathbb{S} \\to \\mathcal{C}^\\T$ such that \n    \\begin{tikzcd}\n        \\mathcal{D}^\\mathbb{S} \\arrow[r,\"R\"] \\arrow[d,\"G^\\mathbb{S}\"] & \\mathcal{C}^\\T \\arrow[d,\"G^\\T\"]\\\\\n        \\mathcal{D} \\arrow[r,\"R\"] & \\mathcal{C}\n    \\end{tikzcd}\n    commutes up to isomorphism.\\\\\n    Suppose also $\\mathcal{D}^\\mathbb{S}$ has reflexive coequalizers. Then $\\bar{R}$ has a left adjoint $\\bar{L}$.\\\\\n    (Note that there's also a version of this for right adjoint, but it is \\emph{not} the dual of this.)\n    \\begin{proof}\n        Note that if $\\bar{L}$ exists, we must have $\\bar{L} F^\\T = F^\\mathbb{S} L$, by (3.6). So we'd expect $\\bar{L}(A,\\alpha)$ to be a coequalizer of two morphisms\n        \\begin{tikzcd}\n            F^\\mathbb{S} LTA \\arrow[r,shift left, \"F^\\mathbb{S} L\\alpha\"] \\arrow[r,shift right, \"?\"'] & F^\\mathbb{S} LA\n        \\end{tikzcd}\n        .\\\\\n        To contruct the second morphism, note first that we can assume, WLOG, that $G^\\T \\bar{R} = RG^\\mathbb{S}$, by transporting $\\T$-algebra structures along the isomorphism $G^\\T \\bar{R} (B,\\beta) \\to RB$.\\\\\n        We obtain $\\theta:TR \\to RS$ by \n        \\begin{equation*}\n            \\begin{aligned}\n                \\frac{R \\xrightarrow{R\\iota} RS = RG^\\mathbb{S} F^\\mathbb{S} = G^\\T \\bar{R} F^\\mathbb{S}}{\\frac{F^\\T R \\to \\bar{R} F^\\mathbb{S}}{TR = G^\\T F^\\T R \\xrightarrow{\\theta} G^\\T \\bar{R} F^\\mathbb{S} = RG^\\mathbb{S} F^\\mathbb{S} = RS}}\n            \\end{aligned}\n        \\end{equation*}\n        Convert it to $\\phi:LT \\to SL$ by\n        \\begin{tikzcd}\n            LT \\arrow[r,\"LT\\gamma\"] & LTRL \\arrow[r,\"L\\theta_L\"] & LRSL \\arrow[r,\"\\delta_{SL}\"] & SL\n        \\end{tikzcd}\n        where $\\gamma$ and $\\delta$ are the unit and counit of $(L\\dashv R)$.\\\\\n        Transposing across $(F^\\mathbb{S} \\dashv G^\\mathbb{S})$, we get $F^\\mathbb{S} LT \\xrightarrow{\\bar{\\phi}} F^\\mathbb{S}L$.\\\\\n        The pair $(F^\\mathbb{S} L\\alpha,\\bar{\\phi}_A)$ is reflexive, with common splitting $F^\\mathbb{S} L\\eta$.\\\\\n        It can be verified that the coequalizer of this pair has the universal property we require for $I(A,\\alpha)$. (Not saying this is examinable, but useful to know.)\n    \\end{proof}\n\\end{thm}\n\n\\newpage\n\n\\section{Cartesian Closed Categories}\n\n\\begin{defi} (6.1)\\\\\n    Let $\\mathcal{C}$ be a category with finite products. We say $A \\in \\ob\\mathcal{C}$ is \\emph{exponentiable} if the functor $(-) \\times A: \\mathcal{C} \\to \\mathcal{C}$ has a right adjoint $(-)^A$.\\\\\n    If every object of $\\mathcal{C}$ is exponentiable, then we say $\\mathcal{C}$ is \\emph{cartesian closed}.\n\\end{defi}\n\n\\begin{eg} (6.2)\\\\\n    (a) We'll expect $\\mathbf{Set}$ to be cartesian closed, and it is indeed, with $B^A = \\mathbf{Set}(A,B)$. A function $f:C \\times A \\to B$ (sometimes called \\emph{lambda conversion}) corresponds to $\\bar{f}: C \\to B^A$.\\\\\n    (b) $\\mathbf{Cat}$ is cartesian closed, with $\\mathcal{D}^\\mathcal{C} = [\\mathcal{C},\\mathcal{D}]$.\\\\\n    (c) In $\\mathbf{Top}$, if an exponential $Y^X$ exists, its points must be the continuous maps $X \\to Y$.\\\\\n    The \\href{https://en.wikipedia.org/wiki/Compact-open_topology}{compact-open topology} on $\\mathbf{Top}(X,Y)$ has the universal property of an exponential iff $X$ is locally compact.\\\\\n    Note that finite products of exponentiable objects are exponentiable: since $(-) \\times (A \\times B) \\cong (- \\times A) \\times B$, we have $(-)^{A \\times B} \\cong ((-)^B)^A$.\\\\\n    However, even if $X$ and $Y$ are locally compact, $X^Y$ need not be (take both $X$ and $Y$ be the real line, and $\\R^\\R$ is too big to be locally compact). So the exponentiable objects don't form a cartesian closed full subcategory.\\\\\n    (d) A cartesian closed poset, is called a \\emph{Heiting semilattice}: it's a poset with finite meets and a binary operation $\\implies$ satisfying $a \\leq (b \\implies c)$ iff $a \\wedge b \\leq c$.\\\\\n    For example, a complete poset is a Heyting semillatice iff it satisfies the infinite distributive law\n    $$a \\wedge \\bigvee \\{b_i | i \\in I\\} = \\bigvee \\{a \\wedge b_i | i \\in I\\}$$\n    For any topological space $X$, the lattice $\\mathcal{O}(X)$ of open subsets satisfies this condition, since $\\wedge$ and $\\bigvee$ coincide with $\\cap$ and $\\bigcup$.\n\\end{eg}\n\nRecall that, if $B \\in ob\\mathcal{C}$, we define $\\mathcal{C}/B$ to have objects which are morphisms $\\begin{pmatrix}A\\\\\\downarrow\\\\B\\end{pmatrix}$ in $\\mathcal{C}$, and morphisms are commutative triangles \n\\begin{tikzcd}\n    A \\arrow[rr] \\arrow[rd] & & A' \\arrow[ld]\\\\\n    & B &\n\\end{tikzcd}\n. The forgetful functor $\\mathcal{C}/B \\to \\mathcal{C}$ will be denoted $\\sum_B$.\\\\\nIf $\\mathcal{C}$ has finite products, $\\sum_B$ has a left adjoint $B^*$ which sends $A$ to $\\begin{pmatrix}A \\times B\\\\\\downarrow \\pi_2\\\\B\\end{pmatrix}$, since morphisms\n\\begin{tikzcd}\n    C \\arrow[rr,\"{(f,g)}\"] \\arrow[rd, \"g\"'] & & A \\times B \\arrow[ld,\"\\pi_2\"]\\\\\n    & B &\n\\end{tikzcd}\ncorresponds to morphisms $C = \\sum_B g \\xrightarrow{f} A$.\n\n\\begin{lemma} (6.3)\\\\\n    If $\\mathcal{C}$ has all finite limits, then an object $B$ is exponetniable iff $B^*:\\mathcal{C} \\to \\mathcal{C}/B$ has a right adjoint $\\prod_B$.\n    \\begin{proof}\n        $\\Leftarrow$: the composite $\\sum_B B^*$ is equal to $(-) \\times B$, so we take $(-)^B$ to be $\\prod_B B^*$.\\\\\n        $\\implies$: Now we have an exponential and we want to build $\\prod_B$. What we'll do is to use a pullback: for any $A \\xrightarrow{f} B$, we define $\\prod_B(f)$ to be the pullback\n\n        \\begin{tikzcd}\n            \\prod_B(f) \\arrow[r] \\arrow[d] & A^B \\arrow[d,\"f^B\"]\\\\\n            1 \\arrow[r,\"\\bar{\\pi_2}\"] & B^B\n        \\end{tikzcd}\n\n        The morphisms $C \\to \\prod_B(f)$ corresponds to morphisms $C \\to A^B$ making \n        \\begin{tikzcd}\n            C \\arrow[r] \\arrow[d] & A^B \\arrow[d,\"f^B\"] \\\\\n            1 \\arrow[r,\"\\bar{\\pi_2}\"] & B^B\n        \\end{tikzcd}\n        commute, i.e. to morphisms $C \\times B \\to A$ making \n        \\begin{tikzcd}\n            C \\times B \\arrow[r] \\arrow[rd,\"\\pi_2\"'] & A \\arrow[d,\"f\"]\\\\\n            & B\n        \\end{tikzcd}\n        commute.\n    \\end{proof}\n\\end{lemma}\n\n---two lectures (19,20) to be typesetted---\n\n--Lecture 19---\n\n\\begin{lemma} (6.4)\\\\\n    Suppose $\\mathcal{C}$ has all finite limits. If $A$ is exponentiable in $\\mathcal{C}$, then $B^*A$ is exponentiable in $\\mathcal{C}/B$ for any $B$.\\\\\n    Moreover, $B^*$ preserves exponentials.\n    \\begin{proof}\n        Given an object $\\begin{pmatrix}C\\\\\\downarrow f\\\\B\\end{pmatrix}$, form the pullback\n            \\begin{tikzcd}\n                P \\arrow[r] \\arrow[d,\"f^{(b^*A)}\"] & C^A \\arrow[d,\"f^A\"]\\\\\n                B \\arrow[r,\"\\bar{\\pi_1}\"] & B^A\n            \\end{tikzcd}\n            . Then for any \n            \\begin{tikzcd}\n                D \\arrow[d,\"g\"]\\\\\n                B\n            \\end{tikzcd}\n            , morphisms $g \\to f^{B^*A}$ in $\\mathcal{C}/B$ corresponds to morphisms $D \\xrightarrow{\\bar{h}} C^A$ making \n            \\begin{tikzcd}\n                D \\arrow[r,\"\\bar{h}\"] \\arrow[d,\"g\"] & C^A \\arrow[d,\"f^A\"]\\\\\n                B \\arrow[r,\"\\bar{\\pi}_1\"] & B^A\n            \\end{tikzcd}\n            commute, and hence to morphisms $D \\times A \\xrightarrow{h} C$ making\n            \\begin{tikzcd}\n                D \\times A \\arrow[r,\"h\"] \\arrow[rd,\"g\\pi_1\"'] & C \\arrow[d,\"f\"]\\\\\n                & B\n            \\end{tikzcd}\n            commute. But\n            \\begin{tikzcd}\n                D \\times A \\arrow[r,\"g \\times 1_A\"] \\arrow[d,\"\\pi_1\"] & B \\times A \\arrow[d,\"\\pi_1\"]\\\\\n                D \\arrow[r,\"g\"] & B\n            \\end{tikzcd}\n            is a pullback in $\\mathcal{C}$, i.e. a product in $\\mathcal{C}/B$.\\\\\n            For the second assertion, note that if \n            \\begin{tikzcd}\n                C \\arrow[d,\"f\"]\\\\\n                B\n            \\end{tikzcd}\n            is of the form\n            \\begin{tikzcd}\n                B \\times E \\arrow[d,\"\\pi_1\"]\\\\\n                B\n            \\end{tikzcd}\n            , then the pullback defining $f^{B^*A}$ becomes\n            \\begin{tikzcd}\n                B \\times E^A \\arrow[r,\"\\bar{\\pi}_1 \\times 1\"] \\arrow[d,\"\\pi_1\"] & B^A \\times E^A \\arrow[d,\"\\pi_1\"]\\\\\n                B \\arrow[r,\"\\bar{\\pi}_1\"] & B^A\n            \\end{tikzcd}\n            , so $f^{B^*A} \\cong B^*(E^A)$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{rem}\n    $\\mathcal{C}/B$ is isomorphic to the category of coalgebras for the monad structure on $(-) \\times B$ (5.2(c)); so the first part of (6.4) could have been proved using (5.16).\n\\end{rem}\n\n\\begin{defi} (6.5)\\\\\n    We say $\\mathcal{C}$ is \\emph{locally Cartesian closed} if it has all finite limits and each $\\mathcal{C}/B$ is cartesian closed.\\\\\n    Note that this includes the fact that $\\mathcal{C}/1 \\cong \\mathcal{C}$ is cartesian closed, so being \\emph{locally} Cartesian closed is actually stronger than being cartesian closed!\n\\end{defi}\n\n\\begin{eg} (6.6)\\\\\n\t(a) $\\mathbf{Set}$ is locally cartesian closed, since $\\mathbf{Set}/B \\cong \\mathbf{Set}^B$ for any $B$.\\\\\n\t(b) For any small category $\\mathcal{C}$, $[\\mathcal{C},\\mathbf{Set}]$ is cartesian closed: by Yoneda, $G^F(A) \\cong [\\mathcal{C},\\mathbf{Set}](\\mathcal{C}(A,-),G^F) \\cong  [\\mathcal{C},\\mathbf{Set}](\\mathcal{C}(A,-) \\times F,G)$.\\\\\n\tSo we take RHS as a definition of $GF(A)$, and define $G^F$ on morphisms $A \\xrightarrow{f} B$ by composition with $\\mathcal{C}(f,-) \\times 1_F$.\\\\\n\tNote that the class of functors $H$ for which we have $[\\mathcal{C},\\mathbf{Set}](H,G^F) \\cong [\\mathcal{C},\\mathbf{Set}](H \\times F,G)$ is closed under colimits; but every functor $\\mathcal{C} \\to \\mathbf{Set}$ is a colimit of representables.\\\\\n\tIn fact, $[\\mathcal{C},\\mathbf{Set}]$ is locally cartesian closed, since all its slice categories $[\\mathcal{C},\\mathbf{Set}]/F$ are of the same form (see q6 on sheet 4).\\\\\n\t(c) Any Heyting semilattice $H$ is locally cartesian closed, since $H/b\\Z \\downarrow (b)$, the poset of elements $\\leq b$, and $b^* = (-) \\wedge b$ is surjective.\\\\\n\t(d) (non-example) $\\mathbf{Cat}$ is not locally cartesian closed, since not all strong epimorphisms are regular (sheet 3 q6).\\\\\n\\end{eg}\n\nNote that, given \n\\begin{tikzcd}\nA \\arrow[d,\"f\"]\\\\\nB\n\\end{tikzcd}\nin $\\mathcal{C}/B$, the iterated slice $(\\mathcal{C}/B)/f$ is isomorphic to $\\mathcal{C}/A$, and this identifies $f^*:\\mathcal{C}/B \\to (\\mathcal{C}/B)/f$ with the operation of pulling back morphisms along $f$. So by (6.3), $\\mathcal{C}$ is lcc iff it has finite limits and $f^*:\\mathcal{C}/B \\to \\mathcal{C}/A$ has a right adjoint $\\Pi_f$ for every $A \\xrightarrow{f} B$ in $\\mathcal{C}$.\n\n\n\\newpage\n\n\\section{Toposes}\n\n---Lecture 21---\n\nSome introduction by lecturer: Grothendick introduced toposes as categories of \\emph{generalized sheaves}. J.Giraud gave a characterization of such categories by (set-theoretic) categorical properties.\n\nF.W.Lawvere and M Tierney investigated the elementary categorical properties of these categories, and come up with the elementary definition.\n\nIn fact, a Grothendieck topos is exactly a Lawvere-Tierneg topos which is (co)complete and locally small, and has a separating set of objects.\n\n\\begin{defi} (7.1)\\\\\n    (a) Let $\\mathcal{E}$ be a category with finite limits. A \\emph{subobject classifier} for $\\mathcal{E}$ is a monomorphism $\\Omega' \\stackrel{\\top}{\\rightarrowtail} \\Omega$ s.t., for every monomorphism $A' \\stackrel{m}{\\rightarrowtail} A$ in $\\mathcal{E}$, there's a unique $\\chi_m:A \\to \\Omega$ for which there is a pullback square\n\n    \\begin{tikzcd}\n        A' \\arrow[r] \\arrow[d,tail,\"m\"] & \\Omega' \\arrow[d,\"\\top\"] \\\\\n        A \\arrow[r,\"\\chi_m\"] & \\Omega\n    \\end{tikzcd}\n\n    Note that, for any $A$, there's a unique $A\\to \\Omega$ which factors through $\\Omega' \\stackrel{\\top}{\\rightarrowtail} \\Omega$, so the domain of $\\top$ is actually a terminal object.\\\\\n    If $\\mathcal{E}$ is well-powered, we have a functor $Sub_\\mathcal{E} (-):\\mathcal{E}^{op} \\to \\mathbf{Set}$ sending $A$ to the set of (isomorphism classes of) subobjects of $A$, and acting on morphisms by pullback, and a subobject classifier is a representation of this functor.\n\n    (b) A \\emph{topos} is a category which has finite limits, is cartesian closed, and has a subobject classifier.\n\n    (c) If $\\mathcal{E}$ and $\\mathcal{F}$ are toposes, a \\emph{logical functor} $F:\\mathcal{E} \\to \\mathcal{F}$ is one which preserves finite limits, exponentials and the subobject classifier.\n\\end{defi}\n\n\\begin{eg} (7.2)\\\\\n    (a) $\\mathbf{Set}$ is a topos, with $\\Omega =\\{0,1\\}$ and $t=1:1 \\to \\{0,1\\}$, and of course $\\chi_m$ is just the characteristic function of $A'$.\\\\\n    So also is the category of finite sets $\\mathbf{Set}_F$, or the category of sets of cardinality less than $\\kappa$, $\\mathbf{Set}_\\kappa$, where $\\kappa$ is an infinite cardinal s.t. $\\lambda < \\kappa \\implies 2^\\lambda < \\kappa$.\n\n    (b) For any small category $\\mathcal{C}$, $[\\mathcal{C}^{op},\\mathbf{Set}]$ is a topos: we've seen that it's cartesian closed, and $\\Omega$ is determined by Yoneda: we have\\\\\n    $\\Omega(A) = \\cong [\\mathcal{C}^{op},\\mathbf{Set}](\\mathcal{C}(-,A),\\Omega) \\cong \\{$subfunctors of $\\mathcal{C}(-,A)\\}$.\\\\\n    So we define $\\Omega(A)$ to be the set of \\emph{sieves} on $A$, i.e. sets $R$ of morphisms with codomain $A$, s.t. $f \\in R \\implies fg \\in R$ for any $g$.\\\\\n    Given $B\\xrightarrow{f} A$ and a sieve $R$ on $A$, we need a pullback: define $f^* R$ to be the set of $g$ with codomain $B$ s.t. $fg \\in R$.\\\\\n    This makes $\\Omega$ into a functor $\\mathcal{C}^{op} \\to \\mathbf{Set}$: $T:1 \\to \\Omega$ is defined by $T_A(*) = \\{$all morphisms withcodomain $A\\}$.\\\\\n    Given a subfunctor $F' \\stackrel{m}{\\rightarrowtail} F$, we define $\\chi_m:F \\to \\Omega$ by $(\\chi_m)_A(x) = \\{f:B \\to A|Ff(x) \\in F'(b)\\}$ (lecturer: if you find this not obvious, then write it down and you'll find it obvious).\\\\\n    This is the unique natural transformation making \n\n    \\begin{tikzcd}\n        F' \\arrow[r] \\arrow[d,tail,\"m\"] & 1 \\arrow[d,tail,\"\\top\"]\\\\\n        F \\arrow[r] & \\Omega\n    \\end{tikzcd}\n\n    (c) For any space $X$, $\\mathbf{Sh}(X)$ is a topos. It's cartesian closed by 6.12(ii); for the subobject classifier, we take $\\Omega(U) = \\{V \\in \\mathcal{O}(X) | V \\subseteq U\\}$. $\\Omega(U' \\to U)$ is the map $V \\to V\\cap U'$ and $\\Omega$ is a sheaf since if we have $U=\\cup_{i \\in I} U_i$, and $V_i \\subseteq U_i$ s.t. $V_i \\cap U_j = V_j \\cap U_i$ for each $i,j$, then $V = \\cup_{i \\in I} V_i$ is the unique open subset of $U$ with $V \\cap U_i = V_i$ for each $i$.\\\\\n    If $F' \\stackrel{m}{\\rightarrowtail} F$ is a subsheaf, then for any $x \\in F(U)$, the sieve $\\{V \\subseteq U | x|_V \\in F'(V)\\}$ has a greatest element since $F'$ is a sheaf, so we define $\\chi_m:F \\to \\Omega$ to send $x$ to this (the previous greatest) element.\n\n    (d) Let $\\mathcal{C}$ be a group $G$. The topos structure on $[G,\\mathbf{Set}]$ is particularly simplel: $B^A$ is the set of all $G$-equivariant maps $A\\times G \\xrightarrow{f} B$, but such an $f$ is determined by its values at elements of the form $(a,1)$, since $f(a,g) = g \\cdot f(g^{-1}\\cdot a, 1)$, and this restriction can be any mapping $A \\times \\{1\\} \\to B$. So we can take $B^A$ to be the set of functions $A \\to B$, with $G$ acting by $(g \\cdot f) (a) = g(f(g^{-1} \\cdot a))$. And $\\Omega = \\{0,1\\}$ with trivial $G$-action.\\\\\n    So the forgetful functor $[G,\\mathbf{Set}] \\to \\mathbf{Set}$ is logical, as is the functor which equips a set $A$ with trivial $G$-action.\\\\\n    Moreover, even if $G$ is infinite, $[G,\\mathbf{Set}_f]$ is a topos, and the inclusion $[G,\\mathbf{Set}_f] \\to [G,\\mathbf{Set}]$ is logical. Similarly, if $\\mathcal{G}$ is a large (contrast to small?) group, then $[\\mathcal{G},\\mathbf{Set}]$ is a topos.\n\n    (e) Let $\\mathcal{C}$ be a category such that every slice $\\mathcal{C}/A$ is equivalent to a finite category. Then $[\\mathcal{C}^{op},\\mathbf{Set}_f]$ is a topos just by checking definitions. Similarly, if $\\mathcal{C}$ is large, but all $\\mathcal{C}/A$ are small, then $[\\mathcal{C}^{op},\\mathbf{Set}]$ is a topos, then $[\\mathcal{C}^{op},\\mathbf{Set}]$ is a topos. In particular, $[\\mathbf{On}^{op},\\mathbf{Set}]$ is a topos which is not locally small.\n\\end{eg}\n\n---Lecture 22---\n\n\\begin{lemma} (7.3)\\\\\n    Suppose $\\mathcal{E}$ has finite limits and a subobject classifier. Then every monomorphism in $\\mathcal{E}$ is regular. In particular, $\\mathcal{E}$ is balanced.\n    \\begin{proof}\n        The universal monomorphism $1 \\stackrel{\\top}{\\rightarrowtail} \\Omega$ is split and hence regular (ES1 Q5). But any pullback of a regular monomorphism is regular: if $f$ is an equalizer of $(g,h)$ then $K^*(f)$ is an equalizer of $(gk,hk)$. The second assertion follows since regular epic monomorphism is an isomorphism.\n    \\end{proof}\n\\end{lemma}\n\nGiven an object $A$ in a topos $\\mathcal{E}$, we write $PA$ for the exponential $\\Omega^A$, and $\\ni_A \\rightarrowtail PA \\times A$ for the subobject corresponding to $PA \\times A \\xrightarrow{ev} \\Omega$. This has the property that, for any $B$ and any $R \\stackrel{m}{\\rightarrowtail} B \\times A$, there's a unique ${}^{\\lceil}m^\\rceil): B \\to PA$ s.t.\n\n\\begin{tikzcd}\n    R \\arrow[r] \\arrow[d,tail,\"m\"] & \\ni_A \\arrow[d,tail]\\\\\n    B \\times A \\arrow[r,\"{}^{\\lceil}m^\\rceil) \\times 1_A\"] & PA \\times A\n\\end{tikzcd}\n\nis a pullback.\n\n\\begin{defi} (7.4)\\\\\n    By a \\emph{power-object} for $A$ in a category $\\mathcal{E}$ with finite limits, we mean an object $PA$ equipped with $\\ni_A \\rightarrowtail PA \\times A$ satisfying the above.\\\\\n    We say $\\mathcal{E}$ is a \\emph{weak topos} if every $A \\in \\ob\\mathcal{E}$ has a power-object. Similarly, we say $F:\\mathcal{E} \\to \\mathcal{F}$ is \\emph{weakly logical} if $F(\\ni_A) \\rightarrowtail F(PA) \\times FA$ is a power-object for $FA$, for every $A \\in \\ob\\mathcal{E}$.\n\\end{defi}\n\n\\begin{lemma} (7.5)\\\\\n    $P$ is a functor $\\mathcal{E}^{op} \\to \\mathcal{E}$. Moreover, it is self-adjoint on the right.\n    \\begin{proof}\n        Given $A \\xrightarrow{f} B$, we define $PB \\xrightarrow{PF} PA$ to correspond to the pullback\n\n        \\begin{tikzcd}\n            E_f \\arrow[r] \\arrow[d,tail] & \\ni_B \\arrow[d,tail]\\\\\n            PB \\times A \\arrow[r,\"1\\times f\"] & PB \\times B\n        \\end{tikzcd}\n\n        For any morphism $C \\xrightarrow{{}^{\\lceil}m^\\rceil)} PB$, it's easy to see that $(Pf){}^{\\lceil}m^\\rceil)$ correspond to $(1_C \\times f)^*(m)$; hence $f \\to Pf$ is functorial. For any $A$ and $B$, we have a bijection between subobjects of $A \\times B$ and of $B \\times A$, given by composition with $(\\pi_2,\\pi_1): A \\times B \\to B \\times A$; this yields a (natural) bijection between morphisms $A \\to PB$ and $B \\to PA$.\n    \\end{proof}\n\\end{lemma}\n\nWe write $\\{\\}_A$ (pronounced as \\emph{singleton}) $:A \\to PA$ for the morphism correponding to $A \\stackrel{(1_A,1_A)}{\\rightarrowtail} A \\times A$.\n\n\\begin{lemma} (7.6)\\\\\n    Given $A \\xrightarrow{f} B$, $\\{\\}_B f$ corresponds to $A \\stackrel{(1_A,f)}{\\rightarrowtail} A \\times B$ and $(Pf) \\{\\}_B$ corresponds to $A \\stackrel{(f,1_A)}{\\rightarrowtail} B \\times A$.\n    \\begin{proof}\n        The square\n        \n        \\begin{tikzcd}\n            A \\arrow[r,\"f\"] \\arrow[d,tail,\"{(1,f)}\"] & B \\arrow[d,tail,\"{(1,1)}\"] \\\\\n            A \\times B \\arrow[r,\"f \\times 1\"] & B \\times B\n        \\end{tikzcd}\n\n        is a pullback. Similarly for the second assertion.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{coro} (7.7)\\\\\n    (i) $\\{\\} : A \\to PA$ is monic.\\\\\n    (ii) $P$ is faithful.\n    \\begin{proof}\n        (i) If $\\{\\} f = \\{\\} g$, then $(1_A,f)$ and $(1_A,g)$ are isomorphic as subobjects of $A \\times B$, which forces $f=g$.\\\\\n        (ii) Similarly, if $Pf = Pg$, then $(Pf)\\{\\} = (Pg)\\{\\}$, so we again deduce $f=g$.\n    \\end{proof}\n\\end{coro}\n\nGiven monomorphism $A \\stackrel{f}{\\rightarrowtail} B$ in $\\mathcal{E}$, we define $\\exists f:PA \\to PB$ to correspond to the composite $\\ni_A \\rightarrowtail PA \\times A \\stackrel{1\\times f}{\\rightarrowtail} PA \\times B$. Then, for any $C \\xrightarrow{{}^{\\lceil}m^\\rceil)} PA$, $(\\exists f) {}^{\\lceil}m^\\rceil)$ corresponds to $R \\stackrel{m}{\\rightarrowtail} C \\times A \\rightarrowtail{1 \\times f} C \\times B$.\\\\\nSo $f \\to \\exists f$ is a functor $Mono(\\mathcal{E}) \\to \\mathcal{E}$.\n\n\\begin{lemma} (7.8, Beck-Chevalley condition)\\\\\n    Suppose\n\n    \\begin{tikzcd}\n        D \\arrow[r,\"h\"] \\arrow[d,tail,\"k\"] & A \\arrow[d,tail,\"f\"]\\\\\n        B \\arrow[r,\"g\"] & C\n    \\end{tikzcd}\n\n    is a pullback with $f$ monic. Then the diagram \n\n    \\begin{tikzcd}\n        PA \\arrow[r,\"\\exists f\"] \\arrow[d,\"Ph\"] & PC \\arrow[d,\"Pg\"]\\\\\n        PD \\arrow[r,\"\\exists k\"] & PB\n    \\end{tikzcd}\n\n    commutes.\n    \\begin{proof}\n        Consider the diagram\n\n        \\begin{tikzcd}\n            E_h \\arrow[r] \\arrow[d,tail] & \\ni_A \\arrow[d,tail]\\\\\n            PA \\times D \\arrow[r,\"1 \\times h\"] \\arrow[d,\"1 \\times k\"] & PA \\times A \\arrow[d,\"1 \\times f\"]\\\\\n            PA \\times B \\arrow[r,\"1 \\times g\"] & PA \\times C\n        \\end{tikzcd}\n\n        The lower square is a pullback, so the upper square is a pullback iff the composite is a pullback.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{thm} (7.9, Par\\'e)\\\\\n    The functor $P:\\mathcal{E}^{op} \\to \\mathcal{E}$ is monadic.\n    \\begin{proof}\n        It has a left adjoint $P :\\mathcal{E} \\to \\mathcal{E}^{op}$ by (7.5). It's faithful by 7.7(ii), and hence reflects isomorphsms by (7.3). $\\mathcal{E}^{op}$ has coequalizers, since $\\mathcal{E}$ has equalizers. Suppose now that $A \\stackrel[\\stackrel{\\to}{g}]{\\xrightarrow{f}}{\\stackrel{r}{\\leftarrow}} B$ is a coreflexive pair in $\\mathcal{E}$; then $f$ and $g$ are (split) monic, and the equalizer $E \\xrightarrow{e} A$ makes\n\n        \\begin{tikzcd}\n            E \\arrow[r,\"e\"] \\arrow[d,\"e\"] & A \\arrow[d,\"g\"]\\\\\n            A \\arrow[r,\"f\"] & B\n        \\end{tikzcd}\n\n        a pullback square, since any cone over \n        \\begin{tikzcd}\n            & A \\arrow[d,\"g\"]\\\\\n            A \\arrow[r,\"f\"] & B\n        \\end{tikzcd}\n        has both legs equal.\\\\\n        So by (7.8) we have $(Pf)(\\exists g) =(\\exists e)(Pe)$; but we also have $(Pg)(\\exists g) = 1_{PA}$ since \n\n        \\begin{tikzcd}\n            A \\arrow[r,\"1\"] \\arrow[d,\"1\"] & A \\arrow[d,\"g\"]\\\\\n            A \\arrow[r,\"g\"] & B\n        \\end{tikzcd}\n\n        is a pullback, and similarly $(Pe)(\\exists e) = 1_{PE}$. So\n\n        \\begin{tikzcd}\n            PB \\arrow[r,shift left, \"Pf\"] \\arrow[r,shift right,\"Pg\"'] & PA \\arrow[r,\"Pe\"] \\arrow[l, bend left = 40, \"\\exists g\"] & PE \\arrow[l,bend left=20,\"\\exists e\"]\n        \\end{tikzcd}\n\n        is a split coequalizer, and in particular a coequalizer. Hence by (5.13) $P$ is monadic.\n    \\end{proof}\n\\end{thm}\n\n\\begin{coro} (7.10)\\\\\n    (i) A weak topos has finite colimits. Moreover, if it has any infinite limits, then it has the corresponding colimits.\\\\\n    (ii) If a weakly logical functor has a left adjoint, then it has a right adjoint.\n    \\begin{proof}\n        (i) $P$ creates all limits which exist, by (5.8).\\\\\n        (ii) By definition, if $F$ is weakly logical, then \n\n        \\begin{tikzcd}\n            \\mathcal{E}^{op} \\arrow[r,\"F\"] \\arrow[d,\"P\"] & \\mathcal{F}^{op} \\arrow[d,\"P\"]\\\\\n            \\mathcal{E} \\arrow[r,\"F\"] & \\mathcal{F}\n        \\end{tikzcd}\n\n        commutes up to isomorphism. So this follows from (5.16).\n    \\end{proof}\n\\end{coro}\n\n---Lecture 23---\n\n\\begin{lemma} (7.11)\\\\\n    Let $\\mathcal{E}$ be a category with finite limits, and suppose $A \\in \\ob\\mathcal{E}$ has a power-object $PA$. Then, for any $B$, $B^*(PA)$ is a power-object for $B^*A$ in $\\mathcal{E}/B$.\n    \\begin{proof}\n        Given \n        \\begin{tikzcd}\n            C \\arrow[d,\"g\"]\\\\\n            B\n        \\end{tikzcd}\n        , we have a pullback square\n\n        \\begin{tikzcd}\n            C \\times A \\arrow[r,\"g \\times 1\"] \\arrow[d,\"\\pi_1\"] & B \\times A \\arrow[d,\"\\pi_1\"]\\\\\n            C \\arrow[r,\"g\"] & B\n        \\end{tikzcd}\n\n        So $\\sum_B(g \\times B^* A) \\cong C \\times A$.\\\\\n        Hence $Sub_{\\mathcal{E}/B}(g \\times B^* A) \\cong Sub_{\\mathcal{E}}(C \\times A)$, but if $C \\xrightarrow{h} PA$ corresponds to \n        \\begin{tikzcd}\n            R \\arrow[d,tail]\\\\\n            C \\times A\n        \\end{tikzcd}\n        , then \n\n        \\begin{tikzcd}\n            R \\arrow[d,tail] \\arrow[rr] & & B \\times \\ni_A \\arrow[d,tail]\\\\\n            C \\times A \\arrow[rr,\"{(g,h) \\times 1_A}\"] \\arrow[rd,\"g\\pi_1\"'] & & B \\times PA \\times A \\arrow[ld,\"\\pi_1\"]\\\\\n            & B &\n        \\end{tikzcd}\n        \n        is a pullback. So \n        \\begin{tikzcd}\n            B \\times PA \\arrow[d,\"\\pi_1\"]\\\\\n            B\n        \\end{tikzcd}\n        equipped with $B^*(\\ni_A) \\rightarrowtail B^*(PA\\times A)$ is a power object for $B^* A$.\n    \\end{proof}\n\\end{lemma} \n\n\\begin{thm} (7.12)\\\\\n    Suppose $\\mathcal{E}$ is a weak topos. Then for any $B \\in \\ob\\mathcal{E}$, $\\mathcal{E}/B$ is a weak topos and $B^*:\\mathcal{E} \\to \\mathcal{E}/B$ is weakly logical.\n    \\begin{proof}\n        The second assertion follows from (7.11). For the first, we need to construct a power-object for an arbitrary \n        \\begin{tikzcd}\n            A \\arrow[d,\"f\"]\\\\\n            B\n        \\end{tikzcd}\n        in $\\mathcal{E}/B$. Then the pullback\n\n        \\begin{tikzcd}\n            \\sum_B(g \\times f) \\arrow[r] \\arrow[d] & A \\arrow[d,\"f\"]\\\\\n            C \\arrow[r,\"g\"] & B\n        \\end{tikzcd}\n\n        is a subobject of $C \\times A$, namely the equalizer of $C \\times A \\stackrel[g\\pi_1]{f\\pi_2}{\\rightrightarrows} B$.\\\\\n        DEfine $\\wedge: PA \\times PA \\to PA$ to correspond to the intersection of $\\pi_{13}^* (\\ni_A \\rightarrowtail PA \\times A)$ and $\\pi_{23}^*(\\ni_A \\rightarrowtail PA \\times A)$, and define $P_1A \\rightarrowtail PA \\times PA$ to be the equalizer of $PA \\times PA \\stackrel[\\pi_1]{\\wedge}{\\rightrightarrows} PA$.\\\\\n        Then, for any $C$, $C \\xrightarrow{({}^{\\lceil}m^\\rceil),{}^{\\lceil}n^\\rceil))} PA \\times PA$ factors through $P_1 A$ iff $m \\leq n$ in $Sub_{\\mathcal{E}}(C \\times A)$.\\\\\n        Now form the pullback\n\n        \\begin{tikzcd}\n            Q \\arrow[rr] \\arrow[d,tail,\"({h,k)}\"] & & P_1 A \\arrow[d,tail]\\\\\n            PA \\times B \\arrow[r,\"1 \\times \\{\\}\"] & PA \\times PB \\arrow[r,\"1 \\times Pf\"] & PA \\times PA\n        \\end{tikzcd}\n\n        Given any \n        \\begin{tikzcd}\n            C \\arrow[d,\"g\"]\\\\\n            B\n        \\end{tikzcd}\n        , the morphisms $g \\xrightarrow{l} k$ in $\\mathcal{E}/B$ correspond to morphisms $C \\xrightarrow{hl} PA$ s.t. the subobject named by $hl$ is contained in that named by $(Pf)(\\{\\}) g$. But the latter is indeed $\\sum_B(g \\times f) \\rightarrowtail C \\times A$.\\\\\n        So $k$ is a power-object for $f$ in $\\mathcal{E}/B$.\n    \\end{proof}\n\\end{thm}\n\n\\begin{coro} (7.13)\\\\\n    A weak topos is locally cartesian closed (in particular, it's a topos).\n    \\begin{proof}\n        For any $f:A \\times B$ in $\\mathcal{E}$, we can identify $(\\mathcal{E}/B) / f$ with $\\mathcal{E}/A$, and $f^*:\\mathcal{E}/B \\to \\mathcal{E}/A$ with pullback along $f$. Hence all such functors are weakly logical.\\\\\n        But $f^*$ has a left adjoint $\\sum_f$, so by 7.10(ii) it has a right adjoint $\\pi_f$. Hence by (6.3) $\\mathcal{E}/B$ is cartesian closed for any $B$.\n    \\end{proof}\n\\end{coro}\n\n\\begin{rem}\n    It can be shown that a weakly logical functor is cartesian closed (and hence logical).\n\\end{rem}\n\n\\begin{coro} (7.14)\\\\\n    (i) Any epimorphism in a topos is regular.\\\\\n    (ii) Any $A \\xrightarrow{f} B$ in a topos factors uniquely up to isomorphism as\n    \\begin{tikzcd}\n        A \\arrow[r,two heads,\"q\"] & I \\arrow[r,tail,\"m\"] & B\n    \\end{tikzcd}\n    \\begin{proof}\n        $\\mathcal{E}$ is locally cartesian closed by (7.13) and has coequalizers by 7.10(i), so by (6.7), every $f$ factors uniquely as regular epimorphism + monomorphism. If $f$ itself is epic, then the monic part of this factorization is so by (7.3), so $f$ is regular epic.\n    \\end{proof}\n\\end{coro}\n\n---end of examinable course material---\n\nRecall that $\\mathbf{Sh}(x) \\subseteq [\\mathcal{O}(X)^{op},\\mathbf{Set}]$ is a full subcategory closed under limits (pretty easy to verify); in fact it's reflective, and moreover, the reflector $L:[\\mathcal{O}(X)^{op},\\mathbf{Set}] \\to \\mathbf{Sh}(X)$ preserves finite limits.\\\\\nThis suggests considering reflective subcategories $\\mathcal{D} \\subseteq \\mathcal{E}$ for which the reflector preserves finite limits (equivalently, pullbacks).\n\n\\begin{lemma} (7.15)\\\\\n    Given such a reflective subcategory and a monomorphism $A'\\rightarrowtail A$ in $\\mathcal{E}$, define $c(A') \\rightarrowtail A$ by the pullback diagram\n\n    \\begin{tikzcd}\n        c(A') \\arrow[r] \\arrow[d,tail] & LA' \\arrow[d,tail]\\\\\n        A \\arrow[r,\"\\eta_A\"] & LA\n    \\end{tikzcd}\n\n    Then $A' \\rightarrow c(A')$ is a closure operation on $Sub_\\mathcal{E}(A)$, and commutes with pullback along a fixed morphism of $\\mathcal{E}$.\n    \\begin{proof}\n        Since\n\n        \\begin{tikzcd}\n            A' \\arrow[r,\"\\eta_{A'}\"] \\arrow[d,tail] & LA' \\arrow[d,tail]\\\\\n            A \\arrow[r,\"\\eta_A\"] & LA\n        \\end{tikzcd}\n\n        commutes, we have $A' \\leq c(A')$, and $A' \\leq A''$ in $Sub(A)$ implies $LA' \\leq LA''$ in $Sub(LA)$, and hence $c(A') \\leq c(A'')$.\\\\\n        Since $L\\eta$ is an isomorphism,\n\n        \\begin{tikzcd}\n            LA' \\arrow[r,\"L\\eta_{A'}\"] \\arrow[d,tail] & LLA' \\arrow[d,tail]\\\\\n            LA \\arrow[r,\"L\\eta_A\"] & LLA\n        \\end{tikzcd}\n\n        is a pullback, and since $L$ preserves pullbacks, we deduce $Lc(A') \\cong LA'$ is $Sub(LA)$.\\\\\n        Hence $c(c(A')) \\cong c(A')$.\\\\\n        For stability under pullback, suppose\n\n        \\begin{tikzcd}\n            A' \\arrow[r] \\arrow[d,tail] & B' \\arrow[d,tail]\\\\\n            A \\arrow[r,\"f\"] & B\n        \\end{tikzcd}\n\n        is a pullback. Then in the cube (!!??)\n\n        \\begin{tikzcd}\n            c(A') \\arrow[rr] \\arrow[dd] \\arrow[rd] & & LA'\\arrow[dd] \\arrow[rd]\\\\\n            & c(B') \\arrow[rr, crossing over] \\arrow[dd, crossing over] & & LB' \\arrow[dd]\\\\\n            A \\arrow[rr,\"\\eta_A\"] \\arrow[rd,\"f\"'] & & LA \\arrow[rd,\"Lf\"]\\\\\n            & B \\arrow[rr,\"\\eta_B\"] & & LB\n        \\end{tikzcd}\n\n        the front, back and right faces are pullbacks; whence the left face is too.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{defi} (7.16)\\\\\n    Let $\\mathcal{E}$ be a topos. By a local operator on $\\mathcal{E}$, we mean a morphism $j:\\Omega \\to \\Omega$ satisfying the commutative diagrams\n\n    \\begin{tikzcd}\n        1 \\arrow[r,\"T\"] \\arrow[rd,\"T\"'] & \\Omega \\arrow[d,\"j\"] & \\Omega \\arrow[l,\"j\"'] \\arrow[ld,\"j\"]\\\\\n        & \\Omega &\n    \\end{tikzcd}\n    and \n    \\begin{tikzcd}\n        \\Omega_1 \\arrow[r] \\arrow[d,tail] & \\Omega_1 \\arrow[d,tail]\\\\\n        \\Omega \\times \\Omega \\arrow[r,\"j \\times j\"] & \\Omega \\times \\Omega\n    \\end{tikzcd}\n\n    where $\\Omega_1$ is the order-relation on $\\Omega$, defined as in (7.12).\n\\end{defi}\n\nGiven a closure opeartor on subobjects as in (7.15), define $J \\rightarrowtail \\Omega$ to be the closure of $1 \\stackrel{T}{\\rightarrowtail} \\Omega$, and $j:\\Omega \\to \\Omega$ to be the classifying map of $J \\rightarrowtail \\Omega$.\\\\\nThen, for any $A' \\rightarrowtail A$ with classifying map $\\chi_m: A \\to \\Omega$, the composite $j\\chi_m$ classifies $c(A') \\rightarrowtail A$.\n\n---Lecture 24---\n\nGiven a pullback-stable closure operator $c$ on subobjects, we say $A' \\rightarrowtail A$ is \\emph{dense} if $c(A') \\rightarrowtail A$ is an isomorphism, and \\emph{closed} if $A' \\rightarrowtail c(A')$ is an isomorphism.\n\n\\begin{lemma} (7.17)\\\\\n    Suppose given a commutative square\n\n    \\begin{tikzcd}\n        B' \\arrow[r,\"f'\"] \\arrow[d,tail,\"n\"] & A' \\arrow[d,tail,\"m\"]\\\\\n        B \\arrow[r,\"f\"] & A\n    \\end{tikzcd}\n    \n    with $n$ dense and $m$ closed. Then there's a unique $B \\xrightarrow{g} A'$ with $mg = f$ (and $gn = f'$).\n    \\begin{proof}\n        We have $n \\leq f^*(m)$ in $Sub(B)$, so $1_B \\cong c(n) \\leq f^*(c(m)) \\cong f^*(m)$. So we define $g$ as $B \\stackrel{\\cong}{\\rightarrow} f^*(A') \\to A'$.\n    \\end{proof}\n\\end{lemma}\n\nNote that $c(A')$ may be characterized as the unique (up to isomorphism) subobject $A''$ s.t. $A' \\rightarrowtail A''$ is dense and $A'' \\rightarrowtail A$ is closed.\n\n\\begin{lemma} (7.18)\\\\\n    Suppose $c$ is induced as in (7.15) by a reflector $L:\\mathcal{E} \\to \\mathcal{D}$ preserving finite limits. Then an object $A$ of $\\mathcal{E}$ belongs to $\\mathcal{D}$ (up to isomorphism) iff, given any diagram\n\n    \\begin{tikzcd}\n        B' \\arrow[r,\"f'\"] \\arrow[d,tail,\"m\"] & A\\\\\n        B &\n    \\end{tikzcd}\n\n    with $m$ dense, there exists a unique $B \\xrightarrow{f} A$ with $fm = f'$.\n    \\begin{proof}\n        Note first that $m$ is dense $\\iff$ $Lm$ is an isomorphism. $\\Leftarrow$ follows from the definition; $\\Rightarrow$ follows since by the proof of (7.15), we know $L(B')$ and $L(c(B'))$ are isomorphic in $Sub(B)$.\\\\\n        Given this, if $A$ is in $\\mathcal{D}$, then the given diagram extends uniquely to\n\n        \\begin{tikzcd}\n            B' \\arrow[r,\"\\eta_{B'}\"] \\arrow[d,tail] & LB' \\arrow[r] \\arrow[d,\"\\cong\"] & A\\\\\n            B \\arrow[r,\"\\eta_B\"] & LB \\arrow[ur] &\n        \\end{tikzcd}\n\n        Conversely, suppose $A$ satisfies the condition. Let $R \\stackrel[b]{a}{\\rightrightarrows} A$ be the kernel-pair of $A \\xrightarrow{\\eta_A} LA$, and $d:\\rightarrowtail R$ the factorization of $(1_A,1_A)$ through $(a,b)$. Since $L\\eta_A$ is an isomorphism and $L$ preserves pullbacks, $Ld$ is an isomorphism, so $d$ is dense.\\\\\n        This forces $a=b$, so $\\eta_A$ is monic. And $\\eta_A$ is dense, so we get a unique $r:LA \\to A$ with $r \\eta_A = 1_A$. Now $\\eta_A r \\eta_A = \\eta_A$, and since $LA$ satisfies the condition we have $\\eta_A r = 1_{LA}$.\n    \\end{proof}\n\\end{lemma}\n\nWe say $A$ is a \\emph{sheaf} (for $c$, or for $j$) if it satisfies the condition in (7.18). Given a local operator $j$ on $\\mathcal{E}$, we write $sh_j(\\mathcal{E})$ for the full subcategory of $j$-sheaves in $\\mathcal{E}$.\n\n\\begin{lemma} (7.19)\\\\\n    $sh_j(\\mathcal{E})$ is closed under limits in $\\mathcal{E}$, and an exponential ideal.\n    \\begin{proof}\n        The first assertion follows since the definition involves only morphisms with codomain $A$.\\\\\n        For the second, note that if $B' \\stackrel{m}{\\rightarrowtail} B$ is dense, then so is $B'\\times C \\stackrel{m \\times 1}{\\rightarrowtail} B \\times C$ for any $C$ (since it's $\\pi_1^*(m)$), and so if $A$ is a sheaf then any morphism $B' \\to A^C$ extends uniquely to a morphism $B \\to A^C$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (7.20)\\\\\n    If $A$ is a sheaf, then a subobject $A' \\stackrel{m}{\\rightarrowtail} A$ in $\\mathcal{E}$ is a sheaf iff it's closed.\n    \\begin{proof}\n        $\\Leftarrow$ is immediate from (7.17).\\\\\n        $\\Rightarrow$: Consider $A \\stackrel{p}{\\rightarrowtail} c(A') \\stackrel{q}{\\rightarrowtail} A$. $p$ is dense, so if $A$ is a sheaf we get unique $r:c(A') \\to A'$ with $rp = 1_{A'}$. But $c(A')$ is a sheaf, so $prp = p$. We deduce $pr = 1_{c(A')}$ since $p$ is a monomorphism.\n    \\end{proof}\n\\end{lemma}\n\nWe define $\\Omega_j \\rightarrowtail \\Omega$ to be the equalizer of $\\Omega \\stackrel[1_\\Omega]{j} \\Omega$. Then, for any $A$, morphsims $A \\to \\Omega_j$ corresponds to closed subobjects of $A$.\n\n\\begin{lemma} (7.21)\\\\\n    $\\Omega_j$ is a $j$-sheaf.\n    \\begin{proof}\n        We have to show that if $B \\stackrel{m}{\\rightarrowtail} A$ is a dense monomorphism, then pullback along $m$ yields a bijection from closed subobjects of $A$ to closed subobjects of $B$.\\\\\n        If $A' \\stackrel{n}{\\rightarrowtail} A$ is closed, then in the pullback\n\n        \\begin{tikzcd}\n            B' \\arrow[r,tail,\"m'\"] \\arrow[d,tail,\"n'\"] & A' \\arrow[d,tail,\"n\"]\\\\\n            B \\arrow[r,tail,\"m\"] & A\n        \\end{tikzcd}\n\n        $m'$i s dense, so $A' \\rightarrowtail A$ is the closure of $B' \\rightarrowtail B \\rightarrowtail A$. It remains to show that if $B' \\rightarrowtail B$ is closed, it is isomorphic to the pullback of its closure in $A$.\\\\\n        But (writing $A' \\rightarrowtail A$ for the closure), we have a factorization $B' \\to f^* A'$ which is dense since $B' \\to A'$ is dense, and closed since $B' \\to B$ is closed.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{thm} (7.22)\\\\\n    For any local operator $j$ on $\\mathcal{E}$, $sh_j(\\mathcal{E})$ is a topos.\\\\\n    Moreover, it's reflective in $\\mathcal{E}$ and the reflector preserves finite limits.\n    \\begin{proof}\n        $sh_j(\\mathcal{E})$ is cartesian closed by (7.19), and has a subobject classifier $\\Omega_j$ by (7.20) and (7.21). To construct the reflector, consider the composite\n        \\begin{tikzcd}\n            A \\arrow[r,tail,\"\\{\\}\"] & \\Omega^A \\arrow[r,\"j^A\"] & \\Omega_j^A\n        \\end{tikzcd}\n        , this corresponds to the closure $\\bar{A} \\rightarrowtail A \\times A$ of the diagonal subobject $A \\stackrel{(1_A,1_A)}{\\rightarrowtail} A \\times A$. I claim that $\\bar{A} \\stackrel[b]{a}{\\rightrightarrows} A$ is the kernel-pair of $f$. Hence any morphism $g:A \\to B$ where $B$ is a sheaf satisfies $ga = gb$.\\\\\n        So if we torm(?) the image \n        \\begin{tikzcd}\n            A \\arrow[r,two heads,\"q\"] & I \\arrow[r,tail,\"m\"] & \\Omega_j^A\n        \\end{tikzcd}\n        of $f$, any such $g$ factors uniquely through $q$.\\\\\n        Now $\\Omega_j^A$ is a sheaf by (7.19) and (7.21), so if we form the closure $LA \\rightarrowtail \\Omega_j^A$ of $m$, we get a morphism $A \\to LA$ through which any morphism from $A$ to a sheaf factors uniquely. Hence $L$ becomes a functor $\\mathcal{E} \\to sh_j(\\mathcal{E})$, left adjoint ot the inclusion.\\\\\n        By (6.13), we know $L$ preserves finite products.\\\\\n        In fact it preserves equalizers as well (the proof is quite elementary, but we have no time for it).\n    \\end{proof}\n\\end{thm}\n\nThere's a last thing I want to do, but I'll just state it since there's no time to prove it:\n\\begin{thm} (7.23)\\\\\n    For a category $\\mathcal{E}$, the following are equivalent:\\\\\n    (i) $\\mathcal{E}$ is a topos, complete and locally small, and has a separating set of objects;\\\\\n    (ii) There exists a small category $\\mathcal{C}$ and a local operator on $[\\mathcal{C}^{op},\\mathbf{Set}]$ s.t $\\mathcal{E} \\cong sh_j([\\mathcal{C}^{op},\\mathbf{Set}])$.\n    \\begin{proof}\n        (ii) $\\implies$ (i): since $sh_j([\\mathcal{C}^{op},\\mathbf{Set}])$ has given properties.\\\\\n        (i) $\\implies$ (ii): take $\\mathcal{C}$ to be the full subcategory of $\\mathcal{E}$ on the separating set and consider\n        \\begin{tikzcd}\n            \\mathcal{C} \\arrow[r,\"Y\"] & \\left[\\mathcal{E}^{op},\\mathbf{Set}\\right] \\arrow[r] & \\left[\\mathcal{C}^{op},\\mathbf{Set}\\right]\n        \\end{tikzcd}\n    \\end{proof}\n\\end{thm}\n\n\\newpage\n\n\\section{Example Class 1}\nMany people wrote too much for questions. Do have the confidence to use the duality principle when it's usable!\n\n\\subsection{Question 1}\nWe need to verify\n\\begin{equation*}\n    \\begin{aligned}1q\n        ((AB)C)_{il} &= \\vee_k ((\\vee_j (a_{ij} \\wedge b_{jk} )) \\wedge c_{kl})\\\\\n        &= \\vee_k \\vee_j (a_{ij} \\wedge b_{jk} \\wedge c_{kl})\\\\\n        &= (A(BC))_{il} \\text{ by symmetry}\n    \\end{aligned}\n\\end{equation*}\nand of course identity matrices are identities.\n\nDefine a functor $F:\\mathbf{Mat}_L \\to \\mathbf{Rel}_f$ by $F(n) = \\{1,2,...,n\\}$; if $A: n \\to p$ is a $p \\times n$ matrix in $\\mathbf{Mat}_L$, then $FA = \\{(i,j) | a_{ji} = 1\\}$.\\\\\nImportant: we have to verify this is functorial, which many people didn't bother to do. Why is it functorial? Well again we just have to verify explicitly that\n\\begin{equation*}\n    \\begin{aligned}\n        (AB)_{ik} = 1 \\iff (\\exists j) (a_{ij} = b_{jk} = 1)\n    \\end{aligned}\n\\end{equation*}\nso $F(AB) = FA \\circ FB$. This does require verifications, because you are multiplying the matrices over lattices; for example say if you are doing it for the finite field with 2 elements then it won't work.\\\\\nNow note that to prove they are equivalent we don't really need to find both the two functors and natural transformations; instead we can use a theorem in chapter 1, that $F$ is part of an equivalence if it is full, faithful and essentially surjective. So we just have to verify that $F$ is f,f,and es. Indeed it is, since any finite set is isomorphic to $F(n)$ for some $n$. So by (1.12), $\\mathbf{Mat}_L \\simeq \\mathbf{Rel}_f$.\n\n\\subsection{Question 2}\nPart (i) was easy, but many people had problems on part (ii).\\\\\n(i) Given $(A_i | i \\in I)$, define $\\mathcal{C}$ by $\\ob \\mathcal{C} =\\{(i,a)| i \\in I, a \\in A_i\\}$, and $\\mathcal{C}((i,a)(j,b)) = \\phi$ if $i \\neq j$, and is $\\{*\\}$ if $i=j$.\\\\\n$\\mathcal{C}$ is a groupoid; its isomorphic classes of objects are of the form $\\{i\\} \\times A,i \\in I$. If we've got a skeleton then we can pick out one from each of these, which is equivalent to AC.\\\\\n(ii) Now take $\\ob\\mathcal{C} =I\\times \\{0,1\\}$, and morphisms $(i,m) \\to (i,n)$ are formal finite sums as given in the hint, and of course composition is just addition. Again this is a groupoid because every morphism can be inverted by just reverting the sign of every coefficient. So $\\mathcal{C}$ has isomorphic classes $\\{i\\} \\times \\{0,1\\}, i \\in I$. So this has a skeleton, say we take $\\mathcal{C}_0$ to be the full subcategory on objects $I\\times\\{0\\}$.\\\\\nBut then by assumption we have an equivalence $\\mathcal{C}_0 \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{C}$, then $FG(i,0) = FG(i,1)$ for all $i$. So if we have a natural transfomation $\\beta:FG \\to 1_{\\mathcal{C}}$ which is also an isomorphism, then either $\\beta_{(i,0)}$ or $\\beta_{(i,1)}$ is a non-zero formal finite sum. So we just put $A_i = \\{x \\in A_i | x$ occurs in either $\\beta_{(i,0)}$ or $\\beta_{(i,1)}$ with non-zero coefficient$\\}$.\n\n\\subsection{Question 3}\n(i) Quite a lot of people forgot to verify that it is actually a subgroup! Suppose given automorphisms $F,G,H$ with isomorphisms $\\alpha:F \\to 1_{\\mathcal{C}},\\beta:G \\to 1_{\\mathcal{C}}$. Then $(F^{-1} \\alpha)^{-1} : F^{-1} \\to F^{-1}F = 1_{\\mathcal{C}}$ is an isomorphism, so $F^{-1}$ is inner. Now $FG\\xrightarrow{F\\beta} F \\xrightarrow{\\alpha} 1_\\mathcal{C}$ is isomorphism, so $FG$ is inner.\\\\\nNow we have to verify normality: $HFH^{-1} \\xrightarrow{H \\alpha_{H^{-1}}} HH^{-1} = 1_{\\mathcal{C}}$ is iso, so $HFH^{-1}$ is inner.\\\\\nYou don't have to spend a lot of time to verify that all these are nat transforms (ok).\\\\\n(ii) Note that an isomorphism is in particular an equivalence. Now if $F$ is an automorphism, it is full and faithful, so for any $A$, morphism $A \\to F1$ are in bijection with morphisms $F^{-1} A \\to 1$, so there's just one of them.\\\\\nHence if $F$ is an isomorphism of $\\mathbf{Set}$, $F(1) = 1$, and hence there's a unique $\\alpha: \\mathbf{Set} (1,-) \\to F$ (this is just Yoneda).\\\\\nWe need to show $\\alpha$ is iso: but for any $A$, and any $1 \\xrightarrow{x} A$, \n\\begin{tikzcd}\n    1 \\arrow[r,\"\\alpha_1\"] \\arrow[d,\"x\"] & F1 \\arrow[d,\"Fx\"]\\\\\n    A \\arrow[r,\"\\alpha_A\"] & FA\n\\end{tikzcd}\ncommutes, but $F$ is full and faithful, so $\\alpha_A$ is bijective. Hence by (1.8), $\\alpha$ is an isomorphism.\\\\\n(iii) Note that if $X$ has $\\geq 3$ points, then it has $\\geq 4$ continuous endo maps (constants and identity). If $X$ has $\\leq 1$ point, then its only endo is $1_X$. So the only possibility is $X$ having 2 points. Say $X = \\{0,1\\}$ wit discrete or indiscrete topology, all 4 maps $X \\to X$ are continuous. So the only possible topology is the Sierpinski space given in the question (or the other way), which there are 3 continuous maps $X \\to X$.\\\\\nHence if $F$ is an autom of $\\mathcal{C} \\subseteq \\mathbf{Top}$, we must have $FS \\cong S$.\\\\\nWe also have $F1 \\cong 1$, and $U:\\mathcal{C} \\to \\mathbf{Set}$ is iso to $\\mathcal{C} (1,-)$. So there's a unique nat $\\alpha: U \\to UF$, and $\\alpha_X$ is bijective for all $X$, as before. Now we don't know if $\\alpha_X$ is continuous or not for a given $X$. So we consider naturality squares\n\\begin{tikzcd}\n    UX \\arrow[r,\"\\alpha_X\"] \\arrow[d,\"Uf\"] & UFX \\arrow[d,\"UFf\"]\\\\\n    US \\arrow[r,\"\\alpha_S\"] & UFS\n\\end{tikzcd}\n. If $\\alpha_S$ is discontinuous, then for any $X$, $\\alpha_X$ maps open subsets of $X$ bijecively to closed subsets of $FX$, but this is impossible if not every intersection of open sets in $X$ is open.\\\\\nSo then $\\alpha_S$ is a homeomorphism, and $\\alpha_X$ is a homeomorphism for all $X$.\\\\\n(iv) This basically says that if we restrict to finite topological spaces, then we do have the other case in the above happening. Let $F:\\mathbf{Top}_f \\to\\mathbf{Top}_f$ sending $X$ to the same set with closed sets as new opens.\\\\\nThen $FF = 1_{\\mathbf{Top}_f}$, so $F$ is an automorphism, and it is not isomorphic to the identity as there exists finite spaces $X$ with $X \\not\\cong FX$ (we could find one with 3 points -- lecturer didn't give the explicit example). So $F$ is not inner.\\\\\nNow if $G$ is any non-inner autom, then $GF$ is inner(?????); so $|\\Aut(\\mathbf{Top}_f):Inn(Top_f)| = 2$.\n\n\\subsection{Question 4}\n(i) Suppose we are given \n\\begin{tikzcd}\n    C \\arrow[r,\"h\"] \\arrow[d,\"g\", two heads] & A \\arrow[d,tail,\"f\"]\\\\\n    D \\arrow[r,\"k\"] & B \\arrow[d,\"p\"',shift right] \\arrow[d,\"q\", shift left]\\\\\n    & E\n\\end{tikzcd}\nwhere $f$ is an equalizer of $(p,q)$.\\\\\nThen $pfh = pkg = qkg = qfh$, and $g$ is epic, so $pk = qk$, so exists unique $t$ with $ft=k$. Then $ftg = kg = fh$, and $f$ is monic, so $tg = h$.\\\\\n(ii) \n\\begin{tikzcd}\n    A \\arrow[dr,\"k\"] \\arrow[r,\"f\"] & B \\arrow[d,\"g\"',shift right] \\arrow[d,\"h\", shift left] & D \\arrow[l,\"l\"] \\arrow[dl,\"m\"]\\\\\n    & C &\n\\end{tikzcd}\nNote that $f$ isn't regular monic. Why not? Because it is not iso and not an equalizer of $(g,h)$, since $l$ doesn't factor through it. It is trivially monic and strong monic: the only squares with $f$ on RHS is to put the identity before $f$, but it's trivial to verify those cases.\\\\\nIn some sense we can see that this is a minimal counter-example to the statement (think a bit, there's not anything better you can do).\\\\\n(iii) This actually has nothing to do with the previous two parts. We have \n\\begin{tikzcd}\n    A \\arrow[r,\"f\"] \\arrow[rd,\"k\"] & B \\arrow[d,\"g\"',shift right] \\arrow[d,\"h\",shift left]\\\\\n    & C\n\\end{tikzcd}\nWe want a commutative square\n\\begin{tikzcd}\n    \\cdot \\arrow[r] \\arrow[d] & \\cdot \\arrow[d]\\\\\n    \\cdot \\arrow[r] & \\cdot\n\\end{tikzcd}\nwith one vertical edge $f$ and the other one not. There are still a lot of possibilities, but almost any of it work. Say we pick\n\\begin{tikzcd}\n    \\cdot \\arrow[r,\"f\"] \\arrow[d,\"f\"] & \\cdot \\arrow[d,\"g\"]\\\\\n    \\cdot \\arrow[r,\"h\"] & \\cdot\n\\end{tikzcd}\nTry $f,f,g,h$: the only possible composites are with \n\\begin{tikzcd}\n    \\cdot \\arrow[r,\"h\"] \\arrow[d,\"1_B\"] & \\cdot \\arrow[d,\"1_C\"]\\\\\n    \\cdot \\arrow[r,\"h\"] & \\cdot\n\\end{tikzcd}\nor \n\\begin{tikzcd}\n    \\cdot \\arrow[r,\"h\"] \\arrow[d,\"h\"] & \\cdot \\arrow[d,\"1_C\"]\\\\\n    \\cdot \\arrow[r,\"1_C\"] & \\cdot\n\\end{tikzcd}\nSo $(f,g)$ is vacuously epic.\n\n\\subsection{Question 5}\nThis question has a lots of boring parts so lecturer is not going to write out all of it. The only a little bit tricky part is the strong part of (ii). We'll do that: suppose $gf$ is strong monic, and suppose we are given\n\\begin{tikzcd}\n    \\cdot \\arrow[r,\"l\"] \\arrow[d,\"h\", two heads] & \\cdot \\arrow[d,\"f\"]\\\\\n    \\cdot \\arrow[r,\"k\"] & \\cdot \\arrow[d,\"g\"]\\\\\n    & \\cdot\n\\end{tikzcd}\n. Then\n\\begin{tikzcd}\n    \\cdot \\arrow[r,\"l\"] \\arrow[d, \"k\", two heads] & \\cdot \\arrow[d,\"gf\", tail]\\\\\n    \\cdot \\arrow[ru,\"t\", dashed] \\arrow[r,\"gk\"] & \\cdot\n\\end{tikzcd}\ncommutes. A lot of people used $g$ is monic, but we weren't given it here(oops)! Here $\\exists t$ with $th = l$ (and $gft = gk$). Then $fth = fl = kh$ and $h$ is epic, so $ft = k$.\\\\\nSuppose $gf$ is regular monic, say it's the equalizer of $\\cdot \\stackrel[l]{k}{\\rightrightarrows} \\cdot$. To show that $f$ is an equalizer of $(kg,fg)$, suppose we are given \n\\begin{tikzcd}\n    \\cdot \\arrow[r,\"m\"] & \\cdot\n\\end{tikzcd}\nwith $kgm = lgm$. Then $\\exists ! n$ with $gm = gfn$. But now $g$ is monic. So $m = fn$.\\\\\n(iv) This part is also fairly problematic. The first thing we need to work out is what equalizers look like in this category. Given $A \\stackrel[g]{f}{\\rightrightarrows} B$ in $\\mathcal{C}$, their equalizer in $\\mathbf{AbGp}$ is the subgroup of $\\{a \\in A | f(a) = g(a)\\}$, and this belongs to $\\mathcal{C}$. Since $\\mathcal{C}$ is full, it's also an equalizer in $\\mathcal{C}$. Now $\\mathbf{Z} \\xrightarrow{\\times 2} \\Z$ is an equalizer of $\\Z \\stackrel[0]{q}{\\rightrightarrows} \\Z/2\\Z$, so it's regular monic in $\\mathcal{C}$. But if $\\Z \\xrightarrow{\\times 4} \\Z$ were an equalizer of $\\Z \\stackrel[g]{f}{\\rightrightarrows} A$, then $f(1) - g(1)$ must have order $4$ in $A$, so $A \\not\\in \\ob\\mathcal{C}$.\\\\\nThe last part of this is to find a counter-example to a previos part. We consider $\\Z \\xrightarrow{f} \\Z \\oplus \\Z/2\\Z \\xrightarrow{g} \\Z$, where $f(n) = (2n,[n])$, $g(p,q) = p$.\\\\\nNote that $gf$ is regular monic, but $f$ isn't, as $(1,[1])$ has order $4$ modulo $Im(f)$.\n\n\\subsection{Question 6}\n(i) Suppose $e = fg$, $gf$ an identity. We claim that $e$ is an equalizer of $e$ and $1_{\\dom e}$: we have $ef = fgf = f$, so $f$ has equal composites with $e$ and $1_{\\dom e}$; now if $h$ satisfies $eh = h$, then $h = fgh$, so it factorizes through $h$; moreover this factorization is unique, as $f$ is a split monomorphism.\\\\\nConversely, if $f$ is an equalizer of $(e,1_{\\dom e})$, then of course $e$ must factor trough it since $ee = e$. Say $e=fg$. Now $fgf = ef = f$, and $f$ is monic, so $gf = 1_{\\dom f}$.\\\\\n(ii) $\\mathcal{E} \\subseteq Idem \\mathcal{C}$, morphisms $e \\to d$ are morphisms $\\dom_e \\xrightarrow{f} \\dom d$ in $\\mathcal{C}$ with $dfe = f$. Note that this is equivalent to the two separate equations: one way is clear, now $df=d(dfe) = dfe = f$ (remember $d$ is idempotent!!!). Similarly $fe = f$.\\\\\nComposition in $\\mathcal{C}[\\check{\\mathcal{E}}]$ is composition in $\\mathcal{C}$: if $e \\xrightarrow{f} d \\xrightarrow{g} c$, then $cgf = gf = gfe$, so $gf : e \\to c$. The identity on $e$ is $e \\xrightarrow{e} e$.\\\\\n(iii) We define $I:\\mathcal{C} \\to \\mathcal{C} [\\check{\\mathcal{E}}]$ by $IA = 1_A$, $If = f$ (check this works). $I$ is f and f since all morphisms $A \\to B$ in $\\mathcal{C}$ are morphisms $1_A \\to 1_B$ in $\\mathcal{C} [\\check{\\mathcal{E}}]$.\\\\\nFor every $A \\xrightarrow{e} A$ in $\\mathcal{E}$, $Ie$ splits as $1_A \\xrightarrow{e} e \\xrightarrow{e} 1_A$.\\\\\nSo if $T = \\hat{T}I$, $T$ must send idempotents in $\\mathcal{E}$ to split idempotents.\\\\\nNow we have to show the converse, where we do have to use choice here. Suppose $Te$ is split for every $A \\xrightarrow{e} A$ in $\\mathcal{E}$. Choose a splitting $TA \\xrightarrow{g_e} \\hat{T}e \\xrightarrow{f_e} TA$ of it, and define $\\hat{T}: \\mathcal{C} [\\check{\\mathcal{E}}] \\to \\mathcal{D}$ on morphisms by $\\hat{T} (e \\xrightarrow{h} d) = \\hat{T} e \\xrightarrow{f_e}TA \\xrightarrow{Th} TB \\xrightarrow{g_d} \\hat{T}d$ (verify that this is functorial): provided we split $T(1_A)$ as $TA \\xrightarrow{1_{TA}} TA \\xrightarrow{1_{TA}} TA$, we have $\\hat{T} I = T$.\\\\\n(iv) Now suppose $\\mathcal{E} = \\{$all idempotents of $\\mathcal{C}\\}$. If $e \\xrightarrow{d} e$ is idempotent in $\\mathcal{C} [\\check{\\mathcal{E}}]$, then $dd = d$ in $\\mathcal{C}$, so $d \\in \\mathcal{E}$, and $e \\xrightarrow{d} e$ splits as $e \\xrightarrow{d} d \\xrightarrow{d} e$.\\\\\n(v) If $\\mathcal{D}$ is Cauchy-complete, consider the functor $[\\hat{\\mathcal{C}},\\mathcal{D}] \\xrightarrow{\\Phi} [\\mathcal{C},\\mathcal{D}]$ sending $\\hat{T}$ to $\\hat{T}I$ and $\\alpha \\to \\alpha_I$. $\\Phi$ is surjective on objects by (iii); so we need to show, given $S,T : \\hat{\\mathcal{C}} \\rightrightarrows \\mathcal{D}$, any nat trans $\\alpha:SI \\to TI$ extends uniquely to a nat trans $S \\to T$. Given $A \\xrightarrow{e} A$ in $\\mathcal{E}$, we have a morphism $Se \\xrightarrow{S(e \\xrightarrow{e} 1_A)} SA \\xrightarrow{\\alpha_A} TA \\xrightarrow{T(1_A \\xrightarrow{e} e)} Te$ which we take to be $\\alpha_e$.\\\\\nThis is the only possibility that makes the naturality squares for both $e \\xrightarrow{e} 1_A$ and $1_A \\xrightarrow{e} e$ commute:\n\\begin{tikzcd}\n    Se \\arrow[r,\"S(e\\xrightarrow{e} 1)\"] \\arrow[d,\"\\alpha_e\"] & SA \\arrow[d,\"\\alpha_A\"]\\\\\n    Te \\arrow[r,\"T(e\\xrightarrow{e} 1)\"] & TA\n\\end{tikzcd}\ncommutes since $\\alpha_A$ is natural w.r.t. $1_A \\xrightarrow{e} 1_A$. So this is the only possible way to extend it to a nat trans, and we of course have to verify naturality w.r.t. any $e \\xrightarrow{f} d$ in $\\mathcal{C}[\\check{\\mathcal{E}}]$.\\\\\nSo $\\Phi$ is part of an equivalence by (1.12).\n\n\\subsection{Question 7}\nFor any $F: \\mathcal{C} \\to \\mathbf{Set}$, $\\coprod_{(A,x), A \\in \\ob\\mathcal{C},x \\in FA} \\mathcal{C}(A,-) \\to F$ is pointwise surjective, so $F$ irreducible implies that there exists $\\mathcal{C}(A,-) \\twoheadrightarrow F$.\\\\\nConversely, given $\\mathcal{C}(A,-) \\stackrel{\\alpha}{\\twoheadrightarrow} F$ and an epi $\\coprod_{i \\in I} G_i \\stackrel{f}{\\twoheadrightarrow} F$, we have \n\\begin{tikzcd}\n    & \\mathcal{C}(A,-) \\arrow[dl,dashed, \"\\gamma\"] \\arrow[d,two heads, \"\\alpha\"]\\\\\n    \\coprod_{i \\in I} G_i \\arrow[r,two heads,\"\\beta\"] & F\n\\end{tikzcd}\n$\\gamma$ corresponds to an element of $\\coprod_{i \\in I} G_i A$, which lives in $G,A$ for some $i$. Then \n\\begin{tikzcd}\n    & \\mathcal{C}(A,-) \\arrow[dl,\"\\gamma\"] \\arrow[d,two heads, \"\\alpha\"]\\\\\n    G_i \\arrow[r,\"\\beta_i\"] & F\n\\end{tikzcd}\nforces $\\beta_i$ to be epic.\\\\\n(ii) If $F$ is irreducible and projective, then we get\n\\begin{tikzcd}\n    & F \\arrow[dl,\"f\"] \\arrow[d,\"1\"]\\\\\n    \\mathcal{C}(A,-) \\arrow[r,two heads, \"\\alpha\"] & F\n\\end{tikzcd}\n, so $\\alpha$ is split epic.\\\\\nConversely, if\n\\begin{tikzcd}\n    \\mathcal{C}(A,-) \\arrow[r,two heads,shift right, \"\\alpha\"'] & F \\arrow[l,tail,shift right,\"\\beta\"']\n\\end{tikzcd}\nis split epic, then given\n\\begin{tikzcd}\n    & F \\arrow[d,\"f\"]\\\\\n    & \\mathcal{C}(A,-) \\arrow[ddl, dashed] \\arrow[d,\"\\alpha\"]\\\\\n    & F \\arrow[d]\\\\\n    G \\arrow[r,two heads] & H\n\\end{tikzcd}\nso $F$ is projective.\\\\\nThe composite $\\mathcal{C}(A,-) \\xrightarrow{\\alpha} F \\xrightarrow{\\beta} \\mathcal{C}(A,-)$ is idenpotent; $Y:\\mathcal{C}^{op} \\to [\\mathcal{C},\\mathbf{Set}]$ is full and faithful, so it's of the form $Y(e)$ for a uniqu idempotent $A \\xrightarrow{e} A$ in $\\mathcal{C}$.\\\\\nBut now if this splits as $A \\xrightarrow{g} B \\xrightarrow{f} A$, then $\\mathcal{C}(A,-) \\xrightarrow{\\mathcal{C}(f,-)}\\mathcal{C}(B,-) \\xrightarrow{\\mathcal{C}(g,-)} \\mathcal{C}(A,-)$ is a splitting of $\\beta\\alpha$. But then by Q6(i), so we must have $F \\cong \\mathcal{C}(B,-)$.\\\\\n(iii) We know $[\\mathcal{C},\\mathbf{Set}] \\simeq [\\hat{\\mathcal{C}},\\mathbf{Set}]$ since $\\mathbf{Set}$ is Cauchy-complete. If $\\hat{\\mathcal{C}} \\simeq \\hat{\\mathcal{D}}$ by functors $F$ and $G$, then $T \\to TF$ and $T \\to TG$ give an equivalence $[\\hat{\\mathcal{C}},\\mathbf{Set}] \\simeq [\\hat{\\mathcal{D}},\\mathbf{Set}]$.\\\\\nBut any equivalence $[\\hat{\\mathcal{C}},\\mathbf{Set}] \\simeq [\\hat{\\mathcal{D}},\\mathbf{Set}]$ restricts to an equivalence between the full subcategories of irreducible projectives, which are equivalent to $\\hat{\\mathcal{C}}^{op}$ and $\\hat{\\mathcal{D}}^{op}$.\n\n\\subsection{Question 8}\nThis question is actually quite quick (and Joel says it's actually a question in one past-paper).\\\\\n$\\mathcal{C}(A,-)$ is a monofunctor just means that for any $f:B \\to C$, the map $g \\to fg$ is an injection $\\mathcal{C}(A,B) \\to \\mathcal{C}(A,C)$. This holds for all $A$ iff all $f \\in \\mor\\mathcal{C}$ are monic -- that's the equivalence between (i) and (ii).\\\\\nWe now prove (ii) $\\implies$ (iii): Since we have an epi $\\coprod \\mathcal{C}(A,-) \\twoheadrightarrow F$ and disjoint unions of monofunctors are monofunctors (?).\\\\\nFor (iii) $\\implies$ (ii), if we have $F \\stackrel{\\alpha}{\\twoheadrightarrow} \\mathcal{C}(A,-)$ with $F$ a monofunctor, we have a splitting $\\mathcal{C}(A,-) \\stackrel{\\beta}{\\rightarrowtail} F$, and any subfunctor of a monofunctor is a monofunctor.\\\\\nGiven $f:A \\to B$, consider the push out\n\\begin{tikzcd}\n    \\mathcal{C}(B,-) \\arrow[r,\"{\\mathcal{C}(f,-)}\"] \\arrow[d,\"{\\mathcal{C}(f,-)}\"] & \\mathcal{C}(A,-) \\arrow[d]\\\\\n    \\mathcal{C}(A,-) \\arrow[r] & F\n\\end{tikzcd}\n. Explicitly, $F(C) \\cong \\mathcal{C}(A,C) \\times \\{0,1\\} / \\sim$ where $(g,0) \\sim (g,1) \\iff f$ factors through $g$.\\\\\nIf this is a monofunctor, we must have $(1_A,0) \\simeq (1_A,1)$ (check the relation in the middle), since $Ff$ sends them to the same thing.\\\\\nIf all morphisms of $\\mathcal{C}$ are split monic, then $\\mathcal{C}$ is a groupoid. And of course the converse holds (check).\n\n\\newpage\n\n\\section{Example Class 2}\n\n\\subsection{Question 1}\nThis is intended to be an easy question, although you could spend a lot of time if you want to go into all the details.\n\nDefine $F_0,F_1,...,F_n$ by\n$$F_0(A_1 \\to A_2 \\to ... \\to A_{n-1}) = (0 \\to A_1 \\to A_2 \\to ... \\to A_{n-1})$$\n$$F_n(A_1 \\to ... \\to A_{n-1}) = (A_1 \\to A_2 \\to ... \\to A_{n-1} \\to 1)$$\nand if $1 \\leq i \\leq n-1$,\n$$F_i (A_1 \\to ... \\to A_{n-1}) = (A_1 \\to A_2 \\to ... \\to A_i \\xrightarrow{1} A_i \\to A_{i+1} \\to ... \\to A_{n-1})$$\nSimilarly, $G_0,...,G_{n-1}$ by \n$$G_0(B_1 \\to B_2 \\to ... \\to B_n) = (B_2 \\to ... \\to B_n)$$\n$$G_{n-1}(B_1 \\to ... \\to B_{n-1} \\to B_n) = (B_1 \\to ... \\to B_{n-1})$$\nand if $1 \\leq i \\leq n-2$,\n$$G_i (B_1 \\to B_2 \\to ... \\to B_n) =(B_1 \\to ... \\to B_i \\to B_{i+2} \\to ... \\to B_{n-1})$$\nwhere we compose two morphisms together.\n\nTo show $F_i \\dashv G_i$ (for $i$ in the middle), consider a morphism $F_i(\\mathbf{A}) \\to \\mathbf{B}$. This looks like\n\n\\begin{tikzcd}\n    A_1 \\arrow[d,\"\\alpha_1\"] \\arrow[r] & A_2 \\arrow[d,\"\\alpha_2\"] \\arrow[r] & ... \\arrow[r] & A_i \\arrow[d,\"\\alpha_i\"] \\arrow[r] & A_i \\arrow[d,\"\\alpha_{i+1}\"] \\arrow[r] & A_{i+1} \\arrow[d,\"\\alpha_{i+2}\"] \\arrow[r] & ... \\arrow[r] & A_{n-1} \\arrow[d,\"\\alpha_n\"]\\\\\n    B_1 \\arrow[r] & B_2 \\arrow[r] & ... \\arrow[r] & B_i \\arrow[r] & B_{i+1} \\arrow[r] & B_{i+2} \\arrow[r] & ... \\arrow[r] & B_n\n\\end{tikzcd}\nHere $\\alpha_{i+1}$ is uniquely determined by the other data: if we omit it, we get a morphism $\\mathbf{A} \\to G_i (\\mathbf{B})$. Other adjunctions are similar.\\\\\n$F_0$ doesn't preserve $\\mathbf{1}$, so it can't have a left adjoint; similarly $F_n$ doesn't preserve $\\mathbf{0}$.\n\nFor the last part, we have $(F_0G_0 \\dashv F_1G_0 \\dashv F_1G_1 \\dashv ... \\dashv F_n G_{n-1})$, which is a string of length $2n$; but $F_0G_0$ doesn't preserve $\\mathbf{1}$, $F_nG_{n-1}$ doesn't preserve $\\mathbf{0}$.\n\n\\subsection{Question 2}\nWe know\n\n\\begin{tikzcd}\n    F \\arrow[r,\"F\\alpha\"] \\arrow[d,\"F\\alpha\"] & FGF \\arrow[r,\"\\beta_F\"] \\arrow[d,\"FGF\\alpha\"] & F \\arrow[d,\"F\\alpha\"]\\\\\n    FGF \\arrow[r,\"F\\alpha_{GF}\"] \\arrow[rd,\"1_{FGF}\"] & FGFGF \\arrow[r,\"\\beta_{FGF}\"] \\arrow[d,\"FG\\beta_F\"] & FGF \\arrow[d,\"\\beta_F\"]\\\\\n    & FGF \\arrow[r,\"\\beta_F\"] & F\n\\end{tikzcd}\n\ncommutes by naturality of $\\alpha$ and $\\beta$ and the given triangular identity. So from the diagram we've proved idempotency.\n\nIf we can split $(\\beta_F) (F\\alpha)$ in the functor category $[\\mathcal{C},\\mathcal{D}]$, say as\n\\begin{tikzcd}\n    F \\arrow[r,\"\\delta\"] & F' \\arrow[r,\"\\gamma\"] & F\n\\end{tikzcd}\n, we define $\\eta$ to be \n\\begin{tikzcd}\n    1_\\mathcal{C} \\arrow[r,\"\\alpha\"] & GF \\arrow[r,\"G\\delta\"] & GF'\n\\end{tikzcd}\nand $\\varepsilon$ to be\n\\begin{tikzcd}\n    F'G \\arrow[r,\"\\gamma_G\"] & FG \\arrow[r,\"\\beta\"] & 1_\\mathcal{D}\n\\end{tikzcd}\n\nNow we just have to verify the triangular identities for these:\n\n\\begin{tikzcd}\n    G \\arrow[r,\"\\alpha_G\"] \\arrow[d,\"\\alpha_G\"] & GFG \\arrow[r,\"G\\delta_G\"] \\arrow[d,\"GF\\alpha_G\"] & GF'G \\arrow[d,\"G\\gamma_G\"] \\\\\n    GFG \\arrow[r,\"\\alpha_{GFG}\"] \\arrow[rr,bend right=20, \"1_{GFG}\"'] & GFGFG \\arrow[r, \"G\\beta_{FG}\"] & GFG \\arrow[d,\"G\\beta\"]\\\\\n    & & G\n\\end{tikzcd}\n\nis the identity. For the other triangle,\n\n\\begin{tikzcd}\n    F' \\arrow[d,\"\\gamma\"] \\arrow[dd, bend right=20, \"1_{F'}\"'] \\arrow[r,\"F'\\alpha\"] & F'GF \\arrow[d,\"\\gamma_{GF}\"] \\arrow[r,\"F'G\\delta\"] & F'GF' \\arrow[d,\"\\gamma_{GF'}\"]\\\\\n    F \\arrow[r,\"F\\alpha\"] \\arrow[d,\"\\delta\"] & FGF \\arrow[r,\"FG\\delta\"] \\arrow[d,\"\\beta_F\"] & FGF' \\arrow[d,\"\\beta_{F'}\"]\\\\\n    F' \\arrow[r,\"\\gamma\"] \\arrow[rr,bend right=20, \"1_{F'}\"'] & F \\arrow[r, \"\\delta\"] & F'\n\\end{tikzcd}\n\nFor the last part, take $\\mathcal{C} = \\mathbf{1}$, $\\mathcal{D}$ to be the monoid $\\{1,e|e^2 = e\\}$.\\\\\n$\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D}$ are the unique functors, $GF=1_{\\mathcal{C}}$, so take $\\alpha = 1_{1_{\\mathcal{C}}}$. $FG \\neq 1_\\mathcal{D}$, but $e$ defines a natural transformation $\\beta:FG \\to 1_\\mathcal{D}$. Note that $\\mathcal{D}$ doesn't have an initial object, so $G$ doesn't have a left adjoint (I think so?).\n\n\\subsection{Question 3}\nIn fact (i) and (ii) are immediately equivalent since $(\\varepsilon_F) (F\\eta) = 1_F$, so if one of them is an isomorphism then so is the other one.\\\\\n(ii) implies (iii) since $G$ preserves isomorphisms.\\\\\n(iii) implies (iv) since $\\eta_{GF}$ and $GF\\eta$ are both 1-sided inverses for $G\\varepsilon_F$.\\\\\n(iv) implies (v) is trivial.\\\\\nThe only nontrivial part is (v) $\\implies$ (vi). Assuming (v), we need to show\n\\begin{tikzcd}\n    GFG \\arrow[r,\"G\\varepsilon\"] & G \\arrow[r,\"\\eta_G\"] & GFG\n\\end{tikzcd}\nis the identity, but \n\\begin{tikzcd}\n    GFG \\arrow[r,\"G\\varepsilon\"] \\arrow[d,\"\\eta_{GFG}\"] & G \\arrow[d,\"\\eta_G\"]\\\\\n    GFGFG \\arrow[r,\"GFG\\varepsilon\"] & GFG\n\\end{tikzcd}\ncommutes by naturality, and $(GFG\\varepsilon)(GF\\eta_G) = 1_{GFG}$.\n\n\\subsection{Question 4}\nThese $Fix$s are really only interesting when $F \\dashv G$ is idempotent, since otherwise we usually have both of the $Fix$ being empty.\\\\\n(i) If $A \\in \\ob(Fix(GF))$, then $F\\eta_A$ is an isomorphism, so $\\varepsilon_{FA}$ is isomorphism, so $FA \\in \\ob(Fix(FG))$, and dually $G$ maps $Fix(FG)$ to $Fix(GF)$.\\\\\nThe adjunction restricts to an adjunction $Fix(GF) \\stackrel[G]{F} Fix(FG)$ (note that we are using the same letter for the restricted functors), where unit and counit are isomorphisms. So this is actually an equivalence between categories.\\\\\n(ii) Now if the adjunction is idempotent, then $F$ maps all of $\\mathcal{C}$ into $Fix(FG)$, and $G$ maps $\\mathcal{D}$ into $Fix(GF)$, so these things now can't be empty. Moreover, $GF$ is a functor $\\mathcal{C} \\to Fix(GF)$, and we have a natural transformation $\\eta:1_\\mathcal{C} \\to GF$ s.t. $\\eta$ is an isomorphism precisely when $A \\in \\ob(Fix(GF))$. This yields a bijection between morphisms $A \\xrightarrow{f} A'$ with $A' \\in \\ob Fix(FG)$ and morphisms\n\\begin{tikzcd}\n    GFA \\arrow[r,\"GFf\"] & GFA' \\arrow[r,\"\\eta_{A'}^{-1}\"] & A'\n\\end{tikzcd}\nDually, $FG$ is a right adjoint to the inclusion $Fix(FG) \\hookrightarrow \\mathcal{D}$. So we have\n\n\\begin{tikzcd}\n    \\mathcal{C} \\arrow[r,shift left, \"FGF\"] \\arrow[d,\"GF\"',shift right] & \\mathcal{D} \\arrow[l,\"GFG\", shift left] \\arrow[d,\"FG\",shift left]\\\\\n    Fix(GF) \\arrow[u,shift right,\"I\"'] \\arrow[r,\"F\",shift left] & Fix(FG) \\arrow[u,shift left,\"J\"] \\arrow[l,\"G\",shift left]\n\\end{tikzcd}\n\na factorization of $(F \\dashv G)$ up to isomorphism as reflection + equivalance + coreflection.\\\\\nSuppose given $\\mathcal{C} \\stackrel[G]{F}{\\rightleftarrows} \\mathcal{D} \\stackrel[K]{H}{\\rightleftarrows} \\mathcal{E}$ where $(F\\dashv G)$ is a reflection and $(H \\dashv K)$ is a coreflection.\\\\\nThe unit of $(HF \\dashv GK)$ is $1\\mathcal{C} \\xrightarrow{\\eta} GF \\stackrel[\\simeq]{G\\iota_F}{\\longrightarrow} GKHF$, where $\\eta$ and $\\iota$ are the units of $(F\\dashv G)$ and $(H \\dashv K)$.\\\\\nNow $F \\xrightarrow{F\\eta} FGF \\xrightarrow{\\sim} FGKHF$ is an isomorphism, so $HF \\to HFGKHF$ is an isomorphism.\n\n\\subsection{Question 5}\nStart with $J$ a finite connected category. For $j \\in \\ob\\mathcal{J}$, define $d(j) = |\\{j' \\in \\ob\\mathcal{J} | \\not\\exists j \\to j' \\text{ in } \\mathcal{J}\\}|$. Choose $j_0 \\in \\ob\\mathcal{J}$ with $d(j_0)$ minimal. If $d(j_0) \\neq 0$, pick $k$ in the corresponding above set of $d(j_0)$, we can find a zigzag\n\n\\begin{tikzcd}\n    j_0 \\arrow[rd] & & k_2 \\arrow[ld] \\arrow[rd] & & \\cdot \\arrow[ld] \\arrow[r, dotted, no head] & K=K_n\\\\\n    & k_1 & & k_3 & &\n\\end{tikzcd}\nLet $i$ be minimal s.t. $\\not\\exists j_0 \\to K_i$. Then we have \n\\begin{tikzcd}\n    j_0 \\arrow[rd,\"\\alpha\"] & & k_i \\arrow[ld,\"\\beta\"]\\\\\n    & k_{i-1} &\n\\end{tikzcd}\n. Enlarge $\\mathcal{J}$ to $\\mathcal{J}_1$ by adding\n\\begin{tikzcd}\n    & j_1 \\arrow[ld,\"\\gamma\"] \\arrow[rd,\"\\delta\"] & \\\\\n    j_0 & & k_i\n\\end{tikzcd}\nplus composites subjects to the relation $\\alpha\\gamma = \\beta\\delta$.\\\\\nNote that $d_{\\mathcal{J}_1}(j_1) < d_{\\mathcal{J}}(j_0)$.\\\\\nIf $D:J \\to \\mathcal{C}$ where $\\mathcal{C}$ has pullbacks, we enlarge it to a diagram $D_1: \\mathcal{J}_1 \\to \\mathcal{C}$ by requiring\n\\begin{tikzcd}\n    & D_1(j_1) \\arrow[ld] \\arrow[rd] &\\\\\n    D(j_0) \\arrow[rd] & & D(k_i) \\arrow[ld]\\\\\n    & D(K_{i-1}) &\n\\end{tikzcd}\nto be a pullback. Then any cone over $D$ extends uniquely to a cone over $D_1$, and hence $D_1$ has a limit iff $D$ does.\\\\\nHence, after at most $d(j_0)$ steps, we get a diagram $D': \\mathcal{J}' \\to \\mathcal{C}$ where $\\mathcal{J}'$ has a weakly initial object, s.t. the extended diagram has a limit iff the original diagram $D$ does.\\\\\nNow suppose we are given $D:\\mathcal{J} \\to \\mathcal{C}$ where $\\mathcal{J}$ is finite and has a weakly initial object $j_0$. Let\n$$\\{j_0 \\stackrel[\\beta_i]{\\alpha_i}{\\rightrightarrows} j_i| 1 \\leq i \\leq n\\}$$\nbe a listing of the unequal parallel pairs with domain $j_0$. Now form\n\n\\begin{tikzcd}\n    E_n \\arrow[r] & ... \\arrow[r] & E_2 \\arrow[r] & E_1 \\arrow[r] & D(j_0)\n\\end{tikzcd}\n\nwhere $E_1 \\to D(j_0)$ is the equalizer of $D(\\alpha_1)$ and $D(\\beta_1)$, $E_2 \\to E_1$ is the equalizer of $E_1 \\to D(j_0) \\stackrel[D(\\beta_2)]{D(\\alpha_2)}{\\rightrightarrows} D(j_2)$, and so on.\\\\\nThen the composites $E_n \\to D(j_0) \\to D(j)$ for $j \\in \\ob\\mathcal{J}$ form a cone over $D$; moreover, if $(\\lambda_j| j \\in \\ob\\mathcal{J})$ is any cone over $D$, $\\lambda_{j_0}$ factors uniquely through $D_n \\to D(j_0)$, and the factorization is a moprhism of cones.\n\n(ii) Consider \n\\begin{tikzcd}\n    \\mathcal{C}/A \\arrow[r,\"U\"] & \\mathcal{C}\n\\end{tikzcd}\nby\n\\begin{tikzcd}\n    \\begin{pmatrix}\n        B\\\\\n        \\downarrow f\\\\\n        A\n    \\end{pmatrix} \\arrow[r] & B\n\\end{tikzcd}\n, and suppose given $D:\\mathcal{J} \\to \\mathcal{C}/A$ with $\\mathcal{J}$ connected, and write $D(j) = \\begin{pmatrix}UD(j)\\\\\\downarrow f_j\\\\A \\end{pmatrix}$.\\\\\nGiven any cone $(B\\xrightarrow{\\beta_j} UD(j) | j \\in \\ob\\mathcal{J})$ over $UD$, the composite $f_j \\beta_j$ is independent of $j$, since if $\\exists \\alpha:j \\to j'$, then \n\n\\begin{tikzcd}\n    & B \\arrow[ld,\"\\beta_j\"'] \\arrow[rd,\"\\beta_{j'}\"] &\\\\\n    UD(j) \\arrow[rr,\"UD(\\alpha)\"] \\arrow[rd,\"f_j\"'] & & UD(j') \\arrow[ld,\"f_{j'}\"] \\\\\n    & A &\n\\end{tikzcd}\ncommutes. So there exists a unique $g:B \\to A$ s.t. $\\beta_j$ become a cone in $\\mathcal{C}/A$ with apex $g$.\\\\\nIn particular, if the $\\beta_j$ are a limit cone over $UD$, their liftings are a limit cone over $D$.\n\n(iii) Given $F:\\mathcal{C} \\to \\mathcal{D}$, factor it as $\\mathcal{C} \\xrightarrow{\\hat{F}} D / F1 \\xrightarrow{U} D$, where $\\hat{F}(A) = \\begin{pmatrix} FA\\\\\\downarrow\\\\F1\\end{pmatrix}$. $\\hat{F}$ preserves pullbacks since $F$ preserves them and $U$ creates them. But $\\hat{F}$ also preserves the terminal object. So $\\hat{F}$ preserves all finite limits. And $U$ preserves all connected limits, so $U\\hat{F} = F$ preserves all finite connected limits.\n\n(Solution to question 6-10 to be typesetted)\n\n\\newpage\n\n\\section{Example Class 3}\n\n\\subsection{Question 1}\nAs usual this was meant to be an easy question (jfalksdjf;laskflklj;aj;sdkjflasj).\n\n(i) If $\\alpha,\\beta:1_\\mathcal{C} \\rightrightarrows 1_\\mathcal{C}$, then\n\n\\begin{tikzcd}\n    A \\arrow[r,\"\\alpha_A\"] \\arrow[d,\"\\beta_A\"] & A \\arrow[d,\"\\beta_A\"]\\\\\n    A \\arrow[r,\"\\alpha_A\"] & A\n\\end{tikzcd}\n\ncommutes by naturality.\n\n(ii) If $(1_\\mathcal{C},\\eta,\\mu)$ is a monad, then $\\mu\\eta = 1_{1_\\mathcal{C}}$, so $\\eta \\mu = 1_{1_\\mathcal{C}}$.\n\n(iii) Suppose $\\alpha:1_\\mathcal{C} \\to GC$ is a natural isomorphism. Define $\\eta' = $\n\\begin{tikzcd}\n    1_\\mathcal{C} \\arrow[r,\"\\eta'\"] & GF \\arrow[r,\"\\alpha^{-1}\"] & 1_\\mathcal{C}\n\\end{tikzcd}\n,\\\\\n$\\mu'=$\n\\begin{tikzcd}\n    1_\\mathcal{C} \\arrow[r,\"\\alpha\"] & GF \\arrow[r,\"GF\\alpha\"] & GFGF \\arrow[r,\"\\mu\"] & GF \\arrow[r,\"\\alpha^{-1}\"] & 1_\\mathcal{C}\n\\end{tikzcd}\n\nThen $(1_\\mathcal{C},\\eta',\\mu')$ is a monad, so $\\eta'$ is an isomorphism, so $\\eta = \\alpha\\eta'$ is an isomorphism, i.e. $F$ is full and faithful (a dual to one of the results in lecture).\n\n(iv) We have the forgetful functor $[M,\\mathbf{Set}] \\xrightarrow{U} \\mathbf{Set}$. $FF = M \\times A$ with $M$ acting on first factor $(F \\dashv U)$, but $\\eta:A \\to UFA$ isn't an isomorphism.\\\\\nIf $H:\\mathbf{Set} \\to [M,\\mathbf{Set}]$, $HA = A$ with trivial $M$-action, then $UH = 1_{\\mathbf{Set}}$.\\\\\n$G:[M,\\mathbf{Set}] \\to \\mathbf{Set}$ sends $(A,e)$ to $\\{x \\in A | ex = x\\}$, then $GF \\cong 1_{\\mathbf{Set}}$.\n\n\\subsection{Question 2}\nIf $(A,\\alpha)$ is a $\\T$-algebra, then $\\alpha\\eta_A = 1_A$, and \n\\begin{tikzcd}\n    TA \\arrow[r,\"\\eta_{TA}\"] \\arrow[d,\"\\alpha\"] & TTA \\arrow[d,\"T\\alpha\"]\\\\\n    A \\arrow[r,\"\\eta_A\"] & TA\n\\end{tikzcd}\ncommutes; but $\\eta_{TA} = T\\eta_A$ since both are inverse to $\\mu_A$, so $\\eta_A \\alpha = 1_{TA}$.\\\\\nConversely, if $A \\in \\ob(Fix T)$, then $\\eta_A^{-1}$ is a $\\T$-algebra structure on $A$, and any $A \\xrightarrow{f} B$ in $Fix(T)$ is a homomorphism $(A,\\eta_A^{-1}) \\to (B,\\eta_B^{-1})$.\\\\\nSo $G^\\T: \\mathcal{C}^\\T \\to \\mathcal{C}$ maps $\\mathcal{C}^\\T$ isomorphically to $Fix(T)$.\\\\\n$Fix(T)$ is reflective in $\\mathcal{C}$, with reflector $T$, and $T$ is essentially surjective as a functor $\\mathcal{C} \\to Fix(T)$. So the Kleisli comparison $\\mathcal{C}_\\T \\to Fix(T)$ is an equivalence.\n\nFor the last part, $M$ is the order-preserving endomorphisms of $\\N$. Define $\\eta:1_M \\to T$ by $\\eta_*(n) = n+1$, and $\\mu:TT \\to T$ must send $\\mu_*(0) = 0$, $\\mu_*(n) = n-1$ if $n>0$. But if $\\alpha$ is any $\\T$-algebra structure on $*$, then necessarily $\\alpha(n+1) = n$ for all $n$, and $\\alpha$ is order-preserving so $\\alpha(0) = 0$. So the comparison $M_\\T \\to M^\\T$ is bijective on objects.\n\n\\subsection{Question 3}\n$F:\\mathcal{C} \\to \\mathcal{D}$ induces $F^*:[\\mathcal{D},\\mathbf{Set}] \\to [\\mathcal{C},\\mathbf{Set}]$ with both left and right adjoints, and hence preserving equalizers and coequalizers. So $F^*$ is monadic and comadic $\\iff F^*$ reflects isomorphisms.\\\\\nIf every $B \\in \\ob\\mathcal{D}$ is isomorphic to some $FA$, then for $\\beta: G \\to H$ (where $G,H: \\mathcal{D} \\rightrightarrows \\mathbf{Set})$, $\\beta_{FA}$ is isomorphism for all $A$ implies that $\\beta_B$ is an isomorphism for all $B$, since\n\n\\begin{tikzcd}\n    GFA \\arrow[r,\"G\\alpha\"] \\arrow[d,\"\\beta_{FA}\"] & GB \\arrow[d,\"\\beta_B\"]\\\\\n    HFA \\arrow[r,\"H\\alpha\"] & HB\n\\end{tikzcd}\n\ncommutes.\n\nFor the last part, apply this to $I:\\mathcal{C}_0 \\to \\mathcal{C}$ where $\\mathcal{C}_0$ is the discrete category with same objects as $\\mathcal{C}$, and $I$ is inclusion, we get $[\\mathcal{C},\\mathbf{Set}]$ monadic and comonadic over $[\\mathcal{C}_0,\\mathbf{Set}] \\cong \\mathbf{Set}^{ob\\mathcal{C}}$.\n\n\\subsection{Question 4}\n(Lecturer: This is a very fun question, and I'm pretty happy that I discovered this).\\\\\n$x:\\mathbf{Set} \\times \\mathbf{Set} \\to \\mathbf{Set}$ preserves reflexive coequalizers by ES4 Q3. But $\\phi\\times A = \\phi$ for all $A$, so $\\phi \\times A \\to \\phi \\times B$ is an isomorphism for any $A \\times B$. So it's not monadic.\\\\\nHowever, if $\\mathcal{C}$ is the full subcategory of $\\mathbf{Set} \\times \\mathbf{Set}$ on pairs $(A,B)$ with $A=\\phi \\iff B=\\phi$, then $\\Delta: \\mathbf{Set} \\to \\mathcal{C}$ and $\\times|_\\mathcal{C}$ are still adjoint to each other (because this is a full subcategory), and $\\times|_\\mathcal{C}$ still preserves reflexive coequalizers, and now reflects isomorphisms (because we've thrown away the bad things).\\\\\nA \\emph{rectangular band} is a set $A$ with binary operation $b$ satisfying $b(x,x) = x$ and $b(b(x,y),b(z,w)) = b(x,w)$. The category of rectangular bands is actually isomorphic to the above $\\mathcal{C}$.\n\n\\subsection{Question 5}\n(i) $\\implies$ (ii) because $F$ preserves coequalizers.\\\\\n(ii) $\\implies$ (i) since $\\mathbf{Set}$ is balacned.\\\\\n(ii) $\\iff$ (iii) is the dual of (3.8).\\\\\n(iii) $\\implies$ (iv) is trivial.\\\\\n(iv) $\\implies$ (v) is almost equally trivial, since $F2$ has at least 2 elements.\\\\\n(v) $\\implies$ (iii): Let $(B,\\beta)$ be a $\\T$-algebra with $>1$ elements. Then given $A$ and two distinct elemnets, $x,y \\in A$, we can find $A \\xrightarrow{f} B$ with $f(x) \\neq f(y)$. Then $f$ factors through $\\eta_A$, so $\\eta_A(x) \\neq \\eta_A(y)$.\\\\\n(vii) $\\implies$ (vi) by reflexive comonadicity theorem (dual to 5.13).\\\\\n(vii) $\\iff$ (viii) since $T=GF$ and $G$ creates equalizers.\\\\\n(ix) $\\implies$ (viii): if \n\\begin{tikzcd}\n    A \\arrow[r,\"f\"] & B \\arrow[r,shift left, \"g\"] \\arrow[r,shift right,\"h\"'] & C \\arrow[l,\"r\"]\n\\end{tikzcd}\nus a coreflexive equalizers in $\\mathbf{Set}$, and $A \\vDash \\phi$, note that $g$ and $h$ are injective, and $g(x) = h(y)$ iff $x=y \\in \\im(f)$.\\\\\nSo choose $s:B \\to A$ with $sf = 1_A$; then define $t:C \\to B$ so that $t(z) = y$ if $z=h(y)$, $t(z) = fs(y)$ if $z=g(y)$, and $t(z) = y_0$ if $z \\not\\in (\\im h \\cup \\im g)$.\\\\\nThis is a split coequalizer, so $T$ preserves it. Now suppose $A = \\phi \\neq B$. Then $\\im g$ and $\\im h$ are disjoint.\\\\\nSuppose $x \\in TB$ satisfies $Tg(x) = Th(x)$. Define $t:C \\to B$ by $t(z) = y$ if $z=g(y)$, and is $z_0$ otherwise. then $x = (Tt)(Tg)(x) = (Tt)(Th)x = (Tz_0)(u)$ for some $u \\in T1$.\\\\\nNow consider \n\n\\begin{tikzcd}\n    1 \\arrow[r,shift left] \\arrow[r,shift right] \\arrow[d,\"y_0\"] & 2 \\arrow[d,\"{(gy_0,hy_0)}\"]\\\\\n    B \\arrow[r,shift left, \"g\"] \\arrow[r,shift right, \"h\"'] & C\n\\end{tikzcd}\n\nwhich commutes, and the right hand map is (split) monic, so $T$ maps it to a monomorphism. So $u$ has the same images under $T1 \\rightrightarrows T2$; hence it's in the image of $T\\phi \\to T1$.\n\nFinally (vi) $\\implies$ (ix) is a rather strange argument -- assume (ix) fails: consider the equalizer $E \\rightarrowtail F1$ of $F1 \\rightrightarrows F2$. We know $GE \\to GF1 \\rightrightarrows GF2$ is a coreflexive equalizer diagram with $GE \\neq \\phi$ (since $GF\\phi \\to GE$ is not an isomorphism). So it's split, and hence \n\n\\begin{tikzcd}\n    FGE \\arrow[r] & FGF1 \\arrow[r,shift left] \\arrow[r,shift right] & FGF2 \\\\\n    E \\arrow[u,dashed, \"\\theta\"'] \\arrow[r] & F1 \\arrow[u,\"F\\eta_1\"'] \\arrow[r,shift left] \\arrow[r,shift right] & F2 \\arrow[u,\"F\\eta_2\"']\n\\end{tikzcd}\n\nThis $\\theta$ is a coalgebra structure on $E$. Now the image under the comparison of $\\phi \\to 1$ factors as\n\\begin{tikzcd}\n    (F\\phi,F\\eta_\\phi) \\arrow[r] & (E,\\theta) \\arrow[r,tail] & (F1, F\\eta_1)\n\\end{tikzcd}\nwith neither factor an isomorphism. So $(E,\\theta)$ is not in the essential image (image of objects?) of the comparison.\n\n\\subsection{Question 6}\n(i) (This part is \\emph{straight-forward enough}) Given a $\\T$-algebra homomorphsim $f:(A,\\alpha) \\to (B,\\beta)$, consider\n\n\\begin{tikzcd}\n    TA \\arrow[d,\"\\alpha\"] \\arrow[r,two heads, \"Te\"] & TI \\arrow[r,\"Tm\"] \\arrow[d,dashed,\"\\iota\"] & TB \\arrow[d,\"\\beta\"]\\\\\n    A \\arrow[r,two heads,\"e\"] & I \\arrow[r,tail,\"m\"] & B\n\\end{tikzcd}\n\nWe get an induced $\\iota$ since $Te$ is (strong) epic and monic, and $\\iota$ is an algebra structure.\\\\\nSo $f$ is a strong epimorphsim in $\\mathbf{Set}^\\T$ $\\implies$ $m$ is an isomorphism $\\implies$ $f$ is surjective.\\\\\nGiven a surjective $(A,\\alpha) \\xrightarrow{f} (B,\\beta)$, form the pullback\n\n\\begin{tikzcd}\n    R \\arrow[r,\"a\"] \\arrow[d,\"b\"] & A \\arrow[d,\"f\"]\\\\\n    A \\arrow[r,\"f\"] & B\n\\end{tikzcd}\n\n$R$ has an algebra structure $\\rho$ since $G^\\T$ creates limits.\\\\\nNow\n\\begin{tikzcd}\n    R \\arrow[r,shift left, \"a\"] \\arrow[r, shift right, \"b\"'] & A \\arrow[r,\"f\"] \\arrow[l,bend left=40,\"t\"] & B \\arrow[l,bend left=20,\"s\"]\n\\end{tikzcd}\n, we can choose $s$ with $fs = 1_B$ and define $t$ to be the factorization of $(sf,1_A)$ through the pullback.\\\\\nSo $f$ is a coequalizer of $(R,\\rho) \\stackrel[b]{a}{\\rightrightarrows} (A,\\alpha)$ in $\\mathbf{Set}^\\T$.\n\n(ii) \n\n\\includegraphics[scale=0.5]{image/Cat_08.png}\n\nThe above is anon-regular composite of two regular epimorphisms.\n\n(iii) $\\mathbf{DGph} \\cong [M,\\mathbf{Set}]$ where $M=\\{1,d,c|d^2=cd=d,c^2=dc=c\\}$, and $[M,\\mathbf{Set}] \\xrightarrow{U} \\mathbf{Set}$ is monadic.\\\\\n$G:\\mathbf{Cat} \\to \\mathbf{DGph}$ has a left adjoint: the free category on a digraph $\\mathcal{G}$ has the same objects as $\\mathcal{G}$, and morphisms are composable strings $\\cdot \\to \\cdot \\to \\cdot \\to ... \\to \\cdot$, subject to cancellation of identities, and the adjunction is \\emph{straight-forward} to verify, so \\emph{that's easy}; and $\\varepsilon:FG\\mathcal{C} \\to \\mathcal{C}$ is bijective on objects.\n\nSuppose\n\\begin{tikzcd}\n    \\mathcal{G} \\arrow[r,shift left, \"f\"] \\arrow[r,shift right, \"g\"] & \\mathcal{H} \\arrow[r,\"h\"] \\arrow[l,\"r\"] & \\mathcal{K}\n\\end{tikzcd}\nis a reflexive coequalizer in $\\mathbf{DGph}$ where $f$ and $g$ are bijective on objects. Then $h$ is bijcetive on objects, and the morphisms of $\\mathcal{K}$ are equivalence classes of morphisms of $\\mathcal{H}$.\\\\\nSo if $\\mathcal{G}$ and $\\mathcal{H}$ are categories and $f$ and $g$ are functors, $\\mathcal{K}$ inherits a category structure making $h$ a coequalizer in $\\mathbf{Cat}$ (lecturer: I'm a bit hand-waving on this, the actual verification is a bit long to write down but I hope it's obvious).\\\\\nThis is enough to make the proof of the reflexive monadicity theorem work.\n\n\\subsection{Question 7}\n(i)\n\n\\begin{tikzcd}\n    1 \\arrow[r,\"0\"] & \\N & \\N \\arrow[l,\"s\"']\n\\end{tikzcd}\nis a coproduct and \n\\begin{tikzcd}\n    \\N \\arrow[r,shift left, \"s\"] \\arrow[r,shift right, \"1_\\N\"'] & \\N \\arrow[r] & 1\n\\end{tikzcd}\nis a coequalizer.\\\\\nGiven $A$, $1 \\xrightarrow{a} A$ and $A \\xrightarrow{t} A$ with corresponding diagrams, we define $f: \\N to A$ recursively by $f(0)=a$ and $f(n+1) = tf(a)$.\\\\\nThe coproduct diagram ensures that $f$ is injective.\\\\\nIf it's not surjective, define $h:A \\to \\{0,1\\}$ by $h(a) = 0$ if $a \\in \\im f$ and $h(a)=1$ otherwise. Then $h=ht$, contradicting the coequalizer diagram.\\\\\nSo if $F:\\mathbf{Set} \\to \\mathbf{Set}$ preserves finite limits and colimits, it preserves $\\N$. Hence it preserves countable coproducts, since we have pullbacks\n\n\\begin{tikzcd}\n    F(\\coprod_{n \\in \\N} A_n) \\arrow[d] & FA_n \\arrow[l] \\arrow[d] \\\\\n    F\\N \\arrow[d,no head,\"\\cong\"] & F1 \\arrow[l,\"Fn\"'] \\arrow[d,no head,\"\\cong\"]\\\\\n    \\N & 1 \\arrow[l,\"n\"']\n\\end{tikzcd}\n\n(ii) Suppose $F:\\mathbf{Set} \\to \\mathbf{Set}$ preserves finite limits and countable coproducts (Note that $F$ preserves all epimorphisms, and hence preserves images).\\\\\n$F$ preserves coequalizers of equivalence relations $R \\subseteq A \\times A$ by the hint in question 6.\\\\\nGiven a parallel pair $A \\stackrel[g]{f}{\\rightrightarrows} B$, we construct the equivalence relation on $B$ generated by all pairs $(fx,gx)$ as follows:\\\\\nFirst form the image $I \\rightarrowtail B \\times B$ of $A \\xrightarrow{(f,g)} B \\times B$. Then form the image $S \\rightarrowtail B \\times B$ of $I \\coprod B \\coprod I^{op} \\to B \\times B$ to get a reflexive and symmetric relation. Now form the powers $S^n \\rightarrowtail B \\times B$ using finite limits and images, and then form $R = \\im(\\coprod_{n \\in \\N} S^n \\to B \\times B)$.\\\\\nAll of these is preserved by $F$.\n\n(iii) Suppose $F:\\mathbf{Set} \\to \\mathbf{Set}$ preserves finite limits and colimits. We have $\\alpha:1_{\\mathbf{Set}} \\cong \\mathbf{Set}(1,-) \\to F$ corresponding to the unique element of $F1$.\\\\\nNote $F(1 \\coprod 1) \\cong 1 \\coprod 1$, whence $\\alpha_2$ is bijective, whence $\\alpha_A$ is injective for all $A$.\\\\\nSuppose $\\kappa$ is the least cardinal $(>\\omega)$ s.t. $\\alpha$ isn't surjective on (sets of cardinality) $\\kappa$. Pick $x \\in F(\\kappa) \\setminus \\im \\alpha_\\kappa$; say $A \\subseteq \\kappa$ is \\emph{large} if $x \\in \\im(FA \\to F\\kappa)$.\\\\\nWe can say several things about those large sets: if $A$ is large, $A \\subseteq A'$ then $A'$ is large; if $A,A'$ are large then $A \\cap A'$ is large since $F$ preserves pullbacks.\\\\\nFor every $A$, either $A$ or $\\kappa \\setminus A$ is large since $F$ preserves binary coproducts, but not both of them, since $F$ preserves $\\phi$.\\\\\nThis means that the collection $\\mathcal{U}$ of large sets is an \\href{https://en.wikipedia.org/wiki/Ultrafilter}{ultrafilter}.\\\\\nAll finite sets are small; countable unions of small sets are small (since $F$ preserves countable coproducts), so countable intersections of large sets are large.\\\\\nHence $\\kappa$ is a \\href{https://en.wikipedia.org/wiki/Measurable_cardinal}{measurable cardinal}: if we are working in a model where no measurable cardinals exist, then no such $F$ can exist.\\\\\nGiven a countably complete non-principal ultrafilter $\\mathcal{U}$ on $\\kappa$, we can define $\\pi_\\mathcal{U}: \\mathbf{Set} \\to \\mathbf{Set}$ by $\\pi_\\mathcal{U} (A) = A^\\kappa / \\sim_\\mathcal{U}$, where $f,g: \\kappa \\rightrightarrows A$ are identified iff they agree on a set in $\\mathcal{U}$.\n\n\\newpage\n\n\\section{Example Class 4}\n\n\\subsection{Question 1}\nSuppose $A$ is strict. Then $\\pi_1:A \\times B \\to A$ is an isomorphism. So there exists $\\pi_2\\pi_1^{-1} : A \\to A \\times B \\to B$.\\\\\nFor uniqueness, if $f,g : A \\rightrightarrows{B}$, then $\\pi_1(1,f) = \\pi_1(1,g):A \\to A \\times B \\to A$, so $(1,f) = (1,g)$, so $f=g$.\n\nFor the second part, $\\mathcal{C}$ is Cartesian closed, so $A \\times B$ is initial, so $A \\times B \\xrightarrow{\\pi_1} A$ is an isomorphism. Given $B \\xrightarrow{f} A$, $B \\xrightarrow{(f,1)} A \\times B \\xrightarrow{\\pi_2} B$ is the identity, and $A \\times B \\xrightarrow{\\pi_2} B \\xrightarrow{(f,1)} A \\times B = 1_{A \\times B}$ since $A \\times B$ is initial. So $f=\\pi_1(f,1)$ is an isomorphism.\n\n\\subsection{Question 2}\n(i) If $f:X_1 \\to X_2, g:Y_1 \\to Y_2$ are distance decreasing, then $f \\times g: X_1 \\times Y_1 \\to X_2 \\times Y_2$ is also distance decreasing for all the three metrics.\n\n(ii) $\\pi_1,\\pi_2$ are distance decreasing for all of the metrics; but $X \\xrightarrow{(1,1)} X \\times X$ is only distance decreasing for the $d_\\infty$ metric, so it's the only possible one. Then it's straight-forward to verify that it works: if $f:Z \\to X$ and $g:Z \\to Y$ are dd, then so is $f(f,g):Z \\to X \\times Y$ for $d_\\infty$.\n\n(iii) If $(-) \\times X$ has a right adjoint $(-)^X$, then points of $Y^X$ must correspond to dd maps $1 \\times X \\cong X \\to Y$.\\\\\nWe have a metric on this set given by $d(f,g)=\\sup_{x \\in X} d(f(x),g(x))$. Then, given a map $f:Z \\times X \\to Y$, $f$ is dd for $d_1$ iff $\\bar{f}:Z \\to Y^X$ is dd for this metric, since \n\\begin{equation*}\n\\begin{aligned}\nd(f(z_1,x_1),f(z_2,x_2)) &\\leq d(f(z_1,x_1),f(z_1,x_2)) + d(f(z_1,x_2),d(f(z_2,x_2)))\\\\\n&\\leq d(x_1,x_2)+d(\\bar{f}(z_2))\\\\\n&\\leq d(x_1,x_2)+d(z_1,z_2)\n\\end{aligned}\n\\end{equation*}\n\nThe other two do not have right adjoints, but lecturer forgot how to prove that (he vaguely rememebered that it was some fancy combinatorial argument on a finite metric space). The important point is that we know the result, and hence we don't get a Cartesian closed category.\n\n\\subsection{Question 3}\n(i)\n\n\\begin{tikzcd}\nA_1 \\times A_2 \\arrow[rdd, \"f_1 \\times f_2\", shift left] \\arrow[rdd, \"g_1 \\times g_2\"', shift right] & A_1 \\times B_2 \\arrow[dd,\"f_1 \\times 1\"', shift right] \\arrow[dd,\"g_1 \\times 1\", shift left] \\arrow[r, \"1_{A_1} \\times h_2\"] & A_1 \\times C_2 \\arrow[dd, \"f_1 \\times 1\"', shift right] \\arrow[dd, \"g_1 \\times 1\", shift left] &\\\\\n& & &\\\\\nB_1 \\times A_2 \\arrow[uu,\"r_1 \\times 1_{A_2}\"] \\arrow[r,\"1 \\times f_2\", shift left] \\arrow[r,\"1 \\times g_2\"', shift right] & B_1 \\times B_2 \\arrow[r,\"1 \\times h_2\"] \\arrow[rd, \"h_1 \\times h_2\"'] \\arrow[rrdd, green, bend right=40, \"x\"'] & B_1 \\times C_2 \\arrow[d,\"h_1 \\times 1_{C_2}\"] \\arrow[rdd, green, bend left=40, \"y\"] &\\\\\n& & C_1 \\times C_2 \\arrow[rd,green,\"z\"] &\\\\\n& & & \\textcolor{green}{Z}\n\\end{tikzcd}\n\nGiven $x:B_1 \\times B_2 \\to Z$ with $x(f_1 \\times f_2) = x(g_1 \\times g_2)$, we have $x(1 \\times f_2) = x(1 \\times g_2)$.\\\\\nSo we get $y:B_1 \\times C_2 \\to Z$ with $y(1 \\times h_2) = x$.\\\\\nSimilarly, $x(f_1\\times 1_{B_2}) = x(g_1 \\times 1_{B_2})$, so $y(f_1 \\times 1_{C_2})(1_{A_1} \\times h_2) = y(g_1 \\times 1)(1 \\times h_2)$.\\\\\nBut $(1_{A_1} \\times h_2)$ is epic, so $y$ factors as $z(h_1 \\times 1_{C_2})$.\n\nSuppose given a reflexive pair of monoid homomorphisms $A \\stackrel[g]{f}{\\rightrightarrows} B$ in $\\mathbf{Mon}(\\mathcal{C})$, with coequalizer $B \\xrightarrow{h} C$ in $\\mathcal{C}$. Then we have \n\n\\begin{tikzcd}\nA \\times A \\arrow[r,\"f \\times f\", shift left] \\arrow[r, \"g \\times g\"', shift right] \\arrow[d, \"m_A\"] & B \\times B \\arrow[r,\"h \\times h\"] \\arrow[d,\"m_B\"] & C \\times C \\arrow[d,dashed, \"m_C\"]\\\\\nA \\arrow[r,shift left, \"f\"] \\arrow[r, shift right, \"g\"'] & B \\arrow[r,\"h\"] & C\n\\end{tikzcd}\n\nand we get a unique $m_C:C \\times C \\to C$ s.t. $m_C(h \\times h) = hm_B$ and we define $e_C:1 \\to C$ to be $he_B$.\\\\\nAssociativity of $m$ asserts the equality of $C \\times C \\times C \\stackrel[m(m \\times 1)]{m(1 \\times m)}{\\rightrightarrows} C$, but these have equal composites $b^3 \\stackrel{h^3}{\\twoheadrightarrow} C^3$.\\\\\nSimilarly for the unit laws.\\\\\nSo $C$ is a monoid and $h$ is a monoid homomorphism, and it's a coequalizer in $\\mathbf{Mon}(\\mathcal{C})$.\n\n(ii) Let $MA = \\sum_{n \\in \\N} A^n$ (where $A^0 = 1, A^{n+1} = (A \\times A^n)$).\\\\\nThen $MA \\times MA \\cong \\sum_{p,q \\in \\N} A^p \\times A^q$ since $B \\times (-)$ preserves coproducts.\\\\\nDefine $m:MA \\times MA \\to MA$ by \n\n\\begin{tikzcd}\nA^p \\times A^q \\arrow[r,\"\\simeq\"] \\arrow[d,\"\\nu_{p,q}\"] & A^{p+q} \\arrow[d,\"\\nu_{p+q}\"]\\\\\nMA \\times MA \\arrow[r,\"m\"] & MA\n\\end{tikzcd}\n\nfor all $p,q$. Set $e = \\nu_0:1 \\to MA$. $m$ is associative, since the two isomorphisms \n\n\\begin{tikzcd}\nA^p \\times (A^q \\times A^r) \\arrow[r] \\arrow[d,\"\\simeq\"] & A^{p+q+r}\\\\\n(A^p \\times A^q) \\times A^r \\arrow[ur] &\n\\end{tikzcd}\n\nare equal.\\\\\nWe take $\\eta: A \\to MA$ to be $A \\cong A \\times 1 \\xrightarrow{\\nu_1} MA$. If $B$ is the underlying object of a monoid, we get well-defined multiplications $B^p \\to B$ for all $p$, and hence a map $MB \\xrightarrow{\\varepsilon_B} B$, ... (some more verifications)\n\n\\subsection{Question 4}\n(i) It is sufficient to show that\n$$colim_{\\mathcal{C}}(F \\times \\triangle A) \\to colim_{\\mathcal{C}} F \\times A$$\nis iso. But $A \\cong \\sum_{a \\in A} 1$, so $\\triangle A \\cong \\sum_{a \\in A} 1$ in $[\\mathcal{C},\\mathbf{Set}]$. So $F \\times \\triangle A \\cong \\sum_{a \\in A} F$ since $[\\mathcal{C},\\mathbf{Set}]$ is cc.\\\\\nSo $colim_{\\mathcal{C}}(F \\times \\triangle A) \\cong \\sum_{a \\in A} colim_{\\mathcal{C}} (F) \\cong colim_{\\mathcal{C}} (F) \\times A$.\n\n(ii) We have \n\\begin{equation*}\n\\begin{aligned}\n\\mathcal{C}(-,B)^{\\mathcal{C}(-,A)} (C) &\\cong [\\mathcal{C}^{op}, \\mathbf{Set}](\\mathcal{C}(-,C) \\times \\mathcal{C}(-,A),\\mathcal{C}(-,B))\\\\\n&\\cong [\\mathcal{C}^{op},\\mathbf{Set}](\\mathcal{C}(-,C \\times A),\\mathcal{C}(-,B))\\\\\n&\\cong \\mathcal{C}(C \\times A,B) \\text{ by Yoneda}\\\\\n&\\cong \\mathcal{C}(C,B^A)\\\\\n&=\\mathcal{C}(-,B^A)(C)\n\\end{aligned}\n\\end{equation*}\n\nSo $\\mathcal{C}(-,B)^{\\mathcal{C}(-,A)} \\cong \\mathcal{C}(-,B^A)$.\n\n\\subsection{Question 5}\n(i) Suppose $(-) \\times (A \\times B) \\cong (- \\times A) \\times B$, we have $(-)^{A \\times} \\cong ((-)^B)^A$. So $A,B$ tiny $\\implies A \\times B$ tiny, and $(-)^1 \\cong 1_\\mathcal{C}$, so $1$ is tiny.\n\n(ii) Given $F:\\mathcal{C}^{op} \\to \\mathbf{Set}$\n\\begin{equation*}\n\\begin{aligned}\nF^{\\mathcal{C}(-,A)}(B) &\\cong [\\mathcal{C}^{op},\\mathbf{Set}](\\mathcal{C}(-,B) \\times \\mathcal{C}(-,A),F)\\\\\n&\\cong [\\mathcal{C}^{op},\\mathbf{Set}](\\mathcal{C}(-,B \\times A), F) \\cong F(B \\times A)\n\\end{aligned}\n\\end{equation*}\nSo $F^{\\mathcal{C}(-,A)} \\cong F(- \\times A)$, so $(-)^{\\mathcal{C}(-,A)} \\cong (- \\times A)^*: [\\mathcal{C}^{op},\\mathbf{Set}] \\to [\\mathcal{C}^{op},\\mathbf{Set}]$.\\\\\nBy Sheet 2 q9(ii) we know it has a right adjoint.\n\n(iii) First show $f$ is irreducible projective iff $[\\mathcal{C}^{op},\\mathbf{Set}](F,-)$ preserves both coproducts and epimorphisms (in fact, all colimits, but those are enough).\\\\\n$[\\mathcal{C}^{op},\\mathbf{Set}](F,-)$ preserves coproducts iff every $F \\to \\sum_{i \\in I} G$ factors through just one $G_j \\xrightarrow{\\nu_j} \\sum_{i \\in I} G_i$.\\\\\nIf this holds and $f$ is projective, and we're given $\\sum_{i \\in I} G_i \\stackrel{e}{\\twoheadrightarrow} F$, we have a splitting which factors through some $\\nu_j$, so $e\\nu_j$ is epic.\n\nConversely, if $f$ is irreducible, and we're given $F \\xrightarrow{f} \\sum_{i \\in I} G_i$, form the pullbacks\n\n\\begin{tikzcd}\nF_j \\arrow[r] \\arrow[d,tail] & G_j \\arrow[d,tail,\"\\nu_j\"]\\\\\nF \\arrow[r,\"f\"] & \\sum_{i \\in I} G_i\n\\end{tikzcd}\n\nThen $\\sum_{j \\in J} F_j \\to F$ is iso, so some $F_j \\to F$ is iso, so $f$ factors through some $\\nu_j$.\n\nBut $[\\mathcal{C}^{op},\\mathbf{Set}](F,-)$ is the composite\n\n\\begin{tikzcd}\n{[\\mathcal{C}^{op},\\mathbf{Set}]} \\arrow[r,\"(-)^F\"] & {[\\mathcal{C}^{op},\\mathbf{Set}]} \\arrow[rr,\"{[\\mathcal{C}^{op},\\mathbf{Set}](1,-)}\"] & & \\mathbf{Set}\n\\end{tikzcd}\n\nand $F$ tiny, $1$ representable imply both factors preserve coproducts and epimorphisms.\n\nNow we know\n\n$F$ representable $\\implies$($\\mathcal{C}$ has products) $F$ tiny $\\implies$ ($\\mathcal{C}$ has terminal objects) $F$ irreducible projective $\\implies$ ($\\mathcal{C}$ Cauchy complete) $F$ representable.\n\nHence if $\\mathcal{C}$ has all the three properties, then $[\\mathcal{C}^{op},\\mathbf{Set}]_t \\simeq \\{$ representable functors $\\mathcal{C}^{op} \\to \\mathbf{Set}\\} \\simeq \\mathcal{C}$.\n\nNote that $A^{(-)}$ is a functor $\\mathcal{E}^{op} \\to \\mathcal{E}$ in any ccc $\\mathcal{E}$: given $B_1 \\xrightarrow{g} B_2$, we get $A^{B_2} \\to A^{B_1}$ as the transpose of $A^{B_2} \\times B_1 \\xrightarrow{1 \\times g} A^{B_2} \\times B_2 \\xrightarrow{ev} A$.\n\nSimilarly, if we write $(-)_B$ for the right adjoint of $(-)^B$, $A_{(-)}$ becomes a functor $\\mathcal{E}_t \\to \\mathcal{E}$. So if $B$ is tiny and $e:B \\to B$ is idempotent with splitting $B \\to x \\to B$, we get $(-)^C$ as the splitting of $(-)^B \\to (-)^B$, and $(-)_C$ as the splitting of $(-)_B \\to (-)_B$.\n\n\\subsection{Question 6}\n Suppose given \n\\begin{tikzcd}\nG \\arrow[d,\"\\alpha\"]\\\\\nF\n\\end{tikzcd}\nin $[\\mathcal{C},\\mathbf{Set}]/F$. Define $\\Phi(G):\\mathcal{F} \\to \\mathbf{Set}$ by $\\Phi(G)(A,x) = \\alpha_A^{-1} (x) \\subseteq GA$, and $\\Phi(G)((A,x) \\xrightarrow{f} (B,y)) = Gf|_{\\alpha_A^{-1}(x)}$.\n\n$\\Phi$ is functorial: given \n\n\\begin{tikzcd}\nG \\arrow[rr, \"\\gamma\"] \\arrow[rd, \"\\alpha\"'] & & H \\arrow[ld, \"\\beta\"]\\\\\n& F &\n\\end{tikzcd}\n, $\\Phi(r)_(A,x) = \\gamma_A |_{\\alpha_A^{-1}(x)}$.\n\nGiven $H:\\mathcal{F} \\to \\mathbf{Set}$, define $\\Psi(H):\\mathcal{C} \\to \\mathbf{Set}$ by $\\Psi(H)(A) = \\coprod_{x \\in FA} H(A,x)$ equipped with $\\pi:\\coprod_{x \\in FA} H(A,x) \\to FA$.\\\\\nSimilarly show $\\Psi$ is a functor $[\\mathcal{F},\\mathbf{Set}] \\to [\\mathcal{C},\\mathbf{Set}]/F$, and $\\Phi\\Psi,\\Psi\\Phi$ are both isomorphic to identity.\n\n\\subsection{Question 7}\n(i) Suppose given $\\Omega \\stackrel{f}{\\rightarrowtail} \\Omega$ in a topos. Form the pullback\n\\begin{tikzcd}\nU \\arrow[r,tail] \\arrow[d,tail,\"g\"] & 1 \\arrow[d,tail,\"\\top\"]\\\\\n\\Omega \\arrow[r,tail,\"f\"] & \\Omega\n\\end{tikzcd}\nand\n\\begin{tikzcd}\nV \\arrow[r] \\arrow[d,tail] & 1 \\arrow[d,\"\\top\"]\\\\\nU \\arrow[r,\"g\"] & \\Omega\n\\end{tikzcd}\n, and consider\n\n\\begin{tikzcd}\nV \\arrow[r,\"1\"] \\arrow[d] & V \\arrow[r] \\arrow[d] & U \\arrow[r,\"u\"] \\arrow[d,\"g\"] & 1 \\arrow[d,\"\\top\"]\\\\\nU \\arrow[r,\"u\"] & 1 \\arrow[r,\"\\top\"] &\\Omega \\arrow[r,\"f\"] & \\Omega\n\\end{tikzcd}\n\nThis is a pullback, so $f\\top u = g$ and hence $ff\\top u = fg = \\top u$.\n\nNow \n\\begin{tikzcd}\nU \\arrow[r] \\arrow[d,\"g\",tail] & U \\arrow[r] \\arrow[d,\"g\",tail] & 1 \\arrow[d,\"\\top\"]\\\\\n\\Omega \\arrow[r,\"ff\"] & \\Omega \\arrow[r,\"f\"] & \\Omega\n\\end{tikzcd}\n\n($ffg=f\\top u = g$). The left square is a pullback since $ff$ is monic, so $fff=f$, so $ff=1_\\Omega$.\n\n(ii) In $[\\N, \\mathbf{Set}]$, $\\Omega$ looks like\n\n\\begin{tikzcd}\n\\Omega(0) \\arrow[r] & \\Omega(1) \\arrow[r] & \\Omega(2) \\arrow[r] & ...\\\\\n0 \\arrow[r] & 1 \\arrow[r] & 2 & \\\\\n1 \\arrow[ru] & 2 \\arrow[ru] & 3 & \\\\\n2 \\arrow[ru] & 3 \\arrow[ru] & &\\\\\n3 \\arrow[ru] & & &\\\\\n... & & &\\\\\n\\phi \\arrow[r] & \\phi \\arrow[r] & \\phi \\arrow[r] & ...\n\\end{tikzcd}\n\nThe map $n \\to \\max\\{n-1,m\\}$, $\\phi \\to \\phi$, $\\Omega(m) \\to \\Omega(m)$ defines an epimorphism $\\Omega \\twoheadrightarrow \\Omega$ which isn't mono.\n\n\\subsection{Question 8}\n\nGiven a $G$-set $A$, consider $A_C = \\{a \\in A | stab_G (a)$ is open $\\}$.\n\nThis is a union of $G$-orbits, since $\\exists$ is closed under conjugation, and so a continuous $G$-set.\n\nGiven $f:B \\to A$ in $[G,\\mathbf{Set}]$, we have $stab_G(b) \\subseteq stab_G(f(b))$ for any $b \\in B$. So if $B$ is continuous then $f$ takes values in $A_C$.\n\nGiven $A$ and $B$, $stab_G((a,b)) = stab_G(a) \\cap stab_G(b)$, so $A,B$ continuous $\\to$ $A \\times B$ continuous; and any sub-$G$-set of a continuous $G$-set is continuous, so $\\mathbf{Cont}(G)$ is closed under equalizers.\n\nGiven continuous $G$-sets $A,B,C$, morphisms $C \\times A \\to B$ in $\\mathbf{Cont}(G)$ corresponds to morphisms $C \\to B^A$ in $[G,\\mathbf{Set}]$, and hence to morphisms $C \\to (B^A)_C$ in $\\mathbf{Cont}(G)$.\n\nThe $\\Omega$ of $[t,\\mathbf{Set}]$ has continuous $G$-action, and it is a subobject classifier in $\\mathbf{Cont}(G)$.\n\nIf $A,B$ are uniform continuous $G$-sets, then $A \\times B$ and $B^A$ are both aced on trivially by $H \\cap K$, where $H$ acts trivially on $A$ and $K$ on $B$.\n\nAlso, arbitrary subobjects of uniform continuous $G$-sets are uniform continuous, and $\\Omega$ is uniform continuous.\n\n$Unif(\\Z)$ consists of $\\Z$-sets acted on trivially by $n\\Z$ for some $n$.\\\\\nLet $c_n$ be a single $\\Z$-orbit of size $n$.\\\\\nFor any $n$, there exists a family of morphisms $\\{C_m \\to C_n \\sqcup 1 | m \\in \\N\\}$ whose $n$th member is injective, so if $\\sum_{m \\in \\N} C_m$ existed, each $\\nu_n:C_n \\to \\sum C_n$ need to be injective. Hence $\\sum_{m \\in \\N} C_m$ can't be uniform continuous.\n\n\\subsection{Question 9}\n(i) $\\implies$ (ii),(iii),(iv) since $\\mathcal{E}/B \\xrightarrow{\\Sigma_B} \\mathcal{E}$ is faithful and preserves connected limits (somewhere on sheet 2).\\\\\n(iv) $\\implies$ (iii) by Sheet 2 q5(iii).\\\\\n(iii) $\\implies$ (ii) We have bijections $Sub_{\\mathcal{F}}(A) \\cong \\mathcal{F}(A,\\Omega_F) \\cong \\mathcal{E}(LA,\\Omega_\\mathcal{E}) \\cong Sub_\\mathcal{E}(LA)$, since \n\n\\begin{tikzcd}\nLA' \\arrow[r] \\arrow[tail,d] & LF1 \\arrow[r,\"\\varepsilon\"] \\arrow[d,\"LF(T)\"] & 1 \\arrow[d,\"\\top\"]\\\\\nLA \\arrow[r] & LF\\Omega \\arrow[r,\"\\varepsilon\"] & \\Omega\n\\end{tikzcd}\n\ncommutes, $LA'$ is contained in the subobject corresponding to $A'$ under this bijection.\\\\\nSo $A' \\rightarrowtail A$ proper $\\implies$ $LA' \\rightarrowtail LA$ proper.\n\nHence if $A \\stackrel[g]{f}{\\rightrightarrows} B$ satisfies $f \\neq g$, we get $Lf \\neq Lg$.\n\n(ii) $\\implies$ (i) We can factor $L$ as $\\mathcal{F} \\xrightarrow{\\hat{L}} \\mathcal{E}/L1 \\xrightarrow{\\Sigma_{L1}} \\mathcal{E}$.\\\\\n$\\hat{L}$ has a right adjoint $\\hat{F}$ sending \n\\begin{tikzcd}\nA \\arrow[d,\"g\"]\\\\\nL1\n\\end{tikzcd}\nto the pullback\n\\begin{tikzcd}\n\\hat{F}g \\arrow[r] \\arrow[d] & FA \\arrow[d,\"Fg\"]\\\\\n1 \\arrow[r,\"\\eta_1\"] & FL1\n\\end{tikzcd}\n\n$\\hat{F}$ is the composite\n\\begin{tikzcd}\n\\mathcal{E}/L1 \\arrow[r,\"F/L1\"] & \\mathcal{F}/FL1 \\arrow[r,\"\\eta_1^*\"] & \\mathcal{F}\n\\end{tikzcd}\n, so it's logical.\\\\\n$\\hat{L}$ is faithful since $L$ is, and it preserves $1$.\\\\\nSo by Frobenius reciprocity,\n\n\\begin{tikzcd}\n\\hat{L}(\\hat{F}A \\times 1) \\arrow[r] \\arrow[d,\"\\cong\"] & A \\times \\hat{L} 1 \\arrow[d,\"\\cong\"]\\\\\n\\hat{L}\\hat{F} A \\arrow[r,\"\\varepsilon_A\"] & A\n\\end{tikzcd}\nis iso, i.e. the counit of $(\\hat{L}+\\hat{F})$ is iso.\\\\\n$\\hat{L}$ reflects isos since $\\mathcal{F}$ is balanced, and \n\\begin{tikzcd}\n\\hat{L} \\arrow[r,\"\\hat{L}\\eta\"] \\arrow[rd,\"1\"'] & \\hat{L}\\hat{F}\\hat{L} \\arrow[d,\"\\varepsilon_{\\hat{L}}\"]\\\\\n& L\n\\end{tikzcd}\ncommutes, so $\\hat{L} \\eta$ is iso, so $\\eta$ is iso.\n\n\\subsection{Question 10}\nLecturer does not have time to go through this, but it's not that difficult, and it's quite an important result in sheaf theory.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "da8fc9d47595b2e78b3ed0477d6bc2108c4c3ebb", "size": 207599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Category Theory.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/Category Theory.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/Category Theory.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": 72.8162048404, "max_line_length": 798, "alphanum_fraction": 0.6306533268, "num_tokens": 74277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6837211108300222}}
{"text": "\\chapter{Methods and testing}\n\nSo far we've written programs that have only one method (\\java{main}).\nIn this chapter, we'll show you how to organize programs into multiple methods.\nWe'll also learn how to trace the order in which a program runs.\nFinally, we'll discuss strategies for incrementally developing and testing your code.\n\n%At a conceptual level, a method represents a mathematical {\\em function} or a general {\\em procedure}.\n%Regardless whether they return a value or not, methods enable you to break down a complex program into smaller units of code.\n\n\n\\section{Math methods}\n\n%In the next two sections, we'll take a break from conditions and logic and discuss other areas of mathematics in Java.\n\n\\index{Math class}\n\\index{class!Math}\n\nThe Java library includes a \\java{Math} class that provides common mathematical operations.\n\\java{Math} is in the \\java{java.lang} package, so you don't have to import it.\n\n%slr: 8-14-19\n%\\begin{code}\n%double root = Math.sqrt(17.0);\n%double angle = 1.5;\n%double height = Math.sin(angle);\n%\\end{code}\n% height = 130 + 11 * num_lines\n\\begin{trinket} [210] {UsingMath.java}\npublic class UsingMath {\n\n    public static void main(String[] args) {\n       double root = Math.sqrt(17.0);\n       double angle = Math.PI; //radians\n       double y = Math.sin(angle);\n       System.out.printf(\"The square root of 17 is %f.\\n\",root);\n       System.out.printf(\"sin(pi) is %f.\", y);\n    }\n}\n\\end{trinket}\n%slr:  end 8-14-19\n\nThe first line sets \\java{root} to the square root of 17.\n%slr: change to pi\nThe third line finds the sine of $\\pi$ (the value of \\java{angle}).\n\n\\index{degrees}\n\\index{radians}\n\\index{pi}\n\nValues for the trigonometric functions -- \\java{sin}, \\java{cos}, and \\java{tan} -- must be in {\\em radians}.\nTo convert from degrees to radians, you can divide by 180 and multiply by $\\pi$.\nConveniently, the \\java{Math} class provides a constant double named \\java{PI} that contains an approximation of $\\pi$:\n\n\\begin{code}\ndouble degrees = 90;\ndouble angle = degrees / 180.0 * Math.PI;\n\\end{code}\n\nNotice that \\java{PI} is in capital letters.\nJava does not recognize \\java{Pi}, \\java{pi}, or \\java{pie}.\nAlso, \\java{PI} is the name of a variable, not a method, so it doesn't have parentheses.\nThe same is true for the constant \\java{Math.E}, which approximates Euler's number.\n\nConverting to and from radians is a common operation, so the \\java{Math} class provides methods that do that for you.\n\n\\begin{code}\ndouble radians = Math.toRadians(180.0);\ndouble degrees = Math.toDegrees(Math.PI);\n\\end{code}\n\n\\index{long}\n\\index{type!long}\n\nAnother useful method is \\java{round}, which rounds a floating-point value to the nearest integer and returns a \\java{long}.\nThe following result is 63 (rounded up from 62.8319).\n\n\\begin{code}\nlong x = Math.round(Math.PI * 20.0);\n\\end{code}\n\nA \\java{long} is like an \\java{int}, but bigger.\nMore specifically, an \\java{int} uses 32 bits of memory; the largest value it can hold is $2^{31}-1$, which is about 2 billion.\nA \\java{long} uses 64 bits, so the largest value is $2^{63}-1$, which is about 9 quintillion.\n\nTake a minute to read the documentation for these and other methods in the \\java{Math} class.\nThe easiest way to find documentation for Java classes is to do a web search for ``Java'' and the name of the class.\n\n\n\\section{Composition}\n\n\\index{expression}\n\\index{argument}\n\nYou have probably learned to evaluate simple expressions like $\\sin(\\pi/2)$ and $\\log(1/x)$.\nFirst, you evaluate the expression in parentheses, which is called the {\\bf argument} of the function.\nThen you can evaluate the function itself, either by hand or by punching it into a calculator.\n\nThis process can be applied repeatedly to evaluate more complex expressions like $\\log(1/\\sin(\\pi/2))$.\nFirst we evaluate the argument of the innermost function ($\\pi/2 = 1.57...$), then evaluate the function itself ($\\sin(1.57...) = 1.0$), and so on.\n\n\\index{composition}\n\\index{expression}\n\nJust as with mathematical functions, Java methods can be {\\bf composed} to solve complex problems.\nThat means you can use one method as part of another.\nIn fact, you can use any expression as an argument to a method, as long as the resulting value has the correct type:\n\n\\begin{code}\ndouble x = Math.cos(angle + Math.PI / 2.0);\n\\end{code}\n\nThis statement divides \\java{Math.PI} by two, adds the result to \\java{angle}, and computes the cosine of the sum.\nYou can also take the result of one method and pass it as an argument to another:\n\n\\begin{code}\ndouble x = Math.exp(Math.log(10.0));\n\\end{code}\n\nIn Java, the \\java{log} method always uses base $e$.\nSo this statement finds the log base $e$ of 10, and then raises $e$ to that power.\nThe result gets assigned to \\java{x}.\n\nSome math methods take more than one argument.\nFor example, \\java{Math.pow} takes two arguments and raises the first to the power of the second.\nThis line computes $2^{10}$ and assigns the value \\java{1024.0} to the variable \\java{x}:\n\n\\begin{code}\ndouble x = Math.pow(2.0, 10.0);\n\\end{code}\n\nWhen using \\java{Math} methods, beginners often forget the word \\java{Math}.\nFor example, if you just write \\java{x = pow(2.0, 10.0)}, you will get a compiler error:\n\n\\begin{stdout}\nFile: Test.java  [line: 5]\nError: cannot find symbol\n  symbol:   method pow(double,double)\n  location: class Test\n\\end{stdout}\n\nThe message ``cannot find symbol'' is confusing, but the last two lines provide a useful hint.\nThe compiler is looking for a method named \\java{pow} in the file \\java{Test.java} (the file for this example).\nIf you don't specify a class name when referring to a method, the compiler looks in the current class by default.\n\n%slr: 9-14-19\nHere is an example progam:\n% height = 130 + 11 * num_lines\n\\begin{trinket} [210] {MethodComposition.java}\npublic class MethodComposition {\n\n    public static void main(String[] args) {\n       double angle = Math.PI; //radians\n       double x = Math.cos(angle + Math.PI / 2.0);\n       System.out.printf(\"cos 3 pi / 2 is %f.\\n\",x);\n       System.out.printf(\"e^(ln(10)) is %f.\", Math.exp(Math.log(10.0)));\n    }\n}\n\\end{trinket}\n\n\\textbf{Section Exercises}\n\\begin{enumerate}\n\\item Mess around with the program in the trinket.  Try some other methods from the \\java{Math} package, for example \\java{Math.pow}.\n\\end{enumerate}\n%slr: end 8-14-19\n\n\n\\section{Defining new methods}\n\\label{adding_methods}\n\n\\index{method!declaration}\n\n%You have probably guessed by now that you can define more than one method in a class.\n\nSome methods perform a computation and return a result.\nFor example, \\java{Math.sqrt(25)} returns the value \\java{5.0}.\nOther methods (including \\java{main}) carry out a sequence of actions, without returning a result.\nJava uses the keyword \\java{void} to define such methods.\nHere's a simple example:\n\n\\index{NewLine.java}\n\n\\begin{trinket}[240]{NewLine.java}\npublic class NewLine {\n\n    public static void newLine() {\n        System.out.println();\n    }\n\n    public static void main(String[] args) {\n        System.out.println(\"First line.\");\n        newLine(); //method invocation or call\n        System.out.println(\"Second line.\");\n    }\n}\n\\end{trinket}\n\n\\index{main}\n\\index{case-sensitive}\n\nThe name of the class is \\java{NewLine}.\nBy convention, class names begin with a capital letter.\n\\java{NewLine} contains two methods, \\java{newLine} and \\java{main}.\nRemember that Java is case-sensitive, so \\java{NewLine} and \\java{newLine} are not the same.\n\n\\index{camel case}\n\nMethod names should begin with a lowercase letter and use ``camel case'', which is a cute name for \\java{jammingWordsTogetherLikeThis}.\nYou can use any name you want for methods, except \\java{main} or any of the Java keywords.\n\n\\index{public}\n\\index{invoke}\n\\index{void}\n\\index{type!void}\n\n\\java{newLine} and \\java{main} are \\java{public}, which means they can be {\\bf invoked} (or called) from other classes.\n%They are both \\java{static}, but we won't yet explain what that means.\nAnd they are both \\java{void}, which means that they don't return a result (unlike the \\java{Math} methods, for example).\n\nThe output of this program is:\n\n\\begin{stdout}\nFirst line.\n\nSecond line.\n\\end{stdout}\n\nNotice the extra space between the lines.\nIf we wanted more space between them, we could invoke the same method repeatedly.\nOr we could write yet another method (named \\java{threeLine}) that displays three blank lines.\n%Pulling together the code from the previous section, the complete program looks like this:\n\nIn the following program, \\java{main} invokes \\java{threeLine}, and \\java{threeLine} invokes \\java{newLine} three times.\n%Since \\java{newLine} has no parameters, it requires no arguments, as shown when it is invoked in \\java{main}.\nBecause \\java{newLine} is in the same class as \\java{threeLine}, we don't have to specify the class name like \\java{NewLine.newLine()}.\n\n\\begin{trinket} [320]{NewLine.java}\npublic class NewLine {\n\n    public static void newLine() {\n        System.out.println();\n    }\n\n    public static void threeLine() {\n        newLine();\n        newLine();\n        newLine();\n    }\n\n    public static void main(String[] args) {\n        System.out.println(\"First line.\");\n        threeLine();\n        System.out.println(\"Second line.\");\n    }\n}\n\\end{trinket}\n\n\n\\section{Flow of execution}\n\n\\index{flow of execution}\n\nWhen you look at a class definition that contains several methods, it is tempting to read it from top to bottom.\nBut that is {\\em not} the {\\bf flow of execution}, or the order the program actually runs.\nThe \\java{NewLine} program runs methods in the opposite order than they are listed.\n\nPrograms always begin at the first statement of \\java{main}, regardless of where it is in the source file.\nStatements are executed one at a time, in order, until you reach a method invocation, which you can think of as a detour.\nInstead of going to the next statement, you jump to the first line of the invoked method, execute all the statements there, and then come back and pick up exactly where you left off.\n\nThat sounds simple enough, but remember that one method can invoke another one.\nIn the middle of \\java{main}, the previous example goes off to execute the statements in \\java{threeLine}.\nWhile in \\java{threeLine}, it goes off to execute \\java{newLine}.\nThen \\java{newLine} invokes \\java{println}, which causes yet another detour.\n\nFortunately, Java is good at keeping track of which methods are running.\nSo when \\java{println} completes, it picks up where it left off in \\java{newLine}; when \\java{newLine} completes, it goes back to \\java{threeLine}; and when \\java{threeLine} completes, it gets back to \\java{main}.\n\n%In summary, when you read a program, don't read from top to bottom.\n%Instead, follow the flow of execution.\n\n%Technically, the program does not terminate at the end of \\java{main}.\n%Instead, execution picks up where it left off in the program that invoked \\java{main}, which is the Java interpreter.\n%The interpreter takes care of things like deleting windows and general cleanup, and {\\em then} the program terminates.\n\nBeginners often wonder why it's worth the trouble to write other methods, when they could just do everything in \\java{main}.\nThe \\java{NewLine} example demonstrates a few reasons:\n\n\\begin{itemize}\n\n\\item Creating a new method allows you to {\\em name a block of statements}, which makes the code easier to read and understand.\n%Methods simplify a program by hiding complex computations behind a single statement, and by using English words in place of arcane code.\n%Which is clearer, \\java{newLine} or \\java{System.out.println()}?\n\n\\item Introducing new methods can {\\em make the program shorter} by eliminating repetitive code.\nFor example, to display nine consecutive newlines, you could invoke \\java{threeLine} three times.\n\n\\item A common problem-solving technique is to {\\em break problems down} into sub-problems.\nMethods allow you to focus on each sub-problem in isolation, and then compose them into a complete solution.\n\n\\end{itemize}\n\nPerhaps most importantly, organizing your code into multiple methods allows you to test individual parts of your program separately.\nIt's easier to get a complex program working if you know that each method works correctly.\n\n%slr:  8-14-19\n\\textbf{Section Exercises}\n\\begin{enumerate}\n\\item In the second version of NewLine, does the order in which the methods appear matter?  Try changing the order around and see what happens.\n\\item Change the program to produce nine blank lines by invoking (i.e. calling) the method \\java{threeLine()} three times.\n\\end{enumerate}\n%slr: end 8-14-19\n\n\n\\section{Parameters and arguments}\n\nSome of the methods we have used require arguments, which are the values you provide in parentheses when you invoke the method.\n\nFor example, the \\java{Math.sin} method takes a \\java{double} argument.\nTo find the sine of a number, you have to provide the number: \\java{Math.sin(0.0)}.\nSimilarly, the \\java{System.out.println} method takes a \\java{String} argument.\nTo display a message, you have to provide the message: \\java{System.out.println(\"Hello\")}.\n\n\\index{parameter}\n\\index{argument}\n\nWhen you invoke a method, you provide the arguments.\nWhen you define a method, you declare the {\\bf parameters}, which are variables that indicate what arguments are required.\nThe following class shows an example:\n\n\\index{PrintTwice.java}\n\n\\begin{trinket}[255]{PrintTwice.java}\npublic class PrintTwice {\n\n    //printTwice declares one paramenter\n    public static void printTwice(String s) {\n        System.out.println(s);\n        System.out.println(s);\n    }\n\n    public static void main(String[] args) {\n    \t//the call to printTwice provides a String argument\n        printTwice(\"Don't make me say this twice!\");\n    }\n}\n\\end{trinket}\n\nThe \\java{printTwice} method has a parameter named \\java{s} with type \\java{String}.\nWhen you invoke \\java{printTwice}, you have to provide an argument with type \\java{String}.\n\n%\\java{main} has a single parameter, called \\java{args}, which has type \\java{String[]}.\n%That means that whoever invokes \\java{main} must provide an array of strings (we'll get to arrays in a later chapter).\n\nBefore the method executes, the argument gets assigned to the parameter.\nIn this example, the argument \\java{\"Don't make me say this twice!\"} gets assigned to the parameter \\java{s}.\n\n\\index{parameter passing}\n\nThis process is called {\\bf parameter passing} because the value gets passed from outside the method to the inside.\nAn argument can be any kind of expression, so if you have a \\java{String} variable, you can use its value as an argument:\n\n\\begin{code}\nString message = \"Never say never.\";\nprintTwice(message);\n\\end{code}\n\nThe value you provide as an argument must have the same (or compatible) type as the parameter.\nFor example, if you try:\n\n\\begin{code}\nprintTwice(17);  // syntax error\n\\end{code}\n\nYou will get an error message like this:\n\n\\begin{stdout}\nFile: Test.java  [line: 10]\nError: method printTwice in class Test cannot be applied\n       to given types;\n  required: java.lang.String\n  found: int\n  reason: actual argument int cannot be converted to\n          java.lang.String by method invocation conversion\n\\end{stdout}\n\nSometimes Java can convert an argument from one type to another automatically.\nFor example, \\java{Math.sqrt} requires a \\java{double}, but if you invoke \\java{Math.sqrt(25)}, the integer value \\java{25} is automatically converted to the floating-point value \\java{25.0}.\nBut in the case of \\java{printTwice}, Java can't (or won't) convert the integer \\java{17} to a \\java{String}.\n\n\\index{local variable}\n\\index{variable!local}\n\nParameters and other variables only exist inside their own methods.\nInside \\java{main}, there is no such thing as \\java{s}.\nIf you try to use it there, you'll get a compiler error.\nSimilarly, inside \\java{printTwice} there is no such thing as \\java{message}.\nThat variable belongs to \\java{main}.\nBecause variables only exist inside the methods where they are defined, they are often called {\\bf local variables} and are said to have {\\bf local scope}.\n\n\n%\\section{Multiple parameters}\n\n\\index{parameter!multiple}\n\\index{method!parameters}\n\nHere is an example of a method that takes two parameters:\n\n\\begin{code}\npublic static void printTime(int hour, int minute) {\n    System.out.print(hour);\n    System.out.print(\":\");\n    System.out.println(minute);\n}\n\\end{code}\n\nIn the parameter list, it may be tempting to write:\n\n\\begin{code}\npublic static void printTime(int hour, minute) {  // error\n\\end{code}\n\nBut that format (without the second \\java{int}) is only allowed for local variables.\nFor parameters, you need to declare the type of each variable separately.\n\nTo invoke this method, we have to provide two integers as arguments:\n\n\\begin{code}\nint hour = 11;\nint minute = 59;\nprintTime(hour, minute);\n\\end{code}\n\nBeginners sometimes make the mistake of ``declaring'' the arguments:\n\n\\begin{code}\nint hour = 11;\nint minute = 59;\nprintTime(int hour, int minute);  // syntax error\n\\end{code}\n\nThat's a syntax error, because the compiler sees \\java{int hour} and \\java{int minute} as variable declarations, not expressions.\nYou wouldn't declare the types of the arguments if they were simply integers:\n\n\\begin{code}\nprintTime(int 11, int 59);  // syntax error\n\\end{code}\n\nPulling together the code fragments, here is the complete program:\n\n\\index{PrintTime.java}\n\n\\begin{trinket}[270]{PrintTime.java}\npublic class PrintTime {\n\n    public static void printTime(int hour, int minute) {\n        System.out.print(hour);\n        System.out.print(\":\");\n        System.out.println(minute);\n    }\n\n    public static void main(String[] args) {\n        int hour = 11;\n        int minute = 59;\n        printTime(hour, minute);\n    }\n}\n\\end{trinket}\n\n%slr:  8-14-19\n\\textbf{Section Exercises}\n\\begin{enumerate}\n\\item Try calling the method \\java{printTime()} more than once with different arguments.\n\\item Call \\java{printTime()} with literal arguments (i.e. arguments that are constants).\n\\item Call \\java{printTime()} passing as arguments the expressions \\java{hour + 3} and \\java{minute - 30}.\n\\end{enumerate}\n%slr: end 8-14-19\n\n\\section{Stack diagrams}\n\\label{stack}\n\n\\java{printTime} has two parameters, named \\java{hour} and \\java{minute}.\nAnd \\java{main} has two variables, also named \\java{hour} and \\java{minute}.\nAlthough they have the same names, these variables are not the same.\nThe \\java{hour} in \\java{printTime} and the \\java{hour} in \\java{main} refer to different memory locations, and they can have different values.\nFor example, you could invoke \\java{printTime} like this:\n\n\\begin{code}\nint hour = 11;\nint minute = 59;\nprintTime(hour + 1, 0);\n\\end{code}\n\nBefore the method is invoked, Java evaluates the arguments; in this example, the results are \\java{12} and \\java{0}.\nThen it assigns those values to the parameters.\nInside \\java{printTime}, the value of \\java{hour} is \\java{12}, not \\java{11}, and the value of \\java{minute} is \\java{0}, not \\java{59}.\nFurthermore, if \\java{printTime} modifies one of its parameters, that change has no effect on the variables in \\java{main}.\n\n\\index{stack diagram}\n\\index{diagram!stack}\n\\index{frame}\n\n\nOne way to keep track of everything is to draw a {\\bf stack diagram}, which is a memory diagram (see Section~\\ref{state}) that shows currently running methods.\nFor each method there is a box called a {\\bf frame} that contains the method's parameters and local variables.\nThe name of the method appears outside the frame; the variables and parameters appear inside.\n\n\\begin{figure}[!ht]\n\\begin{center}\n%slr: 12-18-19 original statement: \\includegraphics[height=15em]{figs/stack1.pdf}\n\\includegraphics{figs/stack1.pdf}\n\\caption{Stack diagram for \\java{printTime(hour + 1, 0)}.}\n\\label{fig.stack}\n\\end{center}\n\\end{figure}\n\nAs with memory diagrams, stack diagrams show variables and methods at a particular point in time.\nFigure~\\ref{fig.stack} is a stack diagram at the beginning of the \\java{printTime} method.\nNotice that \\java{main} is on top, because it executed first.\n\n%\\index{scope}\n\n%Stack diagrams help you to visualize the {\\bf scope} of a variable, which is the area of a program where a variable exists.\n\n\\index{Java Tutor}\n\\index{tracing}\n\nStack diagrams are a good mental model for how variables and methods work at run-time.\nLearning to trace the execution of a program on paper (or on a whiteboard) is a useful skill for communicating with other programmers.\n\nThere are educational tools that automatically draw stack diagrams for you.\nFor example, Java Tutor (\\url{http://pythontutor.com/java.html}) allows you to step through an entire program, both forwards and backwards, and see the stack frames and variables at each step.\nIf you haven't already, you should check out the Java examples on that website.\n\n%Or you can use a ``debugger'', like the one that comes with DrJava (see Appendix~\\ref{debugger}).\n%These tools also allow you to visualize the flow of execution.\n\n\n\\section{Return values}\n\n\\index{void}\n\nWhen you invoke a \\java{void} method, the invocation is usually on a line all by itself.\nFor example:\n\n\\begin{code}\nprintTime(hour + 1, 0);\n\\end{code}\n\nOn the other hand, when you invoke a value-returning method, you have to do something with the return value.\n%slr:  8-14-19\n%We usually assign it to a variable or use it as part of an expression, like this:\n%\n%\\begin{code}\n%double error = Math.abs(expect - actual);\n%double height = radius * Math.sin(angle);\n%\\end{code}\nHere is the program we looked at earlier in the chapter which calls methods in the /java{Math} class:\n% height = 130 + 11 * num_lines\n\\begin{trinket} [220] {UsingMath.java}\npublic class UsingMath {\n\n    public static void main(String[] args) {\n       double root = Math.sqrt(17.0);\n       double angle = Math.PI; //radians\n       double y = Math.sin(angle);\n       System.out.printf(\"The square root of 17 is %f.\\n\",root);\n       System.out.printf(\"sin(pi) is %f.\", y);\n    }\n}\n\\end{trinket}\n%slr:  end 8-14-19\n\nHere we see that, for example, the method \\java{Math.sqrt} is a value-returning method and the program has to a assign it to a variable or use it as part of an expression.\n\n\\index{value method}\n\\index{method!value}\n\nCompared to \\java{void} methods, value-returning methods differ in two ways:\n\n\\index{return type}\n\\index{return value}\n\n\\begin{itemize}\n\n\\item They declare the type of the return value (the {\\bf return type});\n\n\\item They use at least one \\java{return} statement to provide a {\\bf return value}.\n\n\\end{itemize}\n\n\nHere's an example from a program named {\\tt Circle.java}.\nThe \\java{calculateArea} method takes a \\java{double} as a parameter and returns the area of a circle with that radius (i.e., $\\pi r^2$).\n\n%slr:  8-14-19\n%\\begin{code}\n%public static double calculateArea(double radius) {\n%    double result = Math.PI * radius * radius;\n%    return result;\n%}\n%\\end{code}\n\n% height = 130 + 11 * num_lines\n\\begin{trinket} [270] {Circle.java}\npublic class Circle {\n\n    public static double calculateArea(double radius) {\n        double result = Math.PI * radius * radius;\n        return result;\n    }\n\n    public static void main(String[] args) {\n       double diameter = 10.0;\n       double area = calculateArea(diameter/2);\n       System.out.printf(\"A circle of radius %f has an area of %f.\", diameter/2, area);\n    }\n}\n\\end{trinket}\n%slr: end 8-14-19\n\nAs usual, this method is \\java{public} and \\java{static}.\nBut in the place where we are used to seeing \\java{void}, we see \\java{double}, which means that the return value from this method is a \\java{double}.\n\n\\index{return}\n\\index{statement!return}\n\nThe last line is a new form of the \\java{return} statement that means, ``return immediately from this method, and use the following expression as the return value.''\nThe expression you provide can be arbitrarily complex, so we could have written this method more concisely:\n\n\\begin{code}\npublic static double calculateArea(double radius) {\n    return Math.PI * radius * radius;\n}\n\\end{code}\n\n\\index{temporary variable}\n\\index{variable!temporary}\n\nOn the other hand, {\\bf temporary variables} like \\java{result} often make debugging easier, especially when you are stepping through code using an interactive debugger (see Appendix~\\ref{debugger}).\n\nFigure~\\ref{fig.param} illustrates how data values flows through the program.\nWhen the \\java{main} method invokes \\java{calculateArea}, the value \\java{5.0} is assigned to the parameter \\java{radius}.\n\\java{calculateArea} then returns the value \\java{78.54}, which is assigned to the variable \\java{area}.\n%Note that you don't ``pass variables'' as arguments and return values -- you copy their values.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/param.pdf}\n\\caption{Passing a parameter and saving the return value.}\n\\label{fig.param}\n\\end{center}\n\\end{figure}\n\nThe type of the expression in the \\java{return} statement must match the return type of the method itself.\nWhen you declare that the return type is \\java{double}, you are making a promise that this method will eventually produce a \\java{double} value.\nIf you try to \\java{return} with no expression, or \\java{return} an expression with the wrong type, the compiler will give an error.\n\n\n\\section{Incremental development}\n\\label{distance}\n\n\\index{incremental development}\n\\index{design process}\n\nPeople often make the mistake of writing a lot of code before they try to compile and run it.\nThen they spend way too much time debugging.\nA better approach is what we call {\\bf incremental development}.\nThe key aspects of incremental development are:\n\n\\begin{itemize}\n\n\\item Start with a working program and make small, incremental changes.\nAt any point, if there is an error, you will know where to look.\n\n\\item Use variables to hold intermediate values so you can check them, either with print statements or by using a debugger.\n\n\\item Once the program is working, you can consolidate multiple statements into compound expressions (but only if it does not make the program more difficult to read).\n\n\\end{itemize}\n\nAs an example, suppose you want to find the distance between two points, given by the coordinates $(x_1, y_1)$ and $(x_2, y_2)$.\nBy the usual definition:\n\n\\[ distance = \\sqrt{(x_2 - x_1)^2 +(y_2 - y_1)^2} \\]\n\nThe first step is to consider what a \\java{distance} method should look like in Java.\nIn other words, what are the inputs (parameters) and what is the output (return value)?\nFor this method, the parameters are the two points, and it is natural to represent them using four \\java{double} values.\n%, although we will see later that there is a \\java{Point} object in Java that we could use.\nThe return value is the distance, which should also have type \\java{double}.\n\n\\index{stub}\n\nAlready we can write an outline for the method, which is sometimes called a {\\bf stub}.\nThe stub includes the method declaration and a \\java{return} statement:\n\n\\begin{code}\npublic static double distance\n        (double x1, double y1, double x2, double y2) {\n    return 0.0;  // stub\n}\n\\end{code}\n\nThe return statement is a placeholder that is only necessary for the program to compile.\nAt this stage the program doesn't do anything useful, but it is good to compile it so we can find any syntax errors before we add more code.\n\n\\index{testing}\n\nIt's usually a good idea to think about testing {\\em before} you develop new methods; doing so can help you figure out how to implement them.\nTo test the method, we can invoke it from \\java{main} using the sample values:\n\n\\begin{code}\ndouble dist = distance(1.0, 2.0, 4.0, 6.0);\n\\end{code}\n\nWith these values, the horizontal distance is 3.0 and the vertical distance is 4.0.\nSo the result should be 5.0, the hypotenuse of a 3-4-5 triangle.\nWhen you are testing a method, it is necessary to know the right answer.\n\nOnce we have compiled the stub, we can start adding code one line at a time.\nAfter each incremental change, we recompile and run the program.\nIf there is an error, we have a good idea where to look: the lines we just added.\n\nThe next step is to find the differences $x_2 - x_1$ and $y_2 - y_1$.\nWe store those values in temporary variables named \\java{dx} and \\java{dy}, so that we can examine them with print statements before proceeding.\nThey should be 3.0 and 4.0.\n\n\\begin{code}\npublic static double distance\n        (double x1, double y1, double x2, double y2) {\n    double dx = x2 - x1;\n    double dy = y2 - y1;\n    System.out.println(\"dx is \" + dx);\n    System.out.println(\"dy is \" + dy);\n    return 0.0;  // stub\n}\n\\end{code}\n\n\\index{scaffolding}\n\nWe will remove the print statements when the method is finished.\nCode like that is called {\\bf scaffolding}, because it is helpful for building the program, but it is not part of the final product.\n\nThe next step is to square \\java{dx} and \\java{dy}.\nWe could use the \\java{Math.pow} method, but it is simpler (and more efficient) to multiply each term by itself.\n\n\\begin{code}\npublic static double distance\n        (double x1, double y1, double x2, double y2) {\n    double dx = x2 - x1;\n    double dy = y2 - y1;\n    double dsquared = dx * dx + dy * dy;\n    System.out.println(\"dsquared is \" + dsquared);\n    return 0.0;  // stub\n}\n\\end{code}\n\nAgain, you should compile and run the program at this stage and check the intermediate value, which should be 25.0.\nFinally, we can use \\java{Math.sqrt} to compute and return the result.\n\n\\begin{code}\npublic static double distance\n        (double x1, double y1, double x2, double y2) {\n    double dx = x2 - x1;\n    double dy = y2 - y1;\n    double dsquared = dx * dx + dy * dy;\n    double result = Math.sqrt(dsquared);\n    return result;\n}\n\\end{code}\n\n%In \\java{main}, we can print and check the value of the result.\n\nAs you gain more experience programming, you might write and debug more than one line at a time.\n%Nevertheless, incremental development can save you a lot of time debugging.\nBut by using incremental development, scaffolding, and testing, your code is more likely to be correct the first time.\n\n\n\\section{Vocabulary}\n\n\\begin{description}\n\n% Note: expanded definition from Chapter 1\n%\\term{method}\n%A named sequence of statements that performs a procedure or function.\n%Methods may or may not take parameters, and may or may not return a value.\n\n%\\term{void}\n%A special return type indicating the method does not return a value.\n\n\\term{argument}\nA value that you provide when you call a method.\nThis value must have the type that the method expects.\n\n\\term{composition}\nThe ability to combine simple expressions and statements into compound expressions and statements.\n\n\\term{invoke}\nTo cause a method to execute.\nAlso known as ``calling'' a method.\n\n\\term{flow of execution}\nThe order in which Java executes methods and statements.\nIt may not necessarily be from top to bottom in the source file.\n\n\\term{parameter}\nA piece of information that a method requires before it can run.\nParameters are variables: they contain values and have types.\n\n\\term{parameter passing}\nThe process of assigning an argument value to a parameter variable.\n\n\\term{local variable}\nA variable declared inside a method.\nLocal variables cannot be accessed from outside their method.\n\n\\term{stack diagram}\nA graphical representation of the variables belonging to each method.\nThe method calls are ``stacked'' from top to bottom, in the flow of execution.\n\n\\term{frame}\nIn a stack diagram, a representation of the variables and parameters for a method, along with their current values.\n\n%\\term{scope}\n%The area of a program where a variable exists.\n\n\\term{return type}\nThe type of value a method returns.\n\n\\term{return value}\nThe value provided as the result of a method invocation.\n\n\\term{temporary variable}\nA short-lived variable, often used for debugging.\n\n\\term{incremental development}\nA process for creating programs by writing a few lines at a time, compiling, and testing.\n\n\\term{stub}\nA placeholder for an incomplete method so that the class will compile.\n\n\\term{scaffolding}\nCode that is used during program development but is not part of the final version.\n\n\\end{description}\n\n\n\\section{Exercises}\n\nThe code for this chapter is in the {\\tt ch04} directory of {\\tt ThinkJavaCode2}.\nSee page~\\pageref{code} for instructions on how to download the repository.\nBefore you start the exercises, we recommend that you compile and run the examples.\n\nIf you have not already read Appendix~\\ref{cltesting}, now might be a good time.\nIt describes an efficient way to test programs that take input from the user and display specific output.\n\n\n\\begin{exercise}  %%V6 Ex4.3\n\nThe purpose of this exercise is to take code from a previous exercise and redesign it as a method that takes parameters.\nYou should start with a working solution to Exercise~\\ref{ex:date}.\n\n\\begin{enumerate}\n\n\\item Write a method called \\java{printAmerican} that takes the day, date, month and year as parameters and that displays them in American format.\n\n\\item Test your method by invoking it from \\java{main} and passing appropriate arguments.\nThe output should look something like this (except that the date might be different):\n\n\\begin{stdout}\nSaturday, July 22, 2015\n\\end{stdout}\n\n\\item Once you have debugged \\java{printAmerican}, write another method called \\java{printEuropean} that displays the date in European format.\n\n\\end{enumerate}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex5.6\n\nThis exercise reviews the flow of execution through a program with multiple methods.\nRead the following code and answer the questions.\n\n\\begin{code}\npublic static void main(String[] args) {\n    zippo(\"rattle\", 13);\n}\n\\end{code}\n\n\\begin{code}\npublic static void baffle(String blimp) {\n    System.out.println(blimp);\n    zippo(\"ping\", -5);\n}\n\\end{code}\n\n\\begin{code}\npublic static void zippo(String quince, int flag) {\n    if (flag < 0) {\n        System.out.println(quince + \" zoop\");\n    } else {\n        System.out.println(\"ik\");\n        baffle(quince);\n        System.out.println(\"boo-wa-ha-ha\");\n    }\n}\n\\end{code}\n\n\\begin{enumerate}\n\n\\item Write the number {\\tt 1} next to the first line of code in this program that will execute.\n\n\\item Write the number {\\tt 2} next to the second line of code, and so on until the end of the program.\nIf a line is executed more than once, it might end up with more than one number next to it.\n\n\\item What is the value of the parameter \\java{blimp} when \\java{baffle} gets invoked?\n\n\\item What is the output of this program?\n\n\\end{enumerate}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex4.1\n\n%The point of this exercise is to practice reading code and to make sure that you understand the flow of execution through a program with multiple methods.\nAnswer the following questions without running the program on a computer.\n\n\\begin{enumerate}\n\n\\item Draw a stack diagram that shows the state of the program the first time \\java{ping} is invoked.\n\n\\item What is output by the following program?\nBe precise about where there are spaces and where there are newlines.\n\n%{\\it Hint:} Start by describing in words what \\java{ping} and \\java{baffle} output.\n\n%\\item What happens if you invoke \\java{baffle();} at the end of the \\java{ping} method? (We will see why in Section~\\ref{recursion}.)\n\n\\end{enumerate}\n\n\\begin{code}\npublic static void zoop() {\n    baffle();\n    System.out.print(\"You wugga \");\n    baffle();\n}\n\\end{code}\n\n\\begin{code}\npublic static void main(String[] args) {\n    System.out.print(\"No, I \");\n    zoop();\n    System.out.print(\"I \");\n    baffle();\n}\n\\end{code}\n\n\\begin{code}\npublic static void baffle() {\n    System.out.print(\"wug\");\n    ping();\n}\n\\end{code}\n\n\\begin{code}\npublic static void ping() {\n    System.out.println(\".\");\n}\n\\end{code}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex6.1\n\nIf you have a question about whether something is legal, and what happens if it is not, a good way to find out is to ask the compiler.\nAnswer the following questions by trying them out.\n\n\\begin{enumerate}\n\n\\item What happens if you invoke a value method and don't do anything with the result; that is, if you don't assign it to a variable or use it as part of a larger expression?\n\n\\item What happens if you use a void method as part of an expression?\nFor example, try \\java{System.out.println(\"boo!\") + 7;}\n\n\\end{enumerate}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex5.2\n\nDraw a stack diagram that shows the state of the program the {\\it second} time \\java{zoop} is invoked.\nWhat is the complete output?\n\n\\begin{code}\npublic static void zoop(String fred, int bob) {\n    System.out.println(fred);\n    if (bob == 5) {\n        ping(\"not \");\n    } else {\n        System.out.println(\"!\");\n    }\n}\n\\end{code}\n\n\\begin{code}\npublic static void main(String[] args) {\n    int bizz = 5;\n    int buzz = 2;\n    zoop(\"just for\", bizz);\n    clink(2 * buzz);\n}\n\\end{code}\n\n\\begin{code}\npublic static void clink(int fork) {\n    System.out.print(\"It's \");\n    zoop(\"breakfast \", fork);\n}\n\\end{code}\n\n\\begin{code}\npublic static void ping(String strangStrung) {\n    System.out.println(\"any \" + strangStrung + \"more \");\n}\n\\end{code}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex6.4\n\nMany computations can be expressed more concisely using the ``multadd'' operation, which takes three operands and computes \\java{a * b + c}.\nSome processors even provide a hardware implementation of this operation for floating-point numbers.\n\n\\begin{enumerate}\n\n\\item Create a new program called {\\tt Multadd.java}.\n\n\\item Write a method called \\java{multadd} that takes three \\java{doubles} as parameters and that returns \\java{a * b + c}.\n\n\\item Write a \\java{main} method that tests \\java{multadd} by invoking it with a few simple parameters, like \\java{1.0, 2.0, 3.0}.\n\n\\item Also in \\java{main}, use \\java{multadd} to compute the following values:\n%\n\\begin{eqnarray*}\n& \\sin \\frac{\\pi}{4} + \\frac{\\cos \\frac{\\pi}{4}}{2} & \\\\\n& \\log 10 + \\log 20 &\n\\end{eqnarray*}\n\n\\item Write a method called \\java{expSum} that takes a double as a parameter and that uses \\java{multadd} to calculate:\n%\n\\begin{eqnarray*}\nx e^{-x} + \\sqrt{1 - e^{-x}}\n\\end{eqnarray*}\n%\n{\\it Hint:} The method for raising $e$ to a power is \\java{Math.exp}.\n\n\\end{enumerate}\n\nIn the last part of this exercise, you need to write a method that invokes another method you wrote.\nWhenever you do that, it is a good idea to test the first method carefully before working on the second.\nOtherwise, you might find yourself debugging two methods at the same time, which can be difficult.\n\nOne of the purposes of this exercise is to practice pattern-matching: the ability to recognize a specific problem as an instance of a general category of problems.\n\n\\end{exercise}\n", "meta": {"hexsha": "33b3cee9749028f969059beb9065dab8beca2530", "size": 38565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch04.tex", "max_stars_repo_name": "StevenLRichardson/ThinkJava2Trinket", "max_stars_repo_head_hexsha": "540f35463dbab881cf2557553e93df28b37a4f32", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-29T10:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-29T10:05:31.000Z", "max_issues_repo_path": "ch04.tex", "max_issues_repo_name": "StevenLRichardson/ThinkJava2Trinket", "max_issues_repo_head_hexsha": "540f35463dbab881cf2557553e93df28b37a4f32", "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": "ch04.tex", "max_forks_repo_name": "StevenLRichardson/ThinkJava2Trinket", "max_forks_repo_head_hexsha": "540f35463dbab881cf2557553e93df28b37a4f32", "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.9078212291, "max_line_length": 213, "alphanum_fraction": 0.7345779852, "num_tokens": 9794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.6836875141274078}}
{"text": "\\chapter{Drag}\n\nThe very first computers were created to do calculations of how\nartillery would fly when shot at different angles. The calculations\nwere similar to the ones you just did for the flying\nhammer with two important differences:\n\\begin{itemize}\n\\item They were interested in two dimensions: the height and the distance across the ground.\n\\item Artillery flies a lot faster, so they had to worry about drag from the air.\n\\end{itemize}\n\n\\section{Wind resistance}\n\nThe first thing they did was put one of the shells in a wind tunnel.\nThey measured how much force was created when they pushed 1 m/s of\nwind over the shell. Let's say it was 0.1 newtons.\n\nOne of the interesting things about the drag from the air (often\ncalled \\newterm{wind resistance}) is that it increases with the\n\\emph{square} of the speed. Thus, if the wind pushing on the shell is\n3 m/s, instead of 1 m/s, the resistance is $3^2 \\times 0.1 = 0.9$\nnewtons.\n\n(Why? Intuitively, three times as many air molecules are hitting the\nshell and each molecule is hitting it three times harder.)\n\nSo, if a shell is moving with the velocity vector $v$, the force\nvector of the drag points in the exact opposite direction. If $\\mu$ is\nthe force of wind resistance of the shell at 1 m/s, then the magnitude\nof the drag vector is $\\mu |v|^2$.\n\n\\section{Initial velocity and acceleration due to gravity}\n\nLet's say a shell is shot out of a tube at $s$ m/s, and let's say the tube\nis tilted $\\theta$ radians above level.  Then, the initial velocity\nwill be given by the vector $[s \\cos(\\theta), s \\sin(\\theta)]$\n\n(The velocity of the shell is actually a 3-dimensional vector, but we\nare only going to worry about height and horizontal distance; we are\nassuming that the operator pointed it in the right direction.)\n\nTo figure out the path of the shell, we need to compute its acceleration. We remember that\n\n$$F = m a$$\n\n(Note that $F$ and $a$ are vectors.)  Dividing both sides by $m$ we get:\n\n$$a = \\frac{F}{m}$$\n\nSo let's figure out the net force on the shell so that we can calculate the acceleration vector.\n\nIf the shell has a mass of $b$, the force due to gravity will be in the\ndownward direction with a magnitude of $9.8 b$ newtons.\n\nTo get the net force, we will need to add the force due to gravity\nwith the force due to wind resistance.\n\n\\section{Simulating artillery in Python}\n\nCreate a file called \\filename{artillery.py}.\n\n\\begin{Verbatim}\n    import numpy as np\n    import matplotlib.pyplot as plt\n    \n    # Constants\n    mass = 45 # kg\n    start_speed = 300.0 # m/s\n    theta = np.pi/5 # radians (36 degrees above level)\n    time_step = 0.01 # s\n    wind_resistance = 0.05 # newtons in 1 m/s wind\n    force_of_gravity = np.array([0.0, -9.8 * mass]) # newtons\n    \n    # Initial state\n    position = np.array([0.0, 0.0]) # [distance, height] in meters\n    velocity = np.array([start_speed * np.cos(theta), start_speed * np.sin(theta)])\n    time = 0.0 # seconds\n    \n    # Lists to gather data\n    distances = []\n    heights = []\n    times = []\n    \n    # While shell is aloft\n    while position[1] >= 0:\n        # Record data\n        distances.append(position[0])\n        heights.append(position[1])\n        times.append(time)\n    \n        # Calculate the next state\n        time += time_step\n        position += time_step * velocity\n    \n        # Calculate the net force vector\n        force = force_of_gravity - wind_resistance * velocity**2\n    \n        # Calculate the current acceleration vector\n        acceleration = force / mass\n    \n        # Update the velocity vector   \n        velocity += time_step * acceleration\n    \n    print(f\"Hit the ground {position[0]:.2f} meters away at {time:.2f} seconds.\")\n    \n    # Plot the data\n    fig, ax = plt.subplots()\n    ax.plot(distances, heights)\n    ax.set_title(\"Distance vs. Height\")\n    ax.set_xlabel(\"Distance (m)\")\n    ax.set_ylabel(\"Height (m)\")\n    plt.show()        \n\\end{Verbatim}\n\nWhen you run it, you should get a message like:\n\\begin{Verbatim}\nHit the ground 1696.70 meters away at 20.73 seconds.\n\\end{Verbatim}\n\nYou should also see a plot of the shell's path:\n\n\\includegraphics[width=0.8\\textwidth]{artillery.png}\n\n\\section{Terminal velocity}\n\nIf you shot the shell very, very high in the sky, it would keep accelerating \ntoward the ground until the force of gravity and the force of the wind resistance were equal.\nThe speed at which this happens is called the \\newterm{terminal velocity}.  The terminal velocity of a\nfalling human is about 53 m/s.\n\n\\begin{Exercise}[title={Terminal velocity}, label=terminal_velocity]\n    What is the terminal velocity of shell described in our example?\n\\end{Exercise}\n\\begin{Answer}[ref=terminal_velocity]\nThe force of gravity is $9.8 \\times 45 = 441$ newtons.\n\nAt any speed $s$, the force of wind resistance is $0.05 \\times s^2 = 0.05 s^2$ newtons.\n\nAt terminal velocity, $0.05 s^2 = 441$. \n\nSolving for $s$, we get $s = \\sqrt{\\frac{441}{0.05}}$\n\nThus, terminal velocity should be about 94 m/s.\n\n\\end{Answer}\n", "meta": {"hexsha": "27960cb6d4df23d61f2625fd10784c55c81afae0", "size": 4994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Functions/drag-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Functions/drag-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Functions/drag-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": 34.2054794521, "max_line_length": 102, "alphanum_fraction": 0.7024429315, "num_tokens": 1304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6836875097529682}}
{"text": "\\subsection{Motivation for axioms for propositional logic}\n\nWe discussed in the previous section the ability to derive new tautologies from others using substitution and Modus Ponens.\n\nWe now aim to identify a group of axioms from which all tautologies can be derived.\n\n\\subsection{The axioms}\n\nThe first is known as \"Simplification\". In words, this is \"if it is cloudy, then if it is a Tuesday it is also cloudy.\"\n\n\\(\\theta \\rightarrow (\\gamma \\rightarrow \\theta )\\)\n\nThe second is called \"Frege\".\n\n\\((\\alpha \\rightarrow (\\beta \\rightarrow \\gamma ))\\rightarrow ((\\alpha \\rightarrow \\beta )\\rightarrow(\\alpha \\rightarrow \\gamma ))\\)\n\nThe third is \"Transposition\". Consider the statement \"If there are no clouds in the sky, it is not raining.\" If this is true then it is also true that \"If it is raining there are clouds in the sky.\"\n\n\\((\\neg \\theta \\rightarrow \\neg \\gamma )\\rightarrow (\\gamma \\rightarrow \\theta )\\)\n\n\\subsection{Independence of axioms}\n\nThese axioms are independent. That is, if you take one away, you cannot derive it from the others.\n\nThese axioms are also effective. One could define all true formulae as axioms, however this is not effective.\n\n\\subsection{Soundness of axioms}\n\nSoundness implies that all theories are true.\n\n\\(T\\vdash A \\Rightarrow T\\vDash A \\)\n\nThese axioms and the deduction rule are sound. We know that the axioms are tautologies, and we know that the inference rule is valid.\n\nAs the axioms are sound, the theories are consistent. That is, it is not possible for both \\(\\theta \\) and \\(\\neg \\theta \\) to be theories.\n\n\\subsection{Completeness of axioms}\n\nCompleteness implies that all true formulae are theories.\n\n\\(T\\vDash A \\Rightarrow T\\vdash A\\)\n\n\\subsection{Axioms and definitions}\n\nA definition is a conservative extension of the language. A definition statement, for example that a new symbol \\(Z\\) is always evaluated as false allows us to make additional statements, but it does not allow us to make additional statements in the original language.\n\nAn axiom allows us to generate additional statements in the original language, a definition does not.\n", "meta": {"hexsha": "7a5064ae564fb9c86e67293240a5a31f84a86d3e", "size": 2103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogicAxioms/01-01-axioms.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogicAxioms/01-01-axioms.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogicAxioms/01-01-axioms.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8125, "max_line_length": 268, "alphanum_fraction": 0.7650974798, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749422, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.6835783567597641}}
{"text": "\\subsection{The Ideal Gas Law and Definining Temperature}\nPossibly the most important equation you'll encounter in thermodynamics is the ideal gas law. It states that\n\\begin{equation}\n    \\label{eqn:(4)}\n    PV=Nk_{b}T\n\\end{equation}\nwhere $P$ is the pressure of the gas (in Pascals), $V$ the volume (in $m^3$), $N$ the number of molecules of gas, $T$ the temperature (in \\textbf{Kelvin})\\footnote{Just as a refresher, x Kelvin = x-273 Celsius, and 0 Kelvin is absolute zero.}, and $k_b$ is Boltzmann's constant ($1.381 \\times 10^{-23} \\textrm{ m}^2 \\textrm{ kg} \\textrm{ s}^{-2} \\textrm{ K}^{-1}$). We can consider this relationship as this as an empirical result; essentially, it is the combination of three simple gas laws that were determined experimentally. First, we had Boyle's Law, which tells us that for fixed temperature $T$ and amount of gas $N$, the pressure $P$ is inversely proportional to the volume $V$:\n\\begin{equation}\n    P \\propto \\frac{1}{V}\n\\end{equation}\nWe then have Charles' Law, which tells us that for fixed pressure $P$ and amount of gas $N$, the volume $V$ is directly proportional to the temperature $T$:\n\\begin{equation}\n    V \\propto T\n\\end{equation}\nFinally, we have Avogadro's Law, which tells us that for constant temperature $T$ and constant pressure $P$, The volume of gas $V$ is directly proportional to the amount $N$:\n\\begin{equation}\n    V \\propto N\n\\end{equation}\nI will leave it to you to show that combining these three leads to the ideal gas law as we have stated it!\\footnote{You can fairly easily show that this version of the gas law is equivalent to $PV=nRT$, the version you might be more familiar with; see the questions section!} \\\\\n\\noindent\nNow, with everything we need in place, let's finally define temperature microscopically. Substituting equation \\ref{eqn:(2)} from the previous section:\n\\begin{align*}\n    \\frac{3}{2}PV=N\\epsilon_{kavg}\n\\end{align*}\nAnd substituting in the ideal gas law, we get:\n\\begin{align*}\n    \\frac{3}{2}Nk_bT = N\\epsilon_{kavg}\n\\end{align*}\nCancelling the $N$s and rearranging for the temperature $T$, we obtain:\n\\begin{equation}\n    \\label{eqn:(8)}\n    T = \\frac{2}{3k_b}\\epsilon_{kavg}\n\\end{equation}\nwhich seems like a good definition of temperature! What it essentially tells us is that the faster particles are moving in a gas on average, the hotter it is (although heavy particles can make up the difference, as mass also plays into kinetic energy).\\\\\n\\noindent\nThe final thing I should definitely mention is the long list of assumptions that equations \\ref{eqn:(2)} and \\ref{eqn:(4)} make. They are, in no particular order:\n\\begin{enumerate}\n    \\item A gas is made up of point-like particles of identical mass.\n    \\item The particles in a gas only interact via collisions.\n    \\item All collisions of particles in a gas are elastic.\n\\end{enumerate}\nThe above three conditions are what it means for a gas to be ideal. For those of you who followed along with the derivation of equation \\ref{eqn:(2)}, you might recognize why these assumptions were necessary to make. \\\\\nYou might be tempted to ask; if equations \\ref{eqn:(2)} and \\ref{eqn:(4)} only hold for ideal gases, then does our new definition of temperature only hold for ideal gases as well? Actually, no! Even though the derivation we did for it used formulas that only applies to ideal gases, it turns out that the definition holds for \\textbf{all} gases.", "meta": {"hexsha": "9df10c4a2d0af8c7466cee4d459d25360881cffe", "size": 3408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Temperature/idealgaslaw.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/idealgaslaw.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/idealgaslaw.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": 79.2558139535, "max_line_length": 686, "alphanum_fraction": 0.7438380282, "num_tokens": 930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.683578353235468}}
{"text": "\\section{Classifying projected simplexes}\n\\label{sec:classifying}\n\n%-----------------------------------------------------------------\n\nThe convex hull of a $(d-1)$ dimensional projection of a $d$-simplex\nis either a $(d-1)$-simplex or a $(d-1)$ dimensional cross polytope.\n\n\\begin{Lemma}\n\\label{rambau-lemma}\nAny set $Z$ of $(d+2)$ points whose convex hull is of dimension $d$\nhas exactly two triangulations denoted $T_{Z^+}$ and $T_{Z^-}$.\n\\end{Lemma}\n\nSee Rambau~\\cite[Lemma~1.1.2]{rambau-jorg-1996}.\n\nLet $S=(\\p_0, \\p_1 \\ldots  \\p_m)$ be an $m$-simplex in $\\Reals^{n}$.\nLet $\\pi$ be a projection from $\\Reals^{n}$ to $Q$, an $(m-1)$-dimensional\naffine subspace of $\\Reals^{n}$.\nAssume $\\pi$ is chosen so that the points\n$\\{\\pi \\p_0, \\pi \\p_1 \\ldots  \\pi \\p_m\\}$ are in {\\it general position},\nthat is, any $l+1$ of the projected points spans an $l$-dimensional\naffine subspace of $Q$.\n\nBy Lemma \\ref{rambau-lemma},\nthere are two exactly triangulations of the convex hull of the projected points.\nThe $(m-1)$-simplexes of the triangulations are images of the $(m-1)$-simplexes of $S$,\nand two triangulations correspond to a partition of $(m-1)$-simplexes of $S$\ninto two subsets, the \"top\" and \"bottom\" of $S$ with respect to $\\pi$.\n\nTo see why this is true, and to further classify the triangulations,\nconsider the fact that the boundary of the convex hull of $\\pi S$\nmust contain either $m$ or $m+1$ of the $\\pi \\p_i$.\n(Any fewer and the points cannot be in general position.)\n\n\\begin{Theorem}\n\\label{one-simplex-case}\nIf the boundary of the convex hull of $\\pi S$\ncontains $m$ of the $\\pi \\p_i$,\nthen it is a $(m-1)$-simplex\nand the image of one of the $(m-1)$-simplexes, $F$, in $S$.\nThe first triangulation is just $\\pi F$.\nThe second triangulation consists of the images of\nall the remaining $(m-1)$-simplexes of $S$.\nThe second triangulation is itself the mutual refinement of both.\n\\end{Theorem}\n\nThe first 2 statements are obvious.\nIf we label the vertices so that $\\{\\pi \\p_1 \\ldots  \\pi \\p_m\\}$\nare on the boundary, and $\\pi \\p_0$ is in the interior,\nthen the second triangulation results from refining the first\ntriangulation {\\it pulling}\n\\cite{lee-hdcg-2004} the vertex $\\pi \\p_0$.\nThe faces of the triangulation formed by pulling\nare the images of the $m$ $(m-1)$-simplexes\nof $S$ that contain $\\p_0$, that is, all the $(m-1)$-simplexes in $S$,\nother than $(\\p_1 \\ldots  \\pi \\p_m)$.\n\n\\begin{Theorem}\n\\label{two-simplex-case}\nIf the boundary of the convex hull of $\\pi S$\ncontains all $m+1$ of the $\\pi \\p_i$,\nthen it is the image of 2 of the $(m-1)$-simplexes in $S$,\nwhich share a common $(m-2)$-simplex.\nThese 2 simplexes are the first triangulation.\nThe second triangulation consists of the images\nof the remaining $m-1$ $(m-1)$-simplexes of $S$,\nwhich share a common $1$-simplex.\nThe mutual refinement is formed by splitting either\nthe shared $(m-2)$-simplex in the first triangulation\nor the shared $1$-simplex in the second.\n\\end{Theorem}\n\n\n\n", "meta": {"hexsha": "7f917564c0463e876ba5db4769dd29eaa3ca95f8", "size": 2965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/flattening/flatten.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/flattening/flatten.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/flattening/flatten.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": 39.0131578947, "max_line_length": 87, "alphanum_fraction": 0.6930860034, "num_tokens": 934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067208930584, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.6835783473703217}}
{"text": "\\section{Examples}\n\\label{sec:examples}\n\nIn this section we look at several small examples which demonstrate\nvarious points of RZ. For a serious case study from computable\nmathematics see the implementation of real numbers with\nRZ by Bauer and Kavkler~\\cite{bauer07:_implem_rz}.\n\nThe main theme is that constructively reasonable axioms yield\ncomputationally reasonable operations.\n\n\\subsection{Decidable sets}\n\\label{sec:decidable-sets}\n\nA set $S$ is said to be decidable when, for all $x, y \\in S$, $x = y$\nor $\\lnot (x = y)$. In classical mathematics all sets are decidable, \n\\iflong\nbecause decidability of equality is just an instance of the law of\nexcluded middle.  But\n\\else\nbut\n\\fi % \\iflong\nRZ requires an axiom\n%\n\\begin{source}\nParameter s : Set.\nAxiom eq: \\iForall x y : s, x = y \\iOr \\iNot (x = y).\n\\end{source}\n%\nto produce a realizer for equality\n%\n\\begin{source}\nval eq : s \\iTo s \\iTo [`or0 | `or1]\nassertion eq : \\iForall (x:\\iT{s}, y:\\iT{s}), (match eq x y with\n                                           `or0 \\iImply x \\iPer{s} y\n                                         | `or1 \\iImply \\iNot (x \\iPer{s} y) )\n\\end{source}\n%\nWe read this as follows: $\\f{eq}$ is a function which takes\narguments~$\\f{x}$ and~$\\f{y}$ of type~$\\f{s}$ and returns\n$\\mathtt{`or0}$ or $\\mathtt{`or1}$. If it returns $\\mathtt{`or0}$,\nthen $\\oper{\\f{s}}{\\f{x}}{\\f{y}}$, and if it returns\n$\\mathtt{`or1}$, then $\\onot{(\\oper{\\f{s}}{\\f{x}}{\\f{y}})}$. In\nother words $\\f{eq}$ is a decision procedure%\n\\iflong\\ \nwhich tells when\nvalues~$\\f{x}$ and~$\\f{y}$ represent the same element of the modest\nset.\n\\else % \\iflong\n.\n\\fi % \\iflong\n\n\\iflong\n\\subsection{Examples with obligations}\n\\label{sec:exampl-with-oblig}\n\nIn this section we show how RZ produces obligations, is sometimes able\nto optimize them away, and show the effect of hoisting.\n\nConsider how we might define division of real numbers. Assuming the\nset of real numbers~$\\f{real}$, constants $\\f{zero}$ and $\\f{one}$, and\nmultiplication operation~$\\f{*}$ have already been declared and\naxiomatized, we might write:\n%\n\\begin{source}\nDefinition nonZeroReal := \\{x : real | \\iNot (x = zero)\\}.\nParameter inv : nonZeroReal \\iTo real.\nAxiom inverse : \\iForall x : real, \\iNot (x = zero) -> x * (inv x) = one.\nDefinition (/) (x : real) (y : nonZeroReal) := x * (inv y).\n\\end{source}\n%\nWe have defined the set of non-zero reals $\\f{nonZeroReal}$ and\nthe inverse operation~$\\f{inv}$ on it. Division $\\f{x/y}$ is defined\nas $\\f{x * inv\\; y}$. This does \\emph{not} mean that the\nprogrammer must necessarily implement division this way, only that the\nimplementation of $\\f{x/y}$ must be equivalent to $\\f{x * inv\\;y}$.\n\nIn the axiom $\\f{inverse}$, RZ encounters the subexpression\n$\\f{inv \\;x}$. Because $\\f{x}$ is quantified as an element of\n$\\f{real}$ rather than $\\f{nonZeroReal}$, the typechecking\nphase inserts a coercion that makes the expression well-typed.\nTranslation sees $\\f{inv}(\\f{x} \\mathbin{{:}}\n\\f{nonZeroReal})$ instead of $\\f{inv\\ x}$ and translates this to\n%\n\\begin{source}\ninv (assure u:unit, \\iNot (x \\iPer{real} zero) in (x, u))\n\\end{source}\n%\nIf this were the final output, the programmer would have to verify\nthat~$\\f{x}$ is not zero, and provide a trivial realizer for it. However,\nin this case the thinning phase first removes the trivial realizer,\n%\n\\iflong\n\\begin{source}\ninv (assure \\iNot (x \\iPer{real} zero) in x)\n\\end{source}\n\\fi % \\iflong\n%\nand then the optimizer determines that the obligation is not needed\nbecause the whole expression appears under the hypothesis that~$\\f{x}$ is\nnot zero. So in the end the programmer sees\n%\n\\begin{source}\nassertion inverse :\n  \\iForall (x:\\iT{real}),  \\iNot (x \\iPer{real} zero) \\iTo (x * inv x) \\iPer{real} one\n\\end{source}\n%\nAssuming further that a strict linear order $<$ on~$\\f{real}$ has\nbeen axiomatized, we might proceed by relating it to $\\f{inv}$:\n%\n\\begin{source}\nAxiom inv_positive: \\iForall x : real, zero < x \\iTo zero < inv x.\n\\end{source}\n%\nOnce again $\\f{inv\\;x}$ appears in the input, but this time the\noptimizer is unable to remove the obligation, so the output is\n%\n\\begin{source}\nassertion inv_positive: \\iForall (x:\\iT{real}),\n   zero < x \\iTo zero < inv (assure (not (x \\iPer{real} zero)) in x)\n\\end{source}\n%\nLocal obligations can sometimes be hard to read, but if we activate the hoisting phase\n(see Section~\\ref{sec:implementation}), the obligation can be moved\nto the top level. As this is done, the hypotheses under which the\nobligation appears are collected, and we get\n%\n\\begin{source}\nassertion inv_positive:\n  assure (\\iForall (x:\\iT{real}),  zero < x \\iTo not (x \\iPer{real} zero))\n    in \\iForall (x:\\iT{real}),  zero < x \\iTo zero < inv x\n\\end{source}\n%\nNow it is easier to understand what must be checked, namely that\npositive reals are not zero---an easy consequence of irreflexivity\nof~$<$, but not something that the RZ optimizer is aware of.\n\nLastly, we could define the golden ratio as the positive solution of\n$x^2 = x + 1$,\n%\n\\begin{source}\nthe x : real, (zero < x \\iAnd x*x = x + one)\n\\end{source}\n%\nNot surprisingly, RZ cannot determine that there is a unique such~$\\f{x}$,\nso it outputs an obligation:\n%\n\\begin{source}\nassure x:real,\n  (x : \\iT{real} \\iAnd zero < x \\iAnd x * x =real= x + one \\iAnd\n    (\\iForall (x':\\iT{real}),  zero < x' \\iAnd x' * x' \\iPer{real} x' + one \\iTo x \\iPer{real} x'))\n  in x\n\\end{source}\n\\fi % \\iflong\n\n\\iflong\n\\subsection{Finite sets}\n\\label{sec:finite-sets}\n\n\\begin{figure}[b]\n\\begin{source}\nDefinition Semilattice :=\nthy\n  Parameter s : Set.\n  Parameter zero : s.\n  Parameter join : s \\iTo s \\iTo s.\n  Implicit Type x y z : s.\n  Axiom commutative: \\iForall x y,   join x y = join y x.\n  Axiom associative: \\iForall x y z, join (join x y) z = join x (join y z).\n  Axiom idempotent:  \\iForall x,     join x x = x.\n  Axiom neutral:     \\iForall x,     join x zero = x.\nend.\n\\end{source}\n\\caption{The theory of a semilattice}\n\\label{fig:semilattice}\n\\end{figure}\n\n\\iflong\nThere are many characterizations of finite sets, but the one that\nworks best constructively is due to Kuratowski, who identified the\nfinite subsets of~$A$ as the least family~$K(A)$ of subsets of~$A$\nthat contains the empty set and is closed under unions with\nsingletons. This characterization relies on powersets, which are not\navailable in RZ. But the gist of it, namely that $K(A)$ is an\n\\emph{initial} structure a suitable sort, can be expressed as follows.\n\n\\else\n%\nThe family $K(A)$ of finite subsets of a set~$A$ may be characterized\nas the free $\\vee$-semilattice generated by~$A$.\n%\n\\fi\n%\nRecall that a \\emph{$\\vee$-semilattice} is a set~$S$ with a\nconstant~$0 \\in S$ and an associative, commutative, and idempotent\noperation ``join'' $\\vee$ on~$S$ such that $0$ is the neutral element\nfor~$\\vee$, see Figure~\\ref{fig:semilattice} for RZ axiomatization of\nsemilattices.\n%\nThe Kuratowski finite sets~$K(A)$ are the \\emph{free} semilattice\ngenerated by a set~$A$, where $\\vee$ is union and $0$ is the empty\nset. This is formalized in RZ as shown in Figure~\\ref{fig:kuratowski}.\n%\n\\begin{figure}\n\\begin{source}\nDefinition K (A : thy \n                    Parameter a : Set.\n                  end) :=\nthy\n  include Semilattice.\n  Parameter singleton : A.a \\iTo s.\n  Definition fin := s.\n  Definition emptyset := zero.\n  Definition union := join.\n\n  Axiom free :\n    \\iForall S : Semilattice, \\iForall f : A.a \\iTo S.s,\n    \\iExistsOne g : fin \\iTo S.s, \n      g emptyset = S.zero \\iAnd\n        (\\iForall x : A.a, f x = g (singleton x)) \\iAnd\n        (\\iForall u v : fin, g (union u v) = S.join (g u) (g v)).\nend.    \n\\end{source}\n  \\caption{Kuratowski finite sets}\n  \\label{fig:kuratowski}\n\\end{figure}\n%\nThe theory $\\f{K}$ is parameterized by a model~$\\f{A}$ which contains a\nset~$\\f{a}$. In the first line we include the theory of semilattices.\nThen we postulate an operation $\\f{singleton}$ which injects the\ngenerators into the semilattice. The three definitions are just a\nconvenience, so that we can refer to the parts of $\\f{K(A)}$ by their\nnatural names, e.g., $\\f{emptyset}$ instead of $\\f{zero}$. The axiom\n$\\f{free}$ expresses the fact that $\\f{K}(\\f{A})$ is the free\nsemilattice on~$\\f{A.a}$: for every semilattice $\\f{S}$ and a map\n$\\f{f} : \\f{A.a} \\to \\f{S.s}$ from the generators to the underlying\nset of~$\\f{S}$, there exists a unique semilattice homomorphism $\\f{g}\n: \\f{fin} \\to \\f{S.s}$ such that $\\f{f}(\\f{x}) = \\f{g}(\\f{singleton\\;\n  x})$.\n\nThe output for $\\f{Semilattice}$ and~$\\f{K}$ specifies\nvalues of suitable types for each declared constant and operation. All\naxioms but the last one are equations and have straightforward\ntranslations in terms of underlying pers. The output for the axiom\n$\\f{free}$ is shown in Figure~\\ref{fig:free}.\n%\n\\begin{figure}\n  \\centering\n\\begin{source}\nmodule Free : functor (S : Semilattice) \\iTo\nsig\n  val free : (A.a \\iTo S.s) \\iTo fin \\iTo S.s\n  assertion free :\n    \\iForall (f:\\iT{A.a \\iTo S.s}), let g = free f in\n      g : \\iT{fin \\iTo S.s} \\iAnd g emptyset \\iPer{S.s} S.zero \\iAnd \n      (\\iForall (x:\\iT{A.a}),  f x \\iPer{S.s} g (singleton x)) \\iAnd \n      (\\iForall (u:\\iT{fin}, v:\\iT{fin}), g (union u v) \\iPer{S.s} S.join (g u) (g v)) \\iAnd \n      (\\iForall h:fin \\iTo S.s,  h : \\iT{fin \\iTo S.s} \\iAnd h emptyset \\iPer{S.s} S.zero \\iAnd \n         (\\iForall (x:\\iT{A.a}), f x \\iPer{S.s} h (singleton x)) \\iAnd \n         (\\iForall (u:\\iT{fin}, v:\\iT{fin}), h (union u v) \\iPer{S.s} S.join (h u) (h v)) \\iTo\n         \\iForall x:fin, y:fin,  x \\iPer{fin} y \\iTo g x \\iPer{S.s} h y)\nend\n\\end{source}\n  \\caption{Output of axiom $\\texttt{free}$.}\n  \\label{fig:free}\n\\end{figure}\n%\nBecause the axiom quantifies over all models~$\\f{S}$ of the theory\n$\\f{Semilattice}$ its translation is a functor~$\\f{Free}$ which\naccepts an implementation of a semilattice~$S$ and yields a realizer\n$\\f{free}$ validating the axiom. The computational meaning of\n$\\f{free}$ is a combination map and fold operation, taking a map\n$\\f{f} : \\f{A.a} \\to \\f{S.s}$ and a finite set~$\\f{u} = \\set{x_1,\n  \\ldots, x_n}$, and return $\\f{f}(x_1) \\vee \\cdots \\vee \\f{f}(x_n)$,\nwhere $\\vee$ is the join operation on the semilattice~$S$.\n\nApplying phase-splitting to this axiom yields the even simpler\nspecification\n%\n\\begin{equation*}\n\\mathtt{val}\\ \\f{free} : \\alpha \\to (\\alpha \\to \\alpha \\to \\alpha) \\to (\\f{A.a}\\to\\alpha) \\to \\f{fin} \\to \\alpha\t\n\\end{equation*}\n%\n(with an appropriate assertion)\nwhich replaces the module parameter \\texttt{S} by two extra term arguments (corresponding to the module components \\texttt{S.zero} and \\texttt{S.join}) \nand a type argument $\\alpha$ for the type of lattice elements (corresponding to the module input \\texttt{S.s}).  This is even\nmore recognizable as a folding operation over the set.\n\n\nIt is important to note that, in contrast to \\texttt{fold} operators found in typical functional\nlanguages, \\texttt{free} is only expected to work for suitable \\texttt{join} arguments (e.g., idempotent and order independent).  These\nsets are not the typical finite-set data structure: there is no membership predicate, nor\nis there a way to compute the size of a set.  There is no\nassumption that equality is decidable for set elements; this permits\nfinite sets of  exact real numbers, for example.  Decidable equality\nis required both for membership and for detecting\nwhether the same element has been added twice to the same set\\footnote{The natural implementation would thus\nbe an unordered collection of elements, possibly with duplicates.}.\n\nSome operations are nevertheless computable.  Using \\texttt{free} carefully, one\ncan determine whether a finite set is empty.  In the case of a set of exact\nreal numbers, we cannot compute the sum of a set (since there might\nbe duplicate elements), but we could compute maximum or minimum.\n\nMore common set implementations (e.g., the \\texttt{Set} module in the OCaml standard library)\nimplement sets over values with decidable total order; these could also be\nformalized in RZ.\n\\fi % \\iflong\n\n\\subsection{Inductive types}\n\\label{sec:inductive-types}\n\nTo demonstrate the use of dependent types we show how RZ handles\ngeneral inductive types, also known as W-types or general\ntrees~\\cite{nordstroem90:_progr_martin_type_theor}. Recall that a\nW-type is a set of well-founded trees, where the branching types of\ntrees are described by a family of sets $B = \\set{T(x)}_{x \\in S}$.\nEach node in a tree has a \\emph{branching type}~$x \\in S$, which\ndetermines that the successors of the node are labeled by the elements\nof~$T(x)$.\n%\n\\iflong\n%\nFor example, to get non-empty binary trees whose leaves are\nlabeled by natural numbers, define\n%\n\\begin{align*}\n  S &= \\set{\\f{cons}} \\cup \\set{\\f{leaf}(n) \\such n \\in \\NN}\n  \\\\\n  T(\\f{cons}) &= \\set{\\f{left}, \\f{right}}\n  \\\\\n  T(\\f{leaf}(n)) &= \\emptyset.\n\\end{align*}\n%\nThen a node of type $\\f{cons}$ has two successors, indexed by\nconstants $\\f{left}$ and $\\f{right}$, while a node of type\n$\\f{leaf}(n)$ does not have any successors.\n\\par\n%\n\\fi % iflong\n%\nFigure~\\ref{fig:wtype} shows an RZ axiomatization of W-types.\n%\n\\begin{figure}\n\\begin{source}\nDefinition Branching :=\nthy\n  Parameter s : Set.      (* branching types *)\n  Parameter t : s -> Set. (* branch labels *)\nend.\n\nParameter W : [B : Branching] \\iTo\nthy\n  Parameter w : Set.\n  Parameter tree : [x : B.s] \\iTo (B.t x \\iTo w) \\iTo w.\n  Axiom induction:\n    \\iForall M : thy Parameter p : w \\iTo Prop. end,\n    (\\iForall x : B.s, \\iForall f : B.t x \\iTo w,\n       ((\\iForall y : B.t x, M.p (f y)) \\iTo M.p (tree x f))) \\iTo\n    \\iForall t : w, M.p t.\nend.\n\\end{source}\n\\vspace{-0.5cm}\n  \\caption{General inductive types}\n  \\label{fig:wtype}\n\\end{figure}\n%\nThe theory $\\f{Branching}$ describes that a branching type\nconsists of a set~$\\f{s}$ and a set~$\\f{t}$ depending on~$\\f{s}$. The theory~$\\f{W}$ is\nparameterized by a branching type~$\\f{B}$. It specifies a set~$\\f{w}$ of\nwell-founded trees and a tree-forming operation $\\f{tree}$ with a\ndependent type $\\Pi_{\\f{x} \\in \\f{B.s}} (\\f{B.t(x)} \\to \\f{w}) \\to \\f{w}$.\n%\n\\iflong\n%\nGiven a\nbranching type~$\\f{x}$ and a map $\\f{f} : \\f{B.t(x)} \\to \\f{w}$, $\\f{tree}\\;\\f{x}\\;\\f{f}$\nis the tree whose root has branching type~$\\f{x}$ and whose successor\nlabeled by $\\ell \\in \\f{B.t}(\\f{x})$ is the tree~$\\f{f}(\\ell)$.\n%\n\\fi\n%\nThe inductive nature of~$\\f{w}$ is expressed with the axiom\n$\\f{induction}$, which states that for every property $\\f{M.p}$, if $\\f{M.p}$\nis an inductive property then every tree satisfies it. A property is\nsaid to be \\emph{inductive} if a tree $\\f{tree}\\;\\f{x}\\;\\f{f}$ satisfies it\nwhenever all its successors satisfy it.\n\n\\iflong\nIn the translation (see Appendix~\\ref{sec:outp-induct-types} for the\ncomplete output) dependencies at the level of types and terms disappear.\n\\else\nIn the translation dependencies at the level of types and terms disappear.\n\\fi\n%\nA branching type is determined by a pair of non-dependent types~$\\f{s}$\nand~$\\f{t}$ but the per $\\per_{\\f{t}}$ depends on~$\\values{\\f{s}}$. The theory~$\\f{W}$\nturns into a signature for a functor receiving a branching type~$\\f{B}$\nand returning a type~$\\f{w}$, and an operation $\\f{tree}$ of type\n$\\f{B.s} \\to (\\f{B.t} \\to \\f{w}) \\to \\f{w}$.  One can use phase-splitting\nto translate axiom\n$\\f{induction}$ into a specification of a polymorphic function\n%\n\\begin{equation*}\n  \\f{induction:\n  (B.s \\to (B.t \\to w) \\to (B.t \\to {\\alpha}) \\to {\\alpha}) \\to w \\to {\\alpha}},\n\\end{equation*}\n%\nwhich is a form of recursion on well-founded trees. Instead of explaining $\\f{induction}$, we show a surprisingly simple,\nhand-written implementation of W-types in OCaml. The reader may enjoy figuring out how it works:\n%\n\\sourcefile{wtype.ml}\n\n\n\\subsection{Axiom of choice}\n\\label{sec:axiom-choice}\n\nRZ can help explain why a generally\naccepted axiom is not constructively valid. Consider the Axiom of\nChoice:\n%\n\\begin{source}\nParameter a b : Set.\nParameter r : a \\iTo b \\iTo Prop.\nAxiom ac: (\\iForall x : a, \\iExists y : b, r x y) \\iTo\n             (\\iExists c : a \\iTo b, \\iForall x : a, r x (c x)).\n\\end{source}\n%\nThe relevant part of the output is\n%\n\\begin{source}\nval ac : (a \\iTo b * ty_r) \\iTo (a \\iTo b) * (a \\iTo ty_r)\nassertion ac :\n  \\iForall f:a \\iTo b * ty_r,\n    (\\iForall (x:\\iT{a}),  let (p,q) = f x in p : \\iT{b} \\iAnd r x p q) \\iTo\n    let (g,h) = ac f in\n      g : \\iT{a \\iTo b} \\iAnd (\\iForall (x:\\iT{a}),  r x (g x) (h x))\n\\end{source}\n%\nThis requires a function $\\f{ac}$ which accepts a function $\\f{f}$\nand computes a pair of functions $\\f{(g,h)}$. The input function~$\\f{f}$ takes\nan $\\ototal{\\f{x}}{\\f{a}}$ and returns a pair $\\f{(p,q)}$ such that $\\f{q}$ realizes\nthe fact that $\\f{r\\;x\\;p}$ holds. The output functions $\\f{g}$ and $\\f{h}$ taking\n$\\ototal{\\f{x}}{\\f{a}}$ as input must be such that $\\f{h\\;x}$ realizes\n$\\f{r\\;x\\;(g\\;x)}$. Crucially, the requirement $\\ototal{\\f{g}}{\\oarrow{\\f{a}}{\\f{b}}}$\nsays that $\\f{g}$ must be extensional, i.e., map equivalent realizers to\nequivalent realizers. We could define~$\\f{h}$ as the second component\nof~$\\f{f}$, but we cannot hope to implement~$\\f{g}$ in general because the\nfirst component of~$\\f{f}$ is not assumed to be extensional.\n\nThe \\emph{Intensional} Axiom of Choice allows the choice function to\ndepend on the realizers:\n%\n\\begin{source}\nAxiom iac: (\\iForall x : a, \\iExists y : b, r x y) \\iTo\n           (\\iExists c : rz a \\iTo b, \\iForall x : rz a, r (rz x) (c x)).\n\\end{source}\n%\nNow the output is\n%\n\\begin{source}\nval iac : (a \\iTo b * ty_r) \\iTo (a \\iTo b) * (a \\iTo ty_r)\nassertion iac :\n  \\iForall f:a \\iTo b * ty_r,\n    (\\iForall (x:\\iT{a}),  let (p,q) = f x in p : \\iT{b} \\iAnd r x p q) \\iTo\n    let (g,h) = iac f in\n      (\\iForall x:a, x : \\iT{a} \\iTo g x : \\iT{b}) \\iAnd (\\iForall (x:\\iT{a}),  r x (g x) (h x))\n\\end{source}\n%\nThis is exactly the same as before \\emph{except} the\ntroublesome requirement \n\\iflong $\\ototal{\\f{g}}{\\oarrow{\\f{a}}{\\f{b}}}$ \n\\fi\nwas weakened to\n$\\oforall{\\f{x}}{\\f{a}}{(\\oimply{\\ototal{\\f{x}}{\\f{a}}}{\\ototal{\\f{g\\;x}}{\\f{b}}})}$. We can implement $\\f{iac}$ in OCaml as\n%\n\\begin{source}\nlet iac f = (fun x -> fst (f x)), (fun x -> snd (f x))\n\\end{source}\n%\nThe Intensional Axiom of Choice is in fact just an instance of the\nusual Axiom of Choice applied to~$\\irz{A}$ and~$B$. Combined with the\nfact that~$\\irz{A}$ covers~$A$, this establishes the validity of\n\\emph{Presentation Axiom}~\\cite{barwise75:_admis_sets_struc}, which\nstates that every set is an image of one satisfying the axiom of\nchoice.\n\n\\subsection{Modulus of Continuity}\n\\label{sec:we-show-modulus-of-continuity-example}\n\nAs a last example we show how certain constructive principles require\nthe use of computational effects. To keep the example short, we\npresume that we are already given the set of natural\nnumbers~$\\f{nat}$ with the usual structure.\n\nA \\emph{type 2 functional} is a map $f : (\\f{nat} \\to \\f{nat}) \\to\n\\f{nat}$. It is said to be continuous if the output of $f(a)$ depends\nonly on an initial segment of the sequence~$a$. We can express the\n(non-classical) axiom that all type~2 functionals are continuous in RZ\nas follows:\n%\n\\begin{source}\nAxiom continuity: \\iForall f : (nat \\iTo nat) \\iTo nat, \\iForall a : nat \\iTo nat,\n  \\iExists k, \\iForall b : nat \\iTo nat, (\\iForall m, m \\iLeq k \\iTo a m = b m) \\iTo f a = f b.\n\\end{source}\n\\goodbreak\n\nThe axiom says that for any $\\f{f}$ and $\\f{a}$ there exists $\\f{k} \\in\n\\f{nat}$ such that $\\f{f(b) = f(a)}$ when sequences~$\\f{a}$\nand~$\\f{b}$ agree on the first $\\f{k}$ terms. It translate to:\n%\n\\begin{source}\nval continuity : ((nat \\iTo nat) \\iTo nat) \\iTo (nat \\iTo nat) \\iTo nat\nassertion continuity :\n  \\iForall (f:\\iT{(nat \\iTo nat) \\iTo nat}, a:\\iT{nat \\iTo nat}),\n    let p = continuity f a in p : \\iT{nat} \\iAnd\n    (\\iForall (b:\\iT{nat \\iTo nat}),\n       (\\iForall (m:\\iT{nat}),  m \\iLeq p \\iTo a m \\iPer{nat} b m) \\iTo f a \\iPer{nat} f b)\n\\end{source}\n%\ni.e., that $\\f{continuity\\;f\\;a}$ is a number~$\\f{p}$ such that\n$\\f{f(a) = f(b)}$ whenever $\\f{a}$ and $\\f{b}$ agree on the first~$\\f{p}$ terms. In\nother words, $\\f{continuity}$ is a \\emph{modulus of continuity}\nfunctional. It cannot be implemented in a purely functional\nlanguage,\\footnote{There are models of $\\lambda$-calculus which validate\n  the choice principle~$AC_{2,0}$, but this contradicts the\n  existence of a modulus of continuity functional,\n  see~\\cite[9.6.10]{Troelstra:van-Dalen:88:2}.} but with the use of\nstore we can implement it in OCaml as\n%\n\\begin{source}\nlet continuity f a = let p = ref 0 in\n                     let a' n = (p := max !p n; a n) in\n                       f a' ; !p\n\\end{source}\n%\nTo compute a modulus for~$\\f{f}$ at~$\\f{a}$, the program creates a\nfunction~$\\f{a'}$ which is just like~$\\f{a}$ except that it stores in~$\\f{p}$ the\nlargest argument at which it has been called. Then $\\f{f\\;a'}$ is\ncomputed, its value is discarded, and the value of~$\\f{p}$ is returned.\nThe program works because~$\\f{f}$ is assumed to be extensional and\ntherefore must not distinguish between extensionally equal sequences~$\\f{a}$\nand~$\\f{a'}$.\n\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"cie\"\n%%% End: \n", "meta": {"hexsha": "f3d6f0f2975fe1d8270a1d041813c8243dd0f6c3", "size": 21041, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "private/cie/examples.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/examples.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/examples.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": 38.1869328494, "max_line_length": 152, "alphanum_fraction": 0.6739698684, "num_tokens": 7005, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6835689108339122}}
{"text": "\\documentclass[11pt,a4paper]{article}\n\n% These are extra packages that you might need for writing the equations:\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{booktabs}\n\\usepackage{hyperref}\n\\usepackage{listings}\n\\usepackage{xcolor}\n\\usepackage{outlines}\n\\usepackage{mathtools}\n\n\n\n\\lstset {language=C++,\n\t\t basicstyle=\\ttfamily,\n         keywordstyle=\\color{blue}\\ttfamily,\n         stringstyle=\\color{red}\\ttfamily,\n         commentstyle=\\color{purple}\\ttfamily,\n         morecomment=[l][\\color{magenta}]{\\#},\n       \t basicstyle=\\tiny}\n\n% You need the following package in order to include figures in your report:\n\\usepackage{graphicx}\n\n% With this package you can set the size of the margins manually:\n\\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}\n\n\\renewcommand{\\vec}[1]{\\mathbf{#1}}\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\begin{document}\n\n% Enter the exercise number, your name and date here:\n\\noindent\\parbox{\\linewidth}{\n \\parbox{.25\\linewidth}{ \\large ICP, Exercise 11 }\\hfill\n \\parbox{.5\\linewidth}{\\begin{center} \\large Beat Hubmann \\end{center}}\\hfill\n \\parbox{.2\\linewidth}{\\begin{flushright} \\large Dec 07, 2018 \\end{flushright}}\n}\n\\noindent\\rule{\\linewidth}{2pt}\n\n\n\\section{Introduction}\n\nThe Jacobi relaxation method and the Gauss-Seidel method were implemented to solve\nthe discretized Poisson equation in two dimensions for point charges in a grounded box.\nThe two methods were compared with each other in terms of time to solution and number of iterations required.\nAlso, the time to solution was compared to a high performance library Cholesky solver.\n\n\\section{Algorithm Description}\n\nFor all cases, the two-dimensional Poisson equation(equation~\\ref{eqn:1}) on $\\Omega$ is \ndiscretized using second-order central finite differences in both the x- and the y-direction (equation~\\ref{eqn:2}).\nBoth axes share a common grid spacing of $\\Delta x= \\frac{1}{N+1}$ where $N$ is the number of interior points\nper axis direction on the grid.\nFollowing the established finite difference method procedure to employ natural ordering, the left-hand side of equation~\\ref{eqn:2} then can be written\nin form of an $N*N \\times N*N$ matrix $\\vec{A}$ while the values of $\\phi$ on the grid get unrolled into a vector $\\vec{b}$ of size $N*N$ on the right-hand side (equation~\\ref{eqn:3}).\\\\\nThe resulting matrix $A$ is both sparse and block tridiagonal.\n\n\n\n\\begin{equation}\n\\Delta \\Phi = -\\phi \\quad \\text{on}\\ \\Omega = (0, 1) \\times (0,1)\n\\label{eqn:1}\n\\end{equation}\n\n\n\\begin{equation}\n4x_{i,j} - x_{i-1, j} - x_{x+1, j} - x_{i, j-1} - x_{i, j+1} = -(\\Delta x)^2 \\cdot \\rho(x_{i,j})\n\\label{eqn:2}\n\\end{equation}\n\n\n\\begin{equation}\nAx = b\n\\label{eqn:3}\n\\end{equation}\n\n\n\\subsection{Jacobi relaxation method}\nIn matrix form, the Jacobi method works by decomposing the matrix $\\vec{A}$ into a matrix $\\vec{D}$ consisting only of $\\vec{A}$'s main diagonal\nand a remainder matrix $\\vec{R} = \\vec{A} - \\vec{D}$. Starting with an initial guess for $\\vec{x} = (1, 1, \\ldots, 1)^{\\text{T}}$, we iterate $\\vec{x}^{(t+1)} = \\vec{D}^{-1}(\\vec{b}- \\vec{R}\\vec{x}^{(t)})$\nuntil $\\norm{\\vec{x}^{(t+1)} - \\vec{x}^{(t)}}$ becomes smaller than a chosen convergence treshold in a chosen norm.\n\n\n\\subsection{Gauss-Seidel method}\nSimilar to the Jacobi relaxation method, the matrix $\\vec{A}$ is decomposed into a lower triagonal matrix $\\vec{L}$ and a strictly upper triagonal matrix $\\vec{U}$ such that\n$\\vec{A} = \\vec{L} + \\vec{U}$. Completely analogous to the Jacobi relaxation method, the iteration step is  $\\vec{x}^{(t+1)} = \\vec{L}^{-1}(\\vec{b}- \\vec{U}\\vec{x}^{(t)})$.\n\n\\section{Results}\n\nThe program was implemented as described above and submitted with this report. \\\\\nBoth methods reached the set conversion treshold of $\\norm{\\vec{x}^{(t+1)} - \\vec{x}^{(t)}}_{2} \\le 10^{-4}$. \\\\\nThe Jacobi relaxation method took $t=3478$ iterations but on average only $\\sim 45 \\text{ms}$ to do so, while the Gauss-Seidel method\nonly took $t=1922$ iterations but $\\sim 6400 \\text{ms}$ to reach the same treshold. For comparison, Eigen's optimized library Cholesky method\nsolver obtained the reference solution in $9 \\text{ms}$.\\\\\nBoth methods' solutions reached similar deviation from the reference Cholesky solution:\\\\ \n$\\norm{\\vec{x}^*_{\\text{Jacobi}} - \\vec{x}^*_{\\text{Cholesky}}}_{2} \\approxeq  \\norm{\\vec{x}^*_{\\text{Gauss-Seidel}} - \\vec{x}^*_{\\text{Cholesky}}}_{2} \\approxeq 0.05$.\nThe heat maps for all three solvers are shown in figures~\\ref{fig:1}, \\ref{fig:2} and~\\ref{fig:3}.\n\n\n\\begin{figure}[ht]\n\\begin{center}\n\\includegraphics[scale=1.2]{figure_1.png} \n\\end{center}\n\\caption{Cholesky solver reference solution for Poisson equation with point charges at $(0.25, 0.75)$, $(0.75, 0.25)$.}\n\\label{fig:1}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\begin{center}\n\\includegraphics[scale=1.2]{figure_2.png} \n\\end{center}\n\\caption{Jacobi relaxation solver solution for Poisson equation with point charges at $(0.25, 0.75)$, $(0.75, 0.25)$.}\n\\label{fig:2}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\begin{center}\n\\includegraphics[scale=1.2]{figure_3.png} \n\\end{center}\n\\caption{Gauss-Seidel solver solution for Poisson equation with point charges at $(0.25, 0.75)$, $(0.75, 0.25)$.}\n\\label{fig:3}\n\\end{figure}\n\n\\section{Discussion}\nThe results are as expected. Further consideration should be given to investigating why the Gauss-Seidel solver\nin this implementation is an order of magnitude slower than the Jacobi relaxation solver.\n\n%\\begin{thebibliography}{99}\n\n\n% \\bibitem{metropolis}\n% Metropolis, N.,\n% Rosenbluth, A.W.,\n% Rosenbluth, M.N.,\n% Teller, A.H.,\n% Teller, E.\\\\\n% \\emph{Equations of State Calculations by Fast Computing Machines},\\\\\n% Journal of Chemical Physics. 21 (6): 1087,\\\\\n% 1953.\n\n\n% \\bibitem{herrmann}\n% \tHerrmann, H. J.,\n% \tSinger, H. M.,\n% \tMueller L.,\n% \tBuchmann, M.-A.,\\\\\n% \t\\emph{Introduction to Computational Physics - Lecture Notes},\\\\\n% \tETH Zurich,\\\\\n% \t2017.\n\n% \\bibitem{Gottschling}\n% Gottschling, Peter\\\\\n% \\emph{Discovering Modern C++},\\\\\n% Addison-Wesley,\\\\\n% 2016.\n\n\n\n\n%\\end{thebibliography}\n\n\\end{document}", "meta": {"hexsha": "b4fb3d3a638e995627ca5fd4039137a54357d176", "size": 6072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex11/ex11_report.tex", "max_stars_repo_name": "BeatHubmann/18H-ICP", "max_stars_repo_head_hexsha": "2ad1bcef73f3f43d832031cf45c4909341176ebd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex11/ex11_report.tex", "max_issues_repo_name": "BeatHubmann/18H-ICP", "max_issues_repo_head_hexsha": "2ad1bcef73f3f43d832031cf45c4909341176ebd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex11/ex11_report.tex", "max_forks_repo_name": "BeatHubmann/18H-ICP", "max_forks_repo_head_hexsha": "2ad1bcef73f3f43d832031cf45c4909341176ebd", "max_forks_repo_licenses": ["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.8, "max_line_length": 205, "alphanum_fraction": 0.7089920949, "num_tokens": 1928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8856314798554445, "lm_q1q2_score": 0.6835688899120407}}
{"text": "% !TEX root = thesis.tex\n\n\\chapter{Extracting information from higher-dimensional models}\n\\label{ch:slicing}\n\nThe previous chapters have discussed various aspects of higher-dimensional representations and operations.\nAs powerful as they can be, these representations and operations are generally incompatible with current 2D/3D software and are also hard to imagine and visualise.\nIn order for them to be used in practice, it is therefore important to have methods to extract meaningful 2D and 3D subsets from a higher-dimensional model.\n\nWhile fully developing methods and algorithms to do so is outside the scope of this thesis, steps towards formalising this problem and looking for potential solutions were made within the context of this thesis, and they are thus documented here.\nThe chapter starts by giving some of the background behind the problem in \\refse{se:slicing-notions}, explaining at a high level the process to extract lower-dimensional information from a higher-dimensional model.\nUsing a simple camera analogy common in computer graphics, \\refse{se:3dto2d} explains how a 3D viewpoint is placed in a 3D scene through the application of different transformations, capturing a 2D view of it by applying a given projection.\n\\refse{se:4dto3d} uses this analogy to give an intuitive description of how this process extends to higher dimensions, later formulating a simple dimension-independent generalisation of the orthographic and perspective projection methods and explaining other projection possibilities.\nFinally, \\refse{se:slicing-conclusions} concludes with some ideas on the value of these methods, what pieces are still missing and how the overall process could be implemented.\n\n\\section{Background}\n\\label{se:slicing-notions}\n\nThe process to obtain a lower-dimensional subset of a higher-dimensional dataset can be regarded as a function that maps a subset of $\\mathbb{R}^n$ to a subset of $\\mathbb{R}^m$, $m < n$, which is obtained by cutting through the dataset in a geometrically meaningful way.\nFor instance, it is possible to cut orthogonally to an axis for a snapshot at one point in space/time, or obliquely for a subset that combines different parametrised characteristics, such as the evolution of different parts of an area in time.\n\nThe process to extract these slices can be conceived as consisting of two broad steps: (i) optionally selecting a subset of the objects in the scene, and (ii) applying a transformation that projects this subset to a lower dimension.\nIn computer graphics, these steps would normally be followed by \\emph{rendering} the selected and projected objects, obtaining a raster image as an end-product.\n\n\\textbf{Selecting} a subset of a dataset is useful to bring certain parts of the dataset into view.\nFor instance, this is commonly applied to parts of a dataset that are normally not visible, such as the interior of an object.\nIt is also widely used to reduce the difficulty of the overall problem and avoiding the need to make unnecessary computations, such as projecting and rendering parts of the dataset that will be clearly out of view.\n\nThis selection process can be relatively simple, such as using all objects that are within a certain bounding box, that are within a certain distance of a point, or being of a given dimension.\nFor instance, 3D rendering programs and 3D games will usually only render the 2D faces of the objects lying (approximately) within a region (\\eg\\ frustum), not their (filled-in) volumes or any 2D faces that are clearly out of view.\n\nHowever, more complex selection processes are useful in many instances, often requiring specialised data structures and geometric algorithms.\nIn particular, a great number of visibility determination algorithms have been developed \\citep[Ch.~36]{Hughes14}, which solve various approximations of the surfaces that are visible in a scene.\nAnother example is a selection process is the computation of cross-sections of volumetric 3D objects, which requires the computation of a Boolean set intersection of a point set with a plane, such as the typical \\emph{conic sections} shown in \\reffig{fig:conic}.\n\n\\begin{figure*}[tb]\n\\centering\n\\subfloat[]{\\includegraphics[width=0.25\\linewidth]{figs/conic-circle}}\n\\subfloat[]{\\includegraphics[width=0.25\\linewidth]{figs/conic-ellipse}}\n\\subfloat[]{\\includegraphics[width=0.25\\linewidth]{figs/conic-parabola}}\n\\subfloat[]{\\includegraphics[width=0.25\\linewidth]{figs/conic-hyperbola}}\n\\caption[Conic sections]{Four types of conic sections: (a) circle, (b) ellipse, (c) parabola and (d) hyperbola.\nThese are obtained by the Boolean set intersection of a pair of cones with a plane.}\n\\label{fig:conic}\n\\end{figure*}\n\n\\textbf{Projecting} the selected subset yields a given view of the scene and reduces the actual dimension of the objects being represented.\nMany types of projections for this purpose can be defined, usually in the form of a transformation that is applied to the objects.\nFor example, orthographic and perspective projections (\\reffig{fig:scheduling}) can directly map an $n$D scene to an $m$D subspace.\nHowever, more complex schemes are also possible, such as projecting first inwards/outwards to an $m$-sphere (for a hypothetical $(m+1)$D Nef polyhedra implementation), then to an $m$D subspace (\\eg\\ using an equiangular projection as shown in \\reffig{fig:ioh-equiangle}).\n\n\\begin{figure}[tb]\n\\centering\n\\subfloat[]{\\includegraphics[width=0.4\\linewidth]{figs/scheduling-orthographic}}\n\\qquad\n\\subfloat[]{\\includegraphics[width=0.4\\linewidth]{figs/scheduling-perspective}}\n\\caption[Orthographic and perspective projections]{The (a) orthographic projection projects objects orthogonally to the projection plane.\nThe (b) perspective projection projects objects in manner such that those that are nearby appear comparatively larger than farther away. \nNote how parallel lines (\\eg\\ wall edges) remain parallel in the former but not in the latter.}\n\\label{fig:scheduling}\n\\end{figure}\n\n\\begin{figure}[tb]\n\\centering\n\\includegraphics[width=\\linewidth]{figs/ioh-equiangle}\n\\caption[Equirectangular projection]{The Equirectangular projection directly maps angles to coordinates.\nA 360$^\\circ$ view is here mapped into a rectangular 180$^\\circ\\times$360$^\\circ$ image.\nRendered from a viewpoint inside the IfcOpenHouse dataset\\protect\\footnotemark.}\n\\label{fig:ioh-equiangle}\n\\end{figure}\n\\footnotetext{\\url{http://blog.ifcopenshell.org/2012/11/say-hi-to-ifcopenhouse.html}}\n\nMany of these projections can be done with techniques that are closely related to computer graphics, which has been dealing with the case of converting a 3D scene into a 2D image for decades, and less frequently covering higher-dimensional cases as well.\nIn this sense, it is useful to consider the same camera analogy that is often used in computer graphics, where a movable camera\\footnote{Even if the movable camera is implemented by moving the dataset instead.} captures a scene as seen from a particular viewpoint.\nIn a higher-dimensional setting, this analogy would consist of an $m$D camera capturing an ($m$D) view of an $n$D scene.\nWhile this is somewhat more difficult to imagine, this analogy emphasises three important aspects that remain true in any dimension:\n\n\\begin{itemize}\n\\item\nMoving the camera around a scene and orienting it makes it possible to capture the data from any given viewpoint.\nSuch a viewpoint can be parametrised---and thus easily defined and stored---by a set of values containing its \\emph{location} and \\emph{orientation}.\n\n\\item\nIt is possible to obtain different views---intuitively corresponding to camera lenses---through various projections.\nThese can also have their own customisable parameters, such as their field of view.\n\n\\item\nDespite the fact that the dimension of the data is reduced (from $n$ to $m$), characteristics that would seem to have been lost in this process can be preserved in the form of attributes and used for further computations.\nFor instance, in computer graphics, the distance from an object to the camera (\\ie\\ the depth) is regularly used for computations of 3D-to-2D projections, either as a simple computation where the objects that are nearer (along a line of sight) occlude those that are farther away, or for more complex effects, such as transparency and reflectivity.\nIn cartography, hypsometric tints, shaded relief, contour lines are all frequently used to encode the height information in a 2D map (\\reffig{fig:wigwam}).\n\\end{itemize}\n\n\\marginpar{\n\\captionsetup{type=figure}\n\\centering\n\\includegraphics[width=\\marginparwidth]{figs/wigwam}\n\\caption[Grand Teton National Park map]{An excerpt of the map for the Grand Teton National Park. From \\citet{Patterson02}.}\n\\label{fig:wigwam}\n}\n\nContinuing with the camera analogy, it is useful to consider the $n$D scene as consisting of a set of 0D--$n$D objects.\nIn the context of this thesis, these would be represented as an $n$-dimensional simplicial complex or cell complex with linear geometries, such that every vertex in the map is embedded in a location in $\\mathbb{R}^n$.\nThe simplices/cells of the complex can be translated, rotated or scaled, if necessary, using the operations described in \\refse{se:ndmath}.\nThey can then be individually projected by the camera, possibly taking into account occlusion or other visual effects, in order to obtain the $m$D scene.\n\nThis projection is simplest when two conditions are met: (i) the objects have linear geometries that are stored as coordinates attached to their vertices (as in this thesis), and (ii) the projection transformation preserves the linearity of the objects.\nIn this case, it is only necessary to apply the transformation to every vertex individually.\n\nHowever, even when one or both of these conditions are not met, it is possible to obtain a good approximation by first subdividing a simplex/cell into small simplices/cells (up to an arbitrary $\\varepsilon$ threshold), assuming that linear geometries will remain approximately linear and projecting only the vertices of the subdivided complex.\nThis subdivision and approximation method is used for the cover of this thesis and the example in \\reffigp{fig:4dhouse}.\n\nThe following sections will therefore assume that the data to be projected consists only of a set of $k$ points with $n$ coordinates, which is stored as a $k \\times n$ matrix.\nThese will be given new coordinates in $\\mathbb{R}^m$ by applying one or more operations expressed in terms of linear algebra.\n\n\\section{3D to 2D projections}\n\\label{se:3dto2d}\n\nProjecting a set of 3D objects into a 2D view is one of the most common tasks in computer graphics.\nAs such, most computer graphics books derive their own versions of the transformations required to apply different types of projections, most of which are interchangeable but are often parametrised in different ways.\n\nFrom a practical perspective, the OpenGL Programming Guide (better known as the Red Book) \\citep{Shreiner13} provides very intuitive forms of 3D-to-2D perspective and orthographic projections, which are based on defining a \\emph{viewing frustum} or \\emph{box} where the objects to be viewed should be located/placed.\nThis can be achieved by translating, rotating and scaling the objects as described in \\refse{se:ndmath}.\n\nAssuming a setup as shown in \\reffig{fig:frustum}, where a camera is placed at $z = 0$ and pointing towards higher values on the $z$ axis, with parameters defining the $x$ coordinates for the left ($l$) and right ($r$), $y$ coordinates for the bottom ($b$) and top ($t$), and $z$ coordinates for the near ($n$) and far ($f$) planes, \\citet[Ch.~5]{Shreiner13} define a transformation that applies a perspective projection $P_p$ and an orthographic projection $P_o$ as:\n\n\\begin{figure}[tb]\n\\centering\n\\subfloat[]{\\includegraphics[width=0.3\\linewidth]{figs/frustum}}\n\\qquad\n\\subfloat[]{\\includegraphics[width=0.4\\linewidth]{figs/ortho}}\n\\caption[Perspective projection's frustum and orthographic projection's box]{The left ($l$), right ($r$), bottom ($b$), top ($t$), near ($n$) and far ($f$) planes that form (a) a perspective projection's frustum and (b) an orthographic projection's box.}\n\\label{fig:frustum}\n\\end{figure}\n\n\\begin{align*}\nP_p &= \\begin{bmatrix} \n\\frac{2n}{r-l} & 0 & \\frac{2(l+r)}{r-l} & 0 \\\\\n0 & \\frac{2n}{t-b} & \\frac{2(t+b)}{t-b} & 0 \\\\\n0 & 0 & \\frac{f+n}{n-f} & \\frac{-2fn}{f-n} \\\\\n0 & 0 & -1 & 0 \\\\\n\\end{bmatrix} &\nP_o &= \\begin{bmatrix} \n\\frac{2}{r-l} & 0 & 0 & \\frac{l+r}{l-r} \\\\\n0 & \\frac{2}{t-b} & 0 & \\frac{b+t}{b-t} \\\\\n0 & 0 & \\frac{-2}{f-n} & \\frac{n+f}{n-f} \\\\\n0 & 0 & 0 & 1 \\\\\n\\end{bmatrix}\n\\end{align*}\n\nHowever, as this thesis attempts to obtain a dimension-independent formulation, it is more interesting to consider a somewhat more complex method that can be extended more readily to higher dimensions.\n\\citet{Foley92} and \\citet[Ch.~13]{Hughes14}, among others, start from the definition of a triplet of vectors $\\hat{x}$, $\\hat{y}$ and $\\hat{z}$, which are computed from a point $from$ where the camera is located, a point $to$ that the camera directly points towards, and an arbitrary vector $\\overrightarrow{up}$ pointing approximately upwards\\footnote{Strictly, it can be defined pointing toward any direction except along the $z$ axis.}.\nThe latter vector is necessary because there is still one degree of rotational freedom even as the camera is pointing towards $to$.\nThe unit vectors $\\hat{x}$, $\\hat{y}$ and $\\hat{z}$ correspond to the $x$, $y$ and $z$ axes from the camera's perspective and are defined as:\n\n% TODO: Figure for vectors\n\n\\begin{align*}\n\\hat{x} &= \\frac{\\hat{z} \\times \\overrightarrow{up}}{\\left\\lVert{}\\hat{z} \\times \\overrightarrow{up}\\right\\rVert} &\n\\hat{y} &= \\hat{x} \\times \\hat{z} &\n\\hat{z} &= \\frac{to-from}{\\left\\lVert{}to-from\\right\\rVert}\n\\end{align*}\n\nNote that if $\\overrightarrow{up}$ is orthogonal to $\\hat{z}$, $\\hat{y}$ defines the up direction as a normalised $\\overrightarrow{up}$.\nIf they are not orthogonal, $\\hat{y}$ defines the up direction differently from $\\overrightarrow{up}$.\n\nBased on the three vectors $\\hat{x}$, $\\hat{y}$ and $\\hat{z}$, a $n \\times 3$ matrix of $n$ point coordinates in terms of the scene $P_\\mathrm{world}$ (world coordinates) can be converted into a matrix of points coordinates in terms of the camera (eye coordinates).\nThis would be computed as:\n\n\\begin{equation*}\nP_\\mathrm{eye} = \\begin{bmatrix} P_\\mathrm{world} - from \\end{bmatrix}\n\\begin{bmatrix} \\hat{x} & \\hat{y} & \\hat{z} \\end{bmatrix}\n\\end{equation*}\n\nIn a 3D to 2D \\textbf{orthographic projection}, the $x$ and $y$ coordinates of this matrix, here denoted as $x_\\mathrm{eye}$ and $y_\\mathrm{eye}$, are directly usable as the coordinates of the points in $\\mathbb{R}^2$.\nAs shown in \\reffig{fig:trig-ortho}, the $z_\\mathrm{eye}$ coordinates represent the distance between the point and the \\emph{projection plane}, \\ie\\ the camera, and thus define the \\emph{depth}.\nPoints with positive $z_\\mathrm{eye}$ values close to zero are thus close to the camera while points with larger $z_\\mathrm{eye}$ values are farther away.\nNote that negative $z_\\mathrm{eye}$ values mean that the point lies behind the camera, and so these would be usually omitted.\n\n\\marginpar{\n\\captionsetup{type=figure}\n\\centering\n\\includegraphics[width=\\marginparwidth]{figs/trig-ortho}\n\\caption[Geometry of an orthographic projection]{The geometry of an orthographic projection for a point $p$. The situation of the $y$ axis is identical to that of the $x$ axis.}\n\\label{fig:trig-ortho}\n}\n\nFor visualisation purposes, it is often convenient to normalise the coordinates so that the range of the $x$ and $y$ coordinates extend as much as possible along a given frame, resulting in objects that are not too small or too large.\n% For this, the the interval $[-1, 1]$ is commonly used.\nThis can be accomplished by finding the point that is farthest along the $\\hat{x}$ and $\\hat{y}$ compared to the desired aspect ratio of the frame in which they should fit.\nAs \\citet{Foley92} point out, in the case of the square $[-1, 1] \\times [-1, 1]$, which is commonly used, point coordinates can be normalised by dividing them by the longest distance of any point to the $to$ point.\n\nIn a 3D to 2D \\textbf{perspective projection}, objects are projected towards a point (the camera viewpoint's coordinates) rather than a plane.\nThis results in new $x_\\mathrm{pers}$ and $y_\\mathrm{pers}$ coordinates that are scaled inwards in inverse proportion to the depth, which is here defined as the distance between a point and the camera viewpoint's coordinates.\nIntuitively, this means that if an object is $n$ times farther than another identical object, it is depicted $n$ times smaller, or $\\frac{1}{n}$ of its size.\n\n\\marginpar{\n\\captionsetup{type=figure}\n\\centering\n\\includegraphics[width=\\marginparwidth]{figs/trig-pers}\n\\caption[Geometry of an perspective projection]{The geometry of a perspective projection for a point $p$. The situation of the $y$ axis is identical to that of the $x$ axis.}\n\\label{fig:trig-pers}\n}\n\nAs shown in \\reffig{fig:trig-pers}, this distance can be easily computed as the hypotenuse of a right-angled triangle, where the adjacent cathetus of an angle $\\vartheta$ is given by the (orthogonal) distance of the point to the projection plane ($z_\\mathrm{eye}$), the opposite cathetus is given by the point's world coordinates ($x_\\mathrm{eye}$ or $y_\\mathrm{eye}$), and $\\vartheta$ is the viewing angle between $\\hat{z}$ (which lies on a line that passes through $from$ and $to$) and the line between the $to$ point and the current point.\nNew $x_\\mathrm{pers}$ and $y_\\mathrm{pers}$ coordinates are thus computed using this angle as follows:\n\n\\begin{align*}\nx_\\mathrm{pers} &= \\frac{x_\\mathrm{eye}}{z_\\mathrm{eye} \\tan(\\vartheta / 2)} &\ny_\\mathrm{pers} &= \\frac{y_\\mathrm{eye}}{z_\\mathrm{eye} \\tan(\\vartheta / 2)} \\\\\n\\end{align*}\n\nThere are many other types of projections that can be defined and can be interesting in higher dimensions, such as the equirectangular projection shown in \\reffig{fig:ioh-equiangle} where evenly spaced angles along a \\emph{rotation plane} (\\refse{se:ndmath}) can be directly converted into evenly spaced coordinates.\nHowever, they will not be discussed here.\nSee \\citet[Chs.~5--7]{Salomon11} for a good reference on how to apply many different types of linear and non-linear projections.\n\n\\section{Higher-dimensional projections}\n\\label{se:4dto3d}\n\nBased on the 3D to 2D projection methods described by \\citet{Foley92}, \\citet{Hollasch91} extends them to perform 4D to 3D orthographic and perspective projections.\nThis section further extends these methods to describe the $n$-dimensional to ($n-1$)-dimensional case, changing some aspects to better explain the geometric meaning of each vector.\n\nFirst, starting from a point $from \\in \\mathbb{R}^n$ where the camera is located, a point $to \\in \\mathbb{R}^n$ that the camera directly points towards, and a set of $n-2$ vectors $\\overrightarrow{v}_1, \\ldots, \\overrightarrow{v}_{n-2}$ in $\\mathbb{R}^n$ that are all linearly independent from each other and from the vector $to - from$, it is possible to define a set of unit vectors $\\hat{x}_0, \\ldots, \\hat{x}_{n-1}$ that define the axes $x_0, \\ldots, x_{n-1}$ of a coordinate system in $\\mathbb{R}^n$ as:\n\n% \\hspace{-\\marginparwidth}\\hspace{-\\marginparsep}\\makebox[\\overflowingheadlen][l]{\n% \\begin{minipage}{\\overflowingheadlen}\n\\begin{align*}\n\\hat{x}_0 &= \\frac{\\overrightarrow{v}_1 \\times \\cdots \\times \\overrightarrow{v}_{n-2} \\times \\hat{x}_{n-1}}{\\begin{Vmatrix} \\overrightarrow{v}_1 \\times \\cdots \\times \\overrightarrow{v}_{n-2} \\times \\hat{x}_{n-1} \\end{Vmatrix}} \\\\\n\\hat{x}_i &= \\frac{\\overrightarrow{v}_{i+1} \\times \\cdots \\times \\overrightarrow{v}_{n-2} \\times \\hat{x}_{n-1} \\times \\hat{x}_0 \\times \\cdots \\times \\hat{x}_{i-1}}{\\begin{Vmatrix} \\overrightarrow{v}_{i+1} \\times \\cdots \\times \\overrightarrow{v}_{n-2} \\times \\hat{x}_{n-1} \\times \\hat{x}_0 \\times \\cdots \\times \\hat{x}_{i-1} \\end{Vmatrix}}, \\mathrm{\\quad{}for\\ } 0 < i < n-2 \\\\\n\\hat{x}_{n-2} &= \\hat{x}_{n-1} \\times \\hat{x}_0 \\times \\cdots \\times \\hat{x}_{n-2} \\\\\n\\hat{x}_{n-1} &= \\frac{to - from}{\\begin{Vmatrix} to - from \\end{Vmatrix}} \\\\\n\\end{align*}\n% \\end{minipage}\n% }\n\nThe vector $\\hat{x}_{n-1}$ is the first that needs to be computed and is oriented along the line from the camera ($from$) and the point that it is oriented towards ($to$).\nAfterwards, the vectors are computed in order from $\\hat{x}_0$ to $\\hat{x}_{n-2}$ as normalised $n$-dimensional cross products of $n-1$ vectors.\nThese contain a mixture of the input vectors $\\overrightarrow{v}_1, \\ldots, \\overrightarrow{v}_{n-2}$ and the computed unit vectors $\\hat{x}_0, \\ldots, \\hat{x}_{n-1}$, starting from $n-2$ input vectors and one unit vector for $\\hat{x}_0$, and removing one input vector and adding the previously computed unit vector for the next $\\hat{x}_i$ vector.\nNote that if $\\overrightarrow{v}_1, \\ldots, \\overrightarrow{v}_{n-2}$ and $\\hat{x}_{n-1}$ are all orthogonal to each other, $\\forall 0 < i < n-1$, $\\hat{x}_i$ is simply a normalised $\\overrightarrow{v}_i$.\n\nSimilarly to the 3D-to-2D case, the vectors $\\hat{x}_0, \\ldots, \\hat{x}_{n-1}$ can be used to transform an $m \\times n$ matrix of $m$ $n$D points in world coordinates $P$ into an $m \\times n$ matrix of $m$ $n$D points in eye coordinates $E$ by applying the following transformation:\n\n\\begin{equation*}\nE = \\begin{bmatrix} P - from \\end{bmatrix}\n\\begin{bmatrix} \\hat{x}_0 & \\cdots & \\hat{x}_{n-1} \\end{bmatrix}\n\\end{equation*}\n\nAs before, if $E$ has rows of the form $\\begin{bsmallmatrix} e_0 & \\cdots & e_{n-1} \\end{bsmallmatrix}$ representing points, $e_0, \\ldots, e_{n-2}$ are directly usable as the coordinates in $\\mathbb{R}^{n-1}$ of the projected point in an $n$-dimensional to ($n-1$)-dimensional \\textbf{orthographic projection}, while $e_{n-1}$ represents the distance between the point and the projection ($n-1$)-dimensional subspace, which can be used for visual cues\\footnote{Visual cues can still be useful in higher dimensions. See \\url{http://eusebeia.dyndns.org/4d/vis/08-hsr}.}.\nThe coordinates along $e_0, \\ldots, e_{n-2}$ could be made to fit within a certain bounding box by computing their extent along each axis, then scaling appropriately using the extent that is largest in proportion to the extent of the bounding box's corresponding axis.\n\nFor an $n$-dimensional to ($n-1$)-dimensional \\textbf{perspective projection}, it is only necessary to compute the distance between a point and the camera as the hypotenuse of a right-angled triangle by taking into account the viewing angle $\\vartheta$ between $\\hat{x}_{n-1}$ and the line between the $to$ point and every point.\nThis situation is the same as that of the 3D-to-2D case shown previously in \\reffig{fig:trig-pers} and results in new $e_0^\\prime, \\ldots, e_{n-2}^\\prime$ coordinates that are shifted inwards.\nThe coordinates are computed as:\n\n\\begin{equation*}\ne_i^\\prime = \\frac{e_i}{e_{n-1} \\tan{\\vartheta / 2}}, \\mathrm{\\quad{}for\\ } 0 \\leq i \\leq n-2 \n\\end{equation*}\n\nThe ($n-1$)-dimensional coordinates generated by this process can then be recursively projected down to progressively lower dimensions using this method.\nThe objects represented by these coordinates can also be discretised into images of any dimension.\nFor instance, \\citet{Hanson94} describes how to perform many of the operations that would be required, such as dimension-independent clipping tests and ray-tracing methods.\n\nIn addition to orthographic and perspective projections, there are other interesting projections that can be applied in higher dimensions.\nIn fact, since we lack an intuitive understanding of higher dimensions, there is little benefit in using projections that work in similar ways as the ways in which we mentally process 3D information.\nFor instance, Jenn 3D\\footnote{\\url{http://www.math.cmu.edu/~fho/jenn/}} visualises polyhedra and polychora by first projecting them inwards/outwards to the volume of a 3-sphere\\footnote{Intuitively, an unbounded volume that wraps around itself, much like a 2-sphere can be seen as an unbounded surface that wraps around itself.}, resulting in curved edges, faces and volumes.\nIn a dimension-independent setting, this projection can be easily done by considering the angles $\\vartheta_0, \\ldots, \\vartheta_{n-2}$ in an \\emph{$n$-dimensional spherical coordinate system}.\n\\citet[\\S{}12.2]{Steeb11} formulates such a system as:\n\n% TODO: Match code\n\n\\begin{align*}\nr &= \\sqrt{x_0^2 + \\cdots + x_{n-1}^2} \\\\\n\\vartheta_i &= \\cos^{-1} \\left( \\frac{x_i}{\\sqrt{r^2 - \\sum_{j=0}^{i-1} x_j^2}} \\right), \\mathrm{\\quad{}for\\ } 0 \\leq i < n-2 \\\\\n\\vartheta_{n-2} &= \\tan^{-1} \\left( \\frac{x_{n-1}}{x_{n-2}} \\right) \\\\\n\\end{align*}\n\nIt is worth to note that the radius $r$ of such a coordinate system is a measure of the depth with respect to the projection $(n-1)$-sphere $S^{n-1}$ and can be used similarly to the previous projection examples.\nThe points can then be converted back into points on the surface of an $(n-1)$-sphere of radius 1 by making $r = 1$ and applying the inverse transformation.\n\\citet[\\S{}12.2]{Steeb11} formulates it as:\n\n\\begin{align*}\nx_i &= r \\cos \\vartheta_i \\prod_{j=0}^{i-1} \\sin \\vartheta_j, \\mathrm{\\quad{}for\\ } 0 \\leq i < n-2 \\\\\nx_{n-1} &= r \\prod_{j=0}^{n-2} \\sin \\vartheta_j \\\\\n\\end{align*}\n\nThe projections on the 3-sphere used by Jenn 3D are then stereographically projected to $\\mathbb{R}^3$, then with a perspective projection (\\reffig{fig:stereo-earth}) down to 2D.\nThe final result of this 4D-to-2D projection in multiple stages is shown in \\reffig{fig:jenn}.\nA stereographic projection is also easy to apply in higher dimensions, mapping an $(n+1)$-dimensional point $x = (x_0, \\ldots, x_n)$ on an $n$-sphere $S^n$ to an $n$-dimensional point $x^\\prime = (x_0, \\ldots, x_{n-1})$ in the $n$-dimensional Euclidean space $\\mathbb{R}^n$.\n\\citet{Chisholm00} formulates this projection as:\n\n\\marginpar{\n\\captionsetup{type=figure}\n\\centering\n\\includegraphics[width=\\marginparwidth]{figs/stereo-earth}\n\\caption[Stereographic projection]{A 2-sphere to $\\mathbb{R}^2$ stereographic projection can map the surface of the Earth to the plane.\nHere, every point $p$ on the sphere is projected to the intersection of the plane with a line passing through the North pole and $p$.\nFrom \\citet{Leys08}.}\n\\label{fig:stereo-earth}\n}\n\n\\begin{equation*}\nx_i^\\prime = \\frac{x_i}{x_n-1}, \\mathrm{\\quad{}for\\ } 0 \\leq i < n\n\\end{equation*}\n\n\\begin{figure}[b]\n\\centering\n\\subfloat[]{\\includegraphics[width=0.5\\linewidth]{figs/jenn-cube}}\n\\subfloat[]{\\includegraphics[width=0.5\\linewidth]{figs/jenn-24-cell}}\n\\caption[Polyhedron and polychoron in Jenn 3D]{A polyhedron and a polychoron in Jenn 3D:\\ (a) a cube and (b) a 24-cell.}\n\\label{fig:jenn}\n\\end{figure}\n\n\\reffig{fig:4dhouse} shows the application of this method to a 4D model of a house.\nFor this, all the cells of the model were manually defined similar to how it was done in \\refse{se:concrete-example} using their boundary cells and 0-embeddings set in $\\mathbb{R}^4$.\nThe 1- and 2-cells were first refined into small line segments and triangles, the 0-, 1- and 2-cells were then projected inwards/outwards to the volume of a 3-sphere ($S^3$), and then stereographically projected to $\\mathbb{R}^3$.\nThe refined 2-cells were exported as to an\\ {}.obj file with materials that reflect which 3- and 4-cell they belong to.\nIcospheres with a set radius were generated around every 0-cell and approximations of cylinders were generated around every refined 1-cell.\nAll of these geometries were then imported into Blender 3D and rendered using a perspective projection down to 2D.\n\n\\begin{figure}[tb]\n\\centering\n\\includegraphics[width=\\linewidth]{figs/4dhouse}\n\\caption[4D to 2D projection of a 4D house]{A 4D model of a house is projected from $\\mathbb{R}^4$ inwards/outwards to the 3-sphere $S^3$, then stereographically to $\\mathbb{R}^3$, finally using a perspective projection down to $\\mathbb{R}^2$.\nA $\\pi / 5$ rotation along the plane passing through the $x_0$ and $x_3$ (LOD) axes makes the bottom and back 2-cells larger than the rest.}\n\\label{fig:4dhouse}\n\\end{figure}\n\n\\section{Conclusions and possibilities}\n\\label{se:slicing-conclusions}\n\nUsing a combination of data \\emph{selection} and \\emph{projections}, it is possible to extract meaningful lower-dimensional information from higher-dimensional datasets, making it possible for these datasets to be used in standard software and visualised.\nSelecting an arbitrary subset of an $\\mathbb{R}^n$ point set is very challenging, as this process might require the computation of Boolean set intersection operations in any dimension.\nHowever, simple selections of the objects within a region or selections involving a finite number of discrete points are relatively straightforward and can be implemented with existing techniques \\citep{Hanson94}.\n\nOn the other hand, projecting higher-dimensional datasets into lower dimensions is simple.\nAs the projection methods explained and developed in this chapter have shown, many projections have dimension-independent formulations using linear algebra that are not that different from their 3D-to-2D versions.\nThey are therefore relatively easy to implement using similar pipelines as current processes \\citep{Chu09}, even if they have not been implemented for general datasets within this thesis due to time constraints.\n\nAs this chapter focused on extracting lower-dimensional information from higher-dimensional models from a high-level perspective and in a generic way, many interesting techniques covering useful special cases have not been explored here.\nFor instance, several authors discuss the visualisation of specific classes of objects, generally in 4D.\n\\citet{Hoffmann90} describes methods to visualise surfaces embedded in 4D space.\n\\citet{Balsys07} render implicit (parametrised) surfaces of 4D objects as evaluated sets of points.\n\nAlso missing from this chapter was any mention of user interaction and the definition of good camera parameters, both of which are important in order to define values for the input variables described in every projection method.\n\\citet{Feiner90} implemented a system where a user sets such variables using a glove.\n\\citet{Zhang07} uses haptic controllers to explore the 3D shadows casted by 4D objects.\n\nIt is good to note that while the techniques mentioned in this chapter are also applicable to different types of objects than those used in GIS and useful for generic applications.\n\\citet{Hanson01} uses similar techniques to those mentioned here in order to visualise relativity, \\citet{Bajaj98} does so for $n$-dimensional scalar fields.\n", "meta": {"hexsha": "3aa90cff84b3f0d8926550eb2d791073158adc2c", "size": 30638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slicing.tex", "max_stars_repo_name": "kenohori/thesis", "max_stars_repo_head_hexsha": "31c026184ba535a491d6a3981c29dd897cba84b5", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 38, "max_stars_repo_stars_event_min_datetime": "2016-03-04T13:55:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T07:28:24.000Z", "max_issues_repo_path": "slicing.tex", "max_issues_repo_name": "kenohori/thesis", "max_issues_repo_head_hexsha": "31c026184ba535a491d6a3981c29dd897cba84b5", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-02-23T16:34:29.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-27T10:12:11.000Z", "max_forks_repo_path": "slicing.tex", "max_forks_repo_name": "kenohori/thesis", "max_forks_repo_head_hexsha": "31c026184ba535a491d6a3981c29dd897cba84b5", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-10-11T04:08:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-28T23:58:06.000Z", "avg_line_length": 87.787965616, "max_line_length": 568, "alphanum_fraction": 0.7642470135, "num_tokens": 8156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6835451097608617}}
{"text": "\\chapterimage{head2.png} % Chapter heading image\n\\chapter{Bayesian Inference Framework 2}\n\\section{Graphical Model}\n\\begin{definition}[Cartesian Space Graphical Model]\\label{graphmodelx}\nThe model can be shown as\n\\begin{center}\n        \\includegraphics[scale=0.8]{ch8/hmm_graphical_xspace.pdf}   \n\\end{center}\nThe joint distribution for this model is given by \n\\begin{equation}\n    p(\\textbf{y}_1,\\cdots,\\textbf{y}_N,\\textbf{x}_1,\\cdots,\\textbf{x}_N) = p(\\textbf{x}_1)\\left[\\prod_{n=2}^{N}p(\\textbf{x}_n|\\textbf{x}_{n-1})\\right]\\prod_{n=1}^{N}p(\\textbf{y}_n|\\textbf{x}_n)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Eigenspace Graphical Model]\\label{graphmodels}\nThe model can be shown as\n\\begin{center}\n    \\includegraphics[scale=0.8]{ch8/hmm_graphical_eigenspace.pdf}   \n\\end{center}\nThe joint distribution for this model is given by \n\\begin{equation}\n    p(\\textbf{y}_1,\\cdots,\\textbf{y}_N,\\textbf{s}_1,\\cdots,\\textbf{s}_N) = p(\\textbf{s}_1)\\left[\\prod_{n=2}^{N}p(\\textbf{s}_n|\\textbf{s}_{n-1})\\right]\\prod_{n=1}^{N}p(\\textbf{y}_n|\\textbf{s}_n)\n\\end{equation}\n\\end{definition}\n    \n\\section{Cartesian Space Probability Amplitude and Eigenspace Probability Vector}\n\\begin{definition}[Cartesian Space Probability and Probability Amplitude]\nGiven $p_{\\rm{eq}}(x)$\n\\begin{equation}\n    \\rho(x,0) = \\frac{p(x,0)}{\\sqrt{p_{\\rm{eq}}(x)}}\n\\end{equation}\nWe can express $\\rho(x,0)$ as the linear combination of eigenfunctions, which fully determined by $p_{\\rm{eq}}(x)$\n\\begin{equation}\n    \\rho(x,0) = \\sum_{k=1}^{N_v} a_k \\psi_{k}(x)\n\\end{equation}\nBy bra-ket notation:\n\\begin{equation}\n    \\left| \\rho_0 \\right> = \\sum_{k=1}^{N_v} a_k \\left| \\psi_{k} \\right>~~~~\\text{where}~~~\\sum_{k=1}^{N_v} a_k^2 = 1\n\\end{equation}\n\\end{definition}\n    \n\\begin{definition}[Eigenspace Probability Vector]\nWe can define a probability vector \n\\begin{equation}\n    p(\\textbf{s}, t=0) = \n    \\begin{bmatrix}\n        a_1^2 & a_2^2 & \\cdots & a_{N_v}^2\n    \\end{bmatrix}^{T}\n\\end{equation}\n\\end{definition}\n\n\\section{The Mechanism of Time Evolution}\n\\begin{definition}[Cartesian Space: $\\rho(x,\\Delta t)$]\n\\begin{equation}\n    \\rho(x,\\Delta t) = \\tilde{a}_1 \\psi_{1}(x) + \\sum_{k=2}^{N_v} a_k e^{-\\lambda_k \\Delta t}\\psi_{k}(x)\n\\end{equation}\nwhere\n\\begin{equation}\n    \\tilde{a}_1 = \\pm \\sqrt{1 - \\sum_{k=2}^{N_v} a_k^2 e^{-2\\lambda_k \\Delta t}}\n\\end{equation}\nThe sign of $\\tilde{a}_1$ is determined by $\\left<\\psi_{1}|\\rho_{\\rm{eq}}\\right>$. And we also can express the above operation in terms of bra-ket notation:\n\\begin{equation}\n    \\left< \\rho_0 \\right| e^{-\\textbf{H} \\Delta t} = \n    \\begin{bmatrix}\n        \\tilde{a}_1 & a_2 e^{-\\lambda_2 \\Delta t} & \\cdots & a_{N_v} e^{-\\lambda_{N_v} \\Delta t}\n    \\end{bmatrix}\n\\end{equation}\n\\end{definition}\n    \n\\begin{definition}[Eigenspace: $p(\\textbf{s}, \\Delta t)$]\n\\begin{equation}\n    p(\\textbf{s}, \\Delta t) = \n    \\begin{bmatrix}\n        \\tilde{a}_1^2 & a_2^2 e^{-2\\lambda_2 \\Delta t} & \\cdots & a_{N_v}^2 e^{-2\\lambda_{N_v} \\Delta t}\n    \\end{bmatrix}^{T}\n\\end{equation}\n\\end{definition}\n    \n\\begin{definition}[Eigenspace: Stochastic matrix $\\textbf{A}$]\n\\begin{equation}\n        \\textbf{A} p(\\textbf{S}, 0) = p(\\textbf{S}, \\Delta t)\n\\end{equation}\nIn terms of matrix\n\\begin{equation}\n\\begin{bmatrix}\n    A_{11} & A_{12} & \\cdots & A_{1,N_v} \\\\\n    A_{21} & A_{22} & \\cdots & A_{2,N_v} \\\\\n    \\vdots & \\vdots & \\cdots & \\vdots \\\\\n    A_{N_v,1} & A_{N_v,2} & \\cdots & A_{N_v,N_v} \n\\end{bmatrix}\n\\begin{bmatrix}\n    a_1^2 \\\\ a_2^2 \\\\ \\vdots \\\\ a_{N_v}^2\n\\end{bmatrix} =\n\\begin{bmatrix}\n    1 - \\sum_{k=2}^{N_v} a_k^2 e^{-2\\lambda_k \\Delta t} \\\\ a_2^2 e^{-2\\lambda_2 \\Delta t} \\\\ \\vdots \\\\ a_{N_v}^2 e^{-2\\lambda_{N_v} \\Delta t}\n\\end{bmatrix}\n\\end{equation}\nTherefore,\n\\begin{equation}\n\\textbf{A} = \n\\begin{bmatrix}\n    1 & 1 -  e^{-2 D_2 \\lambda'_2 \\Delta t} & \\cdots & 1 - e^{-2D_{N_v}\\lambda'_{N_v} \\Delta t} \\\\\n    0 & e^{-2D_2 \\lambda'_2 \\Delta t} & \\cdots & 0 \\\\\n    \\vdots & \\vdots & \\cdots & \\vdots \\\\\n    0 & 0 & \\cdots & e^{-2D_{N_v}\\lambda'_{N_v} \\Delta t}\n\\end{bmatrix}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.45]{ch8/A_first_row.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[D from A]\n\\begin{equation}\n    D_k = \\frac{\\ln{(1-A_{1k})}}{-2 \\lambda'_k \\Delta t}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.45]{ch8/EM_D_result_1.pdf}   \n\\end{center}\n\\begin{center}\n    \\includegraphics[scale=0.45]{ch8/EM_D_result_2.pdf}   \n\\end{center}\n\\end{definition}\n\n\\section{The Initial State}\nNow, we encode the time variable into subscripts such as $\\textbf{x}_1$,...,$\\textbf{x}_{N}$, and $\\textbf{s}_1$,...,$\\textbf{s}_{N}$\n\\begin{definition}[Cartesian Space: Probability Amplitude]\n\\begin{equation}\n    \\rho(\\textbf{x}_1) = \\sum_{k=1}^{N_v} \\pi_k \\psi_k(x_1)\n\\end{equation}\nBy bra-ket notation:\n\\begin{equation}\n    \\left< \\rho_1 \\right| = \\sum_{k=1}^{N_v} \\pi_k \\left< \\psi_k \\right|\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Eigenspace: Probability Vector]\n\\begin{equation}\n        p(\\textbf{s}_1) = \n\\begin{bmatrix}\n        \\pi_1^2 & \\pi_2^2 & \\cdots & \\pi_{N_v}^2\n\\end{bmatrix}^{T}\n~~~~~\\text{where}~~\\sum_{k=1}^{N_v}\\pi_{k}^2=1\n\\end{equation}\n\\end{definition}\n\n\\section{Photon-Operator and Emission Probability}\n\\begin{definition}[Cartesian Space: Photon Operator]\nGiven $\\textbf{y}_n=\\mu_n$, the photon operator $\\hat{\\textbf{y}}_n$ is defined by a normal distribution\n\\begin{equation}\n    \\hat{\\textbf{y}}_n = N(\\mu_n,\\sigma ^{2}) = f_n(x)\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.45]{ch2/photon_mat_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[Cartesian Space: Emission Probability]\n\\begin{equation}\n    p(\\textbf{y}_n|\\textbf{x}_n) = N(\\mu_n=\\textbf{x}_n,\\sigma ^{2})\n\\end{equation}\nand\n\\begin{equation}\n    p(\\textbf{y}_n|\\textbf{s}_n)\n\\end{equation}   \n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/emission_prob_illu.pdf}   \n\\end{center}\n\n\\end{definition}\n\n\\begin{definition}[Eigenspace: Photon Operator]\nTransform $\\hat{\\textbf{y}}_n$ from Cartesian space to eigenspace $\\textbf{y}_n$, and the element of $\\textbf{y}_n$:\n\\begin{equation}\n    y_{ij} = \\langle \\psi_i | \\hat{\\textbf{y}}_{n} | \\psi_j \\rangle = \\int \\psi_i(x) f_n(x) \\psi_j(x) dx\n\\end{equation}\nFor example, \n\\begin{align*}\n    \\left< \\rho_1 \\right| \\textbf{y}_1 &=\\begin{bmatrix}\n        \\pi_1 & \\pi_2 & \\cdots & \\pi_{N_v}\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        y_{11} & y_{12} & \\cdots & y_{1,N_v} \\\\\n        y_{21} & y_{22} & \\cdots & y_{2,N_v} \\\\\n        \\vdots & \\vdots & \\cdots & \\vdots \\\\\n        y_{N_v, 1} & y_{12} & \\cdots & y_{N_v,N_v}\n    \\end{bmatrix}\\\\\n    &=\\begin{bmatrix}\n        \\sum_{k=1}^{N_v}\\pi_k y_{k1} & \\sum_{k=1}^{N_v}\\pi_k y_{k2} & \\cdots & \\sum_{k=1}^{N_v}\\pi_k y_{k,N_v}\n    \\end{bmatrix}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Eigenspace: Emission Probability]\nIn our case, the form of emission probability $p(\\textbf{y}_n|\\textbf{s}_n)$ is complicated. But we always can use the photon operator to get the target joint probability. For example,\n\\begin{align*}\n    &p(\\textbf{y}_1,\\textbf{s}_1) = p(\\textbf{s}_1)p(\\textbf{y}_1|\\textbf{s}_1)\\\\\n    &=\\begin{bmatrix}\n        \\left(\\sum_{k=1}^{N_v}\\pi_k y_{k1}\\right)^2 & \\left(\\sum_{k=1}^{N_v}\\pi_k y_{k2}\\right)^2 & \\cdots & \\left(\\sum_{k=1}^{N_v}\\pi_k y_{k,N_v}\\right)^2\n    \\end{bmatrix}\n\\end{align*}\n\\end{definition}\n\n\\section{Expectation Maximization in Eigenspace}\n\\begin{definition}[E-step: $Q(\\bm{\\theta}, \\bm{\\theta}^{\\text{old}})$]\nFind the posterior distribution of the latent variables\n\\begin{equation}\n    p(\\bm{S}|\\textbf{Y}, \\bm{\\theta}^{\\rm{old}})\n\\end{equation}\nThen, use it to evaluate the expectation of the logarithm of the complete-data likelihodd function\n\\begin{equation}\n    Q(\\bm{\\theta}, \\bm{\\theta}^{\\text{old}}) = \\sum_{\\textbf{S}}p(\\textbf{S}|\\textbf{Y}, \\bm{\\theta}^{\\rm{old}}) \\ln{p(\\textbf{Y},\\textbf{S}|\\bm{\\theta})}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[E-step: $\\gamma$, $\\xi$]\n$\\gamma(\\textbf{s}_n)$ is the marginal posterior distribution of a latent variable $\\textbf{s}_n$\n\\begin{equation}\n    \\gamma(\\textbf{s}_n) = p(\\textbf{s}_n|\\textbf{Y},\\bm{\\theta}^{\\text{old}})\n\\end{equation}\nand $\\xi(\\textbf{s}_{n-1},\\textbf{s}_n)$ is the joint posterior distribution of two successive latent variables\n\\begin{equation}\n    \\xi(\\textbf{s}_{n-1},\\textbf{s}_n) = p(\\textbf{s}_{n-1},\\textbf{s}_n|\\textbf{Y},\\bm{\\theta}^{\\text{old}})\n\\end{equation}\nBy using these two posterior probability, we can rewrite $Q(\\bm{\\theta}, \\bm{\\theta}^{\\text{old}})$\n\\begin{equation}\n    Q(\\bm{\\theta}, \\bm{\\theta}^{\\text{old}}) = \\sum_{k=1}^{N_v}\\gamma(s_{1k})\\ln{\\pi_k} + \\sum_{n=2}^{N}\\sum_{j=1}^{N_v}\\sum_{k=1}^{N_v} \\xi(s_{n-1,j},~s_{nk})\\ln{A_{jk}} + \\sum_{n=1}^{N}\\sum_{k=1}^{N_v} \\gamma(s_{nk}) \\ln{p(\\textbf{y}_n|\\phi_k)}\n\\end{equation} \n\\end{definition}\n\n\\begin{definition}[M-step]\nMaximize $Q(\\bm{\\theta}, \\bm{\\theta}^{\\text{old}})$ with respect to the parameter $\\bm{\\theta}=\\{\\pi, \\textbf{A}, \\phi\\}$ in which we treat $\\gamma(\\textbf{s}_n)$ and $\\xi(\\textbf{s}_{n-1},\\textbf{s}_n)$ as constant. We get\n\\begin{equation}\n    \\pi_k = \\frac{\\gamma(s_{1k})}{\\sum_{j=1}^{N_v}\\gamma(s_{1j})}\n\\end{equation}\nand\n\\begin{equation}\n    A_{jk} = \\frac{ \\sum_{n=2}^{N} \\xi(s_{n-1,j},~s_{nk}) }{ \\sum_{l=1}^{N_v}\\sum_{n=2}^{N} \\xi(s_{n-1,j},~s_{nl}) }\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[M-step: Example]\nSay we have two states, so\n\\begin{align*}\n    A = \\begin{bmatrix}\n        A_{11} & A_{12} \\\\\n        A_{21} & A_{22}\n    \\end{bmatrix}\n\\end{align*}\nand \n\\begin{align*}\n    A_{11} + A_{12} &= 1 \\\\\n    A_{21} + A_{22} &= 2\n\\end{align*}\nand\n\\begin{align*}\n    \\tilde{Q} &= \\xi(s_{1,1},~s_{2,1})\\ln{A_{11}} + \\xi(s_{1,1},~s_{2,2})\\ln{A_{12}} + \\xi(s_{1,2},~s_{2,1})\\ln{A_{21}} + \\xi(s_{1,2},~s_{2,2})\\ln{A_{22}} \\\\\n    &= \\xi(s_{1,1},~s_{2,1})\\ln{A_{11}} + \\xi(s_{1,1},~s_{2,2})\\ln{(1-A_{11})} + \\xi(s_{1,2},~s_{2,1})\\ln{A_{21}}\\\\\n    & + \\xi(s_{1,2},~s_{2,2})\\ln{(1-A_{21})}\n\\end{align*}\nand\n\\begin{align*}\n    \\frac{d \\tilde{Q}}{dA_{11}} = \\frac{\\xi(s_{1,1},~s_{2,1})}{A_{11}}-\\frac{\\xi(s_{1,1},~s_{2,2})}{1-A_{11}} = 0\n\\end{align*}\nso \n\\begin{align*}\n    \\frac{\\xi(s_{1,1},~s_{2,1})}{A_{11}} &= \\frac{\\xi(s_{1,1},~s_{2,2})}{1-A_{11}} \\\\\n    \\xi(s_{1,1},~s_{2,1}) - A_{11}  \\xi(s_{1,1},~s_{2,1}) &= \\xi(s_{1,1},~s_{2,2}) A_{11} \\\\\n    A_{11} &= \\frac{\\xi(s_{1,1},~s_{2,1})}{\\xi(s_{1,1},~s_{2,1})+ \\xi(s_{1,1},~s_{2,2})}\n\\end{align*}\n\\end{definition}\n\n\\section{Forward-Backward Algorithm}\nWe seek an efficient procedure for evaluating the quantities $\\gamma(s_{nk})$ and $\\xi(s_{n-1,j},~s_{nk})$, corresponding to the E step of the EM algorithm.\n\n\\begin{definition}[$\\gamma$,$\\alpha$,$\\beta$]\n\\begin{equation}\n    \\gamma(\\textbf{s}_n) = p(\\textbf{s}_n|\\textbf{Y})\n\\end{equation}\nUsing the conditional independence property,\n\\begin{equation}\n    \\gamma(\\textbf{s}_n) = \\frac{ p(\\textbf{y}_1,\\cdots,\\textbf{y}_n,\\textbf{s}_n) p(\\textbf{y}_{n+1},\\cdots,\\textbf{y}_N|\\textbf{s}_n) }{p(\\textbf{Y})} = \\frac{ \\alpha(\\textbf{s}_n) \\beta(\\textbf{s}_n) }{p(\\textbf{Y})}\n\\end{equation}\nwhere we have defined\n\\begin{align}\n    \\alpha(\\textbf{s}_n) &= p(\\textbf{y}_1,\\cdots,\\textbf{y}_n,\\textbf{s}_n) \\\\\n    \\beta(\\textbf{s}_n) &= p(\\textbf{y}_{n+1},\\cdots,\\textbf{y}_N|\\textbf{s}_n)\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[$\\alpha(\\textbf{s}_n)$]\nIn terms of probability amplitude:\n\\begin{equation}\n    \\left< \\alpha_{n} \\right| = \\left< \\alpha_{n-1} \\right| e^{-\\textbf{H} \\Delta t} \\textbf{y}_n\n\\end{equation}\nand the probability vector in eigenspace is \n\\begin{equation}\n    \\alpha(\\textbf{s}_n) =\n    \\begin{bmatrix}\n        \\left(\\left< \\alpha_{n} | \\psi_1 \\right>\\right)^2 & \\left(\\left< \\alpha_{n} | \\psi_2 \\right>\\right)^2 & \\cdots & \\left(\\left< \\alpha_{n} | \\psi_{N_v} \\right>\\right)^2\n    \\end{bmatrix}^{T}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[$\\beta(\\textbf{s}_n)$]\nIn terms of probability amplitude:\n\\begin{equation}\n    \\left| \\beta_{n} \\right> =  e^{-\\textbf{H} \\Delta t} \\textbf{y}_{n+1}  \\left| \\beta_{n+1} \\right> \n\\end{equation}\nand the probability vector in eigenspace is \n\\begin{equation}\n    \\beta(\\textbf{s}_n) =\n    \\begin{bmatrix}\n        \\left(\\left< \\psi_1 | \\beta_{n} \\right>\\right)^2 & \\left(\\left<  \\psi_2 | \\beta_{n} \\right>\\right)^2 & \\cdots & \\left(\\left< \\psi_{N_v} | \\beta_{n} \\right>\\right)^2\n    \\end{bmatrix}^{T}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[$\\xi(\\textbf{s}_{n-1},~\\textbf{s}_{n})$]\n\\begin{equation}\n    \\xi(\\textbf{s}_{n-1},~\\textbf{s}_{n}) = \\frac{\\alpha(\\textbf{s}_{n-1}) p(\\textbf{y}_n|\\textbf{s}_n) p(\\textbf{s}_n|\\textbf{s}_{n-1}) \\beta(\\textbf{s}_n) }{p(\\textbf{Y})}\n\\end{equation}\n\\end{definition}\n\n\\section{Forward-Backward Algorithm: Scaling Factor}\n\\begin{definition}[Scaling Factor $c_n$]\n\\begin{equation}\n    c_n = p(\\textbf{y}_n|\\textbf{y}_1,\\cdots,\\textbf{y}_{n-1})\n\\end{equation}\nFrom the product rule, we then have\n\\begin{equation}\n    p(\\textbf{y}_1,\\cdots,\\textbf{y}_{n}) = \\prod_{m=1}^{n}c_m\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[$\\hat{\\alpha}$]\nIn terms of probability amplitude and bra-ket notation:\n\\begin{equation}\n    \\left< \\hat{\\alpha}_n \\right| = \\frac{ \\left< \\hat{\\alpha}_{n-1} \\right| e^{-\\textbf{H}\\Delta t} \\textbf{y}_n }{ \\norm{\\left< \\hat{\\alpha}_{n-1} \\right| e^{-\\textbf{H}\\Delta t} \\textbf{y}_n} }\n\\end{equation}\nand the scaling factor is\n\\begin{equation}\n    c_n = \\norm{\\left< \\hat{\\alpha}_{n-1} \\right| e^{-\\textbf{H}\\Delta t} \\textbf{y}_n}^2\n\\end{equation}\nFor the probability vector in eigenspace, we define a normalized version of $\\alpha$ given by \n\\begin{equation}\n    \\hat{\\alpha}(\\textbf{s}_n) = p(\\textbf{s}_n|\\textbf{y}_1,\\cdots,\\textbf{y}_n) = \\frac{\\alpha(\\textbf{s}_n)}{p(\\textbf{y}_1,\\cdots,\\textbf{y}_n)}\n\\end{equation}\nand \n\\begin{equation}\n    \\hat{\\alpha}(\\textbf{s}_n) = \n    \\begin{bmatrix}\n        \\left(\\left< \\hat{\\alpha}_n | \\psi_1 \\right>\\right)^2 & \\left(\\left< \\hat{\\alpha}_n | \\psi_2 \\right>\\right)^2 & \\cdots & \\left(\\left< \\hat{\\alpha}_n | \\psi_{N_v} \\right>\\right)^2 \n    \\end{bmatrix}^{T}\n\\end{equation}\nand it should satisfy $\\sum_{k=1}^{N_v} \\left(\\left< \\hat{\\alpha}_n | \\psi_k \\right>\\right)^2 = 1$\n\\end{definition}\n\n\\begin{definition}[$\\gamma$]\nIn Cartesian space,\n\\begin{equation}\n    \\gamma(\\textbf{x}_n) = p(\\textbf{x}_n| \\textbf{Y}) = \\left(\\left< \\hat{\\alpha}_n | x \\right> \\right)^2 \\left( \\left<  x | \\hat{\\beta}_n \\right> \\right)^2\n\\end{equation}\nand the probability amplitude of $\\gamma(\\textbf{x}_n)$ is \n\\begin{equation}\n    \\left| \\gamma_n \\right> = \\sum_{k=1}^{N_v} g_k \\left| \\psi_k \\right>\n\\end{equation}\nwhere $g_k$ is \n\\begin{equation}\n    g_k = \\int (\\gamma(x_n))^{1/2} \\psi_k(x_n) dx_n\n\\end{equation} \nThen,\n\\begin{equation}\n    \\gamma(\\textbf{s}_n) =\n    \\begin{bmatrix}\n        g^2_1 & g^2_2 & \\cdots & g^2_{N_v}\n    \\end{bmatrix}\n\\end{equation}\nNote\n\\begin{align}\n    \\int \\gamma(\\textbf{x}_n) d\\textbf{x}_n &= 1 \\\\\n    \\sum_{\\textbf{s}_n} \\gamma(\\textbf{s}_n) &= 1 \\\\\n    \\norm{\\left| \\gamma_n \\right>}&= 1\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[$r~$: Scaling factor for $\\beta$]\nFor the last index of photon $N$,\n\\begin{align}\n    r_N = \\int \\left(\\left< \\hat{\\alpha}_N | x \\right> \\right)^2 \\left( \\left<  x | \\beta_N \\right> \\right)^2 dx = 1\n\\end{align}\nFor other index $n$,\n\\begin{align}\n    r_n = \\int \\left(\\left< \\hat{\\alpha}_n | x \\right> \\right)^2 \\left( \\left< x | e^{-\\textbf{H} \\Delta t} \\textbf{y}_{n+1} | \\hat{\\beta}_{n+1} \\right> \\right)^2 dx\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[$\\hat{\\beta}_N$]\nBecause $r_N=1$\n\\begin{equation}\n    \\left| \\hat{\\beta}_{N} \\right> = \\frac{\\left| \\beta_{N} \\right>}{\\sqrt{r_{N}}} = \\left| \\beta_{N} \\right>\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[$\\hat{\\beta}_n$]\nIn terms of probability amplitude and bra-ket notation:\n\\begin{equation}\n    \\left| \\hat{\\beta}_{n} \\right> = \\frac{e^{-\\textbf{H}\\Delta t}\\textbf{y}_{n+1}\\left| \\hat{\\beta}_{n+1} \\right>}{\\sqrt{r_{n}}}\n\\end{equation}\nNote that \n\\begin{equation}\n    \\left<\\hat{\\alpha}_{n} | \\hat{\\beta}_{n} \\right> = 1~~~\\forall~~n\\neq N\n\\end{equation}\nand\n\\begin{equation}\n    \\hat{\\beta}(\\textbf{s}_n) = \n    \\begin{bmatrix}\n        \\left(\\left< \\psi_1 | \\hat{\\beta}_{n} \\right>\\right)^2 &\\left(\\left< \\psi_2 | \\hat{\\beta}_{n} \\right>\\right)^2 & \\cdots & \\left(\\left< \\psi_{N_v} | \\hat{\\beta}_{n} \\right>\\right)^2\n    \\end{bmatrix}^{T}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Check the consistency for $r_n$ and $\\hat{\\beta}$]\nSince the posterior probability should satisfy\n\\begin{equation}\n    \\int \\gamma(\\textbf{x}_n) d\\textbf{x}_n = 1\n\\end{equation}\nand we know that\n\\begin{align*}\n    \\int \\gamma(\\textbf{x}_n) d\\textbf{x}_n &= \\int \\left(\\left< \\hat{\\alpha}_n | x \\right> \\right)^2 \\left( \\left<  x | \\hat{\\beta}_n \\right> \\right)^2 d\\textbf{x}_n \\\\\n    &= \\int \\left(\\left< \\hat{\\alpha}_n | x \\right> \\right)^2  \\left( \\frac{\\left< x|e^{-\\textbf{H}\\Delta t}\\textbf{y}_{n+1}| \\hat{\\beta}_{n+1} \\right>}{\\sqrt{r_{n}}}\\right)^2 d\\textbf{x}_n\n\\end{align*}\nso \n\\begin{equation}\n    \\int \\gamma(\\textbf{x}_n) d\\textbf{x}_n = \\frac{1}{r_n} \\int \\left(\\left< \\hat{\\alpha}_n | x \\right> \\right)^2  \\left( \\left< x|e^{-\\textbf{H}\\Delta t}\\textbf{y}_{n+1}| \\hat{\\beta}_{n+1} \\right>\\right)^2 d\\textbf{x}_n = 1\n\\end{equation}\nand we finally get\n\\begin{align*}\n    r_n = \\int \\left(\\left< \\hat{\\alpha}_n | x \\right> \\right)^2  \\left( \\left< x|e^{-\\textbf{H}\\Delta t}\\textbf{y}_{n+1}| \\hat{\\beta}_{n+1} \\right>\\right)^2 d\\textbf{x}_n\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Likelihood Function $p(\\textbf{Y})$]\n\\begin{equation}\n    p(\\textbf{Y}) = \\prod_{n=1}^{N}c_n\n\\end{equation}\nand log-likelihood is \n\\begin{equation}\n    \\ln{p(\\textbf{Y})} = \\sum_{n=1}^{N}\\ln{c_n}\n\\end{equation}\n\\end{definition}\n\n\n\n\\begin{definition}[$\\xi$]\n\\begin{equation}\n    \\xi(\\textbf{s}_{n-1},\\textbf{s}_n) = c_n^{-1} \\hat{\\alpha}(\\textbf{s}_{n-1}) p(\\textbf{y}_n|\\textbf{s}_n) p(\\textbf{s}_n|\\textbf{s}_{n-1}) \\hat{\\beta}(\\textbf{s}_n)\n\\end{equation}\nThe matrix form is \n\\begin{equation}\n    \\xi(\\textbf{s}_{n-1},\\textbf{s}_n) = \n    \\begin{bmatrix}\n        \\xi(s_{n-1,1},~s_{n1}) & \\xi(s_{n-1,1},~s_{n2}) & \\cdots & \\xi(s_{n-1,1},~s_{n,N_v}) \\\\\n        \\xi(s_{n-1,2},~s_{n1}) & \\xi(s_{n-1,2},~s_{n2}) & \\cdots & \\xi(s_{n-1,2},~s_{n,N_v}) \\\\\n        \\vdots & \\vdots & \\cdots & \\vdots \\\\\n        \\xi(s_{n-1,N_v},~s_{n1}) & \\xi(s_{n-1,N_v},~s_{n2}) & \\cdots & \\xi(s_{n-1,N_v},~s_{n,N_v})\n    \\end{bmatrix}\n\\end{equation}\nWe also can use bra-ket notation to get the matrix\n\\begin{equation}\n\\xi(\\textbf{s}_{n-1},\\textbf{s}_{n}) = \\frac{\\left( \\textbf{y}_n | \\hat{\\beta}_n \\left>\\right<\\hat{\\alpha}_{n-1} |e^{-\\textbf{H}\\Delta t}\\right)^2}{c_n}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Example: $\\xi$]\n\\begin{equation}\n    \\xi(\\textbf{s}_{4},\\textbf{s}_{5}) = p(\\textbf{s}_{4},\\textbf{s}_{5}|\\textbf{Y})\n\\end{equation}\nThe following graphical model shows $\\xi(\\textbf{s}_{4},\\textbf{s}_{5})$\n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/xi_meaning_graphical.pdf}   \n\\end{center}\nand the following shows $\\alpha(\\textbf{s}_{4})$ and $\\beta(\\textbf{s}_5)$\n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/xi_alpha_beta_meaning_graphical.pdf}   \n\\end{center}\nThen,\n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/xi_alpha_eHdt.pdf}   \n\\end{center}\n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/xi_y_beta.pdf}   \n\\end{center}\nand\n\\begin{equation}\n    p(\\textbf{s}_{4},\\textbf{s}_{5},\\textbf{Y}) = \\left( \\textbf{y}_5\\left| \\beta_5 \\right>\\left<\\alpha_4\\right|e^{-\\textbf{H}\\Delta t}\\right)^2\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/xi_ybeta_alphaeHdt.pdf}   \n\\end{center}\nThen, because\n\\begin{equation}\n    \\xi(\\textbf{s}_{4},\\textbf{s}_{5}) = p(\\textbf{s}_{4},\\textbf{s}_{5}|\\textbf{Y}) = \\frac{p(\\textbf{s}_{4},\\textbf{s}_{5},\\textbf{Y})}{p(\\textbf{Y})} = \\frac{p(\\textbf{s}_{4},\\textbf{s}_{5},\\textbf{Y})}{\\prod_{m=1}^{7}c_m}\n\\end{equation}\nwe also know\n\\begin{align}\n    \\left< \\hat{\\alpha}_{4} \\right| &= \\frac{\\left< \\alpha_4 \\right|}{\\left(\\prod_{m=1}^{4}c_m\\right)^{1/2}} \\\\\n    \\left| \\hat{\\beta}_5 \\right> &= \\frac{\\left| \\beta_5 \\right>}{\\left(\\prod_{m=6}^{7}c_m\\right)^{1/2}} \n\\end{align}\nTherefore, we get\n\\begin{equation}\n    \\xi(\\textbf{s}_{4},\\textbf{s}_{5}) = \\frac{\\left( \\textbf{y}_5 | \\hat{\\beta}_5 \\left>\\right<\\hat{\\alpha}_4 |e^{-\\textbf{H}\\Delta t}\\right)^2}{c_5}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[First Part: $\\xi(\\textbf{x}_4, \\textbf{x}_5)$]\n\\begin{align}\n    \\left(\\left<\\hat{\\alpha}_4| x \\right>\\right)^2 &= p(\\textbf{x}_4 | \\textbf{y}_1,...,\\textbf{y}_4)\\\\\n    \\left(\\left<\\hat{\\alpha}_4|e^{-\\textbf{H}\\Delta t} | x \\right>\\right)^2 &= p(\\textbf{x}_5| \\textbf{y}_1,...,\\textbf{y}_4,\\textbf{x}_4)\n\\end{align}\nand\n\\begin{align*}\n    \\left(\\left<\\hat{\\alpha}_4| x \\right>\\right)^2 \\left(\\left<\\hat{\\alpha}_4|e^{-\\textbf{H}\\Delta t} | x \\right>\\right)^2 = p(\\textbf{x}_4, \\textbf{x}_5 | \\textbf{y}_1,...,\\textbf{y}_4)\n\\end{align*}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/p_x4_x5_given_y1toy4.pdf}   \n\\end{center}\nIn bra-ket form:\n\\begin{equation}\n    p(\\textbf{s}_4, \\textbf{s}_5 | \\textbf{y}_1,...,\\textbf{y}_4) = \\left( \\left| \\hat{\\alpha}_4 \\right> \\left<\\hat{\\alpha}_4 \\right| e^{-\\textbf{H}\\Delta t} \\right)^2\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/p_s4_s5_given_y1toy4.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[Second Part: $\\xi(\\textbf{x}_4, \\textbf{x}_5)$]\n\\begin{align}\n   \\left( \\left< x| \\hat{\\beta}_5 \\right> \\right)^2 &= \\frac{p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{x}_5)}{p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{y}_1,...,\\textbf{y}_5)} \\\\\n   \\left( \\left< x| \\textbf{y}_5 | \\hat{\\beta}_5 \\right> \\right)^2 &= \\frac{p(\\textbf{y}_5 |\\textbf{x}_5) p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{x}_5)}{p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{y}_1,...,\\textbf{y}_5)} = \\frac{p(\\textbf{y}_5,...,\\textbf{y}_N|\\textbf{x}_5)}{p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{y}_1,...,\\textbf{y}_5)}\n\\end{align}\nand\n\\begin{equation}\n    \\left( \\frac{\\left< x| \\textbf{y}_5 | \\hat{\\beta}_5 \\right>}{ \\norm{\\textbf{y}_5 \\left| \\hat{\\beta}_5 \\right>}} \\right)^2 = \\frac{p(\\textbf{y}_5,...,\\textbf{y}_N|\\textbf{x}_5)}{p(\\textbf{y}_5|\\textbf{y}_1,...,\\textbf{y}_4) p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{y}_1,...,\\textbf{y}_5)}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/beta_x5_xi.pdf}   \n\\end{center}\nIn eigenspace\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/beta_s5_xi.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[Third Part: $\\xi(\\textbf{x}_4, \\textbf{x}_5)$]\n\\begin{align*}\n    &\\left(\\left<\\hat{\\alpha}_4| x \\right>\\right)^2 \\left(\\left<\\hat{\\alpha}_4|e^{-\\textbf{H}\\Delta t} | x \\right>\\right)^2 \\left( \\frac{\\left< x| \\textbf{y}_5 | \\hat{\\beta}_5 \\right>}{ \\norm{\\textbf{y}_5 \\left| \\hat{\\beta}_5 \\right>}} \\right)^2 \\\\\n    &= \\frac{p(\\textbf{x}_4, \\textbf{x}_5, \\textbf{y}_1,...,\\textbf{y}_4)}{p(\\textbf{y}_1,...,\\textbf{y}_4)} \\frac{p(\\textbf{y}_5,...,\\textbf{y}_N|\\textbf{x}_5)}{p(\\textbf{y}_5|\\textbf{y}_1,...,\\textbf{y}_4) p(\\textbf{y}_6,...,\\textbf{y}_N|\\textbf{y}_1,...,\\textbf{y}_5)} \\\\\n    &= \\frac{p(\\textbf{x}_4, \\textbf{x}_5, \\textbf{y}_1,...,\\textbf{y}_N)}{p(\\textbf{y}_1,...,\\textbf{y}_N)} \\\\\n    &= p(\\textbf{x}_4, \\textbf{x}_5|\\textbf{Y}) = \\xi(\\textbf{x}_4, \\textbf{x}_5)\n\\end{align*}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/xi_1.pdf}   \n\\end{center}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/xi_2.pdf}   \n\\end{center}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/xi_3.pdf}   \n\\end{center}\n\\end{definition}\n\n\\section{Forward-Backward: Example}\nWe will use the following graphical model as an example to check the detail of calculation:\n\\begin{center}\n    \\includegraphics[scale=0.6]{ch8/five_states_example.pdf}   \n\\end{center}\n\n\\subsection{Forward Part}\n\\begin{definition}[$p(\\textbf{s}_1)$]\nWe let $p(\\textbf{x}_1)=p_{\\rm{eq}}(x)$\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/pi_example.pdf}   \n\\end{center}\nThe probability amplitude $\\rho_1$ is \n\\begin{equation}\n    \\left< \\rho_{1} \\right| = \\left(p(\\textbf{s}_1)\\right)^{1/2}\n\\end{equation}  \n\\end{definition}\n\n\\begin{definition}[$\\alpha(\\textbf{s}_1)$]\n\\begin{equation}\n    \\left< \\alpha_{1} \\right| = \\left< \\rho_{1} \\right| \\textbf{y}_1\n\\end{equation}\nand \n\\begin{equation}\n    \\alpha(\\textbf{s}_1) = p(\\textbf{s}_1, \\textbf{x}_1) = \\begin{bmatrix}\\left(\\left< \\alpha_{1} | \\psi_1 \\right>\\right)^2 & \\left(\\left< \\alpha_{1} | \\psi_2 \\right>\\right)^2 & \\cdots & \\left(\\left< \\alpha_{1} | \\psi_{N_v} \\right>\\right)^2 \\end{bmatrix}^{T}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/alpha1_example.pdf}   \n\\end{center}\nThen, we do normalization\n\\begin{equation}\n    \\left< \\hat{\\alpha}_{1} \\right| = \\frac{\\left< \\alpha_{1} \\right|}{\\norm{\\left< \\alpha_{1} \\right|}}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/alpha_hat_1_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[$\\alpha(\\textbf{s}_2)$]\n\\begin{equation}\n    \\left< \\hat{\\alpha}_{1} \\right| e^{-\\textbf{H}\\Delta t}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/alpha_hat_1_edt_example.pdf}   \n\\end{center}\n\\begin{equation}\n    \\left< \\hat{\\alpha}_{1} \\right| e^{-\\textbf{H}\\Delta t}\\textbf{y}_2\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/alpha_hat_1_edt_y2_example.pdf}   \n\\end{center}\n\\begin{equation}\n    \\left< \\hat{\\alpha}_{2} \\right| = \\frac{\\left< \\hat{\\alpha}_{1} \\right| e^{-\\textbf{H}\\Delta t}\\textbf{y}_2}{\\norm{\\left< \\hat{\\alpha}_{1} \\right| e^{-\\textbf{H}\\Delta t}\\textbf{y}_2}}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/alpha_hat_2_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\subsection{Posterior Probability}\n\\begin{definition}[Special case: $p(\\textbf{x}_N|\\textbf{Y})$]\n\\begin{equation}\n    p(\\textbf{x}_N | \\textbf{Y}) =\\frac{(\\left<\\alpha_{N}|\\textbf{x} \\right>)^2 (\\left<\\textbf{x}|\\beta_{N} \\right>)^2 }{p(\\textbf{Y})}\n\\end{equation}\nwhere\n\\begin{align}\n    (\\left<\\alpha_{N}|\\textbf{x} \\right>)^2 &=  p(\\textbf{y}_1,\\cdots,\\textbf{y}_N,\\textbf{x}_N) = p(\\textbf{Y}, \\textbf{x}_N) \\\\\n    (\\left<\\textbf{x}|\\beta_{N} \\right>)^2 &= p(\\textbf{y}_{N+1}|\\textbf{x}_{N})\\text{~~~Some problem here!}\n\\end{align}\nAs you can see, we can not define $\\left<\\textbf{x}|\\beta_{N} \\right>$ because there is no $y_{N+1}$. Also, we notice\n\\begin{align*}\n    p(\\textbf{x}_N | \\textbf{Y}) = \\frac{(\\left<\\alpha_{N}|\\textbf{x} \\right>)^2}{p(\\textbf{Y})} = \\frac{p(\\textbf{Y}, \\textbf{x}_N)}{p(\\textbf{Y})}\n\\end{align*}\nTherefore, we just define\n\\begin{equation}\n    \\left<\\textbf{x}|\\beta_{N} \\right>=1~~\\forall \\textbf{x}\n\\end{equation}\n\\end{definition}\n\n\\subsection{Backward Part}\n\\begin{definition}[$\\beta(\\textbf{s}_5)$]\nBecause\n\\begin{equation}\n    \\left<\\textbf{x}|\\beta_{5} \\right>=1~~\\forall \\textbf{x}\n\\end{equation}\nso\n\\begin{equation}\n    \\beta(\\textbf{x}_5) = \\left(\\left<\\textbf{x}|\\beta_{5} \\right>\\right)^2=1~~\\forall \\textbf{x}\n\\end{equation}\nand\n\\begin{equation}\n    \\left<\\textbf{x}|\\beta_{5} \\right>=1=\\sum_{k=1}^{N_v}b_k\\psi_k(\\textbf{x})\n\\end{equation}\nso\n\\begin{equation}\n    \\left| \\beta_{5} \\right> = \n    \\begin{bmatrix}\n        b_1 & b_2 & \\cdots & b_{N_v}\n    \\end{bmatrix}^T\n\\end{equation}\nand \n\\begin{equation}\n    \\beta(\\textbf{s}_5)= \n    \\begin{bmatrix}\n        b^2_1 & b^2_2 & \\cdots & b^2_{N_v}\n    \\end{bmatrix}^T\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/beta_s5_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[$\\hat{\\beta}(\\textbf{s}_5)$]\nFirst, in Cartesian space \n\\begin{equation}\n    \\gamma(\\textbf{x}_5) = p(\\textbf{x}_5| \\textbf{Y}) = \\left(\\left< \\hat{\\alpha}_5 | x \\right> \\right)^2 \\left( \\left<  x | \\hat{\\beta}_5 \\right> \\right)^2 =  \\left(\\left< \\hat{\\alpha}_5 | x \\right> \\right)^2\n\\end{equation}\nTherefore,\n\\begin{equation}\n    \\left<  x | \\hat{\\beta}_5 \\right> = 1~~~\\forall~x\n\\end{equation}\nso\n\\begin{align}\n    \\left| \\hat{\\beta}_{5} \\right> &= \n    \\begin{bmatrix}\n        b_1 & b_2 & \\cdots & b_{N_v}\n    \\end{bmatrix}^T \\\\\n    \\hat{\\beta}(\\textbf{s}_5) &= \n    \\begin{bmatrix}\n        b^2_1 & b^2_2 & \\cdots & b^2_{N_v}\n    \\end{bmatrix}^T\n\\end{align}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/beta_hat_s5_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[$\\gamma(\\textbf{s}_5)$]\nWe start from\n\\begin{align}\n    \\gamma(\\textbf{x}_5) &= \\left(\\left< \\hat{\\alpha}_5 | x \\right> \\right)^2 \\\\\n    \\left| \\gamma_5 \\right> &= \\sum_{k=1}^{N_v} g_k \\left| \\psi_k \\right>\n\\end{align}\nThen\n\\begin{equation}\n    \\gamma(\\textbf{s}_5) =\n    \\begin{bmatrix}\n        g^2_1 & g^2_2 & \\cdots & g^2_{N_v}\n    \\end{bmatrix}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/gamma5_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[$\\beta(\\textbf{s}_4)$]\n\\begin{equation}\n    e^{-\\textbf{H}\\Delta t}\\textbf{y}_{5}\\left| \\hat{\\beta}_{5} \\right>\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/y_beta5.pdf}   \n\\end{center}\n\\begin{equation}\n    \\left| \\hat{\\beta}_4 \\right> = \\frac{e^{-\\textbf{H}\\Delta t}\\textbf{y}_{5}\\left| \\hat{\\beta}_{5} \\right>}{\\sqrt{r_5}}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/beta4_example.pdf}   \n\\end{center}\n\\end{definition}\n\n\\begin{definition}[$\\beta(\\textbf{s}_3)$]\n\\begin{equation}\n    e^{-\\textbf{H}\\Delta t}\\textbf{y}_{4}\\left| \\hat{\\beta}_{4} \\right>\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/y_beta4.pdf}   \n\\end{center}\n\\begin{equation}\n    \\left| \\hat{\\beta}_3 \\right> = \\frac{e^{-\\textbf{H}\\Delta t}\\textbf{y}_{4}\\left| \\hat{\\beta}_{4} \\right>}{\\sqrt{r_4}}\n\\end{equation}\n\\begin{center}\n    \\includegraphics[scale=0.4]{ch8/beta3_example.pdf}   \n\\end{center}\n\\end{definition}\n", "meta": {"hexsha": "91bd5e63fcb7e6593a36f1f2daa2e05bff42963b", "size": 29660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/chapter8.tex", "max_stars_repo_name": "yizaochen/em_theory", "max_stars_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_stars_repo_licenses": ["MIT"], "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/chapter8.tex", "max_issues_repo_name": "yizaochen/em_theory", "max_issues_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_issues_repo_licenses": ["MIT"], "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/chapter8.tex", "max_forks_repo_name": "yizaochen/em_theory", "max_forks_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_forks_repo_licenses": ["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.1809775429, "max_line_length": 335, "alphanum_fraction": 0.6304787593, "num_tokens": 12122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6835268283018674}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{The circle}\n\\index{circle|(}\n\\index{inductive type!circle|(}\n\nWe have seen inductive types, in which we describe a type by its constructors and an induction principle that allows us to construct sections of dependent types. Inductive types are freely generated by their constructors, which describe how we can construct their terms. \n\nHowever, many familiar constructions in algebra involve the construction of algebras by generators and relations. \nFor example, the free abelian group with two generators is described as the group with generators $x$ and $y$, and the relation $xy=yx$. \n\nIn this chapter we introduce higher inductive types\\index{higher inductive type!circle}, where we follow a similar idea: to allow in the specification of inductive types not only \\emph{point constructors}, but also \\emph{path constructors} that give us relations between the point constructors. \nThe ideas behind the definition of higher inductive types are introduced by studying the simplest non-trivial example: the \\emph{circle}.\n\n\\subsection{The induction principle of the circle}\nThe \\emph{circle} is defined as a higher inductive type $\\sphere{1}$\\index{S 1@{$\\sphere{1}$}|see {circle}} that comes equipped with\\index{base@{$\\base$}}\\index{loop@{$\\lloop$}}\\index{circle!base@{$\\base$}}\\index{circle!loop@{$\\lloop$}}\n\\begin{align*}\n\\base & : \\sphere{1} \\\\\n\\lloop & : \\id{\\base}{\\base}.\n\\end{align*}\nJust like for ordinary inductive types, the induction principle for higher inductive types provides us with a way of constructing sections of dependent types. However, we need to take the \\emph{path constructor}\\index{path constructor} $\\lloop$ into account in the induction principle. \n\nBy applying a section $f:\\prd{x:\\sphere{1}}P(x)$ to the base point of the circle, we obtain a term $f(\\base):P(\\base)$. Moreover, using the dependent action on paths\\index{dependent action on paths} of $f$ of \\cref{defn:apd} we also obtain for any dependent function $f:\\prd{x:\\sphere{1}}P(x)$ a path\n\\begin{align*}\n\\apd{f}{\\lloop} & : \\id{\\tr_P(\\lloop,f(\\base))}{f(\\base)}\n\\end{align*}\nin the fiber $P(\\base)$.\n\n\\begin{defn}\nLet $P$ be a type family over the circle. The \\define{dependent action on generators}\\index{dependent action on generators!for the circle} is the map\\index{dgen_S1@{$\\dgen_{\\sphere{1}}$}}\n\\begin{equation}\\label{eq:dgen_circle}\n\\dgen_{\\sphere{1}}:\\Big(\\prd{x:\\sphere{1}}P(x)\\Big)\\to\\Big(\\sm{y:P(\\base)}\\id{\\tr_P(\\lloop,y)}{y}\\Big)\n\\end{equation}\ngiven by $\\dgen_{\\sphere{1}}(f)\\defeq\\pairr{f(\\base),\\apd{f}{\\lloop}}$.\n\\end{defn}\n\nWe now give the full specification of the circle.\n\n\\begin{defn}\nThe \\define{circle}\\index{circle} is a type $\\sphere{1}$\\index{S 1@{$\\sphere{1}$}} that comes equipped with\\index{base@{$\\base$}}\\index{loop@{$\\lloop$}}\n\\begin{align*}\n\\base & : \\sphere{1} \\\\\n\\lloop & : \\id{\\base}{\\base},\n\\end{align*}\nand satisfies the \\define{induction principle of the circle}\\index{induction principle!of the circle}, which provides for each type family $P$ over $\\sphere{1}$ a map\n\\begin{equation*}\n\\ind{\\sphere{1}}:\\Big(\\sm{y:P(\\base)}\\id{\\tr_P(\\lloop,y)}{y}\\Big)\\to \\Big(\\prd{x:\\sphere{1}}P(x)\\Big),\n\\end{equation*}\nand a homotopy witnessing that $\\ind{\\sphere{1}}$ is a section of $\\dgen_{\\sphere{1}}$\n\\begin{equation*}\n\\comphtpy{\\sphere{1}}:\\dgen_{\\sphere{1}}\\circ \\ind{\\sphere{1}}\\htpy \\idfunc\n\\end{equation*}\nfor the computation rule\\index{computation rules!of the circle}.\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:circle-induction}\n  The type of identifications $(y,p)=(y',p')$ in the type\n  \\begin{equation*}\n    \\sm{y:P(\\base)}\\tr_P(\\lloop,y)=y\n  \\end{equation*}\n  is equivalent to the type of pairs $(\\alpha,\\beta)$ consisting of an identification $\\alpha:y=y'$, and an identification $\\beta$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\tr_P(\\lloop,y) \\arrow[d,equals,swap,\"p\"] \\arrow[r,equals,\"\\ap{\\tr_P(\\lloop)}{\\alpha}\"] & \\tr_P(\\lloop,y') \\arrow[d,equals,\"{p'}\"] \\\\\n      y \\arrow[r,equals,swap,\"\\alpha\"] & y'\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Therefore it follows from the induction principle of the circle that for any $(y,p):\\sm{y:P(\\base)}\\tr_P(\\lloop,y)=y$, there is a dependent function $f:\\prd{x:\\sphere{1}}P(x)$ equipped with an identification\n  \\begin{equation*}\n    \\alpha : f(\\base)=y,\n  \\end{equation*}\n  and an identification $\\beta$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\tr_P(\\lloop,f(\\base)) \\arrow[d,equals,swap,\"{\\apd{f}{\\lloop}}\"] \\arrow[r,equals,\"\\ap{\\tr_P(\\lloop)}{\\alpha}\"] & \\tr_P(\\lloop,y) \\arrow[d,equals,\"{p}\"] \\\\\n      f(\\base) \\arrow[r,equals,swap,\"\\alpha\"] & y\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes.  \n\\end{rmk}\n\n\\subsection{The (dependent) universal property of the circle}\n\\subsectionmark{The universal property of the circle}\n\nOur goal is now to use the induction principle of the circle to derive the \\define{universal property}\\index{universal property!of the circle} of the circle. This universal property states that, for any type $X$ the canonical map\n\\begin{equation*}\n  \\Big(\\sphere{1}\\to X\\Big)\\to\\Big(\\sm{x:X}x=x\\Big)\n\\end{equation*}\ngiven by $f\\mapsto(f(\\base),\\ap{f}{\\lloop})$ is an equivalence. It turns out that it is easier to prove the \\define{dependent universal property}\\index{dependent universal property!of the circle} first. The dependent universal property states that for any type family $P$ over the circle, the canonical map\n\\begin{equation*}\n  \\Big(\\prd{x:\\sphere{1}}P(x)\\Big)\\to\\Big(\\sm{y:P(\\base)}\\tr_P(\\lloop,y)=y\\Big)\n\\end{equation*}\ngiven by $f\\mapsto(f(\\base),\\apd{f}{\\lloop})$ is an equivalence.\n\n\\begin{thm}\\label{thm:circle-dependent-universal-property}\n  For any type family $P$ over the circle, the map\n  \\begin{equation*}\n    \\Big(\\prd{x:\\sphere{1}}P(x)\\Big)\n    \\to\n    \\Big(\\sm{y:P(\\base)}\\tr_P(\\lloop,y)=y\\Big)\n  \\end{equation*}\n  given by $f\\mapsto(f(\\base),\\apd{f}{\\lloop})$ is an equivalence.\n\\end{thm}\n\n\\begin{proof}\n  By the induction principle of the circle we know that the map has a section, i.e., we have\n  \\begin{align*}\n    \\ind{\\sphere{1}} & : \\Big(\\sm{y:P(\\base)}\\tr_P(\\lloop,y)=y\\Big) \\to \\Big(\\prd{x:\\sphere{1}}P(x)\\Big) \\\\\n    \\comphtpy{\\sphere{1}} & : \\dgen_{\\sphere{1}}\\circ\\ind{\\sphere{1}}\\htpy\\idfunc\n  \\end{align*}\n  Therefore it remains to construct a homotopy\n  \\begin{equation*}\n    \\ind{\\sphere{1}}\\circ\\dgen_{\\sphere{1}}\\htpy\\idfunc.\n  \\end{equation*}\n  Thus, for any $f:\\prd{x:\\sphere{1}}P(x)$ our task is to construct an identification\n  \\begin{equation*}\n    \\ind{\\sphere{1}}(\\dgen_{\\sphere{1}}(f))=f.\n  \\end{equation*}\n  By function extensionality it suffices to construct a homotopy\n  \\begin{equation*}\n    \\prd{x:\\sphere{1}} \\ind{\\sphere{1}}(\\dgen_{\\sphere{1}}(f))(x)= f(x).\n  \\end{equation*}\n  We proceed by the induction principle of the circle using the family of types $E_{g,f}(x)\\defeq g(x)=f(x)$ indexed by $x:\\sphere{1}$, where $g$ is the function\n  \\begin{equation*}\n    g\\defeq\\ind{\\sphere{1}}(\\dgen_{\\sphere{1}}(f)).\n  \\end{equation*}\n  Thus, it suffices to construct\n  \\begin{align*}\n    \\alpha & : g(\\base)=f(\\base)\\\\\n    \\beta  & : \\tr_{E_{g,f}}(\\lloop,\\alpha)=\\alpha. \n  \\end{align*}\n  An argument by path induction on $p$ yields that\n  \\begin{equation*}\n    \\Big(\\ct{\\apd{g}{p}}{r}=\\ct{\\ap{\\tr_P(p)}{q}}{\\apd{f}{p}}\\Big)\\to\\Big(\\tr_{E_{g,f}}(p,q)=r\\Big),\n  \\end{equation*}\n  for any $f,g:\\prd{x:X}P(x)$ and any $p:x=x'$, $q:g(x)=f(x)$ and $r:g(x')=f(x')$.\n  Therefore it suffices to construct an identification $\\alpha:g(\\base)=f(\\base)$ equipped with an identification $\\beta$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\tr_P(\\lloop,g(\\base)) \\arrow[d,equals,swap,\"\\apd{g}{\\lloop}\"] \\arrow[r,equals,\"\\ap{\\tr_P(\\lloop)}{\\alpha}\"] & \\tr_P(\\lloop,f(\\base)) \\arrow[d,equals,\"\\apd{f}{\\lloop}\"] \\\\\n      g(\\base) \\arrow[r,equals,swap,\"\\alpha\"] & f(\\base)\"\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Notice that we get exactly such a pair $(\\alpha,\\beta)$ from the computation rule of the circle, by \\cref{rmk:circle-induction}.\n\\end{proof}\n\nAs a corollary we obtain the following uniqueness principle for dependent functions defined by the induction principle of the circle.\n\n\\begin{cor}\n  Consider a type family $P$ over the circle, and let\n  \\begin{align*}\n    y & : P(\\base) \\\\\n    p & : \\tr_{P}(\\lloop,y)=y.\n  \\end{align*}\n  Then the type of functions $f:\\prd{x:\\sphere{1}}P(x)$ equipped with an identification\n  \\begin{equation*}\n    \\alpha: f(\\base)=y\n  \\end{equation*}\n  and an identification $\\beta$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\tr_P(\\lloop,f(\\base)) \\arrow[d,equals,swap,\"{\\apd{f}{\\lloop}}\"] \\arrow[r,equals,\"\\ap{\\tr_P(\\lloop)}{\\alpha}\"] & \\tr_P(\\lloop,y) \\arrow[d,equals,\"{p}\"] \\\\\n      f(\\base) \\arrow[r,equals,swap,\"\\alpha\"] & y\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, is contractible.\n\\end{cor}\n\nNow we use the dependent universal property to derive the ordinary universal property of the circle. It would be tempting to say that it is a direct corollary, but we need to address the transport that occurs in the dependent universal property.\n\n\\begin{thm}\\label{thm:circle_up} \nFor each type $X$, the \\define{action on generators}\\index{action on generators!for the circle}\\index{gen_S1@{$\\mathsf{gen}_{\\sphere{1}}$}}\n\\begin{equation*}\n\\mathsf{gen}_{\\sphere{1}}:(\\sphere{1}\\to X)\\to \\sm{x:X}x=x\n\\end{equation*}\ngiven by $f\\mapsto (f(\\base),\\ap{f}{\\lloop})$ is an equivalence.\n\\end{thm}\n\n\\begin{proof}\n  We prove the claim by constructing a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-2em]\n      \\phantom{\\Big(\\sm{x:X}\\tr_{\\const_X}(\\lloop,x)=x\\Big)} & (\\sphere{1}\\to X) \\arrow[dl,swap,\"\\gen_{\\sphere{1}}\"] \\arrow[dr,\"\\dgen_{\\sphere{1}}\"] \\\\\n      \\Big(\\sm{x:X}x=x\\Big) \\arrow[rr,swap,\"\\simeq\"] & & \\Big(\\sm{x:X}\\tr_{\\const_X}(\\lloop,x)=x\\Big)\n    \\end{tikzcd}\n  \\end{equation*}\n  in which the bottom map is an equivalence. Indeed, once we have such a triangle, we use the fact from \\cref{thm:circle-dependent-universal-property} that $\\dgen_{\\sphere{1}}$ is an equivalence to conclude that $\\gen_{\\sphere{1}}$ is an equivalence.\n\n  To construct the bottom map, we first observe that for any constant type family $\\const_B$ over a type $A$, any $p:a=a'$ in $A$, and any $b:B$, there is an identification\n  \\begin{equation*}\n    \\mathsf{tr\\usc{}const}_B(p,b)=b.\n  \\end{equation*}\n  This identification is easily constructed by path induction on $p$. Now we construct the bottom map as the induced map on total spaces of the family of maps\n  \\begin{equation*}\n    l\\mapsto \\ct{\\mathsf{tr\\usc{}const}_X(\\lloop,x)}{l},\n  \\end{equation*}\n  indexed by $x:X$. Since concatenating by a path is an equivalence, it follows by \\cref{thm:fib_equiv} that the induced map on total spaces is indeed an equivalence.\n\n  To show that the triangle commutes, it suffices to construct for any $f:\\sphere{1}\\to X$ an identification witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=1em]\n      \\tr_{\\const_X}(\\lloop,f(\\base)) \\arrow[dr,equals,swap,\"\\apd{f}{\\lloop}\"] \\arrow[rr,equals,\"{\\mathsf{tr\\usc{}const}_X(\\lloop,f(\\base))}\"] & & f(\\base) \\arrow[dl,equals,\"\\ap{f}{\\lloop}\"] \\\\\n      & f(\\base) & \\phantom{\\tr_{\\const_X}(\\lloop,f(\\base))}\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. This again follows from general considerations: for any $f:A\\to B$ and any $p:a=a'$ in $A$, the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=1em]\n      \\tr_{\\const_B}(p,f(a)) \\arrow[dr,equals,swap,\"\\apd{f}{p}\"] \\arrow[rr,equals,\"{\\mathsf{tr\\usc{}const}_B(p,f(a))}\"] & & f(a) \\arrow[dl,equals,\"\\ap{f}{p}\"] \\\\\n      & f(a') & \\phantom{\\tr_{\\const_B}(p,f(a))}\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes by path induction on $p$.\n\\end{proof}\n\n\\begin{cor}\n  For any loop $l:x=x$ in a type $X$, the type of maps $f:\\sphere{1}\\to X$ equipped with an identification\n  \\begin{equation*}\n    \\alpha : f(\\base)=x \n  \\end{equation*}\n  and an identification $\\beta$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      f(\\base) \\arrow[r,equals,\"\\alpha\"] \\arrow[d,equals,swap,\"\\ap{f}{\\lloop}\"] & x \\arrow[d,equals,\"l\"] \\\\\n      f(\\base) \\arrow[r,equals,swap,\"\\alpha\"] & x\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, is contractible.\n\\end{cor}\n\n\\subsection{Multiplication on the circle}\n\\label{sec:mulcircle}\n\nOne way the circle arises classically, is as the set of complex numbers at distance $1$ from the origin. It is an elementary fact that $|xy|=|x||y|$ for any two complex numbers $x,y\\in\\mathbb{C}$, so it follows that when we multiply two complex numbers that both lie on the unit circle, then the result lies again on the unit circle. Thus, using complex multiplication we see that there is a multiplication operation on the circle. And there is a shadow of this operation in type theory, even though our circle arises in a very different way!\n\n\\begin{defn}\\label{defn:mul-circle}\n  We define a binary operation\n\\begin{equation*}\n  \\mulcircle : \\sphere{1}\\to(\\sphere{1}\\to\\sphere{1}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{proof}[Construction]\n  Using the universal property of the circle, we define $\\mulcircle$ as the unique map $\\sphere{1}\\to(\\sphere{1}\\to\\sphere{1})$ equipped with an identification\n  \\begin{equation*}\n    \\basemulcircle :\\mulcircle(\\base)=\\idfunc\n  \\end{equation*}\n  and an identification $\\loopmulcircle$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      \\mulcircle(\\base) \\arrow[r,equals,\"\\basemulcircle\"] \\arrow[d,equals,swap,\"\\ap{\\mulcircle}{\\lloop}\"] & \\idfunc \\arrow[d,equals,\"\\eqhtpy(\\htpyidcircle)\"] \\\\\n      \\mulcircle(\\base) \\arrow[r,equals,swap,\"\\basemulcircle\"] & \\idfunc\n  \\end{tikzcd}\n  \\end{equation*}\n  commutes. Note that in this square we have a homotopy $\\htpyidcircle:\\idfunc\\htpy\\idfunc$, which is not yet defined. We  use the dependent universal property of the circle with respect to the family $E_{\\idfunc,\\idfunc}$ given by\n  \\begin{equation*}\n    E_{\\idfunc,\\idfunc}(x) \\defeq (x=x),\n  \\end{equation*}\n  to define $\\htpyidcircle$ as the unique homotopy equipped with an identification\n  \\begin{equation*}\n    \\basehtpyidcircle : \\htpyidcircle(\\base)=\\lloop\n  \\end{equation*}\n  and an identification $\\loophtpyidcircle$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      \\tr_{E_{\\idfunc,\\idfunc}}(\\lloop,\\htpyidcircle(\\base)) \\arrow[r,equals,\"\\ap{\\tr_{E_{\\idfunc,\\idfunc}}(\\lloop)}{\\basehtpyidcircle}\"] \\arrow[d,equals,swap,\"\\apd{\\htpyidcircle}{\\lloop}\"] & \\tr_{E_{\\idfunc,\\idfunc}}(\\lloop,\\lloop) \\arrow[d,equals,\"\\gamma\"] \\\\\n      \\htpyidcircle(\\base) \\arrow[r,equals,swap,\"\\basehtpyidcircle\"] & \\lloop\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Now it remains to define the path $\\gamma:\\tr_{E_{\\idfunc,\\idfunc}}(\\lloop,\\lloop)=\\lloop$ in the above square. To proceed, we first observe that a simple path induction argument yields a function\n  \\begin{equation*}\n    \\Big(\\ct{p}{r}=\\ct{q}{p}\\Big)\\to\\Big(\\tr_{E_{\\idfunc,\\idfunc}}(p,q)=r\\Big),\n  \\end{equation*}\n  for any $p:\\base=x$, $q:\\base=\\base$ and $r:x=x$. In particular, we have a function\n  \\begin{equation*}\n    \\Big(\\ct{\\lloop}{\\lloop}=\\ct{\\lloop}{\\lloop}\\Big)\\to\\Big(\\tr_{E_{\\idfunc,\\idfunc}}(\\lloop,\\lloop)=\\lloop\\Big).\n  \\end{equation*}\n  Now we apply this function to $\\refl{\\ct{\\lloop}{\\lloop}}$ to obtain the desired identification\n  \\begin{equation*}\n    \\gamma:\\tr_{E_{\\idfunc,\\idfunc}}(\\lloop,\\lloop)=\\lloop.\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{rmk}\n  In the definition of $H:\\idfunc\\htpy\\idfunc$ above, it is important that we didn't choose $H$ to be $\\reflhtpy$. If we had done so, the resulting operation would be homotopic to $x,y\\mapsto y$, which is clearly not what we had in mind with the multiplication operation on the circle. See also \\cref{ex:circle-constant}.\n\\end{rmk}\n\n\nThe left unit law $\\mulcircle(\\base,x)=x$ holds by the computation rule of the universal property. More precisely, we define\n\\begin{equation*}\n  \\leftunit_{\\sphere{1}}\\defeq \\htpyeq(\\basemulcircle).\n\\end{equation*}\nFor the right unit law, however, we need to give a separate argument that is surprisingly involved, because all the aspects of the definition of $\\mulcircle$ will come out and play their part.\n\n\\begin{thm}\n  The multiplication operation on the circle satisfies the right unit law, i.e., we have\n  \\begin{equation*}\n    \\mulcircle(x,\\base)=x\n  \\end{equation*}\n  for any $x:\\sphere{1}$.\n\\end{thm}\n\n\\begin{proof}\n  The proof is by induction on the circle. In the base case we use the left unit law\n  \\begin{equation*}\n    \\leftunit_{\\sphere{1}}(\\base):\\mulcircle(\\base,\\base)=\\base.\n  \\end{equation*}\n  Thus, it remains to show that\n  \\begin{equation*}\n    \\tr_P(\\lloop,\\leftunit_{\\sphere{1}}(\\base))=\\leftunit_{\\sphere{1}}(\\base),\n  \\end{equation*}\n  where $P$ is the family over the circle given by\n  \\begin{equation*}\n    P(x) \\defeq \\mulcircle(x,\\base)=x.\n  \\end{equation*}\n  Now we observe that there is a function\n  \\begin{equation*}\n    \\Big(\\ct{\\htpyeq(\\ap{\\mulcircle}{p})(\\base)}{r}=\\ct{q}{p}\\Big)\\to\\Big(\\tr_{P}(p,q)=r\\Big),\n  \\end{equation*}\n  for any\n  \\begin{align*}\n    p & : \\base=x \\\\\n    q & : \\mulcircle(\\base,\\base)=\\base \\\\\n    r & : \\mulcircle(x,\\base)=x.\n  \\end{align*}\n  Thus we see that, in order to construct an identification\n  \\begin{equation*}\n    \\tr_{P}(\\lloop,\\leftunit_{\\sphere{1}})=\\leftunit_{\\sphere{1}},\n  \\end{equation*}\n  it suffices to show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      \\mulcircle(\\base,\\base) \\arrow[d,equals,swap,\"\\htpyeq(\\ap{\\mulcircle}{\\lloop})(\\base)\"] \\arrow[r,equals,\"\\leftunit_{\\sphere{1}}(\\base)\"] & \\base \\arrow[d,equals,\"\\lloop\"] \\\\\n      \\mulcircle(\\base,\\base) \\arrow[r,equals,swap,\"\\leftunit_{\\sphere{1}}(\\base)\"] & \\base\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Now we note that we have an identification $H(\\base)=\\lloop$. It is indeed at this point, where it is important that $H$ is not the trivial homotopy, because now we can proceed by observing that the above square commutes if and only if the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=12em]\n      \\mulcircle(\\base,\\base) \\arrow[d,equals,swap,\"\\htpyeq(\\ap{\\mulcircle}{\\lloop})(\\base)\"] \\arrow[r,equals,\"\\htpyeq(\\basemulcircle)(\\base)\"] & \\base \\arrow[d,equals,\"H(\\base)\"] \\\\\n      \\mulcircle(\\base,\\base) \\arrow[r,equals,swap,\"\\htpyeq(\\basemulcircle)(\\base)\"] & \\base\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. The commutativity of this square easily follows from the identification $\\loopmulcircle$ constructed in \\cref{defn:mul-circle}.\n\\end{proof}\n\n\\begin{exercises}\n  \\exercise \\label{ex:circle-connected}\n  \\begin{subexenum}\n  \\item Let $P:\\sphere{1}\\to\\prop$ be a family of propositions over the circle. Show that\n    \\begin{equation*}\n      P(\\base)\\to\\prd{x:\\sphere{1}}P(x).\n    \\end{equation*}\n    In this sense the circle is \\emph{connected}.\n  \\item Show that any embedding $m:\\sphere{1}\\to\\sphere{1}$ is an equivalence.\n  \\item Show that for any embedding $m:X\\to\\sphere{1}$, there is a proposition $P$ and an equivalence $e:\\eqv{X}{\\sphere{1}\\times P}$ for which the triangle\n    \\begin{equation*}\n      \\begin{tikzcd}[column sep=0]\n        X \\arrow[dr,swap,\"m\"] \\arrow[rr,\"e\"] & & \\sphere{1}\\times P \\arrow[dl,\"\\proj 1\"] \\\\\n        \\phantom{\\sphere{1}\\times P} & \\sphere{1}\n      \\end{tikzcd}\n    \\end{equation*}\n    commutes. In other words, all the embeddings into the circle are of the form $\\sphere{1}\\times P\\to \\sphere{1}$.\n  \\end{subexenum}\n  \\exercise \\label{ex:circle-constant}\n  Show that for any type $X$ and any $x:X$, the map\n  \\begin{equation*}\n    \\ind{\\sphere{1}}(x,\\refl{x}):\\sphere{1}\\to X\n  \\end{equation*}\n  is homotopic to the constant map $\\mathsf{const}_x$.\n  \\exercise \\label{ex:mulcircle-is-equiv}\n  \\begin{subexenum}\n  \\item Show that for any $x:\\sphere{1}$, both functions\n    \\begin{equation*}\n      \\mulcircle(x,\\blank)\\qquad\\text{and}\\qquad\\mulcircle(\\blank,x)\n    \\end{equation*}\n    are equivalences.\n  \\item Show that the function\n    \\begin{equation*}\n      \\mulcircle : \\sphere{1}\\to(\\sphere{1}\\to\\sphere{1})\n    \\end{equation*}\n    is an embedding. Compare this fact with \\cref{ex:groupop-embedding}.\n  \\item Show that multiplication on the circle is associative and commutative.\n  \\end{subexenum}\n  \\exercise \\label{ex:circle_connected}\n  \\begin{subexenum}\n  \\item Show that a type $X$ is a set if and only if the map\n    \\begin{equation*}\n      \\lam{x}{t} x : X \\to (\\sphere{1}\\to X)\n    \\end{equation*}\nis an equivalence.\n\\item Show that a type $X$ is a set if and only if the map\n  \\begin{equation*}\n    \\lam{f}f(\\base) : (\\sphere{1}\\to X)\\to X\n  \\end{equation*}\n  is an equivalence.\n  \\end{subexenum}\n  \\exercise Show that the multiplicative operation on the circle is commutative, i.e.~construct an identification\n  \\begin{equation*}\n    \\mulcircle(x,y)=\\mulcircle(y,x).\n  \\end{equation*}\n  for every $x,y:\\sphere{1}$.\n  \\exercise Show that the circle, equipped with the multiplicative operation $\\mulcircle$ is an abelian group, i.e.~construct an inverse operation\n  \\begin{equation*}\n    \\invcircle : \\sphere{1}\\to\\sphere{1}\n  \\end{equation*}\n  and construct identifications\n  \\begin{align*}\n    \\leftinv_{\\sphere{1}} & : \\mulcircle(\\invcircle(x),x) = \\base \\\\\n    \\rightinv_{\\sphere{1}} & : \\mulcircle(x,\\invcircle(x)) = \\base.\n  \\end{align*}\n  Moreover, show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\invcircle(\\base) \\arrow[d,equals] \\arrow[r,equals] & \\mulcircle(\\base,\\invcircle(\\base)) \\arrow[d,equals] \\\\\n      \\mulcircle(\\invcircle(\\base),\\base) \\arrow[r,equals] & \\base\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes.\n  \\exercise Show that for any multiplicative operation\n  \\begin{equation*}\n    \\mu:\\sphere{1}\\to(\\sphere{1}\\to\\sphere{1})\n  \\end{equation*}\n  that satisfies the condition that $\\mu(x,\\blank)$ and $\\mu(\\blank,x)$ are equivalences for any $x:\\sphere{1}$, there is a term $e:\\sphere{1}$ such that\n  \\begin{equation*}\n    \\mu(x,y)=\\mulcircle(x,\\mulcircle(\\bar{e},y))\n  \\end{equation*}\n  for every $x,y:\\sphere{1}$, where $\\bar{e}\\defeq\\invcircle(e)$ is the complex conjucation of $e$ on $\\sphere{1}$.\n\\end{exercises}\n", "meta": {"hexsha": "db4743e66190a2c45c0bab5f554ea8fea1d219ea", "size": 22184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/circle.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/circle.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/circle.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.5906976744, "max_line_length": 542, "alphanum_fraction": 0.6812116841, "num_tokens": 7411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6835139794483023}}
{"text": "\\documentclass{standalone}\n\\begin{document}\n\t\\chapter{Inequalities}\n\t\\section{Quadratic Inequalities}\n\t\\begin{example}\n\t\tSolve the inequality $x^2-2x>3$\n\t\\end{example}\n\t\n\t\\begin{center}\n\t\t$$x^2-2x>3$$\n\t\t$$\\implies x^2-2x-3>0$$\n\t\t$$\\text{Let }x^2-2x-3=0$$\n\t\t$$\\implies(x-3)(x+1)=0$$\n\t\\end{center}\t\n\t\\begin{center}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\twidth=8cm,\n\t\t\t\theight=6cm,\n\t\t\t\taxis line style={-},\n\t\t\t\txmin=-4,\n\t\t\t\txmax=4,\n\t\t\t\tymin=-4,\n\t\t\t\tymax=5,\n\t\t\t\txtick={-1,3}, % remove all ticks from x-axis\n\t\t\t\tytick={-3}, % ditto for y-axis\n\t\t\t\txlabel=$x$, \n\t\t\t\tylabel=$y$,\n\t\t\t\taxis lines=center, % default is to make a box around the axis\n\t\t\t\tsamples=100]\n\t\t\t\t\\addplot [black] {x^2 - 2*x - 3}\n\t\t\t\t;\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{center}\n\t\\hrulefill\n\t\\begin{example}\n\t\tSolve the inequality $\\quad \\dfrac{2x^2}{5} \\leq \\dfrac{7x+10}{2}$\n\t\\end{example}\n\t\\begin{center}\n\t\t$$4x^2 \\leq 35x + 50$$\n\t\t$$\\implies 4x^2-35x-50\\leq 0$$\n\t\t$$\\text{Let }\\quad 4x^2-35x-50=0$$\n\t\t$$(4x+5)(x-10)=0$$\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\twidth=8cm,\n\t\t\t\theight=6cm,\n\t\t\t\taxis line style={-},\n\t\t\t\txmin=-2,\n\t\t\t\txmax=11,\n\t\t\t\tymin=-127,\n\t\t\t\tymax=50,\n\t\t\t\txtick={-5/4,10}, \n\t\t\t\tytick={-50}, \n\t\t\t\txlabel=$x$, \n\t\t\t\tylabel=$y$,\n\t\t\t\taxis lines=center, \n\t\t\t\tsamples=100]\n\t\t\t\t\\addplot [black] coordinates{\n\t\t\t\t\t(-1,-17)(0,-48)(1,-79)(2,-110)(3,-141)(4,-172)(5,-203)(6,-234)(7,-265)(8,-296)(9,-327)(10,-358)(11,-389)\t\n\t\t\t\t};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\t\\hrulefill\n\t\\end{document}", "meta": {"hexsha": "3a8f179c9cec19667c0fa941d6ef8786531abf4a", "size": 1486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/Inequalities.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/Inequalities.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/Inequalities.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": 21.8529411765, "max_line_length": 110, "alphanum_fraction": 0.568640646, "num_tokens": 674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6835139770533224}}
{"text": "\\lab{NumPy Visual Guide}{NumPy Visual Guide}\n\\label{appendix:numpy-visual-guide}\n\\objective{NumPy operations can be difficult to visualize, but the concepts are straightforward.\nThis appendix provides visual demonstrations of how NumPy arrays are used with slicing syntax, stacking, broadcasting, and axis-specific operations.\nThough these visualizations are for 1- or 2-dimensional arrays, the concepts can be extended to $n$-dimensional arrays.\n% See Lab \\ref{lab:NumPy} for an introduction to NumPy operations and synatx.\n}\n\n\\section*{Data Access} % ======================================================\n\nThe entries of a 2-D array are the rows of the matrix (as 1-D arrays).\nTo access a single entry, enter the row index, a comma, and the column index.\nRemember that indexing begins with $0$.\n\n\\begin{align*}\nA[0] = \\left[\\begin{array}{rrrrr}\n\\tikzmarkin{row1}\\times & \\times & \\times & \\times & \\times\\tikzmarkend{row1}\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\end{array}\\right]\n&&\nA[2,1] = \\left[\\begin{array}{rrrrr}\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\tikzmarkin{entry} \\times \\tikzmarkend{entry} & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\n\\end{array}\\right]\n\\end{align*}\n\n\\section*{Slicing} % ==========================================================\n\nA lone colon extracts an entire row or column from a 2-D array.\nThe syntax \\li{[a:b]} can be read as ``the $a^{th}$ entry up to (but not including) the $b^{th}$ entry.''\nSimilarly, \\li{[a:]} means ``the $a^{th}$ entry to the end'' and \\li{[:b]} means ``everything up to (but not including) the $b^{th}$ entry.''\n\n\\begin{align*}\n\\text{\\li{A[1]}} = \\text{\\li{A[1,:]}} = \\left[\\begin{array}{rrrrr}\n\\times & \\times & \\times & \\times & \\times\\\\\n\\tikzmarkin{row2}\\times & \\times & \\times & \\times & \\times\\tikzmarkend{row2}\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\end{array}\\right]\n&&\n\\text{\\li{A[:,2]}} = \\left[\\begin{array}{rrrrr}\n\\times & \\times & \\tikzmarkin{col}\\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times\\tikzmarkend{col} & \\times & \\times\n\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{A[1:,:2]}} = \\left[\\begin{array}{rrrrr}\n\\times & \\times & \\times & \\times & \\times\\\\\n\\tikzmarkin{block}\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\times\\tikzmarkend{block} & \\times & \\times & \\times\n\\end{array}\\right]\n&&\n\\text{\\li{A[1:-1,1:-1]}} = \\left[\\begin{array}{rrrrr}\n\\times & \\times & \\times & \\times & \\times\\\\\n\\times & \\tikzmarkin{interior} \\times & \\times & \\times & \\times\\\\\n\\times & \\times & \\times & \\times \\tikzmarkend{interior} & \\times\\\\\n\\times & \\times & \\times & \\times & \\times\\end{array}\\right]\n\\end{align*}\n\n\\section*{Stacking} % =========================================================\n\n\\li{np.hstack()} stacks sequence of arrays horizontally and \\li{np.vstack()} stacks a sequence of arrays vertically.\n\n\\begin{align*}\nA = \\left[\\begin{array}{ccc}\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n&&\nB = \\left[\\begin{array}{ccc}\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*} \\\\\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*} \\\\\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*}\n\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{np.hstack((A,B,A))}} =\n\\left[\\begin{array}{ccccccccc}\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*}&\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*}&\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*}&\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{np.vstack((A,B,A))}} =\n\\left[\\begin{array}{ccc}\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*} \\\\\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*} \\\\\n\\textcolor{red}{*} & \\textcolor{red}{*} & \\textcolor{red}{*} \\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n\\end{align*}\nBecause 1-D arrays are flat, \\li{np.hstack()} concatenates 1-D arrays and \\li{np.vstack()} stacks them vertically.\nTo make several 1-D arrays into the columns of a 2-D array, use \\li{np.column_stack()}.\n\n\\begin{align*}\nx = \\left[\\begin{array}{cccc}\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n&&\ny = \\left[\\begin{array}{cccc}\n\\textcolor{red}{*}&\\textcolor{red}{*}&\\textcolor{red}{*}&\\textcolor{red}{*}\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{np.hstack((x,y,x))}} =\n\\left[\\begin{array}{cccccccccccc}\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\n\\textcolor{red}{*}&\\textcolor{red}{*}&\\textcolor{red}{*}&\\textcolor{red}{*}&\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{np.vstack((x,y,x))}} =\n\\left[\\begin{array}{cccc}\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{red}{*}&\\textcolor{red}{*}&\\textcolor{red}{*}&\\textcolor{red}{*}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n&&\n\\text{\\li{np.column_stack((x,y,x))}} =\n\\left[\\begin{array}{ccc}\n\\textcolor{blue}{\\times}&\\textcolor{red}{*}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{red}{*}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{red}{*}&\\textcolor{blue}{\\times}\\\\\n\\textcolor{blue}{\\times}&\\textcolor{red}{*}&\\textcolor{blue}{\\times}\n\\end{array}\\right]\n\\end{align*}\n\n\\section*{Broadcasting} % =====================================================\n\nNumPy automatically aligns arrays for component-wise operations whenever possible.\n% The default behavior adds the first element to the first element of each row, the second element to the second element of each row, and so on.\nSee \\url{http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html} for more in-depth examples and broadcasting rules.\n\n\\begin{align*}\nA = \\left[\\begin{array}{ccc}\n1 & 2 & 3\\\\\n1 & 2 & 3\\\\\n1 & 2 & 3\\\\\n\\end{array}\\right]\n&&\nx = \\left[\\begin{array}{ccc}\n10 & 20 & 30\n\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{A + x}}\n&= \\begin{blockarray}{ccc}\n\\begin{block}{[ccc]}\n1 & 2 & 3\\\\\n1 & 2 & 3\\\\\n1 & 2 & 3\\\\\n\\end{block}\n  & + &  \\\\\n\\begin{block}{[ccc]}\n10 & 20 & 30\\\\\n\\end{block}\n\\end{blockarray}\n&= \\left[\\begin{array}{ccc}\n11 & 22 & 33\\\\\n11 & 22 & 33\\\\\n11 & 22 & 33\n\\end{array}\\right]\n\\\\ \\\\\n\\text{\\li{A + np.vstack(x)}}\n&= \\left[\\begin{array}{ccc}\n1 & 2 & 3 \\\\\n1 & 2 & 3 \\\\\n1 & 2 & 3 \\\\\n\\end{array}\\right]\n+ \\left[\\begin{array}{c}\n10 \\\\ 20 \\\\ 30\\\\\n\\end{array}\\right]\n&= \\left[\\begin{array}{ccc}\n11 & 12 & 13\\\\\n21 & 22 & 23\\\\\n31 & 32 & 33\\\\\n\\end{array}\\right]\n\\end{align*}\n\n\\section*{Operations along an Axis} % =========================================\n\nMost array methods have an \\li{axis} argument that allows an operation to be done along a given axis.\nTo compute the sum of each column, use \\li{axis=0}; to compute the sum of each row, use \\li{axis=1}.\n\n\\begin{align*}\nA = \\left[\\begin{array}{cccc}\n1 & 2 & 3 & 4\\\\\n1 & 2 & 3 & 4\\\\\n1 & 2 & 3 & 4\\\\\n1 & 2 & 3 & 4\n\\end{array}\\right]\n\\end{align*}\n\n\\begin{align*}\n\\text{\\li{A.<<sum>>(axis=0)}} &= %np.array([sum(A[:,i] for i in xrange(A.shape[1]))])}} =\n\\left[\\begin{array}{cccc}\n\\tikzmarkin{col1}1 & \\tikzmarkin{col2}2 & \\tikzmarkin{col3}3 & \\tikzmarkin{col4}4\\\\\n1 & 2 & 3 & 4\\\\\n1 & 2 & 3 & 4\\\\\n1\\tikzmarkend{col1} & 2\\tikzmarkend{col2} & 3\\tikzmarkend{col3} & 4\\tikzmarkend{col4}\n\\end{array}\\right]\n= \\left[\\begin{array}{cccc} 4 & 8 & 12 & 16 \\end{array}\\right]\n\\\\ \\\\\n\\text{\\li{A.<<sum>>(axis=1)}} &= %np.array([sum(A[i,:] for i in xrange(A.shape[0]))])}} =\n\\left[\\begin{array}{cccc}\n\\tikzmarkin{rowA}1 & 2 & 3 & 4\\tikzmarkend{rowA}\\\\\n\\tikzmarkin{rowB}1 & 2 & 3 & 4\\tikzmarkend{rowB}\\\\\n\\tikzmarkin{rowC}1 & 2 & 3 & 4\\tikzmarkend{rowC}\\\\\n\\tikzmarkin{rowD}1 & 2 & 3 & 4\\tikzmarkend{rowD}\\\\\n\\end{array}\\right]\n= \\left[\\begin{array}{cccc} 10 & 10 & 10 & 10 \\end{array}\\right]\n\\end{align*}\n\n", "meta": {"hexsha": "52774cdea4ccadcc3916ff404cd2417b9f62a469", "size": 9359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Introduction/NumpyIntro/VisualGuide.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": "Introduction/NumpyIntro/VisualGuide.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": "Introduction/NumpyIntro/VisualGuide.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": 38.9958333333, "max_line_length": 148, "alphanum_fraction": 0.6310503259, "num_tokens": 3438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8824278540866547, "lm_q1q2_score": 0.6835139534998321}}
{"text": "\\subsection{Mathematical Background and Cryptographic Definitions}\n\\label{ssec:math_def}\n\nWe let $\\G_{1}$, $\\G_{2}$, and $\\G_{T}$ be cyclic groups of order $q$.\nLet $g_{1}, h_{1}\\in\\G_{1}$ and $h_{2}\\in\\G_{2}$ be generators and\nrequire that the discrete logarithm $\\dlog_{g_{1}}h_{1}$ is unknown.\nThe groups we use were described in Sec.~\\ref{ssec:pk_curve_specifics}.\nWe let $e:\\G_{1}\\times\\G_{2}\\to\\G_{T}$ be an efficiently computable\nnondegenerate bilinear pairing.\nIn our case, signatures will be elements of $\\G_{1}$ while\npublic keys will be elements of $\\G_{2}$.\nSee Table~\\ref{tab:helper_funcs} for additional functions\nthat will be used in our algorithms.\n\n\\input{tables/helper_funcs.tex}\n\nWe are building a sidechain on top of Ethereum.\nAll of the validators will be required to have an Ethereum\npublic key.\nThe DKG algorithm requires us to index the participants\nfrom $1$ to $n$.\nTo do so, we order the participants with respect to their sorted\nEthereum public keys.\nOur algorithm will need an open broadcast channel;\nthis will take place via smart contracts on the Ethereum\nnetwork.\n\nAt times we will want to ensure\n\n\\begin{equation}\n    e\\parens{h_{1}^{\\alpha},h_{2}} \\overset{?}{=}\n    e\\parens{h_{1},h_{2}^{\\beta}}.\n\\end{equation}\n\n\\noindent\nDue to how \\textsc{PairingCheck} is defined, we\nwill need to check the equivalent\n\n\\begin{equation}\n    e\\parens{h_{1}^{\\alpha},h_{2}^{-1}}\\cdot\n        e\\parens{h_{1},h_{2}^{\\beta}}\n        \\overset{?}{=} 1.\n\\end{equation}\n\n\\noindent\nIf $h^{\\alpha} = \\parens{x,y}$, then\n$\\parens{h^{\\alpha}}^{-1} = \\parens{x,-y}$; this holds for all\nelliptic curves.\nFor ease of notation, we set $\\bar{h} = h^{-1}$.\nIt may be convenient to store both $h_{2}$ and $\\bar{h}_{2}$.\n\n", "meta": {"hexsha": "ce3a26022ac439c84ae8b8f69fa7e3e2e471d1ea", "size": 1721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/tcrypt_math_def.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_math_def.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_math_def.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": 33.0961538462, "max_line_length": 71, "alphanum_fraction": 0.7036606624, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6834704120103012}}
{"text": "\\clearemptydoublepage\n\\chapter{Theory}\n\\label{cha:theory}\n\n\\section{Basis Functions and Interpolation}\n\\label{sec:basisfunctions}\n\nBoth the finite element method (FEM) and the boundary element method (BEM) use\ninterpolation in finding a field solution \\ie the methods find the solution at\na number of points in the domain of interest and then approximate the solution\nbetween these points using interpolation. The points at which the solution is\nfound are known as \\emph{nodes}. \\emph{Basis functions} are used to\ninterpolate the field between nodes within a subregion of the domain known as\nan \\emph{element}. Interpolation is achieved by mapping the field coordinate\nonto a \\emph{local parametric}, or $\\xi$, coordinate (which varies from $0$ to\n$1$) within each element. The global nodes which make up each element are also\nmapped onto local element nodes and the basis functions are chosen (in terms\nof polynomials of the local parametric coordinate) such that the interpolated\nfield is equal to the known nodal values at each node and is thus continuous\nbetween elements. A schematic of this\nscheme is shown in \\figref{fig:nodesandelements}.\n\n\\epstexfigure{svgs/Theory/nodesandelements.eps_tex}{A schematic of the\n  relationship between local and global nodes, elements and the parametric\n  elemental $\\xi$ coordinate.} {A schematic of the relationship between local\n  and global nodes, elements and the parametric elemental $\\xi$\n  coordinate.}{fig:nodesandelements}{0.3}\n\n\\subsection{Summation Notation}\n\\label{subsec:summation notation}\n\nThe following (Einstein) summation notation will be used throughout these notes. In order to\neliminate summation symbols repeated ``dummy'' indices will be used \\ie\n\\begin{equation}\n  \\gsum{i=1}{n}{a^{i}b_{i}}=a^{i}b_{i}\n\\end{equation}\n\nTo indicate an index that is not summed, parentheses will be used\n\\ie $a^{(i)}b_{(i)}$ is talking about the singular expression for $i$ \\eg\n$a^{1}b_{1}$, $a^{2}b_{2}$ \\etc\n\nIn order to indicate a summation the sum must occur over indices that are\ndifferent sub/super-script \\ie the sum must be over an ``upper'' and a\n``lower'' index or a ``lower'' and an ``upper'' index. Note that it may be\nuseful to remember that if an index appears in the denominator of a fractional\nexpression then the index upper- or lower- ness is ``reversed''. \n\nFor some quantities with both upper and lower indices a dot will be used to\nindicate the ``second'' index \\eg in the expression $A^{i}_{.j}$ then $i$ can\nbe considered the first index and $j$ the second index.\n\n\\subsection{Lagrangian Basis Functions}\n\\label{sec:lagrangebasisfunctions}\n\nOne important family of basis functions are the Lagrange basis functions. This\nfamily has one basis function for each of the local element nodes and are\ndefined such that, at a particular node, only one basis function is non-zero\nand has the value of one. In this sense a basis function can be thought of as\nbeing associated with a local node and serves to weight the interpolated\nsolution in terms of the field value at that node. Lagrange basis functions\nhence provide only $C^{0}$ continuity of the field variable across element\nboundaries.\n\n\\subsubsection{Linear Lagrange basis functions}\n\nThe simplest basis functions of the Lagrange family are the \\onedal linear\nLagrange basis functions. These basis functions involve two local nodes and\nare defined as\n\\begin{equation}\n  \\begin{split}\n    \\lbfn{1}{\\xi}&=1-\\xi \\\\\n    \\lbfn{2}{\\xi}&=\\xi\n  \\end{split}\n  \\label{eqn:linearlbfuns}\n\\end{equation}\n\nThe two \\onedal linear Lagrange basis functions are gshown in \\figref{fig:linlagrangebfuns}.\n\n\\pstexfigure{plots/Theory/linlagrangebfuns.pstex}{Linear Lagrange basis functions.}\n{Linear Lagrange basis functions.}{fig:linlagrangebfuns}\n\nThe interpolation of a field variable, $u$, using these basis functions is\ngiven by\n\\begin{equation}\n  \\begin{split}\n    \\fnof{u}{\\xi}&=\\lbfn{1}{\\xi}\\nodept{u}{1}+\\lbfn{2}{\\xi}\\nodept{u}{2} \\\\\n    &=\\pbrac{1-\\xi}\\nodept{u}{1}+\\xi\\nodept{u}{2}\n  \\end{split}\n\\end{equation}\nwhere $\\nodept{u}{1}$ and $\\nodept{u}{2}$ are the values of the field variable at\nthe first and second local nodes respectively. These basis functions hence\nprovide a linear variation between the local nodal values with the local\nelement coordinate, $\\xi$.\n\n\\subsubsection{Quadratic Lagrange basis functions}\n\nLagrange basis functions can also be used to provide higher order variations,\nfor example the one-dimensional quadratic Lagrange basis functions involve\nthree local nodes and can provide a quadratic variation of field parameter\nwith $\\xi$. They are defined as\n\\begin{equation}\n  \\begin{split}\n    \\lbfn{1}{\\xi}&=2\\pbrac{\\xi-\\frac12}\\pbrac{\\xi-1} \\\\\n    \\lbfn{2}{\\xi}&=4\\xi\\pbrac{1-\\xi} \\\\\n    \\lbfn{3}{\\xi}&=2\\xi\\pbrac{\\xi-\\frac12}\n  \\end{split}\n  \\label{eqn:quadraticlbfuns}\n\\end{equation}\n\nThe three \\onedal quadratic Lagrange basis functions are shown in \\figref{fig:quadlagrangebfuns}.\n\n\\pstexfigure{plots/Theory/quadlagrangebfuns.pstex}{Quadratic Lagrange basis functions.}\n{Quadratic Lagrange basis functions.}{fig:quadlagrangebfuns}\n\nThe interpolation formula is\n\\begin{equation}\n  \\begin{split}\n    \\fnof{u}{\\xi}&=\\lbfn{1}{\\xi}\\nodept{u}{1}+\\lbfn{2}{\\xi}\\nodept{u}{2}+\n    \\lbfn{3}{\\xi}\\nodept{u}{3}\\\\\n    &=2\\pbrac{\\xi-\\frac12}\\pbrac{\\xi-1}\\nodept{u}{1}+\n    4\\xi\\pbrac{1-\\xi}\\nodept{u}{2}+2\\xi\\pbrac{\\xi-\\frac12}\\nodept{u}{3}\n  \\end{split}\n\\end{equation}\n\n\\subsubsection{Cubic Lagrange basis functions}\n\nOne-dimensional cubic Lagrange basis functions involve\nfour local nodes and can provide a cubic variation of field parameter\nwith $\\xi$. They are defined as\n\\begin{equation}\n  \\begin{split}\n    \\lbfn{1}{\\xi}&=\\frac12\\pbrac{3\\xi-1}\\pbrac{3\\xi-2}\\pbrac{1-\\xi} \\\\\n    \\lbfn{2}{\\xi}&=\\frac92\\xi\\pbrac{3\\xi-2}\\pbrac{\\xi-1} \\\\\n    \\lbfn{3}{\\xi}&=\\frac92\\xi\\pbrac{3\\xi-1}\\pbrac{1-\\xi} \\\\\n    \\lbfn{4}{\\xi}&=\\frac12\\xi\\pbrac{3\\xi-1}\\pbrac{3\\xi-2}\n  \\end{split}\n  \\label{eqn:cubiclbfuns}\n\\end{equation}\n\nThe four \\onedal cubic Lagrange basis functions are shown in \\figref{fig:cublagrangebfuns}.\n\n\\pstexfigure{plots/Theory/cublagrangebfuns.pstex}{Cubic Lagrange basis functions.}\n{Cubic Lagrange basis functions.}{fig:cublagrangebfuns}\n\nThe interpolation formula is\n\\begin{equation}\n  \\begin{split}\n    \\fnof{u}{\\xi}&=\\lbfn{1}{\\xi}\\nodept{u}{1}+\\lbfn{2}{\\xi}\\nodept{u}{2}+\n    \\lbfn{3}{\\xi}\\nodept{u}{3}+\\lbfn{4}{\\xi}\\nodept{u}{4}\\\\\n    &=\\frac12\\pbrac{3\\xi-1}\\pbrac{3\\xi-2}\\pbrac{1-\\xi}\\nodept{u}{1}+\n    \\frac92\\xi\\pbrac{3\\xi-2}\\pbrac{\\xi-1}\\nodept{u}{2} \\\\\n    &\\quad+\\frac92\\xi\\pbrac{3\\xi-1}\\pbrac{1-\\xi}\\nodept{u}{3}+\n    \\frac12\\xi\\pbrac{3\\xi-1}\\pbrac{3\\xi-2}\\nodept{u}{4}\n  \\end{split}\n\\end{equation}\n\n\\subsubsection{General Lagrange basis functions}\n\nIn general the interpolation formula for the Lagrange family of basis\nfunctions is, using \\index{Einstein summation notation}\\emph{Einstein\n  summation notation}, given by\n\\begin{equation}\n  \\fnof{u}{\\xi}=\\lbfn{\\alpha}{\\xi}\\nodept{u}{\\alpha}\\quad \\alpha=1,\\ldots,n_{e}\n  \\label{eqn:lagrangeinterpolation}\n\\end{equation}\nwhere $n_{e}$ is the number of local nodes in the element. Einstein summation\nnotation uses a repeated index in a product expression to imply summation. For\nexample \\eqnref{eqn:lagrangeinterpolation} is equivalent to\n\\begin{equation}\n  \\fnof{u}{\\xi}=\\gsum{\\alpha=1}{n_{e}}{\\lbfn{\\alpha}{\\xi}\\nodept{u}{\\alpha}}\n\\end{equation}\n\n\\subsubsection{Bilinear Lagrange basis functions}\n\nMulti-dimensional Lagrange basis functions can be constructed from the tensor,\nor outer, products of the one-dimensional Lagrange basis functions. For\nexample the two-dimensional bilinear Lagrange basis functions have four local\nnodes with the basis functions given by\n\\begin{equation}\n  \\begin{split}\n    \\lbfn{1}{\\xione,\\xitwo}&=\\lbfn{1}{\\xione}\\lbfn{1}{\\xitwo}=\n    \\pbrac{1-\\xione}\\pbrac{1-\\xitwo}\\\\\n    \\lbfn{2}{\\xione,\\xitwo}&=\\lbfn{2}{\\xione}\\lbfn{1}{\\xitwo}=\n    \\xione\\pbrac{1-\\xitwo}\\\\\n    \\lbfn{3}{\\xione,\\xitwo}&=\\lbfn{1}{\\xione}\\lbfn{2}{\\xitwo}=\n    \\pbrac{1-\\xione}\\xitwo \\\\\n    \\lbfn{4}{\\xione,\\xitwo}&=\\lbfn{2}{\\xione}\\lbfn{2}{\\xitwo}=\n    \\xione\\xitwo\n  \\end{split}\n\\end{equation}\n\nThe four \\twodal bilinear Lagrange basis functions are shown in \\figref{fig:bilinlagrangebfuns}.\n\n\\pstexfigure{plots/Theory/bilinlagrangebfuns.pstex}{Bilinear Lagrange basis functions.}\n            {Bilinear Lagrange basis functions.}{fig:bilinlagrangebfuns}\n            \nThe multi-dimensional interpolation formula is still a sum of the products of\nthe nodal basis function and the field value at the node. For example the\ninterpolated geometric position vector within an element is given by\n\\begin{equation}\n  \\begin{split}\n    \\fnof{\\vect{x}}{\\xione,\\xitwo}&=\\lbfn{\\alpha}{\\xione,\\xitwo}\n    \\nodept{\\vect{x}}{\\alpha}\\\\\n    &=\\lbfn{1}{\\xione,\\xitwo}\\nodept{\\vect{x}}{1}+\\lbfn{2}{\\xione,\\xitwo}\n    \\nodept{\\vect{x}}{2}+\\lbfn{3}{\\xione,\\xitwo}\\nodept{\\vect{x}}{3}+\n    \\lbfn{4}{\\xione,\\xitwo}\\nodept{\\vect{x}}{4}\n  \\end{split}\n\\end{equation}\nwhere, for the vector field, each component is interpolated separately using\nthe given basis functions.\n\n\\subsection{Hermitian Basis Functions}\n\\label{sec:Hermitianbasisfunctions}\n\nHermitian basis functions preserve continuity of the derivative of the\ninterpolating variable \\ie $C^{1}$ continuity, with respect to $\\xi$ across\nelement boundaries by defining additional nodal derivative parameters. Like\nLagrange bases, Hermitian basis functions are also chosen so that, at a\nparticular node, only one basis function is non-zero and equal to one. They\nalso are chosen so that, at a particular node, the \\emph{derivative} of only\none of four basis functions is non-zero and is equal to one. Hermitian basis\nfunctions hence serve to weight the interpolated solution in terms of the\nfield value and derivative of the field value at nodes.\n\n\\subsubsection{Cubic Hermite basis functions}\n\n\\Cubicherm basis functions are the simplest of the Hermitian family and\ninvolve two local nodes per element. The interpolation within each element is\nin terms of $\\nodept{\\vect{x}}{\\alpha}$ and \\evalat{\\dby{\\vect{x}}{\\xi}}{\\alpha}\nand is given by \\index{cubic Hermite basis!$\\xi$ interpolation formula}\n\\begin{equation}\n  \\fnof{\\vect{x}}{\\xi}=\\chbfn{1}{0}{\\xi}\\nodept{\\vect{x}}{1}+\\chbfn{1}{1}{\\xi}\n  \\evalat{\\dby{\\vect{x}}{\\xi}}{1}+\\chbfn{2}{0}{\\xi}\\nodept{\\vect{x}}{2}+\n  \\chbfn{2}{1}{\\xi}\\evalat{\\dby{\\vect{x}}{\\xi}}{2}\n  \\label{eqn:chxiinterpolation}\n\\end{equation}\nwhere the four \\onedal \\cubicherm basis functions are given in \n\\eqnref{eqn:chbfuns} and shown in \\figref{fig:chbfuns}.\n\\index{cubic Hermite basis!basis functions formulae}\n\\begin{equation}\n  \\begin{split}\n    \\chbfn{1}{0}{\\xi} &= 1-3\\xi^{2}+2\\xi^{3} \\\\\n    \\chbfn{1}{1}{\\xi} &= \\xi(\\xi-1)^{2} \\\\\n    \\chbfn{2}{0}{\\xi} &= \\xi^{2}(3-2\\xi) \\\\\n    \\chbfn{2}{1}{\\xi} &= \\xi^{2}(\\xi-1) \n  \\end{split}\n  \\label{eqn:chbfuns}\n\\end{equation}\n\\pstexfigure{plots/Theory/chbfuns.pstex}{Cubic Hermite basis functions.}\n{Cubic Hermite basis functions.}{fig:chbfuns}\n\n\\subsubsection{Scaling}\n\nOne further step is required to make \\cubicherm basis functions useful in\npractice.  Consider the two \\cubicherm elements shown in\n\\figref{fig:chelements}.\n\n\\epstexfigure{svgs/Theory/cubichermiteelem.eps_tex}{Two\n  cubic Hermite elements formed from three nodes.}{Two cubic Hermite elements\n  (denoted by $\\mathit{1}$ and $\\mathit{2}$) formed from three nodes (shown as\n  a $\\bullet$ and denoted by $\\mathbf{1}, \\mathbf{2}$ and $\\mathbf{3}$) and\n  having \\arclens $s_{1}$ and $s_{2}$ respectively.}{fig:chelements}{0.35}\n\nThe derivative $\\evalat{\\dby{\\vect{x}}{\\xi}}{\\alpha}$ defined at local node\n$\\alpha$ is dependent upon the local element \\xicoord and is therefore, in\ngeneral, different in the two adjacent elements. Interpretation of the\nderivative is hence difficult as two derivatives with the same magnitude in\ndifferent parts of the mesh might represent two completely different physical\nderivatives. This is problematic for modelling and computation if the interpretation of the\nmagnitude of the derivative (or \\emph{scaling}) is unknown \\eg we cannot\nassign physical units. If the scaling varies throughout the mesh then a\nderivative at a node that has a magnitude of, say, 5 will be different from\nanother derivative at another node that also has the magnitude of 5. Thus, a\nnumerical solver that is given a vector of derivative values would assume that\nthe scalings are the same and interpret the magnitudes identically. This would\nmean that algorithms may fail \\eg if, say, we needed to compute the\nnorm of a vector of derivatives then by assuming the same scaling the wrong\nresult would be computed.\n\nIn order to the have a consistent interpretation of the derivative\nthroughout the mesh it is better to base the interpolation on a physical\ncoordinate. Whilst we are free to choose the physical coordinate to be\nanything the optimum choice is arc length as this is what physical processes\nare based on. However, arc-length is extremely difficult to use as an\ninterpolation parameter as the inherent nonlinearity involved in its\ncalculation makes conversion to and from coordinates non trivial.\nThe solution is to find a parameter that scales\nin the same way as arc-length or as close to it as we can. \n\nConsider then basing the derivatives on an \\arclen coordinate at nodes,\n$\\dby{\\nodept{\\vect{x}}{\\alpha}}{s}$, with\n\\begin{equation}\n  \\begin{split}\n    \\evalat{\\dby{\\vect{x}}{\\xi}}{\\alpha}&=\\dby{\\nodept{\\vect{x}}{\n        \\fnof{\\Delta}{\\alpha,e}}}{s}\\pbrac{\\dby{s}{\\xi}}_{e} \\\\ &=\n    \\dby{\\nodept{\\vect{x}}{\\fnof{\\Delta}{\\alpha,e}}}{s}\\esfone{e}\n  \\end{split}\n  \\label{eqn:xitosch}\n\\end{equation}\nused to determine $\\evalat{\\dby{\\vect{x}}{\\xi}}{\\alpha}$. Here\n$\\dby{\\vect{x}}{s}$ is a physical \\arclen derivative,\n$\\fnof{\\Delta}{\\alpha,e}$ is the global node number of local node $\\alpha$ in\nelement $e$, $\\pbrac{\\dby{s}{\\xi}}_{e}$ is an \\index{element scale\n  factor}element \\emph{scale factor}, denoted by $\\esfone{e}$, which scales\nthe \\arclen derivative to the \\xicoord derivative.  Thus $\\dby{\\vect{x}}{s}$\nis constrained to be continuous across element boundaries rather than\n$\\dby{\\vect{x}}{\\xi}$. The \\cubicherm interpolation formula now becomes\n\\begin{equation}\n  \\fnof{\\vect{x}}{\\xi}=\\chbfn{1}{0}{\\xi}\\nodept{\\vect{x}}{1}+\\chbfn{1}{1}{\\xi}\n  \\dby{\\nodept{\\vect{x}}{1}}{s}\\esfone{e}+\\chbfn{2}{0}{\\xi}\\nodept{\\vect{x}}{2}+\n  \\chbfn{2}{1}{\\xi}\\dby{\\nodept{\\vect{x}}{2}}{s}\\esfone{e}\n  \\label{eqn:chseinterpolation}\n\\end{equation}\n\nBy interpolating with respect to $s$ rather than with respect to $\\xi$ there is some\nliberty as to the choice of the element scale factor, $\\esfone{e}$. The choice\nof the scale factor will, however, affect how $\\xi$ changes with $s$.  It is\ncomputationally desirable to have a relatively uniform change of $\\xi$ with\n$s$ (for example not biasing the Gaussian quadrature -- see later -- scheme to\none end of the element). For this reason the element scale factor is chosen as\nsome function of the \\arclen of the element, $s_{e}$. The simplest linear\nfunction that can be chosen is the \\arclen itself. This type of scaling is\ncalled \\index{arc-length scaling}\\emph{\\arclen scaling}.\n\nTo calculate the \\arclen for a particular element an iterative process is\nneeded. The \\arclen for a \\onedal element in \\twods is defined as\n\\index{arc-length definition}\n\\begin{equation}\n  \\text{\\arclen, }s_{e}=\\gint{0}{1}{\\norm{\\dby{\\fnof{\\vect{x}}{\\xi}}{\\xi}}}\n  {\\xi}=\\gint{0}{1}{\\sqrt{\\pbrac{\\dby{\\fnof{x}{\\xi}}{\\xi}}^{2}+\n      \\pbrac{\\dby{\\fnof{y}{\\xi}}{\\xi}}^{2}}}{\\xi}\n  \\label{eqn:arclendef}\n\\end{equation}\n\nHowever, since the interpolation of $\\fnof{\\vect{x}}{\\xi}$, as defined in\n\\eqnref{eqn:chseinterpolation}, uses the \\arclen in the calculation of the\nscaling factor, an iterative root finding technique is needed to obtain the\n\\arclen.\n\nThus, for an element $e$, the \\onedal \\cubicherm interpolation\nformula in \\eqnref{eqn:chseinterpolation} becomes\n\\begin{equation}\n  \\fnof{\\vect{x}}{\\xi}=\\chbfn{\\alpha}{u}{\\xi}\\nodept{\\vect{x}}{\\alpha}_{,u}\n  \\esftwo{e}{u}\n  \\label{eqn:chsfinterpolation}\n\\end{equation}\nwhere $\\alpha$ varies from $1$ to $2$, $u$ varies from $0$ to $1$,\n$\\nodept{\\vect{x}}{\\alpha}_{,0}=\\nodept{\\vect{x}}{\\alpha}$,\n$\\nodept{\\vect{x}}{\\alpha}_{,1}= \\dby{\\nodept{\\vect{x}}{\\alpha}}{s}$,\n$\\esftwo{e}{0}=1$ and $\\esftwo{e}{1}=\\esfone{e}=s_{e}$. \\Eqnref{eqn:chsfinterpolation} is equivalent to\n\\begin{equation}\n  \\fnof{\\vect{x}}{\\xi}=\\chbfn{1}{0}{\\xi}\\nodept{\\vect{x}}{1}_{,0}\\esftwo{e}{0}\n  +\\chbfn{1}{1}{\\xi}\\nodept{\\vect{x}}{1}_{,1}\\esftwo{e}{1}+\n  \\chbfn{2}{0}{\\xi}\\nodept{\\vect{x}}{2}_{,0}\\esftwo{e}{0}\n  +\\chbfn{2}{1}{\\xi}\\nodept{\\vect{x}}{2}_{,1}\\esftwo{e}{1}\n\\end{equation}\n\\ie there is an implied sum with $\\alpha$ and $u$ for $\\chbfn{\\alpha}{u}{\\xi}$\nand $\\nodept{\\vect{x}}{\\alpha}_{,u}$ but not for $\\esftwo{e}{u}$.\n\nThere is one final condition that must be placed on the $\\xi$ to \\arclen\ntransformation to ensure \\arclen derivatives. This condition is based on the\ngeometric defintion of \\arclen which is given by Pythagorus \\ie for \\twods in\nrectangular cartesian coordinate we have\n\\begin{equation}\n  ds^{2}=dx^{2}+dy^{2}\n  \\label{eqn:arclengthpythagorus}\n\\end{equation}\nor, in general coordinates,\n\\begin{equation}\n  ds^{2}=g_{ij}dx^{i}dx^{j}\n  \\label{eqn:genarclengthpythagorus}\n\\end{equation}\nwhere $g_{ij}$ are the components of the metric tensor.\n\nRearranging \\eqnref{eqn:arclengthpythagorus} we find that the \\arclen derivative vector at a\nnode for geometric like fields, for rectangular cartesian coordinates, must\nhave unit magnitude. Thus for global node $A$ we have\n\\begin{equation}\n  \\norm{\\dby{\\nodept{\\vect{x}}{A}}{s}}=1\n  \\label{eqn:chnormconstraint}\n\\end{equation}\n\nIn general coordinates this condition becomes\n\\begin{equation}\n  \\norm{\\delby{\\nodept{\\vect{x}}{A}}{s_{k}}}=\\sqrt{\\det{\\tensor{g}}}\n  \\label{eqn:genchnormconstraint}\n\\end{equation}\nwhere $s_{k}$ is the \\nth{k} global arc-length direction and $\\tensor{g}$ is the metric tensor.\n\nThe use of this constraint on \\arclen derivative magnitude ensures that there is continuity with respect to a physical parameter,\n$s$, rather than with respect to a mathematical parameter $\\xi$. The set of\nmesh parameters, $\\vect{u}$, for \\cubicherm interpolation hence contains the\nset of nodal values (or positions), the set of nodal \\arclen derivatives and\nthe set of scale factors.\n\n\\subsubsection{Extension to higher orders}\n\n\\Bicubicherm basis functions are the \\twodal extension of the \\onedal\n\\cubicherm basis functions. They are formed from the tensor (or outer) product\nof two of the \\onedal cubic Hermite basis functions defined in\n\\eqnref{eqn:chbfuns}.  The interpolation formula for the point\n$\\fnof{\\vect{x}}{\\xione,\\xitwo}$ within an element is obtained from the\n\\bicubicherm interpolation formula \\cite{nielsen:1991a}, \\index{bicubic\n  Hermite basis!$\\xi$ interpolation formula}\n\\begin{equation}\n  \\begin{split}\n    \\fnof{\\vect{x}}{\\xione,\\xitwo} &=\n    \\chbfn{1}{0}{\\xione}\\chbfn{1}{0}{\\xitwo}\\nodept{\\vect{x}}{1} +\n    \\chbfn{2}{0}{\\xione}\\chbfn{1}{0}{\\xitwo}\\nodept{\\vect{x}}{2} + \\\\\n    & \\chbfn{1}{0}{\\xione}\\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{3} +\n    \\chbfn{2}{0}{\\xione}\\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{4} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\chbfn{1}{0}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xione}}\n    {1}+\n    \\chbfn{2}{1}{\\xione}\\chbfn{1}{0}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xione}}\n    {2}+ \\\\ \n    & \\chbfn{1}{1}{\\xione}\\chbfn{2}{0}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xione}}\n    {3}+\n    \\chbfn{2}{1}{\\xione}\\chbfn{2}{0}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xione}}\n    {4} + \\\\ \n    & \\chbfn{1}{0}{\\xione}\\chbfn{1}{1}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xitwo}}\n    {1}+\n    \\chbfn{2}{0}{\\xione}\\chbfn{1}{1}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xitwo}}\n    {2} + \\\\ \n    & \\chbfn{1}{0}{\\xione}\\chbfn{2}{1}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xitwo}}\n    {3}+\n    \\chbfn{2}{0}{\\xione}\\chbfn{2}{1}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xitwo}}\n    {4} + \\\\ \n    & \\chbfn{1}{1}{\\xione}\\chbfn{1}{1}{\\xitwo}\\evalat{\\deltwoby{\\vect{x}}\n      {\\xione}{\\xitwo}}{1} +\n    \\chbfn{2}{1}{\\xione}\\chbfn{1}{1}{\\xitwo}\\evalat{\\deltwoby{\\vect{x}}\n      {\\xione}{\\xitwo}}{2} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\chbfn{2}{1}{\\xitwo}\\evalat{\\deltwoby{\\vect{x}}\n      {\\xione}{\\xitwo}}{3} + \n    \\chbfn{2}{1}{\\xione}\\chbfn{2}{1}{\\xitwo}\\evalat{ \\deltwoby{\\vect{x}}\n      {\\xione}{\\xitwo}}{4}    \n  \\end{split}\n  \\label{eqn:bichxiinterp}\n\\end{equation}\n\nAs with \\onedal \\cubicherm elements, the derivatives with respect to $\\xi$ in\nthe \\twodal interpolation formula above are expressed as the product of a\nnodal \\arclen derivative and a scale factor. This is, however, complicated by\nthe fact that there are now multiple $\\xi$ directions at each node. From the\nproduct rule the transformation from an $\\xi$ based derivative to an \\arclen\nbased derivative is given by,\n\\begin{equation}\n  \\delby{\\vect{x}}{\\xi_{l}}=\\delby{\\vect{x}}{s_{1}}\\delby{s_{1}}{\\xi_{l}}+\n  \\delby{\\vect{x}}{s_{2}}\\delby{s_{2}}{\\xi_{l}}\n  \\label{eqn:xitosproductrule}\n\\end{equation}\n\nNow, by definition, the $\\nth{l}$ \\arclen direction is only a function of the\n$\\nth{l}$ $\\xi$ direction, hence the derivative at local node $\\alpha$ is\n\\begin{equation}\n  \\evalat{\\delby{\\vect{x}}{\\xi_{l}}}{\\alpha}=\\delby{\\nodept{\\vect{x}}{\n      \\fnof{\\Delta}{\\alpha,e}}}{s_{l}}\\esftwo{e}{l}\n  \\label{eqn:xitosbich}\n\\end{equation}\nand the cross-derivative is\n\\begin{equation}\n  \\evalat{\\deltwoby{\\vect{x}}{\\xione}{\\xitwo}}{\\alpha}=\n  \\deltwoby{\\nodept{\\vect{x}}{\\fnof{\\Delta}{\\alpha,e}}}{s_{1}}{s_{2}}\\esftwo{e}{1}\n  \\esftwo{e}{2}\n  \\label{eqn:xitosbichcd}\n\\end{equation}\n\nUnlike the \\onedal \\cubicherm case a condition must be placed on\nthis transformation in order to maintain $C^{1}$ continuity across element\nboundaries. \n\nConsider the line between global nodes $\\mathbf{1}$ and $\\mathbf{2}$ in the\ntwo \\bicubicherm elements shown in \\figref{fig:bichelementcont}.\n\\epstexfigure{svgs/Theory/C1bicubicHermite.eps_tex}{Continuity of two bicubic\n  Hermite elements.}{Two bicubic Hermite elements (denoted by $\\mathit{1}$ and\n  $\\mathit{2}$). The global node numbers are given in boldface, the local node\n  numbers in normal text and the element scale factors used along each line\n  are denoted by $\\esfone{l}$.}{fig:bichelementcont}{0.35}\n\nFor $C^{1}$ continuity, as opposed to $G^{1}$ continuity, between these\nelements the derivative with respect to $\\xione$, that is\n\\delby{\\fnof{\\vect{x}}{\\xitwo}}{\\xione}, must be continuous\\footnote{For\n  $C^{1}$ continuity the normals either side of an element boundary must be in\n  the same direction \\emph{and} have the same magnitude. For $G^{1}$\n  continuity the normals must only have the same direction.}. The formula for\nthis derivative in element $\\mathit{1}$ along the boundary between elements\n$\\mathit{1}$ and $\\mathit{2}$ is\n\\begin{equation}\n  \\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione}=\\chbfn{0}{1}{\\xitwo}\\evalat{\n    \\delby{\\vect{x}}{\\xione}}{2}+\\chbfn{0}{2}{\\xitwo}\\evalat{\n    \\delby{\\vect{x}}{\\xione}}{4}+\\chbfn{1}{1}{\\xitwo}\\evalat{\n    \\deltwoby{\\vect{x}}{\\xione}{\\xitwo}}{2}+\\chbfn{1}{2}{\\xitwo}\\evalat{\n    \\deltwoby{\\vect{x}}{\\xione}{\\xitwo}}{4}\n  \\label{eqn:c1contelem1}\n\\end{equation}\nand for element $\\mathit{2}$ is\n\\begin{equation}\n  \\delby{\\fnof{\\vect{x}}{0,\\xitwo}}{\\xione}=\\chbfn{0}{1}{\\xitwo}\\evalat{\n    \\delby{\\vect{x}}{\\xione}}{1}+\\chbfn{0}{2}{\\xitwo}\\evalat{\n    \\delby{\\vect{x}}{\\xione}}{3}+\\chbfn{1}{1}{\\xitwo}\\evalat{\n    \\deltwoby{\\vect{x}}{\\xione}{\\xitwo}}{1}+\\chbfn{1}{2}{\\xitwo}\\evalat{\n    \\deltwoby{\\vect{x}}{\\xione}{\\xitwo}}{3}\n  \\label{eqn:c1contelem2}\n\\end{equation}\n\nNow substituting \\eqnrefs{eqn:xitosbich}{eqn:xitosbichcd} into the\nabove equations yields for element $\\mathit{1}$\n\\begin{equation}\n  \\begin{split}\n    \\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione} &=\n    \\chbfn{0}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{1}}\\esfone{2}+\n    \\chbfn{0}{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}{4}}{s_{1}}\\esfone{5}+ \\\\\n    &\\quad\\chbfn{1}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{2}}{s_{1}}{s_{2}}\n    \\esfone{2}\\esfone{4}+\n    \\chbfn{1}{2}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{4}}{s_{1}}{s_{2}}\n    \\esfone{5}\\esfone{4}\n  \\end{split}\n\\end{equation}\nand for element $\\mathit{2}$\n\\begin{equation}\n  \\begin{split}\n    \\delby{\\fnof{\\vect{x}}{0,\\xitwo}}{\\xione} &=\n    \\chbfn{0}{1}{\\xione}\\delby{\\nodept{\\vect{x}}{1}}{s_{1}}\\esfone{3}+\n    \\chbfn{0}{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}\\esfone{6}+ \\\\\n    &\\quad\\chbfn{1}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{1}}{s_{1}}{s_{2}}\n    \\esfone{3}\\esfone{4}+ \n    \\chbfn{1}{2}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}\n    \\esfone{6}\\esfone{4}\n  \\end{split}\n\\end{equation}\n\nNow local node $2$ in element $\\mathit{1}$ and local node $1$ in element\n$\\mathit{2}$ is the same as global node $\\mathbf{1}$ and local node $4$ in\nelement $\\mathit{1}$ and local node $3$ in element $\\mathit{2}$ is the same as\nglobal node $\\mathbf{2}$. Hence for a given $\\xitwo$ the condition for $C^{1}$\ncontinuity across the element boundary is\n\\begin{multline}\n  \\chbfn{0}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}{\\mathbf{1}}}{s_{1}}\\esfone{2}+\n  \\chbfn{0}{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}{\\mathbf{2}}}{s_{1}}\\esfone{5}+ \n  \\chbfn{1}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{\\mathbf{1}}}{s_{1}}{s_{2}}\n  \\esfone{2}\\esfone{4} \\\\\n  +\\chbfn{1}{2}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{\\mathbf{2}}}{s_{1}}{s_{2}}\n  \\esfone{5}\\esfone{4} = \\chbfn{0}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}\n    {\\mathbf{1}}}{s_{1}}\\esfone{3}+\\chbfn{0}{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}\n    {\\mathbf{2}}}{s_{1}}\\esfone{6} \\\\\n  +\\chbfn{1}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{\\mathbf{1}}}{s_{1}}{s_{2}}\n  \\esfone{3}\\esfone{4}+\\chbfn{1}{2}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}\n    {\\mathbf{2}}}{s_{1}}{s_{2}}\\esfone{6}\\esfone{4}\n\\end{multline}\nor\n\\begin{multline}\n  \\pbrac{\\esfone{2}-\\esfone{3}}\\pbrac{\\chbfn{0}{1}{\\xitwo}\n    \\delby{\\nodept{\\vect{x}}{\\mathbf{1}}}{s_{1}}+\\chbfn{1}{1}{\\xitwo}\n    \\deltwoby{\\nodept{\\vect{x}}{\\mathbf{1}}}{s_{1}}{s_{2}}\\esfone{4}} = \\\\\n  \\pbrac{\\esfone{6}-\\esfone{5}}\\pbrac{\\chbfn{0}{2}{\\xitwo}\n    \\delby{\\nodept{\\vect{x}}{\\mathbf{2}}}{s_{1}}+\\chbfn{1}{2}{\\xitwo}\n    \\deltwoby{\\nodept{\\vect{x}}{\\mathbf{2}}}{s_{1}}{s_{2}}\\esfone{4}}\n  \\label{eqn:bchc1condition}\n\\end{multline}\n\nNow by choosing the scale factors to be equal on either side of node\n$\\mathbf{1}$ and $\\mathbf{2}$ (\\ie $\\esfone{2}=\\esfone{3}=\\nsfone{\\mathbf{1}}$\nand $\\esfone{5}=\\esfone{6}=\\nsfone{\\mathbf{2}}$), that is nodal based scale\nfactors, \\eqnref{eqn:bchc1condition} is satisfied for any choice of the scale\nfactors.  Hence nodal scale factors are a sufficient condition to ensure\n$C^{1}$ continuity. If it is desired that the scale factors be different\neither side of the node then \\eqnref{eqn:bchc1condition} must be satisfied to\nensure continuity.\n\nThe choice of the scale factors again determines the $\\xi$\nto $s$ spacing. We have a number of choices for the scale factor depending on\nwhether or not the $\\xi$ to $s$ spacing should favour bigger or smaller\nelements. One choice which equally favours both elements either side of the\nnode is for the scale factors to be chosen to be nodally based and equal to the average \\arclen on either side\nof the node for each $\\xi$ direction \\ie for the $\\nth{l}$ direction\n\\begin{equation}\n  \\nsftwo{A}{l}=\\dfrac{\\fnof{s_{l}}{\\fnof{A_{\\ominus}}{l}}+\n    \\fnof{s_{l}}{\\fnof{A_{\\oplus}}{l}}}{2}\n  \\label{eqn:arithmeanarclenscale}\n\\end{equation}\nwhere $\\nsftwo{A}{l}$ is the nodal scale factor in the $\\nth{l}$ $\\xi$\ndirection at global node $A$, $\\fnof{A_{\\ominus}}{l}$ is the element\nimmediately preceding (in the \\nth{l} direction) node $A$, and\n$\\fnof{A_{\\oplus}}{l}$ is the element immediately after (in the \\nth{l}\ndirection) node $A$ and $\\fnof{s_{l}}{e}$ is the \\arclen in the \\nth{l} $\\xi$\ndirection from node $A$ in element $e$. This type of scaling is known as\n\\emph{arithmetic mean \\arclen scaling}.\n\nOther means can be used \\ie \\emph{geometric mean \\arclen scaling}\n\\begin{equation}\n  \\nsftwo{A}{l}=\\sqrt{\\fnof{s_{l}}{\\fnof{A_{\\ominus}}{l}}\n    \\fnof{s_{l}}{\\fnof{A_{\\oplus}}{l}}}\n  \\label{eqn:geomeanarclenscale}\n\\end{equation}\nor \\emph{harmonic mean \\arclen scaling}\n\\begin{equation}\n  \\nsftwo{A}{l}=\\dfrac{\\fnof{s_{l}}{\\fnof{A_{\\ominus}}{l}}\n    \\fnof{s_{l}}{\\fnof{A_{\\oplus}}{l}}}{\\fnof{s_{l}}{\\fnof{A_{\\ominus}}{l}}+\n    \\fnof{s_{l}}{\\fnof{A_{\\oplus}}{l}}}\n  \\label{eqn:harmonicmeanarclenscale}\n\\end{equation}\n\n\n\n\\pstexfigure{plots/Theory/funcscaling.pstex}{Function scaling.}\n{Function scaling.}{fig:functionscaling}{1.5}\n\n\\pstexfigure{plots/Theory/firstdscaling.pstex}{First derivative scaling.}\n{First derivative scaling.}{fig:firstdscaling}{1.5}\n\n\\pstexfigure{plots/Theory/seconddscaling.pstex}{Second derivative scaling.}\n{Second derivative scaling.}{fig:seconddscaling}{1.5}\n\n\n\\subsubsection{Hermite-sector elements}\n\\label{sec:hselements}\n\nOne problem that arises when using quadrilateral elements (such as\n\\bicubicherm elements) to describe a surface is that it is impossible to\n'close the surface' in three-dimensions whilst maintaining consistent $\\xione$\nand $\\xitwo$ directions throughout the mesh. This is important as $C^{1}$\ncontinuity requires either consistent $\\xi$ directions or a transformation at\neach node to take into account the inconsistent directions \\cite{petera:1994}.\n\nOne solution to this problem is to \\emph{collapse} a \\bicubicherm element.\nThis entails placing one of the four local nodes of the element at the same\ngeometric location as another local node of the element and results in a\ntriangular element from which it is possible to close the surface. There are\ntwo main problems with this solution.  The first is that one of the two $\\xi$\ndirections at the collapsed node is undefined.  The second is that the\ndistance between the two nodes at the same location is zero.  Numerical\nproblems can result from this zero distance.  An alternative strategy has\nbeen developed in which special elements, called ``Hermite-sector''\nelements\\index{Hermite-sector elements}, are used to close a \\bicubicherm\nsurface in three-dimensions. There are two types of elements depending on\nwhether the $\\xi$ (or $s$) directions come together at local node one or local\nnode three.  These two elements are shown in \\figref{fig:hermitesectors}.\n\n\\epstexfigure{svgs/Theory/hermitesectors.eps_tex}{Hermite-sector elements.}\n{Hermite-sector elements. (a) Apex node one element. (b) Apex node three\n  element.}{fig:hermitesectors}{0.3}\n\nFrom \\figref{fig:hermitesectors} it can be seen that the $s_{2}$ direction is\nnot unique at the apex nodes. This gives us two choices for the interpolation\nwithin the element: ignore the $s_{2}$ derivative when interpolating or set\nthe $s_{2}$ derivative identically to zero.\n\n\\textbf{Ignore $s_{2}$ apex derivative}: For this case it can be seen from\n\\figref{fig:hermitesectors} that the interpolation in the $\\xione$ direction\nis just the standard cubic Hermite interpolation. The interpolation in the\n$\\xitwo$ direction is now a little different in that the nodal \\arclen\nderivative has been dropped as it is no longer defined at the apex node.  For\nan apex node one element shown in \\figref{fig:hermitesectors}(a) the\ninterpolation for the line between local node one and local node $n$ is now\nquadratic and is given by\n\\begin{equation}\n  \\fnof{\\vect{x}}{\\xitwo}=\\hsonebfn{1}{\\xitwo}\\nodept{\\vect{x}}{1}+\n  \\hsonebfn{2}{\\xitwo}\\nodept{\\vect{x}}{n}+\n  \\hsonebfn{3}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xitwo}}{n}\n  \\label{eqn:hsapex1xiinterp}\n\\end{equation}\nwith the basis functions given by\n\\index{quadratic Hermite basis!apex node one!basis functions formulae}\n\\begin{equation}\n  \\begin{split}\n    \\hsonebfn{1}{\\xi}&=\\pbrac{\\xi-1}^{2} \\\\ \n    \\hsonebfn{2}{\\xi}&=2\\xi-\\xi^{2} \\\\\n    \\hsonebfn{3}{\\xi}&=\\xi^{2}-\\xi\n  \\end{split}\n  \\label{eqn:hsapex1bfuns}\n\\end{equation}\n\nFor the apex node three element shown in \\figref{fig:hermitesectors}(b) the\ninterpolation for the line connecting local node $n$ with local node three is\ngiven by\n\\begin{equation}\n  \\fnof{\\vect{x}}{\\xitwo}=\\hsthreebfn{1}{\\xitwo}\\nodept{\\vect{x}}{3}+\n  \\hsthreebfn{2}{\\xitwo}\\nodept{\\vect{x}}{n}+\n  \\hsthreebfn{3}{\\xitwo}\\evalat{\\delby{\\vect{x}}{\\xitwo}}{n}\n  \\label{eqn:hsapex3xiinterp}\n\\end{equation}\nwith the basis functions given by\n\\index{quadratic Hermite basis!apex node three!basis functions formulae}\n\\begin{equation}\n  \\begin{split}\n    \\hsthreebfn{1}{\\xi}&=\\xi^{2} \\\\ \n    \\hsthreebfn{2}{\\xi}&=1-\\xi^{2} \\\\ \n    \\hsthreebfn{3}{\\xi}&=\\xi-\\xi^{2}\n  \\end{split}\n  \\label{eqn:hsapex3Bfuns}\n\\end{equation}\n \nThe full interpolation formula for the sector element can then be found by\ntaking the tensor product of the interpolation in the $\\xione$ direction,\ngiven in \\eqnref{eqn:chxiinterpolation}, with the interpolation in the\n$\\xitwo$ direction (given by either Equations \\bref{eqn:hsapex1xiinterp} or\n\\bref{eqn:hsapex3xiinterp}). The interpolation formula can be converted from\nnodal $\\xi$ derivatives to nodal \\arclen derivatives using the procedure\noutlined for the \\bicubicherm case. For example, the interpolation formulae for\nan apex node one element is \\index{Hermite-sector basis!apex node one!\\arclen\n  interpolation formula}\n\\begin{equation}\n  \\begin{split}\n    \\fnof{\\vect{x}}{\\xione,\\xitwo} &=\n    \\hsonebfn{1}{\\xitwo}\\nodept{\\vect{x}}{1}+\\chbfn{1}{0}{\\xione}\\hsonebfn{2}\n    {\\xitwo}\\nodept{\\vect{x}}{2}+\\chbfn{2}{0}{\\xione}\\hsonebfn{2}{\\xitwo}\n    \\nodept{\\vect{x}}{3} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\hsonebfn{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{1}}\n    \\nsftwo{2}{1}+\\chbfn{2}{1}{\\xione}\\hsonebfn{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}\n      {3}}{s_{1}}\\nsftwo{3}{1} + \\\\\n    & \\chbfn{1}{0}{\\xione}\\hsonebfn{3}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{2}}\n    \\nsftwo{2}{2} + \\chbfn{2}{0}{\\xione}\\hsonebfn{3}{\\xitwo}\n    \\delby{\\nodept{\\vect{x}}{3}}{s_{2}}\\nsftwo{3}{2} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\hsonebfn{3}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{2}}\n    {s_{1}}{s_{2}}\\nsftwo{2}{1}\\nsftwo{2}{2} + \n    \\chbfn{2}{1}{\\xione}\\hsonebfn{3}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{3}}\n    {s_{1}}{s_{2}}\\nsftwo{3}{1}\\nsftwo{3}{2}    \n  \\end{split}\n  \\label{eqn:hsapex1sinterp}\n\\end{equation}\n\nCare must be taken when using Hermite-sector elements for rapidly changing\nsurfaces. Consider an apex node one element with undefined $s_{2}$ apex\nderivatives. The rate of change of $\\vect{x}$ with respect to\n$\\xione$ along the line from node one to node three (\\ie $\\xione=1$) is\n\\begin{equation}\n  \\begin{split}\n    \\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione} &= \\hsonebfn{2}{\\xitwo}\\delby{\n      \\nodept{\\vect{x}}{3}}{s_{1}}\\nsftwo{3}{1}+\\hsonebfn{3}{\\xitwo}\\deltwoby{\n      \\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}\\nsftwo{3}{1}\\nsftwo{3}{2} \\\\\n    &= \\nsftwo{3}{1}\\pbrac{\\pbrac{2\\xitwo-\\xitwo^{2}}\\delby{\\nodept{\\vect{x}}{3}}\n      {s_{1}}+\\pbrac{\\xitwo^{2}-\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}\n      \\nsftwo{3}{2}}\n  \\end{split}\n\\end{equation}\n\nTaking the dot product of $\\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione}$ with \n$\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}$ gives\n\\begin{equation}\n  \\dotprod{\\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione}}{\\delby{\\nodept{\\vect{x}}{3}}\n    {s_{1}}} = \\nsftwo{3}{1}\n  \\pbrac{\\pbrac{2\\xitwo-\\xitwo^{2}}\\dotprod{\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}\n    {\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}+\\pbrac{\\xitwo^{2}-\\xitwo}\\nsftwo{3}{2}\n    \\dotprod{\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}\n    {\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}}\n  \\label{eqn:hsonedirectiondotprod}\n\\end{equation}\n\nThe normality constraint for \\arclen derivatives means that\n$\\dotprod{\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}{\\delby{\\nodept{\\vect{x}}{3}}\n  {s_{1}}}=1$ and thus the right hand side of\n\\eqnref{eqn:hsonedirectiondotprod} divided by $\\nsftwo{3}{1}$ (\\ie normalised\nby $\\nsftwo{3}{1}$) is the quadratic\n\\begin{equation*}\n  \\pbrac{2\\xitwo-\\xitwo^{2}}+\\pbrac{\\xitwo^{2}-\\xitwo}\\nsftwo{3}{2}\n  \\dotprod{\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}\n      {3}}{s_{1}}} \n\\end{equation*}\nor\n\\begin{equation*}\n  \\pbrac{\\nsftwo{3}{2}\\dotprod{\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}\n    {\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}} -1}\\xitwo^{2}+\n  \\pbrac{2-\\nsftwo{3}{2}\\dotprod{\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}\n    {\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}}\\xitwo\n  \\label{eqn:hsonedirectionpolynomial}\n\\end{equation*}\n\nThis quadratic is $1$ at $\\xitwo=1$ and always has a root at $\\xitwo=0$.\nConsider the case of this quadratic having its second root in the interval\n$(0,1)$. This would mean that at some point in the interval $(0,1)$ the dot\nproduct of \\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione} and\n\\delby{\\nodept{\\vect{x}}{3}}{s_{1}} would go from zero to negative and then\npositive as $\\xitwo$ changed from $0$ to $1$ \\ie the angle between\n$\\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione}$ and\n$\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}$ would, at some stage, be greater than\nninety degrees. As the direction of the normal to the surface along the line\nbetween local node one and three is given by the cross product of\n$\\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xione}$ and\n$\\delby{\\fnof{\\vect{x}}{1,\\xitwo}}{\\xitwo}$ then, if the quadratic became\nsufficiently negative, the normal to the surface could reverse direction from\nan outward to an inward normal as $\\xitwo$ changed from $0$ to $1$. This is\nclearly undesirable. In fact even if the quadratic is only slightly negative\nthe resulting surface would be grossly deformed.\n\nTo avoid these effects the second root of the quadratic must be outside the\ninterval $(0,1)$. From the quadratic formula the conditions for this are\n\\begin{equation}\n  \\dfrac{\\nsftwo{3}{2}\\dotprod{\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}\n    {\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}-2}{\\nsftwo{3}{2}\\dotprod{\n      \\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}{3}}\n      {s_{1}}}-1}<0\n\\end{equation}\nand \n\\begin{equation}\n  \\dfrac{\\nsftwo{3}{2}\\dotprod{\\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}\n    {\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}}-2}{\\nsftwo{3}{2}\\dotprod{\n      \\deltwoby{\\nodept{\\vect{x}}{3}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}{3}}\n      {s_{1}}}-1}>1\n\\end{equation}\nthat is (for the line from local node one to local node $n$) \n\\index{Hermite-sector basis!apex node one!cross-derivative condition}\n\\begin{equation}\n  \\dotprod{\\deltwoby{\\nodept{\\vect{x}}{n}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}\n      {n}}{s_{1}}}<\\dfrac{2}{\\nsftwo{n}{2}}\n\\end{equation}\n\nThe simplest way to interpret this constraint is that if the element is large\n(\\ie $\\nsftwo{n}{2}$ is large) then $\\dotprod{\\deltwoby{\\nodept{\\vect{x}}{n}}\n  {s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}{n}}{s_{1}}}$ must be small. The\nsimplest way for this to happen is to ensure the magnitude of the components of\n$\\deltwoby{\\nodept{\\vect{x}}{n}}{s_{1}}{s_{2}}$ are small (or of opposite sign to\nthe comparable components of $\\delby{\\nodept{\\vect{x}}{n}}{s_{1}}$).\n\nThe equivalent interpolation formula to \\eqnref{eqn:hsapex1sinterp} for an\napex node three Hermite-sector element is \n\\index{Hermite-sector basis!apex node three!\\arclen interpolation formula}\n\\begin{equation}\n  \\begin{split}\n    \\fnof{\\vect{x}}{\\xione,\\xitwo} &=\n    \\chbfn{1}{0}{\\xione}\\hsthreebfn{2}{\\xitwo}\\nodept{\\vect{x}}{1}+\n    \\chbfn{2}{0}{\\xione}\\hsthreebfn{2}{\\xitwo}\\nodept{\\vect{x}}{2}+\n    \\hsthreebfn{1}{\\xitwo}\\nodept{\\vect{x}}{3}+ \\\\\n    & \\chbfn{1}{1}{\\xione}\\hsthreebfn{2}{\\xitwo}\\delby{\\nodept{\\vect{x}}{1}}\n    {s_{1}}\\nsftwo{1}{1}+\\chbfn{2}{1}{\\xione}\\hsthreebfn{2}{\\xitwo}\n    \\delby{\\nodept{\\vect{x}}{2}}{s_{1}}\\nsftwo{2}{1} + \\\\\n    & \\chbfn{1}{0}{\\xione}\\hsthreebfn{3}{\\xitwo}\\delby{\\nodept{\\vect{x}}{1}}\n    {s_{2}}\\nsftwo{1}{2}+\\chbfn{2}{0}{\\xione}\\hsthreebfn{3}{\\xitwo}\n    \\delby{\\nodept{\\vect{x}}{2}}{s_{2}}\\nsftwo{2}{2} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\hsthreebfn{3}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{1}}\n    {s_{1}}{s_{2}}\\nsftwo{1}{1}\\nsftwo{1}{2} + \n    \\chbfn{2}{1}{\\xione}\\hsthreebfn{3}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{2}}\n    {s_{1}}{s_{2}}\\nsftwo{2}{1}\\nsftwo{2}{2}    \n  \\end{split}\n  \\label{eqn:hsapex3sinterp}\n\\end{equation}\nand the equivalent constraint for apex node three Hermite-sector elements (for\nthe line from local node $n$ to local node three) is\n\\index{Hermite-sector basis!apex node three!cross-derivative condition}\n\\begin{equation}\n  \\dotprod{\\deltwoby{\\nodept{\\vect{x}}{n}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}\n      {n}}{s_{1}}}>\\dfrac{-2}{\\nsftwo{n}{2}}\n\\end{equation}\n\n\\textbf{Zero $s_{2}$ apex derivative}: For this case the sector basis\nfunctions are just the cubic Hermite basis functions. The corresponding\ninterpolation formulae for an apex node one element is hence\n\\begin{equation}\n  \\begin{split}\n    \\fnof{\\vect{x}}{\\xione,\\xitwo} &= \\chbfn{1}{0}{\\xitwo}\n    \\nodept{\\vect{x}}{1} + \n     \\chbfn{1}{0}{\\xione}\\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{2} +\n    \\chbfn{2}{0}{\\xione}\\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{3} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\chbfn{2}{0}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{1}}\n    \\nsftwo{2}{1}+\n    \\chbfn{2}{1}{\\xione}\\chbfn{2}{0}{\\xitwo}\\delby{\\nodept{\\vect{x}}{3}}{s_{1}}\n    \\nsftwo{3}{1} + \\\\ \n    & \\chbfn{1}{0}{\\xione}\\chbfn{2}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{2}}\n    \\nsftwo{2}{2}+\n    \\chbfn{2}{0}{\\xione}\\chbfn{2}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{2}}\n    \\nsftwo{3}{2} + \\\\ \n    & \\chbfn{1}{1}{\\xione}\\chbfn{2}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{2}}\n      {s_{1}}{s_{2}}\\nsftwo{2}{1}\\nsftwo{2}{2} + \n    \\chbfn{2}{1}{\\xione}\\chbfn{2}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{3}}\n      {s_{1}}{s_{2}}\\nsftwo{3}{1}\\nsftwo{3}{2}\n  \\end{split}\n\\end{equation}\nand the condition to avoid reversal of the normal is\n\\begin{equation}\n  \\dotprod{\\deltwoby{\\nodept{\\vect{x}}{n}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}\n      {n}}{s_{1}}}<\\dfrac{3}{\\nsftwo{n}{2}}\n\\end{equation}\nand for the apex node three element the interpolation formula is\n\\begin{equation}\n  \\begin{split}\n    \\fnof{\\vect{x}}{\\xione,\\xitwo} &=\n    \\chbfn{1}{0}{\\xione}\\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{1} +\n    \\chbfn{2}{0}{\\xione}\\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{2} + \n    \\chbfn{2}{0}{\\xitwo}\\nodept{\\vect{x}}{3} + \\\\\n    & \\chbfn{1}{1}{\\xione}\\chbfn{1}{0}{\\xitwo}\\delby{\\nodept{\\vect{x}}{1}}{s_{1}}\n    \\nsftwo{1}{1}+\n    \\chbfn{2}{1}{\\xione}\\chbfn{1}{0}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{1}}\n    \\nsftwo{2}{1} + \\\\ \n    & \\chbfn{1}{0}{\\xione}\\chbfn{1}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}{1}}{s_{2}}\n    \\nsftwo{1}{2}+\n    \\chbfn{2}{0}{\\xione}\\chbfn{1}{1}{\\xitwo}\\delby{\\nodept{\\vect{x}}{2}}{s_{2}}\n    \\nsftwo{2}{2} + \\\\ \n    & \\chbfn{1}{1}{\\xione}\\chbfn{1}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{1}}\n      {s_{1}}{s_{2}}\\nsftwo{1}{1}\\nsftwo{1}{2} + \n    \\chbfn{2}{1}{\\xione}\\chbfn{1}{1}{\\xitwo}\\deltwoby{\\nodept{\\vect{x}}{2}}\n      {s_{1}}{s_{2}}\\nsftwo{2}{1}\\nsftwo{2}{2}\n  \\end{split}\n\\end{equation}\nwith a condition of\n\\begin{equation}\n  \\dotprod{\\deltwoby{\\nodept{\\vect{x}}{n}}{s_{1}}{s_{2}}}{\\delby{\\nodept{\\vect{x}}\n      {n}}{s_{1}}}>\\dfrac{-3}{\\nsftwo{n}{2}}\n\\end{equation}\n\nAlthough the Hermite-sector basis function in which the $s_{2}$ apex node\nderivatives are identically zero have an increased limit on the\ncross-derivative constraints (a right hand side numerator of $\\pm 3$ instead\nof $\\pm 2$) they have the problem that as all derivatives vanish at the apex\nany interpolated function has a zero Hessian at the apex. As this can cause\nnumerical problems the Hermite-sector basis functions which have an undefined\n$s_{2}$ derivative are prefered.\n\n\n\\subsection{Simplex Basis Functions}\n\nSimplex basis function and its derivatives are evaluated with respect to external $\\vect{\\xi}$ coordinates.\n\nFor Simplex line elements there are two area coordinates which are a function of $\\xi_{1}$ \\ie\n\\begin{align}\n  L_{1} &= 1 - \\xi_{1} \\\\\n  L_{2} &= \\xi_{1} - 1\n\\end{align}\n\nThe derivatives wrt to external coordinates are then given by \n\\begin{align}\n  \\delby{\\vect{\\sbfnsymb{}}}{\\xi_{1}} &= \\delby{\\vect{\\sbfnsymb{}}}{L_{2}}-\\delby{\\vect{\\sbfnsymb{}}}{L_{1}} \\\\\n  \\deltwosqby{\\vect{\\sbfnsymb{}}}{\\xi_{1}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{1}}-\n  2\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{2}}+\\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{2}}\n\\end{align}\n\nFor Simplex triangle elements there are three area coordinates which are a function of $\\xi_{1}$ and\n$\\xi_{2}$ \\ie\n\\begin{align} \n  L_{1} &= 1 - \\xi_{1} \\\\\n  L_{2} &= 1 - \\xi_{2} \\\\\n  L_{3} &= \\xi_{1} + \\xi_{2} - 1 \n\\end{align}\n\nThe derivatives wrt to external coordinates are then given by \n\\begin{align}\n  \\delby{\\vect{\\sbfnsymb{}}}{\\xi_{1}} &= \\delby{\\vect{\\sbfnsymb{}}}{L_{3}}-\\delby{\\vect{\\sbfnsymb{}}}{L_{1}} \\\\\n  \\delby{\\vect{\\sbfnsymb{}}}{\\xi_{2}} &= \\delby{\\vect{\\sbfnsymb{}}}{L_{3}}-\\delby{\\vect{\\sbfnsymb{}}}{L_{2}} \\\\\n  \\deltwosqby{\\vect{\\sbfnsymb{}}}{\\xi_{1}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{1}}- \n  2\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{3}}+\\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{3}} \\\\\n  \\deltwosqby{\\vect{\\sbfnsymb{}}}{\\xi_{2}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{2}}- \n  2\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{3}}+\\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{3}} \\\\\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{\\xi_{1}}{\\xi_{2}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{3}}-\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{3}}-\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{3}}+\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{2}}\n\\end{align}\n  \nFor Simplex tetrahedral elements there are four area coordinates which are a\nfunction of $\\xi_{1}$, $\\xi_{2}$ and $\\xi_{3}$ \\ie\n\\begin{align}\n  L_{1} &= 1 - \\xi_{1} \\\\\n  L_{2} &= 1 - \\xi_{2} \\\\\n  L_{3} &= 1 - \\xi_{3} \\\\\n  L_{4} &= \\xi_{1} + \\xi_{2} + \\xi_{3} - 2\n\\end{align}\n\nThe derivatives wrt to external coordinates are then given by\n\\begin{align}\n  \\delby{\\vect{\\sbfnsymb{}}}{\\xi_{1}} &= \\delby{\\vect{\\sbfnsymb{}}}{L_{4}}-\\delby{\\vect{\\sbfnsymb{}}}{L_{1}} \\\\\n  \\delby{\\vect{\\sbfnsymb{}}}{\\xi_{2}} &= \\delby{\\vect{\\sbfnsymb{}}}{L_{4}}-\\delby{\\vect{\\sbfnsymb{}}}{L_{2}} \\\\\n  \\delby{\\vect{\\sbfnsymb{}}}{\\xi_{3}} &= \\delby{\\vect{\\sbfnsymb{}}}{L_{4}}-\\delby{\\vect{\\sbfnsymb{}}}{L_{3}} \\\\\n  \\deltwosqby{\\vect{\\sbfnsymb{}}}{\\xi_{1}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{1}}-\n  2\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{4}}+\\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{4}} \\\\\n  \\deltwosqby{\\vect{\\sbfnsymb{}}}{\\xi_{2}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{2}}-\n  2\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{4}}+\\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{4}} \\\\\n  \\deltwosqby{\\vect{\\sbfnsymb{}}}{\\xi_{3}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{3}}-\n  2\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{3}}{L_{4}}+\\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{4}} \\\\  \n  \\deltwoby{\\vect{\\sbfnsymb{}}}{\\xi_{1}}{\\xi_{2}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{4}}-\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{4}}-\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{4}}+\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{2}} \\\\\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{\\xi_{1}}{\\xi_{3}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{4}}-\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{4}}-\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{3}}{L_{4}}+\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{3}} \\\\\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{\\xi_{2}}{\\xi_{3}} &= \\deltwosqby{\\vect{\\sbfnsymb{}}}{L_{4}}-\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{4}}-\\deltwoby{\\vect{\\sbfnsymb{}}}{L_{3}}{L_{4}}+\n  \\deltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{3}} \\\\\n  \\delthreeby{\\vect{\\sbfnsymb{}}}{\\xi_{1}}{\\xi_{2}}{\\xi_{3}} &= \\delthreecuby{\\vect{\\sbfnsymb{}}}{L_{4}}-\n  \\deldeltwoby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{4}}-\\deldeltwoby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{4}}-\n  \\deldeltwoby{\\vect{\\sbfnsymb{}}}{L_{3}}{L_{4}}+ \\\\\n  &\\delthreeby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{2}}{L_{4}}+\\delthreeby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{3}}{L_{4}}+\n  \\delthreeby{\\vect{\\sbfnsymb{}}}{L_{2}}{L_{3}}{L_{4}}-\\delthreeby{\\vect{\\sbfnsymb{}}}{L_{1}}{L_{2}}{L_{3}}\n\\end{align}\n\n\\section{Tensor Analysis}\n\\subsection{Base vectors}\n\nNow, if we have a vector, $\\vect{v}$ we can write\n\\begin{equation}\n  \\vect{v}=v^{i}\\vect{g}_{i}\n\\end{equation}\nwhere $v^{i}$ are the components of the contravariant vector, and\n$\\vect{g}_{i}$ are the covariant base vectors.\n\nSimilarly, the vector $\\vect{v}$ can also be written as \n\\begin{equation}\n  \\vect{v}=v_{i}\\vect{g}^{i}\n\\end{equation}\nwhere $v_{i}$ are the components of the covariant vector, and\n$\\vect{g}^{i}$ are the contravariant base vectors. \n\nWe now note that\n\\begin{equation}\n  \\vect{v}=v^{i}\\vect{g}_{i}=v^{i}\\sqrt{g_{ii}}\\hat{\\vect{g}_{i}}\n\\end{equation}\nwhere $v^{i}\\sqrt{g_{ii}}$ are the physical components of the vector and\n$\\hat{\\vect{g}_{i}}$ are the unit vectors given by\n\\begin{equation}\n  \\hat{\\vect{g}_{i}}=\\dfrac{\\vect{g}_{i}}{\\sqrt{g_{ii}}}\n\\end{equation}\n\n\\subsection{Metric Tensors}\n\\label{sec:metric tensors}\n\nMetric tensors are the inner product of base vectors. If $\\vect{g}_{i}$ are the\ncovariant base vectors then the covariant metric tensor is given by\n\\begin{equation}\n  g_{ij}=\\dotprod{\\vect{g}_{i}}{\\vect{g}_{j}}\n\\end{equation}\n\nSimilarily if $\\vect{g}^{i}$ are the contravariant base vectors then the\ncontravariant metric tensor is given by \n\\begin{equation}\n  g^{ij}=\\dotprod{\\vect{g}^{i}}{\\vect{g}^{j}}\n\\end{equation}\n\nWe can also form a mixed metric tensor from the dot product of a contravariant\nand a covariant base vector \\ie\n\\begin{equation}\n  g^{i}_{.j}=\\dotprod{\\vect{g}^{i}}{\\vect{g}_{j}}\n\\end{equation}\nand \n\\begin{equation}\n  g_{i}^{.j}=\\dotprod{\\vect{g}_{i}}{\\vect{g}^{j}}\n\\end{equation}\n\nNote that for mixed tensors the ``.'' indicates the order of the index \\ie\n$g^{i}_{.j}$ indicates that the first index is contravariant and the second\nindex is covariant whereas $g_{i}^{.j}$ indicates that the first index is\ncovariant and the second index is contravariant.\n\nIf the base vectors are all mutually orthogonal and constant then\n$\\vect{g}_{i}=\\vect{g}^{i}$ and $g_{ij}=g^{ij}$.\n\nThe metric tensors generalise (Euclidean) distance \\ie\n\\begin{equation}\n  ds^{2}=g_{ij}dx^{i}dx^{j}\n\\end{equation}\n\nNote that multiplying by the covariant metric tensor lowers indices \\ie\n\\begin{equation}\n  \\begin{split}\n    \\vect{A}_{i} &= g_{ij}\\vect{A}^{j} \\\\\n    A_{ij} &= g_{ik}g_{jl}A^{kl} = g_{jk}A_{i}^{.k} = g_{ik}A^{k}_{.j} \n  \\end{split}\n\\end{equation}\nand that multiplying by the contravariant metric tensor raises indices \\ie\n\\begin{equation}\n  \\begin{split}\n  \\vect{A}^{i} &=  g^{ij}\\vect{A}_{j} \\\\\n   A^{ij} &= g^{ik}g^{jl}A_{kl} = g^{ik}A_{k}^{.j} = g^{jk}A^{i}_{.k}\n  \\end{split}\n\\end{equation}\nand for the mixed tensors\n\\begin{equation}\n  \\begin{split}\n  A_{i}^{.j} &= g^{jk}A_{ik} = g_{ik}A^{kj} \\\\\n  A^{i}_{.j} &= g^{ik}A_{kj} = g_{jk}A^{ik} \\\\\n  \\end{split}\n\\end{equation}\n\n\\subsection{Transformations}\n\nThe transformation rules for tensors in going from a $\\vect{\\nu}$ coordinate\nsystem to a $\\vect{\\xi}$ coordinate system are as follows: \n\n\nFor a covariant vector (a rank (0,1) tensor)\n\\begin{equation}\n  {\\tilde{a}}_{i}=\\delby{\\nu^{a}}{\\xi^{i}}a_{a}\n\\end{equation}\n\nFor a contravariant vector (a rank (1,0) tensor)\n\\begin{equation}\n  {\\tilde{a}}^{i}=\\delby{\\xi^{i}}{\\nu^{a}}a^{a}\n\\end{equation}\n\nFor a covariant tensor (a rank (0,2) tensor)\n\\begin{equation}\n  {\\tilde{A}}_{ij}=\\delby{\\nu^{a}}{\\xi^{i}}\\delby{\\nu^{b}}{\\xi^{j}}A_{ab} \n\\end{equation}\n\nFor a contravariant tensor (a rank (2,0) tensor)\n\\begin{equation}\n  {\\tilde{A}}^{ij}=\\delby{\\xi^{i}}{\\nu^{a}}\\delby{\\xi^{j}}{\\nu^{b}}A^{ab}\n\\end{equation}\n\nand for Mixed tensors (rank (1,1) tensors)\n\\begin{equation}\n  {\\tilde{A}}^{i}_{.j}=\\delby{\\xi^{i}}{\\nu^{a}}\\delby{\\nu^{b}}{\\xi^{j}}A^{a}_{.b}\n\\end{equation}\nand\n\\begin{equation}\n  {\\tilde{A}}_{i}^{.j}=\\delby{\\nu^{a}}{\\xi^{i}}\\delby{\\xi^{j}}{\\nu^{b}}A_{a}^{.b}\n\\end{equation}\n\n\\subsection{Derivatives}\n\\label{subsec:function derivatives}\n\n\\subsubsection{Scalars}\n\nWe note that a scalar quantity $\\fnof{u}{\\vect{\\xi}}$ has derivatives\n\\begin{equation}\n  \\delby{u}{\\xi^{i}}=\\partialderiv{u}{i}\n\\end{equation}\n\nOr more formally, the covariant derivative ($\\covarderiv{\\cdot}{\\cdot}$) of a\nrank 0 tensor $u$ is\n\\begin{equation}\n  \\covarderiv{u}{i}=\\delby{u}{\\xi^{i}}=\\partialderiv{u}{i}\n\\end{equation}\n\n\\subsubsection{Vectors}\n\nThe derivatives of a vector $\\vect{v}$ are given by\n\\begin{equation}\n  \\begin{split}\n    \\delby{\\vect{v}}{\\xi^{i}} &=\n    \\delby{}{\\xi^{i}}\\pbrac{v^{k}\\vect{g}_{k}} \\\\\n    &= \\delby{v^{k}}{\\xi^{i}}\\vect{g}_{k}+v^{k}\\delby{\\vect{g}_{k}}{\\xi^{i}} \\\\\n    &= \\partialderiv{v^{k}}{i}\\vect{g}_{k}+v^{k}\\partialderiv{\\vect{g}_{k}}{i}\n  \\end{split}\n\\end{equation}\n\nNow introducing the notation\n\\begin{equation}\n  \\christoffelsecond{i}{j}{k} = \\dotprod{\\vect{g}^{i}}{\\delby{\\vect{g}_{j}}{x^{k}}}\n\\end{equation}\nwhere $\\christoffelsecond{i}{j}{k}$ are the Christoffel symbols of the second\nkind. \n\nNote that the Christoffel symbols of the first kind are given by\n\\begin{equation}\n  \\christoffelfirst{i}{j}{k} = \\dotprod{\\vect{g}_{i}}{\\delby{\\vect{g}_{j}}{x^{k}}}\n\\end{equation}\n\nNote that\n\\begin{equation}\n  \\begin{split}\n    \\christoffel{i}{j}{k} &= \\dotprod{\\vect{g}^{i}}{\\partialderiv{\\vect{g}_{j}}{k}} \\\\\n    &=\\dotprod{\\vect{g}^{i}}{\\christoffelsecond{l}{j}{k}\\vect{g}_{l}} \\\\\n    &= \\christoffel{i}{j}{l}g^{i}_{.l} \n  \\end{split}\n\\end{equation}\n\nThe Christoffel symbols of the first kind are also given by\n\\begin{equation}\n  \\christoffelfirst{i}{j}{k}=\\frac{1}{2}\\pbrac{\\delby{g_{ij}}{\\xi^{k}}+\\delby{g_{ik}}{\\xi^{j}}-\\delby{g_{jk}}{\\xi^{i}}}\n\\end{equation}\nand that Christoffel symbols of the second kind are given by\n\\begin{equation}\n  \\begin{split}\n    \\christoffelsecond{i}{j}{k} &= g^{il}\\christoffelfirst{l}{j}{k} \\\\\n    &= \\frac{1}{2}g^{il}\\pbrac{\\delby{g_{lj}}{\\xi^{k}}+\\delby{g_{lk}}{\\xi^{j}}-\\delby{g_{jk}}{\\xi^{l}}} \n  \\end{split}\n\\end{equation}\n\nNote that Christoffel symbols are not tensors and the have the following\ntransformation laws from $\\vect{\\nu}$ to $\\vect{\\xi}$ coordinates\n\\begin{align}\n  \\christoffelfirst{i}{j}{k} &=\n  \\christoffelfirst{a}{b}{c}\\delby{\\nu^{b}}{\\xi^{j}}\\delby{\\nu^{c}}{\\xi^{k}}\\delby{\\nu^{a}}{\\xi^{i}}+\n  g_{ab}\\delby{\\nu^{c}}{\\xi^{i}}\\deltwoby{\\nu^{c}}{\\xi^{j}}{\\xi^{k}} \\\\\n  \\christoffelsecond{i}{j}{k} &= \\christoffelsecond{a}{b}{c}\\delby{\\xi^{i}}{\\nu^{a}}\\delby{\\nu^{b}}{\\xi^{k}}\\delby{\\nu^{c}}{\\xi^{j}}+\n  \\delby{\\xi^{i}}{\\nu^{a}}\\deltwoby{\\nu^{a}}{\\xi^{j}}{\\xi^{k}} \\\\\n\\end{align}\n\nWe can now write (BELOW SEEMS WRONG - CHECK)\n\\begin{equation}\n  \\begin{split}\n    \\partialderiv{\\vect{v}}{i}&=\\partialderiv{v^{k}}{i}\\vect{g}_{k}+\\christoffel{k}{i}{j}v^{j}\\vect{g}_{j}\\\\\n    &=\\partialderiv{v^{k}}{i}\\vect{g}_{k}+\\christoffel{j}{i}{k}v^{k}\\vect{g}_{k}\\\\\n    &=\\pbrac{\\partialderiv{v^{k}}{i}+\\christoffel{j}{i}{k}v^{k}}\\vect{g}_{k}\\\\\n    &=\\covarderiv{v^{k}}{i}\\vect{g}_{k}\n  \\end{split}\n\\end{equation}\nwhere $\\covarderiv{v^{k}}{i}$ is the covariant derivative of $v^{k}$ . \n\nThe covariant derivative of a contravariant (rank (0,1)) tensor $v^{k}$ is\n\\begin{equation}\n  \\covarderiv{v^{k}}{i} =\\partialderiv{v^{k}}{i}+\\christoffel{k}{i}{j}v^{j}\n\\end{equation}\nand the covariant derivative of a covariant tensor  (rank (1,0)) $v_{k}$ is\n\\begin{equation}\n  \\covarderiv{v_{k}}{i} =\\partialderiv{v_{k}}{i}-\\christoffel{j}{k}{i}v_{j}\n\\end{equation}\n\n\\subsubsection{Tensors}\n\nThe covariant derivative of a contravariant (rank (0,2)) tensor $W^{mn}$ is\n\\begin{equation}\n  \\covarderiv{W^{mn}}{i}=\\partialderiv{W^{mn}}{i}+\\christoffel{m}{j}{i}W^{jn}+\\christoffel{n}{j}{i}W^{mj}\n\\end{equation}\nand the covariant derivative of a covariant (rank (2,0)) tensor $W_{mn}$ is\n\\begin{equation}\n  \\covarderiv{W_{mn}}{i}=\\partialderiv{W_{mn}}{i}-\\christoffel{j}{m}{i}W_{jn}-\\christoffel{j}{n}{i}W_{mj}\n\\end{equation}\nand the covariant derivative of a mixed (rank (1,1)) tensor $W^{m}_{.n}$ is\n\\begin{equation}\n  \\covarderiv{W^{m}_{.n}}{i}=\\partialderiv{W^{m}_{.n}}{i}+\\christoffel{m}{j}{i}W^{j}_{.n}-\\christoffel{j}{n}{i}W^{m}_{.j}\n\\end{equation}\n\n\\subsection{Common Operators}\n\nFor tensor equations to hold in any coordinate system the equations must\ninvolve tensor quantities \\ie covariant derivatives rather than partial derivatives.\n\n\\subsubsection{Gradient}\n\nAs the covariant derivative of a scalar is just the partial derivative the\ngradient of a scalar function $\\phi$ using covariant derivatives is\n\\begin{equation}\n  \\text{grad } \\phi = \\gradient{\\phi}=\\covarderiv{\\phi}{i}\\vect{g}^{i}=\\partialderiv{\\phi}{i}\\vect{g}^{i}\n\\end{equation}\nand\n\\begin{equation}\n  \\gradient{\\phi}=\\partialderiv{\\phi}{i}\\vect{g}^{i}=\\partialderiv{\\phi}{i}g^{ij}\\vect{g}_{j}\n\\end{equation}\n\n\\subsubsection{Divergence}\n\nThe divergence of a vector using covariant derivatives is\n\\begin{equation}\n  \\text{div } \\vect{\\phi} = \\diverg{\\vect{\\phi}}=\\covarderiv{\\phi^{i}}{i}=\\frac{1}{\\sqrt{\\abs{g}}}\\partialderiv{\\pbrac{\\sqrt{\\abs{g}}\\phi^{i}}}{i}\n\\end{equation}\nwhere $g$ is the determinant of the covariant metric tensor $g_{ij}$.\n\n\\subsubsection{Curl}\n\nThe curl of a vector using covariant derivatives is\n\\begin{equation}\n  \\text{curl } \\vect{\\phi} = \\curl{\\vect{\\phi}}=\\frac{1}{\\sqrt{g}}\\pbrac{\\covarderiv{\\phi_{j}}{i}-\\covarderiv{\\phi_{i}}{j}}\\vect{g}_{k}\n\\end{equation}\nwhere $g$ is the determinant of the covariant metric tensor $g_{ij}$.\n\n\\subsubsection{Laplacian}\n\nThe Laplacian of a scalar using covariant derivatives is\n\\begin{equation}\n  \\laplacian{\\phi}=\\text{div}\\pbrac{\\text{grad }\\phi}=\\diverg{\\gradient{\\phi}}=\\mixedderiv{\\phi}{i}{i}=\\frac{1}{\\sqrt{g}}\\partialderiv{\\pbrac{\\sqrt{g}g^{ij}\\partialderiv{\\phi}{j}}}{i}\n\\end{equation}\nwhere $g$ is the determinant of the covariant metric tensor $g_{ij}$.\n\nThe Laplacian of a vector using covariant derivatives is\n\\begin{equation}\n  \\laplacian{\\vect{\\phi}}=\\text{grad }\\pbrac{\\text{div }\\vect{\\phi}}-\\text{curl } \\pbrac{\\text{curl }\\vect{\\phi}}==\\mixedderiv{\\vect{\\phi}}{i}{i}\n\\end{equation}\n\nThe Laplacian of a contravariant (rank (0,1)) tensor $\\phi^{k}$ is\n\\begin{equation}\n  \\laplacian{\\vect{\\phi}}=\\pbrac{\\laplacian{\\phi_{k}}-2g^{ij}\\christoffel{K}{j}{H}\\delby{\\phi^{h}}{x^{i}}+\\phi^{h}\\delby{g^{ij}\\christoffel{K}{i}{j}}{x^{h}}}\\vect{e}^{k}\n\\end{equation}\nand the covariant derivative of a covariant tensor  (rank (1,0)) $\\phi_{k}$ is\n\\begin{equation}\n  \\laplacian{\\vect{\\phi}}=\\pbrac{\\laplacian{\\phi_{k}}-2g^{ij}\\christoffel{h}{j}{k}\\delby{\\phi_{h}}{x^{i}}+\\phi_{h}g^{ij}\\delby{\\christoffel{h}{i}{j}}{x^{i}}}\\vect{e}_{k}\n\\end{equation}\n\n\\subsection{Coordinate Systems}\n\\label{sec:coordinate systems}\n\n\\subsubsection{Rectangular Cartesian}\n\nThe base vectors with respect to the global coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    \\vect{i}_{1} \\\\ \n    \\vect{i}_{2} \\\\\n    \\vect{i}_{3} \n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffel symbols of the second kind are all zero.\n\n\\subsubsection{Cylindrical Polar}\n\nThe global coordinates  $\\pbrac{x,y,z}$ with respect to the cylindrical polar\ncoordinates $\\pbrac{r,\\theta,z}$ are defined by\n\\begin{equation}\n  \\begin{aligned}\n    x = r\\cos\\theta  & \\qquad r \\ge0 \\\\\n    y = r\\sin\\theta & \\qquad 0 \\le\\theta\\le2\\pi \\\\\n    z = z          & \\qquad -\\infty < z < \\infty\n  \\end{aligned}\n\\end{equation}\n\nThe base vectors with respect to the global coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    \\cos\\theta\\vect{i}_{1} + \\sin\\theta\\vect{i}_{2} \\\\ \n    -r\\sin\\theta\\vect{i}_{1}+ r\\cos\\theta\\vect{i}_{2} \\\\\n    \\vect{i}_{3} \n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & r^{2} & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & \\frac{1}{r^{2}} & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffell symbols of the second kind are\n\\begin{align}\n  \\christoffelsecond{r}{\\theta}{\\theta}&=-r \\\\\n  \\christoffelsecond{\\theta}{r}{\\theta}=\\christoffelsecond{\\theta}{\\theta}{r}&=\\frac{1}{r}\n\\end{align}\nwith all other Christoffell symbols zero.\n\n\\subsubsection{Spherical Polar}\n\nThe global coordinates $\\pbrac{x,y,z}$ with respect to the cylindrical polar\ncoordinates $\\pbrac{r,\\theta,\\phi}$ are defined by\n\\begin{equation}\n  \\begin{aligned}\n    x = r\\cos\\theta\\sin\\phi & \\qquad r \\ge 0 \\\\\n    y = r\\sin\\theta\\sin\\phi & \\qquad 0 \\le \\theta \\le 2\\pi \\\\\n    z = r\\cos\\phi & \\qquad 0 \\le \\phi \\le \\pi\n  \\end{aligned}\n\\end{equation}\n\nThe base vectors with respect to the spherical polar coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    \\cos\\theta\\sin\\phi\\vect{i}_{1}+\\sin\\theta\\sin\\phi\\vect{i}_{2}+\\cos\\phi\\vect{i}_{3} \\\\ \n    -r\\sin\\theta\\sin\\phi\\vect{i}_{1}+r\\cos\\theta\\sin\\phi\\vect{i}_{2} \\\\\n    r\\cos\\theta\\cos\\phi\\vect{i}_{1}+r\\sin\\theta\\cos\\phi\\vect{i}_{2}-r\\sin\\phi\\vect{i}_{3}\n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & r^{2}\\sin^{2}\\phi & 0 \\\\\n    0 & 0 & r^{2} \n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 &  \\frac{1}{r^{2}\\sin^{2}\\phi} & 0 \\\\\n    0 & 0 & \\frac{1}{r^{2}} \n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffell symbols of the second kind are\n\\begin{align}\n  \\christoffelsecond{r}{\\theta}{\\theta}&=-r\\sin^{2}\\phi \\\\\n  \\christoffelsecond{r}{\\phi}{\\phi}&=-r \\\\\n  \\christoffelsecond{\\phi}{\\theta}{\\theta}&=-\\sin\\phi\\cos\\phi \\\\\n  \\christoffelsecond{\\theta}{r}{\\theta}=\\christoffelsecond{\\theta}{\\theta}{r}&=\\frac{1}{r} \\\\\n  \\christoffelsecond{\\phi}{r}{\\phi}=\\christoffelsecond{\\phi}{\\phi}{r}&=\\frac{1}{r} \\\\\n  \\christoffelsecond{\\theta}{\\theta}{\\phi}=\\christoffelsecond{\\theta}{\\phi}{\\theta}&=\\cot\\phi\n\\end{align}\nwith all other Christofell symbols zero.\n\n\\subsubsection{Prolate Spheroidal}\n\nThe global coordinates $\\pbrac{x,y,z}$ with respect to the prolate spheroidal\ncoordinates $\\pbrac{\\lambda,\\mu,\\theta}$ are defined by\n\\begin{equation}\n  \\begin{aligned}\n    x = a\\sinh\\lambda\\sin\\mu\\cos\\theta & \\qquad \\lambda \\ge 0 \\\\\n    y = a\\sinh\\lambda\\sin\\mu\\sin\\theta & \\qquad 0 \\le \\mu \\le \\pi \\\\\n    z = a\\cosh\\lambda\\cos\\mu & \\qquad 0 \\le \\theta \\le 2\\pi \n  \\end{aligned}\n\\end{equation}\nwhere $a\\ge0$ is the focus.\n\nThe base vectors with respect to the global coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    a\\cosh\\lambda\\sin\\mu\\cos\\theta\\vect{i}_{1}+a\\cosh\\lambda\\sin\\mu\\sin\\theta\\vect{i}_{2}+a\\sinh\\lambda\\cos\\mu\\vect{i}_{3}\\\\ \n    a\\sinh\\lambda\\cos\\mu\\cos\\theta\\vect{i}_{1}+a\\sinh\\lambda\\cos\\mu\\sin\\theta\\vect{i}_{2}-a\\cosh\\lambda\\sin\\mu\\vect{i}_{3}\\\\\n    -a\\sinh\\lambda\\sin\\mu\\sin\\theta\\vect{i}_{1}+a\\sinh\\lambda\\sin\\mu\\cos\\theta\\vect{i}_{2}\n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu} & 0 & 0 \\\\\n    0 & a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu} & 0 \\\\\n    0 & 0 & a^{2}\\sinh^{2}\\lambda\\sin^{2}\\mu \n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    \\frac{1}{a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu}}& 0 & 0 \\\\\n    0 & \\frac{1}{a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu}} & 0 \\\\\n    0 & 0 & \\frac{1}{a^{2}\\sinh^{2}\\lambda\\sin^{2}\\mu} \n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffell symbols of the second kind are\n\\begin{align}\n  \\christoffelsecond{\\lambda}{\\lambda}{\\lambda}&=\\frac{\\sinh\\lambda\\cosh\\lambda}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\lambda}{\\mu}{\\mu}&=\\frac{-\\sinh\\lambda\\cosh\\lambda}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\lambda}{\\theta}{\\theta}&=\\frac{-\\sinh\\lambda\\cosh\\lambda\\sin^{2}\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\lambda}{\\lambda}{\\mu}&=\\frac{\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\mu}{\\mu}&=\\frac{\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\lambda}{\\lambda}&=\\frac{-\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\theta}{\\theta}&=\\frac{-\\sinh^{2}\\lambda\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\mu}{\\lambda}&=\\frac{\\sinh\\lambda\\cosh\\lambda}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\theta}{\\theta}{\\lambda}&=\\frac{\\cosh\\lambda}{\\sinh\\lambda} \\\\\n  \\christoffelsecond{\\theta}{\\theta}{\\mu}&=\\frac{\\cos\\mu}{\\sin\\mu} \\\\\n \\end{align}\nwith all other Christofell symbols zero.\n\n\\subsubsection{Oblate Spheroidal}\n\nThe global coordinates $\\pbrac{x,y,z}$ with respect to the oblate spheroidal\ncoordinates $\\pbrac{\\lambda,\\mu,\\theta}$  are defined by\n\\begin{equation}\n  \\begin{aligned}\n    x = a\\cosh\\lambda\\cos\\mu\\cos\\theta & \\qquad \\lambda \\ge 0 \\\\\n    y = a\\cosh\\lambda\\cos\\mu\\sin\\theta & \\qquad \\frac{-\\pi}{2} \\le \\mu \\le \\frac{\\pi}{2} \\\\\n    z = a\\sinh\\lambda\\sin\\mu & \\qquad 0 \\le \\theta \\le 2\\pi \n  \\end{aligned}\n\\end{equation}\nwhere $a\\ge0$ is the focus.\n\nThe base vectors with respect to the global coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    a\\sinh\\lambda\\cos\\mu\\cos\\theta\\vect{i}_{1}+a\\sinh\\lambda\\cos\\mu\\sin\\theta\\vect{i}_{2}+a\\cosh\\lambda\\sin\\mu\\vect{i}_{3}\\\\\n    -a\\cosh\\lambda\\sin\\mu\\cos\\theta\\vect{i}_{1}-a\\cosh\\lambda\\sin\\mu\\sin\\theta\\vect{i}_{2}+a\\sinh\\lambda\\cos\\mu\\vect{i}_{3}\\\\    \n    -a\\cosh\\lambda\\cos\\mu\\sin\\theta\\vect{i}_{1}+a\\cosh\\lambda\\cos\\mu\\cos\\theta\\vect{i}_{2}\n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu} & 0 & 0 \\\\\n    0 & a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu} & 0 \\\\\n    0 & 0 & a^{2}\\cosh^{2}\\lambda\\cos^{2}\\mu \n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    \\frac{1}{a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu}}& 0 & 0 \\\\\n    0 & \\frac{1}{a^{2}\\pbrac{\\sinh^{2}\\lambda+\\sin^{2}\\mu}} & 0 \\\\\n    0 & 0 & \\frac{1}{a^{2}\\cosh^{2}\\lambda\\cos^{2}\\mu}\n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffell symbols of the second kind are\n\\begin{align}\n  \\christoffelsecond{\\lambda}{\\lambda}{\\lambda}&=\\frac{\\sinh\\lambda\\cosh\\lambda}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\lambda}{\\mu}{\\mu}&=\\frac{-\\sinh\\lambda\\cosh\\lambda}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\lambda}{\\theta}{\\theta}&=\\frac{-\\sinh\\lambda\\cosh\\lambda\\cos^{2}\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\lambda}{\\lambda}{\\mu}&=\\frac{\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\mu}{\\mu}&=\\frac{\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\lambda}{\\lambda}&=\\frac{-\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\theta}{\\theta}&=\\frac{\\cosh^{2}\\lambda\\sin\\mu\\cos\\mu}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\mu}{\\mu}{\\lambda}&=\\frac{\\sinh\\lambda\\cosh\\lambda}{\\sinh^{2}\\lambda+\\sin^{2}\\mu} \\\\\n  \\christoffelsecond{\\theta}{\\theta}{\\lambda}&=\\frac{\\sinh\\lambda}{\\cosh\\lambda} \\\\\n  \\christoffelsecond{\\theta}{\\theta}{\\mu}&=\\frac{-\\sin\\mu}{\\cos\\mu} \\\\\n\\end{align}\nwith all other Christofell symbols zero.\n\n\\subsubsection{Cylindrical parabolic}\n\nThe global coordinates $\\pbrac{x,y,z}$ with respect to the cylindrical parabolic\ncoordinates $\\pbrac{\\xi,\\eta,z}$  are defined by\n\\begin{equation}\n  \\begin{aligned}\n    x = \\xi\\eta & \\qquad -\\infty < \\xi < \\infty \\\\\n    y = \\frac{1}{2}\\pbrac{\\xi^{2}-\\eta^{2}} & \\qquad \\eta \\ge 0 \\\\\n    z =  z & \\qquad -\\infty < z < \\infty\n  \\end{aligned}\n\\end{equation}\n\nThe base vectors with respect to the global coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    \\eta\\vect{i}_{1}+\\xi\\vect{i}_{2}\\\\\n    \\xi\\vect{i}_{1}-\\eta\\vect{i}_{2}\\\\    \n    \\vect{i}_{3}\n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    \\xi^{2}+\\eta^{2} & 0 & 0 \\\\\n    0 & \\xi^{2}+\\eta^{2} & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    \\frac{1}{\\xi^{2}+\\eta^{2}}& 0 & 0 \\\\\n    0 & \\frac{1}{\\xi^{2}+\\eta^{2}} & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffell symbols of the second kind are\n\\begin{align}\n  \\christoffelsecond{\\xi}{\\xi}{\\xi}&=\\frac{\\xi}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\eta}{\\eta}&=\\frac{\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\xi}{\\xi}&=\\frac{-\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\xi}{\\eta}{\\eta}&=\\frac{-\\xi}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\xi}{\\xi}{\\eta}=\\christoffelsecond{\\xi}{\\eta}{\\xi}&=\\frac{\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\xi}{\\eta}=\\christoffelsecond{\\eta}{\\eta}{\\xi}&=\\frac{\\xi}{\\xi^{2}+\\eta^{2}} \\\\\n\\end{align}\nwith all other Christofell symbols zero.\n\n\\subsubsection{Parabolic polar}\n\nThe global coordinates $\\pbrac{x,y,z}$ with respect to the cylindrical parabolic\ncoordinates $\\pbrac{\\xi,\\eta,\\theta}$  are defined by\n\\begin{equation}\n  \\begin{aligned}\n    x = \\xi\\eta\\cos\\theta & \\qquad \\xi \\ge 0 \\\\\n    y = \\xi\\eta\\sin\\theta & \\qquad \\eta \\ge 0 \\\\\n    z = \\frac{1}{2}\\pbrac{\\xi^{2}-\\eta^{2}} & \\qquad 0 \\le \\theta < 2\\pi\n  \\end{aligned}\n\\end{equation}\n\nThe base vectors with respect to the global coordinate system are\n\\begin{equation}\n  \\vect{g}_{i}=\\begin{bmatrix} \n    \\eta\\cos\\theta\\vect{i}_{1}+\\eta\\sin\\theta\\vect{i}_{3}+\\xi\\vect{i}_{3}\\\\\n    \\xi\\cos\\theta\\vect{i}_{1}+\\xi\\sin\\theta\\vect{i}_{3}-\\eta\\vect{i}_{3}\\\\ \n    -\\xi\\eta\\sin\\theta\\vect{i}_{1}+\\xi\\eta\\cos\\theta\\vect{i}_{2}\n  \\end{bmatrix}\n\\end{equation}\n\nThe covariant metric tensor is\n\\begin{equation}\n  g_{ij}=\\begin{bmatrix}\n    \\xi^{2}+\\eta^{2} & 0 & 0 \\\\\n    0 & \\xi^{2}+\\eta^{2} & 0 \\\\\n    0 & 0 & \\xi\\eta\n  \\end{bmatrix}\n\\end{equation}\nand the contravariant metric tensor is\n\\begin{equation}\n  g^{ij}=\\begin{bmatrix}\n    \\frac{1}{\\xi^{2}+\\eta^{2}}& 0 & 0 \\\\\n    0 & \\frac{1}{\\xi^{2}+\\eta^{2}} & 0 \\\\\n    0 & 0 & \\frac{1}{\\xi\\eta}\n  \\end{bmatrix}\n\\end{equation}\n\nThe Christoffell symbols of the second kind are\n\\begin{align}\n  \\christoffelsecond{\\xi}{\\xi}{\\xi}&=\\frac{\\xi}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\eta}{\\eta}&=\\frac{\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\xi}{\\eta}{\\eta}&=\\frac{-\\xi}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\xi}{\\xi}&=\\frac{-\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\theta}{\\theta}&=\\frac{-\\xi^{2}\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\xi}{\\theta}{\\theta}&=\\frac{-\\xi\\eta^{2}}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\xi}{\\xi}{\\eta}=\\christoffelsecond{\\xi}{\\eta}{\\xi}&=\\frac{\\eta}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\eta}{\\xi}{\\eta}=\\christoffelsecond{\\eta}{\\eta}{\\xi}&=\\frac{\\xi}{\\xi^{2}+\\eta^{2}} \\\\\n  \\christoffelsecond{\\theta}{\\xi}{\\theta}=\\christoffelsecond{\\theta}{\\theta}{\\xi}&=\\frac{1}{\\xi} \\\\\n  \\christoffelsecond{\\theta}{\\eta}{\\theta}=\\christoffelsecond{\\theta}{\\theta}{\\eta}&=\\frac{1}{\\eta} \\\\\n\\end{align}\nwith all other Christofell symbols zero.\n\n\\section{Equation set types}\n\n\\subsection{Static Equations}\n\nThe general form for static equations is\n\n\\subsection{Dynamic Equations}\n\nThe general form for dynamic equations is\n\\begin{equation}\n  \\matr{M}\\fnof{\\ddot{\\vect{u}}}{t}+\\matr{C}\\fnof{\\dot{\\vect{u}}}{t}+\\matr{K}\\fnof{\\vect{u}}{t}+\n  \\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t}}+\\fnof{\\vect{f}}{t}=\\vect{0}\n  \\label{eqn:generaldynamicnonlinear}\n\\end{equation}\nwhere $\\fnof{\\vect{u}}{t}$ is the unknown ``displacement vector'', $\\matr{M}$\nis the mass matrix, $\\matr{C}$ is the damping matrix, $\\matr{K}$ is the\nstiffness matrix, $\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t}}$ a non-linear vector\nfunction and $\\fnof{\\vect{f}}{t}$ the forcing vector.\n\nFrom \\cite{zienkiewicz:2006_1} we now expand the unknown vector $\\fnof{\\vect{u}}{t}$ in terms of a polynomial of degree\n$p$. With the known values of $\\vect{u}_{n}$, $\\dot{\\vect{u}}_{n}$,\n$\\ddot{\\vect{u}}_{n}$ up to $\\symover{p-1}{\\vect{u}}_{n}$ at the beginning of\nthe time step $\\Delta t$ we can write the polynomial expansion as\n\\begin{equation}\n  \\fnof{\\vect{u}}{t_{n}+\\tau}\\approx\\fnof{\\tilde{\\vect{u}}}{t_{n}+\\tau}=\\vect{u}_{n}+\\tau\\dot{\\vect{u}}_{n}+\n  \\frac{1}{2!}\\tau^{2}\\ddot{\\vect{u}}_{n}+\\cdots+\\dfrac{1}{\\factorial{p-1}}\\tau^{p-1}\\symover{p-1}{\\vect{u}}_{n}+\n  \\dfrac{1}{p!}\\tau^{p}\\vect{\\alpha}^{p}_{n}\n  \\label{eqn:timepolyexpansion}\n\\end{equation}\nwhere the only unknown is the the vector $\\vect{\\alpha}^{p}_{n}$,\n\\begin{equation}\n  \\vect{\\alpha}^{p}_{n}\\approx\\symover{p}{\\vect{u}}\\equiv\\dnby{p}{\\vect{u}}{t}\n\\end{equation}\n\nA recurrance relationship can be established by substituting\n\\eqnref{eqn:timepolyexpansion} into \\eqnref{eqn:generaldynamicnonlinear} and\ntaking a weighted residual approach \\ie\n\\begin{multline}\n  \\dintl{0}{\\Delta\n    t}\\fnof{W}{\\tau}\\left[\\matr{M}\\pbrac{\\ddot{\\vect{u}}_{n}+\\tau\\dddot{\\vect{u}}_{n}+\\cdots+\n    \\dfrac{1}{\\factorial{p-2}}\\tau^{p-2}\\vect{\\alpha}^{p}_{n}} \\right.\\\\\n  +\\matr{C}\\pbrac{\\dot{\\vect{u}}_{n}+\\tau\\ddot{\\vect{u}}_{n}+\\cdots+\n    \\dfrac{1}{\\factorial{p-1}}\\tau^{p-1}\\vect{\\alpha}^{p}_{n}} \\\\\n  +\\matr{K}\\pbrac{\\vect{u}_{n}+\\tau\\dot{\\vect{u}}_{n}+\\cdots+\n    \\dfrac{1}{p!}\\tau^{p}\\vect{\\alpha}^{p}_{n}} \\\\\n  +\\left.\\fnof{\\vect{g}}{\\vect{u}_{n}+\\tau\\dot{\\vect{u}}_{n}+\\cdots+\n    \\dfrac{1}{p!}\\tau^{p}\\vect{\\alpha}^{p}_{n}}+\\fnof{\\vect{f}}{t_{n}+\\tau}\\right] d\\tau = \\vect{0}\n\\end{multline}\nwhere $\\fnof{W}{\\tau}$ is some weight function, $\\tau=t-t_{n}$ and $\\Delta\nt=t_{n+1}-t_{n}$. Dividing by $\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}$ we obtain\n\\begin{multline}\n  \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\matr{M}\\pbrac{\\ddot{\\vect{u}}_{n}+\\tau\\dddot{\\vect{u}}_{n}+\\cdots+\n        \\dfrac{1}{\\factorial{p-2}}\\tau^{p-2}\\vect{\\alpha}^{p}_{n}}}{\\tau}}{\\gint{0}{\\Delta\n      t}{\\fnof{W}{\\tau}}{\\tau}} \\\\\n  + \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\matr{C}\\pbrac{\\dot{\\vect{u}}_{n}+\\tau\\ddot{\\vect{u}}_{n}+\\cdots+\n        \\dfrac{1}{\\factorial{p-1}}\\tau^{p-1}\\vect{\\alpha}^{p}_{n}}}{\\tau}}{\\gint{0}{\\Delta\n      t}{\\fnof{W}{\\tau}}{\\tau}} \\\\\n  + \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\matr{K}\\pbrac{\\vect{u}_{n}+\\tau\\dot{\\vect{u}}_{n}+\\cdots+\n        \\dfrac{1}{p!}\\tau^{p}\\vect{\\alpha}^{p}_{n}}}{\\tau}}{\\gint{0}{\\Delta\n      t}{\\fnof{W}{\\tau}}{\\tau}} \\\\\n  + \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\fnof{\\vect{g}}{\\vect{u}_{n}+\\tau\\dot{\\vect{u}}_{n}+\\cdots+\n        \\dfrac{1}{p!}\\tau^{p}\\vect{\\alpha}^{p}_{n}}}{\\tau}}{\\gint{0}{\\Delta\n      t}{\\fnof{W}{\\tau}}{\\tau}}  \n  + \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\fnof{\\vect{f}}{t_{n}+\n        \\tau}}{\\tau}}{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}=\\vect{0}\n\\end{multline}\n\nNow if \n\\begin{equation}\n  \\theta_{k}=\\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\tau^{k}}{\\tau}}{{\\Delta\n      t}^{k}\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}} \\text{  for  } k=0,1,\\ldots,p\n\\end{equation}\nand\n\\begin{equation}\n  \\bar{\\vect{f}}=\\dfrac{\\gint{0}{\\Delta\n      t}{\\fnof{W}{\\tau}\\fnof{\\vect{f}}{t_{n}+\\tau}}{\\tau}}{\n    \\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}\n  \\label{eqn:meanweightedloadvector}\n\\end{equation}\nwe can write\n\\begin{multline}\n  \\matr{M}\\pbrac{\\ddot{\\bar{\\vect{u}}}_{n+1}+\\dfrac{\\theta_{p-2}{\\Delta\n        t}^{p-2}}{\\factorial{p-2}}\\vect{\\alpha}^{p}_{n}}+\n  \\matr{C}\\pbrac{\\dot{\\bar{\\vect{u}}}_{n+1}+\\dfrac{\\theta_{p-1}{\\Delta\n        t}^{p-1}}{\\factorial{p-1}}\\vect{\\alpha}^{p}_{n}}+\n  \\matr{K}\\pbrac{\\bar{\\vect{u}}_{n+1}+\\dfrac{\\theta_{p}{\\Delta\n        t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}}+ \\\\\n  + \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\fnof{\\vect{g}}{\\vect{u}_{n}+\\tau\\dot{\\vect{u}}_{n}+\\cdots+\n        \\dfrac{1}{p!}\\tau^{p}\\vect{\\alpha}^{p}_{n}}}{\\tau}}{\\gint{0}{\\Delta\n      t}{\\fnof{W}{\\tau}}{\\tau}}+\\bar{\\vect{f}}=\\vect{0}\n  \\label{eqn:dynamic1}\n\\end{multline}\nwhere\n\\begin{equation}\n  \\begin{split}\n    \\bar{\\vect{u}}_{n+1} &= \\gsum{q=0}{p-1}{\\dfrac{\\theta_{q}{\\Delta\n            t}^{q}}{q!}\\symover{q}{\\vect{u}}_{n}} \\\\\n    \\dot{\\bar{\\vect{u}}}_{n+1} &= \\gsum{q=1}{p-1}{\\dfrac{\\theta_{q-1}{\\Delta\n            t}^{q-1}}{\\factorial{q-1}}\\symover{q}{\\vect{u}}_{n}} \\\\\n    \\ddot{\\bar{\\vect{u}}}_{n+1} &= \\gsum{q=2}{p-1}{\\dfrac{\\theta_{q-2}{\\Delta\n            t}^{q-2}}{\\factorial{q-2}}\\symover{q}{\\vect{u}}_{n}} \n  \\end{split}\n\\end{equation}\n\nWe note that as $\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t}}$ is nonlinear we need to\nevaluate an integral of the form\n\\begin{equation}\n  \\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}+\\tau}}}{\\tau}\n\\end{equation}\n\nTo do this we form Taylor's series expansions for\n$\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t}}$ about the point $\\fnof{\\vect{u}}{t_{n}+\\tau}$ \\ie\n\\begin{equation}\n  \\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}}}=\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}+\\tau}}-\n  \\tau\\delby{\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t}}}{\\vect{u}}\\evalat{\\delby{\\fnof{\\vect{u}}{t}}{t}}{t_{n}+\\tau}\n  + \\orderof{\\tau^{2}}\n  \\label{eqn:firstTaylorexpansion}\n\\end{equation}\nand\n\\begin{equation}\n  \\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n+1}}}=\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}+\\tau}}+\n  \\pbrac{t_{n+1}-t_{n}-\\tau}\\delby{\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t}}}{\\vect{u}}\n  \\evalat{\\delby{\\fnof{\\vect{u}}{t}}{t}}{t_{n}+\\tau}+ \\orderof{\\tau^{2}}\n  \\label{eqn:secondTaylorexpansion}\n\\end{equation}\n\nNow if we add $\\dfrac{1}{\\tau}$ times \\eqnref{eqn:firstTaylorexpansion} and\n$\\dfrac{1}{t_{n+1}-t_{n}-\\tau}=\\dfrac{1}{\\Delta t-\\tau}$ times\n\\eqnref{eqn:secondTaylorexpansion} we obtain\n\\begin{equation}\n  \\dfrac{\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}}}}{\\tau}+\\dfrac{\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n+1}}}}{\\Delta\n    t-\\tau}=\\pbrac{\\dfrac{\\Delta t}{\\tau\\pbrac{\\Delta t-\\tau}}}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}+\\tau}}+\n  \\pbrac{\\dfrac{\\Delta t}{\\tau\\pbrac{\\Delta t-\\tau}}}\\orderof{\\tau^{2}}\n\\end{equation}\n\nMultiplying through by $\\dfrac{\\tau\\pbrac{\\Delta t-\\tau}}{\\Delta t}$ gives\n\\begin{equation}\n  \\dfrac{\\Delta t-\\tau}{\\Delta t}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}}}+\n  \\dfrac{\\tau}{\\Delta t}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n+1}}}=\n  \\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}+\\tau}}+\\orderof{\\tau^{2}}\n\\end{equation}\n\nTherefore\n\\begin{equation}\n  \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}+\\tau}}}{\\tau}}\n  {\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}=\\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\n      \\pbrac{\\dfrac{\\Delta t-\\tau}{\\Delta t}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}}}+\n        \\dfrac{\\tau}{\\Delta t}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n+1}}}+\\orderof{\\tau^{2}}}}{\\tau}}\n  {\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}\n\\end{equation}\n\nNow if we recall that\n\\begin{equation}\n\\theta_{1}=\\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\tau}{\\tau}}{\\Delta t\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}\n\\end{equation}\nwe can write\n\\begin{equation}\n  \\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n+1}}}}{\\tau}}\n  {\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}=\\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n}}}+\n  \\theta_{1}\\fnof{\\vect{g}}{\\fnof{\\vect{u}}{t_{n+1}}}+\\text{Error}\n\\end{equation}\nwhere\n\\begin{equation}\n  \\text{Error}=\\dfrac{\\gint{0}{\\Delta t}{\\fnof{W}{\\tau}\\orderof{\\tau^{2}}}{\\tau}}{\n    \\gint{0}{\\Delta t}{\\fnof{W}{\\tau}}{\\tau}}\n\\end{equation}\n\n\\Eqnref{eqn:dynamic1} now becomes\n\\begin{multline}\n  \\matr{M}\\pbrac{\\ddot{\\bar{\\vect{u}}}_{n+1}+\\dfrac{\\theta_{p-2}{\\Delta\n        t}^{p-2}}{\\factorial{p-2}}\\vect{\\alpha}^{p}_{n}}+\n  \\matr{C}\\pbrac{\\dot{\\bar{\\vect{u}}}_{n+1}+\\dfrac{\\theta_{p-1}{\\Delta\n        t}^{p-1}}{\\factorial{p-1}}\\vect{\\alpha}^{p}_{n}}\\\\\n  +\\matr{K}\\pbrac{\\bar{\\vect{u}}_{n+1}+\\dfrac{\\theta_{p}{\\Delta\n        t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}}+ \n  \\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\vect{u}_{n}}+\\theta_{1}\\fnof{\\vect{g}}{\\vect{u}_{n+1}}+\\bar{\\vect{f}}+\n  \\text{Error}=\\vect{0}\n  \\label{eqn:dynamic2}\n\\end{multline}\nas $\\fnof{\\vect{u}}{t_{n}}=\\vect{u}_{n}$ and\n$\\fnof{\\vect{u}}{t_{n+1}}=\\vect{u}_{n+1}=\\hat{\\vect{u}}_{n+1}+\n\\dfrac{{\\Delta t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}$ where $\\hat{\\vect{u}}_{n+1}$\nis the \\emph{predicted displacement} at the new time step and is given by\n\\begin{equation}\n  \\hat{\\vect{u}}_{n+1}=\\gsum{q=0}{p-1}{\\dfrac{{\\Delta\n        t}^{q}}{q!}\\symover{q}{\\vect{u}}_{n}}\n\\end{equation}\n\nRearranging gives\n\\begin{multline}\n  \\fnof{\\vect{\\psi}}{\\vect{\\alpha}^{p}_{n}}=\\pbrac{\\dfrac{\\theta_{p-2}{\\Delta\n        t}^{p-2}}{\\factorial{p-2}}\\matr{M}+\\dfrac{\\theta_{p-1}{\\Delta\n        t}^{p-1}}{\\factorial{p-1}}\\matr{C}+\\dfrac{\\theta_{p}{\\Delta\n        t}^{p}}{p!}\\matr{K}}\\vect{\\alpha}^{p}_{n}+\\theta_{1}\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+ \n    \\dfrac{{\\Delta t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}} \\\\\n  +\\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\vect{u}_{n}}+\n  \\pbrac{\\matr{M}\\ddot{\\bar{\\vect{u}}}_{n+1}+\\matr{C}\\dot{\\bar{\\vect{u}}}_{n+1}+\\matr{K}\\bar{\\vect{u}}_{n+1}+\n    \\bar{\\vect{f}}}= \\vect{0}\n  \\label{eqn:dynamic}\n\\end{multline}\nor \n\\begin{equation}\n\\fnof{\\vect{\\psi}}{\\vect{\\alpha}^{p}_{n}}=\\matr{A}\\vect{\\alpha}^{p}_{n}+\n\\theta_{1}\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+ \\dfrac{{\\Delta\n      t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}}+\\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\vect{u}_{n}}+\\vect{b}= \\vect{0}\n\\end{equation}\nwhere $\\matr{A}$ is the \\emph{Amplification matrix} given by\n\\begin{equation}\n  \\matr{A}=\\dfrac{\\theta_{p-2}{\\Delta t}^{p-2}}{\\factorial{p-2}}\\matr{M}+\n  \\dfrac{\\theta_{p-1}{\\Delta t}^{p-1}}{\\factorial{p-1}}\\matr{C}+\n  \\dfrac{\\theta_{p}{\\Delta t}^{p}}{p!}\\matr{K}\n\\end{equation}\nand $\\vect{b}$ is the right hand side vector given by\n\\begin{equation}\n  \\vect{b}=\\matr{M}\\ddot{\\bar{\\vect{u}}}_{n+1}+\\matr{C}\\dot{\\bar{\\vect{u}}}_{n+1}+\n  \\matr{K}\\bar{\\vect{u}}_{n+1}+\\bar{\\vect{f}}\n\\end{equation}\n\nIf $\\fnof{\\vect{g}}{\\vect{u}}\\equiv\\vect{0}$ then \\eqnref{eqn:dynamic} is linear in\n$\\vect{\\alpha}^{p}_{n}$ and $\\vect{\\alpha}^{p}_{n}$ can be found by solving\nthe linear equation\n\\begin{equation}\n  \\vect{\\alpha}^{p}_{n} =-\\inverse{\\pbrac{\\dfrac{\\theta_{p-2}{\\Delta t}^{p-2}}{\\factorial{p-2}}\\matr{M}+\n      \\dfrac{\\theta_{p-1}{\\Delta t}^{p-1}}{\\factorial{p-1}}\\matr{C}+\n      \\dfrac{\\theta_{p}{\\Delta\n          t}^{p}}{p!}\\matr{K}}}\\pbrac{\\matr{M}\\ddot{\\bar{\\vect{u}}}_{n+1}+\n    \\matr{C}\\dot{\\bar{\\vect{u}}}_{n+1}+\\matr{K}\\bar{\\vect{u}}_{n+1}+\\bar{\\vect{f}}}\n\\end{equation}\nor \n\\begin{equation}\n  \\vect{\\alpha}^{p}_{n} =-\\inverse{\\matr{A}}\\vect{b}\n\\end{equation}\n\nIf $\\fnof{\\vect{g}}{\\vect{u}}$ is not $\\equiv\\vect{0}$ then\n\\eqnref{eqn:dynamic} is nonlinear in $\\vect{\\alpha}^{p}_{n}$. To solve this\nequation we use Newton's method \\ie\n\\begin{equation}\n  \\begin{split}\n    \\text{1.  } & \\fnof{\\matr{J}}{\\vect{\\alpha}^{p}_{n(i)}}.\\delta\n    \\vect{\\alpha}^{p}_{n(i)} = \n    -\\fnof{\\vect{\\psi}}{\\vect{\\alpha}^{p}_{n(i)}} \\\\\n    \\text{2.  } & \\vect{\\alpha}^{p}_{n(i+1)}=\\vect{\\alpha}^{p}_{n(i)}+\\delta\n    \\vect{\\alpha}^{p}_{n(i)}\n  \\end{split}\n\\end{equation}\nwhere $\\fnof{\\matr{J}}{\\vect{\\alpha}^{p}_{n}}$ is the Jacobian and is given by\n\\begin{equation}\n  \\fnof{\\matr{J}}{\\vect{\\alpha}^{p}_{n}}=\\dfrac{\\theta_{p-2}{\\Delta t}^{p-2}}{\\factorial{p-2}}\\matr{M}+\n  \\dfrac{\\theta_{p-1}{\\Delta\n      t}^{p-1}}{\\factorial{p-1}}\\matr{C}+\\dfrac{\\theta_{p}{\\Delta t}^{p}}{p!}\\matr{K}+\n  \\dfrac{\\theta_{1}{\\Delta t}^{p}}{p!}\n  \\delby{\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+\\dfrac{{\\Delta\n          t}^{p}}{p!}\n      \\vect{\\alpha}^{p}_{n}}}{\\vect{\\alpha}^{p}_{n}}\n\\end{equation}\nor\n\\begin{equation}\n  \\fnof{\\matr{J}}{\\vect{\\alpha}^{p}_{n}}=\\matr{A}+\\dfrac{\\theta_{1}{\\Delta\n      t}^{p}}{p!}\n  \\delby{\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+\\dfrac{{\\Delta t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}}}{\\vect{\\alpha}^{p}_{n}}\n\\end{equation}\n\nOnce $\\vect{\\alpha}^{p}_{n}$ has been obtained the values at the next time step can be obtained from\n\\begin{equation}\n  \\begin{split}\n    \\vect{u}_{n+1} &= \\vect{u}_{n}+\\Delta t\n    \\dot{\\vect{u}}_{n}+\\cdots+\\dfrac{{\\Delta\n        t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}=\\hat{\\vect{u}}_{n+1}+\n    \\dfrac{{\\Delta t}^{p}}{p!}\\vect{\\alpha}^{p}_{n}\\\\\n    \\dot{\\vect{u}}_{n+1} &= \\dot{\\vect{u}}_{n}+\\Delta t\n    \\ddot{\\vect{u}}_{n}+\\cdots+\\dfrac{{\\Delta\n        t}^{p-1}}{\\factorial{p-1}}\\vect{\\alpha}^{p}_{n}=\\dot{\\hat{\\vect{u}}}_{n+1}+\\dfrac{{\\Delta\n        t}^{p-1}}{\\factorial{p-1}}\\vect{\\alpha}^{p}_{n} \\\\\n    &\\vdots \\\\\n    \\symover{p-1}{\\vect{u}}_{n+1} &= \\symover{p-1}{\\vect{u}}_{n}+\\Delta t\\vect{\\alpha}^{p}_{n}\n  \\end{split}\n\\end{equation}\n\nFor algorithms in which the degree of the polynomial, $p$, is higher than the\norder we require the algorithm to be initialised so that the initial velocity\nor acceleration can be computed. The initial velocity or acceleration values\ncan be obtained by substituting the initial displacement or initial\ndisplacement and velocity values into \\eqnref{eqn:generaldynamicnonlinear},\nrearranging and solving. For example consider an the case of a second degree\npolynomial and a first order system. Substituing the initial displacement\n$\\vect{u}_{0}$ into \\eqnref{eqn:generaldynamicnonlinear} gives\n\\begin{equation}\n  \\matr{C}\\dot{\\vect{u}}_{0}+\\matr{K}\\vect{u}_{0}+\\fnof{\\vect{g}}{\\vect{u}_{0}}+\\bar{\\vect{f}}_{0}=\\vect{0}\n\\end{equation}\nand therefore an approximation to the initial velocity can be found from\n\\begin{equation}\n  \\dot{\\vect{u}}_{0}=-\\inverse{\\matr{C}}\\pbrac{\\matr{K}\\vect{u}_{0}+\\fnof{\\vect{g}}{\\vect{u}_{0}}+\\bar{\\vect{f}}_{0}}\n\\end{equation}\n\nSimilarily for a third degree polynomial and a second order system the initial\nacceleration can be found from\n\\begin{equation}\n  \\ddot{\\vect{u}}_{0}=-\\inverse{\\matr{M}}\\pbrac{\\matr{C}\\dot{\\vect{u}}_{0}+\\matr{K}\\vect{u}_{0}+\n    \\fnof{\\vect{g}}{\\vect{u}_{0}}+\\bar{\\vect{f}}_{0}}\n\\end{equation}\n\nTo evaluate the mean weighted load vector, $\\bar{\\vect{f}}$, we need to\nevaluate the integral in \\eqnref{eqn:meanweightedloadvector}. In some cases,\nhowever, we can make the assumption that the load vector varies linearly\nduring the time step. In these cases the mean weighted load vector can be\ncomputed from\n\\begin{equation}\n  \\bar{\\vect{f}}=\\theta_{1}\\vect{f}_{n+1}+\\pbrac{1-\\theta_{1}}\\vect{f}_{n}\n\\end{equation}\n\n\\subsubsection{Special SN11 case, p=1}\n\nFor this special case, the mean predicited values are given by\n\\begin{equation}\n   \\bar{\\vect{u}}_{n+1} = \\vect{u}_{n}\n\\end{equation}\n\nThe predicted displacement values are given by\n\\begin{equation}\n   \\hat{\\vect{u}}_{n+1} = \\vect{u}_{n}\n\\end{equation}\n\nThe amplification matrix is given by\n\\begin{equation}\n  \\matr{A}=\\matr{C}+\\theta_{1}\\Delta t \\matr{K}\n\\end{equation}\n\nThe right hand side vector is given by\n\\begin{equation}\n  \\vect{b}=\\matr{K}\\bar{\\vect{u}}_{n+1}+\\bar{\\vect{f}}\n\\end{equation}\n\nThe nonlinear function is given by\n\\begin{equation}\n  \\fnof{\\vect{\\psi}}{\\vect{\\alpha}^{1}_{n}}=\\matr{A}\\vect{\\alpha}^{1}_{n}+\\theta_{1}\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+ \n    \\Delta t\\vect{\\alpha}^{1}_{n}}+\\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\vect{u}_{n}}+\\vect{b}=\\vect{0}\n\\end{equation}\n\nThe Jacobian matrix is given by\n\\begin{equation}\n  \\fnof{\\matr{J}}{\\vect{\\alpha}^{1}_{n}}=\\matr{A}+\\theta_{1}\\Delta t\n  \\delby{\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+\\Delta t\\vect{\\alpha}^{1}_{n}}}{\\vect{\\alpha}^{1}_{n}}\n\\end{equation}\n\nAnd the time step update is given by\n\\begin{equation}\n    \\vect{u}_{n+1} = \\vect{u}_{n}+\\Delta t\\vect{\\alpha}^{1}_{n}\n\\end{equation}\n\n\\subsubsection{Special SN21 case, p=2}\n\nFor this special case, the mean predicited values are given by\n\\begin{equation}\n  \\begin{split}\n    \\bar{\\vect{u}}_{n+1} &= \\vect{u}_{n}+\\theta_{1}\\Delta t\\dot{\\vect{u}}_{n}\\\\\n    \\dot{\\bar{\\vect{u}}}_{n+1} &= \\dot{\\vect{u}}_{n}\n  \\end{split}\n\\end{equation}\nwhere\n\\begin{equation}\n  \\dot{\\vect{u}}_{0}=-\\inverse{\\matr{C}}\\pbrac{\\matr{K}\\vect{u}_{0}+\\fnof{\\vect{g}}{\\vect{u}_{0}}+\\bar{\\vect{f}}_{0}}\n\\end{equation}\n\nThe predicted displacement values are given by\n\\begin{equation}\n   \\hat{\\vect{u}}_{n+1} = \\vect{u}_{n}+\\Delta t\\dot{\\vect{u}}_{n}\n\\end{equation}\n\nThe amplification matrix is given by\n\\begin{equation}\n  \\matr{A}=\\theta_{1}\\Delta t\\matr{C}+\\dfrac{\\theta_{2}{\\Delta t}^{2}}{2}\\matr{K}\n\\end{equation}\n\nThe right hand side vector is given by\n\\begin{equation}\n  \\vect{b}=\\matr{C}\\dot{\\bar{\\vect{u}}}_{n+1}+\\matr{K}\\bar{\\vect{u}}_{n+1}+\\bar{\\vect{f}}\n\\end{equation}\n\nThe nonlinear function is given by\n\\begin{equation}\n  \\fnof{\\vect{\\psi}}{\\vect{\\alpha}^{2}_{n}}=\\matr{A}\\vect{\\alpha}^{2}_{n}+\\theta_{1}\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+\n    \\dfrac{{\\Delta t}^{2}}{2}\\vect{\\alpha}^{2}_{n}}+\\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\vect{u}_{n}}+\\vect{b}=\\vect{0}\n\\end{equation}\n\nThe Jacobian matrix is given by\n\\begin{equation}\n  \\fnof{\\matr{J}}{\\vect{\\alpha}^{2}_{n}}=\\matr{A}+\\dfrac{\\theta_{1}{\\Delta t}^{2}}{2}\n  \\delby{\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+\\dfrac{{\\Delta t}^{2}}{2}\\vect{\\alpha}^{2}_{n}}}{\\vect{\\alpha}^{2}_{n}}\n\\end{equation}\n\nAnd the time step update is given by\n\\begin{equation}\n  \\begin{split}\n    \\vect{u}_{n+1} &= \\vect{u}_{n}+\\Delta t\\dot{\\vect{u}}_{n} +\\dfrac{{\\Delta t}^{2}}{2}\\vect{\\alpha}^{2}_{n} \\\\\n    \\dot{\\vect{u}}_{n+1} &= \\dot{\\vect{u}}_{n}+\\Delta t\\vect{\\alpha}^{2}_{n}\n  \\end{split}\n\\end{equation}\n\n\\subsubsection{Special SN22 case, p=2}\n\nFor this special case, the mean predicited values are given by\n\\begin{equation}\n  \\begin{split}\n    \\bar{\\vect{u}}_{n+1} &= \\vect{u}_{n}+\\theta_{1}\\Delta t\\dot{\\vect{u}}_{n}\\\\\n    \\dot{\\bar{\\vect{u}}}_{n+1} &= \\dot{\\vect{u}}_{n}\n  \\end{split}\n\\end{equation}\n\nThe predicted displacement values are given by\n\\begin{equation}\n   \\hat{\\vect{u}}_{n+1} = \\vect{u}_{n}+\\Delta t\\dot{\\vect{u}}_{n}\n\\end{equation}\n\nThe amplification matrix is given by\n\\begin{equation}\n  \\matr{A}=\\matr{M}+\\theta_{1}\\Delta t\\matr{C}+\\dfrac{\\theta_{2}{\\Delta t}^{2}}{2}\\matr{K}\n\\end{equation}\n\nThe right hand side vector is given by\n\\begin{equation}\n  \\vect{b}=\\matr{C}\\dot{\\bar{\\vect{u}}}_{n+1}+\\matr{K}\\bar{\\vect{u}}_{n+1}+\\bar{\\vect{f}}\n\\end{equation}\n\nThe nonlinear function is given by\n\\begin{equation}\n  \\fnof{\\vect{\\psi}}{\\vect{\\alpha}^{2}_{n}}=\\matr{A}\\vect{\\alpha}^{2}_{n}+\\theta_{1}\\fnof{\\vect{g}}{\\hat{\\vect{u}}_{n+1}+ \n    \\dfrac{{\\Delta t}^{2}}{2}\\vect{\\alpha}^{2}_{n}}+\\pbrac{1-\\theta_{1}}\\fnof{\\vect{g}}{\\vect{u}_{n}}+\\vect{b}=\\vect{0}\n\\end{equation}\n\nThe Jacobian matrix is given by\n\\begin{equation}\n  \\fnof{\\matr{J}}{\\vect{\\alpha}^{2}_{n}}=\\matr{A}+\\dfrac{\\theta_{1}{\\Delta t}^{2}}{2}\n  \\delby{\\fnof{\\vect{g}}{{\\hat{\\vect{u}}_{n+1}+\\dfrac{{\\Delta t}^{2}}{2}\\vect{\\alpha}^{2}_{n}}}}{\\vect{\\alpha}^{2}_{n}}\n\\end{equation}\n\nAnd the time step update is given by\n\\begin{equation}\n  \\begin{split}\n    \\vect{u}_{n+1} &= \\vect{u}_{n}+\\Delta t\\dot{\\vect{u}}_{n} +\\dfrac{{\\Delta t}^{2}}{2}\\vect{\\alpha}^{2}_{n} \\\\\n    \\dot{\\vect{u}}_{n+1} &= \\dot{\\vect{u}}_{n}+\\Delta t\\vect{\\alpha}^{2}_{n} \n  \\end{split}\n\\end{equation}\n\n\\section{Interface Conditions}\n\n\\subsection{Variational principles}\n\nThe branch of mathematics concerned with the problem of finding a function for\nwhich a certain integral of that function is either at its largest or smallest\nvalue is called the \\emph{calculus of variations}. When scientific laws are formulated in terms of the principles of the calculus\nof variations they are termed \\emph{variational principles}. \n\n\\subsection{Lagrange Multipliers}\n\n", "meta": {"hexsha": "aa343574a4ed48f0d2a43fad8379bb5cbfc3bb4a", "size": 90493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/opencmiss/utils/iron/doc/notes/Theory/Theory.tex", "max_stars_repo_name": "tsalemink/opencmiss.utils", "max_stars_repo_head_hexsha": "c727d9b922330e3ca38967fa7dbe6480f698f9a2", "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/opencmiss/utils/iron/doc/notes/Theory/Theory.tex", "max_issues_repo_name": "tsalemink/opencmiss.utils", "max_issues_repo_head_hexsha": "c727d9b922330e3ca38967fa7dbe6480f698f9a2", "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/opencmiss/utils/iron/doc/notes/Theory/Theory.tex", "max_forks_repo_name": "tsalemink/opencmiss.utils", "max_forks_repo_head_hexsha": "c727d9b922330e3ca38967fa7dbe6480f698f9a2", "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.0355231144, "max_line_length": 183, "alphanum_fraction": 0.6539179826, "num_tokens": 35320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.826711787666479, "lm_q1q2_score": 0.6834523922203591}}
{"text": "\\documentclass{article}\n\\usepackage{mathtools}\n\\usepackage{pgfplots}\n\\usepackage[utf8]{inputenc}\n\n\\title{CSE546 HW0 B}\n\\author{Bobby Deng | 1663039 | dengy7 }\n\\date{March 2020}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\n\n\\begin{document}\n\\maketitle\n\n\\section*{B.1}\nPDF is:\\newline\n\\[ \nf(x) = \\begin{cases}\n1, & \\text{for $0 < x < 1$} \\\\\n0, & \\text{otherwise.}\n\\end{cases} \n\\]\nCDF is:\n\\[ F_x(x)=\\int_{-\\infty}^{x}f(x)dx=x \\]\nLet me calculate the PDF of: $Y=Max(X_1,X_2,....,X_n)$, and here we need to use joint probability to compute.\n\\[ P(Max(X_1,X_2,....,X_n) = P(X_1\\le X,X_2\\le X,...,X_{n-1}\\le X) \\]\nSo we have:\n\\[ f_Y(x)=n[F_x(x)]^{n-1}f(x)=n(x)^{n-1}*1=n(x)^{n-1} \\]\n\\[ \n=\\begin{cases}\nnx^{n-1}, & \\text{for $0 < x < 1$} \\\\\n0, & \\text{otherwise.}\n\\end{cases} \n\\]\nNow we need $E[Y]$, we use mean equation for continuous random variable. \n\\[ E[Y]=\\int_0^1xf_M(x)dx=\\int_0^1xnx^{n-1}dx=n\\int_0^1x^ndx=\\frac{n}{n+1} \\]\n\n\n\\section*{B.2}\nSince, $A\\in \\rm I\\!R^{n \\times m}$, and $B\\in \\rm I\\!R^{m \\times n}$\nSo,\n\\begin{equation}\n\\begin{split}\ntr(AB) = & \\sum_{i=1}^m (AB)_{ii} \\\\\n& = \\sum_{i=1}^m \\sum_{j=q}^n A_{i,j}B_{j,i} \\\\\n& = \\sum_{j=1}^n \\sum_{i=1}^m B_{j,i}A_{i,j} \\\\\n& = \\sum_{j=1}^n (BA)_{j,j} \\\\\n& = tr(BA)\n\\end{split}\n\\end{equation}\n\n\\section*{B.3}\n\\subsection*{a.}\nWhen we consider a matrix of d by d, so, \\newline\nMax rank: d and Min rank: 1; \n\\subsection*{b.}\nBecause V is a b by n matrix, and $v_i$ is none zero vectors, so, \\newline\nMax rank: $min(d,n)$, Min rank: 1;\n\\subsection*{c.}\nSince A is D by d and $v_i$ is d by 1, so $Av_i$ is D by 1. So, we could know that $(Av_i)^T$ is 1 by D. \\newline\n\nSo $(Av_i)(Av_i)^T$ is D by D. Then, \\newline\nMax rank: D, Min rank: 0.\n\\subsection*{d.}\nSince V is d by n, so AV is D by n, so\\newline\nFor AV, Max: min(d,n), Min is 0.\\newline\nIf V is rank d, Max: d, Min: 0.\n\n\n\\end{document}", "meta": {"hexsha": "b5994ecd3faeb86bc5254ac895f5acec9440a12b", "size": 1843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw0/CSE546hw1B.tex", "max_stars_repo_name": "bobbydyr/CSE546-Machine-Learning", "max_stars_repo_head_hexsha": "c3f7e487b60506acfa7886d7cc64dfa61550ee4b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw0/CSE546hw1B.tex", "max_issues_repo_name": "bobbydyr/CSE546-Machine-Learning", "max_issues_repo_head_hexsha": "c3f7e487b60506acfa7886d7cc64dfa61550ee4b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw0/CSE546hw1B.tex", "max_forks_repo_name": "bobbydyr/CSE546-Machine-Learning", "max_forks_repo_head_hexsha": "c3f7e487b60506acfa7886d7cc64dfa61550ee4b", "max_forks_repo_licenses": ["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.5972222222, "max_line_length": 113, "alphanum_fraction": 0.6055344547, "num_tokens": 817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.6834285008758716}}
{"text": "\\chapter{Sets and Measure Theory\t}\n\n\\begin{multicols}{2}[\\subsubsection*{Contents of this chapter}]\n   \\printcontents{}{1}{\\setcounter{tocdepth}{2}}\n\\end{multicols}\n\n\n\nSets are a term to describe collections of things. The things could be countable objects, such as the integers between $1$ and $10$, or contain a continuum, for example all the real numbers between $1$ and $10$. Unless otherwise specified, the elements of a set are assumed to be distinct and as not having an internal order. That is, the set of letters in \"Mississippi\" is $\\{M,i,s,p \\} = \\{i,p,M,s \t\\} = ... $ and so on. A concise resource for notation is \\citeasnoun{stanfordsetnotation}. \n\n\n% representation\n\\section{Representation}\n\n\\begin{tabular}{ll}\nStatement Form & $\\{\\mathrm{integers\\ between\\ 1\\ and\\ 5}\\}$\\\\\nRoster Form & $\\{1,2,3,4,5\\}$ \\\\\nSetbuilder Form & $\\{x|x\\in\\mathbb{N}, 1\\leq x \\leq 5 \\} $\n\\end{tabular}\n\n\n% Set Properties, Types of Sets\n\\section{Set Properties and Types of Sets}\n\n\\subsection{Cardinality}\nThe cardinality of a set is a measure of the size of a set. For finite sets, the cardinality is simply the number of elements. For example, the set  $A = \\{a,b,c,d\\}$ has size $|A|=4$.\n\nFor infinite sets, this intuition breaks down, though it is still possible to make meaningful comparisons. \n\n\\subsection{$\\emptyset$ Empy Set, Null Set}\nThe empty set is the set with no elements. It is denoted $\\{\\}$ or $\\emptyset$. \n\n\\subsection{Singleton Set}\nA singleton set is a set with one element. I.e., $\\{a\\}, \\{b\\}$ are singleton subsets of $\\{a,b\\}$. A singleton has cardinality 1.\n\n\\subsection{Countable Sets}\nA set is countable if it contains finitely many elements or if its elements can be brought into a one-to-one correspondence with the set of integers. The set of all even integers is countable. The set of real numbers between $0$ and $1$ is not countable.\n\n\\subsection{Infinite Sets}\n\n\\subsection{Multisets}\nA multiset is a set that may contain an element more than once. I.e. it makes sense to write $A=\\{a,a,a,b,b\\}$. The number of times an element is included is the \\textit{multiplicity}. The multiset $A$ may be defined in terms of a \\textit{multiplicity function} $m_A(x)$, which describes the multiplicity of a type of element $x\\in U$ where $U$ may be referred to as the \\textit{universe} (en lieu of saying \"univseral\"!). The multiplicity function allows the extension of set characteristics and operations to multisets.\n\n\\subsubsection{Support}\nThe support of a multiset is:\n\n\\begin{equation}\nSupp(A) = \\{ x\\in U | \tm_A(x)>0\\}\n\\end{equation} \n\nWhich is the set of distinct elements in $A$. I.e., if $A = \\{a,a,a,b,b,c\\}$ then $Supp(A) = \\{a,b,c\\}$.\n\n\\subsubsection{Cardinality}\n\nThe cardinality is given by:\n\n\\begin{equation}\n|A| = \\sum_{x\\in U} m_A(x)\n\\end{equation}\n\n\\subsubsection{$\\subseteq$ Inclusion}\nThe concept of subsets can be extended to multisets as:\n\n\\begin{equation}\nA \\subseteq B\n\\end{equation}\n\nif \n\n\\begin{equation}\n\\forall x\\in U, \\ \\ m_A(x) \\leq m_B(x)\n\\end{equation}\n\n\n\\subsubsection{$\\bigcap$ Intersection}\nThe intersection of multisets is sometimes called the \\textit{infimum} or \\textit{greatest common divisor}. If $A\\cap B = C$, then $C$ has multiplicity function:\n\n\\begin{equation}\nm_C(x) = min\\left(m_A(x),m_B(x)\\right)\n\\end{equation}\n\nThat is, it is like an elementwise minimum.\n\n\\subsubsection{$\\bigcup$ Union}\nIn the context of multisets, the term \\textit{union} sometimes refers to multiset addition. Otherwise, it should refer to the overlap of two multisets, i.e.:\n \n\\begin{equation}\nm_C(x) = max\\left(m_A(x),m_B(x)\\right)\n\\end{equation}\n\nThat is, it is like an elementwise maximum.\n\n\\subsubsection{$\\uplus$ Multiset Addition} \nIn contrast to sets in which distinct elements are only contained once, multiset addition makes sense and uses a special symbol \"$\\uplus$\". If $A\\uplus B = C$, then $C$ has multiplicity function:\n\n\\begin{equation}\nm_C(x) = m_A(x) + m_B(x)\n\\end{equation} \n\n\\subsubsection{Multiset Subtraction}\nMultisets can be subtracted, with the condition that the multiplicity can not be less than zero. If $A- B = C$, then $C$ has multiplicity function:\n\n\\begin{equation}\nm_C(x) = max\\left(m_A(x) - m_B(x), 0\\right)\n\\end{equation}\n\n% Powerset\n\\subsection{Powersets}\nThe powerset $P(S)$ of a set $S$ is the set of all subsets of $S$, including the empty set and the set itself. That is:\n\n\\begin{equation}\nP(S) = \\{ A : A\\subseteq S\\}\n\\end{equation}\n\nMy guess is it's called powerset because the number of subsets of S, $|P(S)| = 2^{|S|}$. I have also seen the notation $2^S$ to refer to the space of subsets of $S$.\n\n\n\n% Measurable Sets\n\\subsection{Measurable Sets}\nMeasurable sets have a way of measuring volume on them in a non-trivial way. That is, for some subset of a measurable set $A_i \\subseteq A$, it is possible to define a metric $\\mu$ so that $\\mu(A_i) \\neq0)$. Measurable sets are the elements of a $\\sigma$-algebra. \n\n% universal set\n\\subsection{Universal Set}\nThe \\textit{universal set} is understood to refer to something that is not allowed in the context of Russell's Paradox. It is nevertheless useful to define a set $S$ so that $S^c = \\emptyset$ and I've seen this type of set referred to as \\textit{universal set} a couple of times. In the context of probability theory, $S$ may be the whole event space.\n\n\n\n\n%% open sets, closed sets\n\\subsection{Open Sets, Closed Sets}\nOpen sets and closed sets are generalizations of open and closed intervals on the real line. Open sets a mentioned plenty in the context of measure theory. A set is open if and only if its complement is closed, and a set is closed if and only if its complement is open. Counterintuitively, a set can be both open and closed at the same time, or it can be neither open nor closed at the same time.\n\n\\subsubsection{Interior Points}\nAn interior point of a set $A$ is any point $X$ so that for some $\\epsilon > 0$, the open interval $X-\\epsilon,X+\\epsilon \\subseteq A$ is contained within $A$. One might imagine an interior point as a point that has a neighborhood (a \"ball\") that is included in $A$. \n\n\\subsubsection{Accumulation Points} \nIn contrast, accumulation points do not have a neighborhood contained in $A$. Formally, for some $\\epsilon>0$, $(X-\\epsilon,X+\\epsilon)\\cap (A\\setminus \\{X\\}) \\neq \\emptyset$, which is only possible for a point that is on the very boundary of $A$.\n\n\\subsubsection{Open Sets}\nUnsurprisingly, an open set is a set that only has interior points, i.e. $\\{X: X\\in A, \\exists \\epsilon > 0 \\mathrm{\\ s.\\ th.\\ } X-\\epsilon,X+\\epsilon \\subseteq A  \\}$.\n\n\\subsubsection{Closed Sets}\nClosed sets contain all of their accumulation points. That is, the boundary is included. Points might also be standing alone, for example:\n\n\\begin{equation}\n[2,4]\\cup\\{1\\}\n\\end{equation}\n\nIs a closed set.\n\n\\subsubsection{Both Open and Closed, Neither Open Nor Closed}\nThe set of real numbers $\\mathbb{R}$ is both open and closed. Any point on the real line has a neighborhood in $\\mathbb{R}$, so it is open. On the other hand, the accumulation points of $\\mathbb{R}$ are $\\mathbb{R}$, so it is closed. An interval that has some but not all accumulation points is neither open nor closed. For example $[1,2)$.\t\n\n%% Image\n\\subsection{Image}\n\\label{sec:image}\nThe image are the elements of the codomain that a given subset of the domain is mapped to. For example, given a function $f:\\mathbb{R} \\rightarrow \\mathbb{R}: f(x) = x^2$, the image of $\\{-3,-2,2,3\\}$ in the domain are the elements $\\{4,9\\}$ of the codomain.\n\n%% Preimage \n\\subsection{Preimage, Inverse Image}\n\\label{sec:preimage}\nThe preimage are elements of the domain that are mapped to a given subset of the codomain. For example, given a function $f:\\mathbb{R} \\rightarrow \\mathbb{R}: f(x) = x^2$, the preimage of the elements $\\{4,9\\}$ of the codomain are the elements $\\{-3,-2,2,3\\}$ of the domain..\n\n\n%% Convex Sets\n\\subsection{Convex Sets}\nConvex sets are subsets of vector spaces in which any point along the line connecting to points within the set is contained within the set. A disk in $\\mathbb{R}^2$ is a convex set. A crescent in $\\mathbb{R}^2$ is not a convex set. The boundary of a convex set is a convex function. For example, a parabola $f(x) = x^2$ with $x\\in\\mathbb{R}$ is a convex function, and the area above the parabola, called the epigraph, is a convex subset of $\\mathbb{R}$. Convex optimization deals with the optimization of convex functions over convex sets. The intersection of convex sets is always convex, but the union of convex sets is only convex under certain conditions. \n\nMore generally, if $S$ is a convex set, then affine combinations of the elements $\\mathbf{x}_i  \\in S$ of the form:\n\n\\begin{equation}\n\\sum_i \\mathbf{x}_i \\lambda_i \n\\label{eq:convexsets}\n\\end{equation}  \n\nWith $\\sum_i \\lambda_i = 1$ and $\\lambda_i\\geq 0$ are also contained in $S$. Rather than just the points along the line between two points, these are the essentially the weighted averages of multiple points in the set.  \n\n\\subsubsection{Example: Discrete Probability Distributions}\nThe set of discrete probability distributions $P = \\{ \\mathbf{p}=(p_1,p_2,...): ||\\mathbf{p}||_1 = 1, p_i \\geq 0\\}$ is a convex set. Property \\ref{eq:convexsets} means that a weighted average over members of $P$ is also a member of $P$, so long as the weights satisfy $\\sum_i \\lambda_i = 1$. In general, this guarantees that marginalization results in a probability. I.e. if $p(X|Y) = \\mathbf{p}(X|Y) \\in P$ and $p(Y) = \\mathbf{p}(Y) \\in P$, then $\\mathbf{p}(X) = \\sum_i p_i(X|Y) p_i(Y) \\in P$. \n\n%% Choice sets, Transverse Sets, Cross-sections\n\\subsection{Choice Sets, Transversal Sets, Cross-Sections}\n\\label{sec:choicesets}\nChoice sets, transversal sets or cross-sections are sets that are assembled by picking exactly one element from each member of a family of disjoint sets. The axiom of choice (cf. section \\ref{sec:axiomofchoice}) states that such a set can always be formed.\n\n\\subsubsection{Example: Integers}\nConsider the partition of the integers between $1$ and $40$ into a family of disjoint sets that each contain $10$ elements: \n\n\\begin{equation}\nS = \\{ \\{1,...,10\\}, \\{11,...,20\\}, \\{21,...,30\\},\\{31,...,40\\} \\}\n\\end{equation}\n\nThen a transversal set $A$ could for example be formed by picking the smallest number in each of the subsets. \n\n\\begin{equation}\nA = \\{1,11,21,31\\}\n\\end{equation}\n\nThough we might have picked any other choice function.  \n\n\n% Set operations\n\\section{Set Operations}\n\n\\subsection{$A^c$ Complement}\nGiven a subset $A \\subseteq X$, the complement of the subset $A^c$ refers to everything that is not contained in $A$, i.e. $A^c = X\\setminus A$. \n\n\n\\subsection{$\\bigcup$ Union}\nThe union of sets is the set that contains all of their elements, counting all elements only once. The cardinality of the union is calculated using the important inclusion exclusion principle (\\ref{sec:inclusionexclusion}). In terms of logic, think $A\\cup B$ is \"A or B (or both)\".\n\n\\subsection{$\\bigcap$ Intersection}\nThe intersection of sets is the elements shared by all sets. $A\\cap B$ is \"A and B\".\n\n% Disjoint Union\n\\subsection{$\\bigsqcup$ Disjoint Union, Discriminated Union}\nThe disjoint union, or discriminated union, of sets is the union formed in a way in which the information about which subset an element belonged to is preserved. One way to write this is to include a subset index with each element, i.e.:\n\n\\begin{equation}\n\\bigsqcup_{i\\in\\{i\\}}A_i = \\bigcup_{i\\in\\{i\\}} \\{(x,i): x\\in A_i\\}\n\\end{equation}\n\nFor example, for the two sets $A=\\{1,2,3,4\\}$ and $B=\\{1,2,3\\}$, the disjoint union is:\n\n\\begin{equation}\nA\\sqcup B = \\{(1,A),(2,A),(3,A),(4,A),(1,B),(2,B),(3,B)\\}\n\\end{equation}\n\nThe cardinality of the disjoint union is simply the sum:\n\n\\begin{equation}\n\\left|\\bigsqcup_{i\\in\\{i\\}}A_i\\right| = \\sum_{i\\in\\{i\\}}|A_i\n\\end{equation}\n\nI have also seen the disjoint union be used in the context of forming the union of disjoint sets, perhaps to stress that the sets are disjoint and the cardinality can be calculated through simple summation as above. For example, in dividing up the interval: $[0,2]=[0,1)\\sqcup[1,2]$.\n\n\n% Bijection Principle\n\\section{Bijection Principle}\nThe bijection principle states that when a bijection exists between the elements of two sets, then those sets have the same size. This principle is very useful in combinatorics, and it allows for meaningful comparisons of infinite sets.\n\n\n% DeMorgan\n\\section{DeMorgan's Rules}\n\\label{sec:demorgan}\nDeMorgan's Rules relate the complement of the union to the intersection of the complements, and the complement of the intersection to the union of the complements.\n\n\\begin{equation}\n\\left(\\bigcup_{i\\in\\{i\\}}A_i\\right)^c = \\bigcap_{i\\in\\{i\\}}A^c_i\n\\end{equation}\n\n\\begin{equation}\n\\left(\\bigcap_{i\\in\\{i\\}}A_i\\right)^c = \\bigcup_{i\\in\\{i\\}}A^c_i\n\\end{equation}\n\n\n%Inclusion Exclusion\n\\section{Inclusion - Exclusion Principle}\n\\label{sec:inclusionexclusion}\n\nThe inclusion-exclusion principle is used to calculate the size of the union of sets. This requires counting each region of some complicated overlapping Venn diagram exactly once, which, in turn requires accounting for overcounting wherever sets overlap. Let $\\{A_i | i\\in \\{i\\}_n \\}$ be a collection of $n$ overlapping sets indexed by $i\\in \\{i\\}_n$, then the inclusion-exclusion principle is given by:\n\n\\begin{equation}\n\\left|\\bigcup_{i\\in\\{i\\}_n} A_i\\right| = \\sum^n_{k=1} (-1)^{k-1} \\sum_{\\{j\\}_k \\subseteq \\{i\\}_n} \\left|\\bigcap_{j\\in\\{j\\}_k} A_j\\right|\n\\end{equation}\n\n\nWhere the sum over $\\{j\\}_k \\subseteq \\{i\\}_n$ is over all $k$-element subsets of $\\{i\\}_n$.\n\n\\subsection{Example: n=2 Sets and n=3 Sets}\n\n\\subparagraph{n=2}\n\\begin{equation}\n\\begin{array}{rl}\n\\left|\\bigcup_{i\\in\\{1,2\\}}A_i\\right| =&  \\sum^2_{k=1} (-1)^{k-1} \\sum_{\\{j\\}_k \\subseteq \\{1,2\\}} \\left|\\bigcap_{j\\in\\{j\\}_k} A_j\\right|\\\\\n=&(-1)^{0}\\left(|A_1| + |A_2|\\right) \\\\\n&+ (-1)^{1}\\left(|A_1 \\cap A_2| \\right)\n\\end{array}\n\\end{equation}\n\n\n\\subparagraph{n=3}\n\\begin{equation}\n\\begin{array}{rl}\n\\left|\\bigcup_{i\\in\\{1,2,3\\}}A_i\\right| =&  \\sum^3_{k=1} (-1)^{k-1} \\sum_{\\{j\\}_k \\subseteq \\{1,2,3\\}} \\left|\\bigcap_{j\\in\\{j\\}_k} A_j\\right|\\\\\n=&(-1)^{0}\\left(|A_1| + |A_2| + |A_3|\\right) \\\\\n&+ (-1)^{1}\\left(|A_1 \\cap A_2|  + |A_1 \\cap A_3| + |A_2 \\cap A_3|  \\right) \\\\ \n&+ (-1)^{2}\\left(|A_1 \\cap A_2 \\cap A_3|   \\right)\n\\end{array}\n\\end{equation}\n\n\\subsubsection{Example: Counting Integers}\n\nHow many integers are there between 1 and 100 that are neither divisible by 3,5 nor 7?\n\nLet $S$ be the set of all integers between 1 and 100. The size of the set is $|S| = 100$. The subset of $S$ that is numbers divisible by 3 is $A_3 \\subseteq S$ with $|A_3| = 33$ because $100/3 = 33.\\overline{333}$. Similarly, $|A_5| = 20$ and $|A_7| = 14$.  The set of integers that is not divisible by 3, 5 or 7 is:\n\n\\begin{equation}\nS \\setminus \\bigcup_{i\\in\\{3,5,7\\}} A_i\n\\end{equation}\n\nSo that the sought after quantity is :\n\n\\begin{equation}\n\\begin{array}{rl}\n\\left|S \\setminus \\bigcup_{i\\in\\{3,5,7\\}} A_i\\right| =& |S| - \\left[ |A_3| + |A_5| + |A_7| \\right.\\\\\n& \\left. - |A_3 \\cap A_5| - |A_3 \\cap A_7| - |A_5\\cap A_7| + |A_3\\cap A_5\\cap A_7|\\right]\n\\end{array}\n\\end{equation}\n\nThe size of the intersection $|A_3\\cap A_5| = 6$ because 100 is 6 times divisible by $3\\times 5 = 15$. Similarly, $|A_3 \\cap A_7| =  4$, $|A_5 \\cap A_7| =  2$ and $|A_3\\cap A_5 \\cap A_7| =  0|$. Hence:\n\n\\begin{equation}\n\\left|S \\setminus \\bigcup_{i\\in\\{3,5,7\\}} A_i\\right| = 100 - 33 - 20 - 14 + 6 + 4 + 2 - 0 = 45\n\\end{equation}\n\nThere are 45 integers between 1 and 100 that are not divisible by 3, 5 or 7.\n\n\n\\section{Axiom of Choice}\n\\label{sec:axiomofchoice}\nThe axiom of choice simply states that, given a collection of nonempty, mutually disjoint sets, it is possible to assemble a \\textit{transversal} or \\textit{choice} set that consists of exactly one element from each of the sets in the collection. For example, consider the students in 1st, 2nd, 3rd.. etc grades at a school to be a collection of nonempty, mutually disjoint sets. Then the axiom of choice says that it is possible to assemble a subset of students with exactly one student from each grade. \n\n\nIn terms of functions, one might think of defining a \\textit{choice function} on the family of mutually disjoint sets, which selects members from the collection of sets and adds them to the \\textit{choice} set. According to the axiom of choice, a choice function can be defined for any collection of nonempty, mutually disjoint subsets. This implies that all surjective functions have a right inverse. That is, for any surjective function $f:X\\rightarrow Y$, there exists a function $g:Y\\rightarrow X$ so that $f(g(y)) = y$.   \n\nThe axiom of choice turns out to be associated with famous names and deep consequences \\cite{stanfordaxiomofchoice}.\n\n\\subsection{Example: Pairs of Real Numbers, Right Inverse}\nThe collection of rank-2 sets of pairs of real numbers $A= \\{ A_x = \\{x,-x\\} : x\\in \\mathbb{R}^{+}\\}$ are a collection of mutually disjoint subsets. A transversal set $B$ may be assembled by choosing the largest element of the tuple: $B = \\{y : y max(A_x), A_x \\in A \\}$. An equivalent surjection $f:A\\rightarrow B$ is $f(A_x) = x$. There is a right-inverse $g:B\\rightarrow A$ which is $g(x) = (x,-x)$ so that $f(g(x)) = x$.\n\n\n\n\n\n\n\n\\input{./chapters/sections/sets_sigma.tex}", "meta": {"hexsha": "895dc32809c80f304481e057963ba15668458966", "size": 17274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sets.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/sets.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/sets.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": 50.9557522124, "max_line_length": 660, "alphanum_fraction": 0.7176681718, "num_tokens": 5332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6834284814395901}}
{"text": " \n%% document Notes\n\n\\documentclass[12pt]{article}\n\\usepackage{fullpage,graphicx,psfrag,amsmath,amsfonts,verbatim}\n\\usepackage[small,bf]{caption}\n\n\n\\bibliographystyle{alpha}\n\n\\title{Computational Intelligence         Bonus Problem }\n\n\n\\author{Mostafa Osama Ahmed Metwally Othman}\n\n\\begin{document}\n\\maketitle{Mini Max Problem}\\\\\nThis problem is a Mini max Quadratic problem where we want to solve using CVX solver or any other so we need to reformulate the problem to be in the form of one of the known forms and we are looking for the worst case scenario in order to achieve our goal.\n\n\n\n\n\n\\paragraph{Problem statement:}\n\n%\n\\begin{equation}\n\\begin{aligned}\n& \\underset{\\mathbf{X}}{\\text{min   }}\\underset{\\mathbf{y}}{\\text{max}}\n& & || \\mathbf{X} - \\mathbf{ X^\\star} ||, \\\\\n& \\text{subject to}\n& & \\begin{cases}\n\n   (\\mathbf{y}-\\mathbf{a})^T \\mathbf{D} (\\mathbf{X}-\\mathbf{b}) + \\mathbf{s}^T \\mathbf{y} + \\mathbf{q}^T \\mathbf{X} \\leq h  \\\\\n   ||\\mathbf{H}\\mathbf{y}+\\mathbf{f}|| \\leq p\n    \\end{cases}\n\\end{aligned}\n\\end{equation}\n\n\\paragraph{Solution:}\n\n\n\n\\begin{equation}\n\\begin{aligned}\n\\text{let us consider:}\\\\\n& \\mathbf{v} = ||\\mathbf{H}\\mathbf{y}+\\mathbf{f}||\\\\\n& \\mathbf{y} = \\mathbf{H}^{-1} (\\mathbf{v} - \\mathbf{f})\\\\\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n\\text{substitute in main equation: }\\\\\n& (\\mathbf{y}-\\mathbf{a})^T \\mathbf{D} (\\mathbf{X}-\\mathbf{b}) + \\mathbf{s}^T \\mathbf{y} + \\mathbf{q}^T \\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n& ( \\mathbf{H}^{-1} (\\mathbf{v} - \\mathbf{f})-\\mathbf{a})^T \\mathbf{D} (\\mathbf{X}-\\mathbf{b})+ \\mathbf{s}^T  \\mathbf{H}^{-1} (\\mathbf{v} - \\mathbf{f}) + \\mathbf{q}^T \\mathbf{X} \\leq h  \\\\\n\\text{let us expand the equation:}\\\\\n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n& ( \\mathbf{H}^{-1} \\mathbf{v} - \\mathbf{H}^{-1} \\mathbf{f}-\\mathbf{a})^T \\mathbf{D} (\\mathbf{X}-\\mathbf{b})+ \\mathbf{s}^T  \\mathbf{H}^{-1} \\mathbf{v} - \\mathbf{s}^T\\mathbf{H}^{-1} \\mathbf{f} + \\mathbf{q}^T \\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{v}^T \\mathbf{H}^{-T} \\mathbf{D} (\\mathbf{X}-\\mathbf{b}) - (\\mathbf{H}^{-1} \\mathbf{f}-\\mathbf{a})^T \\mathbf{D} (\\mathbf{X}-\\mathbf{b})+ \\mathbf{s}^T  \\mathbf{H}^{-1} \\mathbf{v} - \\mathbf{s}^T\\mathbf{H}^{-1} \\mathbf{f} + \\mathbf{q}^T \\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\n\n\\begin{equation}\n\\begin{aligned}\n\\text{Using vector operations:}\\\\\n& \\mathbf{s}^T  \\mathbf{H}^{-1} \\mathbf{v} = \\mathbf{v}^T\\mathbf{H}^{-T}\\mathbf{s} \\\\\n& \\mathbf{s}^T\\mathbf{H}^{-1} \\mathbf{f} = \\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s} \\\\\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{v}^T \\mathbf{H}^{-T} \\mathbf{D}\\ (\\mathbf{X}-\\mathbf{b})-(\\mathbf{H}^{-1}\\mathbf{f}-\\mathbf{a})^T\\ \\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{v}^T\\mathbf{H}^{-T}\\mathbf{s}-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\n\n\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{v}^T \\mathbf{H}^{-T} \\mathbf{D}\\ (\\mathbf{X}-\\mathbf{b})-(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{v}^T\\mathbf{H}^{-T}\\mathbf{s}-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\n\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{v}^T \\mathbf{H}^{-T} (\\mathbf{D}\\ (\\mathbf{X}-\\mathbf{b})+\\mathbf{s})-(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\n\nNow by looking at this equation, the worst case scenario corresponds to the largest value of $\\mathbf{V}^T  \\mathbf{H}^{-T} (\\mathbf{D} (\\mathbf{X}-\\mathbf{b})+\\mathbf{s})$ \nwhere $\\mathbf{V}^T$ should align with the other term in order to get the maximum possible value $\\mathbf{p}$\n\n\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{v} = \\mathbf{p} \\frac{\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})}{||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})||} \\\\\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n&\\mathbf{p} \\frac{(\\mathbf{H}^{-T} (\\mathbf{D}\\ (\\mathbf{X}-\\mathbf{b})+\\mathbf{s}))^T\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s}) }\n{||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})||}-(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\ \n\\end{aligned}\n\\end{equation}\n\n\n\n\\begin{equation}\n\\begin{aligned}\n\\mathbf{p} \\frac{(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})^T \\mathbf{H}^{-1}\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s}) } {||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})||}-(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\ \n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{p} \\frac{||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})||^2}{||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})||}-(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\\n\\end{aligned}\n\\end{equation}\n\n\n\\begin{equation}\n\\begin{aligned}\n& \\mathbf{p} ||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})|| -(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\ \\\\\n\\end{aligned}\n\\end{equation}\n\nThen we can Re-Represent the problem into :\n\n%\n\\begin{equation}\n\\begin{aligned}\n& \\underset{\\mathbf{X}}{\\text{min }}\n& & || \\mathbf{X} - \\mathbf{ X^\\star} ||, \\\\\n& \\text{subject to}\n& & \\mathbf{p} ||\\mathbf{H}^{-T}(\\mathbf{D}(\\mathbf{X}-\\mathbf{b})+\\mathbf{s})|| -(\\mathbf{H}\\mathbf{a}+\\mathbf{f})^T\\ \\mathbf{H}^{-T}\\mathbf{D}(\\mathbf{X}-\\mathbf{b})-\\mathbf{f}^T\\ \\mathbf{H}^{-T}\\mathbf{s}+\\mathbf{q}^T\\mathbf{X} \\leq h  \\\\ \n\\end{aligned}\n\\end{equation}\n\nWhich is then considered as a SOCP Problem.\n\n\n\\end{document}", "meta": {"hexsha": "24bdf301cd7f2fbbc1e141a209861b6a0b720f8a", "size": 6210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Slides/MiniMax_Problems/main.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": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-19T17:29:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T08:01:27.000Z", "max_issues_repo_path": "Slides/MiniMax_Problems/main.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": "Slides/MiniMax_Problems/main.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": 39.3037974684, "max_line_length": 373, "alphanum_fraction": 0.6190016103, "num_tokens": 2818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6834284813939981}}
{"text": "\\subsection{Integers}\\label{subsec:integers}\n\n\\begin{definition}\\label{def:set_of_integers}\n  The \\hyperref[def:ring]{ring} \\( \\BbbZ \\) of \\term{integers} is defined as the \\hyperref[thm:grothendieck_semiring_completion]{Grothendieck completion} of the \\hyperref[def:semiring/commutative]{commutative semiring} \\( \\BbbN \\) of zero-based natural numbers.\n\\end{definition}\n\n\\begin{lemma}\\label{thm:integer_signum_lemma}\n  Consider the canonical embedding \\( \\iota: \\BbbN \\to \\BbbZ \\). For every nonzero integer \\( n \\), there either exists a unique natural number \\( a \\) such that \\( n = \\iota(a) \\), or a unique natural number \\( a \\) such that \\( n = -\\iota(a) \\).\n\\end{lemma}\n\\begin{proof}\n  \\SubProof{Proof of existence} Due to the trichotomy on natural numbers shown in \\fullref{def:natural_number_ordering}, we have the following mutually exclusive possibilities:\n  \\begin{itemize}\n    \\item If \\( a = b \\), then \\( x = [(a, a)] = [(0_\\BbbN, 0_\\BbbN)] \\), hence \\( x \\) is zero.\n    \\item If \\( a < b \\), by \\fullref{def:natural_number_ordering}, there exists some positive natural number \\( c \\) such that \\( a + c = 0_\\BbbN + b \\). Then\n    \\begin{equation*}\n      x = [(a, b)] = [(c, 0_\\BbbN)] = \\iota(c).\n    \\end{equation*}\n\n    \\item If \\( a > b \\), there exists some natural number \\( d \\) such that \\( 0_\\BbbN + a = b + d \\). Then\n    \\begin{equation*}\n      x = [(a, b)] = [(0_\\BbbN, d)] = -[(d, 0_\\BbbN)] = -\\iota(d).\n    \\end{equation*}\n  \\end{itemize}\n\n  \\SubProof{Proof of uniqueness} If \\( \\iota(a) = \\iota(b) \\), then there exists some natural number \\( u \\) such that\n  \\begin{equation*}\n     a + 0_\\BbbN + u = 0_\\BbbN + b + u.\n  \\end{equation*}\n\n  By \\fullref{thm:natural_number_addition_properties}, \\( \\BbbN \\) is cancellative, so \\( a = b \\).\n\n  \\SubProof{Proof of exclusive conditions} Finally, suppose that \\( n = \\iota(a) = -\\iota(b) \\). Then \\( a + b = 0_\\BbbN \\). Since \\( \\BbbN \\) is \\hyperref[def:zerosumfree]{zerosumfree} by \\fullref{thm:natural_number_addition_properties}, it follows that \\( a = b = 0_\\BbbN \\), and hence \\( n \\) is zero.\n\n  Therefore, if \\( n \\) is nonzero, either \\( n = \\iota(a) \\) for some \\( a \\) or \\( n = -\\iota(b) \\) for some \\( b \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:integer_signum}\n  Consider the canonical embedding \\( \\iota: \\BbbN \\to \\BbbZ \\). Define the \\term{signum} function\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\sgn: \\BbbZ \\to \\BbbZ \\\\\n      &\\sgn(n) \\coloneqq \\begin{cases}\n        0,  &n = \\iota(0_\\BbbN), \\\\\n        1,  &n = \\iota(a) \\T{for some nonzero natural number} a, \\\\\n        -1, &n = -\\iota(a) \\T{for some nonzero natural number} a.\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  This is a well-defined \\hyperref[def:multi_valued_function/total]{total function} due to \\fullref{thm:integer_signum_lemma}.\n\n  We then classify integers based in their sign as follows\n  \\begin{center}\n    \\begin{tabular}{l | l || l | l}\n      Positive    & \\( \\sgn(n) = 1 \\)  & Nonpositive & \\( \\sgn(n) \\neq 1 \\) \\\\\n      Negative    & \\( \\sgn(n) = -1 \\) & Nonnegative & \\( \\sgn(n) \\neq -1 \\) \\\\\n      Zero        & \\( \\sgn(n) = 0 \\)  & Nonzero     & \\( \\sgn(n) \\neq 0 \\) \\\\\n    \\end{tabular}\n  \\end{center}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:integer_signum}\n  \\hyperref[def:integer_signum]{Integer signs} has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:integer_signum/entire} The ring of integers is \\hyperref[def:divisibility/zero]{entire}, i.e. an \\hyperref[def:integral_domain]{integral domain}.\n    \\thmitem{thm:def:integer_signum/sum} If two integers have the same sign, their sum also has the same sign.\n    \\thmitem{thm:def:integer_signum/product} \\( \\sgn(nm) = \\sgn(n) \\cdot \\sgn(m) \\).\n    \\thmitem{thm:def:integer_signum/zero} \\( n \\) is zero if and only if \\( -n \\) is zero.\n    \\thmitem{thm:def:integer_signum/inverse} \\( n \\) is positive if and only if \\( -n \\) is negative.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:integer_signum/entire} Suppose that \\( nm = 0 \\).\n\n  \\begin{itemize}\n    \\item If \\( n = \\iota(a) \\) and \\( m = \\iota(b) \\) are nonnegative, since \\( \\BbbN \\) is entire and since \\( \\iota \\) is a homomorphism, then \\( nm = \\iota(a) \\cdot \\iota(b) = \\iota(ab) = \\iota(0_\\BbbN) \\) implies that at least one of \\( a \\) or \\( b \\) is zero.\n    \\item If \\( n = \\iota(a) \\) is nonnegative and \\( m = -\\iota(b) \\) is nonpositive, this reduces to the previous case since \\( nm = 0 = n(-m) \\).\n    \\item The other cases are similar.\n  \\end{itemize}\n\n  Therefore, \\( n = 0 \\) or \\( m = 0 \\).\n\n  \\SubProofOf{thm:def:integer_signum/sum} Fix two integers \\( n \\) and \\( m \\).\n\n  \\begin{itemize}\n    \\item If \\( n \\) and \\( m \\) are both zero, their sum is also zero.\n    \\item If \\( n = \\iota(a) \\) and \\( m = \\iota(b) \\) are both positive, then \\( n + m = \\iota(a + b) \\), so \\( n + m \\) is also positive.\n    \\item If \\( n = -\\iota(a) \\) and \\( m = -\\iota(b) \\) are both negative, then \\( n + m = -\\iota(a + b) \\), so \\( n + m \\) is also negative.\n  \\end{itemize}\n\n  \\SubProofOf{thm:def:integer_signum/product} Fix two integers \\( n \\) and \\( m \\).\n\n  \\begin{itemize}\n    \\item If either \\( n \\) or \\( m \\) is zero, the product \\( nm \\) is again zero, so\n    \\begin{equation*}\n      \\sgn(nm) = \\sgn(n) \\cdot \\sgn(m) = 0.\n    \\end{equation*}\n\n    \\item If both \\( n = \\iota(a) \\) and \\( m = \\iota(b) \\) are positive, then \\( nm = \\iota(ab) \\) is nonnegative. Furthermore, \\( nm \\) cannot be zero because \\( \\BbbZ \\) is an integral domain. Hence,\n    \\begin{equation*}\n      \\sgn(nm) = \\sgn(n) \\cdot \\sgn(m) = 1.\n    \\end{equation*}\n\n    \\item If \\( n = \\iota(a) \\) is positive and \\( m = -\\iota(b) \\) is negative, then \\( n(-m) = \\iota(ab) \\) is positive. Furthermore, \\( nm = -n(-m) = -\\iota(ab) \\), and hence \\( nm \\) is negative. Then\n    \\begin{equation*}\n      \\sgn(nm) = \\underbrace{\\sgn(n)}_1 \\cdot \\underbrace{\\sgn(m)}_{-1} = -1.\n    \\end{equation*}\n\n    The case where \\( n \\) is negative and \\( m \\) is positive follows from this one due to commutativity.\n\n    \\item If both \\( n = -\\iota(a) \\) and \\( m = -\\iota(b) \\) are negative, then \\( (-n)(-m) = \\iota(ab) \\) is positive. Furthermore, \\( nm = (-n)(-m) = -\\iota(ab) \\), and hence \\( nm \\) is positive.\n    \\begin{equation*}\n      \\sgn(nm) = \\underbrace{\\sgn(n)}_{-1} \\cdot \\underbrace{\\sgn(m)}_{-1} = 1.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\SubProofOf{thm:def:integer_signum/zero} This is actually a statement about group inverses because \\( 0 = -0 \\).\n\n  \\SubProofOf{thm:def:integer_signum/inverse} From \\fullref{thm:def:integer_signum/product} it follows that \\( \\sgn(-n) = \\sgn(-1) \\cdot \\sgn(n) = -\\sgn(n) \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:integer_ordering}\n  We extend the \\hyperref[def:natural_number_ordering]{natural number ordering} \\( \\leq_\\BbbN \\) to the \\hyperref[def:set_of_integers]{integers} \\( \\BbbZ \\) via the following truth table:\n  \\begin{center}\n    \\begin{tabular}{c c c}\n      \\( n \\) & \\( m \\) & \\( n \\leq m \\) \\\\\n      \\hline\n      nonnegative       & nonnegative & \\( n \\leq_\\BbbN m \\) \\\\\n      nonnegative       & negative    & \\( F \\) \\\\\n      negative          & nonnegative & \\( T \\) \\\\\n      negative          & negative    & \\( -m \\leq_\\BbbN -n \\)\n    \\end{tabular}\n  \\end{center}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:integer_ordering}\n  \\hyperref[def:integer_ordering]{Integer ordering} has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:integer_ordering/positive} \\( 0 \\leq n \\) if and only if \\( n \\) is positive.\n    \\thmitem{thm:def:integer_ordering/negative} \\( 0 \\geq n \\) if and only if \\( n \\) is negative.\n    \\thmitem{thm:def:integer_ordering/inverse} \\( n \\leq m \\) if and only if \\( -m \\leq -n \\).\n    \\thmitem{thm:def:integer_ordering/total} It is a \\hyperref[def:totally_ordered_set]{total order}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:integer_ordering/positive} Trivial.\n  \\SubProofOf{thm:def:integer_ordering/negative} Trivial.\n\n  \\SubProofOf{thm:def:integer_ordering/inverse} Let \\( n \\leq m \\).\n  \\begin{itemize}\n    \\item If \\( n \\) and \\( m \\) are both either nonnegative or negative, then \\( -m \\leq -n \\) by definition.\n    \\item If \\( n \\) is negative and \\( m \\) is not, then by \\fullref{thm:def:integer_signum/inverse} \\( -m \\) is negative and \\( -n \\) is not. Hence \\( -m \\leq -n \\).\n  \\end{itemize}\n\n  The converse direction of the proof is identical.\n\n  \\SubProofOf{thm:def:integer_ordering/total} The order \\( \\leq \\) is clearly defined for every pair of integers, so it remains to show that \\( \\leq \\) is a partial order.\n\n  \\SubProofOf*[def:binary_relation/reflexive]{reflexivity} If \\( n \\) is positive, then \\( n \\leq n \\) since \\( n \\leq_\\BbbN n \\). Otherwise, \\( n \\leq n \\) since \\( -n \\leq_\\BbbN -n \\).\n\n  \\SubProofOf*[def:binary_relation/antisymmetric]{antisymmetry} Suppose that \\( n \\leq m \\) and \\( m \\leq n \\).\n  \\begin{itemize}\n    \\item If \\( n \\) and \\( m \\) are both nonnegative, then \\( n = m \\) from the antisymmetry of the natural number ordering.\n    \\item If \\( n \\) and \\( m \\) are both negative, then \\( -n = -m \\) from the antisymmetry of the natural number ordering.\n    \\item If \\( n \\) is nonnegative and \\( m \\) is negative, we have \\( m \\leq n \\) but not \\( n \\leq m \\). This contradicts our assumption.\n    \\item If \\( n \\) is negative and \\( m \\) is nonnegative, we have \\( n \\leq m \\) but not \\( m \\leq n \\). This contradicts our assumption.\n  \\end{itemize}\n\n  \\SubProofOf*[def:binary_relation/transitive]{transitivity} Suppose that \\( n \\leq m \\) and \\( m \\leq k \\).\n  \\begin{itemize}\n    \\item If \\( n \\), \\( m \\) and \\( k \\) are nonnegative, then \\( n \\leq k \\) from the transitivity of the natural number ordering.\n    \\item If \\( n \\), \\( m \\) and \\( k \\) are negative, then \\( -k \\leq -n \\) and, by \\fullref{thm:def:integer_ordering/inverse}, \\( n \\leq k \\).\n    \\item If \\( n \\) is negative and \\( k \\) is nonnegative, then \\( n \\leq k \\) by definition.\n  \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\\label{def:integer_absolute_value}\n  We define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\abs{\\anon}: \\BbbZ \\to \\BbbN \\\\\n      &\\abs{n} \\coloneqq \\begin{cases}\n        n,  n \\geq 0 \\\\\n        -n, n < 0.\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  We call \\( \\abs{\\anon} \\) the \\term{absolute value function} in \\( \\BbbZ \\). It does satisfy the absolute value axioms from \\fullref{def:absolute_value}. A proof would be cyclic, however, since the real numbers rely on an extension of \\( \\abs{\\anon} \\).\n\\end{definition}\n\n\\begin{algorithm}[Integer division]\\label{alg:integer_division}\n  Fix two integers \\( n \\) and \\( m \\), and assume that \\( m \\) is nonzero. Define\n  \\begin{align*}\n    q &\\coloneqq \\sgn(nm) \\cdot \\max\\set{ y \\geq 0 \\colon y\\abs{m} < \\abs{n} } \\\\\n    r &\\coloneqq n - mq\n  \\end{align*}\n\n  Then \\( q \\) and \\( r \\) and the unique integers such that \\( \\abs{r} < \\abs{m} \\) and\n  \\begin{equation*}\n    n = mq + r.\n  \\end{equation*}\n\n  We will use the notation \\( \\quot(n, m) \\) and \\( \\rem(n, m) \\) from \\fullref{def:euclidean_domain}.\n\\end{algorithm}\n\\begin{proof}\n  \\SubProof{Proof of correctness} The case \\( n = 0 \\) is trivial so assume that \\( n \\neq 0 \\). We have\n  \\begin{center}\n    \\begin{tabular}{l | l | l}\n      \\( n \\)  & \\( m \\)  & \\( q \\) \\\\\n      positive & positive & \\( \\phantom{-}\\max\\set{ y \\geq 0 \\colon (n - m \\leq) \\thickspace y(+m) < +n } \\) \\\\\n      positive & negative & \\( -\\max\\set{ y \\geq 0 \\colon (n + m \\leq) \\thickspace y(-m) < +n } \\) \\\\\n      negative & positive & \\( -\\max\\set{ y \\geq 0 \\colon (m - n \\leq) \\thickspace y(+m) < -n } \\) \\\\\n      negative & negative & \\( \\phantom{-}\\max\\set{ y \\geq 0 \\colon (n - m \\leq) \\thickspace y(-m) < -n } \\)\n    \\end{tabular}\n  \\end{center}\n\n  It follows that \\( \\abs{n - mq} < \\abs{m} \\).\n\n  \\SubProof{Proof of uniqueness} Suppose that \\( n = mq + r = mq' + r' \\), where \\( \\abs{r} < \\abs{m} \\) and \\( \\abs{r'} < \\abs{m} \\). Then\n  \\begin{equation*}\n    m(q - q') = -(r - r').\n  \\end{equation*}\n\n  Thus, \\( m \\) divides \\( r - r' \\). Then \\( m \\) divides \\( r \\) and \\( r' \\) contradicting the assumption that \\( \\abs{r} < \\abs{m} \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:integers_are_euclidean_domain}\n  The \\hyperref[def:set_of_integers]{ring of integers} is an \\hyperref[def:euclidean_domain]{Euclidean domain} with division given by \\fullref{alg:integer_division} and degree function \\( \\abs{\\anon} \\).\n\\end{proposition}\n\\begin{proof}\n  By \\fullref{thm:def:integer_signum/entire}, \\( \\BbbZ \\) is an integral domain. The Euclidean domain structure is described by \\fullref{alg:integer_division}.\n\\end{proof}\n\n\\begin{remark}\\label{rem:integer_domain_chain}\\hfill\n  \\begin{itemize}\n    \\item By \\fullref{thm:integers_are_euclidean_domain}, \\( \\BbbZ \\) is a \\hyperref[def:euclidean_domain]{Euclidean domain}.\n    \\item By \\fullref{thm:def:euclidean_domain/pid}, \\( \\BbbZ \\) is a \\hyperref[def:principal_ideal_domain]{principal ideal domain}.\n    \\item By \\fullref{thm:def:principal_ideal_domain/ufd}, \\( \\BbbZ \\) is a \\hyperref[def:unique_factorization_domain]{unique factorization domain}.\n    \\item By \\fullref{thm:def:unique_factorization_domain/gcd}, \\( \\BbbZ \\) is a \\hyperref[def:gcd_domain]{GCD domain}.\n  \\end{itemize}\n\\end{remark}\n\n\\begin{remark}\\label{rem:integer_gcd}\n  We discuss in \\fullref{rem:choice_of_associates} and \\fullref{rem:lattice_of_principal_ideals} how, in general \\hyperref[def:gcd_domain]{GCD domain}, the \\hyperref[def:gcd_and_lcm]{greatest common divisors} are not unique.\n\n  The \\hyperref[def:gcd_and_lcm]{greatest common divisor} of is, by convention, \\hi{positive}. This leaves a canonical choice for both the greatest common divisor and the least common multiple. By \\fullref{thm:natural_number_divisibility_lattice}, the \\hyperref[thm:semiring_divisibility_order]{divisibility order} of positive integers is compatible with the usual \\hyperref[def:integer_ordering]{integer ordering}.\n\n  \\Fullref{alg:euclidean_algorithm} allows us to explicitly compute both GCDs and LCMs.\n\\end{remark}\n\n\\begin{definition}\\label{def:prime_number}\n  A \\term{prime number} is an integer greater than \\( 1 \\) whose only proper \\hyperref[def:divisibility]{divisor} is \\( 1 \\). Non-prime integers greater than \\( 1 \\) are called \\term{composite numbers}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:prime_numbers}\n  The definition of a prime number given in \\fullref{def:prime_number} is standard, however it seems quite inconsistent with \\fullref{subsec:integral_domains}.\n\n  First, \\fullref{subsec:integral_domains} actually defines \\hyperref[def:domain_divisibility/irreducible]{irreducible elements} rather than \\hyperref[def:domain_divisibility/prime]{prime elements} of the domain \\( \\BbbZ \\). Second, if \\( p \\) is a prime number, \\( -p \\) is also a prime number.\n\n  Fortunately, prime and irreducible elements coincide in \\hyperref[def:gcd_domain]{GCD domains} by \\fullref{thm:def:gcd_domain/irreducible_is_prime} and \\fullref{thm:def:gcd_domain/irreducible_is_prime}. Unfortunately, calling negative prime elements of \\( \\BbbZ \\) \\enquote{prime numbers} is not accepted.\n\n  Coprime integers are, fortunately, defined as in general GCD domains via \\fullref{def:coprime_elements}.\n\\end{remark}\n\n\\begin{lemma}[Euclid's lemma]\\label{thm:euclids_lemma}\n  If \\( p \\) is a \\hyperref[def:prime_number]{prime number}, then \\( p \\mid nm \\) implies \\( p \\mid n \\) or \\( p \\mid m \\).\n\\end{lemma}\n\\begin{proof}\n  Since \\( \\BbbZ \\) is a GCD domain, the lemma follows from \\fullref{thm:def:gcd_domain/irreducible_is_prime}.\n\\end{proof}\n\n\\begin{theorem}[Fundamental theorem of arithmetic]\\label{thm:fundamental_theorem_of_arithmetic}\n  Every integer greater than \\( 1 \\) can be \\hyperref[def:irreducible_factorization]{factored} into a product of \\hyperref[def:prime_number]{prime} powers.\n\\end{theorem}\n\\begin{proof}\n  We have discussed in \\fullref{rem:integer_domain_chain} that \\( \\BbbZ \\) is a unique factorization domain.\n\\end{proof}\n\n\\begin{definition}\\label{def:eulers_totient_function}\n  For any positive integer \\( n \\), denote by \\( \\varphi(n) \\) the number of strictly smaller than \\( n \\) positive integers that are \\hyperref[def:coprime_elements]{coprime} to \\( n \\). We call \\( \\varphi: \\BbbZ_{>0} \\to \\BbbZ_{\\geq 0} \\) \\term{Euler's totient function}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:eulers_totient_function}\n  \\hyperref[def:eulers_totient_function]{Euler's totient function} \\( \\varphi \\) has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:eulers_totient_function/one} \\( \\varphi(1) = 0 \\).\n    \\thmitem{thm:def:eulers_totient_function/prime} If \\( p \\) is \\hyperref[def:prime_number]{prime}, then \\( \\varphi(p) = p - 1 \\).\n    \\thmitem{thm:def:eulers_totient_function/zn} The \\hyperref[def:semiring]{multiplicative group} \\( \\BbbZ_n^\\times \\) of the ring \\hyperref[thm:ring_of_integers_modulo]{\\( \\BbbZ_n \\)} of integers modulo \\( n > 1 \\) has order \\( \\varphi(n) \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:eulers_totient_function/one} There are no positive integers smaller than \\( 1 \\).\n\n  \\SubProofOf{thm:def:eulers_totient_function/prime} Every positive integer smaller than \\( p \\) is coprime to \\( p \\), and there are exactly \\( p - 1 \\) positive integers smaller than \\( p \\) --- \\( 1, 2, \\ldots, p - 1 \\).\n\n  \\SubProofOf{thm:def:eulers_totient_function/zn} Follows from \\fullref{thm:multiplicative_group_of_integers_modulo}.\n\\end{proof}\n\n\\begin{theorem}[Euler's totient theorem]\\label{thm:eulers_totient_theorem}\n  For positive coprime integers \\( n \\) and \\( x \\), we have\n  \\begin{equation*}\n    x^{\\varphi(n)} \\cong 1 \\pmod n,\n  \\end{equation*}\n  where \\( \\varphi \\) is \\hyperref[def:eulers_totient_function]{Euler's totient function}.\n\\end{theorem}\n\\begin{proof}\n  This is vacuous for \\( n = 1 \\) since all integers are equal modulo \\( 1 \\).\n\n  Suppose that \\( n > 1 \\). First, use \\fullref{alg:integer_division} to obtain integers \\( q \\) and \\( y < n \\) such that\n  \\begin{equation*}\n    x = nq + y.\n  \\end{equation*}\n\n  Since \\( x \\) is, by assumption, coprime with \\( n \\), then \\( y \\) is also coprime with \\( n \\). Indeed, every common divisor \\( d \\) of \\( y \\) and \\( n \\) is also a common divisor \\( x \\), and the largest such possible value is \\( \\gcd(n, x) = 1 \\).\n\n  Now consider the \\hyperref[def:semiring]{multiplicative group} \\( \\BbbZ_n^\\times \\) of the ring \\hyperref[thm:ring_of_integers_modulo]{\\( \\BbbZ_n \\)} of integers modulo \\( n \\) and the \\hyperref[def:cyclic_group]{cyclic subgroup} \\( \\set{ 1, y, y^2, \\ldots } \\) (modulo \\( n \\)). It is necessarily finite as a subgroup of \\( \\BbbZ_n^\\times \\). Furthermore, by \\fullref{thm:lagranges_theorem_for_groups}, its order \\( k \\) divides the order of \\( \\BbbZ_n^\\times \\). By \\fullref{thm:def:eulers_totient_function/zn}, the order of \\( \\BbbZ_n^\\times \\) is \\( \\varphi(n) \\).\n\n  We have \\( y^k \\cong 1 \\pmod n \\) since \\( k \\) is the order of a cyclic group. If \\( \\varphi(n) = km \\), then\n  \\begin{equation*}\n    y^{\\varphi(n)}\n    =\n    y^{km}\n    \\reloset {\\eqref{eq:thm:magma_exponentiation_properties/repeated}} =\n    (y^k)^m\n    \\cong\n    1^m\n    \\pmod n.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{corollary}\\label{thm:division_modulo}\n  Given positive integers \\( n \\) and \\( m \\), we can apply \\fullref{alg:integer_division} to obtain \\( n = q \\varphi(m) + r \\), where \\( \\varphi \\) is \\hyperref[def:eulers_totient_function]{Euler's totient function}.\n\n  Then, for a positive integer \\( x \\) coprime to \\( m \\), we have\n  \\begin{equation*}\n    x^n \\cong x^r \\pmod m,\n  \\end{equation*}\n\\end{corollary}\n\\begin{proof}\n  By \\fullref{thm:eulers_totient_theorem}, \\( x^{\\varphi(m)} \\cong 1 \\pmod m \\). Then\n  \\begin{equation*}\n    x^n = (x^{\\varphi(m)})^q x^r \\cong x^r \\pmod m.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:division_modulo}\n  The integers \\( 9 \\) and \\( 10 \\) are coprime. We have \\( \\varphi(9) = 6 \\) and \\( 1000 = 166 \\cdot 6 + 4 \\). By \\fullref{thm:division_modulo},\n  \\begin{equation*}\n    9^{1000} \\cong 9^4 \\cong 6561 \\cong 1 \\pmod {10}.\n  \\end{equation*}\n\n  We can thus vastly simplify finding the last digit of the decimal representation of \\( 9^{1000} \\).\n\\end{example}\n\n\\begin{theorem}[Fermat's little theorem]\\label{thm:fermats_little_theorem}\n  For a \\hyperref[def:prime_number]{prime number} \\( p \\) and for any positive integer \\( x \\), we have\n  \\begin{equation*}\n    x^p \\cong x \\pmod p.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  If \\( p \\mid x \\), then both \\( x^p \\) and \\( x \\) and congruent to \\( 0 \\) modulo \\( p \\).\n\n  Otherwise, by \\fullref{thm:eulers_totient_theorem}, we have \\( x^{\\varphi(p) + 1} \\cong x \\pmod p \\), and by \\fullref{thm:def:eulers_totient_function/prime}, we have \\( \\varphi(p) + 1 = p \\).\n\\end{proof}\n", "meta": {"hexsha": "c1eab1e1daf170afa4353ab7036019a03372021c", "size": 20825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/integers.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/integers.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/integers.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": 56.7438692098, "max_line_length": 570, "alphanum_fraction": 0.649027611, "num_tokens": 7119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938799869521, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6834284780010496}}
{"text": "\n\\subsection{Exponential Decay}\\label{ex:decay-set-sample}\n\nTo demonstrate the qualitative differences in the solutions provided by the set-- and sample--based methods for a nonlinear problem, we consider an exponential decay problem with uncertain decay rate and initial condition (which are paired to form the 2-D vector $\\param$):\n$$\n\\begin{cases}\n  \\frac{\\partial u}{\\partial t} & = \\param_1 u(t), \\\\\n  u(0) &= \\param_2.\n\\end{cases}\n$$\n\nThe solution is described by\n\\begin{equation}\n  u(t;\\param) = u_0\\exp(\\param_1 t), \\; u_0 = \\param_2 ,\n\\end{equation}\n\nand a nominal value of $\\param = 0.5$ is used to simulate the system.\nWe take a single observation at $t=0.5$s and assume a uniform density with interval length $0.2$ centered at $u(1,0.5)$ to represent the uncertainty in the measurement equipment.\nWe assume a uniform ansatz / initial density over the unit domain.\nWe use $N=50$ parameter samples to establish a coarse solution in Figure~\\ref{fig:heatrod-sol-ex1}.\n\n\n\\begin{figure}\n\\begin{minipage}{.475\\textwidth}\n\\includegraphics[width=\\linewidth]{examples/fig_decay_q1/DecayModel--set_N50_em.png}\n\\end{minipage}\n\\begin{minipage}{.475\\textwidth}\n\\includegraphics[width=\\linewidth]{examples/fig_decay_q1/DecayModel--sample_N50_mc.png}\n\\end{minipage}\n\\caption{Observation taken at $t=1$s. The inverse image of the reference measure for set-based (left) and sample-based (right) solutions for $\\nsamps=50$ parameter samples.}\n\\label{fig:heatrod-sol-ex1}\n\\end{figure}\n\nThe decay rate $\\param_1$ shows little reduction in uncertainty overall.\nIf one were to look at marginals of the components of $\\param$, it would not appear as if much was learned.\nHowever, the relationship \\emph{between} these two quantities has very certainly been elucidated by the solution of the inverse problem.\nWhere once $\\pspace$ was a rectangular region, the set of possible parameters has been reduced to a diagonal band.\nThe sample-based approach, especially at this low sample size (density estimation in 2-D at $50$ samples is a stretch), has some visible downsides.\nIt does not capture the equivalence--class nature of the solution set the way the set--valued one does, which benefits from using $\\ndiscs=1$ (aligning with the choice of uniform observed density).\n\n\nWe address what would occur had we been able to observe earlier in time at $t=0.5$ by showing the associated solutions under the same experimental conditions in \\ref{fig:heatrod-sol-ex2}.\nThere is a marked reduction in uncertainty, as several regions of $\\pspace$ have been ruled out from consideration.\n\n\n\\begin{figure}\n\\begin{minipage}{.475\\textwidth}\n\\includegraphics[width=\\linewidth]{examples/fig_decay_q2/DecayModel--set_N50_em.png}\n\\end{minipage}\n\\begin{minipage}{.475\\textwidth}\n\\includegraphics[width=\\linewidth]{examples/fig_decay_q2/DecayModel--sample_N50_mc.png}\n\\end{minipage}\n\\caption{Observation taken at $t=0.5$s. The inverse image of the reference measure for set-based (left) and sample-based (right) solutions for $\\nsamps=50$ parameter samples.}\n\\label{fig:heatrod-sol-ex2}\n\\end{figure}\n\n\nObserving earlier in time helps especially in reducing the (marginal) values for the initial condition $\\param_2$, while the rate $\\param_1$ is still to some degree able to take any values in its original domain.\nBoth solution types suffer from discretization error, as evidenced by the break in the contour structure.\nBy comparison to \\ref{fig:heatrod-sol-ex1}, there is more more confidence in the solution (represented by the reduced support of the image).\n\nHowever, at $\\nsamps=50$, the sample--based approach struggles to assign uniform probability to different contour events.\nThis may suggest that in situations with very limited model evaluation budget and set-valued solutions involving uniform uncertainties in measurements, the set-valued approach may serve a useful purpose.\n", "meta": {"hexsha": "13acd452db08a57663b57b73d8594c78c929156c", "size": 3855, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/decay_set_vs_sample.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "ch02/decay_set_vs_sample.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "ch02/decay_set_vs_sample.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.234375, "max_line_length": 273, "alphanum_fraction": 0.7800259403, "num_tokens": 979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6834284744257327}}
{"text": "%\\nomenclature[]{HMM}{Hidden Markov Model}\n%\\note{Add italics in places}\n%\\note{Could discuss:\n%\\\\Background:\n%What HMMs are,\n%why they're useful in AI,\n%the different commonly used HMMs. \n%\\\\ Use in my research:\n%How the problem can naturally be described by a HMM,\n%Lead into discussion of how DBN is a more natural way to describe the problem and how it leads to efficient factorization of densities for state estimation}\n     \nHMMs appear frequently in AI literature as they provide an abstract framework to deal with stochastic processes, which themselves are pervasive in their use as a tool to model real-world phenomena. This section will outline what HMMs are and their use in literature describing target localisation algorithms. A general overview of HMMs and Markov Processes can be found in \\cite{Murphy1994DynamicLearning}, \\cite{Ghahramani2001AnNetworks}, \\cite{Bhattacharya2009StochasticApplications} and \\cite{papoulis02}, on which we base the following discussion.\n\n\\subsubsection{Markov Processes}\\label{subsubsec:MarkovProcesses}\nIt is instructive to understand what is meant by a stochastic process for some of the concepts mentioned in this thesis. A random process can be described as a family of random variables indexed by a set $\\tau$: $\\{X_t\\}_{t\\in\\tau}$ \\cite{Bhattacharya2009StochasticApplications}. Commonly in AI, stochastic processes model the evolution of a random system through \\textit{discrete} time steps: $\\tau$=$\\mathbb N$. Examples of phenomena that are frequently modelled by stochastic processes include the growth of a bacterial population and the movement of a gas molecule \\cite{Bhattacharya2009StochasticApplications}.\\par\n\nA first-order discrete-time Markov process is a stochastic process that describes a discrete-time stochastic process for which the first-order \\textit{Markov property} holds \\cite{Ghahramani2001AnNetworks}. The first-order Markov property states that the probability distribution of the n$_{th}$ random variable in the process is conditionally independent of all previous probability distributions in the sequence but the $n-1_{st}$: $P(X_t = x_t | X_{t-1} = x_{t-1}, X_{t-2} = x_{t-2}, ... , X_{1} = x_{1}) = P(X_t = x_t | X_{t-1} = x_{t-1})$ \\cite{Ghahramani2001AnNetworks}. This is often referred to as the memoryless property of Markov processes. In order to describe a Markov process, it is therefore necessary to describe what is known as the transition function between each pair of time-steps: $P(X_t = x_t | X_{t-1} = x_{t-1})$. A common assumption is that the rules that govern state transitions are time invariant, meaning that they can be specified generally for any given pair of time-steps. This assumption will be made for the subsequent discussion. If $X_t$ is a discrete random variable defined over $S$ states, the transition function can be described by a stochastic matrix T, where T$_{i,j}$ = $P(X_t = j | X_{t-1} = i)$: \n\n\\begin{center}\n{$\\displaystyle \\left({\\begin{matrix}T_{1,1}&T_{1,2}&\\dots &T_{1,j}&\\dots &T_{1,S}\\\\T_{2,1}&T_{2,2}&\\dots &T_{2,j}&\\dots &T_{2,S}\\\\\\vdots &\\vdots &\\ddots &\\vdots &\\ddots &\\vdots \\\\T_{i,1}&T_{i,2}&\\dots &T_{i,j}&\\dots &T_{i,S}\\\\\\vdots &\\vdots &\\ddots &\\vdots &\\ddots &\\vdots \\\\T_{S,1}&T_{S,2}&\\dots &T_{S,j}&\\dots &T_{S,S}\\\\\\end{matrix}}\\right)$}\n\\end{center}\n\\par\n\nSome obvious results are worth pointing out; as for any stochastic matrix, by the axioms of probability theory, the sum of conditional probabilities across each column sum to one: {$\\displaystyle \\sum _{j=1}^{S}T_{i,j}=1$} and the transition probabilities over $k$ time-steps can be described by the $k_{th}$ power of the transition matrix: ${(T^k)}_{i,j}$ = $P(X_{t+k} = j | X_{t} = i)$. \n\nIt also is possible to calculate the probability of the process experiencing a sequence of states from time-steps 1 as far as $t$, using the chain rule of probability and the Markov property:\n$P(X_{1:t}) = P(X_1, X_2, ..., X_t) = P(X_1)\\times P(X_2 | X_1)\\times P(X_3 | X_2, X_1) \\times ... \\times P(X_t | X_{t-1}, X_{t-2}, ... , X_1) = P(X_1) \\times \\prod_{i=2}^{t}{P(X_i | x_{i-1})}$. Marginalization over variables in this sequence allows the calculation of many useful quantities.\n\\par\n\nMarkov processes can described by graphical models. For example Figure \\ref{fig:markov-processes} displays a graphical representation of first and second order Markov processes, where a directed arrow between nodes represents a directional dependence between those nodes.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.8\\linewidth]{Chapters/BackgroundKnowledgeAndRelatedWork/MultiAgentTargetDetectionBackground/Figs/MarkovProcesses/MarkovProcesses.png}\n    \\caption{A graphical model describing first and second order Markov processes}\n    \\label{fig:markov-processes}\n\\end{figure}\n\n\\subsubsection{HMM Description}\\label{subsubsec:HMMDesc}\nHidden Markov Models (HMMs) are models that build on the Markov Process model, which describes the evolution of a random system in the language of probability theory. HMMs assume that the system being modelled can be described by a Markov process, but that the states of this process are unobservable \\cite{Ghahramani2001AnNetworks}. This means that it is not possible to determine the state of the system exactly at any given point in time. However, it is possible to make an observation of a random variable that is related to the hidden state which yields information about the hidden state. A graphical representation of a HMM is shown in Figure \\ref{fig:hmm},\n\\begin{figure}[]\n    \\centering\n    \\includegraphics[width=0.8\\linewidth]{Chapters/BackgroundKnowledgeAndRelatedWork/MultiAgentTargetDetectionBackground/Figs/HMMs/HMMGraphicalModel.png}\n    \\caption{A graphical model of a HMM}\n    \\label{fig:hmm}\n\\end{figure} where the Markov Process is shown by the variables $X_i$ and the observation variables are shown by variables $E_i$. A HMM can be specified by a triple, $\\lambda$ = $(T, O, \\pi)$, where $T$ is the stochastic transition matrix, $\\pi$ is the initial distribution $P(X_1)$ and O describes the conditional probability of an observation given that the system is in a certain state: $O(E_i, X_i) = P(E_{i} | X_{i})$ \\cite{Rabiner1989ARecognition}. Taken together, it is then possible to specify the joint distribution of the hidden state variables and the evidence variables, analogous to the Markov Process: \n$\nP(X_{1:t}, E_{1:t}) = P(X_1, X_2, ..., X_t, E_1, E_2, ..., E_t) = P(X_1) \\times P(E_1 | X_1) \\times\n\\prod_{i=2}^{t}{(P(X_i | x_{i-1}) \\times P(E_t | X_t))}.\n$ Given this representation, it is then possible to answer questions identified in \\cite{Rabiner1989ARecognition} and \\cite{Murphy1994DynamicLearning}:\n\\begin{itemize}\n\n    \\item Given the HMM, $\\lambda$, what is the probability of occurrence of a particular observation sequence, $P(E_{1:t} | \\lambda)$?\n    \n    \\item Given a sequence of observations $(E_1, E_2, ..., E_n)$, what is the most likely sequence of hidden states that led to these observations? i.e. find \\[\\argmax_{X_{1:t}} P(X_{1:t} | E_{1:t})\\]\n    \n    \\item Determine the parameters of $T$ and $O$, given a training set of observations, i.e. find the solution to \\[\\argmax_{\\lambda} P(E_{1:t} | \\lambda)\\]\n    \n    \\item \\textit{Filtering}: What is the current distribution of the hidden state given all previous evidence (\"belief state\") of the environment at time t: $P(X_t | E_{1:t})$?\n    \n    \\item \\textit{Prediction}: What is the distribution of the hidden state in the future, given all evidence to date: $P(X_{t+k} | E_{1:t})$, for some k$>$0?\n    \n    \\item \\textit{Smoothing}: What is the distribution of a past state given all observations up to the current point in time: $P(X_k | E_{1:t})$, for some 0 $\\leq$ k $<$ t?\n    \n\\end{itemize}\n\\par\n\n%Might include a subsection on a taxonomy of commonly used HMMs.\n\n%\\subsubsection{Summary}\\label{subsubsec:Summary}\n%In summary, HMMs can be used to abstractly describe the evolution of a stochastic system. They have been used to achieve state of the art performance in problems such as speech recognition \\cite{ChiuSTATE-OF-THE-ARTMODELS} and ... . An comprehensive overview of extensions to the vanilla HMM can be found at \\cite{Murphy1994DynamicLearning}.", "meta": {"hexsha": "ce4650ddd311103ca0fe8bad642e06141b9c443f", "size": 8205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/BackgroundKnowledgeAndRelatedWork/MultiAgentTargetDetectionBackground/HMM.tex", "max_stars_repo_name": "DavidLSmyth/ResearchMScThesis", "max_stars_repo_head_hexsha": "754d975535e0da9a8e99cf31b651021698155c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/BackgroundKnowledgeAndRelatedWork/MultiAgentTargetDetectionBackground/HMM.tex", "max_issues_repo_name": "DavidLSmyth/ResearchMScThesis", "max_issues_repo_head_hexsha": "754d975535e0da9a8e99cf31b651021698155c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-18T11:59:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-18T11:59:42.000Z", "max_forks_repo_path": "Chapters/BackgroundKnowledgeAndRelatedWork/MultiAgentTargetDetectionBackground/HMM.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": 115.5633802817, "max_line_length": 1242, "alphanum_fraction": 0.749055454, "num_tokens": 2279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6833606697953173}}
{"text": "\\section{Asymptotics and Recurrences}\n\n% MATH REVIEW SUBSECTION |-----------------------------------------------------|\n\n\\subsection{Math Review}\n\nBefore we talk about asymptotics and recurrences, we quickly review the\nlogarithmic function $\\log$.\n\n\\begin{definition*}\nWe define the \\textbf{logarithm} to be the opposite of exponentiation, i.e. we\nsay that $\\log_b(x) = y$ exactly if $b^y = x$. For example $\\log_2(64) = 6$,\nsince $64 = 2^6$. \n\\end{definition*}\n\nHere's a couple useful properties of the $\\log$ that you will use in this\nsection extensively.\n\n\\begin{enumerate}[(1)]\n\n\\item Product $\\to$ Summation: $\\log_b(xy) = \\log_b(x) + \\log_b(y)$.\n\n\\begin{proof}\n\nBy definition, we know that $b^{\\log_b(xy)} = xy$. However, also notice that $x\n= b^{\\log_b(x)}$ and $y = b^{\\log_b(y)} \\implies xy = b^{\\log_b(x)}b^{\\log_b(y)}\n= b^{\\log_b(x) + \\log_b(y)} \\implies b^{\\log_b(xy)} = b^{\\log_b(x) + \\log_b(y)}$.\n\n\\end{proof}\n\n\\item Quotient $\\to$ Subtraction: $\\log_b \\left( \\frac{x}{y} \\right) = \\log_b(x)\n- \\log_b(y)$. \n\n\\begin{proof}\nThis can be seen using the previous identity, and just taking $y \\mapsto\n\\frac{1}{y}$, and noticing that $\\frac{1}{y} = \\frac{1}{b^{\\log_b(y)}} =\nb^{-\\log_b(y)}$.\n\\end{proof}\n\n\\item Power $\\to$ Scalar Multiplication: $\\log_b(x^p) = p\\log_b(x)$.\n\n\\begin{proof}\n\nBy defintion:\n\n$$\nx = b^{\\log_b(x)} \\implies x^p = \\left(b^{\\log_b(x)}\\right)^p = b^{p\\log_b(x)} \n$$\n\nTherefore it must be true that $\\log_b(x^p) = p\\log_b(x)$.\n\n\\end{proof}\n\n\\item Change of Base: $\\log_b(x) = \\frac{\\log_k(x)}{\\log_k(b)}$.\n\n\\begin{proof}\n\nStarting from $x = b^{\\log_b(x)}$, we can take $\\log_k$ of both sides to\nrecieve:\n\n$$\n\\log_k(x) = \\log_k b^{\\log_b(x)} = \\log_b(x) \\log_k(b)\n$$\n\nTherefore, dividing through by $\\log_k(b)$ gives us the desired identity.\n\n\\end{proof}\n\n\\end{enumerate}\n\n% ASYMPTOTICS SUBSECTION |-----------------------------------------------------|\n\n\\subsection{Asymptotics Analysis}\n\nIn the analysis of algorithms, one of our goals is to classify growth of the\nruntime and storage complexity of functions. To do so, it's in our interest to\nexamine the limiting behavior of functions, i.e. when our input becomes large\nwhat does our function do. To this end we introduce Big O notation.\n\n\\subsubsection{Big O notation}\n\nBig O notation exists to describe the limiting behavior of a function, and us\nComputer Scientists use it to classify algorithms in terms of their input size\n$n$. Due to this, from this point onwards all functions we define are\nnon-negative. \n\nWe give both the informal and formal definition of a couple different\nuseful characterizations. Let $f,g : \\R \\to \\R$ be two functions.\n\n\\begin{itemize}\n\n\\item Upper bound: $\\mathcal{O}$.\n\n\\begin{definition*}\nInformally, we say that $f(x) = \\mathcal{O}(g(x))$ if $ f(x) \\leq cg(x)$, $c$\nsome constant, for sufficiently large $x$. \n\nFormally, $f(x) = \\mathcal{O}(g(x))$ iff:\n\n$$\n\\limsup_{x \\to \\infty} \\abs{\\frac{f(x)}{g(x)}} < \\infty\n$$\n\nFor example, $n^2 = \\mathcal{O}(n^2)$ and $n^2 = \\mathcal{O}(n^5)$ but $n^2 \\neq\n\\mathcal{O}(n)$. To highlight the sufficiently large $x$ portion, notice that it\nis true that $n^2 = \\mathcal{O}(n^3 - n^2)$ ($n^3 - n^2 > n^2, \\forall n > 2$.)\n\n\\end{definition*}\n\n\\item Lower Bound: $\\Omega$.\n\n\\begin{definition*}\n\nInformally, we say that $f(x) = \\Omega(g(x))$ if and only if $g(x) =\n\\mathcal{O}(f(x))$, or that $f(x) \\geq cg(x)$.\n\nFormally $f(x) = \\Omega(g(x)) \\iff \\liminf_{n \\to \\infty}\n\\abs{\\frac{f(n)}{g(n)}} > 0$.\n\n\\end{definition*}\n\n\\item Tight bound: $\\theta$.\n\n\\begin{definition*}\n\nWe say that $f(x) = \\theta(g(x))$ if $f(x) = \\mathcal{O}(g(x))$ and $f(x) =\n\\Omega(g(x))$. Another way to say this is that $\\exists c \\in \\R$ such that\n$\\frac{1}{c} g(x) \\leq f(x) \\leq cg(x)$, for sufficiently large enough $x$.\n\nFormally we must have that:\n\n$$\n\\limsup_{x \\to \\infty} \\abs{\\frac{f(x)}{g(x)}} \\in \\R_{> 0}\n$$\n\nTo those that care, notice that having $f(x) = \\mathcal{O}(g(x))$ and\n$\\Omega(g(x)) \\centernot \\implies \\lim_{x \\to \\infty} \\abs{\\frac{f(x)}{g(x)}}$ exists.\nInstead $\\liminf$ and $\\limsup$ may converge to different values.\n\nSo for example, $n^2 = \\theta(n^2)$ but $n^2 \\neq \\theta(n)$ and $\\neq\n\\theta(n^3)$.\n\n\\end{definition*}\n\n\\end{itemize}\n\n\\subsubsection{Properties of Big O}\n\nThere's a couple of useful properties of Big O that are good to know. Let $f_1 =\n\\theta(g_1)$ and $f_2 = \\theta(g_2)$.\n\n\\begin{enumerate}[(1)]\n\n\\item Product: $f_1f_2 = \\theta(g_1g_2)$. In addition $f \\theta(g) =\n\\theta(fg)$.\n\n\\item Sum: $f_1 + f_2 = \\theta(g_1 + g_2)$. In particular if $f_1 =\n\\mathcal{O}(g)$ and $f_2 = \\mathcal{O}(g)$ then $f_1+f_2 = \\mathcal{O}(g)$.\n\n\\item Scalar multiplication: $\\theta(kg) = \\theta(g)$ supposing $k \\neq 0$. In\naddition $kf_1 = \\theta(g_1)$.\n\n\\item Summation $\\to$ maximization.: $\\theta(g_1 + g_2) = \\theta(\\max(g_1,\ng_2))$. \n\n\\end{enumerate}\n\n\\subsubsection{Time Complexity Comparison}\n\nTypically for problems where we want to compare which function grows faster\nasymptotically, we really want to see at large $x$, which one dominates. Our\nmain strategy to do this, is to reduce these functions down to functions which\nare more easily compared, which I call the time complexity classes. See the time\ncomplexity chart in the figures section for a good table of a commmon few which\nyou should remember. \n\nTake for examples:\n\n\\begin{enumerate}[(1)]\n\n\\item $2^n$ versus $n^2$.\n\n\\begin{proof}[Solution]\n\nIt's clear that $2^n$ is exponential, which grows faster than $n^2$ which is\npolynomial.\n\n\\end{proof}\n\n\\item $n^{\\log(n)}$ versus $n^{100}$.\n\n\\begin{proof}[Solution]\n\nThe left hand function is somewhere above polynomial due to the power being an\nincreasing function of $n$. Therefore, it grows faster than $n^{100}$.\n\n\\end{proof}\n\n\\item $n^{1/\\log_2(n)}$ versus $2$.\n\nThese are strange to compare, since we aren't sure what class the left hand\nfunction falls in. To try to fit it to something we understand, we remember that\nthe logarithm takes powers to scalar multiplcation, so then we notice:\n\n$$\n\\log_2(n^{1/\\log_2(n)}) = \\frac{1}{\\log_2(n)} \\log_2(n) = 1\n$$\n\nBut also $\\log_2(2) = 1$. Therefore we find that these functions are actually\nequal in terms of asymptotic growth.\n\n\\end{enumerate}\n\n% RANDOMIZED FUNCTION SUBSECTION |---------------------------------------------|\n\n\\subsection{Algorithm $\\to$ Recurrence}\n\nHere we want to examine how to turn recursive code into reucurrences\ncharacterizing their properties. We do this by example.\n\n\\subsubsection{Fibbonacci Sequence}\n\n\\begin{algorithmic}[1]\n\\Procedure{F}{$n$}\\Comment{$a_1 = 1, a_2 = 1, a_n = a_{n-1}+a_{n-2}$}\n\t\\If{$n \\leq 2$}\n\t\t\\State Return $1$\n\t\\Else\n\t\t\\State Return $F(n-1)+F(n-2)$\n\t\\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\nSuppose we want to characterize the runtime of the above algorithm using a\nrecurrence equation. The idea is that we count the work per level, and add it.\nLetting $G(n)$ characterize the runtime of $F(n)$.\n\n\\begin{algorithmic}[1]\n\\Procedure{F}{$n$}\n\t\\If{$n \\leq 2$} \\Comment{$\\theta(1)$}\n\t\t\\State Return $1$ \\Comment{$\\theta(1)$}\n\t\\Else \\Comment{$\\theta(1)$}\n\t\t\\State Return $F(n-1)+F(n-2)$ \\Comment{$G(n-1)+G(n-2) + \\theta(1)$}\n\t\\EndIf \\Comment{$\\theta(1)$}\n\\EndProcedure\n\\end{algorithmic}\n\nNotice that $\\theta(1)$ summed a constant number of times is still $\\theta(1)$,\ntherefore we have:\n\n$$\nG(n) = \\begin{cases}\n\\theta(1) & n \\leq 2 \\\\\n\\theta(1) + G(n-1) + G(n-2) & \\text{otherwise}\n\\end{cases}\n$$\n\nFor characterizing things that aren't work, i.e. how many times the $-1$\noperation happens in the above code, we can do a similar process. Let $H(n)$\ncharacterize the number of $-1$ operations in $F(n)$. Then:\n\n\\begin{algorithmic}[1]\n\\Procedure{F}{$n$}\n\t\\If{$n \\leq 2$} \\Comment{$0$}\n\t\t\\State Return $1$ \\Comment{$0$}\n\t\\Else \\Comment{$0$}\n\t\t\\State Return $F(n-1)+F(n-2)$ \\Comment{$H(n-1)+H(n-2) + 1$}\n\t\\EndIf \\Comment{$0$}\n\\EndProcedure\n\\end{algorithmic}\n\nTherefore:\n\n$$\nH(n) = \\begin{cases}\n0 & n \\leq 2 \\\\\n1 + H(n-1) + H(n-2) & \\text{otherwise}\n\\end{cases}\n$$\n\n\\subsubsection{Merge Sort}\n\nLet $F(n)$ characterize the work of Merge Sort on an array of length $n$. Then:\n\n\\begin{algorithmic}[1]\n\\Procedure{Mergesort}{$A$ : Array}\n\t\\State Let $n = len(A)$.\n\t\\If{$n = 1$} \\Comment{$\\theta(1)$}\n\t\t\\State Return $A$ \\Comment{$\\theta(1)$}\n\t\\EndIf \\Comment{$\\theta(1)$}\n\t\\State $B \\gets A[1... \\lfloor n/2 \\rfloor]$ \\Comment{$\\theta(1)$}\n\t\\State $C \\gets A[\\lceil n/2 \\rceil ... n]$ \\Comment{$\\theta(1)$}\n\t\\State $Mergesort(B), Mergesort(C)$ \\Comment{$F(\\lfloor n/2 \\rfloor) +\n\tF(\\lceil n/2 \\rceil)$}\n\t\\State Return $Merge(B,C)$ \\Comment{$\\theta(n)$} \n\\EndProcedure\n\\end{algorithmic}\n\nTherefore we have:\n\n$$\nF(n) = \\begin{cases}\n\\theta(1) & n = 1 \\\\\n\\theta(n) + F(\\lfloor n/2 \\rfloor) + F(\\lceil n/2 \\rceil) & \\text{otherwise}\n\\end{cases}\n$$\n\nSimilarily we can do this for $H(n)$ characterizing storage constraints, but\nI'll leave that as exercise.\n\n\\subsubsection{Randomized Algorithms}\n\nA classic Siegel question is to characterize various facets of the randomized\nalgorithm:\n\n\\begin{algorithmic}[1]\n\\Procedure{Rand}{$n$}\n\t\\If{$n \\leq 1$} \n\t\t\\State Return 0 \n\t\\EndIf \n\t\\State Let $x \\gets 1, 2$ or $3$ with probabilities $1/2, 1/3, 1/6$\n\trespectively.\n\t\\If{$x = 1$}\n\t\t\\State Return $2Rand(n)$\n\t\\ElsIf{$x = 2$}\n\t\t\\State Return $7Rand(n-1) + 12Rand(n-2)$\n\t\\Else\n\t\t\\State Return $nRand(n-1)$\n\t\\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\nDefine function $F, G, H$ which characterize runtime, exact value returned, and\nnumber of times $x \\gets 3$ respectively. The trick to characterizing the above,\nis simply to take whatever happens inside of an if statement and multiply it by\nthe probability of the event occuring. So:\n\n\\begin{align*}\nF(n) & = \\begin{cases}\n\\theta(1) & n \\leq 1 \\\\\n\\theta(1) + \\frac{1}{2} (\\theta(1) + F(n)) + \\frac{1}{3} (\\theta(1) + F(n-1) +\nF(n-2)) + \\frac{1}{6}( \\theta(1) + F(n-1) ) & \\text{otherwise}\n\\end{cases} \\\\\nG(n) & = \\begin{cases}\n0 & n \\leq 1 \\\\\n\\frac{1}{2} (2H(n)) + \\frac{1}{3} (7H(n-1) + 12H(n-2)) + \\frac{1}{6}( nH(n-1) )\n& \\text{otherwise}\n\\end{cases} \\\\\nH(n) & = \\begin{cases}\n0 & n \\leq 1 \\\\\n\\frac{1}{2} (0 + H(n)) + \\frac{1}{3} (0 + H(n-1) + H(n-2)) + \\frac{1}{6}(1 +\nH(n-1) ) & \\text{otherwise}\n\\end{cases} \\\\\n\\end{align*}\n\nThis always appears on the exam.\n\n% Solving RECURRENCES SUBSECTION |---------------------------------------------|\n\n\\subsection{Solving Recurrences}\n\nOk, so now that we know how to characterize certain aspects of recursive code\nusing recurrences, one might ask, how do we solve recurrences? The idea stems\nbehind something called the tree method. For example, consider the recurrence\nequation:\n\n$$\nf(n) = \\begin{cases}\n1 & n = 1 \\\\\nn + 2f(n/3) & \\text{otherwise}\n\\end{cases}\n$$\n\nHere we call $n$ the work function, $3$ the decay rate, and $2$ the branching\nfactor.\n\nWhat we do to solve this is \\textit{unroll} the recursive term over and over\nagain. We represent each unrolling as a new level of the tree, so it may look\nlike:\n\n\\Tree\n[.$n$\n\t[.$n/3$ \n\t\t[.$n/9$ $\\vdots$ $\\vdots$ ] \n\t\t[.$n/9$ $\\vdots$ $\\vdots$ ] \n\t]\n\t[.$n/3$ \n\t\t[.$n/9$ $\\vdots$ $\\vdots$ ] \n\t\t[.$n/9$ $\\vdots$ $\\vdots$ ] \n\t]\n]\n\nThe top level looks like $n + 2f(n/3)$, but then we unroll $f(n/3)$ to $n/3 +\n2(n/9)$, which is our second level. To then figure out what our summation totals\nto, we sum accross the level, and then downward. In the above example, the first\nlevel totals to $n$, the second to $(2/3)n$, the third to $(4/9)n$, etc. In\nfact, we will find that in general the $j$th level will sum to\n$\\frac{2^j}{3^j}n$; this is guarenteed by the unrolling. But what about the leaf\nlevel?\n\nIn general, we have to examine the leaf level seperately, because the recurrence\ndefines something different for it. Here, our recurrence says that each leaf has\ncost $1$. Looking at our tree, we see that at each level the number of vertices\ndoubles (powers of branching factor), therefore at the leaf level $k$ we must\nhave $2^k$ leaves. Each costs 1, therefore the contribution from the leaf level\nis $2^k$.\n\nTherefore our final\ntotal actually looks something like $n + \\frac{2}{3} n + \\frac{2^2}{3^n} n +\n\\dots + \\frac{2^{k-1}}{3^{k-1}}n + 2^k$, for some stopping point $k$. Let's find\n$k$.\n\n$k$ is determined by the point we can \\textit{unroll} no longer, i.e. the decay\nrate has been applied sufficiently enough times such that we get down to our\nbase case, $1$. In other words, we want to solve for $k$ where:\n\n$$\n\\frac{n}{3^k} = 1 \\implies n = 3^k \\implies k = \\log_3(n)\n$$\n\nSince we choose $n$ a power of $3$, we find that $k$ is an integer like we\nwanted it to be. Then, we can write our final answer as:\n\n$$\nf(n) = n \\left(1 + \\frac{2}{3} + \\frac{2^2}{3} + \\dots +\n\\left(\\frac{2}{3}\\right)^{\\log_3(n)-1} \\right) + 2^{\\log_3(n)}\n$$\n\nWe make one note here about the leaf level. Notice that we can say:\n\n$$\n2^{\\log_3(n)} = \\frac{n}{n} 2^{\\log_3(n)} = n\n\\frac{2^{\\log_3(n)}}{3^{\\log_3(n)}} = n \\left( \\frac{2}{3} \\right)^{\\log_3(n)}\n$$\n\nThis looks exactly like our pattern! What's happening? What we've discovered is\nthat our leaf level \\textit{obeys} our recurrence, and I claim that this is in\ngeneral true if the work at the level matches the work function. For example,\nthe work function $w(n)$ is $n$ here. The base case is at $n = 1$, therefore\nlooking at $w(1)$ we see it's $1$. \\textit{This matches our base case}, i.e.\nthat at $n = 1, f(n) = 1$. Whenever this happens, it's unecessary to compute the\nleaf level seperately, and we can pull it into our summation. Rough reasoning\nis that it's modeled perfectly by the recurrence. If we had it that when $n =\n1, f(n) = 5$, we could not do this. Therefore we can write:\n\n$$\nf(n) = n \\left(1 + \\frac{2}{3} + \\frac{2^2}{3} + \\dots +\n\\left(\\frac{2}{3}\\right)^{\\log_3(n)} \\right) \n$$\n\nLet's solve a couple different types of common recurrences you might see.\n\n\\subsubsection{Basic Recurrences}\n\n\\begin{enumerate}[(1)]\n\n\\item Solve the recurrence:\n\n$$\nA(n) = \\begin{cases}\n1 & n = 1 \\\\\nn + 2A(n/2) & \\text{otherwise}\n\\end{cases}\n$$\n\n\\begin{proof}[Solution]\n\nFor this we have work function $f(n) = n$, decay rate $2$ and branching factor\n$2$. The tree we draw looks like:\n\n\\Tree\n[.$n$\n\t[.$n/2$ \n\t\t[.$n/4$ $\\vdots$ $\\vdots$ ] \n\t\t[.$n/4$ $\\vdots$ $\\vdots$ ] \n\t]\n\t[.$n/2$ \n\t\t[.$n/4$ $\\vdots$ $\\vdots$ ] \n\t\t[.$n/4$ $\\vdots$ $\\vdots$ ] \n\t]\n]\n\nSumming across, we come across the surprising fact that each level sums to $n$.\nThis is roughly because the decay rate and the branching factor cancel each\nother out. In general, we find this to be true when $f(\\delta(n)) = \\beta$ where\n$\\beta$ is the branching factor and $\\delta$ is the decay rate as a function of\n$n$ (can you see why?). Ok, so now considering the tree, we can ask how many\nterms are there? Recall this is solving for $\\frac{n}{2^k} = 1 \\implies k =\n\\log_2(n)$. This tells us that there must be $\\log_2(n) + 1$ levels ($k$ tells\nus $k$th level, but count starting from $0$). Finally we notice that $f(1) =\nA(1)$, which implies that we don't have to do the leaf level seperately.\nTherefore our solution is: \n\n$$\nA(n) = n + n + \\dots + n = n( \\text{Number of levels}) = n(log_2(n)+1)\n$$\n\n\\end{proof}\n\n\\item Solve the reucrrence:\n\n$$\nB(n) = \\begin{cases}\n5, & n = 1 \\\\\nn + 2B(n/2), & \\text{otherwise}\n\\end{cases}\n$$\n\n\\begin{proof}[Solution]\nThe difference between this one at the last one is the leaf level. Here we have\nthat $B(1) \\neq f(1)$, which implies we need to compute the leaf level\nseperately. There are $2^{\\log_2(n)} = n$ leaves, and each has work $5$, which\nimplies that the leaf level cost is $5n$. Therefore we can write our answer as:\n$$\nB(n) = nlog_2(n) + 5n\n$$\n\\end{proof}\n\n\\subsubsection{Changing the Leaf Level}\n\nWhat if we have a recurrence like:\n\n$$\nC(n) = \\begin{cases}\n8, & n = 8 \\\\\nn + 3C(n/2), \\text{otherwise} \n\\end{cases}\n$$\n\nIn this case what's strange is that we've changed when we enter the leaf level.\nThe tree method, however, handles this perfectly. Before we asked when\n$\\frac{n}{b^k} = 1$ where $b$ was the decay rate. Here the base case is when $n\n= 8$, so we instead ask $\\frac{n}{2^k} = 8 = 2^3 \\implies k = \\log_2(n) - 3$.\nThen the problem is solved in the same exact manner as in the basic recurrences.\n\n\\subsubsection{Multiple Decay Rates}\n\nWhat happens if we have a recurrence like:\n\n$$\nD(n) = \\begin{cases}\n1, & n = 1 \\\\\nn + D(n/2) + D(n/3), & \\text{otherwise}\n\\end{cases}\n$$\n\nWhat we lose is the guarentee that all leaves live on the same level. In fact,\nthe end of the \\textit{unrolling} will come sooner for the harsher decay rate,\nand later for the kinder decay rate. In $D(n)$, we see that $\\frac{n}{2^k} \\to_k\n1$ slower than $\\frac{n}{2^k} \\to_k 1$. To resolve this problem, what we do is\napproximate; we say that our leaf level $k$ lives somewhere between the leaf\nlevel defined by $2$ and $3$.\n\nIf we follow the decay rate $2$ all of the way down, we know that our leaf level\nis $k_2 = \\log_2(n)$. If we follow $3$, similarily we will recieve $k_3 =\n\\log_3(n)$. We say that our \"leaf level\" lives between these two, or $\\log_3(n)\n\\leq k \\leq \\log_2(n)$.\n\nThen to solve our problem we have the tree:\n\n\\Tree\n[.$n$\n\t[.$n/2$ \n\t\t[.$n/4$ $\\vdots$ $\\vdots$ ] \n\t\t[.$n/6$ $\\vdots$ $\\vdots$ ] \n\t]\n\t[.$n/3$ \n\t\t[.$n/6$ $\\vdots$ $\\vdots$ ] \n\t\t[.$n/9$ $\\vdots$ $\\vdots$ ] \n\t]\n]\n\nWe find that our summation looks like:\n\n$$\nD(n) \\approx n\\left[ 1 + \\frac{5}{6} + \\frac{5^2}{6^2} + \\dots +\n\\left(\\frac{5}{6}\\right)^k \\right],\\quad  \\log_3(n) \\leq k \\leq \\log_2(n)\n$$\n\n\\subsubsection{Strange Decay Rates}\n\nWhat happens if we have a recurrence like:\n\n$$\nE(n) = \\begin{cases}\n1, & n = 1 \\\\\n1 + 2E(\\delta(n)), & \\text{otherwise}\n\\end{cases}\n$$\n\nLots of people get stuck on this, but I claim that our tree method handles this\nperfectly. The tree itself looks like:\n\n\\Tree\n[.$1$\n\t[.$1$ \n\t\t[.$1$ $\\vdots$ $\\vdots$ ] \n\t\t[.$1$ $\\vdots$ $\\vdots$ ] \n\t]\n\t[.$1$ \n\t\t[.$1$ $\\vdots$ $\\vdots$ ] \n\t\t[.$1$ $\\vdots$ $\\vdots$ ] \n\t]\n]\n\nThe real question is, where is the leaf level? Before we asked for decay rate\n$\\delta(n) = \\frac{n}{b}$, how many times do we have to apply it to get down to\nthe base case. This formulated as $\\frac{n}{b^k} = 1 \\implies k = \\log_b(n)$.\nOur question in general is for what $k$ does $\\delta^k(n) = 1$, where $k$ isn't\na power but repeated function compositions. For example if $\\delta(n) = n-1$,\nthen we would be asking $n - k(-1) = 1 \\implies k = n-1$. \n\n\\end{enumerate}\n", "meta": {"hexsha": "1925aa56cf592f436e750b9738a02bff0b832c3f", "size": 18213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/src/src/asymrec.tex", "max_stars_repo_name": "abhijit-c/AlgorithmsTopicReview", "max_stars_repo_head_hexsha": "cc22f5f19a99271a1a784af09df8de4f8c4bcdcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/src/src/asymrec.tex", "max_issues_repo_name": "abhijit-c/AlgorithmsTopicReview", "max_issues_repo_head_hexsha": "cc22f5f19a99271a1a784af09df8de4f8c4bcdcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/src/src/asymrec.tex", "max_forks_repo_name": "abhijit-c/AlgorithmsTopicReview", "max_forks_repo_head_hexsha": "cc22f5f19a99271a1a784af09df8de4f8c4bcdcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7112561175, "max_line_length": 86, "alphanum_fraction": 0.6500301982, "num_tokens": 6316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8791467770088163, "lm_q1q2_score": 0.6833606677211301}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 5.1 Eigenvalues and Eigenvectors of a Symmetric Matrix\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nCompute the N eigenvalues and eigenvectors of an N $\\times $ N symmetric matrix $A$.\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 , EVAL}($\\geq N)$%\n{\\bf ,\\newline\nWORK}($\\geq N)$\n\n\\item[INTEGER]  \\ {\\bf LDA, N, IERR}\n\\end{description}\n\nAssign values to A(,), LDA, and N.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SSYMQL(A, LDA, N, EVAL,\\\\\nWORK, IERR)\\\\\n\\end{tabular}}\n\\end{center}\n\nResults are returned in A(,) and EVAL().\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] On entry the locations on and below the diagonal of\nthis array must contain the lower-triangular elements of the N $\\times $ N\nsymmetric matrix $A$. On return the eigenvectors of $A$ will be stored as\ncolumn vectors in the array A(,). These N eigenvectors will be mutually\northogonal and of unit Euclidean length. The eigenvector stored in column\nJ will be associated with the eigenvalue stored in EVAL(J).\n\n\\item[LDA]  \\ [in] Dimension of the first subscript of the array A(,). Require\nLDA $\\geq $ N.\n\n\\item[N]  \\ [in] Order of the symmetric matrix $A$. N $\\geq 1.$\n\n\\item[EVAL()]  \\ [out] Array in which the N eigenvalues of $A$ will be stored\nby the subroutine. The eigenvalues will be sorted with the algebraically\nsmallest eigenvalue first.\n\n\\item[WORK()]  \\ [scratch] An array of at least N locations used as\ntemporary space.\n\n\\item[IERR]  \\ [out] On exit this is set to~0 if the QL algorithm converges,\notherwise see Section E.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange SSYMQL to DSYMQL, and the REAL type statement to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nThe following symmetric matrix $A$ is\ngiven on page~55 of~\\cite{Gregory:1969:ACM}.\n\\begin{equation*}\nA=\\left[\n\\begin{array}{rrrr}\n5 & 4 & 1 & 1 \\\\\n4 & 5 & 1 & 1 \\\\\n1 & 1 & 4 & 2 \\\\\n1 & 1 & 2 & 4\n\\end{array}\n\\right]\n\\end{equation*}\nThe eigenvalues of this matrix are 1, 2, 5, and 10. Unnormalized\neigenvectors associated with these eigenvalues are (1, -1, 0, 0),\n(0, 0, -1, 1), (-1, -1, 2, 2), and (2, 2, 1, 1), respectively.\n\nThe code in DRSSYMQL, given below, computes the eigenvalues and eigenvectors\nof this matrix. Output from this program is given in the file ODSSYMQL.\n\nBefore the call to SSYMQL, the matrix is saved in an array ASAV() in order\nto compute the relative residual matrix $D$ defined as%\n\\begin{equation*}\nD=\\left( AW-W\\Lambda \\right) /\\gamma\n\\end{equation*}\nwhere $W$ is the matrix whose columns are the computed eigenvectors\nof $A$, $\\Lambda $ is the diagonal matrix of eigenvalues,\nand $\\gamma $ is the maximum-row-sum norm of $A$.\n\nRecall that if ${\\bf v}$ is an eigenvector, then so is $\\alpha {\\bf\nv}$ for any nonzero scalar $\\alpha$.  More generally, if an\neigenvalue, $\\lambda$, of a symmetric matrix occurs with multiplicity\n$k$, there will be an associated  $k$-dimensional subspace in which\nevery vector is an eigenvector for $\\lambda$.  This subroutine will\nreturn eigenvectors constituting an orthogonal basis for such an\neigenspace.\n\n\\subsection{Functional Description}\n\nThe implicit-shift QL algorithm implemented in this subroutine is based on\nthe Algol procedure given in \\cite{Dubrelle:1968:IQR}, pp.~337--383.  The\ncode combines slightly modified EISPACK routines TRED2, and IMTQL2, see\n\\cite{Smith:1974:MER}.  Modifications made are minor changes to convert\nthe code to take advantage of Fortran~77; they should not affect results.\nTRED2 uses Householder orthogonal similarity transformations to transform\nthe matrix $A$ to tridiagonal form.  IMTQL2 uses the QL algorithm with\nimplicit shifts to reduce the off-diagonal elements of the tridiagonal\nmatrix to a magnitude of approximately the last bit of the largest element\nof $A$.\n\nThe resulting diagonal elements are the eigenvalues of $A$. The matrix of\neigenvectors is computed as the product of the orthogonal transformation\nmatrices used in transforming $A$ first to tridiagonal form and then to\n(almost) diagonal form.\n\nThe eigenvalues are sorted in nondecreasing algebraic order and the\neigenvectors are permuted as necessary to correspond to the ordered\neigenvalues.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIf the QL algorithm fails to converge in 30~iterations on the $J^{th}$\neigenvalue the subroutine sets IERR $= J.$ In this case $J-1$ eigenvalues\nand eigenvectors are computed correctly but the eigenvalues are not ordered.\nIf N $\\leq $ 0 on entry, IERR is set to $-$1.  In either case an error\nmessage is printed using IERM1 of Chapter 19.2 with an error level of 0,\nbefore the return.\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} \\\\\nDSYMQL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDIMQL, DSYMQL, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSSYMQL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SIMQL, SSYMQL}\\\\\n\\end{tabular}\n\nConverted by: F. T. Krogh, JPL, October~1991.\n\n\n\\begcode\n\n\\medskip\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSSYMQL}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{ssymql}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSSYMQL}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{ssymql}}\n\n\\end{document}\n", "meta": {"hexsha": "ad2a30286ed0a2dc161a983214da1281e76ccd84", "size": 5782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch05-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/ch05-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/ch05-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": 34.622754491, "max_line_length": 98, "alphanum_fraction": 0.743860256, "num_tokens": 1757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430604060731, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6833567865533936}}
{"text": "\n\\chapter{Numeric algorithms}\n\\Label{cha:numeric}\n\nThe algorithms that we considered so far only \\emph{compared}, \\emph{read} or\n\\emph{copied} values in sequences.\nIn this chapter, we consider so-called \\emph{numeric} algorithms of the \n\\cxx Standard Library \\cite[\\S 29.8]{cxx-17-draft} that use arithmetic\noperations on \\valuetype to\ncombine the elements of sequences.\n\n\\begin{listing}[hbt]\n\\begin{center}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{lstlisting}[style=acsl-block]\n    #define VALUE_TYPE_MAX  INT_MAX \n    #define VALUE_TYPE_MIN  INT_MIN\n\\end{lstlisting}\n\\end{minipage}\n\\end{center}\n\\vspace*{-0.5cm}\n\\caption{\\Label{lst:value-type-limits}Limits of \\valuetype}\n\\end{listing}\n\nIn order to refer to potential arithmetic overflows we introduce the\ntwo constants shown in Listing~\\ref{lst:value-type-limits}\nwhich refer to the numeric limits of \\valuetype \n(see also \\S\\ref{sec:types}).\n\nWe consider the following algorithms.\n\n\\begin{itemize}\n\n\\item \\iotai \nwrites sequentially increasing values into a range\n(\\S\\ref{sec:iotai})\n \n\\item \\accumulate \ncomputes the sum of the elements in a range\n(\\S\\ref{sec:accumulate})\n\n\\item \\innerproduct \ncomputes the inner product of two ranges\n(\\S\\ref{sec:innerproduct})\n\n\\item \\partialsum \ncomputes the sequence of partial sums of a range\n(\\S\\ref{sec:partialsum})\n\n\\item \\adjacentdifference \ncomputes the differences of adjacent elements in a range \n(\\S\\ref{sec:adjacentdifference})\n\n\\item\nFinally, in \\S\\ref{sec:partialsuminv} we show that under\nappropriate preconditions the algorithms \\partialsum and\n\\adjacentdifference are inverse to each other.\n\n\\end{itemize}\n\nThe formal specifications of these algorithms raise new questions.\nIn particular, we now have to deal with arithmetic overflows in \\valuetype.\n\n\\clearpage\n\n\\input{numeric/iota}\n\\input{numeric/accumulate}\n\\input{numeric/inner_product}\n\\input{numeric/partial_sum}\n\\input{numeric/adjacent_difference}\n\\input{numeric/numeric_inverse}\n\n", "meta": {"hexsha": "d4e7f3a219fcedbff8cc4f89f30eb34040d9feab", "size": 1944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/numeric-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/numeric/numeric-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/numeric/numeric-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": 26.6301369863, "max_line_length": 77, "alphanum_fraction": 0.7777777778, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.6833567642918731}}
{"text": "%\\newpage\n\\section{Nonlinear classifiable sets}\nIn the section, we will extend the linearly separable sets to the nonlinear case. \nA natural extension is like what the kernel method does in SVM for binary case. We will introduce the so-called \nfeature mapping.\n\n%Thus, we have the following natural extension for linearly separable by using feature mapping and original definition of linearly separable.\n\n\\begin{definition}[nonlinearly separable sets]\n\tThese data sets $A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$ are called nonlinearly separable, if there exist\n\ta feature space $\\mathbb{R}^{\\tilde d}$ and a smooth (if it has derivatives of all orders) feature mapping \n\t\\begin{equation}\\label{key}\n\t\\varphi: \\mathbb{R}^d \\mapsto \\mathbb{R}^{\\tilde d}\n\t\\end{equation}\n\tsuch that\n\t\\begin{equation}\\label{key}\n\t\\tilde A_i := \\varphi(A_i) = \\{ \\tilde x ~|~ \\tilde x = \\varphi(x), x \\in A_i \\}, \\quad i = 1, 2, \\dots, k,\n\t\\end{equation}\n\tare linearly separable.\n\\end{definition}\n\n\\begin{remark}$ $\\\\\n\t\\begin{enumerate}\n\t\t\\item This definition is  consistent with the definition of linearly separable as we can just take $\\tilde d = d$ and $\\varphi = {\\rm id}$ if $A_1, A_2, \\cdots, A_k$ are already linearly separable.\n\t\t\\item The kernel method in SVM is mainly based on this idea for binary case (k=2) where they use kernel functions to approximate $\\varphi(x)$.\n\t\t\\item Most commonly used deep learning models are related to softmax mappings which means we can interpret these deep learning models as the approximation for feature mapping $\\varphi$.\n\t\\end{enumerate}\t\n\\end{remark}\n\n\n\\begin{theorem}\n\t$A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$ are nonlinearly separable  is equivalent to that there  \n\t exists a smooth classification function \n\t\\begin{equation}\\label{key}\n\t\\psi: \\mathbb{R}^d \\mapsto \\mathbb{R}^{k}\n\t\\end{equation}\n\tsuch that for all $1\\leq i \\leq k$ and $ j \\neq i$\n\t\\begin{equation}\\label{key}\n\t\\psi_i (x) > \\psi_j (x), \\quad \\forall x \\in A_i.\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n\tOn the one hand, it is easy to see that if $A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$ are nonlinearly separable, we can take \n\t\\begin{equation}\\label{key}\n\t\\psi(x) = \\bm p(\\varphi(x); \\theta),\n\t\\end{equation}\t\n\twhere $\\bm p(\\varphi(x); \\theta)$ is the softmax function for linearly separable sets $\\varphi(A_i)$ for $i=1,2,\\cdots,k$.\n\t\n\tOn the other hand, let assume that $\\psi$ is the smooth classification functions for $A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$. \n\tWe can take $\\varphi(x) = \\psi(x)$ and then\n\t\\begin{equation}\\label{key}\n\t\\varphi(A_1), \\varphi(A_2), \\cdots, \\varphi(A_k) \\subset \\mathbb{R}^k \\quad ( \\tilde d = k),\n\t\\end{equation}\n\twill be linearly separable. Recall the definition of softmax mapping in Definition \\ref{softmax}, if we take $\\theta = (I, 0)$ in softmax mapping $\\bm p(x;\\theta)$, \n\tthen the monotonicity of $e^x$ shows that for all $i = 1:k$ and $ j \\neq i$\n\t\\begin{equation}\\label{key}\n\t\\bm p_i ( \\varphi(x);\\theta) = \\frac{e^{\\psi_i(x)}}{\\sum_{i=1}^k e^{\\psi_i(x)}} > \\frac{e^{\\psi_j(x)}}{\\sum_{i=1}^k e^{\\psi_i(x)}} = \\bm p_j ( \\varphi(x);\\theta) , \\quad \\forall x \\in A_i.\n\t\\end{equation}\n\t\n\\end{proof}\n\n\nSimilar to linearly separable sets, we have the next lemma for $k=2$.\n\\begin{lemma}$A_1$ and $A_2 \\subset \\mathbb{R}^d$ are nonlinearly separable  is equivalent that there  \n\texists a function $\\varphi: \\mathbb{R}^d \\mapsto \\mathbb{R}$ such that\n\t\\begin{equation}\\label{NonlinearBinary}\n\t\\varphi(x) > 0 \\quad \\forall x \\in A_1 \\quad \\text{and} \\quad \t\\varphi(x) < 0 \\quad \\forall x \\in A_2.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\nOn the one hand, based the equivalence of nonlinearly separable sets, there exists $\\psi_1(x)$ and $\\psi_2(x)$ such that \nfor all $i = 1:2$ and $ j \\neq i$\n\\begin{equation}\\label{key}\n\\psi_i (x) > \\psi_j (x), \\quad \\forall x \\in A_i.\n\\end{equation}\nThen, we can just take \n\\begin{equation}\\label{key}\n\\varphi(x) = \\psi_1 (x) - \\psi_2 (x).\n\\end{equation}\n\nOn the other hand, if there exist $\\varphi(x)$ satisfies (\\ref{NonlinearBinary}), then we can construct $\\psi_1(x)$ and $\\psi_2(x)$ as\n\\begin{equation}\\label{key}\n\\psi_1(x) =  \\frac{1}{2}\\varphi(x) \\quad \\text{and}\\quad \n\\psi_2(x) = -\\frac{1}{2}\\varphi(x).\n\\end{equation}\n\\end{proof}\n\n\n%\\begin{definition}[nonlinearly separable]\n%\tThese data sets $A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$ are called nonlinearly separable, if there exist\n%\ta infinitely differentiable classification function \n%\t\\begin{equation}\\label{key}\n%\t\\psi: \\mathbb{R}^d \\mapsto \\mathbb{R}^{k}\n%\t\\end{equation}\n%\tsuch that for all $i = 1:k$ and $ j \\neq i$\n%\t\\begin{equation}\\label{key}\n%\t\\psi_i (x) > \\psi_j (x), \\quad \\forall x \\in A_i.\n%\t\\end{equation}\n%\\end{definition}\n\n\\begin{remark}\n%This definition is consistent with the original definition of linearly separable. \n%If $A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$ are linearly separable, then there exists a $\\theta$\n%and softmax mapping $\\bm p(x; \\theta)$ such that for $i = 1:k$ and $ j \\neq i$\n%\\begin{equation}\\label{key}\n%\\bm p_i (x;\\theta) > \\bm p_j (x;\\theta), \\quad \\forall x \\in A_i.\n%\\end{equation}\n%Thus, $A_1, A_2, \\cdots, A_k$ are also nonlinearly separable as we can take $\\psi(x) = \\bm p(x;\\theta)$.\nHere the only assumption is that for all $i = 1:k$ and $ j \\neq i$, we have $\\psi_i (x) > \\psi_j (x)$, $\\forall x \\in A_i$ for nonlinearly separable. We do not assume that $\\psi_i (x) \\ge 0$ or $\\displaystyle\\sum_{i=1}^k \\psi_i (x) = 1$, which means that \n$$\\psi(x) = \\begin{pmatrix}\n\\psi_1 (x), &\\psi_2 (x), &\\cdots, &\\psi_k (x)\n\\end{pmatrix}^T$$ \nis not a discrete probability distribution over all k classes. \n\\end{remark}\n\n\nThe previous theorem shows that the softmax function is not so crucial in nonlinearly separable case. Combined with deep learning models, we have the \nfollowing understanding about what deep learning models.\n\\begin{enumerate}\n\t\\item If  the classification model is followed with a softmax, then it is approximating the feature mapping $\\varphi: \\mathbb{R}^d \\mapsto \\mathbb{R}^{\\tilde d}$.\n\t\\item If the classification model dose not followed by a softmax, then it is approximating $\\psi: \\mathbb{R}^d \\mapsto \\mathbb{R}^{k}$ directly.\n\\end{enumerate}\n \n \n \\begin{example}\n \tConsider $k=2$ and \n\t$$\n\tA_1 \\subset \\{ (x_1, x_2) | x_1^2 + x_2^2 < 1\\}, \\quad A_2 \\subset  \\{(x_1, x_2) | x_1^2 + x_2^2 > 1\\},\n\t$$\n\tthen we have the following nonlinear\n \t feature mapping:\n \t \\begin{equation*}\n \t \\adjustbox{valign=c}{\\includegraphics[width=.25\\textheight,height =0.4\\textheight]{figures/nonlinear2sets.png}} \\xrightarrow[\\text{feature map}]{\\varphi(x,y) = x_1^2 + x_2^2} \n \t \\adjustbox{valign=c}{\\includegraphics[width=.25\\textheight]{figures/nonlinear2sets1D.png}}\n \t \\end{equation*}\n \\end{example}\n\n\n\nHere we have the following comparison between linear and nonlinear models from the viewpoint of\nloss functions:\n\n\\begin{description}\n\\item[Linear case (Logistic regression):] \n$$\nL_{\\lambda }(\\theta) = \\sum_{j=1}^N \\ell (y_j, p(x_j; \\theta)) + \\lambda R(\\|\\theta\\|),\n$$\nas defined in \\eqref{eq:logisticlambda}.\n\\item[Nonlinear case: ]\n$$\nL_{\\lambda }(\\theta) = \\sum_{j=1}^N \\ell (y_j, p( \\varphi(x_j; \\theta_1); \\theta_2)) + \\lambda R(\\|\\theta\\|).\n$$\n\\end{description}\nHere $p(x; \\theta) = {\\rm softmax}(Wx + b)$ where $\\theta = (W,b)$,\nand $\\theta = (\\theta_1, \\theta_2)$ for the nonlinear case.\nFor both cases, $\\displaystyle \\ell(q, p) = \\sum_{i=1}^k - q_i \\log p_i$  represents the cross-entropy, and $\\lambda R(\\|\\theta\\|)$ is the  regularization term.\n%\\begin{remark}We have the following remarks.\n%\\begin{enumerate}\n%\t\\item $\\ell(q, p) = \\sum_{i=1}^k - q_i \\log p_i \\leftrightarrow$  cross-entropy \n%\t\\item $p(x; \\theta) = {\\rm softmax}(Wx + b)$ where $\\theta = (W,b)$\n%\t\\item $\\theta = (\\theta_1, \\theta_2)$ for nonlinear case\n%\t\\item $\\lambda R(\\|\\theta\\|)$ $\\leftrightarrow$  regularization term\n%\\end{enumerate}\n%\\end{remark}\n\nIn general, we have the following popular nonlinear models for $\\varphi(x;\\theta)$:\n\\begin{enumerate}\n\t\\item Polynomials.\n\t\\item Piecewise polynomials (finite element method).\n\t\\item Kernel functions in SVM, see in Section \\ref{sec:SVM}.\n\t\\item Deep neural networks.\n\\end{enumerate}\n \n \n \n \n\n\\endinput\n\nBased on the theorem of partition of unit, we may also have the next definition for \nnonlinear classifiable.\n\\begin{definition}[nonlinearly separable via partition of unit]\n\tThese data sets $A_1, A_2, \\cdots, A_k \\subset \\mathbb{R}^d$ are called nonlinearly separable, \n\tif there exist smooth\n\t\\begin{equation}\\label{key}\n\t\\varphi_i: \\mathbb{R}^d \\mapsto [0, 1], \\quad i = 1, 2, \\cdots, k,\n\t\\end{equation}\n\tsuch that\n\t\\begin{equation}\\label{key}\n\t\\varphi_i(x) = 1, x \\in A_i  \\text{ and } \\varphi_i(0) = 1, x \\in A_j,    \\text{ for } i, j= 1, 2, \\cdots, k \\text{ but } j \\neq i,\n\t\\end{equation}\n\tand \n\t\\begin{equation}\\label{key}\n\t\\sum_{i=1}^k \\varphi_i(x) = 1, \\quad \\forall x \\in \\mathbb{R}^d.\n\t\\end{equation}\n\tare linearly separable.\n\\end{definition}\n\n\\begin{remark}\n\tFor these next observations for definition of nonlinear separable via partition of unit.\n\t\\begin{enumerate}\n\t\t\\item Nonlinearly separable via partition of unit is a special case of nonlinear separable via feature mapping as\n\t\twe can always choose $\\tilde d = k$ and\n\t\t\\begin{equation}\\label{key}\n\t\t\\varphi(x) = \\begin{pmatrix}\n\t\t\\varphi_1(x) \\\\\n\t\t\\varphi_2(x) \\\\\n\t\t\\vdots \\\\\n\t\t\\varphi_k(x)\n\t\t\\end{pmatrix}.\n\t\t\\end{equation}\n\t\tThen it is easy to verify that $\\{\\varphi(A_i)\\}_{i=1}^k$ are linearly separable.\n\t\t\\item Based on the properties of partition of unit, we can prove that if $A_i$ are\n\t\tfinite sets, then there must exist the partition of unit which makes them must be nonlinearly separable.\n%\t\t\\item \n\t\\end{enumerate}\n\\end{remark}\n\n\\subsection{Decision boundary}", "meta": {"hexsha": "1e6462f20151455a43633b7ce3f13fcf52924b51", "size": 9708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/NonlinearClassifiable.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/NonlinearClassifiable.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/NonlinearClassifiable.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.92760181, "max_line_length": 255, "alphanum_fraction": 0.6909765142, "num_tokens": 3371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.6832910867114359}}
{"text": "\\section{Skeletonization}\n\n\\noindent\n\\textbf{Volume Downsampling}\nWe downsample the segmentation data to a resolution of $30$ nm in each direction. \nThe skeletonization algorithm that we use takes as a parameter the minimum distance between joints in the skeleton~\\cite{zhao2014automatic}.\nWhen we downsample, we also reduce this minimum distance by the same rate.\nWe find that this produces expressive skeletons at a fraction of the computational cost. \nTable~\\ref{table:skeleton} shows statistics comparing the skeletonization algorithm on 200 randomly chosen labels.\n\n\\begin{table}\n\t\\scriptsize\n\t\\begin{center}\n\t\t\\begin{tabular}{c c c c c} \\hline\n\t\t\t& \\textbf{Average Time} &  \\textbf{Skeleton Length} & \\textbf{No. Branches} & \\textbf{No. Endpoints} \\\\ \\hline\n\t\t\tFull Resolution & 16.35s & 1,352,157nm & 9,858 & 1,068 \\\\\n\t\t\tDownsampled & 0.56s & 1,671,138nm & 9,359  & 1,824 \\\\ \\hline\n\t\t\\end{tabular}\n\t\\caption{The results of the skeletonization algorithm on both the full resolution and the downsampled data. Downsampling the data provides expressive skeletons at a fraction of the computational cost.}\n\t\\label{table:skeleton}\n\t\\end{center}\n\\end{table}\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\linewidth]{./figures/node-threshold.png}\n\t\t\\caption{The number of remaining nodes after increasing the threshold (blue) and the number of voxels excluded as a percent of the total volume (green).}\n\t\t\\label{fig:node-pruning}\n\t\\end{center}\n\\end{figure}\n\n\\noindent\n\\textbf{Node Generation}\nWe remove all nodes from the graph corresponding to labels with fewer than $t_{seg}$ voxels.\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", "meta": {"hexsha": "c6119a7abddff498b59c2d7d8d61105366d4b4e8", "size": 2340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/quals2018/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/quals2018/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/quals2018/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": 54.4186046512, "max_line_length": 202, "alphanum_fraction": 0.7696581197, "num_tokens": 621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6832910691133995}}
{"text": "\\section{Surface Area}{}{}\\label{sec:Surface Area}\nAnother geometric question that arises naturally is: ``What is the\nsurface area of a volume?'' For example, what is the surface area of a\nsphere? More advanced techniques are required to approach this\nquestion in general, but we can compute the areas of some volumes\ngenerated by revolution.\n\nAs usual, the question is: How might we approximate the surface area?\nFor a surface obtained by rotating a curve around an axis, we can take\na polygonal approximation to the curve, as in the last section, and\nrotate it around the same axis. This gives a surface composed of many\n``truncated cones''; a truncated cone is called a \\dfont{frustum} of a cone. \nFigure~\\ref{fig:approximating surface area} illustrates this approximation. \n\n\\figure[H]\n%\\texonly\n\\vbox{\\centerline{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <0.25truecm,0.25truecm>\n\\setplotarea x from 0 to 30, y from -15 to 15\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/surface_area_approx.eps}}} at 30 0\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/surface_area.eps}}} at 0 0\n\\endpicture}}\n\\caption{\\label{fig:approximating surface area}\nApproximating a surface (left) by portions of cones (right).}\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:approximating surface area}\n%\\htmlfigure{Integration_applications-surface_area_approximation.html}\n%\\htmlonly\n%\\begincaption\n%Approximating a surface (left) by portions of cones (right).\n%You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/jmol_surface_area_approximation/surface_area_approximation.sws\">Sage\n%worksheet</a>\n%for this plot and upload it to your own sage account.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\nSo we need to be able to compute the area of a frustum of a cone.\nSince the frustum can be formed by removing a small cone from the top\nof a larger one, we can compute the desired area if we know the\nsurface area of a cone.\nSuppose a right circular cone has base radius $r$ and slant height\n$h$. If we cut the cone from the vertex to the base circle and\nflatten it out, we obtain a sector of a circle with radius $h$ and arc\nlength $2\\pi r$, as in Figure~\\ref{fig:area of cone}. The angle at\nthe center, in radians, is then $2\\pi r/h$, and the area of the cone\nis equal to the area of the sector of the circle. Let $A$ be the area\nof the sector; since the area of the entire circle is $\\ds \\pi h^2$, we\nhave\n$${A\\over\\pi h^2}={2\\pi r/h\\over 2\\pi}$$\n$$A = \\pi r h.$$\n\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1truecm,1truecm> point at 0 0\n\\setplotarea x from -1.5 to 1.5, y from -1 to 5.3\n\\ellipticalarc  axes ratio 3:1  180 degrees from -1.5 0 center at 0 0\n\\plot 1.5 0 0 5 -1.5 0 /\n\\putrule from -1.5 0 to 0 0\n\\put {$r$} [t] <0pt,-3pt> at -0.75 0\n\\put {$h$} [bl] <2pt,2pt> at 0.75 2.5 \n\\setdashes\n\\ellipticalarc  axes ratio 3:1  180 degrees from 1.5 0 center at 0 0\n\\setsolid\n\\setcoordinatesystem units <1truecm,1truecm> point at -4 0\n\\circulararc 104 degrees from 5.22 0 center at 0 0\n\\circulararc 104 degrees from 1 0 center at 0 0\n\\plot 5.22 0 0 0 -1.26 5.065 /\n\\put {$h$} [t] <0pt,-3pt> at 2.61 0\n\\put {$2\\pi r$} [bl] <2pt,2pt> at 3.69 3.69  \n\\put {$2\\pi r/h$} [bl] <2pt,2pt> at 0.71 0.71\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:area of cone}\n%\\htmlfigure{Integration_applications-area_of_cone.html}\n\\caption{\\label{fig:area of cone}\nThe area of a cone.}\n%\\endcaption\n\\endfigure\n\nNow suppose we have a frustum of a cone with slant height $h$ and\nradii $\\ds r_0$ and $\\ds r_1$, as in Figure~\\xrefn{fig:frustum}. The area of\nthe entire cone is $\\ds \\pi r_1(h_0+h)$, and the area of the small cone is\n$\\ds \\pi r_0 h_0$; thus, the area of the frustum is $\\ds \\pi r_1(h_0+h)-\\pi\nr_0 h_0=\\pi((r_1-r_0)h_0+r_1h)$. By similar triangles, \n$${h_0\\over r_0}={h_0+h\\over r_1}.$$\nWith a bit of algebra this becomes $\\ds (r_1-r_0)h_0= r_0h$; substitution\ninto the area gives\n$$\n  \\pi((r_1-r_0)h_0+r_1h)=\\pi(r_0h+r_1h)=\\pi h(r_0+r_1)=2\\pi\n  {r_0+r_1\\over2} h = 2\\pi r h.\n$$\nThe final form is particularly easy to remember, with $r$ equal to the\naverage of $\\ds r_0$ and $\\ds r_1$, as it is also the formula for the area of\na cylinder. (Think of a cylinder of radius $r$ and height $h$ as the\nfrustum of a cone of infinite height.)\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1truecm,1truecm> point at 0 0\n\\setplotarea x from -1.5 to 1.5, y from -1 to 5\n\\ellipticalarc  axes ratio 3:1  180 degrees from -1.5 0 center at 0 0\n\\plot 1.5 0 0 5 -1.5 0 /\n\\putrule from -1.5 0 to 0 0\n\\put {$r_1$} [t] <0pt,-3pt> at -0.75 0\n\\put {$h_0$} [bl] <2pt,2pt> at 0.45 3.5 \n\\ellipticalarc  axes ratio 3:1  180 degrees from -0.9 2 center at 0 2\n\\putrule from -0.9 2 to 0 2\n\\put {$r_0$} [b] <0pt,3pt> at -0.45 2\n\\put {$h$} [bl] <2pt,2pt> at 1.2 1\n\\setdashes\n\\ellipticalarc  axes ratio 3:1  180 degrees from 1.5 0 center at 0 0\n\\ellipticalarc  axes ratio 3:1  110 degrees from 0.9 2 center at 0 2\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:frustum}\n%\\htmlfigure{Integration_applications-area_of_frustum.html}\n\\caption\n{\\label{fig:frustum}\nThe area of a frustum.}\n%\\endcaption\n\\endfigure\n\nNow we are ready to approximate the area of a surface of\nrevolution. On one subinterval, the situation is as shown in\nFigure~\\ref{fig:surface subinterval}. When the line joining two\npoints on the curve is rotated around the $x$-axis, it forms a frustum\nof a cone. The area is\n$$\n  2\\pi r h= 2\\pi {f(x_i)+f(x_{i+1})\\over2}\n    \\sqrt{1+(f'(t_i))^2}\\,\\Delta x.\n$$\nHere\n$\\ds \\sqrt{1+(f'(t_i))^2}\\,\\Delta x$ is the length of the line segment, \nas we found in the previous section. Assuming $f$ is a continuous\nfunction, there must be some $\\ds x_i^*$ in $\\ds [x_i,x_{i+1}]$\nsuch that\n$\\ds (f(x_i)+f(x_{i+1}))/2 = f(x_i^*)$, so\nthe approximation for the\nsurface area is\n$$\\sum_{i=0}^{n-1} 2\\pi f(x_i^*)\\sqrt{1+(f'(t_i))^2}\\,\\Delta x.$$\nThis is not quite the sort of sum we have seen before, as it contains\ntwo different values in the interval $\\ds [x_i,x_{i+1}]$, namely\n$\\ds x_i^*$ and $\\ds t_i$. Nevertheless, using more advanced techniques\nthan we have available here, it turns out that\n$$\\lim_{n\\to\\infty} \n\\sum_{i=0}^{n-1} 2\\pi f(x_i^*)\\sqrt{1+(f'(t_i))^2}\\,\\Delta x=\n\\int_a^b 2\\pi f(x)\\sqrt{1+(f'(x))^2}\\,dx$$ \nis the surface area we seek. (Roughly speaking, this is because while\n$\\ds x_i^*$ and $\\ds t_i$ are distinct values in $\\ds[x_i,x_{i+1}]$,\nthey get closer and closer to each other as the length of the interval\nshrinks.) \n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1.3truecm,1.3truecm> point at 0 0\n\\setplotarea x from 0 to 5, y from 0 to 3\n\\axis left /\n\\axis bottom ticks short withvalues {$x_i$}\n  {$x_i^*$} {$x_{i+1}$} / at 2.5 3 4 / /\n\\plot 2.5 1.5 4 2.5 /\n\\setquadratic\n\\plot 2.5 1.5 3 2 4 2.5 /\n\\put {$(x_i,f(x_i))$} [r] <-3pt,0pt> at 2.5 1.5\n\\put {$(x_{i+1},f(x_{i+1}))$} [l] <3pt,0pt> at 4 2.5\n%\\putrule from 3.25 0 to 3.25 2\n\\setdashes <2pt>\n\\putrule from 3 0 to 3 2\n\\putrule from 3 2 to 3.25 2\n\\setdashes\n\\putrule from 2.5 0 to 2.5 1.5\n\\putrule from 4 0 to 4 2.5\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:surface subinterval}\n%\\htmlfigure{Integration_applications-surface_area_one_interval.html}\n\\caption{\\label{fig:surface subinterval}\nOne subinterval.}\n\\endfigure\n\n\\begin{example}{Surface Area of a Sphere}{Surface Area of a Sphere}\\label{Surface Area of a Sphere}\nCompute the surface area of a sphere of radius $r$.\n\\end{example}\n\n\\begin{solution}\nThe sphere can be obtained by rotating the graph of\n  $\\ds f(x)=\\sqrt{r^2 - x^2}$ about the $x$-axis.\nThe derivative $f'$ is $\\ds -x/\\sqrt{r^2-x^2}$, so the surface area is\ngiven by\n\\begin{eqnarray*}\nA&=&2\\pi \\int_{-r }^r \\sqrt{r^2 - x^2}\\sqrt{1+{x^2\\over r^2-x^2}}\\,dx\\cr\n&=&2\\pi \\int_{-r }^r \\sqrt{r^2 - x^2}\\sqrt{r^2\\over r^2-x^2}\\,dx\\cr\n&=&2\\pi \\int_{-r }^r r\\,dx=2\\pi r\\int_{-r }^r 1\\,dx=4\\pi r^2\n\\end{eqnarray*}\\vskip-10pt\n\\end{solution}\n\nIf the curve is rotated around the $y$ axis, the formula is nearly\nidentical, because the length of the line segment we use to\napproximate a portion of the curve doesn't change. Instead of the\nradius $\\ds f(x_i^*)$, we use the new radius $\\ds \\bar x_i=\n(x_i+x_{i+1})/2$, and the surface area integral becomes\n$$\\int_a^b 2\\pi x\\sqrt{1+(f'(x))^2}\\,dx.$$\n\n\\begin{example}{Surface Around y-axis}{Surface Around y-axis}\\label{Surface Around y-axis}\nCompute the area of the surface formed when $\\ds f(x)\n=x^2$ between $0$ and $2$ is rotated around the $y$-axis.\n\\end{example}\n\n\\begin{solution}\nWe compute $f'(x)= 2x$, and then\n$$2\\pi\\int_0^2 x\\sqrt{1+4x^2}\\,dx={\\pi\\over6}(17^{3/2}-1),$$\nby a simple substitution.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Surface Area}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n Compute the area of the surface formed when $\\ds f(x)=2\\sqrt{1-x}$\nbetween $-1$ and $0$ is rotated around the $x$-axis.\n\\begin{sol}\n $\\ds 8\\pi\\sqrt3-{16\\pi\\sqrt2\\over 3}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Compute the surface area of example~\\ref{Surface Around y-axis} by rotating $\\ds f(x)=\\sqrt x$ around the $x$-axis.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Compute the area of the surface formed when \n$\\ds f(x)=x^3$ between $1$ and $3$ is rotated around the $x$-axis.\n\\begin{sol}\n $\\ds {730\\pi\\sqrt{730}\\over27}-{10\\pi\\sqrt{10}\\over 27}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Compute the area of the surface formed when \n$\\ds f(x)=2 +\\cosh (x)$ between $0$ and $1$ is rotated around the\n  $x$-axis.\n\\begin{sol}\n $\\ds \\pi +2\\pi e+ {1\\over4}\\pi e^2-{\\pi\\over4e^2}-{2\\pi\\over e}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the surface obtained by rotating the graph of $\\ds\nf(x)=1/x$, $x\\geq 1$, around the $x$-axis. This surface is called\n\\dfont{Gabriel's horn} or \\dfont{Toricelli's trumpet}.  \n%In exercise~\\xrefn{exer:gabriels horn} in \n%section~\\xrefn{sec:improper integrals} we saw that Gabriel's horn has\n%finite volume. \nShow that Gabriel's horn has\ninfinite surface area.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the circle $\\ds (x-2)^2+y^2 = 1$. Sketch the\nsurface obtained by rotating this circle about the $y$-axis. (The\nsurface is called a \\dfont{torus}.) What is the surface area?\n\\begin{sol}\n $8\\pi^2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the ellipse with equation $\\ds x^2/4+y^2 = 1$.\nIf the ellipse is rotated around the $x$-axis it forms \nan \\dfont{ellipsoid}.\nCompute the surface area.\n\\begin{sol}\n $\\ds 2\\pi+{8\\pi^2\\over 3\\sqrt{3}}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Generalize the preceding result: rotate the ellipse\ngiven by $\\ds x^2/a^2+y^2/b^2=1$ about the\n$x$-axis and find the surface area of the resulting ellipsoid. You\nshould consider two cases, when $a>b$ and when $a<b$. Compare to the\narea of a sphere.\n\\begin{sol}\n $a>b$: $\\ds 2\\pi b^2+$\\hfill\\break\n\\hbox{\\hskip1cm}$\\ds {2\\pi a^2b\\over\\sqrt{a^2-b^2}}\n  \\arcsin(\\sqrt{a^2-b^2}/a)$,\\hfill\\break\n$a<b$: $\\ds 2\\pi b^2+ $\\hfill\\break\n\\hbox{\\hskip1cm}$\\ds {2\\pi a^2b\\over\\sqrt{b^2-a^2}}\n  \\ln\\left({b\\over a}+{\\sqrt{b^2-a^2}\\over a}\\right)$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "8f757a60503073d601677688199f11ac6a85be12", "size": 11192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-8-surface-area.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-8-surface-area.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-8-surface-area.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": 35.1949685535, "max_line_length": 148, "alphanum_fraction": 0.6910293066, "num_tokens": 4185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.6832910670068393}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{../../shared/preamble}\n\\addbibresource{../../shared/references.bib}\n\n\\usepackage{../sets/sets}\n\\usepackage{groups}\n\n\\title{Groups}\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 groups and some related objects.\nIt has been type checked by \\fuzz.\n\\end{abstract}\n\n\\section{Introduction}\n\nGroups are ubiquitous throughout mathematics and physics.\nThis article defines the basic algebraic objects related to groups and their homomorphisms.\n\n\\section{Binary Operations}\n\nLet $\\genT$ be a set. We refer to the members of $\\genT$ as its {\\em elements}.\nA {\\em binary operation} on $\\genT$ is a function that maps pairs of elements to elements.\n\n\\subsection{\\zcmd{binop}}\n\nLet $\\binop \\genT$ denote the set of all binary operations on $\\genT$.\n\n\\begin{zed}\n\\binop \\genT == \\genT \\cross \\genT \\fun \\genT\n\\end{zed}\n\n\\subsection{Infix Operator Symbols \\zcmd{timesG}, \\zcmd{mulG}, and \\zcmd{addG}}\n\nThe result of applying a binary operation to the pair of elements $(x, y)$ \nis often denoted by an expression formed using an infix operator symbol,\ne.g. $x \\timesG y$, $x \\mulG y$ or $x \\addG y$.\n\n\\subsection{$MapPerservesOperation$}\n\nLet $\\genT$ and $\\genU$ be sets and let $A$ and $B$ be binary operations on them.\nLet $f$ be a function that maps $\\genT$ to $\\genU$.\nThe function $f$ is said to {\\em preserve the operations} if it maps the product of elements to \nthe product of the mapped elements.\n\nLet $MapPreservesOperation$ denote this situation.\n\n\\begin{schema}{MapPreservesOperation}[\\genT, \\genU]\nf: \\genT \\fun \\genU \\\\\nA: \\binop \\genT \\\\\nB: \\binop \\genU\n\\where\n\\LET (\\_ \\mulG \\_) == A; (\\_ \\timesG \\_) == B @ \\\\\n\\t1\t\\forall x, y: \\genT @ \\\\\n\\t2\t\tf(x \\mulG y) = (f~x) \\timesG (f~y)\n\\end{schema}\n\n\\subsection{\\zcmd{homBinOp}}\n\nA map that preserves operations is said to be an {\\em operation homomorphism}.\n\nLet $A$ and $B$ be binary operations. \nLet $\\homBinOp(A,B)$ denote the set of operation homomorphisms from $A$ to $B$.\n\n\\begin{gendef}[\\genT, \\genU]\n\\homBinOp: \\binop \\genT \\cross \\binop \\genU  \\fun \\power (\\genT \\fun \\genU)\n\\where\n\\homBinOp = (\\lambda A: \\binop \\genT; B: \\binop \\genU @ \\\\\n\\t1\t\\{~ f: \\genT \\fun \\genU | MapPreservesOperation[\\genT, \\genU] ~\\})\n\\end{gendef}\n\n\\begin{remark}\nThe identity map is an operation homomorphism.\n\\end{remark}\n\n\\begin{remark}\nThe composition of two operation homomorphisms is an operation homomorphism.\n\\end{remark}\n\n\\section{Semigroups}\n\n\\subsection{$OperationIsAssociative$}\n\nA binary operation is said to be {\\em associative} if the result of applying it to three elements\nis independent of the order in which it is applied pairwise.\n\nLet $OperationIsAssociative$ denote this situation.\n\n\\begin{schema}{OperationIsAssociative}[\\genT]\nA: \\binop \\genT\n\\where\n\\LET (\\_ \\mulG \\_) == A @ \\\\\n\\t1\t\\forall x, y, z: \\genT @ \\\\\n\\t2\t\t(x \\mulG y) \\mulG z = x \\mulG (y \\mulG z)\n\\end{schema}\n\n\\subsection{\\zcmd{semigroup}}\n\nLet $\\semigroup \\genT$ denote the set of all semigroups on the set of elements $\\genT$.\n\n\\begin{zed}\n\\semigroup \\genT == \\{~ A: \\binop \\genT | OperationIsAssociative[\\genT] ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{homSemigroup}}\n\nA {\\em semigroup homomorphism} from $A$ to $B$ is a homomorphism of the underlying binary operation.\n\nLet $\\homSemigroup(A, B)$ denote the set of all semigroup homomorphisms from $A$ to $B$.\n\n\\begin{gendef}[\\genT, \\genU]\n\\homSemigroup: \\semigroup \\genT \\cross \\semigroup \\genU \\fun \\power (\\genT \\pfun \\genU)\n\\where\n\\homSemigroup = \\\\\n\\t1\t(\\lambda A: \\semigroup \\genT; B: \\semigroup \\genU @ \\homBinOp(A, B))\n\\end{gendef}\n\n\\begin{remark}\nThe identity mapping is a semigroup homomorphism.\n\\end{remark}\n\n\\begin{remark}\nThe composition of two semigroup homomorphisms is another semigroup homomorphism.\n\\end{remark}\n\n\\section{Monoids}\n\n\\subsection{$IdentityElement$}\n\nLet $\\genT$ be a set, let $A$ be a binary operation over $\\genT$, and let $e$ be an element of $\\genT$.\nThe element $e$ is said to be an {\\em identity element} of $A$ if left and right \nproducts with it leave all elements unchanged.\n\nLet $IdentityElement$ denote this situation.\n\n\\begin{schema}{IdentityElement}[\\genT]\nA: \\binop \\genT \\\\\ne: \\genT\n\\where\n\\LET (\\_ \\mulG \\_) == A @ \\\\\n\\t1\t\\forall x: \\genT @ \\\\\n\\t2\t\te \\mulG x = x = x \\mulG e\n\\end{schema}\n\n\\subsection{$identity\\_element$}\n\nLet $identity\\_element$ denote the relation that associates a binary operation one of its identity elements.\n\n\\begin{gendef}[\\genT]\nidentity\\_element: \\binop \\genT \\rel \\genT\n\\where\nidentity\\_element = \\\\\n\\t1\t\\{~ IdentityElement[\\genT] @ A \\mapsto e ~\\}\n\\end{gendef}\n\n\\begin{remark}\nIf a binary operation has an identity element then it is unique.\n\\end{remark}\n\n\\begin{proof}\nLet $\\mulG$ be a binary operation. Suppose $e$ and $e'$ are identity elements.\n\\begin{argue}\ne \\\\\n\\t1\t= e \\mulG e'\t& $e'$ is an identity element \\\\\n\\t1\t= e'\t\t\t& $e$ is an identity element\n\\end{argue}\n\\end{proof}\n\n\\begin{remark}\nSince identity elements are unique if they exist, the relation from binary operations to identity elements is a partial function.\n\n\\begin{zed}\nidentity\\_element \\in \\binop \\setT \\pfun \\setT\n\\end{zed}\n\n\\end{remark}\n\n\n\\subsection{Identity Element Symbols \\zcmd{zeroG}, and \\zcmd{oneG}}\n\nIdentity elements are typically denoted by the symbols  $\\zeroG$ or $\\oneG$.\n\n\\subsection{\\zcmd{monoid}}\n\nLet $\\genT$ be a set of elements.\nA {\\em monoid} over $\\genT$ is a semigroup over $\\genT$ that has an identity element.\n\nLet $\\monoid \\genT$ denote the set of all monoids over $\\genT$.\n\n\\begin{zed}\n\\monoid \\genT == \\{~ A: \\semigroup \\genT | \\exists e: \\genT @ IdentityElement[\\genT] ~\\}\n\\end{zed}\n\n\n\\subsection{$MapPreservesIdentity$}\n\nLet $A$ and $B$ be monoids and let $f$ map the elements of $A$ to the elements of $B$.\nThe map $f$ is said to {\\em preserve the identity element} if it maps the identity element of $A$\nto the identity element of $B$.\n\nLet $MapPreservesIdentity$ denote this situation.\n\n\\begin{schema}{MapPreservesIdentity}[\\genT, \\genU]\nf: \\genT \\fun \\genU \\\\\nA: \\monoid \\genT \\\\\nB: \\monoid \\genU\n\\where\n\\LET e == identity\\_element~A; \\\\\n\\t1\te' == identity\\_element~B @ \\\\\n\\t2\t\tf~e = e'\n\\end{schema}\n\n\\subsubsection{\\zcmd{homMonoid}}\n\nA {\\em monoid homomorphism} from $A$ to $B$ is a homomorphism $f$ of the underlying semigroups\nthat preserves identity.\n\nLet $\\homMonoid(A, B)$ denote the set of all monoid homomorphisms from $A$ to $B$.\n\n\\begin{gendef}[\\genT, \\genU]\n\\homMonoid: \\monoid \\genT \\cross \\monoid \\genU \\fun \\power (\\genT \\fun \\genU)\n\\where\n\\homMonoid = \\\\\n\\t1\t(\\lambda A: \\monoid \\genT; B: \\monoid \\genU @ \\\\\n\\t2\t\t\\{~ f: \\homSemigroup(A, B) | \\\\\n\\t3\t\t\tMapPreservesIdentity[\\genT, \\genU] ~\\})\n\\end{gendef}\n\n\\begin{remark}\nThe identity mapping is a monoid homomorphism.\n\\end{remark}\n\n\\begin{remark}\nThe composition of two monoid homomorphisms is another monoid homomorphism.\n\\end{remark}\n\n\\section{Groups}\n\n\\subsection{$InverseOperation$ and Postfix Operator symbol \\zcmd{invG}}\n\nLet $\\genT$ be a set of elements and let $A$ be a monoid on $\\genT$.\nA function $inv \\in \\genT \\fun \\genT$ is said to be an {\\em inverse operation} if it maps each element\nto an element whose product with it is the identity element.\nTypically, the expression $x \\invG$ is used to denote the inverse of $x$.\n\nLet $InverseOperation$ denote this situation.\n\n\\begin{schema}{InverseOperation}[\\genT]\nA: \\monoid \\genT \\\\\ninv: \\genT \\fun \\genT\n\\where\n\\LET (\\_ \\mulG \\_) == A; \\\\\n\\t1\t\\oneG == identity\\_element~A; \\\\\n\\t1\t(\\_ \\invG) == inv @ \\\\\n\\t2\t\t\\forall x: \\genT @ \\\\\n\\t3\t\t\tx \\mulG x \\invG = \\oneG = x \\invG  \\mulG x\n\\end{schema}\n\n\\subsection{$inverse\\_operation$}\n\nLet $inverse\\_operation$ denote the relation between monoids and their inverse operations.\n\n\\begin{gendef}[\\genT]\ninverse\\_operation: \\monoid \\genT \\rel \\genT \\fun \\genT\n\\where\ninverse\\_operation = \\\\\n\\t1\t\\{~ InverseOperation[\\genT] @ A \\mapsto inv ~\\}\n\\end{gendef}\n\n\\begin{remark}\nIf a monoid has an inverse operation then it is unique.\n\\end{remark}\n\n\\begin{proof}\nLet $x$ be any element.\nSuppose $x \\invG$ and $x \\daggerG$ are inverses of $x$.\n\\begin{argue}\nx\\daggerG \\\\\n\\t1\t= x\\daggerG \\mulG \\oneG\t\t\t\t& $\\oneG$ is an identity element \\\\\n\\t1\t= x\\daggerG \\mulG (x \\mulG x \\invG)\t\t& $x \\invG$ is an inverse \\\\\n\\t1\t= (x\\daggerG \\mulG x) \\mulG x \\invG\t\t& associativity \\\\\n\\t1\t= \\oneG \\mulG x \\invG\t\t\t\t& $x \\daggerG$ is an inverse \\\\\n\\t1\t= x \\invG\t\t\t\t\t\t\t& $\\oneG$ is an identity element\n\\end{argue}\n\\end{proof}\n\n\\begin{remark}\nSince if inverse operation exist they are unique, the relation between monoids and inverse operations\nis a partial function.\n\n\\begin{zed}\ninverse\\_operation \\in \\monoid \\setT \\pfun \\setT \\fun \\setT\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{$\\group$}\n\nA {\\em group} is a monoid that has an inverse operation.\n\nLet $\\genT$ be a set of elements.\nLet $\\group \\genT$ denote the set of all groups over $\\genT$.\n\n\\begin{zed}\n\\group \\genT == \\{~ A: \\monoid \\genT | \\exists inv: \\genT \\fun \\genT @ InverseOperation[\\genT] ~\\}\n\\end{zed}\n\n\\subsubsection{$MapPreservesInverse$}\n\nLet $\\genT$ and $\\genU$ be sets of elements,\nlet $A$ and $B$ be groups over $\\genT$ and $\\genU$, \nand let $f$ map $\\genT$ to $\\genU$.\nThe map $f$ is said to {\\em preserve the inverses} if it maps the inverses of elements of $A$\nto the inverses of the corresponding elements of $B$.\n\nLet $MapPreservesInverse$ denote this situation.\n\n\\begin{schema}{MapPreservesInverse}[\\genT, \\genU]\nf: \\genT \\fun \\genU \\\\\nA: \\group \\genT \\\\\nB: \\group \\genU\n\\where\n\\LET (\\_ \\invG) == inverse\\_operation~A; \\\\\n\\t1\t(\\_ \\daggerG) == inverse\\_operation~B @ \\\\\n\\t2\t\t\\forall x: \\genT @ \\\\\n\\t3\t\t\tf(x \\invG) = (f~x) \\daggerG\n\\end{schema}\n\n\\subsubsection{\\zcmd{homGroup}}\n\nLet $A$ and $B$ be groups.\nA {\\em group homomorphism} from $A$ to $B$ is a monoid homomorphism\nfrom $A$ to $B$ that preserves inverses.\n\nLet $\\homGroup(A, B)$ denote the set of all group homomorphisms from $A$ to $B$.\n\n\\begin{gendef}[\\genT, \\genU]\n\\homGroup: \\group \\genT \\cross \\group \\genU \\fun \\power (\\genT \\fun \\genU)\n\\where\n\\homGroup = \\\\\n\\t1\t(\\lambda A: \\group \\genT; B: \\group \\genU @ \\\\\n\\t2\t\t\\{~ f: \\homMonoid(A, B) | \\\\\n\\t3\t\t\tMapPreservesInverse[\\genT, \\genU] ~\\})\n\\end{gendef}\n\n\\begin{remark}\nThe identity mapping is a group homomorphism.\n\\end{remark}\n\n\\begin{remark}\nThe composition of two group homomorphisms is another group homomorphism.\n\\end{remark}\n\n\\subsection{$bij$}\n\nLet $\\genT$ be a set and let $bij[\\genT]$ denote the set of a bijections $\\genT \\bij \\genT$ from $\\genT$ to itself.\n\n\\begin{gendef}[\\genT]\n\tbij: \\power (\\genT \\fun \\genT)\n\\where\n\tbij = \\genT \\bij \\genT\n\\end{gendef}\n\n\\begin{remark}\nThe composition of bijections is a bijection.\n\n\\begin{zed}\n\t\\forall f, g: bij[\\setT] @ \\\\\n\t\\t1\tf \\circ g \\in bij[\\setT]\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nComposition is associative.\n\n\\begin{zed}\n\t\\forall f, g, h: bij[\\setT] @ \\\\\n\t\\t1\tf \\circ (g \\circ h) = (f \\circ g) \\circ h\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe identity function $\\id \\setT$ acts as a left and right identity element under composition.\n\n\\begin{zed}\n\t\\forall f: bij[\\setT] @ \\\\\n\t\\t1\t \\id \\setT \\circ f = f = f \\circ \\id \\setT\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe inverse $f \\inv$ of a bijection $f$ is its left and right inverse under composition.\n\n\\begin{zed}\n\t\\forall f: bij[\\setT] @ \\\\\n\t\\t1\tf \\circ f \\inv = \\id \\setT = f \\inv \\circ f\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{$Bij$}\n\nThe preceding remarks show that set $bij[\\genT]$ under the operation of composition has the structure of a group.\nLet $Bij[\\genT]$ denote this group.\n\n\\begin{gendef}[\\genT]\n\tBij: bij[\\genT] \\cross bij[\\genT] \\fun bij[\\genT]\n\\where\n\tBij = (\\lambda f, g: bij[\\genT] @ f \\circ g)\n\\end{gendef}\n\n\\begin{example}\nLet $\\setT$ be any non-empty set.\nThe composition operation $Bij[\\setT]$ is a group over the set of bijections $bij[\\setT]$ from $\\setT$ to $\\setT$.\n\n\\begin{zed}\n\\setT \\neq \\emptyset \\implies \\\\\n\\t1\tBij[\\setT] \\in \\group bij[\\setT]\n\\end{zed}\n\n\\end{example}\n\n\\section{Abelian Groups}\n\n\\subsection{OperationIsCommutative}\n\nLet $\\genT$ be a set of elements.\nA binary operation $A$ over $\\genT$ is said to be {\\em commutative} when the product of two elements doesn't depend on \ntheir order.\n\nLet $OperationIsCommutative$ denote this situation.\n\n\\begin{schema}{OperationIsCommutative}[\\genT]\nA: \\binop \\genT\n\\where\n\\LET (\\_ \\mulG \\_) == A @ \\\\\n\\t1\t\\forall x, y: \\genT @ \\\\\n\\t2\t\tx \\mulG y = y \\mulG x\n\\end{schema}\n\n\\subsection{\\zcmd{abgroup}}\n\nAn {\\em Abelian group} is a group in which the binary operation is commutative.\nLet $\\genT$ be a set of elements.\n\nLet $\\abgroup \\genT$ denote the set of all Abelian groups over $\\genT$.\n\n\\begin{zed}\n\\abgroup \\genT == \\{~ A: \\group \\genT | OperationIsCommutative[\\genT] ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{addG}, \\zcmd{zeroG}, and \\zcmd{negG}}\n\nOften in an Abelian group the binary operation is denoted as addition $x \\addG y$,\nthe identity element as a zero $\\zeroG$, and the inverse operation as negation $\\negG x$.\n\n\\begin{example}\nAddition over the integers is an Abelian group.\n\n\\begin{zed}\n\t(\\_ + \\_) \\in \\abgroup \\num\n\\end{zed}\n\n\\end{example}\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "4aa2de74b4039e78a2bb0813ba2c8609137aab7f", "size": 13121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/groups/groups.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/groups/groups.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/groups/groups.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": 27.449790795, "max_line_length": 129, "alphanum_fraction": 0.6923252801, "num_tokens": 4357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6832372755614637}}
{"text": "\\section{Interpolation: Interpolation}\nGiven a set of x, f(x) pairs (e.g., in a pair of arrays\nxarr,yarr), and given an x, use interpolation to find y.\n\nThere are general purpose approaches, and also some\nspecialized to general polynomials and others specialized to \northogonal approximatrixions\nsuch as Chebyshev approximatrixions.  Here we consider only the\ngeneral cases.\n\nThe first step is to find the closest xa value as a start\npoint.  Then one can interpolationolate from that value and its\nyarr pair.  We can do linear, quadtraic, nth order\npolynomial interpolations.\n\n\\subsection*{interpolation\\_linear}\nPretty straightforward.  I found it giving errors of 1--5\\%\nfor a 10-value sin table, and 0.01\\% error for a 100-value\nsin table.\n\n\\subsection*{interpolation\\_polynomial}\nNR92 describes it on pg 109.  In the basic P form, the\nresult is a polynomial with n terms, of which all but 1\n(e.g., k) go to zero.  So one then has:\n\\begin{equation}\n     P(x)=\\frac{(x-x_1)(x-x_2) \\cdots (x-x_n)}\n                 {((x_k-x_1)(x_k-x_2) \\cdots (x_k-x_n))y_k}\n\\end{equation}\nSo we need to collect the numerator and we need to find the\nright k.  Eqn 3.1.3 computes these on the fly, col by col.\nAccording to several other books, polynomial interpolation\nis numerically unstable.  But NR92's suggests improvements, based on\ncapturing differences (NR92's eqn 3.1.5):\n\\begin{eqnarray}\n  D_{m+1,i} & = & \\frac{(x_{i+m+1}-x)(C_{m,i+1}-D_{m,i})}{x_i-x_{i+m+1}}\\\\\n  C_{m+1,i} & = & \\frac{(x_{i}    -x)(C_{m,i+1}-D_{m,i})}{x_i-x_{i+m+1}}\n\\end{eqnarray}\n\n\nNote that the recurrence\nslides the whole equilateral triangle into a right triangle\nform, with the {\\em first} item in each col placed in the C,D\narrays at index 1.  Thus as we go along the cols, the number\nof invalid values grows from the bottom of the arrays.\n\nOnce we have the full col worth of C and D values per the\nrecurrence, we select which one to use.  NR92 uses a cryptic\nformula:\n\\begin{verbatim}\n     if 2*ns < (n-m) then\n       dy=c[ns+1]\n     else\n       dy=d[ns--]\n     end\n\\end{verbatim}\n\nHere, ns is the index aligned with the input x.  Note that\nafter using d we decrement ns.  That is, we move further\ntoward the top of the array.  But after using c we stay put.\nWe do momentarily peek further down the array as c[ns+1],\nbut ns stays the same.\n\nThe next thing to notice is that n-m is the total number of\nnew values in this col.  [From there to n we have old data\nfrom previous cols.]  ns should be centered in this set of\nvalues, which are offset from 1.  So ns should be\n$\\approx ((n-m)-1)/2$.  NR92 replaces the div with a mul by using\n$2 \\mbox{ns} \\approx (n-m)$.\n\nWhat if ns is too small?  That means we are too far\ntoward the top of the array.  That will be alright once we\ngo to the next col, because the array will slide up and ns\nwill be correctly centered again.  But if we are too far\ndown, we need to decrement ns.  Also, if we are dead on, we\nstill need to decrement in order to get centered for the\nnext col.\n\nThe remaining problem is to understand 3.1.5.  First we note\nthat $m$ means the old column, and $m+1$ means the new\ncolumn we are currently generating.  But the easier way to\ndo this is to think of the righthand side c and d as m-1 and\nthe lefthand side as m.  Then as we do the big loop for the\ncolumns (m=1,2,...n-1), we just need to use the old c and d,\nand create the new ones in situ.  With this understanding,\nx[i+m+1] means the x[i+m] as seen for the new column.\n\nNext, note that we have a common factor of $(C_{m,i+1}-\nD{m,i})/(x_i-x_{i+m+1})$.  Before we compute that, we need to\ncheck to see if the denominator is zero.\n\nNext, we need to know how many of the cells are valid for a\ngiven col.  We start with n cells, and lose one every time\nwe calc a new col.  NR92 recalcs this as n-m every loop.  I\nhave pulled it out as col\\_n.  Mainly I did it to make it\nmore readable, but it just might be faster too.\n\nOnce we have the loops running m=1\\dots n-1 and i=1\\dots col\\_n, we\nneed to access the right cells.  I made c and d easier by\nwriting them to 0..n arrays and just using the 1\\dots n part.\nxa is still in the 0\\dots n-1 form, so I have to replace all {\\tt i}\nwith {\\tt i-1}.  I capture the resulting xa accesses as xi for\nx[i] in 3.1.5 and xim1 for x[i+m+1] in 3.1.5.\n\nTo do offsetting (e.g., to do 4 point interpolation out of a much\nlarger table): The idea is to pass start and len with\ndefaults of 0.  If $len \\ne 0$ then we know we need to do\npartial access.  From there, we use symbolic start and end\nvalues to keep track of indexes. C and D still live in their\n1\\dots n world, but we now have to offset the xa[] accesses by\nthe xn1 value (which is usually 0).\n\nThe relative error on even a 10-value sin table is\nimpressive (on the order of 1.0e-8).  It may be complex, but\nit sure does its job.\n", "meta": {"hexsha": "c329b6a9845911a8b5cb67fe4fee2ca78301fab4", "size": 4805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/interpolation.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/interpolation.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/interpolation.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": 41.7826086957, "max_line_length": 74, "alphanum_fraction": 0.7202913632, "num_tokens": 1470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126792, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.6832372735910486}}
{"text": "\n\\subsection{Cournot competition}\n\nWith competition, the elasticity of demand refers to the whole market, not just a single producer. Instead we have:\n\n\\(\\epsilon = \\dfrac{p}{Q}\\dfrac{\\delta Q}{\\delta p}\\)\n\n\\(Q=\\sum_j q_j\\)\n\nWe now get:\n\n\\(p[1+\\dfrac{q}{Q}\\dfrac{\\delta Q}{\\delta q}\\dfrac{Q}{p}\\dfrac{\\delta p}{\\delta Q}]=MC\\)\n\n\\(p[1+\\dfrac{\\mu }{\\epsilon }]=MC\\)\n\nUsing the firm's size elasticity: \\(\\mu = \\dfrac{q}{Q}\\dfrac{\\delta Q}{\\delta q}\\)\n\nWith monopoly this is:\n\n\\(\\mu = 1\\)\n\n", "meta": {"hexsha": "394ccf6a3fa09709ffe0a8dec0d1af2e3cc729d9", "size": 486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/producer/02-01-cournot.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/producer/02-01-cournot.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/producer/02-01-cournot.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0909090909, "max_line_length": 115, "alphanum_fraction": 0.6440329218, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391664210671, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6832099261427388}}
{"text": "\\section{The Gradient}\r\n\\noindent\r\nIf you are on a surface $f: \\mathbb{R}^2 \\to \\mathbb{R}$, what direction $\\langle \\Delta x, \\Delta y \\rangle$ should you go to maximize the change of $f$?\\\\\r\nWe saw earlier that $\\Delta z\\approx \\langle f_x, f_y \\rangle \\cdot \\langle \\Delta x, \\Delta y \\rangle$.\r\nTo maximize a dot product, $\\langle \\Delta x, \\Delta y \\rangle$ should be in the same direction as $\\langle f_x, f_y \\rangle$.\r\nThis directional vector is called the gradient: the direction of steepest ascent.\\\\\r\nNotated mathematically,\r\n\\begin{equation*}\r\n\t\\nabla f(x,y) = \\langle f_x, f_y \\rangle.\r\n\\end{equation*}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./differentialMultivariableCalculus/gradient.png}\r\n\t\\caption{A surface and its gradient vectors}\r\n\\end{figure}\r\n\r\n\\input{./differentialMultivariableCalculus/gradientProperties}\r\n\\input{./differentialMultivariableCalculus/linearApproximationsGradient}\r\n\\input{./differentialMultivariableCalculus/gradientCLevelCurves}", "meta": {"hexsha": "f1e678dead17beaa18d41d4187d16653fdcc6339", "size": 1006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/theGradient.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/theGradient.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/theGradient.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": 50.3, "max_line_length": 157, "alphanum_fraction": 0.7524850895, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6831645358734671}}
{"text": "\\section{The model}\\label{sec:model}\n\nBefore investigating the model in more depth some elaboration of the notation used in this paper: $\\Omega$ is used to denote covariance matrices, with individual elements of $\\Omega$ denoted $\\sigma^{2}_{i,j}$, and noting that the variances are the diagonal of the matrix, these being denoted = $\\sigma^{2}_{i,i} = \\sigma^{2}_{i}$. Moving on,  $\\mu = (\\mu_1, \\mu_2, \\cdots \\mu_{k})$ is used for denoting a vector of $k$ expected returns. It should be noted that $\\Omega$ is a $k\\times k$ matrix, or rather the length $\\mu$ should correspond to the size of the symmetric covariance matrix. The returns at time $t$ are denoted as $\\rr^{(t)} = (r_1^{(t)}, r_2^{(t)}, \\cdots, r_k^{(t)})$. In general the stochastic variables will be upper case, and the realization will be denoted in lower case. such that $\\RR^{(t)}$ is a stochastic vector, and $\\rr^{(t)}$ is vector of realized returns. Let $\\bar{r}$ denote the risk free asset, and let $\\ones$ denote a vector of 1's of length $k$). Sharpe ratio is denoted $sr$. Vectors will be denoted in bold when possible.\n\n\\subsection{CAPM}\n\nAs alluded to in the introduction, in CAPM it's assumed that the returns of stocks are drawn $i.i.d$ from an multivariate distribution with fixed mean $\\mu$ and covariance matrix $\\Omega$. Assuming that the returns are normally distributed the structural model driving the data generating process can be summed up into a single equation:\n\n\\begin{equation}\n    \\RR^{(t)} \\sim N(\\mu, \\Omega)\n\\end{equation}\n\n\\subsection{Model formulation with structural breaks}\n\nAs alluded to in chapter \\ref{sec:data}, the assumption, that a single covariance matrix and expected returns can represent the data generating process seems very unlikely. There are in general two approaches to this problem:\n\n\\begin{enumerate}\n    \\item Assuming the covariance matrix and expected returns steadily moves over time, something akin to a AR process.\n    \\item Assuming in each period with a certain probability a structural break will occur, and this will generate a vector of expected returns vector and a covariance matrix.\n\\end{enumerate}\n\nIn this paper the ladder option is investigated. This leads to the following structural model:\n\nFirst a variable $b^{(t)}\\in \\{0,1\\}$ is drawn which represent a structural break. If $b=1$ a structural break is assumed. The parameter $p$ in equation \\ref{eq:structuralbreak} denotes the probability of a structural break.\n\n\\begin{equation}\\label{eq:structuralbreak}\n    b^{(t)} = bern(p)\n\\end{equation}\n\nIf $b = 1$ a new covariance matrix, and expected returns vector is drawn, where $d_{\\mu}, d_{\\Omega}$ are the distributions of the vector of expected returns  and covariance matrix. These distributions will be addressed later.\n\n\\begin{equation}\n    \\mu^{(t)} \\sim d_{\\mu} \\qquad \\Omega^{(t)} \\sim d_{\\Omega}\n\\end{equation}\n\nIf $b=0$ the covariance matrix and expected returns vector is equal to the previous:\n\n\\begin{equation}\n    \\mu^{(t)} = \\mu^{(t-1)} \\qquad \\Omega^{(t)} = \\Omega^{(t-1)}\n\\end{equation}\n\nLastly we draw the returns just as in the regular CAPM formulation, with the caveat $\\mu$ and $\\Omega$ contains a top-script $t$:\n\n\\begin{equation}\n    \\RR^{(t)} \\sim N(\\mu^{(t)}, \\Omega^{(t)})\n\\end{equation}\n\nSo in any given period the tangency portfolio can be calculated, however this tangency portfolio will change each time a structural break have occurred. The only parameter that cannot be estimated looking to the real data is $p$ the an exogenous parameter to the model.\n\n\\subsection{Approach for stocking picking}\n\nIn this paper Sharpe ratio is used as criteria for stock picking. Sharpe ratio is a risk adjusted measure of the performance of a portfolio, defined as:\n\n\\begin{equation}\n sr = \\frac{\\E[R - \\bar{r}]}{\\std(R)}\n\\end{equation}\n\nwhere we have used the risk free asset as benchmark. In this paper stock picking implies selecting a single stock. This corresponds to a portfolio with all weights at 0, except a weight of 1 for the stock chosen, the choice of stock would be the stock with highest Sharpe ratio.\n\nUnder the normal CAPM assumptions $\\Omega$ and $\\mu$ could be estimated using historical data. This is feasible in the normal CAPM formulation due to law of large numbers, that basically will ensure that as the number of observations increases, the parameter estimates will converge to the true value:\n\n\\begin{equation}\n    (\\hat{\\mu}, \\hat{\\Omega}) \\overset{d}{\\rightarrow} (\\mu, \\Omega) \\qquad \\text{for } n \\rightarrow \\infty\n\\end{equation}\n\nHaving these summary statistics the entire period would imply that we could chose the single stock with highest Sharpe ratio for the entire period.\n\nThis is however not the case under the alternative model formulation, since a structural break can occur at any time which makes it impossible to estimate $\\Omega$, $\\mu$ by using the entire sample of historical data. A different approach is therefore taken in this paper.\n\nSince we know the structural model underlying the problem, we are able to sample from it. Using this fact a generated dataset of arbitrary size can be made with returns and Sharpe ratios for individual stocks. We can the use this data set to train an algorithm, that maps a set of $k$ stock observations to a set of $k$ Sharpe ratios.\n\nMore formally we can denote this as:\n\n\\begin{equation}\n    f_{\\theta}: \\R^{k} \\mapsto \\R^{k}\n\\end{equation}\n\nWhere $f_{\\theta}$ is the algorithm used, that has a set of parameters $\\theta$.\n\nWe can then establish a loss function $L$ such that:\n\n\\begin{equation}\n    \\hat{f_{\\theta}} = \\underset{\\theta}{\\argmin} \\sum L(\\mathbf{sr}^{(t)}, \\hat{\\mathbf{sr}}^{(t)})\n\\end{equation}\n\nwhere $\\hat{\\mathbf{sr}}$ is the prediction of the weights in period $t$ returned by the  algorithm.\n\nFinally when having found the algorithm that performs the best in the simulated data set, we can take it to the real data. This approach allows three things: 1) We can train data hungry algorithms. We have approximately 7000 observations in the real data, but some algorithms (the LSTM mentioned later), needs in excess of a million observations to converge. 2) We have latent variables. Using real data we can only make estimates of $\\Omega$ and $\\mu$, however, when we have simulated from the underlying structural causal model, we can find the true values at any given time in the data set, allowing us to calculate the actual Sharpe ratio for each stock. 3) It is not possible to overfit the data out-of-sample. Had we trained, and tuned the models in-sample, that is used real data for these generalize out-of-sample. This is because our stock picking algorithms might have captured noise in the data, and used that to get overly optimistic estimates of the performance of our algorithms.\n", "meta": {"hexsha": "126b3291f5a5b700263844d5e0ec586e12d3475f", "size": 6756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/model.tex", "max_stars_repo_name": "JakartaLaw/ACFS", "max_stars_repo_head_hexsha": "dd7e6107ae22e987923dd5b81a8605d88650fce9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-04T01:20:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-04T01:20:46.000Z", "max_issues_repo_path": "chapters/model.tex", "max_issues_repo_name": "JakartaLaw/ACFS", "max_issues_repo_head_hexsha": "dd7e6107ae22e987923dd5b81a8605d88650fce9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-03-24T17:21:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T20:09:54.000Z", "max_forks_repo_path": "chapters/model.tex", "max_forks_repo_name": "JakartaLaw/ACFS", "max_forks_repo_head_hexsha": "dd7e6107ae22e987923dd5b81a8605d88650fce9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-07T07:34:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-07T07:34:46.000Z", "avg_line_length": 75.9101123596, "max_line_length": 1058, "alphanum_fraction": 0.7502960332, "num_tokens": 1669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.6831645288143273}}
{"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{From completions to dimensions}\n\nThe main references are \\cite{Mat80,Eis95}.\n\\section{Completions}\nConsider a ring $R$ together with a family of ideals $\\mathcal{I} \\neq \\emptyset$, such that for any $I, J \\in \\mathcal{I}$ there exists $K \\in \\mathcal{I}$ with $K \\subset I \\cap J$. This turns $R$ into a topological ring, characterized by the property that $\\mathcal{I}$ forms a local base of open neighborhoods of $0$. Recall that being a topological ring means that addition, multiplication and $x \\mapsto -x$ are all continuous. By standard arguments, $R$ is Hausdorff if and only if $\\{0\\}$ is closed, if and only if $\\bigcap_{I \\in \\mathcal{I}} I = \\{0\\}$.\\index{topological ring}\n\nTo simplify matters, we assume that\n\\begin{compactitem}\n\t\\item the family $\\mathcal{I}$ is countable, so that the topological properties (accumulation points, etc.) are detected by convergence of \\emph{sequences} as in the case of metric spaces;\n\t\\item furthermore, we may arrange that $\\mathcal{I} = \\{I \\supset J \\supset K \\supset \\cdots \\}$, in other words our topology comes from \\emph{filtrations}.\n\\end{compactitem}\nWithout the countability assumption, the sequences will have to be replaced by \\emph{filters}.\n\nIt makes sense to talk about topological $R$-modules for a topological ring $R$. By replacing filtration by ideals by filtration by $R$-submodules subject to the usual compatibility relation $F^i R \\cdot F^j M \\subset F^{i+j} M$, the recipe above applies to $R$-modules as well. Given $N \\subset M$, the topology so obtained on $M$ passes to $M/N$ by taking the quotient topology, or equivalently the quotient filtration $(F^\\bullet M+N)/N$. If the filtration in question is $I$-adic, where $I \\subsetneq R$ is an ideal, we obtain the \\emph{$I$-adic topology} on rings and modules.\\index{topological ring!$I$-adic}\n\nAn $R$-module $M$ equipped with a topology as above is \\emph{complete} if every Cauchy sequence $(x_n)_{n \\geq 1}$ has a limit; a Cauchy sequence $(x_n)_{n \\geq 1}$ is a sequence satisfying\n\\[ \\forall I \\in \\mathcal{I}, \\; \\exists N \\quad i,j \\geq N \\implies x_i - x_j \\in I. \\]\nAs in the familiar case of metric spaces, one has the \\emph{completion} of $M$. It is actually a morphism $M \\to \\hat{M}$ with $\\hat{M}$ complete Hausdorff, characterized by the following universal property:\\index{completion}\n\\[\n\\begin{tikzcd}[row sep=tiny, column sep=tiny]\n\tM \\arrow[rr, \"\\varphi:\\; \\text{cont. homo.}\" inner sep=0.7em] & & L \\\\\n\t& & \\scriptsize\\text{complete Hausdorff}\n\\end{tikzcd} \\quad \\leadsto\n\\begin{tikzcd}\n\tM \\arrow[rd, \"\\varphi\"'] \\arrow[r] & \\hat{M} \\arrow[dashed, d, \"\\exists! \\hat{\\varphi}\"] \\\\\n\t& L\n\\end{tikzcd}\\]\n\nThe uniqueness results immediately, and the formation of $M \\mapsto \\hat{M}$ is seen to be functorial in $M$. If $M$ is already complete Hausdorff, one may take $\\hat{M} = M$. Certainly, the same applies to the ring $R$.\n\n\\begin{exercise}\n\tSuppose that $R$ is complete Hausdorff with respect to the $I$-adic topology, where $I$ is a proper ideal. Show that every element of the form $u+x$, $u \\in R^\\times$ and $x \\in I$, is invertible.\n\\end{exercise}\n\nFrom the algebraic perspective, the completion of a filtered $R$-module $M = F^0 M \\supset F^1 M \\supset \\cdots$ can be constructed as the projective limit\n\\begin{align*}\n\t\\hat{M} & := \\varprojlim_{i \\geq 1} M/F^i M \\\\\n\t& = \\left\\{ (x_i)_{i \\geq 1} : i \\leq j \\implies x_i \\equiv x_j \\pmod{F^i M} \\right\\} \\subset \\prod_{i \\geq 1} M/F^i M.\n\\end{align*}\nThe morphism $M \\to \\hat{M}$ is the diagonal map. The topology on $\\hat{M}$ arises from the filtration\n\\[ F^i \\hat{M} := \\Ker\\left[ p_i: \\hat{M} \\to M/F^i M \\right] = \\left\\{ (x_n)_n \\in \\hat{M}: i \\leq k \\implies x_i=0 \\right\\}, \\]\nso that the preimage of $F^i \\hat{M}$ in $M$ is precisely $F^i M$. In the case where $M=R$ and $F^i R$ are ideals, we obtain the complete Hausdorff ring $\\hat{R}$, which is a subring of $\\prod_{i \\geq 1} R/F^i R$. Since the filtrations on $R$ and $M$ are assumed compatible, $\\hat{M}$ is an $\\hat{R}$-module.\n\n\\begin{example}\n\tFix a prime number $p$. The completion of $\\Z$ with respect to the ideal $p\\Z$ is nothing but the ring $\\Z_p$ of $p$-adic integers. Similarly, the completion of $\\Bbbk[X]$ with respect to $(X)$ is isomorphic to the $\\Bbbk$-algebra $\\Bbbk\\llbracket X\\rrbracket$.\n\\end{example}\n\n\\begin{exercise}\n\tDescribe the kernel of $M \\to \\hat{M}$ and show $M \\hookrightarrow \\hat{M}$ if and only if $M$ is Hausdorff.\n\\end{exercise}\n\n\\begin{exercise}\n\tShow that the topology of $\\hat{M}$ is the restriction of the product topology of $\\prod_i M/F^i M$, provided that each $M/F^i M$ is endowed with the discrete topology. Show that $\\hat{M}$ is a closed subspace of $\\prod_i M/F^i M$\n\\end{exercise}\n\n\\begin{lemma}\\label{prop:quotient-completion}\n\tLet $M$ be a complete $R$-module with respect to some filtration $F^\\bullet M$. For any submodule $N$, the quotient $M/N$ is also complete with respect to the quotient topology, or equivalently with respect to the quotient filtration $(F^\\bullet M + N)/N$.\n\\end{lemma}\n\\begin{proof}\n\tLet $\\bar{x}_n$ be a Cauchy sequence in $M/N$. Choose preimages $M \\ni x_n \\mapsto \\bar{x}_n$ for all $n$. We have $\\bar{x}_{n+1} - \\bar{x}_n \\in F^{i(n)}M + N$ where $\\lim_{n \\to \\infty} i(n) = \\infty$, therefore we can write $x_{n+1} - x_n = y_n + \\delta_n$ where $y_n \\in F^{i(n)} M$ and $\\delta_n \\in N$. We contend that $x'_n := x_1 + \\sum_{i < n} y_i$ is a Cauchy sequence in $M$. Indeed, for any $i > j$ we have $x'_i - x'_j = \\sum_{j \\leq k < i} y_k$, which lies in $F^{\\inf_k i(k)} M$. This implies $(x'_n)_n$ is a Cauchy sequence, hence has a limit $x \\in M$. It is also clear that $x'_n \\mapsto \\bar{x}_n$. Hence $\\bar{x}'_n$ has a limit $\\bar{x} = x \\bmod N$ in $M/N$.\n\\end{proof}\n\nLet us turn to the exactness of completion. This should be understood in the broader framework of $\\varprojlim$ of arbitrary projective systems. For simplicity, we only consider $I$-adic topologies on finitely generated modules over a Noetherian ring.\n\nObserve that any homomorphism $\\varphi: M \\to N$ between $R$-modules is automatically $\\mathfrak{a}$-adically continuous, for that $\\varphi(\\mathfrak{a}^n M) \\subset \\mathfrak{a}^n N$.\n\n\\begin{proposition}\\label{prop:completion-exactness}\n\tLet $R$ be a Noetherian ring and $I \\subsetneq R$ an ideal. Suppose $0 \\to M' \\to M \\to M'' \\to 0$ is an exact sequence of finitely generated $R$-modules, each term equipped with the $I$-adic topology. The completed sequence $0 \\to \\hat{M}' \\to \\hat{M} \\to \\hat{M''} \\to 0$ is also exact.\n\\end{proposition}\nConsequently, completion preserves the exactness of sequences formed by finitely generated $R$-modules. This is what makes completion so useful.\n\\begin{proof}\n\tWe shall show\n\t\\begin{compactenum}[(i)]\n\t\t\\item the topology on $M'$ induced from $M$ is the same as the $I$-adic topology;\n\t\t\\item the quotient topology on $M'' = M/M'$ is $I$-adic;\n\t\t\\item the completion $\\hat{M}'$ is naturally identified with the closure of the image of $M'$ in $\\hat{M}$;\n\t\t\\item $\\hat{M}''$ is naturally identified with the quotient of $\\hat{M}$ by $\\hat{M}'$.\n\t\\end{compactenum}\n\n\t(i) is a direct consequence of Artin--Rees Theorem \\ref{prop:Artin-Rees}: for $n \\gg 0$ we have\n\t\\begin{gather}\\label{eqn:AR-induced-top}\n\t\tI^n M' \\subset M' \\cap I^n M = I (M' \\cap I^{n-1} M) \\subset I^{n-1} M',\n\t\\end{gather}\n\tand this suffices to identify the resulting topologies.\n\t\n\t(ii) is immediate. As for (iii), we may embed $M'$ into $M$ and work with the induced topology. Realize $\\hat{M}$ as $\\varprojlim_n M/I^n M$. As a topological module $\\hat{M}'$ equals\n\t\\begin{align*}\n\t\t\\varprojlim_n \\frac{M'}{M' \\cap I^n M} & = \\left\\{ \\hat{x} = (x_n)_n \\in \\hat{M} : \\forall k, \\; x_k \\text{ comes from } M' \\right\\} \\\\\n\t\t& = \\left\\{ \\hat{x} \\in \\hat{M}: \\forall k \\; \\exists y \\in M' \\text{ s.t. } \\; \\hat{x} \\in y + F^k \\hat{M} \\right\\}\n\t\\end{align*}\n\twhich is readily seen to be the closure of the image of $M'$.\n\t\n\tFor (iv), the quotient $\\hat{M}/\\hat{M}'$ is Hausdorff since $\\hat{M}'$ is a closed submodule. It is also complete by Lemma \\ref{prop:quotient-completion}. There is a natural homomorphism $M/M' \\to \\hat{M}/\\hat{M}'$. Given any continuous homomorphism $\\varphi: M/M' \\to N$ to a complete Hausdorff $R$-module $N$, we may pull it back to $M \\to N$, which corresponds to a unique continuous $\\hat{M} \\to N$ that is trivial on the image of $M'$; but such a homomorphism must also vanish on the closure $\\hat{M}'$. This yields the required $\\hat{\\varphi}: \\hat{M}/\\hat{M}' \\to N$ in the universal property.\n\\end{proof}\n\nFor any $R$-module $M$ endowed with $I$-adic topology, there is a canonical homomorphism $M \\dotimes{R} \\hat{R} \\to \\hat{M}$. Indeed, $\\hat{M} = \\varprojlim_n M/I^n M$ is a $\\hat{R} = \\varprojlim_n R/I^n$-module by\n\\[ (r_n)_{n \\geq 1} \\cdot (x_n)_{n \\geq 1} = (r_n x_n)_{n \\geq 1}, \\quad (r_n)_n \\in \\hat{R}, \\; (x_n)_n \\in \\hat{M}, \\]\nhence the $R$-homomorphism $M \\to \\hat{M}$ gives rise to $M \\dotimes{R} \\hat{R} \\to \\hat{M}$ by the universal property of base change. This homomorphism is continuous if $M \\dotimes{R} \\hat{R}$ is filtered by the images of $M \\dotimes{R} (F^\\bullet \\hat{R})$, which makes it into a topological $\\hat{R}$-module.\n\n\\begin{theorem}\\label{prop:completion-tensor}\n\tSuppose $R$ is Noetherian. Let $M$ be a finitely generated $R$-module endowed with the $I$-adic topology. The homomorphism $M \\dotimes{R} \\hat{R} \\to \\hat{M}$ is then an isomorphism.\n\\end{theorem}\n\\begin{proof}\n\tWrite down a finite presentation $R^{\\oplus a} \\to R^{\\oplus b} \\to M \\to 0$. By the naturality of the homomorphism above, the right-exactness of $\\otimes$ and Proposition \\ref{prop:completion-exactness}, we have a commutative diagram\n\t\\[\\begin{tikzcd}\n\t\tR^{\\oplus a} \\dotimes{R} \\hat{R} \\arrow[r] \\arrow[d] & R^{\\oplus a} \\dotimes{R} \\hat{R} \\arrow[r] \\arrow[d] & M \\dotimes{R} \\hat{R} \\arrow[r] \\arrow[d] & 0 \\\\\n\t\t\\widehat{R^{\\oplus a}} \\arrow[r] & \\widehat{R^{\\oplus b}} \\arrow[r] & \\hat{M} \\arrow[r] & 0\n\t\\end{tikzcd}\\]\n\twith exact rows. Completion commutes with direct sums: $(N_1 \\oplus N_2)^\\wedge = \\hat{N}_1 \\oplus \\hat{N}_2$ canonically (easy, and the categorical reason is that completion is left adjoint to oblivion $R\\dcate{CompHausMod} \\to R\\dcate{TopMod}$). Therefore the first two vertical arrows may be identified with the canonical arrow $R^{\\oplus \\star} \\dotimes{R} \\hat{R} \\to \\hat{R}^{\\oplus \\star}$, $\\star \\in \\{a,b\\}$, which is an isomorphism of topological $\\hat{R}$-modules. We infer that $M \\dotimes{R} \\hat{R} \\rightiso \\hat{M}$ topologically.\n\\end{proof}\n\\begin{remark}\n\tIn fact $M \\dotimes{R} \\hat{R} \\rightiso \\hat{M}$ is also a homeomorphism. It suffices to observe that in the rows of the commutative diagram above, $M \\dotimes{R} \\hat{R}$ and $\\hat{M}$ are both realized as quotient topological $\\hat{R}$-modules, and that $R^{\\oplus \\star} \\dotimes{R} \\hat{R} \\rightiso \\hat{R}^{\\oplus \\star}$ is a homeomorphism. The second point has been observed in the proof of Proposition \\ref{prop:completion-exactness}, and the first follows from the fact completed modules carry the $\\hat{I}$-adic topology. See Proposition \\ref{prop:completion-top}. We do not need this result.\n\\end{remark}\n\nIn the following statements, $R$ is Noetherian and an ideal $I \\subsetneq R$ is chosen.\n\\begin{corollary}\n\tThe canonical homomorphism $R \\to \\hat{R}$ is flat.\n\\end{corollary}\n\\begin{proof}\n\tFlatness can be tested on short exact sequences of the form $0 \\to \\mathfrak{a} \\to R \\to R/\\mathfrak{a} \\to 0$ where $\\mathfrak{a}$ is a finitely generated ideal of $R$. Its base-change to $\\hat{R}$ is the same as completion, and completion is an exact functor by Proposition \\ref{prop:completion-exactness}.\n\\end{proof}\n\n\\begin{corollary}\\label{prop:completion-auto}\n\tAssume $R$ is $I$-adically complete Hausdorff. Then every finitely generated $R$-module $M$ is $I$-adically complete Hausdorff, and any submodule $N \\subset M$ is closed.\n\\end{corollary}\n\\begin{proof}\n\tFor the first assertion: the completion of $M$ can be identified with the composite $M = M \\dotimes{R} R \\to M \\dotimes{R} \\hat{R} \\to \\hat{M}$, which is bijective. Therefore every Cauchy sequence in $M$ has a limit in $M$.\n\n\tAs to the second assertion, recall that the $I$-adic topology on $N$ is the same as the one restricted from $M$ by \\eqref{eqn:AR-induced-top}. It remains to notice that complete subspaces must be closed.\n\\end{proof}\n\n\\section{Further properties of completion}\nLet $R$ be a Noetherian ring and $M$ a finitely generated $R$-module. Fix an ideal $I \\subsetneq R$. Unless otherwise specified, the topologies and completions are always $I$-adic.\n\n\\begin{proposition}\\label{prop:completion-aux}\n\tLet $\\mathfrak{a}$ be an ideal, then $\\mathfrak{a} \\hat{M} = \\widehat{\\mathfrak{a}M} = \\hat{\\mathfrak{a}}\\hat{M}$ as submodules of $\\hat{M}$. Consequently $\\hat{M}/\\mathfrak{a}\\hat{M} \\simeq (M/\\mathfrak{a}M)^\\wedge$ canonically.\n\\end{proposition}\n\\begin{proof}\n\tBy the exactness of completion (Proposition \\ref{prop:completion-exactness}), we may realize $\\hat{\\mathfrak{a}}$ as an ideal of $\\hat{R}$; in fact it is the image $\\mathfrak{a} \\hat{R}$ of $\\mathfrak{a} \\dotimes{R} \\hat{R} \\to R \\dotimes{R} \\hat{R} = \\hat{R}$. Hence $\\mathfrak{a}\\hat{R} = \\hat{\\mathfrak{a}}$. Now consider the commutative diagram\n\t\\[\\begin{tikzcd}\n\t\t\\mathfrak{a} \\dotimes{R} M \\dotimes{R} \\hat{R} \\arrow[r] \\arrow[rd] \\arrow[twoheadrightarrow, d] & \\mathfrak{a} \\dotimes{R} \\hat{M} \\arrow[d] \\\\\n\t\t\\mathfrak{a}M \\dotimes{R} \\hat{R} \\arrow[r] & \\hat{M}\n\t\\end{tikzcd}\\]\n\tThe upper horizontal arrow is an isomorphism by Theorem \\ref{prop:completion-tensor}, therefore the diagonal arrow has image equal to $\\mathfrak{a}\\hat{M}$. The lower horizontal arrow is just the completion of $\\mathfrak{a}M \\hookrightarrow M$, thus injective with image $(\\mathfrak{a}M)^\\wedge$ by Proposition \\ref{prop:completion-exactness}. A comparison yields $(\\mathfrak{a}M)^\\wedge = \\mathfrak{a}\\hat{M}$. Also note that $\\hat{\\mathfrak{a}}\\hat{M} = \\mathfrak{a}\\hat{R}\\hat{M} = \\mathfrak{a}\\hat{M}$. The final assertion results from the exactness of completion.\n\\end{proof}\nSince the $I$-adic topology on $M/I^n M$ is discrete, as a special case ($\\mathfrak{a} = I^n$) we deduce the natural identifications\n\\begin{gather*}\n\tM/I^n M = \\hat{M}/I^n \\hat{M} = \\hat{M}/\\hat{I}^n \\hat{M}, \\quad \\forall n \\geq 0, \\\\\n\t\\gr_I(R) = \\gr_I(\\hat{R}) = \\gr_{\\hat{I}}(\\hat{R}), \\\\\n\t\\gr_I(M) = \\gr_I(\\hat{M}) = \\gr_{\\hat{I}}(\\hat{M}).\n\\end{gather*}\n\n\\begin{proposition}\\label{prop:completion-top}\n\tFor any finitely generated $R$-module $M$, the topology on $\\hat{M}$ coincides with the $\\hat{I}$-adic one.\n\\end{proposition}\n\\begin{proof}\n\tConsider the closure of the image of $I^n M$ in $\\hat{M}$. It is readily seen to be $\\{(x_k)_k: i \\leq n \\implies x_i=0 \\} = F^n \\hat{M}$. On the other hand, we have seen that this closure is $\\widehat{I^n M} \\subset \\hat{M}$. By virtue of Proposition \\ref{prop:completion-aux}, we have $\\widehat{I^n M} = \\widehat{I^n}\\hat{M}$ and $\\widehat{I^n} = I^n \\hat{R} = (I\\hat{R})^n = \\hat{I}^n$.\n\\end{proof}\n\n\\begin{lemma}\\label{prop:gr-surjective}\n\tConsider a homomorphism $\\varphi: L \\to N$ between filtered modules over some ring, such that $L$ is complete, $N$ is Hausdorff and exhaustive (see \\S\\ref{sec:Artin-Rees}) with respect to their filtrations, and $\\gr(\\varphi): \\gr(L) \\to \\gr(N)$ is surjective. Then $\\varphi$ is also surjective.\n\\end{lemma}\n\\begin{proof}\n\tLet $y \\in F^d N$, we may take $x \\in F^d L$ such that $y' := y- \\varphi(x) \\in F^{d+1} N$. Next, take $x' \\in F^{d+1} L$ with $y'' := y' -  \\varphi(x') \\in F^{d+2} N$, and so forth. Use the completeness of $L$ to define $x_\\infty := x + x' + x'' + \\cdots$, which maps to $y$ since $N$ is Hausdorff.\n\\end{proof}\n\n\\begin{proposition}\\label{prop:completion-rad}\n\tThe ring $\\hat{R}$ is also Noetherian, and $\\hat{I} \\subset \\mathrm{rad}(\\hat{R})$.\n\\end{proposition}\n\\begin{proof}\n\tLet $\\mathfrak{A}$ be any ideal of $\\hat{R}$, equipped with the filtration $F^n \\mathfrak{A} := \\hat{I}^n \\cap \\mathfrak{A}$. We have to show $\\mathfrak{A}$ is finitely generated. Since $\\gr_I(R) = \\gr_{\\hat{I}}(\\hat{R})$ is Noetherian, so is $\\gr_F(\\mathfrak{A})$. Take $t_1, \\ldots, t_n \\in \\mathfrak{A}$, $t_i \\in F^{d_i} \\mathfrak{A}$, whose images $\\bar{t}_i$ in $\\gr^{d_i}_F(\\mathfrak{A})$ generates $\\gr_F(\\mathfrak{A})$. Using an appropriately shifted filtration on $L := \\hat{R}^{\\oplus n}$, we obtain a filtered homomorphism $\\varphi: L \\to  \\mathfrak{A}$ with image $(t_1, \\ldots, t_n)$, such that $\\gr(\\varphi)$ is surjective. Now apply the previous Lemma to obtain the first assertion.\n\t\n\tOne of the characterizations of Jacobson radical says that $\\hat{I} \\subset \\mathrm{rad}(\\hat{R})$ if and only if $1 - \\hat{I} \\subset \\hat{R}^\\times$. This is verified by noting that $(1-t)^{-1} = 1+t+t^2+ \\cdots$ converges $I$-adically. This proves the second assertion.\n\\end{proof}\n\n\\begin{proposition}\\label{prop:completion-semilocal}\n\tThe map $\\mathfrak{p} \\mapsto \\hat{\\mathfrak{p}}$ furnishes an injection from $V(I)$ to $\\Spec(\\hat{R})$ satisfying $R/\\mathfrak{p} \\simeq \\hat{R}/\\hat{\\mathfrak{p}}$ (as rings). It restricts to a bijection $\\MaxSpec(R) \\cap V(I) \\xrightarrow{1:1} \\MaxSpec(\\hat{R})$.\n\n\tConsequently, if $R$ is local (resp. semi-local), so is $\\hat{R}$.\n\\end{proposition}\n\\begin{proof}\n\tSince $\\mathfrak{p} \\supset I$, the $I$-adic topology on $R/\\mathfrak{p}$ is discrete. By Proposition \\ref{prop:completion-aux}, $\\hat{R}/\\hat{p} \\simeq (R/\\mathfrak{p})^\\wedge = R/\\mathfrak{p}$, and here the isomorphism even respects ring structures. Therefore $\\hat{\\mathfrak{p}}$ is a prime ideal. Moreover, it is maximal if and only if $\\mathfrak{p}$ is. Claim: $\\mathfrak{p}$ is the preimage of $\\hat{\\mathfrak{p}} = \\varprojlim_n \\mathfrak{p}/(I^n \\cap \\mathfrak{p})$ under $R \\to \\hat{R} = \\varprojlim_n R/I^n$. Indeed, lying in that preimage amounts to $x \\in I^n + \\mathfrak{p} = \\mathfrak{p}$, for all $n \\geq 1$. Injectivity follows.\n\n\tLemma \\ref{prop:completion-rad} implies that every $\\mathfrak{A} \\in \\MaxSpec(\\hat{R})$ contains $\\hat{I}$, therefore is open by Proposition \\ref{prop:completion-top}. Since $\\hat{R}$ is Noetherian, $\\mathfrak{A}$ is also closed by Corollary \\ref{prop:completion-auto}. As $R \\to \\hat{R}$ has dense image, we conclude that $\\mathfrak{A}$ equals the completion of its preimage $\\mathfrak{m} \\in V(I) \\subset \\Spec(R)$. By the previous paragraph, $\\mathfrak{m}$ is a maximal ideal.\n\\end{proof}\n\n\\section{Hilbert--Samuel polynomials}\nFor a graded ring $R = \\bigoplus_\\gamma R_\\gamma$ (we always assume $1 \\in R_0$) and a given $\\eta$, we may define its twist $R(\\eta)$ as the graded $R$-module\n\\[ R(\\eta)_\\gamma := R_{\\gamma+\\eta}. \\]\n\nTo generate a graded $R$-module $M$ by finitely many homogeneous elements $x_1, \\ldots, x_n$, of degrees $\\eta_1, \\ldots, \\eta_n$ respectively, is equivalent to giving a surjection of graded $R$-modules\n\\begin{equation}\\label{eqn:homogeneous-generation} \\begin{tikzcd}[row sep=tiny]\n\t\\bigoplus_{i=1}^n R(-\\eta_i) \\arrow[r, twoheadrightarrow] & M \\\\\n\t(\\ldots, 0, \\underbracket{1}_{i-\\text{th slot}}, 0, \\ldots) \\arrow[r, mapsto] & x_i.\n\\end{tikzcd}\\end{equation}\n\nHereafter, we assume that\n\\begin{itemize}\n\t\\item everything is graded by $\\Gamma = (\\Z^N_{\\geq 0}, +)$ for some fixed $N$,\n\t\\item $R_0/R_0 \\cap \\mathrm{ann}(M)$ is an Artinian ring,\n\t\\item $R$ is finitely generated over $R_0$.\n\\end{itemize}\nThe appearance of $\\mathrm{ann}(M)$ is harmless since $R$ can be safely replaced by $R/\\mathfrak{ann}(M)$, which is legitimate since $\\mathrm{ann}(M)$ is a graded ideal of $R$. To see this, write $\\mathrm{ann}(M)$ as the intersection of $\\mathrm{ann}(x)$ where $x$ ranges over the homogeneous elements of $M$, and observe that $\\mathrm{ann}(x)$ must be graded.\n\n\\begin{lemma}\\label{prop:Hilbert-poly-0}\n\tFor $R$ as above and $M$ a finitely generated graded $R$-module, each graded piece $M_\\gamma$ is an $R_0$-module of finite length.\n\\end{lemma}\n\\begin{proof}\n\tUsing \\eqref{eqn:homogeneous-generation} this is readily reduced to the case $M = R(-\\eta)$, and then to $M=R$. Write $R = R_0[x_1, \\ldots, x_n]$ where each $x_i$ is homogeneous of degree $d_i$. Given $\\gamma$, the $R_0$-module $M_\\gamma$ is generated by monomials $x_1^{a_1} \\cdots x_n^{a_n}$ with $\\sum_i a_i d_i = \\gamma$ and $a_1, \\ldots, a_n \\in \\Z_{\\geq 0}$; this admits only finitely many solutions $(a_1, \\ldots, a_n)$. We conclude that $M_\\gamma$ has finite length since $R_0/R_0 \\cap \\text{ann}(M)$ is an Artinian ring.\n\\end{proof}\n\nRecall that saying a module $N$ over a ring $A$ has finite length means that there exists a composition series\n\\[ N = N_0 \\supset \\cdots \\supset N_n = \\{0\\}, \\quad \\forall N_i/N_{i+1} \\text{ is simple.} \\]\nThe unique number (Jordan--Hölder Theorem) is called the \\emph{length} of $N$, denoted by $\\ell_A(N)$. The length function is additive in short exact sequences. When $A$ is a field we have $\\ell_A = \\dim_A$. \\index{length}\n\n\\begin{definition}\n\tFor $R$ and $M$ as in Lemma \\ref{prop:Hilbert-poly-0}, we define the functions\n\t\\[ \\chi(M, \\gamma) := \\ell_{R_0}(M_\\gamma), \\quad \\gamma \\in \\Gamma := \\Z_{\\geq 0}^N \\]\n\twith values in $\\Z_{\\geq 0}$.\n\\end{definition}\nOne sees immediately that for a short exact sequence $0 \\to M' \\to M \\to M'' \\to 0$ of finitely generated graded $R$-modules, we have $\\chi(M,\\gamma) = \\chi(M',\\gamma) + \\chi(M'',\\gamma)$ for all $\\gamma \\in \\Gamma$. This extends to alternating sums of $\\chi$ in finite exact sequences.\n\nOne can control the behavior of $\\chi(M, \\cdot)$ by forming the Poincaré series $P_M(\\mathbf{X}) = \\sum_{\\gamma \\in \\Gamma} \\chi(M,\\gamma) \\mathbf{X}^\\gamma$; see \\cite[6.D]{BG09}. Here we shall restrict to the case $N=1$, i.e. $\\Gamma = \\Z_{\\geq 0}$, in order to gain more control of $\\chi(M,\\gamma)$. As a preparation, we say a function $H: \\Z \\to \\CC$ is a \\emph{quasi-polynomial} of period $\\varpi$ if its restriction to each congruence class modulo $\\varpi$ coincides with a polynomial function (necessarily unique); the degree of $\\chi$ is defined by taken the maximum among congruence classes. In particular, a quasi-polynomial of period $1$ is just a polynomial.\n\n\\begin{theorem}\n\tAssume $\\Gamma = \\Z_{\\geq 0}$. Suppose $R$ is generated by homogeneous elements $x_1, \\ldots, x_n$ over $R_0$. There exists a unique quasi-polynomial $H_M$ of degree $\\leq n-1$, with coefficients in $\\Q$ and period $e := \\mathrm{lcm}(\\deg x_1, \\ldots, \\deg x_n)$, such that\n\t\\[ \\chi(M, \\gamma) = H_M(\\gamma), \\quad |\\gamma| \\gg 0. \\]\n\\end{theorem}\n\\begin{proof}\n\tUniqueness is clear. We construct $H_M$ by induction on the minimal number of generators $n$. If $n=0$ then $R = R_0$ and $M_\\gamma = 0$ for $|\\gamma| \\gg 0$, in which case $H_M = 0$.\n\n\tFor $n \\geq 1$, write $R = R_0[x_1, \\ldots, x_n]$ as usual. We may assume that $x_i \\neq 0$ has degree $\\eta_i$, for $i=1,\\ldots,n$. Fix $i$ and define the graded modules\n\t\\[ Z := \\Ker\\left( M \\xrightarrow{\\cdot x_i} M(\\eta_i) \\right), \\quad Y := \\Coker\\left( M(-\\eta_i) \\xrightarrow{\\cdot x_i} M \\right) \\]\n\twhich are again finitely generated, so that we have the exact sequence\n\t\\[ 0 \\to Z_\\gamma \\to M_\\gamma \\to M_{\\gamma + \\eta_i} \\to Y_{\\gamma + \\eta_i} \\to 0, \\quad \\gamma \\in \\Gamma. \\]\n\tSince $x_i$ annihilates $Z$ and $Y$, induction hypothesis entails\n\t\\[ \\chi(M, \\gamma+\\eta_i) - \\chi(M, \\gamma) = \\chi(Y, \\gamma+\\eta_i) - \\chi(Z, \\gamma), \\]\n\tthe right-hand side being quasi-polynomials of period $\\text{lcm}(\\ldots, \\widehat{\\eta_i}, \\ldots)$ for large $|\\gamma|$ and of degrees $\\leq n-2$, since $x_i$ acts trivially on $Z$ and $Y$. Doing this for all $i$ yields difference equations that witness the polynomiality of $\\chi(M, \\gamma)$ for $|\\gamma| \\gg 0$ in every congruence class modulo $e$.\n\\end{proof}\nIn particular, if $R$ is generated by $R_1$ over $R_0$, the period $e=1$ and we have the notion of \\emph{Hilbert--Samuel polynomials}.\\index{Hilbert--Samuel polynomial}\n\n\\begin{example}\\label{eg:count-monomials}\n\tFor $R = M = \\Bbbk[X_1, \\ldots, X_n]$ graded by total degree, where $\\Bbbk$ is a field, our assumptions are readily verified. We see $\\chi(M, \\gamma) = \\dim_{\\Bbbk} \\Bbbk[X_1, \\ldots, X_n]_{\\deg=\\gamma}$ for all $\\gamma \\in \\Z_{\\geq 0}$, which equals $\\binom{\\gamma + n - 1}{n- 1}$ by high school combinatorics. Hence the Hilbert--Samuel polynomial is $H_M(X) = \\binom{X+n-1}{n-1} \\in \\Q[X]$.\n\\end{example}\n\n\\section{Definition of Krull dimension}\\label{sec:Krull-dimension}\nLet $R$ be a ring.\n\n\\begin{definition}[Height and dimension]\\label{def:height-dimension}\\index{height}\\index{dimension}\n\tFor any prime ideal $\\mathfrak{p}$ of $R$, define its \\emph{height} $\\text{ht}(\\mathfrak{p})$ as the supremum of the lengths of prime chains\n\t\\[ \\mathfrak{p} = \\mathfrak{p}_0 \\supsetneq \\mathfrak{p}_1 \\supsetneq \\cdots \\supsetneq \\mathfrak{p}_n, \\quad \\text{length} := n. \\]\n\tFor any ideal $\\mathfrak{a}$ of $R$, we define $\\text{ht}(\\mathfrak{a}) := \\inf\\{ \\text{ht}(\\mathfrak{p}) : \\mathfrak{p} \\supset \\mathfrak{a} \\}$.\n\t\n\tDefine the \\emph{Krull dimension} of $R$ to be $\\dim R := \\sup_{\\mathfrak{p} \\in \\Spec(R)} \\text{ht}(\\mathfrak{p})$.\n\\end{definition}\n\nThe following results are immediate.\n\\begin{itemize}\n\t\\item The zero prime in a domain has height $0$.\n\t\\item Fields have dimension zero. In fact, a ring has dimension zero if and only if every prime ideal is maximal.\n\t\\item We have $\\text{ht}(\\mathfrak{p}) = \\dim R_{\\mathfrak{p}}$ for every prime ideal $\\mathfrak{p} \\subset R$.\n\t\\item For any ideal $\\mathfrak{a}$ we have $\\dim R \\geq \\dim(R/\\mathfrak{a}) + \\text{ht}(\\mathfrak{a})$.\n\\end{itemize}\n\n\\begin{exercise}\n\tVerify the last property above.\n\\end{exercise}\n\n\\begin{exercise}\n\tShow that every principal ideal domain which is not a field has dimension one.\n\\end{exercise}\n\nMore generally, we define the dimension of an $R$-module $M$ as\n\\[ \\dim M := \\dim(R/\\text{ann}(M)), \\quad \\dim\\{0\\} := -\\infty . \\]\nFor a short exact sequence $0 \\to M' \\to M \\to M'' \\to 0$ we have $\\dim M', \\dim M'' \\leq \\dim M$.\n\n\\begin{lemma}\\label{prop:dim-M-equiv}\n\tSuppose $R$ is Noetherian. The following are equivalent for a finitely generated $R$-module $M \\neq \\{0\\}$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\dim M = 0$.\n\t\t\\item $R/\\mathrm{ann}(M)$ is Artinian.\n\t\t\\item $M$ has finite length.\n\t\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n\t(i) $\\iff$ (ii) is already known: recall that a Noetherian ring is Artinian if and only if its prime ideals are all maximal (Corollary \\ref{prop:Artinian-dim-0}). Let us show (i) or (ii) $\\implies$ (iii). By writing $M = M_1 + \\cdots + M_n$ where each $M_i$ is generated by one element,  we may assume $M \\simeq R/\\mathfrak{a}$ for some ideal $\\mathfrak{a} = \\text{ann}(M)$. It has been shown that $R/\\mathfrak{a}$ has finite length as a module since it is an Artinian ring.\n\t\n\t(iii) $\\implies$ (i). Upon modulo $\\text{ann}(M)$ we may assume $\\text{ann}(M)=\\{0\\}$. Take any minimal prime $\\mathfrak{p}$ in $R$. As $\\text{ann}(M) = \\{0\\}$ we have $M_{\\mathfrak{p}} \\neq \\{0\\}$. Therefore $\\mathfrak{p}$ is a minimal element of $\\Supp(M)$, hence belongs to $\\text{Ass}(M)$. We may embed $R/\\mathfrak{p}$ into $M$. The $R$-module $R/\\mathfrak{p}$ has finite length since $M$ does, therefore $R/\\mathfrak{p}$ is an Artinian ring. This implies $\\mathfrak{p}$ is a maximal ideal, therefore $\\dim R = 0$ since every prime in $R$ lies over a minimal prime.\n\\end{proof}\n\nOur strategy is to study the Krull dimension via completions and Hilbert polynomials. As a preparation, we begin with the local, or more generally the semi-local rings.\n\n\\begin{definition}\\index{parameter ideal}\n\tLet $R$ be a Noetherian semi-local ring (i.e. there are finitely many maximal ideals $\\mathfrak{m}_1, \\ldots, \\mathfrak{m}_n$). Let $M \\neq \\{0\\}$ be a finitely generated $R$-module. We say an ideal $I$ is a \\emph{parameter ideal} for $M$ if $I \\subset \\text{rad}(R)$ and $M/IM$ has finite length.\n\\end{definition}\nParameter ideals are often called \\emph{ideals of definition}. Here we follow the terminologies of \\cite{Eis95}.\n\n\\begin{exercise}\n\tShow that $I$ is a parameter ideal for $R$ if and only if there exists $k$ with\n\t\\[ \\text{rad}(R)^k \\subset I \\subset \\text{rad}(R). \\]\n\tShow that such an ideal is a parameter ideal for every $M$. Hint: If $I \\supset \\text{rad}(R)^k$, every prime ideal $\\mathfrak{p} \\supset I$ must contain $(\\mathfrak{m}_1 \\cdots \\mathfrak{m}_n)^k$, hence $\\mathfrak{p} = \\mathfrak{m}_i$ for some $i$. Conversely, show that in an Artinian ring we have $\\text{rad}(R)^k = 0$ for $k \\gg 0$, using Corollary \\ref{prop:Artinian-dim-0}. Hint: for Artinian rings, $\\text{rad}(R)$ equals the nilpotent radical, and is finitely generated.\n\\end{exercise}\n\nDimension theory for modules can be built solely on the parameter ideals for $R$, but we opt to introduce the general notion here.\n\nHereafter we fix a Noetherian semi-local ring $R$ and a finitely generated $R$-module $M \\neq \\{0\\}$.\n\n\\begin{lemma}\\label{prop:para-ideal-characterization}\n\tAn ideal $I \\subset \\mathrm{rad}(R)$ is a parameter ideal for $M$ if and only if there exists $k$ with $\\mathrm{rad}(R)^k \\subset I + \\mathrm{ann}(M)$. In this case $R/(I+\\mathrm{ann}(M))$ is an Artinian ring.\n\t\n\tIn particular, $\\mathrm{rad}(R)$ is a parameter ideal for any $M$.\n\\end{lemma}\n\\begin{proof}\n\tFirst we claim that $V(\\text{ann}(M/IM)) = \\Supp(M/IM)$ equals $V(I+\\text{ann}(M))$. By the exactness of localizations together with Nakayama's Lemma, we have\n\t\\[ \\Supp(M/IM) = \\Supp(M) \\cap \\left\\{ \\mathfrak{p}: IR_{\\mathfrak{p}} \\subsetneq R_{\\mathfrak{p}} \\right\\}; \\]\n\tthe last term equals $\\Supp(M) \\cap V(I) = V(\\text{ann}(M)+I)$, thereby proving our claim. By applying to $M/IM$ the Lemma \\ref{prop:dim-M-equiv}, $I \\subset \\text{rad}(R)$ being a parameter ideal for $M$ is equivalent to any one of the following\n\t\\begin{align*}\n\t\t\\frac{R}{\\text{ann}(M/IM)} \\text{ is Artinian} & \\iff V(\\text{ann}(M/IM)) \\subset \\MaxSpec(R) \\\\\n\t\t& \\iff V(I+\\text{ann}(M)) \\subset \\MaxSpec(R) \\\\\n\t\t& \\iff \\bar{R} := \\frac{R}{I+\\text{ann}(M)} \\text{ is Artinian}.\n\t\\end{align*}\n\tIf $\\bar{R}$ is Artinian, then the image of $\\text{rad}(R)$ in $\\bar{R}$ is contained in $\\text{rad}(\\bar{R})$, and we know $\\text{rad}(\\bar{R})^k = 0$ for large $k$.\n\t\n\tConversely, suppose $\\text{rad}(R)^k \\subset I + \\text{ann}(M)$. We claim that $R/\\text{rad}(R)^k$ is Artinian: $\\mathrm{rad}(R)$ contains the product $\\mathfrak{m}_1 \\cdots \\mathfrak{m}_k$ of all maximal ideals, so every over-prime of $\\text{rad}(R)^k$ is some $\\mathfrak{m}_i$, thus maximal. This shows that $M/IM$ has finite length by the previous equivalences and Lemma \\ref{prop:dim-M-equiv}.\n\\end{proof}\n\nGiven an parameter ideal $I$ for $M$. The $I$-adic grading gives rise to the graded objects\n\\[ \\gr_I(R) = \\bigoplus_{n \\geq 0} \\frac{I^n}{I^{n+1}}, \\quad \\gr_I(M) = \\bigoplus_{n \\geq 0} \\frac{I^n M}{I^{n+1}M}. \\]\n\nRecall that\n\\begin{compactitem}\n\t\\item $\\gr_I(R)$ is finitely generated over $\\gr^0_I(R) = R/I$ as an algebra and is Noetherian (Proposition \\ref{prop:gr-Noetherian});\n\t\\item more precisely, $\\gr_I(R)$ is generated by $\\gr^1_I(R)$ over $R/I$.\n\t\\item $\\gr_I(M)$ is a finitely generated $\\gr_I(R)$-module (Proposition \\ref{prop:gr-fg});\n\t\\item the ring $\\gr^0_I(R) = R/I$ becomes Artinian after modulo $\\gr^0_I(R) \\cap \\text{ann}(\\gr_I(M))$, which contains $(\\text{ann}(M)+I)/I$ (use Lemma \\ref{prop:para-ideal-characterization}).\n\\end{compactitem}\nUpon recalling Lemma \\ref{prop:Hilbert-poly-0}, it are justified to define\n\\[ \\chi(M, I; n) := \\ell_{R/I^n}(M/I^n M) = \\sum_{j=0}^{n-1} \\ell_{R/I}(I^j M/I^{j+1} M), \\quad n \\in \\Z_{\\geq 0}. \\]\nBy the theory of Hilbert--Samuel polynomials, $n \\mapsto \\chi(M,I; n)$ is a polynomial $H_I(M, \\cdot)$ whenever $n \\gg 0$, with $\\deg H_I(M, \\cdot)$ bounded by the minimal number of generators of $\\gr_I(R)$ over $\\gr^0_I(R) = R/I$.\n\\begin{lemma}\\label{prop:Hilbert-poly-I}\n\tLet $M \\neq \\{0\\}$ be a finitely generated $R$-module with parameter ideal $I$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item The degree $d(M)$ of $H_I(M, \\cdot)$ is independent of the choice of the parameter ideal $I$.\n\t\t\\item In a short exact sequence $0 \\to M' \\to M \\to M'' \\to 0$ of finitely generated $M$-modules, we have\n\t\t\\[ \\deg H_I(M', \\cdot), \\deg H_I(M'', \\cdot) \\leq \\deg H_I(M, \\cdot), \\]\n\t\tand $H_I(M, \\cdot) - H_I(M', \\cdot) - H_I(M'', \\cdot)$ has degree $< d(M)$.\n\t\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n\t(i): To compare the graded objects associated to two parameter ideals $I, J$, we apply the characterization in Lemma \\ref{prop:para-ideal-characterization}: it suffices to take $J = \\mathrm{rad}(R)$, so that\n\t\\[ J^m + \\text{ann}(M) \\subset I + \\text{ann}(M) \\subset J + \\text{ann}(M) \\]\n\tfor some $m \\geq 1$. This implies $\\chi(M,J; n) \\leq \\chi(M,I;n)$ and $\\chi(M,I;n) \\leq \\chi(M,J;mn)$ for all $n \\geq 0$. Whence (i).\n\n\t(ii): For the first part, note that $M/I^n M \\to M''/I^n M''$ is surjective, so $\\chi(M'', I; n) \\leq \\chi(M, I; n)$. On the other hand, $M'/I^n M' \\to M/I^n M$ has kernel $\\frac{M' \\cap I^n M}{I^n M'}$. For $n \\geq n_0 \\gg 0$, Artin--Rees (Theorem \\ref{prop:Artin-Rees}) gives\n\t\\begin{multline*}\n\t\t\\ell\\left(\\frac{M' \\cap I^n M}{I^n M'}\\right) = \\ell\\left(\\frac{I^{n - n_0}(M' \\cap I^{n_0} M)}{I^n M'}\\right) \\leq \\ell\\left(\\frac{I^{n - n_0} M'}{I^n M'}\\right) \\\\\n\t\t= \\ell\\left( \\frac{M'}{I^n M'} \\right) - \\ell\\left( \\frac{M'}{I^{n - n_0} M'}\\right) = \\chi(M', I; n) - \\chi(M', I; n-n_0)\n\t\\end{multline*}\n\twhich has degree inferior to $H_I(M', \\cdot)$. Hence $\\deg H_I(M', \\cdot) \\leq \\deg H_I(M, \\cdot)$.\n\n\tTo establish the second part of (ii), we consider $\\chi(M, I; n) - \\chi(M'', I; n)$ which equals\n\t\\begin{gather*}\n\t\t\\ell\\left(\\frac{M}{I^n M}\\right) - \\ell\\left( \\frac{M}{M' + I^n M} \\right) = \\ell\\left( \\frac{M' + I^n M}{I^n M} \\right) = \\ell\\left( \\frac{M'}{M' \\cap I^n M} \\right).\n\t\\end{gather*}\n\tBy Artin--Rees, the rightmost term is squeezed between $\\ell(M'/I^n M') = \\chi(M',I; n)$ and $\\ell( M'/I^{n-k} M') = \\chi(M', I; n-k)$ for some $k$ independent of $n \\gg 0$. Hence $\\chi(M, I; n) - \\chi(M'', I; n)$ is a polynomial with the same leading term as $\\chi(M', I; n)$, for $n \\gg 0$.\n\\end{proof}\n\nDefine $s(M)$ to be the smallest integer $s$ such that there exist $t_1, \\ldots, t_s \\in \\text{rad}(R)$ with $M/\\sum_{i=1}^s t_i M$ of finite length. In other words, $s(M)$ is the minimal number of generators for parameter ideals for $M$. Observe that $M/\\sum_{i=1}^s t_i M \\neq \\{0\\}$, otherwise Nakayama's Lemma will lead to $M = \\{0\\}$.\n\n\\begin{theorem}\\label{prop:dim-s-d}\n\tFor any finitely generated nonzero $R$-module $M$, we have $\\dim M = s(M) = d(M)$. In particular $\\dim M$ is finite.\n\\end{theorem}\n\\begin{proof}\n\tWe argue inductively on $d(M)$ to show $\\dim M \\leq d(M)$. If $d(M)=0$ then $I^n M = I^{n+1} M = \\cdots$ for $n \\gg 0$. Corollary \\ref{prop:Krull-intersection-rad} implies $I^n M = \\{0\\}$, hence $M=M/I^n M$ has finite length and $\\dim M = 0$ by Lemma \\ref{prop:dim-M-equiv}.\n\t\n\tNow assume $d(M) \\geq 1$. Take a minimal $\\mathfrak{p} \\in \\text{Ass}(M)$ verifying $\\dim(R/\\mathfrak{p}) = \\dim M$, so that $R/\\mathfrak{p} \\hookrightarrow M$. As $d(R/\\mathfrak{p}) \\leq d(M)$, we are reduced to the case $M = R/\\mathfrak{p}$. Consider a chain of prime ideals\n\t\\[ \\mathfrak{p} = \\mathfrak{p}_0 \\subsetneq \\cdots \\subsetneq \\mathfrak{p}_m \\]\n\tin $R$. We claim that $m \\leq d(R/\\mathfrak{p})$. We may surely suppose $m \\geq 1$. Take $t \\in \\mathfrak{p}_1 \\smallsetminus \\mathfrak{p}_0$. Reduction modulo $Rt + \\mathfrak{p}$ yields a prime chain of length $m-1$, namely\n\t\\[ \\frac{\\mathfrak{p}_1}{Rt + \\mathfrak{p}} \\subsetneq \\cdots \\frac{\\mathfrak{p}_m}{Rt + \\mathfrak{p}} \\]\n\tin $R/(Rt + \\mathfrak{p})$. Hence $\\dim(R/Rt+\\mathfrak{p}) \\geq m-1$. In view of the exactness of\n\t\\[ 0 \\to R/\\mathfrak{p} \\xrightarrow{t} R/\\mathfrak{p} \\to \\frac{R}{Rt+\\mathfrak{p}} \\to 0, \\]\n\tLemma \\ref{prop:Hilbert-poly-I} (ii) implies that $d(R/Rt+\\mathfrak{p}) < d(R/\\mathfrak{p})$. By induction we deduce $d(R/\\mathfrak{p}) > d(R/Rt+\\mathfrak{p}) \\geq \\dim(R/Rt+\\mathfrak{p}) \\geq m-1$, hence $d(R/\\mathfrak{p}) \\geq m$ as required.\n\t\n\tNext, let us show $s(M) \\leq \\dim M$. Set $r := \\dim M$. We contend that there exist $t_1, \\ldots, t_r \\in \\text{rad}(R)$ such that $M/(t_1, \\ldots, t_r)M$ has finite length; therefore $s \\leq r$. When $r=0$ this follows from Lemma \\ref{prop:dim-M-equiv}. For $r > 0$, we have $\\text{rad}(R) \\not\\subset \\mathfrak{p}$ for any minimal $\\mathfrak{p} \\in \\text{Ass}(M)$ verifying $\\dim R/\\mathfrak{p} = \\dim M$, for otherwise $\\mathfrak{p}$ will contain, thus equal to a maximal ideal as $R$ is semi-local, and we would get $\\dim M = 0$. Using prime avoidance (Proposition \\ref{prop:prime-avoidance} applied to $I := \\mathrm{rad}(R)$ and the primes $\\mathfrak{p}$ above), we may pick $t_1 \\in \\text{rad}(R)$ that does not belong to any $\\mathfrak{p}$ above. From $\\text{ann}(M/t_1 M) \\supset Rt_1 + \\text{ann}(M)$ and our choice of $t_1,$, we see $\\dim M/t_1 M < \\dim M$. Our claim results from induction on $r$.\n\t\n\tWe finish the proof by showing $d(M) \\leq s(M)$. Suppose $M/\\sum_{i=1}^s t_i M \\neq \\{0\\}$ has finite length. We contend that for any $t \\in \\text{rad}(R)$ we have\n\t\\begin{gather}\\label{eqn:d-drop}\n\t\td(M) \\geq d(M/tM) \\geq d(M)-1.\n\t\\end{gather}\n\tIf this holds, we can look at the sequence $M, M/t_1 M, M/(t_1M + t_2 M), \\ldots$: at each step $d(\\cdots)$ drops at most by one; at the end $L := M/\\sum_{j=1}^s t_j M$ we have $d(L)=0$: indeed, as $L$ has finite length, $\\ell(L/I^n L)$ is uniformly bounded by $\\ell(L)$ so that $d(L)=0$. Thus $d(M) \\leq s$ as expected.\n\t\n\tTo prove \\eqref{eqn:d-drop}, first note that $d(M) \\geq d(M/tM)$ is known. Take any parameter ideal $I \\ni t$. We bound $\\chi(M/tM, I; n)$ as follows\n\t\\[ \\ell\\left( \\frac{M}{tM + I^n M} \\right) = \\ell\\left( \\frac{M}{I^n M} \\right) - \\ell\\left( \\frac{tM + I^n M}{I^n M} \\right). \\]\n\tNote that\n\t\\begin{align*}\n\t\t\\frac{M}{I^{n-1} M}\\twoheadrightarrow \\frac{M}{ \\{ x \\in M : tx \\in I^n M \\} } & \\rightiso \\frac{tM}{tM \\cap I^n M} \\simeq \\frac{tM + I^n M}{I^n M} \\\\\n\t\ty & \\mapsto ty.\n\t\\end{align*}\n\tHence $\\chi(M/tM, I; n) \\geq \\chi(M, I; n) - \\chi(M, I; n-1)$ for $n \\gg 0$, proving the second inequality in \\eqref{eqn:d-drop}.\n\\end{proof}\n\n\\begin{corollary}\n\tUnder the same assumptions, we have $\\dim_R M = \\dim_{\\hat{R}} \\hat{M}$, where we take $I$-adic completions.\n\\end{corollary}\n\\begin{proof}\n\tProposition \\ref{prop:completion-aux} gives identifications $\\gr_I(R) = \\gr_{\\hat{I}}(\\hat{R})$ and $\\gr_I(M) = \\gr_{\\hat{I}}(\\hat{M})$; moreover $\\hat{R}$ is still semi-local and $\\hat{I}$ is still a parameter ideal for $\\hat{M}$ (see Proposition \\ref{prop:completion-rad}, \\ref{prop:completion-semilocal}). Since $d(M)$ and $d(\\hat{M})$ are read from these graded modules, they are equal.\n\\end{proof}\n\nThese results will be applied to the case $M=R$ in the next section.\n\n\\section{Krull's theorems and regularity}\nWe still assume $R$ is a Noetherian ring.\n\n\\begin{theorem}[Krull]\n\tSuppose $\\mathfrak{a} = (t_1, \\ldots, t_r)$ is a proper ideal of $R$, then for every minimal over-prime ideal $\\mathfrak{p}$ of $\\mathfrak{a}$, we have $\\mathrm{ht}(\\mathfrak{p}) \\leq r$.\n\\end{theorem}\nFrom Definition \\ref{def:height-dimension} we infer that $\\text{ht}(\\mathfrak{a}) \\leq r$. The special case $r=1$ says that every principal ideal $(t) \\neq R$ has height at most one (exactly one if $t$ is not a zero divisor --- use Theorem \\ref{prop:Ass-properties} (ii)); this is called the Hauptidealsatz.\\index{Hauptidealsatz}\n\\begin{proof}\n\tWe work in $R_{\\mathfrak{p}}$ and $I := \\mathfrak{a} R_{\\mathfrak{p}} = (t_1, \\ldots, t_r)$. Since $I \\subset \\text{rad}(R_{\\mathfrak{p}})$ and $R_{\\mathfrak{p}}/I$ has dimension zero, thus Artinian, $I$ is a parameter ideal. We conclude by Theorem \\ref{prop:dim-s-d} and $\\text{ht}(\\mathfrak{p}) = \\dim R_{\\mathfrak{p}}$.\n\\end{proof}\n\nNow assume $R$ is Noetherian and local with maximal ideal $\\mathfrak{m}$. The parameter ideals of $R$ are precisely those squeezed between $\\mathfrak{m}$ and $\\mathfrak{m}^k$ for some $k \\geq 1$, by Lemma \\ref{prop:para-ideal-characterization}. Set $d := \\dim R$, which is finite by Theorem \\ref{prop:dim-s-d}. The same theorem tells us that we can generate some parameter ideal $I \\subset \\mathfrak{m}$ (namely $R/I$ Artinian) by elements $t_1, \\ldots, t_d \\in \\mathfrak{m}$. These elements form a \\emph{system of parameters} of $R$.\n\n\\begin{proposition}\\label{prop:system-parameter}\n\tSuppose $R$ is a Noetherian local ring with a system of parameters $t_1, \\ldots, t_d$, which generate a parameter ideal $I$. For any $0 \\leq i \\leq d$ we have $\\dim(R/(t_1, \\ldots, t_i)) = d-i$, and $t_{i+1}, \\ldots, t_d$ form a system of parameters for $R/(t_1, \\ldots, t_i)$.\n\\end{proposition}\n\\begin{proof}\n\tConsider the sequence $R, R/(t_1), R/(t_1, t_2), \\ldots, R/(t_1, \\ldots, t_d)$. Recall the formalism in Theorem \\ref{prop:dim-s-d}: at each stage $d(R/\\cdots)$ drops at most by one, by \\eqref{eqn:d-drop}. After $d$ steps we arrive at $R/I$ with $\\dim(\\cdot)=d(\\cdot)=s(\\cdot)=0$, since it has finite length. Hence $d$ drops exactly by one at each stage. The remaining assertions are immediate.\n\\end{proof}\n\nA natural question arises: when can we assure $I=\\mathfrak{m}$?\n\\begin{definition}\\index{regular local ring}\n\tWe say a Noetherian local ring $R$ is a \\emph{regular local ring} if $\\mathfrak{m}$ can be generated by $d = \\dim R$ elements $t_1, \\ldots, t_d$. In this case we say $t_1, \\ldots, t_r$ form a \\emph{regular system of parameters}.\n\\end{definition}\nIn particular, $\\mathfrak{m}=\\{0\\}$ if $R$ is regular local with $\\dim R = 0$.\n\n\\begin{exercise}\n\tLet $\\Bbbk$ be a field. The $\\Bbbk$-algebra of formal power series $\\Bbbk\\llbracket X_1, \\ldots, X_d \\rrbracket$ is a regular local ring. Indeed, it is Noetherian with maximal ideal $\\mathfrak{m} = (X_1, \\ldots, X_d)$, and $X_1, \\ldots, X_d$ form a regular system of parameters. On the other hand, $\\mathfrak{m}/\\mathfrak{m}^2$ has a $\\Bbbk$-basis formed by the images of $X_1, \\ldots, X_d$. One way to determine its dimension and prove its regularity is to calculate the functions $n \\mapsto \\dim_\\Bbbk(\\mathfrak{m}^n/\\mathfrak{m}^{n+1})$ explicitly, i.e. count the monomials in $d$ variables with total degree $n$. You should get a polynomial in $n$ with degree $d-1$, cf. Exercise \\ref{eg:count-monomials}.\n\\end{exercise}\n\n\\begin{theorem}\n\tFor any Noetherian local ring $R$ with maximal ideal $\\mathfrak{m}$ and residue field $\\Bbbk$, we have $\\dim R \\leq \\dim_\\Bbbk \\mathfrak{m}/\\mathfrak{m}^2$. Equality holds if and only if $R$ is a regular local ring.\n\\end{theorem}\n\\begin{proof}\n\tBy Nakayama's Lemma (more precisely, Corollary \\ref{prop:NAK-generation}), $\\mathfrak{m}/\\mathfrak{m}^2$ can be generated over $\\Bbbk$ by $s$ elements if and only if $\\mathfrak{m}$ can be generated over $R$ by $s$ elements, for any $s \\in \\Z_{\\geq 0}$. Hence Theorem \\ref{prop:dim-s-d} imposes the bound $s \\geq \\dim R$, and equality holds if and only if $R$ admits a regular system of parameters.\n\\end{proof}\n\n\\begin{figure}[h]\n\t\\centering \\includegraphics[height=130pt]{OZariski.jpg} \\\\ \\vspace{1em}\n\t\\begin{minipage}{0.7\\textwidth}\n\t\t\\small The $\\Bbbk$-vector space $\\mathfrak{m}/\\mathfrak{m}^2$ is called the \\emph{Zariski cotangent space} of $\\Spec(R)$, in honor of Oscar Zariski (1899--1986). Picture taken from \\href{https://commons.wikimedia.org/wiki/File:Oscar_Zariski.jpg}{Wikimedia Commons}.\n\t\\end{minipage}\n\\end{figure}\n\nDue to time constraints, we cannot say too much about regular local rings. Below is one of their wonderful properties.\n\\begin{theorem}\\label{prop:regular-local-domain}\n\tRegular local rings are integral domains.\n\\end{theorem}\n\\begin{proof}\n\tInduction on $d := \\dim R$. If $\\dim R=0$ then $\\mathfrak{m}=\\{0\\}$, hence $R$ is a field. Assume hereafter that $d > 0$. We know there are only finitely many minimal prime ideals and $\\dim_\\Bbbk \\mathfrak{m}/\\mathfrak{m}^2 \\geq 1$. By prime avoidance (Proposition \\ref{prop:prime-avoidance}) applied to $I := \\mathfrak{m}$, the minimal prime ideals and $\\mathfrak{m}^2$, there exists $t \\in \\mathfrak{m} \\smallsetminus \\mathfrak{m}^2$ that does not lie in any minimal prime ideal. Put $R' := R/(t)$ with maximal ideal $\\mathfrak{m}' = \\mathfrak{m}/(t)$; our choice of $t$ together with Proposition \\ref{prop:system-parameter} imply\n\t\\begin{align*}\n\t\t\\dim R' & = \\dim R - 1, \\\\\n\t\t\\dim_\\Bbbk \\mathfrak{m}'/(\\mathfrak{m}')^2 & = \\dim_\\Bbbk \\mathfrak{m}/\\mathfrak{m}^2 - 1 = \\dim R - 1.\n\t\\end{align*}\n\tHence $R'$ is still regular local, and by induction it is a domain. This implies $(t)$ is prime.\n\t\n\tTake any minimal prime $\\mathfrak{p}$ below $(t)$; note that $t \\notin \\mathfrak{p}$ by construction. To show $R$ is a domain it suffices to prove $\\mathfrak{p}=\\{0\\}$. Indeed, every $s \\in \\mathfrak{p}$ can be written as $s=at$, $a \\in R$. Since $t \\notin \\mathfrak{p}$, we must have $a \\in \\mathfrak{p}$. Hence $\\mathfrak{p}=t\\mathfrak{p} \\subset \\mathfrak{m}\\mathfrak{p}$. Nakayama's Lemma (Theorem \\ref{prop:NAK}) implies $\\mathfrak{p} = \\{0\\}$.\n\\end{proof}", "meta": {"hexsha": "9dee4b60619104f744899df26f473502f797a2fd", "size": 45260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "YAlg3-5.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-5.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-5.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": 94.8846960168, "max_line_length": 910, "alphanum_fraction": 0.6767786125, "num_tokens": 16200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198947, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6831501165483028}}
{"text": "\\section{Density Estimation}\n\n% ===\n%\\subsection{Bayesianism / Frequentism}\n\n\\emph{Bayesianism:}\nDefine prior $P(\\theta)$, define likelihood $P(X\\mid\\theta)$, compute posterior $P(\\theta\\mid x_{1...n})$.\n\\\\\n\\textbf{Bayes:}\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:}\n%Define a parametric model $\\theta$ (e.g. $\\Gauss{\\theta,1}$), compute likelihood of data and compute MLE: $\\hat\\theta\\ped{MLE} = \\argmax_\\theta P(y_{1...n}\\mid\\theta)$.\nDefine param. model $P(Y\\mid X,\\theta)$, compute likelihood of data $P(X,Y\\mid\\theta)$ and compute $\\hat\\theta\\ped{MLE}$ via $\\argmax_\\theta$ of likelihood.\n\n% ===\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:}\nIf $\\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_n(\\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} \\overset{n\\to\\infty}{=} \\frac{1}{I_n(\\theta^\\ast)}$ (Rao Cr.)\\\\\nAmong 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\n% ===\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\nScore func.: $\\bm\\Lambda = \\pderiv{\\log\\P{\\bm x\\mid\\theta}}{\\theta}$,\\; $\\E{\\bm\\Lambda} = 0$\n\nFisher info.: $I_n(\\theta) = \\V{\\bm\\Lambda}$\\\\\n$J(\\theta) = \\E{\\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_n - \\theta^\\ast)^2} \\geq \\frac{\\paren*{ 1 + \\frac{\\partial}{\\partial\\theta} \\mathrm{b}_{\\hat\\theta} }^2\\!\\!}{\\E{\\bm\\Lambda^2}} + \\mathrm{b}_{\\hat\\theta}^2$\n\n\\emph{Unbiased case:} $\\E{(\\hat\\theta_n - \\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\n% ===\n", "meta": {"hexsha": "8c1a55bff0df894805b100572b44a71293695c4f", "size": 2689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/02_density_estimation.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/02_density_estimation.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/02_density_estimation.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.7358490566, "max_line_length": 276, "alphanum_fraction": 0.6307177389, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516187, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6831501160387962}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\n\\begin{document}\n\n\\subsection{Motivation}\nThere are several well-known tensor decomposition methods, but there is no clear understanding how they compare in terms of quality. \n\nIn this work we aim to compare different high-order tensor decomposition techniques, provided in HottBox\\footnote{\\url{https://hottbox.github.io/stable/index.html}} tooling. More specifically, we benchmark CPD, Tucker Decomposition and Tensor-Train against three quality criterions: precision, stability and computational complexity.\n\nAs an input data we use Tensor Flow logo (three dimensional tensor). For this tensor we find low-rank approximations and then calculate quality criterions listed above.\n\n\n\\subsection{Problem statement}\n\nFormally, let's state $X$ is an 3rd order tensor (input image). We define approximations in the following way:\n\n\n\\begin{equation} \\label{eq:kotua_1}\n\\underline{\\mathbf{X}}=\\sum_{r=1}^{R} \\underline{\\mathbf{X}}_{r}=\\sum_{r=1}^{R} \\lambda_{r} \\cdot \\mathbf{a}_{r} \\circ \\mathbf{b}_{r} \\circ \\mathbf{c}_{r} \\end{equation}\n\n\n\\begin{equation} \\label{eq:kotua_2}\n\\underline{\\mathbf{X}}=\\underline{\\mathbf{G}} \\times_{1} \\mathbf{A} \\times_{2} \\mathbf{B} \\times_{3} \\mathbf{C}\\end{equation}\n\n\n\\begin{equation} \\label{eq:kotua_3}\n\\underline{\\mathbf{X}}=\\mathbf{A} \\times{ }_{2}^{1} \\underline{\\mathbf{G}}^{(1)} \\times_{3}^{1} \\underline{\\mathbf{G}}^{(2)} \\times_{3}^{1} \\cdots \\times_{3}^{1} \\underline{\\mathbf{G}}^{(N-1)} \\times_{3}^{1} \\mathbf{B}\\end{equation}\n\nWhere \\ref{eq:kotua_1} - \\ref{eq:kotua_3} correspond to CPD, HOSVD and Tensor-Train decompositions. Corresponding output tensors we define as $X_{cpd}, X_{ho}, X_{tt}$.\n\nPrecision is defined the following way:\n\n\\begin{equation}\n    Precision = \\frac{|X - X_i|}{|X|},  \\forall i \\in \\set{\\{cpd, ho, tt\\}}\n\\end{equation}\n\nComplexity is calculated as time taken to complete decomposition. Stability is estimated as increase in error when some Gaussian noise is added to the input tensor. In this work Gaussian noise is a tensor of same shape as X, where each element is sampled from the normal distribution with parameters $\\mu$ and $\\sigma$.\n\n\\subsection{Experiment description}\n\nTensor Flow logo is taken as an input image. The input converted to the 3rd order tensor with shape (232, 217, 4). \n\nThen, three experiments are conducted for each type of tensor decomposition (CPD, HOSVD and Tensor Train):\n\n\\begin{enumerate}\n    \\item Calculate relative error of decomposition for different ranks of core tensor\n    \\item Measure time taken to compute the decomposition for each of the rank\n    \\item Calculate relative error of decomposition when Gaussian noise with different sigma is added to the input image. Repeat it for each rank and then plot 3D graph, illustrating the stability.\n\\end{enumerate}\n\n\\subsection{Plots and analysis}\n\nFirst of all, we compare how relative error decreases with regards to the rank for different tensor decompositions. As it can be seen from the chart \\ref{fig:kotua:2}, TT and HOSVD showcase almost identical results while CPD is quite noisy and its errors decrease slower.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/errors}\n\\caption{Comparison of relative error of decomposition w.r.t rank for HOSVD, CPD and TT.}\n\\label{fig:kotua:2}\n\\end{figure}\n\nIn terms of the computational complexity, HOSVD is a clear leader. CPD, on the other hand, is again an outsider. On the chart \\ref{fig:kotua:3} the time axis is plotted in the logarithmic scale, so it can be seen, that CPD is slower than HOSVD by a factor of 100.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/times}\n\\caption{Comparison of complexity of decomposition w.r.t rank for HOSVD, CPD and TT.}\n\\label{fig:kotua:3}\n\\end{figure}\n\n\\subsubsection{Noisy Data}\n\nCharts \\ref{fig:kotua:4} - \\ref{fig:kotua:6} show, how noise influences stability of algorithms. In general, algorithms behave identically: the error decreases with regards to rank when noise is insignificant. But when noise becomes large errors start to increase with regards to rank.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/cpd}\n\\caption{Relative error of CPD decomposition w.r.t to rank and standard deviation of Gaussian noise.}\n\\label{fig:kotua:4}\n\\end{figure}\n\nInterestingly enough, regardless of noise amplitude, at low ranks errors decrease before reaching some threshold. After that point the growth trend takes its lead.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/hosvd}\n\\caption{Relative error of HOSVD decomposition w.r.t to rank and standard deviation of Gaussian noise.}\n\\label{fig:kotua:5}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/tt}\n\\caption{Relative error of TT decomposition w.r.t to rank and standard deviation of Gaussian noise.}\n\\label{fig:kotua:6}\n\\end{figure}\n\nTo summarize staiblity criterions, let's take a look on the chart \\ref{fig:kotua:7}. It compares algorithms when small noise (std = 0.1) is added to the picture.As you can see from this chart, HOSVD is the most stable algorithm. CPD is also quite good at high ranks, but no so good at low ranks. Tensor Train is on par with HOSVD at low ranks, but it become less stable at high ranks.  \n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/stability}\n\\caption{Relative error of TT decomposition w.r.t to rank and standard deviation of Gaussian noise.}\n\\label{fig:kotua:7}\n\\end{figure}\n\n\\subsection{Conclusion}\nJudging by all three parameters (precision, stability and complexity) HOSVD is the best algorithm. It's very fast, stable and on par with Tensor Train in terms of precision. Tensor Train has a bit more accurate results, but it's definitely slower and not so stable. CPD is computationally expensive and its error decreases very slow with regards to rank. Though it is quite stable when it comes to high ranks.\n\n\n\\end{document}", "meta": {"hexsha": "1a796d05ee3e68da66c85f5eaeba565bf30c771f", "size": 5989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Kotua2021Lab4/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/Kotua2021Lab4/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/Kotua2021Lab4/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": 53.954954955, "max_line_length": 409, "alphanum_fraction": 0.7647353481, "num_tokens": 1630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.6831290715705138}}
{"text": "\\subsection{Transition detection: mr1d\\_pix}\nProgram {\\em mr1d\\_pix} detects the transitions in all scales at a \ngiven position. The used wavelet transform is the Haar transform,\nso a given wavelet coefficient at position $x$ and at scale $j$ ($j=1..P$,\n$P$ being the number of scales)\nis calculated from pixel values between  positions $x-2^{j}+1$ and $x$.\nOnly pixels in the signal which are on the left of a given position $x$\n(or before a given time for temporal signal) are\nused for the calculation of the wavelet coefficients at position $x$.\nIt allows us to detect new event in a temporal serie whatever the time \nscale of the event.\nBy default, the analysed position is the last one of the signal, but other\nposition can as well being analysed using the \"-x\" option. The program\nprints for each scale $j$ the following information corresponding to \nthe position $x$:\n\\begin{itemize}\n\\item {\\bf No detection} \\\\\n if the wavelet coefficient $\\mid w_j(x) \\mid  < k \\sigma_j$\n\\item {\\bf New upward detection}\\\\\n if $  w_j(x) > k \\sigma_j$  and $\\mid w_j(x-1) \\mid  < k \\sigma_j$\n\\item {\\bf New downward detection}\\\\\n if $  w_j(x) < - k \\sigma_j$ and $\\mid w_j(x-1) \\mid  < k \\sigma_j$\n\\item {\\bf Positive significant structure}\\\\\n if $  w_j(x) > k \\sigma_j$ and $\\mid w_j(x-1) \\mid  > k \\sigma_j$ \\\\\nThe first detected coefficient of the structure is also given.\n\\item {\\bf Negative significant structure}\\\\\n if $  w_j(x) < -k \\sigma_j$ and $\\mid w_j(x-1) \\mid  > k \\sigma_j$ \\\\\nThe first detected coefficient of the structure is also given.\n\\item {\\bf End of significant structure}\\\\\n if $\\mid w_j(x) \\mid  < k \\sigma_j$ and $\\mid w_j(x-1) \\mid  > k \\sigma_j$\n\\end{itemize}\nFurthermore the signal to noise ratio of the wavelet coefficient is given.\n{\\bf\n\\begin{center}\n USAGE: mr1d\\_pix option signal\\_in  \n\\end{center}}\nwhere options are:\n\\begin{itemize}\n\\item {\\bf [-m type\\_of\\_noise]}\n{\\small\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\item Gaussian Noise \n\\item Poisson Noise \n\\item Poisson Noise + Gaussian Noise \n\\item Multiplicative Noise \n\\item Non-stationary additive noise \n\\item Non-stationary multiplicative noise \n\\item Undefined stationary noise \n\\item Undefined noise \n\\end{enumerate}\n}\nDescription in section~\\ref{sect_filter}. Default is Gaussian noise.\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 [-n number\\_of\\_scales]} \n\\item {\\bf [-x Position]}  \\\\\nPosition to analyse. Default is the last point.\n\\end{itemize}\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item mr1d\\_pix sig.dat  \\\\\nAnalyse the last point of the signal with all default option.\n\\item mr1d\\_pix -x 55 -s 10 sig.dat  \\\\\nAnalyse the point at position 55, and detect the transition with a \nsignal to noise ratio equal to 10.\n\\end{itemize}\n\n\n", "meta": {"hexsha": "175edc8c3e33de00a0dae6932e2b1da4bca881d1", "size": 2818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr1/mr1d_pix.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/mr1d_pix.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/mr1d_pix.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.1388888889, "max_line_length": 75, "alphanum_fraction": 0.7182398864, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6831076361988588}}
{"text": "\\section{Lines and Planes}\\label{sec:3Dlinesplanes}\n\nLines and planes are perhaps the simplest of curves and surfaces in\nthree dimensional space. They also will prove important as we seek to\nunderstand more complicated curves and surfaces. \n\nYou may recall that the equation of a line in two dimensions is $ax+by=c$; it is\nreasonable to expect that a line in three dimensions is\ngiven by $ax + by +cz = d$. However it turns out that\nthis is the equation of a plane. We will turn our attention to a study of planes and return to consider lines later in this section. \n\nA plane does not have an obvious ``direction'' as does a line. It is\npossible to associate a plane with a direction in a very useful way,\nhowever: there are exactly two directions perpendicular to a\nplane. Any vector with one of these two directions is called \\dfont{normal}\\index{normal vector}\\index{plane!normal vector} to the plane.\nWhile there are many normal vectors to a given plane, they are all\nparallel or anti-parallel to each other.\n\nSuppose two points $(v_1,v_2,v_3)$ and $(w_1,w_2,w_3)$ are in a plane;\nthen the vector $\\langle w_1-v_1,w_2-v_2,w_3-v_3\\rangle$ is parallel\nto the plane. In particular, if this vector is placed with its tail at\n$(v_1,v_2,v_3)$ then its head is at $(w_1,w_2,w_3)$ and it lies in the\nplane. As a result, any vector perpendicular to the plane is\nperpendicular to $\\langle w_1-v_1,w_2-v_2,w_3-v_3\\rangle$. In fact, it\nis easy to see that the plane consists of \\emph{precisely} those points\n$(w_1,w_2,w_3)$ for which $\\langle w_1-v_1,w_2-v_2,w_3-v_3\\rangle$ is\nperpendicular to a normal to the plane, as indicated in \nFigure~\\ref{fig:plane defined via perp vectors}. Turning this around, suppose\nwe know that $\\langle a,b,c\\rangle$ is normal to a plane containing\nthe point $(v_1,v_2,v_3)$. Then $(x,y,z)$ is in the plane if and only\nif $\\langle a,b,c\\rangle$ is perpendicular to $\\langle\nx-v_1,y-v_2,z-v_3\\rangle$. In turn, we know that this is true\nprecisely when $\\langle a,b,c\\rangle\\cdot\\langle\nx-v_1,y-v_2,z-v_3\\rangle=0$. That is, $(x,y,z)$ is in the plane if and\nonly if\n\\begin{align*}\n  \\langle a,b,c\\rangle\\cdot\\langle x-v_1,y-v_2,z-v_3\\rangle&=0\t\\\\\n  a(x-v_1)+b(y-v_2)+c(z-v_3)&=0\t\\\\\n  ax+by+cz-av_1-bv_2-cv_3&=0\t\\\\\n  ax+by+cz&=av_1+bv_2+cv_3.\n\\end{align*}\nWorking backwards, note that if $(x,y,z)$ is a point satisfying \n$ax+by+cz=d$ then\n\\begin{align*}\n  ax+by+cz&=d\t\\\\\n  ax+by+cz-d&=0\t\\\\\n  a(x-d/a)+b(y-0)+c(z-0)&=0\t\\\\\n  \\langle a,b,c\\rangle\\cdot\\langle x-d/a,y,z\\rangle&=0.\n\\end{align*}\nNamely, $\\langle a,b,c\\rangle$ is perpendicular to the vector with\ntail at $(d/a,0,0)$ and head at $(x,y,z)$. This means that the points\n$(x,y,z)$ that satisfy the equation $ax+by+cz=d$ form a plane\nperpendicular to $\\langle a,b,c\\rangle$. (This doesn't\nwork if $a=0$, but in that case we can use $b$ or $c$ in the role of\n$a$. That is, either $a(x-0)+b(y-d/b)+c(z-0)=0$ or \n$a(x-0)+b(y-0)+c(z-d/c)=0$.)\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{\\epsfxsize6cm\\epsfbox{images/plane_as_perps.eps}}} at 0 0\n\\endpicture}}\n\\caption{A plane defined via vectors perpendicular to a normal. \\label{fig:plane defined via perp vectors}}\n\\end{figure}\n\nThus, given a vector $\\langle a,b,c\\rangle$ we know that all planes\nperpendicular to this vector have the form $ax+by+cz=d$, and any surface\nof this form is a plane perpendicular to $\\langle a,b,c\\rangle$.\n\n\\begin{formulabox}[Standard Form of a Plane]\nAny plane can be written in the form\n\\[\nax + by + cz = d\n\\]\nwhere $a, b, c, d$ are constants and not all $a, b, c$ are zero. \n\nThis plane is perpendicular to the vector $\\langle a,b,c \\rangle$. \\index{plane!standard form}\n\\end{formulabox}\n\n\\begin{example}{Perpendicular Plane}{perpplaneexample}\nFind an equation for the plane perpendicular to $\\langle 1,2,3\\rangle$\nand containing the point $(5,0,7)$.\n\\end{example}\n\\begin{solution}\nUsing the formula above, \nthe plane is $1x+2y+3z=d$. To find $d$ we may substitute\nthe known point on the plane to get $5+2\\cdot0+3\\cdot7=d$, so $d=26$.\n\\end{solution}\n\n\\begin{example}{Normal Vector}{normalvectorexample}\nFind a vector normal to the plane $2x-3y+z=15$.\n\\end{example}\n\\begin{solution}\nOne example is $\\langle 2, -3,1\\rangle$. Any vector parallel or\nanti-parallel to this works as well, so for example\n$-2\\langle 2, -3,1\\rangle=\\langle -4,6,-2\\rangle$ is also normal to the plane.\n\\end{solution}\n\nWe will frequently need to find an equation for a plane given certain\ninformation about the plane. While there may occasionally be slightly\nshorter ways to get to the desired result, it is always possible, and\nusually advisable, to use the given information to find a normal to\nthe plane and a point on the plane, and then to find the equation as\nabove. \n\n\\begin{example}{Plane Perpendicular}{}\nThe planes $x-z=1$ and $y+2z=3$ intersect in a line. Find a\nthird plane that contains this line and is perpendicular to the plane\n$x+y-2z=1$.\n\\end{example} \n\\begin{solution}\nFirst, we note that two planes are perpendicular if and only if their\nnormal vectors are perpendicular. Thus, we seek a vector $\\langle\na,b,c\\rangle$ that is\nperpendicular to $\\langle 1,1,-2\\rangle$. In addition, since the\ndesired plane is to contain a certain line, $\\langle\na,b,c\\rangle$ must be perpendicular to any vector parallel to this\nline. Since $\\langle\na,b,c\\rangle$ must be perpendicular to two vectors, we may find it by\ncomputing the cross product of the two. \n\nTherefore we need a vector parallel\nto the line of intersection of the given planes. For this, it suffices\nto know two points on the line. To find two points on this line, we\nmust find two points that are simultaneously on the two planes, \n$x-z=1$ and $y+2z=3$. Any point on both planes will satisfy \n$x-z=1$ and $y+2z=3$. It is easy to find values for $x$ and $z$\nsatisfying the first, such as $x=1, z=0$ and $x=2, z=1$. Then\nwe can find corresponding values for $y$ using the second equation,\nnamely $y=3$ and $y=1$, so\n$(1,3,0)$ and $(2,1,1)$ are two such points. They are both on the line\nof intersection since they are contained in both planes. \n\nNow \n$\\langle 2-1,1-3,1-0\\rangle=\\langle 1,-2,1\\rangle$ is parallel to the\nline. Finally, we may choose $\\langle a,b,c\\rangle=\\langle\n1,1,-2\\rangle\\times \\langle 1,-2,1\\rangle=\\langle -3,-3,-3\\rangle$.\nWhile this vector will do perfectly well, any vector parallel or\nanti-parallel to it will work as well. For example we might choose\n$\\langle 1,1,1\\rangle$ which is anti-parallel to it, and easier to work with. \n\nNow we know that $\\langle 1,1,1\\rangle$ is normal to the desired plane\nand $(2,1,1)$ is a point on the plane. This gives an equation of $(1)x + (1)y + (1)z = d$. Substituting the value of the point into the equation gives $d = 4$, and therefore an equation of the\nplane is $x+y+z=4$. As a quick check, since $(1,3,0)$ is also on the\nline, it should be on the plane; since $1+3+0=4$, we see that this is\nindeed the case.\n\nNote that had we used $\\langle -3,-3,-3\\rangle$ as the normal, we\nwould have discovered the equation $-3x-3y-3z=-12$. Then we might well\nhave noticed that we could divide both sides by $-3$ to get the\nequivalent $x+y+z=4$.\n\\end{solution}\n\nWe will now turn our attention to a study of lines. Unfortunately, it turns out to be quite inconvenient to\nrepresent a typical line with a single equation; we need to approach\nlines in a different way.\n\nUnlike a plane, a line in three dimensions does have an obvious\ndirection, namely, the direction of any vector parallel to it. In fact\na line can be defined and uniquely identified by providing one point\non the line and a vector parallel to the line (in one of two possible\ndirections). That is, the line consists of exactly those points we can\nreach by starting at the point and going for some distance in the\ndirection of the vector. Let's see how we can translate this into more\nmathematical language. \n\nSuppose a line contains the point $(v_1,v_2,v_3)$ and is parallel\nto the vector $\\langle a,b,c\\rangle$. If we place the vector\n$\\langle v_1,v_2,v_3\\rangle$ with its tail at the origin and its head\nat $(v_1,v_2,v_3)$, and if we place the vector $\\langle\na,b,c\\rangle$ with its tail at $(v_1,v_2,v_3)$, then the head of\n$\\langle a,b,c\\rangle$ is at a point on the line. We can get to\n\\emph{any} point on the line by doing the same thing, except using\n$t\\langle a,b,c\\rangle$ in place of $\\langle a,b,c\\rangle$, where $t$\nis some real number. Because of the way vector addition works, the\npoint at the head of the vector $t\\langle a,b,c\\rangle$ is the point\nat the head of the vector $\\langle v_1,v_2,v_3\\rangle+t\\langle\na,b,c\\rangle$, namely $(v_1+ta,v_2+tb,v_3+tc)$; see\nFigure~\\ref{fig:vector line}.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from -3 to 7, y from 0 to 4.5\n\\arrow <4pt> [0.35, 1] from 0 0 to 2 3\n\\arrow <4pt> [0.35, 1] from 2 3 to 7 4\n\\arrow <4pt> [0.35, 1] from 0 0 to 7 4\n\\put {$(v_1,v_2,v_3)$} [br] <-3pt,3pt> at 2 3\n\\put {$\\langle v_1,v_2,v_3\\rangle$} [r] <-5pt,0pt> at 1 1.5\n\\put {$t\\langle a,b,c\\rangle$} [br] <0pt,4pt> at 4.5 3.5\n\\put {$\\langle v_1,v_2,v_3\\rangle+t\\langle a,b,c\\rangle$} [tl]\n  <3pt,-3pt> at 3.5 2\n\\setdashes\n\\plot -3 2 9.5 4.5 /\n\\endpicture}}\n\\caption{Vector form of a line. \\label{fig:vector line}}\n\\end{figure}\n\nIn other words, as $t$ runs through all possible real values, the\nvector $\\langle v_1,v_2,v_3\\rangle+t\\langle a,b,c\\rangle$ points to\nevery point on the line when its tail is placed at the origin. It is occasionally useful to use this form of a line even in two\ndimensions; a vector form for a line in the $x$-$y$ plane is\n$\\langle v_1,v_2\\rangle+t\\langle a,b\\rangle$, which is the same as\n$\\langle v_1,v_2,0\\rangle+t\\langle a,b,0\\rangle$.\n\n\\begin{formulabox}[Vector Equation of a Line]\nAn equation for a line passing through point $(v_1, v_2, v_3)$ and parallel to the vector$\\langle a, b, c\\rangle$ is\n\\[\n\\langle v_1,v_2,v_3\\rangle+t\\langle a,b,c\\rangle\n\\]\\index{line!vector equation}\n\\end{formulabox}\n\nThe vector $\\langle a, b, c\\rangle$ is called the \\dfont{direction vector}\\index{direction vector}\\index{line!direction vector} for the line. \n\nAnother\ncommon way to write this is as a set of \n\\dfont{parametric equations}\\index{parametric equations}:\n$$ x= v_1+ta\\qquad y=v_2+tb \\qquad z=v_3+tc.$$\n\n\\begin{formulabox}[Parametric Equations of a Line]\nA line in space can be described as \n\\begin{align*}\nx = v_1 + ta \\\\\ny = v_2 + tb \\\\\nz = v_3 + tc\n\\end{align*}\nwhere $(v_1, v_2, v_3)$ is a point on the line and $\\langle a, b, c \\rangle$ is parallel to the line.\\index{line!parametric equations}\n\\end{formulabox}\n\n\\begin{example}{Vector Expression}{vectorexpexample}\nFind a vector expression for the line through $(6,1,-3)$ and\n$(2,4,5)$.\n\\end{example}\n\\begin{solution}\nTo get a vector parallel to the line we subtract $\\langle\n6,1,-3\\rangle-\\langle2,4,5\\rangle=\\langle 4,-3,-8\\rangle$.  The line\nis then given by $\\langle 2,4,5\\rangle+t\\langle 4,-3,-8\\rangle$; there\nare of course many other possibilities, such as $\\langle\n6,1,-3\\rangle+t\\langle 4,-3,-8\\rangle$.\n\\end{solution}\n\n\\begin{example}{Intersecting Lines}{intersecting lines}\nDetermine whether the lines $\\langle 1,1,1\\rangle+t\\langle 1,2,-1\\rangle$ and\n$\\langle 3,2,1\\rangle+t\\langle -1,-5,3\\rangle$ are parallel, intersect, or\nneither.\n\\end{example}\n\\begin{solution}\nIn two dimensions, two lines either intersect or are parallel; in\nthree dimensions, lines that do not intersect might not be parallel.\nIn this case, since the direction vectors for the lines are not\nparallel or anti-parallel we know the lines are not parallel.\nIf they intersect, there must be two values $a$ and $b$ so that\n$\\langle 1,1,1\\rangle+a\\langle 1,2,-1\\rangle=\n\\langle 3,2,1\\rangle+b\\langle -1,-5,3\\rangle$. That is, the following must have a solution: \n\\begin{align*}\n  1+a&=3-b\t\\\\\n  1+2a&=2-5b\t\\\\\n  1-a&=1+3b\n\\end{align*}\nThis gives three equations in two unknowns, so there may or may not be\na solution in general. In this case, it is easy to discover that $a=3$\nand $b=-1$ satisfies all three equations. Substituting these values into $\\langle 1,1,1\\rangle+a\\langle 1,2,-1\\rangle=\n\\langle 3,2,1\\rangle+b\\langle -1,-5,3\\rangle$, the point of intersection is $(4,7,-2)$.\n\\end{solution}\n\n\\begin{example}{Distance from a Point to a Plane}{distancepointplaneexample}\nFind the distance from the point $(1,2,3)$ to the plane\n$2x-y+3z=5$.\n\\end{example}\n\\begin{solution}\nThe distance from a point $P$ to a plane is the shortest\ndistance from $P$ to any point on the plane; this is the\ndistance measured from $P$ perpendicular to the plane; see\nFigure~\\ref{fig:point to plane}. This distance \nis the absolute value of the scalar projection of \n$\\overrightarrow{\\strut QP}$\nonto a normal vector $\\vect{n}$, where $Q$ is any point on the plane.\nIt is easy to find a point on the plane, say $(1,0,1)$.\nThus the distance is\n$$\n  {\\langle 0,2,2\\rangle\\cdot\\langle 2,-1,3\\rangle\\over|\\langle 2,-1,3\\rangle|}=\n  {4\\over\\sqrt{14}}.\n$$\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from -2 to 4, y from -3.5 to 4.5\n\\put {$P$} [b] <0pt,3pt> at 1 4\n\\put {$\\vect{n}$} [b] <0pt,3pt> at -1.5 2\n\\put {$Q$} [t] <0pt,-3pt> at 0 0\n\\multiput {$\\bullet$} at 0 0 1 4 /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1 4\n\\arrow <4pt> [0.35, 1] from 0 0 to -1.5 2\n\\setdashes\n\\setlinear\n\\plot -2 0 4 4.5 3.5 0.5 -2.5 -3.5 -2 0 /\n\\endpicture}}\n\\caption{Distance from a point to a plane. \\label{fig:point to plane}}\n\\end{figure}\n\n\\begin{example}{Distance from a Point to a Line}{distancepointplaneexample}\nFind the distance from the point $(-1,2,1)$ to the line\n$\\langle 1,1,1\\rangle + t\\langle 2,3,-1\\rangle$.\n\\end{example}\n\\begin{solution}\nAgain we want the distance\nmeasured perpendicular to the line, as indicated in\nFigure~\\ref{fig:point to line}. The desired distance is \n$$\n  |\\overrightarrow{\\strut QP}|\\sin\\theta=\n  {|\\overrightarrow{\\strut QP}\\times\\vect{v}|\\over|\\vect{v}|},\n$$\nwhere $\\vect{v}$ is any vector parallel to the line. From the equation of\nthe line, we can use $Q=(1,1,1)$ and $\\vect{v}=\\langle 2,3,-1\\rangle$ along with $P = (-1,2,1)$, so\nthe distance is \n$$\n  {|\\langle -2,1,0\\rangle\\times\\langle2,3,-1\\rangle|\\over\\sqrt{14}}=\n  {|\\langle-1,-2,-8\\rangle|\\over\\sqrt{14}}={\\sqrt{69}\\over\\sqrt{14}}.\n$$\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from -3 to 4, y from -1.5 to 4\n\\put {$P$} [b] <0pt,3pt> at 2 4\n\\put {$\\theta$} [b] <3pt,3pt> at -0.5 -0.25\n\\put {$Q$} [t] <0pt,-3pt> at -1 -0.5\n\\put {$\\vect{v}$} [t] <0pt,-3pt> at 1 0.5\n\\put {$|\\overrightarrow{\\vrule height8pt width 0pt QP}|\\sin\\theta$}\n     [bl] <3pt,3pt> at 2.6 2.8\n\\multiput {$\\bullet$} at -1 -0.5 2 4 /\n\\arrow <4pt> [0.35, 1] from -1 -0.5 to 1 0.5\n\\arrow <4pt> [0.35, 1] from -1 -0.5 to 2 4\n\\setdashes\n\\setlinear\n\\plot -3 -1.5 4 2 /\n\\plot 2 4 3.2 1.6 /\n\\endpicture}}\n\\caption{Distance from a point to a line. \\label{fig:point to line}}\n\\end{figure}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:3Dlinesplanes}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind an equation of the plane containing $(6,2,1)$ and\nperpendicular to $\\langle 1,1,1\\rangle$.\n\\begin{sol}\n\t$(x-6)+(y-2)+(z-1)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the plane containing $(-1,2,-3)$ and\nperpendicular to $\\langle 4,5,-1\\rangle$.\n\\begin{sol}\n\t$4(x+1)+5(y-2)-(z+3)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the plane containing $(1,2,-3)$,\n$(0,1,-2)$ and $(1,2,-2)$.\n\\begin{sol}\n\t$(x-1)-(y-2)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the plane containing $(1,0,0)$,\n$(4,2,0)$ and $(3,2,1)$.\n\\begin{sol}\n\t$-2(x-1)+3y-2z=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the plane containing $(1,0,0)$ and the\nline $\\langle 1,0,2\\rangle + t\\langle 3,2,1\\rangle$.\n\\begin{sol}\n\t$4(x-1)-6y = 0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the plane containing the line of\nintersection of $x+y+z=1$ and $x-y+2z=2$, and perpendicular to the\n$x$-$y$ plane.\n\\begin{sol}\n\t$x+3y=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the line through $(1,0,3)$ and \n$(1,2,4)$.\n\\begin{sol}\n\t$\\langle 1,0,3\\rangle+t\\langle 0,2,1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the line through $(1,0,3)$ and \nperpendicular to the plane $x+2y-z=1$.\n\\begin{sol}\n\t$\\langle 1,0,3\\rangle+t\\langle 1,2,-1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the line through the origin\nand perpendicular to the plane $x+y-z=2$.\n\\begin{sol}\n\t$t\\langle 1,1,-1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $a$ and $c$ so that $(a,1,c)$ is on the line through\n$(0,2,3)$ and $(2,7,5)$.\n\\begin{sol}\n\t$-2/5$, $13/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nExplain how to discover the solution in\nExample~\\ref{exa:intersecting lines}.\n\\end{ex}\n\n\\begin{ex}\nDetermine whether the lines $\\langle 1,3,-1\\rangle+t\\langle\n1,1,0\\rangle$ and $\\langle 0,0,0\\rangle+t\\langle 1,4,5\\rangle$ are\nparallel, intersect, or neither.\n\\begin{sol}\n\tneither\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDetermine whether the lines $\\langle 1,0,2\\rangle+t\\langle\n-1,-1,2\\rangle$ and $\\langle 4,4,2\\rangle+t\\langle 2,2,-4\\rangle$ are\nparallel, intersect, or neither.\n\\begin{sol}\n\tparallel\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDetermine whether the lines $\\langle 1,2,-1\\rangle+t\\langle\n1,2,3\\rangle$ and $\\langle 1,0,1\\rangle+t\\langle 2/3,2,4/3\\rangle$ are\nparallel, intersect, or neither.\n\\begin{sol}\n\tintersect at $(3,6,5)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDetermine whether the lines $\\langle 1,1,2\\rangle+t\\langle\n1,2,-3\\rangle$ and $\\langle 2,3,-1\\rangle+t\\langle 2,4,-6\\rangle$ are\nparallel, intersect, or neither.\n\\begin{sol}\n\tsame line\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a unit normal vector to each of the coordinate planes.\n\\end{ex}\n\n\\begin{ex}\nShow that $\\langle 2,1,3 \\rangle + t \\langle 1,1,2 \\rangle$ and\n$\\langle 3, 2, 5 \\rangle + s \\langle 2, 2, 4 \\rangle$ are the same\nline.\n\\end{ex}\n\n\\begin{ex}\nGive a prose description for each of the following processes:\n\\begin{enumerate}\n\\item\tGiven two distinct points, find the line that goes through them.\n\\item\tGiven three points (not all on the same line), find the plane\n  that goes through them. Why do we need the caveat that not all\n  points be on the same line?\n\\item\tGiven a line and a point not on the line, find the plane that\ncontains them both.\n\\item\tGiven a plane and a point not on the plane, find the line that\nis perpendicular to the plane through the given point.\n\\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\nFind the distance from $(2,2,2)$ to $x+y+z=-1$.\n\\begin{sol}\n\t$7/\\sqrt3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the distance from $(2,-1,-1)$ to $2x-3y+z=2$.\n\\begin{sol}\n\t$4/\\sqrt{14}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the distance from $(2,-1,1)$ to \n$\\langle 2,2,0\\rangle+t\\langle 1,2,3\\rangle$.\n\\begin{sol}\n\t$\\sqrt{131}/\\sqrt{14}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the distance from $(1,0,1)$ to \n$\\langle 3,2,1\\rangle+t\\langle 2,-1,-2\\rangle$.\n\\begin{sol}\n\t$\\sqrt{68}/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cosine of the angle\nbetween the planes $x+y+z=2$ and $x+2y+3z=8$.\n\\begin{sol}\n\t$\\sqrt{42}/7$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cosine of the angle\nbetween the planes $x-y+2z=2$ and $3x-2y+z=5$.\n\\begin{sol}\n\t$\\sqrt{21}/6$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "9383400568b77abb07b0ecb6480e3a6652fa3a37", "size": 19462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12-three-dimensions/12-5-lines-planes.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-5-lines-planes.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-5-lines-planes.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": 35.1299638989, "max_line_length": 192, "alphanum_fraction": 0.7034220532, "num_tokens": 6854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.683107630562796}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Alex Li}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\nIt is singularity which often makes the worst part of our suffering.\\\\\n\\byline{Jane Austen}, not talking about this problem set.\n\\end{inspiration}\n\n\\section{Terminology}\n\nThis week, there is a lot of new terminology to classify the various\nsorts of singularities we might encounter.  For full credit, be sure\nto give careful precise definitions.\n\n\\begin{problem}\n  What is an \\textbf{isolated singularity}?\n  \\end{problem}\n  \\begin{solution}\n  A holomorphic function $f:U\\setminus \\{z_0\\}\\to\\C$ has an isolated singularity at a point $z_0$ if there is an $r$ such that $(B_r(z_0)\\cup z_0) \\subset U$.\n  \\end{solution}\n  \\begin{problem}\n    What is meant by the \\textbf{order} (or \\textbf{multiplicity}) of a zero?  Of a pole?\n    \\end{problem}\n    \\begin{solution}\n    Suppose that $f:U\\to \\C$ is a  holomorphic function from an open set with a zero at $z_0$. The zero is said to have multiplicity $n$ if the function $g(z) = \\frac{f(z)}{(z-z_0)^n}$ is holomorphic and $\\lim_{z\\to z_0} g(z) \\neq 0$.\n\n    If $f$ has a pole at $z_0$, then it is said to have multiplicity $n$ if $g(z) = 1/f(z)$ has a zero of multiplicity $n$ at $z_0$.\n    \\end{solution}\n    \\begin{problem}\n      What is a \\textbf{removable singularity}?\n      \\end{problem}\n      \\begin{solution}\n      An isolated singularity of $f$ at $z_0$ is said to be removable if $\\lim_{z\\to z_0} f(z)$ exists.\n      \\end{solution}\n      \\begin{problem}\n        What does it mean to say that a function $f : \\C \\to \\C$ has a zero of order $n$ at infinity?  Has a pole of order $n$ at infinity?  \n        \\end{problem}\n        \\begin{solution}\n        $f$ has a zero or pole of order $n$ at infinity if $f(\\frac{1}{z})$ has a zero or pole respectively of order $n$ at 0. \n        \\end{solution}\n        \\begin{problem}\n        What is a \\textbf{meromorphic function}?\n        \\end{problem}\n        \\begin{solution}\n        A function $f$ is said to be meromorphic on an open subset $U$ if there is a set of points $S = \\{x_i\\}_i$ such that $f:U\\setminus S\\to \\C$ is holomorphic and every point $x_i$ is removable singularity that happens to also be a pole of $f$.\n        \\end{solution}\n        \\section{Numericals}\n\n        \\begin{problem}\n          Let $f(z) = e^{z \\sin^2 z} - 1$.  What is the order of the zero at $z = 0$?\n          \\end{problem}\n          \\begin{solution}\n          We can use a Taylor expansion of the polynomial at 0, and the index of the first nonzero term will be the order of the zero. Equivalently, the order is the index of the first nonzero derivative.\n\n          \\begin{align}\n          f'(z)  &= (\\sin^2(z) + 2z\\sin(z)\\cos(z))e^{z\\sin^2 z}\n          \\end{align}\n          Clearly this is 0 at $z=0$.\n          Define $g(z) = \\sin^2(z) + 2z\\sin(z)\\cos(z)$.\n          \\begin{align*}\n          g'(z) &= 2\\sin(z)\\cos(z) + 2[\\sin(z)\\cos(z) + z\\cos^2(z) - z\\sin^2(z)]\\\\\n          &= 4\\sin(z)\\cos(z) + 2z(\\cos^2(z) - \\sin^2(z))\\\\\n          f''(z)  &= (g'(z)+g(z)^2)e^{z\\sin^2 z}\n          \\end{align*}\n          We can check that $g'(0)=g(0)=0$, so we look towards the third derivative...\n          \\begin{align*}\n          g''(z) &= (4\\cos^2(z) - 4\\sin^2(z)) + 2(\\cos^2(z) - \\sin^2(z)) + 2z(-2\\cos(z)\\sin(z))-2\\cos(z)\\sin(z))\\\\\n          g''(z) &= 6\\cos^2(z) - 6\\sin^2(z) - 8z(\\cos(z)\\sin(z)))\\\\\n          f'''(z)  &= g(z)(g'(z)+g(z)^2)e^{z\\sin^2 z} + (g''(z)+g'(z)^2)e^{z\\sin^2 z}\n          \\end{align*}\n          At $z=0$, $g''(0) = 6$ and so $f''(0) = 6$. Thankfully we don't have to compute the fourth derivative and can conclude that the order of the zero at 0 is 3.\n          \\end{solution}\n          \\begin{problem}\n            Let $f(z) = \\left( \\cos z \\right) - 1 - z^2/2$, and compute\n              \\[\n                  \\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz\n                    \\]\n                      for $\\gamma : [0,2\\pi]$ given by $\\gamma(\\theta) = e^{i\\theta}$.\n                      \\end{problem}\n                      \\begin{solution}\n                      First, let's expand $\\cos z$ as a Taylor series:\n                      \\begin{align}\\label{f_leading_coef_cos}\n                      f(z) = (\\sum_{n=0}^\\infty \\frac{(-1)^nz^{2n}}{(2n)!}) - 1 - z^2/2 =-z^2 + \\sum_{n=2}^\\infty \\frac{(-1)^nz^{2n}}{(2n)!}\n                      \\end{align}\n                      Now let us use the residue theorem to compute this integral. It will be equal to the sum of the residues at the zeros of $f$. To do this, let's find all poles of the function. At $z=0$, the denominator is 0, and this occurs at no other point, since the magnitude of the first term will be greater than the magnitude of the rest \n                      \\[\n                      \\abs{f(z)} \\geq \\abs{z^2} - \\sum_{n=2}^\\infty \\abs{\\frac{z^{2n}}{(2n)!}} \\geq  \\abs{z^2}(1 - \\sum_{n=2}^\\infty \\frac{1}{(2n)!}) \\geq 0\n                      \\]\n                      That this is more than 0 can be verified by comparison to the formula \n                      \\begin{align*}\n                      e &= \\sum_{n=1}^\\infty \\frac{1}{n!}\\\\\n                      .05 \\approx e - \\sum_{n=0}^3 \\frac{1}{n!} &= \\sum_{n=4}^\\infty \\frac{1}{n!}\\\\\n                      1 &\\geq \\sum_{n=4}^\\infty \\frac{1}{n!} \\geq \\sum_{n=2}^\\infty \\frac{1}{2n!}\n                      \\end{align*}\n\n                      Next we need to determine the order of the pole at $z=0$. Since we already know the first positive coefficient of the power series for f is at $x^2$ from equation \\ref{f_leading_coef_cos}, we can quickly check that we are dealing with a first order pole:\n                      \\begin{align*}\n                          \\frac{f'(z)}{f(z)} &= \\frac{\\Theta(z)}{\\Theta(z^2)} = \\Theta(z^{-1})\n                          \\end{align*}\n                          Thus we can compute the residue by evaluating the limit as $z\\frac{f(z)}{f'(z)}$ approaches 0.\n                          \\[\n                          \\lim_{z\\to 0} \\frac{zf'(z)}{f(z)} =  \\lim_{z\\to 0} \\frac{z(-2z + \\Theta(z^3))}{-z^2 + \\Theta(z^4)} = 2\n                          \\]\n                          The original integral is equal to the sum of the residues, so we can conclude that the value of the integral is 2.\n                          \\end{solution}\n                          \\section{Exploration}\n\n                          \\begin{problem}\n                            Explain the topology on $\\mathbb{C} \\cup \\{ \\infty \\}$, the \\textbf{Riemann sphere}.\n                            \\end{problem}\n                            \\begin{solution}\n                            Well, it's the topology of... a sphere. To see this, we can consider the homeomorphism given by projecting any point $x$ on a unit sphere sitting on the complex plane to the point on the plane on the line between $x$ and the top of the sphere $x_{top}$. The exception is that $x_{top} $ will map to $\\infty$.\n\n                            It's geometrically clear enough that this is a bijection, and besides infinity, it's also clear that this is continuous with a continuous inverse. To see that it's continuous at infinity, notice that any neighborhood of $x_{top}$ is a small circle at the top of the sphere, so it's image under this bijection contains all point sufficiently far from 0. The inverse transformation is continuous since for any neighborhood of $\\infty$, there is an $R$ so that all points distance $R$ from 0 are contained in the neighborhood, so the preimage will be a neighborhood of $x_{top}$.\n\n                            \\end{solution}\n                            \\begin{problem}\\label{jordans-lemma}\n                              Prove \\textbf{Jordan's lemma}; next week, this lemma will help us estimate integrals over the contour $\\gamma : [0,\\pi] \\to \\C$ given by $\\gamma(\\theta) = re^{i\\theta}$.\n                                Specifically, show that if $a > 0$, then\n                                  \\[\n                                      \\abs{\\int_\\gamma e^{iaz} \\, g(z) \\, dz } \\leq \\frac{\\pi}{a} \\sup_{\\theta \\in [0,\\pi]} \\abs{g(\\gamma(\\theta))}.\n                                          \\]\n                                          \\end{problem}\n                                          \\begin{solution}\n                                          Let \\(M = \\sup_{\\theta \\in [0,\\pi]} \\abs{g(\\gamma(\\theta))}\\)\n                                          \\begin{align*}\n                                          \\abs{\\int_\\gamma e^{iaz}g(z)dz}  &= \\abs{\\int_0^\\pi e^{iare^{i\\theta}} g(re^{i\\theta})rie^{i\\theta}d\\theta}\\\\\n                                          &= r\\abs{\\int_0^\\pi e^{iar\\cos(\\theta) - ar\\sin(\\theta)}e^{i\\theta}g(re^{i\\theta})d\\theta}\\\\\n                                          &\\leq rM\\abs{\\int_0^\\pi e^{-ar\\sin(\\theta)}d\\theta}\\\\\n                                          &= 2rM\\int_0^{\\pi/2} e^{-ar\\sin(\\theta)}d\\theta\\\\\n                                          &= 2rM\\frac{\\pi e^{-ar\\frac{2\\theta}{\\pi}}}{2ar}\\big|_0^{2\\pi}\\\\\n                                          &\\leq 2\\pi rM\\frac{1}{2ar} = \\frac{\\pi}{a}M\n                                          \\end{align*}\n                                          \\end{solution}\n\n                                          \\begin{problem}\\label{riemann-removable-singularity}\n                                            For an open set $U \\ni z_0$, suppose\n                                              $f : U \\setminus \\{z_0\\} \\to \\C$ is holomorphic.  Show that\n                                                $\\lim_{z\\to z_0} (z-z_0)f(z)=0$ if and only $f$ extends to a\n                                                  holomorphic function $F : U \\to \\C$.\n                                                  \\end{problem}\n                                                  \\begin{solution}\n                                                  We will additionally assume that $z_0$ is a isolated singularity, to prevent the case where $z_0$ is an isolated point where the limit doesn't exist but $f$ can extend to $F$ just by giving it any value at $z_0$.\n\n                                                  We have 3 cases depending on the type of singularity. If $z_0$ is an essential singularity, then the limit has no chance of existing - since $f(z)$ is dense in every open ball and $z-z_0$ is not, their product is dense in every open ball.  If $z_0$ is a removable discontinuity, then $f$ surely extends to a holomorphic function $F$ with $F(z_0)$ finite. Thus\n                                                  \\[\\lim_{z\\to z_0} (z-z_0)f(z)=\\lim_{z\\to z_0} (z-z_0)F(z) = 0\\]\n\n                                                  Finally, if $z_0$ is a pole of order 1 then by definition $g_1(z) = f(z)/(z-z_0)$ is holomorphic and has a nonzero limit. If the order is $n>1$, then $f(z)/(z-z_0)^n$ has a nonzero limit so $f(z)/(z-z_0)^{n-1}$ diverges.In either case, the limit is not zero, consistend with the fact that $f$ does not extend to $F$.\n                                                  \\end{solution}\n\n                                                  \\begin{problem}\\label{idempotent-entire}\n                                                  Describe holomorphic functions\n                                                    $f : \\C \\to \\C$ with the property that $f(f(z)) = f(z)$ for all\n                                                      $z \\in \\C$.\n                                                      \\end{problem}\n                                                      \\begin{solution}\n                                                      One possible case occurs when $f(z)=c$. Otherwise, since $f:\\C\\to\\C$, the image of $f$ is dense in $\\C$. And for every point $z$ in the image of $f$, $f(z) = z$, so this implies that $f(z)-z = 0$ at a dense subset of the plane, in particular at some convergent sequence of points. Therefore $f(z)-z$ is identically 0, so the only functions with this property are $f(z)=c$ and $f(z)=z$.\n                                                      \\end{solution}\n\n                                                      \\begin{problem}\n                                                        Suppose $U$ is a disk and $f : U \\to \\C$ is holomorphic with\n                                                          finitely many zeros, and repeatedly invoke \\ref{factor-theorem} to\n                                                            explain why you can find $z_1,z_2,\\ldots,z_n \\in \\C$ and write\n                                                              \\[\n                                                                  f(z) = (z-z_1)(z-z_2) \\cdots (z-z_n) \\, g(z)\n                                                                    \\]\n                                                                      for a nowhere-vanishing analytic function $g : U \\to \\C$.\n                                                                      \\end{problem}\n                                                                      \\begin{solution}\n                                                                      Let $w_1, w_2, \\dots w_k$ correspond to the locations of the zeros. If $w_l$ is the location of a zero of order $m_l$, then by \\ref{factor-theorem}, the function $f(z)/ (z-w_l)^{m_l}$ does not vanish at $w_l$ and is still analytic. Furthermore, this does not introduce any new zeros since we are multiplying by a nonzero quantity everywhere besides $w_l$. Repeating this for each root, we see that\n                                                                      \\[\n                                                                      \\frac{f(z)}{\\prod_{l=0}^k (z-w_l)^{m_l}} = g(z)\n                                                                      \\]\n                                                                      is nonzero everywhere in $U$.\n                                                                      \\end{solution}\n                                                                      \\begin{problem}\\label{argument-principle-zeros}\n                                                                        Continuing as above, compute $f'(z)/f(z)$ in terms of $z_1,z_2,\\ldots,z_n \\in \\C$ and $g'(z)/g(z)$, and evaluate\n                                                                          \\[\n                                                                              \\frac{1}{2\\pi i} \\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz\n                                                                                \\]\n                                                                                  in terms of the winding numbers $n(\\gamma,z_j)$.\n                                                                                  \\end{problem}\n                                                                                  \\begin{solution}\n                                                                                  \\begin{align*}\n                                                                                      \\frac{f'(z)}{f(z)} &= \\left(\\frac{d}{dz}\\Log f(z)\\right) \\\\\n                                                                                          &= \\left(\\frac{d}{dz}\\Log g(z)\\prod_{k=1}^n (z-z_k)\\right) \\\\\n                                                                                              &=  \\frac{g(z)\\prod (z-z_i)\\left(\\frac{g'(z)}{g(z)} \\sum_{i=1}^n \\frac{1}{z-z_i}\\right)}{g(z)\\prod (z-z_i)}\\\\\n                                                                                                  &=  \\frac{g'(z)}{g(z)} + \\sum_{i=1}^n \\frac{1}{z-z_i}\n                                                                                                  \\end{align*}\n                                                                                                  The function $\\frac{g'(z)}{g(z)}$ is everywhere holomorphic since $g$ is holomorphic with no zeros, and the rest of the functions have obvious residues. So we can compute the integral:\n                                                                                                  \\begin{align*}\n                                                                                                  \\frac{1}{2\\pi i} \\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz &= \\frac{1}{2\\pi i} \\int_\\gamma \\frac{g'(z)}{g(z)} + \\sum_{i=1}^n \\frac{1}{z-z_i} \\, dz\\\\\n                                                                                                  &= \\sum_{i=1}^n n(\\gamma, z_i)\n                                                                                                  \\end{align*}\n                                                                                                  \\end{solution}\n                                                                                                  \\begin{problem}\n                                                                                                    Let's justify the terminology that a ``zero of multiplicity $n$''\n                                                                                                      really means there are $n$ solutions to a certain equation.  Suppose\n                                                                                                        the holomorphic function $f : B_1(0) \\to \\C$ has a zero of order $n$\n                                                                                                          at zero, i.e., suppose $f(z) = z^n g(z)$ for a holomorphic\n                                                                                                            $g : B_1(0) \\to \\C$ with $g(0) \\neq 0$.  For all sufficiently small\n                                                                                                              $\\epsilon > 0$, find $\\delta > 0$ so that for all\n                                                                                                                $w \\in B_\\epsilon(0) - \\{0\\}$, the set\n                                                                                                                  $f^{-1}(\\{w\\}) \\cap B_\\delta(0)$ consists of $n$ elements.\n                                                                                                                  \\end{problem}\n                                                                                                                  \\begin{solution}\n                                                                                                                  Consider the Talyor expansion of $f$, since $f(z)=z^ng(z)$ is the first nonzero term, the first $n$ coefficents must be zero. Thus \n                                                                                                                  \\[\n                                                                                                                  f(z) = \\sum_{k=1}^\\infty a_nx^n\n                                                                                                                  \\]\n                                                                                                                  We want to show that for some small $w=f(z_0)$, $w - f(z)$ has $k$ roots near 0. Where can the following equation be satisfied?\n                                                                                                                  \\[\n                                                                                                                  w - f(z) = w + a_nz^n + O(z^{n+1}) = 0\n                                                                                                                  \\]\n                                                                                                                  Where $O(f(z))$ means that $\\exists c$ such that $|f(z)|\\leq cz^n$ as $z\\to 0$.\n                                                                                                                  By definition, $z_0$ is a root of this equation, and if we choose a sufficiently small $\\delta>0$, then the dominant term of the equation is $w + a_nz^n$, so any zeros will be in a neighborhood of $z_0e^{2i\\pi k/n}$ for some $k$, and there should be at least one zero in each neighborhood. % Weak argument\n\n                                                                                                                  We can indirectly control the size of the neighborhood by adjusting $\\delta$ and make it suuuper small so that none intersect. Now choose one of the n neighborhoods. If there are two values $z_0, z_1$ in this neighborhood that are equal, then \n                                                                                                                  \\[0 = f(z_0) - f(z_1) = a_n(z_0^n + z_1^n) + \\sum_{k=n+1}^\\infty a_k(z_0^{k+1}-z_1^{k+1})\\]\n                                                                                                                  Writing $z_1 = z_0 + h$ and using the fact that $z_0, z_1$ being in the same neighborhood implies $h$ can be made arbitrarily small,\n                                                                                                                  \\[\n                                                                                                                  0 = a_n(z_0^n + z_1^n) + \\sum_{k=n+1}^\\infty a_k(z_0^{k+1}-z_1^{k+1}) = anz_0^{n-1}h + O(h^2z_0^{n-1}) + O(hz_0^n) = hz_0^{n-1}(a_n + O(h + z_0))\n                                                                                                                  \\]\n                                                                                                                  But since $z_0\\neq 0, a_n\\neq 0$, this implies that $h=0$ and so $z_0=z_1$. Thus there is exactly one point $z_0$ in each neighborhood such that $f(z_0)=w$, so there must be exactly $n$ points within $\\delta$ such that $f(z)=w$.\n                                                                                                                  \\end{solution}\n                                                                                                                  \\section{Prove or Disprove and Salvage if Possible}\n\n                                                                                                                  \\begin{problem}\\label{factor-theorem}\n                                                                                                                    Suppose $U \\subset \\C$ is open, and $f : U \\to \\C$ is analytic, and for some $z_0 \\in U$, we have $f(z_0) = 0$.  Then there is a positive $m \\in \\Z$ so that\n                                                                                                                      \\[\n                                                                                                                          g(z) := \\frac{f(z)}{(z-z_0)^m}\n                                                                                                                            \\]\n                                                                                                                              yields an analytic function $g : U \\to \\C$ which does not vanish at $z_0$.\n                                                                                                                              \\end{problem}\n                                                                                                                              \\begin{solution}\n                                                                                                                              Since $f$ is analytic, it has a power series representation \n                                                                                                                              \\[\n                                                                                                                              f(z) = \\sum_{k=0}^\\infty a_k(z-z_0)^k\n                                                                                                                              \\]\n                                                                                                                              Letting $m$ be the index of the first nonzero term $a_m$ in this representation, the function \n                                                                                                                              \\[\n                                                                                                                              g(z) = \\frac{f(z)}{(z-z_0)^m} =  a_m + \\sum_{k=m+1}^\\infty a_k(z-z_0)^k\n                                                                                                                              \\]\n                                                                                                                              is also analytic, and at the point $z=z_0$, all but the first term vanish and so $g(z_0)=a_m\\neq 0$.\n                                                                                                                              \\end{solution}\n                                                                                                                              \\begin{problem}\\label{entire-dominate-entire}Suppose $f, g : \\C \\to \\C$ are holomorphic and for all $z \\in \\C$ we have $\\abs{f(z)} \\leq \\abs{g(z)}$.  In this case, we say that $g$ dominates $f$.  Then $f(z) = \\lambda \\cdot g(z)$ for some $\\lambda \\in \\C$.  (Compare \\ref{identity-dominate-entire}.)\n                                                                                                                              \\end{problem}\n                                                                                                                              \\begin{solution}\n                                                                                                                              For all $\\epsilon>0$, we see that $\\abs{f(z)/(g(z)+\\epsilon)} \\leq 1$ when $g(z)\\neq 0$. By the identity theorem, the set of points where $g(z)=0$ is isolated, so the set excluding these points is open, and we can apply Liouville's theorem to say that the function $f/g$ is bounded on that open set and hence everywhere. Thus $f/g$ is a constant $\\lambda$.\n                                                                                                                              \\end{solution}\n                                                                                                                              \\begin{problem}\n                                                                                                                                If $f : \\C \\to \\C$ has a pole of order $n$ at infinity, then $f$ is a polynomial of degree at most $n$.\n                                                                                                                                \\end{problem}\n                                                                                                                                \\begin{solution}\n                                                                                                                                False, we aren't assuming that $f$ is holomorphic so we will be destroyed by functions like $\\begin{cases}x&x\\neq 0\\\\ 1 &x=0\\end{cases}$ with a pole of order 1 at infinity. With $f$ holomorphic, it is true, in fact we can say it is a polynomial of degree exactly $n$.\n\n\n                                                                                                                                Since $f(z)$ is a function with a pole of order $n$ at infinity, the function $f(\\frac{1}{z})$ has a pole of order $n$ at 0. Thus the function $f(\\frac{1}{z})z^n$ is analytic and approaches some nonzero value $a_n$ at the point 0.\n\n                                                                                                                                Then the function $f(z)/z^n$ approaches $a_n$ as $z\\to \\infty$.\n\n                                                                                                                                Now, $f(z)$ is analytic so we can write it out as a power series.\n                                                                                                                                \\[\n                                                                                                                                f(z) = \\sum_{k=0}^\\infty a_kz^k\n                                                                                                                                \\]\n                                                                                                                                After dividing by $z^n$, we get a term $\\frac{f(z)}{z^n} = \\sum_{k=0}^n a_kz^k$ which evidentally approaches $a_n$ as $z$ goes to infinity. Thus the other component must be 0 in the limit.\n                                                                                                                                \\[\n                                                                                                                                0 = \\lim_{z\\to\\infty} \\sum_{k=n+1}^\\infty a_kz^{k-n}\n                                                                                                                                \\]\n                                                                                                                                Now, this function is holomorphic on all of $\\C$ and since the limit exists it is bounded, hence constant, hence 0. Therefore $f(z)$ is a degree $n$ polynomial.\n\n                                                                                                                                \\end{solution}\n                                                                                                                                \\begin{problem}\\label{casorati-weierstrass}\n                                                                                                                                  Suppose $f : U \\setminus \\{ z_0 \\} \\to \\C$ is holomorphic with an essential singularity at $z_0 \\in U$.  If $V \\subset U$ is a neighborhood of $z_0$, then $f(V \\setminus \\{ z_0 \\})$ is dense in $\\C$.\n                                                                                                                                  \\end{problem}\n                                                                                                                                  \\begin{solution}\n                                                                                                                                  True. Suppose that it was not dense. Then there is a point $w_0\\in \\C$ such that $f(V\\setminus \\{z_0\\})$ does not take on any value within $\\epsilon$ of $w_0$. Now consider the function \n                                                                                                                                  \\[\\frac{1}{f(z) - w_0}.\\]\n\n                                                                                                                                  For $z \\in V$, the norm of the denominator will always be greater than $\\epsilon$, and thus the norm of this function is bounded above by $\\frac{1}{\\epsilon}$. Since it is bounded, the Riemann theorem on removable singularities says that $g(z) = \\frac{1}{f(z)-w_0}$ has a removable discontinuity. After removing this discontinuity, if $g(z_0) \\neq 0$ then $\\frac{1}{g(z)}+w_0 = f(z)$ will be analytic so $f(z)$ has a removable discontinuity at $z_0$.  If, however, $g(z_0)=0$, then by \\ref{factor-theorem}, we can find an analytic $h(z) = \\frac{g(z)}{(z-z_0)^m}$ that is not zero at $z_0$, so\n                                                                                                                                  \\[\n                                                                                                                                  h(z) = \\frac{1}{(z-z_0)^m(f(z)-w_0)}\\implies f(z) = \\frac{1}{(z-z_0)^mh(z)}+w_0\n                                                                                                                                  \\]\n                                                                                                                                  From this it is clear that $(z-z_0)^mf(z)$ is analytic and equal to $\\frac{1}{h(z_0)}\\neq 0$ at $z_0$, so $f(z)$ has a pole of degree $m$ at $z_0$.\n\n                                                                                                                                  In any case, the discontinuity is not essential, a contradictio.\n                                                                                                                                  \\end{solution}\n                                                                                                                                  \\begin{problem}\n                                                                                                                                    There exists a holomorphic function $f : \\C \\to \\C$ so that both $f$\n                                                                                                                                      and $z \\mapsto e^{f(z)}$ have poles at zero.\n                                                                                                                                      \\end{problem}\n                                                                                                                                      \\begin{solution}\n                                                                                                                                      False, if $f$ is holomorphic on all of $\\C$ it doesn't have any discontinuities, so it doesn't have a pole. Here is a salvage:\n\n                                                                                                                                      If $f$ is a meromorphic function with a pole at 0, then $e^f$ has a essential discontinuity at 0.\n\n                                                                                                                                      Even without this tecnhicality, it is impossible: if $f$ has a pole of degree $d$, then we can write $f = \\sum_{k=-d}^{\\infty} a_kx^k$, and since the leading term dominates as $x$ tends to zero, when $\\epsilon$ is sufficiently small, we can find a value $x_1$ such that $f(x_1)\\approx |\\epsilon|^{-d}$ near 0.\n\n                                                                                                                                      Then $e^{f(x)}$ cannot possibly be a pole or removable discontinuity at 0, as if it were, for some $n\\in \\N$, \n                                                                                                                                      \\[\n                                                                                                                                      0 = \\lim_{x\\to 0} e^{f(x)}/x^n  = \\lim_{x\\to 0} e^{x^d}/x^n = \\infty\n                                                                                                                                      \\]\n                                                                                                                                      \\end{solution}\n                                                                                                                                      \\begin{problem}\n                                                                                                                                        There exists a nowhere-vanishing holomorphic function\n                                                                                                                                          $f : \\C \\to \\C$ such that $\\lim_{z \\to \\infty} f(z) = \\infty$.\n                                                                                                                                          \\end{problem}\n                                                                                                                                          \\begin{solution}\n                                                                                                                                          False. Such a function is a meromorphic function on the extended complex plane with a pole at infinity, so it is a rational function, and can be written out as a quotient of two polynomials $f=p(x)/q(x)$. If $q(x)$ is not constant, it has a root, contradicting the domain of $f$ being all of $\\C$. If $p(x)$ is not constant, then there is a zero of $f$. Thus $f$ is a constant.\n\n                                                                                                                                          A correct statement could be something like \n                                                                                                                                          \\begin{theorem}\n                                                                                                                                          Any non constant meromorphic function $f:\\C\\to \\C$ with $\\lim_{z\\to\\infty} = C$ for some constant $C$ has at least 1 pole.\n                                                                                                                                          \\end{theorem}\n                                                                                                                                          The limit being constant happens exactly when the degree of $p(x)$ is equal to the degree of $q(x)$ in the precceding proof. Since the $f$ isn't constant, $q(x)$ has a root somewhere, and by the definition of meromorphic this root corresponds to a pole.\n                                                                                                                                          \\end{solution}\n                                                                                                                                          % All such functions are rational\n\n                                                                                                                                          \\end{document}\n\n", "meta": {"hexsha": "692897757090e5de6bcc5ee0244236398d3a752c", "size": 38648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol8.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/sol8.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/sol8.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": 118.5521472393, "max_line_length": 722, "alphanum_fraction": 0.3318412337, "num_tokens": 7203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834649, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6830700276666647}}
{"text": "%!TEX root =  ../main.tex\n\n\n\\subsection{Derivatives of Exponentials}\n\n\n\\objective{Describe and use the special status of $e^x$ amongst exponential equations}\n\n\nAs we move past power function, derivatives become a lot harder to compute.  If we\nbegin with the premise that there is some exponential function which is its own \nderivative --- that the height of the function at every point is the same as its slope\n--- then we should find constant for the base.  Empirically, it is easy to see that\nsuch a number is between 2 and 3, but how can we be more precise?  We\nbegin with the definition\n$$\nf'(x) = \\lim_{h\\rightarrow0}\\frac{f(x+h)-f(x)}{h}\n$$\nWe will use the letter $e$ next, but assume we do not know its exact value.  In\nthe problem set, you saw that it's definition is\n$$\ne = \\lim_{h\\rightarrow\\infty}\\left(1+\\frac{1}{h}\\right)^h\n$$\nand so right away we see we are dealing with opposite limits.  We can convert\nfrom a limit at infinity to a limit at zero by taking the reciprocal of the variable\nat every instance.  This leads to a modified definition of $e$:\n$$\ne = \\lim_{h\\rightarrow0}\\left(1+\\cfrac{1}{\\frac{1}{h}}\\right)^{\\frac{1}{h}}\n$$\nArmed wth compatible limits, let us return to the definition of a derivative.\n$$\n(e^x)'  = \\lim_{h\\rightarrow0}\\frac{e^{x+h}-e^x}{h}\n$$\nBy the properties of exponents, a sum in the degree must come\nfrom a multiplication of the bases (i.e. $e^{x+h}=e^x\\cdot{}e^h$).\nFactoring out $e^x$, we get\n$$\n(e^x)' = e^x \\cdot{}\\lim_{h\\rightarrow0}\\frac{e^h-1}{h}\n$$\nWill our definition of $e$ work here?  Substituting it in is very messy, but cleans up\nperfectly.  Just evaluating the limit,\n\\begin{align*}\n\t\\lim_{h\\rightarrow0} & \\frac{\\left[\\left(1+\\cfrac{1}{\\frac{1}{h}}\\right)^{\\frac{1}{h}}\\right]-1}{h} &\\\\\n\t& \\frac{1+\\left(\\cfrac{1}{\\frac{1}{\\frac{1}{h}}}\\right) - 1}{h} &\\\\\n\t& \\frac{\\cfrac{1}{\\frac{1}{h}}}{h} & \\Rightarrow \\frac{h}{h} \\\\\n\t& = 1\n\\end{align*}\n\n\\begin{derivation}{Derivative of $e^x$}\n$$\n(e^x)' = e^x\n$$\n\\end{derivation}\n\n\\personfeature[0in]{\\chapdir/pics/Charles_Hermite_circa_1901_edit}{Charles Hermite}{1822\n- 1901}{was a French mathematician who did research on number theory, \nquadratic forms, invariant theory, orthogonal polynomials, elliptic functions, and algebra.\nHe was the first to prove that $e$, the base of natural logarithms, is a transcendental number. \nHis methods were later used by Ferdinand von Lindemann to prove that $\\pi$ is transcendental.\n\\href{https://en.wikipedia.org/wiki/Charles_Hermite}{Wikipedia}}\n\n\\subsection{Implications}\nHow does this explain the behavior of $2^x, 3^x$ or any other base?  The limit portion of\nthe work shown above was equal to 1, but if we had substituted any other number in,\nwe would have obtained some constant.  We can extend the definition of exponential\nderivative like so:\n\n\\begin{derivation}{Derivative of $b^x$}\n$$\n(b^x)' = b^x \\cdot{} \\ln{b}\n$$\n\\end{derivation}\n\nOften we will need to apply the Chain Rule, since the exponent is rarely just $x$\n$$\n\\left(e^{f(x)}\\right)' = e^{f(x)} \\cdot f'(x)\n$$\n\nLastly, if $e^x$ is it's own derivative, then it is its own anti-derivative as well:\n$$\n\\int e^xdx = e^x + C\n$$\n\nThe TI-8* has an $e^x$ function (2nd-LN) and most computer programs (e.g. MS Excel)\nhave a function \\texttt{exp()}, which is the same thing.\n\n\\begin{figure}\n\\begin{centering}\n\\includegraphics[width=\\textwidth]{\\chapdir/pics/exponentialderivatives}\n\\caption[Exponential tangent lines at (0,1)]{A set of exponential equations tangent lines at (0,1), with original function dotted.  $1.4^x$ in green, $e^x$ in blue, $20^x$ in red.}\n\\end{centering}\n\\end{figure}", "meta": {"hexsha": "0ea01ea3d75205c9a6c73e5042ad0d772d49c656", "size": 3592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch08/0801.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch08/0801.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch08/0801.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.0434782609, "max_line_length": 180, "alphanum_fraction": 0.708518931, "num_tokens": 1145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.6830700209685173}}
{"text": "\\chapter{Statistics}\n\n\\section{Statistical model}\n\n\\index{nonparametric statistical model}%\n\\index{statistical model!nonparametric}%\nA \\emph{nonparametric model} is a set of pdfs.\n\\index{parametric statistical model}%\n\\index{statistical model!parametric}%\n\\index{parameter space}%\nA \\emph{parametric model} \\(F : \\Theta \\to \\Omega \\to \\Real\\)\nmaps a parameter \\(\\theta\\)\nto a pdf \\(F(\\theta)\\)\nwhere \\(\\Theta\\) is the type of the \\emph{parameter space}.\n\n\\section{Point estimation}\n\n\\index{point estimation}%\n\\index{point estimator}%\nA \\emph{point estimator} \\(g : (\\RV(\\Real))^n \\to \\RV(\\Theta)\\)\nis a function taking \\(n\\) iid random variables \\(X_1, \\ldots, X_n\\)\nand giving an \\emph{estimate} \\(\\estimate\\theta = g(X_1,\\ldots,X_n)\\) which is also a random variable.\n\nThe \\emph{sampling distribution} of the estimate is the distribution of the estimate.\n\nThe \\emph{standard error} of the estimate is the variance of the estimate.\n\n\\(\\estimate\\theta\\) is a random variable.\n\\(\\theta\\) is an unknown \\emph{constant}.\n\n\\index{estimate}%\n\\(\\estimate\\theta\\) is an \\emph{estimate} of \\(\\theta\\).\nThe \\emph{bias} of \\(g\\) is \\(\\Expect{\\estimate\\theta} - \\theta\\).\n\nEstimation assumes that the distribution is \\emph{constant} and\nthat the random variables are iid.\n\nExample:\nChecking coin fairness is estimating the parameter of the underlying Bernoulli distribution.\nIf \\(X_1, \\ldots, X_n \\sim \\Bernoulli(p)\\) for an unknown \\(p\\),\nthen \\(p\\) can be estimated by \\(\\hat{p} = g(X_1,\\ldots,X_n) = \\frac{1}{n} \\sum_{k=1}^n X_k\\).\nAs \\(n\\) grows,\ndue to the central limit theorem,\nthe distribution of \\(\\estimate{p}\\) approaches\na normal distribution whose mean is \\(p\\).\n\nExample:\nIn Bayesian point estimation,\nchecking coin fairness is computing \\(\\Pr(\\estimate{p} = \\frac{1}{2} | X_1 = x_1, \\ldots, X_n = x_n)\\).\nAssume that \\(\\estimate{p}\\) is uniformly distributed in \\([0,1]\\).\nAssume \\(\\Pr(h)\\), compute \\(\\Pr(h|d)\\), given \\(\\Pr(d|h)\\).\n\nThere is no way to find out whether the coin is exactly fair,\nbut the estimate can always be made more precise by adding data.\n\n\\section{Central limit theorem}\n\nThe \\emph{central limit theorem} is:\n\nThe distribution of a sum of iid random variables tends to be normal.\n\n\\section{Interval estimation}\n\nConfidence interval is an interval estimation (as opposed to point\nestimation) of a parameter.\n\n\\section{Hypothesis testing}\n\n\\section{Weak law of large numbers}\n\n\\emph{Weak law of large numbers}\n\n\\section{Regression}\n\n\\index{hyperplane!least-squares}%\n\\index{least-squares!linear regression}%\n\\index{least-squares!hyperplane}%\n\\index{least-squares hyperplane}%\n\\index{linear regression!least-squares}%\n\\index{regression!linear!least-squares}%\nThe \\emph{least-squares hyperplane} fitting the data\n\\([(x_1,y_1),\\ldots,(x_n,y_n)] : [(\\Real^m,\\Real)]\\)\nis the \\(f~x = A (x|1)\\) that minimizes\n\\(\\sum_{k=1}^n \\norm{f~x_k - y_k}^2 \\)\nwhere\n\\(m\\) is the number of input variables\nand \\(n\\) is the sample size.\nThat \\(A\\) is also the least-squares solution\nof \\(Z A = Y\\)\nwhere \\(A\\) is the unknown,\n\\(Z = \\bmat{(x_1|1) & \\ldots & (x_n|1)}^T\\),\n\\(Y = \\bmat{y_1 & \\ldots & y_n}^T\\).\nThat hyperplane is the result of\n\\emph{least-squares linear regression} on the data.\n\nThe dictionary meaning of\n\\index{regression}%\n\\index{regress}%\n``to \\emph{regress}'' is ``to go back''\nbut in statistics it \\emph{also} means\n``to estimate model parameters from sample''.\n\n\\emph{Regression} is ...\n\\emph{Parametric regression} is ...\n\\emph{Nonparametric regression} is ...\n\nElsewhere,\n\\index{input variable}%\n\\index{independent variable}%\n\\index{predictor variable}%\n\\index{explanatory variable}%\n\\index{variable!input}%\n\\index{variable!independent}%\n\\index{variable!predictor}%\n\\index{variable!explanatory}%\n\\emph{input}\nvariable is also called independent variable, predictor variable, explanatory variable,\nand\n\\index{output variable}%\n\\index{dependent variable}%\n\\index{criterion variable}%\n\\index{variable!output}%\n\\index{variable!criterion}%\n\\index{variable!dependent}%\n\\emph{output} variable is also called dependent variable, criterion variable.\n\nEstimation is computing probability space from a random variable.\nEstimation is computing the parameters of the distribution from a distribution family and some samples.\nAn estimation is \\emph{parametric} iff the shape of the probability measure function is known.\n\nLaw of the unconscious statistician / law of the lazy statistician\n\nModeling is computing the population probability space from some samples?\n\nSome statistical problems:\n\\begin{enumerate*}[label={(\\arabic*)}]\n    \\item Given distribution, generate samples.\n    \\item\nGiven a population and a sample, compute the probability that\nthe sample was indeed taken from the population.\n\\end{enumerate*}\n\n\\section{Tikhonov regularization}\n\n\\emph{Tikhonov regularization} is ...\n\n\\section{Sobolev spaces}\n\n\\index{Sobolev space}%\nAn example of \\emph{Sobolev spaces} is \\( \\{ f ~|~ \\int_\\Real (x \\to (f''(x))^2) < \\infty \\} \\).\n", "meta": {"hexsha": "0a5a9c72ca928533c0dfb92f1533301a832c499b", "size": 4954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/statistics.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/statistics.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/statistics.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.8079470199, "max_line_length": 103, "alphanum_fraction": 0.7303189342, "num_tokens": 1439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8175744828610096, "lm_q1q2_score": 0.6830700207862295}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=2cm]{geometry}\n\\usepackage{amsmath}\n\\usepackage{slashed}\n\\usepackage{tikz} % includes graphicx\n\n\\begin{document}\n\n\\noindent\nElectron positron annihilation creates two photons.\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] {$e^-$} -- (-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] {$\\gamma$};\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, v_2$} -- (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_3$};\n\\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$p_4$};\n\\draw (1,0.5) node {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nIn a typical collider experiment the momentum vectors are\n\\begin{equation*}\n\\underset{\\text{inbound electron}}\n{p_1=\\begin{pmatrix}E\\\\0\\\\0\\\\p\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound positron}}\n{p_2=\\begin{pmatrix}E\\\\0\\\\0\\\\-p\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound photon}}\n{p_3=\\begin{pmatrix}E\\\\ E\\sin\\theta\\cos\\phi\\\\ E\\sin\\theta\\sin\\phi\\\\ E\\cos\\theta\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound photon}}\n{p_4=\\begin{pmatrix}E\\\\ -E\\sin\\theta\\cos\\phi\\\\ -E\\sin\\theta\\sin\\phi\\\\ -E\\cos\\theta\\end{pmatrix}}\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{inbound positron, spin up}}\n{v_{21}=\\begin{pmatrix}-p\\\\0\\\\E+m\\\\0\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound positron, spin down}}\n{v_{22}=\\begin{pmatrix}0\\\\p\\\\0\\\\E+m\\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$\nfor annihilation where $a$ is the spin state of the inbound electron and\n$b$ is the spin state of the inbound positron.\nThe formula is from Feynman diagrams.\n\\begin{equation*}\n|\\mathcal{M}_{ab}|^2\n=\n\\frac{e^4}{N}\n\\left|\n-\\frac{\\bar{v}_{2b}\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu u_{1a}}{t-m^2}\n-\\frac{\\bar{v}_{2b}\\gamma^\\nu(\\slashed{q}_2+m)\\gamma^\\mu u_{1a}}{u-m^2}\n\\right|^2\n\\end{equation*}\n\n\\noindent\nSymbol $e$ is electron charge and\n\\begin{align*}\nq_1&=p_1-p_3\n\\\\\nq_2&=p_1-p_4\n\\end{align*}\nSymbols $t$ and $u$ are Mandelstam variables\n\\begin{align*}\nt&=q_1^2=(p_1-p_3)^2\n\\\\\nu&=q_2^2=(p_1-p_4)^2\n\\end{align*}\n\n\\noindent\nLet\n\\begin{equation*}\na_1=\\bar{v}_{2b}\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu u_{1a}\n\\qquad\na_2=\\bar{v}_{2b}\\gamma^\\nu(\\slashed{q}_2+m)\\gamma^\\mu u_{1a}\n\\end{equation*}\n\n\\noindent\nThen\n\\begin{align*}\n|\\mathcal{M}_{ab}|^2&=\\frac{e^4}{N}\\left|-\\frac{a_1}{t-m^2}-\\frac{a_2}{u-m^2}\\right|^2\\\\\n&=\n\\frac{e^4}{N}\n\\left(-\\frac{a_1}{t-m^2}-\\frac{a_2}{u-m^2}\\right)\n\\left(-\\frac{a_1}{t-m^2}-\\frac{a_2}{u-m^2}\\right)^*\\\\\n&=\n\\frac{e^4}{N}\\left(\n\\frac{a_1a_1^*}{(t-m^2)^2}\n+\\frac{a_1a_2^*}{(t-m^2)(u-m^2)}\n+\\frac{a_1^*a_2}{(t-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$\nis computed 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 polarization states is already accomplished by contraction\nof $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^*}{(t-m^2)^2}\n+\\frac{a_1a_2^*}{(t-m^2)(u-m^2)}\n+\\frac{a_1^*a_2}{(t-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}_1+m)\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu(\\slashed{p}_2-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}_1+m)\\gamma^\\mu(\\slashed{q}_2+m)\\gamma^\\nu(\\slashed{p}_2-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}_1+m)\\gamma^\\mu(\\slashed{q}_2+m)\\gamma^\\nu(\\slashed{p}_2-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}}{(t-m^2)^2}\n+\\frac{f_{12}}{(t-m^2)(u-m^2)}\n+\\frac{f_{12}^*}{(t-m^2)(u-m^2)}\n+\\frac{f_{22}}{(u-m^2)^2}\n\\right)\n\\end{equation*}\n\n\\noindent\nRun ``annihilation-1.txt'' to verify the Casimir trick for electron positron annihilation.\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_3) (p_1 \\cdot p_4) -\n 32 m^2 (p_1 \\cdot p_2) +\n 64 m^2 (p_1 \\cdot p_3) +\n 32 m^2 (p_1 \\cdot p_4) - 64 m^4\n\\\\\nf_{12}&=\n 16 m^2 (p_1 \\cdot p_3) +\n 16 m^2 (p_1 \\cdot p_4) - 32 m^4\n\\\\\nf_{22}&=\n 32 (p_1 \\cdot p_3) (p_1 \\cdot p_4) -\n 32 m^2 (p_1 \\cdot p_2) +\n 32 m^2 (p_1 \\cdot p_3) +\n 64 m^2 (p_1 \\cdot p_4) - 64 m^4\n\\end{align*}\n\n\\noindent\nIn 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{align*}\nf_{11}&=8 t u - 24 t m^2 - 8 u m^2 - 8 m^4\n\\\\\nf_{12}&=8 s m^2 - 32 m^4\n\\\\\nf_{22}&=8 t u - 8 t m^2 - 24 u m^2 - 8 m^4\n\\end{align*}\n\n\\noindent\nRun ``annihilation-2.txt'' to verify.\n\n\\subsection*{High energy approximation}\nWhen $E\\gg m$ a useful approximation is to set $m=0$ and obtain\n\\begin{align*}\nf_{11}&=8tu\n\\\\\nf_{12}&=0\n\\\\\nf_{22}&=8tu\n\\end{align*}\n\n\\noindent\nHence\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=\n\\frac{e^4}{4}\n\\left(\n\\frac{8tu}{t^2}\n+\\frac{8tu}{u^2}\n\\right)\n\\\\\n&=\n2e^4\n\\left(\n\\frac{u}{t}\n+\\frac{t}{u}\n\\right)\n\\end{align*}\n\n\\noindent\nFor $m=0$ the Mandelstam variables are\n\\begin{align*}\ns&=4E^2\\\\\nt&=-2E^2(1-\\cos\\theta)\n\\\\\nu&=-2E^2(1+\\cos\\theta)\n\\end{align*}\n\n\\noindent\nHence\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=2e^4\\left(\n\\frac{1+\\cos\\theta}{1-\\cos\\theta}+\n\\frac{1-\\cos\\theta}{1+\\cos\\theta}\n\\right)\n\\end{equation*}\n\n\\subsection*{Cross section}\nThe differential cross section is\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}=\\frac{\\langle|\\mathcal{M}|^2\\rangle}{64\\pi^2s}\n=\n\\frac{e^4}{32\\pi^2s}\n\\left(\n\\frac{1+\\cos\\theta}{1-\\cos\\theta}+\n\\frac{1-\\cos\\theta}{1+\\cos\\theta}\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=\n\\frac{\\alpha^2}{2s}\n\\left(\n\\frac{1+\\cos\\theta}{1-\\cos\\theta}+\n\\frac{1-\\cos\\theta}{1+\\cos\\theta}\n\\right)\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*}\n\n\\noindent\nHence\n\\begin{equation*}\nd\\sigma=\n\\frac{\\alpha^2}{2s}\n\\left(\n\\frac{1+\\cos\\theta}{1-\\cos\\theta}+\n\\frac{1-\\cos\\theta}{1+\\cos\\theta}\n\\right)\\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\\frac{2s}{2\\pi\\alpha^2}\n\\int_0^{2\\pi}\\int d\\sigma\n\\\\\n&=\\int\n\\left(\n\\frac{1+\\cos\\theta}{1-\\cos\\theta}+\n\\frac{1-\\cos\\theta}{1+\\cos\\theta}\n\\right)\n\\sin\\theta\\,d\\theta,\n\\quad a\\le\\theta\\le\\pi-a\n\\end{align*}\n\n\\noindent\nAngular support is limited to an arbitrary $a>0$\nbecause $I(0)$ and $I(\\pi)$ are undefined.\nAssume that $I(\\theta)-I(a)$ is computable given $\\theta$ by either symbolic\nor numerical integration.\n\n\\bigskip\n\\noindent\nLet $C$ be the normalization constant\n\\begin{equation*}\nC=I(\\pi-a)-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-a\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\nProbability density function $f(\\theta)$ is the derivative of $F(\\theta)$.\n\\begin{equation*}\nf(\\theta)=\\frac{dF(\\theta)}{d\\theta}=\\frac{1}{C}\n\\left(\n\\frac{1+\\cos\\theta}{1-\\cos\\theta}+\n\\frac{1-\\cos\\theta}{1+\\cos\\theta}\n\\right)\\sin\\theta,\n\\quad a\\le\\theta\\le\\pi-a\n\\end{equation*}\n\n\\noindent\nRun ``annihilation-4.txt\" to plot $f(\\theta)$ for $a=\\pi/6=30^\\circ$.\n\n\\begin{center}\n\\includegraphics[scale=0.5]{annihilation.png}\n\\end{center}\n\n\\noindent\nProbability distribution for $30^\\circ$ bins ($a=30^\\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$ & $30^\\circ$ & -- \\\\\n$30^\\circ$ & $60^\\circ$ & 0.33 \\\\\n$60^\\circ$ & $90^\\circ$ & 0.17 \\\\\n$90^\\circ$ & $120^\\circ$ & 0.17 \\\\\n$120^\\circ$ & $150^\\circ$ & 0.33 \\\\\n$150^\\circ$ & $180^\\circ$ & -- \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection*{Data from DESY PETRA experiment}\n\\noindent\nSee www.hepdata.net/record/ins191231, Table 2, 14.0 GeV.\n\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\n$x$ & $y$\\\\\n\\hline\n$0.0502$ & 0.09983\\\\\n$0.1505$ & 0.10791\\\\\n$0.2509$ & 0.12026\\\\\n$0.3512$ & 0.13002\\\\\n$0.4516$ & 0.17681\\\\\n$0.5521$ & 0.1957\\phantom{0}\\\\\n$0.6526$ & 0.279\\phantom{00}\\\\\n$0.7312$ & 0.33204\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nData $x$ and $y$ have the following relationship\nwith the differential cross section formula.\n\\begin{equation*}\nx=\\cos\\theta\n\\qquad\ny=\\frac{d\\sigma}{d\\Omega}\n\\end{equation*}\n\n\\noindent\nTo compute predicted values $\\hat{y}$ from the cross section formula,\nuse $s=(14.0\\,\\text{GeV})^2$.\nMultiply by $(\\hbar c)^2$ to convert to SI\nand multiply by $10^{37}$ to convert square meters to nanobarns.\n\\begin{equation*}\n\\hat{y}\n=\n\\frac{\\alpha^2}{2s}\n\\left(\n\\frac{1+x}{1-x}+\n\\frac{1-x}{1+x}\n\\right)\n\\times(\\hbar c)^2\n\\times10^{37}\n\\end{equation*}\n\n\\noindent\nThe following table shows predicted values $\\hat{y}$.\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$x$ & $y$ & $\\hat{y}$\\\\\n\\hline\n$0.0502$ & 0.09983 & 0.106325\\\\\n$0.1505$ & 0.10791 & 0.110694\\\\\n$0.2509$ & 0.12026 & 0.120005\\\\\n$0.3512$ & 0.13002 & 0.135559\\\\\n$0.4516$ & 0.17681 & 0.159996\\\\\n$0.5521$ & 0.1957\\phantom{0} & 0.198562\\\\\n$0.6526$ & 0.279\\phantom{00} & 0.262745\\\\\n$0.7312$ & 0.33204 & 0.348884\\\\\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.98\n\\end{equation*}\n\n\\noindent\nThe result indicates that the model $d\\sigma$ explains 98\\% of the variance in the data.\n\n\\bigskip\n\\noindent\nRun ``annihilation-3.txt'' to verify.\n\n\\subsection*{Notes}\nHere are some notes on how the Eigenmath scripts work.\n\n\\bigskip\n\\noindent\nTo convert $a_1$ and $a_2$ to Eigenmath code,\nit is instructive to write $a_1$ and $a_2$ in full component form.\n\\begin{equation*}\na_1^{\\mu\\nu}\n=\\bar{v}_{2\\alpha}\\gamma^{\\mu\\alpha}{}_\\beta(\\slashed{q}_1+m)^\\beta{}_\\rho\\gamma^{\\nu\\rho}{}_\\sigma u_1^\\sigma\n\\qquad\na_2^{\\nu\\mu}\n=\\bar{v}_{2\\alpha}\\gamma^{\\nu\\alpha}{}_\\beta(\\slashed{q}_2+m)^\\beta{}_\\rho\\gamma^{\\mu\\rho}{}_\\sigma u_1^\\sigma\n\\end{equation*}\n\n\\noindent\nTranspose the $\\gamma$ tensors to form inner products over $\\alpha$ and $\\rho$.\n\\begin{equation*}\na_1^{\\mu\\nu}\n=\\bar{v}_{2\\alpha}\\gamma^{\\alpha\\mu}{}_\\beta(\\slashed{q}_1+m)^\\beta{}_\\rho\\gamma^{\\rho\\nu}{}_\\sigma u_1^\\sigma\n\\qquad\na_2^{\\nu\\mu}\n=\\bar{v}_{2\\alpha}\\gamma^{\\alpha\\nu}{}_\\beta(\\slashed{q}_2+m)^\\beta{}_\\rho\\gamma^{\\rho\\mu}{}_\\sigma u_1^\\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{v}_{2\\alpha}\\gamma^{\\alpha\\mu}{}_\\beta(\\slashed{q}_1+m)^\\beta{}_\\rho\\gamma^{\\rho\\nu}{}_\\sigma u_1^\\sigma\n\\\\\n\\rightarrow\\quad\n\\text{\\tt a1 = dot(v2bar[s2],gammaT,qslash1 + m I,gammaT,u1[s1])}\n\\end{multline*}\n\n\\noindent\nwhere $s_1$ and $s_2$ are spin indices.\nSimilarly for $a_2$ we have\n\\begin{multline*}\na_2=\\bar{v}_{2\\alpha}\\gamma^{\\alpha\\mu}{}_\\beta(\\slashed{q}_2+m)^\\beta{}_\\rho\\gamma^{\\rho\\nu}{}_\\sigma u_1^\\sigma\n\\\\\n\\rightarrow\\quad\n\\text{\\tt a2 = dot(v2bar[s2],gammaT,qslash2 + m I,gammaT,u1[s1])}\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_2=a_2^{\\nu\\mu}$.\n\\begin{equation*}\na_1^{\\mu\\nu}a_{2\\nu\\mu}^*\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}_1+m)\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu(\\slashed{p}_2-m)\\gamma_\\nu(\\slashed{q}_1+m)\\gamma_\\mu\n\\right)\\\\\n&=\n(\\slashed{p}_1+m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{q}_1+m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\tau\n(\\slashed{p}_2-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}_1+m)^\\alpha{}_\\beta\n\\gamma^{\\beta\\mu}{}_\\rho\n(\\slashed{q}_1+m)^\\rho{}_\\sigma\n\\gamma^{\\sigma\\nu}{}_\\tau\n(\\slashed{p}_2-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\nThis is the code for transposing $\\gamma$.\n\\begin{align*}\n\\gamma^{\\beta\\mu}{}_\\beta\n&\\quad\\rightarrow\\quad\n\\text{\\tt gammaT = transpose(gamma)}\n\\\\\n\\gamma^\\delta{}_{\\nu\\eta}\n&\\quad\\rightarrow\\quad\n\\text{\\tt gammaL = transpose(dot(gmunu,gamma))}\n\\end{align*}\n\n\\noindent\nTo convert $f_{11}$ to Eigenmath code, use an intermediate variable $T$ for the inner product.\n\\begin{equation*}\nT^{\\alpha\\mu\\nu}{}_{\\nu\\mu\\alpha}\n\\quad\\rightarrow\\quad\n\\text{\\tt T = dot(P1,gammaT,Q1,gammaT,P2,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}_1+m)\\gamma^\\mu(\\slashed{q}_2+m)\\gamma^\\nu(\\slashed{p}_2-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": "953ac895bb7c1923bbb3ec96352e7bfade033a2f", "size": 16378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "annihilation.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": "annihilation.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": "annihilation.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": 24.9284627093, "max_line_length": 113, "alphanum_fraction": 0.6650384662, "num_tokens": 6892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.6830700061139187}}
{"text": "\n\\subsection{Price preferences}\n\nWe start with a simple model, where the customer has price preference.\n\n\\(U_{ij}=-\\beta_i p_{ij} +\\epsilon_{ij}\\)\n\n\\subsection{Product characteristics}\n\n\\(U_{ij}=\\alpha_i x_j -\\beta_i p_{ij} +\\epsilon_{ij}\\)\n\n\\subsection{Individual characteristics}\n\n\\(U_{ij}=\\alpha_i x_j -\\beta_i p_{ij} + \\theta_j d_i +\\epsilon_{ij}\\)\n\n\\subsection{The general form}\n\nWe can convert this to the form:\n\n\\(U_{ij}=\\Theta z_{ij} + \\epsilon_{ij}\\)\n\n", "meta": {"hexsha": "061baa33c1474debd67d44e337bb707d817aa9e5", "size": 461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumerDiscrete/02-01-components.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/02-01-components.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/02-01-components.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.9545454545, "max_line_length": 70, "alphanum_fraction": 0.7028199566, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6830675743237512}}
{"text": "\\subsubsection{Labeled Generic Time Series Model} \\label{labeled_generic_time_series_model}\nA generic time series model was created for the evaluating software. A generic time series over the domain set\n$\\mathbb{U}$ is a linked list of data points. Those data points are containing a generic data object and an\noptional label. The generic object has to be an element of the domain set $\\mathbb{U}$. In the case of the carried out\nexperiment a data point contains the acceleration data of the x-axis, the y-axis and z-axis. Therefore $\\mathbb{U}$ is\nsimilar to $\\mathbb{Z}^3$ or better $\\mathbb{R}^3$. $\\mathbb{U}$ is the set of vectors containing three integer\nvalues and the distance function $d$ on $\\mathbb{U}$ is the euclidean distance\n$\\sqrt[2]{(x_1 - x_2)^2 + (y_1 - y_2)^2 + (z_1 - z_2)^2}$. The generic approach for the implemented time series model\nand the time series measures should make it easier to evaluate similar experiments on other domains. A label of a data\npoint is used to mark a data point as part of a gesture.\n", "meta": {"hexsha": "723902239be105de1d57b5e6f09ad20ea7a70152", "size": 1034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/experiment/experimental_protocol/labeled_generic_time_series_model.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/experiment/experimental_protocol/labeled_generic_time_series_model.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/experiment/experimental_protocol/labeled_generic_time_series_model.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": 94.0, "max_line_length": 118, "alphanum_fraction": 0.7640232108, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6829342429441811}}
{"text": "\\section{Derivation of the two stage promoter equation}\n\nShahreaei and Swain derive the full analytical protein distribution for a two\nstage (i.e. an unregulated promoter) and a three stage (i.e. a promoter that\ntransitions between active and inactive) promoter \\cite{Shahrezaei2008}. In\nthis section wi will follow the derivation augmenting the details at each step\nfor clarity.\n\n\\subsection{From the master equation}\n\nFirst let us write the chemical master equation for this system. Let $p$ and $m$\nbe the protein and mRNA copy numbers, respectively, and $P_{m,p}(t)$ be the\nprobability of having $m$ mRNA and $p$ proteins at time t. Then we can use the\n``spread the butter'' approach to write the discrete difference equation\n\\begin{equation}\n\\begin{aligned}\nP_{m,p}(t + \\Delta t) =\nP_{m,p}(t) +\n\\overbrace{r_m \\Delta t\n\\left[ P_{m-1,p}(t) - P_{m,p}(t) \\right]}^\\text{mRNA production}\n+ \\overbrace{r_p m \\Delta t\n\\left[ P_{m, p-1}(t) - P_{m, p}(t) \\right]}^\\text{protein production}\\\\\n+ \\underbrace{\\gamma_m \\Delta t\n\\left[ (m + 1) P_{m+1,p}(t) - m P_{m, p}(t) \\right]}_\\text{mRNA degradation}\n+ \\underbrace{\\gamma_p \\Delta t\n\\left[ (p + 1) P_{m, p+1}(t) - p P_{m, p}(t) \\right]}_\\text{protein\ndegradation},\n\\end{aligned}\n\\end{equation}\nwhere $r_m$ and $r_p$ are the mRNA and protein production rates respectively,\n$\\gamma_m$ and $\\gamma_p$ are the mRNA and protein degradation rates\nrespectively, and $\\Delta t$ is a time interval small enough so that only one\nevent can take place.\n\nWe rearrange the terms, divide both sides by $\\Delta t$ , obtaining\n\\begin{equation}\n  \\begin{aligned}\n\\frac{P_{m,p}(t + \\Delta t) - P_{m,p}(t)}{\\Delta t} =\nr_m \\left[ P_{m-1,p}(t) - P_{m,p}(t) \\right]\n+ r_p m \\left[ P_{m, p-1}(t) - P_{m, p}(t) \\right]\\\\\n+ \\gamma_m \\left[ (m + 1) P_{m+1,p}(t) - m P_{m, p}(t) \\right]\n+ \\gamma_p \\left[ (p + 1) P_{m, p+1}(t) - p P_{m, p}(t) \\right].\n  \\end{aligned}\n\\end{equation}\nNote that the production of protein is taken per mRNA.\nWe now take the limit $\\Delta t \\rightarrow 0$ to obtain the final form of the\nchemical master equation\n\\begin{equation}\n  \\begin{aligned}\n\\frac{\\partial P_{m,p}}{\\partial t} =\nr_m \\left[ P_{m-1,p}(t) - P_{m,p}(t) \\right] +\nr_p m \\left[ P_{m, p-1}(t) - P_{m, p}(t) \\right]\\\\\n+ \\gamma_m \\left[ (m + 1) P_{m+1,p}(t)\n- m P_{m, p}(t) \\right]\n+ \\gamma_p \\left[ (p + 1) P_{m, p+1}(t) - p P_{m, p}(t) \\right].\n  \\end{aligned}\n\\end{equation}\n\n\\mrm{Eq. 1 of the paper.}\n\nLet us now divide by the slowest rate, i.e. $\\gamma_p$\n\\begin{equation}\n\\begin{aligned}\n\\frac{1}{\\gamma_p} \\frac{\\partial P_{m,p}}{\\partial t} =\n\\frac{r_m}{\\gamma_p} \\left[ P_{m-1,p}(t) - P_{m,p}(t) \\right]\n+ \\frac{r_p}{\\gamma_p} m  \\left[ P_{m, p-1}(t) - P_{m, p}(t) \\right]\\\\\n+ \\frac{\\gamma_m}{\\gamma_p} \\left[ (m + 1) P_{m+1,p}(t) - m P_{m, p}(t) \\right]\n+ \\left[ (p + 1) P_{m, p+1}(t) - p P_{m, p}(t) \\right].\n\\end{aligned}\n\\label{eq_cme_over_gammap}\n\\end{equation}\nWe now introduce the following variables:\n\\begin{align}\n  a \\equiv \\frac{r_m}{\\gamma_p}\\\\\n  b \\equiv \\frac{r_p}{\\gamma_m}\\\\\n  \\gamma \\equiv \\frac{\\gamma_m}{\\gamma_p}\\\\\n  \\tau \\equiv \\gamma_p \\cdot t\n\\end{align}\nSubstituting these variables into \\eref{eq_cme_over_gammap} we obtain\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial P_{m,p}}{\\partial \\tau} =\na \\left[ P_{m-1,p}(t) - P_{m,p}(t) \\right]\n+ b \\gamma m  \\left[ P_{m, p-1}(t) - P_{m, p}(t) \\right]\\\\\n+ \\gamma \\left[ (m + 1) P_{m+1,p}(t) - m P_{m, p}(t) \\right]\n+ \\left[ (p + 1) P_{m, p+1}(t) - p P_{m, p}(t) \\right].\n\\end{aligned}\n\\label{eq_cme_tau}\n\\end{equation}\nNote that we used $\\frac{1}{\\gamma_p}\\frac{\\partial}{\\partial t} =\n\\frac{\\partial}{\\partial \\tau}$.\n\nWe now define the generating function\n\\begin{equation}\nF\\left[ s, z \\right] = \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p P_{m, p},\n\\label{eq_generating_function}\n\\end{equation}\nwhere from now on we abbreviate $P_{m, p}(t)$ as $P_{m, p}$. The generating\nfunction will allow us to write a single PDE rather than an infinite system of\nPDEs for each mRNA and protein copy number. The generating function time\nderivative is given by\n\\begin{equation}\n\\frac{\\partial F}{\\partial \\tau} =\n\\frac{\\partial}{\\partial \\tau} \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p\nP_{m, p} =\n\\sum_{m=0}^{\\infty}\n\\sum_{p=0}^{\\infty} s^m z^p \\frac{\\partial}{\\partial \\tau} P_{m, p}.\n\\label{eq_dF_dtau}\n\\end{equation}\nWe now substitute \\eref{eq_cme_tau} into \\eref{eq_dF_dtau}\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial F}{\\partial \\tau} =\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p\n\\left\\{ a \\left[ P_{m-1,p} - P_{m,p} \\right]\n+ b \\gamma m  \\left[ P_{m, p-1} - P_{m, p} \\right] \\right. \\\\\n\\left. + \\gamma \\left[ (m + 1) P_{m+1,p} - m P_{m, p} \\right]\n+ \\left[ (p + 1) P_{m, p+1} - p P_{m, p} \\right] \\right\\}.\n\\end{aligned}\n\\label{eq_dF_dtau_complete}\n\\end{equation}\n\nIn order to make progress with this equation we note that we can distribute\nthe terms in parenthesis as\n\\begin{equation}\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p \\left( P_{m+1, p} - P_{m, p}\n\\right) =\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p P_{m+1, p}\n- \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p P_{m, p}.\n\\label{eq_split_sum}\n\\end{equation}\nWe can now factorize $s^{-1}$ from the first term on the left hand side of\n\\eref{eq_split_sum} and redefine the variable to sum over.\n\\begin{equation}\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p \\left( P_{m+1, p} - P_{m, p}\n\\right) =\ns^{-1} \\sum_{(m+1)=0}^{\\infty} \\sum_{p=0}^{\\infty} s^{m+1} z^p P_{m+1, p}\n- \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p P_{m, p}.\n\\end{equation}\nBut since both sums on the left hand side are taken over the same ranges we can\nwrite it as\n\\begin{equation}\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p \\left( P_{m+1, p} - P_{m, p}\n\\right) =\n\\left( s^{-1} - 1 \\right) \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p P_{m,\np}\n\\end{equation}\n\nWith this identity we can rewrite \\eref{eq_dF_dtau_complete} as\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial F}{\\partial \\tau} =\n(s - 1) \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p \\left( a P_{m,p} \\right)\n+ (z - 1) \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p b \\gamma m P_{m,p}\n\\\\\n+ \\left( s^{-1} - 1 \\right) \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p\n\\gamma m P_{m,p}\n+ \\left( z^{-1} - 1 \\right) \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p\n\\gamma p P_{m,p}.\n\\end{aligned}\n\\label{eq_dF_dtau_identity}\n\\end{equation}\n\nAnother useful identity can be derived if we note that\n\\begin{equation}\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p m P_{m, p} =\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} z^p s \\frac{\\partial s^m}{\\partial s}\nP_{m, p}.\n\\end{equation}\nBut since $z^p$ and $P_{m, p}$ do not depend on $s$ we can include these terms\ninside the derivative, obtaining\n\\begin{equation}\n\\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p m P_{m, p} =\ns \\frac{\\partial}{\\partial s}\\left( \\sum_{m=0}^{\\infty} \\sum_{p=0}^{\\infty} s^m z^p P_{m, p} \\right) =\ns \\frac{\\partial}{\\partial s}F.\n\\end{equation}\n\nUsing this identity in \\eref{eq_dF_dtau_identity} allow us to remove all the\nsums, obtaining a single PDE of the form\n\\begin{equation}\n\\frac{\\partial F}{\\partial \\tau} =\n(s - 1) a F + (z - 1) b \\gamma s \\frac{\\partial F}{\\partial s}\n+ \\left( s^{-1} - 1 \\right) \\gamma s \\frac{\\partial F}{\\partial s}\n+ \\left( z^{-1} - 1 \\right) z \\frac{\\partial F}{\\partial Z}.\n\\end{equation}\nRearranging terms we obtain\n\\begin{equation}\n\\frac{\\partial F}{\\partial \\tau} =\na (sF - s)\n+ b \\gamma \\left( z s \\frac{\\partial F}{\\partial s} - s \\frac{\\partial\nF}{\\partial s} \\right)\n+ \\gamma \\left( \\frac{\\partial F}{\\partial s} - s \\frac{\\partial F}{\\partial s}\n\\right)\n+ \\left( \\frac{\\partial F}{\\partial z} - z \\frac{\\partial F}{\\partial z}\n\\right).\n\\label{eq_df_dtau_PDE}\n\\end{equation}\n\nWith the generating function we were able to pass from an infinite system of PDE\nfor each mRNA and protein copy number to a single PDE. We now have to find a\nsolution for this equation and then infer back the probability distribution\ngiven the definition of the generating function.\n\nWe now note a pattern in \\eref{eq_df_dtau_PDE}. If we define $u \\equiv s - 1$ and $v \\equiv z - 1$, which satisfy\n\\begin{align}\n  \\frac{\\partial}{\\partial s} = \\frac{\\partial}{\\partial u},\\\\\n  \\frac{\\partial}{\\partial z} = \\frac{\\partial}{\\partial v},\n\\end{align}\nwe can rewrite \\eref{eq_df_dtau_PDE} as\n\\begin{equation}\n  \\frac{\\partial F}{\\partial \\tau} =\n  a u F\n  + b \\gamma v \\left( u + 1  \\right) \\frac{\\partial F}{\\partial u}\n  - \\gamma u \\frac{\\partial F}{\\partial u}\n  - v \\frac{\\partial F}{\\partial v}.\n\\end{equation}\n\nWe now divide by $v$ and rearrange terms obtaining\n\\begin{equation}\n  \\frac{\\partial F}{\\partial v}\n  - \\gamma \\left[ b (u + 1) - \\frac{u}{v} \\right] \\frac{\\partial F}{\\partial u}\n  + \\frac{1}{v} \\frac{\\partial F}{\\partial \\tau}\n  = a \\frac{u}{v} F,\n  \\label{eq_swain_2}\n\\end{equation}\n\\mrm{which is Eq. (2) in \\cite{Shahrezaei2008}.}\n\n\\eref{eq_swain_2} is a semi-linear PDE that can be solved using the method of\nthe characteristics (this method is described in the Appendix\n\\ref{seq_method_characteristics}). In order to apply this method we write\n\\eref{eq_swain_2} as\n\\begin{equation}\n  A(v, u, \\tau) \\frac{\\partial F}{\\partial v}\n  + B(v, u, \\tau) \\frac{\\partial F}{\\partial u}\n  + C(v, u, \\tau) \\frac{\\partial F}{\\partial \\tau}\n  = f(u, v, \\tau, F),\n\\end{equation}\nwhere\n\\begin{equation}\n  \\begin{aligned}\n  A &= 1,\\\\\n  B &= - \\gamma \\left[ b (1 + u) - \\frac{u}{v} \\right],\\\\\n  C &= \\frac{1}{v},\\\\\n  f &= a \\frac{u}{v} F.\n  \\label{eq_coef_definition}\n  \\end{aligned}\n\\end{equation}\n\nThe method of characteristics requires us to solve the PDE along the\ncharacteristic lines. To do so we can parametrize the characteristics with\nparameter $r$. This allow us to write the equality\n\\begin{equation}\n  {{dv \\over dr} \\over A(v, u, \\tau)} =\n  {{du \\over dr} \\over B(v, u, \\tau)} =\n  {{d\\tau \\over dr} \\over C(v, u, \\tau)} =\n  {{dF \\over dr} \\over f(v, u, \\tau, F)}.\n  \\label{eq_lagrange_charpit}\n\\end{equation}\nSubstituting \\eref{eq_coef_definition} into \\eref{eq_lagrange_charpit} gives\n\\begin{equation}\n  {{dv \\over dr} \\over 1} =\n  {{du \\over dr} \\over - \\gamma \\left[ b (1 + u) - \\frac{u}{v} \\right]} =\n  {{d\\tau \\over dr} \\over {1 \\over v}} =\n  {{dF \\over dr} \\over a \\frac{u}{v} F}.\n\\end{equation}\nOr, if a particular parametrization $r$ of the curves is fixed, then these\nequations can be written as a system of ODEs as\n\\begin{align}\n  \\frac{d v}{d r} &= 1,\n  \\label{eq_ODE_1}\\\\\n  \\frac{d u}{d r} &= - \\gamma \\left[ b (1 + u) - \\frac{u}{v}\n  \\right],\n  \\label{eq_ODE_2}\\\\\n  \\frac{d \\tau}{d r} &= \\frac{1}{v},\n  \\label{eq_ODE_3}\\\\\n  \\frac{d F}{d r} &= \\frac{a u}{v} F.\n  \\label{eq_ODE_4}\n\\end{align}\n\n\\subsubsection{Solving system of ODEs}\n\nOnce we find the system of ODEs that integrate the variables along the\ncharacteristic line we can try to solve this system in order to find the general\nintegral surface that solves the PDE. The initial conditions for the system are\ngiven by $\\tau = 0$, $u = u_0$, $v = v_0$. Let's start with \\eref{eq_ODE_1}.\nFor this equation we use separation of variables which simply gives\n\\begin{equation}\n  {\\partial v \\over \\partial r} = 1 \\Rightarrow\n  r = v + C_1,\n  \\label{eq_ODE_sol_1}\n\\end{equation}\nwhere $C_1$ is an integration constant.\n\nFor \\eref{eq_ODE_3} we can write\n\\begin{equation}\n  {\\partial \\tau \\over \\partial r} = {1 \\over v} \\Rightarrow\n  {\\partial r \\over \\partial \\tau} = v.\n\\end{equation}\nIf we now substitute \\eref{eq_ODE_sol_1} we find\n\\begin{equation}\n  {\\partial r \\over \\partial \\tau} = r - C_1.\n\\end{equation}\nUsing separation of variables on this equation we get\n\\begin{equation}\n  \\int {dr \\over r - C_1} = \\int d\\tau,\n\\end{equation}\nwhich when integrated gives\n\\begin{equation}\n  \\ln (r - C_1) = \\tau + C_2'.\n\\end{equation}\nwhere $C_2'$ is an integration constant. If we now solve for $r$ we find\n\\begin{equation}\n  r = C_2e^{\\tau} + C_1,\n  \\label{eq_ODE_sol_3}\n\\end{equation}\nwhere $C_2 \\equiv e^{C_2'}$.\n\nIf we substitute \\eref{eq_ODE_sol_3} back on \\eref{eq_ODE_sol_1} we obtain a\nfunctional relationship between $v$ and $\\tau$ of the form\n\\begin{equation}\n  C_2 e^{\\tau} + C_1 = v + C_1 \\Rightarrow\n  v = C_2 e^{\\tau}.\n\\end{equation}\n\nUsing the initial conditions $\\tau = 0$, $v=v_0$ we find that $C_2 = v_0$,\ntherefore the functional relationship between $\\tau$ and $v$ is of the form\n\\begin{equation}\n  v = v_0 e^{\\tau}.\n  \\label{eq_v_tau_relation}\n\\end{equation}\n\nUsing \\eref{eq_ODE_1} and \\eref{eq_ODE_2} we can compute\n$\\partial u / \\partial v$ as\n\\begin{equation}\n  {\\partial u \\over \\partial v} =\n  - \\gamma \\left[ b (1 + u) - {u \\over v} \\right].\n\\end{equation}\nThis is a first order linear ODE which we can rewrite as\n\\begin{equation}\n  {du \\over dv} = -\\gamma b\n  - \\gamma b u\n  + {\\gamma u \\over v} =\n  -\\gamma b\n  + u \\left( {\\gamma \\over v} - \\gamma b \\right).\n\\end{equation}\nGrouping terms with respect to $u$ gives\n\\begin{equation}\n  {du \\over dv} + \\left( \\gamma b - {\\gamma \\over v} \\right) u = - \\gamma b.\n  \\label{eq_dudv}\n\\end{equation}\n\\eref{eq_dudv} can be solved by the integrating factor method. In this case\nthe integrating factor is given by\n\\begin{equation}\n  e^{\\int \\gamma \\left( b - {1 \\over v} \\right) dv} =\n  e^{\\gamma b v - \\gamma \\ln v} = v^{-\\gamma} e^{\\gamma b v}\n  \\label{eq_dudv_integ_factor}\n\\end{equation}\n\nMultiplying both sides of \\eref{eq_dudv} by \\eref{eq_dudv_integ_factor} we find\nthat the left hand side is transformed into the derivative of the integrating\nfactor times $u$, i.e.\n\\begin{equation}\n  {d \\over dv}\\left[ v^{-\\gamma} e^{\\gamma b v} \\cdot u \\right] =\n  -\\gamma b v^{-\\gamma} e^{-\\gamma b v}.\n\\end{equation}\n\nWe can now integrate both sides, obtaining\n\\begin{equation}\nu v^{-\\gamma} e^{\\gamma b v} =\n-\\gamma b \\int dv \\; v^{-\\gamma} e^{\\gamma b v} + C,\n\\end{equation}\nwhere $C$ is an integrating constant. Solving for $u$ we find\n\\begin{equation}\n  u(v) = v^{\\gamma} e^{-\\gamma b v} \\left[ C -\n  \\gamma b \\int dv {e^{\\gamma b v} \\over v^{\\gamma}} \\right].\n  \\label{eq_implicit_sol_u}\n\\end{equation}\n\\mrm{Eq. (26)}\n\nTo solve the integral we expand the exponential as a Taylor series, i.e.\n\\begin{equation}\n  e^{-\\gamma b v} = \\sum_{n=0}^{\\infty} {\\left( \\gamma b v \\right)^n \\over n!}.\n\\end{equation}\n\nUsing this on the integral in \\eref{eq_implicit_sol_u} gives\n\\begin{equation}\n  \\int dv {e^{\\gamma b v} \\over v^{\\gamma}} =\n  \\int dv {1 \\over v^{\\gamma}}\n  \\sum_{n=0}^{\\infty} {\\left( \\gamma b v \\right)^n \\over n!}\n\\end{equation}\nWe can take out the terms that do not depend on $v$ out of the integral to\nobtain\n\\begin{equation}\n\\int dv {1 \\over v^{\\gamma}}\n  \\sum_{n=0}^{\\infty} {\\left( \\gamma b v \\right)^n \\over n!} =\n  \\sum_{n=0}^{\\infty} {\\left( \\gamma b \\right)^n \\over n!}\n  \\int dv \\; v^{n - \\gamma} =\n  \\sum_{n=0}^{\\infty} {\\left( \\gamma b \\right)^n \\over n!}\n  {v^{n - \\gamma + 1} \\over n - \\gamma + 1}.\n  \\label{eq_integral_implicit_sol_u}\n\\end{equation}\n\nSubstituting \\eref{eq_integral_implicit_sol_u} into \\eref{eq_implicit_sol_u}\ngives\n\\begin{equation}\n  u(v) = v^\\gamma e^{-\\gamma b v}\n  \\left[ C - \\gamma b \\sum_{n=0}^\\infty {\\left( \\gamma b \\right)^n \\over n!}\n  {v^{n - \\gamma + 1} \\over n - \\gamma + 1} \\right].\n\\end{equation}\nThis can be simplified to obtain\n\\begin{equation}\n  u(v) = e^{-\\gamma b v} \\left[ C v^{\\gamma}\n  - \\sum_{n=0}^\\infty {\\left( \\gamma b v \\right)^{n+1} \\over\n  n! \\left( n - \\gamma + 1 \\right)} \\right].\n  \\label{eq_SI_27_uofv}\n\\end{equation}\n\\mrm{Eq (27) in the SI.}\n\nThe question now becomes how can we evaluate the sum\n\\begin{equation}\n  S(\\gamma b v) = \\sum_{n=0}^\\infty {\\left( \\gamma b v \\right)^{n+1} \\over\n  n! \\left( n - \\gamma + 1 \\right)}.\n\\end{equation}\nJust as Shahrenzaei \\& Swain we will follow Bender \\& Orszag and use the\nso-called Laplace's method for sums. The idea behind this method is to find the\nleading behavior of the sum. What this means is that if there are some very\ndominant terms in the sum we can just add those in the vincinity to get a decent\napproximation of the sum.\n\nTo find the leading behavior of the sum we first need to identify the largest\nterms in the series. Let us start by looking at the ratio of the\n$(n+1)^{\\text{th}}$ term to the $n^{\\text{th}}$ term of the sum. This is given\nby\n\\begin{equation}\n{{(\\gamma b v)^{n+2} \\over (n+1)! (n - \\gamma + 2)}\n\\over\n{(\\gamma b v)^{n+1} \\over n! (n - \\gamma + 1)}}\n=\n{\\gamma b v \\over n + 1} \\cdot\n{(n - \\gamma + 1) \\over (n - \\gamma + 2)}.\n\\label{eq_ratio_series}\n\\end{equation}\nFrom this ratio we can see that since we assumed that $\\gamma \\gg 1$ we can\ndiscard the second term on the right hand side of \\eref{eq_ratio_series} since\n\\begin{equation}\n{(n - \\gamma + 1) \\over (n - \\gamma + 2)} \\approx 1.\n\\end{equation}\n\nTaking this approximation we can see that the ratio is greater than 1 if\n$n + 1 < \\gamma b v$ and it is less than one if the opposite is true, i.e.\n$n + 1 > \\gamma b v$. That implies that terms in the series increase until they\nreach $n \\sim \\gamma b v$, to then decrease with increasing $n$.\n\nAs $\\gamma b v \\rightarrow \\infty$ the series become sharply peaked around\n$n = \\gamma b v$. Therefore we could approximate this sum by just summing in the\nvicinity of $n = \\gamma b v$. This would give us\n\\begin{align}\n  S(\\gamma b v) =\n\\sum_{n=0}^\\infty {\\left( \\gamma b v \\right)^{n+1} \\over\n  n! \\left( n - \\gamma + 1 \\right)} \\approx\n\\sum_{n=\\gamma b v (1 - \\epsilon)}\n    ^{\\gamma b v (1 + \\epsilon)}\n    {\\left( \\gamma b v \\right)^{n+1} \\over\n  n! \\left( n - \\gamma + 1 \\right)},\n\\end{align}\nwith errors increasingly smaller as $\\gamma b v \\rightarrow \\infty$.\n\nIf this approximation is valid, that means we can use Stirling's formula to\napproximate the factorial term remaining in the sum. If we let\n$n \\approx \\gamma b v + s$, where $s$ is small compared to $\\gamma b v$, then by\nStirling's approximation we have\n\\begin{equation}\n  n! \\approx \\left( {n \\over e} \\right)^n \\sqrt{2 \\pi n}.\n\\end{equation}\nSubstituting our approximation for $n$ gives\n\\begin{equation}\n  n! \\approx (\\gamma b v + s)^n e^{-n} \\sqrt{2 \\pi n}.\n\\end{equation}\nFor this equation we left the exponent with $n$ untouched. That violates our\napproximation of $n \\approx \\gamma b v + s$, but we will come back to that\nlater. For now it is convenient to carry it as $n$ and substitute at the end.\n\nWe now factorize out the term $\\gamma b v$ obtaining\n\\begin{equation}\n  n! \\approx \\left[ \\gamma b v \\left( 1 + {s \\over \\gamma b v} \\right) \\right]^n\n  e^{-n} \\sqrt{2 \\pi n}.\n\\end{equation}\nWe can rewrite the term in parenthesis in a convenient way as\n\\begin{equation}\n  n! \\approx (\\gamma b v)^n\n  \\exp \\left\\{ n \\ln \\left( 1 + {s \\over \\gamma b v} \\right) \\right\\}\n  e^{-n} \\sqrt{2 \\pi n}.\n\\end{equation}\nThe term in the exponential can be Taylor expanded up to second order as\n\\begin{equation}\nn \\ln \\left( 1 + {s \\over \\gamma b v} \\right) \\approx\nn \\left[ {s \\over \\gamma b v}\n- {1 \\over 2} \\left( {s \\over \\gamma b v}  \\right)^2 \\right].\n\\end{equation}\n\nPutting all these together we obtain an approximation of the form\n\\begin{equation}\n  n! \\approx (\\gamma b v)^n\n             e^{-n}\n             e^{n {s \\over \\gamma b v}}\n             e^{-{n \\over 2} {s^2 \\over (\\gamma b v)^2}}\n             \\sqrt{2 \\pi n}.\n\\end{equation}\nLet's now substitute what we didn't do at the beginning for the exponents.\nLet's replace $n = \\gamma b v + s$ in the exponents obtaining\n\\begin{equation}\n  e^{-n}\n  e^{n {s \\over \\gamma b v}}\n  e^{-{n \\over 2} {s^2 \\over (\\gamma b v)^2}} =\n  \\exp \\left\\{ -\\gamma b v - s\n               + (\\gamma b v + s){s \\over \\gamma b v}\n               - {(\\gamma b v + s) \\over 2} {s^2 \\over (\\gamma b v)^2} \\right\\}.\n\\end{equation}\nExpanding the terms in the exponent gives\n\\begin{equation}\n\\exp \\left\\{ -\\gamma b v - s\n             + (\\gamma b v + s){s \\over \\gamma b v}\n             - {(\\gamma b v + s) \\over 2} {s^2 \\over (\\gamma b v)^2} \\right\\} =\n\\exp \\left\\{ -\\gamma b v - s\n             + s\n             + {s^2 \\over \\gamma b v}\n             - {1 \\over 2} {s^2 \\over \\gamma b v}\n             - {1 \\over s} {s^3 \\over (\\gamma b v)^2} \\right\\}\n\\end{equation}\nSimplifying terms gives\n\\begin{equation}\n  \\exp \\left\\{ -\\gamma b v\n             - s\n             + s\n             + {s^2 \\over \\gamma b v}\n             - {1 \\over 2} {s^2 \\over \\gamma b v}\n             - {1 \\over s} {s^3 \\over (\\gamma b v)^2} \\right\\} =\n\\exp \\left\\{ -\\gamma b v\n             + {1 \\over 2} {s^2 \\over \\gamma b v}\n             - {1 \\over s} {s^3 \\over (\\gamma b v)^2} \\right\\}\n\\end{equation}\nNote that by assumption $s^3 \\ll (\\gamma b v)^2$, therefore we can remove the\nthird term in the exponent. All these steps finally give an approximation for\n$n!$ of the form\n\\begin{equation}\n  n! \\approx (\\gamma b v)^n e^{-\\gamma b v} e^{s^2 \\over 2 \\gamma b v}\n             \\sqrt{2 \\pi \\gamma b v}, \\;\\;\n             \\text{for} \\; (\\gamma b v) \\rightarrow \\infty.\n\\end{equation}\n\\mrm{Eq (28) in the SI}\n\nSo far the Laplace approximation for sums allowed us to find the leading terms\nof the sum to then have an approximation for the $n!$ term. We can now\nsubstitute back this approximation into the sum\n\\begin{align}\n  S(\\gamma b v) &= \\sum_{n = 0}^{\\infty} {(\\gamma b v)^{n + 1} \\over\n                                        n! (n - \\gamma + 1)},\\\\\n  &\\approx \\sum_{n = 0}^{\\infty}\n  {(\\gamma b v)^{n + 1} \\over (n - \\gamma + 1)} \\cdot\n  \\overbrace{\n  { (\\gamma b v)^{-n} e^{\\gamma b v} e^{-s^2 \\over 2 \\gamma b v}\n  \\over\n  \\sqrt{2 \\pi \\gamma b v}\n  }}^{1 \\over n!}.\n\\end{align}\nWe will now substitute for all $n \\approx \\gamma b v + s$ and approximate the\nsum as an integral on $s$ with an extended range from $-\\infty$ to $\\infty$.\nThis is valid since the terms around $n = \\gamma b v$ dominate the sum, so the\nextra terms would have a marginally small impact in the result. With this then\nwe have\n\\begin{equation}\n  S(\\gamma b v) \\approx \\int_{-\\infty}^{\\infty} ds {\n  \\gamma b v e^{\\gamma b v} e^{-s^2 \\over 2 \\gamma b v}\n  \\over\n  \\left[ \\gamma (b v - 1) + s + 1 \\right] \\sqrt{2 \\pi \\gamma b v}\n  }.\n\\end{equation}\n\nNow we factorize a term $\\gamma (b v - 1)$ from the denominator, obtaining\n\\begin{equation}\n  S(\\gamma b v) \\approx \\int_{-\\infty}^{\\infty} ds {\n  \\gamma b v e^{\\gamma b v} e^{-s^2 \\over 2 \\gamma b v}\n  \\over\n  \\gamma (b v - 1) \\left[ 1 + {s + 1 \\over \\gamma (b v - 1) }\\right]\n  \\sqrt{2 \\pi \\gamma b v}\n  }.\n\\end{equation}\nSince we assumed $\\gamma \\gg 1$ and $\\gamma b v \\gg s$ we can safely approximate\n$\\left[ 1 + {s + 1 \\over \\gamma (b v - 1) }\\right] \\approx 1$, obtaining\n\\begin{equation}\n  S(\\gamma b v) \\approx {b v e^{\\gamma b v} \\over b v - 1}\n  \\int_{-\\infty}^{\\infty} ds\n  {e^{-s^2 \\over 2 \\gamma b v}\n  \\over\n  \\sqrt{2 \\pi \\gamma b v}}.\n\\end{equation}\nThe term inside the integral integrates to 1 by the Gaussian integral, so we\nhave\n\\begin{equation}\n  S(\\gamma b v) \\approx {b v e^{\\gamma b v} \\over b v - 1}.\n\\end{equation}\n\\mrm{Eq (29) in the SI.}\n\nWith this rather convoluted result we can go back to \\eref{eq_SI_27_uofv} to\nwrite\n\\begin{align}\n  u(v) &= e^{-\\gamma b v} \\left[ C v^{\\gamma}\n  - \\sum_{n=0}^\\infty {\\left( \\gamma b v \\right)^{n+1} \\over\n  n! \\left( n - \\gamma + 1 \\right)} \\right].\\\\\n  &\\approx e^{-\\gamma b v}\n  \\left[ C v^{\\gamma} - {b v e^{\\gamma b v} \\over b v - 1} \\right]\n\\end{align}\nSimplifying terms we have\n\\begin{equation}\n  u(v) \\approx C v^{\\gamma} e^{-\\gamma b v}\n  - {b v \\over b v - 1}\n  \\label{eq_SI_30_uofv}\n\\end{equation}\n\\mrm{Eq (30) in the SI.}\n\nTo obtain the value of the integration constant $C$ we use the initial\nconditions $u(0) = u_o$ and $v(0) = v_o$. This gives us\n\\begin{equation}\n  u_o = C v_o^{\\gamma} e^{-\\gamma b v_o}\n  - {b v_o \\over b v_o - 1}.\n\\end{equation}\nSolving for $C$ gives\n\\begin{equation}\n  C = \\left[ u_o - {b v_o \\over b v_o - 1} \\right] v_o^{-\\gamma} e^{\\gamma b v}.\n\\end{equation}\n\nThat means that \\eref{eq_SI_30_uofv} is given by\n\\begin{align}\n  u(v) &= \\left[ u_o - {b v_o \\over b v_o - 1} \\right]\n  v_o^{-\\gamma} e^{\\gamma b v_o} v^{\\gamma} e^{-\\gamma b v}\n  - {b v \\over b v - 1}\\\\\n  &= \\left( u_o - {b v_o \\over b v_o - 1}  \\right)\n  \\left( {v \\over v_o} \\right)^{\\gamma}\n  e^{\\gamma b v (v_o - v)}\n  + {b v \\over 1 - b v}.\n  \\label{eq_uofv_with_C}\n\\end{align}\n\nRecall that \\eref{eq_v_tau_relation} tells us the relationship between $v$ and\n$\\tau$, i.e. $v = v_o e^{\\tau}$. This means that since $\\tau > 0$ then\n$v = v_o e^{\\tau} > v_o$, therefore since the first term of\n\\eref{eq_uofv_with_C} is dominated by the exponential, and\n$e^{\\gamma b (v_o - v)}$ quickly converges to zero for large $\\gamma$ we can\napproximate \\eref{eq_uofv_with_C} as\n\\begin{equation}\n  u(v) \\approx {b v \\over 1 - b v}.\n  \\label{eq_SI_31_uofv}\n\\end{equation}\n\\mrm{Eq (30) in the SI and (5) in the main text.}\nInterestingly since in the generating function \\eref{eq_generating_function}\n$u$ was indirectly related to mRNA copy number and $v$ to protein,\n\\eref{eq_SI_31_uofv} implies that since $u$ quickly converges to a fixed\nfunction of $v$, for most of the protein lifetime the mRNA is at steady state.\n\n\\subsection{Finding the generating function}\n\nWith so much mathematical details so far it is easy to lose track of what is\nwhat we are trying to achieve. Let's recall that the ODEs that define the\ncharacteristics of the generating function are given byj\n\\begin{align}\n  \\frac{d v}{d r} &= 1,\n  \\\\\n  \\frac{d u}{d r} &= - \\gamma \\left[ b (1 + u) - \\frac{u}{v}\n  \\right],\n  \\\\\n  \\frac{d \\tau}{d r} &= \\frac{1}{v},\n  \\\\\n  \\frac{d F}{d r} &= \\frac{a u}{v} F.\n\\end{align}\nSo far we found functional relationships between them given by\n\\begin{equation}\n  v = v_o e^{\\tau},\n\\end{equation}\nand\n\\begin{equation}\n  u = {b v \\over 1 - b v}.\n\\end{equation}\n\nNow we can combine ${dv \\over dr}$ and ${dF \\over dr}$ with these relationships\nto obtain\n\\begin{align}\n  {\\partial F \\over \\partial v} &= a {u \\over v} F, \\\\\n  &= a {b v \\over v (1 - b v)} F, \\\\\n  &= {a b \\over 1 - b v} F\n\\end{align}\nThis ODE can be solved by separation of variables as\n\\begin{equation}\n  \\int {dF \\over F} = \\int {a b \\over 1 - b v} dv.\n\\end{equation}\nUpon defining $x = 1 - b v, \\; dx = - b\\; dv$ we have\n\\begin{equation}\n  \\ln F = \\int {a b \\over x} \\cdot {1 \\over -b} dx = -a \\ln x + C'.\n\\end{equation}\nTherefore\n\\begin{equation}\n  \\ln F = -a \\ln (1 - b v) + C',\n  \\label{eq_lnF_constant}\n\\end{equation}\nwhith $C'$ being an integration constant. To find the value of this constant\nwe must use the initial conditions. But we originally didn't set initial\nconditions for $F$. If we start our birth and death process with $k$ proteins\nat time $\\tau = 0$, we would have that\n\\begin{align}\n  F(\\tau = 0) &= \\sum_{p=0}^{\\infty}P_p z^p\\\\\n  &= \\sum_{p=0}^{\\infty} \\delta (p - k) z^p = z^k.\n\\end{align}\nThis initial condition doesn't sum over mRNA, because as explained before for\n\\eref{eq_SI_31_uofv}, for most of the protein lifetime the mRNA is in steady\nstate. Formally this initial condition is valid for times of order\n${\\gamma_p \\over \\gamma_m} = \\gamma^{-1}$. Now $z = 1 + v$, therefore\n$F(\\tau = 0) = (1 - v_o)^k$. Using this initial condition we have\n\\begin{equation}\n  \\ln (1 + v_o)^k = -a \\ln (1 - b v_o) + C'.\n\\end{equation}\nSolving for $C'$ gives\n\\begin{equation}\n  C' = \\ln (1 + v_o)^k + a \\ln (1 - b v_o).\n\\end{equation}\nTherefore substituting this in \\eref{eq_lnF_constant} gives\n\\begin{align}\n  \\ln F &= a \\ln \\left( {1 - b v_o \\over 1 - b v} \\right)^a\n  + \\ln (1 + v_o)^k,\\\\\n  &= \\ln \\left[ \\left( {1 - b v_o \\over 1 - b v} \\right)^a\n  (1 + v_o)^k \\right].\n\\end{align}\nThis gives us the generating function of the form\n\\begin{equation}\n  F =   \\left( {1 - b v_o \\over 1 - b v} \\right)^a\n  (1 + v_o)^k .\n  \\label{eq_generating_function_onv}\n\\end{equation}\n\nWe would like to write the generating function as a function of the original\nvariable $z$ and $\\tau$. This is done by recalling that we defined $z = 1 + v$,\nin combination with \\eref{eq_v_tau_relation} gives $v_o = (z - 1) e^{-\\tau}$.\nUsing this on \\eref{eq_generating_function_onv} gives\n\\begin{equation}\n  F = \\left( {1 - b (z - 1) e^{-\\tau}\n  \\over\n  1 - b (z - 1)\n  } \\right)^a\n  \\left[ 1 + (z - 1) e^{-\\tau} \\right]^k.\n\\end{equation}\n\\mrm{Eq (35) in the SI.}\n\nIf we set $k = 0$ we get\n\\begin{equation}\n  F = \\left( {1 - b (z - 1) e^{-\\tau}\n  \\over\n  1 - b (z - 1)\n  } \\right)^a.\n  \\label{eq_generating_function_onz}\n\\end{equation}\n\\mrm{Eq (7) in the main text.}\n\n\\subsection{Deriving the probability distribution for proteins}\n\nGiven that we know the generating function we can backtrack the entire\ndistribution. The difficulty resides in being able to write\n\\eref{eq_generating_function_onz} in the standard form\n\\begin{equation}\n  F = \\sum_{p} z^p P_p.\n\\end{equation}\nBy the definition of the generating function we can see that to compute any\nprobability we can compute\n\\begin{equation}\n  P_p = {1 \\over p!} \\left. {\\partial ^p F \\over \\partial z^p}.\n  \\right\\rvert_{z=0}\n  \\label{eq_prob_from_generating}\n\\end{equation}\nSo let's rewrite \\eref{eq_generating_function_onz} in a more convenient form\n\\begin{equation}\n  F = \\left( {1 + b (1 - z) e^{-\\tau}\n  \\over\n  1 + b (z - 1)\n  }  \\right)^a.\n\\end{equation}\n\nNow we want to write $F$ as a product of two factors, one of them without any\n$z$ term. This means we can write\n\\begin{align}\n  F(z, \\tau) &= \\left( {1 + b e^{-\\tau} \\over 1 + b } \\right)^a\n  \\left[\n  \\left( {1 + b} \\over 1 + b (1 - z) \\right)^a\n  \\left( {1 + b (1 - z) e^{-\\tau} \\over 1 + b e^{-\\tau}}  \\right)^a\n  \\right], \\\\\n  &= \\left( {1 + b e^{-\\tau} \\over 1 + b } \\right)^a\n  { \\left( {1 + b (1 - z) \\over 1 + b} \\right)^{-a}\n  \\over\n  \\left( {1 + b (1 - z) e^{-\\tau} \\over 1 + b e^{-\\tau}} \\right)^{-a}\n  }, \\\\\n  &= \\left( {1 + b e^{-\\tau} \\over 1 + b } \\right)^a\n  { \\left( {1 + b - b z) \\over 1 + b} \\right)^{-a}\n  \\over\n  \\left( {1 + b e^{-\\tau} - b z e^{-\\tau} \\over 1 + b e^{-\\tau}} \\right)^{-a}\n  }, \\\\\n  &= \\left( {1 + b e^{-\\tau} \\over 1 + b } \\right)^a\n  { \\left( 1 - {b z \\over 1 + b} \\right)^{-a}\n  \\over\n  \\left( 1 - {b z \\over e^{\\tau} + b} \\right)^{-a}\n  }. \\label{eq_generating_final}\n\\end{align}\n\\mrm{Eq. (36) in the SI.}\n\nThere are two identities that Shahrezaei \\& Swain quote for the following steps.\nThe first one is given by\n\\begin{equation}\n    \\left. {\\partial ^n \\over \\partial z^n}\n    \\left[ 1 - q z \\right]^{-a} \\right\\vert _{z=0} =\n    {\\Gamma(a + n) \\over \\Gamma(a)} q^n.\n\\end{equation}\nTo proof this relationship let's first take the first derivative of the function\n\\begin{align}\n  {\\partial \\over \\partial z}\n  \\left. \\left[ 1 - q z \\right]^{-a} \\right\\vert _{z=0}\n  &= \\left. -a \\left[ 1 - q z \\right]^{-(a + 1)} (-q) \\right\\vert _{z=0}\\\\\n  &= a q.\n\\end{align}\n\nNow let's take the second derivative\n\\begin{align}\n  {\\partial^2 \\over \\partial z^2}\n  \\left. \\left[ 1 - q z \\right]^{-a} \\right\\vert _{z=0}\n  &= {\\partial \\over \\partial z}\n  \\left. a q \\left[ 1 - q z \\right]^{-(a + 1)} \\right\\vert _{z=0}\\\\\n  &= \\left. -a (a + 1) q \\left[ 1 - q z \\right]^{-(a + 2)} (-q)\n  \\right\\vert _{z=0} \\\\\n  &= a(a + 1) q^2.\n\\end{align}\n\nThe pattern seems to be emerging now. For completeness let's take the 3rd\nderivative\n\\begin{align}\n  {\\partial^3 \\over \\partial z^3}\n  \\left. \\left[ 1 - q z \\right]^{-a} \\right\\vert _{z=0}\n  &= {\\partial \\over \\partial z}\n  \\left. -a (a + 1) q \\left[ 1 - q z \\right]^{-(a + 2)} (-q)\n  \\right\\vert _{z=0} \\\\\n  &= \\left. -a (a + 1) (a + 2) q^2\n  \\left[ 1 - q z \\right]^{-(a + 3)} (-q) \\right\\vert _{z=0} \\\\\n  &= a(a + 1) (a + 2) q^3.\n\\end{align}\n\nWe have that $a (a + 1) (a + 2) \\cdots (a + n - 1) = {(a + n - 1)! \\over (a -\n1)!}$ for $n, a \\in \\mathbb{Z}$, or in general for any positive $n, a$ we have\n$a (a + 1) (a + 2) \\cdots (a + n - 1) = {\\Gamma(a + n) \\over \\Gamma(a)}$.\nTherefore for the $n^{\\text{th}}$ derivative it must be true that\n\\begin{equation}\n    \\left. {\\partial ^n \\over \\partial z^n}\n    \\left[ 1 - q z \\right]^{-a} \\right\\vert _{z=0} =\n    {\\Gamma(a + n) \\over \\Gamma(a)} q^n.\n    \\label{eq_derivative_identity}\n\\end{equation}\n\\mrm{Eq (37) in the SI.}\n\nThe second identity the authors quote is more convoluted. It could be proof by\ninduction but it would be a really long proof. For convenience we will quote\nthe result. The identity tells us that the $n^{\\text{th}}$ derivative of a ratio\nof functions is given by\n\\begin{equation}\n  {\\partial ^n \\over \\partial z^n} {x(z) \\over y(z)} =\n  n! \\sum_{k=0}^n {\\partial ^{n-k} \\over \\partial z^{n-k}} x(z)\n  \\sum_{j = 0}^k (-1)^j (k + 1) y(z)^{-j-1}\n  {\\partial^k \\over \\partial z^k} y(z)^j\n  \\label{eq_derivative_ratio}\n\\end{equation}\n\\mrm{Eq (39) in SI.}\n\n\\eref{eq_prob_from_generating} gives us the recipe for how to compute any\nprobability from the generating function we derived in\n\\eref{eq_generating_final}. To use \\eref{eq_derivative_ratio} we define from\n\\eref{eq_generating_final}\n\\begin{equation}\n  x(z) = \\left( 1 - {b z \\over 1 + b} \\right)^{-a},\n\\end{equation}\nand\n\\begin{equation}\n  y(z) = \\left( 1 - {b z \\over e^{\\tau} + b} \\right)^{-a}.\n\\end{equation}\nWith these definitions in hand we use \\eref{eq_prob_from_generating} along with\n\\eref{eq_derivative_ratio} to compute\n\\begin{equation}\n  \\scriptscriptstyle\n  P_p = \\left. {1 \\over p!} \\left( {1 + b e^{-\\tau} \\over 1 + b} \\right)^a\n  \\left[ p! \\sum_{k=0}^p  {\\partial^{p-k} \\over \\partial z^{p-k}}\n  \\left(1 - {b z \\over 1 + b} \\right) \\cdot\n  \\sum_{j=0}^k {(-1)^j (k + 1) \\over (j + 1)! (p - k)! (k - j)!} \\cdot\n  \\left[ \\left( 1 - {b z \\over e^\\tau + b} \\right)^{-a} \\right]^{-(j+1)} \\cdot\n  {\\partial^k \\over \\partial z^k}\n  \\left[ \\left( 1 - {b z \\over e^\\tau + b}  \\right)^{-a} \\right]^j\n  \\right]\\right\\vert _{z=0}.\n\\end{equation}\nUsing \\eref{eq_derivative_identity} we can rewrite the derivatives as\n\\begin{equation}\n  \\scriptstyle\n  P_p = \\left( {1 + b e^{-\\tau} \\over 1 + b} \\right)^a\n  \\sum_{k=0}^p {\\Gamma(a + p - k) \\over \\Gamma(a)}\n  \\left( {b \\over 1 + b} \\right)^{p - k} \\cdot\n  \\sum_{j=0}^k {(-1)^j (k + 1) \\over (j + 1)! (p - k)! (k - j)!} \\cdot\n  {\\Gamma(aj + k) \\over \\Gamma(aj)} \\left( {b \\over e^\\tau + b} \\right)^k\n\\end{equation}\n\\mrm{Eq (39) in SI.}\n\nFor the second sum the authors quote the following identity\n\\begin{equation}\n  \\sum_{j=0}^k {(-1)^j \\Gamma(aj + k) \\over (j + 1)! \\Gamma(aj) (k - j)!} =\n  {(-1)^k \\Gamma(a + 1) \\over \\Gamma(a - k + 1) (k + 1)!}.\n\\end{equation}\n\\mrm{Eq (40) in SI. I tried really hard deriving this result, but I\ncouldn't figure it out. Nevertheless computationally it can be shown to be true\nfor several values of $k$.}\n\nUsing this we have\n\\begin{equation}\n  \\scriptstyle\n  P_p = \\left( {1 + b e^{-\\tau} \\over 1 + b} \\right)^a\n  \\sum_{k=0}^p {\\Gamma (a + p - k) \\over \\Gamma(a)}\n  \\left( {b \\over 1 + b} \\right)^{p - k}\n  {(k + 1) \\over (p - k)!} \\left( b \\over e^\\tau + b \\right)^k\n  {(-1)^k \\Gamma(a + 1) \\over \\Gamma(a - k + 1) (k + 1)!}.\n\\end{equation}\nThis can be further simplified to\n\\begin{equation}\n  P_p = \\left( {1 + b e^{-\\tau} \\over 1 + b} \\right)^a\n  \\left( {b \\over 1 + b} \\right)^p\n  \\sum_{k=0}^p {(-1)^k \\over k!}\n  {a \\Gamma(a + p - k) \\over (p - k)! \\Gamma(a - k + 1)}\n  \\left( {1 + b \\over e^\\tau + b} \\right)^k.\n  \\label{eq_dist_nohyper}\n\\end{equation}\n\\mrm{Eq (41) in the SI. Shahrezaei and Swain missed one factor of\n$a$ since $\\Gamma(a + 1) / \\Gamma(a) = a$, but the error doesn't propagate to\nthe other equations.}\n\n\\subsection{Gauss Hypergeometric Function}\n\nAn important function for the solution is the Hypergeometric function\n$_2F_1(a; b; c; z)$. This funciton is defined as\n\\begin{equation}\n  _2F_1(a; b; c; z) \\equiv \\sum_{k=0}^\\infty\n  {(a)_k (b)_k \\over (c)_k} {z^k \\over k!}.\n\\end{equation}\n\nThe series is indetermined if $c$ is a non-positive integer. The $(q)_k$ terms\nare the so-called rising factorials or rising Pochhammer symbols defined as\n\\begin{equation}\n  (q)_k = \\begin{cases}\n  1, & \\text{for }k = 0.\\\\\n  q (q + 1)\\cdots (q + k - 1) & \\text{for k > 0},\n  \\end{cases}\n\\end{equation}\nor using gamma functions\n\\begin{equation}\n  (q)_k = {\\Gamma (q + k) \\over \\Gamma (q)}.\n\\end{equation}\n\nIf $a$ or $b$ are non-positive integers the series reduces to the polynomial\n\\begin{equation}\n_2F_1(-n; b; c; z) = \\sum_{k=0}^\\infty (-1)^k {n \\choose k}\n                    {(b)_k \\over (c)_k} z^k.\n\\end{equation}\nOr for non-integer values we have\n\\begin{equation}\n_2F_1(-n; b; c; z) = \\sum_{k=0}^\\infty (-1)^k\n                    {\\Gamma (n + 1) \\over \\Gamma (n - k + 1)}\n                    {(b)_k \\over (c)_k} {z^k \\over k!}.\n\\end{equation}\n\nFrom the definition of the Pochhammer symbols they must satisfy\n\\begin{equation}\n  (-a)_k = {\\Gamma (a + 1) \\over \\Gamma (a - k + 1)}.\n\\end{equation}\nThis relationship can be shown using the Euler reflection formula\n\\begin{equation}\n  \\Gamma (z) \\Gamma (1 - z) = {\\pi \\over \\sin (\\pi z)}.\n\\end{equation}\n\nIf $z \\equiv -a + k$ we have\n\\begin{equation}\n  \\Gamma(-a + k) \\Gamma(1 - (-a + k)) = {\\pi \\over \\sin(\\pi (-a + k))}.\n\\end{equation}\nOn the other hand if $z \\equiv -a$ we have\n\\begin{equation}\n  \\Gamma(-a) \\Gamma(1 - (-a)) = {\\pi \\over \\sin(\\pi (-a))}.\n\\end{equation}\n\nFrom the definition of $(-a)_k$ we have\n\\begin{equation}\n  (-a)_k = {\\Gamma(-a + k) \\over \\Gamma(-a)}\n         = {{\\pi \\over \\sin(\\pi (-a + k)) \\Gamma(1 - (-a + k))}\n         \\over\n           {\\pi \\over \\sin(\\pi(-a)) \\Gamma(1 - (-a))}}.\n\\end{equation}\nSimplifying this we have\n\\begin{equation}\n  (-a)_k = {\\Gamma(1 - (-a)) \\over \\Gamma(1 - (-a + k))}\\cdot\n           {\\sin(\\pi (-a + k)) \\over \\sin(\\pi (-a))}.\n\\end{equation}\n\nFor $\\sin(\\pi (-a + k))$ we can use the identity\n\\begin{equation}\n  \\sin(\\pi (-a + k)) = \\sin(\\pi (-a)) \\cos(\\pi k) -\n                       \\cos(\\pi (-a)) \\sin(\\pi k).\n\\end{equation}\nSince for $k \\in \\mathbb{Z}$ we have that $\\sin(\\pi k) = 0$, and\n$\\cos(\\pi k) = (-1)^k$, it must be true that for $a \\notin \\mathbb{N}$\n\\begin{align}\n  (-a)_k &= {\\Gamma(a + 1) \\over \\Gamma(a - k + 1)}\n           {(-1)^k \\sin(\\pi (-a)) \\over \\sin(\\pi (-a))},\\\\\n         &= (-1)^k {\\Gamma(a + 1) \\over \\Gamma(a - k + 1)}.\n\\end{align}\n\\mrm{Eq (43) in SI}.\n\nFrom \\eref{eq_dist_nohyper} we can rewrite the term inside the sum as a\nhypergeometric function by rewriting $\\Gamma(a - k + n) =\n\\Gamma(a + n - 1 - k + 1)$. This means that if we carefully look at the elements\nof the sum we can rewrite it as a hypergeometric function like\n\\begin{align}\n  \\sum_{k=0}^p {(-1)^k \\over k!}\n  {a \\Gamma(a + p - k) \\over \\Gamma(p - k + 1) \\Gamma(a - k + 1)}\n  \\left( {1 + b \\over e^\\tau + b} \\right)^k =\n  a\n  \\overbrace{\n  {\\Gamma(p + a - 1 + 1) \\over \\Gamma(a + 1) \\Gamma(p + 1)}\n  }^{\\text{terms to complete } {}_2F_1}\n  \\times \\\\\n  \\sum_{k=0}^p\n  \\overbrace{\n  (-1)^k {\\Gamma(p + 1) \\over \\Gamma(p - k + 1)}\n  }^{(a)_k = (-p)_k}\n  \\overbrace{\n  (-1)^k {\\Gamma(a + 1) \\over \\Gamma(a - k + 1)}\n  }^{(b)_k = (-a)_k}\n  \\underbrace{\n  {1 \\over (-1)^k }{\\Gamma(p + a - 1 + k + 1) \\over \\Gamma(p + a - 1 + 1)}\n  }_{{1 \\over (c)_k} = {1 \\over (-p - a + 1)_k}}\n  \\underbrace{\n  {1 \\over k!} \\left( {1 + b \\over e^\\tau + b} \\right)^k\n  }_{z^k \\over k!}.\n\\end{align}\nTherefore the sum can be simply written as\n\\begin{equation}\n\\sum_{k=0}^p {(-1)^k \\over k!}\n  {a \\Gamma(a + p - k) \\over \\Gamma(p - k + 1) \\Gamma(a - k + 1)}\n  \\left( {1 + b \\over e^\\tau + b} \\right)^k =\n  {a \\Gamma(p + a - 1 + 1) \\over \\Gamma(a + 1) \\Gamma(p + 1)}\n  {}_2F_1 \\left( -p, -a, 1 - a - n, {1 + b \\over e^\\tau + b} \\right)\n\\end{equation}\n\nThis relationship means that we can rewrite \\eref{eq_dist_nohyper} as\n\\begin{equation}\n  P_p = \\left( {1 + b e^{-\\tau} \\over 1 + b} \\right)^a\n  \\left( {b \\over 1 + b} \\right)^p\n  {\\Gamma(p + a) \\over \\Gamma(a) p!}\n  {}_2F_1 \\left( -p, -a, 1 - a - n, {1 + b \\over e^\\tau + b} \\right),\n\\end{equation}\nThis is the final expression for the protein distribution valid for\n$\\Gamma \\gg 1$ and $\\tau \\gg \\Gamma^{-1}$.\n\\mrm{Eq (44) in SI and (8) in main text.}\n\n\\subsection{Steady State Distribution}\nTo compute the steady state distribution we take the limit when\n$\\tau \\rightarrow \\infty$. That gives ${}_2F_1(a, b, c, 0)$ which cancels all\nterms in the sum except for the first one. Therefore ${}_2F_1(a, b, c, 0) = 1$.\nThis means that we have\n\\begin{equation}\n  P_p^{ss} = {\\Gamma(p + a) \\over \\Gamma(p + 1) \\Gamma(a)}\n  \\left( 1 - {b \\over 1 + b}  \\right)^a\n  \\left( {b \\over 1 + b} \\right)^p.\n\\end{equation}\n\\mrm{Eq (9) in main text.}\n\nThis is a negative binomial distribution with mean\n\\begin{equation}\n  \\left\\langle p \\right\\rangle = a \\cdot b =\n  {r_m \\over \\gamma_p}{r_p \\over \\gamma_m},\n\\end{equation}\nand variance\n\\begin{equation}\n  \\sigma_p^2 = ab(1 + b) =\n  {r_m \\over \\gamma_p}{r_p \\over \\gamma_m} \\left(1 + {r_p \\over \\gamma_m}\\right)\n\\end{equation}\n", "meta": {"hexsha": "12d25e16557cf306c345f9e4286455ca5a0b7a7e", "size": 40268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/appendix_two_stage_dist.tex", "max_stars_repo_name": "RPGroup-PBoC/chann_cap", "max_stars_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-21T04:06:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T07:36:58.000Z", "max_issues_repo_path": "doc/appendix_two_stage_dist.tex", "max_issues_repo_name": "RPGroup-PBoC/chann_cap", "max_issues_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/appendix_two_stage_dist.tex", "max_forks_repo_name": "RPGroup-PBoC/chann_cap", "max_forks_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-29T17:43:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-09T00:20:16.000Z", "avg_line_length": 37.0110294118, "max_line_length": 113, "alphanum_fraction": 0.6206665342, "num_tokens": 15450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152325073083131, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.6828550179228817}}
{"text": "\\documentclass{report}\n\\usepackage{amsfonts, amsmath, amssymb, hyperref}\n\\renewcommand{\\chaptername}{}\n\\begin{document}\n\n\\tableofcontents\n\n\\chapter{Brusselator}\n\nThe Brusselator is characterized by the reactions\n\n\\begin{align}\n  &A \\rightarrow X \\\\\n  &2X + Y \\rightarrow 3X \\\\\n  &B + X \\rightarrow Y + D \\\\\n  &X \\rightarrow E\n\\end{align}\n\nand the rate equations are\n\n\\begin{align}\n  \\frac{\\mathrm{d}}{\\mathrm{d}t} \\{X\\} &= \\{A\\} + \\{X\\}^2\\{Y\\} - \\{B\\}\\{X\\} - \\{X\\} \\\\\n  \\frac{\\mathrm{d}}{\\mathrm{d}t} \\{Y\\} &= \\{B\\}\\{X\\} - \\{X\\}^2\\{Y\\}\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Damped spring}\n\nThe damped spring is described by the simple equation\n\n\\begin{equation}\n  m\\frac{\\mathrm{d}^2x}{\\mathrm{d}t^2} = -kx + -c\\dot{x}\n\\end{equation}\n\nwhere $k$ is the spring constant and $c$ is the damping coefficient. We can trivially write this as the following 1st-order ODEs:\n\n\\begin{align}\n  \\frac{\\mathrm{d}x}{\\mathrm{d}t} &= v \\\\\n  \\frac{\\mathrm{d}v}{\\mathrm{d}t} &= -kx + -cv\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Double pendulum}\n\n\\section{Lagrangian}\n\n\\begin{equation}\n  L = \\frac{1}{6} ml^2 \\left[ \\dot{\\theta}^2_2 + 4\\dot{\\theta}^2_1 + 3 \\dot{\\theta}_1 \\dot{\\theta}_2 \\cos(\\theta_1 - \\theta_2) \\right] + \\frac{1}{2} mgl(3 \\cos\\theta_1 + \\cos\\theta_2)\n\\end{equation}\n\n\\section{Equations of motion}\n\nThe momenta are\n\\begin{align}\n  p_{\\theta_1} &= \\frac{\\partial L}{\\partial \\dot{\\theta}_1} = \\frac{1}{6} ml^2 \\left[8 \\dot{\\theta}_1 + 3 \\dot{\\theta}_2 \\cos(\\theta_1 - \\theta_2) \\right] \\\\\n  p_{\\theta_2} &= \\frac{\\partial L}{\\partial \\dot{\\theta}_2} = \\frac{1}{6} ml^2 \\left[2 \\dot{\\theta}_2 + 3 \\dot{\\theta}_1 \\cos(\\theta_1 - \\theta_2) \\right]\n\\end{align}\nwhich can be inverted to\n\\begin{align}\n  \\dot{\\theta}_1 &= \\frac{6}{ml^2} \\frac{2 p_{\\theta_1} - 3 \\cos(\\theta_1 - \\theta_2) p_{\\theta_2}}{16 - 9 \\cos^2(\\theta_1 - \\theta_2)} \\\\\n  \\dot{\\theta}_2 &= \\frac{6}{ml^2} \\frac{8 p_{\\theta_2} - 3 \\cos(\\theta_1 - \\theta_2) p_{\\theta_1}}{16 - 9 \\cos^2(\\theta_1 - \\theta_2)}\n\\end{align}\nFinally,\n\\begin{align}\n  \\dot{p}_{\\theta_1} &= \\frac{\\partial L}{\\partial\\theta_1} = - \\frac{1}{2} ml^2 \\left[\\dot{\\theta}_1 \\dot{\\theta}_2 \\sin(\\theta_1 - \\theta_2) + 3 \\frac{g}{l} \\sin\\theta_1 \\right] \\\\\n  \\dot{p}_{\\theta_2} &= \\frac{\\partial L}{\\partial\\theta_2} = - \\frac{1}{2} ml^2 \\left[- \\dot{\\theta}_1 \\dot{\\theta}_2 \\sin(\\theta_1 - \\theta_2) + \\frac{g}{l} \\sin\\theta_2 \\right]\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Duffing equation}\n\nThe Duffing equation is given by the second-order ODE\n\\begin{equation}\n  \\frac{\\mathrm{d}^2x}{\\mathrm{d}t^2} + \\delta \\frac{\\mathrm{d}x}{\\mathrm{d}t} + \\alpha x + \\beta x^3 = \\gamma \\cos(\\omega t)\n\\end{equation}\nwhich we can cast into the first-order ODEs:\n\\begin{align}\n  \\frac{\\mathrm{d}x}{\\mathrm{d}t} &= v \\\\\n  \\frac{\\mathrm{d}v}{\\mathrm{d}t} &= \\gamma \\cos(\\omega t) - \\delta v - \\alpha x - \\beta x^3\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Lorenz system}\n\n\\begin{align}\n  \\frac{\\mathrm{d}x}{\\mathrm{d}t} &= \\sigma(y - x) \\\\\n  \\frac{\\mathrm{d}y}{\\mathrm{d}t} &= x(\\rho - z) - y \\\\\n  \\frac{\\mathrm{d}z}{\\mathrm{d}t} &= xy - \\beta x\n\\end{align}\n\n\\begin{itemize}\n  \\item $\\sigma = 10, \\beta = 8/3, \\rho = 28$\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Lotka-Volterra equations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Van der Pol oscillator}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{2-D Van der Pol oscillator}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Symmetric top}\n\n\\section{Moments of inertia}\n\n\\begin{align}\n  I_1 = I_2 &= \\frac{3}{20} m \\left( r^2 + \\frac{l^2}{4} \\right) \\\\\n  I_3 &= \\frac{3}{m r^2}\n\\end{align}\n\n\\section{Lagrangian}\n\n\\begin{equation}\n  L = \\frac{1}{2} I_1 \\left( \\dot{\\theta}^2 + \\dot{\\varphi}^2 \\sin^2\\theta \\right) + \\frac{1}{2} I_3 \\left( \\dot{\\psi} + \\dot{\\varphi}\\ \\cos\\theta \\right)^2 - mgl \\cos\\theta\n\\end{equation}\n\n\\section{Equations of motion}\n\nThe Euler-Lagrange equation gives\n\\begin{equation}\n  \\frac{d}{dt} \\frac{\\partial L}{\\partial \\dot{\\theta}} - \\frac{\\partial L}{\\partial \\theta} = 0\n\\end{equation}\n\n\\textit{Fill in derivation later\\dots} \\\\\n\nSolving for $\\ddot{\\theta}$,\n\\begin{equation}\n  \\ddot{\\theta} = \\frac{\\dot{\\varphi}^2 \\sin\\theta \\cos\\theta(I_1 - I_3) - I_3 \\dot{\\varphi} \\dot{\\psi} \\sin\\theta + mgl \\sin\\theta}{I_1}\n\\end{equation}\n\n\\textit{Fill in derivation later\\dots} \\\\\n\nSolving for $\\ddot{\\varphi}$,\n\\begin{equation}\n  \\ddot{\\varphi} = \\frac{2(I_3 - I_1) \\dot{\\varphi} \\dot\\theta \\sin\\theta \\cos\\theta - I_3 \\dot{\\varphi} \\dot{\\theta} \\sin\\theta \\cos\\theta + I_3 \\dot{\\psi} \\dot\\theta \\sin\\theta}{I_1 \\sin^2\\theta}\n\\end{equation}\n\n\\textit{Fill in derivation later\\dots} \\\\\n\nSolving for $\\ddot{\\psi}$,\n\\begin{equation}\n  \\ddot{\\psi} = \\frac{\\cos\\theta \\left[ \\frac{(I_1 \\sin^2\\theta + I_3 \\cos^2\\theta) \\dot{\\varphi} \\dot{\\theta} \\sin\\theta}{\\cos\\theta} - 2(I_3 - I_1) \\dot{\\varphi} \\dot{\\theta} \\sin\\theta \\cos\\theta - I_3 \\dot{\\psi} \\dot{\\theta} \\sin\\theta \\right]}{I_1 \\sin^2\\theta}\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "ebaf7683cff5b003e261b6686d7f04abbdf177f0", "size": 5368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/eqns_of_motion.tex", "max_stars_repo_name": "pauljxtan/odeint", "max_stars_repo_head_hexsha": "64afc85b6c1a1a6ef9eecac92bd76568df9a10eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-02-14T19:48:19.000Z", "max_stars_repo_stars_event_max_datetime": "2015-02-14T19:48:19.000Z", "max_issues_repo_path": "docs/eqns_of_motion.tex", "max_issues_repo_name": "pauljxtan/odeint", "max_issues_repo_head_hexsha": "64afc85b6c1a1a6ef9eecac92bd76568df9a10eb", "max_issues_repo_licenses": ["MIT"], "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/eqns_of_motion.tex", "max_forks_repo_name": "pauljxtan/odeint", "max_forks_repo_head_hexsha": "64afc85b6c1a1a6ef9eecac92bd76568df9a10eb", "max_forks_repo_licenses": ["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.1910828025, "max_line_length": 266, "alphanum_fraction": 0.5584947839, "num_tokens": 1995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619979547273, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.6828550172971528}}
{"text": "\\documentclass[12pt]{article}\n    \\usepackage{mathtools}\n    \\usepackage[hidelinks]{hyperref}\n    \\usepackage{color}\n    \\usepackage{fancyref}\n    \\usepackage{lastpage}\n    \\usepackage{fancyhdr}\n\n    \\pagestyle{fancy}\n    \\fancyhf{}\n    \\fancyhead[LO]{TMA4140: Homework Set 3}\n    \\fancyhead[RO]{Henry S. Sjøen}\n    \\fancyfoot[CO]{\\thepage\\ of \\pageref{LastPage}}\n\n    \\definecolor{darkred}{RGB}{200, 0, 0}\n\n  \\author{Henry S. Sjøen}\n  \\title{\n  \\textbf{TMA4140 - Homework Set 3}\\\\\n  Basic structures: Sets, Functions, Sequences and Sums\\\\\n    \\color{darkred}{\\textbf{RETTES}}\n  }\n\\begin{document}\n    \\maketitle\n    \\thispagestyle{empty}\n    \\tableofcontents\n\n    \\pagebreak\n    \\section{Chapter 2.6 Matrices}\n    \\subsection{Exercise 27c}\n    Let\n    $ A =\n        \\begin{bmatrix}\n          1 & 0 & 1 \\\\\n          1 & 1 & 0 \\\\\n          0 & 0 & 1\n        \\end{bmatrix}\n    $\n    and\n    $\n    B =\n        \\begin{bmatrix}\n            0&1&1\\\\\n            1&0&1\\\\\n            1&0&1\n        \\end{bmatrix}\n    $. Find $A \\odot B$.\n\n\n    \\begin{equation}\n        \\begin{split}\n            A \\odot B =&\n            \\begin{bmatrix}\n                1 & 0 & 1 \\\\\n                1 & 1 & 0 \\\\\n                0 & 0 & 1\n            \\end{bmatrix}\n                \\odot\n            \\begin{bmatrix}\n                0 & 1 & 1\\\\\n                1 & 0 & 1\\\\\n                1 & 0 & 1\n            \\end{bmatrix}\\\\\n            =&\n            \\begin{bmatrix}\n                (1\\wedge 0) \\vee (0\\wedge1) \\vee (1\\wedge1) & (1\\wedge1) \\vee (0\\wedge0) \\vee (1\\wedge0) & (1\\wedge1) \\vee (0\\wedge1) \\vee (1\\wedge1) \\\\\n                (1\\wedge0) \\vee (1\\wedge1) \\vee (0\\wedge1) & (1\\wedge1) \\vee (1\\wedge0) \\vee (0\\wedge0) & (1\\wedge1) \\vee (1\\wedge1) \\vee (0\\wedge1) \\\\\n                (0\\wedge0) \\vee (0\\wedge1) \\vee (1\\wedge1) & (0\\wedge1) \\vee (0\\wedge0) \\vee (1\\wedge0) & (0\\wedge1) \\vee (0\\wedge1) \\vee (1\\wedge1)\n            \\end{bmatrix}\\\\\n            =&\n            \\begin{bmatrix}\n                0\\vee0\\vee1&1\\vee0\\vee0&1\\vee0\\vee1\\\\\n                0\\vee1\\vee0&1\\vee0\\vee0&1\\vee1\\vee0\\\\\n                0\\vee0\\vee1&0\\vee0\\vee0&0\\vee0\\vee1\n            \\end{bmatrix}\\\\\n            =&\n            \\begin{bmatrix}\n                1&1&1\\\\\n                1&1&1\\\\\n                1&0&1\n            \\end{bmatrix}\n        \\end{split}\n    \\end{equation}\n\n    \\pagebreak\n    \\section{Chapter 3.1 Algorithms}\n    \\subsection{Exercise 53}\n    Use the greedy algorithm to make change using quarters (25), dimes (10), nickels (5), and pennies (1) for\\label{e:53}:\\\\\n    \\textbf{a)} 51 cents = 2 quarters (25) + 1 penny (1) $\\Rightarrow$ 3 coins\\\\\n    \\textbf{b)} 69 cents = 2 quarters (25) + 1 dime (10) + 1 nickel (5) + 4 pennies (1) $\\Rightarrow$ 8 coins\\\\\n    \\textbf{c)} 76 cents = 3 quarters (25) + 1 penny (1) $\\Rightarrow$ 4 coins\\\\\n    \\textbf{d)} 60 cents = 2 quarters (25) + 1 dime (10) $\\Rightarrow$ 3 coins\n\n    \\subsection{Exercise 55 }\n    Use the greedy algorithm to make change using quarters, dimes, and pennies (but no nickels) for each of the amounts given in Exercise 53. For which of these amounts does the greedy algoritm use the fewest coins of these denominations possible?\\label{e:55}\\\\\n    \\textbf{a)} 51 cents $\\Rightarrow$ 2 quarters (25) + 1 penny (1) $\\Rightarrow$ 3 coins\\\\\n     Exercise 53 and 55 provides the same answer.\\\\\n    \\textbf{b)} 69 cents = 2 quarters (25) + 1 dimes (10) + 9 pennies (1) $\\Rightarrow$ 12 coins\\\\\n    Exercise 53 uses the fewest amount of coins of the two.\\\\\n    \\textbf{c)} 76 cents = 3 quarters (25) + 1 penny (1) $\\Rightarrow$ 4 coins\\\\\n    Exercise 53 and 55 provides the same answer.\\\\\n    \\textbf{d)} 60 cents = 2 quarters (25) + 1 dime (10) $\\Rightarrow$ 3 coins\\\\\n    Exercise 53 and 55 provides the same answer.\n\n    \\subsection{Exercise 56}\n    Show that if there were a coin worth 12 cents, the greedy algoritm using quarters, 12-cent coins, dimes, nickels, and pennies would not always produce change using the fewest coins possible.\n\n    If we wanted change for 15 cents then the greedy algorithm would give us\n    1 (12) + 3 pennies (1) = 15 cents $\\Rightarrow$ 4 coins.\n    But a more fitting change would be 1 dime + 1 nickel $\\Rightarrow$ 2 coins.\n\n    % Another example\n    % 21=> 12 + 5 + 1 + 1 + 1 + 1\n    % 21=> 10 + 10 + 1\n\n    \\pagebreak\n    \\section{Chapter 3.2 The Growth of Functions}\n    \\subsection{Exercise 27a, 27b}\n    Give a big-$O$ estimate for each of these functions. For the function $g$ in your estimate that $f(x)$ is $O(g(x))$, use a simple function $g$ of the smallest order.\\\\\n    a)$n log(n^2+1)+n^2 log n = O(n^2logn)$\\\\\n    b)$(n log n + 1)^2+(log n+1)(n^2+1)=O(n^2(logn)^2)$\n\n    \\subsection{Exercise 30c, 30e}\n    Show that each of these pairs of functions are of the same order.\\\\\n    c)$\\lfloor x + 1/2 \\rfloor,x$\\\\\n    Let $f(x) = \\lfloor x + 1/2 \\rfloor$ and $g(x)=x$.\n    $x<2 \\lfloor x+1/2\\rfloor$ and for $x>2$: $| \\lfloor x +1/2 \\rfloor | > \\frac{1}{2}\\cdot|x|$\\\\\n    That means $\\lfloor x+1/2 \\rfloor$ is $\\Omega(x)$.\\\\\n    $\\lfloor x + 1/2 \\rfloor <2x for x>2$ it follows that $|\\lfloor x+1/2 \\rfloor| <2 cdot |x|$\\\\\n    Thus, $\\lfloor x+1/2 \\rfloor$ is $O(x)$.\\\\\n    And we conclude that $\\lfloor x+1/2 \\rfloor$ and $x$ are of the same order.\\\\\n    e)$log_{10}x,log_{2}x$\\\\\n    Let $f(x)=log_{10}x$ and $g(x)=log_2x$.\n    \\begin{equation}\n        \\begin{split}\n            f(x)&=log_{10}x\\\\\n                &=\\frac{log x}{log 10}\\\\\n                &=\\frac{log 2}{log 2}\\frac{log x }{log 10}\\\\\n                &=\\frac{log 2}{log 10}\\frac{log x}{log 2}\\\\\n                &=\\frac{1}{log_{2}10}log_{2}x\n        \\end{split}\n    \\end{equation}\n    Thus $|log_{10}x| \\leq \\frac{1}{log_{2}10}x|$ and it follows that $log_{10}x$ is $O(log_2 x)$\n\n    \\subsection{Exercise 34}\n    Show that $3x^2+x+1$ is $\\theta (3x^2)$ by directly finding the constants $k, C_1$ and $C_2$ in Exercise 33.\n\n    \\textbf{Exercise 33:}\n    Show that if $f(x)$ and $g(x)$ are functions from the set of real numbers to the set of real numbers, then $f(x)$ is $\\theta (g(x))$ if and only if there are positive constants $k, C_1$ and $C_2$ such that $C_1|g(x) \\leq |f(x)| \\leq C_2|g(x)|$ whenever $x > k$.\n\n    \\begin{equation}\n        3x^2+x+1 = \\theta (3x^2)\n    \\end{equation}\n\n    \\subsection{Exercise 42}\n    Suppose that $f(x)$ is $O(g(x))$. Does it follow that $2^{f(x)}$ is $O(2^{g(x)})$?\\\\\n    No it does not. For example $f(x)=2x$ and $g(x)=x$.\n    Then $f(x)$ is $O(g(x))$. But $2f(x)$ is not $O(2^{g(x)})$.\n\n    \\pagebreak\n    \\section{Chapter 4.1 Divisibility and Modular Arithmetic}\n    \\subsection{Exercise 11}\n    \\textbf{What time does a 12-hour clock read:}\\\\\n    \\textbf{a)} 80 hours after it reads 11:00?\\\\\n    \\emph{Answer:} 7:00\\\\\n    \\textbf{b)} 40 hours before it reads 12:00?\\\\\n    \\emph{Answer:} 8:00\\\\\n    \\textbf{c)} 100 hours after it reads 6:00?\\\\\n    \\emph{Answer:} 10:00\n\\end{document}\n", "meta": {"hexsha": "dcc9b3d9eaa2071e8df77d6839714f2074b339c1", "size": 6871, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "O3/o3.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": "O3/o3.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": "O3/o3.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": 40.1812865497, "max_line_length": 265, "alphanum_fraction": 0.5625090962, "num_tokens": 2606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410784, "lm_q2_score": 0.8376199633332893, "lm_q1q2_score": 0.6828550115992701}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{pylatex}\n\\usepackage{mmalatex}\n\\usepackage{geometry}\n\\usepackage{amsmath}\n\\usepackage{pgf}\n\\usepackage{caption}\n\\usepackage{hyperref}\n\\usepackage{examples}\n\n% portrait\n\\geometry{papersize={210mm,297mm},hmargin=2cm,tmargin=1.0cm,bmargin=1.5cm}\n\\parskip=8pt plus 4pt minus 2pt\n\n% landscape\n% \\geometry{papersize={297mm,210mm},hmargin=2cm,tmargin=1.0cm,bmargin=1.5cm}\n% \\parskip=6pt plus 3pt minus 2pt\n\n\\begin{document}\n\n\\section*{A mixed Mathematica-Python example}\n\nThis example demonstrates a cooperative effort where Mathematica is used to do the analytic computations while Python is used to plot the data.\n\nThe example chosen here is to find and plot the solution to the boundary value problem defined by\n\\begin{align*}\n   \\frac{d^2y}{dx^2} + 2 \\frac{dy}{dx} + 10 y = 0\\quad\\quad\\text{with }y(0)=3,\\> y'(0)=0\n\\end{align*}\n\nThis example requires two passes, once for Mathematica and once for Python (and in that order). This example can be run using\n\n\\vspace{5pt}\n\n\\begin{lstlisting}\n   mmalatex.sh -x -i mixed\n   pylatex.sh  -x -i mixed\n   pdflatex          mixed\n\\end{lstlisting}\n\n\\vspace{5pt}\n\nNote that the last pair of commands could also be combined as {\\small\\tt pylatex.sh -i mixed}.\n\n\\subsection*{The Mathematica code}\n\nHere Mathematica is used to first find the general solution of th differential equation.\nThe boundary conitions are then imposed and finally a uniform sampling of the solution\nis written to a file for later use by Python and Matplotlib.\n\n\\vspace{10pt}\n\n\\begin{mathematica}\n   sol = DSolve[y''[x] + 2 y'[x] + 10 y[x] == 0, y, x]\n   ans = y[x]/.sol[[1]]                  (* mma(ans.101,ans)*)\n\n   sol = DSolve[{y''[x] + 2 y'[x] + 10 y[x] == 0, y[0]==3, y'[0]==0}, y, x]\n   foo = y[x]/.sol[[1]]                  (* mma(ans.102,foo)*)\n   bah = Simplify[y'[x]/.sol[[1]]]       (* mma(ans.103,bah)*)\n\n   (* now sample y and dy at selected points *)\n   myData = Table[{x, foo, bah}, {x, 0, 2 Pi, 0.02}];\n   Export[\"mixed.txt\", myData, \"Table\",  \"FieldSeparators\" -> \" \"];\n\\end{mathematica}\n\n\\vspace{10pt}\n\nThe general solution of the differential equation is\n\\begin{equation*}\n  y(x) = \\mma{ans.101}\n\\end{equation*}\nwhile the particular solution satifying the boundary conditions is given by\n\\vspace{5pt}\n\\begin{align*}\n    y(x) &= \\mma{ans.102}\n\\end{align*}\n\n\\clearpage\n\n\\subsection*{The Python code}\n\nThis is a straighforward use of Matplotlib to plot two functions. The code reads the datafile created previously by Mathematica and then calls Matplotlib to plot that data.\n\n\\begin{python}\n   import numpy as np\n   import matplotlib.pyplot as plt\n\n   plt.matplotlib.rc('text', usetex = True)\n   plt.matplotlib.rc('grid', linestyle = 'dotted')\n   plt.matplotlib.rc('figure', figsize = (5.5,4.1)) # (width,height) inches\n\n   x, y, dy = np.loadtxt ('mixed.txt', unpack=True)\n\n   plt.plot (x,y)\n   plt.plot (x,dy)\n\n   plt.xlim (0.0,4.0)\n\n   plt.legend(('$y(x)$', '$dy(x)/dx$'), loc = 0)\n   plt.xlabel('$x$')\n   plt.ylabel('$y(x),\\> dy/dx$')\n   plt.grid(True)\n   plt.tight_layout(0.5)\n\n   plt.savefig('mixed-fig.pdf')\n\\end{python}\n\n\\vspace{10pt}\n\n\\begin{minipage}{\\textwidth}\n   \\centering\n   \\IfFileExists{mixed-fig.pdf}%\n   {\\includegraphics[width=0.75\\textwidth]{mixed-fig.pdf}}{Failed to create pdf plot.}\n   \\captionof{figure}{The function and its derivative.}\n\\end{minipage}\n\n\\end{document}\n", "meta": {"hexsha": "a7c97fae5b42df89acd0d6ae0ff8dae59b26ceaa", "size": 3360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematica/examples/mixed.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "mathematica/examples/mixed.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mathematica/examples/mixed.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.7179487179, "max_line_length": 172, "alphanum_fraction": 0.681547619, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410783, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.6828550082947281}}
{"text": "% $Id$\n%\n% Author: David Fournier\n% Copyright (c) 2008 Regents of the University of California\n%\n\nLet $y_i$ be an $N$-dimensional multivariate time series for\n$i=1,\\ldots,n$, where $y_i$ is a random vector with probability\ndensity function $p(y_i | \\alpha_i)$.  For each $i$,\nthe $\\alpha_i$ are random vectors that satisfy the condition\n\\begin{equation}\n  \\alpha_i=T_i(\\alpha_{i-1},y_{i-1})+\\eta_i\n\\end{equation}\nwhere $\\mu_{\\eta_i}=0$ and $\\sigma^2_{\\eta_i}=\\sigma^2_\\eta$.\n\nLet $p(\\alpha_1)$ be the probability density function for \n$\\alpha_1$ before $y_1$ is observed. After observing \n$y_1$, we want to calculate the probability distribution of $\\alpha_1$\ngiven $y_1$. This is given by\n\\begin{equation}\n  p(\\alpha_1 | y_1)=p(y_1|\\alpha_1)\\,p(\\alpha_1)\\big/p(y_1)\n\\end{equation}\nwhere\n\\begin{equation}\\label{eq:xx6}\n  p(y_1)=\\int_{-\\infty}^\\infty p(y_1|\\alpha_1)\\, p(\\alpha_1) \\,\\,\\textrm{d}\\alpha_1\n\\end{equation}\nLet $\\phi(y_1,\\alpha_1)=\\log(p(y_1|\\alpha_1)p(\\alpha_1))$ and\n$\\hat\\alpha_1(y_1)=\\max_{\\alpha_1} \\{\\phi(y_1,\\alpha_1)\\}$.\nApproximate $\\phi$ by its second-order Taylor expansion in\n$\\alpha_1$ at $\\hat\\alpha_1$.\n\\begin{equation}\n  \\phi(y_1,\\alpha_1)\\approx \\phi(y_1,\\hat\\alpha_1) \n  + D^2_{\\alpha_1\\alpha_1}\\phi \\big(y_1,\\hat\\alpha_1(y_1)\\big) \\big(\\alpha_1-\\hat\\alpha_1(y),\n  \\alpha_1-\\hat\\alpha_1(y) \\big)\n\\end{equation}\nso that \n\\begin{equation}\\label{eq:xx5}\n  p(y)\\approx e^{\\phi(y_1,\\hat\\alpha_1(y_1))} \\kern-.5em \n  \\int_{-\\infty}^\\infty \\kern-.25em \\exp\\bigg\\{- \n  \\Big(-D^2_{\\alpha_1\\alpha_1}\\phi \n      \\big(y_1,\\hat\\alpha_1(y_1) \\big)\\,\n      \\big (\\alpha_1-\\hat\\alpha_1(y),  \\alpha_1-\\hat\\alpha_1(y) \\big) \\,\n   \\Big) \\bigg\\}\\,\\textrm{d}\\alpha_1\n\\end{equation}\nMaking a change of variables and integrating, we obtain\n\\begin{equation}\\label{eq:xx4}\n  p(y_1)\\approx e^{\\phi (y_1,\\hat\\alpha_1(y_1) )}  (2\\pi)^{n/2} \n  \\Big | -D^2_{\\alpha_1\\alpha_1} \\phi \\big(y_1,\\hat\\alpha_1(y_1) \\big) \\Big |^{-1/2}\n\\end{equation}\n\\X{Laplace approximation}\n\\XX{Laplace approximation}{in Kalman filter}\n\\X{robust Kalman filter}\nThis is the Laplace approximation to the integral in equation~(\\ref{eq:xx6}).\n\nIf the distribution of $\\alpha_1$ is (multivariate) normal and\nthe distribution of $y_1|\\alpha_1$ is multivariate normal,\nthen $\\phi(y_1,\\alpha_1)$ is a quadratic function of $\\alpha_1$, so\nthe Laplace approximation is exact. The advantage of the\nLaplace approximation is that it can be employed for non-normal distributions.\n\nTo illustrate this advantage, consider the simple 1-dimensional case where\n$\\alpha_1$ has a (univariate) normal distribution with mean~0 and\nvariance~$\\sigma_\\alpha^2$.\nAssume that the distribution of $y_1|\\alpha_1$ is a fat-tailed\ndistribution, which is a mixture of $0.95$  normal distribution and $0.05$ Cauchy\ndistribution. Then,\n\\begin{align}\n\\nonumber \\phi(y_1,\\alpha_1)=& \\log \\bigg[ 0.95\\exp \\Big(\\kern-.1em -0.5 (y_1-\\alpha_1)^2  \\Big/  \\sigma_y^2 \\Big)\n     + 0.05\\sqrt{2/\\pi} \\Big/ \\Big(1+ (y-\\alpha_1)^2 \\big/ \\sigma_y^2 \\Big) \\bigg] \\\\\n   & -0.5\\alpha_1^2 \\big/ \\sigma_\\alpha^2 + \\textrm{const}\n   \\label{eq:xx9.7}\n\\end{align}\nwhereas if $y_1$ is assumed to have a normal distribution,\n\\begin{equation}\n  \\phi(y_1,\\alpha_1)=-0.5(y_1-\\alpha_1)^2 \\big/  \\sigma_y^2\n    -0.5\\alpha_1^2 \\big/ \\sigma_\\alpha^2\\ + \\textrm{const}\n    \\label{eq:xx9.8}\n\\end{equation}\nwhere ``$\\textrm{const}$'' denotes some constant independent of~$\\alpha_1$.\nThere are two drawbacks to the use of equation~(\\ref{eq:xx9.8}). %fixed $5.b$\nIf the value of $y_1$ is an outlier from the point of the normal\nmodel, then it will have too much influence on the mode of the estimate of\n$p(\\alpha_1 | y_1)$.  Also, since the variance %xx added a { to middle term:\n\\begin{equation}\n  \\sigma_{\\alpha_1|y_1}^2=\\big\\{D^2_{\\alpha_1\\alpha_1}\\phi(y_1,\\beta_i)\\big\\}^{-1}=\\Big[1/\\sigma_y^2 + 1/\\sigma_\\alpha^2\\Big]^{-1}\n\\end{equation}\nis independent of the value of $y_1$ observed, \n$\\sigma_{\\alpha_1|y_1}^2$ will be underestimated.  This is incorrect behavior,\nsince if $y_1$ is an outlier, it contains (almost) no information\nabout the value of $p(\\alpha_1|y_1)$.  So, \n$p(\\alpha_1|y_1)$ should be almost equal to~$p(\\alpha_1)$.\nThe likelihood function based on equation~(\\ref{eq:xx9.7}) %fixed $5a$\nhas the desired behavior.\n\nTo calculate expression~(\\ref{eq:xx4}), it is necessary to maximize $\\phi(y_1,\\alpha_1)$ with respect to $\\alpha_1$,\nand to calculate its Hessian matrix with respect to $\\alpha_1$.\n\nFor the maximization, we employ the Newton-Raphson algorithm. \nLet $\\beta_0=\\mu_{\\alpha_1}$\n\\begin{equation}\n \\beta_{i+1}=\\beta_i-\\big\\{D^2_{\\alpha_1\\alpha_1}\\phi(y_1,\\beta_i)\\big\\}^{-1}\n  \\big(D_{\\alpha_1}\\phi(y_1,\\beta_i) \\big)\n\\end{equation}\nThis operation is carried out a fixed number, $r$, times and then\n$\\hat\\alpha_1(y_1)\\approx\\beta_r$.\nFor ``well behaved'' problems, the sequence $\\beta_i$ converges\nquadratically to $\\hat\\alpha_1(y_1)$.\nWe approximate $p(\\alpha_1|y_1)$ by a multivariate normal with\n\\begin{align*}\n  \\mu_{\\alpha_1|y_1}&=\\beta_r\\\\[6pt]\n  \\sigma^2_{\\alpha_1|y_1}&=\n  \\big\\{-D^2_{\\alpha_1\\alpha_1}\\phi(y_1,\\beta_r)\\big\\}^{-1}\\\\\n\\end{align*}\nand approximate $p(\\alpha_2|y_1)$ by a multivariate normal with\n\\begin{align*}\n  \\mu_{\\alpha_2|y_1}&=T(\\beta_r,y_1)\\cr \n  \\sigma^2_{\\alpha_2|y_1}&= \n  D_{\\alpha_1}\\, T_1(\\beta_r,y_1)\\sigma^2_{\\alpha_1|y_1}\n  D_{\\alpha_1}\\, T_1(\\beta_r,y_1) ^{\\prime}+\n  \\sigma^2_\\eta\\cr\n\\end{align*}\nNow,\n\\begin{equation}\\label{eq:xx3}\n  p(y_2|y_1)=\\int_{-\\infty}^\\infty p(y_2|\\alpha_2)\\, p(\\alpha_2|y_1)\n  \\,\\textrm{d}\\alpha_2\n\\end{equation}\nAs above, we maximize the integrand of equation~(\\ref{eq:xx3}) with respect to\n$\\alpha_2$ and use the Laplace approximation to the integral.\nThis produces the sequence of conditional probabilities $p(y_i|y_{i-1})$.\nThe log-likelihood function for the observed sequence ${y_i}$\nis given by \n\\begin{equation}\n  \\sum_{i=1}^n \\log\\Big(p(y_i|y_{i-1})\\Big)\n\\end{equation}\n\n\n\\section{Parameter estimation}\n\nAlthough we have not explicitly shown them, the conditional likelihood\nfunctions $p(y_i|y_{i-1})$  depend on a number of \nparameters. These parameters include the specification of $T$, other\nparameters in the probability density $p(y_i|\\alpha_i)$, and parameters\nthat determine $\\sigma^2_\\eta$. If we denote these parameters by\n$\\theta$ and write $\\big(p(y_i|y_{i-1},\\theta)\\big)$ to indicate this\ndependence, the log-likelihood function becomes\n\\begin{equation}\\label{eq:xx1}\n  \\sum_{i=1}^n \\log\\Big(p(y_i|y_{i-1},\\theta)\\Big)\n\\end{equation}\nThe maximum likelihood estimates for the parameter vector $\\theta$ are\nfound by maximizing expression~(\\ref{eq:xx1}) with respect to~$\\theta$.\n\n\n\\X{stochastic volatility model}\n\\section{The stochastic volatility model}\n\nThe version of the stochastic volatility model presented here is from\n\\cite{RePEc:eee:empfin:v:5:y:1998:i:2:p:155-173}.\n\nIt is assumed that $y_i$ has a multivariate normal distribution with\n$\\mu_{y_i}=0$ and covariance matrix \n$\\Omega_i(\\alpha_i)=H_i(\\alpha_i)RH_i(\\alpha_i)$.\n$H_i(\\alpha_i)$ is an $m\\times m$ diagonal matrix whose $j^\\textrm{th}$ element\non the diagonal is given by $\\exp(\\alpha_{ij})/2$, where the\n$\\alpha_{ij}$ satisfy the relationship\n\\begin{equation}\n  \\alpha_i=w+\\ep(\\delta,\\alpha_{i-1}) +\\ep(\\lambda_1,y_{i-1}) \n   + \\ep(\\lambda_2,|y_{i-1}|) + \\eta_i\n\\end{equation}\nwhere, in turn, $\\eta_i$ is a multivariate normal random variable with\n$\\mu_{\\eta_i}=0$ and $\\sigma^2_{\\eta_i}=\\sigma^2_\\eta$.\nIf $u$ and $v$ are two vectors with $j^\\textrm{th}$ component $u_j$ and $v_j$,\n$\\ep(i,v)$ is the vector with $j^\\textrm{th}$ component $u_jv_j$.\n$R$ is an  $m\\times m$ positive definite matrix satisfying $r_{jj}=1$,\nthat is, a correlation matrix.\nThen,\n\\begin{equation}\n  \\log\\big(p(y_i | \\alpha_i)\\big)=\n     -0.5\\log|\\Omega_i(\\alpha_i)|-0.5y^\\prime_i\\,\\,\\Omega_i(\\alpha_i)^{-1}y_i\n\\end{equation}\nand the distribution of $\\alpha_i|y_{i-1}$ is multivariate normal, with\nmean vector and covariance matrix given by\n\\begin{align}\n  \\mu_{\\alpha_i|y_{i-1}}&=w+\\ep(\\delta,\\mu_{\\alpha_{i-1}|y_{i-1}})\n     +\\ep(\\lambda,y_{i-1})\\\\[4pt]\n  \\sigma^2_{\\alpha_i|y_{i-1}}&=i\\,\\diag(\\delta)\n   \\sigma^2_{\\alpha_{i-1}|y_{i-1}}\\diag(\\delta) \n  +\\sigma^2_\\eta \n\\end{align}\n$\\diag(\\delta)$ is the diagonal matrix whose diagonal is equal to the vector\n$\\delta$. \n\\begin{align} \\label{eq:xx2}\n  \\log\\big(p(y_i|\\alpha_i)\\,p(\\alpha_i|y_{i-1})\\big)&=\n     -0.5\\log|\\Omega_i(\\alpha_i)|-0.5y_i^\\prime\\Omega_i(\\alpha_i)^{-1}y_i\n     -0.5\\log|\\sigma^2_{\\alpha_i|y_{i-1}}|\\\\[6pt]\n     &\\quad   -0.5(\\alpha_i-\\mu_{\\alpha_i|y_{i-1}})^\\prime\n          (\\sigma^2_{\\alpha_i|y_{i-1}})^{-1}\n             (\\alpha_i-\\mu_{\\alpha_i|y_{i-1}}) \n\\end{align}\nTo perform the Newton-Raphson calculations, it is necessary to calculate\nthe first and second derivatives of expression~(\\ref{eq:xx2}) with respect\nto the parameter vector~$\\alpha$. This is the most involved part of the\ncalculations and will depend on the particular form of the model. In the present\ncase, the calculations are simplified by the fact that $\\Omega_i$ only depends on\n$\\alpha$ through the diagonal matrix $H(\\alpha_i)$.\n\nThe probability density function $p(\\alpha_1)$ is \nassumed to be multivariate normal with $\\mu_{\\alpha_1}=\\theta_0$\nand $\\sigma^2_{\\alpha_1}=0$.\n\n\n\\section{The data}\n\nThe data consist of the daily Mark/Dollar and Yen/dollar exchange rates\nand the U.S. and Japanese stock index data. There are 1301\ntime periods, with some missing data. The missing data, which are denoted by the\nimpossibly large value of 10,000, were replaced with\nthe average from the period before and after. They can, however, easily\nbe estimated in the model, if desired.\n\n\n\\section{The results}\n\nThe model was fit with various combinations of the parameters,\nand the log-likelihood was examined to investigate the improvement in\nfit due to the addition of the parameters.  See Table~\\ref{tab:parameters}.\n\\begin{table}[htbp]\n\\begin{center}\n\\begin{tabular}{@{\\vrule height 16pt depth 6pt width0pt}@{\\extracolsep{1em}}c c c}\n\\\\\n\\hline \n\\bf Parameters in model & \\bf Number of parameters & \\bf Log-likelihood \\\\[3pt]\n\\hline \n%\\noalign{\\medskip}\n $w,\\delta,R,\\sigma^2_\\eta$ & 24 & 3774.7 \\\\\n $w,\\delta,R,\\sigma^2_\\eta,\\lambda_1$ & 28 & 3806.6 \\\\\n $w,\\delta,R,\\sigma^2_\\eta,\\lambda_1,\\theta_0$ & 32 & 3808.6 \\\\\n $w,\\delta,R,\\sigma^2_\\eta,\\lambda_1,\\theta_0,\\lambda_2$ & 36 & 3811.2 \\\\[6pt]\n\\hline\n\\\\\n\\end{tabular}\n\\end{center}\n\\emptycaption\n\\label{tab:parameters}\n\\end{table}\n\n\nThe parameters $\\theta_0$ and $\\lambda_2$ did not produce a significant\nimprovement to the fit.  $\\lambda_2$ measures the asymmetry \nin the response of the variance to positive and negative shocks.\n\nHere are the parameter estimates and their standard deviations for\nthe model with $w,\\delta,R,\\sigma^2_\\eta$, and $\\lambda_1$:\n\\begin{lstlisting}\n index   name    value      std.dev   \n    1   w(1)       -1.3749e-001 4.9434e-002\n    2   w(2)       -6.5649e-001 1.6161e-001\n    3   w(3)        3.1693e-002 1.0574e-002\n    4   w(4)       -1.2973e-002 1.5375e-002\n    5   lambda1(1)  1.5564e-001 4.9688e-002\n    6   lambda1(2)  1.8647e-001 6.9525e-002\n    7   lambda1(3)  -6.9265e-002 1.4158e-002\n    8   lambda1(4)  -1.6689e-001 3.1626e-002\n    9   delta(1)    8.2229e-001 4.6074e-002\n   10   delta(1)    5.0848e-001 1.0785e-001\n   11   delta(1)    9.5763e-001 1.4602e-002\n   12   delta(1)    9.3610e-001 1.8812e-002\n   29   R(1,1)      1.0000e+000 0.0000e+000\n   30   R(1,2)      5.3821e-001 2.2883e-002\n   31   R(1,3)      -7.1704e-002 2.9477e-002\n   32   R(1,4)      -3.8796e-002 2.9278e-002\n   33   R(2,1)      5.3821e-001 2.2883e-002\n   34   R(2,2)      1.0000e+000  0.0000e+000\n   35   R(2,3)      -1.2932e-001 2.9111e-002\n   36   R(2,3)      -4.1466e-002 2.9468e-002\n   37   R(3,1)      -7.1704e-002 2.9477e-002\n   38   R(3,2)      -1.2932e-001 2.9111e-002\n   39   R(3,3)      1.0000e+000  0.0000e+000\n   40   R(1,4)      8.8811e-002 2.9085e-002\n   41   R(4,1)      -3.8796e-002 2.9278e-002\n   42   R(4,2)      -4.1466e-002 2.9468e-002\n   43   R(4,3)      8.8811e-002 2.9085e-002\n   44   R(4,4)      1.0000e+000  0.0000e+000\n   45   Omega(1,1)  6.5973e-001 6.3099e-002\n   46   Omega(1,2)  1.9827e-001 1.6129e-002\n   47   Omega(1,3)  -1.3395e-001 5.4982e-002\n   48   Omega(1,4)  -3.5161e-002 2.6676e-002\n   49   Omega(2,1)  1.9827e-001 1.6129e-002\n   50   Omega(2,2)  2.0570e-001 2.3994e-002\n   51   Omega(2,3)  -1.3489e-001 3.2608e-002\n   52   Omega(2,4)  -2.0985e-002 1.5016e-002\n   53   Omega(3,1)  -1.3395e-001 5.4982e-002\n   54   Omega(3,2)  -1.3489e-001 3.2608e-002\n   55   Omega(3,3)  5.2895e+000 5.7872e-001\n   56   Omega(3,4)  2.2791e-001 7.9318e-002\n   57   Omega(4,1)  -3.5161e-002 2.6676e-002\n   58   Omega(4,2)  -2.0985e-002 1.5016e-002\n   59   Omega(4,3)  2.2791e-001 7.9318e-002\n   60   Omega(4,4)  1.2451e+000 1.7043e-001\n   61   Z(1,1)      2.3967e-001 7.4268e-002\n   62   Z(1,2)      2.0711e-001 5.5599e-002\n   63   Z(1,3)      3.8832e-002 1.8505e-002\n   64   Z(1,4)      2.4097e-002 2.0344e-002\n   65   Z(2,1)      2.0711e-001 5.5599e-002\n   66   Z(2,2)      4.6309e-001 1.1143e-001\n   67   Z(2,3)      3.4298e-002 2.3017e-002\n   68   Z(2,4)      9.6831e-003 2.9999e-002\n   69   Z(3,1)      3.8832e-002 1.8505e-002\n   70   Z(3,2)      3.4298e-002 2.3017e-002\n   71   Z(3,3)      3.9101e-002 1.6885e-002\n   72   Z(3,4)      2.4602e-002 1.1053e-002\n   73   Z(4,1)      2.4097e-002 2.0344e-002\n   74   Z(4,2)      9.6831e-003 2.9999e-002\n   75   Z(4,3)      2.4602e-002 1.1053e-002\n   76   Z(4,4)      9.6109e-002 3.4268e-002\n\\end{lstlisting}\n\nThe AD Model Builder \\textsc{tpl} file for the model is given below:\n\\begin{lstlisting}\nDATA_SECTION\n  init_int ndim\n  init_int nobs\n  int ndim1\n  int ndim2\n !! ndim1=ndim*(ndim+1)/2;\n !! ndim2=ndim*(ndim-1)/2;\n  init_matrix Y(1,nobs,1,ndim)\n LOC_CALCS\n  // replace missing values (10000) with the average of before and after.\n  for (int i=2;i<nobs;i++)\n    for (int j=1;j<=ndim;j++)\n      if (Y(i,j)==10000)\n      {\n        int i2=i+1;\n        do\n        {\n          if (Y(i2,j)==10000) \n            i2++;\n          else\n            break; \n        } \n        while(1);\n        Y(i,j)=(Y(i-1,j)+Y(i2,j))/2.;\n        if (Y(i,j)>100.0)     // did this work\n          cerr << \" Y(i,j) too big \" << Y(i,j) << endl; \n      }      \n END_CALCS\n \nPARAMETER_SECTION\n  matrix h_mean(1,nobs,1,ndim)\n  3darray h_var(1,nobs,1,ndim,1,ndim)\n  number ldR;\n  init_vector theta0(1,ndim,3);\n  vector lmin(1,nobs)\n  init_bounded_vector w(1,ndim,-10,10)\n  vector w1(1,ndim)\n  init_vector lambda(1,ndim,2)\n  init_vector lambda2(1,ndim,-1)\n  init_bounded_vector delta(1,ndim,0,.98)\n  sdreport_matrix R(1,ndim,1,ndim)\n  sdreport_matrix Omega(1,ndim,1,ndim)\n  matrix ch_R(1,ndim,1,ndim)\n  matrix Rinv(1,ndim,1,ndim)\n  init_bounded_vector v_R(1,ndim2,-1.0,1.0)\n  sdreport_matrix Z(1,ndim,1,ndim)\n  matrix ch_Z(1,ndim,1,ndim)\n  init_bounded_vector v_Z(1,ndim1,-1.0,1.0)\n  matrix S(1,ndim,1,ndim);\n  objective_function_value f\nINITIALIZATION_SECTION\n  delta 0.9\nPROCEDURE_SECTION\n\n  fill_the_matrices();\n  int sgn;\n  ldR=ln_det(R,sgn);\n  Rinv=inv(R);\n  dvar_vector tmp(1,ndim);\n  dvar_matrix sh(1,ndim,1,ndim);\n  h_mean(1)=theta0;\n  h_var(1)=0; \n  for (int i=2;i<=nobs;i++)\n  {\n    dvar_vector tmean=update_the_means(w,h_mean(i-1),Y(i-1));\n    dvar_matrix v=update_the_variances(h_var(i-1));\n    tmp=tmean;\n    dvar_vector h(1,ndim);\n    dvar_vector gr(1,ndim);\n    for (int ii=1;ii<=4;ii++)  // do the Newton-Raphson 4 times\n    {\n      xfp12(tmp, Y(i),tmean,v,gr,sh); // get 1st and 2nd derivatives\n      h=-solve(sh,gr);  //sh is hessian and gr is the gradient\n      tmp+=h;  // add new step h\n    }\n    double nh=norm2(value(h)); // check size of h for convergence\n    if (nh>1.e-1) \n      cout << \"No convergence in NR \" << nh << endl;\n    if (nh>1.e+02) \n    {\n      f+=1.e+7;   // this ensures that the function minimizer will take a\n      return;    // smaller step\n    }\n    h_mean(i)=tmp;\n    h_var(i)=inv(sh);\n    lmin(i)=fp(tmp,Y(i),tmean,v);\n    int sgn;\n    f+=lmin(i)+0.5*ln_det(sh,sgn);  // Laplace approximation\n  }\n  f-=0.5*nobs*ndim*log(2.*PI);\n  Omega=S;\n\nFUNCTION  dvar_vector update_the_means(dvar_vector& w,dvar_vector& m,dvector& e)\n  dvar_vector tmp= w+elem_prod(delta,m)+elem_prod(lambda,e);\n  if (active(lambda2))\n    tmp+=elem_prod(lambda2,fabs(e)); \n  return tmp;\n  \nFUNCTION  dvar_matrix update_the_variances(dvar_matrix& v)\n  dvar_matrix tmp(1,ndim,1,ndim);\n  for (int i=1;i<=ndim;i++)\n  {\n    for (int j=1;j<=i;j++)\n    {\n      tmp(i,j)=delta(i)*delta(j)*v(i,j);\n      if (i!=j) tmp(j,i)=tmp(i,j);\n    }\n  }\n  tmp+=Z;\n  return tmp;\n  \nFUNCTION dvariable fp(dvar_vector& h, dvector& y, dvar_vector& m,dvar_matrix& v)\n  dvar_vector eh=exp(.5*h);\n  for (int i=1;i<=ndim;i++)\n  {\n    for (int j=1;j<=i;j++)\n    {\n      S(i,j)= eh(i)*eh(j)*R(i,j);\n      if (i!=j) S(j,i)=S(i,j);\n    }\n  }   \n\n  dvariable lndet;\n  dvariable sgn;\n  dvar_vector u=solve(S,y,lndet,sgn);\n  dvariable l;\n  l=.5*lndet+.5*(y*u);\n  dvar_vector hm=h-m;\n  w1=solve(v,hm,lndet,sgn);\n  l+=.5*lndet+.5*(w1*hm);\n  return l;\n\nFUNCTION void xfp12(dvar_vector& h, dvector& y,dvar_vector& m,dvar_matrix& v,\n dvar_vector gr,dvar_matrix& hess)\n  dvar_vector ehinv=exp(-.5*h);\n  dvariable lndet;\n  dvariable sgn;\n  dvar_vector ys=elem_prod(ehinv,y);\n  dvar_vector u=Rinv*ys;\n  gr=0.5;\n  dvar_vector vv=elem_prod(ys,u);\n  gr-=.5*vv;\n  dvar_vector hm=h-m;\n  dvar_vector w=solve(v,hm,lndet,sgn);\n  gr+=w;\n  for (int i=1;i<=ndim;i++)\n  {\n    for (int j=1;j<=i;j++)\n    {\n      hess(i,j)=0.25*ys(i)*ys(j)*Rinv(i,j);\n      if (i!=j) hess(j,i)=hess(i,j);\n    }\n  }\n  for (i=1;i<=ndim;i++)\n  {\n    hess(i,i)+=.25*vv(i);\n  }\n  hess+=inv(v);\n\nFUNCTION  fill_the_matrices\n  int ii=1;\n  ch_Z.initialize();\n  for (int i=1;i<=ndim;i++)\n  {\n    for (int j=1;j<=i;j++)\n      ch_Z(i,j)=v_Z(ii++);  \n    ch_Z(i,i)+=0.5;\n  }\n  Z=ch_Z*trans(ch_Z);\n  ch_R.initialize();\n  ii=1;\n  for (i=1;i<=ndim;i++)\n  {\n    for (int j=1;j<i;j++)\n      ch_R(i,j)=v_R(ii++);  \n    ch_R(i,i)+=0.1;\n    ch_R(i)/=norm(ch_R(i));\n  }\n  R=ch_R*trans(ch_R);\n\nREPORT_SECTION\n  report<<\"observed\"<<Y<<endl;\n  for (int i=1;i<=nobs;i++)\n  {\n    report<< \"mean\" <<endl;\n    report<< h_mean(i) <<endl;\n    report<< \"covariance\" <<endl;\n    report<<h_var(i)<<endl;\n    report<<endl;\n  }\n  report<< \"S(nobs) \" << endl;\n  report<< Omega << endl;\n  report<< \"Z \" << endl;\n  report<< Z << endl;\n  report<< \"R \" << endl;\n  report<< R << endl;\n\nTOP_OF_MAIN_SECTION\n  arrmblsize=20000000;\n  gradient_structure::set_CMPDIF_BUFFER_SIZE(25000000);\n  gradient_structure::set_GRADSTACK_BUFFER_SIZE(1000000);\n\\end{lstlisting}\n\n", "meta": {"hexsha": "00f74af28b4a63362992a2c590bf1df4e71a4044", "size": 18482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manuals/admb/kal_lap.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/kal_lap.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/kal_lap.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": 35.4061302682, "max_line_length": 130, "alphanum_fraction": 0.6522562493, "num_tokens": 7459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6828550059590573}}
{"text": "%================================\n\\section{Subspaces}\n%================================\n\n\n% Let B be a base for X and let Y be a subspace of X. Then if we intersect each element of B with Y, the resulting collection of sets is a base for the subspace Y.\n\n\n\n%--------------------------------\n\\begin{definition}\n\t[subspace topology]\n\t\\label{def: subspace topology}\n\tLet $(X, \\mathcal T)$ be a topological space and let $A \\subseteq X$. The \\textit{subspace topology} $\\mathcal T_A$ on $A$ is defined to be the family of the intersections of open sets in $(X, \\mathcal T)$ and $A$. That is,\n\t$$\n\t\\mathcal T_A = \\left\\{ U \\cap A : \\ U \\in \\mathcal T \\right\\}.\n\t$$\n\\end{definition}\n%--------------------------------", "meta": {"hexsha": "098f8d8f24a2d41fb1a274a408a9a013f8df927a", "size": 710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/subspaces.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/subspaces.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/subspaces.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.3684210526, "max_line_length": 224, "alphanum_fraction": 0.5591549296, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.6828550036233864}}
{"text": "%!TEX root = ceres-solver.tex\n\\chapter{Solving}\nEffective use of Ceres requires some familiarity with the basic components of a nonlinear least squares solver, so before we describe how to configure the solver, we will begin by taking a brief look at how some of the core optimization algorithms in Ceres work and the various linear solvers and preconditioners that power it.\n\n\\section{Trust Region Methods}\nLet $x \\in \\mathbb{R}^{n}$ be an $n$-dimensional vector of variables, and\n$ F(x) = \\left[f_1(x),   \\hdots,  f_{m}(x) \\right]^{\\top}$ be a $m$-dimensional function of $x$.  We are interested in solving the following optimization problem~\\footnote{At the level of the non-linear solver, the block and residual structure is not relevant, therefore our discussion here is in terms of an optimization problem defined over a state vector of size $n$.},\n\\begin{equation}\n        \\arg \\min_x \\frac{1}{2}\\|F(x)\\|^2\\ .\n        \\label{eq:nonlinsq}\n\\end{equation}\nHere, the Jacobian $J(x)$ of $F(x)$ is an $m\\times n$ matrix, where $J_{ij}(x) = \\partial_j f_i(x)$  and the gradient vector $g(x) = \\nabla  \\frac{1}{2}\\|F(x)\\|^2 = J(x)^\\top F(x)$. Since the efficient global optimization of~\\eqref{eq:nonlinsq} for general $F(x)$ is an intractable problem, we will have to settle for finding a local minimum.\n\nThe general strategy when solving non-linear optimization problems is to solve a sequence of approximations to the original problem~\\cite{nocedal2000numerical}. At each iteration, the approximation is solved to determine a correction $\\Delta x$ to the vector $x$. For non-linear least squares, an approximation can be constructed by using the linearization $F(x+\\Delta x) \\approx F(x) + J(x)\\Delta x$, which leads to the following linear least squares  problem:\n\\begin{equation}\n         \\min_{\\Delta x} \\frac{1}{2}\\|J(x)\\Delta x + F(x)\\|^2\n        \\label{eq:linearapprox}\n\\end{equation}\nUnfortunately, na\\\"ively solving a sequence of these problems and updating $x \\leftarrow x+ \\Delta x$ leads to an algorithm that may not converge.  To get a convergent algorithm, we need to control the size of the step $\\Delta x$. And this is where the idea of a trust-region comes in. The generic trust-region loop for non-linear least squares problems looks something like this\n\n\n\\begin{algorithmic}\n\\REQUIRE Initial point $x$ and a trust region radius $\\mu$.\n\\LOOP\n\\STATE{Solve $\\arg \\min_{\\Delta x} \\frac{1}{2}\\|J(x)\\Delta x + F(x)\\|^2$ s.t. $\\|D(x)\\Delta x\\|^2 \\le \\mu$}\n\\STATE{$\\rho = \\frac{\\displaystyle \\|F(x + \\Delta x)\\|^2 - \\|F(x)\\|^2}{\\displaystyle \\|J(x)\\Delta x + F(x)\\|^2 - \\|F(x)\\|^2}$}\n\\IF {$\\rho > \\epsilon$}\n\\STATE{$x = x + \\Delta x$}\n\\ENDIF\n\\IF {$\\rho > \\eta_1$}\n\\STATE{$\\rho = 2 * \\rho$}\n\\ELSE\n\\IF {$\\rho < \\eta_2$}\n\\STATE {$\\rho = 0.5 * \\rho$}\n\\ENDIF\n\\ENDIF\n\\ENDLOOP\n\\end{algorithmic}\n\nHere, $\\mu$ is the trust region radius, $D(x)$ is some matrix used to define a metric on the domain of $F(x)$ and $\\rho$ measures the quality of the step $\\Delta x$, i.e., how well did the linear model predict the decrease in the value of the non-linear objective. The idea is to increase or decrease the radius of the trust region depending on how well the linearization predicts the behavior of the non-linear objective, which in turn is reflected in the value of $\\rho$.\n\nThe key computational step in a trust-region algorithm is the solution of the constrained optimization problem\n\\begin{align}\n        \\arg\\min_{\\Delta x}& \\frac{1}{2}\\|J(x)\\Delta x + F(x)\\|^2 \\\\\n        \\text{such that}&\\quad  \\|D(x)\\Delta x\\|^2 \\le \\mu\n\\label{eq:trp}\n\\end{align}\n\nThere are a number of different ways of solving this problem, each giving rise to a different concrete trust-region algorithm. Currently Ceres, implements two trust-region algorithms - Levenberg-Marquardt and Powell's Dogleg.\n\n\\subsection{Levenberg-Marquardt}\nThe Levenberg-Marquardt algorithm~\\cite{levenberg1944method, marquardt1963algorithm} is the most popular algorithm for solving non-linear least squares problems.  It was also the first trust region algorithm to be developed~\\cite{levenberg1944method,marquardt1963algorithm}. Ceres implements an exact step~\\cite{madsen2004methods} and an inexact step variant of the Levenberg-Marquardt algorithm~\\cite{wright1985inexact,nash1990assessing}.\n\nIt can be shown, that the solution to~\\eqref{eq:trp} can be obtained by solving an unconstrained optimization of the form\n\\begin{align}\n        \\arg\\min_{\\Delta x}& \\frac{1}{2}\\|J(x)\\Delta x + F(x)\\|^2 +\\lambda  \\|D(x)\\Delta x\\|^2\n\\end{align}\nWhere, $\\lambda$ is a Lagrange multiplier that is inverse related to $\\mu$. In Ceres, we solve for\n\\begin{align}\n        \\arg\\min_{\\Delta x}& \\frac{1}{2}\\|J(x)\\Delta x + F(x)\\|^2 + \\frac{1}{\\mu} \\|D(x)\\Delta x\\|^2\n\\label{eq:lsqr}\n\\end{align}\nThe matrix $D(x)$ is a non-negative diagonal matrix, typically the square root of the diagonal of the matrix $J(x)^\\top J(x)$.\n\nBefore going further, let us make some notational simplifications. We will assume that the matrix $\\sqrt{\\mu} D$ has been concatenated at the bottom of the matrix $J$ and similarly a vector of zeros has been added to the bottom of the vector $f$ and the rest of our discussion will be in terms of $J$ and $f$, \\ie the linear least squares problem.\n\\begin{align}\n \\min_{\\Delta x} \\frac{1}{2} \\|J(x)\\Delta x + f(x)\\|^2 .\n \\label{eq:simple}\n\\end{align}\nFor all but the smallest problems the solution of~\\eqref{eq:simple} in each iteration of the Levenberg-Marquardt algorithm is the dominant computational cost in Ceres. Ceres provides a number of different options for solving~\\eqref{eq:simple}. There are two major classes of methods - factorization and iterative.\n\nThe factorization methods are based on computing an exact solution of~\\eqref{eq:lsqr} using a Cholesky or a QR factorization and lead to an exact step Levenberg-Marquardt algorithm. But it is not clear if an exact solution of~\\eqref{eq:lsqr} is necessary at each step of the LM algorithm to solve~\\eqref{eq:nonlinsq}. In fact, we have already seen evidence that this may not be the case, as~\\eqref{eq:lsqr} is itself a regularized version of~\\eqref{eq:linearapprox}. Indeed, it is possible to construct non-linear optimization algorithms in which the linearized problem is solved approximately. These algorithms are known as inexact Newton or truncated Newton methods~\\cite{nocedal2000numerical}.\n\nAn inexact Newton method requires two ingredients. First, a cheap method for approximately solving systems of linear equations. Typically an iterative linear solver like the Conjugate Gradients method is used for this purpose~\\cite{nocedal2000numerical}. Second, a termination rule for the iterative solver. A typical termination rule is of the form\n\\begin{equation}\n        \\|H(x) \\Delta x + g(x)\\| \\leq \\eta_k \\|g(x)\\|. \\label{eq:inexact}\n\\end{equation}\nHere, $k$ indicates the Levenberg-Marquardt iteration number and $0 < \\eta_k <1$ is known as the forcing sequence.  Wright \\& Holt \\cite{wright1985inexact} prove that a truncated Levenberg-Marquardt algorithm that uses an inexact Newton step based on~\\eqref{eq:inexact} converges for any sequence $\\eta_k \\leq \\eta_0 < 1$ and the rate of convergence depends on the choice of the forcing sequence $\\eta_k$.\n\nCeres supports both exact and inexact step solution strategies. When the user chooses a factorization based linear solver, the exact step Levenberg-Marquardt algorithm is used. When the user chooses an iterative linear solver, the inexact step Levenberg-Marquardt algorithm is used.\n\n\\subsection{Powell's Dogleg}\nAnother strategy for solving the trust region problem~\\eqref{eq:trp} was introduced by M. J. D. Powell. The key idea there is to compute two vectors\n\\begin{align}\n        \\Delta x^{\\text{Gauss-Newton}} &= \\arg \\min_{\\Delta x}\\frac{1}{2} \\|J(x)\\Delta x + f(x)\\|^2.\\\\\n        \\Delta x^{\\text{Cauchy}} &= -\\frac{\\|g(x)\\|^2}{\\|J(x)g(x)\\|^2}g(x).\n\\end{align}\nNote that the vector $\\Delta x^{\\text{Gauss-Newton}}$ is the solution to~\\eqref{eq:linearapprox} and $\\Delta x^{\\text{Cauchy}}$ is the vector that minimizes the linear approximation if we restrict ourselves to moving along the direction of the gradient.\n\nThen Powell's Dogleg method finds a vector $\\Delta x$ in the two dimensional subspace defined by $\\Delta x^{\\text{Gauss-Newton}}$ and $\\Delta x^{\\text{Cauchy}}$ that solves the trust region problem. For more details on the exact reasoning and computations, please see Madsen et al~\\cite{madsen2004methods}.\n\nThe key advantage of the Dogleg over Levenberg Marquardt is that if the step computation for a particular choice of $\\mu$ does not result in sufficient decrease in the value of the objective function, Levenberg-Marquardt solves the linear approximation from scratch with a small value of $\\mu$. Dogleg on the other hand, only needs to compute the interpolation between the Gauss-Newton and the Cauchy vectors, as neither of them depend on the value of $\\mu$.\n\nThe Dogleg method can only be used with the exact factorization based linear solvers.\n\n\\section{\\texttt{LinearSolver}}\nRecall that in both of the trust-region methods described above, the key computational cost is the solution of a linear least squares problem of the form\n\\begin{align}\n \\min_{\\Delta x} \\frac{1}{2} \\|J(x)\\Delta x + f(x)\\|^2 .\n \\label{eq:simple2}\n\\end{align}\n\n\nLet $H(x)= J(x)^\\top J(x)$ and $g(x) = -J(x)^\\top  f(x)$. For notational convenience let us also drop the dependence on $x$. Then it is easy to see that solving~\\eqref{eq:simple2} is equivalent to solving the {\\em normal equations}\n\\begin{align}\nH \\Delta x  &= g \\label{eq:normal}\n\\end{align}\n\nCeres provides a number of different options for solving~\\eqref{eq:normal}.\n\n\\subsection{\\texttt{DENSE\\_QR}}\nFor small problems (a couple of hundred parameters and a few thousand residuals) with relatively dense Jacobians, \\texttt{DENSE\\_QR} is the method of choice~\\cite{bjorck1996numerical}. Let $J = QR$ be the QR-decomposition of $J$, where $Q$ is an orthonormal matrix and $R$ is an upper triangular matrix~\\cite{trefethen1997numerical}. Then it can be shown that the solution to~\\eqref{eq:normal} is given by\n\\begin{align}\n    \\Delta x^* = -R^{-1}Q^\\top f\n\\end{align}\nCeres uses \\texttt{Eigen}'s dense QR decomposition routines.\n\n\n\\subsection{\\texttt{SPARSE\\_NORMAL\\_CHOLESKY}}\nLarge non-linear least square problems are usually sparse. In such cases, using a dense QR factorization is inefficient. Let $H = R^\\top R$ be the Cholesky factorization of the normal equations, where $R$ is an upper triangular matrix, then the  solution to ~\\eqref{eq:normal} is given by\n\\begin{equation}\n    \\Delta x^* = R^{-1} R^{-\\top} g.\n\\end{equation}\nThe observant reader will note that the $R$ in the Cholesky factorization of $H$ is the same upper triangular matrix $R$ in the QR factorization of $J$. Since $Q$ is an orthonormal matrix, $J=QR$ implies that $J^\\top J = R^\\top Q^\\top Q R = R^\\top R$.\n\n\nThere are two variants of Cholesky factorization -- sparse and dense. \\texttt{SPARSE\\_NORMAL\\_CHOLESKY}, as the name implies performs a sparse Cholesky factorization of the normal equations. This leads to substantial savings in time and memory for large sparse problems. We use the Professor Tim Davis' \\texttt{CHOLMOD} library (part of the \\texttt{SuiteSparse} package) to perform the sparse cholesky~\\cite{chen2006acs}.\n\n\n\\subsection{\\texttt{DENSE\\_SCHUR} \\& \\texttt{SPARSE\\_SCHUR}}\nWhile it is possible to use \\texttt{SPARSE\\_NORMAL\\_CHOLESKY} to solve bundle adjustment problems, bundle adjustment problem have a special structure, and a more efficient scheme for solving~\\eqref{eq:normal} can be constructed.\n\nSuppose that the SfM problem consists of $p$ cameras and $q$ points and the variable vector $x$ has the  block structure $x = [y_{1},\\hdots,y_{p},z_{1},\\hdots,z_{q}]$. Where, $y$ and $z$ correspond to camera and point parameters, respectively.  Further, let the camera blocks be of size $c$ and the point blocks be of size $s$ (for most problems $c$ =  $6$--$9$ and $s = 3$). Ceres does not impose any constancy requirement on these block sizes, but choosing them to be constant simplifies the exposition.\n\nA key characteristic of the bundle adjustment problem is that there is no term $f_{i}$ that includes two or more point blocks.  This in turn implies that the matrix $H$ is of the form\n\\begin{equation}\n        H =  \\left[\n                \\begin{matrix} B & E\\\\ E^\\top & C\n                \\end{matrix}\n                \\right]\\ ,\n\\label{eq:hblock}\n\\end{equation}\nwhere, $B \\in \\reals^{pc\\times pc}$ is a block sparse matrix with $p$ blocks of size $c\\times c$ and  $C \\in \\reals^{qs\\times qs}$ is a block diagonal matrix with $q$ blocks of size $s\\times s$. $E \\in \\reals^{pc\\times qs}$ is a general block sparse matrix, with a block of size $c\\times s$ for each observation. Let us now block partition $\\Delta x = [\\Delta y,\\Delta z]$ and $g=[v,w]$ to restate~\\eqref{eq:normal} as the block structured linear system\n\\begin{equation}\n        \\left[\n                \\begin{matrix} B & E\\\\ E^\\top & C\n                \\end{matrix}\n                \\right]\\left[\n                        \\begin{matrix} \\Delta y \\\\ \\Delta z\n                        \\end{matrix}\n                        \\right]\n                        =\n                        \\left[\n                                \\begin{matrix} v\\\\ w\n                                \\end{matrix}\n                                \\right]\\ ,\n\\label{eq:linear2}\n\\end{equation}\nand apply Gaussian elimination to it. As we noted above, $C$ is a block diagonal matrix, with small diagonal blocks of size $s\\times s$.\nThus, calculating the inverse of $C$ by inverting each of these blocks is  cheap. This allows us to  eliminate $\\Delta z$ by observing that $\\Delta z = C^{-1}(w - E^\\top \\Delta y)$, giving us\n\\begin{equation}\n        \\left[B - EC^{-1}E^\\top\\right] \\Delta y = v - EC^{-1}w\\ .  \\label{eq:schur}\n\\end{equation}\nThe matrix\n\\begin{equation}\nS = B - EC^{-1}E^\\top\\ ,\n\\end{equation}\nis the Schur complement of $C$ in $H$. It is also known as the {\\em reduced camera matrix}, because the only variables participating in~\\eqref{eq:schur} are the ones corresponding to the cameras. $S \\in \\reals^{pc\\times pc}$ is a block structured symmetric positive definite matrix, with blocks of size $c\\times c$. The block $S_{ij}$ corresponding to the pair of images $i$ and $j$ is non-zero if and only if the two images observe at least one common point.\n\nNow, \\eqref{eq:linear2}~can  be solved by first forming $S$, solving for $\\Delta y$, and then back-substituting $\\Delta y$ to obtain the value of $\\Delta z$.\nThus, the solution of what was an $n\\times n$, $n=pc+qs$ linear system is reduced to the inversion of the block diagonal matrix $C$, a few matrix-matrix and matrix-vector multiplies, and the solution of block sparse $pc\\times pc$ linear system~\\eqref{eq:schur}.  For almost all  problems, the number of cameras is much smaller than the number of points, $p \\ll q$, thus solving~\\eqref{eq:schur} is significantly cheaper than solving~\\eqref{eq:linear2}. This is the {\\em Schur complement trick}~\\cite{brown-58}.\n\nThis still leaves open the question of solving~\\eqref{eq:schur}. The\nmethod of choice for solving symmetric positive definite systems\nexactly is via the Cholesky\nfactorization~\\cite{trefethen1997numerical} and depending upon the\nstructure of the matrix, there are, in general, two options. The first\nis direct factorization, where we store and factor $S$ as a dense\nmatrix~\\cite{trefethen1997numerical}. This method has $O(p^2)$ space complexity and $O(p^3)$ time\ncomplexity and is only practical for problems with up to a few hundred\ncameras. Ceres implements this strategy as the \\texttt{DENSE\\_SCHUR} solver.\n\n\n But, $S$ is typically a fairly sparse matrix, as most images\nonly see a small fraction of the scene. This leads us to the second\noption: sparse direct methods. These methods store $S$ as a sparse\nmatrix, use row and column re-ordering algorithms to maximize the\nsparsity of the Cholesky decomposition, and focus their compute effort\non the non-zero part of the factorization~\\cite{chen2006acs}.\nSparse direct methods, depending on the exact sparsity structure of the Schur complement,\nallow bundle adjustment algorithms to significantly scale up over those based on dense\nfactorization. Ceres implements this strategy as the \\texttt{SPARSE\\_SCHUR} solver.\n\n\\subsection{\\texttt{CGNR}}\nFor general sparse problems, if the problem is too large for \\texttt{CHOLMOD} or a sparse linear algebra library is not linked into Ceres, another option is the \\texttt{CGNR} solver. This solver uses the Conjugate Gradients solver on the {\\em normal equations}, but without forming the normal equations explicitly. It exploits the relation\n\\begin{align}\n    H x = J^\\top J x = J^\\top(J x)\n\\end{align}\nWhen the user chooses \\texttt{ITERATIVE\\_SCHUR} as the linear solver, Ceres automatically switches from the exact step algorithm to an inexact step algorithm.\n\n%Currently only the \\texttt{JACOBI} preconditioner is available for use with this solver. It uses the block diagonal of $H$ as a preconditioner.\n\n\n\\subsection{\\texttt{ITERATIVE\\_SCHUR}}\nAnother option for bundle adjustment problems is to apply PCG to the reduced camera matrix $S$ instead of $H$. One reason to do this is that $S$ is a much smaller matrix than $H$, but more importantly, it can be shown that $\\kappa(S)\\leq \\kappa(H)$.  Ceres implements PCG on $S$ as the \\texttt{ITERATIVE\\_SCHUR} solver. When the user chooses \\texttt{ITERATIVE\\_SCHUR} as the linear solver, Ceres automatically switches from the exact step algorithm to an inexact step algorithm.\n\nThe cost of forming and storing the Schur complement $S$ can be prohibitive for large problems. Indeed, for an inexact Newton solver that computes $S$ and runs PCG on it, almost all of its time is spent in constructing $S$; the time spent inside the PCG algorithm is negligible in comparison. Because  PCG only needs access to $S$ via its product with a vector, one way to evaluate $Sx$ is to observe that\n\\begin{align}\n  x_1 &= E^\\top x \\notag \\\\\n  x_2 &= C^{-1} x_1 \\notag\\\\\n  x_3 &= Ex_2 \\notag\\\\\n  x_4 &= Bx \\notag\\\\\n  Sx &= x_4 - x_3\\ .\\label{eq:schurtrick1}\n\\end{align}\nThus, we can run PCG on $S$ with the same computational effort per iteration as PCG on $H$, while reaping the benefits of a more powerful preconditioner. In fact, we do not even need to compute $H$, \\eqref{eq:schurtrick1} can be implemented using just the columns of $J$.\n\nEquation~\\eqref{eq:schurtrick1} is closely related to {\\em Domain Decomposition methods} for solving large linear systems that arise in structural engineering and partial differential equations. In the language of Domain Decomposition, each point in a bundle adjustment problem is a domain, and the cameras form the interface between these domains. The iterative solution of the Schur complement then falls within the sub-category of techniques known as Iterative Sub-structuring~\\cite{saad2003iterative,mathew2008domain}.\n\n\\section{Preconditioner}\nThe convergence rate of Conjugate Gradients  for solving~\\eqref{eq:normal} depends on the distribution of eigenvalues of $H$~\\cite{saad2003iterative}. A useful upper bound is $\\sqrt{\\kappa(H)}$, where, $\\kappa(H)$f is the condition number of the matrix $H$. For most bundle adjustment problems, $\\kappa(H)$ is high and a direct application of Conjugate Gradients to~\\eqref{eq:normal} results in extremely poor performance.\n\nThe solution to this problem is to replace~\\eqref{eq:normal} with a {\\em preconditioned} system.  Given a linear system, $Ax =b$ and a preconditioner $M$ the preconditioned system is given by $M^{-1}Ax = M^{-1}b$. The resulting algorithm is known as Preconditioned Conjugate Gradients algorithm (PCG) and its  worst case complexity now depends on the condition number of the {\\em preconditioned} matrix $\\kappa(M^{-1}A)$.\n\nThe computational cost of using a preconditioner $M$ is the cost of computing $M$ and evaluating the product $M^{-1}y$ for arbitrary vectors $y$. Thus, there are two competing factors to consider: How much of $H$'s structure is captured by $M$ so that the condition number $\\kappa(HM^{-1})$ is low, and the computational cost of constructing and using $M$.  The ideal preconditioner would be one for which $\\kappa(M^{-1}A) =1$. $M=A$ achieves this, but it is not a practical choice, as applying this preconditioner would require solving a linear system equivalent to the unpreconditioned problem.  It is usually the case that the more information $M$ has about $H$, the more expensive it is use. For example, Incomplete Cholesky factorization based preconditioners  have much better convergence behavior than the Jacobi preconditioner, but are also much more expensive.\n\n\nThe simplest of all preconditioners is the diagonal or Jacobi preconditioner, \\ie,  $M=\\operatorname{diag}(A)$, which for block structured matrices like $H$ can be generalized to the block Jacobi preconditioner.\n\nFor \\texttt{ITERATIVE\\_SCHUR} there are two obvious choices for block diagonal preconditioners for $S$. The block diagonal of the matrix $B$~\\cite{mandel1990block} and the block diagonal $S$, \\ie the block Jacobi preconditioner for $S$. Ceres's implements both of these preconditioners and refers to them as  \\texttt{JACOBI} and \\texttt{SCHUR\\_JACOBI} respectively.\n\nFor bundle adjustment problems arising in reconstruction from community photo collections, more effective preconditioners can be constructed by analyzing and exploiting the camera-point visibility structure of the scene~\\cite{kushal2012}. Ceres implements the two visibility based preconditioners described by Kushal \\& Agarwal as \\texttt{CLUSTER\\_JACOBI} and \\texttt{CLUSTER\\_TRIDIAGONAL}. These are fairly new preconditioners and Ceres' implementation of them is in its early stages and is not as mature as the other preconditioners described above.\n\n\\section{Ordering}\nAll three of the Schur based solvers depend on the user indicating to the solver, which of the parameter blocks correspond to the points and which correspond to the cameras. Ceres refers to them as \\texttt{e\\_block}s and \\texttt{f\\_blocks}. The only constraint on \\texttt{e\\_block}s is that there should be no term in the objective function with two or more \\texttt{e\\_block}s.\n\nAs we saw in Section~\\ref{chapter:tutorial:bundleadjustment}, there are two ways to indicate \\texttt{e\\_block}s to Ceres. The first is to explicitly create an ordering vector \\texttt{Solver::Options::ordering} containing the parameter blocks such that all the \\texttt{e\\_block}s/points occur before the \\texttt{f\\_blocks}, and setting \\texttt{Solver::Options::num\\_eliminate\\_blocks} to the number \\texttt{e\\_block}s.\n\nFor some problems this is an easy thing to do and we recommend its use. In some problems though, this is onerous and it would be better if Ceres could automatically determine \\texttt{e\\_block}s. Setting \\texttt{Solver::Options::ordering\\_type} to \\texttt{SCHUR} achieves this.\n\nThe \\texttt{SCHUR} ordering algorithm is based on the observation that\nthe constraint that no two \\texttt{e\\_block} co-occur in a residual\nblock means that if we were to treat the sparsity structure of the\nblock matrix $H$ as a graph, then the set of \\texttt{e\\_block}s is an\nindependent set in this graph. The larger the number of\n\\texttt{e\\_block}, the smaller is the size of the Schur complement $S$. Indeed the reason Schur based solvers are so efficient at solving bundle adjustment problems is because the number of points in a bundle adjustment problem is usually an order of magnitude or two larger than the number of cameras.\n\nThus, the aim of the \\texttt{SCHUR} ordering algorithm is to identify the largest independent set in the graph of $H$. Unfortunately this is an NP-Hard problem. But there is a  greedy approximation algorithm that performs well~\\cite{li2007miqr} and we use it to identify \\texttt{e\\_block}s in Ceres.\n\n\\section{\\texttt{Solver::Options}}\n\n\\texttt{Solver::Options} controls the overall behavior of the solver. We list the various settings and their default values below.\n\n\\begin{enumerate}\n\n\\item{\\texttt{trust\\_region\\_strategy\\_type }} (\\texttt{LEVENBERG\\_MARQUARDT}) The  trust region step computation algorithm used by Ceres. Currently \\texttt{LEVENBERG\\_MARQUARDT } and \\texttt{DOGLEG} are the two valid choices.\n\n\\item{\\texttt{max\\_num\\_iterations }}(\\texttt{50}) Maximum number of iterations for Levenberg-Marquardt.\n\n\\item{\\texttt{max\\_solver\\_time\\_in\\_seconds }} ($10^9$) Maximum amount of time for which the solver should run.\n\n\\item{\\texttt{num\\_threads }}(\\texttt{1})\nNumber of threads used by Ceres to evaluate the Jacobian.\n\n\\item{\\texttt{initial\\_trust\\_region\\_radius } ($10^4$)} The size of the initial trust region. When the \\texttt{LEVENBERG\\_MARQUARDT} strategy is used, the reciprocal of this number is the initial regularization parameter.\n\n\\item{\\texttt{max\\_trust\\_region\\_radius } ($10^{16}$)} The trust region radius is not allowed to grow beyond this value.\n\\item{\\texttt{max\\_trust\\_region\\_radius } ($10^{-32}$)} The solver terminates, when the trust region becomes smaller than this value.\n\n\\item{\\texttt{min\\_relative\\_decrease }}($10^{-3}$) Lower threshold for relative decrease before a Levenberg-Marquardt step is acceped.\n\n\\item{\\texttt{lm\\_min\\_diagonal } ($10^6$)} The \\texttt{LEVENBERG\\_MARQUARDT} strategy, uses a diagonal matrix to regularize the the trust region step. This is the lower bound on the values of this diagonal matrix.\n\n\\item{\\texttt{lm\\_max\\_diagonal } ($10^{32}$)}  The \\texttt{LEVENBERG\\_MARQUARDT} strategy, uses a diagonal matrix to regularize the the trust region step. This is the upper bound on the values of this diagonal matrix.\n\n\\item{\\texttt{max\\_num\\_consecutive\\_invalid\\_steps } (5)} The step returned by a trust region strategy can sometimes be numerically invalid, usually because of conditioning issues. Instead of crashing or stopping the optimization, the optimizer can go ahead and try solving with a smaller trust region/better conditioned problem. This parameter sets the number of consecutive retries before the minimizer gives up.\n\n\\item{\\texttt{function\\_tolerance }}($10^{-6}$) Solver terminates if\n\\begin{align}\n\\frac{|\\Delta \\text{cost}|}{\\text{cost}} < \\texttt{function\\_tolerance}\n\\end{align}\nwhere, $\\Delta \\text{cost}$ is the change in objective function value (up or down) in the current iteration of Levenberg-Marquardt.\n\n\\item \\texttt{Solver::Options::gradient\\_tolerance } Solver terminates if\n\\begin{equation}\n    \\frac{\\|g(x)\\|_\\infty}{\\|g(x_0)\\|_\\infty} < \\texttt{gradient\\_tolerance}\n\\end{equation}\nwhere $\\|\\cdot\\|_\\infty$ refers to the max norm, and $x_0$ is the vector of initial parameter values.\n\n\\item{\\texttt{parameter\\_tolerance }}($10^{-8}$) Solver terminates if\n\\begin{equation}\n    \\frac{\\|\\Delta x\\|}{\\|x\\| + \\texttt{parameter\\_tolerance}} < \\texttt{parameter\\_tolerance}\n\\end{equation}\nwhere $\\Delta x$ is the step computed by the linear solver in the current iteration of Levenberg-Marquardt.\n\n\\item{\\texttt{linear\\_solver\\_type }(\\texttt{SPARSE\\_NORMAL\\_CHOLESKY})}\n\n\\item{\\texttt{linear\\_solver\\_type }}(\\texttt{SPARSE\\_NORMAL\\_CHOLESKY}/\\texttt{DENSE\\_QR}) Type of linear solver used to compute the solution to the linear least squares problem in each iteration of the Levenberg-Marquardt algorithm. If Ceres is build with \\suitesparse linked in  then the default is \\texttt{SPARSE\\_NORMAL\\_CHOLESKY}, it is \\texttt{DENSE\\_QR} otherwise.\n\n\\item{\\texttt{preconditioner\\_type }}(\\texttt{JACOBI}) The preconditioner used by the iterative linear solver. The default is the block Jacobi preconditioner. Valid values are (in increasing order of complexity) \\texttt{IDENTITY},\\texttt{JACOBI}, \\texttt{SCHUR\\_JACOBI}, \\texttt{CLUSTER\\_JACOBI} and \\texttt{CLUSTER\\_TRIDIAGONAL}.\n\n\\item{\\texttt{sparse\\_linear\\_algebra\\_library } (\\texttt{SUITE\\_SPARSE})} Ceres supports the use of two sparse linear algebra libraries, \\texttt{SuiteSparse}, which is enabled by setting this parameter to \\texttt{SUITE\\_SPARSE} and \\texttt{CXSparse}, which can be selected by setting this parameter to $\\texttt{CX\\_SPARSE}$. \\texttt{SuiteSparse} is a sophisticated and complex sparse linear algebra library and should be used in general. If your needs/platforms prevent you from using \\texttt{SuiteSparse}, consider using \\texttt{CXSparse}, which is a much smaller, easier to build library. As can be expected, its performance on large problems is not comparable to that of \\texttt{SuiteSparse}.\n\n\n\\item{\\texttt{num\\_linear\\_solver\\_threads }}(\\texttt{1}) Number of threads used by the linear solver.\n\n\\item{\\texttt{num\\_eliminate\\_blocks }}(\\texttt{0})\nFor Schur reduction based methods, the first 0 to num blocks are\n    eliminated using the Schur reduction. For example, when solving\n     traditional structure from motion problems where the parameters are in\n     two classes (cameras and points) then \\texttt{num\\_eliminate\\_blocks} would be the\n     number of points.\n\n\\item{\\texttt{ordering\\_type }}(\\texttt{NATURAL})\n Internally Ceres reorders the parameter blocks to help the\n various linear solvers. This parameter allows the user to\n     influence the re-ordering strategy used. For structure from\n     motion problems use \\texttt{SCHUR}, for other problems \\texttt{NATURAL} (default)\n     is a good choice. In case you wish to specify your own ordering\n     scheme, for example in conjunction with \\texttt{num\\_eliminate\\_blocks},\n     use \\texttt{USER}.\n\n\\item{\\texttt{ordering }} The ordering of the parameter blocks. The solver pays attention\n    to it if the \\texttt{ordering\\_type} is set to \\texttt{USER} and the ordering vector is\n    non-empty.\n\n\\item{\\texttt{use\\_block\\_amd } (\\texttt{true})} By virtue of the modeling layer in Ceres being block oriented,\nall the matrices used by Ceres are also block oriented.\nWhen doing sparse direct factorization of these matrices, the\nfill-reducing ordering algorithms can either be run on the\nblock or the scalar form of these matrices. Running it on the\nblock form exposes more of the super-nodal structure of the\nmatrix to the Cholesky factorization routines. This leads to\nsubstantial gains in factorization performance. Setting this parameter to true, enables the use of a block oriented Approximate Minimum Degree ordering algorithm. Settings it to \\texttt{false}, uses a scalar AMD algorithm. This option only makes sense when using \\texttt{sparse\\_linear\\_algebra\\_library = SUITE\\_SPARSE} as it uses the \\texttt{AMD} package that is part of \\texttt{SuiteSparse}.\n\n\\item{\\texttt{linear\\_solver\\_min\\_num\\_iterations }}(\\texttt{1}) Minimum number of iterations used by the linear solver. This only makes sense when the linear solver is an iterative solver, e.g., \\texttt{ITERATIVE\\_SCHUR}.\n\n\\item{\\texttt{linear\\_solver\\_max\\_num\\_iterations }}(\\texttt{500}) Minimum number of iterations used by the linear solver. This only makes sense when the linear solver is an iterative solver, e.g., \\texttt{ITERATIVE\\_SCHUR}.\n\n\\item{\\texttt{eta }} ($10^{-1}$)\n Forcing sequence parameter. The truncated Newton solver uses\n    this number to control the relative accuracy with which the\n     Newton step is computed. This constant is passed to ConjugateGradientsSolver which uses\n     it to terminate the iterations when\n\\begin{equation}\n      \\frac{Q_i - Q_{i-1}}{Q_i} < \\frac{\\eta}{i}\n\\end{equation}\n\n\\item{\\texttt{jacobi\\_scaling }}(\\texttt{true}) \\texttt{true} means that the Jacobian is scaled by the norm of its columns before being passed to the linear solver. This improves the numerical conditioning of the normal equations.\n\n\\item{\\texttt{logging\\_type }}(\\texttt{PER\\_MINIMIZER\\_ITERATION})\n\n\n\\item{\\texttt{minimizer\\_progress\\_to\\_stdout }}(\\texttt{false})\nBy default the Minimizer progress is logged to \\texttt{STDERR} depending on the \\texttt{vlog} level. If this flag is\nset to true, and \\texttt{logging\\_type } is not \\texttt{SILENT}, the logging output\nis sent to \\texttt{STDOUT}.\n\n\\item{\\texttt{return\\_initial\\_residuals }}(\\texttt{false})\n\\item{\\texttt{return\\_final\\_residuals }}(\\texttt{false})\nIf true, the vectors \\texttt{Solver::Summary::initial\\_residuals } and \\texttt{Solver::Summary::final\\_residuals } are filled with the residuals before and after the optimization. The entries of these vectors are in the order in which ResidualBlocks were added to the Problem object.\n    \n\\item{\\texttt{return\\_initial\\_gradient }}(\\texttt{false})\n\\item{\\texttt{return\\_final\\_gradient }}(\\texttt{false})\nIf true, the vectors \\texttt{Solver::Summary::initial\\_gradient } and \\texttt{Solver::Summary::final\\_gradient } are filled with the gradient before and after the optimization. The entries of these vectors are in the order in which ParameterBlocks were added to the Problem object.\n\nSince \\texttt{AddResidualBlock } adds ParameterBlocks to the \\texttt{Problem } automatically if they do not already exist, if you wish to have explicit control over the ordering of the vectors, then use \\texttt{Problem::AddParameterBlock } to explicitly add the ParameterBlocks in the order desired.\n    \n\\item{\\texttt{return\\_initial\\_jacobian }}(\\texttt{false})\n\\item{\\texttt{return\\_initial\\_jacobian }}(\\texttt{false})\nIf true, the Jacobian matrices before and after the optimization are returned in \\texttt{Solver::Summary::initial\\_jacobian } and \\texttt{Solver::Summary::final\\_jacobian } respectively.\n\nThe rows of these matrices are in the same order in which the ResidualBlocks were added to the Problem object. The columns are in the same order in which the ParameterBlocks were added to the Problem object.\n        \nSince \\texttt{AddResidualBlock } adds ParameterBlocks to the \\texttt{Problem } automatically if they do not already exist, if you wish to have explicit control over the column ordering of the matrix, then use \\texttt{Problem::AddParameterBlock } to explicitly add the ParameterBlocks in the order desired.\n\nThe Jacobian matrices are stored as compressed row sparse matrices. Please see \\texttt{ceres/crs\\_matrix.h } for more details of the format.\n    \n\\item{\\texttt{lsqp\\_iterations\\_to\\_dump }}\n List of iterations at which the optimizer should dump the\n     linear least squares problem to disk. Useful for testing and\n     benchmarking. If empty (default), no problems are dumped.\n\n\\item{\\texttt{lsqp\\_dump\\_directory }} (\\texttt{/tmp})\n If \\texttt{lsqp\\_iterations\\_to\\_dump} is non-empty, then this setting determines the directory to which the files containing the linear least squares problems are written to.\n\n\n\\item{\\texttt{lsqp\\_dump\\_format }}(\\texttt{TEXTFILE}) The format in which linear least squares problems should be logged\nwhen \\texttt{lsqp\\_iterations\\_to\\_dump} is non-empty.  There are three options\n\\begin{itemize}\n\\item{\\texttt{CONSOLE }} prints the linear least squares problem in a human readable format\n  to \\texttt{stderr}. The Jacobian is printed as a dense matrix. The vectors\n   $D$, $x$ and $f$ are printed as dense vectors. This should only be used\n   for small problems.\n\\item{\\texttt{PROTOBUF }}\n   Write out the linear least squares problem to the directory\n   pointed to by \\texttt{lsqp\\_dump\\_directory} as a protocol\n   buffer. \\texttt{linear\\_least\\_squares\\_problems.h/cc} contains routines for\n   loading these problems. For details on the on disk format used,\n   see \\texttt{matrix.proto}. The files are named \\texttt{lm\\_iteration\\_???.lsqp}. This requires that \\texttt{protobuf} be linked into Ceres Solver.\n\\item{\\texttt{TEXTFILE }}\n   Write out the linear least squares problem to the directory\n   pointed to by \\texttt{lsqp\\_dump\\_directory} as text files\n   which can be read into \\texttt{MATLAB/Octave}. The Jacobian is dumped as a\n   text file containing $(i,j,s)$ triplets, the vectors $D$, $x$ and $f$ are\n   dumped as text files containing a list of their values.\n\n   A \\texttt{MATLAB/Octave} script called \\texttt{lm\\_iteration\\_???.m} is also output,\n   which can be used to parse and load the problem into memory.\n\\end{itemize}\n\n\n\n\\item{\\texttt{check\\_gradients }}(\\texttt{false})\n Check all Jacobians computed by each residual block with finite\n     differences. This is expensive since it involves computing the\n     derivative by normal means (e.g. user specified, autodiff,\n     etc), then also computing it using finite differences. The\n     results are compared, and if they differ substantially, details\n     are printed to the log.\n\n\\item{\\texttt{gradient\\_check\\_relative\\_precision }} ($10^{-8}$)\n  Relative precision to check for in the gradient checker. If the\n  relative difference between an element in a Jacobian exceeds\n  this number, then the Jacobian for that cost term is dumped.\n\n\\item{\\texttt{numeric\\_derivative\\_relative\\_step\\_size }} ($10^{-6}$)\n Relative shift used for taking numeric derivatives. For finite\n     differencing, each dimension is evaluated at slightly shifted\n     values, \\eg for forward differences, the numerical derivative is\n\n\\begin{align}\n       \\delta &= \\texttt{numeric\\_derivative\\_relative\\_step\\_size}\\\\\n       \\Delta f &= \\frac{f((1 + \\delta)  x) - f(x)}{\\delta x}\n\\end{align}\n\n\n     The finite differencing is done along each dimension. The\n     reason to use a relative (rather than absolute) step size is\n     that this way, numeric differentiation works for functions where\n     the arguments are typically large (e.g. $10^9$) and when the\n     values are small (e.g. $10^{-5}$). It is possible to construct\n     \"torture cases\" which break this finite difference heuristic,\n     but they do not come up often in practice.\n\n\\item{\\texttt{callbacks }}\n  Callbacks that are executed at the end of each iteration of the\n     \\texttt{Minimizer}. They are executed in the order that they are\n     specified in this vector. By default, parameter blocks are\n     updated only at the end of the optimization, i.e when the\n     \\texttt{Minimizer} terminates. This behavior is controlled by\n     \\texttt{update\\_state\\_every\\_variable}. If the user wishes to have access\n     to the update parameter blocks when his/her callbacks are\n     executed, then set \\texttt{update\\_state\\_every\\_iteration} to true.\n\n     The solver does NOT take ownership of these pointers.\n\n\\item{\\texttt{update\\_state\\_every\\_iteration }}(\\texttt{false})\nNormally the parameter blocks are only updated when the solver terminates. Setting this to true update them in every iteration. This setting is useful when building an interactive application using Ceres and using an \\texttt{IterationCallback}.\n\\end{enumerate}\n\n\\section{\\texttt{Solver::Summary}}\nTBD\n", "meta": {"hexsha": "c2b73174ff35c784e54d1cf62f34c000a8a6917b", "size": 38456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/solving.tex", "max_stars_repo_name": "pritasam/ceres-solver", "max_stars_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/solving.tex", "max_issues_repo_name": "pritasam/ceres-solver", "max_issues_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/solving.tex", "max_forks_repo_name": "pritasam/ceres-solver", "max_forks_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.0583153348, "max_line_length": 869, "alphanum_fraction": 0.7514302059, "num_tokens": 10208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.6826745900605639}}
{"text": "\\section{A basic machine learning problem: image classification}\n%The ultimate goal of supervised learning algorithms is to classify the data into correct categories.\n%Classification is a very basic  yet important problem\n%which is based on a training set of data containing observations (or instances) whose category memberships are known. An example is to classify a given email into ``spam\" or ``non-spam\" classes. Assigning a diagnosis to a given patient based on the observed characteristics of the patient (such as gender, blood pressure, presence or absence of certain symptoms, etc.) would be another example. To understand what it the image classification problem, let us propose the following question:\nClassification problem is a very important part of machine learning. Its goal is to determine which class a new data belongs to based on a set of training data whose class is known. For example, in mail management, classifying an e-mail as ``spam\" or ``non-spam\" is a typical binary classification problem, and the classification of credit rating of credit card customers by banks belong to multiple classification problems. More specifically, in order to understand image classification problem, let us pose the following question:\n\n\n\\begin{itemize}\n\t\\item Given a set of images of cat, dog and rabbit, how does a machine classify the three different classes?\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{figures/cat-dog-1.png}\n\t\\end{center}\n\t%\t\\caption{}\n\\end{figure}\n\n\\break\n\nFirst of all, we introduce how an image is represented on computer. Mathematically, {gray-scale image can be considered as a matrix  in $ \\mathbb{R}^{n_0\\times n_0}$ shown below, where the left one is the image from human vision and the right one is the matrix represented in computer. Each entry in this $ \\mathbb{R}^{n_0\\times n_0}$ corresponds to the value of a pixel belong to $[0,255]$.\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{6DL/figures/gray-1.png}\n\t\\end{center}\n\t%The next figure shows different results from: {human vision and computer representation}:{\\color{red}Lian comments: should it be a 3D tensor?}\n\t%\\begin{figure}[H]\n\t%\t\\begin{center}\n\t%\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{figures/ImagePixels.png}\n\t%\t\\end{center}\n\t%\\end{figure}\n\tA color image can be taken as 3D tensor (matrix with $3$ channels (RGB)) in $ \\mathbb{R}^{n_0\\times n_0 \\times 3}$\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{6DL/figures/corlor-1.png}\n\t\\end{center}\n\t\n\t%\\begin{itemize}\n\t%\t\\item An image is just a big grid of numbers between [0, 255]\n\t%\t\\begin{itemize}\n\t%\t\t\\item e.g. 800$\\times$600$\\times$3 (3 channels RGB)\n\t%\t\\end{itemize}\n\t%\\end{itemize}\n\t\n\t\n\t\\break\n\t\n\tThen, let us think about the image classification problem of cat, dog and rabbit. Each image is a big vector of pixel values, for example\n\t$$ d=1280\\times720\\times 3  (\\text{width} \\times \\text{height} \\times \\text{RGB channel}) \\approx 3\\text{M},$$\n\twhich can be considered as a point $x \\in \\mathbb{R}^d$. The question becomes: given 3 different sets of points (cat, dog and rabbit) in $\\mathbb{R}^d$, how does a machine classify them?\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=.3\\textwidth, height=.3\\textwidth]{figures/cat-dog-2.png}   \\quad \\quad  \\quad \\quad\n\t\t\t\\includegraphics[width=.3\\textwidth, height=.3\\textwidth]{figures/cat-dog-3.png}\n\t\t\\end{center}\n\t\\end{figure}\n\t\n\t\\noindent To answer this question, we consider a mathematical problem: Find $f(\\cdot; \\bm \\theta): \\mathbb{R}^d \\to \\mathbb{R}^3$ such that:\n\t$$\n\tf(\\includegraphics[width=.07\\textwidth]{figures/cat.png}; \\Theta)\n\t\\approx \\begin{pmatrix}\n\t1\\\\ 0 \\\\ 0\n\t\\end{pmatrix}\n\t,\\quad\n\tf(\\includegraphics[width=.07\\textwidth]{figures/dog.png}; \\Theta)\n\t\\approx \\begin{pmatrix}\n\t0\\\\ 1 \\\\ 0\n\t\\end{pmatrix}\n\t,\\quad\n\tf(\\includegraphics[width=.07\\textwidth]{figures/rabbit.png};\n\t\\Theta) \\approx\n\t\\begin{pmatrix}\n\t0\\\\ 0 \\\\ 1\n\t\\end{pmatrix}\n\t.\n\t$$\n\t$f(\\cdot; \\bm \\theta)$ maps a given image to a 3-dimensional vector, which is a probability distribution  $\\begin{pmatrix}\n\tp_1\\\\ p_2 \\\\ p_3\n\t\\end{pmatrix}$\n\t, where $p_1, p_2, p_3$ are probabilities of the given image being cat, dog, rabbit, respectively. For example\n\t\n\t$$\n\tf(\\includegraphics[width=.07\\textwidth]{figures/cat.png}; \\bm \\theta)\n\t=\n\t\\begin{pmatrix}\n\t0.7\\\\ 0.2 \\\\ 0.1\n\t\\end{pmatrix}\n\t\\quad \\Longrightarrow \\quad \\includegraphics[width=.07\\textwidth]{figures/cat.png}= {\\rm cat}.\n\t$$\n\t$f$ is a classifier that can be used to classify what a given image is.\n\t\n%%\tAs an example, we introduce the image classification of cat, dog, rabbit above. More general, classification problem is to find some curves or surfaces to separate some sets of data. As examples, the following two images show how a circle and a curve separate different sets of points\n%%\t\\begin{figure}[H]\n%%\t\t\\begin{center}\n%%\t\t\t\\includegraphics[width=1.5in]{NLinearS1.png}  \\quad\n%%\t\t\t\\quad  \\includegraphics[width=1.5in]{NLinearS2.png}\n%%\t\t\\end{center}\n%%\t\\end{figure}\n%%\t\\noindent It begins with a data set (training data)\n%%\t$$\n%%\tD := \\{(x_j, y_j)\\}_{j=1}^N,\n%%\t$$\n%%\tand\n%%\t$$\n%%\tA = \\{ x_1, x_2, \\cdots, x_N\\} \\quad \\text{with} \\quad A = A_1\\cup A_2\\cup \\cdots \\cup A_k, ~A_i\\cap A_j = \\emptyset, \\forall i \\neq j,\n%%\t$$\n%%\twhere $A_1,...,A_k$ are a collection of subsets of A,\n%%\t$y_j \\in \\mathbb{R}^{k}$ is the label of data $x_j$ with\n%%\t$y_j[i]$ as the probability of $x_j$ in class $i$ or $x_j \\in A_i$. If $x_j \\in A_{i_j}$, we often choose\n%%\t\\begin{equation}\\label{key}\n%%\ty_j = e_{i_j},\n%%\t\\end{equation}\n%%\tor we say $x_j$ has real label $i_j$.\n%%\n%%\t\\noindent Then, an classification problem can be thought as a data fitting\n%%\tproblem in a high dimensional space $\\mathbb{R}^d$: Given data $\\{x_j, y_j\\}_{j=1}^N$, we need to find a mapping\n%%\t$f:  \\mathbb R^{d}\\mapsto \\mathbb R^k,$\n%%\tsuch that, for a given data $(x_j,y_j)$,\n%%\t\\begin{equation}\\label{eq:idealouput}\n%%\tf(x_j)\\approx y_j = e_{i_j} \\in \\mathbb R^k,\n%%\t\\end{equation}\n%%\tfor all $x_j \\in A$.\n%%\tFor the general setting above, we use a probatilistic model for understanding the\n%%\toutput $f(x) \\in \\mathbb{R}^{k}$ as a discrete\n%%\tdistribution on $\\{1, \\cdots,k\\}$, with $[f(x)]_i$ as the probability\n%%\tfor $x$ in the class $i$, namely\n%%\t\\begin{equation}\n%%\t\\label{distrib}\n%%\t0 \\le [f(x)]_i \\le 1,\\quad\n%%\t\\sum_{i=1}^k  [f(x)]_i=1.\n%%\t\\end{equation}\n%%\tThen, we choose\n%%\t\\begin{equation}\\label{eq:maxchoose}\n%%\t\\mathop{\\arg\\max}_{i}\\{[f(x)]_i~:~ i = 1:k\\},\n%%\t\\end{equation}\n%%\tas the label for a data $x$, which is ideally close to\n%%\t\\eqref{eq:idealouput}.  The remaining key issue is the construction of\n%%\tthe classification mapping $f$.\n%%\t\n%%\t\n%%\tIn order to find a good $f$, we consider to solve the following {optimization problem}\n%%\t$$\\mathcal L(\\bm \\theta):= \\mathbb E_{(x,y)\\sim \\mathcal D} [\\ell(f(x;\\theta),y)]$$\n%%\twhich defines the ideal loss function which measures the distance over all possible data for the parameterized function model $f(x;\\theta)$. However, in practice, we can only have the finite sampled data set $D = \\{ (x_j,y_j)\\}_{j=1}^N$ from the original data distribution $\\mathcal D$.\n%%\tBased on the statistical mechanism, we approximate the expectation in the ideal loss function by sampling, which leads to the following approximation of $\\mathcal L(\\theta)$\n%%\t\\begin{equation}\\label{key}\n%%\t\\mathcal L(\\bm \\theta)\\approx L(\\theta) := \\frac{1}{N} \\sum_{j=1}^N \\ell(f(x_j,\\theta), y_j).\n%%\t\\end{equation}\n%%\tAs examples, two commonly used distances are\n%%\t\\begin{itemize}\n%%\t\t\\item $\\ell^2$ distance:\n%%\t\t$$\n%%\t\t\\ell(y_j,f(x_j; \\bm \\theta)) = \\|y_j - f(x_j; \\bm \\theta)\\|^2.\n%%\t\t$$\n%%\t\t\\item KL-divergence distance:\n%%\t\t$$\n%%\t\t\\ell(y_j, f(x_j; \\bm \\theta)) = \\sum_{i=1}^k [y_j]_i \\log\\frac{[y_j]_i }{[f(x_j;\\bm \\theta)]_i}.\n%%\t\t$$\n%%\t\\end{itemize}\n%%\n%%\n%%In order to verify the performance of trained model $f$, there will be a test set\n%%\\begin{equation}\\label{key}\n%%T = \\{ (x_j ,y_j) \\}_{j=1}^M,\n%%\\end{equation}\n%%with the same dimension of training data $D$, but is not known before\n%%we finish the training process.\n%%\n%%In the following, we briefly introduce linear models and logistic regression in order to better understand the classification problem.\n%%\\subsection{Linear models: decision boundaries given by hyper-planes}\n%%This is a demo of classification for binary and multi-classed cases.\n%%The original data sets are\n%%\\begin{figure}[H]\n%%\t\\begin{center}\n%%\t\t\\includegraphics[width=.35\\textwidth]{lr2noboundary} \\quad \\quad  \\includegraphics[width=.35\\textwidth]{lr3noboundary}\n%%\t\\end{center}\n%%\\end{figure}\n%%Then the decision boundaries given by hyper-planes would be:\n%%\\begin{figure}[H]\n%%\t\\begin{center}\n%%\t\t\\includegraphics[width=.35\\textwidth]{lr2boundary} \\quad \\quad  \\includegraphics[width=.35\\textwidth]{lr3boundary}\n%%\t\\end{center}\n%%\\end{figure}\n%%\n%%\\break\n%%\\subsection{How to find these hyper-planes:  logistic regressions}\n%%For a collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$, try to find\n%%\\begin{equation}\n%%\\label{Wb}\n%%W=\n%%\\begin{pmatrix}\n%%w_1\\\\\n%%\\vdots\\\\\n%%w_k\n%%\\end{pmatrix}\n%%\\in \\mathbb{R}^{k\\times d},\n%%b=\n%%\\begin{pmatrix}\n%%b_1\\\\\n%%\\vdots\\\\\n%%b_k\n%%\\end{pmatrix}\n%%\\in \\mathbb{R}^{k\\times d},\n%%\\end{equation}\n%%such that,   for each $1\\le i\\le k$ and $ j \\neq i$\n%%\\begin{equation}\n%%\\label{eq:3}\n%%(Wx+b)_i > (Wx+b)_j,\\ \\forall x\\in A_i,\n%%\\end{equation}\n%%or\n%%\\begin{equation}\n%%\\label{eq:3}\n%%w_ix+b_i > w_jx+b_j,\\ \\forall x\\in A_i.\n%%\\end{equation}\n%\n%More details of logistic regression will be discussed later.\n\n\n\n\\break\n\\section{Some popular data sets in image classification}\nIn this subsection, we will introduce some popular and standard data sets\nin image classification. The most popular four data sets, MNIST, CIFAR-10, CIFAR-100 and ImageNet are shown in Table \\ref{popular_dataset}.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|c|}\n\t\t\\hline\n\t\t% after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\n\t\tdataset &  training (N) & test (M)   & classes (k) & channels (c)& input size (d)\\\\\\hline\n\t\tMNIST\t&\t60K\t&\t10K\t&\t10\t& Greyscale & 28*28  \\\\\\hline\n\t\tCIFAR-10\t&\t50K \t&\t10K\t&\t10 & RGB & 32*32   \\\\\\hline\n\t\tCIFAR-100\t&\t50K \t&\t10K\t&\t100 & RGB & 32*32   \\\\\\hline\n\t\tImageNet\t&\t1.2M \t&\t50K\t&\t1000 &\tRGB & 224*224  \\\\\\hline\n\t\\end{tabular}\n\t\\caption{Basic descriptions about popular datasets }\n\t\\label{popular_dataset}\n\\end{table}\n\n\\break\n\\subsection{MNIST (Modified National Institute of Standards and Technology Database)}\nMNIST\\cite{lecun1998mnist} is a database for handwritten digits. It is a simple database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting. In order to use MNIST for the classification problem, the following setup is often used:\n\\begin{itemize}\n\t\\item Training set : $N = 60,000$;\n\t\\item Test set : $M = 10,000$;\n\t\\item Image size : $d =28*28*1=784$;\n\t\\item Classes: $ k = 10$;\n\\end{itemize}\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[height=.2\\textheight]{mnist_short.png}\n\t\t\\caption{Some images in MNIST.}\n\t\\end{center}\n\\end{figure}\nThe following example shows  an image of handwritten digits is represented mathematically\n\\break\n$$\nx=\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_1.jpg}}\n=\n\\begin{pmatrix}\n  x_1\\\\\nx_2\\\\\n\\vdots\\\\\nx_{784}\n\\end{pmatrix}\n\\in \\mathbb R^{784}.\n$$\nMNIST has 10 classes denoted by $\\{A_k\\}_{k=1}^{10}$ as shown in the following, where $A_{k}$ is the set of handwritten digits $k$ for $k=1,2,3,...,9$ and $A_{10}$ is the set of handwritten digits $0$\n%\\begin{equation}\n%\\label{A1}\n%A_1=\n%\\left\\{\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist1_1.jpg}},\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist1_2.jpg}},\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist1_3.jpg}}, \\cdots\n%\\right\\}\n%\\subset \\mathbb R^{784}\n%\\end{equation}\n\\begin{equation}\n  \\label{A2}\nA_2=\n\\left\\{\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_1.jpg}},\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_2.jpg}},\\cdots\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_3.jpg}}, \\cdots\n\\right\\},~\n%\\subset \\mathbb R^{784}\nA_{9}=\n\\left\\{\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist9_1.jpg}},\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist9_2.jpg}},\\cdots\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist9_3.jpg}}, \\cdots\n\\right\\},~\nA_{10}=\n\\left\\{\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist0_1.jpg}},\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist0_2.jpg}}, \\cdots\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist0_3.jpg}}, \\cdots\n\\right\\}\n\\subset \\mathbb R^{784}.\n\\end{equation}\n\n\n\n\\break\n\\subsection{CIFAR}\n\\paragraph{CIFAR-10}\nCIFAR-10\\cite{krizhevsky2009learning} is a set of images that can be used to teach a computer how to recognize objects. It contains 60,000 32x32 color images in 10 different classes,  with 6000 images per class. The 10 different classes represent airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships, and trucks. In order to use CIFAR-10 for the classification problem, people usually use the following setup:\n\\begin{itemize}\n\t\\item Training set : $N = 50,000$\n\t\\item Test set : $M = 10,000$\n\t\\item Image size : $d  = 32*32*3$\n\t\\item Classes: $k = 10$\n\\end{itemize}\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[height=.26\\textheight]{cifar10.jpg}\n\t\t\\includegraphics[height=0.26\\textheight]{cifar100.png}\n\t\t\\label{Fig: CIFAR-10}\n\t\t\\caption{Left: Some images in CIFAR-10. Right: Some images in CIFAR-100.}\n\t\\end{center}\n\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\begin{center}\n%\t\t\\includegraphics[height=.4\\textheight]{cifar10.jpg}\n%\t\t\\label{Fig: CIFAR-10}\n%\t\t\\caption{Some images in CIFAR-10.}\n%\t\\end{center}\n%\\end{figure}\n%\\begin{figure}[H]\n%\t\\begin{center}\n%\t\t\\includegraphics[height=0.35\\textheight]{cifar100.png}\n%\t\t\\caption{Some images in CIFAR-100.}\n%\t\\end{center}\n%\\end{figure}\n\n\\break\n\n\\paragraph{CIFAR-100}\nCIFAR-100\\cite{krizhevsky2009learning} is just like the CIFAR-10, except it has 100 classes containing 600 images each. There are 500 training images and 100 testing images per class. The 100 classes in the CIFAR-100 are grouped into 20 superclasses and each superclass has 5 classes. Each image comes with a ``fine\" label (the class to which it belongs) and a ``coarse\" label (the superclass to which it belongs). In order to use CIFAR-100 for the classification problem, people usually use the following setup:\n\n\\begin{itemize}\n\t\\item Training set : $N = 50,000$\n\t\\item Test set : $M = 10,000$\n\t\\item Image size : $d = 32*32*3$\n\t\\item Classes: $k = 100$\n\t\\end{itemize}\n%\\begin{figure}[H]\n%\t\\begin{center}\n%\t\t\\includegraphics[height=0.35\\textheight]{cifar100.png}\n%\t\t\\caption{Some images in CIFAR-100.}\n%\t\\end{center}\n%\\end{figure}\n\n\\subsection{ImageNet}\nThe ImageNet\\cite{deng2009imagenet} project is a large visual database designed for use in visual object recognition software research. More than 1 million images have been hand labeled to indicate what objects are pictured. It is organized according to the WordNet hierarchy (currently only the nouns), in which each node of the hierarchy is depicted by hundreds and thousands of images.\nSince 2010, the ImageNet runs an annual software contest, the ImageNet Large Scale Visual Recognition Challenge (ILSVRC), where software programs compete to correctly classify and detect objects and scenes. In order to use ImageNet for the classification problem, we list the setup of ILSVRC2012 in the following\n\\begin{itemize}\n\t\\item Training set : $N = 1,200,000$\n\t\\item Test set : $M = 50,000$\n\t\\item Image size : $d = 224*224*3$\n\t\\item Classes: $k = 1,000$\n\\end{itemize}\n%\\begin{figure}[H]\n%\t\\begin{center}\n%\t\t\\includegraphics[height=0.25\\textheight]{imagenet.jpeg}\n%\t\t\n%\t\\end{center}\n%\\end{figure}\n\n\n\\begin{figure}[H]\n\t\\begin{center}\n\\includegraphics[height=0.22\\textheight]{imagenet-example.png}\n\t\t\\caption{Some images in ImageNet.}\n\t\\end{center}\n\\end{figure}\n\n\n\\break\n%\\section{Classification and decision boundaries}\n%A classification problem is to find some curves or surfaces to separate some sets of data. As examples, the following two images show how a circle and a curve separate different sets of points\n%\\begin{figure}[H]\n%\t\\begin{center}\n%\t\t\\includegraphics[width=1.5in]{NLinearS1.png}  \\quad\n%                \\quad  \\includegraphics[width=1.5in]{NLinearS2.png}\n%\t\\end{center}\n%\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\begin{center}\n%\t\t \\includegraphics[width=.35\\textwidth,\n%                 height=0.3\\textheight]{nlr3boundary}\n%\t\\end{center}\n%\\end{figure}\n%\\input{Jianqing}\n", "meta": {"hexsha": "0d38b9f1d510b91d5264a5ad37641f4c93f41045", "size": 16828, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/1 Machine Learning and Image Classification/1.2-ClassificationProblem.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/1 Machine Learning and Image Classification/1.2-ClassificationProblem.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/1 Machine Learning and Image Classification/1.2-ClassificationProblem.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": 42.6025316456, "max_line_length": 532, "alphanum_fraction": 0.7103042548, "num_tokens": 5539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6826745699401044}}
{"text": "% Section: Gaussian Process Regression\n\\section{Gaussian Process Regression} \\label{sec:intro}\n\n\\subsection{Regression}\n\n\\para{Regression}\nRegression is probably one of the most fundamental problems in a wide range of fields including \\emph{Statistics}, \\emph{Signal Processing} and \\emph{Machine Learning}, etc. A regression problem is usually formulated as follows:\nGiven a training set $D = \\{ (\\textbf{x}_{i}, y_{i}) | i = 1,2,...,n \\}$, we assume that $\\textbf{x}_{i}, y_{i}$ have the following relationship:\n\t\\begin{equation}\n\t\ty_{i} = f(\\textbf{x}_{i}) + e\n\t\\end{equation}\nwhere $e$ is the error noise. By finding such $f(\\cdot)$, we can predict what a corresponding $y^{*}$ is in some test case $\\textbf{x}^{*}$. Note that $\\textbf{x}$ can either be a vector or a scalar.\n\n\\para{Generalized Linear Model}\nA widely used regression model is called Generalized Linear Model(GLM)\\cite{mccullagh1984generalized}, in which a regression function can be expressed as a linear combination:\n\t\\begin{equation}\n\t\tf(\\textbf{x}) = \\sum_{i=1}^{M} w_{i}\\phi_i (\\textbf{x})\n\t\\end{equation}\nwhere $\\phi_{i}(x)$ is called the basis function.\nIn a regular GLM analysis, we have to firstly determine what our basis functions we are going to use, and subsequently can we use the training dataset to derive the parameters in the basis functions and the coefficients in the regression function.\n\t\n\\para{Mean Square Error}\nWe use a measurement called the Mean Square Error(MSE) to evaluate the performance of the regression function. It is defined as follows:\n\t\\begin{equation}\n\t\tMSE = \\frac{1}{m}\\sum^{m}_{i=1} (f(\\textbf{x}^{*})-y_{i}^{*})^{2}\n\t\\end{equation}\nwhere $f(x)$ represents the regression function. A smaller MSE represents a better regression function on a test set.\n\n\n\\subsection{Gaussian Process Regression}\n\n\\para{Gaussian Process}\nA Gaussian Process(GP) is any distribution over functions such that any finite set of function values $f(x_1), f(x_2), ..., f(x_N)$ have a joint Gaussian distribution\\cite{rasmussen2006gaussian}. It can usually be represented as\n\\begin{equation}\nN\\{ E[ f(x) ], Cov[f(x), f(x^{'})] \\}\n\\end{equation}\nwhere $E[ f(x) ]$ refers to its \\emph{Mean Function}, and $Cov[f(x), f(x^{'})]$ refers to its \\emph{Covariance Function}.\n\n\\para{Gaussian Process Regression}\nGauss Process Regression(GPR)\\cite{rasmussen2006gaussian} is a popular regression method these years.\nThe key of this method is to model the regression function $\\{ f(\\textbf{x}) | \\textbf{x} \\in S\\}$ as a GP \n\\begin{equation}\nf(x) \\gets N \\{ m(\\textbf{x}), K (\\textbf{x},\\textbf{x}^{'}) \\}\n\\end{equation}\nwhere $m(\\textbf{x})$ is the \\emph{Mean function} and $K (\\textbf{x},\\textbf{x}^{'})$ is the \\emph{Kernel Function}.\n\nIn a GPR, we don't have to derive the exact form of the regression function, we just need to determine the form of the above two functions. \nAs introduced in GP, the \\emph{Kernel Function} $K (\\textbf{x},\\textbf{x}^{'})$ is actually the covariance between $f(\\textbf{x})$ and $f(\\textbf{x}^{'})$, and if it is a zero-mean GP, the covariance turns into correlation. So a \\emph{Kernel Function} represents the relationship between $f(\\textbf{x})$ and $f(\\textbf{x}^{'})$.\n\nBy calculating the posterior probability of the desired $f(\\textbf{x}^{*})$, \\emph{i.e.} $p(f(\\textbf{x}^{*}) | \\textbf{x}^{*}, D)$, we can derive the mean value along with the standard deviation of this estimation. \nOn the other hand, we must noted that calculating the posterior probability will become an intractable work when we have a high-dimensional dataset. It is a need that we introduce some inference method to estimate this work. \\\\\n\nTo summarize, choosing a suitable \\emph{Mean Functions}, \\emph{Kernel Functions} as well as the \\emph{Likelihood Functions} and the \\emph{Inference Methods} is the key of a GPR model.\nRasmussen's \\emph{Gaussian Processes for Machine Learning}\\cite{rasmussen2006gaussian} has implemented some marvellous Matlab/Octave code of GPR, it is available on his website\\footnote{Available at \\color{blue}\\href{http://www.gaussianprocess.org/gpml/code/matlab/doc/}{http://www.gaussianprocess.org/gpml/code/}} known as \\textbf{\\emph{GPML}}.\n\n\n", "meta": {"hexsha": "60632fcce74f17625a2b81c99f397bf04fd98149", "size": 4161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/GPR.tex", "max_stars_repo_name": "lzhbrian/gpr", "max_stars_repo_head_hexsha": "912c530fec02e4fe1a4d49b96e6fc3a25b2bdf3c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-08T13:38:19.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-07T02:26:12.000Z", "max_issues_repo_path": "tex/GPR.tex", "max_issues_repo_name": "lzhbrian/gpr", "max_issues_repo_head_hexsha": "912c530fec02e4fe1a4d49b96e6fc3a25b2bdf3c", "max_issues_repo_licenses": ["MIT"], "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/GPR.tex", "max_forks_repo_name": "lzhbrian/gpr", "max_forks_repo_head_hexsha": "912c530fec02e4fe1a4d49b96e6fc3a25b2bdf3c", "max_forks_repo_licenses": ["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.0, "max_line_length": 345, "alphanum_fraction": 0.7308339342, "num_tokens": 1186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.6825923167501126}}
{"text": "\\chapter{Sample Spaces and Events}\nIn the previous chapter we discussed games that do not involve move by chance.\nA theory that studies experiments, processes and interactions that are subject\nto chance is called \\emph{probability theory}; we are going to study this theory\nin this part.\n\nThe most important assumption of probability theory is that nonetheless the\noutcome of an experiment is not known in advance --- the set of all possible\noutcomes is known. This set is called the \\emph{sample space} or the\n\\emph{probability space}.\n\nFor example, if our experiment consists of tossing a coin, then the sample space\nconsists of two outcomes $\\set{H, T}$, where $H$ stands for heads and $T$ stands\nfor tails.\n\\begin{exercise}\n  Write the sample space for the experiment consisting of tossing two coins.\n\\end{exercise}\nEach element of the sample space is called an \\emph{outcome} or an\n\\emph{elementary event}. Typically, we are interested in observing several\noutcomes; e.g., in the experiment consisting of tossing five coins, the set\n$\\set{HTTTT, THTTT, TTHTT, TTTHT, TTTTH}$ describe all possible outcomes when\nexactly one coin shows heads. We say that a set of outcomes is an \\emph{event}.\n\nAnother assumption of probability theory is that every outcome $\\omega$ of a\nsample space $\\Omega$ is assigned some probability $\\Distribution{D}(\\omega)$;\nintuitively, $\\Distribution{D}(\\omega)$ is the likelihood that the outcome\n$\\omega$ occurs in the experiment. It is convenient to normalize probabilities,\nso we require that $0 \\le \\Distribution{D}(\\omega) \\le 1$ for all $\\omega \\in\n\\Omega$ and the sum of $\\Distribution{D}(\\omega)$ for $\\omega \\in \\Omega$ is\nequal to $1$. \n(In the sequel, we use $\\sum_{x \\in X} f(x)$ to describe the sum of $f(x)$ for\n$x \\in X$; see \\Cref{section:generalized-sum} for the formal definition.)\n\\nomenclature[C]{$\\sum_{i \\in S ~:~ P(i)} \\alpha_i$}{denotes $\\alpha_{i_1} +\n\\dots + \\alpha_{i_k}$, where $\\set[P(i)]{i \\in S} = \\set{i_1, \\dots, i_k}$}\nThe function $\\Distribution{D}$ is called a \\emph{probability distribution} on\n$\\Omega$.\n\nThe pair of a sample space and a probability distribution on the space is called\na \\emph{finite discrete probability space}.\n\nWe can extend the notion of probability from elementary events to all events as\nfollows. Let $E \\subseteq \\Omega$ be an event in the finite discrete probability\nspace $(\\Omega, \\Distribution{D})$. Then $\\Pr_{\\Distribution{D}}(E)$ denotes\n$\\sum_{\\omega \\in E} \\Distribution{D}(\\omega)$. \n\n\\begin{exercise}\n  In many cases we consider \\emph{uniform distribution} on a set $\\Omega$, the\n  distribution $\\Uniform{\\Omega}$ such that all the outcomes are equally\n  likely.\n  Let $\\Omega = \\set{HH, HT, TH, TT}$ and $\\Uniform{\\Omega}$ be the\n  uniform distribution on $\\Omega$. Find the probability of the event \n  $\\set{HT, TH, TT}$, and give an informal interpretation of the answer.\n\\end{exercise}\n\n\\section{Basic Principles}\n\nEvents are subsets of the sample space; hence, they can be combined using the\nstandard set operations. So it is natural to ask whether the probabilities\n$\\Pr_{\\Distribution{D}}(A \\cup B)$ and $\\Pr_{\\Distribution{D}}(A \\cap B)$ can be\nexpressed in terms of $\\Pr_{\\Distribution{D}}(A)$ and $\\Pr_{\\Distribution{D}}(B)$.\n\n\\begin{theorem}[The Additive Principle]\n  Let $(\\Omega, \\Distribution{D})$ be a finite discrete probability space, and let $A, B\n  \\subseteq \\Omega$ be two disjoint events. Then \n  $\\Pr_{\\Distribution{D}}(A \\cup B) = \\Pr_{\\Distribution{D}}(A) +\n  \\Pr_{\\Distribution{D}}(B)$.\n\\end{theorem}\n\\begin{proof}[Proof Sketch, see \\Cref{theorem:additive-principle}]\n  Let $A = \\set{\\omega_{1, 1}, \\dots, \\omega_{1, k}}$ and \n  let $B = \\set{\\omega_{2, 1}, \\dots, \\omega_{2, \\ell}}$. \n  Then $A \\cup B = \\set{\\omega_{1, 1}, \\dots, \\omega_{1, k}, \n    \\omega_{2, 1}, \\dots, \\omega_{2, \\ell}}$.\n  Therefore $\\Pr_{\\Distribution{D}}(A \\cup B) = \n    \\Pr_{\\Distribution{D}}(\\omega_{1, 1}) + \\dots +\n    \\Pr_{\\Distribution{D}}(\\omega_{2, k}) +\n    \\Pr_{\\Distribution{D}}(\\omega_{2, 1}) + \\dots +\n    \\Pr_{\\Distribution{D}}(\\omega_{2, \\ell}) = \n    \\Pr_{\\Distribution{D}}(A) +\n    \\Pr_{\\Distribution{D}}(B)$.\n\\end{proof}\n\n\\begin{exercise}\n  Let $(\\Omega, \\Distribution{D})$ be a finite discrete probability space, and let $A\n  \\subseteq \\Omega$ be an event. Show that \n  $\\Pr_{\\Distribution{D}}(\\Omega \\setminus A) = 1 - \\Pr_{\\Distribution{D}}(A)$.\n\\end{exercise}\n\nThis result can be easily extended to the cases when $A$ and $B$ are not\ndisjoint.\n\\begin{corollary}[The Inclusion-exclusion Principle]\n\\label{corollary:inclusion-exclusion-probability}\n  Let $(\\Omega, \\Pr)$ be a finite discrete probability space, and let $A, B\n  \\subseteq \\Omega$ be two events. Then \n  $\\Pr_{\\Distribution{D}}(A \\cup B) = \\Pr_{\\Distribution{D}}(A) +\n   \\Pr_{\\Distribution{D}}(B) -\n   \\Pr_{\\Distribution{D}}(A \\cap B)$.\n\\end{corollary}\n\nUnfortunately, $\\Pr_{\\Distribution{D}}(A \\cap B)$ cannot be expressed via\n$\\Pr_{\\Distribution{D}}(A)$ and $\\Pr_{\\Distribution{D}}(B)$.\nHowever, in many cases $\\Pr_{\\Distribution{D}}(A \\cap B) =\n\\Pr_{\\Distribution{D}}(A) \\Pr_{\\Distribution{D}}(B)$; if this equality holds,\nwe say that $A$ and $B$ are \\emph{independent}.\n\nFor example, let us consider an experiment where we toss two fair coins; i.e.,\nlet us consider $\\Omega = \\set{HH, HT, TH, TT}$ and let\n$\\Uniform{\\Omega}$ be the uniform distribution on $\\Omega$. It is easy to\nsee that $\\Pr_{\\Uniform{\\Omega}}(\\set{HH, HT}) = 1 / 2$,\n$\\Pr_{\\Uniform{\\Omega}}(\\set{HH, TH}) = 1 / 2$, and\n$\\Pr_{\\Uniform{\\Omega}}(\\set{HH, HT} \\cap \\set{HH, TH}) =\n\\Pr_{\\Uniform{\\Omega}}(\\set{HH}) =  1 / 4$. Hence, these two events are\nindependent.\n\nTo analyze experiments consisting of tossing several coins, we need to be able\nto study products of finite discrete probability spaces.\n\\begin{theorem}[The Multiplicative Principle]\n\\label{theorem:multiplicative-principle-probability}\n  Let $\\Omega = \\Omega_1 \\times \\Omega_2$ and \n  let $(\\Omega_1, \\Distribution{D}_1)$ and\n  $(\\Omega_2, \\Distribution{D}_2)$ be finite discrete probability spaces. Then \n  $\\Distribution{D} : \\Omega \\to \\R$ such that \n  $\\Distribution{D}(\\omega_1, \\omega_2) = \n  \\Pr_{\\Distribution{D}_1}(\\omega_1) \\cdot \\Pr_{\\Distribution{D}_2}(\\omega_2)$\n  is a probability distribution on $\\Omega$.\n  Moreover, $\\Pr_{\\Distribution{D}}(E_1 \\times E_2) = \n  \\Pr_{\\Distribution{D}_1}(E_1) \\cdot \\Pr_{\\Distribution{D}_2}(E_2)$ for all \n  $E_1 \\subseteq \\Omega_1$ and $E_2 \\subseteq \\Omega_2$.\n\\end{theorem}\n\nUsing this principle we can show that in the experiment consisting of tossing\nfive coins, the event where the first flip is $H$ and the event where the second\nflip is $H$ are independent. Indeed, let $\\Omega = \\set{H, T}^5$; \n$\\Pr$ be the uniform distribution on $\\Omega$; and \n$E_1 = \\set[t_1 = H]{t \\in \\set{H, T}^5}$ and\n$E_2 = \\set[t_2 = H]{t \\in \\set{H, T}^5}$. By\n\\Cref{theorem:multiplicative-principle-probability},\n$\\Pr(E_1) = \\Pr(E_2) = 1 / 2$. Moreover, \n$E_1 \\cap E_2 = \\set[t_1 = H \\text{ and } t_2 = H]{t \\in \\set{H, T}^5}$;\ntherefore, $\\Pr_{\\Distribution{D}}(E_1 \\cap E_2) = \\frac{1}{4}$.\n\n\\section{Random Variables}\nSometimes we are more interested in some function of the result of the\nexperiment rather than the result itself. For example, Sasha may play Dungeons\nand Dragons and be interested in his chances to roll $7$ on two dice together.\nLet us formalize the question. Let $\\Omega = \\range{6}^2$ and $\\Pr$ be a the\nuniform distribution on $\\Omega$. Sasha is interested in the probability of the\nevent $\\set[x + y = 7]{(x, y) \\in \\range{6}^2}$.\n\nMore generally, let $(\\Omega, \\Distribution{D})$ be a finite discrete\nprobability space. Then a function $\\chi : \\Omega \\to \\R$ is called a\n\\emph{random variable} and\n$\\Pr_{\\Distribution{D}}(\\chi = a)$ denotes \n$\\Pr_{\\Distribution{D}}(\\set[\\chi(\\omega) = a]{\\omega \\in \\Omega})$. \n\nIn the example about Dungeons and Dragons, $\\chi(x, y) = x + y$ and \nwe are interested in $\\Pr_{\\Distribution{D}}(\\chi = 7) = \n\\Pr_{\\Distribution{D}}(\\set{(1, 6), (2, 5), \\dots, (6, 1)} = 1 / 6$.\n\\begin{exercise}\n  Let $\\Omega = \\range{6}^2$ and $\\Uniform{\\Omega}$ be the uniform distribution\n  on $\\Omega$. Let $\\chi : \\Omega \\to \\R$ be the random variable such that \n  $\\chi(x, y) = x + y$. Find $\\Pr_{\\Uniform{\\Omega}}(\\chi = 1)$, \\dots,\n  $\\Pr_{\\Uniform{\\Omega}}(\\chi = 12)$.\n\\end{exercise}\n\nWe are going to adopt some simple additional notation, if \n$\\chi_1, \\chi_2 : \\Omega \\to \\R$ are random variables then \n$(\\chi_1 + \\chi_2), (\\chi_1 \\cdot \\chi_2) : \\Omega \\to \\R$ are the random\nvariables such that $(\\chi_1 + \\chi_2)(\\omega) = \\chi_1(\\omega) +\n\\chi_2(\\omega)$ and $(\\chi_1 \\cdot \\chi_2)(\\omega) = \\chi_1(\\omega) \\cdot\n\\chi_2(\\omega)$.\n\n\\begin{chapterendexercises}\n  \\exercise Prove \\Cref{corollary:inclusion-exclusion-probability}.\n  \\exercise Let $\\Omega = \\set{HH, HT, TH, TT}$ and let $\\Uniform{\\Omega}$ be\n    the uniform distribution on $\\Omega$. Show that $\\set{HH}$ and $\\set{TT}$\n    are not independent.\n  \\exercise Alice is rolling a dice $n$ times, compute the probability\n    that Alice sees $6$, $6$, and $6$ in three consecutive rolls.\n  \\exercise Alice is rolling a dice $n$ times, compute the probability\n    that Alice sees $4$, $5$, and $6$ in three consecutive rolls.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "603367d5a56527113074bc9fa4a16098cc6d2069", "size": 9224, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_3/chapter_14_sample_space.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_3/chapter_14_sample_space.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_3/chapter_14_sample_space.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": 50.6813186813, "max_line_length": 88, "alphanum_fraction": 0.6897224631, "num_tokens": 2925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.682592302889235}}
{"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)}$ Use recursive relation to compute\n$\\Expect(X_i)$.\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: $X \\sim \\text{Exp}(\\lambda) \\equiv \\text{Gamma}(1, \\lambda)$\n\n$\nf(x) = \\lambda e^{-\\lambda x},\n\\quad x > 0\n\\qquad \\Expect X = \\frac{1}{\\lambda},\n\\quad \\Var X = \\frac{1}{\\lambda ^2}\n$\n\nCDF $F(x) = 1 - e^{-\\lambda x}$\n\n\\textbf{Chi square}\nSpecial case: $X \\sim \\chi^2_n \\equiv \\text{Gamma}(\\frac{n}{2}, \\frac{1}{2})$\n\n$\nf(x) \\propto x^{\\frac{n}{2} - 1} e^{\\frac{-x}{2}},\n\\quad x > 0\n\\qquad \\Expect X = n,\n\\quad \\Var X = 2n\n$\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\n\\textbf{Transformations} If $g$ 1:1 with continuous derivatives and nonzero\nJacobian, and $Y = g(X)$, then the density\n\\[\n    f_Y(y) = f_X(g^{-1}(y)) |J_{g^{-1}}(y)|\n\\]\nFor affine transformation $Y = AX + c$ then \n\\[\n    f_Y(y) = f_X(A^{-1}(y - c)) |\\det A|^{-1}\n\\]\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\\section*{TODO - add measure theory}\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\\subsection*{Asymptotics}\n\n\\textbf{Almost Sure convergence}\n\\[\n    X_n \\xrightarrow{a.s.} X \\quad \\text{means} \\quad P(X_n \\rightarrow X)\n    = 1\n\\]\nTheorem: $\\iff P(\\sup_{m \\geq n} |X_m - X| > \\epsilon) \\rightarrow 0\n\\quad \\forall \\epsilon > 0$.\n\n\\textbf{Convergence in Probability}\n\\[\n    X_n \\xrightarrow{p} X\n\\]\nmeans that $P( |X_n - X| > \\epsilon ) \\rightarrow 0$ for all $\\epsilon > 0$.\n\n\\textbf{Generalized Chebychev Inequality}\nLet $X$ be a r.v. and $g$ be a\nnonnegative function increasing on the range of $X$. Then\n\\[\n    P(X \\geq a) \\leq \\frac{\\Expect g(X)}{g(a)}\n\\]\n\n\\textbf{Borel Cantelli Lemma}\n\n\\textbf{Hoeffding Inequality}\nLet $X_1, \\dots, X_n$ be independent (not necessarily iid) with $a_i \\leq\nX_i \\leq b_i$ and $\\Expect X_i = 0$. Then \n\\[\n    P \\left( \\sum_{i=1}^n X_i \\geq \\eta \\right) \\leq \n    \\exp \\left\\{ -\\frac{2\\eta^2}{\\sum_{i=1}^n (b_i - a_i)^2} \\right\\}\n\\]\n\n\\newpage\n\\subsection*{Multivariate Normal}\n\nlog likelihood for $k$ vector $x \\sim N(\\mu, \\Sigma)$\n\\[\n    l_x = -\\frac{k}{2} \\log 2 \\pi - \\frac{1}{2}\n    \\{ \\log \\det \\Sigma + (x - \\mu)^T \\Sigma^{-1} (x - \\mu) \\}\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\\]\nInvert $2 \\times 2$ matrix:\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\nSum identities:\n\\[\n    \\sum_{k=0}^{\\infty} p^k = \\frac{p}{1 - p} \\qquad \n    \\sum_{k=0}^{\\infty} k p^k = \\frac{p}{(1 - p)^2} \\qquad |p| < 1\n\\]\n\nIntegration by parts:\n\\[\n    \\int uv' = uv - \\int u'v\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$\\frac{\\partial}{\\partial \\theta_i} \\log (|A|) =\ntr( A^{-1} \\frac{\\partial A}{\\partial \\theta_i}$)\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Linear Models}\n\nLeast Squares Principle\n\\[\n    \\text{arg min}_\\beta \\norm{Y - X\\beta}^2\n\\]\n\nNormal Model \n\\[\n    Y = X\\beta + \\epsilon, \\qquad \\epsilon \\sim N(0, \\sigma^2 I)\n\\]\n\nNormal Equations - Any $b$ satistfying this solves the least squares\n\\[\n    X^T X b = X^T y\n\\]\n\nGauss Markov Theorem - $\\hat{\\beta}$ is Best Linear Unbiased\nEstimator (BLUE) of $\\beta$.\n\\[\n    \\hat{\\beta} = (X^T X)^{-1} X^T y \\sim N(\\beta, \\sigma^2 (X^T X)^{-1})\n\\]\n\nEstimating the variance: $\\frac{\\norm{y - X \\hat{\\beta}}^2}{\\sigma^2} \\sim\n\\chi^2_{n-p}$.\n\\[\n    \\hat{\\sigma}^2 = \\frac{\\norm{y - X \\hat{\\beta}}^2}{n - p}\n\\]\n\nUse t test for hypothesis testing and confidence intervals for the value of\na particular $\\beta_j$ coefficient. \nLet $w_{ii}$ be the $i$th diagonal entry of $(X^T X)^{-1}$.\n\\[\n    \\frac{\\beta_j - \\beta_j^*}{\\hat{\\sigma} \\sqrt{w_{ii}}} \\sim t_{n-p}\n\\]\n$1 - \\alpha$ Confidence intervals for new observation $Y_h$ at $x_h$ and $E[Y_h]$:\n\\[\n    E[y_h] \\approx \\hat{y_h} \\pm t(n-p, 1 - \\frac{\\alpha}{2}) \\hat{\\sigma}\n        \\sqrt{x_h^T (X^T X)^{-1} x_h}\n\\]\n\\[\n    y_h \\approx \\hat{y_h} \\pm t(n-p, 1 - \\frac{\\alpha}{2}) \\hat{\\sigma}\n        \\sqrt{1 + x_h^T (X^T X)^{-1} x_h}\n\\]\nSimultaneous (Working-Hotelling) confidence interval for $\\Expect (y_h)$:\n\\[\n    \\hat{y}_h \\pm \\sqrt{p F_{p, n - p, 1 - \\alpha}} se\\{ \\hat{y}_h \\}\n\\]\n\\[\n    \\frac{(\\hat{\\beta} - \\beta)^T X^T X (\\hat{\\beta} - \\beta) /\n    p}{\\hat{\\sigma}^2}\n    \\sim F_{p, n - p}\n\\]\n\nGeneral linear tests. Partition $\\beta = (\\beta_1, \\beta_2)$ where $\\beta_1$\nis an $r$ vector and $\\beta_2$ is $p - r$. Null hypothesis $H_0: \\beta_2 =\n\\beta_2^*$ (often 0), and $H_a: \\beta_2 \\neq \\beta_2^*$. Then\n$SSE_r = \\norm{y - X_2 \\beta_2^* - X_1 \\tilde{\\beta_1}}^2$ is the sum of\nsquared error for the reduced model and \n$SSE_f = \\norm{y - X \\hat{\\beta}}^2$ is the squared sum of error for the\nfull model.\nUnder $H_0$:\n\\[\n    \\frac{\\frac{SSE_r - SSE_f}{p - r}}\n         {\\frac{SSE_f}{n - p}}\n         \\sim F_{p-r, n-p}\n\\]\n\nAlternate forms of linear test, and testing a linear combination if $R\\beta\n= r$, for $R$ full rank $s \\times p$ matrix.\n\\[\n    \\frac{(R \\hat{\\beta} - r)^T (R(X^T X)^{-1} R^T)^{-1} (R \\beta - r) / s}\n    {\\hat{\\sigma}^2} \\sim F_{s, n-p}\n\\]\n\n\n\\subsection*{Model selection and diagnostics}\n\n$SSTO = \\sum_{i=1}^n (y_i - \\bar{y}) = \\norm{y - \\bar{y} 1_n }^2\n        = \\norm{(I - J)y}^2$\n\n$SSR = \\sum_{i=1}^n (\\hat{y}_i - \\bar{y}) = \\norm{\\hat{y} - \\bar{y} 1_n}^2\n    = \\norm{(H - P)y}^2$\n\n$SSE = \\sum_{i=1}^n (y_i - \\hat{y}_i) = \\norm{y - \\hat{y}}^2\n        = \\norm{(I - H)y}^2$\n\nIf the model contains the intercept in the column space of $X$  then $SSTO = SSR + SSE$.\n\n$R^2 = 1 - \\frac{SSE}{SSTO}$\n\nAdjusted $R^2_a = 1 - \\frac{SSE / (n-p)}{SSTO / (n-1)}$\n\n$AIC = n \\log SSE + 2p$\n\n$BIC = n \\log SSE + p \\log n$\n\n$Cp = \\frac{SSE}{MSE} - (n - 2p)$\n\nResiduals: $\\hat{\\epsilon}_i = y_i - \\hat{y}_i$\n\nStudentized residuals (\\texttt{rstandard} in R): \n\\[\n    \\gamma_i =\n    \\frac{\\hat{\\epsilon}_i}{ s \\{ \\hat{\\epsilon}_i \\} } = \n    \\frac{\\hat{\\epsilon}_i}{\\hat{\\sigma} \\sqrt{1 - h_{ii}}}\n\\]\n\nPrediction sum of squares (PRESS) is the same as leave one out cross\nvalidation (LOOCV). Prediction error on $i$th observation is called deleted\nresiduals:\n\\[\n    y_i - \\hat{y}_{i (-i)} = \\frac{y_i - \\hat{y}_i}{1 - H_{ii}}\n\\]\nWorks for ridge regression also, letting \n$H = X(X^T X + \\lambda I)^{-1} X^T$.\n\nStudentized deleted residuals: \n\\[\n    t_i = \\frac{\\hat{\\epsilon}_i}{\\sqrt{MSE_{(-i)} (1 - h_{ii})}} \\sim t_{n - p -1}\n\\]\nWhere $MSE_{(-i)} = SSE_{(-i)} / (n - 1 - p)$ and\n$SSE_{(-i)} = SSE - \\frac{\\hat{\\epsilon}_i}{1 - h_{ii}}$ can be used to\ncalculate without refitting model.\n\n\\subsection*{ANOVA}\n\nThree principles of experimental design: 1) Replication 2) Randomization 3)\nBlocking\n\nOne way ANOVA with $n$ total observations, $K$ groups:\n\n{\n\\centering\n\\begin{tabular}{lll}\n    SS   &  & DF     \\\\\n    SSTR & $\\sum_{j=1}^K n_j (\\bar{y_{j \\cdot}} - \\bar{y_{\\cdot \\cdot}})^2$  & K - 1 \\\\\n    SSE  & $\\sum_{i=1}^n (y_{ij} - \\bar{y_{j \\cdot}})^2$  & n - K \\\\\n    SSTO & $\\sum_{i=1}^n (y_{ij} - \\bar{y_{\\cdot \\cdot}})^2$  & n - 1 \n\\end{tabular}\n}\n\nContrasts are sums of the form $\\Phi = \\sum_{i=1}^K c_i \\mu_i$ with\n$\\sum_{i=1}^K c_i = 0$.\nTukey's works for all pairwise contrasts.\nScheffe's and extended Tukey works for all contrasts.\nBonferroni's is for a limited number of pre specified contrasts.\n\n\\textbf{Ridge Regression} for $\\lambda > 0$ solves\n\\[\n    \\min_\\beta ||Y - X\\beta||^2 + \\lambda ||\\beta||^2\n\\]\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\textbf{Linear mixed models}\n\\[\n    y = X \\beta + Z \\alpha + \\epsilon\n\\]\nStandard assumptions:\n\n$\\Expect ( \\alpha) = 0$, $\\Expect ( \\epsilon) = 0$,\n$\\Cov(\\epsilon, \\alpha) = 0$\n\n$\\alpha \\sim N(0, G), \\epsilon \\sim N(0, R)$ are jointly normal.\n\nMarginal model $y \\sim N(X \\beta, V)$ where $V = R + ZGZ'$.\n\nThe idea of reduced maximum likelihood (REML) is to first estimate the random components of the model.\nThis is done through a transformation of the data to create a new model\ncontaining only the random components, and no fixed components.\n\nLet $\\xi = b' \\beta + a' \\alpha$ be a mixed effect. These are what we're\ninterested in estimating. We call them predictions rather than estimations\nbecause we're predicting a random component.\n\nBLUE - Best linear unbiased estimator, \n$\\tilde{\\beta} = (X' V^{-1} X)^{-1} X' V^{-1} y$. This is the MLE of\n$\\beta$.\n\nBP - Best predictor, $\\Expect (\\xi | y) = b' \\beta + a' G Z' V^{-1} (y - X\n\\beta)$ a theoretical ideal that's\nusually difficult or impossible to derive.\n\nBLUP - Best linear predictor, which plugs in $\\tilde{\\beta}$ into BP.\n\nEBLUP - Empirical best linear predictor, plugs in $\\hat{\\theta}$. This is\ntypically the one we compute and use.\n\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Applied Lectures - 232B}\n\n4 Jan - Matrix form for linear mixed model, assumptions\n\n6 Jan - Examples mixed models, time series, non gaussian, marginal, max\nlikelihood estimation, REML\n\n11 Jan - Lambs example, parametric bootstrap\n\n13 Jan - Asymptotic covariance matrix of fixed effects $\\hat{\\beta}$,\ncomputing examples\n\n18 Jan - Holiday\n\n20 Jan - Mixed model prediction, BP, BLUE, BLUP, example algebra in\ndiscussion\n\n25 Jan - Empirical BLUP, Fay Herriot model, jackknife\n\n27 Jan - EBLUP for random effects, intro to GLM's\n\n1 Feb - GLMM with several examples, Monte carlo and the E-M algorithm,\nimportance sampling\n\n3 Feb - Rejection sampling, Markov Chain Monte Carlo (MCMC), Markov chain\nconvergence theorem, Gibb's Sampler\n\n8 Feb - Gibbs Sampler, transition kernel, MCMC, threshold model, data\ncloning\n\n10 Feb - Midterm\n\n\\subsection*{Math Lectures - 231B}\n\n4 Jan - Maximum likelihood, determining MLE\n\n6 Jan - Normal examples MLE, constraints, MLE of pdf $f$ decreasing on $[0,\n    \\infty)$.\n\n11 Jan - MLE maximizing $\\Expect l_X (\\theta_0)$, KL divergence and\nproperties, M estimation\n\n13 Jan - least squares and mean absolute deviation (MAD) as examples of m\nestimators, existence and uniqueness theorems for optimization, review of\nexponential families\n\n18 Jan - Holiday\n\n20 Jan - Existence and uniqueness of MLE for canonical and curved\nexponential families, review convexity\n\n25 Jan - Long proof of existence and uniqueness of MLE\n\n27 Jan - Z estimation aka estimating equation estimation, method of\nmoments, gamma example, plug in principle\n\n1 Feb - Asymptotics, modes of convergence and associated theorems,\nBorel-Cantelli lemma, generalized Chebyshev\n\n3 Feb - Hoeffding's inequality and proof, strong, weak, and uniform\nconsistency\n\n8 Feb - Consistency theorem for MLE's in canonical exp families,\nconsistency of M estimator\n\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Applied Lectures - 232A}\n\n30 Nov - Outliers in x and y, leverage, DFFITS, cook's distance, influence\nplot, add variable plot, robust regression\n\n25 Nov - Model selection criteria, deleted residuals, forward and backward\nselection in lab\n\n23 Nov - BIC, AIC derivations, Mallow's cp, stepwise selection algorithms,\noutliers and studentized residuals\n\n18 Nov - F test with orthogonalized X, model selection criteria,\nbootstrap t method in lab\n\n16 Nov - Multicollinearity, Variance Inflation Factor,\nridge regression, bias variance tradeoff, AIC, BIC, cross validation, proof leave\none out cross validation formula for OLS \n\n11 Nov - Holiday\n\n9 Nov - Linear model with random $X$, transformations of $y$ and $X$, box\ncox procedure, bootstrap with percentile-t and fixed $X$ sampling, weighted\nleast squares\n\n4 Nov - Interaction plots for two way ANOVA with balanced design, Linear\nmodels with random $X$\n\n2 Nov - Midterm\n\n28 Oct - Kronecker product formulae for two way ANOVA\n\n26 Oct - Kronecker product 1 way ANOVA, decomposition of two way ANOVA,\nnoncentral $\\chi^2$ distributions for ANOVA table SSA, SSB, SSAB\n\n21 Oct - Tukey's method for pairwise contrasts, Bonferroni's method,\ndefinition and properties of Kronecker product\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Math Lectures - 231A}\n\n30 Nov - Bayesian inference, risk, decision rules, conjugate families,\nBinomial, normal examples\n\n25 Nov - Exponential families, GLM's, full rank exp families, decision\ntheory, Bayes risk\n\n23 Nov - Fisher information, Cramer Rao inequality, Exponential families\nand properties\n\n18 Nov - Rao-Blackwell theorem, Lehmann-Scheffe theorem, UMVUE examples for\nnormal, uniform, Poisson, Fisher information\n\n16 Nov - Minimal sufficiency, likelihood ratio, ancillary statistics,\ncompleteness, Basu's theorem, loss functions\n\n11 Nov - Holiday\n\n9 Nov - Distribution of order statistics, factorization theorem, sufficient\nstatistics for Exponential families and uniform dist\n\n4 Nov - Midterm\n\n2 Nov - Location-scale families, invariance, ancillary and sufficient\nstatistics, order statistics, multinomial distribution\n\n28 Oct - Transformation of discrete and continuous random variables,\nJacobian, examples with beta distributions, Dirichlet distribution\n\n26 Oct - Jensen's and Holder's inequality, convex functions and sets,\nproducts of normal random variables\n\n21 Oct - Convolution formula, examples with Uniform, Gamma, Poisson,\nmarginal and conditional distributions for multivariate normal\n\\newpage\n\n\\subsection*{Problem Solving Strategies}\n\n\\textbf{Read the whole question}\n\nRead carefully and do the right problem! If there's a hint, it should\nprobably be used. Early parts of a question can help for later parts, and later\nparts occasionaly provide insight for earlier parts.\n\n\\textbf{First principles}\n\nWhen in doubt, work from definitions.\n\n\\textbf{Look for Distributions} \n\nCan the question be solved by knowing the distribution of some\nquantity?  Ex: $\\sum (x_i - \\bar{x})^2$ is $\\chi^2_{n-1}$ for\n$x_i \\sim N(\\mu, 1)$.\n\n\\textbf{Fast and correct algebra}\n\nBetter to write more than to make a simple algebra mistake.\nPractice common manipulations so don't have to think about them\nwhen testing.\n\n\\begin{table}[]\n    \\centering\n    \\caption{Problems in past 231 exams - Came from a brief glance at the\n    question statements. TODO- make second updated table after solving\n    questions that shows which techniques are used.}\n    \\label{231problems}\n    \\begin{tabular}{rl}\n\n        Binomial                & ******* \\\\\n        Poisson                 & ****** \\\\\n        Uniform                 & ****** \\\\\n        Normal                  & ****** \\\\\n        Gamma                   & *** \\\\\n        Exponential             & ** \\\\\n        Negative binomial       & * \\\\\n        Beta                    & * \\\\\n        Geometric               & * \\\\\n        MLE                     & ************* \\\\\n        asymptotic distribution & *********** \\\\\n        Bayes estimator / risk  & ********** \\\\\n        UMVUE / Cramer-Rao      & ********* \\\\\n        minimiax                & ****** \\\\\n        UMP test                & ****** \\\\\n        linear regression       & ***** \\\\\n        likelihood ratio        & **** \\\\\n        Wald's test             & *** \\\\\n        sufficient statistic    & ** \\\\\n        Hierarchical model      & * \\\\\n        method of moments       & * \\\\\n        hypothesis testing      & * \\\\\n        order statistics        & * \\\\\n\n    \\end{tabular}\n\\end{table}\n\n\\end{document}\n", "meta": {"hexsha": "338b9f2cfc994aa76f8e3f202187506330605fb1", "size": 26424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "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": "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": "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": 28.2006403415, "max_line_length": 102, "alphanum_fraction": 0.6123599758, "num_tokens": 8926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6825922922886225}}
{"text": "\\problemname{Jumbled Communication}\n\n\\illustration{0.4}{SDC10461-scaled.jpg}{\\copyright{} NWERC Jury}%\nYour best friend Adam has recently bought a Raspberry Pi and some equipment, including a wireless temperature sensor and a 433MHz receiver to receive the signals the sensors sends.\nAdam plans to use the Raspberry Pi as an in-door display for his weather sensor.\nAs he is very good with electronics, he quickly managed to get the receiver to receive the signals of the sensor.\nHowever, when he looked at the bytes sent by the sensor he could not make heads or tails of them.\nAfter some hours looking through a lot of websites, he found a document explaining that his weather sensor scrambles the data it sends, to prevent it from being used together with products from other manufacturers.\n\nLuckily, the document also describes how the sensor scrambles its communication.\nThe document states that the sensor applies the expression \\verb|x ^ (x << 1)|\nto every byte sent.  The \\verb|^| operator is bit-wise XOR\\footnote{In bit-wise\nXOR, the $i$th bit of the result is $1$ if and only if exactly one of the two\narguments has the $i$th bit set.}, e.g., $\\verb|10110000 ^ 01100100| =\n\\verb|11010100|$.\nThe \\verb|<<| operator is a (non-circular) left shift of a byte value\\footnote{In\n\\texttt{x <{}< $j$}, the bits of \\texttt{x} are moved $j$ steps to the left.\nThe $j$ most significant bits of $x$ are discarded, and $j$ zeroes are added\nas the least significant bits of the result.}, e.g.,\n$\\verb|10111001 << 1| = \\verb|01110010|$.\n\nIn order for Adam's Raspberry Pi to correctly interpret the bytes sent by the weather sensor, the transmission needs to be unscrambled.\nHowever, Adam is not good at programming (actually he is a pretty bad programmer). So he asked you to help him and as a good friend, you are always happy to oblige.\nCan you help Adam by implementing the unscrambling algorithm?\n\n\n\\section*{Input}\n\nThe input consists of:\n\\begin{itemize}\n\\item one line with an integer $n$ ($1 \\le n \\le 10^5$), the number of bytes in the message sent by the weather sensor;\n\\item one line with $n$ integers $b_1, \\ldots, b_n$ ($0 \\leq b_i \\leq 255$ for all $i$), the byte values of the message.\n\\end{itemize}\n\n\\section*{Output}\n\nOutput $n$ byte values (in decimal encoding), the unscrambled message.\n", "meta": {"hexsha": "668669554cfc82a34076299f2ca84c0a3d103795", "size": 2300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/jumbledcommunication/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/jumbledcommunication/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/jumbledcommunication/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": 60.5263157895, "max_line_length": 214, "alphanum_fraction": 0.7543478261, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.6825922903852178}}
{"text": "%!TEX root =  ../main.tex\n\\subsection{Growth}\n\n\\objective{Model and predict year-over-year percentile growth}\n\n\nIn linear equations, everything is relative to the number 0.  Have a derivative or slope \nof 0 constitutes a flat line.  Numbers greater than 0 are called positive slope, while\nnumbers less than it are called negative slope.  If the initial value is not 0, then it is\nadded to the equation, unlike the slope, which is multiplied against the independent\nvariable.\n\nEverything about exponential equations is moved to the next level of operators.  We saw\nback in §1.4 that the standard form of an exponential equation is $y=a\\cdot{}b^x$.\nAll such equations begin at the point $(0,a)$, because plugging in 0 yields $b^0$\nand regardless of what $b$ is, anything to the zero power is 1.  Multiplying by $a$ \ntherefore changes our initial value.  And because powers are simply repeated multiplication,\nhave $b$ as a base means the equation multiplies by $b$ every unit step of $x$.\n\nWhat if $b=1$?  No matter what exponent we put on 1, it will remain 1.  If $b>1$,\nthen every increment of $x$ will grow the output.  If $b<1$, then every increment\nof $x$ will reduce the output.  Because exponential equations are build off of \nmultiplication --- not addition --- everything is relative to 1, not 0.\n\nHopefully, you are very familiar with percentages, and how even the word comes\nfrom the Latin \\textit{``out of one hundred''}.  This give us the clue to convert\npercentages to decimals: divide by 100.  So if a mathematical model verbally says a \nsystem is growing at 5\\%, means that any given year, the value is 105\\% of the\nvalue from the year before.  This means $b$ in our equation is $1.05$.  Were we \nto use a $b$ of $0.05$, that would be a 95\\% loss year-over-year!\n\n\\subsubsection{TI-8*}\nThe TI-8* is a very useful tool for modeling exponential growth.  In many \nreal-life situations, everything takes place in QI, but the $y$-scale often\nvaries greatly from problem to problem.  For example, what is a good\nwindow for the following problem?  A house was purchases for \\$500,000\nand appreciates 3.2\\% per year.  What is its future value in 5, 10, and 30\nyears?  When will it exceed 2 million dollars?\n\nBecause this is a strictly increasing function, the value at the beginning will be \nthe lowest.  This means our Xmin and Ymin should be 0 and 500000 respectively.\nWe know we need to see at least to the year 30, so our Xmax must be at least that,\nand our Ymax must be at least 2000000.  These turn out to be overly conservative\nestimates, but they help us see how to guess.  The TABLE is also very useful in\nsetting up windows.\n\n\\subsection{Compound Interest}\nIn most banking institutions, money moves hands and changes more often than once\na year, so interest is compounds (or calculated) more often.  If you are making\nfive percent per annum, but the bank compounds monthly, that does not mean you\nmake 5\\% twelve times a year!   Instead, they give you a twelfth of 5\\% twelve times\nper year.  This makes our equation more complicated:\n\n$$\nA = P\\left(1+\\frac{r}{n}\\right)^{n\\cdot{}t}\n$$\n\n$A$ is the amount at the end of the term, $P$ is the principle which the investment began\nat (the initial amout of money), $r$ is the interest rate, $n$ is the number of times per year\nit is compounded, and $t$ is the number of years the investment is left in.  If banks think\nin terms of periods (be they month, quarters, years, etc.) then the exponent is the number\nof periods the money is left in.\n\n\n\\subsection{Doubling Time}\nHow can we build an equation when we don't know the rate of growth, except as a time?\nFor example, suppose your grandfather noticed that movie theater prices have doubled \nevery eight years.  When he was a kid, it was a quarter!  One way would be to generate\nnumerical data and run a regression on them.  Let $x$ be years since your grandfather\nwas a kid.  You know $a$ is 0.25, a quarter dollar.  So far, we have $y=\\frac{1}{4}b^x$.\nWe know every eight years, the price has doubled, so that makes points (8,0.5) ; (16,1)\n; (24,2), etc.  The TI-8*'s EXPREG yields $y=0.25(1.090507733)^x$.\n\nAnother way might be to recognize that we want to be multiplying by 2 every time (since\nwe are talking about doubling) but that only every 8 years should it happen.\n$y=\\frac{1}{4}2^x$ would double every day, so dilate the function to be 8 times wider:\n$y=\\frac{1}{4}2^\\frac{x}{12}$.  This shows us that the same exponential function\ncan have multiple (in fact, infinite number of) representations.\n\n\\paragraph{e}\nWe will not explain its origin until next chapter, but you should know that many (if not most)\nexponential equations involve the number $e$.  Like $\\pi$, it is around 3, only $e$ is a little less,\nnot a little more.  You can find $e$ on your TI-8* as 2ND $\\div$, or the more useful $e^x$\nas 2ND-LN.", "meta": {"hexsha": "88ba4c75dabd43bce88612a2f23fdfdd6fabfd36", "size": 4834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch07/0702.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch07/0702.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch07/0702.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": 57.5476190476, "max_line_length": 101, "alphanum_fraction": 0.7451386016, "num_tokens": 1319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6825922844112303}}
{"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\\section{Elastic Deformation}\n\\label{ELASTIC CHAP}\nIn this section we want to examine the deformation of a linear elastic body caused by expansion through a heat distribution.\nWe want a displacement field $u_{i}$ which solves the momentum\nequation\\index{momentum equation}:\n\\begin{eqnarray}\\label{HEATEDBLOCK general problem}\n - \\sigma_{ij,j}=0\n\\end{eqnarray}\nwhere the stress $\\sigma$ is given by\n\\begin{eqnarray}\\label{HEATEDBLOCK linear elastic}\n \\sigma_{ij}= \\lambda u_{k,k} \\delta_{ij} + \\mu ( u_{i,j} + u_{j,i})\n - (\\lambda+\\frac{2}{3} \\mu)  \\; \\alpha  \\;  (T-T_{ref})\\delta_{ij} \\;.\n\\end{eqnarray}\nIn this formula $\\lambda$ and $\\mu$ are the Lam\\'e coefficients, $\\alpha$ is the\ntemperature expansion coefficient, $T$ is the temperature distribution and $T_{ref}$ a reference temperature.\nNote that \\eqn{HEATEDBLOCK general problem} is similar to \\eqn{WAVE general problem}\nintroduced in \\Sec{WAVE CHAP} but the inertia term $\\rho u_{i,tt}$\nhas been dropped as we assume a static scenario here.\nMoreover, in comparison to the \\eqn{WAVE stress} definition of stress $\\sigma$\nin \\eqn{HEATEDBLOCK linear elastic} an extra term is introduced to bring in\nstress due to volume changes through temperature dependent expansion.\n\nOur domain is the unit cube\n\\begin{eqnarray} \\label{HEATEDBLOCK natural location}\n\\Omega=\\{(x_{i}) | 0 \\le x_{i} \\le 1 \\}\n\\end{eqnarray}\nOn the boundary the normal stress component is set to zero\n\\begin{eqnarray} \\label{HEATEDBLOCK natural}\n\\sigma_{ij}n_{j}=0\n\\end{eqnarray}\nand on the face with $x_{i}=0$ we set the $i$-th component of the displacement to $0$:\n\\begin{eqnarray} \\label{HEATEDBLOCK constraint}\nu_{i}(x)=0 & \\mbox{ where } & x_{i}=0 \\;\n\\end{eqnarray}\nFor the temperature distribution we use\n\\begin{eqnarray} \\label{HEATEDBLOCK temperature}\nT(x)= T_{0} e^{-\\beta \\|x-x^{c}\\|}\n\\end{eqnarray}\nwith a given positive constant $\\beta$ and location $x^{c}$ in the domain.\n\n%Later in \\Sec{MODELFRAME} we will use\n% $T$ from a time-dependent temperature diffusion problem as discussed in \\Sec{DIFFUSION CHAP}.\nWhen we insert \\eqn{HEATEDBLOCK linear elastic} we get a second order system\nof linear PDEs for the displacements $u$ which is called the Lam\\'e equation\\index{Lam\\'e equation}.\nWe want to solve this using the \\LinearPDE class.\nFor a system of PDEs and a solution with several components the \\LinearPDE class takes PDEs of the form\n\\begin{equation}\\label{LINEARPDE.SYSTEM.1 TUTORIAL}\n-(A_{ijkl} u_{k,l})_{,j}=-X_{ij,j} \\; .\n\\end{equation}\n$A$ is a \\RankFour and $X$ is a \\RankTwo.\nWe show here the coefficients relevant for the problem we are trying to solve.\nThe full form is given in \\eqn{LINEARPDE.SYSTEM.1}.\nThe natural boundary conditions\\index{boundary condition!natural} take the form\n\\begin{equation}\\label{LINEARPDE.SYSTEM.2 TUTORIAL}\nn_{j} A_{ijkl} u_{k,l}=n_{j}X_{ij}\n\\end{equation}\nwhile constraints\\index{constraint} take the form\n\\begin{equation}\\label{LINEARPDE.SYSTEM.3 TUTORIAL}\nu_{i}=r_{i} \\mbox{ where } q_{i}>0\n\\end{equation}\n$r$ and $q$ are each a \\RankOne.\nWe can easily identify the coefficients in \\eqn{LINEARPDE.SYSTEM.1 TUTORIAL}:\n\\begin{eqnarray}\\label{LINEARPDE ELASTIC COEFFICIENTS}\nA_{ijkl}=\\lambda \\delta_{ij} \\delta_{kl} + \\mu (\n\\delta_{ik} \\delta_{jl}\n+ \\delta_{il} \\delta_{jk}) \\\\\nX_{ij}=(\\lambda+\\frac{2}{3} \\mu) \\;  \\alpha \\; (T-T_{ref})\\delta_{ij} \\\\\n\\end{eqnarray}\nThe characteristic function $q$ defining the locations and components where constraints are set is given by:\n\\begin{equation}\\label{HEATEDBLOCK MASK}\nq_{i}(x)=\\left\\{\n\\begin{array}{cl}\n1 & x_{i}=0\\\\\n0 & \\mbox{otherwise.}\\\\\n\\end{array}\n\\right.\n\\end{equation}\nUnder the assumption that $\\lambda$, $\\mu$, $\\beta$ and $T_{ref}$\nare constant we may use $Y_{i}=(\\lambda+\\frac{2}{3} \\mu) \\; \\alpha \\; T_{i}$.\nHowever, this choice would lead to a different natural boundary condition\nwhich does not set the normal stress component as defined in \\eqn{HEATEDBLOCK linear elastic} to zero.\n\nAnalogous to the concept of symmetry for a single PDE, we call the PDE\ndefined by \\eqn{LINEARPDE.SYSTEM.1 TUTORIAL} symmetric\\index{symmetric PDE} if\n\\begin{eqnarray}\\label{LINEARPDE.SYSTEM.SYMMETRY TUTORIAL}\nA_{ijkl} =A_{klij} \\\\\n\\end{eqnarray}\nThis Lam\\'e equation is in fact symmetric, given the difference in $D$ and $d$ as compared to the scalar case.\nThe \\LinearPDE class is notified of this fact by calling its \\method{setSymmetryOn} method.\n\nAfter we have solved the Lam\\'e equation we want to analyse the actual stress distribution.\nTypically the \\emph{von-Mises} stress\\index{von-Mises stress} defined by\n\\begin{equation}\n\\sigma_{mises} = \\sqrt{\n\\frac{1}{2} ((\\sigma_{00}-\\sigma_{11})^2\n            + (\\sigma_{11}-\\sigma_{22})^2\n            + (\\sigma_{22}-\\sigma_{00})^2)\n+ 3( \\sigma_{01}^2+\\sigma_{12}^2+\\sigma_{20}^2) }\n\\end{equation}\nis used to detect material damage.\nHere we want to calculate the von-Mises stress and write it to a file for visualization.\n\nThe following script, which is available in \\file{heatedblock.py} in the\n\\ExampleDirectory, solves the Lam\\'e equation and writes the displacements and\nthe von-Mises stress\\index{von-Mises stress} into a file \\file{deform.vtu} in\nthe \\VTK file format\\index{scripts!\\file{diffusion.py}}:\n\\begin{python}\n  from esys.escript import *\n  from esys.escript.linearPDEs import LinearPDE\n  from esys.finley import Brick\n  from esys.weipa import saveVTK\n  #... set some parameters ...\n  lam=1.\n  mu=0.1\n  alpha=1.e-6\n  xc=[0.3, 0.3, 1.]\n  beta=8.\n  T_ref=0.\n  T_0=1.\n  #... generate domain ...\n  mydomain = Brick(l0=1., l1=1., l2=1., n0=10, n1=10, n2=10)\n  x=mydomain.getX()\n  #... set temperature ...\n  T=T_0*exp(-beta*length(x-xc))\n  #... open symmetric PDE ...\n  mypde=LinearPDE(mydomain)\n  mypde.setSymmetryOn()\n  #... set coefficients ...\n  C=Tensor4(0., Function(mydomain))\n  for i in range(mydomain.getDim()):\n    for j in range(mydomain.getDim()):\n       C[i,i,j,j]+=lam\n       C[i,j,i,j]+=mu\n       C[i,j,j,i]+=mu\n  msk=whereZero(x[0])*[1.,0.,0.] \\\n     +whereZero(x[1])*[0.,1.,0.] \\\n     +whereZero(x[2])*[0.,0.,1.]\n  sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)\n  mypde.setValue(A=C, X=sigma0, q=msk)\n  #... solve pde ...\n  u=mypde.getSolution()\n  #... calculate von-Mises stress\n  g=grad(u)\n  sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0\n  sigma_mises=sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \\\n                    (sigma[2,2]-sigma[0,0])**2)/2. \\\n                   +3*(sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2))\n  #... output ...\n  saveVTK(\"deform.vtu\", disp=u, stress=sigma_mises)\n\\end{python}\n\n\\begin{figure}\n\\centerline{\\includegraphics[width=\\figwidth]{HeatedBlock}}\n\\caption{von-Mises Stress and Displacement Vectors}\n\\label{HEATEDBLOCK FIG 2}\n\\end{figure}\n\n\\noindent Finally, the results can be visualized by calling\n\\begin{verbatim}\nmayavi2 -d deform.vtu -f CellToPointData -m Vectors -m Surface\n\\end{verbatim}\nNote that the filter \\text{CellToPointData} is applied to create a smoother\nrepresentation of the von-Mises stress.\n\\fig{HEATEDBLOCK FIG 2} shows the results where the colour of the vertical\nplanes represent the von-Mises stress and a horizontal plane of arrows shows\nthe displacements vectors.\n\n", "meta": {"hexsha": "14301b737e135ebd45ce5159af251f942eabc8ee", "size": 7759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user/heatedblock.tex", "max_stars_repo_name": "markendr/esys-escript.github.io", "max_stars_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/user/heatedblock.tex", "max_issues_repo_name": "markendr/esys-escript.github.io", "max_issues_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-14T03:07:43.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-14T03:07:43.000Z", "max_forks_repo_path": "doc/user/heatedblock.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": 42.3989071038, "max_line_length": 124, "alphanum_fraction": 0.6995746875, "num_tokens": 2430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6825851253608864}}
{"text": "\\section*{Exercise 26.2-7}\r\nProof of Lemma 26.2.\r\n\\\\\r\n\\\\\r\nWe first prove, that $f_p$ is a flow in $G_f$, by proving the capacity constraint and flow conservation property holds in $G_f$.\r\n\\\\\r\n\\\\\r\nCapacity constraint:\r\n\\\\\r\nIt is given, that $f_p(u,v)=c_f(p)$, if $(u,v)$ is on the path $p$. We also know that the residual capacity $c_f(p)$ is the minimum capacity of any edge on $p$, which gives us the upper bound on the flow through all edges on the path\r\n\\\\\r\n$f_p(u,v)\\leq c_f(u,v)$\r\n\\\\\r\nFurthermore, it is also given, that $f_p(u,v)=0$, if $(u,v)$ is not on $p$, which gives the lower bound on the flow\r\n\\\\\r\n$0 \\leq f_p(u,v)$.\r\n\\\\\r\n\\\\\r\nFlow conservation property:\r\n\\\\\r\nAs noted earlier, the flow on $p$ will be determined by the residual capacity $c_f(p)$ of $p$, meaning the same flow will be pushed through all edges on $p$. Hence, the flow conservation property holds.\r\n\\\\\r\n\\\\\r\nProof that $|f_p| = c_f(p)>0$:\r\n\\\\\r\nWe know from the definition of the value of a flow, that \r\n\\begin{align}\r\n|f| = \\sum_{v\\in V}f(s,v) - \\sum_{v\\in V}f(v,s)\r\n\\end{align}\r\n\r\nOn a path from $s$ to $t$, the number of edges with a positive flow leaving $s$ will be exactly one more than the number of edges with a positive flow that are entering $s$. If this was not the case, then $p$ would not be a path from $s$ to $t$. Hence as all flow on $p$ is the same, the net flow out of $s$ corresponds to what a single edge in the flow can carry in the path $p$ which is $c_f(p)$. So\r\n\\begin{align}\r\n|f| = \\sum_{v\\in V}f(s,v) - \\sum_{v\\in V}f(v,s) = c_f(p)\r\n\\end{align}\r\nTo show that $c_f(p)>0$, we note that $c_f(p)$ is the minimum residual capacity on $p$, and since only edges with a positive residual capacity are included in the residual network, the value must be positive.", "meta": {"hexsha": "24aecdc1da74bfac909f6eb602c702d47cf8e27f", "size": 1755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/26.2-7.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-7.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-7.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": 50.1428571429, "max_line_length": 402, "alphanum_fraction": 0.6746438746, "num_tokens": 538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.6825372437355564}}
{"text": "\\subsubsection{int -- a numeric type}\nBooleans are a subtype of integers.\nIntegers have unlimited precision.\n\nBitwise operations make sense for integers: \\mintinline{python}{x | y} (bitwise or), \\mintinline{python}{x ^ y} (bitwise xor), \\mintinline{python}{x & y} (bitwise and), \\mintinline{python}{x << n} (left shift), \\mintinline{python}{x >> n} (right shift).\n% Todo: underscores in integers (requires Python 3.6+).", "meta": {"hexsha": "e55c2647b36e5c6393d448161453b7a6a3e4ab91", "size": 419, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/python3/sections/built-in-types-numerics-int.tex", "max_stars_repo_name": "remigiusz-suwalski/programming-notes", "max_stars_repo_head_hexsha": "dd7d6f30d945733f7ed792fcccd33875b59d240f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T05:03:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T05:03:18.000Z", "max_issues_repo_path": "src/python3/sections/built-in-types-numerics-int.tex", "max_issues_repo_name": "remigiusz-suwalski/programming-notes", "max_issues_repo_head_hexsha": "dd7d6f30d945733f7ed792fcccd33875b59d240f", "max_issues_repo_licenses": ["MIT"], "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/python3/sections/built-in-types-numerics-int.tex", "max_forks_repo_name": "remigiusz-suwalski/programming-notes", "max_forks_repo_head_hexsha": "dd7d6f30d945733f7ed792fcccd33875b59d240f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-11-24T19:55:47.000Z", "max_forks_repo_forks_event_max_datetime": "2016-11-24T19:55:47.000Z", "avg_line_length": 69.8333333333, "max_line_length": 253, "alphanum_fraction": 0.723150358, "num_tokens": 120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.6825372437355564}}
{"text": "\\begin{flushleft}\n    \\subsection{Data Clustering}\n        Data clustering is a common practice that is often used in \n        Exploratory Data Analysis (EDA) and Data Mining (DM) for the \n        benefit of gaining insight on your data. In a society where there \n        is a vast amount of data to draw insight from, it is quite necessary \n        for the knowledge extraction process to happen efficiently. Due to this \n        many data scientists use Machine Learning (ML) algorithms, specifically \n        unsupervised ML algorithms, because often times the data they wish to cluster \n        does not have predefined labels.\n        \\\\\n        Granted that the focus of this assignment is on the application of MOPSO, rather \n        than data clustering, I have chosen the KMeans algorithm which is a relatively simple \n        yet effective unsupervised ML algorithm that will, for the sake of this assignment, \n        demonstrate how MOPSO can be applied to traditional static data clustering. The reader \n        should be aware that other unsupervised ML algorithms such as ...  that are commonly used\n        could perhaps provide a more efficient solution than the one proposed in this report. However, \n        that investigation is ommitted in this report and left for the reader to persue.\n\n    \\subsection{KMeans Clustering Algorithm}\n        The standard KMeans clustering algorithm operates by doing the following: \\\\\n        let S be the dataset, where each data sample is of I-dimensions \\\\\n        Randomly initialize K cluster centroids c[k] each of I-dimensions, where 1 <= k <= K \\\\\n        Repeat \\\\\n            let s be a data sample not yet presented \\\\\n            let c be the centroid closest to s \\\\\n            for every cluster c[k] \\\\\n                move that cluster to the average(mean) of points assigned to that cluster \\\\\n        Until stopping_condition \\\\\n\n        Note that for my implementation, I added slight variations to the standard KMeans algorithm to remove\n        any possible biases in the order of presentation or in the initial value for the centroids. \n        For this, I simply randomly shuffled the data samples after every epoch and initialized each centroid to \n        uniformly distributed values within the ranges of each attribute of the data set.\n\n    \\subsection{Multi Objective Particle Swarm Optimization}\n        MOPSO is a class of Computation Intelligence, namely Swarm Intelligence, and often describes optimization \n        problems with more than one, but less than four objectives to optimize.\n\n        For this assignment there were two objectives:\n        \\begin{itemize}\n            \\item minimize the intra-cluster distances, and\n            \\item maximize the inter-cluster distances.\n        \\end{itemize}\n\n        In my approach, I viewed the task at hand as a traditional clustering task that required finding a set of cluster centroids, \n        such that the intra-cluster distances are minimized and the inter-cluster distances are maximize. As a result my approach \n        involves using two sub-swarms, each swarm aiming to solve the objective function that finds the centroids who's summated \n        intra-cluster distance is minimal and who's summated inter-cluster distance is maximal over all. However, with this approach, \n        rises a need for communication between particles of each swarm such that the global best solutions of each swarm \n        can be utilized in satisfying the given objectives. To achieve this I chose to represent a particle in the following way: \\\\\n        \\begin{itemize}\n            \\item A particle has a set of centroids, i.e. the set of centroids that satisfy the objectives.\n            \\item A particle's position is a vector that contains the intra-cluster distances and the inter-cluster distances for the \n            centroids belonging to that particle.\n            \\item A particle's personal best and velocity vectors are of the same dimensions as the particle's position vector.\n        \\end{itemize}\n        The swarms of the MOPSO algorithm are also then represented in the following way: Each swarm contains a set of particles, \n        a global best position vector and a global best centroids set, which will be the set of centroids that make up the global \n        best position vector's elements.\n\n        For the case of dynamically determining the optimal number of clusters, I applied the above approach through several cluster sizes, \n        and with each, measuring the silhouette score and finally determining the optimal number of clusters by taking the difference between \n        adjacent cluster's silhouette scores and selecting the one with the highest difference, i.e. selecting the cluster with the steepest slope.\n\\end{flushleft}", "meta": {"hexsha": "3d8a03fa9f97bbf90ee88bb516227c1390ad3f05", "size": 4796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/src/backg.tex", "max_stars_repo_name": "kmdinake/le-creyol", "max_stars_repo_head_hexsha": "16c77292e2e82092e2b3fd8a68991e4915bb2de7", "max_stars_repo_licenses": ["MIT"], "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/src/backg.tex", "max_issues_repo_name": "kmdinake/le-creyol", "max_issues_repo_head_hexsha": "16c77292e2e82092e2b3fd8a68991e4915bb2de7", "max_issues_repo_licenses": ["MIT"], "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/src/backg.tex", "max_forks_repo_name": "kmdinake/le-creyol", "max_forks_repo_head_hexsha": "16c77292e2e82092e2b3fd8a68991e4915bb2de7", "max_forks_repo_licenses": ["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.7846153846, "max_line_length": 147, "alphanum_fraction": 0.72206005, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7905303186696748, "lm_q1q2_score": 0.6825372390117406}}
{"text": "\\section{Heuristic optimization}\n\nA heuristic is a problem-solving strategy that is based on rules\nof thumb or common sense, possibly also using expert\nknowledge. Heuristics are often used when no efficient (exact) algorithms\nare known, or when applying such algorithms would take too\nlong.\n\n\\subsection{Hill Climbing}\nSearch for improvements in neighborhood and improve current solution successively.\n\n\\begin{enumerate}\n    \\item Initialization: Start with random solution. \\\\\n    Evaluate initial solution.\n    \\item Iteratively: \\\\\n    Explore neighborhood and evaluate new solution candidates. Continue with best solution found, if this improves the target function. (Otherwise we’re in a local optimum.)\n    \\item Return solution\n\\end{enumerate}\n\n\\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]\nVariant: Always take best solution from neighborhood, even if this decreases target function. Pros and cons?\n\\begin{itemize}\n    \\item Might escape from local optima.\n    \\item Not monotone increasing.\n    \\item Might go back and forth, i.e. run into a cycle.\n\\end{itemize}\n\\end{tcolorbox}\n\n\\subsubsection{Stochastic hill climbing}\n\n\\begin{enumerate}\n    \\item Initialization: Start with random solution. \\\\\n    Evaluate initial solution.\n    \\item Iteratively: \\\\\n    Choose random solution in neighborhood (i.e. perform a\nrandom modification). Evaluate new solution candidate,\nand accept it, if it is better. Continue until termination\ncriterion is reached.\n    \\item Return solution\n\\end{enumerate}\n\n\\clearpage\n\\subsubsection{Continuous hill climbing}\n\n\\begin{enumerate}\n    \\item Initialization: $i = 0$:\n    Initial solution $x_0$.\n    \\item Iteration $i \\rightarrow i + 1$: \\\\\n        $x_{i+1} =\n        \\begin{cases}\n        y_i       & \\quad \\text{if } f(y_i) \\leq f(x_i)\\\\\n        x_i       & \\quad \\text{if } f(y_i) > f(x_i)\n        \\end{cases}$\n        \\item Return solution\n\\end{enumerate}\n\n\\subsection{Tabu search}\nSimilar to hill climbing, but with some memory. Try to avoid steps that go back to previously visited solutions, or\nthat undo the effect of previous steps. (These steps are „tabu“.). The goal is to promote diversity of the solutions explored, in\nparticular to reduce cyclic behaviour and to escape from local\noptima.\n\n\\begin{enumerate}\n    \\item Start with random solution. \\\\\n        Evaluate initial solution.\n    \\item Iteratively: \\\\\n    Explore neighborhood and evaluate new solution\ncandidates. Only consider steps that are not tabu.\nProceed with step 2 with the best solution found and\nupdate tabu list until termination criterion is reached.\n    \\item Return solution\n\\end{enumerate}\n\n\\subsubsection{Tabu List}\n\\begin{itemize}\n    \\item Simplest variant: Only store last solution as a tabu (to\navoid going back and forth).\n\\item Probably better: Keep e.g. a tabu list corresponding to last\nk moves.\n\\item How restrictive should the tabus be? (Forbid specific\nconfigurations, whole classes of moves, certain values for\ncertain variables, ...?)\n\\item Duration of tabus (short- vs. mid- vs. longterm)?\nSize and organization of tabu list(s)?\n\\item Are the tabus enforced strictly or do we allow exceptions\n(„aspiration“)? When and why?\n\\end{itemize}\n\n\\subsubsection{Randomized tabu search}\n\\textbf{Stochastic version.}\n\n\\begin{enumerate}\n    \\item Start with random solution. \\\\\n        Evaluate initial solution.\n    \\item Iteratively: \\\\\nChoose a random solution from the neighborhood.\nEvaluate the new solution candidate, if its not tabu.\nIf a better solution is found, continue with this solution,\nupdate tabu list and proceed with step 2. Continue until\ntermination criterion is reached.\n    \\item Return solution\n\\end{enumerate}\n\n\\subsection{Simulated annealing}\nSimilar to hill climbing, but also allow non-improving\nmoves to escape from local optima.\n\n\\begin{enumerate}\n    \\item Start with random solution. \\\\\n        Evaluate initial solution.\n    \\item Iteratively: \\\\\nChoose random solution in neighborhood and evaluate it. If\nit is better, accept it. If it is worse, accept it only with some\nprobability.\nContinue until termination criterion is reached.\n    \\item Return solution\n\\end{enumerate}\n\nWith other words\n\n\\begin{enumerate}\n    \\item Initialization: \\\\\n    Start with $x_0$\n    \\item Iteratively: $x_i \\rightarrow x_{i+1}$ \\\\\n    Sample a random solution $y_i$ in the neighborhood and accept it to be $x_{i+1}$ with probability $min\\{ 1, e^{\\frac{f(x_i)-f(y_i)}{T_i}}\\}$\n\\end{enumerate}\n\n\\subsection{Population based methods}\nAn evolving population of (partial) solutions, whose\nmembers evolve and adapt individually to the problem and are\nsearching for the optimum. Problem-specific information can be\nexchanged between the members of the population, and can\nalso be passed on to descendants.\n\n\\clearpage\n\\subsection{Genetic Algorithms}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/encodingGenotype.png}\n\\caption{Genotype encoding}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/knapsackGenotype.png}\n\\caption{Genotype encoding - Knapsack Example}\n\\end{figure}\n\nA small change in genotype should corresponds to a small\nchange in phenotype.\n\nImportant points in the evolutionary process, i.e. when creating a new generation:\n\\begin{itemize}\n    \\item Population development\n    \\item Natural selection: Selection of individuals for reproduction\n    \\item Recombination\n    \\item Mutation\n\\end{itemize}\n\n\\clearpage\n\\subsubsection{Terminology}\n\nAn \\textbf{individual} is often represented as a vector with $n$ (binary, integer or\nreal) entries. The individual entries in (e.g.) the vector representation of an\nindividual are its \\textbf{genes}. They describe the genetic information and the properties of the\nindividuals. E.g., the individual (0, 0, 1, 0, 1) (binary encoding) consists of\nfive genes.\n\nThe concrete values of a gene can take in an individual are\ncalled \\textbf{alleles}. In binary-encoded individuals, the only possible alleles are 0\nand 1.\n\nThe \\textbf{population}is the set of all individuals in an optimization\nproblem at a given time. A \\textbf{generation} is the population at a specific point in time.\n\nThe \\textbf{genotype} is the encoded form of an individual. The \\textbf{phenotype} is the decoded form of an individual. It does\nnot depend on our choice of encoding. The \\textbf{fitness function} is our measure for the quality of a\nsolution candidate in the optimization problem.\n\n\\subsubsection{Algorithm}\n\n\\begin{enumerate}\n    \\item \\textbf{Initialization:} Random starting population\n    \\item \\textbf{Iteratively:} Create next generation according to\nevoluationary principles: \n\\begin{itemize}\n    \\item Assign fitness to individuals\n    \\item Natural selection and choosing parents for reproduction\n    \\item Recombination process\n    \\item Mutation process\n\\end{itemize}\nRepeat 2 until termination criterion is satisfied\n\\item Return best individual\n\\end{enumerate}\n\n\\subsubsection{Selection Pressure}\nBetter individuals should have a higher\nchance of reproduction.\n\\begin{itemize}\n    \\item \\textbf{Better exploration} of search space when selection pressure is \\textbf{low}.\n    \\item \\textbf{Better exploitation} of good individuals when selection pressure is \\textbf{high}. \\\\\n    Be careful with dominant solution candidates $\\rightarrow$ crowding\n\\end{itemize}\n\n\\textbf{Strategy:}Low selection pressure early on, increasing selection\npressure in later generations. (Compare with simulated\nannealing.)\n\n\\clearpage\n\\subsubsection{Recombinations}\n\n\\textbf{One-Point Crossover}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{figures/onepointcrossover.png}\n\\caption{One-Point Crossover}\n\\end{figure}\n\n\\textbf{Two-Point Crossover}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{figures/twopointcrossover.png}\n\\caption{Two-Point Crossover}\n\\end{figure}\n\n\\textbf{Repair Mechanism for Two-Point Crossover}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/repairtwopointcrossover.png}\n\\caption{Repair Mechanism for Two-Point Crossover}\n\\end{figure}\n\n\\textbf{Uniform Crossover}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{figures/uniformcrossover.png}\n\\caption{Uniform Crossover}\n\\end{figure}\n\n\\textbf{Adjacency method}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{figures/adjacencyMethod.png}\n\\caption{Adjacency Method}\n\\end{figure}\n\n\\clearpage\n\\subsubsection{Mutations}\nImportant to obtain new solution candidates (diversification) for exploration of search space.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/mutations.png}\n\\caption{Mutations}\n\\end{figure}\n\n\\subsubsection{Combination}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/combination.png}\n\\caption{Combination}\n\\end{figure}\n\n\\subsection{Ant Colony}\n\\begin{itemize}\n    \\item No central instance that coordinates ants. The colony is self-organized. Ants are indpendent from each other. \n    \\item An individual ant lays down pheromone trails when looking for food. \n    \\item The higher the pheromone concentration on a path, the higher the probability an ant chooses it. If an ant lays down pheromone at a constant rate, shorter paths receive more pheromone per time. $\\rightarrow$ Frequently used good paths are reinforced and attract even more ants.\n    \\item Unused paths become unattractive because of evaporation.\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/ants.png}\n\\caption{Ant Colony}\n\\end{figure}\n\n\\clearpage", "meta": {"hexsha": "b3e16076c176f595f7d2d5ac2116b03285344f41", "size": 9565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FTP_Optimiz/07_HeuristicOptimization.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": "FTP_Optimiz/07_HeuristicOptimization.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": "FTP_Optimiz/07_HeuristicOptimization.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": 34.1607142857, "max_line_length": 286, "alphanum_fraction": 0.7668583377, "num_tokens": 2396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.6825372346581801}}
{"text": "% !TeX spellcheck = en_GB\r\n\\chapter{Matrices}\r\nWe  come  across  matrices often while  we  deal  with various physical systems. When we need to solve  a  set  of  linear  equations  ,  when  we  need  to  rotate  vectors, in quantum mechanics etc. Let us find what a matrix is.\r\n\\begin{definition}\r\nA matrix can be defned as a collection of numbers arranged in a rectangular way, in rows and columns and bounded by brackets , $[\\hspace{0.2cm} ]$  or  $(\\hspace{0.2cm})$. Individual numbers or functions inside a matrix  are known as elements of the matrix.\\\\ A matrix can also be viewed as an operator (a linear transformation) from $\\mathbb{R}^{n}$ to $\\mathbb{R}^{n}$.\t\r\n\\end{definition}\r\n\\begin{example}\r\n$\\left[\\begin{array}{ll}2 & 3 \\\\ 4 & 7\\end{array}\\right]$,$\\left[\\begin{array}{lll}-7 & 5 &3i\\\\ 4 & -7i&8\\\\4 & 5-i &3i \\end{array}\\right]$,$\\left[\\begin{array}{llll}x & y &z&w\\\\ p & q&r&s\\\\a & b &c&d \\end{array}\\right]$\t\t\r\n\\end{example}\r\n\\textbf{Order of a matrix}\r\n\\newline A matrix of order $m\\times n$ has $m$ number of rows and  $n$  number of columns.Every elment of the matrix is charecterized by a row index $i$ and a column index $j$.Then an element of $i^{th}$ row and $j^{th}$ column of a matrix can be represented as, $a_{ij}$.\r\n\\\\A matrix $A$ of $m$ rows and $n$ columns is written as,\r\n$A=[a_{ij}]_{m\\times n}$\r\n\r\n\\section{Types of matrices}\r\n\\begin{itemize}\r\n\t\\item \\textbf{Row Matrix}\\\\\r\n\tIf a matrix has only one row and any number of columns, it is called a Row matrix, \\begin{example}\r\n\t\t$\\left[\\begin{array}{llll}\r\n\t\t2 & 7 & 3 & 9\r\n\t\\end{array}\\right]$\r\n\t\\end{example}\r\n\r\n\t\\item \\textbf{Column Matrix}\\\\\r\n\t A matrix, having one column and any number of rows, is called a Column  matrix .\r\n\t\\begin{example}\r\n\t\t$\r\n\t\\text {}\\left[\\begin{array}{l}\r\n\t\t1 \\\\\r\n\t\t2 \\\\\r\n\t\t3\r\n\t\\end{array}\\right]\r\n\t$\r\n\t\\end{example}\r\n\t\\item \\textbf{Null Matrix or Zero Matrix}\\\\\r\n\t Any matrix, in which all the elements are zeros, is called a Zero matrix or Null matrix .\r\n\t\\begin{example}\r\n\t\t$\r\n\t\\left[\\begin{array}{llll}\r\n\t\t0 & 0 & 0 & 0 \\\\\r\n\t\t0 & 0 & 0 & 0\r\n\t\\end{array}\\right]\r\n\t$\r\n\t\\end{example}\r\n\t\\item \\textbf{Square Matrix }\\\\\r\n\tA matrix, in which the number of rows is equal to the number of columns, is called a square matrix \r\n\\begin{example}\r\n\t\t$\\left[\\begin{array}{ll}\r\n\t\t2 & 5 \\\\\r\n\t\t1 & 4\r\n\t\\end{array}\\right]$\r\n\\end{example}\r\n\r\n\t \\item \\textbf{Diagonal matrix}\\\\\r\n\t Matrix having elements other than the principal diagonal elements are zero\r\n\t i.e $a_{i j}=0$ for $i \\neq j$.\r\n\t\\begin{example}\r\n\t\t $\\left[\\begin{array}{ll}a & 0 \\\\ 0 & b\\end{array}\\right]$\r\n\t\\end{example}\r\n\t \\item \\textbf{Scalar matrix}\r\n\t \\\\ A diagonal matrix in which all the diagonal elements are equal to a scalar, say $(k)$ is called a scalar matrix. i.e., $\\mathrm{A}=\\left[a_{i j}\\right]_{n \\times n}$ is a scalar matrix if $a_{i j}=\\left\\{\\begin{array}{ll}0, & \\text { when } i \\neq j \\\\ k, & \\text { when } i=j\\end{array}\\right.$ \r\n\t \\begin{example}\r\n\t \t$\r\n\t \\left[\\begin{array}{lll}\r\n\t \t2 & 0 & 0 \\\\\r\n\t \t0 & 2 & 0 \\\\\r\n\t \t0 & 0 & 2\r\n\t \\end{array}\\right],\\left[\\begin{array}{rrrr}\r\n\t \t-6 & 0 & 0 & 0 \\\\\r\n\t \t0 & -6 & 0 & 0 \\\\\r\n\t \t0 & 0 & -6 & 0 \\\\\r\n\t \t0 & 0 & 0 & -6\r\n\t \\end{array}\\right]\r\n\t $\r\n\t\r\n\t \\end{example}\r\n\t \\item  \\textbf{ldentity/unit matrix}\\\\\r\n\t Diagonal matrix having all principal diagonal elements equal to one.\r\n\t i.e. $a_{i j}=0$ for $i \\neq j$ and $a_{i i}$ is equal to 1 for all $i$.\r\n\t\\begin{example}\r\n\t\t  $\\left[\\begin{array}{ll}1 & 0 \\\\ 0 & 1\\end{array}\\right]$\r\n\t\\end{example}\r\n\t \\item\\textbf{ Triangular Matrix}\\\\  A square matrix, all of whose elements below the leading diagonal are zero, is called an upper triangular matrix. A square matrix, all of whose elements above the leading diagonal are zero, is called a lower triangular matrix\r\n\t\r\n\t\\begin{example}\r\n\t\t $\\text{Upper triangular matrix}\\rightarrow\r\n\t \\left[\\begin{array}{lll}\r\n\t \t1 & 3 & 2 \\\\\r\n\t \t0 & 4 & 1 \\\\\r\n\t \t0 & 0 & 6\r\n\t \\end{array}\\right]\\\\ \\rightarrow\\text{Lower triangular matrix}\\left[\\begin{array}{lll}\r\n\t \t2 & 0 & 0 \\\\\r\n\t \t4 & 1 & 0 \\\\\r\n\t \t5 & 6 & 7\r\n\t \\end{array}\\right]\r\n\t $\r\n\t\\end{example}\r\n\t \\item \\textbf{ Periodic matrix}\\\\\r\n\t  A square matrix ' $A$ ' for which $A^{k+1}=A,$ is called periodic matrix of period $k$.\r\n\t \\begin{example}\r\n\t \t $A=\\left[\\begin{array}{cc}0 & -1 \\\\ 1 & 0\\end{array}\\right] \\Rightarrow A^{5}=A$ i.e $A$ is periodic matrix of period 4\r\n\t \\end{example}\r\n\t \\item \\textbf{ Idempotent matrix}\\\\\r\n\t A square matrix ' $A$ ' for which $A^{2}=A,$ is called idempotent matrix. It is a periodic matrix of period 1 . Any idempotent matrix will be either singular matrix or non-singular unit matrix.\r\n\t\\begin{example}\r\n\t\t $\\left[\\begin{array}{ll}1 & 1 \\\\ 0 & 0\\end{array}\\right],\\left[\\begin{array}{ccc}2 & -2 & -4 \\\\ -1 & 3 & 4 \\\\ 1 & -2 & -3\\end{array}\\right]$\r\n\t\\end{example}\r\n\t \\item \\textbf{Nilpotent matrix}\\\\\r\n\t  A square matrix for which $A^{p}=0,$ is called nilpotent matrix of index ' $p$ '. The trace and determinant of the nilpotent matrix is always zero.\r\n\t\\begin{example}\r\n\t\t $A=\\left[\\begin{array}{ll}0 & 0 \\\\ 1 & 0\\end{array}\\right]$ is a nilpotent matrix of index '2'.\r\n\t\\end{example}\r\n\t \\item  \\textbf{Involutory Matrix}\\\\ A square matrix for which $A^{2}=I$, is called involutory matrix. It is a self-inverse matrix.\r\n\t \\begin{example}\r\n\t \t$\\left[\\begin{array}{lll}1 & 0 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right]$\r\n\t \\end{example}\r\n\t \\item \\textbf{Symmetric Matrix}\\\\\r\n\t A square matrix will be called symmetric, if for all values of $i$ and $j,$ $a_{i j}=a_{j i}$ i.e., $A^{\\prime}=A$\r\n\t\\begin{example}\r\n\t\t $\r\n\t \\left[\\begin{array}{lll}\r\n\t \ta & h & g \\\\\r\n\t \th & b & f \\\\\r\n\t \tg & f & c\r\n\t \\end{array}\\right]\r\n\t $\r\n\t\\end{example}\r\n\t \\item \\textbf{Skew Symmetric Matrix}\\\\A square matrix is called skew symmetric matrix, if\r\n\t (1) $a_{i j}=-a_{j i}$ for all values of $i$ and $j,$ or $A^{\\prime}=-A$\r\n\t (2) All diagonal elements are zero.\r\n\t\\begin{example}\r\n\t\t $\r\n\t \\left[\\begin{array}{ccc}\r\n\t \t0 & -h & -g \\\\\r\n\t \th & 0 & -f \\\\\r\n\t \tg & f & 0\r\n\t \\end{array}\\right]\r\n\t $\r\n\t\\end{example}\r\n\t \\end{itemize}\r\n\t \\section{Elementary matrix arithmetic}\r\n\t \\subsection{Matrix addition}\r\n\t The operation of addition of two matrices is only defined when both matrices have the same dimensions. If ${A}$ and ${B}$ are both $(m \\times n)$, then the sum,\r\n\t \\\\$\r\n\t {C}={A}+{B}\r\n\t $\\\\\r\n\t the order of the sum is also $(m \\times n)$ and is defined to have each element the sum of the corresponding elements of ${A}$ and ${B},$ thus\r\n\t \\\\$\r\n\t c_{i j}=a_{i j}+b_{i j}\r\n\t $\r\n\t \\subsubsection{Properties of vector addition}\r\n\t Only matrices of the same order can be added or subtracted.\r\n\t \\begin{itemize}\r\n\t \t\\item  Commutative Law \\quad  $A+B=B+A$.\r\n\t \t\\item Associative law \\quad $A+(B+C)=(A+B)+C$.\r\n\t \\end{itemize}\r\n\t\r\n\t \\begin{exercise}\r\n\t \tIf $\\begin{aligned} A &=\\left[\\begin{array}{rrr}4 & 2 & 5 \\\\ 1 & 3 & -6\\end{array}\\right] \\text{and} & B=\\left[\\begin{array}{lll}1 & 0 & 2 \\\\ 3 & 1 & 4\\end{array}\\right] \\end{aligned}$ find (A+B).\\end{exercise}\r\n \t\\begin{answer}\r\n \t\t\t$$\\begin{aligned}\r\n \t\t\tA+B &=\\left[\\begin{array}{lrl}4+1 & 2+0 & 5+2 \\\\ 1+3 & 3+1 & -6+4\\end{array}\\right]=\\left[\\begin{array}{lll}5 & 2 & 7 \\\\ 4 & 4 & -2\\end{array}\\right] \\end{aligned}$$\r\n \t\\end{answer}\r\n\t \r\n\t \r\n\t %........................................................\r\n\t \\subsection{Matrix multiplication}\r\n\t \\subsubsection{$\\bullet$Scalar multiple of a matrix}\r\n\t If a matrix is multiplied by a scalar quantity $k$, then each element o fthe matrix is multiplied by $k$.\r\n\t \\subsubsection{$\\bullet$Multiplication between matrices}\r\n\tThe product of two matrices $A$ and $\\mathrm{B}$ is only possible if the number of columns in $A$ is equal to the number of rows in $B$.\r\n\t \r\n\t Let $A=\\left[a_{i j}\\right]$ be an $m \\times n$ matrix and $B=\\left[b_{i j}\\right]$ be an $n \\times p$ matrix. Then the product $A B$ of these matrices is an $m \\times p$ matrix $C=\\left[c_{i j}\\right]$ where\r\n\t $$\r\n\t c_{i j}=a_{i 1} b_{1 j}+a_{i 2} b_{2 j}+a_{i 3} b_{3 j}+\\ldots .+a_{i n} b_{n j}\r\n\t $$\r\n\t $$\\left[\\begin{array}{ll}a_{1 1} & a_{1 2} \\\\ a_{2 1} & a_{2 2 }\\end{array}\\right] \\cdot\\left[\\begin{array}{ll} b_{1 1} &  b_{1 2} \\\\b_{2 1} & b_{22 }\\end{array}\\right]=\\left[\\begin{array}{ll}{a_{1}} \\cdot {b_{1}} & {a_{1}} \\cdot b_{2} \\\\ {a_{2}} \\cdot {b_{1}} & {a_{2}} \\cdot {b_{2}}\\end{array}\\right]$$\\\\\\\\\r\n\t \\textbf{Properties of matrix multiplication}\r\n\t \\begin{itemize}\r\n\t \t\\item Multiplication of matrices is not commutative.\r\n\t \t$$\r\n\t \tA B \\neq B A\r\n\t \t$$\r\n\t \t\\item Matrix multiplication is associative, if conformability is assured.\r\n\t \t$$\r\n\t \tA(B C)=(A B) C\r\n\t \t$$\r\n\t \t\\item  Matrix multiplication is distributive with respect to addition.\r\n\t \t$$\r\n\t \tA(B+C)=A B+A C\r\n\t \t$$\r\n\t \t\\item Multiplication of matrix $A$ by unit matrix.\r\n\t \t$$\r\n\t \tA I=I A=A\r\n\t \t$$\r\n\t \t\\item Multiplicative inverse of a matrix exists if $|\\mathrm{A}| \\neq 0$.\r\n\t \t$$\r\n\t \tA \\cdot A^{-1}=A^{-1} \\cdot A=I\r\n\t \t$$\r\n\t \t\\item  If $\\mathrm{A}$ is a square then $A \\times A=A^{2}, A \\times A \\times A=\\mathrm{A}^{3}$.\r\n\t \t\\item  $\\quad A^{0}=I$\r\n\t \t\\item  $\\quad I^{n}=I,$ where $n$ is positive integer.\r\n\t \\end{itemize}\r\n \\begin{exercise}\r\n \t$$\r\n \t\\text {  If } A=\\left[\\begin{array}{rrr}\r\n \t\t1 & -2 & 3 \\\\\r\n \t\t2 & 3 & -1 \\\\\r\n \t\t-3 & 1 & 2\r\n \t\\end{array}\\right] \\text { and } B=\\left[\\begin{array}{lll}\r\n \t\t1 & 0 & 2 \\\\\r\n \t\t0 & 1 & 2 \\\\\r\n \t\t1 & 2 & 0\r\n \t\\end{array}\\right]\r\n \t$$ \\end{exercise}\r\n \\begin{answer}\r\n \tfrom the products $A B$ and $B A,$ and show that $A B \\neq B A$.\\\\\r\n \\\\Here,\r\n $$\r\n A B=\\left[\\begin{array}{rrr}\r\n \t1 & -2 & 3 \\\\\r\n \t2 & 3 & -1 \\\\\r\n \t-3 & 1 & 2\r\n \\end{array}\\right]\\left[\\begin{array}{lll}\r\n \t1 & 0 & 2 \\\\\r\n \t0 & 1 & 2 \\\\\r\n \t1 & 2 & 0\r\n \\end{array}\\right]\r\n $$\r\n $$\r\n =\\left[\\begin{array}{ccc}\r\n \t1-0+3 & 0-2+6 & 2-4+0 \\\\\r\n \t2+0-1 & 0+3-2 & 4+6-0 \\\\\r\n \t-3+0+2 & 0+1+4 & -6+2+0\r\n \\end{array}\\right]=\\left[\\begin{array}{rrr}\r\n \t4 & 4 & -2 \\\\\r\n \t1 & 1 & 10 \\\\\r\n \t-1 & 5 & -4\r\n \\end{array}\\right]\r\n $$$$\r\n \\begin{array}{l}\r\n \tB A=\\left[\\begin{array}{lll}\r\n \t\t1 & 0 & 2 \\\\\r\n \t\t0 & 1 & 2 \\\\\r\n \t\t1 & 2 & 0\r\n \t\\end{array}\\right]\\left[\\begin{array}{rrr}\r\n \t\t1 & -2 & 3 \\\\\r\n \t\t2 & 3 & -1 \\\\\r\n \t\t-3 & 1 & 2\r\n \t\\end{array}\\right]\\\\=\\left[\\begin{array}{ccc}\r\n \t\t1+0-6 & -2+0+2 & 3-0+4 \\\\\r\n \t\t0+2-6 & 0+3+2 & 0-1+4 \\\\\r\n \t\t1+4+0 & -2+6+0 & 3-2+0\r\n \t\\end{array}\\right]=\\left[\\begin{array}{rrr}\r\n \t\t-5 & 0 & 7 \\\\\r\n \t\t-4 & 5 & 3 \\\\\r\n \t\t5 & 4 & 1\r\n \t\\end{array}\\right] \r\n \t\r\n \\end{array}\r\n $$\r\n \r\n \\end{answer}\r\n \r\n\r\n\r\n\\subsection{Trace of a matrix}\r\nIn linear algebra, tthe trace of a matrix is defined as the sum of the principal diagonal elements of the matrix i.e.\r\n$$\r\n\\operatorname{Tr}({A})=a_{11}+a_{22}+a_{33}+\\ldots \\ldots \\ldots \\ldots+a_{n n}=\\sum_{i=1}^{n} a_{i i}\r\n$$\r\n\\textbf{Properties of trace}\r\n\\begin{itemize}\r\n\t\\item  $\\operatorname{Tr}(A+B)=\\operatorname{Tr}(A)+\\operatorname{Tr}(B)$\r\n\t\\item $\\operatorname{Tr}(c A)=c \\operatorname{Tr}(A)[$ where $c$ is constant $]$\r\n\t\\item $\\operatorname{Tr}(A B)=\\operatorname{Tr}(B A)$\r\n\t\\item $\\operatorname{Tr}(A B C D)=\\operatorname{Tr}(B C D A)=\\operatorname{Tr}(C D A B)=\\operatorname{Tr}(D A B C)$\r\n\\end{itemize}\r\n\\begin{example}\r\n\t\\leavevmode\r\n\t\\newline\r\n\t$\r\n\t\\begin{array}{l}\r\n\t\tA=\\left[\\begin{array}{rrr}\r\n\t\t\t3 & 5 & 6 \\\\\r\n\t\t\t7 & 8 & 9 \\\\\r\n\t\t\t12 & 15 & 12\r\n\t\t\\end{array}\\right] \\\\\\\\\r\n\t\t\\operatorname{Tr}(\\mathrm{A})=\\mathrm{a}_{11}+\\mathrm{a}_{22}+\\mathrm{a}_{33}=8+3+12=23\r\n\t\\end{array}\r\n\t$\r\n\\end{example}\r\n\\subsection{Transpose of a matrix}\r\nThe transpose of an arbitrary matrix $A$ is written as $A^{T}$ is obtained by interchanging corresponding rows into column of $A$ i.e. if element of $A$ is $a_{i j}$ then element of $A^{T}$ is $a_{j i}$.\\\\\r\n\\textbf{Properties:}\r\n\\begin{itemize}\r\n\t\\item $\\left(A^{T}\\right)^{T}=A$\r\n\t\\item $(A B)^{T}=B^{T} A^{T}$\r\n\\end{itemize}\r\n \r\n\\begin{example}\r\n$\r\nA=\\left[\\begin{array}{lll}\r\n\t2 & 3 & 4 \\\\\r\n\t1 & 0 & 5 \\\\\r\n\t6 & 7 & 8\r\n\\end{array}\\right], A^{T}=\\left[\\begin{array}{lll}\r\n\t2 & 1 & 6 \\\\\r\n\t3 & 0 & 7 \\\\\r\n\t4 & 5 & 8\r\n\\end{array}\\right]\r\n$\t\r\n\\end{example}\r\n\\subsection{Conjugate of a Matrix}\r\nConjugate of a matrix obtained by taking the complex conjugate of each element  i.e\r\n\\begin{example}\r\n\t$\r\n\tA=\\left[\\begin{array}{ccc}\r\n\t\t2+i & 2-3 i & 0 \\\\\r\n\t\t1-2 i & -i & 3-2 i\r\n\t\\end{array}\\right]\r\n\t \\Rightarrow{A^{\\ast}}=\\left[\\begin{array}{ccc}\r\n\t\t2-i & 2+3 i & 0 \\\\\r\n\t\t1+2 i & i & 3+2 i\r\n\t\\end{array}\\right]\r\n\t$\r\n\\end{example}\r\n\r\n\\subsection{Transpose Conjugate of a Matrix:}\r\nTranspose conjugate of a matrix obtained by taking the transpose of the matrix and then taking the complex conjugate of each element or vice versa i.e\r\n$$\r\nA^{\\dagger}=\\left(A^{T}\\right)^{*}=\\left(A^{*}\\right)^{T}\r\n$$\r\n\\begin{example}\r\n\t$\r\n\t \\quad A=\\left[\\begin{array}{ccc}\r\n\t\t2 & 4+i & 1 \\\\\r\n\t\t-i & 5 & 4-i \\\\\r\n\t\t3i & 0 & 3i\r\n\t\\end{array}\\right] \\Rightarrow A^{\\dagger}=\\left[\\begin{array}{ccc}\r\n\t\t2 & i & -3i \\\\\r\n\t\t4-i & 5 & 0 \\\\\r\n\t\t1 & 4+ i & -3i\r\n\t\\end{array}\\right]\r\n\t$\r\n\\end{example}\r\n\\subsection{Unitary Matrix}\r\n A square matrix $A$ is said to be unitary if,\r\n \\begin{equation*}\r\n A^{\\dagger}A=I\r\n \\end{equation*}\r\nWhere $A^{\\dagger}$ is the conjugate transpose of the matrix, $ A$ and $I$ is a unit matrix. And \r\n \\begin{equation*}\r\n A^{\\dagger}=A^{-1}\r\n \\end{equation*} \r\n\\subsection{Symmetric matrix}\r\nA square matrix is called symmetric if for all values of i and j, $a_{i j}=a_{j i}$, then $A^{T}=A$ \r\n\\begin{example} $\\left[\\begin{array}{lll}a & b & f \\\\ b & c & d \\\\ f & d & e\\end{array}\\right]$\t \r\n\t\\end{example}\r\n\\subsubsection{Skew-Symmetric matrix}\r\nA square matrix is called skew-symmetric if for all values of i and j, $a_{i j}=-a_{j i}$, then $A^{T}=-A$ \r\n\\begin{example} $\\left[\\begin{array}{ccc}a & -b & -f\\\\ b & c & -d \\\\ f & d & e\\end{array}\\right]$\t \r\n\\end{example}\r\n\\begin{note}\r\nEvery square matrix can be uniquely expressed as the sum of symmetric and a skew symmetric matrix.$$  A=\\frac{1}{2}(A+A^{T})+\\frac{1}{2}(A-A^{T})$$\t\r\n\\end{note}\r\n\\subsection{Orthogonal matrix}\r\n A square matrix $A$ is called an orthogonal matrix if the product of the matrix $A$ and the transpose matrix $A^{T}$ , is an identity matrix \r\n\\\\$\r\n\\text { A. } A^{T}=I\r\n$\\hspace{1cm}if $|A|=1,$ matrix $A$ is proper.\r\n\\begin{example}\r\n\t$$\\begin{aligned}\r\n\t\t\\text{If  }A&=\\left[\\begin{array}{ccc}1 / 3 & 2 / 3 & -2 / 3 \\\\ -2 / 3 & 2 / 3 & 1 / 3 \\\\ 2 / 3 & 1 / 3 & 2 / 3\\end{array}\\right]\\\\\r\n\tA^{T} A&=\\left[\\begin{array}{ccc}1 / 3 & 2 / 3 & -2 / 3 \\\\ -2 / 3 & 2 / 3 & 1 / 3 \\\\ 2 / 3 & 1 / 3 & 2 / 3\\end{array}\\right]\\left[\\begin{array}{ccc}1 / 3 & -2 / 3 & 2 / 3 \\\\ 2 / 3 & 2 / 3 & 1 / 3 \\\\ -2 / 3 & 1 / 3 & 2 / 3\\end{array}\\right]&=\\left[\\begin{array}{ccc}1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1\\end{array}\\right]\r\n\t\\end{aligned}$$\r\n\t\r\n\r\n\t\\end{example}\r\n\\subsection{Hermitian Matrix}\r\nA square matrix $A=\\left(a_{i j}\\right)$ is called Hermitian matrix, if every $i$ -jth element of $A$ is equal to conjugate complex $j-i$ th element of $A$. Then, $A^{\\dagger}=A$\r\n\\begin{example}\r\n\t$\\text{A=}\\left[\\begin{array}{lll}\r\n\t\t\t1 & 2+3 i & 3+i \\\\\r\n\t\t\t2-3 i & 2 & 1-2 i \\\\\r\n\t\t\t3-i & 1+2 i & 5\r\n\t\\end{array}\\right]$\r\n\\end{example}\r\n\\subsubsection{Skew Hermitian Matrix}\r\n A square matrix $A=\\left(a_{i j}\\right)$ will be called a Skew Hermitian matrix if every $i$ -$j^{th}$ element of $A$ is equal to negative conjugate complex of $j$ -$i^{th}$ element of $A$.\r\n\\\\In other words, $\\quad a_{i j}=-{a}_{j i}^{\\ast}$.\\\\All the diagonal elements of a Skew Hermitian matrix are either zeros or pure imaginary.\r\n\\begin{example}\r\n\t$\\left[\\begin{array}{ccc}i & 1-3 i & 4+7 i \\\\ -(1+3 i) & 0 &  i \\\\ -(4-7i) &  i & -5 i\\end{array}\\right]$\r\n\\end{example}\r\n\\subsection{Singular Matrix} If the determinant of the matrix is zero, then the matrix is known as singular matrix \\begin{example}\r\n\t $A=\\left[\\begin{array}{ll}1 & 2 \\\\ 3 & 6\\end{array}\\right]$ is singular matrix, because $|A|=6-6=0$..\r\n\\end{example}\r\n%............................................................................................\r\n\\subsection{Adjoint of a square matrix}\r\n\\textbf{Minor}:\\\\In a square matrix, each element possesses its own minor. The minor is defined as a value obtained from the determinant of a square matrix by deleting out a row and a column corresponding to the element of a matrix.\r\n\\\\\\\\\\textbf{Cofactor}:\\\\ The cofactor is defined the signed minor. An (i,j) cofactor is computed by multiplying\r\n(i, j) minor by $(-1)^{i+j}$ and is denoted by $C_{i j}$. The formula to find cofactor $=C_{i j}=(-1)^{i+j} . M_{i j}$ where $M_{i j}$ denotes the minor of $i^{t h}$ row and $j^{\\text {th }}$ column of a matrix.\r\n\\\\\\\\\\textbf{Adjoint:}\\\\\r\nLet $A=\\left[a_{i j}\\right]$ be a square matrix of order $n$ and let $C_{i j}$ be the cofactor of $a_{i j}$ in $A .$ Then the transpose of the matrix of cofactors of ellements of $A$ is called the adjoint of $A$ and is denoted by adj $A$.\r\n\\\\Thus, adj $A=\\left[C_{i j}\\right]^{T} \\Rightarrow(\\operatorname{adj} A)_{i j}=C_{j i}=$ cofactor of\r\n$a_{j i}$ in\r\n$A .$\r\n$$\r\n\\begin{array}{l}\r\n\t\\text { If } A=\\left[\\begin{array}{lll}\r\n\t\ta_{11} & a_{12} & a_{13} \\\\\r\n\t\ta_{21} & a_{22} & a_{23} \\\\\r\n\t\ta_{31} & a_{32} & a_{33}\r\n\t\\end{array}\\right] \\\\\r\n\t\\text { Then } \\operatorname{adj}(A)=\\left[\\begin{array}{lll}\r\n\t\tc_{11} & c_{12} & c_{13} \\\\\r\n\t\tc_{21} & c_{22} & c_{23} \\\\\r\n\t\tc_{31} & c_{32} & c_{33}\r\n\t\\end{array}\\right]=\\left[\\begin{array}{lll}\r\n\t\tc_{11} & c_{21} & c_{31} \\\\\r\n\t\tc_{12} & c_{22} & c_{32} \\\\\r\n\t\tc_{13} & c_{23} & c_{33}\r\n\t\\end{array}\\right]\r\n\\end{array}\r\n$$\r\n\\subsection{Inverse of a matrix}\r\nA square matrix of order $n$ is invertible if there exists a square matrix $B$ of the same order such that\r\n$$\r\nA B=I_{n}=B A\r\n$$\r\nIn the above case, $B$ is called the inverse of $A$ and is denoted by $A^{-1}$ where,\r\n$$\r\nA^{-1}=\\frac{(\\operatorname{adj} A)}{|A|}\r\n$$\r\n\\subsubsection{Properties}\r\n\\begin{itemize}\r\n\t\\item  $A^{-1}$ exists only when $A$ is non-singular, i.e. $|A| \\neq 0$.\r\n\t\\item The inverse of a matrix is unique.\r\n\t\\item Reversal laws: If $A$ and $B$ are invertible matrices of the same order, then,\r\n\t$$\r\n\t(A B)^{-1}=B^{-1} A^{-1}\r\n\t$$\r\n\t\\item If $A$ is an invertible square matrix, then, $$\\left(A^{T}\\right)^{-1}= \\left(A^{-1}\\right)^{T}$$\r\n   \\item The inverse of an invertible symmetric matrix is a symmetric matrix.\r\n\t\\item Let $A$ be a non-singular square matrix of order $n$. Then,\r\n\t$$\r\n\t|\\operatorname{adj} A|=|A|^{n-1}\r\n\t$$\r\n\t\\item If $A$ is an invertible square matrix, then, $$\\operatorname{adj} A^{T}=(\\operatorname{adj} A)^{T}$$\r\n\t\\item If $A$ and $B$ are non-singular square matrices of the same order. then, $$\\operatorname{adj}(A B)=(\\operatorname{adj} B)(\\operatorname{adj} A)$$\r\n\t\\item If $A$ is a non-singular matrix, then,\r\n\t$$\r\n\t\\left|A^{-1}\\right|=|A|^{-1}, \\text {i.e. }\\left|A^{-1}\\right|=\\frac{1}{|A|}\r\n\t$$\r\n\\end{itemize}\r\n\\begin{exercise}\r\n\tIf $A=\\left[\\begin{array}{rrr}3 & -3 & 4 \\\\ 2 & -3 & 4 \\\\ 0 & -1 & 1\\end{array}\\right],$ find $A^{-1}$\\end{exercise}\r\n\\begin{answer}\r\n$$\r\n\\begin{aligned}\r\n\tA&=\\left[\\begin{array}{rrr}3 & -3 & 4 \\\\ 2 & -3 & 4 \\\\ 0 & -1 & 1\\end{array}\\right]\\\\\r\n\t|A|&=3(-3+4)+3(2-0)+4(-2-0)=3+6-8=1\\\\\r\n\t\\text{cofactor of A}&=\\left[\\begin{array}{lll}\r\n\t\t(-3+4) & (-2-0) & (-2-0) \\\\\r\n\t\t(3-4) & (3-0) & (3-0) \\\\\r\n\t\t(-12+12) & (-12+8) & (-9+6)\r\n\t\\end{array}\\right]\\\\&= \\left[\\begin{array}{rrr}1 & -2 & -2 \\\\ -1 & 3 & 3 \\\\ 0 & -4 & -3\\end{array}\\right]\\\\\\text { Adj. } A&=\\left[\\begin{array}{rrr}1 & -1 & 0 \\\\ -2 & 3 & -4 \\\\ -2 & 3 & -3\\end{array}\\right]\\\\ A^{-1}&=\\frac{1}{|A|} \\text { Adj.A }\\\\ &=\\frac{1}{1}\\left[\\begin{array}{rrr}1 & -1 & 0 \\\\ -2 & 3 & -4 \\\\ -2 & 3 & -3\\end{array}\\right]=\\left[\\begin{array}{rrr}1 & -1 & 0 \\\\ -2 & 3 & -4 \\\\ -2 & 3 & -3\\end{array}\\right]\r\n\\end{aligned}$$\r\n\\end{answer}\r\n\t\r\n\r\n\\subsubsection{Rank of a matrix}\r\n\r\nThe rank of a matrix is said to be $r$ if,\r\n\\begin{itemize}\r\n\t\\item It has at least one non-zero minor of order $r$.\r\n\t\\item Every minor of $A$ of order higher than $r$ is zero. \r\n\\end{itemize}\r\n \r\n \\begin{note}\r\n \t\\begin{itemize}\r\n \t\t\\item Non-zero row is that row in which all the elements are not zero.\\\\\r\n \t\t\\item  $\\text{Rank(AB)}< \\text{Rank(A) or} \\text{ Rank(B)}$\r\n \t\tThe rank of the product matrix $A B$ of two matrices $A$ and $B$ is less than the rank of either of the matrices $A$ and $B$.\\\\\r\n \t\t\\item  Corresponding to every matrix $A$ of rank $r,$ there exist non-singular matrices $P$ and $Q$ such\r\n \t\tthat $P A Q=\\left[\\begin{array}{cc}I_{r} & 0 \\\\ 0 & 0\\end{array}\\right]$\r\n \t\\end{itemize}\r\n \\end{note}\r\n\\section{Determinants}\r\nThe concept of determinant and the notation were introduced by the renowned German mathematician and philosopher Gottfried Wilhelm von Leibniz. A determinant can be defined as  a number associated with any \\textbf{square} matrix. We'll write it as,  $\\operatorname{det}A$ or $|A|$. The determinant encodes a lot of information about the matrix. \r\n\\subsection{Properties}\r\n\\begin{enumerate}\r\n\t\\item The matrix is invertible exactly when the determinant is non-zero.\r\n\t\\item Determinant of identity Matrix is unity $\\operatorname{det} I=1$\r\n\t\\item If you exchange two rows of a matrix, you reverse the sign of its determinant from positive to negative or from negative to positive.\r\n\ti.e., If $\\left|\\begin{array}{ll}\r\n\t1 & 0 \\\\\r\n\t0 & 1\r\n\t\\end{array}\\right|=1$ ,\\ then, $\\left|\\begin{array}{ll}0 & 1 \\\\ 1 & 0\\end{array}\\right|=-1$\r\n\t\\item \r\n\t\\begin{itemize}\r\n\t\t\\item If we multiply one row of a matrix by $p$, the determinant is multiplied by $p:$\\\\\\\\ $\\left|\\begin{array}{rr}p a & p b \\\\ c & d\\end{array}\\right|=p\\left|\\begin{array}{cc}a & b \\\\ c & d\\end{array}\\right|$\r\n\t\t\\item The determinant behaves like a linear function on the rows of the\r\n\t\tmatrix:\\\\\\\\\r\n\t\t$\r\n\t\t\\left|\\begin{array}{cc}\r\n\t\ta+a^{\\prime} & b+b^{\\prime} \\\\\r\n\t\tc & d\r\n\t\t\\end{array}\\right|=\\left|\\begin{array}{ll}\r\n\t\ta & b \\\\\r\n\t\tc & d\r\n\t\t\\end{array}\\right|+\\left|\\begin{array}{cc}\r\n\t\ta^{\\prime} & b^{\\prime} \\\\\r\n\t\tc & d\r\n\t\t\\end{array}\\right|\r\n\t\t$\r\n\t\\end{itemize}\r\n\t\\item If any two rows or columns of a determinant are identical, then the value of the\r\n\tdeterminant is zero.\r\n\t\\item The determinant of a triangular matrix is the product of the diagonal elemets. This propery holds true for diagonal matrix also.\r\n\t\\item $\\operatorname{det} A=0$\\\\  Exactly when $A$ is singular.\r\n\t\\item $\\operatorname{det} A B=(\\operatorname{det} A)(\\operatorname{det} B)$\\\\\r\n\tAlthough the determinant of a sum does not equal the sum of the determinants, it is true that the determinant of a product equals the product of the determinants. For example:\r\n\t$$\r\n\t\\operatorname{det} A^{-1}=\\frac{1}{\\operatorname{det} A}\\quad \t(\\text{Because,}\\ A^{-1} A=1)\r\n\t$$\r\n\t(Note that if $A$ is singular then,\\  $A^{-1}$ does not exist and $\\operatorname{det} A^{-1}$ is undefined.) Also, $\\operatorname{det} A^{2}=(\\operatorname{det} A)^{2}$ and $\\operatorname{det} 2 A=2^{n} \\operatorname{det} A$\r\n\t(applying property 3 to each row of the matrix). \r\n\t\\item Determinant of Matrix and its Transpose are equal. $$\\operatorname{det} A^{T}=\\operatorname{det} A$$\r\n\\end{enumerate}\r\n\\section{Eigen values and eigen vectors}\r\n\r\n If $A=\\left[a_{i j}\\right]_{n \\times n}$ is a square matrix of order $n,$ then the vector equation $$A X=\\lambda X$$ Where $X$ is an unknown column vector and $\\lambda$ is an unknown scalar value, is called an eigenvalue problem. To solve this, we need to determine the value of $X$ 's and $\\lambda$ 's to satisfy the above mentioned vector.\r\n Take all unknowns to one side:$$(A-\\lambda I) X=0$$\r\n Where $I$ is a unit matrix with the same dimensions as $A$.\r\n (Note that $A X-\\lambda X=0$ does not simplify to $(A-\\lambda) X=0$ as you cannot subtract a scalar $\\lambda$ from a matrix $A$ ).\r\n For this system non-trivial solutions will only exist if the determinant of the coefficient matrix is zero.\r\n $$\r\n \\operatorname{det}(A-\\lambda I)=0\r\n $$\r\n \\begin{itemize}\r\n \t\\item \\textbf{Characteristic Polynomial}:\\\\ The determinant $|A-\\lambda I|$ when expanded will give a polynomial, which we call as characteristic polynomial of matrix $A$.With degree being the same order of $A$.\r\n \t\\item \\textbf{Characteristic Equation:}\\\\ The equation $|A-\\lambda I|=0$ is called the characteristic equation of the matrix $A$.\r\n \t\\item \\textbf{Characteristic Roots or Eigen Values:}\\\\ The roots of characteristic equation $|A-\\lambda I|=0$ are called characteristic roots of matrix .\r\n \\end{itemize}\r\nFor every $\\lambda$ there corresponds $X\\neq 0$ which satisfies the equation $A X=\\lambda X$\r\nThen $X$ is said to be Eigen vector corresponding to Eigen value $\\lambda$ of matrix $A$.\r\n\r\n\r\n\\section{Eigenvalues}\r\nThe eigenvalues of a square matrix A are the roots of the characteristic equation\r\n of A.\\\\\r\nHence an n $\\times$ n matrix has at least one eigenvalue and at most 'n' numerically\r\ndifferent eigenvalues.\r\n\\begin{note}\r\n\t\\begin{itemize}\r\n\t\t\\item \t The trace of a matrix is equal to the sum of the\r\n\t\teigenvalues of a matrix.\r\n\t\t\\[\r\n\t\t\\sum_{\\substack{i }} a_{ii}=\\sum_{\\substack{i }} \\lambda_{i}\r\n\t\t\\]\r\n\t\t\\item The product of the eigenvalues of a matrix is equal\r\n\t\tto the determinant of that matrix.\r\n\t\t\\[\r\n\t\tDet(A)=\\prod_{\\substack{i }} \\lambda_{i}\r\n\t\t\\]\r\n\t\t\r\n\t\\end{itemize}\r\n\t\r\n\\end{note}\r\n\\begin{exercise}\r\n\tObtain eigen values of the following matrices.\\\\$1.\\left[\\begin{array}{ccc}2 & 1 & 1\\\\ 1 & 2 & 1\\\\ 0 & 0& 1\\end{array}\\right]$\\\\$2.\\left[\\begin{array}{cc}4 & 1 \\\\ 2 & 3\\end{array}\\right]$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t$$\r\n\t\\begin{aligned}\r\n\t\t1.\\text{Trace}&=5, \\text{Determinant}=3\\Longrightarrow \\lambda=1,1,3(\\because 1+1+3=5,1\\times1\\times3=3)\\\\\r\n\t\t2.\\text{Trace}&=7, \\text{Determinant}=10\\Longrightarrow \\lambda=5,2(\\because 5+2=7,5\\times2=10)\t\r\n\t\\end{aligned}$$\r\n \r\n\\end{answer}\r\n\r\n\r\n\r\n\\subsection{Properties of eigen values}\r\n\\begin{itemize}\r\n\t\\item  Any square matrix $A$ and its transpose $A^{T}$ have the same eigen values.\r\n    \\item If $\\lambda_{1}, \\lambda_{2}, \\ldots \\lambda_{n}$ are the eigen values of $A,$ then the eigen values of,\r\n\t\\begin{itemize}\r\n\t\t\\item  $k A$ are $k \\lambda_{1}, \\quad k \\lambda_{2}, \\ldots \\ldots, k \\lambda_{n}$\\\\\r\n\t\t\\item  $A^{m}$ are $\\lambda_{1}^{m}, \\lambda_{2}^{m}, \\ldots \\ldots ., \\lambda_{n}^{m}$\\\\\r\n\t\t\\item $A^{-1}$ are $\\frac{1}{\\lambda_{1}}, \\frac{1}{\\lambda_{2}}, \\ldots, \\frac{1}{\\lambda_{n}}$.\r\n\t\\end{itemize}\r\n\t\\item  If $A$ and $B$ are similar matrices, i.e. $A=I B,$ then $A$ and $B$ have the same eigenvalues.\r\n\\item  If $A$ and $B$ are two matrices of same order, then the matrices $A B$ and $B A$ have the same eigenvalues.\r\n\\item  The eigenvalues of a triangular matrix are equal to the diagonal elements of the matrix.\r\n\\begin{example}\r\n\t\t$\\left[\\begin{array}{ccc}a & d & e \\\\ 0 & b & f \\\\ 0 & 0 & c\\end{array}\\right]$, $ \\lambda=a,b,c$\r\n\\end{example}\r\n\\item The eigen values of diagonal matrix are equal to the diagonal elements of the matrix.\r\n\\begin{example}\r\n\t$\\left[\\begin{array}{ccc}a & 0 & 0 \\\\ 0 & b & 0 \\\\ 0 & 0 & c\\end{array}\\right]$, $ \\lambda=a,b,c$\r\n\\end{example}\r\n\\item For matrix whose rows or columns are identical, then $ \\lambda=\\text{Trace},0,0,0,..(n-1)$\r\n\\begin{example}\r\n\t\t$\\left[\\begin{array}{ccc}a & a & a \\\\ a & a & a \\\\ a & a & a\\end{array}\\right]$, $ \\lambda=3a,0,0$,$\\left[\\begin{array}{ccc}2 & 1 & 3 \\\\ 2 & 1 & 3 \\\\ 2 & 1 & 3\\end{array}\\right]$, $ \\lambda=6,0,0$\r\n\\end{example}\r\n\\item For a skew symmetric matrix eigen value is , $\\lambda= 0,\\pm i\\sqrt {\\text{sum of squares of non diagonal elements}}$\r\n\\begin{example}\r\n$\\left[\\begin{array}{ccc}0 & -a & -b \\\\ a & 0 & -c \\\\ b & c & 0\\end{array}\\right]$ $ \\lambda=0,\\pm i\\sqrt{a^{2}+b^{2}+c^{2}}$\t\r\n\\end{example}\r\n\r\n\\end{itemize}\r\n\\begin{exercise}\r\n\t Find the characteristic roots of the matrix $\\left[\\begin{array}{rrr}6 & -2 & 2 \\\\ -2 & 3 & -1 \\\\ 2 & -1 & 3\\end{array}\\right]$ \\end{exercise}\r\n \\begin{answer}\r\n \t The characteristic equation of the given matrix is $\\left|\\begin{array}{rrr}6-\\lambda & -2 & 2 \\\\ -2 & 3-\\lambda & -1 \\\\ 2 & -1 & 3-\\lambda\\end{array}\\right|=0$\r\n \t\\\\\\\\$\\Rightarrow \\quad(6-\\lambda)\\left(9-6 \\lambda+\\lambda^{2}-1\\right)+2(-6+2 \\lambda+2)+2(2-6+2 \\lambda)=0$\r\n \t\\\\\\\\\t$\\Rightarrow$\r\n \t$-\\lambda^{3}+12 \\lambda^{2}-36 \\lambda+32=0$\r\n \t\\\\\\\\By trial, $\\lambda=2$ is a root of this equation. \\\\\\\\$\\Rightarrow \\quad(\\lambda-2)\\left(\\lambda^{2}-10 \\lambda+16\\right)=0 \\\\\\\\\\Rightarrow(\\lambda-2)(\\lambda-2)(\\lambda-8)=0$\r\n \t\\\\\\\\$\\Rightarrow \\quad \\lambda=2,2,8$ are the characteristic roots or Eigen values.\r\n \t\r\n \\end{answer}\r\n \r\n\\begin{exercise}\r\n\t The matrix $A$ is defined as $A=\\left[\\begin{array}{rrr}1 & 2 & -3 \\\\ 0 & 3 & 2 \\\\ 0 & 0 & -2\\end{array}\\right]$Find the eigen values of $3 A^{3}+5 A^{2}-6 A+2 I$\r\n\t\\end{exercise}\r\n\\begin{answer}\r\n\t \r\n\t\\begin{align*}\r\n\t\t|A-\\lambda I|&=0\\\\\r\n\t\t\\Rightarrow \\quad(1-\\lambda)(3-\\lambda)(-2-\\lambda)&=0\\\\ \\text { or } \\lambda&=1,3,-2\\\\\r\n\t\t\\text{ie,Eigen values of } A&=1,3,-2\\\\\r\n\t\t\\text{Eigen values of } A^{3}&=1,27,-8\\\\\r\n\t\t\\text{Eigen values of }A^{2}&=1,9,4\\\\\r\n\t\t\\text{Eigen values of }I&=1,1,1\\\\\r\n\t\t\\text{Eigen values of }3 A^{3}+5 A^{2}-6 A+2 I,\\\\\r\n\t\t\\text{First eigen value}&=3(1)^{3}+5(1)^{3}-6(1)+2(1)=4\\\\\t\r\n\t\t\\text{Second eigen value}&=3(27)+5(9)-6(3)+2(1)=110\\\\\r\n\t\t\\text{Third eigen value}&=3(-8)+5(4)-6(-2)+2(1)=10\\\\\\text{Then Required eigen values are } 4,110,10\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\t\r\n\\subsection{Eigen vectors}\r\n\\subsubsection{Properties of eigen vectors}\r\n\\begin{itemize}\r\n\t\\item The eigen vector $X$ of a matrix $A$ is not unique.\r\n\t\\item  If $\\lambda_{1}, \\lambda_{2}, \\ldots, \\lambda_{n}$ be distinct eigen values of an $n \\times n$ matrix then corresponding eigen vectors $X_{1}, X_{2}, \\ldots \\ldots ., X_{n}$ form a linearly independent set.\r\n\t\\item If two or more eigen values are equal it may or may not be possible to get linearly independent eigen vectors corresponding to the equal roots.\r\n\t\\item  Two eigen vectors $X_{1}$ and $X_{2}$ are called orthogonal vectors if $X_{1}^{T} X_{2}=0$.\r\n\t\\item Eigen vectors of a symmetric matrix corresponding to different eigen values are orthogonal.\r\n\t\r\n\\end{itemize}\r\n\\begin{note}\r\n\t  To find normalised form of $\\left[\\begin{array}{l}a \\\\ b \\\\ c\\end{array}\\right],$ we divide each element by $\\sqrt{a^{2}+b^{2}+c^{2}}$\r\n\t  \\begin{exampleT}\r\n\t  \tnormalised form of $\\left[\\begin{array}{l}1 \\\\ 2 \\\\ 3\\end{array}\\right]$ is $\\left[\\begin{array}{l}1 / \\sqrt{14} \\\\ 2 / \\sqrt{14} \\\\ 2 / \\sqrt{14}\\end{array}\\right]$\\\\$ \\left[ \\because \\sqrt {1^{2}+2^{2}+3^{2}}=\\sqrt{14}\\right]$\r\n\t  \\end{exampleT}\r\n\\end{note} \r\n\r\n\\begin{exercise}\r\n\t Find the eigen values and eigen vectors of matrix $A=\\left[\\begin{array}{lll}3 & 1 & 4 \\\\ 0 & 2 & 6 \\\\ 0 & 0 & 5\\end{array}\\right]$\\end{exercise}\r\n \\begin{answer}\r\n \t\\begin{align*}\r\n \t\t|A-\\lambda I|&=\\left|\\begin{array}{ccc}\r\n \t\t\t3-\\lambda & 1 & 4 \\\\\r\n \t\t\t0 & 2-\\lambda & 6 \\\\\r\n \t\t\t0 & 0 & 5-\\lambda\r\n \t\t\\end{array}\\right|\\\\&=(3-\\lambda)(2-\\lambda)(5-\\lambda)\\\\\r\n \t\\end{align*}\r\n \t\\begin{align*}\r\n \t\t\\text{Hence the characteristic equation of matrix $A$ is given by},\\\\\r\n \t\t|A-\\lambda I| &=0 \\\\\\Rightarrow (3-\\lambda)(2-\\lambda)(5-\\lambda)&=0 \\\\\r\n \t\t\\therefore  \\lambda &=2,3,5\\\\\r\n \t\t\\text{Thus the eigen values of matrix A are 2,3,5 .}\r\n \t\t\\\\\\text{The eigen vectors of the matrix A corresponding to the eigen value}\\\\\\text{$\\lambda$ is given by the nonzero solution of the equation (A-$\\lambda I)$ X=0}\\\\\r\n \t\t\\left[\\begin{array}{lll}\r\n \t\t\t3-\\lambda & 1 & 4 \\\\\r\n \t\t\t0 & 2-\\lambda & 6 \\\\\r\n \t\t\t0 & 0 & 5-\\lambda\r\n \t\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n \t\t\tx_{1} \\\\\r\n \t\t\tx_{2} \\\\\r\n \t\t\tx_{3}\r\n \t\t\\end{array}\\right]=\\left[\\begin{array}{l}\r\n \t\t\t0 \\\\\r\n \t\t\t0 \\\\\r\n \t\t\t0\r\n \t\t\\end{array}\\right]\\\\\r\n \t\t\\text{When $\\lambda=2,$ the corresponding eigen vector is given by}\\\\\r\n \t\t\\left[\\begin{array}{lll}\r\n \t\t\t3-2 & 1 & 4 \\\\\r\n \t\t\t0 & 2-2 & 6 \\\\\r\n \t\t\t0 & 0 & 5-2\r\n \t\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n \t\t\tx_{1} \\\\\r\n \t\t\tx_{2} \\\\\r\n \t\t\tx_{3}\r\n \t\t\\end{array}\\right]=\\left[\\begin{array}{l}\r\n \t\t\t0 \\\\\r\n \t\t\t0 \\\\\r\n \t\t\t0\r\n \t\t\\end{array}\\right]\\\\\r\n \t\t\\Rightarrow\\left[\\begin{array}{lll}\r\n \t\t\t1 & 1 & 4 \\\\\r\n \t\t\t0 & 0 & 6 \\\\\r\n \t\t\t0 & 0 & 3\r\n \t\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n \t\t\tx_{1} \\\\\r\n \t\t\tx_{2} \\\\\r\n \t\t\tx_{3}\r\n \t\t\\end{array}\\right]=\\left[\\begin{array}{l}\r\n \t\t\t0 \\\\\r\n \t\t\t0 \\\\\r\n \t\t\t0\r\n \t\t\\end{array}\\right]\\\\\r\n \t\t\\begin{array}{r}\r\n \t\t\tx_{1}+x_{2}+4 x_{3}=0 \\\\\r\n \t\t\t0 x_{1}+0 x_{2}+6 x_{3}=0 \\\\\r\n \t\t\t\\frac{x_{1}}{6-0}=\\frac{x_{2}}{0-6}=\\frac{x_{3}}{0-0}=k\r\n \t\t\\end{array}\\\\\r\n \t\t\\Rightarrow \\quad \\frac{x_{1}}{1}=\\frac{x_{2}}{-1}=\\frac{x_{3}}{0}=k \\quad \\Rightarrow \\quad x_{1}=k, x_{2}=-k, x_{3}=0\\\\\r\n \t\t\\text { Hence } X_{1}=\\left[\\begin{array}{r}\r\n \t\t\tk \\\\\r\n \t\t\t-k \\\\\r\n \t\t\t0\r\n \t\t\\end{array}\\right]=k\\left[\\begin{array}{r}\r\n \t\t\t1 \\\\\r\n \t\t\t-1 \\\\\r\n \t\t\t0\r\n \t\t\\end{array}\\right] \\\\\r\n \t\t\\text { can be taken as an eigen vector of A corresponding to the eigen } \\\\\r\n \t\t\\text { value } \\lambda=2\r\n \t\\end{align*}\r\n \\end{answer}\r\n\t\r\n\r\n\r\n\\subsection{Cayley-Hamilton theorem}\r\nAccording to the Cayley-Hamilton theorem, every square matrix satisfies its own characteristic equations. \r\n\\begin{equation}\r\n|A-\\lambda I|=(-1)^{n}\\left(\\lambda^{n}+a_{1} \\lambda^{n-1}+a_{2} \\lambda^{n-2}+\\cdots+a_{n}\\right)\r\n\\label{cayley hamilton}\r\n\\end{equation}\r\n\r\nHence, if  equation \\ref{cayley hamilton}  is the characteristic polynomial of a matrix $A$ of order $n$, then the matrix equation,\r\n\\begin{equation}\r\nX^{n}+a_{1} X^{n-1}+a_{2} X^{n-2}+\\cdots+a_{n} I=0\r\n\\end{equation}\r\n\r\nIs satisfied by $X=A$.ie,\r\n\\begin{equation}\r\nA^{n}+a_{1} A^{n-1}+a_{2} A^{n-2}+\\ldots+a_{n} I=0\r\n\\end{equation} \r\n\\begin{exercise}\r\n\t Verify Cayley-Hamilton theorem for the matrix $A=\\left(\\begin{array}{cc}1 & 2 \\\\ 2 & -1\\end{array}\\right)$ and hence find $A^{-1}$.\\end{exercise}\r\n\r\n\r\n\\begin{answer}\r\n The characteristic equation of the matrix is \r\n\r\n\\begin{align*}\r\n\t| A-\\lambda I|&=0\\\\\r\n\t\\begin{array}{cc}|1-\\lambda & 2 \\\\ 2 & -1-\\lambda\\end{array}|=0\\\\\r\n\t(1-\\lambda)(-1-\\lambda)-4&=0\\\\ \\Rightarrow-1+\\lambda^{2}-4&=0 \\\\\\Rightarrow \\lambda^{2}-5&=0\\\\\r\n\t\\newline\\text{By Cayley-Hamilton Theorem,} A^{2}-5 I&=0\\\\\r\n\tA^{2}=A . A &=\\left[\\begin{array}{rr}1 & 2 \\\\ 2 & -1\\end{array}\\right]\\left[\\begin{array}{rr}1 & 2 \\\\ 2 & -1\\end{array}\\right]=\\left[\\begin{array}{cc}5 & 0 \\\\ 0 & 5\\end{array}\\right] \\\\A^{2}-5 I&=\\left[\\begin{array}{ll}5 & 0 \\\\ 0 & 5\\end{array}\\right]-5\\left[\\begin{array}{ll}1 & 0 \\\\ 0 & 1\\end{array}\\right]\\\\&=\\left[\\begin{array}{ll}5 & 0 \\\\ 0 & 5\\end{array}\\right]+\\left[\\begin{array}{rr}-5 & 0 \\\\ 0 & -5\\end{array}\\right]\\\\&=\\left[\\begin{array}{ll}0 & 0 \\\\ 0 & 0\\end{array}\\right]=0 \\\\\r\n\t\\text{ Thus Cayley hamilton theorem is verified.}\\\\\r\n\tA^{2}-5 I&=0\\\\\\text{Multiplying by}\\ A^{-1} \\ \\text{we get},\\\\\r\n\tA-5 A^{-1}&=0 \\\\\\Rightarrow A^{-1}=\\frac{1}{5} A \\\\\\Rightarrow A^{-1}=\\frac{1}{5}\\left[\\begin{array}{cc}\r\n\t\t1 & 2 \\\\\r\n\t\t2 & -1\r\n\t\\end{array}\\right]=\\left[\\begin{array}{cc}\r\n\t\t\\frac{1}{5} & \\frac{2}{5} \\\\\r\n\t\t\\frac{2}{5} & -\\frac{1}{5}\r\n\t\\end{array}\\right]\r\n\\end{align*}\r\n\r\n\\end{answer}\r\n\r\n\\subsection{Similiarity transformation}\r\nLet $A$ and $B$ be two square matrices of order $n$. Then $B$ is said to be similar to $A$ if there exists a non-singular matrix $P$ such that\r\n\\begin{equation}\r\nB=P^{-1} A P\r\n\\end{equation}\r\n\r\nThis transformation that gives B from A is called a similarity transformation.\r\n\\begin{note}\r\n\tIf A and B are similiar matrices then both of them have same eigen values.Furthermore, if $\\mathbf{x}$ is an eigenvector of $\\mathbf{A},$ then $\\mathbf{y}=\\mathbf{P}^{-1} \\mathbf{x}$ is an eigenvector of $\\mathbf{B}$ corresponding to the same eigenvalue.\\end{note}\r\n\\subsection{Diagonalisation}\r\nDiagonalisation of a matrix A is the process of reduction of A to a diagonal form D.\r\n\r\nIf an $n \\times n$ matrix $\\mathbf{A}$ has a basis of eigenvectors, then\r\n\\begin{equation}\r\n\\mathbf{D}=\\mathbf{P}^{-1} \\mathbf{A} \\mathbf{P}\r\n\\end{equation}\r\nis diagonal, with the eigenvalues of $\\mathbf{A}$ as the entries on the main diagonal. Here $\\mathbf{X}$ is the matrix with these eigenvectors as column vectors. Also,\r\n\\begin{equation}\r\n\\mathbf{D}^{m}=\\mathbf{P}^{-1} \\mathbf{A}^{m} \\mathbf{P} \\quad(m=2,3, \\cdots)\r\n\\end{equation}\r\n\\subsubsection{Theorem on diagonalisation of matrix}\r\n\\begin{theorem}\r\n\tIf a square matrix $A$ of order $n$ has $n$ linearly independent eigen vectors, then a matrix $P$ can be found such that $P^{-1} A P$ is a diagonal matrix.\r\n\\end{theorem}\r\n\r\n\t$\\bullet$ The square matrix $P$, which diagonalises $A$, is found by grouping the eigen vectors of $A$ into square-matrix and the resulting diagonal matrix has the eigen values of $A$ as its diagonal elements.\r\n\t \r\n\\begin{exercise}\r\n\tLet $A=\\left[\\begin{array}{rrr}6 & -2 & 2 \\\\ -2 & 3 & -1 \\\\ 2 & -1 & 3\\end{array}\\right]$ Find matrix $P$ such that $P^{-1} A P$ is diagonal matrix.\\end{exercise}\r\n\\begin{answer}\r\nThe characteristic equation of the  matrix $A$\\\\\r\n$$\\left|\\begin{array}{rrr}6-\\lambda & -2 & 2 \\\\ -2 & 3-\\lambda & -1 \\\\ 2 & -1 & 3-\\lambda\\end{array}\\right|=0$$\r\n\\begin{align*}\r\n\t(6-\\lambda)\\left[9+\\lambda^{2}-6 \\lambda-1\\right]+2[-6+2 \\lambda+2]+2[2-6+2 \\lambda]&=0 \\\\(6-\\lambda)\\left(\\lambda^{2}-6 \\lambda+8\\right)-8+4 \\lambda-8+4 \\lambda&=0 \\\\\r\n\t6 \\lambda^{2}-36 \\lambda+48-\\lambda^{3}+6 \\lambda^{2}-8 \\lambda-16+8 \\lambda&=0 \\\\-\\lambda^{3}+12 \\lambda^{2}-36 \\lambda+32=0 \\quad \\Rightarrow \\quad \\lambda^{3}-12 \\lambda^{2}+36 \\lambda-32&=0 \\\\\r\n\t(\\lambda-2)^{2}(\\lambda-8)=0 \\quad \\Rightarrow \\quad \\lambda=2,2,8\r\n\\end{align*}\r\nEigen vector for $\\lambda=2$\\\\\r\n\\begin{align*}\r\n\t\\left[\\begin{array}{ccc}\r\n\t\t4 & -2 & 2 \\\\\r\n\t\t-2 & 1 & -1 \\\\\r\n\t\t2 & -1 & 1\r\n\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\tx_{1} \\\\\r\n\t\tx_{2} \\\\\r\n\t\tx_{3}\r\n\t\\end{array}\\right]&=\\left[\\begin{array}{l}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t0\r\n\t\\end{array}\\right]\\\\\\left[\\begin{array}{rrr}\r\n\t\t2 & -1 & 1 \\\\\r\n\t\t-2 & 1 & -1 \\\\\r\n\t\t2 & -1 & 1\r\n\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\tx_{1} \\\\\r\n\t\tx_{2} \\\\\r\n\t\tx_{3}\r\n\t\\end{array}\\right]&=\\left[\\begin{array}{l}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t0\r\n\t\\end{array}\\right] \\begin{array}{l}\r\n\t\tR_{2} \\rightarrow R_{1}+R_{2} \\\\\r\n\t\tR_{3} \\rightarrow R_{2}+R_{3}\r\n\t\\end{array}\\\\\r\n\t\\left[\\begin{array}{ccc}\r\n\t\t2 & -1 & 1 \\\\\r\n\t\t0 & 0 & 0 \\\\\r\n\t\t0 & 0 & 0\r\n\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\tx_{1} \\\\\r\n\t\tx_{2} \\\\\r\n\t\tx_{3}\r\n\t\\end{array}\\right]&=\\left[\\begin{array}{l}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t0\r\n\t\\end{array}\\right] \\text { or } 2 x_{1}-x_{2}+x_{3}=0\\\\\r\n\t\\intertext{This equation is satisfied by $ x_{1}=0, x_{2}=1, x_{3}=1$}\r\nX_{1}&=\\left[\\begin{array}{l}\r\n\t\t0 \\\\\r\n\t\t1 \\\\\r\n\t\t1\r\n\t\\end{array}\\right]\r\n\t\\text{and again }\r\n\tx_{1}=1, x_{2}=3, x_{3}=1\r\n\t\\\\X_{2}&=\\left[\\begin{array}{l}\r\n\t\t1 \\\\\r\n\t\t3 \\\\\r\n\t\t1\r\n\t\\end{array}\\right]\r\n\t\\intertext{Eigen vector for $ \\lambda=8$}\\begin{array}{r}\r\n\t\t{\\left[\\begin{array}{rrr}\r\n\t\t\t\t-2 & -2 & 2 \\\\\r\n\t\t\t\t-2 & -5 & -1 \\\\\r\n\t\t\t\t2 & -1 & -5\r\n\t\t\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\t\t\tx_{1} \\\\\r\n\t\t\t\tx_{2} \\\\\r\n\t\t\t\tx_{3}\r\n\t\t\t\\end{array}\\right]=\\left[\\begin{array}{l}\r\n\t\t\t\t0 \\\\\r\n\t\t\t\t0 \\\\\r\n\t\t\t\t0\r\n\t\t\t\\end{array}\\right]} \\\\\r\n\t\t-2 x_{1}-2 x_{2}+2 x_{3}=0 \\\\\r\n\t\t-2 x_{1}-5 x_{2}-x_{3}=0\r\n\t\\end{array}\r\n\\end{align*}\r\n\\begin{align*}\r\n\t\\frac{x_{1}}{2+10}&=\\frac{x_{2}}{-4-2}=\\frac{x_{3}}{10-4}\\\\ \\Rightarrow \\frac{x_{1}}{12}&=\\frac{x_{2}}{-6}=\\frac{x_{3}}{6}\\\\ \\Rightarrow \\frac{x_{1}}{2}&=\\frac{x_{2}}{-1}=\\frac{x_{3}}{1}\\\\X_{3}&=\\left[\\begin{array}{r}\r\n\t\t2 \\\\\r\n\t\t-1 \\\\\r\n\t\t1\r\n\t\\end{array}\\right]\r\n\\end{align*}\r\n\\begin{align*}\r\n\t\\therefore \\quad P&=\\left[\\begin{array}{rrr}\r\n\t\t0 & 1 & 2 \\\\\r\n\t\t1 & 3 & -1 \\\\\r\n\t\t1 & 1 & 1\r\n\t\\end{array}\\right], \\quad P^{-1}=-\\frac{1}{6}\\left[\\begin{array}{rrr}\r\n\t\t4 & 1 & -7 \\\\\r\n\t\t-2 & -2 & 2 \\\\\r\n\t\t-2 & 1 & -1\r\n\t\\end{array}\\right]\\intertext { Now }\\\\ \\quad P^{-1} A P&=-\\frac{1}{6}\\left[\\begin{array}{rrr}\r\n\t\t4 & 1 & -7 \\\\\r\n\t\t-2 & -2 & 2 \\\\\r\n\t\t-2 & 1 & -1\r\n\t\\end{array}\\right]\\left[\\begin{array}{rrr}\r\n\t\t6 & -2 & 2 \\\\\r\n\t\t-2 & 3 & -1 \\\\\r\n\t\t2 & -1 & 3\r\n\t\\end{array}\\right]\\left[\\begin{array}{rrr}\r\n\t\t0 & 1 & 2 \\\\\r\n\t\t1 & 3 & -1 \\\\\r\n\t\t1 & 1 & 1\r\n\t\\end{array}\\right]|\\\\&=\\left[\\begin{array}{lll}\r\n\t\t2 & 0 & 0 \\\\\r\n\t\t0 & 2 & 0 \\\\\r\n\t\t0 & 0 & 8\r\n\t\\end{array}\\right]\r\n\\end{align*}\r\n\r\n\\end{answer}\r\n\r\n\r\n\r\n\\subsubsection{Power of a matrix}\r\nWe can obtain powers of a matrix by using diagonalisation.\r\nWe know that\r\n$$\r\nD=P^{-1} A P\r\n$$\r\n\\\\We have ,\\ $${D}^{m}={P}^{-1} {A}^{m} {P} \\quad(m=2,3, \\cdots)$$\r\n\\\\Pre-multiply by $P$ and post-multiply by $P^{-1}$ we get\\\\\r\n$$\r\n\\begin{aligned}\r\n\tP D^{m} P^{-1} &=P\\left(P^{-1} A^{m} P\\right) P^{-1} \\\\\r\n\t&=\\left(P P^{-1}\\right) A^{m}\\left(P P^{-1}\\right) \\\\\r\n\t&=A^{m}\r\n\\end{aligned}\r\n$$\r\n\\begin{itemize}\r\n\t\\item  Find eigen values for a square matrix $A$.\r\n\t\\item  Find eigen vectors to get the matrix $P$.\r\n\t\\item  Find the diagonal matrix $D,$ by the formula $D=P^{-1} \\mathrm{AP}$\r\n\t\\item  Obtain $A^{m}$ by the formula $A^{m}=P D^{m} P^{-1}$.\r\n\\end{itemize}\r\n\\begin{exercise}\r\n\tEvaluate $A^{50}$ for the matrix $A=\\left[ \\begin{array}{cc}\r\n\t\\frac{4}{3}& \\frac{\\sqrt{2}}{3}\\\\\r\n\t\\frac{\\sqrt{2}}{3}& \\frac{5}{3} \r\n\t\\end{array}\\right]$\\\\Their eigen values and eigen vectors are given as,$1\\Longrightarrow \\left\\lbrace \\sqrt{2},1\\right\\rbrace $ and for $2\\Longrightarrow \\left\\lbrace  1,\\sqrt{2}\\right\\rbrace $\\end{exercise}\r\n\\begin{answer}\r\n\t$P=\\left[ \\begin{array}{cc}\r\n\t\t\\sqrt{2}& 1\\\\\r\n\t\t1& \\sqrt{2} \r\n\t\\end{array}\\right]\\Longrightarrow p^{-1}AP=\\left[ \\begin{array}{cc}\r\n\t\t1& 0\\\\\r\n\t\t0& 2 \r\n\t\\end{array}\\right]=D$\\\\\r\n\t$|A|\\neq 0\\Longrightarrow\\text{matrix A is non singular}$\\\\\r\n\thence, $$\r\n\t\\begin{aligned}\r\n\t\tA^{50}=PD^{50}P^{-1}&=\\left[ \\begin{array}{cc}\r\n\t\t\t\\sqrt{2}& 1\\\\\r\n\t\t\t1& \\sqrt{2} \r\n\t\t\\end{array}\\right] \\left[ \\begin{array}{cc}\r\n\t\t\t1& 0\\\\\r\n\t\t\t0& 2^{50} \r\n\t\t\\end{array}\\right] \\left[ \\begin{array}{cc}\r\n\t\t\t\\frac{\\sqrt{2}}{3}& \\frac{-1}{3}\\\\\r\n\t\t\t\\frac{{1}}{3}& \\frac{\\sqrt{2}}{3} \r\n\t\t\\end{array}\\right]\r\n\t\t\\\\&=\\frac{1}{3} \\left[ \\begin{array}{cc}\r\n\t\t\t2^{50}+2& 2^{50}-{\\sqrt{2}}\\\\\r\n\t\t\t(2^{50}-1)\\sqrt{2}& 2^{51}+1 \r\n\t\t\\end{array}\\right]\r\n\t\\end{aligned}$$\r\n\t\r\n\t\r\n\\end{answer}\r\n\r\n\\subsubsection{Exponential of matrix}\r\nAccording to similarity tranformation, $$D=P^{-I} A P \\quad \\Rightarrow A=P D P^{-1}$$Then,\r\n$$(\\exp A)=P(e x p D) P^{-1}$$\r\n\\begin{exercise}\r\n\tEvaluate $ e^{A}$ where matrix A is given by, $\\left[ \\begin{array}{cc}\r\n\t\t1& 0\\\\\r\n\t\t0& 2 \r\n\t\\end{array}\\right] $\r\nThe eigen values of the given diagonal matrix are,$ \\lambda_{1}=1  \\text{and}  \\lambda_{2}=2$\r\n\\end{exercise}\r\n\\begin{answer}\r\nIt is given that,\r\n$$ \\begin{aligned}\r\n\t(\\exp A)&=P(e x p D) P^{-1} \\\\\r\n\t&\\text{then,}\\\\\r\n\te^{A}=\\left[ \\begin{array}{cc}\r\n\t\te^{\\lambda_{1}}& 0\\\\\r\n\t\t0& e^{\\lambda_{2}}\r\n\t\\end{array}\\right]&=\\left[ \\begin{array}{cc}\r\n\te^{1}& 0\\\\\r\n\t0& e^{2}\r\n\\end{array}\\right]\r\n\\end{aligned}$$\r\n\\end{answer}\r\n\\subsubsection{Logarithm of a matrix}\r\nAccording to similarity tranformation, $$D=P^{-I} A P \\quad \\Rightarrow A=P D P^{-1}$$\r\n$$\r\n\\Rightarrow(\\ln A)=P(\\ln D) P^{-1}\r\n$$\r\n\\section{Applications}\r\n\\subsection{Matrix representation of vector}\r\nWe can use matrix formalism to represent vectors.a vector can be representsed as a one-column matrix.\\\\\r\n$\\vec{A}=a\\hat{i}+b\\hat{j}+c\\hat{k}$\r\n$\\Longrightarrow \\left[ \\begin{array}{c}\r\n\ta\\\\b\\\\c\\end{array}\\right] $\r\n\\\\We can also use the matrix formalism to generate scalar products, but in\r\norder to do so we must convert one of the column vectors into a row vector. The operation\r\nof transposition provides a way to do this. Thus, letting $a$ and $b$ stand for vectors in $R^{3}$,\\\\\\\\\r\nif $\\vec{A}=a_{1}\\hat{i}+a_{2}\\hat{j}+a_{3}\\hat{k}$ and $\\vec{B}=b_{1}\\hat{i}+b_{2}\\hat{j}+b_{3}\\hat{k}$ then their scalar product,\r\n$${A} \\cdot {B} \\quad \\longrightarrow \\quad\\left(\\begin{array}{lll}a_{1} & a_{2} & a_{3}\\end{array}\\right)\\left(\\begin{array}{l}b_{1} \\\\ b_{2} \\\\ b_{3}\\end{array}\\right)=a_{1} b_{1}+a_{2} b_{2}+a_{3} b_{3}$$\r\nIf in a matrix context we regard a and ${b}$ as column vectors, the above equation assumes the form\r\n$$\r\n{A} \\cdot {B} \\quad \\longrightarrow  {A}^{T} {B}\r\n$$\r\n\\subsection{Cooordinate transformation}\r\nMatrices are linear operators or maps such as rotations. In many problems we will need to use different coordinate systems inorder to describe different vector quantities .Components of a vector are transformed when we change the reference frame.\r\n\\newline Let $(x, y, z)$ be a cartesian coordinate system in a three dimension space. \\\\\\\\Let $\\vec{r}=x \\hat{i}+y \\hat{j}$ be a vector in $x-y$ plane. \\\\\\\\If we consider a rotation of coordinate system about $z$ -axis through an angle $\\theta$ in anticlockwise sense\r\nand indicate the new axis by then the components of the same vector \\ $\\vec{r}=x^{\\prime} \\hat{i}+y^{\\prime} \\hat{j}^{\\prime}$\\  relative to the new system may be expressed as,\r\n\\\\\\\\$x^{\\prime}=x \\cos \\theta+y \\sin \\theta$\\\\\r\n$y^{\\prime}=-x \\sin \\theta+y \\cos \\theta$\\\\\\\\\r\nThen equations in matrix form can be represented as ,\\\\\\\\\r\n$\\left[\\begin{array}{l}x \\\\ y\\end{array}\\right]=\\left[\\begin{array}{cc}\\cos \\theta & \\sin \\theta \\\\ -\\sin \\theta & \\cos \\theta\\end{array}\\right]\\left[\\begin{array}{l}x \\\\ y\\end{array}\\right]=R_{z}(\\theta)\\left[\\begin{array}{l}x \\\\ y\\end{array}\\right]$\r\n\\\\\\\\\r\nWhere $R_{z}(\\theta)$ is the transformation matrix corresponding to the rotation in $x-y$ plane about $z$ -axis.\\\\\\\\\\textbf{Properties of Transformation matrix matrix}\r\n\\begin{itemize}\r\n\t\\item $R_{z}(\\theta)$ is orthogonal matrix.\r\n\t\\item Determinant of $R_{=}(\\theta)$ is 1.\r\n\t\\item  Eigenvalues of $R_{z}(\\theta)$ are $e^{i \\theta}$ and $e^{-i \\theta}$.\r\n\\end{itemize}\r\nLet us consider a vector in space i.e. $\\vec{r}=x \\hat{i}+y \\hat{j}+z \\hat{k} .$ Here, three types of rotation is possible:\r\n\\\\\\\\\\textbf{Type I: Rotation about z-axis:}\r\nRotation matrix. $$R_{z}(\\theta)=\\left[\\begin{array}{ccc}\\cos \\theta & \\sin \\theta & 0 \\\\ -\\sin \\theta & \\cos \\theta & 0 \\\\ 0 & 0 & 1\\end{array}\\right]$$\r\n\\\\\\textbf{Type  II: Rotation about x-axis:}\r\nRotation matrix. $$R_{x}(\\theta)=\\left[\\begin{array}{ccc}1 & 0 & 0 \\\\ 0 & \\cos \\theta & \\sin \\theta \\\\ 0 & -\\sin \\theta & \\cos \\theta\\end{array}\\right]$$\r\n\\textbf{Type III: Rotation about y-axis:}\r\nRotation matrix. $$R_{y}(\\theta)=\\left[\\begin{array}{ccc}\\cos \\theta & 0 & -\\sin \\theta \\\\ 0 & 1 & 0 \\\\ \\sin \\theta & 0 & \\cos \\theta\\end{array}\\right]$$\r\n%.................................net..............................................\r\n\r\n\\section{Linear system of equations and  their solutions}\r\nOne of the major applications of determinants is in the establishment of a condition for the existence of a nontrivial solution for a set of linear homogeneous algebraic equations.\\\\\r\nLet $\\mathrm{a}_{1}, \\ldots \\mathrm{a}_{\\mathrm{n}}$ be elements of a vector  field , and let $\\mathrm{x}_{1}, \\ldots \\mathrm{x}_{\\mathrm{n}}$ be unknowns\r\n(also called variables or indeterminates). Then an equation of the form\r\n$$\r\n\\mathrm{a}_{1} \\mathrm{x}_{1}+\\cdots+\\mathrm{a}_{\\mathrm{n}} \\mathrm{x}_{\\mathrm{n}}=\\mathrm{y}\r\n$$\r\nis called a linear equation in $n$ unknowns (over the vector field.)\r\nin which case we say that $\\left(c_{1}, \\ldots, c_{n}\\right)$ satisfies the equation. The set of all such solutions is called the solution set (or the general solution).\r\nNow consider the following system of ${m}$ linear equations in '${n}$' unknowns:\r\n$$\r\n\\begin{array}{c}\r\n\ta_{11} x_{1}+\\cdots+a_{1 n} x_{n}=y_{1} \\\\\r\n\ta_{21} x_{1}+\\cdots+a_{2 n} x_{n}=y_{2} \\\\\r\n\t\\vdots \\\\\r\n\ta_{m 1} x_{1}+\\cdots+a_{m n} x_{n}=y_{m}\r\n\\end{array}\r\n$$\r\nWe abbreviate this system as,\r\n$$\r\n\\sum_{j=1}^{n} a_{i j} x_{j}=y_{i}, \\quad i=1, \\ldots m\r\n$$\r\nSuppose we have a system of '$ i $' linear equation in '$ j $' unknowns, such as,\r\n$$\r\n\\begin{array}{c}\r\n\ta_{11} x_{1}+a_{12} x_{2}+\\cdots+a_{i j} x_{j}=b_{1} \\\\\r\n\ta_{221} x_{1}+a_{22} x_{2}+\\cdots+a_{2 j} x_{j}=b_{2} \\\\\r\n\t: \\quad: \\quad: \\quad: \\quad:\r\n\\end{array}\r\n$$\r\nThe above system of equations can be written in the matrix form as follows:\r\n$$\r\n\\left[\\begin{array}{cccc}\r\n\ta_{11} & a_{12} & \\cdots & a_{i j} \\\\\r\n\ta_{21} & a_{22} & \\cdots & a_{2 j} \\\\\r\n\t\\vdots & \\vdots & \\vdots & \\vdots \\\\\r\n\ta_{i 1} & a_{i 2} & \\cdots & a_{i j}\r\n\\end{array}\\right]\\left[\\begin{array}{c}\r\n\tx_{1} \\\\\r\n\tx_{2} \\\\\r\n\t\\vdots \\\\\r\n\tx_{j}\r\n\\end{array}\\right]=\\left[\\begin{array}{c}\r\n\tb_{1} \\\\\r\n\tb_{2} \\\\\r\n\t\\vdots \\\\\r\n\tb_{j}\r\n\\end{array}\\right]\r\n$$\r\nThe equation can be represented by the form $A X=B$.\\\\\r\n$x=\\left[\\begin{array}{c}x_{1} \\\\ x_{2} \\\\ \\vdots \\\\ x_{j}\\end{array}\\right]$ is of the order of $j \\times 1$ and\\\\\r\n$B=\\left[\\begin{array}{c}b_{1} \\\\ b_{2} \\\\ \\vdots \\\\ b_{i}\\end{array}\\right]$ is of the order of $i \\times 1 .$\\\\ $[A]_{i \\times j}$ is called the coefficient matrix of system of linear equations.\r\n\\subsection{Solution of Homogeneous System of Linear Equations}\r\nAs already discussed, for a homogeneous system of linear equation with ' $j$ unknowns,\r\n$$\r\n\\begin{array}{c}\r\n\tA X=B \\text { becomes } \\\\\r\n\tA X=0(\\because B=0)\r\n\\end{array}\r\n$$\r\nThere are two cases that arise for homogeneous systems:\r\n\\begin{enumerate}\r\n\t\\item  \\textbf{Matrix $A$ is non-singular or $|A| \\neq 0$.}\\\\\r\n\tThe solution of the homogeneous system in the above equation has a unique solution, $X=0,$ i.e. $x_{1}=x_{2}=\\cdots=x_{j}=0$\r\n\t\t\\item \\textbf{Matrix $A$ is singular or $|A|=0.$}\\\\ Then it has infinite many solutions. To find the solution when $|A|=0$, put $z=k$ (where $k$ is any real number) and solve any two equations for $x$ and $y$ using the matrix method. The values obtained for $x$ and $y$ with $z=$ $k$ is the solution of the system.\r\n\\end{enumerate}\r\n\r\n\\subsection{Solution of Non-Homogeneous System of Simultaneous Linear Equations}\r\nTo solve a non-homogeneous system of simultaneous linear equations. We have to find the number of unknowns and the number of equations.\r\n\\begin{enumerate}\r\n\t\\item  Given that $A$ is a non-singular matrix, then a system of equations represented by $A X=B$ has the unique solution which can be calculated by $X=A^{-1} B$\r\n\t\\item  If $A X=B$ is a system with linear equations equal to the number of unknowns, then three cases arise:\r\n\\end{enumerate}\r\n\r\n\\begin{itemize}\r\n\t\\item  If $|A| \\neq 0$, system is consistent and has a unique solution given by $X=A^{-1} B$.\r\n\t\\item If $|A|=0$ and $(\\operatorname{adj} A) B=0,$ system is consistent and has infinite solutions.\r\n\t\\item If $|A|=0$ and $(\\operatorname{adj} A) B \\neq 0,$ system is inconsistent.\r\n\t\r\n\\end{itemize}\r\n\\subsection{Cramer's rule}\r\nOur real problem in solving a linear equation is to determine under what conditions there is any solution, apart from the trivial one $x_{1}=0, x_{2}=0, x_{3}=0$. \r\nSuppose we have the following system of linear equations:\r\n\\begin{equation}\r\n\\begin{array}{l}\r\na_{1} x+b_{1} y+c_{1} z=k_{1} \\\\\r\na_{2} x+b_{2} y+c_{2} z=k_{2} \\\\\r\na_{3} x+b_{3} y+c_{3} z=k_{3}\r\n\\end{array}\\label{Matrices linear 001}\r\n\\end{equation}\r\nIf we use vector notation $\\mathbf{x}=\\left(x_{1}, x_{2}, x_{3}\\right)$ for the solution and three rows $\\mathbf{a}=\\left(a_{1}, a_{2}, a_{3}\\right), \\mathbf{b}=\\left(b_{1}, b_{2}, b_{3}\\right), \\mathbf{c}=\\left(c_{1}, c_{2}, c_{3}\\right)$ of coefficients, then the three equations, Equation.\\label{Matrices linear 001}, become\r\nNow, if\r\n$$\r\n\\begin{array}{l}\r\n\t\\Delta=\\left[\\begin{array}{lll}\r\n\t\ta_{1} & b_{1} & c_{1} \\\\\r\n\t\ta_{2} & b_{2} & c_{2} \\\\\r\n\t\ta_{3} & b_{3} & c_{3}\r\n\t\\end{array}\\right] \\neq 0 \\\\\r\n\t\\Delta_{1}=\\left[\\begin{array}{lll}\r\n\t\tk_{1} & b_{1} & c_{1} \\\\\r\n\t\tk_{2} & b_{2} & c_{2} \\\\\r\n\t\tk_{3} & b_{3} & c_{3}\r\n\t\\end{array}\\right] \\neq 0 \\\\\r\n\t\\Delta_{2}=\\left[\\begin{array}{lll}\r\n\t\ta_{1} & k_{1} & c_{1} \\\\\r\n\t\ta_{2} & k_{2} & c_{2} \\\\\r\n\t\ta_{3} & k_{3} & c_{3}\r\n\t\\end{array}\\right] \\neq 0 \\\\\r\n\t\\Delta_{3}=\\left[\\begin{array}{lll}\r\n\t\ta_{1} & b_{1} & k_{1} \\\\\r\n\t\ta_{2} & b_{2} & k_{2} \\\\\r\n\t\ta_{3} & b_{3} & k_{3}\r\n\t\\end{array}\\right] \\neq 0\r\n\\end{array}\r\n$$\r\nThus, the solution of the system of equations is given by\r\n$$\r\n\\begin{array}{l}\r\n\tx=\\frac{\\Delta_{1}}{\\Delta} \\\\\r\n\ty=\\frac{\\Delta_{2}}{\\Delta} \\\\\r\n\tz=\\frac{\\Delta_{3}}{\\Delta}\r\n\\end{array}\r\n$$\\subsection{Augmented matrix}\r\nConsider the following system of equations:\r\n$$\r\n\\begin{array}{c}\r\n\ta_{11} x_{1}+a_{12} x_{2}+\\cdots+a_{1 n} x_{n}=b_{1} \\\\\r\n\ta_{21} x_{1}+a_{22} x_{2}+\\cdots+a_{2 n} x_{n}=b_{2} \\\\\r\n\t\\vdots \\quad \\vdots \\\\\r\n\ta_{m 1} x_{1}+a_{m 2} x_{2}+\\cdots+a_{m n} x_{n}=b_{m}\r\n\\end{array}\r\n$$\r\nThis system can be represented as $A X=B$.\r\n$$\r\n\\begin{aligned}\r\n\t\\text { where } A &=\\left[\\begin{array}{cccc}\r\n\t\ta_{11} & a_{12} & \\cdots & a_{1 n} \\\\\r\n\t\ta_{21} & a_{22} & \\cdots & a_{2 n} \\\\\r\n\t\t\\vdots & \\vdots & \\vdots & \\vdots \\\\\r\n\t\ta_{m 1} & a_{m 2} & \\cdots & a_{m n}\r\n\t\\end{array}\\right], X=\\left[\\begin{array}{l}\r\n\t\tx_{1} \\\\\r\n\t\tx_{2} \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_{n}\r\n\t\\end{array}\\right] \\text { and } \\\\\r\n\t& B=\\left[\\begin{array}{c}\r\n\t\tb_{1} \\\\\r\n\t\tb_{2} \\\\\r\n\t\t\\vdots \\\\\r\n\t\tb_{n}\r\n\t\\end{array}\\right] .\r\n\\end{aligned}\r\n$$\r\nThe matrix $[A \\mid B]=\\left[\\begin{array}{cccc|c}a_{11} & a_{12} & \\cdots & a_{1 n} & b_{1} \\\\ a_{21} & a_{22} & \\cdots & a_{2 n} & b_{2} \\\\ \\vdots & \\vdots & \\vdots & \\vdots & \\vdots \\\\ a_{m 1} & a_{m 2} & \\cdots & a_{m n} & b_{m}\\end{array}\\right]$ is called\r\naugmented matrix\r\n\\begin{exercise}\r\n\tShow that the homogeneous system of equations has a non-trivial solution and find the solution.\r\n\t$$\r\n\t\\begin{array}{r}\r\n\t\tx-2 y+z=0 \\\\\r\n\t\tx+y-z=0 \\\\\r\n\t\t3 x+6 y-5 z=0\r\n\t\\end{array}\r\n\t$$\r\n\\end{exercise}\r\n\\begin{answer}[H]\r\n\tThe given system of equations can be written in the matrix form as follows:\r\n\t\\begin{align*}\r\n\t\t\\left[\\begin{array}{ccc}\r\n\t\t\t1 & -2 & 1 \\\\\r\n\t\t\t1 & 1 & -1 \\\\\r\n\t\t\t3 & 6 & -5\r\n\t\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\t\tx \\\\\r\n\t\t\ty \\\\\r\n\t\t\tz\r\n\t\t\\end{array}\\right]&=\\left[\\begin{array}{l}\r\n\t\t\t0 \\\\\r\n\t\t\t0 \\\\\r\n\t\t\t0\r\n\t\t\\end{array}\\right]\\\\\r\n\\text{\tWhich is similar to }\\ A X=O, \\\\\\text{Where}\\ A&=\\left[\\begin{array}{ccc}3 & 6 & -5\\end{array}\\right]\\left[\\begin{array}{ccc}1 & -2 & 1 \\\\ 1 & 1 & -1 \\\\ 3 & 6 & -5\\end{array}\\right],\\\\\r\n\tX&=\\left[\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right]\\text{ and } O=\\left[\\begin{array}{l}0 \\\\ 0 \\\\ 0\\end{array}\\right]\\\\\\text{Now,}\\\r\n|A|&=\\left|\\begin{array}{ccc}\r\n\t\t\t1 & -2 & 1 \\\\\r\n\t\t\t1 & 1 & -1 \\\\\r\n\t\t\t3 & 6 & -5\r\n\t\t\\end{array}\\right|\\\\&=1(-5+6)-1(10-6)+3(2-1)=0 \r\n\t\\end{align*}\r\nThus, $|A|=0$ and hence the given system of equations has a non-trivial solution.\r\nNow, to find the solution, we put $z=k$ in the first two equations.\r\n\\begin{align*}\r\n\t\\begin{array}{c}\r\n\t\tx-2 y=-k \\\\\r\n\t\tx+y=k \\\\\r\n\t\t{\\left[\\begin{array}{cc}\r\n\t\t\t\t1 & -2 \\\\\r\n\t\t\t\t1 & 1\r\n\t\t\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\t\t\tx \\\\\r\n\t\t\t\ty\r\n\t\t\t\\end{array}\\right]=\\left[\\begin{array}{l}\r\n\t\t\t\t-k \\\\\r\n\t\t\t\tk\r\n\t\t\t\\end{array}\\right]}\r\n\t\\end{array}\\\\\r\n\\text{which is similar to}\\ A X=B, \\text{where}\\ A=\\left[\\begin{array}{cc}1 & -2 \\\\ 1 & 1\\end{array}\\right],\\\\ X=\\left[\\begin{array}{l}x \\\\ y\\end{array}\\right] \\text{and}\\ B=\\left[\\begin{array}{l}-k \\\\ k\\end{array}\\right]\\\\\r\n\\text{Now,}\r\n|A|=\\left|\\begin{array}{cc}\r\n\t1 & -2 \\\\\r\n\t1 & 1\r\n\\end{array}\\right|=3 \\neq 0\\\\\\text{Hence,}\\  A^{-1} exists.\r\n\\\\\r\n\\begin{array}{r}\r\n\\text { Now, adj } A=\\left[\\begin{array}{cc}\r\n\t1 & 2 \\\\\r\n\t-1 & 1\r\n\\end{array}\\right] \\\\\r\nA^{-1}=\\frac{1}{3}\\left[\\begin{array}{cc}\r\n\t1 & 2 \\\\\r\n\t-1 & 1\r\n\\end{array}\\right]\r\n\\end{array}\r\n\\\\\r\n\\text { Now, } X=A^{-1} B \\\\ \\Rightarrow\\left[\\begin{array}{l}\r\n\t\tx \\\\\r\n\t\ty\r\n\t\\end{array}\\right]=\\frac{1}{3}\\left[\\begin{array}{cc}\r\n\t\t1 & 2 \\\\\r\n\t\t-1 & 1\r\n\t\\end{array}\\right]\\left[\\begin{array}{l}\r\n\t\t-k \\\\\r\n\t\tk\r\n\t\\end{array}\\right]=\\left[\\begin{array}{l}\r\n\t\tk / 3 \\\\\r\n\t\t2 k / 3\r\n\t\\end{array}\\right]\r\n\t\\\\ \\Rightarrow x=\\frac{k }{3}, y=\\frac{2 k}{3}\\\\\r\n\\text{Hence,}\\ x=\\frac{k }{3}, y=\\frac{2 k}{3}\\ \\text{and}\\ z=k\r\n\\end{align*}\r\nWhere k is any real number that satisfies the given set of equations.\r\n\\end{answer}\r\n\r\n\\newpage\r\n\\pagestyle{plain}\r\n\r\n\r\n\\begin{abox}\r\n\tProblem set-1\r\n\t\\end{abox}\r\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\r\n\t\\item Consider the matrix $M=\\left(\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1\\end{array}\\right)$\\\\\r\n\t\\textbf{A.} The eigenvalues of $M$ are\r\n\t{\\exyear{NET/JRF(JUNE-2011)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $0,1,2$\r\n\t\t\\task[\\textbf{B.}] $0,0,3$\r\n\t\t\\task[\\textbf{C.}] $1,1,1$\r\n\t\t\\task[\\textbf{D.}] $-1,1,3$\r\n\t\\end{tasks}\r\n\t\\textbf{B.} The exponential of $M$ simplifies to ( $I$ is the $3 \\times 3$ identity matrix)\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] $e^{M}=I+\\left(\\frac{e^{3}-1}{3}\\right) M$\r\n\t\t\\task[\\textbf{B.}] $e^{M}=I+M+\\frac{M^{2}}{2 !}$\r\n\t\t\\task[\\textbf{C.}] $e^{M}=I+3^{3} M$\r\n\t\t\\task[\\textbf{D.}] $e^{M}=(e-1) M$\r\n\t\\end{tasks}\r\n\t\\item A $3 \\times 3$ matrix $M$ has $\\operatorname{Tr}[M]=6, \\operatorname{Tr}\\left[M^{2}\\right]=26$ and $\\operatorname{Tr}\\left[M^{3}\\right]=90$. Which of the following can be a possible set of eigenvalues of $M ?$\r\n\t{\\exyear{NET/JRF(DEC-2011)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $\\{1,1,4\\}$\r\n\t\t\\task[\\textbf{B.}] $\\{-1,0,7\\}$\r\n\t\t\\task[\\textbf{C.}] $\\{-1,3,4\\}$\r\n\t\t\\task[\\textbf{D.}] $\\{2,2,2\\}$\r\n\t\\end{tasks}\r\n\t\\item The eigen values of the matrix $A=\\left(\\begin{array}{lll}1 & 2 & 3 \\\\ 2 & 4 & 6 \\\\ 3 & 6 & 9\\end{array}\\right)$ are\r\n\t{\\exyear{NET/JRF(JUNE-2012)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $(1,4,9)$\r\n\t\t\\task[\\textbf{B.}] $(0,7,7)$\r\n\t\t\\task[\\textbf{C.}] $(0,1,13)$\r\n\t\t\\task[\\textbf{D.}] $(0,0,14)$\r\n\t\\end{tasks}\r\n\t\\item The eigenvalues of the antisymmetric matrix,\r\n\t$$\r\n\tA=\\left(\\begin{array}{ccc}\r\n\t0 & -n_{3} & n_{2} \\\\\r\n\tn_{3} & 0 & -n_{1} \\\\\r\n\t-n_{2} & n_{1} & 0\r\n\t\\end{array}\\right)\r\n\t$$\r\n\twhere $n_{1}, n_{2}$ and $n_{3}$ are the components of a unit vector, are\r\n\t{\\exyear{NET/JRF(JUNE-2012)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $0, i,-i$\r\n\t\t\\task[\\textbf{B.}] $0,1,-1$\r\n\t\t\\task[\\textbf{C.}] $0,1+i,-1,-i$\r\n\t\t\\task[\\textbf{D.}]  $0,0,0$\r\n\t\\end{tasks}\r\n\t\\item Consider an $n \\times n(n>1)$ matrix $A$, in which $A_{i j}$ is the product of the indices $i$ and $j$ $\\left(\\right.$ namely $\\left.A_{i j}=i j\\right)$. The matrix $A$\r\n\t{\\exyear{NET/JRF(DEC-2013)}}\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{A.}]  Has one degenerate eigevalue with degeneracy $(n-1)$\r\n\t\t\\task[\\textbf{B.}] Has two degenerate eigenvalues with degeneracies 2 and $(n-2)$\r\n\t\t\\task[\\textbf{C.}] Has one degenerate eigenvalue with degeneracy $n$\r\n\t\t\\task[\\textbf{D.}] Does not have any degenerate eigenvalue\r\n\t\\end{tasks}\r\n\t\\item Consider the matrix\r\n\t$$\r\n\tM=\\left(\\begin{array}{ccc}\r\n\t0 & 2 i & 3 i \\\\\r\n\t-2 i & 0 & 6 i \\\\\r\n\t-3 i & -6 i & 0\r\n\t\\end{array}\\right)\r\n\t$$\r\n\tThe eigenvalues of $M$ are\r\n\t{\\exyear{NET/JRF(JUNE-2014)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $-5,-2,7$\r\n\t\t\\task[\\textbf{B.}] $-7,0,7$\r\n\t\t\\task[\\textbf{C.}] $-4 i, 2 i, 2 i$\r\n\t\t\\task[\\textbf{D.}] $2,3,6$\r\n\t\\end{tasks}\r\n\t\\item The column vector $\\left(\\begin{array}{l}a \\\\ b \\\\ a\\end{array}\\right)$ is a simultaneous eigenvector of $A=\\left(\\begin{array}{ccc}0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\end{array}\\right)$ and $B=\\left(\\begin{array}{lll}0 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 0\\end{array}\\right)$ if\r\n\t{\\exyear{NET/JRF(DEC-2014)}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] $b=0$ or $a=0$\r\n\t\t\\task[\\textbf{B.}] $b=a$ or $b=-2 a$\r\n\t\t\\task[\\textbf{C.}] $b=2 a$ or $b=-a$\r\n\t\t\\task[\\textbf{D.}] $b=a / 2$ or $b=-a / 2$\r\n\t\\end{tasks}\r\n\t\\item The matrix $M=\\left(\\begin{array}{ccc}1 & 3 & 2 \\\\ 3 & -1 & 0 \\\\ 0 & 0 & 1\\end{array}\\right)$ satisfies the equation\r\n\t{\\exyear{NET/JRF(DEC-2016)}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] $M^{3}-M^{2}-10 M+12 I=0$\r\n\t\t\\task[\\textbf{B.}] $M^{3}+M^{2}-12 M+10 I=0$\r\n\t\t\\task[\\textbf{C.}] $M^{3}-M^{2}-10 M+10 I=0$\r\n\t\t\\task[\\textbf{D.}] $M^{3}+M^{2}-10 M+10 I=0$\r\n\t\\end{tasks}\r\n\t\\item   Which of the following can not be the eigen values of a real $3 \\times 3$ matrix\r\n\t{\\exyear{NET/JRF(JUNE-2017)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}]  $2 i, 0,-2 i$\r\n\t\t\\task[\\textbf{B.}] $1,1,1$\r\n\t\t\\task[\\textbf{C.}] $e^{i \\theta}, e^{-i \\theta}, 1$\r\n\t\t\\task[\\textbf{D.}] $i, 1,0$\r\n\t\\end{tasks}\r\n\t\\item  Let $\\sigma_{x}, \\sigma_{y}, \\sigma_{z}$ be the Pauli matrices and $x^{\\prime} \\sigma_{x}+y^{\\prime} \\sigma_{y}+z^{\\prime} \\sigma_{z}=\\exp \\left(\\frac{i \\theta \\sigma_{z}}{2}\\right) \\times$\r\n\t$$\r\n\t\\left[x \\sigma_{x}+y \\sigma_{y}+z \\sigma_{z}\\right] \\exp \\left(-\\frac{i \\theta \\sigma_{z}}{2}\\right)\r\n\t$$\r\n\tThen the coordinates are related as follows\r\n\t{\\exyear{NET/JRF(JUNE-2017)}}\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{A.}] $\\left(\\begin{array}{l}x^{\\prime} \\\\ y^{\\prime} \\\\ z^{\\prime}\\end{array}\\right)=\\left(\\begin{array}{ccc}\\cos \\theta & -\\sin \\theta & 0 \\\\ \\sin \\theta & \\cos \\theta & 0 \\\\ 0 & 0 & 1\\end{array}\\right)\\left(\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right)$\r\n\t\t\\task[\\textbf{B.}] $\\left(\\begin{array}{l}x^{\\prime} \\\\ y^{\\prime} \\\\ z^{\\prime}\\end{array}\\right)=\\left(\\begin{array}{ccc}\\cos \\theta & \\sin \\theta & 0 \\\\ -\\sin \\theta & \\cos \\theta & 0 \\\\ 0 & 0 & 1\\end{array}\\right)\\left(\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right)$\r\n\t\t\\task[\\textbf{C.}] $\\left(\\begin{array}{l}x^{\\prime} \\\\ y^{\\prime} \\\\ z^{\\prime}\\end{array}\\right)=\\left(\\begin{array}{ccc}\\cos \\frac{\\theta}{2} & \\sin \\frac{\\theta}{2} & 0 \\\\ -\\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} & 0 \\\\ 0 & 0 & 1\\end{array}\\right)\\left(\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right)$\r\n\t\t\\task[\\textbf{D.}] $\\left(\\begin{array}{l}x^{\\prime} \\\\ y^{\\prime} \\\\ z^{\\prime}\\end{array}\\right)=\\left(\\begin{array}{ccc}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2} & 0 \\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} & 0 \\\\ 0 & 0 & 1\\end{array}\\right)\\left(\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right)$\r\n\t\\end{tasks}\r\n\t\\item  Let $A$ be a non-singular $3 \\times 3$ matrix, the columns of which are denoted by the vectors $\\vec{a}, \\vec{b}$ and $\\vec{c}$, respectively. Similarly, $\\vec{u}, \\vec{v}$ and $\\vec{w}$ denote the vectors that form the corresponding columns of $\\left(A^{T}\\right)^{-1}$. Which of the following is true?\r\n\t{\\exyear{NET/JRF(DEC-2017)}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] $\\vec{u} \\cdot \\vec{a}=0, \\vec{u} \\cdot \\vec{b}=0, \\vec{u} \\cdot \\vec{c}=1$\r\n\t\t\\task[\\textbf{B.}]  $\\vec{u} \\cdot \\vec{a}=0, \\vec{u} \\cdot \\vec{b}=1, \\vec{u} \\cdot \\vec{c}=0$\r\n\t\t\\task[\\textbf{C.}] $\\vec{u} \\cdot \\vec{a}=1, \\vec{u} \\cdot \\vec{b}=0, \\vec{u} \\cdot \\vec{c}=0$\r\n\t\t\\task[\\textbf{D.}]  $\\vec{u} \\cdot \\vec{a}=0, \\vec{u} \\cdot \\vec{b}=0, \\vec{u} \\cdot \\vec{c}=0$\r\n\t\\end{tasks}\r\n\t\\item Consider the matrix equation\r\n\t$$\r\n\t\\left(\\begin{array}{llc}\r\n\t1 & 1 & 1 \\\\\r\n\t1 & 2 & 3 \\\\\r\n\t2 & b & 2 c\r\n\t\\end{array}\\right)\\left(\\begin{array}{l}\r\n\tx \\\\\r\n\ty \\\\\r\n\tz\r\n\t\\end{array}\\right)=\\left(\\begin{array}{l}\r\n\t0 \\\\\r\n\t0 \\\\\r\n\t0\r\n\t\\end{array}\\right)\r\n\t$$\r\n\tThe condition for existence of a non-trivial solution and the corresponding normalised solution (upto a sign) is\r\n\t{\\exyear{NET/JRF(DEC-2017)}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] $b=2 c$ and $(x, y, z)=\\frac{1}{\\sqrt{6}}(1,-2,1)$\r\n\t\t\\task[\\textbf{B.}] $c=2 b$ and $(x, y, z)=\\frac{1}{\\sqrt{6}}(1,1,-2)$\r\n\t\t\\task[\\textbf{C.}] $c=b+1$ and $(x, y, z)=\\frac{1}{\\sqrt{6}}(2,-1,-1)$\r\n\t\t\\task[\\textbf{D.}] $b=c+1$ and $(x, y, z)=\\frac{1}{\\sqrt{6}}(1,-2,1)$\r\n\t\\end{tasks}\r\n\t\\item  Which of the following statements is true for a $3 \\times 3$ real orthogonal matrix with determinant $+1 ?$\r\n\t{\\exyear{NET/JRF(JUNE-2018)}}\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{A.}] The modulus of each of its eigenvalues need not be 1, but their product must be 1\r\n\t\t\\task[\\textbf{B.}] At least one of its eigenvalues is $+1$\r\n\t\t\\task[\\textbf{C.}] All of its eigenvalues must be real\r\n\t\t\\task[\\textbf{D.}]  None of its eigenvalues must be real\r\n\t\\end{tasks}\r\n\t\\item One of the eigenvalues of the matrix $e^{A}$ is $e^{a}$, where $A=\\left(\\begin{array}{ccc}a & 0 & 0 \\\\ 0 & 0 & a \\\\ 0 & a & 0\\end{array}\\right)$. The product of the other two eigenvalues of $e^{A}$ is\r\n\t{\\exyear{NET/JRF(DEC-2018)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $e^{2 a}$\r\n\t\t\\task[\\textbf{B.}] $e^{-a}$\r\n\t\t\\task[\\textbf{C.}]  $e^{-2 a}$\r\n\t\t\\task[\\textbf{D.}] 1\r\n\t\\end{tasks}\r\n\t\\item A $4 \\times 4$ complex matrix $A$ satisfies the relation $A^{\\dagger} A=4 I$, where $I$ is the $4 \\times 4$ identity matrix. The number of independent real parameters of $A$ is\r\n\t{\\exyear{NET/JRF(DEC-2018)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 32\r\n\t\t\\task[\\textbf{B.}] 10\r\n\t\t\\task[\\textbf{C.}] 12\r\n\t\t\\task[\\textbf{D.}] 16\r\n\t\\end{tasks}\r\n\t\\item  The element of a $3 \\times 3$ matrix $A$ are the products if its row and column indices $A_{i j}=i j$ (where $i, j=1,2,3)$. The eigenvalues of $A$ are\r\n\t{\\exyear{NET/JRF(JUNE-2019)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $(7,7,0)$\r\n\t\t\\task[\\textbf{B.}]  $(7,4,3)$\r\n\t\t\\task[\\textbf{C.}] $(14,0,0)$\r\n\t\t\\task[\\textbf{D.}] $\\left(\\frac{14}{3}, \\frac{14}{3}, \\frac{14}{3}\\right)$\r\n\t\\end{tasks}\r\n\t\\item  The operator $A$ has a matrix representation $\\left(\\begin{array}{ll}2 & 1 \\\\ 1 & 2\\end{array}\\right)$ in the basis spanned by $\\left(\\begin{array}{l}1 \\\\ 0\\end{array}\\right)$ and $\\left(\\begin{array}{l}0 \\\\ 1\\end{array}\\right) .$ In another basis spanned by $\\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)$, the matrix representation of $A$ is\r\n\t{\\exyear{NET/JRF(JUNE-2019)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $\\left(\\begin{array}{ll}2 & 0 \\\\ 0 & 2\\end{array}\\right)$\r\n\t\t\\task[\\textbf{B.}] $\\left(\\begin{array}{ll}3 & 0 \\\\ 0 & 1\\end{array}\\right)$\r\n\t\t\\task[\\textbf{C.}] $\\left(\\begin{array}{ll}3 & 1 \\\\ 0 & 1\\end{array}\\right)$\r\n\t\t\\task[\\textbf{D.}] $\\left(\\begin{array}{ll}3 & 0 \\\\ 1 & 1\\end{array}\\right)$\r\n\t\\end{tasks}\r\n\t\\item  If the rank of an $n \\times n$ matrix $A$ is $m$, where $m$ and $n$ are positive integers with $1 \\leq m \\leq n$, then the rank of the matrix $A^{2}$ is\r\n\t{\\exyear{NET/JRF(DEC-2019)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}]  $m$\r\n\t\t\\task[\\textbf{B.}] $m-1$\r\n\t\t\\task[\\textbf{C.}] $2 \\mathrm{~m}$\r\n\t\t\\task[\\textbf{D.}] $m-2$\r\n\t\\end{tasks}\r\n\t\\item   The eigenvalues of the $3 \\times 3$ matrix $M=\\left(\\begin{array}{lll}a^{2} & a b & a c \\\\ a b & b^{2} & b c \\\\ a c & b c & c^{2}\\end{array}\\right)$ are\r\n\t{\\exyear{NET/JRF(JUNE-2020)}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] $a^{2}+b^{2}+c^{2}, 0,0$\r\n\t\t\\task[\\textbf{B.}] $b^{2}+c^{2}, a^{2}, 0$\r\n\t\t\\task[\\textbf{C.}] $a^{2}+b^{2}, c^{2}, 0$\r\n\t\t\\task[\\textbf{D.}] $a^{2}+c^{2}, b^{2}, 0$\r\n\t\\end{tasks}\r\n\\end{enumerate}\r\n \\colorlet{ocre1}{ocre!70!}\r\n\\colorlet{ocrel}{ocre!30!}\r\n\\setlength\\arrayrulewidth{1pt}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\arrayrulecolor{ocre}\r\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\r\n\t\t\\hline\r\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\r\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\r\n\t\t1&\\textbf{B} &2&\\textbf{C}\\\\\\hline \r\n\t\t3&\\textbf{D} &4&\\textbf{A} \\\\\\hline\r\n\t\t5&\\textbf{A} &6&\\textbf{B} \\\\\\hline\r\n\t\t7&\\textbf{B}&8&\\textbf{C}\\\\\\hline\r\n\t\t9&\\textbf{D}&10&\\textbf{B}\\\\\\hline\r\n\t\t11&\\textbf{C} &12&\\textbf{D}\\\\\\hline\r\n\t\t13&\\textbf{B}&14&\\textbf{D}\\\\\\hline\r\n\t\t15&\\textbf{D}&16&\\textbf{C}\\\\\\hline\r\n\t\t17&\\textbf{B} &18&\\textbf{A}\\\\\\hline\r\n\t\t19&\\textbf{A}& & \\\\\\hline\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\newpage\r\n\\begin{abox}\r\n\tProblem set-2\r\n\\end{abox}\r\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\r\n\t\\item The eigenvalues of the matrix $\\left(\\begin{array}{lll}2 & 3 & 0 \\\\ 3 & 2 & 0 \\\\ 0 & 0 & 1\\end{array}\\right)$ are\r\n\t{\\exyear{GATE 2010}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $5,2,-2$\r\n\t\t\\task[\\textbf{B.}] $-5,-1,-1$\r\n\t\t\\task[\\textbf{C.}]  $5,1,-1$\r\n\t\t\\task[\\textbf{D.}] $-5,1,1$\r\n\t\\end{tasks}\r\n\t\\item Two matrices $A$ and $B$ are said to be similar if $B=P^{-1} A P$ for some invertible matrix $P$.Which of the following statements is NOT TRUE?\r\n\t{\\exyear{GATE 2011}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] Det $A=\\operatorname{Det} B$\r\n\t\t\\task[\\textbf{B.}]  Trace of $A=$ Trace of $B$\r\n\t\t\\task[\\textbf{C.}] $A$ and $B$ have the same eigenvectors\r\n\t\t\\task[\\textbf{D.}] $A$ and $B$ have the same eigenvalues\r\n\t\\end{tasks}\r\n\t\\item A $3 \\times 3$ matrix has elements such that its trace is 11 and its determinant is 36 . The eigenvalues of the matrix are all known to be positive integers. The largest eigenvalues of the matrix is\r\n\t{\\exyear{GATE 2011}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 18\r\n\t\t\\task[\\textbf{B.}]  12\r\n\t\t\\task[\\textbf{C.}] 9\r\n\t\t\\task[\\textbf{D.}] 6\r\n\t\\end{tasks}\r\n\t\\item  The number of independent components of the symmetric tensor $A_{i j}$ with indices $i, j=1,2,3$ is\r\n\t{\\exyear{GATE 2012}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 1\r\n\t\t\\task[\\textbf{B.}] 3\r\n\t\t\\task[\\textbf{C.}] 6\r\n\t\t\\task[\\textbf{D.}] 9\r\n\t\\end{tasks}\r\n\t\\item  The eigenvalues of the matrix $\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ are\r\n\t{\\exyear{GATE 2012}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $0,1,1$\r\n\t\t\\task[\\textbf{B.}] $0,-\\sqrt{2}, \\sqrt{2}$\r\n\t\t\\task[\\textbf{C.}]  $\\frac{1}{\\sqrt{2}}, \\frac{1}{\\sqrt{2}}, 0$\r\n\t\t\\task[\\textbf{D.}] $\\sqrt{2}, \\sqrt{2}, 0$\r\n\t\\end{tasks}\r\n\t\\item    The degenerate eigenvalue of the matrix $\\left[\\begin{array}{ccc}4 & -1 & -1 \\\\ -1 & 4 & -1 \\\\ -1 & -1 & 4\\end{array}\\right]$ is (your answer should be an\r\n\tinteger)---\r\n\t{\\exyear{GATE 2013}}\r\n\t\\item  The matrix\r\n\t$$\r\n\tA=\\frac{1}{\\sqrt{3}}\\left[\\begin{array}{cc}\r\n\t1 & 1+i \\\\\r\n\t1-i & -1\r\n\t\\end{array}\\right] \\text { is }\r\n\t$$\r\n\t{\\exyear{GATE 2014}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] Orthogonal\r\n\t\t\\task[\\textbf{B.}] Symmetric\r\n\t\t\\task[\\textbf{C.}]  Anti-symmetric\r\n\t\t\\task[\\textbf{D.}]  Unitary\r\n\t\\end{tasks}\r\n\t\\item  Let $X$ be a column vector of dimension $n>1$ with at least one non-zero entry. The number of non-zero eigenvalues of the matrix $M=X X^{T}$ is\r\n\t{\\exyear{GATE 2017}}\r\n\t \\begin{tasks}(4)\r\n\t \t\\task[\\textbf{A.}] 0\r\n\t \t\\task[\\textbf{B.}] $n$\r\n\t \t\\task[\\textbf{C.}] 1\r\n\t \t\\task[\\textbf{D.}] $n-1$\r\n\t \\end{tasks}\r\n\t \\item The eigenvalues of a Hermitian matrix are all\r\n\t {\\exyear{GATE 2018}}\r\n\t \\begin{tasks}(4)\r\n\t \t\\task[\\textbf{A.}]  Real\r\n\t \t\\task[\\textbf{B.}] Imaginary\r\n\t \t\\task[\\textbf{C.}] Of modulus one\r\n\t \t\\task[\\textbf{D.}] Real and positive\r\n\t \\end{tasks}\r\n\t \\item During a rotation, vectors along the axis of rotation remain unchanged. For the rotation matrix $\\left(\\begin{array}{ccc}0 & 1 & 0 \\\\ 0 & 0 & -1 \\\\ -1 & 0 & 0\\end{array}\\right)$, the vector along the axis of rotation is\r\n\t {\\exyear{GATE 2019}}\r\n\t \\begin{tasks}(2)\r\n\t \t\\task[\\textbf{A.}] $\\frac{1}{3}(2 \\hat{i}-\\hat{j}+2 \\hat{k})$\r\n\t \t\\task[\\textbf{B.}]  $\\frac{1}{\\sqrt{3}}(\\hat{i}+\\hat{j}-\\hat{k})$\r\n\t \t\\task[\\textbf{C.}] $\\frac{1}{\\sqrt{3}}(\\hat{i}-\\hat{j}-\\hat{k})$\r\n\t \t\\task[\\textbf{D.}] $\\frac{1}{3}(2 \\hat{i}+2 \\hat{j}-\\hat{k})$\r\n\t \\end{tasks}\r\n\\end{enumerate}\r\n \\colorlet{ocre1}{ocre!70!}\r\n\\colorlet{ocrel}{ocre!30!}\r\n\\setlength\\arrayrulewidth{1pt}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\arrayrulecolor{ocre}\r\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\r\n\t\t\\hline\r\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\r\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\r\n\t\t1&\\textbf{C} &2&\\textbf{C}\\\\\\hline \r\n\t\t3&\\textbf{D} &4&\\textbf{C} \\\\\\hline\r\n\t\t5&\\textbf{B} &6&\\textbf{-} \\\\\\hline\r\n\t\t7&\\textbf{D}&8&\\textbf{C}\\\\\\hline\r\n\t\t9&\\textbf{A}&10&\\textbf{B}\\\\\\hline\r\n\t\t\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\newpage\r\n\\begin{abox}\r\n\tProblem set-3\r\n\t\\end{abox}\r\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\r\n\t\\item Consider the matrices $X_{(4 \\times 3)}, Y_{(4 \\times 3)}$ and $P_{(2 \\times 3)}$ The order of $\\left[P\\left(X^{T} Y\\right)^{-1} P^{T}\\right]^{T}$ will be\r\n\t\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}] $(2 \\times 2)$  \r\n\t\t\\task[\\textbf{b.}]$(3 \\times 3)$\r\n\t\t\\task[\\textbf{c.}]$(4 \\times 3)$ \r\n\t\t\\task[\\textbf{d.}]$(3 \\times 4)$ \r\n\t\\end{tasks}\r\n\t\r\n\t\\begin{answer}\r\n\tWe know that the order of\r\n\t\\begin{align*}\r\n\tX \\rightarrow 4 \\times 3, Y &\\rightarrow 4 \\times 3 \\text { and } P \\rightarrow 2 \\times 3\\\\\r\n\t\\text{Hence, we can calculate the following orders:}\\\\\r\n\tX^{T} \\rightarrow 3 \\times 4, X^{T} Y &\\rightarrow 3 \\times 3 \\quad\\text{and}\r\n\t\\\\\r\n\t\\left(X^{T} Y\\right)^{-1} &\\rightarrow 3 \\times 3 \\quad\\text{also}\\\\\r\n\tP^{T} &\\rightarrow 3 \\times 2\\\\\\therefore \\left(P\\left(X^{T} Y\\right)^{-1} P^{T}\\right)^{T} &\\rightarrow 2 \\times 2\\\\\r\n\t\\text{and}\\\\P\\left(X^{T} Y\\right)^{-1}\\\\\r\n\tP^{T} \\rightarrow(2 \\times 3)(3 \\times 3)(3 \\times 2) &\\rightarrow 2 \\times 2\\\\\r\n\t\\text{ Thus the order of the matrix is $2 \\times 2$}\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\item What are the eigenvalues of the following $2 \\times 2$ matrix?\r\n$\r\n\\left[\\begin{array}{rr}\r\n2 & -1 \\\\\r\n-4 & 5\r\n\\end{array}\\right]\r\n$\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]-1 and 1  \r\n\t\\task[\\textbf{b.}]1 and 6\r\n\t\\task[\\textbf{c.}]2 and 5 \r\n\t\\task[\\textbf{d.}]4 and -1 \r\n\\end{tasks}\t\r\n\\begin{answer}\r\n\tWe have\r\n\t$$\r\n\tA=\\left[\\begin{array}{rr}\r\n\t2 & -1 \\\\\r\n\t-4 & 5\r\n\t\\end{array}\\right]\r\n\t$$\r\n\tThe characteristic equation of this matrix is given by\r\n\t$$\r\n\t\\begin{aligned}\r\n\t|A-\\lambda I| &=0 \\\\\r\n\t\\left|\\begin{array}{rr}\r\n\t2-\\lambda & -1 \\\\\r\n\t-4 & 5-\\lambda\r\n\t\\end{array}\\right| &=0 \\\\\r\n\t(2-\\lambda)(5-\\lambda)-4 &=0 \\\\\r\n\t\\lambda &=1,6\r\n\t\\end{aligned}\r\n\t$$\r\n\tTherefore, the eigenvalues of $A$ are 1 and 6 .\\\\Hence, option(b)is correct.\r\n\\end{answer}\r\n\\item Given a $2 \\times 2$ unitary matrix $U$ satisfying $U^{\\dagger} U=U U^{\\dagger}=1$ with $\\operatorname{det} U=e^{i \\varphi}$, one can construct a\r\nunitary matrix $V\\left(V^{\\dagger} V=V V^{\\dagger}=1\\right)$ with $\\operatorname{det} V=1$ from it by\r\n\\begin{tasks}(1)\r\n\t\\task[\\textbf{a.}]multiplying $U$ by $e^{-i \\varphi / 2}$  \r\n\t\\task[\\textbf{b.}] multiplying any single element of $U$ by $e^{-i \\varphi}$\r\n\t\\task[\\textbf{c.}]multiplying any row or column of $U$ by $e^{-i \\varphi / 2}$ \r\n\t\\task[\\textbf{d.}]multiplying $U$ by $e^{-i \\varphi}$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\\text{Let}\\quad U=\\left(\\begin{array}{ll}a & b \\\\ c & d\\end{array}\\right)&\\\\\\text{and}\\quad \\operatorname{det} U=a d-b c=e^{i \\phi}( \\text{Given })\\\\\\text{Let,}\\quad V=e^{-i \\phi / 2} U \\quad \\Rightarrow \\quad V=\\left(\\begin{array}{ll}e^{-i \\phi / 2} a & e^{-i \\phi / 2} b \\\\ e^{-i \\phi / 2} c & e^{-i \\phi / 2} d\\end{array}\\right)\\\\\r\n\t\\operatorname{det} V=e^{-i \\phi} a d-e^{-i \\phi} b c=e^{-i \\phi}(a d-b c)=e^{-i \\phi} e^{i \\phi}=1\\\\\r\n\t\\text{We have to multiply U with}\\quad {e}^{-\\mathrm{i} \\phi / 2}\r\n\t\\text{to get,}\\mathrm{V}\\text{with determinant =1}\r\n\t\\end{align*}\r\n\tCorrect answer is (a)\r\n\t\r\n\\end{answer} \r\n\\item Determine the values of $\\alpha, \\beta, \\gamma$ when\r\n$$\r\n\\left[\\begin{array}{rrr}\r\n0 & 2 \\beta & \\gamma \\\\\r\n\\alpha & \\beta & -\\gamma \\\\\r\n\\alpha & -\\beta & \\gamma\r\n\\end{array}\\right] \\text { is orthogonal. }\r\n$$\r\n\\begin{answer}\r\n\t$$\r\n\t\\text { Let } A=\\left[\\begin{array}{rrr}\r\n\t0 & 2 \\beta & \\gamma \\\\\r\n\t\\alpha & \\beta & -\\gamma \\\\\r\n\t\\alpha & -\\beta & \\gamma\r\n\t\\end{array}\\right]\r\n\t$$\r\n\tOn transposing $A,$ we have\r\n\t$$\r\n\tA^{T}=\\left[\\begin{array}{rrr}\r\n\t0 & \\alpha & \\alpha \\\\\r\n\t2 \\beta & \\beta & -\\beta \\\\\r\n\t\\gamma & -\\gamma & \\gamma\r\n\t\\end{array}\\right]\r\n\t$$\r\n\tIf $A$ is orthogonal, then $A A^{T}=I$\r\n\tEquating the corresponding elements, we have\r\n\tBut\r\n\t$$\r\n\t\\left.\\begin{array}{r}\r\n\t4 \\beta^{2}+\\gamma^{2}=1 \\\\\r\n\t2 \\beta^{2}-\\gamma^{2}=0\r\n\t\\end{array}\\right\\} \\Rightarrow \\beta=\\pm \\frac{1}{\\sqrt{6}}, \\gamma=\\pm \\frac{1}{\\sqrt{3}}\r\n\t$$\r\n\tBut $\\quad \\alpha^{2}+\\beta^{2}+\\gamma^{2}=1$ as $\\beta=\\pm \\frac{1}{\\sqrt{6}}, \\gamma=\\pm \\frac{1}{\\sqrt{3}}, \\alpha=\\pm \\frac{1}{\\sqrt{2}}$\r\n\\end{answer}\r\n\\item Find for what values of $\\lambda$ and $\\mu$ the system of linear equations.\r\n$$\r\n\\begin{aligned}\r\nx+y+z &=6 \\\\\r\nx+2 y+5 z &=10 \\\\\r\n2 x+3 y+\\lambda z &=\\mu\r\n\\end{aligned}\r\n$$\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}] a unique solution  \r\n\t\\task[\\textbf{b.}]no solution\r\n\t\\task[\\textbf{c.}]infinite solutions \r\n\\\\Also find the solution for $\\lambda=2$ and $\\mu=8$.\r\n\\end{tasks}\r\n\\begin{answer}\r\n$\\begin{aligned}\\left[\\begin{array}{lll}1 & 1 & 1 \\\\ 1 & 2 & 5 \\\\ 2 & 3 & \\lambda\\end{array}\\right]\\left[\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right]=\\left[\\begin{array}{c}6 \\\\ 10 \\\\ \\mu\\end{array}\\right] \\\\ A X &=B \\end{aligned}$.\\\\\\\\\r\n$\\begin{aligned} C=(A, B) &=\\left[\\begin{array}{lllll}1 & 1 & 1 & : & 6 \\\\ 1 & 2 & 5 & : & 10 \\\\ 2 & 3 & \\lambda & : & \\mu\\end{array}\\right] \\sim\\left[\\begin{array}{ccccc}1 & 1 & 1 & : & 6 \\\\ 0 & 1 & 4 & : & 4 \\\\ 0 & 1 & \\lambda-2 & : & \\mu-12\\end{array}\\right] \\begin{array}{l}R_{2} \\rightarrow R_{2}-R_{1} \\\\ R_{3} \\rightarrow R_{3}-2 R_{1}\\end{array} \\\\ & \\sim\\left[\\begin{array}{ccccc}1 & 1 & 1 & : & 6 \\\\ 0 & 1 & 4 & : & 4 \\\\ 0 & 0 & \\lambda-6 & : & \\mu-16\\end{array}\\right] R_{3} \\rightarrow R_{3}-R_{2} \\end{aligned}$......(1)\\\\\r\n\\\\\\textbf{(i)} $\\quad$ A unique solution If $R(A)=R(C)=3$\r\n\\\\then $\\lambda-6 \\neq 0 \\Rightarrow \\lambda \\neq 6$ and $\\mu-16 \\neq 0 \\Rightarrow \\mu \\neq 16$\r\n\\\\\\\\\\textbf{(ii)} No solutions If $R(A) \\neq R(C),$ \\\\then $R(A)=2$ and $R(C)=3$ $\\lambda-6=0 \\Rightarrow \\lambda=6$ and $\\mu-16 \\neq 0 \\Rightarrow \\mu \\neq 16$\r\n\\\\\\\\\\textbf{(iii)} Infinite solutions If $R(A)=R(C)=2$\r\n\\\\then $\\lambda-6=0$ and $\\mu-16=0$\r\n$\\Rightarrow \\quad \\lambda=6$ and $\\mu=16$\\\\\r\n\\\\\\\\\\textbf{(iv)} Putting $\\lambda=2$ and $\\mu=8$ in (1), we get\r\n$$\r\n\\begin{aligned}\r\n\\left[\\begin{array}{rrrrr}\r\n1 & 1 & 1 & : & 6 \\\\\r\n0 & 1 & 4 & : & 4 \\\\\r\n0 & 0 & -4 & : & -8\r\n\\end{array}\\right] & \\Rightarrow\\left[\\begin{array}{rrr}\r\n1 & 1 & 1 \\\\\r\n0 & 1 & 4 \\\\\r\n0 & 0 & -4\r\n\\end{array}\\right]\\left[\\begin{array}{l}\r\nx \\\\\r\ny \\\\\r\nz\r\n\\end{array}\\right]=\\left[\\begin{array}{r}\r\n6 \\\\\r\n4 \\\\\r\n-8\r\n\\end{array}\\right] \\\\\r\n& x+y+z=6 \\\\\r\n& y+4 z=4 \\\\\r\n&-4 z=-8 & \\Rightarrow \\quad z=2\r\n\\end{aligned}\r\n$$\r\nPutting $z=2$ in (3), we get\r\n$$\r\ny+8=4 \\quad \\Rightarrow \\quad y=-4\r\n$$\r\nPutting $y=-4, z=2$ in (1), we get\\\\\r\n\r\n$$\r\nx-4+2=6 \\quad \\Rightarrow \\quad x=8\r\n$$\r\nHence, $\\quad x=8, \\quad y=-4, \\quad z=2$\r\n\\end{answer}\r\n\\item Consider the following system of linear equations:\r\n$$\r\n\\left[\\begin{array}{rrr}\r\n2 & 1 & -4 \\\\\r\n4 & 3 & -12 \\\\\r\n1 & 2 & -8\r\n\\end{array}\\right]\\left[\\begin{array}{l}\r\nx \\\\\r\ny \\\\\r\nz\r\n\\end{array}\\right]=\\left[\\begin{array}{l}\r\n\\alpha \\\\\r\n5 \\\\\r\n7\r\n\\end{array}\\right]\r\n$$\r\nNotice that the second and third columns of the\r\ncoefficient matrix are linearly dependent.For how many values of $\\alpha,$ does this system of equations have infinitely many solutions?\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]0  \r\n\t\\task[\\textbf{b.}]1\r\n\t\\task[\\textbf{c.}]2 \r\n\t\\task[\\textbf{d.}]Infinitely many \r\n\\end{tasks}\r\n\\begin{answer}\r\n The given system of equations is\r\n$$\r\n\\left[\\begin{array}{rrr}\r\n2 & 1 & -4 \\\\\r\n4 & 3 & -12 \\\\\r\n1 & 2 & -8\r\n\\end{array}\\right]\\left[\\begin{array}{l}\r\nx \\\\\r\ny \\\\\r\nz\r\n\\end{array}\\right]=\\left[\\begin{array}{l}\r\n\\alpha \\\\\r\n5 \\\\\r\n7\r\n\\end{array}\\right]\r\n$$\r\nThe augmented matrix for the given system is\r\n$$\r\n\\left[\\begin{array}{rrr|r}\r\n2 & 1 & -4 & \\alpha \\\\\r\n4 & 3 & -12 & 5 \\\\\r\n1 & 2 & -8 & 7\r\n\\end{array}\\right]\r\n$$\r\nFor infinite solutions to exist, the rank of the augmented matrix should be less than the total unknown variables, i.e. 3 . Therefore,\r\n$$\r\n\\begin{array}{l}\r\n\\left|\\begin{array}{lll}\r\n2 & 1 & \\alpha \\\\\r\n4 & 3 & 5 \\\\\r\n1 & 2 & 7\r\n\\end{array}\\right|=0 \\\\\r\n\\Rightarrow \\alpha(8-3)-5(4-1)+7(6-4)=0 \\\\\r\n\\Rightarrow \\alpha=\\frac{1}{5}\r\n\\end{array}\r\n$$\r\nTherefore, there is only one value of $\\alpha$ for which infinite solutions exist.\t\r\n\\end{answer}\r\n\\item The eigen value of matrix $A=\\left(\\begin{array}{lll}1 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 1\\end{array}\\right)$ is\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\lambda=1,0,2$  \r\n\t\\task[\\textbf{b.}]$\\lambda=-1, \\quad 2,2$\r\n\t\\task[\\textbf{c.}]$\\lambda=0,0,3$ \r\n\t\\task[\\textbf{d.}]$\\lambda=1,1,1$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n For eigen value $|A-\\lambda I|=0$\r\n$$\r\n\\begin{array}{l}\r\n\\left|\\begin{array}{ccc}\r\n1-\\lambda & 0 & 1-\\lambda \\\\\r\n0 & 1-\\lambda & 0 \\\\\r\n1 & 0 & 1-\\lambda\r\n\\end{array}\\right|=(1-\\lambda)\\left[(1-\\lambda)^{2}-0\\right]+0+1[-(1-\\lambda)]=0 \\\\\r\n\\Rightarrow-\\lambda^{3}+3 \\lambda^{2}-2 \\lambda=0 \\Rightarrow \\lambda=0,1,2\r\n\\end{array}\r\n$$\t\r\n\\end{answer}\r\n\\item  Which one of the following is the inverse of the matrix $\\left(\\begin{array}{cc}1 & -1 \\\\ 0 & 1\\end{array}\\right)?$\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\left(\\begin{array}{cc}1 & 1 \\\\ -1 & 1\\end{array}\\right)$  \r\n\t\\task[\\textbf{b.}]$\\left(\\begin{array}{ll}1 & 0 \\\\ 1 & 1\\end{array}\\right)$\r\n\t\\task[\\textbf{c.}] $\\left(\\begin{array}{ll}1 & 1 \\\\ 0 & 1\\end{array}\\right)$\r\n\t\\task[\\textbf{d.}]$\\left(\\begin{array}{cc}-1 & 1 \\\\ 0 & -1\\end{array}\\right)$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n$A^{-1}=\\frac{a d j A}{|A|}=\\frac{1}{1}\\left[\\begin{array}{ll}1 & 1 \\\\ 0 & 1\\end{array}\\right]=\\left[\\begin{array}{ll}1 & 1 \\\\ 0 & 1\\end{array}\\right]$\r\n\\\\Correct option is (c)\t\r\n\\end{answer}\r\n\\item The eigenvalues and eigenvectors of the matrix $\\left[\\begin{array}{ll}5 & 4 \\\\ 1 & 2\\end{array}\\right]$ are\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]6,1 and $\\left[\\begin{array}{c}4 \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -1\\end{array}\\right]$  \r\n\t\\task[\\textbf{b.}]2,5 and $\\left[\\begin{array}{c}4 \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -1\\end{array}\\right]$\r\n\t\\task[\\textbf{c.}] 6,1 and $\\left[\\begin{array}{c}4 \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -1\\end{array}\\right]$\r\n\t\\task[\\textbf{d.}]$(\\mathrm{d}) 2,5$ $\\left[\\begin{array}{c}4 \\\\ 1\\end{array}\\right],\\left[\\begin{array}{c}1 \\\\ -1\\end{array}\\right]$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\\begin{align*}\r\nA&=\\left[\\begin{array}{ll}\r\n5 & 4 \\\\\r\n1 & 2\r\n\\end{array}\\right] ;\\\\ \\text { eigenvalue equation: }|A-\\lambda I|&=0\\\\\r\n\\Rightarrow\\left|\\begin{array}{cc}\r\n5-\\lambda & 4 \\\\\r\n1 & 2-\\lambda\r\n\\end{array}\\right|&=0 \\quad\\\\ \\Rightarrow(\\lambda-2)(\\lambda-5)-4&=0 \\Rightarrow \\lambda^{2}-7 \\lambda+6=0 \\Rightarrow \\lambda=6,1\\\\\r\n\\begin{array}{l}\r\n\\text { Now, }(A-\\lambda I) X=0 \\\\\r\n\\Rightarrow \\quad\\left(\\begin{array}{cc}\r\n5-\\lambda & 4 \\\\\r\n1 & 2-\\lambda\r\n\\end{array}\\right)\\left(\\begin{array}{c}4 \\\\ 1\\end{array}\\right),\\left(\\begin{array}{c}1 \\\\ -1\\end{array}\\right)=0\r\n\\end{array}\r\n\\end{align*}\t\r\n\\end{answer}\r\n\\item $ \\mathrm{A}\\  3 \\times 3$ matrix $M$ has $\\operatorname{Tr}[M]=6, \\operatorname{Tr}\\left[M^{2}\\right]=26, \\operatorname{Tr}\\left[M^{3}\\right]=90 .$ Which of the following can be possible set of eigenvalues of M?\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]\\{1,1,4\\}  \r\n\t\\task[\\textbf{b.}]\\{-1,0,7\\}\r\n\t\\task[\\textbf{c.}] \\{-1,3,4\\} \r\n\t\\task[\\textbf{d.}]\\{2,2,2\\} \r\n\\end{tasks}\r\n\\begin{answer}\r\n$$\\lambda_{1}+\\lambda_{2}+\\lambda_{3}=6 ; \\quad \\lambda_{1}^{2}+\\lambda_{2}^{2}+\\lambda_{3}^{2}=26 ; \\lambda_{1}^{3}+\\lambda_{2}^{3}+\\lambda_{3}=90$$\r\n\\\\It is trivial to check that only \\{-1,3,4\\} satisfies there three equation.\t\r\n\\end{answer}\r\n\r\n\\end{enumerate}\r\n\r\n", "meta": {"hexsha": "d0950f1ddbb0b23e8e02e7d0c80127b734d7c7f0", "size": 81459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/matrices.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/matrices.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/matrices.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.9243437983, "max_line_length": 536, "alphanum_fraction": 0.5937219951, "num_tokens": 32204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.6824901506534035}}
{"text": "\\section{First Order Linear Equations}{}{}\\label{sec:first order linear}\nAs you might guess, a first order linear differential equation has the form \n$\\ds y' + p(t)y = f(t)$. Not only is this closely related in form\nto the first order homogeneous linear equation, we can use what we\nknow about solving homogeneous equations to solve the general linear\nequation. \n\nSuppose that $y_1(t)$ and $y_2(t)$ are solutions to \n$\\ds y' + p(t)y = f(t)$. Let $\\ds g(t)=y_1-y_2$. Then\n\\begin{eqnarray*}\n g'(t)+p(t)g(t)&=&y_1'-y_2'+p(t)(y_1-y_2)\\cr\n&=&(y_1'+p(t)y_1)-(y_2'+p(t)y_2)\\cr\n&=&f(t)-f(t)=0.\n\\end{eqnarray*}\nIn other words, $\\ds g(t)=y_1-y_2$ is a solution to the homogeneous\nequation $\\ds y' + p(t)y = 0$. Turning this around, any solution\nto the linear equation $\\ds y' + p(t)y = f(t)$, call it $y_1$, can\nbe written as $y_2+g(t)$, for some particular $y_2$ and some solution\n$g(t)$ of the homogeneous equation $\\ds y' + p(t)y = 0$. Since we\nalready know how to find all solutions of the homogeneous equation,\nfinding just one solution to the equation $\\ds y' + p(t)y = f(t)$\nwill give us all of them.\n\nHow might we find that one particular solution to $\\ds y' + p(t)y\n= f(t)$? Again, it turns out that what we already know helps. We know\nthat the general solution to the homogeneous equation\n$\\ds y' + p(t)y = 0$ looks like $\\ds Ae^{P(t)}$. We now make an\ninspired guess: Consider the function $\\ds v(t)e^{P(t)}$, in which we\nhave replaced the constant parameter $A$ with the function\n$v(t)$. This technique is called \n\\dfont{variation of parameters}.\nFor\nconvenience write this as $s(t)=v(t)h(t)$, where $\\ds h(t)=e^{P(t)}$ \nis a solution to the\nhomogeneous equation. Now let's compute a bit with $s(t)$:\n\\begin{eqnarray*}\ns'(t)+p(t)s(t)&=&v(t)h'(t)+v'(t)h(t)+p(t)v(t)h(t)\\cr\n&=&v(t)(h'(t)+p(t)h(t)) + v'(t)h(t)\\cr\n&=&v'(t)h(t).\\end{eqnarray*}\nThe last equality is true because $\\ds h'(t)+p(t)h(t)=0$. Since $h(t)$\nis a solution to the homogeneous equation. We are hoping to find a\nfunction $s(t)$ so that $\\ds s'(t)+p(t)s(t)=f(t)$; we will have such a\nfunction if we can arrange to have $\\ds v'(t)h(t)=f(t)$, that is,\n$\\ds v'(t)=f(t)/h(t)$. But this is as easy (or hard) as finding an\nanti-derivative of $\\ds f(t)/h(t)$. Putting this all together, the\ngeneral solution to $\\ds y' + p(t)y = f(t)$ is\n$$v(t)h(t)+Ae^{P(t)} = v(t)e^{P(t)}+Ae^{P(t)}.$$\n\\begin{example}{Solving an IVP}{Solving an IVP}\\label{Solving an IVP}\n Find the solution of the initial value problem\n$\\ds y'+3y/t=t^2$, $y(1)=1/2$. \n\\end{example}\n\n\\begin{solution}\nFirst we find the general solution;\nsince we are interested in a solution with a given condition at $t=1$,\nwe may assume $t>0$.\nWe start by solving the homogeneous equation as usual; call the\nsolution $g$:\n$$g=Ae^{-\\int (3/t)\\,dt}=Ae^{-3\\ln t}=At^{-3}.$$\nThen as in the discussion, $\\ds h(t)=t^{-3}$ and\n$\\ds v'(t)=t^2/t^{-3}=t^5$, so $\\ds v(t)=t^6/6$. We know that\nevery solution to the equation looks like\n$$v(t)t^{-3}+At^{-3}={t^6\\over6}t^{-3}+At^{-3}={t^3\\over6}+At^{-3}.$$\nFinally we substitute to find $A$:\n\\begin{eqnarray*}\n{1\\over 2}&=&{(1)^3\\over6}+A(1)^{-3}={1\\over6}+A\\cr\nA&=&{1\\over 2}-{1\\over6}={1\\over3}.\n\\end{eqnarray*}\nThe solution is then\n$$y={t^3\\over6}+{1\\over3}t^{-3}.$$\n\\end{solution}\n\nAnother common method for solving such a differential equation is by means of an\n\\dfont{integrating factor}. \n\n\\subsection*{Using an Integrating Factor}\n\\label{sec:integrating-factor}\n\nLinear equations of the form $ y'+p(t)y=q(t) $ can always be solved by multiplying both sides of the equation\nwith a specially chosen function called the \\emph{integrating factor,} $ I(t)$.  It is\ndefined by\n\\begin{equation}\nI (t) = e^{\\int p(t)\\; dt}.\n  \\label{eq:integrating-factor-defined}\n\\end{equation}\n It looks like we just pulled this definition\nof $I(t)$ out of a hat.  \n\nMultiply the equation by the integrating factor\n$I(t)$ to get\n\\[\nI(t)\\frac{d y}{d t}+p(t)I(t)y = I(t)q(t).\n\\]\nBy the chain rule the integrating factor satisfies\n\\[\n\\frac{ d }{d t}I(t) = \\frac{d} {d t} e^{\\int p(t)\\; dt}\n= \\underbrace{\\frac{d} {d t} \\left( \\int p(t)\\; dt\\right)}_{=p(t)} ~\\underbrace{e^{\\int p(t)\\; dt}_{}}_{=I(t)}\n= p(t)I(t).\n\\]\nTherefore one has\n\\begin{align*}\n  \\frac{d }{d t}I(t)y\n  &= I(t)\\frac{\\; d }{\\; d t}y +p(t)I(t)y \\\\\n  &= I(t)\\Bigl\\{\\frac{d}{d t} y+p(t)y \\Bigr\\}\\\\\n  &= I(t)q(t).\n\\end{align*}\nIntegrating and then dividing by the integrating factor gives the solution\n\\[\ny=\\frac1{I(t)}\\left(\\int I(t)q(t)\\,d t+C\\right).\n\\]\nIn this derivation we have to divide by $I(t)$, but since $I(t)=e^{\\int p(t)\\; dt}$ and since\nexponentials never vanish we know that $I (t)\\neq0$, so we can always divide by $I\n(t)$.\n\n\n% In the differential equation\n%$\\ds y'+p(t)y=f(t)$, we note that if we multiply through by a function\n%$I(t)$ to get $\\ds I(t)y'+I(t)p(t)y=I(t)f(t)$, the left hand side\n%looks like it could be a derivative computed by the product rule:\n%$${d\\over dt}(I(t)y)=I(t)y'+I'(t)y.$$\n%Now if we could choose $I(t)$ so that $I'(t)=I(t)p(t)$, this would be\n%exactly the left hand side of the differential equation. But this is\n%just a first order homogeneous linear equation, and we know a solution\n%is $\\ds I(t)=e^{Q(t)}$, where $\\ds Q(t)=\\int p\\,dt$; note that \n%$Q(t)=-P(t)$, where $P(t)$ appears in the variation of parameters\n%method and $P'(t)=-p$. Now the modified differential equation is \n%\\begin{eqnarray*}\n%e^{-P(t)}y'+e^{-P(t)}p(t)y&=&e^{-P(t)}f(t)\\cr\n%{d\\over dt}(e^{-P(t)}y)&=&e^{-P(t)}f(t).\\cr\n%\\end{eqnarray*}\n%Integrating both sides gives\n%\\begin{eqnarray*}\n%e^{-P(t)}y&=&\\int e^{-P(t)}f(t)\\,dt\\cr\n%y&=&e^{P(t)}\\int e^{-P(t)}f(t)\\,dt.\\cr\n%\\end{eqnarray*}\nIf you look carefully, you will see that this is exactly the same\nsolution we found by variation of parameters, because\n$\\ds e^{-P(t)}q(t)=q(t)/h(t)$.\n\nSome people find it easier to remember how to use the integrating\nfactor method, rather than variation of parameters. Since ultimately they\nrequire the same calculation, you should use whichever of the two methods\nappeals to you more strongly. \n\n\n\n\n\n\\begin{example}{}{sec:an-example}\nFind the general solution to the differential equation\n\\[\n\\frac{\\; d y} {\\; d x} = y + x.\n\\]\nThen find the solution that satisfies \\upshape\n\\begin{equation}\n  y(2)=0.\n  \\label{eq:example-linear-initial-condition}\n\\end{equation}\n\\end{example}\n\n\n\\begin{solution}\nWe first write the equation in the standard linear form\n\\begin{equation}\n  \\label{eq:diffeq-linear-example}\n  \\frac{\\; d y} {\\; d x} - y = x,\n\\end{equation}\nand then multiply by the integrating factor $I(x)$.  We could of course memorize\nthe formula \n\\[\nI(x) = e^{\\int p(x)\\;dx}\n\\]\nbut the following procedure will always give us the integrating factor.\n\nAssuming that $I(x)$ is as yet unknown we multiply the differential\nequation~\\eqref{eq:diffeq-linear-example} by $I$,\n\\begin{equation}\n  I(x)\\frac{\\; d y} {\\; d x} - I(x) y = I(x)x.\n  \\label{eq:example-multiplied-with-m}\n\\end{equation}\nIf $I(x)$ is such that\n\\begin{equation}\n  -I(x) = \\frac{\\; d I(x)} {\\; d x},\n  \\label{eq:integrating-factor-condition}\n\\end{equation}\nthen equation~\\eqref{eq:example-multiplied-with-m} implies\n\\[\n  I(x)\\frac{\\; d y} {\\; d x} + \\frac{\\; d I(x)} {\\; d x} y = I(x)x.\n\\]\nThe expression on the left is exactly what comes out of the product rule -- this is\nthe point of multiplying with $I(x)$ and then insisting\non~\\eqref{eq:integrating-factor-condition}.  So, if $I(x)$\nsatisfies~\\eqref{eq:integrating-factor-condition}, then the differential equation for\n$y$ is equivalent with\n\\[\n\\frac{\\; d I(x) y} {\\; d x} = I(x) x.\n\\]\nWe can integrate this equation,\n\\[\nI(x) y = \\int I(x) x \\;\\; d x,\n\\]\nand thus find the solution\n\\begin{equation}\n  y(x) =  \\frac{1} {I(x)}  \\int I(x) x \\;\\; d x.\n  \\label{eq:example-linear-almost-solved}\n\\end{equation}\nAll we have to do is find the integrating factor $I$.  This factor can be any\nfunction that satisfies~\\eqref{eq:integrating-factor-condition}.\nEquation~\\eqref{eq:integrating-factor-condition} is a differential equation for $I$,\nbut it is separable, and we can easily solve it:\n\\[\n\\frac{\\; d I} {\\; d x} = -I \\iff\n\\frac{1} {I} \\; d I = -\\; d x \\iff\n\\ln|I| = -x +C.\n\\]\nSince \\textit{we only need one integrating factor} $I$ we are not interested in\nfinding all solutions of~\\eqref{eq:integrating-factor-condition}, and therefore we\ncan choose the constant $C$.  The simplest choice is $C=0$, which leads to\n\\[\n\\ln |I| = -x \\iff |I| = e^{-x} \\iff I = \\pm e^{-x}. \n\\]\nAgain, we only need one integrating factor, so we may choose the $\\pm$~sign: the simplest\nchoice for $I$ here is\n\\[\nm(x) = e^{-x}.\n\\]\nWith this choice of integrating factor we can now complete the calculation that led\nto~\\eqref{eq:example-linear-almost-solved}.  The solution to the differential\nequation is\n\\begin{align*}\n  y(x)\n  &= \\frac{1} {I(x)}  \\int I(x) x \\;\\; d x \\\\\n  &= \\frac{1} {e^{-x}} \\int e^{-x}x \\;\\; d x\n  &\\text{\\color{red}\\sffamily\\footnotesize%\n    (integrate by parts)}\\\\\n  &= e^{x} \\Bigl\\{-e^{-x}x - e^{-x} + C\\Bigr\\} \\\\\n  &= -x-1+Ce^x.\n\\end{align*}\nThis is the general solution.\n\nTo find the solution that satisfies not just the differential equation, but also the\n``initial condition''~\\eqref{eq:example-linear-initial-condition}, i.e.~$y(2)=0$, we\ncompute $y(2)$ for the general solution,\n\\[\ny(2) = -2-1+Ce^2 = -3 + Ce^2.\n\\]\nThe requirement $y(2) = 0$ then tells us that $C=3e^{-2}$.  The solution of the\ndifferential equation that satisfies the prescribed initial condition is therefore\n\\[\ny(x) = -x-1+3e^{x-2}.\n\\]\n\\end{solution}\n\n\n\n\\begin{example}\nUse the Integrating Factor method to solve the IVP in Example \\ref{exa:Solving an IVP}\n\\end{example}\n\n\n\\begin{solution}\nGiven $\\ds y'+3y/t=t^2$, we have $ p(t) = \\frac{3}{t} $, $ q(t) =  t^2 $, the integrating factor is $ I(t) = e^{\\int(p(t)\\; dt} $, and the solution to the differential equation is\n\\[\ny=\\frac{1}{I(t)}\\int I(t)q(t)\\; dt\n\\] \nwhere \n\\[\nI(t) = \\ds e^{\\int 3/t}=e^{3\\ln |t|}=|t^3|=\\pm t^3\n\\]\n\nAgain, we only need one integrating factor, so we may choose $ I(t)=t^3 $. So the general solution is\n\n\\[\ny=\\frac{1}{t^3}\\int t^3\\cdot t^2\\; dt = \\frac{1}{t^3}\\int t^5\\; dt = \\frac{1}{t^3}\\left(\\frac{t^6}{6}+C\\right) =\\frac{t^3}{6}+\\frac{C}{t^3} \n\\] \n\nThe initial value $ y(1)=\\frac12 $ then gives $ C=\\frac13 $, giving the same answer as before.\n \n\\end{solution}\n\n%Using this method to solve the  the solution of the previous\n%example would look just a bit different: Starting with\n%$\\ds y'+3y/t=t^2$, we recall that the integrating factor is\n%$I(t) = \\ds e^{\\int 3/t}=e^{3\\ln t}=t^3$. Then we multiply through by the\n%integrating factor and solve:\n%\\begin{eqnarray*}\n%t^3y'+t^3 3y/t&=&t^3t^2\\cr\n%t^3y'+t^2 3y&=&t^5\\cr\n%{d\\over dt}(t^3 y)&=&t^5\\cr\n%t^3 y&=&t^6/6\\cr\n%y&=&t^3/6.\n%\\end{eqnarray*}\n%This is the same answer, of course, and the problem is then finished\n%just as before.\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:first order linear}}\n\n\\begin{enumialphparenastyle}\n\nIn the following exercises, find the general solution of the equation.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' +4y=8$\n\\begin{sol}\n $\\ds y=Ae^{-4t}+2$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'-2y=6$\n\\begin{sol}\n $\\ds y=Ae^{2t}-3$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' +ty=5t$\n\\begin{sol}\n $\\ds y=Ae^{-(1/2)t^2}+5$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'+e^ty=-2e^t$\n\\begin{sol}\n $\\ds y=Ae^{-e^t}-2$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'-y=t^2$\n\\begin{sol}\n $\\ds y=Ae^{t}-t^2-2t-2$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds 2y' +y=t$\n\\begin{sol}\n $\\ds y=Ae^{-t/2}+t-2$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds ty' -2y=1/t$, $t>0$\n\\begin{sol}\n $\\ds y=At^2-{1\\over3t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds ty'+y=\\sqrt{t}$, $t>0$\n\\begin{sol}\n $\\ds y={c\\over t}+{2\\over3}\\sqrt t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'\\cos t+y\\sin t=1$, $-\\pi/2<t<\\pi/2$\n\\begin{sol}\n $\\ds y= A\\cos t+\\sin t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' + y\\sec t=\\tan t$, $-\\pi/2<t<\\pi/2$\n\\begin{sol}\n $\\ds y= {A\\over\\sec t+\\tan t}+1-{t\\over\\sec t+\\tan t}$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "f1f83d59d433d7d4f0d0a7e54c599250f04d73d0", "size": 12092, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-3-first-order-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-3-first-order-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-3-first-order-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": 30.5353535354, "max_line_length": 179, "alphanum_fraction": 0.6366192524, "num_tokens": 4415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.6824901448674696}}
{"text": "\\chapter{Appendix}\\label{cha:appendix}\n\n\\section{3D Bresenham Algorithm}\\label{app:3dbresen}\n\\begin{algorithm}[H]\n  \\caption{The Bresenham algorithm for calculating a straight line in 3D}\n  \\SetAlgoLined\n  \\DontPrintSemicolon\n  $e_y \\leftarrow 2 \\Delta Y - \\Delta X$\\;\n  $e_z \\leftarrow 2 \\Delta Z - \\Delta X$\\;\n  $x \\leftarrow X_0$, $y \\leftarrow Y_0$, $z \\leftarrow Z_0$\\;\n  \\While{$x \\le X_1$}\n  {\n    $voxel \\leftarrow (x,y,z)$\\;\n    SetVoxel($voxel$)\\;\n    $x \\leftarrow x + 1$\\;\n    \\eIf{$e_y \\ge 0$}\n    {\n      $y \\leftarrow y + 1$\\;\n      $e_y \\leftarrow e_y + 2(\\Delta Y - \\Delta X)$\\;\n    }\n    {\n      $e_y \\leftarrow e_y + 2\\Delta Y$\\;\n    }\n    \\eIf{$e_z \\ge 0$}\n    {\n      $z \\leftarrow z + 1$\\;\n      $e_z \\leftarrow e_z + 2(\\Delta Z - \\Delta X)$\\;\n    }\n    {\n      $e_z \\leftarrow e_z + 2\\Delta Z$\\;\n    }\n  }\n\\end{algorithm}\n\n\\newpage\n\n\\section{6-Connected Bresenham Algorithm Modification}\\label{app:3dbresen-4}\n\\begin{algorithm}[H]\n  \\caption{Modification for the y-axis of the Bresenham algorithm to voxelize a 6-connected line. The same modification is done for the z-axis.}\n  \\SetAlgoLined\n  \\DontPrintSemicolon\n  \\eIf{$e_y \\ge 0$}\n  {\n    \\eIf{$e_y \\geq \\Delta Y$}\n    {\n      $voxel \\leftarrow (voxel.x, voxel.y+1, voxel.z)$\\;\n    }\n    {\n      $voxel \\leftarrow (x,y,z)$\\;\n    }\n    SetVoxel($voxel$)\\;\n    $y \\leftarrow y + 1$\\;\n    $e_y \\leftarrow e_y + 2(\\Delta Y - \\Delta X)$\\;\n  }\n  {\n    $e_y \\leftarrow e_y + 2\\Delta Y$\\;\n  }\n\\end{algorithm}\n\n\\newpage\n\n\\section{CUDA-OpenGL Interoperability}\\label{app:cuda-opengl-inter}\n\\begin{lstlisting}[language=C++]\n  // ================ DEVICE ================\n\n  surface<void, 3> voxelGrid;\n\n  __device__\n  void WriteToTexture(int3 voxel, unsigned char color)\n  {\n      surf3Dwrite(color, voxelGrid, voxel.x, voxel.y, voxel.z);\n  }\n\n  // ================= HOST =================\n\n  // Create OpenGL texture\n  glGenTextures(1, &glTex);\n  glBindTexture(GL_TEXTURE_3D, glTex);\n  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\n  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\n  glTexImage3D(GL_TEXTURE_3D, 0, GL_R8, size, size, size, 0, GL_RED, GL_FLOAT, nullptr);\n\n  // Register the OpenGL texture as a CUDA texture\n  cuGraphicsGLRegisterImage(&cudaTex,  glTex, GL_TEXTURE_3D, CU_GRAPHICS_REGISTER_FLAGS_SURFACE_LDST);\n\n  // Bind the CUDA texture to a CUDA array\n  cuGraphicsMapResources(1, &cudaTex, 0);\n  cuGraphicsSubResourceGetMappedArray(&cudaArray, cudaTex, 0, 0);\n  cuGraphicsUnmapResources(1, &cudaTex, 0);\n\n  // Link the CUDA array to a CUDA surface\n  cuModuleGetSurfRef(&cudaSurfRef, module, \"voxelGrid\");\n  cuSurfRefSetArray(cudaSurfRef, cudaArray, 0);\n\\end{lstlisting}\n\n\\newpage\n\n\\section{Voxelizations}\\label{app:voxelizations}\n\\voxelizationfig{monkey}{rlv}{Floating-point voxelization using RLV of the Blender monkey at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{monkey}{ilv}{Integer voxelization using ILV of the Blender monkey at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{monkey}{bre}{Integer voxelization using Bresenham of the Blender monkey at 16, 32, 64, \n128, 256 and 512 resolution}{}\n\n\\FloatBarrier\n\n\\voxelizationfig{dragon}{rlv}{Floating-point voxelization using RLV of the Stanford dragon at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{dragon}{ilv}{Integer voxelization using ILV of the Stanford dragon at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{dragon}{bre}{Integer voxelization using Bresenham of the Stanford dragon at 16, 32, 64, 128, 256 and 512 resolution}{}\n\n\\FloatBarrier\n\n\\section{Performance Data}\\label{app:performance-data}\n\\begin{table}[h]\n  \\centering\n\\begin{tabular}{l|l|lllll}\n  Model & Algorithm & 128 & 256 & 512 & 1024 & 2048 \\\\\n  \\hline\n         & RLV & 0.168047 & 0.360608 & 1.17848 & 4.18106 & 16.5649 \\\\\n  Monkey & ILV & 0.213802 & 0.576965 & 1.84135 & 5.96018 & 21.9102 \\\\\n         & Bre & 0.24961 & 0.636628 & 1.86863 & 5.72366 & 19.9131 \\\\\n  \\hline\n         & RLV & 0.193737 & 0.369392 & 1.76889 & 6.86508 & 21.5765 \\\\\n  Bunny  & ILV & 0.602098 & 1.22562 & 3.29431 & 9.25156 & 27.0328 \\\\\n         & Bre & 0.988574 & 1.92251 & 4.5347 & 11.6089 & 31.9672 \\\\\n  \\hline\n         & RLV & 1.22597 & 1.50882 & 2.32364 & 4.89038 & 18.1659 \\\\\n  Dragon & ILV & 3.86642 & 5.36262 & 8.12676 & 16.3983 & 42.3611 \\\\\n         & Bre & 6.71438 & 9.32611 & 13.8366 & 26.5671 & 60.6166 \\\\\n\\end{tabular}\n\\caption{The Raw performance data of the different algorithms, with varying models and resolution. Bre in the table is short for Bresenham. Timings are in milliseconds.}\n\\end{table}\n\n\n\\section{Voxelization Error}\\label{app:compare-error}\nIn the following figures the yellow voxels are voxels in both algorithms. The red voxels are only in the algorithm mentioned first and the blue voxels are only in the algorithm mentioned last. \nFor example, in \\figref{fig:monkey-compare}, RLV is mentioned first and therefore corrispond with red voxels, while ILV is mentioned last and are blue voxels. \n\n\\voxelizationfig{monkey}{rlv_ilv}{Difference between RLV and ILV for the Blender monkey at 16, 32, 64, 128, 256 and 512 resolution}{fig:monkey-compare}\n\\voxelizationfig{monkey}{rlv_bre}{Difference between RLV and Bresenham for the Blender monkey at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{monkey}{ilv_bre}{Difference between ILV and Bresenham for the Blender monkey at 16, 32, 64, 128, 256 and 512 resolution}{}\n\n\\FloatBarrier\n\n\\voxelizationfig{bunny}{rlv_ilv}{Difference between RLV and ILV for the Stanford bunny at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{bunny}{rlv_bre}{Difference between RLV and Bresenham for the Stanford bunny at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{bunny}{ilv_bre}{Difference between ILV and Bresenham for the Stanford bunny at 16, 32, 64, 128, 256 and 512 resolution}{}\n\n\\FloatBarrier\n\n\\voxelizationfig{dragon}{rlv_ilv}{Difference between RLV and ILV for the Stanford dragon at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{dragon}{rlv_bre}{Difference between RLV and Bresenham for the Stanford dragon at 16, 32, 64, 128, 256 and 512 resolution}{}\n\\voxelizationfig{dragon}{ilv_bre}{Difference between ILV and Bresenham for the Stanford dragon at 16, 32, 64, 128, 256 and 512 resolution}{}\n\n\\FloatBarrier\n", "meta": {"hexsha": "f1e440925eb33fdc82744e58b84c49bd7f33f25c", "size": 6317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Latex/appendix.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/appendix.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/appendix.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": 40.7548387097, "max_line_length": 193, "alphanum_fraction": 0.6927338927, "num_tokens": 2186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.6824901444189961}}
{"text": "\\chapter{Pricing}\n\n\\section{Non-risky instruments}\n\nTime preference.\nDiscount.\n\nThe price of a risky instrument\nis the risk-neutral price plus the \\emph{risk premium}.\n\n\\section{Risk-neutral price of risky instruments}\n\nLet $X$ be random process of the price.\n$X t$ is the random variable for the price at time $t$.\n\n\\section{Futures contracts}\n\nThe risk-neutral price of futures contract with $T$ time to expiration.\n\\begin{align}\n    \\int_{\\mathbb{R}} p [X T = x] \\cdot x \\cdot e^{- r \\cdot T} \\cdot dx\n\\end{align}\n\n\\section{European call options}\n\nThe risk-neutral price of European call option\nthat has strike price $k$ and expires in time $T$ from now\nshould be\n\\begin{align}\n    \\int_k^\\infty p [X T = x] \\cdot (x - k) \\cdot e^{- r \\cdot T} \\cdot dx\n\\end{align}\nor, discretely,\n\\begin{align}\n    \\sum_{x \\in \\mathbb{X}} p[X T = x] \\cdot (x - k) \\cdot e^{- r \\cdot T} \\cdot \\Delta x,\n\\end{align}\npossibly with $\\Delta x = \\$ 0.01$\nand $p$ taken from binomial distribution.\n\nGiven any two of these three quantities,\nthe other one can be computed:\n\\begin{itemize}\n    \\item actual current price,\n    \\item implied distribution of price at expiration,\n    \\item risk-free interest rate.\n\\end{itemize}\n\n\\section{American call options}\n\nThe risk-neutral price of American call option\nthat has strike price $k$ and expires in time $T$ from now\nshould be\n\\begin{align}\n    \\int_0^T \\int_k^\\infty p [X t = x] \\cdot (x - k) \\cdot e^{-r \\cdot t} \\cdot dx \\cdot dt\n\\end{align}\n\nThe probability that the instrument price lies in the interval $X$\nwhen the time is in the interval $T$ is\n\\begin{align}\n    \\int_T \\int_X f x t \\cdot dx \\cdot dt\n\\end{align}\n", "meta": {"hexsha": "13d5134d8f881f815e1de14f62d2ee2b5eb10a13", "size": 1647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/pricing.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/pricing.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/pricing.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": 27.45, "max_line_length": 91, "alphanum_fraction": 0.6988463874, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6823926005526766}}
{"text": "\\section{Introduction} \\label{sec:introduction}\n\n\n% notation\n\nLet us define a society of $\\pop = \\{ 1, \\ldots, P\\}$ composed by $P \\geq 1$ populations. Each population consist of a large number of agents, which conform a mass $m^p > 0$, with $p \\in \\pop$. \nLet $S^p = \\{ 1, \\ldots, n^p \\}$ be the set of actions (or pure strategies) available for each agent of the $p\\th$ population. \nEach agent selects a pure strategy and the resulting state of the population is the usage proportion of each strategy. The set of population states is defined as $X^p = \\{ x^p \\in \\mathbb{R}_+^{n^p} : \\sum_{i \\in S^p} x_i^p = m^p \\}$, where the $i\\th$ component of the state, denoted by $x_i^p \\in \\mathbb{R}_+$, is the mass of players that select the $i\\th$ strategy of the population $p$.\n\nPopulation games (or large games) capture some properties of the interactions of many economic agents, e.g., \n\n\\begin{enumerate}\n\\item large number of agents.\n\\item Continuity: The actions of an agent has small impact on the payoff of other agents.\n\\item Anonymity: means that the utility of each agent only depends on the aggregated actions of the other agents.\n\\end{enumerate}\n\nGame theory is useful to model decision making of agents that are rational. In game theory rationality is the ability to adopt the best actions to achieve some particular goals. This implies that agents use all the information available to make decisions. Evolutionary games relax the rationality assumption by considering myopic behavior. Thus, we assume that agents choose that actions that seem to improve their fitness, however, these actions might not be optimal (as would be the case for rational agents). Thus, evolutionary games can be useful to analyze the behavior of agents in repeated games, where rationality assumptions cannot be made. \n\n\nIn particular, an economic agent decides whether to modify or not its strategy according to the available information. In this respect, we assume that the agent's behavior satisfies both inertia and myopia properties. On the one hand, inertia \nis the tendency to remain at the status-quo, unless there exist motives to do that.\nAlso, this implies that the strategy adjustment events are rare events.\nOn the other hand, myopia means that the information used to make decisions is limited, e.g., each user makes decisions based on the current state of the population and do not estimate future actions. These two properties are based on the population games theoretical framework \\cite{sandholm_book}\nand behavioral economics \\cite{gal}.\n\nTo accomplish the inertia property, the time between two successive updates of one \nagent's strategy is modeled with an exponential distribution (this distribution is used to model the occurrence of rare events). \nThus, strategy actualization events could be characterized by means of stochastic alarm clocks.\nParticularly, a rate $R_i$ Poisson alarm clock produces time among rings described by\na rate $R_i$ exponential distribution.\nThe whole actualization events in the population can be considered as a rate $R=\\sum_{j\\in \\mathcal{V}} R_j$ Poisson alarm clock.\nTherefore, the average number of events in a given time interval is $R$ and the probability of selecting the $i^{th}$\nagent in a given time instant is\n $\\frac{R_i}{R}$ \\cite{sandholm_book}.\n\nAt each update opportunity (revision opportunity), the $i\\th$ agent might compare the average profit of its strategy with the average profit of other strategies. Particularly, an agent might change its strategy with rate $\\rho_{ij}$.\n \n The rate of change $\\rho_{ij}$ is determined by a revision protocol, which defines the procedure used by each user to decide whether to change or not its strategy. The scalar $\\rho_{ij} (\\pi^p, x^p)$ is the \\emph{conditional switch rate} from strategy $i$ to strategy $j$ in function of a given payoff vector $\\pi$ and a population state $x^p$.\n \n Using the law of large numbers we can approximate the evolution of the society's state to a dynamical equation defined by\n \\begin{equation}\\label{eq:mean_dynamic}\n  \\dot{x}_i^p = \\sum_{j\\in S^p} x_j^p \\rho_{ji} (\\pi^p, x^p) - x_i^p \\sum_{j\\in S^p} \\rho_{ij}(\\pi^p, x^p).\n \\end{equation}\nThe previous equation is known as the \\emph{mean dynamic}, which is used to define  some of the dynamics in the next section.\n\n ", "meta": {"hexsha": "689a90381832ca55a4b806c32226eedf15e5b169", "size": 4303, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/introduction.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/introduction.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/introduction.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": 91.5531914894, "max_line_length": 650, "alphanum_fraction": 0.7678363932, "num_tokens": 1046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6823399691684647}}
{"text": "\\documentclass[a4paper,twocolumn]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{textcomp}\n\n\\usepackage[dvips,pdftex]{geometry}\n\\usepackage{graphicx}\n\\usepackage{listings}\n\\usepackage{pifont}\n\\DeclareMathOperator{\\rank}{rank}\n\\DeclareMathOperator{\\ld}{ld}\n\n\\newcommand{\\set}[1]{\\left\\{#1\\right\\}}\n\\newcommand{\\io}[2]{{\\par\\noindent\\textbf{Input:} #1 \\\\}{\\textbf{Output:} #2 \\\\}}\n\\newcommand{\\wa}[1]{\\textbf{Wolframalpha:} $#1$ \\\\}\n\\newcommand{\\scriptref}[1]{\\textbf{Skriptum.} page #1 \\\\}\n\\newcommand{\\dt}[1]{\\textbf{Deutsch } #1 \\\\}\n\n\\begin{document}\n\\tableofcontents\n\n\\section{Basic Linear Algebra}\n\n\\[\n    0 := \\begin{pmatrix}\n        0 & \\ldots & 0 \\\\\n        \\vdots & \\ddots & \\vdots \\\\\n        0 & \\ldots & 0 \\\\\n    \\end{pmatrix}\n\\] \\[\n    A = B \\Leftrightarrow a_{ij} \\in A = b_{ij} \\in B\n\\] \\[\n    A + 0 = 0 + A = A\n    \\qquad\n    A + (-A) = 0\n\\] \\[\n    A \\cdot x = b\n    \\quad\\Rightarrow\\quad\n    x = A^{-1} \\cdot b\n\\] \\[\n    a_{ij} \\in A \\Leftrightarrow (-a_{ij}) \\in (-A)\n\\] \\[\n    A + (B + C) = (A + B) + C\n    \\qquad\n    A(BC) = (AB)C\n\\] \\[\n    (\\lambda + \\mu) \\cdot A = \\lambda \\cdot A + \\mu \\cdot A\n\\] \\[\n    A \\text{ has $m$ rows and $n$ columns}\n        \\Leftrightarrow A \\in M(m\\times n)\n\\]\n\nA linear system of equations can be translated to matrizes\ndirectly.\n%\n\\[\n    \\begin{array}{cccccc}\n        -3x & + & -3y & -3z & = & -3 \\\\\n        -2x & + &  2y &   z & = & 0 \\\\\n          x & + & -3y &  3z & = & 0 \\\\\n    \\end{array}\n\\] \\[\n    \\Rightarrow\n    A = \\left(\\begin{array}{cccc}\n        -3 & -3 & -3 & -3 \\\\\n        -2 &  2 &  1 & 0 \\\\\n         1 & -3 &  3 & 0 \\\\\n    \\end{array}\\right)\n\\]\n\nTo create an extended coefficient matrix, you have to add the solutions\nas the most right column (thus $\\{A, b\\}$).\nIf you want to solve this system, you have to find $x$ in\n$A\\times x = b$, where $A$ are the coefficients of the system and\n$b$ are the solutions.\n\nThis can be done by performing arithmetic row-wise operations.\nAn example is taking the third row minus $\\frac12$ times the second\nrow. The result is a tuple $(0, -4, 2.5, 0)$ which can replace . Each operation returns\na factor (here: $-\\frac12$); we will need this for decompositions.\nOkay, the result can be taken as new second row. So how is the general\nalgorithm?\n\n\\subsection{Gaussian elimination}\n\\io{Invertible square matrix}{triangular form}\n\\wa{\\operatorname{RowReduce}[A]}\n\\scriptref{9}\n\nIn a $m\\times n$ matrix ($m$ rows, $n$ columns), we want to reach\nthe structure of an upper triangular matrix. So if the result of such\nan operation is $(0, -4, 2.5, 0)$, we will prefer to use it as the\nsecond row (because of the one zero to the left). We will perform operations\nuntil we reach the expected structure; the ''triangular form'' (numerical\nanalysis) or ''row echelon form'' (abstract algebra).\n%\n\\[\n    \\left(\\begin{array}{cccc}\n        -3 & -3 &   -3 & -3 \\\\\n        0  & -4 &  2.5 &  0 \\\\\n        0  &  0 & -0.5 & -1 \\\\\n    \\end{array}\\right)\n\\]\n\nThis structure can be easily transformed to the solution of the linear\nsystem.\n%\n\\begin{minipage}{0.2\\textwidth}\\[\n    -0.5z = -1\n\\] \\[\n    -4y + 2.5 \\cdot (-1) = 0\n\\] \\[\n    y = \\frac54\n\\]\n\\end{minipage}\\begin{minipage}{0.3\\textwidth}\n\\[\n    -3x - \\frac{15}{4} = \\frac{12}{4}\n\\] \\[\n    x = -\\frac94\n\\]\\end{minipage}\n\nOtherwise we can continue the elimination algorithm to create an\nidentity matrix on the left side (columns 1--3 here). This way\nwe can read the variable values immediately. This algorithm is\ncalled Gauss-Jordan Elimination.\n\n\\subsection{Notes}\n\n\\begin{itemize}\n  \\item Pivot elements are the most-left numbers of the rows.\n        $-3$, $-4$ and $-0.5$ in the  previous example.\n  \\item $\\rank{A}$ is the number of rows with non-zero pivot elements\n        in the triangular matrix of $A$. $\\rank{A} = 3$ in the\n        previous example.\n  \\item Sometimes swapping rows is necessary to reach a triangular\n        structure.\n  \\item If there are only non-zero pivots, there is only one solution\n        for the linear system. Otherwise we don't know anything about\n        solutions.\n  \\item There are 3 operations that can be performed (elementary row\n        operations):\n    \\begin{itemize}\n      \\item Swapping rows\n      \\item multiplication of a row with $\\lambda \\neq 0$\n      \\item addition of row i with row j\n    \\end{itemize}\n  \\item If there is only one solution the equivalent equation\n        ($A\\cdot x = 0$) can only be solved by $x = 0$.\n  \\item The system $Ax = b$ has a solution if \n        \\[\n            \\rank{\\left(A\\mid b\\right)} = \\rank{(A)}\n        \\]\n  \\item There is one unique solution if\n        \\[\n            \\rank{\\left(A\\mid b\\right)} = \\rank{(A)} = n\n        \\]\n  \\item There is one unique solution in a quadratic system if\n        $\\det{(A)} \\neq 0$.\n\\end{itemize}\n\n\\subsection{Matrix multiplication}\n\n\\io{Two matrices $A$ and $B$ where\n    number of $\\text{columns}(A) =$ number of $\\text{rows}(B)$\n}{One matrix $C$}\n\\wa{A * B}\n\\scriptref{5}\n%\n\\[\n    A \\cdot B = C\n\\] \\[\n    \\begin{pmatrix}\n        2 & 3 & 6 \\\\\n        4 & 5 & 3 \\\\\n    \\end{pmatrix}\n    \\cdot\n    \\begin{pmatrix}\n        1 & 3 \\\\\n        2 & 4 \\\\\n        7 & 8 \\\\\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n        50 & 66 \\\\\n        35 & 56 \\\\\n    \\end{pmatrix}\n\\]\n\n$50$ is the sum of $2\\cdot1 + 3\\cdot2 + 6\\cdot7$.\nMatrix multiplication is \\emph{not} commutative.\n\n\\subsection{Arithmetic matrix operations}\n\nMatrix additions or operations with a scalar happen element-wise.\n\n\\subsection{Set operations}\n\nSee figure~\\ref{fig:set_operations}. Copyright Wikipedia.\n%\n\\begin{figure}[h]\n  \\begin{center}\n    \\includegraphics[scale=0.5]{set_operations.pdf}\n    \\caption{\n        Basic set operations from left to right:\n        first row: Intersection ($\\cap$), union ($\\cup$).\n        second row: relative complement ($A \\setminus B$),\n            complement $U \\setminus A$ (U is universal set),\n            symmetric difference ($A \\Delta B = (A\\setminus B) \\cup (B\n            \\setminus A)$)\n    }\n    \\label{fig:set_operations}\n  \\end{center}\n\\end{figure}\n\n\\subsection{Transposed matrix}\n\n\\io{A matrix $A \\in M(m\\times n)$}{Matrix $A^T \\in M(n\\times m)$}\n\\wa{\\operatorname{Transpose}[A]}\n\\scriptref{6}\n%\n\\[\n    \\begin{pmatrix}\n        12 & 6 \\\\\n        2  & 3 \\\\\n        4  & 8 \\\\\n    \\end{pmatrix}^T\n    =\n    \\begin{pmatrix}\n        12 & 2 & 4 \\\\\n        6 & 3 & 8 \\\\\n    \\end{pmatrix}\n\\] \\[\n    (a_{ij})^T = (a_{ji})\n\\] \\[\n    (A + B)^T = A^T + B^T\n\\] \\[\n    (A\\cdot B)^T = B^T\\cdot A^T\n\\] \\[\n    A = A^T \\Leftrightarrow A\\text{ is a ''symmetrical matrix''}\n\\]\n\n\\subsection{Inverse matrix}\n\n\\io{$A \\in M(n\\times n), \\rank{A} = n$}{$C \\in M(n\\times n)$ if $A$ is regular}\n\\wa{A^{-1}}\n\\scriptref{16}\n\nIf $A$ has an inverse matrix, $A$ is called ''regular matrix'';\n''singular'' otherwise.\n%\n\\[\n  \\begin{array}{lrcl}\n    A\\text{ is regular}: & (A \\cdot B)^{-1} &=& B^{-1} \\cdot A^{-1} \\\\\n    A^{-1}\\text{ is regular}: & (A^{-1})^{-1} &=& A \\\\\n    A^T\\text{ is regular}: & (A^T)^{-1} &=& (A^{-1})^T \\\\\n  \\end{array}\n\\]\n%\n\\[\n    A \\in M(n\\times n) \\quad \\Rightarrow A\\cdot A^{-1} = I\n\\]\n\nThe inverse matrix of $A$ is $A^{-1}$. This matrix can be found by\nsolving the system:\n%\n\\[\n    (A, I) = \\left( \\begin{array}{ccc|cccc}\n        a_{11} & \\ldots & a_{1n} & 1 & 0 & \\ldots & 0 \\\\\n        a_{21} & \\ldots & a_{2n} & 0 & 1 & \\ldots & 0 \\\\\n        \\vdots & \\ddots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n        a_{n1} & \\ldots & a_{nn} & 0 & 0 & \\ldots & 1 \\\\\n    \\end{array} \\right)\n\\]\n\nOnce there is an identity matrix on the left side (by elementary row-wise\noperations), the inverse matrix can be read from the right side of the\nseparator.\n\n\\section{Decompositions}\n\n\\begin{description}\n  \\item[LUP decomposition]\n    $\n        PA = LU\n    $\n  \\item[LDU decomposition]\n    $\n        A = LDU\n    $\n  \\item[LU decomposition with full pivoting]\n    $\n        PAQ = LU\n    $\n\\end{description}\n\n\\subsection{LU decomposition}\n\n\\io{$A \\in M(m\\times n)$}{$L$ and $U$ with $A=LR$}\n\\wa{\\operatorname{LUDecomposition}[]}\n\\scriptref{18}\n%\n\\[\n    A = L \\cdot U\n    \\quad\\text{(without swapped rows)}\n\\]\n%\n\\begin{itemize}\n  \\item U is matrix A in triangular form\n  \\item L is a quadratic matrix with ones in the diagonal and below\n        negative factors created by row-wise operations performed before.\n\\end{itemize}\n\n\\[\n    A = P^T \\cdot L \\cdot R\n    \\quad\\text{(with swapped rows)}\n\\]\n%\n\\begin{itemize}\n  \\item U is matrix A in triangular form\n  \\item L is a quadratic matrix with ones in the diagonal and below\n        negative factors created by row-wise operations performed before.\n        While swapping rows, you have to swap all components of the rows\n        left to the right ones accordingly.\n  \\item Permutation matrix $P$ can be created by constructing an identity\n        matrix and swapping all rows you did with L. $P^T = P^{-1}$.\n\\end{itemize}\n\nA solution for $Ax = b$ can be found by applying\n\\[\n    L\\cdot y = b\n\\] \\[\n    R\\cdot x = y\n\\]\n\n\\subsection{QR decomposition}\n\n\\io{$A \\in M(m\\times n), m \\geq n$ and linear independent column vectors}\n    {$Q(m\\times n)$ and $R(n\\times n)$ with $A = QR$}\n\\wa{\\operatorname{QRDecomposition}[A]}\n\\scriptref{58}\n%\n\\begin{enumerate}\n  \\item Apply Gram-Schmidt-Process to column vectors\n  \\item $Q = \\{q_1, q_2, \\ldots\\}$\n  \\item $Q^T A = R \\Rightarrow R$\n\\end{enumerate}\n\\[\n    a\n\\]\n\n$Q$ is a matrix of orthonormal column vectors and $R$ is an invertible upper\ntriangular matrix.\n\n\\section{Determinant}\n\n\\io{$A \\in M(n\\times n)$}{a scalar}\n\\wa{\\operatorname{Det}[A]}\n\\scriptref{21}\n%\n\\[\n    n=1: \\det{A} = (a,) := a\n\\] \\[\n    n=2: \\det{A} := \\begin{vmatrix}\n        a_{11} & a_{12} \\\\\n        a_{21} & a_{22} \\\\\n    \\end{vmatrix} :=\n    a_{11}\\cdot a_{22} - a_{12}\\cdot a_{21}\n\\]\n\nFor $n=3$, it's recommended to evaluate the determinant by using\nthe rule of Sarrus.\nThis can be done by adding as many column duplicates as necessary to\nget valid diagonals (simply $2m - 1$). This structure allows you to simply\nread all necessary addition and subtraction operations\n(see figure~\\ref{fig:sarrus}).\n%\n\\begin{figure}[h]\n  \\begin{center}\n    \\includegraphics[width=150pt]{sarrus.pdf}\n    \\caption{Rule of sarrus}\n    \\label{fig:sarrus}\n  \\end{center}\n\\end{figure}\n\n\\[\n    \\det{A} = 1\\cdot 1\\cdot 1 + 2\\cdot 3\\cdot(-1) + (-1)\\cdot 0\\cdot 2\n\\] \\[\n    - [(-1) \\cdot 1 \\cdot (-1)] - [1\\cdot 3\\cdot 2] - [2\\cdot 0\\cdot 1]\n    = -12\n\\]\n%\nThe algebraic complement $A_{ij}'$ of $A$ is the determinant\nof the $(n-1)\\times(n-1)$ matrix created by removing row $i$\nand column $j$.\n%\n\\[\n    A = (a_{ij}) \\in M(n\\times n)\n\\] \\[\n    \\det{A} = \\sum_{j=1}^n (-1)^{1+j} a_{1j} A_{ij}'\n\\]\n%\n\\begin{itemize}\n  \\item $\\det{A^T} = \\det{A}$\n  \\item Entire row or column is zero $\\Rightarrow \\det{A} = 0$\n  \\item $A\\in M(n\\times n), \\lambda \\in \\mathbb{K}:\n        \\det{(\\lambda A)} = \\lambda^n \\det{A}$\n  \\item Two rows or columns are identical: $\\det{A} = 0$\n  \\item $\\det{(A\\cdot B)} = \\det{A}\\cdot\\det{B}$\n  \\item $\\det{(A + B)} \\neq \\det{A} + \\det{B}$\n\\end{itemize}\n%\n\\[\n    A \\text{ is regular}\n    \\Leftrightarrow\n    \\rank{A} = n\n    \\Leftrightarrow\n    \\det{A} \\neq 0\n\\]\n\n\\section{Vectors}\n\n\\wa{\\{\\{1\\},\\{2\\},\\{3\\}\\}}\n\\scriptref{24}\n%\n\\[\n    \\lambda, \\mu \\in \\mathbb{R}\n\\]\n%\n\\begin{itemize}\n  \\item Vector $\\vec{v}$ with $\\|\\vec{v}\\| = 0$ is called Null vector.\n  \\item Vector $\\vec{v}$ with $\\|\\vec{v}\\| = 1$ is called Unit vector.\n  \\item $\\vec{a} + 0 = \\vec{a}, \\quad \\vec{a} \\cdot 0 = 0$\n  \\item $\\vec{a} + \\vec{b} = \\vec{b} + \\vec{a}$\n  \\item $(\\vec{a} + \\vec{b}) + c = \\vec{a} + (\\vec{b} + c)$\n  \\item $\\|\\lambda\\cdot \\vec{a}\\| = |\\lambda| \\cdot \\|\\vec{a}\\|$\n  \\item $\\lambda\\cdot (\\vec{a} + b) = \\lambda\\cdot \\vec{a} + \\lambda\\cdot b$\n  \\item $(\\lambda + \\mu)\\cdot \\vec{a} = \\lambda\\cdot \\vec{a}\n        + \\mu\\cdot \\vec{a}$\n  \\item $\\|\\vec{a} + \\vec{b}\\| \\leq \\|\\vec{a}\\| + \\|\\vec{b}\\|$\n\\end{itemize}\n\n\\section{Norm (length) of a vector}\n%\n\\io{A vector $\\vec{v}$}{A scalar}\n\\wa{\\operatorname{Norm}[\\{2,3\\}]}\n%\n\\[\n    \\|\\vec{v}\\| = \\sqrt{\\sum_i v_i^2}\n\\]\n\n\\section{Products of vectors}\n\n\\subsection{Dot product (of vectors)}\n\n\\io{2 arbitrary vectors $\\vec{a}$ and $\\vec{b}$}{A scalar}\n\\wa{\\operatorname{vector}\\{1,2,3\\} . \\operatorname{vector}\\{2,3,4\\}}\n\\scriptref{26}\n\\dt{''Skalarprodukt''}\n%\n\\[\n    \\langle a, b\\rangle = \\|a\\|\\cdot\\|b\\| \\cdot \\cos{\\varphi}\n\\]\n%\n\\begin{itemize}\n  \\item $\\langle \\vec{a}, \\vec{b}\\rangle = \\langle \\vec{b}, \\vec{a}\\rangle$\n  \\item $\\langle \\vec{a}, \\vec{b}+\\vec{c}\\rangle = \\langle \\vec{b},\n        \\vec{a}\\rangle + \\langle \\vec{a},\\vec{c}\\rangle$\n  \\item $\\langle \\vec{a}, \\vec{b}\\rangle = 0 \\Leftrightarrow\n        \\vec{a}\\bot \\vec{b}$\n  \\item $\\langle \\vec{a}, \\vec{a}\\rangle = \\|\\vec{a}\\|^2$\n  \\item $\\vec{a} \\in \\mathbb{R}^3:\n        \\langle \\vec{a},\\vec{b} \\rangle = a_1b_1 + a_2b_2 + a_3b_3$\n  \\item $\\vec{a} \\in \\mathbb{R}^3:\n        \\|\\vec{a}\\| = \\sqrt{\\langle \\vec{a}, \\vec{a}\\rangle}\n        = \\sqrt{a_1^2 + a_2^2 + a_3^3}$\n\\end{itemize}\n\n\\subsection{Cross product}\n\n\\io{2 arbitrary vectors $\\vec{a}$ and $\\vec{b}$}{A scalar $c$}\n\\wa{\\{1,2,3\\} \\operatorname{cross} \\{2,3,4\\}}\n\\scriptref{27}\n\\dt{''Vektorprodukt''}\n%\n\\[\n    \\vec{a}, \\vec{b}\\in\\mathbb{R}^3:\n        \\quad c := \\vec{a}\\times \\vec{b}\n\\] \\[\n    c := \\|\\vec{a}\\| \\cdot \\|\\vec{b}\\| \\cdot \\sin{\\varphi}\n\\]\n%\nExample:\n%\n\\[\n    \\begin{pmatrix} 2 \\\\ 4 \\\\ 5 \\end{pmatrix}\n        \\times\n    \\begin{pmatrix} 3 \\\\ 6 \\\\ 1 \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n        4\\cdot1 - 5\\cdot6 \\\\\n        -(2\\cdot1 - 5\\cdot3) \\\\\n        2\\cdot6 - 4\\cdot3 \\\\\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n        -26 \\\\\n        13 \\\\\n        0 \\\\\n    \\end{pmatrix}\n\\]\n\n\\subsection{Triple product}\n\n\\io{3 arbitrary vectors $\\vec{a}$, $\\vec{b}$ and $\\vec{c}$}{A scalar}\n\\wa{\\{1,2,3\\} \\operatorname{cross} \\{2,3,4\\}}\n\\scriptref{27}\n\\dt{''Spatprodukt''}\n%\n\\[\n    \\vec{a}, \\vec{b}, \\vec{c} \\in \\mathbb{R}^n\n\\] \\[\n    |\\langle \\vec{a}\\times \\vec{b}, \\vec{c}\\rangle|\n        = \\|\\vec{a}\\times \\vec{b}\\| \\cdot \\|\\vec{c}\\| \\cdot\n        \\cos{\\angle(\\vec{a}\\times \\vec{b}, \\vec{c})}\n\\]\n\n\\section{Linear maps}\n\n\\begin{itemize}\n  \\item injective (injections can be undone)\n        \\[\n            \\forall x_1, x_2 \\in A: f(x_1) = f(x_2)\n                \\Leftrightarrow x_1 = x_2\n        \\]\n  \\item surjective (each element has a root):\n        \\[\n            \\forall y \\in B: \\exists x \\in A:\n                f(x) = y\n        \\]\n  \\item bijective = injective and surjective\n\\end{itemize}\n\n\\begin{figure}[h]\n  \\begin{center}\n    \\includegraphics[scale=0.5]{set_relations.pdf}\n    \\caption{Relations of sets (top to bottom)\n        1. injective\n        2. surjective\n        3. bijective\n    }\n    \\label{fig:set_relations}\n  \\end{center}\n\\end{figure}\n\n\\section{Vector spaces}\n\n$\\mathbb{K}$ is either $\\mathbb{R}$ or $\\mathbb{C}$.\n$\\mathbb{P}_m$ is vector space of polynomials with degree\n$m$ at maximum.\nA non-empty set $V$ is called vector space of $\\mathbb{K}$ if\n\n\\begin{enumerate}\n  \\item The sum of $a, b \\in V$ is defined and in $V$\n  \\item The product of $\\lambda \\in \\mathbb{K}$ and $a \\in V$\n        ($= \\lambda \\cdot a$) is defined and an element of $V$\n\\end{enumerate}\n\n\\begin{itemize}\n  \\item null vector: $0 \\in V, \\forall a \\in V: a + 0 = a$\n  \\item unit vector: $1 \\in V, \\forall a \\in V: a \\cdot 1 = a$\n  \\item negative vector: $(-a) \\in V, a + (-a) = 0$\n  \\item Is $V$ a vector space of $K$. A non-empty subspace $U \\subset V$\n        is called ''linear subspace of $V$'' if $\\lambda \\in K$ and\n        $a, b \\in U$ with\n        \\[\n            a + b \\in U,\n                \\quad \\lambda \\cdot a \\in U\n        \\]\n  \\item A line in $\\mathbb{R}^2$ and $\\mathbb{R}^3$ containing the origin\n        are linear subspaces.\n  \\item A plane in $\\mathbb{R}^3$ containing the origin is a linear\n        subspace of $\\mathbb{R}^3$.\n\\end{itemize}\n\n\\section{Linear independency}\n\nA non-empty subset $U \\subset V$ is called \\emph{linear independent} if\na finite number of vectors in $U$ are linear independent.\n%\n\\[\n    \\lambda_1, \\ldots, \\lambda_m \\in K,\n    \\quad a_1, \\ldots, a_m \\in V\n\\]\n\nA vector like\n%\n\\[\n    a = \\lambda_1 a_1 + \\ldots + \\lambda_m a_m\n\\]\n%\nis called linear combination of vectors ($a_1,\\ldots,a_m$). A linear\ncombination is \\emph{trivial} if $\\lambda_1 = \\ldots = \\lambda_m = 0$.\n\nVectors $a_1,\\ldots,a_m$ are linear dependent if there is a non-trivial\nlinear combination with\n%\n\\[\n    \\lambda_1 a_1 + \\ldots + \\lambda_m a_m = 0\n\\]\n%\nThese vectors are linear independent if \n%\n\\[\n    \\lambda_1 = 0, \\ldots, \\lambda_m = 0\n\\]\n\nIs $U \\subset V$ is a non-empty subspace. The set of all linear combinations\nof vectors of $U$ ($= L(U)$) is called the spanned space by $a_i \\in U$.\n\n\\[\n    L(U) = \\left\\{ a = \\sum_i \\lambda_i a_i,\n            \\lambda_i \\in K, a_i \\in U\\right\\}\n\\]\n\nIs $U = \\{a_1,\\ldots,a_m\\}$:\n\n\\[\n    L(U) = L(a_1, \\ldots, a_m)\n\\]\n\n\\section{Base of a vector space}\n\n$V$ is a vector space of $K$. A subspace $U \\subset V$ of linear\nindependent vectors is called basis of $V$ if $L(U) = V$.\nA vector space with a finite basis is called finite-dimensional.\n\nAll bases in a finite-dimensional vector space $V$ have the same number\nof vectors. This number is called dimension ($\\dim{V}$).\n\n\\begin{itemize}\n  \\item The base of $\\mathbb{R}^n$ is $\\set{e_1,\\ldots,e_n}$.\n        $\\dim{\\mathbb{R}^n} = n$\n  \\item The base of $\\mathbb{P}^m$ is $\\set{1, x,\\ldots,x^m}$.\n        $\\dim{\\mathbb{P}_m} = m + 1$\n\\end{itemize}\n\n$V$ is a vector space with basis $B = \\set{v_1,\\ldots,v_n}$. Each vector\n$v \\in V$ can be created by unique scalars $\\lambda_1,\\ldots,\\lambda_n$.\n%\n\\[\n    v = \\lambda_1 v_1 + \\ldots + \\lambda_n v_n\n\\]\n\n\\section{Diagonalisation}\n\n\\io{A diagonalisable matrix $A \\in M(n\\times n)$}\n   {diagonal matrix $D$ with $B = C^{-1}DC$}\n\\wa{\\operatorname{Diagonalize}[A]}\n\\scriptref{63}\n\nThe eigenvalues of a diagonal matrix are the diagonal elements.\n$A$ is diagonalisable if $A$ has $n$ linear independent eigenvectors.\n$C$ can be created by linear independent eigenvectors of $A$ as\ncolumns in $C$. This structure satisfies $D = C^{-1} AC$.\n\n\\section{Eigenvalues}\n\n\\io{$A \\in M(n\\times n)$}{a scalar $\\lambda$}\n\\wa{eigenvalues[A]}\n\\scriptref{59}\n%\n\\[\n    \\det{(A - \\lambda I)} = 0\n\\]\nwith $\\lambda$ as unknown variable. If you resolve the determinant,\nyou will get a polynomial you want to know the Zero of. This polynomial\nis called ''characteristic polynomial of $A$''. In a polynomial of\ndegree $n$ you will get $n$ solutions and therefore $n$ eigenvalues\n$\\lambda$.\nRow swapping is allowed.\n\n$\\lambda$ satisfies:\n\\[\n    A\\cdot v = \\lambda\\cdot v\n\\]\n\n\\section{Eigenvectors}\n\n\\io{$A \\in M(n\\times n)$ and eigenvalues $\\sigma_{1,\\ldots,n}$}\n   {$n$ linear independent vectors}\n\\wa{\\operatorname{eigenvectors}[A]}\n\\scriptref{59}\n\nIf $\\sigma_{i} \\neq \\sigma_j \\quad\\forall i, j \\in [1,n], i \\neq j$\nthen linear independence is given for eigenvectors for sure.\n\n\\[\n    (A - \\lambda_i I) \\cdot v_i = 0\n\\]\nSolve this equation system for $v_i$ which will be your eigenvector.\n\n\\section{Gram-Schmidt process}\n\n\\io{2 or more vectors}{as many vectors as given by input}\n\\wa{\\operatorname{Orthogonalize}[\\{A,B,C\\}]}\n\\scriptref{56}\n%\n\\[\n    w_1 = \\frac{1}{\\| v_1\\|}\\cdot v_1\n\\] \\[\n    w_i = \\frac{1}{\\| u_i\\|}\\cdot u_i, \\quad i = 2,\\ldots,n\n\\] \\[\n    u_i = v_i - \\sum_{k=1}^{i-1} \\langle v_i, w_k\\rangle w_k, \\quad i = 2,\\ldots,n\n\\]\n\n\\section{Pseudoinverse}\n\n\\io{Matrix $A \\in M(m\\times n)$}{$A^{\\#} \\in M(n\\times m)$}\n\\wa{\\operatorname{PseudoInverse}[A]}\n\\scriptref{92}\n\\textbf{More precise name:} Moore-Penrose-Inverse\n\n\\begin{enumerate}\n    \\item Evaluate $A^T\\cdot A$\n    \\item Evaluate $(A^T\\cdot A)^{-1}$\n    \\item Evaluate $(A^T\\cdot A)^{-1} \\cdot A^T = A^\\#$\n\\end{enumerate}\n%\nProbably the evaluation of the inverse is impossible. In this case,\nthe pseudoinverse might be possible to evaluate using the singular\nvalue decomposition (SVD):\n\\[\n    A = U\\Sigma V^T\n        \\Rightarrow A^\\# = V\\Sigma^\\# U^T\n\\]\n%\n$\\Sigma^\\#$ can be created by inverting all singular values\nin D: $\\sigma_1^{-1}$, $\\sigma_2^{-1}$, $\\sigma_i^{-1}$.\n\n\\section{Singular value decomposition}\n\n\\io{Matrix $A \\in M(n\\times n)$}{Matrices $U$, $\\Sigma$, $V$\n    where $A = U\\Sigma V^T$}\n\\wa{\\operatorname{SVD}[A]}\n\\scriptref{68}\n\\dt{Singulärwertzerlegung}\n%\n\\[\n    A(m\\times n) = U(m\\times m) \\cdot \\Sigma(m\\times n)\n        \\cdot V(n\\times n)^T\n\\]\nIf $A$ is positiv definit and symmetrical, the procedure is the same like\northogonal diagonalisation.\n%\n\\begin{enumerate}\n    \\item Evaluate $A^T\\cdot A$\n    \\item Evaluate die eigenvalues of\n          $A^T\\cdot A: \\lambda_1, \\lambda_2, \\ldots$\n    \\item Sort the eigenvalues by value\n    \\item The singular values $\\sigma_1, \\sigma_2, \\ldots$\n          are the squareroots of the eigenvalues $\\sqrt{\\lambda_1},\n          \\sqrt{\\lambda_2}, \\ldots$\n    \\item Evaluate the eigenvectors $v_1, v_2, \\ldots$\n    \\item Normalize the eigenvectors ($\\leftarrow$ length is 1)\n    \\item Combine the eigenvectors as column vectors $\\{v_1, v_2, \\ldots\\} = V$\n    \\item Create a $n\\times n$ matrix and insert the $\\sigma_i$ as\n          diagonals:\n          \\[\n            \\Sigma = \n            \\begin{pmatrix}\n                \\sigma_1 & 0 & 0 \\\\\n                0 & \\sigma_2 & 0 \\\\\n                0 & \\vdots   & 0 \\\\\n                0 & 0 & \\sigma_n \\\\\n            \\end{pmatrix}\n          \\]\n    \\item Evaluate $u_i = \\frac{1}{\\sigma_i} \\cdot A \\cdot v_i$ or find\n          other orthonormal vectors\n    \\item Combine the vectors as column vectors $\\{u_1, u_2, \\ldots\\} = U$\n    \\item Evaluate $V^T$\n\\end{enumerate}\n%\n$U$ and $V$ are not unique.\n\n\\section{Gauss-Seidel Iteration}\n\n\\io{Linear equation system $(A\\mid b)$ and start vector $x_0$}\n   {A vector close to the solution of the equation system}\n\\scriptref{87}\n\nIf no start vector is given, $\\begin{pmatrix} 1 \\\\ 0 \\\\ 1 \\end{pmatrix}$ is\nprefered.\n\nThe Gauss-Seidel-Iteration converges if\n\\begin{itemize}\n  \\item either $A$ is positive definit\n  \\item or for each eigenvector $\\lambda$ of $S^{-1} T$\n        it states $|\\lambda| < 1$\n\\end{itemize}\n\n\\section{Spectral radius}\n\n\\io{$A$ of an iteration algorithm}{a scalar}\n\\scriptref{86}\n\nIn the context of iteration algorithms, $A$ is typically\n$S^{-1}T$.\n%\n\\[\n    \\rho(A) := \\max_i{|\\lambda_i|}\n\\]\n%\nwith $\\lambda_i$ as eigenvalue of $A$.\n\n\\section{Condition number}\n\n\\io{regular matrix $A \\in M(n\\times n)$}{a scalar}\n%\\wa{N/A}\n\\scriptref{82}\n\n\\[\n    \\operatorname{cond}(A) := \\|A^{-1}\\| \\cdot \\|A\\|\n\\] \\[\n    \\|A\\|_\\infty = \\max{\\left\\{\n        \\sum_{j=1}^n |a_{ij}|  \\mid i = 1,\\ldots,n\n    \\right\\}}\n\\]\n\n\\section{Interpolation and Approximation}\n\n\\begin{figure}[h]\n  \\begin{center}\n    \\includegraphics[scale=0.4]{interpolation.png}\n    \\caption{Interpolation}\n    \\label{fig:interpolation}\n  \\end{center}\n\\end{figure}\n\\begin{figure}[h]\n  \\begin{center}\n    \\includegraphics[scale=0.4]{approximation.png}\n    \\caption{Approximation}\n    \\label{fig:approximation}\n  \\end{center}\n\\end{figure}\n\n\\section{Cubic Spline Interpolation}\n\n\\io{List of $\\{x,y\\}$ pairs}{A polynomial}\n\\wa{\\operatorname{BSplineCurve}[pts, SplineDegree\\rightarrow3]}\n\\scriptref{115}\n\n\\textbf{Is S(x) a cubic spline interpolation?} \\\\\n\\begin{itemize}\n  \\item The function has to be continous. So all functions must stop\n        at the same value at the borders.\n  \\item $f_i'(x_i) = f_{i+1}'(x_i)$ must be satisfied for all $i$\n\\end{itemize}\n\n\\section{Glossary}\n\n\\begin{description}\n  \\item[identity matrix] $a_{ii} := 1, 0$ otherwise\n  \\item[positiv definit] $A$ is positiv definit if \\emph{one} of\n    the following requirements is satisfied:\n    \\begin{equation}\n        x^T A x > 0 \\quad \\forall x \\in \\mathbb{R}^n, x\\neq 0\n    \\end{equation} \\begin{equation}\n        \\lambda_i > 0 \\quad \\forall \\lambda_i \\text{ of } A\n    \\end{equation} \\begin{equation}\n        m > 0 \\quad \\forall m \\text{ as minor of } A\n    \\end{equation} \\begin{equation}\n        d_i > 0 \\quad \\forall d \\in A_t\n    \\end{equation}\n    with $d$ as the pivot elements of the triangular form\n    (\\emph{without} row swapping) of $A$.\n  \\item[regular matrix] $M(m\\times n)$ has an inverse matrix\n  \\item[singular matrix] $M(m\\times n)$ has no inverse matrix\n  \\item[similar matrix] $A, B \\in M(n\\times n)$ are similar\n        if $C \\in M(n\\times n)$ in $B = C^{-1} AC$ exists;\n        $A$ and $B$ have the same characteristic polynomial and\n        the same eigenvalues\n  \\item[spectral radius] $\\rho(S^{-1}T) := \\max_i{|\\lambda_i|}$\n  \\item[strongly diagonal dominant] \\hfill{}\n    \\[\n        |a_{ii}| > \\sum_{\\substack{j=1 \\\\ j\\neq i}}^n\n        |a_{ij}| \\quad \\forall i = 1,\\ldots,n\n    \\]\n  \\item[symmetrical matrix]\n    $a_{ij} = a_{ji} \\quad\\forall a \\in M(m\\times n)$\n  \\item[permutation] An identity matrix where the same\n    elementary row operations of the Gaussian algorithm\n    have been applied on\n  \\item[triangular form]\n    %elements below or above diagonal line are all 0\n    $a_{ij} = 0 \\quad\\forall i > j$ or $\\forall i < j$\n  \\item[quadratic matrix] $A \\in M(n\\times m): n = m$\n\\end{description}\n\n\\end{document}\n", "meta": {"hexsha": "80774d447139172fbd56164305f011ed163a87b8", "size": 24971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pub/nrla_summary.tex", "max_stars_repo_name": "meisterluk/tug_lp", "max_stars_repo_head_hexsha": "eaf7e0a9bfaa91400248f7231c6891531ee71275", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pub/nrla_summary.tex", "max_issues_repo_name": "meisterluk/tug_lp", "max_issues_repo_head_hexsha": "eaf7e0a9bfaa91400248f7231c6891531ee71275", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pub/nrla_summary.tex", "max_forks_repo_name": "meisterluk/tug_lp", "max_forks_repo_head_hexsha": "eaf7e0a9bfaa91400248f7231c6891531ee71275", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6840354767, "max_line_length": 87, "alphanum_fraction": 0.6014176445, "num_tokens": 8849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8840392725805823, "lm_q1q2_score": 0.6823399643757079}}
{"text": "\\newpage\n\\section{Some popular CNN models}\\label{sec:CNNs}\nIn this section, we will use these convolutional operations\nintroduced above to give a brief description of some classic convolutional\nneural network (CNN) models.\nFirstly, CNNs are actually a class of special DNN models. Let us recall the \nDNN structure as:\n\\begin{equation}\n\\begin{cases}\nf^0(x) &= x \\\\\nf^{\\ell}(x) &=  \\sigma(\\theta^\\ell (f^{\\ell-1})) \\quad \\ell = 1:L \\\\\nf(x) &= W^L f^{L} + b^L \\\\\n\\end{cases},\n\\end{equation}\nwhere $f^0$ is the original image, $\\theta^\\ell$ is a linear mapping and $\\sigma$ is the activation function\n\\begin{equation}\n\\theta^\\ell (f^{\\ell-1}) = W^\\ell f^{\\ell-1}(x)  + b^\\ell.\n\\end{equation}\nThe key features of CNNs are\n\\begin{enumerate}\n\t\\item Replace the general\nlinear mapping $\\theta^\\ell$ by convolution operations with multi-channel.\n\\item Use multi-resolution of images as shown in the next diagram.\n\\end{enumerate}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=.85\\textwidth]{figures/multiresolution-CNN}\n\\end{figure}\n\nThen we will introduce some classical architectures in convolution neural \nnetworks.\n\n\n\\subsection{LeNet-5, AlexNet and VGG}\nLeNet-5 \\cite{lecun1998gradient} is aconvolutional network designed for handwritten and machine-printed character recognition.  AlexNet \\cite{krizhevsky2012imagenet} showed, for the first time, that the features obtained by learning can transcend manually-designed features, breaking the previous paradigm in computer vision. While previous derivatives of AlexNet focused on smaller window sizes and strides in the first convolutional layer, VGG \\cite{simonyan2014very} addresses another very important aspect of CNNs: depth.\n\nThe  LeNet-5, AlexNet and VGG\ncan be written as:\n\\begin{breakablealgorithm}\n\t\\footnotesize\n\t\\caption{$ h = \\text{Classic CNN}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:presnet}\n\t\\begin{algorithmic}[1]\n\t\t\\State Initialization:  $f^{1,0} = f_{\\rm in}(f)$.\n\t\t%\t\t\\State Initialization $u^{1,0}$\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State Basic Block:\n\t\t\\begin{equation}\\label{ori-ResNet}\n\t\tf^{\\ell,i} = \\sigma \\left( \\theta^{\\ell,i} \\ast f^{\\ell,i-1}\\right)\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t%\t\t\\State Note: $ u^\\ell= u^{\\ell,\\nu_\\ell} $\n\t\t\\State Pooling(Restriction):\n\t\t\\begin{equation}\n\t\t\\label{ori-ResNet0}\n\t\tf^{\\ell+1,0} = R_\\ell^{\\ell+1} \\ast_2 f^{\\ell, \\nu_\\ell} \n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Final average pooling layer:\n\t\t$h =  R_{\\rm ave}( f^{L,\\nu_\\ell})$.\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nHere $R_\\ell^{\\ell+1} \\ast_2$ represents for the pooling operation to \nsub-sampling these tensors into coarse spatial level (lower resolution).\nHere we use $R_\\ell^{\\ell+1} \\ast_2$ to stand for the pooling operation. \nIn general we can also have\n\\begin{itemize}\n\t\\item average pooling: fixed kernels such as \n\t\\begin{equation}\\label{key}\n\tR_\\ell^{\\ell+1}  = \\frac{1}{9} \n\t\\begin{pmatrix}\n\t1 & 1 & 1 \\\\\n\t1 & 1 & 1 \\\\\n\t1 & 1 & 1\n\t\\end{pmatrix}\n\t\\end{equation}\n\t\\item Max pooling $R_{\\rm max}$ as discussed before.\n\\end{itemize}\n\nIn these classic CNN models, they still need some \nextra fully connected layers after $h$ as the output of CNNs. \nAfter few layers of fully connected layers, the model is completed by following\na multi-class logistic regression model.\n\nThese fully connected layers are removed in ResNet to be described below.\n\n\n\\subsection{ResNet}\nThe original ResNet developed in~\\cite{he2016deep} is one\nof the most popular CNN architectures in image classification problems.\n\\begin{breakablealgorithm}\n\t\\footnotesize\n\t\\caption{$ h = \\text{ResNet}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:resnet}\n\t\\begin{algorithmic}[1]\n\t\t\\State Initialization:  $r^{1,0} = f_{\\rm in}(f)$.\n\t\t%\t\t\\State Initialization $u^{1,0}$\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State Basic Block:\n\t\t\\begin{equation}\\label{ori-ResNet}\n\t\t\tr^{\\ell,i} = \\sigma\\left(r^{\\ell, i-1} + A^{\\ell,i} \\ast  \\sigma \\circ B^{\\ell,i}\\ast r^{\\ell,i-1}\\right).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t%\t\t\\State Note: $ u^\\ell= u^{\\ell,\\nu_\\ell} $\n\t\t\\State Pooling(Restriction):\n\t\t\\begin{equation}\n\t\t\t\\label{ori-ResNet0}\n\t\t\tr^{\\ell+1,0} = \\sigma \\left( R_\\ell^{\\ell+1} \\ast_2  r^{\\ell, \\nu_\\ell} + A^{\\ell+1,0} \\circ \\sigma \\circ B^{\\ell+1,0} \\ast_2 r^{\\ell, \\nu_\\ell} \\right).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Final average pooling layer:\n\t\t$h =  R_{\\rm ave}( r^{L,\\nu_\\ell})$.\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nHere $f_{\\rm in}(\\cdot)$ may depend on different data set and problems \nsuch as $f_{\\rm in}(f) = \\sigma \\circ \\theta^0 \\ast f $ for CIFAR~\\cite{krizhevsky2009learning} and\n$f_{\\rm in}(f) = R_{\\rm max}\\circ \\sigma \\circ \\theta^0 \\ast  f$ for ImageNet~\\cite{deng2009imagenet} as in~\\cite{he2016identity}.\nIn addition $r^{\\ell,i} =   r^{\\ell, i-1} +  A^{\\ell,i} \\ast  \\sigma \\circ B^{\\ell,i} \\ast \\sigma (r^{i-1})$ is often called the basic ResNet block.\nHere, $A^{\\ell,i}$ with $i\\ge0$ and $B^{\\ell,i}$ with $i\\ge1$ are general $3\\times3$ convolutions with zero padding and stride 1.\nIn pooling block, $\\ast _2$ means convolution with stride 2 and $B^{\\ell,0}$ is taken as the $3\\times3$ kernel with same output channel dimension of $R_\\ell^{\\ell+1}$\nwhich is taken as $1\\times1$ kernel and called as projection operator in \\cite{he2016identity}. \nDuring two consecutive pooling blocks, index $\\ell$ means the fixed resolution or we $\\ell$-th grid level as in multigrid methods.\nFinally, $R_{\\rm ave}$ ($R_{\\rm max}$) means average (max) pooling with different strides which is also dependent on datasets and problems.\n\n\n\\subsection{pre-act ResNet} \nThe pre-act ResNet~\\cite{he2016identity} shares a similar\nstructure with ResNet. \n\\begin{breakablealgorithm}\n\t\\footnotesize\n\t\\caption{$ h = \\text{pre-act ResNet}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:presnet}\n\t\\begin{algorithmic}[1]\n\t\t\\State Initialization:  $r^{1,0} = f_{\\rm in}(f)$.\n\t\t%\t\t\\State Initialization $u^{1,0}$\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State Basic Block:\n\t\t\\begin{equation}\\label{ori-ResNet}\n\t\t\tr^{\\ell,i} = r^{\\ell, i-1} + A^{\\ell,i} \\ast  \\sigma \\circ B^{\\ell,i}\\ast   \\sigma (r^{\\ell,i-1}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t%\t\t\\State Note: $ u^\\ell= u^{\\ell,\\nu_\\ell} $\n\t\t\\State Pooling(Restriction):\n\t\t\\begin{equation}\n\t\t\t\\label{ori-ResNet0}\n\t\t\tr^{\\ell+1,0} = R_\\ell^{\\ell+1} \\ast_2  r^{\\ell, \\nu_\\ell} + A^{\\ell+1,0} \\circ \\sigma \\circ B^{\\ell+1,0} \\ast_2  \\sigma (r^{\\ell, \\nu_\\ell} ).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Final average pooling layer:\n\t\t$h =  R_{\\rm ave}( r^{L,\\nu_\\ell})$.\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nHere pre-act ResNet share almost the same setup with ResNet.\n\n\nThe only difference between ResNet and pre-act ResNet can be viewed as \nputting a $\\sigma$ in different places. \nThe connection of those three models are often shown with next diagrams:\n\\begin{figure}[!htb]\n\t\\begin{center}\n\t\t\\includegraphics[width=.6\\textwidth, height=.13\\textheight]{CNN_ResNet} \n\t\\end{center}\n\t\\caption{Comparison of CNN Structures}\n\\end{figure}\n\nWithout loss of generality, we extract the key \nfeedforward steps on the same grid in different CNN models as follows.\n\\begin{description}\n\t\\item[Classic CNN] \n\t\\begin{equation}\\label{eq:cCNN}\n\tf^{\\ell,i} = \\xi^i \\circ \\sigma (f^{\\ell,i-1}) \\quad \\text{or} \\quad f^{\\ell,i} = \\sigma \\circ \\xi^{i} (f^{\\ell,i-1}) .\n\t\\end{equation}\n\t\\item[ResNet] \n\t\\begin{equation}\\label{eq:ResNet}\n\tr^{\\ell,i} = \\sigma( r^{\\ell,i-1} + A^{\\ell,i} \\circ \\sigma \\circ B^{\\ell,i}(r^{\\ell,i-1})).\n\t\\end{equation}\n\t\\item[pre-act ResNet]\n\t\\begin{equation}\\label{eq:pre-act ResNet}\n\tr^{\\ell,i} = r^{\\ell,i-1} + A^{\\ell,i} \\circ \\sigma \\circ B^{\\ell,i}\\circ \\sigma(r^{\\ell,i-1}).\n\t\\end{equation}\n\\end{description} ", "meta": {"hexsha": "408d14d46144f7ccd2cca22ea59187cef45a7488", "size": 7637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ClassicCNNs.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/ClassicCNNs.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/ClassicCNNs.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.2810810811, "max_line_length": 525, "alphanum_fraction": 0.6849548252, "num_tokens": 2723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6823315215598933}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\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    \n\nLet $G:= (V, E)$ be a bridgless undirected cubic planar graph.\n\\begin{lemma}\n    If $G$ is cubic, then $|V|$ is even.\n\\end{lemma}\n\n\\begin{proof}\n    $2|E| = \\sum_{v \\in V} d(v) = 3|V| $ \\\\\n    As $|E|$ must be integer, it follows that we must be able o divide $|V|$ by 2.\n\\end{proof}\n\n\\begin{lemma}\n    If $G$ is cubic, planar and bridgless, then $G$ has a chromatic index of 3. \n\\end{lemma}\n\n\nConsider the graph $G':= (V', E')$, obtained from $G$ by removing an edge $xy$, adding a vertex $z$, and adding edges $xz$ and $yz$. \n\\begin{lemma}\n    $G'$ has a chromatic index of 4.\n\\end{lemma}\n\n\\begin{proof}\n    As $\\Delta(G') = 3$; we prove the $\\chi'(G') \\le 4$ thanks to Vizing's theorem.\\\\\n    Now consider a matching $M$ of the edges of $E'$. as $|V'| = |V|+1$ is odd, each matching can cover at most $|V|$ vertices,\n    so it can at most contains $\\tfrac{|V|}{2}$ edges. However, we have $|E'| = \\tfrac{3}{2} |V| + 1$ edges, so we must have $\\chi'(G') \\ge 4$.\n\\end{proof}\n\n\n\n\n\n\n\\newpage\n\\section{On-a-grid graphs}\n\nWe know that the concept of directions in a unit-square graphs has proved quite useful. For instance, we know that for $C_4$; all the squares must have their\nneighbours in adjacent directions; for a $C_5$; exactly one square has it's neighboursin opposite directions, etc. \\\\\nWe propose here a new tool to these particular graphs. It will prove rather useful later to prove a large number of statements. \n\n\\begin{definition} [On-a-grid]\n    A graph $G$ is said on-a-grid if it is represented such that $\\forall e_1, e_2 \\in E(G)$, $e_1$ and $e_2$ are either parallels or perpendicular, and no edge is represented including an other.\n    Moreover, the length of all the edges is a integer. \n\\end{definition}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.2]{tex_images/on_a_grid_g1.png}\n    \\caption{The graph $G$ is on-a-grid.}\n\\end{figure}\n\n\\begin{remark}\n    There is no ambiguity or \"hidden\" edges; so, for instance, only $10$ edges in Fig. 1.\n\\end{remark}\n\n\\begin{lemma}\n    All on-a-grid graphs are triangle-free.\n\\end{lemma}\n\n\\begin{proof}\n    A non-degenerate triangle can't have only parallel or perpendicular edges.\n\\end{proof}\n\nThere exists two special lines in the representation of a on-a-grid graph: those such that every edge is parallel to one of them.\nThese are called the \\textit{directions of the grid}.\nWe will only consider the case where they are represented with a $\\tfrac{\\pi}{4}$ angle with regard to the usual cartesian system (see Fig.1) as it will be more convenient for the future applications.\n\n\\begin{definition}[RL, LR lines]\n    We refer to the \\textit{directions of the grid} as LR and RL: LR is the one going from down Left to up Right; RL is the other one. \n\\end{definition}\n\nRL and LR lines will be useful later to consider \"layers\" of vertices to generate an algorithm to pass from a representation to another\n% OR just from squares to on-a-grid, who knows.\n\n\\begin{lemma}\n    If $G$ is on-a-grid, $\\Delta(G) \\le 4$.\n\\end{lemma}\n\n\\begin{proof}\n    Trivial.\n    %Suppose by contradiction that $G$ is on a grid with a vertex $v$ such that $d(v) \\ge 5$. \\\\\n    %Call $e_1, .. e_5$ five distinct edges of $G$ containing $v$. \\\\\n    %As every edge is parallel to one of RL or LR it means at least three of the $e_1, .. e_5$ are parallel; suppose it is $e_1, e_2$ and $e_3$.\\\\\n\\end{proof}\n\n\\begin{definition}[DL, DR, UL, UR directions]\n    Let $xy$ be an edge of $G$ we say that $xy$ is in the UR (Up-Right) direction if: $xy$ is parallel to LR and $y$ is higher on the plane than $x$.\\\\\n    We have analogous definitions for UL, DR and  DL. \n\\end{definition}\n\n\\begin{remark}\n    if $xy$ is in UR direction, then $yx$ is in DL direction.\n\\end{remark}\n\n\\begin{definition}[upper vertex, upper edge]\n    We say that $y$ is a vertex upper than $x$ if there exists a path $xv_1-v_ky$ possibly trivial such that every edge of the path is in direction UL or UR. \n    An edge is upper than a vertex $v$ if it contains a vertex upper than $v$.\n\\end{definition}\n\nWe have analogous definition for lower, righter and lefter.\n\n\n\n\\subsection{From square corner intersection graphs to on-a-grid representation }\n\n\\begin{definition}[$P(UR)$]\n    Let $P$ be a path in $G$. $P(UR)$ is the number of UR connection in $P$.\n\\end{definition}\n\n\\begin{definition}[on the same RL diagonal] %remark: it could use a lower/higher version. Think of a last layer\n    Let $G$ be an intersection graph of a corner square family. Let $x, y$ be two squares of $G$. $x$ and $y$ are said to be on the same RL diagonal\n    if the smallest path $P$ from $x$ to $y$ using only UL, UR and DL connections have $P(UR) = P(DL)$. \n\\end{definition}\n\nSee on the Fig. 2 for instance: A, D and F are on the same RL diagonal. Although there exist a path from F to D in 3 UR and 1 DL connection, the smallest one is the trivial FD. \\\\\nWe can observe that, if this definition is clear when the squares share a UL connection, it is also true when they are disjoint; in this example, I and G are on the same RL diagonal.\\\\\nWe have an analogous definition for squares on the same LR diagonal; here: F, E, I, H for instance.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.3]{tex_images/same_diagonals.png}\n    \\caption{Example of corner intersection graph.}\n\\end{figure}\n\n\\begin{definition}[number of diagonals]\n    The number of RL diagonals of a square corner intersection graph $G$ is the number regroupements you must make of squares that are on the same RL diagonal in order to take in account every square.\n\n\\end{definition}\n\nFor instance in Fig. 2 we have 4 RL diagonals, the regroupements being: $\\{(A, D, F); (E); (I, G); (H) \\}$.\\\\\nWe have an analogous definition for the number of LR diagonals; here, there are only 3.\n\n\\begin{definition}[order on diagonals]\n    Let two RL distinct diagonals $D := \\{d_1, d_2, ... d_k \\} $ and $E:= \\{e_1, ... e_l\\}$.   \\\\\n    We say that $D<E$ if:  \n    $$\\forall d_i, e_j, d_{RL}(d_i, e_j) \\ge 1$$.\n\\end{definition}\nThis will allow us later to choose in which order we will treat the diagonals.\n\n\\begin{remark}\n    This is not an obvious way \n\\end{remark}\n\n\\begin{definition}[Layer difference]\n    Let $x,y$ be two squares on the same RL diagonal. We call $d_{LR}(x,y)$ the LR-layer difference of $x$ and $y$. \n    $$ d_{LR}(x,y) = max_P(P(UR)-P(DL))$$ \n    where $P$ is a path from $x$ to $y$.     \n\\end{definition}\n\n\\begin{remark}\n    If $x$ and $y$ are neighbours with a UL connection, then $d_{LR}(x,y) = 0$ and $d_{RL}(x,y) = 1$.\n\\end{remark}\n\n\\begin{lemma}\n    If $x$ and $y$ are on the same RL diagonal (resp. LR) and $y$ and $z$ are on the same RL diagonal (resp. LR), then $x$ and $z$ are on the same RL (resp. LR) diagonal.\n\\end{lemma}\n\n\\begin{proof}\n    Call $P_{xy}$ and $P_{yz}$ the path confirming the definitions. \\\\\n    Then $P := P_{xy}P_{yz}$ confirms the latter. \n\\end{proof}\n\n\n%% THE LEMMA IS TO FINISH\n\\begin{lemma}\n    Let $x_1, y_1, x_2, y_2$ be four squares on the same LR diagonal, with $x_i$ intersecting $y_i$ in UL direction, and $d_{RL}(x1, x2) >0$. Then: $$d_{RL}(x_1, y_1) \\ge d_{RL}(x_1, x_2),$$\n    with the equality being reached when $x_2 = y_1$.\n\\end{lemma}\n\n\\begin{remark}\n    This simply means that placing vertex on a line according to $d_{RL}(x, .)$ is enough to verify that no edge is implicit.\n\\end{remark}\n\n\\begin{proof}\n    When $x_2 = y_1$ the result is trivial.\\\\\n    Observe that $d_{RL}(y_1, x_2) >= 1$.\n    Otherwise, \n\\end{proof}\n\n\\begin{theorem}\n    Every corner square graph can be viewed as a on-gird graph.\n\\end{theorem}\n\n%remark: this do not take in account yet the fact some diagonal may have no vertex neighbouring a previous one. \n\n\\begin{proof}\n    The proof is done by presenting an algorithm that genereates the on-a-grid graph.\\\\\n    Start by choosing a square $s_1$. Place it on the plane and trace a RL line. Now place all the squares that are on the same RL diagonal; and place them in order to respect the distance $d_LR(x,y)$.\n    Finaly, trace all the edges that are supposed to appear. Thanks to lemma 1.4, we know that none of the edges we trace at this step is intersecting an other. \\\\\n    Then we move to the next RL diagonal. We start by placing one square that have a neighbour in the previous diagonal. $s_2$. Then, we can geoemtrically determine the positions of all the squares that have a neighbour both on this diagonal and in the previous. \n    For those which do not have any other neighbour already in place, we place them according to the distance previously used. \\\\\n    In the case where, when placing a new diagonal, there is not any vertex that have a neighbour in a previously placed diagonal, then we move to the next diagonal and we will place this one when at least a neighbour is available. \n\n\\end{proof}\n\nLet's apply it with the graph shown in Fig. 3:\nWe can identify 5 RL layers: $\\{(A, B, C), (G, F, D), (I, H, E),(J), (K)\\}$.\\\\\nStart by placing B. as A and C are on the same RL diagonal, we place them at the same time. As $d_LR(B,C) = 1$, C is placed at a distance of one unit from B.\nAs $d_LR(A, B) = 2$ (through the path BDFGA), A is placed at a distance of 2 units from B.\\\\\n\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.3]{tex_images/example_algorithm.png}  \n    \\caption{Example of application of the algorithm.}  \n\\end{figure}\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{What about the other way?}\n\n\n\\begin{theorem}\n    Every on-a-grid graph can be drawn as an intersection graph of squares. \n\\end{theorem}\n\n\n\n\\begin{proof}\n    Organize the squares by their order on RL parallel line; then from bottom to top. We denote them $v_{i,j}$. $i$ denotes on on which RL-parallel line they are;\n    $j$ denotes the order (bottom-top) on the $i$-th line. \\\\\n    The proof consists in an algorithm explaining how to construct the squares. It is done by considering the RL lines one by one. \n    \n    Start by representing all the squares on the lowest RL-line. They have a default size of 2; when two vertex are neighbours, merge the corners and centers.\n    When two vertices are not neighbours, merge their corners (Fig. 2). \n    \\begin{figure}[h]\n        \\centering\n        \\includegraphics[scale=0.2]{tex_images/on_a_grid_2.png}\n        \\includegraphics[scale=0.17]{tex_images/on_a_grid_3.png}\n        \\caption{Lowest RL diagonal treatment.}\n    \\end{figure}\n\n    Now consider the next RL line. We can observe 4 different cases:\n    \\begin{itemize}\n        \\item a: The lines are identical.\n        \\item b: Some vertex of the previous have no neighbours here.\n        \\item c: Some vertex on the new line have no neighbours with the previous line.\n        \\item d: Mixes from b and c.\n    \\end{itemize}\n\n    %n case of a: simply copy what has been done on the previous line and merge corners with centers accordingly.\\\\\n    %In case of c: \\\\\n\n\n\n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "6c2495914af331001f7ffdcf9e6b37d269e4f596", "size": 11253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/cubics_1/cubics_1.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/cubics_1/cubics_1.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/cubics_1/cubics_1.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": 41.3713235294, "max_line_length": 263, "alphanum_fraction": 0.6951923931, "num_tokens": 3300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.6822971380841849}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{The circle}\n\nWe have seen inductive types, in which we describe a type by its constructors and an induction principle that allows us to construct sections of dependent types. Inductive types are freely generated by their constructors, which describe how we can construct their terms. \n\nHowever, many familiar constructions in algebra involve the construction of algebras by generators and relations. \nFor example, the free abelian group with two generators is described as the group with generators $x$ and $y$, and the relation $xy=yx$. \n\nIn this chapter we introduce higher inductive types, where we follow a similar idea: to allow in the specification of inductive types not only \\emph{point constructors}, but also \\emph{path constructors} that give us relations between the point constructors. \nThe ideas behind the definition of higher inductive types are introduced by studying the simplest non-trivial example: the \\emph{circle}.\n\n\\subsection{The induction principle of the circle}\nThe \\emph{circle}\\index{circle} is defined as a higher inductive type\\index{higher inductive type} $\\sphere{1}$\\index{S 1@{$\\sphere{1}$}} that comes equipped with\\index{base@{$\\base$}}\\index{loop@{$\\lloop$}}\n\\begin{align*}\n\\base & : \\sphere{1} \\\\\n\\lloop & : \\id{\\base}{\\base}.\n\\end{align*}\nJust like for ordinary inductive types, the induction principle for higher inductive types provides us with a way of constructing sections of dependent types. However, we need to take the \\emph{path constructor}\\index{path constructor} $\\lloop$ into account in the induction principle. \n\nBy applying a section $f:\\prd{t:\\sphere{1}}P(t)$ to the base point of the circle, we obtain a term $f(\\base):P(\\base)$. Moreover, using the dependent action on paths\\index{dependent action on paths} of $f$ of \\cref{defn:apd} we also obtain for any dependent function $f:\\prd{t:\\sphere{1}}P(t)$ a path\n\\begin{align*}\n\\apd{f}{\\lloop} & : \\id{\\mathsf{tr}_P(\\lloop,f(\\base))}{f(\\base)}\n\\end{align*}\nin the fiber $P(\\base)$.\n\n\\begin{defn}\nLet $P$ be a type family over the circle. The \\define{dependent action on generators}\\index{dependent action on generators!for the circle|textbf} is the map\\index{dgen_S1@{$\\mathsf{dgen}_{\\sphere{1}}$}|textbf}\n\\begin{equation}\\label{eq:dgen_circle}\n\\mathsf{dgen}_{\\sphere{1}}:\\Big(\\prd{t:\\sphere{1}}P(t)\\Big)\\to\\Big(\\sm{y:P(\\base)}\\id{\\mathsf{tr}_P(\\lloop,y)}{y}\\Big)\n\\end{equation}\ngiven by $\\mathsf{dgen}_{\\sphere{1}}(f)\\defeq\\pairr{f(\\base),\\apd{f}{\\lloop}}$.\n\\end{defn}\n\nWe now give the full specification of the circle.\n\n\\begin{defn}\nThe \\define{circle}\\index{circle|textbf} is a type $\\sphere{1}$\\index{S 1@{$\\sphere{1}$}} that comes equipped with\\index{base@{$\\base$}}\\index{loop@{$\\lloop$}}\n\\begin{align*}\n\\base & : \\sphere{1} \\\\\n\\lloop & : \\id{\\base}{\\base},\n\\end{align*}\nand satisfies the \\define{induction principle of the circle}\\index{induction principle!of the circle}, which provides for each type family $P$ over $\\sphere{1}$ a map\n\\begin{equation*}\n\\ind{\\sphere{1}}:\\Big(\\sm{y:P(\\base)}\\id{\\mathsf{tr}_P(\\lloop,y)}{y}\\Big)\\to \\Big(\\prd{t:\\sphere{1}}P(t)\\Big),\n\\end{equation*}\nand a homotopy witnessing that $\\ind{\\sphere{1}}$ is a section of $\\mathsf{dgen}_{\\sphere{1}}$\n\\begin{equation*}\n\\mathsf{dgen}_{\\sphere{1}}\\circ \\ind{\\sphere{1}}\\htpy \\idfunc\n\\end{equation*}\nfor the computation rule\\index{computation rules!of the circle}.\n\\end{defn}\n\n\\begin{rmk}\nThe induction principle of the circle provides us with a dependent function $f:\\prd{t:\\sphere{1}}P(t)$ equipped with an identification\n\\begin{equation*}\n(f(\\base),\\apd{f}{\\lloop})=(x,p),\n\\end{equation*}\nfor any $x : P(\\base)$ and $p : \\mathsf{tr}_P(\\lloop,x)=x$. By \\cref{thm:eq_sigma} the identification\n$(f(\\base),\\apd{f}{\\lloop})=(x,p)$ is equivalently described as a pair of identifications\n\\begin{samepage}\n\\begin{align*}\n\\alpha & : f(\\base)= x \\\\\n\\beta & : \\mathsf{tr}(\\alpha,\\apd{f}{\\lloop}) = p.\n\\end{align*}\\end{samepage}%\nHere, the transport is taken with respect to the family $x\\mapsto \\mathsf{tr}_P(\\lloop,x)=x$. \n\nThe identity type $\\mathsf{tr}(\\alpha,\\apd{f}{\\lloop}) = p$ is equivalent to the type\n\\begin{equation*}\n\\ct{\\apd{f}{\\lloop}}{\\alpha}=\\ct{\\mathsf{ap}_{\\mathsf{tr}_P(\\lloop)}(\\alpha)}{p}.\n\\end{equation*}\nIndeed, such an equivalence can be constructed by path induction, because types reduce to the type $\\apd{f}{\\lloop}=p$ when $\\alpha\\jdeq\\refl{f(x)}$. Therefore we obtain from the computation rule of the circle an identification $\\alpha:f(\\base)=x$, and an identification\n\\begin{equation*}\n\\beta':\\ct{\\apd{f}{\\lloop}}{\\alpha}=\\ct{\\mathsf{ap}_{\\mathsf{tr}_P(\\lloop)}(\\alpha)}{p}\n\\end{equation*}\nwitnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\n\\mathsf{tr}_P(\\lloop,f(\\base)) \\arrow[d,equals,swap,\"\\apd{f}{\\lloop}\"] \\arrow[r,equals,\"\\ap{\\mathsf{tr}_P(\\lloop)}{\\alpha}\"] & \\mathsf{tr}_P(\\lloop,x) \\arrow[d,equals,\"p\"] \\\\\nf(\\base) \\arrow[r,equals,swap,\"\\alpha\"] & x\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\end{rmk}\n\n\\subsection{The universal property of the circle}\n\nIn the following theorem we establish the \\define{universal property}\\index{universal property!of the circle} of the circle. The proof requires \\cref{lem:circle_up_htpy,lem:circle_up_tr_compute}, which we state after we encounter their application.\n\n\\begin{thm}\\label{thm:circle_up} \nFor each type $X$, the \\define{action on generators}\\index{action on generators!for the circle}\\index{gen_S1@{$\\mathsf{gen}_{\\sphere{1}}$}|textbf}\n\\begin{equation*}\n\\mathsf{gen}_{\\sphere{1}}:(\\sphere{1}\\to X)\\to \\sm{x:X}x=x\n\\end{equation*}\ngiven by $f\\mapsto (f(\\base),\\ap{f}{\\lloop})$ is an equivalence.\n\\end{thm}\n\n\\begin{proof}\nLet $x:X$ and let $p:x=x$. By \\cref{ex:trans_triv} we have an identification \n\\begin{equation*}\n\\mathsf{tr\\usc{}triv}(\\lloop,x):\\mathsf{tr}_{W_{\\sphere{1}}X}(\\lloop,x)=x,\n\\end{equation*}\nfrom which we obtain a fiberwise equivalence\n\\begin{equation*}\n\\varphi : \\prd{x:X} (x=x) \\to (\\mathsf{tr}_{W_{\\sphere{1}}X}(\\lloop,x)=x)\n\\end{equation*}\ngiven by $p\\mapsto \\ct{\\mathsf{tr\\usc{}triv}(\\lloop,x)}{p}$.\nMoreover, for any $f:A\\to B$, and any $p:x=y$ there is an identification $\\ct{\\mathsf{tr\\usc{}triv}(p,f(x))}{\\mathsf{ap}_f(p)}=\\apd{f}{p}$, so it follows that the triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=0]\n& (\\sphere{1}\\to X) \\arrow[dl,swap,\"\\mathsf{gen}_{\\sphere{1}}\"] \\arrow[dr,swap,\"\\mathsf{dgen}_{\\sphere{1}}\" near start] \\\\\n\\sm{x:X}x=x \\arrow[rr,\"\\total{\\varphi}\"',\"\\eqvsym\"] & & \\sm{x:X} \\mathsf{tr}_{W_{\\sphere{1}}X}(\\lloop,x)=x \\arrow[ul,densely dotted,bend right=15,swap,\"\\ind{\\sphere{1}}\"]\n\\end{tikzcd}\n\\end{equation*}\ncommutes, and the map $\\total{\\varphi}$ is a fiberwise equivalence by \\cref{thm:fib_equiv}. Since the triangle commutes and $\\ind{\\sphere{1}}$ is a section of $\\mathsf{dgen}_{\\sphere{1}}$, it follows that the composite\n\\begin{equation*}\n\\rec{\\sphere{1}}\\defeq \\ind{\\sphere{1}}\\circ \\total{\\varphi}\n\\end{equation*}\nis a section of $\\mathsf{gen}_{\\sphere{1}}$. Therefore it remains to show that $\\rec{\\sphere{1}}$ is also a retraction of $\\mathsf{gen}_{\\sphere{1}}$, i.e., we have to show that for every $f:\\sphere{1}\\to X$ there is an identification\n\\begin{equation*}\n\\rec{\\sphere{1}}(\\mathsf{gen}_{\\sphere{1}}(f))=f.\n\\end{equation*}\nIn \\cref{lem:circle_up_htpy} below we establish that\n\\begin{equation*}\n(\\mathsf{gen}_{\\sphere{1}}(\\rec{\\sphere{1}}(\\mathsf{gen}_{\\sphere{1}}(f)))=\\mathsf{gen}_{\\sphere{1}}(f))\\to (\\rec{\\sphere{1}}(\\mathsf{gen}_{\\sphere{1}}(f))=f).\n\\end{equation*}\nWe get an identification $\\mathsf{gen}_{\\sphere{1}}(\\rec{\\sphere{1}}(\\mathsf{gen}_{\\sphere{1}}(f)))=\\mathsf{gen}_{\\sphere{1}}(f)$ from the fact that $\\rec{\\sphere{1}}$ is a section of $\\mathsf{gen}_{\\sphere{1}}$.\n\\end{proof}\n\n\\begin{lem}\\label{lem:circle_up_htpy}\nLet $f,g:\\sphere{1}\\to X$ be two dependent functions. Then there is a map\n\\begin{equation*}\n(\\mathsf{gen}_{\\sphere{1}}(f)=\\mathsf{gen}_{\\sphere{1}}(g))\\to (f=g)\n\\end{equation*}\n\\end{lem}\n\n\\begin{proof}\nLet $p:\\mathsf{gen}_{\\sphere{1}}(f)=\\mathsf{gen}_{\\sphere{1}}(g)$. By function extensionality, it suffices to show that $f\\htpy g$. However, since $f\\htpy g$ is just the type $\\prd{t:\\sphere{1}}f(t)=g(t)$, we can construct such a homotopy by $\\sphere{1}$-induction. Thus, it suffices to construct a term of type\n\\begin{equation*}\n\\sm{p:f(\\base)=g(\\base)} \\mathsf{tr}_{E_{f,g}}(\\lloop,p)=p, \n\\end{equation*}\nwhere $E_{f,g}$ is the family over $\\sphere{1}$ given by $t\\mapsto f(t)=g(t)$.\n\nWe claim that it suffices to construct for each $p:f(\\base)=g(\\base)$ an equivalence\n\\begin{equation*}\n\\Big(\\mathsf{tr}_{E_{f,g}}(\\lloop,p)=p\\Big)\\eqvsym\\Big(\\mathsf{tr}_{L}(p,\\ap{f}{\\lloop})=\\ap{g}{\\lloop}\\Big),\n\\end{equation*}\nwhere $L$ is the family over $X$ given by $x\\mapsto x=x$. \nTo see that this suffices, we note that such a fiberwise equivalence induces an equivalence on total spaces, and the total space\n\\begin{align*}\n\\sm{p:f(\\base)=g(\\base)} \\mathsf{tr}_{L}(p,\\ap{f}{\\lloop})=\\ap{g}{\\lloop},\n\\end{align*}\nand is equivalent to $\\mathsf{gen}(f)=\\mathsf{gen}(g)$, of which we have assumed a term.\n\nThe asserted fiberwise equivalence that we need for this proof to go through requires a sufficient generalization so that it can be constructed by path induction, so it is established separately in \\cref{lem:circle_up_tr_compute} below.\n\\end{proof}\n\n\\begin{comment}\nConsider $f,g:\\sphere{1}\\to X$ with a homotopy $H:f\\htpy g$. Then we have $H(\\base):f(\\base)=g(\\base)$, and the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\nf(\\base) \\arrow[r,equals,\"H(\\base)\"] \\arrow[d,swap,equals,\"\\ap{f}{\\lloop}\"] & g(\\base) \\arrow[d,equals,\"\\ap{g}{\\lloop}\"] \\\\\nf(\\base) \\arrow[r,equals,swap,\"H(\\base)\"] & g(\\base)\n\\end{tikzcd}\n\\end{equation*}\ncommutes by the naturality of homotopies, established in \\cref{defn:htpy_nat}\\index{naturality!of homotopies}. In the following lemma we will relate such squares in two ways to a transport, by generalizing the above situation sufficiently so that path induction becomes applicable. We will use these computations of transports to establish the universal property of the circle. \n\\end{comment}\n\nWith the following lemma we complete the proof of the universal property of the circle. \n\n\\begin{samepage}%\n\\begin{lem}\\label{lem:circle_up_tr_compute} ~\n\\begin{enumerate}\n\\item Let $f,g:A \\to B$, and let $E_{f,g}$ be the family over $A$ given by \n\\begin{equation*}\nE_{f,g}(x)\\defeq f(x)=g(x).\n\\end{equation*}\nThen for any $p:x=x'$ in $A$ there is an equivalence\n\\begin{equation*}\n\\eqv{(\\mathsf{tr}_{E_{f,g}}(p,q)=q')}{(\\ct{\\ap{f}{p}}{q'}=\\ct{q}{\\ap{g}{p}})}.\n\\end{equation*}\nfor any $q:f(x)=g(x)$ and $q':f(x')=g(x')$. In other words, there is an identification $\\mathsf{tr}_{E_{f,g}}(p,q)=q'$ if and only if the square\n\\begin{equation*}\n\\begin{tikzcd}\nf(x) \\arrow[r,equals,\"q\"] \\arrow[d,equals,swap,\"\\ap{f}{p}\"] & g(x) \\arrow[d,equals,\"\\ap{g}{p}\"] \\\\\nf(x') \\arrow[r,equals,swap,\"{q'}\"] & g(x') \n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\item Let $L$ be the family over $B$ given by $L(y)\\defeq y=y$, and let $q:y=y'$ be an identification in $B$. Then there is an equivalence\n\\begin{equation*}\n\\eqv{(\\mathsf{tr}_L(q,p)=p')}{(\\ct{q}{p'}=\\ct{p}{q})}. \n\\end{equation*}\nfor any $p:y=y$ and $p':y'=y'$. In other words, there is an identification $\\mathsf{tr}_L(q,p)=p'$ if and only if the square\n\\begin{equation*}\n\\begin{tikzcd}\ny \\arrow[r,equals,\"p\"] \\arrow[d,swap,equals,\"q\"] & y \\arrow[d,equals,\"q\"] \\\\\ny' \\arrow[r,equals,swap,\"{p'}\"] & y'\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\item Let $f,g:A \\to B$, let $p:x=x$ be a loop in $A$, and let $q:f(x)=g(x)$. Then there is an equivalence\n\\begin{equation*}\n\\eqv{(\\mathsf{tr}_{E_{f,g}}(p,q)=q)}{(\\mathsf{tr}_L(q,\\ap{f}{p})=\\ap{g}{p}).}\n\\end{equation*}\n\\end{enumerate}\n\\end{lem}\n\\end{samepage}%\n\n\\begin{proof}\nThe first claim follows by path induction on $p$, and the second claim follows by path induction on $q$. The third claim follows by combining the first two, since the types on both sides are equivalent to the type\n\\begin{equation*}\n\\ct{\\ap{f}{p}}{q}=\\ct{q}{\\ap{g}{p}}\n\\end{equation*}\nof witnesses that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\nf(x) \\arrow[r,equals,\"q\"] \\arrow[d,swap,equals,\"\\ap{f}{p}\"] & g(x) \\arrow[d,equals,\"\\ap{g}{p}\"] \\\\\nf(x) \\arrow[r,equals,swap,\"q\"] & g(x)\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\end{proof}\n\n\\begin{exercises}\n\\item \\label{ex:circle_up_pushout}Show that\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nX^{\\sphere{1}} \\arrow[r,\"\\blank\\circ\\mathsf{const}_{\\base}\"] \\arrow[d,swap,\"\\blank\\circ\\mathsf{const}_{\\base}\"] & X^\\unit \\arrow[d,\"\\blank\\circ\\mathsf{const}_{\\ttt}\"] \\\\\nX^\\unit \\arrow[r,swap,\"\\blank\\circ\\mathsf{const}_{\\ttt}\"] & X^\\bool\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square for each type $X$.\n\\item \\label{ex:circle_dup}In this exercise we establish the \\emph{dependent universal property} of the circle, analogous to the proof of \\cref{thm:circle_up}.\n\\begin{subexenum}\n\\item Let $f,g:\\prd{x:A}B(x)$, and let $E_{f,g}$ be the family over $A$ given by \n\\begin{equation*}\nE_{f,g}(x)\\defeq f(x)=g(x).\n\\end{equation*}\nConstruct for any $p:x=x'$ in $A$ an equivalence\n\\begin{equation*}\n\\eqv{(\\mathsf{tr}_{E_{f,g}}(p,q)=q')}{(\\ct{\\apd{f}{p}}{q'}=\\ct{\\ap{\\mathsf{tr}_B(p)}{q}}{\\apd{g}{p}})}.\n\\end{equation*}\nfor any $q:f(x)=g(x)$ and $q':f(x')=g(x')$.\n\\item Let $B$ be a family over $A$, and for $l:x=_A x$ let $L_x$ be the family over $B(x)$ given by \n\\begin{equation*}\nL_x(y)\\defeq \\mathsf{tr}_B(l,y)=y.\n\\end{equation*}\nFurthermore, let $q:y=y'$ be an identification in $B(x)$. \nConstruct an equivalence\n\\begin{equation*}\n\\eqv{(\\mathsf{tr}_{L_x}(q,p)=p')}{(\\ct{\\ap{\\mathsf{tr}_B(l)}{q}}{p'}=\\ct{p}{q})}. \n\\end{equation*}\nfor any $p:\\mathsf{tr}_B(l,y)=y$ and $p':\\mathsf{tr}_B(l,y')=y'$.\n\\item Let $f,g:\\prd{x:A}B(x)$, let $p:x=x$ be a loop in $A$, and let $q:f(x)=g(x)$. \nConstruct an equivalence\n\\begin{equation*}\n\\eqv{(\\mathsf{tr}_{E_{f,g}}(p,q)=q)}{(\\mathsf{tr}_{L_x}(q,\\apd{f}{p})=\\apd{g}{p}).}\n\\end{equation*}\n\\item Show that for any $f,g:\\prd{t:\\sphere{1}}P(t)$ there is a function\n\\begin{equation*}\n\\Big(\\mathsf{dgen}_{\\sphere{1}}(f)=\\mathsf{dgen}_{\\sphere{1}}(g)\\Big)\\to (f=g).\n\\end{equation*}\n\\item Show that for any type family $P$ over $\\sphere{1}$, the \\emph{dependent action on generators}\n\\begin{equation*}\n\\Big(\\prd{t:\\sphere{1}}P(t)\\Big)\\to \\sm{u:P(\\base)}\\mathsf{tr}_P(\\lloop,u)=u\n\\end{equation*}\nis an equivalence.\n\\end{subexenum}\n\\item \\label{ex:circle-connected}Let $P:\\sphere{1}\\to\\prop$ be a family of propositions over the circle. Show that\n\\begin{equation*}\nP(\\base)\\to\\prd{t:\\sphere{1}}P(t).\n\\end{equation*}\nIn this sense the circle is \\emph{connected}.\n\\item Show that\n\\begin{equation*}\n\\prd{x,y:\\sphere{1}}\\neg\\neg(x=y).\n\\end{equation*}\n\\item \\label{ex:circle_constant}\nShow that for any type $X$ and any $x:X$, the map\n\\begin{equation*}\n\\rec{\\sphere{1}}(x,\\refl{x}):\\sphere{1}\\to X\n\\end{equation*}\nis homotopic to the constant map $\\mathsf{const}_x$.\n\\item \\label{ex:circle_connected}\n\\begin{subexenum}\n\\item Show that a type $X$ is a set if and only if the map\n\\begin{equation*}\n\\lam{x}{t} x : X \\to (\\sphere{1}\\to X)\n\\end{equation*}\nis an equivalence.\n\\item Show that a type $X$ is a set if and only if the map\n\\begin{equation*}\n\\lam{f}f(\\base) : (\\sphere{1}\\to X)\\to X\n\\end{equation*}\nis an equivalence.\n\\end{subexenum}\n\\end{exercises}\n\n\\section{The fundamental cover of the circle}\n\nIn this lecture we show that the loop space of the circle is equivalent to $\\mathbb{Z}$ by constructing the universal cover of the circle as an application of the univalence axiom. \n\n\\subsection{Families over the circle}\n\nThe type of small families over $\\sphere{1}$ is just the function type $\\sphere{1}\\to\\UU$, so in fact we may use the universal property of the circle to construct small dependent types over the circle. \nBy the universal property, small type families over $\\sphere{1}$ are equivalently described as pairs $(X,p)$ consisting of a type $X:\\UU$ and an identification $p:X=X$.\nThis is where the univalence axiom\\index{univalence axiom!families over $\\sphere{1}$} comes in. By the map\n\\begin{equation*}\n\\mathsf{eq\\usc{}equiv}_{X,X}:(\\eqv{X}{X})\\to (X=X)\n\\end{equation*}\nit suffices to provide an equivalence $\\eqv{X}{X}$.\n\n\\begin{defn}\\label{defn:circle_descent}\nConsider a type $X$ and every equivalence $e:\\eqv{X}{X}$.\nWe will construct a dependent type $\\mathcal{D}(X,e):\\sphere{1}\\to\\UU$ with an equivalence $x\\mapsto x_{\\mathcal{D}}:\\eqv{X}{\\mathcal{D}(X,e,\\base)}$ for which the square\n\\begin{equation*}\n\\begin{tikzcd}\nX \\arrow[r,\"\\eqvsym\"] \\arrow[d,swap,\"e\"] & \\mathcal{D}(X,e,\\base) \\arrow[d,\"\\mathsf{tr}_{\\mathcal{D}(X,e)}(\\lloop)\"] \\\\\nX \\arrow[r,swap,\"\\eqvsym\"] & \\mathcal{D}(X,e,\\base)\n\\end{tikzcd}\n\\end{equation*}\ncommutes. We also write $d\\mapsto d_{X}$ for the inverse of this equivalence, so that the relations\n\\begin{samepage}%\n\\begin{align*}\n(x_{\\mathcal{D}})_X & =x & (e(x)_{\\mathcal{D}}) & = \\mathsf{tr}_{\\mathcal{D}(X,e)}(\\lloop,x_{\\mathcal{D}}) \\\\\n(d_X)_{\\mathcal{D}} & =d & (\\mathsf{tr}_{\\mathcal{D}(X,e)}(d))_X & = e(d_X)\n\\end{align*}\n\\end{samepage}%\nhold.\n\nThe type $\\sm{X:\\UU}\\eqv{X}{X}$ is also called the type of \\define{descent data}\\index{descent data!for the circle|textbf} for the circle.\n\\end{defn}\n\n\\begin{constr}\nBy \\cref{ex:tr_ap} we have an identification\n\\begin{equation*}\n\\mathsf{equiv\\usc{}eq}(\\ap{P}{\\lloop})=\\mathsf{tr}_P(\\lloop)\n\\end{equation*}\nfor each dependent type $P:\\sphere{1}\\to\\UU$. Therefore we see that the triangle\\index{desc_S1@{$\\mathsf{desc}_{\\sphere{1}}$}}\n\\begin{equation*}\n\\begin{tikzcd}\n& (\\sphere{1}\\to \\UU) \\arrow[dl,swap,\"\\mathsf{gen}_{\\sphere{1}}\"] \\arrow[dr,\"\\mathsf{desc}_{\\sphere{1}}\"] \\\\\n\\sm{X:\\UU}X=X \\arrow[rr,swap,\"\\total{\\lam{X}\\mathsf{equiv\\usc{}eq}_{X,X}}\"] & & \\sm{X:\\UU}\\eqv{X}{X}\n\\end{tikzcd}\n\\end{equation*}\ncommutes, where the map $\\mathsf{desc}_{\\sphere{1}}$ is given by $P\\mapsto\\pairr{P(\\base),\\mathsf{tr}_P(\\lloop)}$ and the bottom map is an equivalence by the univalence axiom and \\cref{thm:fib_equiv}.\nNow it follows by the 3-for-2 property that $\\mathsf{desc}_{\\sphere{1}}$ is an equivalence, since $\\mathsf{gen}_{\\sphere{1}}$ is an equivalence by \\cref{thm:circle_up}.\nThis means that for every type $X$ and every $e:\\eqv{X}{X}$ there is a type family $\\mathcal{D}(X,e):\\sphere{1}\\to\\UU$ such that\n\\begin{equation*}\n\\pairr{\\mathcal{D}(X,e,\\base),\\mathsf{tr}_{\\mathcal{D}(X,e)}(\\lloop)}=\\pairr{X,e}.\n\\end{equation*}\nEquivalently, we have $p:\\id{\\mathcal{D}(X,e,\\base)}{X}$ and $\\mathsf{tr}(p,{\\mathsf{tr}_{\\mathcal{D}(X,e)}(\\lloop)})=e$. Thus, we obtain $\\mathsf{equiv\\usc{}eq}(p):\\eqv{\\mathcal{D}(X,e,\\base)}{X}$, for which the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\n\\mathcal{D}(X,e,\\base)\\arrow[r,\"\\mathsf{equiv\\usc{}eq}(p)\"] \\arrow[d,swap,\"\\mathsf{tr}_{\\mathcal{D}(X,e)}(\\lloop)\"] & X \\arrow[d,\"e\"] \\\\\n\\mathcal{D}(X,e,\\base)\\arrow[r,swap,\"\\mathsf{equiv\\usc{}eq}(p)\"] & X\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\end{constr}\n\n\\begin{comment}\n\\begin{defn}\\label{defn:fiber_sequence}\nA \\define{fiber sequence} \n\\begin{equation*}\nF \\hookrightarrow E \\twoheadrightarrow B\n\\end{equation*}\nconsists of a \\define{base type} $B$ with a base point $b_0$ and a dependent type $P:B\\to\\type$, a type $F$ called the \\define{fiber} with an equivalence $\\eqv{P(b_0)}{F}$, and a type $E$ called the \\define{total space} with a map $p:E\\to B$ and an equivalence $e:\\eqv{(\\sm{b:B}P(b))}{E}$ such that the triangle\n\\begin{equation*}\n\\begin{tikzcd}\n\\Big(\\sm{b:B}P(b)\\Big) \\arrow[rr,\"e\"] \\arrow[dr,swap,\"\\proj 1\"] & & E \\arrow[dl,\"p\"] \\\\\n& B\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\end{defn}\n\\end{comment}\n\n\\subsection{The fundamental cover of the circle}\n\nThe \\emph{fundamental cover}\\index{fundamental cover!of the circle} of the circle is a family of sets over the circle with contractible total space.\nClassically, the fundamental cover is described as a map $\\mathbb{R}\\to\\sphere{1}$ that winds the real line around the circle.\nIn homotopy type theory there is no analogue of such a construction.\n\nRecall from \\cref{ex:succ_equiv} that the successor function $\\mathsf{succ}:\\Z\\to \\Z$ is an equivalence. Its inverse is the predecessor function defined in \\cref{ex:int_pred}. \n\n\\begin{defn}\nThe \\define{fundamental cover}\\index{fundamental cover!of the circle|textbf} of the circle is the dependent type $\\mathcal{E}_{\\sphere{1}}\\defeq\\mathcal{D}(\\Z,\\mathsf{succ}):\\sphere{1}\\to\\UU$.\\index{Z@{$\\Z$}!fundamental cover of S1@{fundamental cover of $\\sphere{1}$}}\\index{E_S1@{$\\mathcal{E}_{\\sphere{1}}$}|textbf}\n\\end{defn}\n\n\\begin{rmk}\n  The fundamental cover of the circle comes equipped with an equivalence\n  \\begin{equation*}\n    e:\\mathbb{Z} \\simeq \\mathcal{E}_{\\sphere{1}}(\\mathsf{base})\n  \\end{equation*}\n  and a homotopy witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\mathbb{Z} \\arrow[r,\"e\"] \\arrow[d,swap,\"\\mathsf{succ}\"] & \\mathcal{E}_{\\sphere{1}}(\\mathsf{base}) \\arrow[d,\"\\mathsf{tr}_{\\mathcal{E}_{\\sphere{1}}}(\\mathsf{loop})\"] \\\\\n      \\mathbb{Z} \\arrow[r,swap,\"e\"] & \\mathcal{E}_{\\sphere{1}}(\\mathsf{base})\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes.\n\n  For convenience, we write $k_{\\mathcal{E}}$ for the term $e(k):\\mathcal{E}_{\\sphere{1}}(\\mathsf{base})$, for any $k:\\mathbb{Z}$. \n\\end{rmk}\n\nThe picture of the fundamental cover is that of a helix\\index{helix} over the circle. This picture emerges from the path liftings of $\\mathsf{loop}$ in the total space. The segments of the helix connecting $k$ to $k+1$ in the total space of the helix, are constructed in the following lemma.\n\n\\begin{lem}\nFor any $k:\\Z$, there is an identification\n\\begin{equation*}\n\\mathsf{segment\\usc{}helix}_k:(\\base,k_{\\mathcal{E}})=(\\base,\\mathsf{succ}(k)_{\\mathcal{E}})\n\\end{equation*}\nin the total space $\\sm{t:\\sphere{1}}\\mathcal{E}(t)$.\n\\end{lem}\n\n\\begin{proof}\nBy \\cref{thm:eq_sigma} it suffices to show that\n\\begin{equation*}\n\\prd{k:\\Z} \\sm{\\alpha:\\base=\\base} \\mathsf{tr}_{\\mathcal{E}}(\\alpha,k_{\\mathcal{E}})= \\mathsf{succ}(k)_{\\mathcal{E}}.\n\\end{equation*}\nWe just take $\\alpha\\defeq\\lloop$. Then we have $\\mathsf{tr}_{\\mathcal{E}}(\\alpha,k_{\\mathcal{E}})= \\mathsf{succ}(k)_{\\mathcal{E}}$ by the commuting square provided in the definition of $\\mathcal{E}$.\n\\end{proof}\n\n\\subsection{Contractibility of general total spaces}\nConsider a type $X$, a family $P$ over $X$, and a term $c:\\sm{x:X}P(x)$, and suppose our goal is to construct a contraction\n\\begin{equation*}\n  \\prd{t:\\sm{x:X}P(x)}c=t.\n\\end{equation*}\nOf course, the first step is to apply the induction principle of $\\Sigma$-types, so it suffices to construct a term of type\n\\begin{equation*}\n\\prd{x:X}{y:P(x)} c = (x,y).\n\\end{equation*}\nIn the case where $P$ is the fundamental cover of the circle, we are given an equivalence $e:\\eqv{\\Z}{\\mathcal{E}(\\base)}$. Using this equivalence, we obtain an equivalence\n\\begin{equation*}\n  \\Big(\\prd{y:\\mathcal{E}(y)}c=(\\mathsf{base},y)\\Big)\\to \\Big(\\prd{k:\\Z}c=(\\mathsf{base},k_{\\mathcal{E}})\\Big).\n\\end{equation*}\nMore generally, if we are given an equivalence $e:\\eqv{F}{P(x)}$ for some $x:X$, then we have an equivalence\n\\begin{equation}\n\\Big(\\prd{y:P(x)}c=(x,y)\\Big) \\to \\Big(\\prd{y:F}c=(x,e(y))\\Big)\n\\end{equation}\nby precomposing with the equivalence $e$. Therefore we can construct a term of type $\\prd{y:P(x)}c=(x,y)$ by constructing a term of type $\\prd{y:F}c=(x,e(y))$. \n\nFurthermore, if we consider a path $p:x=x'$ in $X$ and a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      F \\arrow[r,\"e\"] \\arrow[d,swap,\"f\"] & P(x) \\arrow[d,\"\\mathsf{tr}_P(p)\"] \\\\\n      F' \\arrow[r,\"{e'}\"] & P(x')\n    \\end{tikzcd}\n  \\end{equation*}\n  where $e$, $e'$, and $f$ are all equivalences, then we obtain a function\n  \\begin{equation*}\n    \\psi : \\Big(\\prd{y:F}c=(x,e(y))\\Big)\\to \\Big(\\prd{y':F'}c=(x,e'(y'))\\Big).\n  \\end{equation*}\n  The function $\\psi$ is constructed as follows. Given $h:\\prd{y:F}c=(x,e(y))$ and $y':F'$ we have the path $h(f^{-1}(y')):c=(x,e(f^{-1}(y')))$. Moreover, writing $G$ for the homotopy $f\\circ f^{-1} \\htpy\\idfunc$, we have the path\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      {\\mathsf{tr}_P(p,e(f^{-1}(y')))} \\arrow[r,equals,\"{H(f^{-1}(y'))}\"] &\n      {e'(f(f^{-1}(y')))} \\arrow[r,equals,\"\\ap{e'}{G(y')}\"] &\n      {e'(y')}.\n    \\end{tikzcd}\n  \\end{equation*}\n  From this concatenated path we obtain the path\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=14em]\n      {(x,e(f^{-1}(y')))} \\arrow[r,equals,\"{\\mathsf{eq\\usc{}pair}(p,\\ct{H(f^{-1}(y'))}{\\ap{e'}{G(y')}})}\"] & {(x',e'(y'))}.\n    \\end{tikzcd}\n  \\end{equation*}\n  Now we define the function $\\psi$ by\n  \\begin{equation*}\n    h\\mapsto \\lam{y'}\\ct{h(f^{-1}(y'))}{\\mathsf{eq\\usc{}pair}(p,\\ct{H(f^{-1}(y'))}{\\ap{e'}{G(y')}})}.\n  \\end{equation*}\n  Note that $\\psi$ is an equivalence, since it is given as precomposition by the equivalence $f^{-1}$, followed by postcomposition by concatenation, which is also an equivalence. Now we state the main technical result of this section, which will help us prove the contractibility of the total space of the fundamental cover of the circle by computing transport in the family $x\\mapsto \\prd{y:P(x)}c=(x,y)$.\n\n  \\begin{defn}\n    Consider a path $p:x=x'$ in $X$ and a commuting square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        F \\arrow[r,\"e\"] \\arrow[d,swap,\"f\"] & P(x) \\arrow[d,\"\\mathsf{tr}_P(p)\"] \\\\\n        F' \\arrow[r,\"{e'}\"] & P(x')\n      \\end{tikzcd}\n    \\end{equation*}\n    with $H:e'\\circ f ~ \\mathsf{tr}_P(p)\\circ e$, where $e$, $e'$, and $f$ are all equivalences. Then there is for any $y:F$ an identification\n    \\begin{equation*}\n      \\mathsf{segment\\usc{}tot}(y):(x,e(y))=(x',e'(f(y)))\n    \\end{equation*}\n    defined as $\\mathsf{segment\\usc{}tot}(y)\\defeq\\mathsf{eq\\usc{}pair}(p,H(y)^{-1})$.\n  \\end{defn}\n\n  \\begin{lem}\\label{lem:compute-tr-contraction}\n    Consider a path $p:x=x'$ in $X$ and a commuting square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        F \\arrow[r,\"e\"] \\arrow[d,swap,\"f\"] & P(x) \\arrow[d,\"\\mathsf{tr}_P(p)\"] \\\\\n        F' \\arrow[r,\"{e'}\"] & P(x')\n      \\end{tikzcd}\n    \\end{equation*}\n    with $H:e'\\circ f ~ \\mathsf{tr}_P(p)\\circ e$, where $e$, $e'$, and $f$ are all equivalences. Furthermore, let\n    \\begin{align*}\n      h & : \\prd{y:F}c=(x,e(y)) \\\\\n      h' & : \\prd{y':F'}c=(x',e'(y')).\n    \\end{align*}\n    Then there is an equivalence\n    \\begin{equation*}\n      \\Big(\\prd{y:F} h'(f(y))=\\ct{h(y)}{\\mathsf{segment\\usc{}tot}(y)}\\Big)\n      \\simeq \\Big(\\mathsf{tr}_C(p,\\varphi(h))= \\varphi'(h')\\Big).\n    \\end{equation*}\n  \\end{lem}\n\n  \\begin{proof}\n    We first note that we have a commuting square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        \\prd{y:B(x)}c=(x,y) \\arrow[r,\"\\blank\\circ e\"] \\arrow[d,swap,\"\\mathsf{tr}_C(p)\"] & \\prd{y:F}c=(x,e(y)) \\\\\n        \\prd{y':B(x')}c=(x',y') \\arrow[r,swap,\"\\blank\\circ {e'}\"] & \\prd{y':F'}c=(x',e'(y')) \\arrow[u,swap,\"\\psi\"]\n      \\end{tikzcd}\n    \\end{equation*}\n    where $\\psi(h')=\\lam{y}\\ct{h'(f(y))}{\\mathsf{segment\\usc{}tot}(y)^{-1}}$. All the maps in this square are equivalences. In particular, the inverses of the top and bottom maps are $\\varphi$ and $\\varphi'$, respectively. The claim follows from this observation, but we will spell out the details.\n\n    Since any equivalence is an embedding, we see immediately that the type $\\mathsf{tr}_C(p)(\\varphi(h))=\\varphi'(h')$ is equivalent to the type\n    \\begin{equation*}\n      \\psi(\\mathsf{tr}_C(p)(\\varphi(h))\\circ e')=\\psi(\\varphi'(h')\\circ e').\n    \\end{equation*}\n    By the commutativity of the square, the left hand side is $h$. The right hand side is $\\psi(h')$. Therefore it follows that\n    \\begin{align*}\n      \\Big(\\mathsf{tr}_C(p)(\\varphi(h))=\\varphi'(h')\\Big)\n      & \\simeq \\Big(h= \\lam{y}\\ct{h'(f(y))}{\\mathsf{segment\\usc{}tot}(y)^{-1}}\\Big) \\\\\n      & \\simeq \\Big(h'\\circ f \\htpy (\\lam{y}\\ct{h(y)}{\\mathsf{segment\\usc{}tot}(y)}\\Big).\\qedhere\n    \\end{align*}\n  \\end{proof}\n  \n  Applying these observations to the fundamental cover of the circle, we obtain the following lemma that we will use to prove that the total space of $\\mathcal{E}$ is contractible.\n  \n  \\begin{cor}\\label{cor:construct-contraction-fundamental-cover}\n    In order to show that the total space of $\\mathcal{E}$ is contractible, it suffices to construct a function\n    \\begin{equation*}\n      h : \\prd{k:\\Z}(\\base,0_{\\mathcal{E}})=(\\base,k_{\\mathcal{E}})\n    \\end{equation*}\n    equipped with a homotopy\n    \\begin{equation*}\n      H : \\prd{k:\\Z}h(\\mathsf{succ}(k)_{\\mathcal{E}})=\\ct{h(k)}{\\mathsf{segment\\usc{}helix}(k)}.\n    \\end{equation*}\n  \\end{cor}\n\n  In the next section we establish the dependent universal property of the integers, which we will use with \\cref{cor:construct-contraction-fundamental-cover} to show that the total space of the fundamental cover is contractible.\n  \n\n\\subsection{The dependent universal property of the integers}\n\\begin{lem}\\label{lem:elim-Z}\nLet $B$ be a family over $\\Z$, equipped with a term $b_0:B(0)$, and an equivalence\n\\begin{equation*}\ne_k : B(k)\\eqvsym B(\\mathsf{succ}(k))\n\\end{equation*}\nfor each $k:\\Z$. Then there is a dependent function $f:\\prd{k:\\Z}B(k)$ equipped with identifications $f(0)=b_0$ and\n\\begin{equation*}\nf(\\mathsf{succ}(k))=e_k(f(k))\n\\end{equation*}\nfor any $k:\\Z$.\n\\end{lem}\n\n\\begin{proof}\nThe map is defined using the induction principle for the integers, stated in \\cref{lem:Z_ind}. First we take\n\\begin{align*}\nf(-1) & \\defeq e^{-1}(b_0) \\\\\nf(0) & \\defeq b_0 \\\\\nf(1) & \\defeq e(b_0).\n\\end{align*}\nFor the induction step on the negative integers we use\n\\begin{equation*}\n\\lam{n}e_{\\mathsf{neg}(S(n))}^{-1} : \\prd{n:\\N} B(\\mathsf{neg}(n))\\to B(\\mathsf{neg}(S(n)))\n\\end{equation*}\nFor the induction step on the positive integers we use\n\\begin{equation*}\n\\lam{n}e(\\mathsf{pos}(n)) : \\prd{n:\\N} B(\\mathsf{pos}(n))\\to B(\\mathsf{pos}(S(n))).\n\\end{equation*}\nThe computation rules follow in a straightforward way from the computation rules of $\\Z$-induction and the fact that $e^{-1}$ is an inverse of $e$. \n\\end{proof}\n\n\\begin{eg}\nFor any type $A$, we obtain a map $f:\\Z\\to A$ from any $x:A$ and any equivalence $e:\\eqv{A}{A}$, such that $f(0)=x$ and the square\n\\begin{equation*}\n\\begin{tikzcd}\n\\Z \\arrow[d,swap,\"\\mathsf{succ}\"] \\arrow[r,\"f\"] & A \\arrow[d,\"e\"] \\\\\n\\Z \\arrow[r,swap,\"f\"] & A\n\\end{tikzcd}\n\\end{equation*}\ncommutes. In particular, if we take $A\\jdeq (x=x)$ for some $x:X$, then for any $p:x=x$ we have the equivalence $\\lam{q}\\ct{p}{q}:(x=x)\\to (x=x)$. This equivalence induces a map\n\\begin{equation*}\nk\\mapsto p^k : \\Z \\to (x=x),\n\\end{equation*}\nfor any $p:x=x$. This induces the \\define{degree $k$ map} on the circle\n\\begin{equation*}\n\\mathsf{deg}(k) : \\sphere{1}\\to\\sphere{1},\n\\end{equation*}\nfor any $k:\\mathbb{Z}$, see \\cref{ex:degk}.\n\\end{eg}\n\nIn the following theorem we show that the dependent function constructed in \\cref{lem:elim-Z} is unique.\n\n\\begin{thm}\n  Consider a type family $B:\\mathbb{Z}\\to\\UU$ equipped with $b:B(0)$ and a family of equivalences\n  \\begin{equation*}\n    e:\\prd{k:\\Z} \\eqv{B(k)}{B(\\mathsf{succ}(k))}.\n  \\end{equation*}\n  Then the type\n  \\begin{equation*}\n    \\sm{f:\\prd{k:\\Z}B(k)}(f(0)=b)\\times\\prd{k:\\Z}f(\\mathsf{succ}(k))=e_k(f(k))\n  \\end{equation*}\n  is contractible.\n\\end{thm}\n\n\\begin{proof}\n  In \\cref{lem:elim-Z} we have already constructed a term of the asserted type.\n  Therefore it suffices to show that any two terms of this type can be identified.\n  Note that the type $(f,p,H)=(f',p',H')$ is equivalent to the type\n  \\begin{equation*}\n    \\sm{K:f\\htpy f'} (K(0)= \\ct{p}{(p')^{-1}})\\times \\prd{k:\\Z}K(\\mathsf{succ}(k))=\\ct{(\\ct{H(k)}{\\ap{e_k}{K(k)}})}{H'(k)^{-1}}. \n  \\end{equation*}\n  We obtain a term of this type by applying \\cref{lem:elim-Z} to the family $C$ over $\\Z$ given by $C(k)\\defeq f(k)=f'(k)$, which comes equipped with a base point\n  \\begin{equation*}\n    \\ct{p}{(p')^{-1}} : C(0),\n  \\end{equation*}\n  and the family of equivalences\n  \\begin{equation*}\n    \\lam{\\alpha:f(k)=f'(k)}\\ct{(\\ct{H(k)}{\\ap{e_k}{\\alpha}})}{H'(k)^{-1}}:\\prd{k:\\Z}\\eqv{C(k)}{C(\\mathsf{succ}(k))}.\\qedhere\n  \\end{equation*}\n\\end{proof}\n\nOne way of phrasing the following corollary, is that $\\Z$ is the `initial type equipped with a point and an automorphism'.\n\n\\begin{cor}\n  For any type $X$ equipped with a base point $x_0:X$ and an automorphism $e:\\eqv{X}{X}$, the type\n  \\begin{equation*}\n    \\sm{f:\\Z\\to X}(f(0)=x_0)\\times ((f \\circ \\mathsf{succ})\\htpy(e\\circ f))\n  \\end{equation*}\n  is contractible.\n\\end{cor}\n\n\n\n\\subsection{The identity type of the circle}\n\n\\begin{lem}\\label{thm:circle_fundamental}\nThe total space $\\sm{t:\\sphere{1}}\\mathcal{E}(t)$ of the fundamental cover of $\\sphere{1}$ is contractible.\\index{circle!fundamental cover!total space is contractible}\n\\end{lem}\n\n\\begin{proof}\n  By \\cref{cor:construct-contraction-fundamental-cover} it suffices to construct\n  a function\n  \\begin{equation*}\n    h : \\prd{k:\\Z}(\\base,0_{\\mathcal{E}})=(\\base,k_{\\mathcal{E}})\n  \\end{equation*}\n  equipped with a homotopy\n  \\begin{equation*}\n    H : \\prd{k:\\Z}h(\\mathsf{succ}(k)_{\\mathcal{E}})=\\ct{h(k)}{\\mathsf{segment\\usc{}helix}(k)}.\n  \\end{equation*}\n  We obtain $h$ and $H$ by the elimination principle of \\cref{lem:elim-Z}. Indeed, the family $P$ over the integers given by $P(k)\\defeq (\\base,0_{\\mathcal{E}})=(\\base,k_{\\mathcal{E}})$ comes equipped with a term $\\refl{(\\base,0_{\\mathcal{E}})}:P(0)$, and a family of equivalences\n  \\begin{equation*}\n    \\prd{k:\\Z}P(k) \\simeq P(\\mathsf{succ}(k))\n  \\end{equation*}\n  given by $k,p\\mapsto \\ct{p}{\\mathsf{segment\\usc{}helix}(k)}$. \n\\end{proof}\n\n\\begin{comment}\n\\begin{proof}\nWe show that the total space satisfies singleton induction (i.e., we apply \\cref{thm:contractible}). Let $P$ be a family over the total space of the fundamental cover, and let $p_0:P(\\base,0_{\\mathcal{E}})$. Our goal is to construct a term of type\n\\begin{equation*}\n\\prd{t:\\sphere{1}}{x:\\mathcal{E}(t)} P(t,x).\n\\end{equation*}\nWe do this by induction. For the base case we must construct a term of type\n\\begin{equation*}\n\\prd{k:\\Z}P(\\base,k_{\\mathcal{E}}).\n\\end{equation*}\nSince we have the identifications $s_k: (\\base,k_{\\mathcal{E}})=(\\base,\\mathsf{succ}(k)_{\\mathcal{E}})$, we have the equivalences\n\\begin{equation*}\n\\mathsf{tr}_P(s_k) : \\eqv{P(\\base,k_{\\mathcal{E}})}{P(\\base,\\mathsf{succ}(k)_{\\mathcal{E}})}\n\\end{equation*}\nfor each $k:\\Z$. Thus we obtain a dependent function $f:\\prd{x:\\mathcal{E}(\\base)}P(\\base,x)$ satisfying $f(0_{\\mathcal{E}})=p_0$ and $f(\\mathsf{succ}(k)_{\\mathcal{E}})=\\mathsf{tr}_P(s_k,f(k_{\\mathcal{E}}))$, for each $k:\\Z$. \n\nFor the loop case we must show that\n\\begin{equation*}\n\\mathsf{tr}_Q(\\lloop,f)=f,\n\\end{equation*}\nwhere $Q$ is the family over $\\sphere{1}$ given by $Q(t)\\defeq \\prd{x:\\mathcal{E}(t)} P(t,x)$. By function extensionality it suffices to construct a homotopy, and the transport along $\\lloop$ in $Q$ computes as\n\\begin{equation*}\n\\mathsf{tr}_Q(\\lloop,f)(k_{\\mathcal{E}})= \\mathsf{tr}_P(s_k,f(\\mathsf{succ}^{-1}(k)_{\\mathcal{E}})). \n\\end{equation*}\nTherefore the following computation completes the proof:\n\\begin{align*}\n\\mathsf{tr}_Q(\\lloop,f)(k_{\\mathcal{E}})\n& = \\mathsf{tr}_P(s_k,f(\\mathsf{succ}^{-1}(k)_{\\mathcal{E}})) \\\\\n& = f(\\mathsf{succ}(\\mathsf{succ}^{-1}(k))_{\\mathcal{E}}) \\\\\n& = f(k_{\\mathcal{E}}).\\qedhere\n\\end{align*}\n\\end{proof}\n\\end{comment}\n\n\\begin{thm}\\label{thm:eq-circle}\n  The family of maps\n  \\begin{equation*}\n    \\prd{t:\\sphere{1}} (\\base=t)\\to \\mathcal{E}(t)\n  \\end{equation*}\n  sending $\\refl{\\base}$ to $0_{\\mathcal{E}}$ is a family of equivalences. In particular, the loop space of the circle is equivalent to $\\Z$.\n\\end{thm}\n\n\\begin{proof}\n  This is a direct corollary of \\cref{thm:circle_fundamental,thm:id_fundamental}. \n\\end{proof}\n\n\\begin{cor}\n  The circle is a $1$-type and not a $0$-type.\\index{circle!is a 1-type@{is a $1$-type}|textit}\n\\end{cor}\n\n\\begin{proof}\n  To see that the circle is a $1$-type we have to show that $s=t$ is a $0$-type for every $s,t:\\sphere{1}$. By \\cref{ex:circle-connected} it suffices to show that the loop space of the circle is a $0$-type. This is indeed the case, because $\\Z$ is a $0$-type, and we have an equivalence $(\\base=\\base)\\simeq \\Z$.\n\n  Furthermore, since $\\Z$ is a $0$-type and not a $(-1)$-type, it follows that the circle is a $1$-type and not a $0$-type.\n\\end{proof}\n\n\\begin{exercises}\n\\item \\label{ex:degk}Use the fundamental cover of the circle to show that\n\\begin{equation*}\n\\neg\\Big(\\prd{t:\\sphere{1}}\\base=t\\Big).\n\\end{equation*}\n\\item \\label{ex:circle_degk}\n\\begin{subexenum}\n\\item Show that for every $x:X$, we have an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{f:\\sphere{1}\\to X}f(\\base)= x \\Big)}{(x=x)}\n\\end{equation*}\n\\item Show that for every $t:\\sphere{1}$, we have an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{f:\\sphere{1}\\to \\sphere{1}}f(\\base)= t \\Big)}{\\Z}\n\\end{equation*}\nThe base point preserving map $f:\\sphere{1}\\to\\sphere{1}$ corresponding to $k:\\Z$ is called the \\define{degree $k$ map} on the circle, and is denoted by $\\mathsf{deg}(k)$.\n\\item Show that for every $t:\\sphere{1}$, we have an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{e:\\eqv{\\sphere{1}}{\\sphere{1}}}e(\\base)= t \\Big)}{\\bool}\n\\end{equation*}\n\\end{subexenum}\n\\item \\label{ex:circle_double_cover} The \\define{(twisted) double cover} of the circle is defined as the type family $\\mathcal{T}\\defeq\\mathcal{D}(\\bool,\\mathsf{neg}):\\sphere{1}\\to\\UU$, where $\\mathsf{neg}:\\eqv{\\bool}{\\bool}$ is the negation equivalence of \\cref{ex:neg_equiv}.\n\\begin{subexenum}\n\\item Show that $\\neg(\\prd{t:\\sphere{1}}\\mathcal{T}(t))$.\n\\item Construct an equivalence $e:\\eqv{\\sphere{1}}{\\sm{t:\\sphere{1}}\\mathcal{T}(t)}$ for which the triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\n\\sphere{1} \\arrow[rr,\"e\"] \\arrow[dr,swap,\"\\mathsf{deg}(2)\"] & & \\sm{t:\\sphere{1}}\\mathcal{T}(t) \\arrow[dl,\"\\proj 1\"] \\\\\n\\phantom{\\sm{t:\\sphere{1}}\\mathcal{T}(t)} & \\sphere{1}\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\\end{subexenum}\n\\item Show that $\\eqv{(\\eqv{\\sphere{1}}{\\sphere{1}})}{\\sphere{1}+\\sphere{1}}$. Conclude that a univalent universe containing a circle is not a $1$-type.\n\\item \\label{ex:is_invertible_id_S1}\n\\begin{subexenum}\n\\item Construct a family of equivalences\n\\begin{equation*}\n\\prd{t:\\sphere{1}} \\big(\\eqv{(t=t)}{\\Z}\\big).\n\\end{equation*}\n\\item Use \\cref{ex:circle_connected} to show that $\\eqv{(\\idfunc[\\sphere{1}]\\htpy\\idfunc[\\sphere{1}])}{\\Z}$.\n\\item Use \\cref{ex:idfunc_autohtpy} to show that\n\\begin{equation*}\n\\eqv{\\mathsf{has\\usc{}inverse}(\\idfunc[\\sphere{1}])}{\\Z},\n\\end{equation*}\nand conclude that ${\\mathsf{has\\usc{}inverse}}(\\idfunc[\\sphere{1}])\\not\\simeq{\\isequiv(\\idfunc[\\sphere{1}])}$. \n\\end{subexenum}\n\\item Consider a map $i:A \\to \\sphere{1}$, and assume that $i$ has a retraction. Construct a term of type\n  \\begin{equation*}\n    \\iscontr(A)+\\isequiv(i).\n  \\end{equation*}\n\\end{exercises}\n", "meta": {"hexsha": "7de2356857e7d455db54dfec36fec114c92a3e24", "size": 38610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/circle.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/circle.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/circle.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": 49.8837209302, "max_line_length": 406, "alphanum_fraction": 0.6698005698, "num_tokens": 14037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6822971243831564}}
{"text": "% --- [ Type Lattice ] ---------------------------------------------------------\n\n\\subsection{Type Lattice}\n\nA type lattice may be thought of as a set of subtyping relationships, represented as a directed graph from the \\textit{top} type $\\top$ to the \\textit{bottom} type $\\bot$; where every type is a subtype of $\\top$, and no type is a subtype of $\\bot$.\n\n\\begin{itemize}\n\t\\item $\\top$: any type\n\t\\item $\\bot$: inconsistent type\n\\end{itemize}\n\nIn the primitive type lattice of TIE (see figure \\ref{fig:primitive_type_lattice}) for instance, both signed and unsigned 32-bit integers (\\texttt{int32} and \\texttt{uint32}, respectively) are subtypes of 32-bit integers (\\texttt{num32}) \\cite{tie_reverse_engineering_of_types}.\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.40\\textwidth]{inc/tie_primitive_type_lattice.png}\n\t\\caption{Primitive type lattice of TIE.}\n\t\\label{fig:primitive_type_lattice}\n\\end{figure}\n\nIn the context of type recovery, a type lattice may be used to specify the set of possible types for a variable through upper and lower bounds; thus imposing type constraints on the variable.\n", "meta": {"hexsha": "9ba7e09ccfdfe623ac9cfbbb8addd2d716e54115", "size": 1120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/type_analysis/sections/2_background/2_type_lattice.tex", "max_stars_repo_name": "decomp/doc", "max_stars_repo_head_hexsha": "fb82b6a5074aa8721afb24a5537bf1964ed20467", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-05-27T10:16:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T08:14:04.000Z", "max_issues_repo_path": "report/type_analysis/sections/2_background/2_type_lattice.tex", "max_issues_repo_name": "decomp/doc", "max_issues_repo_head_hexsha": "fb82b6a5074aa8721afb24a5537bf1964ed20467", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 48, "max_issues_repo_issues_event_min_datetime": "2019-01-30T19:08:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-29T19:17:53.000Z", "max_forks_repo_path": "report/type_analysis/sections/2_background/2_type_lattice.tex", "max_forks_repo_name": "decomp/doc", "max_forks_repo_head_hexsha": "fb82b6a5074aa8721afb24a5537bf1964ed20467", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-05-25T21:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-09T07:36:14.000Z", "avg_line_length": 50.9090909091, "max_line_length": 278, "alphanum_fraction": 0.7241071429, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.6822971151675595}}
{"text": "\\subsection{2018 Free-Response Questions}\r\nQuestions 1 and 2 are part of the same section and are allotted 30 minutes for completion with the aid of a graphing calculator.\r\nQuestion 3 through 6 are part of the same section are allotted 1 hour for completion without the aid of a graphing calculator.\r\n\r\n\\begin{enumerate}\r\n\t\\item People enter a line for an escalator at  rate modeled by the function $r$ given by\r\n\t\\begin{equation*}\r\n\t\tr(t) = \\begin{cases}\r\n\t\t\t44\\left(\\frac{t}{100}\\right)^3\\left(1-\\frac{t}{300}\\right)^7 & \\text{for } 0 \\leq t \\leq 300 \\\\\r\n\t\t\t0 & \\text{for } t > 300,\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\twhere $r(t)$ is measured in people per scond and $t$ is measured in seconds.\r\n\tAs people get on to the escalator, they exit the line at a rate of 0.7 person per second,\r\n\tThere are 20 people in line at time $t=0$.\r\n\t\\begin{enumerate}\r\n\t\t\\item How many people entered the line for the escalator during the time interval $0 \\leq t \\leq 300$?\r\n\t\t\\item During the time interval $0 \\leq t \\leq 300$, there are always people in line for the escalator.\r\n\t\t\tHow many people are in line at time $t=300$?\r\n\t\t\\item For time $t > 300$, what is the first time $t$ that there are no people in line for the escalator?\r\n\t\t\\item For time $0 \\leq t \\leq 300$, at what time $t$ is the number of people in line at a minimum?\r\n\t\t\tTo the nearest whole number, find the number of people in line at this time.\r\n\t\t\tJustify your answer.\r\n\t\\end{enumerate}\r\n\r\n\t\\item Researchers on a boat are investigating plankton cells in a sea.\r\n\t\tAt a depth of $h$ meters, the density of plankton cells, in millions of cells per cubic meter, is modeled by $p(h) = 0.2h^2e^{-0.0025h^2}$ for $0 \\leq h \\leq 30$ and is modeled by $f(h)$ for $h\\geq 30$.\r\n\t\tThe continuous function $f$ is not explicitly given.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find $p^\\prime(25)$.\r\n\t\t\t\tUsing correct units, interpret the meaning of $p^\\prime(25)$ in the context of the problem.\r\n\t\t\t\\item Consider a vertical column of water in this sea with horizontal cross sections of constant area 3 square meters.\r\n\t\t\t\tTo the nearest million, how many plankton cells are in this column of water between $h=0$ and $h=30$ meters?\r\n\t\t\t\\item There is a function $u$ such that $0 \\leq f(h) \\leq u(h)$ for all $h \\geq 30$ and $\\int_{30}^{\\infty}{u(h)\\d{h}} = 105$.\r\n\t\t\t\tThe column of water in part (b) is $K$ meters deep, where $K > 30$.\r\n\t\t\t\tWrite an expression involving one or more integrals that gives the number of plankton cells in the entire column.\r\n\t\t\t\tExplain why this number of plankton cells is less than or equal to 2000 million.\r\n\t\t\t\\item The boat is moving on the surface of the sea.\r\n\t\t\t\tAt time $t \\geq 0$, the position of the boat is $(x(t),y(t))$, where $x^\\prime(t) = 662\\sin{(5t)}$ and $y^\\prime(t)=880\\cos{(6t)}$.\r\n\t\t\t\tTime $t$ is measured in hours, and $x(t)$ and $y(t)$ are measured in meters.\r\n\t\t\t\tFind the total distance traveled by the boat over the time interval $0 \\leq t \\leq 1$.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\t\\begin{figure}[H]\r\n\t\t\t\\label{2018_3}\r\n\t\t\t\\centering\r\n\t\t\t\\includegraphics[width=0.5\\textwidth]{./additional_materials/2018_3.png}\r\n\t\t\t\\caption{\\hyperref{https://apcentral.collegeboard.org/pdf/ap18-frq-calculus-bc.pdf}{}{}{AP Calculus BC 2018 Exam Free-Response Question 3, Graph of $g$}}\r\n\t\t\\end{figure}\r\n\t\r\n\t\\item\r\n\t\tThe graph of the continuous function $g$, the derivative of a function $f$, is shown above.\r\n\t\tThe function $g$ is piecewise linear for $-5 \\leq x < 3$ and $g(x)=2(x-4)^2$ for $3 \\leq x \\leq 6$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item If $f(1)=3$, what is the value of $f(-5)$?\r\n\t\t\t\\item Evaluate $\\int_{1}^{6}{g(x)\\d{x}}$.\r\n\t\t\t\\item For $-5 < x < 6$, on what open intervals, if any, is the graph of $f$ both increasing and concave up?\r\n\t\t\t\tGive a reason for your answer.\r\n\t\t\t\\item Find the $x$-coordinate of each point of inflection of the graph of $f$.\r\n\t\t\t\tGive a reason for your answer.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\t\\begin{table}[H]\r\n\t\t\t\\begin{center}\r\n\t\t\t\t\\begin{tabular}{|c||c|c|c|c|c|}\r\n\t\t\t\t\t\\hline\r\n\t\t\t\t\t$t$ (years) & 2 & 3 & 5 & 7 & 10 \\\\\r\n\t\t\t\t\t\\hline\r\n\t\t\t\t\t$H(t)$ (meters) & 1.5 & 2 & 6 & 11 & 15 \\\\\r\n\t\t\t\t\t\\hline\r\n\t\t\t\t\\end{tabular}\r\n\t\t\t\\end{center}\r\n\t\t\\end{table}\r\n\t\r\n\t\\item The height of a tree at time $t$ is given by a twice-differentiable function $H$, where $H(t)$ is measured in meters and $t$ is measured in years.\r\n\t\tSelected values of $H(t)$ are given in the table above.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Use the data in the table to estimate $H^\\prime(6)$.\r\n\t\t\t\tUsing correct units, interpret the meaning of $H^\\prime(6)$ in the context of the problem.\r\n\t\t\t\\item Explain why there must be at least one time $t$, for $2 \\leq t \\leq 10$ such that $H^\\prime(t) = 2$.\r\n\t\t\t\\item Use a trapezoidal sum with 4 subintervals indicated by the data in the table to approximate the average height of the tree over the time interval $2 \\leq 2 \\leq 10$.\r\n\t\t\t\\item The height of the tree, in meters, can also be modeled by the function $G$, given by $G(x)=\\frac{100x}{1+x}$, where $x$ is the diameter of the base of the tree, in meters.\r\n\t\t\t\tWhen the tree is 50 meters tall, the diameter of the base of the tree is increasing at a rate of 0.03 meters per year.\r\n\t\t\t\tAccording to this model, what is the rate of the change of the height of the tree with respect to time, in meters per year, at the time when the tree is 50 meters tall?\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{2018_5}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width=0.5\\textwidth]{./additional_materials/2018_5.png}\r\n\t\t\\caption{\\hyperref{https://apcentral.collegeboard.org/pdf/ap18-frq-calculus-bc.pdf}{}{}{AP Calculus BC 2018 Exam Free-Response Question 5}}\r\n\t\\end{figure}\r\n\t\r\n\t\\item The graph of the polar curves $r=4$ and $r=3+2\\cos{\\theta}$ are shown in the figure above.\r\n\t\tThe curves intersect at $\\theta = \\frac{\\pi}{3}$ and $\\theta = \\frac{5\\pi}{3}$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Let $R$ be the shaded region inside the graph of $r=4$ and outside the graph of $r=3+2\\cos{\\theta}$, as shown in the figure above.\r\n\t\t\t\tWrite an expression involving an integral for the area of $R$.\r\n\t\t\t\\item Find the slope of the line tangent to the graph $r=3+2\\cos{\\theta}$ at $\\theta = \\frac{\\pi}{2}$.\r\n\t\t\t\\item A particle moves along the portion of the curve  $r=3+2\\cos{\\theta}$ for $0 < \\theta < \\frac{\\pi}{2}$.\r\n\t\t\t\tThe particle moves in such a way that the distance between the particle and the origin increases at a constant rate of 3 units per second.\r\n\t\t\t\tFind the rate at which the angle $\\theta$ changes with respect to time at the instant when the position of the particle corresponds to $\\theta = \\frac{\\pi}{3}$.\r\n\t\t\t\tIndicate units of measure.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\item The Maclaurin series for $\\ln{(1+x)}$ is given by\r\n\t\t\\begin{equation*}\r\n\t\t\tx - \\frac{x^2}{2} + \\frac{x^3}{3} - \\frac{x^4}{4} + \\ldots + (-1)^{n+1}\\frac{x^n}{n} + \\ldots .\r\n\t\t\\end{equation*}\r\n\t\tOn its interval of convergence, this series converges to $\\ln{(1+x)}$.\r\n\t\tLet $f$ be a function defined by $f(x) = x\\ln{\\left(1+\\frac{x}{3}\\right)}$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Write the first four nonzero erms and the general term of the Maclaurin series for $f$.\r\n\t\t\t\\item Determine the interval of convergence for $f$.\r\n\t\t\t\tShow the work that leads to your answer.\r\n\t\t\t\\item Let $P_4(x)$ be the fourth-degree Taylor polynomial for $f$ about $x=0$.\r\n\t\t\t\tUse the alternating series estimation bound to find an upper bound for $\\abs{P_4(2)-f(2)}$.\r\n\t\t\\end{enumerate}\r\n\t\r\n\\end{enumerate}", "meta": {"hexsha": "44f2fbcb8efee5e380c6e4a9cf8d95eb974afd0a", "size": 7413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/additional_materials/2018_questions.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/2018_questions.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/2018_questions.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.775, "max_line_length": 205, "alphanum_fraction": 0.6743558613, "num_tokens": 2374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.6822819444068033}}
{"text": "\\documentclass{article}\n\n\\usepackage[margin=.25in, letterpaper]{geometry}\n\n\\usepackage{siunitx}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{mathtools}\n\\usepackage{multicol}\n\\usepackage{enumitem}\n\\usepackage{scrextend}\n\\usepackage{microtype}\n\\usepackage{mathrsfs}\n\\usepackage{booktabs}\n\n\\theoremstyle{remark}\n\\newtheorem{example}{Example}[section]\n\\newtheorem*{solution}{Solution}\n\n\\begin{document}\n\n\\section{Probability}\n\\begin{align*}\n    P[A|B] & = \\frac{P[B|A] P[A]}{P[B]} \\\\\n           & = \\frac{P[A \\cap B]}{P[B]}\n\\end{align*}\n\n\\begin{align*}\n    P[A \\cap B]                      & =P[A] P[B|A]  \\\\\n                                     & = P[B] P[A|B] \\\\\n    \\text{(A and B are independent)} & = P[A] P[B]\n\\end{align*}\n\n\\[\n    P[A \\cup B] = P[A] + P[B] - P[A \\cap B]\n\\]\n\n\\[\n    P[A \\cup B \\cup C] = P[A] + P[B] + P[C] - P[A \\cap B] - P[B \\cap C] - P[A \\cap C] + P[A \\cap B \\cap C]\n\\]\n\n\\begin{align*}\n    P[A] & = P[A \\cap B_1] + P[A \\cap B_2] + \\cdots + P[A\\cap B_n]       \\\\\n         & = P[A|B_1] P[B_1]+ P[A|B_2] P[B_2] + \\cdots + P[A|B_n] P[B_n]\n\\end{align*}\n\n\\[\n    P[A^C | B] = 1 - P[A|B]\n\\]\n\n\\(k\\) samples, \\(n\\) objects\n\n\\begin{table}[!htbp]\n    \\centering\n    \\begin{tabular}{ c c }\n        \\toprule\n        Action                         & Equation                                      \\\\\n        \\midrule\n        With replacement               & \\(nk\\)                                        \\\\\n        Without Replacement            & \\(\\frac{n!}{(n-k)!} = nPk = {(n)}_k\\)         \\\\\n        Without Replacement, unordered & \\(\\frac{n!}{(n-k)!k!} = nCk = {n \\choose k}\\) \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}\n\n\\section{Random Values}\n\n\\begin{multicols*}{2}\n    \\subsection{PMF CDF PDF}\n\n    PMF (Discrete):\\@\n    \\begin{itemize}\n        \\item \\(P_X(x) = P[X = x]\\)\n        \\item \\(P_X(x) \\geq 0, \\forall x\\)\n        \\item \\(\\sum_{x\\in S_X} P_X(x) = 1\\)\n        \\item \\(P[B] = \\sum_{x\\in B} P_X(x)\\)\n    \\end{itemize}\n\n    CDF (Discrete):\\@\n    \\begin{itemize}\n        \\item \\(F_X(a) = P[X \\leq a]\\)\n        \\item \\(F_X(-\\infty) = 0,  F_X(\\infty) = 1\\)\n        \\item \\(a_i \\geq a_j \\rightarrow F_X(a_i) \\geq F_X(a_j)\\)\n        \\item \\(\\lim_{\\epsilon \\rightarrow 0} F_X(a_i) - F_X(a_i - \\epsilon) = P_X(a_i)\\)\n    \\end{itemize}\n\n    CDF (Continuous):\\@\n    \\begin{itemize}\n        \\item \\(F_X(x) = P[X \\leq x]\\)\n        \\item \\(F_X(-\\infty) = 0,  F_X(\\infty) = 1\\)\n        \\item \\(x_1 < x_2 \\rightarrow F_X(x_1) \\leq F_X(x_2)\\)\n        \\item \\(P_[x_1 < X \\leq x_2] = F_X(x_2) - F_X(x_1)\\)\n        \\item \\(P[X\\leq x_1] = P[X < x_1]\\)\n    \\end{itemize}\n\n    PDF (Continuous):\\@\n    \\begin{itemize}\n        \\item \\(f_X(x) = \\frac{d}{dx} F_X(x)\\)\n        \\item \\(f_X(x) \\geq 0\\)\n        \\item \\(F_X(x) = \\int_{-\\infty}^x f_X(u) du\\)\n        \\item \\(\\int_{-\\infty}^{\\infty} f_X(x) = 1\\)\n        \\item \\(P[x_1 < X \\leq x_2] = \\int_{x_1}^{x_2} f_X(x)dx\\)\n    \\end{itemize}\n\n    \\subsection{Expected Value and Variance}\n    \\(E[X]\\)\n    \\begin{itemize}\n        \\item \\(E[X] = \\sum_{x\\in S_X} xP_X(x) = \\mu_X\\)\n        \\item \\(E[g(X)] = \\sum_{x\\in S_X} g(x) P_X(x) \\)\n        \\item \\(E[aX + b] = a E[X] + b\\)\n    \\end{itemize}\n    \\(Var[X]\\)\n    \\begin{itemize}\n        \\item \\(Var[X] = \\sigma^2_X = E[{(X-\\mu_X)}^2] = E[X^2] - {(E[X])}^2\\)\n        \\item \\(Var[aX+b] = a^2 Var[X]\\)\n    \\end{itemize}\n\\end{multicols*}\n\nDiscrete RV:\\@\n\\begin{table}[!htbp]\n    \\centering\n    \\begin{tabular}{ c c c c c }\n        \\toprule\n        Name                & Use                                  & PMF \\(P_X(i)\\)                      & E[X]        & Var[X]                      \\\\\n        \\midrule\n        Bernoulli\\((p)\\)    & Two Outcomes                         & \\((p, x=1),(1-p, x=0)\\)             & \\(p\\)       & \\(p(1-p)\\)                  \\\\\n        Geometric\\((p)\\)    & Bernoulli until first success        & \\({(1-p)}^{i-1}p\\)                  & \\(1/p\\)     & \\((1-p)/p^2\\)               \\\\\n        Binomial\\((n, p)\\)  & Successes in sequence of N Bernoulli & \\((nCi) p^i {(1-p)}^{n-i}\\)         & \\(np\\)      & \\(np(1-p)\\)                 \\\\\n        Pascal\\((k,p)\\)     & Trials until n success               & \\((i - 1 C k-1) p^k {(1-p)}^{i-k}\\) & \\(k/p\\)     & \\(k(1-p)/p^2\\)              \\\\\n        Poisson\\((\\alpha)\\) & Events in time                       & \\( (\\alpha ^i e^{-\\alpha})/i! \\)    & \\(\\alpha \\) & \\(\\alpha \\)                 \\\\\n        Uniform\\((l,k)\\)    & Always same                          & \\(1/(k-l + 1)\\)                     & \\((k+l)/2\\) & \\(\\frac{(k-l)(k-1+2)}{12}\\) \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}\n\nContinuous RV:\\@\n\\begin{table}[!htbp]\n    \\centering\n    \\begin{tabular}{ c c c c c }\n        \\toprule\n        Name                        & PDF \\(f_X(x)\\)                                                        & CDF  \\(F_X(x)\\)      & E[X]                  & Var[X]                   \\\\\n        \\midrule\n        Uniform\\((a,b)\\)            & \\(1/(b-a)\\)                                                           & \\(\\frac{x-a}{b-a}\\)  & \\((b+a)/2\\)           & \\(\\frac{{(b-a)}^2}{12}\\) \\\\\n        Exponential\\((\\lambda)\\)    & \\(\\lambda e^{-\\lambda x}\\)                                            & \\(1-e^{-\\lambda a}\\) & \\(\\frac{1}{\\lambda}\\) & \\(\\frac{1}{\\lambda^2}\\)  \\\\\n        Gaussian\\((\\mu, \\sigma^2)\\) & \\(\\frac{1}{\\sqrt{2\\pi \\sigma^2}}e^{-\\frac{{(x-\\mu )}^2}{2\\sigma^2}}\\) & \\(\\phi(a)\\)          & \\(\\mu \\)              & \\(\\sigma ^2\\)            \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}\n\nNormalization:\n\\[\n    Z = \\frac{X-\\mu}{\\sigma}\n\\]\n\\end{document}\n", "meta": {"hexsha": "484638d271c56f75647a43780407a12b67dc9f13", "size": 5556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/ECE342FinalCheatsheet.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": "CheatSheets/ECE342FinalCheatsheet.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": "CheatSheets/ECE342FinalCheatsheet.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": 35.8451612903, "max_line_length": 184, "alphanum_fraction": 0.4132469402, "num_tokens": 2012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926007, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.6822819296296212}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 15.2 Cumulative Distribution Function and Percentage Points\n\\hbox{for Normal Probability Distribution}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThe procedures described in this chapter compute the Cumulative Distribution\nFunction (CDF) and the percentage points of the Normal or Gaussian\ndistribution. The CDF is sometimes called the lower tail. The lower tail,\nor CDF, $g(x;\\mu ,\\sigma )$, and the upper\ntail, $h(x;\\mu ,\\sigma )$ for the Normal probability distribution with mean $%\n\\mu $ and standard deviation $\\sigma $ are defined by%\n\\begin{gather*}\n\\hspace{-15pt}g(x;\\mu ,\\sigma )=\\frac 1{\\sigma \\sqrt{2\\pi }}\\int_{-\\infty }^x\\!\\!\\exp\n\\!\\left( -\\frac{(t-\\mu )^2}{2\\sigma ^2}\\right) dt,\\rule{50pt}{0pt}\\\\\n\\hspace{-15pt}h(x;\\mu ,\\sigma )=\\frac 1{\\sigma \\sqrt{2\\pi }}\\int_x^\\infty \\!\\!\\exp\n\\!\\left( -\\frac{(t-\\mu )^2}{2\\sigma ^2}\\right) dt=g(-x;\\mu ,\\sigma )\n\\end{gather*}\nThe percentage point of a distribution is the value of $x$ that gives the\nlower tail a specified value. In this case, the problem is to compute $x$\ngiven $u = g(x;\\mu ,\\sigma )$, $\\mu $ and $\\sigma $, that is, compute $x =\ng^{-1}(u;\\mu ,\\sigma ).$\n\n\\subsection{Usage}\n\n\\subsubsection{Cumulative Distribution Function}\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf U, X, MU, SIGMA, SCDNML}\n\n\\item[EXTERNAL]  \\ {\\bf SCDNML}\n\\end{description}\n\nAssign values to X, MU and SIGMA and obtain U $= g(x;\\mu ,\\sigma )$ by using\n$$\n\\fbox{{\\bf U = SCDNML(X, MU, SIGMA)}}\n$$\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[X]  \\ [in] Argument $x$ of the function $g(x;\\mu ,\\sigma ).$\n\n\\item[MU]  \\ [in] Parameter $\\mu $ of the function $g(x;\\mu ,\\sigma ).$\n\n\\item[SIGMA]  \\ [in] Parameter $\\sigma $ of the function $g(x;\\mu ,\\sigma ).$\n\\end{description}\n\n\\subsubsection{Percentage Points}\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf U, X, MU, SIGMA, SPPNML}\n\n\\item[EXTERNAL]  \\ {\\bf SPPNML}\n\\end{description}\n\nAssign values to U, MU and SIGMA and obtain X $= g^{-1}(u;\\mu ,\\sigma )$ by\nusing\n$$\n\\fbox{{\\bf X = SPPNML(U, MU, SIGMA)}}\n$$\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[U]  \\ [in] Argument $u$ of the function $g^{-1}(u;\\mu ,\\sigma ).$\nRequire $0.0 \\leq \\text{U} \\leq 1.0.$\n\n\\item[MU]  \\ [in] Parameter $\\mu $ of the function $g^{-1}(u;\\mu ,\\sigma ).$\n\n\\item[SIGMA]  \\ [in] Parameter $\\sigma $ of the function $g^{-1}(u;\\mu\n,\\sigma ).$\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double precision computation, change the REAL type statement to\nDOUBLE PRECISION and change the initial letter of the function names to D.\nSince these functions are not generic intrinsic functions, it is important\nto declare them explicitly to be DOUBLE PRECISION, because the default\nimplicit type would be REAL.\n\n\\subsection{Example and Remarks}\n\nSee DRDCDNML and ODDCDNML for an example of the usage of these subprograms.\n\n\\subsection{Functional Description}\n\n\\subsubsection{Method}\n\nTo avoid cancellation error when $x-\\mu << 0$, the identity $g(x;\\mu\n,\\sigma) = \\frac 12 \\erfc ((\\mu - x)/\\sigma \\sqrt 2)$ is used.  This\nexpression never causes more cancellation error than mathematically\nequivalent alternatives, so it is used for all allowed values of $x$,\n$\\mu $, and $\\sigma $ (see Section E for restrictions). The procedure\nSERFC described in Chapter~2.2 is used to\nevaluate $\\erfc ((\\mu - x)/\\sigma \\sqrt 2).$\n\nTo compute the percentage points, invert the last expression to compute $x =\ng^{-1}(u;\\mu ,\\sigma ) = \\mu - \\sigma \\sqrt 2$\\ erfc$^{-1}(2u)$. The\nprocedure SERFCI described in Chapter~2.13 is used to evaluate erfc$%\n^{-1}(2u).$\n\n\\subsubsection{Accuracy Tests}\n\nSee Sections 2.2.D and~2.13.D.\n\n\\subsection{Error Procedures and Restrictions}\n\nThe procedure SERFC issues a warning message by way of the error message\nprocessor described in Chapter~19.2 if (X $-$ MU)/($\\sqrt{2.0}\\ \\times $\nSIGMA) $< -xmax$. The value of $xmax$ depends on the system and the precision.\nLet $t=\\sqrt {-\\log(\\sqrt \\pi f)}$ where $f$ is the underflow limit\nprovided by R1MACH(1) or D1MACH(1) of Chapter~19.1.  Then $xmax = t\n- ((\\log \\,t)/t) - 0.01.$ For example, $xmax \\approx 9.18$ (26.5) for single\n(double) precision IEEE arithmetic.  The procedure SERFCI issues an error\nmessage at level 2 by way of the error message processor described in\nChapter~19.2 if U $< 0.0 $ or U $> 1.0.$\n\\subsection{Supporting Information}\n\nDesigned and programmed by W. V. Snyder, JPL, 1993.\n\n\\pagebreak\n%\\rule[-50pt]{0pt}{10pt}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDCDNML & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DCSEVL, DERF, DERM1, DERV1, DINITS, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDPPNML & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERFI, DERM1, DERV1, DPPNML, ERFIN, ERMSG\\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} \\\\\nSCDNML & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, IERM1, IERV1, SCSEVL, SERF, SERM1, SERV1, SINITS\\rule[-5pt]{0pt}{8pt}}\\\\\nSPPNML & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERFI, SERM1, SERV1, SPPNML}\\\\\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 DRDCDNML}\\vspace{5pt}\n\\lstinputlisting{\\codeloc{dcdnml}}\n\n\\vspace{15pt}\\centerline{\\bf \\large ODDCDNML}\\vspace{5pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dcdnml}}\n\\end{document}\n", "meta": {"hexsha": "50580b165902a5f03468383b0a2a1561afd25063", "size": 5824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch15-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/ch15-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/ch15-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": 35.950617284, "max_line_length": 98, "alphanum_fraction": 0.7019230769, "num_tokens": 1965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.6822819241678518}}
{"text": "\\section{表达式处理}\n\n\\begin{minted}{c++}\nbool shouldPopFromStack(char current, char fromStack) {\n    int p1 = (current == '*' || current == '/') ? 1 : 0;\n    int p2 = (fromStack == '*' || fromStack == '/') ? 1 : 0;\n    return p1 <= p2;\n}\nstring convert(string raw) {\n    int length = raw.length();\n    stack<char> s;\n    string res = \"\";\n    for (int i = 0; i < length; i++) {\n        if (raw[i] >= '0' && raw[i] <= '9') {\n            res += raw[i];\n            continue;\n        }\n        else\n            res += ' ';\n        if (raw[i] == '(')\n            s.push('(');\n        else if (raw[i] == ')')  {\n            while (true) {\n                char now = s.top();\n                s.pop();\n                if (now == '(')\n                    break;\n                else\n                    res += now;\n            }\n        }\n        else {\n            if (s.empty())\n                s.push(raw[i]);\n            else {\n                while (!s.empty()) {\n                    char now = s.top();\n                    if (now == '(' || !shouldPopFromStack(raw[i], now))\n                        break;\n                    else {\n                        s.pop();\n                        res += now;\n                    }\n                }\n                s.push(raw[i]);\n            }\n        }\n    }\n    res += ' ';\n    while (!s.empty()) {\n        char now = s.top();\n        s.pop();\n        res += now;\n    }\n    return res;\n}\nint main() {\n    /* ... */\n    stack<long long> s;\n    int length = res.length();\n    long long cur = 0;\n    for (int i = 0; i < length; i++) {\n        if (res[i] >= '0' && res[i] <= '9') {\n            cur = cur * 10 + res[i] - '0';\n        } else if (res[i] == ' ') {\n            s.push(cur);\n            cur = 0;\n        }\n        else {\n            long long s2 = s.top();\n            s.pop();\n            long long s1 = s.top();\n            s.pop();\n            switch (res[i]) {\n                case '+':\n                    s.push(s1 + s2);\n                    break;\n                case '-':\n                    s.push(s1 - s2);\n                    break;\n                case '*':\n                    s.push(s1 * s2);\n                    break;\n                case '/':\n                    s.push(s1 / s2);\n                    break;\n            }\n        }\n    }\n    /* ... */\n}\n\\end{minted}", "meta": {"hexsha": "4ce35bb8bbd44d7e9d2b13848865d3474319e2b7", "size": 2329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch11-uncategorized/expression.tex", "max_stars_repo_name": "kirainmoe/algorithm-library", "max_stars_repo_head_hexsha": "c84bfa1143a00acd9a83071c0b2b8a76235b587b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-03-14T19:43:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-11T21:14:11.000Z", "max_issues_repo_path": "chapters/ch11-uncategorized/expression.tex", "max_issues_repo_name": "kirainmoe/oi-algorithm-library", "max_issues_repo_head_hexsha": "c84bfa1143a00acd9a83071c0b2b8a76235b587b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-14T01:34:52.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T01:34:52.000Z", "max_forks_repo_path": "chapters/ch11-uncategorized/expression.tex", "max_forks_repo_name": "kirainmoe/oi-algorithm-library", "max_forks_repo_head_hexsha": "c84bfa1143a00acd9a83071c0b2b8a76235b587b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-08-29T05:31:31.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T16:55:55.000Z", "avg_line_length": 25.3152173913, "max_line_length": 71, "alphanum_fraction": 0.2979819665, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6822507765752595}}
{"text": "\\chapter{Local polynomial regression}\n\\section{Different bandwidths and kernels}\nThis exercise is about a method for non-parametric regression called local polynomial regression (LPR). It is a generalisation of the kernel based Nadaraya-Watson estimator, similar to the kernel density estimation in Exercise 6. The Nadaraya-Watson estimator is a local weighted mean estimation. The local polynomial regression estimation for $(X_1,Y_1),...,(X_n,Y_n)\\stackrel{iid}{\\sim}(X,Y)$ and the model $$Y_i=f(X_i)+\\varepsilon_i, \\; \\varepsilon_i \\stackrel{iid}{\\sim}\\left\\langle0,\\sigma^2\\right\\rangle$$ is derived by a Taylor approximation of the function $f$. \n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=0.8\\textwidth, keepaspectratio]{ex9/polyfits.png}\n\\caption{First: Age against Z-score in the Kenyan children data. Second row: LPR fit with different bandwidths and Epanechnikov kernel. Third: LPR fit with different kernels and fixed bandwidth $h=10$.}\n\\label{7fits}\n\\end{figure}\n\nWe apply this method to the data of Kenyan children already used in Exercise 1. We want to fit a curve for the Z-score for wasting (\\texttt{zwast}) against age. This Z-score is a transformation of a child's weight standardised by the median and standard deviation of the weight of healthy children with the same height. We wrote our own function for fitting a local polynomial curve with data, bandwidth, kernel and polynomial order as arguments. To examine the influence of argument choice we again fitted a curve for different bandwidths and the same kernels as in Exercise 6 with a fixed order 1 polynomial regression (see Figure \\ref{7fits}).\n\nWe see similar results as in Exercise 6. With increasing bandwidth the curve gets smoother. With a bandwidth of 1 the fit represents the data rather locally. With $h=2$ some of the fluctuations are flattened out and with increasing bandwidth the curve converges to the constant mean of the data (see blue line). I took 40 as the highest bandwidth here to demonstrate this fact. A reasonable choice seems to be $h=10$ since there the functions looks pretty smooth but still represents the first drop of the Z-score and the slight increase and convergence afterwards that we see in the scatter plot in Figure \\ref{7fits}. Then using this bandwidth we were asked to fit the curve for different kernels. Like in Exercise 6 again we see that the Gaussian kernel produces the most flat curve. Indeed it looks quite similar to the fit for the Epanechnikov kernel with an astonishing high bandwidth compared to the one used here. The fits for the triangular and Epanechnikov kernel don't differ obviously. The red line representing the fit for the rectangular kernel seems piecewise linear which is quite natural as the kernel is piecewise constant and we used a LPR of order 1 (i.e. using linear polynomials) in all these plots.  \n\n\\section{Generalised cross-validation}\nSimilar to the cross-validation method in Exercise 6 there is a generalised version for LPR we want to use here to find the best bandwidth for different polynomial degrees. The generalised cross-validation criterion (GCV) is given by $$GCV(h)=\\frac{\\sum_{i=1}^{n}{\\left[Y_i-\\hat{f}_{n,h}(X_i)\\right]^2}}{1-n^{-1}\\sum_{i=1}^{n} W_{i}(X_i,h)}$$ where $W_i$ are the weights of the different observations for the linear generalised least square estimation used to compute the parameters. This time we used only the Epanechnikov kernel to search for the minimal GCV. Again we have the same problem - like in Exercise 6 - that the GCV curve is not unimodal and thus optimize won't find the global minimum (see Figure \\ref{7opth}). \n\\begin{figure}[!bht]\n\\centering\n\\includegraphics[width=0.8\\textwidth, keepaspectratio]{ex9/opth.png}\n\\caption{GCV against $h$. Points show optimal $h$ for the scan over 30 points (blue) and the \\texttt{optimize} function (red).}\n\\label{7opth}\n\\end{figure}\n\nWe therefore use a scanning strategy only to get the optimal bandwidths. The results are shown in Table \\ref{7tableh}. We see that the results for degree 2 and 3 are identical (rounded to two digits) and similar to the results for degree 4 whereas for degree 1 a lower bandwidths seems the best option. The degree 4 fit gives the highest GCV indicating a worse fit.\n\\begin{table}[!ht]\n\\centering\n\\begin{tabular}{lrr}\n  \\hline\ndeg & h & GCV \\\\ \n  \\hline\n1 & 1.44 & 6517.30 \\\\ \n  2 & 3.19 & 6518.00 \\\\ \n  3 & 3.19 & 6518.00 \\\\ \n  4 & 3.06 & 6522.78 \\\\ \n   \\hline\n\\end{tabular}\n\\caption{Optimal bandwidth $h$ together with minimal GCV for different polynmial degrees (deg).}\n\\label{7tableh}\n\\end{table}\n\nNow have a look at the fitted curves (see Figure \\ref{7fitsh}). The curves don't differ but look very similar. This is especially surprising since the optimal bandwidth for degree 1 is much lower than for the other curves. But with higher polynomial degree the regression as more degrees of freedom (i.e. more parameters) to adapt to the data. This would explain why all three curves look like a very local fit. On the left border all three curves decrease as age tends to 0. This does not seem reasonable since the shape of the data suggests that the Z-score is very high at birth and decreases rapidly in the first months. This is one disadvantage of local non-parametric regressions, that in general at the border and outside of the observed data range the prediction is not valid and thus generalisations difficult. Finally note, that the curves in Figure \\ref{7fitsh} look piecewise linear. Indeed in this plot they are drawn since we approximated the regression curves at the data points. One could have generalised the function fitting the curve with an argument $x$ to draw a better approximation with more points but note that one has to fit a linear model for every point then and this would lead to higher computational effort. Still one would recognizes difference in shape in the way the data is presented here. Summing up and looking back to the second plot in Figure \\ref{7fits} using the GCV may not be the best method to find a suitable bandwidth in every case but can result in a - in my opinion - too low bandwidth that results in a more local representation than a reasonable and useful trend analysis of the data.   \n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[width=0.8\\textwidth, keepaspectratio]{ex9/fitsh.png}\n\\caption{LPR fit for different polynomial degrees each with optimal bandwidth according to Table \\ref{7tableh} with Epanechnikov kernel.}\n\\label{7fitsh}\n\\end{figure}\n\n\\section{Estimating derivatives}\nWhen considering the change of a variable over time it may be useful to have a look at the derivative of the curve. The method of LPR provides also an on-the-fly method to estimate the derivatives since it is based on a Taylor expansion of the function. For a regression of the derivatives of the curve we use the R function \\texttt{localpoly.reg} in the package \\texttt{NonpModelCheck}. \n\\begin{figure}[p]\n\\centering\n\\includegraphics[width=\\textwidth, height=0.87\\textheight, keepaspectratio]{ex9/deriv.png}\n\\caption{LPR fits with function \\texttt{localpoly.reg} for different polynomial degrees. First plot: first derivative with optimal bandwidths according to \\ref{7tableh}; Second plot: regression curve with fixed bandwidth $h=10$; Third plot: first derivative with fixed bandwidth $h=10$.}\n\\label{7deriv}\n\\end{figure}\n\nIndeed this function provides all functionality we need for this exercise. The result in the first row Figure \\ref{7deriv} show the derivatives with the optimal bandwidths with respect to GCV we found in the last section. We recognize that the strong fluctuation of the regression function itself, shown in the previous section, is also visible for the derivative with is also highly fluctuating and thus in my opinion not really helpful for a reasonable examination of the change in the Z-score. Especially the values at the borders are very high and don't fit at all to the apparently converging behaviour of the data we see in Figure \\ref{7fits}. Here we would maybe guess that the Z-score is improving since the derivative is positive but because of the high fluctuation we would expect it to decrease shortly afterwards. I decided to use a higher bandwidth again and fit the curve again (see second and third plot in Figure \\ref{7deriv}). I used $h=10$ because it seemed already a reasonable bandwidth in the first section. I included the regression for the actual function and their derivative. Obviously the fluctuation is lower as expected. The fits for degree 3 and 4 still show a slight overfit, especially at the left border. The green and the red line are hard do distinct, so the fit for degree 1 and 2 are very similar. Both start with a negative derivative that tends to 0 and keeps a slightly positive value then. All in all I would conclude that there is a very small improvement of the Z-score at the age of 2 since the red and green curve are slightly above 0 on the right corner of Figure \\ref{7deriv} in the last plot. \n", "meta": {"hexsha": "5af13ee1338064d167432481c6db9ee3764feca7", "size": 8990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex9/ex9.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": "ex9/ex9.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": "ex9/ex9.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": 149.8333333333, "max_line_length": 1640, "alphanum_fraction": 0.7867630701, "num_tokens": 2162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8807970654616711, "lm_q1q2_score": 0.6822507717278348}}
{"text": "% !TEX root = ../master/master.tex\n\n%% Dexter Barrows, 2016\n%% dbarrows.github.io\n\n\n\tMarkov Chain Monte Carlo (MCMC) is a general class of methods designed to sample from the posterior distribution of model parameters \\cite{Andrieu2003}. It is an algorithm used when we wish to fit a model $M$ that depends on some parameter (or more typically vector of parameters) $\\theta$ to observed data $D$. MCMC works by constructing a Markov chain whose stationary distribution converges to desired posterior distribution. The samples drawn using MCMC are used to numerically approximate the stationary distribution, and in turn the posterior \\cite{Andrieu2003}.\n\n\n\\section{Markov Chains}\n\n    Figure [\\ref{fsm}] shows a finite state machine with 3 states $S = \\{x_1, x_2, x_3\\}$.\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=0.8\\linewidth}\n        \\includegraphics[width=0.5\\textwidth]{./images/finitemachine.pdf}\n        \\caption{A finite state machine. States are shown as graph nodes, and the probability of transitioning from one particular state to another is shown as a weighted graph edge. \\cite{Andrieu2003} \\label{fsm}}\n    \\end{figure}\n\n    The transition probabilities can be summarized as a matrix as\n\n    \\begin{equation}\n    \tT = \n\t    \\begin{bmatrix}\n\t        0 & 1 & 0 \\\\\n\t        0 & 0.1 & 0.9 \\\\\n\t        0.6 & 0.4 & 0\n\t    \\end{bmatrix}.\n    \\end{equation}\n\n    The probability vector $\\mu(x^{(1)})$ for a state $x^{(1)}$ can be evolved using $T$ by evaluating $\\mu(x^{(1)})T$, then again by evaluating $\\mu(x^{(1)})T^2$, and so on. If we take the limit as the number of transitions approaches infinity, we find\n\n    \\begin{equation}\n    \t\\lim_{t \\to \\infty} \\mu(x^{(1)})T^t = (27/122, 50/122, 45/122).\n    \\end{equation}\n\n    This indicates that no matter what we pick for the initial probability distribution $\\mu(x^{(1)})$, the chain will always stabilize at the equilibrium distribution.\n\n    This property holds when the chain satisfies the following conditions\n\n    \\begin{itemize}\n        \\item \\textit{Irreducible} Any state A can be reached from any other state B with non-zero probability\n        \\item \\textit{Positive Recurrent} The number of steps required for the chain to reach state A from state B must be finite\n        \\item \\textit{Aperiodic} The chain must be able to explore the parameter space without becoming trapped in a cycle\n    \\end{itemize}\n\n    Note that MCMC sampling generates a Markov chain $(\\theta^{(1)}, \\theta^{(2)},..., \\theta^{(N)})$ that does indeed satisfy these conditions, and uses the chain's equilibrium distribution to approximate the posterior distribution of the parameter space \\cite{Andrieu2003}.    \n\n\n\\section{Likelihood}\n\n    MCMC and similar methods hinge on the idea that the weight or support bestowed upon a particular set of parameters $\\theta$ should be proportional to the probability of observing the data $D$ given the model output using that set of parameters $M(\\theta)$. In order to do this we need a way to evaluate whether or not $M(\\theta)$ is a good fit for $D$; this is done by specifying a likelihood function $\\mathcal{L}(\\theta)$ such that\n\n    \\begin{equation}\n    \t\\mathcal{L}(\\theta) \\propto P(D|\\theta).\n    \\end{equation}\n\n    In frequentist Maximum Likelihood approaches, $\\mathcal{L}(\\theta)$ is searched to find a value of $\\theta$ that maximizes $\\mathcal{L}(\\theta)$, then this $\\theta$ is taken to be the most likely true value. Bayesian approaches take this further by aiming to generate a posterior distribution of likelihood values conditioned on prior information about the parameters and the data -- to not just maximize the likelihood but to also explore the area around it \\cite{Andrieu2003}.\n\n\n\\section{Prior distribution}\n\n    Another significant component of MCMC is the user-specified prior distribution for $\\theta$ or distributions for the individual components of $\\theta$ (priors). Priors serve as a way for us to tell the MCMC algorithm what we think consist of good values for the parameters. Note that if very little is known about the parameters, or we are worried about biasing our estimate of the posterior, we can simply use a a wide uniform distribution. We cannot, however, avoid this problem entirely. Bayesian frameworks, such as MCMC, \\textit{require} priors to be specified; what the user must decide is how strong to make priors.\n\n   \tExceedingly weak priors can prove problematic in some circumstances. In the case of MCMC, weak priors handicap the algorithm in two ways: convergence of the chain may become exceedingly slow, and more pressure is put on the likelihood function to be as good as possible -- it will now be the only thing informing the algorithm of what constitutes a ``good'' set of parameters, and what should be considered poor. In the majority of cases this does not pose as much as a problem as it would appear; if enough samples are drawn, we should still obtain a good posterior estimate. We will only really run into problems if an exceedingly weak prior, such as an unbounded uniform distribution, or another unbounded distribution with a high standard deviation, is specified -- in those cases we may obtain poor posterior estimates if the data are weak \\cite{Andrieu2003}.\n\n\\section{Proposal distribution}\n\n    As part of the MCMC algorithm, when we find a state in the parameter space that is accepted as part of the Markov chain construction process, we need a good way of generating a good next step to try. Unlike basic rejection sampling in which we would just randomly sample from our prior distribution, MCMC attempts to optimise our choices by choosing a step that is close enough to the last accepted step so as to stand a decent chance of also being accepted, but far enough away that it doesn't get ``trapped'' in a particular region of the parameter space.\n\n    This is done through the use of a proposal or candidate distribution. This will usually be a distribution centred around our last accepted step and with a dispersion potential narrower than that of our prior distribution.\n\n    The choice of this distribution is theoretically not of the utmost importance, but in practice becomes important so as to not waste computer time \\cite{Andrieu2003}.\n\n\n\\section{Algorithm}\n\n    Now that we have all the pieces necessary, we can discuss the details of the MCMC algorithm.\n\n    We will denote the previously discussed quantities as\n\n    \\begin{itemize}\n        \\item $p(\\cdot)$ - the prior distribution\n        \\item $q(\\cdot|\\cdot)$ - the proposal distribution\n        \\item $\\mathcal{L}(\\cdot)$ - the Likelihood function\n        \\item $\\mathcal{U}(\\cdot,\\cdot)$ - the uniform distribution\n    \\end{itemize}\n\n    and the define the acceptance ratio, $r$, as\n\n    \\begin{equation}\n    \tr = \\frac{\\mathcal{L}(\\theta^*)p(\\theta^*)q(\\theta^*|\\theta)}{\\mathcal{L}(\\theta)p(\\theta)q(\\theta|\\theta^*)},\n    \\end{equation}\n\n    where $\\theta^*$ is the proposed sample to draw from the posterior, and $\\theta$ is the last accepted sample. This is known as the Metropolis-Hastings rule.\n\n    In the special case of the Metropolis variation of MCMC, the proposal distribution is symmetric, meaning $q(\\theta^*|\\theta) = q(\\theta|\\theta^*)$, and so the acceptance ratio simplifies to\n\n    \\begin{equation}\n    \tr = \\frac{\\mathcal{L}(\\theta^*)p(\\theta^*)}{\\mathcal{L}(\\theta)p(\\theta)}.\n    \\end{equation}\n\n    Algorithm [\\ref{mhmcmc}] shows the Metropolis MCMC algorithm.\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{Initialize $\\theta^{(1)}$}\n\n        \\BlankLine\n\n        \\For{$i = 2:N$}{\n\n            \\BlankLine\n\n            \\tcc{Sample}\n            $\\theta^* \\sim q(\\cdot|\\theta^{(i-1)})$ \\;\n            $u \\sim \\mathcal{U}(0,1)$\n\n            \\BlankLine\n\n            \\tcc{Evaluate acceptance ratio}\n            $r$ $\\gets$ $\\frac{\\mathcal{L}(\\theta^*)p(\\theta^*)}{\\mathcal{L}(\\theta)p(\\theta)}$\n\n            \\BlankLine\n\n            \\tcc{Step acceptance criterion}\n            \\eIf{ $u < \\min\\left\\{ 1 , r \\right\\}$ }{ \n                $\\theta^{(i)} = \\theta^*$\\;\n            }{\n                $\\theta^{(i)} = \\theta^{(i-1)}$\\;\n            }\n        }\n\n        \\BlankLine\n\n        \\tcc{Samples from approximated posterior distribution}\n        \\Output{Chain of samples $(\\theta^{(1)},\\theta^{(2)},...,\\theta^{(N)})$}\n\n        \\BlankLine\n\n        \\caption{Metropolis MCMC \\label{mhmcmc}}\n\n    \\end{algorithm}\n    \n\n    In this way we are ensuring that steps that lead to better likelihood outcomes are likely to be accepted, but steps that do not will not be accepted as frequently. Note that these less ``advantageous'' moves will still occur but that this is by design -- it ensures that as much of the parameter space as possible will be explored but more efficiently than using pure brute force \\cite{Andrieu2003}.\n\n\n\\section{Burn-in}\n\n    One critical aspect of MCMC-based algorithms has yet to be discussed. The algorithm requires an initial starting point $\\theta$ to be selected, but as the proposal distribution is supposed to restrict moves to an area close to the last accepted state, then the posterior distribution will be biased towards this starting point. This issue is avoided through the use of a Burn-in period.\n\n    Burning in a chain is the act of running the MCMC algorithm normally without saving first $M$ samples. As we are seeking a chain of length $N$, the total computation will be equivalent to generating a chain of length $M+N$ \\cite{Andrieu2003}.\n\n\n\\section{Thinning}\n\n    Some models will require very long chains to get a good approximation of the posterior, which will consequently require a non-trivial amount of computer storage. One way to reduce the burden of storing so many samples is by thinning. This involves saving only every $n^{\\text{th}}$ step, which should still give a decent approximate of the posterior (since the chain has time to explore a large portion of the parameter space), but requires less room to store \\cite{Link2012}.\n\n\n\\section{Hamiltonian Monte Carlo}\n\n    The Metropolis-Hastings algorithm has a primary drawback in that the parameter space may not be explored efficiently in some circumstances -- a consequence of the rudimentary proposal mechanism. Instead, smarter moves can be proposed through the use of Hamiltonian dynamics, leading to a better exploration of the target distribution and a potential decrease in overall computational complexity. This algorithm is coined Hamiltonian MCMC (HMC) \\cite{Neal2011}. Prior to the advent of HMC, some work was conducted exploring adaptive step-sizing using MCMC-based methods, but found they lack strong theoretical justification, and can lead to some samples being drawn from an incorrect distribution \\cite{Neal2011}. HMC has in fact existed for nearly the same amount of time as MCMC -- both methods having been developed to model molecular dynamics, with MCMC taking a probabilistic approach and HMC taking a more deterministic one -- but had not received much attention outside its native discipline until recently.\n\n    In the HMC formulation, the parameter estimates are treated as a physical particle exploring a sloped likelihood surface. From physics, we will borrow the ideas of potential and kinetic energy. Here potential energy, or gravity, is analogous to the negative log likelihood of the parameter selection given the data, formally\n\n    \\begin{equation}\n        U(\\theta) = -\\log(\\mathcal{L}(\\theta)p(\\theta)).\n    \\end{equation}\n\n    Kinetic energy will serve as a way to ``nudge'' the parameters along a different moment for each component of $\\theta$. We introduce $n$ auxiliary variables $r = (r_1, r_1,...,r_n)$, where $n$ is the number of components in $\\theta$. Note that the samples drawn for $r$ are not of interest, they are only used to inform the evolution of the Hamiltonian dynamics of the system. We can now define the kinetic energy as\n\n    \\begin{equation}\n        K(r) = \\frac{1}{2} r^T M^{-1} r,\n    \\end{equation}\n\n    where $M$ is an $n \\times n$ matrix. In practice $M$ can simply be chosen as the identity matrix of size $n$, however it can also be used to account for correlation between components of $\\theta$.\n\n    The Hamiltonian of the system is defined as\n\n    \\begin{equation}\n        H(\\theta,r) = U(\\theta) + K(r),\n    \\end{equation}\n\n    where the Hamiltonian dynamics of the combined system can be simulated using the following system of ODEs:\n\n    \\begin{equation}\n        \\begin{array}{rl}\n        \\displaystyle\n            \\dfrac{d\\theta}{dt} & = M^{-1} r \\\\\n            \\dfrac{dr}{dt} & = - \\nabla U(\\theta) .\n        \\end{array}\n    \\end{equation}\n\n    It is tempting to try to integrate this system using the standard Euler evolution scheme, but in practice this leads to instability as it will not preserve the volume of the system. Instead the ``Leapfrog'' scheme is used. This scheme is very similar to Euler scheme, except instead of using a fixed step size $h$ for all evolutions, a step size of $\\epsilon$ is used for most evolutions, with a half step size of $\\epsilon / 2$ for evolutions of $\\frac{dr}{dt}$ at the first step, and last step $L$. In this way the evolution steps ``leapfrog'' over each other while using future values from the other set of steps, leading to the scheme's name.\n\n    The end product of the Leapfrog steps are the new proposed parameters $(\\theta^*,r^*)$. These are either accepted or rejected using a mechanism similar to that of standard Metropolis-Hastings MCMC. Now, however, the acceptance ratio $r$ is defined as\n\n    \\begin{equation}\\label{hmcratio}\n        r = \\exp \\left[ H(\\theta,r) - H(\\theta^*,r^*) \\right],\n    \\end{equation}\n\n    where $(\\theta,r)$ are the last values in the chain. This form of the acceptance ratio comes from the definition of the Hamiltonian as an energy function. If we define the distribution of the total potential energy in the system (known as the canonical distribution) as a function of the Hamiltonian as\n\n    \\begin{equation}\n    \tP(\\theta,r) = \\frac{1}{Z} \\exp (-H(\\theta,r))\n    \\end{equation}\n\n    where $Z$ is a normalizing constant, then taking the ratio of the total potential energy of the proposed step $P(\\theta^*,r^*)$ to the total potential energy in the last accepted step $P(\\theta, r)$, we obtain Equation (\\ref{hmcratio}).\n\n    Together, we have Algorithm [\\ref{hmcmc}].\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{Initialize $\\theta^{(1)}$}\n\n        \\BlankLine\n\n        \\For{$i = 2:N$}{\n\n            \\BlankLine\n\n            \\tcc{Resample moments}\n            \\For{$i = 1:n$}{\n                r(i) $\\gets$ $\\mathcal{N}(0,1)$\n            }\n\n            \\BlankLine\n\n            \\tcc{Leapfrog initialization}\n            $\\theta_0$ $\\gets$ $\\theta^{(i-1)}$ \\;\n            $r_0$ $\\gets$ $r - \\nabla U(\\theta_0) \\cdot \\epsilon / 2$\n\n            \\BlankLine\n\n            \\tcc{Leapfrog intermediate steps}\n            \\For{$j = 1:L-1$}{\n                $\\theta_j$ $\\gets$ $\\theta_{j-1} + M^{-1} r_{j-1} \\cdot \\epsilon$ \\;\n                $r_j$ $\\gets$ $r_{j-1} - \\nabla U(\\theta_j) \\cdot \\epsilon$\n            }\n\n            \\BlankLine\n\n            \\tcc{Leapfrog last steps}\n            $\\theta^*$ $\\gets$ $\\theta_{L-1} + M^{-1} r_{L-1} \\cdot \\epsilon$ \\;\n            $r^*$ $\\gets$ $\\nabla U(\\theta_L) \\cdot \\epsilon / 2 - r_{L-1}$            \n            \\BlankLine\n\n            \\tcc{Evaluate acceptance ratio}\n            $r = \\exp \\left[ H(\\theta^{(i-1)},r) - H(\\theta^*,r^*) \\right]$\n\n            \\BlankLine\n\n            \\tcc{Sample}\n            $u \\sim \\mathcal{U}(0,1)$\n\n            \\BlankLine\n\n            \\tcc{Step acceptance criterion}\n            \\eIf{ $u < \\min\\left\\{ 1 , r \\right\\}$ }{ \n                $\\theta^{(i)} = \\theta^*$\\;\n            }{\n                $\\theta^{(i)} = \\theta^{(i-1)}$\\;\n            }\n        }\n\n        \\BlankLine\n\n        \\tcc{Samples from approximated posterior distribution}\n        \\Output{Chain of samples $(\\theta^{(1)},\\theta^{(2)},...,\\theta^{(N)})$}\n\n        \\BlankLine\n\n        \\caption{Hamiltonian MCMC \\label{hmcmc}}\n\n    \\end{algorithm}\n\n    Note that the parameters $\\epsilon$ and $L$ have to be tuned in order to maintain stability and maximize efficiency, a sometimes non-trivial process utilising trial fitting with candidate values of $\\epsilon$ and $L$ \\cite{Neal2011}. However, some recent algorithms, such as the No U-Turn sampler implemented in RStan, and adaptively select appropriate values automatically during the sampling process \\cite{Hoffman2014}.\n    \n\n\\section{RStan Fitting}\n\n    Here we will examine a test case in which Hamiltonian MCMC will be used to fit a Susceptible-Infected-Removed (SIR) epidemic model to mock infectious count data.\n\n    The synthetic data was produced by taking the solution to a basic SIR ODE model, sampling it at regular intervals, and perturbing those values by adding in observation noise. The SIR model used was outlined in the introduction in Equation [\\ref{sirode}].\n\n    The solution to this system was obtained using the \\verb|ode()| function from the \\verb|deSolve| package. The required derivative array function in the format required by \\verb|ode()| was specified as the gradient in Equation [\\ref{sirode}].\n\n    The true parameter values were set to $\\mathcal{R}_0 = 3.0$, $\\gamma = 0.1$ recoveries/week, $N = 500$ individuals. The initial conditions were set to 5 infectious individuals, 495 people susceptible to infection, and no one had yet recovered from infection and been removed. The system was integrated over $[0,100]$ weeks with infected counts drawn at each integer time step.\n\n    The 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}] shows the system simulation results.\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[width=\\textwidth]{./images/dataplot.pdf}\n        \\caption{True SIR ODE solution infected counts, and with added observation noise. \\label{mcmcdataplot}}\n    \\end{figure}\n\n    The Hamiltonian MCMC model fitting was done using Stan (\\url{http://mc-stan.org/}), a program written in \\verb|C++| that does Baysian statistical inference using Hamiltonian MCMC. Stan's R interface (\\url{http://mc-stan.org/interfaces/rstan.html}) was used to ease implementation.\n\n    Throughout this paper, the explicit Euler integration scheme was used to obtain solutions to our ODE-based models. While this scheme is not the most accurate or efficient one available, it as chosen for its ease of implementation in the required languages and transparency with regards to stochastic processes, which have been added into later models. Using a more advanced integrator such as Runge-Kutta makes it harder to properly specify how stochastic process evolution should be handled, and would have required significantly more implementation work to boot. Hence, we have opted for the lo-fi solution we know will function the way we require.\n\n    In order to use an Explicit Euler-like stepping method, with a step size of one per day, in the later Stan model, the synthetic observation counts were treated as weekly observations in which the counts on the other six days of the week were unobserved.\n\n    Figure [\\ref{traceplot}] shows the traceplot for the the post-burn-in chain data returned by the RStan fitting. We see that the chains are mixing well and convergence has likely been reached.\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=0.8\\linewidth}\n        \\includegraphics[width=\\textwidth]{./images/traceplotR0.pdf}\n        \\caption{Traceplot of samples drawn for parameter $\\mathcal{R}_0$, excluding burn-in. \\label{traceplot}}\n    \\end{figure}\n\n\tFigure [\\ref{traceplot2}] shows the chain data including the burn-in samples. We can see why it is wise to discard these samples (note the scale).\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=0.8\\linewidth}\n        \\includegraphics[width=\\textwidth]{./images/traceplotR0_inc.pdf}\n        \\caption{Traceplot of samples drawn for parameter $\\mathcal{R}_0$, including burn-in. \\label{traceplot2}}\n    \\end{figure}\n\n    Figure [\\ref{hmckernels}] shows the the kernel density estimates for each of the model parameters and the initial number of cases. We see that while the estimates are not perfect, they are more than satisfactory.\n\n    \\begin{figure}\n    \t\\centering\n    \t\\captionsetup{width=0.8\\linewidth}\n        \\begin{subfigure}[tl]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{./images/kernelR0.pdf}\n        \\end{subfigure}\n        \\begin{subfigure}[tr]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{./images/kernelr.pdf}\n        \\end{subfigure}\n        \\begin{subfigure}[bl]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{./images/kernelsigma.pdf}\n        \\end{subfigure}\n        \\begin{subfigure}[br]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{./images/kernelinfec.pdf}\n        \\end{subfigure}\n        \\caption{Kernel density estimates produced by Stan. Dashed lines show true parameter values. \\label{hmckernels}}\n    \\end{figure}", "meta": {"hexsha": "06311e1f7f6ec5a47eb3c19ec5378d109d95fc4e", "size": 21415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writing/MCMC-HMCMC/mcmc-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/MCMC-HMCMC/mcmc-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/MCMC-HMCMC/mcmc-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": 59.8184357542, "max_line_length": 1017, "alphanum_fraction": 0.699416297, "num_tokens": 5355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.6822268104145082}}
{"text": "\n\\section{The \\makeheap algorithm}\n\\Label{sec:makeheap}\n\n\nWhereas in the \\cxx Standard Library \\cite[\\S 28.7.7.3]{cxx-17-draft}\n\\makeheap works on a pair of generic random access\niterators,\nour version operators on a range of \\valuetype.\nThus the signature of \\makeheap reads\n\n\\begin{lstlisting}[style = acsl-block]\n\n    void make_heap(value_type* a, size_type n);\n\\end{lstlisting}\n\nThe function \\makeheap rearranges the elements of the given\narray \\inl{a[0..n-1]} such that they form a heap.\n\nAs an examples we look at the array in Figure~\\ref{fig:makeheap-array-pre}.\nThe elements of this array do not form a heap, as indicated by the grey colouring.\nExecuting the \\makeheap algorithm on this array rearranges its elements\nso that they form a heap as shown in Figure~\\ref{fig:heap-array}.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.65\\linewidth]{Figures/make_heap_array_pre.pdf}\n\\caption{\\Label{fig:makeheap-array-pre}Array before the call of \\makeheap}\n\\end{figure}\n\n\n\\FloatBarrier\n\n\\subsection{Formal specification of \\makeheap}\n\nThe following listing shows the specification of \\makeheap.\n\n\\input{Listings/make_heap.h.tex}\n\nLike with \\pushheap the formal specification of \\makeheap\nmust ensure that the resulting array is a heap of size \\inl{n}\nand contains the same multiset of elements as in the pre-state of the function.\nThese properties are expressed by the \\inl{heap} and \\inl{reorder}\npostconditions respectively.\nThe \\inl{reorder} postcondition uses the predicate \\logicref{MultisetReorder}\nto ensure that \\makeheap only rearranges the array elements.\n\n\\clearpage\n\n\\subsection{Implementation of \\makeheap}\n\nThe implementation of \\makeheap, shown in the next listing, is straightforward.\n%\nFrom low to high the array's elements are pushed to the growing heap.\n%\nWe used \\inl{i < n} as loop condition, rather than the more tempting\n\\inl{i <= n}, in order to admit also \\inl{n == SIZE_TYPE_MAX};\nas a consequence, we had to call \\specref{pushheap} with \\inl{i+1}.\n%\nThe iteration starts at \\inl{i+1 == 2}, because an array with length one is\na heap already.\n\n\\input{Listings/make_heap.c.tex}\n\nSince the loop statement consists just of a call to \\specref{pushheap}\nwe obtain the both loop invariants \\inl{heap} and \\inl{reorder} by simply \nlifting them from the contract of \\pushheap.\n\nThe postcondition of \\pushheap only specifies the multiset\nof elements from index 0 to \\inl{i}.\n%\nWe therefore also have to specify\nthat the elements from index \\inl{i+1} to \\inl{n-1}  are only reordered.\n%\nThis property can be derived from the \\inl{unchanged} property of \\pushheap.\n\n\\clearpage\n\n", "meta": {"hexsha": "a60c748d804c6a3bb42413b26ac6cd5186ea608e", "size": 2606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/heap/make_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/make_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/make_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": 32.9873417722, "max_line_length": 82, "alphanum_fraction": 0.7705295472, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8902942268497306, "lm_q1q2_score": 0.6822268065110779}}
{"text": "\\section{Camera and Image formation process}\n\\label{imageFormation}\n\nTo understand how a camera perceives the environment, it is necessary we understand the image formation process. For us humans, we “see” things when a light originating from a light source is reflected on an object and enters our eyes. A camera acts very much similar to the human eye. The earliest and first model of an optical camera is the pinhole camera which is a simple and highly accurate representation of our eye model. This is the simplest device to form an image of a 3D scene on a 2D surface. As seen in figure 1 rays of light enter the pinhole and forms an inverted image of the object. This is called perspective projection. As the image formed in the image place is inverted, we consider a virtual plane in front of the pinhole that acts as the image plane.  \n\n% For one-column wide figures use\n\\begin{figure}[H]\n% Use the relevant command to insert your figure file.\n% For example, with the graphicx package use\n  \\includegraphics[width=\\textwidth]{./figures/imageFormation.png}\n% figure caption is below the figure\n\\caption{Pinhole Image formation~\\cite{imgFormBoomgaard}}\n\\label{fig:1}       % Give a unique label\n\\end{figure}\n\nAlthough the pinhole model is quite accurate, modern cameras have lenses. They help gather more light from a source leading to higher quality sharper images. Ignoring the internal diffraction, we assume thin lens equations for the imaging process. Every camera has a region of depths over which the scene is sharp. Modern cameras have variable apertures which help in focusing on objects at varying distances in the scene.  \n\nEvery camera has an intrinsic, extrinsic and distortion parameters that are important to understand for every application. These parameters are used to correct for lens distortion, measure objects in physical world and to determine the location of the camera in the real world. Camera calibration is the process of estimating these parameters specific to a given camera and application setup. Figure~\\ref{fig:transform} demonstrates how a real world 3D coordinate is related to a 2D pixel coordinate using the parameters mentioned above. The intrinsic camera matrix \\textbf{K} is given by\n\\begin{equation}\nK = \n\\begin{pmatrix}\n  f_x & s & c_x \\\\\n  0 & f_y & c_y \\\\\n  0 & 0 & 1 \\\\\n \\end{pmatrix}\n\\end{equation}\nwhere $(f_x, f_y)$ is the focal length, $(c_x, c_y)$ is the optical center\nand $s$ is skew factor. The extrinsic camera matrix $\\textbf{[R|t]}$ is given by\n\\begin{equation}\nR = \n\\begin{pmatrix}\n  r_1 & r_2 & r_3 \\\\\n  r_4 & r_5 & r_6 \\\\\n  r_7 & r_8 & r_9 \\\\\n \\end{pmatrix}\nt = \n\\begin{pmatrix}\n  t_x \\\\\n  t_y \\\\\n  t_z \\\\\n \\end{pmatrix}\n\\end{equation}\nwhere $R$ is the rotation matrix and $t$ is the translation vector between the camera center and world co-ordinates. The camera matrix $P$ is given by \n\\begin{equation}\nP = K[R t]\n\\end{equation}\n\n% For one-column wide figures use\n\\begin{figure}[H]\n% Use the relevant command to insert your figure file.\n% For example, with the graphicx package use\n  \\includegraphics[width=\\textwidth]{./figures/imageParams.png}\n% figure caption is below the figure\n\\caption{World co-ordinates to pixel co-ordinates~\\cite{camMATLAB}}\n\\label{fig:transform}       % Give a unique label\n\\end{figure}\n\nThe extrinsic parameters relate the rotation $R$ and translation $t$ of the camera origin at the optical center to the world frame. The intrinsic parameters consists of the focal length given by $f_x$ and $f_y$, the optical center given by $c_x$ and $c_y$ and the skew coefficient $s$. The distortion parameters consists of radial and tangential distortion along the $x$ and $y$ direction respectively. The number of coefficients are decided based on the lens in consideration. Camera calibration techniques presented in~\\cite{zhang,bouguet2004camera,heikkila1997four} are widely used in commercial and open source camera calibration tool boxes.", "meta": {"hexsha": "4f80cdd71c703567b64198a2f5354e235012844e", "size": 3927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/text/imageFormation.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/imageFormation.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/imageFormation.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": 67.7068965517, "max_line_length": 774, "alphanum_fraction": 0.7705627706, "num_tokens": 967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.6821518027447137}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb,fouriernc,parskip,amsthm}\n\\usepackage{hyperref}\n\\hypersetup{\n  citecolor=red,\n  colorlinks=true\n}\n\n\\begin{document}\n\\theoremstyle{definition}\n\\newtheorem{thm}{Theorem}[section]\n\\newtheorem{lem}[thm]{Lemma}\n\n\\section{Normalized Fractions/Exponents}\n\n\\begin{lem}\n\\label{pow}\nLet\n\\begin{equation*}\nS = \\left \\{ \\; i \\in \\mathbb{Z}^{\\geq 0} \\; | \\; r^{p - 1} \\leq f \\cdot r^i \n\\; \\right \\}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\forall r, f, p \\in \\mathbb{N} \\; . f > 0 \\; \\wedge \\; p > 0 \\; \n\\Longrightarrow \\; \\exists i^* \\in S \\; . \\forall i \\in S \\; . \\; i^* \\leq i\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Since $f > 0$, $f \\geq 1$. Moreover, \n$p > 0$, so $p - 1 \\geq 0$ and $r^{p - 1} \\leq f \\cdot r^{p - 1}$. It follows\nthat $p - 1 \\in S$. From the Well-Ordering Principle, $S$ has a smallest\nelement $i^*$. \n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{posfrac}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R}, f \\in \\mathbb{N}, e \\in \\mathbb{Z} \\; . \\; \nx \\neq 0 \\; \\wedge \\; frep(f,e,x) \\; \\Longrightarrow \\; f > 0\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Expanding the defn of $frep$, we know\n\\begin{equation*}\n|x| = f \\cdot r^{(e - p + 1)}\n\\end{equation*}\nSince $x \\neq 0$, $|x| > 0$. $r^{(e - p + 1)}$ is always positive, so $f > 0$.\n\\end{proof}\n\\end{lem}\n\n\\begin{thm}\n\\label{normexists}\n\\begin{align*}\n&\\forall x \\in \\mathbb{R} \\; . \\; x \\neq 0 \\; \\wedge \\; is\\_float(x) \\; \n\\Longrightarrow \\\\\n& \\qquad \\exists f' \\in \\mathbb{N}, e' \\in \\mathbb{Z} \\; . \\; \nis\\_norm\\_frac(f', x) \\; \\wedge \\; is\\_norm\\_exp(e', x)\n\\end{align*}\n\\begin{proof} Assume $is\\_float(x)$ and $x \\neq 0$. From the defn of\n$is\\_float$, we know there exists $f \\in \\mathbb{N}$ and $e \\in \\mathbb{Z}$\nsuch that $frep(f, e, x)$. From ~\\ref{posfrac}, we know $f > 0$.\n\nAlso, from the defn of $frep$, we know\n\\begin{equation*}\nf < r^p \\; \\wedge \\; |x| = f \\cdot r^{(e - p + 1)}\n\\end{equation*}\nFrom ~\\ref{pow}, we know there is a smallest integer $i^*$ such that\n$r^{p - 1} \\leq f \\cdot r^{i^*}$. We also know that $f \\cdot r^{i^*} < r^p$\n(if it wasn't, we could cancel r on both sides and obtain a smaller\n$i$, contradicting the definition of $i^*$). Take $f' = f \\cdot r^{i^*}$.\nIt immediately follows that $f' \\geq r^{p - 1}$. If we also take\n$e' = e - i^*$, then\n\\begin{align*}\nf' \\cdot r^{e' - p + 1} &= f \\cdot r^{i^*} \\cdot r^{e - i^* - p + 1}\\\\\n&= f \\cdot r^{e - p + 1}\\\\\n&= |x|\n\\end{align*}\nand so $is\\_norm\\_frac(f', x)$ is true and $is\\_norm\\_exp(e', x)$ is true.\n\\end{proof}\n\\end{thm}\n\n\\begin{lem}\n\\label{normbound}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; x \\neq 0 \\; \\wedge \\; is\\_float(x) \\;\n\\Longrightarrow \\; r^{ne(x)} \\leq |x| < r^{ne(x) + 1}\n\\end{equation*}\n(where $ne(x)$ is an abbreviation for $decode\\_norm\\_exp(x)$).\n\\begin{proof} Assume the antecedent. Because $x$ is a non-zero float, we\nknow from ~\\ref{normexists} that $x$ has a normalized fraction and exponent\n$f$ and $e$ with $r^{p - 1} \\leq f < r^p$. Multiply all three by the positive\nvalue $r^{e - p + 1}$ to get $r^e \\leq |x| < r^{e + 1}$.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{expupper}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R}, i \\in \\mathbb{Z} \\; . \n\\; x \\neq 0 \\; \\wedge \\; is\\_float(x) \\; \\wedge \\; |x| \\leq r^i\n\\Longrightarrow \\; ne(x) < i\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Because $x$ is a non-zero float,\nfrom ~\\ref{normbound} we know\n\\begin{equation*}\nr^{ne(x)} \\leq |x| < r^i\n\\end{equation*}\nFrom the monotonicty of pow, we can conlude $ne(x) < i$.\n\\end{proof}\n\\end{lem}\n\n\\section{largest/smallest}\n\n\\begin{lem}\n\\label{realpow1}\n\\begin{equation*}\n\\forall n, r \\in \\mathbb{N} \\; . \\; r > 1 \\; \\Longrightarrow \\;\n\\exists i \\in \\mathbb{Z} \\; . \\; r^i > n\n\\end{equation*}\n\\begin{proof} Let $r > 1$. The proof is by induction on $n$.\n\n\\textsc{Base case.} For $n = 0, 1$, take $i = 1$.\n\n\\textsc{Inductive step.} Assume there is an $i$ such that $r^i > n$, and\nconsider $n + 1$:\n\\begin{align*}\nn + 1 &< r^i + 1 \\tag{induction hyp}\\\\\n&< r^i + r \\tag{$r > 1$}\\\\\n&\\leq r^{i'} + r^{i'} \\tag{$i' = max(i, 1)$, monotonicity of pow}\\\\\n&= 2r^{i'}\\\\\n&\\leq r \\cdot r^{i'} \\tag{$r \\geq 2$}\\\\\n&= r^{i' + 1}\n\\end{align*}\nSo, take $i = i' + 1$, and we're done.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{realpow2}\n\\begin{equation*}\n\\forall r \\in \\mathbb{N}, x \\in \\mathbb{R}^{\\geq 0} \\; . \\; r > 1 \\; \n\\Longrightarrow \\; \\exists i \\in \\mathbb{Z} \\; . \\; r^i > x\n\\end{equation*}\n\\begin{proof} Let $x$ and $r > 1$. From the archimedean property (available\nin HOL light), we know\nthere is an $n$ such that $n > x$. From ~\\ref{realpow1}, there is an $i$\nsuch that $r^i > n > x$.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{realpow3}\n\\begin{equation*}\n\\forall r \\in \\mathbb{N}, x \\in \\mathbb{R^+} \\; . \\; r > 1 \\; \\Longrightarrow \\;\n\\exists i \\in \\mathbb{Z} \\; . \\; r^i < x\n\\end{equation*}\n\\begin{proof} Let $x$ and $r > 1$. Since $x > 0$,\n$inv(x) > 0$, and from ~\\ref{realpow2}, there is an $i'$ such that\n$r^{i'} > inv(x)$. Then, multiplying by $x$ and $r^{-i'}$ on both sides (both are\npositive):\n\\begin{equation*}\nx > r^{-i'}\n\\end{equation*}\nTake $i = i'$.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{realbetw}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; \\exists u, v \\in \\mathbb{Z} \\; . \\;\nv = u + 1 \\; \\wedge \\; u \\leq x < v\n\\end{equation*}\n\\begin{proof} Let $x \\in \\mathbb{R}$.\n\\begin{itemize}\n\\item If $x > 0$, let $S = \\{ \\; n \\in \\mathbb{N} \\; | \\; x < n \\; \\}$.\nFrom the archimedean property (REAL\\_ARCH), we know $S$ is non-empty,\nand so from the well-ordering property (num\\_WOP), $S$ has a least element\n$n^*$. Since $n^* > x > 0$, $n^* - 1 < n^*$, and hence $n^* - 1 \\leq x$.\nTake $u = n^* - 1$ and $v = n^*$.\n\\item If $x < 0$, get $u', v'$ for $-x > 0$ such that $u' \\leq -x < v'$. Then\n$-v' < x \\leq -u'$. If $x = -u'$, take $u = -u'$ and $v = -u' + 1$. If\n$x < -u'$, take $v = -u'$ and $u = -u' - 1 \\geq -v'$. (I'm guessing the\nreal arithmetic decision procedures could take over from here ...).\n\\item If $x = 0$, take $u = 0$ and $v = 1$.\n\\end{itemize}\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{intmax}\n\\begin{equation*}\n\\forall S \\subset \\mathbb{Z}, b \\in \\mathbb{R} \\; . \\;\n S \\neq \\emptyset \\; \\wedge \\; \\big [ \\; \\forall s \\in S \\; . \\; s \\leq b \\;\n\\big ] \\; \\Longrightarrow \\; \\exists s^* \\in S \\; . \\; \\forall s \\in S \\; . \\;\ns \\leq s^*\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Because $S \\neq \\emptyset$ and\nthere is an upper bound $b$ for $S$, $sup(S)$ exists.\n\\begin{itemize}\n\\item If $sup(S) \\in S$, take $s^* = sup(S)$ (from the HOL-light defn of \n$sup$, the result will follow).\n\\item Otherwise, $sup(S) \\notin S$. From ~\\ref{realbetw}, there are\n$u, v \\in \\mathbb{Z}$ with $u \\leq sup(S) < v$.\n\\begin{itemize}\n\\item If $u = sup(S)$, then\n\\begin{itemize}\n\\item If $u \\in S$, then $sup(S) \\in S$, contradiction.\n\\item If $u \\notin S$, then consider $u - 1$. If $u - 1 \\geq s$ for all\n$s \\in S$, then we get a contradiction in the defn of sup. Otherwise, if\nthere is some $s \\in S$ with $s > u - 1$, then $s \\geq u = sup(S)$\n(INT\\_GT\\_DISCRETE). If $s = sup(S)$, then $sup(S) \\in S$, contradiction.\nOtherwise, $s > sup(S)$, also a contradiction.\n\\end{itemize}\n\\item If $u < sup(S)$, then if for all $s \\in S$, $s \\leq u$, we get a \ncontradiction in defn of sup. Otherwise, there is some $s \\in S$ with\n$s > u$, so $s \\geq u + 1 = v > sup(S)$, contradiction.\n\\end{itemize}\n\\end{itemize}\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{intmin}\n\\begin{equation*}\n\\forall S \\subset \\mathbb{Z}, b \\in \\mathbb{R} \\; . \\;\n S \\neq \\emptyset \\; \\wedge \\; \\big [ \\; \\forall s \\in S \\; . \\; s \\geq b \\;\n\\big ] \\; \\Longrightarrow \\; \\exists s^* \\in S \\; . \\; \\forall s \\in S \\; . \\;\ns \\geq s^*\n\\end{equation*}\n\\begin{proof} Assume the antecedent, and take $S' = -S$. Since $S \\neq \n\\emptyset$, $S' \\neq \\emptyset$. Also, since $b \\leq s$ for all $s \\in S$,\n$b' = -b \\geq -s$ for all $s \\in S$, hence $b'$ is an upper bound for\n$-S$. From ~\\ref{intmax}, we know there is an $s^* \\in S'$ with\n$s^* \\geq s'$ for all $s' \\in S'$. This in turn means $-s^* \\leq -s'$ for all\n$s' \\in S'$, and $s^* = -s^*$ is the minimum for $S$ (probably some tedious\ndetails to sort out here).\n\\end{proof}\n\\end{lem}\n\n\\begin{thm}\n\\label{maxabsexists}\n\\begin{equation*}\n\\forall S \\subset F, b \\in \\mathbb{R}^+ \\; . \\; S \\neq \\emptyset \\; \\wedge \\;\n\\big [ \\; \\forall s \\in S \\; . \\; |s| \\leq b \\; \\big ] \\;\n\\Longrightarrow \\exists s^* \\in S \\; . \\; \\forall s \\in S \\; . \\; |s| \\leq |s^*|\n\\end{equation*}\n\\begin{proof} Assume the antecedent. If $S = \\{0\\}$, then $s^* = 0$ and we're\ndone. Otherwise, assume there is $s \\neq 0$ in $S$. Take $S' = \\{ \\; s \\in S \\;\n| s \\neq 0 \\; \\}$.\n\nFrom ~\\ref{realpow2}, we know there is an integer $i$ with $r^i > b$. \nThis implies that $|s| < r^i$ for all $s \\in S'$. From ~\\ref{expupper}, we\nknow $ne(s) < i$ for all $s \\in S'$. Let\n\\begin{equation*}\nExp = \\{ \\; e \\; | \\; \\exists s \\in S' \\; . \\; e = ne(s) \\; \\}\n\\end{equation*}\n$i$ is therefore an upper bound for $Exp$. From ~\\ref{intmax}, there is a\nmaximal element $e^*$ in $Exp$.\n\nNext, take\n\\begin{equation*}\nFrac = \\{ \\; f \\; | \\; \\exists s \\in S' \\; . \\; f = nf(s) \\; \\wedge \\;\nne(s) = e^* \\; \\}\n\\end{equation*}\nSince $f < r^p$ for all $f \\in Frac$, from ~\\ref{intmax}, there is a maximal\nelement $f^* \\in Frac$. Take $s^* = f^* \\cdot r^{e^* - p + 1}$.\n\nConsider any $s \\in S'$. We know $ne(s) \\leq e^*$. If $ne(s) < e^*$, then\n\\begin{align*}\n|s| &= nf(s) \\cdot r^{ne(s) - p + 1}\\\\\n& < r^p \\cdot r^{ne(s) - p + 1}\\\\\n&\\leq r^{e^*}\\\\\n& = r^{p - 1} \\cdot r^{e^* - p + 1}\\\\\n& \\leq f^* \\cdot r^{e^* - p + 1}\\\\\n& = |s^*|\n\\end{align*}\nIf $ne(s) = e^*$, then, since $nf(s) \\leq f^*$,\n\\begin{equation*}\n|s| = nf(s) \\cdot r^{e^* - p + 1} \\leq f^* \\cdot r^{e^* - p + 1} = |s^*|\n\\end{equation*}\nFinally, since $f^* > 0$, $|s^*| > 0$, so the claim is true for $s = 0$, and\nhence true for all $s \\in S$.\n\\end{proof}\n\\end{thm}\n\n\\end{document}\n", "meta": {"hexsha": "2fe135815dd48ef4ebec204dc7957d30f6f998bf", "size": 9872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "formal/ieee754/outline/outline.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/outline/outline.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/outline/outline.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": 34.5174825175, "max_line_length": 81, "alphanum_fraction": 0.5738452188, "num_tokens": 4252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8006920116079208, "lm_q1q2_score": 0.6821517967834985}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{tikz}\n\\usepackage{placeins}\n\n\\begin{document}\n\n\\title{FISHER'S LINEAR DISCRIMINANT ANALYSIS}\n\\date{}\n\\maketitle\n\nFisher's Linear Discriminant Analysis (FDA) is a dimensionality reduction technique to ease classification.\n\n\\section{Two Class Case}\n\nConsider the case of $N$ points in $d$ dimensions, with each point belonging to one of the two classes $C_1$ and $C_2$. The idea is to find the optimal direction to project the vector of these points to. Such a projection can be represented as,\n\n\\begin{align*}\n\ty = \\boldsymbol{w}^T\\boldsymbol{x} \n\\end{align*}\n\nwhere $\\boldsymbol{w}$ is a $d$ dimensional vector defining the direction of projection, $\\boldsymbol{x}$ is the vector being projected and $y$ is a scalar representing the magnitude of projection.\n\nThe projection should serve two purposes as discussed in the following subsections:\n\n\\subsection{Maximizing Between-Class Scatter}\n\nThe class means should be projected as far apart as possible. Let $\\boldsymbol{m_1}$ and $\\boldsymbol{m_2}$ denote the mean of class $C_1$ and $C_2$ respectively.\n\n\\begin{align*}\n\t\\boldsymbol{m_1} & = \\frac{1}{N} \\sum_{\\boldsymbol{x_i} \\in C_1} \\boldsymbol{x_i} \\\\\n\t\\boldsymbol{m_2} & = \\frac{1}{N} \\sum_{\\boldsymbol{x_i} \\in C_2} \\boldsymbol{x_i} \n\\end{align*} \n\n\nIf $\\boldsymbol{m_1}$ is projected to $m_1$ and $\\boldsymbol{m_2}$ is projected to $m_2$, then the between-scatter is defined by,\n\n\\begin{align*}\n\t(m_1 - m_2)^2 & = (\\boldsymbol{w}^T\\boldsymbol{m_1} - \\boldsymbol{w}^T\\boldsymbol{m_2})^2                                    \\\\\n\t              & = (\\boldsymbol{w}^T(\\boldsymbol{m_1} - \\boldsymbol{m_2}))^2                                                  \\\\\n\t              & = \\boldsymbol{w}^T(\\boldsymbol{m_1} - \\boldsymbol{m_2})\\boldsymbol{w}^T(\\boldsymbol{m_1} - \\boldsymbol{m_2}) \\\\\n\t              & = \\boldsymbol{w}^T(\\boldsymbol{m_1} - \\boldsymbol{m_2})(\\boldsymbol{m_1} - \\boldsymbol{m_2})^T\\boldsymbol{w} \\\\\n\t              & = \\boldsymbol{w}^T\\boldsymbol{S_B}\\boldsymbol{w}                                                             \n\\end{align*} \n\nwhere $\\boldsymbol{S_B}$ represents the between-class scatter matrix.\n\n\\subsection{Minimizing Within-Class Scatter}\n\nThe projections of each class should be as condensed as possible. The within-class scatter of the transformed data belonging to class $C_k$ is denoted by,\n\n\\begin{align*}\n\ts_k^2 & = \\sum_{i \\in C_k} (y_i - m_k)^2                                                                                            \\\\\n\t      & = \\sum_{i \\in C_k} (\\boldsymbol{w}^T\\boldsymbol{x_i} - \\boldsymbol{w}^T\\boldsymbol{m_k})^2                                  \\\\\n\t      & = \\sum_{i \\in C_k} (\\boldsymbol{w}^T(\\boldsymbol{x_i} -\\boldsymbol{m_k}))^2                                                 \\\\\n\t      & = \\sum_{i \\in C_k} \\boldsymbol{w}^T(\\boldsymbol{x_i} -\\boldsymbol{m_k})(\\boldsymbol{x_i} -\\boldsymbol{m_k})^T\\boldsymbol{w} \\\\\n\t      & = \\boldsymbol{w}^T \\boldsymbol{S_k} \\boldsymbol{w}                                                                          \\\\\n\\end{align*}  \n\nwhere,\n\\begin{align*}\n\t\\boldsymbol{S_k} = \\sum_{i \\in C_k}(\\boldsymbol{x_i} -\\boldsymbol{m_k})(\\boldsymbol{x_i} -\\boldsymbol{m_k})^T \n\\end{align*}\n\nIn the case of two classes, total within class scatter is denoted by,\n\n\\begin{align*}\n\ts_1^2 + s_2^2 & = \\boldsymbol{w}^T \\boldsymbol{S_1} \\boldsymbol{w} + \\boldsymbol{w}^T \\boldsymbol{S_1} \\boldsymbol{w} \\\\\n\t              & = \\boldsymbol{w}^T (\\boldsymbol{S_1}+\\boldsymbol{S_2}) \\boldsymbol{w}                                 \\\\\n\t              & = \\boldsymbol{w}^T \\boldsymbol{S_W} \\boldsymbol{w}                                                    \n\\end{align*}\n\nwhere $\\boldsymbol{S_W}$ represents the within-class scatter matrix.\n\n\\subsection{Combining Minimization and Maximization}\n\nA reasonable way to simultaneously maximize the between-class scatter and minimize the within-class scatter is to maximize their fraction defined as follows,\n\n\\begin{align*}\n\tJ(\\boldsymbol{w}) = \\frac{\\boldsymbol{w}^T \\boldsymbol{S_B} \\boldsymbol{w}}{\\boldsymbol{w}^T \\boldsymbol{S_W} \\boldsymbol{w}} \n\\end{align*}\n\nNote that $J(\\boldsymbol{w})$ is invariant under rescalings of the form $\\boldsymbol{w} \\Rightarrow \\alpha \\boldsymbol{w}$. This sets up the reformulation of this problem as per the following,\n\n\\begin{align*}\n\t\\text{maximize} & \\ \\ \\boldsymbol{w}^T \\boldsymbol{S_B} \\boldsymbol{w}     \\\\\n\t\\text{s.t.}     & \\ \\ \\boldsymbol{w}^T \\boldsymbol{S_W} \\boldsymbol{w} = 1 \n\\end{align*}\n\nUsing the concept of Lagrangian, \n\n\\begin{align*}\n\tL(\\boldsymbol{w}, \\lambda) = \\boldsymbol{w}^T \\boldsymbol{S_B} \\boldsymbol{w} - \\lambda(\\boldsymbol{w}^T \\boldsymbol{S_W} \\boldsymbol{w} - 1) \n\\end{align*}\n\nDifferentiating w.r.t. $\\boldsymbol{w}$,\n\n\\begin{align*}\n\t\\frac{\\partial L(\\boldsymbol{w}, \\lambda)}{\\partial \\boldsymbol{w}} = 2\\boldsymbol{S_B}\\boldsymbol{w} - 2\\lambda \\boldsymbol{S_W}\\boldsymbol{w} \n\\end{align*}\n\nEquating the diffenrential to zero, the solution follows,\n\n\\begin{align*}\n\t\\boldsymbol{S_B}\\boldsymbol{w} = \\lambda \\boldsymbol{S_W}\\boldsymbol{w} \n\\end{align*}\n\nThis is the generalized eigenvalue problem that can be solved easily. Note that since $\\boldsymbol{S_B}$ is a product of two vectors and thus of rank one, the above equation will only yield one eigenvalue, eigenvector pair. The eigenvector is the sought projection direction.\n\n\\section{Example}\n\nConsider the following set of six points in two dimesions distributed equally among the two classes,\n\n\\FloatBarrier\\clearpage\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\tikzstyle {point line} = [line width=0.15em]\n\t\t\\tikzstyle {margin} = [dashed]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[step=1.0, gray, very thin] (-5.5, -2.5) grid (5.5, 4.5);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-6,0) -- (6,0) node[right]{x1};\n\t\t\\draw[-latex] (0,-3) -- (0,5) node[left]{x2};\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, 1) -- (-0.7, 1);\t\n\t\t\\draw[point line] (-1, 0.7) -- (-1, 1.3);\n\t\t\\draw (-1, 1) node [below right] {(-1, 1)};    \t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-4.3, -1) -- (-3.7, -1);\t\n\t\t\\draw[point line] (-4, -1.3) -- (-4, -0.7);\t\n\t\t\\draw (-4, -1) node [below left] {(-4, -1)};   \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-4.3, 3) -- (-3.7, 3);\t\n\t\t\\draw[point line] (-4, 2.7) -- (-4, 3.3);\t\n\t\t\\draw (-4, 3) node [above left] {(-4, 3)};   \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (1.7, 1) -- (2.3, 1);\t\t\n\t\t\\draw (2, 1) node [above left] {(2, 1)}; \n\t\t\t\t\t\t\n\t\t\\draw[point line] (2.7, 0) -- (3.3, 0);\t\t\n\t\t\\draw (3, 0) node [above left] {(3, 0)};\n\t\t\t\t\t\t\n\t\t\\draw[point line] (0.7, 2) -- (1.3, 2);\t\t\n\t\t\\draw (1, 2) node [above left] {(1, 2)};\t\t\t\t  \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   \t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nThe means for the respective classes are,\n\n\\begin{align*}\n\t\\boldsymbol{m_{+}} & = \\begin{pmatrix} \n\t-3 \\\\\n\t1 \n\t\\end{pmatrix} \\\\\n\t\\boldsymbol{m_{-}} & = \\begin{pmatrix} \n\t2 \\\\\n\t1 \n\t\\end{pmatrix}    \n\\end{align*}\n\nNow, the between-class scatter matrix is calculated as follows,\n\n\\begin{align*}\n\t\\boldsymbol{S_B} & = (\\boldsymbol{m_{+}} - \\boldsymbol{m_{-}})(\\boldsymbol{m_{+}} - \\boldsymbol{m_{-}})^T \\\\ \n\t                 & = \\begin{pmatrix}                                                                      \n\t-5 \\\\\n\t0 \n\t\\end{pmatrix} \\begin{pmatrix}\n\t-5               & 0                                                                                      \n\t\\end{pmatrix} \\\\\n\t                 & = \\begin{pmatrix}                                                                      \n\t25               & 0                                                                                      \\\\\n\t0                & 0                                                                                      \n\t\\end{pmatrix}         \n\\end{align*}\n\nAnd then, the within-class scatter matrix is calculated,\n\n\\begin{align*}    \n\tS_+              & = \\sum_{i \\in +}(\\boldsymbol{x_i} -\\boldsymbol{m_+})(\\boldsymbol{x_i} -\\boldsymbol{m_+})^T \\\\\n\t                 & = \\begin{pmatrix}                                                                          \n\t2 \\\\\n\t0\n\t\\end{pmatrix} \\begin{pmatrix}\n\t2                & 0                                                                                          \n\t\\end{pmatrix} + \\begin{pmatrix}\n\t-1 \\\\\n\t2\n\t\\end{pmatrix} \\begin{pmatrix}\n\t-1               & 2                                                                                          \n\t\\end{pmatrix} + \\begin{pmatrix}\n\t-1 \\\\\n\t-2\n\t\\end{pmatrix} \\begin{pmatrix}\n\t-1               & -2                                                                                         \n\t\\end{pmatrix}  \\\\\n\t                 & = \\begin{pmatrix}                                                                          \n\t6                & 0                                                                                          \\\\\n\t0                & 8                                                                                          \n\t\\end{pmatrix} \\\\\n\tS_-              & = \\sum_{i \\in -}(\\boldsymbol{x_i} -\\boldsymbol{m_-})(\\boldsymbol{x_i} -\\boldsymbol{m_-})^T \\\\\n\t                 & = \\begin{pmatrix}                                                                          \n\t0 \\\\\n\t0\n\t\\end{pmatrix} \\begin{pmatrix}\n\t0                & 0                                                                                          \n\t\\end{pmatrix} + \\begin{pmatrix}\n\t-1 \\\\\n\t1\n\t\\end{pmatrix} \\begin{pmatrix}\n\t-1               & 1                                                                                          \n\t\\end{pmatrix} + \\begin{pmatrix}\n\t1 \\\\\n\t-1\n\t\\end{pmatrix} \\begin{pmatrix}\n\t1                & -1                                                                                         \n\t\\end{pmatrix}  \\\\\n\t                 & = \\begin{pmatrix}                                                                          \n\t2                & -2                                                                                         \\\\\n\t-2               & 2                                                                                          \n\t\\end{pmatrix} \\\\\n\t\\boldsymbol{S_W} & = \\boldsymbol{S_+} + \\boldsymbol{S_-}                                                      \\\\\n\t                 & = \\begin{pmatrix}                                                                          \n\t8                & -2                                                                                         \\\\\n\t-2               & 10                                                                                         \n\t\\end{pmatrix}\n\\end{align*}\n\nThe eigenvalue problem is formulated as,\n\n\\begin{align*}\n\t\\boldsymbol{S_B}\\boldsymbol{w} = \\lambda \\boldsymbol{S_W}\\boldsymbol{w} \n\\end{align*}\n\nEquating the determinant of $\\boldsymbol{S_B} - \\lambda \\boldsymbol{S_W}$ to zero,\n\n\\begin{align*}\n\t\\begin{vmatrix}\n\t25-8\\lambda   & 2\\lambda   \\\\\n\t2\\lambda      & -10\\lambda \n\t\\end{vmatrix} & = 0        \\\\\n\t\\lambda = \\frac{125}{38}\n\\end{align*}\n\nThe corresponding eigenvector amounts to $\\frac{1}{\\sqrt{26}}\\begin{pmatrix}\n5 \\\\\n1\n\\end{pmatrix}$ which is the direction of projection. The below plot helps to visualize how this projection direction divides the two classes.\n\n\\FloatBarrier\\clearpage\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\tikzstyle {point line} = [line width=0.15em]\n\t\t\\tikzstyle {margin} = [dashed]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[step=1.0, gray, very thin] (-5.5, -2.5) grid (5.5, 4.5);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-6,0) -- (6,0) node[right]{x1};\n\t\t\\draw[-latex] (0,-3) -- (0,5) node[left]{x2};\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, 1) -- (-0.7, 1);\t\n\t\t\\draw[point line] (-1, 0.7) -- (-1, 1.3);\n\t\t\\draw (-1, 1) node [below right] {(-1, 1)};    \t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-4.3, -1) -- (-3.7, -1);\t\n\t\t\\draw[point line] (-4, -1.3) -- (-4, -0.7);\t\n\t\t\\draw (-4, -1) node [below left] {(-4, -1)};   \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-4.3, 3) -- (-3.7, 3);\t\n\t\t\\draw[point line] (-4, 2.7) -- (-4, 3.3);\t\n\t\t\\draw (-4, 3) node [above left] {(-4, 3)};   \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (1.7, 1) -- (2.3, 1);\t\t\n\t\t\\draw (2, 1) node [above left] {(2, 1)}; \n\t\t\t\t\t\t\n\t\t\\draw[point line] (2.7, 0) -- (3.3, 0);\t\t\n\t\t\\draw (3, 0) node [above left] {(3, 0)};\n\t\t\t\t\t\t\n\t\t\\draw[point line] (0.7, 2) -- (1.3, 2);\t\t\n\t\t\\draw (1, 2) node [above left] {(1, 2)};\n\t\t\t\t\t\t\n\t\t\\draw[dashed] (5.5, 1.1) -- (-5.5, -1.1);\t\n\t\t\\draw[thin] (-4, -1) -- (-4.04, -0.81);\t\n\t\t\\draw[thin] (-1, 1) -- (-0.77, -0.15);\n\t\t\\draw[thin] (-4, 3) -- (-3.27, -0.66);\n\t\t\t\t\t    \t\n\t\t\\draw[thin] (1, 2) -- (1.35, 0.27);\n\t\t\\draw[thin] (2, 1) -- (2.12, 0.42);\t    \t    \n\t\t\\draw[thin] (3, 0) -- (2.88, 0.58);\t    \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   \t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\section{Multi-Class Case}\n\nIn two class case dimensionality was reduced to 1. In $K$ class case, it is reduced to $K-1$. Hence, instead of finding an optimal $d$-dimensional vector $\\boldsymbol{w}$ in the two class case, a matrix of $K-1$ $d$-dimensional vectors $\\boldsymbol{W}^T = \\begin{pmatrix}\n\\boldsymbol{w_1}^T \\\\\n\\boldsymbol{w_1}^T \\\\\n\\vdots \\\\\n\\boldsymbol{w_{K-1}}^T \\\\        \n\\end{pmatrix}$ must be found. The projection is defined as $\\boldsymbol{y}=\\boldsymbol{W}^T\\boldsymbol{x}$ where $\\boldsymbol{y}$ is a $K-1$ dimensional vector as expected.\n\nThe generalization for within-class matrix is as follows,\n\n\\begin{align*}\n\t\\boldsymbol{S_W} = \\sum_{k=1}^K \\sum_{i \\in C_k} (\\boldsymbol{x_i} - \\boldsymbol{m_k})(\\boldsymbol{x_i} - \\boldsymbol{m_k})^T \n\\end{align*}\n \nFor generalizing between-class matrix, consider the total scatter matrix $\\boldsymbol{S_T}$ as follows,\n\n\\begin{align*}\n\t\\boldsymbol{S_T} & = \\sum_{i=1}^N (\\boldsymbol{x_i} - \\boldsymbol{m})(\\boldsymbol{x_i} - \\boldsymbol{m})^T                                                                                                                               \\\\\n\t                 & = \\sum_{k=1}^K \\sum_{i \\in C_k} (\\boldsymbol{x_i} - \\boldsymbol{m})(\\boldsymbol{x_i} - \\boldsymbol{m})^T                                                                                                              \\\\\n\t                 & = \\sum_{k=1}^K \\sum_{i \\in C_k} (\\boldsymbol{x_i} - \\boldsymbol{m_k} + \\boldsymbol{m_k} - \\boldsymbol{m})(\\boldsymbol{x_i} - \\boldsymbol{m_k} + \\boldsymbol{m_k} - \\boldsymbol{m})^T                                  \\\\\n\t                 & = \\sum_{k=1}^K \\sum_{i \\in C_k} (\\boldsymbol{x_i} - \\boldsymbol{m_k})(\\boldsymbol{x_i} - \\boldsymbol{m_k})^T + \\sum_{k=1}^K \\sum_{i \\in C_k} (\\boldsymbol{m_k} - \\boldsymbol{m})(\\boldsymbol{m_k} - \\boldsymbol{m})^T \\\\\n\t                 & = \\boldsymbol{S_W} + \\sum_{k=1}^K N_k(\\boldsymbol{m_k} - \\boldsymbol{m})(\\boldsymbol{m_k} - \\boldsymbol{m})^T                                                                                                         \\\\\n\t                 & = \\boldsymbol{S_W} + \\boldsymbol{S_B}                                                                                                                                                                                 \n\\end{align*} \n\nThe maximization problem is then generalized as follows,\n\n\\begin{align*}\n\tJ(\\boldsymbol{W}) = \\frac{det(\\boldsymbol{W}^T \\boldsymbol{S_B} \\boldsymbol{W})}{det(\\boldsymbol{W}^T \\boldsymbol{S_W} \\boldsymbol{W})} \n\\end{align*}\n\nThe solution to find the matrix $\\boldsymbol{W}$ is to find the largest $K-1$ eigenvalues of the following equation and arrange the corresponding eigenvectors in a matrix. \n\n\\begin{align*}\n\t\\boldsymbol{S_B}\\boldsymbol{w} = \\lambda \\boldsymbol{S_W}\\boldsymbol{w} \n\\end{align*}    \n\nAdditionally, there are no more than $K-1$ non-zero eigenvectors to the above \nequation due to the redundancy of the matrix $\\boldsymbol{S_B}$ as was seen in the two class case.\n \n\\end{document}\n", "meta": {"hexsha": "48afdb16fc93bda2b6216e9c3f97bbb031211691", "size": 15710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Fisher's Linear Discriminant Analysis/Fisher's Linear Discriminant Analysis.tex", "max_stars_repo_name": "singaurav/machine-learning-notes", "max_stars_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-26T11:33:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-26T11:33:39.000Z", "max_issues_repo_path": "Fisher's Linear Discriminant Analysis/Fisher's Linear Discriminant Analysis.tex", "max_issues_repo_name": "singaurav/machine-learning-notes", "max_issues_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fisher's Linear Discriminant Analysis/Fisher's Linear Discriminant Analysis.tex", "max_forks_repo_name": "singaurav/machine-learning-notes", "max_forks_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-22T18:56:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-22T18:56:20.000Z", "avg_line_length": 46.2058823529, "max_line_length": 275, "alphanum_fraction": 0.4899427116, "num_tokens": 4799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.682151788679752}}
{"text": "\n\\subsection{Representing natural numbers}\n\nWe will use a byte to describe natural numbers. This gives us a range of \\(2^8=256\\). As we include \\(0\\) the largest number here is \\(255\\).\n\n\\subsection{Zero}\n\nWe describe zero using all \\(0\\)s.\n\n\\(0=00000000\\)\n\n\\subsection{Natural numbers}\n\nWe show other natural numbers by iterating through the possible bits. To increase by one we take the last bit and use the NOT operator on it. If this bit is \\(1\\) we are done.\n\nIf this bit is now \\(0\\) we move to the next bit and flip that. We then repeat the check and repeat until we either run out of bits, or flip a bit to \\(1\\).\n\n", "meta": {"hexsha": "afc27267e4637fd3fe2da99478ee636cdd70bece", "size": 623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/numbers/01-01-natural.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/numbers/01-01-natural.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/numbers/01-01-natural.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6111111111, "max_line_length": 175, "alphanum_fraction": 0.7239165329, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6820625921110207}}
{"text": "\\chapter{Paths in Graphs}\n\\label{chapter:paths}\n\\section{Connectivity}\nImagine you are developing a game, where the map is generated automatically.\nIn this gate there are several areas connected by portals. So you need to check\nthat all the areas in your map are reachable from one another.\n\nFirst we need to somehow understand what we mean by ``reachable'', we say that\nan area $A$ is reachable from an area $B$ if there is a path from $A$ to\n$B$. To formalize this notion using graphs we need to introduce a graph\ncorresponding to the map, consider a graph $G = (V, E)$ such that vertices of\nthe graph are areas in your map and $(A, B) \\in E$ iff the areas $A$ and $B$\nare connected by a portal. So a path from $A$ to $B$ is a sequence of areas\n$A = C_1$, \\dots, $C_\\ell = B$ such that $C_i$ and $C_{i + 1}$ are connected by\na portal (i.e. $(C_i, C_{i + 1}) \\in E$).\n\\begin{definition}\n  Let $G = (V, E)$ be a graph. We say that a path from $u$ to $v$ is\n  a sequence $w_1, \\dots, w_\\ell \\in V$\\footnote{%\n    Usually such an object is called a walk, and it is called a path if\n    all the vertices $w_1$, \\dots, $w_\\ell$ are different. However,\n    for our applications it does not matter and we will use the word ``path''.\n  } such that\n  \\begin{itemize}\n    \\item $w_1 = u$, $w_\\ell = v$, and\n    \\item $(w_i, w_{i + 1}) \\in E$ for $i \\in [\\ell - 1]$.\n  \\end{itemize}\n\n  We say that $u, v \\in V$ are connected iff there is a path from $u$ to $v$.\n  So the graph is connected iff any $u, v \\in V$ are connected.\n\\end{definition}\n\n\\begin{exercise}\n  Let $G = ([2n], E)$ be a graph such that $(i, j) \\in E$ if $|i - j| = 2$.\n  Is $G$ connected?\n\\end{exercise}\n\nSo, using this notation, we need to check whether the graph corresponding to\nthe map is connected. There are numerous ways to do it, we consider a simple\nalgorithm just to see how it works.\n\\begin{algorithm}\n  \\begin{algorithmic}[1]\n    \\Function{Connected}{$n$, $E$}\n      \\State $S \\gets \\emptyset$\n      \\State $Q \\gets \\set{1}$\n\n      \\label{algorithm:connectivity-cycle}\n      \\While{$Q \\neq \\emptyset$}\n        \\State Choose an element $v$ from $Q$\n        \\State $Q \\gets S \\setminus \\set{v}$\n\n        \\State $S \\gets S \\cup \\set{v}$\n\n        \\State $Q \\gets Q \\cup\n          \\set[{(v, u) \\in E \\text{ and } u \\notin S}]{u \\in \\range{n}}$\n      \\EndWhile\n      \\label{line:connectivity-last}\n      \\State \\Return{$S = \\range{n}$}\n    \\EndFunction\n  \\end{algorithmic}\n  \\caption{An algorithm checking whether the graph on $[n]$ with the set of\n  edges $E$ is connected.}\n  \\label{algorithm:connectivity}\n\\end{algorithm}\n\n\\begin{theorem}\n  Algorithm~\\ref{algorithm:connectivity} checks whether the graph $([n], E)$\n  is connected.\n\\end{theorem}\n\\begin{proof}\n  First of all, note that the algorithm has a finite running time since\n  size of $S$ increases by $1$ in the cycle starting on\n  line~\\ref{algorithm:connectivity-cycle}.\n  It is also easy to see that if a vertex $v \\in Q$ at some point it is\n  in $S$ on line~\\ref{line:connectivity-last}. In addition, if $v \\in Q$\n  at some point, then $\\set[{(v, u) \\in E}]{u \\in \\range{n}} \\subseteq S$ on\n  line~\\ref{line:connectivity-last}.\n\n  Therefore if $u \\notin S$ and $(v, u) \\in E$,\n  then $v \\notin S$. Using this observation we may prove that\n  if $G = ([n], E)$ is connected, then Algorithm~\\ref{algorithm:connectivity}\n  returns true. Indeed, assume the opposite. Consider $u \\in \\range{n} \\setminus S$,\n  and $N_i \\subseteq \\range{n}$ such that \\[\n    N_0 = \\set{u},\n    N_{i + 1} = N_i \\cup \\set[{w \\in N_i, (v, w) \\in E}]{v \\in \\range{n}}.\n  \\]\n  Note that by the previous observation if $v \\in N_i$, then $v \\notin S$.\n  Since $G$ is connected, there is a path $u = v_1, \\dots, v_k = 1$.\n  Note that $u \\in N_0$, $v_2 \\in N_1$, \\dots, $v_k \\in N_{k - 1}$.\n  Therefore $1 = v_k \\notin S$ which is a contradiction.\n\n  To finish the proof we need to show that if $S = \\range{n}$, then the graph is\n  connected. To prove the statement we prove by induction that there is a path\n  from $1$ to any element of $S$ and $Q$ in every iteration of\n  line~\\ref{algorithm:connectivity-cycle}. Indeed, initially $S$ is empty and\n  $Q$ contains only $1$. After an iteration of\n  line~\\ref{algorithm:connectivity-cycle} we choose an element $v$ from $Q$\n  and by the induction hypothesis there is a path from $1$ to $v$.\n  We add it to $S$ and the statement about $S$ holds, afterwards we\n  add all the neighbours of $v$ to $Q$. So the statement about $Q$ is\n  also true.\n\\end{proof}\n\nNot all the graphs are connected, but it is always possible to split the\ngraph into connected parts, such parts are called connected components.\n\\begin{definition}\n  Let $G = (V, E)$ be a graph. We say that $U \\subseteq V$ is a connected\n  component if for any $u \\in U$ and $v \\in V$,\n  $v \\in U$ iff there is a path from $u$ to $v$ in $G$.\n\\end{definition}\n\n\\begin{theorem}\n  Let $G = (V, E)$ be a graph.\n  If $U_1$ and $U_2$ are connected components of $G$, then they\n  either equal to each other or disjoint.\n  Moreover there are connected components\n  $V_1$, \\dots, $V_k$ in $G$ such that $V_1 \\cup \\dots \\cup V_k = V$\n  and $V_1$, \\dots, $V_k$ are disjoint.\n\\end{theorem}\n\n\\begin{exercise}\n  Let $G = ([2n], E)$ be a graph such that $(i, j) \\in E$ if $|i - j| = 2$.\n  Find all the connected components of $G$.\n\\end{exercise}\n\n\\begin{exercise}\n  Find a modification of Algorithm~\\ref{algorithm:connectivity}\n  that can find all the connected components of $([n], E)$.\n\\end{exercise}\n\n\\section{Eulerian Paths}\n\nGraph theory originated from a simple question asked by Leonard Euler:\n``Is it possible to walk through the town of K\\\"{o}nigsberg, starting and\nending at the same place, so that we use each bridge exactly once?'' (the map of\nK\\\"{o}nigsberg is depicted on Figure~\\ref{figure:konigsberg}).\n\\begin{figure}\n  \\begin{center}\n    \\begin{tikzpicture}[thick]\n      \\draw plot [smooth] coordinates {(0,0) (1, 0) (2,0.3) (3,0) (4,-0.3) (5, 0) (6, 0)};\n      \\draw plot [smooth] coordinates {(0, -3) (3.5, -3.3) (6, -3)};\n\n      \\draw plot [smooth] coordinates {(0,-1) (1, -1.1) (2, -1.5) (1, -1.9) (0,-2)};\n\n      \\draw plot [smooth cycle] coordinates {(4, -1) (5, -1.1) (6, -1.5) (5, -1.9) (4, -2)};\n\n      \\draw [line width=2mm] (0.5, 0.3) -- (0.5, -1.3);\n      \\draw [line width=2mm] (0.5, -3.3) -- (0.5, -1.7);\n      \\draw [line width=2mm] (4.5, 0.5) -- (4.5, -1.3);\n      \\draw [line width=2mm] (4.5, -3.5) -- (4.5, -1.7);\n      \\draw [line width=2mm] (5.5, 0.3) -- (5.3, -1.3);\n      \\draw [line width=2mm] (5.5, -3.3) -- (5.3, -1.7);\n      \\draw [line width=2mm] (1.7, -1.5) -- (4.1, -1.5);\n    \\end{tikzpicture}\n  \\end{center}\n  \\caption{K\\\"{o}nigsberg's map}\n  \\label{figure:konigsberg}\n\\end{figure}\nIt is possible to see that the geometry of the islands is not important for\nthis problem, the only important property is the number of bridges between\nislands.\n\nIn other words, all the necessary information can be described by the graph\n(the islands are vertices and the bridges are edges) depicted on\nFigure~\\ref{figure:konigsberg-graph}.\n\\begin{figure}\n  \\begin{center}\n    \\begin{tikzpicture}[thick]\n      \\node[circle, draw, inner sep=0pt, minimum size=6pt] (v1) at (0,0) {};\n      \\node[circle, draw, inner sep=0pt, minimum size=6pt] (v2) at (1,1) {};\n      \\node[circle, draw, inner sep=0pt, minimum size=6pt] (v3) at (-1,1) {};\n      \\node[circle, draw, inner sep=0pt, minimum size=6pt] (v4) at (0,2) {};\n\n      \\draw (v4) to[out=-60, in=150] (v2);\n      \\draw (v4) to[out=-30, in=120] (v2);\n      \\draw (v1) to[out=60, in=-150] (v2);\n      \\draw (v1) to[out=30, in=-120] (v2);\n      \\draw (v2) -- (v3);\n      \\draw (v1) -- (v3);\n      \\draw (v4) -- (v3);\n    \\end{tikzpicture}\n  \\end{center}\n  \\caption{The graph of K\\\"{o}nigsberg's bridges}\n  \\label{figure:konigsberg-graph}\n\\end{figure}\nHence, to formalize the problem we need to give the following definition.\n\\begin{definition}\n  A path $v_1$, \\dots, $v_k$ in a graph $G = (V, E)$ is called Eulerian if for\n  any edge $(u_1, u_2) \\in E$ there is exactly one $i \\in [k - 1]$ such that\n  $u_1 = v_i$ and $u_2 = v_{i + 1}$.\n\n  An Eulerian path is called an Eulerian cycle if $v_1 = v_k$.\n\\end{definition}\nUsing this definition the question is whether there exists an Eulerian cycle in\nthe graph of K\\\"{o}nigsberg's bridges.\n\n\\begin{exercise}\n  Check whether the graph of K\\\"{o}nigsberg's bridges has an Eulerian cycle or\n  not.\n\\end{exercise}\n\nThe following theorem gives a simple criterion that allows us to solve the\nproblem in the general case.\n\\begin{theorem}\n\\label{theorem:eulerian}\n  A connected graph $G$ has an Eulerian cycle if and only if all vertices\n  of $G$ have even degree.\n  (Note that the statement holds even if $G$ has parallel edges).\n\\end{theorem}\n\n\\begin{proof}\n  Assume that such a cycle exists\n  If a vertex $v$ appears $k$ times in the cycle, then there are $2k$ edges\n  involving $v$ in the cycle (because, each time $v$ is visited, there is an\n  edge used to step on $v$ and one to leave from $v$); since the cycle contains\n  all the edges of the graph, $v$ has degree $2k$. Therefore all vertices have\n  even degree. This shows that if a connected graph contains an Eulerian cycle,\n  then every vertex has even degree.\n\n  To prove this statement in the other direction, we will prove by induction a\n  stronger statement, we will prove that if $G$ is a graph in which every\n  vertex has even degree, then every connected non-trivial connected\n  component of $G$ (a connected component is trivial if it contains only an\n  isolated vertex of degree zero) has an Eulerian cycle. We will proceed by\n  induction on the number of edges.\n\n  If there are zero edges, then every connected component has only one vertex\n  and so it is nothing to prove. This is the base case of the induction.\n\n  If we have a graph $G = (V,E)$ with a non-empty set of edges and in which\n  every vertex has even degree, then let $V_1$, \\dots, $V_m$ be the non-trivial\n  connected components of $V$. If $m \\ge 2$, then every connected component has\n  strictly less vertices than $G$, and so we can apply the inductive hypothesis\n  and find Eulerian cycles in each of $V_1$, \\dots, $V_m$.\n\n  It remains to consider the case in which the set $V'$ of vertices of non-zero\n  degree of $G$ are all in the same connected component. Let $G' = G[V']$.\n  Since every vertex of $G'$ has degree at least, there must be a cycle in\n  $G'$. Let $C$ be a simple cycle (that is, a cycle with no vertices repeated)\n  in $G'$, and let $G'' - C$. Since we have removed two edges from every\n  vertex, we have that $G''$ is still a graph in which every vertex has even\n  degree. Since $G''$ has fewer edges than $G'$ we can apply the induction\n  hypothesis, and find an Eulerian cycle in each non-trivial connected\n  component of $G''$. We can then patch together these Eulerian cycles with $C$\n  as follows: we traverse $C$, starting from any vertex; the first time we\n  reach one of the non-trivial connected components of $G''$, we stop\n  traversing $C$, and we traverse the Eulerian cycle of the component, then\n  continue on $C$, until we reach for the first time one of the non-trivial\n  connected components of $G''$ that we haven’t traversed yet, and so on. This\n  describes a Eulerian path into all of $G'$\n\\end{proof}\n\n\\begin{exercise}\n  Finish the proof of Theorem~\\ref{theorem:eulerian} by proving that if a graph\n  $G$ has only vertices of an odd degree, then there is a simple cycle in $G$.\n\\end{exercise}\n\n\\begin{corollary}\n  A graph $G$ has an Eulerian path starting and ending in two different\n  vertices if and only if in $G$ there are exactly two vertices with odd\n  degrees.\n  (Note that the statement holds even if $G$ has parallel edges).\n\\end{corollary}\n\\begin{proof}\n  Let $G = (V, E)$ and $u$ and $v$ be the vertices with odd degrees. Let us\n  consider the graph $G + (u, v) = (V, E \\cup (u, v))$ (if there are edges\n  between $u$ and $v$ we increase their number by one). Note that all\n  the degrees in $G + (u, v)$ are even.\n  \\nomenclature[G]{$G + e$}{denotes the graph $(V, E \\cup \\set{e})$}\n  Therefore by Theorem~\\ref{theorem:eulerian}, there is an Eulerian cycle in\n  $G + (u, v)$. Without loss of generality the cycle is in the form $u$, $v$,\n  $w_1$, \\dots, $w_k$, $v$. Therefore, there is an Eulerian path $v$,\n  $w_1$, \\dots, $w_k$, $v$ in $G$.\n\\end{proof}\n\n\\section{Hamiltonian Paths}\n\nAnother example of a path that mathematicians are interested in is Hamiltonian\npath.\n\\begin{definition}\n  Let $G$ be a graph. We say that a path in $G$ is Hamilton\n  if it visits every vertex in $G$ exactly once. We say that such a path is a\n  Hamiltonian cycle if its starting and ending vertices are\n  connected.\\footnote{%\n    Hamiltonian paths and cycles are named after William Rowan Hamilton who\n    invented the icosian game, now also known as Hamilton's puzzle, which\n    involves finding a Hamiltonian cycle in the edge graph of the dodecahedron.\n  }\n\\end{definition}\n\nThe greatest difference with Eulerian cycles is that it is not known whether\nthere is a fast (polynomial-time) algorithm that allows to find the Hamiltonian\ncycles in a graph.\\footnote{%\n  Proving or disproving that there is a polynomial-time algorithm allowing to\n  check whether a graph $G$ has a Hamiltonian path is one of the Millennium\n  Problems. Clay Mathematics Institute offers a prize of \\$1 million to a person\n  who solves the problem.\n}\n\nIt is easy to design an algorithm that checks whether a path exists in\n$O((n - 1)!)$ by just brute forcing all the possible candidates for such a path.\nHowever, using the ideas of the inclusion-exclusion principle, we may design\na much faster algorithm.\n\\begin{theorem}\n\\label{theorem:hamiltonian-algorithm}\n  There is an algorithm with the running time $O(2^n n^3)$ such that it finds\n  the number of Hamiltonian cycles in a graph $G = ([n], E)$.\n\\end{theorem}\n\nBefore we prove the theorem, recall that if $U$ and\n$A_1, \\dots, A_n \\subseteq U$ are some finite sets, then\n\\[\n  \\left| \\bigcap_{i = 1}^n A_i \\right| =\n  \\sum_{X \\subseteq \\range{n}} (-1)^{|X|}\n    \\left| \\bigcap_{i \\in X} \\overline{A}_i \\right|,\n\\]\nwhere $\\overline{A}_i = U \\setminus A_i$ and\n$\\bigcap_{i \\in \\emptyset} \\overline{A}_i = U$.\n\n\\begin{proof}[Proof of Theorem~\\ref{theorem:hamiltonian-algorithm}]\n  As we mentioned before we the inclusion-exclusion principle to find the number\n  of Hamilton cycles. Let $U$ be the set of all the cycles of length $n$\n  (length is the number of edges in the path) going\n  via the vertex $1$ and $A_v \\subseteq U$ ($v \\in \\range{n})$ be the set of cycles of\n  length $n$ going via the vertices $1$ and $v$.\n\n  It is clear that the answer is $\\left| \\bigcap_{i = 1}^n A_i \\right|$.\n  Therefore it is enough to find all the cardinalities of\n  $\\left| \\bigcap_{i \\in X} \\overline{A}_i \\right|$. Note that\n  $\\bigcap_{i \\in X} \\overline{A}_i$ is equal to the set of all the cycles of\n  length $n$ going via the vertex $1$ in $G - X$. We denote the cardinality of\n  this set by $C_X$.\n\n  To find the value of $C_X$ we use the following notation.\n  Let $E_X$ be the set of edges in $G - X$ and let $T_X(d, x)$ be\n  the number of length $d$ paths from $1$ to $x \\in \\range{n} \\setminus X$ in $G - X$.\n  Clearly $T_X(0, x) = 1$ if $x = 1$ and $T_X(0, x) = 0$ otherwise. In addition,\n  $T_X(d + 1, x) = \\sum_{y ~:~ (y, x) \\in E_X} T_X(d, y)$. Therefore, we may\n  compute $T_X(n, x)$ for all $x \\in \\range{n} \\setminus X$ in $n^3$ steps. As a\n  result, we may find the value of $\\sum_{X \\subseteq \\range{n}} (-1)^{|X|} C_X$ in\n  $2^n n^3$ steps.\n\\end{proof}\n\nHowever, one may prove that if all the vertices in a graph have large degree,\nthen the graph has a Hamiltonian cycle.\n\\begin{theorem}[Dirac]\n  Let $G$ be a graph on $n \\ge 3$ vertices. If every vertex $v$ in $G$ has\n  degree at least $n / 2$, then there is a Hamiltonian cycle in $G$.\n\\end{theorem}\n\\begin{proof}\n  For the sake of contradiction, let us assume that $G$ has no Hamiltonian\n  cycle but all the vertices have degree at least degree $n / 2$, where $n$ is\n  the number of vertices in $G$.\n\n  Let us start adding edges to $G$ as long as we are not creating a\n  Hamiltonian cycle. When we stop we get a graph $H = (V, E)$ such that\n  all the vertices of $H$ have degree at least $n / 2$, $H$ does\n  not have a Hamiltonian cycle, but adding any new edge would create a\n  Hamiltonian cycle.\n\n  Consider any two vertices $x$ and $y$ that are not connected by\n  an edge. We know that in the graph $H + (x, y)$ there is\n  a Hamiltonian cycle $x = v_1$, \\dots, $v_n = y$. Note that\n  $|\\set[{(x, v) \\in E \\text{ or } (y, v) \\in E}]{v \\in V}| \\ge n$\n  since $\\deg_H(x) \\ge n / 2$ and $\\deg_H(y) \\ge n / 2$.\n  Therefore by the pigeonhole principle, there is $2 \\le i \\le n - 1$\n  such that $(x, v_i) \\in E$ and $(v_{i - 1}, y) \\in E$. As a result,\n  $x$, $v_2$, \\dots, $v_{i - 1}$, $y$, $v_{n - 1}$, \\dots, $v_i$\n  is a Hamiltonian cycle in $H$.\n\\end{proof}\n\nThere are plenty of different applications of Hamiltonian paths. Here we describe\nthe one that comes from bioinformatics.\n\nImagine that we want to read a DNA strand, i.e., determine the order in which\nnucleotides occur on a strand of DNA. One of the methods, called\n``Sequencing by Hybridization'', is based on Hamiltonian paths.\n\nThe method works as follows.\n\\begin{itemize}\n  \\item Attach all possible DNA probes of length $k$ to a flat surface, each\n    probe at a distinct and known location. This set of probes is called\n    the DNA microarray.\n  \\item Apply a solution containing fluorescently labeled copies of a DNA\n    fragment to the array.\n  \\item The DNA fragment hybridizes with those probes that are\n    complementary to substrings of length $k$ of the fragment.\n  \\item Using a spectroscopic detector, determine which probes hybridize to\n    the DNA fragment to obtain the $k$-mer composition of the DNA fragment.\n  \\item Reconstruct the sequence of the DNA fragment from the $k$-mer\n    composition.\n\\end{itemize}\n\nIn other words, we need to reconstruct a string $s$ from all $n - k + 1$\nsubstrings of length $k$; e.g, we need to reconstruct the string TATGGTGC\nfrom the strings ATG, GGT, GTG, TAT, TGC, TGG (in this example $k = 3$).\n(Note that different strings may have the same sets of substrings.\nStrings GTATCT and GTCTAT correspond to the strings\nAT, CT, GT, TA, TC when $k = 2$.)\n\nBy a given set $p_1$, \\dots, $p_\\ell$ of strings ($k$-mers) of length $k$\nwe construct the following graph. There are $\\ell$ vertices corresponding to\nthe strings $p_1$, \\dots, $p_\\ell$; there is an edge between $p_i$ and $p_j$\nwhenever the same string of length $k - 1$ is a suffix of $p_i$ and a\nprefix of $p_j$ (for example, TG is a suffix of ATG and a prefix of TGG).\nIt is easy to see that we can find a string corresponding to\n$p_1$, \\dots, $p_\\ell$ if we have a Hamiltonian path in the graph.\n\n\\begin{chapterendexercises}\n  \\exercise Is it true that if a graph has a closed Eulerian walk, then it has\n    an even number of edges?\n  \\exercise Let $G$ be a graph such that every vertex has degree $4$. Show that\n    it is possible to color edges of the graph into two colors, red and blue,\n    such that every vertex has exactly two red edges and two blue edges.\n    \\begin{solution}\n      Without loss of generality the graph is connected. Since all the vertices\n      of $G$ have even degree, there is an Euler cycle $e_1$, \\dots, $e_m$ in\n      $G$. We color $e_{2k}$ in red and $e_{2k + 1}$ in blue, for all possible\n      $k$. Note that for every vertex $v$ (except the first in the path) there\n      are $j_1 \\neq j_2$ such that $e_{j_1}$, $e_{j_1 + 1}$, $e_{j_2}$, $e_{j_2\n      + 1}$ are going from $v$. Hence, $v$ has exactly two red edges and two\n      blue edges. As about the first vertex, note that number of edges in the\n      graph is equal to $m = 2n$, hence, $e_m$ is colored on red and $e_1$ is\n      colored in blue. Additionally, there is $j_1$ sucht that $e_{j}$ and $e_{j\n      + 1}$ are going from the first vertex. Hence, the first vertex has exactly\n      two red edges and two blue edges.\n    \\end{solution}\n  \\exercise[recommended] Let $G$ be a graph such that there are only $2$\n    vertices with odd degree. Prove that they belong to the same connected\n    component.\n  \\exercise Let $G = (V, E)$ be a connected graph and $c : V \\to \\set{0, 1}$\n    be a function.\n    \\begin{enumerate}\n      \\item Assume that $\\sum_{v \\in V} c(v)$ is odd.\n        Show that for any $s : E \\to \\set{0, 1}$, there is a vertex\n        $v \\in V$ such that $\\sum_{(u, v) \\in E} s(u, v)$ and $c(v)$\n        have different remainders modulo $2$.\n      \\item Assume that $\\sum_{v \\in V} c(v)$ is even.\n        Show that there is a function $s : E \\to \\set{0, 1}$\n        such that $\\sum_{(u, v) \\in E} s(u, v)$ is odd iff $c(v)$ is odd\n        for all $v \\in V$.\n    \\end{enumerate}\n  \\exercise Find a minimal $k(n)$ such that for any graph $G$ on $n$ vertices,\n    if $G$ has at least $k(n)$ edges, then $G$ is connected.\n    \\begin{solution}\n      Let $G$ be some graph. The graph $G$ has at most $\\binom{n}{2}$ many edges\n      by \\Cref{exercise:maximal-number-of-edges}.\n\n      Let us assume that $G$ is not connected i.e. we may split $G$ into two\n      disjoint subgraphs $G_1$ and $G_2$ of $G$ such that vertices of $G_1$ are\n      not connected with vertices of $G_2$. Let $n_1$ and $n_2$ denote the\n      number of vertices in $G_1$ and $G_2$ respectively. Note that $G_i$ has at\n      most $\\binom{n_i}{2}$ edges for every $i \\in \\range{2}$. Hence, $G$ has at\n      most $\\binom{n_1}{2} + \\binom{n_2}{2}$ edges.\n\n      However, $f(n_1) = \\binom{n_1}{2} + \\binom{n - n_1}{2}$ reaches the minimum for \n      $1 \\le n_1 \\le n - 1$ at $n_1 = 1$. As a result, $k(n) \\le \\binom{n - 1}{2} + 1$.\n\n      Additionally, note that there is a not connected graph $G$ with $\\binom{n\n      - 1}{2}$ edges (it is a complete graph on $n - 1$ vertices and one\n      additional vertex). Thus $k(n) = \\binom{n-1}{2} + 1$.\n    \\end{solution}\n  \\exercise Show that the following graph has no Hamiltonian cycle.\n    \\begin{center}\n    \t\\begin{tikzpicture}[scale=0.5, thick]\n\t\t    % Draw a 7,11 network\n    \t\t% First we draw the vertices\n\t\t    \\foreach \\pos/\\name in {{(0,0)/1}, {(3,0)/2}, {(5,0)/3},\n        \t                    {(7,0)/4}, {(10,0)/5}, {(4,2)/6}, {(6,2)/7},\n\t\t\t  \t    {(5,4)/8}, {(4,-2)/9}, {(6,-2)/10}, {(5,-4)/11}}\n\t\t\t    \\node[circle, draw, inner sep=0pt, minimum size=6pt] (\\name) at \\pos {};\n    \t\t\\foreach \\source/ \\dest in {1/2, 4/5, 2/6, 2/9, 3/6, 3/9, 3/7,\n\t\t  \t\t    3/10, 4/7, 4/10, 8/6, 8/7, 11/9, 11/10, 1/8, 1/11, 5/8, 5/11}\n\t\t\t    \\draw (\\source) -- (\\dest);\n        \\end{tikzpicture}\n  \t\\end{center}\n    \\begin{solution}\n      Note that we can color all the vertices in black and yellow so that\n      vertices of the same color are not adjacent.\n      \\begin{center}\n        \\begin{tikzpicture}[scale=0.5, auto,swap]\n        \t% Draw a 7,11 network\n        \t% First we draw the vertices\n      \t  \\foreach \\pos/\\name in {{(3,0)/2}, {(5,0)/3},\t{(7,0)/4}, \n              {(5,4)/8}, {(5,-4)/11}}\n            \\node[circle, fill=black, draw, inner sep=0pt, minimum size=6pt] \n              (\\name) at \\pos {};\n          \\foreach \\pos/\\name in {{(0,0)/1}, {(10,0)/5}, {(4,2)/6}, \n              {(6,2)/7}, {(4,-2)/9}, {(6,-2)/10}}\n      \t\t  \\node[circle, fill=yellow, draw, inner sep=0pt, minimum size=6pt]\n              (\\name) at \\pos {};\n      \t  \\foreach \\source/ \\dest in {1/2, 4/5, 2/6, 2/9, 3/6, 3/9, 3/7, \n              3/10, 4/7, 4/10, 8/6, 8/7, 11/9, 11/10, 1/8, 1/11, 5/8, 5/11}\n      \t\t  \\draw (\\source) -- (\\dest);\n        \\end{tikzpicture}\n      \\end{center}\n      Note that there are $11$ vertices in total, there are $6$ yellow vertices\n      and $5$ black. Assume that there is a Hamiltonian path $v_1$, \\dots,\n      $v_11$. Without loss of generality $v_1$ is yellow. This implies that\n      $v_1$, $v_3$, $v_5$, $v_7$, $v_9$, and $v_11$ are also yellow since\n      vertices of the same color are not adjacent. However, it also mean that\n      $v_1$ and $v_11$ are adjacent and of the same color, which is a contradiction.\n    \\end{solution}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "c5010318cda6af2936f78d71889c840a8ad59f7d", "size": 24134, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_8/chapter_33_paths.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_8/chapter_33_paths.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_8/chapter_33_paths.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": 47.8849206349, "max_line_length": 92, "alphanum_fraction": 0.657329908, "num_tokens": 7897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998560157665, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.6820625867931503}}
{"text": "\\section{Second Order Homogeneous Equations}{}{}\\label{sec:second order homogeneous}\nA second order differential equation is one containing the second\nderivative $y''$. These are in general quite complicated, but one fairly\nsimple type is useful: The second order linear equation with constant\ncoefficients. \n\n\\begin{example}{Second Order Homogeneous Equation}{Second Order Homogeneous Equation}\\label{Second Order Homogeneous Equation}\nAnalyze the intial value problem $y''-y'-2y=0$,\n$y(0)=5$, $y'(0)=0$. \n\\end{example}\n\n\\begin{solution}\nWe make an inspired guess: might there be a\nsolution of the form $\\ds e^{rt}$? This seems at least plausible,\nsince in this case $\\ds y''$, $\\ds y'$, and $y$ all\ninvolve $\\ds e^{rt}$. \n\nIf such a function is a solution then\n\\begin{eqnarray*}\nr^2 e^{rt}-r e^{rt}-2e^{rt}&=&0\\cr\ne^{rt}(r^2-r-2)&=&0\\cr\n(r^2-r-2)&=&0\\cr\n(r-2)(r+1)&=&0,\n\\end{eqnarray*}\nso $r$ is $2$ or $-1$. Not only are $\\ds f=e^{2t}$ and $\\ds g=e^{-t}$\nsolutions, but notice that $\\ds y=Af+Bg$ is also, for any constants $A$\nand $B$:\n\\begin{eqnarray*}\n(Af+Bg)''-(Af+Bg)'-2(Af+Bg)&=&Af''+Bg''-Af'-Bg'-2Af-2Bg\\cr\n&=&A(f''-f'-2f)+B(g''-g'-2g)\\cr\n&=&A(0)+B(0)=0.\n\\end{eqnarray*}\nCan we find $A$ and $B$ so that this is a solution to the initial\nvalue problem? Let's substitute:\n$$\n5=y(0)=Af(0)+Bg(0)=Ae^0+Be^0=A+B\n$$\nand \n$$0=y'(0)=Af'(0)+Bg'(0)=A2e^{0}+B(-1)e^0=2A-B.$$\nSo we need to solve this system of \\underline{two} equations with \\underline{two} unknowns:\n\\[\n\\left\\{\n\\begin{array}{ll}\nA+B\t&\t=5\t\\\\\n2A-B\t&\t=0\n\\end{array}\n\\right.\n\\]\nLet $B=2A$, substitute into the first equation to get $5=A+2A=3A$. Then $A=5/3$ and $B=10/3$, and the\ndesired solution is $\\ds (5/3)e^{2t}+(10/3)e^{-t}$. You now see why\nthe initial condition in this case included both $y(0)$ and $y'(0)$:\nWe needed two equations in the two unknowns $A$ and $B$\n\\end{solution}\n\nYou should of course wonder whether there might be other solutions, but as it turns out,\nthe answer is no. We will not prove this, but here is the theorem that\ntells us what we need to know:\n\n\\begin{theorem}{Solutions to Second Order Homogeneous}{Solutions to Second Order Homogeneous}\\label{Solutions to Second Order Homogeneous}\nGiven the differential equation $\\ds ay''+by'+cy=0$, $a\\not=0$,\nconsider the quadratic polynomial $ar^2+br+c=0$, called the\n\\dfont{characteristic polynomial}. Using the quadratic formula, this polynomial\nalways has one or two roots, call them $r_1$ and $r_2$.  The general\nsolution of the differential equation is:\n\n\\begin{enumerate}[(a)]\n\\item\t$\\ds y=Ae^{r_1t}+Be^{r_2t}$, if the roots $r_1$ and $r_2$ are real\n  numbers, and $r_1\\not=r_2$.\n\\item\t$\\ds y=Ae^{r_1t}+Bte^{r_2t}$, if $r_1=r_2$ is a real, repeated root.\n\\item\t$\\ds y=A\\cos(\\beta t)e^{\\alpha t}+B\\sin(\\beta t)e^{\\alpha t}$, \nif the roots are complex numbers, $r=\\alpha\\pm\\beta i$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{example}{}{}\n\tSolve the differential equation $y''+A^2y=0$.\n\\end{example}\n\\begin{solution}\n\tFirst we write the characteristic equation, $r^2+A^2=0$. Then we find the roots of the characteristic equation: \n\t\\[r^2=-A^2\\implies r=\\pm Ai\\]\n\tThese are imaginary roots, so the solution of the differential equation is in the form:\n\t\\[y=c_1\\cos(At)+c_2\\sin(At)\\]\n\\end{solution}\n\n\\begin{example}{}{}\n\tSolve the differential equation $y''-A^2y=0$.\n\\end{example}\n\\begin{solution}\n\tFirst we write the characteristic equation, $r^2-A^2=0$. Then we find the roots of the characteristic equation: \n\t\\[r^2=A^2\\implies r=\\pm A\\]\n\tThese are imaginary roots, so the solution of the differential equation is in the form:\n\t\\[y=c_1e^{At}+c_2e^{-At}=c_1e^{At}+\\frac{c_2}{e^{At}}\\]\n\\end{solution}\n\n\\begin{example}{Damped Spring Oscillation}{Damped Spring Oscillation}\\label{Damped Spring Oscillation}\nUse a differential equation to describe the position of a mass hung on a spring.\n\\end{example}\n\n\\begin{solution}\n Suppose a mass $m$ is hung on a spring with spring\nconstant $k$. If the spring is compressed or stretched and then\nreleased, the mass will oscillate up and down. Due to friction,\nthe oscillation will be damped: Eventually the motion will cease. The\ndamping will depend on the amount of friction; for example, if the\nsystem is suspended in oil the motion will cease sooner than if the\nsystem is in air. Using some simple physics, it is not hard to see\nthat the position of the mass is described by the differential\nequation:\n$\\ds my''+by'+ky=0$. Using $m=1$, $b=4$, and $k=5$ we find the\nmotion of the mass. The characteristic polynomial is \n$r^2+4r+5=0$, with roots $r=(-4\\pm\\sqrt{16-20})/2=-2\\pm i$. Thus the\ngeneral solution is\n$\\ds y=A\\cos(t)e^{-2t}+B\\sin(t)e^{-2t}$.\nSuppose we know that $y(0)=1$ and $y'(0)=2$. Then as before we\nform two simultaneous equations: From $y(0)=1$ we get\n$1=A\\cos(0)e^0+B\\sin(0)e^0=A$. For the second we compute\n$$y''=-2Ae^{-2t}\\cos(t)+Ae^{-2t}(-\\sin(t))-2Be^{-2t}\\sin(t)+\nBe^{-2t}\\cos(t),$$\nand then\n$$2=-2Ae^0\\cos(0)-Ae^0\\sin(0)-2Be^0\\sin(0)+Be^0\\cos(0)\n=-2A+B.$$\nSo we get $A=1$, $B=4$, and $\\ds y=\\cos(t)e^{-2t}+4\\sin(t)e^{-2t}$.\n\nHere is a useful trick that makes this easier to understand: We have\n$\\ds y=(\\cos t+4\\sin t)e^{-2t}$. The expression $\\cos t+4 \\sin t$ is a\nbit reminiscent of the trigonometric formula\n$\\cos(\\alpha-\\beta)=\\cos(\\alpha)\\cos(\\beta)+\\sin(\\alpha)\\sin(\\beta)$\nwith $\\alpha=t$.\nLet's rewrite it a bit as\n$$\\sqrt{17}\\left({1\\over\\sqrt{17}}\\cos t + {4\\over\\sqrt{17}}\\sin t\\right).$$\nNote that $\\ds (1/\\sqrt{17})^2+(4/\\sqrt{17})^2=1$, \nwhich means that there is an angle\n$\\beta$ with $\\ds \\cos\\beta=1/\\sqrt{17}$ and \n$\\ds \\sin\\beta=4/\\sqrt{17}$ (of course, $\\beta$ may not be a ``nice'' angle). Then\n$$\\cos t+4\\sin t = \\sqrt{17}\\left(\\cos t\\cos \\beta+\\sin\\beta\\sin t\\right)\n=\\sqrt{17}\\cos(t-\\beta).$$\nThus, the solution may also be written\n$\\ds y=\\sqrt{17}e^{-2t}\\cos(t-\\beta)$.\nThis is a cosine curve  that has been shifted $\\beta$ to the\nright; the $\\ds \\sqrt{17}e^{-2t}$ has the effect of diminishing the\namplitude of the cosine as $t$ increases.\n%; see figure~\\ref{fig:damped oscillation}. The oscillation is damped very\n%quickly, so in the first graph it is not clear that this is an\n%oscillation. The second graph shows a restricted range for $t$.\n\\end{solution}\n\nOther physical systems that oscillate can also be described by such\ndifferential equations. Some electric circuits, for example, generate\noscillating current.\n\n%\\figure[!ht]\n%%\\texonly\n%\\hbox to \\hsize{\\hfill\n%\\def\\yarrow{-- +(-1.5pt,-3pt) +(0pt,0pt) -- +(1.5pt,-3pt) +(0pt,0pt)}\n%\\def\\xarrow{-- +(-3pt,-1.3pt) +(0pt,0pt) -- +(-3pt,1.5pt) +(0pt,0pt) }\n%\\tikzpicture[domain=0:3,x=1.2cm,y=3cm]\n%\\draw (0,0) -- (5.2,0) \\xarrow node [right] {$x$};\n%\\draw (0,0) -- (0,1.3) \\yarrow node [above] {$y$};\n%\\gpad\n%\\draw[color=black] plot[smooth,id=\\the\\gpnum,domain=0:5] function{sqrt(17)*exp(-2*x)*cos(x-asin(4/sqrt(17)))};\n%\\foreach \\x in {1,2,3,4,5} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\n%\\foreach \\y in {0,1} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east]\n         %{$\\y$};\n%\\endtikzpicture\n%\\hfill\n%\\tikzpicture[domain=2.5:5,x=1.6cm,y=120cm]\n%\\draw (2.5,0) -- (5.2,0) \\xarrow node [right] {$x$};\n%\\draw (2.5,0) -- (2.5,0.03) \\yarrow node [above] {$y$};\n%\\gpad\n%\\draw[color=black] plot[smooth,id=\\the\\gpnum,domain=2.5:5] function{sqrt(17)*exp(-2*x)*cos(x-asin(4/sqrt(17)))};\n%\\foreach \\x in {3,4,5} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\n%\\foreach \\y in {0,0.01,0.02} \\draw (2.5,\\y) -- (2.4,\\y) node[anchor=east] {$\\y$};\n%\\endtikzpicture\n%\\hfill}%\\endtexonly\n%%\\figrdef{fig:damped oscillation}\n%%\\htmlfigure{DE-damped_oscillation.html}\n%\\caption{\\label{fig:damped oscillation}\n%Graph of a damped oscillation.}\n%%\\endcaption\n%\\endfigure\n\n\\begin{example}{}{}\\label{}\n Find the solution to the intial value problem\n$\\ds y''-4y'+4y=0$, $y(0)=-3$, $y'(0)=1$.\n\\end{example}\n\n\\begin{solution}\nThe characteristic polynomial is $r^2-4r+4=(r-2)^2$, so there is one root,\n$r=2$, \nand the general solution is $\\ds Ae^{2t}+Bte^{2t}$. Substituting\n$t=0$ we get $-3=A+0=A$. The first derivative is\n$\\ds 2Ae^{2t}+2Bte^{2t}+Be^{2t}$; substituting $t=0$ gives\n$1=2A+0+B=2A+B=2(-3)+B=-6+B$, so $B=7$. The solution is\n$\\ds -3e^{2t}+7te^{2t}$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:second order homogeneous}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%%\n%\\begin{ex}\n %Verify that the function in part (a) of\n%theorem~\\xrefn{thm:solns to second order homogeneous} is a solution to\n%the differential equation $\\ds ay''+by'+cy=0$.\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\begin{ex}\n %Verify that the function in part (b) of\n%theorem~\\xrefn{thm:solns to second order homogeneous} is a solution to\n%the differential equation $\\ds ay''+by'+cy=0$.\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\begin{ex}\n %Verify that the function in part (c) of\n%theorem~\\xrefn{thm:solns to second order homogeneous} is a solution to\n%the differential equation $\\ds ay''+by'+cy=0$.\n%\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem $\\ds y''-\\omega^2y=0$,\n$y(0)=1$, $\\ds y'(0)=1$, assuming $\\omega\\not=0$.\n\\begin{sol}\n $\\ds {\\omega+1\\over2\\omega}e^{\\omega t}+\n{\\omega-1\\over2\\omega}e^{-\\omega t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem $\\ds2y''+18y=0$,\n$y(0)=2$, $\\ds y'(0)=15$.\n\\begin{sol}\n $\\ds 2\\cos(3t)+5\\sin(3t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+6y' +5y=0$,\n$y(0)=1$, $\\ds y'(0)=0$.\n\\begin{sol}\n $\\ds -(1/4)e^{-5t}+(5/4)e^{-t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''-y'-12y=0$,\n$y(0)=0$, $\\ds y'(0)=14$.\n\\begin{sol}\n $\\ds-2e^{-3t}+2e^{4t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+12y'+36y=0$,\n$y(0)=5$, $\\ds y'(0)=-10$.\n\\begin{sol}\n $\\ds 5e^{-6t}+20te^{-6t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''-8y'+16y=0$,\n$y(0)=-3$, $\\ds y'(0)=4$.\n\\begin{sol}\n $\\ds (16t-3)e^{4t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+5y=0$,\n$y(0)=-2$, $\\ds y'(0)=5$.\n\\begin{sol}\n $\\ds -2\\cos(\\sqrt5t)+\\sqrt{5}\\sin(\\sqrt{5}t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+y=0$,\n$y(\\pi/4)=0$, $\\ds y'(\\pi/4)=2$.\n\\begin{sol}\n $\\ds -\\sqrt2\\cos t+\\sqrt2\\sin t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+12y'+37y=0$,\n$y(0)=4$, $\\ds y'(0)=0$.\n\\begin{sol}\n $\\ds e^{-6t}\\left(4\\cos t+24\\sin t\\right)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+6y'+18y=0$,\n$y(0)=0$, $\\ds y'(0)=6$.\n\\begin{sol}\n $\\ds 2e^{-3t}\\sin(3t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+4y=0$,\n$y(0)=\\sqrt3$, $\\ds y'(0)=2$. \n%Put your answer in the form developed\n%at the end of exercise~\\xrefn{example:damped spring oscillation}.\n\\begin{sol}\n $\\ds 2\\cos(2t-\\pi/6)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+100y=0$,\n$y(0)=5$, $\\ds y'(0)=50$. \n%Put your answer in the form developed\n%at the end of exercise~\\xrefn{example:damped spring oscillation}.\n\\begin{sol}\n $\\ds 5\\sqrt2\\cos(10t-\\pi/4)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''+4y'+13y=0$,\n$y(0)=1$, $\\ds y'(0)=1$. \n%Put your answer in the form developed\n%at the end of exercise~\\xrefn{example:damped spring oscillation}.\n\\begin{sol}\n $\\ds \\sqrt2 e^{-2t}\\cos(3t-\\pi/4)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem \n$\\ds y''-8y'+25y=0$,\n$y(0)=3$, $\\ds y'(0)=0$. \n%Put your answer in the form developed\n%at the end of exercise~\\xrefn{example:damped spring oscillation}.\n\\begin{sol}\n $\\ds 5e^{4t}\\cos(3t+\\arcsin(4/5))$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A mass-spring system $\\ds my''+by'+kx$ has\n$k=29$, $b=4$, and $m=1$. At time $t=0$ the position is $y(0)=2$ and\nthe velocity is $y'(0)=1$. Find $y(t)$.\n\\begin{sol}\n $\\ds (2\\cos(5t)+\\sin(5t))e^{-2t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A mass-spring system $\\ds my''+by'+kx$ has\n$k=24$, $b=12$, and $m=3$. At time $t=0$ the position is $y(0)=0$ and\nthe velocity is $y'(0)=-1$. Find $y(t)$.\n\\begin{sol}\n $\\ds-(1/2)e^{-2t}\\sin(2t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Consider \n%\\exrdef{exer:second order really first order}\nthe differential equation $\\ds ay'' + by'=0$,\nwith $a$ and $b$ both non-zero. Find the general solution by the\nmethod of this section. Now let $\\ds g=y'$; the equation may be\nwritten as $\\ds ag'+bg=0$, a first order linear homogeneous\nequation. Solve this for $g$, then use the relationship $\\ds g=y'$ to\nfind $y$.\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Suppose that $y(t)$ is a solution to $\\ds ay''+by'+cy=0$, $y(t_0)=0$, $\\ds y'(t_0)=0$. Show that $y(t)=0$.\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "156cc8deeb61fe790c884a9b0a766e92ad828e39", "size": 12782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-5-second-order-homo.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-5-second-order-homo.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-5-second-order-homo.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0046948357, "max_line_length": 138, "alphanum_fraction": 0.6388671569, "num_tokens": 4849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.6820625863389164}}
{"text": "% Copyright 2016 The FANCy Project, licensed under GNU FDL v1.3\n% main author: \n%   Markus J. Pflaum\n%\n\\section{Some useful inequalities}\n\\label{sec:useful-inequalities}\n%\n%\nIn this section we collect several inequalities from real analysis which will \nbe of use later in this monograph. \n\\begin{theorem}[Young's inequality]\n\\label{thm:Youngs-inequality}\nLet $a,b \\geq 0$, and assume that $p,q >1$ satisfy the relation $\\frac 1p + \\frac 1q =1$. Then \n\\[\n   ab \\leq \\frac 1p a^p + \\frac 1q b^q \\: .\n\\]\n  Equality holds if and only if $a^p = b^q$. \n\\end{theorem}\n\\begin{proof}\nSince the second derivative $\\exp''$ of the exponential function attains\nonly positive values, the function $\\exp$ is strictly convex that means satisfies\n\\[\n   \\exp \\big( \\lambda x + (1-\\lambda) y \\big) \\leq \n   \\lambda \\exp ( x ) +   (1-\\lambda)  \\exp ( y ) \n\\]\nfor all $x,y\\in \\R$ and $\\lambda \\in [0,1]$ with equality holding true if and only if $x = y$ or $\\lambda \\in \\{ 1,0 \\}$.\nPutting $x = p \\ln a$, $y = q \\ln b$, and $\\lambda = \\frac 1p$ one obtains\n\\[\n   ab = \\exp\\big( \\lambda x + (1-\\lambda) y \\big)   \\leq \n   \\lambda \\exp ( x ) +   (1-\\lambda)  \\exp ( y ) = \\frac 1p a^p + \\frac 1q b^q \\: .\n\\]\nEquality holds if and only if $x = y$ which is equivalent to  $a^p = b^q$.\n\\end{proof}\n\\begin{theorem}[Cauchy--Schwarz inequality for sums]\n\\label{thm:Cauchy-Schwartz-inequality-for-sums}\nLet $v,w \\in \\C^n$. Then \n\\[\n  \\Big| \\sum_{i=1}^n v_i \\overline{w_i} \\: \\Big|^2 \\leq \\Big( \\sum_{i1}^n |v_i|^2 \\Big)  \\Big( \\sum_{i=1}^n |w_i|^2 \\Big).\n\\]  \nEquality holds true if and only if  $v$ and $w$ are linearly dependant. \n\\end{theorem}\n\\begin{proof}\nLet us use the \\emph{inner product} notation \n\\[\n   \\langle v,w\\rangle := \\sum_{i=1}^n v_i \\overline{w_i} \\quad \\text{for } v,w\\in \\C^n.\n\\]\nThen the $\\ell^2$-\\emph{norm}\n\\[\n  \\| v \\| :=  \\left( \\sum_{i=1}^n |v_i|^2\\right)^{1/2} = \\langle v , v \\rangle^{1/2}\n\\]\nis well-defined and non-negative for any $v\\in \\C^n$. If $\\|v \\| =0$ or $\\| w \\|= 0$, then $v=0$ or $w=0$, and \nthe claim is trivial. So we assume $\\|v \\|, \\| w \\| > 0$ and compute \n\\begin{equation}\n\\label{eq:inequality-chain}\n\\begin{split}\n  0 \\leq \\, & \\big\\langle \\|w\\| v - \\|v\\| w , \\|w\\| v - \\|v\\| w \\big\\rangle  = \n  \\sum_{i=1}^n \\big( \\|w\\| v_i - \\|v\\| w_i \\big)\\big( \\|w\\| \\overline{v_i} - \\|v\\| \\overline{w_i} \\big)  = \\\\ \n  = \\, &   \\sum_{i=1}^n \\|w\\|^2 v_i\\overline{v_i} - \\|w\\| \\|v\\| v_i \\overline{w_i}  -  \\|w\\| \\|v\\| w_i \\overline{v_i} \n    +  \\|v\\|^2 w_i\\overline{w_i}  = \\\\\n  = \\, &  2 \\|v\\|\\|w\\| \\Big(  \\|v\\|\\|w\\| - \\Re \\langle v,w \\rangle \\Big) .\n\\end{split}\n\\end{equation}\nNow choose $c \\in \\C$ with $|c|=1$ such that $ c \\langle  v,w \\rangle = |\\langle  v,w \\rangle|$. Replacing $v$ by $cv$ \nin inequality \\eqref{eq:inequality-chain} and observing that $\\|cv \\|$ and $ \\| w \\| $ are positive then entails\n\\[\n  0 \\leq \\|c v\\|\\|w\\| - \\Re \\langle c v,w \\rangle  =  \\|v\\|\\|w\\| - \\Re (c \\langle v,w \\rangle) =\n  \\|v\\|\\|w\\| -  |\\langle  v,w \\rangle|,\n\\] \nwhich is the claimed Cauchy--Schwartz inequality for sums in abbreviated form. \n\nEquality holds true if and only if $\\|w\\| c v - \\|v\\| w =0$. So if $\\|v\\|\\|w\\| =  |\\langle  v,w \\rangle| $,\nthen $v$ and $w$ are linearly dependant. To show the converse, assume that $av =bw$ for some $a,b\\in \\C$ \nwith $(a,b) \\neq (0,0)$. Because we consider  the nontrivial case where both $v$ and $w$ are nonzero, we can \nassume without loss of generality that $b=1$. But then \n\\[ |\\langle v,w \\rangle |= |\\langle v, av \\rangle | = |a| \\|v\\|^2 = \\|v\\| \\, \\|w\\| \\ , \\]\nhence equality holds in this case. The proof is finished.\n\\end{proof}\n\n\\para\nBesides the $\\ell^2$-norm on $\\C^n$ one has the so-called $\\ell^p$-norms \n$\\| \\cdot \\| : \\C^n \\to \\R_{\\geq 0}$ for $p \\geq 1$. \nThey are defined by \n\\[\n  \\| v \\|_p = \\left( \\sum_{k=1}^n |v_k|^p \\right)^{1/p} \\quad \\text{for } v \\in \\C^n  \\ . \n\\] \nThe \\emph{maximum norm} or $\\ell^\\infty$-norm $\\| \\cdot \\|_\\infty$ is given by \n\\[\n  \\| v \\|_\\infty = \\sup \\big\\{ |v_k| \\bigmid k = 1,\\ldots , n \\big\\}  \\ .\n\\]\nThe $\\ell^p$-norms are all norms indeed as we will later see. \n\\begin{theorem}[H\\\"older's inequality for sums]\nLet $p,q \\in [1, \\infty )$ such that $\\frac 1p + \\frac 1q =1$. Then \n\\[\n   \\sum_{k=1}^n | v_k w_k | \\leq  \\| v \\|_p \\cdot \\| w\\|_q \\quad \\text{for all } v,w\\in \\C^n \\ .\n\\]\n\\end{theorem}\n\\begin{proof}\nIf $p=1$ or $q=1$ the claim is immediate, because then $q=\\infty$  or $p=\\infty$, respectively,\nand  the two estimates\n\\[\n  \\sum_{k=1}^n | v_k w_k | \\leq  \\left( \\sum_{k=1}^n | v_k | \\right) \\cdot \n  \\sup\\big\\{ |w_k| \\bigmid k = 1,\\ldots , n \\big\\} \n\\]\nand\n\\[\n  \\sum_{k=1}^n | v_k w_k | \\leq  \\left( \\sum_{k=1}^n | w_k | \\right) \\cdot \n  \\sup \\big\\{ |v_k| \\bigmid k = 1,\\ldots , n \\big\\} \n\\]\nobviously hold. So we can assume $1 < p,q < \\infty$. Moreover we can assume that both $v$ and $w$ \nare nonzero because otherwise the claim is trivial. Now observe that by Young's inequality\n\\[\n  \\frac{|v_k|}{\\| v \\|_p} \\cdot \\frac{|w_k|}{\\| w \\|_q} =\n  \\left(\\frac{|v_k|^p}{\\| v \\|_p^p} \\right)^{1/p} \\cdot \\left(\\frac{|w_k|^q}{\\| w \\|_q^q} \\right)^{1/q}\n  \\leq \\frac 1p \\frac{|v_k|^p}{\\| v \\|_p^p} + \\frac 1q \\frac{|w_k|^q}{\\| w \\|_q^q} \\quad \n  \\text{for } k=1,\\ldots , n\\ .\n\\]\nSumming over all $k$ gives\n\\[\n   \\sum_{k=1}^n \\frac{|v_k|}{\\| v \\|_p} \\cdot \\frac{|w_k|}{\\| w \\|_q} \\leq \n   \\frac 1p  \\frac{\\|v\\|_p^p}{\\| v \\|_p^p} + \\frac 1q \\frac{\\|w\\|_q^q}{\\| w \\|_q^q} = \n   \\frac 1p + \\frac 1q = 1 \\ .\n\\]\nMultiplication of both sides by $ \\| v \\|_p \\cdot \\| w\\|_q$ entails H\\\"older's inequality.\n\\end{proof}\n\n\\begin{theorem}[Minkowski's inequality for sums]\nLet $p  \\in [1, \\infty )$. Then\n\\[\n   \\| v + w \\|_p \\leq \\| v\\|_q + \\| w \\|_p \\quad \\text{for all } v,w\\in \\C^n \\ .\n\\] \n\\end{theorem}\n\n\\begin{proof}\nFor $p=1$ the claim is trivial, likewise for $p=\\infty$. So assume $1  < p <  \\infty$\nand put $q := \\frac{p}{p-1}$. Then $\\frac 1p + \\frac 1q =1$, and we can apply   \nH\\\"older's inequality to compute\n\\begin{equation*}\n  \\begin{split}\n   \\| v + w \\|_p^p\\, &  =  \\sum_{k=1}^n | v_k + w_k|^p \\leq  \n   \\sum_{k=1}^n |v_k| \\, | v_k + w_k|^{p-1} +  |v_k| \\, | v_k + w_k|^{p-1} \n   \\leq \\\\\n   &\\leq  \\| v \\|_p \\cdot \\left(  | v_k + w_k|^{(p-1)q} \\right)^{1/q} +\n   \\| w \\|_p \\cdot \\left(  | v_k + w_k|^{(p-1)q} \\right)^{1/q}  = \\\\\n   & = \\left( \\| v \\|_p +  \\| w \\|_p \\right) \\,  \\| v + w \\|_p^{p/q} \\ . \n\\end{split}\n\\end{equation*}\nMinkowski's inequality follows. \n\\end{proof}\n", "meta": {"hexsha": "5925e75ab3e79919bf55452b387c7cb9d3a59956", "size": 6379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/useful-inequalities.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/useful-inequalities.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/useful-inequalities.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": 42.8120805369, "max_line_length": 122, "alphanum_fraction": 0.5695250039, "num_tokens": 2711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568417, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.6820625847568488}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Real Analysis}\n\n\\objective{Apply the basic principles of Analysis to solve improper integral and use hyperreal numbers}\n\n\nAn \\textbf{improper integral} is a definite limit where one and/or the other bound is\nan infinity.  For example, \n$$\n\\int_0^\\infty e^{-x}dx\n$$\nIn this case, we integrate like normal, but take the upper bound to be a limit, \nwritten more simply.  (No one wanted to write a limit on top of an integral!)  \n$$\n\\int_0^\\infty e^{-x}dx = \\left.-e^{-x}\\right|_0^\\infty = \\lim_{x\\rightarrow\\infty} -e^{-x} - -e^0\n$$\nThe limit approaches 0 while the function evaluates to -1.  We say, therefore, that\nthe entire integral is assigned a value of 1.  What are we saying?  The area under\nan infinite curve is a finite number?  Remarkable.\n\n\\subsubsection{Special Functions}\nSome functions come up so often in higher mathematics that they are given\ntheir own name, often involving Greek letters.  Many of them have wildly \ncomplicated definitions, and not a few are improper integrals.  One such\nfunction is the Gamma function, which is defined thus:\n\n\\begin{equation}\n\\Gamma(z)=\\int_{0}^{\\infty}x^{z-1}e^{-x}dx\n\\end{equation}\n\nWe shall see in chapter 14 that there is very common function in math called\n\\textbf{factorial}.  The Gamma function is the \\textbf{analytic continuation} of\nthe factorial function, such that $\\Gamma(n) = (n-1)!$.  This has many uses in\nprobability theory, allowing us to calculate values in between the integers.\n\n\n\\subsection{Non-Standard Analysis}\nWhen Leibniz and Newton invented Calculus in the mid-17th century, their discoveries were\na culmination of two centuries of fierce debate over the idea of infinitesimals.  Was the\ncontinuum (we might use the were ``number line'' or Reals) made up on indivisible, smallest\nelements or not?  Leibniz called the infinitesimals and Newton called them fluxions.  \nThe assumption of their existence had made it possible to grow beyond a dependence\nupon Euclid and the Classics, and enabled the ability to make new discoveries in \nmathematics, along the lines of Analytic Geometry (the algebra of Geometry).\n\n\nUnfortunately, Newton and Leibniz did not cultivate a rigor science of infinitesimals,\nand later centuries have much preferred the work of Cauchy and Weierstrauss, \nbecause of its consistency and explanatory power.  However, given the antiquity of\nthe method of \\textbf{exhaustion} and current understand of Planck Length, \nPlanck Time, Planck Mass, etc., this textbook has attempted to keep some measure\nof the method of infinitesimals at its core.  These methods were made rigorous in\nthe 1960s by Abraham Robinson and codified in a system of numbers known as \n\\textbf{Hyperreal} Numbers, or simply, the Hyperreals.\n\nThe hyperreals are an extension of the reals, as the name implies.  We need only\nposit two numbers: $\\omega$ and $\\epsilon$.  $\\omega$ (the last letter of the\nGreek alphabet, only always lowercase, pronounced oh-MEG-uh or oh-MAY-guh)\nis analogous to infinity as most people think of it.  Infinity is \\emph{supposed}\nto be a concept, not a number, the idea of going on without end.  $\\omega$ is\na number bigger than any real number, just smaller than infinity.  $\\epsilon$ is\nits reciprocal, a positive number smaller than any real number but not zero.\n\nThis leads to a system where numbers may be composed of two (even three)\nparts.  For example, $3+2\\epsilon$ may not be simplified any further.  But \n$\\omega(3+2\\epsilon)$ can be: $3\\omega + 2$.  What good is such an arbitrary,\nnew system.  Well actually, its quite old and caused the invention of calculus!\n\n\\subsubsection{Old Definitions}\nThe Difference Quotient can be stated without limits using hyperreals as\n\\begin{equation}\nf'(x) = \\frac{f(x+\\epsilon) - f(x)}{x+\\epsilon -x}  \\outnote{(Hyperreal Difference Quotient)}\n\\end{equation}\n\n$e$ can be stated without limits as follows:\n\\begin{equation}\ne = (1+\\epsilon)^\\omega  \\outnote{(Hyperreal Definition of $e$)}\n\\end{equation}\n\n\\subsubsection{Derivative}\nLet us do one example, with several others in the exercises, finding the derivative of \n$x^2$.\n$$\n(x^2)' = \\frac{(x+\\epsilon)^2-x^2}{\\epsilon} = \\frac{x^2+2x\\epsilon+\\epsilon^2-x^2}{\\epsilon}\n= 2x+\\epsilon\n$$\nUnlike limits notation, the infinitesimal does not disappear.  Every $\\epsilon$ step in\nthe $x$-direction produces a jump of $2x$ in the $y$-direction.  According to quantum\nmechanics (and Zeno's Paradox), the jumps are done without intervening steps,\nthat at the smallest level, elementary particles proceed in a way quite unlike\nour macroscopic world.\n", "meta": {"hexsha": "2788eb6049d0145b329e25b98881766def79649b", "size": 4574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch08/0805.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch08/0805.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch08/0805.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": 49.1827956989, "max_line_length": 103, "alphanum_fraction": 0.7608220376, "num_tokens": 1212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6820625801125779}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\marginpar{Tuesday\\\\ 2020-11-3, \\\\ compiled \\\\ \\today}\n\nA \\textbf{stationary distribution} for a Markov Chain is a probability distribution \\(p(\\vec{x})\\) for \\(\\vec{x}\\) in \\(\\Omega \\) such that the following property holds: \n%\n\\begin{align}\np(\\vec{y}) = \\sum _{\\vec{x} \\in \\Omega} \\mathbb{P}(\\vec{y} | \\vec{x}) p(\\vec{x})\n\\,,\n\\end{align}\n%\nwhere \\(\\mathbb{P}(\\vec{y} | \\vec{x})\\) is the transition probability from \\(\\vec{x}\\) to \\(\\vec{y}\\): the probability that we are in \\(\\vec{y}\\), given that we were in \\(\\vec{x}\\) at the previous step. \nWhat this means is that after a step in the chain leaves \\(p(\\vec{x})\\) unchanged. \n\nIn terms of the transition matrix, the problem reads \\(p_i = T_{ij} p_j\\), so \\(p_i\\) is an eigenvector of \\(T_{ij}\\) with eigenvalue \\(1\\). \n\nIn our case, we want to build a MC which converges to a stationary probability distribution which is our posterior. \nSo, first we need to ask whether this can be done, and then how long it takes for us to converge to that distribution. \n\n\\begin{theorem}\n    A finite, ergodic Markov chain has a unique stationary distribution. \n\\end{theorem}\n\nA state has \\textbf{period} \\(k\\) if any return to it requires a multiple of \\(k\\) steps. Formally, \n%\n\\begin{align}\nk(\\vec{x}) =  \\gcd \\qty{ n \\in \\mathbb{N}: \\text{the probability of returning from \\(\\vec{x}\\) to \\(\\vec{x}\\) in \\(n\\) steps is } >0}\n\\,.\n\\end{align}\n%\n\nIf \\(k=1\\) the state is aperiodic. \nIf a MC is ergodic and one state is aperiodic then all states are.  \n\nA state is \\textbf{recurrent} if with probability 1 we will return to it at some point if we leave it.\nIt is called \\textbf{transient} otherwise.\n\nA recurrent state is \\textbf{positive recurrent} if the expected return time is finite; \\textbf{null recurrent} if it diverges. \n\n\\begin{theorem}\n    A finite, ergodic, positive recurrent, aperiodic Markov Chain converges to its stationary distribution as \\(n \\to \\infty \\). \n\\end{theorem}\n\nSo, eventually convergence is ensured, but we must also design a MC which converges \\emph{quickly}. \n\nLet us now give a practical example, with \\(\\Omega = \\qty{A, B, C}\\).\nThe transition matrix is \n%\n\\begin{align}\nT_{ij} = \n\\left[\\begin{array}{ccc}\n\\num{.25} & \\num{.5} & \\num{0.25} \\\\ \n0 & \\num{.5} & \\num{.5} \\\\ \n\\num{.33} & \\num{.33} & \\num{.34}\n\\end{array}\\right]\n\\,,\n\\end{align}\n%\nas required all the rows are normalized to one. \nThe initial condition is given by \\(q_0 = [0, \\num{.5}, \\num{.5}]\\).\n\nThe following steps can be calculated as \\(q_n = q_0 (T^{n}) \\).\n\nLet us define \\(m(s_i, s_j)\\) as the mean time to go from \\(s_i\\) to \\(s_j\\). How do we compute it? We need to make sure that it is finite.\nLet us fix a state, say \\(C\\). What is \\(m(C, C)\\)?\n\nSuppose that the first step is from \\(C\\) to \\(B\\). Then, we will have \\(m(C,C) = 1 + m(B, C)\\). Similarly, if we go from \\(C\\) to \\(A\\) we have \\(m(C, C) = 1 + m(A, C)\\); while if we jump directly to \\(C\\) we have \\(m(C, C) =1\\). \n\nThe overall recurrence time is obtained by integrating over all the possibilities: \n%\n\\begin{align}\nm(C, C) &= \n\\mathbb{P}(C | A) \\qty[1 + m(A, C)] + \n\\mathbb{P}(C | B) \\qty[1 + m(B, C)] \n+  \\mathbb{P}(C | C)  \\\\\n&= \n\\underbrace{\\mathbb{P}(C |A ) +\n\\mathbb{P}(C |B) +\n\\mathbb{P}(C |C )}_{1} +\n\\mathbb{P}(C |A ) m(A, C) +\n\\mathbb{P}(C |B ) m(B, C) +\n\\,.\n\\end{align}\n\nWe can do a similar thing for the other recurrence times, this yields a linear system we can solve, in terms of the three unknowns \\(m(*, C)\\). \nIn this case we get \\(m(C, C) = \\num{2.54}\\), \\(m(B, C) = \\num{2.0}\\), \\(m(A,C) = \\num{2.67}\\). \n\nTherefore, this MC will admit a stationary distribution and converge to it.\\footnote{Check out the convergence by downloading the notebook at \\url{https://github.com/jacopok/notes/blob/master/ap_third_semester/astrostatistics_cosmology/figures/markov.ipynb}!}\nWe can calculate it through the left eigenvalue problem \\(\\pi = \\pi T\\). \n\nA Markov Chain is \\textbf{reversible} if there exists a probability distribution \\(\\pi \\) such that \\(\\mathbb{P}(x | y) \\pi (y) = \\mathbb{P}(y | x) \\pi (x)\\). \nThis is called the \\textbf{detailed balance} equation, and if it holds it tells us that \\(\\pi \\) is the stationary distribution of the Markov chain: if we sum over \\(y\\) we get \n%\n\\begin{align}\n\\sum _{y} \\mathbb{P}(x | y) \\pi (y) = \\sum _{y} \\mathbb{P}(y | x) \\pi (x) \n= \\pi (x) \\sum _{y} \\mathbb{P}(y | x ) = \\pi (x)\n\\,,\n\\end{align}\n%\nwhich is precisely the stationarity condition.\n\n\\subsection{Metropolis-Hastings} \n\nSuppose we have a posterior \\(p(\\vec{\\theta})\\), in terms of a parameter vector \\(\\vec{\\theta}\\). \n\nThe current state is denoted as\n%\n\\begin{align}\nX_\\theta = \\qty(\\theta_{1, t },  \\dots, \\theta_{n, t})\n\\,.\n\\end{align}\n\nWe choose a transition distribution \\(Q\\);\nthis can be some easy-to-sample distribution of our choosing. \n\nThen, the new state is \\textbf{proposed} by updating the old position\n%\n\\begin{align}\nY \\sim Q ( \\cdot | X_t)\n\\,,\n\\end{align}\n%\nand choose to accept it or reject it depending on the following: we draw a uniform variable, and accept with probability \n%\n\\begin{align}\n\\alpha (X_{t+1} = y | X_t = x) = \n\\min \\qty{ \\frac{\\mathscr{L}(\\vec{y})}{\\mathscr{L}(\\vec{x})} \\frac{Q(\\vec{x} | \\vec{y})}{Q(\\vec{y} | \\vec{x})}, 1}\n\\,.\n\\end{align}\n\nSimply put, we favor steps which move us in a region of higher likelihood. \nThe ratio of the \\(Q\\)s might well go away if we choose a symmetric transition matrix. \n\nThis satisfies the detailed balance equation: let us show it. \nOne side of the equation reads\n%\n\\begin{align}\n\\underbrace{\\alpha (\\vec{y} | \\vec{x}) Q (\\vec{y} | \\vec{x})}_{\\text{transition probability}} p(\\vec{x})\n&= \\min \\qty{\\frac{\\mathscr{L}(\\vec{y})}{\\mathscr{L}(\\vec{x})} \n\\frac{Q(\\vec{x} | \\vec{y})}{Q(\\vec{y} | \\vec{x})}, 1} Q(\\vec{y} | \\vec{x}) p(\\vec{x})  \\\\\n&= \\min \\qty{Q(\\vec{x} | \\vec{y}) \\mathscr{L}(\\vec{y}), Q(\\vec{y} | \\vec{x}) \\mathscr{L}(\\vec{x})} \\mathscr{L} (\\vec{x} ) \n\\,,\n\\end{align}\n%\n\\todo[inline]{check calculation}\n\nWe apply Bayes' theorem\\dots\nFinally, we show that \n%\n\\begin{align}\n\\alpha (\\vec{y} | \\vec{x}) Q (\\vec{y} | \\vec{x}) p(\\vec{x}) \n= \\alpha (\\vec{x} | \\vec{y}) Q(\\vec{x} | \\vec{y}) p(\\vec{y})\n\\,.\n\\end{align}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "7a5911e54bf20d97fcc57fcf4321474f99f4a7f1", "size": 6196, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostatistics_cosmology/nov03.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/nov03.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/nov03.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.725, "max_line_length": 259, "alphanum_fraction": 0.6471917366, "num_tokens": 2118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6819239718533409}}
{"text": "\\subsection{Topological vector spaces}\\label{subsec:topological_vector_spaces}\n\n\\begin{definition}\\label{def:topological_vector_space}\n  Let \\( X \\) be any vector space and let \\( \\mscrT \\) be a topology on \\( X \\). The space \\( (X, +, \\cdot, \\mscrT) \\) is called a \\term{topological vector space} if the linear and topological structure agree, that is, the operations \\( +: X \\times X \\to X \\) and \\( \\cdot: X \\times \\BbbR \\to X \\) are continuous with respect to \\( \\mscrT \\).\n\n  Both the additive group \\( (X, +) \\) and the multiplicative group \\( (X \\setminus \\{ 0 \\}, \\cdot) \\) are \\hyperref[def:topological_group]{topological groups}. We regard \\( X \\) as a subgroup of its additive topological group.\n\n  See \\fullref{rem:hausdorff_topological_groups}, \\fullref{def:continuous_dual_space} and \\fullref{def:category_of_topological_vector_spaces} for more nuances.\n\\end{definition}\n\nGiven that a topological vector space \\( X \\) has both a topological and an algebraic structure, we should adapt certain definitions.\n\n\\begin{definition}\\label{def:continuous_dual_space}\n  We define the \\term{continuous dual space} \\( X^* \\) of a topological space \\( X \\) as the vector space of all \\hyperref[def:global_continuity]{continuous} linear functionals. This differs drastically from \\fullref{def:dual_vector_space} because in the general case, the continuous dual space may be trivial, i.e. only contain the zero functional. See \\fullref{def:locally_convex_duality_pairing}.\n\n  We use the same notation for both the algebraic dual spaces and the continuous dual space because the meaning is usually clear from the context. In particular, hyperplanes as defined in \\fullref{def:hyperplane} are only relevant to continuous linear functionals.\n\\end{definition}\n\n\\begin{definition}\\label{def:category_of_topological_vector_spaces}\n  The category \\( \\cat{TopVect}_{\\BbbK} \\) of topological vector spaces over \\( \\BbbK \\) is a subcategory of both \\( \\cat{Top} \\) and \\( \\cat{Vect}_K \\). Its morphisms are the \\hyperref[def:global_continuity]{continuous} linear \\hyperref[def:linear_operator]{maps}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:origin_neighborhoods_in_topological_vector_spaces}\n  As in \\fullref{rem:origin_neighborhoods_in_topological_groups}, we are only interested in neighborhoods of the origin \\( 0 \\) since any neighborhood \\( U \\) of \\( x \\) is simply a translation of the neighborhood \\( U - x \\) of the origin.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:topological_vector_space_is_uniform}\n  A Hausdorff topological vector space \\( X \\) is a uniform space with the families of entourages\n  \\begin{balign*}\n     & V_A \\coloneqq \\{ (x, y) \\in X \\times X \\colon x - y \\in A \\},\n  \\end{balign*}\n  where \\( A \\) is a \\hyperref[def:neighborhood_set_types/symmetric]{symmetric} neighborhood of the origin \\( 0 \\).\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:topological_group_uniform_space}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:linearity_of_sequence_limits}\n  If \\( \\{ a_\\alpha \\}_{\\alpha \\in \\mscrK} \\) and \\( \\{ b_\\alpha \\}_{\\alpha \\in \\mscrK} \\) are \\hyperref[def:topological_net]{nets} in a Hausdorff topological vector space \\( X \\) that converge to \\( a \\) and \\( b \\), correspondingly, then\n  \\begin{thmenum}\n    \\thmitem{thm:linearity_of_sequence_limits/addition} \\( a_\\alpha + b_\\alpha \\to a + b \\).\n    \\thmitem{thm:linearity_of_sequence_limits/scalar_multiplication} \\( \\lambda a_\\alpha \\to \\lambda a \\) for any scalar \\( \\lambda \\in \\BbbK \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  Fix a neighborhood \\( U \\) of \\( 0 \\) and fix an index \\( \\alpha_0 \\) such that for \\( \\alpha \\geq \\alpha_0 \\) we have both \\( a - a_\\alpha \\in U \\) and \\( b - b_\\alpha \\in U \\).\n\n  \\SubProofOf{thm:linearity_of_sequence_limits/addition} For addition, we have\n  \\begin{equation*}\n    (a + b) - (a_\\alpha + b_\\alpha) = (a - a_\\alpha) + (b - b_\\alpha) \\in 2U.\n  \\end{equation*}\n\n  \\SubProofOf{thm:linearity_of_sequence_limits/scalar_multiplication} For scalar multiplication, we have\n  \\begin{equation*}\n    \\lambda a - \\lambda a_\\alpha \\in \\lambda U.\n  \\end{equation*}\n\n  In both cases the containing neighborhood does not depend on \\( \\alpha \\), hence the nets converge to their desired values.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:linearity_of_function_limits}\n  If \\( f, g: X \\to Y \\) are continuous functions between topological vector spaces, then for any point \\( x_0 \\in X \\) we have\n  \\begin{equation*}\n    \\lim_{x \\to x_0} (f(x) + g(x)) = \\lim_{x \\to x_0} f(x) + \\lim_{x \\to x_0} g(x)\n  \\end{equation*}\n  and for any \\( \\lambda \\in \\BbbK \\)\n  \\begin{equation*}\n    \\lim_{x \\to x_0} \\lambda f(x) = \\lambda \\lim_{x \\to x_0} f(x).\n  \\end{equation*}\n\\end{corollary}\n\n\\begin{definition}\\label{def:locally_convex_space}\\mcite[1.8]{Rudin1991Functional}\n  We say that a \\hyperref[def:topological_vector_space]{topological vector space} is \\term{locally convex} if there exists a \\hyperref[def:topological_base]{topological base} of \\hyperref[def:convex_set]{convex} sets.\n\\end{definition}\n\n\\begin{remark}\\label{def:locally_convex_duality_pairing}\n  Given a Hausdorff locally convex space \\( X \\), \\fullref{thm:hahn_banach_implies_functionals_vanish_nowhere} shows that the canonical duality pairing as defined in \\fullref{def:locally_convex_duality_pairing} is nondegenerate. If the space is not locally convex, we cannot guarantee that the pairing will be nondegenerate and our restriction to continuous linear functionals could interfere with our habits of working with linear functionals.\n\\end{remark}\n\n\\begin{definition}\\label{def:sublinear_functional}\n  We say that \\( f: X \\to \\BbbR \\) is a \\term{sublinear functional} if it satisfies\n  \\begin{thmenum}\n    \\thmitem{def:sublinear_functional/subadditivity}(subadditivity) \\( f(x + y) \\leq f(x) + f(y) \\) for any \\( x, y \\in X \\).\n    \\thmitem{def:sublinear_functional/positive_homogeneity}(positive homogeneity) \\( f(tx) \\leq t f(x) \\) for any \\( t > 0 \\) and \\( x \\in X \\).\n  \\end{thmenum}\n\n  Compare this definition to \\fullref{def:linear_operator}.\n\\end{definition}\n", "meta": {"hexsha": "339fcb1fcbb13292d585fa1520aa50909a5f591c", "size": 6065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/topological_vector_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/topological_vector_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/topological_vector_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": 68.1460674157, "max_line_length": 444, "alphanum_fraction": 0.7297609233, "num_tokens": 1835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6819239684467693}}
{"text": "\nThis appendix describes the equations for handling the cross-sections in different sections of this thesis.\n\n\\section{Group constants homogenization}\n\\label{appendix:group-const-homo}\n\n% duderstadt 10-17 and stacey 14.56\nThe following relations homogenize the group constants over a certain volume $V_T$ \\cite{duderstadt_nuclear_1976}\n\n\\begin{align}\n  & \\phi_{g, T} = \\frac{\\sum_i \\phi_{g, i} V_i}{V_T}  \\\\\n  & \\Sigma^t_{g, T} = \\frac{\\sum_i \\Sigma^t_{g, i} \\phi_{g, i} V_i}{\\phi_g V_T}  \\\\\n  & \\nu\\Sigma^f_{g, T} = \\frac{\\sum_i \\nu\\Sigma^f_{g, i} \\phi_{g, i} V_i}{\\phi_g V_T}  \\\\\n  & \\Sigma^s_{g'\\rightarrow g, T} = \\frac{\\sum_i \\Sigma^s_{g'\\rightarrow g, i} \\phi_{g, i} V_i}{\\phi_g V_T}  \\\\\n  & \\chi^t_{g, T} = \\frac{\\sum_i \\chi^t_{g, i} \\nu\\Sigma^f_{g, i} \\phi_{g, i} V_i}{\\nu\\Sigma^f_g \\phi_g V_T}  \\\\\n  & D_{g, T} = \\frac{\\sum_i D_{g, i} \\phi_{g, i} V_i}{\\phi_g V_T}\n\\intertext{where}\n  & \\phi_{g, i} = \\mbox{group $g$, region $i$ neutron flux } [n \\cdot cm^{-2} \\cdot s^{-1}] \\notag \\\\\n  & V_i = \\mbox{region $i$ volume } [cm^{3}] \\notag \\\\\n  & V_T = \\mbox{total volume where the homogenization takes place } [cm^{3}] \\notag \\\\\n  & \\Sigma^t_{g, i} = \\mbox{group $g$, region $i$ macroscopic total cross-section } [cm^{-1}] \\notag \\\\\n  & \\nu = \\mbox{number of neutrons produced per fission } [-] \\notag \\\\\n  & \\Sigma^f_{g, i} = \\mbox{group $g$, region $i$ macroscopic fission cross-section } [cm^{-1}] \\notag \\\\\n  & \\Sigma^s_{g'\\rightarrow g, i} = \\mbox{group $g'$ to group $g$, region $i$ macroscopic scattering cross-section } [cm^{-1}] \\notag \\\\  \n  & \\chi^t_{g, i} = \\mbox{group $g$, region $i$ total fission spectrum } [-] \\notag\\\\\n  & D_{g, i} = \\mbox{group $g$, region $i$ diffusion coefficient } [cm]. \\notag\n\\end{align}\n\n\n\\section{Group constants condensation}\n\\label{appendix:group-const-condense}\n\n% duderstadt 7-54 and tsoulfiniadis 5.12\nThe following equations collapse the group constants \\cite{duderstadt_nuclear_1976}\n\\begin{align}\n  & \\phi_{h} = \\sum_g \\phi_{g} \\\\\n  & \\chi_{h}^t = \\sum_g \\chi_g^t \\\\\n  & D_{h}^t = \\frac{\\sum_g D_g^t \\phi_{g}}{\\phi_{g'}} \\\\\n  & \\Sigma_{h}^t = \\frac{\\sum_g \\Sigma_g^t \\phi_{g}}{\\phi_{g'}} \\\\\n  & \\nu\\Sigma_{h}^f = \\frac{\\sum_g \\nu\\Sigma_g^f \\phi_{g}}{\\phi_{g'}} \\\\\n  & \\Sigma_{h'\\rightarrow h}^s = \\frac{\\sum_{g'} \\sum_{g} \\Sigma_{g'\\rightarrow g}^s \\phi_{g'}}{\\phi_{h'}}\n  \\intertext{where}\n  & \\phi_g = \\mbox{group $g$ neutron flux } [n \\cdot cm^{-2} \\cdot s^{-1}] \\notag \\\\\n  & \\chi_g^t = \\mbox{group $g$ total fission spectrum } [-] \\notag\\\\\n  & D_g = \\mbox{group $g$ diffusion coefficient } [cm] \\notag \\\\\n  & \\Sigma_g^t = \\mbox{group $g$ macroscopic total cross-section } [cm^{-1}] \\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  & G = \\mbox{original number of energy groups } [-] \\notag \\\\\n  & H = \\mbox{new number of energy groups } [-] \\notag \\\\\n  & \\Sigma_{g'\\rightarrow g}^s = \\mbox{group $g'$ to group $g$ macroscopic scattering cross-section } [cm^{-1}]. \\notag\n\\end{align}\n\n\n\\section{Benchmark group constants}\n\\label{appendix:group-const-bench}\n\nThe benchmark specifies the following group constants: the normalized neutron flux $\\phi_g$, the total fission spectrum $\\chi_g^t$, the diffusion coefficient $D_g$, the macroscopic total cross-section $\\Sigma_g^t$, number of neutrons produced per fission by the macroscopic fission cross-section $\\nu\\Sigma_g^f$, the macroscopic fission cross-section $\\Sigma_g^f$, and the macroscopic scattering cross-section $\\Sigma_{g'\\rightarrow g}^s$.\n\nMoltres solves equation \\ref{eq:app-eigenvalue}, and requires the following group constants: the diffusion coefficient $D_g$, the macroscopic removal cross-section $\\Sigma_g^r$, the macroscopic scattering cross-section $\\Sigma_{g'\\rightarrow g}^s$, the total fission spectrum $\\chi_g^t$, and the number of neutrons produced per fission by the macroscopic fission cross-section $\\nu\\Sigma_g^f$.\n\n% duderstadt 7-23\nEquation \\ref{eq:app-removal} calculates the removal cross-section \\cite{duderstadt_nuclear_1976}\n\\begin{align}\n% \\Sigma_{r,g} &= \\Sigma_{a,g} + \\sum_{g' \\ne g} \\Sigma_{s,g \\rightarrow g'} = \\Sigma_{t,g} - \\Sigma_{s, g \\rightarrow g} \\label{eq:app-removal}\n\\Sigma_{r,g} &= \\Sigma_{t,g} - \\Sigma_{s, g \\rightarrow g}. \\label{eq:app-removal}\n\\end{align}\n", "meta": {"hexsha": "e32e5f17325413292ea6703b2ab09ac74c6bcf07", "size": 4347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendixB.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": "appendixB.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": "appendixB.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": 63.9264705882, "max_line_length": 439, "alphanum_fraction": 0.6618357488, "num_tokens": 1550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6819239679527068}}
{"text": "\\subsection{2017 Free-Response Questions}\r\nQuestions 1 and 2 are part of the same section and are allotted 30 minutes for completion with the aid of a graphing calculator.\r\nQuestions 3 through 6 are part of the same section and are allotted 1 hour for completion without the aid of a graphing calculator.\r\n\r\n\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{|c||c|c|c|c|}\r\n\t\t\t\\hline\r\n\t\t\t$h$ (feet) & 0 & 2 & 5 & 10 \\\\\r\n\t\t\t\\hline\r\n\t\t\t$A(h)$ (square feet) & 50.3 & 14.4 & 6.5 & 2.9 \\\\\r\n\t\t\t\\hline\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\\end{table}\r\n\r\n\\begin{enumerate}\r\n\t\r\n\t\\item A tank has a height of 10 feet.\r\n\t\tThe are of the horizontal cross section of the tank at $h$ feet is given by the function $A$, where $A(h)$ is measured in square feet.\r\n\t\tThe function $A$ is continuous and decreases as $h$ increases.\r\n\t\tSelected values for $h$ are given in the table above.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Use a left Riemann sum with three subintervals indicated by the data to approximate the volume of the tank.\r\n\t\t\t\tIndicate units of measure.\r\n\t\t\t\\item Does the approximate in part (a) overestimate or underestimate the volume of the tank?\r\n\t\t\t\tExplain your reasoning.\r\n\t\t\t\\item The area, in square feet, of the horizontal cross section at height $h$ feet is modeled by the function $f$ given by $f(h)=\\frac{50.3}{e^{0.2h}+h}$.\r\n\t\t\t\tBased on this model, find the volume of the tank.\r\n\t\t\t\tIndicate units of measure.\r\n\t\t\t\\item Water is pumped into the tank.\r\n\t\t\t\tWhen the height of the water is 5 feet, the height is increasing at a rate of 0.26 foot per minute.\r\n\t\t\t\tUsing the model from part (c), find the rate at which the volume of water is changing with respect to time when the height of the water is 5 feet.\r\n\t\t\t\tIndicate units of measure.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{2017_2}\r\n\t\t\\centering\r\n\t\t\\includegraphics{./additional_materials/2017_2.png}\r\n\t\t\\caption{\\hyperref{https://apcentral.collegeboard.org/pdf/ap-calculus-bc-frq-2017.pdf}{}{}{AP Calculus BC 2017 Exam Free-Response Question 2}}\r\n\t\\end{figure}\r\n\r\n\t\\item The figure above show the polar curves $r=f(\\theta)=1+\\sin{\\theta}\\cos{(2\\theta)}$ and $r=g(\\theta)=2\\cos{\\theta}$ for $0 \\leq \\theta \\leq \\frac{\\pi}{2}$.\r\n\t\tLet $R$ be the region in the first quadrant bounded by the curve $r=f(\\theta)$ and the $x$-axis.\r\n\t\tLet $S$ be the region in the first quadrant bounded by the curve $r=f(\\theta)$ the curve $r=g(\\theta)$, and the $x$-axis.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find the area of $R$.\r\n\t\t\t\\item The ray $\\theta = k$, where $0 < k < \\frac{\\pi}{2}$, divides $S$ into two regions of equal area.\r\n\t\t\t\tWrite out, but do not solve, an equation involving one or more integrals whose solution gives the value of $k$.\r\n\t\t\t\\item For each $\\theta$, $0 \\leq \\theta \\leq \\frac{\\pi}{2}$, let $w(\\theta)$ be the distance between the points with polar coordinates $(f(\\theta),\\theta)$ and $(g(\\theta),\\theta)$.\r\n\t\t\t\tWrite an expression for $w(\\theta)$.\r\n\t\t\t\tFind $w_A$, the average value of $w(\\theta)$ over the interval $0 \\leq \\theta \\leq \\frac{\\pi}{2}$.\r\n\t\t\t\\item Using the information given from part (c), find the value of $\\theta$ for which $w(\\theta)=w_A$.\r\n\t\t\t\tIs the function $w(\\theta)$ increasing or decreasing at that value of $\\theta$?\r\n\t\t\t\tGive a reason for your answer.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{2017_3}\r\n\t\t\\centering\r\n\t\t\\includegraphics{./additional_materials/2017_3.png}\r\n\t\t\\caption{\\hyperref{https://apcentral.collegeboard.org/pdf/ap-calculus-bc-frq-2017.pdf}{}{}{AP Calculus BC 2017 Exam Free-Response Question 3, Graph of $f^\\prime$}}\r\n\t\\end{figure}\r\n\t\r\n\t\\item The function $f$ is differentiable on the closed interval $[-6,5]$ and satisfies $f(-2)=7$.\r\n\t\tThe graph of $f^\\prime$, the derivative of $f$, consists of a semicircle and three line segments, as shown in the figure above.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find the values of $f(-6)$ and $f(5)$.\r\n\t\t\t\\item On what intervals is $f$ increasing?\r\n\t\t\t\tJustify your answer.\r\n\t\t\t\\item Find the absolute minimum value of $f$ on the closed interval $[-6,5]$.\r\n\t\t\t\tJustify your answer.\r\n\t\t\t\\item For each of $f^{\\prime\\prime}(-5)$ and $f^{\\prime\\prime}(3)$, find the value or explain why it doesn't exist.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\item At time $t=0$, a boiled potato is taken from a pot on a stove and left to cool in a kitchen.\r\n\t\tThe internal temperature of the potato is 91 degrees Celsius ($^\\circ C$) at time $t=0$, and the internal temperature of the potato is greater than $27^\\circ C$ for all time $t > 0$.\r\n\t\tThe internal temperature of the potato at time $t$ minutes can be modeled by a function $H$ that satisfies the differential equation $\\dd{H}{t} = -\\frac{1}{4}(H-27)$, where $H(t)$ is measured in degrees Celsius and $H(0)=91$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Write an equation for the line tangent to the graph of $H$ at $t=0$.\r\n\t\t\t\tUse this equation to approximate the internal temperature of the potato at time $t=3$.\r\n\t\t\t\\item Use $\\dd{^2H}{t^2}$ to determine whether your answer in part (a) is an underestimate or overestimate of the internal temperature of the potato at time $t=3$.\r\n\t\t\t\\item For $t<10$, an alternate model for the internal temperature of the potato at time $t$ minutes is the function $G$ that satisfies the differential equation $\\dd{G}{t} = -(G-27)^{2/3}$, where $G(t)$ is measured in degrees Celsius and $G(0)=91$.\r\n\t\t\t\tBased on this model, what is the internal temperature of the potato at time $t=3$?\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\item Let $f$ be the function defined by $f(x) = \\frac{3}{2x^2-7x+5}$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find the slope of the tangent line of the graph of $f$ at $x=3$.\r\n\t\t\t\\item Find the $x$-coordinate of each critical point of $f$ in the interval $1 < x < 2.5$.\r\n\t\t\t\tClassify each critical point as the location of a relative minimum, a relative maximum, or neither.\r\n\t\t\t\tJustify your answer.\r\n\t\t\t\\item Using the identity that $\\frac{3}{2x^2-7x+5} = \\frac{2}{2x-5} - \\frac{1}{x-1}$, evaluate $\\int_{5}^{\\infty}{f(x)\\d{x}}$ or show that the integral diverges.\r\n\t\t\t\\item Determine whether the series $\\sum_{n=5}^{\\infty}{\\frac{3}{2n^2-7n+5}}$ converges or diverges.\r\n\t\t\t\tState the conditions of the test used for determining convergence or divergence.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\begin{align*}\r\n\t\tf(0) &= 0 \\\\\r\n\t\tf^\\prime(0) &= 1 \\\\\r\n\t\tf^{(n+1)}(0) &= -n\\cdot f^{(n)}(0) \\text{ for all } n \\geq 1\r\n\t\\end{align*}\r\n\t\r\n\t\\item A function $f$ has derivatives of all order for $-1 < x < 1$.\r\n\t\tThe derivatives of $f$ satisfy the conditions above.\r\n\t\tThe Maclaurin Series for $f$ converges to $f(x)$ for $\\abs{x} < 1$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Show that the first four non-zero terms of the Maclaurin series for $f$ are $x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\frac{x^4}{4}$, and write the general term for the Maclaurin series for $f$.\r\n\t\t\t\\item Determine whether the Maclaurin series described in part (a) converges absolutely, converges conditionally, or diverges at $x=1$.\r\n\t\t\t\tExplain your reasoning.\r\n\t\t\t\\item Write the first four nonzero terms and the general term for the Maclaurin series for $g(x) = \\int_{0}^{x}{f(t)\\d{t}}$.\r\n\t\t\t\\item Let $P_n\\left(\\frac{1}{2}\\right)$ represent the $n$th degree Taylor polynomial for $g$ about $x=0$ and evaluated at $x=\\frac{1}{2}$, where $g$ is the function defined in part (c).\r\n\t\t\t\tUse the alternating series error bound to show that\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\biggr\\lvert P_4\\left(\\frac{1}{2}\\right) - g\\left(\\frac{1}{2}\\right) \\biggr\\rvert < \\frac{1}{500}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\\end{enumerate}\r\n\t\r\n\\end{enumerate}", "meta": {"hexsha": "99b86895fa28f29e8e6b79798d01624cbbc1bc57", "size": 7496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/additional_materials/2017_questions.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_questions.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_questions.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": 62.4666666667, "max_line_length": 252, "alphanum_fraction": 0.6762273212, "num_tokens": 2370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.6819239672245795}}
{"text": "% BASIC SETTINGS\n\\documentclass[a4paper,12pt]{article} % Set paper size and document type\n\\usepackage{lmodern} % Use a slightly nicer looking font\n\\usepackage{enumitem} % Allow lists to pick up numbering where the last list left off\n\n% Change margins - default margins are too broad\n\\usepackage[margin=20mm]{geometry}\n\n% PREPARE TITLE\n\\title{\\textbf{Homework \\#2 - Binary Numbers}}\n\\author{Name: }\n\\date{} % Hide the date\n\n% START DOCUMENT\n\\begin{document}\n\n\\maketitle % Insert the title\n\n\\section{Intro}\n\nIf we want to write good computer programs, we need to understand a little bit about the inner workings of computers. All modern computers use electronic devices to store and manipulate data and programs. To help make them simpler, these devices are built to work with only two voltages, an \"ON\" and an \"OFF\" voltage (usually 0V and 3.3V or 0V and 5V). Because of this, all data in the computer is represented using the numbers \"0\" and \"1\" (the 0 is the \"OFF\" state and the 1 is the \"ON\" state). Everything, and I mean \\textbf{everything} that the computer can do is done using only these two numbers. Videos, text, pictures, and computer programs themselves are all stored inside the computer as sequences of ones and zeros. We have to understand how these numbers work (how to do math with them, compare them etc...) in order to write good computer programs. I have introduced you to binary, decimal, and hexadecimal numbers in class before. This homework tests your ability to understand and convert between these three types of numbers.\n\n\\section{Binary Conversion}\n\nConvert the following numbers into binary (\\textbf{hint}: use the repeated division method we talked about in class):\n\n\\begin{enumerate}\n\\item $45_{10} = $\n\\item $255_{10} = $ \n\\item $0_{10} = $\n\\item $36_{10} = $ \n\\end{enumerate}\n\n\\noindent\nWhat would happen if you tried to convert 256 into an 8-bit binary number? Can you do this or do you need more than 8 bits? \n\n\\section{Binary to Decimal Conversion}\n\nConvert the following binary numbers into decimal:\n\n\\begin{enumerate}[resume]\n\\item $101_{2} = $\n\\item $00001111_{2} = $\n\\item $10000000_{2} = $\n\\item $10101010_{2} = $\n\\end{enumerate}\n\n\\section{Addition for positive numbers}\n\n\\noindent\nAdd these binary numbers together:\n\n\\begin{enumerate}[resume]\n\\item $1010_{2} + 0010_{2} = $\n\\item $0010_{2} + 1110_{2} = $\n\\item $11110010_{2} + 00101110_{2} = $\n\\end{enumerate}\n\n\\noindent\nThink about what happens if you try to add two 8-bit numbers together and the result uses more than 8-bits. What will the computer do? \n\n\\section{Forming the two's complement}\n\nIn the computer, positive and negative numbers are \\textbf{not} stored using the \"sign magnitude\" form we are used to, where a number has a + or - in front to show its sign. Instead, negative numbers in binary are represented by forming the \"two's complement\" of a positive number with the correct magnitude (size). For instance, in binary the number \"5\" is represented by \"101\" or if our computer uses 8-bit memory, \"00000101\". That is the same as \"+5\". How do we make \"-5\"? We have to change all of the \"1\"s to \"0\"s and then add an additional \"1\" to the number. Like this:\n\n$$00000101_{2} \\rightarrow 11111010_{2} + 1_{2} \\rightarrow 11110101_{2}$$\n\n\\noindent\nSo \"-5\" is actually represented by \"11110101\". You try! Convert the following \\textbf{negative} decimal numbers to their negative binary equivalents:\n\n\\begin{enumerate}[resume]\n\\item $-45_{10} = $ \n\\item $-255_{10} = $ \n\\item $-0_{10} = $\n\\item $-36_{10} = $\n\\end{enumerate}\n\n\\noindent\n\\textbf{Hint:} Since these are the same decimal numbers you converted to binary at the beginning of the homework, you can use the binary conversions you already did to form the two's complement. What happens when you form the two's complement of 0? Does this seem like the right behavior?\n\n\\section{Representing fractions}\n\nIn decimal or base 10 numbers, a fraction like 0.255 is represented as:\n\n$$2 \\cdot 10^{-1} + 5 \\cdot 10^{-2} + 5 \\cdot 10^{-3}$$\n\n\\noindent\nYou can see that it's the same system we use for representing integers (225, 34) but with negative exponents. We can do this with binary numbers as well. For instance 0000.1000 in binary would convert to the following decimal number:\n\n$$1 \\cdot 2^{-1} + 0 \\cdot 2^{-2} + 0 \\cdot 2^{-3} + 0 \\cdot 2^{-4} = $$\n$$0.5 + 0 + 0 + 0 = 0.5$$\n\n\\clearpage\n\n\\noindent\nSo $0.1_{2} = 0.5_{10}$. Try it yourself for the following numbers:\n\n\\begin{enumerate}[resume]\n\\item $0000.1010_{2} = $\n\\item $0000.0010_{2} = $\n\\item $1010.0101_{2} = $\n\\item $1100.0011_{2} = $\n\\end{enumerate}\n\n\\noindent\nNow try to go the other way!\n\n\\begin{enumerate}[resume]\n\\item $0.5_{10} = $\n\\item $0.1_{10} = $\n\\item $2.5_{10} = $\n\\item $45.25_{10} = $\n\\end{enumerate}\n\n\\noindent\nNotice that some numbers do not have an exact representation when you convert them from one base to another. 0.1 in decimal has no exact representation in base 2 because it repeats forever! \n\n\\section{Understanding Hexadecimal}\n\nConverting between bases is easier when they share the relationship $R_{1} = R_{2}^K$. This is the case for base 2 and base 16 where $16 = 2^4$, and because of this base 16 is a popular way to represent numbers when talking about computer systems. Hexadecimal numbers are shorter than their binary equivalents which makes them easier to read and write, and there's a lower chance of making mistakes when writing them. In hexadecimal, there are actually 16 different symbols instead of the 10 (0 to 9) we use in decimal. In hexadecimal, the first 10 digits are represented by the numbers 0 to 9 just like in decimal, but the last 6 digits are represented by the letters A to F, where A = 10, B = 11, ...up to F = 15\\\\\n\n\\noindent\nBecause the bases are closely related, you can easily convert to and from hexadecimal and binary almost just by looking at a number. Each hexadecimal digit represents 4 binary digits, so the number A in hex would be 1010 in binary, or 10 in decimal. The number F is decimal 15 or 1111, so FF would be 11111111, and so on... Try it yourself for the numbers below:\n\n\\begin{enumerate}[resume]\n\\item $FE_{16} = $\n\\item $FF_{16} = $\n\\item $DEAD_{16} = $\n\\item $ABCD_{16} = $\n\\end{enumerate}\n\n\\noindent\nNow try to go the other way, converting into hexadecimal (note if a binary number does NOT break evenly into groups of 4 digits, just add zeros on the left side of the number until it does!):\n\n\\begin{enumerate}[resume]\n\\item $1010_{2} = $\n\\item $0010_{2} = $\n\\item $001_{2} = $\n\\item $10101111_{2} = $\n\\end{enumerate}\n\n\\end{document}\n\n", "meta": {"hexsha": "49c58e185306a069bf3d66f4316c7824cccc5753", "size": 6534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "class02/02_02_binaryNumbers.tex", "max_stars_repo_name": "jeremypedersen/cppZero", "max_stars_repo_head_hexsha": "69fc8119fdcc8186fee50896ff378a3c55076fa7", "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": "class02/02_02_binaryNumbers.tex", "max_issues_repo_name": "jeremypedersen/cppZero", "max_issues_repo_head_hexsha": "69fc8119fdcc8186fee50896ff378a3c55076fa7", "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": "class02/02_02_binaryNumbers.tex", "max_forks_repo_name": "jeremypedersen/cppZero", "max_forks_repo_head_hexsha": "69fc8119fdcc8186fee50896ff378a3c55076fa7", "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": 45.375, "max_line_length": 1040, "alphanum_fraction": 0.7327823691, "num_tokens": 1839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.6819239672245795}}
{"text": "\n\\subsection*{Observations}\n\n1. Problem Formulation: the Networked Cournot Game can be described by the following set of constrained optimization problems (ref. Equation (5) of \\citep{Yi_2019}, note the difference in the last inequality constraints):\n\\begin{equation}\n\\label{eq:original_problem}\n\\def\\arraystretch{1}\n\\begin{array}{rl}\n\\min & g(x_i) = f_i(x_i, \\mathbf{x}_{-i}) = c_i(x_i) - (P(Ax))^TA_ix_i \\\\\n\\text{s.t.} & x_i \\in \\Omega_i \\subsetneq \\mathbb{R}^{n_i} \\\\\n& Ax \\leqslant r\n\\end{array}\n\\qquad i = 1, \\ldots, N\n\\end{equation}\nwhere\n\\begin{align*}\n& c_i: \\Omega_i \\to \\mathbb{R} \\text{ is the local production cost function,} \\\\\n& P: \\mathbb{R}^m \\to \\mathbb{R}^m \\text{ maps the total supply of each market to its corresponding price,}\n\\end{align*}\n$A = [A_1, \\ldots, A_N]$, $x = \\operatorname{col}(x_1, \\ldots, x_N)$, $Ax = \\sum\\limits_{1 \\leqslant j \\leqslant N} A_jx_j$, $\\Omega_i$ the feasible set of $x_i$, usually a rectangle in the Euclidean space. The last constraint is called the shared affine coupling constraint.\n\nThis set of optimization problems can be reformulated as unconstrained optimization problems:\n\\begin{equation}\n\\label{eq:reformulated_problem}\n\\begin{array}{rl}\n\\min & g_i(x_i) + \\langle \\lambda_i, r-Ax \\rangle + \\iota_{\\Omega_i} (x_i), \\quad \\lambda_i \\in \\mathbb{R}_-^m\n\\end{array}\n\\end{equation}\nwhere $\\iota_{\\Omega_i} (x_i)$ is the indicator function of $\\Omega_i$, whose subgradient is the normal cone $\\mathcal{N}_{\\Omega_i} (x_i)$ of $\\Omega_i$, and $\\operatorname{prox}_{\\mathcal{N}_{\\Omega_i}}(x_i) = \\Pi_{\\Omega_i}(x_i)$. Then applying (Douglas-Rachford? not the same) splitting, one gets the Algorithms (Algorithm 1 and 2) proposed in \\citep{Yi_2019}.\n\n\n2. It is stated in the numerical study section of \\citep{Yu_2017} that ``\\textcolor{red!60}{However, we rely on (110) in the simulations to examine the numerical performance regardless of solution feasibility.}'', where (110) is the constraints on the market capacities, similar to\n\\begin{align*}\nA_i x_i \\leqslant r_i, ~ \\sum r_i \\leqslant r ~ (\\text{or } \\sum r_i = r).\n\\end{align*}\n\nIn the first paragraph of section 3.2 of \\citep{Yi_2019}, it is stated that ``\\textcolor{red!60}{the shared affine coupling constraint is decomposed such that each player only knows a local block of the constraint matrix. Notice that $A_i$ characterizes how agent $i$ is involved in the coupling constraint (shares the global resource), also assumed to be privately known by player $i$. Then, the globally shared constraint $Ax \\geqslant b$ couples the agents’ feasible decision sets, but is not known by any agent}''.\n\n\\begin{question}\nWhat does it mean by ``each player only knows a local block of the constraint matrix''?\n\\end{question}\n\nIf one changes the original problem \\eqref{eq:original_problem} to\n\\begin{equation}\n\\label{eq:new_problem}\n\\def\\arraystretch{1}\n\\begin{array}{rl}\n\\min & g(x_i) = f_i(x_i, \\mathbf{x}_{-i}) = c_i(x_i) - (P(Ax))^TA_ix_i \\\\\n\\text{s.t.} & x_i \\in \\Omega_i \\subsetneq \\mathbb{R}^{n_i} \\\\\n& A_ix_i \\leqslant r_i \\\\\n& \\sum r_i = r\n\\end{array}\n\\qquad i = 1, \\ldots, N\n\\end{equation}\nThen the reformulated unconstrained problem is\n\\begin{equation}\n\\label{eq:reformulated_new_problem}\n\\begin{array}{rl}\n\\min & g_i(x_i) + \\langle \\lambda_i, r_i-A_ix_i \\rangle + \\langle \\mu_i, r - \\sum r_i \\rangle + \\iota_{\\Omega_i} (x_i), \\quad \\lambda_i \\in \\mathbb{R}_-^m\n\\end{array}\n\\end{equation}\n\n\n3. In the last paragraph of section 3.2 of \\citep{Yi_2019}, it is stated that ``\\textcolor{red!60}{The update of $z_i$ in Algorithm 1 can be regarded as the discrete-time integrator for the consensual errors of local multipliers, which will ensure the consensus of $\\lambda_i$ eventually}''. Since the authors stated that ``In this work, we seek a GNE with the same Lagrangian multiplier for all the agents, called variational GNE'' in section 3.1\n\n\\begin{question}\nWhat is the situation for problems where the multipliers do not need a consensus?\n\\end{question}\n\nTO ADD MORE ...\n\n\\subsection*{Computation of Gradients}\n\nComputation of the gradient of the function in equation (36) in \\citep{Yi_2019}\n\nConsider the objective function\n$$g(x_i) = f_i(x_i, \\mathbf{x}_{-i}) = c_i(x_i) - (P(Ax))^T A_ix_i,$$\n\nLet $p_i: \\mathbb{R}^{n_i} \\to \\mathbb{R}^m$ be the function of supply of the $i$-th company to the markets, i.e. $p_i(x_i) = P(Ax) = P\\left(\\sum\\limits_{1 \\leqslant j \\leqslant N} A_jx_j\\right)$. Then\n\\begin{align*}\n\\operatorname{grad} g(x_i) & = \\nabla_{x_i} f_i(x_i, \\mathbf{x}_{-i}) = \\operatorname{grad} c_i(x_i) - \\left( \\dfrac{\\partial \\left( (p_i(x_i))^T A_ix_i \\right)}{\\partial (x_i)_k} \\right)_{k=1}^{n_i} \\\\\n& = \\operatorname{grad} c_i(x_i) - \\left( \\dfrac{\\partial \\left( \\sum\\limits_{1\\leqslant t \\leqslant m} (p_i(x_i))_t (A_ix_i)_t \\right)}{\\partial (x_i)_k} \\right)_{k=1}^{n_i} \\\\\n& = \\operatorname{grad} c_i(x_i) - \\left( \\sum\\limits_{1\\leqslant t \\leqslant m}\\left( \\dfrac{\\partial \\left( (p_i(x_i))_t \\right)}{\\partial (x_i)_k} (A_ix_i)_t + \\dfrac{\\partial \\left( (A_ix_i)_t \\right)}{\\partial (x_i)_k} (p_i(x_i))_t \\right) \\right)_{k=1}^{n_i} \\\\\n% & = \\operatorname{grad} c_i(x_i) - \\left( \\sum\\limits_{1\\leqslant t \\leqslant m}\\left( \\left(\\operatorname{Jac} (p_i(x_i)) \\right)_{tk} (A_ix_i)_t + \\dfrac{\\partial \\left( \\sum\\limits_{s} (A_i)_{ts} (x_i)_s \\right)}{\\partial (x_i)_k} (p_i(x_i))_t \\right) \\right)_{k=1}^{n_i} \\\\\n& = \\operatorname{grad} c_i(x_i) - \\left( \\sum\\limits_{1\\leqslant t \\leqslant m}\\left( \\left(\\operatorname{Jac} (p_i)(x_i) \\right)_{tk} (A_ix_i)_t + (A_i)_{tk} (p_i(x_i))_t \\right) \\right)_{k=1}^{n_i} \\\\\n& = \\operatorname{grad} c_i(x_i) - \\left( \\langle \\operatorname{Jac}(p_i)(x_i)_{[:,k]}, A_ix_i \\rangle + \\langle (A_i)_{[:,k]}, p_i(x_i) \\rangle \\right)_{k=1}^{n_i} \\\\\n& =\\operatorname{grad} c_i(x_i) - \\left( \\operatorname{Jac}(p_i)(x_i) \\right)^T A_ix_i - A_i^T p_i(x_i),\n\\end{align*}\nwith $\\operatorname{Jac}(p_i)(x_i) = \\left( \\operatorname{Jac}(P)\\left(\\sum\\limits_j A_jx_j\\right) \\right) \\cdot A_i$.\n\n\nWhen $p$ is the linear inverse demand function $P(s) = p − Ds$, where $p, s \\in \\mathbb{R}^m$, $D = \\operatorname{diag}(d_1, \\ldots, d_m) \\in \\operatorname{GL}_m(\\mathbb{R})$. Then $\\operatorname{Jac}(P)(s) = -D$. Let the local production cost functions be $c_i(x_i) = \\pi_i \\left(\\sum\\limits_{j=1}^{n_i} [x_i]_j\\right)^2 + b_i^Tx_i$, then $\\operatorname{grad} c_i(x_i) = 2\\pi_i \\left(\\sum\\limits_{j=1}^{n_i} [x_i]_j\\right) + b_i$. Therefore,\n\\begin{align*}\n\\operatorname{grad} g(x_i) & = \\left(2\\pi_i \\left(\\sum\\limits_{j=1}^{n_i} [x_i]_j\\right) + b_i \\right) + \\left( A_i^TDA_ix_i - A_i^T \\left( p - D\\sum\\limits_{1 \\leqslant j \\leqslant N} A_jx_j \\right) \\right)\n\\end{align*}\n\nThe expression of $\\operatorname{Jac}(p_i)(x_i)$ corresponds to the function \\texttt{market\\_price\\_jac} in the file \\texttt{python/simulation.py}, the expression of $\\operatorname{grad} g(x_i)$ corresponds to the attribute \\texttt{\\_objective\\_grad} of the \\texttt{Company} class in \\texttt{python/networked\\_cournot\\_game.py}.\n\n\n\\subsection*{Minimal Example}\n\nConsider the networked Cournot game where there is one market with two companies. Let the price function of the market be $p(s) = 4 - s$ where $s$ is the supply. Let the production cost functions for the two companies be identical: $c(x_i) = x_i^2 + x_i$, $i = 1, 2$. Then the objective function for the companies are\n$$\\begin{cases}\n\\text{min} \\ x_1^2 + x_1 - (4 - (x_1 + x_2)) x_1 \\\\\n\\text{min} \\ x_2^2 + x_2 - (4 - (x_1 + x_2)) x_2 \\\\\n\\end{cases}$$\nThe solution is $x_1 = x_2 = 0.6.$\n\n\n\\printbibliography\n", "meta": {"hexsha": "82b744d76c729b801d848a73f117fa42340ef61e", "size": 7520, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/dgne_notes.tex", "max_stars_repo_name": "wenh06/dgne", "max_stars_repo_head_hexsha": "4441e8136108b1df64de6330318556f3f3e4d075", "max_stars_repo_licenses": ["MIT"], "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/dgne_notes.tex", "max_issues_repo_name": "wenh06/dgne", "max_issues_repo_head_hexsha": "4441e8136108b1df64de6330318556f3f3e4d075", "max_issues_repo_licenses": ["MIT"], "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/dgne_notes.tex", "max_forks_repo_name": "wenh06/dgne", "max_forks_repo_head_hexsha": "4441e8136108b1df64de6330318556f3f3e4d075", "max_forks_repo_licenses": ["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.7477477477, "max_line_length": 518, "alphanum_fraction": 0.6989361702, "num_tokens": 2710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.681923964546135}}
{"text": "\\chapter{Limits}\n\nHere is a function:\n\n$$f(x) = \\frac{x^2}{x} + 1$$\n\nThis $f$ is defined for any real number \\emph{except 0}. (You can't\ndivide anything, including zero, by zero.)\n\nLet's plot $f$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin] (-3,-3) grid (3,3);\n\n\n    \\draw[<->,thick,dashed] (-3.2,0) -- (3.2,0) node[right] {$x$};\n    \\draw[<->,thick,dashed] (0,-3.2) -- (0, 3.2) node[above] {$y$};\n% curve\n\\draw[<-,draw=black,thick,domain=-3:-0.1,samples=300,variable=\\x] plot (\\x,{\\x + 1});\n\\draw[thick] (0,1) circle (0.1);\n\\draw[->,draw=black,thick,domain=0.1:2,samples=300,variable=\\x] plot (\\x,{\\x + 1});\n\\end{tikzpicture}\n\nYou can see that the function is the same as $x + 1$ everywhere except\n$x = 0$.  You can see that as the function approaches $x=0$ from the\nleft, the value of the function approaches 1.  You can see that as the\nfunction approaches $x=1$ from the right, the value of the function\napproaches 1.\n\nMathematicians say ``The \\newterm{limit} of $f$ as $x$ approaches 0, is 1.''  We have a notation for this:\n\n$$\\lim_{x \\rightarrow 0} f(x) = 1$$\n\nWe generally use limit whenever we mean ``We are getting arbitrarily\nclose, but we can never really get there.''  For example, you might\nsay ``The limit of $1/t$ as $t$ goes to infinity is 0.''\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin] (-5,-5) grid (5,5);\n    \\draw[<->,thick,dashed] (-5.2,0) -- (5.2,0) node[below] {$t$};\n    \\draw[<->,thick,dashed] (0,-5.2) -- (0, 5.2);\n% curve\n\\draw[<->,draw=black,thick,domain=0.2:5,samples=300,variable=\\x] plot (\\x,{1/\\x});\n\\draw[<->,draw=black,thick,domain=-5:-0.2,samples=300,variable=\\x] plot (\\x,{1/\\x});\n\\draw (5.0, 0.2) node[above] {$t \\rightarrow \\infty$, $1/t \\rightarrow 0$};\n\\draw (0.0, 5.2) node[above] {$t \\rightarrow 0$ from the right, $1/t \\rightarrow \\infty$};\n\\draw (0.0, -5.2) node[below] {$t \\rightarrow 0$ from the left, $1/t \\rightarrow -\\infty$};\n\\draw (-5.0, -0.2) node[below] {$t \\rightarrow -\\infty$, $1/t \\rightarrow 0$};\n\n\\end{tikzpicture}\n\nWhat is the limit of $1/t$ as $t$ approaches zero? The limit isn't\ndefined because if you approach from the right, $1/t$ goes to\ninfinity, but if you approach from the left, $1/t$ goes to negative\ninfinity.\n", "meta": {"hexsha": "7a33525982a14553980a47887e9aee05100fc3f9", "size": 2437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Limits/intro-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Limits/intro-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Limits/intro-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 38.078125, "max_line_length": 106, "alphanum_fraction": 0.6233073451, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6819239601514383}}
{"text": "\\subsection{Helices}\r\n\\noindent\r\nA helix looks like a spring and appears to look like a circle when viewed from the top looking down.\r\nIt has the form $\\vec{r}(t) = \\langle r\\cos{t}, r\\sin{t}, ct\\rangle$ where $a\\in\\mathbb{R}$. $a$ defines the ``tightness'' between consecutive windings.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./vectorValuedFunctions/Helix.png}\r\n\t\\caption{A helix}\r\n\\end{figure}", "meta": {"hexsha": "7a313eae477fb74ac4e037772ad3315a24438213", "size": 430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/helices.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/vectorValuedFunctions/helices.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/vectorValuedFunctions/helices.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": 43.0, "max_line_length": 153, "alphanum_fraction": 0.7209302326, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024556, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6819239596573756}}
{"text": "\\documentclass[revision-guide.tex]{subfiles}\n%% Current Author: PS\n\\setcounter{chapter}{16}\n\\begin{document}\n\\raggedbottom\n\\chapter{Nuclear Physics}\n\\begin{content}\n    \\item equations of radioactive decay\n    \\item mass excess and nuclear binding energy\n    \\item antimatter\n    \\item the standard model\n\\end{content}\n\\section*{Candidates should be able to:}\n\n\\spec{recall and show that the random nature of radioactive decay leads to the differential equation\n\\begin{equation} \\label{n-diff} \\frac{dN}{dt} = -\\lambda N \\end{equation} and that\n\\begin{equation} \\label{n-exp} N = N_0 e^{-\\lambda t} \\end{equation} is a solution to this equation.}\n\nRadioactive decay is characterised by the fact that the number of nuclei which disintegrate per unit time is directly proportional to the number of unchanged nuclei remaining. Since a disintegrating nucleus reduces the number remaining, there is a negative sign in the proportionality. This relationship can be expressed mathematically as equation \\ref{n-diff}. Where $N$ is the number of nuclei and $\\lambda$ is called the decay constant, with units \\si{\\per\\second}.\n\nEquation \\ref{n-diff} is a differential equation with respect to time and therefore the solution to it is a function of time. We can show that equation \\ref{n-exp} is a solution to this equation by differentiating it.\n\n\\begin{align*}\nN &= N_0 e^{-\\lambda t} \\\\\n\\frac{dN}{dt} &= \\left( -\\lambda \\right) N_0 e^{-\\lambda t} \\\\\n&= -\\lambda N\n\\end{align*}\n\n\\spec{recall that activity \\begin{equation} A = -\\frac{d N}{dt} \\end{equation} and show that \\( A = \\lambda N \\)  and \\( A = A_0e^{-\\lambda t}\\)}\n\nEvery time a radioactive nucleus disintegrates it emits a particle of ionising radiation. Thus the activity is simply the negative of the rate of change of the number of unchanged nuclei remaining. Simple substitutions allow the derivation of the following equations.\n\n\\begin{align*}\nA &= -\\frac{dN}{dt} & N &= N_0 e^{-\\lambda t} \\\\\n&= -(-\\lambda N) & -\\lambda N &= -\\lambda N_0 e^{-\\lambda t} \\\\\n&= \\lambda N & A &= A_0e^{-\\lambda t}\n\\end{align*}\n\nNote that we do not measure the true activity as that would mean detecting all of the radiation given off by the sample. However, we assume that the measured activity is proportional to the true activity and therefore all our measurements behave in the same way.\n\n\\spec{show that the half-life \\[ t_\\frac{1}{2} = \\frac{\\ln{2}}{\\lambda} \\]}\n\nThe half-life is defined as the time take for half of the nuclei to decay. Therefore I can substitute $N = \\frac{N_0}{2}$ into equation \\ref{n-diff} to give:\n\\begin{align*}\n\\frac{1}{2} = e^{-\\lambda t_\\frac{1}{2}}  \\\\\n\\ln{\\frac{1}{2}} = -\\lambda t_\\frac{1}{2} \\\\\nt_\\frac{1}{2} = \\frac{\\ln{2}}{\\lambda}\n\\end{align*}\n\n\\spec{use the equations in (a), (b) and (c) to solve problems}\n\n\\spec{recognise and use the equation \\begin{equation} \\label{I-exp} I = I_0e^{- \\mu x} \\end{equation} as applied to attenuation losses}\n\nWhen a wave or ionising radiation travels through a medium its amplitude will reduce due to \\emph{attenuation}. This is due to scattering and/or absorption by the medium. Note that is this different to a reduction in intensity due to the radiation spreading out. It is assumed that if a given fraction of the intensity is absorbed in a unit length then equation \\ref{n-diff} can be used, replacing $N$ with intensity, $t$ with distance, $x$ and the constant of proportionality with $\\mu$. This gives\n\\begin{equation} \\label{I-diff}\n\\frac{dI}{dx} = -\\mu I\n\\end{equation}\nUsing a similar logic to that for equation \\ref{n-exp} we can show that equation \\ref{I-exp} is a solution to this equation.\n\n\\spec{recall that radiation emitted from a point source and travelling through a non-absorbing material obeys an inverse square law and use this to solve problems}\n\n\\begin{figure}[h]\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.6]\n      \\draw[->-, thick]  (0,0.5) -- (0,4);\n      \\draw[->-, thick] ({sqrt(.125)},{sqrt(.125)}) -- ({sqrt(9)},{sqrt(9)});\n      \\draw[->-, thick] (.5,0) -- (4,0);\n      \\draw[->-, thick] ({sqrt(.125)},-{sqrt(.125)}) -- ({sqrt(9)},-{sqrt(9)});\n      \\draw[->-, thick] (0,-.5) -- (0,-4);\n      \\draw[->-, thick] (-{sqrt(.125)},-{sqrt(.125)}) -- (-{sqrt(9)},-{sqrt(9)});\n      \\draw[->-, thick] (-.5,0) -- (-4,0);\n      \\draw[->-, thick] (-{sqrt(.125)},{sqrt(.125)}) -- (-{sqrt(9)},{sqrt(9)});\n      \\filldraw[fill=yellow] (0,0) circle (0.5cm);\n    \\end{tikzpicture}\n  \\end{center}\n  \\caption{Radial radiation}\n  \\label{radiation-spreading}\n\\end{figure}\n\nRadiation emitted from a point source spreads out symmetrically in all directions as shown in figure \\ref{radiation-spreading}. The intensity is defined as the power per unit area of radiation. A distance $r$ from the centre of the source the radiation is spread over the surface of a sphere and is therefore calculated using\n\\begin{equation}\n  I = \\frac{P}{4\\pi r^2}\n\\end{equation}\n\nSince $I\\propto r^{-2}$ this is known as an inverse-square law.\n\n\\spec{estimate the size of a nucleus from the distance of closest approach of a charged particle}\n\nWhen particles approach a nucleus head-on they begin with kinetic energy $E_K$. All of this kinetic energy is converted to electrical potential energy, $EPE$. If the energy of the alpha particles is known then a distance of minimum separation can be calculated.\n\n\\begin{example}\n  Calculate the minimum distance of separation of a alpha particle of kinetic energy \\SI{4.0}{\\mega\\electronvolt} travelling directly towards a gold nucleus ($Z=79$).\n\n  \\answer\n\n  Equating the initial kinetic energy to the electrostatic potential gives\n  \\[ E_k = \\frac{Q_1 Q_2}{4\\pi \\epsilon_0 d} \\]\n  therefore\n  \\begin{align*}\n    d &= \\frac{Q_1 Q_2}{4 \\pi \\epsilon_0 E_k} \\\\\n    &= \\frac{2\\times79\\times (\\num{1.6e-19})^2}{4\\pi \\epsilon_0 \\times \\num{4.0e6} \\times \\num{1.6e-19}} \\\\\n    &= \\SI{5.7e-14}{\\meter}\n  \\end{align*}\n\\end{example}\n\nIt turns out that if high energy alpha particles are fired at the nucleus then Rutherford's deflection formulae break down and the distribution of alpha particles no longer fits the expectation. Under these circumstances it can be assumed the alpha particle is interacting with the nucleus and therefore has been able to approach to within the nuclear radius.\n\n\\newpage\n\\spec{understand the concept of nuclear binding energy, and recognise and use the equation $ \\Delta E = c^2 \\Delta m$ (binding energy will be taken to be positive)}\n\nIt turns out that the mass of a nucleus is always smaller than the total mass of the constituent protons and neutrons. This difference is called the \\emph{mass deficit} and can be converted to an energy using $ \\Delta E = c^2 \\Delta m$. The reduction in mass corresponds to the energy released by combining the nucleons.\n\n\\begin{example}\n  Calculate the binding energy of a helium-4 nucleus of mass \\SI{4.0015}{\\amu}\n\n  \\answer\n\n  The helium-4 nucleus is composed of two protons and two neutrons. Their total mass is\n  \\[ 2\\times \\SI{1.00728}{\\amu}+2\\times \\SI{1.00867}{\\amu} = \\SI{4.0319}{\\amu} \\]\n  The mass deficit, $\\Delta m$, is given by\n  \\[ \\Delta m = \\SI{4.0319}{\\amu} - \\SI{4.00215}{\\amu} = \\SI{0.0304}{\\amu} \\]\n  Therefore the binding energy is calculated as\n  \\[ \\num{0.0304} \\times \\num{1.66e-27} \\times c^2 = \\SI{4.54e-12}{\\joule} = \\SI{28.4}{\\mega\\electronvolt} \\]\n\\end{example}\n\n\\newpage\n\\spec{recall, understand and explain the curve of binding energy per nucleon against nucleon number}\n\nA useful measure of the stability of the nucleus is given by its \\emph{binding energy per nucleon}. This is the binding energy divided by the nucleon number. A plot of the binding energy per nucleon against nucleon number is show in figure \\ref{binding-energy}.  The nucleus with the largest binding energy is iron-56 and this therefore is the most stable nucleus. Nuclei with nucleon numbers below iron-56 will release energy when they undergo nuclear fusion and those above iron-56 will release energy when they undergo fission.\n\n\\begin{figure}[h]\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.75]\n      \\draw[-] (0,0) -- (0,9);\n      \\foreach \\y in {0,1,...,9} {\n        \\draw (-.2,\\y) node {\\y};\n        \\draw (0,\\y) -- (0.1,\\y);\n      }\n      \\draw[-] (0,0) -- (12,0);\n      \\foreach \\x in {0,40,80,...,240} {\n        \\draw (\\x/20,-0.4) node{{\\x}};\n        \\draw (\\x/20,0) -- (\\x/20,0.1);\n      }\n      \\draw[thick] (0.1,1) .. controls (0.1,9) and (2,8.8) .. (2.8,8.8) .. controls (4.8,8.8) and (9,8.5) .. (12,7.8);\n      \\draw (6,-1) node{Nucleon Number};\n      \\draw (-0.9,4.5) node {\\rotatebox{90}{Binding Energy per Nucleon / MeV}};\n    \\end{tikzpicture}\n  \\end{center}\n  \\caption{Variation of binding energy per nucleon with nucleon number}\n  \\label{binding-energy}\n\\end{figure}\n\n\\spec{recall that antiparticles have the same mass but opposite charge and spin to their corresponding\nparticles}\n\nAll normal particles have an antiparticle partner with the same mass, but some properties which are opposite including electrical charge.\n\n\\spec{relate the equation $\\Delta E = c^2 \\Delta m$ to the creation or annihilation of particle-antiparticle pairs}\n\nA particle-antiparticle pair can be created whenever there is enough energy present to do so. For example, if a photon of light is near an atomic nucleus it can spontaneously convert into an electron-positron pair.\n\n\\begin{example}\n  Calculate the minimum energy a photon must have in order to create an electron-positron pair.\n  \\answer\n  \\[ E = c^2 \\Delta m = c^2 \\times 2 \\times\\num{9.11e-31} = \\SI{1.02}{\\mega\\electronvolt} \\]\n\\end{example}\n\n\\spec{recall the quark model of the proton (uud) and the neutron (udd)}\n\nThe theory of quarks was developed to explain the large number of particles discovered in the early particle colliders. Particles made of quarks are called \\emph{hadrons}. Normal matter is made up of two types of quark, the up quark (charge $+\\frac{2}{3}e$) and the down quark (charge $-\\frac{1}{3}e$). From the charges it is possible to see that the proton must be uud and the neutron udd.\n\n\\spec{understand how the conservation laws for energy, momentum and charge in beta-minus decay were used to predict the existence and properties of the antineutrino}\n\nThe existence of the antineutrino was first predicted from the energy spectrum of beta decay. Beta particles are produced when a neutron in the nucleus is converted into a proton and a high energy electron. These electrons leave the nucleus at high speed and are detected as beta particles. In such a scenario (a two body process) the electrons should have a fixed amount of energy due to the conservation of momentum. However, the electron was found to have a range of energies. The explanation provided was that whenever an electron was emitted with little energy a third particle has carried away a lot of energy (and vice-versa). The particle had to be neutral (to conserve charge) and of very small mass and was named the \\textbf{neutrino}.\n\nThe full beta decay equation now becomes\n\\[ \\text{n} \\rightarrow \\text{p} + \\text{e}^- + \\overline{\\nu}_\\text{e} \\]\n\nFurther evidence for the existence of this third particle comes from bubble chamber tracks left by beta decay which show the nucleus and electron both recoiling away from a particle which does not leave a trace in the bubble chamber - the neutrino. A photo of this decay can be seen at the science photo library here: \\url{http://www.sciencephoto.com/media/1210/view}\n\n\\spec{balance nuclear transformation equations for alpha, beta-minus and beta-plus emissions}\n\nWhen these nuclear decays occur total nucleon number remains the same and charge is conserved. In order to make life easier we give beta-minus particles a proton number of $-1$ and a nucleon number of zero. Beta-plus particles (positrons) are given a proton number of $+1$. Alpha particles are helium-4 nucleii ($_2^4\\text{He}$).\n\nAs an example, if we know that magnesium-23 decays by beta-plus decay we can write\n\\[ _{12}^{23}\\text{Mg} \\rightarrow _Z^A\\text{X} + _{1}^{0}e^+ \\]\n\nWe can deduce the identity of X by conserving nucleon number ($A+0=23$) and proton number ($Z+1 = 12$). Therefore:\n\n\\[ _{12}^{23}\\text{Mg} \\rightarrow _{11}^{23}\\text{Na} + _{1}^{0}e^+ \\]\n\n\\spec{recall that the standard model classifies matter into three families: quarks (including up and down),leptons (including electrons and neutrinos) and force carriers (including photons and gluons)}\n\nAn important feature to note is that quarks and gluons are never observed on their own. There are further `generations' of quarks and leptons but these only exist at higher energies.\n\n\\spec{recall that matter is classified as baryons and leptons and that baryon numbers and lepton numbers are conserved in nuclear transformations.}\n\nBaryons are made up of three quarks and have a baryon number of +1. Similarly, leptons have a lepton number of +1. Anti-baryons and anti-leptons have respective numbers of -1.\n\nFor example, conservation of baryon number prohibits the following:\n\\begin{align*}\n    p + n &\\rightarrow p + e^+ + e^- \\\\\n    B = 1 + 1 &\\neq 1 + 0 + 0\n\\end{align*}\n\nConservation of lepton number also shows why the anti-electron neutrino is required in beta decay:\n\\begin{align*}\n    n &\\rightarrow p + e^- + \\overline{\\nu}_e \\\\\n    L = 0 &= 0 + 1 + (-1) \\\\\n    B = 1 &= 1 + 0 + 0\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "e20073634f489c277a1a1663988cb4bdea498f1e", "size": 13283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "17-nuclear-physics.tex", "max_stars_repo_name": "dhruvrattan/physicsrevision", "max_stars_repo_head_hexsha": "99bf9346cd40ebe6f312f164d731b7010b86534a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2017-03-13T19:37:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-08T21:47:07.000Z", "max_issues_repo_path": "17-nuclear-physics.tex", "max_issues_repo_name": "dhruvrattan/physicsrevision", "max_issues_repo_head_hexsha": "99bf9346cd40ebe6f312f164d731b7010b86534a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2016-12-19T16:46:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T08:14:03.000Z", "max_forks_repo_path": "17-nuclear-physics.tex", "max_forks_repo_name": "dhruvrattan/physicsrevision", "max_forks_repo_head_hexsha": "99bf9346cd40ebe6f312f164d731b7010b86534a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2016-12-19T16:16:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-09T13:48:59.000Z", "avg_line_length": 62.0700934579, "max_line_length": 745, "alphanum_fraction": 0.7171572687, "num_tokens": 3770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6818044457041413}}
{"text": "\\problemname{Gwen's Gift}\n\nGwen loves most numbers. In fact, she loves every number that is \\textit{not} a multiple of $n$ (she really hates the number $n$).\nFor her friends' birthdays this year, Gwen has decided to draw each of them a sequence of $n-1$ flowers.\nEach of the flowers will contain between $1$ and $n-1$ flower petals (inclusive).\nBecause of her hatred of multiples of $n$, the total number of petals in\nany non-empty contiguous subsequence of flowers cannot be a multiple of $n$. For example, if $n = 5$, then the top two paintings are valid,\nwhile the bottom painting is not valid since the second, third and fourth flowers have a total of $10$ petals.\n(The top two images are Sample Input $3$ and $4$.)\n\n\\begin{center}\n \\includegraphics[width=0.9\\textwidth]{gift-flowers.png}\n\\end{center}\n\nGwen wants her paintings to be unique, so no two paintings will have\nthe same sequence of flowers.  To keep track of this, Gwen recorded\neach painting as a sequence of $n-1$ numbers specifying the number of\npetals in each flower from left to right.  She has written down all\nvalid sequences of length $n-1$ in lexicographical order. A sequence\n$a_1,a_2,\\dots, a_{n-1}$ is lexicographically smaller than \n$b_1, b_2, \\dots, b_{n-1}$ if there exists an index $k$ such that $a_i = b_i$\nfor $i < k$ and $a_k < b_k$.\n\nWhat is the $k$th sequence on Gwen's list?\n\n\n\\section*{Input}\n\nThe input consists of a single line containing two integers $n$~($2 \\leq n \\leq 1\\,000$),\nwhich is Gwen's hated number, and $k$~($1 \\leq k \\leq 10^{18}$), which is the index of the valid sequence in question\nif all valid sequences were ordered lexicographically.\nIt is guaranteed that there exist at least $k$ valid sequences for this value of $n$.\n\n\n\\section*{Output}\n\nDisplay the $k$th sequence on Gwen's list.\n\n", "meta": {"hexsha": "8cedd83ea7766a9558597388eb26d705ab2c652d", "size": 1796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/gwensgift/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/gwensgift/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/gwensgift/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": 46.0512820513, "max_line_length": 139, "alphanum_fraction": 0.7388641425, "num_tokens": 502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.6818044379724397}}
{"text": "\\section{Formulation of the Data Compression Problem}\nZ-checker has plentiful algorithms and functions for assessing lossy compressors on scientific data sets.\nWe list the metrics that Z-checker can evaluate for assessing lossy compressors as follows.\n\\begin{itemize}\n\\item Pointwise compression error between original and reconstructed data sets, for example, absolute error and value-range-based relative error. In this report, we will present the value range of the data in the description-of-data section, and then adopt the absolute error bound (a constant such as 1E-5) to control the error in the compression.\n\\item Statistical compression error between original and reconstructed data sets, such as root mean squared error (RMSE), normalized RMSE (NRMSE), and peak signal-to-noise ratio (PSNR). According to the definition of NRMSE and PSNR, the smaller NRMSE, the larger the PSNR. In this report, hence, we focus on PSNR, which is compuated as follows.\n\\begin{equation}\nPSNR = 20\\cdot \\log_{10}{(value\\_range)} - 10\\cdot \\log_{10}{(MSE)}. \n\\end{equation}  \nwhere value\\_range and MSE refer to data value range and the mean squared compression error respectively.\n\\item Distribution of compression errors refers to the probability distribution density of the compression errors.\nIt is an important metric for some scientific researchers require the compression errors to follow some certain distributions, such as Gaussian distribution.\n\\item Compression ratio (a.k.a, compression factor) is to evaluate the reduction size as a result of the compression. It is calculated by the original data size divided by the compressed data size.\n\\item Bit rate (bits/value) represents the amortized number of bits used to represent a data point's value after compression.\n\\item Rate-distortion based on statistical compression error and bit rate. It represents the distortion quality per bit of compressed storage. \nRate refers to bit rate in bits/value. Distortion refers to the overall deviation of the data after compression and is generally assessed via PSNR.\n\\item Compression and decompression rate is to evaluate the processing speed.\nIn order to save I/O time during the execution, not only do the users hope to get a high compression factor, but the compression also has to suffer from limited compression/decompression time such that the overall execution performance can be maximized.\nCompression/decompression rate refers to the amount of data to be compressed/decompressed per second, e.g., MB/s.\n\\item Autocorrelation of compression errors is important for assessing the degree of autocorrelation (if any) that the lossy compressors add to the original data sets.\n\\item Distortion of spectrum is to evaluate the distortion of the spectrum values (generated by discrete Fourier transform) between original and reconstructed data sets.\nMinimizing such distortion is required by some scientist researchers.\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "c569b1ac86f7304013b273901f3ab65989b66db6", "size": 2932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "template/tex/metrics.tex", "max_stars_repo_name": "CODARcode/Z-checker", "max_stars_repo_head_hexsha": "249fb901bba9e786a1cb093b4174b724df0c7db8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2017-06-18T15:43:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:00:10.000Z", "max_issues_repo_path": "template/tex/metrics.tex", "max_issues_repo_name": "CODARcode/Z-checker", "max_issues_repo_head_hexsha": "249fb901bba9e786a1cb093b4174b724df0c7db8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-06-19T12:44:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-30T12:55:52.000Z", "max_forks_repo_path": "template/tex/metrics.tex", "max_forks_repo_name": "CODARcode/Z-checker", "max_forks_repo_head_hexsha": "249fb901bba9e786a1cb093b4174b724df0c7db8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-06-18T15:39:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T22:36:05.000Z", "avg_line_length": 108.5925925926, "max_line_length": 348, "alphanum_fraction": 0.8107094134, "num_tokens": 605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.859663754105328, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.6818044372962337}}
{"text": "\\chapter{Solutions for Chapter 1}\n\n\\ex{1.1}\n\\begin{enumerate}\n    \\item \n    $R = \\SI{5}{\\kohm} + \\SI{10}{\\kohm} = \\mans{\\SI{15}{\\kohm}}$\n\n    \\item \n    $R = \\dfrac{R_1 R_2}{R_1 + R_2} = \\dfrac{\\SI{5}{\\kohm} \\times \\SI{10}{\\kohm}}{\\SI{5}{\\kohm} + \\SI{10}{\\kohm}} = \\mans{\\SI{3.33}{\\kohm}}$\n\n\\end{enumerate}\n\n\\ex{1.2}\n$P = IV = \\left(\\dfrac{V}{R}\\right)V = \\dfrac{(\\SI{12}{\\V})^2}{\\SI{1}{\\ohm}} = \\mans{\\SI{144}{\\W}}$\n\n\\ex{1.3}\nConsider a simple series resistor circuit.\n\\begin{circuit}{fig:1.3.1}{A basic series circuit.}\n    (0,0) to[V=$V$,invert] (0,4)\n        to[short,i=$I$] (2,4)\n        to[R=$R_1$,v=$V_{1}$] (2,2)\n        to[R=$R_2$,v=$V_{2}$] (2,0)\n        to (0,0)\n\\end{circuit}\nBy KVL and Ohm's law \\[ V = V_{1} + V_{2} = R_{1}\\cdot I + R_{2} \\cdot I = (R_{1}+R_{2}) \\cdot I = R \\cdot I \\]\nwhere \\[\\mans{R = R_{1} + R_{2}}\\] is the resistance of $R_{1}$ and $R_{2}$ in series. Now, consider a simple parallel resistor circuit.\n\n\\begin{circuit}{fig:1.3.2}{A basic parallel circuit.}\n    (0,0) to[V=$V$,invert] (0,3)\n    to[short,i=$I$] (2,3)\n    to[R=$R_1$,i>^=$I_{1}$] (2,0);\n    \\draw (2,3) to[short] (4,3)\n    to[R=$R_2$,i>^=$I_{2}$] (4,0)\n    to (0,0)\n\\end{circuit}\nBy KCL and Ohm's law \\[ I = I_{1} + I_{2} = \\frac{V}{R_{1}} + \\frac{V}{R_{2}} = \\left(\\frac{1}{R_{1}}+\\frac{1}{R_{2}}\\right)\\cdot V \\]\nsolving for V as a function of I we get\n\\[V = \\dfrac{1}{\\frac{1}{R_{1}}+\\frac{1}{R_{2}}}\\cdot I = \\frac{R_{1}R_{2}}{R_{1}+R_{2}}\\cdot I = R\\cdot I \\]\nwhere \\[\\mans{R = \\dfrac{1}{\\frac{1}{R_{1}}+\\frac{1}{R_{2}}} = \\frac{R_{1}R_{2}}{R_{1}+R_{2}}}\\] is the resistance of $R_{1}$ and $R_{2}$ in parallel.\n\n\\ex{1.4}\nWe known that the resistance $R_{12}$\\footnote{Here we have only assigned a name to the resistance in parallel between $R_{1}$ and $R_{2}$.} of two resistors $R_{1}$ and $R_{2}$ in parallel is given by \\[R_{12} = \\dfrac{1}{\\frac{1}{R_{1}}+\\frac{1}{R_{2}}}\\]\n\nNow, the resistance $R_{123}$ of three resistors $R_{1}$, $R_{2}$ and $R_{3}$ in parallel is equal to the resistance of two resistors $R_{12}$ (the resistance between $R_{1}$ and $R_{2}$ in parallel) and $R_{3}$ in parallel, then \\[R_{123} = \\frac{1}{\\frac{1}{R_{12}}+\\frac{1}{R_{3}}} = \\frac{1}{\\frac{1}{R_{1}}+\\frac{1}{R_{2}}+\\frac{1}{R_{3}}}\\]\n\nWe will prove by induction that the resistance $R_{1\\cdots n}$ of $n$ resistances $R_{1}, R_{2}, \\ldots, R_{n}$ in parallel is given by \\[R_{1\\cdots n} = \\dfrac{1}{\\sum_{i=1}^{n}\\frac{1}{R_{i}}}\\]\n\nFirst, it's trivial to show that with $n = 1$ the equality holds. Now, we will assume that the equality is satisfied for $n = k$, that is\n\\[R_{1\\cdots k} = \\dfrac{1}{\\sum_{i=1}^{k}\\frac{1}{R_{i}}}\\]\n\nThen, we must show that equality holds for $n = k+1$. Thus, the resistance $R_{1\\cdots (k+1)}$ of $(k+1)$ resistances $R_{1}, R_{2}, \\ldots, R_{k+1}$ in parallel is equal to the resistance of two resistors $R_{1\\cdots k}$ and $R_{k+1}$ in parallel, then \\[R_{1\\cdots (k+1)} = \\frac{1}{\\frac{1}{R_{1\\cdots k}}+\\frac{1}{R_{k+1}}} = \\frac{1}{\\sum_{i=1}^{k}\\frac{1}{R_{i}}+\\frac{1}{R_{k+1}}} = \\frac{1}{\\sum_{i=1}^{k+1}\\frac{1}{R_{i}}}\\]\nwhere we have proved that equality holds for $n = k+1$. Finally, the resistance of $n$ resistors in parallel is given by \\[\\mans{R_{1\\cdots n} = \\dfrac{1}{\\sum_{i=1}^{n}\\frac{1}{R_{i}}} = \\frac{1}{\\frac{1}{R_{1}}+\\frac{1}{R_{2}}+\\ldots+\\frac{1}{R_{n}}}}\\]\n\n\\ex{1.5}\nGiven that $P = \\dfrac{V^2}{R}$, we know that the maximum voltage we can achieve is \\SI{15}{\\V} and the smallest resistance we can have across the resistor in question is \\SI{1}{\\kohm}. Therefore, the maximum amount of power dissipated can be given by \\[P = \\frac{V^2}{R} = \\frac{(\\SI{15}{\\V})^2}{\\SI{1}{\\kohm}} = \\mans{\\SI{0.225}{\\W}}\\]\nThis is less than the \\SI{0.25}{\\W} power rating.\n\n\\ex{1.6}\n\\begin{enumerate}\n    \\item\n    The total current required by New York City that will flow through the\n    cable is \n    \\[I = \\frac{P}{V} = \\frac{\\SI{1e10}{\\W}}{\\SI{115}{\\V}} = \\SI{86.96}{\\mega\\A}\\]\n    Therefore, the total power lost per foot of cable can be calculated by:\n    \\[P = I^2R = \\left(\\SI{86.96e6}{\\A}\\right)^2 \\times \\left(\\SI{5e-8}{\\ohm\\per ft}\\right) = \\mans{\\SI{3.78e8}{\\W\\per ft}}\\] \n    \\item\n    The length of cable over which all $\\SI{1e10}{\\W}$ will be lost is:\n    \\[L = \\frac{\\SI{1e10}{\\W}}{\\SI{3.78e8}{\\W\\per ft}} = \\mans{\\SI{26.45}{ft}}\\]\n    \\item\n    To calculate the heat dissipated by the cable, we can use the Stefan-Boltzmann equation $T = \\sqrt[4]{\\frac{P}{A\\sigma}}$, with A corresponding to the cylindrical surface area of the \\SI{26.45}{ft} section of 1-foot diameter cable. Note that $\\sigma$ is given in \\si{\\cm^2}, so we will need to use consistent units.\n    \\[A = \\pi DL = \\pi \\times \\SI{30.48}{\\cm}\\times \\SI{806.196}{\\cm} = \\SI{7.72e4}{\\cm^2}\\]\n    Therefore,\n    \\[T = \\sqrt[4]{\\frac{P}{A\\sigma}} = \\sqrt[4]{\\frac{\\SI{1e10}{\\W}}{\\SI{7.72e4}{\\cm^2} \\times \\SI{6e-12}{\\W\\per\\kelvin^4\\per\\cm^2}}} = \\mans{\\SI{12121}{K}} \\]\n    This is indeed a preposterous temperature, more than twice that at the surface of the Sun! The solution to this problem is that power should be transmitted along long distances at high voltage. This greatly reduces $I^2R$ losses. For example, a typical high voltage line voltage is $\\SI{115}{\\kV}$. At this voltage, the power loss per foot of cable is only \\SI{378}{\\W} per foot. Intuitively, we know that reducing current allows for lower power dissipation. We can deliver the same amount of power with a lower current by using a higher voltage.\n\\end{enumerate}\n\n\\ex{1.7}\nA \\SI{20000}{\\ohm\\per\\V} meter read, on its \\SI{1}{\\V} scale, puts a $\\SI{20000}{\\ohm\\per\\V} \\cdot \\SI{1}{\\V} = \\SI{20000}{\\ohm} = \\SI{20}{\\kohm}$ resistor in series with an ideal ammeter (ampere meter). Also, a voltage source with an internal resistance is equivalent to an ideal voltage source with its internal resistance in series.\n\\begin{enumerate}\n    \\item In the first question, we have the following circuit:\n    \\begin{circuit}{fig:1.7.1}{A voltage source with internal resistance and a \\SI{20000}{\\ohm\\per\\V} meter read in its \\SI{1}{\\V} scale.}\n        (0,0) to[V=\\SI{1}{\\V},invert] (0,4)\n        to[R=\\SI{10}{\\kohm},i>^=$I$] (5,4);\n        \\draw[blue] (5,4) to[R=\\SI{20}{\\kohm},*-,color=blue] (5,2)\n        to node[draw,circle,fill=white] {A} (5,0);\n        \\draw[blue] node[draw,circle,fill=blue,inner sep=1pt] at(5,0) {};\n        \\draw (5,0) to (0,0)\n    \\end{circuit}\n    Then, we have that the current in the ideal ammeter and the voltage in the meter resistance are given by\\footnote{When a meter only measures currents, it puts a resistance in series to measures the current through that resistance and internally converts that current into voltage to \\textit{measure voltages}.}\n    \\[I = \\frac{\\SI{1}{\\V}}{\\SI{10}{\\kohm} + \\SI{20}{\\kohm}} = \\mans{\\SI{0.0333}{\\mA}} \\quad \\text{ and } \\quad V = \\SI{0.0333}{\\mA} \\times \\SI{20}{\\kohm} = \\mans{\\SI{0.666}{\\V}}\\]\n    \\item In the second question, we have the following circuit:\n    \\begin{circuit}{fig:1.7.2}{A $\\SI{10}{\\kohm}-\\SI{10}{\\kohm}$ voltage divider and a $\\SI{20000}{\\ohm\\per\\V}$ meter read in its $\\SI{1}{\\V}$ scale.}\n        (0,0) to[V=$\\SI{1}{\\V}$,invert] (0,4)\n        to[short] (3,4)\n        to[R=$\\SI{10}{\\kohm}$] (3,2)\n        to[R=$\\SI{10}{\\kohm}$] (3,0);\n        \\draw[blue] (3,2) to node[draw,circle,fill=white] {A} (5,2)\n        to[R=$\\SI{20}{\\kohm}$,color=blue] (5,0)\n        to[short,-*,color=blue] (3,0);\n        \\draw[blue] node[draw,circle,fill=blue,inner sep=1pt] at(3,2) {};\n        \\draw (3,0) to (0,0)\n    \\end{circuit}\n    Now, we can to obtain the Thévenin equivalent circuit of circuit in Figure \\ref{fig:1.7.2} with\n    \\[R_{\\Th} = \\frac{\\SI{10}{\\kohm} \\cdot \\SI{10}{\\kohm}}{\\SI{10}{\\kohm} + \\SI{10}{\\kohm}} = \\SI{5}{\\kohm}\\]\n    and\n    \\[V_{\\Th} = \\SI{1}{\\V} \\cdot \\frac{\\SI{10}{\\kohm}}{\\SI{10}{\\kohm} + \\SI{10}{\\kohm}} = \\SI{0.5}{\\V}\\]\n    Then, we have the following equivalent circuit:\n    \\begin{circuit}{fig:1.7.3}{Thévenin equivalent circuit of circuit in Figure \\ref{fig:1.7.2}.}\n        (0,0) to[V=$V_{\\Th}$,invert] (0,4)\n        to[R=$R_{\\Th}$,i>^=$I$] (5,4);\n        \\draw node[draw,circle,fill=blue,inner sep=1pt] at(5,4) {};\n        \\draw[blue] (5,4)\n        to node[draw,circle,fill=white] {A} (5,2)\n        to[R=$\\SI{20}{\\kohm}$,-*,color=blue] (5,0);\n        \\draw (5,0) to (0,0)\n    \\end{circuit}\n    Finally, we have that the current in the ideal ammeter and the voltage in the meter resistance are given by\n    \\[I = \\frac{\\SI{0.5}{\\V}}{\\SI{5}{\\kohm} + \\SI{20}{\\kohm}} = \\mans{\\SI{0.02}{\\mA}} \\quad \\text{ and } \\quad V = \\SI{0.02}{\\mA} \\cdot \\SI{20}{\\kohm} = \\mans{\\SI{0.4}{\\V}}\\]\n\\end{enumerate}\n\n\\ex{1.8}\n\\begin{enumerate}\n    \\item In the first part, we have the following circuit:\n    \\begin{circuit}{fig:1.8.1}{\\SI{50}{\\uA} ammeter with \\SI{5}{\\kohm} internal\n        resistance (shown in blue) in parallel with shunt resistor.}\n\n        (0,0) to[isource, l=$I$, -*] (0,2)\n        (0,2) to[short] (0,3);\n        \\draw[blue]\n        (0,2) to[R=\\SI{5}{\\kohm}, i>^=$I_m$, color=blue] (4,2)\n        (4,2) to node[draw, circle, fill=white] {A} (6,2);\n        \\draw\n        (0,3) to[R=$R_s$, i>^=$I_s$] (6,3)\n        (6,3) to[short, -*] (6,2)\n        (6,2) to[short] (6,0)\n        (6,0) to[short] (0,0)\n    \\end{circuit}\n\n    We want to measure $I$ for 0-1 A, and the ideal ammeter measures\n    up to \\SI{50}{\\uA}. To find what shunt resistance $R_s$ allows us to do so,\n    we set $I = \\SI{1}{\\A}$ and $I_m = \\SI{50}{\\uA}$. By KCL we know $I_s = \\SI{0.999950}{\\A}$.\n    To determine $R_s$, we still need to find the voltage across it. We can\n    find this voltage by doing\n    \\[V = I_m R_m = \\SI{50}{\\uA} \\cdot \\SI{5}{\\kohm} = \\SI{0.25}{\\V}\\]\n    Then we simply do\n    \\[R_s = \\frac{V}{I_s} = \\frac{\\SI{0.25}{\\V}}{\\SI{0.999950}{\\A}} = \\mans{\\SI{0.25}{\\ohm}}\\]\n\n    \\item In the second part, we have the following circuit:\n    \\begin{circuit}{fig:1.8.2}{\\SI{50}{\\uA} ammeter with \\SI{5}{\\kohm} internal\n        resistance (shown in blue) with a series resistor.}\n\n        (0,0) to[V=$V$, invert, i^>=$I$] (0,2);\n        \\draw[blue]\n        (0,2) to[R=\\SI{5}{\\kohm}, color=blue] (2,2)\n        (2,2) to node[draw, circle, fill=white] {A} (4,2);\n        \\draw\n        (4,2) to[R=$R_s$] (4,0)\n        (4,0) to[short] (0,0)\n    \\end{circuit}\n    We want to measure $V$ for 0-10 V, and the ideal ammeter measures up to\n    \\SI{50}{\\uA}. To find the series resistance $R_s$, we set $V = \\SI{10}{\\V}$ and\n    $I = \\SI{50}{\\uA}$. Then we solve\n    \\[\\frac{V}{I} = \\SI{5}{\\kohm} + R_s\\]\n    \\[R_s = \\frac{\\SI{10}{\\V}}{\\SI{50}{\\uA}} - \\SI{5}{\\kohm} = \\mans{\\SI{195}{\\kohm}}\\]\n\\end{enumerate}\n\n\\ex{1.9}\nIn order to measure resistance well above the range of your multimeter, you need to get creative.  We will be using the multimeter in voltmeter mode.  Lets start by connecting our DC voltage source, voltmeter, and the high-value resistor in series.  (The reason for doing this will become clear later).\n\n\\begin{circuit}{fig:1.9.1}{Connection of three components.}\n    (0,2) to[V=$V_{\\in}$] (0,0)\n    (0,2) to[qvprobe=voltmeter] (4,2)\n    (4,2) to[R=$R_L$] (4,0)\n    (4,0) to[short] (0,0)\n\\end{circuit}\n\n$V_{\\in}$ is our test voltage, and $R_L$ is our leakage resistance. We need to revise the model for our voltmeter.\n\n\\begin{circuit}{fig:1.9.2}{The voltmeter is now modeled as a resistor with value $R_M$.}\n    (0,2) to[V=$V_{\\in}$] (0,0)\n    (0,2) to[short, i>^=$I_{\\in}$] (1,2)\n    (1,2) to[R=$R_M$, i>_=$I_M$] (3,2)\n    (3,2) to[short] (4,2)\n    (4,2) to[R=$R_L$, i>_=$I_L$] (4,0)\n    (4,0) to[short] (0,0)\n\\end{circuit}\n\nThe current flowing through our meter (modeled by the resistor $R_M$) is equal to the current flowing through the leakage resistor. This is also equal to the current supplied from our voltage source.\n\\[I_M = I_L = I_{\\in}\\]\n\n\\begin{circuit}{fig:1.9.3}{Voltage and current labels are added.}\n    (0,2) to[V=$V_{\\in}$] (0,0)\n    (0,2) to[short, i>^=$I_{\\in}$] (1,2)\n    (1,2) to[R=$R_M$, v_>=$V_M$] (3,2)\n    (3,2) to[short] (4,2)\n    (4,2) to[R=$R_L$, v_>=$V_L$] (4,0)\n    (4,0) to[short] (0,0)\n\\end{circuit}\n\nNotice: this test circuit is a \\textbf{voltage divider}.  When you use this technique, the voltmeter itself makes up half of the divider. The voltage across the leakage resistor cannot be measured directly, so we calculate it using Kirchhoff's Voltage Law by subtracting our voltmeter's reading from the voltage of our DC supply.\n\\[V_L = V_{\\in} - V_M\\]\nThe current through the voltmeter's resistance is given by Ohm's Law.\n\\[I_M = \\frac{V_M}{R_M}\\]\nThe current through the leakage resistor is given by Ohm's Law.\n\\[I_L = \\frac{V_L}{R_L}\\]\nWe already determined that $I_M$ and $I_L$ are equal, so we can set the two previous expressions equal to each other.\n\\[I_M = I_L  \\Rightarrow  \\frac{V_M}{R_M} = \\frac{V_L}{R_L}\\]\nWe will rearrange the above equation to give an expression for $R_L$.\n\\[R_L = R_M \\frac{V_L}{V_M}\\]\nNow we can substitute our first expression for $V_L$ into the previous equation to eliminate $V_M$ (the final unknown term).\n\\[R_L = R_M \\frac{V_{\\in} - V_M}{V_M}\\]\nRewriting the equation, the final result is\n\\[\\mans{R_L = R_M \\left(\\frac{V_{\\in}}{V_M} - 1\\right)}\\]\n\nTo measure leakage current with a voltmeter, simply divide the meter's reading by the resistance of the meter.  For example, if your \\SI{10}{\\Mohm} voltmeter measures \\SI{0.023}{\\V}, then $I_{leakage} = \\SI{23}{\\mV} / \\SI{10}{\\Mohm} = \\SI{2.3}{\\nA}$.  The accuracy of such a measurement depends both on the accuracy of the voltage measurement, and the tolerance of the meter's resistance.\n\n\\ex{1.10}\n\\begin{enumerate}\n    \\item \n    With two equal-value resistors, the output voltage is half the input voltage.\n    \\[V_\\out = \\frac{1}{2}V_\\in = \\frac{\\SI{30}{\\V}}{2} = \\mans{\\SI{15}{\\V}}\\]\n\n    \\item \n    To treat $R_2$ and $R_{\\load}$ as a single resistor, combine the two resistors which are in parallel to find that the combined (equivalent) resistance is \\SI{5}{\\kohm}. Now, we have a simple voltage divider with a \\SI{10}{\\kohm} resistor in series with the \\SI{5}{\\kohm} equivalent resistor. The output voltage is across this equivalent resistance. The output voltage is given by \n    \\[V_\\out = V_{\\in} \\frac{\\SI{5}{\\kohm}}{\\SI{10}{\\kohm} + \\SI{5}{\\kohm}} = \\frac{\\SI{30}{\\V}}{3} = \\mans{\\SI{10}{\\V}} \\]\n    \\begin{circuit}{fig:1.10.1}{Voltage divider with simplified equivalent resistance}\n        % \\label{1.10fig1}\n        (0,2) to[V=$V_{\\in}$] (0,0)\n        to[short] (2,0)\n        to[R=$R_{eq}$] (2,2)\n        to[R=$R_1$](0,2)\n        (2,0) to[short, *-o] (3,0)\n        (2,2) to[short, *-o] (3,2)\n        (3,0) to[open, v_<=$V_\\out$] (3,2)\n    \\end{circuit}\n\n    \\item \n    We can redraw the voltage divider circuit to make the ``port'' clearer. \n    \\begin{circuit}{fig:1.10.2}{Voltage divider with port shown.}\n        % \\label{1.10fig1}\n        (0,2) to[V=$V_\\in$] (0,0)\n        to[short] (2,0)\n        to[R=$R_2$] (2,2)\n        to[R=$R_1$](0,2)\n        (2,0) to[short, *-o] (3,0)\n        (2,2) to[short, *-o] (3,2)\n        (3,0) to[open, v_<=$V_\\out$] (3,2)\n    \\end{circuit}\n\n    We can find $V_\\Th$ by leaving the ports open (open circuit) and measuring $V_\\out$, the voltage across $R_2$. This comes out to be half the input voltage when $R_1 = R_2$, so $V_\\out = \\SI{15}{\\V}$. Thus $V_{\\Th} = \\mans{\\SI{15}{\\V}}$.\n    \n    To find the Th\\'evinen resistance, we need to find the short circuit current, $I_{SC}$. We short circuit the port and measure the current flowing through it.\n    \\begin{circuit}{fig:1.10.3}{Voltage divider with short circuit on the output.}\n        (0,2) to[V=$V_\\in$] (0,0) \n        to[short] (2,0)\n        to[R=$R_2$] (2,2)\n        to[R=$R_1$](0,2)\n        (2,0) to[short] (3,0)\n        (2,2) to[short] (3,2)\n        (3,0) to[short, i_<=$I_{SC}$] (3,2) \n    \\end{circuit}\n    \n    In this circuit, no current flows through $R_2$, flowing through the short instead. Thus we have $I_{SC} = \\dfrac{V_\\in }{R_1}$. From this, we can find $R_\\Th$ from $R_\\Th = \\dfrac{V_\\Th}{I_{SC}}$. This gives us \n    \\[R_\\Th = \\frac{V_\\Th}{I_{SC}} = \\frac{V_\\Th}{V_\\in/R_1} = \\frac{\\SI{15}{\\V}}{\\SI{30}{\\V}/\\SI{10}{\\kohm}} = \\mans{\\SI{5}{\\kohm}}\\]\n\n    The Th\\'evenin equivalent circuit takes the form shown below.\n    \\begin{circuit}{fig:1.10.4}{Th\\'evenin equivalent circuit.}\n        (0,2) to[V=$V_\\Th$] (0,0)\n        to[short, -o] (3,0)\n        (0,2) to[R=$R_\\Th$, -o] (3,2)\n        (3,0) to[open, v_<=$V_\\out$] (3,2)\n    \\end{circuit}\n    In terms of behavior at the ports, this circuit is equivalent to the circuit in Figure \\ref{fig:1.10.1}. \n\n    \\item \n    We connect the $\\SI{10}{\\kohm}$ load to the port of the Th\\'evenin equivalent circuit in Figure \\ref{fig:1.10.4} to get the following circuit.\n    \\begin{circuit}{fig:1.10.5}{Th\\'evenin equivalent circuit with $\\SI{10}{\\kohm}$ load.}\n        (0,2) to[V=$V_{\\Th}$] (0,0)\n        to[short] (3,0)\n        (0,2) to[R=$R_{\\Th}$] (3,2)\n        (3,0) to[R=$\\SI{10}{\\kohm}$, v_<=$V_\\out$] (3,2)\n    \\end{circuit}\n    From here, we can find $V_\\out$, treating this circuit as a voltage divider.\n    \\[V_\\out = \\frac{\\SI{10}{\\kohm}}{R_\\Th + \\SI{10}{\\kohm}} V_\\Th = \\frac{\\SI{10}{\\kohm}}{\\SI{5}{\\kohm} + \\SI{10}{\\kohm}} \\cdot \\SI{15}{\\V} = \\mans{\\SI{10}{\\V}}\\] \n    This is the same answer we got in part (b).\n\n    \\item \n    To find the power dissipated in each resistor, we return to the original three-resistor circuit. \n    \\begin{circuit}{fig:1.10.6}{Original voltage divider with $\\SI{10}{\\kohm}$ load attached.}\n        (0,2) to[V, l_=$V_\\in$] (0,0)\n            to[short] (3,0)\n            to[R, l_=$R_\\load$] (3,2)\n            to[short] (2,2)\n            to[R=$R_1$] (0,2)\n        (2,0) to[R=$R_2$, *-*] (2,2)\n    \\end{circuit}\n\n    From part (d), we know that the output voltage is 10V and that this is the voltage across the load resistor. Since $P = IV = \\frac{V^2}{R}$, we find that the power through $R_\\load$ is \n    \\[P_\\load = \\frac{V^2}{R_\\load} = \\frac{(\\SI{10}{\\V})^2}{\\SI{10}{\\kohm}} = \\mans{\\SI{10}{\\mW}}\\]\n    Similarly, we know that the power across $R_2$ is the same since the voltage across $R_2$ is the same as the voltage across $R_\\load$. Thus we have\n    \\[P_2 = \\mans{\\SI{10}{\\mW}}\\]\n    To find the power dissipated in $R_1$, we first have to find the voltage across it. From Kirchoff's loop rule, we know that the voltage around any closed loop in the circuit must be zero. We can choose the loop going through the voltage source, $R_1$, and $R_2$. The voltage supplied by the source is 30V. The voltage dropped across $R_2$ is 10V as discussed before. Thus the voltage dropped across $R_1$ must be $\\SI{30}{\\V} - \\SI{10}{\\V} - \\SI{20}{\\V}$. Now we know the voltage across and the resistance of $R_1$. We use the same formula as before to find the power dissipated.\n    \\[P_1 = \\frac{V^2}{R_1} = \\frac{(\\SI{20}{\\V})^2}{\\SI{10}{\\kohm}} = \\mans{\\SI{40}{\\mW}}\\]\n\\end{enumerate}\n\n\\ex{1.11}\nConsider the following Th\\'evenin circuit where $R_\\source$ is just another name for the Th\\'evenin resistance, $R_\\Th$.\n\\begin{circuit}{fig:1.11.1}{Standard Th\\'evenin circuit with attached load.}\n    (0,2) to[V, l_=$V_\\Th$] (0,0)\n        to[short] (2,0)\n        to[R, l_=$R_\\load$] (2,2)\n        to[R, l_=$R_\\source$] (0,2)\n\\end{circuit}\nWe will first calculate the power dissipated in the load and then maximize it with calculus. We can find the power through a resistor using current and resistence since $P = IV = I(IR) = I^2R$. To find the total current flowing through the resistors, we find the equivalent resistance which is $R_\\source + R_\\load$. Thus the total current flowing is $I = \\dfrac{V_\\Th}{R_\\source + R_\\load}$. The power dissipated in $R_\\load$ is thus \n\\[P_\\load = I^2R_\\load = \\dfrac{V_\\Th^2 R_\\load}{(R_\\source + R_\\load)^2}\\]\nTo maximize this function, we take the derivative and set it equal to 0.\n\\begin{align*}\n    \\frac{dP_\\load}{dR_\\load} &= V_\\Th \\frac{(R_\\source + R_\\load)^2 - 2R_\\load(R_\\source + R_\\load)}{(R_\\source + R_\\load)^4} = 0 \\\\\n    &\\Longrightarrow R_\\source + R_\\load = 2R_\\load \\\\\n    &\\Longrightarrow R_\\source = R_\\load\n\\end{align*}\n\n\\ex{1.12}\n\\begin{enumerate}\n    \\item \n    Voltage ratio: $\\frac{V_2}{V_1} = 10^{\\si{\\dB}/20} = 10^{3/20} = \\mans{1.413}$\n\n    Power ratio: $\\frac{P_2}{P_1} = 10^{\\si{\\dB}/10} = 10^{3/10} = \\mans{1.995}$\n\n    \\item \n    Voltage ratio: $\\frac{V_2}{V_1} = 10^{\\si{\\dB}/20} = 10^{6/20} = \\mans{1.995}$\n\n    Power ratio: $\\frac{P_2}{P_1} = 10^{\\si{\\dB}/10} = 10^{6/10} = \\mans{3.981}$\n    \n    \\item \n    Voltage ratio: $\\frac{V_2}{V_1} = 10^{\\si{\\dB}/20} = 10^{10/20} = \\mans{3.162}$\n\n    Power ratio: $\\frac{P_2}{P_1} = 10^{\\si{\\dB}/10} = 10^{10/10} = \\mans{10}$\n    \n    \\item \n    Voltage ratio: $\\frac{V_2}{V_1} = 10^{\\si{\\dB}/20} = 10^{20/20} = \\mans{10}$\n\n    Power ratio: $\\frac{P_2}{P_1} = 10^{\\si{\\dB}/10} = 10^{20/10} = \\mans{100}$\n\\end{enumerate}\n\n\\ex{1.13}\nThere are two important facts to notice from Exericse 1.12:\n\\begin{enumerate}[label=\\arabic*.]\n    \\item \n    An increase of \\SI{3}{\\dB} corresponds to doubling the power \n    \n    \\item \n    An increase of \\SI{10}{\\dB} corresponds to 10 times the power.\n\\end{enumerate}\nUsing these two facts, we can fill in the table. Start from \\SI{10}{\\dB}. Fill in \\SI{7}{\\dB}, \\SI{4}{\\dB}, and \\SI{1}{\\dB} using fact 1. Then fill in \\SI{11}{\\dB} using fact 2. Then fill in \\SI{8}{\\dB}, \\SI{5}{\\dB}, and \\SI{2}{\\dB} using fact 1 and approximating 3.125 as $\\pi$.\n\n\\begin{center}\n    \\begin{tabular}{c|c}\n        \\si{\\dB} & ratio($P/P_0$) \\\\ \\hline \n        0 & 1\\\\\n        1 & \\tans{1.25}\\\\\n        2 & $\\mans{\\pi/2}$\\\\\n        3 & 2\\\\\n        4 & \\tans{2.5}\\\\\n        5 & \\tans{3.125 $\\approx \\pi$}\\\\\n        6 & 4\\\\\n        7 & \\tans{5}\\\\\n        8 & \\tans{6.25}\\\\\n        9 & 8\\\\\n        10 & 10\\\\\n        11 & \\tans{12.5}\n    \\end{tabular}\n\\end{center}\n\n\\ex{1.14}\nRecall the relationship between $I$, $V$, and $C$: $I = C\\frac{dV}{dt}$. Now, we perform the integration:\n\\begin{align*}\n    \\int dU &= \\int_{t_0} ^{t_1} VIdt\\\\\n    U &= \\int_{t_0} ^{t_1} CV\\frac{dV}{dt}dt\\\\\n    &= C\\int_0^{V_f} V dV\\\\\n    U &= \\frac{1}{2}CV_f^2\n\\end{align*}\n\n\\ex{1.15}\nConsider the following two capacitors in series.\n\\begin{circuit}{fig:1.15.1}{Two capacitors in series.}\n    (0,0) to[C=$C_1$] (2,0)\n        to[C=$C_2$] (4,0)\n    (-0.5,-0.5) to[open, v_>=$V_\\text{total}$] (4.5,-0.5)\n\\end{circuit}\n\nTo prove the capacitance formula, we need to express the total capacitance of both of these capacitors in terms of the individual capacitances. From the definition of capacitance, we have \n\\[C_\\text{total} = \\frac{Q_\\text{total}}{V_\\text{total}}\\]\nNotice that $V_\\text{total}$ is the sum of the voltages across $C_1$ and $C_2$. We can get each of these voltages using the definition of capacitance.\n\\[V_\\text{total} = V_1 + V_2 = \\frac{Q_1}{C_1} + \\frac{Q_2}{C_2}\\]\nThe key observation now is that because the right plate of $C_1$ is connected to the left plate of $C_2$, the charge stored on both plates must be of equal magnitude.\\footnotemark Therefore, we have $Q_1 = Q_2$. Let us call this charge stored $Q$ (i.e. $Q = Q_1 = Q_2$). Now, we know that the total charge stored is also $Q$.\\footnotemark Therefore, we know that $Q_\\text{total} = Q$. Now, we have \n\\[C_\\text{total} = \\frac{Q_\\text{total}}{V_\\text{total}} = \\frac{Q}{Q_1/C_1 + Q_2/C_2} = \\frac{Q}{Q/C_1 + Q/C_2} = \\frac{1}{1/C_1 + 1/C_2}\\]\n\n\\footnotetext{If this were not true, then there would be a net charge on these two plates and the wire between them. Because we assume that the capacitors started out with no net charge and there is no way for charge to leave the middle wire or the two plates it connects, this is impossible. }\n\n\\footnotetext{If you are having trouble seeing this, suppose we apply a positive voltage to the left plate of $C_1$ relative to the right plate of $C_2$. Suppose this causes the left plate of $C_1$ to charge to some charge $q$. We now must have a charge of $-q$ on the right plate of $C_1$ because $q$ units of charge are now pushed onto the left plate of $C_2$. Now the left of $C_2$ has $q$ units of charge which causes a corresponding $-q$ charge on the right side of $C_2$. Thus the overall total charge separated across these two capacitors is $q$. \n}\n\n\\ex{1.16}\nEquation 1.21 gives us the relationship between the time and the voltage ($V_\\out$) across the capacitor while charging. To find the rise time, subtract the time it takes to reach 10\\% of the final value from the time it takes to reach 90\\% of the final value.\n\\begin{align*}\n    V_\\out &= 0.1V_f = V_f(1-e^{-t_1/RC}) \\\\\n    0.1 &= 1 - e^{-t_1/RC}\\\\ \n    t_1 &= -RC \\ln(0.9)\n\\end{align*}\nSimilarly, we find that $t_2 = -RC \\ln(0.1)$. Subtracting these two gives us \n\\[t_2 - t_1 = -RC(\\ln(0.1) - \\ln(0.9)) = 2.2RC\\]\n\n\\ex{1.17}\nThe voltage divider on the left side of the circuit can be replaced with the Th\\'evenin equivalent circuit found Exercise 1.10 (c). Recall that $V_\\Th = \\frac{1}{2} V_\\in$ and $R_\\Th = \\SI{5}{\\kohm}$. This gives us the following circuit.\n\\begin{circuit}{fig:1.17.1}{Th\\'evenin equivalent circuit to Figure 1.36 from the textbook.}\n    (0,2) to[open, v_>=$V_\\Th$, o-o] (0,0) node[ground]{}\n    (0,2) to[R=$R_\\Th$] (3,2)\n        to[C=$C$, *-] (3,0) node[ground]{}\n    (3,2) to[short, -o] (5,2)\n    to[open, v^>=$V(t)$, o-o] (5,0) node[ground]{}\n\\end{circuit}\n\nNow we have a simple RC circuit which we can apply Equation 1.21 to. The voltage across the capacitor is given by \n\\[V(t) = V_\\text{final}(1 - e^{-t/RC}) = V_\\Th (1 - e^{-t/R_\\Th C} = \\mans{\\frac{1}{2}V_\\in (1 - e^{-t/5 \\times 10^{-4}})}\\]\n\n\\begin{plot}{fig:1.17.2}{V(t) sketch.}\n    [->] (0,0) -- (6,0) node[right] {$t /ms$};\n    \\draw[->] (0,0) -- (0,5) node[left] {$V$};\n    \\draw[smooth, domain = 0:6, color=black, thick] plot (\\x,{1/2*8*(1-e^(-\\x/0.5))});\n    \\fill [blue] ($(0,0)$) circle (1.5pt) node at (1.4,0)[left] {\\color{blue}$(0,0)$};\n    \\node at (4.5,4.5)[right] {\\footnotesize\\color{blue}$\\frac{1}{2}V_\\in (1 - e^{-t/(5 \\times 10^{-4})})$};\n    \\draw[smooth, dashed, domain=0:4.5, color=gray] plot (\\x,4);\n    \\node at (0,4)[left] {\\footnotesize\\color{blue}$\\frac{1}{2}V_\\in$};\n    \\fill [blue] ($(0.5,2.52)$) circle (1.5pt) node at (0.5,2.5)[right] {\\color{blue}$(0.5,\\frac{1}{2}V_\\in \\times 63\\%)$};\n\\end{plot}\n\n\\ex{1.18}\nFrom the capacitor equation in the previous paragraph, we have \n\\[V(t) = (I/C)t = (\\SI{1}{\\mA}/\\SI{1}{\\micro\\farad}) \\times t = \\SI{10}{\\V}\\]\nThis gives us\n\\[\\mans{t = \\SI{0.01}{\\s}}\\]\n\n\\ex{1.19}\nSuppose a current \\(I\\) is flowing through a loop of wire with cross-sectional area \\(A\\).\nThis induces a magnetic field \\(B\\), and the flux \\(\\Phi\\) through the loop is\n\\[\\Phi = BA\\]\nNow suppose the same current \\(I\\) flows through a wire coiled into \\(n\\) loops, each with the same cross-sectional area \\(A\\).\nThis induces a magnetic field of \\(n\\) times the strength, \\(B_n = nB\\). Since each loop has area \\(A\\),\nthe total cross-sectional area of the coil can be considered \\(A_n = nA\\). Then the magnetic flux\nthrough the coil is\n\\[\\Phi_n = B_nA_n = n^2BA = n^2\\Phi\\]\nSince inductance is defined as flux through a coil divided by current through the flux,\nwe can see that \\(\\Phi_n = n^2\\Phi\\) implies \\(L \\propto n^2\\).\n\n\\ex{1.20}\nWe can use the formula for the full-wave rectifier ripple voltage to find the capacitance.\n\\[\\frac{I_\\load}{2fC} = \\Delta V \\le 0.1 \\text{V}_\\pp\\]\nThe maximum load current is 10mA and assuming a standard wall outlet frequency of 60 Hz, we have\n\\[C \\ge \\frac{\\SI{10}{\\mA}}{2\\times \\SI{60}{\\Hz} \\times \\SI{0.1}{\\V}} = \\mans{\\SI{833}{\\micro\\farad}}\\]\nNow we need to find the AC input voltage. The peak voltage after rectification must be \\SI{10}{\\V} (per the requirements). Since each phase of the AC signal must pass through 2 diode drops, we have to add this to find out what our AC peak-to-peak voltage must be. Thus we have\n\\[V_{\\in, \\pp} = \\SI{10}{\\V} + 2(\\SI{0.6}{\\V}) = \\mans{\\SI{11.2}{\\V}}\\]\n\n\\ex{1.21}\nIn order to calculate the minimum fuse rating for a time-varying current signal, one must calculate the RMS current of the signal - \\emph{not} the average current.  This is because most fuses are designed to blow at a certain average power level, and average power is related to the average of the \\textit{square} of current.\n\nSquare waves are defined by two amplitudes.  When one of those amplitudes is zero, the RMS value is given by the following equation:\n\\[ I_{\\text{RMS}} = \\sqrt{\\frac{I^2 + 0}{2}} = \\sqrt{\\frac{I^2}{2}} = \\frac{I}{\\sqrt{2}}\\]\nSo in the case of a 0 to 2.0 A square wave with 50\\% duty cycle, the theoretical minimum current a fuse should be rated for is:\n\\[\\frac{I}{\\sqrt{2}} = \\frac{2}{\\sqrt{2}} = \\mans{\\sqrt{2} A}\\]\nIn this case, sizing a fuse for the \\textit{average} current (1 A) would too small by a factor of $\\sqrt{2}$!\n\n\\ex{1.22}\n\\begin{circuit}{fig:1.22.1}{A symmetric 5.6 V clamping circuit.}\n    % next macro is available in ctikzmanutils.sty\n    (0,2.5) node[vcc](vcc){+5V}\n    (0,-2.5) node[vee](vee){-5V}\n    (0,0) to[D, l_=1N4148] (0,2.5)\n    (0,-2.5) to[D, l_=1N4148] (0,0)\n    (-4,0) node[above]{$V_\\in$} to[R, l=$\\SI{1}{\\kohm}$, o-*] (0,0)\n    (0,0) to[short, -o] (4,0) node[above]{$V_\\out$}\n\\end{circuit}\n\n\\ex{1.23}\nFor both low-pass and high-pass filters of the first-order, the \\textbf{input} impedance is calculated by the series combination of impedances of both circuit elements.  The \\textbf{output} impedance is calculated as the parallel combination of the impedances of the two circuit elements.\n\\begin{circuit}{fig:1.23.1}{Low-Pass Filter Driven by a Voltage Source.}\n    (-1,2) to[V, l_=$V_\\in$] (-1,0)\n    (-1,2) to[R, l=$R$] (2,2)\n    to[C=$C$, *-*] (2,0)\n    to[short] (-1,0)\n    (2,2)  to[short, -o] (4,2)\n    (2,0) to[short, -o] (4,0)\n    (4,0) to[open, v_<=$V_\\out$] (4,2)\n\\end{circuit}\nThe minimum input impedance of a low-pass filter occurs at high frequency when the capacitor looks like a short circuit.  This is true because this minimizes the impedance of the series-combination of impedances.\n\\[\\mans{Z_{\\in,\\min} = R + 0 = R}\\]\nThe maximum output impedance a low-pass filter occurs at low frequency when the capacitor looks like an open circuit.  This is true because this maximizes the impedance of the parallel-combination of impedances.\n\\[\\mans{Z_{\\out,\\max} = R \\parallel \\infty = R}\\]\n\\begin{circuit}{fig:1.23.2}{High-Pass Filter Driven by a Voltage Source.}\n    (-1,2) to[V, l_=$V_\\in$] (-1,0)\n    (-1,2) to[C=$C$] (2,2)\n    to[R, l_=$R$, *-*] (2,0)\n    to[short] (-1,0)\n    (2,2)  to[short, -o] (4,2)\n    (2,0) to[short, -o] (4,0)\n    (4,0) to[open, v_<=$V_\\out$] (4,2)\n\\end{circuit}\nThe reasoning for the high-pass filter is the same as for the low-pass filter.  The circuit elements are swapped in their position, but the analysis is the same because: minimizing the input impedance is still a function of minimizing the series combination impedance; maximizing the output impedance is still a function of maximizing the parallel combination impedance.\n\n\\ex{1.24}\nAs the question indicated, the bandpass filter is made of a highpass filter and lowpass filter as shown below.\n\\begin{circuit}{fig:1.24.1}{Bandpass filter}\n    (0,-2.5) node[ground](gnd){}\n    (0,-2.5) to[R, l_=$R1$] (0,0)\n    (-4,0) node[above]{$V_\\in$} to[C, l=$C1$, o-*] (0,0)\n    (0,0) to [R, l=$R2$, *-*] (4,0)\n    (4,-2.5) node[ground](gnd){}\n    (4,0) to [C, l=$C2$] (4,-2.5)\n    (4,0) to[short, -o] (6.5,0) node[above]{$V_\\out$}\n\\end{circuit}\nFor highpass and lowpass filters, we have \\[ f_\\text{3dB} = \\frac{1}{2\\pi*RC}\\] \nGiven breakpoints, we can determine the resistors and capacitors values to meet the design requirements.\n\\begin{enumerate}\n    \\item\n    Given $f_1 = \\SI{100}{\\Hz}$ from the question:\n    \\[R_1*C_1 = \\frac{1}{2\\pi*\\SI{100}{\\Hz}} = \\SI{1.6}{\\ms} \\]\n    Because the signal source output impedance is \\SI{100}{\\ohm},\n    we select a value 10 times higher: $R_1 = \\SI{1}{\\kohm}$ then:\n    \\[C_1 = \\frac{\\SI{1.6}{\\ms}}{\\SI{1}{\\kohm}} = \\mans{\\SI{1.6}{\\micro\\farad}}\\]\n    \\item\n    Given $f_2 = \\SI{10}{\\kHz}$ from the question:\n    \\[R_2*C_2 = \\frac{1}{2\\pi*\\SI{10}{\\kHz}} = \\SI{16}{\\us} \\]\n    Because the output impedance of the high-pass filter was approximately \\SI{1}{\\kohm},\n    we select a value 10 times greater: $R_2 = \\SI{10}{\\kohm}$  then:\n    \\[C_2 = \\frac{\\SI{16}{\\us}}{\\SI{10}{\\kohm}} = \\mans{\\SI{1.6}{\\nano\\farad}}\\]\n\\end{enumerate}\n\n\\ex{1.25}\n\\begin{enumerate}\n    \\item\n    The impedance of 2 parallel capacitors is equal to the impedance of a single capacitor $C$ of value $C_1 + C_2$:\n    \\[ \\mathbf{Z_\\text{parallel}} = \\frac{1}{ \\frac{1}{\\mathbf{Z_1}} + \\frac{1}{\\mathbf{Z_2}} } = \\frac{1}{ j\\omega C_1 + j\\omega C_2 } = \\mans{\\frac{1}{j\\omega (C_1 + C_2)}} \\]\n    \n    \\item\n    The impedance of 2 series capacitors is equal to the impedance of a single capacitor $C$ of value $\\frac{C_1 C_2}{C_1 + C_2}$:\n    \\begin{align*}\n        \\mathbf{Z_{\\text{series}}} &= \\mathbf{Z_1} + \\mathbf{Z_2} \\\\\n        &=  \\frac{1}{j\\omega C_1} + \\frac{1}{j\\omega C_2} \\\\\n        &= \\frac{1}{j\\omega} \\left( \\frac{1}{C_1} + \\frac{1}{C_2} \\right) \\\\\n        &= \\frac{1}{j\\omega} \\left( \\frac{C_2}{C_1 C_2} + \\frac{C_1}{C_2 C_1} \\right) \\\\\n        &= \\frac{1}{j\\omega} \\left( \\frac{C_1 + C_2}{C_1 C_2} \\right) \\\\\n        &= \\frac{1}{j\\omega} \\frac{1}{\\left( \\frac{C_1 C_2}{C_1 + C_2} \\right)} \\\\\n        &= \\mans{ \\frac{1}{j\\omega\\left( \\frac{C_1 C_2}{C_1 + C_2} \\right)}}\n    \\end{align*}\n\\end{enumerate}\n\n\\ex{1.26}\n\\[ A e^{j\\theta} = B e^{j\\phi}C e^{j\\alpha} = BC e^{j\\left(\\phi + \\alpha\\right)}\\]\nTherefore, because $A$, $B$, and $C$ are all real numbers, $\\theta$ must be equal to $(\\phi + \\alpha)$, so the exponentials on either side of the equation cancel.\n\\[A e^{j\\theta} =  BC e^{j\\left(\\phi + \\alpha\\right)}\\]\n\\[A e^{j\\theta} = BC e^{j\\theta}\\]\n\\[\\mans{\\textnormal{\\textit{A}} = \\textnormal{\\textit{BC}}}\\]\n\n\\ex{1.27}\nWe can solve this problem from two aproaches: analitically, or by inspecting the\npower waveform over a full cycle. First analytically:\\bigskip\n\\begin{align*}\n    V(t)&=V_0\\mathrm{cos}\\left(2\\pi f t\\right)&& \\text{Define the voltage}\\\\\n    I(t)&=I_0\\mathrm{cos}\\left(2\\pi f t + \\tfrac{\\pi}{2}\\right)&&\\text{and current waveforms}\\\\\n    \\\\\n    P(t)&=V(t)\\cdot I(t)\\\\\n    &=V_0I_0\\mathrm{cos}\\left(2\\pi f t\\right)\\mathrm{cos}\\left(2\\pi f t + \\tfrac{\\pi}{2}\\right)&&\\text{Using cosine multiplication rule}\\\\\n        &=V_0I_0\\frac{\\mathrm{cos}\\left(4\\pi f t + \\tfrac{\\pi}{2}\\right)+\\cancelto{0}{\\mathrm{cos}\\left(\\tfrac{\\pi}{2}\\right)}}{2}&&\\text{we express the power waveform}\\\\\n  & &&\\text{as a sum of two cosines}\\\\\n    \\\\\n    P_{\\mathrm{av}}&=\\frac{1}{T}\\int_0^TV_0I_0\\frac{\\mathrm{cos}\\left(4\\pi f t + \\tfrac{\\pi}{2}\\right)}{2}\\mathrm{d}t&&\\text{From this point we take the integral}\\\\\n    &=\\frac{V_0I_0}{2T}\\left[\\frac{\\mathrm{sin}\\left(4\\pi f t+ \\tfrac{\\pi}{2}\\right)}{4\\pi f}\\right]_{t=0}^{t=T}&& \\text{and evaluate over one cycle}\\\\\n    &=\\frac{V_0I_0}{8\\pi}\\underbrace{\\left(\\mathrm{sin}\\left(4\\pi+\\tfrac{\\pi}{2}\\right)-\\mathrm{sin}\\left(\\tfrac{\\pi}{2}\\right)\\right)}_{1-1=0}=\\mans{0}\n\\end{align*}\n\nAs an alternative method we can avoid the integration part by simply observing\nthe power waveform over one full cycle considering $f=1, I_0=V_0=2$\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[samples=100,domain=0:2,legend pos=outer north east]\n            \\addplot[mark=none, blue] {-2*sin(deg(2*pi*x))}; \n            \\addplot[mark=none, red] {2*cos(deg(2*pi*x))};\n            \\addplot[mark=none, fill=red,   domain=0:0.25, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=green, domain=0.25:0.5, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=red,   domain=0.5:0.75, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=green, domain=0.75:1, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=red,   domain=1:1.25, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=green, domain=1.25:1.5, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=red,   domain=1.5:1.75, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\addplot[mark=none, fill=green, domain=1.75:2, fill opacity=0.2 ] {(-4*sin(deg(4*pi*x)))};\n            \\legend{$I(t)$,$V(t)$,$P(t)$}\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\nFrom the plot it is clear that the red and green areas are equal and opposite\nand thus when integrating over a integer number of cycles the average power will\nbe zero.\n\n\\ex{1.28}\n\n\\begin{circuit}{fig:1.28}{Pow}\n    (0,0) node[ground] {} to[V, invert, v=$V_0\\cos(\\omega t)$] (0,2)\n    to[short, i=$i(t)$] ++ (1,0)\n    to[C=C] ++(1,0)\n    to[short] ++ (1,0)\n    to[R=R] ++(0,-2) node[ground] {};\n\\end{circuit}\n\n\\begin{align*}\n  V\\subb{R}^2=&V_0\\frac{Z\\subb{R}}{Z\\subb{C}+Z\\subb{R}}\\\\\n  \\\\\n  \\frac{Z\\subb{R}}{Z\\subb{C}+Z\\subb{R}}=&\\frac{R}{\\frac{1}{\\j\\omega C}+R}=\\frac{1}{1+\\j\\omega R C} \\\\\n  \\\\\n  V\\subb{R}^2 =& \\left( \\frac{1}{1+\\j\\omega R C} \\right)^2 = \\frac{1}{1+2\\j\\omega R C -\\left( \\omega R C \\right)^2}\n\\end{align*}\nFirst let us calculate the total real power in delivered by the voltage source\ndefined by $P=\\Re\\left\\{ \\frac{V_0^2}{Z} \\right\\}$, where $Z$ is the total\nimpedance connected to the voltage source. We can start by calculating\nthe $V_0^2/Z$ term and then taking its imaginary part.\n\n\\begin{equation*}\n  \\frac{1}{Z}=\\frac{1}{R+\\tfrac{1}{\\j\\omega C}}=\\frac{\\j\\omega C}{1+\\j\\omega RC}\n\\end{equation*}\n\nTo take the imaginary part we multiply the fraction by the conjugate of the\ndenomiantor to remove the imaginary units from the denominator.\n\n\\begin{equation*}\n  \\frac{\\j\\omega C}{1+\\j\\omega RC}\\frac{1-\\j\\omega RC}{1-\\j\\omega RC}=\\frac{\\j\\omega C(1-\\j\\omega RC)}{1+\\omega^2R^2C^2}=\n  \\frac{\\j\\omega c+\\omega^2RC^2}{1+\\omega^2R^2C^2}=\\frac{1}{Z}\n\\end{equation*}\nFinally we can compute:\n\\begin{equation*}\n    \\label{}\n    P=\\Re\\left\\{ \\frac{V_0^2}{Z} \\right\\} = V_0^2\\frac{\\omega^2RC^2}{1+\\omega^2R^2C^2}\n\\end{equation*}\nTo compute the value of $\\frac{V\\subb{R}^2}{R}$ we will first compute\n$V\\subb{R}^2$\n\n\\begin{equation*}\n    \\label{}\n    V\\subb{R}=V_o\\frac{R}{R+\\tfrac{1}{\\j\\omega C}}= V_0\\frac{\\j\\omega R C}{1+\\j \\omega R C}\n\\end{equation*}\n\n\\begin{multline*}\n  V\\subb{R}^2=V_0^2\\frac{-\\omega^2R^2C^2}{1+2\\j\\omega\n      RC-\\omega^2R^2C^2}=-V_0^2\\omega^2R^2C^2\\frac{1+\\omega^2R^2C^2-2\\j\\omega\n      RC}{1-2\\omega^2R^2C^2+\\omega^4R^4C^4+4\\omega^2R^2C^2}=\\\\\n  =-V_0^2\\omega^2R^2C^2\\frac{1+\\omega^2R^2C^2-2\\j\\omega\n      RC}{\\underbrace{ 1+2\\omega^2R^2C^2+\\omega^4R^4C^4\n      }_{\\left(1+\\omega^2R^2C^2\\right)^2}}=V_0^2\\frac{\\omega^2R^2C^2\\cancel{ \\left(1+\\omega^2R^2C^2\\right) }}{\\left(1+\\omega^2R^2C^2\\right)^{\\cancel{ 2 }}}=\\frac{\\omega^2R^2C^2}{1+\\omega^2R^2C^2}=V\\subb{R}^2\n\\end{multline*}\n\n\\begin{equation*}\n    \\frac{V\\subb{R}^2}{R}=V_0^2\\frac{\\omega^2RC^2}{1+\\omega^2R^2C^2}\n\\end{equation*}\n\nWe can see that the result obtained in both $P$ and $V\\subb{R}^2/R$ is the same\nand thus we can conclude that all the (real) power delivered by the voltage source is\nconsumed at the resistor.\n\n\n\n\n\n\n\\todoex{1.29}\n\n\\ex{1.30}\n$V_\\out$ is simply the voltage at the output of an impedance voltage divider. We know that $Z_R = R$ and $Z_C = \\frac{1}{j\\omega C}$. Thus we have \n\\[V_\\out = \\frac{Z_C}{Z_R + Z_C} V_\\in = \\frac{\\frac{1}{j \\omega C}}{R + \\frac{1}{j \\omega C}} V_\\in = \\frac{1}{1 + j \\omega R C} V_\\in\\]\nThe magnitude of this expression can be found by multiplying by the complex conjugate and taking the square root.\n\\[\\sqrt{V_\\out V_\\out^*} = \\frac{1}{\\sqrt{1 + \\omega^2R^2C^2}}V_\\in\\]\n\n\\todoex{1.31}\n\n\\todoex{1.32}\n\n\\todoex{1.33}\n\n\\todoex{1.34}\n\n\\todoex{1.35}\n\n\\todoex{1.36}\n\n\\todoex{1.37}\n\n\\todoex{1.38}\n\n\\todoex{1.39}\n\n\\todoex{1.40}\n\n\\todoex{1.41}\n\n\\todoex{1.42}\n\n\\todoex{1.43}\n\n\\ex{1.44}\nThe equivalent capacitance of the oscilloscope and cable is\n\\[ C_o = \\SI{100}{\\pico\\farad} + \\SI{20}{\\pico\\farad} =  \\SI{120}{\\pico\\farad}\\]\nThe equivalent input impedance of the oscilloscope and the total capacitance is:\n$Z_o = \\left( R_o \\parallel \\frac{1}{j\\omega C_o} \\right)$\nwhere $R_o$ is the input resistance of the scope (\\SI{1}{\\mega\\ohm}).\nIn order to reduce the voltage by a factor of 10, let us create a voltage divider between the probe tip and the equivalent scope-and-cable input impedance.\n\\begin{circuit}{fig:1.44.1}{Basic Voltage Divider}\n    (-1,0) to[open, v_<=$V_\\in$] (-1,2)\n    (-1,2) to[generic=$Z_{\\text{probe}}$] (2,2)\n    to[generic, l_=$Z_o$, *-*] (2,0)\n    to[short] (-1,0)\n    (2,2)  to[short, -o] (4,2)\n    (2,0) to[short, -o] (4,0)\n    (4,0) to[open, v_<=$V_\\out$] (4,2)\n\\end{circuit}\nIn order to reduce the voltage by a factor of ten, our circuit must satisfy\n\\[V_{\\out} = \\frac{V_{\\in}}{10}\\]\nWe know that the output of a voltage divider is given by\n\\[V_{\\out} = V_{\\in}\\frac{Z_{\\out}}{Z_{\\out} + Z_{\\in}}\\]\nWhen we equate the previous two expressions, it yields\n\\[\\frac{V_{\\in}}{10} = V_{\\in}\\frac{Z_o}{Z_o + Z_{\\text{probe}}}\\]\nWe may cancel $V_{\\in}$ from both sides of the equation and rearrange terms\n\\[Z_o + Z_{\\text{probe}} = 10 Z_o\\]\nSubtract $Z_o$ from both sides to solve for the probe impedance:\n\\begin{align*}\n    Z_{\\text{probe}} &= 9 Z_o \\\\\n    &= 9 \\left( R_o \\parallel \\frac{1}{ j\\omega C_o } \\right) \\\\\n    &= 9 R_o \\parallel \\frac{9}{ j\\omega C_o } \\\\\n    &= 9 R_o \\parallel \\frac{1}{ j\\omega \\left( \\frac{1}{9} C_o \\right) }\n\\end{align*}\n\nSo our ``x10 probe'' should be the parallel combination of a resistor and a capacitor.  The resistor should be 9 times greater than the input resistance of the scope ($R_o$).  The probe's capacitor should be 9 times \\textit{smaller} than $C_o$ (the total capacitance of the cable and the oscilloscope).\n\\[R_{\\text{probe}} = 9 R_o\\]\n\\[C_{\\text{probe}} = \\frac{1}{9} C_o\\]\n\\begin{circuit}{fig:1.44.2}{x10 Probe}\n    (-1,0) to[open, v_<=$V_\\in$, o-] (-1,2)\n    (0,3) to[C, l=$C_{\\text{probe}}$] (2,3)\n    (0,2) to[R, l_=$R_{\\text{probe}}$, *-*] (2,2)\n    (0,3) to[short] (0,2)\n    (2,3) to[short] (2,2)\n    (0,2)  to[short, -o] (-1,2)\n    (3,2) to[R, l_=$R_o$, *-*] (3,0)\n    (4,0)to[C, l_=$C_o$, *-*] (4,2)\n    (2,0) to[short] (-1,0)\n    (2,2)  to[short, -o] (6,2)\n    (2,0) to[short, -o] (6,0)\n    (6,0) to[open, v_<=$V_\\out$] (6,2)\n\\end{circuit}\nMany x10 probes implement $C_{\\text{probe}}$ as a variable capacitor that the user may tune to very near one ninth the cable-plus-oscilloscope capacitance.  This is sometimes referred to as ``probe compensation''.\n\nThe input impedance of this x10 probe is\n\\begin{align*}\n    Z_{\\in} &= Z_{\\text{probe}} + Z_o \\\\\n    &= 9 R_o \\parallel \\frac{1}{ j\\omega \\left( \\frac{1}{9} C_o \\right) } + \\left( R_o \\parallel \\frac{1}{ j\\omega C_o } \\right) \\\\\n    &= 9 \\left( R_o \\parallel \\frac{1}{ j\\omega C_o } \\right) + \\left( R_o \\parallel \\frac{1}{ j\\omega C_o } \\right) \\\\ \n    &= 10 \\left( R_o \\parallel \\frac{1}{ j\\omega C_o } \\right) \\\\\n    Z_{\\in} &= \\mans{ 10 Z_o }\n\\end{align*}\nFinally, lets take a look at how the probe and the oscilloscope (working as a voltage divider) affect the output voltage as a function of the input voltage.\n\\begin{align*}\n    \\frac{V_{\\out}}{V_{\\in}} &= \\frac{Z_o}{Z_{\\in}} \\\\\n    &= \\frac{ R_o \\parallel \\frac{1}{ j\\omega C_o } }{ 10 \\left( R_o \\parallel \\frac{1}{ j\\omega C_o } \\right) } \\\\\n    \\frac{V_{\\out}}{V_{\\in}} &= \\frac{1}{10}\n\\end{align*}\nIt is remarkable! The voltage transfer function of this circuit is \\textit{precisely} $\\frac{1}{10}$.  This circuit contains four passive components (two of them reactive) but \\textbf{the transfer function does not depend on frequency}. Truly, the ancients were wise and knew many great things.\n\n% Here ends Chapter 1.\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "480f113779ec3a062cd81906478b374ef54d66b7", "size": 43517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter1.tex", "max_stars_repo_name": "jagjordi/TAoE3Solutions", "max_stars_repo_head_hexsha": "9739d385144179b666ad18a19773091f12732935", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter1.tex", "max_issues_repo_name": "jagjordi/TAoE3Solutions", "max_issues_repo_head_hexsha": "9739d385144179b666ad18a19773091f12732935", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter1.tex", "max_forks_repo_name": "jagjordi/TAoE3Solutions", "max_forks_repo_head_hexsha": "9739d385144179b666ad18a19773091f12732935", "max_forks_repo_licenses": ["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.7195902689, "max_line_length": 583, "alphanum_fraction": 0.6164487442, "num_tokens": 16976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6818044342979723}}
{"text": "\\section{Turing Machines}\n\n\\subsection{Definition}\n\n\\begin{itemize}\n\t\n\t\\item A Turing machine is a tuple $ T = (Q, F, A, I, \\tau, q_0) $\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ Q $ is a finite set of states\n\t\t\n\t\t\\item $ F \\subseteq Q $ is the set of final states\n\t\t\n\t\t\\item $ A $ is a finite set, the tape alphabet, with a distinguished blank symbol $ B \\in A $\n\t\t\n\t\t\\item $ I $ is a subset of $ A \\setminus \\set{B} $, the input alphabet\n\t\t\n\t\t\\item $ \\tau \\subseteq Q \\times A \\times Q \\times A \\times \\set{L, R} $ is the set of transitions\n\t\t\n\t\t\\item $ q_0 \\in Q $ is the initial state\n\t\t\t\t\n\t\\end{itemize}\n\t\n\t\\item As in an FSA, non-determinism is allowed\n\t\n\t\\item The tape is infinite in both directions, but only ever contains a finite number of non-blank symbols\n\t\n\t\\item A \\textit{tape description} for $ T $ is a triple $ (a, \\alpha, \\beta) $ with $ a \\in A $, and $ \\alpha: \\Nat \\to A $ and $ \\beta: \\Nat \\to A $ being functions with $ a(n) = B $ and $ B(n) = B $ for all but finitely many $ n \\in \\Nat $\n\t\n\t\\begin{itemize}\n\t\t\\item So the tape looks like: $ \\dots BBB \\beta(l) \\beta(l - 1) \\dots \\beta(0) \\underline{a} \\alpha(0) \\alpha(1) \\dots \\alpha(r) BBB \\dots $, with $ l, r \\in \\Nat $\n\t\\end{itemize}\n\t\n\t\\item A \\textit{configuration} of $ T $ is a tuple $ (q, a, \\alpha, \\beta) $ where $ q \\in Q $ and $ (a, \\alpha, \\beta) $ is a tape description\n\t\n\t\\item If $ c = (q, a, \\alpha, \\beta) $ is a configuration, a configuration $ c' $ is obtained (reachable) from $ c $ by a single move if one of the following holds:\n\t\n\t\\begin{itemize}\n\t\t\\item $ (q, a, q', a', L) \\in \\tau $ and $ c' = (q', \\beta(0), \\alpha', \\beta') $ where:\n\t\t$ \\alpha'(0) = a', \\alpha'(n) = \\alpha(n - 1), n > 0 $ and $ \\beta'(n) = \\beta(n + 1), n \\ge 0 $, or\n\t\t\n\t\t\\item $ (q, a, q', a', R) \\in \\tau $ and $ c' = (q', \\alpha(0), \\alpha', \\beta') $ where:\n\t\t$ \\alpha'(n) = \\alpha(n + 1), n \\ge 0 $ and $\\beta'(0) = a', \\beta'(n) = \\beta(n - 1), n > 0 $\n\t\\end{itemize}\n\n\t\\item A \\textit{computation} of $ T $ is a finite sequence of configurations $ c_1, \\dots, c_n = c' $ where $ n \\ge 1 $ and $ c_{i+1} $ is obtained from $ c_i $ by a single move, for $ 1 \\le i \\le n - 1 $\n\t\n\t\\item A configuration is \\textit{terminal} if no configuration is reachable from it\n\t\n\t\\item A computation halts if $ c' $ is terminal (i.e. there is no configuration reachable from $ c' $)\n\t\n\t\\item We may write $ c \\turingcomputes{T} c' $ if there is a computation starting at $ c $ and ending at $ c' $\n\t\n\\end{itemize}\n\n\\subsection{Turing Machine as Language Recogniser}\n\n\\begin{itemize}\n\t\n\t\\item For $ w = a_1 \\dots a_n \\in A^* $, let $ c_w = (q_0, \\underline{a_1} \\dots a_n) $ (recall $ \\underline{a_1} \\dots a_n $ is a tape description $ (a, \\alpha, \\beta) $)\n\t\n\t\\item If $ w = \\varepsilon $, we put $ c_w = (q_0, \\underline{B}) $\n\t\n\t\\item The TM $ T $ \\textit{accepts} $ w $ if $ c_w \\turingcomputes{T} c' $ for some $ c' = (q, 'a', \\alpha', \\beta') $ with $ q' \\in F $\n\t\n\t\\item The language recognised by $ T $ is $ \\Lang(T) = \\setcomp{w \\in I^*}{w \\text{ is accepted by } T } $\n\t\n\t\\item Note that $ \\Lang(T) $ is a language over $ I $ rather than over $ A $\n\t\n\t\\item $ T $ is deterministic if for every $ (q, a) \\in Q \\times A $ there is \\textit{at most one} element of $ \\tau $ starting with $ (q, a) $\n\t\n\t\\item Then, there is at most one config $ c' $ obtained from $ c $ by a single move; set $ \\delta(c) = c' $\n\t\n\t\\item $ \\delta: C \\to C $ is then a partial function\n\t\n\\end{itemize}\n\n\\clearpage\n\n\\subsection{Numerical Turing Machines: TMs as Function Calculators}\n\n\\begin{itemize}\n\t\n\t\\item We want to use TMs to describe a partial function $ f: \\Nat^n \\to \\Nat $\n\t\n\t\\item A \\textit{numerical TM} is a deterministic TM $ T = (Q, F, A, I, \\tau, q_0) $ with:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ F = I = \\emptyset $\n\t\t\n\t\t\\item $ A = \\set{0, 1} $, with $ 0 $ as the blank symbol\n\t\t\n\t\\end{itemize}\n\n\t\\item In a numerical TM, the final states $ F $ and input alphabets $ I $ are not relevant\n\t\n\t\\item For $ \\vec{x} = (x_1, \\dots, x_n) \\in \\Nat^n $, define the tape description $ Tape(\\vec{x}) = \\underline{0} 1^{x_1} 0 1^{x_2} 0 \\dots 0 1^{x_n} $\n\t\n\t\\item Define the partial function $ \\varphi_{T, n}: \\Nat^n \\to \\Nat $ as follows:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Let $ \\vec{x} \\in \\Nat^n $ be given\n\t\t\n\t\t\\item The initial config of $ T $ is $ (q_0, Tape(\\vec{x})) $\n\t\t\n\t\t\\item If $ T $ halts with tape $ \\underline{0} 1^{y} = Tape(y) $ for some $ y \\in \\Nat $, then $ \\varphi_{T, n}(\\vec{x}) = y $\n\t\t\n\t\t\\item Otherwise, $ \\varphi_{T, n} $ is undefined\n\t\t\n\t\\end{itemize}\n\n\t\\item If $ f: \\Nat^n \\to \\Nat = \\varphi_{T, n} $ for some numerical TM $ T $, then $ f $ is \\textit{TM computable}  \n\t\n\t\\item Note that when considering TMs as language recognisers, halting is regarded as an error -- but for a numerical TM, it is fine \\textit{so long as} it ends with a configuration of the form $ (q, \\underline{0}1^y) $ with $ y \\in \\Nat $\n\t\n\t\\item Example: an addition function $ S: \\Nat^2 \\to \\Nat $\n\t\n\t\\begin{tikzpicture}\n\t\\node[circle,thick,draw] (q0) at (0, 0) {$ - $};\n\t\\node[circle,thick,draw] (q1) at (2, 0) {$ q_1 $};\n\t\\node[circle,thick,draw] (q2) at (4, 0) {$ q_2 $};\n\t\\node[circle,thick,draw] (q3) at (6, 0) {$ q_3 $};\n\t\n\t\\draw[edge] (q0) to node[above] {0/R/0} (q1);\n\t\\draw[edge] (q1) to node[above] {1/R/0} (q2);\n\t\\draw[edge] (q2) to node[above] {0/L/1} (q3);\n\t\n\t\\draw[edge] (q2) to[loop above] node[above] {1/R/1} (q2);\n\t\\draw[edge] (q3) to[loop above] node[above] {1/L/1} (q3);\n\t\\end{tikzpicture}\n\t\n\t\\item Ultimate theorem: All TM computable functions are partial recursive, and conversely all partial recursive functions are TM computable\n\t\n\\end{itemize}\n", "meta": {"hexsha": "09e6443d6b1840d6f51f3a3d86f24bcc675eebce", "size": 5613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH3306/computability/c_tm.tex", "max_stars_repo_name": "mcoot/CourseNotes", "max_stars_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATH3306/computability/c_tm.tex", "max_issues_repo_name": "mcoot/CourseNotes", "max_issues_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATH3306/computability/c_tm.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": 40.6739130435, "max_line_length": 242, "alphanum_fraction": 0.6062711562, "num_tokens": 2092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.6818044300940186}}
{"text": "\\section{Sets, Functions, and Integers}\n\\subsection{Sets}\n\n\\subsubsection{Exercise 5}\nWhen constructing a subset, each element in the set can either be in or out (2 choices).\nHence, $2^n$.\n\n\\subsubsection{Exercise 6}\nThere are $n$ choices for the first element, $n-1$ choices for the second element,\nand so on up to $n-m$, hence dividing $n!$ by $(n-m)!$. The order of these $m$ selected\nelements doesn't matter, hence the division by $m!$.\n\n\\subsection{Functions}\n\n\\subsubsection{Exercise 2}\n$h_g \\circ h_f$, where $h$ corresponds to left-inverse.\n\n\\subsubsection{Exercise 3}\nLet $f:A \\to B$ and $g:B \\to C$ be surjections. Then  $g \\circ f$ is surjective\nsince $\\exists x \\in B$ such that $g(x) = y \\quad \\forall y \\in C$, and \n$\\exists x' \\in A$ such that $f(x') = x \\quad \\forall x \\in B$\n(from the surjectivity of $f$ and $g$). Proving injectivity follows similarly.\n\n\\subsubsection{Exercise 4}\nThe reverse direction follows from Exercise 3. If $f \\circ g$ is injective and $g$ is not,\nwe could choose two elements from the domain of $g$ that map to the same element in \nthe domain of $f$ (contradiction). Surjectivity is a similar argument.\n\n\\subsubsection{Exercise 5}\n$f$ has no right inverse since it is not surjective.\nThere are infinitely many left inverses of $f$, two possibilities are \nmapping to square roots when possible and to 1 or 2 otherwise.\n\n\\subsubsection{Exercise 6}\nApply the left inverse of $f$.\n\n\\subsubsection{Exercise 7}\nWhen surjective, use right inverse.\n\n\\subsubsection{Exercise 8}\nDefine $h$ such that $h(y) = x$ if $\\exists x \\in S \\: | \\: f(x) = y$, and $h(y) = x'$ otherwise\n(axiom of choice necessary for choosing $x$). If $f$ is injective, there will only be\none choice of $x$, and if $f$ is surjective, there will be some $x$ for every $y$.\n\n\\subsubsection{Exercise 9}\nUnique right inverse indicates that every element in the range has\nonly one choice to map back to in the domain, implying injectivity.\n\n\\subsubsection{Exercise 10}\nIf $g$ is a bijection, then we can define $f$ such that $f(y) = x$ \nwhere $g(x) = y$. $f$ is then a two-sided inverse.\nIf  $f$ is a two-sided inverse of $g$, then every element of $T$ maps to a\nunique element of $S$ (from left inverse) and vice versa. Hence $g$ is\na bijection.\n\n\\subsubsection{Exercise 11}\nFollowing the hint, we can see that $f: U \\to \\mathcal{F}$ is surjective since\n$S \\in \\mathcal{F} \\implies S \\neq \\emptyset \\implies \\exists u \\in S \\implies u \\in U \\implies f(u) = S$.\nThe existence of the right inverse then gives us the axiom of choice.\n\n\\subsection{Relations and Binary Operations}\n\n\\subsubsection{Exercise 2}\nSymmetry + transitivity imply circularity. \nFor the other direction, we have \n$xRy, \\: yRy \\implies yRx$, which gives both symmetry and transitivity.\n\n\\subsubsection{Exercise 3}\nThis only implies reflexivity for the elements $x, y \\in X \\: | \\: (x, y) \\in R$, not $\\forall x \\in X$.\n\n\\subsubsection{Exercise 4}\nIf $R$ is transitive $T = R$. Otherwise, start with $T = R$ and add $(x, z)$ to $T$\nwhenever  $(x, y), (y, z) \\in R$. Repeat this process until there are no more pairs to add.\n\n\\subsubsection{Exercise 5}\nLet $R \\subset X \\times Y, \\: S \\subset Y \\times Z, \\: T \\subset Z \\times A$.\n\\begin{align*}\n        x R \\circ (S \\circ T) a &\\implies \\exists y \\in Y \\: | \\: xRy, y (S \\circ T) a \\\\\n        &\\implies \\exists z \\in Z \\: | \\: ySz, zTa \\\\\n        &\\implies x (R \\circ S) z \\\\\n        &\\implies x (R \\circ S) \\circ T a\n\\end{align*}\n\n\\subsubsection{Exercise 6}\nLet $R \\subset X \\times Y, \\: S \\subset Y \\times Z$.\n\\begin{align*}\n        z (R \\circ S)^{\\smile} x &\\implies x (R \\circ S) z \\\\\n                                 &\\implies \\exists y \\in Y \\: | \\: xRy, ySz \\\\\n                                 &\\implies yR^{\\smile} x, \\:  zS^{\\smile} y \\\\\n                                 &\\implies z (S^{\\smile} \\circ R^{\\smile}) x\n\\end{align*}\n\n\\subsubsection{Exercise 7}\n\\begin{align*}\n        (x, z) \\in G(g \\circ f) &\\implies \\exists y \\in Y \\: | \\: g(y) = z, \\: f(x) = y \\\\\n                                &\\implies (x, y) \\in G(f), \\: (y, z) \\in G(g) \\\\\n                                &\\implies (x, z) \\in G(f) \\circ G(g)\n\\end{align*}\n\n\\subsubsection{Exercise 9} \n\\begin{align*}\n        (x, y) \\in G(f) &\\implies \\forall x \\in X, \\: \\exists y \\in Y \\: | \\: f(x) = y \\\\\n                        &\\implies \\forall x \\in X, \\: (x, x) \\in G(f) \\circ G^{\\smile} (f) \\\\\n                        &\\text{and} \\quad \\forall y \\in \\text{Im} f, \\: (y, y) \\in G^{\\smile} (f) \\circ G(f)\n\\end{align*}\n\n\\subsubsection{Exercise 10}\n\\begin{align*}\n        &x \\square y = u \\square (x \\square y) = (u \\square y) \\square x = y \\square x \\\\\n        &x \\square (y \\square z) = x \\square (z \\square y) = (x \\square y) \\square z\n\\end{align*}\n\n\\subsection{The Natural Numbers}\n\n\\subsubsection{Exercise 1}\n$f^0 = 1_X$ is trivially an injection. Suppose $f^n$ is an injection for some $n \\in \\mathbb{N}$.\nThen $f^{\\sigma(n)} = f \\circ f^n$ is a composition of injections and we are done.\n\n\\subsubsection{Exercise 2}\nSame thing as Exercise 1.\n\n\\subsubsection{Exercise 3}\nWe have that $\\sigma^0(0) = 0$. Now assuming  $\\sigma^n(0) = n$ for some $n \\in \\mathbb{N}$,\nwe have $\\sigma^{\\sigma(n)}(0) = \\sigma \\circ \\sigma^n(0) = \\sigma(n) = n + 1$.\n\n\\subsubsection{Exercise 6}\nWe can take $\\sigma^{-1}(n) = n - 1$ for $n > 0$ and $\\sigma^{-1}(0) = 0, 1, 2$\nto get 3 different left inverses.\n\n\\subsubsection{Exercise 8}\nLet $n \\in U$ if the elements in all sets of size $n$ are equal.\nSince we can construct a set with two different elements, we have that $n = 1$ does\nnot imply $\\sigma(n) \\in U$, and the induction axiom cannot be applied to $U$.\n\n\\subsubsection{Exercise 9}\n(Property I, Property II): Take $X = \\mathbb{N}$ and $\\sigma(x) = x^2 + 1$.\n\n(Property I, Property III): Let $X = \\{0, 1\\}$ and let $\\sigma(0) = 1, \\: \\sigma(1) = 0$.\nThen $\\sigma$ is clearly injective, and any subset of $X$ that contains 0 and $\\sigma(0)$ \nis all of $X$.\n\n(Property II, Property III): Again take $X = \\{0, 1\\}$, but this time let $\\sigma(0) = \\sigma(1) = 1$.\n\n\\subsection{Addition and Multiplication}\n\n\\subsubsection{Exercise 1}\n\\begin{align*}\n        n = 0 &:  \\: (f^m)^0 = 1 = f^0 = f^{(\\sigma^m)^0 (0)} = f^{m 0} \\\\\n        \\text{Assume n} &: \\: (f^m)^{(\\sigma(n))} = f^m \\circ f^{mn} = f^{m(n+1)}\n\\end{align*}\n\n\\subsubsection{Exercise 2}\n(a) $mn = (\\sigma^m)^n (0) = \\sigma^{mn} (0) = \\sigma^{nm} (0) = nm$.\n\n(b) $\\sigma(m) (n + n') = (\\sigma^{\\sigma(m)})^{n + n'}(0) = (\\sigma^{\\sigma(m)})^n(0) + (\\sigma^{\\sigma(m)})^{n'}(0)$.\n\n\\subsubsection{Exercise 3}\n(a) To obtain a valid $\\tau$, simply permute the first few mappings of $\\sigma$.\nFor example, $\\tau(0) = 2, \\tau(1) = 3, \\tau(2) = 1, n \\geq 3 : \\: \\tau(n) = n + 1$.\n\n(b) Suppose $\\tau$ satisfies Peano. Then we can let $\\beta(0) = 0$ and \n$\\beta(n) = \\tau(\\beta(n - 1))  \\: \\forall n > 0$. $\\beta$ is a bijection since\n$\\tau$ is injective and maps to all of $\\mathbb{N} / \\{0\\}$.\nFurthermore, $\\beta \\sigma (n) = \\beta (n+1) = \\tau \\beta (n)$.\n\n\\subsubsection{Exercise 4}\n(a)\n\\begin{align*}\n        \\phi(n) = m &\\implies \\sigma(\\phi(n)) = m + 1 \\\\\n                    &\\implies \\phi(\\sigma(n)) = \\phi(n + 1) = m + 1\n\\end{align*}\nThus, once we fix $\\phi(0)$, we fix the rest of $\\phi$.\n\n(b) There is only one choice of $\\tau$ which satisfies Peano's Postulates:\n$\\tau(0) = 1$ with $\\tau$ satisfying the relation indicated in (a). \nThis is exactly the successor function $\\sigma$.\n\n\\subsubsection{Exercise 6}\n$k + n = \\sigma^n(k) = \\sigma^n(m) \\implies k = m$ since a composition of injections\nis an injection.\n\n\\subsection{Inequalities}\n\n\\subsubsection{Exercise 1}\nSince  $x = x$ we have reflexivity of $\\leq$.\nSince $x \\leq y \\implies x + a = y$ and $y \\leq z \\implies y + b = z$,\nwe have $x + a + b = z$ giving transitivity.\n\n\\subsubsection{Exercise 2}\n \\begin{align*}\n         m < n &\\implies m + x = n \\\\\n               &\\implies m + x + k = n + k \\\\\n               &\\implies m + k < n + k\n\\end{align*}\nMultiplication is also isotonic since it's just iterated addition.\n\n\\subsubsection{Exercise 3}\nSuppose $0 \\in U, \\: n \\in U \\implies \\sigma(n) \\in U$ and $U \\neq \\mathbb{N}$.\nThen from well-ordering, we have that $\\mathbb{N} / U$ has a first element $f$ \nsuch that $m < f \\implies m \\in U$. However, this gives us that\n$\\exists m \\in  U \\: | \\: \\sigma(m) = f$ which leads to a contradiction.\n\n\\subsubsection{Exercise 4}\nSuppose $S$ is well-ordered with first element $f$ but $U \\subset S$ is not.\nThen $V \\subset U \\: | \\: V \\neq \\emptyset$ and $V$ has no first element.\nHowever, since $V \\subset S$, we have a contradiction, since well-ordering\nimplies that every subset of $S$ has a first element.\n\n\\subsubsection{Exercise 6}\nThe subset consisting of that infinite descending sequence would contain no\nfirst element.\n\n\\subsection{The Integers}\n\n\\subsubsection{Exercise 1}\nLet $u = sdu + u_0$ and let $v = sdv + v_0$.\n\\begin{align*}\n        uv &= (sdu) (sdv) + (sdu) (v_0) + (u_0) (sdv) + u_0 v_0 \\\\ \n        d(uv) &= d((sdu) (sdv)) + 0 + 0 + 0 \\\\\n              &= (du) (dv)\n\\end{align*}\n\n\\subsubsection{Exercise 3}\nFollows from the steps of lemma, since we have that $du \\oplus' dv = d(u + v) = d(sdu + sdv) = du \\oplus dv$.\n\n\\subsubsection{Exercise 4}\nSuppose $a \\oplus x_1 = a \\oplus x_2$. Then $a' \\oplus (a \\oplus x_1) = a' \\oplus (a \\oplus x_2)$,\nwhich gives $x_1 = x_2$.\n\n\\subsubsection{Exercise 5}\nSame logic as Exercise 3, except using the result of Exercise 1.\n\n\\subsection{The Integers Modulo N} \n\n\\subsubsection{Exercise 3}\n\\begin{align*}\n        h - k \\in n\\mathbb{Z},\\:  r - s \\in n\\mathbb{Z} &\\implies (h - k) + (r - s) \\in n\\mathbb{Z} \\\\\n                                                     &\\implies (h + r) - (k + s) \\in n\\mathbb{Z} \\\\\n        h (r - s) \\in n\\mathbb{Z},\\: s (h - k) \\in n\\mathbb{Z} &\\implies h (r - s) + s (h - k) \\in n\\mathbb{Z} \\\\\n                                                               &\\implies hr - ks \\in n\\mathbb{Z}\n\\end{align*}\n\n\\subsubsection{Exercise 4}\nJust check the squares of $0, ..., 7$ mod 8 to get the desired result.\n\n\\subsubsection{Exercise 5}\n7 cannot be decomposed into a sum of 3 integers from the set $\\{0, 1, 4\\}$.\n\n\\subsubsection{Exercise 6}\nOne of the three consecutive integers must be divisible by 3; let the remainder of this integer mod 9 be\n$k$. Then, WLOG, we can let the other two integers be $k - 1$ and $k + 1$ mod 9. We then have that\n$(k - 1)^3 + k^3 + (k + 1)^3 = 3k^3 + 6k$, which is divisible by 9 since $k$ is divisible by 3.\n\n\\subsection{Equivalence Relations and Quotient Sets}\n\n\\subsubsection{Exercise 1}\nThe quotient $T / S$ consists of the set of all possible equivalence classes of triangles\nbased on the relation of triangle similarity. Thus, each element of $T / S$ corresponds to a\ndifferent kind of triangle similarity, or ``shape''.\n\n\\subsubsection{Exercise 2}\n$p \\times p$ is an equivalence relation on $\\mathbb{Z} \\times \\mathbb{Z}$. Furthermore,\n$(p \\times p) (x, y) = (p \\times p) (x', y') \\implies p(x + y) = p(x' + y')$.\nThen by Theorem 19, we can define addition of cosets of two integers as the function\nthat commutes with the coset of the sum of the integers.\n\n\\subsubsection{Exercise 3}\nReflexivity and symmetry are clear; transitivity follows from the fact that if  $(x_1, y_1)E(x_2,y_2), \\: \n(x_2, y_2)E(x_3, y_3)$, then $x_3 - x_1 = x_3 - x_2 + x_2 - x_1$ which is the sum of two integers and\ntherefore an integer. \n\n\\subsection{Morphisms}\n\n\\subsubsection{Exercise 1}\nThe additive endomorphisms of $\\mathbb{Z}$ are completely determined by the value they map 1 to.\nThus, they are all functions of the form $f(z) = c z$ for some constant $c \\in \\mathbb{Z}$.\n\n\\subsubsection{Exercise 2}\nEvery additive morphism from $\\mathbb{Z}_n$ to $\\mathbb{Z}_m$ is of the form $f(z) = p_m (c z)$ \nwhere $p_m: \\mathbb{Z} \\to \\mathbb{Z}_m$ maps elements of $\\mathbb{Z}$ to their remainders mod $m$  \nand $c \\in  \\mathbb{Z}_m$.\n\n\\subsubsection{Exercise 3}\nFollows the structure indicated in Exercise 2.\n\n\\subsubsection{Exercise 4}\nEach rotation of the square can be decomposed into clockwise rotations. If we label the vertices of \nthe square as $0, 1, 2, 3$, then a clockwise rotation can be thought of as adding 1 mod 4. Thus,\nthe isomorphisms between $(\\mathbb{Z}_4, +)$ and $(Q, \\circ)$ are exactly the additive isomorphisms\nbetween $\\mathbb{Z}_4$ and itself. There are only 2 such isomorphisms: $f(1) = 1$ and $f(1) = 3$.\n\n\\subsubsection{Exercise 5}\nFollows from left inverse for injectivity and right inverse for surjectivity.\n\n\\subsubsection{Exercise 7}\nAny morphism $f: (\\mathbb{R}, \\times) \\to (\\mathbb{R}, +)$ satisfies\n\\begin{align*}\n        f(1 * 1) &= f(1) + f(1) \\implies f(1) = 0 \\\\\n        f(0 * 0) &= f(0) + f(0) \\implies f(0) = 0\n\\end{align*}\nWhich means $f$ cannot be an isomorphism.\n\n\\subsection{Semigroups and Monoids}\n\n\\subsubsection{Exercise 1}\nIf $u$ and $u'$ are both units, then $u \\square u' = u' = u$.\n\n\\subsubsection{Exercise 2}\nThe terms $a_1, ..., a_m$ and $a_{m+1}, ..., a_{m+n}$ together give $a_1, ..., a_{m + n}$.\n\n\\subsubsection{Exercise 3}\nAs stated in the text, follows from induction on $n$ (the proofs can be found in previous sections).\n\n\\subsubsection{Exercise 4}\nDue to commutativity, we can rearrange the terms in the double sum as we like, thereby allowing us\nto swap sums.\n\n\\subsubsection{Exercise 5}\nLet $f: (\\mathbb{N}, +) \\to (\\mathbb{N}, \\times)$ be such that $f(n) = 0 \\:  \\forall n \\in \\mathbb{N}$.\nThen $f$ is a morphism that does not map the additive unit 0 to the multiplicative unit 1.\n", "meta": {"hexsha": "901449f445a0a448c83ba5ae22f3749fd6492a7d", "size": 13478, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algebra_Maclane_Birkhoff/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": "Algebra_Maclane_Birkhoff/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": "Algebra_Maclane_Birkhoff/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": 41.9875389408, "max_line_length": 119, "alphanum_fraction": 0.6322154622, "num_tokens": 4596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.6818044230385225}}
{"text": "\\section*{Ex.34.5-1}\n\\subsection*{Subgraph--isomorphism problem (SI)}\n\n\nTo show that SI is NP complete we want to show that 1) SI is in NP, and 2) CLIQUE $\\leq_P$ SI.\n\nTo show that SI is NP:\n\\\\\nGiven the function $f$ which map vertex names in $G_1$ to vertex names in $G_2$, the isomorphism problem can be verified in linear time. Given vertices $V_1$ and edges $E_1$ in $G_1$ we can also in linear time determine if $G_1$ is a sub--graph of $G_2$. Combining the two we can in linear time determine if $G_1$ is subgraph--isomorphic to $G_2$. Hence SI is NP.\n\nTo see that CLIQUE $\\leq_P$ SI:\n\\\\\nNote that we must map all CLIQUE problem to some $G_1$. Let $G_1$ be the complete graph with $k$ vertices, then solving SI would also solve CLIQUE, and as CLIQUE is NP complete, so is SI.", "meta": {"hexsha": "22b1ccdeac0881ef772b6956ebceaee9b94eb2f5", "size": 781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.5-1.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-1.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-1.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": 60.0769230769, "max_line_length": 363, "alphanum_fraction": 0.7247119078, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772318846387, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.681774039613984}}
{"text": "\\section{The Algorithm}\n\\label{sec:radix}\n\nRadix Sort is a non-comparative sorting algorithm that works on integer or string keys. The ordering is done by grouping keys into buckets, according to their individual digits.\\\\\n\nThere are two variants of the algorithm. The \\emph{Least Significant Digit Radix Sort} which starts by grouping keys based on their least significant digit. After each key is sent to their respective bucket, the buckets are concatenated orderly. At this point the keys will be ordered up to the digit upon which the step was made. After iterating through all the digits, the keys are ordered. The \\emph{Most Significant Digit Radix Sort} uses a different approach, and is recursive in nature. Starting on the most significant digit, keys are grouped to their buckets. However, instead of merging all buckets after this step, a recursive step is taken, ordering each bucket internally based on the next digit.\\\\\n\nThis report will focus only on the first version, since it's an iterative, simple method, instead of a recursive one, and because of that, it's parallelization is not only easier to implement, but probably allows for better load balance.\\\\\n\n\n\\subsection{How it works}\n\\label{subsec:how_it_works}\n\nConsider the following list of integers:\n\n\\begin{lstlisting}\n\tarr = [170, 45, 75, 90, 802, 24, 2, 66]\n\\end{lstlisting}\n\nIn the first iteration, the least significant digit is considered. After sending each key into the correct bucket, the result is the following:\n\n\\begin{lstlisting}\n\t0: [170, 90],\n\t2: [802, 2],\n\t4: [24],\n\t5: [45, 75],\n\t6: [66]\n\\end{lstlisting}\n\nAnd after merging all buckets:\n\n\\begin{lstlisting}\n\tarr = [170, 90, 802, 2, 24, 45, 75, 66]\n\\end{lstlisting}\n\nThis completes the first iteration. The process is repeated until there are no more digits do process. In the previous example, two more iterations would be necessary for the array to be completely ordered.\nTo order the keys descendingly, the only change would be on the merging step, where the arrays would be merged starting from the last one.\n", "meta": {"hexsha": "fb0348d5ed03f136106a538a00b8dc493008f680", "size": 2053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/first/report_files/2_radix.tex", "max_stars_repo_name": "naps62/parallel-sort", "max_stars_repo_head_hexsha": "23ffbc48e06c4ad79d41a103e09a750c5c4eef56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-02-02T00:03:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T05:12:23.000Z", "max_issues_repo_path": "doc/first/report_files/2_radix.tex", "max_issues_repo_name": "naps62/parallel-sort", "max_issues_repo_head_hexsha": "23ffbc48e06c4ad79d41a103e09a750c5c4eef56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-05T16:08:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-05T17:02:53.000Z", "max_forks_repo_path": "doc/first/report_files/2_radix.tex", "max_forks_repo_name": "naps62/parallel-sort", "max_forks_repo_head_hexsha": "23ffbc48e06c4ad79d41a103e09a750c5c4eef56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-07-10T18:32:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-08T18:50:18.000Z", "avg_line_length": 54.0263157895, "max_line_length": 710, "alphanum_fraction": 0.7720409157, "num_tokens": 499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.6817740313059476}}
{"text": "\\subsection{Ground Litter Decomposition Model}\nDue to the irregular shape of ground litter, it is hard to represent ground litter as a special geometric. Therefore, we simplified it as the process of fungi decomposition of a plane, shown as follows.\n\\par\n\\begin{figure}[H]\n  \\label{figure2}\n  \\centering\n  \\includegraphics[width=0.55\\textwidth]{figures/litter.png}\n  \\caption{Decomposition plane.}\n\\end{figure}\n\\par\nSimilar to the \\textit{Woody Fibers Decomposition Model}, fungi that could decompose cellulose or lignin are distributed on a flat surface, gradually decomposing ground litter from outside to inside. By consulting the literature~\\cite{literature}, the decomposition rate function of fungi decomposing ground litter on the plane is similar to the \\textbf{logarithmic function} in \\textit{Eq.~(\\ref{eightheq})} as follows.\n\\begin{equation}\n  \\label{eightheq}\n  DR \\propto \\ln (1+\\frac{1}{4d})\n\\end{equation}\nCombined with the analysis of environmental decomposition constant ($\\varepsilon_{DR}$) and fungi activity factor ($ACT$) in \\textit{Model~4.1}, we deduce the \\textbf{decomposition rate of fungi in the plane distribution} as \\textit{Eq.~(\\ref{ninetheq})}\n\\begin{equation}\n  \\label{ninetheq}\n  DR=\\frac{\\beta}{\\varepsilon_{DR}} \\ln (1+\\frac{1}{4d}),\\ d\\in (0.05,\\ +\\infty)\n\\end{equation}\nwhere $\\beta$ represents fungi areal density, and $d$ represents the depth of fungi's current decomposition.\n\\par\nConsidering that fungal decomposing needs to be carried out at a certain distance below ground level, we set a lower limit of $0.05$ meters for the current depth of fungal decomposition, which avoids invalid information when $d\\longrightarrow 0^+$, $DR\\longrightarrow +\\infty$.", "meta": {"hexsha": "16c73ed751d478e9d81dc212d240be1734c2494b", "size": 1700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/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/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/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": 73.9130434783, "max_line_length": 420, "alphanum_fraction": 0.7694117647, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.681774022997911}}
{"text": "\\section{Introduction}\nPolytope Packing is the problem of placing a given set of\npolytopes into a parallelepiped of given length and width\nwith the goal of finding the minimal possible height that\navoids polytopes collision (polytopes may touch but they\ncannot compenetrate). \n\nThe problem has been studied for instance by \nStoyan et. al in~\\cite{sto03}, which we use as\na reference and comparison for this report. More related\nwork can be found in the aforementioned paper and others\nby the same authors.\n\nOur approach is a plain encoding into an SMT2~\\cite{SMTLIB} \nformula. SMT, Satisfiability Modulo Theories, is an area of \nresearch that combines efficient SAT-Solving and domain-specific\ndecision procedures to build efficient tools that could\nreason about, for instance, arbitraty boolean combinations \nof linear arithmetic costraints. Efficient SMT-Solvers are\navailable off-the-shelf and under continuos improvement. \nOur encoding into SMT exploits the notion of Minkowski sum \nto formally describe concepts such as ``polytope intersection''.\n\nTherefore, the approach can be summarized as follows: \ntake a set of polytope descriptions, encode the problem\ninto SMT2, execute an SMT-Solver to find a solution (if any\nexists), read the solution and translate it back to\ncoordinates that describes the polytopes placement.\n", "meta": {"hexsha": "9a6d38ce708c6cb89a7ab743c0845e3fdf9dd360", "size": 1328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/introduction.tex", "max_stars_repo_name": "formalmethods/polytopepacking", "max_stars_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-07T13:54:39.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-07T13:54:39.000Z", "max_issues_repo_path": "report/introduction.tex", "max_issues_repo_name": "bobosoft/polytopepacking", "max_issues_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-03-18T08:05:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-21T20:44:27.000Z", "max_forks_repo_path": "report/introduction.tex", "max_forks_repo_name": "formalmethods/polytopepacking", "max_forks_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7931034483, "max_line_length": 64, "alphanum_fraction": 0.8125, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.7879312031126511, "lm_q1q2_score": 0.6817370550852585}}
{"text": "\\section{Dimensionality Reduction}\n\\begin{itemize}\n\t\\item Reasons: \n\t\\begin{itemize}\n\t\t\\item reduce a complex dataset to a \\textbf{lower dimension}.\n\t\t\\item simplify data understanding, visualization and manipulation\n\t\t\\item reduce computation time\n\t\t\\item reveal hidden dynamics -- latent variables, \\textbf{multicollinearity}\n\t\t\\item the data lies on a lower dimensional subspace anyway. \n\t\\end{itemize}\n\n\t\\item Techniques to Dimensionality Reduction (combat multicollinearity):\n\t\\begin{itemize}\n\t\t\\item Subset Selection \n\t\t\\begin{itemize}\n\t\t\t\\item Best Subset, Forward Selection, Backward Elimination, Stepwise Selection\n\t\t\\end{itemize}\n\t\t\\item Derived Input in Regression\n\t\t\\begin{itemize}\n\t\t\t\\item Principal Component Regression\n\t\t\t\\item Partial Least Squares\n\t\t\\end{itemize}\n\t\t\\item Regularization (Coefficient Shrinkage)\n\t\t\\begin{itemize}\n\t\t\t\\item Subset selection\n\t\t\t\\item Ridge Regression\n\t\t\t\\item Lasso Coefficient\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\n\t\\item Comparison Linear Regression VS. Dimension-Reduction Techniques\n\t\\begin{itemize}\n\t\t\\item Linear Regresion: \n\t\t\\begin{itemize}\n\t\t\t\\item requires $n \\geq p$, more observations than variables. \n\t\t\t\n\t\t\t$\\rightarrow$ reality large observation too costly, variables too much\n\t\t\t\\item if number of variables too large $\\rightarrow$ \\textbf{Overfitting}\n\t\t\t\\item can't combat multicollinearity, separate test on VIF.\n\t\t\t\\item \\textbf{unstable} to little variability on data in prediction results\n\t\t\\end{itemize}\n\t\t\\item Dimension-Reduction Techniques:\n\t\t\\begin{itemize}\n\t\t\t\\item PCR: combats multicollinearity through computing linear uncorrelated principal components.\n\t\t\t\\item \\textbf{more stable} to the variability on data if variables are correlated.\n\t\t\t\\item Regularization: through feature selection, introduce \\textbf{bias} but \\textbf{reduce variance (smaller MSE)}.  \n\t\t\\end{itemize}\n\t\\end{itemize}\n\\end{itemize}\n\\subsection{Principal Component Analysis}\n\\begin{itemize}\n\t\\item Definition: converts a set of possibly \\textbf{correlated} variables into a (possibly smaller) set of \\textbf{linearly uncorrelated} variables -- \\textbf{Principal Components}.\n\t\n\t\\item Goal: transform the data, such that the new dimensions are \\textbf{linear uncorrelated} and we \\textbf{maximize the variance} along the axes.\n\t\\item Assumption: relationship among variables is \\textbf{linear}.\n\t\\item \\textbf{Principal Components}: \\textbf{explain most of the variability} in the original dataset. \n\t\\begin{itemize}\n\t\t\\item the \\textbf{eigenvectors} of the covariance/correlation matrix\n\t\t\\item the direction are those in feature space along which the original data is \\textbf{highly variable}.\n\t\t\\item the \\textbf{first PC} has \\textbf{largest possible variance}.  It's the direction of \\textbf{maximum variance from origin}.\n\t\t\\item \\textbf{subsequent PCs} are \\textbf{orthogonal} to first PC. They describe \\textbf{maximum residual variance}.\n\t\t\\item each element of eigenvector represents the \\textbf{contribution of a variable} to the PC.\n\t\\end{itemize}\n\t\\item PCA \\textbf{Eigenvalues}: give the \\textbf{proportion of variance explained} by the corresponding principal components. \n\t\\begin{itemize}\n\t\t\\item $\\lambda_1$ shows the proportion of variance explained by PC1. $\\rightarrow$ the \\textbf{spread of data} in PC1 direction.\n\t\\end{itemize}\n\t\\item PCA \\textbf{Scores}: Z, score of x are the coefficients of in each PC direction. \n\\end{itemize}\n\n\\subsubsection{Process}\n\\begin{enumerate}[label= \\protect \\circled{\\arabic*} ]\n\t\\item \\textbf{center} the data, subtract the \\textbf{mean} from each data dimension. $\\rightarrow$ zero-mean dataset.\n\t\\item compute \\textbf{covariance/correlation matrix}:\n\t\\begin{itemize}\n\t\t\\item covariance matrix: variables in \\textbf{comparable units}, \\textbf{difference in variance} across variable \\textbf{important}\n\t\t\\item correlation matrix: variables in \\textbf{different units}, \\textbf{difference in variance} across variable \\textbf{not important}\n\t\\end{itemize}\n\t$$Var(x_j) =  \\frac{1}{N-1} \\cdot\\Sigma x_{ij}^2$$\n\t$$Cov(x_{j1}, x_{j2}) = \\frac{1}{N-1} \\cdot \\Sigma x_{ij1} x_{ij2} $$\n\t\n\t\\item compute \\textbf{eigenvalues and eigenvectors} of the covariance/correlation matrix. \\textbf{Normalized} the eigenvectors.\n\t\\item \\textbf{order} eigenvectors according to \\textbf{its eigenvalues in descending order} $\\Phi$.\n\t\\item compute variance explained by each principal component:\n\t$$\\text{variance explained} = \\frac{\\lambda_i}{\\Sigma \\lambda_i}$$\n\t\\item Project the transformed data onto principal components: all principal components are \\textbf{orthonormal basis}.\n\t$$Z = X\\cdot \\Phi$$\n\t\\item Compress: choose $k$ most important PCs. $\\rightarrow$ slight \\textbf{information loss}\n\\end{enumerate}\n\n\\subsubsection{Reconstruction of Original Data}\n$$D \\approx Z \\Phi^T + \\text{means}$$\n\nIf \\textbf{dimensionality reduced}, we \\textbf{lose} those dimensions we choose to \\textbf{discard}. The information loss is relatively small.\n\\subsubsection{Computation Principal Component: Singular Value Decomposition}\n$$A = U\\cdot S \\cdot T^{T}$$\n\n\\begin{itemize}\n\t\\item Alternative to compute principal components.\n\t\\item principal axes/components: columns of V\n\t\\item principal component scores $U\\cdot S$\n\t\\item Use-case: recommendation system\n\\end{itemize}\n\\subsection{Principal Component Regression}\n\\begin{itemize}\n\t\\item Multiple Linear Regression VS. Principal Component Regression\n\t\\begin{itemize}\n\t\t\\item PC combines the correlated variables into linear uncorrelated variables. It explain the most important variability of the model. \n\t\t\n\t\t$\\rightarrow$ \\textbf{combats multicollinearity and unstability} to minor change in data from linear regression models. \n\t\\end{itemize}\n\t\\item PCR Model:\n\t$$y = Z \\cdot \\gamma + \\varepsilon,  \\quad \\text{with} \\quad Z = X \\cdot \\Phi  $$\n\t\\begin{itemize}\n\t\t\\item independent variables: principal components in Z\n\t\\end{itemize}\n\t\\item works well when the first few principal components are sufficient to explain most of the variation.\n\t\\item not a feature selection method.\n\\end{itemize}\n\n\\subsubsection{Partial Least Squares}\n\\begin{itemize}\n\t\\item identifies new features in a \\textbf{supervised} way:\n\t\\begin{itemize}\n\t\t\\item new features \\textbf{approximate old features} and are \\textbf{related to response}.\n\t\t\\item weights reflect the covariance structure between \\textbf{predictors and response}\n\t\\end{itemize}\n\t\\item requires more complicated iterative algorithms\n\\end{itemize}\n\n\\subsection{Regularization: Ridge Regression}\n\\subsubsection{Regularization}\n\\begin{itemize}\n\t\\item Goal: \\textbf{introduce bias} into regression solution that can \\textbf{reduce variance} relative to OLS solution.\n\t\\item Objective function in regularization:\n\t$$J(\\theta) = L(\\theta) + \\Omega(\\theta)$$\n\t\\begin{itemize}\n\t\t\\item $L(\\theta)$ : training loss, describes \\textbf{model fit}\n\t\t\\item $\\Omega(\\theta)$: regularization, describes \\textbf{model complexity} \n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Ridge Regression}\n\\begin{itemize}\n\t\\item Goal: \\textbf{minimizes} a \\textbf{penalized} RSS\n\t\\item Penality: \\textbf{$\\mathbf{l_2}$ penality}\n\t\n\t$$\\hat{\\beta}^{ridge} = \\arg\\min_{\\beta} (RSS + \\lambda \\cdot\\Sigma \\beta_j^2)$$\n\t\\begin{itemize}\n\t\t\\item $\\lambda \\uparrow$ , coefficients $\\rightarrow 0$ \n\t\t\\item coefficents will never be exactly 0, but nearly 0.\n\t\\end{itemize}\n\t\\item Evaluation: estimates \\textbf{more biased} but have \\textbf{lower variance} than OLS-Estimator. \n\\end{itemize}\n\n\n\\subsection{Regularization: Lasso}\n\\begin{itemize}\n\t\\item Goal: \\textbf{minimizes quantity}\n\t\\item Penality: \\textbf{$\\mathbf{l_1}$ penality}\n\t$$\\hat{\\beta}^{lasso} = \\arg\\min_{\\beta} (RSS + \\lambda \\cdot \\Sigma |\\beta_j|)$$\n\t\n\t\\item Finding tuning parameter $\\lambda$ : select a grid of values + cross-validation\n\t\\item Evaluation \\& Comparison Ridge Regression:\n\t\\begin{itemize}\n\t\t\\item has the effect of forcing some coefficients to be \\textbf{exactly zero}, when $\\lambda$ is large. \n\t\t\n\t\t$\\rightarrow$ feature selection\n\t\t\\item produces \\textbf{simpler and more interpretable} models involving only \\textbf{subset of predictors}\n\t\t\\item similar behavior to ridge regression: $\\lambda \\uparrow$, variance $\\downarrow$, bias $\\uparrow$.\n\t\t\\item generate \\textbf{more accurate predictions}.\n\t\\end{itemize}\n\\end{itemize}", "meta": {"hexsha": "f920a80b477fc5c7192f02e451a97bd3a723ba9e", "size": 8250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/dimreduce.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/dimreduce.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/dimreduce.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": 47.6878612717, "max_line_length": 183, "alphanum_fraction": 0.7572121212, "num_tokens": 2328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523327, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6817370486222453}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[ruled,vlined]{algorithm2e}\n\n\n\\begin{document}\n\n\\title{Increasing Reservoir Computer Responsiveness to Initial Conditions}\n\\maketitle\n\n\\subsection*{Overview}\n\nGiven an $n_d$ dimensional orbit $\\mathbf{u}(t)$ for $t_0 < t < T$, through a system that we will attempt to learn, a reservoir computer is trained by driving the reservoir with the input $\\mathbf{u}(t)$, then projecting $\\mathbf{u}(t)$ onto the resulting driven orbit of the reservoir nodes. \n\nThis occurs as follows. Given $\\mathbf{u}(t)$, choose an $n_r$ dimensional reservoir initial condition $\\mathbf{r}_0$. Standard practice selects $r_0$ randomly, but it is more useful if $\\mathbf{r}_0 = \\phi(\\mathbf{u}(t_0))$ for some $\\phi$. Then, we solve the following initial value problem numerically for solution values at the discrete time points $\\{t_0, ..., tt_n\\}$.\n\n\\begin{equation} \\label{untrained}\n\\frac{d\\mathbf{r}}{dt} = -\\gamma\\big[\\mathbf{r}(t) + f\\big(A\\mathbf{r}(t) + \\sigma W_\\text{in} \\mathbf{u}(t)\\big)\\big], \\quad\n\\mathbf{r}(t_0) = \\mathbf{r}_0\n\\end{equation}\n\nHere $\\gamma > 0$ and $\\sigma > 0$ are hyper parameters, $f$ is an activation function $W_\\text{in}$ is an $n_r \\times n_d$ dimensional read-in matrix and  $A$ is an adjacency matrix that governs how the nodes in the reservoir interact. \n\nLet $R$ represent the numerical solution to the IVP above and let $U$ represent $\\mathbf{u}(t)$ sampled at corresponding time points. That is,\n\\[\nR =\n\\begin{bmatrix}\n\\mathbf{r}(t_0)^T \\\\\n\\mathbf{r}(t_1)^T \\\\\n\\vdots \\\\\n\\mathbf{r}(t_{n-1})^T \\\\\n\\mathbf{r}(T)^T \\\\\n\\end{bmatrix}\n\\quad \nU =\n\\begin{bmatrix}\n\\mathbf{u}(t_0)^T \\\\\n\\mathbf{u}(t_1)^T \\\\\n\\vdots \\\\\n\\mathbf{u}(t_{n-1})^T \\\\\n\\mathbf{u}(T)^T \\\\\n\\end{bmatrix}\n\\]\nIf we use $n+1$ time values, then $R$ is an $(n+1)\\times n_r$ matrix and $U$ is an $(n+1)\\times n_d$ matrix.\n\nWe then approximate the projection of $\\mathbf{u}(t)$ onto $\\mathbf{r}(t)$ by finding a $n_d \\times n_r$ matrix $W_\\text{out}$ that projects the rows of $U$ onto the rows of $R$.\n\nThis is computed by solving the Tikanov regression problem\n\\[ ||W_\\text{out} R^T - U||_2 + \\alpha ||W_\\text{out}||\n\\]\n for minimizer $W_\\text{out}$.\n \n It is important to note that $W_\\text{out}$ does not send $\\mathbf{r}(t)$ to $\\mathbf{u}(t)$. Instead attempts to send every row of $R$ to the corresponding row in $U$ . Therefore, the usefulness of a particular $W_\\text{out}$ for a given problem depends on the kind of data that is in $R$ and $U$. By adjusting the data (adding or removing rows) in $R$ and $U$ we can provide additional conditions or constraints to our desired $W_\\text{out}$. \n \n Since we are interested in the problem of arbitrary initial conditions, we note that in standard reservoir computer training, only a single row of $R$ and $U$ corresponds to an initial condition. We hypothesize that the importance of $W_\\text{out}$ getting this projection correct relative to the all the other rows, is not very high. This results in misaligned predictions.  \n More explicitly, for initial test data $\\mathbf{\\hat{u}}_0$\n  and $\\mathbf{\\hat{r}}_0 = \\phi(\\mathbf{\\hat{u}}_0)$  \n the magnitude of $||W_\\text{out}\\mathbf{\\hat{r}}_0  - \\mathbf{\\hat{u}}_0 ||$ is large. If the reservoir is unable to match the initial test data even before solving the autonomous IVP, we can't expect it to predict accurately.\n \n \n We attempt to remedy this by teaching $W_\\text{out}$ to associate multiple initial conditions from the training data with corresponding reservoir initial conditions. In theory, we could just augment $R$ and $U$ with initial condition mappings like this:\n \\[\n R_\\text{aug} = \n \\begin{bmatrix}\n R \\\\\n \\phi(\\mathbf{u}(\\tau_1)) \\\\\n \\phi(\\mathbf{u}(\\tau_2)) \\\\\n \\vdots \\\\\n \\phi(\\mathbf{u}(\\tau_k)) \\\\\n \\end{bmatrix}\n \\quad\n  U_\\text{aug} = \n \\begin{bmatrix}\n U \\\\\n \\mathbf{u}(\\tau_1) \\\\\n \\mathbf{u}(\\tau_2) \\\\\n \\vdots \\\\\n \\mathbf{u}(\\tau_k) \\\\\n \\end{bmatrix}\n \\]\n\nwhere $\\tau_1, ... \\tau_k$ are random times in $(t_0, T)$. In fact, this might do better than our current window training method!\n\nHowever, your author believes the evolution of the reservoir computer state immediately after a new initial condition is important to include in $R$ and $U$. This is done with the intention of teaching $W_\\text{out}$ to map the beginnings of orbits to the correct places rather than just sending the initial condition to the right place. Thus, we use windows over the training data in the current algorithm.\n\n\\subsection*{Initial Condition Mappings}\n\nThe initial condition mapping, $\\phi$, is a key element of creating a correspondence between an orbit in the training signal space and an orbit in the reservoir space. By reservoir space, we mean the $n_r$ dimensional space that contains reservoir node trajectories.\n\nIf we train a reservoir with standard techniques, it can continue the trajectory of the training orbit. Using the notation from before, this is because\n\\[\n\\mathbf{u}(T) \\approx W_\\text{out} \\mathbf{r}(T)\n\\]\n which only occurs because $\\mathbf{u}(T)$ and $\\mathbf{r}(T)$ were included in the matrices used to solve for $W_\\text{out}$. In other words, $W_\\text{out}$ \"learned\" what reservoir initial state should correspond to $\\mathbf{u}(T)$ because $W_\\text{out}$ is the solution to a regularized least squares problem that creates a correspondence between  $\\mathbf{u}(T)$ and $\\mathbf{r}(T)$.\n\nHowever, what if we want to know the evolution of our unknown system from a new initial condition $\\mathbf{u}^\\star$ and we don't have any orbit leading up to $\\mathbf{u}^\\star$ to use to train our reservoir? \nOur trained reservoir is an $n_r$ dimensional ODE that requires an initial condition in $\\mathbb{R}^{n_r}$. \nIf we assume our reservoir has indeed \"learned\" the unknown system, there should be an $n_r$ dimensional initial condition $\\mathbf{r}^\\star$ such that the evolution of the reservoir nodes from this point corresponds to the evolution of the unknown system from $\\mathbf{u}^\\star$. \n\nWe know that $W_\\text{out}$ sends reservoir node states to the training signal space, and here we are trying to do the inverse operation, send a point in the training signal space to the reservoir space. Thus, a natural choice for mapping $\\mathbf{u}^\\star$ to an appropriate $\\mathbf{r}^\\star$ is the pseudo inverse $W_\\text{out}^\\dagger$. However, in practice, the pseudo inverse does not work. This appears to be because it does not respect the bounds on reservoir node state magnitude that are imposed by the activation function. If $f(\\mathbf{r}) = \\tanh(\\mathbf{r})$, reservoir node states will remain within $[-1,1]$ for all time (after a transient period where they travel to this interval). Thus, the reservoir node states that are used to create $W_\\text{out}$ are all within this interval, and therefore, the learned dynamics of the unknown system are embedded in the reservoir space inside the hyper-cube $[-1,1]^{n_r}$. Thus, the important reservoir initial conditions are likely to all lie within this hyper-cube. However, in practice the pseudo inverse does not respect this region, and it's proposed initial condition vectors often end up in the transient region outside of this hyper cube. This leads to predictions that begin outside the of the area of interest, and then converge to the expected dynamics after a short time.\n\nFrom this experience we hypothesize that good initial condition mappings probably place the reservoir condition inside the constraining hyper cube.\n\n\\subsubsection*{Inverting the Initial Condition Mapping}\nWhen we discussed using the pseudo inverse, we assumed that $W_\\text{out}$ was already known and we used $W_\\text{out}^\\dagger$ to create an initial condition mapping. However this method did not work. Instead of building an initial condition mapping from $W_\\text{out}$, we take a different approach. We chose an arbitrary mapping $\\phi (\\mathbf{u}) = \\mathbf{r}$ from the training space to the reservoir space and train  $W_\\text{out}$ to invert $\\phi(\\mathbf{u})$.  This is done by adding many initial condition correspondences $\\{ \\big( \\phi (\\mathbf{u}_i), \\mathbf{u}_i \\big)\\}_{i=1}^{k}$ to the training data as explained previously. \n\nWhen this process is complete, \n\\[W_\\text{out} \\phi(\\mathbf{u}^\\star) \\approx \\mathbf{u}^\\star\n\\]\nfor any $\\mathbf{u}^\\star$.\n\nBecause of this we can use $\\mathbf{r}^\\star = \\phi(mathbf{u}^\\star)$ as an initial condition for the trained reservoir and be confident that the beginning of the reservoir orbit will align with the beginning of the orbit though unknown system. \n\nThis occurs because when we generate a trained reservoir orbit $\\hat{\\mathbf{r}}(t)$ and apply $W_\\text{out}$ to produce a prediction, \n\\[ \n\\hat{\\mathbf{u}}(t) = W_\\text{out} \\hat{\\mathbf{r}}(t)\\]\n we know that \n \\[\n \\hat{\\mathbf{u}}(t_0) = \\mathbf{u}^\\star \\approx W_\\text{out} \\phi(\\mathbf{u}^\\star) =  W_\\text{out} \\hat{\\mathbf{r}}^\\star = W_\\text{out} \\hat{\\mathbf{r}}(t_0)\n \\]\n so the beginning of the orbits will correspond.\n\n \\subsubsection*{The Role of Transience}\n\nIn untrained reservoir computers, the dynamical system always has at least one attracting fixed point. The location of this fixed point depends on the value of the driving signal. If the reservoir initial condition is not exactly this attracting fixed point, the orbit of the reservoir node will have an initial period of transience until it moves close enough to the attracting fixed point. After this transient period, the orbit of the node will simply follow the systems attracting fixed points as their location evolves in time.\n\nWe can set our unknown initial condition $\\mathbf{r}^\\star$ to the location of an attracting fixed point corresponding to the input $\\mathbf{u}(t)$. This creates a reservoir node orbit with no transience. That is, upon supplying the initial condition, reservoir nodes will follow the oscillations of the fixed point without any period of moving \"in range\". We use this method in our research and call it the \"relax\" method. This is because, in order to compute the location of the attracting fixed point, we give the untrained reservoir the constant input $\\mathbf{u}^\\star$ and allow the reservoir nodes to relax into a steady state at the attracting fixed point.\n\nHowever, preliminary experimentation showed that allowing some transience in the initial condition mapping was, in fact, helpful. To accommodate this, we use the function $\\phi(\\mathbf{u}) = f(W_\\text{in} \\mathbf{u})$. \nHere $W_\\text{in}$ sends the $n_d$ dimensional initial condition to the reservoir space, \n$\\mathbb{R}^{n_r}$, and \napplying the activation function $f$ to the resulting $n_r$ dimensional vector constrains the initial condition to the aforementioned hyper cube. The result will likely not be a reservoir computer fixed point, but it will be close to one. This provides a little bit of transience to the beginning of a node's orbit. We call this method \"activf\" in our research.\n\nIt remains to be seen which initial condition mapping is the best, but the fact that this method outperforms  the \"relax\" method suggests that transience may be useful.\n\n\\subsection*{Algorithm Description}\nFrom initial condition $\\mathbf{u}_0$, generate an array $(m \\times n_d)$ of samples, $U$ from the system you want to learn.\nSet the reservoir initial condition with $\\mathbf{r}_0=W_\\text{in} \\mathbf{u}_0$. Drive the reservoir states with the solution array to obtain $R$, the $(m \\times n_r)$ array of reservoir node states.\n\nSolve $||W_\\text{out} R - U||_2$ for minimizer $W_\\text{out}$. Tikanov regression with regularization parameter  $\\alpha$ gives\n\n\\[\nW_\\text{out} = (R^TR - \\alpha I)^{-1} R^T U\n\\]\n\nWhen $n$ is large the cost of storing $R$ in memory can be prohibitive. This problem is addressed by computing $R^TR$ and $R^TU$ in batches. We write\n\\[\nR = \\begin{bmatrix}\nR_1 \\\\\nR_2\\\\\nR_3 \\\\\n\\vdots  \\\\\nR_k\n\\end{bmatrix}  \n\\]\nwhere each $Ri$ is an $(m_i \\times n_r)$ array and $\\sum_i^k m_i = m$.\n\nThen \n\\[\nR^TR = \n\\begin{bmatrix}\nR_1 &  R_2 & R_3 & \\cdots & R_k\n\\end{bmatrix}  \n\\begin{bmatrix}\nR_1 \\\\ \nR_2\\\\\nR_3 \\\\\n\\vdots \\\\ \nR_k\n\\end{bmatrix}  = \\sum_i^k R_i^T R_i\n\\]\nIf we break up $U$ into \n\\[\nU = \n\\begin{bmatrix}\nU_1 \\\\ U_2 \\\\  \\vdots \\\\ U_k\n\\end{bmatrix} \n\\]where each $U_i$ has dimension $(m_i \\times n_d)$ we can compute $R^TU = \\sum_i^k R_i^T U_i$. This allows us to compute $W_\\text{out}$ in batches. If the resulting matrices are saved, $W_\\text{out}$ can be updated with additional data.\n\nA challenge with this approach is that the reservoir computer only associates one initial conditions with data. The even if the trained reservoir computer can continue the orbit on which it was trained, it may not learn to predict the orbit of an arbitrary initial condition, even if this new initial condition was close to the original initial condition. This paper presents a solution to this problem.\n\nContinuing with the concept of batch computation of $W_\\text{out}$ we point out that there is no requirement that $R_i$ corresponds with $R_j$ when $j \\neq i$. That is, whereas before, we assumed that $R$ was a continuous stream of node states, and $W_\\text{out}$ projects $R$ onto $U$, what is really true is that $W_\\text{out}$ attempts to send the rows of $R$ to the associated rows in $U$. Therefore, the matrix $U$ may contain orbits from multiple different initial conditions as long as the corresponding rows of $R$ are the response of the reservoir computer to those orbits and their corresponding initial conditions.\n\nThus, if $U_i$ contains a discretized solution to an ode, then the first row of $R_i$ should be $W_\\text{in} \\mathbf{u}_0$ where $u_0$ is the first row of $U_i$ and the remaining rows should be the evolution of node states with input from the entries of $U_i$. Therefore, each subsection of $R$ must associate with $U$ but the subsections $R_i$ need not relate to each other.\n\nThis means that a reservoir computer may be trained with multiple different streams of input. Furthermore, on each individual stream, the reservoir computer can reset it's initial condition so that it learns to associate initial conditions with the appropriate response.\n\nHow to break up the data is an important question, because if the batch windows are too small, the reservoir computer will not be trained on long term prediction.\n\nLuckily, since there is no limit on how many rows are in $R$, we can provide orbit association on multiple time scales if appropriate for the problem at hand. This is done by concatenating different length streams of input data into one large $U$ matrix (Or computing the solution to the Tikhanov Regression problem in batches, with each input data matrix as a separate batch.\n\nNext, focusing on a particular input stream, and assuming it is continuous, we can break it up into overlapping time windows and drive the reservoir computer with each window separately. For each window, we reset the reservoir internal initial condition to correspond with the first input condition of the particular time window.  After this we can map the driven internal states back on to the concatenation of time windows. This allows us to train a reservoir computer to replicate an orbit starting from multiple places along the orbit. The number and size of time windows is a hyper parameter that can be tuned.\n\n\\subsection*{Algorithm Example}\nNext we will consider an example of applying this algorithm to learning an ODE. Let's assume we are using a discrete solver for the ODE and therefore can define a function $F$ which accepts an array of $m$ time values $\\mathbf{t} = [t_1, t_2, ..., t_m]$ and an initial condition $\\mathbf{u}$ where $\\mathbf{u}$ is a vector of length $n_d$. \nPassing these values to $F$ produces $U = F(t, \\mathbf{u})$ where $U$ is a $(m \\times n_d)$ matrix and the $i^\\text{th}$ row of $U$ corresponds to the solution of the ODE at time $t_i$. \nSimilarly, we can define a function $G$ that corresponds to the untrained reservoir ODE so that for a $n_r$ dimensional vector $\\mathbf{r}$, $R = G(t, \\mathbf{r}, U)$ where $R$ is an $(m \\times n_r)$ matrix and the $i^\\text{th}$ row of $R$ corresponds to the solution to the driven reservoir ode at time $t_i$.\n \n\\begin{algorithm}[H]\n \\caption{Robust Reservoir Computer Training}\n\\SetAlgoLined\n\\KwResult{Write here the result }\n $\\hat{R} \\leftarrow (n_r \\times n_r)$ array of zeros \\\\\n $\\hat{U} \\leftarrow (n_r \\times n_d)$ array of zeros \\\\\n $T \\leftarrow$ Maximum number of time-steps per batch \\\\\n $\\mathbf{v}_1, \\mathbf{v}_2, \\cdots \\mathbf{v}_N \\leftarrow$ Initial conditions for the ode\\\\\n $ \\mathbf{\\tau}_1, \\mathbf{\\tau}_2, \\cdots \\mathbf{\\tau}_k \\leftarrow$ discretized time arrays for each initial condition \\\\\n \\For{$j$ in $1\\cdots N$ }{\n      $\\mathbf{t} \\leftarrow \\mathbf{\\tau}_j$ \\\\\n      $ \\mathbf{u} \\leftarrow \\mathbf{v}_j$ \\\\\n     $U \\leftarrow F(\\mathbf{t}, \\mathbf{u})$\\\\\n     \\For{i in $1 \\cdots k$}{\n         start $\\leftarrow T(i - 1) + 1$ \\\\\n         end $\\leftarrow Ti$ \\\\\n         $U_i \\leftarrow U[\\text{start:end, : }]$\\\\\n         $\\mathbf{t}_i \\leftarrow \\mathbf{t}[\\text{start:end}]$\\\\\n         $\\mathbf{u}_i \\leftarrow U_i[\\text{1, : }]$\\\\\n         $\\mathbf{r}_0 \\leftarrow W_\\text{in} \\mathbf{u}_i$\\\\\n         $R_i \\leftarrow G(\\mathbf{t}_i, \\mathbf{r}_0, U_i)$\\\\\n         $\\hat{R} \\leftarrow \\hat{R} + R_i^TR_i$\\\\\n         $\\hat{U} \\leftarrow \\hat{U} + R_i^T U_i$\\\\\n     }  \n }\n $W_\\text{out} \\leftarrow (\\hat{R} - \\alpha I)^{-1} \\hat{U}$\\\\\n\\end{algorithm}\n\n\\end{document}", "meta": {"hexsha": "725a5455d2dba0ce5f7a7da9cd38b646ed9b6bd3", "size": 17456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/AlgorithmWriteUp/algo_writeup.tex", "max_stars_repo_name": "djpasseyjr/RCInitialCond", "max_stars_repo_head_hexsha": "ca1a6aa8fdcb09a4d073683ea6dcdcdd18e63a77", "max_stars_repo_licenses": ["MIT"], "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/AlgorithmWriteUp/algo_writeup.tex", "max_issues_repo_name": "djpasseyjr/RCInitialCond", "max_issues_repo_head_hexsha": "ca1a6aa8fdcb09a4d073683ea6dcdcdd18e63a77", "max_issues_repo_licenses": ["MIT"], "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/AlgorithmWriteUp/algo_writeup.tex", "max_forks_repo_name": "djpasseyjr/RCInitialCond", "max_forks_repo_head_hexsha": "ca1a6aa8fdcb09a4d073683ea6dcdcdd18e63a77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-14T21:23:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-06T04:32:31.000Z", "avg_line_length": 76.5614035088, "max_line_length": 1343, "alphanum_fraction": 0.7319546288, "num_tokens": 4819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6817341961527801}}
{"text": "%---------------------------Stretch-----------------------------\n\\section{Stretch}\n\nThe stretch is\n\\[\nq = \\frac{ \\sqrt{2} \\min_{i\\in\\{0,1,2,3\\}}\\left\\{L_i\\right\\} }{ D_{\\max} }\n\\]\n\nNote that if $D_{\\max} < DBL\\_MIN$, we take $q = DBL\\_MAX$.\n\n\\quadmetrictable{stretch}%\n{$1$}%                                      Dimension\n{$[0.25,1]$}%                               Acceptable range\n{$[0,1]$}%                                  Normal range\n{$[0,DBL\\_MAX]$}%                           Full range\n{$1$}%                                      Unit square\n{\\cite{fimesh:xx}}%                         Citation\n{v\\_quad\\_stretch}%                         Verdict function name\n\n", "meta": {"hexsha": "2e65fbc6b08c94609dd7cfb7b806ab46963c9bc2", "size": 672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadStretch.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/QuadStretch.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/QuadStretch.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": 33.6, "max_line_length": 74, "alphanum_fraction": 0.375, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6817341870740806}}
{"text": "\\vssub\n\\subsection{~Derived parameters} \\label{sub:outpars}\n\\vssub\n\n\\subsubsection{Directional slopes and near-nadir backscatter}\nUnder the linear wave assumption, the surface slopes are Gaussian and fully prescribed by the \nmean square slope tensor mss$_x$, mss$_y$, mss$_{xy}$. In \\ws\\ the computed mss parameters are the down-wave $\\mathrm{mss}_u$, which is \nin the direction given by $\\mathrm{mss}_d$, and a cross-wave $\\mathrm{mss}_c$ which is in the perpendicular dimension. \n\nAs a a result, the \nmean square slope tensor for the (long) wave resolved by the wave model, after converting $\\mathrm{mss}_d$ to radians, are given by \n\\begin{eqnarray}\n   \\mathrm{mss}_{x,\\mathrm{long}} &=& \\mathrm{mss}_u \\cos^2(\\mathrm{mss}_d)+\\mathrm{mss}_c \\sin^2(\\mathrm{mss}_d) \\\\\n   \\mathrm{mss}_{y,\\mathrm{long}} &=& \\mathrm{mss}_u \\sin^2(\\mathrm{mss}_d)+\\mathrm{mss}_c \\cos^2(\\mathrm{mss}_d) \\\\\n   \\mathrm{mss}_{xy,\\mathrm{long}}&=&0.5 (\\mathrm{mss}_u - \\mathrm{mss}_c) \\sin(2 \\mathrm{mss}_d)\n\\end{eqnarray}\nThe contribution of short waves (above the maximum frequency of the model) should be added to these for a comparison with observations \nsuch as the backscatter power ($\\sigma^0$) of near-nadir optical or radar data (altimeters, GPM or CFOSAT/SWIM data).\n   \n\\subsubsection{Stokes drift profile}\nThe spectrum of the surface Stokes drift has the two components that are computed as \\\\\n{\\code usf(IK)= SUM( E(IK,ITH)*ECOS(ITH)*DTH(ITH) )*DK(IK)*2*WN(IK,ISEA) *  FACT(KD)/DF(IK)}\n\n{\\code vsf(IK)= SUM( E(IK,ITH)*ESIN(ITH)*DTH(ITH) )*DK(IK)*2*WN(IK,ISEA) *  FACT(KD)/DF(IK)}\n\nWhere WN is the wavenumber and FACT(KD) is a function of the non-dimensional water depth.\n\nFrom this spectrum, the Stokes drift at any depth $z$, counted positive upwards from a reference $z=0$, are given by\n\nUs(z)= SUM{IK=I1,I2} ( usf(IK) * FACT2(z,KD)*DF(IK))\nVs(z)= SUM{IK=I1,I2} ( vsf(IK) * FACT2(z,KD)*DF(IK))\n\nThis requires a knowledge of the local water depth D and mean sea level LEV and the wavenumbers WN(IK). KD=D*WN(IK) is thus a local function if the frequency/wavenumber index IK.\n\nThe coefficent FACT2(z,KD) is equal to EXP(2*WN(IK)*(z-LEV)) if KD $>$ 6, and otherwise, \\\\\nFACT2(z,KD)=COSH(2*WN(IK)*(z+H))/COSH(2*WN(IK)*D).\n", "meta": {"hexsha": "1659c63cf5b7faa1ac53a8585c391b0fe64ceca6", "size": 2210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WW3/manual/eqs/derived.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/derived.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/derived.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": 59.7297297297, "max_line_length": 178, "alphanum_fraction": 0.7108597285, "num_tokens": 746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6817296863972929}}
{"text": "\\chapter{Generate data}\nIn this chapter we go through the method of generating data from an non-homogenous poisson distribution. This method is used to generate data for sampling and tests.\n\\\\\n\\\\\nFirst one must choose what time interval to generate data, $[0, \\tau]$. Then simulate how many events $n$ that is occuring on this interval. This is done by using a homogenous poisson process(HPP) with rate $\\Lambda(\\tau)$, where $\\Lambda$ is from ??. The probability density for a NHPP is given by,\n\\begin{equation}\nf(t) = \\frac{\\lambda(t)}{\\Lambda(\\tau)}, \\quad 0\\leq t \\leq \\tau.\n\\end{equation}\nThis is the distribution to draw $n$ values from. Furthermore we need the cumulative distribution to draw the samples. The cumulative distribution is given by\n\\begin{equation}\nF(t) = \\frac{\\Lambda(t)}{\\Lambda(\\tau)}, \\quad 0\\leq t \\leq \\tau.\n\\end{equation}\nTo get a sample one draws first a value $u$ from an uniform distribution $U[0, 1]$. This value simulates the value for the cumulative distribution. Furthermore to get the sample from the poisson distribution one finds the $t$ value such that $F(t) = u$. Finding this value can be done in several ways. The prefered one is finding the inverse of $F(t)$. However this is difficult for $\\Lambda(t)$, hence a numerical approach is used to calculate $\\Lambda(t)$ and find $t$. An overview of the algorithm is found below.\n\\begin{algorithm}\n\\caption{Generate data from NHPP given model parameters}\n\\label{alg:gendata}\n\\begin{algorithmic}\n\\STATE Simulating on interval $[0, \\tau]$\n\\STATE $N \\sim Poisson(\\Lambda(\\tau))$\n\\FOR{$N$ values}\n\\STATE Draw $u \\in U[0, 1]$\n\\STATE Find a $t$ such that $F(t) = u$\n\\ENDFOR\n\\end{algorithmic}\n\\end{algorithm}", "meta": {"hexsha": "2d4d17a873a74a1943db9eaa806c27e7ed08aabb", "size": 1689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Thesis/chapters/datagen.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/datagen.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/datagen.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": 67.56, "max_line_length": 516, "alphanum_fraction": 0.737714624, "num_tokens": 465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6817296861896751}}
{"text": "\\subsection{Machine learning models}\n    \\label{sec:models}\n\n    The main goal of this work is to assert whether traditional machine learning models can ``separate'' documents according to BP citations. We will explore two approaches: unsupervised and supervised learning, with a focus on the latter.\n\n    Unsupervised learning means extracting patterns from data that is not labeled, \\eg, our raw documents. Considering this, we will present the raw documents to some algorithms, without explaining which precedents are being cited, and we will check their outputs to see if there is some pattern.\n\n    We have vectors representing our texts as $X$ and cited BPs as $y$, the definition of supervised learning. With this in mind, we will also adjust several supervised models in this data.\n\n    \\paragraph{Latent Dirichlet allocation.} Because we are dealing with texts, it is very convenient to experiment with latent Dirichlet allocation (LDA), the most common topic modeling technique. Assuming the existence of $K$ topics, each document has a distribution over the topics, and each topic has a distribution over the words. Mathematically, the formulation is:\n\n    \\begin{itemize}\n            \\item Each topic $k \\in \\{1, \\cdots, K\\}$ has distribution $\\beta_k \\sim \\text{Dirichlet}(\\eta)$ over the words;\n            \\item Each document $d \\in \\{1, \\cdots, D\\}$ has distribution $\\theta_d \\sim \\text{Dirichlet}(\\alpha)$ over the topics;\n            \\item Given a document $d$, the topics have distribution $z | \\theta_d \\sim \\text{Multinomial}(\\theta_d)$;\n            \\item Given a topic $k$, the words have distribution $w | \\beta_k \\sim \\text{Multinomial}(\\beta_k)$.\n    \\end{itemize}\n\n    The idea of using this model is to verify whether LDA can recover the topic of the BP being cited in a document. For example, if there were only two cited precedents on the dataset, one could fit LDA using two topics and verify if the most important words for each topic are representative of the precedents themselves. Even more, it is possible to verify if this topic-to-precedent assignment is good.\n\n    \\paragraph{Truncated SVD dimensionality reduction.} We will reduce the dimensionality of TF-IDF vectors to visualize if they are of some kind separable. The dimensionality reduction technique will be the (truncated) singular value decomposition, already explained in \\autoref{sec:document_embedding}. We will experiment with dimensionalities 2 and 3, which can be visualized on a 2-dimensional screen.\n\n    \\paragraph{K-nearest neighbors.} As TF-IDF vectors lie in some vector space, the decision of which BP is being cited could be taken considering its neighbor's cited precedent. This is what the k-nearest neighbors (k-NN) model does. The number of neighbors (parameter $k$) is chosen by cross-validation.\n\n    \\paragraph{Linear regression.} This model is already well known, but for regression. For classification, and when the target is binary, it is easy to fit a regression model using $y \\in \\{-1, 1\\}$ and considering the predicted class as the prediction sign. For multiclass, it is fitted one regression per target, and the class with the highest value is chosen. We will also use Ridge regularization, and the hyperparameter is chosen by cross-validation.\n\n    Although using linear regression for classification is not that convenient, mainly because the output can't be interpreted as a probability, we can use this model to assert if our vectors are \\textbf{linearly separable} in the very high dimensional space.\n\n    \\paragraph{Logistic regression.} Logistic regression is like a linear regression for classification, so it is more suitable for our task. For adjusting the model for various classes, we will minimize the multinomial logistic regression loss \\cite{bishop2006pattern}:\n    \\[- \\sum_{n=1}^N \\sum_{k=1}^K y_{nk} \\ln p_{nk},\\]                  \n    $y_{nk}$ indicating that the sample $n$ belongs to class $k$, $p_{nk}$ the estimated probability of sample $n$ belonging to class $k$ (calculated with softmax of linear functions of $X_n$). We also experiment with $\\ell^2$ regularization, with hyperparameter chosen by cross-validation.\n\n    \\paragraph{Linear discriminant analysis.} Linear discriminant analysis fits a probability distribution for each class, considering the priori as the proportion of that class in the data and the distribution of data, given the class, as a multivariate Gaussian. The decision boundary is linear, so we can also assert the \\textbf{linear separability} of the documents using this model.\n\n    \\paragraph{Random forest.} From the decision tree-based models, we experiment with random forests. Just like an ordinary decision tree, but many of them aggregated, each considering a bootstrap sample of the dataset and also a sample of the predictors. For a regression task, we have learned that, when the decision space is divided into various nodes, the output of the model is the mean of the samples inside that node.\n\n    It is natural to extend regression decision trees to classification decision trees. For example, with the already adjusted model, the predicted class is the class with more samples inside the node, and the probabilities are the class sample proportions.\n\n    There are some hyperparameters to be chosen, \\eg, depth of the trees and number of trees. These are chosen using cross-validation.\n\n    \\paragraph{Support vector machines.} Support vector machines (SVM) are very powerful, even having a simple mathematical formulation. Intuitively, they fit an optimal hyperplane dividing (a transformation of) the dataset, but also allowing some points to not obey this restriction. The optimization problem is:\n    \\[\\begin{aligned}\n        \\min_{w, b, \\zeta} \\quad & \\frac{1}{2}w^\\intercal w + C \\sum_{i = 1}^{N}{\\zeta_i} \\\\\n        \\textrm{s.t.} \\quad & y_i (w^\\intercal \\phi(x_i) + b) \\ge 1 - \\zeta_i \\\\\n        & \\zeta_i \\ge 0, \\ \\ i = 1, \\cdots, n. \\\\\n    \\end{aligned}\\]\n    The regularization $C$ parameter is chosen by cross-validation. The kernel function also is chosen by CV, between linear and radial basis function (RBF), so as the $\\gamma$ hyperparameter of RBF.\n", "meta": {"hexsha": "66d6cfce5e7b6068c145ee897bff0d4abd0b9029", "size": 6162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "a2_assignment/models.tex", "max_stars_repo_name": "lucasresck/machine-learning", "max_stars_repo_head_hexsha": "fd038632bf5c5d58a3e7ccf939b27b3d71ae648a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "a2_assignment/models.tex", "max_issues_repo_name": "lucasresck/machine-learning", "max_issues_repo_head_hexsha": "fd038632bf5c5d58a3e7ccf939b27b3d71ae648a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "a2_assignment/models.tex", "max_forks_repo_name": "lucasresck/machine-learning", "max_forks_repo_head_hexsha": "fd038632bf5c5d58a3e7ccf939b27b3d71ae648a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 128.375, "max_line_length": 457, "alphanum_fraction": 0.7583576761, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6817099943570661}}
{"text": "\\section{Scaling and Critical Phenomena}\nFree energy density is\n\\begin{align}\n    f\\left( t, h \\right)\n\\end{align}\nwhere $f=F/V$, $t=\\frac{|T - T_c|}{T_c}$ and $h$ is external field.\nThen the scaling hypothesis is\n\\begin{align}\n    f\\left( \\lambda^{u} t, \\lambda^{w} h \\right)\n    &=\n    \\lambda f\\left( t, h \\right)\n\\end{align}\nfor some scaling parameters $u,w$.\n\nFrom the scaling hypothesis you can drive these beautiful equalities\n\\begin{align}\n    \\alpha + \\beta\\left( \\delta + 1 \\right) &= 2\\\\\n    \\alpha + 2\\beta + \\gamma &= 2\n\\end{align}\nThey are called the Griffiths equality and Rushbrooke equality.\n", "meta": {"hexsha": "ae3577ff271fee63bb7b6f1f764fa8227e72c0c5", "size": 609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture34.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/lecture34.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/lecture34.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0, "max_line_length": 68, "alphanum_fraction": 0.6699507389, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701655, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6815924960691161}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Babylonian Method}\n\n\\objective{Graph and understand the slope of root functions.}\n\nSquare roots are useful whenever someone tell you the square footage of an area.  If it \nwere a square, how long would each side be?  Cube roots are similar for volume. \n\nDealing with square roots without calculator can be rather intimidating.  But it doesn't have\nto be.  3,000 years ago, the Babylonians found a method that truly repays the effort put into it:\neach iteration double the number of digits in the estimate!  Few formula converge so quickly.\n\nThe square root of $A$:\n\n$R_{n+1}=\\cfrac{R_n + \\frac{A}{R_n}}{2}$\n\nIn short:\n\\begin{enumerate}\n\\item Pick the best number you can.\n\\item Divide the original by ``the number''\n\\item Average the answer with ``the number''\n\\item Return to step 2 with this as ``the number''\n\\end{enumerate}\n\n\n\\subsection{Even vs. Odd}\nOK, so you found the square or cube root of some number to as many decimal places as\nyou need.  Rather than doing \\emph{that} more than once, wouldn't it be preferable to find\nout how much adding to the inside of a square root changes the output?  In other words,\nwhat is the rate of change, or the derivative?\n\nYou will need to multiply top and bottom of the difference quotient by the conjugate of the\nnumerator.\n\n\n\\begin{example}\n\\exProblem\nA woman rode a train where the cost of train ride is directly proportional to the square \nroot of the distance ridden.  Her ticket to ride 140 miles cost \\$24.40.  \nFind the final per mile rate of a man who got off after 35 miles, \ncompared the woman's final rate.\n\n\\exSolution\nDirectly proportional means we can set up an equation $c = k \\sqrt{d}$, where $c$ and $d$\nare the cost and distance.  If $24.4 = k\\sqrt{140}$ then $k=\\frac{24.4}{\\sqrt{140}}$.  The\nderivative of $\\frac{24.4}{\\sqrt{140}}\\sqrt{x} = \\frac{12.2}{\\sqrt{140x}}$.  At 35, the\nderivative is equal to $\\frac{24.4}{sqrt{140}} \\approx 0.17$, and at 140 it is \n$\\frac{12.2}{\\sqrt{140}} \\approx 0.09$.  This means the woman exited paying over\n\\$0.08 less per mile than the man.\n\\end{example}\n\n~\\vfill\n", "meta": {"hexsha": "9b63b429925492d3622717c292d3841bce2187b1", "size": 2105, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/0304.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/0304.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/0304.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": 38.9814814815, "max_line_length": 97, "alphanum_fraction": 0.7325415677, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.6815924071206129}}
{"text": "\\subsection{One-Parameter Subgroups and the Exponential Map}\n\n\\subsubsection{One-Parameter Subgroups}\n\n\\begin{theorem}[20.1]\\textbf{(Characterizations of One-Parameter Subgroups)}\n\\end{theorem}\n\n\n\\begin{proposition}[20.8] \\textbf{(Properties of Exponential Map)} Let $\\begin{aligned} & \\quad \\\\ \n    & G \\quad \\, & \\text{ Lie group } \\\\\n    & \\mathfrak{g} \\quad \\, & \\text{ Lie algebra } \\end{aligned}$\n\n\\begin{enumerate}\n\\item[(a)] $\\exp: \\mathfrak{g} \\to g$ smooth\n\\item[(b)] $\\forall \\, X \\in \\mathfrak{g}$, $s,t\\in \\mathbb{R}$, $\\exp{(s+t)}X = \\exp{sX}\\exp{tX}$\n\\item[(c)] $\\forall \\, X \\in \\mathfrak{g}$, $(\\exp{X})^{-1} = \\exp{(-X)}$\n\\item[(d)] $\\forall \\, X \\in \\mathfrak{g}$, $n\\in \\mathbb{Z}$, $(\\exp{X})^n = \\exp{(nX)}$\n\\item[(e)] differential $(d\\exp)_0:T_0\\mathfrak{g} \\to T_eG$ is identity, under canonical identifications of both $T_0\\mathfrak{g}$ and $T_eG$ with $\\mathfrak{g}$ itself.\n\\item[(f)] $\\exp$ restricts to diffeomorphism from some neighborhood of $0$ in $\\mathfrak{g}$ to neighborhood of $e$ in $G$.  \n\\item[(g)] if $\\Phi:G\\to H$ lie group homomorphism, following commutes\n\n\n\n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=3em, column sep=2em, minimum width=1em]\n  {\n \\mathfrak{g}  &   \\mathfrak{h}      \\\\\nG     &   H   \\\\ };\n%  \\path[-stealth]\n\\path[->]\n  (m-1-1) edge node [above] {$\\Phi_*$} (m-1-2)\nedge node [left] {$\\exp$} (m-2-1)\n(m-1-2) edge node [auto] {$\\exp$} (m-2-2)\n  (m-2-1) edge node [auto] {$\\Phi$} (m-2-2);\n\\end{tikzpicture}\n\n\\item[(h)] flow $\\theta$ of left-invariant vector field $X$, $\\theta_t = R_{\\exp{tX}}$\n\\end{enumerate}\n\\end{proposition}\n\n\\begin{proof}\n\\begin{enumerate}\n\\item[(a)]\n\\item[(b)]\n\\item[(c)]\n\\item[(d)]\n\\item[(e)] Let $X\\in \\mathfrak{g}$ arbitrary, let $\\begin{aligned} & \\quad \\\\ \n  & \\sigma: \\mathbb{R} \\to \\mathfrak{g} \\\\\n  & \\sigma(t) = tX \\\\\n  & \\dot{\\sigma}(0) = X \\end{aligned}$\n\n\n\n\n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=3em, column sep=2em, minimum width=1em]\n  {\n \\mathfrak{g}  &   G      \\\\\nT_0\\mathfrak{g}     &   T_eG   \\\\ };\n%  \\path[-stealth]\n\\path[->]\n  (m-1-1) edge node [above] {$\\exp$} (m-1-2)\nedge node [left] {$$} (m-2-1)\n(m-1-2) edge node [auto] {$(d\\exp)_0$} (m-2-2)\n  (m-2-1) edge node [auto] {$$} (m-2-2);\n\\end{tikzpicture}\n\n\\[\n(d\\exp )_0(X) = (d\\exp )_0(\\dot{\\sigma}(0)) = (\\exp \\circ \\sigma)'(0) = (\\exp{ (tX)})'(0) = \\left. \\frac{d}{dt} \\right|_{t=0} \\exp{ (tX)}= X\n\\]\n\\item[(f)] $(d\\exp )_0 =1$ and so by inverse function thm., $\\exists \\, (d\\exp)_0^{-1}=1^{-1}=1$, and so $\\begin{aligned} & \\quad \\\\\n  & U \\ni 0 \\\\\n  & U \\subseteq \\mathfrak{g} \\end{aligned} \\xrightarrow{ \\simeq } \\begin{aligned} & \\quad \\\\ \n  & V \\ni e \\\\\n  & V \\subseteq G \\end{aligned}$\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\\end{proof}\n", "meta": {"hexsha": "1d19d48227fa144844ee499d99e6634744489276", "size": 2732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LeeJM/20ExponentialMap.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/20ExponentialMap.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/20ExponentialMap.tex", "max_forks_repo_name": "wacfeldwang333/mathphysics", "max_forks_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2018-01-21T05:33:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T20:15:13.000Z", "avg_line_length": 31.4022988506, "max_line_length": 170, "alphanum_fraction": 0.5845534407, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6815924053377573}}
{"text": "\\section{Finite types}\n\n\\subsection{The pigeonhole principle}\n\nThe pigeonhole principle states that if we place more than $n$ balls in $n$ bags, then at least one bag will contain more than one ball. In this section we will give a type theoretical proof of the pigeonhole principle.\n\nFirst we give a definition of a function that counts the number of elements in a decidable subset of $\\Fin(n)$.\n\n\\begin{defn}\n  Let $P$ be a decidable subset of $\\Fin(n)$. We define the number $|P|:\\N$ of elements in $P$.\n\\end{defn}\n\n\\begin{proof}[Construction]\n  We give the construction of $|P|$ by induction on $n:\\N$. In the base case we note that $\\Fin(\\zeroN)$ has no elements, so we define $|P|\\defeq\\zeroN$.\n\n  For the inductive step, we define $|P|$ by case analysis on $P(\\inr(\\ttt))+\\neg P(\\inr(\\ttt))$. Let $P'$ be the family over $\\Fin(n)$ given by $P'(i)\\defeq P(\\inl(i))$. In the case where $P(\\inr(\\ttt))$ holds, then we define $|P|\\defeq \\succN |P'|$. In the case where $P(\\inr(\\ttt))$ doesn't hold we define $|P|\\defeq |P'|$.\n\\end{proof}\n\n\\begin{defn}\n  For any $i:\\Fin(\\succN(n))$ we define a function\n  \\begin{equation*}\n    \\skipFin(i):\\Fin(n)\\to\\Fin(\\succN(n)).\n  \\end{equation*}\n\\end{defn}\n\n\\begin{proof}[Construction]\n  The function $\\skipFin(i)$ is defined by induction on $n:\\N$. In the base case, the function\n  \\begin{equation*}\n    \\skipFin(i):\\Fin(\\zeroN)\\to\\Fin(\\succN(\\zeroN))\n  \\end{equation*}\n  is defined to be the unique map out of the empty type. In the successor case we define\n  \\begin{equation*}\n    \\skipFin(i) : \\Fin(\\succN(n))\\to\\Fin(\\succN(\\succN(n))) \n  \\end{equation*}\n  by induction on $i:\\Fin(\\succN(\\succN(n)))$. The function\n  \\begin{equation*}\n    \\skipFin(\\inl(i)):\\Fin(\\succN(n))\\to\\Fin(\\succN(\\succN(n)))\n  \\end{equation*}\n  is a map between coproducts, so it can be defined using the functorial action of coproducts of \\cref{ex:coproduct_functor}. We take\n  \\begin{equation*}\n    \\skipFin(\\inl(i))\\defeq \\skipFin(i)+\\idfunc.\n  \\end{equation*}\n  The function \n  \\begin{equation*}\n    \\skipFin(\\inr(i)):\\Fin(\\succN(n))\\to\\Fin(\\succN(\\succN(n)))\n  \\end{equation*}\n  is just the function $\\inl$.\n\\end{proof}\n\n\\begin{lem}\n  For each $i:\\Fin(\\succN(n))$, the function\n  \\begin{equation*}\n    \\skipFin(i):\\Fin(n)\\to\\Fin(\\succN(n))\n  \\end{equation*}\n  is an embedding.\n\\end{lem}\n\n\\begin{proof}\n  This assertion is proven by induction on $n$. In the base case, we note that any map out of the empty type is an embedding, by \\cref{ex:is-emb-empty}. In the inductive step we proceed by case analysis on $i:\\Fin(\\succN(\\succN(n)))$. In the case of $\\inl(i)$ we note that\n  \\begin{equation*}\n    \\skipFin(\\inl(i))\\jdeq \\skipFin(i)+\\idfunc\n  \\end{equation*}\n  is the functorial action of coproducts on two embeddings. Therefore we conclude by \\cref{ex:is-emb-coprod} that this map is an embedding. In the case of $\\inr(i)$ we note that $\\inl$ is an embedding by \\cref{ex:is-emb-inl-inr}.\n\\end{proof}\n\n\\begin{lem}\n  Consider a map $g:\\Fin(m)\\to\\Fin(\\succN(n))$. Furthermore, suppose that $i:\\Fin(\\succN(n))$ is not in the image of $g$, i.e.~that $\\neg(\\fib{g}{i})$. Then we can construct a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & \\Fin(n) \\arrow[d,\"\\skipFin(i)\"] \\\\\n      \\Fin(m) \\arrow[r,swap,\"g\"] \\arrow[ur,densely dotted,\"f\"] & \\Fin(\\succN(n)).\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{lem}\n\nFinally, we prove the pigeonhole principle.\n\n\\begin{thm}\\label{thm:pigeonhole}\n  For any $m,n:\\N$ and any function $f:\\Fin(m)\\to\\Fin(n)$, if $m>n$, then there is an $i:\\Fin(n)$ which is in the image of more than one point in $\\Fin(m)$.\n\\end{thm}\n\n\\begin{proof}\n  The pigeonhole principle is proven by induction on $m,n:\\N$. In the base case for $m$ there is nothing to show because $m>n$ is empty. For the inductive step on $m$ and the base case for $n$, we note that $\\Fin(\\succN(m))\\jdeq \\Fin(m)+\\unit$ and $\\Fin(\\zeroN)\\jdeq \\emptyt$. Therefore $f:\\Fin(\\succN(m))\\to\\Fin(\\zeroN)$ is a function from a pointed type to the empty type, which gives us a contradiction.\n\n  It remains to give the inductive step for $n$. Let $i\\defeq f(\\inr(\\ttt)):\\Fin(\\succN(n))$. Since the ordering relation $<$ on $\\N$ is decidable, we can decide whether $i$ is in the image of more than one point in $\\Fin(m)$ by deciding whether or not $1<|P|$ holds for\n  \\begin{equation*}\n    P(j)\\defeq (f(j)=i)\n  \\end{equation*}\n  If this is the case, this completes the proof.\n\n  Now suppose that $1\\not<|P|$. Since $P(\\inr(\\ttt))$ holds it follows that $|P|=1$. Now we observe that $i$ is not in the image of $f\\circ \\inl$. Therefore we obtain a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\Fin(m) \\arrow[r,densely dotted,\"{f'}\"] \\arrow[d,swap,\"\\inl\"] & \\Fin(n) \\arrow[d,\"{\\skipFin(i)}\"] \\\\\n      \\Fin(\\succN(m)) \\arrow[r,swap,\"f\"] & \\Fin(\\succN(n)).\n    \\end{tikzcd}\n  \\end{equation*}\n\n  Note that the induction hypothesis the pigeonhole principle applies to the function $f':\\Fin(m)\\to\\Fin(n)$. Since $m>n$ it follows that there is an element $j:\\Fin(n)$ that is in the image of $f'$ of more than one element of $\\Fin(m)$. Now we observe that there is an equivalence\n  \\begin{equation*}\n    \\fib{f'}{j}\\simeq \\fib{f}{\\skipFin(i,j)}\n  \\end{equation*}\n  because both the left and right maps in the commuting square are embeddings. Therefore we conclude that $\\skipFin(i,j)$ is in the image of $f$ of more than one element of $\\Fin(\\succN(m))$. \n \\end{proof}\n\n\\begin{cor}\\label{cor:pigeonhole}\n  Given $m>n$, no function $\\Fin(m)\\to\\Fin(n)$ is an embedding.\n\\end{cor}\n\nIt is straightforward to see that the statements of \\cref{thm:pigeonhole,cor:pigeonhole} are equivalent, and one might argue that the statement of \\cref{cor:pigeonhole} is the more `type theoretical way' of phrasing the pigeonhole principle. However, the relation to counting the number of points that get mapped to \n\n\\begin{thm}\\label{thm:generalized-pigeonhole}\n  For any $m,n:\\N$ and any function $f:\\Fin(m)\\to\\Fin(n)$, if $m>kn$ for some $k:\\N$, then there is an $i:\\Fin(n)$ which is in the image of more than $k$ points in $\\Fin(m)$. \n\\end{thm}", "meta": {"hexsha": "bd2011b63b0a7aebf84afecd99dbbf0d460c2d3a", "size": 6053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/finite-types.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/finite-types.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/finite-types.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 53.0964912281, "max_line_length": 406, "alphanum_fraction": 0.6735503056, "num_tokens": 2017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790619, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6815924035091997}}
{"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{fmhyp}\n\\section*{\\hspace*{-1.6cm} fmhyp}\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 hyperbolic frequency modulation or group delay law.\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] = fmhyp(N,P1)\n[x,iflaw] = fmhyp(N,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 fmhyp} generates a signal with a hyperbolic frequency\n        modulation\n\\[        x(t) = \\exp\\left(i2\\pi\\left(f_0 t +\n\\frac{c}{log|t|}\\right)\\right).\\]   \n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c} Name &\nDescription & Default value\\\\ \\hline {\\ty N} & number of points in time\\\\\n{\\ty P1} & if {\\ty nargin==2, P1} is a vector containing the two\ncoefficients {\\ty [f0 c]}.  If {\\ty nargin==3, P1} (as {\\ty P2}) is a\ntime-frequency point of the form {\\ty [ti fi]}. {\\ty ti} is in seconds and\n{\\ty fi} is a normalized frequency (between 0 and 0.5). The coefficients\n{\\ty f0} and {\\ty c} are then deduced such that the frequency modulation\nlaw fits the points {\\ty P1} and {\\ty P2}\\\\ {\\ty P2} & same as {\\ty P1} if\n{\\ty nargin==3} & optional\\\\ \\hline {\\ty x } & time row vector containing\nthe modulated signal samples \\\\ {\\ty iflaw} & instantaneous frequency law\\\\\n \n\\hline\n\\end{tabular*}\n\\end{minipage}\n\\vspace*{.5cm}\n \n{\\bf \\large \\sf Examples}\n\\begin{verbatim}\n         [X,iflaw]=fmhyp(100,[1 .5],[32 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}\nfmlin, fmsin, fmpar, fmconst, fmodany, fmpower.\n\\end{verbatim}\n\\end{minipage}\n\n\n", "meta": {"hexsha": "dfc4e20e4d8e554d39383c3152e870af4c9bb9d7", "size": 2031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/fmhyp.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/fmhyp.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/fmhyp.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.7236842105, "max_line_length": 75, "alphanum_fraction": 0.650418513, "num_tokens": 747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.6815923947777286}}
{"text": "\\chapter{Algebraic Integers}\n\t\\setcounter{page}{1}\n\t\\pagenumbering{arabic}\n\t\\section{Integral closure and algebraic integers}\n\t\t\\subsection{Definition and examples}\n\t\t\tProblems in solving polynomial equations give rise to a lot of concepts in algebra and geometry. If we are specifically interested in $\\mds{Z}$, we have the concept of \\textbf{algebraic integers}.\n\t\t\t\\begin{definition}\n\t\t\t\tA finite extension $K$ of the rational number $\\mds{Q}$ is called a \\textbf{number field}. The integral closure of $\\mds{Z}$ in $K$ is called the ring of \\textbf{algebraic integers} of $K$, and is denoted by $\\OK$. To be precise, every element $x \\in \\OK$ is a zero of a monic polynomial $f \\in \\Z[X].$\n\t\t\t\\end{definition}\n\t\t\t\n\t\t\tFor this concept we have a lot of classic examples:\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tIf $K=\\Q$, then $\\OK$ is simply $\\Z$. This is intuitive because suppose $x=a/b \\in \\Q$ is integral over $\\Z$ where $(a,b)=1$, then\n\t\t\t\t\\[\n\t\t\t\tx^n+c_1x^{n-1}+\\cdots+c_n = 0\n\t\t\t\t\\]\n\t\t\t\twhere $c_i \\in \\Z$. Multiplying by $b^n$ yields\n\t\t\t\t\\[\n\t\t\t\ta^n+c_1a^{n-1}b+\\cdots+c_nb = 0\n\t\t\t\t\\]\n\t\t\t\tHence $b$ divides $a^n$. But we also have $(a^n,b)=1$, hence $b=\\pm 1$, which is to say $x \\in \\Z$.\n\t\t\t\t\n\t\t\t\tThere is an more general setting. Since $\\Z$ is a unique factorial domain (UFD), and UFD is integrally closed \\href{https://proofwiki.org/wiki/Unique_Factorization_Domain_is_Integrally_Closed}{[proof]}, we have $\\Z=\\OK$. \n\t\t\t\\end{example}\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tThe Gaussian rational $\\Q(i)=K$. Indeed it is natural to consider Gaussian integer $\\Z[i]$ first. For any $z=m+ni \\in \\Z[i]$, we have\n\t\t\t\t\\[\n\t\t\t\tz^2-2mz+m^2+n^2=0\n\t\t\t\t\\]\n\t\t\t\tHence $\\Z[i] \\subset \\OK$. The converse is similar to our proof when $K=\\Q$.\n\t\t\t\\end{example}\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tCyclotomic field $K=Q(\\xi_n)$, where $\\xi_n$ is the root of $x^n-1$. In this case we have $\\OK = \\Z[\\xi_n]$.\n\t\t\t\\end{example}\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tQuadratic field $K=\\Q(\\sqrt{d})$, where $d$ is a square-free integer $>1$. This time the algebraic integer ring is different from what you may have thought: $\\OK = \\Z[\\omega]$ where\n\t\t\t\t\\[\n\t\t\t\t\\omega = \\begin{cases}\n\t\t\t\t\t\\frac{1+\\sqrt{d}}{2}, &\\quad d = 4k+1, \\\\\n\t\t\t\t\t\\sqrt{d}, &\\quad \\text{otherwise}.\n\t\t\t\t\\end{cases}\n\t\t\t\t\\]\n\t\t\t\\end{example}\n\t\t\tIt turns out we are studying polynomials such as\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $x^2+1=0$.\n\t\t\t\t\\item $x^n-1=0$.\n\t\t\t\t\\item $x^2-d=0$.\n\t\t\t\\end{itemize}\n\t\tIt also turns out that many properties are not restricted to $\\Z$, but to a specific class of rings. Hence we will investigate some properties in the sense of commutative ring theory.\n\t\t\\subsection{Algebraic extension and integral closure}\n\t\t\tFirst of all we show that being algebraic almost implies being integral. \n\t\t\t\\begin{lemma}\\label{alg-int}\n\t\t\t\tLet $A$ be a domain, $K$ its quotient field, and $x$ algebraic over $K$. Then there exists an element $c \\ne 0$ of $A$ such that $cx$ is integral over $A$.\n\t\t\t\\end{lemma}\n\t\t\t\\begin{proof}\n\t\t\t\tSince $x$ is algebraic, we have an equation\n\t\t\t\t\\[\n\t\t\t\t\ta_nx^n+\\cdots+a_0=0\n\t\t\t\t\\]\n\t\t\t\twith $a_i \\in A$ and $a_n \\ne 0$. Hence\n\t\t\t\t\\[\n\t\t\t\t\ta_n^{n-1}(a_nx^n+\\cdots+a_0)=(a_nx)^n+\\cdots+a_0a_n^{n-1}=0\n\t\t\t\t\\]\n\t\t\t\twhich is to say $a_nx$ is integral over $A$. \n\t\t\t\\end{proof}\n\t\t\t\n\t\t\tSince finite extensions are algebraic, we are always free to use this lemma for the topic of number field.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{closure-f-g}\n\t\t\t\tLet $A$ be an integrally closed Noetherian ring. Let $L$ be a finite separable extension of its quotient field $K$. Then the integral closure of $A$ in $L$ is finitely generated over $A$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tSince $A$ is Noetherian, all submodules of a finitely generated module over $A$ is finitely generated. Hence it suffices to prove that the integral closure of $A$ is contained in a finitely generated $A$-module.\\\\\n\t\t\t\tLet $w_1,\\dots,w_n$ be a basis of $L$ over $K$. After multiplying each $w_i$ by some suitable element of $A$ (see lemma \\ref{alg-int}), we may assume without loss of generality that the $w_i$ are integral over $A$. To study the integral closure of $A$ in $L$, we pick an arbitrary element $z = b_1w_1+\\cdots+b_nw_n$ and study its coefficients. \\\\\n\t\t\t\tSince $L/K$ is separable, the \\href{https://stacks.math.columbia.edu/tag/0BIF}{field trace} form\n\t\t\t\t\\[\n\t\t\t\t\tQ_{L/K}:L \\times L \\to K, \\quad (x,y) \\mapsto \\tr_{L/K}(xy)\n\t\t\t\t\\]\n\t\t\t\tis non-degenerate  \\href{https://stacks.math.columbia.edu/tag/0BIL}{[proof]}, so we claim that $L^\\ast$ is isomorphic to $L$ under $Q_{L/K}$. Indeed, one can define a $K$-linear map\n\t\t\t\t\\[\n\t\t\t\t\td:L \\to L^\\ast, \\quad x \\mapsto (y \\mapsto Q_{L/K}(x,y)=\\tr(xy)).\n\t\t\t\t\\]\n\t\t\t\tThis map is injective because $Q_{L/K}$ is non-degenerate. Since $L$ and $L^\\ast$ has the same dimension, $d$ has to be surjective.\\\\\n\t\t\t\tLet $w^1,\\dots,w^n$ be the dual basis of $w_1,\\dots,w_n$. If we put $v_i=d^{-1}(w^i)$, we have\n\t\t\t\t\\[\n\t\t\t\t\t\\tr(v_i w_j) = \\delta_{ij}.\n\t\t\t\t\\]\n\t\t\t\tLet $c \\ne 0$ be an element of $A$ such that $cv_i$ is integral over $A$, then $cv_iz$ is integral and so is $\\tr(cv_iz)$. Since $\\tr$ is a $K$-valued function, we have\n\t\t\t\t\\[\n\t\t\t\t\t\\tr(czv_i)=c\\tr(v_iz)=c d(v_i)(z) = cb_i \\in A \\implies b_i \\in Ac^{-1}.\n\t\t\t\t\\]\n\t\t\t\tHence\n\t\t\t\t\\[\n\t\t\t\t\tz \\in Ac^{-1}w_1+\\cdots+Ac^{-1}w_n\n\t\t\t\t\\]\n\t\t\t\twhich is to say $z$ is finitely generated. Since $z$ is arbitrarily picked, the closure itself is contained in a finitely generated $A$-module, which finishes the proof. \n\t\t\t\\end{proof}\n\t\t\tNote $Z$ is itself a Noetherian ring and integrally closed. $\\Q$ is the fraction ring of $\\Z$, and finite extensions of $\\Q$ are always separable. It follows (non-trivially) that\n\t\t\t\\begin{corollary}\n\t\t\t\t$\\OK$ is finitely generated over $\\Z$.\n\t\t\t\\end{corollary}\n\t\t\t\n\t\t\tNext we study the rank of $\\OK$ over $\\Z$. Being finitely generated is not exactly what we want.\n\t\t\t\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A$ be a principal ideal ring, and $L$ a finite separable extension of its quotient field $K$, of degree $n$. Let $B$ be the integral closure of $A$ in $L$. Then $B$ is a free module of rank $n$ over $A$. \n\t\t\t\\end{theorem}\n\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tSince $A$ is contained in $K$, $B$ is contained in $L$, whenever $ab=0$ with $a \\in A$, $b \\in B$, we have $a=0$ or $b=0$. Hence $B$ is torsion-free. Therefore as a finitely generated (theorem \\ref{closure-f-g}) torsion-free module, $B$ is a free module over $A$ \\href{http://du.ac.in/du/uploads/departments/mathematics/study-material/MMATH18-201\\%20_MT_PID.pdf}{[Theorem 2.7]}. Since $L$ is a $n$-dimensional vector space over $K$, for $y \\in L$ we have\n\t\t\t\t\\[\n\t\t\t\t\ty = c_1e_1+\\cdots+c_ne_n\n\t\t\t\t\\]\n\t\t\t\twhere $e_1,\\dots,e_n$ is a basis and $c_1,\\cdots,c_n \\in K$. When $y \\in B$, we must have $c_1,\\cdots,c_n \\in A$, which is to say $B$ has rank $[L:K]=n$.\n\t\t\t\\end{proof}\n\t\t\tHence the rank of $\\OK$ over $\\Z$ is determined by $[K:\\Q]$.\n\t\t\n\t\t\\subsection{Localisation}\n\t\t\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A \\subset B$ be rings, and $S$ a multiplicatively closed subset of $A$. If $B$ is integral over $A$, then $S^{-1}B$ is integrally closed in $S^{-1}A$. If $C$ is the integral closure of $A$ in $B$, then $S^{-1}C$ is the integral closure of $S^{-1}A$. \n\t\t\t\\end{theorem}\n\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tFirst we assume $B$ is integral over $A$. Pick $x/s \\in S^{-1}B$ with $x \\in B$ and $s \\in S$. By definition we have\n\t\t\t\t\\[\n\t\t\t\t\tx^n + a_1x^{n-1}+\\cdots + a_n = 0\n\t\t\t\t\\]\n\t\t\t\twith $a_i \\in A$. Multiplying by $(1/s)^n$ gives\n\t\t\t\t\\[\n\t\t\t\t\t(x/s)^n + (a_1/s)(x/s)^{n-1}+\\cdots+a_n/s^n = 0\n\t\t\t\t\\]\n\t\t\t\twhich shows that $x/s$ is integral over $S^{-1}A$. Hence the first statement is proved. \\\\\n\t\t\t\tNow we assume $C$ is the integral closure of $A$ in $B$. By the first statement we see $S^{-1}C$ is integral over $S^{-1}A$. Suppose $b/s \\in S^{-1}B$ is integral over $S^{-1}A$, we have an equation of the form\n\t\t\t\t\\[\n\t\t\t\t\t(b/s)^n+(a_1/s_1)(b/s)^{n-1}+\\cdots+a_n/s_n=0.\n\t\t\t\t\\]\n\t\t\t\tMultiplying by $(st)^n$ where $t=s_1\\cdots s_n$ gives an equation of integral independence for $bt$ over $A$. Hence $bt \\in C$. But $b/s = bt/st$, hence $b/s \\in S^{-1}C$ and we are done. \n\t\t\t\\end{proof}\n\t\t\n\t\t\tIf $S$ happens to be a complement of a prime ideal $\\mfk{p}$, we have a satisfying result\n\t\t\t\n\t\t\t\\begin{corollary}\\label{int-loc}\n\t\t\t\tIf $B$ is integral over $A$, then $B_\\mfk{p}$ is integral over $A_\\mfk{p}$.\n\t\t\t\\end{corollary}\n\t\t\t\n\t\t\tIf $B$ is replaced by a field extension $L$ of the quotient field of $A$, and $C$ is replaced by the integral closure of $A$, we have the following corollary:\n\t\t\t\n\t\t\t\\begin{corollary}\n\t\t\t\tIf $B$ is the integral closure of $A$ in some field extension $L$ of the quotient field of $A$, then $S^{-1}B$ is the integral closure of $S^{-1}A$ in $L$.\n\t\t\t\\end{corollary}\n\t\t\t\n\t\t\t% TODO: ADD SOME EXAMPLES\n\t\t\\subsection{Prime Ideals}\n\t\t\tBy theorem \\ref{closure-f-g}, $\\OK$ is a finitely-generated $\\Z$-module, hence is a Noetherian domain. By transitivity of integral closures, $\\OK$ is integrally closed. We are now interested in the Krull dimension of $\\OK$. To do this, we investigate more of the prime ideal with respect to integral closure. \n\t\t\t\\begin{definition}\n\t\t\t\tLet $B$ be a ring containing a ring $A$. Let $\\mfk{p}$ be a prime ideal of $A$ and $\\mfk{P}$ a prime ideal of $B$. We say that $\\mfk{P}$ \\textbf{lies above} $\\mfk{p}$ if $\\mfk{P} \\cap A = \\mfk{p}$ and we then write $\\mfk{P}|\\mfk{p}$.\n\t\t\t\\end{definition}\n\t\t\t\n\t\t\tIf $\\mfk{P}|\\mfk{p}$, we have a commutative diagram:\n\t\t\t\\[\n\t\t\t\\begin{tikzcd}\n\t\t\t\tB \\arrow[r, \"\\pi'\"]               & B/\\mathfrak{P}                  \\\\\n\t\t\t\tA \\arrow[r, \"\\pi\"] \\arrow[u, \"i\"] & A/\\mathfrak{p} \\arrow[u, \"i'\"']\n\t\t\t\\end{tikzcd}\n\t\t\t\\]\n\t\t\twhere $i$ and $i'$ are inclusions, $\\pi$ and $\\pi'$ are canonical homomorphisms. \\\\\n\t\t\tIf $B$ is integral over $A$, then $B/\\mfk{P}$ is integral over $A/\\mfk{p}$, this is because of the following lemma if we take $\\sigma$ to be $\\pi$:\n\t\t\t\\begin{lemma}\n\t\t\t\tLet $A \\subset B$ be rings, and $\\sigma:B \\to C$ be a homomorphism. If $B$ is integral over $A$, then $\\sigma(B)$ is integral over $\\sigma(A)$.\n\t\t\t\\end{lemma}\n\t\t\t\\begin{proof}\n\t\t\t\tIf $B$ is integral over $A$, then for any $x \\in B$ there is an equation\n\t\t\t\t\\[\n\t\t\t\tx^n + a_{n-1}x^{n-1}+\\cdots+a_0 = 0.\n\t\t\t\t\\]\n\t\t\t\tTherefore\n\t\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\sigma(x^n+a_{n-1}x^{n-1}+\\cdots+a_0) &= \\sigma(x^n)+\\sigma(a_{n-1}x^{n-1})+\\cdots+\\sigma(a_0) \\\\\n\t\t\t\t\t&= \\sigma(x)^n + \\sigma(a_{n-1})\\sigma(x)^{n-1}+\\cdots+\\sigma(\\sigma) \\\\\n\t\t\t\t\t&= 0.\n\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tHence $\\sigma(x)$ is integral in $\\sigma(A)$.\n\t\t\t\\end{proof}\n\t\t\t\n\t\t\tWe want to show that prime ideals of $\\OK$ is maximal, and they should be corresponded to prime ideals in $\\Z$, which is maximal. For this reason we show the existence of lying-above prime ideals.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{lying-above}\n\t\t\t\tLet $A$ be a ring, $\\mfk{p}$ a prime ideal, and $B \\supset A$ integral over $A$. Then $\\mfk{p}B \\ne B$, and there exists a prime ideal $\\mfk{P}$ of $B$ lying above $\\mfk{p}$. \n\t\t\t\\end{theorem}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tWe know that $B_\\mfk{p}$ is integral over $A_\\mfk{p}$ (corollary \\ref{int-loc}) and that $A_\\mfk{p}$ is local with maximal ideal $\\mfk{m}_\\mfk{p}=\\mfk{p}A_\\mfk{p}$. It follows that\n\t\t\t\t\\[\n\t\t\t\t\\mfk{p}B_\\mfk{p}=\\mfk{p}A_\\mfk{p}B = \\mfk{p}A_\\mfk{p}B_\\mfk{p}=\\mfk{m}_\\mfk{p}B_\\mfk{p}.\n\t\t\t\t\\]\n\t\t\t\tHence it suffices to prove our assertion when $A$ is local. If $\\mfk{p}B=B$, we have an equation\n\t\t\t\t\\[\n\t\t\t\t1 = a_1b_1+\\cdots+a_nb_n\n\t\t\t\t\\]\n\t\t\t\twith $a_i \\in \\mfk{p}$ and $b_i \\in B$. Let $B_0 = A[b_1,\\cdots,b_n]$. Then $\\mfk{p}B_0=B_0$ and $B_0$ is a finitely generated $A$-module. Hence by Nakayama's lemma, $B_0=0$, which is absurd.\n\t\t\t\t\n\t\t\t\tTo prove the existence of $\\mfk{P}$, consider the following commutative diagram:\n\t\t\t\t\\[\n\t\t\t\t\\begin{tikzcd}\n\t\t\t\t\tB \\arrow[r]           & B_\\mathfrak{p}           \\\\\n\t\t\t\t\tA \\arrow[r] \\arrow[u] & A_\\mathfrak{p} \\arrow[u]\n\t\t\t\t\\end{tikzcd}\n\t\t\t\t\\]\n\t\t\t\twhere all arrows are natural inclusions. As is proved, $\\mfk{m}_\\mfk{p}B_\\mfk{p} \\ne B_\\mfk{p}$. Hence $\\mfk{m}_\\mfk{p}B_\\mfk{p}$ is contained in a maximal ideal $\\mfk{M}$ of $\\mfk{p}$, and therefore $\\mfk{M} \\cap A_\\mfk{p}$ contains $\\mfk{m}_\\mfk{p}$. And we pick $\\mfk{P}=\\mfk{M} \\cap B$. Then $\\mfk{P}$ is a prime ideal of $B$, and taking intersection with $A$ going both ways around our diagram shows that $\\mfk{M} \\cap A = \\mfk{p}$, so that\n\t\t\t\t\\[\n\t\t\t\t\\mfk{P} \\cap A = \\mfk{p},\n\t\t\t\t\\]\n\t\t\t\tas was to be shown.\n\t\t\t\\end{proof}\n\t\t\t\n\t\t\tNow we proceed to the crucial theorem to determine whether a prime lying above is maximal.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{lie-above-maximal}\n\t\t\t\tLet $A$ be a subring of $B$, and assume $B$ is integral over $A$. Let $\\mfk{P}$ be a prime ideal of $B$ lying over a prime ideal $\\mfk{p}$ of $A$. Then $\\mfk{P}$ is maximal $\\iff$ $\\mfk{p}$ is maximal.\n\t\t\t\\end{theorem}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\t$\\implies$: Note $B/\\mfk{P}$ is a field and is integral over the ring $A/\\mfk{p}$. Were $A/\\mfk{p}$ not a field, there would be a non-trivial ideal $\\mfk{m}$ of it, and $B/\\mfk{P}$ would have a prime ideal $\\mfk{M}$ lying above $\\mfk{m}$, by theorem \\ref{lying-above}. A contradiction. \\\\\n\t\t\t\t$\\impliedby$: Note $A/\\mfk{p}$ is a field. It suffices to prove that a ring $R$ which is integral over a field $k$ is a field. If $k$ is a field and non-zero $x \\in R$ is integral over $k$, we have a minimal polynomial\n\t\t\t\t\\[\n\t\t\t\tx^n+c_{n-1}y^{n-1}+\\cdots+c_0=0\n\t\t\t\t\\]\n\t\t\t\twith $c_i \\in k$. Since $R$ is integral, we have $c_0 \\ne 0$. We can clearly write\n\t\t\t\t\\[\n\t\t\t\tx^{-1}=-c_0^{-1}(x^{n-1}+c_{n-1}y_{n-2}+\\cdots+c_1) \\in R,\n\t\t\t\t\\]\n\t\t\t\twhich is to say $R$ is integral, and the theorem is therefore proved.\n\t\t\t\\end{proof}\n\t\t\tWith respect to localisation, we can show the stability of prime ideals lying above:\n\t\t\t\\begin{corollary}\n\t\t\t\tLet $A \\subset B$ be rings, $B$ integral over $A$; Let $\\mfk{P}$ and $\\mfk{P}'$ be prime ideals of $B$ such that $\\mfk{P} \\subset \\mfk{P}'$ and both $\\mfk{P}$ and $\\mfk{P}'$ lie above a prime ideal $\\mfk{p}$ of $A$, then $\\mfk{P}=\\mfk{P}'$. \n\t\t\t\\end{corollary}\n\t\t\t\\begin{proof}\n\t\t\t\tBy corollary \\ref{int-loc}, $B_\\mfk{p}$ is integral over $A_\\mfk{p}$. Let $\\mfk{m}$ be the extension of $\\mfk{p}$ in $A_\\mfk{p}$ and $\\mfk{M},\\mfk{M}'$ be the extensions of $\\mfk{P}$ and $\\mfk{P}'$ respectively in $B_\\mfk{p}$. Then $\\mfk{m}$ is the maximal ideal of $A_\\mfk{p}$; $\\mfk{M} \\subset \\mfk{M}'$, and $\\mfk{M}$, $\\mfk{M}'$ lies above $\\mfk{m}$. Hence by theorem \\ref{lie-above-maximal}, $\\mfk{M}$ and $\\mfk{M}'$ are both maximal, hence equal. This reduces to $\\mfk{P}=\\mfk{P}'$.\n\t\t\t\\end{proof}\n\t\t\tAnd now we are ready to prove that $\\OK$ is Dedekind.\n\t\t\t\n\t\t\t\\begin{theorem}\\label{o_k-dedekind}\n\t\t\t\tEvery prime ideal $\\mfk{P}$ in $\\OK$ is maximal. Hence $\\OK$ is of Krull dimension $1$ and is therefore Dedekind.\n\t\t\t\\end{theorem}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\t\tNote it suffices to prove that every prime ideal $\\mfk{P}$ of $\\OK$ lies above some prime ideal of $\\Z$, since $\\Z$ has Krull dimension $1$, and the proof follows from theorem \\ref{lie-above-maximal}. All we need to do is to prove that $\\mfk{P} \\cap \\Z$ is non-zero: since the inverse image of a prime ideal is prime, we are done. For each $x \\in \\mfk{P}$, we have a minimal polynomial $f \\in \\Z[X]$ such that\n\t\t\t\t\\[\n\t\t\t\tf(x) = x^n+c_{n-1}x^{n-1}+\\cdots+c_0=0\n\t\t\t\t\\]\n\t\t\t\twith $c_i \\in \\Z$ and $c_0 \\ne 0$. It follows that\n\t\t\t\t\\[\n\t\t\t\tc_0=-(x^n+c_{n-1}x^{n-1}+\\cdots+c_1x) \\in \\mfk{P} \\cap \\Z,\n\t\t\t\t\\]\n\t\t\t\twhich is to say $\\mfk{P} \\cap \\Z$ is indeed non-zero. This concludes the proof.\n\t\t\t\\end{proof}\n\t\t\t\\begin{example}\n\t\t\t\tAs a classic example, consider $K=\\Q(\\sqrt{-5})$ and $\\OK = \\Z[\\sqrt{-5}]$. This ring is not a unique factorial domain because we have\n\t\t\t\t\\[\n\t\t\t\t6 = 2 \\cdot 3 = (1-\\sqrt{-5}) \\cdot (1+\\sqrt{-5}).\n\t\t\t\t\\]\n\t\t\t\tBut if we view in the sense of product of ideals, nothing goes wrong. Let $\\mfk{m}$ be the maximal ideal containing $6$, then\n\t\t\t\t\\[\n\t\t\t\t\\mfk{m} = (2,1-\\sqrt{-5})(2,1+\\sqrt{-5})\n\t\t\t\t\\]\n\t\t\t\tis unique. Note two ideals on the right hand side are indeed maximal (hence prime) because\n\t\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\frac{\\Z[\\sqrt{-5}]}{(2,1-\\sqrt{-5})} &\\cong \\frac{\\Z[X]/(X^2+5)}{(2,1-X,X^2+5)/(X^2+5)} \\\\\n\t\t\t\t\t&\\cong \\frac{\\Z[X]}{(2,1-X,X^2+5)} \\cong \\frac{\\Z_2[X]}{(1-X,X^2-1)} \\cong \\frac{\\Z_2[X]}{(1-X)} \\cong \\Z_2.\n\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tLikewise,\n\t\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\frac{\\Z[\\sqrt{-5}]}{(3,1+\\sqrt{-5})} &\\cong \\frac{\\Z[X]/(X^2+5)}{(3,1+X,X^2+5)/(X^2+5)} \\\\\n\t\t\t\t\t&\\cong \\frac{\\Z[X]}{(3,1+X,X^2+5)} \\cong \\frac{\\Z_3[X]}{(1+X,X^2-1)} \\cong \\frac{\\Z_3[X]}{(1+X)} \\cong \\Z_3.\n\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\\end{example}\n\t\\section{Galois extensions}\n\t\t\\subsection{Decomposition group and decomposition field}\n\t\t\tIf $K$ is a Galois extension of $\\Q$, then the Galois group allows us to transform amongst prime ideals in a natural way. This is because of the following theorem.\n\t\t\t\\[\n\t\t\t\t\\begin{tikzcd}\n\t\t\t\t\t\\mathfrak{P} \\arrow[rr, \"\\exists \\sigma \\in G\"] &                                    & \\mathfrak{Q} \\\\\n\t\t\t\t\t& \\mathfrak{p} \\arrow[lu] \\arrow[ru] &             \n\t\t\t\t\\end{tikzcd}\n\t\t\t\\]\n\t\t\t\\begin{theorem}\\label{galois-lie-above}\n\t\t\t\tLet $A$ be a ring, integrally closed in its quotient field $K$. Let $L$ be a finite Galois extension of $K$ with group $G$. Let $\\mfk{p}$ be a maximal ideal of $A$, and let $\\mfk{P}$, $\\mfk{Q}$ be prime ideals of the integral closure of $A$ in $L$ lying above $\\mfk{p}$. Then there exists $\\sigma \\in G$ such that $\\sigma\\mfk{P} = \\mfk{Q}$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tSuppose that $\\mfk{P}=\\sigma\\mfk{Q}$ for all $\\sigma \\in G$. By the Chinese remainder theorem, we have some $x \\in B$ such that \n\t\t\t\t\\[\n\t\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\tx &\\equiv 0 \\mod \\mfk{P} \\\\\n\t\t\t\t\t\tx &\\equiv 1 \\mod \\sigma\\mfk{Q}, \\quad \\forall \\sigma \\in G.\n\t\t\t\t\t\\end{aligned}\n\t\t\t\t\\]\n\t\t\t\tThen the norm\n\t\t\t\t\\[\n\t\t\t\t\tN_K^L(x) = \\prod_{\\sigma \\in G}\\sigma{x}\n\t\t\t\t\\]\n\t\t\t\tlies in $B \\cap K = A$ since $A$ is integrally closed, and lies in $\\mfk{P} \\cap A = \\mfk{p}=\\mfk{Q} \\cap A \\subset \\mfk{Q}$. But we also have $\\sigma{x} \\not\\in \\mfk{Q}$ for all $\\sigma \\in G$, hence $N_K^L(x) \\not \\in \\mfk{Q}$, a contradiction.\n\t\t\t\\end{proof}\n\t\t\tIf one localise, the consideration on whether a prime ideal is maximal is not required. Besides, if $A$ is of Krull dimension $1$, then one has no need to consider as well. Since we have shown that $\\OK$ is a Dedekind domain, this theorem can be applied as well. Next we show the finiteness of prime ideals lying above.\n\t\t\t\n\t\t\t\\begin{corollary} \n\t\t\t\tLet $A$ be an integrally closed domain whose field of fraction is $K$. Let $E$ be a finite separable extension of $K$, and $B$ the integral closure of $A$ in $E$. Let $\\mfk{p}$ be a maximal ideal of $A$. Then there exists only a finite number of prime ideals of $B$ lying above $\\mfk{p}$.\n\t\t\t\\end{corollary}\n\t\t\t\\begin{proof}\n\t\t\t\t If $E$ is Galois over $K$, then by theorem \\ref{galois-lie-above}, $\\sigma\\mfk{P}_1 = \\mfk{P}_2$ for some $\\sigma \\in \\gal(E/K)$. Suppose $\\mfk{P}_1|\\mfk{p}$, then the set of prime ideals lying above $\\mfk{p}$ is contained in the set\n\t\t\t\t\\[\n\t\t\t\t\t\\{\\mfk{Q} \\subset B: \\mfk{Q}=\\sigma\\mfk{P}_1,\\sigma\\in\\gal(E/K)\\},\n\t\t\t\t\\]\n\t\t\t\thence is finite because $\\gal(E/K)$ is finite. If $E$ is not necessarily Galois, we can pick the smallest Galois extension $L/K$ containing $E$, which is a finite extension as well. Let $C$ be the integral closure of $A$ in $L$. Suppose $\\mfk{P},\\mfk{Q} \\in \\spec(B)$ are two distinct prime ideals lying above $\\mfk{p}$, and $\\mfk{P}',\\mfk{Q}' \\in \\spec(C)$ lying above $\\mfk{P}$ and $\\mfk{Q}$ respectively. Note $\\mfk{P}' \\ne \\mfk{Q}'$ because if not then $\\mfk{P}=\\mfk{Q}$, a contradiction. Therefore the distinct prime ideals of $B$ lying above $\\mfk{p}$ are less than the distinct prime ideals of $C$ lying above $\\mfk{p}$, which proves our assertion.\n\t\t\t\t\\[\n\t\t\t\t\t\\begin{tikzcd}\n\t\t\t\t\t\t\\mathfrak{P}'          &                                    & \\mathfrak{Q}'          & C                   \\\\\n\t\t\t\t\t\t\\mathfrak{P} \\arrow[u] &                                    & \\mathfrak{Q} \\arrow[u] & B \\arrow[u, dashed] \\\\\n\t\t\t\t\t\t& \\mathfrak{p} \\arrow[lu] \\arrow[ru] &                        & A \\arrow[u, dashed]\n\t\t\t\t\t\\end{tikzcd}\n\t\t\t\t\\]\n\t\t\t\\end{proof}\n\t\t% TODO: ADD SOME EXAMPLES\n\t\t\\subsection{Inertia group and field}\n\t\t\\subsection{Automorphisms}\n\t\\section{Dedekind domain}\n\t\t\n\t\t\\subsection{Ramification index}\n\t\t\n\t\t\\subsection{Norm}\n\t\t\n\t\t\\subsection{Discrete valuation rings}\n\t\t\tA \\textbf{discrete valuation ring} can be considered as a localisation of Dedekind domain. Indeed, if $A$ is a discrete valuation ring, then $A$ is Noetherian and of Krull dimension $1$, and is integrally closed, hence Dedekind. If $A$ is local and Dedekind, then $A$ is a discrete valuation ring. In general, a Noetherian domain $A$ of Krull dimension one is Dedekind if and only if the localisation $A_\\mfk{p}$ is a discrete valuation ring for all prime $\\mfk{p}$. With respect to localisation we have a natural result:\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A$ be a Dedekind ring and $M,N$ two modules over $A$. If $M_\\mfk{p} \\subset N_\\mfk{p}$ for all prime $\\mfk{p}$, then $M \\subset N$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tLet $a \\in M$. For each $\\mfk{p}$ we can find $x_\\mfk{p} \\in N$ and $s_\\mfk{p} \\in A \\setminus \\mfk{p}$ such that $a = x_\\mfk{p}/s_\\mfk{p}$. Let $\\mfk{b}$ be the ideal generated by the $s_\\mfk{p}$, ranging through all $\\mfk{p} \\in \\spec(A)$. Then $\\mfk{b}$ is the unit ideal $A$, and we can write\n\t\t\t\t\\[\n\t\t\t\t\t1 = \\sum_{\\mfk{p} \\in \\spec(A)} y_\\mfk{p}s_\\mfk{p}\n\t\t\t\t\\]\n\t\t\t\twith elements $y_\\mfk{p} \\in A$ all but a finite number of which are $0$. This yields\n\t\t\t\t\\[\n\t\t\t\t\ta = \\sum_{\\mfk{p} \\in \\spec(A)} y_\\mfk{p}s_\\mfk{p}a = \\sum_{\\mfk{p} \\in \\spec(A)} y_\\mfk{p}x_\\mfk{p} \\in N\n\t\t\t\t\\]\n\t\t\t\tas desired.\n\t\t\t\\end{proof}\n\t\t\n\t\t\tNow we study torsion-free modules over a discrete valuation ring. If $A$ is a discrete valuation ring, then in particular, $A$ is a principal ideal ring, and any finitely generated torsion-free module $M$ over $A$ is free. If its rank is $n$, and if $\\mfk{p}$ is the maximal idea, then $M/\\mfk{p}M$ is a free module of rank $n$. Further, we have\n\t\t\t\\begin{theorem}\n\t\t\t\tLet $A$ be a local ring and $M$ a free module of rank $n$ over $A$. Let $\\mfk{p}$ be the maximal ideal of $A$. Then $M/\\mfk{p}M$ is a vector space of dimension $n$ over $A/\\mfk{p}$.\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\t\tLet $\\{x_1,\\dots,x_n\\}$ be a basis of $M$ over $A$, then\n\t\t\t\t\\[\n\t\t\t\t\tM \\cong \\bigoplus_{i}Ax_i\n\t\t\t\t\\]\n\t\t\t\tand\n\t\t\t\t\\[\n\t\t\t\t\tM/\\mfk{p}M \\cong \\bigoplus_{i}(A/\\mfk{p})\\overline{x}_i\n\t\t\t\t\\]\n\t\t\t\twhere $\\overline{x}_i$ is the residue class of $x_i$ mod $\\mfk{p}$.\n\t\t\t\\end{proof}", "meta": {"hexsha": "4a693789451e2ae2295c014ce39ed2800d813fd7", "size": 22454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Ch01.tex", "max_stars_repo_name": "a234/algebraic-number-theory-note", "max_stars_repo_head_hexsha": "4d46963bdb030bd8d7181822314c7c0231b29716", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/Ch01.tex", "max_issues_repo_name": "a234/algebraic-number-theory-note", "max_issues_repo_head_hexsha": "4d46963bdb030bd8d7181822314c7c0231b29716", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/Ch01.tex", "max_forks_repo_name": "a234/algebraic-number-theory-note", "max_forks_repo_head_hexsha": "4d46963bdb030bd8d7181822314c7c0231b29716", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.8773333333, "max_line_length": 659, "alphanum_fraction": 0.6200231585, "num_tokens": 8248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.6815818657818603}}
{"text": "\\section{Moment and Center of Mass}\\label{sec:MomentCenterMass}\n\nUsing a single integral we were able to compute the center of mass for\na one-dimensional object with variable density, and a two dimensional\nobject with constant density. With a double integral we can handle two\ndimensions and variable density.\n\nJust as before, the coordinates of the center of mass are\n\\[\\bar x={M_y\\over M} \\qquad \\bar y={M_x\\over M},\\]\nwhere $M$ is the total mass, $M_y$ is the moment around the $y$-axis,\nand $M_x$ is the moment around the $x$-axis. (You may want to review\nthe concepts in Section~\\ref{sec:centerofmass}.)\\index{moment}\\index{center of mass}\n\nThe key to the computation, just as before, is the approximation of\nmass. In the two-dimensional case, we treat density $\\sigma$ as mass\nper square area, so when density is constant, mass is \n$(\\hbox{density})(\\hbox{area})$. If we have a two-dimensional region\nwith varying density given by $\\sigma(x,y)$, and we divide the region\ninto small subregions with area $\\Delta A$, then the mass of one\nsubregion is approximately $\\sigma(x_i,y_j)\\Delta A$, the total mass\nis approximately the sum of many of these, \nand as usual the sum\nturns into an integral in the limit:\n$$M=\\int_{x_0}^{x_1}\\int_{y_0}^{y_1} \\sigma(x,y)\\,dy\\,dx,$$\nand similarly for computations in cylindrical coordinates.\nThen as before\n\\begin{align*}\nM_x &= \\int_{x_0}^{x_1}\\int_{y_0}^{y_1} y\\sigma(x,y)\\,dy\\,dx\t\\\\\nM_y &= \\int_{x_0}^{x_1}\\int_{y_0}^{y_1} x\\sigma(x,y)\\,dy\\,dx.\n\\end{align*}\n\n\\begin{example}{Center of Mass of Uniform Plate}{CenterMassUniformPlate}\nFind the center of mass of a thin, uniform plate whose shape\nis the region between $y=\\cos x$ and the $x$-axis between $x=-\\pi/2$\nand $x=\\pi/2$.\n\\end{example}\n\\begin{solution}\nSince the density is constant, we may take\n$\\sigma(x,y)=1$. \n\nIt is clear that $\\bar x=0$, but for practice let's\ncompute it anyway. First we compute the mass:\n\\[\nM=\\int_{-\\pi/2}^{\\pi/2} \\int_0^{\\cos x} 1\\,dy\\,dx\n=\\int_{-\\pi/2}^{\\pi/2} \\cos x\\,dx\n=\\left.\\sin x\\right|_{-\\pi/2}^{\\pi/2}=2.\n\\]\nNext,\n\\[\nM_x=\\int_{-\\pi/2}^{\\pi/2} \\int_0^{\\cos x} y\\,dy\\,dx\n=\\int_{-\\pi/2}^{\\pi/2} {1\\over2}\\cos^2 x\\,dx={\\pi\\over4}.\n\\]\nFinally,\n\\[\nM_y=\\int_{-\\pi/2}^{\\pi/2} \\int_0^{\\cos x} x\\,dy\\,dx\n=\\int_{-\\pi/2}^{\\pi/2} x\\cos x\\,dx=0.\n\\]\nSo $\\bar x=0$ as expected, and $\\bar y=\\pi/4/2=\\pi/8$. \nThis is the same problem as in Example~\\ref{exa:centerofmassundercos};\nit may be helpful to compare the two solutions.\n\\end{solution}\n\n\\begin{example}{Center of Mass of 2-D Plate}{CenterMass2DPlate}\nFind the center of mass of a two-dimensional plate \nthat occupies the quarter circle $x^2+y^2\\le1$ in the\nfirst quadrant and has density\n$k(x^2+y^2)$.\n\\end{example}\n\\begin{solution}\nIt seems clear that because of the symmetry of both the\nregion and the density function (both are important!), $\\bar x=\\bar y$.\nWe'll do both to check our work.\n\nJumping right in:\n\\[\nM=\\int_0^1 \\int_0^{\\sqrt{1-x^2}} k(x^2+y^2)\\,dy\\,dx\n=k\\int_0^1 x^2\\sqrt{1-x^2}+{(1-x^2)^{3/2}\\over3}\\,dx.\n\\]\nThis integral is something we can do, but it's a bit unpleasant. Since\neverything in sight is related to a circle, let's back up and try\npolar coordinates. Then $x^2+y^2=r^2$ and\n\\[M=\\int_0^{\\pi/2} \\int_0^{1} k(r^2)\\,r\\,dr\\,d\\theta\n=k\\int_0^{\\pi/2}\\left.{r^4\\over4}\\right|_0^1\\,d\\theta\n=k\\int_0^{\\pi/2} {1\\over4}\\,d\\theta\n=k{\\pi\\over8}.\n\\]\nMuch better. Next, since $y=r\\sin\\theta$,\n\\[M_x=k\\int_0^{\\pi/2} \\int_0^{1} r^4\\sin\\theta\\,dr\\,d\\theta\n=k\\int_0^{\\pi/2} {1\\over5}\\sin\\theta\\,d\\theta\n=k\\left.-{1\\over5}\\cos\\theta\\right|_0^{\\pi/2}={k\\over5}.\n\\]\nSimilarly,\n\\[M_y=k\\int_0^{\\pi/2} \\int_0^{1} r^4\\cos\\theta\\,dr\\,d\\theta\n=k\\int_0^{\\pi/2} {1\\over5}\\cos\\theta\\,d\\theta\n=k\\left.{1\\over5}\\sin\\theta\\right|_0^{\\pi/2}={k\\over5}.\n\\]\nFinally, $\\ds\\bar x = \\bar y = {8\\over5\\pi}$.\n\\end{solution}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:MomentCenterMass}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the square $[0,1]\\times[0,1]$\nand has density\nfunction $xy$.\n\\begin{sol}\n$\\bar x=\\bar y=2/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the triangle $0\\le x\\le1$, $0\\le y\\le x$,\nand has density\nfunction $xy$.\n\\begin{sol}\n$\\bar x=4/5$, $\\bar y=8/15$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the upper unit semicircle centered at $(0,0)$\nand has density\nfunction $y$.\n\\begin{sol}\n$\\bar x=0$, $\\bar y=3\\pi/16$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the upper unit semicircle centered at $(0,0)$\nand has density\nfunction $x^2$.\n\\begin{sol}\n$\\bar x=0$, $\\bar y=16/(15\\pi)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the triangle formed by $x=2$, $y=x$, and $y=2x$\nand has density\nfunction $2x$.\n\\begin{sol}\n$\\bar x=3/2$, $\\bar y=9/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the triangle formed by $x=0$, $y=x$, and $2x+y=6$\nand has density\nfunction $\\ds x^2$.\n\\begin{sol}\n$\\bar x=6/5$, $\\bar y=12/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two-dimensional plate \nthat occupies the region enclosed by the parabolas $x=y^2$, $y=x^2$\nand has density\nfunction $\\ds\\sqrt{x}$.\n\\begin{sol}\n$\\bar x=14/27$, $\\bar y=28/55$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the centroid of the area in the first quadrant bounded by\n $x^2-8y+4=0$, $x^2=4y$, and $x=0$. (Recall that the centroid\\index{centroid}\nis the center of mass when the density is 1 everywhere.)\n\\begin{sol}\n$(3/4,2/5)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the centroid of one loop of the three-leaf rose\n$r=\\cos(3\\theta)$.  (Recall that the centroid is the\ncenter of mass when the density is 1 everywhere, and that the mass in\nthis case is the same as the area, which was the subject of\nExercise~\\ref{ex:areaofthreeleafroseloop} in\nSection~\\ref{sec:DoubleIntegralsinPolarCoordinates}.)  The\ncomputations of the integrals for the moments $M_x$ and $M_y$ are\nelementary but quite long; Sage can help.\n\\begin{sol}\n$\\ds\\left({81\\sqrt3\\over80\\pi},0\\right)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of a two dimensional\nobject that occupies the region $0\\le x\\le \\pi$, $0\\le y\\le \\sin x$,\nwith density $\\sigma=1$.\n\\begin{sol}\n$\\bar x=\\pi/2$, $\\bar y=\\pi/8$ \n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA two-dimensional object has shape given by \n$r=1+\\cos\\theta$ and density $\\sigma(r,\\theta)=2+\\cos\\theta$. Set up\nthe three integrals required to compute the center of mass.\n\\begin{sol}\n$\\ds M=\\int_0^{2\\pi} \\int_0^{1+\\cos\\theta} (2+\\cos\\theta)r\\,dr\\,d\\theta$,\n\\hfill\\break\n$\\ds M_x=\\int_0^{2\\pi} \\int_0^{1+\\cos\\theta} \\sin\\theta(2+\\cos\\theta)r^2\\,dr\\,d\\theta$,\n\\hfill\\break\n$\\ds M_y=\\int_0^{2\\pi} \\int_0^{1+\\cos\\theta} \\cos\\theta(2+\\cos\\theta)r^2\\,dr\\,d\\theta$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA two-dimensional object has shape given by \n$r=\\cos\\theta$ and density $\\sigma(r,\\theta)=r+1$. Set up\nthe three integrals required to compute the center of mass.\n\\begin{sol}\n$\\ds M=\\int_{-\\pi/2}^{\\pi/2} \\int_0^{\\cos\\theta} (r+1)r\\,dr\\,d\\theta$,\n\\hfill\\break\n$\\ds M_x=\\int_{-\\pi/2}^{\\pi/2} \\int_0^{\\cos\\theta} \\sin\\theta(r+1)r^2\\,dr\\,d\\theta$,\n\\hfill\\break\n$\\ds M_y=\\int_{-\\pi/2}^{\\pi/2} \\int_0^{\\cos\\theta} \\cos\\theta(r+1)r^2\\,dr\\,d\\theta$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA two-dimensional object sits inside $r=1+\\cos\\theta$\nand outside $r=\\cos\\theta$, and has density $1$ everywhere.\nSet up\nthe integrals required to compute the center of mass.\n\\begin{sol}\n$\\ds M= \\int_{-\\pi/2}^{\\pi/2}\\int_{\\cos\\theta}^{1+\\cos\\theta}\nr\\,dr\\,d\\theta + \\int_{\\pi/2}^{3\\pi/2}\\int_0^{1+\\cos\\theta}r\\,dr\\,d\\theta$,\n\\hfill\\break\n$\\ds M_x=\\int_{-\\pi/2}^{\\pi/2}\\int_{\\cos\\theta}^{1+\\cos\\theta}\nr^2\\sin\\theta\\,dr\\,d\\theta + \\int_{\\pi/2}^{3\\pi/2}\\int_0^{1+\\cos\\theta}r^2\\sin\\theta\\,dr\\,d\\theta$,\n\\hfill\\break\n$\\ds M_y=\\int_{-\\pi/2}^{\\pi/2}\\int_{\\cos\\theta}^{1+\\cos\\theta}\nr^2\\cos\\theta\\,dr\\,d\\theta + \\int_{\\pi/2}^{3\\pi/2}\\int_0^{1+\\cos\\theta}r^2\\cos\\theta\\,dr\\,d\\theta$.\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "890db05a02d72d01bb593e1203fc4722ace125fc", "size": 8150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-multiple-integration/15-3-moment-center-mass.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "15-multiple-integration/15-3-moment-center-mass.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15-multiple-integration/15-3-moment-center-mass.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3412698413, "max_line_length": 99, "alphanum_fraction": 0.6766871166, "num_tokens": 3119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942472, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6815444688349787}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{preamble}\n\\addbibresource{../../shared/references.bib}\n\n\\usepackage{sets}\n\\usepackage{groups}\n\\usepackage{integers}\n\n\\title{Integers}\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 integers, $\\num$, and some related objects.\nIt has been type checked by \\fuzz.\n\\end{abstract}\n\n\\section{Introduction}\n\nThe integers, $\\num$, are built-in to Z Notation.\nThis article provides type declarations for some related objects so that they can be used and type checked in formal Z specifications.\n\n\\section{Integers}\n\n\\subsection{$AddIntegerSequences$}\n\nLet $l$ be a natural number and\nlet $x$ and $y$ be two integer sequences of length $l$.\nTheir sum $z = x + y$ is the integer sequence of length $l$ defined by point-wise addition of \nof the terms in $x$ and $y$.\nLet the schema $AddIntegerSequences$ denote this situation.\n\n\\begin{schema}{AddIntegerSequences}\n\tl : \\nat \\\\\n\tx, y, z : \\seq \\num\n\\where\n\tl = \\# x = \\# y\n\\also\n\tz = (\\lambda i : 1 \\upto l @ x~i + y~i)\n\\end{schema}\n\\begin{itemize}\n\t\\item The sequence $z$ is defined by pointwise addition of the sequences $x$ and $y$.\n\\end{itemize}\n\n\\subsection{$add\\_int\\_seq$}\n\nLet the function $add\\_int\\_seq(x, y) = z$ be the sum of two equal-length integer sequences.\n\n\\begin{zed}\n\tadd\\_int\\_seq == \\{~ AddIntegerSequences @ (x, y) \\mapsto z ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{addSeqZ}}\n\nWe introduce the notation $x \\addSeqZ y = add\\_int\\_seq(x, y)$.\n\n\\begin{zed}\n\t(\\_ \\addSeqZ \\_) == add\\_int\\_seq\n\\end{zed}\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "d795391526cec29a100c747689b63862ad784d29", "size": 1663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/integers/integers.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/integers/integers.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/integers/integers.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": 24.4558823529, "max_line_length": 134, "alphanum_fraction": 0.7131689717, "num_tokens": 509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.681518474803653}}
{"text": "%%%%%%%%%%%%%%%%%\n% Basic Notions %\n%%%%%%%%%%%%%%%%%\n\n\\section{Basic Notions and Notation}\n\n\\begin{example}{1.1}{}\n\n    Simplest \\SigmaAlgebra:\n\n        \\begin{itemize}\n            \\setlength{\\parskip}{0em}\n            \\item $\\{\\emptyset, \\Omega\\}$, \\emph{contained in every} \\SigmaAlgebra \\ on $\\Omega$,\n            \\item Family of all subsets of $\\Omega$, \\emph{containing every} \\SigmaAlgebra on $\\Omega$.\n        \\end{itemize}\n\n\\end{example}\n\n\\begin{exercise}{1.1}{}\n\n    Let $\\CalF$ be a \\SigmaAlgebra. Then $A_n \\in \\CalF$ for every integer $n \\geq 1$ $\\Rightarrow \\bigcap_{n=1}^{\\infty} A_n \\in \\CalF$.\n\n\\end{exercise}\n\n\\begin{proposition}{1.2}{}\n\n    Let $P$ be a probability measure on \\SigmaAlgebra\\ $\\CalF$. Then the following statements hold:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item $A, B \\in \\CalF$ s.t. $A \\subseteq B$ $\\Rightarrow$ $P(A) \\leq P(B)$;\n            \\item For \\emph{increasing} sequence $(A_n)_{n=1}^{\\infty}$ we have\n\n                \\begin{align*}\n                    \\lim_{n \\to \\infty} P(A_n) = P\\left(\\bigcup_{n=1}^{\\infty} A_n \\right);\n                \\end{align*}\n            \\item For \\emph{decreasing} sequence $(A_n)_{n=1}^{\\infty}$ we have\n\n                \\begin{align*}\n                    \\lim_{n \\to \\infty} P(A_n) = P\\left(\\bigcap_{n=1}^{\\infty} A_n \\right).\n                \\end{align*}\n        \\end{enumerate}\n\n\\end{proposition}\n\n\\begin{proposition}{1.2}{General}\n\n    Let $\\mu$ be a measure on \\SigmaAlgebra\\ $\\CalF$. Then the following statements hold:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item $A, B \\in \\CalF$ s.t. $A \\subseteq B$ $\\Rightarrow$ $\\mu(A) \\leq \\mu(B)$;\n            \\item For \\emph{increasing} sequence $(A_n)_{n=1}^{\\infty}$ we have\n\n                \\begin{align*}\n                    \\lim_{n \\to \\infty} \\mu(A_n) = \\mu\\left(\\bigcup_{n=1}^{\\infty} A_n \\right);\n                \\end{align*}\n            \\item For \\emph{decreasing} sequence $(A_n)_{n=1}^{\\infty}$ we have\n\n                \\begin{align*}\n                    \\lim_{n \\to \\infty} \\mu(A_n) = \\mu\\left(\\bigcap_{n=1}^{\\infty} A_n \\right).\n                \\end{align*}\n        \\end{enumerate}\n\n\\end{proposition}\n\n\\begin{proposition}{}{Bounding Intersections}\n\n    Let $A, B \\in \\CalF$. Then $\\mu(A \\cap B) \\leq \\mu(A)$.\n\n    \\Hint $\\sigma$-additivity and $A = (A \\cap B) \\cup (A \\setminus B)$.\n\n\\end{proposition}\n\n\\begin{proposition}{}{Measure of Set Difference, I}\n\n    Let $A, B \\in \\CalF$, then $\\mu(A \\setminus B) = \\mu(A) - \\mu(A \\cap B)$.\n\n\\end{proposition}\n\n\\begin{proposition}{}{Measure of Set Difference, II}\n\n    Let $A, B \\in \\CalF$ and $B \\subseteq A$, then $\\mu(A \\setminus B) = \\mu(A) - \\mu(B)$.\n\n\\end{proposition}\n\n\\begin{proposition}{}{Complement of Limit Inferior/Superior}\n\n    Let $(A_n)_{n=1}^{\\infty}$ be a sequence of sets in $\\CalF$, then:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item\n                \\begin{align*}\n                    \\left(\\liminf_{n \\to \\infty} A_n\\right)^C = \\limsup_{n \\to \\infty} A_n^C\n                \\end{align*}\n            \\item\n                \\begin{align*}\n                    \\left(\\limsup_{n \\to \\infty} A_n\\right)^C = \\liminf_{n \\to \\infty} A_n^C\n                \\end{align*}\n        \\end{enumerate}\n\n\\end{proposition}\n\n\\begin{exercise}{Ws 2, 1}{Limit Inferior/Superior Properties}\n\n       Let $(A_n)_{n=1}^{\\infty}$ be a sequence of sets in $\\CalF$, then:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item\n                \\begin{align*}\n                    \\liminf_{n \\to \\infty} A_n \\coloneqq \\bigcup_{n = 1}^{\\infty}\\bigcap_{k = n}^{\\infty} A_k\n                \\end{align*}\n\n                is the set of those $\\omega$ that are \\emph{in all but finitely many $A_n$}, i.e. that uphold the property $A_n$ captures for all except a finite amount of values of $n$.\n            \\item\n                \\begin{align*}\n                    \\limsup_{n \\to \\infty} A_n \\coloneqq \\bigcap_{n = 1}^{\\infty}\\bigcup_{k = n}^{\\infty} A_k\n                \\end{align*}\n\n                is the set of those $\\omega$ that are \\emph{in infinitely many $A_n$}, i.e. that uphold the property $A_n$ captures for an infinite amount of values of $n$.\n        \\end{enumerate} \n\n\\end{exercise}\n\n\\begin{proposition}{}{Continuous Implies Borel-Measurability}\n\n    Let $f: \\mathbb{R} \\to \\overline{\\mathbb{R}}$ be a \\emph{continuous} function. Then $f$ is Borel-measurable.\n\n\\end{proposition}\n\n\\begin{proposition}{}{Countable Sets}\n\n    Every countable subset of $\\mathbb{R}$ is Borel-measurable.\n\n\\end{proposition}\n", "meta": {"hexsha": "d7327e7b7bae205fe00c7dfc206f3e9cb22fc1f0", "size": 4640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/basic-notions.tex", "max_stars_repo_name": "smueksch/measure-theory-overview", "max_stars_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/basic-notions.tex", "max_issues_repo_name": "smueksch/measure-theory-overview", "max_issues_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/basic-notions.tex", "max_forks_repo_name": "smueksch/measure-theory-overview", "max_forks_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-02T15:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-02T15:34:51.000Z", "avg_line_length": 33.6231884058, "max_line_length": 186, "alphanum_fraction": 0.549137931, "num_tokens": 1526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6815184410570747}}
{"text": "% Question  ##################################################################################################################\n\\section{Question 1}\\label{ssec:pt1q1}\n\\textbf{The objective of this question is to analyse the data for different instruments, based on last year’s data, and provide your opinion in terms of their respective risk and return.}\n\n% END Question  ##############################################################################################################\n\n% Question (i) ###############################################################################################################\n\n\\subsection{Q1 (i)}\\label{sssec:pt1q1i}\n\\textbf{Download daily closing price data for S\\&P500, FTSE100 and Gold (SPDR) for the years 2014 to 2017.}\n\n\\noindent\nCode to download the closing prices for the assets specified in this question can be found in ‘Question 1 (i)’ in the python notebook. The data was downloaded from Yahoo Finance and saved as .csv format in the following path \\textit{‘src/data/part\\_1’}. The files were saved as follows \\textit{‘FTSE100.csv’}, \\textit{‘S\\&P500.csv’} and \\textit{‘GOLD.csv’}. The data was then reloaded from the files and converted into pandas dataframes. \n\n% END Question (i) ###########################################################################################################\n\n% Question (ii) ##############################################################################################################\n\n\\subsection{Q1 (ii)}\\label{sssec:pt1q1ii}\n\\textbf{Why log returns are normally preferred from standard arithmetic returns?}\n\n\\noindent\nLog returns are preferred over arithmetic returns for several reasons, one of which is that when using log returns you are inherently normalizing all the values. The process of normalization makes the returns easier to compare with and this is very useful in analytical situations or machine learning. Another advantage is time-additivity, meaning when using log-returns it is easier to compound returns since you only need to add the values unlike when using arithmetic returns \\cite{meucci2010quant}. Also, in theory prices are assumed to be distributed log normally (not always true for every price series) and transforming to log makes the values normally distributed. This is very useful in situations where it is assumed that the values are normally distributed, which is quite common in machine learning and statistics.\n\n% END Question (ii) ##########################################################################################################\n\n% Question (iii) #############################################################################################################\n\n\\subsection{Q1 (iii)}\\label{sssec:pt1q1iii}\n\n\\textbf{Identify the first 4 distribution moments for each index/product mentioned in part (i). For your\ncalculations utilise daily log returns. In your answer describe the calculations/steps performed.}\n\n\\noindent\nFirst the log returns were calculated for each index/product using the adjusted closing price. Once the log returns were computed a new column was added in each pandas dataframe called “Log Returns”, so it can be utilised when calculating the distribution moments.  A function to compute the log returns was created in the ‘fintech’ library and another function was also created to compute the four distribution moments. These functions can be shown in Fig.~\\ref{fig:logretfunc} and Fig.~\\ref{fig:distmomfunc}. The first and second distribution moments were calculated using numpy \\cite{python:numpy} functions. The third and the forth distribution moments were calculated using scipy \\cite{python:scipy}. \\\\\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/log_diff_func.png}\n  \\caption{Function to compute log returns.}\n  \\label{fig:logretfunc}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .7]{imgs/dist_mom_func.png}\n  \\caption{Function to compute four distribution moments.}\n  \\label{fig:distmomfunc}\n\\end{figure} \\\\\n\n\\noindent\nTo further explain these functions used in the code, the following equations are presented. Eq.~\\ref{eq:logdiff} is used to compute the log returns, which basically takes the natural log of the adjusted price at $t$ divided by the adjusted price at $t - 1$.\n\n\\begin{equation} \\label{eq:logdiff}\n    Log \\ Returns = \\ln(\\frac{S_t}{S_{t-1}})\n\\end{equation}\n\n\\noindent\nThe first distribution moment is calculated using the Eq.~\\ref{eq:1mom} which basically is the mean of the computed log returns. By finding the mean of the log returns we get a value of the expected return and it gives us the centre point under the distribution. The second distribution moment as shown in Eq.~\\ref{eq:2mom} is the standard deviation of the log returns. Such value shows us the volatility of the index/product and measures the disperation in the distribution.\n\n\\noindent\nThe third moment is the computed Skew of the log returns and this is shown in Eq.~\\ref{eq:3mom}. Skew is calculated by taking the sum of the log return $Y_i$ subtracted by the log return mean $\\overline{Y}$ and raised to the power of 3. Then this summation is divided by the number of the log return values ($N$). After doing so this result is divided by the standard deviation raised to the power of 3  which is shown as $s^3$. This gives us the measure of symmetry for the distribution and show us how skewed the log returns are. Similarly the fourth moment, which is also know as Kurtosis, is calculated in the same way but raised to the power of 4 as shown in Eq.~\\ref{eq:4mom}. This measures the shape of our distribution for the log returns (tails, tall or flat) and the distribution is set to be normally distributed if it is close to 3. \n\n\\begin{equation} \\label{eq:1mom}\n    1st \\ Moment = \\frac{\\Sigma x}{N}\n\\end{equation}\n\n\\begin{equation} \\label{eq:2mom}\n    2nd \\ Moment = \\sqrt{\\frac{\\Sigma(x - \\overline{x})^2}{N}}\n\\end{equation}\n\n\\begin{equation} \\label{eq:3mom}\n    3rd \\ Moment = \\frac{\\sum_{i=1}^{N}(Y_i - \\overline{Y})^3 / N}{s^3}\n\\end{equation}\n\n\\begin{equation} \\label{eq:4mom}\n    4th \\ Moment = \\frac{\\sum_{i=1}^{N}(Y_i - \\overline{Y})^4 / N}{s^4}\n\\end{equation}\n\n\\noindent\nThe functions described above were called from the notebook as shown in Fig.~\\ref{fig:momcode} and the other Fig.~\\ref{fig:momresults} shows the output of the distribution moments for each index/product. \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .60]{imgs/moments_code.png}\n  \\caption{Code used in the notebook to get distribution moments.}\n  \\label{fig:momcode}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .60]{imgs/moments_results.png}\n  \\caption{Function to compute log returns }\n  \\label{fig:momresults}\n\\end{figure}\n\n% END Question (iii) #########################################################################################################\n\n% Question (iv) ##############################################################################################################\n\n\\subsection{Q1 (iv)}\\label{sssec:pt1q1iv}\n\n\\textbf{Comment on the measured statistics from the perspective of risk and return. In your answer\ncompare the results obtained.}\n\n\\noindent\nAs described the first moment is the expected return of an asset, while the second moment gives as the expected volatility of an asset. This means that the volatility gives as the dispersion of where the price might go. The higher the volatility the larger the swings for the price over time, which can make an asset quite risky since the price can move in an upward or downward direction. The Skew measure will help us determine the extremes of where the price might go. The more skewed an asset is the less accurate financial models will be, since most of them rely on normally distributed data. When having a positively skewed returns, means that there were frequent small losses and a few large gains, while a negatively skewed returns, means that there were frequent small gains and a few large loses. In terms of risk and reward an attractive asset would be an asset with the following traits; high expected returns, low volatility, a positive skew and a Kurtosis measure close to 3 (normal distribution). \n\n\\noindent\nLooking at the S\\&P500 statistics the expected returns (0.036\\%) and volatility (0.7621\\%) is more attractive in terms of risk and return than the FTSE100 index with expected returns (0.0134\\%) and volatility (0.8815\\%). This is because S\\&P500 has higher expected return with less volatility making it a safer bet according to historic data. Both assets have a negative Skew and the Kurtosis measure for both assets are close to 3 with a difference of +0.120574 and –0.2278 respectively.\n\n\\noindent\nOn the other hand, the gold asset has an expected return (0.0062\\%) and volatility (0.8785\\%), which although it is less volatile than the FTSE100, the expected return is significantly lower. Unlike the other assets, the FTSE100 has a positively skewed return which is preferred over negatively skewed values. Also, the Kurtosis is close to 3 with a difference of -0.72061. \n\n\\noindent\nIn terms of risk and return, the most attractive asset from the results obtained is the S\\&P500 index. \n\n% END Question (iv) ##########################################################################################################\n\n% Question (v) ###############################################################################################################\n\n\\subsection{Q1 (v)}\\label{sssec:pt1q1v}\n\n\\textbf{Annualize daily return (first moment) and volatility (second moment). In your scaling process assume 250 days for the year. In your answer describe the calculations/steps performed.}\n\n\\noindent\nThe code for this task can be found in ‘Question 1 (v)’ in the python notebook. A function called ‘annretvol\\_asset’ was created in the ‘fintech’ library to annualize the log returns and volatility. This function is shown in Fig.~\\ref{fig:annasset}.  \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/annualize_asset.png}\n  \\caption{Function to annualize returns and volatility for an asset. }\n  \\label{fig:annasset}\n\\end{figure}\n\n\\noindent\nIn the first line of the function the first moment and second moment are computed for the specific asset. Once these are computed the daily log return is annualized by simply using ($First \\ moment \\times 250$) and the volatility is annualized using  ($Second \\ moment \\times \\sqrt{250}$). The formulas described were used since returns scale with time, while volatility scales with square root of time. The computed values are then converted to percentages and returned by the function. To calculate the annualized returns and volatility for each asset, this function was called from a loop and the daily log returns found in (iii) were passed as a parameter. Results for these two measurements are shown in Fig.~\\ref{fig:annassetresult}. \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/annualize_asset_results.png}\n  \\caption{Annualized returns and volatility for the three assets. }\n  \\label{fig:annassetresult}\n\\end{figure}\n\n% END Question (v) ###########################################################################################################\n\n% Question (vi) ##############################################################################################################\n\n\\subsection{Q1 (vi)}\\label{sssec:pt1q1vi}\n\n\\textbf{By considering the last closing price at the end of 2017, and the annualized volatility from question (v), what would be the price level of S&P 500 after 1 month, that according to normal probability, there is a 32\\% chance that the actual price will be above it. Show your workings.}\n\n\\noindent\nCode for this task can be found in ‘Question 1 (vi)’ in the python notebook. To find the price level for the asset after one month the last closing price was fetched, which was equal to \\$2,673.61. After doing so the annualized volatility $(12.05\\%)$ was scaled to one month using the following formula $(\\frac{12.05}{100} \\times \\sqrt{\\frac{20}{250}})$ and it was assumed that a one month period contains 20 days. Using these two values the price deviation could be computed using $(\\$2,673.61 \\times (\\frac{12.05}{100} \\times \\sqrt{\\frac{20}{250}}))$ which outputs \\$91.12. So the price levels after one month is in the range of ($\\$2,673.61 - \\$91.12$) to ($\\$2,673.61 + \\$91.12$) which is equal to the range of \\$2,582.49 - \\$2,764.73.\n\n\\noindent\nUsing the Z-score equation as shown in Eq.~\\ref{eq:zscore}, we can find the number of standard deviations a value is from the mean. In this case the mean is set to be the last closing price for the asset, which is equal to \\$2,673.61. We found that the price has a 16\\% chance that it will be above of \\$2,764.73. To find a price which has a 32\\% chance of being above the actual price, we rearrange the formula to find $X$. Using a z-score table we know that a z-score of 0.47 has 68\\% area under the distribution. So, by finding this value we would be able to find a price which has 32\\% chance that the actual price will be above it. \n\n\\begin{equation} \\label{eq:zscore}\n    Z = \\frac{X - \\mu}{\\sigma}\n\\end{equation}\n\n\\noindent\nThe price which has 32\\% chance of being above the actual price is ($0.47 \\times \\$91.12 + \\$2,673.61$), which is equal to \\$2716.44.\n\n% END Question (vi) ##########################################################################################################\n\n% Question (vii) #############################################################################################################\n\n\\subsection{Q1 (vii)}\\label{sssec:pt1q1vii}\n\n\\textbf{Download the Google and Amazon daily prices for the last 5 years (till 31/12/2017). By utilizing a\nregression model, perform the Beta-test against the S\\&P 500 index. Comment on your findings.}\n\n\\noindent\nCode for this task can be found in ‘Question 1 (vii)’ in the python notebook. The data was downloaded from Yahoo Finance and saved as .csv format in the following path \\textit{‘src/data/part\\_1’}. The files were saved as \\textit{‘GOOGLE.csv’}, \\textit{‘AMAZON.csv’} and \\textit{‘S\\&P500BETA.csv’}. The data was then reloaded from the files and converted into pandas dataframes. A new dataframe with the percentage changes (daily adjusted closing prices) for the three assets was created, with each column holding the percentage changes for each asset.\n\n\\noindent\nA function called ‘beta\\_test\\_ols’ (uses Ordinary Least Squares from 'statsmodels' \\cite{seabold2010statsmodels}) was created in the ‘fintech’ library and was utilised to perform the beta-test. Two beta-test were conducted ‘GOOGLE VS S\\&P500’ as shown in Fig.~\\ref{fig:beta_1} and ‘AMAZON vs S\\&P500’ as shown in Fig.~\\ref{fig:beta_2}. The plots for the results are shown in Fig.~\\ref{fig:beta_1_plot} and Fig.~\\ref{fig:beta_2_plot} respectively.  \n\n\\begin{figure}[H]\n     \\centering\n     \\begin{subfigure}[b]{0.8\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{imgs/beta_1.png}\n         \\caption{GOOGLE VS S\\&P500 Beta-test.}\n         \\label{fig:beta_1}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.8\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{imgs/beta_2.png}\n         \\caption{AMAZON vs S\\&P500 Beta-test.}\n         \\label{fig:beta_2}\n     \\end{subfigure}\n\\end{figure}\n\n\\noindent\nThe beta-test (Capital Asset Pricing Model (CAPM)) is used to provide a measure which describes the risk/return ratio for the two assets. In this task we use the beta-test to test the relation of a stock price relative to a stock market index (systematic risk). The beta is calculated using Eq.~\\ref{eq:beta}. \n\n\\begin{equation} \\label{eq:beta}\n    Market \\ Return = \\alpha + (\\beta \\times stock \\ return)\n\\end{equation}\n\n\\noindent\nLet’s look at the first result ‘GOOGLE vs S\\&P500’ which has a beta of 1.0707 and a p-value which makes this measurement statistically significant. With 95\\% confidence that the value lies between 0.9876 and 1.1538. Since the $\\beta > 1$, this asset is volatile and moves with the rest of the market. This means that if the market moves in an upwards direction this asset is likely to move in the same direction and the same goes if the market moves in a downward direction. So as a benchmark we know that this asset is positively correlated with the market index as shown in the plot in Fig.~\\ref{fig:beta_1_plot}. Looking at the confidence levels, although the beta can be less than 1 it is still a very high value and this means that this stock is likely to move with the market or follows a similar trend. \n\n\\noindent\nIn the other test ‘AMAZON VS S\\&P500’ the beta was 1.2151 and has a p-vale which makes the measurement statistically significant. With 95\\% confidence that the value lies between 1.0977 and 1.3325. Like the previous test this stock is volatile and moves with the rest of the market, since it’s correlated according to the test. One must note that the beta confidence levels and the beta is a bit higher than the previous stock which makes this asset to move a bit higher or lower than the benchmark (market-index). This means if the market is moving in an upward direction this stock will see more returns relative to the market and it will see more loses when moving in a downward direction. In fact the beta for the Google stock is close to 1 meaning it will move very similar to the market and this difference between the movements of the two assets can be seen in both the plots Fig.~\\ref{fig:beta_1_plot} and Fig.~\\ref{fig:beta_2_plot}. \n\n\\begin{figure}[H]\n     \\centering\n     \\begin{subfigure}[b]{0.6\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{imgs/beta_1_plot.png}\n         \\caption{GOOGLE VS S\\&P500 Beta-test plot.}\n         \\label{fig:beta_1_plot}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.6\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{imgs/beta_2_plot.png}\n         \\caption{AMAZON vs S\\&P500 Beta-test plot.}\n         \\label{fig:beta_2_plot}\n     \\end{subfigure}\n\\end{figure}\n\n\\noindent\nWe would like to add that beta-test does not detect any unsystematic risk. Since we are measuring beta for separate stocks it will give us an indication of how much risk such assets will add or subtract to a portfolio. Such measure does not always predict the stock movements, but it can be a useful indication when building a portfolio as it gives us some indication of how a stock moves with the market. It is also important to note that we used the daily values to measure the beta while it is more common to use the monthly measurements. When using the monthly data, it can faster to compute, easier to identify change in trends and can be good for long term forecasting but if you are looking at daily changes it is better to use daily data. On the other hand, daily is more optimal if you are forecasting for short to medium periods of time but data can be susceptible to noise. Choosing the time period to work with depends on the problem you are trying to solve/predict. \n\n% END Question (vii) #########################################################################################################\n", "meta": {"hexsha": "9173b1480674c2e0a783e2aa9add8021a130fe05", "size": 19197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/LaTeX/sections/1_part/1_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/1_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/1_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": 82.3905579399, "max_line_length": 1012, "alphanum_fraction": 0.6890659999, "num_tokens": 4604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.681448640985988}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 5}\n\nA word on an alphabet A is \\textit{square-free} if it contains no infix of the form $xx$, where $x \\in A^+$.\n\\begin{enumerate}[label=(\\alph*)] \n\t\\item\n\tList all square-free words of length three over the alphabet \\{a,b\\}.\n\n\t\\item\n\tShow that for the alphabet $\\{a,b\\}$ there are no square-free words of length at least equal to 4.\n\n\t\\item\n\tLet $f:A \\rightarrow A$ be a one-to-one mapping.\n\tProve that if $x$ is square-free then so is $f(x)$.\n\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\t\\item\n\tThe only three-letter square-free words over the alphabet $\\{a,b\\}$ are $\\{aba,bab\\}$.\n\n\t\\item\n\tA four-letter word is constructed by adding a symbol to the end of one of the possible three-letter combinations of which only \\textit{aba} and \\textit{bab} are square-free. If other three-letter combinations are chosen to construct upon, they have already failed to satisfy square-free condition. Table \\ref{5tab1} shows that even if three-letter square-free words be chosen to construct upon, addition of any symbol would lead to infixes. As cases presented in table \\ref{5tab1} are inclusive, it is concluded that no four-letter words over alphabet $\\{a,b\\}$ are square-free.\n\n\tAs any word of more than four symbols contains a four-letter combination, it is proven that no words of length at least equal to four are square free.\n\n\t\\begin{table}\n\t\t\\centering\n\t\t\\begin{tabular}{c|c|c|c}\n\t\t\t\\textbf{initial} & \\textbf{$4^{th}$ letter} & \\textbf{final combination} & \\textbf{infix}\\\\\n\t\t\t\\hline\n\t\t\taba & a & abaa & a\\\\\n\t\t\taba & b & abab & ab\\\\\n\t\t\tbab & a & baba & ba\\\\\n\t\t\tbab & b & babb & b\n\t\t\\end{tabular}\n\t\t\\caption{Constructing 4-letter words from 3-letter words}\\label{5tab1}\n\t\\end{table}\n\n\t\\item\n\tStatement is shown to be true using proof of contradiction. It is assumed that there is a $y$ that is square-free whose $f(y)$ is not. $y$ can be represented as $klmn$ where $k, l, m, n \\in A^*$ and $k \\neq l \\neq m \\neq n$. $f(y)$ can also be represented as $tuuv$ where $t, u, v \\in A^*$ and $u \\neq \\lambda$ and $t \\neq u \\neq v$.\n\n\tTaking advantage of the assumption that $f:A\\rightarrow A$ is one-to-one,\n\n\t\\begin{equation}\\label{5eq1}\n\tf(y) = f(k)f(l)f(m)f(n)\n\t\\end{equation}\n\n\tBased on our assumption, it is true that\n\n\t\\begin{equation}\\label{5eq2}\n\t\\exists k, l, m, n \\mid y = klmn, f(k)=t, f(l)=u, f(m)=u, f(n)=v\n\t\\end{equation}\n\n\tHowever \\eqref{5eq2} claims that $f(l) = f(m)$ which is in contrast to our given assumption that $f:A\\rightarrow A$ is one-to-one. Hence, our assumption is not valid and statement is proven to be true.\n\n\\end{enumerate}\n", "meta": {"hexsha": "04dd85772aac081fb2aa033b02d34591a970d3df", "size": 2963, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q05.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q05.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q05.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 44.223880597, "max_line_length": 579, "alphanum_fraction": 0.6689166385, "num_tokens": 898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6814486263550211}}
{"text": "% Studentds question collection\n%# Author Alejandro Gonzalez Recuenco and SKR students\n%# e-mail <alejandrogonzalezrecuenco@gmail.com>\n\n\\documentclass{exam}\n%SET-UP:\n\\usepackage{amsmath, physics, tikz, tcolorbox, graphicx}\n\n\n\n%! TexExamRandomizer = {\"noutput\":2}\n%! TexExamRandomizer = {\"randominfo\": {\"randomnumber\":100000000, \"switchnumber\":[\"even\", \"odd\", \"stop\"]}}\n%! TexExamRandomizer = {\"layercmd\":[\"item\", \"(choice|CorrectChoice)\"],\"layernames\":[\"itemize\", \"choices\"]}\n%! TexExamRandomizer = {\"table\":\"TestClass.csv\"}\n%! TexExamRandomizer = {\"extrainfo\":{\"Class\":\"class\", \"Roll Number\":\"rollnumber\",\"Nickname\":\"nickname\"}}\n\n\\newcommand{\\randomnumber}{3}\n\\newcommand{\\switchnumber}{hi}\n\\newcommand{\\class}{class}\n\\newcommand{\\rollnumber}{rollnumber}\n\\newcommand{\\nickname}{nickname}\n\\newcommand\\myversion{0}\n\\newcommand\\rseed{seed}\n\n\n% DOCUMENT STARTS HERE\n\\begin{document}\n\n\\author{\\class\\ --- \\nickname --- \\rollnumber}\n\\title{\\textsc{Exam collection} --- mini-exam, random \\randomnumber, switch \\switchnumber }\n\n\n\\maketitle\n\n\n\n\\section{Word problems}\\begin{itemize}\n\n\t\\item What is the mathematical definition of derivative.\n\n\t\\begin{choices}\n\t\t\\choice $f'(x) = \\lim_{h\\to 0}$ $\\frac{f(x)-f(x)}{h+x}$\n\t\t\\choice $f'(x) = \\lim_{h\\to 0}$ $\\frac{f(x)-f(h)}{x}$\n\t\t\\choice $f'(x) = \\lim_{h\\to 0}$ $\\frac{f(x+h)+f(h)}{x}$\n\t\t\\CorrectChoice $f'(x) = \\lim_{h\\to 0}$ $\\frac{f(x+h)-f(x)}{h}$\n\t\\end{choices}\n\t\\item What is the derivative of the function $h(x) = \\frac{f(x)}{g(x)}$,\n\n\t\\begin{choices}\n\t\t\\choice $h'(x) = f'(g(x)) \\cdot g'(x).$\n\t\t\\choice $h'(x) = f'(x)g(x)-f(x)g'(x).$\n\t\t\\choice $h'(x) = f'(x)g(x)+f(x)g'(x).$\n\t\t\\CorrectChoice $h'(x) = \\frac{f(x)g'(x)-f'(x)g(x)}{(g(x))^2}.$\n\t\\end{choices}\n\n\t\\item Which one is the correct form of the chain rule ?\n\n\t\\begin{choices}\n\t\t\\choice $(f(g'))(x)=f'(g(x'))g'(x)$\n\t\t\\choice $(f(g'))'(x)=f'(g(x'))g'(x)$\n\t\t\\choice $(f(g))'(x)=f'(g'(x'))g'(x')$\n\t\t\\CorrectChoice $(f(g))'(x)=f'(g(x))g'(x)$\n\t\\end{choices}\n\n\t\\item Which of the following is NOT a type of discontinuity?\n\n\t\\begin{choices}\n\t\t\\choice Removable.\n\t\t\\choice Infinite jump.\n\t\t\\choice Finite jump.\n\t\t\\CorrectChoice Endpoint.\n\t\\end{choices}\n\n\t\\item What does a `Derivative' describe?\n\t\\begin{choices}\n\t\t\\choice It describes the instantaneous change of rate of the functions at $x$ axis.\n\t\t\\choice It describes the instantaneous change of rate of the functions at $y$ axis.\n\t\t\\choice It describes the instantaneous change of rate of the functions at some point.\n\t\t\\CorrectChoice It describes the instantaneous change of rate of the functions at every point.\n\t\\end{choices}\n\t\\item What is a tangent line to a curve at a point $x = a$?\n\n\t\\begin{choices}\n\t\t\\choice A line that crosses a  curve once.\n\t\t\\choice None of the other choices are correct.\n\t\t\\choice A line that crosses a curve in two points.\n\t\t\\CorrectChoice A line that has the same slope as the curve at the point $x = a$.\n\t\\end{choices}\n\t\\item What type of graph is the derivative of $f(x)= 5x^3+6x^2+5x-1$ graph?\n\n\t\\begin{choices}\n\t\t\\choice Line.\n\t\t\\choice Circle.\n\t\t\\choice Hyperbola.\n\t\t\\CorrectChoice Parabola.\n\t\\end{choices}\n\t\\item The derivative of a function at a point $x = a$ tells us \\ldots\n\n\t\\begin{choices}\n\t\t\\choice The limit of the function\n\t\t\\choice The integral of the function.\n\t\t\\choice The average rate of change.\n\t\t\\CorrectChoice The slope of a tangent line of the graph at $x = a$.\n\t\\end{choices}\n\n\\end{itemize}\n\n\\section{Easy}\n\n\\begin{itemize}\n\t\\item If $y=\\cos5x$ find $\\dv{y}{x}$.\n\n\t\\begin{choices}\n\t\t\\choice $\\dv{y}{x} = 5\\cos5x$.\n\t\t\\choice $\\dv{y}{x} = -2\\sin5x$.\n\t\t\\choice $\\dv{y}{x} = 5\\cos2x$.\n\t\t\\CorrectChoice $\\dv{y}{x} = -5\\sin5x$.\n\t\\end{choices}\n\t\\item Given $y=2x^2-3x+5$, What is $\\dv[2]{y}{x}$\n\n\t\\begin{choices}\n\t\t\\choice $\\dv[2]{y}{x}=4x-3$\n\t\t\\choice $\\dv[2]{y}{x}=16x-12$\n\t\t\\choice $\\dv[2]{y}{x}=0$\n\t\t\\CorrectChoice $\\dv[2]{y}{x}=4$\n\t\\end{choices}\n\t\\item What is the derivative of $y=\\sin (2x + 5)$\n\n\t\\begin{choices}\n\t\t\\choice $ \\cos(2x+5)$\n\t\t\\CorrectChoice $ 2\\cos(2x+5)$\n\t\t\\choice $ 2\\cos(2x)+5$\n\t\t\\choice $ -2\\cos(2x-5)$\n\t\\end{choices}\n\n\n\t\\item If the functions $f(x)$ and $g(x)$ are continuous everywhere then, what can we say about the function $h(x) = \\frac{f(x)}{g(x)}$:\n\n\t\\begin{choices}\n\t\t\\CorrectChoice $\\frac{f(x)}{g(x)}$ is also continuous everywhere except at the zeros of $g(x)$.\n\t\t\\choice $h(x) = \\frac{f(x)}{g(x)}$ is also continuous everywhere.\n\t\t\\choice $h(x)$ will never cross the x axis.\n\t\t\\choice More information is needed to answer this question.\n\t\\end{choices}\n\n\n\t\\item Find the value of $\\lim_{x\\to 2}\\frac{x-1}{x^2-x-1}$\n\n\t\\begin{choices}\n\t\t\\choice $0$.\n\t\t\\CorrectChoice $1$.\n\t\t\\choice $\\infty$.\n\t\t\\choice Not possible.\n\t\\end{choices}\n\n\t\\item What is the derivative of $f(x)= 3x^4+2x^3-3x-2$\n\t\\begin{choices}\n\t\t\\choice $f'(x)= 3x^7+2x^6-3x^3-2$.\n\t\t\\choice $f'(x)= 12x^3+6x^2-5$.\n\t\t\\choice $f'(x)= 7x^4+5x^3-4x-2$.\n\t\t\\CorrectChoice $f'(x)= 12x^3+6x^2-3$.\n\t\\end{choices}\n\t\\item What is the derivative of $(x^{2} + 3)(5 x + 2)$ ?\n\n\t\\begin{choices}\n\t\t\\choice $15 x^{2} + 19 x$\n\t\t\\choice $50 x^{2} + 60 x$\n\t\t\\choice $2 x + 5$\n\t\t\\CorrectChoice $15 x^{2} + 4 x + 15$\n\t\\end{choices}\n\t\\item When $f'(x) = 0$ what happens?\n\n\t\\begin{choices}\n\t\t\\choice $f''(x) = 1$\n\t\t\\choice $f''(x) = 0 $\n\t\t\\CorrectChoice The point is a critical  point\n\t\t\\choice Local maximum or minimum or an inflection point.\n\t\\end{choices}\n\t\\item What is the derivative of $f(x) = (2x+8)^2$\n\n\t\\begin{choices}\n\t\t\\choice $32$\n\t\t\\choice $3x+32$\n\t\t\\choice $4x+32$\n\t\t\\CorrectChoice $8x+32$\n\t\\end{choices}\n\n\t\\item If $f(x) =\\sqrt{x^3 - 4x}$, calculate when $f(x)=0 $\n\n\t\\begin{choices}\n\t\t\\choice $x = 0,\\,1,\\,{-1}$\n\t\t\\choice $x= 0, $\n\t\t\\choice $x= 0,\\,2 $\n\t\t\\CorrectChoice$ x= 0,\\,2,\\,{-2} $\n\t\\end{choices}\n\t\\item Given $f(x) = \\frac{x^3-4}{2x+2}$, then $\\lim_{x\\to 4} f(x) = \\ldots$\n\n\t\\begin{choices}\n\t\t\\choice $\\ldots3.$\n\t\t\\choice $\\ldots4.$\n\t\t\\choice $\\ldots5.$\n\t\t\\CorrectChoice $\\ldots6.$\n\t\\end{choices}\n\t\\item  Suppose $f(x) = x^2 + 3$  and $g(x) = x - 2$. Which of the following is  $(f-g)(x)$?\n\n\t\\begin{choices}\n\t\t\\choice  $(f-g)(x)=x^2 - x +1$\n     \t\\choice  $(f-g)(x)=x^3 + 2x^2 + 3x -2$\n\t\t\\choice  $(f-g)(x)=x^2 - 4x + 7$\n\t\t\\CorrectChoice   $(f-g)(x)=x^2 - x + 5$\n\t\\end{choices}\n\n\t\\item Given the functions $f(x) = x^4+3$ and $g(x) = \\sqrt{x}$, find the value of $(f\\circ g)'(x)\\ldots$\n\n\t\\begin{choices}\n\t\t\\choice $(f\\circ g)'(x) = x$\n\t\t\\CorrectChoice $(f\\circ g)'(x) = 2x$\n\t\t\\choice $(f\\circ g)'(x) = 3x$\n\t\t\\choice $(f\\circ g)'(x) = 4x$\n\t\\end{choices}\n\t\\item Which one is the correct form of the product rule?\n\n\t\\begin{choices}\n\t\t\\choice $(f(x)\\cdot g(x))' = f'(x)g'(x)+f'(x)g'(x)$\n\t\t\\choice $(f(x)\\cdot g(x))' = f'(x)g'(x)+f(x)g(x)$\n\t\t\\choice $(f(x)\\cdot g(x))' = f(x)g'(x)+f(x)g'(x)$\n\t\t\\CorrectChoice $(f(x)\\cdot g(x))' = f'(x)g(x) + f(x)g'(x)$\n\t\\end{choices}\n\n\t\\item What is the derivative of $f(x) = \\sqrt{4x+5}$\n\n\t\\begin{choices}\n\t\t\\choice $2\\sqrt{x+5}$.\n\t\t\\choice $8$.\n\t\t\\choice $\\frac{\\sqrt{4x+5}}{2}$.\n\t\t\\CorrectChoice $\\frac{2}{\\sqrt{4x+5}}$.\n\t\\end{choices}\n\t\\item Calculate the derivative of $f(x) = 2x^2+3$\n\n\t\\begin{choices}\n\t\t\\CorrectChoice $f'(x) = 4x$\n\t\t\\choice $f'(x) = 2x$\n\t\t\\choice $f'(x) = 5x$\n\t\t\\choice $f'(x) = 6x$\n\t\\end{choices}\n\t\\item Calculate the derivative  of $y=\\sin(3x{^2}+1)$\n\n\t\\begin{choices}\n\t\t\\choice $\\dv{y}{x} = \\sin(3x{^2}+1)$\n\t\t\\choice $\\dv{y}{x} = \\cos(3x{^2}+1)$\n        \\choice $\\dv{y}{x} = 6x\\sin(3x{^2}+1)$\n\t\t\\CorrectChoice $\\dv{y}{x} = 6x \\cos(3x{^2}+1)$\n\t\\end{choices}\n\t\\item Find the derivative of $f(x) = \\sqrt[6]{4x+4}$\n\n\t\\begin{choices}\n\t\t\\choice $f'(x) = 4 (4x+4)^{-1/3} $\n\t\t\\choice $f'(x) = \\frac{4x }{6 \\sqrt[3]{4x+4}}$\n\t\t\\choice $f'(x) = \\frac{4 x + 4}{6 \\sqrt[6]{(4x + 4)^{5}}} $\n\t\t\\CorrectChoice $f'(x) = \\frac{4}{6 \\sqrt[6]{(4x + 4)^{5}}}$\n\t\\end{choices}\n\n\\end{itemize}\n\n\n\n\n\\section{Medium}\n\n\\begin{itemize}\n\t\\item What is the derivative of f(x)=$(1-6x^2)^4$\n\t\\begin{choices}\n\t\t\\choice $4(1-6x^2)^3$\n\t\t\\choice $4x(1-6x^2)^3$\n\t\t\\choice $48x(1-6x^2)^3$\n\t\t\\CorrectChoice $-48x(1-6x^2)^3 y$\n\t\\end{choices}\n\n\t\\item Find the slope of the tangent line of the curve $y = \\frac{1}{x}$ at the point $(3,\\frac13)$\n\n\t\\begin{choices}\n\t\t\\choice $\\frac{1}{3}$\n\t\t\\choice $\\frac{-1}{3}$\n\t\t\\choice $\\frac{1}{9}$\n\t\t\\CorrectChoice $\\frac{-1}{9}$\n\t\\end{choices}\n\n\t\\item Calculate the following limit: $\\lim_{x \\to -2} = \\frac{x^3+8}{x+2}\\ $\n\n\t\\begin{choices}\n\t\t\\choice $\\infty$.\n\t\t\\choice $4$.\n\t\t\\choice $1$.\n\t\t\\CorrectChoice $12$.\n\t\\end{choices}\n\t\\item  Is this function continuous or discontinuous? $f(x) = \\frac{x+8}{x-4}$\n\n\t\\begin{choices}\n\t\t\\choice  Continuous.\n\t\t\\choice Discontinuous, contains a removable discontinuities.\n\t\t\\choice No other answer is correct.\n\t\t\\CorrectChoice Discontinuous, contains a jump discontinuities.\n\t\\end{choices}\n\n\t\\item $\\displaystyle \\lim_{x\\to 4}{x^{2} + 2 x - 4}$ ?\n\n\t\\begin{choices}\n\t\t\\choice 14\n\t\t\\choice 16\n\t\t\\choice 18\n\t\t\\CorrectChoice 20\n\t\\end{choices}\n\n\t\\item What is the name of the functions $\\frac1{\\cos x}$ ?\n\t\\begin{choices}\n\t\t\\choice $\\csc x$\n\t\t\\choice $\\cot x$\n\t\t\\choice $\\tan x$\n\t\t\\CorrectChoice $\\sec x$\n\t\\end{choices}\n\n\t\\item Find the value of $\\displaystyle \\lim_{x \\to 6} \\frac{x^2 -36}{x^3 -216}$\n\n\t\\begin{choices}\n\t\t\\choice $\\frac{1}{6}$\n\t\t\\CorrectChoice $\\frac{1}{9}$\n\t\t\\choice $\\frac{1}{12}$\n\t\t\\choice $\\frac{1}{15}$\n\t\\end{choices}\n\t\\item What is the function $f$ whose derivative is $f'(x)=x^5 +30$\n\n    \\begin{choices}\n\t\t\\choice $f(x) = 5x^4 +30x$\n\t\t\\choice $f(x) = 5x^4$\n\t\t\\choice $f(x) = x^6 +30x$\n\t\t\\CorrectChoice $f(x) = \\frac{x^6}{6} +30x$\n\t\\end{choices}\n\t\\item Find the derivative of $f(x) = \\frac{x-1}{x+1}$\n\n\t\\begin{choices}\n\t\t\\choice $f'(x) = \\frac{-2}{(x+1)^2}$\n\t\t\\choice $f'(x) = \\frac{2}{(x-1)^2}$\n\t\t\\choice $f'(x) = \\frac{-2}{(x-1)^2}$\n\t\t\\CorrectChoice $f'(x) = \\frac{2}{(x+1)^2}$\n\t\\end{choices}\n\n\\end{itemize}\n\n\n\n\n\\section{Hard}\n\n\\begin{itemize}\n\t\\item  Calculate $\\lim_{x\\to 1}\\frac{\\sin (2x^2-2)}{x^2-1}$. (Hint: L'H\\^opital rule)\n\n\t\\begin{choices}\n\t\t\\choice   $1$\n\t\t\\choice  $-1$\n\t\t\\choice  The limit does not exist.\n\t\t\\CorrectChoice  $2$\n\t\\end{choices}\n\t\\item What is the local minimum of $x^3-2x^2$ in the range where $-1<x<1$?\n\n\t\\begin{choices}\n\t\t\\choice  $x=0$\n\t\t\\choice  $x=-1$\n\t\t\\choice There is no local minimum in that range.\n\t\t\\CorrectChoice  $x=\\frac43$\n\t\\end{choices}\n\t\\item What is the derivative of $f(x) = 2x \\sin x + 2 \\cos x - x^{2}\\cos x.$\n\n\t\\begin{choices}\n\t\t\\choice $f'(x) = x^{2} \\sin x + 2 x \\cos x -2\\sin x$.\n\t\t\\choice $f'(x) = x^{2}\\cos x$.\n\t\t\\choice $f'(x) = 2x\\cos x$.\n\t\t\\CorrectChoice $f'(x) = x^{2}\\sin x$.\n\t\\end{choices}\n\n\t\\item What is value of the $\\displaystyle \\lim_{h \\to 0} \\frac{f(x+h) -f(x)}{h}$ tells about the function?\n\n\t\\begin{choices}\n\t\t\\choice\\label{choice:der1} The Slope of the graph.\n\t\t\\choice\\label{choice:der2} The critical point of the function , when the value of the limit is 0.\n\t\t\\CorrectChoice Both options, \\ref{choice:der1} and \\ref{choice:der2}, are correct.\n\t\t\\choice None of the above.\n\t\\end{choices}\n\n\t\\item What is the derivative of $f(x) = \\arctan(2x)$ ?\n\n\t\\begin{choices}\n\t\t\\choice $\\frac{2}{1 + x^{2}}$\n\t\t\\choice $\\frac{2}{2 + x^{2}}$\n\t\t\\choice $\\frac{2}{2 + 4x^{2}}$\n\t\t\\CorrectChoice $\\frac{2}{1 + 4x^{2}}$\n\t\\end{choices}\n\t\\item Find the derivatives of f(x) = $\\sin^6(x^4)$\n\n\t\\begin{choices}\n\t\t\\choice $6\\sin^{5}(x^4)$\n\t\t\\choice $24 x^{3}\\sin(x^3) \\sin(x^4)$\n\t\t\\choice $24\\sin(x^4)  \\cos(x^3)$\n\t\t\\CorrectChoice $24 x^{3} \\sin^{5}(x^4)  \\cos(x^4) $\n\t\\end{choices}\n\t\\item Find the derivative of $f(x)$ = $\\sqrt{x^2+3x}$.\n\n\t\\begin{choices}\n\t\t\\choice $f'(x) = \\frac{1}{2}\\sqrt{2x+3}$.\n\t\t\\choice $f'(x) = \\frac{1}{x^2+3x}(2x+3)$.\n\t\t\\choice $f'(x) = \\frac{-1}{2 \\sqrt{2x + 3}}$.\n\t\t\\CorrectChoice $f'(x) = \\frac{2x + 3}{2 \\sqrt{2x + 3}}$.\n\t\\end{choices}\n\n\n\\end{itemize}\n\n\n\\section{Graphic problems}\n\n\\begin{itemize}\n\t\\item\n\tFrom the following graph find $\\lim_{x \\to -2 } f(x)$\n\t\\par\\nopagebreak\n\t\\includegraphics[width = 6cm]{limgraph.jpg}\n\n\t\\begin{choices}\n\t\t\\choice $0$.\n\t\t\\choice $5$.\n\t\t\\choice $4$.\n\t\t\\CorrectChoice undefined.\n\t\\end{choices}\n\n\\end{itemize}\n\n\n\\section{Bonus, integration}\n\n\\begin{itemize}\n\t\\item Find the area of the graph between f(x) = $x^4$ and f(x) = $(x-6)^4$\n\n\t\\begin{choices}\n\t\t\\choice $\\frac{243}{5}$\n\t\t\\choice $\\frac{243}{10}$\n\t\t\\choice $\\frac{486}{10}$\n\t\t\\CorrectChoice $\\frac{486}{5}$\n\t\\end{choices}\n\t\\item Find the integral of $ 4x^3+3x^2 $\n\n\t\\begin{choices}\n\t\t\\choice $12x^2 + 6x$\n\t\t\\choice $4x^2 + 3x$\n\t\t\\choice $4x^4 + 3x^3 + c$\n\t\t\\CorrectChoice $x^4 + x^3 +c$\n\t\\end{choices}\n\t\\item What is the area under the graph $y = x^3$, the line $y = 0$ and the lines $x=0$ and $x=2$?\n\n\t\\begin{choices}\n\t\t\\choice 8\n\t\t\\choice 16\n\t\t\\choice 24\n\t\t\\CorrectChoice 4\n\t\\end{choices}\n\t\\item Which of these processes are used to calculate the area under a curve?\n\t\\begin{choices}\n\t\t\\choice First derivative\n\t\t\\choice Product rule\n\t\t\\choice Second derivative\n\t\t\\CorrectChoice Integral\n\t\\end{choices}\n\n\n\n\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "d9a0c3aabb7ce5c06b4ec81dc0f2179a1a63eb8b", "size": 12807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inst/extdata/ExampleTexDocuments/exam_testing_itemize.tex", "max_stars_repo_name": "alexrecuenco/TexExamRandomizer", "max_stars_repo_head_hexsha": "8284ffdda2a116a8c448ce371706fa056d270905", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-01T16:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-01T16:11:20.000Z", "max_issues_repo_path": "inst/extdata/ExampleTexDocuments/exam_testing_itemize.tex", "max_issues_repo_name": "alexrecuenco/TexExamRandomizer", "max_issues_repo_head_hexsha": "8284ffdda2a116a8c448ce371706fa056d270905", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-02-13T01:00:18.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-15T01:46:24.000Z", "max_forks_repo_path": "inst/extdata/ExampleTexDocuments/exam_testing_itemize.tex", "max_forks_repo_name": "alexrecuenco/TexExamRandomizer", "max_forks_repo_head_hexsha": "8284ffdda2a116a8c448ce371706fa056d270905", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-06T00:57:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T23:33:51.000Z", "avg_line_length": 26.8490566038, "max_line_length": 136, "alphanum_fraction": 0.6112282346, "num_tokens": 5286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.6813838127923034}}
{"text": "% !TEX root = ../master/master.tex\n\n%% Dexter Barrows, 2016\n%% dbarrows.github.io\n\n\\section{Spatial SIR}\n\n\tSpatial epidemic models provide a way to capture not just the temporal trend in an epidemic, but to also integrate spatial data and infer how the infection is spreading in both space and time. One such model we can use is a dynamic spatiotemporal SIR model.\n\n\tWe wish to construct a model build upon the stochastic SIR compartment model described previously but one that consists of several connected spatial locations, each with its own set of compartments. Consider a set of locations numbered $i = 1, ..., N$, where $N$ is the number of locations. Further, let $N_i$ be the number of neighbours location $i$ has. The model is then\n\n\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\t\t\\frac{dS_i}{dt} & = - \\left( 1 - \\phi \\frac{N_i}{N_i + 1} \\right) \\beta_i S_i I_i - \\left( \\frac{\\phi}{N_i + 1} \\right) S_i \\sum_{j = 0}^{N_i} \\beta_j I_j \\\\\n\t\t\t\\frac{dI_i}{dt} & = \\left( 1 - \\phi \\frac{N_i}{N_i + 1} \\right) \\beta_i S_i I_i + \\left( \\frac{\\phi}{N_i + 1} \\right) S_i \\sum_{j = 0}^{N_i} \\beta_j I_j - \\gamma I \\\\\n\t\t\t\\frac{dR_i}{dt} & = \\gamma I,\n\t\t\\end{aligned}\n\t\\end{equation}\n    \n\tNeighbours for a particular location are numbered $j = 1, ..., N_i$. We have a new parameter, $\\phi \\in [0,1]$, which is the degree of connectivity. If we let $\\phi = 0$ we have total spatial isolation, and the dynamics reduce to the basic SIR model. If we let $\\phi = 1$ then each of the neighbouring locations will have weight equivalent to the parent location.\n\n\tAs before we let $\\beta$ embark on a geometric random walk defined as\n\n\t\\begin{equation}\n\t\t\\beta_{i, t+1} = \\exp \\left( \\log(\\beta_{i, t}) + \\eta (\\log(\\bar{\\beta}) - \\log(\\beta_{i, t})) + \\epsilon_{t} \\right).\n\t\\end{equation}\n\t\n\tNote that as $\\beta$ is a state variable, each location has its own stochastic process driving the evolution of its $\\beta$ state.\n\n\tIf we imagine a circular topology in which each of $8$ locations is connected to exactly two neighbours (i.e. location $1$ is connected to locations $N$ and $2$, location $2$ is connected to locations $1$ and $3$, etc.), and we start each location with completely susceptible populations except for a handful of infected individuals in one of the locations, we obtain a plot of the outbreak progression in Figure [\\ref{spatialdataplot}].\n\n\t\\begin{figure}\n        \\centering\n        \\captionsetup{width=.8\\linewidth}\n        \\includegraphics[width=0.8\\textwidth]{./images/dataplot.pdf}\n        \\caption{Evolution of a spatial epidemic in a ring topology. The outbreak was started with 5 cases in Location 2. Parameters were $\\mathcal{R}_0 = 3.0$, $\\gamma = 0.1$, $\\eta = 0.5$, $\\sigma_{err} = 0.5$, and $\\phi = 0.5$. \\label{spatialdataplot}}\n    \\end{figure}\n\n    If we add noise to the data from Figure [\\ref{spatialdataplot}], we obtain Figure [\\ref{spatialdataplot2}].\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=.8\\linewidth}\n        \\includegraphics[width=0.8\\textwidth]{./images/dataplot2.pdf}\n        \\caption{Evolution of a spatial epidemic as in Figure [\\ref{spatialdataplot}], with added observation noise drawn from $\\mathcal{N}(0,10)$. \\label{spatialdataplot2}}\n    \\end{figure}\n\n\n\\section{Dewdrop Regression}\n\n\tDewdrop regression \\cite{Hsieh2008} aims to overcome the primary disadvantage suffered by methods such as the S-map or its cousin Simplex Projection: the requirement of long time series from which to build a library. Suggested by Sugihara's group in 2008, Dewdrop Regression works by stitching together shorter, related, time series, in order to give the S-map or similar methods  enough data to operate on. The underlying idea is that as long as the underlying dynamics of the time series display similar behaviour (such as potentially collapsing to the same attractor), they can be treated as part of the same overarching system.\n\n\tIt is not enough to simply concatenate the shorter time series together -- several procedures must be carried out and a few caveats observed. First, as the individual time series can be or drastically differing scales and breadths, they all must be rescaled to unit mean and variance. Then the library is constructed as before with an embedding dimension $E$, but any library vectors that span any of the seams joining the time series are discarded. Further, and predictions stemming from a library vector must stay within the time series from which they originated. In this way we are allowing the ``shadow'' of of the underlying dynamics of the separate time series to infer the forecasts for segments of other time series. Once the library has been constructed, S-mapping can be carried out as previously specified.\n\n\tThis procedure is especially well-suited to the spatial model we are using. While the dynamics are stochastic, they still display very similar means and variances. This means the rescaling process in Dewdrop Regression is not necessary and can be skipped. Further, the overall variation between the epidemic curves in each location is on the smaller side, meaning the S-map will have a high-quality library from which to build forecasts.\n\n\n\\section{Spatial Model Forecasting}\n\n\tIn order to compare the forecasting efficacy of Dewdrop Regression with S-mapping against IF2 and HMC, we generated 20 independent spatial data sets up to time $T = 50$ weeks in each of $L = 10$ locations and forecasted $10$ weeks into the future. Forecasts were compared to that of the true model evolution, and the average $SSE$ for each week ahead in the forecast were computed. The number of bootstrapping trajectories used by IF2 and HMC was reduced from 200 to 50 to curtail running times.\n\n\tThe results are shown in Figure [\\ref{spatialsseplot}]. \n\n\t\\begin{figure}\n        \\centering\n        \\captionsetup{width=.8\\linewidth}\n        \\includegraphics[width=0.8\\textwidth]{./images/sseplot.pdf}\n        \\caption{Average SSE (log scale) across each location and all trials as a function  of the number of weeks ahead in the forecast. \\label{spatialsseplot}}\n    \\end{figure}\n\n    The results show a clear delineation in forecast fidelity between methods. IF2 maintains an advantage regardless of how long the forecast produced. Interestingly, Dewdrop Regression with S-mapping performs almost as well as IF2, and outperforms HMC. HMC lags behind both methods by a healthy margin.\n\n    If we examine the runtimes for each forecast framework, we obtain the data in Figure [\\ref{spatialtimeplot}].\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=.8\\linewidth}\n        \\includegraphics[width=0.8\\textwidth]{./images/timeplot.pdf}\n        \\caption{Runtimes for producing spatial SIR forecasts. The box shows the middle 50th percent, the bold line is the median, and the dots are outliers. \\label{spatialtimeplot}}\n    \\end{figure}\n\n    As before, the S-map with Dewdrop Regression runs faster than the other two methods with a huge margin. It is again hard to see exactly how large the margin is from the figure due to the scale, but we can examine the average values: the average running time for S-mapping with Dewdrop Regression was about $249$ seconds, whereas the average times for IF2 and HMC were about $29,000$ seconds and $38,800$ seconds, respectively. This is a speed-up of just over 116x over IF2 and 156x over HMC.\n\n    Considering how well S-mapping performed with regards to forecast error, it shows a significant advantage over HMC in particular -- it outperforms it in both forecast error and running times.\n\n    As before, we are interested in coverage. Again, a full coverage analysis would require roughly a 100-fold increase in computational complexity, but we can use the trajectories generated by IF2 and HMC to display forecast coverage across data sets, given particular weeks in the forecast.\n\n    Figure [\\ref{sirscoverage}] shows such plots for forecasts 2 and 10 weeks ahead in location 8. Location 8 was used as it lands in the middle of the cohort of locations in terms of outbreak progression. We can see that the error bars are much wider when attempting to predict further into the future. HMC is consistently underestimates the intensity of the epidemic in both forecast lengths, but produces smaller error bars for the longer forecast.\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=.8\\linewidth}\n        \\includegraphics[width=0.8\\textwidth]{./images/coverage.pdf}\n        \\caption{Coverage plots for forecast weeks 2 (top) and 10 (bottom) in location 8. Black bars are from IF2 forecast trajectories, and grey bars are from HMC trajectories. \\label{sirscoverage}}\n    \\end{figure}", "meta": {"hexsha": "613ba13c7544a5cddc0485b8d7a060721c037591", "size": 8645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writing/SPATIAL/spatial-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/SPATIAL/spatial-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/SPATIAL/spatial-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": 91.0, "max_line_length": 819, "alphanum_fraction": 0.7489878543, "num_tokens": 2149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6813838057511112}}
{"text": "\n\\documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size\n\\usepackage{physics}\n\\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs\n\\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default\n\\usepackage[english]{babel} % English language/hyphenation\n\\usepackage{amsmath,amsfonts,amsthm} % Math packages\n\\usepackage{braket}\n\\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template\n\\usepackage{tikz}\n\\usepackage{amsmath}\n\\usepackage{sectsty} % Allows customizing section commands\n\\allsectionsfont{\\centering \\normalfont\\scshape} % Make all sections centered, the default font and small caps\n\\usepackage[mathscr]{euscript}\n\\usepackage{bm}\n\\newcommand{\\uvec}[1]{\\boldsymbol{\\hat{\\textbf{#1}}}}\n\\usepackage[thinlines]{easytable}\n\\usepackage{fancyhdr} % Custom headers and footers\n\\pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers\n\\fancyhead{} % No page header - if you want one, create it in the same way as the footers below\n\n\\usepackage{multicol}\n\\fancyfoot[L]{} % Empty left footer\n\\fancyfoot[C]{} % Empty center footer\n\\fancyfoot[R]{\\thepage} % Page numbering for right footer\n\\renewcommand{\\headrulewidth}{0pt} % Remove header underlines\n\\renewcommand{\\footrulewidth}{0pt} % Remove footer underlines\n\\setlength{\\headheight}{13.6pt} % Customize the height of the header\n\\usepackage{float}\n\\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\n\\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\n\\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\n\n\\setlength\\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text\n\\usepackage{pgfplots}\n\n\\pgfplotsset{\n  compat=newest,\n  xlabel near ticks,\n  ylabel near ticks\n}\n%----------------------------------------------------------------------------------------\n%\tTITLE SECTION\n%----------------------------------------------------------------------------------------\n\n\\newcommand{\\horrule}[1]{\\rule{\\linewidth}{#1}} % Create horizontal rule command with 1 argument of height\n\n\\title{\t\n\\normalfont \\normalsize \n\\textsc{California State University San Marcos \\\\ Dr. De Leone, Physics 323} \\\\ [25pt] % Your university, school and/or department name(s)\n\\horrule{0.5pt} \\\\[0.4cm] % Thin top horizontal rule\n\\huge H.W. 5 \\\\ % The assignment title\n\\horrule{2pt} \\\\[0.5cm] % Thick bottom horizontal rule\n}\n\n\\author{Josh Lucas} % Your name\n\n\\date{\\normalsize\\today} % Today's date or a custom date\n\n\\begin{document}\n\n\\maketitle % Print the title\n\n%----------------------------------------------------------------------------------------\n%\tPROBLEM 1\n%----------------------------------------------------------------------------------------\n\n\\section*{Problem 1.13}\n\\textbf{Consider a quantum system with an observable A that has three possible measurement\nresults: a1, a2, and a3.}\\\\\n\\textbf{a) Write down the three kets $\\ket{a_1}, \\ket{a_2}, \\ket{a_3},$ corresponding to these possible results\nusing matrix notation.}\\\\\n\\\\\nWe can write the state vectors in matrix notation by choosing  orthogonal directions for each observable, giving them a magnitude of one and writing them in column form.\n$$\n\\ket{a_1} =\n\\begin{pmatrix}\n1\\\\ 0\\\\0\n\\end{pmatrix},\n\\quad\n\\ket{a_2} =\n\\begin{pmatrix}\n0\\\\ 1\\\\0\n\\end{pmatrix},\n\\quad\n\\ket{a_3} = \n\\begin{pmatrix}\n0\\\\0\\\\1\n\\end{pmatrix}\n$$\n\\textbf{b) The system is prepared in the state}\\\\\n$$\\ket{\\psi} = 1\\ket{a_1} -2\\ket{a_2} +5\\ket{a_3}$$\n\\textbf{Write this state in matrix notation and calculate the probabilities of all possible measurement\nresults of the observable A. Plot a histogram of the predicted measurement results.}\\\\\n\\\\\nThe magnitude of each observable is multiplied by its unit vector.\n\\begin{equation*}\n\\ket{\\psi} = \\begin{pmatrix}\n1\\\\0\\\\0\n\\end{pmatrix} -\n2 \\begin{pmatrix}\n0\\\\1\\\\0\n\\end{pmatrix} +\n5 \\begin{pmatrix}\n0\\\\0\\\\1\n\\end{pmatrix}\\ =\\\n\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix}\n\\end{equation*}\nWe need to normalize the wave function by dividing the ket by its magnitude,\n\\begin{align*}\n\\ket{\\psi} & = C\n\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix} \\\\\n\\braket{\\psi|\\psi} & = C^2 (\\ 1\\quad -2\\quad 5\\ ) \n\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix}\\\\\n& = C^2(1+4+25) \\\\\nC & = \\frac{1}{\\sqrt{30}}\\\\\n\\ket{\\psi} & = \\frac{1}{\\sqrt{30}} \n\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix}\n\\end{align*}\nWe can find the probabilities of each result by multiplying possible bra measurement direction with the normalized ket, \n\\begin{multicols}{3}\n\\noindent\n\\begin{align*}\n\\mathscr{P}_{a_1} & = \\bigg| \\braket{a_1|\\psi} \\bigg|^2 \\\\\n& = \\Bigg| (\\ 1\\quad 0\\quad 0\\ ) \n\\frac{1}{\\sqrt{30}}\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix} \n \\Bigg|^2 \\\\\n& = \\Big | \n\\frac{1}{\\sqrt{30}} \n  \\Big |^2 \\\\\n  \\mathscr{P}_{a_1} & = \\frac{1}{30}\n\\end{align*}\n\\begin{align*}\n\\mathscr{P}_{a_2} & = \\bigg| \\braket{a_2|\\psi} \\bigg|^2 \\\\\n& = \\Bigg| (\\ 0\\quad 1\\quad 0\\ ) \n\\frac{1}{\\sqrt{30}}\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix} \n \\Bigg|^2 \\\\\n& = \\Big | \n\\frac{-2}{\\sqrt{30}} \n  \\Big |^2 \\\\\n  \\mathscr{P}_{a_2} & = \\frac{4}{30}\n\\end{align*}\n\\begin{align*}\n\\mathscr{P}_{a_3} & = \\bigg| \\braket{a_3|\\psi} \\bigg|^2 \\\\\n& = \\Bigg| (\\ 0\\quad 0\\quad 1\\ ) \n\\frac{1}{\\sqrt{30}}\\begin{pmatrix}\n1\\\\-2\\\\5\n\\end{pmatrix} \n \\Bigg|^2 \\\\\n& = \\Big | \n\\frac{5}{\\sqrt{30}} \n  \\Big |^2 \\\\\n  \\mathscr{P}_{a_3  } & = \\frac{25}{30} = \\frac{5}{6}\n\\end{align*}\n\\end{multicols}\n\\begin{center}\n\\begin{tikzpicture}\n    \\begin{axis}[\n      ybar,\n      bar width=15pt,\n      xlabel={$\\bra{\\psi}$},\n      ylabel={Probability},\n      ymin=0,\n      ymax =100,\n      ytick=\\empty,\n      xtick=data,\n      axis x line=bottom,\n      axis y line=left,\n      enlarge x limits=0.2,\n      symbolic x coords={ $ a_1$, $ a_2$, $a_3$ },\n      xticklabel style={anchor=base,yshift=-\\baselineskip},\n      nodes near coords={\\pgfmathprintnumber\\pgfplotspointmeta\\%}\n    ]\n      \\addplot[fill=white] coordinates {\n        ($ a_1$,3.33)\n        ($ a_2$,13.3)\n        ($a_3$, 83.3)\n      };\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\n\\textbf{c) In a different experiment, the system is prepared in the state}\\\\\n$$\n\\ket{\\psi} = 2\\ket{a_1} +3i\\ket{a_2}\n$$\n\\textbf{Write this state in matrix notation and calculate the probabilities of all possible measurement\nresults of the observable A. Plot a histogram of the predicted measurement results.}\n\\begin{align*}\n\\ket{\\psi} & = \n\\begin{pmatrix}\n2\\\\3i\\\\0\n\\end{pmatrix} \\quad \\text{Normalize the function} \\\\\n\\braket{\\psi|\\psi} & = C^* (\\ 2\\quad -3i\\quad 0\\ )\\ \nC \\begin{pmatrix}\n2\\\\ 3i\\\\ 0\n\\end{pmatrix}\\\\\n& = C^2 (4 + 9)\\\\\nC & = \\frac{1}{\\sqrt{13}} \\\\\n\\ket{\\psi} & = \\frac{1}{\\sqrt{13}}\n\\begin{pmatrix}\n2\\\\3i \\\\ 0\n\\end{pmatrix}\n\\end{align*}\n\n\\begin{multicols}{3}\n\\noindent\n\\begin{align*}\n\\mathscr{P}_{a_1} & = \\bigg| \\braket{a_1|\\psi} \\bigg|^2 \\\\\n& = \\Bigg| (\\ 1\\quad 0\\quad 0\\ ) \n\\frac{1}{\\sqrt{13}}\\begin{pmatrix}\n2\\\\3i\\\\0\n\\end{pmatrix} \n \\Bigg|^2 \\\\\n& = \\Big | \n\\frac{2}{\\sqrt{13}} \n  \\Big |^2 \\\\\n  \\mathscr{P}_{a_1} & = \\frac{4}{13}\n\\end{align*}\n\\begin{align*}\n\\mathscr{P}_{a_2} & = \\bigg| \\braket{a_2|\\psi} \\bigg|^2 \\\\\n& = \\Bigg| (\\ 0\\quad 1\\quad 0\\ ) \n\\frac{1}{\\sqrt{13}}\\begin{pmatrix}\n2\\\\3i\\\\0\n\\end{pmatrix} \n \\Bigg|^2 \\\\\n& = \\Big | \n\\frac{3i}{\\sqrt{13}} \n  \\Big |^2 \\\\\n  \\mathscr{P}_{a_2} & = \\frac{9}{13}\n\\end{align*}\n\\begin{align*}\n\\mathscr{P}_{a_3} & = \\bigg| \\braket{a_3|\\psi} \\bigg|^2 \\\\\n& = \\Bigg| (\\ 0\\quad 0\\quad 1\\ ) \n\\frac{1}{\\sqrt{13}}\\begin{pmatrix}\n2\\\\3i\\\\0\n\\end{pmatrix} \n \\Bigg|^2 \\\\\n& = 0 \\\\\n  \\mathscr{P}_{a_3} & = 0\n\\end{align*}\n\\end{multicols}\n\n\n\n\\begin{center}\n\\begin{tikzpicture}\n    \\begin{axis}[\n      ybar,\n      bar width=15pt,\n      xlabel={$\\bra{\\psi}$},\n      ylabel={Probability},\n      ymin=0,\n      ymax =100,\n      ytick=\\empty,\n      xtick=data,\n      axis x line=bottom,\n      axis y line=left,\n      enlarge x limits=0.2,\n      symbolic x coords={ $ a_1$, $ a_2$, $a_3$ },\n      xticklabel style={anchor=base,yshift=-\\baselineskip},\n      nodes near coords={\\pgfmathprintnumber\\pgfplotspointmeta\\%}\n    ]\n      \\addplot[fill=white] coordinates {\n        ($ a_1$,30.7)\n        ($ a_2$,69.2)\n        ($a_3$, 0)\n      };\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 1.15}\n\\textbf{Consider a quantum system described by a basis} $\\ket{a_1}, \\ket{a_2},$ and $\\ket{a_3}$. \\textbf{The system is initially in a state}\\\\\n\\begin{equation*}\n\\ket{\\psi_i} = \\tfrac{i}{\\sqrt{3}} \\ket{a_1} + \\sqrt{\\tfrac{2}{3}} \\ket{a_2}.\n\\end{equation*}\n\\textbf{Find the probability that the system is measured to be in the final state}\n\\begin{equation*}\n\\ket{\\psi_f} = \\tfrac{1+i}{\\sqrt{3}} \\ket{a_1} + \\frac{1}{\\sqrt{6}} \\ket{a_2} +\\tfrac{1}{\\sqrt{6}} \\ket{a_3}.\n\\end{equation*}\n\\begin{align*}\n\\mathscr{P}_{\\psi_f} & = \\Big |\\braket{\\psi_f|\\psi_i} \\bigg|^2 \\\\\n& = \\Bigg|\\bigg(\\tfrac{1-i}{\\sqrt{3}}\\quad \\tfrac{1}{\\sqrt{6}}\\quad \\tfrac{1}{\\sqrt{6}} \\bigg)  \n\\begin{pmatrix}\n\\tfrac{i}{\\sqrt{3}} \\\\\n\\sqrt{\\tfrac{2}{3}} \\\\\n0\n\\end{pmatrix}\n \\Bigg|^2 \\\\\n & =  \\Bigg |  \\frac{1-i}{3} + \\sqrt{\\frac{2}{9}} + 0  \\Bigg |^2 \\\\\n & =  \\Bigg |  \\frac{1-i}{3} + \\frac{1}{3}  \\Bigg |^2 \\\\\n & = \\Bigg (  \\frac{2}{3} + \\frac{1}{3}  \\Bigg )^2 \\\\\n \\mathscr{P}_{\\psi_f} & = \\frac{5}{9} \n\\end{align*}\n%----------------------------------------------------------------------------------------\n\\section*{Problem 1.16}\n\\textbf{The spin components of a beam of atoms prepared in the state} $\\ket{\\psi_{in}}$ \\textbf{are measured and the following\nexperimental probabilities are obtained:}\n\\begin{multicols}{3}\n\\noindent\n\\begin{align*}\n\\mathscr{P}_+ & = \\tfrac{1}{2} \\\\\n\\mathscr{P}_- & = \\tfrac{1}{2}\n\\end{align*}\n\\begin{align*}\n\\mathscr{P}_{+x} & = \\tfrac{3}{4} \\\\\n\\mathscr{P}_{-x} & = \\tfrac{1}{4}\n\\end{align*}\n\\begin{align*}\n\\mathscr{P}_{+y} & = 0.067 \\\\\n\\mathscr{P}_{-y} & = 0.933\n\\end{align*}\n\\end{multicols}\n\\textbf{From the experimental data, determine the input state.}\n\\begin{align*}\n\\frac{1}{2} & = \\big | \\braket{+|\\psi} \\big |^2  &  \\frac{1}{2} & = \\big | \\braket{-|\\psi} \\big |^2                                    \\\\\n& = \\bigg | \\bra{+} \\bigg \\{ a\\ket{+} + b\\ket{-} \\Bigg \\} \\bigg|^2 &    & = \\bigg | \\bra{-} \\bigg \\{ a\\ket{+} + b\\ket{-} \\Bigg \\} \\bigg|^2                   \\\\\n& = \\bigg | a \\braket{+|+} \\bigg|^2         &        & = \\bigg | b \\braket{-|-} \\bigg|^2                                      \\\\\n& = \\bigg | a \\bigg |^2       &         & = \\bigg | b \\bigg |^2                                                    \\\\\na & = \\frac{1}{\\sqrt{2}}  &   b & = \\frac{1}{\\sqrt{2}}\n\\end{align*}\n\\horrule{2pt}\n\\begin{multicols}{2}\n\\noindent\n\\begin{align*}\n\\tfrac{3}{4} & = \\big | \\braket{+_x| \\psi}  \\big |^2 \\\\\n\\tfrac{3}{4} & = \\bigg |  \\tfrac{1}{\\sqrt{2}} \\bigg ( \\bra{+} + \\bra{-} \\bigg ) \\tfrac{1}{\\sqrt{2}} \\bigg ( \\ket{+}  + e^{i\\phi}\\ket{-} \\bigg )  \\bigg |^2 \\\\\n& = \\bigg | \\tfrac{1}{2} \\big ( 1 + e^{i\\phi}  \\big )  \\bigg|^2 \\\\\n& = \\tfrac{1}{4} \\big ( 1 + e^{i\\phi}  \\big ) \\big ( 1 + e^{-i\\phi}   \\big ) \\\\\n& = \\tfrac{1}{4} \\big (  1^2 + 2\\cos(\\phi) + e^0 \\big ) \\\\\n& = \\tfrac{1}{4} \\big ( 2 + 2\\cos(\\phi) \\big ) \\\\\n& + \\tfrac{1}{2} \\big (  1 + \\cos(\\phi) \\big ) \\\\\n\\tfrac{3}{2} - 1 & = \\cos(\\phi) \\\\\n\\cos^{-1}(\\tfrac{1}{2}) &= \\pm \\tfrac{\\pi}{3}\n\\end{align*}\n\\begin{align*}\n\\tfrac{1}{4} & = \\big | \\braket{-_x| \\psi}  \\big |^2 \\\\\n\\tfrac{1}{4} & = \\bigg |  \\tfrac{1}{\\sqrt{2}} \\bigg ( \\bra{+} - \\bra{-} \\bigg ) \\tfrac{1}{\\sqrt{2}} \\bigg ( \\ket{+}  + e^{i\\phi}\\ket{-} \\bigg )  \\bigg |^2 \\\\\n& = \\bigg | \\tfrac{1}{2} \\big ( 1 - e^{i\\phi}  \\big )  \\bigg|^2 \\\\\n& = \\tfrac{1}{4} \\big ( 1 - e^{i\\phi}  \\big ) \\big ( 1 - e^{-i\\phi}   \\big ) \\\\\n& = \\tfrac{1}{4} \\big (  1^2 - 2\\cos(\\phi) + e^0 \\big ) \\\\\n& = \\tfrac{1}{4} \\big ( 2 - 2\\cos(\\phi) \\big ) \\\\\n& = \\tfrac{1}{2} \\big (  1 - \\cos(\\phi) \\big ) \\\\\n\\cos(\\phi) & = 1- \\tfrac{1}{2}  \\\\\n\\cos^{-1}(\\tfrac{1}{2}) & =  \\pm \\tfrac{\\pi}{3}\n\\end{align*}\n\\end{multicols}\n\\horrule{2pt}\n\\begin{multicols}{2}\n\\noindent\n\\begin{align*}\n0.067 & = \\big | \\braket{+_y| \\psi}  \\big |^2 \\\\\n & = \\bigg |  \\tfrac{1}{\\sqrt{2}} \\bigg ( \\bra{+} -i \\bra{-} \\bigg ) \\tfrac{1}{\\sqrt{2}} \\bigg ( \\ket{+}  + e^{i\\phi}\\ket{-} \\bigg )  \\bigg |^2 \\\\\n& = \\bigg | \\tfrac{1}{2} \\big ( 1 - ie^{i\\phi}  \\big )  \\bigg|^2 \\\\\n& = \\tfrac{1}{4} \\big ( 1 - ie^{i\\phi}  \\big ) \\big ( 1 + ie^{-i\\phi}   \\big ) \\\\\n& = \\tfrac{1}{4} \\big (  1^2 + 2\\sin(\\phi) + e^0 \\big ) \\\\\n& = \\tfrac{1}{4} \\big ( 1+ 2\\sin(\\phi) \\big ) \\\\\n& = \\tfrac{1}{2} \\big (  1 + \\sin(\\phi) \\big ) \\\\\n\\sin(\\phi) & = 2(0.067) - 1 \\\\\n\\sin^{-1}(-0.866) & = - \\tfrac{\\pi}{3 } \\ or\\ -\\tfrac{2\\pi}{3}\n\\end{align*}\n\\begin{align*}\n0.933 & = \\big | \\braket{+_y| \\psi}  \\big |^2 \\\\\n & = \\big |  \\tfrac{1}{\\sqrt{2}} \\big ( \\bra{+} +i \\bra{-} \\bigg ) \\tfrac{1}{\\sqrt{2}} \\big ( \\ket{+}  + e^{i\\phi}\\ket{-} \\big )  \\bigg |^2 \\\\\n& = \\bigg | \\tfrac{1}{2} \\big ( 1 + ie^{i\\phi}  \\big )  \\bigg|^2 \\\\\n& = \\tfrac{1}{4} \\big ( 1 + ie^{i\\phi}  \\big ) \\big ( 1 - ie^{-i\\phi}   \\big ) \\\\\n& = \\tfrac{1}{4} \\big (  1^2 + 2\\sin(\\phi) + e^0 \\big ) \\\\\n& = \\tfrac{1}{4} \\big ( 1+ 2\\sin(\\phi) \\big ) \\\\\n& = \\tfrac{1}{2} \\big (  1 + \\sin(\\phi) \\big ) \\\\\n\\sin(\\phi) & = 2(0.933) - 1 \\\\\n\\sin^{-1}(0.866) & = \\pm \\tfrac{\\pi}{3 } \\ \n\\end{align*}\n\\end{multicols}\n\\begin{equation*}\n\\ket{\\psi_{in}} = \\tfrac{1}{\\sqrt{2}} \\big ( \\ket{+} + e^{-i\\tfrac{\\pi}{3}} \\ket{-} \\big )\n\\end{equation*}\n\\end{document}", "meta": {"hexsha": "1829f1a37c3d5892606bcfebc31a39d666b67184", "size": 13475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "H.W.5 Due Monday 9-17-2018/H.W.5.tex", "max_stars_repo_name": "Epikarsios/QuantumHW", "max_stars_repo_head_hexsha": "1db9c1f3d6e4627a6848a69b8530b9f24c14a889", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "H.W.5 Due Monday 9-17-2018/H.W.5.tex", "max_issues_repo_name": "Epikarsios/QuantumHW", "max_issues_repo_head_hexsha": "1db9c1f3d6e4627a6848a69b8530b9f24c14a889", "max_issues_repo_licenses": ["MIT"], "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.W.5 Due Monday 9-17-2018/H.W.5.tex", "max_forks_repo_name": "Epikarsios/QuantumHW", "max_forks_repo_head_hexsha": "1db9c1f3d6e4627a6848a69b8530b9f24c14a889", "max_forks_repo_licenses": ["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.6401028278, "max_line_length": 169, "alphanum_fraction": 0.5626716141, "num_tokens": 5400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.8705972616934406, "lm_q1q2_score": 0.6813838021797596}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[fleqn]{amsmath}\n\\usepackage{textcomp}\n\\usepackage{gensymb}\n\\usepackage{amsfonts}\n\\usepackage{enumitem}\n%\\usepackage{tikz}  % Include for figures.\n%\\usepackage{subfiles}  % Include for subfiles.\n\n\\newcommand{\\HOMEWORKNUM}{6}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-05-29}\n\n\\title{\\vspace{-4\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Solve.}\n\\begin{align*}\n\t1x + 0y + 0z &= 0 \\\\\n\t0x + \\frac{1}{2}y + \\frac{1}{2}z &= 0 \\\\\n\t0x + \\frac{1}{2}y + \\frac{1}{2}z &= 1\n\\end{align*}\nThis system can be rewritten in matrix form $A\\vec{v} = \\vec{b}$ as\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t1 & 0 & 0 \\\\\n\t\t0 & \\frac{1}{2} & \\frac{1}{2} \\\\\n\t\t0 & \\frac{1}{2} & \\frac{1}{2}\n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty \\\\\n\t\tz\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t0 \\\\\n\t\t1\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\nSuch a matrix $A$ is an orthographic projection onto the plane $z = y$. \\\\\nSince the vector $\\vec{b}$ does not lie on the plane $z = y$,\n\\boxed{\\text{no solutions exist}}\nfor $\\vec{v}$.\n\n\\section*{2.}\n\\textit{Solve.}\n\\begin{align*}\n\t1x + 0y + 0z &= 10 \\\\\n\t0x + \\frac{1}{2}y + \\frac{1}{2}z &= 5 \\\\\n\t0x + \\frac{1}{2}y + \\frac{1}{2}z &= 5\n\\end{align*}\nThis system can be rewritten (again) in matrix form $A\\vec{v} = \\vec{c}$ as\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t1 & 0 & 0 \\\\\n\t\t0 & \\frac{1}{2} & \\frac{1}{2} \\\\\n\t\t0 & \\frac{1}{2} & \\frac{1}{2}\n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty \\\\\n\t\tz\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t10 \\\\\n\t\t5 \\\\\n\t\t5\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\nSuch a matrix $A$ is (still) an orthographic projection onto the plane\n$z = y$. \\\\\nThus, solutions to the system are in the form\n\\begin{equation*}\n\t\\vec{v} =\n\t\\boxed{\n\t\t\\vec{c} + s \\begin{pmatrix} 0 \\\\ 1 \\\\ -1 \\end{pmatrix}\n\t}\n\t,\n\\end{equation*}\nwhere $s \\in \\mathbb{R}$.\n\n\\section*{3.}\n\\textit{Solve.}\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t\\cos(30 \\degree) & -\\sin(30 \\degree) & 0 \\\\\n\t\t\\sin(30 \\degree) & \\cos(30 \\degree) & 0 \\\\\n\t\t0 & 0 & 1\n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty \\\\\n\t\tz\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(40 \\degree) \\\\\n\t\t\\sin(40 \\degree) \\\\\n\t\t10\n\t\\end{pmatrix}\n\\end{equation*}\nThe matrix\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t\\cos(30 \\degree) & -\\sin(30 \\degree) & 0 \\\\\n\t\t\\sin(30 \\degree) & \\cos(30 \\degree) & 0 \\\\\n\t\t0 & 0 & 1\n\t\\end{pmatrix}\n\\end{equation*}\nis an instance of the rotation matrix about the z-axis\n\\begin{equation*}\n\t\\text{Rot}_z(\\theta) =\n\t\\begin{pmatrix}\n\t\t\\cos \\theta & -\\sin \\theta & 0 \\\\\n\t\t\\sin \\theta & \\cos \\theta & 0 \\\\\n\t\t0 & 0 & 1\n\t\\end{pmatrix}\n\\end{equation*}\nwhere $\\theta = 30 \\degree$. \\\\\nFrom this, the equation can be rewritten as\n\\begin{equation*}\n\t\\text{Rot}_z(30 \\degree)\n\t\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t=\n\t\\text{Rot}_z(40 \\degree)\n\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 10 \\end{pmatrix}\n\t.\n\\end{equation*}\nThus,\n\\begin{align*}\n\t\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t&=\n\t(\\text{Rot}_z(30 \\degree))^{-1}\n\t\\text{Rot}_z(40 \\degree)\n\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 10 \\end{pmatrix} \\\\\n\t&=\n\t\\text{Rot}_z(-30 \\degree)\n\t\\text{Rot}_z(40 \\degree)\n\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 10 \\end{pmatrix} \\\\\n\t&=\n\t\\text{Rot}_z(10 \\degree)\n\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 10 \\end{pmatrix} \\\\\n\t&=\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t\\cos(10 \\degree) \\\\\n\t\t\t\\sin(10 \\degree) \\\\\n\t\t\t10\n\t\t\\end{pmatrix}\n\t}\n\t.\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "71891efe07a4ab7693d915dcc4e32da750aa9eba", "size": 3433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw06/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/hw06/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/hw06/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": 20.6807228916, "max_line_length": 75, "alphanum_fraction": 0.5974366443, "num_tokens": 1484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.8705972616934406, "lm_q1q2_score": 0.6813838021797596}}
{"text": "\\subsubsection{Time Series Normalization}\n\n\\begin{frame}{Time Series Normalization}{$\\eta$ Normalization}\n    Given is a time series $Q = (q_1, \\dots, q_n)$ of length $n$\n    \\begin{block}{$\\eta$ Normalization}\n        $\\eta(q_i) = q_i - \\mu$\n    \\end{block}\n    \\begin{block}{Mean of $Q$}\n        $\\mu = \\frac{1}{n} \\sum \\limits_{i=1}^{n} q_i$\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $\\eta$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-40,\n                                    ymax=40,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-40,\n                                ymax=40,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization $\\eta$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[gray, quiver={u=\\thisrow{u}, v=\\thisrow{v}}] table {../data/fig/norm1/path.dat};\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-40,\n                                    ymax=40,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};\n                                \\addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm1/matrix_path.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-40,\n                                ymax=40,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization}{$z$ Normalization}\n    Given is a time series $Q = (q_1, \\dots, q_n)$ of length $n$\n    \\begin{block}{$z$ Normalization}\n        $z(q_i) = \\frac{q_i - \\mu}{\\sigma}$\n    \\end{block}\n    \\begin{block}{Standard deviation of $Q$}\n        $\\sigma = \\frac{1}{n} \\sum \\limits_{i=1}^{n} (q_i - \\mu)^2$\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $z$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-2,\n                                    ymax=2,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-2,\n                                ymax=2,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization $z$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[gray, quiver={u=\\thisrow{u}, v=\\thisrow{v}}] table {../data/fig/norm2/path.dat};\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-2,\n                                    ymax=2,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};\n                                \\addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm2/matrix_path.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-2,\n                                ymax=2,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n", "meta": {"hexsha": "e165c74c2753afb0f01004608c73ea7106218b17", "size": 15507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "iotstreaming2017/background/dynamic_time_warping/time_series_normalization.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "iotstreaming2017/background/dynamic_time_warping/time_series_normalization.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "iotstreaming2017/background/dynamic_time_warping/time_series_normalization.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 45.8786982249, "max_line_length": 124, "alphanum_fraction": 0.3279809118, "num_tokens": 2959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6813491130483534}}
{"text": "\\documentclass[12pt,letterpaper]{article}\n\n\\usepackage[margin=1.9cm]{geometry}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{pgfplots}\n\\usepackage{siunitx}\n\n\\pgfplotsset{compat=1.16}\n\n\\begin{document}\n\\section*{Part 1 Series RC}\n\\subsection*{1.}\n\\begin{tikzpicture}\n    \\begin{axis}[\n        title = {Voltage vs Time},\n        xlabel = Time (\\si{\\micro\\second}),\n        ylabel = Voltage (\\si{\\volt}),\n        xmin = 0, \n        xmax = 85,\n        ymin = 0,\n        ymax = 11,\n        axis lines=left,\n        grid = both,\n        height = 6cm,\n        width = 17cm,\n        legend pos=south west\n    ]\n\n    \\addplot table [x=t, y=Output, col sep=comma, mark=none] {Part1.csv};\n    \\addlegendentry{Output Voltage}\n    \\addplot table [x=t, y=Input, col sep=comma, mark=none] {Part1.csv};\n    \\addlegendentry{Input Voltage}\n    \\addplot [mark=none, black, domain=0:45.65] {3.59};\n    \\draw (45.65,0) -- (45.65, 3.59);\n    \\addplot [mark=*] coordinates {(45.65, 3.59)};\n\\end{axis}\n\\end{tikzpicture}\n\\subsection*{2.}\nThe time constant $\\tau$ appears at $V = \\frac{V_0}{e} = \\frac{10}{e} = \\SI{3.59}{\\volt}$\n\nAt $\\SI{3.59}{\\volt}$, $\\tau = \\SI{45.65}{\\micro\\second}$\n\\subsection*{3a.}\n$$\\frac{|47-45.65|}{47} \\times 100 \\% = 2.88\\%$$\n\\subsection*{3b.}\n$$\\frac{|47-45.21|}{47} \\times 100 \\% = 3.83\\%$$\n\\subsection*{3c.}\n$$\\frac{|47-43.1|}{47} \\times 100 \\% = 8.51\\%$$\n\\subsection*{4.}\nUsing KVL:\n$$V_c = V_o - V_r$$\nwhere:\n\\begin{gather*}\n    V_r = V_o e^{\\frac{t}{\\tau}}, \\tau = \\SI{43}{\\micro\\second}\\\\\nV_c = V_o - V_o e^{\\frac{t}{\\tau}} = V_o (1-e^{\\frac{t}{\\tau}})\n\\end{gather*}\n\nComparison:\n\nRecorded $V_c = \\SI{1.84}{\\volt}$\nCalculated $V_c = 10(1-e^{-\\frac{10}{43}}) = \\SI{2.07}{\\volt}$\n\\section*{Part 2 Series RL}\n\\subsection*{5.}\n\\begin{tikzpicture}\n    \\begin{axis}[\n        title = {Current vs Time},\n        xlabel = Time (\\si{\\micro\\second}),\n        ylabel = Current (\\si{\\ampere}),\n        xmin = 0, \n        xmax = 80,\n        ymin = 0,\n        ymax = 0.08,\n        axis lines=left,\n        grid = both,\n        height = 7cm,\n        width = 17cm,\n        legend pos=south east\n    ]\n    \\addplot table [x=t, y=Theoretical, col sep=comma, mark=none] {Part2.csv};\n    \\addlegendentry{Theoretical Current}\n    \\addplot table [x=t, y=Calculated, col sep=comma, mark=none] {Part2.csv};\n    \\addlegendentry{Actual Current}\n    \\end{axis}\n\\end{tikzpicture}\n\n\\subsection*{6.}\n\\begin{gather*}\n\\tau_{RL} = \\SI{14.6}{\\micro\\second} = \\frac{L}{R}\\\\\nL = \\SI{14.6}{\\micro\\second} * \\SI{150}{\\ohm} = \\SI{2.19}{\\milli\\henry}\n\\end{gather*}\n\nComparison between calculated and labelled:\n\n$$\\frac{|2.5-2.19|}{2.5} \\times 100 \\% = 12.4\\%$$\n\\section*{Part 3 Series RLC}\n\\subsection*{7.}\nApply Ohm's law to voltages\n\\begin{center}\n    \\begin{tabular}{|c|c|}\n        \\hline\n        {Peak Current (\\si{\\ampere})} & {Time (\\si{\\second})} \\\\ \\hline\n        0.015&7.2\\\\  \\hline\n        -0.0086&22.8\\\\\\hline\n        0.0054&38.8\\\\\\hline\n        -0.003&54.8\\\\\\hline\n        0.00168&70.8\\\\\\hline\n        -0.00104&86.8\\\\\\hline\n    \\end{tabular}\n\\end{center}\nExample calculation:\n\n$$\\text{Voltage peak at } t = \\SI{7.2}{\\micro\\second} \\text{ is } \\SI{1.5}{\\volt} \\text{ which is } \\frac{\\SI{1.5}{\\volt}}{\\SI{100}{\\ohm}} = \\SI{0.015}{\\ampere}$$\n\\subsection*{8.}\n\\begin{tikzpicture}\n    \\begin{axis}[\n        title = {$\\ln|i|$ vs Time},\n        xlabel = Time (\\si{\\micro\\second}),\n        ylabel = $\\ln|i|$,\n        xmin = 0, \n        xmax = 80,\n        ymin = -8,\n        ymax = -2,\n        grid = both,\n        height = 5.5cm,\n        width = 17cm\n    ]\n    \\addplot table [green, x=t, y=i, col sep=comma, mark=none] {Part3.csv};\n    \\addlegendentry{Calculated}\n    \\addplot [mark=none, black, domain=0:80, opacity=0.5] {-0.033747*x - 3.96};\n    \\addlegendentry{Linear Regression}\n\n\\end{axis}\n\\end{tikzpicture}\n\nThe slope, through linear regression, was calculated to be $\\alpha = 33747 = \\frac{R}{2L}$\n$$L=\\frac{R}{2\\alpha} = \\frac{\\SI{150}{\\ohm}}{2\\times33747} = \\SI{2.22}{\\milli\\henry}$$\n\n\\subsection*{9.}\n\\begin{gather*}\n\\ln\\left(\\frac{V_o}{\\omega_D L}\\right) = - 3.96\\\\\n\\frac{V_o}{\\omega_D L} = e^{-3.96}\\\\\nL=\\frac{V_o}{\\omega_D L} e^{-3.96} = \\frac{\\SI{10}{\\volt}}{2\\pi} (\\SI{31.65}{\\kilo\\hertz}) e^{-3.96} = \\SI{2.64}{\\milli\\henry}\n\\end{gather*}\n\n\\subsection*{10.}\n\\begin{gather*}\nf = \\frac{\\omega}{2\\pi}\n\\end{gather*}\nWhere the damped frequency is given by $\\omega_D = \\sqrt{\\omega_o^2-\\alpha ^2}$\n\nSince $\\omega_o^2 \\gg \\alpha ^2$, the damped frequency yields a result such that $\\omega_D \\simeq \\sqrt{\\omega_o^2} = \\omega_o$\n\nExample:\n\\begin{gather*}\n\\omega_o = 2\\pi f_o = 2\\pi \\SI{31.8}{\\kilo\\hertz} = \\SI{199805.29}{\\radian\\per\\second}\\\\\n\\omega_o^2 = 3.9922\\times 10^{10} \\gg \\alpha^2 = 1.14\\times 10^9\\\\\n\\omega_D = \\sqrt{\\omega_o ^2 - \\alpha^2} = \\SI{196934.75}{\\radian\\per\\second} \\simeq \\omega_o\n\\end{gather*}\n\n\\subsection*{11.}\n\\begin{gather*}\n31.8\\times10^3 = \\frac{1}{2\\pi \\sqrt{L \\cdot 10\\times10^{-9}}}\\\\\nL = \\SI{0.00250}{\\henry} = \\SI{2.50}{\\milli\\henry} \n\\end{gather*}\n\n\n\\end{document}\n", "meta": {"hexsha": "212fe3d4b09337d92f24836297e17d48ad44b121", "size": 4995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LabReports/ECE203/Lab1/main.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": "LabReports/ECE203/Lab1/main.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": "LabReports/ECE203/Lab1/main.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.7321428571, "max_line_length": 162, "alphanum_fraction": 0.5821821822, "num_tokens": 1980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6813049394041039}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Convergence of Measurable Functions %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Convergence of Measurable Functions}\n\n\\begin{exercise}{5.1}{}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of $\\CalF$-measurable functions $f_n: \\Omega \\to \\mathbb{R}$. Then the set $A$ of those $\\omega \\in \\Omega$ such that $\\lim_{n \\to \\infty} f_n(\\omega)$ converges to some (finite) number belongs to $\\CalF$.\n\n\\end{exercise}\n\n\\begin{exercise}{5.2}{Almost Finite, Converging Sequence is Bounded}\n\n    Assume that $\\mu(\\Omega) < \\infty$. Let $(f_n)_{n=1}^{\\infty}$ be \\emph{$\\mu$-a.e. finite}, converging in measure to $\\mu$ to some $f: \\Omega \\to \\mathbb{R}$. Then the sequence of $f_n$ is \\emph{bounded in measure $\\mu$, uniformly in $n$}, i.e.:\n\n        \\begin{align*}\n            \\lim_{K \\to \\infty} \\sup_{n \\geq 1} \\mu(|f_n| \\geq K) = 0.\n        \\end{align*}\n\n    \\Hint $f_n$ \\emph{$\\mu$-a.e. finite} \\emph{and} $\\mu(\\Omega) < \\infty$ $\\Rightarrow$ $f_n$ bounded in measure (not necessarily uniformly), so\n\n        \\begin{align*}\n            \\lim_{K \\to \\infty} \\sup_{n \\geq 1} \\mu(|f_n| \\geq K) = \\\\ \\lim_{K \\to \\infty} \\limsup_{n \\to \\infty} \\mu(|f_n| \\geq K).\n        \\end{align*}\n\n    Then use observation of splitting measures of inequalities.\n\n\\end{exercise}\n\n\\begin{exercise}{5.3}{Product of Bounded \\& Zero Convergent is Zero Convergent}\n\n    Let $(f_n)_{n=1}^{\\infty}$ and $(g_n)_{n=1}^{\\infty}$ be sequences of $\\mu$-a.e. finite measurable functions such that the $f_n$ are bounded in measure $\\mu$, uniformly in $n$ and $g_n \\to 0$ in measure $\\mu$, as $n \\to \\infty$. Then $f_ng_n \\to 0$ in measure $\\mu$, as $n \\to \\infty$.\n\n\\end{exercise}\n\n\\begin{exercise}{Ws 3, 1}{}\n\n    Let $\\mu-\\lim f_n = f$, then there exists a subsequence $(f_{n_k})_{k=1}^{\\infty}$ such that $(n_k)_{k=1}^{\\infty}$ is increasing and $f_{n_k} \\to f$ ($\\mu$-a.e.).\n\n    \\Hint Borel-Cantelli with $A_k = \\{ |f_{n_k} - f| \\geq 1/k \\}$ s.t. $\\mu(A_k) \\leq 1/k^2$.\n\n\\end{exercise}\n\n\\begin{theorem}{5.4}{Measure Convergence Has Almost Everywhere Converging Subsequence}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of functions converging in measure $\\mu$ to some $\\mu$-a.e. finite function $f$. Then there exists a (strictly) increasing sequence $(n_k)_{k=1}^{\\infty}$ of positive integers such that $\\lim_{k \\to \\infty} f_{n_k} = f$ $\\mu$-almost everywhere.\n\n\\end{theorem}\n\n\\begin{exercise}{5.5}{}\n\n    Convergence in measure $\\mu$ does not imple convergence $\\mu$-almost everywhere.\n\n    \\Hint $(\\mathbb{R}, \\mathcal{B}(\\mathbb{R}), \\lambda)$ with $f_n = \\Indicator{[k/2^m, (k+1)/2^m]}$ where $k = 0,1,\\hdots,2^m - 1$ and $m=0,1,\\hdots$ such that $n = 2^m + k$.\n\n\\end{exercise}\n\n\\begin{exercise}{Ws 3, 2}{Convergence Implication}\n\n    Let $\\mu(\\Omega) < \\infty$. Then $\\lim_{n \\to \\infty} f_n = f$ ($\\mu$-a.e.) $\\Rightarrow$ $\\mu-\\lim_{n \\to \\infty} f_n = f$.\n\n\\end{exercise}\n\n\\begin{exercise}{Ws 3, 3}{Relaxed Domnitated Convergence}\n\n    Lebegue's Theorem on Dominated convergence holds under the following, relaxed conditions:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item $\\lim_{n \\to \\infty} f_n = f$ \\emph{$\\mu$-a.e.},  $|f_n| \\leq g|$ $\\mu$-a.e. and $g \\in L_1(\\Omega, \\CalF, \\mu)$, i.e. $\\int_{\\Omega} |g| \\, d\\mu < \\infty$; and\n            \\item $\\mu-\\lim_{n \\to \\infty} f_n = f$,  $|f_n| \\leq g|$ $\\mu$-a.e. and $g \\in L_1(\\Omega, \\CalF, \\mu)$, i.e. $\\int_{\\Omega} |g| \\, d\\mu < \\infty$.\n        \\end{enumerate}\n\n\\end{exercise}\n", "meta": {"hexsha": "84b051a9c2ae1e86de3aaf6cce04aefdb55bea13", "size": 3503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/convergence.tex", "max_stars_repo_name": "smueksch/measure-theory-overview", "max_stars_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/convergence.tex", "max_issues_repo_name": "smueksch/measure-theory-overview", "max_issues_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/convergence.tex", "max_forks_repo_name": "smueksch/measure-theory-overview", "max_forks_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-02T15:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-02T15:34:51.000Z", "avg_line_length": 46.0921052632, "max_line_length": 289, "alphanum_fraction": 0.5989152155, "num_tokens": 1295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6811133304444087}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Exponential Equations}\n\n\\objective{Solve exponential/logarithmic equations through a variety of techniques}\n\n\nWhatever function we are dealing with, if $f(x)=f(3)$ then $x$ must equal 3.  This is true\nif $f(x)$ is a logarithmic, exponential or other kind of function.  So, if $\\log_{\\pi}(x+3) =\n\\log_{\\pi}{7-x}$, then $x+3 = 7 - x$ and $2x = 4$, so $x$ must equal 2.  Similarly,\nif $3^{2x+1} = 3^7$ then $2x+1 =7$ and $x=3$.  These are the most basic kinds of\nexponential equations.\n\nYou are probably pretty good at spotting when numbers are related via multiplication\nand division because of so many years of practicing such arithmetic.  $56x+49=0$ should\nleap out to you as $7(8x+7)=0$ or even $x=-\\frac{7}{8}$ because you have known\nyour seven times table for so many years now.  Exponents are not memorized to the\nsame extent --- and nor should they be --- but perhaps you might consider expanding your\nfamiliarity with them just a little more.  The return on investment is pretty low after cubes,\nbut you will be pleasantly surprised at the added reach knowing the numbers on the following\ntable will give you:\n\n$$\n\\begin{matrix} \n2 & 4 & 8 & 16 & 32 \\\\ \n3 & 9 & 27 & 81 & 243 \\\\ \n4 & 16 & 64 & 256 & 1024 \\\\ \n5 & 25 & 125 & 625 &  \\\\ \n6 & 36 & 216 &  &  \\\\ \n7 & 49 & 343 &  &  \\\\ \n8 & 64 & 512 &  &  \\\\ \n9 & 81 & 729 &  &  \n\\end{matrix}\n$$\n\n\\begin{example}{Exponential Base Manipulation}\n\\exProblem\nSolve $9^{x+1}=\\left(\\frac{1}{27}\\right)^{2x}$.\n\n\\exSolution\nWith a familiarity with exponents, we see that both numbers are power of 3.  We can \nre-write each base to show this, and use the same equality principle as before.\n\\begin{align*}\n\t9^{x+1} &= \\left(\\frac{1}{27}\\right)^{2x}\\\\\n\t(3^2)^{x+1} &= (3^{-3})^{2x}\\\\\n\t3^{2x+2} &= 3^{-6x}\\\\\n\t2x + 2 &= -6x\\\\\n\t8x &= -2\\\\\n\tx &= -\\frac{1}{4}\n\\end{align*}\n\\end{example}\n\n\\begin{example}{Logarithmic Base Manipulation}\n\\exProblem\nSolve $\\log_7{x} = \\log_{49}{2x}$.\n\n\\exSolution\nThere are lot of transformation we could try at this point which would be valid.\nLet us consider how we can make both sides have a logarithmic base of 49.\n$\\log_7{7} = \\log_{49}{49}$, which shows that is you square the base, you must square\nwhat you are taking the log of.  This will allow us to rewrite the equation and solve.\n\\begin{align*}\n\t\\log_7{x} &= \\log_{49}{2x}\\\\\n\t\\log_{49}{x^2} &= \\log_{49}{2x}\\\\\n\tx^2 &= 2x \\\\\n\tx^2 - 2x &= 0\\\\\n\tx(x-2) &= 0\\\\\n\tx &= \\{0, 2\\}\n\\end{align*}\nIf we check our two solutions, however, we find a contradiction.  $\\log_b{0}$ does\nnot exist: there is no exponent you can raise a number to and get 0.  We can check that\n2 works as a solution in our TI-8*.  (Newer TI-8*'s have a LOGBASE function under MATH, \nbut everyone can check by typing $\\frac{\\log{2}}{\\log{7}}$ etc.)\n\\end{example}\n\n\\begin{example}{Combining Logs}\n\\exProblem\nSolve for $x$: $\\log_4{(x+10)}+\\log_4{(x+34)}=4$\n\n\\exSolution\nWe can (must) combine the two logs, in order to make the problem simpler.\n\\begin{align*}\n\t\\log_4{(x+10)(x+34)} &= 4\\\\\n\t\\log_4{x^2+44x+340)} &= 4\\\\\n\t4^4 &= x^2+44x+340\\\\\n\t0 &= x^2+44x+340-256\\\\\n\t0 &= (x+2)(x+42)\n\\end{align*}\nOf the two solutions, only -2 works in the original problem; -42 does not\n\\end{example}\n\n\\subsection{Substitution}\nFinally, there are some problems which do not yield to combination, manipulation, or\nchanging log-form.  These problems require substitution.  For example, nothing in \n$e^{2x}+5e^x=1$ seems to fit what we have so far described.  We cannot combine\nany terms of the left, so we must ``explain away'' for a moment the troublesome\nexponents.  We pick a variable to represent what we cannot deal with: $e^x$.  \n\nThe problem now becomes $u^2+5u=1$.  This is not magic: we must un-substitute at the\nend, or else we are solving a different problem.  But the magical aspect is that we can now\nsee that this is a quadratic problem.  $u^2+5u-1=0$ does not yield to factoring, so\nwe must resort to the Quadratic Formula.\n\n$$\nu=\\frac{-5\\pm\\sqrt{29}}{2}\n$$\n\nWe check with the TI-8*, and the ```plus'' solution is positive, while the ``minus'' one is not.\nSince $u$ is really just a cipher for $e^x$, we need only the positive solution.  This means\n$e^x=\\frac{-5+\\sqrt{29}}{2}$ or $x=\\ln{-5+\\sqrt{29}}-\\ln{2}$, which is around -1.65.\n", "meta": {"hexsha": "4f33b2d3d19389f1fd923cc9eccdfd3b2ab22183", "size": 4252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch07/0704.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch07/0704.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch07/0704.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": 38.3063063063, "max_line_length": 96, "alphanum_fraction": 0.6738005644, "num_tokens": 1450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6811133304444087}}
{"text": "\\input{../../style/preamble}\n\\input{../../latex-math/basic-math}\n\\input{../../latex-math/basic-ml}\n\n\\newcommand{\\titlefigure}{figure_man/ridge_hat.png}\n\\newcommand{\\learninggoals}{\n  \\item Know the regularized linear model\n  \\item Know Ridge regression ($L2$ penalty)\n  \\item Know Lasso regression ($L1$ penalty)\n}\n\n\\title{Introduction to Machine Learning}\n\\date{}\n\n\\begin{document}\n\n\\lecturechapter{Lasso and Ridge Regression}\n\\lecture{Introduction to Machine Learning}\n\n\n\\begin{vbframe}{Regularization in the linear model}\n\n  \\begin{itemize}\n  \\item Linear models can also overfit if we operate in a high-dimensional space with not that many observations.    \n  \\item OLS usually require a full-rank design matrix.\n  \\item When features are highly correlated, the least-squares estimate becomes highly sensitive to random errors in the observed response, producing a large variance in the fit. \n  \\item We now add a complexity penalty to the loss:\n  $$\n  \\riskrt = \\sumin \\left(\\yi - \\thetab^\\top \\xi \\right)^2 + \\lambda \\cdot J(\\thetab). \n  $$ \n  \\item Intuitive to measure model complexity as deviation from the 0-origin, as the 0-model is empty and contains no effects. Models close to this either have few active features or only weak effects. \n  \\item So we measure $J(\\thetab)$ through a vector norm.\n    This shrinks coefficients closer 0, hence the term \\textbf{shrinkage methods}.\n  \\end{itemize}\n\n\\end{vbframe}\n\n\n% \\section{Ridge Regression}\n\n\\begin{vbframe}{Ridge Regression}\n\n  \\textbf{Ridge regression} uses a simple $L2$ penalty:\n  \\begin{eqnarray*}  \n  \\thetah_{\\text{Ridge}} &=& \\argmin_{\\thetab} \\sumin \\left(\\yi - \\thetab^T \\xi \\right)^2 + \\lambda \\|\\thetab\\|_2^2 \\\\\n  &=& \\argmin_{\\thetab} \\left(\\yv - \\Xmat \\thetab\\right)^\\top \\left(\\yv - \\Xmat \\thetab\\right) + \\lambda \\thetab^\\top \\thetab.\n  \\end{eqnarray*}\n\nOptimization is possible (as in the normal LM) in analytical form:\n$$\\thetah_{\\text{Ridge}} = ({\\Xmat}^T \\Xmat  + \\lambda \\id)^{-1} \\Xmat^T\\yv$$\n\nName comes from the fact that we add positive entries along the diagonal \"ridge\" $\\Xmat^T \\Xmat$.\n\n\\framebreak \n\nWe understand the geometry of these 2 mixed components in our regularized risk objective much better, if we formulate the optimization as a constrained problem (see this as Lagrange multipliers in reverse).\n\n\\vspace{-0.5cm}\n\n\\begin{eqnarray*}\n\\min_{\\thetab} && \\sumin \\left(\\yi - \\fxit\\right)^2 \\\\\n  \\text{s.t. } && \\|\\thetab\\|_2^2  \\leq t \\\\\n\\end{eqnarray*}\n\n\\vspace{-1.0cm}\n\n\\begin{figure}\n\\includegraphics[width=0.3\\textwidth]{figure_man/ridge_hat.png}\n\\end{figure}\n\n\\begin{footnotesize} \nNB: Relationship between $\\lambda$ and $t$ will be explained later.\n\\end{footnotesize}\n\n\\framebreak\n  \n\\begin{columns}\n\\begin{column}{0.5\\textwidth}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figure_man/ridge_hat.png}\n\\end{figure}\n\\end{column}\n\n\\begin{column}{0.5\\textwidth}\n\\begin{footnotesize} \n\\begin{itemize}\n  \\item We still optimize the $\\risket$, but cannot leave a ball around the origin.\n  \\item $\\risket$ grows monotonically if we move away from $\\thetah$.\n  \\item Inside constraints perspective: From origin, jump from contour line to contour line (better) until you become infeasible, stop before.\n\\item Outside constraints perspective: From $\\thetah$, jump from contour line to contour line (worse) until you become feasible, stop then.\n  \\item So our new optimum will lie on the boundary of that ball.\n\\end{itemize}\n\\end{footnotesize}\n\\end{column}\n\\end{columns}\n\n\n\\end{vbframe}\n\n\n\n\\begin{vbframe}{Example: Polynomial Ridge Regression}\n\nTrue (unknown) function is \\(f(x) = 5 + 2x +10x^2 - 2x^3 + \\epsilon\\) (in red).\n\n\\lz\n\nLet us consider a \\(d\\)th-order polynomial\n\\[ f(x) = \\theta_0 + \\theta_1 x + \\cdots + \\theta_d x^d = \\sum_{j = 0}^{d} \\theta_j x^j\\text{.} \\]\nUsing model complexity $d = 10$ overfits:\n\n\\begin{center}\n\\includegraphics[width = 10cm ]{figure/poly_ridge_1.png} \\\\\n\\end{center}\n\n\\framebreak\n\nWith an $L2$ penalty we can now select $d$ \"too large\" but regularize our model by shrinking its coefficients. Otherwise we have to optimize over the discrete $d$.\n\n\\vfill\n\n\\begin{center}\n\\includegraphics[width = 11cm ]{figure/poly_ridge_2.png} \\\\\n\\end{center}\n\n\n\\begin{center}\n\\tiny\n\\begin{tabular}{ c| c c c c c c c c c c c c}\n $\\lambda$ & $\\beta_0$ & $\\beta_1$ & $\\beta_2$ & $\\beta_3$ & $\\beta_4$ & $\\beta_5$ & $\\beta_6$ & $\\beta_7$ & $\\beta_8$ & $\\beta_9$ & $\\beta_{10}$ \\\\ \n \\hline\n 0.00 & 12.00 & -16.00 & 4.80 & 23.00 & -5.40 & -9.30 & 4.20 & 0.53 & -0.63 & 0.13 & -0.01 \\\\  \n 10.00 & 5.20 &1.30 & 3.70 & 0.69 & 1.90 & -2.00 & 0.47 & 0.20 & -0.14 & 0.03 & -0.00 \\\\ \n 100.00 & 1.70 & 0.46 & 1.80 & 0.25 & 1.80 & -0.94 & 0.34 & -0.01 & -0.06 & 0.02 & -0.00\n\\end{tabular}\n\\end{center}\n\n\n\\end{vbframe}\n\n% \\section{Lasso Regression}\n\n\\begin{vbframe}{Lasso Regression}\n\nAnother shrinkage method is the so-called \\textbf{Lasso regression}, which uses an $L1$ penalty on $\\thetab$:\n\n\\begin{eqnarray*}\n\\thetah_{\\text{Lasso}} &=&  \\argmin_{\\thetab} \\sumin \\left(\\yi - \\thetab^T \\xi\\right)^2 + \\lambda \\|\\thetab\\|_1 \\\\\n  &=& \\argmin_{\\thetab} \\left(\\yv - \\Xmat \\thetab\\right)^\\top \\left(\\yv - \\Xmat \\thetab\\right) + \\lambda \\|\\thetab\\|_1.\n\\end{eqnarray*}\n\nNote that optimization now becomes much harder. $\\riskrt$ is still convex, but we have moved from an optimization problem with an analytical solution towards a non-differentiable problem.\n\n\\lz\n\nName: least absolute shrinkage and selection operator.\n\n\\framebreak \n\nWe can also rewrite this as a constrained optimization problem. The penalty results in the constrained region to look like a diamond shape.\n\n\\begin{eqnarray*}\n\\min_{\\thetab} && \\sumin \\left(\\yi - \\fxit\\right)^2\\\\\n\\text{subject to: } && \\|\\thetab\\|_1 \\leq t \\\\\n\\end{eqnarray*}\n\n\\vspace*{-1cm}\n\n  \\begin{figure}\n\\includegraphics[width=0.3\\textwidth]{figure_man/lasso_hat.png}\\\\\n\\end{figure}\n\n\\end{vbframe}\n\n\n\\endlecture\n\\end{document}\n\n", "meta": {"hexsha": "bb9ce5af8b507acb634ff29b6eca9335c46fbcf9", "size": 5864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/regularization/slides-regu-l1l2.tex", "max_stars_repo_name": "slds-lmu/lecture_i2ml", "max_stars_repo_head_hexsha": "b1cec2c8a8d0cff584e9f5d70c232c64d652f62c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-10-31T11:24:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T12:31:51.000Z", "max_issues_repo_path": "slides/regularization/slides-regu-l1l2.tex", "max_issues_repo_name": "slds-lmu/lecture_i2ml", "max_issues_repo_head_hexsha": "b1cec2c8a8d0cff584e9f5d70c232c64d652f62c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 72, "max_issues_repo_issues_event_min_datetime": "2021-10-14T09:42:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T17:47:37.000Z", "max_forks_repo_path": "slides/regularization/slides-regu-l1l2.tex", "max_forks_repo_name": "slds-lmu/lecture_i2ml", "max_forks_repo_head_hexsha": "b1cec2c8a8d0cff584e9f5d70c232c64d652f62c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-10-15T09:09:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T12:31:53.000Z", "avg_line_length": 32.7597765363, "max_line_length": 206, "alphanum_fraction": 0.6971350614, "num_tokens": 1947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.681113327927071}}
{"text": "%\n% Chapter 3.3\n%\n\n\\section*{3.3 Graphing Derivatives}\n\n\\subsection*{Increasing/Decreasing Test}\n\n\\begin{itemize}\n    \\item If \\(f'(x)>0\\) on an interval, then \\(f\\) is increasing on that interval.\n    \\item If \\(f'(x)<0\\) on an interval, then \\(f\\) is decreasing on that interval.\n\\end{itemize}\n\n\\subsection*{First Derivative Test}\n\n\\begin{itemize}\n    \\item If \\(f'\\) changes from positive to negative at \\(c\\), then \\(f\\) has a \\textbf{local maximum} at \\(c\\).\n    \\item If \\(f'\\) changes from negative to positive at \\(c\\), then \\(f\\) has a \\textbf{local minimum} at \\(c\\).\n    \\item If \\(f'\\) is positive to the left and right of \\(c\\), or negative to the left and right of \\(c\\), then \\(f\\) has no local maximum or minimum at \\(c\\).\n\\end{itemize}\n\n\\subsection*{Concavity Test}\n\n\\begin{itemize}\n    \\item If \\(f''(x) > 0\\) for all \\(x\\) in \\(I\\), then the graph of \\(f\\) is concave upward on\n\\(I\\).\n    \\item If \\(f''(x) < 0\\) for all \\(x\\) in \\(I\\), then the graph of \\(f\\) is concave downward on \\(I\\).\n\\end{itemize}\nIf the graph of \\(f\\) lies above all of its tangents on an interval \\(I\\), then it is called concave upward on \\(I\\). If the graph of \\(f\\) lies below all of its tangents on \\(I\\), it is called concave downward on \\(I\\).\n\\\\\\\\\nA point \\(P\\) on a curve \\(y=f(x)\\) is called an \\textbf{inflection point} if \\(f\\) is continuous there and the curve changes from concave upward to concave downward or vice versa.\n\n\\subsection*{Second Derivative Test}\n\nSuppose \\(f''(x)\\) is continuous near \\(c\\).\n\\begin{itemize}\n    \\item If \\(f'(c) = 0\\) and \\(f''(c) > 0\\), then \\(f\\) has a local minimum at \\(c\\).\n    \\item If \\(f'(c) = 0\\) and \\(f''(c) < 0\\), then \\(f\\) has a local maximum at \\(c\\).\n\\end{itemize}\n", "meta": {"hexsha": "e841bcdb61478f9b620fde86e0f8d9a9a99e555b", "size": 1721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3-3.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/3-3.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/3-3.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.025, "max_line_length": 220, "alphanum_fraction": 0.6252178966, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6811133208370397}}
{"text": "\n\\subsection{Edgeworth box}\n\nSo now we have a framework for how agents can interact. We want to model trade, what games can do this?\n\nTo do this we introduce the Edgeworth box. This is a rectangle where the length of the \\(x\\) and \\(y\\) axes represent the total amount of those goods, and points on the box represent allocations of the goods. There is an initial endowment of goods.\n\n\\(x=\\{0.2,0.8\\}\\)\n\n\\(y=\\{0.8,0.2\\}\\)\n\n[Put box here]\n\nTheir respective utility functions are:\n\n\\(u_a=f_a(x_a,y_a)\\)\n\n\\(u_b=f_b(x_b,y_b)\\)\n\nIn this example we use:\n\n\\(u_{a,b}=x^{0.5}y^{0.5}\\)\n\nWe can add indifference curves to this box, which intercept at the endowment.\n\n[Put box here]\n\nThe agents would be better off if they could trade so that they both had half of a unit of each good.\n\n\\(x=\\{0.5,0.5\\}\\)\n\n\\(y=\\{0.5,0.5\\}\\)\n\nHowever they could also both be better off with\n\n\\(x=\\{0.6,0.6\\}\\)\n\n\\(y=\\{0.4,0.4\\}\\)\n\n[Box here]\n\nThere are many such trades which could be made, which agents would rank differently.\n\nThere are also points where no further trade would be agreed by both parties. For example with the above outcome, any further trade would make at least one party worse off.\n\nSuch points are called Pareto efficient. That is, if a point is not Pareto efficient at least one party can be made better off without harming others.\n\n[Box here]\n\n", "meta": {"hexsha": "d13f235be2f553d13ca8f7225ac71f347237bbb2", "size": 1335, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/edgeworth/01-01-tradeEdgeworth.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/edgeworth/01-01-tradeEdgeworth.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/edgeworth/01-01-tradeEdgeworth.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.7, "max_line_length": 248, "alphanum_fraction": 0.7146067416, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6811133170864888}}
{"text": "\\section{Artificial Neural Networks}\nTo understand neural networks, first it is necessary to understand its building blocks, artificial neurons. Commonly called just neurons, nodes, or units (the preferred term used in this document will be unit), these were historically inspired by biological neurons. The idea behind them is that a single unit is a very simple element that receives some inputs and produces an output, the real power comes from connecting many of these together, from thousands, to millions, or even billions of connections\\footnote{\n  As of writing this document GPT-3 is the biggest neural network model of all time, having 175 billion parameters \\cite{gpt3_2020}.\n}.\n\\begin{figure}[hbt]\n    \\centering\n    \\caption{Single unit representation}\n    \\includegraphics[width=0.4\\textwidth]{chapters/NeuralNets/figures/neuron.pdf}\n    \\fonte{From the author (2021)}\n    \\label{fig:neuron}\n\\end{figure}\n\n\\autoref{fig:neuron} shows a representation of an artificial unit, it receives a set of inputs $[x_0, x_1, ..., x_n]$, denoted as a vector $\\bm{x}$, and each input has a corresponding scalar value $w_i$ called its weight. Units will also often have a bias term $b$ that is independent of the inputs and that is useful for shifting the output.\n\nBy changing the set of weights (in vector form $\\bm{w}$) and the bias term, it is possible to achieve different behaviours from the unit based on its inputs. \\autoref{eq:weighted_input} shows how these parameters are used to calculate what is called the \\textit{weighted input} ($z$) of the unit \\cite[Chapter 2]{NN&DL2015}.\n\\begin{equation} \\label{eq:weighted_input}\n    z = \\sum_{i}^{n}{w_i x_i} + b =\n    %\n    \\begin{bmatrix}w_0, & w_1, & ... & w_n\\end{bmatrix}\n    \\begin{bmatrix}x_0, & x_1, & ... & x_n\\end{bmatrix}^T + b =\n    %\n    \\bm{w} \\cdot \\bm{x}^T + b\n\\end{equation}\n\nThe weighted input is usually passed through a non-linear function $f$, called the \\textit{activation function}, to produce the output $a$, called the unit activation, as seen in \\autoref{eq:activation}.\n\\begin{equation} \\label{eq:activation}\n    a = f\\left(z\\right) = f\\left(\\bm{w} \\cdot \\bm{x}^T + b\\right)\n\\end{equation}\n\nA neural network is built by combining multiple units together and the learning process consists of adjusting all the weights and biases in order to produce the expected results given the dataset. Any combination of connections can be considered a neural network, however for the overwhelming majority of cases the networks are divided into layers, and for most of these cases the connections form an acyclic graph. This means that there are no cycles in the network, the input flows from one layer to the next, and there is usually no connection between layers that are not consecutive \\textbf{--} exceptions to this are \\gls{LSTM} networks \\cite{lstm1997} and Residual Networks \\cite{resnet2015}, but they are not the focus of this document.\n\nThe layers of the network are commonly divided into input layer, hidden layers, and output layer. The input layer represents the input data, usually in diagram representations the inputs are drawn like units, this however is just an stylistic choice since the values do not pass through any calculation in this layer.\n\nThe output layer contains the units that will be interpreted as the result produced from the input. For example, in a case where the network is trying to predict the price of apartments given area, number of rooms, and others properties (classical machine learning example), the output would be a single unit whose activation is the predicted price. Problems where the output can assume a range of values are usually called \\textit{regression} problems.\n\nOn the other hand, problems where the output is better interpreted as a discrete value are called \\textit{classification} problems. Predicting the digits of \\gls{MNIST} falls into the category of classification problems, where the output represents which of the 10 possible digits the input image represents.\n\nIn the case of \\gls{MNIST} the output layer can be made of 10 units, where each of the activations gives the probability of the input belonging to the corresponding digit. A natural question to raise from this description is: why would there be a need for one unit to represent each class, when the number 10 can be more efficiently represented using only 4 bits (4 units)? Or even, why not use just one unit that outputs the predicted number?\n\nOne reason for this is that these simpler representations would lose the property of interpretability of the output as a probability distribution. But the most important reason can be validated empirically, it is easier for a network to classify the inputs into isolated units then it is to try and correlate them with specific bits for each class \\cite[Chapter 1]{NN&DL2015} or to reduce the output into a single unit.\n\nFor most classification problems using a neural network the output layer will contain one unit for each possible class and the desired output will be a vector where all elements are 0's, except for the element corresponding to the true label that will be a 1, indicating the 100\\% probability for that class. This way of encoding the outputs is called \\textit{one-hot encoding}.\n\n\nThe rest of the layers in a neural network, called the hidden layers, are all the layers between the input and output. A neural network does not need to have any hidden layers, but they are fundamental for building more complex relations and robust models.\n\n\\textcite{universalApproximator1989} showed that, given sufficient hidden units, any neural network with a single hidden layer can be used to approximate any function to any amount of precision, in other words, neural networks with at least a hidden layer are \\textit{universal approximators}. But in practice it is observed that more hidden layers usually perform better, they are able to divide the problems into steps and gradually reach the result. For example, an image classifier might use the first layers to distinguish lower level features like edges, while deeper layers recognize shapes, textures, and all the way to complex patterns like faces \\cite{deepLearningBook2016}.\n\nMore recent years have seen a resurgence of \\gls{DL}, this is generally understood as learning with networks having at least two hidden layers, but modern models can have much more than that\\footnote{\n    Google's Inception v3 image classifier model has 42 layers in total \\cite{inceptionV3_2015}\n}.\n\n\\autoref{fig:network} shows an example of the layered structure of a neural network, for simplicity the diagram shows only fully connected layers (all the units of a layer are connected to all the units of the previous layer, see \\autoref{subsub:fully_connected}) but it could also have different types of layer without losing the general idea of input, hidden, and output.\n\\begin{figure}[hbt]\n    \\centering\n    \\caption{Diagram of a fully connected neural network}\n    \\includegraphics[width=0.8\\textwidth]{chapters/NeuralNets/figures/network.pdf}\n    \\fonte{From the author (2021)}\n    \\label{fig:network}\n\\end{figure}\n\n\n\\subsection{Types of layers}\nThe networks constructed for this document will all use a combination of fully connected and convolutional layers. This section will explain how these work, how they differ, and their advantages in relation to each other.\n\nBefore proceeding however, it is important to define the notation that will be used. Since from now on the focus will changes from single units to an entire network, it is necessary to establish a notation that allows for indexing individual units, in any layer, and also their parameters.\n\nThe bias, weighted input, and activation for unit $i$ in layer $l$ will be written as $b_{i}^{(l)}$, $z_{i}^{(l)}$, and $a_{i}^{(l)}$ respectively. The weight connecting unit $j$ in layer $l-1$, to unit $i$ in layer $l$ will be written as $w_{ij}^{(l)}$.\n\nThe set of biases, weighted inputs, and activations in layer $l$ can also be written as the vectors $\\bm{b}^{(l)}$, $\\bm{z}^{(l)}$ and $\\bm{a}^{(l)}$. The weights connecting the units in layer $l-1$ to units in layer $l$ can be written as the weight matrix $\\bm{W}^{(l)}$.\n\\begin{equation*}\n    \\renewcommand{\\arraystretch}{1.4}\n    \\setlength\\arraycolsep{4pt}\n    \\bm{z}^{(l)} = \\begin{bmatrix}\n        z_{0}^{(l)} \\\\\n        z_{1}^{(l)} \\\\\n        \\vdots \\\\\n        z_{n}^{(l)}\n    \\end{bmatrix}\n    %\n    \\quad\n    \\bm{a}^{(l)} = \\begin{bmatrix}\n        a_{0}^{(l)} \\\\\n        a_{1}^{(l)} \\\\\n        \\vdots \\\\\n        a_{n}^{(l)}\n    \\end{bmatrix}\n    %\n    \\quad\n    \\bm{b}^{(l)} = \\begin{bmatrix}\n        b_{0}^{(l)} \\\\\n        b_{1}^{(l)} \\\\\n        \\vdots \\\\\n        b_{n}^{(l)}\n    \\end{bmatrix}\n    %\n    \\quad\n    \\bm{W}^{(l)} = \\begin{bmatrix}\n        w_{00}^{(l)} & w_{01}^{(l)} & \\dots  & w_{0m}^{(l)} \\\\\n        w_{10}^{(l)} & w_{11}^{(l)} & \\dots  & w_{1m}^{(l)} \\\\\n        \\vdots       & \\vdots       & \\ddots & \\vdots \\\\\n        w_{n0}^{(l)} & w_{n1}^{(l)} & \\dots  & w_{nm}^{(l)}\n    \\end{bmatrix}\n\\end{equation*}\n\nRecall that the activation of a unit is simply its activation function, denoted here as $f$, applied to the weighted input. \\autoref{eq:activation_again} rewrites this relation as shown in \\autoref{eq:activation} using the revised notation.\n\\begin{equation} \\label{eq:activation_again}\n    \\bm{a}^{(l)} = f\\left( \\bm{z}^{(l)} \\right)\n\\end{equation}\n\nObserve that in \\autoref{eq:activation_again} the activation function is applied to the vector $\\bm{z}^{(l)}$, this is a common shorthand notation to represent the element-wise application of the function to the vector. This notation will be used throughout the entirety of this document, all functions applied to vectors will be applied element-wise unless otherwise noted.\n\n\\subsubsection{Fully connected layer} \\label{subsub:fully_connected}\nFully connected, also called Dense layers, are a type of layer where all the inputs are connected to all outputs of the previous layer. \\autoref{eq:dense_weighted_input} shows how the weighted inputs of this layer are calculated from the activations of the previous layer.\n\\begin{equation} \\label{eq:dense_weighted_input}\n    z_{i}^{(l)} = \\sum_{j}{w_{ij}^{(l)} a_{j}^{(l-1)}} + b_i^{(l)}\n\\end{equation}\n\nIf the previous layer is the input layer, the values for $\\bm{a}^{(l-1)}$ will be the input of the network. To abstract the type of input it is useful to just replace the notation with a general layer input $\\bm{x}$. The activation can be written more simply by using vector form as shown in \\autoref{eq:dense_activation}, the layer superscripts were also omitted for more clarity.\n\\begin{equation} \\label{eq:dense_activation}\n    \\bm{a} = f\\left( \\bm{W}\\bm{x} + \\bm{b} \\right)\n\\end{equation}\n\nDense layers are extremely common, being used in many types of neural networks. They are very useful for mapping their inputs, that can have any number of dimensions, to a vector with any different number of dimensions, this is used in almost all classifiers to reduce the detected features into a one-hot encoded vector of the possible classes. For example, in the 2012 ImageNet challenge the three last layers of the network AlexNet were fully connected, they mapped the $43,264$ features into a $1000$ dimensional vector corresponding to all classes of images in the challenge \\cite{alexnet2012}.\n\nThis type of layer can also be used to apply transformations to features that will be used later in the network, this is used in \\acp{GAN} to map the latent space to a vector that is transformed into the generated image (see\\autoref{cha:gans}). They can even be used for full feature extraction, but this is usually not the best choice since they are quite expensive given the high number of connections and, as will be seen, they lack some useful properties that are present in convolutional layers.\n\n\n\\subsubsection{Convolutional layer}\nOne drawback of fully connected layers is that they do not leverage the structure of the data when calculating the activations. Consider for example the case of images, when dealing with random values all pixels are uncorrelated with one another, but in real world situations the pixels of an image group together to make edges, shapes and complex figures. The same could be said for audio, video, language and many other situations \\cite{guide_conv2018}.\n\nConsider the example of a simple image of a digit in the \\gls{MNIST} dataset, by translating the image by a couple of pixels or by slightly warping the strokes the digit represented does not change. But since the fully connected layer has no sense of neighbouring pixels (or temporal coherence for audio and video, etc.), then it has no choice other than learning weights for all possible slight transformations to the inputs. This not only makes learning more difficult, but also introduces many unnecessary parameters to the network.\n\nConvolutional layers are a way of dealing with this problem. Initially inspired by the visual cortex of vertebrates \\cite{neurocognitron1982}, the idea behind them is to detect the presence of features, no matter where they are present or if they are slight perturbed (e.g. an edge should be seen as an edge, no matter where it is located in the image or if it is slightly rotated).\n\nNeural networks that employ convolutional layers are usually called \\acp{CNN}, their history is very long and they were already used in the 1990's for learning the \\gls{MNIST} dataset when it was introduced \\cite{mnist1998}. However they were not very popular for larger problems and only grew in popularity after the great breakthrough in the ImageNet challenge achieved by the \\gls{CNN} AlexNet in 2012 \\cite{alexnet2012}. Since then they have become very common and are used in a variety of situations, even outside of image recognition. \n\nThis section will only explain how they work for the 2-dimensional case, but the idea can be easily generalized to the 1-dimensional or multidimensional cases. The inputs of a convolutional layer share the properties that they are represented as multidimensional arrays, have one or more axis where the ordering matters (for images these are the width and height), and can have an axis representing different views of the data (e.g. the RGB channels for a colored image) \\cite{guide_conv2018}.\n\nThe name convolution is not a coincidence, the layer operation is related to the convolutions seen in signal processing for 1D discrete signals, the image convolutions like gaussian and Sobel filters, or higher dimensions mathematical convolutions. The operation consists of sliding a window of weights, called the kernel, over the entire input and calculating the sum of the weighted inputs covered by this window to produce the resulting values.\n\\begin{figure}[hbt]\n    \\centering\n    \\caption{Convolutional layer kernel properties}\n    \\includegraphics[width=0.55\\textwidth]{chapters/NeuralNets/figures/cnn.pdf}\n    \\fonte{From the author (2021)}\n    \\label{fig:kernel_properties}\n\\end{figure}\n\nIt is simpler to understand this by looking at an image representation, \\autoref{fig:kernel_properties} shows an example of a kernel being applied at the corner of an image with a single channel, whose values are $255$, and that is padded with zeros.\n\nAs seen in the figure, the kernel will start at the top left of the image (including some optional zero padding) and calculate a value for that position, then it will step a number of pixels, called the stride, and calculate the next value. When there is no more room to step horizontally, the kernel will start again at the left of the image and step a stride size downward, this is repeated until the whole image is traversed.\n\nThe convolution value between the kernel window and the pixels is simply the sum of the element wise products between the pixel values and the corresponding kernel weight. An image can be used again to help visualize this process, \\autoref{fig:convolution} shows how a convolution is calculated for a $3\\times3$ kernel, on a $3\\times3$ image, with $1$ pixel zero padding, and stride of $1$ for both horizontal and vertical directions.\n\\begin{figure}[hbt]\n    \\centering\n    \\caption{Simple convolution process}\n    \\includegraphics[width=0.7\\textwidth]{chapters/NeuralNets/figures/convolution.pdf}\n    \\fonte{From the author (2021)}\n    \\label{fig:convolution}\n\\end{figure}\n\nAlso note that the kernel does not change when calculating the outputs of the convolution, in other words, the weights of the kernel are shared between the units. These weight are learned instead of being predefined, this allows for the network to decide which features the kernels should detect in order to solve the problem; these could be for example edges, textures, shapes, specific colors or others.\n\nOne important detail to mention is that the examples shown until now only consist of single channel images. For colored images with 3 channels, and more general cases with $n$ channels, the kernel is not just a 2D matrix but is more accurately represented as a volume (i.e. one 2D kernel for each channel) . This means that in \\autoref{fig:convolution} the kernel is a $3\\times3\\times1$ volume, if the input were a colored image it would be a $3\\times3\\times3$ volume. For the general case of an $n$ channel input, the volume would be $h\\times w\\times n$ for a kernel with height $h$ and width $w$.\n\nThe convolution for multiple channels is basically the same as for a single channel, each $h\\times w$ slice of the volume is convoluted with one of the channels and the results are added together to get the final convolution. These resulting values can be considered as the weighted inputs $\\bm{z}$ of the convolutional layer, so the activation function should be applied in order to get the final layer output.\n\nIn summary, for the case of images, a convolutional layer takes as input a 3D volume (i.e. two spatial dimensions to convolve with, and 1 channel dimension to give different views of the image) and operates on it using a kernel volume, the spatial sizes of the kernel are free to choose, but the number of channels must match. The convolution operation with a single kernel will reduce the input volume to a 2D feature map, where each point in the map indicates how much the feature is present at that region of the input covered by the kernel window. In general it is desirable to detect many different features from the input image, this means that convolutional layers will have multiple kernels and all the resulting convolutions will be stacked to produce an output volume.\n\nThe output will have as many channels as the number of kernels used in the convolutional layer, but the width and height will depend on the kernel size, stride, and padding. Consider sliding the kernel in the horizontal direction (the same logic applies to any direction and for all input dimensions), the number of values calculated by the convolution will be the number of possible positions that the kernel can be placed in this direction.\n\nSuppose that in the horizontal direction the sizes of input, kernel, zero padding, and stride are $i$, $k$, $p$, and $s$ respectively. Then the output size $o$ in this direction is given by \\autoref{eq:conv_output_size} \\cite{guide_conv2018}, where $\\lfloor{.}\\rfloor$ is the floor function.\n\\begin{equation} \\label{eq:conv_output_size}\n    o = \\left\\lfloor{\n        \\frac{i + 2p - k}{s}\n    }\\right\\rfloor + 1\n\\end{equation}\n\nConvolutions can be used to enlarge the input image, but are most commonly used to reduce the dimensions while raising the number of features detected. For example, the GoogLeNet Inception architecture reduces the $224\\times224\\times3$ input image to a feature map of size $7\\times7\\times1024$ \\cite{inceptionV1_2014}. This reduction is usually not done using only a single convolutional layer, it is most common for the input volume to pass through multiple convolutions that gradually reduce its width and height while increasing its depth. Looking at the Inception model again, the whole network is $22$ layers deep with most of those being convolutions for feature extraction \\cite{inceptionV1_2014}.\n\nAccording to \\textcite[chap. 9]{deepLearningBook2016}, convolutional layers leverage the ideas of sparse interactions, shared parameters, and equivariant representations to improve a machine learning system. They describe sparse interactions in the sense that kernels are smaller than the input, reducing the number of parameters, the memory used, the processing cost, and improving statistical efficiency. And the idea of equivariant representations is related with the invariance to translation, since at least in principle, the use of a sliding window allows for detecting the same feature no matter where it might appear on the image.\n\n\\subsubsection{Transposed Convolutions}\nAny convolution operation can be converted to a matrix multiplication where the input is flattened to a 1-dimensional vector and the kernel is converted to a sparse matrix $\\bm{C}$. The forward pass through the network, which is when the convolution is applied, is equivalent to multiplying the flattened input by $\\bm{C}$, and the backward pass is equivalent with multiplying by $\\bm{C}^T$ \\cite{guide_conv2018}. The multiplication with $\\bm{C}^T$ converts the output volume to the input volume and is commonly called the transposed convolution, or sometimes \\textit{deconvolution}.\n\nAny kernel represents both a convolution or transposed convolution, it all depends on how the values are interpreted as a matrix. It is important to note that the transposed convolution is not a way to reverse the convolution step, it is generally not possible to calculate the input of a convolution based on the kernel and output values. But the transpose operation can be considered as a reverse in the sense of transforming the output volume into the input volume.\n\nGiven the property of producing the opposite volume in relation to convolutions, transposed convolution layers are commonly used to upscale data to higher dimensions. For example, they are used in \\acp{GAN} to upscale the latent space vector into the corresponding image (see\\autoref{cha:gans}) \\cite{nipsGAN2017}. However, upscaling with this method has been shown to produce image artifacts \\cite{deconvolutionArtifacts2016} and some models, like styleGAN \\cite{styleGAN2018}, already drop the use of transposed convolution layers for different upscaling approaches.\n\n\\subsubsection{Pooling layer}\nPooling layers are very similar to convolutional layers in the sense that they both slide an window of some width and height through the image, using some stride value, optional padding, and producing a number for each possible position of the window. But pooling layers do not have any learnable parameters and just execute a predefined function over all the inputs inside the sliding window to produce the output.\n\nThe two most common types of pooling are max and average pooling. Max pooling, as the name suggests, simply returns the maximum value present in the sliding window, while average pooling returns the average of those values. Pooling layers are very commonly used together with convolutional layers, \\textcite[p. 355-336]{deepLearningBook2016} describe that a usual convolutional layer in a \\gls{CNN} consists of a convolution operation, followed by the nonlinear activation, and lastly by a pooling layer; they say that this operation helps to make the representation approximately invariant to input translations.\n\n\\subsubsection{Embedding Layer}\nThis layer is an alternative way of representing discrete valued inputs. Recall that one way to represent a discrete value (e.g. the class of a given input) is to use one-hot encoding, this allows for mapping $n$ possible values into a $n$ dimensional vector of all 0's and a single 1 representing the value.\n\nEmbedding layers offer a way to map $n$ values into a vector with $m$ dimensions, where $m$ can be any number. The mapping from value to vector in an embedding layer is not something fixed, but is also learned during training. This type of layer is very useful in language models, where encoding thousands of possible words into one-hot vectors is infeasible, embeddings allow for much smaller representations that can be learned by the model to best fit a given problem.\n\nWhen conditioning \\acp{GAN} with class information for the \\glsunset{CGAN} \\gls{CGAN} variant (see \\autoref{sub:cgan}), it is necessary to combine the label of the data together with the input. Embedding layers offer a more robust solution to this when compared to one-hot vectors, because of that they were used for conditioning in the experiments seen in\\autoref{cha:experiments}.\n\n\n\\subsection{Activation Functions}\nHistorically one of the first implementations of artificial neural networks used the step function as activation for the units \\cite[Chapter 1]{NN&DL2015}, this means that for positive inputs the step function produces a $1$ and for all other values it produces a $0$. It also could use the sign function \\cite{thePerceptron2017}, producing a $-1$ for non positive inputs.\n\nThis type of approach is called a Perceptron, one notable example of its implementation was the MARK I Perceptron, a hardware solution where all weights were regulated by potentiometers and automatically adjusted by motors to train the network \\cite{perceptron1960}. However it was later shown that this type of binary activation was very limited and could only solve linear separable problems \\cite{thePerceptron2017}.\n\nOne may question the need for activation functions or why do they need to be nonlinear, what is the reason for introducing nonlinearity to the network? To understand this, first note that not using an activation function is the same as setting the output $y = x$, this is also a linear relationship between the values, so it is only necessary to explain why a linear activation is a problem.\n\nThe nonlinearity is introduced to make the network able to learn more complex relationships in the data, since not all real world situations have a linear dependence between input and output. By transforming the input through multiple nonlinear activations it is possible to create very elaborate mappings from input to output. This does not hold true for linear transformations, since applying a sequence of them to some input is equivalent to applying just a single one.\n\nTo see this consider an input vector $\\bm{x}$ with two transformations matrices $\\bm{A}_1$, $\\bm{A}_2$ and vectors $\\bm{b}_1$, $\\bm{b}_2$. The output $\\bm{y}_2$ is obtained by applying two linear transformations to the input vector as follows.\n\\begin{equation} \\label{eq:linearity_1}\n    \\bm{y}_1 = \\bm{A}_1 \\bm{x} + \\bm{b}_1\n    \\qquad \\text{and} \\qquad\n    \\bm{y}_2 = \\bm{A}_2 \\bm{y}_1 + \\bm{b}_2 \\\\\n\\end{equation}\n\nBy rearranging the terms it can be confirmed that the two linear transformations are equivalent to a single one, this can be seen by the following derivation.\n\\begin{align*}\n    \\bm{y}_2& = \\bm{A}_2 (\\bm{A}_1 \\bm{x} + \\bm{b}_1) + \\bm{b}_2 \\\\\n    & = \\bm{A}_2 \\bm{A}_1 \\bm{x} +  \\bm{A}_2 \\bm{b}_1 + \\bm{b}_2 \\\\\n    & = \\bm{A} \\bm{x} + \\bm{b}\n\\end{align*}\n\nThis logic holds true for any number of linear transformations. Now it should be hopefully clear to see that there is inherently no difference between a multilayered neural network with linear activations and a simple two layered input-output network. It is necessary to introduce nonlinearities in the hidden layers in order to build more complex models \\textbf{--} linear transformations can however be used in the output layer to map the values to a more desirable range, regression problems are an example.\n\nAlthough nonlinear, the binary property of the step function limits the capabilities of a neural network, to work around this limitations it is necessary to introduce a different type of activation. To avoid the problem of jumping values it is best to have a continuous function instead of a discrete one, it is also important that this function be differentiable in its domain and that the derivatives are not zero everywhere (see \\glsunset{ReLU} \\gls{ReLU} activation in \\autoref{subsub:relu} for more remarks about this restrictions). The derivative requirements are necessary to make possible the use of the learning algorithm Gradient Descent with Backpropagation (see sections \\ref{sec:loss_&_gradient_descent} and \\ref{sec:backpropagation}).\n\nThis section will briefly introduce some important activation functions that are widely used in multiple machine learning problems and that were used in the experiments found in\\autoref{cha:experiments}.\n\n\\subsubsection{Sigmoid} \\label{subsub:sigmoid}\nUsually denoted by \\gls{sigmoid}, the sigmoid function maps all real numbers to the interval $(0, 1)$. For a given input $x$, the value for $\\sigma(x)$ is given by \\autoref{eq:sigmoid}.\n\\begin{equation} \\label{eq:sigmoid}\n    \\gls{sigmoid}(x) = \\frac{1}{1 + e ^ {-x}}\n\\end{equation}\n\nThe sigmoid function can be considered the continuous version of the step function, as the absolute value of $x$ grows, $\\sigma(x)$ gets exponentially closer to $\\mathsf{step}(x)$, but there is a continuous transition close to $0$. This can be seen more clearly in\\autoref{fig:activations}.\n\\begin{figure}[hbt]\n    \\centering\n    \\caption{Curves of sigmoid, tanh and ReLU activation functions}\n    \\includegraphics[width=0.6\\textwidth]{chapters/NeuralNets/figures/Activations.pdf}\n    \\fonte{From the author(2021)}\n    \\label{fig:activations}\n\\end{figure}\n\nThis function can be useful to convert a single output to a probability value or to normalize a set of outputs. However, the fact that the outputs are always positive raises some problems, \\textcite{efficientBackprop2012} showed that in these situations the backpropagation algorithm must update all the network parameters in the same direction, this means that the parameters are not free to wander the parameter space in the best direction.\n\nMost of the time the network will benefit more by adding to some parameters while subtracting from others, the restriction to always update in the same direction makes learning more difficult and can greatly reduce the speed of convergence. \\textcite{efficientBackprop2012} also argue that any deviation in the average of the outputs will bias the update direction, so it is better to have activations that are zero centered.\n\nKnowing this problem, it only makes sense to consider sigmoid activations in the output layer, since for most cases it is better to use a zero centered alternative like the \\gls{tanh} in the hidden layers.\n\n\\subsubsection{Hyperbolic Tangent}\nThe hyperbolic tangent function, as seen in \\autoref{eq:tanh}, is a zero centered, scaled, and shifted version of the sigmoid function.\n\\begin{equation} \\label{eq:tanh}\n    \\tanh(x) = \\frac{e^x - e^{-x}}{e^x + e^{-x}} = 2\\sigma(2x) - 1\n\\end{equation}\n\nThis function is almost always better than sigmoid since it has the same shape and properties without having the disadvantage of not being zero centered. It can be used in any layer, including the output. The times were a sigmoid would be preferred are when it is desired that the output be bounded to $(0,1)$, as is the case for a probability value.\n\n\\subsubsection{Rectified Linear Unit} \\label{subsub:relu}\n\\glsreset{ReLU}\nBoth the sigmoid and hyperbolic tangent functions have two characteristics that can raise some problems when training a machine learning model. The first one is that they can only produce very close approximations of the number zero, but not the exact value \\textbf{--} the only exception would be when the input of the \\gls{tanh} function is also exactly zero, but this is very unlikely to happen and would only work for very specific inputs.\n\nThe lack of a true zero can be undesirable when the goal of the network is to build a sparse representation of the data, that is, a representation that only depends on a small number of inputs that strongly correlate to the output. This is in contrast with a model that depends on many inputs, but most of them have very little impact on the output.\n\nThe sparsity argument not only has some biological support, but has been shown to also positively influence the quality of a model \\cite{relu2011}. Promoting sparsity is found in many other areas of science (e.g. statistical modeling, image compression) and it is very useful for producing simpler representations of the data \\cite{dataDrivenScience2019}.\n\nThe other problem present in the sigmoid and \\gls{tanh} functions is that they saturate for high absolute values of the input. Most of the variation in these functions occur close to zero, but for larger values there is barely any difference between outputs. For example, the difference between the \\gls{tanh} activation between inputs $1$ and $2$ is around $0.2$, while the difference from $2$ to $100$ is just $0.036$. One other way to say this is that the derivatives of these functions are very close to zero for inputs far from the origin (see \\autoref{fig:derivatives}), this can give rise to the vanishing gradients problem and make learning extremely slow (see \\autoref{sub:vanishing_gradients}).\n%\n\\begin{figure}[hbt]\n    \\centering\n    \\caption{Derivative of sigmoid, tanh and ReLU activation functions}\n    \\includegraphics[width=0.6\\textwidth]{chapters/NeuralNets/figures/Derivatives.pdf}\n    \\fonte{From the author(2021)}\n    \\label{fig:derivatives}\n\\end{figure}\n\nThe \\gls{ReLU} activation function is an alternative that addresses both of the mentioned problems with sigmoid and \\gls{tanh}. It is constructed from combining different linear regions (called a piecewise linear function), this allows for the activation to inherit many desirable properties of linear transformations while still retaining nonlinearity and being able to build complex relations \\cite{deepLearningBook2016}.\n\nThe \\gls{ReLU} function is simply composed of a constant zero for all negative inputs and the identity function for everything else, this means that for an input $x$ the activation is calculated as shown in \\autoref{eq:relu}.\n\\begin{equation} \\label{eq:relu}\n    \\ReLU(x) = \\max(0, x)\n\\end{equation}\n\nThis definition allows for \\gls{ReLU} to produce exact zeros for any negative inputs, promoting sparsity in the model representations. The constant positive derivative (see \\autoref{fig:derivatives}) also removes the problem of vanishing gradients, since the units never saturate. Another big advantage of \\gls{ReLU} is that it is extremely easy to compute, a simple \\texttt{if} statement is enough to get the result; compared with the need to calculate exponentials in the sigmoid and \\gls{tanh} functions, \\gls{ReLU} performance is much faster.\n\nSince around 2010, with papers like \\cite{relu2011} exploring the \\gls{ReLU} activation, there were many popular methods that showed impressive results using this function (e.g. \\cite{alexnet2012} and \\cite{inceptionV3_2015}). At the current time \\gls{ReLU} is the standard recommended activation function to be used in most problems \\cite{deepLearningBook2016}.\n\nThere are however some downsides to this activation. First there is the sharp change in the function behavior at the value $0$, making its derivative undefined at that point, this however does not seem to be a problem in practice \\cite{relu2011}. \\gls{ReLU} also loses the desirable zero centered property that made \\gls{tanh} a good substitute for the sigmoid, the argument from \\textcite{efficientBackprop2012} holds for all activations, this means that all the network updates for units that use \\gls{ReLU} must be made in the same direction, making learning more difficult.\n\nLastly, for a unit to be able to learn it is necessary that it outputs a value in the range where the activation function has a non-zero derivative for at least one example in the training data. But it is possible that for all the training data in a given problem, there exists some units using \\gls{ReLU} activations that will always output zero, this makes learning impossible in these units and effectively freezes them on their state forever.\n\nThere are many other alternatives proposed to address these problems, some relevant examples are Maxout, LeakyReLU, ELU, GELU and PReLU, these have found some success in big machine learning problems\\footnote{\n    GELU is used in natural language processing models like GPT-3 \\cite{gpt3_2020}\n} and the benchmark by \\cite{CaffeNetBench2017} showed good results for some of these alternatives \\textbf{--} although \\gls{ReLU} also fared well in those tests.\n\nBetween these alternatives, LeakyReLU is specially relevant for \\acp{GAN}, being an important piece of the \\glsunset{DCGAN}\\gls{DCGAN} variant that is the base of many \\gls{GAN} architectures. It consists of a simple change from ReLU that just guarantees that the units will always have at least some positive derivative. This activation is calculated as shown in \\autoref{eq:leaky_relu}, where $\\alpha$ is a hyperparameter that must be a small value (usually $0.3$).\n\\begin{equation} \\label{eq:leaky_relu}\n    \\LeakyReLU(x) = \\max(\\alpha x, x)\n\\end{equation}\n\n\\subsubsection{Softmax}\nIn classification problems it is very common to have the output layer encode the input class has a $n$ dimensional, one-hot encoded vector, where $n$ is the number of classes. Since in one-hot encoding each element corresponds to the probability of the input belonging to the corresponding class (all zeros and a single $1$ for the correct class), it is desirable for the output of a classification model to also be a probability distribution. Besides the fact that it aligns with the encoding representation, it also gives a meaningful representation for the output of the network, by observing the output probabilities it is possible to have an idea of how confident the network is in the results\\footnote{\n    Since the values in a probability distribution should always add to $100\\%$ this may not always give good representations, this is the case for adversarial examples that can fool the network to misclassify images with a high degree of confidence \\cite{adversarialExamples2013}.\n}.\n\nThe softmax activation function offers a way to map all the units weighted inputs to a probability distribution. One difference when compared to the other activation functions is that the softmax does not take a single number as input, instead it uses all values in the layer for calculating the unit activation. This makes sense since the probabilities are dependent on the proportions of each unit weighted input. \\autoref{eq:softmax} shows how the activation for the unit $i$ is calculated based on the layer weighted inputs $(z_0 \\dots z_n)$, the layer superscripts were omitted for clarity.\n\\begin{equation} \\label{eq:softmax}\n    a_i = \\frac{e^{z_i}}{ \\sum\\limits_{k=0}^{n}{e^{z_k}} }\n\\end{equation}\n", "meta": {"hexsha": "72da75e9dcb29123f87cc0ca4019b13d0c5a9154", "size": 38850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Overleaf/chapters/NeuralNets/ANN.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/ANN.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/ANN.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": 124.5192307692, "max_line_length": 778, "alphanum_fraction": 0.7781724582, "num_tokens": 9099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6810720829943405}}
{"text": "\\section{Support Vector Machines II}\n\n\\subsection{Hard Margin Problem}\n\n\\begin{frame}\n  \\frametitle{Hard Margin Problem}\n\n  The hard margin SVM optimization problem is formulated as:\n\n  \\begin{eqnarray*}\n    & \\mbox{minimize}   & \\frac{1}{2} {\\|\\vec \\alpha\\|^2_2} \\\\[.3cm]\n    & \\mbox{subject to} & \\forall i: \\quad y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1 \\geq 0\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\subsection{Soft Margin Problem}\n\n\\begin{frame}\n  \\frametitle{Soft Margin Problem}\n \n  The soft margin SVM optimization problem is formulated as:\n  \n  \\begin{eqnarray*}\n    & \\mbox{minimize}   & \\frac{1}{2} {\\|\\vec \\alpha\\|^2_2} + \\mu \\sum_i \\xi_i \\\\[.5cm]\n    & \\mbox{subject to} & \\forall i: \\quad -(y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1+\\xi_i) \\leq 0~, \\\\[.3cm]\n    &                   & \\forall i: \\quad -\\xi_i \\leq 0\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\subsection{Lagrangian}\n\n\\begin{frame}\n  \\frametitle{Lagrangian}\n\n  The solution of the \\structure{constrained convex optimization problem} \\\\\n  requires the Lagrangian:\n \n  \\begin{eqnarray*}\n    L(\\vec \\alpha, \\alpha_0, \\vec \\xi, \\vec \\lambda, \\vec \\mu)\n     & = & \\frac{1}{2} {\\|\\vec \\alpha\\|^2_2} + \\mu \\sum_i \\xi_i  -\\sum_i \\mu_i \\xi_i\\\\\n     &   & \\quad - \\sum_i \\lambda_i (y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1+\\xi_i)\n  \\end{eqnarray*}\n\\end{frame}\n\n\\subsection{Lagrangian}\n\n\\begin{frame}\n  \\frametitle{Lagrangian}\n\n  The solution of the \\structure{constrained convex optimization problem} \\\\\n  requires the Lagrangian:\n\n~\\\\ \n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\bf{meta-}~~~~~~~~\\bf{Lagrangian}\\\\\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\bf{parameter}~~~~\\bf{multiplier}\n  \\begin{eqnarray*}\n    L(\\vec \\alpha, \\alpha_0, \\vec \\xi, \\vec \\lambda, \\vec \\mu)\n\t  & = & \\frac{1}{2} {\\|\\vec \\alpha\\|^2_2} + {\\color{red} \\mu} \\sum_i \\xi_i  -\\sum_i {\\color{red} \\mu_i} \\xi_i\\\\\n     &   & \\quad - \\sum_i \\lambda_i (y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1+\\xi_i)\n  \\end{eqnarray*}\n\\end{frame}\n\n\\subsection{Lagrangian}\n\n\\begin{frame}\n  \\frametitle{Lagrangian}\n\n  The solution of the \\structure{constrained convex optimization problem} \\\\\n  requires the Lagrangian:\n\n~\\\\ \n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\bf{meta-}~~~~~~~~\\bf{Lagrangian}\\\\\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\bf{parameter}~~~~\\bf{multiplier}\n  \\begin{eqnarray*}\n    L(\\vec \\alpha, \\alpha_0, \\vec \\xi, \\vec \\lambda, \\vec \\mu)\n\t  & = & \\frac{1}{2} {\\|\\vec \\alpha\\|^2_2} + {\\color{red} c} \\sum_i \\xi_i  -\\sum_i {\\color{red} \\mu_i} \\xi_i\\\\\n     &   & \\quad - \\sum_i \\lambda_i (y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1+\\xi_i)\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Lagrangian \\cont}\n\n  \\structure{Partial derivatives  I:}\n \n  \\begin{displaymath}\n    \\frac{\\partial  L(\\vec \\alpha, \\alpha_0, \\vec \\xi, \\vec \\lambda, \\vec \\mu)}{\\partial \\vec \\alpha} ~=~ \n    \\vec \\alpha - \\sum_i \\lambda_i y_i \\vec x_i ~\\stackrel{!}{=}~ \n    \\vec 0.\n  \\end{displaymath}\n\n  Thus we have:\n\n  \\begin{displaymath}\n    \\vec \\alpha = \\sum_i \\lambda_i y_i \\vec x_i~. \n  \\end{displaymath}\n\\end{frame}\n \n \n\\begin{frame}\n\n  \\frametitle{Lagrangian \\cont}\n  \n  \\structure{Partial derivatives  II:}\n  \n  \\begin{displaymath}\n    \\frac{\\partial  L(\\vec \\alpha, \\alpha_0, \\vec \\xi, \\vec \\lambda, \\vec \\mu)}{\\partial \\alpha_0} ~=~\n   -\\sum_i \\lambda_i y_i ~\\stackrel{!}{=}~ \n   0\n  \\end{displaymath}\n  \\pspread\n\n  \\structure{Partial derivatives  III:}\n  \n  \\begin{displaymath}\n    \\frac{\\partial  L(\\vec \\alpha, \\alpha_0, \\vec \\xi, \\vec \\lambda, \\vec \\mu)}{\\partial \\xi_i} ~=~ \n    c - \\mu_i - \\lambda_i ~\\stackrel{!}{=}~ \n    0\n  \\end{displaymath}\n\\end{frame}\n\n\n\\subsection{Lagrange Dual}\n\n\\begin{frame}\n  \\frametitle{Lagrange Dual}\n \n  Let us consider the \\structure{Lagrange function for the dual problem} for the hard margin case:\n  \n  \\begin{eqnarray*}\n    L_\\text{D}\n    &=& \\frac{1}{2} {\\vec \\alpha^T \\vec \\alpha} -\n        \\sum_i \\lambda_i (y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1) \\\\[.3cm] \\pause\n    &=& \\frac{1}{2}{\\vec \\alpha^T \\vec \\alpha} - \n        (\\underbrace{\\sum_i \\lambda_i y_i\\cdot \\vec x_i)^T}_{{\\vec \\alpha^T}} \\vec \\alpha - \n        \\underbrace{ \\sum_i \\lambda_iy_i}_{ = 0}\\ \\alpha_0 + \n        \\sum_i \\lambda_i \\\\[.3cm] \\pause\n    &=& -\\frac{1}{2} \\sum_i \\sum_j \\lambda_i \\lambda_j y_i y_j \\cdot \\vec x_i^T\\vec x_j +  \\sum_i \\lambda_i\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{The Lagrange Dual Problem}\n \n  The Lagrange dual problem is given by the optimization problem: \\\\[.25cm]\n  \n  \\begin{center}\n    \\tikz[baseline]{\n      \\node[fill=bl1!100,anchor=base,rounded corners=3pt] (d1) {\n        \\color{bl3}\n        $\\begin{aligned}\n           \\displaystyle \n           \\mbox{maximize}   & \\qquad -\\frac{1}{2} \\sum_i \\sum_j \\lambda_i \\lambda_j y_i y_j \\cdot \\vec x_i^T\\vec x_j + \\sum_i \\lambda_i \\\\[.3cm]\n           \\mbox{subject to} & \\qquad \\vec{\\lambda}\\succeq 0 \\\\\n                             & \\qquad \\sum_{i} \\lambda_i \\, y_i = 0\n         \\end{aligned}$\n      };\n    }\n  \\end{center}\n  \\pause\n\n  \\structure{Benefits of the dual representation}\n  \\begin{itemize}\n    \\item The model can be reformulated using kernels.\n    \\item SVMs can be applied efficiently to feature spaces whose dimensionality exceeds the number of samples.\n  \\end{itemize}\n\\end{frame}\n\n\\note{\n  From Bishop: Pattern Recognition and Machine Learning\n\n  The solution to a quadratic programming problem in $d$ variables in general has computational complexity that is $\\mathcal{O}(d^3)$.\n  In going to the dual formulation we have turned the original optimization problem, which involved minimizing\n  \\begin{eqnarray*}\n    & \\mbox{minimize}   & \\frac{1}{2} {\\|\\vec \\alpha\\|^2_2} \\\\[.3cm]\n    & \\mbox{subject to} & \\forall i: \\quad y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) -1 \\geq 0\n  \\end{eqnarray*}\n  over $d$ variables, into the dual problem, which has $m$ variables.\n  For a fixed set of basis functions whose number $d$ is smaller than the number $m$ of data points, the move to the dual problem appears disadvantageous. \n  However, it allows the model to be reformulated using kernels, and so the maximum margin classifier can be applied efficiently to feature spaces whose dimensionality exceeds the number of data points, including infinite feature spaces.\n  The kernel formulation also makes clear the role of the constraint that the kernel function $k(\\vec{x},\\vec{x}')$ be positive definite, because this ensures that the Lagrangian function $L_\\text{D}$ is bounded below, giving rise to a well-defined optimization problem.\n}\n\n\n\\begin{frame}\n  \\frametitle{Lagrange Dual Problem \\cont}\n \n  For convex optimization problems with differentiable objective and constraint functions, the duality gap is zero,\n  if the KKT conditions are satisfied. \\\\[.5cm] \\pause \n\n  Especially the \\structure{complementary slackness} condition is interesting for us:\n  \\begin{displaymath}\n    \\forall i: \\quad \\lambda_i \\, f_i(\\vec{x}) = 0 \n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Lagrange Dual Problem \\cont}\n \n  \\structure{Complementary slackness for hard margin SVMs:}\n\n  \\begin{displaymath}\n    \\forall i: \\quad \\lambda_i \\, (y_i\\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) - 1) = 0 \\pause\n  \\end{displaymath}\n \n  \\structure{Implications:} \\\\[.2cm]\n  \n  \\begin{enumerate}\n    \\item If $\\lambda_i>0$, then $y_i \\, (\\vec{\\alpha}^T \\vec{x}_i + \\alpha_0) - 1=0$, and thus:\n      \\begin{displaymath}\n        y_i(\\vec{\\alpha}^T \\vec{x}_i + \\alpha_0) = 1~.\n      \\end{displaymath}\n      All $\\vec x_i$ with $\\lambda_i>0$  are elements at the boundary of the slab; \\\\\n      these samples are called \\structure{\\emph{support vectors}}. \\\\[.2cm] \\pause\n    \\item We have seen that $  \\vec \\alpha = \\sum_i \\lambda_i y_i \\vec x_i $, thus the norm vector of the decision boundary is a linear combination of support vectors.\n  \\end{enumerate}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Dual Representation}\n\n  The \\structure{decision function} can also be rewritten using the duality:\n\n  \\begin{center}\n    \\tikz[baseline]{\n      \\node[fill=bl1!100,anchor=base,rounded corners=3pt] (d1) {\n        \\color{bl3}\n        $\\begin{aligned}\n           \\displaystyle \n           f(\\vec x) = \n           \\vec{\\alpha}^T \\vec{x} +\\alpha_0 = \n           \\sum_{i=1}^m \\lambda_i y_i \\vec x_i^T \\vec x + \\alpha_0\n         \\end{aligned}$\n      };\n    }\n  \\end{center}\n  \\pause\n\n  \\vspace{.5cm}\n  \\structure{Conclusion:} \\\\[.2cm]\n \n  Feature vectors only appear in inner products, both in the learning and the classification phase.\n\\end{frame}\n\n\n\\subsection{Feature Transforms}\n\n\\begin{frame}\n  \\frametitle{Feature Transforms}\n\n  \\structure{Linear decision boundaries} in its current form have serious \\structure{limitations}: \\\\[.2cm]\n  \n  \\begin{itemize}\n    \\item  Non-linearly separable data cannot be classified. \\\\[.3cm]\n    \\item  Noisy data cause problems. \\\\[.3cm]\n    \\item  Formulation deals with vectorial data only.\n  \\end{itemize}\n  \\pspread\n\n  \\structure{Possible solution:} \\\\[.2cm]\n\n  \\begin{itemize}\n    \\item Map data into richer feature space using non-linear feature transform, \\\\\n      then use a linear classifier.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transforms \\cont}\n \n  We select a feature transform \n  \\begin{displaymath}\n    \\phi: \\real^d \\rightarrow \\real^D, \\quad D \\ge d\n  \\end{displaymath}\n  such that the resulting features \n  \\begin{displaymath}\n    \\phi(\\vec x_i), \\quad i = 1, 2, \\dots, m\n  \\end{displaymath}\n  are linearly separable.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transforms \\cont}\n\n  \\begin{ovalblock}{Example}\n    Assume the decision boundary is given by the quadratic function\n    \\begin{displaymath}\n      f(\\vec x) = a_0 + a_1 x_1^2 + a_2 x_2^2 + a_3 x_1 x_2 + a_4 x_1+a_5 x_2.\n    \\end{displaymath}\n\n    Obviously this is not a linear decision boundary. \\\\[.25cm] \\pause\n\n    By the following mapping, we get features that have a linear decision boundary:\n    \\small\n    \\begin{displaymath}\n      \\phi(\\vec x) = \\left(\\begin{array}{c}\n                             1 \\\\ x_1^2 \\\\ x_2^2 \\\\ x_1x_2 \\\\ x_1 \\\\ x_2\n                           \\end{array}\n                     \\right)\n    \\end{displaymath}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transforms \\cont}\n  \n  These feature transforms can be easily incorporated into SVMs:\\\\[.25cm]\n  \n  \\begin{itemize}\n    \\item \\structure{Decision boundary:}\n      {\\small\n        \\begin{displaymath}\n          f(\\vec x) = \\sum_i \\lambda_i y_i \\cdot  \\langle\\phi(\\vec x_i), \\phi(\\vec x) \\rangle + \\alpha_0 \\pause\n        \\end{displaymath}\n      }\n    \\item The Lagrange dual problem is given by the \\structure{optimization problem}:\n      {\\small\n        \\begin{eqnarray*}\n          \\mbox{maximize}  & & -\\frac{1}{2} \\sum_i \\sum_j \\lambda_i \\lambda_j y_i y_j \\cdot \\langle\\phi(\\vec x_i),\\phi(\\vec x_j)\\rangle + \\sum_i \\lambda_i \\\\[.5cm]\n          \\mbox{subject to} & &\\vec{\\lambda}\\succeq 0, \\quad \\sum_{i} \\lambda_i \\, y_i = 0\n        \\end{eqnarray*}\n      }\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Kernel Functions}\n\n\\begin{frame}\n  \\frametitle{Kernel Functions}\n  \n  We now define \\structure{kernel functions}:\n  \\begin{displaymath}\n    k(\\vec x, \\vec x') =  \\langle \\phi(\\vec x), \\phi(\\vec x') \\rangle\n  \\end{displaymath}\n  \\pspread\n \n  Typical kernel functions are: \\\\[.25cm]\n \n  \\small\n  \\begin{itemize}\n    \\item \\structure{Linear:} \n      \\begin{displaymath}\n        k(\\vec x, \\vec x') =~ \\langle\\vec x, \\vec x'\\rangle\n      \\end{displaymath}\n    \\item \\structure{Polynomial:} \n      \\begin{displaymath}\n        k(\\vec x, \\vec x') = (\\langle\\vec x, \\vec x'\\rangle + 1)^k\n      \\end{displaymath}\n    \\item \\structure{Radial basis function:} \n      \\begin{displaymath}\n        k(\\vec x, \\vec x') = e^{-\\gamma\\|\\vec x- \\vec x'\\|_2^2}\n      \\end{displaymath}\n    \\item \\structure{Sigmoid kernel:} \n      \\begin{displaymath}\n        k(\\vec x, \\vec x') =\\mbox{tanh}({ \\alpha \\langle\\vec x, \\vec x'\\rangle + \\beta})\n      \\end{displaymath}\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Lessons Learned}\n\n\\begin{frame}\n  \\frametitle{Lessons Learned}\n  \n  \\begin{itemize}\n    \\item Lagrangian formulation of the hard and soft margin problems \\\\[.5cm]\n    \\item Lagrange dual representation \\\\[.5cm]\n    \\item Idea of feature transforms\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 Bernhard Sch{\\\"o}lkopf, Alexander J. Smola: \\\\\n      \\structure{Learning with Kernels}, \\\\\n      The MIT Press, Cambridge, 2003. \\\\[.15cm]\n    \\item Vladimir N. Vapnik: \\\\\n      \\structure{The Nature of Statistical Learning Theory}, \\\\\n      Information Science and Statistics, Springer, Heidelberg, 2000. \\\\[.15cm]\n    \\item S.~Boyd, L.~Vandenberghe: \\\\\n      \\structure{Convex Optimization}, \\\\\n      Cambridge University Press, 2004. \\\\\n      \\point{\\small \\url{http://www.stanford.edu/~boyd/cvxbook/}} \\\\[.15cm]\n    \\item Christopher M.\\ Bishop: \\\\\n      \\structure{Pattern Recognition and Machine Learning}, \\\\ \n      Springer, New York, 2006\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 Lagrangian of the hard margin SVM? \\\\[1cm]\n    \\item What are the KKT optimality conditions for the hard margin SVM? \\\\[1cm]\n    \\item How do we apply the KKT conditions to the Lagrange Dual? \\\\[1cm]\n    \\item What can we conclude from this reformulated Lagrange Dual?\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "9a8366dd93d020ff75a926d1fdf98fb29310b92d", "size": 13601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14_svm_2.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": "14_svm_2.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": "14_svm_2.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": 32.3833333333, "max_line_length": 270, "alphanum_fraction": 0.631644732, "num_tokens": 4426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.681072082237629}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Maximum likelihood estimators}\\label{sec:mle}\n\n% defn: MME\n\\begin{definition}\nAn estimator $T = T(\\mathbf{X})$ is said to be a \\emph{maximum likelihood estimator} (MLE) of $\\theta$ if\n\\[\nT = \\argmax_{\\theta\\in\\Theta} L(\\theta;\\mathbf{X}),\n\\]\nwhich means that $T$ is a value of $\\theta$ which maximises the likelihood function $L(\\theta,\\mathbf{X})$ over the parameter space $\\Theta$.\n%\n%Given $\\mathbf{X}=\\mathbf{x}$, a \\emph{maximum likelihood estimate} of the true parameter value is one that maximises the likelihood function over the parameter space $\\Theta$. This can be written as\n%\\[\n%T_{\\text{\\tiny{MLE}}}(\\mathbf{x})\n%\t= \\argmax_{\\theta\\in\\Theta} L(\\theta;\\mathbf{x}) \n%%\t= \\argmax_{\\theta\\in\\Theta} \\prod_{i=1}^n f(x_i;\\theta).\n%\\]\n%The estimator $T_{\\text{\\tiny{MLE}}}(\\mathbf{X})$ is called a \\emph{maximum likelihood estimator} (MLE) of $\\theta$.\n\\end{definition}\n\n%%-----------------------------\n%\\subsection{Log-likelihood}\n%\nTo find a value of $\\theta$ that maximises $L(\\theta;\\mathbf{X})$ we might differentiate it with respect to $\\theta$, then set the resulting expression to zero and solve for $\\theta$. Computing derivatives of products such as $\\prod_{i=1}^n f(X_i;\\theta)$ is not always straightforward however, so we work with the \\emph{log-likelihood} function whenever possible.\n\n\\begin{definition}\nGiven $\\mathbf{X}=\\mathbf{x}$, the \\emph{log-likelihood function} $\\ell:\\Theta\\to [0,\\infty)$ is\n\\[\n\\ell(\\theta;\\mathbf{x}) = \\log L(\\theta;\\mathbf{x}) = \\displaystyle\\sum_{i=1}^n \\log f(x_i;\\theta).% \\quad\\text{for $\\theta\\in\\Theta$.}\n\\]\n\\end{definition}\n%Because log is a one-to-one function, there is no loss of information in considering $\\ell(\\theta)$ instead of $L(\\theta)$.\n%\n%\n%\\begin{definition}\n%$\\log L(\\theta;\\mathbf{x})$ is called the \\emph{log-likelihood function} of $\\theta$, which we denote by\n%\\[\n%\\ell(\\theta;\\mathbf{x}) \n%%\t= \\log L(\\theta;\\mathbf{x}) \n%\t= \\sum_{i=1}^n \\log f(x_i;\\theta)\n%\\]\n%\\end{definition}\n\nBecause $\\log$ is a strictly increasing function, a value of $\\theta$ that maximizes $\\ell(\\theta;\\mathbf{x})$ coincides with a value of $\\theta$ that maximizes $L(\\theta;\\mathbf{x})$. A maximum likelihood estimate of $\\theta=(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ can therefore be obtained by solving the equations\n\\[\n\\frac{\\partial\\ell}{\\partial\\theta_1}=0,\n\\quad\n\\frac{\\partial\\ell}{\\partial\\theta_2}=0,\n\\quad\\ldots\\quad,\n\\frac{\\partial\\ell}{\\partial\\theta_k}=0.\n\\]\n\n% example: MLE for bernoulli\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Bernoulli}(\\theta)$ distribution where $0<\\theta<1$ is unknown. Find the MLE of $\\theta$.\n\\begin{solution}\nLet $\\boldx = (x_1,x_2,\\ldots,x_n)$ be a realisation of the sample.\n\\bit\n\\it PMF: $ f(x_i;\\theta) = \\theta^{x_i} (1-\\theta)^{1-x_i}$ for $x_i\\in\\{0,1\\}$.\n\\it Likelihood function: $ L(\\theta) = L(\\theta;\\mathbf{x}) = \\prod_{i=1}^n \\theta^{x_i} (1-\\theta)^{1-x_i}$\n\\it Log-likelihood: $ \\ell(\\theta) = \\sum_{i=1}^n\\big[ x_i\\log\\theta + (1-x_i)\\log(1-\\theta) \\big]$\n\\it First derivative: $ \\ell'(\\theta) = \\frac{1}{\\theta(1-\\theta)}\\sum_{i=1}^n (x_i - \\theta)$\n\\it Setting $\\ell'(\\theta)=0$, we obtain $ \\theta = \\frac{1}{n}\\sum_{i=1}^n x_i$.\n\\it Second derivative: \n$ \\ell''(\\theta) = -\\sum_{i=1}^n \\frac{x_i(1-\\theta)^2 + (1-x_i)\\theta^2}{\\theta^2(1-\\theta)^2} < 0$ because $x_i\\in\\{0,1\\}$ and $0<\\theta<1$.\n\\it Since $\\ell''(\\theta) < 0$ for all $\\theta>0$, the turning point is indeed a maximum.\n\\it The MLE of $\\theta$ is therefore the proportion of successes in $n$ trials:\n\\[\nT = \\frac{1}{n}\\sum_{i=1}^n X_i.\n\\]\n\\eit\n%\\textbf{Note}: in the expression for $\\ell''(\\theta)$ each summand is either $1/\\theta^2$ (when $x_i=0$) or $1/(1-\\theta)^2$ (when $x_i=1$), and hence greater than one. Thus $\\ell''(\\theta) < -n$, so the maximum becomes `sharper' as $n$ increases.\n\\end{solution}\n\\end{example}\n\n% example: MLE for uniform\n\\begin{example}\\label{ex:mleuniform}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Uniform}[0,\\theta]$ distribution where $\\theta>0$ is unknown. Find the maximum likelihood estimator of $\\theta$.\n\\end{example}\n\n\\begin{solution}\nLet $\\boldx = (x_1,x_2,\\ldots,x_n)$ be a realisation of the sample.\n\n\\bigskip\nThe PDF of the $\\text{Uniform}[0,\\theta]$ distribution is $f(x) = 1/\\theta$ for $0 < x < \\theta$ (and zero otherwise)\n\n\\bigskip\nThe parameter space is $\\Theta = \\{\\theta:\\theta>0\\}$, and the likelihood function is\n\\[\nL(\\theta;\\mathbf{x}) = \\left\\{\\begin{array}{ll}\n\t\\displaystyle\\frac{1}{\\theta^n}\t& \\text{for } \\theta > \\max\\{x_1,x_2,\\ldots,x_n\\} \\\\[2ex]\n\t0\t\t\t\t& \\text{otherwise}.\n\\end{array}\\right.\n\\]\n\\bit\n\\it $L(\\theta;\\mathbf{x})$ is a decreasing function of $\\theta$ for all $\\theta>\\max\\{x_1,x_2,\\ldots,x_n\\}$.\n\\it Thus the MLE of $\\theta$ is $\\max\\{X_1,X_2,\\ldots,X_n\\}$.\n\\eit\n\\end{solution}\n\n% example: mle for normal\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\mu,\\sigma^2)$ distribution, where $\\mu$ and $\\sigma^2$ are both unknown. Find the MLEs of $\\mu$ and $\\sigma^2$.\n\\begin{solution}\nLet $\\mathbf{x} = (x_1,x_2,\\ldots,x_n)$ be a realisation of the sample. The common PDF of the $X_i$ is\n\\[\nf(x;\\mu,\\sigma) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left(-\\frac{1}{2}\\left(\\frac{x-\\mu}{\\sigma}\\right)^2\\right).\n\\]\nThe likelihood function is \n\\[\nL(\\mu,\\sigma) = \\prod_{i=1}^n \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left(-\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\right).\n\\]\nThe log-likelihood function is\n\\begin{align*}\n\\ell(\\mu,\\sigma) \n\t= \\sum_{i=1}^n \\log f(x_i;\\mu,\\sigma) \n\t& = \\sum_{i=1}^n \\left( -\\log(\\sqrt{2\\pi}) - \\frac{1}{2}\\log(\\sigma^2) - \\frac{(x_i-\\mu)^2}{2\\sigma^2}\\right) \\\\\n\t& = -n\\log(\\sqrt{2\\pi}) - \\frac{n}{2}\\log(\\sigma^2) - \\frac{1}{2\\sigma^2}\\sum_{i=1}^n (x_i-\\mu)^2\n\\end{align*}\nThe partial derivatives of $\\ell(\\mu,\\sigma)$ with respect to $\\mu$ and $\\sigma$ are, respectively,\n\\[\n\\frac{\\partial\\ell}{\\partial\\mu} = \\frac{1}{\\sigma^2}\\sum_{i=1}^n(x_i-\\mu)\n\\qquad\\text{and}\\qquad\n\\frac{\\partial\\ell}{\\partial\\sigma} = -\\frac{n}{\\sigma} + \\frac{1}{\\sigma^3}\\sum_{i=1}^n(x_i-\\mu)^2.\n\\]\nSetting these to equal zero then solving for $\\mu$ and $\\sigma$, we obtain\n\\[\n\\hat{\\mu}_{\\text{\\scriptsize{MLE}}} = \\frac{1}{n}\\sum_{i=1}^n X_i = \\Xbar\n\\qquad\\text{and}\\qquad\n\\hat{\\sigma}^2_{\\text{\\scriptsize{MLE}}} = \\frac{1}{n}\\sum_{i=1}^n (X_i-\\Xbar)^2.\n\\]\n\\bit\n\\it The MLE of $\\mu$ is the \\emph{sample mean}.\n\\it The MLE of $\\sigma^2$ is the \\emph{empirical mean squared deviation from the sample mean}.\n\\eit\n\\end{solution}\n\\end{example}\n\n% exercises\n\\begin{exercise}\n\\begin{questions}\n\n\\question % mle for exponential\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Exponential}(\\lambda)$ distribution, where the rate parameter $\\lambda>0$ is unknown. Find the MLE of $\\lambda$. \n\\begin{answer}\nLet $\\mathbf{x}=(x_1,x_2,\\ldots,x_n\\}$ be a realization of the sample. The PDF of the $\\text{Exponential}(\\lambda)$ distribution is\n\\[\nf(x;\\lambda) = \\left\\{\\begin{array}{ll} \n\t\\lambda\\exp(-\\lambda x) \t& \\text{for } x>0, \\\\\n\t0\t\t\t\t\t\t& \\text{otherwise}.\n\\end{array}\\right.\n\\]\nHence the likelihood function is\n\\[\nL(\\lambda) = L(\\lambda;\\mathbf{x}) \n\t= \\prod_{i=1}^nf(x_i;\\lambda)\n\t= \\prod_{i=1}^n\\lambda e^{-\\lambda x_i} \n\t= \\lambda^n\\exp\\left(-\\lambda\\sum_{i=1}^n x_i\\right).\n\\]\nand the log-likelihood function is therefore \n\\[\n\\ell(\\lambda) = n\\log\\lambda - \\lambda\\sum_{i=1}^nx_i\n\\]\nThe first derivative of the log-likelihood function (with respect to $\\lambda$) is\n\\[\n\\ell'(\\lambda) = \\frac{n}{\\lambda } -\\sum_{i=1}^{n}x_{i},\n\\]\nand setting this equal to zero we obtain \n\\[\n\\lambda =\\left(\\frac{1}{n}\\sum_{i=1}^n x_i\\right)^{-1}.\n\\]\nThe second derivative of $\\ell(\\lambda)$ is\n\\[\n\\ell''(\\lambda) = -\\frac{n}{\\lambda^2} < 0 \\text{\\quad for all $\\lambda > 0$.}\n\\]\nHence the turning point is a maximum, so the MLE is $\\hat{\\lambda}_{\\text{\\scriptsize{MLE}}} = \\bar{X}^{-1}$.\n\n\\end{answer}\n\n\\question % mle for Poisson\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Poisson}(\\lambda)$ distribution, where $\\lambda>0$ is unknown. Find the MLE of $\\lambda$.\n\\begin{answer}\nLet $\\mathbf{x}=(x_1,x_2,\\ldots,x_n\\}$ be a realization of the sample. The PMF of the $\\text{Poisson}(\\lambda)$ distribution is\n\\[\nf(x;\\lambda) = \\left\\{\\begin{array}{ll} \n\t\\displaystyle\\frac{\\lambda^x\\exp(-\\lambda)}{x!} \t& \\text{for } x=0,1,2,3,\\ldots \\\\[2ex]\n\t0\t\t\t\t\t\t\t\t\t& \\text{otherwise}.\n\\end{array}\\right.\n\\]\nThe likelihood function is \n\\[\nL(\\lambda) = L(\\lambda;\\mathbf{x}) \n\t= \\prod_{i=1}^n f(x_i ;\\lambda )\n\t= \\frac{\\lambda^{\\sum_{i=1}^n x_i}\\exp(-n\\lambda)}{\\prod_{i=1}^n x_i!},\n\\]\nand the log-likelihood function is therefore\n\\[\n\\ell(\\lambda)= \\left(\\sum_{i=1}^n x_i\\right)\\log\\lambda - n{\\lambda}- \\sum_{i=1}^n\\log(x_i!)\n\\]\nThe first derivative of $\\ell(\\lambda)$ with respect to $\\lambda$ is\n\\[\n\\ell'(\\lambda) = \\frac{\\sum_{i=1}^n x_i}{\\lambda} - n.\n\\]\nSetting this equal to zero, we obtain \n\\[\n\\lambda = \\frac{1}{n}\\sum_{i=1}^n x_i.\n\\]\nThe second derivative is\n\\[\n\\ell''(\\lambda) = \\frac{-\\sum_{i=1}^n x_i}{\\lambda ^{2}} < 0 \\text{\\quad for all $\\lambda > 0$.}\n\\]\nHence the turning point is a maximum, so the MLE is $\\hat{\\lambda}_{\\text{\\scriptsize{MLE}}} = \\bar{X}$.\n\\end{answer}\n\n\\question % mle for binomial\nLet $X$ be a single observation from the $\\text{Binomial}(n,\\theta)$ distribution, where $n$ is known but $\\theta$ is unknown. Find the MLE of $\\theta$. \n\n\\begin{answer}\nThe likelihood function for the observation $X=k$ is \n\\[\nL(\\theta) = L(\\theta; k) = \\binom{n}{\\theta} \\theta^{k}(1 - \\theta)^{n-k}\n\\]\nand the log-likelihood is\n\\[\n\\ell(\\theta) = \\log \\binom{n}{k} + k\\log \\theta + (n - k)\\log(1 - \\theta).\n\\]\nTaking the derivative of $\\ell(\\theta)$ with respect to the $\\theta$,\n\\[\n\\ell'(\\theta) = \\frac{k}{\\theta} -\\frac{(n-k)}{(1-\\theta)} \n\\]\nSetting this to zero,\n\\[\n\\frac{k(1-\\theta)-(n-k)\\theta}{\\theta(1-\\theta)} = 0 \\quad\\Rightarrow\\quad \\theta=\\frac{k}{n}.\n\\]\nThe second derivative of $\\ell(\\theta)$ is \n\\[\n\\ell''(\\theta) =  \\frac{-k}{\\theta^{2}} - \\frac{(n-k)}{(1-\\theta)^{2}}.\n\\]\nBecause $k\\leq n$, this is always negative, so the turning point is a maximum. Hence the MLE of $\\theta$ is \n\\[\n\\hat{\\theta}(X) = \\frac{X}{n},\n\\]\nwhich is the observed proportion of successes.\n\\end{answer}\n\n\\question % mle for geometric\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Geometric}(\\theta)$ distribution. Find the MLE of $\\theta$. \n\\begin{answer}\nLet $X\\sim\\text{Geometric}(\\theta)$ distribution. The PMF of $X$ is\n\\[\nf(x;\\theta) = \\theta(1-\\theta)^{x-1}\\quad x = 1,2,\\ldots \\text{\\quad (and zero otherwise).}\n\\]\nLet $(x_1,x_2,\\ldots,x_n)$ be a realisation of the sample. The likelihood function is\n\\[\nL(\\theta) = L(\\theta;x_1,\\ldots,x_n) \n\t= \\prod_{i=1}^n f(x_i;\\theta)\n\t= \\prod_{i=1}^n \\theta(1-\\theta)^{x_i-1}\n\t= \\theta^n(1-\\theta)^{\\sum_{i=1}^{n}(k_i-1)}.\n\\]\nThe log-likelihood function is\n\\[\n\\ell(\\theta) = n\\log\\theta +  \\log(1-\\theta)\\sum_{i=1}^{n}(k_i-1).\n\\]\nThe first derivative of $\\ell(\\theta)$ is\n\\[\n\\ell'(\\theta) = \\frac{n}{\\theta} - \\frac{\\sum_{i=1}^{n}(k_i-1)}{1-\\theta}.\n\\]\nSetting this equal to zero, we obtain\n\\[\n\\theta = \\left(\\frac{1}{n}\\sum_{i=1}^n k_i\\right)^{-1}.\n\\]\nHence the maximum likelihood estimator of $\\theta$ is $\\bar{X}^{-1}$. This makes sense: the longer we wait until the first success, the lower our estimate of the probability of success.\n\\end{answer}\n\n\\question % ordinary-least-squares method\n\\textbf{Simple Linear Model}. Let $X$ and $Y$ be two random variables, and consider the simple linear model:\n\\[\nY = \\alpha + \\beta X + \\epsilon \\quad\\text{where}\\quad \\epsilon\\sim N(0,\\sigma^2)\n\\]\nwhere $\\alpha$, $\\beta$ and $\\sigma^2>0$ are unknown parameters and the \\emph{error variable} $\\epsilon$ is independent of $X$. Let $(X_1,Y_1),(X_2,Y_2),\\ldots,(X_n,Y_n)$ be a random sample of observations from the joint distribution of $X$ and $Y$.\n\\begin{parts}\n\\part\nShow that the maximum likelihood estimators of $\\alpha$ and $\\beta$ are \n\\[\n\\hat{\\alpha} = \\bar{Y}-\\hat{\\beta}\\bar{X}\n\\quad\\text{and}\\quad\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2}\n\\]\nrespectively.\n\\begin{answer}\nIf we observe $X=x$ we have that $Y\\sim N(\\alpha+\\beta x, \\sigma^2)$, so\n\\[\nf(y;\\alpha,\\beta) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{y-(\\alpha+\\beta x)}{\\sigma}\\right)^2\\right]\n\\]\nIn particular,\n\\[\n\\expe(Y|X=x) = \\alpha + \\beta x \\quad\\text{and}\\quad \\var(Y|X=x) = \\sigma^2.\n\\]\nLet $\\{(x_1,y_1),(x_2,y_2),\\ldots,(x_n,y_n)\\}$ be a realisation of the sample. The likelihood function and log-likelihood functions are \n\\begin{align*}\nL(\\alpha,\\beta,\\sigma^2)\n\t& = \\left(\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\right)^n \\exp\\left[-\\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2\\right].\n\\ell(\\alpha,\\beta,\\sigma^2) \\\\\n\t& = - \\frac{n}{2}\\log(2\\pi\\sigma^2) - \\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\end{align*}\nThe MLE estimates of $\\alpha$ and $\\beta$ are obtained by the \\emph{method of least squares}, which is to minimise the sum of squared errors\n\\[\nS(\\alpha,\\beta) = \\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2\n\\]\n% partial derivatives\nThe partial derivatives of $S(\\alpha,\\beta)$ with respect to $\\alpha$ and $\\beta$ are\n\\begin{align*}\n\\frac{\\partial S}{\\partial\\alpha} \n\t& = 2\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big] (-1) \\\\\n\\frac{\\partial S}{\\partial\\beta} \n\t& = 2\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big] (-x_i) \\\\\n\\end{align*}\nTo find the MLEs of $\\alpha$ and $\\beta$, we set the partial derivatives to equal zero.\n% alpha\n\\begin{align*}\n\\frac{\\partial H}{\\partial\\alpha} = 0\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n y_i- n\\alpha -\\beta\\sum_{i=1}^n x_i = 0 \\\\\n\t& \\ \\Rightarrow\\  n\\alpha  = \\sum_{i=1}^n y_i- \\beta\\sum_{i=1}^n x_i \\\\\n\t& \\ \\Rightarrow\\  \\alpha = \\bar{y}-\\beta\\bar{x}.\n\\end{align*}\n% beta\n\\begin{align*}\n\\frac{\\partial H}{\\partial\\beta} =0\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n x_i y_i - \\alpha\\sum_{i=1}^n x_i -\\beta\\sum_{i=1}^n x_i^2 = 0 \\\\\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n x_i y_i - (\\bar{y}-\\beta\\bar{x})\\sum_{i=1}^n x_i -\\beta\\sum_{i=1}^n x_i^2 = 0 \\\\\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n x_i(y_i-\\bar{y}) - \\beta\\sum_{i=1}^n x_i(x_i-\\bar{x}) = 0 \\\\\n\t& \\ \\Rightarrow\\  \\sum_{i=1}^n (x_i-\\bar{x})(y_i-\\bar{y}) - \\beta\\sum_{i=1}^n (x_i-\\bar{x})^2 = 0 \\\\\n\t& \\ \\Rightarrow\\  \\beta = \\frac{\\sum_{i=1}^n (x_i-\\bar{x})(y_i-\\bar{y})}{\\sum_{i=1}^n (x_i-\\bar{x})^2}\n\\end{align*}\nThe maximum-likelihood estimators of $\\alpha$ and $\\beta$ are therefore\n\\[\n\\hat{\\alpha} = \\bar{Y}-\\hat{\\beta}\\bar{X}\n\\text{\\quad and\\quad}\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2}.\n\\]\n\\end{answer}\n\n\\part % mle for residual variance\nShow that the MLE of the error variance $\\sigma^2$ is \n\\[\n\\hat{\\sigma}^2 = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \n\\text{\\quad where\\quad} \n\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} X_i).\n\\]\n\\begin{answer}\nRecall the log-likelihood function:\n\\[\n\\ell(\\alpha,\\beta,\\sigma^2)\n\t= \\frac{n}{2}\\log(2\\pi\\sigma^2) + \\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\nThe first partial derivative of $\\ell(\\alpha,\\beta,\\sigma^2)$ with respect to $\\sigma^2$ is\n\\[\n\\frac{\\partial\\ell}{\\partial(\\sigma^2)} \n\t= \\frac{n}{2\\sigma^2} - \\frac{1}{2(\\sigma^2)^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\nSetting this equal to zero,\n\\[\n\\sigma^2 = \\frac{1}{n}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n\\]\nSubstituting our MLEs for $\\alpha$ and $\\beta$ we obtain the MLE\n\\[\n\\hat{\\sigma^2} = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \\text{\\quad where\\quad} \\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i)\n\\]\nas required.\n\\end{answer}\n\\end{parts}\n\n\\end{questions}\n\\end{exercise}\n", "meta": {"hexsha": "8de0fc316ce395542543d6aaa695c75a70c891b2", "size": 15634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/08B_maximum_likelihood_estimators.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/08B_maximum_likelihood_estimators.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/08B_maximum_likelihood_estimators.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": 41.4694960212, "max_line_length": 364, "alphanum_fraction": 0.6407189459, "num_tokens": 5955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6810720710319691}}
{"text": "\\lab{Applications}{Web Page Experiments}{Web Page Experiments}\n\\objective{This lab applies multi-armed bandit problems to web page experiments.}\n\n\\section*{Web Page Experiments}\nOne application of the multi-armed bandit problem is in web page design.  \nBandit problems provide a way to compare the success of different variations of a web page.\nSuppose a business wants to test new versions of a web page.  \nThe goal of the page might be to get the user to click a certain link, make a purchase, etc.  \nWhen the user does this, we call it a conversion.  The proportion of web page visits \nthat results in a conversion is called the conversion rate, or CvR.  \nThe website designer wants to determine which variation of the web page has the best CvR.\n\nWe can model this situation as a bandit problem by considering each page as a different arm. \nEach page has some unknown probability (the CvR) that a user will perform the desired action.\nThe company then wants to experiment with giving different users different versions of \nthe page in order to determine which variation is most successful.\n\nThis method is the same that is used by Google Analytics.  Take a moment to skim their description located here:\n\\url{http://analytics.blogspot.com/2013/01/multi-armed-bandit-experiments.html}.\n\nIn this lab we will apply the Thompson Sampling method from the previous lab (the same method used by Google)\nto solve this problem.  We will simulate the results and attempt to replicate Google's results found at the website above.\n\n\\section*{The Experiment}\nHere we describe how we will design our web page experiment using bandits and how we will simulate it. \nWe will have some number of variations of a web page, $n$.  Each day, the web-page will receive 100 visitors\n(for the purposes of our simulation).  Twice each day, at the beginning and after 50 visits, \nwe will compute the number of each variation to deliver to the next 50 visitors using the weights \nmethod described in the previous lab (you should have written a function that does this in Problem 4 \nof the previous algorithms lab).\n\n\\begin{problem}\nWrite a function that simulates the experiment for one day.  \nThe function should accept a vector of length $n$ of the true probabilities (CvR) \nfor different web page variations.  It should also accept the state of the variations \nat the beginning of the day; this is an $n \\times 2$ array with the number of previous \nsuccesses plus one in the first column and the number of previous failures plus one in \nthe second column (so if it is the first day the state for any arm would be $(1,1)$ \ncorresponding to a $Beta(1,1)$ distribution).\n\nThe function could be outlined like this: first compute how many times each variation \nshould be used in the next 50 visits.  When determining the weights you will need to use \nthe \\li{sim_data} function.  Use 100 as the number of draws here and throughout this lab. \nThen ``visit'' each page the number of times given by the weights.  \nWhether each visit results in a conversion (1) or not (0) can be randomly determined using the following function:\n\\begin{lstlisting}\nimport scipy as sp\ndef pull(p):\n    return sp.random.binomial(1,p,size = None).\n\\end{lstlisting}\nThis will return a random one or zero based on the probability input \\li{p}.\n\nAfter the first 50 visits, update the state of each arm.  \nThen recompute the weights and do the same for the next 50 visits, resulting in 100 visits total.\n\nThis function should return the resulting states and their corresponding weights.\n\\end{problem}\n\nIn this manner we will continue from day to day, always updating the state of each arm \n(the beta distribution for the CvR of each arm).  We will have three criteria to determine when to stop the experiment.  \nThe first, is that the experiment must run at least two weeks to make sure the \nresults are not overly influenced by a small number of random draws.\n\nThe second stopping criteria is that there be a $95\\%$ probability that one of the variations is the best variation.\nThis is the same as saying that, of the weights for each variation, the largest is greater than $.95$.\n\nIt may seem that these two criteria should be enough; however, in some cases, the \nexperiment could last a very long time using just these criteria.  \nFor example, consider the case that two of the web page variations have nearly the same CvR. \nIn this case it will be very difficult to determine which is best.  \nIt will also not be very important since the results are so similar.  \nThus we will use a measure that we will call the potential value remaining \nin the experiment as the third criteria.  The value remaining is computed by \nsimulating many draws for each arm.  Using this data, the potential value remaining \nfor arm $i$ is obtained by computing the following for each simulated data point:\n\\begin{equation}\\label{valrem}\n\\frac{\\theta_{max} - \\theta^*}{\\theta^*}\n\\end{equation}\nwhere $\\theta_{max}$ is the largest value for the random draw and $\\theta^*$ is the \nvalue of the arm that is currently believed to be the best \n(the arm with the highest weighting, or probability of being optimal).  \nThe result is some distribution of numbers between $0$ and $1$ that we can think \nof as the distribution of value remaining.  For example, if $50\\%$ of the numbers are 0, \nthen about $50\\%$ of the time the arm that is currently believed optimal will perform the best.  \nThe potential value remaining is the $95$th percentile of this distribution.  \nIf the potential value remaining were $.2$, we could interpret it as meaning \nthat there is about a $5\\%$ chance that another arm beats the current best arm by $.2$ or more.\nWe stop the experiment if this value is less than $1\\%$ of the current best arm's CvR.\nThis way we stop the experiment if there seems to be little chance of improvement over \nthe current best arm, regardless of whether we've met the $95\\%$ tolerance for the weights.\n\nThe value remaining can be computed using the following code:\n\\begin{lstlisting}\nimport scipy as sp\ndef val_remaining(data,prob):\n    champ_ind = sp.argmax(prob)\n    thetaM = sp.amax(data,1)\n    valrem = (thetaM - data[:,champ_ind])/data[:,champ_ind]\n    pvr = sp.stats.mstats.mquantiles(valrem,.95)\n    return valrem,pvr\n\\end{lstlisting}\nwhere data is simulated using the \\li{sim_data} function from the previous algorithms lab, \nand prob is a vector containing the probabilities that each arm is optimal\n(also computed using a function from the previous lab).\n\n\\begin{problem}\nWrite a function that simulates the problem described above, using the stopping criteria described above.\nThe function should accept a vector of the true probabilities of the arms.  \nIt should use the function from the previous problem to simulate each day and \ncontinue until the stopping criteria are met.\n\nThe function should return the state of each arm (i.e. an $n$ by $2$ matrix with the \nsuccesses and failures of each arm), a matrix that contains the weights assigned to \neach arm each day, the index of the winning variation, and the number of days it took to converge.\n\nYour code should have a while loop that checks for the stopping criteria after each day.  \nIt might look something like this:\n\\begin{lstlisting}\nwhile ((delta < p_tol) and (champ_cvr/100. < v_quant)) or days < 14:\n\\end{lstlisting}\nwhere \\li{delta} is the largest weight for the current day, meaning if there were two arms and you determined the weights to be .9 and .1, then delta would be .9.  We stop when the largest weight is greater than .95, so \\li{p_tol} is .95.  The variables \\li{champ_cvr} and \\li{v_quant} describe the stop mechanism that accounts for the potential value remaining.  First, \\li{champ_cvr} is the conversion rate of the current best arm over the course of the experiment.  So if it has been used 100 times with 4 successes, then \\li{champ_cvr} would be .04.  The variable \\li{v_quant} is the potential value remaining, i.e. the $95$th percentile of the value remaining distribution described above.  The variable \\li{pvr} can be computed using the \\li{val_remaining} function given above.\nThe \\li{days} variable simply keeps track of how many days the experiment has been running.\n\\end{problem}\n\nNow let's see how our bandit performs with specific examples.\n\n\\begin{problem}\nSuppose a web page has two variations and the true CvR of the original is \n$.04$ and the true CvR of the new variation is $.05$. \nCreate a plot similar to \\ref{fig:weights1} that shows how the weights \nassigned to the pages changes from day to day until the optimal page is chosen and the experiment stops.\n\nNext run the same simulation 200 times and keep track of how many days \nthe experiment took in each case.  Create a histogram that shows the \nnumber of days it takes to complete the experiment.  \nThe following code will create such a histogram:\n\\begin{lstlisting}\nimport scipy as sp\nfrom matplotlib import pyplot as plt\nhist, bins = sp.histogram(dayvec, bins = 12)\nwidth = (bins[1]-bins[0])\ncenter = (bins[:-1]+bins[1:]) / 2\nplt.bar(center, hist, align = 'center', width = width, color = 'g')\nplt.show()\n\\end{lstlisting}\nwhere \\li{dayvec} is a vector containing the number of days each simulation took to complete. \nAlso track which arm is determined to be optimal in each simulation.  \nWhat percent of the time did the bandit find the optimal arm?\n\nCreate the same two types of plots, this time with six variations having \nweights $.04,.02,.03,.035,.045,.05$.  This time only run the simulation 100 times.  \nWhat percent of the time did the bandit find the optimal arm in this case?\n\\end{problem}\n\n\\begin{figure}[h]\n\\centering\n\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{weights1.pdf}\n\\caption{Optimal arm probabilities in the two arm case}\n\\label{fig:weights1}\n\\end{subfigure}\n\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{weights2.pdf}\n\\caption{Optimal arm probabilities in the six arm case}\n\\label{fig:weights2}\n\\end{subfigure}\n\\end{figure}\n\n% \\begin{figure}[h]\n% \\centering\n% \\includegraphics[width=\\textwidth]{weights2.pdf}\n% \\caption{Optimal arm probabilities in the six arm case}\n% \\label{fig:weights2}\n% \\end{figure}\n\n\n\\section*{Comparison with Classical Tests}\nA more classical approach to this problem would be to split traffic between each \nvariation for a predetermined amount of time, which should give enough data to \ndetermine the best arm with some level of confidence.  \nUsing the bandit approach described here has significant advantages over a classical test.  \nThere are two main reasons why the bandit approach is more efficient.\n\nThe first reason is that the bandit method generally converges more quickly.  \nA standard test would require splitting the web page views between the different \nvariations over a long period of time.  According to Google's explanation in the \nwebsite mentioned at the beginning of this lab, the two arm case would take 223 days \nand the 6 arm case would take 919 days.  The results from the simulations you performed\nshould show that on average the bandit method finishes much faster.  \nThere are other ways we could choose our stopping criteria that may result in even shorter experiment times.\nIn general, we can always adjust the tolerance of our stopping criteria to shorten experiment time or increase accuracy.\n\nThe second reason the bandit approach is more efficient is that, as we gain more information,\nwe allocate more visits to the variation that we believe has a better CvR.\nIn the classical method we would split the visits evenly until the end of the experiment.\nThis way we gain many more conversions during testing than we would using classical tests.\n", "meta": {"hexsha": "7531c0038cd643ed795128d47c63e23217825d99", "size": 11697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/MarkDecProc/Web_Exper.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/MarkDecProc/Web_Exper.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/MarkDecProc/Web_Exper.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.1940298507, "max_line_length": 784, "alphanum_fraction": 0.7747285629, "num_tokens": 2733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.6810654916746639}}
{"text": "\\section{Transformations and Expectations}\n\n\\subsection{Transformations}\n\nIf $X$ and $Y$ are discrete random variables, with $Y = g(X)$, then\n\\begin{equation}\n    f_Y(y) = \\sum_{\\{x: g(x) = y\\}} f_X(x).\n\\end{equation}\n\nFor the remainder of this section we will take $X$ and $Y$ to be continuous random variables, with $Y = g(X)$. As such, we will define the following sets $\\X{} = \\{x: f_X(x) > 0\\}$ and $\\Y{} = \\{y: y =g(x) \\quad x \\in S \\subseteq \\X{} \\}$.\\\\\n\n\\begin{theorem}\n    Let $X$ have cdf $F_X(s)$, let $Y = g(X)$ and let $\\X{}$ and $\\Y{}$ be defined as above. Then\n    \\begin{enumerate}[a.]\n        \\item If g is increasing on $\\X{}$, then $F_Y(y) = F_X(g^{-1}(y))$ for $y \\in \\Y{}$.\n        \\item If g is decreasing on $\\X{}$, then $F_Y(y) = 1 - F_X(g^{-1}(y))$ for $y \\in \\Y{}$. \n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}\n    Let $X$ have pdf $f_X(x)$ and $Y = g(X)$, where $g$ is monotone. Define $\\X{}$ and $\\Y{}$ as above. Suppose $f_X(x)$ is continuous on $\\X{}$ and $g^{-1}(y)$ has continuous first derivative on $\\Y{}$. Then the pdf of $Y$ is given by:\n    \\begin{equation*}\n        f_Y(y) = \\1{y \\in \\Y{}} f_X(g^{-1}(y)) \\abs{ \\frac{\\d{}}{\\d{}y} g^{-1}(y) }\n    \\end{equation*}\n\\end{theorem}\n\nIf $g$ is not globally monotone, then we just partition $\\X{}$ into subsets on which $g$ is continuous and monotone and sum the results. If such a partition doesn't exist, then we have technical problems.\\\\\n\n\\begin{theorem}[Probability integral transform]\n    Let $X$ have continuous cdf $F_X(x)$ and define the random variable $Y$ by $Y = F_X(X)$. Then $Y$ is uniformly distributed on $(0, 1)$.\n\\end{theorem}\n\nIf $F_X(x) = y$ is constant on some interval then we define the inverse by \n\\[\n    F_X^{-1}(y) = \\inf \\{x: F_X(x) = y\\}.\n\\]\n\n\\subsection{Expectations}\n\n\\begin{definition}[Expected value]\n    The \\emph{expected value} of a random variable $g(X)$, denoted $\\E{}[X]$ is defined by:\n    \\begin{itemize}[-]\n        \\item $\\E{}[X] = \\int_{\\R{}}g(x)f_X(x)\\d{}x$ if $X$ is continuous,\n        \\item $\\E{}[X] = \\sum_{x \\in \\X{}}g(x)\\P{}(X = x)$ if $X$ is discrete.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{theorem}[Properties of expectation]\n    \\begin{enumerate}[a.]\n        \\item Linearity.\n        \\item $g_1(x) \\geq g_2(x) \\,\\, \\forall x \\quad \\implies \\quad \\E{}[g_1(X)] \\geq \\E{}[g_2(X)]$\n        \\item $a \\leq g(x) \\leq b \\,\\, \\forall x \\quad \\implies \\quad a \\leq \\E[g(X)] \\leq b $\n        \\item $\\argmin_{c}\\E{}[(X - c)^2] = \\E{}[X]$\n    \\end{enumerate}\n\\end{theorem}\n\n\\subsection{Moments}\n\n\\begin{definition}[Moment]\n    For integer $n$, the $n^{\\mathrm{th}}$ \\emph{moment} of $X$ is\n    \\[\n        \\mu_n' = \\E{}[X^n].\n    \\]\n    The $n^{\\mathrm{th}}$ \\emph{central moment}, $\\mu_n$ is \n    \\[\n        \\mu_n = \\E[(X - \\mu)^n].\n    \\]\n    Where $\\mu = \\mu_1 = \\E{}[X]$\n\\end{definition}\n\n\\subsubsection{Variance}\n\\begin{definition}[Variance]\n    The \\emph{variance} of a random variable $X$, written $\\Var{}[X]$ is the second central moment of $X$,\n    \\[\n        \\Var{}[X] = \\E{}[(X - \\E{}[X])^2].\n    \\]\n    The \\emph{standard deviation} of $X$, denoted $\\sigma_X$, is given by $\\sigma_X = \\sqrt{\\Var{}[X]}$.\n\\end{definition}\n\n\\begin{theorem}[Properties of variance]\n    If $X$ has finite variance then:\n    \\begin{enumerate}[a.]\n        \\item $\\Var{}[aX + b] = a^2\\Var{}[X]$\n        \\item $\\Var{}[X] = \\E{}[X^2] - \\E{}[X]^2$\n    \\end{enumerate}\n\\end{theorem}\n\n\\subsubsection{Moment Generating Functions}\n\\begin{definition}[Moment generating function]\n    Let $X$ be a random variable with cdf $F_X$. The \\emph{moment generating function (mgf)} of $X$, denoted $M_X(t)$, is given by\n    \\[\n        M_X(t) = \\E{}[e^{tX}]\n    \\]\n    provided that the expectation exists for $t$ in some (open) neighbourhood of 0 (otherwise we say the mgf does not exist).\n\\end{definition}\n\n\\begin{remark}\n    The mgf is the Laplace transform of the pdf.\n\\end{remark}\n\n\\begin{theorem}\n    If $X$ has mgf $M_X(t)$ then\n    \\[\n        \\E{}[X^n] = \\left. \\frac{\\d}{\\d t}M_X(t)\\right|_{t=0}\n    \\]\n\\end{theorem}\n\nThe mgf can be used to calculate moments, but its principal utility is in characterising a distribution. This relationship can run into some technical difficulties. If the mgf exists, it characterises an infinite set of moments. However, it is possible for two distinct random variables to give rise to the same set of moments.\\\\\n    \nThe problem of uniqueness of moments does not occur if the random variables have bounded support (in this case an infinite sequence of moments uniquely determines the distribution). Further, if the mgf exists in a neighbourhood of 0 then it uniquely determines the distribution, no matter the support. Thus, existence of an infinite set of moments is not equivalent to the existence of the mgf. We have the following theorem, describing when the mgf determines the distribution.   \n\n\\begin{theorem}[When mgf determines distribution]\n    Let $F_X(x)$ and $F_Y(y)$ be two cdfs all of whose moments exist.\n    \\begin{enumerate}[a.]\n        \\item If $X$ and $Y$ have bounded support then $F_X(u) = F_Y(u) \\,\\, \\forall u$ if and only if $\\E{}[X^r] = \\E{}[Y^r] \\,\\, \\forall r \\in \\N$. (So the cdfs are equal if and only if all the moments agree.)\n        \\item If the mgfs exist and are identical in some neighbourhood of 0 then the cdfs are equal.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}[Convergence of mgfs near 0 implies convergence of cdfs]\n    Suppose $\\{X_i, i=1, 2, \\dots$\\} is a sequence of random variables, each with mgf $M_{X_i}(t)$. Suppose also that for all $t$ in a neighbourhood of 0\n    \\[\n        lim_{i \\to  \\infty} M_{X_i} = M_X(t) \n    \\]\n    where $M_X(t)$ is an mgf. Then there is a unique cdf $F_X$ whose moments are determined by $M_X(t)$ and, for all $x$ at which $F_X(x)$ is continuous, we have\n    \\[\n        lim_{i\\to\\infty} F_{X_i}(x) = F_X(x).\n    \\]\n\\end{theorem}  \n\n\\begin{remark}\n    The convergence of a sequence of moments is not enough to show the convergence of random variables. We need the moment sequence to be unique too. However, if the mgfs converge in a neighbourhood of 0 as above, then we know that the random variables converge. Convergence of mgfs is therefore a sufficient, but not necessary, condition for convergence of the random variables.\n\\end{remark}\n\n\\begin{theorem}\n    For any constants $a$ and $b$\n    \\[\n        M_{aX + b}(t) = e^{bt}M_X(at)\\\n    \\]\n\\end{theorem}\n\n\\subsection{Other Generating Functions}\n\n\\begin{definition}[Cumulant generating function]\n    The \\emph{cumulant generating function} is $\\log(M_X(t))$. The \\emph{cumulants} of $X$ are defined as the coefficients of the Taylor series of this function.\n\\end{definition}\n\n\\begin{definition}[Factorial moment generating function]\n    The \\emph{factorial moment generating function} is $\\E{}[t^X]$. The name comes from\n    \\[\n        \\left. \\frac{\\d^r}{\\d t^r} \\E{}[t^X] \\right|_{t=1} = \\E{}[X(X-1)\\cdots(X-r+1).\n    \\]\n    For discrete distributions this is the \\emph{probability generating function} and the coefficients of the power series give the probabilities\n    \\[\n        \\left. \\frac{1}{k!} \\frac{\\d^k}{\\d t^k} \\E{}[t^X] \\right|_{t=0}  = \\P{}(X=k).\n    \\]\n\\end{definition}\n\n\\begin{definition}[Characteristic function]\n    The \\emph{characteristic function} of a random variable $X$ is\n    \\[\n        \\phi_X(t) = \\E{}[e^{itX}]\n    \\]\n\\end{definition}\n\n\\begin{remark}\n    The characteristic function is the most useful of the generating functions. Every cdf has a unique characteristic function. When the moments of the cdf exist, the characteristic function can be used to calculate them.\n\\end{remark}\n\n\n    \n\n\n    \n\n    \n\n    \n\n        \n\n\n\n\n    \n\n", "meta": {"hexsha": "4e8233b63797f2ee86f213f6464e9e48e390d2b0", "size": 7643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter2/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/chapter2/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/chapter2/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": 40.871657754, "max_line_length": 481, "alphanum_fraction": 0.6353526102, "num_tokens": 2439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.6810654803232494}}
{"text": "%---------------------------Shear-----------------------------\n\\section{Shear\\label{s:quad-shear}}\n\nThe shear metric\n\\[\nq = \\min \\left\\{ \\frac {\\alpha_0} {\\normvec{L_0} \\normvec{L_3}}, \n                 \\frac {\\alpha_1} {\\normvec{L_1} \\normvec{L_0}},\n                 \\frac {\\alpha_2} {\\normvec{L_2} \\normvec{L_1}},\n                 \\frac {\\alpha_3} {\\normvec{L_3} \\normvec{L_2}} \\right\\}\n\\]\nis the same as the scaled Jacobian, except that it has a truncated range.\n\nNote that if $\\alpha_i < DBL\\_MIN$ or any edge has length $L < DBL\\_MIN$, we set $q = 0$.\n\n\\quadmetrictable{shear}%\n{$1$}%                                      Dimension\n{$[0.3,1]$}%                                Acceptable range\n{$[0,1]$}%                                  Normal range\n{$[0,1]$}%                                  Full range\n{$1$}%                                      Unit square\n{\\cite{knu:03}}%                            Citation\n{v\\_quad\\_shear}%                           Verdict function name\n\n", "meta": {"hexsha": "2b95d46570ff3bc1fe1e7920df21dac2b9d680d0", "size": 986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadShear.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/QuadShear.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/QuadShear.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.0833333333, "max_line_length": 89, "alphanum_fraction": 0.4350912779, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6810502134622058}}
{"text": "%% ps1_q3.tex\n\\section{ Is it an isomorphism? }\n\nYes. Since $g \\circ f : c \\rightarrow c$ and $f \\circ g : d \\rightarrow d$ both must be valid morphisms\nin the category, and the only morphisms $c \\rightarrow c$ and $d \\rightarrow d$ are the identities,\nthen $g \\circ f = id_c$ and $f \\circ g = id_d,$ q.e.d.\n", "meta": {"hexsha": "5da9e9df2c11ded155c0a93271d88bf729756bc6", "size": 308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps1/ps1_q3.tex", "max_stars_repo_name": "alf239/procats", "max_stars_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps1/ps1_q3.tex", "max_issues_repo_name": "alf239/procats", "max_issues_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps1/ps1_q3.tex", "max_forks_repo_name": "alf239/procats", "max_forks_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.0, "max_line_length": 103, "alphanum_fraction": 0.6785714286, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6809724783551844}}
{"text": "\\clearpage\n\\subsection{Expression} % (fold)\n\\label{sub:expression}\n\nSome statements need data, this data can be calculated or provided as a literal value in the code. The term \\textbf{expression} is used in programming to describe the places in a statement where data must be supplied. At run time each expression becomes a value that is used by the statement.\n\n\\begin{figure}[h]\n   \\centering\n   \\includegraphics[width=\\textwidth]{./topics/program-creation/diagrams/Expression} \n   \\caption{An expression provides a \\textbf{value} to be used in a Statement.}\n   \\label{fig:program-creation-expression}\n\\end{figure}\n\n\n\\mynote{\n\\begin{itemize}\n  \\item An expression is a \\textbf{term} given to code that calculates a value.\n  \\item The concepts related to expressions are shown in Figure \\ref{fig:program-creation-expression}.\n  \\item An expression provides a \\textbf{value} that is used in a Statement.\n  \\item The expression's value may be calculated or entered directly into the code.\n  \\item Calculations can use mathematical operators: + for addition, - for subtraction, * for multiplication, $/$ for division, and parenthesis ( ) for grouping.\n  \\item Expressions are evaluated using the BODMAS\\footnote{BODMAS indicates that expressions are evaluated \\textbf{B} brackets first, \\textbf{O} orders (which includes powers and square roots), \\textbf{DM} for division and multiplication (which are of equal precedence, and are evaluated left-to-right), then \\textbf{AS} addition and subtraction (of equal precedence, evaluated left-to-right).} order of operations.\n  \\item Values entered directly within an expression are \\textbf{Literal} values.\n\\end{itemize}\n}\n\n% section program (end)", "meta": {"hexsha": "09f46f50aebc3417b22cfa66e557cf3d235c840a", "size": 1688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/program-creation/concepts/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/concepts/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/concepts/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": 62.5185185185, "max_line_length": 416, "alphanum_fraction": 0.7731042654, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.6809649102149147}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{(-1)^n}{n+1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Important Remark}\r\n\r\n{\\color{red}If we were to use the Ratio Test, on this series, we would consider the limit\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| \\frac{(-1)^{n+1}}{n+2} \\cdot \\frac{n+1}{(-1)^n}\\right|\r\n= \\lim_{n \\to \\infty} \\left| \\frac{(-1)(n+1)}{n+2}\\right|\r\n= \\lim_{n \\to \\infty} \\frac{n+1}{n+2}\r\n= \\lim_{n \\to \\infty} \\frac{1}{1} \r\n= 1\r\n\\end{align*}\r\nwith one use of L'Hopital's above. Since $L=1$, we get NO INFORMATION from the Ratio Test. (Note that later in the solution, we well get a limit of $1$, but since we're using the Limit Comparison Test, which has different requirements, we WILL get information.)}\r\n\r\n\\subsection*{Solution}\r\n\r\nThe series $\\displaystyle \\sum_{n=1}^\\infty \\frac{(-1)^n}{n+1}$ is alternating, and $b_n = |a_n| = \\frac1{n+1}$. The sequence $b_n$ is decreasing and has limit $0$. So by the Alternating Series Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{(-1)^n}{n+1}$ converges.\r\n\r\nTo determine if $\\displaystyle \\sum_{n=1}^\\infty \\frac{(-1)^n}{n+1}$ converges absolutely or conditionally, we consider the series $\\sum |a_n|$, which in this case is\r\n\\[\\sum_{n=1}^\\infty \\frac{1}{n+1}.\\]\r\nThis series can be shown to diverge using the Integral Test (with a substitution of $u=x+1$) or using the Direct Comparison Test, or using the Limit Comparison Test. We'll use the Limit Comparison Test here. Note that the series $\\sum \\frac1n$ diverges by the $p$-test. Let $a_n = \\frac1{n+1}$ and let $b_n = \\frac1n$.\r\n\\[ \\lim_{n \\to \\infty} \\frac{a_n}{b_n} = \\lim_{n \\to \\infty} \\frac{n}{n+1} = \\lim_{n \\to \\infty} \\frac11 = 1.\\]\r\nTherefore, the Limit Comparison Test applies and the series $\\sum_{n=1}^\\infty \\frac{1}{n+1}$ diverges. Thus, the series  $\\displaystyle \\sum_{n=1}^\\infty \\frac{(-1)^n}{n+1}$  converges conditionally.\r\n\r\n\\subsection*{Epiloque}\r\n\r\n{\\color{blue} When using the Ratio Test, we got \\[\\displaystyle \\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|=1\\] while with the Limit Comparison Test, we got \\[\\lim_{n \\to \\infty} \\frac{a_n}{b_n} = 1.\\]\r\nWhen the limit of the sequence $\\left|\\frac{a_{n+1}}{a_n}\\right|$ is $1$ in the Ratio Test, we get NO information. However, as long as the limit of the sequence $\\frac{a_n}{b_n}$ is a finite positive number (including $1$) we DO get to conclude something in the Limit Comparison Test, simply because the requirements of the two tests are different. Don't let this freak you out too much: in any case, the two tests made you study DIFFERENT sequences anyway!\r\n}\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "9337b6d965b937b9737e4d25e4a15fc1b13ae46b", "size": 3355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/l1.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/l1.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/l1.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": 56.8644067797, "max_line_length": 458, "alphanum_fraction": 0.6718330849, "num_tokens": 1123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.6809649004582461}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section*{Fri Nov 29 2019}\n\nThe Plummer sphere is defined by \n%\n\\begin{subequations}\n\\begin{align}\n  \\rho (r) \\dd[3]{r} &= \\frac{3M}{4 \\pi a^3} \\qty(1 + \\frac{r^2}{a^2})^{-5/2} \\dd[3]{r}  \\\\\n  &= \\frac{3M}{4 \\pi a^3} \\qty(1 + \\frac{r^2}{a^2})^{-5/2} r^2 \\dd{r} \\dd{\\Omega }\n\\,,\n\\end{align}\n\\end{subequations}\n%\nand it models the mass density in a star cluster.\nWe can marginalize over the angles to find the pdf of the radius alone: this just amounts to multiplying by \\(4 \\pi \\) by isotropy,\n%\n\\begin{align}\n  \\rho (r) \\dd{r} = \\frac{3M}{a^3} \\qty(1 + \\frac{r^2}{a^2})^{-5/2} r^2 \\dd{r}\n\\,,\n\\end{align}\n%\nand if we rescale the radius as \\(R = r/a\\) we find the PDF \n%\n\\begin{align}\n  \\rho (R) \\dd{R} = 3M \\qty(1 + R^2)^{-5/2} R^2 \\dd{R}\n\\,,\n\\end{align}\n%\nwhich can be integrated analytically: we get \n%\n\\begin{align}\n  \\int_{0}^{R_{\\text{max}}} \\rho(R) \\dd{R} = \\frac{ M R^3 _{\\text{max}}}{\\qty(R^2 _{\\text{max}} + 1)^{3/2}}\n\\,.\n\\end{align}\n%\n\nThe velocities are isotropically distributed, with the probability of their moduli being described by a Maxwellian density: \n%\n\\begin{align}\n  p(v) \\dd{v} = \\sqrt{\\frac{2}{\\pi }} \\frac{v^2}{\\sigma^3}\n  \\exp( -\\frac{v^2}{2 \\sigma^2}) \\dd{v}\n\\,.\n\\end{align}\n\nDo note that this is \\emph{not} normalized on \\(\\mathbb{R}\\) as given: its integral is \\(2\\), it is normalized on \\(\\mathbb{R}^{+}\\).\n\nThe parameters are given by: \\(M = \\num{e4} M_{\\odot}\\), \\(a = \\SI{5}{\\parsec}\\), \\(\\sigma = \\SI{5}{km/s}\\).\n\nHere is my approach to the problem without reading the suggestions, it might not be the most efficient way to do it. \n\nWe need to be able to draw samples from three distributions: the Plummer sphere, the Maxwell distribution and the angular distribution; since both the star's positions and their velocities are isotropically distributed on the 2-sphere. \nThe volume element on the sphere \\(S^{2}\\) is given by \\(\\dd{A} = \\sin \\theta \\dd{\\theta } \\dd{\\varphi }\\); so we can draw our \\(\\varphi \\) from a uniform distribution on \\([0, 2 \\pi ]\\), while our \\(\\theta \\) will need to be distributed according to \\(p(\\theta ) \\dd{\\theta }= \\sin \\theta \\dd{\\theta }  \\). \n\nSince we are computing angles spanning the whole \\(2\\)-sphere, for both the radius \\(r\\) and the velocity \\(v\\) we do not need to simulate negative values.\n\nThis was my first approach, but then I noticed that it is really hard to sample from a distribution \\(f(x) \\sim x^2 \\exp(-x^2)\\). \n\nFor the Plummer distribution it makes sense to sample from the radial and angular distribution separately, while for the Maxwell distribution it is much easier to sample the three components of the velocity vector in cartesian coordinates. Let us see this: first, we rescale \\(V = v/\\sigma \\). We get: \n%\n\\begin{align}\n  p(V) \\dd{V} = \\sqrt{\\frac{2}{\\pi }} \\exp(- V^2/2)V^2 \\dd{V}\n\\,,\n\\end{align}\n%\nand we can add in the uniform distribution \\(1/ 4\\pi \\) of the angular part: we find \n%\n\\begin{subequations}\n\\begin{align}\np(V) \\dd{V} \\dd{\\Omega } &= \\frac{1}{4 \\pi } \\sqrt{\\frac{2}{\\pi }} \\exp(-V^2/2) V^2 \\dd{V} \\dd{\\Omega }  \\\\\n&= \\frac{1}{(2 \\pi )^{3/2}} \\exp(-V^2/2) \\dd[3]{V}  \\\\\n&= \\prod_{i=1}^{3} \\qty(\\frac{1}{\\sqrt{2 \\pi }} \\exp(-V_i^2/2) \\dd{V_i})\n\\,,\n\\end{align}\n\\end{subequations}\n%\nso we can see that in cartesian coordinates each component is just distributed according to a Gaussian. \n\n\\end{document}", "meta": {"hexsha": "a3e4f4af05d05d0f263f89b7ad8408c31d92ff08", "size": 3370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/numerical_methods/29nov.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/29nov.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/29nov.tex", "max_forks_repo_name": "jacopok/notes", "max_forks_repo_head_hexsha": "805ebe1be49bbd14c6b46b24055f9fc7d1cd2586", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-03T16:20:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-06T16:11:07.000Z", "avg_line_length": 42.125, "max_line_length": 308, "alphanum_fraction": 0.6474777448, "num_tokens": 1195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631541, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.6809648946074357}}
{"text": "\\section{Connectedness}\r\nAn interval $I$ in $\\mathbb R$ has the defining property that $\\forall x,y,z,x<y<z$, then $x,z\\in I\\implies y\\in I$.\r\nWe know that a real continuous function maps intervals to intervals due to the intermediate value theorem.\r\nBut it may not work if the (restricted) domain is not an interval.\r\n\\begin{definition}\r\n    A topological space $X$ is disconnected if there are open $U,V\\subset X$ such that $U\\neq\\varnothing$ and $V\\neq\\varnothing$ partitions $X$, that is $U\\cap V=\\varnothing$ and $U\\cup V=X$.\r\n    In this case, we say $U,V$ disconnect $x$.\\\\\r\n    A topological space $X$ is connected if it is not disconnected.\r\n\\end{definition}\r\n\\begin{lemma}\\label{image_connected}\r\n    The image of continuous function on connected space is connected.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $f:X\\to Y$ is continuous.\r\n    Note that if we consider $f$ as $f:X\\to\\operatorname{Im}f$ then it is still continuous.\r\n    Then if $U,V$ disconnect $\\operatorname{Im}f$, then $f^{-1}(U),f^{-1}(V)$ disconnect $X$.\r\n\\end{proof}\r\n\\begin{theorem}\\label{connected_eqv}\r\n    For a topological space $X$, the followings are equivalent:\\\\\r\n    1. $X$ is connected.\\\\\r\n    2. If $f:X\\to\\mathbb R$ is continuous, then $f(X)$ is an interval.\\\\\r\n    3. Every continous function $f:X\\to D$, where $D$ is discrete and $|D|\\ge 2$, is constant.\r\n    \\footnote{Most of the time we take $D=\\mathbb Z$}\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $1\\implies 2$: Obvious due to the preceding lemma and the trivial fact that an open set in $\\mathbb R$ is connected if and only if it is an interval.\\\\\r\n    $2\\implies 3$: Immediate, also from the preceding lemma.\\\\\r\n    $3\\implies 1$: We shall prove the contrapositive.\r\n    Suppose that $U,V$ disconnects $X$, then choose $d,e\\in D$ with $d\\neq e$, then the function $f$ defined by\r\n    $$f(x)=\r\n    \\begin{cases}\r\n        d\\text{, if $x\\in U$}\\\\\r\n        e\\text{, otherwise, that is if $x\\in V$}\r\n    \\end{cases}$$\r\n    is continuous but is not constant, contradiction.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. $\\varnothing$ and singletons are connected.\\\\\r\n    2. Any indiscrete topological space is connected.\\\\\r\n    3. The cofinite topology on an infinite set is connected.\\\\\r\n    4. The discrete topology is disconnected if it is not a singleton.\r\n\\end{example}\r\n\\begin{lemma}\r\n    A subspace $Y\\subset X$ is disconnected if and only if there are open sets $U,V\\in X$ such that $U\\cap Y\\neq\\varnothing, V\\cap Y\\neq\\varnothing, U\\cap V\\cap Y=\\varnothing, Y\\subset U\\cup V$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{proposition}\\label{closure_connected}\r\n    Let $Y$ be a connected subspace of $X$, then $\\bar Y$ is connected.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Assume not, then by the preceding lemma, there exists open sets $U,V$ in $X$ such that $U\\cap\\bar Y\\neq\\varnothing, V\\cap\\bar Y\\neq\\varnothing, U\\cap V\\cap\\bar Y=\\varnothing, \\bar Y\\subset U\\cup V$.\r\n    It follows that $U\\cap V\\cap Y=\\varnothing, Y\\subset U\\cup V$, so we must have, WLOG, $U\\cap Y=\\varnothing$, then $Y\\subset X\\setminus U\\implies\\bar Y\\subset X\\setminus U\\implies \\bar Y\\cap U=\\varnothing$, contradiction.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. Alternatively, we can use the third part of Theorem \\ref{connected_eqv}.\r\n    2. In fact, for any $Z$ with $Y\\subset Z\\subset\\bar Y$ is connected since the closure of $Z$ is $\\bar Y$.\r\n\\end{remark}\r\n\\begin{proof}[Alternative proof of Lemma \\ref{image_connected}]\r\n    Let $f:X\\to Y$ be continuous, for convenience we can just assume $f$ is surjective using the same argument as the original proof, then consider any continuous $g:Y\\to\\mathbb Z$, then $g\\circ f$ is continuous hence constant since $f$ is connected, but $f$ is surjective, so $g$ is constant, then it is done by Theorem \\ref{connected_eqv}.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. Connectedness is a topological property.\\\\\r\n    2. If $f:X\\to Y$ is continuous and $A\\subset X$ and $A$ is connected, then $f(A)$ is connected.\r\n\\end{remark}\r\n\\begin{corollary}\r\n    If $X$ is connected and $R$ an equivalence relation on $X$, then $X/R$ is connected.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    The quotient map is continuous and surjective.\r\n\\end{proof}\r\n\\begin{example}\r\n    let $Y=\\{(x,\\sin(1/x)):x>0\\}\\subset\\mathbb R^2$ is connected since it is the image of $f(x)=(x,\\sin(1/x))$, which is continuous since its components are connected, over $\\mathbb R_{>0}$.\\\\\r\n    By Proposition \\ref{closure_connected}, $\\bar Y=Y\\cup(\\{0\\}\\times [-1,1])$ is also connected.\r\n    This is called the Topologist's Sine Wave.\r\n\\end{example}\r\n\\begin{lemma}\\label{union_connected}\r\n    Let $\\mathscr A$ be a family of connected subset of a topological space $X$ such that $\\forall A,B\\in\\mathscr A,A\\cap B=\\varnothing$, then $\\bigcup_{A\\in\\mathscr A}A$ is connected.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $f:\\bigcup_{A\\in\\mathscr A}A\\to\\mathbb Z$ is connected, then $f|_A$ is continuous for any $A\\in\\mathscr A$, thus it is constant, say it is $n_A$, then $\\forall A,B\\in\\mathscr A$, then $n_A=n_B$ since $A\\cap B\\neq\\varnothing$.\r\n    Thus $f$ is constant, hence $\\bigcup_{A\\in\\mathscr A}A$ is connected.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    If $X,Y$ are connected, so is $X\\times Y$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Observe that $\\forall x\\in X,\\{x\\}\\times Y\\cong Y$ is connected and $\\forall y\\in Y, X\\times \\{y\\}\\cong X$ is connected as well, so since $(x,y)\\in (\\{x\\}\\times Y)\\cap(X\\times \\{y\\})\\neq\\varnothing$, by the preceding lemma $A_{x,y}=(\\{x\\}\\times Y)\\cup(X\\times \\{y\\})$ is connected.\r\n    Now obviously $(x,y')\\in A_{x,y}\\cap A_{x',y'}\\neq\\varnothing$, so $X\\times Y=\\bigcup_{x\\in X,y\\in Y}A_{x,y}$ is connected by the preceding lemma.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $X$ be a topological space, we define an equivalence relation $R$ by $xRy$ if and only if there is a connected $U\\subset X$ such that $x,y\\in U$.\r\n    One can check that this is an equivalence relation by Lemma \\ref{union_connected}, and the partition of $X$ by $R$ is called the connected components of $X$.\r\n\\end{definition}\r\nLet $C_x$ be the equivalence class containing $x$.\r\n\\begin{proposition}\r\n    Connected components are nonempty and are maximal (wrt inclusion) connected subset of $X$, also they are closed.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $C$ be a connected component, so it is the equivalence class of some $x$, so $C=C_x$, so $C$ is nonempty since it contains $X$.\r\n    So given $y\\in C$, $\\exists A_y\\ni x,y$ such that $U$ is connected.\r\n    $A_y\\in C$ by definition of the relation.\r\n    Now $\\forall y,z\\in C, x\\in A_y\\cap A_z\\neq\\varnothing$, therefore by Lemma\\ref{union_connected}, hence $C=\\bigcup_{y\\in C}A_y$ is connected.\\\\\r\n    If $C\\subset D$ and $D$ is connected, then $\\forall y\\in D$, $x,y\\in D$, thus since $D$ is connected $y\\in C$, so $D\\subset C\\implies C=D$.\\\\\r\n    Hence since $\\bar C$ is connected and contains $C$, by maximality $C=\\bar C$, therefore $C$ is closed.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A topological space $X$ is called path-connected if $\\forall x,y\\in X,\\exists\\gamma:[0,1]\\to X$ continuous, $\\gamma(0)=x,\\gamma(1)=y$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Any path-connected space is connected.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose not, then $X$ is path-connected but not connected, so there are open $U,V$ disconnects $X$.\r\n    Then fixing $x\\in U,y\\in V$, there exists a continuous $\\gamma:[0,1]\\to X$ such that $\\gamma(0)=x,\\gamma(1)=y$.\r\n    Thus $\\gamma^{-1}(U),\\gamma^{-1}(V)$ are nonempty, open, and partitions $[0,1]$, thus $[0,1]$ is disconnected by them, which is a contradiction.\r\n\\end{proof}\r\nThe converse, however, is not true.\r\n\\begin{example}\r\n    Take the Topologist's Sine Wave, $X=\\{(x,\\sin(1/x)):x>0\\}\\cup(\\{0\\}\\times [-1,1])$.\r\n    We have already shown it is connected.\r\n    But it is not path-connected.\r\n    Indeed, pick points $(0,0),(1,\\sin(1))\\in X$.\r\n    Assume that $\\gamma:[0,1]\\to X$ is continuous and $\\gamma(0)=(0,0)=x,\\gamma(1)=(1,\\sin(1))=y$.\r\n    Let $\\gamma_1,\\gamma_2$ be the components of $\\gamma$, which are continuous.\r\n    For $\\gamma_1(t)>0$, then $[0,\\gamma_1(t)]\\subset \\gamma_1([0,t])$ by IVT, so $\\exists n\\in\\mathbb N,(2\\pi n)^{-1},(2\\pi n+\\pi/2)^{-1}\\in (0,\\gamma_1(t))\\subset \\gamma_1([0,t])$.\r\n    So there is some $a,b$ with $\\gamma_1(a)=(2\\pi n)^{-1},\\gamma_1(b)=(2\\pi n+\\pi/2)^{-1}$, hence $\\gamma_2(a)=0,\\gamma_2(b)=1$, so we can thus find a sequence $1>t_1>t_2>\\cdots>0$ with\r\n    $$\\gamma_2(t_n)=\r\n    \\begin{cases}\r\n        1\\text{, if $n$ is even}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    So $t_n$ converges but $\\gamma_2(t_n)$ does not.\r\n    This is a contradiction.\r\n\\end{example}\r\n\\begin{lemma}[Gluing Lemma]\r\n    Let $f:X\\to Y$ be a function between topological spaces.\r\n    If $X=A\\cup B$ where $A,B$ are closed and $f|_A,f|_B$ are continuous, then $f$ is continuous.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Given closed $V$ in $Y$,\r\n    $$f^{-1}(V)=(f^{-1}(V)\\cap A)\\cup (f^{-1}(V)\\cap B)=(f|_A)^{-1}(V)\\cup (f|_B)^{-1}(V)$$\r\n    which is closed since $A,B$ are closed.\r\n    Hence $f$ is continuous.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $X$ be a topological space.\r\n    Define the relation $R$ by $xRy$ if and only if there is a continuous $\\gamma:[0,1]\\to X$ such that $\\gamma(0)=x,\\gamma(1)=y$.\r\n    Then this is an equivalence relation.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $U\\subset\\mathbb R^n$ be open, then $U$ is connected if and only if $U$ is path-connected.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffice to show every open connected subset of $\\mathbb R^n$ is path-connected.\\\\\r\n    WLOG $U\\neq\\varnothing$, fix $x_0\\in U$, let $V$ be the path-connected component containing $x_0$.\r\n    We shall show that $V,U\\setminus V$ are both open, so by assumption $V=U$, thus the proof will be done.\\\\\r\n    $V$ open: Since $U$ is open, for any $x\\in U$, there is $r>0$ such that $D_r(x)\\in U$.\r\n    But any ball is path connected, so $\\forall x\\in V,\\exists r_x>0, D_{r_x}(x)\\in V$, so $V$ is open.\\\\\r\n    $U\\setminus V$ open: Fix by the same proof as above, any path-connected components in $V$ is open, so since $U\\setminus V$ is the union of some of them (the ones except $V$), it is open.\r\n\\end{proof}\r\n\\begin{example}\r\n    For $n\\ge 2$, $\\mathbb R^n$ is not homeomorphic to $\\mathbb R$.\r\n    Assume $f:\\mathbb R^n\\to \\mathbb R$ is a homeomorphism.\r\n    Fix $x\\in\\mathbb R^n$, and let $y=f(x)$, then $f|_{\\mathbb R^n\\setminus\\{x\\}}$ is still a homeomorphism to $\\mathbb R\\setminus\\{y\\}$.\r\n    But then $\\mathbb R^n\\setminus\\{x\\}$ is connected by the preceding theorem, but $\\mathbb R\\setminus\\{y\\}$ is not, contradiction.\r\n\\end{example}\r\n", "meta": {"hexsha": "b5aec928ce1976b871e60e1be139adaa7b18ae77", "size": 10675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/connect.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": "6/connect.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": "6/connect.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": 62.0639534884, "max_line_length": 342, "alphanum_fraction": 0.6622014052, "num_tokens": 3520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8670357718273068, "lm_q1q2_score": 0.6808906315526243}}
{"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{fmpar}\n\\section*{\\hspace*{-1.6cm} fmpar}\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 parabolic 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] = fmpar(N,P1)\n[x,iflaw] = fmpar(N,P1,P2,P3)\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 fmpar} generates a signal with parabolic frequency modulation\n        law : \\[x(t) = \\exp(j2\\pi(a_0 t + \\frac{a_1}{2} t^2 +\\frac{a_2}{3} t^3)).\\]\n\\vspace*{.2cm}\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 P1} & if {\\ty nargin=2}, {\\ty P1} is a vector containing the three \n            coefficients {\\ty (a0 a1 a2)} of the polynomial instantaneous phase.\n            If {\\ty nargin=4}, P1 (as {\\ty P2} and {\\ty P3}) is a\n\t    time-frequency point of the form {\\ty (ti fi)}.\n            The coefficients {\\ty (a0,a1,a2)} are then deduced such that  \n            the frequency modulation law fits these three points\\\\\n        {\\ty P2, P3} & 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\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Examples}\n\\begin{verbatim}\n         [x,iflaw]=fmpar(200,[1 0.4],[100 0.05],[200 0.4]);\n         subplot(211);plot(real(x));subplot(212);plot(iflaw);\n         [x,iflaw]=fmpar(100,[0.4 -0.0112 8.6806e-05]);\n         subplot(211);plot(real(x));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}\nfmconst, fmhyp, fmlin, fmsin, fmodany, fmpower.\n\\end{verbatim}\n\\end{minipage}\n\n\n\n", "meta": {"hexsha": "15eab61f78dcf37813b009e3907516286cafa76c", "size": 2201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/fmpar.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/fmpar.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/fmpar.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.8414634146, "max_line_length": 83, "alphanum_fraction": 0.6228986824, "num_tokens": 809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6808906183713461}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{MAT257 Notes}\n\\author{Jad Elkhaleq Ghalayini}\n\\date{October 17 2018}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{mathtools}\n\\usepackage{enumitem}\n\\usepackage{graphicx}\n\\usepackage{cancel}\n\n\\usepackage[margin=1in]{geometry}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{definition}{Definition}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem{exercise}{Exercise}\n\n\\newcommand{\\reals}[0]{\\mathbb{R}}\n\\newcommand{\\nats}[0]{\\mathbb{N}}\n\\newcommand{\\ints}[0]{\\mathbb{Z}}\n\\newcommand{\\rationals}[0]{\\mathbb{Q}}\n\\newcommand{\\brac}[1]{\\left(#1\\right)}\n\\newcommand{\\sbrac}[1]{\\left[#1\\right]}\n\\newcommand{\\mc}[1]{\\mathcal{#1}}\n\\newcommand{\\eval}[3]{\\left.#3\\right|_{#1}^{#2}}\n\\newcommand{\\ip}[2]{\\left\\langle#1,#2\\right\\rangle}\n\\newcommand{\\prt}[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{The Inverse Function Theorem Implies the Implicit Function Theorem}\n\nWe have to start with the hypotheses of the implicit function theorem: given a \\(\\mc{C}^r\\) (where \\(r \\geq 1\\)) function\n\\(f: U \\to \\reals^n\\)\nwhere \\(U \\in \\reals^{m + n}\\), \\(f(a, b) = 0\\) and \\(\\det M \\neq 0\\), where\n\\[M = \\left(\\prt{f_i}{y_j}(a, b)\\right)\\]\nDefine\n\\[F: U \\to \\reals^m\\times\\reals^n, (x, y) \\mapsto (x, f(x, y))\\]\nIn particular,\n\\[F(a, b) = (a, 0)\\]\nThis is what we're going to apply the inverse function theorem to. So we've got to show that this function satisfies the hypotheses of the inverse function theorem. So we've got to show that its derivative matrix at the point \\((a, b)\\) is invertable. So let's compute: the derivative is given by\n\\[F'(a, b) = \\left(\\begin{array}{c|c} I & 0 \\\\ \\hline * & M \\end{array}\\right) \\implies \\det F'(a, b) = \\det I \\det M = \\det M \\neq 0\\]\nThese are the conditions under which we can apply the inverse function theorem. So by the inverse function theorem, there exists an open neighborhood \\(V\\) of \\((a, b)\\), and an open neighborhood \\(W\\) of \\((0, 0)\\) so that \\(F: V \\to W\\) has a \\(\\mc{C}^r\\) inverse\n\\(F^{-1}: W \\to V\\). We can assume \\(V = A \\times B\\), where \\(A, B\\) are open neighborhoods of \\(a, b\\). \\(F^{-1}(u, v)\\) has the form \\((u, h(u, v))\\). So\n\\[F(F^{-1}(u, v)) = F(u, h(u, v)) = (u, f(u, h(u, v))) = (u, v) \\implies f(u, h(u, v)) = v\\]\n\\[\\implies f(u, h(u, 0)) = 0\\]\nLet \\(g(x) = h(x, 0)\\), which is \\(\\mc{C}^r\\). Then\n\\[f(x, g(x)) = 0\\]\nRemark: we can find \\(g'(x)\\) by \\underline{implicit differentiation}. We have\n\\[\\forall i \\in \\{1,...,n\\}, f_i(x, g(x)) = 0\\]\nWe can write\n\\[\\prt{f_i}{x_j}(x, g(x)) + \\sum_{k = 1}^n\\prt{f_i}{y_k}(x, g(x))\\prt{g_k}{x_j}(x) = 0\\]\nWe can solve for \\(\\prt{g_k}{x_j}\\) because \\(\\left(\\prt{f_i}{y_k}(x, y)\\right)\\) is invertible near \\((a, b)\\).\n\n\\section*{The Implicit Function Theorem Implies the Inverse Function Theorem}\n\nThis time, we start with the hypotheses of the \\textit{inverse} function theorem. So here we have a \\(\\mc{C}^r\\) function \\(f: U \\to \\reals^n\\) with \\(\\det f'(a) \\neq 0\\).\n\nLet \\(b = f(a)\\), and define\n\\[F(x, y) = y - f(x)\\]\nThis is a \\(\\mc{C}^r\\) function of \\((a, b)\\) and \\(F(a, b) = 0\\). We have\n\\[\\prt{F}{x}(a, b) = \\det(-f'(a)) \\neq 0\\]\nBy the implicit function theorem there exist open neighborhoods \\(A, B\\) of \\(a, b\\) respectively such that for all \\(y \\in A\\), there is a unique \\(\\mc{C}^r\\) \\(x = g(y)\\) in \\(B\\) such that\n\\[F(g(y), y) = 0 \\iff y - f(g(y)) = 0\\]\nTake \\(V = f^{-1}(A) \\cap B\\), \\(W = A\\). Then\n\\[x \\in V \\implies f(x) \\in A\\]\nand \\(x\\) is the unique element of \\(B\\) such that \\(g(f(x)) = 0\\), i.e. \\(x = g(f(x))\\).\n\n\\end{document}\n", "meta": {"hexsha": "f542345cfac3c8225bbee02409f5f9917c81d6ca", "size": 3599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/october17.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/october17.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/october17.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": 46.141025641, "max_line_length": 296, "alphanum_fraction": 0.620450125, "num_tokens": 1381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.8918110511888303, "lm_q1q2_score": 0.6808832673396865}}
{"text": "\n\\section{Computing the closest point on a patch  \\label{app:closest_point}}\n%\\subsection{Optimization\\label{app:closest_point_opt}}\n%\\begin{figure}%[!htb]\n%  \\centering\n%    \\includegraphics[width=.5\\linewidth]{figs/newton-opt.pdf}\n%    \\mcaption{fig:newton-opt}{Closest point optimization schematic}{}\n%\\end{figure}\nWe include our algorithm to find the closest point $\\vy$ on a patch $\\vP$ to a point $\\vx \\in \\mathbb{R}^3$ in the section for completeness.\nFor a surface or quadrature patch $\\vP$ and point $\\vx \\in \\mathbb{R}^3$, \nwe need to compute a point $\\vy = \\vP(s^*, t^*)$ such that\n\\begin{equation}\n  (s^*, t^*) = \\argmin_{(s,t) \\in [-1,1]^2} \\|\\vx - \\vP(s,t)\\|_2^2 =  \\argmin_{(s,t) \\in [-1,1]^2} \\vr(s,t)\\cdot \\vr(s,t)\n\\end{equation}\nwhere $ \\vr = \\vr(s,t) = \\vx - \\vP(s,t)$; let $g(s,t) = \\vr\\cdot \\vr$.\nWe first consider the unconstrained problem\n\\begin{equation}\n    (s^*, t^*) = \\argmin_{(s,t) \\in \\mathbb{R}^2} \\|\\vx - \\vP(s,t)\\|_2^2  = \\argmin_{(s,t) \\in \\mathbb{R}^2} \\psi(s,t) \n\\end{equation}\nWe solve this optimization problem with Newton's method.\nThe first and second derivatives of $\\psi$ can be evaluated efficiently, since they are polynomials of fixed order.\nThe gradient and Hessian of the objective function are:\n\\begin{equation}\n  \\nabla \\psi  =\n  \\begin{pmatrix}\n    -\\vP_s\\cdot \\vr \\\\\n    -\\vP_t\\cdot \\vr \\\\\n  \\end{pmatrix}, \\quad\n  %\\label{eq:grad-newton} \n  \\nabla^2 \\psi = \n\\begin{pmatrix}\n  \\vP_s \\cdot \\vP_s - \\vr\\cdot \\vP_{ss} & \\vP_s \\cdot \\vP_t - \\vr\\cdot \\vP_{st}\\\\\n  \\vP_s \\cdot \\vP_t - \\vr\\cdot \\vP_{st} & \\vP_t \\cdot \\vP_t - \\vr\\cdot \\vP_{tt}  \\\\\n\\end{pmatrix}.\n  \\label{equ:grad-hess-newton}\n\\end{equation}\nThe optimality conditions are \n\\begin{equation}\n\\vP_s^* \\cdot \\vr^* = 0, \\quad \\vP_t^* \\cdot \\vr^* = 0, \\quad (u,v) = (s^*, t^*).\n  \\label{eq:kkt}\n\\end{equation}\nat a local optimum $(s^*, t^*)$.\n\nLet $\\psi_i = \\psi(s_i,t_i)$, where $(s_i,t_i)$ is the value of the solution during the $i$th iteration of Newton's method.\nTo solve for the descent direction in Newton's method, we need to solve\n\\begin{equation}\n  \\nabla^2 \\psi_i \\, \\eta_i = -\\nabla \\psi_i\n  \\label{eq:newton-system}\n\\end{equation}\nwhere $\\eta_i = (\\Delta s_i,\\Delta t_i)$ is the $i$th Newton update to $(s_i,t_i)$ such that\n\\begin{equation}\n  s_{i+1} = \\alpha_i\\Delta s_i + s_i,\\quad\n  t_{i+1} = \\alpha_i\\Delta t_i + t_i\n  \\label{}\n\\end{equation}\n\nWe use four iterations of a backtracking line search with an Armijo condition to compute the step length $\\alpha_i$ to ensure an appropriate size step is taken in case the initial guess is outside the region of quadratic convergence.\nWe compute the solution $(s^*, t^*)$ by iterating\n\\begin{equation}\n  (s_n,t_n) = (s_{n-1}, t_{n-1}) + \\alpha_{n-1} \\eta_{n-1}, \\quad \\text{ while } \\vP_s \\cdot \\vr > \\err{opt}, \\quad \\vP_t \\cdot \\vr > \\err{opt},\n  \\label{eq:descent_iter}\n\\end{equation}\nuntil convergence, i.e., $\\psi_i\\approx \\err{opt}$, $\\vr \\approx \\vn(\\vy)$.\n\nIf $(s^*, t^*) \\in (-1,1)^2$, then the solution to the unconstrained problem is also the solution to the constrained problem.\nHowever, if the closest point lies in $\\mathbb{R}\\setminus [-1,1]^2$, we need to ensure the inequality constraints are satisfied.\nAdditionally, if $(s^*, t^*)$ is on the boundary of $[-1,1]^2$, either $s^*$ or $t^*$ should be exactly zero; with the optimization scheme above, we can only claim that $|s^*| < \\err{opt}$ (similarly for $t^*$).\nTo address both of these troubles, we can solve a one-dimensional projection of \\cref{eq:newton-system} on to the boundary of $[-1,1]^2$.\nFor example, to find the closest point along the edge $v=0$, the Newton iteration becomes\n\\begin{equation}\n  s_n = s_{n-1} + \\alpha_{n-1}\\frac{-\\vP_s \\cdot \\vr}{\\vP_s\\cdot \\vP_s - \\vr\\cdot \\vP_{ss}},\n  \\label{eq:geom-newton-1d}\n\\end{equation}\nwhere $\\vP_s$, $\\vP_{ss}$ and $\\vr$ are evaluated at $s_{n-1}$.\nSince the boundary is composed of $[-1,t]$, $[1,t]$, $[s,-1]$, $[s,1]$ for $s,t\\in[-1,1]$, we solve \\cref{eq:geom-newton-1d} once for each interval.\n\nThis final algorithm to compute the closest point is as follows:\n\\begin{enumerate}\n  \\item We solve \\cref{eq:newton-system} on an extended parameter domain $[-1-c, 1+c]^2$, and terminate the Newton iteration if $(s_i,t_i)$ walks outside this boundary. \n    If the Newton iteration terminates inside $[-1,1]^2$, then we've found the closest point.\n    We typically choose $c = .2$.\n  \\item  If the solution is outside $[-1,1]^2$, we solve \\cref{eq:newton-system} along each component of the boundary of $[-1,1]^2$, also on an extended parameter domain $[-1-c,1+c]$,\n    by choosing an initial guess contained within the interval.\n    The solution to these four problems that yields a minimal distance to $\\vx$ to used as the closest point, if the solution is inside $[-1,1]$.\n  \\item If the closest point on the boundary is still outside of $[-1,1]^2$, the\n      closest point to $\\vx$ is chosen from $\\vP(-1,-1), \\vP(-1,1), \\vP(1,-1),$ and $\\vP(1,1)$ closest to $\\vx$.\n\\end{enumerate}\nThis gives us an algorithm to compute the closest point on a quadrature patch $\\vP$ to $\\vx$.\nThe \\oned and \\twod Newton minimizations converge in ten iterations on average.\n\n", "meta": {"hexsha": "fbbd5d812195b8f799a0c2b2ee465159f798cbad", "size": 5153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hedgehog/closest_point.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/closest_point.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/closest_point.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": 56.6263736264, "max_line_length": 233, "alphanum_fraction": 0.6710653988, "num_tokens": 1775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6808832537588834}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\n\\begin{document}\n\n\\section*{Introduction}\nSummary of the Analysis II course given by Sir Thomas Mountford.\n\n\\section{Notes}\n\n\\begin{itemize}\n\t\\item A \\emph{metric space} is a vector space equipped with a metric, that is a function that measures distance between every two elements of the space, whereas a norm space is simply a vector space equipped with a norm: all metric spaces are norm spaces, but the converse is not true.\n\t\\item BASIC CONCEPT OF TOPOLOGY: a \\emph{neighborhood}, or \\emph{open ball} of x $B(\\vec x, r) = \\{\\vec y \\ : \\ d(\\vec x, \\vec y) < r\\}$ is a \"zone around a point\" (a set of points) such that these points are less than a certain distance around $\\vec x$ (actually it's not, it's \"any set containing $B(\\vec x, \\epsilon)$ for some $\\epsilon > 0$\n\t\\item OPEN SET: An open set $O \\subseteq \\mathbb{R}^n$ is a set such that $\\forall \\vec x \\in O \\exists \\epsilon_x > 0$ such that $B(\\vec x, \\epsilon_x) \\subset O$ (So $O$ is open $\\iff$ $O$ is an ... for each of its points)\n\t\\item PROPERTIES: union over any collection of open sets is open; the intersection of two open sets is open\n\t\\item CLOSED SET: a set $F \\subset \\mathbb{R}^n$ is closed if $F^C = \\{\\vec x \\ : \\ \\vec x \\notin F\\}$ is open. Intuitively, think of a disc from which you remove all points on the circle. Ex: $\\overline{B} (\\vec x, r) = \\{\\vec y \\ : \\ d(\\vec x, \\vec y) \\leq r\\}$ is closed. Ex: in one dimension, take $F = [0, 1]$. Then compute $F^C = ]-\\infty, 0[ \\cup ]1, \\infty[$ is a union of open sets, and therefore is an open set. Therefore, $F$ is a closed set by definition. ($F^C$ means \"$F$ complement\")\n\t\\item BOUNDARY: Given $S \\subset \\mathbb{R}^n$, the boundary of $S$, that is, $\\delta s$, is the collection $\\{\\vec x \\ : \\ \\forall \\epsilon > 0 \\ B(\\vec x, \\epsilon) \\cap S \\neq \\emptyset \\land B(\\vec x, \\epsilon) \\cap S^C \\neq \\emptyset\\}$\n\t\\item given $S$, the closure (adherence) of $S$, $\\overline S$, is $S \\cup \\delta S$\n\\end{itemize}\n\n\\end{document}", "meta": {"hexsha": "5294c7f0df79ff7833bb447e0f4df60175e9b84a", "size": 2058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "BA2/analysis2/analysis2-mountford-resume.tex", "max_stars_repo_name": "betrisey/almighty-handbook-of-sleep-deprived-student", "max_stars_repo_head_hexsha": "6fbe6f73f9ca438cfd9e9213e4363effe3ceabdd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2018-11-18T22:16:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-22T20:58:19.000Z", "max_issues_repo_path": "BA2/analysis2/analysis2-mountford-resume.tex", "max_issues_repo_name": "betrisey/almighty-handbook-of-sleep-deprived-student", "max_issues_repo_head_hexsha": "6fbe6f73f9ca438cfd9e9213e4363effe3ceabdd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BA2/analysis2/analysis2-mountford-resume.tex", "max_forks_repo_name": "betrisey/almighty-handbook-of-sleep-deprived-student", "max_forks_repo_head_hexsha": "6fbe6f73f9ca438cfd9e9213e4363effe3ceabdd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-11-18T22:16:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-12T23:15:43.000Z", "avg_line_length": 85.75, "max_line_length": 499, "alphanum_fraction": 0.6797862002, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867851, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.6808739038513434}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\\chapter{Higher Derivatives}\nHigher derivatives are derivatives of derivatives. \nFor instance, if $y^\\prime$ is the derivative of $y'$, \nthen $y^{\\prime\\prime}$ is the derivative of $y^\\prime$.\n\\begin{table}[h]\n    \\centering\n    \\caption{All the different notations for higher derivates}\n    \\label{tab:notations}\n    \\begin{tabular}{c|c|c|c}\n    $y'$      & $\\frac{d}{dx}y$                   & $\\frac{dy}{dx}$     & $Dy$   \\\\ \\hline\n    $y''$     & $\\left( \\frac{d}{dx} \\right)^2 y$ & $\\frac{d^2y}{dx^2}$ & $D^2y$ \\\\ \\hline\n    $y'''$    & $\\left( \\frac{d}{dx} \\right)^3 y$ & $\\frac{d^3y}{dx^3}$ & $D^3y$ \\\\ \\hline\n    $y^{(4)}$ & $\\left( \\frac{d}{dx} \\right)^4 y$ & $\\frac{d^4y}{dx^4}$ & $D^4y$ \\\\ \\hline\n    $y^{(n)}$ & $\\left( \\frac{d}{dx} \\right)^n y$ & $\\frac{d^ny}{dx^n}$ & $D^ny$\n    \\end{tabular}\n\\end{table}\n\nHigher derivatives are pretty straightforward --- \njust keep taking the derivative!\n\\begin{exmp}\n    Let us see what happens if we keep taking the derivative of \n    $f(x) = \\sin x$:\n    \\begin{align*}\n        f'(x)   &= \\cos x   \\\\\n        f''(x)  &= - \\sin x \\\\\n        f'''(x) &= - \\cos x \\\\\n        f^{(4)} &= \\sin x\n    \\end{align*}\n    We have, somehow, arrived back at the original function, \n    $f''''(x) = f(x)$.\n    The sine and cosine functions, both, have this property.\n\\end{exmp}\n\\begin{exmp}\n    What is $D^n x^n$?  \\\\\n    We will start small and look for a pattern. We know:\n    \\begin{align*}\n        \\frac{d}{dx} x^n        &= nx^{n - 1}               \\\\\n        \\frac{d^2}{dx^2} x^n    &= n(n - 1)x^{n - 2}        \\\\\n        \\frac{d^3}{dx^3} x^n    &= n(n - 1)(n - 2)x^{n - 3} \\\\\n    \\end{align*}\n    We can reasonably extend this pattern to deduce:\n    \\[\n        \\frac{d^{n - 1}}{dx^{n - 1}} x^n =\n        n(n - 1)(n - 2)(n - 3) \\cdots 3 \\cdot 2 \\cdot x\n    \\]\n    Finally, we get:\n    \\[\n        \\frac{d^{n}}{dx^{n}} x^n =\n        n(n - 1)(n - 2)(n - 3) \\cdots 3 \\cdot 2 \\cdot 1\n    \\]\n    There is a name for this pattern of products; \\emph{factorials} ($n!$).\n    Therefore:\n    \\[ \\frac{d^{n}}{dx^{n}} x^n = n! \\]\n    Now, we can also see:\n    \\[ \\frac{d^{n + 1}}{dx^{n + 1}} x^n = 0 \\]\n    We just (unwittingly) did a proof by \\emph{mathematical induction}! \n    It is an extremely useful tool in every mathematician's toolbox.\n\\end{exmp}\n\\end{document}", "meta": {"hexsha": "8a7a1e58f46ee123557bfb03590d4df1b737895e", "size": 2356, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter4.tex", "max_stars_repo_name": "DanialHaseeb/single-variable-calculus", "max_stars_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter4.tex", "max_issues_repo_name": "DanialHaseeb/single-variable-calculus", "max_issues_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-01-22T21:42:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-15T13:01:11.000Z", "max_forks_repo_path": "chapters/chapter4.tex", "max_forks_repo_name": "DanialHaseeb/single-variable-calculus", "max_forks_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0, "max_line_length": 90, "alphanum_fraction": 0.5178268251, "num_tokens": 898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6808738872660984}}
{"text": "\\subsection{Gluing Riemann Surfaces}\r\nWhen we were studying the $k^{th}$ roots, we constructed a Riemann surface $R_k$ equipped with analytic $\\pi,g$ such that\r\n\\[\r\n    \\begin{tikzcd}\r\n        R_k\\arrow[swap]{dr}{\\pi}\\arrow{r}{g}&\\mathbb C_\\star\\arrow{d}{p_k}\\\\\r\n        &\\mathbb C_\\star\r\n    \\end{tikzcd}\r\n\\]\r\ncommutes.\r\nWe also observed that this diagram can be compactified by resolving the removable singularities\r\n\\[\r\n    \\begin{tikzcd}\r\n        \\hat{R}_k\\arrow[swap]{dr}{\\hat\\pi}\\arrow{r}{\\hat{g}}&\\mathbb C_\\infty\\arrow{d}{\\hat{p}_k}\\\\\r\n        &\\mathbb C_\\infty\r\n    \\end{tikzcd}\r\n\\]\r\nHow do we do this in general?\r\nThe answer is via gluing.\r\n\\begin{definition}\r\n    Let $X,Y$ be topological spaces and with subspaces $X'\\subset X,Y'\\subset Y$ and a homeomorphism $\\Phi:X'\\to Y'$.\r\n    The result of gluing $X,Y$ along $\\Phi$ is the topological space $Z=(X\\sqcup Y)/\\sim$ where $\\sim$ is the minimal equivalence relation such that $x\\sim\\Phi(x)$ for all $x\\in X'$.\r\n    It is sometimes denoted by $X\\cup_{\\Phi}Y$ or $X\\cup_{X'}Y$ if the homeomorphism $\\Phi$ is understood.\r\n\\end{definition}\r\nWe need to understand how gluing gives rise to a new Riemann surface in the case where $X,Y$ are Riemann surfaces.\r\n\\begin{proposition}\r\n    Let $R_1,R_2$ be Riemann urfaces and $S_j\\in R_j$ are non empty, connected and open subsets and $\\Phi:S_1\\to S_2$ is a conformal equvalence of Riemann surfaces, then there is a unique conformal stucture on $R=R_1\\cup_\\Phi R_2$ such that the inclusions $i_j:R_j\\to R$ are analytic.\r\n    In particular, if $R$ is Hausdorff, then it is a Riemann surface.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider the family of charts $(\\phi_j\\circ i_j^{-1},i_j(U_j))$ where $(\\phi_j,U_j)$ is a chart on $R_j$.\r\n    The transition functions are then either transition functions of $R_j$ or $\\phi_2\\circ i_2^{-1}\\circ i_1\\circ\\phi_1^{-1}=\\phi_2\\circ\\Phi\\circ\\phi_1^{-1}$ which is analytic as $\\Phi$ is.\r\n    This induces a conformal structure on $R$.\\\\\r\n    For uniqueness, suppose $(\\phi_j,U_j)$ is a chart on $R_j$ and $(\\psi,V)$ is a chart in another conformal stucture on $R$ such that the condition holds, then $\\psi\\circ i_j\\circ\\phi_j^{-1}$ is analytic since $i_j$ is.\r\n    This means that $\\phi_j\\circ i_j^{-1}$ has analytic transition function with all charts\r\n    So by maximality the two conformal structures are equal.\\\\\r\n    It is quite obvious that $R$ is connected.\r\n    So if we assume further that $R$ is Hausdorff, then $R$ is a Riemann surface.\r\n\\end{proof}\r\n\\begin{example}[Non-example]\r\n    Take $R_1=R_2=\\mathbb C,S_1=S_2=\\mathbb C_\\star$, then $R=\\mathbb C\\cup_{\\operatorname{id}_{\\mathbb C_\\star}}\\mathbb C$ is not Hausdorff.\r\n\\end{example}\r\n\\begin{example}\r\n    Let $R_1=R_2=\\mathbb C$ and $S_1=S_2=\\mathbb C_\\star$ and let $\\Phi:\\mathbb C_\\star\\to\\mathbb C_\\star$ be the inversion $z\\mapsto 1/z$.\r\n    Then $R=\\mathbb C\\cup_\\Phi\\mathbb C$ is obviously Hausdorff hence is a Riemann surface by the preceding proposition.\r\n    One can also see easily that $R$ is compact.\r\n    Easily, one can see that $R$ is exactly the Riemann sphere $\\mathbb C_\\infty$.\r\n\\end{example}", "meta": {"hexsha": "6d625cc0c223ae7d73f984a65f137cbca7ccce11", "size": 3119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9/gluing.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": "9/gluing.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": "9/gluing.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": 66.3617021277, "max_line_length": 285, "alphanum_fraction": 0.690926579, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.6808738837200081}}
{"text": "\\clearpage\n\n\n\n\\begin{appendix}\n\\section{}\nFor every individual i in i = 1,\\ldots, N:\n\\[Y_i \\sim \\mathcal{N}(\\mathbf{0}, \\Sigma),\\] where\n\\[\\Sigma = \\Lambda\\Psi\\Lambda',\\] \\[\\Lambda = \n    \\begin{bmatrix}\n    0.75 & 0 \\\\\n    0.75 & 0 \\\\\n    0.75 & 0.2/0.5 \\\\\n    0.2/0.5 & 0.75 \\\\\n    0 & 0.75 \\\\\n    0 & 0.75\n    \\end{bmatrix},\\] \\[\\Psi =\n    \\begin{bmatrix}\n     1 & 0.5 \\\\\n     0.5 & 1\n    \\end{bmatrix}\n,\\] and \\[\\Theta = diag[0.3, 0.3, 0.3, 0.3, 0.3, 0.3].\\]\n\\end{appendix}\n", "meta": {"hexsha": "8ad052b5b88a038d67b6c5785cfc80343019b274", "size": 478, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rmd/report/appendixA.tex", "max_stars_repo_name": "JMBKoch/1vs2StepBayesianRegSEM", "max_stars_repo_head_hexsha": "784ddefac6efd23aa3c4179f33474a071cbf0314", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Rmd/report/appendixA.tex", "max_issues_repo_name": "JMBKoch/1vs2StepBayesianRegSEM", "max_issues_repo_head_hexsha": "784ddefac6efd23aa3c4179f33474a071cbf0314", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rmd/report/appendixA.tex", "max_forks_repo_name": "JMBKoch/1vs2StepBayesianRegSEM", "max_forks_repo_head_hexsha": "784ddefac6efd23aa3c4179f33474a071cbf0314", "max_forks_repo_licenses": ["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.9166666667, "max_line_length": 56, "alphanum_fraction": 0.4874476987, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6808547168026058}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Miscellaneous} \\label{app:misc}\n\n\\section{Implicit Euler algorithm} \\label{app:implicit_euler}\nAll new values $(x,y,p_x,p_y)_{i+1}$ refer to the same unknown values in the same time step $(x,y,p_x,p_y)_{i+1}$.\n\\begin{align}\n    X_{i+1} &= X_i + (P_{X,i+1} + Y_{i+1})h, \\\\[0.2cm]\n    Y_{i+1} &= Y_i + (P_{Y,i+1} - X_{i+1})h , \\\\[0.2cm]\n    P_{X,i+1} &= P_{X,i} + \\left(P_{Y,i+1} - \\dfrac{(1-k)(k+X_{i+1})}{((k+X_{i+1})^2+Y_{i+1}^2)^{3/2}} + \\dfrac{k(X_{i+1}-1+k)}{((X_{i+1}-1+k)^2+Y_{i+1}^2)^{3/2}}\\right)h, \\\\[0.2cm]\n    P_{Y,i+1} &= P_{Y,i} + \\left(-P_{X,i+1} - \\dfrac{(1-k)Y_{i+1}}{((k+X_{i+1})^2+Y_{i+1}^2)^{3/2}} - \\dfrac{k Y_{i+1}}{((X_{i+1}-1+k)^2+Y_{i+1}^2)^{3/2}}\\right)h.\n\\end{align}\n\n\\section{Restricted Three-Body Problem Symplectic Euler Derivations (Mathematica)} \\label{app:r3b-symplectic-euler}\n\\begin{figure}[h!]\n\\centering \n\\includegraphics[scale=0.8]{appendices/Miscellaneous/symplectic_euler_derivation.pdf}\n\\end{figure}\n\n\\section{Restricted Three-Body Problem Störmer-Verlet Derivations (Mathematica)} \\label{app:r3b-verlet}\n\\begin{figure}[h!]\n\\centering \n\\includegraphics[scale=0.60]{appendices/Miscellaneous/R3B_Verlet_derivations.pdf}\n\\end{figure}\n\n\n\\clearpage\n\n\\section{Medium and Short Hohmann orbits} \\label{app:more_hohmann}\n\\begin{adjustwidth*}{0cm}{-0.4cm}\n\\begin{lstlisting}[language=Python,caption=Medium duration Hohmann]\n# --------------------------------------------------------------------------\nduration = 3/unit_time\npos      = -2.272183066647597\nang      = -0.075821466029764\nburn     = 3.135519748743719/unit_vel\nx0       = -0.023110975767437\ny0       = -0.012972499765730\npx0      = 8.032228991913522\npy0      = -7.100537706154897\n# --------------------------------------------------------------------------\n# dV(earth-escape) = 3.135520 km/s\n# dV(moon-capture) = 0.879826 km/s\n# dV(total)        = 4.015346 km/s\n# Flight-time      = 2.999939 days\n# --------------------------------------------------------------------------\n\\end{lstlisting}\n\\end{adjustwidth*}\n\n\n\\begin{adjustwidth*}{0cm}{-0.4cm}\n\\begin{lstlisting}[language=Python,caption=Fast duration Hohmann]\n# --------------------------------------------------------------------------\nduration = 2/unit_time\npos      = -2.277784119105456\nang      = 0.046759232345463\nburn     = 3.809267777777778/unit_vel\nx0       = -0.023183463163465\ny0       = -0.012910923775798\npx0      = 8.760501647975921\npy0      = -7.267405934327472\n# --------------------------------------------------------------------------\n# dV(earth-escape) = 3.809268 km/s\n# dV(moon-capture) = 3.014142 km/s\n# dV(total)        = 6.823410 km/s\n# Flight-time      = 1.000007 days\n# --------------------------------------------------------------------------\n\\end{lstlisting}\n\\end{adjustwidth*}", "meta": {"hexsha": "02847fbefb0195e20f7b32a66938735f87f26559", "size": 2784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/Miscellaneous.tex", "max_stars_repo_name": "GandalfSaxe/leto", "max_stars_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/Miscellaneous.tex", "max_issues_repo_name": "GandalfSaxe/leto", "max_issues_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/Miscellaneous.tex", "max_forks_repo_name": "GandalfSaxe/leto", "max_forks_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9411764706, "max_line_length": 181, "alphanum_fraction": 0.5510057471, "num_tokens": 985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.680823341673259}}
{"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-15.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 15 Verifying the BSSN equations}\n\nThis is short example verifies two of the main equations in the Phys Rev D paper\nby Miguel Alcubierre, Bernd Brugmann etal. (Phys.Rev.D. (62) 044034 (2000)).\n\nThe code for the full set of BSSN equations can be found at\n\\url{https://github.com/leo-brewin/adm-bssn-equations}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,i,j,k,l,m,n,o,p,q,r,s,u#}::Indices(position=independent,values={t,x,y,z}).\n   {t,x,y,z}::Coordinate.\n\n   \\partial{#}::PartialDerivative.\n   D{#}::Derivative.\n   DBar{#}::Derivative.\n\n   N::Depends(t,x,y,z).\n\n   g_{a b}::Symmetric.\n   g^{a b}::Symmetric.\n   g_{a}^{b}::KroneckerDelta.\n   g^{a}_{b}::KroneckerDelta.\n\n   g_{a b}::Depends(t,x,y,z).\n   g^{a b}::Depends(t,x,y,z).\n\n   gBar_{a b}::Symmetric.\n   gBar^{a b}::Symmetric.\n   gBar_{a}^{b}::KroneckerDelta.\n   gBar^{a}_{b}::KroneckerDelta.\n\n   gBar_{a b}::Depends(t,x,y,z).\n   gBar^{a b}::Depends(t,x,y,z).\n\n   trK::LaTeXForm(\"K\").\n   detg::LaTeXForm(\"g\").\n   ABar{#}::LaTeXForm(\"{\\bar{A}}\").\n   DBar{#}::LaTeXForm(\"{\\bar{D}}\").\n\\end{cadabra}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\subsection*{15.1 Evolution equation for $\\phi$}\n\n\\begin{cadabra}\n   phi     := \\phi -> (1/12) \\log(detg).\n   gdotK   := g^{i j} K_{i j} -> trK.\n   DdetgDt := \\partial_{t}{detg} -> detg g^{i j} \\partial_{t}{g_{i j}}.\n\n   DgijDt  := \\partial_{t}{g_{i j}} -> -2 N K_{i j}.\n\n   dlog    := \\partial_{a?}{\\log(A?)} -> (1/A?)\\partial_{a?}{A?}.\n   dexp    := \\partial_{a?}{\\exp(A?)} -> \\exp(A?)\\partial_{a?}{A?}.\n\n   dotphi  := \\partial_{t}{\\phi}.\n\n   substitute (dotphi, phi)                 # cdb (ex-15-02.101,dotphi)\n   substitute (dotphi, dlog)                # cdb (ex-15-02.102,dotphi)\n   substitute (dotphi, DdetgDt)             # cdb (ex-15-02.103,dotphi)\n   substitute (dotphi, DgijDt)              # cdb (ex-15-02.104,dotphi)\n   substitute (dotphi, gdotK)               # cdb (ex-15-02.105,dotphi)\n   map_sympy  (dotphi, \"simplify\")          # cdb (ex-15-02.106,dotphi)\n\n   DphiDt := \\partial_{t}{\\phi} -> @(dotphi).\n\n   checkpoint.append (dotphi)\n\\end{cadabra}\n\n\\begin{align*}\n  \\frac{d{\\phi}}{dt} &=\\Cdb{ex-15-02.101}\\\\[10pt]\n                     &=\\Cdb{ex-15-02.102}\\\\[10pt]\n                     &=\\Cdb{ex-15-02.103}\\\\[10pt]\n                     &=\\Cdb{ex-15-02.104}\\\\[10pt]\n                     &=\\Cdb{ex-15-02.105}\\\\[10pt]\n                     &=\\Cdb{ex-15-02.106}\n\\end{align*}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\subsection*{15.2 Evolution equation for ${\\bar g}_{ij}$}\n\n\\begin{cadabra}\n   gBarij := gBar_{i j} -> \\exp(-4\\phi) g_{i j}.\n   Kij    := K_{i j} -> A_{i j} + (1/3) g_{i j} trK.\n   A2ABar := \\exp(-4\\phi) A_{i j} -> ABar_{i j}.\n   ABar2A := ABar_{i j} -> \\exp(-4\\phi) A_{i j}.\n\n   dotgBarij := \\partial_{t}{gBar_{i j}}.\n\n   substitute   (dotgBarij, gBarij)         # cdb (ex-15-03.101,dotgBarij)\n   product_rule (dotgBarij)                 # cdb (ex-15-03.102,dotgBarij)\n   substitute   (dotgBarij, dexp)           # cdb (ex-15-03.103,dotgBarij)\n   substitute   (dotgBarij, DgijDt)         # cdb (ex-15-03.104,dotgBarij)\n   substitute   (dotgBarij, DphiDt)         # cdb (ex-15-03.105,dotgBarij)\n   substitute   (dotgBarij, Kij)            # cdb (ex-15-03.106,dotgBarij)\n   distribute   (dotgBarij)                 # cdb (ex-15-03.107,dotgBarij)\n   map_sympy    (dotgBarij, \"simplify\")     # cdb (ex-15-03.108,dotgBarij)\n   substitute   (dotgBarij, A2ABar)         # cdb (ex-15-03.109,dotgBarij)\n\n   DgBarijDt := \\partial_{t}{gBar_{i j}} -> @(dotgBarij).\n\n   checkpoint.append (dotgBarij)\n\\end{cadabra}\n\n\\begin{align*}\n  \\frac{d{\\bar g}_{ij}}{dt} &=\\Cdb{ex-15-03.101}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.102}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.103}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.104}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.105}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.106}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.107}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.108}\\\\[10pt]\n                            &=\\Cdb{ex-15-03.109}\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": "09602d22716fa67568e6ecd80006b17a22458475", "size": 5041, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-15.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-15.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-15.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": 32.7337662338, "max_line_length": 94, "alphanum_fraction": 0.5024796667, "num_tokens": 1781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6807491045065277}}
{"text": "\n\\chapter{\\label{chap-filt}Filters and filtrators}\n\nThis chapter is based on my article \\cite{filters}.\n\nThis chapter is grouped in the following way:\n\\begin{itemize}\n\\item First it goes a short introduction in pedagogical order (first less\ngeneral stuff and examples, last the most general stuff):\n\n\\begin{itemize}\n\\item filters on a set;\n\\item filters on a meet-semilattice;\n\\item filters on a poset.\n\\end{itemize}\n\\item Then it goes the formal part.\n\\end{itemize}\n\n\\section{Implication tuples}\n\\begin{defn}\nAn \\emph{implications tuple} is a tuple $(P_{1},\\ldots,P_{n})$ such\nthat $P_{1}\\Rightarrow\\ldots\\Rightarrow P_{n}$.\\end{defn}\n\\begin{obvious}\n$(P_{1},\\ldots,P_{n})$ is an implications tuple iff $P_{i}\\Rightarrow P_{j}$\nfor every $i<j$ (where $i,j\\in\\{1,\\ldots,n\\}$).\n\\end{obvious}\nThe following is an example of a theorem using an implication tuple:\n\\begin{example}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item $A$.\n\\item $B$.\n\\item $C$.\n\\end{enumerate}\n\\end{example}\nThis example means just that $A\\Rightarrow B\\Rightarrow C$.\n\nI prefer here a verbal description instead of symbolic implications\n$A\\Rightarrow B\\Rightarrow C$, because $A$, $B$, $C$ may be long\nEnglish phrases and they may not fit into the formula layout.\n\nThe main (intuitive) idea of the theorem is expressed by the implication\n$P_{1}\\Rightarrow P_{n}$, the rest implications ($P_{2}\\Rightarrow P_{n}$,\n$P_{3}\\Rightarrow P_{n}$, ...) are purely technical, as they express\ngeneralizations of the main idea.\n\nFor uniformity theorems in the section about filters and filtrators\nstart with the same $P_{1}$: ``$(\\mathfrak{A},\\mathfrak{Z})$ is\na powerset filtrator.'' (defined below) That means that the main\nidea of the theorem is about powerset filtrators, the rest implications\n(like $P_{2}\\Rightarrow P_{n}$, $P_{3}\\Rightarrow P_{n}$, ...) are\njust technical generalizations.\n\n\n\\section{Introduction to filters and filtrators}\n\n\n\\subsection{Filters on a set}\n\nWe sometimes want to define something resembling an infinitely small\n(or infinitely big) set, for example the infinitely small interval\nnear $0$ on the real line. Of course there is no such set, just like\nas there is no natural number which is the difference $2-3$. To overcome\nthis shortcoming we introduce whole numbers, and $2-3$ becomes well\ndefined. In the same way to consider things which are like infinitely\nsmall (or infinitely big) sets we introduce \\emph{filters}.\n\nAn example of a filter is the infinitely small interval near $0$\non the real line. To come to infinitely small, we consider all intervals\n$]-\\epsilon;\\epsilon[$ for all $\\epsilon>0$. This filter consists\nof all intervals $]-\\epsilon;\\epsilon[$ for all $\\epsilon>0$ and\nalso all subsets of $\\mathbb{R}$ containing such intervals as subsets.\nInformally speaking, this is the greatest filter contained in every\ninterval $]-\\epsilon;\\epsilon[$ for all $\\epsilon>0$.\n\\begin{defn}\n\\index{filter!on a set}A filter on a set $\\mho$ is a $\\mathcal{F}\\in\\subsets\\subsets\\mho$\nsuch that:\n\\begin{enumerate}\n\\item $\\forall A,B\\in\\mathcal{F}:A\\cap B\\in\\mathcal{F}$;\n\\item $\\forall A,B\\in\\subsets\\mho:(A\\in\\mathcal{F}\\land B\\supseteq A\\Rightarrow B\\in\\mathcal{F})$.\n\\end{enumerate}\n\\end{defn}\n\\begin{xca}\nVerify that the above introduced infinitely small interval near $0$\non the real line is a filter on $\\mathbb{R}$.\n\\end{xca}\n\n\\begin{xca}\nDescribe ``the neighborhood of positive infinity'' filter on $\\mathbb{R}$.\\end{xca}\n\\begin{defn}\n\\index{filter!proper}A filter not containing empty set is called\na \\emph{proper filter}.\\end{defn}\n\\begin{obvious}\nThe non-proper filter is $\\subsets\\mho$.\\end{obvious}\n\\begin{rem}\nSome other authors require that all filters are proper. This is a\nstupid idea and we allow non-proper filters, in the same way as we\nallow to use the number~$0$.\n\\end{rem}\n\n\\subsection{Intro to filters on a meet-semilattice}\n\nA trivial generalization of the above:\n\\begin{defn}\n\\index{filter!on a meet-semilattice}A filter on a meet-semilattice\n$\\mathfrak{Z}$ is a $\\mathcal{F}\\in\\subsets\\mathfrak{Z}$ such that:\n\\begin{enumerate}\n\\item $\\forall A,B\\in\\mathcal{F}:A\\sqcap B\\in\\mathcal{F}$;\n\\item $\\forall A,B\\in\\mathfrak{Z}:(A\\in\\mathcal{F}\\land B\\sqsupseteq A\\Rightarrow B\\in\\mathcal{F})$.\n\\end{enumerate}\n\\end{defn}\n\n\\subsection{Intro to filters on a poset}\n\\begin{defn}\n\\index{filter!on a poset}A filter on a poset~$\\mathfrak{Z}$ is\na $\\mathcal{F}\\in\\subsets\\mathfrak{Z}$ such that:\n\\begin{enumerate}\n\\item $\\forall A,B\\in\\mathcal{F}\\exists C\\in\\mathcal{F}:C\\sqsubseteq A,B$;\n\\item $\\forall A,B\\in\\mathfrak{Z}:(A\\in\\mathcal{F}\\land B\\sqsupseteq A\\Rightarrow B\\in\\mathcal{F})$.\n\\end{enumerate}\n\\end{defn}\nIt is easy to show (and there is a proof of it somewhere below) that\nthis coincides with the above definition in the case if $\\mathfrak{Z}$\nis a meet-semilattice.\n\n\n\\section{Filters on a poset}\n\n\n\\subsection{Filters on posets}\n\nLet $\\mathfrak{Z}$ be a poset.\n\\begin{defn}\n\\index{filter base}\\emph{Filter base} is a nonempty subset $F$ of\n$\\mathfrak{Z}$ such that\n\\[\n\\forall X,Y\\in F\\exists Z\\in F:(Z\\sqsubseteq X\\land Z\\sqsubseteq Y).\n\\]\n\\end{defn}\n\\begin{defn}\n\\index{ideal base}\\emph{Ideal base} is a nonempty subset $F$ of\n$\\mathfrak{Z}$ such that\n\\[\n\\forall X,Y\\in F\\exists Z\\in F:(Z\\sqsupseteq X\\land Z\\sqsupseteq Y).\n\\]\n\\end{defn}\n\n\\begin{obvious}\nIdeal base is the dual of filter base.\n\\end{obvious}\n\n\\begin{obvious}\n~\n\\begin{enumerate}\n  \\item A poset with a lowest element is a filter base.\n  \\item A poset with a greatest element is an ideal base.\n\\end{enumerate}\n\\end{obvious}\n\n\\begin{obvious}\n~\n\\begin{enumerate}\n  \\item A meet-semilattice is a filter base.\n  \\item A join-semilattice is an ideal base.\n\\end{enumerate}\n\\end{obvious}\n\n\\begin{obvious}\nA nonempty chain is a filter base and an ideal base.\\end{obvious}\n\\begin{defn}\n\\index{filter!on poset}\\emph{Filter} is a subset of $\\mathfrak{Z}$\nwhich is both a filter base and an upper set.\n\\end{defn}\nI will denote the set of filters (for a given or implied poset $\\mathfrak{Z}$)\nas $\\mathfrak{F}$ and call $\\mathfrak{F}$ the set of filters over\nthe poset $\\mathfrak{Z}$.\n\\begin{prop}\nIf $\\top$ is the maximal element of $\\mathfrak{Z}$ then $\\top\\in F$\nfor every filter~$F$.\\end{prop}\n\\begin{proof}\nIf $\\top\\notin F$ then $\\forall K\\in\\mathfrak{Z}:K\\notin F$ and\nso $F$ is empty what is impossible.\\end{proof}\n\\begin{prop}\nLet $S$ be a filter base on a poset. If $A_{0},\\ldots,A_{n}\\in S$\n($n\\in\\mathbb{N}$), then\n\\[\n\\exists C\\in S:(C\\sqsubseteq A_{0}\\land\\ldots\\land C\\sqsubseteq A_{n}).\n\\]\n\\end{prop}\n\\begin{proof}\nIt can be easily proved by induction.\\end{proof}\n\\begin{defn}\nA function~$f$ from a poset~$\\mathfrak{A}$ to a poset~$\\mathfrak{B}$\n\\emph{preserves filtered meets} iff whenever $\\bigsqcap S$ is defined\nfor a filter base~$S$ on~$\\mathfrak{A}$ we have $f\\bigsqcap S=\\bigsqcap\\rsupfun fS$.\n\\end{defn}\n\n\\subsection{Filters on meet-semilattices}\n\\begin{thm}\n\\label{filt-eq-char}\\index{filter!on meet-semilattice}If $\\mathfrak{Z}$\nis a meet-semilattice and $F$ is a nonempty subset of $\\mathfrak{Z}$\nthen the following conditions are equivalent:\n\\begin{enumerate}\n\\item \\label{fmslat-filt}$F$ is a filter.\n\\item \\label{fmslat-two}$\\forall X,Y\\in F:X\\sqcap Y\\in F$ and $F$ is\nan upper set.\n\\item \\label{fmslat-one}$\\forall X,Y\\in\\mathfrak{Z}:(X,Y\\in F\\Leftrightarrow X\\sqcap Y\\in F)$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{fmslat-filt}$\\Rightarrow$\\ref{fmslat-two}}] Let $F$ be\na filter. Then $F$ is an upper set. If $X,Y\\in F$ then $Z\\sqsubseteq X\\land Z\\sqsubseteq Y$\nfor some $Z\\in F$. Because $F$ is an upper set and $Z\\sqsubseteq X\\sqcap Y$\nthen $X\\sqcap Y\\in F$.\n\\item [{\\ref{fmslat-two}$\\Rightarrow$\\ref{fmslat-filt}}] Let $\\forall X,Y\\in F:X\\sqcap Y\\in F$\nand $F$ be an upper set. We need to prove that $F$ is a filter base.\nBut it is obvious taking $Z=X\\sqcap Y$ (we have also taken into account\nthat $F\\ne\\emptyset$).\n\\item [{\\ref{fmslat-two}$\\Rightarrow$\\ref{fmslat-one}}] Let $\\forall X,Y\\in F:X\\sqcap Y\\in F$\nand $F$ be an upper set. Then\n\\[\n\\forall X,Y\\in\\mathfrak{Z}:(X,Y\\in F\\Rightarrow X\\sqcap Y\\in F).\n\\]\n\n\n\nLet $X\\sqcap Y\\in F$; then $X,Y\\in F$ because $F$ is an upper set.\n\n\\item [{\\ref{fmslat-one}$\\Rightarrow$\\ref{fmslat-two}}] Let\n\\[\n\\forall X,Y\\in\\mathfrak{Z}:(X,Y\\in F\\Leftrightarrow X\\sqcap Y\\in F).\n\\]\n\n\n\nThen $\\forall X,Y\\in F:X\\sqcap Y\\in F$. Let $X\\in F$ and $X\\sqsubseteq Y\\in\\mathfrak{Z}$.\nThen $X\\sqcap Y=X\\in F$. Consequently $X,Y\\in F$. So $F$ is an\nupper set.\n\n\\end{description}\n\\end{proof}\n\\begin{prop}\nLet $S$ be a filter base on a meet-semilattice. If $A_{0},\\ldots,A_{n}\\in S$\n($n\\in\\mathbb{N}$), then\n\\[\n\\exists C\\in S:C\\sqsubseteq A_{0}\\sqcap\\dots\\sqcap A_{n}.\n\\]\n\\end{prop}\n\\begin{proof}\nIt can be easily proved by induction.\\end{proof}\n\\begin{prop}\nIf $\\mathfrak{Z}$ is a meet-semilattice and $S$ is a filter base\non it, $A\\in\\mathfrak{Z}$, then $\\rsupfun{A\\sqcap}S$ is also a filter\nbase.\\end{prop}\n\\begin{proof}\n$\\rsupfun{A\\sqcap}S\\ne\\emptyset$ because $S\\ne\\emptyset$.\n\nLet $X,Y\\in\\rsupfun{A\\sqcap}S$. Then $X=A\\sqcap X'$ and $Y=A\\sqcap Y'$\nwhere $X',Y'\\in S$. There exists $Z'\\in S$ such that $Z'\\sqsubseteq X'\\sqcap Y'$\n. So $X\\sqcap Y=A\\sqcap X'\\sqcap Y'\\sqsupseteq A\\sqcap Z'\\in\\rsupfun{A\\sqcap}S$.\n\\end{proof}\n\n\\subsection{Order of filters. Principal filters}\n\nI will make the set of filters $\\mathfrak{F}$ into a poset by the\norder defined by the formula: $a\\sqsubseteq b\\Leftrightarrow a\\supseteq b$.\n\\begin{defn}\n\\index{filter!principal}The principal filter corresponding to an\nelement $a\\in\\mathfrak{Z}$ is\n\\[\n\\uparrow a=\\setcond{x\\in\\mathfrak{Z}}{x\\sqsupseteq a}.\n\\]\n\n\nElements of $\\mathfrak{P}=\\rsupfun{\\uparrow}\\mathfrak{Z}$ are called\n\\emph{principal filters}.\\end{defn}\n\\begin{obvious}\nPrincipal filters are filters.\n\\end{obvious}\n\n\\begin{obvious}\n$\\uparrow$ is an order embedding from $\\mathfrak{Z}$ to $\\mathfrak{F}$.\\end{obvious}\n\\begin{cor}\n$\\uparrow$ is an order isomorphism between $\\mathfrak{Z}$ and $\\mathfrak{P}$.\n\\end{cor}\nWe will equate principal filters with corresponding elements of the\nbase poset (in the same way as we equate for example nonnegative whole\nnumbers and natural numbers).\n\\begin{prop}\n$\\uparrow K\\sqsupseteq\\mathcal{A}\\Leftrightarrow K\\in\\mathcal{A}$.\\end{prop}\n\\begin{proof}\n$\\uparrow K\\sqsupseteq\\mathcal{A}\\Leftrightarrow\\uparrow K\\subseteq\\mathcal{A}\\Leftrightarrow K\\in\\mathcal{A}$.\n\\end{proof}\n\n\\section{Filters on a Set}\n\nConsider filters on the poset $\\mathfrak{Z}=\\subsets\\mathfrak{U}$\n(where $\\mathfrak{U}$ is some fixed set) with the order $A\\sqsubseteq B\\Leftrightarrow A\\subseteq B$\n(for $A,B\\in\\subsets\\mathfrak{A}$).\n\nIn fact, it is a complete atomistic boolean lattice with $\\bigsqcap S=\\bigcap S$,\n$\\bigsqcup S=\\bigcup S$, $\\overline{A}=\\mathfrak{U}\\setminus A$\nfor every $S\\in\\subsets\\subsets\\mathfrak{U}$ and $A\\in\\subsets\\mathfrak{U}$,\natoms being one-element sets.\n\\begin{defn}\n\\index{filter!on set}\\index{filter!on powerset}I will call a filter\non the lattice of all subsets of a given set $\\mathfrak{U}$ as a\n\\emph{filter on set}.\n\\end{defn}\n\n\\begin{defn}\nI will denote the set on which a filter $\\mathcal{F}$ is defined\nas $\\Base(\\mathcal{F})$.\\end{defn}\n\\begin{obvious}\n$\\Base(\\mathcal{F})=\\bigcup\\mathcal{F}$.\\end{obvious}\n\\begin{prop}\nThe following are equivalent for a non-empty set $F\\in\\subsets\\subsets\\mathfrak{U}$:\n\\begin{enumerate}\n\\item $F$ is a filter.\n\\item $\\forall X,Y\\in F:X\\cap Y\\in F$ and $F$ is an upper set.\n\\item $\\forall X,Y\\in\\subsets\\mathfrak{U}:(X,Y\\in F\\Leftrightarrow X\\cap Y\\in F)$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nBy theorem \\ref{filt-eq-char}.\\end{proof}\n\\begin{obvious}\nThe minimal filter on $\\subsets\\mathfrak{U}$ is $\\subsets\\mathfrak{U}$.\n\\end{obvious}\n\n\\begin{obvious}\nThe maximal filter on $\\subsets\\mathfrak{U}$ is $\\{\\mathfrak{U}\\}$.\n\\end{obvious}\nI will denote $\\uparrow A=\\uparrow^{\\mathfrak{U}}A=\\uparrow^{\\subsets\\mathfrak{U}}A$.\n(The distinction between conflicting notations $\\uparrow^{\\mathfrak{U}}A$\nand $\\uparrow^{\\subsets\\mathfrak{U}}A$ will be clear from the context.)\n\\begin{prop}\nEvery filter on a finite set is principal.\\end{prop}\n\\begin{proof}\nLet $\\mathcal{F}$ be a filter on a finite set. Then obviously $\\mathcal{F}=\\bigsqcap^{\\mathfrak{Z}}\\up\\mathcal{F}$\nand thus $\\mathcal{F}$ is principal.\n\\end{proof}\n\n\\section{Filtrators}\n\n$(\\mathfrak{F},\\mathfrak{P})$ is a poset and its subset (with induced\norder on the subset). I call pairs of a poset and its subset like\nthis \\emph{filtrators}.\n\\begin{defn}\n\\index{filtrator}I will call a \\emph{filtrator} a pair $(\\mathfrak{A},\\mathfrak{Z})$\nof a poset $\\mathfrak{A}$ and its subset $\\mathfrak{Z}\\subseteq\\mathfrak{A}$.\nI call $\\mathfrak{A}$ the \\emph{base} of the filtrator and $\\mathfrak{Z}$\nthe \\emph{core} of the filtrator. I will also say that $(\\mathfrak{A},\\mathfrak{Z})$\nis a filtrator \\emph{over} poset $\\mathfrak{Z}$.\n\nI will denote $\\base(\\mathfrak{A},\\mathfrak{Z})=\\mathfrak{A}$, $\\core(\\mathfrak{A},\\mathfrak{Z})=\\mathfrak{Z}$\nfor a filtrator $(\\mathfrak{A},\\mathfrak{Z})$.\n\\end{defn}\n\nWhile \\emph{filters} are customary and well known mathematical objects,\nthe concept of \\emph{filtrators} is probably first researched by me.\n\nWhen speaking about filters, we will imply that we consider the filtrator\n$(\\mathfrak{F},\\mathfrak{P})$ or what is the same (as we equate principal\nfilters with base elements) the filtrator $(\\mathfrak{F},\\mathfrak{Z})$.\n\n\n\\begin{defn}\n\\index{filtrator!lattice}I will call a \\emph{lattice filtrator} a\npair $(\\mathfrak{A},\\mathfrak{Z})$ of a lattice $\\mathfrak{A}$ and\nits subset $\\mathfrak{Z}\\subseteq\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!complete lattice}I will call a \\emph{complete lattice\nfiltrator} a pair $(\\mathfrak{A},\\mathfrak{Z})$ of a complete lattice\n$\\mathfrak{A}$ and its subset $\\mathfrak{Z}\\subseteq\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!central}I will call a \\emph{central filtrator} a\nfiltrator $(\\mathfrak{A},Z(\\mathfrak{A}))$ where $Z(\\mathfrak{A})$\nis the center of a bounded lattice $\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{element!of filtrator}I will call \\emph{element} of a filtrator\nan element of its base.\n\\end{defn}\n\n\\begin{defn}\n$\\up^{\\mathfrak{Z}}a=\\up a=\\setcond{c\\in\\mathfrak{Z}}{c\\sqsupseteq a}$\nfor an element $a$ of a filtrator.\n\\end{defn}\n\n\\begin{defn}\n$\\down^{\\mathfrak{Z}}a=\\down a=\\setcond{c\\in\\mathfrak{Z}}{c\\sqsubseteq a}$\nfor an element $a$ of a filtrator.\\end{defn}\n\\begin{obvious}\n``$\\up$'' and ``$\\down$'' are dual.\n\\end{obvious}\nOur main purpose here is knowing properties of the core of a filtrator\nto infer properties of the base of the filtrator, specifically properties\nof $\\up a$ for every element~$a$.\n\\begin{defn}\n\\index{filtrator!with join-closed core}I call a filtrator \\emph{with\njoin-closed core} such a filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nthat $\\bigsqcup^{\\mathfrak{Z}}S=\\bigsqcup^{\\mathfrak{A}}S$ whenever\n$\\bigsqcup^{\\mathfrak{Z}}S$ exists for $S\\in\\subsets\\mathfrak{Z}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!with meet-closed core}I call a filtrator \\emph{with\nmeet-closed core} such a filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nthat $\\bigsqcap^{\\mathfrak{Z}}S=\\bigsqcap^{\\mathfrak{A}}S$ whenever\n$\\bigsqcap^{\\mathfrak{Z}}S$ exists for $S\\in\\subsets\\mathfrak{Z}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!with binarily join-closed core}I call a filtrator\nwith \\emph{binarily join-closed core} such a filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nthat $a\\sqcup^{\\mathfrak{Z}}b=a\\sqcup^{\\mathfrak{A}}b$ whenever $a\\sqcup^{\\mathfrak{Z}}b$\nexists for $a,b\\in\\mathfrak{Z}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!with binarily meet-closed core}I call a filtrator\nwith \\emph{binarily meet-closed core} such a filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nthat $a\\sqcap^{\\mathfrak{Z}}b=a\\sqcap^{\\mathfrak{A}}b$ whenever\n$a\\sqcap^{\\mathfrak{Z}}b$ exists for $a,b\\in\\mathfrak{Z}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!prefiltered}\\emph{Prefiltered filtrator} is a filtrator\n$(\\mathfrak{A},\\mathfrak{Z})$ such that ``$\\up$'' is injective.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!filtered}\\emph{Filtered filtrator} is a filtrator\n$(\\mathfrak{A},\\mathfrak{Z})$ such that\n\\[\n\\forall a,b\\in\\mathfrak{A}:(\\up a\\supseteq\\up b\\Rightarrow a\\sqsubseteq b).\n\\]\n\\end{defn}\n\\begin{thm}\nA filtrator $(\\mathfrak{A},\\mathfrak{Z})$ is filtered iff $\\forall a\\in\\mathfrak{A}:a=\\bigsqcap^{\\mathfrak{A}}\\up a$.\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Leftarrow$}] $\\up a\\supseteq\\up b\\Rightarrow\\bigsqcap^{\\mathfrak{A}}\\up a\\sqsubseteq\\bigsqcap^{\\mathfrak{A}}\\up b\\Rightarrow a\\sqsubseteq b$.\n\\item [{$\\Rightarrow$}] $a=\\bigsqcap^{\\mathfrak{A}}\\up a$ is equivalent\nto $a$ is a greatest lower bound of $\\up a$. That is the implication\nthat $b$ is lower bound of $\\up a$ implies $a\\sqsupseteq b$.\n\n\n$b$ is lower bound of $\\up a$ implies $\\up b\\supseteq\\up a$. So\nas it is filtered $a\\sqsupseteq b$.\n\n\\end{description}\n\\end{proof}\n\\begin{obvious}\nEvery filtered filtrator is prefiltered.\n\\end{obvious}\n\n\\begin{obvious}\n\\label{up-straight}``$\\up$'' is a straight map from $\\mathfrak{A}$\nto the dual of the poset $\\subsets\\mathfrak{Z}$ if $(\\mathfrak{A},\\mathfrak{Z})$\nis a filtered filtrator.\\end{obvious}\n\\begin{defn}\nAn \\emph{isomorphism} between filtrators $(\\mathfrak{A}_{0},\\mathfrak{Z}_{0})$\nand $(\\mathfrak{A}_{1},\\mathfrak{Z}_{1})$ is an isomorphism between\nposets~$\\mathfrak{A}_{0}$ and~$\\mathfrak{A}_{1}$ such that it\nmaps $\\mathfrak{Z}_{0}$ into $\\mathfrak{Z}_{1}$.\\end{defn}\n\\begin{obvious}\nIsomorphism isomorphically maps the order on $\\mathfrak{Z}_{0}$ into\norder on~$\\mathfrak{Z}_{1}$.\\end{obvious}\n\\begin{defn}\nTwo filtrators are \\emph{isomorphic} when there exists an isomorphism\nbetween them.\n\\end{defn}\n\n\\begin{defn}\nI will call \\emph{primary filtrator} a filtrator isomorphic to the\nfiltrator consisting of the set of filters on a poset and the set\nof principal filters on this poset.\\end{defn}\n\\begin{obvious}\nThe order on a primary filtrator is defined by the formula $a\\sqsubseteq b\\Leftrightarrow\\up a\\supseteq\\up b$.\\end{obvious}\n\\begin{defn}\n\\index{filtrator!powerset}I will call a primary filtrator over a\nposet isomorphic to a powerset as \\emph{powerset filtrator}.\\end{defn}\n\\begin{obvious}\n$\\up\\mathcal{F}$ is a filter for every element~$\\mathcal{F}$ of\na primary filtrator. Reversely, there exists a filter $\\mathcal{F}$\nif $\\up\\mathcal{F}$ is a filter.\\end{obvious}\n\\begin{thm}\n\\label{thm1:prim-exists}For every poset~$\\mathfrak{Z}$ there exists\na poset $\\mathfrak{A}\\supseteq\\mathfrak{Z}$ such that $(\\mathfrak{A},\\mathfrak{Z})$\nis a primary filtrator.\\end{thm}\n\\begin{proof}\nSee appendix~\\ref{app:prim-exists}.\n\\end{proof}\n\n\\subsection{Filtrators with Separable Core}\n\\begin{defn}\n\\index{filtrator!with separable core}Let $(\\mathfrak{A},\\mathfrak{Z})$\nbe a filtrator. It is a \\emph{filtrator with separable core} when\n\\[\n\\forall x,y\\in\\mathfrak{A}:(x\\asymp^{\\mathfrak{A}}y\\Rightarrow\\exists X\\in\\up x:X\\asymp^{\\mathfrak{A}}y).\n\\]\n\\end{defn}\n\\begin{prop}\nLet $(\\mathfrak{A},\\mathfrak{Z})$ be a filtrator. It is a \\emph{filtrator\nwith separable core} iff\n\\[\n\\forall x,y\\in\\mathfrak{A}:(x\\asymp^{\\mathfrak{A}}y\\Rightarrow\\exists X\\in\\up x,Y\\in\\up y:X\\asymp^{\\mathfrak{A}}Y).\n\\]\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] Apply the definition twice.\n\\item [{$\\Leftarrow$}] Obvious.\n\\end{description}\n\\end{proof}\n\\begin{defn}\n\\index{filtrator!with co-separable core}Let $(\\mathfrak{A},\\mathfrak{Z})$\nbe a filtrator. It is a \\emph{filtrator with co-separable core} when\n\\[\n\\forall x,y\\in\\mathfrak{A}:(x\\equiv^{\\mathfrak{A}}y\\Rightarrow\\exists X\\in\\down x:X\\equiv^{\\mathfrak{A}}y).\n\\]\n\\end{defn}\n\\begin{obvious}\nCo-separability is the dual of separability.\\end{obvious}\n\\begin{defn}\n\\index{filtrator!with co-separable core}Let $(\\mathfrak{A},\\mathfrak{Z})$\nbe a filtrator. It is a \\emph{filtrator with co-separable core} when\n\\[\n\\forall x,y\\in\\mathfrak{A}:(x\\equiv^{\\mathfrak{A}}y\\Rightarrow\\exists X\\in\\down x,Y\\in\\down y:X\\equiv^{\\mathfrak{A}}Y).\n\\]\n\\end{defn}\n\\begin{proof}\nBy duality.\n\\end{proof}\n\n\\section{Alternative primary filtrators}\n\n\n\\subsection{Lemmas}\n\\begin{lem}\nA set $F$ is a lower set iff $\\overline{F}$ is an upper set.\\end{lem}\n\\begin{proof}\n$X\\in\\overline{F}\\wedge Z\\sqsupseteq X\\Rightarrow Z\\in\\overline{F}$\nis equivalent to $Z\\in F\\Rightarrow X\\in F\\vee Z\\nsqsupseteq X$ is\nequivalent $Z\\in F\\Rightarrow(Z\\sqsupseteq X\\Rightarrow X\\in F)$\nis equivalent $Z\\in F\\wedge X\\sqsubseteq Z\\Rightarrow X\\in F$.\\end{proof}\n\\begin{prop}\nLet $\\mathfrak{Z}$ be a poset with least element~$\\bot$. Then for\nupper set~$F$ we have $F\\ne\\subsets\\mathfrak{Z}\\Leftrightarrow\\bot\\notin F$.\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] If $\\bot\\in F$ then $F=\\subsets\\mathfrak{Z}$\nbecause $F$ is an upper set.\n\\item [{$\\Leftarrow$}] Obvious.\n\\end{description}\n\\end{proof}\n\n\\subsection{Informal introduction}\n\nWe have already defined filters on a poset. Now we will define three\nother sets which are order-isomorphic to the set of filters on a poset:\nideals ($\\mathfrak{I}$), free stars ($\\mathfrak{S}$), and mixers\n($\\mathfrak{M}$).\n\nThese four kinds of objects are related through commutative diagrams.\nFirst we will paint an informal commutative diagram (it makes no formal\nsense because it is not pointed the poset for which the filters are\ndefined):\\[\n\\begin{tikzcd}\n  \\mathfrak{F}\n\t\\arrow[d, leftrightarrow, \"\\lnot\"]\n    \\arrow[r, leftrightarrow, \"\\rsupfun{\\dual}\"]\n    & \\mathfrak{I} \\arrow[d, leftrightarrow, \"\\lnot\"] \\\\\n  \\mathfrak{M}\n\t\\arrow[r, leftrightarrow, \"\\rsupfun{\\dual}\"]\n    & \\mathfrak{S}\n\\end{tikzcd}\n\\]\n\nThen we can define ideals, free stars, and mixers as sets following\ncertain formulas. You can check that the intuition behind these formulas\nfollows the above commutative diagram. (That is transforming these\nformulas by the course of the above diagram, you get formulas of the\nother objects in this list.)\n\nAfter this, we will paint some formal commutative diagrams similar\nto the above diagram but with particular posets at which filters,\nideals, free stars, and mixers are defined.\n\n\n\\subsection{Definitions of ideals, free stars, and mixers}\n\n\\emph{Filters} and \\emph{ideals} are well known concepts. The terms\n\\emph{free stars} and \\emph{mixers} are my new terminology.\n\nRecall that \\emph{filters} are nonempty sets $F$ with $A,B\\in F\\Leftrightarrow\\exists Z\\in F:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\begin{defn}\n\\emph{Ideals} are nonempty sets $F$ with $A,B\\in F\\Leftrightarrow\\exists Z\\in F:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\end{defn}\n\n\\begin{defn}\n\\emph{Free stars} are sets $F$ not equal to $\\subsets\\mathfrak{Z}$\nwith $A,B\\in\\overline{F}\\Leftrightarrow\\exists Z\\in\\overline{F}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\end{defn}\n\n\\begin{defn}\n\\emph{Mixers} are sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with\n$A,B\\in\\overline{F}\\Leftrightarrow\\exists Z\\in\\overline{F}:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\end{defn}\nBy duality and and an above theorem about filters, we have:\n\\begin{prop}\n~\n\\begin{itemize}\n\\item Filters are nonempty upper sets $F$ with $A,B\\in F\\Rightarrow\\exists Z\\in F:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\item Ideals are nonempty lower sets $F$ with $A,B\\in F\\Rightarrow\\exists Z\\in F:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\item Free stars are upper sets $F$ not equal to $\\subsets\\mathfrak{Z}$\nwith $A,B\\in\\overline{F}\\Rightarrow\\exists Z\\in\\overline{F}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\item Mixers are lower sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with\n$A,B\\in\\overline{F}\\Rightarrow\\exists Z\\in\\overline{F}:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\end{itemize}\n\\end{prop}\n\n\\begin{prop}\nThe following are equivalent:\n\\begin{enumerate}\n\\item \\label{free-alt-star}$F$ is a free star.\n\\item \\label{free-alt-eq}$\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B\\Rightarrow Z\\in F)\\Leftrightarrow A\\in F\\vee B\\in F$\nfor every $A,B\\in\\mathfrak{Z}$ and $F\\neq\\subsets\\mathfrak{Z}$.\n\\item \\label{free-alt-impl}$\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B\\Rightarrow Z\\in F)\\Rightarrow A\\in F\\vee B\\in F$\nfor every $A,B\\in\\mathfrak{Z}$ and $F$ is an upper set and $F\\neq\\subsets\\mathfrak{Z}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{free-alt-star}$\\Leftrightarrow$\\ref{free-alt-eq}}] The following\nis a chain of equivalencies:\n\\begin{gather*}\n\\exists Z\\in\\overline{F}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)\\Leftrightarrow A\\notin F\\wedge B\\notin F;\\\\\n\\forall Z\\in\\overline{F}:\\neg(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)\\Leftrightarrow A\\in F\\vee B\\in F;\\\\\n\\forall Z\\in\\mathfrak{Z}:(Z\\notin F\\Rightarrow\\neg(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B))\\Leftrightarrow A\\in F\\vee B\\in F;\\\\\n\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B\\Rightarrow Z\\in F)\\Leftrightarrow A\\in F\\vee B\\in F.\n\\end{gather*}\n\n\\item [{\\ref{free-alt-eq}$\\Rightarrow$\\ref{free-alt-impl}}]\nLet $A=B\\in F$. Then $A\\in F\\lor B\\in F$. So $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B\\Rightarrow Z\\in F)$\nthat is $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\Rightarrow Z\\in F)$ that is $F$ is an upper set.\n\n\\item [{\\ref{free-alt-impl}$\\Rightarrow$\\ref{free-alt-eq}}] We need\nto prove that $F$ is an upper set. let $A\\in F$ and $A\\sqsubseteq B\\in\\mathfrak{Z}$.\nThen $A\\in F\\lor B\\in F$ and thus $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B\\Rightarrow Z\\in F)$\nthat is $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq B\\Rightarrow Z\\in F)$\nand so $B\\in F$.\n\\end{description}\n\\end{proof}\n\\begin{cor}\nThe following are equivalent:\n\\begin{enumerate}\n\\item $F$ is a mixer.\n\\item $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B\\Rightarrow Z\\in F)\\Leftrightarrow A\\in F\\vee B\\in F$\nfor every $A,B\\in\\mathfrak{Z}$ and $F\\neq\\subsets\\mathfrak{Z}$.\n\\item $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B\\Rightarrow Z\\in F)\\Rightarrow A\\in F\\vee B\\in F$\nfor every $A,B\\in\\mathfrak{Z}$ and $F$ is an lower set and $F\\neq\\subsets\\mathfrak{Z}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item A free star cannot contain the least element of the poset.\n\\item A mixer cannot contain the greatest element of the poset.\n\\end{enumerate}\n\\end{obvious}\n\n\\subsection{Filters, ideals, free stars, and mixers on semilattices}\n\\begin{prop}\n~\n\\begin{itemize}\n\\item Free stars are sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with\n$A\\in F\\lor B\\in F\\Leftrightarrow\\lnot\\exists Z\\in\\overline{F}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\item Free stars are upper sets $F$ not equal to $\\subsets\\mathfrak{Z}$\nwith $A\\in F\\lor B\\in F\\Leftarrow\\lnot\\exists Z\\in\\overline{F}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\item Mixers are sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with $A\\in F\\lor B\\in F\\Leftrightarrow\\lnot\\exists Z\\in\\overline{F}:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\item Mixers are lower sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with\n$A\\in F\\lor B\\in F\\Leftarrow\\lnot\\exists Z\\in\\overline{F}:(Z\\sqsubseteq A\\wedge Z\\sqsubseteq B)$\n(for every $A,B\\in\\mathfrak{Z}$).\n\\end{itemize}\n\\end{prop}\n\\begin{proof}\nBy duality.\n\\end{proof}\nBy duality and and an above theorem about filters, we have:\n\\begin{prop}\n~\n\\begin{itemize}\n\\item Filters are nonempty sets $F$ with $A\\sqcap B\\in F\\Leftrightarrow A\\in F\\land B\\in F$\n(for every $A,B\\in\\mathfrak{Z}$), whenever $\\mathfrak{Z}$ is a meet-semilattice.\n\\item Ideals are nonempty sets $F$ with $A\\sqcup B\\in F\\Leftrightarrow A\\in F\\land B\\in F$\n(for every $A,B\\in\\mathfrak{Z}$), whenever $\\mathfrak{Z}$ is a join-semilattice.\n\\item Free stars are sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with\n$A\\sqcup B\\in F\\Leftrightarrow A\\in F\\lor B\\in F$ (for every $A,B\\in\\mathfrak{Z}$),\nwhenever $\\mathfrak{Z}$ is a join-semilattice.\n\\item Mixers are sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with $A\\sqcap B\\in F\\Leftrightarrow A\\in F\\lor B\\in F$\n(for every $A,B\\in\\mathfrak{Z}$), whenever $\\mathfrak{Z}$ is a meet-semilattice.\n\\end{itemize}\n\\end{prop}\nBy duality and and an above theorem about filters, we have:\n\\begin{prop}\n~\n\\begin{itemize}\n\\item Filters are nonempty upper sets $F$ with $A\\sqcap B\\in F\\Leftarrow A\\in F\\land B\\in F$\n(for every $A,B\\in\\mathfrak{Z}$), whenever $\\mathfrak{Z}$ is a meet-semilattice.\n\\item Ideals are nonempty lower sets $F$ with $A\\sqcup B\\in F\\Leftarrow A\\in F\\land B\\in F$\n(for every $A,B\\in\\mathfrak{Z}$), whenever $\\mathfrak{Z}$ is a join-semilattice.\n\\item Free stars are upper sets $F$ not equal to $\\subsets\\mathfrak{Z}$\nwith $A\\sqcup B\\in F\\Rightarrow A\\in F\\lor B\\in F$ (for every $A,B\\in\\mathfrak{Z}$),\nwhenever $\\mathfrak{Z}$ is a join-semilattice.\n\\item Mixers are lower sets $F$ not equal to $\\subsets\\mathfrak{Z}$ with\n$A\\sqcap B\\in F\\Rightarrow A\\in F\\lor B\\in F$ (for every $A,B\\in\\mathfrak{Z}$),\nwhenever $\\mathfrak{Z}$ is a meet-semilattice.\n\\end{itemize}\n\\end{prop}\n\n\\subsection{The general diagram}\n\nLet $\\mathfrak{A}$ and $\\mathfrak{B}$ be two posets connected by\nan order reversing isomorphism $\\theta:\\mathfrak{A}\\rightarrow\\mathfrak{B}$.\nWe have commutative diagram on the figure~\\ref{theta-sets} in the\ncategory $\\mathbf{Set}$:\n\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=1cm, column sep=2cm]\n  \\subsets \\mathfrak{A}\n\t\\arrow[d, leftrightarrow, \"\\lnot\"]\n    \\arrow[r, shift left, rightarrow, \"\\rsupfun{\\theta}\"]\n    & \\subsets \\mathfrak{B} \\arrow[l, shift left, rightarrow, \"\\rsupfun{\\theta^{-1}}\"] \\arrow[d, leftrightarrow, \"\\lnot\"] \\\\\n  \\subsets \\mathfrak{A}\n\t\\arrow[r, shift left, rightarrow, \"\\rsupfun{\\theta}\"]\n    & \\subsets \\mathfrak{B} \\arrow[l, shift left, rightarrow, \"\\rsupfun{\\theta^{-1}}\"]\n\\end{tikzcd}\n\\caption{\\label{theta-sets}}\n\\end{figure}\n\n\\begin{thm}\nThis diagram is commutative, every arrow of this diagram is an isomorphism,\nevery cycle in this diagrams is an identity (therefore ``parallel''\narrows are mutually inverse).\\end{thm}\n\\begin{proof}\nThat every arrow is an isomorphism is obvious.\n\nShow that $\\rsupfun{\\theta}\\lnot X=\\lnot\\rsupfun{\\theta}X$ for every\nset $X\\in\\subsets\\mathfrak{A}$.\n\nReally,\n\\begin{multline*}\np\\in\\rsupfun{\\theta}\\lnot X\\Leftrightarrow\\exists q\\in\\lnot X:p=\\theta q\\Leftrightarrow\\exists q\\in\\lnot X:\\theta^{-1}p=q\\Leftrightarrow\\theta^{-1}p\\in\\lnot X\\Leftrightarrow\\\\\n\\nexists q\\in X:q=\\theta^{-1}p\\Leftrightarrow\\nexists q\\in X:\\theta q=p\\Leftrightarrow p\\notin\\rsupfun{\\theta}X\\Leftrightarrow p\\in\\lnot\\rsupfun{\\theta}X.\n\\end{multline*}\n\n\nThus the theorem follows from lemma~\\ref{four-loop-lem}.\n\\end{proof}\nThis diagram can be restricted to filters, ideals, free stars, and\nmixers, see figure~\\ref{theta-flt}:\n\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=1cm, column sep=2cm]\n  \\mathfrak{F}(\\mathfrak{A})\n\t\\arrow[d, leftrightarrow, \"\\lnot\"]\n    \\arrow[r, shift left, rightarrow, \"\\rsupfun{\\theta}\"]\n    & \\mathfrak{I}(\\mathfrak{B}) \\arrow[l, shift left, rightarrow, \"\\rsupfun{\\theta^{-1}}\"] \\arrow[d, leftrightarrow, \"\\lnot\"] \\\\\n  \\mathfrak{M}(\\mathfrak{A})\n\t\\arrow[r, shift left, rightarrow, \"\\rsupfun{\\theta}\"]\n    & \\mathfrak{S}(\\mathfrak{B}) \\arrow[l, shift left, rightarrow, \"\\rsupfun{\\theta^{-1}}\"]\n\\end{tikzcd}\n\\caption{\\label{theta-flt}}\n\\end{figure}\n\n\\begin{thm}\nIt is a restriction of the above diagram. Every arrow of this diagram\nis an isomorphism, every cycle in these diagrams is an identity. (To\nprove that, is an easy application of duality and the above lemma.)\n\\end{thm}\n\n\\subsection{Special diagrams}\n\nHere are two important special cases of the above diagram:\\begin{equation}\\label{two-diags}\\begin{tikzcd}\n  \\mathfrak{F}(\\mathfrak{A})\n\t\\arrow[d, leftrightarrow, \"\\lnot\"]\n    \\arrow[r, leftrightarrow, \"\\rsupfun{\\dual}\"]\n    & \\mathfrak{I}(\\dual\\mathfrak{A}) \\arrow[d, leftrightarrow, \"\\lnot\"] \\\\\n  \\mathfrak{M}(\\mathfrak{A})\n\t\\arrow[r, leftrightarrow, \"\\rsupfun{\\dual}\"]\n    & \\mathfrak{S}(\\dual\\mathfrak{A})\n\\end{tikzcd}\n\\quad\\text{and}\\quad\n\\begin{tikzcd}\n  \\mathfrak{F}(\\mathfrak{A})\n\t\\arrow[d, leftrightarrow, \"\\lnot\"]\n    \\arrow[r, leftrightarrow, \"\\rsupfun{\\lnot}\"]\n    & \\mathfrak{I}(\\mathfrak{A}) \\arrow[d, leftrightarrow, \"\\lnot\"] \\\\\n  \\mathfrak{M}(\\mathfrak{A})\n\t\\arrow[r, leftrightarrow, \"\\rsupfun{\\lnot}\"]\n    & \\mathfrak{S}(\\mathfrak{A})\n\\end{tikzcd}\n\\end{equation}(the second diagram is defined for a boolean lattice~$\\mathfrak{A}$).\n\n\n\\subsection{Order of ideals, free stars, mixers}\n\nDefine order of ideals, free stars, mixers in such a way that the\nabove diagrams isomorphically preserve order of filters:\n\\begin{itemize}\n\\item $A\\sqsubseteq B\\Leftrightarrow A\\supseteq B$ for filters and ideals;\n\\item $A\\sqsubseteq B\\Leftrightarrow A\\subseteq B$ for free stars and mixers.\n\\end{itemize}\n\n\\subsection{Principal ideals, free stars, mixers}\n\\begin{defn}\n\\emph{Principal} ideal generated by an element~$a$ of poset~$\\mathfrak{A}$\nis $\\downarrow a=\\setcond{x\\in\\mathfrak{A}}{x\\sqsubseteq a}$.\n\\end{defn}\n\n\\begin{defn}\nAn ideal is \\emph{principal} iff it is generated by some poset element.\n\\end{defn}\n\n\\begin{defn}\nThe \\emph{filtrator of ideals} on a given poset is the pair consisting\nof the set of ideals and the set of principal ideals.\n\nThe above poset isomorphism maps principal filters into principal\nideals and thus is an isomorphism between the filtrator of filters\non a poset and the filtrator of ideals on the dual poset.\\end{defn}\n\\begin{xca}\nDefine principal free stars and mixers, filtrators of free stars and\nmixers and isomorphisms of these with the filtrator of filters (these\nisomorphisms exist because the posets of free stars and mixers are\nisomorphic to the poset of filters).\\end{xca}\n\\begin{obvious}\nThe following filtrators are primary:\n\\begin{itemize}\n\\item filtrators of filters;\n\\item filtrators of ideals;\n\\item filtrators of free stars;\n\\item filtrators of mixers.\n\\end{itemize}\n\\end{obvious}\n\n\\subsubsection{Principal free stars}\n\\begin{prop}\nAn upper set $F\\in\\subsets\\mathfrak{Z}$ is a principal filter iff\n$\\exists Z\\in F\\forall P\\in F:Z\\sqsubseteq P$.\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] Obvious.\n\\item [{$\\Leftarrow$}] Let $Z\\in F$ and $\\forall P\\in F:Z\\sqsubseteq P$.\n$F$ is nonempty because $Z\\in F$. It remains to prove that $Z\\sqsubseteq P\\Leftrightarrow P\\in F$.\nThe reverse implication follows from $\\forall P\\in F:Z\\sqsubseteq P$.\nThe direct implication follows from that $F$ is an upper set.\n\\end{description}\n\\end{proof}\n\\begin{lem}\nIf $S\\in\\subsets\\mathfrak{Z}$ is not the complement of empty set and for every $T\\in\\subsets\\mathfrak{Z}$\n\\[\n\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)\\Leftrightarrow T\\cap S\\neq\\emptyset,\n\\]\nthen $S$ is a free star.\\end{lem}\n\\begin{proof}\nTake $T=\\{A,B\\}$. Then $\\forall Z\\in\\mathfrak{Z}:(Z\\sqsupseteq A\\wedge Z\\sqsupseteq B\\Rightarrow Z\\in S)\\Leftrightarrow A\\in S\\vee B\\in S$.\nSo $S$ is a free star.\\end{proof}\n\\begin{prop}\nA set $S\\in\\subsets\\mathfrak{Z}$ is a principal free star iff $S$\nis not the complement of empty set and for every $T\\in\\subsets\\mathfrak{Z}$\n\\[\n\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)\\Leftrightarrow T\\cap S\\neq\\emptyset.\n\\]\n\\end{prop}\n\\begin{proof}\nLet $S=\\overline{\\langle\\dual\\rangle^{\\ast}F}$. We need to prove\nthat $F$ is a principal filter iff the above formula holds. Really, we have the following chain\nof equivalencies:\n\n$\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)\\Leftrightarrow T\\cap S\\neq\\emptyset$;\n\n$\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\notin\\langle\\dual\\rangle^{\\ast}F)\\Leftrightarrow T\\cap\\overline{\\langle\\dual\\rangle^{\\ast}F}\\neq\\emptyset$;\n\n$\\forall Z\\in\\dual\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsubseteq X\\Rightarrow Z\\notin F)\\Leftrightarrow T\\cap\\overline{F}\\neq\\emptyset$;\n\n$\\forall Z\\in\\dual\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsubseteq X\\Rightarrow Z\\notin F)\\Leftrightarrow T\\nsubseteq F$;\n\n$T\\subseteq F\\Leftrightarrow\\neg\\forall Z\\in\\dual\\mathfrak{Z}:(Z\\in F\\Rightarrow\\neg\\forall X\\in T:Z\\sqsubseteq X)$;\n\n$T\\subseteq F\\Leftrightarrow\\neg\\forall Z\\in\\dual\\mathfrak{Z}:(Z\\notin F\\vee\\neg\\forall X\\in T:Z\\sqsubseteq X)$;\n\n$T\\subseteq F\\Leftrightarrow\\exists Z\\in\\dual\\mathfrak{Z}:(Z\\in F\\wedge\\forall X\\in T:Z\\sqsubseteq X)$;\n\n$T\\subseteq F\\Leftrightarrow\\exists Z\\in F\\forall X\\in T:Z\\sqsubseteq X$;\n\n$\\exists Z\\in F\\forall X\\in F:Z\\sqsubseteq X$ that is $F$ is a principal\nfilter ($S$ is an upper set because by the lemma it is a free star;\nthus $F$ is also an upper set).\\end{proof}\n\\begin{prop}\n$S\\in\\subsets\\mathfrak{Z}$ where $\\mathfrak{Z}$ is a poset is a\nprincipal free star iff all the following:\n\\begin{enumerate}\n\\item \\label{princ-fs-least}The least element (if it exists) is not in\n$S$.\n\\item \\label{princ-fs-form}$\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)\\Rightarrow T\\cap S\\neq\\emptyset$\nfor every $T\\in\\subsets\\mathfrak{Z}$.\n\\item $S$ is an upper set.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] \\ref{princ-fs-least} and \\ref{princ-fs-form}\nare obvious. $S$ is an upper set because $S$ is a free star.\n\\item [{$\\Leftarrow$}] We need to prove that\n\\[\n\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)\\Leftarrow T\\cap S\\neq\\emptyset.\n\\]\nLet $X'\\in T\\cap S$. Then $\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\sqsupseteq X'\\Rightarrow Z\\in S$\nbecause $S$ is an upper set.\n\\end{description}\n\\end{proof}\n\\begin{prop}\nLet $\\mathfrak{Z}$ be a complete lattice. $S\\in\\subsets\\mathfrak{Z}$ is a principal\nfree star iff all the following:\n\\begin{enumerate}\n\\item The least element is not in $S$.\n\\item $\\bigsqcup T\\in S\\Rightarrow T\\cap S\\neq\\emptyset$ for every $T\\in\\subsets\\mathfrak{Z}$.\n\\item $S$ is an upper set.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] We need to prove only $\\bigsqcup T\\in S\\Rightarrow T\\cap S\\neq\\emptyset$.\nLet $\\bigsqcup T\\in S$. Because $S$ is an upper set, we have $\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\sqsupseteq\\bigsqcup T\\Rightarrow Z\\in S$\nfor every $Z\\in\\mathfrak{Z}$;\nfrom which we conclude $T\\cap S\\neq\\emptyset$.\n\\item [{$\\Leftarrow$}] We need to prove only $\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)\\Rightarrow T\\cap S\\neq\\emptyset$.\n\n\nReally, if $\\forall Z\\in\\mathfrak{Z}:(\\forall X\\in T:Z\\sqsupseteq X\\Rightarrow Z\\in S)$\nthen $\\bigsqcup T\\in S$ and thus $\\bigsqcup T\\in S\\Rightarrow T\\cap S\\neq\\emptyset$.\n\n\\end{description}\n\\end{proof}\n\\begin{prop}\nLet $\\mathfrak{Z}$ be a complete lattice. $S\\in\\subsets\\mathfrak{Z}$\nis a principal free star iff the least element is not\nin $S$ and for every $T\\in\\subsets\\mathfrak{Z}$\n\\[\n\\bigsqcup T\\in S\\Leftrightarrow T\\cap S\\neq\\emptyset.\n\\]\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] We need to prove only $\\bigsqcup T\\in S\\Leftarrow T\\cap S\\neq\\emptyset$\nwhat follows from that $S$ is an upper set.\n\\item [{$\\Leftarrow$}] We need to prove only that $S$ is an upper set.\nTo prove this we can use the fact that $S$ is a free star.\n\\end{description}\n\\end{proof}\n\\begin{xca}\nWrite down similar formulas for mixers.\n\\end{xca}\n\n\\subsection{Starrish posets}\n\\begin{defn}\n\\index{starrish}\\index{poset!starrish}I will call a poset \\emph{starrish}\nwhen the full star $\\fullstar a$ is a free star for every element\n$a$ of this poset.\\end{defn}\n\\begin{prop}\nEvery distributive lattice is starrish.\\end{prop}\n\\begin{proof}\nLet $\\mathfrak{A}$ be a distributive lattice, $a\\in\\mathfrak{A}$.\nObviously $\\bot\\notin\\fullstar a$ (if $\\bot$ exists); obviously\n$\\fullstar a$ is an upper set. If $x\\sqcup y\\in\\fullstar a$, then\n$(x\\sqcup y)\\sqcap a$ is non-least that is $(x\\sqcap a)\\sqcup(y\\sqcap a)$\nis non-least what is equivalent to $x\\sqcap a$ or $y\\sqcap a$ being\nnon-least that is $x\\in\\fullstar a\\lor y\\in\\fullstar a$.\\end{proof}\n\\begin{thm}\n\\label{atoms-join}If $\\mathfrak{A}$ is a starrish join-semilattice\nlattice then\n\\[\n\\atoms(a\\sqcup b)=\\atoms a\\cup\\atoms b\n\\]\nfor every $a,b\\in\\mathfrak{A}$.\\end{thm}\n\\begin{proof}\nFor every atom $c$ we have:\n\\begin{align*}\nc\\in\\atoms(a\\sqcup b) & \\Leftrightarrow\\\\\nc\\nasymp a\\sqcup b & \\Leftrightarrow\\\\\na\\sqcup b\\in\\fullstar c & \\Leftrightarrow\\\\\na\\in\\fullstar c\\lor b\\in\\fullstar c & \\Leftrightarrow\\\\\nc\\nasymp a\\lor c\\nasymp b & \\Leftrightarrow\\\\\nc\\in\\atoms a\\lor c\\in\\atoms b.\n\\end{align*}\n\n\\end{proof}\n\n\\subsubsection{Completely starrish posets}\n\\begin{defn}\n\\index{completely starrish}I will call a poset \\emph{completely starrish}\nwhen the full star $\\star a$ is a principal free star for every element\n$a$ of this poset.\\end{defn}\n\\begin{obvious}\nEvery completely starrish poset is starrish.\\end{obvious}\n\\begin{prop}\nEvery complete join infinite distributive lattice is completely starrish.\\end{prop}\n\\begin{proof}\nLet $\\mathfrak{A}$ be a join infinite distributive lattice, $a\\in\\mathfrak{A}$.\nObviously $\\bot\\notin\\fullstar a$ (if $\\bot$ exists); obviously\n$\\fullstar a$ is an upper set. If $\\bigsqcup T\\in\\fullstar a$, then\n$\\left(\\bigsqcup T\\right)\\sqcap a$ is non-least that is $\\bigsqcup\\rsupfun{a\\sqcap}T$\nis non-least what is equivalent to $a\\sqcap x$ being non-least for\nsome $x\\in T$ that is $x\\in\\fullstar a$.\\end{proof}\n\\begin{thm}\nIf $\\mathfrak{A}$ is a completely starrish complete lattice lattice\nthen\n\\[\n\\atoms\\bigsqcup T=\\bigcup\\rsupfun{\\atoms}T.\n\\]\nfor every $T\\in\\subsets\\mathfrak{A}$.\\end{thm}\n\\begin{proof}\nFor every atom $c$ we have:\n\\begin{multline*}\nc\\in\\atoms\\bigsqcup T\\Leftrightarrow c\\nasymp\\bigsqcup T\\Leftrightarrow\\bigsqcup T\\in\\fullstar c\\Leftrightarrow\\exists X\\in T:X\\in\\fullstar c\\Leftrightarrow\\\\\n\\exists X\\in T:X\\nasymp c\\Leftrightarrow\\exists X\\in T:c\\in\\atoms X\\Leftrightarrow c\\in\\bigcup\\rsupfun{\\atoms}T.\n\\end{multline*}\n\n\\end{proof}\n\n\\section{Basic properties of filters}\n\\begin{prop}\n$\\up\\mathcal{A}=\\mathcal{A}$ for every filter $\\mathcal{A}$ (provided\nthat we equate elements of the base poset~$\\mathfrak{Z}$ with corresponding\nprincipal filters.\\end{prop}\n\\begin{proof}\n$A\\in\\up\\mathcal{A}\\Leftrightarrow A\\sqsupseteq\\mathcal{A}\\Leftrightarrow\\uparrow A\\sqsupseteq\\mathcal{A}\\Leftrightarrow\\uparrow A\\subseteq\\mathcal{A}\\Leftrightarrow A\\in\\mathcal{A}$.\n\\end{proof}\n\n\\subsection{Minimal and maximal filters}\n\\begin{obvious}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator.\n\\item $\\bot^{\\mathfrak{A}}$ (equal to the principal filter for the least\nelement of $\\mathfrak{Z}$ if it exists) defined by the formula $\\up\\bot^{\\mathfrak{A}}=\\mathfrak{Z}$\nis the least element of~$\\mathfrak{A}$.\n\\end{enumerate}\n\\end{obvious}\n\\begin{prop}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator with greatest\nelement.\n\\item $\\top^{\\mathfrak{A}}$ defined by the formula $\\up\\top^{\\mathfrak{A}}=\\{\\top^{\\mathfrak{Z}}\\}$\nis the greatest element of~$\\mathfrak{A}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nTake into account that filters are nonempty.\n\\end{proof}\n\n\\subsection{Alignment}\n\\begin{defn}\n\\index{filtrator!down-aligned}I call \\emph{down-aligned} filtrator\nsuch a filtrator $(\\mathfrak{A},\\mathfrak{Z})$ that $\\mathfrak{A}$\nand $\\mathfrak{Z}$ have common least element. (Let's denote it $\\bot$.)\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!up-aligned}I call \\emph{up-aligned} filtrator such\na filtrator $(\\mathfrak{A},\\mathfrak{Z})$ that $\\mathfrak{A}$ and\n$\\mathfrak{Z}$ have common greatest element. (Let's denote it $\\top$.)\\end{defn}\n\\begin{obvious}\n\\label{filt-aligned}~\n\\begin{enumerate}\n\\item If $\\mathfrak{Z}$ has least element, the primary filtrator is down-aligned.\n\\item If $\\mathfrak{Z}$ has greatest element, the primary filtrator is\nup-aligned.\n\\end{enumerate}\n\\end{obvious}\n\\begin{cor}\nEvery powerset filtrator is both up and down-aligned.\n\\end{cor}\nWe can also define (without requirement of having least and greatest\nelements, but coinciding with the above definitions if least/greatest\nelements are present):\n\\begin{defn}\n\\index{filtrator!weakly down-aligned}I call \\emph{weakly down-aligned}\nfiltrator such a filtrator $(\\mathfrak{A},\\mathfrak{Z})$ that\nwhenever~$\\bot^{\\mathfrak{Z}}$ exists, $\\bot^{\\mathfrak{A}}$\nalso exists and $\\bot^{\\mathfrak{Z}}=\\bot^{\\mathfrak{A}}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{filtrator!weakly up-aligned}I call \\emph{weakly up-aligned}\nfiltrator such a filtrator $(\\mathfrak{A},\\mathfrak{Z})$ that\nwhenever~$\\top^{\\mathfrak{Z}}$ exists, $\\top^{\\mathfrak{A}}$\nalso exists and $\\top^{\\mathfrak{Z}}=\\top^{\\mathfrak{A}}$.\n\\end{defn}\n\n\\begin{obvious}\n~\n\\begin{enumerate}\n \\item Every up-aligned filtrator is weakly up-aligned.\n \\item Every down-aligned filtrator is weakly down-aligned.\n\\end{enumerate}\n\\end{obvious}\n\n\\begin{obvious}\\label{f-weak-down-up}\n~\n\\begin{enumerate}\n\\item Every primary filtrator is weakly down-aligned.\n\\item Every primary filtrator is weakly up-aligned.\n\\end{enumerate}\n\\end{obvious}\n\n\\section{More advanced properties of filters}\n\n\n\\subsection{Formulas for Meets and Joins of Filters}\n\\begin{lem}\n\\label{embed-lemma}If $f$ is an order embedding from a poset $\\mathfrak{A}$\nto a complete lattice $\\mathfrak{B}$ and $S\\in\\subsets\\mathfrak{A}$\nand there exists such $\\mathcal{F}\\in\\mathfrak{A}$ that $f\\mathcal{F}=\\bigsqcup^{\\mathfrak{B}}\\rsupfun fS$,\nthen $\\bigsqcup^{\\mathfrak{A}}S$ exists and $f\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{B}}\\rsupfun fS$.\\end{lem}\n\\begin{proof}\n$f$ is an order isomorphism from $\\mathfrak{A}$ to $\\mathfrak{B}|_{\\rsupfun f\\mathfrak{A}}$.\n$f\\mathcal{F}\\in\\mathfrak{B}|_{\\rsupfun f\\mathfrak{A}}$.\n\nConsequently, $\\bigsqcup^{\\mathfrak{B}}\\rsupfun fS\\in\\mathfrak{B}|_{\\rsupfun f\\mathfrak{A}}$\nand $\\bigsqcup^{\\mathfrak{B}|_{\\rsupfun f\\mathfrak{A}}}\\rsupfun fS=\\bigsqcup^{\\mathfrak{B}}\\rsupfun fS$.\n\n$f\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{B}|_{\\rsupfun f\\mathfrak{A}}}\\rsupfun fS$\nbecause $f$ is an order isomorphism.\n\nCombining, $f\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{B}}\\rsupfun fS$.\\end{proof}\n\\begin{cor}\nIf $\\mathfrak{B}$ is a complete lattice and $\\mathfrak{A}$ is its\nsubset and $S\\in\\subsets\\mathfrak{A}$ and $\\bigsqcup^{\\mathfrak{B}}S\\in\\mathfrak{A}$,\nthen $\\bigsqcup^{\\mathfrak{A}}S$\nexists and $\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{B}}S$.\\end{cor}\n\n\\begin{xca}\nThe below theorem does not work for $S=\\emptyset$. Formulate the general case.\n\\end{xca}\n\n\\begin{thm}\\label{join-filt-gen}\n~\n\\begin{enumerate}\n\\item \\label{inf-lat-filt-b} If $\\mathfrak{Z}$ is a meet-semilattice, then $\\bigsqcup^{\\mathfrak{F}(\\mathfrak{Z})}S$\nexists and $\\bigsqcup^{\\mathfrak{F}(\\mathfrak{Z})}S=\\bigcap S$ for every bounded above set~$S\\in\\subsets\\mathfrak{F}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$.\n\\item \\label{inf-lat-ideal-b} If $\\mathfrak{Z}$ is a join-semilattice, then $\\bigsqcap^{\\mathfrak{I}(\\mathfrak{Z})}S$ exists\nand $\\bigsqcap^{\\mathfrak{I}(\\mathfrak{Z})}S=\\bigcap S$ for for every bounded below set~$S\\in\\subsets\\mathfrak{I}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [\\ref{inf-lat-filt-b}] Taking into account the lemma, it is enough\nto prove that $\\bigcap S$ is a filter.\nLet's prove that $\\bigcap S$ is nonempty.\nThere is an upper bound~$\\mathcal{T}$ of~$S$. Take arbitrary\n$T\\in\\mathcal{T}$. We have $T\\in\\mathcal{X}$ for\nevery~$\\mathcal{X}\\in S$. Thus~$S$ is nonempty.\n\nFor every $A,B\\in\\mathfrak{Z}$ we have:\n\\[\nA,B\\in\\bigcap S\\Leftrightarrow\\forall P\\in S:A,B\\in P\\Leftrightarrow\\forall P\\in S:A\\sqcap B\\in P\\Leftrightarrow A\\sqcap B\\in\\bigcap S.\n\\]\nSo $\\bigcap S$ is a filter.\n\\item [\\ref{inf-lat-ideal-b}] By duality.\n\\end{widedisorder}\n\\end{proof}\n\n\\begin{thm}\n~\n\\begin{enumerate}\n\\item \\label{inf-lat-filt}If $\\mathfrak{Z}$ is a meet-semilattice with\ngreatest element, then $\\bigsqcup^{\\mathfrak{F}(\\mathfrak{Z})}S$\nexists and $\\bigsqcup^{\\mathfrak{F}(\\mathfrak{Z})}S=\\bigcap S$ for\nevery $S\\in\\subsets\\mathfrak{F}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$.\n\\item \\label{inf-lat-ideal}If $\\mathfrak{Z}$ is a join-semilattice with\nleast element, then $\\bigsqcap^{\\mathfrak{I}(\\mathfrak{Z})}S$ exists\nand $\\bigsqcap^{\\mathfrak{I}(\\mathfrak{Z})}S=\\bigcap S$ for every\n$S\\in\\subsets\\mathfrak{I}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$.\n\\item \\label{inf-lat-fs}If $\\mathfrak{Z}$ is a join-semilattice with least\nelement, then $\\bigsqcup^{\\mathfrak{S}(\\mathfrak{Z})}S$ exists and\n$\\bigsqcup^{\\mathfrak{S}(\\mathfrak{Z})}S=\\bigcup S$ for every $S\\in\\subsets\\mathfrak{S}(\\mathfrak{Z})$.\n\\item \\label{inf-lat-mix}If $\\mathfrak{Z}$ is a meet-semilattice with\ngreatest element, then $\\bigsqcap^{\\mathfrak{M}(\\mathfrak{Z})}S$\nexists and $\\bigsqcap^{\\mathfrak{M}(\\mathfrak{Z})}S=\\bigcup S$ for\nevery $S\\in\\subsets\\mathfrak{M}(\\mathfrak{Z})$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{inf-lat-filt}}] From the previous theorem.\n\\item [{\\ref{inf-lat-ideal}}] By duality.\n\\item [{\\ref{inf-lat-fs}}] Taking into account the lemma, it is enough\nto prove that $\\bigcup S$ is a free star. $\\bigcup S$ is not the\ncomplement of empty set because $\\bot\\notin\\bigcup S$. For every\n$A,B\\in\\mathfrak{Z}$ we have:\n\\begin{multline*}\nA\\in\\bigcup S\\lor B\\in\\bigcup S\\Leftrightarrow\\exists P\\in S:(A\\in P\\lor B\\in P)\\Leftrightarrow\\\\\n\\exists P\\in S:A\\sqcup B\\in P\\Leftrightarrow A\\sqcup B\\in\\bigcup S.\n\\end{multline*}\n\n\\item [{\\ref{inf-lat-mix}}] By duality.\n\\end{widedisorder}\n\\end{proof}\n\\begin{cor}\n\\label{f-join-form}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{f-join-form-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{f-join-form-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a meet-semilattice with greatest element~$\\top$.\n\\item \\label{f-join-form-conc}$\\bigsqcup^{\\mathfrak{A}}S$ exists and $\\up\\bigsqcup^{\\mathfrak{A}}S=\\bigcap\\rsupfun{\\up}S$\nfor every $S\\in\\subsets\\mathfrak{A}\\setminus\\{\\emptyset\\}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{f-join-form-p}$\\Rightarrow$\\ref{f-join-form-fltr}}] Obvious.\n\\item [{\\ref{f-join-form-fltr}$\\Rightarrow$\\ref{f-join-form-conc}}] By\nthe theorem.\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{filt-is-complete}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a meet-semilattice\nwith greatest element~$\\top$.\n\\item $\\mathfrak{A}$ is a complete lattice.\n\\end{enumerate}\n\\end{cor}\n\nWe will denote meets and joins on the lattice of filters just as~$\\sqcap$ and~$\\sqcup$.\n\\begin{prop}\\label{filt-meet-form}\nThe following is an implications tuple:\n\\begin{enumerate}\n  \\item\\label{fjoin-ex-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n  \\item\\label{fjoin-ex-flt}  $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\n    over an ideal base.\n  \\item\\label{fjoin-ex-res}  $\\mathfrak{A}$ is a join-semilattice and for\n    any $\\mathcal{A},\\mathcal{B}\\in\\mathfrak{A}$\n\\[\n\\up(\\mathcal{A}\\sqcup^{\\mathfrak{A}}\\mathcal{B})=\\up\\mathcal{A}\\cap\\up\\mathcal{B}.\n\\]\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item[\\ref{fjoin-ex-pow}$\\Rightarrow$\\ref{fjoin-ex-flt}]\n  Obvious.\n\\item[\\ref{fjoin-ex-flt}$\\Rightarrow$\\ref{fjoin-ex-res}]\n  Taking in account the lemma it is enough to prove that $R = \\up\n  \\mathcal{A} \\cap \\up \\mathcal{B}$ is a filter.\n\n  $R$ is nonempty because we can take $X \\in \\up \\mathcal{A}$ and $Y \\in\n  \\up \\mathcal{B}$ and $Z\\sqsupseteq X\\land Z\\sqsupseteq Y$ and then $R \\ni Z$.\n\n  Let $A, B \\in R$. Then $A, B \\in \\up \\mathcal{A}$; so exists $C \\in\n  \\up \\mathcal{A}$ such that $C \\sqsubseteq A \\land C \\sqsubseteq B$.\n  Analogously exists $D \\in \\up \\mathcal{B}$ such that $D \\sqsubseteq A \\land\n  D \\sqsubseteq B$. Take $E\\sqsupseteq C\\land E\\sqsupseteq D$. Then $E \\in \\up\n  \\mathcal{A}$ and $E \\in \\up \\mathcal{B}$; $E \\in R$ and $E \\sqsubseteq A \\land\n  E \\sqsubseteq B$. So $R$ is a filter base.\n\n  That $R$ is an upper set is obvious.\n\\end{widedisorder}\n\\end{proof}\n\n\\begin{thm}\\label{distr-meet}\nLet $\\mathfrak{Z}$ be a distributive lattice. Then\n\\begin{enumerate}\n\\item $\\bigsqcap^{\\mathfrak{F}(\\mathfrak{Z})}S=\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nfor $S\\in\\subsets\\mathfrak{F}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$;\n\\item $\\bigsqcup^{\\mathfrak{I}(\\mathfrak{Z})}S=\\setcond{K_{0}\\sqcup^{\\mathfrak{Z}}\\dots\\sqcup^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nfor $S\\in\\subsets\\mathfrak{I}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only the first, as the second is dual.\n\nLet's denote the right part of the equality to be proven as $R$.\nFirst we will prove that $R$ is a filter. $R$ is nonempty because\n$S$ is nonempty.\n\nLet $A,B\\in R$. Then $A=X_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}X_{k}$,\n$B=Y_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}Y_{l}$ where\n$X_{i},Y_{j}\\in\\bigcup S$. So\n\\[\nA\\sqcap^{\\mathfrak{Z}}B=X_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}X_{k}\\sqcap^{\\mathfrak{Z}}Y_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}Y_{l}\\in R.\n\\]\n\n\n\nLet element $C\\sqsupseteq A\\in R$. Consequently (distributivity used)\n\\[\nC=C\\sqcup^{\\mathfrak{Z}}A=(C\\sqcup^{\\mathfrak{Z}}X_{0})\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}(C\\sqcup^{\\mathfrak{Z}}X_{k}).\n\\]\n\n\n\n$X_{i}\\in P_{i}$ for some $P_{i}\\in S$; $C\\sqcup^{\\mathfrak{Z}}X_{i}\\in P_{i}$;\n$C\\sqcup^{\\mathfrak{Z}}X_{i}\\in\\bigcup S$; consequently $C\\in R$.\n\n\nWe have proved that that $R$ is a filter base and an upper set. So\n$R$ is a filter.\n\n\nLet $\\mathcal{A}\\in S$. Then $\\mathcal{A}\\subseteq\\bigcup S$;\n\\[\nR\\supseteq\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\mathcal{A}\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}=\\mathcal{A}.\n\\]\n\n\n\nConsequently $\\mathcal{A}\\sqsupseteq R$.\n\n\nLet now $\\mathcal{B}\\in\\mathfrak{A}$ and $\\forall\\mathcal{A}\\in S:\\mathcal{A}\\sqsupseteq\\mathcal{B}$.\nThen $\\forall\\mathcal{A}\\in S:\\mathcal{A}\\subseteq\\mathcal{B}$; $\\mathcal{B}\\supseteq\\bigcup S$.\nThus $\\mathcal{B}\\supseteq T$ for every finite set $T\\subseteq\\bigcup S$.\nConsequently $\\up\\mathcal{B}\\ni\\bigsqcap^{\\mathfrak{Z}}T$. Thus $\\mathcal{B}\\supseteq R$;\n$\\mathcal{B}\\sqsubseteq R$.\n\n\nComparing we get $\\bigsqcap^{\\mathfrak{F}(\\mathfrak{Z})}S=R$.\n\n\\end{proof}\n\\begin{cor}\n\\label{f-inf-meet-form}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{inf-meet-form-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{inf-meet-form-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a distributive lattice.\n\\item \\label{inf-meet-form-conc}$\\up\\bigsqcap^{\\mathfrak{A}}S=\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nfor $S\\in\\subsets\\mathfrak{A}\\setminus\\{\\emptyset\\}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{inf-meet-form-p}$\\Rightarrow$\\ref{inf-meet-form-fltr}}] Obvious.\n\\item [{\\ref{inf-meet-form-fltr}$\\Rightarrow$\\ref{inf-meet-form-conc}}] By\nthe theorem.\n\\end{description}\n\\end{proof}\n\\begin{thm}\nLet $\\mathfrak{Z}$ be a distributive lattice. Then:\n\\begin{enumerate}\n\\item $\\mathcal{F}_{0}\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\dots\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\mathcal{F}_{m}=\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{m}}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nfor any $\\mathcal{F}_{0},\\dots,\\mathcal{F}_{m}\\in\\mathfrak{F}(\\mathfrak{Z})$;\n\\item $\\mathcal{F}_{0}\\sqcup^{\\mathfrak{I}(\\mathfrak{Z})}\\dots\\sqcup^{\\mathfrak{I}(\\mathfrak{Z})}\\mathcal{F}_{m}=\\setcond{K_{0}\\sqcup^{\\mathfrak{Z}}\\dots\\sqcup^{\\mathfrak{Z}}K_{m}}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nfor any $\\mathcal{F}_{0},\\dots,\\mathcal{F}_{m}\\in\\mathfrak{I}(\\mathfrak{Z})$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\nLet's denote the right part of the equality to be proven as $R$.\nFirst we will prove that $R$ is a filter. Obviously $R$ is nonempty.\n\nLet $A,B\\in R$. Then $A=X_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}X_{m}$,\n$B=Y_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}Y_{m}$ where\n$X_{i},Y_{i}\\in\\mathcal{F}_{i}$.\n\\[\nA\\sqcap^{\\mathfrak{Z}}B=(X_{0}\\sqcap^{\\mathfrak{Z}}Y_{0})\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}(X_{m}\\sqcap^{\\mathfrak{Z}}Y_{m}),\n\\]\n\n\nconsequently $A\\sqcap^{\\mathfrak{Z}}B\\in R$.\n\nLet filter $C\\sqsupseteq A\\in R$\n\\[\nC=A\\sqcup^{\\mathfrak{Z}}C=(X_{0}\\sqcup^{\\mathfrak{Z}}C)\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}(X_{m}\\sqcup^{\\mathfrak{Z}}C)\\in R.\n\\]\n\n\nSo $R$ is a filter.\n\nLet $P_{i}\\in\\mathcal{F}_{i}$. Then $P_{i}\\in R$ because $P_{i}=(P_{i}\\sqcup^{\\mathfrak{Z}}P_{0})\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}(P_{i}\\sqcup^{\\mathfrak{Z}}P_{m})$.\nSo $\\mathcal{F}_{i}\\subseteq R$; $\\mathcal{F}_{i}\\sqsupseteq R$.\n\nLet now $\\mathcal{B}\\in\\mathfrak{A}$ and $\\forall i\\in\\{0,\\dots,m\\}:\\mathcal{F}_{i}\\sqsupseteq\\mathcal{B}$.\nThen $\\forall i\\in\\{0,\\dots,m\\}:\\mathcal{F}_{i}\\subseteq\\mathcal{B}$.\n\nLet $L_{i}\\in\\mathcal{B}$ for every $L_{i}\\in\\mathcal{F}_{i}$. $L_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}L_{m}\\in\\mathcal{B}$.\nSo $\\mathcal{B}\\supseteq R$; $\\mathcal{B}\\sqsubseteq R$.\n\nSo $\\mathcal{F}_{0}\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\dots\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\mathcal{F}_{m}=R$.\\end{proof}\n\\begin{cor}\n\\label{f-fin-filt-meet}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{f-fin-filt-meet-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{fin-filt-meet-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a distributive lattice.\n\\item \\label{fin-filt-meet-conc}$\\up(\\mathcal{F}_{0}\\sqcap^{\\mathfrak{A}}\\dots\\sqcap^{\\mathfrak{A}}\\mathcal{F}_{m})=\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{m}}{K_{i}\\in\\up\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nfor any $\\mathcal{F}_{0},\\dots,\\mathcal{F}_{m}\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{f-fin-filt-meet-p}$\\Rightarrow$\\ref{fin-filt-meet-fltr}}] Obvious.\n\\item [{\\ref{fin-filt-meet-fltr}$\\Rightarrow$\\ref{fin-filt-meet-conc}}] By\nthe theorem.\n\\end{description}\n\\end{proof}\nMore general case of semilattices follows:\n\\begin{thm}\\label{meet-prim-mlat}\n~\n\\begin{enumerate}\n\\item $\\bigsqcap^{\\mathfrak{F}(\\mathfrak{Z})}S=\\bigcup\\setcond{\\uparrow(K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n})}{K_{i}\\in\\bigcup S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nfor $S\\in\\subsets\\mathfrak{F}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$\nif $\\mathfrak{Z}$ is a meet-semilattice;\n\\item $\\bigsqcup^{\\mathfrak{I}(\\mathfrak{Z})}S=\\bigcup\\setcond{\\uparrow(K_{0}\\sqcup^{\\mathfrak{Z}}\\dots\\sqcup^{\\mathfrak{Z}}K_{n})}{K_{i}\\in\\bigcup S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nfor $S\\in\\subsets\\mathfrak{I}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$\nif $\\mathfrak{Z}$ is a join-semilattice.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\nIt follows from the fact that\n\\[\n\\bigsqcap^{\\mathfrak{F}(\\mathfrak{Z})}S=\\bigsqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}\n\\]\nand that $\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nis a filter base.\\end{proof}\n\\begin{cor}\n\\label{meet-filtx}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a meet-semilattice.\n\\item $\\up\\bigsqcap S=\\bigcup\\setcond{\\up(K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n})}{K_{i}\\in\\bigcup\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}}$\nfor every $S\\in\\subsets\\mathfrak{A}\\setminus\\{\\emptyset\\}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{thm}\n~\n\\begin{enumerate}\n\\item $\\mathcal{F}_{0}\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\dots\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\mathcal{F}_{m}=\\bigcup\\setcond{\\uparrow(K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{m})}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nfor $S\\in\\subsets\\mathfrak{F}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$\nif $\\mathfrak{Z}$ is a meet-semilattice;\n\\item $\\mathcal{F}_{0}\\sqcup^{\\mathfrak{I}(\\mathfrak{Z})}\\dots\\sqcup^{\\mathfrak{I}(\\mathfrak{Z})}\\mathcal{F}_{m}=\\bigcup\\setcond{\\uparrow(K_{0}\\sqcup^{\\mathfrak{Z}}\\dots\\sqcup^{\\mathfrak{Z}}K_{m})}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nfor $S\\in\\subsets\\mathfrak{I}(\\mathfrak{Z})\\setminus\\{\\emptyset\\}$\nif $\\mathfrak{Z}$ is a join-semilattice.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\nIt follows from the fact that\n\\[\n\\mathcal{F}_{0}\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\dots\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\mathcal{F}_{m}=\n\\bigsqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{m}}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}\n\\]\nand that $\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{m}}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nis a filter base.\\end{proof}\n\\begin{cor}\n$\\up(\\mathcal{F}_{0}\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\dots\\sqcap^{\\mathfrak{F}(\\mathfrak{Z})}\\mathcal{F}_{m})=\\bigcup\\setcond{\\up(K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{m})}{K_{i}\\in\\mathcal{F}_{i}\\text{ where }i=0,\\dots,m}$\nif $\\mathfrak{Z}$ is a meet-semilattice.\n\\end{cor}\n\n\\begin{lem}\nIf $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nand~$\\mathfrak{Z}$ is a meet-semilattice and an ideal base,\nthen~$\\mathfrak{A}$ is a lattice.\n\\end{lem}\n\n\\begin{proof}\nIt is a join-semilattice by proposition~\\ref{filt-meet-form}. It is a meet-semilattice by theorem~\\ref{meet-prim-mlat}.\n\\end{proof}\n\n\\begin{cor}\\label{f-is-distr}\nIf $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nand~$\\mathfrak{Z}$ is a lattice,\nthen~$\\mathfrak{A}$ is a lattice.\n\\end{cor}\n\n\\subsection{Distributivity of the Lattice of Filters}\n\\begin{thm}\n\\label{f-inf-assc}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{inf-assc-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{inf-assc-prim}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a distributive lattice.\n\\item \\label{inf-assc-conc}$\\mathcal{A}\\sqcup^{\\mathfrak{A}}\\bigsqcap^{\\mathfrak{A}}S=\\bigsqcap^{\\mathfrak{A}}\\rsupfun{\\mathcal{A}\\sqcup^{\\mathfrak{A}}}S$\nfor $S\\in\\subsets\\mathfrak{A}$ and $\\mathcal{A}\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{inf-assc-p}$\\Rightarrow$\\ref{inf-assc-prim}}] Obvious.\n\\item [{\\ref{inf-assc-prim}$\\Rightarrow$\\ref{inf-assc-conc}}] Taking\ninto account the previous section, we have:\n\\begin{align*}\n\\up\\left(\\mathcal{A}\\sqcup^{\\mathfrak{A}}\\bigsqcap^{\\mathfrak{A}}S\\right) & =\\\\\n\\up\\mathcal{A}\\cap\\up\\bigsqcap^{\\mathfrak{A}}S & =\\\\\n\\up\\mathcal{A}\\cap\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}\\in\\up\\mathcal{A},K_{i}\\in\\bigcup\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\up\\mathcal{A},K_{i}\\in\\bigcup\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\up\\mathcal{A}\\cap\\bigcup\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup\\rsupfun{\\up\\mathcal{A}\\cap}\\rsupfun{\\up}S\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup\\setcond{\\up\\mathcal{A}\\cap\\up\\mathcal{X}}{\\mathcal{X}\\in S}\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\setcond{K_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}K_{n}}{K_{i}\\in\\bigcup\\setcond{\\up(\\mathcal{A}\\sqcup^{\\mathfrak{A}}\\mathcal{X})}{\\mathcal{X}\\in S}\\text{ where }i=0,\\dots,n\\text{ for }n\\in\\mathbb{N}} & =\\\\\n\\up\\bigsqcap^{\\mathfrak{A}}\\setcond{\\mathcal{A}\\sqcup^{\\mathfrak{A}}\\mathcal{X}}{\\mathcal{X}\\in S} & =\\\\\n\\up\\bigsqcap^{\\mathfrak{A}}\\rsupfun{\\mathcal{A}\\sqcup^{\\mathfrak{A}}}S.\n\\end{align*}\n\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{filt-also-distr}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a distributive\nlattice which is an ideal base.\n\\item $\\mathfrak{A}$ is a distributive and co-brouwerian lattice.\n\\end{enumerate}\n\\end{cor}\n\n\\begin{cor}\\label{filt-co-frame}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a distributive lattice with greatest element.\n\\item $\\mathfrak{A}$ is a co-frame.\n\\end{enumerate}\n\\end{cor}\n\nThe below theorem uses the notation and results from section~\\ref{some-frames}.\n\\begin{thm}\n\\label{frame-main}If $\\mathfrak{A}$ is a co-frame and~$L$ is a\nbounded distributive lattice which,\nthen $\\operatorname{Join}(L,\\mathfrak{A})$\nis also a co-frame.\n\\end{thm}\n\\begin{proof}\nLet $F=\\uparrow\\circ\\bigsqcap:\\Upper(\\mathfrak{A})\\rightarrow\\Upper(\\mathfrak{A})$;\n$F$ is a co-nucleus by above.\n\nSince $\\Upper(\\mathfrak{A})\\cong\\mathbf{Pos}(\\mathfrak{A},2)$ by\nproposition \\ref{down-is-homo}, we may regard $F$ as a co-nucleus\non $\\mathbf{Pos}(\\mathfrak{A},2)$.\n\n$\\operatorname{Join}(L,\\mathfrak{A})\\cong\\operatorname{Join}(L,\\Fix(F))$\nby corollary \\ref{down-meet-co-nucleus}.\n\n$\\operatorname{Join}(L,\\Fix(F))\\cong\\Fix(\\operatorname{Join}(L,F))$\nby lemma \\ref{join-fix-inter}.\n\nBy corollary \\ref{join-map-co-nucleus} the function $\\operatorname{Join}(L,F)$\nis a co-nucleus on $\\operatorname{Join}\\left(L,\\mathbf{Pos}(\\mathfrak{A},2)\\right)$.\n\\begin{eqnarray*}\n\\operatorname{Join}\\left(L,\\mathbf{Pos}(\\mathfrak{A},2)\\right) & \\cong & \\text{(by lemma \\ref{join-pos-interch})}\\\\\n\\mathbf{Pos}(\\mathfrak{A},\\operatorname{Join}(L,2)) & \\cong\\\\\n\\mathbf{Pos}(\\mathfrak{A},\\mathfrak{F}(X)).\n\\end{eqnarray*}\n$\\mathfrak{F}(X)$ is a co-frame by corollary~\\ref{filt-co-frame}. Thus\n$\\mathbf{Pos}(\\mathfrak{A},\\mathfrak{F}(X))$ is a co-frame by lemma~\\ref{join-pos-interch}.\n\nThus $\\operatorname{Join}(L,\\mathfrak{A})$ is isomorphic to a poset\nof fixed points of a co-nucleus on the co-frame $\\mathbf{Pos}(\\mathfrak{A},\\mathfrak{F}(X))$.\nBy lemma \\ref{fix-is-co-frame} $\\operatorname{Join}(L,\\mathfrak{A})$\nis also a co-frame.\n\\end{proof}\n\n\\section{Misc filtrator properties}\n\\begin{thm}\n\\label{semifilt-joinclosed}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{semifilt-joinclosed-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a\npowerset filtrator.\n\\item \\label{semifilt-joinclosed-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a\nprimary filtrator.\n\\item \\label{semifilt-joinclosed-sfit}$(\\mathfrak{A},\\mathfrak{Z})$ is\na filtered filtrator.\n\\item \\label{semifilt-joinclosed-conc}$(\\mathfrak{A},\\mathfrak{Z})$ is\na filtrator with join-closed core.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{semifilt-joinclosed-p}$\\Rightarrow$\\ref{semifilt-joinclosed-f}}] Obvious.\n\\item [{\\ref{semifilt-joinclosed-f}$\\Rightarrow$\\ref{semifilt-joinclosed-sfit}}] The formula\n$\\forall a,b\\in\\mathfrak{A}:(\\up a\\supseteq\\up b\\Rightarrow a\\sqsubseteq b)$ is obvious for primary filtrators.\n\\item [{\\ref{semifilt-joinclosed-sfit}$\\Rightarrow$\\ref{semifilt-joinclosed-conc}}] Let\n$(\\mathfrak{A},\\mathfrak{Z})$ be a filtered filtrator. Let $S\\in\\subsets\\mathfrak{Z}$\nand $\\bigsqcup^{\\mathfrak{Z}}S$ be defined. We need to prove $\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{Z}}S$.\nThat $\\bigsqcup^{\\mathfrak{Z}}S$ is an upper bound for $S$ is obvious.\nLet $a\\in\\mathfrak{A}$ be an upper bound for $S$. It's enough to\nprove that $\\bigsqcup^{\\mathfrak{Z}}S\\sqsubseteq a$. Really,\n\\[\nc\\in\\up a\\Rightarrow c\\sqsupseteq a\\Rightarrow\\forall x\\in S:c\\sqsupseteq x\\Rightarrow c\\sqsupseteq\\bigsqcup^{\\mathfrak{Z}}S\\Rightarrow c\\in\\up\\bigsqcup^{\\mathfrak{Z}}S;\n\\]\nso $\\up a\\subseteq\\up\\bigsqcup^{\\mathfrak{Z}}S$ and thus $a\\sqsupseteq\\bigsqcup^{\\mathfrak{Z}}S$\nbecause it is filtered.\n\\end{description}\n\\end{proof}\n\n\\section{Characterization of Binarily Meet-Closed Filtrators}\n\\begin{thm}\n\\label{up-filt-crit}The following are equivalent for a filtrator\n$(\\mathfrak{A},\\mathfrak{Z})$ whose core is a meet semilattice such\nthat $\\forall a\\in\\mathfrak{A}:\\up a\\ne\\emptyset$:\n\\begin{enumerate}\n\\item \\label{mcl-crit}The filtrator is with binarily meet-closed core.\n\\item \\label{mcl-up}$\\up a$ is a filter for every $a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{mcl-crit}$\\Rightarrow$\\ref{mcl-up}}] Let $X,Y\\in\\up a$.\nThen $X\\sqcap^{\\mathfrak{Z}}Y=X\\sqcap^{\\mathfrak{A}}Y\\sqsupseteq a$.\nThat $\\up a$ is an upper set is obvious. So taking into account that\n$\\up a\\ne\\emptyset$, $\\up a$ is a filter.\n\\item [{\\ref{mcl-up}$\\Rightarrow$\\ref{mcl-crit}}] It is enough to prove\nthat $a\\sqsubseteq A,B\\Rightarrow a\\sqsubseteq A\\sqcap^{\\mathfrak{Z}}B$\nfor every $A,B\\in\\mathfrak{A}$. Really:\n\\[\na\\sqsubseteq A,B\\Rightarrow A,B\\in\\up a\\Rightarrow A\\sqcap^{\\mathfrak{Z}}B\\in\\up a\\Rightarrow a\\sqsubseteq A\\sqcap^{\\mathfrak{Z}}B.\n\\]\n\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{f-meet-closed}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{f-meet-closed-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{f-meet-closed-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a meet semilattice.\n\\item \\label{f-meet-closed-conc}$(\\mathfrak{A},\\mathfrak{Z})$ is with\nbinarily meet-closed core.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{f-meet-closed-p}$\\Rightarrow$\\ref{f-meet-closed-fltr}}] Obvious.\n\\item [{\\ref{f-meet-closed-fltr}$\\Rightarrow$\\ref{f-meet-closed-conc}}] From\nthe theorem.\n\\end{description}\n\\end{proof}\n\n\\subsection{Separability of Core for Primary Filtrators}\n\n\\begin{thm}\\label{when-sep-core}\n\\begin{enumerate}\nThe following is an implications tuple:\n\\item \\label{when-sep-core-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{when-sep-core-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a meet semilattice with least element.\n\\item \\label{when-sep-core-conc}$(\\mathfrak{A},\\mathfrak{Z})$ is with\nseparable core.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{when-sep-core-p}$\\Rightarrow$\\ref{when-sep-core-fltr}}] Obvious.\n\\item [{\\ref{when-sep-core-fltr}$\\Rightarrow$\\ref{when-sep-core-conc}}] Let\n$\\mathcal{A}\\asymp^{\\mathfrak{A}}\\mathcal{B}$ where $\\mathcal{A},\\mathcal{B}\\in\\mathfrak{A}$.\n\\[\n\\up(\\mathcal{A}\\sqcap^{\\mathfrak{A}}\\mathcal{B})=\\bigcup\\setcond{\\up(A\\sqcap^{\\mathfrak{Z}}B)}{A\\in\\up\\mathcal{A},B\\in\\up\\mathcal{B}}.\n\\]\nSo\n\\begin{align*}\n\\bot\\in\\up(\\mathcal{A}\\sqcap^{\\mathfrak{A}}\\mathcal{B}) & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A},B\\in\\up\\mathcal{B}:\\bot\\in\\up(A\\sqcap^{\\mathfrak{Z}}B) & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A},B\\in\\up\\mathcal{B}:A\\sqcap^{\\mathfrak{Z}}B=\\bot & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A},B\\in\\up\\mathcal{B}:A\\sqcap^{\\mathfrak{A}}B=\\bot^{\\mathfrak{A}}\n\\end{align*}\n(used proposition \\ref{f-meet-closed}).\n\\end{description}\n\\end{proof}\n\n\\section{Core Part}\nLet $(\\mathfrak{A},\\mathfrak{Z})$ be a filtrator.\n\\begin{defn}\n\\index{core part}The \\emph{core part} of an element $a\\in\\mathfrak{A}$\nis $\\Cor a=\\bigsqcap^{\\mathfrak{Z}}\\up a$.\n\\end{defn}\n\n\\begin{defn}\n\\index{core part!dual}The \\emph{dual core part} of an element $a\\in\\mathfrak{A}$\nis $\\Cor'a=\\bigsqcup^{\\mathfrak{Z}}\\down a$.\\end{defn}\n\\begin{obvious}\n$\\Cor'$ is dual of $\\Cor$.\n\\end{obvious}\n\n\\begin{obvious}\n$\\Cor a=\\Cor'a=a$ for every element $a$ of the core of a filtrator.\\end{obvious}\n\\begin{thm}\n\\label{cor-less}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{cor-less-p}$a$ is a filter on a set.\n\\item \\label{cor-less-fcomp}$a$ is a filter on a complete lattice.\n\\item \\label{cor-less-flt}$a$ is an element of a filtered filtrator and\n$\\Cor a$ exists.\n\\item \\label{cor-less-conc}$\\Cor a\\sqsubseteq a$ and $\\Cor a\\in\\down a$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cor-less-p}$\\Rightarrow$\\ref{cor-less-fcomp}}] Obvious.\n\\item [{\\ref{cor-less-fcomp}$\\Rightarrow$\\ref{cor-less-flt}}] Theorem~\\ref{semifilt-joinclosed}.\n\\item [{\\ref{cor-less-flt}$\\Rightarrow$\\ref{cor-less-conc}}] $\\Cor a=\\bigsqcap^{\\mathfrak{Z}}\\up a\\sqsubseteq\\bigsqcap^{\\mathfrak{A}}\\up a=a$.\nThen obviously $\\Cor a\\in\\down a$.\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{f-cor-max}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{cor'a-le-p}$a$ is a filter on a set.\n\\item \\label{cor'a-le-fltr}$a$ is a filter on a complete lattice.\n\\item \\label{cor'a-le-a-jce}$a$ is an element $a$ of a filtrator with\njoin-closed core and $\\Cor'a$ exists.\n\\item \\label{cor'a-le-a}$\\Cor'a\\sqsubseteq a$ and $\\Cor'a\\in\\down a$\nand $\\Cor'a=\\max\\down a$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cor'a-le-p}$\\Rightarrow$\\ref{cor'a-le-fltr}}] Obvious.\n\\item [{\\ref{cor'a-le-fltr}$\\Rightarrow$\\ref{cor'a-le-a-jce}}] It is\njoin closed by \\ref{semifilt-joinclosed}. $\\Cor'a$ exists because\nour filtrator is join-closed.\n\\item [{\\ref{cor'a-le-a-jce}$\\Rightarrow$\\ref{cor'a-le-a}}] $\\Cor'a=\\bigsqcup^{\\mathfrak{Z}}\\down a=\\bigsqcup^{\\mathfrak{A}}\\down a\\sqsubseteq a$.\nNow $\\Cor'a\\in\\down a$ is obvious. Thus $\\Cor'a=\\max\\down a$.\n\\end{description}\n\\end{proof}\n\\begin{prop}\n$\\Cor'a\\sqsubseteq\\Cor a$ whenever both $\\Cor a$ and $\\Cor'a$ exist\nfor any element $a$ of a filtrator with join-closed core.\\end{prop}\n\\begin{proof}\n$\\Cor a=\\bigsqcap^{\\mathfrak{Z}}\\up a\\sqsupseteq\\Cor'a$ because $\\forall A\\in\\up a:\\Cor'a\\sqsubseteq A$.\\end{proof}\n\\begin{thm}\n\\label{cor-eq}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{cor-eq-pow}$a$ is a filter on a set.\n\\item \\label{cor-eq-mlat}$a$ is a filter on a complete lattice.\n\\item \\label{cor-eq-filt}$a$ is an element of a filtered filtrator and\nboth $\\Cor a$ and $\\Cor'a$ exist.\n\\item \\label{cor-eq-conc}$\\Cor'a=\\Cor a$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cor-eq-pow}$\\Rightarrow$\\ref{cor-eq-mlat}}] Obvious.\n\\item [{\\ref{cor-eq-mlat}$\\Rightarrow$\\ref{cor-eq-filt}}] By theorem~\\ref{semifilt-joinclosed}.\n\\item [{\\ref{cor-eq-filt}$\\Rightarrow$\\ref{cor-eq-conc}}] It is with\njoin-closed core because it is filtered. So $\\Cor'a\\sqsubseteq\\Cor a$.\n$\\Cor a\\in\\down a$. So $\\Cor a\\sqsubseteq\\bigsqcup^{\\mathfrak{Z}}\\down a=\\Cor'a$.\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{dcor-eq-cor}$\\Cor'a=\\Cor a=\\bigcap a$ for every filter $a$\non a set.\n\\end{cor}\n\n\\section{Intersection and Joining with an Element of the Core}\n\n\\begin{defn}\n  A filtrator $(\\mathfrak{A}; \\mathfrak{Z})$ is with \\emph{correct\n  intersection} iff $\\forall a, b \\in \\mathfrak{Z}: (a \\nasymp^{\\mathfrak{Z}}\n  b \\Leftrightarrow a \\nasymp^{\\mathfrak{A}} b)$.\n\\end{defn}\n\n\\begin{defn}\n  A filtrator $(\\mathfrak{A}; \\mathfrak{Z})$ is with \\emph{correct\n  joining} iff $\\forall a, b \\in \\mathfrak{Z}: (a \\equiv^{\\mathfrak{Z}}\n  b \\Leftrightarrow a \\equiv^{\\mathfrak{A}} b)$.\n\\end{defn}\n\n\\begin{prop}\\label{is-corr-inters}\nThe following is an implications tuple:\n\\begin{enumerate}\n \\item\\label{wcorr-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n \\item\\label{wcorr-flt}  $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over\n   a meet-semilattice.\n \\item\\label{wcorr-con} $(\\mathfrak{A},\\mathfrak{Z})$ is with binarily meet-closed core,\n   weakly down-aligned filtrator, and~$\\mathfrak{Z}$ is a meet-semilattice.\n \\item\\label{wcorr-res} $(\\mathfrak{A},\\mathfrak{Z})$ is with correct intersection.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n \\item[\\ref{wcorr-pow}$\\Rightarrow$\\ref{wcorr-flt}] Obvious.\n \\item[\\ref{wcorr-flt}$\\Rightarrow$\\ref{wcorr-con}]\n  Corollary~\\ref{f-meet-closed}.\n \\item[\\ref{wcorr-con}$\\Rightarrow$\\ref{wcorr-res}]\n  $a \\nasymp^{\\mathfrak{Z}} b \\Rightarrow a \\nasymp^{\\mathfrak{A}} b$ is\n  obvious. Let $a \\asymp^{\\mathfrak{Z}} b$. Then $a \\sqcap^{\\mathfrak{Z}} b$\n  exists; so $\\bot^{\\mathfrak{Z}}$ exists and $a \\sqcap^{\\mathfrak{Z}} b =\n  \\bot^{\\mathfrak{Z}}$ (as otherwise $a \\sqcap^{\\mathfrak{Z}} b$ is\n  non-least). So $\\bot^{\\mathfrak{Z}} = \\bot^{\\mathfrak{A}}$. We have $a\n  \\sqcap^{\\mathfrak{A}} b = \\bot^{\\mathfrak{A}}$. Thus $a\n  \\asymp^{\\mathfrak{A}} b$.\n\\end{description}\n\\end{proof}\n\n\\begin{prop}\\label{is-corr-join}\nThe following is an implications tuple:\n\\begin{enumerate}\n \\item\\label{wcorr2-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n \\item\\label{wcorr2-flt}  $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over\n   a join-semilattice.\n \\item\\label{wcorr2-con} $(\\mathfrak{A},\\mathfrak{Z})$ is with binarily join-closed core,\n   weakly up-aligned filtrator, and~$\\mathfrak{Z}$ is a join-semilattice.\n \\item\\label{wcorr2-res} $(\\mathfrak{A},\\mathfrak{Z})$ is with correct joining.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n \\item[\\ref{wcorr2-pow}$\\Rightarrow$\\ref{wcorr2-flt}] Obvious.\n \\item[\\ref{wcorr2-flt}$\\Rightarrow$\\ref{wcorr2-con}]\n  Corollary~\\ref{semifilt-joinclosed}.\n \\item[\\ref{wcorr2-con}$\\Rightarrow$\\ref{wcorr2-res}]\n  Dual of the previous proposition.\n\\end{description}\n\\end{proof}\n\n\\begin{lem}\\label{int-join-lem}\n\\label{bool-compl}For a filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nwhere $\\mathfrak{Z}$ is a boolean lattice, for every $B\\in\\mathfrak{Z}$,\n$\\mathcal{A}\\in\\mathfrak{A}$:\n\\begin{enumerate}\n\\item $B\\asymp^{\\mathfrak{A}}\\mathcal{A}\\Leftrightarrow\\overline{B}\\sqsupseteq\\mathcal{A}$\nif it is with separable core and with correct intersection;\n\\item $B\\equiv^{\\mathfrak{A}}\\mathcal{A}\\Leftrightarrow\\overline{B}\\sqsubseteq\\mathcal{A}$\nif it is with co-separable core and with correct joining.\n\\end{enumerate}\n\\end{lem}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\\begin{align*}\nB\\asymp^{\\mathfrak{A}}\\mathcal{A} & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A}:B\\asymp^{\\mathfrak{A}}A & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A}:B\\asymp^{\\mathfrak{Z}}A & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A}:\\overline{B}\\sqsupseteq A & \\Leftrightarrow\\\\\n\\overline{B}\\in\\up\\mathcal{A} & \\Leftrightarrow\\\\\n\\overline{B}\\sqsupseteq\\mathcal{A}.\n\\end{align*}\n\n\\end{proof}\n\n\\section{Stars of Elements of Filtrators}\n\\begin{defn}\n\\index{core star}\\index{star!core}Let $(\\mathfrak{A},\\mathfrak{Z})$\nbe a filtrator. \\emph{Core star} of an element $a$ of the filtrator\nis\n\\[\n\\corestar a=\\setcond{x\\in\\mathfrak{Z}}{x\\nasymp^{\\mathfrak{A}}a}.\n\\]\n\\end{defn}\n\\begin{prop}\n$\\up a\\subseteq\\corestar a$ for any non-least element $a$ of a filtrator.\\end{prop}\n\\begin{proof}\nFor any element $X\\in\\mathfrak{Z}$\n\\[\nX\\in\\up a\\Rightarrow a\\sqsubseteq X\\land a\\sqsubseteq a\\Rightarrow X\\nasymp^{\\mathfrak{A}}a\\Rightarrow X\\in\\corestar a.\n\\]\n\\end{proof}\n\\begin{thm}\n\\label{part-is-free}Let $(\\mathfrak{A},\\mathfrak{Z})$ be a distributive\nlattice filtrator with least element and binarily join-closed core\nwhich is a join-semilattice. Then $\\corestar a$ is a free star for\neach $a\\in\\mathfrak{A}$.\\end{thm}\n\\begin{proof}\nFor every $A,B\\in\\mathfrak{Z}$\n\\begin{align*}\nA\\sqcup^{\\mathfrak{Z}}B\\in\\corestar a & \\Leftrightarrow\\\\\nA\\sqcup^{\\mathfrak{A}}B\\in\\corestar a & \\Leftrightarrow\\\\\n(A\\sqcup^{\\mathfrak{A}}B)\\sqcap^{\\mathfrak{A}}a\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\n(A\\sqcap^{\\mathfrak{A}}a)\\sqcup^{\\mathfrak{A}}(B\\sqcap^{\\mathfrak{A}}a)\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\nA\\sqcap^{\\mathfrak{A}}a\\ne\\bot^{\\mathfrak{A}}\\lor B\\sqcap^{\\mathfrak{A}}a\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\nA\\in\\corestar a\\lor B\\in\\corestar a.\n\\end{align*}\n\n\nThat $\\corestar a$ doesn't contain $\\bot^{\\mathfrak{A}}$ is obvious.\\end{proof}\n\\begin{defn}\n\\index{filtrator!star-separable}I call a filtrator \\emph{star-separable}\nwhen its core is a separation subset of its base.\n\\end{defn}\n\n\\section{Atomic Elements of a Filtrator}\n\nSee \\cite{primeidealsandfilters,primefilters} for more detailed treatment\nof ultrafilters and prime filters.\n\n\\begin{prop}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item\\label{f-atoms-meet-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item\\label{f-atoms-meet-prim} $(\\mathfrak{A},\\mathfrak{Z})$\n  is a primary filtrator over a meet-semilattice with greatest element.\n\\item\\label{f-atoms-meet-slat} $\\mathfrak{A}$~is a complete lattice.\n\\item\\label{f-atoms-meet-resx} $\\atoms\\bigsqcap S=\\bigcap\\rsupfun{\\atoms}S$ for every $S\\in\\subsets\\mathfrak{A}$.\n\\item\\label{f-atoms-meet-res} $\\atoms(a\\sqcap b)=\\atoms a\\cap\\atoms b$ for $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{disorder}\n\\item[\\ref{f-atoms-meet-pow}$\\Rightarrow$\\ref{f-atoms-meet-prim}] Obvious.\n\\item[\\ref{f-atoms-meet-prim}$\\Rightarrow$\\ref{f-atoms-meet-slat}] Corollary~\\ref{filt-is-complete}.\n\\item[\\ref{f-atoms-meet-slat}$\\Rightarrow$\\ref{f-atoms-meet-resx}] Theorem~\\ref{atoms-infmeet}.\n\\item[\\ref{f-atoms-meet-resx}$\\Rightarrow$\\ref{f-atoms-meet-res}] Obvious.\n\\end{disorder}\n\\end{proof}\n\n\\begin{prop}\\label{f-atoms-join}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item\\label{f-atoms-join-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item\\label{f-atoms-join-prim} $(\\mathfrak{A},\\mathfrak{Z})$\n  is a primary filtrator over a distributive lattice\n  which is and ideal base.\n\\item\\label{f-atoms-join-slat} $\\mathfrak{A}$~is a starrish join-semilattice.\n\\item\\label{f-atoms-join-res} $\\atoms(a\\sqcup b)=\\atoms a\\cup\\atoms b$ for $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{disorder}\n\\item[\\ref{f-atoms-join-pow}$\\Rightarrow$\\ref{f-atoms-join-prim}] Obvious.\n\\item[\\ref{f-atoms-join-prim}$\\Rightarrow$\\ref{f-atoms-join-slat}] Corollary~\\ref{filt-also-distr}.\n\\item[\\ref{f-atoms-join-slat}$\\Rightarrow$\\ref{f-atoms-join-res}] Corollary~\\ref{atoms-join}.\n\\end{disorder}\n\\end{proof}\n\n\\begin{thm}\n\\label{atom-both}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{atom-both-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{atom-both-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a meet-semilattice.\n\\item \\label{atom-both-mlat}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\nweakly down-aligned filtrator with binarily meet-closed core $\\mathfrak{Z}$\nwhich is a meet-semilattice.\n\\item \\label{atom-both-conc}$a$ is an atom of $\\mathfrak{Z}$ iff $a\\in\\mathfrak{Z}$\nand $a$ is an atom of $\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{atom-both-p}$\\Rightarrow$\\ref{atom-both-f}}] Obvious.\n\\item [{\\ref{atom-both-f}$\\Rightarrow$\\ref{atom-both-mlat}}] It is filtered\nby the theorem~\\ref{semifilt-joinclosed}, binarily meet-closed by\ncorollary~\\ref{f-meet-closed}.\n\\item [{\\ref{atom-both-mlat}$\\Rightarrow$\\ref{atom-both-conc}}] ~\n\n\\begin{description}\n\\item [{$\\Leftarrow$}] Let $a$ be an atom of $\\mathfrak{A}$ and $a \\in \\mathfrak{Z}$. Then either\n$a$ is an atom of $\\mathfrak{Z}$ or $a$ is the least element of\n$\\mathfrak{Z}$. But if $a$ is the least element of $\\mathfrak{Z}$ then $a$ is\nalso least element of $\\mathfrak{A}$ and thus is not an atom of\n$\\mathfrak{A}$. So the only possible outcome is that $a$ is an atom of\n$\\mathfrak{Z}$.\n\\item [{$\\Rightarrow$}]\nWe need to prove that if $a$ is an atom of $\\mathfrak{Z}$\nthen $a$ is an atom of $\\mathfrak{A}$. Suppose the contrary that\n$a$ is not an atom of $\\mathfrak{A}$. Then there exists $x\\in\\mathfrak{A}$\nsuch that $x\\sqsubset a$ and~$x$ is not least element of~$\\mathfrak{A}$. Because ``$\\up$'' is a straight\nmonotone map to the dual of the poset $\\subsets\\mathfrak{Z}$ (obvious\n\\ref{up-straight}), $\\up a\\subset\\up x$. So there exists $K\\in\\up x$\nsuch that $K\\notin\\up a$. Also $a\\in\\up x$. We have $K\\sqcap^{\\mathfrak{Z}}a=K\\sqcap^{\\mathfrak{A}}a\\in\\up x$;\n$K\\sqcap^{\\mathfrak{Z}}a$ is not least of~$\\mathfrak{Z}$\n(Suppose for the contrary that\n$K\\sqcap^{\\mathfrak{Z}}a=\\bot^{\\mathfrak{Z}}$, then\n$K\\sqcap^{\\mathfrak{Z}}a=\\bot^{\\mathfrak{A}}\\notin\\up x$.) and\n$K\\sqcap^{\\mathfrak{Z}}a\\sqsubset a$.\nSo $a$ is not an atom of $\\mathfrak{Z}$.\n\\end{description}\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{up-eq-corestar}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{up-eq-corestar-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{up-eq-corestar-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator.\n\\item \\label{up-eq-corestar-mlat}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered filtrator.\n\\item \\label{up-eq-corestar-conc}$a\\in\\mathfrak{A}$ is an atom of $\\mathfrak{A}$\niff $\\up a=\\corestar a$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{up-eq-corestar-p}$\\Rightarrow$\\ref{up-eq-corestar-f}}] Obvious.\n\\item [{\\ref{up-eq-corestar-f}$\\Rightarrow$\\ref{up-eq-corestar-mlat}}] By the theorem~\\ref{semifilt-joinclosed}.\n\\item [{\\ref{up-eq-corestar-mlat}$\\Rightarrow$\\ref{up-eq-corestar-conc}}] ~\n\n\\begin{description}\n\\item [{$\\Rightarrow$}] For any $K\\in\\mathfrak{A}$\n\\[\nK\\in\\up a\\Leftrightarrow K\\sqsupseteq a\\Leftrightarrow K\\nasymp^{\\mathfrak{A}}a\\Leftrightarrow K\\in\\corestar a.\n\\]\n\n\\item [{$\\Leftarrow$}] Let $\\up a=\\corestar a$. Then~$a$ is not\nleast element of~$\\mathfrak{A}$. Consequently\nfor every $x\\in\\mathfrak{A}$ if~$x$ is not the least element\nof~$\\mathfrak{A}$ we have\n\\begin{align*}\nx\\sqsubset a & \\Rightarrow\\\\\nx\\nasymp^{\\mathfrak{A}}a & \\Rightarrow\\\\\n\\forall K\\in\\up x:K\\in\\corestar a & \\Rightarrow\\\\\n\\forall K\\in\\up x:K\\in\\up a & \\Rightarrow\\\\\n\\up x\\subseteq\\up a & \\Rightarrow\\\\\nx\\sqsupseteq a.\n\\end{align*}\n\n\n\nSo $a$ is an atom of $\\mathfrak{A}$.\n\n\\end{description}\n\\end{description}\n\\end{proof}\n\\begin{prop}\n\\label{coat}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{coat-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{coat-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator.\n\\item \\label{coat-conc}Coatoms of $\\mathfrak{A}$ are exactly coatoms of\n$\\mathfrak{Z}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{coat-p}$\\Rightarrow$\\ref{coat-fltr}}] Obvious.\n\\item [{\\ref{coat-fltr}$\\Rightarrow$\\ref{coat-conc}}] Suppose $a$ is\na coatom of $\\mathfrak{Z}$. Then $a$ is the only non-greatest element\nin $\\up a$. Suppose $b\\sqsupset a$ for some $b\\in\\mathfrak{A}$.\nThen $a$ cannot be in $\\up b$ and thus the only possible element\nof $\\up b$ is the greatest element of $\\mathfrak{Z}$ (if it exists)\nfrom what follows $b=\\top^{\\mathfrak{A}}$. So $a$ is a coatom of\n$\\mathfrak{A}$.\n\n\nSuppose now that $a$ is a coatom of $\\mathfrak{A}$. To finish the\nproof it is enough to show that $a$ is principal. (Then $a$ is non-greatest\nand thus is a coatom of $\\mathfrak{Z}$.)\n\n\nSuppose $a$ is non-principal. Then obviously exist two distinct elements\n$x$ and $y$ of the core such that $x,y\\in\\up a$. Thus $a$ is not\nan atom of $\\mathfrak{A}$.\n\n\\end{description}\n\\end{proof}\n\\begin{cor}\nCoatoms of the set of filters on a set~$U$ are exactly sets $U\\setminus\\{x\\}$\nwhere $x\\in U$.\\end{cor}\n\\begin{prop}\n\\label{coat-ic}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{coat-ic-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{coat-ic-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a coatomic poset.\n\\item \\label{coat-ic-conc}$\\mathfrak{A}$ is coatomic.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{coat-ic-p}$\\Rightarrow$\\ref{coat-ic-fltr}}] Obvious.\n\\item [{\\ref{coat-ic-fltr}$\\Rightarrow$\\ref{coat-ic-fltr}}] Suppose\n$\\mathcal{A}\\in\\mathfrak{A}$ and $\\mathcal{A}\\neq\\top^{\\mathfrak{A}}$.\nThen there exists $A\\in\\up\\mathcal{A}$ such that $A$ is not greatest\nelement of $\\mathfrak{Z}$. Consequently there exists a coatom $a\\in\\mathfrak{Z}$\nsuch that $a\\sqsupseteq A$. Thus $a\\in\\up\\mathcal{A}$ and $a$ is\nnot greatest.\n\\end{widedisorder}\n\\end{proof}\n\n\\section{Prime Filtrator Elements}\n\\begin{defn}\n\\index{prime element}Let $(\\mathfrak{A},\\mathfrak{Z})$ be a filtrator. \\emph{Prime} filtrator elements are such $a\\in\\mathfrak{A}$\nthat $\\up a$ is a free star (in lattice~$\\mathfrak{Z}$).\\end{defn}\n\\begin{prop}\n\\label{atom-is-prime}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{atom-is-prime-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{atom-is-prime-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a distributive lattice which is an\nideal base.\n\\item \\label{atom-is-prime-jlat}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtrator with binarily join-closed core, where $\\mathfrak{A}$ is\na starrish join-semilattice and $\\mathfrak{Z}$ is a join-semilattice.\n\\item \\label{atom-is-prime-conc}Atomic elements of this filtrator are prime.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{atom-is-prime-p}$\\Rightarrow$\\ref{atom-is-prime-f}}] Obvious.\n\\item [{\\ref{atom-is-prime-f}$\\Rightarrow$\\ref{atom-is-prime-jlat}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis with binarily join-closed core by the theorem \\ref{semifilt-joinclosed},\n$\\mathfrak{A}$ is a distributive lattice by theorem \\ref{filt-also-distr}.\n\\item [{\\ref{atom-is-prime-jlat}$\\Rightarrow$\\ref{atom-is-prime-conc}}] Let\n$a$ be an atom of the lattice $\\mathfrak{A}$. We have for every\n$X,Y\\in\\mathfrak{Z}$\n\\begin{align*}\nX\\sqcup^{\\mathfrak{Z}}Y\\in\\up a & \\Leftrightarrow\\\\\nX\\sqcup^{\\mathfrak{A}}Y\\in\\up a & \\Leftrightarrow\\\\\nX\\sqcup^{\\mathfrak{A}}Y\\sqsupseteq a & \\Leftrightarrow\\\\\nX\\sqcup^{\\mathfrak{A}}Y\\nasymp^{\\mathfrak{A}}a & \\Leftrightarrow\\\\\nX\\nasymp^{\\mathfrak{A}}a\\lor Y\\nasymp^{\\mathfrak{A}}a & \\Leftrightarrow\\\\\nX\\sqsupseteq a\\lor Y\\sqsupseteq a & \\Leftrightarrow\\\\\nX\\in\\up a\\lor Y\\in\\up a.\n\\end{align*}\n\n\\end{description}\n\\end{proof}\nThe following theorem is essentially borrowed from \\cite{stone-spaces}:\n\\begin{thm}\n\\label{f-prime-crit}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{prim-crit-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{prim-crit-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{prim-crit-conc}Let $a\\in\\mathfrak{A}$. Then the following\nare equivalent:\n\n\\begin{enumerate}\n\\item \\label{prim-prim}$a$ is prime.\n\\item \\label{a-not-a}For every $A\\in\\mathfrak{Z}$ exactly one of $\\{A,\\overline{A}\\}$\nis in $\\up a$.\n\\item \\label{prim-atom}$a$ is an atom of $\\mathfrak{A}$.\n\\end{enumerate}\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{prim-crit-p}$\\Rightarrow$\\ref{prim-crit-fltr}}] Obvious.\n\\item [{\\ref{prim-crit-fltr}$\\Rightarrow$\\ref{prim-crit-conc}}] ~\n\n\\begin{description}\n\\item [{\\ref{prim-prim}$\\Rightarrow$\\ref{a-not-a}}] Let $a$ be prime.\nThen $A\\sqcup^{\\mathfrak{Z}}\\overline{A}=\\top^{\\mathfrak{A}}\\in\\up a$.\nTherefore $A\\in\\up a\\lor\\overline{A}\\in\\up a$. But since $A\\sqcap^{\\mathfrak{Z}}\\overline{A}=\\bot^{\\mathfrak{Z}}$\nit is impossible $A\\in\\up a\\land\\overline{A}\\in\\up a$.\n\\item [{\\ref{a-not-a}$\\Rightarrow$\\ref{prim-atom}}] Obviously $a\\ne\\bot^{\\mathfrak{A}}$.\n\nLet a filter $b\\sqsubset a$. Take $X\\in\\up b$ such that $X\\notin\\up a$. Then $\\overline{X}\\in\\up a$ because $a$ is prime and thus\n$\\overline{X}\\in\\up b$. So\n$\\bot^{\\mathfrak{Z}}=X\\sqcap^{\\mathfrak{Z}}\\overline{X}\\in\\up b$\nand thus $b=\\bot^{\\mathfrak{A}}$. So $a$ is atomic.\n\\item [{\\ref{prim-atom}$\\Rightarrow$\\ref{prim-prim}}] By the previous\nproposition.\n\\end{description}\n\\end{description}\n\\end{proof}\n\n\\section{Stars for filters}\n\\begin{thm}\n\\label{da-is-free-star}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{da-is-free-star-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{da-is-free-star-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a distributive lattice which is an ideal\nbase and has least element.\n\\item \\label{da-is-free-star-conc}$\\corestar a$ is a free star for each\n$a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{da-is-free-star-p}$\\Rightarrow$\\ref{da-is-free-star-fltr}}] Obvious.\n\\item [{\\ref{da-is-free-star-fltr}$\\Rightarrow$\\ref{da-is-free-star-conc}}] $\\mathfrak{A}$\nis a distributive lattice by the corollary \\ref{filt-also-distr}.\nThe filtrator $(\\mathfrak{A},\\mathfrak{Z})$ is binarily join-closed\nby corollary \\ref{semifilt-joinclosed}. So we can apply the theorem\n\\ref{part-is-free}.\n\\end{description}\n\\end{proof}\n\n\\subsection{Stars of Filters on Boolean Lattices}\n\nIn this section we will consider the set of filters $\\mathfrak{A}$\non a boolean lattice $\\mathfrak{Z}$.\n\\begin{thm}\n\\label{f-simpl-star-dual}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{simpl-star-dual-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{simpl-star-dual-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{simpl-star-dual-conc}$\\corestar\\mathcal{A}=\\lnot\\rsupfun{\\lnot}\\up\\mathcal{A}=\\rsupfun{\\lnot}\\lnot\\up\\mathcal{A}$\nand $\\up\\mathcal{A}=\\lnot\\rsupfun{\\lnot}\\corestar\\mathcal{A}=\\rsupfun{\\lnot}\\lnot\\corestar\\mathcal{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{simpl-star-dual-p}$\\Rightarrow$\\ref{simpl-star-dual-fltr}}] Obvious.\n\\item [{\\ref{simpl-star-dual-fltr}$\\Rightarrow$\\ref{simpl-star-dual-conc}}] Because\nof properties of diagram~(\\ref{two-diags}), it is enough to prove\njust $\\corestar\\mathcal{A}=\\lnot\\rsupfun{\\lnot}\\up\\mathcal{A}$. Really,\n\\[X\\in\\up\\mathcal{A}\\Leftrightarrow X\\sqsupseteq\\mathcal{A}\\Leftrightarrow\\overline{X}\\asymp^{\\mathfrak{A}}\\mathcal{A}\\Leftrightarrow\\overline{X}\\notin\\corestar\\mathcal{A}\\]\nfor any $X\\in\\mathfrak{Z}$ (taking into account theorems~\\ref{up-filt-crit},\n\\ref{when-sep-core}, and lemma~\\ref{bool-compl}).\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{d-inj}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a boolean\nlattice.\n\\item $\\corestar$ is an order isomorphism from $\\mathfrak{A}$ to $\\mathfrak{S}(\\mathfrak{Z})$.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\nBy properties of the diagram~(\\ref{two-diags}).\\end{proof}\n\\begin{cor}\n\\label{d-f-join}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{d-f-join-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{d-f-join-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{d-f-join-conc}$\\corestar\\bigsqcup^{\\mathfrak{A}}S=\\bigcup\\rsupfun{\\corestar}S$\nfor every $S\\in\\subsets\\mathfrak{A}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{d-f-join-p}$\\Rightarrow$\\ref{d-f-join-fltr}}] Obvious.\n\\item [{\\ref{d-f-join-fltr}$\\Rightarrow$\\ref{d-f-join-conc}}] $\\corestar\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{S}(\\mathfrak{Z})}\\rsupfun{\\corestar}S=\\bigcup\\rsupfun{\\corestar}S$.\n\\end{description}\n\\end{proof}\n\n\\section{Generalized Filter Base}\n\\begin{defn}\n\\index{filter base!generalized}\\emph{Generalized filter base} is\na filter base on the set $\\mathfrak{A}$ where $(\\mathfrak{A},\\mathfrak{Z})$\nis a primary filtrator.\n\\end{defn}\n\n\\begin{defn}\nIf $S$ is a generalized filter base and $\\mathcal{A}=\\bigsqcap^{\\mathfrak{A}}S$\nfor some $\\mathcal{A}\\in\\mathfrak{A}$, then we call $S$ a generalized\nfilter base of~$\\mathcal{A}$.\\end{defn}\n\\begin{thm}\n\\label{genbase-main}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{genbase-main-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{genbase-main-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a meet-semilattice.\n\\item \\label{genbase-main-conc}For a generalized filter base $S$ of $\\mathcal{F}\\in\\mathfrak{A}$\nand $K\\in\\mathfrak{Z}$ we have\n\\[\nK\\in\\up\\mathcal{F}\\Leftrightarrow\\exists\\mathcal{L}\\in S:K\\in\\up\\mathcal{L}.\n\\]\n\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{genbase-main-p}$\\Rightarrow$\\ref{genbase-main-fltr}}] Obvious.\n\\item [{\\ref{genbase-main-fltr}$\\Rightarrow$\\ref{genbase-main-conc}}] ~\n\n\\begin{description}\n\\item [{$\\Leftarrow$}] Because $\\mathcal{F}=\\bigsqcap^{\\mathfrak{A}}S$.\n\\item [{$\\Rightarrow$}] Let $K\\in\\up\\mathcal{F}$. Then (taken into account\ncorollary~\\ref{meet-filtx} and that $S$ is nonempty) there exist\n$X_{1},\\dots,X_{n}\\in\\bigcup\\rsupfun{\\up}S$ such that $K\\in\\up(X_{1}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}X_{n})$\nthat is $K\\in\\up(\\uparrow X_{1}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}\\uparrow X_{n})$.\nConsequently (by theorem \\ref{up-filt-crit}) $K\\in\\up(\\uparrow X_{1}\\sqcap^{\\mathfrak{A}}\\dots\\sqcap^{\\mathfrak{A}}\\uparrow X_{n})$.\nReplacing every $\\uparrow X_{i}$ with such $\\mathcal{X}_{i}\\in S$\nthat $X_{i}\\in\\up\\mathcal{X}_{i}$ (this is obviously possible to\ndo), we get a finite set $T_{0}\\subseteq S$ such that $K\\in\\up\\bigsqcap^{\\mathfrak{A}}T_{0}$.\nFrom this there exists $\\mathcal{C}\\in S$ such that $\\mathcal{C}\\sqsubseteq\\bigsqcap^{\\mathfrak{A}}T_{0}$\nand so $K\\in\\up\\mathcal{C}$.\n\\end{description}\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{genbase-corr}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a meet-semilattice\nwith least element.\n\\item For a generalized filter base $S$ of a $\\mathcal{F}\\in\\mathfrak{A}$\nwe have\n\\[\n\\bot^{\\mathfrak{A}}\\in S\\Leftrightarrow\\mathcal{F}=\\bot^{\\mathfrak{A}}.\n\\]\n\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\nSubstitute $\\bot^{\\mathfrak{A}}$ as $K$.\\end{proof}\n\\begin{thm}\n\\label{genbase-f-closed}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a meet-semilattice\nwith least element.\n\\item Let $\\mathcal{F}_{0}\\sqcap^{\\mathfrak{A}}\\dots\\sqcap^{\\mathfrak{A}}\\mathcal{F}_{n}\\ne\\bot^{\\mathfrak{A}}$\nfor every $\\mathcal{F}_{0},\\dots,\\mathcal{F}_{n}\\in S$, where $S$\nis a nonempty set of elements of $\\mathfrak{A}$. Then $\\bigsqcap^{\\mathfrak{A}}S\\ne\\bot^{\\mathfrak{A}}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nConsider the set\n\\[\nS'=\\setcond{\\mathcal{F}_{0}\\sqcap^{\\mathfrak{A}}\\dots\\sqcap^{\\mathfrak{A}}\\mathcal{F}_{n}}{\\mathcal{F}_{0},\\dots,\\mathcal{F}_{n}\\in S}.\n\\]\n\n\nObviously $S'$ is nonempty and binarily meet-closed. So $S'$ is\na generalized filter base. Obviously $\\bot^{\\mathfrak{A}}\\notin S$.\nSo by properties of generalized filter bases $\\bigsqcap^{\\mathfrak{A}}S'\\ne\\bot^{\\mathfrak{A}}$.\nBut obviously $\\bigsqcap^{\\mathfrak{A}}S=\\bigsqcap^{\\mathfrak{A}}S'$.\nSo $\\bigsqcap^{\\mathfrak{A}}S\\ne\\bot^{\\mathfrak{A}}$.\\end{proof}\n\\begin{cor}\n\\label{princ-fbase}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{princ-fbase-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{princ-fbase-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a meet-semilattice with least element.\n\\item \\label{princ-fbase-conc}Let $S\\in\\subsets\\mathfrak{Z}$ such that\n$S\\ne\\emptyset$ and $A_{0}\\sqcap^{\\mathfrak{Z}}\\dots\\sqcap^{\\mathfrak{Z}}A_{n}\\ne\\bot^{\\mathfrak{Z}}$\nfor every $A_{0},\\dots,A_{n}\\in S$. Then $\\bigsqcap^{\\mathfrak{A}}S\\ne\\bot^{\\mathfrak{A}}$.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{princ-fbase-p}$\\Rightarrow$\\ref{princ-fbase-fltr}}] Obvious.\n\\item [{\\ref{princ-fbase-fltr}$\\Rightarrow$\\ref{princ-fbase-conc}}] Because\n$(\\mathfrak{A},\\mathfrak{Z})$ is binarily meet-closed (by the theorem\n\\ref{up-filt-crit}).\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{filt-atomic}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{filt-atomic-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{filt-atomic-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a bounded meet-semilattice.\n\\item \\label{filt-atomic-conc}$\\mathfrak{A}$ is an atomic lattice.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{filt-atomic-p}$\\Rightarrow$\\ref{filt-atomic-fltr}}] Obvious.\n\\item [{\\ref{filt-atomic-fltr}$\\Rightarrow$\\ref{filt-atomic-conc}}] Let\n$\\mathcal{F}\\in\\mathfrak{A}$. Let choose (by Kuratowski's lemma)\na maximal chain $S$ from $\\bot^{\\mathfrak{A}}$ to $\\mathcal{F}$.\nLet $S'=S\\setminus\\{\\bot^{\\mathfrak{A}}\\}$. $a=\\bigsqcap^{\\mathfrak{A}}S'\\ne\\bot^{\\mathfrak{A}}$\nby properties of generalized filter bases (the corollary \\ref{genbase-corr}\nwhich uses the fact that $\\mathfrak{Z}$ is a meet-semilattice with\nleast element). If $a\\notin S$ then the chain $S$ can be extended\nadding there element $a$ because $\\bot^{\\mathfrak{A}}\\sqsubset a\\sqsubseteq\\mathcal{X}$\nfor any $\\mathcal{X}\\in S'$ what contradicts to maximality of the\nchain. So $a\\in S$ and consequently $a\\in S'$. Obviously $a$ is\nthe minimal element of $S'$. Consequently (taking into account maximality\nof the chain) there is no $\\mathcal{Y}\\in\\mathfrak{A}$ such that\n$\\bot^{\\mathfrak{A}}\\sqsubset\\mathcal{Y}\\sqsubset a$. So $a$ is\nan atomic filter. Obviously $a\\sqsubseteq\\mathcal{F}$.\n\\end{description}\n\\end{proof}\n\\begin{defn}\nA complete lattice is \\emph{co-compact} iff $\\bigsqcap S=\\bot$ for\na set $S$ of elements of this lattice implies that there is its finite\nsubset $T\\subseteq S$ such that $\\bigsqcap T=\\bot$.\\end{defn}\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{cmpct-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{cmpct-filt}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a bounded meet-semilattice.\n\\item \\label{cmpct-conc}$\\mathfrak{A}$ is co-compact.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cmpct-p}$\\Rightarrow$\\ref{cmpct-filt}}] Obvious.\n\\item [{\\ref{cmpct-filt}$\\Rightarrow$\\ref{cmpct-conc}}] Poset~$\\mathfrak{A}$\nis complete by corollary~\\ref{filt-is-complete}.\n\n\nIf $\\bot\\in\\up\\bigsqcap^{\\mathfrak{A}}S$ then there are $K_{i}\\in\\up\\bigcup S$\nsuch that $\\bot\\in\\up(K_{0}\\sqcap^{\\mathfrak{Z}}\\ldots\\sqcap^{\\mathfrak{Z}}K_{n})$\nthat is $K_{0}\\sqcap^{\\mathfrak{Z}}\\ldots\\sqcap^{\\mathfrak{Z}}K_{n}=\\bot$\nfrom which easily follows $\\mathcal{F}_{0}\\sqcap^{\\mathfrak{A}}\\ldots\\sqcap^{\\mathfrak{A}}\\mathcal{F}_{n}=\\bot$\nfor some $\\mathcal{F}_{i}\\in S$.\n\n\\end{description}\n\\end{proof}\n\n\\section{Separability of filters}\n\\begin{prop}\n\\label{filt-is-sep}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{filt-is-sep-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{filt-is-sep-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{filt-is-sep-conc}$\\mathfrak{A}$ is strongly separable.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{filt-is-sep-p}$\\Rightarrow$\\ref{filt-is-sep-fltr}}] Obvious.\n\\item [{\\ref{filt-is-sep-fltr}$\\Rightarrow$\\ref{filt-is-sep-conc}}] By\nproperties of stars of filters.\n\\end{description}\n\\end{proof}\n\n\\begin{rem}\n \\cite{2832846}~seems to show that the above theorem cannot\n be generalized for a wider class of lattices.\n\\end{rem}\n\n\\begin{thm}\n\\label{filt-atomistic}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{filt-atomistic-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{filt-atomistic-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{filt-atomistic-conc}$\\mathfrak{A}$ is an atomistic poset.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{filt-atomistic-p}$\\Rightarrow$\\ref{filt-atomistic-fltr}}] Obvious.\n\\item [{\\ref{filt-atomistic-fltr}$\\Rightarrow$\\ref{filt-atomistic-conc}}] Because\n(used theorem \\ref{atomistic-enough}) $\\mathfrak{A}$ is atomic\n(theorem \\ref{filt-atomic}) and separable.\n\\end{description}\n\\end{proof}\n\\begin{cor}\n\\label{f-atom-sep}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a boolean\nlattice.\n\\item $\\mathfrak{A}$ is atomically separable.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\nBy theorem \\ref{atms-is-asep}.\n\\end{proof}\n\n\\section{Some Criteria}\n\\begin{thm}\n\\label{crit1}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{crit1-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{crit1-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a complete boolean lattice.\n\\item \\label{crit1-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a down-aligned,\nwith join-closed, binarily meet-closed and separable core which is\na complete boolean lattice.\n\\item \\label{crit1-conc}The following conditions are equivalent for any\n$\\mathcal{F}\\in\\mathfrak{A}$:\n\n\\begin{enumerate}\n\\item \\label{crit1-core}$\\mathcal{F}\\in\\mathfrak{Z}$;\n\\item \\label{crit1-flt}$\\forall S\\in\\subsets\\mathfrak{A}:\\left(\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S\\ne\\bot\\Rightarrow\\exists\\mathcal{K}\\in S:\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\mathcal{K}\\ne\\bot\\right)$;\n\\item \\label{crit1-princ}$\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S\\ne\\bot\\Rightarrow\\exists K\\in S:\\mathcal{F}\\sqcap^{\\mathfrak{A}}K\\ne\\bot\\right)$.\n\\end{enumerate}\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{crit1-p}$\\Rightarrow$\\ref{crit1-f}}] Obvious.\n\\item [{\\ref{crit1-f}$\\Rightarrow$\\ref{crit1-fltr}}] The filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nis with with join-closed core by theorem \\ref{semifilt-joinclosed},\nbinarily meet-closed core by corollary~\\ref{f-meet-closed}, with\nseparable core by theorem \\ref{when-sep-core}.\n\\item [{\\ref{crit1-fltr}$\\Rightarrow$\\ref{crit1-conc}}] ~\n\n\\begin{description}\n\\item [{\\ref{crit1-core}$\\Rightarrow$\\ref{crit1-flt}}] Let $\\mathcal{F}\\in\\mathfrak{Z}$.\nThen (taking into account the lemma~\\ref{bool-compl})\n\\[\n\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S\\ne\\bot\\Leftrightarrow\\overline{\\mathcal{F}}\\nsqsupseteq\\bigsqcup^{\\mathfrak{A}}S\\Rightarrow\\exists\\mathcal{K}\\in S:\\overline{\\mathcal{F}}\\nsqsupseteq\\mathcal{K}\\Leftrightarrow\\exists\\mathcal{K}\\in S:\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\mathcal{K}\\ne\\bot.\n\\]\n\n\\item [{\\ref{crit1-flt}$\\Rightarrow$\\ref{crit1-princ}}] Obvious.\n\\item [{\\ref{crit1-princ}$\\Rightarrow$\\ref{crit1-core}}] ~\n\\begin{align*}\n\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S\\ne\\bot\\Rightarrow\\exists K\\in S:\\mathcal{F}\\sqcap^{\\mathfrak{A}}K\\ne\\bot\\right) & \\Leftrightarrow\\\\\n\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\mathcal{F}\\nasymp^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{Z}}S\\Rightarrow\\exists K\\in S:\\mathcal{F}\\nasymp^{\\mathfrak{A}}K\\right) & \\Leftrightarrow\\text{ (lemma \\ref{bool-compl})}\\\\\n\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\overline{\\bigsqcup^{\\mathfrak{Z}}S}\\nsqsupseteq\\mathcal{F}\\Rightarrow\\exists K\\in S:\\overline{K}\\nsqsupseteq\\mathcal{F}\\right) & \\Leftrightarrow\\\\\n\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\forall K\\in S:\\overline{K}\\sqsupseteq\\mathcal{F}\\Rightarrow\\overline{\\bigsqcup^{\\mathfrak{Z}}S}\\sqsupseteq\\mathcal{F}\\right) & \\Leftrightarrow\\\\\n\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\forall K\\in S:\\overline{K}\\sqsupseteq\\mathcal{F}\\Rightarrow\\bigsqcap^{\\mathfrak{Z}}\\rsupfun{\\lnot}S\\sqsupseteq\\mathcal{F}\\right) & \\Leftrightarrow\\\\\n\\forall S\\in\\subsets\\mathfrak{Z}:\\left(\\forall K\\in S:K\\sqsupseteq\\mathcal{F}\\Rightarrow\\bigsqcap^{\\mathfrak{Z}}S\\sqsupseteq\\mathcal{F}\\right) & \\Rightarrow\\\\\n\\bigsqcap^{\\mathfrak{Z}}\\up\\mathcal{F}\\sqsupseteq\\mathcal{F} & \\Leftrightarrow\\\\\n\\bigsqcap^{\\mathfrak{Z}}\\up\\mathcal{F}\\in\\up\\mathcal{F} & \\Rightarrow\\\\\n\\mathcal{F}\\in\\mathfrak{Z}.\n\\end{align*}\n\n\\end{description}\n\\end{description}\n\\end{proof}\n\\begin{rem}\nThe above theorem strengthens theorem 53 in \\cite{filters}. Both\nthe formulation of the theorem and the proof are considerably simplified.\\end{rem}\n\\begin{defn}\n\\index{filter base!generated by}Let $S$ be a subset of a meet-semilattice.\nThe \\emph{filter base generated by} $S$ is the set\n\\[\n[S]_{\\sqcap}=\\setcond{a_{0}\\sqcap\\dots\\sqcap a_{n}}{a_{i}\\in S,n=0,1,\\dots}.\n\\]\n\\end{defn}\n\\begin{lem}\nThe set of all finite subsets of an infinite set $A$ has the same\ncardinality as $A$.\\end{lem}\n\\begin{proof}\nLet denote the number of $n$-element subsets of $A$ as $s_{n}$.\nObviously $s_{n}\\le\\card A^{n}=\\card A$. Then the number $S$ of\nall finite subsets of $A$ is equal to\n\\[\ns_{0}+s_{1}+\\dots\\le\\card A+\\card A+\\dots=\\card A.\n\\]\n\n\nThat $S\\ge\\card A$ is obvious. So $S=\\card A$.\\end{proof}\n\\begin{lem}\nA filter base generated by an infinite set has the same cardinality\nas that set.\\end{lem}\n\\begin{proof}\nFrom the previous lemma.\\end{proof}\n\\begin{defn}\n\\index{filter-closed}Let $\\mathfrak{A}$ be a complete lattice. A\nset $S\\in\\subsets\\mathfrak{A}$ is \\emph{filter-closed} when for every\nfilter base $T\\in\\subsets S$ we have $\\bigsqcap T\\in S$.\\end{defn}\n\\begin{thm}\\label{fclosed}\nA subset $S$ of a complete lattice is filter-closed iff for every\nnonempty chain $T\\in\\subsets S$ we have $\\bigsqcap T\\in S$.\\end{thm}\n\\begin{proof}\n(proof sketch by \\noun{Joel David Hamkins})\n\\begin{description}\n\\item [{$\\Rightarrow$}] Because every nonempty chain is a filter base.\n\\item [{$\\Leftarrow$}] We will assume that cardinality of a set is an\nordinal defined by von Neumann cardinal assignment (what is a standard\npractice in ZFC). Recall that $\\alpha<\\beta\\Leftrightarrow\\alpha\\in\\beta$\nfor ordinals $\\alpha$,~$\\beta$.\n\n\nWe will take it as given that for every nonempty chain $T\\in\\subsets S$\nwe have $\\bigsqcap T\\in S$.\n\n\nWe will prove the following statement: If $\\card S=n$ then $S$ is\nfilter closed, for any cardinal~$n$.\n\n\nInstead we will prove it not only for cardinals but for wider class\nof ordinals: If $\\card S=n$ then $S$ is filter-closed, for any ordinal\n$n$.\n\n\nWe will prove it using transfinite induction by~$n$.\n\n\nFor finite $n$ we have $\\bigsqcap T\\in S$ because $T\\subseteq S$\nhas minimal element.\n\n\nLet $\\card T=n$ be an infinite ordinal.\n\n\nLet the assumption hold for every $m\\in\\card T$.\n\n\nWe can assign $T=\\setcond{a_{\\alpha}}{\\alpha\\in\\card T}$ for some\n$a_{\\alpha}$ because $\\card\\card T=\\card T$.\n\n\nConsider $\\beta\\in\\card T$.\n\n\nLet $P_{\\beta}=\\setcond{a_{\\alpha}}{\\alpha\\in\\beta}$. Let $b_{\\beta}=\\bigsqcap P_{\\beta}$.\nObviously $b_{\\beta}=\\bigsqcap[P_{\\beta}]_{\\sqcap}$. We have\n\\[\n\\card[P_{\\beta}]_{\\sqcap}=\\card P_{\\beta}=\\card\\beta<\\card T\n\\]\n(used the lemma and von Neumann cardinal assignment). By the assumption\nof induction $b_{\\beta}\\in S$.\n\n\n$\\forall\\beta\\in\\card T:P_{\\beta}\\subseteq T$ and thus $b_{\\beta}\\sqsupseteq\\bigsqcap T$.\n\n\nIt is easy to see that the set $\\setcond{P_{\\beta}}{\\beta\\in\\card T}$\nis a chain. Consequently $\\setcond{b_{\\beta}}{\\beta\\in\\card T}$ is\na chain.\n\n\nBy the theorem conditions $b=\\bigsqcap_{\\beta\\in\\card T}b_{\\beta}\\in S$\n(taken into account that $b_{\\beta}\\in S$ by the assumption of induction).\n\n\nObviously $b\\sqsupseteq\\bigsqcap T$.\n\n\n$b\\sqsubseteq b_{\\beta}$ and so $\\forall\\beta\\in\\card T,\\alpha\\in\\beta:b\\sqsubseteq a_{\\alpha}$.\nLet $\\alpha\\in\\card T$. Then (because $\\card T$ is a limit ordinal,\nsee \\cite{wiki:limit-ordinal}) there exists $\\beta\\in\\card T$ such\nthat $\\alpha\\in\\beta\\in\\card T$. So $b\\sqsubseteq a_{\\alpha}$ for\nevery $\\alpha\\in\\card T$. Thus $b\\sqsubseteq\\bigsqcap T$.\n\n\nFinally $\\bigsqcap T=b\\in S$.\n\n\\end{description}\n\\end{proof}\n\n\\section{Co-Separability of Core}\n\\begin{thm}\n\\label{cosep-crit}The following is an implications tuple.\n\\begin{enumerate}\n\\item \\label{cosep-crit-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{cosep-crit-prim}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a meet infinite distributive complete lattice.\n\\item \\label{cosep-crit-uff}$(\\mathfrak{A},\\mathfrak{Z})$ is an up-aligned\nfiltered filtrator whose core is a meet infinite distributive complete\nlattice.\n\\item \\label{cosep-crit-conc}This filtrator is with co-separable core.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cosep-crit-p}$\\Rightarrow$\\ref{cosep-crit-prim}}] Obvious.\n\\item [{\\ref{cosep-crit-prim}$\\Rightarrow$\\ref{cosep-crit-uff}}] It\nis obviously up-aligned, and filtered by theorem~\\ref{semifilt-joinclosed}.\n\\item [{\\ref{cosep-crit-uff}$\\Rightarrow$\\ref{cosep-crit-conc}}] Our\nfiltrator is with join-closed core (theorem \\ref{semifilt-joinclosed}).\n\n\nLet $a,b\\in\\mathfrak{A}$. $\\Cor a$ and $\\Cor b$ exist since $\\mathfrak{Z}$\nis a complete lattice.\n\n\n$\\Cor a\\in\\down a$ and $\\Cor b\\in\\down b$ by the theorem~\\ref{cor-less}\nsince our filtrator is filtered. So we have\n\\begin{align*}\n\\exists x\\in\\down a,y\\in\\down b:x\\sqcup^{\\mathfrak{A}}y=\\top & \\Leftarrow\\\\\n\\Cor a\\sqcup^{\\mathfrak{A}}\\Cor b=\\top & \\Leftrightarrow\\text{(by finite join-closedness of the core)}\\\\\n\\Cor a\\sqcup^{\\mathfrak{Z}}\\Cor b=\\top & \\Leftrightarrow\\\\\n\\bigsqcap^{\\mathfrak{Z}}\\up a\\sqcup^{\\mathfrak{Z}}\\bigsqcap^{\\mathfrak{Z}}\\up b=\\top & \\Leftrightarrow\\text{(by infinite distributivity)}\\\\\n\\bigsqcap^{\\mathfrak{Z}}\\setcond{x\\sqcup^{\\mathfrak{Z}}y}{x\\in\\up a,y\\in\\up b}=\\top & \\Leftarrow\\\\\n\\forall x\\in\\up a,y\\in\\up b:x\\sqcup^{\\mathfrak{Z}}y=\\top & \\Leftrightarrow\\text{(by binary join-closedness of the core)}\\\\\n\\forall x\\in\\up a,y\\in\\up b:x\\sqcup^{\\mathfrak{A}}y=\\top & \\Leftarrow\\\\\na\\sqcup^{\\mathfrak{A}}b=\\top.\n\\end{align*}\n\n\n\\end{description}\n\\end{proof}\n\n\\section{Complements and Core Parts}\n\\begin{lem}\nIf $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered, up-aligned filtrator\nwith co-separable core which is a complete lattice, then for any $a,c\\in\\mathfrak{A}$\n\\[\nc\\equiv^{\\mathfrak{A}}a\\Leftrightarrow c\\equiv^{\\mathfrak{A}}\\Cor a.\n\\]\n\\end{lem}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] If $c\\equiv^{\\mathfrak{A}}a$ then by co-separability\nof the core exists $K\\in\\down a$ such that $c\\equiv^{\\mathfrak{A}}K$.\nTo finish the proof we will show that $K\\sqsubseteq\\Cor a$. To show\nthis is enough to show that $\\forall X\\in\\up a:K\\sqsubseteq X$ what\nis obvious.\n\\item [{$\\Leftarrow$}] $\\Cor a\\sqsubseteq a$ (by theorem~\\ref{cor-less}\nusing that our filtrator is filtered).\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{cocompl-cor}If $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\nup-aligned complete lattice filtrator with co-separable core which\nis a complete boolean lattice, then $a^{+}=\\overline{\\Cor a}$ for\nevery $a\\in\\mathfrak{A}$.\\end{thm}\n\\begin{proof}\nOur filtrator is with join-closed core (theorem \\ref{semifilt-joinclosed}).\n\\begin{align*}\na^{+} & =\\\\\n\\bigsqcap^{\\mathfrak{A}}\\setcond{c\\in\\mathfrak{A}}{c\\sqcup^{\\mathfrak{A}}a=\\top^{\\mathfrak{A}}} & =\\\\\n\\bigsqcap^{\\mathfrak{A}}\\setcond{c\\in\\mathfrak{A}}{c\\sqcup^{\\mathfrak{A}}\\Cor a=\\top^{\\mathfrak{A}}} & =\\\\\n\\bigsqcap^{\\mathfrak{A}}\\setcond{c\\in\\mathfrak{A}}{c\\sqsupseteq\\overline{\\Cor a}} & =\\\\\n\\overline{\\Cor a}\n\\end{align*}\n(used the lemma above and lemma~\\ref{bool-compl}).\\end{proof}\n\\begin{cor}\nIf $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered up-aligned complete\nlattice filtrator with co-separable core which is a complete boolean\nlattice, then $a^{+}\\in\\mathfrak{Z}$ for every $a\\in\\mathfrak{A}$.\\end{cor}\n\\begin{thm}\\label{compl-and-cor}\n~\n\\begin{enumerate}\n\\item \\label{compl-and-cor-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{compl-and-cor-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a complete boolean lattice.\n\\item \\label{compl-and-cor-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\ncomplete lattice filtrator with down-aligned, binarily meet-closed,\nseparable core which is a complete boolean lattice.\n\\item \\label{compl-and-cor-res} $a^{\\ast}=\\overline{\\Cor a}=\\overline{\\Cor'a}$\nfor every $a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n\\item [\\ref{compl-and-cor-p}$\\Rightarrow$\\ref{compl-and-cor-f}] Obvious.\n\\item [\\ref{compl-and-cor-f}$\\Rightarrow$\\ref{compl-and-cor-fltr}]\nIt is filtered by theorem~\\ref{semifilt-joinclosed}. It is complete lattice filtrator by~\\ref{filt-is-complete}.\nIt is with binarily meet-closed core (proposition~\\ref{f-meet-closed}),\nwith separable core (theorem~\\ref{when-sep-core}).\n\\item [\\ref{compl-and-cor-fltr}$\\Rightarrow$\\ref{compl-and-cor-res}]\nOur filtrator is with join-closed core (theorem \\ref{semifilt-joinclosed}).\n\\[ a^{\\ast}=\\bigsqcup^{\\mathfrak{A}}\\setcond{c\\in\\mathfrak{A}}{c\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}. \\]\nBut \\[c\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}\\Rightarrow\\exists C\\in\\up c:C\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}.\\]\nSo\n\\begin{align*}\na^{\\ast} & =\\\\\n\\bigsqcup^{\\mathfrak{A}}\\setcond{C\\in\\mathfrak{Z}}{C\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}} & =\\\\\n\\bigsqcup^{\\mathfrak{A}}\\setcond{C\\in\\mathfrak{Z}}{a\\sqsubseteq\\overline{C}} & =\\\\\n\\bigsqcup^{\\mathfrak{A}}\\setcond{\\overline{C}}{C\\in\\mathfrak{Z},a\\sqsubseteq C} & =\\\\\n\\bigsqcup^{\\mathfrak{A}}\\setcond{\\overline{C}}{C\\in\\up a} & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}\\setcond{\\overline{C}}{C\\in\\up a} & =\\\\\n\\overline{\\bigsqcap^{\\mathfrak{Z}}\\setcond C{C\\in\\up a}} & =\\\\\n\\overline{\\bigsqcap^{\\mathfrak{Z}}\\up a} & =\\\\\n\\overline{\\Cor a}\n\\end{align*}\n(used lemma~\\ref{bool-compl}).\n\n$\\Cor a=\\Cor'a$ by theorem \\ref{cor-eq}.\\end{proof}\n\\begin{thm}\n\\label{compl-eq-dual}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{compl-eq-dual-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{compl-eq-dual-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete boolean lattice.\n\\item \\label{compl-eq-dual-det}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered down-aligned and up-aligned\ncomplete lattice filtrator with binarily meet-closed, separable and\nco-separable core which is a complete boolean lattice.\n\\item \\label{compl-eq-dual-conc}$a^{\\ast}=a^{+}=\\overline{\\Cor a}=\\overline{\\Cor' a}\\in\\mathfrak{Z}$ for\nevery $a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{compl-eq-dual-p}$\\Rightarrow$\\ref{compl-eq-dual-fltr}}] Obvious.\n\\item [{\\ref{compl-eq-dual-fltr}$\\Rightarrow$\\ref{compl-eq-dual-det}}] The\nfiltrator $(\\mathfrak{A},\\mathfrak{Z})$ is filtered by the theorem~\\ref{semifilt-joinclosed}.\n$\\mathfrak{A}$ is a complete lattice by corollary \\ref{filt-is-complete}.\n$(\\mathfrak{A},\\mathfrak{Z})$ is with co-separable core by theorem\n\\ref{cosep-crit}.\n$(\\mathfrak{A},\\mathfrak{Z})$ is\nbinarily meet-closed by proposition \\ref{f-meet-closed}, with separable\ncore by theorem~\\ref{when-sep-core}.\n\n\\item [{\\ref{compl-eq-dual-det}$\\Rightarrow$\\ref{compl-eq-dual-conc}}] Comparing two last theorems.\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{compl-in-core}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{compl-in-core-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete lattice.\n\\item \\label{compl-in-core-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a complete\nlattice filtrator with join-closed separable core which is a complete\nlattice.\n\\item \\label{compl-in-core-conc}$a^{\\ast}\\in\\mathfrak{Z}$ for every $a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{compl-in-core-f}$\\Rightarrow$\\ref{compl-in-core-fltr}}] $\\mathfrak{A}$\nis a complete lattice by corollary~\\ref{filt-is-complete}. $(\\mathfrak{A},\\mathfrak{Z})$\nis a filtrator with join-closed core by theorem~\\ref{semifilt-joinclosed}.\n$(\\mathfrak{A},\\mathfrak{Z})$ is a filtrator with separable core\nby theorem~\\ref{when-sep-core}.\n\\item [{\\ref{compl-in-core-fltr}$\\Rightarrow$\\ref{compl-in-core-conc}}] $\\setcond{c\\in\\mathfrak{A}}{c\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}\\supseteq\\setcond{A\\in\\mathfrak{Z}}{A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}$;\nconsequently $a^{\\ast}\\sqsupseteq\\bigsqcup^{\\mathfrak{A}}\\setcond{A\\in\\mathfrak{Z}}{A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}$.\n\n\nBut if $c\\in\\setcond{c\\in\\mathfrak{A}}{c\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}$\nthen there exists $A\\in\\mathfrak{Z}$ such that $A\\sqsupseteq c$\nand $A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}$ that is $A\\in\\setcond{A\\in\\mathfrak{Z}}{A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}$.\nConsequently $a^{\\ast}\\sqsubseteq\\bigsqcup^{\\mathfrak{A}}\\setcond{A\\in\\mathfrak{Z}}{A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}$.\n\n\nWe have $a^{\\ast}=\\bigsqcup^{\\mathfrak{A}}\\setcond{A\\in\\mathfrak{Z}}{A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}=\\bigsqcup^{\\mathfrak{Z}}\\setcond{A\\in\\mathfrak{Z}}{A\\sqcap^{\\mathfrak{A}}a=\\bot^{\\mathfrak{A}}}\\in\\mathfrak{Z}$.\n\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{dual-compl-pseudo}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{dual-compl-pseudo-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{dual-compl-pseudo-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete boolean lattice.\n\\item \\label{dual-compl-pseudo-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is an\nup-aligned filtered complete lattice filtrator with co-separable core\nwhich is a complete boolean lattice.\n\\item \\label{dual-compl-pseudo-conc}$a^{+}$ is dual pseudocomplement of\n$a$, that is\n\\[\na^{+}=\\min\\setcond{c\\in\\mathfrak{A}}{c\\sqcup^{\\mathfrak{A}}a=\\top^{\\mathfrak{A}}}\n\\]\nfor every $a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{dual-compl-pseudo-p}$\\Rightarrow$\\ref{dual-compl-pseudo-f}}] Obvious.\n\\item [{\\ref{dual-compl-pseudo-f}$\\Rightarrow$\\ref{dual-compl-pseudo-fltr}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis filtered by the theorem~\\ref{semifilt-joinclosed}. It is with\nco-separable core by theorem~\\ref{cosep-crit}. $\\mathfrak{A}$ is\na complete lattice by corollary \\ref{filt-is-complete}.\n\\item [{\\ref{dual-compl-pseudo-fltr}$\\Rightarrow$\\ref{dual-compl-pseudo-conc}}] Our\nfiltrator is with join-closed core (theorem \\ref{semifilt-joinclosed}).\nIt's enough to prove that $a^{+}\\sqcup^{\\mathfrak{A}}a=\\top^{\\mathfrak{A}}$.\nBut $a^{+}\\sqcup^{\\mathfrak{A}}a=\\overline{\\Cor a}\\sqcup^{\\mathfrak{A}}a\\sqsupseteq\\overline{\\Cor a}\\sqcup^{\\mathfrak{A}}\\Cor a=\\overline{\\Cor a}\\sqcup^{\\mathfrak{Z}}\\Cor a=\\top^{\\mathfrak{A}}$\n(used the theorem \\ref{cor-less} and the fact that our filtrator\nis filtered).\n\\end{description}\n\\end{proof}\n\\begin{defn}\n\\index{edge part}The \\emph{edge part} of an element $a\\in\\mathfrak{A}$\nis $\\Edg a=a\\setminus\\Cor a$, the \\emph{dual edge part} is $\\Edg'a=a\\setminus\\Cor'a$.\n\\end{defn}\nKnowing core part and edge part or dual core part and dual edge part\nof an element of a filtrator, the filter can be restored by the formulas:\n\\[\na=\\Cor a\\sqcup^{\\mathfrak{A}}\\Edg a\\quad\\text{and}\\quad a=\\Cor'a\\sqcup^{\\mathfrak{A}}\\Edg'a.\n\\]\n\n\\section{Core Part and Atomic Elements}\n\\begin{prop}\n\\label{cor-join-atom}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{cor-join-atom-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{cor-join-atom-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover an atomistic lattice.\n\\item \\label{cor-join-atom-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtrator\nwith join-closed core and $\\mathfrak{Z}$ be an atomistic lattice.\n\\item \\label{cor-join-atom-conc}$\\Cor'a=\\bigsqcup^{\\mathfrak{Z}}\\setcond x{x\\text{ is an atom of }\\mathfrak{Z},x\\sqsubseteq a}$\nfor every $a\\in\\mathfrak{A}$ such that $\\Cor'a$ exists.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cor-join-atom-p}$\\Rightarrow$\\ref{cor-join-atom-f}}] Obvious.\n\\item [{\\ref{cor-join-atom-f}$\\Rightarrow$\\ref{cor-join-atom-fltr}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis with join-closed core by corollary \\ref{semifilt-joinclosed}.\n\\item [{\\ref{cor-join-atom-fltr}$\\Rightarrow$\\ref{cor-join-atom-conc}}] ~\n\\begin{align*}\n\\Cor'a & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}\\setcond{A\\in\\mathfrak{Z}}{A\\sqsubseteq a} & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}\\setcond{\\bigsqcup^{\\mathfrak{Z}}\\atoms^{\\mathfrak{Z}}A}{A\\in\\mathfrak{Z},A\\sqsubseteq a} & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}\\bigcup\\setcond{\\atoms^{\\mathfrak{Z}}A}{A\\in\\mathfrak{Z},A\\sqsubseteq a} & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}\\setcond x{x\\text{ is an atom of }\\mathfrak{Z},x\\sqsubseteq a}.\n\\end{align*}\n\n\\end{description}\n\\end{proof}\n\\begin{cor}\n$\\Cor a=\\uparrow\\setcond{p\\in\\mathfrak{U}}{\\uparrow\\{p\\}\\sqsubseteq a}$\nand $\\bigcap a=\\setcond{p\\in\\mathfrak{U}}{\\uparrow\\{p\\}\\sqsubseteq a}$\nfor every filter $a$ on a set $\\mathfrak{U}$.\\end{cor}\n\\begin{proof}\nBy proposition \\ref{dcor-eq-cor}.\n\\end{proof}\n\n\\section{Distributivity of Core Part over Lattice Operations}\n\\begin{thm}\n\\label{dual-cor-meet}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{dual-cor-meet-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{dual-cor-meet-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete lattice.\n\\item \\label{dual-cor-meet-mlat}$(\\mathfrak{A},\\mathfrak{Z})$ is a join-closed\nfiltrator and $\\mathfrak{A}$ is a meet-semilattice and $\\mathfrak{Z}$\nis a meet-semilattice.\n\\item \\label{dual-cor-meet-conc}$\\Cor'(a\\sqcap^{\\mathfrak{A}}b)=\\Cor'a\\sqcap^{\\mathfrak{Z}}\\Cor'b$\nfor every $a,b\\in\\mathfrak{A}$.\nwhenever $\\Cor'(a\\sqcap^{\\mathfrak{A}}b)$, $\\Cor'a$, and\n$\\Cor'b$ exist\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{dual-cor-meet-p}$\\Rightarrow$\\ref{dual-cor-meet-f}}] Obvious.\n\\item [{\\ref{dual-cor-meet-f}$\\Rightarrow$\\ref{dual-cor-meet-mlat}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis with join-closed core by corollary \\ref{semifilt-joinclosed}.\n$\\mathfrak{A}$ is a meet-semilattice by corollary \\ref{filt-is-complete}.\n\\item [{\\ref{dual-cor-meet-mlat}$\\Rightarrow$\\ref{dual-cor-meet-conc}}] We have $\\Cor'p\\sqsubseteq p$ for every $p\\in\\mathfrak{A}$ whenever $\\Cor'p$ exists, because\nour filtrator is with join-closed core (theorem~\\ref{f-cor-max}).\n\n\nObviously $\\Cor'(a\\sqcap^{\\mathfrak{A}}b)\\sqsubseteq\\Cor'a$ and $\\Cor'(a\\sqcap^{\\mathfrak{A}}b)\\sqsubseteq\\Cor'b$.\n\n\nIf $x\\sqsubseteq\\Cor'a$ and $x\\sqsubseteq\\Cor'b$ for some $x\\in\\mathfrak{Z}$\nthen $x\\sqsubseteq a$ and $x\\sqsubseteq b$, thus $x\\sqsubseteq a\\sqcap^{\\mathfrak{A}}b$\nand $x\\sqsubseteq\\Cor'(a\\sqcap^{\\mathfrak{A}}b)$.\n\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{dual-cor-inf-meet}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{cor-inf-meet-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{cor-inf-meet-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a complete lattice.\n\\item \\label{cor-inf-meet-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a join-closed\nfiltrator.\n\\item \\label{cor-inf-meet-conc}$\\Cor'\\bigsqcap^{\\mathfrak{A}}S=\\bigsqcap^{\\mathfrak{Z}}\\rsupfun{\\Cor'}S$\nfor every $S\\in\\subsets\\mathfrak{A}$\nwhenever both sides of the equality are defined.\nAlso $\\Cor'\\bigsqcap^{\\mathfrak{A}}T=\\bigsqcap^{\\mathfrak{Z}}T$\nfor every $T\\in\\subsets\\mathfrak{Z}$\nwhenever both sides of the equality are defined.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cor-inf-meet-p}$\\Rightarrow$\\ref{cor-inf-meet-f}}] Obvious.\n\\item [{\\ref{cor-inf-meet-f}$\\Rightarrow$\\ref{cor-inf-meet-fltr}}] It\nis with join-closed core by theorem~\\ref{semifilt-joinclosed}.\n$\\mathfrak{A}$ is a complete lattice by corollary \\ref{filt-is-complete}.\n\\item [{\\ref{cor-inf-meet-fltr}$\\Rightarrow$\\ref{cor-inf-meet-conc}}] We have $\\Cor'p\\sqsubseteq p$ for every $p\\in\\mathfrak{A}$ because\nour filtrator is with join-closed core (theorem~\\ref{f-cor-max}).\n\n\nObviously $\\Cor'\\bigsqcap^{\\mathfrak{A}}S\\sqsubseteq\\Cor'a$ for every\n$a\\in S$.\n\n\nIf $x\\sqsubseteq\\Cor'a$ for every $a\\in S$ for some $x\\in\\mathfrak{Z}$\nthen $x\\sqsubseteq a$, thus $x\\sqsubseteq\\bigsqcap^{\\mathfrak{A}}S$\nand $x\\sqsubseteq\\Cor'\\bigsqcap^{\\mathfrak{A}}S$.\n\n\nSo $\\Cor'\\bigsqcap^{\\mathfrak{A}}S=\\bigsqcap^{\\mathfrak{Z}}\\rsupfun{\\Cor'}S$.\n$\\Cor'\\bigsqcap^{\\mathfrak{A}}T=\\bigsqcap^{\\mathfrak{Z}}T$ trivially\nfollows from this.\n\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{dual-core-join}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{dual-core-join-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{dual-core-join-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete atomistic distributive lattice.\n\\item \\label{dual-core-join-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\ndown-aligned filtrator with binarily meet-closed core $\\mathfrak{Z}$\nwhich is a complete atomistic lattice and $\\mathfrak{A}$ is a complete\nstarrish lattice.\n\\item \\label{dual-core-join-conc}$\\Cor'(a\\sqcup^{\\mathfrak{A}}b)=\\Cor'a\\sqcup^{\\mathfrak{Z}}\\Cor'b$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{dual-core-join-p}$\\Rightarrow$\\ref{dual-core-join-f}}] Obvious.\n\\item [{\\ref{dual-core-join-f}$\\Rightarrow$\\ref{dual-core-join-fltr}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis filtered by theorem~\\ref{semifilt-joinclosed}. It is with binarily\nmeet-close core by corollary~\\ref{f-meet-closed}. $\\mathfrak{A}$ is starrish\nby corollary \\ref{filt-also-distr}. $\\mathfrak{A}$ is complete by\ncorollary~\\ref{filt-is-complete}.\n\\item [{\\ref{dual-core-join-fltr}$\\Rightarrow$\\ref{dual-core-join-conc}}] From\ntheorem conditions it follows that $\\Cor'(a\\sqcup^{\\mathfrak{A}}b)$\nexists.\n\n\n$\\Cor'(a\\sqcup^{\\mathfrak{A}}b)=\\bigsqcup^{\\mathfrak{Z}}\\setcond x{x\\text{ is an atom of }\\mathfrak{Z},x\\sqsubseteq a\\sqcup^{\\mathfrak{A}}b}$\n(used proposition \\ref{cor-join-atom}).\n\n\nBy theorem \\ref{atom-both} we have\n\\begin{align*}\n\\Cor'(a\\sqcup^{\\mathfrak{A}}b) & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}((\\atoms^{\\mathfrak{A}}(a\\sqcup^{\\mathfrak{A}}b))\\cap\\mathfrak{Z}) & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}((\\atoms^{\\mathfrak{A}}a\\cup\\atoms^{\\mathfrak{A}}b)\\cap\\mathfrak{Z}) & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}((\\atoms^{\\mathfrak{A}}a\\cap\\mathfrak{Z})\\cup(\\atoms^{\\mathfrak{A}}b\\cap\\mathfrak{Z})) & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}(\\atoms^{\\mathfrak{A}}a\\cap\\mathfrak{Z})\\sqcup^{\\mathfrak{Z}}\\bigsqcup^{\\mathfrak{Z}}(\\atoms^{\\mathfrak{A}}b\\cap\\mathfrak{Z})\n\\end{align*}\n(used the theorem \\ref{atoms-join}). Again using theorem \\ref{atom-both},\nwe get\n\\begin{align*}\n\\Cor'(a\\sqcup^{\\mathfrak{A}}b) & =\\\\\n\\bigsqcup^{\\mathfrak{Z}}\\setcond x{x\\text{ is an atom of }\\mathfrak{Z},x\\sqsubseteq a}\\sqcup^{\\mathfrak{Z}}\\bigsqcup^{\\mathfrak{Z}}\\setcond x{x\\text{ is an atom of }\\mathfrak{Z},x\\sqsubseteq b} & =\\\\\n\\Cor'a\\sqcup^{\\mathfrak{Z}}\\Cor'b\n\\end{align*}\n(again used proposition \\ref{cor-join-atom}).\n\n\\end{description}\n\\end{proof}\n\nSee also theorem~\\ref{dpdfiff-meet} above.\n\n\\section{Separability criteria}\n\\begin{thm}\n\\label{f-intrs-and-compl}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{intrs-compl-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{intrs-compl-prim}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{intrs-compl-filt}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtrator with correct intersection,\nwith binarily meet-closed and separable core.\n\\item \\label{intrs-compl-conc}$B\\asymp^{\\mathfrak{A}}\\mathcal{A}\\Leftrightarrow\\overline{B}\\sqsupseteq\\mathcal{A}$\nfor every $B\\in\\mathfrak{Z}$, $\\mathcal{A}\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{intrs-compl-p}$\\Rightarrow$\\ref{intrs-compl-prim}}] Obvious.\n\\item [{\\ref{intrs-compl-prim}$\\Rightarrow$\\ref{intrs-compl-filt}}] Using\nproposition~\\ref{is-corr-inters}, corollary~\\ref{f-meet-closed}, theorem\n\\ref{when-sep-core}.\n\\item [{\\ref{intrs-compl-filt}$\\Rightarrow$\\ref{intrs-compl-conc}}] By\nthe lemma~\\ref{int-join-lem}.\n\\end{description}\n\\end{proof}\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{join-compl-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{join-compl-prim}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete boolean lattice.\n\\item \\label{join-compl-filt}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtrator over a boolean lattice\nwith correct joining and co-separable core.\n\\item \\label{join-compl-conc}$B\\equiv^{\\mathfrak{A}}\\mathcal{A}\\Leftrightarrow\\overline{B}\\sqsubseteq\\mathcal{A}$\nfor every $B\\in\\mathfrak{Z}$, $\\mathcal{A}\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{join-compl-p}$\\Rightarrow$\\ref{join-compl-prim}}] Obvious.\n\\item [{\\ref{join-compl-prim}$\\Rightarrow$\\ref{join-compl-filt}}] Using\nobvious \\ref{is-corr-join}, theorem \\ref{cosep-crit}.\n\\item [{\\ref{join-compl-filt}$\\Rightarrow$\\ref{join-compl-conc}}] By\nthe lemma~\\ref{int-join-lem}.\n\\end{description}\n\\end{proof}\n\n\\section{Filtrators over Boolean Lattices}\n\\begin{prop}\n\\label{b-bool-minus}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{bool-minus-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{bool-minus-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a boolean lattice.\n\\item \\label{bool-minus-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a down-aligned\nand up-aligned binarily meet-closed and binarily join-closed distributive\nlattice filtrator and $\\mathfrak{Z}$ is a boolean lattice.\n\\item \\label{bool-minus-conc}$a\\setminus{}^{\\mathfrak{A}}B=a\\sqcap^{\\mathfrak{A}}\\overline{B}$\nfor every $a\\in\\mathfrak{A}$, $B\\in\\mathfrak{Z}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{bool-minus-p}$\\Rightarrow$\\ref{bool-minus-f}}] Obvious.\n\\item [{\\ref{bool-minus-f}$\\Rightarrow$\\ref{bool-minus-fltr}}] $\\mathfrak{A}$\nis a distributive lattice by corollary \\ref{filt-also-distr}. Our\nfiltrator is binarily meet-closed by the corollary~\\ref{f-meet-closed}\nand with join-closed core by the theorem \\ref{semifilt-joinclosed}.\nIt is also up and down aligned.\n\\item [{\\ref{bool-minus-fltr}$\\Rightarrow$\\ref{bool-minus-conc}}] ~\n\\begin{gather*}\n(a\\sqcap^{\\mathfrak{A}}\\overline{B})\\sqcup^{\\mathfrak{A}}B=(a\\sqcup^{\\mathfrak{A}}B)\\sqcap^{\\mathfrak{A}}(\\overline{B}\\sqcup^{\\mathfrak{A}}B)=\\\\(a\\sqcup^{\\mathfrak{A}}B)\\sqcap^{\\mathfrak{A}}(\\overline{B}\\sqcup^{\\mathfrak{Z}}B)=(a\\sqcup^{\\mathfrak{A}}B)\\sqcap^{\\mathfrak{A}}\\top=a\\sqcup^{\\mathfrak{A}}B.\\\\\n(a\\sqcap^{\\mathfrak{A}}\\overline{B})\\sqcap^{\\mathfrak{A}}B=a\\sqcap^{\\mathfrak{A}}(\\overline{B}\\sqcap^{\\mathfrak{A}}B)=a\\sqcap^{\\mathfrak{A}}(\\overline{B}\\sqcap^{\\mathfrak{Z}}B)=a\\sqcap^{\\mathfrak{A}}\\bot=\\bot.\n\\end{gather*}\nSo $a\\sqcap^{\\mathfrak{A}}\\overline{B}$ is the difference of $a$\nand $B$.\n\\end{description}\n\\end{proof}\n\n\\begin{prop}\nFor a primary filtrator over a complete boolean lattice both edge\npart and dual edge part are always defined.\\end{prop}\n\\begin{proof}\nCore part and dual core part are defined because the core is a complete\nlattice. Using the theorem \\ref{b-bool-minus}.\\end{proof}\n\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item\\label{filt-pseud-filt} $(\\mathfrak{A}, \\mathfrak{Z})$ is a primary filtrator over a boolean lattice.\n\\item\\label{filt-pseud-fltr} $(\\mathfrak{A}, \\mathfrak{Z})$ is a complete co-brouwerian atomistic\n  down-aligned lattice filtrator with binarily meet-closed and separable boolean core.\n\\item\\label{filt-pseud-res} The three expressions of pseudodifference of~$a$ and~$b$ in theorem~\\ref{pdiff-eq1} are also equal to\n  $\\bigsqcup \\setcond{ a \\sqcap \\overline{B} }{ B \\in \\up b }$.\n\\end{enumerate}\n\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item[\\ref{filt-pseud-filt}$\\Rightarrow$\\ref{filt-pseud-fltr}]\n  The filtrator of filters on a boolean lattice is:\n  \\begin{itemize}\n  \\item complete by corollary~\\ref{filt-is-complete};\n  \\item atomistic by theorem~\\ref{filt-atomistic};\n  \\item co-brouwerian by corollary~\\ref{filt-also-distr};\n  \\item with separable core by theorem~\\ref{when-sep-core};\n  \\item with binarily meet-closed core by corollary~\\ref{f-meet-closed}.\n  \\end{itemize}\n\n\\item[\\ref{filt-pseud-fltr}$\\Rightarrow$\\ref{filt-pseud-res}]\n  $\\bigsqcup \\setcond{ z \\in \\mathscr{F} }{ z\n  \\sqsubseteq a \\wedge z \\sqcap b = \\bot } \\sqsubseteq \\bigsqcup\n  \\setcond{ a \\sqcap \\overline{B} }{ B \\in \\up b }$ because\n  \\begin{multline*}\n    z \\in \\setcond{ z \\in \\mathscr{F} }{ z \\sqsubseteq\n    a \\wedge z \\sqcap b = \\bot } \\Leftrightarrow z \\sqsubseteq a \\wedge\n    z \\sqcap b = \\bot \\Leftrightarrow \\text{(separability)}\\\\\n    z \\sqsubseteq a \\wedge \\exists B \\in \\up b : z \\sqcap B = \\bot\n    \\Leftrightarrow \\text{(theorem~\\ref{f-intrs-and-compl})} \\Leftrightarrow z \\sqsubseteq a\n    \\wedge \\exists B \\in \\up b : z \\sqsubseteq \\overline{B}\n    \\Leftrightarrow\\\\\n    \\exists B \\in \\up b : \\left( z \\sqsubseteq a \\wedge z \\sqsubseteq\n    \\overline{B} \\right) \\Leftrightarrow \\exists B \\in \\up b : z\n    \\sqsubseteq a \\sqcap \\overline{B} \\Rightarrow\\\\\n    z \\sqsubseteq \\bigsqcup \\setcond{ a \\sqcap \\overline{B} }{ B \\in \\up b } .\n  \\end{multline*}\n\n  But $a \\sqcap \\overline{B} \\in \\setcond{ z \\in \\mathscr{F} }{ z \\sqsubseteq a \\wedge z \\sqcap b = \\bot }$ because\n  \\[ \\left( a \\sqcap \\overline{B} \\right) \\sqcap b = a \\sqcap \\left(\n     \\overline{B} \\sqcap b \\right) \\sqsubseteq a \\sqcap \\left( \\overline{B}\n     \\sqcap^{\\mathfrak{A}} B \\right) = a \\sqcap \\left( \\overline{B}\n     \\sqcap^{\\mathfrak{Z}} B \\right) = a \\sqcap \\bot = \\bot \\]\n  and thus\n  \\[ a \\sqcap \\overline{B} \\sqsubseteq \\bigsqcup \\setcond{ z \\in \\mathscr{F}\n     }{ z \\sqsubseteq a \\wedge z \\sqcap b = \\bot\n     } \\]\n  so $\\bigsqcup \\setcond{ z \\in \\mathscr{F} }{ z\n  \\sqsubseteq a \\wedge z \\sqcap b = \\bot } \\sqsupseteq \\bigsqcup\n  \\setcond{ a \\sqcap \\overline{B} }{ B \\in \\up b\n  }$.\n\\end{widedisorder}\n\\end{proof}\n\n\\section{Distributivity for an Element of Boolean Core}\n\\begin{lem}\n\\label{bb-bool-adj}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{bool-adj-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{bool-adj-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator\nover a boolean lattice.\n\\item \\label{bool-adj-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is an up-aligned\nbinarily join-closed and binarily meet-closed distributive lattice\nfiltrator over a boolean lattice.\n\\item \\label{bool-adj-conc}$A\\sqcap^{\\mathfrak{A}}$ is a lower adjoint\nof $\\overline{A}\\sqcup^{\\mathfrak{A}}$ for every $A\\in\\mathfrak{Z}$.\n\\end{enumerate}\n\\end{lem}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{bool-adj-p}$\\Rightarrow$\\ref{bool-adj-f}}] Obvious.\n\\item [{\\ref{bool-adj-f}$\\Rightarrow$\\ref{bool-adj-fltr}}] It is binarily join closed by theorem~\\ref{semifilt-joinclosed}.\nIt is binarily meet-closed by corollary~\\ref{f-meet-closed}. It is distributive by\ncorollary~\\ref{filt-also-distr}.\n\\item [{\\ref{bool-adj-fltr}$\\Rightarrow$\\ref{bool-adj-conc}}] We will\nuse the theorem \\ref{galois-second}.\n\n\nThat $A\\sqcap^{\\mathfrak{A}}$ and $\\overline{A}\\sqcup^{\\mathfrak{A}}$\nare monotone is obvious.\n\n\nWe need to prove (for every $x,y\\in\\mathfrak{A}$) that\n\\[\nx\\sqsubseteq\\overline{A}\\sqcup^{\\mathfrak{A}}(A\\sqcap^{\\mathfrak{A}}x)\\quad\\text{and}\\quad A\\sqcap^{\\mathfrak{A}}(\\overline{A}\\sqcup^{\\mathfrak{A}}y)\\sqsubseteq y.\n\\]\n\n\n\nReally,\n\\begin{multline*}\n\\overline{A}\\sqcup^{\\mathfrak{A}}(A\\sqcap^{\\mathfrak{A}}x)=(\\overline{A}\\sqcup^{\\mathfrak{A}}A)\\sqcap^{\\mathfrak{A}}(\\overline{A}\\sqcup^{\\mathfrak{A}}x)=\\\\\n(\\overline{A}\\sqcup^{\\mathfrak{Z}}A)\\sqcap^{\\mathfrak{A}}(\\overline{A}\\sqcup^{\\mathfrak{A}}x)=\\top\\sqcap^{\\mathfrak{A}}(\\overline{A}\\sqcup^{\\mathfrak{A}}x)=\\overline{A}\\sqcup^{\\mathfrak{A}}x\\sqsupseteq x\n\\end{multline*}\n\n\n\nand\n\\begin{multline*}\nA\\sqcap^{\\mathfrak{A}}(\\overline{A}\\sqcup^{\\mathfrak{A}}y)=(A\\sqcap^{\\mathfrak{A}}\\overline{A})\\sqcup^{\\mathfrak{A}}(A\\sqcap^{\\mathfrak{A}}y)=(A\\sqcap^{\\mathfrak{Z}}\\overline{A})\\sqcup^{\\mathfrak{A}}(A\\sqcap^{\\mathfrak{A}}y)=\\\\\n\\bot\\sqcup^{\\mathfrak{A}}(A\\sqcap^{\\mathfrak{A}}y)=A\\sqcap^{\\mathfrak{A}}y\\sqsubseteq y.\n\\end{multline*}\n\n\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{b-f-back-distr}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{f-back-distr-p}($\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{f-back-distr-f}($\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over\na boolean lattice.\n\\item \\label{f-back-distr-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is an up-aligned\nbinarily join-closed and binarily meet-closed distributive lattice\nfiltrator over a boolean lattice.\n\\item \\label{f-back-distr-conc}$A\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{A}}\\rsupfun{A\\sqcap^{\\mathfrak{A}}}S$\nfor every $A\\in\\mathfrak{Z}$ and every set $S\\in\\subsets\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{f-back-distr-p}$\\Rightarrow$\\ref{f-back-distr-f}}] Obvious.\n\\item [{\\ref{f-back-distr-f}$\\Rightarrow$\\ref{f-back-distr-fltr}}] It is binarily join-closed by theorem~\\ref{semifilt-joinclosed}.\nIt is binarily meet-closed by corollary~\\ref{f-meet-closed}. It is distributive by\ncorollary~\\ref{filt-also-distr}.\n\\item [{\\ref{f-back-distr-fltr}$\\Rightarrow$\\ref{f-back-distr-conc}}] Direct\nconsequence of the lemma.\n\\end{description}\n\\end{proof}\n\n\\section{More about the Lattice of Filters}\n\\begin{defn}\n\\index{ultrafilter}Atoms of $\\mathfrak{F}$ are called \\emph{ultrafilters}.\n\\end{defn}\n\n\\begin{defn}\n\\index{ultrafilter!trivial}Principal ultrafilters are also called\n\\emph{trivial ultrafilters}.\\end{defn}\n\\begin{thm}\n\\label{pow-filt-central}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{filt-central-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{filt-central-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{filt-central-conc}The filtrator $(\\mathfrak{A},\\mathfrak{Z})$\nis central.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{filt-central-p}$\\Rightarrow$\\ref{filt-central-fltr}}] Obvious.\n\\item [{\\ref{filt-central-fltr}$\\Rightarrow$\\ref{filt-central-conc}}] We\ncan conclude that $\\mathfrak{A}$ is atomically separable (the corollary\n\\ref{f-atom-sep}), with separable core (the theorem \\ref{when-sep-core}),\nand with join-closed core (theorem~\\ref{semifilt-joinclosed}),\nbinarily meet-closed by corollary~\\ref{f-meet-closed}.\n\n\nWe need to prove $Z(\\mathfrak{A})=\\mathfrak{Z}$.\n\n\nLet $\\mathcal{X}\\in Z(\\mathfrak{A})$. Then there exists $\\mathcal{Y}\\in Z(\\mathfrak{A})$\nsuch that $\\mathcal{X}\\sqcap^{\\mathfrak{A}}\\mathcal{Y}=\\bot^{\\mathfrak{A}}$\nand $\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\mathcal{Y}=\\top^{\\mathfrak{A}}$.\nConsequently there is $X\\in\\up\\mathcal{X}$ such that $X\\sqcap^{\\mathfrak{A}}\\mathcal{Y}=\\bot^{\\mathfrak{A}}$;\nwe also have $X\\sqcup^{\\mathfrak{A}}\\mathcal{Y}=\\top^{\\mathfrak{A}}$.\nSuppose $X\\sqsupset\\mathcal{X}$. Then there exists $a\\in\\atoms^{\\mathfrak{A}}X$\nsuch that $a\\notin\\atoms^{\\mathfrak{A}}\\mathcal{X}$. We can conclude\nalso $a\\notin\\atoms^{\\mathfrak{A}}\\mathcal{Y}$ (otherwise $X\\sqcap^{\\mathfrak{A}}\\mathcal{Y}\\ne\\bot^{\\mathfrak{A}}$).\nThus $a\\notin\\atoms(\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\mathcal{Y})$\nand consequently $\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\mathcal{Y}\\ne\\top^{\\mathfrak{A}}$\nwhat is a contradiction. We have $\\mathcal{X}=X\\in\\mathfrak{Z}$.\n\n\nLet now $X\\in\\mathfrak{Z}$. Let $Y=\\overline{X}$. We have $X\\sqcap^{\\mathfrak{Z}}Y=\\bot^{\\mathfrak{A}}$\nand $X\\sqcup^{\\mathfrak{Z}}Y=\\top^{\\mathfrak{A}}$. Thus $X\\sqcap^{\\mathfrak{A}}Y=\\bigsqcap^{\\mathfrak{A}}\\{X\\sqcap^{\\mathfrak{Z}}Y\\}=\\bot^{\\mathfrak{A}}$;\n$X\\sqcap^{\\mathfrak{A}}Y=X\\sqcap^{\\mathfrak{Z}}Y=\\top^{\\mathfrak{A}}$.\nWe have shown that $X\\in Z(\\mathfrak{A})$.\n\n\\end{description}\n\\end{proof}\n\n\\section{More Criteria}\n\\begin{thm}\n\\label{closed-free-star}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{closed-free-star-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{closed-free-star-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a\nprimary filtrator over a boolean lattice.\n\\item \\label{closed-free-star-conc}For every $S\\in\\subsets\\mathfrak{A}$\nthe condition $\\exists\\mathcal{F}\\in\\mathfrak{A}:S=\\fullstar\\mathcal{F}$\nis equivalent to conjunction of the following items:\n\n\\begin{enumerate}\n\\item \\label{fs-star}$S$ is a free star on $\\mathfrak{A}$;\n\\item \\label{fs-fclos}$S$ is filter-closed.\n\\end{enumerate}\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{closed-free-star-p}$\\Rightarrow$\\ref{closed-free-star-fltr}}] Obvious.\n\\item [{\\ref{closed-free-star-fltr}$\\Rightarrow$\\ref{closed-free-star-conc}}] ~\n\n\\begin{description}\n\\item [{$\\Rightarrow$}] ~\n\n\\begin{widedisorder}\n\\item [{\\ref{fs-star}}] That $\\bot^{\\mathfrak{A}}\\notin\\fullstar\\mathcal{F}$\nis obvious. For every $a,b\\in\\mathfrak{A}$\n\\begin{align*}\na\\sqcup^{\\mathfrak{A}}b\\in\\fullstar\\mathcal{F} & \\Leftrightarrow\\\\\n(a\\sqcup^{\\mathfrak{A}}b)\\sqcap^{\\mathfrak{A}}\\mathcal{F}\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\n(a\\sqcap^{\\mathfrak{A}}\\mathcal{F})\\sqcup^{\\mathfrak{A}}(b\\sqcap^{\\mathfrak{A}}\\mathcal{F})\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\na\\sqcap^{\\mathfrak{A}}\\mathcal{F}\\ne\\bot^{\\mathfrak{A}}\\lor b\\sqcap^{\\mathfrak{A}}\\mathcal{F}\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\na\\in\\fullstar\\mathcal{F}\\lor\\in\\fullstar\\mathcal{F}\n\\end{align*}\n(taken into account corollary \\ref{filt-also-distr}). So $\\fullstar\\mathcal{F}$\nis a free star on $\\mathfrak{A}$.\n\\item [{\\ref{fs-fclos}}] We have a filter base $T\\subseteq S$ and need to prove that\n$\\bigsqcap^{\\mathfrak{A}}T\\sqcap\\mathcal{F}\\ne\\bot^{\\mathfrak{A}}$.\nBecause $\\rsupfun{\\mathcal{F}\\sqcap^{\\mathfrak{A}}}T$ is a generalized\nfilter base, $\\bot^{\\mathfrak{A}}\\in\\rsupfun{\\mathcal{F}\\sqcap^{\\mathfrak{A}}}T\\Leftrightarrow\\bigsqcap^{\\mathfrak{A}}\\rsupfun{\\mathcal{F}\\sqcap^{\\mathfrak{A}}}T=\\bot^{\\mathfrak{A}}\\Leftrightarrow\\bigsqcap^{\\mathfrak{A}}T\\sqcap^{\\mathfrak{A}}\\mathcal{F}\\ne\\bot^{\\mathfrak{A}}$.\nSo it is left to prove $\\bot^{\\mathfrak{A}}\\notin\\rsupfun{\\mathcal{F}\\sqcap^{\\mathfrak{A}}}T$\nwhat follows from $T\\subseteq S$.\n\\end{widedisorder}\n\\item [{$\\Leftarrow$}] Let $S$ be a free star on $\\mathfrak{A}$. Then\nfor every $A,B\\in\\mathfrak{Z}$\n\\begin{align*}\nA,B\\in S\\cap\\mathfrak{Z} & \\Leftrightarrow\\\\\nA,B\\in S & \\Leftrightarrow\\\\\nA\\sqcup^{\\mathfrak{A}}B\\in S & \\Leftrightarrow\\\\\nA\\sqcup^{\\mathfrak{Z}}B\\in S & \\Leftrightarrow\\\\\nA\\sqcup^{\\mathfrak{Z}}B\\in S\\cap\\mathfrak{Z}\n\\end{align*}\n(taken into account the theorem \\ref{semifilt-joinclosed}). So $S\\cap\\mathfrak{Z}$\nis a free star on $\\mathfrak{Z}$.\n\n\nThus there exists $\\mathcal{F}\\in\\mathfrak{A}$ such that $\\corestar\\mathcal{F}=S\\cap\\mathfrak{Z}$.\nWe have $\\up\\mathcal{X}\\subseteq S\\Leftrightarrow\\mathcal{X}\\in S$\n(because $S$ is filter-closed) for every $\\mathcal{X}\\in\\mathfrak{A}$;\nthen (taking into account properties of generalized filter bases)\n\\begin{align*}\n\\mathcal{X}\\in S & \\Leftrightarrow\\\\\n\\up\\mathcal{X}\\subseteq S & \\Leftrightarrow\\\\\n\\up\\mathcal{X}\\subseteq\\corestar\\mathcal{F} & \\Leftrightarrow\\\\\n\\forall X\\in\\up\\mathcal{X}:X\\sqcap^{\\mathfrak{A}}\\mathcal{F}\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\n\\bot^{\\mathfrak{A}}\\notin\\rsupfun{\\mathcal{F}\\sqcap^{\\mathfrak{A}}}\\up\\mathcal{X} & \\Leftrightarrow\\\\\n\\bigsqcap^{\\mathfrak{A}}\\rsupfun{\\mathcal{F}\\sqcap^{\\mathfrak{A}}}\\up\\mathcal{X}\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\n\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\bigsqcap^{\\mathfrak{A}}\\up\\mathcal{X}\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\n\\mathcal{F}\\sqcap^{\\mathfrak{A}}\\mathcal{X}\\ne\\bot^{\\mathfrak{A}} & \\Leftrightarrow\\\\\n\\mathcal{X}\\in\\fullstar\\mathcal{F}.\n\\end{align*}\n\n\n\\end{description}\n\\end{description}\n\\end{proof}\n\n\\section{Filters and a Special Sublattice}\n\nRemind that $Z(X)$ is the center of lattice~$X$ and $Da$~is the lattice $\\setcond{x\\in\\mathfrak{A}}{x\\sqsubseteq a}$.\n\n\\begin{thm}\n\\label{core-if-intr}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{core-if-intr-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{core-if-intr-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{core-if-intr-conc}Let $\\mathcal{A}\\in\\mathfrak{A}$. Then\nfor each $\\mathcal{X}\\in\\mathfrak{A}$\n\\[\n\\mathcal{X}\\in Z(D\\mathcal{A})\\Leftrightarrow\\exists X\\in\\mathfrak{Z}:\\mathcal{X}=X\\sqcap^{\\mathfrak{A}}\\mathcal{A}.\n\\]\n\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{core-if-intr-p}$\\Rightarrow$\\ref{core-if-intr-fltr}}] Obvious.\n\\item [{\\ref{core-if-intr-fltr}$\\Rightarrow$\\ref{core-if-intr-conc}}] ~\n\n\\begin{description}\n\\item [{$\\Leftarrow$}] Let $\\mathcal{X}=X\\sqcap^{\\mathfrak{A}}\\mathcal{A}$\nwhere $X\\in\\mathfrak{Z}$. Let also $\\mathcal{Y}=\\overline{X}\\sqcap^{\\mathfrak{A}}\\mathcal{A}$.\nThen \\[\\mathcal{X}\\sqcap^{\\mathfrak{A}}\\mathcal{Y}=X\\sqcap^{\\mathfrak{A}}\\overline{X}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=(X\\sqcap^{\\mathfrak{Z}}\\overline{X})\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\bot^{\\mathfrak{A}}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\bot^{\\mathfrak{A}}\\]\n(used corollary~\\ref{f-meet-closed}) and \\[\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\mathcal{Y}=(X\\sqcup^{\\mathfrak{A}}\\overline{X})\\sqcap^{\\mathfrak{A}}\\mathcal{A}=(X\\sqcup^{\\mathfrak{Z}}\\overline{X})\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\top^{\\mathfrak{A}}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\mathcal{A}\\]\n(used theorem~\\ref{semifilt-joinclosed} and corollary \\ref{filt-also-distr}).\nSo $\\mathcal{X}\\in Z(D\\mathcal{A})$.\n\\item [{$\\Rightarrow$}] Let $\\mathcal{X}\\in Z(D\\mathcal{A})$. Then there\nexists $\\mathcal{Y}\\in Z(D\\mathcal{A})$ such that $\\mathcal{X}\\sqcap^{\\mathfrak{A}}\\mathcal{Y}=\\bot^{\\mathfrak{A}}$\nand $\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\mathcal{Y}=\\mathcal{A}$. Then\n(used theorem \\ref{when-sep-core}) there exists $X\\in\\up\\mathcal{X}$\nsuch that $X\\sqcap^{\\mathfrak{A}}\\mathcal{Y}=\\bot^{\\mathfrak{A}}$.\nWe have\n\\[\n\\mathcal{X}=\\mathcal{X}\\sqcup(X\\sqcap^{\\mathfrak{A}}\\mathcal{Y})=X\\sqcap^{\\mathfrak{A}}(\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\mathcal{Y})=X\\sqcap^{\\mathfrak{A}}\\mathcal{A}.\n\\]\n\n\\end{description}\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\n  The following is an implication tuple:\n  \\begin{enumerate}\n    \\item \\label{fzda-pow} $(\\mathfrak{A}; \\mathfrak{Z})$ is a powerset filtrator.\n\n    \\item \\label{fzda-bool} $(\\mathfrak{A}; \\mathfrak{Z})$ is a primary filtrator over a boolean\n    lattice.\n\n    \\item \\label{fzda-res} $\\mathfrak{F} (Z (D \\mathcal{A}))$ is order-isomorphic to $D\n    \\mathcal{A}$ by the formulas\n    \\begin{itemize}\n      \\item $\\mathcal{Y} = \\bigsqcap \\mathcal{X}$ for every $\\mathcal{X} \\in\n      \\mathfrak{F} (Z (D \\mathcal{A}))$;\n\n      \\item $\\mathcal{X} = \\setcond{ \\mathcal{F} \\in Z (D \\mathcal{A})\n      }{ \\mathcal{F} \\sqsupseteq \\mathcal{Y}\n      }$ for every $\\mathcal{Y} \\in D \\mathcal{A}$.\n    \\end{itemize}\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{widedisorder}\n\n\\item[\\ref{fzda-pow}$\\Rightarrow$\\ref{fzda-bool}]\nObvious.\n\n\\item[\\ref{fzda-bool}$\\Rightarrow$\\ref{fzda-res}]\n  We need to prove that the above formulas define a bijection, then it becomes\n  evident that it's an order isomorphism (take into account that the order of\n  filters is \\emph{reverse} to set inclusion).\n\n  First prove that these formulas describe correspondences between\n  $\\mathfrak{F} (Z (D \\mathcal{A}))$ and $D \\mathcal{A}$.\n\n  Let $\\mathcal{X} \\in \\mathfrak{F} (Z (D \\mathcal{A}))$. Consider\n  $\\mathcal{Y} = \\bigsqcap \\mathcal{X}$. Every element of $\\mathcal{X}$ is\n  below $\\mathcal{A}$, consequently $\\mathcal{Y} \\in D \\mathcal{A}$.\n\n  Let now $\\mathcal{Y} \\in D \\mathcal{A}$. Then $\\setcond{ \\mathcal{F} \\in Z (D\n  \\mathcal{A}) }{ \\mathcal{F} \\sqsupseteq \\mathcal{Y}\n  }$ is a filter.\n\n  It remains to prove that these correspondences are mutually inverse.\n\n  Let $\\mathcal{X} = \\setcond{ \\mathcal{F} \\in Z (D \\mathcal{A}) }{\n  \\mathcal{F} \\sqsupseteq \\mathcal{Y}_0 }$ and\n  $\\mathcal{Y}_1 = \\bigsqcap \\mathcal{X}$ for some $\\mathcal{Y}_0 \\in D\n  \\mathcal{A}$.\n\n  $\\mathcal{Y}_1 \\sqsupseteq \\mathcal{Y}_0$ is obvious. By theorem~\\ref{core-if-intr} and the\n  condition~\\ref{fzda-bool} we have $\\mathcal{Y}_1 = \\bigsqcap \\mathcal{X} \\sqsubseteq\n  \\bigsqcap^{\\mathfrak{A}} \\setcond{ F \\sqcap \\mathcal{A} }{\n  F \\in \\up \\mathcal{Y}_0 } =\n  \\bigsqcap^{\\mathfrak{A}} \\setcond{ F }{ F \\in\n  \\up \\mathcal{Y}_0 } \\sqcap \\mathcal{A} = \\mathcal{Y}_0 \\sqcap\n  \\mathcal{A} = \\mathcal{Y}_0$. So $\\mathcal{Y}_1 = \\mathcal{Y}_0$.\n\n  Let now $\\mathcal{Y} = \\bigsqcap \\mathcal{X}_0$ and $\\mathcal{X}_1 = \\setcond{\n  \\mathcal{F} \\in Z (D \\mathcal{A}) }{ \\mathcal{F}\n  \\sqsupseteq \\mathcal{Y} }$ for some $\\mathcal{X}_0 \\in \\mathfrak{F}\n  (Z (D \\mathcal{A}))$.\n\n  $\\mathcal{X}_1 = \\setcond{ \\mathcal{F} \\in Z (D \\mathcal{A}) }{\n  \\mathcal{F} \\sqsupseteq \\bigsqcap \\mathcal{X}_0 } =\n  \\text{(by generalized filter bases)} = \\setcond{ \\mathcal{F} \\in Z (D\n  \\mathcal{A}) }{ \\exists X \\in \\mathcal{X}_0 :\n  \\mathcal{F} \\sqsupseteq X } = \\setcond{ \\mathcal{F} \\in Z (D\n  \\mathcal{A}) }{ \\mathcal{F} \\in \\mathcal{X}_0\n  } = \\mathcal{X}_0$ because $\\mathcal{F} \\in \\mathcal{X}_0\n  \\Leftrightarrow \\exists X \\in \\mathcal{X}_0 : \\mathcal{F} \\sqsupseteq X$ if\n  $\\mathcal{F} \\in Z (D \\mathcal{A})$.\n\\end{widedisorder}\n\\end{proof}\n\n\n\\section{Distributivity of quasicomplements}\n\\begin{thm}\n\\label{f-compl-meet}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{compl-meet-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{compl-meet-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a complete boolean lattice.\n\\item \\label{compl-meet-dual-det}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered down-aligned and up-aligned\ncomplete lattice filtrator with binarily meet-closed, separable and\nco-separable core which is a complete boolean lattice.\n\\item \\label{compl-meet-conc}$(a\\sqcap^{\\mathfrak{A}}b)^{\\ast}=(a\\sqcap^{\\mathfrak{A}}b)^{+}=a^{\\ast}\\sqcup^{\\mathfrak{A}}b^{\\ast}=a^{+}\\sqcup^{\\mathfrak{A}}b^{+}$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{compl-meet-p}$\\Rightarrow$\\ref{compl-meet-fltr}}] Obvious.\n\n\\item [{\\ref{compl-meet-fltr}$\\Rightarrow$\\ref{compl-meet-dual-det}}] The\nfiltrator $(\\mathfrak{A},\\mathfrak{Z})$ is filtered by the theorem~\\ref{semifilt-joinclosed}.\n$\\mathfrak{A}$ is a complete lattice by corollary \\ref{filt-is-complete}.\n$(\\mathfrak{A},\\mathfrak{Z})$ is with co-separable core by theorem\n\\ref{cosep-crit}.\n$(\\mathfrak{A},\\mathfrak{Z})$ is\nbinarily meet-closed by proposition \\ref{f-meet-closed}, with separable\ncore by theorem~\\ref{when-sep-core}.\n\n\n\\item [{\\ref{compl-meet-dual-det}$\\Rightarrow$\\ref{compl-meet-conc}}]\nTheorem~\\ref{compl-eq-dual} apply.\nAlso theorem~\\ref{dual-cor-meet} apply because every filtered filtrator is join-closed.\nSo\n\\begin{multline*}\n(a\\sqcap^{\\mathfrak{A}}b)^{\\ast}=(a\\sqcap^{\\mathfrak{A}}b)^{+}=\\overline{\\Cor(a\\sqcap^{\\mathfrak{A}}b)}=\\\\\\overline{\\Cor a\\sqcap^{\\mathfrak{Z}}\\Cor b}=\\overline{\\Cor a}\\sqcup^{\\mathfrak{A}}\\overline{\\Cor b}=a^{+}\\sqcup^{\\mathfrak{A}}b^{+}=a^{\\ast}\\sqcup^{\\mathfrak{A}}b^{\\ast}.\n\\end{multline*}\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{uni-join-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{uni-join-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\nstarrish down-aligned and up-aligned complete lattice filtrator with binarily meet-closed,\nseparable and co-separable core which is a complete atomistic boolean lattice.\n\\item \\label{uni-join-conc}$(a\\sqcup^{\\mathfrak{A}}b)^{\\ast}=(a\\sqcup^{\\mathfrak{A}}b)^{+}=a^{\\ast}\\sqcap^{\\mathfrak{A}}b^{\\ast}=a^{+}\\sqcap^{\\mathfrak{A}}b^{+}$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{uni-join-f}$\\Rightarrow$\\ref{uni-join-fltr}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis a filtered (theorem~\\ref{semifilt-joinclosed}), distributive\n(corollary \\ref{filt-also-distr}) complete lattice filtrator (corollary\n\\ref{filt-is-complete}), with binarily meet-closed core (corollary~\\ref{f-meet-closed}),\nwith separable core (theorem~\\ref{when-sep-core}), with co-separable core (theorem~\\ref{cosep-crit}).\n\\item [{\\ref{uni-join-fltr}$\\Rightarrow$\\ref{uni-join-conc}}] $(a\\sqcup^{\\mathfrak{A}}b)^{+}=(a\\sqcup^{\\mathfrak{A}}b)^{\\ast}=\\overline{\\Cor'(a\\sqcup^{\\mathfrak{A}}b)}=\\overline{\\Cor'a\\sqcup^{\\mathfrak{Z}}\\Cor'b}=\\overline{\\Cor'a}\\sqcap^{\\mathfrak{Z}}\\overline{\\Cor'b}=a^{\\ast}\\sqcap^{\\mathfrak{Z}}b^{\\ast}=a^{\\ast}\\sqcap^{\\mathfrak{A}}b^{\\ast}=a^{+}\\sqcap^{\\mathfrak{A}}b^{+}$\n(used theorems~\\ref{compl-and-cor}, \\ref{dual-core-join}, \\ref{compl-eq-dual}).\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{meet-pseudo-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{meet-pseudo-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a complete boolean lattice.\n\\item \\label{meet-pseudo-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\ncomplete lattice filtrator with down-aligned, binarily meet-closed,\nseparable core which is a complete boolean lattice.\n\\item \\label{meet-pseudo-res}$(a\\sqcap^{\\mathfrak{A}}b)^{\\ast}=a^{\\ast}\\sqcup^{\\mathfrak{A}}b^{\\ast}$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [\\ref{meet-pseudo-p}$\\Rightarrow$\\ref{meet-pseudo-f}] Obvious.\n\\item [\\ref{meet-pseudo-f}$\\Rightarrow$\\ref{meet-pseudo-fltr}]\nIt is filtered by theorem~\\ref{semifilt-joinclosed}. It is complete lattice filtrator by~\\ref{filt-is-complete}.\nIt is with binarily meet-closed core (corollary~\\ref{f-meet-closed}),\nwith separable core (theorem~\\ref{when-sep-core}).\n\\item [\\ref{meet-pseudo-fltr}$\\Rightarrow$\\ref{meet-pseudo-res}]\nIt is join closed because it is filtered.\n\\begin{multline*}\n(a\\sqcap^{\\mathfrak{A}}b)^{\\ast} = \\overline{\\Cor'(a\\sqcap^{\\mathfrak{A}}b)} =\n\\overline{\\Cor'a\\sqcap^{\\mathfrak{Z}}\\Cor'b} =\\\\\n\\overline{\\Cor'a}\\sqcup^{\\mathfrak{Z}}\\overline{\\Cor'b} =\na^{\\ast}\\sqcup^{\\mathfrak{Z}}b^{\\ast} = a^{\\ast}\\sqcup^{\\mathfrak{A}}b^{\\ast}\n\\end{multline*}\n(theorems~\\ref{dual-cor-meet}, \\ref{compl-and-cor}).\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\n\\label{compl-join}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{compl-join-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{compl-join-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\nstarrish down-aligned complete lattice filtrator with binarily meet-closed,\nseparable core which is a complete atomistic boolean lattice.\n\\item \\label{compl-join-conc}$(a\\sqcup^{\\mathfrak{A}}b)^{\\ast}=a^{\\ast}\\sqcap^{\\mathfrak{A}}b^{\\ast}$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{compl-join-p}$\\Rightarrow$\\ref{compl-join-fltr}}] $(\\mathfrak{A},\\mathfrak{Z})$\nis a filtered (theorem~\\ref{semifilt-joinclosed}), distributive\n(corollary \\ref{filt-also-distr}) complete lattice filtrator (corollary\n\\ref{filt-is-complete}), with binarily meet-closed core (corollary~\\ref{f-meet-closed}),\nwith separable core (theorem~\\ref{when-sep-core}).\n\\item [{\\ref{compl-join-fltr}$\\Rightarrow$\\ref{compl-join-conc}}]\n\\begin{multline*}\n(a\\sqcup^{\\mathfrak{A}}b)^{\\ast}=\\overline{\\Cor'(a\\sqcup^{\\mathfrak{A}}b)}=\\overline{\\Cor'a\\sqcup^{\\mathfrak{Z}}\\Cor'b}=\\\\\\overline{\\Cor'a}\\sqcap^{\\mathfrak{Z}}\\overline{\\Cor'b}=a^{\\ast}\\sqcap^{\\mathfrak{Z}}b^{\\ast}=a^{\\ast}\\sqcap^{\\mathfrak{A}}b^{\\ast}\n\\end{multline*}\n(used theorems~\\ref{compl-and-cor}, \\ref{dual-core-join}).\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{meet-dpseudo-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{meet-dpseudo-f}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a complete boolean lattice.\n\\item \\label{meet-dpseudo-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a filtered up-aligned complete lattice filtrator with\nco-separable core which is a complete boolean lattice.\n\\item \\label{meet-dpseudo-res}$(a\\sqcap^{\\mathfrak{A}}b)^{+}=a^{+}\\sqcup^{\\mathfrak{A}}b^{+}$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item [\\ref{meet-dpseudo-p}$\\Rightarrow$\\ref{meet-dpseudo-f}] Obvious.\n\\item [\\ref{meet-dpseudo-f}$\\Rightarrow$\\ref{meet-dpseudo-fltr}]\nIt is filtered by theorem~\\ref{semifilt-joinclosed},\nis a complete lattice by corollary \\ref{filt-is-complete},\nis with co-separable core by theorem~\\ref{cosep-crit}.\n\\item [\\ref{meet-dpseudo-fltr}$\\Rightarrow$\\ref{meet-dpseudo-res}]\n\\begin{multline*}\n(a\\sqcap^{\\mathfrak{A}}b)^{+}=\n\\overline{\\Cor(a\\sqcap^{\\mathfrak{A}}b)} =\n\\overline{\\Cor'(a\\sqcap^{\\mathfrak{A}}b)} =\n\\overline{\\Cor' a\\sqcap^{\\mathfrak{Z}}\\Cor' b} =\\\\\n\\overline{\\Cor'a}\\sqcup^{\\mathfrak{Z}}\\overline{\\Cor'b}=\n\\overline{\\Cor'a}\\sqcup^{\\mathfrak{A}}\\overline{\\Cor'b}=\na^{+}\\sqcup^{\\mathfrak{A}}b^{+}\n\\end{multline*}\nusing theorems~\\ref{cocompl-cor}, \\ref{cor-eq}, \\ref{dual-cor-meet} and the fact that filtered filtrator is join-closed.\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{join-dpseudo-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item \\label{join-dpseudo-fltr} $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered\ndown-aligned and up-aligned filtrator with binarily meet-closed core, with co-separable core $\\mathfrak{Z}$\nwhich is a complete atomistic boolean lattice and $\\mathfrak{A}$ is a complete\nstarrish lattice.\n\\item \\label{join-dpseudo-res}$(a\\sqcup^{\\mathfrak{A}}b)^{+}=a^{+}\\sqcap^{\\mathfrak{A}}b^{+}$\nfor every $a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item [\\ref{join-dpseudo-p}$\\Rightarrow$\\ref{join-dpseudo-fltr}] Obvious.\n\\item [\\ref{join-dpseudo-fltr}$\\Rightarrow$\\ref{join-dpseudo-res}]\n\\begin{multline*}\n(a\\sqcup^{\\mathfrak{A}}b)^{+}=\n\\overline{\\Cor(a\\sqcup^{\\mathfrak{A}}b)} =\n\\overline{\\Cor'(a\\sqcup^{\\mathfrak{A}}b)} =\n\\overline{\\Cor'a\\sqcup^{\\mathfrak{Z}}\\Cor'b} =\\\\\n\\overline{\\Cor'a}\\sqcap^{\\mathfrak{Z}}\\overline{\\Cor'b} =\n\\overline{\\Cor a}\\sqcap^{\\mathfrak{A}}\\overline{\\Cor b} =\na^{+}\\sqcap^{\\mathfrak{A}}b^{+}\n\\end{multline*}\nusing theorems~\\ref{cocompl-cor}, \\ref{cor-eq}, \\ref{dual-core-join}.\n\\end{description}\n\\end{proof}\n\n\\section{Complementive Filters and Factoring by a Filter}\n\\begin{defn}\nLet $\\mathfrak{A}$ be a meet-semilattice and $\\mathcal{A}\\in\\mathfrak{A}$.\nThe relation~$\\sim$ on~$\\mathfrak{A}$ is defined by the formula\n\\[\n\\forall X,Y\\in\\mathfrak{A:}(X\\sim Y\\Leftrightarrow X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=Y\\sqcap^{\\mathfrak{A}}\\mathcal{A}).\n\\]\n\\end{defn}\n\n\\begin{prop}\nThe relation $\\sim$ is an equivalence relation.\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{Reflexivity}] Obvious.\n\\item [{Symmetry}] Obvious.\n\\item [{Transitivity}] Obvious.\n\\end{description}\n\\end{proof}\n\\begin{defn}\nWhen $X,Y\\in\\mathfrak{Z}$ and $\\mathcal{A}\\in\\mathfrak{A}$ we define\n$X\\sim Y\\Leftrightarrow\\uparrow X\\sim\\uparrow Y$.\\end{defn}\n\\begin{thm}\n\\label{eqrel-princ}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{eqrel-princ-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{eqrel-princ-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a distributive lattice.\n\\item \\label{eqrel-princ-conc}For every $\\mathcal{A}\\in\\mathfrak{A}$ and\n$X,Y\\in\\mathfrak{Z}$ we have\n\\[\nX\\sim Y\\Leftrightarrow\\exists A\\in\\up\\mathcal{A}:X\\sqcap^{\\mathfrak{Z}}A=Y\\sqcap^{\\mathfrak{Z}}A.\n\\]\n\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{eqrel-princ-p}$\\Rightarrow$\\ref{eqrel-princ-fltr}}] Obvious.\n\\item [{\\ref{eqrel-princ-fltr}$\\Rightarrow$\\ref{eqrel-princ-conc}}] ~\n\\begin{align*}\n\\exists A\\in\\up\\mathcal{A}:X\\sqcap^{\\mathfrak{Z}}A=Y\\sqcap^{\\mathfrak{Z}}A & \\Leftrightarrow \\text{ (corollary~\\ref{f-meet-closed})}\\\\\n\\exists A\\in\\up\\mathcal{A}:\\uparrow X\\sqcap^{\\mathfrak{A}}\\uparrow A=\\uparrow Y\\sqcap^{\\mathfrak{A}}\\uparrow A & \\Rightarrow\\\\\n\\exists A\\in\\up\\mathcal{A}:\\uparrow X\\sqcap^{\\mathfrak{A}}\\uparrow A\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\uparrow Y\\sqcap^{\\mathfrak{A}}\\uparrow A\\sqcap^{\\mathfrak{A}}\\mathcal{A} & \\Leftrightarrow\\\\\n\\exists A\\in\\up\\mathcal{A}:\\uparrow X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\uparrow Y\\sqcap^{\\mathfrak{A}}\\mathcal{A} & \\Leftrightarrow\\\\\n\\uparrow X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\uparrow Y\\sqcap^{\\mathfrak{A}}\\mathcal{A} & \\Leftrightarrow\\\\\n\\uparrow X\\sim\\uparrow Y & \\Leftrightarrow\\\\\nX\\sim Y.\n\\end{align*}\n\n\n\nOn the other hand,\n\\begin{align*}\n\\uparrow X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=\\uparrow Y\\sqcap^{\\mathfrak{A}}\\mathcal{A} & \\Leftrightarrow\\\\\n\\setcond{X\\sqcap^{\\mathfrak{Z}}A_{0}}{A_{0}\\in\\mathcal{A}}=\\setcond{Y\\sqcap^{\\mathfrak{Z}}A_{1}}{A_{1}\\in\\mathcal{A}} & \\Rightarrow\\\\\n\\exists A_{0},A_{1}\\in\\up\\mathcal{A}:X\\sqcap^{\\mathfrak{Z}}A_{0}=Y\\sqcap^{\\mathfrak{Z}}A_{1} & \\Rightarrow\\\\\n\\exists A_{0},A_{1}\\in\\up\\mathcal{A}:X\\sqcap^{\\mathfrak{Z}}A_{0}\\sqcap^{\\mathfrak{Z}}A_{1}=Y\\sqcap^{\\mathfrak{Z}}A_{0}\\sqcap^{\\mathfrak{Z}}A_{1} & \\Rightarrow\\\\\n\\exists A\\in\\up\\mathcal{A}:Y\\sqcap^{\\mathfrak{Z}}A=X\\sqcap^{\\mathfrak{Z}}A.\n\\end{align*}\n\n\n\\end{description}\n\\end{proof}\n\\begin{prop}\nThe relation $\\sim$ is a congruence\\footnote{See Wikipedia for a definition of congruence.}\nfor each of the following:\n\\begin{enumerate}\n\\item \\label{cong-mslat}a meet-semilattice $\\mathfrak{A}$;\n\\item \\label{cong-dist}a distributive lattice $\\mathfrak{A}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nLet $a_{0},a_{1},b_{0},b_{1}\\in\\mathfrak{A}$ and $a_{0}\\sim a_{1}$\nand $b_{0}\\sim b_{1}$.\n\\begin{disorder}\n\\item [{\\ref{cong-mslat}}] $a_{0}\\sqcap b_{0}\\sim a_{1}\\sqcap b_{1}$because\n$(a_{0}\\sqcap b_{0})\\sqcap\\mathcal{A}=a_{0}\\sqcap(b_{0}\\sqcap\\mathcal{A})=a_{0}\\sqcap(b_{1}\\sqcap\\mathcal{A})=b_{1}\\sqcap(a_{0}\\sqcap\\mathcal{A})=b_{1}\\sqcap(a_{1}\\sqcap\\mathcal{A})=(a_{1}\\sqcap b_{1})\\sqcap\\mathcal{A}$.\n\\item [{\\ref{cong-dist}}] Taking the above into account, we need to prove\nonly $a_{0}\\sqcup b_{0}\\sim a_{1}\\sqcup b_{1}$. We have\n\\[\n(a_{0}\\sqcup b_{0})\\sqcap\\mathcal{A}=(a_{0}\\sqcap\\mathcal{A})\\sqcup(b_{0}\\sqcap\\mathcal{A})=(a_{1}\\sqcap\\mathcal{A})\\sqcup(b_{1}\\sqcap\\mathcal{A})=(a_{1}\\sqcup b_{1})\\sqcap\\mathcal{A}.\n\\]\n\n\\end{disorder}\n\\end{proof}\n\\begin{defn}\nWe will denote $A/(\\sim)=A/((\\sim)\\cap A\\times A)$ for a set $A$\nand an equivalence relation $\\sim$ on a set $B\\supseteq A$. I will\ncall $\\sim$ a congruence on $A$ when $(\\sim)\\cap(A\\times A)$\nis a congruence on $A$.\\end{defn}\n\\begin{thm}\n\\label{factor-isomor}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{factor-isomor-p}$(\\mathfrak{A},\\mathfrak{Z})$ is a powerset\nfiltrator.\n\\item \\label{factor-isomor-fltr}$(\\mathfrak{A},\\mathfrak{Z})$ is a primary\nfiltrator over a boolean lattice.\n\\item \\label{factor-isomor-conc}Let $\\mathcal{A}\\in\\mathfrak{A}$. Consider the function\n$\\gamma:Z(D\\mathcal{A})\\rightarrow\\mathfrak{Z}/\\mathord\\sim$ defined\nby the formula (for every $p\\in Z(D\\mathcal{A})$)\n\\[\n\\gamma p=\\setcond{X\\in\\mathfrak{Z}}{X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p}.\n\\]\n\n\n\nThen:\n\\begin{enumerate}\n\\item $\\gamma$ is a lattice isomorphism.\n\\item $\\forall Q\\in q:\\gamma^{-1}q=Q\\sqcap^{\\mathfrak{A}}\\mathcal{A}$ for\nevery $q\\in\\mathfrak{Z}/\\mathord\\sim$.\n\\end{enumerate}\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{factor-isomor-p}$\\Rightarrow$\\ref{factor-isomor-fltr}}] Obvious.\n\\item [{\\ref{factor-isomor-fltr}$\\Rightarrow$\\ref{factor-isomor-conc}}] $\\forall p\\in Z(D\\mathcal{A}):\\gamma p\\ne\\emptyset$\nbecause of theorem \\ref{core-if-intr}. Thus it is easy to see that\n$\\gamma p\\in\\mathfrak{Z}/\\mathord\\sim$ and that $\\gamma$ is an injection.\n\n\nLet's prove that $\\gamma$ is a lattice homomorphism:\n\n\n$\\gamma(p_{0}\\sqcap^{\\mathfrak{A}}p_{1})=\\setcond{X\\in\\mathfrak{Z}}{X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p_{0}\\sqcap^{\\mathfrak{A}}p_{1}}$;\n\\begin{align*}\n\\gamma p_{0}\\sqcap^{\\mathfrak{Z}/\\mathord\\sim}\\gamma p_{1} & =\\\\\n\\setcond{X_{0}\\in\\mathfrak{Z}}{X_{0}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p_{0}}\\sqcap^{\\mathfrak{Z}/\\mathord\\sim}\\setcond{X_{1}\\in\\mathfrak{Z}}{X_{1}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p_{1}} & =\\\\\n\\setcond{X_{0}\\sqcap^{\\mathfrak{A}}X_{1}}{X_{0},X_{1}\\in\\mathfrak{Z},X_{0}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p_{0}\\land X_{1}\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p_{1}} & \\subseteq\\\\\n\\setcond{X'\\in\\mathfrak{Z}}{X'\\sqcap^{\\mathfrak{A}}\\mathcal{A}=p_{0}\\sqcap^{\\mathfrak{A}}p_{1}} & =\\\\\n\\gamma(p_{0}\\sqcap^{\\mathfrak{A}}p_{1}).\n\\end{align*}\n\n\n\nBecause $\\gamma p_{0}\\sqcap^{\\mathfrak{Z}/\\mathord\\sim}\\gamma p_{1}$\nand $\\gamma(p_{0}\\sqcap^{\\mathfrak{A}}p_{1})$ are equivalence classes,\nthus follows $\\gamma p_{0}\\sqcap^{\\mathfrak{Z}/\\mathord\\sim}\\gamma p_{1}=\\gamma(p_{0}\\sqcap^{\\mathfrak{A}}p_{1})$.\n\n\nTo finish the proof it is enough to show that $\\forall Q\\in q:q=\\gamma(Q\\sqcap^{\\mathfrak{A}}\\mathcal{A})$\nfor every $q\\in\\mathfrak{Z}/\\mathord\\sim$. (From this it follows\nthat $\\gamma$ is surjective because $q$ is not empty and thus $\\exists Q\\in q:q=\\gamma(Q\\sqcap^{\\mathfrak{A}}\\mathcal{A})$.)\nReally,\n\\[\n\\gamma(Q\\sqcap^{\\mathfrak{A}}\\mathcal{A})=\\setcond{X\\in\\mathfrak{Z}}{X\\sqcap^{\\mathfrak{A}}\\mathcal{A}=Q\\sqcap^{\\mathfrak{A}}\\mathcal{A}}=[Q]=q.\n\\]\n\n\n\\end{description}\n\\end{proof}\nThis isomorphism is useful in both directions to reveal properties\nof both lattices $Z(D\\mathcal{A})$ and $q\\in\\mathfrak{Z}/\\mathord\\sim$.\n\\begin{cor}\n\\label{frac-is-bool}The following is an implications tuple:\n\\begin{enumerate}\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a boolean\nlattice.\n\\item $\\mathfrak{Z}/\\mathord\\sim$ is a boolean lattice\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\nBecause $Z(D\\mathcal{A})$ is a boolean lattice (theorem \\ref{centr-bool}).\n\\end{proof}\n\n\\section{Pseudodifference of filters}\n\\begin{prop}\n\\label{filt-pseudo}The following is an implications tuple:\n\\begin{enumerate}\n\\item \\label{filt-pseudo-p}$\\mathfrak{A}$ is a lattice of filters on a\nset.\n\\item \\label{filt-pseudo-f}$\\mathfrak{A}$ is a lattice of filters over\na boolean lattice.\n\\item \\label{filt-pseudo-atcbr}$\\mathfrak{A}$ is an atomistic co-brouwerian\nlattice.\n\\item \\label{filt-pseudo-conc}For every $a,b\\in\\mathfrak{A}$ the following\nexpressions are always equal:\n\n\\begin{enumerate}\n\\item $a\\psetminus b=\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}$\n(quasidifference of $a$ and $b$);\n\\item $a\\mathop\\#b=\\bigsqcup\\setcond{z\\in\\mathfrak{A}}{z\\sqsubseteq a\\land z\\sqcap b=\\bot}$\n(second quasidifference of $a$ and $b$);\n\\item $\\bigsqcup(\\atoms a\\setminus\\atoms b)$.\n\\end{enumerate}\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{filt-pseudo-p}$\\Rightarrow$\\ref{filt-pseudo-f}}] Obvious.\n\\item [{\\ref{filt-pseudo-f}$\\Rightarrow$\\ref{filt-pseudo-atcbr}}] By\ncorollary \\ref{filt-also-distr} and theorem \\ref{filt-atomistic}.\n\\item [{\\ref{filt-pseudo-atcbr}$\\Rightarrow$\\ref{filt-pseudo-conc}}] Theorem\n\\ref{pdiff-eq1}.\\end{description}\n\\begin{conjecture}\n$a\\psetminus b=a\\mathop\\#b$ for arbitrary filters $a$, $b$ on powersets\nis not provable in ZF (without axiom of choice).\n\\end{conjecture}\n\\end{proof}\n\n\\section{Function spaces of posets}\n\\begin{defn}\nLet $\\mathfrak{A}_{i}$ be a family of posets indexed by some set\n$\\dom\\mathfrak{A}$. We will define order of indexed families of elements of posets by\nthe formula\n\\[\na\\sqsubseteq b\\Leftrightarrow\\forall i\\in\\dom\\mathfrak{A}:a_{i}\\sqsubseteq b_{i}.\n\\]\n\\index{function space of posets}\\index{product order}I will call\nthis new poset $\\prod\\mathfrak{A}$ \\emph{the function\nspace} of posets and the above order \\emph{product order}.\\end{defn}\n\\begin{prop}\nThe function space for posets is also a poset.\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{Reflexivity}] Obvious.\n\\item [{Antisymmetry}] Obvious.\n\\item [{Transitivity}] Obvious.\n\\end{description}\n\\end{proof}\n\\begin{obvious}\n$\\mathfrak{A}$ has least element iff each $\\mathfrak{A}_{i}$ has\na least element. In this case\n\\[\n\\bot^{\\prod\\mathfrak{A}}=\\prod_{i\\in\\dom\\mathfrak{A}}\\bot^{\\mathfrak{A}_{i}}.\n\\]\n\\end{obvious}\n\\begin{prop}\n$a\\nasymp b\\Leftrightarrow\\exists i\\in\\dom\\mathfrak{A}:a_{i}\\nasymp b_{i}$\nfor every $a,b\\in\\prod\\mathfrak{A}$ if every $\\mathfrak{A}_{i}$\nhas least element.\\end{prop}\n\\begin{proof}\nIf $\\dom\\mathfrak{A}=\\emptyset$, then $a=b=\\bot$, $a\\asymp b$ and\nthus the theorem statement holds. Assume $\\dom\\mathfrak{A}\\neq\\emptyset$.\n\\begin{align*}\na\\nasymp b & \\Leftrightarrow\\\\\n\\exists c\\in\\prod\\mathfrak{A}\\setminus\\{\\bot^{\\prod\\mathfrak{A}}\\}:(c\\sqsubseteq a\\land c\\sqsubseteq b) & \\Leftrightarrow\\\\\n\\exists c\\in\\prod\\mathfrak{A}\\setminus\\{\\bot^{\\prod\\mathfrak{A}}\\}\\forall i\\in\\dom\\mathfrak{A}:(c_{i}\\sqsubseteq a_{i}\\land c_{i}\\sqsubseteq b_{i}) & \\Leftrightarrow\\\\\n\\text{(for the reverse implication take \\ensuremath{c_{j}=\\bot^{\\mathfrak{A}_{j}}} for \\ensuremath{i\\ne j})}\\\\\n\\exists i\\in\\dom\\mathfrak{A},c\\in\\mathfrak{A}_{i}\\setminus\\{\\bot^{\\mathfrak{A}_{i}}\\}:(c\\sqsubseteq a_{i}\\land c\\sqsubseteq b_{i}) & \\Leftrightarrow\\\\\n\\exists i\\in\\dom\\mathfrak{A}:a_{i}\\nasymp b_{i}.\n\\end{align*}\n\\end{proof}\n\\begin{prop}\n~\n\\begin{enumerate}\n\\item If $\\mathfrak{A}_{i}$ are join-semilattices then $\\mathfrak{A}$\nis a join-semilattice and\n\\begin{equation}\nA\\sqcup B=\\mylambda i{\\dom\\mathfrak{A}}{Ai\\sqcup Bi}.\\label{func-union}\n\\end{equation}\n\n\\item If $\\mathfrak{A}_{i}$ are meet-semilattices then $\\mathfrak{A}$\nis a meet-semilattice and\n\\[\nA\\sqcap B=\\mylambda i{\\dom\\mathfrak{A}}{Ai\\sqcap Bi}.\n\\]\n\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nIt is enough to prove the formula (\\ref{func-union}).\n\nIt's obvious that $\\mylambda i{\\dom\\mathfrak{A}}{Ai\\sqcup Bi}\\sqsupseteq A,B$.\n\nLet $C\\sqsupseteq A,B$. Then (for every $i\\in\\dom\\mathfrak{A}$)\n$Ci\\sqsupseteq Ai$ and $Ci\\sqsupseteq Bi$. Thus $Ci\\sqsupseteq Ai\\sqcup Bi$\nthat is $C\\sqsupseteq\\mylambda i{\\dom\\mathfrak{A}}{Ai\\sqcup Bi}$.\\end{proof}\n\\begin{cor}\nIf $\\mathfrak{A}_{i}$ are lattices then $\\prod\\mathfrak{A}$ is a lattice.\\end{cor}\n\\begin{obvious}\nIf $\\mathfrak{A}_{i}$ are distributive lattices then $\\prod\\mathfrak{A}$\nis a distributive lattice.\\end{obvious}\n\\begin{prop}\nIf $\\mathfrak{A}_{i}$ are boolean lattices then $\\prod\\mathfrak{A}$\nis a boolean lattice.\\end{prop}\n\\begin{proof}\nWe need to prove only that every element $a\\in\\prod\\mathfrak{A}$\nhas a complement. But this complement is evidently $\\mylambda i{\\dom a}{\\overline{a_{i}}}$.\\end{proof}\n\\begin{prop}\\label{cw-join}\nIf every $\\mathfrak{A}_{i}$ is a poset then for every $S\\in\\subsets\\prod\\mathfrak{A}$\n\\begin{enumerate}\n\\item $\\bigsqcup S=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup_{x\\in S}x_{i}}$\nwhenever every $\\bigsqcup_{x\\in S}x_{i}$ exists;\n\\item $\\bigsqcap S=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcap_{x\\in S}x_{i}}$\nwhenever every $\\bigsqcap_{x\\in S}x_{i}$ exists.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nIt's enough to prove the first formula.\n\n$\\left(\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup_{x\\in S}x_{i}}\\right)_{i}=\\bigsqcup_{x\\in S}x_{i}\\sqsupseteq x_{i}$\nfor every $x\\in S$ and $i\\in\\dom\\mathfrak{A}$.\n\nLet $y\\sqsupseteq x$ for every $x\\in S$. Then $y_{i}\\sqsupseteq x_{i}$\nfor every $i\\in\\dom\\mathfrak{A}$ and thus $y_{i}\\sqsupseteq\\bigsqcup_{x\\in S}x_{i}=\\left(\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup_{x\\in S}x_{i}}\\right)_{i}$\nthat is $y\\sqsupseteq\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup_{x\\in S}x_{i}}$.\n\nThus $\\bigsqcup S=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup_{x\\in S}x_{i}}$\nby the definition of join.\\end{proof}\n\\begin{cor}\\label{cw-join-back}\n\\label{prod-join2}If $\\mathfrak{A}_{i}$ are posets then for every\n$S\\in\\subsets\\prod\\mathfrak{A}$\n\\begin{enumerate}\n\\item $\\bigsqcup S=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup_{x\\in S}x_{i}}$\nwhenever $\\bigsqcup S$ exists;\n\\item $\\bigsqcap S=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcap_{x\\in S}x_{i}}$\nwhenever $\\bigsqcap S$ exists.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\nIt is enough to prove that (for every $i$) $\\bigsqcup_{x\\in S}x_{i}$\nexists whenever $\\bigsqcup S$ exists.\n\nFix $i\\in\\dom\\mathfrak{A}$.\n\nTake $y_{i}=\\left(\\bigsqcup S\\right)_{i}$ and let prove that $y_{i}$\nis the least upper bound of $\\setcond{x_{i}}{x\\in S}$.\n\n$y_{i}$ is it's upper bound because $\\bigsqcup S\\sqsupseteq x$\nand thus $\\left(\\bigsqcup S\\right)_{i}\\sqsupseteq x_{i}$ for every\n$x\\in S$.\n\nLet $x\\in S$ and for some $t\\in\\mathfrak{A}_{i}$\n\\[\nT(t)=\\mylambda j{\\dom\\mathfrak{A}}{\\begin{cases}\nt & \\text{if }i=j\\\\\nx_{j} & \\text{if }i\\ne j.\n\\end{cases}}\n\\]\nLet $t\\sqsupseteq x_{i}$. Then $T(t)\\sqsupseteq x$ for every $x\\in S$.\nSo $T(t)\\sqsupseteq\\bigsqcup S$ and consequently $t=T(t)_{i}\\sqsupseteq y_{i}$.\n\nSo $y_{i}$ is the least upper bound of $\\setcond{x_{i}}{x\\in S}$.\\end{proof}\n\\begin{cor}\nIf $\\mathfrak{A}_{i}$ are complete lattices then $\\mathfrak{A}$\nis a complete lattice.\\end{cor}\n\\begin{obvious}\nIf $\\mathfrak{A}_{i}$ are complete (co-)brouwerian lattices then\n$\\mathfrak{A}$ is a (co-)brouwerian lattice.\\end{obvious}\n\\begin{prop}\nIf each $\\mathfrak{A}_{i}$ is a separable poset with least element\n(for some index set $n$) then $\\prod\\mathfrak{A}$ is a separable\nposet.\\end{prop}\n\\begin{proof}\nLet $a\\neq b$. Then $\\exists i\\in\\dom\\mathfrak{A}:a_{i}\\neq b_{i}$.\nSo $\\exists x\\in\\mathfrak{A}_{i}:(x\\nasymp a_{i}\\wedge x\\asymp b_{i})$\n(or vice versa).\n\nTake $y=\\mylambda{j}{\\dom\\mathfrak{A}}{\\begin{cases}x&\\text{ if }j=i;\\\\\\bot^{\\mathfrak{A}_j}&\\text{ if }j\\ne i.\\end{cases}}$\nThen $y\\nasymp a$ and $y\\asymp b$.\\end{proof}\n\\begin{obvious}\nIf every $\\mathfrak{A}_{i}$ is a poset with least element,\nthen the set of atoms of $\\prod\\mathfrak{A}$ is\n\\[\n\\setcond{\\mylambda{i}{\\dom\\mathfrak{A}}{\\left(\\begin{cases}a&\\text{ if }i=k;\\\\\\bot^{\\mathfrak{A}_i}&\\text{ if }i\\ne k\\end{cases}\\right)}}{k\\in\\dom\\mathfrak{A}, a\\in\\atoms^{\\mathfrak{A}_{k}}}.\n\\]\n\\end{obvious}\n\\begin{prop}\nIf every $\\mathfrak{A}_{i}$ is an atomistic poset with least element, then $\\prod\\mathfrak{A}$ is an atomistic poset.\\end{prop}\n\\begin{proof}\n$x_{i}=\\bigsqcup\\atoms x_{i}$ for every $x_{i}\\in\\mathfrak{A}_{i}$.\nThus\n\\begin{multline*}\nx=\\mylambda i{\\dom x}{x_{i}}=\n\\mylambda i{\\dom x}{\\bigsqcup\\atoms x_{i}}=\\\\\n\\bigsqcup_{i\\in\\dom x}\\mylambda j{\\dom x}{\\begin{cases}\nx_{i} & \\text{if }j=i\\\\\n\\bot^{\\mathfrak{A}_j} & \\text{if }j\\ne i\n\\end{cases}} = \\\\\n\\bigsqcup_{i\\in\\dom x}\\mylambda j{\\dom x}{\\begin{cases}\n\\bigsqcup\\atoms x_{i} & \\text{if }j=i\\\\\n\\bot^{\\mathfrak{A}_j} & \\text{if }j\\ne i\n\\end{cases}} =\\\\\n\\bigsqcup_{i\\in\\dom x}\\bigsqcup_{q\\in\\atoms x_i}\\mylambda j{\\dom x}{\\begin{cases}\nq & \\text{if }j=i\\\\\n\\bot^{\\mathfrak{A}_j} & \\text{if }j\\ne i\n\\end{cases}}.\n\\end{multline*}\nThus $x$ is a join of atoms of $\\prod\\mathfrak{A}$.\\end{proof}\n\\begin{cor}\nIf $\\mathfrak{A}_{i}$ are atomistic posets with least elements, then\n$\\prod\\mathfrak{A}$ is atomically separable.\\end{cor}\n\\begin{proof}\nProposition \\ref{atms-is-asep}.\\end{proof}\n\\begin{prop}\nLet $(\\mathfrak{A}_{i\\in n},\\mathfrak{Z}_{i\\in n})$ be a family of\nfiltrators. Then $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis a filtrator.\\end{prop}\n\\begin{proof}\nWe need to prove that $\\prod\\mathfrak{Z}$ is a sub-poset of $\\prod\\mathfrak{A}$.\nFirst $\\prod\\mathfrak{Z}\\subseteq\\prod\\mathfrak{A}$ because $\\mathfrak{Z}_{i}\\subseteq\\mathfrak{A}_{i}$\nfor each $i\\in n$.\n\nLet $A,B\\in\\prod\\mathfrak{Z}$ and $A\\sqsubseteq^{\\prod\\mathfrak{Z}}B$.\nThen $\\forall i\\in n:A_{i}\\sqsubseteq^{\\mathfrak{Z}_{i}}B_{i}$; consequently\n$\\forall i\\in n:A_{i}\\sqsubseteq^{\\mathfrak{A}_{i}}B_{i}$ that is\n$A\\sqsubseteq^{\\prod\\mathfrak{A}}B$.\\end{proof}\n\\begin{prop}\nLet $(\\mathfrak{A}_{i\\in n},\\mathfrak{Z}_{i\\in n})$ be a family of\nfiltrators.\n\\begin{enumerate}\n\\item The filtrator $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis (binarily) join-closed if every $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$\nis (binarily) join-closed.\n\\item The filtrator $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis (binarily) meet-closed if every $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$\nis (binarily) meet-closed.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nLet every $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ be binarily join-closed.\nLet $A,B\\in\\prod\\mathfrak{Z}$ and $A\\sqcup^{\\prod\\mathfrak{Z}}B$\nexist. Then (by corollary \\ref{prod-join2})\n\\[\nA\\sqcup^{\\prod\\mathfrak{Z}}B=\\mylambda in{A_{i}\\sqcup^{\\mathfrak{Z}_{i}}B_{i}=}\\mylambda in{A_{i}\\sqcup^{\\mathfrak{A}_{i}}B_{i}=}A\\sqcup^{\\prod\\mathfrak{A}}B.\n\\]\n\n\nLet now every $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ be join-closed.\nLet $S\\in\\subsets\\prod\\mathfrak{Z}$ and $\\bigsqcup^{\\prod\\mathfrak{Z}}S$\nexist. Then (by corollary \\ref{prod-join2})\n\\[\n\\bigsqcup^{\\prod\\mathfrak{Z}}S=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup^{\\mathfrak{Z}_{i}}\\setcond{x_{i}}{x\\in S}}=\\mylambda i{\\dom\\mathfrak{A}}{\\bigsqcup^{\\mathfrak{A}_{i}}\\setcond{x_{i}}{x\\in S}}=\\bigsqcup^{\\prod\\mathfrak{A}}S.\n\\]\n\n\nThe rest follows from symmetry.\\end{proof}\n\\begin{prop}\nIf each $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ where $i\\in n$ (for\nsome index set $n$) is a down-aligned\nfiltrator with separable core\nthen $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$ is with separable\ncore.\\end{prop}\n\\begin{proof}\nLet $a\\neq b$. Then $\\exists i\\in n:a_{i}\\neq b_{i}$. So $\\exists x\\in\\mathfrak{Z}_{i}:(x\\nasymp a_{i}\\wedge x\\asymp b_{i})$\n(or vice versa).\n\nTake $y=\n\\mylambda{j}{n}{\\begin{cases}\nx &\\text{if }j=i\\\\\n\\bot^{\\mathfrak{A}_j} &\\text{if }j\\ne i\n\\end{cases}}$. Then we have\n$y\\nasymp a$ and $y\\asymp b$ and $y\\in\\mathfrak{Z}$.\\end{proof}\n\\begin{prop}\nLet every $\\mathfrak{A}_{i}$ be a bounded lattice. Every $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$\nis a central filtrator iff $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis a central filtrator.\\end{prop}\n\\begin{proof}\n~\n\\begin{align*}\nx\\in Z\\left(\\prod\\mathfrak{A}\\right) & \\Leftrightarrow\\\\\n\\exists y\\in\\prod\\mathfrak{A}:(x\\sqcap y=\\bot^{\\prod\\mathfrak{A}}\\land x\\sqcup y=\\top^{\\prod\\mathfrak{A}}) & \\Leftrightarrow\\\\\n\\exists y\\in\\prod\\mathfrak{A}\\forall i\\in\\dom\\mathfrak{A}:(x_{i}\\sqcap y_{i}=\\bot^{\\mathfrak{A}_{i}}\\land x_{i}\\sqcup y_{i}=\\top^{\\mathfrak{A}_{i}}) & \\Leftrightarrow\\\\\n\\forall i\\in\\dom\\mathfrak{A}\\exists y\\in\\mathfrak{A}_{i}:(x_{i}\\sqcap y=\\bot^{\\mathfrak{A}_{i}}\\land x_{i}\\sqcup y=\\top^{\\mathfrak{A}_{i}}) & \\Leftrightarrow\\\\\n\\forall i\\in\\dom\\mathfrak{A}:x_{i}\\in Z(\\mathfrak{A}_{i}).\n\\end{align*}\n\n\nSo\n\\begin{multline*}\nZ\\left(\\prod\\mathfrak{A}\\right)=\\prod\\mathfrak{Z}\\Leftrightarrow\\prod_{i\\in\\dom\\mathfrak{A}}Z(\\mathfrak{A}_{i})=\\prod\\mathfrak{Z}\\Leftrightarrow\\\\\n\\text{(because every \\ensuremath{\\mathfrak{Z}_{i}} is nonempty)}\\Leftrightarrow\\forall i\\in\\dom\\mathfrak{A}:Z(\\mathfrak{A}_{i})=\\mathfrak{Z}_{i}.\n\\end{multline*}\n\\end{proof}\n\\begin{prop}\nFor every element $a$ of a product filtrator $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$:\n\\begin{enumerate}\n\\item $\\up a=\\prod_{i\\in\\dom a}\\up a_{i}$;\n\\item $\\down a=\\prod_{i\\in\\dom a}\\down a_{i}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\\begin{multline*}\n\\up a=\\setcond{c\\in\\prod\\mathfrak{Z}}{c\\sqsupseteq a}=\\setcond{c\\in\\prod\\mathfrak{Z}}{\\forall i\\in\\dom a:c_{i}\\sqsupseteq a_{i}}=\\\\\n\\setcond{c\\in\\prod\\mathfrak{Z}}{\\forall i\\in\\dom a:c_{i}\\in\\up a_{i}}=\\prod_{i\\in\\dom a}\\up a_{i}.\n\\end{multline*}\n\\end{proof}\n\\begin{prop}\nIf every $(\\mathfrak{A}_{i\\in n},\\mathfrak{Z}_{i\\in n})$ is a prefiltered\nfiltrator, then $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis a prefiltered filtrator.\\end{prop}\n\\begin{proof}\nLet $a,b\\in\\prod\\mathfrak{A}$ and $a\\neq b$. Then there exists $i\\in n$\nsuch that $a_{i}\\neq b_{i}$ and so $\\up a_{i}\\neq\\up b_{i}$. Consequently\n$\\prod_{i\\in\\dom a}\\up a_{i}\\neq\\prod_{i\\in\\dom a}\\up b_{i}$\nthat is $\\up a\\neq\\up b$.\\end{proof}\n\\begin{prop}\nLet every $(\\mathfrak{A}_{i\\in n},\\mathfrak{Z}_{i\\in n})$ be a filtered\nfiltrator with $\\up x\\neq\\emptyset$ for every $x\\in\\mathfrak{A}_{i}$\n(for every $i\\in n$). Then $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis a filtered filtrator.\\end{prop}\n\\begin{proof}\nLet every $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ be a filtered filtrator.\nLet $\\up a\\supseteq\\up b$ for some $a,b\\in\\prod\\mathfrak{A}$. Then\n$\\prod_{i\\in\\dom a}\\up a_{i}\\supseteq\\prod_{i\\in\\dom a}\\up b_{i}$\nand consequently (taking into account that $\\up x\\neq\\emptyset$ for\nevery $x\\in\\mathfrak{A}_{i}$) $\\up a_{i}\\supseteq\\up b_{i}$ for\nevery $i\\in n$. Then $\\forall i\\in n:a_{i}\\sqsubseteq b_{i}$ that\nis $a\\sqsubseteq b$.\\end{proof}\n\\begin{prop}\nLet $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ be filtrators and each\n$\\mathfrak{Z}_{i}$ be a complete lattice with $\\up x\\neq\\emptyset$\nfor every $x\\in\\mathfrak{A}_{i}$ (for every $i\\in n$). For $a\\in\\prod\\mathfrak{A}$:\n\\begin{enumerate}\n\\item $\\Cor a=\\mylambda i{\\dom a}{\\Cor a_{i}}$;\n\\item $\\Cor'a=\\mylambda i{\\dom a}{\\Cor'a_{i}}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nWe will prove only the first, because the second is dual.\n\\begin{align*}\n\\Cor a & =\\\\\n\\bigsqcap^{\\prod\\mathfrak{Z}}\\up a & =\\\\\n\\mylambda i{\\dom a}{\\bigsqcap^{\\mathfrak{Z}_{i}}\\setcond{x_{i}}{x\\in\\up a}} & =\\text{(\\ensuremath{\\up x\\ne\\emptyset} taken into account)}\\\\\n\\mylambda i{\\dom a}{\\bigsqcap^{\\mathfrak{Z}_{i}}\\setcond x{x\\in\\up a_{i}}} & =\\\\\n\\mylambda i{\\dom a}{\\bigsqcap^{\\mathfrak{Z}_{i}}\\up a_{i}} & =\\\\\n\\mylambda i{\\dom a}{\\Cor a_{i}}.\n\\end{align*}\n\\end{proof}\n\\begin{prop}\nIf each $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ is a filtrator with\n(co)separable core and each $\\mathfrak{A}_{i}$ has a least (greatest)\nelement, then $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$\nis a filtrator with (co)separable core.\\end{prop}\n\\begin{proof}\nWe will prove only for separable core, as co-separable core is dual.\n\\begin{align*}\nx\\asymp^{\\prod\\mathfrak{A}}y & \\Leftrightarrow\\\\\n\\text{(used the fact that \\ensuremath{\\mathfrak{A}_{i}} has a least element)}\\\\\n\\forall i\\in\\dom\\mathfrak{A}:x_{i}\\asymp^{\\mathfrak{A}_{i}}y_{i} & \\Rightarrow\\\\\n\\forall i\\in\\dom\\mathfrak{A}\\exists X\\in\\up x_{i}:X\\asymp^{\\mathfrak{A}_{i}}y_{i} & \\Leftrightarrow\\\\\n\\exists X\\in\\up x\\forall i\\in\\dom\\mathfrak{A}:X_{i}\\asymp^{\\mathfrak{A}_{i}}y_{i} & \\Leftrightarrow\\\\\n\\exists X\\in\\up x:X\\asymp^{\\prod\\mathfrak{A}}y\n\\end{align*}\nfor every $x,y\\in\\prod\\mathfrak{A}$.\\end{proof}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item If each $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ is a down-aligned filtrator,\nthen $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$ is a down-aligned\nfiltrator.\n\\item If each $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ is an up-aligned filtrator,\nthen $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$ is an up-aligned\nfiltrator.\n\\end{enumerate}\n\\end{obvious}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item If each $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ is a weakly down-aligned filtrator,\nthen $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$ is a weakly down-aligned\nfiltrator.\n\\item If each $(\\mathfrak{A}_{i},\\mathfrak{Z}_{i})$ is a weakly up-aligned filtrator,\nthen $\\left(\\prod\\mathfrak{A},\\prod\\mathfrak{Z}\\right)$ is a weakly up-aligned\nfiltrator.\n\\end{enumerate}\n\\end{obvious}\n\\begin{prop}\nIf every $b_{i}$ is substractive from $a_{i}$ where $a$ and $b$\nare $n$-indexed families of elements of distributive lattices with least elements\n(where $n$ is an index set), then $a\\setminus b=\\mylambda in{a_{i}\\setminus b_{i}}$.\\end{prop}\n\\begin{proof}\nWe need to prove $(\\mylambda in{a_{i}\\setminus b_{i}})\\sqcap b=\\bot$\nand $a\\sqcup b=b\\sqcup(\\mylambda in{a_{i}\\setminus b_{i}})$. Really\n\\begin{gather*}\n(\\mylambda in{a_{i}\\setminus b_{i}})\\sqcap b=\\mylambda in{(a_{i}\\setminus b_{i})\\sqcap b_{i}}=\\bot;\\\\\nb\\sqcup(\\mylambda in{a_{i}\\setminus b_{i}})=\\mylambda in{b_{i}\\sqcup(a_{i}\\setminus b_{i})}=\\mylambda in{b_{i}\\sqcup a_{i}=a\\sqcup b}.\n\\end{gather*}\n\\end{proof}\n\\begin{prop}\nIf every $\\mathfrak{A}_{i}$ is a distributive lattice, then $a\\setminus^{\\ast}b=\\mylambda i{\\dom\\mathfrak{A}}{a_{i}\\setminus^{\\ast}b_{i}}$\nfor every $a,b\\in\\prod\\mathfrak{A}$ whenever every $a_{i}\\setminus^{\\ast}b_{i}$\nis defined.\\end{prop}\n\\begin{proof}\nWe need to prove that $\\mylambda i{\\dom\\mathfrak{A}}{a_{i}\\setminus^{\\ast}b_{i}}=\\bigsqcap\\setcond{z\\in\\prod\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}$.\n\nTo prove it is enough to show $a_{i}\\setminus^{\\ast}b_{i}=\\bigsqcap\\setcond{z_{i}}{z\\in\\prod\\mathfrak{A},a\\sqsubseteq b\\sqcup z}$\nthat is $a_{i}\\setminus^{\\ast}b_{i}=\\bigsqcap\\setcond{z\\in\\mathfrak{A}_{i}}{a_{i}\\sqsubseteq b_{i}\\sqcup z}$\nbecause $z'\\in\\setcond{z_{i}}{z\\in\\prod\\mathfrak{A},a\\sqsubseteq b\\sqcup z} \\Leftrightarrow z'\\in\\setcond{z\\in\\mathfrak{A}_{i}}{a_{i}\\sqsubseteq b_{i}\\sqcup z}$\n(for the reverse implication take $z_{j}=a_{i}$ for $j\\neq i$),\nbut $a_{i}\\setminus^{\\ast}b_{i}=\\bigsqcap\\setcond{z\\in\\mathfrak{A}_{i}}{a_{i}\\sqsubseteq b_{i}\\sqcup z}$ is true by definition.\\end{proof}\n\\begin{prop}\nIf every $\\mathfrak{A}_{i}$ is a distributive lattice with least\nelement, then $a\\mathbin\\#b=\\lambda i\\in\\dom\\mathfrak{A}:a_{i}\\mathbin\\#b_{i}$\nfor every $a,b\\in\\prod\\mathfrak{A}$ whenever every $a_{i}\\mathbin\\#b_{i}$\nis defined.\\end{prop}\n\\begin{proof}\nWe need to prove that $\\lambda i\\in\\dom\\mathfrak{A}:a_{i}\\mathbin\\#b_{i}=\\bigsqcup\\setcond{z\\in\\prod\\mathfrak{A}}{z\\sqsubseteq a\\land z\\asymp b}$.\n\nTo prove it is enough to show $a_{i}\\mathbin\\#b_{i}=\\bigsqcup\\setcond{z_{i}}{z\\in\\prod\\mathfrak{A},z\\sqsubseteq a\\land z\\asymp b}$\nthat is $a_{i}\\mathbin\\#b_{i}=\\bigsqcup\\setcond{z_i}{z\\in\\prod\\mathfrak{A},z_i\\sqsubseteq a_{i}\\land\\forall j\\in\\dom\\mathfrak{A}:z_{j}\\asymp b_{j}}$\nthat is $a_{i}\\mathbin\\#b_{i}=\\bigsqcup\\setcond{z\\in\\mathfrak{A}_{i}}{z\\sqsubseteq a_{i}\\land z\\asymp b_{i}}$\n(take $z_{j}=\\bot^{\\mathfrak{A}_j}$ for $j\\ne i$) what is true by definition.\\end{proof}\n\\begin{prop}\nLet every $\\mathfrak{A}_{i}$ be a poset with least element and $a_{i}^{\\ast}$\nis defined. Then $a^{\\ast}=\\mylambda i{\\dom\\mathfrak{A}}{a_{i}^{\\ast}}$.\\end{prop}\n\\begin{proof}\nWe need to prove that $\\mylambda i{\\dom\\mathfrak{A}}{a_{i}^{\\ast}}=\\bigsqcup\\setcond{c\\in\\prod\\mathfrak{A}}{c\\asymp a}$.\nTo prove this it is enough to show that $a_{i}^{\\ast}=\\bigsqcup\\setcond{c_{i}}{c\\in\\prod\\mathfrak{A},c\\asymp a}$\nthat is $a_{i}^{\\ast}=\\bigsqcup\\setcond{c_{i}}{c\\in\\prod\\mathfrak{A},\\forall j\\in\\dom\\mathfrak{A}:c_{j}\\asymp a_{j}}$\nthat is $a_{i}^{\\ast}=\\bigsqcup\\setcond{c_{i}}{c\\in\\prod\\mathfrak{A},c_{i}\\asymp a_{i}}$\n(take $c_{j}=\\bot^{\\mathfrak{A}_j}$ for $j\\neq i$) that is $a_{i}^{\\ast}=\\bigsqcup\\setcond{c\\in\\mathfrak{A}_{i}}{c\\asymp a_{i}}$\nwhat is true by definition.\\end{proof}\n\\begin{cor}\nLet every $\\mathfrak{A}_{i}$ be a poset with greatest element and\n$a_{i}^{+}$ is defined. Then $a^{+}=\\mylambda i{\\dom\\mathfrak{A}}{a_{i}^{+}}$.\\end{cor}\n\\begin{proof}\nBy duality.\n\\end{proof}\n\n\\section{Filters on a Set}\n\nIn this section we will fix a powerset filtrator~$(\\mathfrak{A},\\mathfrak{Z})=(\\mathfrak{A},\\subsets\\mathfrak{U})$\nfor some set~$\\mathfrak{U}$.\n\nThe consideration below is about filters on a set $\\mathfrak{U}$,\nbut this can be generalized for filters on complete atomic boolean\nalgebras due complete atomic boolean algebras are isomorphic to algebras\nof sets on some set $\\mathfrak{U}$.\n\n\n\\subsection{Fr\\'echet Filter}\n\\begin{defn}\n\\index{filter!Fr\\'echet}\\index{filter!cofinite}$\\Omega=\\setcond{\\mathfrak{U}\\setminus X}{X\\text{ is a finite subset of }\\mathfrak{U}}$\nis called either \\emph{Fr\\'echet filter} or \\emph{cofinite filter}.\n\\end{defn}\nIt is trivial that Fr\\'echet filter is a filter.\n\\begin{prop}\n$\\Cor\\Omega=\\bot^{\\mathfrak{Z}}$; $\\bigcap\\Omega=\\emptyset$.\\end{prop}\n\\begin{proof}\nThis can be deduced from the formula $\\forall\\alpha\\in\\mathfrak{U}\\exists X\\in\\Omega:\\alpha\\notin X$.\\end{proof}\n\\begin{thm}\n$\\max\\setcond{\\mathcal{X}\\in\\mathfrak{A}}{\\Cor\\mathcal{X}=\\bot^{\\mathfrak{Z}}}=\\max\\setcond{\\mathcal{X}\\in\\mathfrak{A}}{\\bigcap\\mathcal{X}=\\emptyset}=\\Omega$.\\end{thm}\n\\begin{proof}\nDue the last proposition, it is enough to show that $\\Cor\\mathcal{X}=\\bot^{\\mathfrak{Z}}\\Rightarrow\\mathcal{X}\\sqsubseteq\\Omega$\nfor every filter $\\mathcal{X}$.\n\nLet $\\Cor\\mathcal{X}=\\bot^{\\mathfrak{Z}}$ for some filter $\\mathcal{X}$.\nLet $X\\in\\Omega$. We need to prove that $X\\in\\mathcal{X}$.\n\n$X=\\mathfrak{U}\\setminus\\{\\alpha_{0},\\dots,\\alpha_{n}\\}$. $\\mathfrak{U}\\setminus\\{\\alpha_{i}\\}\\in\\mathcal{X}$\nbecause otherwise $\\alpha_{i}\\in\\uparrow^{-1}\\Cor\\mathcal{X}$. So\n$X\\in\\mathcal{X}$.\\end{proof}\n\\begin{thm}\n$\\Omega=\\bigsqcup^{\\mathfrak{A}}\\setcond x{x\\text{ is a non-trivial ultrafilter}}$.\\end{thm}\n\\begin{proof}\nIt follows from the facts that $\\Cor x=\\bot^{\\mathfrak{Z}}$ for every\nnon-trivial ultrafilter $x$, that $\\mathfrak{A}$ is an atomistic\nlattice, and the previous theorem.\\end{proof}\n\\begin{thm}\n$\\Cor$ is the lower adjoint of $\\Omega\\sqcup^{\\mathfrak{A}}\\mathord-$.\\end{thm}\n\\begin{proof}\nBecause both $\\Cor$ and $\\Omega\\sqcup^{\\mathfrak{A}}\\mathord-$ are\nmonotone, it is enough (theorem~\\ref{galois-second}) to prove (for\nevery filters $\\mathcal{X}$ and $\\mathcal{Y}$)\n\\[\n\\mathcal{X}\\sqsubseteq\\Omega\\sqcup^{\\mathfrak{A}}\\Cor\\mathcal{X}\\quad\\text{and}\\quad\\Cor(\\Omega\\sqcup^{\\mathfrak{A}}\\mathcal{Y})\\sqsubseteq\\mathcal{Y}.\n\\]\n\n$\\Cor(\\Omega\\sqcup^{\\mathfrak{A}}\\mathcal{Y})=\\Cor\\Omega\\sqcup^{\\mathfrak{Z}}\\Cor\\mathcal{Y}=\\bot^{\\mathfrak{Z}}\\sqcup^{\\mathfrak{Z}}\\Cor\\mathcal{Y}=\\Cor\\mathcal{Y}\\sqsubseteq\\mathcal{Y}$.\n\n$\\Omega\\sqcup^{\\mathfrak{A}}\\Cor\\mathcal{X}\\sqsupseteq\\Edg\\mathcal{X}\\sqcup^{\\mathfrak{A}}\\Cor\\mathcal{X}=\\mathcal{X}$.\n\\end{proof}\n\\begin{cor}\n$\\Cor\\mathcal{X}=\\mathcal{X}\\psetminus\\Omega$ for every filter on\na set.\\end{cor}\n\\begin{proof}\nBy theorem \\ref{cobrow-adj}.\\end{proof}\n\\begin{cor}\n$\\Cor\\bigsqcup^{\\mathfrak{A}}S=\\bigsqcup^{\\mathfrak{A}}\\rsupfun{\\Cor}S$\nfor any set $S$ of filters on a powerset.\n\\end{cor}\nThis corollary can be rewritten in elementary terms and proved elementarily:\n\\begin{prop}\n$\\bigcap\\bigcap S=\\bigcup_{F\\in S}\\bigcap F$ for a set~$S$ of filters\non some set.\\end{prop}\n\\begin{proof}\n(by \\noun{Andreas Blass}) The $\\supseteq$ direction is rather formal.\nConsider any one of the sets being intersected on the left side, i.e.,\nany set $X$ that is in all the filters in $S$, and consider any\nof the sets being unioned (that's not a word, but you know what I\nmean) on the right, i.e., $\\bigcap F$ for some $F\\in S$. Then, since\n$X\\in F$, we have $\\bigcap F\\subseteq X$. Taking the union over\nall $F\\in S$ (while keeping $X$ fixed), we get that the right side\nof your equation is $\\subseteq X$. Since that's true for all $X\\in\\bigcap S$,\nwe infer that the right side is a subset of the left side. (This argument\nseems to work in much greater generality; you just need that the relevant\ninfima (in place of intersections) exist in your poset.)\n\nFor the $\\subseteq$ direction, consider any element $x\\in\\bigcap\\bigcap S$,\nand suppose, toward a contradiction, that it is not an element of\nthe union on the right side of your equation. So, for each $F\\in S$,\nwe have $x\\notin\\bigcap F$, and therefore we can find a set $A_{F}\\in F$\nwith $x\\notin A_{F}$. Let $B=\\bigcup_{F\\in S}A_{F}$ and notice that\n$B\\in F$ for every $F\\in S$ (because $B\\supseteq A_{F}$). So $B\\in\\bigcap S$.\nBut, by choice of the $A_{F}$'s, we have $x\\notin B$, contrary to\nthe assumption that $x\\in\\bigcap\\bigcap S$.\\end{proof}\n\\begin{prop}\n$\\corestar\\Omega(U)$ is the set of infinite subsets of $U$.\\end{prop}\n\\begin{proof}\n$\\corestar\\Omega(U)=\\lnot\\rsupfun{\\lnot}\\Omega(U)$.\n\n$\\rsupfun{\\lnot}\\Omega$ is the set of finite subsets of~$U$. Thus\n$\\lnot\\rsupfun{\\lnot}\\Omega(U)$ is the set of infinite subsets of\n$U$.\n\\end{proof}\n\n\\subsection{Number of Filters on a Set}\n\\begin{defn}\n\\index{finite intersection property}A collection $Y$ of sets has\nfinite intersection property iff intersection of any finite subcollection\nof $Y$ is non-empty.\n\\end{defn}\nThe following was borrowed from \\cite{blassnotesultra}. Thanks to\n\\noun{Andreas Blass} for email support about his proof.\n\\begin{lem}\n(by \\noun{Hausdorff}) For an infinite set $X$ there is a family $\\mathcal{F}$\nof $2^{\\card X}$ many subsets of $X$ such that given any disjoint\nfinite subfamilies $\\mathcal{A}$, $\\mathcal{B}$, the intersection\nof sets in $\\mathcal{A}$ and complements of sets in $\\mathcal{B}$\nis nonempty.\\end{lem}\n\\begin{proof}\nLet\n\\[\nX'=\\setcond{(P,Q)}{P\\in\\subsets X\\text{ is finite},Q\\in\\subsets\\subsets P}.\n\\]\n\n\nIt's easy to show that $\\card X'=\\card X$. So it is enough to show\nthis for $X'$ instead of $X$. Let\n\\[\n\\mathcal{F}=\\setcond{\\setcond{(P,Q)\\in X'}{Y\\cap P\\in Q}}{Y\\in\\subsets X}.\n\\]\n\n\nTo finish the proof we show that for every disjoint finite $Y_{+}\\in\\subsets\\subsets X$\nand finite $Y_{-}\\in\\subsets\\subsets X$ there exist $(P,Q)\\in X'$\nsuch that\n\\[\n\\forall Y\\in Y_{+}:(P,Q)\\in\\setcond{(P,Q)\\in X'}{Y\\cap P\\in Q}\\quad\\text{and}\\quad\\forall Y\\in Y_{-}:(P,Q)\\notin\\setcond{(P,Q)\\in X'}{Y\\cap P\\in Q}\n\\]\nwhat is equivalent to existence $(P,Q)\\in X'$ such that\n\\[\n\\forall Y\\in Y_{+}:Y\\cap P\\in Q\\quad\\text{and}\\quad\\forall Y\\in Y_{-}:Y\\cap P\\notin Q.\n\\]\n\n\nFor existence of this $(P,Q)$, it is enough existence of $P$ such\nthat intersections $Y\\cap P$ are different for different $Y\\in Y_{+}\\cup Y_{-}$.\n\nReally, for each pair of distinct $Y_{0},Y_{1}\\in Y_{+}\\cup Y_{-}$\nchoose a point which lies in one of the sets $Y_{0}$, $Y_{1}$ and\nnot in an other, and call the set of such points $P$. Then $Y\\cap P$\nare different for different $Y\\in Y_{+}\\cup Y_{-}$.\\end{proof}\n\\begin{cor}\nFor an infinite set $X$ there is a family $\\mathcal{F}$ of $2^{\\card X}$\nmany subsets of $X$ such that for arbitrary disjoint subfamilies\n$\\mathcal{A}$ and $\\mathcal{B}$ the set $\\mathcal{A}\\cup\\setcond{X\\setminus A}{A\\in\\mathcal{B}}$\nhas finite intersection property.\\end{cor}\n\\begin{thm}\nLet $X$ be a set. The number of ultrafilters on $X$ is $2^{2^{\\card X}}$\nif $X$ is infinite and $\\card X$ if $X$ is finite.\\end{thm}\n\\begin{proof}\nThe finite case follows from the fact that every ultrafilter on a\nfinite set is trivial. Let $X$ be infinite. From the lemma, there\nexists a family $\\mathcal{F}$ of $2^{\\card X}$ many subsets of $X$\nsuch that for every $\\mathcal{G}\\in\\subsets\\mathcal{F}$ we have $\\Phi(\\mathcal{F},\\mathcal{G})=\\bigsqcap^{\\mathfrak{A}}\\mathcal{G}\\sqcap\\bigsqcap^{\\mathfrak{A}}\\setcond{X\\setminus A}{A\\in\\mathcal{F}\\setminus\\mathcal{G}}\\ne\\bot^{\\mathfrak{A}(X)}$.\n\nThis filter contains all sets from $\\mathcal{G}$ and does not contain\nany sets from $\\mathcal{F}\\setminus\\mathcal{G}$. So for every suitable\npairs $(\\mathcal{F}_{0},\\mathcal{G}_{0})$ and $(\\mathcal{F}_{1},\\mathcal{G}_{1})$\nthere is $A\\in\\Phi(\\mathcal{F}_{0},\\mathcal{G}_{0})$ such that $\\overline{A}\\in\\Phi(\\mathcal{F}_{1},\\mathcal{G}_{1})$.\nConsequently all filters $\\Phi(\\mathcal{F},\\mathcal{G})$ are disjoint.\nSo for every pair $(\\mathcal{F},\\mathcal{G})$ where $\\mathcal{G}\\in\\subsets\\mathcal{F}$\nthere exist a distinct ultrafilter under $\\Phi(\\mathcal{F},\\mathcal{G})$,\nbut the number of such pairs $(\\mathcal{F},\\mathcal{G})$ is $2^{2^{\\card X}}$.\nObviously the number of all filters is not above $2^{2^{\\card X}}$.\\end{proof}\n\\begin{cor}\nThe number of filters on $\\mathfrak{U}$ is $2^{2^{\\card X}}$ if\n$\\mathfrak{U}$ us infinite and $2^{\\card\\mathfrak{U}}$ if $\\mathfrak{U}$\nis finite.\\end{cor}\n\\begin{proof}\nThe finite case is obvious. The infinite case follows from the theorem\nand the fact that filters are collections of sets and there cannot\nbe more than $2^{2^{\\card\\mathfrak{U}}}$ collections of sets on $\\mathfrak{U}$.\n\\end{proof}\n\n\\section{Bases on filtrators}\n\n\\begin{defn}\n  A set $S$ of binary relations is a \\emph{base} on a filtrator~$(\\mathfrak{A},\\mathfrak{Z})$\n  of~$f\\in\\mathfrak{A}$ when all elements\n  of $S$ are above $f$ and $\\forall X \\in \\up f \\exists T \\in S : T \\sqsubseteq X$.\n\\end{defn}\n\n\\begin{obvious}\nEvery base on an up-aligned filtrator is nonempty.\n\\end{obvious}\n\n\\begin{prop}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item\\label{maxbase-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item\\label{maxbase-prim} $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator.\n\\item\\label{maxbase-fltr} $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered filtrator.\n\\item\\label{maxbase-res} A set $S\\in\\subsets\\mathfrak{Z}$ is a base of a filtrator element iff\n  $\\bigsqcap^{\\mathfrak{A}} S$ exists and~$S$ is a base of $\\bigsqcap^{\\mathfrak{A}} S$.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  ~\n  \\begin{description}\n  \\item[\\ref{maxbase-pow}$\\Rightarrow$\\ref{maxbase-prim}, \\ref{maxbase-prim}$\\Rightarrow$\\ref{maxbase-fltr}] Obvious.\n\n  \\item[\\ref{maxbase-fltr}$\\Rightarrow$\\ref{maxbase-res}]\n    ~\n    \\begin{description}\n      \\item[$\\Leftarrow$] Obvious.\n\n      \\item[$\\Rightarrow$] Let $S$ be a base of an~$f\\in\\mathfrak{A}$.\n      $f$~is obviously a lower bound of~$S$. Let~$g$ be a lower bound of~$S$.\n      Then for every $X\\in\\up f$ we have $g\\sqsubseteq X$ that is $X\\in\\up g$.\n      Thus $\\up f\\subseteq\\up g$ and thus $f\\sqsupseteq g$ that is~$f$ is the greatest upper bound of~$S$.\n    \\end{description}\n  \\end{description}\n\\end{proof}\n\n\\begin{prop}\nThere exists an~$f\\in\\mathfrak{A}$ such that $\\up f=S$ iff $S$ is a base and is an upper set\n(for every set~$S\\in\\subsets\\mathfrak{Z}$).\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Rightarrow$] If $\\up f=S$ then~$S$ is an upper set and~$S$ is a base of~$f$ because\n  $\\forall X\\in\\up f\\,\\exists T\\in S:T=X$.\n\n\\item[$\\Leftarrow$] Let~$S$ be a base of some filtrator element~$f$ and is an upper set.\nThen for every $X\\in\\up f$ there is $T\\in S$ such that $T\\sqsubseteq X$.\nThus $X\\in S$. We have $\\up f\\subseteq S$. But $S\\subseteq\\up f$ is obvious.\nWe have $\\up f=S$.\n\\end{description}\n\\end{proof}\n\n\\begin{prop}\n$\\up f$ is a base of~$f$ for every~$f\\in\\mathfrak{A}$.\n\\end{prop}\n\n\\begin{proof}\nDenote $S=\\up f$. That~$f$ is a lower bound of~$S$ is obvious.\n\nIf $X\\in\\up f$ then $\\exists T\\in S:T=X$. Thus~$S$ is a base of~$f$.\n\\end{proof}\n\n\\begin{prop}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item\\label{baseint-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item\\label{baseint-prim} $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator.\n\\item\\label{baseint-fltr} $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered filtrator.\n\\item\\label{baseint-res} $f = \\bigsqcap^{\\mathfrak{A}} S$ for every base~$S$ of an~$f\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  ~\n  \\begin{description}\n  \\item[\\ref{baseint-pow}$\\Rightarrow$\\ref{baseint-prim}, \\ref{baseint-prim}$\\Rightarrow$\\ref{baseint-fltr}] Obvious.\n\n  \\item[\\ref{baseint-fltr}$\\Rightarrow$\\ref{baseint-res}]\n    $f$ is a lower bound of~$S$ by definition.\n\n    Let~$g$ be a lower bound of~$S$. Then for every $X\\in\\up f$ there we have $g\\sqsubseteq X$ that is~$X\\in\\up g$.\n    Thus~$\\up f\\subseteq\\up g$ and thus $f\\sqsupseteq g$ that is $f$ is the greatest lower bound of~$S$.\n  \\end{description}\n\\end{proof}\n\n\\begin{prop}\nThe following is an implications tuple:\n  \\begin{enumerate}\n  \\item\\label{base-inf-pow} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n  \\item\\label{base-inf-prim} $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator.\n  \\item\\label{base-inf-fltr} $(\\mathfrak{A},\\mathfrak{Z})$ is a filtered filtrator.\n  \\item\\label{base-inf-res} If $S$ is a base on a filtrator, then $\\bigsqcap^{\\mathfrak{A}} S$ exists and\n    $\\up \\bigsqcap^{\\mathfrak{A}} S = \\bigcup_{K\\in S}\\up K$.\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  ~\n  \\begin{description}\n  \\item[\\ref{base-inf-pow}$\\Rightarrow$\\ref{base-inf-prim}, \\ref{base-inf-prim}$\\Rightarrow$\\ref{base-inf-fltr}] Obvious.\n\n  \\item[\\ref{base-inf-fltr}$\\Rightarrow$\\ref{base-inf-res}]\n    $\\bigsqcap^{\\mathfrak{A}} S$ exists because our filtrator is filtered.\n    Above we proved that~$S$ is a base of~$\\bigsqcap^{\\mathfrak{A}} S$.\n    That $\\bigcup_{K\\in S}\\up K \\subseteq \\up \\bigsqcap^{\\mathfrak{A}} S$ is obvious.\n    If $X\\in\\up\\bigsqcap^{\\mathfrak{A}} S$ then by properties of bases we have\n    $K\\in S$ such that $K\\sqsubseteq X$. Thus $X\\in\\up K$ and so $X\\in\\bigcup_{K\\in S}\\up K$.\n    So $\\up \\bigsqcap^{\\mathfrak{A}} S \\subseteq \\bigcup_{K\\in S}\\up K$.\n  \\end{description}\n\\end{proof}\n\n\\begin{prop}\nThe following is an implications tuple:\n\\begin{enumerate}\n\\item\\label{same-base-prim} $(\\mathfrak{A},\\mathfrak{Z})$ is a powerset filtrator.\n\\item\\label{same-base-flt} $(\\mathfrak{A},\\mathfrak{Z})$ is a primary filtrator over a meet-semilattice.\n\\item\\label{same-base-mid} $(\\mathfrak{A},\\mathfrak{Z})$ is a filtrator with binarily meet-closed core such that\n  $\\forall a\\in\\mathfrak{A}:\\up a\\ne\\emptyset$.\n\\item\\label{same-base-res} A base on the filtrator~$(\\mathfrak{A};\\mathfrak{Z})$ is the same\nas base of a filter (on~$\\mathfrak{Z}$).\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[\\ref{same-base-prim}$\\Rightarrow$\\ref{same-base-flt}] Obvious.\n\n\\item[\\ref{same-base-flt}$\\Rightarrow$\\ref{same-base-mid}] Corollary~\\ref{f-meet-closed}.\n\n\\item[\\ref{same-base-mid}$\\Rightarrow$\\ref{same-base-res}] ~\n  \\begin{description}\n  \\item[$\\Rightarrow$] Let~$S$ be a base of~$f$ on the filtrator~$(\\mathfrak{A};\\mathfrak{Z})$.\n  Then for every $a,b\\in S$ we have $a,b\\in\\up f$ and thus $a\\sqcap^{\\mathfrak{Z}}b=a\\sqcap^{\\mathfrak{A}}b\\in\\up f$.\n  Thus $\\exists x\\in S:x\\sqsubseteq a\\sqcap^{\\mathfrak{Z}}b$ that is $x\\sqsubseteq a\\land x\\sqsubseteq b$.\n  It remains to show that~$S$ is nonempty, but this follows from $\\up a$ being nonempty.\n\n  \\item[$\\Leftarrow$] Let~$S$ be a base of filter~$f$ (on~$\\mathfrak{Z}$).\n  Let $X\\in\\up f$. Then there is $T\\in S$ such that $T\\sqsubseteq X$.\n  \\end{description}\n\\end{description}\n\\end{proof}\n\n\\section{Some Counter-Examples}\n\\begin{example}\nThere exist a bounded distributive lattice which is not lattice with\nseparable center.\\end{example}\n\\begin{proof}\nThe lattice with the Hasse diagram\\footnote{See Wikipedia for a definition of Hasse diagrams.}\non figure \\ref{not-sep-center} is bounded and distributive because\nit does not contain ``diamond lattice'' nor ``pentagon lattice''\nas a sublattice \\cite{wiki:distributive-lattice}.\n\\begin{figure}\n\\[\n\\xymatrix{ & 1\\\\\n & a\\ar@{-}[u]\\\\\nx\\ar@{-}[ur] &  & y\\ar@{-}[ul]\\\\\n & 0\\ar@{-}[ul]\\ar@{-}[ur]\n}\n\\]\n\\caption{\\label{not-sep-center}}\n\\end{figure}\n\n\nIt's center is $\\{0,1\\}$. $x\\sqcap y=0$ despite $\\up x=\\{x,a,1\\}$\nbut $y\\sqcap1\\ne 0$ consequently the lattice is not with separable\ncenter.\\end{proof}\n\nIn this section $\\mathfrak{A}$ denotes the set of filters on a set.\n\\begin{example}\nThere is a separable poset (that is a set with $\\fullstar$ being\nan injection) which is not strongly separable (that is $\\fullstar$ isn't order reflective).\\end{example}\n\\begin{proof}\n(with help of sci.math partakers) Consider a poset with the Hasse\ndiagram~\\ref{sep-counter}.\n\n\\begin{figure}[ht]\n\\[\n\\xymatrix{a\\ar@{-}[d]\\ar@{-}[dr] & b\\ar@{-}[dl]\\ar@{-}[d]\\ar@{-}[dr]\\\\\np & q & r\n}\n\\]\n\\caption{\\label{sep-counter}}\n\\end{figure}\n\n\nThen $\\fullstar p=\\{p,a,b\\}$, $\\fullstar q=\\{q,a,b\\}$, $\\fullstar r=\\{r,b\\}$,\n$\\fullstar a=\\{p,q,a,b\\}$, $\\fullstar b=\\{p,q,a,b,r\\}$.\n\nThus $\\fullstar x=\\fullstar y\\Rightarrow x=y$ for any $x$, $y$\nin our poset.\n\n$\\fullstar a\\subseteq\\fullstar b$ but not $a\\sqsubseteq b$.\\end{proof}\n\\begin{example}\nThere is a prefiltered filtrator which is not filtered.\\end{example}\n\\begin{proof}\n(\\noun{Matthias Klupsch}) Take $\\mathfrak{A}=\\{a,b\\}$ with the order\nbeing equality and $\\mathfrak{Z}=\\{b\\}$. Then $\\up a=\\emptyset\\sqsubseteq\\{b\\}=\\up b$,\nso $\\up$ is injective, hence the filtrator is prefiltered, but because\nof $a\\nsqsubseteq b$ the filtrator is not filtered.\n\\end{proof}\nFor further examples we will use the filter $\\Delta$ defined by the\nformula\n\\[\n\\Delta=\\bigsqcap^{\\mathfrak{A}}\\setcond{]-\\epsilon;\\epsilon[}{\\epsilon\\in\\mathbb{R},\\epsilon>0}\n\\]\nand more general\n\\[\n\\Delta+a=\\bigsqcap^{\\mathfrak{A}}\\setcond{]a-\\epsilon;a+\\epsilon[}{\\epsilon\\in\\mathbb{R},\\epsilon>0}.\n\\]\n\n\\begin{example}\nThere exists $A\\in\\subsets U$ such that $\\bigsqcap^{\\mathfrak{A}}A\\ne\\bigsqcap A$.\\end{example}\n\\begin{proof}\n$\\bigsqcap^{\\mathfrak{Z}}\\setcond{]-\\epsilon;\\epsilon[}{\\epsilon\\in\\mathbb{R},\\epsilon>0}=\\uparrow\\{0\\}\\ne\\Delta$.\\end{proof}\n\\begin{example}\nThere exists a set $U$ and a filter $a$ and a set $S$ of filters\non the set $U$ such that $a\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S\\ne\\bigsqcup^{\\mathfrak{A}}\\rsupfun{a\\sqcap^{\\mathfrak{A}}}S$.\\end{example}\n\\begin{proof}\nLet $a=\\Delta$ and $S=\\setcond{\\uparrow^{\\mathbb{R}}]\\epsilon;+\\infty[}{\\epsilon>0}$.\nThen $a\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}S=\\Delta\\sqcap^{\\mathfrak{A}}]0;+\\infty[)\\ne\\bot^{\\mathfrak{A}}$\nwhile $\\bigsqcup^{\\mathfrak{A}}\\rsupfun{a\\sqcap^{\\mathfrak{A}}}S=\\bigsqcup^{\\mathfrak{A}}\\{\\bot^{\\mathfrak{A}}\\}=\\bot^{\\mathfrak{A}}$.\\end{proof}\n\\begin{example}\nThere are tornings which are not weak partitions.\\end{example}\n\\begin{proof}\n$\\setcond{\\Delta+a}{a\\in\\mathbb{R}}$ is a torning but not weak partition\nof the real line.\\end{proof}\n\\begin{lem}\nLet $\\mathfrak{A}$ be the set of filters on a set $U$. Then $X\\sqcap^{\\mathfrak{A}}\\Omega\\sqsubseteq Y\\sqcap^{\\mathfrak{A}}\\Omega$\niff $X\\setminus Y$ is a finite set, having fixed sets $X,Y\\in\\subsets U$.\\end{lem}\n\\begin{proof}\nLet $M$ be the set of finite subsets of $U$.\n\\begin{align*}\nX\\sqcap^{\\mathfrak{A}}\\Omega\\sqsubseteq Y\\sqcap^{\\mathfrak{A}}\\Omega & \\Leftrightarrow\\\\\n\\setcond{X\\cap K_{X}}{K_{X}\\in\\Omega}\\supseteq\\setcond{Y\\cap K_{Y}}{K_{Y}\\in\\Omega} & \\Leftrightarrow\\\\\n\\forall K_{Y}\\in\\Omega\\exists K_{X}\\in\\Omega:Y\\cap K_{Y}=X\\cap K_{X} & \\Leftrightarrow\\\\\n\\forall L_{Y}\\in M\\exists L_{X}\\in M:Y\\setminus L_{Y}=X\\setminus L_{X} & \\Leftrightarrow\\\\\n\\forall L_{Y}\\in M:X\\setminus(Y\\setminus L_{Y})\\in M & \\Leftrightarrow\\\\\nX\\setminus Y\\in M.\n\\end{align*}\n\\end{proof}\n\\begin{example}\nThere exists a filter $\\mathcal{A}$ on a set $U$ such that $(\\subsets U)/\\mathord\\sim$\nand $Z(D\\mathcal{A})$ are not complete lattices.\\end{example}\n\\begin{proof}\nDue to the isomorphism it is enough to prove for $(\\subsets U)/\\mathord\\sim$.\n\nLet take $U=\\mathbb{N}$ and $\\mathcal{A}=\\Omega$ be the Fr\\'echet\nfilter on $\\mathbb{N}$.\n\nPartition $\\mathbb{N}$ into infinitely many infinite sets $A_{0},A_{1},\\ldots$.\nTo withhold our example we will prove that the set $\\{[A_{0}],[A_{1}],\\dots\\}$\nhas no supremum in $(\\subsets U)/\\mathord\\sim$.\n\nLet $[X]$ be an upper bound of $[A_{0}],[A_{1}],\\ldots$ that is\n$\\forall i\\in\\mathbb{N}:X\\sqcap^{\\mathfrak{A}}\\Omega\\sqsupseteq A_{i}\\sqcap^{\\mathfrak{A}}\\Omega$\nthat is $A_{i}\\setminus X$ is finite. Consequently $X$ is infinite.\nSo $X\\cap A_{i}\\ne\\emptyset$.\n\nChoose for every $i\\in\\mathbb{N}$ some $z_{i}\\in X\\cap A_{i}$. The\n$\\{z_{0},z_{1},\\dots\\}$ is an infinite subset of $X$ (take into\naccount that $z_{i}\\ne z_{j}$ for $i\\ne j$). Let $Y=X\\setminus\\{z_{0},z_{1},\\dots\\}$.\nThen $Y\\sqcap^{\\mathfrak{A}}\\Omega\\sqsupseteq A_{i}\\sqcap^{\\mathfrak{A}}\\Omega$\nbecause $A_{i}\\setminus Y=A_{i}\\setminus(X\\setminus\\{z_{i}\\})=(A_{i}\\setminus X)\\cup\\{z_{i}\\}$\nwhich is finite because $A_{i}\\setminus X$ is finite. Thus $[Y]$\nis an upper bound for $\\{[A_{0}],[A_{1}],\\dots\\}$.\n\nSuppose $Y\\sqcap^{\\mathfrak{A}}\\Omega=X\\sqcap^{\\mathfrak{A}}\\Omega$.\nThen $Y\\setminus X$ is finite what is not true. So $Y\\sqcap^{\\mathfrak{A}}\\Omega\\sqsubset X\\sqcap^{\\mathfrak{A}}\\Omega$\nthat is $[Y]$ is below $[X]$.\n\\end{proof}\n\n\\subsection{Weak and Strong Partition}\n\\begin{defn}\n\\index{independent family}A family $S$ of subsets of a countable\nset is \\emph{independent} iff the intersection of any finitely many\nmembers of $S$ and the complements of any other finitely many members\nof $S$ is infinite.\\end{defn}\n\\begin{lem}\nThe ``infinite'' at the end of the definition could be equivalently\nreplaced with ``nonempty'' if we assume that $S$ is infinite.\\end{lem}\n\\begin{proof}\nSuppose that some sets from the above definition has a finite intersection\n$J$ of cardinality $n$. Then (thanks $S$ is infinite) get one more\nset $X\\in S$ and we have $J\\cap X\\ne\\emptyset$ and $J\\cap(\\mathbb{N}\\setminus X)\\ne\\emptyset$.\nSo $\\card(J\\cap X)<n$. Repeating this, we prove that for some finite\nfamily of sets we have empty intersection what is a contradiction.\\end{proof}\n\\begin{lem}\nThere exists an independent family on $\\mathbb{N}$ of cardinality\n$\\mathfrak{c}$.\\end{lem}\n\\begin{proof}\nLet $C$ be the set of finite subsets of $\\mathbb{Q}$. Since $\\card C=\\card\\mathbb{N}$,\nit suffices to find $\\mathfrak{c}$ independent subsets of $C$. For\neach $r\\in\\mathbb{R}$ let\n\\[\nE_{r}=\\setcond{F\\in C}{\\card(F\\cap]-\\infty;r[)\\text{ is even}}.\n\\]\n\n\nAll $E_{r_{1}}$ and $E_{r_{2}}$ are distinct for distinct $r_{1},r_{2}\\in\\mathbb{R}$\nsince we may consider $F=\\{r'\\}\\in C$ where a rational number $r'$\nis between $r_{1}$ and $r_{2}$ and thus $F$ is a member of exactly\none of the sets $E_{r_{1}}$ and $E_{r_{2}}$. Thus $\\card\\setcond{E_{r}}{r\\in\\mathbb{R}}=\\mathfrak{c}$.\n\nWe will show that $\\setcond{E_{r}}{r\\in\\mathbb{R}}$ is independent.\nLet $r_{1},\\dots,r_{k},s_{1},\\ldots,s_{k}$ be distinct reals. It\nis enough to show that these have a nonempty intersection, that is\nexistence of some $F$ such that $F$ belongs to all the $E_{r}$\nand none of $E_{s}$.\n\nBut this can be easily accomplished taking $F$ having zero or one\nelement in each of intervals to which $r_{1},\\ldots,r_{k},s_{1},\\ldots,s_{k}$\nsplit the real line.\\end{proof}\n\\begin{example}\nThere exists a weak partition of a filter on a set which is not a\nstrong partition.\\end{example}\n\\begin{proof}\n(suggested by \\noun{Andreas Blass}) Let $\\setcond{X_{r}}{r\\in\\mathbb{R}}$ be\nan independent family of subsets of $\\mathbb{N}$. We can assume $a\\ne b\\Rightarrow X_{a}\\ne X_{b}$\ndue the above lemma.\n\nLet $\\mathcal{F}_{a}$ be a filter generated by $X_{a}$ and the complements\n$\\mathbb{N}\\setminus X_{b}$ for all $b\\in\\mathbb{R}$, $b\\ne a$.\nIndependence implies that $\\mathcal{F}_{a}\\ne\\bot^{\\mathfrak{A}}$\n(by properties of filter bases).\n\nLet $S=\\setcond{\\mathcal{F}_{r}}{r\\in\\mathbb{R}}$. We will prove\nthat $S$ is a weak partition but not a strong partition.\n\nLet $a\\in\\mathbb{R}$. Then $X_{a}\\in\\mathcal{F}_{a}$ while $\\forall b\\in\\mathbb{R}\\setminus\\{a\\}:\\mathbb{N}\\setminus X_{a}\\in\\mathcal{F}_{b}$\nand therefore $\\mathbb{N}\\setminus X_{a}\\in\\bigsqcup^{\\mathfrak{A}}\\setcond{\\mathcal{F}_{b}}{\\mathbb{R}\\ni b\\ne a}$.\nTherefore $\\mathcal{F}_{a}\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}\\setcond{\\mathcal{F}_{b}}{\\mathbb{R}\\ni b\\ne a}=\\bot^{\\mathfrak{A}}$.\nThus $S$ is a weak partition.\n\nSuppose $S$ is a strong partition. Then for each set $Z\\in\\subsets\\mathbb{R}$\n\\[\n\\bigsqcup^{\\mathfrak{A}}\\setcond{\\mathcal{F}_{b}}{b\\in Z}\\sqcap^{\\mathfrak{A}}\\bigsqcup^{\\mathfrak{A}}\\setcond{\\mathcal{F}_{b}}{b\\in\\mathbb{R}\\setminus Z}=\\bot^{\\mathfrak{A}}\n\\]\nwhat is equivalent to existence of $M(Z)\\in\\subsets\\mathbb{N}$ such\nthat\n\\[\nM(Z)\\in\\bigsqcup^{\\mathfrak{A}}\\setcond{\\mathcal{F}_{b}}{b\\in Z}\\quad\\text{and}\\quad\\mathbb{N}\\setminus M(Z)\\in\\bigsqcup^{\\mathfrak{A}}\\setcond{\\mathcal{F}_{b}}{b\\in\\mathbb{R}\\setminus Z}\n\\]\nthat is\n\\[\n\\forall b\\in Z:M(Z)\\in\\mathcal{F}_{b}\\quad\\text{and}\\quad\\forall b\\in\\mathbb{R}\\setminus Z:\\mathbb{N}\\setminus M(Z)\\in\\mathcal{F}_{b}.\n\\]\n\n\nSuppose $Z\\ne Z'\\in\\subsets\\mathbb{N}$. Without loss of generality\nwe may assume that some $b\\in Z$ but $b\\notin Z'$. Then $M(Z)\\in\\mathcal{F}_{b}$\nand $\\mathbb{N}\\setminus M(Z')\\in\\mathcal{F}_{b}$. If $M(Z)=M(Z')$\nthen $\\mathcal{F}_{b}=\\bot^{\\mathfrak{A}}$ what contradicts to the\nabove.\n\nSo $M$ is an injective function from $\\subsets\\mathbb{R}$ to $\\subsets\\mathbb{N}$\nwhat is impossible due cardinality issues.\\end{proof}\n\\begin{lem}\n(by \\noun{Niels Diepeveen}, with help of \\noun{Karl Kronenfeld}) Let\n$K$ be a collection of nontrivial ultrafilters. We have $\\bigsqcup K=\\Omega$\niff $\\exists\\mathcal{G}\\in K:A\\in\\up\\mathcal{G}$ for every infinite\nset $A$.\\end{lem}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] Suppose $\\bigsqcup K=\\Omega$ and let $A$ be\na set such that $\\nexists\\mathcal{G}\\in K:A\\in\\up\\mathcal{G}$. Let's\nprove $A$ is finite.\n\n\nReally, $\\forall\\mathcal{G}\\in K:\\mathfrak{U}\\setminus A\\in\\up\\mathcal{G}$;\n$\\mathfrak{U}\\setminus A\\in\\up\\Omega$; $A$ is finite.\n\n\\item [{$\\Leftarrow$}] Let $\\exists\\mathcal{G}\\in K:A\\in\\up\\mathcal{G}$.\nSuppose $A$ is a set in $\\up\\bigsqcup K$.\n\n\nTo finish the proof it's enough to show that $\\mathfrak{U}\\setminus A$\nis finite.\n\n\nSuppose $\\mathfrak{U}\\setminus A$ is infinite. Then $\\exists\\mathcal{G}\\in K:\\mathfrak{U}\\setminus A\\in\\up\\mathcal{G}$;\n$\\exists\\mathcal{G}\\in K:A\\notin\\up\\mathcal{G}$; $A\\notin\\up\\bigsqcup K$,\ncontradiction.\n\n\\end{description}\n\\end{proof}\n\\begin{lem}\n(by \\noun{Niels Diepeveen}) If $K$ is a non-empty set of ultrafilters\nsuch that $\\bigsqcup K=\\Omega$, then for every $\\mathcal{G}\\in K$\nwe have $\\bigsqcup(K\\setminus\\{\\mathcal{G}\\})=\\Omega$.\\end{lem}\n\\begin{proof}\n$\\exists\\mathcal{F}\\in K:A\\in\\up\\mathcal{F}$ for every infinite set\n$A$.\n\nThe set $A$ can be partitioned into two infinite sets $A_{1}$, $A_{2}$.\n\nTake $\\mathcal{F}_{1},\\mathcal{F}_{2}\\in K$ such that $A_{1}\\in\\mathcal{F}_{1}$,\n$A_{2}\\in\\mathcal{F}_{2}$.\n\n$\\mathcal{F}_{1}\\ne\\mathcal{F}_{2}$ because otherwise $A_{1}$ and\n$A_{2}$ are not disjoint.\n\nObviously $A\\in\\mathcal{F}_{1}$ and $A\\in\\mathcal{F}_{2}$.\n\nSo there exist two different $\\mathcal{F}\\in K$ such that $A\\in\\up\\mathcal{F}$.\nConsequently $\\exists\\mathcal{F}\\in K\\setminus\\{\\mathcal{G}\\}:A\\in\\up\\mathcal{F}$\nthat is $\\bigsqcup(K\\setminus\\{\\mathcal{G}\\})=\\Omega$.\\end{proof}\n\\begin{example}\nThere exists a filter on a set which cannot be weakly partitioned\ninto ultrafilters.\\end{example}\n\\begin{proof}\nConsider cofinite filter $\\Omega$ on any infinite set.\n\nSuppose $K$ is its weak partition into ultrafilters. Then $x\\asymp\\bigsqcup(K\\setminus\\{x\\})$\nfor some ultrafilter $x\\in K$.\n\nWe have $\\bigsqcup(K\\setminus\\{x\\})\\sqsubset\\bigsqcup K$ (otherwise\n$x\\sqsubseteq\\bigsqcup(K\\setminus\\{x\\})$) what is impossible due\nthe last lemma.\\end{proof}\n\\begin{cor}\nThere exists a filter on a set which cannot be strongly partitioned\ninto ultrafilters.\n\\end{cor}\n\n\\section{Open problems about filters}\n\nUnder which conditions $a\\psetminus b$ and $a\\mathop\\#b$ are complementive\nto $a$?\n\nGeneralize straight maps for arbitrary posets.\n\n\n\\section{Further notation}\n\nBelow to define funcoids and reloids we need a fixed powerset filtrator.\n\nLet $(\\mathscr{F}A,\\mathscr{T}A)$ be an arbitrary but fixed powerset\nfiltrator. This filtrator exists by the theorem~\\ref{thm1:prim-exists}.\n\n\\index{filter object}I will call elements of $\\mathscr{F}$ \\emph{filter\nobjects}.\n\nFor brevity we will denote lattice operations on $\\mathscr{F}A$ without\nindexes (for example, take $\\bigsqcap S=\\bigsqcap^{\\mathscr{F}A}S$\nfor $S\\in\\subsets\\mathscr{F}A$).\n\nNote that above we also took operations on $\\mathscr{T}A$ without\nindexes (for example, take $\\bigsqcap S=\\bigsqcap^{\\mathscr{T}A}S$\nfor $S\\in\\subsets\\mathscr{T}A$).\n\nBecause we identify $\\mathscr{T}A$ with principal elements of $\\mathscr{F}A$,\nthe notation like $\\bigsqcap S$ for $S\\in\\subsets\\mathscr{T}A$ would\nbe inconsistent (it can mean both $\\bigsqcap^{\\mathscr{T}A}S$ or\n$\\bigsqcap^{\\mathscr{F}A}S$). We explicitly state that $\\bigsqcap S$\nin this case does \\emph{not} mean $\\bigsqcap^{\\mathscr{F}A}S$.\n\nFor $\\mathcal{X}\\in\\mathscr{F}$ we will denote $\\GR\\mathcal{X}$\nthe corresponding filter on $\\subsets A$. It is a convenient notation\nto describe relations between filters and sets, consider for example\nthe formula: $\\{x\\}\\subseteq\\bigcap\\GR\\mathcal{X}$.\n\nWe will denote lattice operations without pointing a specific set\nlike $\\bigsqcap^{\\mathscr{F}}S=\\bigsqcap^{\\mathscr{F}(A)}S$ for a\nset $S\\in\\subsets\\mathscr{F}(A)$.\n\n\\section{Equivalent filters and rebase of filters}\n\nThroughout this section we will assume that~$\\mathfrak{Z}$\nis a lattice.\n\nAn important example:~$\\mathfrak{Z}$ is the lattice of\nall small (regarding some Grothendieck universe) sets.\n(This~$\\mathfrak{Z}$ is not\na powerset, and even not a complete lattice.)\n\nThroughout this section I will use the word \\emph{filter}\nto denote a filter on a sublattice~$DA$\nwhere~$A\\in\\mathfrak{Z}$ (if not told explicitly to be a\nfilter on some other set).\n\nThe following is an embedding from\nfilters~$\\mathcal{A}$ on a lattice~$DA$ into the lattice of\nfilters on~$\\mathfrak{Z}$:\n$\\mathscr{S}\\mathcal{A}=\\setcond{K\\in\\mathfrak{Z}}{\n\\exists X\\in\\mathcal{A}:X\\sqsubseteq K}$.\n\n\\begin{prop}\nValues of this embedding are filters on the\nlattice~$\\mathfrak{Z}$.\n\\end{prop}\n\n\\begin{proof}\nThat $\\mathscr{S}\\mathcal{A}$ is an upper set is obvious.\n\nLet $P,Q\\in\\mathscr{S}\\mathcal{A}$.\nThen~$P,Q\\in\\mathfrak{Z}$ and there is an $X\\in\\mathcal{A}$\nsuch that~$X\\sqsubseteq P$ and $Y\\in\\mathcal{A}$ such\nthat~$Y\\sqsubseteq Q$. So $X\\sqcap Y\\in\\mathcal{A}$\nand $P\\sqcap Q\\sqsupseteq X\\sqcap Y\\in\\mathcal{A}$, so\n$P\\sqcap Q\\in\\mathscr{S}A$.\n\\end{proof}\n\n\\subsection{Rebase of filters}\n\n\\begin{defn}\n\\index{rebase!filters}\\emph{Rebase} for every\nfilter~$\\mathcal{A}$\nand every $A\\in\\mathfrak{Z}$ is\n  $\\mathcal{A} \\div A = \\bigsqcap \\setcond{ \\uparrow^A  (X \\sqcap A) }\n  { X \\in \\mathcal{A} }$.\n\\end{defn}\n\n\\begin{obvious}\n$\\rsupfun{A\\sqcap}\\mathscr{S}\\mathcal{A}$ is a filter on $A$.\n\\end{obvious}\n\n\\begin{prop}\nThe rebase conforms to the formula\n\\[\n\\mathcal{A}\\div A=\\rsupfun{A\\sqcap}\\mathscr{S}\\mathcal{A}.\n\\]\n\\end{prop}\n\n\\begin{proof}\nWe know that $\\rsupfun{A\\sqcap}\\mathscr{S}\\mathcal{A}$ is a\nfilter.\n\nIf $P \\in \\rsupfun{A\\sqcap}\\mathscr{S}\\mathcal{A}$ then $P \\in \\subsets A$ and $Y\\sqcap A\n\\sqsubseteq P$ for some $Y \\in \\mathcal{A}$. Thus $P \\sqsupseteq Y \\sqcap A \\in\n\\bigsqcap \\setcond{ \\uparrow^A  (Y \\sqcap A) }{ Y \\in \\mathcal{A} }$.\n\nIf $P \\in \\bigsqcap \\setcond{ \\uparrow^A  (X \\sqcap A) }{\nX \\in \\mathcal{A} }$ then by properties of generalized filter bases,\nthere exists $X \\in \\mathcal{A}$ such that $P \\sqsupseteq X \\sqcap A$. Also $P \\in\n\\subsets A$. Thus $P \\in \\rsupfun{A\\sqcap}\\mathscr{S}\\mathcal{A}$.\n\\end{proof}\n\n\\begin{prop}\\label{rebase-itself}\n$\\mathcal{X}\\div\\Base(\\mathcal{X}) = \\mathcal{X}$.\n\\end{prop}\n\n\\begin{proof}\nBecause $X\\sqcap\\Base(\\mathcal{X}) = X$ for\n$X\\in\\mathcal{X}$.\n\\end{proof}\n\n\\begin{prop}\\label{double-rebase}\n  $(\\mathcal{X} \\div A) \\div B = \\mathcal{X} \\div B$ if $B \\sqsubseteq A$.\n\\end{prop}\n\n\\begin{proof}\n\\begin{multline*}\n(\\mathcal{X} \\div A) \\div B = \\bigsqcap \\setcond{ \\uparrow^B  (Y \\sqcap B)\n  }{ Y \\in \\bigsqcap \\setcond{ \\uparrow^A  (X \\sqcap A)}\n  {X \\in \\mathcal{X} } \\mathcal{} } =\n  \\bigsqcap \\setcond{ \\uparrow^B  (X \\sqcap A) }{ X \\in\n  \\mathcal{X} } \\sqcap \\uparrow^B B =\\\\\n  \\bigsqcap \\setcond{ \\uparrow^B  (X\n  \\sqcap A \\sqcap B) }{ X \\in \\mathcal{X} } =\n  \\bigsqcap \\setcond{ \\uparrow^B  (X\n  \\sqcap B) }{ X \\in \\mathcal{X} } =\n  \\mathcal{X} \\div B.\n\\end{multline*}\n\\end{proof}\n\n\\begin{prop}\nIf $A\\in\\mathcal{A}$ then\n$\\mathcal{A}\\div A=\\mathcal{A}\\cap\\subsets A$.\n\\end{prop}\n\n\\begin{proof}\n$\\mathcal{A}\\div A=\n\\rsupfun{A\\sqcap}\\mathscr{S}\\mathcal{A} =\n\\rsupfun{A\\sqcap}\\setcond{K\\in\\mathfrak{Z}}{\n\\exists X\\in\\mathcal{A}:X\\sqsubseteq K} =\n\\setcond{K\\in\\mathfrak{Z}}{\nK\\in\\mathcal{A}\\land K\\in\\subsets A} =\n\\mathcal{A}\\cap\\subsets A$.\n\\end{proof}\n\n\\begin{prop}\nLet filters~$\\mathcal{X}$\nand~$\\mathcal{Y}$ be such that\n$\\Base(\\mathcal{X})=\\Base(\\mathcal{Y})=B$. Then\n$\\mathcal{X}\\div C=\\mathcal{Y}\\div C\n\\Leftrightarrow \\mathcal{X}=\\mathcal{Y}$ for every\n$\\mathfrak{Z}\\ni C\\sqsupseteq B$.\n\\end{prop}\n\n\\begin{proof}\n$\\mathcal{X}\\div C=\\mathcal{Y}\\div C\\Leftrightarrow\n\\mathcal{X}\\cup\\setcond{K\\in\\subsets C}{K\\sqsupseteq B} = \\mathcal{Y}\\cup\\setcond{K\\in\\subsets C}{K\\sqsupseteq B} \\Leftrightarrow\n\\mathcal{X}=\\mathcal{Y}$.\n\\end{proof}\n\n\\subsection{Equivalence of filters}\n\n\\begin{defn}\n\\index{equivalent!filters}Two filters $\\mathcal{A}$ and $\\mathcal{B}$\n(with possibly different base sets) are equivalent ($\\mathcal{A}\\sim\\mathcal{B}$)\niff there exists an~$X\\in\\mathfrak{Z}$ such that $X\\in\\mathcal{A}$ and $X\\in\\mathcal{B}$\nand $\\subsets X\\cap\\mathcal{A}=\\subsets X\\cap\\mathcal{B}$.\\end{defn}\n\n\\begin{prop}\n$\\mathcal{X}$ and~$\\mathcal{Y}$ are equivalent iff\n($\\mathcal{X}\\sim\\mathcal{Y}$) iff\n$\\mathcal{Y} = \\mathcal{X} \\div \\Base(\\mathcal{Y})$ and\n$\\mathcal{X} = \\mathcal{Y} \\div \\Base(\\mathcal{X})$.\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Rightarrow$] Suppose $\\mathcal{X}\\sim\\mathcal{Y}$\nthat is there exists a set~$P$ such that\n$\\subsets P\\cap\\mathcal{X}=\\subsets P\\cap\\mathcal{Y}$ and\n$P\\in\\mathcal{X}$, $P\\in\\mathcal{Y}$. Then\n$\\mathcal{X}\\div\\Base(\\mathcal{Y}) =\n(\\subsets P\\cap\\mathcal{X})\\cup\n\\setcond{K\\in\\subsets\\Base(\\mathcal{Y})}{K\\sqsupseteq P} =\n(\\subsets P\\cap\\mathcal{Y})\\cup\n\\setcond{K\\in\\subsets\\Base(\\mathcal{Y})}{K\\sqsupseteq P} =\n\\mathcal{Y}$. So\n$\\mathcal{X}\\div\\Base(\\mathcal{Y}) = \\mathcal{Y}$,\n$\\mathcal{Y}\\div\\Base(\\mathcal{X}) = \\mathcal{X}$ is similar.\n\n\\item[$\\Leftarrow$] We have\n$\\mathcal{Y}=(\\mathcal{Y}\\div\\Base(\\mathcal{X}))\\div\\Base(\\mathcal{Y})$.\n\nThus as easy to show\n$\\Base(\\mathcal{X})\\sqcap\\Base(\\mathcal{Y})\\in\\mathcal{Y}$\nand similarly\n$\\Base(\\mathcal{X})\\sqcap\\Base(\\mathcal{Y})\\in\\mathcal{X}$.\n\nIt's enough to show\n$\\mathcal{X}\\div(\\Base(\\mathcal{X})\\sqcap\\Base(\\mathcal{Y})) =\n\\mathcal{Y}\\div(\\Base(\\mathcal{X})\\sqcap\\Base(\\mathcal{Y}))$\nbecause for every $P\\in\\mathcal{X},\\mathcal{Y}$ we have $\\mathcal{X}\\cap\\subsets P = \\mathcal{X}\\div P =\n(\\mathcal{X}\\div(\\Base(\\mathcal{X})\\sqcap\\Base(\\mathcal{Y})))\\div P$ and similarly $\\mathcal{Y}\\cap\\subsets P =\n(\\mathcal{Y}\\div(\\Base(\\mathcal{X})\\sqcap\\Base(\\mathcal{Y})))\\div P$. But it follows from the conditions and\nproposition~\\ref{double-rebase}.\n\\end{description}\n\\end{proof}\n\n\\begin{prop}\nIf two filters with the same base are equivalent they are equal.\\end{prop}\n\\begin{proof}\nLet $\\mathcal{A}$ and $\\mathcal{B}$ be two filters and $\\subsets X\\cap\\mathcal{A}=\\subsets X\\cap\\mathcal{B}$\nfor some set $X$ such that $X\\in\\mathcal{A}$ and $X\\in\\mathcal{B}$,\nand $\\Base(\\mathcal{A})=\\Base(\\mathcal{B})$. Then\n\\begin{multline*}\n\\mathcal{A}=(\\subsets X\\cap\\mathcal{A})\\cup\\setcond{Y\\in D\\Base(\\mathcal{A})}{Y\\sqsupseteq X}=\\\\\n(\\subsets X\\cap\\mathcal{B})\\cup\n\\setcond{Y\\in D\\Base(\\mathcal{B})}{Y\\sqsupseteq X}=\\mathcal{B}.\n\\end{multline*}\n\\end{proof}\n\n\\begin{prop}\\label{filteq-ext}\nIf $A\\in\\mathscr{S}\\mathcal{A}$ then\n$\\mathcal{A}\\div A\\sim\\mathcal{A}$.\n\\end{prop}\n\\begin{proof}\n~\n\\begin{align*}\n(\\mathcal{A}\\div A)\\cap\\subsets(A\\sqcap\\Base(\\mathcal{A})) & =\\\\\n\\mathscr{S}\\mathcal{A}\\cap\\subsets A\\cap\\subsets(A\\sqcap\\Base(\\mathcal{A})) & =\\\\\n\\mathscr{S}\\mathcal{A}\\cap\\subsets(A\\sqcap\\Base(\\mathcal{A})) & =\n\\mathcal{A}\\cap\\subsets(A\\sqcap\\Base(\\mathcal{A})).\n\\end{align*}\nThus $\\mathcal{A}\\div A\\sim\\mathcal{A}$ because $A\\sqcap\\Base(\\mathcal{A})\\sqsupseteq X\\in\\mathcal{A}$\nfor some $X\\in\\mathcal{A}$ and \n\\[\nA\\sqcap\\Base(\\mathcal{A})\\sqsupseteq X\\sqcap\\Base(\\mathcal{A})\\in\\mathcal{A}\\div A.\n\\]\n\\end{proof}\n\n\\begin{prop}\n$\\sim$ is an equivalence relation.\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{Reflexivity}] Obvious.\n\\item [{Symmetry}] Obvious.\n\\item [{Transitivity}] Let $\\mathcal{A}\\sim\\mathcal{B}$ and $\\mathcal{B}\\sim\\mathcal{C}$\nfor some filters $\\mathcal{A}$, $\\mathcal{B}$, and $\\mathcal{C}$.\nThen there exist a set $X$ such that $X\\in\\mathcal{A}$ and $X\\in\\mathcal{B}$\nand $\\subsets X\\cap\\mathcal{A}=\\subsets X\\cap\\mathcal{B}$ and a set\n$Y$ such that $Y\\in\\mathcal{B}$ and $Y\\in\\mathcal{C}$ and $\\subsets Y\\cap\\mathcal{B}=\\subsets Y\\cap\\mathcal{C}$.\nSo $X\\sqcap Y\\in\\mathcal{A}$ because\n\\[\n\\subsets Y\\cap\\subsets X\\cap\\mathcal{A}=\\subsets Y\\cap\\subsets X\\cap\\mathcal{B}=\\subsets(X\\sqcap Y)\\cap\\mathcal{B}\\supseteq\\{X\\sqcap Y\\}\\cap\\mathcal{B}\\ni X\\sqcap Y.\n\\]\nSimilarly we have $X\\sqcap Y\\in\\mathcal{C}$. Finally\n\\begin{multline*}\n\\subsets(X\\sqcap Y)\\cap\\mathcal{A}=\\subsets Y\\cap\\subsets X\\cap\\mathcal{A}=\\subsets Y\\cap\\subsets X\\cap\\mathcal{B}=\\\\\n\\subsets X\\cap\\subsets Y\\cap\\mathcal{B}=\\subsets X\\cap\\subsets Y\\cap\\mathcal{C=}\\subsets(X\\sqcap Y)\\cap\\mathcal{C}.\n\\end{multline*}\n\n\\end{description}\n\\end{proof}\n\n\\begin{defn}\nI will call equivalence classes as\n\\emph{unfixed filters}.\n\\end{defn}\n\n\\begin{rem}\nThe word ``unfixed'' is meant to negate ``fixed'' (having\na particular base) filters.\n\\end{rem}\n\n\\begin{prop}\\label{filteq-if-sim}\n$\\mathcal{A}\\sim\\mathcal{B}$ iff\n$\\mathscr{S}\\mathcal{A}=\\mathscr{S}\\mathcal{B}$ for every\nfilters~$\\mathcal{A}$,~$\\mathcal{B}$ on sets.\\footnote{Use this proposition to shorten proofs of other\ntheorem about equivalence of filters? (Our proof\nuses transitivity of equivalence of filters. So we can't\nuse it to prove that it is an equivalence relation, to avoid circular proof.)}\n\\end{prop}\n\n\\begin{proof}\nLet $\\mathcal{A}\\sim\\mathcal{B}$. Then there is a set~$P$\nsuch that~$P\\in\\mathcal{A}$,~$P\\in\\mathcal{B}$ and\n$\\mathcal{A}\\cap\\subsets P=\\mathcal{B}\\cap\\subsets P$.\nSo $\\mathscr{S}\\mathcal{A} = (\\mathcal{A}\\cap\\subsets P)\\cup\n\\setcond{K\\in\\mathfrak{Z}}{K\\sqsupseteq P}$.\nSimilarly\n$\\mathscr{S}\\mathcal{B} = (\\mathcal{B}\\cap\\subsets P)\\cup\n\\setcond{K\\in\\mathfrak{Z}}{K\\sqsupseteq P}$.\nCombining, we have $\\mathscr{S}\\mathcal{A}=\\mathscr{S}\\mathcal{B}$.\n\nLet now $\\mathscr{S}\\mathcal{A}=\\mathscr{S}\\mathcal{B}$.\nTake $K\\in\\mathscr{S}\\mathcal{A}=\\mathscr{S}\\mathcal{B}$.\nThen $\\mathcal{A}\\div K=\\mathcal{B}\\div K$ and thus\n(proposition~\\ref{filteq-ext})\n$\\mathcal{A}\\sim\\mathcal{A}\\div K =\n\\mathcal{B}\\div K\\sim\\mathcal{B}$, so having\n$\\mathcal{A}\\sim\\mathcal{B}$.\n\\end{proof}\n\n\\begin{prop}\\label{sim-rebase}\n$\\mathcal{A}\\sim\\mathcal{B} \\Rightarrow\n\\mathcal{A}\\div B=\\mathcal{B}\\div B$ for every\nfilters~$\\mathcal{A}$ and~$\\mathcal{B}$ and set~$B$.\n\\end{prop}\n\n\\begin{proof}\n$\\mathcal{A}\\div B =\n\\rsupfun{B\\sqcap}\\mathscr{S}\\mathcal{A} =\n\\rsupfun{B\\sqcap}\\mathscr{S}\\mathcal{B} =\n\\mathcal{B}\\div B$.\n\\end{proof}\n\n\\subsection{Poset of unfixed filters}\n\n\\begin{lem}\nLet filters~$\\mathcal{X}$\nand~$\\mathcal{Y}$ be such that\n$\\Base(\\mathcal{X})=\\Base(\\mathcal{Y})=B$. Then\n$\\mathcal{X}\\div C\\sqsubseteq\\mathcal{Y}\\div C\n\\Leftrightarrow \\mathcal{X}\\sqsubseteq\\mathcal{Y}$ for every\nset~$C\\supseteq B$.\n\\end{lem}\n\n\\begin{proof}\n\\begin{multline*}\n\\mathcal{X}\\div C\\sqsubseteq\\mathcal{Y}\\div C\\Leftrightarrow\n\\mathcal{X}\\div C\\supseteq\\mathcal{Y}\\div C\\Leftrightarrow\\\\\n\\mathcal{X}\\cup\\setcond{K\\in\\subsets C}{K\\sqsupseteq B} \\supseteq \\mathcal{Y}\\cup\\setcond{K\\in\\subsets C}{K\\sqsupseteq B} \\Leftrightarrow\n\\mathcal{X}\\supseteq\\mathcal{Y} \\Leftrightarrow\n\\mathcal{X}\\sqsubseteq\\mathcal{Y}.\n\\end{multline*}\n\\end{proof}\n\n\\begin{prop}\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y} \\Rightarrow\n\\mathcal{X}\\div B\\sqsubseteq\\mathcal{Y}\\div B$ for every\nfilters~$\\mathcal{X}$,~$\\mathcal{Y}$ with the same base\nand set~$B$.\n\\end{prop}\n\n\\begin{proof}\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y} \\Leftrightarrow\n\\mathcal{X}\\supseteq\\mathcal{Y} \\Rightarrow\n\\mathcal{X}\\div B\\supseteq\\mathcal{Y}\\div B \\Leftrightarrow\n\\mathcal{X}\\div B\\sqsubseteq\\mathcal{Y}\\div B$.\n\\end{proof}\n\nDefine order of unfixed filters using already defined order\nof filters of a fixed base:\n\n\\begin{defn}\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y} \\Leftrightarrow\n\\exists x\\in\\mathcal{X},y\\in\\mathcal{Y}:\n(\\Base(x)=\\Base(y)\\land x\\sqsubseteq y)$ for unfixed\nfilters~$\\mathcal{X}$,~$\\mathcal{Y}$.\n\\end{defn}\n\nProposition~\\ref{filteq-if-sim} allows to define:\n\n\\begin{defn}\n$\\mathscr{S}\\mathcal{A} = \\mathscr{S}a$ for\nevery~$a\\in\\mathcal{A}$ for every unfixed\nfilter~$\\mathcal{A}$.\n\\end{defn}\n\n\\begin{thm}\\label{mathscrs-iso}\n$\\mathscr{S}$~is an order-isomorphism from the poset of\nunfixed filters to the poset of filters on~$\\mathfrak{Z}$.\n\\end{thm}\n\n\\begin{proof}\nWe already know that~$\\mathscr{S}$ is an order embedding.\nIt remains to prove that it is a surjection.\n\nLet~$\\mathcal{Y}$ be a filter on~$\\mathfrak{Z}$.\nTake $\\mathfrak{Z}\\ni X\\in\\mathcal{Y}$. Then\n$\\rsupfun{X\\sqcap}\\mathcal{Y}$ is a filter on~$X$ and\n$\\mathscr{S}[\\rsupfun{X\\sqcap}\\mathcal{Y}]=\\mathscr{S}\\rsupfun{X\\sqcap}\\mathcal{Y}=\\mathcal{Y}$. We have proved that\nit is a surjection.\n\\end{proof}\n\n\\begin{lem}\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y} \\Leftrightarrow\n\\mathscr{S}\\mathcal{X}\\sqsubseteq\\mathscr{S}\\mathcal{Y}$\nfor every unfixed filters~$\\mathcal{X}$,~$\\mathcal{Y}$.\n\\end{lem}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Rightarrow$] Suppose\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y}$. Then there\nexist~$x\\in\\mathcal{X}$,~$y\\in\\mathcal{Y}$ such that\n$\\Base(x)=\\Base(y)$ and $x\\sqsubseteq y$. Then\n$\\mathscr{S}\\mathcal{X} =\n\\mathscr{S}x \\sqsubseteq \\mathscr{S}y =\n\\mathscr{S}\\mathcal{Y}$.\n\n\\item[$\\Leftarrow$] Suppose\n$\\mathscr{S}\\mathcal{X}\\sqsubseteq\\mathscr{S}\\mathcal{Y}$.\nThen there are $x\\in\\mathcal{X}$,~$y\\in\\mathcal{Y}$\nsuch that $\\mathscr{S}x\\sqsubseteq\\mathscr{S}y$.\nConsequently\n$\\mathscr{S}x' \\sqsubseteq\\mathscr{S}y'$ for\n$x'=x\\div(\\Base(x)\\sqcup\\Base(y))$,\n$y'=y\\div(\\Base(x)\\sqcup\\Base(y))$.\nSo we have~$x'\\in\\mathcal{X}$,~$y'\\in\\mathcal{Y}$,\n$\\Base(x')=\\Base(y')$ and $x'\\sqsubseteq y'$,\nthus $\\mathcal{X}\\sqsubseteq\\mathcal{Y}$.\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\n$\\sqsubseteq$~on the set of unfixed filters is a poset.\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[Reflexivity] From the previous theorem.\n\n\\item[Transitivity] From the previous theorem.\n\n\\item[Antisymmetry] Suppose\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y}$ and\n$\\mathcal{Y}\\sqsubseteq\\mathcal{X}$. Then\n$\\mathscr{S}\\mathcal{X}\\sqsubseteq\\mathscr{S}\\mathcal{Y}$ and\n$\\mathscr{S}\\mathcal{Y}\\sqsubseteq\\mathscr{S}\\mathcal{X}$.\nThus $\\mathscr{S}\\mathcal{X}=\\mathscr{S}\\mathcal{Y}$ and\nso $\\mathscr{S}x=\\mathscr{S}y$ for\nsome~$x\\in\\mathcal{X}$,~$y\\in\\mathcal{Y}$. Consequently\n$\\mathscr{S}(x\\div B)=\\mathscr{S}(y\\div B)$ for\n$B=\\Base(x)\\sqcup\\Base(y)$. Thus $x\\div B=y\\div B$\nand so $x\\sim y$, thus $\\mathcal{X}=\\mathcal{Y}$.\n\\end{description}\n\\end{proof}\n\n\\begin{thm}\n$[x]\\sqsubseteq[y] \\Leftrightarrow x\\sqsubseteq y$ for\nfilters~$x$ and~$y$ with the same base set.\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Leftarrow$] Obvious.\n\n\\item[$\\Rightarrow$] Let $\\Base(x)=\\Base(y)=B$.\nSuppose $[x]\\sqsubseteq[y]$. Then\nthere exist $x'\\sim x$ and $y'\\sim y$ such that\n$C=\\Base(x')=\\Base(y')$ (for some set~$C$) and\n$x'\\sqsubseteq y'$.\n\nWe have by the lemma\n$x'\\div(B\\sqcup C)\\sqsubseteq y'\\div(B\\sqcup C)$.\n\nBut $x'\\div(B\\sqcup C)=x\\div(B\\sqcup C)$ and\n$y'\\div(B\\sqcup C)=y\\div(B\\sqcup C)$. So\n$x\\div(B\\sqcup C)\\sqsubseteq y\\div(B\\sqcup C)$ and thus again\napplying the lemma $x\\sqsubseteq y$.\n\\end{description}\n\\end{proof}\n\n\\subsection{Rebase of unfixed filters}\n\nProposition~\\ref{sim-rebase} allows to define:\n\n\\begin{defn}\n$\\mathcal{A}\\div B = a\\div B$ for an unfixed\nfilter~$\\mathcal{A}$ and arbitrary $a\\in\\mathcal{A}$.\n\\end{defn}\n\n\\begin{prop}\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y} \\Rightarrow\n\\mathcal{X}\\div C\\sqsubseteq\\mathcal{Y}\\div C$ for every\nunfixed filters~$\\mathcal{X}$,~$\\mathcal{Y}$ and set~$C$.\n\\end{prop}\n\n\\begin{proof}\nLet $\\mathcal{X}\\sqsubseteq\\mathcal{Y}$. Then there\nare~$x\\in\\mathcal{X}$,~$y\\in\\mathcal{Y}$ such that\n$\\Base(x)=\\Base(y)$ and $x\\sqsubseteq y$.\nThen by proved above $x\\div C\\sqsubseteq y\\div C$ what is\nequivalent to\n$\\mathcal{X}\\div C\\sqsubseteq\\mathcal{Y}\\div C$.\n\\end{proof}\n\n\\begin{prop}\nIf~$C\\in\\mathscr{S}\\mathcal{X}$\nand~$C\\in\\mathscr{S}\\mathcal{Y}$ for unfixed\nfilters~$\\mathcal{X}$ and~$\\mathcal{Y}$ then\n$\\mathcal{X}\\div C\\sqsubseteq\\mathcal{Y}\\div C \\Leftrightarrow\n\\mathcal{X}\\sqsubseteq\\mathcal{Y}$.\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Leftarrow$] Previous proposition.\n\n\\item[$\\Rightarrow$] Let\n$\\mathcal{X}\\div C\\sqsubseteq\\mathcal{Y}\\div C$.\nWe have some~$x\\in\\mathcal{X}$,~$y\\in\\mathcal{Y}$,\nsuch that $\\Base(x)=\\Base(y)$ and\n$x\\div C\\sqsubseteq y\\div C$.\nSo $\\mathscr{S}(x\\div C)\\sqsubseteq\\mathscr{S}(y\\div C)$.\nBut $\\mathscr{S}(x\\div C)\\sim x$ and\n$\\mathscr{S}(y\\div C)\\sim y$. Thus\n$\\mathscr{S}x\\sqsubseteq\\mathscr{S}y$ that is\n$x\\sqsubseteq y$ and so\n$\\mathcal{X}\\sqsubseteq\\mathcal{Y}$.\n\\end{description}\n\\end{proof}\n\n\\begin{obvious}\n$(\\mathcal{X}\\div A)\\div B = \\mathcal{X}\\div B$ if\n$B\\sqsubseteq A$ for every unfixed filter~$\\mathcal{X}$ and\nsets~$A$,~$B$.\n\\end{obvious}\n\n\\begin{obvious}\n$\\mathcal{A}\\div B = \\rsupfun{B\\sqcap}\\mathscr{S}\\mathcal{A}$\nfor every unfixed filter~$\\mathcal{A}$.\n\\end{obvious}\n\n\\begin{obvious}\nIf $A\\in\\mathscr{S}\\mathcal{A}$ then\n$\\mathcal{A}\\div A\\in\\mathcal{A}$ for every unfixed\nfilter~$\\mathcal{A}$.\n\\end{obvious}\n\n\\begin{prop}\nIf~$C\\in\\mathscr{S}\\mathcal{X}$\nand~$C\\in\\mathscr{S}\\mathcal{Y}$ for unfixed\nfilters~$\\mathcal{X}$ and~$\\mathcal{Y}$ then\n$\\mathcal{X}\\div C=\\mathcal{Y}\\div C \\Leftrightarrow\n\\mathcal{X}=\\mathcal{Y}$.\n\\end{prop}\n\n\\begin{proof}\nThe backward implication is obvious. Let now\n$\\mathcal{X}\\div C=\\mathcal{Y}\\div C$.\nTake~$x\\in\\mathcal{X}$,~$y\\in\\mathcal{Y}$.\nWe have\n$\\mathcal{X}\\div C=x\\div C=(x\\div B)\\div C$\nfor $B=C\\sqcup\\Base(x)\\sqcup\\Base(y)$.\nSimilary $\\mathcal{Y}\\div C=(y\\div B)\\div C$.\nThus $(x\\div B)\\div C=(y\\div B)\\div C$ and thus\n$x\\div B=y\\div B$, so $x\\sim y$ that is\n$\\mathcal{X}=\\mathcal{Y}$.\n\\end{proof}\n\n\\begin{prop}\n$\\mathcal{A}\\div A =\n\\bigsqcap\\setcond{\\uparrow^A(X\\sqcap A)}{X\\in\\mathscr{S}\\mathcal{A}}$ for every unfixed filter~$\\mathcal{A}$.\n\\end{prop}\n\n\\begin{proof}\nTake~$a\\in\\mathcal{A}$.\n\\begin{multline*}\n\\bigsqcap\\setcond{\\uparrow^A(X\\sqcap A)}{X\\in\\mathscr{S}\\mathcal{A}} =\n\\bigsqcap\\setcond{\\uparrow^A(X\\sqcap A\\sqcap\\Base(a))}{X\\in\\mathscr{S}\\mathcal{A}} = \\\\\n\\bigsqcap\\setcond{\\uparrow^A(X\\sqcap A)}{X\\in\\mathscr{S}\\mathcal{A}\\cap\\subsets\\Base(a)} =\n\\bigsqcap\\setcond{\\uparrow^A(X\\sqcap A)}{X\\in\\mathscr{S}a\\cap\\subsets\\Base(a)} = \\\\\n\\bigsqcap\\setcond{\\uparrow^A(X\\sqcap A)}{X\\in a}=\na\\div A = \\mathcal{A}\\div A.\n\\end{multline*}\n\\end{proof}\n\n\\subsection{The diagram for unfixed filters}\n\nFix a set~$B$.\n\n\\begin{lem}\n$\\mathcal{X}\\mapsto\\mathcal{X}\\div B$ and $x\\mapsto[x]$ are\nmutually inverse order isomorphisms between\n$\\setcond{\\text{unfixed filter }\\mathcal{X}}{B\\in\\mathscr{S}\\mathcal{X}}$ and $\\mathfrak{F}(DB)$.\n\\end{lem}\n\n\\begin{proof}\nFirst, $\\mathcal{X}\\div B\\in\\mathfrak{F}(DB)$ for\n$\\mathcal{X}\\in\\setcond{\\text{unfixed filter }\\mathcal{X}}{B\\in\\mathscr{S}\\mathcal{X}}$ and\n$[x]\\in\\setcond{\\text{unfixed filter }\\mathcal{X}}{B\\in\\mathscr{S}\\mathcal{X}}$\nfor $x\\in\\mathfrak{F}(DB)$.\n\nSuppose $\\mathcal{X}_0\\in\\setcond{\\text{unfixed filter }\\mathcal{X}}{B\\in\\mathscr{S}\\mathcal{X}}$,\n$x=\\mathcal{X}_0\\div B$, and $\\mathcal{X}_1=[x]$. We will prove\n$\\mathcal{X}_0=\\mathcal{X}_1$. Really, $x\\in\\mathcal{X}_1$,\n$x=k\\div B$ for $k\\in\\mathcal{X}_0$, $x\\sim k$, thus\n$x\\in\\mathcal{X}_0$. So $\\mathcal{X}_0=\\mathcal{X}_1$.\n\nSuppose $x_0\\in\\mathfrak{F}(DB)$, $\\mathcal{X}=[x_0]$,\n$x_1=\\mathcal{X}\\div B$. We will prove $x_0=x_1$. Really,\n$x_1=x_0\\div B$. So $x_1=x_0$ because\n$\\Base(x_0)=\\Base(x_1)=B$.\n\nSo we proved that they are mutually inverse bijections. That\nthey are order preserving is obvious.\n\\end{proof}\n\n\\begin{lem}\n$\\mathscr{S}$ and\n$\\mathcal{X}\\mapsto\\rsupfun{B\\sqcap}\\mathcal{X}=\n\\mathcal{X}\\cap\\subsets B$\nare mutually inverse order isomorphisms\nbetween~$\\mathfrak{F}(DB)$ and\n$\\setcond{\\mathcal{X}\\in\\mathfrak{F}(\\mathfrak{Z})}{B\\in\\mathcal{X}}$.\n\\end{lem}\n\n\\begin{proof}\nFirst, $\\mathscr{S}x\\in\\setcond{\\mathcal{X}\\in\\mathfrak{F}(\\mathfrak{Z})}{B\\in\\mathcal{X}}$ for $x\\in\\mathfrak{F}(DB)$\nbecause of theorem~\\ref{mathscrs-iso} and\n$\\rsupfun{B\\sqcap}\\mathcal{X}\\in\\mathfrak{F}(DB)$ obviously.\n\nLet's prove\n$\\rsupfun{B\\sqcap}\\mathcal{X}=\\mathcal{X}\\cap\\subsets B$.\nIf $X\\in\\rsupfun{B\\sqcap}\\mathcal{X}$ then\n$X\\in\\mathcal{X}$ (because $B\\in\\mathcal{X}$) and\n$X\\in\\subsets B$. So $X\\in\\mathcal{X}\\cap\\subsets B$. If\n$X\\in\\mathcal{X}\\cap\\subsets B$ then\n$X=B\\cap X\\in\\rsupfun{B\\sqcap}\\mathcal{X}$.\n\nLet~$x_0\\in\\mathfrak{F}(DB)$, $\\mathcal{X}=\\mathscr{S}x$, and\n$x_1=\\rsupfun{B\\sqcap}\\mathcal{X}$. Then obviously $x_0=x_1$.\n\nLet now\n$\\mathcal{X}_0\\in\\setcond{\\mathcal{X}\\in\\mathfrak{F}(\\mathfrak{Z})}{B\\in\\mathcal{X}}$, $x=\\rsupfun{B\\sqcap}\\mathcal{X}_0$, and\n$\\mathcal{X}_1=\\mathscr{S}x$. Then\n$\\mathcal{X}_1=\n\\mathcal{X}_0\\cup\\setcond{K\\in\\mathfrak{Z}}{K\\sqsupseteq B}=\n\\mathcal{X}_0$.\n\nSo we proved that they are mutually inverse bijections. That\nthey are order preserving is obvious.\n\\end{proof}\n\n\\begin{thm}\\label{powfilt-diag}\nThe diagram at the figure~\\ref{unfix-dia} (with the horizontal ``unnamed''\narrow \\emph{defined} as the inverse isomorphism of its opposite arrow)\nis a commutative diagram (in category $\\mathbf{Set}$), every arrow\nin this diagram is an isomorphism. Every cycle in this diagram is\nan identity (therefore ``parallel'' arrows are mutually inverse).\nThe arrows preserve order.\n\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=2cm, column sep=0.5cm]\n& \\mathfrak{F}(DB)\n\\arrow[rd, shift left, \"x\\mapsto{[x]}\"]\n\\arrow[ld, shift left, \"\\mathscr{S}\"] \\\\\n\\setcond{\\mathcal{X}\\in\\mathfrak{F}(\\mathfrak{Z})}\n  {B\\in\\mathcal{X}}\n\\arrow[ru, shift left, \"\\mathcal{X}\\mapsto\\rsupfun{B\\sqcap}\\mathcal{X}=\\mathcal{X}\\cap\\subsets B\"]\n\\arrow[rr, shift left]\n& & \\setcond{\\text{unfixed filter }\\mathcal{X}}\n  {B\\in\\mathscr{S}\\mathcal{X}}\n\\arrow[lu, shift left, \"\\mathcal{X}\\mapsto\\mathcal{X}\\div B\"]\n\\arrow[ll, shift left, \"\\mathscr{S}\"]\n\\end{tikzcd}\n\\caption{\\label{unfix-dia}}\n\\end{figure}\n\\end{thm}\n\n\\begin{proof}\nIt's proved above, that all morphisms (except the ``unnamed'' arrow,\nwhich is the inverse morphism by definition) depicted on the diagram\nare bijections and the depicted ``opposite'' morphisms are mutually\ninverse.\n\nThat arrows preserve order is obvious.\n\nIt remains to apply lemma~\\ref{three-loop-lem} (taking into account the proof of theorem~\\ref{mathscrs-iso}).\n\\end{proof}\n\n\\subsection{The lattice of unfixed filters}\n\n\\begin{thm}\nEvery nonempty set of unfixed filters has an infimum,\nprovided that the lattice~$\\mathfrak{Z}$ is distributive.\n\\end{thm}\n\n\\begin{proof}\nTheorem~\\ref{distr-meet}.\n\\end{proof}\n\n\\begin{thm}\nEvery bounded above set of unfixed filters has a supremum.\n\\end{thm}\n\n\\begin{proof}\nTheorem~\\ref{join-filt-gen} for nonempty sets of unfixed\nfilters. The join $\\bigsqcup\\emptyset=[\\bot]$ for the\nleast filter~$\\bot\\in\\mathfrak{Z}(DA)$ for\narbitrary~$A\\in\\mathfrak{Z}$.\n\\end{proof}\n\n\\begin{cor}\nIf~$\\mathfrak{Z}$ is the set of small sets, then\nevery small set of unfixed filters has a supremum.\n\\end{cor}\n\n\\begin{proof}\nLet~$S$ be a set of filters on~$\\mathfrak{Z}$. Then $T_{\\mathcal{X}}\\in\\mathcal{X}$ is a small set\nfor every~$\\mathcal{X}\\in S$.\nThus\n$\\setcond{T_{\\mathcal{X}}}{\\mathcal{X}\\in S}$ is small\nset and thus\n$T=\\bigcup\\setcond{T_{\\mathcal{X}}}{\\mathcal{X}\\in S}$ is small set. Take the filter $\\mathcal{T}=\\uparrow T$.\nThen~$\\mathcal{T}$ is an upper bound of~$S$ and we can apply the theorem.\n\\end{proof}\n\n\\begin{obvious}\nThe poset of unfixed filters for the lattice of small sets\nis bounded below (but not above).\n\\end{obvious}\n\n\\begin{prop}\nThe set of unfixed filters forms a co-brouwerian (and thus\ndistributive) lattice, provided that~$\\mathfrak{Z}$ is\ndistributive lattice which is an ideal base.\n\\end{prop}\n\n\\begin{proof}\nCorollary~\\ref{filt-also-distr}.\n\\end{proof}\n\n\\subsection{Principal unfixed filters and filtrator of unfixed filters}\n\n\\begin{defn}\n\\emph{Principal} unfixed filter is an unfixed filter\ncorresponding to a principal filter on the\nposet~$\\mathfrak{Z}$.\n\\end{defn}\n\n\\begin{defn}\nThe \\emph{filtrator of unfixed filters} is the filtrator\nwhose base are unfixed filters and whose core are principal\nunfixed filters.\n\\end{defn}\n\nWe will equate principal unfixed filters with corresponding\nsets.\n\n\\begin{thm}\nIf we add principal filters on~$DB$, principal filters\non~$\\mathfrak{Z}$ containing~$B$, and above defined\nprincipal unfixed filters corresponding to them to\nappropriate nodes of the diagram~\\ref{unfix-dia}, then\nthe diagram turns into a commutative diagram of isomorphisms\nbetween filtrators. (I will not draw the modified diagram\nfor brevity.)\n\nEvery arrow of this diagram is an isomorphism between\nfiltrators, every cycle in the diagram is identity.\n\\end{thm}\n\n\\begin{proof}\nWe need to prove only that principal filters on~$B$ and\nprincipal filters on~$\\mathfrak{Z}$ containing~$B$\ncorrespond to each other by the isomorphisms of the diagram.\nBut that's obvious.\n\\end{proof}\n\n\\begin{obvious}\nThe filtrator of unfixed filters is a primary filtrator.\n\\end{obvious}\n\n\\begin{obvious}\nThe filtrator of unfixed filters is down-aligned.\n\\end{obvious}\n\n\\begin{prop}\nThe filtrator of unfixed filters is\n\\begin{enumerate}\n\\item filtered;\n\\item with join-closed core.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{semifilt-joinclosed}.\n\\end{proof}\n\n\\begin{prop}\nThe filtrator of unfixed filters is with binarily meet-closed core.\n\\end{prop}\n\n\\begin{proof}\nCorollary~\\ref{f-meet-closed}.\n\\end{proof}\n\n\\begin{prop}\nThe filtrator of unfixed filters is with separable core.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{when-sep-core}.\n\\end{proof}\n\n\\begin{prop}\n$\\Cor\\mathcal{X}$ and $\\Cor'\\mathcal{X}$ are defined for every\nunfixed filter~$\\mathcal{X}$ and\n$\\Cor\\mathcal{X}=\\Cor'\\mathcal{X}$, provided that every\n$DA$ is a complete lattice.\n\\end{prop}\n\n\\begin{proof}\n$\\Cor\\mathcal{X}$ and $\\Cor'\\mathcal{X}$ exists because\nof the above isomorphism.\n\n$\\Cor'\\mathcal{X}=\\Cor\\mathcal{X}$ by\ntheorem~\\ref{cor-eq}.\n\\end{proof}\n\n\\begin{obvious}\n$\\Cor\\mathcal{X}=\\Cor'\\mathcal{X}=\\bigcap\\mathcal{X}$ for\nevery filter~$\\mathcal{X}\\in\\mathfrak{F}(\\text{small sets})$.\n\\end{obvious}\n\n\\begin{prop}\n$\\atoms\\bigsqcap S=\\bigcap\\rsupfun{\\atoms}S$\nwhenever~$\\bigsqcap S$ is defined.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{atoms-infmeet}.\n\\end{proof}\n\n\\begin{prop}\n$\\atoms(\\mathcal{A}\\sqcup\\mathcal{B})=\\atoms\\mathcal{A}\\cup\\atoms\\mathcal{B}$ for unfixed\nfilters~$\\mathcal{A}$,~$\\mathcal{B}$, whenever~$\\mathfrak{Z}$\nis a distributive lattice which is an ideal base.\n\\end{prop}\n\n\\begin{proof}\nProposition~\\ref{f-atoms-join}.\n\\end{proof}\n\n\\begin{prop}\n$\\corestar\\mathcal{X}$ is a free star for every unfixed\nfilter~$\\mathcal{X}$, whenever~$\\mathfrak{Z}$\nis a distributive lattice which is an ideal base which\nhas a least element.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{da-is-free-star}.\n\\end{proof}\n\n\\begin{prop}\nThe poset of unfixed filters is an atomistic lattice if\nevery~$DA$ (for~$A\\in\\mathfrak{A}$) is an\natomistic lattice.\n\\end{prop}\n\n\\begin{proof}\nEasily follows from~\\ref{powfilt-diag} by isomorphism.\n\\end{proof}\n\n\\begin{prop}\nThe poset of unfixed filters is a strongly separable lattice\nif every~$DA$ (for~$A\\in\\mathfrak{A}$) is an\natomistic lattice.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{atom-is-sep}.\n\\end{proof}\n\n\\begin{prop}\n$\\Cor\\mathcal{X}=\\bigsqcup(\\mathfrak{Z}\\cap\\atoms^{\\text{unfixed filters}})$\nfor every unfixed filter~$\\mathcal{X}$ if every~$DA$\n(for~$A\\in\\mathfrak{A}$) is an atomistic lattice.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{cor-join-atom}.\n\\end{proof}\n\n\\begin{prop}\n$\\Cor(\\mathcal{A}\\sqcap\\mathcal{B})=\n\\Cor\\mathcal{A}\\sqcap\\Cor\\mathcal{B}$ for every unfixed\nfilters~$\\mathcal{A}$,~$\\mathcal{B}$, provided\nevery $DA$ (for~$A\\in\\mathfrak{A}$) is a complete lattice.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{dual-cor-meet}.\n\\end{proof}\n\n\\begin{prop}\n$\\Cor\\bigsqcap^{\\mathfrak{A}}S=\\bigsqcap^{\\mathfrak{Z}}\\rsupfun{\\Cor}S$ for the filtrator of unfixed filters for\nevery nonempty set~$S$ of unfixed filters, provided\nevery $DA$ (for~$A\\in\\mathfrak{A}$) is a complete lattice.\n\\end{prop}\n\n\\begin{proof}\nTheorem~\\ref{dual-cor-inf-meet}.\n\\end{proof}\n\n\\begin{prop}\n$\\Cor(\\mathcal{A}\\sqcup^{\\mathfrak{A}}\\mathcal{B}) =\n\\Cor\\mathcal{A}\\sqcup^{\\mathfrak{Z}}\\Cor\\mathcal{B}$ for the filtrator of unfixed filters for every unfixed filters~$\\mathcal{A}$, and~$\\mathcal{B}$, provided\nevery $DA$ (for~$A\\in\\mathfrak{A}$) is a complete atomistic\ndistributive lattice.\n\\end{prop}\n\n\\begin{proof}\nCan be easily deduced from theorem~\\ref{dual-core-join}\nand the triangular diagram (above) of isomorphic filtrators.\n\\end{proof}\n\n\\begin{conjecture}\nThe theorem~\\ref{closed-free-star} holds for unfixed\nfilters, too.\n\\end{conjecture}\n\nIt is expected to be easily provable using isomorphisms from\nthe triangular diagram.\n", "meta": {"hexsha": "d4ac35c919794338474e715a5ae0594d96d8d62b", "size": 246757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-filt.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-filt.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-filt.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": 41.5976062036, "max_line_length": 377, "alphanum_fraction": 0.7014188047, "num_tokens": 95601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6807490954702893}}
{"text": "% !TEX root = Main.tex\n\\section{Word Embeddings}\n\\textbf{Distributional Model:}\\\\\n$p_\\theta(w|w')$ = Pr[$w$ occurs in context of $w'$]\\\\\n\\textbf{Log-likelihood:}\\\\\n$L(\\theta; \\mathbf{w}) = \\sum_{t=1}^T\\sum_{\\Delta \\in I}{\\log p_\\theta(w^{(t+\\Delta)}|w^{(t)})}$\\\\\n\\textbf{Latent Vector Model:} $w \\rightarrow (\\mathbf{x}_w, b_w) \\in \\mathbb{R}^{D+1} \\\\p_{\\theta}(w|w') = \\frac{\\exp[\\langle \\mathbf{x}_w,\\mathbf{x}_{w'}\\rangle + b_w]}{\\sum_{v\\in V}{\\exp[\\langle \\mathbf{x}_v,\\mathbf{x}_{w'}\\rangle + b_v ]}}$ (soft-max).\\\\\n\\textbf{Modifications:}\\\\\n$\\log p_{\\theta}(w|w') = \\langle  y_{w} , x_{w'} \\rangle + b_w$,  word $y_w$, c'txt $x_{w'}$\\\\\nuse GloVe objective\\\\\nnegative sampling (logistic classification) over-samples by factor $k$ and defines $p_n$ by reusing active words from the data with random context, apply the exponent $\\alpha<1$ to reduce frequent words importance.\\\\\n$\n\\sum_{(i,j)\\in\\Delta_+}log(\\sigma(\\langle x_i, y_j\\rangle)) + \\sum_{(i,j)\\in\\Delta_-}log(\\sigma(-\\langle x_i, y_j\\rangle))\n$\n\\subsection*{GloVe (Weighted Square Loss)}\n\\textbf{Co-occurence Matrix:}\\\\\n$\\textbf{N} = (n_{ij}) \\in \\mathbb{R}^{|V|\\times|C|} = \\textbf{\\# of word} w_i$ in context $w_j$\\\\\n$\\textbf{N}$ easily computed (one data pass) and sparse\\\\\n\\textbf{Objective:} $H(\\theta;\\textbf{N})$\\\\\n$= \\sum_{n_{ij} > 0} f(n_{ij})(\\log n_{ij} - \\log \\exp[\\langle \\textbf{x}_i, \\textbf{y}_j \\rangle + b_i + d_j])^2$\\\\\nwith $f(n) = \\min\\{1, (\\frac{n}{n_{max}})^\\alpha\\}$, $\\alpha \\in (0;1]$, $f(n_{ij}$ small for small counts as noisy and limited for big counts,\n\\textbf{unnormalized} distr. $\\rightarrow$ 2-sided loss function\\\\\n1. sample $(i,j) u.a.r, s.t. n_{ij}>0$\\\\\n2. $\\mathbf{x}_i^{new} \\leftarrow \\mathbf{x}_i + 2\\eta f(n_{ij})(\\log n_{ij} - \\langle \\mathbf{x}_i, \\mathbf{y}_j \\rangle)\\mathbf{y}_j$\\\\\n3. $\\mathbf{y}_j^{new} \\leftarrow \\mathbf{y}_j + 2\\eta f(n_{ij})(\\log n_{ij} - \\langle \\mathbf{x}_i, \\mathbf{y}_j \\rangle)\\mathbf{x}_i$\n\n\\subsection*{Discussion}\nWord embeddings can model analogies and relatedness, but antonyms are usually not.\n", "meta": {"hexsha": "fcd720710bbb4d1e9eba6d62c32a4c9d56d1ce1f", "size": 2037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WordEmbedding.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": "WordEmbedding.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": "WordEmbedding.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": 70.2413793103, "max_line_length": 257, "alphanum_fraction": 0.6445753559, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6806711731652224}}
{"text": "\\documentclass[en,12pt]{elegantpaper}\n\n\\begin{document}\n    \\section*{3}\n    \\noindent For Beta($\\alpha. \\alpha$), \n    \\[\n        f(x|\\alpha)=\\mathbf{1}_{0<x<1}\\exp\\left((\\alpha-1)\\log(x(1-x))-\\log\\left(\\frac{\\Gamma^2(\\alpha)}{\\Gamma(2\\alpha)}\\right)\\right). \n    \\]\n    Let $\\eta=\\alpha-1$, then $A(\\eta)=\\log\\frac{\\Gamma^2(\\eta+1)}{\\Gamma(2\\eta+2)}$. And we know that $T(X)=\\log(X(1-X))$ is a sufficient statistics. So, \n    \\[\n        \\begin{aligned}\n            \\mathbb{E}(T(X))=A'(\\eta){}&=\\log(\\Gamma^2(\\eta+1))-\\log(\\Gamma(2\\eta+2))\\\\&=\\frac{2\\Gamma(\\eta+1)\\Gamma'(\\eta+1)}{\\Gamma^2(\\eta+1)}-\\frac{2\\Gamma'(2\\eta+2)}{\\Gamma(2\\eta+2)}\\\\\n            &=\\frac{2\\Gamma(\\alpha)\\Gamma'(\\alpha)}{\\Gamma^2(\\alpha)}-\\frac{2\\Gamma'(2\\alpha)}{\\Gamma(2\\alpha)}\n        \\end{aligned}\n    \\]\n    where $\\Gamma'(n)=(n-1)!\\left(\\sum_{i=1}^{n-1}\\frac{1}{i}-\\gamma\\right)$, $\\gamma$ is Euler's constant. \n\\end{document}", "meta": {"hexsha": "6f2da278dc8f4224a489340f041e053a75f42ee3", "size": 908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/midterm1/3.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/3.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/3.tex", "max_forks_repo_name": "Addasecond86/MS-Stat-Tulane", "max_forks_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.4117647059, "max_line_length": 188, "alphanum_fraction": 0.5561674009, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6806340495819354}}
{"text": "\n% JuliaCon proceedings template\n\\documentclass{juliacon}\n\\setcounter{page}{1}\n\n\n%-------- user macros -----------------------------------------------------------\n\\usepackage{mathtools} %add-on and patches to amsmath  \n\\def\\E{\\mathbb{E}} \n%================================================================================\n\n\\begin{document}\n\n\\input{header}\n\n\\maketitle\n\n\\begin{abstract}\nSolid Modeling algorithms and applications usually demand very linked and pretty complex data structures, often denoted as ``non-manifold representations'' to remark the breadth of their domain. Conversely, we are implementing in Julia~\\cite{bezanson2017julia} topological methods making only use of sparse binary or integer arrays, and their standard algebraic operations, like product, transposition and filtering, and standard topological operators of boundary and coboundary between linear spaces of chains generated by the cells of a space partition. \nWe show computational methods to generate the 2D/3D space partition induced by a collection of 1D/2D/3D geometric objects. Methods and language are those of basic geometric and algebraic topology. Only sparse arrays are used to compute spaces and maps (the chain complex) from dimension zero to three.\nIn particular, we show how to build a space arrangement with general non-convex and non-contractible piecewise-linear cells, and how to compute Boolean operations between solid models generated by this approach, reducing them to standard tables of Boolean values.\n\\end{abstract}\n\n%================================================================================\n\\section{Introduction}\n%================================================================================\n\nIn this paper we discuss the current status of a novel approach to geometric computing, and its  implementation in Julia. Rather than using standard methods of geometric computing and solid modeling, normally built on top of complicated data structures, our work is mostly developed making advantage of    sparse arrays and their algebraic operations. In particular, this approach is established over basic concepts of algebraic topology, like cellular complexes, chain and cochain spaces and operators, and chain complexes.  Piecewise-linear algebraic topology allows to treat rather general complexes, with cells homeomorphic to polyhedra, \\emph{i.e.},~to triangulable spaces, and hence possibly non convex and multiply connected. We use simplicial complexes, \\emph{i.e.}, triangulations, just for graphics, where to stream triangles to the GPU is almost mandatory. \n\nAt the knowledge of the author, there are no previous approaches to geometric and solid modeling that build over a similar framework, \\emph{e.g}, to compute the \\emph{chain complex} codifying the arrangement of $d$-space generated by a collection of ($d$-1)-geometric objects. A wide comparison with previous work in this field may be found in~\\cite{TSAS:17,Dicarlo:2014:TNL:2543138.2543294}. \nAfter a short synthesis of basic algebraic topological \nconcepts, this paper discusses the arrangement of space induced by solid objects, as the basis for resolution of solid-valued expressions. A survey of functions from our packages \\texttt{LinearAlgebraicRepresentation}, \\texttt{Triangle}, and \\texttt{ViewerGL} follows. Simple examples generating pictures conclude the paper.\n\n%================================================================================\n\\section{Linear Algebraic Representation}\n%================================================================================\n\nWe summarize  in the following the concepts and definitions on which our \\texttt{Lar} (Linear Algebraic Representation)~\\cite{Dicarlo:2014:TNL:2543138.2543294} is based on. \n\n\\subsection{Cell, Complex, Chain}\n%--------------------------------------------------------------------------------\nA $p$-cell $\\sigma$ ($0\\leq p\\leq d$) is a piecewise-linear, connected, but possibly non-contractible $p$-manifold. An $r$-face $\\tau$ of a $p$-cell $\\sigma$ ($0\\leq r\\leq p$) is a $r$-cell contained in the frontier of $\\sigma$.\nA $d$-complex $\\Lambda$ is a partition of a topological $d$-space $X$ in a discrete set of $p$-cells ($0\\leq p\\leq d$) such that: (a) $\\sigma\\in \\Lambda$ implies $\\tau\\in \\Lambda$ for all faces $\\tau$ of $\\sigma$; (b) the closure intersection of every pair of cells of $\\Lambda$ is either in $\\Lambda$ or the empty set. A $p$-chain can be defined as a subset of $p$-cells. To the $p$-chains can be given the structure of a (graded) linear space $C_p$ by defining (a) sums of chains with the same dimension, and (b) products times scalars in a field, with the usual properties. A basis $U_p$ for $C_p$ is the set of elementary chains $u_p$, given by single cells in $\\Lambda_p$. Every chain $c\\in C_p$ may be uniquely generated by a linear combination of the basis $U_p$. Once fixed the basis $U_p$, the coordinate representation of each $\\sigma\\in C_p$ is unique. This one is an ordered sequence of coefficients, either from $\\{0,1\\}$ (said unsigned rep.) or from $\\{-1,0,+1\\}$ (called signed representation).\n\n\\subsection{Boundary and coboundary operators}\n%--------------------------------------------------------------------------------\nBondary operators are linear maps $\\partial_p : C_p \\to C_{p-1}$, ($1\\leq p\\leq d$). Coboundary operators are linear maps $\\delta_p : C_p \\to C_{p+1}$, ($0\\leq p\\leq d-1$). Once fixed the bases $U_{p-1}, U_{p}, U_{p+1}$, \\emph{i.e.}, once fixed an ordering among the cells in each $\\Lambda_p$, their matrix representations $[\\partial_{p}]$ and $[\\delta_{p}]$ are uniquely determined. \nIt is worthwhile to remark the meaning of such matrices: once fixed the bases, the matrix $[M]$ of a linear operator $M: A\\to B$ contains by columns the coordinate representation (\\emph{i.e.}, the coefficients of the linear combination) of the $A$ basis expressed as linear combination of $B$ basis elements. This property is the conceptual key of our methods.\n\nA \\emph{$p$-cycle} is a chain \\emph{without} boundary. It is a chain that the boundary operator $\\partial_p$ sends to the kernel (zero-set) of $C_p$. In particular, the $j$-th column of $[\\partial_p]$ contains a basis element $u_j\\in U_p$ represented as a ($p-1$)-cycle, \\emph{i.e.}, contains the coefficients of it as linear combination of elements of $U_{p-1}$. Such linear combinations are $(p-1)$-cycles, since $\\partial_{p-1}\\circ\\partial_p = 0$.  In other words, the matrix $[\\partial_2]$ represents the 2-cells in $\\Lambda_2$ as 1-cycles (closed polygons) in $C_1$.  Analogously, $[\\partial_3]$ contains by columns the 3-cells of $\\Lambda_3$ as cycles (shells) made by 2-cells in $\\Lambda_2$ (\\emph{e.g.}, see Figure~\\ref{fig:threecubes}d).\n\nWe  have already seen the topological equations $\\partial_{p-1}\\circ\\partial_p = 0$ ($d\\leq p\\leq 2$) that guarantee the boundary of a boudary being empty. Think about the 2-disk $d \\in C_2$ in the plane, with support $|d|\\subset\\E^2$. The circumference $c\\in C_1$, with $|c| = |\\partial_2\\, d| \\subset E^2$ is  a closed curve. In fact we have $\\partial (\\partial\\, c) = 0$. In our case, where cells live in Euclidean spaces, chain spaces $C_p$ can be identified with their dual spaces of $p$-cochains $C^p$, that are spaces of maps $\\mu^p: C_p\\to \\mathbb{F}$ from $p$-chains to the field $\\mathbb{F}$ of coefficients. In this case we have $C^p = C_p^\\top$, and hence $[C^p] = [C_p]^t$. The matrix-vector multiplication $[\\partial_p][c]$ provides the (coordinate representation of) the ($p$-1)-cycle on the frontier of $c$, whereas $[\\delta^p][c]$ gives the (coordinate repre. of) the ($p$+1)-chain made by all ($p$+1)-cells incident on $c$.\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.4\\linewidth]{figs/image1.png}%\n   \\includegraphics[width=0.6\\linewidth]{figs/image2.png}%\n   \\caption{The 3-cells of the arrangement of $\\E^3$ generated by a collection of five random cubes.\n   The 3-cells are here not in scale, and suitably rotated to better show their complex structure.\n   Their assembly provides the union of the five cubes.\n   Each \\emph{3-cell is given} by \\emph{a column} of the \\emph{sparse matrix} of \\emph{chain map} $\\partial_3: C_3\\to C_2$,  with values in $\\{-1,0,1\\}$.}\n   \\label{fig:example}\n\\end{figure}\n\n\n\n\\subsection{Incidence/adjacency operators}\n%--------------------------------------------------------------------------------\nSpecialized data structures are commonly used to efficiently answer the queries about the incidence and adjacecy relations between boundary elements (vertices, edges and faces), in order to implement the various geometric and topological algorithms of solid modeling. Given the three sets \\texttt{V}, \\texttt{E}, and \\texttt{F} (vertices, edges and faces), ${3\\times 3}$ binary relations \\texttt{VV}, \\texttt{VE}, \\texttt{VF}, \\texttt{EV}, \\texttt{EE}, \\texttt{EF}, \\texttt{FV}, \\texttt{FE}, \\texttt{FF} are used. Several different combinations of such relations have been defined as specialized data structures, with the aim of minimizing the time and space complexity of algorithms on solid models.\n\nIt is easy to see that each relation can be computed by a proper combination of one or two (co)boundary matrices, possibly transposed. Their ordered list follow: $\\texttt{VV}\\equiv[\\partial_1][\\delta_0]$, $\\texttt{VE}\\equiv[\\partial_1]$, $\\texttt{VF}\\equiv[M_2]^t$, $\\texttt{EV}\\equiv[\\partial_1]^t$, $\\texttt{EE}\\equiv[\\delta_0][\\partial_1]$, $\\texttt{EF}\\equiv[\\partial_2]$, $\\texttt{FV}\\equiv[M_2]$, $\\texttt{FE}\\equiv[\\delta_1]$, $\\texttt{FF}\\equiv[\\delta_1][\\partial_2]$, where $M_p$ is the sparse binary \\emph{characteristic matrix} of $p$-cells, that holds by rows the images of characteristic functions of $p$-cells as subsets of $0$-cells (vertices).\n\nA typical topological query may be asked as: ``what edges (elementary 1-chains) are adjacent to edge $e$?''\nThe \\texttt{Lar} answer is computed as the product $[\\delta_0][\\partial_1][e]$, where $[e]$ is the coordinate representation of $e\\in C_1$ (a sparse column vector with just one non-zero element) and, of course, the matrix $[\\delta_0][\\partial_1] =: [\\texttt{EE}]$ was computed in advance, and once for all.\n\nThe cardinality of such incidence/adjacency algebraic tools between p-cells and q-cells $(0\\leq p,q \\leq 2)$ is equivalent to that of relations itself~\\cite{Woo:85}, in force of their sparsity.  For example, $\\#\\texttt{EV} = O(Space([\\delta_1]) = 2\\#\\texttt{E}$), where \\texttt{V} are the vertices of a solid B-rep and \\texttt{EV} are binary incidences of edges with vertices. Every set of local queries about the $3\\times 3$ incidences/adjacencies between cells can be answered by multiplication, via software kernels for \\emph{sparse matrix} product and transposition, just by collecting the coordinate vectors of unit chains, ``subject''  of elementary queries, as \\emph{columns} of a sparse $Q$ matrix, and by left-multiplying $Q$ times one/two operator matrices $[\\partial_1]$ and/or $[\\partial_2]$, suitably ordered and/or transposed~\\cite{Dicarlo:2014:TNL:2543138.2543294}, to get the algebraic equivalent of multiple database queries at once.\n\n%================================================================================\n\\section{Arrangement Algorithms}\n%================================================================================\n\nA \\emph{chain complex} is a short exact sequence of graded linear spaces \\(C_p\\) of (co)chains, with linear\nboundary/coboundary maps \\(\\partial_p\\) and\n\\(\\delta_p=\\partial_{p+1}^\\top\\): \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\\] \n\nThe subject of Reference~\\cite{TSAS:17} is the computation of the chain complex $C_\\bullet = (C_p,\\partial_p)$, starting from some representation\\footnote{Our prototype implementation in\\\\ \\href{https://github.com/cvdlab/LinearAlgebraicRepresentation.jl}{\\scriptsize \\texttt{https://github.com/cvdlab/LinearAlgebraicRepresentation.jl}}, makes use of the \\texttt{Lar} representation~\\cite{Dicarlo:2014:TNL:2543138.2543294}, on which this approach strongly relies.} of an input set $\\mathcal{S}$ of ($d$-1)-complexes. In particular, we compute the matrices of the linear maps $\\partial_p$ (and their duals $\\delta_{p-1}$)  between chain spaces $C_p$. All definitions and more examples are given in Reference~\\cite{TSAS:17}. We describe here the main steps of space decomposition in reverse order, starting from the last operation, because of possible iteration on dimensions, starting from 3D.\n\n\n\\subsection{Topological gift wrapping}\n%--------------------------------------------------------------------------------\nThe main goal is to compute, starting from ($d$-1)-dimensional geometric object, the $d$-cells of the space partition (arrangement) generated by them. Examples of input include, but are not limited to: line segments, quads, triangles, polygons, meshes, pixels, voxels, volume images, B-reps, \\emph{etc.} \nIn mathematical terms, a geometric object is a topological space embedded in some $\\E^d$ .\n\nThe topological method introduced in~\\cite{TSAS:17} is reminiscent of the ``gift-wrapping'' algorithm~\\cite{Cormen:2009:IAT:1614191,Jarvis:1973:ICH} for computing convex hulls of 2D and 3D discrete sets of points, but it works with higer-dimensional cells instead with points, and is mostly based on applications of boundary and coboundary operators. Our \\texttt{TGW} (Topological Gift Wrapping) algorithm~\\cite{TSAS:17} takes a sparse matrix $[\\partial_{d-1}]$ as input and produces in output the \\emph{unknown} sparse matrix  $[\\partial_{d}^+]$, augmented with the outer cell. A geometric embedding function $\\mu: X_0\\to\\E^d$ is used to compute the angular ordering, around some ($d$-2)-cells, of ($d$-1)-basis elements in the boundary's coboundary, while wrapping up a ($d$-1)-cycle, as illustrated in Figure~\\ref{fig:3D}. The built cycles are set up as columns of $[\\partial_d]$, in the construction of a $C_d$ basis.\n\n\n\\begin{figure*}[htbp] %  figure placement: here, top, bottom, or page\n\\hfill\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D1a.png}%\n\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D2.png}%\n\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D3b.png}%\n\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D4a.png}%\n\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D5a.png}%\n\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D6b.png}%\n\\includegraphics[height=0.15\\textwidth,width=0.1428\\textwidth]{figs/3D7a.png}\n\n{\\footnotesize\\hspace{.06\\textwidth}(a)\\hfill(b)\\hfill(c)\\hfill(d)\\hfill(e)\\hfill(f)\\hfill(g)\\hspace{.06\\textwidth}}\n\n\\caption{Extraction of a minimal 2-cycle from $\\mathcal{A}(X_2)$: (a) initial (0-th) value for $c\\in C_2$; (b) cyclic subgroups on  $\\delta\\partial c$; (c)~1-st value of $c$; (d) cyclic subgroups on $\\delta\\partial c$; (e) 2-nd value of $c$; (f) cyclic subgroups on $\\delta\\partial c$; (g) 3-rd value of $c$, such that $\\partial c=0$, hence stop.}\n   \\label{fig:3D}\n\\end{figure*}\n\n\n\\subsection{Merge of 2-skeletons}\n%--------------------------------------------------------------------------------\nThe input to the computational pipeline is a collection $\\mathcal{S}$ of geometric objects that do not necessarily constitute a cellular complex, since they can intersect out of cell boundaries. The first step is hence the computation of mutual interctions of their 2-skeletons, \\emph{i.e.}, of their sets of 2-cells (for a 3D problem), or their 1-skeletons (for a 2D problem). This phase is executed by intersecting independently each 2-cell $\\sigma\\in\\mathcal{S}_2$ with all 2-cells which might intersect it. Their subset is denoted $\\mathcal{I}(\\sigma)$ and is computed using efficient spatial indices on the containment boxes of 2-cells. In particular, each $\\mathcal{I}(\\sigma)$ is given by the intersection of outputs of $d$ independent queries over one-dimensional interval-trees built upon the input.\n\nIt may be interesting to remark that the \\texttt{merge} algorithm is embarrassingly parallel, and is implemented in Julia making use of two \\texttt{Channel}s to ditribute the jobs to workers and to return the output to the master node. This more efficient strategy is quite unusual in Solid Modeling, where even recent variadic approaches~\\cite{Zhou:2016:MAS:2897824.2925901} iteratively intersect a new operand against the cell complex generated by the previous operations. \n\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.25\\linewidth]{figs/1.png}%\n   \\includegraphics[width=0.25\\linewidth]{figs/2.png}%\n   \\includegraphics[width=0.25\\linewidth]{figs/3.png}%\n   \\includegraphics[width=0.25\\linewidth]{figs/4.png} \n\n   \\includegraphics[width=0.25\\linewidth]{figs/5.png}%\n   \\includegraphics[width=0.25\\linewidth]{figs/6.png}%\n   \\includegraphics[width=0.25\\linewidth]{figs/7.png}%\n   \\includegraphics[width=0.25\\linewidth]{figs/8.png}%\n   \n   \\caption{Cartoon display of the computational pipeline: (a) two solids in $\\mathcal{S}$; (b) the exploded input collection $\\mathcal{S}_2$ in $\\E^3$; (c) 2-cell $\\sigma$ (red) and the set $\\Sigma(\\sigma)$ (blue) of possible intersection; (d)  $\\sigma\\cup\\Sigma$ affinely mapped on $z=0$; \n   (e)~reduction to a set of 1D segments in $\\E^2$ via intersection with $z=0$; (f) pairwise intersections; (g) exploded $U_2$ basis of $C_2$ generated as columns of $\\partial_2: C_2 \\to C_1$; (h) exploded $U_3$ basis of $C_3$ generated as columns of operator's $\\partial_3: C_3 \\to C_2$ sparse matrix, via the \\texttt{TGW} algorithm in 3D.    }\n   \\label{fig:process}\n\\end{figure}\n\n\nThe independent processing of 2-cells is made possible by considering and enforcing the congruence (i.e.~the boundary compatibility) between adjacent fragmented cells. Hence, each input 2-cell $\\sigma$ is fragmented in 2D independently from each other.  For this purpose,  a suitable affine transformation maps each set $\\{\\sigma\\}\\cup\\mathcal{I}(\\sigma)$ and puts $\\sigma$ into the $z=0$ subspace.\n\n\n\\subsection{Reduction to line intersection in 2D}\n%--------------------------------------------------------------------------------\nAt this point the single 3D arrangement problem is reduced to a collection of several independent 2D arrangement problems, one-to-one with the 2-cells in the 3D input. Every 2-cell in $\\mathcal{I}(\\sigma)$ is independently intersected (in parallel) with $z=0$, so providing a number $n$ of line segment sets $\\mathcal{S}_1$ for independent computation of the 2D arrangement generated by it. The computational pipeline is depicted as cartoon in Figure~\\ref{fig:process}. In particular: each set of line segments is mutually intersected (using again two 1D interval-trees of containment boxes of segments for acceleration); the dangling edges and subgraphs are removed from the generated linear graph; and the \\texttt{TGW} is used in 2D to build the matrix $[\\partial_2]$ of the arrangement, and the corresponding basis of elementary 2-chains (2-cells) of the  $\\sigma$ cell decomposition.\n\n\n\\subsection{Congruence of 2D arrangements}\n%--------------------------------------------------------------------------------\nEach 2-complex $X_\\sigma$ providing an independent arrangement of 2-space, is transformed back in 3D using the inverse affine transformation of $\\sigma$. Here, congruent cells (e.g., edges member of the boundary of two or more fragmented faces) must be identified as belonging to the same equivalence class, and substituted by a single instance, so implementing a set quotient operation on fragmented cells. Numerical identification of vertices via dictionaries having arrays of floats as keys (permitted by Julia) are used for this purpose. Once identified congruent vertices, the identification of congruent edges and faces is done using their canonical \\texttt{Lar} representation, \\emph{i.e.,} the ordered arrays of integer indices of vertices. \n\n%================================================================================\n\\section{Variadic Boolean Operations}\n%================================================================================\n\nWhen the unknown sparse boundary matrix $[\\partial_3]$ has been generated by \\texttt{TGW} in 3D, the computation of any Boolean operation or solid-valued expression, including solid arguments and Boolean operators, is actually straightforward\\footnote{Even if not yet implemented.}. Let us note that the arrangement itself corresponds to the output of a union operation.\nTo compute any general solid-valued expression, it suffices to suitably store the dependencies, of each possibly fragmented 2-cell of resulting 3-cells, from the input 2-cells that generated it, i.e. from its ``father(s)\". This storing allows to reconstruct the containment relations of arrangement's 3-cells with their parents, and hence to write truth tables having them on columns, and the original solids (or their boundaries) on the rows.\nIt is worthwhile to note that most of the required information is already coded by the non-zero coefficients of $[\\partial_3]$, and in particular by their indices and signs.\n\n\n\\subsection{Columns and rows of 3-boundary matrix}\n%--------------------------------------------------------------------------------\nWe already know that columns of $[\\partial_3]$ represent the single 3-cells of the arrangement, corresponding to cycles (closed chains) of 2-cells. \nFirst, let us consider a solid model $B$ as a 3-chain in $C_3$, which is possibly made by more then one 2-cycles, corresponding to one or more columns in $[\\partial_3]$. \nThis set of columns $[\\partial_3]_B$, possibly a singleton, codifies the non-empty set of shells of $B$, where each one may be either inner (boundary of empty holes) or outer (boundary of connected components).  \nThe number of $[\\partial_3]$ rows is the number of elements of the (combinatorial) set union of fragments of original 2-cells in the input of arrangement algorithm. \n The rows, one-to-one with fragmented 2-cells, can be subdivided in two classes, corresponding to the type of input they belong to, which can be either a B-rep or a cellular model~\\cite{HofShapiro:2017}: \n \n\\begin{enumerate}\n\\item\nif some shell of the ``solid'' chain $B\\in C_3$ is represented by a 2-cycle $b\\in\\partial B\\subseteq U_2$, then each elementary 2-chain --- \\emph{i.e.}, basis element (2-cell) --- $\\sigma\\in b$  belongs to \\emph{only one} elementary 3-chain $u_3$ of the $B$'s  linear combination  generated by our algorithmic pipeline.\\footnote{Some conceptual and notational ambiguity may arise, since a chain or cycle may be seen either as element $(\\in)$ of a chain space (linear combination of the basis) or as a subset $(\\subset)$ of the basis.}\n\n\\item\nif a row corresponds to a fragment of 2-cell originally in the interior of $B$, then it will belong to \\emph{exactly two} cells $u_3\\in C_3$ that are solid fragments of $B$.\n\\end{enumerate}\n\n\n\n\\subsection{Mapping from output $d$-cells to input ($d$-$1$)-cells}\n%--------------------------------------------------------------------------------\nAccording to the properties listed above, each column of $[\\partial_3]$, \\emph{i.e.}, each solid 3-cell in the output, must be mapped to the input surfaces that generated it, going from fragments on the related rows to their ancestor 2-cells. This parental relationship is carefully recorded and maintained during the pipeline computation.\n\n\\subsection{Boolean ops on truth tables}\n%--------------------------------------------------------------------------------\nTwo binary parental relationships between input and output 2-cells, and between output 2-cells and output 3-cells are used to compute the solid-valued results of Boolean expressions between solid models. We call $Q$ matrix the first, whereas the second is simply the unsigned sparse matrix $[\\partial_3]^o$. A third sparse binary matrix $P=[\\delta_2]^i$ stores the membership of original 2-cells to solid models being operated.\nIt is interesting to note that $P$ is a diagonal block matrix, where the blocks are the coboundary matrices $[\\delta_2]_k$ ($1\\leq k\\leq n$) of the $n$ solid arguments of the expression to be evaluated.\nThe analysis of results of compatible matrix product \n$\n[\\delta_2]^i\\,Q\\,[\\partial_3]^o\n$\n finally produces the membership of the output 3-cells to the input arguments, and allows for on-off computation of solid-valued expression.\n\n%================================================================================\n\\section{Julia packages}\n%================================================================================\n\nThe methods and algorithms described above were implemented in the Julia packages \\texttt{LinearAlgebraicRepresentation} and \\texttt{Triangle}. In the following (and in our Julia software) it will be often called \\texttt{\\texttt{Lar}} for the sake of brevity. \\texttt{ViewerGL} is a visual package whose development started recently.  It provides OpenGL interactive visualization for \\texttt{\\texttt{Lar}} in native Julia code, on top of \\texttt{GLFW}, \nthe multi-platform library for OpenGL, OpenGL ES and Vulkan, that  provides a simple API for creating windows and graphics context. The other dependency, \\texttt{ModernGL}, provides OpenGL 3+ bindings for Julia. The main functionalities in our packages follow.\n\n\n\\subsection{\\texttt{LinearAlgebraicRepresentation.jl}}\n%--------------------------------------------------------------------------------\n\\texttt{\\texttt{Lar}}, as its ancestor geometric\nlanguage \\texttt{PLaSM} and its father library \\texttt{pyplasm}, aims to\nbe multidimensional. Hence many functions generate geometric models of\nvarying dimensions. Important examples are \\texttt{cuboidGrid} and\n\\texttt{simplexGrid}, whose unique parameter is the \\texttt{shape} of the\ngenerated mesh, i.e.~the number of \\(1\\)-dimensional cells in each\ndimension, with \\texttt{d = length(shape)}. The vertices of the mesh\nstay on the integer grid of suitable dimension and size.\n\n\\paragraph*{\\texttt{Lar} model}\nA \\texttt{Lar} model is a pair \\emph{geometry}, \\emph{topology}. The\n\\emph{geometry} is specified by the position vectors of \\emph{vertices}\nin a Euclidean point space $\\E^d$\nwith $d$ coordinates. The \\emph{topology} is specified by one or\nmore bases of singleton $k$-chains\n(\\emph{i.e.}, $k$-cells) for\n$0 \\leq\\ k\\leq d$. The vertex\nsharing between cells implicitly provides the attachment maps between\ncells of various dimensions. Vertex positions are represented, by\ncolumns, by a 2-array of $d$ real coordinates. \nWith abuse of language, we consider a finite cellular complex $X$\nas generated by a discrete partition of an Euclidean space. In computing\na cellular complex as the space arrangement of a collection of geometric\nobjects $\\mathcal{S}$, \\emph{i.e.}, when\n$X\\ := \\mathcal{A}(\\mathcal{S})$,\nwe actually compute the whole \\emph{chain complex}\n$C_\\bullet$ generated by $X$.\n\n\n\\paragraph*{Multidimensional grids}\n\\texttt{src/largrid} and \\texttt{src/simplexn} allow for multidimensional \\emph{grids} of\n\\texttt{cuboidal} and \\texttt{simplicial} cell complexes, and  \\emph{Cartesian product} of cellular complexes. Both kind of\noperators, depending on the dimension of their input, may generate\neither \\emph{full-dimensional} (i.e.~solid) output complexes, or\n\\emph{lower-dimensional} complexes of dimension $d$ embedded in\nEuclidean space of dimension $n$, with\n$d\\leq n$. E.g., just think to a mesh of 3D cubes in three-dimensional space for\nthe first case, and to the (non-manifold) framework of boundary polygons\nof such cubic meshes for the second case. In particular, both\n$n$-dimensional \\emph{solid grids} of (hyper)-cuboidal cells\nand their $d$-dimensional \\emph{skeletons}\n($0\\leq d\\leq n$), embedded in\n$\\E^n$, are generated by assembling the cells produced by a\nnumber $n$ of either $0$- or $1$-dimensional cell\ncomplexes, that in such lowest dimensions coincide with \\emph{simplicial\ncomplexes}. Generation of \\emph{grids} works by \\emph{Cartesian product} of\n$0/1$-complexes; the \\emph{output complex} is generated by the product of\n\\emph{any number} of either 0- or 1-dimensional complexes. The\nproduct of $d$ one-dimensional complexes generates \\emph{solid}\n$d$-cells, while the product of $n$ zero-dimensioanl complexes and\n$n-d$ 1-complexes ($d < n$) generates\n\\emph{non-solid} $(n-d)$-cells, properly embedded in\n$n$-space, i.e.~with vertices having $n$ coordinates.\n\n\n\\paragraph*{Assemblies of cellular complexes}\nHierarchical models of assemblies are generated by aggregation\nof cellular complexes, each one defined in a local coordinate system,\nand possibly relocated by affine transformations of coordinates. This\noperation may be repeated hierarchically, with subassemblies defined by\naggregation of simpler parts, and so on, until to obtain a set of \\texttt{Lar}\nmodels, which are not further decomposed.\nThis \\emph{hierarchical model}, defined inductively\nas an assembly of component parts, is described by an \\emph{acyclic\ndirected multigraph}, often called a \\emph{scene graph} or\n\\emph{hierarchical structure} in computer graphics and modeling. The\nmain algorithm in \\texttt{Lar} with hierarchical assemblies is the \\texttt{traversal}\nfunction, which transforms every component from \\emph{local coordinates}\nto global coordinates, called \\emph{world coordinates}.\n\n\\paragraph*{Hierarchical modeling}\nTwo main advantages can be found in a hierarchical modeling approach.\n(a) Each component complex and each assembly, at every hierarchical level,\nare defined independently from each other, using a local coordinate\nframe, suitably chosen to make its definition easier. (b) Only\none copy of each component is stored in memory, and may be instanced in\ndifferent locations and orientations how many times it is needed.\n\nA \\emph{container} of geometrical objects is defined by applying the\nfunction \\texttt{Struct} to the array of contained objects. The value\nreturned from the application is a value of \\texttt{Struct} type. The\ncoordinate system of this value is the one associated with the first\nobject of the \\texttt{Struct} parameters. Also, the resulting\ngeometrical value is often associated with a variable name.\nAn affine \\(3\\times 3\\) transformation matrix, generated in homogeneous\nnormalized coordinates by the function call \\texttt{t(-0.5,-0.5)}, can\nbe \\emph{applied} to a \\texttt{Lar} object \\texttt{obj} both \\emph{explicitly} by\nusing the function \\texttt{apply(Matrix, obj)} or \\emph{implicitly} by\ncreating a \\texttt{Struct} hierarchical object.\n\n\\paragraph*{From hierarchical models to flat models}\nThe generation of container nodes may continue hierarchically by\nsuitably applying \\texttt{Struct}. Notice that each \\texttt{Lar} object in a\n\\texttt{Struct} container is transformed by each matrix before it\n\\emph{within the container}, going from right to left. The action of a\ntransformation (tensor) extends to every object rightwise within its\nown container. Conversely, the action of a tensor does not extend outside\nits container, according to the semantics of \\texttt{PHIGS} structures.\nThe function \\texttt{evalStruct}, when applied to a \\texttt{Struct}\nvalue, generates an \\texttt{Array} of \\texttt{Lar} models, each one originally\ndefined in a \\emph{local coordinate} system, transforming all of them in\nthe same \\emph{world coordinate}, equal to the one of the \\emph{first}\nobject in the \\texttt{Struct} parameter sequence (see Section~\\ref{sec:boolean}).\nConversely, the \\texttt{struct2lar} function generates a \\emph{single}\n\\texttt{Lar} model (cellular complex), whose components are there assigned\n to variables \\texttt{V} (coordinates of vertices),\n\\texttt{FV} faces (2-cells), and \\texttt{EV} edges (1-cells). Notice\nthat the whole model is \\emph{embedded in 3D}, since the \\texttt{V}\narray (coordinates by columns) has \\emph{three rows}.\n\n\\paragraph*{Parametric objects}\nThe \\texttt{src/mapper.jl} file contains the implementation of several\nparametric primitives, including \\emph{curves}, \\emph{surfaces} and \\emph{solids} embedded in\neither 2D or 3D.\nA constructive approach is common to all methods. It consists in\ngenerating a simplicial or cuboidal decomposition of a simple\ngeometrical domain in ${u,v}$ or ${u,v,w}$ parametric space. Then\na change of coordinates, \\emph{e.g.}, from polar or cylindrical\nto Cartesian, is applied to vertices of the cellular complex which\ndecomposes the domain.\n\n\\paragraph*{Integration of monomials}\nA finite integration method is implemented in \\texttt{src/integr.jl}, to compute\nmonomial integrals over polyhedral solids and surfaces in\n3D space. This integration can be used for the exact evaluation of\ndomain integrals of trivariate polynomials.\nThe evaluation of surface and volume integrals is achieved by\ntransform into line integrals over the boundary of every 2-simplex\nof a boundary triangulation. The \\texttt{Lar} integration formulae \nmay also be used with models consisting of the collection of its boundary's 2-loops (polygons).\nLoops must be oriented counter-clockwise if external, clockwise if internal\nto another loop. \n\n\\subsection{\\texttt{ViewerGL.jl}}\n%--------------------------------------------------------------------------------\nThe work on this package started only recently, but already provides useful visualization tools, allowing for fast 3D user interaction with 2D and 3D geometric models.\n\n\\paragraph*{Basic \\texttt{ModernGL} infrastructure} Several Julia's \\texttt{struct} objects are used at the basic implementation level of \\texttt{ViewerGL}, and in particular for describing the current state of variables of  types  \\texttt{Point}, \\texttt{Matrix}, \\texttt{Quaternion}, \\texttt{Box}, \\texttt{Frustum}, \\texttt{Viewer}, \\texttt{GLColorBuffer}, \\texttt{GLMesh}, \\texttt{GLPhongShader}, \\texttt{GLShader}, \\texttt{GLText}, \\texttt{GLUtils}, \\texttt{GLVertexArray}, and \\texttt{GLVertexBuffer}.\n\\texttt{Graphictext} is a cellular implementation of a native Julia's vector font, mainly used to help  the visual testing and debugging of geometric codes, by visually numbering vertices, edges, faces, and solid cells.   \n\n\n\\paragraph*{High-level visualization primitives}\nAt low-level, OpenGL uses only few basic primitives, whose vertices must suitably embedded into proper buffers for \\texttt{points}, \\texttt{normals}, and \\texttt{colors}. \nA number of high-level, user-oriented, graphics primitives were implemented to allow direct and easy rendering of various types of cellular complexes, both 2D and 3D, each reurning an object of type \\texttt{GLMesh} to direvtly feed the \\texttt{Viewer}. Those primitives currently include:  \n\\texttt{GLHull}, \\texttt{GLHull2d}, \\texttt{GLHulls}, \\texttt{GLPolygon}, \\texttt{GLPolygons}, \\texttt{GLLar2gl}, \\texttt{GLLines}, \\texttt{GLPoints}, \\texttt{GLPolyhedron}, \\texttt{GLPolyhedrons}, \\texttt{GLGrid}, and \\texttt{GLExplode}, that all accept as input a \\texttt{\\texttt{Lar}} model.\n\n\n%================================================================================\n\\section{Examples}\n%================================================================================\n\nBoth \\texttt{LinearAlgebraicRepresentation} and \\texttt{ViewerGL} packages contain several simple \\texttt{examples/} scripts, to help the user to get acquainted. The actual APIs are not yet completely defined.\n\n\n\\subsection{Arrangement of circles and rectangles}\n%--------------------------------------------------------------------------------\n\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.5\\linewidth]{figs/bubble1.png}%\n   \\includegraphics[width=0.5\\linewidth]{figs/bubble2.png}%\n   \n   \\includegraphics[width=0.5\\linewidth]{figs/bubble3.png}%\n   \\includegraphics[width=0.5\\linewidth]{figs/bubble4.png}%\n   \\caption{Four views of the 2D arrangement generated by circles and regular polygons:\n   (a) the input random polylines; (b) 2-space partition generated by the input; \n   (c) exploded view of the output arrangement; (d) exploded view of boundary 1-cycles of \n   unit 2-chains of the 2-space arrangement.}\n   \\label{fig:example}\n\\end{figure}\n\n\n\\begin{figure}[htb] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.5\\linewidth]{figs/squares1.png}%\n   \\includegraphics[width=0.5\\linewidth]{figs/squares2.png}\n   \n   \\caption{Two views of the 2D arrangement generated by random rectangles:\n   (a) exploded view of fragmented 1-chain generated by the input boundaries of rectangles; \n   (b) the 2-space arrangement generated by the input.}\n   \\label{fig:example}\n\\end{figure}\n\n\n\n\\subsection{Boolean 3D workflow}\\label{sec:boolean}\\footnote{You may enjoy trying \\texttt{Lar.cuboidGrid([2,2,2],true)}}\n%--------------------------------------------------------------------------------\nFirst define \\texttt{cube} as a single element of a grid of cubes:\n\n{\\footnotesize\\begin{verbatim}\nusing LinearAlgebraicRepresentation, ViewerGL, SparseArrays\nLar = LinearAlgebraicRepresentation; GL = ViewerGL\nV,(VV,EV,FV,CV) = Lar.cuboidGrid([1,1,1],true)\ncube = V,FV,EV\n\\end{verbatim}}\n\nThen position three instances of cubes in $\\E^3$ within a hierarchical scene graph, using the \\texttt{Struct} function:\n\n{\\footnotesize\\begin{verbatim}\nthreecubes = Lar.Struct([ cube,\n\tLar.t(.3,.4,.25),Lar.r(pi/5,0,0),Lar.r(0,0,pi/12),cube,\n\tLar.t(-.2,.4,-.2),Lar.r(0,pi/5,0),Lar.r(0,pi/12,0),cube ]);\n\\end{verbatim}}\n\nConvert \\texttt{threecubes} to single (self-intersecting) model \\texttt{V,FV,EV}, and visualize the collection \\texttt{FV} of faces (2-cells). It is not a cellular complex, since cells intersect out of boundaries. See Figure~\\ref{fig:threecubes}a:\n\n{\\footnotesize\\begin{verbatim}\nV,FV,EV = Lar.struct2lar(threecubes)\nGL.VIEW([ GL.GLGrid(V,FV), GL.GLFrame ])\n\\end{verbatim}}\n\nNext, prepare the input data types for computing the 3-space arrangement. \nWe have to yet better define the  IDE. \\texttt{Lar.Cells} and \\texttt{Lar.ChainOp} are array or sparse matrix of $p$-cells, respectively.\n\n{\\footnotesize\\begin{verbatim}\ncop_EV = Lar.coboundary_0(EV::Lar.Cells);\ncop_EW = convert(Lar.ChainOp, cop_EV);\ncop_FE = Lar.coboundary_1(V,FV::Lar.Cells,EV::Lar.Cells);\nW = convert(Lar.Points, V');\n\\end{verbatim}}\n\n$[\\delta_2],\\;[\\delta_1],\\;[\\delta_0]=\\texttt{ChainOp[copCF}, \\texttt{copFE}, \\texttt{copEV]}$, \\emph{Chain Complex} embedded in $\\E^3$ by  $3\\times n$ vertex matrix \\texttt{V}, is finally generated:\n\n{\\footnotesize\\begin{verbatim}\nV, copEV, copFE, copCF = \n\tLar.Arrangement.spatial_arrangement(W, cop_EW, cop_FE)\n\\end{verbatim}}\n\nThe 8 rows of the $\\delta_2: C_2\\to C_3$ matrix (below) or the 8 columns of $[\\partial_3]=[\\delta_2]^t$, $\\partial_3: C_3\\to C_2$, generate the eight\n3-cells of Figure~\\ref{fig:threecubes}d.\n\n{\\footnotesize\\begin{verbatim}\n@show Matrix(copCF);\n\\end{verbatim}}\\vspace{-2mm}\n{\\tiny\\begin{verbatim}\nInt8[\n-1 0 1 0 0 0 1 0 -1 0 -1 0 0 0 -1 1 0 1 0 0 -1 1 0 1 -1 0 0 0 -1 -1 0 1 0 0 -1 0 1 0 0 0 1 -1 0 -1 0 0 1;\n 0 -1 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 1 0 -1 0 0 0 -1 1 0 1 0 0 -1;\n 0 0 0 -1 0 0 0 -1 0 0 0 1 1 0 0 0 -1 0 0 1 0 0 -1 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 1 0 0 0 0 0 1 0 0;\n 0 0 0 0 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 -1 0 0 0 0 0 -1 0 0;\n 1 0 -1 0 0 0 -1 0 1 0 1 0 0 0 1 -1 0 -1 0 -1 0 0 1 0 0 0 -1 0 0 0 0 0 -1 0 0 0 0 1 0 0 0 0 -1 0 0 0 0;\n 0 0 0 1 0 0 0 1 0 0 0 -1 -1 0 0 0 1 0 0 0 1 -1 0 -1 1 0 0 0 1 1 0 -1 0 0 0 -1 0 0 0 1 0 0 0 0 0 1 0;\n 0 1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 -1 0 0 0 0 1 0 0 0 0;\n 0 0 0 0 1 0 0 0 0 0 0 0 0 -1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 -1 0]\n\\end{verbatim}}\n\n\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.5\\linewidth]{figs/3cubes1.png}%\n   \\includegraphics[width=0.5\\linewidth]{figs/3cubes2.png}%\n   \n   \\includegraphics[width=0.5\\linewidth]{figs/3cubes3.png}%\n   \\includegraphics[width=0.5\\linewidth]{figs/3cubes4.png}%\n  \\caption{Images of the 3D arrangement generated by three unit cubes:\n   (a) transparent view of the input; (b) exploded 2-skeleton of 3D space partition; \n   (c) exploded view of boundary 1-cycles of 2-cells; (d) exploded view of (transparent) \n   3-chain, which is the basis of 3-space arrangement generated by the input. The white 2-cycle is the \n   boundary of outer space.}\n  \\label{fig:threecubes}\n \\end{figure}\n\nFinally, the \\texttt{Lar} model is triangulated, via \\texttt{Triangle.jl} package, giving CDT (constrained Delaunay Triangulation), and converted to triangle arrays per 3-cell, per 2-cell, and per  polygon boundary:\n\n{\\footnotesize\\begin{verbatim}\nW = convert(Lar.Points, V')\nV,CVs,FVs,EVs = Lar.pols2tria(W, copEV, copFE, copCF)\n\\end{verbatim}}\n\n\n\n{\\footnotesize\\begin{verbatim}\nGL.VIEW(GL.GLExplode(V,FVs,1.5,1.5,1.5,99,1));\nGL.VIEW(GL.GLExplode(V,EVs,1.5,1.5,1.5,99,1));\nmeshes = GL.GLExplode(V,CVs[1:end],8,4,6,99,0.5);\nGL.VIEW( push!( meshes, GL.GLFrame) );\n\\end{verbatim}}\n\n\n%================================================================================\n\\section*{Acknowledgements}\n%================================================================================\nThe author is grateful to Antonio DiCarlo and Vadim Shapiro for sharing a lasting curiosity in the exploration of novel geometric territories, and to Giorgio Scorzelli, Francesco Furiani and Giulio Martella for help with the software.\n\n%================================================================================\n\\section{Conclusion}\n%================================================================================\nIn this paper a very simple and general approach to geometric and topological computing using only Julia's~\\cite{bezanson2017julia} sparse arrays was presented. Sparse arrays should fit well with the fast diffusion of hybrid architectures and their advanced applications, using the best-in-class numerical language. The future applications may cover disparate fields of visual calculus, including geomapping, solid and geometric computer-aided design, virtual reality, computer vision, and medical imaging.  \nWe are just at the beginning of this journey. A lot of work remains, and this author has strong hope to share the enjoyment of discovery with the Julia's community.\n\n\n\\bibliographystyle{juliacon}\n\\scriptsize\n\\bibliography{ref}\n\n\n%\\input{bib.tex}\n\n\\end{document}\n\n% Inspired by the International Journal of Computer Applications template\n", "meta": {"hexsha": "2398954e9fd9cfe742b748c9fcfd60c3e345ecdc", "size": 42732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/paper.tex", "max_stars_repo_name": "ramorimo/LinearAlgebraicRepresentation.jl", "max_stars_repo_head_hexsha": "53fb941a83f11967361518e5a981679b851e45ea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-25T16:45:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-25T16:45:01.000Z", "max_issues_repo_path": "paper/paper.tex", "max_issues_repo_name": "ramorimo/LinearAlgebraicRepresentation.jl", "max_issues_repo_head_hexsha": "53fb941a83f11967361518e5a981679b851e45ea", "max_issues_repo_licenses": ["MIT"], "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": "ramorimo/LinearAlgebraicRepresentation.jl", "max_forks_repo_head_hexsha": "53fb941a83f11967361518e5a981679b851e45ea", "max_forks_repo_licenses": ["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.7788279773, "max_line_length": 1009, "alphanum_fraction": 0.7113404474, "num_tokens": 11727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6806221865446699}}
{"text": "\\section{Methods}\n\n\\subsection{Notation}\n\nIn the following, we will use definitions and notations introduced by \\citep{rougier:2011} where a neural map is defined as the projection from a manifold $\\Omega \\subset \\mathbb{R}^d$ onto a set $\\mathcal{N}$ of $n$ {\\em  neuron}s which is formally written as $\\Phi : \\Omega \\rightarrow \\mathcal{N}$. Each neuron $i$ is associated with a code word $\\mathbf{w}_i \\in \\mathbb{R}^d$, all of which establish the set  $\\{\\mathbf{w}_i\\}_{i \\in   \\mathcal{N}}$ that is referred as the code book. The mapping from $\\Omega$ to $\\mathcal{N}$ is a closest-neighbor winner-take-all rule such that any vector $\\mathbf{v} \\in \\Omega$ is mapped to a neuron $i$ with the code $\\mathbf{w}_\\mathbf{v}$ being closest to the actual presented stimulus vector $\\mathbf{v}$,\n\\begin{equation}\n\\Phi : \\mathbf{v} \\mapsto argmin_{i \\in \\mathcal{N}} (\\lVert \\mathbf{v} -\n\\mathbf{w}_i \\rVert).\n\\label{eq:psi}\n\\end{equation}\nThe neuron $\\mathbf{w}_\\mathbf{v}$ is named the best matching unit (BMU) and the set $C_i = \\{x \\in \\Omega | \\Phi(x) = \\mathbf{w}_i \\}$ defines the {\\em receptive field} of the neuron $i$.\n\n\n%Before we present our new SOM learning algorithm, we introduce the notation  and terminology we are using throughout the present work. We borrow the notation from a previous work \\citep{rougier:2011}.  A neural map is defined to be the projection from a manifold $\\Omega \\subset \\mathbb{R}^d$ onto a set $\\mathcal{N}$ of $n$ {\\em neuron}s $\\Phi : \\Omega \\rightarrow \\mathcal{N}$. Each neuron $i$ is associated with a code word $\\mathbf{w}_i \\in \\mathbb{R}^d$, all of which establish the set  $\\mathcal{W} = \\{\\mathbf{w}_i, i \\in \\mathcal{N}\\}$ that is referred as the code book. The mapping from $\\Omega$ to $\\mathcal{N}$ is a closest-neighbor winner-take-all rule such that any vector $\\mathbf{v} \\in \\Omega$ is mapped to a neuron $i$ with the code $\\mathbf{w}_\\mathbf{v}$ being closest to the current input vector $\\mathbf{v}$,\n%\\begin{equation}\n%\\Phi : \\mathbf{v} \\mapsto argmin_{i \\in \\mathcal{N}} (\\lVert \\mathbf{v} -\n%\\mathbf{w}_i \\rVert).\n%\\label{eq:psi}\n%\\end{equation}\n%The neuron $\\mathbf{w}_\\mathbf{v}$ is named the best matching unit (BMU) and the set $C_i = \\{x \\in \\Omega | \\Phi(x) = \\mathbf{w}_i \\}$ defines the {\\em receptive field} of neuron $i$.\n\n\n\\subsection{Spatial distribution} % \\& Centroidal Voronoi Tesselation}\n\\label{sec:spatial_dist}\n\nThe SOM space is usually defined as a two-dimensional region where nodes are arranged in a regular lattice (rectangular or hexagonal). Here, we consider instead the random placement of neurons with a specific spectral distribution (blue noise). As explained in \\citep{Zhou:2012}, the spectral distribution property of noise patterns is often described in terms of the Fourier spectrum color. White noise corresponds to a flat spectrum with equal energy distributed in all frequency bands while blue noise has weak low-frequency energy, but strong high-frequency energy. In other words, blue noise has intuitively good properties with points evenly spread without visible structure (see figure~\\ref{fig:sampling} for a comparison of spatial distributions).\n%%\n\\begin{figure}[htbp]\n  \\includegraphics[width=\\textwidth]{figure-blue-noise.pdf}\n  \\caption{\\textbf{Spatial distributions.}\n    \\textbf{\\textsf{A.}} Uniform sampling (n=1000) corresponding to white noise.\n    \\textbf{\\textsf{B.}} Regular grid (n=32$\\times$32) + jitter (2.5\\%).\n    \\textbf{\\textsf{C.}} Poisson disc sampling (n=988) corresponding to blue noise.}\n  \\label{fig:sampling}\n\\end{figure}\n%%\nThere exists several methods \\citep{Lagae:2008} to obtain blue noise sampling that have been originally designed for computer graphics (e.g. Poisson disk sampling, dart throwing, relaxation, tiling, etc.). Among these methods, the fast Poisson disk sampling in arbitrary dimensions \\citep{Bridson:2007} is among the fastest ($\\mathcal{O}(n)$) and easiest to use. This is the one we retained for the placement of neurons over the normalized region $[0,1]\\times[0,1]$. Such Poisson disk sampling guarantees that samples are no closer to each other than a specified minimum radius. This initial placement is further refined by applying a LLoyd relaxation \\citep{Lloyd:1982} scheme for 10 iterations, achieving a quasi centroidal Voronoi tesselation.\n\n\n%The SOM space is usually defined as a two-dimensional manifold where nodes are arranged in a regular lattice (rectangular or hexagonal). Here, we follow a  different approach and, instead of the regular lattice, we place the neurons randomly by sampling a specific spectral distribution. More specifically, we assign neurons positions by drawing samples from a blue noise distribution. \\citep{Zhou:2012}. have shown that the spectral distribution property of noise patterns is often described in terms of the Fourier spectrum color. For instance, white noise corresponds to a flat spectrum with signal's energy equally distributed to all frequency bands while blue  noise has weak low-frequency energy and strong high-frequency energy. An interesting property of the blue noise distribution is that  the resulting positions of neurons drawn are evenly spread without any apparent structure (see figure~\\ref{fig:sampling} for a comparison of spatial distributions).\n%%\n%\\begin{figure}[htbp]\n%  \\includegraphics[width=\\textwidth]{figures/blue-noise.pdf}\n%  \\caption{\\textbf{Spatial distributions.}\n%    \\textbf{\\textsf{A.}} Uniform sampling (n=1000) corresponding to white noise.\n%    \\textbf{\\textsf{B.}} Regular grid (n=32$\\times$32) + jitter (2.5\\%).\n%    \\textbf{\\textsf{C.}} Poisson disc sampling (n=988) corresponding to blue noise.}\n%  \\label{fig:sampling}\n%\\end{figure}\n%%\n\n%Blue noise distributions have been used in the field of computer graphics for many years and there are manych different techniques for computing them: Poisson disk sampling, dart throwing, relaxation, tiling, and other applications (see \\citep{Lagae:2008} for a review). One of the fastest and easiest to implement method for generating blue noise samples is the  fast Poisson disk sampling. This method, introduced by \\citep{Bridson:2007}, can be used on arbitrary dimensions in linear time ($\\mathcal{O}(n)$). In this work, we propose to use this method for placing neurons over a normalized  region of $[0,1]\\times[0,1]$. Such Poisson disk sampling guarantees that samples are no closer to each other than a specified minimum radius. This initial placement is further refined by applying a Lloyd relaxation~\\cite{Lloyd:1982} scheme for $10$ iterations to achieve a quasi centroidal Voronoi tesselation.\n\n\\subsection{Topology}\n\\label{sec:topo}\n\nConsidering a set of $n$ points $P = \\{P_i\\}_{i \\in [1,n]}$ on a finite region,\nwe first compute the Euclidean distance matrix $E$, where $e_{ij} = \\lVert P_i - P_j \\rVert$ \nand we subsequently define a connectivity matrix $G^{p}$\n%= \\{G^{p}_{ij}\\}_{i,j \\in [1,n]}$ \\gid{$G^{p} = g^{p}_{ij},\\, \\text{where } i,j \\in [1,n]$}\nsuch that only the $p$ closest points\nare connected. More precisely, if $P_j$ is among the $p$ closest neighbours of\n$P_i$ then $g^p_{ij} = 1$ else we have $g^p_{ij} = 0$.\nFrom this connectivity\nmatrix representing a graph, we compute the length of the shortest path between\neach pair of nodes and stored them into a distance matrix $D^p$. Note that\nlengths are measured in the number of nodes between two nodes such that two\nnearby points (relatively to the Euclidean distance) may have a corresponding\nlong graph distance as illustrated in figure \\ref{fig:topology}. This matrix\ndistance is then normalized by dividing it by the maximum distance between two\nnodes such that the maximum distance in the matrix is 1. In the singular case\nwhen two nodes cannot be connected through the graph, we recompute a spatial\ndistribution until all nodes can be connected.\n%%\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{figure-distances.pdf}\n  \\caption{\\textbf{Influence of the number of neighbours on the graph\n    distance.} The same initial set of 1003 neurons has been equiped with\n    2-nearest neighbors, 3 nearest neighbors and 4-nearest neighbors induced\n    topology (panels \\textbf{A}, \\textbf{B} and \\textbf{C} respectively). A\n    sample path from the the lower-left neuron to the upper-right neuron has\n    been highlighted with a thick line (with respective lengths of 59, 50 and\n    46 nodes).}\n  \\label{fig:topology}\n\\end{figure}\n\n%Consider a set $P$ of $n$ points on a finite region of $[0, 1] \\times [0, 1]$. The steps we follow to determine the topology of the SOM are: First, we compute the Euclidean distance matrix ${\\bf E} \\in \\mathbb{R}^{n\\times n}$, where $e_{ij} = \\lVert p_i - p_j \\rVert$ and $i, j=1, \\ldots, n$. Subsequently  we define a connectivity matrix ${\\bf G}_m$ with elements $g_{ij} = 1$ if $p_j$ belongs to the $m$ closest points to $p_i$ and $g_{ij} = 0$ otherwise. This definition implies that the matrix ${\\bf G}_m$ carries information about connected neurons within a predetermined vicinity. Once we compute matrix ${\\bf G_m}$, which essentially represents a graph, we compute the shortest path between each pair of nodes on the graph and we store them into a new matrix called ${\\bf D}_m$. Note that lengths are measured in number of nodes (hops) required to reach two nodes such that the two corresponding Euclidean points (represented by the nodes) may have a graph distance as illustrated in figure \\ref{fig:topology}.  \\gid{This matrix distance is then normalized by dividing it by the maximum distance between two nodes. NOT VERY CLEAR}. In the degenerative case where two nodes are not connected on the graph, we resample from a spatial distribution until all nodes have degree greater than one (are connected at least with one other node \\gid{IS THIS CORRECT?}).\n%%\n%\\begin{figure}\n%  \\includegraphics[width=\\columnwidth]{figures/distances.pdf}\n%\\caption{\\textbf{Influence of the number of neighbours on the graph distance.} The same initial set of 1003 neurons has been equipped with 2-nearest neighbors, 3 nearest neighbors and 4-nearest neighbors induced topology (panels \\textbf{A}, \\textbf{B} and \\textbf{C} respectively). A sample path from the the lower-left neuron to the upper-right neuron has been highlighted with a thick line (with respective lengths of 59, 50 and 46 nodes).}\n%  \\label{fig:topology}\n%\\end{figure}\n\n\n\\subsection{Learning}\n\nThe learning process is an iterative process between time $t=0$ and time $t=t_f \\in \\mathbb{N}^+$ where vectors $\\mathbf{v} \\in \\Omega$ are sequentially presented to the map. For each presented vector $\\mathbf{v}$ at time $t$, a winner $s \\in \\mathcal{N}$ is determined according to equation (\\ref{eq:psi}). All codes $\\mathbf{w}_{i}$ from the code book are shifted towards $\\mathbf{v}$ according to\n\\begin{equation}\n  \\Delta\\mathbf{w}_{i} = \\varepsilon(t)~h_\\sigma(t,i,s)~(\\mathbf{v} -\n  \\mathbf{w}_i)\n  \\label{eq:som-learning}\n\\end{equation}\nwith $h_\\sigma(t,i,j)$ being a neighborhood function of the form\n\\begin{equation}\n  h_\\sigma(t,i,j) = e^{- \\frac{{d^p_{ij}}^2}{\\sigma(t)^2}}\n  \\label{eq:som-neighborhood}\n\\end{equation}\nwhere $\\varepsilon(t) \\in \\mathbb{R}$ is the learning rate and $\\sigma(t) \\in \\mathbb{R}$\nis the width of the neighborhood defined as\n\\begin{equation}\n  \\sigma(t) =\n  \\sigma_i\\left(\\frac{\\sigma_f}{\\sigma_i}\\right)^{t/t_f}, \\text{ with } \\varepsilon(t) =\n  \\varepsilon_i\\left(\\frac{\\varepsilon_f}{\\varepsilon_i}\\right)^{t/t_f},\n\\end{equation}\nwhile $\\sigma_i$ and $\\sigma_f$ are respectively the initial and final neighborhood width and $\\varepsilon_i$ and $\\varepsilon_f$ are respectively the initial and final learning rate. We usually have $\\sigma_f \\ll \\sigma_i$ and $\\varepsilon_f \\ll \\varepsilon_i$.\n\n%The learning algorithm we propose in this work relies on the standard SOM algorithm~\\cite{Kohonen:1982}. Once we have define the topology of the map following the steps we described in paragraph~\\ref{sec:topo}, we can start the learning process. Learning is iterative and starts at a time $t_0=0$ and runs until some predetermined final time step, $t_f \\in \\mathbb{N}^+$, has been reached. At every iteration input vectors $\\mathbf{v} \\in \\Omega$ are sequentially given to the map with respect to the probability density function $f$ \\gid{Where is defined?}. For each vector $\\mathbf{v}$ at time $t$, a winner neuron with index  $s \\in \\mathcal{N}$ is determined according to equation (\\ref{eq:psi}). This means that at time $t$ neuron $s$ is closer to the input vector ${\\bf v}$, in the sense of Euclidean distance, than any other neuron. Once the winner neuron has been identified all codes $\\mathbf{w}_{i}$ from the current code book are shifted towards $\\mathbf{v}$ according to\n%\\begin{align}\n%\\label{eq:som-learning}\n%    \\Delta\\mathbf{w}_{i} &= \\varepsilon(t)~h(t,i,s;\\sigma)~(\\mathbf{v} - \\mathbf{w}_i), \n%\\end{align}\n%where $s$ is the index of the winner neuron, $i$ is the index of code words in the code book and $t$ is the current time step. $h_\\sigma(t,i,j;\\sigma)$ is a neighborhood function of the form\n%\\begin{equation}\n%  h(t,i,j; \\sigma) = \\exp\\Big(-\\frac{{d_{ij}}^2}{\\sigma(t)^2}\\Big)\n%  \\label{eq:som-neighborhood}\n%\\end{equation}\n%where $\\varepsilon: \\mathbb{R} \\rightarrow \\mathbb{R}$ is the learning rate time-dependent function given by $\\varepsilon(t) = \\varepsilon_i\\left(\\frac{\\varepsilon_f}{\\varepsilon_i}\\right)^{t/t_f}$, where $\\varepsilon_i$ and $\\varepsilon_f$ are the initial and final learning rates, respectively. $\\sigma: \\mathbb{R} \\rightarrow \\mathbb{R}$ is determines the width of the  neighborhood function~\\eqref{eq:som-neighborhood} and it is reads $\\sigma(t) = \\sigma_i\\left(\\frac{\\sigma_f}{\\sigma_i}\\right)^{t/t_f}$, where $\\sigma_i$ and $\\sigma_f$ are the initial and final neighborhood widths, respectively. We usually assume $\\sigma_f \\ll \\sigma_i$ and  $\\varepsilon_f \\ll \\varepsilon_i$. The entire learning procedure is summarized by Algorithm~\\ref{algo:vsom}. \n\n%% \\input{algorithm}\n\n\\subsection{Analysis Tools}\nIn order to analyze and compare the results of RSOM and SOM, we used a spectral method and persistence diagram analysis on the respective codebooks. These analysis tools are detailed below but roughly, the spectral method allows to estimate the distributions of eigenvalues in the activity of the maps while the persistence diagram allows to check for discrepancies between the topology of the input space and the topology of the map.\n\n% To analyze the results of both the Kohonen SOM and VSOM algorithms and to make any comparison between the two algorithms we use a spectral method and persistence diagram on codebooks. The spectral method estimates the distributions of eigenvalues of the activity of neurons. The persistence diagram is a topological-geometrical  approach, more precisely is a tool coming from the field of topological data analysis (TDA). TDA provides the tools to investigate the topology of the maps and the input space and spot differences between the topology of the input space and the neural space of the SOM algorithms (Kohonen and VSOM). \n\n%\\subsubsection{Topological Data Analysis}\n\\label{sec:tda}\n\nTopological Data Analysis (TDA) \\citep{Carlsson:2009} provides methods and tools to study topological structures of data sets such as point cloud and is useful when geometrical or topological information is not apparent within a data set. Furthermore, TDA tools are insensitive to dimension reduction and noise which make them well suited to analyze high-dimensional self-organized maps and their corresponding input data sets. In this work, we use the notion of persistent barcodes and diagrams \\citep{Edelsbrunner:2008} to spot any differences between the topology of the input and neural spaces. Furthermore, we can apply some metrics from TDA such as the Bottleneck distance and measure how close two persistent diagrams are.\n\n\\correction { We provide, here, a simple example of how we used TDA to\n  extract information relative to the underlying topology of input and\n  neural spaces (a more rigorous description of the methods used in this work\n  are given in section~\\ref{sec:si_tda} of SI).\n  Figure~\\ref{fig:tda_example} illustrates a complete example of how we apply\n  TDA in this work. First we need to collect the data (point cloud). In our\n  example the data are either the $2$-dimensional points of the input space or\n  the codebooks of the neural space (see panel A of\n  Figure~\\ref{fig:tda_example}). Once we have the point cloud we apply\n  a filtration process, where a disc of a specific radius, $\\alpha$ is\n  drawn around each point. We increase the radius systematically and\n  all the intersected discs are registered. In\n  figure~\\ref{fig:tda_example} B, radius $\\alpha_1$ is too small and\n  therefore there are no intersected discs. The simplicial complex\n  (see section~\\ref{sec:si_tda} for more details) in this case is a\n  set of points (\\emph{i.e.}, simplex $0$). The isolated points in the \n  bottom panel of figure~\\ref{fig:tda_example}B define the homology group\n  $H0$. This can be seen also in the persistence barcode shown in\n  figure~\\ref{fig:tda_example}E, where the blue lines correspond to the\n  isolated points. The beginning of the line segment indicates the\n  radius at which each point is born and the end of the line shows when it\n  vanished (died). A line segment on the persistent barcode\n  (figure~\\ref{fig:tda_example}F) or a point on the persistent diagram\n  (figure~\\ref{fig:tda_example}E) appears when a disc is applied on a\n  data point (birth) and it is preserved until the disc intersects\n  another disc (or other discs). Then the line segment or the point\n  dies and a new one that represents the joint (intersected discs)\n  appear in the persistent barcode or diagram.  If a point persists\n  the most then that point considered significant from a topological\n  point of view. }\n\n\\correction{Back to our example, the radius $\\alpha$ is increased\n  until some discs intersect each other ($\\alpha_2$, panel C).  When\n  two discs intersect, we connect their centers (dots) with a line\n  segment (\\emph{i.e.}, simplex $1$). In figure~\\ref{fig:tda_example}C, bottom\n  panel, we see that there is a closed path formed by the connected\n  linear segments and there is a hole in the complex.  This hole\n  corresponds to an $H1$ homology group and the isolated point (or\n  points) to $H0$ homology. The persistent barcode reveals the\n  formation of a hole when the radius reaches the $\\alpha_2$ and the\n  orange linear segment first appears in figure~\\ref{fig:tda_example}E. The\n  other orange line segment corresponds to some other radius that is not\n  shown for illustration purposes. Increasing the radius even\n  further, we get larger discs and now in some cases, more than two\n  discs intersect. When three discs intersect we obtain a triangle\n  (simplex $2$, pink triangles in panel D) and when four discs\n  intersect we get a tetrahedron (simplex $3$, blue color in panel D), etc.\n  Both the triangles and the tetrahedron are not important topological\n  features and thus we ignore them. What is important here is the\n  number of isolated points, holes an voids (we are not considering\n  voids in this example). }\n\n\\correction{By following the procedure described in the\n  aforementioned example, for any $n$-dimensional inputs, we can\n  obtain the persistence barcodes and diagrams, like the ones in\n  figures~\\ref{fig:tda_example} \\textbf{E} and \\textbf{F},\n  respectively. By inspecting the barcodes we can decide if there is\n  any important (persistent) topological feature. Furthermore, we can\n  compare quantitatively the persistence diagrams by using distance\n  functions such as the Bottleneck distance~\\citep{Chazal:2017}. Thus\n  we can examine how close two persistence diagrams are and hence, we\n  can infer how the self-organizing maps retain or degenerate the\n  topology of the input space since we compare the persistence of\n  input space against the codebooks of the neural space. Therefore, we\n  can compare the input space against the learned codebooks of our\n  algorithm (RSOM) and those learned by Kohonen's SOM. Finally, we can\n  draw some conclusions on which algorithm retains the topology of\n  input space the best. For the analysis in this work we used the\n  Gudhi library~\\citep{Maria:2014}. In section~\\ref{sec:si_tda}, we\n  provide a rigorous description of how we compute the persistent\n  barcodes and diagrams and we give more details on the tools we\n  used. }\n\n\n\\begin{figure}[!htpb]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{TDA.pdf}\n    \\caption{\\textbf{Example of Topological Data Analysis.}\n      \\textbf{A} Point cloud (input data to TDA algorithm). In our\n      case this can be either the data points of the input space or\n      the codebooks of neural space. The filtration begins with discs\n      of small radius $\\alpha$ placed on the data points. For\n      instance, in \\textbf{B} we have small discs (radius is\n      $\\alpha_1$) and we observe that no disc intersect with\n      another. Therefore the simplicial complex in this case is just a\n      set of points (bottom panel of \\textbf{B}). Then the radius is\n      being increased to $alpha_2$ and we see in \\textbf{C} that now\n      many intersecting discs appear. Whenever two discs intersect we\n      connect their centers with a line segment and we obtain the\n      simplicial complex at the bottom panel. In this case we have a\n      circle (hole marked in orange color) and a disconnected point.\n      This hole is reflected in the persistent barcode (see panel E)\n      as the longer orange line segment (H1 homology).  In \\textbf{D}\n      the radius is being further increased to $\\alpha_3$ and thus\n      more discs are now intersecting with each other. In this case\n      there are three or four discs intersecting and thus triangles\n      (simplex $3$) and tetrahedrons are formed (see the purple and\n      pink colors in the bottom panel, respectively). However, the\n      hole that formed when the radius was set to $\\alpha_2$ is still\n      present (persists) and this is reflected to the persistent\n      barcode (panel E) by the longer orange line segment.  The\n      persistent barcode in \\textbf{E} illustrates the isolated points\n      and the holes detected during the filtration process. The points\n      are represented by the blue line segments and the holes by the\n      orange ones. We call the former $H0$ group (homology $0$) and\n      the latter $H1$ homology. A similar representation is given by\n      the persistence diagram in \\textbf{F}, where each dot represents\n      a pair of (birth, death) of a persistent feature. For instance,\n      when we apply the discs on data points for first time we mark\n      the birth and once the discs intersect for first time then the\n      two points that correspond to the intersected discs die and one\n      new is generated (the two center of discs have been joined with\n      a line segment). In the persistent diagram the blue dots\n      correspond to $H0$ and orange ones to $H1$ homology.}\n    \\label{fig:tda_example}\n\\end{figure}\n\n\n\n\n\\subsection{Simulation Details}\n\nUnless specified otherwise, all the models were parameterized using values given in table \\ref{table:parameters}. These values were chosen to be simple and do not really impact the performance of the model. All simulations and figures were produced using the Python scientific stack, namely, SciPy \\citep{Jones:2001}, Matplotlib \\citep{Hunter:2007}, NumPy \\citep{Walt:2011}, Scikit-Learn \\citep{Pedregosa:2011}. Analysis were performed using Gudhi \\citep{Maria:2014}). \nSources are available at \\href{https://github.com/rougier/VSOM}{github.com/rougier/VSOM}.\n%%\n\\begin{table}[!ht]\n  \\begin{center}\n    \\begin{tabular}{ll}\n        \\textbf{Parameter} & \\textbf{Value} \\\\\n        \\hline\n        Number of epochs      ($t_f$)           & 25000\\\\\n        Learning rate initial ($\\varepsilon_i$) & 0.50\\\\\n        Learning rate final   ($\\varepsilon_f$) & 0.01\\\\\n        Sigma initial         ($\\sigma_i$)      & 0.50\\\\\n        Sigma final           ($\\sigma_f$)      & 0.01\\\\\n    \\end{tabular}\n      \\caption{\\textbf{Default parameters} Unless specified otherwise, these are\n        the parameters used in all the simulations.}\n      \\label{table:parameters}\n  \\end{center}\n\\end{table}\n\n%We conduct all the experiments using the parameters provided by Table~\\ref{table:parameters}. In all the experiments the input space is the Cartesian product $[0, 1] \\times [0, 1]$ and neurons positions drawn from a blue noise distribution using the fast Poisson disk sampling algorithm~\\cite{Bridson:2007} (see paragraph~\\ref{sec:spatial_dist} for more details).  The source code of the proposed algorithm is written in the Python programming language (SciPy~\\cite{Jones:2001}, Matplotlib~\\cite{Hunter:2007} and NumPy~\\cite{Walt:2011}, Scikit-Learn~\\cite{Pedregosa:2011}, Gudhi~\\cite{Maria:2014}). Sources are available at \\href{https://github.com/rougier/VSOM}{github.com/rougier/VSOM}.\n\n\n%% Considering a set of $n$ points $P = \\{P_i\\}_{i \\in [1,n]}$ on a finite domain\n%% $D \\in \\mathbb{R}^2$, the Voronoi tesselation $V(P) = \\{V_i\\}_{i \\in [1,n]}$ of\n%% $P$ is defined as:\n%% %\n%% \\begin{equation}\n%%   \\forall i \\in [1,n], V_i = \\{x \\in D \\mid\n%%   \\lVert x - P_i \\rVert \\leq \\lVert x - P_j \\rVert, \\forall j \\neq i\\}\n%% \\end{equation}\n%% %\n%% Reciprocally, the (unique) Delaunay triangulation $T(P) = \\{T_i\\}_{i \\in\n%%   [1,n]}$ of $P$ is the dual graph of the Voronoi diagram and defined such that\n%% no point in $P$ is inside the circumcircle of any triangles in $T(P)$. The\n%% centers of the circumcircles are equivalent to the Voronoi diagram, i.e. a\n%% partition of $D$ into Voronoi cells. For each of the cell $V_i$, we can compute\n%% its centroid $C_i$ which is the center of mass of the cell. A Voronoi\n%% tesselation is said to be centroidal when we have $\\forall i \\in [1,n], C_i =\n%% P_i$ (see figure~\\ref{fig:CVT}).\\\\\n\n%% For an arbitrary set of points, there is no guarantee that the corresponding\n%% Voronoi tesselation is centroidal but different methods can be used to\n%% generate a centroidal tesselation from an arbitrary set of points. One of the\n%% most straightforward and iterative methods is the Lloyd relaxation scheme\n%% \\cite{Lloyd:1982}:\n%% \\begin{enumerate}\n%%   \\item The Voronoi diagram of the $n$ points is computed\n%%   \\item The centroid of each of the $n$ Voronoi cell is computed.\n%%   \\item Each point is moved to the corresponding centroid of its Voronoi cell\n%%   \\item The method terminates if criterion is met (see below), else go to 1\n%% \\end{enumerate}\n%% The algorithm finishes when the maximum distance between points and centroids\n%% is less than a given threshold as illustrated in figure~\\ref{fig:CVT}. It is\n%% to be noted that because of numerical imprecisions, there is no guarantee that\n%% an arbitrary small threshold can be reached.\n\n\n%% \\begin{figure}[htbp]\n%%   \\includegraphics[width=\\textwidth]{figures/CVT.pdf}\n%%   \\caption{\\textbf{Centroidal Voronoi Tesselation.}  \\textbf{\\textsf{A.}}\n%%     Voronoi diagram of a uniform distribution (n=100) where red dots represent\n%%     the uniform distribution and white circles represent the centroids of each\n%%     Voronoi cell. \\textbf{\\textsf{B.}} Centroidal Voronoi diagram where the\n%%     point distribution matches the centroid distribution which constitutes a\n%%     blue noise distribution (i.e. {\\em a distribution that is roughly uniformly\n%%       random with no preferred inter-point directions or distances} according\n%%     to the definition of \\cite{Ebeida:2014}). This figure has been obtained\n%%     from the initial distribution on the left after 50 iterations of the Lloyd\n%%     relaxation algorithm. }\n%%   \\label{fig:CVT}\n%% \\end{figure}\n%\n", "meta": {"hexsha": "93ca6861864439f67f330657dcfc370c48eb8749", "size": 27744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article-overleaf/02-methods-revision.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/02-methods-revision.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/02-methods-revision.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": 82.3264094955, "max_line_length": 1366, "alphanum_fraction": 0.7449538639, "num_tokens": 7398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6805866775224201}}
{"text": "\\chapter{Extensions}\r\n\\section {Transversals} \r\n{\\bf Definition 1:}\r\n$G$ is an \\emph{extension} of $K$ by $Q$ if $G \\triangleright K$ and $G/K \\cong Q$\r\nor equivalently $1 \\rightarrow K \\rightarrow G \\rightarrow Q \\rightarrow 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 1:}\r\nIf $1 \\rightarrow N \\rightarrow_{i} G \\rightarrow_{\\varphi} Q \\rightarrow 1$, the following\r\nare equivalent\r\n(1) $\\exists Q^* \\subseteq G: Q^* \\rightarrow Q$ and\r\n(2) $\\exists s:Q \\rightarrow G$ such that $\\varphi \\cdot s = id$.\r\n(3) $G$ is a semi-direct product of $N$ by $Q$ written $N \\ltimes Q$; in this\r\ncase, we say $G$ is a split extension of $N$ by $Q$.\r\n\\begin{quote}\r\n\\emph{Proof:}  See the chapter on constructions.\r\n\\end{quote}\r\n{\\bf Extending a group:}\r\nSuppose $G$ is an extension of $N$ by $H$ and let $\\phi: H \\rightarrow G/N$.  Pick\r\n$s:G \\rightarrow H$ such that $s(1)=1$ and $\\phi(h) = N s(h)$, then \r\n$\\exists f: H \\times H \\rightarrow N: s(h_1) s(h_2)= f(h_1, h_2) s(h_1 h_2)$\r\nand $f(h_1, h_2) f(h_1 h_2, h_3)= f(h_2, h_3)^{s(h_1)} f(h_1 , h_2 h_3)$.  Note\r\nthat $\\theta_h: n \\mapsto s(h) n s(h)^{-1}$ is in $Aut(N)$ and\r\n$\\theta_{h_1}(\\theta_{h_2}(n))= \\theta_{h_1 h_2}(n)^{f(h_1, h_2)}$.  Note, here $a^b = b a b^{-1}$, usually,\r\nwe write $a^b = b ^ {-1} a b$, oh well.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nGiven $N,H$ with $\\theta_h \\in Aut(N)$ and $\\theta_1 = 1$ and a map\r\n$f: H \\times H \\rightarrow N$ with $f(1,h)=f(h,1)=1$ and\r\n$f(h_1, h_2) f(h_1 h_2 , h_3)= \\theta_{h_1}(f(h_2, h_3)) f(h_1, h_2 h_3)$, \r\nsuppose $f$ is compatible in the sense that \r\n$\\theta_{h_1}(\\theta_{h_2}(n))= \\theta_{h_1h_2}(n)^{f(h_1, h_2)}$ then the\r\noperation $(n_1, h_1) \\cdot (n_2, h_2) = (n_1 \\theta_{h_1}(n_2) f(h_1, h_2), h_1 h_2)$\r\ndefines a group $G$ which is an extension of $N$ by $H$.  \r\n$1 \\rightarrow N \\rightarrow G \\rightarrow H \\rightarrow 1$ holds with the obvious\r\nembedding $n \\mapsto (n,1)$ and $h \\mapsto (1,h)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Put $(n,h)^{-1}= \\theta^{-1}[n^{-1} f(h,h^{-1})^{-1}], h^{-1})$.\r\n$(n,h)^{-1} \\cdot (n,h)= (1,1)$.   $(n,h) \\cdot (1,1)= (n,h)$.  Associativity is a long\r\ncalculation but works.\r\n\\end{quote}\r\n{\\bf Definition 2:}\r\nA subset ${\\cal T}$ consisting of a representative of each coset\r\nin $G/K$ is called a \\emph{transversal}. \r\n\\\\\r\n\\\\\r\n{\\bf Definition 3:}\r\nIf $\\pi: G \\rightarrow Q$ is a surjective homomorphism with kernel\r\n$K$, $l: Q \\rightarrow G$ is a \\emph{lifting} if $\\pi(l(x))=x$.\r\nIf $\\pi: Q \\rightarrow G$ is a surjective homomorphism with\r\nkernel $K$ and $l:Q \\rightarrow G$ is a transversal with $l(1)=0$ then\r\n$f: Q \\times Q \\rightarrow K$ defined by $l(x)+l(y)= f(x,y) + l(xy)$ is\r\ncalled a \\emph{factor set}.  An ordered triple, $(Q, K, \\theta)$ is called \\emph{data}\r\nif $K$ is an abelian group, $\\theta: Q \\rightarrow Aut(K)$; a group $G$ is said to\r\n\\emph{realize} the data if $G$ is and extension of $K$ by $Q$ and for every transversal,\r\n$l: Q \\rightarrow G$ satisfies $xa = \\theta_x(a)\r\n= l(x) +a-l(x)$.  Note additive notation for non-abelian operation.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 2:}\r\nLet $G$ be an extension of $K$ by $Q$ and\r\n$l: Q \\rightarrow G$ a transversal.  If $K$ is abelian there is a homomorphism\r\n$\\theta: Q \\rightarrow Aut(K)$ with $\\theta(a)= l(x)+a-l(x), \\forall a \\in K$;\r\nIf $l_1: Q \\rightarrow G$ is another transversal then\r\n$ l(x)+a-l(x)= l_1(x)+a-l_1(x)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$K \\lhd G$ so $\\gamma_{g|K}$ is an automorphism of $K$ ($\\gamma_g$ is conjugation by $g$).\r\n$\\mu: G \\rightarrow Aut(K)$ given by $\\mu(g)= \\gamma_g$ is a homomorphism with\r\n$K \\leq ker(\\mu)$.  $\\mu$ induces a homomorphism $\\mu_{\\#}: G/K \\rightarrow Aut(K)$ given by\r\n$\\mu_{\\#}(Kg)= \\mu(g)$.\r\nThe first isomorphism theorem gives the isomorphism $\\lambda: Q \\rightarrow G/K$ and if\r\n$l:Q \\rightarrow G$ is a transversal $\\lambda(x)=K+l(x)$.\r\nIf $l_1: Q \\rightarrow G$ is another transversal then $l(x) - l_1(x) \\in K$ so\r\n$ K+l(x)= K+l_1(x), \\forall x \\in Q $.  Thus $\\lambda$ does not depend on the choice of transversal.\r\nPut $\\theta= \\mu_{\\#} \\lambda$.  $\\theta_x = \\mu_{\\#}(K+l(x))= \\mu(l(x)) \\in Aut(K)$ so for $a \\in K:\r\n\\theta_x(a)= \\mu(l(x))(a)= l(x)+a-l(x)$.\r\n\\end{quote}\r\n{\\bf Theorem 3:}\r\nLet $\\pi: G \\rightarrow Q$ be a surjective homomorphism with kernel $K$ and\r\n$l:Q \\rightarrow G$ be a transversal with $l(1)=0$ and $f: Q \\times Q \\rightarrow K$ the corresponding\r\nfactor set.  $f(1,y)=0=f(x,1), \\forall x,y \\in Q$ and \r\nthe \\emph{cocycle identity} $xf(y,z)-f(xy,z)+f(x,yz)-f(x,y)=0$ holds $\\forall x,y,z \\in Q$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nDefinition gives $l(x)+l(y)= f(x,y)+l(xy)$.\r\nSo $l(1)+l(y)= f(1,y)+l(y)$ and since $l(1)=0$, $f(1,y)= 0$.  Similarly, $f(x,1)=0$.\r\n$[l(x)+l(y)]+l(z)= f(x,y)+f(xy,z)+l(xyz)$ and\r\n$l(x)+[l(y)+l(z)]= xf(y,z)+f(x,yz)+l(xyz)$.\r\n\\end{quote}\r\n{\\bf Theorem 4:}\r\nLet $G$ realize $(Q, K, \\theta )$ and $l$ and $l'$ be transversals with\r\n$l(1)=l'(1)=0$ giving rise to factor sets $f$ and $f'$ then there is an\r\n$h:Q \\rightarrow K$ with $h(1)=0$ such that \r\n$f'(x,y)-f(x,y)= xh(y)-h(xy)+h(x), \\forall x,h \\in Q$.\r\nThe \\emph{cocycle identity} $xf(y,z)-f(xy,z)+f(x,yz)-f(x,y)=0$ holds $\\forall x,y,z \\in Q$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy definition, \r\n$l(x) + l(y)= f(x,y) + l(xy)$\r\nand\r\n$l(1) + l(y)= f(1,y) + l(xy)$; since $l(1)=0$, this gives $f(1,y)=0$ similarly $f(x,1)=0$.\r\n$[l(x)+l(y)]+l(z) = f(x,y)+f(xy,z)+l(xyz)$ and\r\n$l(x)+[l(y)+l(z)] = xf(y,z)+l(xy)+l(z)= xf(y,z)+f(xy,z)+l(xyz)$ so the result follows from associativity.\r\n\\end{quote}\r\n{\\bf Definition:}  Given data $(Q, K, \\theta)$ a \\emph{coboundary} is a function\r\n$g: Q \\times Q \\rightarrow K$ for which $\\exists h: Q \\rightarrow K$ such that\r\n$h(1)=0$ and $g(x,y)= xh(x)-h(xy)+h(x)$.\r\nThe set of all coboundaries is $B^2 (Q,K,\\theta)$.\r\n$Z^2 (Q, K, \\theta)$ is the set of all \\emph{ factor sets}.\r\n$H^2 (Q, K, \\theta) \\cong Z^2 (Q, K, \\theta) / B^2 (Q, K, \\theta)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 5:} \r\nGiven data $(Q, K, \\theta)$ a function $f: Q \\times Q \\rightarrow K$ is a factor set iff it satisfies the\r\ncocycle identity.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThe $\\rightarrow$ direction is the previous theorem.  For $\\leftarrow$, let $G$ be the set of all ordered pairs,\r\n$(a,x) \\in K \\times Q$ with the operation\r\n$(a,x)+(b,y)= (a+xb+f(x,y), xy)$.  This is a group with the cocycle identity required for associativity.\r\n\\end{quote}\r\n{\\bf Notation:} Denote the $G$ constructed in the previous proof as $G_f$ realizing\r\n$(Q, K, \\theta )$ with factor set $f$ arising from $l(x)= (0,x)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nTwo extensions $G, G'$ realizing\r\n$(Q, K, \\theta )$ with factor sets $f, f'$ are \\emph{equivalent} if $f'-f \\in B^2(Q, K, \\theta)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 6:}\r\nTwo extensions are equivalent if the difference of\r\ntheir two factor sets is in $B^2 (Q, K, \\theta)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFor each $x \\in Q$, $l(x)$ and $l'(x)$ are representatives of the same coset\r\nof $K$ in $G$.  Thus $\\exists h(x) \\in K$ with $l'(x)= h(x) + l(x)$.  Since\r\n$l'(1)= 0 = l(1)$, $h(1) = 0$.  We have\r\n$l'(x) + l'(y) =\r\n(h(x) + l(x)) +\r\n(h(y) + l(y)) =\r\nh(x) + x h(y) + f(x, y) + l(xy) =\r\nh(x) + x h(y) + f(x, y) - h(xy) + l'(xy)$.  Therefore\r\n$f'(, y)= h(x) + x h(y) + f(x, y) - h(xy)$.  The conclusion follows since each term\r\nis in an abelian group.\r\n\\end{quote}\r\n{\\bf Theorem 7:}\r\nThere is a bijection from $H^2(Q,K,\\theta)$ to the set, $E$, of \r\nall equivalence classes realizing the data\r\n$(Q, K, \\theta )$ taking the identity to the class of the semidirect product.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet  the\r\nequivalence classes of the extensions realizing the data\r\n$(Q, K, \\theta )$ be denoted by \r\n$[G]$.  Define $\\varphi: H^2(Q, K, \\theta ) \\rightarrow E $ by $\\varphi(f+B^2(Q, K, \\theta))= G_f$.\r\n$\\varphi$ is well defined since if $f,g$ are factor sets, $f-g \\in\r\nB^2(Q, K, \\theta )$ and $[G_f]=[G_g]$. $\\varphi$ is a surjection since if\r\n$[G] \\in E$ and $f$ is a factor set, $[G]=[G_f]$ and $[G]= \\varphi(f+B^2)$.  Finally, an extension is a\r\nsemidirect product off its factor set is in $B^2(Q,K,\\theta)$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nA \\emph{projective representation} of a group $Q$ is a homomorphism\r\n$\\tau: Q \\rightarrow PGL_n({\\mathbb C})$.\r\nWe say $U$ has the \\emph{projective lifting property} if every projective representation\r\nof $Q$ can be lifted to $U$.\r\nIf $Q$ is a group then a \\emph{cover} (or \\emph{representation group}) of $Q$ is a\r\ncentral extension of $U$ of $K$ by $Q$ (for some abelian $K$) with the projective lifting property\r\nand $K \\le U'$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nThe \\emph {Schur multiplier} is\r\n$M(Q)=H^2 (Q, {\\mathbb C}^{\\times})$ ($\\theta$ is trivial).\r\nHere $f(1,y)=f(x,1)=1$, $f(x,y) f(xy,z)^{-1} f(x,yz) f(x,y)^{-1}=1$,\r\n$g: Q \\times Q \\rightarrow {\\mathbb C}^{\\times}$ is a coboundary\r\niff $\\exists h: Q \\rightarrow {\\mathbb C}^{\\times}$ with $h(1)=1$ such that\r\n$g(x,y)= h(y)(h(xy))^{-1}h(x)$.\r\n\\\\\r\n\\\\\r\n{\\bf Schur's Theorem:} Every finite group, $Q$, has a cover $U$ which is a central extension\r\nof $M(Q)$ by $Q$.\r\n\\begin{quote}\r\n\\emph{Proof:} See Rotman.\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$exp(G)= min \\{e: x^e = 1, \\forall x \\in G \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 8:} If $Q$ is finite then $M(Q)$ is a finite abelian group and\r\n$exp(M(Q)) \\mid |Q|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSee Rotman, p 201-211\r\n\\end{quote}\r\n{\\bf Theorem 9:} If $Q$ is finite $p$-group then $M(Q)$ is a finite abelian $p$-group.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSee, Rotman, p 202\r\n\\end{quote}\r\n{\\bf Theorem 10:} Let $G$ be a group with $G/{\\mathbb Z}(G)$ finite, then $G^{(1)}$ is finite.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $n= |G/{\\mathbb Z}(G)|$.  For $z \\in {\\mathbb 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 Observation:}\r\nA cyclic extension $G$ of $N$ is\r\none where $G/N$ is cyclic.  Solvable groups are built from cyclic extensions.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} \r\n$G$, an extension of $K$ by $Q$, is a \\emph{central extension} if $K<{\\mathbb Z}(G)$.  Functorially,\r\na central extension $G$ is a pair $(H, \\pi)$ satisfying\r\n$\\pi: H \\rightarrow G, ker(\\pi) \\subseteq {\\mathbb Z}(H)$.  \r\n$\\alpha: (H_1 , \\pi_1) \\rightarrow (H_2, \\pi_2)$ is a morphism in this category. \r\nThe universal object in this category (if it exists) is called a \r\n\\emph{universal central extension}.\r\nIt follows that $(\\tilde{G}, \\tilde{\\pi})$ is universal if \r\n$\\forall (H, \\sigma), \\exists ! \\alpha : (\\tilde{G}, \\tilde{\\pi}) \\rightarrow\r\n(H, \\sigma)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 11:} Up to isomorphism, there is at most one universal central extension.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nIf $(G_1, \\pi_i), i= 1, 2$ are universal central extensions of $G$, \r\n$\\exists \\alpha_1:(G_i, \\pi_i) \\rightarrow (G_{3-i}, \\pi_{3-i})$.\r\n$\\alpha \\alpha_{3-i} = 1$ and by the uniqueness $\\alpha_1 \\alpha_2 = 1 = \\alpha_2 \\alpha_1$.\r\nThus the $\\alpha_i$ is an isomorphism.\r\n\\end{quote}\r\n{\\bf Theorem 12:}   If $(\\tilde{G}, \\pi)$ is a universal central extension of $G$ then\r\nboth $G$ and $\\tilde{G}$ are perfect.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $H = \\tilde{G} \\times (\\tilde{G}/\\tilde{G}')$ and define $\\alpha: H \\rightarrow G$ by\r\n$\\alpha(x,y)= \\pi(x)$.   Then $(H, \\alpha)$ is a central extension of $G$ and\r\n$\\alpha_i: (\\tilde{G}, \\pi) \\rightarrow (H, \\alpha)$ are morphisms\r\nwhere $\\alpha_1(x)= (x,1)$ and $\\alpha_2(a)= (x, x \\tilde{G}')$.  By uniqueness,\r\n$\\alpha_1= \\alpha_2$, hence $\\tilde{G} = \\tilde{G}'$.  Thus $\\tilde{G}$ is perfect and so\r\n$G= \\pi(\\tilde{G})$.\r\n\\end{quote}\r\n{\\bf Theorem 13:}  Let $G$ be perfect and $H, \\pi$ be a central extension of $G$ then\r\n$H=ker(\\pi)H'$ with $H'$ perfect.\r\n\\begin{quote}\r\n\\emph{Proof:} $\\pi: H \\rightarrow G$, $\\pi(H')= \\pi(H)'=G'=G$ and $ker(\\pi) \\le {\\mathbb Z}(H)$.\r\n$H/H^2 = {\\mathbb Z}(H/H^2)= H'/H^2$ is abelian and $H'=H^2$ so $H'$ is perfect.\r\n\\end{quote}\r\n{\\bf Theorem 14:}\r\n$G$ possesses a universal central extension iff $G$ is perfect.\r\nIf $(\\tilde{G}, \\pi)$ is a universal central extension then $ker(\\pi)$ is called\r\nthe \\emph{Schur multiplier}.\r\n\\begin{quote}\r\n\\emph{Proof:}  $\\rightarrow$ is easy.  For the converse, suppose $G$ is perfect\r\n$g \\mapsto {\\overline g}$ is a bijection, $F$ the free group on the symbols of $G$,\r\n$\\Gamma= \\{ {\\overline x} {\\overline y} {\\overline x}^{-1} {\\overline y}^{-1}$.\r\n$M= \\langle \\Gamma \\rangle \\lhd F$, $\\Delta= \\{ [w,z], w \\in \\Gamma, z \\in G \\}$, \r\n$N= \\langle \\Delta \\rangle \\lhd F$.\r\n$N=[M,F] \\lhd M$, $M/N \\le {\\mathbb Z}(F/N)$.. $\\exists \\pi: F/N \\rightarrow G$\r\n$\\pi({\\overline x}N)= x$, $ker(\\pi) \\le {\\mathbb Z}(F/N)$.  Now let $H, \\sigma$ be any\r\ncentral extension.  $w= h(x) h(y) H(xy)^{-1} \\in ker(\\sigma)$.  $ker(\\sigma) \\le C_H(h(z))$\r\nand $[w,h(z)]=1$.  $\\tilde{G} =(F/N)'$ and $F/N = ker(\\pi) \\tilde{G}$; further,\r\n$\\tilde{G}' = \\tilde{G}$.  $(\\tilde{G}, \\pi)$ is a universal central extension.\r\n\\end{quote}\r\n{\\bf Note:} Quasisimple groups are exactly the central extensions of simple groups.  \r\n$H_2(G,{\\mathbb Z}) = {\\frac {(R \\cap F')} {[F,R]}}$, further, if $Q$ is\r\nperfect then  $F'/[F,R]$ is a cover of $Q$. $SL_k(p)$ is a central extension of\r\n$PSL_k(p)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 15:}\r\nLet $(H, \\alpha)$ be a central extension of a group $G$ and $(K, \\beta)$ is a perfect\r\ncentral extension of $H$ then $(K, \\alpha \\beta )$ is a perfect central extension of\r\n$G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\alpha \\beta : K \\rightarrow G$ is surjective.  Let $x \\in ker(\\alpha \\beta)$ and\r\n$y \\in K$.  $\\beta(x) \\in ker( \\alpha ) {\\mathbb Z}(H)$, so \r\n$\\beta([x,y]) = [\\beta(x), \\beta(y)] =1$ and $[x,y] \\in ker ( \\beta ) \\le {\\mathbb Z}(K)$.\r\nThus $[ker( \\alpha \\beta ), K, K] = 1$ so $ker( \\alpha \\beta ) \\le  {\\mathbb Z}(K)$.\r\n\\end{quote}\r\n{\\bf Theorem 16:}\r\nLet $(H, \\alpha)$ and $(K, \\beta)$ be central extensions of $G$ with $K$ with\r\n$K$ perfect and $\\gamma: (H, \\alpha) \\rightarrow (K, \\beta)$ a morphism of central\r\nextensions, then $(H, \\alpha)$ is a central extension of $K$.\r\ncentral extension of $H$ then $(K, \\beta \\alpha)$ is a perfect central extension of\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\gamma: H \\rightarrow K$ is a homomorphism with $\\alpha = \\beta \\gamma$.\r\n$ker( \\gamma ) \\le {\\mathbb Z}(H)$ so all we have to show is that $\\alpha$ is surjective.\r\n$K= \\gamma (H) ker( \\beta )$.  $ker( \\beta ) \\le {\\mathbb Z}(H)$,\r\n$\\gamma(H) \\lhd K$ and $K/ {\\mathbb Z}(H)$ is abelian and thus $K= \\gamma(H)$ is perfect.\r\n\\end{quote}\r\n{\\bf Theorem 17:}\r\nLet $\\tilde{G}$ be the covering group of a perfect group $G$ and let $(H, \\alpha)$ be\r\na perfect central extension of $\\tilde{G}$, then $\\alpha$ is an isomorphism.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\pi : \\tilde{G} \\rightarrow G$ be the universal covering.  By previous result,\r\n$H( \\pi \\alpha)$ is a perfect central extension of $G$.  By universality,\r\n$\\exists \\beta: ( \\tilde{G}, \\pi) \\rightarrow (H, \\pi \\alpha )$.  By uniqueness,\r\n$\\pi \\alpha \\beta = \\pi$, $\\alpha \\beta = 1$ and $\\beta: \\tilde{G} \\rightarrow H$ is\r\nan injection.  By previous result, $\\beta$ is surjective.  Thus $\\beta$ is an isomorphism,\r\n$\\alpha \\beta = 1$, $\\alpha = \\beta^{-1}$ is an isomorphism too.\r\n\\end{quote}\r\n{\\bf Theorem 18:}\r\nLet $G$ be perfect and $(\\tilde{G}, \\pi)$ the universal central extension of $G$ and\r\n$(H, \\sigma)$ a perfect central extension of $G$.  Then:\r\n(1) There exists a covering $\\alpha: \\tilde{G} \\rightarrow H$ with $\\pi = \\alpha \\sigma$;\r\n(2) $(\\tilde{G}, \\alpha)$ is the universal central extension of $H$;\r\n(3) The Schur multiplier of $H$ is a subgroup of the Schur multiplier of $G$;\r\n(4) if ${\\mathbb Z}(G)=1$ then ${\\mathbb Z}(\\tilde{G})$ is the Schur multiplier of $G$\r\nand ${\\mathbb Z}(H) \\cong ker(\\pi)/ker(\\alpha)$ is the quotient of the Schur multiplpier of\r\n$G$ by the Schur multiplier of $H$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy the universal property, $\\exists \\alpha: (\\tilde{G}, \\pi) \\rightarrow (H, \\sigma)$.\r\n$\\alpha$ is a covering by previous result.  Let $(\\tilde{H}, \\beta )$ be the universal covering\r\nof $H$.  By the universal property, \r\n$\\exists \\gamma: (\\tilde{H}, \\beta ) \\rightarrow (\\tilde{G}, \\alpha)$.  By previous result,\r\n$\\gamma$ is an isomorphism so (2) holds.  (3) and (4) are routine.\r\n\\end{quote}\r\n{\\bf Theorem 19:}\r\nLet $G$ be a group with $G/{\\mathbb Z}(G)$ finite then $G'$ is finite.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $n=|G/{\\mathbb Z}(G)|$, $z \\in {\\mathbb Z}(G)$, $g, h \\in G$.\r\n$[g, hz]= [g,h]= [gz, h]$ so the set $\\Delta$ of commutators has order $\\le n^2$.\r\n\\\\\r\n\\emph{Claim:} If $g \\in G'$ then $g= x_1 x_2 \\ldots x_m$, $x_i \\in \\Delta$ then $m \\le n^3$. \r\nThis and the previous statement proves the theorem.\r\n\\\\\r\n\\emph{Proof of Claim:} Pick expression of minimal length, $m$.  If $m > n^3$ then,\r\nsince $|\\Delta| \\le n^2$, $\\exists d \\in \\Delta$ with $\\Gamma= \\{i: x_i=d \\}$\r\nof order $k > n$.\r\n$x_i x_{i+1}= x_{i+1} x_i^{x_{i+1}}$\r\n$x_i^{x_{i+1}} \\in \\Delta$ and $\\Gamma= \\{ 1 \\le i \\le n \\}$.\r\nNow it STS, $d^{n+1}$ is  a product of $n$ commutators which contradicts the minimality of\r\n$m$.  Let $d= [x,y]$, $|G/{\\mathbb Z}(G)|=n$, $d^n \\in {\\mathbb Z}(G)$ so\r\n$d^{n+1}= (d^n)^x d= (d^{n-1})^x d^x d = (d^x)^{n-1} [x^2 , y]$ so $d$ is a product of $n$\r\n commutators.\r\n\\end{quote}\r\n{\\bf Theorem 20:}\r\nLet $G$ be a perfect finite group then the universal covering group of $G$ and the Schur\r\nmultiplier are both finite.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFollows from previous result.\r\n\\end{quote}\r\n{\\bf Theorem 21:}\r\nLet $(H, \\sigma)$ be a perfect central extension of a finite group, $G$,\r\nand $M$ the Schur multiplier of $G$, $p$,\r\na prime and $P \\in S_p(H)$ then $P \\cap ker(\\sigma) \\le \\Phi(P)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy looking at $H / (\\Phi(P) \\cap ker( \\sigma )$, we can assume $\\Phi(P) ker( \\sigma )=1$\r\nand show $X= P \\cap ker( \\sigma ) = 1$.  ${\\overline P}= P/\\Phi(P)$ is elementary\r\nabelian so $\\exists {\\overline Y}: {\\overline Y} {\\overline X}= {\\overline P}$,\r\n$P = X \\times Y$ and $P$ splits by Gaschutz, $H$ splits over $X$ hence, $H$ is perfect,\r\n$X \\le {\\mathbb Z}(H)$, $X=1$.\r\n\\end{quote}\r\n{\\bf Theorem 22:}\r\nLet $(H, \\sigma)$ be a perfect finite group and $M$ the Schur multiplier of $G$,\r\nthen $\\pi(M) \\subseteq \\pi(G)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFollows from previous result.\r\n\\end{quote}\r\n{\\bf Homological version:} If $G>N$\r\nand $H>K$ are normal subgroups isomorphic under $\\phi$, the pullback\r\nis $(g, h)$ where $gN= \\phi(hK)$.\r\n$(Q, K, \\theta)$ is trivial iff every extension realizing $(Q, K, \\theta)$\r\nis a central extension.  There's a bijection between $H^2 (Q, K, \\theta)$\r\nand central extensions. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem 23:}\r\nAssume $G$ is perfect then a central extension\r\n$(E, \\phi)$ of $G$ is universal iff (a) $E$ is perfect and (b) all \r\ncentral extensions of $E$ are trivial. In that case,\r\n$1 \\rightarrow R \\rightarrow F \\rightarrow G \\rightarrow 1$, $F$, free and\r\n$E= [F,F][F,R] \\rightarrow [F,F]/R=G$.\r\n\\begin{quote}\r\n\\end{quote}\r\n", "meta": {"hexsha": "4a8abed196d7f28c39cf0dead2f8168311ae716b", "size": 18848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtExtensions.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/gtExtensions.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/gtExtensions.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.4524421594, "max_line_length": 113, "alphanum_fraction": 0.607385399, "num_tokens": 7147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938819, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6805866742717342}}
{"text": "\\documentclass{article}\n\n\\usepackage{siunitx,amsmath,amssymb}\n\n\\title{Elastic Properties of Mountains}\n\\author{Matthias J. Raives}\n\n\\begin{document}\n  \n  \\maketitle{}\n  \n  \\section{Elastic Limit of Rock}\n  The simplest theory of mountains suggests that the maximum height is the height that makes the pressure at the base of the mountain equal to the elastic limit---if the mountain is taller than this, then the base will deform inelastically and the mountain will sink.  This sets a limit:\n  \\begin{equation}\n    P =\\rho g h\\\\\n  \\end{equation}\n  where $P$ is the elastic limit of the rock, measured in pressure units.  Mount Everest has a height of about \\SI{8}{\\km}, and rock has a density of about \\SI{3}{\\gram\\per\\cm\\cubed}.  Thus, the elastic limit of rock is:\n  \\begin{equation}\n    P = \\SI{2.4e8}{\\Pa} = \\SI{2.4e9}{dyne\\per\\cm\\squared}\n  \\end{equation}\n  \\section{Mars' Mons}\n  Applying this limit to other solar system bodies, we could write a scaling relation\n  \\begin{align}\n    h_{\\max} &= \\SI{8}{\\km}\\;\\left(\\frac{g}{\\SI{e3}{\\cm\\per\\second\\squared}}\\right)^{-1}\\\\\n    h_{\\max} &= \\SI{8}{\\km}\\;\\left(\\frac{M}{M_{\\oplus}}\\right)^{-1}\\left(\\frac{R}{R_{\\oplus}}\\right)^{2}\n  \\end{align}\n  Mars has a mass $M_{\\mathrm{Mars}}\\sim0.1{M_{\\oplus}}$ and a radius $R_{\\mathrm{Mars}}\\sim0.5R_{\\oplus}$, thus implying:\n  \\begin{equation}\n    h_{\\max} = \\SI{20}{\\km}\n  \\end{equation}\n  which is pretty close to the actual height of Olympus Mons $(\\sim\\SI{25}{\\km})$\n  \\section{Spherical Bodies}\n  We can consider an aspherical asteroid as a spherical one with a really large mountain, of height comparable to the asteroid's radius, on one side.  Again, scaling to mountains on Earth:\n  \\begin{align}\n    g_{\\oplus}h_{\\max,\\oplus} &= g(R)R\\\\\n    \\frac{GM(R_{\\oplus})}{R_{\\oplus}^{2}}h_{\\max,\\oplus} &= \\frac{GM(R)}{R}\\\\\n    \\frac{4\\pi\\rho R_{\\oplus}}{3}h_{\\max,\\oplus} &= \\frac{4\\pi}{3}\\rho R^{2}\\\\\n    R &= \\sqrt{R_{\\oplus}h_{\\max,\\oplus}}\\\\\n    R &\\sim \\SI{230}{\\km}\n  \\end{align}\n  \n\\end{document}\n", "meta": {"hexsha": "159a7b24eef9f667e79f0ff807b23f30f3c53428", "size": 1999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mountains/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": "Mountains/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": "Mountains/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": 46.488372093, "max_line_length": 287, "alphanum_fraction": 0.667833917, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6805651284470112}}
{"text": "% !TeX root = ./main.tex\n% chktex-file 46\n% !TeX spellcheck = en-GB\n% !TeX encoding = utf8\n\n\\section{Consistency of notations}%\n\\label{sec:consistency}\n\nUsing the notation from the blog and the paper, including $H'\\in\\mathbb{R}^{N\\times D}$, $A\\in\\mathbb{R}^{N\\times N}$, $H\\in\\mathbb{R}^{N\\times D}$, the propagation rule is:\n\n\\begin{equation}\n\tH' = A H\n\\end{equation}\n\nis equivalent to\n\n\\begin{equation}\n\t\\begin{split}\n\t\tH'_{v_i, m} & = \\sum_l \\overbrace{A_{v_i, l}}^{\\in \\{0, 1\\}} H_{l, m} \\\\\n\t\t            & = \\sum_{l'} H_{l',m}\n\t\\end{split}\n\\end{equation}\n\nwhere $l'$ takes all $A_{v_i,l}=1$, i.e.\\ neighbours, into account.\n\nHence, I do understand that the notations are equal.\n\n\\section{Formulate normalisation}\n\nUse from ICLR 2017 paper the normalisation $D_{ii} = \\sum_j \\hat{A}_{ij}$.\n\nUse the knowledge from the blog post to write:\n\n\\begin{equation}\n\t\\begin{split}\n\t\t\\overbrace{H'}^{\\in \\mathbb{R}^{N\\times D}} & = \\overbrace{D^{-1}}^{\\in\\mathbb{R}^{N\\times N}} \\overbrace{\\hat{A}}^{\\in \\mathbb{R}^{N\\times N}} \\overbrace{H}^{\\in\\mathbb{R}^{N\\times D}} \\\\\n\t\t\\Leftrightarrow H'_{v_i, m} & = \\sum_k \\overbrace{D^{-1}_{v_i,k}}^{=D_{v_i,v_i}, \\delta_{v_i, k}} {(\\hat{A} H)}_{km} \\\\\n\t\t\t& = D^{-1}_{v_i, v_i} {(\\hat{A} H)}_{v_i, m} \\\\\n\t\t\t& = D^{-1}_{{v}_i, v_i} \\sum_k \\hat{A}_{v_i, k} H_{k, m} \\\\\n\t\t\t& = \\sum_k \\underbrace{\\frac{\\hat{A}_{v_i, k}}{\\sum_j \\hat{A}_{v_i, j}}}_{\\text{normalised}} H_{k, m}.\n\t\\end{split}\n\\end{equation}\n\nThe weighting by the adjacency matrix is, indeed, normalised to its column sums.\n\nNote that this part is also normalised:\n\n\\begin{equation}\n\\begin{split}\n\t\\sum_m H'_{v_i, m} & = \\sum_m \\sum_k \\frac{\\hat{A}_{v_i, k}}{\\sum_j \\hat{A}_{v_i, j}} H_{k, m} \\\\\n\t& = \\sum_k \\frac{\\hat{A}_{v_i, k}}{\\sum_j \\hat{A}_{v_i, j}} \\underbrace{\\sum_m H_{k,m}}_{=1\\text{, per construction}} \\\\\n\t& = 1\n\\end{split}\n\\end{equation}\n\n\\newpage\n\\raggedright{}\n\\bibliography{bibliography}", "meta": {"hexsha": "33ea80e1ec4632b37836b6ad2fe82f8ce1f5fe47", "size": 1899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sections/appendix.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/sections/appendix.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/sections/appendix.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": 32.7413793103, "max_line_length": 190, "alphanum_fraction": 0.6234860453, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571775, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6805651152757192}}
{"text": "\\chapter{Bag of Words}\n\n\\newthought{Every machine learning needs numbers, but all we have is text.} A simple way to convert documents into numeric vectors is to \\dots well, count the words in each text.\n\n\\begin{center}\n    \\begin{tabular}{c|c|c|c|c|c|c}\n    Document & this & is & an & example & another & apple \\\\\n    \\hline\n    \\emph{This is an example} & 1 & 1 & 1 & 1 & 0 & 0 \\\\ \n    \\emph{Another example} & 0 & 0 & 0 & 1 & 1 & 0 \\\\  \n    \\emph{This is another apple} & 1 & 1 & 0 & 0 & 1 & 1    \n    \\end{tabular}\n\\end{center}\n\n\\widget{Bag of Words} creates a table with words in columns and documents in rows. Values are word frequencies in each document.\n\n\\begin{wrapfigure}{o}{0.6\\textwidth}\n    \\includegraphics[scale=0.5]{bag-of-words.png}\n    \\caption{$\\;$}\n\\end{wrapfigure}\n\nWe can simply count the words (TF or term frequency) or weigh the words according to how often they appear in the documents (IDF or inverse document frequency). Using TF-IDF, common words will have a low value as they appear across most documents, while significant words will have a high value because they appear frequently in a small number of documents.\n\nPass the data through a \\widget{Bag of Words} widget and then again to a \\widget{Data Table}. We get a new column that contains word counts for each document. Now that we have numbers, we can finally perform some magic!\n\n\\vspace{-0.2cm}\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=\\linewidth]{workflow.png}%\n  \\caption{$\\;$}\n\\end{figure}\n\\vspace{-0.3cm}\n\n\\vspace{-0.2cm}\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=1.2\\linewidth]{data-table.png}%\n  \\caption{$\\;$}\n\\end{figure}\n\\vspace{-0.3cm}", "meta": {"hexsha": "d8250f8c7e5e926b146a7d31429d929c3dc12c92", "size": 1662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/text-012-bag-of-words/bag-of-words.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/text-012-bag-of-words/bag-of-words.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/text-012-bag-of-words/bag-of-words.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": 41.55, "max_line_length": 357, "alphanum_fraction": 0.7009626955, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6805651102115469}}
{"text": "\\chapter{Probability and Statistics}\n\\label{chap:Probability and Statistics}\nOne role for the distributions is to model the probability distribution $p(\\vec{x})$ of a random variable $x$,given a finite set of observations.This problem is known as \\textbf{density estimation}.We shall assume that the data points are independent and identically distributed.\n\n\\textbf{Parameter} distributions are governed by a small number of adaptive parameters,such as the mean and variance in the case of a Gaussian for example.In a frequentist treatment, we choose specific values for the parameters by optimizing some criterion, such as the likelihood function. By contrast, in a Bayesian treatment we introduce prior distributions over the parameters and then use Bayes’ theorem to compute the corresponding posterior distribution given the observed data.\n\nAn important role is played by \\textbf{conjugate priors},that lead to posterior distributions having the same functional form as the prior,and that therefore lead to a greatly simplified Bayesian analytics.\n\n\\textbf{Nonparametric} density estimation methods in which the form of the distribution typically depends on the size of the data set.Parameters in such models control the model complexity rather than the form of the distribution.We cover three nonparametric methods based respectively on histograms,nearest-neighbours,and kernels.\n\n\\section{Frequentists vs. Bayesians}\nThere are two different interpretations of probability.\nOne is called the \\textbf{frequentist} interpretation. In this view, probabilities represent long run \\textbf{frequencies} of events. For example, the above statement means that, if we flip the coin many times, we expect it to land heads about half the time.\n\nThe other interpretation is called the \\textbf{Bayesian} interpretation of probability. In this view, probability is used to quantify our \\textbf{uncertainty} about something; hence it is fundamentally related to information rather than repeated trials (Jaynes 2003). In the Bayesian view, the above statement means we believe the coin is equally likely to land heads or tails on the next toss\n\nOne big advantage of the Bayesian interpretation is that it can be used to model our uncertainty about events that do not have long term frequencies. For example, we might want to compute the probability that the polar ice cap will melt by 2020 CE. This event will happen zero or one times, but cannot happen repeatedly. Nevertheless,we thought to be able to quantify our uncertainty about this event. To give another machine learning oriented example, we might have observed a “blip” on our radar screen, and want to compute the\nprobability distribution over the location of the corresponding target (be it a bird, plane, or missile). In all these cases, the idea of repeated trials does not make sense, but the Bayesian interpretation is valid and indeed quite natural. We shall therefore adopt the Bayesian interpretation in this book. Fortunately, the\nbasic rules of probability theory are the same, no matter which interpretation is adopted.\n\n\n\\section{probability theory}\n\n%\\subsection{Basic concepts}\n\\subsection{Concepts}\nThe expression $p(A)$ denotes the probability that event A is true.We require that $0\\leq p(A) \\leq 1$,where 0 means the event definitely will not happen,and $p(A)=1$ means the event definitely will happen.$p(\\hat{A})$ denotes the probability of the event not A;this is defined to be $p(\\hat{A})=1-p(A)$.\n\nWe denote a random event by defining a \\textbf{random variable} $X$.\n\n\\textbf{Descrete random variable}: $X$ ,which can take on any value from a finite or countably infinite set .We denote the probability of the event that $X=x$ by $p(X=x)$,or just $p(x)$ for short.Here $p()$ is called a \\textbf{probability mass function} or \\textbf{pmf}.The pmfs are defined one \\textbf{state space}.$\\mathbb{I}$ denotes the binary \\textbf{indicator funcition}.\n\n\\textbf{Continuous random variable}: the value of $X$ is real-valued.\n\n\n\\begin{description}\n\\item[\\textbf{probability}] Probability is the measure of the likeliness that an event will occur.\n\\item[\\textbf{conditional probability}] A conditional probability measures the probability of an event given that (by assumption, presumption, assertion or evidence) another event has occurred.\n\\item[\\textbf{joint probability}] Joint probability is a measure of two events happening at the same time, and can only be applied to situations where more than one observation can be occurred at the same time.\n\\item[\\textbf{prior probability distribution}]\nIn Bayesian statistical inference, a prior probability distribution, often called simply the prior, of an uncertain quantity p is the probability distribution that would express one's uncertainty about p \\textbf{before} some evidence is taken into account.\n\n\\item[\\textbf{posterior probability distribution}]\nIn Bayesian statistics, the posterior probability of a random event or an uncertain proposition is the \\textbf{conditional probability} that is assigned \\textbf{after} the relevant evidence or background is taken into account.\n\n\\item[\\textbf{likelihood function}]\nIn statistics, a likelihood function (often simply the likelihood) is a function of the parameters of a statistical model.The likelihood of a set of parameter values, θ, given outcomes x, is equal to the \\textbf{probability}  or \\textbf{probability desity} of those observed outcomes given those parameter values.\n\\end{description}\n\n\\subsection{Fundamental rules}\nIn this section,we review the basic rule of probability.\n\\subsubsection{Probability of a union of two events}\nGiven two events,$A$ and B,we define the probability of A or B as follows:\n\\begin{align}\np(A\\cup B)& = p(A) + p(B) - p(A\\cap B)\t\\\\\n\t\t  & = p(A) + p(B)\n\\end{align}\nif A and B are mutually independent \n\n\n\\subsubsection{Joint probabilities}\nWe define the probability of the joint event A and B as follows:\n\\begin{equation}\np(A,B) = p(A\\cap B) = p(A|B)p(B)\n\\end{equation}\nThis is sometimes called the \\textbf{product rule}\n\\subsubsection{Conditional probability}\nDefine the \\textbf{conditional probability} of event A,given that event B is true,as follows:\n\\begin{equation}\np(A|B)= \\frac{p(A,B)}{p(B)},if p(B) > 0\n\\end{equation}\n\n\\subsubsection{sum rule}\n\\begin{equation}\np(X) = \\sum_{Y}p(X,Y)\n\\end{equation}\n\n\\subsubsection{product rule}\n\\begin{align}\np(X,Y) &= p(Y|X)p(X) \\\\\np(A,B|C) &= p(A|C)p(B|AC) = p(B|C)p(A|BC)\n\\end{align}\n\\begin{proof}\n\t$p(X,Y) = p(Y|X)p(X)$ is by definition.\n\t\\begin{align}\n\t\tp(A,B|C) &= \\dfrac{p(A,B,C)}{p(C)} \\\\\n\t\t&=\\dfrac{p(A,C)p(B|A,C)}{p(C)}\\\\\n\t\t&=p(A|C)p(B|A,C)\n\t\\end{align}\n\t\t\\begin{align}\n\t\tp(C|A,B) &= \\dfrac{p(A,B,C)}{p(A,B)} \\\\\n\t\t&=\\dfrac{\\dfrac{p(A,B,C)}{p(B)}}{\\dfrac{p(A,B)}{p(B)}}\\\\\n\t\t&=\\dfrac{p(A,C|B)}{p(A|B)}\n\t\t\\end{align}\n\\end{proof}\n\n\\subsubsection{CDF}\n\\begin{equation}\nF(x) \\triangleq P(X \\leq x)=\\begin{cases}\n\\sum_{u \\leq x}p(u) & \\text{, discrete}\\\\\n\\int_{-\\infty}^{x} f(u)\\mathrm{d}u & \\text{, continuous}\\\\\n\\end{cases}\n\\end{equation}\n\n\n\\subsubsection{PMF and PDF}\nFor descrete random variable, We denote the probability of the event that $X=x$ by $P(X=x)$, or just $p(x)$ for short. Here $p(x)$ is called a \\textbf{probability mass function} or \\textbf{PMF}.A probability mass function is a function that gives the probability that a discrete random variable is exactly equal to some value\\footnote{\\url{http://en.wikipedia.org/wiki/Probability_mass_function}}. This satisfies the properties $0 \\leq p(x) \\leq 1$ and $\\sum_{x \\in \\mathcal{X}} p(x)=1$.\n\nFor continuous variable, in the equation $F(x)=\\int_{-\\infty}^{x} f(u)\\mathrm{d}u$, the function $f(x)$ is called a \\textbf{probability density function} or \\textbf{PDF}. A probability density function is a function that describes the relative likelihood for this random variable to take on a given value\\footnote{\\url{http://en.wikipedia.org/wiki/Probability_density_function}}.This satisfies the properties $f(x) \\geq 0$ and $\\int_{-\\infty}^{\\infty} f(x)\\mathrm{d}x=1$.\n\n\\subsubsection{probability densities}\nprobability densities\n\\begin{equation}\np(x\\in (a,b)) = \\int_{a}^{b}p(x)dx\n\\end{equation}\nThe probability density function p(x) must satisfy the two conditions\n\\begin{equation}\n\\begin{cases}\np(x) \\geq 0               \\\\\n\\int_{-\\infty}^{\\infty}p(x)dx = 1\n\\end{cases}\n\\end{equation}\n\nCombinations of discrete and continuous variables.\n\\begin{equation}\np(x) = \\int_p(x,y)dy\t\n\\end{equation}\n\\begin{equation}\np(x,y) = p(y|x)p(x)\n\\end{equation}\n\n\n\n\\subsection{Mutivariate random variables}\n\n\n\\subsubsection{Joint CDF}\nWe denote joint CDF by $F(x,y) \\triangleq P(X \\leq x \\cap Y \\leq y)=P(X \\leq x , Y \\leq y)$.\n\n\\begin{equation}\nF(x,y) \\triangleq P(X \\leq x, Y \\leq y)=\\begin{cases}\n\\sum_{u \\leq x, v \\leq y}p(u,v) \\\\\n\\int_{-\\infty}^{x}\\int_{-\\infty}^{y} f(u,v)\\mathrm{d}u\\mathrm{d}v \\\\\n\\end{cases}\n\\end{equation}\n\n\\textbf{product rule}:\n\\begin{equation}\\label{eqn:product-rule}\np(X,Y)=P(X|Y)P(Y)\n\\end{equation}\n\n\\textbf{Chain rule}:\n\\begin{equation}\np(X_{1:N})=p(X_1)p(X_3|X_2,X_1)...p(X_N|X_{1:N-1})\n\\end{equation}\n\n\n\\subsubsection{Marginal distribution}\n\\textbf{Marginal CDF}:\n\\begin{equation}\\begin{split}\nF_X(x) \\triangleq F(x,+\\infty)= \n& \\begin{cases}\n\\sum\\limits_{x_i \\leq x}P(X=x_i)=\\sum\\limits_{x_i \\leq x}\\sum\\limits_{j=1}^{+\\infty}P(X=x_i,Y=y_j) \\\\\n\\int_{-\\infty}^{x}f_X(u)du=\\int_{-\\infty}^{x}\\int_{-\\infty}^{+\\infty} f(u,v)\\mathrm{d}u\\mathrm{d}v \\\\\n\\end{cases}\n\\end{split}\\end{equation}\n\n\\begin{equation}\\begin{split}\nF_Y(y) \\triangleq F(+\\infty,y)= \n& \\begin{cases}\n\\sum\\limits_{y_j \\leq y}p(Y=y_j)=\\sum\\limits_{i=1}^{+\\infty}\\sum_{y_j \\leq y}P(X=x_i,Y=y_j) \\\\\n\\int_{-\\infty}^{y}f_Y(v)dv=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{y} f(u,v)\\mathrm{d}u\\mathrm{d}v \\\\\n\\end{cases}\n\\end{split}\\end{equation}\n\n\\textbf{Marginal PMF and PDF}:\n\\begin{equation} \\begin{cases}\nP(X=x_i)=\\sum_{j=1}^{+\\infty}P(X=x_i,Y=y_j) & \\text{, descrete}\\\\\nf_X(x)=\\int_{-\\infty}^{+\\infty} f(x,y)\\mathrm{d}y & \\text{, continuous}\\\\\n\\end{cases}\\end{equation}\n\n\\begin{equation}\\begin{cases}\np(Y=y_j)=\\sum_{i=1}^{+\\infty}P(X=x_i,Y=y_j) & \\text{, descrete}\\\\\nf_Y(y)=\\int_{-\\infty}^{+\\infty} f(x,y)\\mathrm{d}x & \\text{, continuous}\\\\\n\\end{cases}\\end{equation}\n\n\n\\subsubsection{Conditional distribution}\n\\textbf{Conditional PMF}:\n\\begin{equation}\np(X=x_i|Y=y_j)=\\dfrac{p(X=x_i,Y=y_j)}{p(Y=y_j)} \\text{ if } p(Y)>0\n\\end{equation}\nThe pmf $p(X|Y)$ is called \\textbf{conditional probability}.\n\n\\textbf{Conditional PDF}:\n\\begin{equation}\nf_{X|Y}(x|y)=\\dfrac{f(x,y)}{f_Y(y)}\n\\end{equation}\n\n\\subsection{Bayes rule}\n%\\begin{equation}\n%\\begin{split}\n%p(Y=y|X=x) & =\\dfrac{p(X=x,Y=y)}{p(X=x)} \\\\\n%           & =\\dfrac{p(X=x|Y=y)p(Y=y)}{\\sum_{y'}p(X=x|Y=y')p(Y=y')}\n%\\end{split}\n%\\end{equation}\n\nBayes' theorem\n\\begin{equation}\n                                  p(Y|X) = \\frac{p(X|Y)p(Y)}{p(X)}\n\\end{equation}\nDenominator in Bayes' theorem\n\\begin{equation}\n                                  p(X) = \\sum_Y{p(X|Y)p(Y)}\n\\end{equation}\n\nBayesian probabilities\nSo far, we have viewed probabilities in terms of the frequencies of random,repeatable events,which we shall refer to as the classical or frequentist interpretation of probability.Now we turn to the more general Bayesian view,in which probabilities provide a quantification of uncertainty.\n\nWe can adopt a similar approach when making inferences about quantities such as the parameters $\\mathbf{w}$ in the polynomial curve fitting.We capture our assumptions about \\textbf{w},before observing the data,in the form of a \\textbf{prior} probability distribution $p(\\mathbf{w})$.The effect of the observed data $\\mathcal{D} = {t_1,...,t_N}$ is expressed through the conditional probability $p(D|w)$.Bayes' theorem,which takes the form\n\\begin{equation}\np(\\textbf{w}|\\mathcal{D}) = \\frac{p(\\mathcal{D}|\\textbf{w})p(\\textbf{w})}{p(\\mathcal{D})}\n\\end{equation}\nthen allows us to evaluate the uncertainty in $\\vec{w}$ \\textbf{after} we have observed $\\mathcal{D}$ in the form of the \\textbf{posterior} probability $p(\\mathbf{w}|\\mathcal{D})$.\n\nThe quantity $p(D|w)$ on the right-hand side of Bayes' theorem is evaluated for the observed data set D and \ncan be viewed as a function of the parameter vector $\\mathbf{w}$,in which case it is called the \\textbf{likelihood function}.It expresses how probable the observed data set is for different settings of the parameter vector $\\vec{w}$.\n\\begin{equation}\nposteroir \\propto likelihood \\times prior\n\\end{equation}\nwhere all of these quantities are viewed as functions of $\\vec{w}$.\nSumming both side with respect to $\\mathbf{w}$\n\\begin{align}\n& p(\\mathcal{D})p(\\vec{w}|\\mathcal{D}) &= p(\\mathcal{D}|\\vec{w})p(\\vec{w}) \\\\\n&\\Rightarrow \\sum_{\\vec{w}}p(\\mathcal{D})p(\\vec{w}|\\mathcal{D}) &= \\sum_{\\vec{w}}p(\\mathcal{D}|\\vec{w})p(\\vec{w}) \\\\\n&\\Rightarrow p(\\mathcal{D})&= \\sum_{\\vec{w}}p(\\mathcal{D}|\\vec{w})p(\\vec{w}) \\\\\n\\end{align}\nIntegrating both side with respect to $\\mathbf{w}$\n\\begin{align}\n\\int p(\\mathcal{D})p(\\vec{w}|\\mathcal{D})d{\\vec{w}} &= \\int p(\\mathcal{D}|\\vec{w})p(\\vec{w}) d{\\vec{w}} \\\\ \np(\\mathcal{D}) &= \\int p(\\mathcal{D}|\\mathbf{w}) p(\\mathbf{w})d\\mathbf{w} \n \\end{align}\n\nA widely used frequentist estimator is \\textbf{maximum likelihood},in which $\\mathbf{w}$ is set to the value that maximizes the likelihood function $p(\\mathcal{D}|w)$.In the machine learning literature,the negative log of the likelihood function is called an \\textbf{error function}.\n\nOner approach to determining the frequentist error bars is the \\textbf{bootstrap},in which multiple data sets are created as follows.Suppose out original data set consists of $N$ data points.We can create a new data set $X_B$ by drawing $N$ points at random from $X$, with \\textbf{replacement}, so that some points in X may be replicated in XB, whereas other points in X may be absent from $X_B$. This process can be repeated L times to generate L data sets each of size N and each obtained by sampling from the original data set X. The statistical accuracy of parameter estimates can then be evaluated by looking at the variability of predictions between the different bootstrap data sets.\n\n\n\n\\subsection{Independence and conditional independence}\nWe say $X$ and $Y$ are unconditionally independent or marginally independent, denoted $X \\perp Y$, if we can represent the joint as the product of the two marginals, i.e.,\n\\begin{equation}\nX \\perp Y=P(X,Y)=P(X)P(Y)\n\\end{equation}\n\nWe say $X$ and $Y$ are conditionally independent(CI) given $Z$ if the conditional joint can be written as a product of conditional marginals:\n\\begin{equation}\nX \\perp Y|Z=P(X,Y|Z)=P(X|Z)P(Y|Z)\n\\end{equation}\n\n\\subsection{Quantiles}\nSince the cdf $F$ is a monotonically increasing function, it has an inverse; let us denote this by $F^{-1}$. If $F$ is the cdf of $X$ , then $F^{-1}(\\alpha)$ is the value of $x_{\\alpha}$ such that $P(X \\leq x_{\\alpha})=\\alpha$; this is called the $\\alpha$ quantile of $F$. The value $F^{-1}(0.5)$ is the \\textbf{median} of the distribution, with half of the probability mass on the left, and half on the right. The values $F^{-1}(0.25)$ and $F^{−1}(0.75)$are the lower and upper \\textbf{quartiles}.\n\n\\subsection{Mean and variance}\nThe most familiar property of a distribution is its \\textbf{mean},or \\textbf{expected value}, denoted by $\\mu$. For discrete rv’s, it is defined as $\\mathbb{E}[X] \\triangleq \\sum_{x \\in \\mathcal{X}}xp(x)$, and for continuous rv’s, it is defined as $\\mathbb{E}[X] \\triangleq \\int_{\\mathcal{X}}xp(x)\\mathrm{d}x$. If this integral is not finite, the mean is not defined (we will see some examples of this later). \n\nThe \\textbf{variance} is a measure of the “spread” of a distribution, denoted by $\\sigma^2$. This is defined as follows:\n\\begin{align}\nvar[X]& =\\mathbb{E}[(X-\\mu)^2] \\\\\n      & =\\int{(x-\\mu)^2p(x)\\mathrm{d}x} \\nonumber \\\\\n      & =\\int{x^2p(x)\\mathrm{d}x}+{\\mu}^2\\int{p(x)\\mathrm{d}x}-2\\mu\\int{xp(x)\\mathrm{d}x} \\nonumber \\\\\n\t  & =\\mathbb{E}[X^2]-{\\mu}^2\n\\end{align}\n\nfrom which we derive the useful result\n\\begin{equation}\n\\mathbb{E}[X^2]=\\sigma^2+{\\mu}^2\n\\end{equation}\n\nThe \\textbf{standard deviation} is defined as\n\\begin{equation}\nstd[X] \\triangleq \\sqrt{var[X]}\n\\end{equation}\n\nThis is useful since it has the same units as $X$ itself.\n\nExpectations and covariances\nThe average value of some function $f(x)$ under a probability distribution p(x) is called the expectation of f(x) and\nwill be denoted by \n\\begin{equation}\n                                  \\mathbb{E}[f] = \\sum_{x}p(x)f(x)\n                                  \\mathbb{E}[f] = \\int p(x)f(x)dx\n\\end{equation}\n\napproximation\n\\begin{equation}\n\\mathbb{E}[f] \\simeq \\frac{1}{N}\\sum_{n=1}^{N}{f(x_n)}\n\\end{equation}\n                                  \nconditional expectation with respect to a conditional distribution                                \n\\begin{equation}\n\\mathbb{E}_x[f|y] = \\sum_{x}p(x|y)f(x)\n\\end{equation}\n\nvariance of f(x) is defined by\n\\begin{equation}\nvar[f] = \\mathbb{E}[(f(x) - \\mathbb{E}[f(x)])^2\nvar[f] = \\mathbb{E}[f(x)^2]-\\mathbb{E}[f(x)]^2\n\\end{equation}\nconvariance \n\\begin{equation}\ncov[x,y] = \\mathbb{E}_{x,y}[\\{x- \\mathbb{E}[x]\\}\\{y-\\mathbb{E}[y]\\}]\n\\end{equation}\n\nIn the case of two vectors of random variables \\textbf{x} and \\textbf{y}\n\\begin{equation}\ncov[\\textbf{x},\\textbf{y}] = \\mathbb{E}_{x,y}[\\{\\textbf{x}-\\mathbb{E}[\\textbf{x}]\\} \\{ \\textbf{y}^T - \\mathbb{E}[\\textbf{y}^T ]\\}] \\\\\ncov[\\textbf{x},\\textbf{y}] = \\mathbb{E}_{x,y}[\\textbf{x}\\textbf{y}^T] - \\mathbb{E}[\\textbf{x}] \\mathbb{E}[\\textbf{y}^T]\n\\end{equation}\n\n\\section{Some common discrete distributions}\nIn this section, we review some commonly used parametric distributions defined on discrete state spaces, both finite and countably infinite.\n\n\n\\subsection{The Bernoulli and binomial distributions}\n\n\\begin{definition}\nNow suppose we toss a coin only once. Let $X \\in \\{0,1\\}$ be a binary random variable, with probability of “success” or “heads” of $\\theta$. We say that $X$ has a \\textbf{Bernoulli distribution}. This is written as $X \\sim \\text{Ber}(\\theta)$, where the pmf is defined as \n\\begin{equation}\n\\text{Ber}(x|\\theta) \\triangleq \\theta^{\\mathbb{I}(x=1)}(1-\\theta)^{\\mathbb{I}(x=0)}\n\\end{equation}\n\\end{definition}\n\n\n\\begin{definition}\nSuppose we toss a coin $n$ times. Let $X \\in \\{0,1,\\cdots,n\\}$ be the number of heads. If the probability of heads is $\\theta$, then we say $X$ has a \\textbf{binomial distribution}, written as $X \\sim \\text{Bin}(n, \\theta)$. The pmf is given by \n\\begin{equation}\\label{eqn:binomial-pmf}\n\\text{Bin}(k|n,\\theta) \\triangleq \\dbinom{n}{k}\\theta^k(1-\\theta)^{n-k}\n\\end{equation}\n\\end{definition}\n\n\n\\subsection{The multinoulli and multinomial distributions}\n\n\\begin{definition}\nThe Bernoulli distribution can be used to model the outcome of one coin tosses. To model the outcome of tossing a K-sided dice, let $\\vec{x} =(\\mathbb{I}(x=1),\\cdots,\\mathbb{I}(x=K)) \\in \\{0,1\\}^K$ be a random vector(this is called \\textbf{dummy encoding} or \\textbf{one-hot encoding}), then we say $X$ has a \\textbf{multinoulli distribution}(or \\textbf{categorical distribution}), written as $X \\sim \\text{Cat}(\\theta)$. The pmf is given by: \n\\begin{equation}\np(\\vec{x}) \\triangleq \\prod\\limits_{k=1}^K\\theta_k^{\\mathbb{I}(x_k=1)}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nSuppose we toss a K-sided dice $n$ times. Let $\\vec{x} =(x_1,x_2,\\cdots,x_K) \\in \\{0,1,\\cdots,n\\}^K$ be a random vector, where $x_j$ is the number of times side $j$ of the dice occurs, then we say $X$ has a \\textbf{multinomial distribution}, written as $X \\sim \\text{Mu}(n, \\vec{\\theta})$. The pmf is given by \n\\begin{equation}\\label{eqn:multinomial-pmf}\np(\\vec{x}) \\triangleq \\dbinom{n}{x_1 \\cdots x_k} \\prod\\limits_{k=1}^K\\theta_k^{x_k}\n\\end{equation}\nwhere $\\dbinom{n}{x_1 \\cdots x_k} \\triangleq \\dfrac{n!}{x_1!x_2! \\cdots x_K!}$\n\\end{definition}\n\nBernoulli distribution is just a special case of a Binomial distribution with $n=1$, and so is multinoulli distribution as to multinomial distribution. See Table \\ref{tab:multinomial-summary} for a summary.\n\n\\begin{table}\n\\caption{Summary of the multinomial and related distributions.}\n\\label{tab:multinomial-summary}\n\\centering\n\\begin{tabular}{llll}\n\\hline\\noalign{\\smallskip}\nName & K & n & X \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nBernoulli & 1 & 1 & $x \\in \\{0,1\\}$ \\\\\nBinomial & 1 & - & $\\vec{x} \\in \\{0,1,\\cdots,n\\}$ \\\\\nMultinoulli & - & 1 & $\\vec{x} \\in \\{0,1\\}^K, \\sum_{k=1}^K x_k=1$ \\\\\nMultinomial & - & - & $\\vec{x} \\in \\{0,1,\\cdots,n\\}^K, \\sum_{k=1}^K x_k=n$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table} \n\n\n\\subsection{The Poisson distribution}\nPoisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a \\textbf{fixed interval} of time and/or space if these events occur with a \\textbf{known average rate} and \\textbf{independently} of the time since the last event.\n\\begin{definition}\nWe say that $X \\in \\{0,1,2,\\cdots\\}$ has a \\textbf{Poisson distribution} with parameter $\\lambda>0$, written as $X \\sim \\text{Poi}(\\lambda)$, if its pmf is\n\\begin{equation}\np(x|\\lambda)=e^{-\\lambda}\\dfrac{\\lambda^x}{x!}\n\\end{equation}\n\\end{definition}\n\nThe first term is just the normalization constant, required to ensure the distribution sums to 1.\n\nThe Poisson distribution is often used as a model for counts of rare events like radioactive decay and traffic accidents. \n\n\\begin{table*}\n\\caption{Summary of Bernoulli, binomial multinoulli and multinomial distributions.}\n\\label{tab:Summary-distribution}\n\\centering\n\\begin{tabular}{llllll}\n\\hline\\noalign{\\smallskip}\nName & Written as & X & $p(x)$(or $p(\\vec{x})$) & $\\mathbb{E}[X]$ & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nBernoulli & $X \\sim \\text{Ber}(\\theta)$ & $x \\in \\{0,1\\}$ & $\\theta^{\\mathbb{I}(x=1)}(1-\\theta)^{\\mathbb{I}(x=0)}$ & $\\theta$ & $\\theta(1-\\theta)$ \\\\\nBinomial & $X \\sim \\text{Bin}(n,\\theta)$ & $x \\in \\{0,1,\\cdots,n\\}$ & $\\dbinom{n}{k}\\theta^k(1-\\theta)^{n-k}$ & $n\\theta$ & $n\\theta(1-\\theta)$ \\\\\nMultinoulli & $X \\sim \\text{Cat}(\\vec{\\theta})$ & $\\vec{x} \\in \\{0,1\\}^K, \\sum_{k=1}^K x_k=1$ & $\\prod\\limits_{k=1}^K\\theta_j^{\\mathbb{I}(x_j=1)}$ & - & - \\\\\nMultinomial & $X \\sim \\text{Mu}(n,\\vec{\\theta})$ & $\\vec{x} \\in \\{0,1,\\cdots,n\\}^K, \\sum_{k=1}^K x_k=n$ & $\\dbinom{n}{x_1 \\cdots x_k} \\prod\\limits_{k=1}^K\\theta_j^{x_j}$ & - & - \\\\\nPoisson & $X \\sim \\text{Poi}(\\lambda)$ & $x \\in \\{0,1,2,\\cdots\\}$ & $e^{-\\lambda}\\dfrac{\\lambda^x}{x!}$ & $\\lambda$ & $\\lambda$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table*}\n\nThe Poisson distribution can be derived as a \\textbf{limiting case to the binomial distribution} as the number of trials goes to infinity and the expected number of successes remains fixed,known as \\textbf{law of rare events}.Assume that there exists a small enough subinterval for which the probability of an event occurring twice is \"negligible\".Given only the information of expected number of total events in the whole interval,denoted as $\\lambda$,\\textbf{divide the whole interval into n subintervals} $I_1,I_2,...,I_n$ of equal size,such that $n > \\lambda$. The occurrence of an event in the whole interval can be seen as a \\textbf{Bernoulli trial}, where the $i$th  trial corresponds to looking whether an event happens at the subinterval $I_i$ with probability $p= \\lambda / n$.Then the number of events $x$ that occur obey \\textbf{binomial distribution} $X\\sim B(x;n,p)$.\n\\begin{eqnarray*}\n\t& P(x) &= B(x;n,p)\\\\\n\t&=&C_n^x \\left( p \\right)^x \\left( 1-p \\right)^{n-x} \\\\\n\t&=&\\frac{n!}{x!(n-x)!}p^x(1-p)^{n-x}\\\\\n\t&=&\\frac{n(n-1)(n-2) \\cdots (n-x+1)}{x!} \\cdot \\frac{\\lambda^x}{n^x} \\left( 1 - \\frac{\\lambda}{n} \\right)^{n-x} \\\\\n\t&=&\\frac{n}{n} \\cdot \\frac{n-1}{n} \\cdots \\frac{n-x+1}{n} \\cdot \\frac{\\lambda^x}{x!}\\left( 1 - \\frac{\\lambda}{n} \\right)^{n-x} \\\\\n\t&=&\\frac{n}{n} \\cdot \\frac{n-1}{n} \\cdots \\frac{n-x+1}{n} \\cdot \\frac{\\lambda^x}{x!}\n\t\t\\left(\\left( 1 - \\frac{\\lambda}{n} \\right)^{-\\frac{n}{\\lambda}}\\right)^{-\\lambda}\\left( 1 - \\frac{\\lambda}{n} \\right)^{-x}\n\\end{eqnarray*}\nFor $n \\rightarrow \\infty$,we have\n\\begin{align}\n& (1-\\frac{1}{n})(1-\\frac{2}{n})\\cdots(1-\\frac{x-1}{n})&\\rightarrow 1 \\\\\n& \\left(\\left( 1 - \\frac{\\lambda}{n} \\right)^{-\\frac{n}{\\lambda}}\\right)^{-\\lambda} &\\rightarrow e^{-\\lambda} \\\\\n& (1-\\frac{\\lambda}{n})^{-x}&\\rightarrow 1\n\\end{align}\nSo we have\n\\begin{align}\n\\lim_{n \\rightarrow \\infty} P(x) = \\frac{e^{-\\lambda} \\lambda^x}{x!}\n\\end{align}\n\n\\subsection{The empirical distribution}\nThe \\textbf{empirical distribution function}\\footnote{\\url{http://en.wikipedia.org/wiki/Empirical_distribution_function}}, or \\textbf{empirical cdf}, is the cumulative distribution function associated with the empirical measure of the sample. Let $\\mathcal{D}=\\{x_1,x_2,\\cdots,x_N\\}$ be a sample set, it is defined as \n\\begin{equation}\nF_n(x) \\triangleq \\dfrac{1}{N}\\sum\\limits_{i=1}^N\\mathbb{I}(x_i \\leq x)\n\\end{equation}\n\n\n\\section{Some common continuous distributions}\nIn this section we present some commonly used univariate (one-dimensional) continuous probability distributions.\n\n\n\\subsection{Gaussian (normal) distribution}\n\n% \\begin{table}\n% \\caption{Summary of Gaussian distribution}\n% \\centering\n% \\begin{tabular}{cccccc}\n% \\hline\\noalign{\\smallskip}\n% Name & Written as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n% \\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n% Gaussian distribution & $X \\sim \\mathcal{N}(\\mu,\\sigma^2)$ & $\\dfrac{1}{\\sqrt{2\\pi}\\sigma}e^{-\\frac{1}{2\\sigma^2}\\left(x-\\mu\\right)^2}$ & $\\mu$ & $\\mu$ & $\\sigma^2$ \\\\\n% \\noalign{\\smallskip}\\hline\n% \\end{tabular}\n% \\end{table} \n\n\\begin{table}\n\\caption{Summary of Gaussian distribution.}\n\\centering\n\\begin{tabular}{cccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\mathcal{N}(\\mu,\\sigma^2)$ & $\\dfrac{1}{\\sqrt{2\\pi}\\sigma}e^{-\\frac{1}{2\\sigma^2}\\left(x-\\mu\\right)^2}$ & $\\mu$ & $\\mu$ & $\\sigma^2$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table} \n\nIf $X \\sim N(0,1)$,we say $X$ follows a \\textbf{standard normal} distribution.\n\nThe Gaussian distribution is the most widely used distribution in statistics. There are several reasons for this. \n\\begin{enumerate}\n\\item First, it has two parameters which are easy to interpret, and which capture some of the most basic properties of a distribution, namely its mean and variance. \n\\item Second,the central limit theorem (Section TODO) tells us that sums of independent random variables have an approximately Gaussian distribution, making it a good choice for modeling residual errors or “noise”. \n\\item Third, the Gaussian distribution makes the least number of assumptions (has maximum entropy), subject to the constraint of having a specified mean and variance, as we show in Section TODO; this makes it a good default choice in many cases. \n\\item Finally, it has a simple mathematical form, which results in easy to implement, but often highly effective, methods, as we will see. \n\\end{enumerate}\nSee (Jaynes 2003, ch 7) for a more extensive discussion of why Gaussians are so widely used.More about Gaussian distribution is discussed in \\ref{sec:Gaussian distribution}. \n\n\\subsection{Student's t-distribution}\n\\begin{table}\n\\caption{Summary of Student's t-distribution.}\n\\centering\n\\begin{tabular}{cccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\mathcal{T}(\\mu,\\sigma^2,\\nu)$ & $\\dfrac{\\Gamma(\\frac{\\nu+1}{2})}{\\sqrt{\\nu\\pi}\\Gamma(\\frac{\\nu}{2})}\\left[1+\\dfrac{1}{\\nu}\\left(\\dfrac{x-\\mu}{\\nu}\\right)^2\\right]$ & $\\mu$ & $\\mu$ & $\\dfrac{\\nu\\sigma^2}{\\nu-2}$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table}\nwhere  $\\Gamma(x)$ is the gamma function:\n\\begin{equation}\n\\Gamma(x) \\triangleq \\int_0^\\infty t^{x-1}e^{-t}\\mathrm{d}t\n\\end{equation}\n$\\mu$ is the mean, $\\sigma^2>0$ is the scale parameter, and $\\nu>0$ is called the \\textbf{degrees of freedom}. See Figure \\ref{fig:pdfs-for-NTL} for some plots.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.70]{pdfs-for-NTL-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{pdfs-for-NTL-b.png}}\n\\caption{(a) The pdf’s for a $\\mathcal{N}(0,1)$, $\\mathcal{T}(0,1,1)$ and $Lap(0,1/\\sqrt{2})$. The mean is 0 and the variance is 1 for both the Gaussian and Laplace. The mean and variance of the Student is undefined when $\\nu=1$.(b) Log of these pdf’s. Note that the Student distribution is not log-concave for any parameter value, unlike the Laplace distribution, which is always log-concave (and log-convex...) Nevertheless, both are unimodal.}\n\\label{fig:pdfs-for-NTL} \n\\end{figure}\n\nThe variance is only defined if $\\nu>2$. The mean is only defined if $\\nu>1$.\n\nAs an illustration of the robustness of the Student distribution, consider Figure \\ref{fig:robustness}. We see that the Gaussian is affected a lot, whereas the Student distribution hardly changes. This is because the Student has heavier tails, at least for small $\\nu$(see Figure \\ref{fig:pdfs-for-NTL}).\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.70]{robustness-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{robustness-b.png}}\n\\caption{Illustration of the effect of outliers on fitting Gaussian, Student and Laplace distributions. (a) No outliers (the Gaussian and Student curves are on top of each other). (b) With outliers. We see that the Gaussian is more affected by outliers than the Student and Laplace distributions.}\n\\label{fig:robustness} \n\\end{figure}\n\nIf $\\nu=1$, this distribution is known as the \\textbf{Cauchy} or \\textbf{Lorentz} distribution. This is notable for having such heavy tails that the integral that defines the mean does not converge.\n\nTo ensure finite variance, we require $\\nu>2$. It is common to use $\\nu=4$, which gives good performance in a range of problems (Lange et al. 1989). For $\\nu \\gg 5$, the Student distribution rapidly approaches a Gaussian distribution and loses its robustness properties.\n\n\n\\subsection{The Laplace distribution}\n\\begin{table}\n\\caption{Summary of Laplace distribution.}\n\\centering\n\\begin{tabular}{cccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\text{Lap}(\\mu,b)$ & $\\dfrac{1}{2b}\\exp\\left(-\\dfrac{|x-\\mu|}{b}\\right)$ & $\\mu$ & $\\mu$ & $2b^2$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table}\n\nHere $\\mu$ is a location parameter and $b>0$ is a scale parameter. See Figure \\ref{fig:pdfs-for-NTL} for a plot.\n\nIts robustness to outliers is illustrated in Figure \\ref{fig:robustness}. It also put mores probability density at 0 than the Gaussian. This property is a useful way to encourage sparsity in a model, as we will see in Section TODO.\n\n\n\\subsection{The gamma distribution}\n\n\\begin{table}\n\\caption{Summary of gamma distribution}\n\\centering\n\\begin{tabular}{ccccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $X$ & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\text{Ga}(a,b)$ & $x \\in \\mathbb{R}^+$ & $\\dfrac{b^a}{\\Gamma(a)}x^{a-1}e^{-xb}$ & $\\dfrac{a}{b}$ & $\\dfrac{a-1}{b}$ & $\\dfrac{a}{b^2}$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table} \n\nHere $a>0$ is called the shape parameter and $b>0$ is called the rate parameter. See Figure \\ref{fig:gamma-distribution} for some plots.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{gamma-distribution-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{gamma-distribution-b.png}}\n\\caption{Some Ga$(a, b=1)$ distributions. If $a \\leq 1$, the mode is at 0, otherwise it is $>0$.As we increase the rate $b$, we reduce the horizontal scale, thus squeezing everything leftwards and upwards. (b) An empirical pdf of some rainfall data, with a fitted Gamma distribution superimposed.}\n\\label{fig:gamma-distribution} \n\\end{figure}\n\n\n\\subsection{The beta distribution}\n\n\\begin{table*}\n\\caption{Summary of Beta distribution}\\label{tab:beta-distribution}\n\\centering\n\\begin{tabular}{ccccccc}\n\\hline\\noalign{\\smallskip}\nName & Written as & $X$ & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nBeta distribution & $X \\sim \\text{Beta}(a,b)$ & $x \\in [0,1]$ & $\\dfrac{1}{B(a,b)}x^{a-1}(1-x)^{b-1}$ & $\\dfrac{a}{a+b}$ & $\\dfrac{a-1}{a+b-2}$ & $\\dfrac{ab}{(a+b)^2(a+b+1)}$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table*} \n\nHere $B(a, b)$is the beta function,\n\\begin{equation}\nB(a,b) \\triangleq \\dfrac{\\Gamma(a)\\Gamma(b)}{\\Gamma(a+b)}\n\\end{equation}\n\nSee Figure \\ref{fig:beta-distribution} for plots of some beta distributions. We require  $a, b >0$ to ensure the distribution is integrable (i.e., to ensure $B(a, b)$ exists). If $a=b=1$, we get the uniform distirbution. If $a$ and $b$ are both less than 1, we get a bimodal distribution with “spikes” at 0 and 1; if $a$ and $b$ are both greater than 1, the distribution is unimodal.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.60]{beta-distribution.png}\n\\caption{Some beta distributions.}\n\\label{fig:beta-distribution} \n\\end{figure}\n\n\n\\subsection{Pareto distribution}\n\n\\begin{table*}\n\\caption{Summary of Pareto distribution}\n\\centering\n\\begin{tabular}{ccccccc}\n\\hline\\noalign{\\smallskip}\nName & Written as & $X$ & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nPareto distribution & $X \\sim \\text{Pareto}(k,m)$ & $x \\geq m$ & $km^kx^{-(k+1)}\\mathbb{I}(x \\geq m)$ & $\\dfrac{km}{k-1} \\text{ if } k > 1$ & $m$ & $\\dfrac{m^2k}{(k-1)^2(k-2)} \\text{ if } k>2$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table*} \n\nThe \\textbf{Pareto distribution} is used to model the distribution of quantities that exhibit \\textbf{long tails}, also called \\textbf{heavy tails}.\n\nAs $k \\rightarrow \\infty$, the distribution approaches $\\delta(x-m)$. See Figure \\ref{fig:Pareto-distribution}(a) for some plots. If we plot the distribution on a log-log scale, it forms a straight line, of the form $\\log p(x)=a\\log x+c$ for some constants $a$ and $c$. See Figure \\ref{fig:Pareto-distribution}(b) for an illustration (this is known as a \\textbf{power law}).\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{pareto-distribution-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{pareto-distribution-b.png}}\n\\caption{(a) The Pareto distribution Pareto$(x|m, k)$ for $m=1$. (b) The pdf on a log-log scale.}\n\\label{fig:Pareto-distribution} \n\\end{figure}\n\n\\section{The Gaussian Distribution}\n\\label{sec:Gaussian distribution}\nThe Gaussian distributions,also known as the normal distributions,is a widely used model for the distribution of continuous variables.In the case of single variable $x$,the Gaussian is in the form\n\\begin{align}\\label{eqn:univariate Gaussian distributions}\n\\mathcal{N}(x|\\mu,\\sigma^2)=\\dfrac{1}{(2\\pi\\sigma^2)^{1/2}}\\exp\\{-\\dfrac{1}{(2\\sigma)^2}(x-\\mu)^2 \\}\n\\end{align}\nwhere $\\mu$ is the mean and $\\sigma^2$ is the variance.For a $D$-dimensional vector $\\vec{x}$,the multivariate Gaussian distribution takes the form\n\\begin{align}\\label{eqn:multivariate Gaussian}\n\t\\mathcal{N}(\\vec{x}|\\vec{\\mu},\\vec{\\Sigma})\n\t=\\dfrac{1}{(2\\pi)^{D/2}}\\dfrac{1}{\\mid \\vec{\\Sigma}\\mid^{1/2}}\n\t\\exp\\{-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu}) \\}\n\\end{align}\nwhere $\\vec{\\mu}$ is a $D$-dimensional mean vector,$\\vec{\\Sigma}$ is a $D\\times D$ covariance matrix,and $\\mid\\vec{\\Sigma}\\mid$ denotes the determinant of $\\vec{\\Sigma}$.\n\nThe Gaussian distribution arises in many different contexts and can be motivated from a variety of different perspectives,such as maximizing the entropy and the sum of multiple random variables.The \\textbf{central limit theorem} tells us the latter.\n\\subsection{Linear Transformation based on Eigenvector}\nRecall from Section \\ref{sec:MVN},for a $D-dimensionl$ vector \\vec{x},the multivariate Gaussian distribution(MVN),i.e. the \\textbf{pdf} takes the form:\n\\begin{equation}\n\\mathcal{N}(\\vec{x}|\\vec{\\mu},\\Sigma) \\triangleq \\dfrac{1}{(2\\pi)^{\\frac{D}{2}}|\\Sigma|^{\\frac{1}{2}}}\\exp\\left[-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu})\\right]\n\\end{equation}\nwhere $\\mu$ is a $D-dimensional$ mean vector,$\\Sigma$ is a $D\\times D$ covariance matrix,and $|\\Sigma|$ denotes the determinant of $\\Sigma$.\n\nThe Gaussian distribution arises in many different contexts and can be motivated from variety of different\nperspectives,such as the distribution that maximizes the entropy.Another situation in which the Gaussian distribution arises is when we consider the sum of multiple random variables.The $central limit theorem$ (due to Laplace),tells us that,subject to certain mild conditions,the sum of a set of random variables,which is of course itself a random variable,has a distribution that becomes increasingly Gaussian as the number of terms in the sum increases(Walker,1969).\n\nThe expression inside the exponent,which is the functional dependence of the Gaussian on $\\vec{x}$,is through the quadratic form\n\\begin{equation}\\label{eqn:Gaussian quadratic form}\n\\Delta^2 = (\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu})\n\\end{equation}\nThe quantity $\\Delta$ is the $Mahalanobis distance$ between a data vector $\\vec{x}$ and the mean vector $\\vec{\\mu}$ and reduces to the Euclidean distance when $\\Sigma$ is the identity matrix. We can gain a better understanding of this quantity by performing an \\textbf{eigendecomposition} of $\\vec{\\Sigma}$. That is, we write $\\vec{\\Sigma}=\\vec{U}\\vec{\\Lambda}\\vec{U}^T$, where $\\vec{U}$ is an orthonormal matrix of eigenvectors satsifying $\\vec{U}^T\\vec{U}=\\vec{I}$, and $\\vec{\\Lambda}$ is a diagonal matrix of eigenvalues. Using the eigendecomposition, we have that\n\\begin{equation}\n\\vec{\\Sigma}^{-1}=\\vec{U}^{-T}\\vec{\\Lambda}^{-1}\\vec{U}^{-1}=\\vec{U}\\vec{\\Lambda}^{-1}\\vec{U}^T=\\sum\\limits_{i=1}^D \\dfrac{1}{\\lambda_i}\\vec{u}_i\\vec{u}_i^T\n\\end{equation}\nwhere $\\vec{u}_i$ is the $i$'th column of $\\vec{U}$, containing the $i$'th eigenvector. Hence we can rewrite the Mahalanobis distance as follows:\n\\begin{align}\n(\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu}) & =(\\vec{x}-\\vec{\\mu})^T\\left(\\sum\\limits_{i=1}^D \\dfrac{1}{\\lambda_i}\\vec{u}_i\\vec{u}_i^T\\right)(\\vec{x}-\\vec{\\mu}) \\\\\n& =\\sum\\limits_{i=1}^D \\dfrac{1}{\\lambda_i}(\\vec{x}-\\vec{\\mu})^T\\vec{u}_i\\vec{u}_i^T(\\vec{x}-\\vec{\\mu}) \\\\\n& =\\sum\\limits_{i=1}^D \\dfrac{y_i^2}{\\lambda_i}\n\\end{align}\nwhere $y_i \\triangleq \\vec{u}_i^T(\\vec{x}-\\vec{\\mu})$. Recall that the equation for an ellipse in 2d is\n\\begin{equation}\n\\dfrac{y_1^2}{\\lambda_1}+\\dfrac{y_2^2}{\\lambda_2}=1\n\\end{equation}\n\nHence we see that the contours of equal probability density of a Gaussian lie along ellipses. This is illustrated in Figure \\ref{fig:2d-MVN}. The eigenvectors determine the orientation of the ellipse, and the eigenvalues determine how elogonated it is.\n\n\\begin{figure}[hbtp]\n\t\\centering\n\t\\includegraphics[scale=.70]{2d-MVN.png}\n\t\\caption{Visualization of a 2 dimensional Gaussian density. The major and minor axes of the ellipse are defined by the first two eigenvectors of the covariance matrix, namely $\\vec{u}_1$ and $\\vec{u}_2$. Based on Figure 2.7 of (Bishop 2006a)}\n\t\\label{fig:2d-MVN} \n\\end{figure}\n\nIn general, we see that the Mahalanobis distance corresponds to Euclidean distance in a transformed coordinate system, where we shift by $\\vec{\\mu}$ and rotate by $\\vec{U}$.\n\\begin{proof}\n\tFirst of all,we note that the matrix $\\Sigma$ can be taken to be symmetric,without loss of generality.Now we consider the eigenvector equation for the convariance matrix\n\t\\begin{equation}\n\t\\Sigma\\vec{\\mu_i} = \\lambda_i\\vec{\\mu_i}\n\t\\end{equation}\n\twhere $ i = 1,...,D $.Because $\\Sigma$ is real,symmetric matrix its eigenvalues will be real,and its eigenvectors can be chosen to form an orthonormal set,so that\n\t\\begin{equation}\n\t\\vec{\\mu_i}^T\\vec{\\mu_j} = \\mathcal{I}_{ij}\n\t\\end{equation}\n\twhere $\\mathcal{I}_{ij}$ is the $i,j$ element of the identity matrix and satisfies \n\t\\begin{align}\n\t\\mathcal{I}_{ij} = \\begin{cases}\n\t& 1,\\text{if i=j} \\\\\n\t& 0,\\text{otherwise}.\n\t\\end{cases}\n\t\\end{align}\n\tThe covariance matrix $\\Sigma$ can be expressed as an equation in terms of its eigenvectors in the form\n\t\\begin{eqnarray}\n\t\\vec{\\Sigma} & =\\vec{U}\\vec{\\Lambda}\\vec{U}^T \\\\\n\t& = \\sum\\limits_{i=1}^{D}\\lambda_i\\vec{\\mu_i}\\vec{\\vec{u_i}^T}\n\t\\end{eqnarray}\n\twhere $\\vec{u}_i$ is the $i$'th column of $\\vec{U}$, containing the $i$'th eigenvector.\n\tSimilarly,the inverse covariance matrix $\\Sigma^{-1}$ can be expressed as \n\t\\begin{equation}\\label{eqn:Gaussian inverse covariance matrix eigen form}\n\t\\vec{\\Sigma^{-1}} = \\sum\\limits_{i=1}^{D}\\dfrac{1}{\\lambda_i}\\vec{u_i}\\vec{u_i}^T\n\t\\end{equation}\n\tSubstituting \\ref{eqn:Gaussian inverse covariance matrix eigen form} into \\ref{eqn:Gaussian quadratic form} ,the quadratic form becomes\n\t\\begin{equation}\n\t\\Delta^2 = \\sum\\limits_{i=1}^{D}\\dfrac{y_i^2}{\\lambda_i}\n\t\\end{equation}\n\twhere we have defined \n\t\\begin{equation}\n\ty_i = \\vec{u_i}^T(\\vec{x}-\\vec{u})\n\t\\end{equation}\n\tWe can interpret $\\{y_i\\}$ as a new coordinate system defined by the orthonormal vectors $\\vec{u_i}$ that are shifted and rotated with respect to the original $x_i$ coordinates.Forming the vector $\\vec{y}=(y_1,...,y_D)^T$,we have\n\t\\begin{equation}\n\t\\vec{y} = \\vec{U}(\\vec{x}-\\vec{\\mu})\n\t\\end{equation}\n\twhere\n\t\\begin{equation}\n\t\\vec{U} = \\begin{bmatrix}\n\t\\vec{u_1}^T & \\vec{u_2}^T&...&\\vec{u_n}^T\n\t\\end{bmatrix}\n\t\\end{equation}\n\t$\\vec{U}$ is an $orthogonal$ matrix.\n\tA matrix whose eigenvalue are strictly positive is said to be \\textbf{positive definite}, and if all the eigenvalues are nonnegative,then the covariance matrix is said to be \\textbf{positive semidefinite}.\n\t\n\tNow consider  the form of Gaussian distribution in the new coordinate system defined by the $y_i$.In going from $\\vec{x}$ to $\\vec{y}$ coordinate system,we have a \\textbf{Jacobian matrix} $\\vec{J}$ with elements given by\n\t\\begin{eqnarray}\n\tJ_{ij} = \\dfrac{\\partial x_i}{\\partial y_i} = U_{ji}\\\\\n\t\\vec{J} = \\dfrac{\\partial\\vec{x}}{\\partial\\vec{y}}\n\t\\end{eqnarray}\n\twhere $U_{ji}$ are the elements of the matrix $\\vec{U}^T$.Using the orthonormality property of the matrix $\\vec{U}$, we see that the square of the determinant of the Jacobian matrix is\n\t\\begin{equation}\n\t|\\vec{J}|^2 = |\\vec{I}| = 1\n\t\\end{equation}\n\tAlso,the determinant $|\\vec{\\Sigma}|$ of the covariance matrix can be written as the product of its eigenvalues,and hence\n\t\\begin{eqnarray}\n\t|\\vec{\\Sigma}|^{1/2} = \\prod_{j=1}^{D}\\lambda_j^{1/2}\n\t\\end{eqnarray}\n\tThus in the $y_i$ coordinate system,the Gaussian distribution takes the form\n\t\\begin{equation}\n\tp(\\vec{y}) = p(\\vec{x})|\\vec{J}| = \\prod_{j=1}^{D}\\dfrac{1}{(2\\pi \\lambda_j)^{1/2}}\\exp\\{-\\dfrac{y_j ^2}{2\\lambda_j}\\}\n\t\\end{equation}\n\twhich is the product of $D$ independent univariate Gaussian distributions.So we have normalized the multivariate Gaussian.\n\\end{proof}\nNow we can check the first and second order moments of the Gaussian.\n\n\\subsubsection{limitations}\nGaussian distribution has quadratically growing parameters with dimension.A further limitation of the Gaussian distribution is that it is intrinsically unimodal(i.e.,has a single maximum) and so is unable to provide a good approximation to multimodal distributions.We will introduce $latent$ variables,also called $hidden$ variables or $unobserved$ variables to address both of these problems.\n\n\\subsubsection{MLE for a MVN}\n\\begin{theorem}(\\textbf{MLE for a MVN})\n\tIf we have $N$ iid samples $\\vec{x}_i \\sim \\mathcal{N}(\\vec{\\mu},\\vec{\\Sigma})$, then the MLE for the parameters is given by\n\t\\begin{align}\n\t\\bar{\\vec{\\mu}}    & =\\dfrac{1}{N}\\sum\\limits_{i=1}^N \\vec{x}_i \\triangleq \\bar{\\vec{x}} \\\\\n\t\\bar{\\vec{\\Sigma}} & =\\dfrac{1}{N}\\sum\\limits_{i=1}^N (\\vec{x}_i-\\bar{\\vec{x}})(\\vec{x}_i-\\bar{\\vec{x}})^T \\\\\n\t& =\\dfrac{1}{N}\\left(\\sum\\limits_{i=1}^N \\vec{x}_i\\vec{x}_i^T\\right)-\\bar{\\vec{x}}\\bar{\\vec{x}}^T\n\t\\end{align}\n\\end{theorem}\n\n\n\\subsubsection{Maximum entropy derivation of the Gaussian *}\nIn this section, we show that the multivariate Gaussian is the distribution with maximum entropy subject to having a specified mean and covariance (see also Section TODO). This is one reason the Gaussian is so widely used: the first two moments are usually all that we can reliably estimate from data, so we want a distribution that captures these properties, but otherwise makes as few addtional assumptions as possible.\n\nTo simplify notation, we will assume the mean is zero. The pdf has the form\n\\begin{equation}\nf(\\vec{x})=\\dfrac{1}{Z}\\exp\\left(-\\dfrac{1}{2}\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}\\right)\n\\end{equation}\n\n\n\\subsection{Conditional Gaussian distributions}\n\\begin{theorem}\nIf two sets of variables are jointly multivariate Gaussian, then the conditional distribution of one set conditioned on the other is again Gaussian. Similarly, the marginal distribution of either set is also Gaussian.\n\\end{theorem}\nThe multivariate normal distribution is given by\n\\begin{align}\n\\frac{1}{(2\\pi)^{D/2}|\\Sigma|^{1/2}} \\exp\\left(-\\frac{1}{2} (\\vec{x}-\\vec{\\mu})^T \\Sigma^{-1} (\\vec{x}-\\vec{\\mu})\\right)\n\\end{align}\nWrite $\\vec{x}$ as\n\\begin{equation}\n\\vec{x} = \\left[ \\begin{array}{c} \\vec{x}_a\\\\ \\vec{x}_b \\end{array} \\right],\n\\vec{x} = \\left[ \\begin{array}{c} \\vec{\\mu}_a\\\\ \\vec{\\mu}_b \\end{array} \\right]\n\\end{equation}\nConsider the conditional distribution $p(\\vec{x}_a|\\vec{x}_b)$ and marginal distribution $p(\\vec{x}_a)$.\nSeparate the components of the covariance matrix $\\vec{\\Sigma}$ into partitioned block matrix\n\\begin{align}\n\\vec{\\Sigma} = \\left[ \\begin{array}{cc} \\vec{\\Sigma}_{aa} & \\vec{\\Sigma}_{ab} \\\\ \\vec{\\Sigma}_{ba} & \\vec{\\Sigma}_{bb} \\end{array}\\right]\n\\end{align}\nwhere $\\vec{\\Sigma},\\vec{\\Sigma}_{aa},\\vec{\\Sigma}_{bb}$ are all symmetric and $\\vec{\\Sigma}_{ab} = \\vec{\\Sigma}_{ab}^T$.\n\nFrom the product rule of probability, we see that this conditional distribution can be evaluated from the joint distribution $p(\\vec{x}) = p(\\vec{x}_a,\\vec{x}_b)$ simple by fixing $\\vec{x}_b$ to the observed value and \\textbf{normalizing} the resulting expression to obtain a valid probability distribution over $\\vec{x}_a$.To evaluate the conditional probability from the joint probability,for any arbitrary $\\vec{x}_b$,we can use \\textbf{product and sum} rule of probability\n\\begin{align}\np(\\vec{x}_b) &= \\int p(\\vec{x}_a,\\vec{x}_b) d\\vec{x}_a \\\\\np(\\vec{x}_a\\vec{x}_b) &= \\dfrac{p(\\vec{x}_a,\\vec{x}_b)}{p(\\vec{x}_b)}\n\\end{align}\nBecause $p(\\vec{x}_b)$ is observed value,so we have\n\\begin{align}\np(\\vec{x}_a\\vec{x}_b) &\\sim \\dfrac{p(\\vec{x}_a,\\vec{x}_b)}{p(\\vec{x}_b)} \\\\\n&\\sim p(\\vec{x}_a,\\vec{x}_b)\n\\end{align}\nwhich has the \\textbf{exponential quadratic form},and hence the corresponding conditional distribution will be Gaussian.\n\\begin{align}\n&-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu}) \\\\\n&=-\\dfrac{1}{2}\\left[ \\begin{array}{cc} \n(\\vec{x}_a-\\vec{\\mu}_a)^T & (\\vec{x}_b-\\vec{\\mu}_b)^T \n\\end{array}\\right]\n\\left[ \\begin{array}{cc} \n\\vec{\\varLambda}_{aa} & \\vec{\\varLambda}_{ab}  \\\\\n\\vec{\\varLambda}_{ba} & \\vec{\\varLambda}_{bb}    \n\\end{array}\\right]\n\\left[ \\begin{array}{cc} \n(\\vec{x}_a-\\vec{\\mu}_a) \\\\\n(\\vec{x}_b-\\vec{\\mu}_b)\n\\end{array}\\right] \\\\\n&=-\\dfrac{1}{2}\\left[ \\begin{array}{cc} \n(\\vec{x}_a-\\vec{\\mu}_a)^T\\vec{\\varLambda}_{aa}+(\\vec{x}_b-\\vec{\\mu}_b)^T\\vec{\\varLambda}_{ba} &\n(\\vec{x}_a-\\vec{\\mu}_a)^T\\vec{\\varLambda}_{ab}+(\\vec{x}_b-\\vec{\\mu}_b)^T\\vec{\\varLambda}_{bb}    \n\\end{array}\\right]\n\\left[ \\begin{array}{cc} \n(\\vec{x}_a-\\vec{\\mu}_a) \\\\\n(\\vec{x}_b-\\vec{\\mu}_b)\n\\end{array}\\right] \\\\\n&=-\\dfrac{1}{2}((\\vec{x}_a-\\vec{\\mu}_a)^T\\vec{\\varLambda}_{aa}(\\vec{x}_a-\\vec{\\mu}_a)\n+(\\vec{x}_b-\\vec{\\mu}_b)^T\\vec{\\varLambda}_{ba}(\\vec{x}_a-\\vec{\\mu}_a) \\\\\n&+ (\\vec{x}_a-\\vec{\\mu}_a)^T\\vec{\\varLambda}_{ab}(\\vec{x}_b-\\vec{\\mu}_b)\n+(\\vec{x}_b-\\vec{\\mu}_b)^T\\vec{\\varLambda}_{bb}(\\vec{x}_b-\\vec{\\mu}_b) )\n\\end{align}\nWith the operation called 'completing the square' of the exponent form in a General Gaussian distribution $\\mathcal{N}(\\vec{x}|\\vec{\\mu,\\vec{\\Sigma}})$\n\\begin{align}\n-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu}) &= \n-\\dfrac{1}{2}\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}+\\vec{x}^T\\vec{\\Sigma}\\vec{\\mu} + \\text{const}\n\\end{align}\nBased on this,we can apply \\textbf{method of undetermined coefficients} to determinate the super parameters.Covariance matrix is in the corresponding second-order term in $\\vec{x}_a$,and mean vector is in the corresponding linear term in $\\vec{x}_a$. \n\nWe need to make use of \\textbf{Schur complement} for the inverse covariance matrix(\\textbf{precision matrix})\n\\begin{align}\n\\left[ \\begin{array}{cc} \n\\vec{A} & \\vec{B} \\\\\n\\vec{C} & \\vec{D}  \n\\end{array}\\right]^{-1}\n= \\left[ \\begin{array}{cc} \n\\vec{M} & -\\vec{M}\\vec{B}\\vec{D}^{-1} \\\\\n-\\vec{D}^{-1}\\vec{C}\\vec{M} & \\vec{D}^{-1}\\vec{C}\\vec{M}\\vec{B}\\vec{D}^{-1}\n\\end{array}\\right]^{-1} \\\\\n\\end{align}\nwhere\n\\begin{align}\n\\vec{M} = (\\vec{A}-\\vec{B}\\vec{D}^{-1}\\vec{C})^{-1}\n\\end{align}\nThen the precision matrix\n\\begin{align}\n\\left[ \\begin{array}{cc}\n \\vec{\\Sigma}_{aa} & \\vec{\\Sigma}_{ab} \\\\\n \\vec{\\Sigma}_{ba} & \\vec{\\Sigma}_{bb} \n \\end{array}\\right]^{-1} =\n \\left[ \\begin{array}{cc} \\vec{\\varLambda}_{aa} & \\vec{\\varLambda}_{ab} \\\\\n  \\vec{\\varLambda}_{ba} & \\vec{\\varLambda}_{bb} \\end{array}\\right]\n\\end{align}\ncan be evaluated.\n\n\\subsection{Marginal Gaussian distributions}\nWrapping up,given joint Gaussian distribution,we can obtain partitioned Gaussians.\nConditional distribution:\n\\begin{align}\np(\\vec{x}_a|\\vec{x}_b) &= \\mathcal{N}(\\vec{x}|\\vec{\\mu}_{a|b},\\vec{\\varLambda}_{aa}^{-1}) \\\\\n\\vec{\\mu}_{a|b} &= \\vec{\\mu}_a-\\vec{\\varLambda}_{aa}^{-1}\\vec{\\varLambda}_{ab}(\\vec{x}_b-\\vec{\\mu}_b)\n\\end{align}\nMarginal distribution:\n\\begin{align}\np(\\vec{x}_a) = \\mathcal{N}(\\vec{x}_a|\\vec{\\mu}_a,\\vec{\\Sigma}_{aa})\n\\end{align}\n\\subsection{Baye's theorem for Gaussian variables}\n\n\\section{The exponential family}\n\\label{sec:exponential-family}\n\nBefore defining the exponential family, we mention several reasons why it is important:\n\\begin{itemize}\n\t\\item{It can be shown that, under certain regularity conditions, the exponential family is the only family of distributions with finite-sized sufficient statistics, meaning that we can compress the data into a fixed-sized summary without loss of information. This is particularly useful for online learning, as we will see later.}\n\t\\item{The exponential family is the only family of distributions for which conjugate priors exist, which simplifies the computation of the posterior (see Section \\ref{sec:Bayes-for-the-exponential-family}).}\n\t\\item{The exponential family can be shown to be the family of distributions that makes the least set of assumptions subject to some user-chosen constraints (see Section \\ref{sec:Maximum-entropy-derivation-of-the-exponential-family}).}\n\t\\item{The exponential family is at the core of generalized linear models, as discussed in Section \\ref{sec:GLMs}.}\n\t\\item{The exponential family is at the core of variational inference, as discussed in Section TODO.}\n\\end{itemize}\n\n\n\\subsection{Definition}\nA pdf or pmf $p(\\vec{x}|\\vec{\\theta})$,for $\\vec{x} \\in \\mathbb{R}^m$ and $\\vec{\\theta} \\in \\mathbb{R}^D$, is said to be in the \\textbf{exponential family} if it is of the form\n\\begin{align}\np(\\vec{x}|\\vec{\\theta}) \n&= h(\\vec{x})g(\\vec{\\theta})\\exp\\{\\vec{\\theta}^T\\vec{\\phi}(\\vec{x})\\} \\\\\n&=\\dfrac{1}{Z(\\vec{\\theta})}h(\\vec{x})\\exp[\\vec{\\theta}^T\\phi(\\vec{x})] \\\\\n& = h(\\vec{x})\\exp[\\vec{\\theta}^T\\phi(\\vec{x})-A(\\vec{\\theta})] \\label{eqn:exponential-family}\n\\end{align}\nwhere\n\\begin{align}\nZ(\\vec{\\theta}) & =\\int h(\\vec{x})\\exp[\\vec{\\theta}^T\\phi(\\vec{x})]\\mathrm{d}\\vec{x} \\\\\nA(\\vec{\\theta}) & =\\log Z(\\vec{\\theta})\n\\end{align}\n\nHere $\\vec{\\theta}$ are called the \\textbf{natural parameters} or \\textbf{canonical parameters}, $\\phi(\\vec{x}) \\in \\mathbb{R}^D$ is called a vector of \\textbf{sufficient statistics}, $Z(\\vec{\\theta})$ is called the \\textbf{partition function}, $A(\\vec{\\theta})$ is called the \\textbf{log partition function} or \\textbf{cumulant function}, and $h(\\vec{x})$ is the a scaling constant, often 1. If $\\phi(\\vec{x})=\\vec{x}$, we say it is a \\textbf{natural exponential family}.\n\nEquation \\ref{eqn:exponential-family} can be generalized by writing\n\\begin{equation}\np(\\vec{x}|\\vec{\\theta}) = h(\\vec{x})\\exp[\\eta(\\vec{\\theta})^T\\phi(\\vec{x})-A(\\eta(\\vec{\\theta}))]\n\\end{equation}\nwhere $\\eta$ is a function that maps the parameters $\\vec{\\theta}$ to the canonical parameters $\\vec{\\eta}=\\eta(\\vec{\\theta})$.If $\\mathrm{dim}(\\vec{\\theta})<\\mathrm{dim}(\\eta(\\vec{\\theta}))$, it is called a \\textbf{curved exponential family}, which means we have more sufficient statistics than parameters. If $\\eta(\\vec{\\theta})=\\vec{\\theta}$, the model is said to be in \\textbf{canonical form}. We will assume models are in canonical form unless we state otherwise.\n\n\\subsection{Maximum likelihood and sufficient statistics}\n\n\\subsection{Conjugate priors}\n\n\\subsection{Noninformative prios}\nIn many cases,however,we may have little idea of what form the distribution should take.We may then seek a form of prior distribution,called a \\textbf{noninformative prior},which is intended to have little influence on the posterior distribution as possible(Jeffries,1946;Box and Tao,1973;Bernardo and Smith,1994).\n\nSuppose we have a distribution $p(x|\\lambda)$ governed by a parameter $\\lambda$,we might be tempted to propose a prior distribution $p(\\lambda) = $const as a suitable prior.Improper priors are ones in which the domain $\\lambda$ is unbounded and the prior distribution cannot be correctly normalized because the integral over $\\lambda$ diverges.A second difficulty arises from the transformation behaviour of a probability density under a nonlinear change of variables.For example\n\\begin{equation}\np_\\eta(\\eta) = p_\\lambda(\\lambda) \\left | \\dfrac{d\\lambda}{d\\eta} \\right | = p_\\lambda(\\eta^2)\\eta\\propto \\eta\n\\end{equation}\nso the density over $\\eta$ will not be constant.\n\nHere are two simple examples of noninformative priors(Berger,1985).\nFirst of all,if a density takes the form\n\\begin{equation}\np(x|\\mu) = f(x-\\mu)\n\\end{equation}\nthen the parameter $\\mu$ is known as a \\textbf{location parameter}.This family of densities exhibits \\textbf{translation invariance} because if we shift $x$ by a constant to give $\\hat{x} = x+c$,then\n\\begin{equation}\np(\\hat{x}|\\hat{\\mu}) = f(\\hat{x}-\\hat{\\mu})\n\\end{equation}\nwhere $\\hat{\\mu} = \\mu +c$.\n\nA second example,\n\\begin{equation}\\label{eqn:density scale parameter}\np(x|\\sigma) = \\dfrac{1}{\\sigma}f(\\dfrac{x}{\\sigma})\n\\end{equation}\nwhere $\\sigma>0$.Note that this will be a normalized density provided f(x) is correctly normalized.The parameter $\\sigma$ is known as a \\textbf{scale parameter},and the density exhibits \\textbf{scale invariance}.\n\n\\subsection{Examples}\n\n\n\\subsubsection{Bernoulli}\nThe Bernoulli for $x \\in \\{0,1\\}$ can be written in exponential family form as follows:\n\\begin{equation}\\begin{split}\n\\mathrm{Ber}(x|\\mu)& =\\mu^x(1-\\mu)^{1-x} \\\\\n& =\\exp[x\\log\\mu+(1-x)\\log(1-\\mu)]\n\\end{split}\\end{equation}\nwhere $\\phi(x)=(\\mathbb{I}(x=0),\\mathbb{I}(x=1))$ and $\\vec{\\theta}=(\\log\\mu,\\log(1-\\mu))$. \n\nHowever, this representation is \\textbf{over-complete} since $\\vec{1}^T\\phi(x)=\\mathbb{I}(x=0)+\\mathbb{I}(x=1)=1$. Consequently $\\vec{\\theta}$ is not uniquely identifiable. It is common to require that the representation be \\textbf{minimal}, which means there is a unique $\\theta$ associated with the distribution. In this case, we can just define\n\\begin{align}\n\\mathrm{Ber}(x|\\mu) & =(1-\\mu)\\exp\\left(x\\log\\dfrac{\\mu}{1-\\mu}\\right) \\\\\n\\text{where } \\phi(x) & =x, \\theta=\\log\\dfrac{\\mu}{1-\\mu}, Z=\\dfrac{1}{1-\\mu}  \\nonumber\n\\end{align}\n\nWe can recover the mean parameter $\\mu$ from the canonical parameter using\n\\begin{equation}\n\\mu=\\mathrm{sigm}(\\theta)=\\dfrac{1}{1+e^{-\\theta}}\n\\end{equation}\n\n\n\\subsubsection{Multinoulli}\nWe can represent the multinoulli as a minimal exponential family as follows:\n\\begin{equation*}\\begin{split}\n& \\mathrm{Cat}(\\vec{x}|\\vec{\\mu}) = \\prod\\limits_{k=1}^K = \\exp\\left(\\sum\\limits_{k=1}^K x_k\\log\\mu_k\\right) \\\\\n& = \\exp\\left[\\sum\\limits_{k=1}^{K-1} x_k\\log\\mu_k+  (1-\\sum\\limits_{k=1}^{K-1} x_k)\\log(1-\\sum\\limits_{k=1}^{K-1} \\mu_k)\\right] \\\\\n& = \\exp\\left[\\sum\\limits_{k=1}^{K-1} x_k\\log\\dfrac{\\mu_k}{1-\\sum_{k=1}^{K-1} \\mu_k} + \\log(1-\\sum\\limits_{k=1}^{K-1} \\mu_k) \\right] \\\\\n& = \\exp\\left[\\sum\\limits_{k=1}^{K-1} x_k\\log\\dfrac{\\mu_k}{\\mu_K}+\\log\\mu_K\\right] \\text{, where } \\mu_K \\triangleq 1-\\sum\\limits_{k=1}^{K-1} \\mu_k\n\\end{split}\\end{equation*}\n\nWe can write this in exponential family form as follows:\n\\begin{align}\n\\mathrm{Cat}(\\vec{x}|\\vec{\\mu}) & = \\exp[\\vec{\\theta}^T\\phi(\\vec{x})-A(\\vec{\\theta})] \\\\\n\\vec{\\theta} & \\triangleq (\\log\\dfrac{\\mu_1}{\\mu_K},\\cdots,\\log\\dfrac{\\mu_{K-1}}{\\mu_K}) \\\\\n\\phi(\\vec{x}) & \\triangleq (x_1,\\cdots,x_{K-1})\n\\end{align}\n\nWe can recover the mean parameters from the canonical parameters using\n\\begin{align}\n\\mu_k & = \\dfrac{e^{\\theta_k}}{1+\\sum_{j=1}^{K-1} e^{\\theta_j}} \\\\\n\\mu_K & = 1- \\dfrac{\\sum_{j=1}^{K-1} e^{\\theta_j}}{1+\\sum_{j=1}^{K-1} e^{\\theta_j}}=\\dfrac{1}{1+\\sum_{j=1}^{K-1} e^{\\theta_j}}\n\\end{align}\nand hence\n\\begin{equation}\nA(\\vec{\\theta]} = -\\log\\mu_K=\\log(1+\\sum\\limits_{j=1}^{K-1} e^{\\theta_j})\n\\end{equation}\n\n\n\\subsubsection{Univariate Gaussian}\nThe univariate Gaussian can be written in exponential family form as follows:\n\\begin{align}\n\\mathcal{N}(x|\\mu,\\sigma^2) & =\\dfrac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left[-\\dfrac{1}{2\\sigma^2}(x-\\mu)^2\\right] \\nonumber \\\\\n& = \\dfrac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left[-\\dfrac{1}{2\\sigma^2}x^2+\\dfrac{\\mu}{\\sigma^2}x-\\dfrac{1}{2\\sigma^2}\\mu^2\\right] \\nonumber \\\\\n& = \\dfrac{1}{Z(\\vec{\\theta})}\\exp[\\vec{\\theta}^T\\phi(x)]\n\\end{align}\nwhere\n\\begin{align}\n\\vec{\\theta} & = (\\dfrac{\\mu}{\\sigma^2}, -\\dfrac{1}{2\\sigma^2}) \\\\\n\\phi(x) & =(x,x^2) \\\\\nZ(\\vec{\\theta}) & =\\sqrt{2\\pi}\\sigma\\exp(\\dfrac{\\mu^2}{2\\sigma^2})\n\\end{align}\n\n\n\\subsubsection{Non-examples}\nNot all distributions of interest belong to the exponential family. For example, the uniform distribution,$X \\sim U(a,b)$, does not, since the support of the distribution depends on the parameters. Also, the Student T distribution (Section TODO) does not belong, since it does not have the required form.\n\n\n\\subsection{Log partition function}\nAn important property of the exponential family is that derivatives of the log partition function can be used to generate \\textbf{cumulants} of the sufficient statistics.\\footnote{The first and second cumulants of a distribution are its mean $\\mathbb{E}[X]$ and variance $\\mathrm{var}[X]$, whereas the first and second moments are its mean $\\mathbb{E}[X]$ and $\\mathbb{E}[X^2]$.} For this reason, $A(\\vec{\\theta})$ is sometimes called a \\textbf{cumulant function}. We will prove this for a 1-parameter distribution; this can be generalized to a $K$-parameter distribution in a straightforward way. For the first derivative we have\n\nFor the second derivative we have\n\\begin{align}\n\\dfrac{\\mathrm{d} A}{\\mathrm{d} \\theta} & = \\dfrac{\\mathrm{d}}{\\mathrm{d} \\theta}\\left\\{\\log\\int\\exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x\\right\\} \\nonumber \\\\\n& = \\dfrac{\\frac{\\mathrm{d}}{\\mathrm{d} \\theta}\\int\\exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x}{\\int\\exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x} \\nonumber \\\\\n& = \\dfrac{\\int\\phi(x)exp\\left[\\theta\\phi(x)\\right]h(x)\\mathrm{d}x}{\\exp(A(\\theta))} \\nonumber \\\\\n& = \\int \\phi(x)\\exp\\left[\\theta\\phi(x)-A(\\theta)\\right]h(x)\\mathrm{d}x \\nonumber \\\\\n& = \\int \\phi(x)p(x)\\mathrm{d}x=\\mathbb{E}[\\phi(x)]\n\\end{align}\n\nFor the second derivative we have\n\\begin{align}\n\\dfrac{\\mathrm{d}^2 A}{\\mathrm{d} \\theta^2} & = \\int \\phi(x)\\exp\\left[\\theta\\phi(x)-A(\\theta)\\right]h(x)\\left[\\phi(x)-A'(\\theta)\\right]\\mathrm{d}x \\nonumber \\\\\n& = \\int \\phi(x)p(x)\\left[\\phi(x)-A'(\\theta)\\right]\\mathrm{d}x \\nonumber \\\\\n& = \\int \\phi^2(x)p(x)\\mathrm{d}x-A'(\\theta)\\int \\phi(x)p(x)\\mathrm{d}x \\nonumber \\\\\n& = \\mathbb{E}[\\phi^2(x)]-\\mathbb{E}[\\phi(x)]^2=\\mathrm{var}[\\phi(x)]\n\\end{align}\n\nIn the multivariate case, we have that\n\\begin{equation}\n\\dfrac{\\partial^2 A}{\\partial \\theta_i \\partial \\theta_j}=\\mathbb{E}[\\phi_i(x)\\phi_j(x)]-\\mathbb{E}[\\phi_i(x)]\\mathbb{E}[\\phi_j(x)]\n\\end{equation}\nand hence\n\\begin{equation}\n\\nabla^2A(\\vec{\\theta}) = \\mathrm{cov}[\\phi(\\vec{x})]\n\\end{equation}\n\nSince the covariance is positive definite, we see that $A(\\vec{\\theta})$ is a convex function (see Section \\ref{sec:Convexity}).\n\n\n\\subsection{MLE for the exponential family}\nThe likelihood of an exponential family model has the form\n\\begin{equation}\np(\\mathcal{D}|\\vec{\\theta})=\\left[\\prod\\limits_{i=1}^N h(\\vec{x}_i)\\right]g(\\vec{\\theta})^N\\exp\\left[\\vec{\\theta}^T\\left(\\sum\\limits_{i=1}^N \\phi(\\vec{x}_i)\\right)\\right]\n\\end{equation}\n\nWe see that the sufficient statistics are $N$ and\n\\begin{equation}\n\\phi(\\mathcal{D})=\\sum\\limits_{i=1}^N \\phi(\\vec{x}_i)=(\\sum\\limits_{i=1}^N \\phi_1(\\vec{x}_i),\\cdots,\\sum\\limits_{i=1}^N \\phi_K(\\vec{x}_i))\n\\end{equation}\n\nThe \\textbf{Pitman-Koopman-Darmois theorem} states that, under certain regularity conditions, the exponential family is the only family of distributions with finite sufficient statistics. (Here, finite means of a size independent of the size of the data set.)\n\nOne of the conditions required in this theorem is that the support of the distribution not be dependent on the parameter.\n\n\n\\subsection{Bayes for the exponential family}\n\\label{sec:Bayes-for-the-exponential-family}\nTODO\n\n\n\\subsubsection{Likelihood}\n\n\n\n\\subsection{Maximum entropy derivation of the exponential family *}\n\\label{sec:Maximum-entropy-derivation-of-the-exponential-family}\n\n\n\\section{Nonparametric Methods}\n\\subsection{Kernel density estimators}\n\\subsection{Nearest-neighbour methods}\n\n\n\\section{Joint probability distributions}\nGiven a \\textbf{multivariate random variable} or \\textbf{random vector} \\footnote{\\url{http://en.wikipedia.org/wiki/Multivariate_random_variable}} $X \\in \\mathbb{R}^D$, the \\textbf{joint probability distribution}\\footnote{\\url{http://en.wikipedia.org/wiki/Joint_probability_distribution}} is a probability distribution that gives the probability that each of $X_1, X_2, \\cdots,X_D$ falls in any particular range or discrete set of values specified for that variable. In the case of only two random variables, this is called a \\textbf{bivariate distribution}, but the concept generalizes to any number of random variables, giving a \\textbf{multivariate distribution}.\n\nThe joint probability distribution can be expressed either in terms of a \\textbf{joint cumulative distribution function} or in terms of a \\textbf{joint probability density function} (in the case of continuous variables) or \\textbf{joint probability mass function} (in the case of discrete variables). \n\n\n\\subsection{Covariance and correlation}\n\\begin{definition}\nThe \\textbf{covariance} between two rv’s $X$ and $Y$ measures the degree to which $X$ and $Y$ are (linearly) related. Covariance is defined as\n\\begin{equation}\n\\begin{split}\n\\mathrm{cov}[X,Y] & \\triangleq \\mathbb{E}\\left[(X-\\mathbb{E}[X])(Y-\\mathbb{E}[Y])\\right] \\\\\n         & =\\mathbb{E}[XY]-\\mathbb{E}[X]\\mathbb{E}[Y]\n\\end{split}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nIf $X$ is a $D$-dimensional random vector, its \\textbf{covariance matrix} is defined to be the following symmetric, positive definite matrix:\n\\begin{align}\n\\mathrm{cov}[\\vec{x}] & \\triangleq \\mathbb{E}\\left[(\\vec{x}-\\mathbb{E}[\\vec{x}])(\\vec{x}-\\mathbb{E}[\\vec{x}])^T\\right] \\\\\n       &  = \\left( \\begin{array}{cccc}\n           \\text{var}[\\vec{x_1}] & \\text{Cov}[\\vec{x_1},\\vec{x_2}] & \\cdots & \\text{Cov}[\\vec{x_1},\\vec{x_D}] \\\\\n           \\text{Cov}[\\vec{x_2},\\vec{x_1}] & \\text{var}[x_2] & \\cdots & \\text{Cov}[\\vec{x_2},\\vec{x_D}] \\\\\n\t\t   \\vdots & \\vdots & \\ddots & \\vdots \\\\\n           \\text{Cov}[\\vec{x_D},\\vec{x_1}] & \\text{Cov}[\\vec{x_D},\\vec{x_2}] & \\cdots & \\text{var}[\\vec{x_D}] \\end{array} \\right)\n\\end{align}\n\\end{definition}\nFor \n\n\\begin{definition}\nThe (Pearson) \\textbf{correlation coefficient} between $X$ and $Y$ is defined as\n\\begin{equation}\n\\text{corr}[X,Y] \\triangleq \\dfrac{\\text{Cov}[X,Y]}{\\sqrt{\\text{var}[X],\\text{var}[Y]}}\n\\end{equation}\n\\end{definition}\n\nA \\textbf{correlation matrix} has the form\n\\begin{equation}\n\\mathbf{R} \\triangleq \\left( \\begin{array}{cccc}\n           \\text{corr}[X_1,X_1] & \\text{corr}[X_1,X_2] & \\cdots & \\text{corr}[X_1,X_D] \\\\\n           \\text{corr}[X_2,X_1] & \\text{corr}[X_2,X_2] & \\cdots & \\text{corr}[X_2,X_D] \\\\\n\t\t   \\vdots & \\vdots & \\ddots & \\vdots \\\\\n           \\text{corr}[X_D,X_1] & \\text{corr}[X_D,X_2] & \\cdots & \\text{corr}[X_D,X_D] \\end{array} \\right)\n\\end{equation}\n\nThe correlation coefficient can viewed as a degree of linearity between $X$ and $Y$, see Figure \\ref{fig:Correlation-examples}.\n\\begin{figure*}[hbtp]\n\\centering\n    \\includegraphics[scale=.80]{Correlation-examples.png}\n\\caption{Several sets of $(x, y)$ points, with the Pearson correlation coefficient of $x$ and $y$ for each set. Note that the correlation reflects the noisiness and direction of a linear relationship (top row), but not the slope of that relationship (middle), nor many aspects of nonlinear relationships (bottom). N.B.: the figure in the center has a slope of 0 but in that case the correlation coefficient is undefined because the variance of $Y$ is zero.Source:\\url{http://en.wikipedia.org/wiki/Correlation}}\n\\label{fig:Correlation-examples} \n\\end{figure*}\n\n\\textbf{Uncorrelated does not imply independent}. For example, let $X \\sim U(-1,1)$ and $Y =X^2$. Clearly $Y$ is dependent on $X$(in fact, $Y$ is uniquely determined by $X$), yet one can show that corr$[X, Y]=0$. Some striking examples of this fact are shown in Figure \\ref{fig:Correlation-examples}. This shows several data sets where there is clear dependence between $X$ and $Y$, and yet the correlation coefficient is 0. A more general measure of dependence between random variables is mutual information, see Section TODO.\n\n\n\\subsection{Multivariate Gaussian distribution}\n\\label{sec:MVN}\nThe \\textbf{multivariate Gaussian} or \\textbf{multivariate normal}(MVN) is the most widely used joint probability density function for continuous variables. We discuss MVNs in detail in Chapter 4; here we just give some definitions and plots.\n\nThe pdf of the MVN in $D$ dimensions is defined by the following:\n\\begin{equation}\n\\mathcal{N}(\\vec{x}|\\vec{\\mu},\\Sigma) \\triangleq \\dfrac{1}{(2\\pi)^{D/2}|\\Sigma|^{1/2}}\\exp\\left[-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu})\\right]\n\\end{equation}\nwhere $\\vec{\\mu}=\\mathbb{E}[X] \\in \\mathbb{R}^D$ is the mean vector, and $\\Sigma=\\text{Cov}[X]$ is the $D \\times D$ covariance matrix. The normalization constant $(2\\pi)^{D/2}|\\Sigma|^{1/2}$ just ensures that the pdf integrates to 1.\n\nFigure \\ref{fig:2d-Gaussions} plots some MVN densities in 2d for three different kinds of covariance matrices. A full covariance matrix has A $D(D+1)/2$ parameters (we divide by 2 since $\\Sigma$ is symmetric). A diagonal covariance matrix has $D$ parameters, and has 0s in the off-diagonal terms. A spherical or isotropic covariance,$\\Sigma=\\sigma^2\\vec{I}_D$, has one free parameter.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-b.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-c.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-d.png}}\n\\caption{We show the level sets for 2d Gaussians. (a) A full covariance matrix has elliptical contours.(b) A diagonal covariance matrix is an axis aligned ellipse. (c) A spherical covariance matrix has a circular shape. (d) Surface plot for the spherical Gaussian in (c).}\n\\label{fig:2d-Gaussions} \n\\end{figure}\n\n\n\\subsection{Multivariate Student's t-distribution}\nA more robust alternative to the MVN is the multivariate Student's t-distribution, whose pdf is given by\n\\begin{align}\n& \\mathcal{T}(x|\\vec{\\mu},\\Sigma,\\nu) \\nonumber \\\\\n& \\triangleq \\dfrac{\\Gamma(\\frac{\\nu+D}{2})}{\\Gamma(\\frac{\\nu}{2})}\\dfrac{|\\Sigma|^{-\\frac{1}{2}}}{\\left(\\nu\\pi\\right)^{\\frac{D}{2}}}\\left[1+\\dfrac{1}{\\nu}\\left(\\vec{x}-\\vec{\\mu}\\right)^T\\Sigma^{-1}\\left(\\vec{x}-\\vec{\\mu}\\right)\\right]^{-\\frac{\\nu+D}{2}} \\\\\n&= \\dfrac{\\Gamma(\\frac{\\nu+D}{2})}{\\Gamma(\\frac{\\nu}{2})}\\dfrac{|\\Sigma|^{-\\frac{1}{2}}}{\\left(\\nu\\pi\\right)^{\\frac{D}{2}}}\\left[1+\\left(\\vec{x}-\\vec{\\mu}\\right)^T\\vec{V}^{-1}\\left(\\vec{x}-\\vec{\\mu}\\right)\\right]^{-\\frac{\\nu+D}{2}}\n\\end{align}\nwhere $\\Sigma$ is called the scale matrix (since it is not exactly the covariance matrix) and $\\vec{V}=\\nu\\Sigma$. This has fatter tails than a Gaussian. The smaller $\\nu$ is, the fatter the tails. As $\\nu \\rightarrow \\infty$, the distribution tends towards a Gaussian. The distribution has the following properties\n\\begin{equation}\n\\text{mean}=\\vec{\\mu} \\text{ , mode}=\\vec{\\mu} \\text{ , Cov}= \\dfrac{\\nu}{\\nu-2}\\Sigma\n\\end{equation}\n\n\n\\subsection{Dirichlet distribution}\nA multivariate generalization of the beta distribution is the \\textbf{Dirichlet distribution}, which has\nsupport over the probability simplex, defined by\n\\begin{equation}\nS_K=\\left\\{\\vec{x}:0 \\leq x_k \\leq 1,\\sum\\limits_{k=1}^K x_k=1\\right\\}\n\\end{equation}\n\nThe pdf is defined as follows:\n\\begin{equation}\n\\text{Dir}(\\vec{x}|\\vec{\\alpha}) \\triangleq \\dfrac{1}{B(\\vec{\\alpha})}\\prod\\limits_{k=1}^K x_k^{\\alpha_k-1}\\mathbb{I}(\\vec{x} \\in S_K)\n\\end{equation}\nwhere $B(\\alpha_1,\\alpha_2,\\cdots,\\alpha_K)$ is the natural generalization of the beta function to $K$ variables:\n\\begin{equation}\nB(\\alpha) \\triangleq \\dfrac{\\prod_{k=1}^K \\Gamma(\\alpha_k)}{\\Gamma(\\alpha_0)} \\text{ where } \\alpha_0 \\triangleq \\sum_{k=1}^K \\alpha_k\n\\end{equation}\n\nFigure \\ref{fig:3d-Dirichlet} shows some plots of the Dirichlet when $K=3$, and Figure \\ref{fig:5d-Dirichlet} for some sampled probability vectors. We see that $\\alpha_0$ controls the strength of the distribution (how peaked it is), and theαkcontrol where the peak occurs. For example, Dir$(1,1,1)$ is a uniform distribution, Dir$(2,2,2)$ is a broad distribution centered at $(1/3,1/3,1/3)$, and Dir$(20,20,20)$ is a narrow distribution centered at $(1/3,1/3,1/3)$.If $\\alpha_k < 1$ for all $k$, we get “spikes” at the corner of the simplex.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{3d-Dirichlet-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{3d-Dirichlet-b.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{3d-Dirichlet-c.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{3d-Dirichlet-d.png}}\n\\caption{(a) The Dirichlet distribution when $K=3$ defines a distribution over the simplex, which can be represented by the triangular surface. Points on this surface satisfy $0 \\leq \\theta_k \\leq 1$ and $\\sum_{k=1}^K \\theta_k=1$. (b) Plot of the Dirichlet density when $\\vec{\\alpha}=(2,2,2)$. (c) $\\vec{\\alpha}=(20,2,2)$.}\n\\label{fig:3d-Dirichlet} \n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[$\\vec{\\alpha}=(0.1,\\cdots,0.1)$. This results in very sparse distributions, with many 0s.]{\\includegraphics[scale=.50]{5d-Dirichlet-a.png}} \\\\\n\\subfloat[$\\vec{\\alpha}=(1,\\cdots,1)$. This results in more uniform (and dense) distributions.]{\\includegraphics[scale=.50]{5d-Dirichlet-b.png}}\n\\caption{Samples from a 5-dimensional symmetric Dirichlet distribution for different parameter values.} \n\\label{fig:5d-Dirichlet} \n\\end{figure}\n\nFor future reference, the distribution has these properties\n\\begin{equation}\\label{eqn:Dirichlet-properties}\n\\mathbb{E}(x_k)=\\dfrac{\\alpha_k}{\\alpha_0} \\text{, mode}[x_k]=\\dfrac{\\alpha_k-1}{\\alpha_0-K} \\text{, var}[x_k]=\\dfrac{\\alpha_k(\\alpha_0-\\alpha_k)}{\\alpha_0^2(\\alpha_0+1)}\n\\end{equation}\n\n\n\\section{Transformations of random variables}\nIf $\\vec{x} \\sim P()$ is some random variable, and $\\vec{y}=f(\\vec{x})$, what is the distribution of $Y$? This is the question we address in this section.\n\n\n\\subsection{Linear transformations}\nSuppose $g()$ is a linear function: \n\\begin{equation}\ng(\\vec{x})=A\\vec{x}+b\n\\end{equation}\n\nFirst, for the mean, we have\n\\begin{equation}\n\\mathbb{E}[\\vec{y}]=\\mathbb{E}[A\\vec{x}+b]=A\\mathbb{E}[\\vec{x}]+b\n\\end{equation}\nthis is called the \\textbf{linearity of expectation}.\n\nFor the covariance, we have\n\\begin{equation}\n\\text{Cov}[\\vec{y}]=\\text{Cov}[A\\vec{x}+b]=A\\Sigma A^T\n\\end{equation}\n\n\n\\subsection{General transformations}\n\\label{sec:General-transformations}\nIf $X$ is a discrete rv, we can derive the pmf for $y$ by simply summing up the probability mass for all the $x$’s such that $f(x)=y$:\n\\begin{equation}\\label{eqn:transformation-discrete}\np_Y(y)=\\sum\\limits_{x:g(x)=y}p_X(x)\n\\end{equation}\n\nIf $X$ is continuous, we cannot use Equation \\ref{eqn:transformation-discrete} since $p_X(x)$ is a density, not a pmf, and we cannot sum up densities. Instead, we work with cdf’s, and write\n\\begin{equation}\nF_Y(y)=P(Y \\leq y)=P(g(X) \\leq y)=\\int\\limits_{g(X) \\leq y} f_X(x)\\mathrm{d}x\n\\end{equation}\n\nWe can derive the pdf of $Y$ by differentiating the cdf:\n\\begin{equation}\\label{eqn:General-transformations}\nf_Y(y)=f_X(x)|\\dfrac{dx}{dy}|\n\\end{equation}\n\nThis is called \\textbf{change of variables} formula. We leave the proof of this as an exercise. \n\nFor example, suppose $X \\sim U(−1,1)$, and $Y=X^2$. Then $p_Y(y)=\\dfrac{1}{2}y^{-\\frac{1}{2}}$.\n\n\n\\subsubsection{Multivariate change of variables *}\nLet $f$ be a function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^n$, and let $\\vec{y}=f(\\vec{x})$. Then its Jacobian matrix $\\vec{J}$ is given by\n\\begin{equation}\n\\vec{J}_{\\vec{x} \\rightarrow \\vec{y}} \\triangleq \\frac{\\partial \\vec{y}}{\\partial \\vec{x}} \\triangleq \\left(\\begin{array}{ccc}\n\\frac{\\partial y_1}{\\partial x_1} & \\cdots & \\frac{\\partial y_1}{\\partial x_n} \\\\\n\\vdots & \\vdots & \\vdots \\\\\n\\frac{\\partial y_n}{\\partial x_1} & \\cdots & \\frac{\\partial y_n}{\\partial x_n}\n\\end{array}\\right)\n\\end{equation}\n$|\\mathrm{det}(\\vec{J})|$ measures how much a unit cube changes in volume when we apply $f$.\n\nIf $f$ is an invertible mapping, we can define the pdf of the transformed variables using the Jacobian of the inverse mapping $\\vec{y} \\rightarrow \\vec{x}$:\n\\begin{equation}\\label{eqn:Multivariate-transformation}\np_y(\\vec{y})=p_x(\\vec{x})|\\mathrm{det}(\\frac{\\partial \\vec{x}}{\\partial \\vec{y}})|=p_x(\\vec{x})|\\mathrm{det}(\\vec{J}_{\\vec{y} \\rightarrow \\vec{x}})|\n\\end{equation}\n\n\n\\subsection{Central limit theorem}\nGiven $N$ random variables $X_1,X_2,\\cdots,X_N$, each variable is \\textbf{independent and identically distributed}\\footnote{\\url{http://en.wikipedia.org/wiki/Independent_identically_distributed}}(\\textbf{iid} for short), and each has the same mean $\\mu$ and variance $\\sigma^2$, then\n\\begin{equation}\n\\dfrac{\\sum\\limits_{i=1}^n X_i-N\\mu}{\\sqrt{N}\\sigma} \\sim \\mathcal{N}(0,1)\n\\end{equation}\nthis can also be written as\n\\begin{equation}\n\\dfrac{\\bar{X}-\\mu}{\\sigma/\\sqrt{N}} \\sim \\mathcal{N}(0,1) \\quad \\text{, where } \\bar{X} \\triangleq \\dfrac{1}{N}\\sum\\limits_{i=1}^n X_i\n\\end{equation}\n\n\n\\section{Monte Carlo approximation}\n\\label{sec:Monte-Carlo-approximation}\nIn general, computing the distribution of a function of an rv using the change of variables formula can be difficult. One simple but powerful alternative is as follows. First we generate $S$ samples from the distribution, call them $x_1,\\cdots,x_S$. (There are many ways to generate such samples; one popular method, for high dimensional distributions, is called Markov chain Monte Carlo or MCMC; this will be explained in Chapter TODO.) Given the samples, we can approximate the distribution of $f(X)$ by using the empirical distribution of $\\left\\{f(x_s)\\right\\}_{s=1}^S$. This is called a \\textbf{Monte Carlo approximation}\\footnote{\\url{http://en.wikipedia.org/wiki/Monte_Carlo_method}}, named after a city in Europe known for its plush gambling casinos.\n\nWe can use Monte Carlo to approximate the expected value of any function of a random variable. We simply draw samples, and then compute the arithmetic mean of the function applied to the samples. This can be written as follows:\n\\begin{equation}\n\\mathbb{E}[g(X)]=\\int g(x)p(x)\\mathrm{d}x \\approx \\dfrac{1}{S}\\sum\\limits_{s=1}^S f(x_s)\n\\end{equation}\nwhere $x_s \\sim p(X)$.\n\nThis is called \\textbf{Monte Carlo integration}\\footnote{\\url{http://en.wikipedia.org/wiki/Monte_Carlo_integration}}, and has the advantage over numerical integration (which is based on evaluating the function at a fixed grid of points) that the function is only evaluated in places where there is non-negligible probability.\n\n\n\\section{Information theory}\n\n\\subsection{Entropy}\n\\label{sec:Entropy}\nThe entropy of a random variable $X$ with distribution $p$, denoted by $\\mathbb{H}(X)$ or sometimes $\\mathbb{H}(p)$, is a measure of its uncertainty. In particular, for a discrete variable with $K$ states, it is defined by\n\\begin{equation}\n\\mathbb{H}(X) \\triangleq -\\sum\\limits_{k=1}^{K}{p(X=k)\\log_2p(X=k)}\n\\end{equation}\n\nUsually we use log base 2, in which case the units are called \\textbf{bits}(short for binary digits). If we use log base $e$ , the units are called \\textbf{nats}. \n\nThe discrete distribution with maximum entropy is the uniform distribution (see Section XXX for a proof). Hence for a K-ary random variable, the entropy is maximized if $p(x = k)=1/K$; in this case, $\\mathbb{H}(X)=\\log_2K$. \n\nConversely, the distribution with minimum entropy (which is zero) is any \\textbf{delta-function} that puts all its mass on one state. Such a distribution has no uncertainty.\n\n\n\\subsection{KL divergence}\nOne way to measure the dissimilarity of two probability distributions, $p$ and $q$ , is known as the \\textbf{Kullback-Leibler divergence}(\\textbf{KL divergence})or \\textbf{relative entropy}. This is defined as follows:\n\\begin{equation}\n\\mathbb{KL}(P||Q) \\triangleq \n\\sum\\limits_{x}{p(x)\\log_2\\dfrac{p(x)}{q(x)}}\n\\end{equation}\nwhere the sum gets replaced by an integral for pdfs\\footnote{The KL divergence is not a distance, since it is asymmetric. One symmetric version of the KL divergence is the \\textbf{Jensen-Shannon divergence}, defined as $JS(p_1,p_2)=0.5\\mathbb{KL}(p_1||q)+0.5\\mathbb{KL}(p_2||q)$,where $q=0.5p_1+0.5p_2$}. The KL divergence is only defined if P and Q both sum to 1 and if $q(x)=0$ implies $p(x)=0$ for all $x$(absolute continuity). If the quantity  $0\\ln0$ appears in the formula, it is interpreted as zero because $\\lim\\limits_{x \\to 0}x\\ln x$. We can rewrite this as\n\\begin{equation}\\begin{split}\n\\mathbb{KL}(p||q) & \\triangleq \\sum\\limits_{x}{p(x)\\log_2p(x)}-\\sum\\limits_{k=1}^{K}{p(x)\\log_2q(x)} \\\\\n    & =\\mathbb{H}(p)-\\mathbb{H}(p,q)\n\\end{split}\\end{equation}\nwhere $\\mathbb{H}(p,q)$ is called the \\textbf{cross entropy},\n\\begin{equation}\\label{eqn:cross-entropy}\n\\mathbb{H}(p,q)=\\sum\\limits_{x}{p(x)\\log_2q(x)}\n\\end{equation}\n\nOne can show (Cover and Thomas 2006) that the cross entropy is the average number of bits needed to encode data coming from a source with distribution $p$ when we use model $q$ to define our codebook. Hence the “regular” entropy $\\mathbb{H}(p)=\\mathbb{H}(p,p)$, defined in section \\S \\ref{sec:Entropy},is the expected number of bits if we use the true model, so the KL divergence is the diference between these. In other words, the KL divergence is the average number of \\emph{extra} bits needed to encode the data, due to the fact that we used distribution $q$ to encode the data instead of the true distribution $p$.\n\nThe “extra number of bits” interpretation should make it clear that $\\mathbb{KL}(p||q) \\geq 0$, and that the KL is only equal to zero if $q = p$. We now give a proof of this important result.\n\n\\begin{theorem}\n(\\textbf{Information inequality}) $\\mathbb{KL}(p||q) \\geq 0 \\text{ with equality iff } p=q$.\n\\end{theorem}\n\nOne important consequence of this result is that \\emph{the discrete distribution with the maximum\nentropy is the uniform distribution}.\n\n\n\\subsection{Mutual information}\n\\label{sec:Mutual-information}\n\\begin{definition}\n\\textbf{Mutual information} or \\textbf{MI}, is defined as follows:\n\\begin{equation}\\begin{split}\n\\mathbb{I}(X;Y) & \\triangleq \\mathbb{KL}(P(X,Y)||P(X)P(X)) \\\\\n    & =\\sum\\limits_x\\sum\\limits_yp(x,y)\\log\\dfrac{p(x,y)}{p(x)p(y)}\n\\end{split}\\end{equation}\nWe have $\\mathbb{I}(X;Y) \\geq 0$ with equality if $P(X,Y)=P(X)P(Y)$. That is, the MI is zero if the variables are independent.\n\\end{definition}\n\nTo gain insight into the meaning of MI, it helps to re-express it in terms of joint and conditional entropies. One can show that the above expression is equivalent to the following:\n\\begin{eqnarray}\n\\mathbb{I}(X;Y)&=&\\mathbb{H}(X)-\\mathbb{H}(X|Y)\\\\\n               &=&\\mathbb{H}(Y)-\\mathbb{H}(Y|X)\\\\\n               &=&\\mathbb{H}(X)+\\mathbb{H}(Y)-\\mathbb{H}(X,Y)\\\\\n               &=&\\mathbb{H}(X,Y)-\\mathbb{H}(X|Y)-\\mathbb{H}(Y|X)\n\\end{eqnarray}\nwhere $\\mathbb{H}(X)$ and $\\mathbb{H}(Y)$ are the \\textbf{marginal entropies}, $\\mathbb{H}(X|Y)$ and $\\mathbb{H}(Y|X)$ are the \\textbf{conditional entropies}, and $\\mathbb{H}(X,Y)$ is the \\textbf{joint entropy} of $X$ and $Y$, see Fig. \\ref{fig:mi}\\footnote{\\url{http://en.wikipedia.org/wiki/Mutual_information}}.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.25]{mutual-information.png}\n\\caption{Individual $\\mathbb{H}(X),\\mathbb{H}(Y)$, joint $\\mathbb{H}(X,Y)$, and conditional entropies for a pair of correlated subsystems $X,Y$ with mutual information $\\mathbb{I}(X;Y)$.}\n\\label{fig:mi} \n\\end{figure}\n\nIntuitively, we can interpret the MI between $X$ and $Y$ as the reduction in uncertainty about $X$ after observing $Y$, or, by symmetry, the reduction in uncertainty about $Y$ after observing $X$.\n\nA quantity which is closely related to MI is the \\textbf{pointwise mutual information} or \\textbf{PMI}. For two events (not random variables) $x$ and $y$, this is defined as\n\\begin{equation}\nPMI(x,y) \\triangleq \\log\\dfrac{p(x,y)}{p(x)p(y)}=\\log\\dfrac{p(x|y)}{p(x)}=\\log\\dfrac{p(y|x)}{p(y)}\n\\end{equation}\n\nThis measures the discrepancy between these events occuring together compared to what would be expected by chance. Clearly the MI of $X$ and $Y$ is just the expected value of the PMI. Interestingly, we can rewrite the PMI as follows:\n\\begin{equation}\nPMI(x,y)=\\log\\dfrac{p(x|y)}{p(x)}=\\log\\dfrac{p(y|x)}{p(y)}\n\\end{equation}\n\nThis is the amount we learn from updating the prior $p(x)$ into the posterior $p(x|y)$ , or equivalently, updating the prior $p(y)$ into the posterior $p(y |x)$ .", "meta": {"hexsha": "09d2b0ad211714f32573de347dc6ecb955ac721c", "size": 82130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/ProbabilityAndStatistics.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/ProbabilityAndStatistics.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/ProbabilityAndStatistics.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": 59.9926953981, "max_line_length": 881, "alphanum_fraction": 0.7070741507, "num_tokens": 26597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6805651081903223}}
{"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{tfrridh}\n\\section*{\\hspace*{-1.6cm} tfrridh}\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}\nReduced Interference Distribution with Hanning kernel.\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] = tfrridh(x)\n[tfr,t,f] = tfrridh(x,t)\n[tfr,t,f] = tfrridh(x,t,N)\n[tfr,t,f] = tfrridh(x,t,N,g)\n[tfr,t,f] = tfrridh(x,t,N,g,h)\n[tfr,t,f] = tfrridh(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        Reduced Interference Distribution with a kernel based on the\n        Hanning window.  {\\ty tfrridh} computes either the distribution of\n        a discrete-time signal {\\ty x}, or the cross representation between\n        two signals. This distribution has the following expression :\\\\\n%\\begin{multline*}\n\\begin{eqnarray*}\nRIDH_x(t,\\nu)&=&\\int_{-\\infty}^{+\\infty} h(\\tau)\\,R_x(t,\\tau)\\,\ne^{-j2\\pi\\nu\\tau}\\ d\\tau,\\\\\n{\\rm with}\\quad \nR_x(t,\\tau)&=&\n\\int_{-\\frac{|\\tau|}{2}}^{+\\frac{|\\tau|}{2}} \\frac{g(v)}{|\\tau|}\\ \n\\left(1+\\cos(\\frac{2\\pi v}{\\tau})\\right)\n\\ x(t+v+\\frac{\\tau}{2})\\ x^*(t+v-\\frac{\\tau}{2})\\,dv.\n\\end{eqnarray*}\n%\\end{multline*}\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-RIDH, or {\\ty [x1,x2]} if cross-RIDH ({\\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 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 output arguments, {\\ty tfrridh} 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(31,'rect'); h=window(63,'rect');  \n         tfrridh(sig,1:128,128,g,h,0);\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] J. Jeong, W. Williams ``Kernel Design for Reduced Interference\nDistributions'' IEEE Trans. on Signal Proc., Vol. 40, No. 2, pp. 402-412,\nFeb. 1992.\n\\end{minipage}\n\n", "meta": {"hexsha": "016e7a5de1e369f2e06cc6a963f7680eb5e90f9d", "size": 3147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrridh.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/tfrridh.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/tfrridh.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.5533980583, "max_line_length": 136, "alphanum_fraction": 0.5910390848, "num_tokens": 1141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6804247677270251}}
{"text": "\\section{Data Analysis and Results}\n% description of any analytically steps: parameter estimation, error estimation, model-fitting...\n\n\n\n\\subsection{Single Dish's Estimation of the Sun's Angular Diameter}\n\nWe  obtain a first estimative of the angular diameter of the Sun by comparing the Fourier components of the single dish measurements of the Sun and of the satellite. The size of the solar disk is the deconvolution of the single-dish solar profile with the single-dish satellite profile,\n$$FFT(\\Phi_{sun}^{Sin}) = \\frac{FFT^{Sin}_{sun}}{FFT^{Sin}_{sat}},$$\nresulting on the figure \\ref{11}. We approximate the  central peak by a normal distribution and calculate the {\\it full width at half maximum} (FWHM), as rough value for the  diameter of the Sun, $\\Phi^{Sin}_{sun} \\approx 25' $.\n\n\n \\begin{figure}[htb]\n\\begin{center}\n \\includegraphics[scale=1.2]{plots/single.pdf}\n\\caption{The Sun's single dish Fourier component  over the satellite's. We  obtain a first calculation of the angular diameter of the Sun by calculating the FWHM of the central peak and Fourier transforming it. }\n\\label{11}\n\\end{center}\n\\end{figure}\n\n\\bigskip\n\\subsection{Calculation of the  Baselines  and Visibility Functions}\nWe calculate the baseline lengths for the set of five measurements of the Sun and of the satellite with the equation (\\ref{BB}), converting the object's azimuth to the declination value, as in equation (\\ref{dec}). The fringe frequency was numerically calculated by the Fourier transform profiles of the the total power data. The final values are shown in the table \\ref{baselines} in the appendix.\n\nFrom the same Fourier profiles we calculated the $P_{max}$ and $P_{min}$ points, as shown in the session \\ref{visb}. The visibility functions are automatically obtained from the equation (\\ref{vis}). \n\n\n\n\n\n\\bigskip\n\\subsection{Obtaining the $\\Phi_{sun}$ by Taylor-Approximating the Visibility Function} \\label{taylormet}\n\nThe first method to estimate the value of the diameter of the sun is by plunging the values we have obtained for the visibility function into a Taylor approximation of the visibility equation (\\ref{vissinc}),\n$$ V_{sun}^{Tay}  = \\frac{\\sin(x)}{x} \\approx \\frac{x-x^3/6}{x} = 1 - \\frac{x^2}{6}$$\nwhere $x=\\pi B_{\\lambda} \\Phi^{Tay}_{sun} $.\n\nThis gives  a value in radians for the  diameter of the Sun for one baseline, and it can later converted into arc minutes. A {\\it Fast Fourier Transform} (FFT) of the fringe pattern shows a peak at the frequency of the fringe period $\\Delta t$. Together with the equation (\\ref{BB}), the angular diameter of the Sun can be calculated by\n\\begin{equation}\n\\Phi_{sun}^{Tay} = \\frac{\\sqrt{6}}{\\pi} \\frac{1}{B_{\\lambda}} \\sqrt{1 - V_{sun}^{Tay}(B_{\\lambda})}.\n\\label{vistay}\n\\end{equation}\n\nThe mean and the standard deviation  for the five values obtained from this method results on $\\Phi^{Tay}_{sun} = 37.43' \\pm 5.33'$.\n\n\n\n\\bigskip\n\n\\subsection{Obtaining $\\Phi_{sun}$ by Fitting the Fourier Components} \\label{fitmet}\n\n\nThe second method to calculate the angular diameter of the sun is based on the fact that each measurement gives one Fourier component for baseline length. In the observations we obtain five Fourier components, $V_{sun}(B_{\\lambda})$, which are a Fourier transformation of the energy density distribution, $\\varepsilon(\\theta_0)$. \n\nPlotting   $V_{sun}(B_{\\lambda})$ vs. $B_{\\lambda}$  exhibits  the Fourier transformation of the object structure. Since the structure of the Sun should be a {\\it top-hat function}, the resulting plot (for its Fourier transformation) is exactly the {\\it sinc function},\n$$V^{fit}_{sun}(B_{\\lambda}) = \\mbox{ sinc }(B_{\\lambda} {\\Phi^{fit}_{sun}}),$$\n we saw in the equation (\\ref{vissinc}). The sinc function sinc(x), also called the {\\it sampling function} and  arises frequently in signal processing and the theory of Fourier transforms \\cite{wiki}. \n\nWe plot the Fourier components of the visibility function versus their baseline lengths, shown in the figure \\ref{sing}. The fit gives the value of  $\\Phi^{Fit}_{sun}= 32.77' \\pm 5.28'$.\n\n\n\n\n \\begin{figure}[htb]\n\\begin{center}\n \\includegraphics[scale=0.85]{plots/sinc3.png}\n \\includegraphics[scale=0.85]{plots/sinc1.pdf}\n\\caption{The Fourier components of the visibility function versus baselines, which is fitted by a sinc function, giving the value of the angular diameter of the sun. }\n\\label{sing}\n\\end{center}\n\\end{figure}\n\n\n\n\\bigskip\n\\subsection{Chi-Squared Fitting}\nWe use our knowledge of the {\\it variance} (the measure of how far a set of numbers is spread out) of the measurements to fit it statistically by using the weighted sum of squared errors:\n$$X^2 = \\sum_i \\frac{(O_i-E_i)^2}{\\sigma_i^2}.$$\n\nWe assume that the variances, $\\sigma^i$,  or our measurements are Gaussian functions and the the above equation will follow a {\\it chi-squared distribution}. We obtain $\\chi^2 = 12.3$ for the previous analysis.\n", "meta": {"hexsha": "c888299eb3711f6641c95b3fa5fc37c5a2872422", "size": 4896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/dataana.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": "2019-10-28T03:13:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-08T23:54:22.000Z", "max_issues_repo_path": "tex/dataana.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/dataana.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": 60.4444444444, "max_line_length": 398, "alphanum_fraction": 0.7483660131, "num_tokens": 1265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6803009872308776}}
{"text": "\\chapter{Formulation by Babu, Krishnan and Paleri}\n\\label{chap:chapter3}\n\nOne of the problems with other former approaches to Herbrand \nequivalence is that most of the alogrithms are based on fix point \ncomputations. But the classical definition of Herbrand equivalence is \nnot a fix point based definition making it difficult to prove their \nprecision or completeness. Babu, Krishnan and Paleri \\cite{Babu} gave \na new lattice theoretic formulation of Herbrand equivalences and \nproved its equivalence to the classical version.\n\nThe paper defines a congruence relation on the set of all possible \nexpressions and shows that the set of all congruences form a complete \nlattice. Then for a given dataflow framework with $n$ program points, \na continuous composite transfer function is defined over the $n$-fold \nproduct of the above lattice such that the maximum fix point of the \nfunction yields the set of Herbrand equivalence classes at various \nprogram points. Finally, equivalence of this approach to the \nclassical meet over all path definition of Herbrand equivalence is \nestablished.\n\nBelow is a brief summary of the developments in the paper, for more \ndetailed approach and proofs and for equivalence to MOP characterization \nrefer to \\cite{Babu}.\n\n\\section{Program Expressions}\n\\label{sec:ProgramExpressions}\n\nLet $\\mathcal C$ and $\\mathcal X$ be the set of constants and variables \noccurring in the program respectively. The program expressions (terms) \ncan be described as \n$$t\\ ::=\\ c\\ \\mid\\ x\\ \\mid\\ t_1 + t_2$$\nwhere $c \\in \\mathcal C$ and $x \\in \\mathcal X$.\n\n\\section{Congruence Relation}\n\\label{sec:CongruenceRelation}\nLet $\\mathcal T$ be the set of all program terms. A partition $\\mathcal P$ of terms \nin $\\mathcal T$ is said to be a congruence (of terms) if \n\\begin{itemize} \\tightlist\n    \\item For $t$, $t'$, $s$, $s'$ $\\in$ $\\mathcal T$, $t' \\cong t$ and $s' \\cong s$ iff $t' + s' \\cong t + s$. \n    \\item For $c \\in \\mathcal C$, $t \\in \\mathcal T$, if $t \\cong c$ then either $t = c$ or $t \\in \\mathcal X$.\n\\end{itemize}\nLet $\\mathcal G(\\mathcal T)$ be the set of all congruences over $\\mathcal T$. \nAn ordering is defined over $\\mathcal G(\\mathcal T)$ as $\\mathcal P_1 \\preceq \\mathcal P_2$ for $\\mathcal P_1, \\mathcal P_2 \\in \\mathcal G(\\mathcal T)$, if \n$\\forall \\mathcal A_1 \\in \\mathcal P_1, \\ \\exists \\mathcal A_2 \\in \\mathcal P_2$ \nsuch that $\\mathcal A_1 \\subseteq \\mathcal A_2$. \\\\\nAlso binary \\textbf{confluence operation ($\\land$)} is defined on $\\mathcal G(\\mathcal T)$ as\n$$\\mathcal P_1 \\land \\mathcal P_2\\ =\\ \\{\\mathcal A_i \\cap \\mathcal B_j\\ \\mid\\ \\mathcal A_i \\in \\mathcal P_1,\\ \\mathcal B_j \\in \\mathcal P_2 \\text{ and } \\mathcal A_i \\cap \\mathcal B_j \\neq \\phi\\}$$\nFinally $\\mathcal G(\\mathcal T)$ is extended to $\\overline{\\mathcal G(\\mathcal T)}$ \nby introducing an abstract congruence $\\top$ satisfying \n$\\mathcal P \\land \\top = \\top, \\forall \\mathcal P \\in \\overline{\\mathcal G(\\mathcal T)}$.\nAlso the congruence in which every element is in a separate class, is denoted as \n$\\bot$.\\\\ \nWith these definitions, $(\\overline{\\mathcal G(\\mathcal T)}, \\preceq, \\bot, \\top)$ \nforms a complete lattice, with $\\land$ as its \\textbf{meet operator}.\n\n\\section{Transfer Function}\n\\label{sec:TransferFunction}\nAn assignment $y := \\beta$ transforms a congruence $\\mathcal P$ to another \ncongruence $\\mathcal P'$. This can be described in the form of \\textbf{transfer function} \n$f_{y := \\beta}:\\mathcal G(\\mathcal T) \\to \\mathcal G(\\mathcal T)$, given by\n\\begin{itemize} \\tightlist\n    \\item $\\mathcal B_i = \\{t \\in \\mathcal T\\ |\\ t[y \\leftarrow \\beta] \\in \\mathcal A_i\\}, \\text{ for each } \\mathcal A_i \\in \\mathcal P$\n    \\item $f_{y := \\beta}(\\mathcal P) = \\{\\mathcal B_i\\ | \\ \\mathcal B_i \\neq \\phi\\}$\n\\end{itemize}\nThis definition is extended to form \\textbf{extended transfer function}, \n$\\overline{f}_{y := \\beta} : \\overline{\\mathcal G(\\mathcal T)} \\to \\overline{\\mathcal G(\\mathcal T)}$ \nby defining $\\overline{f}_{y := \\beta}(\\top)\\ =\\ \\top$, otherwise \n$\\overline{f}_{y := \\beta}(\\mathcal P) = f_{y := \\beta}(\\mathcal P)$.\nThe extended transfer function is \\textbf{distributive}, \\textbf{monotonic} and \n\\textbf{continuous}.\n\n\\section{Non Deterministic Assignment}\n\\label{sec:NonDeterministicAssignment}\nAn assignment $y := *$ also transforms a congruence $\\mathcal P$ to another \ncongruence $\\mathcal P'$. This can be described in the form of \\textbf{transfer function} \n$f_{y := *}:\\mathcal G(\\mathcal T) \\to \\mathcal G(\\mathcal T)$, given by\n$\\forall t, t' \\in \\mathcal T,\\ t \\cong_{f(\\mathcal P)} t'$, (here \n$f(\\mathcal P) = f_{y := *}(\\mathcal P)$ for simplicity) iff\n\\begin{itemize} \\tightlist\n    \\item $t \\cong_{\\mathcal P} t'$\n    \\item $\\forall \\beta \\in (\\mathcal T \\setminus \\mathcal T(y)),\\ t[y \\leftarrow \\beta] \\cong_{\\mathcal P} t'[y \\leftarrow \\beta]$\n\\end{itemize}\nAs before this transfer function is extended to \n$\\overline{f}_{y := *} : \\overline{\\mathcal G(\\mathcal T)} \\to \\overline{\\mathcal G(\\mathcal T)}$ \nby defining $\\overline{f}_{y := *}(\\top)\\ =\\ \\top$, otherwise \n$\\overline{f}_{y := *}(\\mathcal P) = f_{y := *}(\\mathcal P)$. The function \n$\\overline{f}_{y := *}$ is also \\textbf{continuous}.\n\n\\section{Dataflow Analysis Framework}\n\\label{sec:DataflowAnalysisFramework}\nA dataflow framework over $\\mathcal T$ is $\\mathcal D = (G, \\mathcal F)$ where \n$G(V, E)$ is the control flow graph associated with the program and $\\mathcal F$ \nis a collection of transfer function associated with program points.\n\n\\section{Herbrand Congruence Function}\n\\label{sec:HerbrandCongruenceFunction}\nThe Herbrand congruence function \n$\\mathcal H_{\\mathcal D} : V(G) \\to \\overline{\\mathcal G(\\mathcal T)}$ \ngives the Herbrand congruence associated with each program point and \nis defined to be \\textbf{the maximum fix point} of the \\textbf{continuous\ncomposite transfer function} \n$f_{\\mathcal D} : \\overline{\\mathcal G(\\mathcal T)}^n \\to \\overline{\\mathcal G(\\mathcal T)}^n$, \nwhere $\\overline{\\mathcal G(\\mathcal T)}^n$ is the product lattice, \n$f_{\\mathcal D}$ is a function satisfying $\\pi_k \\circ f_{\\mathcal D} = f_k$. Here $\\pi_k$ is the projection map\nand $f_k : \\overline{\\mathcal G(\\mathcal T)}^n \\to \\overline{\\mathcal G(\\mathcal T)}$ \nis defined as follows \n\\begin{itemize} \\tightlist\n    \\item   If $k = 1$, the entry point of the program $f_k = \\bot$.\n    \\item   If $k$ is a function point with \\texttt{Pred}($k$) = $\\{j\\}$, then \n    $f_k = h_k \\circ \\pi_j$ where $h_k$ is the extended transfer function \n    corresponding to function point $k$.\n    \\item   If $k$ is a confluence point with \\texttt{Pred}($k$) = $\\{i, j\\}$, \n    then $f_k = \\pi_{i, j}$, where $\\pi_{i, j}:\\overline{\\mathcal G(\\mathcal T)}^n \\to \\overline{\\mathcal G(\\mathcal T)}$ \n    is given by $\\pi_{i,j}(\\mathcal P_1,\\ \\dots,\\ \\mathcal P_n) = \\mathcal P_i \\land \\mathcal P_j$.\n\\end{itemize}\n", "meta": {"hexsha": "46c579b9eb396dc1d592ea136161ea7c78327097", "size": 6834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Rep_End_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_End_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_End_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": 58.4102564103, "max_line_length": 197, "alphanum_fraction": 0.7020778461, "num_tokens": 2195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6803009788415104}}
{"text": "\n\\section{A* Search Algorithm}\n\\label{sec:aStar}\n\nThe A* search algorithm has been used in this project to find a route to the goal. \n\nThe input to the algorithm is a matrix which consist of areas where the robot  can go and not go. The matrix also contains the information of the robots' position, and a goal for the robot.\n\n\\begin{lstlisting}[caption={An example of the matrix which the A* uses as input.}, label=a_star]\nchar[,] matrix = new char[,] {{'-', 'S', '-', '-', 'X'},\n\t\t\t\t\t\t\t  {'-', 'X', '-', 'X', '-'},\n\t\t\t\t\t\t\t  {'-', '-', 'X', '-', 'X'},\n\t\t\t\t\t\t\t  {'X', '-', 'X', 'E', '-'},\n\t\t\t\t\t\t\t  {'-', '-', '-', '-', 'X'}};\n\\end{lstlisting}\n\nIn listing \\ref{a_star} the 'X's marks places the robot can not move through. The 'S' is the position of the robot, and 'E' is the goal. The array itself is a multidimensional char array.\n\nThe nodes in the algorithm consist not only of coordinate x and y. The nodes also needs to contain a reference to its parent node (where it came from). This is used to backtrace the route. The node also needs to contain the information g(n) which is the cost of the path from the start node to node n. The node also contain h(n) which is a heuristic that estimates the cost of the cheapest path from n to the goal 'E'. The last property of the node is f(n) and f(n) = g(n) + h(n).\n\nThe g(n) is calculated by finding the euclidean distance between the start position and current position. This is shown in listing \\ref{g_n}.\n\n\\begin{lstlisting}[caption={Calculation of g(n).}, label=g_n]\nMath.Abs(Math.Sqrt((nbrX - startX) ^ 2 + (nbrY - startY) ^ 2))\n\\end{lstlisting}\n\nThe h(n) which is the heuristics and it is calculated as shown in listing \\ref{h_n}. \n\n\\begin{lstlisting}[caption={Calculation of h(n).}, label=h_n]\nvar dx = Math.Abs(node.x - x);\nvar dy = Math.Abs(node.y - y);\nreturn D*(dx + dy);\n\\end{lstlisting}\n\nA dictionary is used for the open and closed lists. The open and closed dictionary consist of unvisited or visited coordinates, hence open and closed coordinates. Where the key is a string containing the coordinate x + y. For example the key for x = 1, y = 1 would be \"11\". The reason for this is that later on in the search the coordinate can then be checked if it is in the closed dictionary, without searching thorugh a list - this saves us computation time. If the coordinate is in the closed dictionary then the node will be ignored.\n\nThe output of the A* algorithm is the endnode which contain a reference to its parent. To find the next step in the route you need to traverse the parents until you finally hit the next step.\n\nIf you plot the endnode you will get what you see in figure \\ref{fig:endNodeAdd}\n\n\\myFigure{Implementation/AStar/plot_with_arrows}{An example of the matrix with the endnode added to the matrix.}{fig:endNodeAdd}{0.4}\n", "meta": {"hexsha": "91e73b626322bc68b8016fbea41c0479841a27ed", "size": 2798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/implementation/aStar.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/implementation/aStar.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/implementation/aStar.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": 66.619047619, "max_line_length": 538, "alphanum_fraction": 0.7101501072, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6802931878542349}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\begin{flushright}\n\n\\vspace{1.1cm}\n\n%Put ISR Title\n{\\bf\\Huge Problem Set 5}\n\n\\rule{0.25\\linewidth}{0.5pt}\n\n\\vspace{0.5cm}\n%Put Authors\nJustin Ely\n\\linebreak\n\\newline\n%Put Author's affiliations\n\\footnotesize{AST615 University of Maryland College Park, MD\\\\}\n\\vspace{0.5cm}\n% Date here below\n01 December, 2011\n\\end{flushright}\n\n\\noindent\\rule{\\linewidth}{1.0pt}\n\\section*{Problem 1}\nFigures 1,2, and 3 show the integration of $\\frac{dx^2}{dt^2}+x=0$ using the Euler, RK4, and Leapfrog methods for various stepsizes.  The integrations are plotted with the analytical solution, $sin(t)$, and the plots include a loglog plot of the difference between the analytical and numerical solutions aa function of stepsize. \n \nFrom the plots showing the numerical and exact solutions, we can see that the Euler method can get very wrong very quickly, and that error compounds as time goes on.  The RK4 and Leapfrog methods, however, appear to have small, non-compounding errors even with larger stepsizes.  \n\nThe error of these 3 methods appear to have an exponentially decreasing relationship with stepsize, where the error with RK4 method is the smallest and the Euler method being the largers.  It is also interesting that the Euler method gets a smaller decrease in error with each smaller stepsize, Leapfrog is fairly stable in loglog space, and the gain gets much larger with each stepsize for the RK4 method.\n\n\n\\section*{Problem 2}\nGiven a 2D orbit described by the potential $\\Phi=\\frac{-1}{\\sqrt{1+2x^2+2y^2}}$ and $F=-\\frac{d\\Phi}{dx}$, by the chain rule $F_x=ma_x=\\frac{2x}{(1+2x^2+2y^2)^{3/2}}$.  Using unit mass, and repeating the procedure for the y component we get the equations:\n\\begin{equation}\n\\frac{d^2x}{dt^2}=\\frac{2x}{(1+2x^2+2y^2)^{3/2}}\n\\end{equation}\n\\begin{equation}\n\\frac{d^2y}{dt^2}=\\frac{2y}{(1+2x^2+2y^2)^{3/2}}\n\\end{equation}\n\nThese then reduce down to 4 coupled first order equations:\n\\begin{eqnarray}\n  \\frac{dx}{dt}=Z_x(t) \\\\\n  \\frac{dZ_x(t)}{dt}=\\frac{-2x}{(1+2x^2+2y^2)^{3/2}}\\\\\n  \\frac{dy}{dt}=Z_y(t) \\\\\n  \\frac{dZ_y(t)}{dt}=\\frac{-2y}{(1+2x^2+2y^2)^{3/2}}\n\\end{eqnarray}\n\nIn Figures 4 and 5, plots of X vs Y, and Energy vs Time can be seen for both the RK4 method and the Leapfrog method for stepsizes of 1,.5,.25, and .01.  The differences between the two methodes becomes very apparent when comparing these plots.  The stability of the leapfrog system keeps the body in an clean orbit, becoming more circular with smaller stepsizes, where the RK4 method has a very complicated orbit that appears to degrade with time.  This same trend is seen in the plots of Energy vs Time where the RK4 method shows the energy of the system falling to 0 with the larger stepsizes, whereas the Energy of the Leapfrog system oscillates around a nominal value even with large stepsizes. \n\n\n\n\\section*{Problem 3}\nFigure 6 shows a phase-plane plot produced with the RK4 method and stepsizes of 1,.5,.25, and .1.  In this phase-plane, A=1,B=.1,C=1.5,D=.03,d=e=0.  If we use a q$\\sim$1.25, both populations drop below $10^{-9}$ before t=100, although the wolves drop below much quicker.\n\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=.6]{Euler_int.pdf}\n\\caption{Euler integration for various stepsizes.  Also shown is a loglog plot of the difference between the numerical and exact solutions at the last point as a function of stepsize.}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=.6]{RK4_int.pdf}\n\\caption{RK4 integration for various stepsizes.  Also shown is a loglog plot of the difference between the numerical and exact solutions at the last point as a function of stepsize.}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=.6]{Leapfrog_int.pdf}\n\\caption{Leapfrog integration for various stepsizes.  Also shown is a loglog plot of the difference between the numerical and exact solutions at the last point as a function of stepsize.}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=.6]{RK4_orbit_int.pdf}\n\\caption{RK4 orbit integration for various stepsizes.  Also shown for each stepstize is a plot of the calculated enerygy of the system with time.}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=.6]{Leapfrog_orbit_int.pdf}\n\\caption{Leapfrog orbit integration for various stepsizes.  Also shown for each stepstize is a plot of the calculated enerygy of the system with time.}\n\\end{center}\n\\end{figure}\n\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=.7]{Phase_plane.pdf}\n\\caption{Phase plane diagram for Lotka-Volterra Predadtor-Prey Model where A=1,B=.1,C=1.5,D=.03,d=e=0.  RK4 integrated phase planes are shown for different timesteps.}\n\\end{center}\n\\end{figure}\n\\end{document}\n", "meta": {"hexsha": "2c02ffd329709ae6748a213f95901904b048e7f2", "size": 4845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "UMD/AST615/HW5/hw5.tex", "max_stars_repo_name": "justincely/classwork", "max_stars_repo_head_hexsha": "2d2b1882f9141bc5776977a5c7c6a4788ea7bc4f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-16T03:17:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-16T03:17:26.000Z", "max_issues_repo_path": "UMD/AST615/HW6_2/hw6.tex", "max_issues_repo_name": "justincely/classwork", "max_issues_repo_head_hexsha": "2d2b1882f9141bc5776977a5c7c6a4788ea7bc4f", "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": "UMD/AST615/HW6_2/hw6.tex", "max_forks_repo_name": "justincely/classwork", "max_forks_repo_head_hexsha": "2d2b1882f9141bc5776977a5c7c6a4788ea7bc4f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2017-06-13T13:11:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T17:04:32.000Z", "avg_line_length": 46.5865384615, "max_line_length": 699, "alphanum_fraction": 0.7527347781, "num_tokens": 1445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.6802931877091475}}
{"text": "\\lab{PageRank Algorithm}{PageRank Algorithm}\n\\label{lab:PageRank}\n\\objective{Model a network as a graph and implement the PageRank algorithm based on this model. \nUse PageRank to predict the rankings of sports teams. }\n\n\\begin{comment}\nWhen you enter keywords into Google's search engine, Google finds every page containing your keywords and lists the pages in order of their \\emph{rank}.\nThe rank of a page reflects many factors, including how often the page is visited and how connected it is to other pages.\n\\end{comment}\nAs of 2013, the PageRank algorithm is one of over 200 algorithms that Google uses to determine the \\emph{rank}, or relative importance, of a webpage.\nNamed for Larry Page, cofounder of Google, this algorithm ranks pages based on how many other pages link to them.\n\n\\begin{comment}\nThe PageRank algorithm is also used in applications other than internet search engines.\nFor example, it has been used to rank graduate institutions and the impact factor of journals, and it has been used in some biological applications.\n\\end{comment}\n\n\\section*{The Internet as a Graph}\nThe PageRank algorithm models the internet with a directed graph. \nEach webpage is a node, and there is an edge from node $i$ to node $j$ if page $i$ links to page $j$.\nLet $\\In(i)$ be the websites linking to page $i$ and let $\\Out(i)$ be the websites that page $i$ links to. \nThat is, $\\In(i)$ is the set of nodes with an arrow to node $i$, and $\\Out(i)$ is the set of nodes with an arrow from node $i$.\nAn example is illustrated in Figure \\ref{fig:network1}.\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}[node distance=1.75cm, thick ]\n\n\\node[draw=none](2)[]{2};\n\\node[draw=none](3)[right of=2]{3};\n\\node[draw=none](4)[right of=3]{4};\n\\node[draw=none](5)[right of=4]{5};\n\\node[draw=none](6)[right of=5]{6};\n\\node[draw=none](1)[above of=3]{1};\n\\node[draw=none, node distance=2.5cm](0)[right of=1]{0};\n\\node[draw=none](dummy)[above right of=0]{};\n\\node[draw=none, node distance=.5cm](7)[below \n\tof=dummy]{7};\n\n\\foreach \\x/\\y in {3/2, 4/5, 5/6, 1/0, 3/0, 4/0, 5/0} \\draw[->, \n\t>=stealth'](\\x)--(\\y);\n\\draw[->, >=stealth'](6)--(0);\n\\draw[->, >=stealth', shorten >= .1cm](7)edge[bend left=20](0);\n\\draw[->, >=stealth', shorten <= .1cm](0)edge[bend left=20](7);\n\\draw[->, >=stealth', shorten <= .1cm](3)edge[bend right=40](6.9,-.25);\n\\draw[->, >=stealth', shorten <= .1cm](4)edge[bend right](6);\n\n\n\n\\end{tikzpicture}\n\n\\caption{This directed graph describes the links between 8 webpages. In this example, $\\In(0)=\\{1,3,4,5,6,7\\}$ and $\\Out(0)=\\{7\\}$.}\n\\label{fig:network1}\n\\end{figure}\n\nThe PageRank algorithm ranks pages by how many others link to them.\nA link from a more important page counts more than one from a less important page.\nFor example, in Figure \\ref{fig:network1} we would expect node 0 to have a very high rank because every other node links to it. \nConsequently, we would expect node 7 to have a fairly high rank because node 0 links to it, even though node 0 is the only node to do so.\n\n\\section*{The PageRank Algorithm}\nThe PageRank algorithm assumes that a surfer chooses a starting webpage randomly.\nThen, if the surfer is at page $i$, they randomly select a page from $\\Out(i)$ to visit next.\nThis means that the surfer's chance of being on page $i$ at time $t$ is determined by where they were at time $t-1$.\n\nSuppose the internet has $N$ webpages, and let $p_i(t)$ be the likelihood that the surfer is on page $i$ at time $t$.\nThen the probabilities $p_i(t)$ are given by\n\\begin{equation}\\label{equ:pr1}\np_i(0)=\\frac{1}{N} \\qquad p_i(t+1) = \\sum_{j \\in \\In(i)} \\frac{p_j(t)}{\\abs{\\Out(j)}}.\n\\end{equation}\n\nFor example, in Figure \\ref{fig:network1} we have $N=8$, and \n\\[\np_6(t+1)=\\frac{p_3(t)}{3}+\\frac{p_4(t)}{3} + \\frac{p_5(t)}{2}.\n\\]\n\n\\subsection*{Refining the Model: Pages with No Outbound Links}\nA node with no outbound links, such as node 2 in Figure \\ref{fig:network1}, is called a \\emph{sink}. \nAccording to our model, if the surfer ever visits a sink, they will stay there forever.\n\nThis is not very realistic; in this situation, a person would likely select another webpage at random and begin surfing again.\nHence, in our model we replace sinks with nodes linking to every other page. \nThis means we modify Figure \\ref{fig:network1} (where node 2 is a sink) to look like Figure \\ref{fig:network2}.\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}[node distance=1.75cm, >=stealth', thick]\n\n\\node[draw=none](2)[]{2};\n\\node[draw=none](3)[right of=2]{3};\n\\node[draw=none](4)[right of=3]{4};\n\\node[draw=none](5)[right of=4]{5};\n\\node[draw=none](6)[right of=5]{6};\n\\node[draw=none](1)[above of=3]{1};\n\\node[draw=none, node distance=2.5cm](0)[right of=1]{0};\n\\node[draw=none](dummy)[above right of=0]{};\n\\node[draw=none, node distance=.5cm](7)[below \n\tof=dummy]{7};\n\n\n\\draw[->, color=black!35!](2)--(1);\n\\draw[->, color=black!35!, shorten >= .2cm](2)--(0);\n\\foreach \\x/\\y in {2/3, 2/4, 2/5} \\draw[->, color=black!35!](\\x)\n\tedge[bend right](\\y);\n\n\\draw[->, shorten <= .1cm, color=black!35!](2)edge[bend right=50](7,-.35);\n\\draw[->, shorten <= .1cm](3)edge[bend right=40](6.9,-.25);\n\\draw[->, shorten <= .1cm](4)edge[bend right](6);\n\\draw[->, shorten <=.1cm, color=black!35!](2)edge[bend left=40](7);\n\n\\draw[->, shorten >= .1cm](7)edge[bend left=20](0);\n\\draw[->, shorten <= .1cm](0)edge[bend left=20](7);\n\n\\foreach \\x/\\y in {3/2, 4/5, 5/6, 1/0, 3/0, 4/0, 5/0} \\draw[->, \n\t>=stealth'](\\x)--(\\y);\n\\draw[-> ](6)--(0);\n\n\\end{tikzpicture}\n\n\\caption{Here Figure \\ref{fig:network1} has been modified to guarantee that page 2 is no longer a sink. A new link has been added from page 2 to every other page (the added links are grey).}\n\\label{fig:network2}\n\\end{figure}\n\n\\subsection*{Refining the Model: Adding Boredom}\nThe equations in \\eqref{equ:pr1} assume that the current page must link to the next page.\nHowever, the model is more realistic if we assume that the surfer sometimes gets bored and randomly picks a new starting page.\nWe will denote the probability that a surfer stays interested at step $t$ by a constant $d$, called the \\emph{damping factor}.\nThen the probability that the surfer gets bored at time $t$ is $1-d$.\nThe formulas in \\eqref{equ:pr1} then become\n\\begin{equation}\\label{equ:pr2}\np_i(0)=\\frac{1}{N} \\qquad p_i(t+1) = d\\sum_{j \\in \\In(i)} \\frac{p_j(t)}{\\abs{\\Out(j)}}+\\frac{1-d}{N} .\n\\end{equation}\n\n\\subsection*{Matrix Form of the PageRank Algorithm}\nWe can rewrite \\eqref{equ:pr2} as the matrix equation\n\\begin{equation}\\label{equ:pr3}\n\\mathbf{p}(0)=\\frac{1}{N}\\mathbf{1} \\qquad \\mathbf{p}(t+1) = dK\\mathbf{p}(t) + \\frac{1-d}{N}\\mathbf{1}\n\\end{equation}\nwhere $\\mathbf{p}(t)=(p_1(t), p_2(t), \\ldots, p_N(t))^T$, \n$\\mathbf{1}$ is a vector of $N$ ones, \nand $K$ is defined by\n\\[K_{ij} = \\begin{cases} \\frac{1}{\\abs{\\Out(j)}} & \\mbox{ if j links to i} \\\\\n\t0 & \\mbox{ otherwise.} \\end{cases}\\]\n\n\n\\subsection*{Defining Page Rank}\nAs given by the PageRank algorithm, the \\emph{rank} of page $i$ is\n\\[p_i = \\lim_{t\\to \\infty} p_i(t).\\]\nIn other words, the page ranks are the steady state of the modified Markov chain defined in \\eqref{equ:pr3}.\n\n\n\n\\section*{Implementation in Python}\n\n\nThe adjacency matrix $A$ of a directed graph has $A_{ij}=1$ if there is an edge from node $i$ to node $j$, and $A_{ij}=0$ otherwise.\nThe adjacency matrix of the graph in Figure \\ref{fig:network1} is defined below.\nWe use a code environment to describe $A$ so you can easily use this example to debug the problems in this lab.\n\\begin{lstlisting}\nA = np.array([[ 0,  0,  0,  0,  0,  0,  0,  1],\n              [ 1,  0,  0,  0,  0,  0,  0,  0],\n              [ 0,  0,  0,  0,  0,  0,  0,  0],\n              [ 1,  0,  1,  0,  0,  0,  1,  0],\n              [ 1,  0,  0,  0,  0,  1,  1,  0],\n              [ 1,  0,  0,  0,  0,  0,  1,  0],\n              [ 1,  0,  0,  0,  0,  0,  0,  0],\n              [ 1,  0,  0,  0,  0,  0,  0,  0]])\n\\end{lstlisting}\n\n\\begin{problem}\nWrite the following function that creates a sparse adjacency matrix from a file.\n\\begin{lstlisting}\ndef to_matrix( filename, n ):\n    ''' Return the nxn adjacency matrix described by the file.\n    \n    INPUTS:\n    filename - Name of a .txt file describing a directed graph. Lines \n    \t\t    describing edges should have the form \n\t\t\t\t'<from node>\\t<to node>'. \n\t\t\t\tThe file may also include comments.\n    n\t\t- The number of nodes in the graph described by datafile\n    \n    RETURN:\n    Return a SciPy sparse `dok_matrix'.\n    '''\n\\end{lstlisting}\nHints:\n\\begin{enumerate}\n\\item The file \\texttt{datafile.txt} included with this lab describes the matrix in Figure \\ref{fig:network1} and has the adjacency matrix \\li{A} given above. \nYou may use it to test your function.\n\n\\item You can open a file in Python using the \\li{with} syntax. \nThen, you can iterate through the lines using a \\li{for} loop.\nHere is an example.\n\\begin{lstlisting}\n# Open `datafile.txt' for read-only\nwith open('./datafile.txt', 'r') as myfile:\n    for line in myfile:\n        print line\n\\end{lstlisting}\n\n\\item Here is an example of how to process a line of the form in \\li{datafile}.\n\\begin{lstlisting}\n>>> line = '0\\t4\\n'\n# strip() removes trailing whitespace from a line.\n# split() returns a list of the space-separated pieces of the line.\n>>> line.strip().split()\n['0', '4']\n\\end{lstlisting}\n\n\\item Rather than testing for lines of \\texttt{datafile.txt} that contain comments, put all your string operations in a \\li{try} block with an \\li{except} block following.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{info}\nIt makes sense to initialize $A$ as a sparse matrix, since $A$ is mostly zeros. To make the coding easier, throughout the rest of the lab the algorithms will be coded using non-sparse matrices. Don't forget, however, that in a real-world sparse adjacency matrices are generally much more time-efficient than dense matrices. \n\nTo convert from a sparse to a non-sparse matrix, use the syntax \\li{A.todense()}.\n\\end{info}\n\nThe next step is to compute $K$ from \\eqref{equ:pr3}. \nA good strategy for computing $K$ comes from writing\n\\[\nK = (D^{-1}A)^T\n\\]\nwhere $A$ is the adjacency matrix of the directed graph representing the internet and $D$ is a diagonal matrix with $D_{jj}=\\abs{\\Out(j)}$.\nModify $A$ so that rows corresponding to sinks have all ones instead of all zeros.\nFor Figure \\ref{fig:network2}, the modified adjacency matrix is defined below.\n\\begin{lstlisting}\nAm = np.array([[ 0,  0,  0,  0,  0,  0,  0,  1],\n               [ 1,  0,  0,  0,  0,  0,  0,  0],\n               [ 1,  1,  1,  1,  1,  1,  1,  1],\n               [ 1,  0,  1,  0,  0,  0,  1,  0],\n               [ 1,  0,  0,  0,  0,  1,  1,  0],\n               [ 1,  0,  0,  0,  0,  0,  1,  0],\n               [ 1,  0,  0,  0,  0,  0,  0,  0],\n               [ 1,  0,  0,  0,  0,  0,  0,  0]])\n\\end{lstlisting}\n\n\nThe matrix $D$ is easily obtained by summing the rows of $A$. \nAlthough  $K=(D^{-1}A)^T$, it is better practice to only store the diagonal entries of $D$ as a vector, and then use array broadcasting to divide $A$ by $D$.\n\nNotice that we need to transpose $D^{-1}A$ to get $K$. This is because $D^{-1}A$ is \\emph{row stochastic} (meaning that  the rows sum to 1), but we need to multiply \\emph{column stochastic} matrices (where the columns sum to 1) To make $K$ be column stochastic, we have to take a transpose.\n\nFor Figure \\ref{fig:network2}, the matrix $K$ is as follows.\n\n\\begin{lstlisting}\nK = np.array([[ 0   ,  1   ,  1./8,  1./3,  1./3,  1./2,  1   ,  1   ],\n              [ 0   ,  0   ,  1./8,  0   ,  0   ,  0   ,  0   ,  0   ],\n              [ 0   ,  0   ,  1./8,  1./3,  0   ,  0   ,  0   ,  0   ],\n              [ 0   ,  0   ,  1./8,  0   ,  0   ,  0   ,  0   ,  0   ],\n              [ 0   ,  0   ,  1./8,  0   ,  0   ,  0   ,  0   ,  0   ],\n              [ 0   ,  0   ,  1./8,  0   ,  1./3,  0   ,  0   ,  0   ],\n              [ 0   ,  0   ,  1./8,  1./3,  1./3,  1./2,  0   ,  0   ],\n              [ 1   ,  0   ,  1./8,  0   ,  0   ,  0   ,  0   ,  0   ]])\n\\end{lstlisting}\n\\begin{problem}\nWrite a function that computes the K matrix given an adjacency matrix.\n\\begin{enumerate}\n\\item Compute the diagonal matrix $D$.\n\\item Compute the modified adjacency matrix where the rows corresponding to sinks all have ones instead of zeros.\n\\item Compute $K$ using array broadcasting.\n\\end{enumerate}\n\\end{problem}\n\n\n\\subsection*{Solving for the Page Ranks}\nThere are several ways to solve for $\\lim_{t \\to \\infty} \\mathbf{p}(t)$.\n\\subsubsection*{Algebraic Method}\nOne possibility is to assume the modified Markov chain has a steady state $\\mathbf{p}$ and solve for it algebraically:\n\\begin{equation}\\label{equ:matrix_solve}\n(I-dK)\\mathbf{p} = \\frac{1-d}{N} \\mathbf{1}.\n\\end{equation}\n\nWe can use SciPy's solver to find the page ranks of the network in Figure \\ref{fig:network2}.\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n>>> I = np.eye(8)\n>>> d = .85\n>>> la.solve(I-d*K, ((1-d)/8)*np.ones(8))\narray([ 0.43869288,  0.02171029,  0.02786154,  0.02171029,  0.02171029,\n        0.02786154,  0.04585394,  0.39459924])\n\\end{lstlisting}\nAs expected, node 0 has the highest rank, approximately equal to .44. \nNode 7 has a higher rank than node 6, even though $\\In(7)=1$ and $\\In(6)=3$. \nThis is because node 7's single in-edge comes from a node that has a very high rank (node 0).\n\n\\subsubsection*{Iterative Method}\nSolving the system in \\eqref{equ:matrix_solve} is feasible for our small working example, but this is not an efficient strategy for very large systems.\n\nOne option for large systems is an iterative method. \nStarting with a guess for $\\mathbf{p}(0)$, we iterate on Equation \\eqref{equ:pr3} until $\\norm{\\mathbf{p}(t)-\\mathbf{p}(t-1)}$ is sufficiently small. \nAt this point we assume we have reached the steady state.\n\n\n\\begin{problem}\n\\label{prob:pagerank_dense_iter}\nImplement the function below, using the iterative method to find the steady state of the PageRank algorithm.\nWhen the argument \\li{N} is not \\li{None}, work with only the upper $N \\times N$ portion of the array \\li{adj}.\nTest your function against the example in the lab.\n\\begin{lstlisting}\ndef iter_solve( adj, N=None, d=.85, tol=1E-5):\n    '''\n    Return the page ranks of the network described by 'adj' using the iterative method.    \n    \n    INPUTS:\n    adj - A NumPy array representing the adjacency matrix of a directed \n            graph\n    N     - Restrict the computation to the first `N` nodes of the graph. \n            Defaults to N=None; in this case, the entire matrix is used.\n    d     - The damping factor, a float between 0 and 1. \n            Defaults to .85.\n    tol  - Stop iterating when the change in approximations to the \n            solution is less than `tol'. Defaults to 1E-5.    \n            \n    OUTPUTS:\n    Return the approximation to the steady state of p.\n    '''\n\\end{lstlisting}\nHints:\n\\begin{enumerate}\n\\item Try making your initial guess for $\\mathbf{p}(0)$ a random vector.\n\\item NumPy can do unexpected things with the dimensions when performing matrix-vector multiplication.\nWhen debugging, check at each iteration that all arrays have the dimensions you expect.\n\\end{enumerate}\n\\end{problem}\n\n\\subsubsection*{Eigenvalue Method}\nAnother way to solve this problem is to make it into an eigenvalue problem. \nLet $E$ be an $N \\times N$ matrix of ones; then $E\\mathbf{p}(t) = \\mathbf{1}$. \nHence, the matrix equation \\eqref{equ:pr3} for $\\mathbf{p}(t+1)$ becomes\n\\[\\mathbf{p}(t+1) = \\Big(dK + \\frac{1-d}{N}E\\Big)\\mathbf{p}(t).\\]\nIf we write $B = dK + \\frac{1-d}{N}E$, this simplifies to $\\mathbf{p}(t+1) = B\\mathbf{p}(t).$\nThus, the steady state $\\mathbf{p}(t)$ is an eigenvector of $B$ corresponding to the eigenvalue 1.\n\nThe columns of $B$ sum to 1, and the entries of $B$ are strictly positive (because the entries of $E$ are all positive).\nWith these hypotheses, the Perron-Frobenius theorem says that 1 is the unique eigenvalue of B of largest magnitude, and the corresponding eigenvector is unique.\nIn this case, the ``iterative method'' described above is just the power method for finding the eigenvector corresponding to a dominant eigenvalue, introduced in the lab on eigensolvers. %TODO: make sure the reference to another lab is accurate.\n\nWe can also compute $\\mathbf{p}$ using eigenvalue solvers in SciPy.\n\n%TODO: the output from scipy.linalg.eig is not very accurate, even for the small example in this lab.\n\\begin{problem}\nImplement the function below, using the eigenvalue method to find the steady state of the PageRank algorithm.\n\\begin{lstlisting}\ndef eig_solve( adj, N=None, d=.85):\n    '''\n    Return the page ranks of the network described by `adj`.\n    \n    INPUTS:\n    adj - A NumPy array representing the adjacency matrix of a directed \n            graph\n    N     - Restrict the computation to the first `N` nodes of the graph. \n            Defaults to N=None; in this case, the entire matrix is used.\n    d     - The damping factor, a float between 0 and 1. \n            Defaults to .85.\n    \n    OUTPUTS:\n    Return the approximation to the steady state of p.\n    '''\n\\end{lstlisting}\nHint: Review the techniques from the Markov chain section of Lab \\ref{lab:EigSolve}.\n\\end{problem}\n\n\\section*{Ranking Teams}\nThis ranking algorithm can be applied not only to webpages, but to any problem with a directed graph structure. \nOne such application is ranking sports teams.\n\nSuppose we have data about a collection of sports teams, including which teams played each other and who won each match. \nWe can model this as a directed graph. Each node in the graph represents a team.\nAn edge between two nodes points from the losing team to the winning team. \nIf two teams never played each other, there is no edge between them.\nWins and losses do not cancel out; if BYU and Boise played twice, and each team won once, then there is an edge from BYU to Boise and another edge from Boise to BYU. TODO: add a picture.\n\nTo simplify our model, edges are not weighted. So if Duke ever beat Harvard, no matter whether they beat them once or 5 times, there is only one edge pointing from Harvard to Duke. \n\nThe key here is that edges tend to lead from worse teams to better teams. \nSo by starting with some team and randomly following edges, we should end up visiting better teams more often. \nThis is reminiscent of the PageRank algorithm! Given an appropriate dataset, we can use PageRank to estimate team rankings.  \n\nNote that in this scenario, the parameter $d$ no longer represents boredom. \nIt allows us to jump randomly from one team to another, so it could represent a surprise upset, or the random outcome of a game between two teams who have never played each other.\n\n\\begin{problem}\nBy applying the PageRank algorithm to win-loss data from the 2013 NCAA basketball season, produce a comparative ranking of the teams.\n\\begin{enumerate}\n\\item The file  \\texttt{ncaa2013.csv} contains data on over 5000 basketball games. \nThe first line is a header.\nAfter the header, each line represents a game and has the winning team followed by the losing team (there are no ties in basketball). \n\nLoad this file and use it to create the adjacency matrix $A$, where $A_{ij} = 1$ if team $j$ beat team $i$. \nMake sure to ignore the header line.\nYou will need some way of mapping from team names to the integers and vice versa.\n\\item Use the iterative method from Problem \\ref{prob:pagerank_dense_iter} with $d = 0.7$ to find the steady state. \nThe steady-state solution is your vector of ranks. \n\\item Return the ranks sorted from largest to smallest, and the corresponding list of teams sorted from ``best'' to ``worst''. \n\\end{enumerate}\nHints:\n\\begin{enumerate}\n\\item The code below may be helpful for processing the .csv file:\n\\begin{lstlisting}\n>>> with open('./ncaa2013.csv', 'r') as ncaafile:\n>>>     ncaafile.readline() #reads and ignores the header line\n>>>     for line in ncaafile:\n>>>         teams = line.strip().split(',') #split on commas\n>>>         print teams\n>>> ['Middle Tenn St', 'Alabama St']\n>>> ...\n>>> ['Mississippi', 'Florida']\n\\end{lstlisting}\n\\item Before creating the adjacency matrix, you can get all the unique teams by running through all the matches once and adding every team to a set. \nNext, count the number of unique teams and initialize $A$ to be the right size.\nTry using dictionaries, lists, or both to map numbers to teams and teams to numbers and fill in $A$. \nThere is more than one right way to do this.\n\\item The function \\li{np.argsort()} will be useful for sorting the ranks and teams.\n\\item There should be 347 teams. PageRank should predict that the top five ranked teams are Duke, Butler, Louisville, Illinois, and Indiana (in that order). Use this to check your results.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Optional: SNAP Datasets}\nThe SNAP graph library, located at \\url{http://snap.stanford.edu/data/index.html}, provides a variety of medium sized data sets for public use.\nThese datasets have to do with networks, including road systems, social networks, and online communities. There are some interesting resources here for those wanting to experiment further with the PageRank algorithm on different datasets.\n\\begin{comment}\nThe \\li{matplotlib.pyplot.spy} command on the adjacency matrix from a SNAP data set yielded the plot shown in Figure \\ref{fig:WebSparse}\n\\end{comment}\n\n\\begin{comment}\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{sparse_web.png}\n\\caption{Output of the \\li{spy} command on the adjacency matrix corresponding to the websites supported by Notre Dame University in 1999.\nData was taken from the SNAP datasets.}\n\\label{fig:WebSparse}\n\\end{figure}\n\\end{comment}\n\n\\begin{problem}\n(Optional) Try running the functions you wrote in this lab on a data set downloaded from SNAP.\n\\begin{enumerate}\n\\item Begin by running your methods on the first 100 nodes of the data set.\n\\item Modify your solution to Problem \\ref{prob:pagerank_dense_iter} so that it uses only sparse matrices. \nWith this modification, you should be able to run the function on more nodes.\nHint: Convert the adjacency matrix to a \\li{csc_matrix} or a \\li{csr_matrix} to perform the computations.\n\\end{enumerate}\n\\end{problem}\n", "meta": {"hexsha": "a2ba9200c304cd90bfb75a539750d2e9bff03eb1", "size": 22076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Vol1B/PageRank/PageRank.tex", "max_stars_repo_name": "jaredawebb/Labs", "max_stars_repo_head_hexsha": "4134c7ed6eadd921d84e40deb40dc5b212d77c07", "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/Vol1B/PageRank/PageRank.tex", "max_issues_repo_name": "jaredawebb/Labs", "max_issues_repo_head_hexsha": "4134c7ed6eadd921d84e40deb40dc5b212d77c07", "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/Vol1B/PageRank/PageRank.tex", "max_forks_repo_name": "jaredawebb/Labs", "max_forks_repo_head_hexsha": "4134c7ed6eadd921d84e40deb40dc5b212d77c07", "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": 49.3870246085, "max_line_length": 324, "alphanum_fraction": 0.6878057619, "num_tokens": 6775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7879311906630568, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.6802931806399555}}
{"text": "%#########################################################\n\\chapter{Diffusion Tensor Imaging}\n\\label{ch: Diffusion}\n%#########################################################\nMolecular diffusion in biological tissues is restricted due to interactions with many obstacles, such as fibers and neural tracts. \nTherefore diffusion patterns can be used to provide microscopic details about tissue architecture. This information is further used to detect abnormalities in skeletal muscles, heart and brain. \nMRI-based diffusion tensor imaging (DTI) is a relatively new modality, which allows the noninvasive \\textit{in-vivo} determination of diffusion of water molecules arising from random motions due to the thermal energy of the tissue.\n%-new paragraph-%\n\n%-new paragraph-%\nThis chapter gives a brief introduction into diffusion theory and provides an overview of spin-echo and stimulated echo MR echo planar imaging pulse sequences that were used in the experiments discussed further in chapter~\\ref{ch: DiffusionExp}.\n%=========================================================\n\\section{Brownian Motion and Einstein Relation}\n%=========================================================\nIn 1855 Adolf Fick explained diffusion through the flux of particles arising from the gradient of local concentration $c(\\mathbf{r},t)$~\\cite{Fick}:\n%.........................................................\n\\begin{equation}\\label{eq:Fick1}\n\\mathbf{J}=-D\\nabla c(\\mathbf{r},t)\n\\end{equation}\n%.........................................................\nFor the total number of particles to be conserved divergence of the local flux should be related to the rate of change of $c(\\mathbf{r},t)$ as $\\nabla\\mathbf{J}=-\\frac{\\partial c}{\\partial t}$. This gives the diffusion equation:\n%.........................................................\n\\begin{equation}\\label{eq:Fick2}\n\\frac{\\partial c}{\\partial t}=D\\nabla^2c\n\\end{equation}\n%.........................................................\nEquations~\\ref{eq:Fick1} and \\ref{eq:Fick2} are known as Fick's law. \nIt was obtained for the case of admixture, when particles drift from higher to lower concentration regions, and this process is called \\textit{mutual diffusion}. \nAlbert Einstein in 1905 explained Brownian motion quantitatively~\\cite{Einstein} and showed that Fick's laws are also valid for the case of \\textit{self-diffusion}. \nEinstein described the motion of particles inside a finite volume $\\delta V$ considering small displacements $\\delta x$ due to the net force $K$, such that free energy is minimized: $\\delta F=\\delta E - T\\delta S=0$. \nUtilizing the ideal gas model he related the work done by the particles with the change in entropy $\\delta S = -k_B\\frac{\\partial V}{V}$. Thus the equilibrium condition is given:\n%.........................................................\n\\begin{equation}\\label{eq:EQ_Condition}\n-Kn+k_BT\\frac{\\partial c}{\\partial x}=0\n\\end{equation}\n%.........................................................\nwhere $k_B$ is Boltzmann's constant. The net flow of particles due to to net force $K$ is $J_{\\mathrm{drift}}=\\mu K $, where $\\mu$ is mobility. Drift is counteracted by diffusive flow,  which according to Fick's law, is $J_{\\mathrm{diff}}=-D\\frac{\\partial c}{\\partial x}$. \nThese flows are balanced and, together with equilibrium condition Equation~(\\ref{eq:EQ_Condition}), result in a famous Einstein-Smoluchowski relation:\n%.........................................................\n\\begin{equation}\\label{eq:Einstein-Smoluchowski}\nD=\\mu k_BT\n\\end{equation}\n%.........................................................\nwhich was obtained independently by Albert Einstein~\\cite{Einstein} in 1905, and Marian Smoluchowski~\\cite{Smoluchowski} in 1906. \nFor the small spherical particles of radius $r$, mobility is given by Stock's law $\\mu=1/{(6\\pi\\eta r)}$, and Equation~(\\ref{eq:EQ_Condition}) can be written in the following form:\n%.........................................................\n\\begin{equation}\\label{eq:Einstein-Stocks}\nD=\\frac{k_BT}{6\\pi\\eta r}\n\\end{equation}\n%.........................................................\nIn addition to the expression for the diffusion coefficient, Einstein was able to describe  Brownian motion as a stochastic process~\\cite{Einstein}. \nHe considered conditional probability $P(\\mathbf{r}|\\mathbf{r'},t)$ for the particle at $\\mathbf{r}$ at time $t_0=0$ to be at $\\mathbf{r'}$ after time $t$. \nLocal particle concentration~$c(\\mathbf{r'}, t)$~is:\n%.........................................................\n\\begin{equation}\\label{eq:probability_concentration}\nc(\\mathbf{r'},t)=\\int d\\mathbf{r} \\, c(\\mathbf{r},0)P(\\mathbf{r}|\\mathbf{r'},t)\n\\end{equation}\n%.........................................................\nSince $c(\\mathbf{r'},t)$ satisfies the diffusion equation Equation~(\\ref{eq:Fick2}) for arbitrary choice of initial $c(\\mathbf{r},0)$, the diffusion equation is also valid for probability $P(\\mathbf{r'}|\\mathbf{r}, t)$.\n%.........................................................\n\\begin{equation}\\label{eq:probability_diffusion}\n\\frac{\\partial}{\\partial t}P(\\mathbf{r}|\\mathbf{r'}t)=D\\nabla^2P(\\mathbf{r'}|\\mathbf{r}, t)\n\\end{equation}\n%.........................................................\nWith the initial condition $P(\\mathbf{r'}|\\mathbf{r}, 0)=\\delta(\\mathbf{r}-\\mathbf{r'})$ the solution of the Equation~(\\ref{eq:probability_diffusion}) is a Gaussian:\n%.........................................................\n\\begin{equation}\\label{eq:probability}\nP(\\mathbf{r}|\\mathbf{r'},t)=\\frac{1}{(4\\pi Dt)^{3/2}} \\mathrm{exp}\\left( -\\frac{(\\mathbf{r'}-\\mathbf{r})^2}{4Dt}\\right)\n\\end{equation}\n%.........................................................\nFrom this equation, the mean square displacement is liner in time:\n%.........................................................\n\\begin{equation}\\label{eq:ms_dr}\n\\left<(\\mathbf{r'}-\\mathbf{r})^2\\right>=6Dt\n\\end{equation}\n%.........................................................\nor in one dimension:\n%.........................................................\n\\begin{equation}\\label{eq:ms_dx}\n\\left<(x'-x)^2\\right>=2Dt\n\\end{equation}\n%.........................................................\nThe following definition of the diffusion coefficient flows from the Equation~(\\ref{eq:ms_dx}):\n%.........................................................\n\\begin{equation}\\label{eq:D_v}\nD=\\lim_{t\\rightarrow\\infty}\\frac{1}{2}\\frac{\\partial\\left<\\Delta x^2\\right>}{\\partial t}\n\\end{equation}\n%.........................................................\nSince $\\Delta x = \\int_0^t \\mathrm{d}\\tau \\, v({\\tau})$ the mean square displacement is:\n%.........................................................\n\\begin{equation}\\label{eq:D_v}\n\\left<\\Delta x^2\\right>=\\int\\limits_0^tdt_1\\int\\limits_0^tdt_2\\left<v(t_1)v(t_2)\\right>\n\\end{equation}\n%.........................................................\nBy taking the derivative of this expression and using time translation invariance one can obtain Green-Kubo relation for diffusion coefficient $D$~\\cite{Peliti}:\n%.........................................................\n\\begin{equation}\\label{eq:Green-Kubo}\nD=\\lim_{t \\rightarrow \\infty}\\int\\limits_0^\\infty \\mathrm{d} t \\, \\left<v(t) v(0)\\right>\n\\end{equation}\n%.........................................................\nwhere $\\left<v(t) v(0)\\right>$ is the autocorrelation function of the molecular velocity $v$. In fact Equation~(\\ref{eq:Green-Kubo}) represents a zero frequency component of the diffusion spectrum:\n%.........................................................\n\\begin{equation}\\label{eq:diffusion spectrum}\nD(\\omega)=\\int\\limits_0^\\infty dt \\, \\left< v(t) v(0)\\right> \\mathrm{exp}(i\\omega t) \n\\end{equation}\n%.........................................................\nThe correlation time is defined as:\n%.........................................................\n\\begin{equation}\\label{eq:correlation_time}\nt_c=\\int\\limits_0^\\infty dt \\, \\frac{\\left<v(t) v(0)\\right> }{\\left< v^2\\right>} \n\\end{equation}\n%.........................................................\nand provides a timescale over which the fluctuating molecular velocity becomes decorrelated~\\cite{DerekKJones}. \nThis is an important result. \nIn free solution, the correlation time is short. \nHowever, biological tissue molecules take much longer to thermalize because the length-scales of the spatial heterogeneities are typically much larger than the molecular scale. \nThus in case of restricted diffusion, it's possible to access spectral features of the diffusion coefficient which provide detailed information even in case of complicated tissue architecture~\\cite{Tuch:2002ts}.\n%=========================================================\n\\section{Bloch-Torrey Equations and Diffusion Tensor}\n%=========================================================\nIn 1950, just four years after the discovery of the NMR phenomenon by Bloch and Purcell~\\cite{Bloch1946}, Ervin Hahn discovered that the spin-echoes he observed are sensitive to the effects of diffusion. \nHe related the reduction of the signal to a dephasing caused by translational diffusion of spins subjected to local magnetic field gradients~\\cite{Hahn}. \nIn the presence of the diffusion term Bloch equations for the magnetization would change: \n%.........................................................\n\\begin{align}\\label{eq:Bloch-Torrey}\n\\frac{dM_x}{dt}&=\\gamma\\left(\\mathbf{M}\\times B_0\\right)_x-\\frac{M_x}{\\mathrm{T_2}}+D\\Delta M_x\\nonumber\\\\\n\\frac{dM_y}{dt}&=\\gamma\\left(\\mathbf{M}\\times B_0\\right)_y-\\frac{M_y}{\\mathrm{T_2}}+D\\Delta M_y\\\\\n\\frac{dM_z}{dt}&=\\gamma\\left(\\mathbf{M}\\times B_0\\right)_z+\\frac{M_0-M_z}{\\mathrm{T_1}}+D\\Delta(M_z-M_0)\\nonumber\n\\end{align}\n%.........................................................\nThis is so called Bloch-Torrey equations first introduced by Torrey in 1956~\\cite{Torrey}.\nHere $\\mathbf{M}$ is the magnetization of a sample [\\si{\\ampere/\\meter}], $B_0$ is a static magnetic field applied [\\si{\\tesla}], $\\gamma$ is a gyromagnetic ratio [\\si{\\radian/\\second \\tesla}], $M_x$, $M_y$, $M_z$ are the $x$, $y$ and $z$ components of $\\mathbf{M}, M_0$ is magnetization at thermal equilibrium and $\\mathrm{T_1}, \\mathrm{T_2}$ are the longitudinal and transversal relaxation times respectively. \nAfter \\ang{90} radio frequency (RF) pulse is applied to the system, Bloch-Torrey equations give the following solution for the magnetization in the transverse plane:\n%.........................................................\n\\begin{equation}\\label{eq: dif_mag}\n\\bar{M}=M_0e^{-\\frac{t}{T_2}}e^{-bD}\n\\end{equation}\n%.........................................................\nAs opposed to the solution for the spin-echo Equation~(\\ref{eq: dif_mag}) has an additional exponential factor $e^{-bD}$, \\textit{b-}value identifies the measurement sensitivity to diffusion and determines the strength and duration of the diffusion gradients. The units of \\textit{b-}value are [\\si{\\second/\\milli\\meter\\squared}]:\n%.........................................................\n\\begin{equation}\\label{eq: b-value}\nb=\\gamma^2\\int\\limits_{0}^{\\mathrm{TE}}dt\\left(\\int\\limits_{0}^{t}dt'G(t')\\right)^2\n\\end{equation}\n%.........................................................\nwhere $G$ is time-varying gradient of the magnetic field and $\\mathrm{TE}$ is the echo-time.\nTypical diffusion-weighted gradient consists of two lobes with equal area. In basic spin-echo sequences, two lobes ($G_{\\mathrm{d1,2}}$) have the same polarity and are placed at either side of a refocusing RF-pulse as seen in Figure~\\ref{fig: DTISeq}a. \nIn gradient-echo sequences, however, the two lobes must have opposite polarity as shown in Figure~\\ref{fig: DTISeq}b.\n%*********************************************************\n\\begin{figure}[t]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=1\\textwidth]{Figures/DiffusionPS.pdf}\n\\caption[Diffusion-weightning gradients in spin-echo and gradient echo pulse sequences]{Diffusion-weightning gradients in spin-echo and gradient echo pulse sequences.}\\label{fig: DTISeq}\n\\end{figure}\n%*********************************************************\nAn application of balanced bipolar gradients for the diffusion measurements was offered by Stejskal and Tanner~\\cite{Stejskal}. \nAlthough the first gradient creates a spatially dependent phase to each spin the second gradient eliminates this effect for the stationary spins. \nEach of the protons experiencing a random diffusive displacement between the application of the two gradient pulses will acquire a phase offset proportional to the magnitude of the displacements. \nThe result is phase dispersion proportional to the spread of positions. Thus, the diffusion coefficient $D$ along any direction can be measured by comparing MR signals $S(b)=M_0e^{-t/\\mathrm{T_2}}e^{-bD}$ and $S(0)=M_0e^{-t/\\mathrm{T_2}}$:\n\\begin{equation}\\label{eq: Diffusion from bvalue}\rD=-\\frac{1}{b}\\ln{\\frac{S(b)}{S(0)}}\r\\end{equation}\n%.........................................................\nUntil now diffusion coefficient $D$ was considered as a scalar in anisotropic medium. \nBiological tissues with regularly ordered microstructure such as skeletal muscle, spine, tongue, heart, white matter exhibit anisotropic water diffusion. \nAn anisotropic media can be described in terms of tensor formalism. \nA diffusion tensor is a covariant tensor of $\\rank$~2 that is described by a $3\\times3$ symmetric matrix with 6 unique elements:\n%.........................................................\n\\begin{equation}\n\\mathbf{D} =\\left[\r\\begin{array}{ccc}\rD_{xx} & D_{xy} & D_{xz} \\\\[4pt]\rD_{yx} & D_{yy} & D_{yz} \\\\[4pt]\rD_{zx} & D_{zy} & D_{zz} \\\\\r\\end{array}\\right]\n\\end{equation}\n%.........................................................\nThe components of the diffusion tensor can be calculated from the diffusion weighted image (DWI) set collected with the diffusion gradients applied in six or more directions. \nFor the arbitrary number of gradient directions $n \\geq 6$, the following system of liner equations can be written:\n%.........................................................\n\\begin{align}\n\\begin{cases}\n-\\ln{\\dfrac{S(b_1)}{S(b_0)}}&=\\displaystyle\\sum_{i,j=1}^3 b_{1ij}D_{ij}\\\\[2em]\n-\\ln{\\dfrac{S(b_2)}{S(b_0)}}&=\\displaystyle\\sum_{i,j=1}^3 b_{2ij}D_{ij}\\\\\n&\\setbox0\\hbox{=}\\mathrel{\\makebox[\\wd0]{\\vdots}} \\\\\n-\\ln{\\dfrac{S(b_n)}{S(b_0)}}&=\\displaystyle\\sum_{i,j=1}^3 b_{nij}D_{ij}\\\\\n\\end{cases}\n\\end{align}\n%.........................................................\nwhere indexes $i$ and $j$ stand for $x,y$ and $z$ components.\nDiffusion tensor yields several useful metrics. Mean Apparent Diffusion Coefficient (ADC) which gives the magnitude of the diffusion:\n%.........................................................\n\\begin{equation}\n\\mathrm{ADC}=\\frac{1}{3}\\mathrm{Tr}\\mathbf{D}\n\\end{equation}\n%.........................................................\nAnd  fractional anisotropy (FA) which is calculated after diffusion tensor eigenvalue decomposition is performed:\n%.........................................................\n\\begin{equation}\n\\mathrm{FA}=\\frac{\\sqrt{3\\displaystyle\\sum_{i=1}^3 (\\lambda_i-\\mathrm{ADC})^2}}{\\sqrt{2\\displaystyle\\sum_{i=1}^3 \\lambda_i^2}}\n\\end{equation}\n%.........................................................\nwhere $\\lambda_{1,2,3}$ are the eigenvalues of the diffusion tensor.\nFA describes the degree of anisotropy and can take values between zero and one. \nConventionally diffusion tensors are represented by ellipsoids.\n%*********************************************************\n\\begin{figure}[h]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[scale=0.8]{Figures/DiffusionFA.pdf}\n\\caption[Visual representation of the diffusion tensor in the isotropic and anisotropic cases]{Visual representation of the diffusion tensor in the isotropic and anisotropic cases.}\\label{fig: AnisIso}\n\\end{figure}\n%*********************************************************\n\\noindent If $\\mathrm{FA} = 1$, then diffusion occurs only along one axis and is fully restricted along all others. $\\mathrm{FA} = 0$ means an isotropic diffusion (Figure~\\ref{fig: AnisIso}a). \nBiological tissues, such as muscle are anisotropic (Figure~\\ref{fig: AnisIso}b) and diffusion mostly occurs along one of the eigenvectors, being restricted along the remaining two.\n%=========================================================\n\\section{Echo Planar Imaging (EPI)}\n\\label{sec: EPI}\n%=========================================================\nA conventional MRI spin echo sequence acquires \\textit{k}-space by sequential repetition of the basic spin echo pulse sequence ($\\SI{90}{\\degree}$ excitation RF-pulse followed by refocusing $\\SI{180}{\\degree}$). \nThis sequence is too long compared to physiological (patient) motion. \nAddition of diffusion sensitization to routine spin echo sequence will essentially result in a completely wiped out image. \nIn order to freeze motion, the established method for performing diffusion weighted imaging is to use a single shot technique, a spin echo echo-planar imaging (EPI) sequence, rather than a conventional spin echo.\n%-new paragraph-%\n\n%-new paragraph-%\nEcho planar imaging (EPI) is the fastest MRI pulse sequence. \nWith the modern hardware EPI allows producing of a 2D image as fast as tens of a millisecond. \nThe main difference of EPI pulse sequence from the conventional pulse sequences (such as spin echo and gradient echo), is that the entire \\textit{k}-space is acquired with one RF excitation (single-shot)~\\cite{RNDT23}. \nThis is accomplished by a series of bipolar readout gradients. \nTo generate a train of gradient echoes (Figure~\\ref{fig: EPI}a) with accompanying small phase-encoding gradients ('blips'), each gradient echo is distinctively spatially encoded so that multiple \\textit{k}-space lines can be sampled under an RF spin echo (Figure~\\ref{fig: EPI}b).\n%*********************************************************\n\\begin{figure}[!h]\n\\vspace{+0.2cm}\n\\includegraphics[width=\\textwidth]{Figures/EPI.pdf}\n\\caption[Spin-echo diffusion weighted EPI sequence and \\textit{k}-space sampling path]{Spin-echo diffusion weighted EPI sequence and \\textit{k}-space sampling path.}\\label{fig: EPI} \n\\end{figure}\n%*********************************************************\nEPI generates an image in a considerably shorter time than any other MRI sequence. \nTypical EPI pulse sequence is capable of producing $\\sim 100$ gradient echoes as a result 2D image can be constructed from a single RF excitation~\\cite{RNDT24}.\n%-new paragraph-%\n\n%-new paragraph-%\nCompared to conventional MR imaging pulse sequences, EPI is more prone to a variety of artifacts. \nThese artifacts arise from the fact the effective bandwidth in the phase-encoding direction is very small so that small differences in the frequency (other than from the phase encode gradient) at different spatial locations can result in severe mismapping. \nThese frequency differences occur due to eddy currents from the large diffusion gradients, as well as from magnetic field inhomogeneities arising primarily from susceptibility differences in tissues and air. \nIn my studies several correction techniques for eddy current, strong steady field inhomogeneity magnetic susceptibility were incorporated at the image pre-processing stage.\n%-new paragraph-%\n\n%-new paragraph-%\nIn spin-echo EPI sequence diffusion gradients are applied right before and immediately after $\\SI{180}{\\degree}$ refocusing pulse. \nAs a result the range of the diffusion times is very constrained. \nAbility to measure diffusion tensor at diffusion times much longer compared to spin-echo EPI sequence provides an extra dimension in the data and a better estimate for micro-structural parameters.\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Stimulated Echo Acquisition Mode (STEAM)}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nCompared to spin-echo which uses two RF-pulses Stimulated Echo~\\cite{Hahn} uses three $\\SI{90}{\\degree}$ pulses with the same phase and observes total of five echos: three primary spin echos, one secondary and one simulated echo. \nAll primary and a secondary echo experience $\\mathrm{T_2^*}$ dephasing in between second and third RF-pulses while the magnetization forming stimulated echo is preserved along the longitudinal axis. \nThe phase evolution of the magnetization in the pulse sequence with three RF-pulses is conveniently described using the diagram from~Figure~\\ref{fig: STEAM_phase}.\n%*********************************************************\n\\begin{figure}[!h]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width=\\textwidth]{Figures/STEAM_Phase.pdf}\n\\caption[Spin-phase evolution diagram for the MR pulse sequence with three RF-pulses]{Spin-phase evolution diagram for the MR pulse sequence with three RF-pulses.}\\label{fig: STEAM_phase} \n\\end{figure}\n%*********************************************************\n To keep only simulated echo pathway while eliminating signal from all the other four echoes as well as signal from free induction decays a set of four crusher gradients $\\phi_{1-4}$ must be introduced. \n For signal to be produced the accumulated phase due to the crusher must cancel out. \n Phase dispersion created by a crusher gradient is directly proportional to its area thus by manipulating the size of the crusher gradients $\\phi_{1-4}$ the stimulated echo pathway can be chosen while other echos can be destroyed.\n%-new paragraph-%\n\n%-new paragraph-%\n The stimulated echo signal pathway denoted SE in~Figure~\\ref{fig: STEAM_phase}: first $\\mathrm{RF_1}$ excites magnetization (1), next, phase is accumulated (2) due to gradient $\\phi_1$, then $\\mathrm{RF_2}$ reverses the phase (3) and locks magnetization longitudinally (4), following $\\mathrm{RF_3}$ magnetization is restored in the transverse plane(5) and rephased by crusher gradient $\\phi_4$ (6) to form an echo (7).\n%-new paragraph-%\n\n%-new paragraph-%\nConditions for stimulated echo are the following:\n%.........................................................\n\\begin{equation}\\label{eq: STEAM phase}\n{\\setstretch{1.0}\n\\begin{cases}\n    \\mathrm{E_1} &= -\\phi_1 + \\phi_2\\\\\n    \\mathrm{E_2} &= -\\phi_1 + \\phi_2 + \\phi_3 - \\phi_4\\\\\n    \\mathrm{E_3} &= -\\phi_2 + \\phi_3 + \\phi_4\\\\\n    \\mathrm{E_4} &= -\\phi_1 - \\phi_2 - \\phi_3 + \\phi_4\\\\\n    \\mathrm{E_{1-4}} &\\neq 0\\\\\n    \\mathrm{SE} &= -\\phi_1 + \\phi_4\\\\\n    \\phi_2 &\\neq 0\\\\\n    \\phi_4 &\\neq 0\\\\\n\\end{cases}\n}\n\\end{equation}\n%.........................................................\nwhere first five equations are the conditions to destroy four echos, last two equations are conditions to remove signal originating from free induction decay and the equation for SE is the requirement to preserve stimulated echo. \nDiffusion weighting is added into the STEAM sequence by placing two identical diffusion gradients: first is placed in between $\\mathrm{RF_1}$ and $\\mathrm{RF_2}$ and second after $\\mathrm{RF_3}$ pulse.\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsection{Correction to the \\textit{b}-matrix}\n\\label{subsection: STEAM b value}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nIn STEAM diffusion weighted sequence contribution to the \\textit{b-}matrix (Equation~\\ref{eq: bmatrix}) from cross-terms between different gradients becomes significant at long diffusion time $\\Delta$ and must be calculated from the Equation~\\ref{eq: b-value}. \n%.........................................................\n\\begin{equation}\\label{eq: bmatrix}\nb =\\left[\r\\begin{array}{ccc}\rb_{rr} & b_{rp} & b_{rs} \\\\\rb_{pr} & b_{pp} & b_{ps} \\\\[1pt]\rb_{sr} & b_{sp} & b_{ss} \\\\\r\\end{array}\\right]\n\\end{equation}\n%.........................................................\nwhere indices $r, p, s$ are corresponding to three gradient axis: readout, phase encoding and slice selection respectively. \n%-new paragraph-%\n\n%-new paragraph-%\nFigure~\\ref{fig: STEAM_GE} shows a plot of STEAM pulse sequence programmed in EPIC (GE Medical Systems, Milwaukee, WI, USA). \nImportant timing parameters marked: diffusion time ($\\Delta$) measured as time between diffusion gradients, duration of the diffusion gradients ($\\delta$) and mixing time TM, measured as time between centers of the second and third RF-pulses.\n%*********************************************************\n\\begin{figure}[h]\n\\vspace{+0.2cm}\n\\centering\n\\includegraphics[width =0.7\\textwidth]{Figures/STEAM_GE.pdf}\n\\caption[Plot of STEAM pulse sequence programmed for GE scanner]{Plot of STEAM pulse sequence programmed for GE scanner.}\\label{fig: STEAM_GE} \n\\end{figure}\n%*********************************************************\nTo satisfy conditions~\\ref{eq: STEAM phase} the following configuration of crusher gradients was chosen:\n%.........................................................\n\\begin{equation}\\label{eq: bmatrix}\n{\\setstretch{1.0}\n\\begin{cases}\n    \\phi_1 = \\phi_4\\\\\n    \\phi_1 \\neq \\phi_2\\\\\n    \\phi_2 \\neq 0\\\\\n    \\phi_4 \\neq 0\\\\\n    \\phi_2 \\neq - \\phi_3\\\\\n    \\phi_3 \\neq \\phi_2 - \\phi_1\\\\\n    \\phi_3 \\neq 2\\phi_1 - \\phi_2\\\\\n    \\phi_3 < \\phi_2 < \\phi_1\n\\end{cases}\n}\n\\end{equation}\n%.........................................................\nUsing full analytic form derived in~\\cite{RNDT} independent components for \\textit{b-}matrix due to diffusion, crusher and slice select gradient interactions are:\n%.........................................................\n\\begin{equation}\\label{eq: bmatrix}\n{\\setstretch{1.0}\n\\begin{array}{l}\n    b_{rr} = \\gamma^2\\Bigl[G_{\\mathrm{d}r}^2\\tau_{11} + 2G_{\\mathrm{d}r}G_{\\mathrm{c}r}\\tau_{12} + G_{\\mathrm{c}r}^2\\tau_{22}\\Bigr]\\\\[10pt]\n    \n    b_{pp} = \\gamma^2\\Bigl[G_{\\mathrm{d}p}^2\\tau_{11} + 2G_{\\mathrm{d}p}G_{\\mathrm{c}p}\\tau_{12} + G_{\\mathrm{c}p}^2\\tau_{22} \\Bigr]\\\\[10pt]\n    \n    b_{ss} = \\gamma^2\\Bigl[G_{\\mathrm{d}s}^2\\tau_{11} +2G_{\\mathrm{d}s}G_{\\mathrm{c}s}\\tau_{12} + G_{\\mathrm{c}s}^3\\tau_{22} + G_{\\mathrm{sl}}^2\\tau_{33} \\Bigr]\\\\[10pt]\n    \n    b_{rp} = b_{pr} = \\gamma^2\\Bigl[G_{\\mathrm{d}r}G_{\\mathrm{d}p}\\tau_{11} + \\left(G_{\\mathrm{c}p}G_{\\mathrm{d}r} + G_{\\mathrm{c}r}G_{\\mathrm{d}p}\\right)\\tau_{12} + G_{\\mathrm{c}r}G_{\\mathrm{c}p}\\tau_{22} \\Bigr]\\\\[10pt]\n    \n    \\begin{split}\n\tb_{rs} &= b_{sr} = \\gamma^2\\Bigl[G_{\\mathrm{d}s}G_{\\mathrm{d}r} \\tau_{11} + \\left( G_{\\mathrm{d}s}G_{\\mathrm{c}r} + G_{\\mathrm{d}r}G_{\\mathrm{c}s}\\right)\\tau_{12} + \\\\[2pt]\n    \t \t&\\qquad\\qquad\\qquad\\quad  + G_{\\mathrm{c}r}G_{\\mathrm{c}s}\\tau_{22} + G_{\\mathrm{sl}}G_{\\mathrm{d}r}\\tau_{13}+G_{\\mathrm{sl}}G_{\\mathrm{c}r}\\tau_{23}\\Bigr]\n\t\\end{split}\n    \\\\[4ex]\n    \\begin{split}\n\tb_{ps} &= b_{sp} = \\gamma^2 \\Bigl[G_{\\mathrm{d}s}G_{\\mathrm{d}p} \\tau_{11} + \\left( G_{\\mathrm{d}s}G_{\\mathrm{c}p} + G_{\\mathrm{d}p}G_{\\mathrm{c}s}\\right)\\tau_{12} + \\\\[2pt]\n    \t \t&\\qquad\\qquad\\qquad\\quad  + G_{\\mathrm{c}p}G_{\\mathrm{c}s}\\tau_{22} + G_{\\mathrm{sl}}G_{\\mathrm{d}p}\\tau_{13}+G_{\\mathrm{sl}}G_{\\mathrm{c}p}\\tau_{23}\\Bigr]\\\\[4pt]\n\t\\end{split}\n    \\end{array}\n}\n\\end{equation}\n%.........................................................\nwith gradients amplitudes: $G_{\\mathrm{d}*}$ and $G_{\\mathrm{c}*}$ being diffusion and crusher pulses respectively where $*$ denotes gradient axis ($r,p$ or $s$), $G_{\\mathrm{sl}}$ being an amplitude of a slice selection gradient pulse. \nTime constants $\\tau_{ij}$ for the trapezoid gradient shape approximation are:\n%.........................................................\n\\begin{equation}\\label{eq: bmatrix timing}\n{\\setstretch{1.0}\n\\begin{array}{l}\n\t\n\t\\tau_{11} = \\delta_1^2\\left( \\Delta_1 - \\dfrac{1}{3}\\delta_1\\right) + \\dfrac{1}{30}\\epsilon_{\\mathrm{d}}^3-\\dfrac{1}{6}\\delta_1\\epsilon_{{\\mathrm{d}}}^2\\\\[12pt]\n\t\\tau_{22} = \\delta_2^2\\left( \\Delta_2 - \\dfrac{1}{3}\\delta_2\\right) + \\dfrac{1}{30}\\epsilon_{\\mathrm{c}}^3-\\dfrac{1}{6}\\delta_2\\epsilon_{{\\mathrm{c}}}^2\\\\[12pt]\n\t\\tau_{12} = \\delta_1\\delta_2\\Delta_2\\\\[12pt]\n\t\\tau_{13} = \\dfrac{1}{4}\\delta_1\\delta_{\\mathrm{sl}}^2\\\\[12pt]\n\t\\tau_{23} = \\dfrac{1}{4}\\delta_2\\delta_{\\mathrm{sl}}^2\\\\[12pt]\n\t\\tau_{33} = \\dfrac{1}{12}\\delta_{\\mathrm{sl}}^3\\\\[12pt]\n\\end{array}\n}\n\\end{equation}\n%.........................................................\nwhere $\\Delta_1$ is diffusion time, time constant $\\Delta_2$ and pulse durations $\\delta_{1,2}$ defined:\n%.........................................................\n\\begin{equation}\\label{eq: bmatrix timing delta}\n{\\setstretch{1.0}\n\\begin{array}{l}\n\t\\Delta_{2} = \\Delta_{1}-(\\delta_{\\mathrm{d}}+\\delta_{\\mathrm{c}})-2(\\epsilon_{\\mathrm{d}}+\\epsilon_{\\mathrm{c}})\\\\[12pt]\n\t\\delta_{1} = \\delta_{\\mathrm{d}}+\\epsilon_{\\mathrm{d}}\\\\[12pt]\n\t\\delta_{2} = \\delta_{\\mathrm{c}}+\\epsilon_{\\mathrm{c}}\n\\end{array}\n}\n\\end{equation}\n%.........................................................\n$\\delta_{\\mathrm{d}}$ and $\\delta_{\\mathrm{c}}$ durations of the diffusion and crusher gradients, $\\epsilon_{\\mathrm{d}}$ and $\\epsilon_{\\mathrm{c}}$ rise time of the diffusion and crusher gradients, $\\delta_{\\mathrm{sl}}$ duration of the slice selection gradient.\n\t\n\t", "meta": {"hexsha": "17dcca3860e0c91d48dc7f66033d227e1ecdc1bd", "size": 28869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter5.tex", "max_stars_repo_name": "vmalis/PhDissertation", "max_stars_repo_head_hexsha": "7c6a343f902eb7a76d3f0ceca9aeb54def160c59", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter5.tex", "max_issues_repo_name": "vmalis/PhDissertation", "max_issues_repo_head_hexsha": "7c6a343f902eb7a76d3f0ceca9aeb54def160c59", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter5.tex", "max_forks_repo_name": "vmalis/PhDissertation", "max_forks_repo_head_hexsha": "7c6a343f902eb7a76d3f0ceca9aeb54def160c59", "max_forks_repo_licenses": ["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.4046391753, "max_line_length": 420, "alphanum_fraction": 0.6238872147, "num_tokens": 7694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.6802931715660758}}
{"text": "\\documentclass[11pt]{article}\r\n\\usepackage{cctbx_preamble}\r\n\\usepackage{amscd}\r\n\r\n\\title{Restraint Gradients}\r\n\\author{\\rjgildea}\r\n\\date{\\today}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\r\n\\section{ADP similarity restraint}\r\n\\label{ADP:similarity}\r\nThe anisotropic displacement parameters of two atoms are restrained to have the\r\nsame $U_{ij}$ components.  This is equivalent to a SHELXL SIMU restraint \\cite{SHELX:man97}.\r\nThe weighted least-squares residual is defined as\r\n\\begin{equation}\r\nR = w \\sum_{i=1}^3 \\sum_{j=1}^3 (U_{A,ij} - U_{B,ij})^2,\r\n\\end{equation}\r\nwhich we note is the square of the Frobenius norm of the matrix of deltas.\r\nBut since $\\mat{U}$ is symmetric, i.e. $U_{ij} = U_{ji}$, this can be rewritten as\r\n\\begin{equation}\r\nR = w \\left( \\sum_{i=1}^3 (U_{A,ii} - U_{B,ii})^2 + 2 \\sum_{i < j} (U_{A,ij} - U_{B,ij})^2 \\right) .\r\n\\end{equation}\r\nTherefore the gradient of the residual with respect to the diagonal element $U_{A,ii}$ is then\r\n\\begin{equation}\r\n\\partialder{R}{U_{A,ii}} = 2w(U_{A,ii} - U_{B,ii}).\r\n\\end{equation}\r\nSimilarly the gradient with respect to the off-diagonal element $U_{A,ij}$ is\r\n\\begin{equation}\r\n\\partialder{R}{U_{A,ij}} = 4w(U_{A,ij} - U_{B,ij}).\r\n\\end{equation}\r\n\r\n\\section{Rigid-bond restraint}\r\n\r\nIn a `rigid-bond' restraint the components of the anisotropic displacement parameters\r\nof two atoms in the direction of the vector connecting those two atoms are restrained\r\nto be equal.  This corresponds to Hirshfeld's `rigid-bond' test \\cite{Hirshfeld:1976} for testing\r\nwhether anisotropic displacement parameters are physically reasonable (see SHELX\r\nmanual, DELU restraint \\cite{SHELX:man97}).  We must therefore minimise the mean square displacement of\r\nthe atom in the direction of the bond.\r\n\r\nThe weighted least-squares residual is then\r\n\\begin{equation}\r\nR = w(z^2_{A,B} - z^2_{B,A})^2,\r\n\\end{equation}\r\nwhere in the Cartesian coordinate system the mean square displacement of atom A\r\nalong the vector $\\overrightarrow{AB}$, $z^2_{A,B}$, is given by\r\n\\begin{equation}\r\nz^2_{A,B} = \\frac{\\vec{r}^t\\mat{U}_{cart,A}\\vec{r}}{\\norm{\\vec{r}}^2},\r\n\\end{equation}\r\nwhere\r\n\\begin{equation}\r\n\\vec{r} = \\begin{pmatrix} x_A - x_B\\\\y_A - y_B\\\\z_A - z_B \\end{pmatrix}\r\n= \\begin{pmatrix} x\\\\y\\\\z \\end{pmatrix},\r\n\\end{equation}\r\n$\\vec{r}^t$ is the transpose of $\\vec{r}$ (\\textit{i.e.} a row vector) and\r\n$\\norm{\\vec{r}}$ is the length of the vector $\\overrightarrow{AB}$.\r\n\r\nThe derivative of the residual with respect to an element of $\\vec{U}_{cart,A}$,\r\n$U_{A,ij}$ is given by (using the chain rule)\r\n\\begin{align}\r\n\\partialder{R}{U_{A,ij}} &= \\partialder{R}{z^2_{A,B}} \\partialder{z^2_{A,B}}{U_{A,ij}}\\\\\r\n&=2w(z^2_{A,B} - z^2_{B,A}) \\partialder{z^2_{A,B}}{U_{A,ij}}\\label{eqn:r_derivative}\r\n\\end{align}\r\n\r\nThe matrix multiplication in obtaining $z^2_{A,B}$ can be evaluated as follows\r\n(remembering $\\vec{U}_{cart}$ is symmetric):\r\n\\begin{align}\r\n\\vec{r}^t\\vec{U}_{cart,A}\\vec{r} &= \r\n\\begin{pmatrix} x & y & z \\end{pmatrix}\r\n\\begin{pmatrix} U_{11} & U_{12} & U_{13}\\\\\r\n  U_{12} & U_{22} & U_{23}\\\\\r\n  U_{13} & U_{23} & U_{33}\\end{pmatrix}\r\n\\begin{pmatrix} x\\\\y\\\\z\\end{pmatrix}\\\\\r\n&= U_{11}\\: x^2 + U_{22}\\: y^2 + U_{33}\\: z^2 + 2U_{12}\\: xy + 2U_{13}\\: xz + 2U_{23}\\: yz\r\n\\end{align}\r\nIt then follows that\r\n\\begin{equation}\r\n\\partialder{z^2_{A,B}}{U_{11}} = \\frac{x^2}{\\norm{\\vec{r}}^2} ,\\qquad\r\n\\partialder{z^2_{A,B}}{U_{22}} = \\frac{y^2}{\\norm{\\vec{r}}^2} ,\\qquad\r\n\\partialder{z^2_{A,B}}{U_{33}} = \\frac{z^2}{\\norm{\\vec{r}}^2} ,\r\n\\end{equation}\r\nand\r\n\\begin{equation}\r\n\\partialder{z^2_{A,B}}{U_{12}} = \\frac{2xy}{\\norm{\\vec{r}}^2} ,\\qquad\r\n\\partialder{z^2_{A,B}}{U_{13}} = \\frac{2xz}{\\norm{\\vec{r}}^2} ,\\qquad\r\n\\partialder{z^2_{A,B}}{U_{23}} = \\frac{2yz}{\\norm{\\vec{r}}^2} .\r\n\\end{equation}\r\nThese can be combined with \\eqnref{r_derivative} to give us the derivatives\r\nwith respect to each $U_{ij}$ component.\r\n\r\n\\section{Isotropic ADP restraint}\r\nHere we minimise the difference between the Cartesian ADPs, $\\mat{U}_{cart}$ and\r\nthe isotropic equivalent, $\\mat{U}_{eq}$.  As in section \\ref{ADP:similarity}, we\r\nmust remember that we are dealing with symmetric matrices, and we can therefore\r\ndefine the weighted least-squares residual as\r\n\\begin{equation}\r\nR = w \\left( \\sum_{i=1}^3 (U_{ii} - U_{eq,ii})^2 + 2 \\sum_{i<j} (U_{ij} - U_{eq,ij})^2 \\right) ,\r\n\\end{equation}\r\nwhere\r\n\\begin{equation}\r\n\\mat{U}_{eq} = \r\n\\begin{pmatrix} U_{iso} & 0 & 0\\\\\r\n  0 & U_{iso} & 0\\\\\r\n  0 & 0 & U_{iso}\\end{pmatrix},\r\n\\end{equation}\r\nand\r\n\\begin{equation}\r\nU_{iso} = \\tfrac{1}{3} \\mathrm{tr}(\\mat{U}_{cart}).\r\n\\end{equation}\r\nWe expand the summation of the residual as follows\r\n\\begin{equation}\r\nR = w \\left( (U_{11} - U_{iso})^2 + (U_{22} - U_{iso})^2 + (U_{33} - U_{iso})^2 + 2 U_{12}^2 + 2 U_{13}^2 + 2 U_{23}^2 \\right) .\r\n\\end{equation}\r\nWe can now see by inspection that the derivatives of the residual with respect to the off-diagonal elements are\r\n\\begin{equation}\r\n\\partialder{R}{U_{ij,i\\neq j}} = 4 w U_{ij}.\r\n\\end{equation}\r\nThe derivatives of the residual with respect to the diagonal elements can be obtained as follows\r\n\\begin{align}\r\n\\partialder{R}{U_{11}} =& w \\left( 2 (U_{11} - U_{iso})\\partialder{(U_{11} - U_{iso})}{U_{11}}\\right. \\nonumber\\\\\r\n                        &+ 2 (U_{22} - U_{iso})\\partialder{(U_{22} - U_{iso})}{U_{22}}\\nonumber\\\\\r\n                        &+ 2 \\left. (U_{33} - U_{iso})\\partialder{(U_{33} - U_{iso})}{U_{33}} \\right) \\nonumber\\\\\r\n                       =& w \\left( 2 (U_{11} - U_{iso})(1 - \\tfrac{1}{3}) + 2 (U_{22} - U_{iso})(-\\tfrac{1}{3}) + 2 (U_{33} - U_{iso})(-\\tfrac{1}{3}) \\right) \\nonumber\\\\\r\n                       =& w \\left( \\tfrac{4}{3} U_{11} - \\tfrac{2}{3} U_{22} - \\tfrac{2}{3} U_{33}\\right) \\nonumber\\\\\r\n                       =& 2 w (U_{11} - U_{iso}) .\r\n\\end{align}\r\nThis can be generalised as\r\n\\begin{equation}\r\n\\partialder{R}{U_{ii}} = 2 w (U_{ii} - U_{iso}) .\r\n\\end{equation}\r\n\r\n\\bibliography{cctbx_references}\r\n\r\n\\end{document}", "meta": {"hexsha": "ea144c7e97168e72f2b14028aa34c28fbb72f64d", "size": 5923, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cctbx/adp_restraints/gradients.tex", "max_stars_repo_name": "rimmartin/cctbx_project", "max_stars_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 155, "max_stars_repo_stars_event_min_datetime": "2016-11-23T12:52:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:35:44.000Z", "max_issues_repo_path": "cctbx/adp_restraints/gradients.tex", "max_issues_repo_name": "rimmartin/cctbx_project", "max_issues_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 590, "max_issues_repo_issues_event_min_datetime": "2016-12-10T11:31:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T23:10:09.000Z", "max_forks_repo_path": "cctbx/adp_restraints/gradients.tex", "max_forks_repo_name": "rimmartin/cctbx_project", "max_forks_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 115, "max_forks_repo_forks_event_min_datetime": "2016-11-15T08:17:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T15:30:14.000Z", "avg_line_length": 43.5514705882, "max_line_length": 170, "alphanum_fraction": 0.6412291069, "num_tokens": 2219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6802684415527744}}
{"text": "\\chapter{Field Theory}\n\\label{sec:field_theory}\nIn the last sections, we dealt with discrete and finite dimensional problems. Now, we want to extend our theory to an infinite number of degrees of freedom and apply it on field theory. The main difference is that we can analyse not only several points but every point in space at once. Imagine assigning the amplitude $q(\\bar{x})$ to each point $\\bar{x} \\in \\mathbb{R}^3$:\n\n\\begin{example}  \n\\begin{align}\nL(q_i,\\dot{q}_i) = \\sum_{i=1}^n \\left( \\frac{\\dot{q}_i^2}{2} - \\gamma \\frac{q_i^2}{2} \\right).\n\\end{align}\nIn the finite dimensional case, we just have n oscillating points. \n\\begin{align}\nL[q_{\\bar{x}},\\dot{q}_{\\bar{x}}] = \\int d^3 x \\left( \\frac{\\dot{q}^2(\\bar{x})}{2} - \\gamma \\frac{q^2(\\bar{x})}{2} \\right).\n\\end{align}\nNow, we have oscillators in every point of space.\n\\end{example}\n\nIn field theory, for instance, we want to know the value of the field $\\varphi$ in every point $\\bar{x}$, see Fig.~\\ref{fig:6}. Of course, there is the option to assign more than one field to every point $\\bar{x}$.\nOne can see that the discrete index $i$ is replaced by the continous variable $\\bar{x}$.\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.7]{img/field.png}\n\\end{center}\n\\caption{Assigning the value of the field $\\varphi$ to each point $\\bar{x} \\in \\mathbb{R}^3$.}\n\\label{fig:6}\n\\end{figure}\n\nThe difference between finite dimensional and infinite dimensional theory is summerized in the following table: \n\n\\begin{table}[H]\n\\begin{tabular}{>{\\centering}p{.45\\textwidth} | >{\\centering}p{.45\\textwidth}} \nDiscrete case \\vspace{5pt} & Continuous case \\vspace{5pt} \\tabularnewline \\hline \n\\vspace{5pt} $q_i(t), \\ \\ \\ i=1, \\dots, n$ & \\vspace{5pt} $q_{\\bar{x}}(t) = q(\\bar{x},t), \\ \\ \\ \\bar{x} \\in \\mathbb{R}^3$ \\tabularnewline \n\\vspace{3pt} $\\sum_{i=1}^n$ & \\vspace{3pt} $\\int d^3 x$ \\tabularnewline \n\\vspace{3pt} $L(q_1, \\dots, q_n, \\dot{q}_1, \\dots, \\dot{q}_n)$ & \\vspace{3pt} $L[q_{\\bar{x}}, \\dot{q}_{\\bar{x}}]$ \\tabularnewline \n\\end{tabular}\n\\caption{Comparison between finite dimensional and infinite dimensional theory.}\n\\end{table}\n\nWe want our theory to be relativistic invariant, so we have to make our fields dependent on time $q(t, \\vec{x}) = q(x^{\\mu})$ and build the Lagrangian out of Lorentz scalars:\n\\begin{align}\nL = \\frac{1}{2} \\int d^3 x \\left( \\dot{q}^2 - \\gamma q^2 \\right) \\ \\ \\longrightarrow \\ \\ \\frac{1}{2} \\int d^3 x \\left( \\partial_{\\mu} q \\partial^{\\mu} q - \\gamma q^2 \\right),\n\\end{align}\nwhere $\\mu = 0,1,2,3$. If we apply a Lorentz transformation on the old Lagrangian, space and time are mixed together so that we get a different result. The new Lagrangian should be build in a way to compensate this mixing and leave the action invariant under Lorentz transformations. We will use the $(+ - - -)$ signature of Minkowski spacetime. \\\\\nThe simplest example for such a relativistic invariant field theory is the Klein-Gordon-Fock field:\n\n\\begin{example}[Klein-Gordon-Fock field]\n\\begin{align}\nL[\\varphi, \\dot{\\varphi}] &= \\frac{1}{2} \\int d^3 x \\left( \\partial_{\\mu} \\varphi \\partial^{\\mu} \\varphi - m^2 \\varphi^2 \\right) \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\left( \\dot{\\varphi}^2 - (\\nabla \\varphi)^2 - m^2 \\varphi^2 \\right) \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\left( \\dot{\\varphi}^2 + \\varphi \\Delta \\varphi - m^2 \\varphi^2 \\right) \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\left( \\dot{\\varphi}^2 + \\varphi (\\Delta - m^2) \\varphi \\right).\n\\end{align}\nThis Lagrangian is regular, so no constraints appear.\n\\end{example}\n\nWe would like to illustrate the Hamiltonian formulation of field theory with the KGF field. The above form of the Lagrangian will be useful later. \\\\\nThe next step is to find the Hamiltonian from a given Lagrangian. In the discrete case, we used to differentiate the Lagrangian with respect to the generalized velocities to find the conjugated momenta. What are the generalized velocities now and how to define the conjugated momenta in field theory? To answer this questions, we will need a mathematical tool which we want to develop in the next section. \n\n\\pagebreak\n\n\\section{Functional derivative}\n\nThe directional derivative for a function $M(q_1, \\dots, q_n)$ of $n$ varibles is defined as\n\\begin{align}\n\\frac{\\partial M}{\\partial q_k} = \\lim_{a \\rightarrow 0} \\ \\frac{M(q_1, \\dots, q_k + a, \\dots, q_n) - M(q_1, \\dots, q_k, \\dots, q_n)}{a}.\n\\end{align}\nWe want to generalize the directional derivative for functionals\n\\begin{align}\nM(q_1, \\dots, q_n) \\ \\longrightarrow \\ M[q(x)].\n\\end{align}\nThe problem is that the functional doesn't depend on the variable $x$ but on the function $q$. For instance, if $x \\in [a,b]$, we have to consider every possible path from $a$ to $b$:\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=1.8]{img/variation.pdf}\n\\end{center}\n\\caption{Variation of a path $q(x)$ with fixed endpoints.}\n\\label{fig:7}\n\\end{figure}\nUsually, the knowledge of the complete functional for all possible paths is not required. We rather want to know the behavior of the functional in the vicinity of the function $q$, which makes it extremal or stationary. Therefore, we can take the path $q(x)$ and disturb or variate it by adding a small but arbitrary function $\\delta q(x)$. One way of generalizing the directional derivative is by using the variation $\\delta M$ of the functional $M[q(x)]$:\n\n\\begin{definition}[Functional derivative]\n\\begin{align}\n\\delta M \\equiv M[q(x) + \\delta q(x)] - M[q(x)] = \\displaystyle\\int\\limits_{a}^{b} dx \\ \\frac{\\delta M[q]}{\\delta q(x)} \\ \\delta q(x).\n\\end{align}\n\\end{definition}\n\n\\pagebreak\n\nIf we write $\\delta q(x) = \\varepsilon \\ \\eta(x)$, where $\\eta(x)$ is an arbitrary function and $\\varepsilon$ is infinitesimally small, we can Taylor expand our definition and find:\n\\begin{align}\n\\left. \\frac{d M[q + \\varepsilon \\eta]}{d\\varepsilon} \\ \\right|_{\\varepsilon=0} = \\displaystyle\\int\\limits_{a}^{b} dx \\ \\frac{\\delta M[q]}{\\delta q(x)} \\ \\eta(x).\n\\end{align}\n\nThis is a useful result to calculate the functional derivative, if one has more complicated functionals. Now, let us look at some simple examples to get comfortable with the definition and understand what's going on.\n\\vspace{15pt}\n\\begin{example}\nConsider the following functional\n\\begin{align}\nM[q(x)] =  \\displaystyle\\int\\limits_{a}^{b} dx \\ q(x).\n\\end{align}\nWe can use our definition of the functional derivative\n\\begin{align}\n\\delta M = \\displaystyle\\int\\limits_{a}^{b} dx \\left( q(x) + \\delta q(x) \\right) - \\displaystyle\\int\\limits_{a}^{b} dx \\ q(x) = \\displaystyle\\int\\limits_{a}^{b} dx \\ \\delta q(x) \\overset{!}{=} \\displaystyle\\int\\limits_{a}^{b} dx \\ \\frac{\\delta M}{\\delta q(x)} \\ \\delta q(x)\n\\end{align}\nand read off the result\n\\begin{align}\n\\frac{\\delta M}{\\delta q(x)} = 1.\n\\end{align}\n\\end{example}\n\\vspace{20pt}\n\\begin{example}\nNext, let us take the functional\n\\begin{align}\nK[q(x)] =  \\displaystyle\\int\\limits_{a}^{b} dx \\ q^n(x).\n\\end{align}\nThen, we can use our helpful result\n\\begin{align}\n\\left. \\frac{d K[q + \\varepsilon \\eta]}{d\\varepsilon} \\ \\right|_{\\varepsilon=0} = \\displaystyle\\int\\limits_{a}^{b} dx \\ n q^{n-1}(x) \\ \\eta(x) \\overset{!}{=} \\displaystyle\\int\\limits_{a}^{b} dx \\ \\frac{\\delta K}{\\delta q(x)} \\ \\eta(x) \n\\end{align}\nto find\n\\begin{align}\n\\frac{\\delta K}{\\delta q(x)} = n q^{n-1}(x).\n\\end{align}\n\\end{example}\n\\vspace{15pt}\n\n\nOne can see that the functional derivative is very similar to the ordinary derivative. In fact, all the properties of the ordinary derivative (like Leibniz rule, chain rule, ...) are satisfied by the functional derivative. We want to show one last useful tool for working with functional derivatives. It is no coincidence that the functional derivative of the above examples looks like the ordinary derivative. \\\\\n\n\nMore general, we have the property that\n\\begin{align}\nM[q(x)] = \\displaystyle\\int\\limits_{a}^{b} dx \\ f(q(x)) \\ \\ \\Longrightarrow \\ \\ \\frac{\\delta M}{\\delta q(y)} = f'(q(y)).\n\\end{align}\n\n\\begin{proof}\nConsider a parametrized family of functionals $M_z[q(x)]$. For a fixed $q$, we can have different outputs depending on $z$. So it looks much like a function with variable $z$:\n\\begin{align}\nM_z[q(x)] \\equiv q(z).\n\\end{align}\nBy calculating the variation\n\\begin{align}\n\\delta M_z &= M_z[q(x) + \\delta q(x)] - M_z[q(x)] = q(z) + \\delta q(z) - q(z) = \\delta q(z) \\notag \\\\\n&= \\displaystyle\\int\\limits_{a}^{b} dx \\ \\delta(x-z) \\delta q(x).\n\\end{align}\nwe note that \n\\begin{align}\n\\frac{\\delta q(z)}{\\delta q(x)} \\equiv \\frac{\\delta M_z}{\\delta q(x)} = \\delta(x-z).\n\\end{align}\nWith a bit more work, one can show some more properties of the functional derivative (like changing the order of integration and derivation or the chain rule) and get\n\\begin{align}\n\\frac{\\delta M}{\\delta q(y)} = \\displaystyle\\int\\limits_{a}^{b} dx \\ \\frac{\\delta f(q(x))}{\\delta q(y)} = \\displaystyle\\int\\limits_{a}^{b} dx \\ f'(q(x)) \\frac{\\delta q(x)}{\\delta q(y)} = f'(q(y)). \n\\end{align}\n\\end{proof}\n\n\n\n\\section{Hamiltonian description}\n\nNow, we are in the position to continue with the Hamiltonian description of field theory. First, we will define the needed quantities in general and see how the Hamiltonian equations generalizes in field theory. After, we will apply it to the KGF field and see how to interpret the results. Let's go ahead and define the conjugated or generalized momentum for a given field $\\varphi$ to be:\n\n\\begin{definition}[Generalized momentum]\n\\begin{align}\n\\pi(\\bar{x}) = \\frac{\\delta L}{\\delta \\dot{\\varphi}(\\bar{x})}.\n\\end{align}\n\\end{definition}\n\nThe Hamiltonian will be given by\n\\begin{definition}[Hamiltonian]\n\\begin{align}\nH[\\varphi(\\bar{x}), \\pi(\\bar{x})] = \\int d^3 x \\ \\dot{\\varphi}(\\bar{x}) \\pi(\\bar{x}) \\ - \\ L.\n\\end{align}\n\\end{definition}\n\n\nThe equation of motion (or time-evolution) is calculated like before\n\\begin{align}\n\\dot{g}[\\varphi(\\bar{x}), \\pi(\\bar{x})] = \\left\\{ g,H \\right\\},\n\\end{align}\nwhere the Poisson bracket is defined analogous to the discrete case by\n\\begin{definition}[Poisson bracket]\n\\begin{align}\n\\left\\{ f,g \\right\\} \\equiv \\displaystyle\\int d^3 z \\left( \\frac{\\delta f}{\\delta \\varphi(\\bar{z})} \\frac{\\delta g}{\\delta \\pi(\\bar{z})} - \\frac{\\delta g}{\\delta \\varphi(\\bar{z})} \\frac{\\delta f}{\\delta \\pi(\\bar{z})} \\right).\n\\end{align}\n\\end{definition}\n\nThe Hamiltonian equations of motion in field theory take the form:\n\\begin{align}\n\\dot{\\varphi}(\\bar{x}) = \\left\\{ \\varphi(\\bar{x}),H \\right\\} = \\displaystyle\\int d^3 z \\ \\frac{\\delta \\varphi(\\bar{x})}{\\delta \\varphi(\\bar{z})} \\frac{\\delta H}{\\delta \\pi(\\bar{z})} &= \\displaystyle\\int d^3 z \\ \\delta^3(\\bar{x} - \\bar{z}) \\frac{\\delta H}{\\delta \\pi(\\bar{z})} = \\frac{\\delta H}{\\delta \\pi(\\bar{x})} \\\\\n\\dot{\\pi}(\\bar{x}) = \\left\\{ \\pi(\\bar{x}),H \\right\\} = - \\displaystyle\\int d^3 z \\frac{\\delta H}{\\delta \\varphi(\\bar{z})} \\frac{\\delta \\pi(\\bar{x})}{\\delta \\pi(\\bar{z})} &= - \\displaystyle\\int d^3 z \\frac{\\delta H}{\\delta \\varphi(\\bar{z})} \\delta^3(\\bar{x} - \\bar{z}) = - \\frac{\\delta H}{\\delta \\varphi(\\bar{x})}.\n\\end{align}\n\nLet's apply this results to the Klein-Gordon-Fock field. Remembering the Lagrangian for the KGF field, one gets for the generalized momentum\n\\begin{align}\n\\pi(\\bar{x}) = \\frac{\\delta L}{\\delta \\dot{\\varphi}(\\bar{x})} = \\dot{\\varphi}(\\bar{x}).\n\\end{align}\nThe Hamiltonian can be written as:\n\\begin{align}\nH[\\varphi(\\bar{x}), \\pi(\\bar{x})] &= \\int d^3 x \\ \\dot{\\varphi}(\\bar{x}) \\pi(\\bar{x}) \\ - \\ L \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\left( \\pi^2(\\bar{x}) + (\\nabla \\varphi)^2 + m^2 \\varphi^2 \\right).\n\\end{align}\nThe Hamiltonian equations of motion are\n\\begin{align}\n\\dot{\\varphi}(\\bar{x}) &= \\frac{\\delta H}{\\delta \\pi(\\bar{x})} = \\pi(\\bar{x}) \\label{eq:1h} \\\\\n\\dot{\\pi}(\\bar{x}) &= - \\frac{\\delta H}{\\delta \\varphi(\\bar{x})} = - m^2 \\phi(\\bar{x}) - \\frac{\\delta \\left[\\displaystyle\\int (\\nabla \\varphi)^2 d^3 y \\right]}{2 \\ \\delta \\varphi(\\bar{x})} \\notag \\\\\n&= - m^2 \\phi(\\bar{x}) - \\displaystyle\\int d^3 y \\ \\nabla \\varphi(\\bar{y}) \\ \\frac{\\delta (\\nabla \\varphi(\\bar{y}))}{\\delta \\varphi(\\bar{x})} \\notag \\\\\n&= - m^2 \\phi(\\bar{x}) - \\displaystyle\\int d^3 y \\ \\nabla_y \\varphi(\\bar{y}) \\ \\nabla_y \\left( \\delta^3(\\bar{x}-\\bar{y}) \\right) \\notag \\\\\n&= - m^2 \\varphi(\\bar{x}) + \\displaystyle\\int d^3 y \\ \\Delta \\varphi(\\bar{y}) \\ \\delta^3(\\bar{x}-\\bar{y}) \\notag \\\\\n&= - m^2 \\varphi(\\bar{x}) + \\Delta \\varphi(\\bar{x}). \\label{eq:2h}\n\\end{align}\n\nDifferentiating equation \\eqref{eq:1h} and inserting equation \\eqref{eq:2h} yields\n\\begin{align}\n\\ddot{\\varphi}(t, \\bar{x}) = \\dot{\\pi}(t, \\bar{x}) = (\\Delta - m^2) \\ \\varphi(t, \\bar{x}),\n\\end{align}\nwhich is nothing less than the Klein-Gordon-Fock equation.\n\n\n\\begin{definition}[Klein-Gordon-Fock equation]\n\\begin{align}\n(\\partial_{\\mu} \\partial^{\\mu} + m^2) \\ \\varphi(x^{\\nu}) = 0. \n\\end{align}\n\\end{definition}\n\n\\vspace{10pt}\n\nNow, we want to analyse this equation a bit further. Its general solution is:\n\\begin{align}\\label{eq:KGF}\n\\varphi(t,\\bar{x}) = \\displaystyle\\int d^3 k \\ c_1(\\bar{k}) \\ \\text{e}^{i k_{\\mu} x^{\\mu}} + \\displaystyle\\int d^3 k \\ c_2(\\bar{k}) \\ \\text{e}^{- i k_{\\mu} x^{\\mu}},\n\\end{align}\nwhere $c_1(\\bar{k}), c_2(\\bar{k})$ are complex coefficients for each $\\bar{k}$. If $c_2(\\bar{k}) = c_1^*(\\bar{k})$, the field $\\varphi(t,\\bar{x})$ is real-valued. One can easily derive a condition which $k_{\\mu}$ must satisfy in order to be a solution of the KGF equation. Inserting the plane wave exponential into the KGF equation, we get \n\\begin{alignat*}{2}\n    &\\qquad& (\\partial_{\\mu} \\partial^{\\mu} + m^2) \\text{e}^{i k_{\\mu} x^{\\mu}} &= 0 \\\\\n    &\\Leftrightarrow& \\left((i k_0)^2 - (- i \\bar{k})^2 + m^2 \\right) \\text{e}^{i k_{\\mu} x^{\\mu}} &= 0 \\\\\n    &\\Leftrightarrow& \\left( - k_0^2 + \\bar{k}^2 + m^2 \\right) \\text{e}^{i k_{\\mu} x^{\\mu}} &= 0 .\n\\end{alignat*}\nSince the exponential isn't zero, it follows that we must have\n\\begin{align}\nk_0 = \\pm \\sqrt{m^2 + \\bar{k}^2}\n\\end{align}\nfor a solution of the KGF equation. This is the relativistic dispersion relation for a particle with\nmass $m$. That's why we really can interpret the quadratic terms in the fields like mass terms. From here, it follows also that we have two solutions, one with positive frequency and one with negative frequency. If we change $\\bar{k} \\rightarrow -\\bar{k}$, the sign of the space part does change too but the time part stays the same:\n\\begin{align}\nk_{\\mu} x^{\\mu} = \\sqrt{m^2 + \\bar{k}^2} \\ t - \\bar{k} \\bar{x}.\n\\end{align} \nThat's why we can split the general solution into two parts like in \\eqref{eq:KGF}. Since the KGF Lagrangian is regular, we have no constraints. In electrodynamics, this is not the case anymore and we will see how constraints enter into the Hamiltonian description.", "meta": {"hexsha": "4ef20610390c4680f721ccc5f1a08b90039ebfa7", "size": 14587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04_field.tex", "max_stars_repo_name": "Spektralzerleger/Hamilton-Systems", "max_stars_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-11T22:55:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-11T22:55:50.000Z", "max_issues_repo_path": "04_field.tex", "max_issues_repo_name": "Spektralzerleger/Hamilton-Systems", "max_issues_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "04_field.tex", "max_forks_repo_name": "Spektralzerleger/Hamilton-Systems", "max_forks_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.2967479675, "max_line_length": 457, "alphanum_fraction": 0.6790292726, "num_tokens": 4899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.680251711250623}}
{"text": "\\section{Tricks}\n\\begin{enumerate}\n\n\\item\nIn a script, line breaking is allowed provided the line breaks occur immediately after operators.\nThe scanner will automatically go to the next line after an operator.\n\n\\item\nSetting \\verb$trace=1$ in a script causes each line to be printed just before it is evaluated.\nThis is useful for debugging.\n\n\\item\nThe last result is stored in the symbol $last$.\n\n\\item\nUse \\verb$contract(A)$ to get the mathematical trace of matrix $A$.\n\n\\item\nUse \\verb$binding(s)$ to get the unevaluated binding of symbol $s$.\n\n\\item\nUse \\verb$s=quote(s)$ to clear symbol $s$.\n\n\\item\nUse \\verb$float(pi)$ to get the floating point value of $\\pi$.\nSet \\verb$pi=float(pi)$ to evaluate expressions with a numerical value for $\\pi$.\nSet \\verb$pi=quote(pi)$ to make $\\pi$ symbolic again.\n\n\\item\nAssign strings to unit names so they are printed normally.\nFor example, setting \\verb$meter=\"meter\"$ causes the symbol {\\it meter}\nto be printed as meter instead of $m_{eter}$.\n\n\\item\nUse \\verb$expsin$ and \\verb$expcos$ instead of \\verb$sin$ and \\verb$cos$.\nTrigonometric simplifications occur automatically when exponentials are used.\n\n\\item\nUse \\verb$A==B$ or \\verb$A-B==0$ to test for equality of $A$ and $B$.\nThe equality operator \\verb$==$ uses a cross multiply algorithm to eliminate denominators.\nHence \\verb$==$ can typically determine equality even when the unsimplified result of $A-B$ is nonzero.\nNote: Equality tests involving floating point numbers can be problematic\ndue to roundoff error.\n\n\\item\nIf local symbols are needed in a function, they can be appended to {\\it arg-list}.\n(The caller does not have to supply all the arguments.)\nThe following example uses Rodrigues's formula to\ncompute an associated Legendre function of $\\cos\\theta$.\n\\begin{equation*}\nP_n^m(x)=\\frac{1}{2^n\\,n!}(1-x^2)^{m/2}\\frac{d^{n+m}}{dx^{n+m}}(x^2-1)^n\n\\end{equation*}\nFunction $P$ below first computes $P_n^m(x)$ for local variable\n$x$ and then uses {\\it eval} to replace $x$ with $f$.\nIn this case, $f=\\cos\\theta$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nx = 123 -- global x in use, need local x in P\nP(f,n,m,x) = eval(1/(2^n n!) (1 - x^2)^(m/2) d((x^2 - 1)^n,x,n + m),x,f)\nP(cos(theta),2,0) -- arguments f, n, m, but not x\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{3}{2} \\cos(\\theta)^2-\\tfrac{1}{2}$\n\n\\bigskip\n\\noindent\nNote: The maximum number of arguments is nine.\n\n\\end{enumerate}\n", "meta": {"hexsha": "3d3b9de193c5193347121d95d448a0ca46a0e724", "size": 2400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tricks.tex", "max_stars_repo_name": "wuyudi/eigenmath", "max_stars_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/tricks.tex", "max_issues_repo_name": "wuyudi/eigenmath", "max_issues_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/tricks.tex", "max_forks_repo_name": "wuyudi/eigenmath", "max_forks_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 33.8028169014, "max_line_length": 103, "alphanum_fraction": 0.72, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6802517018651447}}
{"text": "\\chapter{Markov Random Fields}\n\\emph{“但是你们肯定没我懂”}\n\\newpage\n\n\n\\section{Markov Random Fields}\n    A stochastic process is a collection of random variables $\\{X_t|x\\in\\mathbb{T}\\}$ where $\\mathbb{T}$ is a subset of reals $\\mathbb{R}$. And a \\textbf{Random Field} is a generalization of a stochastic process.\n\n    \\subsection{Markov Random Fields}\n        \\begin{definition}[Random Field]\n            A \\textbf{Random Field} is a collection of random variables $\\{X_s:s\\in\\mathcal{G}\\}$, where $\\mathcal{G}$ is not necessarily a subset of $\\mathbb{R}$. And we will consider $\\mathcal{G}$ to be a set of nodes of a \\emph{graph}. \n        \\end{definition}\n\n        \\begin{definition}\n            Given a graph $\\mathcal{G}$ with nodes $V=\\{1,2,\\dots,n\\}$, let $\\mathcal{N}(t)$ denote the set of neighbours of $t$. The collection of $\\{X_1, \\dots, X_n\\}$ is a \\textbf{Markov Random Field} if\n            \\[ \\forall v \\quad \\mathbb{P}\\left[X_v = i \\middle\\vert \\bigwedge_{w \\in V-\\{v\\}} X_w = j_w\\right] = \\mathbb{P}\\left[X_v = i \\middle\\vert \\bigwedge_{w\\in\\mathcal{N}(v)}X_w=j_w\\right] \\]\n            i.e. the state of current node is only dependent on its neightbours.\n        \\end{definition}\n\n    \\subsection{Some Notations}\n        Let $x$ be the values of random varialbes $[X_1,\\dots,X_n]$(a vector of length $n$), where each element $x_v$ (the state of each node) come from a state space $\\{1,2,\\dots,q\\}$. Let $S$ be a subset of $V$, then\n        \\begin{itemize}\n            \\item We use $x_S$ to denote the values of random varialbes $X_v \\quad v \\in S$. (a vector $[x_v]$ of length $|S|$, where $v\\in S$)\n            \\item We use $p(x_S)$ to denote $\\mathbb{P}[X_S=x_S]$.\n        \\end{itemize}\n        $p(x_S)$ is the probability that the nodes in $S$ have states in $x_S$.\n\n        Let $S$, $T$ be two subsets of $V$, let $x$ be the vector of nodes in $S$, let $y$ be the vector of nodes in $T$, then\n        \\begin{itemize}\n            \\item We use $p(x_S|y_T)$ to denote $\\mathbb{P}[X_S=x_S|X_T=y_T]$\n        \\end{itemize}\n\n        And here comes the problem: In a Markov chain, once the initial distribution and the probability transition matrix are specified, we will be able to construct and simulate the chain. However, for a MRF, even if we know all $\\mathbb{P}[X_t=j|\\mathcal{N}(j)]$, we may still be unable to construct the MRF, because the joint distribution of all $v \\in V$ may not even exist.\n\n        Consider the simplest yet still non-trivial MRF, which consists of only two nodes $X_1$ and $X_2$ taking values in $\\{0,1\\}$. We have to specify 3 of the 4 values $p(x_1, x_2)$ (only 3 are required because they sum up to 1 so the fourth one is determine once the remaining 3 are specified), such that they satify the 4 specified conditional probabilities $\\mathbb{P}[x_1|x_2=1/0]$ and $\\mathbb{P}[x_2|x_1=1/0]$. This is generally difficult (just like we cannot generally solve a system of 4 equations containing only 3 unknown variables).\n\n        Therefore in MRF, specifying all conditional probabilities is of little help. Luckily, an alternative exists.\n\n\n\\section{Gibbs Distribution}\n    In this section, we discuss the Gibbs Distribution. A random field having the Markov property is equivalent to its having a Gibbs distribution, and the latter one is much more friendly than conditional probabilities.\n\n    \\subsection{Completeness}\n        \\begin{definition}[Complete Graphs]\\label{def:CompleteGraph}\n            A set of nodes $C$ is \\textbf{complete} if all distinct nodes in $C$ are neightbours of each other.\n        \\end{definition}\n        \\begin{remark}\n            That is, $C$ is not complete if two of its nodes are not neightbours.\n        \\end{remark}\n\n        \\begin{definition}[Clique]\\label{def:Clique}\n            A \\textbf{clique} of a set $C$ is a maximal complete set of nodes in $C$.\n        \\end{definition}\n\n    \\subsection{Gibbs Distribution}\n        \\begin{definition}[Gibbs Distribution]\\label{def:GibbsDistribution}\n            Let $\\mathcal{G}$ be a finite graph. A \\textbf{Gibbs Distribution} with respect to $\\mathcal{G}$ is a probability mass function that can be expressed in the form of\n            \\[ p(x) = \\prod_{\\text{$C$ complete}}V_C(x) \\]\n            where $V_C(\\cdot)$ is a function that only depends on the values $x_C = [x_v:v \\in C]$ of $x$ at the nodes in a clique $C$. That is, if $x_C = y_C$, then $V_C(x) = V_C(y)$.\n        \\end{definition}\n\n    \\subsection{Examples of Gibbs Distibutions}\n        \\subsubsection{Independent Sets on a Graph}\n        Let $\\mathcal{G}=(V,E)$ be a graph. We want to generate a mask $\\{0,1\\}^{|V|}$ such that the result is a independent set. \\emph{The uniform distribution of all independent sets of $\\mathcal{G}$ has a Gibbs distribution}.\n\n        Let $A$ be any complete sub-graph of $\\mathcal{G}$, we define a weight function $w_A$ on $A$\n        \\[ w_A(x) = \\begin{cases}\n            0 &\\quad |A| = 2, x_A = [1,1]\\\\\n            1 &\\quad o.w.\n        \\end{cases} \\] \n\n        Therefore\n        \\[ p(x) \\sim w_A(x) = \\prod_{\\{i,j\\}\\in E}\\mathbb{I}[x(i) \\neq 1 \\vee x(j) \\neq 1] \\]\n\n        \\subsubsection{Proper Coloring}\n        Consider the coloring of a graph, suppose there are $q$ colors, let $\\Omega=\\{1,2,\\dots,q\\}^{|V|}$ be the sample space consisting of all possible color assignment to each node in $V$. Let $c$ be a mapping from $V$ to $\\Omega$, which represents a way to color all the nodes. A coloring is \\textbf{proper} if no neighbouring nodes have the same color. We will show that \\emph{the uniform distribution of all proper colorings on the graph has a Gibbs distribution}.\n        \\[ \\forall \\{i,j\\} \\in E \\quad c(i) \\neq c(j) \\]\n\n        We define a weight function $w_A(x)$ on all complete subgraphs of $\\mathcal{G}$ by\n        \\[ w_A(c) = \\begin{cases}\n            0 &\\quad c(i) = c(j), |A|=2\\\\\n            1 &\\quad o.w.\n        \\end{cases} \\]\n\n        And Therefore\n        \\[ p(c) \\sim w_A(c) = \\prod_{\\{i,j\\} \\in E}\\mathbb{I}[c(i) \\neq c(j)] \\]\n\n        \\subsubsection{Ising Model}\n        Consider a graph $\\mathcal{G}$ whose nodes form a subset of $\\mathbb{Z}^d$. For each $v \\in V$ there is a corresponding random variable $X_v \\in \\{0,1\\}$ (sometimes in $\\{-1,1\\}$). The Ising model gives a joint distribution of these random variables.\n\n        Let $\\sigma: V \\mapsto \\{0,1\\}$ be the configuration of each node. We consider a special case: let $m(x)$ be the set of monochromatic edges in $E$. By ``monochromatic'' we mean the configuration of the nodes $i,j$ of edge $e=\\{i,j\\}$ are the same.\n        \\[ m(x) = \\{\\{i,j\\}: \\sigma(i) = \\sigma(j)\\} \\]\n\n        The Ising model is parametrized by a positive parameter $\\beta$ (typically $\\beta < 1$). Let\n        \\[ w(x) = \\beta^{|m(x)|} \\]\n\n        Then the distribution $\\mu(x) \\sim w(x)$ is a Gibbs distribution.\n        \\[ \\mu(x) \\sim w(x) = \\prod_{\\{i,j\\} \\in E}\\beta^{\\mathbb{I}[x(i)\\neq x(j)]} \\]\n\n    \\subsection{Hammersley-Clifford Theorem}\n        \\begin{theorem}[Hammersley-Clifford]\\label{thm:HammersleyClifford}\n            Suppose that $X=(X_1,\\dots,X_n)$ has a positive joint probability mass function $\\mu(X) > 0 \\quad \\forall X$. Then $X$ is a Markov random field on $\\mathcal{G}$ if and only if $X$ has a Gibbs distribution w.r.t. $\\mathcal{G}$.\n        \\end{theorem}\n\n        The proof of the theorem is skipped due to time limitation. Can be found in References.\n\n\n\\section{Hidden Markov Models}\n    A Hidden Markov Model is a Markov random fields in which some random variables are observable, while others are not.\n\n    Suppose a hidden random variable chain is a Markov Chain $\\{X_t\\}$ with initial distribution $\\xi$ and transition probability $A$, and suppose each hidden state $X_t$ emits an observation $Y_t$ according to a probability matrix $B$. We can only oberseve $Y_t$, and we want to estimate $\\theta ] \\{\\xi, A, B\\}$.\n\n    Given a sequence of observations $y = (y_1, y_2, \\dots ,y_n)$, our goal is to find\n    \\[ \\hat{\\theta} = \\arg\\max_{\\theta} p_{\\theta}(y) = \\sum_x p_{\\theta}(x,y) \\]\n\n    If we can directly maximize $p_{\\theta}(y)$, then we are done. But this is practically impossible because we need to enumerate over all possible $x$.\n    \n    \\subsection{Expectation Maximization}\n        Let $L(\\theta) = p_{\\theta}(y)$. Maximizing $L(\\theta)$ is equivalent to maximizing $\\mathcal{L}(\\theta) = \\log L(\\theta)$.\n\n        The EM algorithm maximizes the \\emph{Expectation} of $p_{\\theta}(X,y)$ due to the complexity of directly maximizing $p_{\\theta}(x,y)$. Furthermore, it maximizes $\\mathbb{E}[p_{\\theta_t}(X,y)]$ using a current estimator $\\theta_t$ of $\\theta$, and update $\\theta_t$ iteratively.\n\n        The general framework for the M-Step of an EM Algorithm is\n        \\[ \\theta_{t+1} = \\arg\\max_{\\theta} \\mathbb{E}_{\\theta_t}\\left[ \\log p_{\\theta}(X,y)|Y=y \\right] \\]\n\n        \\subsubsection{Proof Of Correctness}\n        \\begin{definition}[KL Divergence]\\label{def:KLDivergence}\n            The \\textbf{KL-Divergence} is used to measure the difference of two distributions\n            \\[ D_{KL}(p\\|q) = \\sum_i p_i\\log p_i - \\sum_i p_i \\log q_i \\]\n        \\end{definition}\n        \\begin{proposition}[Non-negativity of KL Divergence]\\label{prop:PositivityOfKLDivergence}\n            \\[ D_{KL}(p\\|q) \\ge 0 \\]\n            The equality is achieved if and only if $p=q$.\n        \\end{proposition}\n\n        \\begin{lemma}\\label{lem:IncreasingLowerBoundOfEMAlgo}\n            If there exist $\\theta_0$ and $\\theta_1$ such that\n            \\[ \\mathbb{E}_{\\theta_0}[p_{\\theta_1}(X,y)|Y=y] > \\mathbb{E}_{\\theta_0}[p_{\\theta_0}(X,y)|y] \\]\n            Then\n            \\[ p_{\\theta_1}(y) > p_{\\theta_0}(y) \\]\n        \\end{lemma}\n        \\begin{proof}\n            By assuption of the lemma, we move the LHS to RHS,\n            \\begin{align*}\n                0 &< \\mathbb{E}_{\\theta_0}\\left[ \\log \\frac{p_{\\theta_1}(X,y)}{p_{\\theta_0}(X,y)} \\middle\\vert Y=y \\right]\\\\\n                &= \\sum_x p_{\\theta_0}(x|y) \\log \\frac{p_{\\theta_1}(x,y)}{p_{\\theta_0}(x,y)} \\quad \\text{(definition of conditional expectation)}\\\\\n                &= \\sum_x p_{\\theta_0}(x|y) \\log \\frac{p_{\\theta_1}(y)}{p_{\\theta_0}(y)} - \\sum_x p_{\\theta_0}(x,y)\\log\\frac{p_{\\theta_0}(x|y)}{p_{\\theta_1}(x|y)} \\quad \\text{(乘法定理)} \\\\\n                &\\le \\log\\frac{p_{\\theta_1}(y)}{p_{\\theta_0}(y)}\n            \\end{align*}\n        \\end{proof}\n\n    \\subsection{M-Step of HMM}\n        \\[ p_{\\theta}(x,y) = \\xi(x_0) \\cdot \\prod_{t=0}^{n-1}A(x_t,x_{t+1}) \\cdot \\prod_{t=0}^n B(x_t, y_t) \\]\n        Taking logarithm and expectation,\n        \\[ \\mathbb{E}_{\\theta_0}\\left[ \\log p_{\\theta}(X,y)|y \\right] = \\mathbb{E}_{\\theta_0}[\\log\\xi(x_0)|y] + \\sum_{t=0}^{n-1}\\mathbb{E}_{\\theta_0}[\\log A(x_t,x_{t+1})|y] + \\sum_{t=0}^n\\mathbb{E}_{\\theta_0}[\\log B(x_t,y_t)|y] \\]\n\n        Notice that the first term only involves $\\xi$, the second term only involves $A$ and the last tern only involes $B$.\n\n        \\subsubsection{Maximizing Term 1}\n        \\[ Term1 = \\sum_i \\mathbb{P}_{\\theta_0}[x=i|y]\\log\\xi(i) \\]\n        By Property of KL-Divergence \\ref{prop:PositivityOfKLDivergence}, $Term1$ is maximized when $\\xi(i) = \\mathbb{P}_{\\theta_0}[x=i|y]$.\n\n        \\subsubsection{Maximizing Term 2}\n        \\[ Term2 = \\sum_{t=0}^{n-1}\\sum_i\\sum_j \\mathbb{P}_{\\theta_0}[x_t=i,x_{t+1}=j|y] \\cdot \\log A(i,j) \\]\n        Exchange the summations,\n        \\[ \\sum_i\\sum_j \\left(\\sum_t \\mathbb{P}_{\\theta_0}[x_t=i,x_{t+1}=j|y] \\cdot \\log A(i,j)\\right) \\]\n        Again by \\ref{prop:PositivityOfKLDivergence}, $A(i,j)$ is maximized when\n        \\[ A(i,j) = \\frac{\\sum_t \\mathbb{P}_{\\theta_0}[x_t=i,x_{t+1}=j|y]}{\\sum_j\\sum_t \\mathbb{P}_{\\theta_0}[x_t=i,x_{t+1}=j|y]} \\]\n\n        \\subsubsection{Maximizing Term 3}\n        \\begin{align*}\n            Term3 &= \\sum_i \\sum_t \\mathbb{P}_{\\theta_0}[x_t=i|y]\\cdot\\log B(i,y_t)\\\\\n            &= \\sum_i \\sum_j \\sum_{t:y_t=j}\\mathbb{P}_{\\theta_0}[x_t=i|y]\\log B(i,j)\n        \\end{align*}\n        By Mafs, $B(i,j)$ is maximized when\n        \\[ B(i,j) = \\frac{\\sum_{t:y_t=j}\\mathbb{P}_{\\theta_0}[x_t=i|j]}{\\sum_j\\sum_{t:y_t=j}\\mathbb{P}_{\\theta_0}[x_t=i|j]} \\]\n\n    \\subsection{E-Step of HMM}\n        All the values required in M-step can be efficiently computed by dynamic programming algorithms. This method is generally known as the \\emph{forward-backward algorithm}. For details, please refer to AI2651 Notes.\n\n        We first clarify some notations.\n        \\begin{itemize}\n            \\item Let $Y=y$ be a sequence of observation, where $y_t$ denotes the observation at time $t$.\n            \\item Let $X=x$ be a sequence of hidden states, where $X_t=x_t$ denotes the hidden random variable and its value at time $t$.\n            \\item We use $y_1^t$ to denote the sequence $(y_1,\\dots,y_t)$, and similarly use $y_i^j$ to denote $(y_i, y_{i+1},\\dots, y_j)$.\n            \\item Suppose there are $N$ hidden states.\n            \\item Suppose the time ranges from $0$ to $T$.\n        \\end{itemize}\n    \n        All the probabilities computed below should be conditioned on (or parametrized by) $\\theta_0$, but for brevity, the parameter is intentionally omitted in the following part. \n        \n        Let\n        \\[ \\gamma_{(i,j)}(t) \\triangleq \\mathbb{P}[X_t=i, X_{t+1}=j | Y=y] \\]\n        be the probability that, given an observation $y$, the $t$-th and $(t+1)$-th hidden state are $i$ and $j$ repectively.\n    \n        Let\n        \\[ \\gamma_i(t) \\triangleq \\mathbb{P}[X_t=i|Y=y] \\]\n        be the probability that, given an observation $y$, the $t$-th hidden state is $i$.\n    \n        By the Law of Total Probability,\n        \\[ \\gamma_i(t) = \\sum_{j=1}^N \\gamma_{(i,j)}(t) \\]\n    \n        Then the parameters of the HMM is updated by\n        \\begin{itemize}\n            \\item $\\xi(i) = \\mathbb{P}[X_0=i|Y=y]$.\n            \\item $A(i,j) = \\frac{\\sum_{t=1}^T \\gamma_{(i,j)}(t)}{\\sum_{j'=1}^N\\sum_{t=1}^T\\gamma_{(i,j')}(t)}$\n            \\item $B(i,j) = \\frac{\\sum_{t:y_t=j}\\gamma_i(t)}{\\sum_{t=1}^T\\gamma_i(t)}$\n        \\end{itemize}\n    \n        So the problem is reduced to computing $\\gamma_{(i,j)}(t)$ and $\\gamma_i(t)$.\n    \n        By definition of conditional probability,\n        \\[ \\gamma_i(t) = \\mathbb{P}[X_t=i|Y=y] = \\frac{\\mathbb{P}[X_t=i, Y=y]}{\\mathbb{P}[Y=y]} \\]\n    \n        \\[ \\gamma_{(i,j)}(t) = \\mathbb{P}[X_t=i, X_{t+1}=j|Y=y] = \\frac{\\mathbb{P}[X_t=i, X_{t+1}=j, Y=y]}{\\mathbb{P}[Y=y]} \\]\n    \n        And the problem becomes computing $\\mathbb{P}[X_t=i, Y=y]$, $\\mathbb{P}[X_t=i,X_{t+1}=j, Y=y]$ and $\\mathbb{P}[Y=y]$.\n    \n        Define\n        \\[ \\alpha_i(t) \\triangleq \\mathbb{P}[X_t=i, Y_0^t=y_0^t] \\]\n        which is the probability that the hidden state at $t$ is $i$ when we observe $y_0^t$ in time interval $0:t$, where we recall that $y_1^t$ is the sequence $(y_0,y_2,\\dots,y_t)$.\n    \n        Define\n        \\[\\beta_i(t) \\triangleq \\mathbb{P}[Y_{t+1}^T=y_{t+1}^T|X_t=i] \\]\n        which is the probability that we observe $y_{t+1}^T$, given the hidden state at $t$ is $i$.\n    \n        \\begin{align*}\n            \\alpha_i(t) &= \\mathbb{P}[y_0^t, X_t=i]\\\\\n            &= \\sum_{j=1}^{N}\\mathbb{P}[y_0^t,X_t=i,X_{t-1}=j] \\quad \\text{(Law of Total Probability)}\\\\\n            &= \\sum_{j=1}^{N}\\mathbb{P}[y_0^{t-1},y_t,X_t=i,X_{t-1}=j] \\quad (\\text{Extract $y_t$ from $y_0^t$})\\\\\n            &= \\sum_{j=1}^{N}\\mathbb{P}[y_t|y_0^{t-1},X_t=i,X_{t-1}=j]\\\\\n            &\\quad \\cdot \\mathbb{P}[X_t=i|y_0^{t-1},X_{t-1}=j]\\\\\n            &\\quad \\cdot \\mathbb{P}[y_0^{t-1},X_{t-1}=j] \\quad \\text{(Expand terms using conditional expectation)}\\\\\n            &= \\sum_{j=1}^{N}\\mathbb{P}[y_t|X_t=i] \\cdot \\mathbb{P}[X_t=i|X_{t-1}=j] \\cdot \\mathbb{P}[y_0^{t-1},X_{t-1}=j]\\quad\\text{(Assumption of HMM/MRF)}\\\\\n            &= B(i,y_t)\\sum_{j=1}^{N}A(j,i)\\alpha_j(t-1) \\quad \\text{(Definitions)}\n        \\end{align*}\n        This result gives a recursive relation between $\\alpha_i(t)$ and all $\\alpha_j(t-1)$, so $\\alpha_i(t)$ can be computed by memoized search over $t=0:T$.\n    \n        Similarly,\n        \\begin{align*}\n            \\beta_i(t) &= \\mathbb{P}[y_{t+1}^T|X_t=i]\\\\\n            &= \\sum_{j=1}^{N}\\mathbb{P}[y_{t+1},y_{t+2}^T,X_{t+1}=j|X_t=i]\\\\\n            &= \\sum_{j=1}^{N}\\mathbb{P}[y_{t+1}|X_{t+1}=j]\\mathbb{P}[X_{t+1}=j|X_t=i]p(y_{t+2}^T|_{t+1}=j)\\\\\n            &= \\sum_{j=1}^{N}B(j, y_{t+1})A(i,j)\\beta_{j}(t+1)\n        \\end{align*}\n        Again this result is a recursive relation between $\\beta_i(t)$ and $\\beta_j(t+1)$, so $\\beta_i(t)$ can be computed by memoized search over $t=T:0$.\n    \n        Notice that the $A(i,j)$ and $B(i,j)$ here are the results computed in the previous iteration.\n    \n        Once all $\\alpha_i(t)$ and $\\beta_i(t)$ are computed, using the law of total probability and enumerate all hidden state at some time $t$, we have\n        \\[ \\mathbb{P}[Y=y] = \\sum_{i=1}^N\\mathbb{P}[y_0^t, y_{t+1}^T, X_t=i] = \\sum_{i=1}^N \\mathbb{P}[y_0^t, X_t=i]\\mathbb{P}[y_{t+1}^T|X_t=i] = \\sum_{i=1}^N \\alpha_i(t)\\beta_i(t) \\quad \\forall t \\]\n        Therefore we should be able to compute $\\mathbb{P}[Y=y]$.\n    \n        Furthermore,\n        \\begin{align*}\n            \\mathbb{P}[X_t=i,X_{t+1}=j, y_0^T] &= \\mathbb{P}[y_{t+2}^T, y_{t+1}, y_1^t, X_t=i, X_{t+1}=j] \\quad \\text{(Split $y_1^T$)}\\\\\n            &= \\mathbb{P}[y_{t+2}^T|X_{t+1}=j]\\\\\n            &\\quad \\cdot \\mathbb{P}[y_{t+1}|X_{t+1}=j]\\\\\n            &\\quad \\cdot \\mathbb{P}[X_{t+1}=j|X_t=i]\\\\\n            &\\quad \\cdot \\mathbb{P}[X_t=i, y_0^t] \\quad \\text{(Conditional Probability and HMM assumptions)}\\\\\n            &= \\beta_j(t+1)B(j,y_{t+1})A(i,j)\\alpha_i(t)\n        \\end{align*}\n    \n        And similarly\n        \\begin{align*}\n            \\mathbb{P}[X_t=i, y_0^T] &= \\mathbb{P}[y_0^{t}, y_{t+1}^T, X_t=i]\\\\\n            &= \\mathbb{P}[y_{t+1}^T|X_t=i]\\mathbb{P}[y_0^t, X_t=i]\\\\\n            &= \\beta_i(t)\\alpha_i(t)\n        \\end{align*}\n    \n        Therefore, once we have $\\alpha_i(t)$ and $\\beta_i(t)$, and $A(i,j)$ and $B(i,j)$ in the previous iteration, we will also be able to compute $\\mathbb{P}[X_t=i, X_{t+1}=j, y_0^T]$ and $\\mathbb{P}[X_t=i,y_0^T]$. Then it follows that we will be able to compute $\\gamma_{(i,j)}(t)$ and $\\gamma_i(t)$.\n    \n        \\[ \\gamma_i(t) = \\frac{\\beta_i(t)\\alpha_i(t)}{\\sum_{i=1}^N \\alpha_i(t)\\beta_i(t)} \\]\n    \n        \\[ \\gamma_{(i,j)}(t) = \\frac{\\beta_j(t+1)B(j,y_{t+1})A(i,j)\\alpha_i(t)}{\\sum_{i=1}^N \\alpha_i(t)\\beta_i(t)} \\]\n        where $A(i,j)$ and $B(i,j)$ are the parameters in the previous iteration, and $\\alpha_i(t)$ and $\\beta_i(t)$ can be computed efficiently by DP, using the recursive relationship mentioned above.\n    \n        And eventually, we will be able to update the parameters.\n        \\[ A(i,j) = \\frac{\\sum_{t=1}^T \\gamma_{(i,j)}(t)}{\\sum_{j'=1}^N\\sum_{t=1}^T\\gamma_{(i,j')}(t)} \\]\n        \\[ B(i,j) = \\frac{\\sum_{t:y_t=j}\\gamma_i(t)}{\\sum_{t=1}^T\\gamma_i(t)} \\]\n        \\[ \\xi(i) = \\gamma_i(0) \\]\n", "meta": {"hexsha": "4c1fba63d6bbba5fefc1ef0ac35639b73d21e216", "size": 18784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/MarkovRandomFields.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/MarkovRandomFields.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/MarkovRandomFields.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.609929078, "max_line_length": 546, "alphanum_fraction": 0.6017355196, "num_tokens": 6485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6800174679242775}}
{"text": "\\section{Methods}\nAs our project is to create a model with reinforcement learning, specifically DQN,\nwe do not have a predefined dataset. With this in mind, our methodology can be separated\ninto three parts.\n\n\\subsection{Reinforcement Learning}\nReinforcement Learning (RL) is a subset of Machine Learning (ML) where the\naim is to teach a model, called agent, via its interactions with the surrounding environment.\nThis method of learning requires no set of labeled or unlabeled data to be collected before\nthe learning actually starts. Instead the agent, typically a neural network,\nis used for predicting the optimal action to be taken at each step based on its observation\nand a reward is determined by the environment which is used for training the agent.\nIn RL, this environment is modeled as a Markov Decision Process (MDP)~\\autocite{BUSONIU20188}.\n\n\\subsubsection{Markov Decision Process}\nMDP is a mathematical framework based on Markov Chains for decision making processes\nwith inherent randomness. In Markov Decision Processes, we define:\n\\begin{itemize}\n    \\item \\(S\\): State Space (finite set),\n    \\item \\(A\\): Action Space (finite set),\n    \\item \\(A_s\\): Set of actions available at state \\(s\\),\n    \\item\n          \\(P^a_{ss'} = P_a(s,s') = P(s_{t+1} = s' \\;|\\; s_t = s, a_t = a)\\) is the probability of action \\(a\\) in state \\(s\\) leading to state \\(s'\\),\n    \\item \\(R_a(s, s')\\): Reward received after transitioning from \\(s\\) to \\(s'\\).\n\\end{itemize}\n\n\\subsubsection{Markov Property}\nFor RL agents to work with MDPs we need the environment to be fully observable,\nmeaning that state \\(s\\) must capture all the characteristics of the environment.\nIn more technical terms, any state is \\(S\\) must satisfy the Markov Property which is defined as.\n\\begin{equation}\n    P[s_{t+1} \\;|\\; s_t] = P[s_{t+1} \\;|\\; s_1, \\ldots, s_t]\n\\end{equation}\nThis property essentially enables the environment to be memoryless which is required for\nMarkov Chains and more importantly its extension MDPs.\n\n\\subsubsection{Policy}\nThe objective in an MDP is to optimize the \\textit{policy} of the decision making algorithm.\nHere, we define the function \\(\\pi(s)\\) that outputs the action chosen by the decision maker\nbased on the current state \\(s\\). This optimization mainly done by maximizing the cumulative\nreward function. This function can be expressed as:\n\\begin{equation}\n    G_t = \\sum^{\\infty}_{t=0}{\\gamma^t R_a(s_t, s_{t+1})},\\;\n\\end{equation}\nwhere \\(0\\leq \\gamma \\leq 1\\) is the discount factor. The equation above introduces the concept of \\textit{discount factors}. This parameter is quite important as it is one of the hyperparameters of RL training loops. It is useful for avoiding cyclic behavior and infinite returns, and representing an exponentially increasing uncertainty for the future time steps.\n\nMoreover, the policy that maximizes the function given above is regarded as as the\n\\textit{optimal policy} and denoted as \\(\\pi^*(s)\\). It should be noted that this optimal policy is not necessarily unique.\n\n\\subsubsection{State-Value Function}\nThe state-value function, or just value function, is denoted by \\(V_\\pi(s)\\). It is the expected return stating from state \\(s\\) and following policy \\(\\pi \\) of an MDP\\@. In most applications, it is used to evaluate how good being in a state is. It is mathematically expressed as:\n\\begin{equation}\n    V_\\pi(s) = E_\\pi[G_t \\;|\\; s_t = s]\n\\end{equation}\nAs can be seen in the equation above, calculating the cumulative reward function is required\nto find the value function of a state. This can be decomposed into a recursive function\nas the current reward plus the discounted value function of the successor by utilizing\nthe Bellman Equation.\n\\begin{equation}\n    V_\\pi(s) = E_\\pi[R_{t+1} + \\gamma V_\\pi(s_{t+1}) \\;|\\; s_t = s]\n\\end{equation}\nWith this done, we now define the state-value function that is produced by the optimal\npolicy \\(\\pi^*\\) as the \\textit{optimal state-value function}. In mathematical terms:\n\\begin{equation}\n    V_*(s) = \\max_\\pi{V_\\pi(s)}\n\\end{equation}\n\n\\subsubsection{Action Value Function}\nThe action value function, also called the Q-function, is the expected return starting from state \\(s\\), taking action \\(a\\), and then following policy \\(\\pi \\). This is expressed as:\n\\begin{equation}\n    Q_\\pi(s,a) = E_\\pi[G_t \\;|\\; s_t = s, a_t = a]\n\\end{equation}\nSimilar to the state-action function, we can also decompose this into a recursive function by redefining\n\\begin{equation}\n    G_{t} = R_{t+1} + \\gamma Q_\\pi(s_{t+1}, a_{t+1}),\n\\end{equation}\nand define the optimal action-value function as:\n\\begin{equation}\n    Q_*(s,a) = \\max_\\pi{Q_\\pi(s,a)}\n\\end{equation}\n\n\\subsubsection{Finding the Optimal Policy}\nIn all MDPs, three conditions are satisfied:\n\\begin{itemize}\n    \\item An optimal policy \\(\\pi^*\\) exists (not necessarily unique),\n    \\item Optimal policy achieves the optimal state-value function\n          \\begin{equation}\n              V_{\\pi^*}(s) = V_*(s)\n          \\end{equation}\n    \\item Optimal policy achieves the optimal action-value function\n          \\begin{equation}\n              Q_{\\pi^*}(s,a) = Q_*(s, a)\n          \\end{equation}\n\\end{itemize}\nThese three assumptions can be used to shows that finding the optimal policy\n\\(\\pi^*\\) to solve the MDP can be done by maximizing over \\(Q_*(s,a)\\) with:\n\\begin{equation}\n    \\pi_*(a | s) =\n    \\begin{cases}\n        1 & \\text{if }\\argmax_{a}{Q_*(s,a)} \\\\\n        0 & \\text{otherwise}\n    \\end{cases}\n\\end{equation}\nThis equation essentially means that finding the optimal policy can be done by\nfollowing the path given by \\(Q_*(s,a)\\) assuming that the optimal Q function is known~\\autocite{mnih2013playing}.\n\n\\subsection{Neural Networks}\nArtificial Neural Networks (ANNs), or simply Neural Networks (NNs), are\nmachine learning models that are loosely based on real life neurons and their connections.\nAlthough the theoretical work for these types of models were mostly developed in mid\n20\\textsuperscript{th} century, the applications of them were quite limited considering\nthe computational power required for the necessary calculations.\n\n\\begin{figure}[h]\n    \\centering{}\n    \\includegraphics[width=\\linewidth, height=0.3\\textheight, keepaspectratio]{img/ann.png}\n    \\caption{A Basic ANN Structure~\\autocite{buseyarentekin}}~\\label{fig:ANN}\n\\end{figure}\n\nIn our project, the observation provided to the RL agent compromises of screenshots of\nthe game's graphics. Therefore, the NN we used is made up of mainly convolutional layers\nfor image processing with smaller fully connected layers at the end for decision making.\nThe entire neural network used is:\n\\begin{enumerate}\n    \\item Convolutional Layer: 32 filters,\n    \\item ReLu Activation Layer,\n    \\item Convolutional Layer: 64 filters,\n    \\item ReLu Activation Layer,\n    \\item Convolutional Layer: 64 filters,\n    \\item ReLu Activation Layer,\n    \\item Fully Connected Layer: 512 wide,\n    \\item ReLu Activation Layer,\n    \\item Fully Connected Layer: 3 wide\n\\end{enumerate}\n\n\\subsection{Deep Q Learning (DQN)}\nThe standard Q learning algorithm uses the training episodes to fill up a Q table where\neach value corresponds to a specific action taken in a specific state. This method\nfunctions properly when the amount of state action pairs are relatively low.\nFor example, the ``Cliff Walking Problem'', shown below, is simple enough that a Q table would be the feasible. In fact, the table would only have between 160 to 192 entries depending on  how the environment is defined.\n\n\\begin{figure}[h]\n    \\centering{}\n    \\includegraphics[width=\\linewidth, height=0.3\\textheight, keepaspectratio]{img/cliff_walking.png}\n    \\caption{Cliff Walking Problem~\\autocite{Cliff_photo}}~\\label{fig:CliffWalk}\n\\end{figure}\n\n\nFor more complicated environments, this approach quickly loses its feasibility.\nIn those cases, like what we have in Breakout, a neural network is used as a\nnonlinear function approximator to replace the table. In DQN, the nn provides a\nmapping from the give state \\(s\\), to the Q function of all possible actions in that\nstate \\(Q(s,\\underline{a})\\).\\\\\nThe training loop of our network has a few additional, but still standard, features.\nThese are:\n\\begin{enumerate}\n    \\item\n          \\(\\epsilon \\)-greedy Policy: To simulate \\textit{exploration}, the action will be chosen randomly with probability \\(\\epsilon \\),\n    \\item Experience Replay Memory: To combat the unstable nature of deep reinforcement\n          learning, a circular memory with a set size will be used to reduce the correlations\n          between the sequence of observations used in every training batch.\n    \\item Target Network: An additional \\textit{target network} is used to increase the\n          stability of the learning.\n\\end{enumerate}\nThe final learning algorithm is given in~\\autoref{algo:dqn} in~\\autoref{app:dqn}.\n", "meta": {"hexsha": "75b52f3abba13aa5ba3615adad7f863c0a54c823", "size": 8837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "final/methods.tex", "max_stars_repo_name": "atahanyorganci/dqn", "max_stars_repo_head_hexsha": "56bc0d964dd1c84ba02780bd9288370d257f126d", "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": "final/methods.tex", "max_issues_repo_name": "atahanyorganci/dqn", "max_issues_repo_head_hexsha": "56bc0d964dd1c84ba02780bd9288370d257f126d", "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": "final/methods.tex", "max_forks_repo_name": "atahanyorganci/dqn", "max_forks_repo_head_hexsha": "56bc0d964dd1c84ba02780bd9288370d257f126d", "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": 53.234939759, "max_line_length": 365, "alphanum_fraction": 0.7388253932, "num_tokens": 2275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6800174606996997}}
{"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 6: The Laplace 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 goals of this assignment are:\n\\begin{itemize}\n    \\item To analyze LTI Systems using Laplace Transform.\n    \\item To see how RLC systems can be used as a low pass filter.\n    \\item To understand how to use the \\code{scipy.signals} toolkit.\n    \\item To plot graphs to understand the Laplace Transform.\n\\end{itemize}\n\n\n\n\n\\section{Subquestions}\n\\subsection{Time Response of a Spring}\nWe use the Laplace transform to solve a simple spring system.\nThe system is characterized by the differential equation:\n\\[\\dv[2]{x}{t} + 2.25x = f(t)\\]\nwith initial values being 0.\nThe Laplace Transform of the differential equation is:\n\\[H(s) =  \\frac{1}{s^2+2.25}\\]\nThe input signal is of the form \\(f(t) = \\cos{(\\omega t)}\\exp(-at)u(t)\\),\nwhere $a$ is the decay factor and $\\omega$ is the frequency of the cosine. \\\\\nThe Laplace Transform of the input signal is:\n\\[ F(s) = \\frac{s+a}{(s+a)^2+\\omega^2 }\\]\nFirst, these function are defined using numpy polynomials and multiply to get the output Laplace Transform.\nThen, the ILT of the function is evaluated using \\code{sp.impulse} to get the time domain sequences.\nThis is done for $\\omega=1.5$ (natural frequency of the system), and decay of 0.5.\n\\pagebreak\n\nThe time response is evaluated using:\n\\begin{lstlisting}\n    def time_response_spring(decay):\n        den = np.polymul([1, 0, 1.5**2], [1, 2*decay, decay**2 + 1.5**2])\n        return sp.lti([1, decay], den)\n\\end{lstlisting}\n\nThe impulse response is then plotted using:\n\\begin{lstlisting}\n    t, x = sp.impulse(time_response_spring(0.5), T=np.linspace(0, 50, 501))\n    plot(t, x, \"Damped Oscillator with 0.5/s Decay\", \"$t$\", \"$x$\")\n\\end{lstlisting}\n\nThus, we get:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{1.png}\n\\end{figure}\n\n\n\\subsection{Time Response with a Smaller Decay}\nWe do the same for a decay of 0.05. The impulse response is then plotted using:\n\\begin{lstlisting}\n    _, x = sp.impulse(time_response_spring(0.05), T=t)\n    plot(t, x, \"Damped Oscillator with 0.05/s Decay\", \"$t$\", \"$x$\")\n\\end{lstlisting}\n\nThus, we get:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{2.png}\n\\end{figure}\n\n\n\\subsection{Time Response at Varying Frequencies}\nThe frequency of the cosine term in $f(t)$ is varied from 1.4 to 1.6 in steps of 0.05\nand its effect plotted using:\n\\begin{lstlisting}\n    H = sp.lti([1], [1, 0, 1.5 ** 2])\n\n    for i, freq in enumerate(np.linspace(1.4, 1.6, 5)):\n        f = np.cos(freq * t) * np.exp(-0.05 * t) * (t >= 0)\n        x = sp.lsim(H, f, t)[1]\n        plt.plot(t, x)\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.55]{3.png}\n\\end{figure}\n\nWhen the input frequency is at the natural frequency, the output amplitude is maximum.\nIn the other cases the output amplitude decreases. \\\\\nThis is due to resonance.\n\n\n\\subsection{Coupled Spring Problem}\nIn this problem we have two differential equations and two variables to solve for.\nThe equations are:\n\\[\\dv[2]{x}{t} +(x-y) = 0 \\]\n\\[\\dv[2]{y}{t} +2(y-x) = 0 \\]\nwith initial condition as $x(0) = 1$. $y$ in the second equation is substituted from the first,\nand a fourth order differential equation in terms of $x$ is obtained.\nSimplifying this results in:\n\\[X(s) = \\frac{s^2+2}{s^3+3s} \\]\n\\[Y(s) =  \\frac{2}{s^3+3s} \\]\nTaking the ILT of these two expressions gives the time domain expressions of $x(t)$ and $y(t)$:\n\\begin{lstlisting}\n    # d2x/dt2 + (x - y) = 0\n    # d2y/dt2 + 2*(y - x) = 0\n    t, x = sp.impulse(sp.lti([1, 0, 2], [1, 0, 3, 0]), T=np.linspace(0, 20, 201))\n    _, y = sp.impulse(sp.lti([2], [1, 0, 3, 0]), T=t)\n\n    plot(t, x)\n    plot(t, y, \"Coupled Springs\", \"t\", \"$x(t)$  &  $y(t)$\", [\"$x(t)$\", \"$y(t)$\"])\n\\end{lstlisting}\nThese have been plotted as functions of time:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{4.png}\n\\end{figure}\n\n\n\\subsection{Magnitude \\& Phase Responses of Transfer Function}\nThe transfer function of the given RLC filter is:\n\\[ H(s) = \\frac{1}{LCs^2 + RCs + 1}\\]\nwith the initial conditions being zero. This is evaluated using:\n\\begin{lstlisting}\n    H = sp.lti([1], [1e-6 * 1e-6, 100 * 1e-6, 1])\n\\end{lstlisting}\nThe magnitude and phase responses of the transfer function are plotted using:\n\\begin{lstlisting}\n    w, S, phi = H.bode()\n    plt.semilogx(w, S)\n    plt.semilogx(w, phi)\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{5.png}\n\\end{figure}\n\nFrom the Bode plots, it is clear that the RLC System is a second order low pass filter,\nwith a 3db bandwidth of $10^4$ rad/s.\n\\pagebreak\n\n\n\\subsection{Analysis of the Output Signal}\nThe input is of the form:\n\\[v_i(t) = \\cos{(10^3t)}u(t) - \\cos{(10^6t)}u(t)\\]\nThe output voltage $v_o(t)$ is obtained by:\n\\begin{lstlisting}\n    def v_o(t, H):\n        v_i = np.cos(1e3 * t) * (t >= 0) - np.cos(1e6 * t) * (t >= 0)\n        return sp.lsim(H, v_i, t)[1]\n\\end{lstlisting}\n\nThe output voltage is then plotted using:\n\\begin{lstlisting}\n    y = v_o(np.linspace(0, 30e-6, 10000), H)\n    plot(np.linspace(0, 30, 10000), y,\n         \"Output Voltage for $0<t<30\\mu$s (short term)\",\n         \"$t$ (in $\\mu$s)\", \"$V_o(t)$\")\n\n    y = v_o(np.linspace(0, 15e-3, 10000), H)\n    plot(np.linspace(0, 15, 10000), y,\n         \"Output Voltage for $0<t<15m$s (long term)\", \"$t$ (in ms)\", \"$V_o(t)$\")\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{6a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{6b.png}\n\\end{figure}\n\nFrom the Bode plot, it is clear that the RLC System is a second order low pass filter,\nwith a 3db bandwidth of $10^4$ rad/s. \\\\\nThe short term response plot shows that the capacitor is charging up to meet the input amplitude. \\\\\nThe high frequency component can be seen as a ripple in the short term response plot.\nThis component is highly attenuated and hence not visible in the long term response plot. \\\\\nIn the long term response plot, the low frequency component passes almost unchanged,\nand the amplitude is almost 1. This is because $\\omega = 10^3$ rad/s is well within the 3-dB bandwidth\n($\\omega_{3dB} = 10^4$ rad/s) of the system. \\\\\nClearly, this demonstrates the fact that this is a low pass filter with bandwidth\n$\\omega_{3dB} = 10^4$ rad/s.\n\n\n\n\\section{Conclusion}\n\\begin{itemize}\n    \\item We analyzed LTI Systems using the Laplace Transform.\n    \\item We saw a low pass filter constructed from an RLC circuit.\n    \\item We used the scipy signals toolkit to calculate the time domain response and the Bode Plot.\n    \\item We plotted graphs to understand the above.\n\\end{itemize}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "bb0cd4d8dc769dc619b3f1ab452ca5bf289244f3", "size": 7177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment_06/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_06/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_06/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.0737327189, "max_line_length": 107, "alphanum_fraction": 0.6789745019, "num_tokens": 2282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6800174506090543}}
{"text": "\n%*******************************************************************************\n%*********************************** First Chapter *****************************\n%*******************************************************************************\n%!TEX root = 0.main.tex\n\n\\section{Graph Spherical Convolutions}\\label{sec:Graph Spherical Convolutions}\nIn this chapter we first introduce DeepSphere \\cite{DeepSphere}, an example of Graph Spherical Convolutional Neural Network that uses a modified version of the HKGL to perform graph convolutions and hierarchical pooling to achieve rotation equivariance, and computational efficiency. In section \\ref{sec:Chapter2:pointwise convergence of the Heat Kernel Graph Laplacian on the Sphere} we prove a pointwise convergence result of the full HKGL in the case of the sphere using a regular deterministic sampling scheme. In section \\ref{sec:Chapter2:How to build a good graph} we show a way of modifying the original graph of DeepSphere to improve its spectral convergence to $\\Delta_{\\mathbb S^2}$ while managing to contain the computational costs of graph convolutions.\n\\subsection{Graph Spherical Convolutional Neural Networks} \\label{sec:Chapter1:DeepSphere}\nPerraudin et al. \\cite{DeepSphere} have proposed a Spherical CNN to process and analyze spherical sky maps, as the Cosmic Radiation map in figure \\ref{fig:cosmicradiation}. Sky images are modeled as signals on the vertices of a \\textit{sparse} graph $G$ on the vertex set $V$ of the image pixels $(v_i)$ with weights\n$$\nw_{ij}=\\exp \\left(-\\frac{\\norm {v_i-v_j}^2}{4t}\\right)\n$$\nwhere the kernel width $t$ is a parameter to optimize. In an earlier work, Belkin et al. \\cite{NIPS2006_2989} proved the convergence of eigenvectors of the \\textit{full} graph $G$ to the eigenfunctions of the Laplace Beltrami operator $\\Delta_{\\mathbb S^2}$, when the data is sampled from a uniform distribution on $\\mathbb S^2$ (see Section \\ref{sec:Chapter1:theoretical foundations}, theorem \\ref{theo:spectral convergence}). For this reason and for the intuition we presented at the beginning of Chapter 2 when introducing the mean equivariance error $\\overline E_G$, we expect the construction of Perraudin et al. to work well only for images that were sampled with equi area sampling schemes. On such sampling schemes, since the graph Laplacian eigenvectors well approximate the spherical harmonics, the graph convolution (\\ref{eq:graph convolution}) well approximates the true spherical convolution (\\ref{eq:convolution}).\n\\begin{equation}\\label{eq:approx}\n\\mathbf f^\\intercal\\mathbf v_{i(\\ell, m)} \\approx \\int_{\\eta \\in \\mathbb S^2}f(\\eta)Y_\\ell^m(\\eta)d\\mu(\\eta)=\\hat f(\\ell,m)\n\\end{equation}\nThe most used sampling scheme by cosmologists and astrophysics is called HEALPix \\cite{HEALPix}, and is the one implemented in DeepSphere. HEALPix is an acronym for Hierarchical Equal Area isoLatitude Pixelization of a sphere. This sampling scheme produces a subdivision of the sphere in which each pixel covers the same surface area as every other pixel. It is parametrized by a parameter $N_{side}\\in\\mathbb N$, and is made of $n=12N_{side}^2$ pixels. The points of this sampling lie on isolatitude rings, making it possible to implement an FFT algorithm for the discrete SHT. The minimal resolution for HEALPix is given by $N_{side}=1$ and is made by 12 pixels. For each increasing value of $N_{side}$ each patch is divided into 4 equal area patches centered around the pixels of the new sampling (figure \\ref{fig:healpix sampling}).\n\nIn chapter \\ref{sec:Chapter4} of this work we'll deepen the relationship between the continuous spherical Fourier transform and the graph Fourier transform in case of non-uniform sampling measures. Perraudin et al. propose an efficient implementation of the graph convolution (\\ref{eq:graph convolution}) to be implemented in each layer of their Graph Spherical Convolutional Neural Network. They propose to learn only those filters that are polynomials of degree $q$ of the eigenvalues $\\lambda_i$\n\\begin{equation}\\label{eq:deepsphere filter}\n\\begin{aligned}\nk(\\lambda) &= \\sum_{j=0}^{q} \\theta_{j} \\lambda^{j}\\\\ \n\\Omega_k \\mathbf f &= \\mathbf{V}\\left(\\sum_{j=0}^{q} \\theta_{j} \\mathbf{\\Lambda}^{j}\\right) \\mathbf{V}^{\\top} \\mathbf{f}=\\sum_{j=0}^{q} \\theta_{j} \\mathbf{L}^{j} \\mathbf{f}\n\\end{aligned}\n\\end{equation}\nLearning the filter $k$ means learning the $q+1$ coefficients $\\theta_j$. In this way they solve different problems at once: first, to compute the graph convolution (\\ref{eq:graph convolution}) there's no need of computing the expensive eigen decomposition of $\\mathbf L$, but they just need to evaluate a polynomial of the sparse matrix $\\mathbf L$. Thanks to a suitable parametrization of the polynomial $\\sum_{j=0}^{q} \\theta_{j} \\mathbf{L}^{j}$ in term of Chebyshev polynomials, they manage to reduce the computations needed to evaluate such filter to $\\mathcal O(|E|)$. Since in a NN this filtering operation has to be computed in every forward and backward step of the training phase, this gain in efficiency is dramatically important and led to speedups of different orders of magnitude compared to the architecture of Cohen et al. (see Chapter 5, table \\ref{tab:SHREC17_class}). The filtering operation (\\ref{eq:deepsphere filter}) can be seen also in the vertex domain as a weighted sum of the $q$-neighborhoods of each vertex. This is due to the fact that $\\mathbf L $ has the same sparsity structure of the adjacency matrix of the graph, and thus $(\\mathbf L^q)_{ij}$ will be non-zero if and only if the vertices $v_i, v_j$ are connected by a path of length $q$. \n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{figs/chapter1/healpix.jpg}\n\t\\caption{\\label{fig:healpix sampling}HEALPix sampling for $N_{side}=1,2,3,4$ \\cite{HEALPix}}\n\\end{figure}\n\n Despite theorem \\ref{theo:spectral convergence} \\cite{Belkin:2005:TTF:2138147.2138189} states the spectral convergence of the \\textit{full} HKGL to $\\Delta_{\\mathbb S^2}$, the \\textit{sparse} version of the HKGL of Perraudin et al. does not seem to show such convergence. In figure (\\ref{fig:Old spectrum1}) we see the correspondence between the subspaces spanned by the graph Fourier modes of the graph Laplacian used by Perraudin et al. and the true spherical harmonics. We can also see the plot of the graph eigenvalues: we can see that they clearly come in groups of $(2\\ell+1)$ eigenvalues corresponding to each $\\ell$th degree of the spherical harmonics. We thus call $\\mathbf v_{i(\\ell, m)}$ the $i$th graph eigenmode corresponding the the one of degree $\\ell$ and order $m$. We compute the normalized Discrete Spherical Harmonic Transform (DSHT) of each $\\mathbf v_{i(\\ell, m)}$ up to the degree $\\ell_\\text{max}$. The entry $(\\ell, \\kappa)$ of the matrix represented in the figure corresponds to the percentage of energy of the $\\ell$th eigenspace $V_\\ell = \\text{span}\\{\\mathbf v_{i(\\ell, -\\ell)}, \\mathbf v_{i(\\ell, -\\ell+1)},...,\\mathbf v_{i(\\ell, \\ell)}\\}$ contained in the $\\kappa$th eigenspace of the true spherical harmonics. \n\\begin{figure}[h]\n\t\\begin{center}\n\t\t\\includegraphics[width=1\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/deepsphere_original.png}\n\t\t\\includegraphics[width=1\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/deepsphere_original_diagonal.png}\n\t\t\\includegraphics[width=1\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/05_figs/old_results3.png}\n\t\\end{center}\n\t\\caption{\\label{fig:Old spectrum1}Alignment of the eigenvectors of the graph Laplacian of the DeepSphere graph, the starting point of this work. In the middle we plot the diagonals of the matrices on top, and on the bottom we plot its spectrum for $N_{side}=16$.}\n\\end{figure} \nIn a perfect situation, this matrix would be the identity matrix, being all the energy of the $\\ell$th graph eigenspace contained in the corresponding one spanned by the true spherical harmonics. It can be seen that the eigenmodes of the graph Laplacian span almost the same subspaces as the spherical harmonics in the low frequencies, but this alignment gets worse at higher frequencies. Furthermore, it can be noticed that even by improving the resolution of the graph, the low frequency eigenspaces do not get better aligned.\n\n\n\n\\subsection{Pointwise convergence of the Heat Kernel Graph Laplacian on the Sphere}\n\n\\label{sec:Chapter2:pointwise convergence of the Heat Kernel Graph Laplacian on the Sphere}\nHere we prove a pointwise convergence result of the full graph Laplacian in the case of the sphere on a deterministic sampling scheme that is regular enough. Our proof will be constructed following the ideas presented in the proof of theorem \\ref{theo:Belkin pointwise convergence}.\n\\vspace{0.5cm}\n\\begin{definition}{}(Heat Kernel Graph Laplacian operator)\\\\\n\t\\label{def:Heat Kernel Graph Laplacian operator}\n\t\\text{Given a sampling $\\{x_i\\in\\mathcal M\\}_{i=0}^{n-1}$ of the manifold we define the \\textbf{operator} }$L_n^t$ such that\n\t$$L_n^tf(y) := \\frac{1}{n}\\left[ \\sum_{i=0}^{n-1} \\exp{-\\frac{||x_i-y||^2}{4t}}\\left(f(y)-f(x_i)\\right)\\right]$$\n\\end{definition}\n\\vspace{0.5cm}\nObserve that the Heat Kernel Graph Laplacian operator restricted on the sample points $x_0, ..., x_{n-1}$ acts as the usual Heat Kernel Graph Laplacian matrix $\\mathbf L_n^t$ rescaled by a factor of $\\frac{1}{n}$:\n$$L_n^tf(x_i) = \\frac{1}{n} (\\mathbf L_n^t\\mathbf f)_i$$.\n\\vspace{0.5cm}\n\\begin{snugshade*}\n\\begin{theorem}{from \\cite[Belkin et al.]{Belkin:2005:TTF:2138147.2138189}}\\\\\n\t\\label{theo:Belkin pointwise convergence}\n\tLet $\\mathcal M$ be a $k$-dimensional compact smooth manifold embedded in some euclidean space $\\mathbb R^N$, and fix $p\\in\\mathcal M$. Let the data points $x_1, ... x_n$ be sampled form a uniform distribution on the manifold $\\mathcal M$. Set $t_n=n^{-\\frac{1}{k+2+\\alpha}}$, for any $\\alpha>0$ and let $f\\in\\mathcal C_\\infty(\\mathcal M)$. Then:\n\t\n\t$$\\forall \\epsilon>0\\quad \\mathbb{P}\\left[\\left|\\frac{1}{t}\\frac{1}{(4 \\pi t)^{k/2}}L_{n}^{t_n} f(p)-  \\frac{1}{\\text{vol}(\\mathcal M)}L^{t_n} f(p)\\right|>\\epsilon\\right] \\xrightarrow{n\\to\\infty} 0$$\n\\end{theorem}\n\\end{snugshade*}\n\\vspace{0.5cm}\nThis theorem states a convergence in probability of $L_n^t$ to $L^t$, that is far from being as strong as spectral convergence of theorem \\ref{theo:spectral convergence}. However, we want to show that a similar result still holds in the specific case of the manifold $\\mathcal M$ being the 2-Sphere $\\mathbb S^2$ and where the points $x_1, ..., x_n$ are not sampled from a random distribution on $\\mathbb S^2$, but are defined by the HEALPix sampling. To understand the differences between theorem \\ref{theo:Belkin pointwise convergence} and theorem \\ref{theo:pointwise convergence in the healpix case} it is useful to first review the proof of theorem \\ref{theo:Belkin pointwise convergence}. For this proof we'll need to use the Hoeffding's inequality that we recall here under:\n\n(\\textit{Hoeffding's inequality})\\\\\nLet \\(X_{1}, \\ldots, X_{n}\\) be independent identically distributed random variables, such that\n\\(\\left|X_{i}\\right| \\leqslant K .\\) Then\n\\begin{equation}\\label{eq:Hoeffding}\n\\mathbb P\\left\\{\\left|\\frac{\\sum_{i} X_{i}}{n}-\\mathbb{E} X_{i}\\right|>\\epsilon\\right\\}<2 \\exp \\left(-\\frac{\\epsilon^{2} n}{2 K^{2}}\\right)\n\\end{equation}\n\n\\begin{proof}[Proof of Theorem \\ref{theo:Belkin pointwise convergence}]\n The first step is to observe that for any fixed $t>0$, any fixed function $f$ and a fixed point $y\\in\\mathbb S^2$,  the Heat Kernel Graph Laplacian $L_n^t$ is an unbiased estimator for the Functional Approximation of the Laplace-Beltrami $L^t$. In other words, $L_n^tf(y)$ is the empirical average of $n$ i.i.d. random variables $X_i= e^{-\\frac{||x_i-y||^2}{4t}}\\left(f(y)-f(x_i)\\right)$ with expected value corresponding to $L^tf(y)$. Thus,\n\\begin{equation}\n\\label{eq:expected value of heat kernel grah laplacian}\n\t\\mathbb E L_n^tf(y) = \t\\mathbb E \\frac{1}{n}X_i = \\mathbb E X_i = L^tf(y),\n\\end{equation}\nand by the strong law of large numbers we have that\n\\begin{equation}\n\\label{eq:convergence in probability}\n\\lim_{n\\to\\infty}L_n^tf(y) = L^t(y).\n\\end{equation}\nThe core of the work of Belkin et al. is the proof, that we will not discuss, of the following proposition.\n\n\\begin{prop} Under the same hypothesis of theorem \\ref{theo:Belkin pointwise convergence}, we have the following pointwise convergence\n\t$$\\frac{1}{t}\\frac{1}{(4\\pi t)^{k/2}} L^tf(p) \\xrightarrow{t\\to 0 } \\frac{1}{\\text{vol}(\\mathcal M)}\\triangle_{\\mathcal M}f(p).$$\n\t\\label{prop:3}\n\\end{prop}\nThanks to Proposition \\ref{prop:3} and equation (\\ref{eq:convergence in probability}), a straightforward application of Hoeffding's inequality with $K=\\frac{1}{t}\\frac{1}{(4\\pi t)^{k/2}}$ together with equation  (\\ref{eq:expected value of heat kernel grah laplacian}) leads to\n\n\\begin{equation}\n\t\\label{eq:hoeffding applied}\n\t\\mathbb{P}\\left[\\frac{1}{t(4 \\pi t)^{k / 2}}\\left|L_{n}^{t} f(y)- L^{t} f(y)\\right|>\\epsilon\\right] \\leq 2 e^{-1 / 2 \\epsilon^{2} n t(4 \\pi t)^{k / 2}}\n\\end{equation}\n\nWe want the right hand side of equation (\\ref{eq:hoeffding applied}) to go to $0$ for $n\\to\\infty, t\\to0$ at the same time. For this to happen, we need to find a sequence $(t_n)$ such that \n$$\\begin{cases}\nt_n\\xrightarrow{n\\to\\infty}0\\\\\n2 e^{-1 / 2 \\epsilon^{2} n t_n(4 \\pi t_n)^{k / 2}}\\xrightarrow{n\\to\\infty}0\\\\\n\\end{cases}$$\n\nBy fixing $t_n=n^{-\\frac{1}{k+2+\\alpha}}$, for any $\\alpha>0$, it is easy to check that \\\\$-1 / 2 \\epsilon^{2} n t_n(4 \\pi t_n)^{k / 2}\\xrightarrow{n\\to\\infty}+\\infty$, thus concluding the proof.\n\n\\end{proof}\n\nNow we can observe that in order to adapt this proof to the case of the sphere with an equi area sampling scheme we need to modify two key things. First, due to the deterministic nature of the sampling scheme, we need to prove that for any fixed $t>0$, any fixed function $f$ and any point $y\\in\\mathbb S^2$ \n\\begin{equation}\\label{eq:limit}\n\t\\left|L_n^tf(y)-L^tf(y)\\right|\\xrightarrow{n\\to \\infty} 0,\n\\end{equation}\nwithout relying on the strong law of large numbers. Once proven such result, we need to prove that\n\n$$\\left|\\frac{1}{4\\pi t^2}\\left(L_n^tf(x) - L^tf(x)\\right)\\right|\\xrightarrow[n\\to \\infty]{t\\to 0}0$$\n\nWe need now to define some geometrical quantities that we'll need. Given a sampling $x_0, ..., x_{n-1}$ define $\\sigma_i$ to be the patch of the surface of the sphere corresponding to the $i$th point of the sampling, define $A_i$ to be its corresponding area and $d_i$ to be the radius of the smallest ball in $\\mathbb R^3$ containing the i-th patch (see Figure \\ref{fig:Geometric characteristics of a patch}). Define $d^{(n)} := \\max_{i=0, ..., n}d_i$ and $A^{(n)}=\\max_{i=0, ..., n}A_i$.\\\\\nOnce proven the limit (\\ref{eq:limit}), Proposition \\ref{prop:3} leads to our main result:\n\\vspace{1cm}\n\\begin{snugshade*}\n\t\\begin{theorem}\n\t\tFor a sampling $\\mathcal P = \\{x_i\\in\\mathbb S^2\\}_{i=0}^{n-1}$ of the sphere that is equi area and such that $d^{(n)})\\leq \\frac{C}{\\sqrt{n}}$, for all $f: \\mathbb S^2 \\rightarrow \\mathbb R$ Lipschitz with respect to the euclidean distance in $\\mathbb R^3$, for all $y\\in\\mathbb S^2$, there exists a sequence $t_n = n^\\beta$ such that the rescaled Heat Kernel Graph Laplacian operator $\\frac{|\\mathbb S^2|}{4\\pi t_n}L^t_n$ converges pointwise to the Laplace Beltrami operator on the sphere $\\triangle_{\\mathbb S^2}$  for $n\\to\\infty$:\n\t\t$$ \\lim_{n\\to\\infty}\\frac{|\\mathbb S^2|}{4\\pi t_n} L_n^{t_n}f(y) =  \\triangle_{\\mathbb S^2}f(y).$$\n\t\t\\label{theo:pointwise convergence in the healpix case}\n\t\\end{theorem}\n\\end{snugshade*}\n\n\\vspace{1cm}\n\\begin{minipage}{.4\\textwidth}\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{figs/chapter1/d_iA_i.jpg}\n\t\\captionof{figure}{\\label{fig:Geometric characteristics of a patch}Geometric characteristics of the $i$th patch}\n\\end{minipage}%\n\\hfill\n\\begin{minipage}{.5\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{figs/chapter1/Heal_Base.png}\n\t\\captionof{figure}{\\label{fig:HEALPix equal areas patches}HEALPix equal areas patches for $N_{side}=1$, $N_{side}=2$}\n\t\\vspace{0.5cm}\n\\end{minipage}\n\n\\subsubsection{Proof of the pointwise convergence of the Heat Kernel Graph Laplacian on the Sphere for an equi area sampling scheme}\n\nOur first goal is to prove the following Proposition: \n\\vspace{0.5cm}\n\\begin{prop}\\label{prop:1}\n\tFor an equal area sampling $\\{x_i\\in\\mathbb S^2\\}_{i=0}^{n-1}: A_i=A_j \\forall i,j$ of the sphere it is true that for all $f: \\mathbb S^2 \\rightarrow \\mathbb R$ Lipschitz with respect to the euclidean distance $||\\cdot||$ with Lipschitz constant $\\mathcal L_f$ \n\t$$\n\t\\left| \\int_{\\mathbb S^2}f({ x})\\text{d}{\\mu(x)} - \\frac{1}{n}\\sum_i f( x_i)\\right|\\leq \\mathcal L_fd^{(n)}.\n\t$$\n\tFurthermore, for all $y\\in\\mathbb S^2$ the Heat Kernel Graph Laplacian operator $L^t_n$ converges pointwise to the functional approximation of the Laplace Beltrami operator $L^t$\n\t$$ L_n^tf(y)\\xrightarrow{n\\to\\infty} L^tf(y).$$\n\\end{prop} \n\\vspace{0.5cm}\n\n\n\\begin{proof}\n\tLet us assume that the function $f:\\mathbb R^3\\rightarrow \\mathbb R$ is Lipschitz with Lipschitz constant $\\mathcal L_f$, we have \n\t\n\t$$\\left| \\int_{\\sigma_{i}}f({ x})\\text{d}{\\mu(x)} - \\frac{1}{n}f( x_i)\\right| \\leq \\mathcal L_fd^{(n)}\\frac{1}{n} $$\n\n\tSo, by triangular inequality and by summing all the contributions of all the $n$ patches\n\t$$\\left| \\int_{\\mathbb S^2}f({ x})\\text{d}{\\mu(x)} - \\frac{1}{n}\\sum_i f( x_i)\\right| \\leq \\sum_i \\left| \\int_{\\sigma_{i}}f({ x})\\text{d}{\\mu(x)} - \\frac{1}{n}f( x_i)\\right|\\leq n  \\mathcal L_fd^{(n)}\\frac{1}{n} = \\mathcal L_fd^{(n)}$$\t\n\tThanks to this result, we have the following two pointwise convergences\n\t\n\t$$\\forall f \\text{ Lipschiz,}\\quad \\forall y\\in\\mathbb S^2,  \\quad\\quad \\frac{1}{n}\\sum_i e^{-\\frac{||x_i-y||^2}{4t}}\\rightarrow \\int e^{-\\frac{||x-y||^2}{4t}}d\\mu(x)$$\n\t$$\\forall f \\text{ Lipschiz,}\\quad \\forall y\\in\\mathbb S^2,  \\quad\\quad \\frac{1}{n}\\sum_i e^{-\\frac{||x_i-y||^2}{4t}}f(x_i)\\rightarrow \\int e^{-\\frac{||x-y||^2}{4t}}f(x)d\\mu(x)$$\n\t\n\tDefinitions \\ref{def:Heat Kernel Graph Laplacian operator} and \\ref{def:Functional approximation to the Laplace-Beltrami operator} end the proof.\n\\end{proof}\n\\vspace{0.5cm}\n\nNow, we just proved that \\textit{keeping t fixed} $L_n^tf(x)\\rightarrow L^tf(x)$. Now our goal is to prove that:\n\n\\vspace{0.5cm}\n\\begin{prop}\\label{prop:2}\n\tGiven a sampling regular enough i.e., for which we assume $A_i=A_j \\ \\forall i,j\\text{ and }d^{(n)}\\leq \\frac{C}{\\sqrt{n}}$, for a fixed $t>0$, a fixed Lipschitz function $f$ and a fixed point $y\\in\\mathbb S^2$ there exists a sequence $t_n = n^\\beta, \\beta<0$ such that \n$$\n\\forall f \\text{ Lipschitz, } \\forall x\\in\\mathbb S^2 \\quad \\left|\\frac{1}{4\\pi t_n^2}\\left(L_n^{t_n}f(x) - L^{t_n}f(x)\\right)\\right|\\xrightarrow{n\\to \\infty}0.\n$$\n\\end{prop}\n\\vspace{0.5cm}\n\nThe main result of this section, theorem  \\ref{theo:pointwise convergence in the healpix case}, is then an immediate consequence of Proposition \\ref{prop:2} and Proposition \\ref{prop:3}.\n\n\n\\begin{proof}[Proof of Proposition \\ref{prop:2}]\n\t\n\tWe define for simplicity of notation\n\t\\begin{align*}\n\t\t\\phi^t(x;y) &:= e^{-\\frac{||x-y||^2}{4t}}\\left(f(y)-f(x)\\right)\\\\\n\t\tK^t(x,y) &:=  e^{-\\frac{||x-y||^2}{4t}}\n\t\\end{align*}\n\tWe start by writing the following chain of inequalities\n\t\\begin{align*}\n\t\t||L_n^tf-L^tf||_\\infty &= \\max _{y\\in \\mathbb S^2} \\left|L_n^tf(y)-L^tf(y)\\right|\\\\\n\t\t&= \\max _{y\\in \\mathbb S^2} \\left| \\frac{1}{n} \\sum_{i=1}^n \\phi^t(x_i; y)- \\int_{\\mathbb S^2} \\phi^t(x;y)d\\mu(x) \\right|\\\\\n\t\t&\\leq \\max _{y\\in \\mathbb S^2}  \\sum_{i=1}^n   \\left| \\frac{1}{n}  \\phi^t(x_i; y)- \\int_{\\sigma_i} \\phi^t(x;y)d\\mu(x) \\right|\\\\\n\t\t&\\leq  \\max _{y\\in \\mathbb S^2} \\left[\\mathcal L_{\\phi^t_y}d^{(n)} \\right]\\\\\n\t\\end{align*}\n\twhere $\\mathcal L_{\\phi^t_y}$ is the Lipschitz constant of $x \\rightarrow \\phi^t(x, y)$ and where we used for the last inequality Proposition \\ref{prop:1}. If we assume $d^{(n)}\\leq \\frac{C}{\\sqrt{n}}$ we have that\n\t\n\t$$||L_n^tf-L^tf||_\\infty  \\leq  \\max _{y\\in \\mathbb S^2} \\left[ \\mathcal L_{\\phi^t_y} \\frac{C}{\\sqrt{n}} \\right]$$\n\t\n\tLet's now find the explicit dependence $t\\rightarrow \\mathcal L_{\\phi^t_y}$\n\t\\begin{align*}\n\t\t\\mathcal L_{\\phi^t_y} &= ||\\partial_x\\phi^t(\\cdot;y)||_\\infty\\\\&\n\t\t= ||\\partial_x\\left(K^t(\\cdot;y)f\\right)||_\\infty\\\\&\n\t\t= ||\\partial_x K^t(\\cdot;y)f + K^t(\\cdot;y)\\partial_x f||_\\infty\\\\&\n\t\t\\leq ||\\partial_x K^t(\\cdot;y)f||_\\infty + ||K^t(\\cdot;y)\\partial_x f||_\\infty\\\\&\n\t\t\\leq  ||\\partial_x K^t(\\cdot;y)||_\\infty||f||_\\infty + ||K^t(\\cdot;y)||_\\infty||\\partial_x f||_\\infty\\\\&\n\t\t= ||\\partial_x K^t(\\cdot;y)||_\\infty||f||_\\infty + ||\\partial_x f||_\\infty\\\\&\n\t\t= \\mathcal L_{K^t_y} ||f||_\\infty + ||\\partial_xf||_\\infty\\\\&\n\t\t= \\mathcal L_{K^t_y} ||f||_\\infty + \\mathcal L_f\n\t\\end{align*}\n\twhere $\\mathcal L_{K^t_y}$ is the Lipschitz constant of $x\\rightarrow K^t(x;y)$. We can observe that such constant does not depend on $y$:\n\t\n\t$\\mathcal L_{K^t_y} = \\norm{\\partial_x e^{-\\frac{x^2}{4t}}}_\\infty = \\norm{\\frac{x}{2t}e^{-\\frac{x^2}{4t}}}_\\infty = \\left. \\frac{x}{2t}e^{-\\frac{x^2}{4t}}\\right|_{x=\\sqrt{2t}}=(2et)^{-\\frac{1}{2}}\\propto t ^ {-\\frac{1}{2}}$\n\t\n\tSo we can continue\n\t\\begin{align*}\n\t\t\\max _{y\\in \\mathbb S^2} \\left[  \\mathcal L_{\\phi^t_y} \\frac{C}{\\sqrt{n}} \\right]\n\t\t&\\leq  \\frac{C}{\\sqrt{n}} \\left( (2et)^{-\\frac{1}{2}} \\norm{f}_\\infty + \\mathcal L_f \\right)\\\\\n\t\t&\\leq \\frac{C\\norm{f}_\\infty}{\\sqrt{n}(2et)^\\frac{1}{2}} +   \\frac{C}{\\sqrt{n}}\\mathcal L_f\\\\\n\t\\end{align*}\n\tSo we have that, rescaling by a factor $\\frac{1}{4\\pi t^2}$\n\t\\begin{align*}\n\t\t\\norm{\\frac{1}{4\\pi t^2}\\left(L_n^tf-L^tf\\right)}_\\infty&\\leq \\frac{1}{4\\pi t^2}\\norm{\\left(L_n^tf-L^tf\\right)}_\\infty \\\\\n\t\t&\\leq \\frac{C}{4\\pi}\\left[\\frac{\\norm{f}_\\infty}{\\sqrt{2e}}\\frac{1}{\\sqrt{n}t^\\frac{5}{2}} + \\frac{\\mathcal L_f}{\\sqrt{n}t^2}\\right]\n\t\\end{align*}\n\n\t\n\twe want $\\begin{cases}\n\tt \\rightarrow 0\\\\\n\tn \\rightarrow \\infty\\\\\n\t\\sqrt{n}t^\\frac{5}{2} \\rightarrow \\infty\\\\\n\t\\sqrt{n}t^2 \\rightarrow \\infty\n\t\\end{cases}$ in order for $ \\frac{C}{4\\pi}\\left[\\frac{\\norm{f}_\\infty}{\\sqrt{2e}}\\frac{1}{\\sqrt{n}t^\\frac{5}{2}} + \\frac{\\mathcal L_f}{\\sqrt{n}t^2}\\right] \\xrightarrow[t\\to 0 ]{n\\to\\infty}0$\n\t\n\tThis is true if $\\begin{cases}\n\tt(n) = n^\\beta, &\\beta\\in(-\\frac{1}{5}, 0) \\\\\n\tt(n) = n^\\beta, &\\beta\\in(-\\frac{1}{4}, 0)\n\t\\end{cases} \\implies t(n) = n^\\beta, \\quad \\beta\\in(-\\frac{1}{5}, 0)$\n\t\n\tIndeed \n\t\n\t$\\sqrt{n}t^\\frac{5}{2}=n^{5/2\\beta+1/2}\\xrightarrow{n \\to \\infty} \\infty$ since $\\frac{5}{2}\\beta+1/2>0 \\iff \\beta>-\\frac{1}{5}$\n\t\n\t$\\sqrt{n}t^2=n^{2\\beta+1/2}\\xrightarrow {N \\to \\infty} \\infty$ since $2\\beta+1/2>0 \\iff \\beta>-\\frac{1}{4}$\n\t\n\tSo, for $t=n^\\beta$ with $\\beta\\in(-\\frac{1}{5}, 0)$ we have that \n\t\n\t$$\\begin{cases}\n\t(t_n)\\xrightarrow{n\\to\\infty}0\\\\\n\t\\norm{\\frac{1}{4\\pi t_n^2}L_n^{t_n}f-\\frac{1}{4\\pi t_n^2}L^{t_n}f}_\\infty  \\xrightarrow{n\\to\\infty}0\n\t\\end{cases}$$\n\t\n\\end{proof}\n\nThe proof of theorem \\ref{theo:pointwise convergence in the healpix case} is now trivial:\n\\begin{proof}[Proof of Theorem \\ref{theo:pointwise convergence in the healpix case}]\n\tThanks to Proposition \\ref{prop:2} and Proposition \\ref{prop:3}\twe conclude that $\\forall y\\in\\mathbb S^2 $\n\t$$\\lim_{n\\to\\infty}\\frac{1}{4\\pi t_n^2} L_n^{t_n}f(y) =  \\lim_{n\\to\\infty}\\frac{1}{4\\pi t_n^2} L^{t_n}f(y) = \\frac{1}{|\\mathbb S^2|}\\triangle_{\\mathbb S^2}f(y) $$\n\\end{proof}\n\nThe proof of this result is instructive since it shows that we need to impose some regularity conditions on the sampling. If the sampling is equal area as HEALPix, meaning that all the patches $\\sigma_i$ have the same area (i.e., HEALPix, see figure \\ref{fig:HEALPix equal areas patches}), then we need to impose that $ d^{(n)}\\leq \\frac{1}{\\sqrt{n}}$. If the sampling is not equal area, meaning that in general $A_i\\neq A_j$, it can be shown that we need a slightly more complex condition: $\\max_{i=0,...,n-1}d_iA_i\\leq Cn^{-\\frac{3}{2}}$.\\\\\nIn the work of Belkin et al. \\cite{Belkin:2005:TTF:2138147.2138189} the sampling is drawn form a uniform random distribution on the sphere, and their proof heavily relies on the uniformity properties of the distribution from which the sampling is drawn. In our case the sampling is deterministic, and the fact that for a sphere there doesn't exist a regular sampling with more than 12 points (the vertices of a icosahedron) is indeed a problem that we need to overcome by imposing the regularity conditions above. \n\n\nTo conclude, we can see that the result obtained has the same form than the result obtained in \\cite{Belkin:2005:TTF:2138147.2138189}. Given the kernel density $t(n)=n^\\beta$, if Belkin et al. proved convergence in the random case for $\\beta \\in (-\\frac{1}{4}, 0)$, we proved convergence in the HEALPix case for $\\beta \\in (-\\frac{1}{5}, 0)$. This kind of result can be interpreted in the following way. In order to have this pointwise convergence, we need to reduce the kernel width but \\textit{not so fast} compared to the resolution of the graph. In other words, the kernel width has to be reduced but is somewhat limited by the resolution of the graph. In the next section we'll see how to set in practice a good kernel width $t$ given a graph resolution $n$.\n\\begin{remark}\n\tPointwise convergence is just a necessary condition for spectral convergence.  Theorem \\ref{theo:pointwise convergence in the healpix case} does not imply convergence of eigenvalues and eigenvectors.\n\\end{remark}\n\n\\subsection{How to build a good graph to approximate spherical convolutions}\n\\label{sec:Chapter2:How to build a good graph}\nThe current state of the art of rotation equivariant Graph CNN is DeepSphere \\cite{DeepSphere}. However, if we measure the alignment of the eigenspaces spanned by the eigenvectors of its graph Laplacian and the ones spanned by the spherical harmonics we see that it does not get better as $N_{side}$ increases (figure \\ref{fig:deepsphere results}). We'll see that the main cause of this bad behavior of the eigenspaces is the fixed number of neighbors used for the construction of the graph. In this subsection we'll see that \\textit{to obtain the desired spectral convergence it is necessary to increase the number of neighbors as we decrease the kernel width} $t$. We'll follow in practice what we did in proving theorem \\ref{theo:pointwise convergence in the healpix case}: first we'll build a full graph, and let the number of pixels $n$ increase while keeping the kernel width $t$ fixed. After having discussed the results, we'll try to find a sequence $(t_{N_{side}})$ to obtain the expected spectral convergence. Only in the end we'll find a way to make the graph sparse to limit the computational costs of graph convolutions but keeping the eigen decomposition of the graph Laplacian as close to the spherical harmonics as possible.\n\n\\subsubsection{Full graph, $n\\to\\infty$}\\label{sec:Chapter1: n to infty}\nHere we analyze what happens to the power density spectrum of the \\textit{full} Heat Kernel Graph Laplacian as we make $n$ go to infinity while keeping $t$ fixed. Since in the previous section we proved that (Proposition \\ref{prop:3}) for a sampling regular enough and a fixed $t$, a fixed function $f$, a fixed point $y$\n$$L_n^tf(y)\\xrightarrow{n\\to\\infty}L^tf(y)$$\nSince HEALPix is a very regular sampling of the sphere, we expect to observe (even if we didn't prove it) the corresponding spectral convergence proved in theorem \\ref{theo:spectral convergence}. The results obtained are in figure \\ref{fig:n to infinity1}, \\ref{fig:n to infinity3}.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/n.png}\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/n_diagonal.png}\t\n\t\\caption{\\label{fig:n to infinity1}Alignment of the eigenvectors of the HKGL with a fixed kernel width $t$}\n\t\n\\end{figure}\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=0.49\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/n_eigenvalues.png}\n\t\t\\includegraphics[width=0.49\\textwidth]{figs/chapter1/trueeigenvalues.png}\t\n\t\\caption{\\label{fig:n to infinity3}Left: spectrum of the HKGL with a fixed kernel width $t$. Right: true spectrum of $\\Delta_{\\mathbb S^2}$}\n\\end{figure}\n\nIn figure \\ref{fig:n to infinity1} we see two things: first that there's a frequency threshold beyond which the Graph Laplacian is completely blind, approximately located at the 15th degree, and second that before this frequency threshold, we actually see the convergence expected: the alignment gets better as $n$ gets bigger.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=0.45\\textwidth]{figs/chapter1/frequency_threshold1.png}\t\\hfill\n\t\\includegraphics[width=0.45\\textwidth]{figs/chapter1/frequency_threshold2.png}\t\n\t\\caption{\\label{fig:n to infinity4}Frequency threshold explained.}\n\\end{figure}\n\n\n To explain this we refer to figure \\ref{fig:n to infinity4} where we show a simplified situation where we are sampling the interval $[0, 2]$ and we plot the Gaussian kernel centered around the first pixel of the sampling corresponding to the origin. On the leftmost image the pixels are correctly spaced with respect to the kernel width, in the sense that the values of the kernel evaluated on the pixels are well far apart from each other. This makes the graph able to \"see\" all the pixels differently, and thus all the frequencies with wavelength around the order of magnitude of the average pixel distance will be captured by the graph. On the rightmost image in figure \\ref{fig:n to infinity4} there are too many pixels with respect to the kernel width: the values of the kernel evaluated on the pixels close to the origin, because of the slope of the kernel being almost zero are too close to each other (in red); because of this any variation of a signal on the red pixels would be almost invisible to the graph Laplacian. With this fixed kernel width $t$, no matter how much we sample the interval $[0,2]$, any frequency with wavelength shorter than the radius $r\\approx0.25$ becomes invisible to the graph Laplacian.\\\\\n This phenomenon can be seen also in the spectrum represented in figure \\ref{fig:n to infinity3} where we plot the eigenvalues of the matrix $\\mathbf L_n^t$: as $N_{side}$ gets bigger the eigenvalues get more and more grouped in the usual groups of the same multiplicity of the corresponding spherical harmonics; however, there's a frequency (corresponding approximately to the degree $\\ell=15$) from which all the eigenspaces tend to merge into one, corresponding to the eigenvalue $1$.\n \n\\subsubsection{Full graph, $t\\to 0$}\nIn this section we fix the parameter $N_{side}$ and and we make the kernel width $t$ go to $0$. \n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/t_sensitivity}\n\t\\caption{\\label{fig:t_sensitivity_eigenspaces}Alignment of the eigenspaces of the HKGL with a fixed number of points $n$ corresponding to $N_{side}=8$}\n\\end{figure}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/t_sensitivity_diagonal.png}\n\t\\caption{\\label{fig:t_sensitivity_diagonal}Whole trend}\n\\end{figure}%\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/t_sensitivity_diagonal_2.png}\n\t\\caption{\\label{fig:t_sensitivity_diagonal_2}First trend: error stays low for low frequencies, and gets lower for high frequencies}\n\t\\vspace{0.5cm}\n\\end{figure}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/t_sensitivity_diagonal_1.png}\n\t\\caption{\\label{fig:t_sensitivity_diagonal_1}Second trend: error gets higher for both high and low frequencies}\n\\end{figure}%\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figs/chapter1/t.png}\t\n\t\\caption{\\label{fig:weights}One row of the weight matrix for different values of the kernel width $t$ plotted on the HEALPix sampling with $N_{side}=8$. On the left, for a too large $t$, the HKGL can not capture high frequencies. On the right, for a too small $t$, the graph becomes almost completely disconnected. In the center a good value for $t$ makes the HKGL able to see the most frequencies.}\n\\end{figure}\n\nResults are in figure \\ref{fig:t_sensitivity_eigenspaces}, \\ref{fig:t_sensitivity_diagonal}: Starting from $t=0.32$, the error in the high frequencies starts to get smaller, while the error in the low frequencies keeps staying low (Figure \\ref{fig:t_sensitivity_diagonal_2}) up to $t=0.05$. For $t$ that gets smaller and smaller up to $t=0.01$, we get worse alignment both in high and low frequencies (Figure \\ref{fig:t_sensitivity_diagonal_1}). This behavior can be explained with the same arguments used in the previous section: high values of the kernel width correspond to a very flat kernel (figure \\ref{fig:weights}, left), and thus the graph loses the capacity of individuating high frequencies as discussed before. On the opposite side, low values of the kernel width correspond to a very peaked kernel, that causes all the weights to be close to zero and thus the graph becomes less and less connected loosing every capability of identifying different frequencies  (figure \\ref{fig:weights}, right). \n\n\\subsubsection{Putting it together: full graph, $n\\to\\infty$ and $t\\to 0$}\nA grid search has been used to find the following optimal kernel width for different values of $N_{side}$, always in the case of a full graph, where we maximized the number of graph eigenspaces with the alignment value in figure \\ref{fig:optimal graph} bigger than $80\\%$. The optimal values of the kernel width $t$ are shown in figure \\ref{fig:t}. In DeepSphere $t$ is set to the average of the non zeros weight matrix entries, where the number of neighbors of each vertex is fixed between 7 and 8. We can see that the heuristic way of DeepSphere of setting the standard deviation $t$ produces results of the same order of magnitude of the optimal value. It can be seen that the optimal values of $t$ are very close to a linear trend in the log-log plot, showing an approximately polynomial relationship with the parameter $N_{side}$ that could be used to extrapolate possible values of $t$ for higher $N_{side}$.\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.7\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/kernelwidth.png}\n\\caption{\\label{fig:t}Standard deviation of the Gaussian kernel  in a log-log plot. A straight line indicates a polynomial relation.}\n\\end{figure}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_full.png}\t\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_full_diagonal.png}\n\\caption{\\label{fig:optimal graph}Alignment of eigenspaces of the optimal full graph.}\n\\end{figure}\nIn figure \\ref{fig:optimal graph} we can appreciate that for a full graph, each time we double the parameter $N_{side}$, we approximately double the degree $\\ell$ at which the graph eigenvectors are correctly aligned with the spherical harmonics.\n\\subsubsection{Reducing the number of neighbors}\nFor what it concerns how to make the graph sparse, the intuition is the following: remember that we want our graph Laplacian to approximate the operator $L^t$, that for sufficiently small $t$ approximates $\\Delta$\n$$\\frac{1}{n}\\left(\\sum_i e^{-\\frac{||x_i-y||^2}{4t}}(f(y)-f(x_i)) \\right)  \\approxeq  \\int_{\\mathbb S^2} e^{-\\frac{||x-y||^2}{4t}}\\left(f(y)-f(x)\\right)d\\mu(x) \\approxeq \\Delta_{\\mathbb S^2} f(y)$$\n\nSo far we showed how to do so optimally with a full graph; however, a full graph comes at the cost of leading to a matrix $\\mathbf L_n^t$ that is full, and thus to a graph filtering cost of $\\mathcal O(n^2)$, worse than the common SHT cost of $\\mathcal O(n^{3/2})$. Perraudin et al. \\cite{DeepSphere} constructed a nearest neighbor graph constraining the number of neighbors for each vertex to be fixed, making the graph filtering cost linear in the number of pixels. However, as we saw at the beginning of this section this leads to a poor alignment of the graph eigenvectors with the spherical harmonics and thus to a not so optimal rotation equivariance. Here we propose a different approach, based on the following intuition: making the graph sparse means deciding which weights $w_{ij}=\\exp{-\\frac{||x_i-x_j||^2}{4t}}$ to set to zero. For this approximation to be accurate we want to set to zero only those weights that are small enough: let's define a new \\textit{epsilon graph} $G'$ by fixing a threshold $\\epsilon$ on $w_{ij}=e^{-\\frac{||x_i-x_j||^2}{4t}}$ such that\n\n$$w'_{ij} = \\begin{cases}\ne^{-\\frac{||x_i-x_j||^2}{4t}}\\quad& \\text{if } e^{-\\frac{||x_i-x_j||^2}{4t}} \\geq \\epsilon\\\\\n0 \\quad & \\text{if } e^{-\\frac{||x_i-x_j||^2}{4t}} < \\epsilon\n\\end{cases}$$\n\nBy setting $\\epsilon = 0.01$ - or equivalently, thresholding the weights at \\\\$\\norm{x_i-x_j}\\approx 3\\sigma$ where $\\sigma=\\sqrt{2t}$ is the standard deviation of the kernel - in figure \\ref{fig:optimal_thresholded} we can see the usual alignment plots of the graph $G'$:\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{ c|c} \n\t\t$N_{side}$ & Number of neighbors \\\\ \n\t\t1 & 11 \\\\ \n\t\t2 & 16 \\\\ \n\t\t4 & 37 \\\\ \n\t\t8 & 43 \\\\ \n\t\t16 & 52 \\\\ \n\t\\end{tabular}\n\\caption{\\label{table:NN}}\n\\end{table}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_thresholded.png}\t\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_thresholded_diagonal.png}\n\t\\caption{\\label{fig:optimal_thresholded}Optimal construction \\textbf{thresholded at $k=0.01$}}\n\\end{figure}\n\nWe see that we need to increase the number of neighbors as $N_{side}$ gets bigger. Again, the intuition is the following: to have spectral convergence (a strong type of convergence) we need more and more global information and more precise. By fitting the relationship\n$$\n\\text{Number of neighbors} = (N_{side})^\\alpha\n$$\nto the data in table \\ref{table:NN} we obtain that $\\alpha$ should be close to $1/2$, meaning that the complexity graph filtering with $G'$ could be approximated by\n$$\n\\mathcal O(|E|) = \\mathcal O(n\\sqrt{N_{side}})  = \\mathcal{O}(n^{5/4}).\n$$\nwhere $n$ is the number of vertices of the graph. This complexity is exactly in the middle between the linear complexity of DeepSphere and the complexity $\\mathcal O(n^{3/2})$ of the SCNNs of Cohen and Esteves \\cite{SCNN} \\cite{Esteves}. In practice the number of neighbors grows very slowly with the number of pixels, making graph convolutions with $G'$ still very efficient and fast (see section \\ref{sec:Chapter5:Experimental validation}, table \\ref{table:results}). \n\nTo conclude, we show in figure \\ref{fig:Old spectrum}, \\ref{fig:New spectrum} a confront between the alignment of the graph Laplacian eigenvectors of the DeepSphere graph $G$, the starting point of this work, and  of the graph $G'$. It can appreciated how the alignment plots show a much better behavior of the graph Laplacian eigenvectors of $G'$, and how the spectrum of $G'$ resembles more accurately the spectrum of $\\Delta_{\\mathbb S^2}$.\\\\\n\\begin{minipage}{.5\\textwidth}\n\t\\centering\n\t\\vspace{0.4cm}\n\t\\includegraphics[width=0.95\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/deepsphere_original.png}\n\t\\includegraphics[width=0.95\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/deepsphere_original_diagonal.png}\n\t\\includegraphics[width=0.95\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/05_figs/old_results3.png}\n\t\\captionof{figure}{\\label{fig:Old spectrum}Alignment of the graph Laplacian eigenvectors of the DeepSphere graph $G$, the starting point of this work, and its spectrum.}\n\\end{minipage}%\n\\begin{minipage}{.5\\textwidth}\n\t\\centering\n\t\\includegraphics[width=0.95\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_thresholded.png}\n\t\\includegraphics[width=0.95\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_thresholded_diagonal.png}\n\t\\includegraphics[width=0.95\\linewidth]{../codes/02.HeatKernelGraphLaplacian/HEALPix/06_figures/optimal_thresholded_eigenvalues.png}\n\t\\captionof{figure}{\\label{fig:New spectrum}Alignment of the graph Laplacian eigenvectors of the proposed graph $G'$, and its spectrum.}\n\\end{minipage}\n\\subsubsection{Equivariance error}\nSo far we used the plots of the alignment of the eigenvectors with the spherical harmonics as a proxy of the quantity we are really interested in, the mean equivariance error $\\overline E_G$, because they gave us more valuable interpretations about what was happening. Now we want to have the confirmation that the proposed graph $G'$ led to a smaller mean equivariance error than the one of the original graph $G$ of DeepSphere.\nIn figure \\ref{fig:DeepSphere equivariance error} we plot the mean equivariance error \n$$\\overline E = \\mathbb E_{f, g}\\ E(f, g)\n$$ of the diffusion filter $k(\\lambda_i) = \\exp(-\\lambda_i)$ for both graphs $G, G'$ by spherical harmonic degree $\\ell$ at different resolutions. This was obtained as the empirical average over a uniform sample of rotations $g\\in SO(3)$ and a uniform sample of functions $f\\in V_\\ell = \\text{span}\\{Y_\\ell^m, |m|\\leq \\ell\\}$. We recall that for HEALPix there's no sampling theorem that guarantees the existence of an exact reconstruction operator $T^{-1}$, so to calculate this quantity we had to rotate the sampled signal in the discrete domain, introducing important interpolation errors. We can see that DeepSphere has a mean equivariance error that is almost 30\\% in the low frequencies, and decreases slowly for higher ones. The graph $G'$ has a much better behavior: the error stays low for the small frequencies, rising up for the higher ones and always remaining confined under 5\\%. To compare it we reported also the results for the full HKGL, where we can appreciate a behavior similar to $G'$ but with an error always smaller than 2\\%.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/DeepSphereonHEALPix.png}\t\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/OptimalHKGLonHEALPix.png}\t\n\t\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/FullHKGLonHEALPix.png}\t\n\t\\caption{\\label{fig:DeepSphere equivariance error}Mean equivariance error of the diffusion filter $\\exp(-\\Lambda)$ for $G$, $G'$ and the full HKGL, by spherical harmonic degree. Notice the difference in the scale of the y axis for DeepSphere, that reaches errors up to 30\\%.}\n\\end{figure}\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/img_example_DeepSphere/DS.png}\t\n\t\\caption{\\label{fig:DeepSphere equivariance error in practice}DeepSphere V1 equivariance error. On the left, a signal $f$. Top right, $f$ was first rotated and then filtered through a diffusion filter $k(\\lambda) = \\exp (-\\lambda)$. Bottom right, $f$ was first filtered and then rotated. The difference in the two outcomes is evident.}\n\\end{figure}\n\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/img_example_thresholdedHKGL/thresholdedHKGL.png}\t\n\t\\caption{\\label{fig:Optimal equivariance error in practice}DeepSphere V2 equivariance error. On the left, a signal $f$. Top right, $f$ was first rotated and then filtered through a diffusion filter $k(\\lambda) = \\exp (-\\lambda)$. Bottom right, $f$ was first filtered and then rotated. No difference in the two outcomes is visible to the human eye.}\n\\end{figure}\n\nIn figure \\ref{fig:DeepSphere equivariance error in practice} we see the visualization of the equivariance error of DeepSphere: on the left, the original sampled signal $Tf$. Top right, the rotated and filtered signal $\\Omega_k T \\Lambda(g) f$. Bottom right, the filtered and rotated signal $T \\Lambda(g) T^{-1} \\Omega_k T f $. In figure \\ref{fig:Optimal equivariance error in practice} we see the visualization of the equivariance error of the graph $G'$: on the left, the same, original sampled signal $Tf$. Top right, the rotated and filtered signal $\\Omega_k T \\Lambda(g) f$. Bottom right, the filtered and rotated signal $T \\Lambda(g) T^{-1} \\Omega_k T f $. No difference can be appreciated at a visual analysis for the graph $G'$, while for DeepSphere the difference is clearly visible.\n\\clearpage\nTo conclude, we report in table \\ref{tab:final results}, as final metric for the evaluation of rotation equivariance of the two graphs $G$, $G'$, the mean equivariance error for a different values of $N_{side}$ that we computed by sampling random coefficients $\\theta_\\ell^m \\in(0,1)$ of linear combinations of all the spherical harmonics up to degree $\\ell=16$\n$$f(x) = \\sum_{\\ell\\leq 16,\\ |m|\\leq\\ell}\\theta_\\ell^m Y_\\ell^m(x)\n$$\nand by averaging on random rotations $g\\in SO(3)$. Our graph shows lower errors as $N_{side}$ grows, and a much lower error than DeepSphere.\n\n\\begin{table}\n\t\t\\centering\n\\begin{tabular}{c|ccc}\n\tMean equivariance error $\\overline{E}$& $N_{side}=4$& $N_{side}=8$&$N_{side}=16$ \\\\\\hline\n\tDeepSphere graph $G$ & 12.37\\% & 12.03\\% & 12.23\\% \\\\\n\tOptimal graph $G'$ & 4.57\\% & 3.98 \\% & 1.54\\%\n\\end{tabular}\n\\caption{\\label{tab:final results}}\n\\end{table}\n\n", "meta": {"hexsha": "b9dd3548cb649c05fc5e1f8cc9352c15a4e19628", "size": 45322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDF/2.Chapter1.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/2.Chapter1.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/2.Chapter1.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": 97.6767241379, "max_line_length": 1274, "alphanum_fraction": 0.7356692114, "num_tokens": 13864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504226, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6800174496536983}}
{"text": "\\section{Enhanced techniques}\\label{sec:enhanced}\r\n\\subsection{Combining different data types - MT 1d inversion}\\label{sec:mt1d}\r\nFile \\file{doc/tutorial/code/enhanced/mt1dinv0.cpp}\\\\\r\nIn magnetotelluric (MT) inversion for every period an amplitude $\\rho^a$ and a phase $\\phi$ is computed from the electric and magnetic registrations. The file \\file{1000\\_100\\_1000\\_n5\\_1.dat} contains a synthetic three layer case of 1000$\\Omega$m-100$\\Omega$m-1000$\\Omega$m with 5\\,\\% Gaussian noise on the $\\rho^a$ and 1 degree on the phases.\r\nThe three columns $T$, $\\rho^a$ and $\\phi$ are read extracted as vectors by\r\n\\begin{lstlisting}\r\n    RMatrix TRP; //! real matrix with period(T), resistivity(R) & phase(P)\r\n    loadMatrixCol( TRP, dataFileName ); //! read column-based file\r\n    size_t nP = TRP.rows(); //! number of data\r\n    RVector T( TRP[0] ), rhoa( TRP[1] ), phi( TRP[2] ); //! columns\r\n\\end{lstlisting}\r\nIt is based on the forward operator \\lstinline|MT1dModelling| in \\file{src/em1dmodelling.h/cpp}, giving back a vector that consists of the amplitudes and phases for each period. \r\nOf course both have completely different valid ranges. \r\nThe phases a linearly related between 0 and $\\pi/2$, whereas the amplitudes are usually treated logarithmically.\r\nOn the (1d block) model side, thickness and apparent resistivity use log or logLU transforms as done for DC resistivity.\r\n\\begin{lstlisting}\r\n    /*! Model transformations: log for resistivity and thickness */\r\n    RTransLog transThk;\r\n    RTransLogLU transRho( lbound, ubound );\r\n    /*! Data transformations: log apparent resistivity, linear phases */\r\n    RTransLog transRhoa;\r\n    RTrans transPhi;\r\n\\end{lstlisting}\r\nSince amplitudes and phases are combined in one vector, we create a cumulative transformation of the two by specifying their lengths. \r\nSimilarly, the assumed relative error of the $\\rho^a$ and $\\phi$ are combined using a cat command.\r\n\\begin{lstlisting}\r\n    CumulativeTrans< RVector > transData; //! combination of two trans\r\n    transData.push_back( transRhoa, nP ); //! append rhoa trans (length nP)\r\n    transData.push_back( transPhi, nP );  //! append phi trans\r\n    RVector error( cat( RVector(nP,errRhoa/100), RVector(errPhase/phi) ) );\r\n\\end{lstlisting}\r\n\r\nSimilar to DC resistivity inversion, we create a 1d block mesh, initialise the forward operator and set up options for the two regions (0-thicknesses,1-resistivities).\r\nStarting values for the $\\rho_i$ and $d_i$ are computed by the mean apparent resistivity and an associated skin depth.\r\n\\begin{lstlisting}\r\n    MT1dModelling f( T, nlay, false );\r\n    double medrhoa = median( rhoa ); //! median apparent resistivity\r\n    double medskindepth = sqrt( median( T ) * medrhoa ) * 503.0; //!skin d.\r\n    f.region( 0 )->setTransModel( transThk ); //! transform\r\n    f.region( 1 )->setTransModel( transRho );\r\n    f.region( 0 )->setConstraintType( 0 ); //! min. length\r\n    f.region( 1 )->setConstraintType( 0 );\r\n    f.region( 0 )->setStartValue( medskindepth / nlay );\r\n    f.region( 1 )->setStartValue( medrhoa );\r\n    /*! Real valued inversion with combined rhoa/phi and forward op. */\r\n    RInversion inv( cat( rhoa, phi ), f, verbose, dosave );\r\n\\end{lstlisting}\r\n\r\nThe rest is done as for DC resistivity block inversion.\r\nIn Figure~\\ref{fig:mt1dblock-resres} the inversion result and its resolution matrix is shown.\r\nThe model is very close to the synthetic one and represents an equivalent solution.\r\nThis is also represented by the resolution matrix, where $\\rho_1$, $\\rho_3$ and $d_1$ are resolved almost perfectly, whereas $\\rho_2$ and $d_2$ show slight deviations.\r\n\\begin{figure}[htbp]\r\n\\centering\\includegraphics[width=0.7\\textwidth]{mt1dblock-resres}\\\\[-3ex]\r\n~\\hfill a\\hfill ~ \\hfill ~~~~~b \\hfill ~ \\hfill ~ \\hfill ~\r\n\\caption{a) Block 1d resistivity inversion result (red-synthetic model, blue-estimated model)) and b) resolution matrix}\\label{fig:mt1dblock-resres}\r\n\\end{figure}\r\n\r\nOne can easily test the inversion only based on $\\rho^a$ or $\\phi$ by increasing the errors of the others by a large factor.\r\nAccording to (\\ref{eq:phid}) the corresponding weight goes to zero.\r\nBy skipping $\\phi$ the model deviates slightly and the cell resolutions for $\\rho_2$ and $d_2$ decrease to 0.9 and 0.86, respectively. If the $\\rho^a$ are neglected the solution becomes obviously non-unique. Only $d_1$ is determined pretty well, the other parameters obtain cell resolutions of 0.6-0.8. Note also that for local regularisation the resolution does not contain the resolution of the preceding models \\citep{friedel03}.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Combining different parameter types - offsets in travel time}\\label{sec:ttoffset}\r\nNext, we consider a 2d travel-time tomographic problem.\r\nIn the library there is a forward operator called \\cw{TTDijkstraModelling}, which is using a Dijkstra \\citep{dijkstra} algorithm that restricts the ray paths to mesh edges. Although this is only an approximation, it is sufficiently accurate for high-quality meshes.\r\nAssume the zero point (shot) of the traces is not exactly known. This might be due to long trigger cables, problems in the device or placing besides the profile.\r\nAim is to include an unknown delay for each shot position into the inversion\\footnote{A similar problem is the issue of static shift in MT inversion caused by local conductivity inhomogeneity, which shifts the apparent resistivity curves.}.\r\n\r\nFirst, we derive a new forward modelling class \\cw{TTOffsetModelling}  from the existing \\cw{TTDijkstraModelling} (abbreviated by \\cw{TTMod}) since we want to use their functionality.\r\nAdditionally to the existing class we need the number of shot positions and a simple 0d/1d mesh holding the offset values for them added to the original mesh.\r\n\\begin{lstlisting}\r\nclass TTOffsetModelling : public TTMod {\r\npublic:\r\n    TTOffsetModelling( Mesh & mesh, DataContainer & data )\r\n      : TTMod( mesh, data ) {\r\n        //! find occuring shots, and map them to indices starting from zero\r\n        shots_ = unique( sort( dataContainer.get(\"s\") ) );\r\n        std::cout << \"found \" << shots_.size() << \" shots.\" << std::endl;\r\n        for ( size_t i = 0 ; i < shots_.size() ; i++ )\r\n            shotMap_.insert( std::pair< int, int >( shots_[ i ], i ) );\r\n        //! create new region containing offsets with special marker\r\n        offsetMesh_ = createMesh1D( shots_.size() );\r\n        for ( size_t i = 0 ; i < offsetMesh_.cellCount() ; i++ )\r\n            offsetMesh_.cell( i ).setMarker( NEWREGION );\r\n        regionManager().createRegion( NEWREGION, offsetMesh_ );\r\n    }\r\n...\r\n\\end{lstlisting}\r\n\r\nThe two functions \\lstinline|response| and \\lstinline|createJacobian| need to be overwritten.\r\nHowever we want to expand the original functions by the changes needed.\r\nThis is straight forward for the response vector.\r\nFirst part of the model is the slowness vector whose response is calculated calling the original function.\r\n\r\n\\begin{lstlisting}\r\n    RVector TTOffsetModelling::response( const RVector & model ){\r\n        //! extract slowness from model and call old function\r\n        RVector slowness( model, 0, model.size() - shots_.size() );\r\n        RVector offsets( model, model.size() - shots_.size(), model.size()); \r\n        RVector resp = TTMod::response( slowness ); //! normal response\r\n        RVector shotpos = dataContainer_->get( \"s\" );\r\n        for ( size_t i = 0; i < resp.size() ; i++ ){\r\n            resp[ i ] += offsets[ shotMap_[ shotpos[ i ] ] ];\r\n        }\r\n        return resp;\r\n    }\r\n\\end{lstlisting}\r\n\r\nFor the Jacobian the case is a bit more complicated.\r\nInstead of increasing the size of the matrix a-posteriori, we use a block matrix type \\lstinline|H2SparseMapMatrix| consisting of two horizontally concatenated matrices called by \\lstinline|H1()| and \\lstinline|H2()| \\footnote{See appendix on matrices \\ref{app:matrix} for existing matrix types.}.\r\nThe first is the normal way matrix holding the path lengths.\r\nThe second is a matrix with a value of 1 in the position of the shot number and 0 elsewhere.\r\n\r\n\\begin{lstlisting}\r\n    RVector TTOffsetModelling::createJacobian( H2Matrix & jacobian, \r\n                                          const RVector & model ){\r\n        //! extract slowness from model and call old function\r\n        RVector slowness( model, 0, model.size() - shots_.size() );\r\n        RVector offsets( model, model.size() - shots_.size(), model.size());\r\n        TTMod::createJacobian( jacobian.H1(), slowness );\r\n        jacobian.H2().setRows( dataContainer_->size() );\r\n        jacobian.H2().setCols( offsets.size() );\r\n        //! set 1 entries for the used shot\r\n        RVector shotpos = dataContainer_->get( \"s\" );\r\n        for ( size_t i = 0; i < dataContainer_->size(); i++ ) {\r\n            jacobian.H2().setVal( i, shotMap_[ shotpos[ i ] ], 1.0 ); \r\n        }\r\n    }\r\n\\end{lstlisting}\r\n\r\nAs a result the model vector holds both slowness values and the offsets, which can be sliced out of the vector for individual post-processing.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{What else?}\r\n\\begin{itemize}\r\n\t\\item Full waveform TDR inversion?\r\n\t\\item Gravity 2d or 3d inversion?\r\n\t\\item what is enhanced?\r\n\\end{itemize}\r\n", "meta": {"hexsha": "e731874a7a48c326e97d7a5f0a71a057bad78418", "size": 9239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tutorial/enhanced.tex", "max_stars_repo_name": "mjziebarth/gimli", "max_stars_repo_head_hexsha": "196ac4d6dd67e0326cccc44a87b367f64051e490", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-10T00:56:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T12:43:38.000Z", "max_issues_repo_path": "doc/tutorial/enhanced.tex", "max_issues_repo_name": "ivek1312/gimli", "max_issues_repo_head_hexsha": "5fafebb7c96dd0e04e2616df402fa27a01609d63", "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/tutorial/enhanced.tex", "max_forks_repo_name": "ivek1312/gimli", "max_forks_repo_head_hexsha": "5fafebb7c96dd0e04e2616df402fa27a01609d63", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-29T04:28:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T04:28:40.000Z", "avg_line_length": 65.524822695, "max_line_length": 433, "alphanum_fraction": 0.6989933976, "num_tokens": 2373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6799981096623492}}
{"text": "%!TEX root = thesis.tex\r\n\r\n\\chapter{Derivations and Equations}\r\n\\label{app:Derivations}\r\n% --------------------------------------------------------- %\r\n\\section{Belief Update}\r\n\\label{app:BeliefUpdates}\r\n% --------------------------------------------------------- %\r\n\\begin{equation}\r\n  B_t^i \\defeq p(S_t = i | A_{1:t}, O_{1:t})\r\n\\end{equation}\r\n\r\n\\begin{subequations}\\label{belief_update}\r\n  \\begin{align}\r\n    b_t^j &= p(S_t = j | a_{1:t}, o_{1:t})\\label{belief_state} \\\\\r\n          &= \\frac{ p(S_t = j, o_t | a_{1:t}, o_{1:t-1}) } { p(o_t) } \\\\\r\n          &= \\frac{ p(o_t | S_t = j, a_{1:t}, o_{1:t-1}) p(S_t = j | a_{1:t}, o_{1:t-1})} { p(o_t) } \\\\\r\n          \\intertext{and since $o_t$ is independent of $o_{1:t-1}$ we can write}\r\n          &= \\frac{ p(o_t | S_t = j, a_{1:t}) p(S_t = j | a_{1:t}, o_{1:t-1})} { p(o_t) } \\\\\r\n          &= \\frac{ p(o_t | S_t = j, a_{1:t}) \\sum_{i} p(S_t = j, S_{t-1} = i | a_{1:t}, o_{1:t-1})} { p(o_t) } \\\\\r\n          &= \\frac{ p(o_t | S_t = j, a_{1:t}) \\sum_{i} p(S_t = j | S_{t-1} = i, a_{1:t}, o_{1:t-1}) p(S_{t-1} = i | a_{1:t-1}, o_{1:t-1})} { p(o_t) } \\\\\r\n          \\intertext{Markovian assumption; given $S_{t-1}$, $S_t$ is independent of $a_{1:t-1}, o_{1:t-1}$ so we get}\r\n          &= \\frac{ p(o_t | S_t = j, a_{1:t}) \\sum_{i} p(S_t = j | S_{t-1} = i, a_t) p(S_{t-1} = i | a_{1:t-1}, o_{1:t-1}) } { p(o_t) } \\\\\r\n          \\intertext{Using \\eqref{belief_state} we can write}\r\n          &= \\frac{ p(o_t | S_t = j, a_{1:t}) \\sum_{i} p(S_t = j | S_{t-1} = i, a_t) b_{t-1}^i } { p(o_t) } \\\\\r\n          \\intertext{Markovian assumption again; given $S_t$, $o_t$ is independent of $a_{1:t-1}$ so we get}\r\n          &= \\frac{ p(o_t | S_t = j, a_t) \\sum_{i} p(S_t = j | S_{t-1} = i, a_t) b_{t-1}^i } { p(o_t) }\r\n  \\end{align}\r\n\\end{subequations}\r\nIf the state never changes we have\r\n\\begin{equation}\\label{fixed_target}\r\n  p(S_t = j | S_{t-1} = i, a_t) =\r\n  \\begin{cases}\r\n    1 & \\text{if $j = i$} \\\\\r\n    0 & \\text{otherwise}\r\n  \\end{cases}\r\n\\end{equation}\r\nand then \\eqref{belief_update} becomes\r\n\\begin{equation}\\label{belief_update_fixed}\r\n  b_t^j = \\frac{ p(o_t | S_t = j, a_t) b_{t-1}^j }{ p(o_t) }\r\n\\end{equation}\r\nwhere $p(o_t)$ can be treated as a normalization factor.\r\n\r\n% --------------------------------------------------------- %\r\n\\section{Observations}\r\n% --------------------------------------------------------- %\r\nThe observation model is\r\n\\begin{equation}\\label{app:ObservationModel}\r\n  \\begin{split}\r\n    O_t^j &= \\delta (S_t, j) d_{j,k} + Z_t^j \\\\\r\n          &= \\begin{cases}\r\n                d_{j,k} + Z_t^j & \\text{if $S_t = j$}\\\\\r\n                Z_t^j           & \\text{otherwise}\r\n             \\end{cases}\r\n  \\end{split}\r\n\\end{equation}\r\nwhere $Z_t^j$ is zero mean, unit variance Gaussian random noise (i.e. white noise) and in the case of an exponential-decay vision system \r\n\\begin{equation}\r\n  d_{j,k} = 3 \\cdot e^{-dist(j,k)}\r\n\\end{equation}\r\nwhere $dist(j,k)$ is the Euclidean distance between locations $j$ and $k$.\r\n\r\nWe assume that given an image, individual observations (i.e. each pixel)\r\n\\begin{equation}\r\n  o_t = (o_t^1, \\dotsc, o_t^{|\\mathcal{S}|})\r\n\\end{equation}\r\nare conditionally independent. Then we can write the probability of an observation as\r\n\\begin{subequations}\r\n  \\begin{align}\r\n    p(o_t | S_t = i, A_t = k) \r\n      &= \\prod_j p(o_t^j | S_t = i, A_t = k) \\\\\r\n      &= p(o_t^i | S_t = i, A_t = k) \\prod_{j \\neq i} p(o_t^j | S_t = i, A_t = k) \\\\\r\n      \\intertext{Given the observation model from equation \\eqref{app:ObservationModel} we get}\r\n      &= \\gaussianexp{o_t^i - d_{i,k}} \\prod_{j \\neq i} \\gaussianexp{o_t^j} \\\\\r\n      &= \\frac{1}{\\sqrt{2\\pi}} \\frac{\\gaussianexppart{o_t^i - d_{i,k}}}{\\gaussianexppart{o_t^i}} \\prod_j \\gaussianexp{o_t^j} \\\\\r\n      &= \\frac{\\gaussianexppart{o_t^i - d_{i,k}}}{\\gaussianexppart{o_t^i}} Z \\\\\r\n      &= \\exp((o_t^i - \\frac{d_{i,k}}{2}) d_{i,k}) K\r\n  \\end{align}\r\n\\end{subequations}\r\nwhere $K$ is a constant. Ignoring the constant $K$ and terms not containing $o_t^i$ we can write\r\n\\begin{equation}\r\n  \\label{app:ProportionalObservationLikelihood}\r\n  p(o_t | S_t = i, A_t = k) \\propto \\exp{(d_{i,k} o_t^i)}\r\n\\end{equation}\r\n\r\n% --------------------------------------------------------- %\r\n\\section{Proportional Belief Update}\r\n% --------------------------------------------------------- %\r\nCombining \\eqref{belief_update_fixed} and \\eqref{app:ProportionalObservationLikelihood} yields the proportional belief update\r\n\\begin{equation}\r\n  % b_{t+1}^i \\propto \\exp(\\alpha_{i,k} d_{i,k}) b_t^i\r\n  b_{t+1}^i \\propto \\exp{(d_{i,k} o_t^i)} b_t^i\r\n\\end{equation}\r\n", "meta": {"hexsha": "4605ae4aefc97671e0e3363c100ebfb83b21c96d", "size": 4585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix_equations.tex", "max_stars_repo_name": "bjorgvino/kth-thesis", "max_stars_repo_head_hexsha": "8d8063c119e8472ae6db503d9534a7147cc180ef", "max_stars_repo_licenses": ["MIT"], "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_equations.tex", "max_issues_repo_name": "bjorgvino/kth-thesis", "max_issues_repo_head_hexsha": "8d8063c119e8472ae6db503d9534a7147cc180ef", "max_issues_repo_licenses": ["MIT"], "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_equations.tex", "max_forks_repo_name": "bjorgvino/kth-thesis", "max_forks_repo_head_hexsha": "8d8063c119e8472ae6db503d9534a7147cc180ef", "max_forks_repo_licenses": ["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.7765957447, "max_line_length": 153, "alphanum_fraction": 0.5293347874, "num_tokens": 1683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6799251173510068}}
{"text": "\n\\subsection{Paths and loops}\n\n\\subsubsection{Paths}\n\nWe have the set \\(X\\). We define a mapping \\([0,1]\\rightarrow X\\)\n\nIf a path exists between any two points, then the space is path-connected.\n\n\\subsubsection{Loops}\n\nThis is a path which ends on itself.\n\nIf \\(f(0)=f(1)\\) then it is a loop.\n\n", "meta": {"hexsha": "b184ae89951cdf6ca7d167f1eba0c871bead8d6d", "size": 295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsTopological/03-01-paths.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/03-01-paths.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/03-01-paths.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.4375, "max_line_length": 74, "alphanum_fraction": 0.7016949153, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6798971404053719}}
{"text": "\\section*{Appendix}\n\n\n\n\\subsubsection{Derivations of the Model for homogenous factors $\\Lambda_k = \\Lambda$}\n\\label{derivation}\nHere, we provide a detailed study of the possible behaviors of the model, also around the critical point $\\Lambda =1$.\n\nThree regimes must be considered:\n\\begin{enumerate}\n\\item For $\\Lambda < 1$, the distribution is given by\n\\be\nP_{\\Lambda <1}(S  \\geq s) = (1-\\beta) \\left(1 - {s \\over s_{\\rm max}}\\right)^c~, ~~~s_{\\rm max} := {S_0 \\Lambda \\over 1-\\Lambda}~, ~~c := {\\rm{ln}{\\beta} \n\\over \\rm{ln}{\\Lambda}} >0~.\n\\label{trjruyk5i}\n\\ee\nThis distribution can be approximated in its central part, away from the maximum possible reward $s_{\\rm max}$,\nby a Weibull distribution of the form\n\n\\be\n{\\rm Pr}_{\\rm }({\\rm S} \\geq s) \\sim e^{-(s/d)^{c}}~.\n\\label{trjeargquju}\n\\ee\n\nFor $\\Lambda \\to 1^-$, \nwe have $s_{\\rm max} \\to +\\infty$ and, for $s \\ll s_{\\rm max}$,\nexpression (\\ref{trjruyk5i}) simplifies into a simple exponential function \n\\be\nP_{\\Lambda \\to 1^-}(S  \\geq s) \\sim e^{-|\\ln(\\beta)| s/S_0}~.\n\\label{jrtikik}\n\\ee\n\n\\item For $\\Lambda = 1$, the distribution of rewards  is a simple exponential function since $S_{n} = n S_{0}$ is linear in the rank $n$ and the probability of reaching rank $n$ is the exponential\n$P(n) = \\beta^{n} (1-\\beta)$. Actually, the expression\n(\\ref{jrtikik}) becomes asymptotical exact as\n\\be\nP_{\\Lambda =1}(S  \\geq s) = (1-\\beta) e^{-|\\ln(\\beta)| s/S_0}~.\n\\label{jrtikik}\n\\ee\n\n\n\\item For $\\Lambda > 1$, the distribution of rewards is of the form,\n\n\\be\nP_{\\Lambda >1}(S  \\geq s) = \\frac{1}{{{(1+ \\frac{s}{s*})}^{c}}}~,~~s^{*} := {S_0 \\Lambda \\over \\Lambda -1}~, ~~c := {|\\rm{ln}{\\beta}|\\over \\rm{ln}{\\Lambda}}~,\n\\label{jrtisdfjl}\n\\ee\n\nwhich develops to a power law distribution of reward of the form\n${\\rm Pr}({\\rm reward} \\geq S) = C/S^{\\mu}$ with $\\mu = c$, when $\\Lambda \\rightarrow +\\infty$.\n\n%For $\\Lambda \\to 1^+$, the tail is still power law and the exponent $\\mu$ grows without bound if the probability $\\beta$ does not converge to $1$ at the same rate.  Denoting $\\Lambda = 1-a$, $\\beta = 1-\\rho a$, with $a \\to 0^+$ and $\\rho$ constant, we have $\\mu \\to \\rho$.\n\\end{enumerate}", "meta": {"hexsha": "f8ea31936178a15c89fc4ff8d1201c5ce1d062f7", "size": 2144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscripts/sections/appendix.tex", "max_stars_repo_name": "wazaahhh/bountyhunters", "max_stars_repo_head_hexsha": "3b2f09de463268f22d3cb65e364b7fe380062169", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "manuscripts/sections/appendix.tex", "max_issues_repo_name": "wazaahhh/bountyhunters", "max_issues_repo_head_hexsha": "3b2f09de463268f22d3cb65e364b7fe380062169", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manuscripts/sections/appendix.tex", "max_forks_repo_name": "wazaahhh/bountyhunters", "max_forks_repo_head_hexsha": "3b2f09de463268f22d3cb65e364b7fe380062169", "max_forks_repo_licenses": ["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.4528301887, "max_line_length": 273, "alphanum_fraction": 0.6478544776, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6798971333361084}}
{"text": "\n\\chapter{Miscellaneous problems}\n\n%=====================================================================\n% \\section{Fun problems}\n% \\label{sec:funproblems}\n\\sectionWithAnswers{Fun problems}{sec:funproblems}\n\nIn this section we present a number of problems for the interested\nreader to pursue.\n\n\\begin{Exercise}\\label{ex:misc:riffle}\n  A riffle shuffle of a deck of even-numbered cards splits the deck\n  into two equal parts, and then alternates the cards. That is, if the\n  cards were originally numbered $1$ \\ldots $10$, they will end up $1,\n  6, 2, 7, 3, 8, 4, 9, 5, 10$. Write a function {\\tt riffle} that\n  takes an even number of elements and returns the elements in the new\n  order. The signature of your function should be:\n\\begin{code}\n   riffle : {a b} (fin a) => [2*a]b -> [2*a]b;\n\\end{code}\nYou might find the following Cryptol primitive functions useful:\n\\begin{Verbatim}\n   length : {n, a, b} (fin n, Literal n b) => [n]a -> b\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   join : {parts, each, a} (fin each) => [parts][each]a -> [parts * each]\n\\end{Verbatim}\nUse the interpreter to pass arguments to these functions to\nfamiliarize yourself with their operation first. What happens when you\ncall {\\tt riffle} with a sequence that has an odd number of elements?\n\\end{Exercise}\n\n\\begin{Answer}\\ansref{ex:misc:riffle}\n\\begin{code}\n  riffle xs = join [ [x, y] | x <- fh | y <- sh ]\n    where [fh, sh] = split xs\n\\end{code}\nThe Cryptol type-checker will {\\em not} allow passing an odd number of\nelements to {\\tt riffle}. To see the error message, issue: {\\tt riffle\n  [1..5]}.\n\\end{Answer}\n\n\\begin{Exercise}\\label{ex:misc:riffle2}\n  Given a deck of 52 cards, 8 riffles returns the deck to its original\n  position. Write a theorem stating this fact and prove it.\n\\end{Exercise}\n\\begin{Answer}\\ansref{ex:misc:riffle2}\n  Note that the actual contents of the input sequence is immaterial;\n  we will just use 8-bit numbers.\n\\begin{code}\n   riffle8 : [52][8] -> Bit;\n   property riffle8 deck = decks @ 8 == deck\n     where decks = [deck] # [ riffle d | d <- decks ]\n\\end{code}\n\\end{Answer}\n\n\\begin{Exercise}\\label{ex:misc:sort}\n  Define the merge-sort function in Cryptol, that works over arbitrary\n  finite sequences of words. Prove its correctness. You might want to\n  split the proof in two parts. First prove that the output is a\n  permutation of the input, and then prove that the output is always\n  in increasing order.\n\\end{Exercise}\n\\begin{Answer}\\ansref{ex:misc:sort}\n  A solution to the merge-sort problem can be found in the {\\tt\n    Examples} directory of the Cryptol distribution.\n\\end{Answer}\n\n\\begin{Exercise}\\label{ex:misc:legato}\n  Legato's challenge refers to the verification of an 8-bit\n  multiplication algorithm encoded in Mostek assembly code. More\n  information on Legato's challenge can be found at:\n\\begin{center}\n \\url{http://www.cs.utexas.edu/~moore/acl2/workshop-2004/contrib/legato/Weakest-Preconditions-Report.pdf}\n\\end{center}\nWrite a Cryptol program to model Legato's multiplication algorithm\nfollowing the machine model. Prove that the multiplier is correct.\n\\end{Exercise}\n\\begin{Answer}\\ansref{ex:misc:legato}\nA solution can be found at:\n\\begin{center} \\url{http://www.galois.com/blog/2009/07/08/legatosmultiplierincryptol}\n\\end{center}\n\\end{Answer}\n\n\\begin{Exercise}\\label{ex:misc:skein}\n  The Cryptol distribution comes with a variety of crypto algorithm\n  implementations, including AES and the SHA-3 candidate Skein.  Study\n  these definitions and experiment with them using the Cryptol\n  interpreter.\n\\end{Exercise}\n", "meta": {"hexsha": "583552e7d1f1fba6f1baf1e0e4ff4e459bdd4e7c", "size": 3655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/ProgrammingCryptol/misc/Misc.tex", "max_stars_repo_name": "golegen/cryptol", "max_stars_repo_head_hexsha": "8cf1450fe6849d666007a71fe543f13cd32b942f", "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/misc/Misc.tex", "max_issues_repo_name": "golegen/cryptol", "max_issues_repo_head_hexsha": "8cf1450fe6849d666007a71fe543f13cd32b942f", "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/misc/Misc.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": 39.7282608696, "max_line_length": 105, "alphanum_fraction": 0.7135430917, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.843895100591521, "lm_q1q2_score": 0.6798690610983215}}
{"text": "% \\begin{savequote}[75mm]\n% Nulla facilisi. In vel sem. Morbi id urna in diam dignissim feugiat. Proin molestie tortor eu velit. Aliquam erat volutpat. Nullam ultrices, diam tempus vulputate egestas, eros pede varius leo.\n% \\qauthor{Quoteauthor Lastname}\n% \\end{savequote}\n\n\\chapter{Statistics}\nStatistics is a branch of mathematics dealing with the collection, organization, analysis, interpretation and presentation of data.\n\\href{https://en.wikipedia.org/wiki/Statistics}{wikipedia}\n\n\\section{Probability}\nTODO: Probability (general + simple), CDF, Variance, Markov-Property, etc.\n\\subsection{$L_p$-Space for Random-Variables}\nThe $L_p$-Norm for Random-Variables $X$, where $\\mathbb{E}|X|^p < \\infty$, is defined through:\n\\begin{align*}\n\t||X||_p:=(\\mathbb{E}[|X|^p])^{\\frac{1}{p}}\n\\end{align*}\n\\href{http://www2.stat.duke.edu/courses/Fall18/sta711/lec/wk-05.pdf}{lecture}\n\n\\subsection{Jensens-Inequality for Random Variables}\nIf $\\phi$ is a konvex function and $X$ a Random-Variable, then\n\\begin{align*}\n\t\\phi(\\mathbb{E}X) \\leq \\mathbb{E}\\phi(X)\n\\end{align*}\n\\href{https://en.wikipedia.org/wiki/Jensen%27s_inequality}{wikipedia}\n\n\\subsection{Fisher-Information}\nFor the parametric family $\\mathcal{P} \\in \\{ \\mathcal{P}_\\theta | \\theta \\in \\Theta_L\\}$...TODO\\\\\nIf we assume $p_\\theta(x,y)=p_\\theta(y|x)p(x)$, the Fisher-Information Matrix $\\mathcal{I}(\\theta)$ becomes:\n\\begin{align*}\n\t\\mathcal{I}(\\theta) = \\mathbb{E}_{(X,Y)\\sim {P}_\\theta}[\\nabla_{\\theta}\\log p_{\\theta}(Y|X)\\otimes\\nabla_{\\theta}\\log p_{\\theta}(Y|X)]\\text{,}\n\\end{align*}\nwhere $\\otimes$ is the inner-product.\\\\\n\\href{https://arxiv.org/abs/1711.01530}{paper}\n\n\\section{Distributions}\nIn this section, $X$ denotes a Random Vairable and $f$ the density-function.\\\\\nTODO: More common distributions\n\\subsection{Normal Distribution}\nIf $X \\sim {\\mathcal {N}}(\\mu ,\\sigma ^{2})$ for ${\\displaystyle \\mu \\in \\mathbb {R}}$ and $\\sigma ^{2} > 0 \\in \\mathbb {R}$, then:\n\\begin{align*}\n\tf(x) &= {\\displaystyle {\\frac {1}{\\sqrt {2\\pi \\sigma ^{2}}}}e^{-{\\frac {(x-\\mu )^{2}}{2\\sigma ^{2}}}}}\\\\\n\t\\mathbb{E}X &= \\mu \\\\\n\tVar[X] &= \\sigma^2\n\\end{align*}\n\\href{https://en.wikipedia.org/wiki/Normal_distribution}{wikipedia}\n\n\\subsection{Normal Distribution (Multivariate)}\nIf $X \\sim {\\mathcal {N}}(\\mu ,\\Sigma)$ for $\\mu \\in \\mathbb {R}^k$ and $\\Sigma \\in \\mathbb {R}^{k \\times k}$ with $\\Sigma$ being positve semi-definite, then:\n\\begin{align*}\n\tf(x) &= \\operatorname {det} (2\\pi {\\boldsymbol {\\Sigma }})^{-{\\frac {1}{2}}}\\,e^{-{\\frac {1}{2}}(\\mathbf {x} -{\\boldsymbol {\\mu }})'{\\boldsymbol {\\Sigma }}^{-1}(\\mathbf {x} -{\\boldsymbol {\\mu }})}\\\\\n\t\\mathbb{E}X &= \\mu \\\\\n\tVar[X] &= \\Sigma\n\\end{align*}\n\\href{https://en.wikipedia.org/wiki/Multivariate_normal_distribution}{wikipedia}\n\n\\subsection{Empirical Distribution}\nFor any observation $X'=(x'_1, \\cdots, x'_n)$, the empirical distribution is defined as:\n\\begin{align*}\n\tf(x) &= \\hat{f}(x) =\\frac{1}{n}\\sum_{i=1}^{n}\\delta(x - x_i)\\text{, where $\\delta$ is the dirac-delta function}\\\\\n\t\\mathbb{E}X &= \\hat{\\mathbb{E}}X = \\frac{1}{n}\\sum_{i=1}^{n}x_i \\\\\n\tVar[X] &= \\hat{Var}[X] =\\frac{1}{n}\\sum_{i=1}^{n}(x_i-\\hat{\\mathbb{E}}X)^2\n\\end{align*}\n\\href{http://www.stat.umn.edu/geyer/5102/slides/s1.pdf}{lecture}\n\n\\section{Estimation}\nTODO: ML, Score-Function, biased/unbiased, Cramér–Rao bound, confidence-interval\n\n\\section{Divergences}\nConventions for this section: $P$ and $Q$ are probability measures over a set $X$, and $P$ is absolutely continuous with respect to $Q$. $S$ is a space of all probability distributions with common support.\n\\subsection{Divergence}\nA divergence on $S$ is a function $D: S \\times S \\rightarrow R$ satisfying\n\\begin{enumerate}\n\t\\item $D(p || q) \\geq 0  \\forall p, q \\in S$,\n\t\\item $D(p || q) = 0 \\Leftrightarrow p = q$\n\\end{enumerate}\n\\textit{A divergence is a \"sense\" of distance between two probability distributions. It's not a metric, but a pre-metric.}\\\\\n\\href{https://en.wikipedia.org/wiki/Divergence_(statistics)}{wikipedia}\n\n\\subsection{f-Divergence}\n\\begin{enumerate}\n\t\\item Generalization of whole family of divergences\n\t\\item For a convex function $f$ such that $f(1) = 0$, the f-divergence of $P$ from $Q$ is defined as:\\\\\n\t$D_{f}(P\\parallel Q)\\equiv \\int _{{\\Omega }}f\\left({\\frac{dP}{dQ}}\\right)\\,dQ$\n\t\\item \\href{https://en.wikipedia.org/wiki/Divergence_(statistics)}{wikipedia}\n\\end{enumerate}\n\n\\subsection{KL-Divergence}\n\\begin{enumerate}\n\t\\item The Kullback–Leibler divergence from $Q$ to $P$ is defined as\\\\\n\t$D_{\\mathrm {KL} }(P\\|Q)=\\int _{X}\\log {\\frac {dP}{dQ}}\\,dP=D_{t\\log t}$.\n\t\\item maxmizing likelihood is equivalent to minimizing $D_{KL}(P(. \\vert \\theta^{\\ast}) \\, \\Vert \\, P(. \\vert \\theta))$ (the foreward-KL Divergence), where $P(. \\vert \\theta^{\\ast})$ is the true distribution and $P(. \\vert \\theta)$ is our estimate.\n\t\\item \\href{https://en.wikipedia.org/wiki/Kullback–Leibler_divergence}{wikipedia}\n\t\\item TODO: Fisher-Matrix infitesimal relationship\n\\end{enumerate}\n\n\\subsection{Jensen–Shannon divergence}\nThe Jensen–Shannon divergence from $Q$ to $P$ is defined as\n\\begin{align*}\n\t{{\\rm {JSD}}}(P\\parallel Q)={\\frac  {1}{2}}D(P\\parallel M)+{\\frac  {1}{2}}D(Q\\parallel M)\n\\end{align*}, where $M={\\frac  {1}{2}}(P+Q)$\\\\\n\\href{https://en.wikipedia.org/wiki/Jensen–Shannon_divergence}{wikipedia}\n\n\\subsection{TODO: Wasserstein \\& Wasserstein Dual}\n\n\\section{Information Geometry}\nInformation Geometry defines a Riemannian Manifold over probability distributions for statistical models.\\\\\n\\subsection{Fisher-Rao Metric}\nFor the parametric family $\\mathcal{P} \\in \\{ \\mathcal{P}_\\theta | \\theta \\in \\Theta_L\\}$ and every $\\alpha, \\beta \\in \\mathbb{R}^d$ with their tangent-vectors $\\bar{\\alpha}=dp_{\\theta + t\\alpha}/dt|_{t=0}$ and $\\bar{\\beta}=dp_{\\theta + t\\beta}/dt|_{t=0}$, we define the inner local product as follows:\n\\begin{align*}\n\t<\\bar{\\alpha}, \\bar{\\beta}> &:= \\int_M\\frac{\\bar{\\alpha}}{p_\\theta}\\frac{\\bar{\\beta}}{p_\\theta}p_\\theta\\\\\n\t&=<\\alpha, \\mathcal{I}(\\theta)\\beta>\\text{,}\n\\end{align*}\nwhere $\\mathcal{I}(\\theta)$ is the Fisher-Information Matrix.\n\\subsection{Natural Gradient}\nThe natural gradient is the gradient descent induced by the Fisher-Rao geometry of $\\{\\mathcal{P}_\\theta \\}$.\\\\\n\\href{https://arxiv.org/abs/1711.01530}{paper}", "meta": {"hexsha": "c1c00ca3ce14cf5ead6c1fb4b7689b3b91741817", "size": 6223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Statistics.tex", "max_stars_repo_name": "ML-KA/PDG-Code", "max_stars_repo_head_hexsha": "77f13079a86288bc09d4f9e7992d94abab2a1918", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-01T17:47:45.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-01T17:47:45.000Z", "max_issues_repo_path": "Statistics.tex", "max_issues_repo_name": "ML-KA/PDG-Code", "max_issues_repo_head_hexsha": "77f13079a86288bc09d4f9e7992d94abab2a1918", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-08-31T08:26:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-06T13:13:02.000Z", "max_forks_repo_path": "Statistics.tex", "max_forks_repo_name": "ML-KA/PDG-Code", "max_forks_repo_head_hexsha": "77f13079a86288bc09d4f9e7992d94abab2a1918", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-30T06:08:36.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-30T06:08:36.000Z", "avg_line_length": 53.6465517241, "max_line_length": 302, "alphanum_fraction": 0.6913064438, "num_tokens": 2144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6798690595168478}}
{"text": "%\n% 337\n%\n\\chapter{The Confluent Hypergeometric Function}\n\n\\Section{16}{1}{The confluence of two singularities of Riemanns equation}\n\nWe have seen \\hardsectionref{10}{8}) that the linear differential equation with two\nregular singularities only can be integrated in terms of elementary\nfunctions; while the solution of the linear differential equation\nwith three regular singularities is substantially the topic of Chapter\nxiv. As the next type in order of complexity, we shall consider a\nmodified form of the differential equation which is obtained from\nRiemann's equation by the confluence of two of the singularities. This\nconfluence gives an equation with an irregular singularity\n(corresponding to the confluent singularities of Riemann's equation)\nand a regular singularity corresponding to the third singularity of\nRiemann's equation.\n\nThe confluent equation is obtained by making c -* oo in the equation\ndefined by the scheme\n\nX c\n\n-.--m -c c - k\n\nP\n\n1;\n\n2\n\n.7 - ni k\n\nThe equation in question is readily found to be\n\nWe modify this equation by writing TODO and obtain as the equation*\nfor Wkmi)\n\nThe reader will verify that the singularities of this equation are at\n6 and X, the former being regular and the latter irregular; and when\n2m is not an integer, two integrals of equation (B) which are regular\nnear and valid for all finite values of z are given by the series\n\n* This equation was given by Whittaker, Bulletin American Math. Soc.\nx. (1904), pp. 125-134. W. M. A. 22\n\n%\n% 338\n%\n\nThese series obviously form a fundamental system of solutions.\n\n[Note. Series of the type in \\{ \\} have been considered by Kummer* and\nmore recently by Jticobsthalt and Barnes J; the special series in\nwhich k = had been investigated by Lagrange in 1762-1765 (Oeuvres, I.\np. 480). In the notation of Kummer, modified by Barnes, they would be\nwritten iF-i \\{h±ni - k; ± 2m + 1; 2\\}; the reason for discussing\n\nsolutions of equation (B) rather than those of the equation 2\n\nwhich iFi (a; p; z) is a solution, is the greater appearance of\nsymmetry in the formulae, together with a simplicity in the equations\ngiving various functions of Applied Mathe- matics (see \\hardsectionref{16}{2}) in\nterms \"of solutions of equation (B).]\n\n\\Subsection{16}{1}{1}{Kummer s formulae.}\n\n(I) We shall now shew that, if '2'm is not a negative integer, then\n\n---il/,,() = (-)-i\\~''W,,,(-), that is to say,\n\n., (I + m - k) (f + m - k)\n\n \"\" -\" 2 ! (2w + 1) (271 + 2)\n\nh\n\n+ m -\n\nk\n\n1!\n\n\\{2m +\n\n1)\n\ni\n\n+ m +\n\nk\n\n  . ( + w + k) (f + m + k) .,\n\nl!(2m + l) 2 ! (2m + 1) (2m +2) ' '■**\n\nFor, replacing TODO by its expansion in powers of z, the coefficient\nof TODO in the product of absolutely convergent series on the left is\n\nby \\hardsubsectionref{14}{1}{1}, and this is the coefficient of \" on the right§; we have\nthus obtained the required result.\n\nThis will be called Kummej-'s first formula.\n\n(II) The equation\n\nvalid when 2m is not a negative integer, will be called Kummer s\nsecond formula.\n\nTo prove it we observe that the coefficient of £\"+\"'+? in the product\nTODO\n\n* Journal fur Math. xv. (1836), p. 139. t Math. Ann. lvi. (1903), pp.\n129-154. X Trans. Camb. Phil. Soc. xx. (1908), pp. 253-279.\n\n§ The result is still true when ?h +  + k is a negative integer, by\na slight modification of the analysis of \\hardsubsectionref{14}{1}{1}.\n\n%\n% 339\n%\n\nof which the second and third factors possess absolutely convergent\nexpansions, is \\hardsubsectionref{3}{7}{3})\n\nnl\\{2m+l)\\{2m + 2) ...\\{27n+7i); - -\n\nby Kummer's relation*\n\nTODO\n\nvalid when a' i; and so the coefficient of 2\"+'\"\"'\" (by\n\\hardsubsectionref{14}{1}{1}) is\n\n(| + w)(§ + m) ... \\{n-m-- ) T \\{-n + h-m)r \\{ ) n (2i+l)(2m +\n2)... (2m + 7i) T \\{-m-hi)T\\{-n)\n\nn (2m + 1 ) \\{2m -- 2) . . . \\{2m + n) r ( - w - hi) r ( - 1?0 '\nand when n is odd this vanishes; for even values of n\\{ = 2p) it is\n\nr(i-/)(-)(-|)...(i-p)\n\nl.S...\\{2p-l) 1\n\n2pl 23p(m + l)(m + 2)...(m+p) 2*P.p \\{m + 1) \\{m + 2) ... \\{m+p)'\n\n\\Subsection{16}{1}{2}{Definition f of the function Wic,m (2) }\n\nThe solutions -il/t.imC') of equation (B) of \\hardsectionref{16}{1} are not,\nhowever, the most convenient to take as the standard solutions, on\naccount of the disappearance of one of them when 2m is an integer.\n\nThe integral obtained by confluence from that of \\hardsectionref{14}{6}, when\nmultiplied by a constant multiple of TODO is TODO:\n\nIt is supposed that arg has its principal value and that the contour\nis so chosen that the point t = - z is outside it. The integrand is\nrendered one- valued by taking; arg (- ) |  tt and taking that\nvalue of arg (1 + t/z) which tends to zero as i -*- by a path lying\ninside the contour.\n\nUnder these circumstances it follows from \\hardsubsectionref{5}{3}{2} that the integral is\nan analytic function of z. To shew that it satisfies equation (B),\nwrite\n\n* See Chapter xiv, examples 12 and 13, p. 298.\n\n+ The function TODO was defined by means of an integral in this manner\nby Whittaker, ioc. cit. p. 125.\n\n* A suitable contour has been chosen and the variable t of \\hardsectionref{14}{6}\nreplaced by - 1.\n\n22-2\n\n%\n% 340\n%\n\nand we have without difficulty*\n\nTODO\n\nsince the expression in \\{ \\} tends to zero as i -* + oo; and this is\nthe condition that TODO should satisfy (B).\n\nAccordingly the function Wk, m \\{z) defined by the integral\n\nis a solution of the differential equation (B).\n\nThe formula for TfA;,m () becomes nugatory when ' - 2 - w is a\nnegative integer. To overcome this difficulty, we observe that\nwhenever\n\nand k - - m is not an integer, we may transform the contour integral\ninto an infinite integral, after the manner of \\hardsubsectionref{12}{2}{2}; and so, when\n\nRik -i-:- 7n 0,\n\nThis formula suffices to define Wimiz) in the critical cases when m\n+ 2->t is a positive integer, and so Wk,m\\{z) is defined for all\nvalues of k and m and all values of z except negative real values f.\nExample. Solve the equation\n\ndu ( b c\n\nin terms of functions of the type Tft, (2), where a, 6, c are any\nconstants.\n\n\\Section{16}{2}{Expression of various functions by functions of the\n  type Wk,n(z)}\n\nIt has been shewn:!: that various functions employed in Applied Mathe-\nmatics are expressible by means of the function Wk,m (2); the\nfollowing are a few examples :\n\n* The differentiations under the sign of integration are legitimate by \\hardsubsectionref{4}{4}{4} corollary.\n\nt When z is real and negative, TODO may be defined to be either TODO\nor TODO whichever is more convenient.\n\n+ Whittaker, Bulletin American Math. Soc. x.; this paper contains a\nmore complete account than is given here.\n\n%\n% 341\n%\n(I) The Error function* which occurs in connexion with the theories of\nProbability, Errors of Observation, Refraction and Conduction of Heat\nis defined by the equation\n\nErfc()=[ e-''dt, where a; is real.\n\nWriting t = x\\{w - l) and then iu = s/x in the integral for TT.j.\n.(a), we get\n\nJi = TODO\n\nJ X\n\nand so the error function is given by the formula\n\nErfc (a;) = TODO\n\nOther integrals which occur in connexion with the theory of Conduction\nrb of Heat, e.g. TODO, can be expressed in terms of error functions,\nand\n\nJ a\n\nSO in terms of TODO functions.\n\nExaviple. Shew that the formula for the eri'or function is true for\ncomplex values of x.\n\n(II) The Incomplete Gamma function, studied by Legendre and othersf,\nis defined by the equation\n\ny\\{n, x)= j f'-'e-dt. Jo\n\nBy writing t = s - x in the integral for Wi.,,i in(x), the reader\nwill\n\nverify that\n\nTODO\n\n(III) The Logarithmic-integral function, which has been discussed by\nEuler and others :|:, is defined, when | arg \\{- log ■j < tt, by the\nequation\n\n* This name is also applied to the function\n\nErf(x)= I ''e-«'d( = 7r-Erfc(j-).\n\n\\{ Legendre, Exercices, i. p. 339; Hocevar, Zeitschrift fiir Math,\nund Phys. xxi. (1876), p. 449; Schlomilch; Zeitschrift fur Math, und\nPhys. xvi. (1871), p. 261; Prym, Journal filr Math, lxxxii. (1877),\np. 165.\n\nX Euler, Inst. Calc. Int. i.; Soldner, Monatliche- Correspondenz, von\nZach (1811), p. 182; Briefwechsel zwischen Gauss und Bessel (1880),\npp. 114-120; Bessel, Konigsherger Archiv, i. (1812), pp. 369-405;\nLaguerre, Bulletin de la Soc.Math.de France, vii. (1879), p. 72;\nStieltjes, Ann. de VEcole norm. sup. (3), iii. (1886). The\nlogarithmic-integral function is of considerable importance in the\nhigher parts of the Theory of Prime Numbers. See Landau, Primzahlen,\np. 11.\n\n%\n% 342\n%\n\nOn writing 5 - log z = u and then u = - log t in the integral for\n\nit may be verified that\n\nTODO\n\nIt will appear later that Weber's Parabolic Cylinder functions\n(\\hardsectionref{16}{5})\nand Bessel's Circular Cylinder functions (Chapter xvii) are\nparticular cases of the Wkrn function. Other functions of like\nnature are given in the Miscellaneous Examples at the end of this\nchapter.\n\n[Note. The error function has been tabulated by Encke, Berliner ast.\nJahrbuch, 1834, pp. 248-304, and Burgess, Tram. Roy. Soc. Edin. xxxix.\n(1900), p. 257. The logarithmic- integral function has been tabulated\nby Bessel and by Soldner. Jahnke und Emde, Fiinktionentafeln (Leipzig,\n1909), and Glaisher, Factor Tables (London, 1883), should also be\nconsulted.]\n\n\\Section{16}{3}{The asymptotic expansion of TT'a;,w \\{z), when z is large}\nFrom the contour integral by which Wk,rn,\\{z) was defined, it is\npossible to obtain an asymptotic expansion for W]cm\\{z) valid when\n|arg| < tt.\n\nFor this purpose, we employ the result given in Chap, v, example 6,\nthat\n\n1+-) =1+- + ...+ - - + Rn (t, Z),\n\nz) TODO\n\nSubstituting this in the formula of \\hardsubsectionref{16}{1}{2}, and integrating\nterm-by-term, it follows from the result of \\hardsubsectionref{12}{2}{2} that\n\nyyjc,m\\{2) =  -z ji + YY +- 212 +\n\n[m - (k - y-] \\{m' -(k- f] . . . (m -\\{k-n-if f]\n\nwhere\n\nn ! z\n\nI ««\n\nprovided that n be taken so large that R \\{n - k---- m j > 0.\n\nNow, if I arg 2 |  tt - a and z > 1, then\n\n11(1 + /0)11+ R\\{z)Q I (1 + tjz) 1  sin a R (z)  O] '\n\nand so*\n\nTODO\n\n* It is supposed that is real; the inequality has to be slightly\nmodified for complex values of\n\n%\n% 343\n%\n\nTherefore Rn\\{t,z)\n\nTODO\n\nsince 1 +;< < 1 + t\n\nTherefore, when j  | > 1,\n\n= TODO\n\n= TODO\n\nsince the integral converges. The constant implied in the symbol is\nindependent of arg2, but depends on a, and tends to infinity as a-\n0.\n\nThat is to say, the asymptotic expansion of TODO is given by tlie\nformula\n\nTODO\n\nfor large values ofz when arg 2; |  tt - a < tt.\n\n\\Subsection{16}{3}{1}{The second solution of the equation for TODO}\n\nThe differential equation (B) of \\hardsectionref{16}{1} satisfied by Wk,m\\{z) is\nunaltered if the signs of z and k are changed throughout.\n\nHence, if TODO is a solution of the equation.\n\nSince, when $absval{\\arg z} < Tr$,\n\nTODO\n\nwhereas, when | arg ( - 2) | < tt,\n\nW.k,.n\\{-z) = e'H-z)-[l + 0\\{z-%\n\nthe ratio W]cm\\{z)jW-]cjn\\{- z) cannot be a constant, and so\nWkm\\{z) and -k,m\\{- z) form a fundamental system of solutions of\nthe differential equation.\n\n\\Section{16}{4}{Contour integrals of Barnes type for Wc,n(z)}\n\nConsider now\n\nTODO\n\nwhere | arg; ] < - tt, and neither of the numbers k + m + 5 is a\npositive integer\n\n%\n% 344\n%\n\nor zero*; the contour has loops if necessary so that the poles of T\n(s) and those of r ( - s - k-m + 5 ) F (- s - k + m + j are on\nopposite sides of it.\n\nIt is easily verified, by \\hardsectionref{13}{6}, that, as s->cc on the contour,\n\nTODO\n\nand so the integi-al represents a function of 2 which is analytic at\nall points f in the domain j arg z TODO\n\nNow choose N so that the poles oi T (- s - k - m + j T (- s - k+ m +\nj\n\nare on the right of the line R(s) = - N-; and consider the integral\ntaken\n\nround the rectangle whose corners are TODO, where  is\npositive J and large.\n\nThe reader will verify that, when 1 arg z <x, the integrals TODO\n\ntend to zero as - > 00; and so, by Cauchy's theorem,\n\nTODO\n\nwhere Rn is the residue of the integrand at s = - n.\n\nWrite s = - N - I + it, and the modulus of the last integrand is\n\nwhere the constant implied in the symbol is independent of z.\n\nSince TODO converges, we find that\n\nTODO\n\n* In these cases the series of \\hardsectionref{16}{3} terminates and TODO is a\ncombination of elementary' functions.\n\nt The integral is rendered one- valued when J? (z) <0 by specifying\narg z.\n\nX The line joining ±j may have loops to avoid poles of the integrand\nas explained above.\n\n%\n% 345\n%\nBut, on calculating the residue Rn, we get\n\nTODO\n\nand so TODO has the same asymptotic expansion as TODO.\n\nFurther / satisfies the differential equation for Wk, m () ! for, on\n\nsubstituting 1 r\\{s) F (- s - k - m + j F (- s - k + m + j zds\nfor v in\n\nthe expression (given in \\hardsubsectionref{16}{1}{2})\n\nTODO\n\nwe get\n\nTODO\n\nSince there are no poles of the last integrand between the contours,\nand since the integrand tends to zero as | * j - > oo, s being\nbetween the contours, the expression under consideration vanishes, by\nCauchy's theorem; and so / satisfies the equation for TTjt, m \\{2).\n\nTherefore TODO,\n\nwhere A and B are constants. Making $\\absval{TODO} \\rightarrow \\infty$\nwhen R(z)>0 we see, from the asymptotic expansions obtained for / and\nW±k,m\\{± ). that\n\n = 1, 5 = 0.\n\nAccordingly, by the theory of analytic continuation, the equality\n\nI=W,,,n(z) persists for all values of z such that argr|<7r; and, for\nvalues* of arg' such that TT < I arg  I < I TT, Wk,m (z) may be\ndefined to be the expression /.\n\nExample 1. Shew that\n\ntaken along a suitable contour.\n\n* It would have been possible, by modifying the path of integration in \\hardsectionref{16}{3}, to have shewn that that integral could be made to define an\nanalytic function when $\\arg z < TODO$. But the reader will see that\nit is unnecessary to do so, as Barnes' integral affords a simpler\ndefinition of the function.\n\n%\n% 346\n%\n\nExample 2. Obtain Barnes' integral for TODO by writing for TODO in the\nintegral of TODO and changing the order of integration.\n\nTODO\n\n\\Subsection{16}{4}{1}{Relations betiveen Wk,m\\{z) '-nd Mk,±m\\{z)- }\nIf we take the\nexpression\n\nTODO\n\nwhich occurs in Barnes' integral for TODO. and write it in the form\n\nTODO\n\nr(s + k + m + )r\\{s + k - m + )cos\\{s + k + m) ir cos \\{s--k - m)\nit ' we see, by \\hardsectionref{13}{6}, that, when B (s)  0, we have, as, 5 | - > x\n,\n\nF\\{s) = exp|C-s--2'jlog5 +\n\nsec \\{s + k -- m) tt sec \\{s + k - m) ir.\n\nHence, if | arg 2 | <  tt, jF\\{s)z--ds, taken round a semicircle\non the\n\nright of the imaginary axis, tends to zero as the radius of the\nsemicircle tends to infinity, provided the lower bound of the distance\nof the serai- circle from the poles of the integrand is positive (not\nzero).\n\nTherefore Tf,,..(.) = - r(,,, +)r(-yfc + m + f) '\n\nwhere SR' denotes the sum of the residues of F(s) at its poles on the\nright of the contour (cf.\\hardsectionref{14}{5}) which occurs in equation (C) of §\n16*4.\n\nEvaluating these residues we find without difficulty that, when\n\nI arg 2 : < I TT, and 2m is not an integer*,\n\n,,, T(-2m),.,, r(2m),,,\n\nExample 1. Shew that, when | arg ( -s) | <|7r and 2m is not an\ninteger,\n\n\\addexamplecitation{Earnest.} Example 2. AVhen - -stt < arg s < f tt and - f tt < arg ( -\n) < tt, shew that\n\n* When 1m is an integer some of the poles are generally double poles,\nand their residues involve logarithms of z. The result has not been\nproved when fe- |i 7h. is a positive integer or zero, but may be\nobtained for such values of k and m by comparing the terminating\nseries for ')t,m (2) with the series for Mj.±, (2).\n\nt Barnes' results are given in the notation explained in \\hardsectionref{16}{1}.\n\n%\n% 347\n%\n\nExample 3. Obtain Kummer's first formula \\hardsubsectionref{16}{1}{1}) from the result\n\nTODO \\addexamplecitation{Barnes.}\n\nInl J -xi\n\n\\Section{16}{5}{The parabolic cylinder functions. Weber's equation}\n\nConsider the differential equation satisfied by TODO it is\n\nTODO\n\nthis reduces to TODO\n\nTherefore the function satisfies the differential equation\n\nAccordingly Dn(z) is one of the functions associated with the\nparabolic cylinder in harmonic analysis*; the equation satisfied by it\nwill be called Weber's equation.\n\nFrom \\hardsubsectionref{16}{4}{1}, it follows that\n\nQ\n\nwhen I arg z < -tt.\n\nBut\n\nz\n\n4 -i\n\nand these are one-valued analytic functions of z throughout the\nTODO-plane. Accordingly Dn (z) is a one-valued function of z\nthroughout the TODO-plane; and,\n\nby \\hardsectionref{16}{4}, its asymptotic expansion when arg  < - tt is\n\nTODO\n\n\\Subsection{16}{5}{1}{The second solution of Weber's equation.}\n\nSince Weber's equation is unaltered if we simultaneously replace n and\nz by - n - 1 and + iz respectively, it follows that Dn-i (iz) and\nD-n-i (- iz) are solutions of Weber's equation, as is also Dn (- z).\n\n* Weber, Math. Ann. i. (1869), pp. 1-36; Whittaker, Proc, London Math.\nSoc. xxxv. (1903), pp. 417-427.\n\n%\n% 348\n%\n\nIt is obvious from the asymptotic expansions of Dn\\{z) and\nZ)i(2e'*), valid in the range -  tt < arg z < -ir, that the\nratio of these two solutions is not a constant.\n\n16'511. The relation between the functions Dn\\{z), Dn (+ iz).\n\nFrom the theory of linear diiSerential equations, a relation of the\nform Dn \\{z) = aDn-i \\{iz) + h Di (- iz) must hold when the\nratio of the functions on the right is not a constant.\n\nTo obtain this relation, we observe that if the functions involved be\nexpanded in ascending powers of z, the expansions are\n\nH i=nr - 1 -  - z + ... ■\n\nComparing the first two terms we get\n\na = (27r) - * r (w + 1) e'''' h = (27r) \"  T (w + 1) e \" and so\n\nr(n + l)\n\nI>n\\{z) =\n\nTODO\n\n\\Subsection{16}{5}{2}{The general asymptotic expansion of Dn \\{z). }\nSo far the\nasymptotic expansion of D (z) for large values of z has only\n\nbeen given (§ ] 6*5) in the sector arg z < jTt. To obtain its form for\nvalues\n\nof arg z not comprised in this range we write - iz for z and -n - 1\nfor 7i in the formula of the preceding section, and get\n\nTODO\n\nNow, if TODO, we can assign to TODO and TODO arguments between\n\nTODO + J TT; and arg (- z) = arg z - ir, arg (- iz) = arg z - tt;\nand then, applying the asymptotic expansion of \\hardsectionref{16}{5} to Dn\\{- z) and\nDn-i\\{-iz), we see that, TODO\n\n%\n% 349\n%\n\nThis formula is not inconsistent with that of \\hardsectionref{16}{5} since in their\ncommon range of validity, viz. TODO for all positive values of w.\n\nTo obtain a formula valid in the range TODO, we use the formula\n\nand we get an asymptotic expansion which differs from that which has\njust been obtained only in containing e\"\"'' in place of e'\"'.\n\nSince Dn(z) is one-valued and one or other of the expansions obtained\nis valid for all values of arg z in the range - tt  arg z tt, the\ncomplete asymptotic expansion of i) (z) has been obtained.\n\n\\Section{16}{6}{A contour integral for Dn(z)}\n\nTODO Consider TODO, where TODO; it represents a one-valued\n\nanalytic function of z throughout the -plane \\hardsubsectionref{5}{3}{2}) and further\n\nthe differentiations under the sign of integration being easily\njustified; accordingly the integral satisfies the differential\nequation satisfied by e \\~ i Z) (2); and therefore\n\ne-'- e-'f-i-t)-'-'dt = aB\\{z) + bDi\\{iz),\n\nwhere a and b are constants.\n\nNow, if the expression on the right be called E (2)5 we have\n\nEn\\{0)= e-¥\\{-t)--dt, En'\\{0)= e-¥-t)-dt.\n\nTo evaluate these integrals, which are analytic functions of n, we\nsuppose first that R \\{n) <0; then, deforming the paths of\nintegration, we get\n\nTODO\n\nSimilarly TODO.\n\nBoth sides of these equations being analytic functions of TODO, the\nequations are true for all values of n; and therefore\n\nTODO\n\nTherefore TODO.\n\n%\n% 350\n%\n\n\\Subsection{16}{6}{1}{Recurrence formulae for Dn \\{z). }\nFrom the equation\n\nafter using \\hardsectionref{16}{6}, we see that\n\nDn+, (z) - z Dn (z) + n Dn-, \\{z) = 0. Further, by differentiating the\nintegral of \\hardsectionref{16}{6}, it follows that\n\nD \\{z) + zDn \\{z) - nDn-, \\{z) = 0. Example. Obtain these results\nfrom the ascendiug power series of \\hardsectionref{16}{5}.\n\n\\Section{16}{7}{Properties of Dn (z) when n is an integer}\n\nWhen n is an integer, we may write the integral of \\hardsectionref{16}{6} in the form\n\nTODO\n\nIf now we write t = v - z, we get\n\nTODO\n\na result due to Hermite*.\n\nAlso, if m and n be unequal integers, we see from the differential\nequations that\n\nDn \\{z) Dm\" (z) - D, \\{z) Dn\" (z) + (m - n) Dm (z) Dn (z) = 0, and so\n\nDn\\{z)DJ\\{z)-Dm(z)Dn'\\{z)\n\n\\{m - 71) I Di (z) Dn (z) dz =\n\nJ -ex\n\n= 0,\n\nby the expansion of \\hardsectionref{16}{5} in descending powers of z (which terminates\nand is valid for all values of arg z when n is a positive integer).\n\nTherefore if m and n are unequal positive integers\n\nD,iz)Dn\\{z)dz=0.\n\n■>\n\nComptes Rendus, lviii. (1864), pp. 266-273.\n\n%\n% 351\n%\n\nOn the other hand, when 7n = n, we have\n\nJ - cc\n\n= D, (Z) Dn+, (Z)] + I \\l zDn iz) D,,, \\{Z) - Dn+ (z) D' (z) dz\n\n=r [D,,\\{z)Ydz,\n\nJ -X\n\non using the recurrence formula, integrating by parts and then using\nthe recurrence formula again.\n\nIt follows by induction that\n\nf \\{Dr,(z)Y-dz = nir [D,\\{z)Ydz\n\nJ -CO\n\n= (27r)n!, by \\hardsubsectionref{12}{1}{4} corollary 1 and \\hardsectionref{12}{2}.\n\nIt follows at once that if, for a function /(), an expansion of the\nform\n\n/(z) = aoDo (z) + a, D,\\{z)+... + aDn \\{z)+ ...\n\nexists, and if it is legitimate to integrate term-by-term between the\nlimits - oc and oo, then\n\nTODO\n\nREFERENCES.\n\nW. Jacobsthal, Math. Ann. LVi. (1903), pp. 129-154.\n\nE. W. Barnes, Trans. Camb. Phil. Soe. xx. (1908), pp. 253-279.\n\nE. T. Whittaker, Bulletin American Math. Soc. x. (1904), pp. 125-134.\n\nH. Weber, Math. Ann. i. (1869), pp. 1-36.\n\nA. Adamoff, Ann. de VInstitut Polytechnique de St Petershourg, v.\n(1906), pp. 127-143.\n\nE. T. Whittaker, Proc. London Math. Soc. xxxv. (1903), pp. 417-427.\n\nG. N. Watson, Proc. London Math. Soc. (2), viii. (1910), pp. 393-421;\nxvn. (1919), pp. 116-148.\n\nH. E. J. CuRZON, Proc. London Math. Soc. (2), xii. (1913), pp.\n236-259.\n\nA. Milne, Proc. Edinburgh Math. Soc. xxxii. (1914), pp. 2-14; xxxill.\n(1915), pp. 48-64.\n\nN. Nielsen, Meddelelser K. Danske Videnskabernes Selskab, i. (1918),\nno. 6.\n\n%\n% 352\n%\n\nMiscellaneous Examples.\n\n1. Shew that, if the integral is convergent, then\n\nTODO\n\n2. Shew that TODO\n\n3. Obtain the recurrence formulae\n\n4. Prove that Ht,,1(2) is the integral of an elementary function when\neither of the numbers k-h + m is a negative integer,\n\n5. Shew that, by a suitable change of variables, the equation can be\nbrought to the form\n\n\\{a.2 + b2.v) + \\{ai + biX)-£ + \\{ao + box)i/ =\n\nderive this equation from the equation for F\\{a, b; c; x) by writing x\n= lb and making 6-*-« .\n\n6. Shew that the cosine integral of Schlomilch and Besso \\{Oiornale di\nMatematiche, VI.), defined by the equation\n\nTODO\n\nis equal to TODO\n\nShew also that Schlomilch's function, defined \\{Zeitschrift filr Math,\nund Physik, iv. (1859), p. 390) by the equations\n\nS\\{v,z)=j \\{l + t)-''e-'dt = z''-e' I du,\n\nis equal to i\" - 1 i W  1  1  1  (2).\n\n7. Express in terms of W,ci functions the two functions\n\nTODO\n\nJot J z t\n\n8. Shew that Sonine's polynomial, defined \\{Math. Ann. xvi. p. 41) by\nthe equation TODO\n\nis equal to TODO\n\n%\n% 353\n%\n\n9. Shew that the function TODO defined by Lagrange in 1762-1765\n\\{Oeuv)-es, i. p. 520) and by Abel (Oeuvres, 1881, p. 284) as the\ncoefficient of /('*' in the expansion of (1 - A)-i e-''Mi-ft) is eqnal\nto\n\n10*. Shew that the Pearson-Cunningham function \\{Proc. Royal Soc.\nLxxxi. p. 310), <>>n,m (■')) defined as\n\nT\\{n\n\nn- hm\n\nis equal to  TODO\n\n11. Shew that, if | arg z < n, and | arg (1 + ) | < tt,\n\n\\addexamplecitation{Whittaker.}\n\n12. Shew that, if n be not a positive integer and if ! arg z < frr,\nthen\n\nTODO\n\nand that this result holds for all values of args if the integral be /\n, the contours enclosing the poles of r ( - but not those of r \\{t\n-n).\n\n13. Shew that, if j arg a | < it,\n\nJ tc\n\n= - r, n(-*\". hn-¥i<;hn-hn + - l-ia-).\n\nr(-w)r(m-i + l)aH'+i)\n\n14. Deduce from example 13 that, if the integral is convergent, then\n\n|J e - i'' z\"\"' A«+i (2) c/2 = (v/2)-i-'\" r (i + 1) sin ( - \\{m) n.\n\n\\addexamplecitation{Watson.}\n\n15. Shew that, if n be a positive integer, and if\n\nE, \\{x) = T J- '' \\{z - .v) - 1 n,, (z) dz,\n\nthen TODO.\n\nthe upper or lower signs being taken according as the imaginary part\nof x is positive or negative. \\addexamplecitation{Watson.}\n\n16. Shew that, if n be a positive integer,\n\nTODO\n\nJo sm\n\nwhere fi is n or J(n- 1), whichever is an integer, and the cosine or\nsine is taken as n is even or odd. \\addexamplecitation{AdamoflF.}\n\n* The results of examples 8, 9, 10 were communicated to us by Mr\nBateman. W. M. A. 23\n\n%\n% 354\n%\n\n17. Shew that, if n be a positive integer,\n\nwhere TODO\n\nTODO \\addexamplecitation{Adamoff}\n\n18. With the notation of the preceding examples, shew that, when x is\nreal,\n\nTODO\n\nwhile Ja satisfies both the inequalities\n\nTODO\n\nShew also that as v increases from to 1, o- (/') decreases from to a\nminimum at- TODO and then increases to at i'=l; and as v increases\nfrom 1 to $\\infty$, o-(v) increases to a maximum at l + /?2 and then\ndecreases, its limit being zero; where\n\nTODO \\addexamplecitation{Adamoff.}\n\n19. By employing the second mean value theorem when necessary, shew\nthat\n\nA.(.') = V2.(v'0 e\n\ncos(.r«2 -:-)iTr) + '\n\ns'n J'\n\nwhere co,j(.r) satisfies both the inequalities\n\nI X I 'TT D\n\nwhen X is real and n is an integer greater than 2. \\addexamplecitation{AdamofF.}\n\n3-35... ia;2,,,, .1 i\n\n20. Shew that, if n be positive but otherwise unrestricted, and if m\nbe a positive integer (or zero), then the equation in z\n\nhas m positive roots when TODO. \\addexamplecitation{Milne.}", "meta": {"hexsha": "a9b002fafb503be505f7140fa207e4c69b983c53", "size": 25310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch16.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-ch16.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-ch16.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.4884189325, "max_line_length": 154, "alphanum_fraction": 0.6932042671, "num_tokens": 8022, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321843145404, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6798690548033592}}
{"text": "\\section{More inductive types}\n\nAnalogous to the type of natural numbers, many types can be specified as inductive types. In this section 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}\n\\index{unit type|(}\n\\index{inductive type!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} to be a closed type $\\unit$\\index{unit type!is a closed type} 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}\\index{unit type!induction principle} that for any type family of types $P(x)$ indexed by $x:\\unit$, there is a term\\index{ind 1@{$\\indunit$}}\\index{unit type!indunit@{$\\indunit$}}\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}\\index{unit type!computation rules}\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 $\\pt_x\\defeq\\indunit(x):\\unit\\to A$.\\index{ptx@{$\\pt_x$}}\n\\index{unit type|)}\n\\index{inductive type!unit type|)}\n\n\\subsection{The empty type}\n\\index{empty type|(}\n\\index{inductive type!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}} to be a type $\\emptyt$ satisfying the induction principle\\index{induction principle!of empty type}\\index{empty type!induction principle} that for any family of types $P(x)$ indexed by $x:\\empty$, there is a term\\index{ind 0@{$\\indempty$}}\\index{empty type!indempty@{$\\indempty$}}\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}\\index{negation!of types}\\index{neg (A)@{$\\neg A$}|see {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}\\index{proof of negation}. Proofs of negation are not to be confused with \\emph{proofs by contradiction}\\index{proof 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\\index{empty type|)}\n\\index{inductive type!empty type|)}\n\n\\subsection{The booleans}\n\\index{booleans}\n\\index{inductive type!booleans}\n\n\\begin{defn}\nWe define the \\define{booleans}\\index{2 @{$\\bool$}|see {booleans}} to be a type $\\bool$ that comes equipped with\\index{booleans!btrue@{$\\btrue$}}\\index{booleans!bfalse@{$\\bfalse$}}\\index{0 2@{$\\bfalse$}}\\index{1 2@{$\\btrue$}}\n\\begin{align*}\n\\bfalse & : \\bool \\\\\n\\btrue & : \\bool\n\\end{align*}\nsatisfying the induction principle\\index{induction principle!of booleans}\\index{booleans!induction principle} that for any family of types $P(x)$ indexed by $x:\\bool$, there is a term\\index{ind 2@{$\\indbool$}}\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}\\index{booleans!computation rules}\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}\\label{eg:boolean-ops}\n  \\index{boolean operations|(}\\index{boolean logic|(}\n  Using the induction principle of $\\bool$ we can define all the operations of Boolean algebra\\index{boolean algebra}. For example, the \\define{boolean negation}\\index{booleans!negation} operation $\\negbool : \\bool \\to \\bool$\\index{negation function!on booleans}\\index{neg 2@{$\\negbool$}}\\index{booleans!neg 2@{$\\negbool$}} is defined by\n  \\begin{align*}\n    \\negbool(\\btrue) & \\defeq \\bfalse & \\negbool(\\bfalse) & \\defeq \\btrue.\n  \\end{align*}\n  The \\define{boolean conjunction}\\index{booleans!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}\\index{booleans!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 defining the boolean operations by the induction principle of $\\bool$ is not that different from defining them by truth tables\\index{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.\\index{boolean operations|)}\\index{boolean logic|)}\n\\end{eg}\n\\index{booleans|)}\n\\index{inductive type!booleans|)}\n\n\\subsection{Coproducts and the type of integers}\n\\index{coproduct|(}\n\\index{inductive type!coproduct|(}\n\\begin{defn}\nLet $A$ and $B$ be types. We define the \\define{coproduct}\\index{disjoint sum|see {coproduct}} $A+B$\\index{A + B@{$A+B$}|see {coproduct}} to be a type that comes equipped with\\index{inl@{$\\inl$}}\\index{coproduct!inl@{$\\inl$}}\\index{inr@{$\\inr$}}\\index{coproduct!inr@{$\\inr$}}\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}\\index{coproduct!induction principle} that for any family of types $P(x)$ indexed by $x:A+B$, there is a term\\index{ind +@{$\\ind{+}$}}\\index{coproduct!ind+@{$\\ind{+}$}}\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}\\index{coproduct!computation rules}\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\n\\index{integers|(}\nAn important example of a type that can be defined using coproducts is the type $\\Z$ of integers.\\index{coproduct!Z@{$\\Z$}}\n\n\\begin{defn}\n  We define the \\define{integers}\\index{Z@{$\\Z$}|see {integers}} to be the type $\\Z\\defeq\\N+(\\unit+\\N)$. The type of integers comes equipped with inclusion functions of the positive and negative integers\\index{integers!in-pos@{$\\inpos$}}\\index{integers!in-neg@{$\\inneg$}}\n  \\begin{align*}\n    \\inpos & \\defeq \\inr\\circ\\inr \\\\\n    \\inneg & \\defeq \\inl,\n  \\end{align*}\n  which are both of type $\\N\\to\\Z$, and the constants\\index{integers!-1 Z@{$-1_\\Z$}}\\index{integers!0 Z@{$0_\\Z$}}\\index{integers!1 Z@{$1_\\Z$}}\\index{-1 Z@{$-1_\\Z$}}\\index{0 Z@{$0_\\Z$}}\\index{1 Z@{$1_{\\Z}$}}\n  \\begin{align*}\n    -1_\\Z & \\defeq \\inneg(0)\\\\\n    0_\\Z & \\defeq \\inr(\\inl(\\ttt))\\\\\n    1_\\Z & \\defeq \\inpos(0).\n  \\end{align*}\n\\end{defn}\n\nIn the following lemma we derive an induction principle\\index{induction principle!of Z@{of $\\Z$}}\\index{integers!induction principle} 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(\\inneg(n))\\to P(\\inneg(\\succN(n)))\\\\\n    p_{0} & : P(0_\\Z) \\\\\n    p_{1} & : P(1_\\Z) \\\\\n    p_{S} & : \\prd{n:\\N}P(\\inpos(n))\\to P(\\inpos(\\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:\\index{integers!computation rules}\\index{computation rules!of Z@{of $\\Z$}}\n  \\begin{align*}\n    f(-1_\\Z) & \\jdeq p_{-1} \\\\\n    f(\\inneg(\\succN(n))) & \\jdeq p_{-S}(n,f(\\inneg(n))) \\\\\n    f(0_\\Z) & \\jdeq p_{0} \\\\\n    f(1_\\Z) & \\jdeq p_{1} \\\\\n    f(\\inpos(\\succN(n))) & \\jdeq p_S(n,f(\\inpos(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 $\\inneg\\jdeq\\inl$ and $-1_\\Z\\jdeq \\inneg(\\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(\\inneg(n))\\to P(\\inneg(\\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$}}\\index{function!succ Z@{$\\succZ$}} on the integers $\\succZ:\\Z\\to\\Z$\\index{succ Z@{$\\succZ$}}\\index{integers!succ Z@{$\\succZ$}} using the induction principle of \\cref{lem:Z_ind}, taking\n\\begin{align*}\n\\succZ(-1_\\Z) & \\defeq 0_\\N \\\\\n\\succZ(\\inneg(\\succN(n))) & \\defeq \\inneg(n) \\\\\n\\succZ(0_\\Z) & \\defeq 1_\\N \\\\\n\\succZ(1_\\Z) & \\defeq \\inpos(1_\\N) \\\\\n\\succZ(\\inpos(\\succN(n))) & \\defeq \\inpos(\\succN(\\succN(n))).\n\\end{align*}\n\\end{defn}\n\\index{integers|)}\n\\index{coproduct|)}\n\\index{inductive type!coproduct|)}\n\n\\subsection{Dependent pair types}\n\n\\index{dependent pair type|(}\n\\index{inductive type!dependent pair type|(}\n\nGiven a type family $B$ over $A$, we may consider pairs $(a,b)$ of terms, where $a:A$ and $b:B(a)$. Note that the type of $b$ depends on the first term in the pair, so we call such a pair a \\define{dependent pair}\\index{dependent pair}.\n\nThe \\emph{dependent pair type} is an inductive type that is generated by the dependent pairs.\n\n\n\\begin{defn}\n  Consider a type family $B$ over $A$.\n  The \\define{dependent pair type} (or $\\Sigma$-type) \\index{Sigma-type@{$\\Sigma$-type}|see {dependent pair type}}is defined to be the inductive type $\\sm{x:A}B(x)$ equipped with a \\define{pairing function}\\index{pairing function}\\index{(-,-)@{$(\\blank,\\blank)$}}\\index{dependent pair type!(-,-)@{$(\\blank,\\blank)$}}\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}}\\index{dependent pair type!induction principle} 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\\index{dependent pair type!indSigma@{$\\ind{\\Sigma}$}}\\index{ind Sigma@{$\\ind{\\Sigma}$}}\n\\begin{equation*}\n\\ind{\\Sigma}:\\Big(\\prd{x:A}\\prd{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}}\\index{dependent pair type!computation rule}\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}\\lam{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}\\index{projection maps!first projection}\\index{dependent pair type!pr 1@{$\\proj 1$}}\\index{pr 1@{$\\proj 1$}}\\index{function!pr 1@{$\\proj 1$}}\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}\\index{projection map!second projection}\\index{dependent pair type!pr 2@{$\\proj 2$}}\\index{pr 2@{$\\proj 2$}}\\index{function!pr 2@{$\\proj 2$}} 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\\index{dependent pair type|)}\n\\index{inductive type!dependent pair type|)}\n\n\\subsection{Cartesian products}\n\n\\index{cartesian product|(}\n\\index{inductive type!cartesian product|(}\nA special case of the $\\Sigma$-type occurs when the $B$ is a constant family over $A$, i.e., when $B$ is just a type.\nIn this case, the inductive type $\\sm{x:A}B(x)$ is generated by \\emph{ordinary} pairs $(x,y)$ where $x:A$ and $y:B$. In other words, if $B$ does not depend on $A$, then the type $\\sm{x:A}B$ is the \\emph{(cartesian) product} $A\\times B$.\nThe cartesian product is a very common special case of the dependent pair type, just as the type $A\\to B$ of ordinary functions from $A\\to B$ is a common special case of the dependent product. Therefore we provide its specification along with the induction principle for cartesian products.\n\n\\begin{defn}\nConsider two types $A$ and $B$. The \\define{(cartesian) product}\\index{product of types}\\index{A x B@{$A\\times B$}|see {cartesian product}} of $A$ and $B$ is defined as the inductive type $A\\times B$ 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}\\index{cartesian product!induction principle} for $A\\times B$ asserts that for any type family $P$ over $A\\times B$, one has\\index{ind times@{$\\ind{\\times}$}}\\index{cartesian product!indtimes@{$\\ind{\\times}$}}\n\\begin{equation*}\n\\ind{\\times} : \\Big(\\prd{x:A}\\prd{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}\\index{cartesian product!computation rule} 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\\index{cartesian product|)}\n\\index{inductive type!cartesian product|)}\n\n\\begin{exercises}\n\\exercise\n  \\index{rules!for unit type}\\index{unit type!rules}\n  \\index{rules!for empty type}\\index{empty type!rules}\n  \\index{rules!for booleans}\\index{booleans!rules}\n  \\index{rules!for coproduct}\\index{coproduct!rules}\n  \\index{rules!for dependent pair type}\\index{dependent pair type!rules}\n  \\index{rules!for cartesian product}\\index{cartesian product!rules}\n  Write the rules for $\\unit$, $\\emptyt$, $\\bool$, $A+B$, $\\sm{x:A}B(x)$, and $A\\times B$. As usual, present the rules in four sets:\n  \\begin{enumerate}\n  \\item A formation rule.\n  \\item Introduction rules.\n  \\item An elimination rule.\n  \\item Computation rules.\n  \\end{enumerate}\n  \\exercise Let $P$ and $Q$ be types. Use the fact that $\\neg P$\\index{negation} is defined as the type $P\\to\\emptyt$ of functions from $P$ to the empty type\\index{empty type}, to give type theoretic proofs of the following taugologies\\index{tautologies} of constructive logic\\index{constructive logic}.\\label{ex:dne-dec}\n  \\begin{subexenum}\n  \\item $P\\to\\neg\\neg P$\n  \\item $(P\\to Q)\\to(\\neg\\neg P\\to\\neg\\neg Q)$\n  \\item $(P+\\neg P)\\to(\\neg\\neg P\\to P)$\n  \\item $\\neg\\neg(P+\\neg P)$\n  \\item $\\neg\\neg(\\neg\\neg P \\to P)$\n  \\item $(P\\to \\neg\\neg Q)\\to (\\neg\\neg P \\to\\neg\\neg Q)$\n  \\item $\\neg\\neg\\neg P \\to \\neg P$\n  \\item $\\neg\\neg(P \\to \\neg\\neg Q)\\to (P\\to\\neg\\neg Q)$\n  \\item $\\neg\\neg((\\neg\\neg P)\\times(\\neg\\neg Q))\\to (\\neg\\neg P)\\times(\\neg\\neg Q)$\n  \\end{subexenum}\n\\exercise \\label{ex:boolean-operation}Define the following operations of Boolean algebra:\\index{boolean algebra}\\index{booleans!exclusive disjunction}\\index{booleans!implication}\\index{booleans!if and only if}\\index{booleans!Peirce's arrow}\\index{booleans!Sheffer stroke}\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\\exercise \\label{ex:int_pred}\\index{integers|(}\\index{predecessor function}\\index{function!pred Z@{$\\predZ$}}\\index{integers!pred Z@{$\\predZ$}}\\index{pred Z@{$\\predZ$}}Define the predecessor function $\\predZ:\\Z\\to \\Z$.\n\\exercise \\label{ex:int_group_ops}\\index{group operations!on Z@{on $\\Z$}}Define the group operations\\index{add Z@{$\\addZ$}}\\index{integers!add Z@{$\\addZ$}}\\index{neg Z@{$\\negZ$}}\\index{integers!neg Z@{$\\negZ$}}\\index{mul Z@{$\\mulZ$}}\\index{integers!mul Z@{$\\mulZ$}}\n  \\begin{align*}\n    \\addZ & : \\Z \\to (\\Z \\to \\Z) \\\\\n    \\negZ & : \\Z \\to \\Z,\n    \\intertext{and define the multiplication}\n    \\mulZ & : \\Z \\to (\\Z \\to \\Z).\n  \\end{align*}\n\\exercise Construct a function $F:\\Z\\to\\Z$ that extends the Fibonacci sequence\\index{Fibonacci sequence}\\index{integers!Fibonacci sequence} to the negative integers\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.\\index{integers|)}\n\\exercise \\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\\exercise \\label{ex:lists}For any type $A$ we can define the type $\\lst(A)$\\index{list A@{$\\lst(A)$}|see {lists in $A$}} of \\define{lists}\\index{lists in A @{lists in $A$}}\\index{inductive type!list A@{$\\lst(A)$}} elements of $A$ as the inductive type with constructors\\index{lists in A@{lists in $A$}!nil@{$\\nil$}}\\index{nil@{$\\nil$}}\\index{cons(a,l)@{$\\cons(a,l)$}}\\index{lists in A@{lists in $A$}!cons@{$\\cons$}}\n  \\begin{align*}\n    \\nil & : \\lst(A) \\\\\n    \\cons & : A \\to (\\lst(A) \\to \\lst(A)).\n  \\end{align*}\n  \\begin{subexenum}\n  \\item Write down the induction principle and the computation rules for $\\lst(A)$.\\index{induction principle!list A@{$\\lst(A)$}}\\index{lists in A@{lists in $A$}!induction principle}\n  \\item Let $A$ and $B$ be types, suppose that $b:B$, and consider a binary operation $\\mu:A\\to (B \\to B)$. Define a function\\index{fold-list@{$\\foldlist$}}\\index{lists in A@{lists in $A$}!fold-list@{$\\foldlist$}}\n    \\begin{equation*}\n      \\foldlist(\\mu) : \\lst(A)\\to B\n    \\end{equation*}\n    that iterates the operation $\\mu$, starting with $\\foldlist(\\mu,\\nil)\\defeq b$.\n  \\item Define a function $\\lengthlist:\\lst(A)\\to\\N$.\\index{length-list@{$\\lengthlist$}}\\index{lists in A@{lists in $A$}!length-list@{$\\lengthlist$}}\n  \\item Define a function\\index{sum-list@{$\\sumlist$}}\\index{lists in A@{lists in $A$}!sum-list@{$\\sumlist$}}\n    \\begin{equation*}\n      \\sumlist : \\lst(\\N) \\to \\N\n    \\end{equation*}\n    that adds all the elements in a list of natural numbers.\n  \\item Define a function\\index{concat-list@{$\\concatlist$}}\\index{lists in A@{lists in $A$}!concat-list@{$\\concatlist$}}\\index{concatenation!of lists}\n    \\begin{equation*}\n      \\concatlist : \\lst(A) \\to (\\lst(A) \\to \\lst(A))\n    \\end{equation*}\n    that concatenates any two lists of elements in $A$.\n  \\item Define a function\\index{flatten-list@{$\\flattenlist$}}\\index{lists in A@{lists in $A$}!flatten-list@{$\\flattenlist$}}\n    \\begin{equation*}\n      \\flattenlist : \\lst(\\lst(A)) \\to \\lst(A)\n    \\end{equation*}\n    that concatenates all the lists in a lists of lists in $A$.\n  \\item Define a function $\\reverselist : \\lst(A) \\to \\lst(A)$ that reverses the order of the elements in any list.\\index{reverse-list@{$\\reverselist$}}\\index{lists in A@{lists in $A$}!reverse-list@{$\\reverselist$}}\n  \\end{subexenum}\n\\end{exercises}\n", "meta": {"hexsha": "b104217b911d5340f227e969351d53e039a1c3cc", "size": 24003, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/inductive.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/inductive.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/inductive.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": 59.2666666667, "max_line_length": 458, "alphanum_fraction": 0.6979544224, "num_tokens": 7907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895098628499, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6798690536095211}}
{"text": "% !TEX root = scombinatorics.tex\n\\documentclass[scombinatorics.tex]{subfiles}\n\\begin{document}\n\\chapter{Small transversals}\n\\label{fractional}\n\n\\def\\medrel#1{\\parbox[t]{5ex}{$\\displaystyle\\hfil #1$}}\n\\def\\ceq#1#2#3{\\parbox[t]{23ex}{$\\displaystyle #1$}\\medrel{#2}{$\\displaystyle #3$}}\nUnlike the rest of these notes, this chapter is not self contained, as it relies on the duality of linear programming.\nThe reader can use the result as a black box.\nOtherwise, we recommend~\\cite{LPmatousek}*{Chapter 6}, a lively and conceptual introduction to linear programming (a rarity for an otherwise rather dry subject).\n\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Transversals and packings}\\label{Transversals_Packings}\n\nLet $\\phi(x\\,;z)$ be given. \nLet $A\\subseteq\\U$ and $B\\subseteq\\V$ be finite sets. \n%(It seems that most of the section smoothly generalizes to rational valued formulas and multisets, see below.)\n\nA subset $A'\\subseteq A$ is a \\emph{transversal\\/} if $\\phi(A',b)\\neq\\0$ for every $b\\in B$. Equivalently, if the sets $\\phi(a,B)_{a\\in A'}$ cover $B$, i.e.\n\n\\ceq{\\hfill B}\n{=}\n{\\bigcup_{a\\in A'}\\phi(a,B).}\n\nThe \\emph{transversal number\\/} is the smallest cardinality of a transversal $A'$.\nIt denoted by \\emph{$\\tau$.} \n\nA subset $B'\\subseteq B$ is a \\emph{packing\\/} if $\\phi(A,b)\\cap\\phi(A,b')=\\0$ for every distinct $b,b'\\in B'$. Equivalently if $|\\phi(a,B')|\\le1$ for every $a\\in A$.\nThe \\emph{packing number\\/} is the largest cardinality of a packing $B'$.\nIt is denoted by \\emph{$\\nu$.}\n\nWe may write \\emph{$\\tau_{\\phi(A,B)}$} and  \\emph{$\\nu_{\\phi(A,B)}$} when ambiguity is of concern. \n\nIf $A'$ is a transversal and $B'\\subseteq B$, then the sets $\\phi(a,B')_{a\\in A'}$ cover $B'$.\nNow, suppose $B'$ is a packing, then these sets contain at most one element, hence $|B'|\\le|A'|$.\nTherefore, we always have $\\nu\\le\\tau$.\nVery little can be said in general about the reverse direction.\n\n\\begin{example}\\label{expl_tr_pk}\n  Let $\\U=\\RR^2$ and $\\V$ is the set of lines in $\\RR^2$.\n  Let $\\phi(x\\,;z)$ be the incidence (that is, membership) relation.\n  Let $A\\subseteq\\U$ and let $B\\subseteq\\V$ be a set of $n$ lines in generic position\n  (any to lines intersect and every point is contained in at most two lines).\n  Then $\\tau=\\lceil n/2\\rceil$, as each point belongs to at most two lines, while $\\nu=1$, as any two lines intersect.\\QED\n\\end{example}  \n\n\nA (fractional) multiset over $\\U$ is a real-valued function $A':\\U\\to\\RR$.\nThe support \\emph{support} of a multiset $A'$ is the set where it takes nonzero values.\nIn this chapter will only consider nonnegative multisets with finite support.\nThese can be interpreted as measures concentrated on a finite set.\n\nIf $A'':\\U\\to\\RR$ is another multiset, we write \\emph{$A'\\cdot A''$\\/} for the pointwise product of the two. \nWe write \\emph{$A'\\le A''$\\/} if $A'(a)\\le A''(a)$ for every $a\\in \\U$.\n\nWe define the \\emph{size\\/} of $A'$ to be\\smallskip \n\n\\ceq{\\hfill\\emph{$|A'|$}}\n{=}\n{\\sum_{a\\in\\U}A'(a)}\n\nWe write \\emph{$\\phi(A',b)$\\/} for the multiset $A'\\cdot\\Indicator_{\\phi(\\U,b)}$.\n\nMultisets over $\\V$ are defined analogously.\n \n%seiIf $A'$ and $A''$ are multisets we write $A'\\le A''$ if $A'(a)\\le A''(a)$ holds for every $a$.\nA \\emph{fractional transversal\\/} is a multiset $A'\\le\\Indicator_A$ such that $|\\phi(A', b)|\\ge1$ for every $b\\in B$.\nThe \\emph{fractional transversal number\\/} of $\\phi(x\\,;z)$, denoted by $\\tau^*$, is the  infimum of the size of the fractional transversals of $\\phi(x\\,;z)$.\n\nA fractional multiset $B'\\le\\Indicator_B$ over $\\V$ is a \\emph{fractional packing\\/} if $|\\phi(a,B')|\\le1$ for every $a\\in A$.\nThe \\emph{fractional packing number\\/} of $\\phi(x\\,;z)$, denoted by $\\nu^*$, is the supremum of the size of the fractional packings of $\\phi(x\\,;z)$.\n\n\\begin{example}\n  The sets $\\U,\\V$ and the relation $\\phi(A\\,;B)$ are as in the example~\\ref{expl_tr_pk}.\n  Let $B'$ be a multiset that assigns $1/2$ to every line in $B$. Then $|\\phi(a,B')|\\le1$ holds because each point is contained in at most two lines.\n  Then $\\nu^*\\ge |B'|=n/2$.\n  It is easy to see that $\\tau^*\\ge n/2$.\n  We claim that $\\tau\\le n/2$.\n  If $n$ is even, use the same transversal $A'$ as in Example~\\ref{expl_tr_pk} is even.\n  If $n$ is odd, take $3$ any lines, and assign $1/2$ to the three intersection points.\n  Proceed as in the even case with the other lines.\\QED\n\\end{example}\n\n\\begin{exercise}\nLet $\\U=\\RR$ and $\\V$ is a set of finitely many closed intervals.\nLet $\\phi(x\\,;z)$ be the membership relation.\nThen $\\nu=\\tau$.\nHint: use induction on $\\nu$.\\QED\n\\end{exercise}\n\n\\begin{theorem}\\label{thm_fractional_nu=tau}\n For all $\\phi(x\\,;z)$ and all finite sets $A\\subseteq\\U$ and $B\\subseteq\\V$, we have $\\nu^*=\\tau^*$ and this value is rational.\n\\end{theorem}\n\\begin{proof}\nLet $A=\\{a_1,\\dots,a_m\\}$ and $B=\\{b_1,\\dots,b_n\\}$.\nLet $F$ be the $m\\times n$-matrix with entries $\\Indicator_{\\phi(a_i,b_j)}$.\nA multi-set over $A$ is a naturally associated to a vector $0\\le x\\in\\RR^m$.\nA multi-set over $B$ is associated to a vector $0\\le y\\in\\RR^n$.\nThen it is easy to verify that\n\n\\ceq{\\hfill\\tau^*}\n{=}\n{\\inf\\,\\big\\{\\,1_m^{\\rm T}\\;x\\ :\\ F^{\\rm T}\\,x\\ge 1_n,\\ 0\\le x\\};}\n\n\\ceq{\\hfill\\nu^*}\n{=}\n{\\sup\\big\\{\\,1_n^{\\rm T}\\ y\\,\\  :\\ \\ F\\,y\\le 1_m,\\,\\  0\\le y\\}.}\n\nTherefore, by he duality of linear programming $\\nu^*=\\tau^*$.\n\nAs $\\tau^*$ is the minimum of the linear function $x\\mapsto 1_m^{\\rm T}\\;x$ over a polyhedron, such minimum is attained at vertex.\nThe inequalities describing the polyhedron have rational coefficients, so also the vertices have rational coordinates (elaborate on this).\n\\end{proof}\n\nWhen $\\phi(x\\,;z)$ has finite \\vc-dimension, the transversal number $\\tau$ is bounded by a function of $\\tau^*$. \n\n\\begin{proposition}\\label{prop_bound_fractional_trans}\n  Let $\\phi(x\\,;z)$ have \\vc-dimension $k$.\n  Then for all finite sets $A\\subseteq\\U$ and $B\\subseteq\\V$\n  \n  \\ceq{\\hfill\\tau}{\\le}{ c\\,k\\,(\\tau^*)^2\\,\\ln (k\\,\\tau^*)}\n  \n  where $c$ is an absolute constant.\n\\end{proposition}\n  \n\\begin{proof}\n  Let $A'$ be an optimal fractional transversal.\n  After normalizing, $A'$ defines a probability measure $\\Pr$ on $\\U$.\n  Namely, $\\Pr(\\{a\\})=A'(a)/\\tau^*$ for $a\\in\\U$.\n  By the definition of fractional transversal, every set $\\phi(A\\,;b)_{b\\in B}$ has measure at last $1/\\tau^*$.\n  By Proposition~\\ref{prop_vc_sample}, for every $\\epsilon>0$ there is a sample $s$ of size\n  \n  \\ceq{\\hfill n}\n  {\\le}\n  {c\\,\\frac{k}{\\epsilon^2}\\log\\frac{k}{\\epsilon}}\n\n  If we set $\\epsilon=1/\\tau^*$, then $\\range(s)$ is a transversal and we obtain the required bound.\n\\end{proof}\n\nThe bound in the proposition above can be improved.\nOne can replace $(\\tau^*)^2$ with  $\\tau^*$ at the cost of a more difficult proof.\n\n\\section{Helly-type properties}\n\nWe now investigate methods of bounding $\\tau^*=\\nu^*$.\nAs motivation we cite a classical theorem of Helly.\n\n\\begin{proposition}[(Helly Theorem)]\nLet $\\Phi$ be a finite family of convex sets in $\\RR^d$.\nAssume that any $d+1$ sets from $\\Phi$ have non-empty intersection.\nThen the whole family $\\Phi$ has non-empty intersection.\\QED\n\\end{proposition}\n\nNote that Helly's theorem does not hold for families of finite \\vc-dimension.\nA counter example of \\vc-dimension $2$ can be constructed with a family containing sets that are unions of two finite intervals of the real line.\n\nWe will deal with the following property, which is more robust. It says that if there is \\textit{plenty\\/} of \\textit{small\\/} collections of sets with nonempty intersection, then there is a \\textit{large\\/} collection with nonempty intersection.\n\n\\begin{definition}\nWe say that $\\phi(x\\,;z)$ \\emph{has fractional Helly number $k$\\/} if for all $\\alpha>0$ there is a $\\beta>0$ such that  for every finite $A\\subseteq\\U$ and $B\\subseteq\\V$ the following holds (write $n$ for $|B|$):\n\n\\ceq{(1)\\hfill \\bigcap_{b\\in B'}\\phi(A,b)}{\\neq}{\\0}\\hfill for at least \\ $\\displaystyle\\alpha{n\\choose k}$ \\ sets \\ $\\displaystyle B'\\in{B\\choose k}$\n\nthen\n\n\\ceq{(2)\\hfill\\bigcap_{b\\in B''}\\phi(A,b)}{\\neq}{\\0}\\hfill for some $B''\\subseteq B$ of cardinality $\\ge\\beta\\,n$.\n\nWe say that $\\phi$ has the \\emph{fractional Helly property\\/} if it has fractional Helly number $k$ for some finite $k$.\nThe \\emph{fractional Helly number\\/} of $\\phi(x\\,;z)$ is the smallest number $k$ satisfying the property above.\\QED\n\\end{definition}\n\nFor further reference, we note that (2) in the definition above can be rewritten as \n\n\\ceq{(2$'$)\\hfill\\big|\\phi(a,B)\\big|}{\\geq}{\\beta\\,n}\\hfill for some $a\\in A$.\n\nThe following theorem proves that \\nip{} formulas have the fractionally Helly property (in a strong sense).\n\n\\begin{theorem}[(Matou\\v{s}ek)]\\label{thm_matousek}\nLet  $\\phi(x\\,;z)$ have \\vc-codimension $<k$.\nThen $\\phi(x\\,;z)$ has fractional Helly number $k$.\nMoreover, $\\beta$ in the definition above only depends on $\\alpha$ and $k$.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\alpha$ be arbitrary and set $\\beta=1/2m$ where $m$ is such that \n\n\\ceq{\\hfill \\bigsum^{k-1}_{i=0} \\binom{m}{i}}{<}{\\frac\\alpha4{m\\choose k}.}\n\nNote that, by the Sauer-Shelah Lemma~\\ref{lem_sauer}, the r.h.s.\\@ is strictly larger than $\\pi^*_\\phi(m)$ for all $\\phi(x\\,;z)$ with \\vc-codimension $<k$.\n\nAssume for a contradiction that some finite $A\\subseteq\\U$ and $B\\subseteq\\V$ contradicts the definition above.\nThat is,\n \n\\ceq{(1)\\hfill \\bigcap_{b\\in B'}\\phi(A,b)}{\\neq}{\\0}\\hfill for at least \\ $\\displaystyle\\alpha{n\\choose k}$ \\ sets \\ $\\displaystyle B'\\in{B\\choose k}$\n\nand\n\n\\ceq{(2)\\hfill\\big|\\phi(a\\,;B)\\big|}{<}{\\beta\\,n}\\hfill for all $a\\in A$.\n\nNote that we can assume that $n>2m$ otherwise $\\beta\\,n<1$ and (2) never occur.\nWe will find a set $B''\\subseteq B$ of cardinality $m$ with more than $\\pi^*(m)$ distinct $\\phi(x\\,;z)^{\\rm op}$-definable subsets, a contradiction.\n\nLet $P$ be the set of pairs $B'\\subseteq B''\\subseteq B$ such that $|B'|=k$ and $|B''|=m$.\nWe say that a pair $B'\\subseteq B''$ in $P$ is \\textit{good\\/} if there is $a\\in A$ such that $B'=\\phi(a\\,;B'')$.\nThat is, $B'$ is a $\\phi(x\\,;z)^{\\rm op}$-definable subset of $B''$.\n\nClaim 1. \nAssume the uniform probability on $P$.\nThen the probability that a random pair is good is $\\ge\\alpha/4$.\n\nAssume Claim~1 for now and continue with the proof.\nWe can think that the random pair in $P$ is chosen by first picking $B''\\in{B\\choose m}$ with the uniform distribution and than $B'\\in{B''\\choose k\\phantom{'}}$ again with the uniform distribution. \n(To put it more pedantically, we are applying the theorem of total probability.)\nIf the the probability that a pair is good is $\\ge\\alpha/4$, then for at least one $B''\\in{B\\choose m}$ the probability of finding a good subset $B'$ is $\\ge\\alpha/4$.\nTherefore, $B''$ has $\\ge\\frac\\alpha4{m\\choose k}>\\pi^*(m)$ good subsets.\nA contradiction which proves the theorem given the claim.\n\nWe now prove the claim.\nThere is another equivalent way to pick a random pair in $P$.\nFirst we choose at random $B'\\subseteq B$ of cardinality $k$ then obtain $B''$ by adding $m-k$ random elements from $B\\sm B'$.\nBy (1), the probability that $B'$ is such that $\\bigcap_{b\\in B'}\\phi(A,b)\\neq\\0$ is at least $\\alpha$.\nSo, assume that $B'$ is such, and fix any $a$ is this intersection.\nBy (2), there are $|\\phi(a,B)|<\\beta n$.\nThen the probability that all $b\\in B''\\sm B'$ are such that $\\neg\\phi(a,b)$ is at least\\smallskip\n\n\\ceq{\\hfill{n-\\beta n\\choose m-k}\\bigg/{n-k\\choose m-k}}\n{=}\n{\\prod^{m-k-1}_{i=0}\\frac{n-\\beta n-i}{n-k-i}}\n\\hfill we write $\\beta n$ for $\\lfloor \\beta n \\rfloor$\n\n\\ceq{}\n{\\ge}\n{\\prod^{m-k-1}_{i=0}\\frac{n-\\beta n-m}{n-m}}\n\n\\ceq{}\n{=}\n{\\bigg(\\frac{n-\\beta n-m}{n-m}\\bigg)^m}\n\n\\ceq{}\n{=}\n{\\bigg(1-\\frac{\\beta n}{n-m}\\bigg)^m}\n\n\\ceq{}\n{\\ge}\n{\\displaystyle(1-2\\beta)^m\\vphantom{\\bigg)}}\n\\hfill because $n>2m$\n\n\\ceq{}\n{\\ge}\n{\\bigg(1-\\frac{1}{m}\\bigg)^m}\n\\hfill because $\\beta\\le1/2m.$\n\nAs we can assume $m\\ge 2$, the probability that a random pair in $P$ is good is at least $\\alpha/4$.\nThis proves Claim~1 and with it the theorem.\n\\end{proof}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The (p,q)-theorem}\n\nFor integers $p\\ge q$ we say that $\\phi(x\\,;z)$ has the \\emph{$(p,q)$-property\\/} if for every finite $A\\subseteq\\U$ and every $B\\subseteq\\V$ of cardinality $p$ there is some $B'\\subseteq B$ of cardinality $q$ such that\n\n\\ceq{\\hfill \\bigcap_{b\\in B'}\\phi(A\\,;b)}\n{\\neq}\n{\\0}\n\nFor ease of speaking we call $\\phi(A\\,;b)_{b\\in B}$ a $p$-collection of definable subsets of $A$.\nNote that, strictly speaking, these is not collection of sets but collection of parameters defining sets (though not intrinsically relevant, it is convenient not to assume extensionality). \n\nHence, we can rephrase the $(p,q)$-property in plain English: out of any $p$-collection of definable sets there are at least $q$ sets with nonempty intersection.\n\nHelly's theorem says that any finite collection of convex sets in $\\RR^d$ satisfying the $(d + 1, d + 1)$-property has non-empty intersection, i.e.\\@ admits a transversal of size $1$.\nA generalization of this was conjectured by Hadwiger and Debrunner, and many\nyears later proved by Alon and Kleitman~\\cite{AK1},~\\cite{AK2}.\nSubsequently, after proving Theorem~\\ref{thm_matousek}, Matou\\v{s}ek~\\cite{matousek} noted that the method in~\\cite{AK2} applies also to collections of sets with finite \\vc-dimension.\nMore precisely, Matou\\v{s}ek proved the existence of a bound to the cardinality of the transversal number $\\tau$ of {\\nip} formulas with the $(p,q)$-property, and that this bound depends only on $p,q$ and the \\vc-codimension of the formula. \n(Formally, the results~\\cite{AK2} and~\\cite{matousek} do not imply each other.)\n\n\\begin{theorem}[(Alon, Kleitman + Matou\\v{s}ek)]\n  Let $p\\ge q> k$ be natural numbers.\n  There is a number $N=N(k,p,q)$ such that \n  $\\tau_{\\phi(A\\,;B)}\\le N$ for all formulas $\\phi(x\\,;z)$ with the $(p,q)$-property and \\vc-codimension $< k$, and every $A\\subseteq\\U$ and $B\\subseteq\\V$.\n\\end{theorem}\n\n\\begin{proof}\nAs we are not trying to optimize $N$, we may prove the theorem for $q=k+1$.\nBy Proposition~\\ref{prop_bound_fractional_trans}, the transversal number is bounded by a function of $\\tau^*$, so it is enough to bound $\\tau^*$. By Theorem~\\ref{thm_fractional_nu=tau}, we can equivalently bound the fractional packing number $\\nu^*$ because it coincides with $\\tau^*$.\n\nLet $B'\\subseteq B$ be an optimal fractional packing.  That is, $\\nu^*=|B'|$ where $B'\\le\\Indicator_B$ is such that $|\\phi(a,B')|\\le1$ for every $a\\in A$. As we rather work with regular sets than with fractional multisets, we apply a trick that allows to replace $B'$ with a regular set $C'$. \n\nBy Theorem~\\ref{thm_fractional_nu=tau} we may assume that $B'$ is rational valued. Therefore $B'=(1/m)\\,C$ where $m$ is a positive integer and $C$ is a integral valued multiset over $\\V$.\nReplace $\\V$ with $\\V\\times[m]$.\nDefine $\\phi\\!_{_\\times}\\!(a\\,;b,i)$ to be the relation that holds if and only if $\\phi(a\\,;b)$ holds.\nThen we can replace the multiset $C$ with a regular set $C'\\subseteq\\V\\times[m]$ such that $|\\phi\\!_{_\\times}\\!(a\\,;C')|\\le m$ for every $a\\in A$.\n\nIf write $n$ for $|C'|$, then $\\nu^*=n/m$.\n\n\\smallskip\nClaim~1. $\\phi\\!_{_\\times}\\!(x\\,;z,y)$ satisfies the $(qp,q)$-property.\n\nLet $D\\subseteq\\V\\times[m]$ have cardinality $qp$. \nIf the $qp$-collection $\\phi\\!_{_\\times}\\!(A\\,;b,i)_{b,i\\in D}$ contains $q$ copies of the same definable set $\\phi(A\\,;b)$, then we immediately have the required $q$-collection with nonempty intersection.\nSo, suppose not.\nThen  $\\phi\\!_{_\\times}\\!(A\\,;b,i)_{b,i\\in D}$ contains $p$ distinct sets $\\phi(A,b_1),\\dots,\\phi(A,b_p)$. \nThen the $q$-collection with nonempty intersection is obtained from the $(p,q)$-property of $\\phi(x\\,;z)$.\n\n\\smallskip\nClaim 2.\nThere is an $\\alpha=\\alpha(p,q)>0$ such that\n\n\\ceq{\\hfill \\bigcap_{b,i\\in D}\\phi\\!_{_\\times}\\!(A\\,;b,i)}{\\neq}{\\0}\\hfill for at least \\ $\\displaystyle\\alpha{n\\choose q}$ \\ sets \\ $\\displaystyle D\\in{C'\\choose q}$.\n\nBy Claim~1, every $qp$-collection of $\\phi\\!_{_\\times}\\!$-definable sets contains at least one $q$-collection with non-empty intersection.\nEvery $q$-collection is contained in ${n-q\\choose qp-q}$ many $qp$-collections.\nTherefore the number $q$-collections with non-empty intersection is at least\n\n\\ceq{\\hfill{n\\choose qp}\\Big/{n-q\\choose qp-q}}{=}{{n\\choose q}\\Big/{qp\\choose q}.}\n\nTherefore, the claim holds with $\\displaystyle1/\\alpha={qp\\choose q}$.\n\nNow we can resume the proof of the theorem (recall that our goal is to bound $\\nu^*$ by a function of $p,q$, and $k$).\nLet $\\beta=\\beta(\\alpha,k)$ be as in Theorem~\\ref{thm_matousek}.\nAs $\\phi\\!_{_\\times}\\!(x\\,;z,y)$ has the same \\vc-codimension as $\\phi(x\\,;z)$, by Claim~2 there is an $a\\in A$ such that $\\phi(a,C')$ has cardinality at least $\\beta\\,n$. So, from $\\beta\\,n\\le |\\phi(a,C')|\\le m$ we obtain $\\nu^*\\le 1/\\beta$.\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "64e2ed2d323a595fdbc5ee1840e7244b89a6ebe9", "size": 16954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fractional.tex", "max_stars_repo_name": "LorenzoNot/scombinatorics", "max_stars_repo_head_hexsha": "64392c4f5793019b479376acb5eb248115335b93", "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": "fractional.tex", "max_issues_repo_name": "LorenzoNot/scombinatorics", "max_issues_repo_head_hexsha": "64392c4f5793019b479376acb5eb248115335b93", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-27T12:37:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-27T12:37:11.000Z", "max_forks_repo_path": "fractional.tex", "max_forks_repo_name": "LorenzoNot/scombinatorics", "max_forks_repo_head_hexsha": "64392c4f5793019b479376acb5eb248115335b93", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-19T08:23:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-19T08:23:27.000Z", "avg_line_length": 50.4583333333, "max_line_length": 293, "alphanum_fraction": 0.6696354843, "num_tokens": 5659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.6798690524466149}}
{"text": "\\section{Distributionally Robust Optimization}\n\\label{sec:DROCapitalBudgeting}\n\nWe consider another risk-averse decision making approach\nusing distributionally robust optimization (DRO). To this end, we begin with\na nominal stochastic optimization problem:\n\n\\begin{equation}\n\\max_{s\\in S} \\sum_{\\sigma\\in \\Sigma} q^\\sigma f(s,\\xi^\\sigma)\n\\end{equation}\n\nIn our context, the nominal model is a stochastic capital budgeting problem\nin which we maximize expected NPV, and we could have\n$f(s,\\xi^\\sigma)=NPV(s,\\xi^\\sigma)$. In this context ``$s\\in S$'' simply\nindicates the constraints that a prioritized solution must satisfy, wherein\nwe prioritize project selection subject to uncertainty in costs and the NPV\nof each project as well as uncertainty in resource availability. The goal is\nto prioritize so as to maximize expected NPV, assuming that nominal distribution,\nspecified by the probability mass function $q^\\sigma, \\sigma \\in \\Sigma$.\n\nWe suppose that $\\xi$ is a discrete random variable with finite sample space $\\Omega$,\nso that $\\xi^\\omega, \\omega \\in \\Omega$ enumerates all possible realizations.\nWe further suppose that we only have observations of\n$\\xi^\\sigma, \\sigma \\in \\Sigma \\subset \\Omega$,\ni.e., possibly a strict subset, which may arise in a data-driven setting. In such a\ndata-driven setting we could have, for example, probability mass $q^\\sigma = 1/|\\Sigma|$\nfor all $\\sigma \\in \\Sigma$.\nA DRO variant of this nominal stochastic optimization model is then given by:\n\n\\begin{equation}\n\\max_{s\\in S} \\min_{p\\in P} \\sum_{\\omega\\in \\Omega} p^\\omega f(s,\\xi^\\omega)\n\\end{equation}\n\nHere, we may view this DRO model as playing a ``game'' against nature. First, we select\n$s\\in S$, and then knowing $s$, nature selects a worst-case probability distribution,\n$p\\in P$, to minimize the expected NPV, which we seek to maximize. We will make precise\nwhat we mean by the Distributional Uncertainty Set (DUS), denoted by $P$, below, but\nfor the moment it is enough to think of the set as representing a neighborhood of\nprobability distributions centered on the given probability mass function, $q$,\nwith the radius of the neighborhood specified by parameter $\\varepsilon$. If\n$\\varepsilon = 0$ then the DRO model reduces to the nominal model. If $\\varepsilon$ is very\nlarge then nature will select the single worst-case scenario, e.g., the scenario\nwith lowest budgets, highest costs, and lowest NPVs. This is too conservative to be useful\n(i.e. if we are living in this world, it is very likely that the plant would be\nuneconomical no matter what decisions are made). However, with moderate values of\n$\\varepsilon$ we obtain solutions that hedge against deviations from $q$ without being\nexcessively conservative.\n\nImportantly, we do not view nature as malevolent, despite occasional evidence to the contrary.\nRather, we use ``$min_{p\\in P}$'' to combat over-adapting our solution to a specific assumption\nabout the probability distribution. In this sense, DRO plays the role of a ``regularizer'' to\ncombat over-fitting that is analogous to regularizers used in high-dimensional statistics\nand statistical machine learning. Our approach to DRO requires further mathematical and\nintuitive development before we can analyze solutions to the DRO problem.\n\n\\subsection{Defining a Distributional Uncertainty Set via the Wasserstein Distance}\n\\label{subsec:WassersteinDistance}\nBy the constraints denoted by $p\\in P$ we require that nature select a probability\nmass function, $p$, that is ``close'' to the nominal or empirical data-driven distribution\n$q$. We define the DUS as follows:\n\n\\begin{equation}\nP=\\{p: D(p,q)\\le \\varepsilon, \\sum_{\\omega\\in \\Omega} p^\\omega = 1, p^\\omega \\ge 0, \\omega \\in \\Omega \\}\n\\end{equation}\n\nwhere $D(p, q)$ is the distance between nature’s choice, $p$, and the nominal data-driven distribution,\n$q$. As indicated above, the radius parameter $\\varepsilon$ governs the latitude we give nature,\nwhich in turn governs the degree of conservatism that we face when selecting decision $s\\in S$.\n\nThere are multiple ways to measure the ``distance'', $D(p, q)$, between two probability distributions,\nwhich include the Kolmogorov-Smirnov distance, Kullback-Leibler divergence, chi-squared distances,\ntotal variation, and more general $\\psi$-divergences. The Wasserstein distance, which is based on\nthe idea of optimal transport, is a particularly useful way to measure such a distance in the\ncontext of distributionally robust optimization. For a distribution with known finite support,\nthe Wasserstein distance, $D(p, q)$, between a given distribution, $q^\\sigma, \\sigma \\in \\Sigma$,\nand a given candidate robust distribution, $p^\\omega, \\omega \\in \\Omega$, is provided by the\noptimal value of the transportation problem:\n\n\\begin{subequations}\\label{WassersteinEq}\n\\begin{eqnarray}\n& & D(q, p) = \\min_{z} \\sum_{\\sigma \\in \\Sigma, \\omega \\in \\Omega} d_{\\sigma, \\omega} z_{\\sigma, \\omega} \\\\\n& & s.t. \\sum_{\\omega \\in \\Omega} z_{\\sigma, \\omega} = q^\\sigma, \\sigma \\in \\Sigma \\\\\n& & \\sum_{\\sigma \\in \\Sigma} z_{\\sigma, \\omega} = p^\\omega, \\omega \\in \\Omega \\\\\n& & z_{\\sigma, \\omega} \\ge 0, \\sigma \\in \\Sigma, \\omega \\in \\Omega\n\\end{eqnarray}\n\\end{subequations}\n\nThe intuition behind this measure concerns the magnitude of probability mass, $q^\\sigma$,\nthat must be transported distance $d_{\\sigma, \\omega}$ from vector $\\xi^\\sigma$ to vector $\\xi^\\omega$\nvia variable $z_{\\sigma, \\omega}$. In one extreme case, if the two sample spaces and probability\nmass functions coincide, i.e., $\\Omega = \\Sigma$ and $p^\\omega = q^\\omega$, and $d_{\\omega, \\omega} = 0$\nfor all $\\omega \\in \\Omega$ then $D(p, q) = 0$.\n\nTo fully specify $D(p, q)$ we must define $d_{\\sigma, \\omega}= dist(\\xi^\\sigma, \\xi^\\omega)$.\nTo do so we can select $dist(\\cdot, \\cdot)$, for example, to be the two-norm distance, or a more\ngeneral $\\eta$-norm distance, between the vectors, $\\xi^\\sigma$ and $\\xi^\\omega$,\ni.e., $dist(\\cdot, \\cdot) = ||\\xi^\\sigma - \\xi^\\omega||_\\eta$.\n\nWith the Wasserstein distance, if we are given distribution, $q$, we can then define:\n\n\\begin{equation}\nP=\\{p: D(p,q)\\le \\varepsilon, \\sum_{\\omega\\in \\Omega} p^\\omega = 1, p^\\omega \\ge 0, \\omega \\in \\Omega \\}\n\\end{equation}\n\nfor a given radius $\\varepsilon$. Here, we think of $P$ as a ball, or neighborhood, of\nprobability distributions centered on $q$, where the neighborhood has radius $\\varepsilon$.\nWith $\\Sigma \\subset \\Omega$, if $\\varepsilon = 0$ then $P$ is the singleton ${q}$, and\nlarger values of $\\varepsilon$ lead to increasingly large neighborhoods. In the context\nof robust optimization, if $\\varepsilon = 0$ then we will simply be solving the nominal\nstochastic optimization model, and as $\\varepsilon$ grows large we will consider\nincreasingly conservative models.\n\nWe can now represent the set $P$ via the following so-called extended-variable set of constraints:\n\n\\begin{subequations}\\label{WassersteinConstraints}\n\\begin{eqnarray}\n& & \\sum_{\\sigma \\in \\Sigma, \\omega \\in \\Omega} d_{\\sigma, \\omega} z_{\\sigma, \\omega} \\le \\varepsilon \\\\\n& & \\sum_{\\omega \\in \\Omega} z_{\\sigma, \\omega} = q^\\sigma, \\sigma \\in \\Sigma \\\\\n& & \\sum_{\\sigma \\in \\Sigma} z_{\\sigma, \\omega} = p^\\omega, \\omega \\in \\Omega \\\\\n& & z_{\\sigma, \\omega} \\ge 0, \\sigma \\in \\Sigma, \\omega \\in \\Omega\n\\end{eqnarray}\n\\end{subequations}\n\n\\subsection{Towards a Computationally Tractable Reformulation}\n\\label{subsec:TractableReformulation}\nDue to the max min construct in the DRO model, the model is not amenable to direct solution\nvia optimization software. So, we reformulate the model to facilitate computation.\nFor the moment let $s\\in S$ be fixed so that $f(s, \\xi^\\omega)$ is just a known numerical\nvalue for each $\\omega \\in \\Omega$. Then, nature’s problem may be written:\n\n\\begin{subequations}\n\\begin{eqnarray}\n& & \\min_{p, z} \\sum_{\\omega \\in \\Omega} p^\\omega f(s, \\xi^\\omega) \\\\\n& & s.t. \\sum_{\\sigma \\in \\Sigma, \\omega \\in \\Omega} d_{\\sigma, \\omega} z_{\\sigma, \\omega} \\le \\varepsilon : [-\\gamma] \\\\\n& & \\sum_{\\omega \\in \\Omega} z_{\\sigma, \\omega} = q^\\sigma, \\sigma \\in \\Sigma : [\\nu^\\sigma]\\\\\n& & \\sum_{\\sigma \\in \\Sigma} z_{\\sigma, \\omega} = p^\\omega, \\omega \\in \\Omega : [\\beta^\\omega]\\\\\n& & z_{\\sigma, \\omega} \\ge 0, \\sigma \\in \\Sigma, \\omega \\in \\Omega\n\\end{eqnarray}\n\\end{subequations}\n\nHere, $\\gamma, \\nu^\\sigma$, and $\\beta^\\omega$ denote dual variables.\nIn this model, nature optimizes over $z$ and over $p$ to select a worst-case distribution\nwithin radius $\\varepsilon$ of $q$.\n\nTaking the dual of the linear DRO program, and substituting out the dual variable\n$\\beta^\\omega= -f(s, \\xi^\\omega)$, we obtain the following:\n\n\\begin{subequations}\\label{dualProlem}\n\\begin{eqnarray}\n& & \\max_{\\gamma, \\nu} -\\gamma \\varepsilon + \\sum_{\\sigma\\in \\Sigma} \\nu^\\sigma q^\\sigma \\\\\n& & s.t. -\\gamma d_{\\sigma, \\omega} + \\nu^\\sigma \\le f(s, \\xi^\\omega), \\sigma \\in \\Sigma, \\omega \\in \\Omega \\\\\n& & \\gamma \\ge 0\n\\end{eqnarray}\n\\end{subequations}\n\nFor a better understanding of the model, consider two extreme cases, $\\varepsilon = 0$ and $\\varepsilon = \\infty$.\nIf $\\varepsilon = 0$ then there is no penalty in the objective function for allowing $\\gamma$\nto grow large. As $gamma$ grows large, the constraint becomes vacuous for all $\\sigma \\ne \\omega$;\nhowever, for $\\sigma = \\omega$ we have $d_{\\sigma, \\sigma} = ||\\xi^\\sigma - \\xi^\\omega|| = 0$,\nand hence the constraint reduces to $\\nu^\\sigma \\le f(s, \\xi^\\omega)$, and coupled with the objective\nfunction the optimal value reduces to $\\sum_\\sigma q^\\sigma f(s, \\xi^\\sigma) = \\sum_\\omega p^\\omega f(s, \\xi^\\omega)$,\ni.e., it reduces to the objective function value of the nominal stochastic optimization model,\nas it must with $\\varepsilon = 0$.\n\nIn the other extreme, as $\\varepsilon$ grows sufficiently large we must have $\\gamma = 0$\nto avoid a huge penalty in the objective function. Thus, for each $\\sigma \\in \\Sigma$,\nthe constraint reduces to $\\nu^\\sigma \\le f(s, \\xi^\\omega)$, i.e.,\nthe objective function reduces to:\n\n\\begin{equation}\n\\sum_\\sigma \\min_\\omega f(s, \\xi^\\omega) q^\\sigma = \\min_\\omega f(s, \\xi^\\omega) \\sum_\\sigma q^\\sigma = \\min_\\omega f(s, \\xi^\\omega)\n\\end{equation}\n\nAgain, this matches what it must: if $\\varepsilon = \\infty$ then nature has enough latitude\nto place a probability of one on the single worst-case scenario.\n\nSpecializing $s\\in S$ to be the constraints for prioritization, and specializing\n$f(s,\\xi^\\omega)$ to define the NPV under scenario $\\omega\\in \\Omega$, the DRO variant of the\nstochastic capital budgeting problem is as follows:\n\n\\begin{subequations}\\label{fullDRO}\n\\begin{eqnarray}\n& & \\max_{x, y, \\gamma, \\nu} -\\gamma \\varepsilon + \\sum_{\\sigma\\in \\Sigma} \\nu^\\sigma q^\\sigma \\\\\n& & s.t. -\\gamma d_{\\sigma, \\omega} + \\nu^\\sigma \\le \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}a_{ij}^{ \\omega }x_{ij}^{ \\omega }, \\sigma \\in \\Sigma, \\omega \\in \\Omega \\\\\n& & y_{ii^{'}}+y_{i^{'}i} \\geq 1,~ i<i^{'}\\text{, i, }i^{'} \\in I \\\\\n& & \\sum_{j=1}^{J_i} x_{ij}^\\omega \\geq \\sum_{j=1}^{J_i} x_{i'j}^\\omega + y_{ii'} -1,~ i \\neq i^{'}\\text{, i, }i^{'} \\in I,  \\omega  \\in  \\Omega \\\\\n& & \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}\\text{~ c}_{ijkt}^{ \\omega }x_{ij}^{ \\omega }~  \\leq  b_{kt}^{ \\omega },~ k \\in K, t \\in T,  \\omega  \\in  \\Omega \\\\\n& & \\sum_{j\\in J_i} x_{ij}^{ \\omega } \\leq 1,~ i \\in I, \\omega  \\in  \\Omega \\\\\n& & \\gamma \\ge 0\n\\end{eqnarray}\n\\end{subequations}\n\n\\subsection{LOGOS Settings for DRO Problems}\n\\label{subsec:DROSettings}\nDRO approach is an extension for stochastic optimization approach discussed in\nSection~\\ref{sec:StochasticCapitalBudgeting}. Both of them share the same input\nstructures except the \\xmlNode{Settings} block. In both cases, the user need to\nspecify a collection of scenarios via \\xmlNode{Uncertainties} block. The\n\\xmlNode{problem\\_type} within \\xmlNode{Settings} block is used to select the\ntype of DRO problems. The currently available DRO problem types are:\n\\xmlString{droskp}, \\xmlString{dromkp}, and \\xmlString{dromckp}. The user can\nuse \\xmlNode{radius\\_ambiguity} to control the Wasserstein distance for DRO problems.\n\nExample LOGOS input XML for DRO:\n\\begin{lstlisting}[style=XML]\n<Settings>\n<Logos>\n  <solver>cbc</solver>\n  <solverOptions>\n    <StochSolver>EF</StochSolver>\n    <!-- epsilon radius -->\n    <radius_ambiguity>0.1</radius_ambiguity>\n  </solverOptions>\n  <sense>maximize</sense>\n  <problem_type>droskp</problem_type>\n</Settings>\n</Logos>\n\\end{lstlisting}\n\n\\subsection{DRO for Single Knapsack Problem}\n\\label{subsec:DRO_SKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{DROSimpleKP}\n\\begin{eqnarray}\n& & \\max_{x, y} \\max_{\\gamma, \\nu} (-\\gamma \\varepsilon + \\sum_{\\sigma \\in \\Sigma} \\nu^\\sigma q^\\sigma)  \\\\\n& &  -\\gamma d_{\\sigma, \\omega} + \\nu^\\sigma \\le \\sum _{i \\in I} a_{i}^{ \\omega }x_{i}^{ \\omega }, \\sigma \\in \\Sigma, \\omega \\in \\Omega \\\\\n& & \\sum_{i \\in I} c_{i}^\\omega x_{i}^\\omega \\leq b^\\omega \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & x_{i}^\\omega \\geq x_{i'}^\\omega + y_{ii'}-1, i\\neq i' \\\\\n& & x_{i}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\gamma \\ge 0\n\\end{eqnarray}\n\\end{subequations}\n\nSee next section~\\ref{subsec:DRO_DKP} for the example of LOGOS input file, since multi-dimensional Knapsack problem\nis just a simple extension of a single-dimensional Knapsack problem, and both of them belong to the same\n\\xmlNode{problem\\_type}: \\xmlString{droskp}.\n\n\n\\subsection{DRO for Multi-Dimensional Knapsack Problem}\n\\label{subsec:DRO_DKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{DROMultiDKP}\n\\begin{eqnarray}\n& & \\max_{x, y} \\max_{\\gamma, \\nu} (-\\gamma \\varepsilon + \\sum_{\\sigma \\in \\Sigma} \\nu^\\sigma q^\\sigma)  \\\\\n& &  -\\gamma d_{\\sigma, \\omega} + \\nu^\\sigma \\le \\sum _{i \\in I} a_{i}^{ \\omega }x_{i}^{ \\omega }, \\sigma \\in \\Sigma, \\omega \\in \\Omega \\\\\n& & \\sum_{i \\in I} c_{it}^\\omega x_{i}^\\omega \\leq b_{t}^\\omega, t\\in T \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & x_{i}^\\omega \\geq x_{i'}^\\omega + y_{ii'}-1, i\\neq i' \\\\\n& & x_{i}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\gamma \\ge 0\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16\n    </investments>\n    <time_periods>\n      1,2,3,4,5\n    </time_periods>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      2.315,0.824,22.459,60.589,0.667,5.173,4.003,0.582,0.122,\n      -2.870,-0.102,-0.278,-0.322,-3.996,-0.246,-20.155\n    </net_present_values>\n    <costs index=\"investments, time_periods\">\n      0.219,0.257,0.085,0.0,0.0,\n      0.0,0.0,0.122,0.103,0.013,\n      5.044,1.839,0.0,0.0,0.0,\n      6.74,6.134,10.442,0.0,0.0,\n      0.425,0.0,0.0,0.0,0.0,\n      2.125,2.122,0.0,0.0,0.0,\n      2.387,0.19,0.012,2.383,0.192,\n      0.0,0.95,0.0,0.0,0.0,\n      0.03,0.03,0.688,0.0,0.0,\n      0,0.2,0.763,0.739,2.539,\n      0.081,0.032,0,0,0,\n      0.3,0,0,0,0,\n      0.347,0,0,0,0,\n      4.025,0.297,0,0,0,\n      0.095,0.095,0.095,0,0,\n      5.487,5.664,0.5,6.803,6.778\n    </costs>\n    <available_capitals index=\"time_periods\">\n      18,18,18,18,18\n    </available_capitals>\n  </Parameters>\n\n  <Uncertainties>\n    <available_capitals>\n      <totalScenarios>10</totalScenarios>\n      <probabilities>\n        0.012, 0.019, 0.032, 0.052, 0.086, 0.142, 0.235, 0.188, 0.141, 0.093\n      </probabilities>\n      <!--\n        scenarios is ordered by numberScenarios * parametersIndex,\n        the number of scenarios is determined by\n        the number of elements in <probabilities>, for this case:\n        numberScenarios * time_periods = 10 * 5\n      -->\n      <scenarios>\n        11, 11, 11, 11, 11,\n        12, 12, 12, 12, 12,\n        13, 13, 13, 13, 13,\n        14, 14, 14, 14, 14,\n        15, 15, 15, 15, 15,\n        16, 16, 16, 16, 16,\n        17, 17, 17, 17, 17,\n        18, 18, 18, 18, 18,\n        19, 19, 19, 19, 19,\n        20, 20, 20, 20, 20\n      </scenarios>\n    </available_capitals>\n  </Uncertainties>\n\n  <Settings>\n    <mandatory>10,11,12,13,14,15,16</mandatory>\n    <solver>cbc</solver>\n    <solverOptions>\n      <StochSolver>EF</StochSolver>\n      <!-- epsilon radius -->\n      <radius_ambiguity>0.1</radius_ambiguity>\n    </solverOptions>\n    <sense>maximize</sense>\n    <problem_type>droskp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\n\n\\subsection{DRO for Multiple Knapsack Problem}\n\\label{subsec:DRO_MKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{DROMKP}\n\\begin{eqnarray}\n& & \\max_{x, y} \\max_{\\gamma, \\nu} (-\\gamma \\varepsilon + \\sum_{\\sigma \\in \\Sigma} \\nu^\\sigma q^\\sigma)  \\\\\n& &  -\\gamma d_{\\sigma, \\omega} + \\nu^\\sigma \\le \\sum _{i \\in I} \\sum _{m \\in M}a_{i}^{ \\omega }x_{im}^{ \\omega }, \\sigma \\in \\Sigma, \\omega \\in \\Omega \\\\\n& & \\sum _{i \\in I}^{} c_{i}^{ \\omega }x_{im}^{ \\omega }~  \\leq  b_{m}^{ \\omega },~ m \\in M,  \\omega  \\in  \\Omega \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & \\sum_{m=1}^{M} x_{im}^\\omega \\geq \\sum_{m=1}^{M} x_{i'm}^\\omega + y_{ii'} -1,~ i \\neq i^{'}\\text{, i, }i^{'} \\in I,  \\omega  \\in  \\Omega \\\\\n& & x_{i,m}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\gamma \\ge 0\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9,10\n    </investments>\n    <capitals>\n      unit_1, unit_2\n    </capitals>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      78, 35, 89, 36, 94, 75, 74, 79, 80, 16\n    </net_present_values>\n    <costs index=\"investments\">\n      18, 9, 23, 20, 59, 61, 70, 75, 76, 30\n    </costs>\n    <available_capitals index=\"capitals\">\n      103, 156\n    </available_capitals>\n  </Parameters>\n\n  <Uncertainties>\n    <available_capitals>\n      <totalScenarios>10</totalScenarios>\n      <probabilities>\n        0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n      </probabilities>\n      <scenarios>\n        101, 154,\n        102, 155,\n        103, 156,\n        104, 157,\n        105, 158,\n        106, 159,\n        107, 160,\n        108, 161,\n        109, 162,\n        110, 163\n      </scenarios>\n    </available_capitals>\n  </Uncertainties>\n\n  <Settings>\n    <solver>cbc</solver>\n    <solverOptions>\n      <StochSolver>EF</StochSolver>\n      <!-- epsilon radius -->\n      <radius_ambiguity>0.1</radius_ambiguity>\n    </solverOptions>\n    <sense>maximize</sense>\n    <problem_type>dromkp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\n\n\\subsection{DRO for Multiple-Choice Knapsack Problem}\n\\label{subsec:DRO_MCKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{DROMCKP}\n\\begin{eqnarray}\n& & \\max_{x, y} \\max_{\\gamma, \\nu} (-\\gamma \\varepsilon + \\sum_{\\sigma \\in \\Sigma} \\nu^\\sigma q^\\sigma)  \\\\\n& &  -\\gamma d_{\\sigma, \\omega} + \\nu^\\sigma \\le \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}a_{ij}^{ \\omega }x_{ij}^{ \\omega }, \\sigma \\in \\Sigma, \\omega \\in \\Omega \\\\\n& & \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}\\text{~ c}_{ijkt}^{ \\omega }x_{ij}^{ \\omega }~  \\leq  b_{kt}^{ \\omega },~ k \\in K, t \\in T,  \\omega  \\in  \\Omega \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & \\sum_{j=1}^{J_i} x_{ij}^\\omega \\geq \\sum_{j=1}^{J_i} x_{i'j}^\\omega + y_{ii'} -1,~ i \\neq i^{'}\\text{, i, }i^{'} \\in I,  \\omega  \\in  \\Omega \\\\\n& & x_{i,j}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\gamma \\ge 0\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17\n    </investments>\n    <options index='investments'>\n      1;\n      1;\n      1;\n      1,2,3;\n      1,2,3,4;\n      1,2,3,4,5,6,7;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1\n    </options>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index='options'>\n      2.046\n      2.679\n      2.489\n      2.61\n      2.313\n      1.02\n      3.013\n      2.55\n      3.351\n      3.423\n      3.781\n      2.525\n      2.169\n      2.267\n      2.747\n      4.309\n      6.452\n      2.849\n      7.945\n      2.538\n      1.761\n      3.002\n      3.449\n      2.865\n      3.999\n      2.283\n      0.9\n      8.608\n    </net_present_values>\n    <costs index='options'>\n      36538462\n      83849038\n      4615385\n      2788461538\n      2692307692\n      5480769231\n      1634615385\n      2981730768\n      7211538462\n      9038461538\n      649038462\n      650000000\n      216346154\n      212500000\n      3076923077\n      3942307692\n      1144230769\n      675721154\n      1442307692\n      99711538\n      4807692\n      123076923\n      138461538\n      86538462\n      108653846\n      75092404\n      6413462\n      147932692\n    </costs>\n    <available_capitals>\n      15E9\n    </available_capitals>\n  </Parameters>\n\n  <Uncertainties>\n    <available_capitals>\n      <totalScenarios>3</totalScenarios>\n      <probabilities>\n        0.2,0.6,0.2\n      </probabilities>\n      <scenarios>\n        5E9,10E9,15E9\n      </scenarios>\n    </available_capitals>\n  </Uncertainties>\n\n  <Settings>\n    <solver>glpk</solver>\n    <solverOptions>\n      <StochSolver>EF</StochSolver>\n      <!-- epsilon radius -->\n      <radius_ambiguity>0.1</radius_ambiguity>\n    </solverOptions>\n    <sense>maximize</sense>\n    <problem_type>dromckp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n", "meta": {"hexsha": "810d45136e56c2f0146e90887c1a4fef05163edf", "size": 21154, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/include/DRO.tex", "max_stars_repo_name": "dgarrett622/LOGOS", "max_stars_repo_head_hexsha": "7234b8b5e80bc79526b4cbced7efd5ae482f7c44", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-05-04T08:42:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T13:14:12.000Z", "max_issues_repo_path": "doc/user_manual/include/DRO.tex", "max_issues_repo_name": "albernsrya/LOGOS", "max_issues_repo_head_hexsha": "535a25ccd3a83259b615acd569257d751fe00439", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2021-01-12T17:41:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-03T18:20:16.000Z", "max_forks_repo_path": "doc/user_manual/include/DRO.tex", "max_forks_repo_name": "albernsrya/LOGOS", "max_forks_repo_head_hexsha": "535a25ccd3a83259b615acd569257d751fe00439", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-05T17:18:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T14:36:42.000Z", "avg_line_length": 38.602189781, "max_line_length": 169, "alphanum_fraction": 0.652737071, "num_tokens": 7344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6798592402820804}}
{"text": "\\section{Properties of the Dual Map and Double Dual}\r\n\\begin{lemma}\r\n    Let $V,W$ be vector spaces over $F$ and $\\alpha\\in L(V,W)$.\r\n    Let $\\alpha^\\ast\\in L(W^\\ast,V^\\ast)$ be the dual map, then:\\\\1\r\n    1. $\\ker\\alpha^\\ast=(\\operatorname{Im}\\alpha)^\\circ$, so $\\alpha^\\ast$ is injective iff $\\alpha$ is surjective.\\\\\r\n    2. $\\operatorname{Im}\\alpha^\\ast\\le(\\ker\\alpha)^\\circ$ with equality if $V,W$ are finite dimensional, in which case it implies that $\\alpha^\\ast$ is surjective iff $\\alpha$ is injective.\r\n\\end{lemma}\r\nThis is very important as it shows how we can understand $\\alpha$ from $\\alpha^\\ast$, which is often simpler.\r\n\\begin{proof}\r\n    1. Pick $\\epsilon\\in W^\\ast$, then $\\epsilon\\in\\ker\\alpha^\\ast$ iff $\\alpha^\\ast(\\epsilon)=0$ iff $\\epsilon\\circ\\alpha=0$ iff $\\epsilon\\in(\\operatorname{Im}\\alpha)^\\circ$.\\\\\r\n    2. We first show that $\\operatorname{Im}\\alpha^\\ast\\le(\\ker\\alpha)^\\circ$.\r\n    Indeed, for any $\\epsilon\\in\\operatorname{Im}\\alpha^\\ast$, we have $\\epsilon=\\alpha^\\ast(\\phi)=\\phi\\circ\\alpha$ for some $\\phi\\in W^\\ast$.\r\n    But then for any $u\\in \\ker\\alpha$ we have $\\epsilon(u)=\\phi\\circ\\alpha(u)=\\phi(0)=0$, which means $\\epsilon\\in(\\ker\\alpha)^\\circ$.\r\n    In finite dimension, pick bases $B,C$ of $V,W$ and we get\r\n    \\begin{align*}\r\n        \\dim\\operatorname{Im}\\alpha^\\ast&=r(\\alpha^\\ast)=r([\\alpha^\\ast]_{C^\\ast,B^\\ast})=r([\\alpha]_{B,C}^\\top)\\\\\r\n        &=r([\\alpha]_{B,C})=r(\\alpha)\\\\\r\n        &=\\dim V-\\dim\\ker\\alpha\\\\\r\n        &=\\dim (\\ker\\alpha)^\\circ\r\n    \\end{align*}\r\n    So they have the same dimension, hence equal.\r\n\\end{proof}\r\nWe now turn to a very important concept known as double dual.\r\n$V^\\ast$ is a vector space too, so we can also construct its dual\r\n$$V^{\\ast\\ast}=L(V^\\ast,F)=(V^\\ast)^\\ast$$\r\nWhy is it important?\r\nWell, not much in finite dimensions, but in infinite dimensonal spaces, it is very hard to find obvious relations between $V$ and $V^\\ast$.\r\nHowever, there is a canonical embedding of $V$ into $V^{\\ast\\ast}$.\r\nIndeed, pick $v\\in V$, consider $\\hat{v}:V^\\ast\\to F$ via $\\epsilon\\mapsto\\epsilon(v)$, which is a well-defined element of $V^{\\ast\\ast}$.\r\nQuite ironically, our first theorem on this topic is about finite-dimensional spaces.\r\n\\begin{theorem}\r\n    If $V$ is finite dimensional, then this operation $\\hat{}:V\\to V^{\\ast\\ast}$ we just described is an isomorphism of vector spaces.\r\n\\end{theorem}\r\nSo we can just identify $V^{\\ast\\ast}$ with $V$.\r\n\\begin{proof}\r\n    Linearity is standard.\r\n    To see it is injective, let $e\\in V\\setminus\\{0\\}$ and extend $\\{e\\}$ to a basis $\\{e,e_2,\\ldots,e_n\\}$ of $V$.\r\n    So the dual basis $(\\epsilon,\\epsilon_2,\\ldots,\\epsilon_n)$ would have $\\hat{e}(\\epsilon)=\\epsilon(e)=1$.\r\n    Therefore $\\hat{}$ has trivial kernel, hence injective.\r\n    It then follows that it is an isomorphism as $\\dim V=\\dim V^\\ast=\\dim V^{\\ast\\ast}$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    In further linear analysis and functional analysis, we will see that $\\hat{}$ remains injective for a huge class of infinite dimensional vector spaces (those of interests are often space of functions).\r\n    And there are many of them (called reflexive spaces) where $\\hat{}$ is actually an isomorphism.\r\n    The theories emerged from here have numerous applications in analysis.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Let $V$ be a finite dimensional vector space over $F$ and $U\\le V$.\r\n    Define $\\hat{U}=\\{\\hat{u}:u\\in U\\}\\le V^{\\ast\\ast}$.\r\n    Then $\\hat{U}=U^{\\circ\\circ}=(U^\\circ)^\\circ$.\r\n\\end{lemma}\r\nThus we can identify $U^{\\circ\\circ}$ with $U$ too.\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $V$ be finite dimensional vector space over $F$ and $U_1,U_2\\le V$, then:\\\\\r\n    1. $(U_1+U_2)^\\circ=U_1^\\circ\\cap U_2^\\circ$.\\\\\r\n    2. $(U_1\\cap U_2)^\\circ=U_1^\\circ+U_2^\\circ$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Just write it out.\r\n\\end{proof}", "meta": {"hexsha": "af20025ac3edce5339214bfb75abb041b188feb1", "size": 3858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9/double.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": "9/double.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": "9/double.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.2380952381, "max_line_length": 206, "alphanum_fraction": 0.6555209953, "num_tokens": 1235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8872046041554922, "lm_q1q2_score": 0.67985923881052}}
{"text": "\\section{Green's Theorem}\\label{sec:GreensTheorem}\n\nWe now come to the first of three important theorems that extend the\nFundamental Theorem of Calculus to higher dimensions. (The Fundamental\nTheorem of Line Integrals has already done this in one way, but in\nthat case we were still dealing with an essentially one-dimensional\nintegral.) They all share with the Fundamental Theorem the following\nrather vague description: \\emph{To compute a certain sort of integral over a\nregion, we may do a computation on the boundary of the region\nthat involves one fewer integrations.}\n\nNote that this does indeed describe the Fundamental Theorem of\nCalculus and the Fundamental Theorem of Line Integrals: to\ncompute a single integral over an interval, we do a computation on the\nboundary (the endpoints) that involves one fewer integrations, namely,\nno integrations at all.\n\n\\begin{theorem}{Green's Theorem}{greens theorem}\nIf the vector field $\\vect{f}=\\langle\nf_1,f_2\\rangle$ and the region $D$ are sufficiently nice, and if $C$ is\nthe boundary of $D$ ($C$ is a closed curve), then\n$$\\iint_D {\\partial f_2\\over\\partial x}\n-{\\partial f_1\\over\\partial y} \\,dA = \\int_C f_1\\,dx +f_@\\,dy ,$$\nprovided the integration on the right is done counter-clockwise around\n$C$.\\index{Green's theorem}\n\\end{theorem}\n\nThe proof of Green's Theorem will follow a discussion and several examples.\n\nTo indicate that an integral $\\ds\\int_C$ is being done over a closed\ncurve in the counter-clockwise direction, we usually write\n$\\ds\\oint_C$. We also use the notation $\\partial D$ to mean the\nboundary of $D$ \\dfont{oriented} in the\ncounterclockwise direction. With this notation,\n$\\ds\\oint_C=\\int_{\\partial D}$.\n\nWe already know one case, not particularly interesting, in which this\ntheorem is true: If $\\vect{f}$ is conservative, we know that the integral\n$\\ds\\oint_C \\vect{f}\\cdot d\\vect{r}=0$, because any integral of a\nconservative vector field around a closed curve is zero. We also know\nin this case that $\\partial f_1 /\\partial y=\\partial f_2 /\\partial x$, so\nthe double integral  in the theorem is simply the integral of the zero\nfunction, namely, 0. So in the case that $\\vect{f}$ is conservative, the\ntheorem says simply that $0=0$. \n\n\\begin{example}{}{greenseg}\nWe illustrate the theorem by computing both sides of\n$$\\int_{\\partial D} x^3\\,dx + xy^2\\,dy=\\iint_D y-0\\,dA,$$\nwhere $D$ is the triangular region with corners $(0,0)$, $(1,0)$,\n$(0,-1)$.\n\\end{example}\n\\begin{solution}\nStarting with the double integral:\n$$\\iint_D y^2-0\\,dA=\\int_0^1\\int_0^{-1+x} y^2\\,dy\\,dx=\n\\int_0^1\n{(-1+x)^3\\over3}\\,dx=\\left.{(-1+x)^4\\over12}\\right|_0^1=-{1\\over12}.$$\n\nThere is no single formula to describe the boundary of $D$, so to\ncompute the left side directly we need to compute three separate\nintegrals corresponding to the three sides of the triangle, and each\nof these integrals we break into two integrals, the ``$dx$'' part and\nthe ``$dy$'' part.\nThe three sides are described by $y=0$, $y=-1+x$, and $x=0$. The\nintegrals are then\n\\begin{align*}\n\\int_{\\partial D}\\> \\> x^3\\,dx + xy^2\\,dy&=\n\\int_0^1 x^3\\,dx+\\int_0^0 0\\,dy+\\int_1^0 x^3\\,dx+\\int_0^{-1} (y+1)y^2\\,dy+\n\\int_0^0 0\\,dx+\\int_0^{-1} 0\\,dy\t\\\\\n&={1\\over4}+0-{1\\over4}+-{1\\over12}+0+0=-{1\\over12}.\n\\end{align*}\n\nAlternately, we could describe the three sides in vector form as\n$\\langle t,0\\rangle$ for $t$ from $0$ to $1$, $\\langle t+1,t\\rangle$ for $t$ from $0$ to $-1$, and $\\langle 0,-1+t\\rangle$ for $t$ from $0$ to $1$. Note that in each case, as $t$ ranges from lower to upper bound, we\nfollow the corresponding side in the correct direction. Now\n\\begin{align*}\n\\int_{\\partial D} x^3\\,dx + xy^2\\,dy&=\n\\int_0^1 t^3 + t\\cdot 0^2\\,dt + \\int_0^{-1} (t+1)^3 + (t+1)t^2\\,dt\n+\\int_0^1 0 + 0(-1+t)\\,dt\t\\\\\n&=\\int_0^1 t^3\\,dt + \\int_0^{-1} (t+1)^3 + (t+1)t^2 \\,dt\n=-{1\\over12}.\n\\end{align*}\n% The three integrals on the right in the first line deserve a\n% bit of explanation. The first arises from\n% $$\\int_C \\vect{f}\\cdot d\\vect{r},$$\n% where $C$ is given by $\\vect{r}=\\langle t,0\\rangle$, that is, by\n% $x=t$ and $y=0$. This implies that $dx=dt$ and $dy=0\\cdot dt$. \n% Now substituting into $x^4\\,dx + xy\\,dy$ gives\n% $t^4\\,dt+t\\cdot0\\cdot0\\,dt$. In the second integral we have \n% $\\vect{r}=\\langle 1-t,t\\rangle$, so $x=1-t$, $y=t$,\n% $dx=-dt$, and $dy=dt$. Substitution gives the integral shown. The\n% third integral arises in the same way.\n%\n%Now computing the easy integrals gives\n%$(1/5)+(-1/5+1/2-1/3)+(0)=1/6$ as before.\n\\end{solution}\n\nIn this case, none of the integrations are difficult, but the second\napproach is somewhat tedious because of the necessity to set up three\ndifferent integrals. In different circumstances, either of the\nintegrals, the single or the double, might be easier to\ncompute. Sometimes it is worthwhile to turn a single integral into the\ncorresponding double integral, sometimes exactly the opposite approach\nis best.\n\nHere is a clever use of Green's Theorem: We know that areas can be\ncomputed using double integrals, namely,\n$$\\iint_D 1\\,dA$$\ncomputes the area of region $D$. If we can find $f_1$ and $f_2$ so that\n$\\partial f_2 /\\partial x-\\partial f_1 /\\partial y=1$, then the area is also\n$$\\int_{\\partial D} f_1\\,dx+f_2\\,dy.$$\nIt is quite easy to do this: $f_1=0,f_2=x$ works, as do\n$f_1=-y, f_2=0$ and $f_1=-y/2,f_2=x/2$. \n\n\\begin{example}{}{}\nAn ellipse centered at the origin, with its two principal axes\naligned with the $x$ and $y$ axes, is given by\n$${x^2\\over a^2}+{y^2\\over b^2}=1.$$ Find the area of the\ninterior of the ellipse.\n\\end{example}\n\\begin{solution}\nWe find the area of the interior\nof the ellipse\nvia Green's theorem. To do this we need a vector equation for the\nboundary; one such equation is $\\langle a\\cos t,b\\sin t\\rangle$, as\n$t$ ranges from 0 to $2\\pi$. We\ncan easily verify this by substitution:\n$${x^2\\over a^2}+{y^2\\over b^2}=\n{a^2\\cos^2 t\\over a^2}+{b^2\\sin^2t\\over b^2}=\n\\cos^2t+\\sin^2t=1.$$\nLet's consider the three possibilities for $f_1$ and $f_2$ above:\nUsing 0 and $x$ gives\n$$\\oint_C 0\\,dx+x\\,dy=\\int_0^{2\\pi} a\\cos(t)b\\cos(t)\\,dt=\n\\int_0^{2\\pi} ab\\cos^2(t)\\,dt.$$\nUsing $-y$ and 0 gives\n$$\\oint_C -y\\,dx+0\\,dy=\\int_0^{2\\pi} -b\\sin(t)(-a\\sin(t))\\,dt=\n\\int_0^{2\\pi} ab\\sin^2(t)\\,dt.$$\nFinally, using $-y/2$ and $x/2$ gives\n\\begin{align*}\n\\oint_C -{y\\over2}\\,dx+{x\\over2}\\,dy&=\n\\int_0^{2\\pi} -{b\\sin(t)\\over2}(-a\\sin(t))\\,dt\n+{a\\cos(t)\\over2}(b\\cos(t))\\,dt\t\\\\\n&=\\int_0^{2\\pi} {ab\\sin^2t\\over2}+{ab\\cos^2t\\over2}\\,dt=\n\\int_0^{2\\pi} {ab\\over2}\\,dt=\\pi ab.\n\\end{align*}\nThe first two integrals are not particularly difficult, but the third\nis very easy, though the choice of $f_1$ and $f_2$ seems more complicated.\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <1truecm,1truecm>\n\\setplotarea x from -3.1 to 3.1, y from -2.1 to 2.1\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 /\n\\put {$(0,b)$} [bl] <2pt,2pt> at 0 2\n\\put {$(a,0)$} [tl] <2pt,-2pt> at 3 0\n\\multiput {$\\bullet$} at 0 2 3 0 /\n\\ellipticalarc axes ratio 3:2 360 degrees from 3 0 center at 0 0\n\\endpicture}}\n\\caption{A ``standard'' ellipse, ${x^2\\over a^2}+{y^2\\over b^2}=1$. \\label{fig:standard ellipse}}\n\\end{figure}\n\nNow we look at the proof of Green's Theorem.\n\n\\begin{proof}\nWe cannot here prove Green's Theorem in general, but we can do a\nspecial case. We seek to prove that for a vector field $\\vect{f} = \\langle f_1, f_2 \\rangle$\n$$\\oint_C f_1 \\,dx + f_2\\,dy = \\iint_{D} {\\partial f_2\\over\\partial x}\n-{\\partial f_1\\over\\partial y} \\,dA.$$\nIt is sufficient to show that\n$$\\oint_C f_1 \\,dx=\\iint_{D}-{\\partial f_1 \\over\\partial y} \\,dA\\qquad\\hbox{and}\n\\qquad\\oint_C f_2 \\,dy=\\iint_{D} {\\partial f_2 \\over\\partial x}\\,dA,$$\nwhich we can do if we can compute the double integral in both possible\nways, that is, using $dA=dy\\,dx$ and $dA=dx\\,dy$.\n\nFor the first equation, we start with\n$$\\iint_{D}{\\partial f_1\\over\\partial y}\\,dA=\n\\int_a^b\\int_{g_1(x)}^{g_2(x)} {\\partial f_1\\over \\partial y}\\,dy\\,dx=\n\\int_a^b f_1(x,g_2(x))-f_1(x,g_1(x))\\,dx.$$\nHere we have simply used the ordinary Fundamental Theorem of Calculus,\nsince for the inner integral we are integrating a derivative with\nrespect to $y$: an antiderivative of $\\partial f_1/\\partial y$ with\nrespect to $y$ is simply $f_1(x,y)$, and then we substitute $g_1$ and\n$g_2$ for $y$ and subtract.\n\nNow we need to manipulate $\\oint_C f_1\\,dx$. The boundary of region $D$\nconsists of 4 parts, given by the equations $y=g_1(x)$, $x=b$,\n$y=g_2(x)$, and $x=a$. On the portions $x=b$ and $x=a$, $dx=0\\,dt$, so\nthe corresponding integrals are zero. For the other two portions, we\nuse the parametric forms $x=t$, $y=g_1(t)$, $a\\le t\\le b$, and\n$x=t$, $y=g_2(t)$, letting $t$ range from $b$ to $a$, since we are\nintegrating counter-clockwise around the boundary.\nThe resulting integrals give us\n\\begin{align*}\n\\oint_C f_1\\,dx = \\int_a^b f_1(t,g_1(t))\\,dt+\\int_b^a f_1(t,g_2(t))\\,dt\n&=\\int_a^b f_1(t,g_1(t))\\,dt-\\int_a^b f_1(t,g_2(t))\\,dt\t\\\\\n&=\\int_a^b f_1(t,g_1(t))-f_1(t,g_2(t))\\,dt\n\\end{align*}\nwhich is the result of the double integral times $-1$, as desired.\n\nThe equation involving $f_2$ is essentially the same, and left as an\nexercise.\n\\end{proof}\n\nWe can now rewrite Green's Theorem using the concepts of divergence and curl; these rewritten\nversions in turn are closer to some later theorems we will see.\n\nSuppose we write a two dimensional vector field in the\nform $\\vect{f}=\\langle f_1,f_2,0\\rangle$, where $f_1$ and $f_2$ are functions\nof $x$ and $y$. Then \n$$\\nabla\\times \\vect{f} =\n\\left|\n\\begin{matrix}\n\\vect{i}\t&\t\\vect{j}\t&\t\\vect{k}\t\\\\\n{\\partial \\over\\partial x}\t&\t{\\partial\\over\\partial y}\t&\t{\\partial \\over\\partial z}\t\\\\\nf_1\t&\tf_2\t&\t0\n\\end{matrix}\n\\right|=\n\\langle 0,0,{\\partial f_2\\over\\partial x}-{\\partial f_1\\over\\partial y}\\rangle,$$\nand so $(\\nabla\\times \\vect{f})\\cdot\\vect{k}=\\langle 0,0,{\\partial f_2\\over\\partial x}-{\\partial f_1\\over\\partial y}\\rangle\\cdot\n\\langle 0,0,1\\rangle = {\\partial f_2\\over\\partial x}-{\\partial f_1\\over\\partial y}$. So Green's Theorem says\n\\begin{equation}\\label{eq:greens theorem second form}\n\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}=\n\\int_{\\partial D} f_1\\,dx +f_2dy = \\iint_{D} {\\partial f_2\\over\\partial x}   - {\\partial f_1\\over\\partial y}   \\,dA\n=\\iint_{D}(\\nabla\\times \\vect{f})\\cdot\\vect{k}\\,dA.\n\\end{equation}\nRoughly speaking, the right-most integral adds up the curl (tendency\nto swirl) at each point in the region; the left-most integral adds up\nthe tangential components of the vector field around the entire\nboundary. Green's Theorem says these are equal, or roughly, that the\nsum of the ``microscopic'' swirls over the region is the same as the\n``macroscopic'' swirl around the boundary.\n\nNext, suppose that the boundary $\\partial D$ has a vector form\n$\\vect{r}(t)$, so that $\\vect{r}'(t)$ is tangent to the boundary, and\n$\\vect{T}=\\vect{r}'(t)/|\\vect{r}'(t)|$ is the usual unit tangent vector.\nWriting $\\vect{r}=\\langle x(t),y(t)\\rangle$ we get\n$$\\vect{T}={\\langle x',y'\\rangle\\over|\\vect{r}'(t)|}$$\nand then\n$$\\vect{N}={\\langle y',-x'\\rangle\\over|\\vect{r}'(t)|}$$\nis a unit vector perpendicular to $\\vect{T}$, that is, a unit normal to\nthe boundary. \nNow\n\\begin{align*}\n\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds&=\n\\int_{\\partial D} \\langle f_1, f_2\\rangle\\cdot{\\langle\n  y',-x'\\rangle\\over|\\vect{r}'(t)|} |\\vect{r}'(t)|dt=\n\\int_{\\partial D} f_1 y'\\,dt - f_2 x'\\,dt\t\\\\\n&=\\int_{\\partial D} f_1 \\,dy - f_2 \\,dx\n=\\int_{\\partial D} - f_2 \\,dx+ f_1\\,dy.\n\\end{align*}\nSo far, we've just rewritten the original integral using alternate\nnotation. The last integral looks just like the left side of Green's\nTheorem (\\ref{thm:greens theorem}) except that $f_1$ and $f_2$ have\ntraded places and $f_2$ has acquired a negative sign. Then applying\nGreen's Theorem we get \n$$\n\\int_{\\partial D} - f_2\\,dx+f_1\\,dy=\\iint_{D} {\\partial f_1\\over\\partial x}+{\\partial f_2\\over\\partial y}\\,dA=\n\\iint_{D} \\nabla\\cdot\\vect{f}\\,dA.$$\nSummarizing the long string of equalities, \n\\begin{equation}\\label{eq:greens theorem third form}\n\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds=\\iint_{D} \\nabla\\cdot\\vect{f}\\,dA.\n\\end{equation}\nRoughly speaking, the first integral adds up the flow across the\nboundary of the region, from inside to out, and the second sums the\ndivergence (tendency to spread) at each point in the interior. The\ntheorem roughly says that the sum of the ``microscopic'' spreads is\nthe same as the total spread across the boundary and out of the region.\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:GreensTheorem}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} 2y\\,dx + 3x\\,dy$, \nwhere $D$ is described by $0\\le x\\le1$, $0\\le y\\le 1$.\n\\begin{sol}\n\t$1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} xy\\,dx + xy\\,dy$, \nwhere $D$ is described by $0\\le x\\le1$, $0\\le y\\le 1$.\n\\begin{sol}\n\t$0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} e^{2x+3y}\\,dx + e^{xy}\\,dy$, \nwhere $D$ is described by $-2\\le x\\le 2$, $-1\\le y\\le 1$.\n\\begin{sol}\n\t$1/(2e)-1/(2e^7)+e/2-e^7/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} y\\cos x\\,dx + y\\sin x\\,dy$, \nwhere $D$ is described by $0\\le x\\le \\pi/2$, $1\\le y\\le 2$.\n\\begin{sol}\n\t$1/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} x^2y\\,dx + xy^2\\,dy$, \nwhere $D$ is described by $0\\le x\\le 1$, $0\\le y\\le x$.\n\\begin{sol}\n\t$-1/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} x\\sqrt{y}\\,dx + \\sqrt{x+y}\\,dy$, \nwhere $D$ is described by $1\\le x\\le 2$, $2x\\le y\\le 4$.\n\\begin{sol}\n\t$(2\\sqrt3-10\\sqrt5+8\\sqrt6)/3-2\\sqrt2/5+1/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} (x/y)\\,dx + (2+3x)\\,dy$, \nwhere $D$ is described by $1\\le x\\le 2$, $1\\le y\\le x^2$.\n\\begin{sol}\n\t$11/2-\\ln(2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} \\sin y\\,dx + \\sin x\\,dy$, \nwhere $D$ is described by $0\\le x\\le \\pi/2$, $x\\le y\\le \\pi/2$.\n\\begin{sol}\n\t$2-\\pi/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} x\\ln y\\,dx$,\nwhere $D$ is described by $1\\le x\\le 2$, $\\ds e^x\\le y\\le e^{x^2}$.\n\\begin{sol}\n\t$-17/12$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} \\sqrt{1+x^2}\\,dy$, \nwhere $D$ is described by $-1\\le x\\le 1$, $x^2\\le y\\le 1$.\n\\begin{sol}\n\t$0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} x^2y\\,dx - xy^2\\,dy$, \nwhere $D$ is described by $x^2+y^2\\le 1$.\n\\begin{sol}\n\t$-\\pi/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int_{\\partial D} y^3\\,dx + 2x^3\\,dy$, \nwhere $D$ is described by $x^2+y^2\\le 4$.\n\\begin{sol}\n\t$12\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\oint_C (y-\\sin(x))\\,dx + \\cos(x) \\, dy$,\nwhere $C$ is the boundary of the triangle with vertices $(0,0)$,\n$(1,0)$, and $(1,2)$ oriented counter-clockwise.\n\\begin{sol}\n\t$2\\cos(1)-2\\sin(1)-1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFinish our proof of Green's Theorem by showing that\n$\\ds\\oint_C f_2\\,dy=\\iint_{D} {\\partial f_2\\over\\partial x}\\,dA$.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "c66f76839adee66bd61464ab40b3a5dfbf646996", "size": 14951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-4-green-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-4-green-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-4-green-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": 38.1403061224, "max_line_length": 215, "alphanum_fraction": 0.6791518962, "num_tokens": 5665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.679859236853994}}
{"text": "\\documentclass[final]{siamart171218}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{bm}\n\n\\setlength{\\oddsidemargin}{0.65in}\n\\setlength{\\evensidemargin}{0.65in}\n\n\\title{Differential count analysis with a topic model}\n\n\\author{Peter Carbonetto\\thanks{Dept. of Human Genetics and the Research Computing Center, University of Chicago, Chicago, IL}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Motivation, and overview of methods}\n\nThe aim of this document is to derive, from first principles, a method\nfor analysis of differential gene expression using a topic model (also\nknown as ``grade of membership model'' \\cite{dey-2017}). This method\nmay have other uses --- say, to identify ``key words'' in a topic\nmodeling analysis of text documents --- but since our main motivation\nis analysis of gene expression data, we describe the methods with that\napplication in mind.\n\nTopic modeling brings a new twist to analysis of differential gene\nexpression: In conventional differential expression analysis, each\nsample is assigned to a single condition; in topic modeling, the\nassignments to each topic are {\\em proportional.} This needs to be\naccounted for in developing the new methods for differential\nexpression analysis.\n\nFor motivation, we begin with the ``log-fold change'' statistic\ncommonly used in microarray and RNA sequencing experiments to quantify\nexpression differences between two conditions (e.g.,\n\\cite{cui-churchill-2003, quackenbush-2002}). The log-fold change for\ngene $j$ and condition $k$ is a ratio of two conditional expectations,\n\\begin{equation}\n\\beta_{jk} \\equiv\n\\log_2 \\frac{E[\\,x_j \\,|\\, \\mathrm{condition} = k\\,]}\n            {E[\\,x_j \\,|\\, \\mathrm{condition} \\neq k\\,]},\n\\label{eq:lfc}\n\\end{equation}\nwhere $x_j$ is the measured expression level of gene\n$j$.\\footnote{Defining $x_{jk}$ as the total gene expression for gene\n  $j$ among all samples (expression profiles) in condition $k$, $x_j$\n  as the total gene expression for gene $j$ in all samples, $n_k$ as\n  the number of samples in condition $k$, and $n$ as the total sample\n  size, the log-fold change can be computed as $\\beta_{jk} = \\log_2\n  \\Big\\{ \\frac{x_{jk}}{x_j - x_{jk}} \\times \\frac{n - n_k}{n_k}\n  \\Big\\}$.} The way in which the expression level $x_j$ is defined can\nlead to different log-fold change statistics. For example, several\npopular methods for analyzing differential expression compare changes\nin {\\em relative} expression (say, relative to total expression in a\ncell) \\cite{bullard-2010, voom, DESeq2, edgeR}. As we will see, a\ntopic modeling perspective provides a natural way to analyze\ndifferential gene expression when comparing either relative or\nabsolute expression levels.\n\n\\section{A binomial model}\n\nTo develop the methods, we begin with a simple binomial model that\npredicts expression of a single gene given the proportional\nassignments to a topic:\n\\begin{equation}\nx_i \\sim \\mathrm{Binom}(s_i, \\pi_i).\n\\label{eq:binomial}\n\\end{equation}\nHere, $x_i$ is the expression level of the target gene in sample $i$,\n$s_i$ is the total expression in sample $i$, and $\\mathrm{Binom}(n,\n\\theta)$ denotes the binomial distribution with $n$ trials and success\nprobability $\\theta$. In this simple model, the binomial probabilities\nare defined as\n\\begin{equation}\n\\pi_i = (1 - q_i) p_0 + q_i p_1,\n\\label{eq:binomial-prob}\n\\end{equation}\nwhere $q_i \\in [0,1]$ is the (known) proportion of sample $i$ that is\nattributed to the topic, and $p_0, p_1 \\in [0, 1]$ are two unknowns to\nbe estimated.\\footnote{This is a special case of the {\\em linear\n    probability model} in econometrics called \\cite{stock-watson}. The\n  linear probability model would be typically written as $\\pi_i = b_0\n  + q_i b$, where $b_0 = p_0$ and $n = p_1 - p_0 \\in [-1, +1]$. This\n  is a regression model for the binomial probability $\\pi_i$, in which\n  $\\pi_i$ increases linearly with topic proportion $q_i$.}\n\nStatistical inference with this simple binomial model implements\nanalysis of differential gene expression. In particular, $\\beta \\equiv\n\\log_2(p_1/p_0)$ is the {\\em log-fold change in relative expression.}\nTo show that this is so, consider the following statistical process\nfor generating the counts $x_1, \\ldots, x_n$:\n\\vspace{1em}\n\\begin{itemize}\n\n\\item for $i = 1, \\ldots, n$\n\\begin{enumerate}\n\n  \\item for $t = 1, \\ldots, s_i$\n  \\begin{enumerate}\n\n  \\item Sample a topic, $z_{it} \\sim \\mathrm{Binom}(1,q_i)$.\n\n  \\item Sample a gene, $w_{it} \\,|\\, z_{it} \\sim \\left\\{\\begin{array}{ll}\n  \\mathrm{Binom}(1,p_1) & \\mbox{if $z_{it} = 1$} \\\\\n  \\mathrm{Binom}(1,p_0) & \\mbox{otherwise.}\n  \\end{array}\\right.$\n\n  \\end{enumerate}\n\n  \\item Generate the final gene count, \n  $x_i \\leftarrow w_{i1} + \\cdots + w_{is_i}$.\n\n\\end{enumerate}\n\\end{itemize}\n\\vspace{1em} In this statistical process, $q_i = p(z_{it} = 1)$ is the\ntopic probability, $p_1 = p(w_{it} = 1 \\,|\\, z_{it} = 1)$ is the\nconditional probability that the gene is expressed given membership to\nthe topic, and $p_0 = p(w_{it} = 1 \\,|\\, z_{it} = 0)$ is the\nprobability that the gene is expressed when not belonging to the\ntopic. Therefore, we have\n\\begin{equation}\n\\beta \\equiv \\log_2 \\frac{p_1}{p_0}  \n= \\log_2 \\frac{p(w_{it} = 1 \\,|\\, z_{it} = 1)}\n            {p(w_{it} = 1 \\,|\\, z_{it} = 0)}.\n\\label{eq:lfc-binom}\n\\end{equation}\n{\\em This is the log-fold change statistic for relative expression\n  given proportional topic assignments $q_1, \\ldots, q_n$.} The\nbinomial model \\eqref{eq:binomial} can in fact be derived from this\nstatistical process (proof not shown). Therefore, estimating $p_0,\np_1$ for the binomial model \\eqref{eq:binomial} provides an estimate\nof the log-fold change \\eqref{eq:lfc-binom}.\n\nBefore continuing, we point out that the $s_i$'s, in practice, do not\nneed to be the total expression for each sample $i$ ({\\em i.e.}, the\ntotal counts); for example, some researchers have suggested setting\n$s_i$ to some pre-defined quantile of the sample's nonzero count\ndistribution (e.g., \\cite{bullard-2010}). This approach has been\nmotivated in settings where a small number of genes are much more\nhighly expressed than the others, and therefore these few genes have a\nlarge effect relative expression levels. In short, the binomial model\nis quite flexible, and can accommodate different relative differential\nexpression analyses defines the $s_i$'s. The only constraint on $s_i$\nis that it cannot be smaller than $x_i$.\n\n\\section{A Poisson model}\n\nThe Poisson likelihood with rate $\\lambda = n\\theta$ closely\napproximates the Binomial likelihood $\\mathrm{Binom}(n, \\theta)$ when\n$\\theta$ is small and $n$ is large. (The Poisson arises as the\nlimiting distribution of the binomial as $n \\rightarrow \\infty, \\pi\n\\rightarrow 0, n\\theta \\rightarrow \\lambda$.) This is usually the case in\ngene expression studies; the total gene expression is large, whereas\nthe contribution of each gene is small, even for genes with the\nhighest levels of expression. This suggests a Poisson model of\nexpression $x_i$ given topic proportions $q_i$:\n\\begin{equation}\nx_i \\sim \\mathrm{Poisson}(t_i \\lambda_i),\n\\label{eq:poisson}\n\\end{equation}\nin which the Poisson rates are defined as\n\\begin{equation}\n\\lambda_i = (1 - q_i) f_0 + q_i f_1,\n\\end{equation}\nand the two unknowns to be estimated are $f_0, f_1 \\geq 0$. Observe\nthat, unlike the binomial model, the unknowns for the Poisson model\nare not constrained to be in $[0, 1]$, and so they do not necessarily\nrepresent probabilities. However, by setting $t_i = s_i$, we have that\n\\begin{align*}\nf_0 &\\approx p_0 \\\\\nf_1 &\\approx p_1,\n\\end{align*}\nwhen $p_0, p_1$ are close to zero and all $s_i$ are large. (See the\nAppendix for an alternative motivation of the Poisson model.)\n\nIn the next section, we derive the mathematical expressions needed to\nimplement differential count analysis based on the Poisson model.\n\n\\section{Poisson model derivations}\n\nTo derive an algorithm for computing MLEs of $f_0, f_1$ in the Poisson\nmodel \\eqref{eq:poisson}, we begin with the log-likelihood,\n\\begin{equation}\n\\ell(f_0, f_1) \\equiv \\log p(x \\,|\\, f_0, f_1) = \n\\sum_{i=1}^n x_i \\log (t_i \\lambda_i) - t_i \\lambda_i +\n\\mbox{const,}\n\\label{eq:loglik-poisson}\n\\end{equation}\nin which the ``const'' captures all terms that do not depend on $f_0$\nor $f_1$. A useful identity is that the partial derivative of the\nlog-likelihood with respect to $\\lambda_i$ is\n\\begin{equation*}\n\\frac{\\partial\\ell}{\\partial\\lambda_i} = \\frac{x_i}{\\lambda_i} - t_i.\n\\end{equation*}\nMaking use of this result, the partial derivatives of the\nlog-likelihood with respect to the model parameters $f_0$ and $f_1$\nare\n\\begin{align}\n\\frac{\\partial\\ell}{f_0} &= \n\\sum_{i=1}^n (x_i/\\lambda_i - t_i) \\times (1-q_i) \\\\\n\\frac{\\partial\\ell}{f_1} &= \n\\sum_{i=1}^n (x_i/\\lambda_i - t_i) \\times q_i.\n\\end{align}\nWe use a quasi-Newton method implemented in the R function {\\tt optim}\nto minimize the negative log-likelihood\n\\eqref{eq:loglik-poisson}. Note that in the special case in which all\nthe topic proportions are either 0 or 1, the MLEs have a simple\nclosed-form solution:\n\\begin{align}\nf_0 &= \\frac{\\sum_{i=1}^n (1 - q_i) x_i}{\\sum_{i=1}^n (1 - q_i) t_i} \\\\\nf_1 &= \\frac{\\sum_{i=1}^n q_i x_i}{\\sum_{i=1}^n q_i t_i} \n\\end{align}\n\n\\subsection{EM for Poisson model} \n\nWe also implement a simple EM algorithm for fitting the Poison model\n\\eqref{eq:poisson}. The key is to introduce latent variables $a_i \\sim\n\\mathrm{Poisson}(t_i (1-q_i) f_0)$ and $b_i \\sim \\mathrm{Poisson}(t_i\nq_i f_1)$, then work with the expected complete log-likelihood\n$E[\\,\\log p(x, a, b \\,|\\, f_0, f_1)\\,]$. The ``M-step'' updates work\nout to\n\\begin{align}\nf_0 &= \\frac{\\sum_{i=1}^n \\phi_i}{\\sum_{i=1}^n t_i(1-q_i)} \\\\\nf_1 &= \\frac{\\sum_{i=1}^n \\gamma_i}{\\sum_{i=1}^n t_i q_i},\n\\end{align}\nwhere we have introduced notation for the posterior expectations of\nthe latent variables, $\\phi_i \\equiv E[a_i]$ and $\\gamma_i \\equiv\nE[b_i]$. It can be shown that the posterior distribution of $(a_i,\nb_i)$ is multinomial with number of trials $x_i$ and event\nprobabilities proportional to $(1-q_i) f_0$ and $q_i f_1$. So the\nposterior expectations computed in the ``E-step'' are\n\\begin{align}\n\\phi_i   &= x_i (1 - q_i) f_0 / \\lambda_i \\\\\n\\gamma_i &= x_i q_i f_1 / \\lambda_i.\n\\end{align}\nThis completes the description of the EM algorithm for the Poisson\nmodel.\n\n\\subsection{glm identity parameterization}\n\nOnce we have obtained MLEs of $f_0$ and $f_1$, we would also like to\ncharacterize uncertainty in these estimates---that is, compute the\nstandard error (s.e.). In particular, we are interested in the s.e. of\nthe log-fold change statistic, $\\beta$. As an intermediate step, we\nconsider the ``glm identity'' parameterization $\\lambda_i = b_0 + q_i\nb$, where $b = f_1 - f_0$ and $b_0 = f_0$. This parameterization can\nbe implemented using {\\tt glm} in R with {\\tt family = poisson(link =\n  \"identity\")}, and therefore can be used to verify our calculations.\n\nUnder the Laplace approximation to the likelihood at the MLE\n$(\\hat{b}_0, \\hat{b})$, the covariance matrix is $-H^{-1}$, where $H$\nis the $2 \\times 2$ matrix of second-order partial derivatives,\n\\begin{equation*}\n\\frac{\\partial^2\\ell}{\\partial b_0^2} = \n-\\sum_{i=1}^n \\frac{x_i}{\\lambda_i^2}, \\qquad\n\\frac{\\partial^2\\ell}{\\partial b^2} = \n-\\sum_{i=1}^n \\frac{x_i q_i^2}{\\lambda_i^2}, \\qquad\n\\frac{\\partial^2\\ell}{\\partial b_0 \\partial b} = \n-\\sum_{i=1}^n \\frac{x_i q_i}{\\lambda_i^2}.\n\\end{equation*}\nThis result can be used to obtain the standard errors and $z$-scores\nfor $\\hat{b}_0$ and $\\hat{b}$.\n\n\\subsection{Log-fold change parameterization}\n\nHere we derive the s.e. for the MLE of $\\beta \\equiv \\log\n(f_1/f_0)$. (For convenience, we use the natural logarithm here rather\nthan the base-2 logarithm; to obtain the base-2 log-fold change\nstatistic and its s.e., divide by $\\log 2$.) With this new\nparameterization, the Poisson rates are\n\\begin{equation}\n\\lambda_i = f_0 \\times \\{1 - q_i(1-e^{\\beta})\\}\n\\end{equation}\nThe second-order partial derivatives needed to compute the $2 \\times\n2$ Hessian are\n\\begin{align}\n\\frac{\\partial\\ell}{f_0} &= \\frac{1}{f_0} \\sum_{i=1}^n \nx_i - t_i\\lambda_i \\\\\n\\frac{\\partial\\ell}{\\beta} &= f_1 \\sum_{i=1}^n \n(x_i/\\lambda_i - t_i) \\times q_i \\\\\n\\frac{\\partial^2\\ell}{f_0^2} &=\n-\\frac{1}{f_0^2} \\sum_{i=1}^n x_i \\\\\n\\frac{\\partial^2\\ell}{\\beta^2} &= \n-f_1 \\sum_{i=1}^n t_i q_i - x_i f_0 q_i (1-q_i)/\\lambda_i^2 \\\\\n\\frac{\\partial^2\\ell}{\\partial f_0 \\partial\\beta} &= \n-\\frac{f_1}{f_0} \\sum_{i=1}^n t_i q_i.\n\\end{align}\nThe expression for $\\frac{\\partial^2\\ell}{\\partial f_0 \\partial\\beta}$\nis the more complicated one, but fortuately it simplifies at the MLE,\n$\\beta = \\hat{\\beta}$ (at the MLE, the gradient of the log-likelihood\nwith respect to $\\beta$ vanishes):\n\\begin{equation}\n\\frac{\\partial^2\\ell}{\\beta^2} = -f_1^2 \\sum_{i=1}^n x_i (q_i/\\lambda_i)^2.\n\\end{equation}\nTherefore, at the MLE $\\beta = \\hat{\\beta}$, the standard error is\n\\begin{equation}\n\\mathrm{se}(\\hat{\\beta}) = \\frac{1}{f_1} \\times \n\\sqrt{\\frac{\\bar{a}}{\\bar{a} \\times \\bar{c} - \\bar{b}^2}},\n\\end{equation}\nwhere I've defined\n\\begin{equation*}\n\\bar{a} = \\sum_{i=1}^n x_i, \\qquad\n\\bar{b} = \\sum_{i=1}^n t_i q_i, \\qquad\n\\bar{c} = \\sum_{i=1}^n x_i (q_i/\\lambda_i)^2.\n\\end{equation*}\nFrom this, the $z$-score is recovered as $z =\n\\hat{\\beta}/se(\\hat{\\beta})$.\n\n\\appendix\n\n\\section{More on Poisson model}\n\nConsider the following process for generating the counts $x_1, \\ldots,\nx_n$:\n\\begin{itemize}\n\n\\item for $i = 1, \\ldots, n$\n\\begin{enumerate}\n\n\\item $a_i \\sim \\mathrm{Poisson}(f_1)$ \n\\hfill Sample the within-topic gene count. \\hspace{2em}\n\n\\item $b_i \\sim \\mathrm{Poisson}(f_0)$ \n\\hfill Sample the outside-topic gene count. \\hspace{2em}\n\n\\item $a_i' \\sim \\mathrm{Binom}(a_i, q_i)$ \n\\hfill Subsample the within-topic genes. \\hspace{2em}\n\n\\item $b_i' \\sim \\mathrm{Binom}(b_i, 1-q_i)$ \n\\hfill Subsample the outside-topic genes. \\hspace{2em}\n\n\\item $x_i \\leftarrow a_i' + b_i'$ \n\\hfill Generate the final gene count. \\hspace{2em}\n\n\\end{enumerate}\n\\end{itemize}\nIn this generative process, $f_1 = E[a_i]$ represents the\nwithin-topic gene rate, and $f_0 = E[b_i]$ is the outside-topic gene\nrate, and therefore \n\\begin{equation}\n\\beta^{\\mathsf{abs}} \\equiv \n\\log_2 \\frac{f_1}{f_0} = \\log_2 \\frac{E[a_i]}{E[b_i]}\n\\label{eq:lfc-poisson}\n\\end{equation}\nis the {\\em log-fold change statistic in (absolute) expression given\n  proportional topic assignments $q_1, \\ldots, q_n$.} For intuition,\nwhen all the topic proportions $q_i$ are 0 or 1, this statistical\nprocess simplify to $x_i \\sim \\mathrm{Poisson}(f_1)$ if $q_i = 1$, and\n$x_i \\sim \\mathrm{Poisson}(f_0)$ if $q_i = 0$, and so\n\\eqref{eq:lfc-poisson} would reduce to the ratio of the mean\nexpression levels inside and outside the topic. The Poisson model\n\\eqref{eq:poisson} can be derived from this statistical process, and\nso estimating $f_0, f_1$ for the Poisson model \\eqref{eq:poisson}\nprovides an estimate of the log-fold change \\eqref{eq:lfc-poisson}.\n\n\\bibliographystyle{siamplain}\n\\bibliography{diffcount}\n\n\\end{document}\n\n", "meta": {"hexsha": "4dd95326d0587a767b322d59e3c4329c3bcb2e67", "size": 14947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inst/derivations/diffcount/diffcount.tex", "max_stars_repo_name": "stephenslab/fastTopics", "max_stars_repo_head_hexsha": "b64d729c2938e763df5756781170510d5791ef92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2020-02-10T03:38:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T15:48:57.000Z", "max_issues_repo_path": "inst/derivations/diffcount/diffcount.tex", "max_issues_repo_name": "PeiKaLunCi/fastTopics", "max_issues_repo_head_hexsha": "9eda1f541cf9ed0371d022b09e7c70abc2681ebf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2020-04-28T18:27:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T13:02:36.000Z", "max_forks_repo_path": "inst/derivations/diffcount/diffcount.tex", "max_forks_repo_name": "PeiKaLunCi/fastTopics", "max_forks_repo_head_hexsha": "9eda1f541cf9ed0371d022b09e7c70abc2681ebf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-22T10:55:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-30T06:05:53.000Z", "avg_line_length": 41.2900552486, "max_line_length": 127, "alphanum_fraction": 0.7216832809, "num_tokens": 4848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.679837497552885}}
{"text": "\\section{Model of Muscle Contraction}\\label{sec:model_muscle_contraction}\n\n\n%Because of possibly large strains, a nonlinear hyperelastic formulation is used. \n%For mathematical foundations in continuum mechanics, we refer to basic literature such as the books of Holzapfel \\cite{holzapfel2000nonlinear} and Marsden and Hughes \\cite{marsden1994mathematical}, as well as literature on the application of the finite element method in continuum mechanics \\cite{zienkiewicz1977finite,SUSSMAN1987357,zienkiewicz2005finite}.\n\n%The following section provides a more profound introduction of solid mechanics to complement the overview given in \\cref{sec:model_muscle_contraction}. It also describes the finite element discretization of the solid mechanics model and the algorithms used to obtain a numeric solution. \n\nMuscle contraction is described on the organ level by a solid mechanics model. The goal is to describe the deformation of the tissue caused by the internal forces that are generated by sarcomeres and as a response to outer constraints such as applied forces, the attachment to tendons and inertia effects.\n\nDifferent modeling approaches exist to describe the mechanical muscle behavior. Dynamic \\emph{finite elasticity} methods for large strains exist that use hyperelastic materials, both compressible and incompressible. Further, \\emph{linear elasticity} descriptions with linearizations at various levels are used in appropriate applications where small strains can be assumed. The whole range from simplifying linearized models to accurate nonlinear approaches can be found in the literature, sometimes with varying conventions and symbols.\nIn this section, we introduce consistent notation and formulate the model equations for both approaches. The discretization and solution is discussed later in \\cref{sec:discretization_mechanics}.\n\nThe derivation largely follows the book of Holzapfel \\cite{holzapfel2000nonlinear} and the discretization follows the work of Zienkiewicz, Taylor et al. \\cite{zienkiewicz1977finite,zienkiewicz2005finite}. Further details can be found also in the book of Marsden and Hughes \\cite{marsden1994mathematical}.\n\n%  The implementation of a solver for such generic descriptions exploiting parallel execution and integrating a multi-scale biomechanics model, being a contribution of this work, is an interdisciplinary endeavour. Therefore, we introduce consistent notation and summarize the required basics and the derivation up to the final algorithm  such that it may serve also readers that are not specialized in the field of continuum mechanics. \n\n% -v-\n\n\\subsection{Geometric Description}\\label{sec:geometric_description}\n\n% introduce quantities\n% F, C, E, E(u), variation δE\n%  S, P, sigma\n\nWe begin with the geometric description of the material body and define the basic quantities that are subsequently used to describe the physics. We consider the 3D muscle domain $\\Omega_0=\\Omega_M \\subset \\R^3$ in reference configuration at time $t=0$ that deforms into a current configuration $\\Omega_t$ at time $t$. The material points are given by $\\bfX \\in \\Omega_0$. The corresponding points $\\bfx \\in \\Omega_t$ in the current configuration are defined by the function $\\bfx = \\bfvarphi_t(\\bfX)$. \n\nIn the following, capital letters refer to quantities in material or Lagrangian description, i.e., defined in the reference configuration and small letters refer to quantities in spatial or Eulerian description, i.e., defined in the current configuration.\n\nThe relation of point coordinates in the current configuration with respect to the reference configuration can also be described by the displacements field $\\bfU$:\n\\begin{align*}\n  \\bfx(\\bfX) = \\bfX + \\bfU(\\bfX).\n\\end{align*}\nThe symbol $\\bfu$ with $\\bfu(\\bfx(\\bfX))=\\bfU(\\bfX)$ denotes the displacements formulated in current configuration.\nThe current velocity $\\bfv$ is the time derivative of the displacements, $\\bfv := \\dot{\\bfu}$.\n\nThe deformation gradient $\\bfF$ is the second order tensor that is obtained by differentiating the function $\\bfvarphi_t$. It is given using the unit vectors $\\bfe_i$ and components $F_{aA}$:\n\\begin{align*}\n  \\bfF &= F_{aA}\\,\\bfe_a \\otimes \\bfe_A, \\quad && F_{aA} = \\p{x_a}{X_A}.\n\\end{align*}\nCapital and small indices refer to reference and current configuration, respectively. The deformation gradient can also be expressed using the displacement field $\\bfU$:\n\\begin{align}\\label{eq:solid1}\n  \\bfF = \\bfI + ∇\\bfU.\n\\end{align}\n%\nHere and in the following, the gradient symbol $∇$ refers to differentiation with respect to material coordinates $\\bfX$. \nWe assume Cartesian coordinates.\n\n% tangent, normal, volume map\nThe determinant of the deformation gradient is $J:= \\det \\bfF>0$. It is positive for any physically valid transformation.\nThe deformation gradient is used to map geometric quantities from the reference to the current configuration:\n\\begin{subequations}\\label{eq:geometry_maps}\n  \\begin{align}\n    \\bft &= \\bfF\\,\\bfT, & \\text{(tangent map)} \\label{eq:tangent_map}\\\\[4mm]\n    \\bfa &= \\cof(\\bfF)\\,\\bfA, & \\text{(normal map)} \\label{eq:normal_map}\\\\[4mm]\n    v &= J\\,V. & \\text{(volume map)}\\label{eq:volume_map}\n  \\end{align}\n\\end{subequations}\n%\nAs given in \\cref{eq:tangent_map} and visualized in \\cref{fig:geometric_quantities}, the tensor $\\bfF$ maps material tangents $\\bfT$ in $\\Omega_0$ to the corresponding spatial line elements $\\bft$ in $\\Omega_t$. \nAccordingly, the spatial stretch at a point $\\bfx \\in \\Omega_t$ in a certain direction is given by $\\lambda=\\sqrt{\\bflambda^\\top\\,\\bflambda}$ with $\\bflambda = \\bfF\\,\\bfM$, where $\\bfM$ is a material line element with unit length pointing in the respective Lagrangian direction.\n\nIn \\cref{eq:normal_map}, the cofactor of $\\bfF$ given by $\\cof(\\bfF) = J\\,\\bfF^{-\\top}$ maps normals $\\bfA$ and surface areas $|\\bfA|$ from $\\Omega_0$ to the corresponding values $\\bfa$ and $|\\bfa|$ in $\\Omega_t$. Nanson's formula, $\\d \\bfa = \\cof(\\bfF)\\,\\d\\bfA$, is used to transform surface integrals from Eulerian to Lagrangian description.\nNote that tangents at a point $\\bfX$ live in the tangent space $T_\\bfX\\Omega_0$ and normals live in the co-tangent space $T^\\ast_\\bfX\\Omega_0$.\n\n\\Cref{eq:volume_map} describes the volume map from $\\Omega_0$ to $\\Omega_t$, which simply scales the reference volume $V$ by the determinant $J$ to obtain the volume $v$ in the current configuration.\n\n% geometric quantities\n\\begin{figure}\n  \\centering%\n  \\def\\svgwidth{0.7\\textwidth}\n  \\input{images/theory/geometric_quantities.pdf_tex}%\n  \\caption{Vector spaces and variables used in the geometric description of the solid mechanics model. The left side shows the reference configuration with tangent and co-tangent space of point $\\bfX$. The right side shows tangent and co-tangent space for the current domain and a point $\\bfx$. The spatial stretch $\\lambda$ is defined by mapping a material element $\\bfM$ to the current configuration. The maps $\\bfvarphi_t$, $\\bfF$ and $\\bfF^{-\\top}$ map tangents $\\bfT,\\bft$ and normals $\\bfA,\\bfa$ between the configurations.}%\n  \\label{fig:geometric_quantities}%\n\\end{figure}\n\nFurthermore, the deformation gradient $\\bfF$ is used to define the right Cauchy Green tensor $\\bfC = \\bfF^\\top\\bfF$, which maps from tangent to co-tangent space in reference configuration, and subsequently the Green-Lagrange strain tensor:\n%\n\\begin{align*}\n  \\bfE = \\dfrac12(\\bfC - \\bfI).\n\\end{align*}\n%\nThis strain measure can be interpreted as comparing the current Lagrangian metric $\\bfC$, a measure for the symmetric part of the current deformation, with the reference metric which is the identity. Using \\cref{eq:solid1}, the Green-Lagrange strain tensor can be formulated in terms of derivatives of the displacements:%\n\\begin{align}\\label{eq:green_lagrange_u}\n  \\bfE &= \\dfrac12\\big((∇\\bfU)^\\top + ∇\\bfU + ∇\\bfU^\\top ∇\\bfU\\big).\n\\end{align}\n\nIn case of small displacements, a simplification is to not distinguish between reference and current configuration.\nThe strain expression given in \\cref{eq:green_lagrange_u} can be linearized by neglecting products of the derivatives and using the spatial displacements $\\bfu$ instead of $\\bfU$. As a result, the linearized strain tensor $\\eps$ is given by:\n\\begin{align}\\label{eq:linearized_helper3}\n  \\bfeps = \\dfrac12\\big((∇\\bfu)^\\top + ∇\\bfu\\big).\n\\end{align}\nIt can be used together with linear material models to derive a completely linear model.\n\n\\subsection{Stress Metrics}\n\nContinuum mechanical models establish equations for the unknown displacement function $\\bfu$ and its evolution in time via relations between stresses and strains. In the following, we introduce the required stress metrics.\n\n% stress measures \nThe Cauchy stress tensor $\\bfsigma$ results from Euler's cut principle: we consider the mechanical action on an arbitrary, virtual cut out of the body in current configuration. The contact forces on the cut surface at a point $\\bfx$ are described by the traction force $\\bft$.\nThe traction vector acts on the current configuration and is a function of the position $\\bfx \\in \\Omega_t$ and the local orientation of the cut given by the normal vector $\\bfn$. Cauchy's theorem states that this relation is linear and can be described by the second order Cauchy stress  tensor $\\bfsigma$:\n\\begin{align}\\label{eq:cauchy_theorem}\n  \\bft = \\bfsigma \\cdot \\bfn.\n\\end{align}\n\nThus, the Cauchy stress describes the \\say{true stress} of contact forces per deformed surface area. Both slots of the second order tensor are associated with the current configuration. More specifically, $\\bfsigma$ is contravariant and maps from a normal $\\bfn$ in co-tangent space $T^\\ast_\\bfx\\Omega_t$ to the traction $\\bft$ in tangent space $T_\\bfx\\Omega_t$. \n\nWhile the physical description is natural in this Eulerian setting, the numerical treatment is more convenient in the Lagrangian setting, where we can integrate over a non-deforming domain. \nMoreover, a two-point setting, where surface areas are measured in the undeformed configuration and traction forces are measured in the deformed configuration, is often useful in engineering. This is the natural setting, e.g., in tension tests. Therefore, other stress measures involving the reference configuration are defined.\n\n% numerics -> physics\n% pull-back, push-back\nUsing the mappings presented in \\cref{eq:geometry_maps}, all quantities can be transformed between both configurations. \nThe physical derivation can be carried out equivalently in a Lagrangian or Eulerian setting and switching between them is possible at any point in the derivation. For this purpose, two operations are defined: the pull-back $\\varphi^\\ast(\\bfa) = \\bfF^\\top\\bfa\\,\\bfF$ and push-forward operations $\\varphi_\\ast(\\bfA) = \\bfF^{-\\top}\\bfA\\,\\bfF^{-1}$, which bring tensors from Eulerian to Lagrangian description and vice-versa.\n\n% sigma, 1st PK, 2nd PK\nThe first Piola-Kirchhoff stress tensor $\\bfP$ measures contact forces in the current configuration with regard to the area of the reference configuration and relates to the Cauchy stress as $\\bfP = \\bfsigma\\,\\cof(\\bfF)$. The second Piola-Kirchhoff tensor $\\bfS$ is a fully Lagrangian field given as the pull-back of the Cauchy stress scaled by $J$:%\n\\begin{align*}\n  \\bfS = \\varphi^\\ast(J\\,\\bfsigma) = J\\,\\bfF^{-1}\\bfsigma\\,\\bfF^{-\\top}.\n\\end{align*}\n%It appears in the summary of the muscle contraction model in \\cref{eq:contraction} in connection with the strain energy function $\\Psi$.\n\n% stress tensors\n\\begin{figure}\n  \\centering%\n  \\def\\svgwidth{0.5\\textwidth}\n  \\input{images/theory/stress_tensors.pdf_tex}%\n  \\caption{Stress tensors and geometric maps that can be used together in a solid mechanics formulation. The right Cauchy-Green tensor $\\bfC$  and the second Piola-Kirchhoff stress $\\bfS$ are dual Eulerian tensors and map between tangent space $T_\\bfX\\Omega_0$ and co-tangent space $T^\\ast_\\bfX\\Omega_0$ in the reference domain. The deformation gradient $\\bfF$ and the first Piola-Kirchhoff stress $\\bfP$ are dual two-point tensors mapping from the reference to the current configuration. The Cauchy stress $\\bfsigma$ is defined entirely in the Eulerian setting.\n  %The Eulerian metric $\\bfg$, which is the identity in cartesian coordinates and the Kirchhoff stress $J\\,\\bfsigma$ (where $\\bfsigma$ is the Cauchy stress) are the dual objects in the Eulerian setting. All three pairs of dual tensors are linked together by transformations such as pull-back and push-forward.\n  }%\n  \\label{fig:stress_tensors}%\n\\end{figure}\n\n\\Cref{fig:stress_tensors} summarizes the geometric maps by black arrows and the stress measures by red arrows. \n%To relate strains and stresses in a material model, the corresponding tensors have to be dual objects. Here, three settings are possible: The Eulerian setting uses the metric $\\bfg$ and the dual Kirchhoff stress $J\\,\\bfsigma$. The two-point setting uses the deformation gradient $\\bfF$ and the dual first Piola-Kirchhoff stress $\\bfP$. The Lagrangian setting uses the right Cauchy-Green tensor $\\bfC$ and the dual second Piola-Kirchhoff stress $\\bfS$. \n%Different matching pairs of strain and stress tensors can be used to describe physical relations. \nThe Lagrangian setting defines the right Cauchy-Green tensor $\\bfC$ and the second Piola-Kirchhoff stress tensor $\\bfS$.\nWe use these quantities in the derivation of the discretized equations, because the Lagrangian formulation is natural for this task and allows integrating over the non-deforming domain $\\Omega_0$.\n\nThe Cauchy stress $\\bfsigma$ is completely defined in the Eulerian setting. It is used to formulate physical balance principles.\n\n% ---\n\\subsection{Overview of the Physical Relations}\n\nThe previously introduced quantities are linked together by various relations, which are summarized in the diagram in \\cref{fig:tonti_diagram}. The goal is to find the relationship between given forces (top left in \\cref{fig:tonti_diagram}) and the resulting deformation of the body described by the displacements (top right in \\cref{fig:tonti_diagram}).\nPrescribed external traction forces $\\bfT$ and external or inertial body forces $\\bfB$ act on the body and result in stresses $\\bfS$ satisfying the \\emph{equilibrium} relation. A \\emph{material law} connects stresses $\\bfS$ and strains $\\bfE$. The \\emph{kinematics} of the body determine the relationship between displacements $\\bfu$ and strains $\\bfE$. Geometric Dirichlet boundary conditions prescribe displacements and Neumann boundary conditions such as traction forces contribute to the stress field. \n\nWhereas the equilibrium relation is linear, the material and kinematic descriptions can both be chosen to be linear or nonlinear. \nIn cases of small strains, geometric and material linearity can be assumed. We derive two such formulations: a linear formulation where all relations are linear and a nonlinear formulation with nonlinear material and kinematic relations.\n\n% Tonti diagram\n\\begin{figure}\n  \\centering%\n  \\def\\svgwidth{\\textwidth}\n  \\input{images/theory/tonti_diagram.pdf_tex}%\n  \\caption{The three relations between various quantities that compose the solid mechanics model: Equilibrium links traction and body forces $\\bfT$ and $\\bfB$ to the stresses $\\bfS$. A material model connects them to strains $\\bfE$. The kinematic relations yield the resulting displacement field $\\bfu$. Note that all quantities in this diagram are given in Lagrangian formulation.}%\n  \\label{fig:tonti_diagram}%\n\\end{figure}\n% linear, static and dynamic\n\n\\subsection{Assumptions and Model Equations}\\label{sec:assumptions_and_model_equations}\n% ----\n\nThe foundation of continuum mechanics usually builds on three balance principles: conservation of mass, of momentum and of angular momentum. In the following, these principles are presented in their Eulerian forms.\n\nFirst, we assume \\emph{conservation of mass} in terms of the densities $\\rho_0(\\bfX)$ and $\\rho(\\bfx)$ in reference and current configurations:\n%\n\\begin{align*}\n  \\ds\\int\\limits_{V_0} \\rho_0\\,\\d V = \\int\\limits_{V_t} \\rho \\,\\d v.\n\\end{align*}\n%\nThe equation holds for all corresponding subdomains $V_0\\subset \\Omega_0$ and $V_t \\subset \\Omega_t$. With the intermediate step of deducing $\\d/\\d t \\int_{\\Omega_t} \\rho \\,\\d v=0$, we get the following differential equation:%\n\\begin{align}\\label{eq:contraction_helper1}\n  \\dot{\\rho}(\\bfv,t) + \\rho(\\bfx,t)\\,\\div\\big(\\bfv(\\bfx,t)\\big) = 0.\n\\end{align}\n%\n\nAs muscle tissue largely consists of water, it is typically assumed to be an incompressible domain. This is equivalent to a constant density, $\\dot{\\rho}=0$, and, thus, \\cref{eq:contraction_helper1} reduces to\n%\n\\begin{align}\\label{eq:assumption_1_local}\n  \\div(\\bfv(\\bfx,t)) = 0.\n\\end{align}\n%\n\nThe second assumption is the \\emph{balance of momentum}, which is expressed as %\n\\begin{align}\\label{eq:assumption_2_integral}\n  \\d{t} \\ds\\int\\limits_{V_t} \\rho\\,\\bfv\\, \\d v = \\ds\\int\\limits_{V_t} \\rho\\,\\bfb \\,\\d v + \\ds\\int\\limits_{∂V_t} \\bft \\,\\d a.\n\\end{align}\nHere, $\\bfb$ describes a body force and $\\bft$ describes a traction force that acts on the surface of the domain $V_t$. Using the Cauchy theorem \\cref{eq:cauchy_theorem}, it can be replaced by the Cauchy stress $\\bfsigma$. The corresponding differential form is given by the following differential equation:%\n\\begin{align}\\label{eq:assumption_2_local}\n  \\rho\\,\\dot{\\bfv}(\\bfx,t) = \\rho\\,\\bfb(\\bfx,t) + \\div\\bfsigma(\\bfx,t).\n\\end{align}\nIt relates external forces to the internal stress field and describes the \\emph{equilibrium} relation in \\cref{fig:tonti_diagram} in Eulerian form.\nFor the discretization, a Lagrangian form is typically used.\n\n\nFor hyperelastic materials, which we consider in the muscle model, the equilibrium relation can also be formulated in terms of the \\emph{Hellinger-Reissner energy functional} $\\Pi_L(\\bfu,p)$, which describes the potential energy of the system depending on the displacement and pressure functions $\\bfu$ and $p$. Analog to the local form in \\cref{eq:assumption_2_local}, it contains terms for the external loads and for the internal response of the body.\nThe functional is additively composed of external and internal potential energy:\n\\begin{align}\\label{eq:hellinger_reissner}\n  \\Pi_L(\\bfu,p) = \\Pi_\\text{ext}(\\bfu) + \\Pi_\\text{int}(\\bfu,p).\n\\end{align}\nThe external energy functional is formulated by\n\\begin{align}\\label{eq:pi_ext}\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$ in reference configuration and prescribed surface traction $\\bar{\\bfT}$ on the traction boundary $∂\\Omega_0^t$. The body force term $\\bfB$ also includes the inertial forces of mass density times acceleration, $\\rho\\,\\dot{\\bfv}$, in case of a dynamic model.\nThe internal energy functional $\\Pi_\\text{int}(\\bfu,p)$ describes the strain energy of the system depending on the displacement field $\\bfu$ and the hydrostatic pressure $p$. The term is defined in \\cref{sec:section_with_pi_int}.\n\nThe \\emph{principle of stationary potential energy} demands that the potential energy functional $\\Pi_L$ is stationary.\nVariational calculus and differentiation of \\cref{eq:hellinger_reissner} lead to the local Eulerian description given in \\cref{eq:assumption_2_integral,eq:assumption_2_local}.\n\n\nThe third assumption is the \\emph{balance of angular momentum} and can be formulated using the 3D cross-product:%\n\\begin{align*}\n  \\d{t} \\ds\\int\\limits_{V_t} \\bfx \\times (\\rho\\,\\bfv)\\, \\d v = \\ds\\int\\limits_{V_t} \\bfx \\times (\\rho\\,\\bfb) \\,\\d v + \\ds\\int\\limits_{∂V_t} \\bfx \\times \\bft\\,\\d a.\n\\end{align*}\n%\nThis can be shown to be equivalent to the symmetry of the Cauchy stress tensor, $\\bfsigma = \\bfsigma^\\top$.\n\nA further assumption in the multi-scale muscle framework is to only consider isothermal conditions. \nAn activated muscle performs work and energy is added to the system by metabolism. Further, the muscle is not thermodynamically isolated. The system is not closed regarding conversion and transfer of energy and, thus, the balance of energy cannot be modeled easily.\n\nRegarding the required relations to obtain the deformation of the body from external loads given in \\cref{fig:tonti_diagram}, the \\emph{equilibrium} relation is given by \\cref{eq:assumption_2_local} and the nonlinear \\emph{kinematic} relation is given by \\cref{eq:green_lagrange_u}.\nThe \\emph{material} relation has yet to be defined. The mathematical description is closed by defining a constitutive relation between stresses and strains in the next sections.\n\n\\Cref{sec:material_linear_model} defines a linear material model that can be used together with linearized kinematics to formulate a fully linear model. \\Cref{sec:material_nonlinear_model} presents the nonlinear material model to proceed with the fully nonlinear description. \n\n\\subsection{Linear Material Model}\\label{sec:material_linear_model}\n\nFor a linear constitutive relation between strain and stress, the linearized strain tensor $\\bfeps$, defined in \\cref{eq:linearized_helper3} is used together with the Eulerian Cauchy stress $\\bfsigma$. The generic linear material model is \\emph{Hooke}'s law, given by \n%\n\\begin{align}\\label{eq:linearized_helper2}\n  \\bfsigma = \\C:\\bfeps\n\\end{align}\nwith the fourth order material tensor%\n\\begin{align*}\n  \\C_{abcd} = K\\,δ_{ab}\\,δ_{cd} + μ\\,(δ_{ac}\\,δ_{bd} + δ_{ad}\\,δ_{bc} - \\dfrac23 δ_{ab}\\,δ_{cd}).\n\\end{align*}\nThe bulk modulus $K$ is a measure for the (in-)compressibility and the shear modulus $\\mu$ specifies the elastic shear stiffness. $δ_{ab}$ is the Kronecker delta.\nThe material tensor $\\C$ exhibits the following major and minor symmetries:%\n\\begin{subequations}\\label{eq:symmetries}\n\\begin{align}\n  \\C_{abcd} &= \\C_{cdab}, \\quad &\\text{(major symmetries)}\\\\[4mm]\n  \\C_{abcd} &= \\C_{bacd} = \\C_{abdc} = \\C_{badc}, \\quad & \\text{(minor symmetries)}\n\\end{align}\n\\end{subequations}\neffectively reducing the number of independent entries from 81 to 21 for 3D domains.\n\nTo incorporate force generation in the muscle, the stress can be additively composed of the passive stress $\\bfsigma$ and an additional active stress term $\\bfsigma_\\text{active}$:%\n\\begin{align}\\label{eq:active_stress_linear}\n  \\bfsigma^\\text{total} = \\bfsigma + \\bfsigma^\\text{active}.\n\\end{align}\n\n\\subsection{Nonlinear Material Modeling}\\label{sec:material_modeling}\n%\nNext, we present the derivation of a nonlinear model that does not make any linearization assumptions of small strains as in the previous section.\nWe begin with the description of the material law, which links strains and stresses.\n\nThe scalar strain energy function $\\Psi$ describes the elastic energy of the material depending on the deformation.\nThe definition of $\\Psi$ suffices to describe the behavior of a hyperelastic material.\nThe strain energy function links the right Cauchy Green tensor $\\bfC$ to the second Piola-Kirchhoff stress tensor $\\bfS$ by the relation%\n\\begin{align}\\label{eq:material_model_helper1}\n  \\bfS = 2\\p{\\Psi(\\bfC)}{\\bfC}.\n\\end{align}\n\nThe \\emph{principle of material objectivity} requires that material properties are invariant under a change of observer. As a result, the \\emph{representation theorem for isotropic materials} states that the stress tensor can be represented using three strain invariants $I_1, I_2$ and $I_3$. For a transversely isotropic material, two invariants $I_4$ and $I_5$ that depend on the anisotropy direction $\\bfa_0$ (corresponding to a fiber direction) are added.\nConsequently, we can formulate the strain energy function $\\Psi=\\Psi(I_1,I_2,I_3,I_4,I_5)$ in terms of these invariants. The principle strain invariants $I_1$ to $I_3$ of the right Cauchy-Green tensor $\\bfC$ and the additional anisotropic invariants $I_4$ and $I_5$ are defined as:\n\\begin{align*}\n  &I_1(\\bfC) = \\tr(\\bfC),  &\n  &I_2(\\bfC) = \\dfrac12\\big(\\tr(\\bfC)^2 - \\tr(\\bfC^2)\\big), &\n  I_3(\\bfC) = \\det(\\bfC) = J^2,\\\\[4mm]\n  &I_4(\\bfC,\\bfa_0) = \\bfa_0 \\cdot \\bfC \\, \\bfa_0, &\n  &I_5(\\bfC,\\bfa_0) = \\bfa_0 \\cdot \\bfC^2 \\, \\bfa_0. &\n\\end{align*}\nThe fiber stretch is related to the fourth invariant by $\\lambda_f = \\sqrt{I_4}$. Note that requiring incompressibility is equivalent to enforcing $J=1$, and, in this case, we get ${I_3(\\bfC) = 1}$. \n\nIt is convenient to use a decoupled description, where the deformation gradient $\\bfF$ and the right Cauchy-Green tensor $\\bfC$ are multiplicatively decomposed into volume-changing (volumetric) and volume-preserving (isochoric) parts:%\n\\begin{align*}\n  \\bfF &= (J^{1/3}\\bfI)\\,\\bar{\\bfF},  & \\bfC &= (J^{2/3}\\bfI)\\,\\bar{\\bfC}.\n\\end{align*}\n%\nHere, the volumetric parts are the identity tensors scaled by a power of the determinant $J$ of the deformation gradient. The isochoric or distortional parts $\\bar{\\bfF}$ and $\\bar{\\bfC}$ are given by%\n\\begin{align}\\label{eq:reduced_fc}\n  \\bar{\\bfF} &= J^{-1/3}\\,\\bfF,  & \\bar\\bfC &= J^{-2/3}\\,\\bfC.\n\\end{align}\nThe reduced invariants $\\bar{I}_1$ to $\\bar{I}_5$ of the reduced right Cauchy-Green tensor $\\bar\\bfC$ are defined accordingly.\nSimilarly, the strain energy function has a decoupled representation with volumetric part $\\Psi_\\text{vol}$ and isochoric part $\\Psi_\\text{iso}$:\n\\begin{align}\\label{eq:psi_iso}\n  \\Psi = \\Psi_\\text{vol}(J) + \\Psi_\\text{iso}(\\bar{\\bfC}) = \\Psi_\\text{vol}(J) + \\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2,\\bar{I}_4,\\bar{I}_5).\n\\end{align}\n\nUsing the decoupled form, any incompressible material can be modeled with the \\emph{penalty method} as follows. \nThe material behavior is given by the isochoric strain energy $\\Psi_\\text{iso}(\\bar{\\bfC})$, e.g., by employing the Mooney-Rivlin model in \\cref{eq:mooney_rivlin}. The volumetric part is defined as\n\\begin{align*}\n  \\Psi_\\text{vol}(J) &= \\kappa\\,G(J) \\qquad \\text{with } G(J) = \\dfrac12 (J-1)^2,\n\\end{align*}\nwith the incompressibility parameter $\\kappa$ and the penalty function $G(J)$. This function is strictly convex and approaches zero as $J$ approaches 1. For large values of $\\kappa$, the behavior is nearly incompressible. A disadvantage of this method is, that the resulting system becomes singular for $J \\to 1$.\n\nA better approach in this regard is to use a mixed formulation, where incompressibility is enforced exactly using a Lagrange multiplier. This approach is also implemented in OpenDiHu and is the preferred method for incompressible materials. \n\nIn OpenDiHu, the strain energy function of a new material can be given using the following four terms:\n%\n\\begin{align}\\label{eq:definition_psi}\n  \\Psi = \\Psi_\\text{vol}(J) + \\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2,\\bar{I}_4,\\bar{I}_5) + \\Psi_1(I_1,I_2,I_3) + \\Psi_2(\\bfC,\\bfa_0).\n\\end{align}\nThe decoupled form is available with $\\Psi_\\text{vol}$ and $\\Psi_\\text{iso}$, the coupled form for isotropic materials can be used via $\\Psi_1$. The term $\\Psi_2$ gives the most flexibility, as the constitutive model can be directly formulated using the right Cauchy-Green tensor $\\bfC$ and the fiber direction $\\bfa_0$. The unused terms among $\\Psi_\\text{vol},\\Psi_\\text{iso},\\Psi_1$ and $\\Psi_2$ can be defined as constant zero. The incompressibility constraint using Lagrange multipliers can be switched on or off such that both incompressible and compressible materials can be computed.\n%\n% ---\n\n\\subsection{The Nonlinear Material Model for Muscle Contraction}\\label{sec:material_nonlinear_model}\n\nIn the muscle contraction model of \\cite{Heidlauf2013}, the strain energy function is additively composed of two passive terms, one isotropic, one anisotropic, and one additional active term:\n\\begin{align}\\label{eq:transiso_mooney_rivlin}\n  \\Psi(\\bfC) = \\Psi_\\text{isotropic}(I_1,I_2) + \\Psi_\\text{anisotropic}(\\lambda_f) + \\Psi_\\text{active}(\\gamma).\n\\end{align}\nThe isotropic term $\\Psi_\\text{isotropic}$ is formulated in terms of the strain invariants $I_1=\\tr(\\bfC)$ and $I_2=\\big(\\tr(\\bfC)^2 - \\tr(\\bfC^2)\\big)/2$. The anisotropic term $\\Psi_\\text{anisotropic}$ depends on the fiber stretch $\\lambda_f$. The active term $\\Psi_\\text{active}$ yields the active stress that results from muscular activation, which is described by the activation parameter $\\gamma$.\n%Note the missing dependency on the third invariant $I_3$, which is constant because of the enforced incompressibility.\n\nThe passive behavior of muscle tissue is modeled by a transversely isotropic Mooney-Rivlin material.\nThe isotropic part is given by the Mooney-Rivlin formulation:%\n\\begin{align}\\label{eq:mooney_rivlin}\n  \\Psi_\\text{isotropic}(I_1,I_2) = c_1\\,(I_1 - 3) + c_2\\,(I_2-3).\n\\end{align}\nThe values of the two material parameters $c_1$ and $c_2$ can be determined by compression tests and are summarized in the work of \\cite{Heidlauf2013}.\n\nThe anisotropic behavior depends only on the fiber stretch $\\lambda_f$. The formulation in \\cite{Heidlauf2013} uses two material parameters $b$ and $d$ and the following function:\n\\begin{align*}\n  \\Psi_\\text{anisotropic}(\\lambda_f) = \\dfrac{b}{d}(\\lambda_f^d - 1) - b\\,\\log(\\lambda_f).\n\\end{align*}\n%\n\nThe active contribution is directly formulated in terms of the second Piola-Kirchhoff stress $\\bfS$. The relation between the active stress $\\bfS_\\text{active}$ and the active contribution $\\Psi_\\text{active}$ of the strain energy function as well as the definition of $\\bfS_\\text{active}$ is given as follows:\n\\begin{align}\\label{eq:active_stress_term}\n  \\bfS_\\text{active} = \\dfrac{1}{\\lambda_f}\\p{\\Psi_\\text{active}}{\\lambda_f} \\bfA \\otimes \\bfA = \\dfrac{1}{\\lambda_f} \\cdot S_\\text{max,active}\\cdot f_\\ell(\\lambda_f)\\cdot\\bar{\\gamma}\\, \\bfA \\otimes \\bfA.\n\\end{align}\n%\nHere, the resulting active stress tensor $\\bfS_\\text{active}$ is the second order tensor oriented according to the material fiber direction $\\bfA: \\Omega_0 \\to \\R^3$ and given by the dyadic product $\\bfA \\otimes \\bfA = A_{i}\\,A_{j}\\,\\bfe_i \\otimes \\bfe_j$, scaled by the maximum active stress parameter $S_\\text{max,active}$, a function $f_\\ell$ that models the force-length relation, and the 3D homogenized value $\\bar{\\gamma}$ of the activation parameter $\\gamma \\in [0,1]$ following from the half-sarcomere model.\n\nIn the deforming body fat layer, the active stress contribution is disregarded. For simulating tendons, different material models can be used such as the model proposed by Carniel et al. \\cite{Carniel2017}, which describes microstructural interactions between collagen fibers and their matrix in addition to the elastic response of the fibers themselves. To alter the material model, the definition of $\\Psi$ can simply be changed while all other equations of the solid mechanics model remain intact. \n%Similarly, other material models can be defined using the framework of the strain energy function.\n\n\\subsection{Summary of the Solid Mechanics Model Equations}\nIn summary, the model of solid mechanics for muscle contraction is solved for the unknown displacements $\\bfu$ and additionally the velocities $\\bfv$ if a dynamic formulation is considered.\n\nThe model equations follow from the following balance principles:\n%\n\\begin{subequations}\\label{eq:contraction}\n  \\begin{align}\n    \\div(\\bfv) &= 0, \\qquad &&\\text{(incompressibility)} \\label{eq:contraction_1}\\\\[4mm]\n    \\rho\\,\\dot{\\bfv} &= \\rho\\,\\bfb + \\div\\bfsigma, && \\text{(balance of linear momentum)}\\label{eq:contraction_2}\\\\[4mm]\n    \\bfsigma &= \\bfsigma^\\top, && \\text{(balance of angular momentum)}\\label{eq:contraction_3}\n  \\end{align}\n\\end{subequations}\nwith the constant density $\\rho$, external body forces $\\bfb$ and the Cauchy stress tensor $\\bfsigma$.\n\nAdditionally, geometric relations between displacements $\\bfu$ and strains $\\bfE$ or $\\bfeps$ are assumed, either fully nonlinear in \\cref{eq:green_lagrange_u} or with corresponding linearization assumptions in \\cref{eq:linearized_helper3}.\nFurthermore, a material model is given that relates strains and stresses. A linear model is described in \\cref{sec:material_linear_model}. The framework for nonlinear hyperelastic models uses a strain energy function $\\Psi$ as described in \\cref{sec:material_modeling}. A particular nonlinear material model for muscle contraction from the literature is described in \\cref{sec:material_nonlinear_model}.\n\nThe description of the multi-scale model \\cite{Roehrle2012,Heidlauf2013} assumes quasi-static conditions, which means that the velocities are set to zero, $\\bfv=\\bfzero$, and inertial terms are neglected. As a consequence, the incompressibility constraint in \\cref{eq:contraction_1} has to be formulated differently and the balance of momentum in \\cref{eq:contraction_2} reduces to $\\rho\\,\\bfb + \\div \\bfsigma = 0$.\nOur implementation extends the model to the fully dynamic formulation given in \\cref{eq:contraction_1,eq:contraction_2,eq:contraction_3}. \n\nInitial conditions for the displacements $\\bfu$ and velocities $\\bfv$ define the initial pose of the muscle tissue:\n%\n\\begin{align*}\n  \\bfu(\\bfx,0) &= \\bfu_0(\\bfx), & \\bfv(\\bfx,0) &= \\bfv_0(\\bfx) \\quad &&\\text{for } \\bfx \\in \\Omega_M.\n\\end{align*}\n%\nDirichlet boundary conditions for $\\bfu$ and $\\bfv$ can fix certain parts of the muscle, e.g., at the attachment points of the tendons:\n\\begin{align*}\n  \\bfu(\\bfx,t) &= \\bar{\\bfu}(t), & \\bfv(\\bfx,t) &= \\bar{\\bfv}(t) \\quad &&\\text{for } \\bfx \\in ∂\\Omega_\\text{Dirichlet}.\n\\end{align*}\n%\nAdditionally, Neumann boundary conditions can be used to prescribe traction forces on the surface.\n\nThe derivation of the finite element formulation and the resulting numerical scheme to obtain the solution functions $\\bfu$ and $\\bfv$ are discussed in \\cref{sec:discretization_mechanics}.\n\n%\\subsection{Sensory Organs and Motor Neurons}\n%text of paper:\n%Muscle spindles and Golgi tendon organs are located in the muscle and sense fiber stretch, contraction velocity, contraction acceleration and muscle forces. \n%They are connected via layers of inter neurons to the motor neurons, which reside in the spinal cord.\n%In turn, the motor units innervate and activate the muscle.\n\n%We use CellML models to compute the dynamics of muscle spindles \\cite{Mileusnic2006} and motor neurons \\cite{CisiKohn2008}.\n\n", "meta": {"hexsha": "7a8274afeec89bf2419505335c8c77a27d988241", "size": 33921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/05_theory_1.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_1.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_1.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.1064935065, "max_line_length": 590, "alphanum_fraction": 0.7660151529, "num_tokens": 9176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6798355336217887}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find $\\begin{mymatrix}{c}\n    1 \\\\\n    2 \\\\\n    3\n  \\end{mymatrix}\n  + \\begin{mymatrix}{c}\n    1 \\\\\n    5 \\\\\n    1\n  \\end{mymatrix}\n  + \\begin{mymatrix}{c}\n    -1 \\\\\n    2 \\\\\n    -4\n  \\end{mymatrix}$.\n\n  \\begin{sol}\n    $\\begin{mymatrix}{r}\n      1 \\\\\n      9 \\\\\n      0\n    \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the properties of vector addition from\n  Proposition~\\ref{prop:properties-vector-addition} to show the following\n  equalities. Justify every step.\n  \\begin{enumerate}\n  \\item $(\\vect{u}+\\vect{v})+\\vect{w} = (\\vect{v}+\\vect{w})+\\vect{u}$.\n  \\item $(\\vect{u}+\\vect{0})+(\\vect{v}+(-\\vect{u})) = \\vect{v}$.\n  \\end{enumerate}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item\n      $(\\vect{u}+\\vect{v})+\\vect{w} = (\\vect{v}+\\vect{u})+\\vect{w} =\n      \\vect{v}+(\\vect{u}+\\vect{w}) = \\vect{v}+(\\vect{w}+\\vect{u}) =\n      (\\vect{v}+\\vect{w})+\\vect{u}$. Here we have used the commutative\n      law, the associative law, the commutative law, and the\n      associative law, in that order.\n    \\item\n      $(\\vect{u}+\\vect{0})+(\\vect{v}+(-\\vect{u})) =\n      \\vect{u}+(\\vect{v}+(-\\vect{u})) = \\vect{u}+((-\\vect{u})+\\vect{v})\n      = (\\vect{u}+(-\\vect{u}))+\\vect{v} = \\vect{0}+\\vect{v} =\n      \\vect{v}+\\vect{0} = \\vect{v}$. Here we have used the additive\n      unit, the commutative law, the associative law, the additive\n      inverse, the commutative law, and the additive unit, in that\n      order.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "c973152b396dab0838e1909ee7b32db2d1d3998e", "size": 1494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Vectors-Addition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Vectors-Addition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Vectors-Addition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 25.7586206897, "max_line_length": 73, "alphanum_fraction": 0.546854083, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.67973745559854}}
{"text": "\\chapter{Model Selection}\nSuppose we observe a realization of a random variable $Y$, with\ndistribution defined by a parameter $\\bb$\n\\begin{equation}\n\\label{gdef}\n\\prod_{\\bx_i \\in N_0} f(y_i; \\bx_i,\\bb) \\equiv\nf_\\bY(\\by ;\\bX,\\bb)  \n\\end{equation}\nwhere $\\by$ is the observed response associated with the\ncovariates $\\bX$ and \n$\\bb \\in \\mathbb{R}^P$ is a $P \\times 1$ parameter vector. \n\nWe are interested in estimating $\\bb$. Suppose that before\ndoing so, we need to choose from amongst $P$\ncompeting models, generated by simply restricting the\ngeneral parameter space $R^P$ in which $\\bb$ lies.\n\nIn terms of the\nparameters, we represent {\\sl the full model} with $P$ parameters as:\n\\[\n\\mbox{Model(P): } f_\\bY(\\by ;\\bx,\\bb_P),\n  \\bb_P = (\\beta_1,\\dots,\\beta_p,\\beta_{p+1},\\dots,\\beta_P)'.\n\\]\nWe denote the ``true value'' of the parameter vector $\\bb$ with\n$\\bb^*$. \n\nAkaike (1977)\nformulates the problem of statistical model identification as one of\nselecting a model $f_\\bY(\\by;\\bx,\\bb_p)$\nbased on the  \nobservations from that distribution, where the particular restricted\nmodel is defined by the constraint $\\beta_{p+1} = \\beta_{p+2} = \\dots\n= \\beta_{P} = 0$, so that \n\\begin{equation}\n\\label{modelpdef}\n\\mbox{Model(p): } f_\\bY(\\by;\\bx,\\bb_p),\n\\bb_p =  (\\beta_1,\\dots,\\beta_p,0,\\dots,0)' \n\\end{equation}\nWe will refer to $p$ as the {\\sl number of parameters} and to\n$\\Omega_p$ as the sub-space of $\\mathbb{R}^P$ defined by restriction\n(\\ref{modelpdef}). For each $p=1,\\dots,P$, we may assume model(p) to\nestimate the non-zero \ncomponents of the vector $\\bb^*$. We are interested in a \ncriterion that helps us chose amongst these $P$ competing estimates.\n\nIn this Chapter we consider 3 methods for model selection.\n\n\n\\input{section-09-01}\n\\input{section-09-02}\n\\input{section-09-03}\n\\input{references-09}\n", "meta": {"hexsha": "160074f009ca203a608766e2bcce5f0fde665266", "size": 1806, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-09.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-09.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-09.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.0754716981, "max_line_length": 69, "alphanum_fraction": 0.7109634551, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.6797134547611304}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{graphicx}\n\\usepackage{mathtools}\n\\usepackage{enumerate}\n\\usepackage[letterpaper,left=1.25in,right=1.25in,top=1in,bottom=1in]{geometry}\n\\usepackage{fancyhdr}\n\\usepackage[parfill]{parskip}\n\\usepackage{changepage}\n\n\\pagestyle{fancy}\n\\fancyfoot{}\n% header/footer settings\n\\lhead{Kevin Nash (kjn33)}\n\\chead{EECS 391 -- P2}\n\\rhead{\\today}\n\\cfoot{\\thepage}\n\n\\begin{document}\n\n\\section{Linear Decision Boundaries}\n\n\\subsection{Plotting Iris Classes}\nThis project is written in Python, using Pandas dataframes to manipulate data\nand Matplotlib to plot it.\n\nThe data is initialized like so,\n\\begin{verbatim}\n# Read the file into a Pandas dataframe\niris_data = pd.read_csv(filename)\n# Capitalize the column names and remove underscores\niris_data.columns = [\"Sepal Length\", \"Sepal Width\", \"Petal Length\",\n                     \"Petal Width\", \"Species\"]\n# Remove any species other than those specified by the assignment\niris_data = iris_data.loc[iris_data[\"Species\"].isin([\"versicolor\", \"virginica\"])]\n# Select the versicolor and virginica species individually\nversi_data = iris_data.loc[iris_data[\"Species\"] == \"versicolor\"]\nvirgi_data = iris_data.loc[iris_data[\"Species\"] == \"virginica\"]\n\\end{verbatim}\nThe assignment asks us to consider only the versicolor and virginica species.\nLet's take a look at the first few rows of each.\n\\begin{verbatim}\nIn [2]: versi_data.head(3)\n    Sepal Length  Sepal Width  Petal Length  Petal Width     Species\n50           7.0          3.2           4.7          1.4  versicolor\n51           6.4          3.2           4.5          1.5  versicolor\n52           6.9          3.1           4.9          1.5  versicolor\n\nIn [3]: virgi_data.head(3)\n     Sepal Length  Sepal Width  Petal Length  Petal Width    Species\n100           6.3          3.3           6.0          2.5  virginica\n101           5.8          2.7           5.1          1.9  virginica\n102           7.1          3.0           5.9          2.1  virginica\n\\end{verbatim}\nWe are interested in the petal dimensions. To plot them:\n\\begin{verbatim}\nfig = plt.figure()\nax = fig.add_subplot(111)\nax.scatter(x=dataset_1[\"Petal Length\"], y=dataset_1[\"Petal Width\"],\n           color=\"b\", marker=\"o\", label=\"versicolor\")\nax.scatter(x=dataset_2[\"Petal Length\"], y=dataset_2[\"Petal Width\"],\n           color=\"r\", marker=\"^\", label=\"virginica\")\nplt.xlabel(\"Petal Length (cm)\")\nplt.ylabel(\"Petal Width (cm)\")\nplt.legend(loc=\"upper left\")\nplt.savefig(\"plot_1a.pdf\", bbox_inches=\"tight\")\n\\end{verbatim}\nThis gives us\n\\begin{center}\n\\includegraphics{plot_1a.pdf}\n\\end{center}\nIt is clear that at least two points of different classes overlap, which means\nthat our data is not going to be linearly separable.\n\n\\subsection{Choosing a Boundary by Hand}\n\nI chose a boundary by physically drawing a line on the above plot using an\nimage editor. The line reaches from 2.4 on the y-axis to 6.5 on the x-axis.\nThen we can get an equation in slope-intercept form from the coordinates\n$(3, 2.4), (6.5, 1)$. $y=mx+b$ where $m=-0.4$ and $b=3.6$.\n\nThe code to generate this plot is identical to the above plot, except the line\n\\begin{verbatim}\nplt.plot([3, 6.5], [2.4, 1], color=\"k\", linestyle=\"-\", linewidth=1)\n\\end{verbatim}\nis now added before saving.\n\\begin{center}\n\\includegraphics{plot_1b.pdf}\n\\end{center}\n\n\\subsection{Defining a Threshold Classifier}\n\nWe can now define a threshold classifier using the above parameters to compare\nagainst our data points. Simply put, if the point is above the line, it is\npredicted to be virginica. Otherwise it is predicted to be versicolor.\n\nThe calculation is shown here, where $x$ and $y$ correspond to $petal\\ length$\nand $petal\\ width$, respectively.\n\\begin{verbatim}\n\"\"\" Returns the distance from point (x,y) to the line in slope-intercept form \"\"\"\ndef dist_from_line(x, y, m, b):\n    return y - (m * x + b)\n\n\"\"\" Returns \"virginica\" if the point (length, width) is above the line \"\"\"\ndef classify_linear(row, slope, intercept):\n    if 0 < dist_from_line(row[\"Petal Length\"], row[\"Petal Width\"], slope, intercept):\n        return \"virginica\"\n    return \"versicolor\"\n\\end{verbatim}\n\nTo plot this data, we isolate the misclassified points into their own dataframes.\nMisclassified points are defined as those for which $Species \\neq Classification$.\n\\begin{verbatim}\n# Classify data linearly for part 1c\niris_data[\"Classification\"] = iris_data.apply(\n    lambda row: classify_linear(row, -0.4, 3.6), axis=1\n)\nmisclassified = pd.DataFrame(columns=iris_data.columns)\n\nfor i, row in iris_data.iterrows():\n    if not row[\"Classification\"] == row[\"Species\"]:\n        misclassified.loc[len(misclassified.index)] = row\n\nprint(\"Linear decision accuracy: {}%\".format(100 - len(misclassified.index) /\n      len(iris_data.index) * 100))\n\nversi_class = misclassified.loc[misclassified[\"Species\"] == \"versicolor\"]\nvirgi_class = misclassified.loc[misclassified[\"Species\"] == \"virginica\"]\nplot_linear_bound(versi_class, virgi_class, \"plot_1c.pdf\")\n\\end{verbatim}\nThis threshold classifier misclassifies six data points, as shown in the next\nplot. Note that points \\textit{above} the line are supposed to be virginica\n(red triangles), and points \\textit{below} the line are supposed to be\nversicolor (blue circles), but the opposite is true of misclassified points.\n\\begin{center}\n\\includegraphics{plot_1c.pdf}\n\\end{center}\n\n\\subsection{Circle Decision Boundaries}\n\nInstead of defining our decision boundary with a straight line, we can use\na circle instead. The technique is the same, although in this case the decision\nis made considering whether a point is inside or outside of the circle, rather\nthan above or below a line. The functions are similar to those first shown in\nsection 1.3.\n\\begin{verbatim}\n\"\"\" Returns the distance from point (x,y) to the edge of the circle \"\"\"\ndef dist_from_circle(x, y, x_circ, y_circ, r):\n    return ((x - x_circ)**2 + (y - y_circ)**2)**0.5 - r\n\n\"\"\" Returns \"virginica\" if the point (length, width) is outside of the circle \"\"\"\ndef classify_circular(row, x, y, radius):\n    if 0 < dist_from_circle(row[\"Petal Length\"], row[\"Petal Width\"], x, y, radius):\n        return \"virginica\"\n    return \"versicolor\"\n\\end{verbatim}\nNow we need to pick parameters for our circle ($x_{0}, y_{0}, r$). The\nassignment instructs us to pick three sets. I started at the center of the plot\nwith an arbitrary radius of $\\frac{1}{2}$. This, predictably, didn't give great\nresults, but with two adjustments the decision accuracy eventually met that of\nthe linear threshold ($94\\%$). The parameters and results are shown below,\nfollowed by the plot of each. Note that because the $x,y$ scales are not $1:1$,\nthe circle is \\textit{mathematically} circular, \\textit{not graphically} circular.\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\n$x$ & $y$ & $r$ & Accuracy\\\\\n\\hline\\hline\n$4.75$ & $1.7$ & $0.5$ & 58\\%\\\\\n\\hline\n$4.5$ & $1.2$ & $0.5$ & 79\\%\\\\\n\\hline\n$4.0$ & $1.2$ & $1$ & 94\\%\\\\\n\\hline\n\\end{tabular}\n\\includegraphics{plot_1d_1.pdf}\n\\includegraphics{plot_1d_2.pdf}\n\\includegraphics{plot_1d_3.pdf}\n\\end{center}\n\nThe plotting code is easy to imagine. Instead of drawing a line, just draw\na circle according to\n\\begin{verbatim}\ncircle = plt.Circle((x, y), r, color=\"k\", fill=False)\nax.add_artist(circle)\n\\end{verbatim}\n\n\\section{Objective Functions}\n\n\\subsection{Calculating Mean-Squared Error}\n\nThe mean squared error is given by\n\\begin{equation*}\nE = \\frac{1}{N}\\sum_{n=1}^N\\left(\\boldsymbol{w}^T\\boldsymbol{x}_n-c_n\\right)^2\n\\end{equation*}\nIn our case the predicted and actual values are $\\boldsymbol{w}^T\\boldsymbol{x}_n$\nand $c_n$, where class of $x$ in pattern vector $\\boldsymbol{x}_n$ is given by\n\\[\n    x \\in\n    \\begin{cases}\n    \\text{class 1} & \\text{if } y\\geq 0\\\\\n    \\text{class 2} & \\text{if } y < 0\n    \\end{cases}\n\\]\nand we can number the classes $0$ or $1$ to give $c_n$ a value according to\n\\[\n    c_n =\n    \\begin{cases}\n    0 & \\boldsymbol{x}_n \\in \\text{class 1}\\\\\n    1 & \\boldsymbol{x}_n \\in \\text{class 2}\n    \\end{cases}\n\\]\nHowever by this definition, $(\\boldsymbol{x}_n-c_n)\\subset \\{-1,0,1\\}$ and\ntherefore $(\\boldsymbol{x}_n-c_n)^2\\subset \\{0,1\\}$. The mean of zeroes and\nones doesn't give us a very percise error value, and so we can redefine the\nfirst term. Rather than assigning a zero or a one based on the predicted class,\nwe can plug distance into a modified version of the sigmoid function, shown\nbelow.\n\\begin{equation*}\np = \\frac{1}{1+10^{-d}}\n\\end{equation*}\nwhere $d$ is the distance from the decision boundary and $p$ is the predictive\nvalue. $p\\in[0,1]$, which changes the prediction from a discrete set of one and\nzero to a continuum from zero to one. By making this change, we qualify our\npredictions with a degree of confidence and theoretically make our MSE value\nmore accurate.\n\nFrom now on the MSE value will be superimposed over the graph. The current\nboundary gives a value of $0.0645$.\n\\begin{center}\n\\includegraphics{plot_2a.pdf}\n\\end{center}\n\\begin{verbatim}\nif show_mse:\n    combined_data = pd.concat([dataset_1, dataset_2])\n    mse = mean_squared_error(combined_data, slope, intercept)\n    plt.text(0.85, 0.05, \"MSE: %.4f\" % mse, ha='center', va='center',\n             fontsize=12, transform=ax.transAxes)\n\\end{verbatim}\nThe mean squared error calculation is calculated like so\n\\begin{verbatim}\ndef mean_squared_error(dataset, m, b, classes={\"versicolor\": 0, \"virginica\": 1}):\n    sum_diffs = 0\n    for i, row in dataset.iterrows():\n        dist = dist_from_line(m=m, b=b, row=row)\n        sum_diffs += (classes[row[\"Species\"]] -\n            classes[classify_prediction(dist)] * sigmoid(dist))**2\n    return sum_diffs / len(dataset.index)\n\ndef sigmoid(x):\n    return 1 / (1 + 10**(-x))\n\\end{verbatim}\n \n\\subsection{Examples of Large and Small Errors}\n\nAs was shown in the previous section, the MSE value for a line with $m=-0.4$, $b=3.6$ was\nquite small ($0.0645$). We can generate a large MSE value ($0.6862$) by using a positive\nslope. Here the boundary misclassifies the majority of the data points!\n\\begin{verbatim}\n# Very high MSE\nplot_linear_bound(versi_data, virgi_data, 1.5, -5.5, show_mse=True, filename=\"plot_2b_1.pdf\")\n\\end{verbatim}\n\\begin{center}\n\\includegraphics{plot_2b_1.pdf}\n\\end{center}\nTo lower the MSE, we should move our parameters back to their ``approximately optimal''\nvalues. Let's see what a zero slope about halfway through the data gives us.\n\\begin{verbatim}\n# Lower MSE\nplot_linear_bound(versi_data, virgi_data, 0, 1.65, show_mse=True, filename=\"plot_2b_2.pdf\")\n\\end{verbatim}\n\\begin{center}\n\\includegraphics{plot_2b_2.pdf}\n\\end{center}\n$0.0889$ is much closer to our original value of $0.0645$.\n\n\\subsection{Derivation of the Gradient}\n\nStarting with the mean square equation from section 2.1,\n\\begin{equation*}\nE = \\frac{1}{N}\\sum_{n=1}^N\\left(\\boldsymbol{w}^T\\boldsymbol{x}_n-c_n\\right)^2\n\\end{equation*}\nWhere $E$ is the mean-squared error, $N$ is the number of data points (in this\ncase 100), $\\boldsymbol{w}^T$ is the vector of weights, $\\boldsymbol{x}_n$ is\nthe vector of data point classifications, and $c_n$ is its actual class (in\nthis case species).\n\nAs was previously stated, I am improving the error function with a modified\nsigmoid curve. The distance value supplied to that function is calculated with\n\\begin{equation*}\nd = W_n - (w_1 \\cdot L_n + w_2)\n\\end{equation*}\nwhere $W_n$ is the petal width, $L_n$ is the petal length, $w_1$ is the first\nweight corresponding to slope, $w_2$ is the second weight corresponding to\nintercept.\n\nThe modified sigmoid function is then used to get a bias term ($w_0$).\n\\begin{equation*}\nw_0 = S(d) = \\frac{1}{1+10^{-d}}\n\\end{equation*}\nThe derivative of this sigmoid function is\n\\begin{equation*}\nS'(d) = S(d)\\cdot(1-S(d))\\cdot\\text{ln}|10|\n\\end{equation*}\n\nIf we combine these equations, the MSE equation is written\n\\begin{equation*}\nE = \\frac{1}{N}\\sum_{n=1}^N\\left(S(W_n - (w_1 \\cdot L_n + w_2))\\cdot\\boldsymbol{x}_n-c_n\\right)^2\n\\end{equation*}\nThe gradient for this MSE involves differentiating its equation, as is done below.\n\\begin{equation*}\n\\begin{split}\n\\frac{\\partial E}{\\partial\\boldsymbol{w}} &= \\frac{2}{N}(1-S(\\boldsymbol{x}\\boldsymbol{w}))(S(\\boldsymbol{x}\\boldsymbol{w})-\\boldsymbol{c})\\boldsymbol{x}\\\\\n&= \\frac{2}{N}(1-\\boldsymbol{p})(\\boldsymbol{p}-\\boldsymbol{c})\\boldsymbol{x}\n\\end{split}\n\\end{equation*}\nAt the end we replace the sigmoid function call with a vector of the predictive\nvalues that it returns, notated $\\boldsymbol{p}$.\n\nThis is the vector form. The scalar form will be shown in the next section.\n\n\\subsection{Gradients in Scalar and Vector Form}\n\nWe can expand the vector form of the gradient into a scalar form.\nWhen expanded, it looks like:\n\\begin{equation*}\n\\text{Scalar:\\quad} \\frac{\\partial E}{\\partial w_i} = \\frac{2}{N}\\sum_{n=1}^N(x_{i,n}\\cdot(1-S(x_n w)\\cdot(S(x_n w)-c_n))\n\\end{equation*}\n\\begin{equation*}\n\\frac{2}{N}\\sum_{n=1}^N(w_0x_{0,n}+\\ldots+w_ix_{i,n}+\\ldots+w_Mx_{M,n}-c_n)x_{i,n}\n\\end{equation*}\nIn this form the expression is summed over $N$ terms. The vector form is similar but\ndoes not feature the summation, since it is implicit from the use of vectors\ninstead of scalar variables (e.g. $x_{i,n}$ and $\\boldsymbol{x}$).\n\\begin{equation*}\n\\text{Vector:\\quad} \\frac{\\partial E}{\\partial\\boldsymbol{w}} = \\frac{2}{N}(1-S(\\boldsymbol{x}\\boldsymbol{w}))(S(\\boldsymbol{x}\\boldsymbol{w})-\\boldsymbol{c})\\boldsymbol{x}\n\\end{equation*}\nThen to update the weight, we use an iteration function:\n\\begin{equation*}\nw_i^{t+1}=w_1^t-\\varepsilon\\frac{\\partial E}{\\partial w_i}\n\\end{equation*}\nEpsilon here is a small value that ensure we eventually converge on a minimum value.\nAt this point the difference between one MSE and the MSE of the next step is\nnegligible.\n\n\\subsection{Summing the Gradient for an Ensemble of Patterns}\n\nWe can now use a gradient to take steps that should ultimately minimize mean\nsquared error. To do this, we simply combine the tools outlined above.\nNamely, we need the predictive function by which to compare the relative\nconfidence in each categorization, and the derivative, which tells us how to\nimprove this confidence (thereby lowering MSE).\n\n\\begin{verbatim}\ndef sum_gradient(dataset, m, b, classes={\"versicolor\": 0, \"virginica\": 1}):\n    epsilon = 0.1 / len(dataset.index)\n    gradient = 0\n    for i, row in dataset.iterrows():\n        pred = sigmoid(dist_from_line(m=m, b=b, row=row))\n        error = pred - classes[row[\"Species\"]]\n        gradient += (2 / len(dataset.index)) * (1 - pred) * error\n    if m < 0:\n        new_m = m + epsilon * gradient\n    else:\n        new_m = m - epsilon * gradient\n    new_b = b - epsilon * gradient\n    return new_m, new_b\n\\end{verbatim}\n\nThe above function calculates the new slope and intercept for weights in the\nnext step in a gradient descent. Below are function calls to plotting routines\nthat produce the following plots. The plots show sequential steps (magenta)\nfrom an initial decision boundary (black, dashed).\n\n\\begin{verbatim}\nplot_gradient_descent(versi_data, virgi_data, -0.1, 5, snapshots=5, filename=\"plot_2e_1.pdf\")\nplot_gradient_descent(versi_data, virgi_data, -0.5, 3, snapshots=5, filename=\"plot_2e_2.pdf\")\n\\end{verbatim}\n\\begin{center}\n\\includegraphics{plot_2e_1.pdf}\n\\includegraphics{plot_2e_2.pdf}\n\\end{center}\n\n\\section{Learning a Decision Boundary Through Optimization}\n\n\\subsection{Implementing Gradient Descent}\n\nThis section is basically the one above, since in the above plots I considered\nit more helpful to show multiple steps at once. However since this section\ncovers the gradient descent implementation, I will point out that on the\nprevious graphs we notice initial and final MSE values, also reproduced\nin the table below. The final value comes after 1000 steps, though not all\nsteps are always necessary.\n\\begin{center}\n\\begin{tabular}{|r|r|r|}\n\\hline\nInitial MSE & Final MSE & Reduction\\\\\n\\hline\\hline\n0.4953 & 0.1175 & 76.3\\%\\\\\n\\hline\n0.2586 & 0.1093 & 57.7\\%\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\nWe can also take a look at the descent function.\n\\begin{verbatim}\nmse_0 = mean_squared_error(combined_data, slope, intercept)\nm = slope\nb = intercept\nsteps = 1000\nfor i in range(steps):\n    m, b = sum_gradient(combined_data, m, b)\n    if (i == 1) or (i % (steps / snapshots) == 0):\n        # x_vals = np.array(ax.get_xlim())\n        y_vals = b + m * x_vals\n        plt.plot(x_vals, y_vals, color=\"m\", linestyle='-', linewidth=1)\nmse_f = mean_squared_error(combined_data, m, b)\n\\end{verbatim}\nFirst the mean squared error is calculated for the inital weights. This is\n$\\text{MSE}_0$. Then we take $1000$ steps, and for every step a new gradient sum is\ncalculated, $m$ and $b$ are updated and plotted. After the $1000^{\\text{th}}$\nstep, we calculated mean squared error once more. This is $\\text{MSE}_f$.\n\nThe main point here is that there can be a significant reduction in MSE by\ngradient descent.\n\n\\subsection{Showing the Learning Curve}\n\nNow let us look at a learning curve for the first descent plot. This time it\nis shown with a 100 steps visible, rather than just 5. You can see how the steps\n``slow down'' as the boundary converges. Plus it might make a cool Moiré pattern\non your screen.\n\\begin{center}\n\\includegraphics{plot_3b_1.pdf}\n\\includegraphics{plot_3b_2.pdf}\n\\end{center}\nThe learning curve is shown above.\n\\begin{verbatim}\nmse_vals = []\nm = slope\nb = intercept\nsteps = 10000\nfor i in range(steps):\n    if i % 100 == 0:\n        mse_vals.append(mean_squared_error(dataset, m, b))\n    m, b = sum_gradient(dataset, m, b)\n\nfig = plt.figure()\nax = fig.add_subplot(111)\n# mse_vals = mse_vals[int(-len(mse_vals)/2):]\nax.scatter(x=list(range(1, len(mse_vals) + 1)), y=mse_vals, color=\"k\", marker=\"|\")\nplt.xlabel(\"Steps\")\nplt.ylabel(\"MSE at Step\")\nplt.savefig(filename, bbox_inches=\"tight\")\nplt.close(fig)\n\\end{verbatim}\n\n\\subsection{Illustration with Random Weights}\n\nSince this section uses a random element, the results will be different\nevery time the code is run. Therefore I can't comment on specifics here.\nEnjoy the plots.\n\\subsubsection{Initial}\n\\begin{center}\n\\includegraphics{plot_3c_1.pdf}\n\\includegraphics{plot_3c_2.pdf}\n\\end{center}\n\\subsubsection{Middle}\n\\begin{center}\n\\includegraphics{plot_3c_3.pdf}\n\\includegraphics{plot_3c_4.pdf}\n\\end{center}\n\\subsubsection{Final}\n\\begin{center}\n\\includegraphics{plot_3c_5.pdf}\n\\includegraphics{plot_3c_6.pdf}\n\\end{center}\n\n\\subsection{Choosing the Gradient Step Size}\n\nThe gradient step size was selected similarly to an example discussed in\nlecture. It is determined by the size of the data, namely\n\\begin{equation*}\n\\varepsilon = \\frac{0.1}{N}\n\\end{equation*}\nwhere $N$ is the size of the dataset, in this case 100.\nThis value was chosen because if the step size is too large, there is an\nincreased probability that the learning will diverge. On the other hand,\nif the step size is too small, learning will take too long to converge.\nBy making the step size a function of the data size, we guarantee that the\nstep could adapt to a change in size of the data.\n\nFor this dataset and algorithm, I found that the step size was somewhat lenient.\nI tested between 0.001 and 0.01 and both of these values worked properly.\n\n\\subsection{Choosing the Stopping Criterion}\n\nI tested three different stopping criteria, keeping in mind that once the\nlearning converges, there is no point in continuing further.\n\nFirst was to\ndetect a lack of change in the mean squared error (MSE), since it seems\nreasonable to claim that once the MSE stops changing no more steps are needed.\nHowever in practice this assumption is not always true. If the decision boundary\nis ever completely outside of the clusters of points (\\textit{all} points fall\non one side or another), then this method will falsely detect convergence, since\nshifting the boundary will usually keep the MSE at around 0.50. Even if the\nboundary is within the data, the data are granular enough that you can sometimes\nshift the boundary without changing any classifications.\n\nSecond was to detect a lack of change in an ``upstream'' variable. This method\nis more sensitive to stillness. I decided that if the boundary does not move\nat all within some degree of freedom, then the learning has converged, and it\nended up working successfully for my code. The degree of freedom was adjusted\nover testing. A very small number was initially used, then when the runtime was\nlong, it was sequentially reduced until it produced good results in an\nacceptible time.\n\\begin{verbatim}\nwhile 0.0001 < b_2 - b:\n    (continue calculation)\n\\end{verbatim}\nWhen this criterion is used, it stops slightly after 1300 steps.\n\nThird we can set a limit on number of steps. This is arguably the best way\nto do it if you have the empirical data to back it up. Since we are working\nwith a single dataset and not in a general application, this is easy to\ncalculate, however it is technically wasteful in some cases, as the\nconvergence will occur before the step limit is reached, and for this reason\nI chose the second method instead.\n\n\\end{document}", "meta": {"hexsha": "1ea9c2a9c9538e17045e29e5f83c4c683a5fed0c", "size": 20975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "P2/writeup.tex", "max_stars_repo_name": "nashkevin/EECS-391", "max_stars_repo_head_hexsha": "35cb315af9aa8fbca2f19f7707f3e14616a22577", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "P2/writeup.tex", "max_issues_repo_name": "nashkevin/EECS-391", "max_issues_repo_head_hexsha": "35cb315af9aa8fbca2f19f7707f3e14616a22577", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P2/writeup.tex", "max_forks_repo_name": "nashkevin/EECS-391", "max_forks_repo_head_hexsha": "35cb315af9aa8fbca2f19f7707f3e14616a22577", "max_forks_repo_licenses": ["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.4266917293, "max_line_length": 172, "alphanum_fraction": 0.7267699642, "num_tokens": 6028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6797134512508244}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Sets and Number Systems}\r\n\r\nA \\dfont{set} can be thought of as any collection of \\ifont{distinct} objects, called {\\bf{elements}} of the set.\\\\\r\n\r\nIn general, there are three ways to describe sets.  \r\n\r\n\t\r\n\\begin{formulabox}[Ways to Describe Sets]\r\n\t\r\n\t\\begin{enumerate}\r\n\t\t\r\n\t\t\\item \\textbf{Verbally:} Use a sentence to define a set.\\index{set ! verbal description}\r\n\t\t\r\n\t\t\\item \\textbf{Roster Notation:}  Begin with a left brace `$\\{$', list each element of the set \\textit{only once} and then end with a right brace `$\\}$'.\\index{set ! roster method}\r\n\t\t\r\n\t\t\\item \\textbf{Set-Builder Notation:} A combination of verbal and roster notation using a ``dummy variable'' such as $x$.\\index{set ! set-builder notation}\\index{set-builder notation}\r\n\t\\end{enumerate}\r\n\\end{formulabox} \t\r\n\r\n\r\n\\begin{example}{Roster Notation for Sets}{Sets}\r\n\tThe collection $\\{a,b,1,2\\}$ is a set. It consists of the collection of\r\n\tfour distinct objects, namely, $a$, $b$, $1$ and $2$. The order of the elements doesn't matter, so the same set could be described as $\\{2,a,1,b\\}$. \r\n\\end{example}\r\n\r\nTypically, sets are represented using \r\n\\dfont{set-builder notation} and are surrounded by braces.\r\nRecall that $(,)$ are called \\dfont{parentheses} or \\dfont{round brackets};\r\n$[,]$ are called \\dfont{square brackets}; and $\\{,\\}$ are called \\dfont{braces} or \\dfont{curly brackets}. \\\\\r\n\r\n\\begin{example}{Set-Builder Notation for Sets}{SetBuilder}\r\nThe expression $\\displaystyle{ \\{x \\, \\ssep  x \\geq 0 \\} }$ can be read as the set of all elements $x$ such that $x$ is greater than or equal to zero.  The vertical bar $\\ssep$, which can also be written as a colon $:$, is a separator that can be read as \"such that\", \"for which\", or \"with the property that\". \r\n\\end{example}\t\r\n\r\nLet $S$ be any set. We use the notation $\\dfont{x\\in S}$ to mean that $x$ \r\nis an element \\ifont{inside} of the set $S$, and the notation $\\dfont{x\\not\\in S}$ to mean that $x$ is \\ifont{not} an element of the set $S$. \\\\\r\n\r\n\r\n\\begin{example}{Set Membership}{SetMembership}\r\nIf $S=\\{a,b,c\\}$, then $a\\in S$ but $d\\not\\in S$.\r\n\\end{example}\r\n\r\n%The \\dfont{intersection} between two sets $S$ and $T$ is denoted \r\n%by $S\\cap T$ and is the collection of all elements that belong to \r\n%\\ifont{both} $S$ and $T$. The \\dfont{union} between two sets $S$ \r\n%and $T$ is denoted by $S\\cup T$ and is the collection of all elements \r\n%that belong to \\ifont{either} $S$ or $T$ (or both). \\\\\r\n%\r\n%\\begin{example}{Union and Intersection}{UnionIntersection}\r\n%Let $S=\\{a,b,c\\}$ and $T=\\{b,d\\}$.\r\n%Then $S\\cap T=\\{b\\}$ and $S\\cup T=\\{a,b,c,d\\}$. \r\n%Note that we do \\ifont{not} write the element $b$ twice in $S\\cup T$ even \r\n%though $b$ is in both $S$ and $T$.\r\n%\\end{example}\r\n\r\nNumbers can be classified into sets called \\dfont{number systems}.\r\n\r\n\r\n\\begin{formulabox}[Sets of Numbers]\r\n\r\n\\begin{enumerate}\r\n\t\r\n\t\\item The \\textbf{Empty Set}:\\index{set ! empty}\\index{empty set} $\\emptyset=\\{ \\}=\\{x\\,|\\,\\mbox{$x\r\n\t\t\\neq x$}\\}$.  This is the set with no elements.  Like the number `$0$,' it  plays a vital role in mathematics.\r\n\t\r\n\t\\item The \\textbf{Natural Numbers}:\\index{natural number ! set of}\\index{natural number ! definition of} $\\mathbb N= \\{ 1, 2, 3,  \\ldots\\}$ The periods of ellipsis here indicate that the natural numbers contain $1$, $2$, $3$, `and so forth'.\r\n\t\r\n\t\\item The \\textbf{Whole Numbers}:\\index{whole number ! set of}\\index{whole number ! definition of} $\\mathbb W = \\{ 0, 1, 2, \\ldots \\}$\r\n\t\r\n\t\\item The \\textbf{Integers}:\\index{integer ! set of}\\index{integer ! definition of} $\\mathbb Z=\\{ \\ldots, -1, -2, -1, 0, 1, 2, 3, \\ldots \\}$\r\n\t\r\n\t\\item The \\textbf{Rational Numbers}:\\index{rational number ! set of}\\index{rational number ! definition of} $\\mathbb Q=\\left\\{\\frac{a}{b} \\, | \\, a \\in \\mathbb Z \\, \\mbox{and} \\, b \\in \\mathbb Z \\right\\}$.  \\underline{Ratio}nal numbers are the \\underline{ratio}s of integers (provided the denominator is not zero!)  It turns out that another way to describe the rational numbers is: \\[\\mathbb Q=\\{x\\,|\\,\\mbox{$x$ possesses a repeating or terminating decimal representation.}\\}\\]\r\n\t\r\n\t\\item The \\textbf{Real Numbers}:\\index{real number ! set of}\\index{real number ! definition of} $\\mathbb R = \\{ x\\,|\\,\\mbox{$x$ possesses a decimal representation.}\\}$\r\n\t\r\n\t\\item The \\textbf{Irrational Numbers}:\\index{irrational number ! set of}\\index{irrational number ! definition of} $\\mathbb P = \\{x\\,|\\,\\mbox{$x$ is a non-rational real number.}\\}$  Said another way, an \\underline{ir}rational number is a decimal which neither repeats nor terminates.\r\n\t\r\n\t\\item The \\textbf{Complex Numbers}:\\index{complex number ! set of}\\index{complex number ! definition of} $\\mathbb C=\\{a+bi\\,|\\,\\mbox{$a$,$b \\in \\mathbb R$ and $i=\\sqrt{-1}$}\\}$  Despite their importance, the complex numbers play only a minor role in the text.\r\n\t\r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\nIt is important to note that every natural number is a whole number, which, in turn, is an integer.   Each integer is a rational number (take $b =1$ in the above definition for $\\mathbb Q$) and the rational numbers are all real numbers, since they possess decimal representations.   If we take $b=0$ in the above definition of $\\mathbb C$, we see that every real number is a complex number.  In this sense, the sets $\\mathbb N$, $\\mathbb W$, $\\mathbb Z$, $\\mathbb Q$, $\\mathbb R$, and $\\mathbb C$ are nested.\r\n\r\n\r\n\r\n%\\begin{center}\r\n%  \\begin{tabular}{| c || c | c |}\r\n%    \\hline\r\n%    $\\mathbb{N}$ & the \\dfont{natural} numbers \r\n%    \t\t& $\\{1, 2, 3,\\ldots\\}$ \\\\ \\hline\r\n%    $\\mathbb{Z}$ & the \\dfont{integers} \r\n%    \t\t& $\\{\\dots,-3,-2, -1, 0, 1, 2, 3,\\dots\\}$ \\\\ \\hline\r\n%    $\\mathbb{Q}$ & the \\dfont{rational} numbers \r\n%    \t\t& Ratios of integers: $\\left\\{\\frac{p}{q}\\, \\ssep\\,p,q\\in\\mathbb{Z},q\\not=0\\right\\}$ \\\\ \\hline\r\n%    $\\mathbb{R}$ & the \\dfont{real} numbers \r\n%    \t\t& Can be written using a finite or infinite \\ifont{decimal expansion} \\\\ \\hline\r\n%    $\\mathbb{C}$ & the \\dfont{complex} numbers \r\n%    \t\t& These allow us to solve equations such as $x^2+1=0$ \\\\\r\n%    \\hline\r\n%  \\end{tabular}\r\n%\\end{center}\r\n\r\n%In the table, the set of rational numbers is written using\r\n%set-builder notation. The vertical bar $\\ssep$, which can also be written as a colon $:$, is a separator that can be read as \"such that\", \"for which\", or \"with the property that\". \r\n%The expression $\\left\\{\\frac{p}{q}\\, \\ssep\\,p,q\\in\\mathbb{Z},q\\not=0\\right\\}$ can be read out loud as\r\n%\\ifont{the set of all fractions $p$ over $q$ such that $p$ and $q$ are both integers and $q$ is not equal to zero}. \r\n%\\\\\r\n\r\n\\begin{example}{Rational Numbers}{RationalNumbers}\r\nThe numbers $-\\frac{3}{4}$, $2.647$, $17$, $0.\\bar{7}$ are all rational numbers. \r\nYou can think of rational numbers as \\ifont{fractions} of one integer over another. \r\nNote that 2.647 can be written as a fraction: \r\n\\[ 2.647=2.647\\times\\frac{1000}{1000}=\\frac{2647}{1000} \\]\r\nAlso note that in the expression $0.\\bar{7}$, the bar over the $7$ indicates \r\nthat the $7$ is repeated forever: \r\n\\[ 0.77777777\\ldots=\\frac{7}{9}\\]\r\n\\vspace{-0.5cm}\r\n\\end{example} \r\n\r\nAll rational numbers are real numbers with the property that\r\ntheir decimal expansion either \\ifont{terminates} after a finite number \r\nof digits or begins to \\ifont{repeat} the same finite sequence of digits over and over.\r\nReal numbers that are not rational are called \\dfont{irrational}. \\\\\r\n\r\n\r\n\r\n\\begin{example}{Irrational Numbers}{IrrationalNumbers}\r\nSome of the most common irrational numbers include:\r\n\\begin{itemize}\r\n\t\\item $\\sqrt 2$.\\quad \r\n\t\t\tCan you prove this is irrational? (The proof uses a technique called \\ifont{contradiction}.)\r\n\t\\item $\\pi$.\\quad \r\n\t\t\tRecall that $\\pi$ (\\dfont{pi}) is defined as the ratio of the circumference of a circle to its diameter and can be approximated by $3.14159265$.\r\n\t\\item $e$.\\quad \r\n\t\t\tSometimes called Euler's number, $e$ can be approximated by $2.718281828459$. \r\n\t\t\tWe will review the definition of $e$ in a later chapter.\r\n\\end{itemize}\r\n\\end{example}\r\n\r\nLet $S$ and $T$ be two sets. If every element of $S$ is also an element of $T$, then\r\nwe say $S$ is a \\dfont{subset} of $T$ and write $S\\subseteq T$. Furthermore, if $S$ is\r\na subset of $T$ but not equal to $T$, we often write $S\\subset T$.\r\nThe five sets of numbers in the table give an increasing sequence of sets:\r\n\\[ \\mathbb{N} \\subset \\mathbb{Z} \\subset \\mathbb{Q} \\subset \\mathbb{R} \\subset \\mathbb{C}. \\]\r\n\r\nThat is, all natural numbers are also integers, all integers are also rational numbers, all rational numbers are also real numbers, and all real numbers are also complex numbers.\\\\\r\n\r\nFor the most part, this textbook focuses on sets whose elements come from the real numbers $\\mathbb R$.  Recall that we may visualize $\\mathbb R$ as a line. Segments of this line are called \\textbf{intervals}\\index{interval ! definition of} of numbers. Below is a summary of the so-called \\textbf{interval notation}\\index{interval ! notation for} associated with given sets of numbers.  For intervals with finite endpoints, we list the left endpoint, then the right endpoint.  We use square brackets, `$[$' or `$]$', if the endpoint is included in the interval and use a filled-in or `closed' dot to indicate membership in the interval. Otherwise, we use parentheses, `$($' or `$)$' and an `open' circle to indicate that the endpoint is not part of the set.  If the interval does not have finite endpoints, we use the symbols $-\\infty$ to indicate that the interval extends indefinitely to the left and $\\infty$ to indicate that the interval extends indefinitely to the right.  Since infinity is a concept, and not a number, we always use parentheses when using these symbols in interval notation, and use an appropriate arrow to indicate that the interval extends indefinitely in one (or both) directions.\\\\\r\n\r\n\r\n\r\n", "meta": {"hexsha": "e772be54613f1f6781f531ddfdcb0f468a1efa59", "size": 9882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-1-1-numbers-systems-sets.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-1-numbers-systems-sets.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-1-numbers-systems-sets.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": 64.1688311688, "max_line_length": 1209, "alphanum_fraction": 0.6797207043, "num_tokens": 2986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6797134476489026}}
{"text": "\\section{Error Analysis}\n\n\\begin{slide}{Fitting Strategies in IFEFFIT }\n    \n\n    The general idea is to find a {\\RedEmph{Model}} that best matches the {\\BlueEmph{Data}}.\n\n    \\vmm\n    \n    We use $\\bchi^2$ (don't confuse with EXAFS $\\bchi$!!) to describe our\n    fit:\n\n    \\[ \\displaystyle{\\mathbf{\n        \\chi^2  =   \\sum_i^{N_{\\rm fit}} \\frac{[\\chi_i^{\\rm data} - \\chi_i^{\\rm\n            model}({x})]^2}{\\epsilon^2} \n      }} \\]\n\n    \n    \\vmm $\\mathbf{N_{\\rm fit}} = $ number of points to fit, \n    $\\mathbf{x} = $  the set of variables, and $\\mathbf{\\epsilon} =$ the estimated noise\n    level in the data.\n\n    \\vmm \\hrule \\vmm\n    \n    But we usually oversample our data (that is, $\\mathbf{N_{\\rm fit} >\n      N_{\\rm idp} } $), so we renormalize this to $ \\mathbf{N_{\\rm idp}}$,\n    and assert that $\\epsilon$ is a constant:\n\n    \\begin{center} \\highlightbox{\n        $ \\displaystyle{\\mathbf{\n            \\chi^2  =  \\frac{ N_{\\rm idp}}{\\epsilon^2 N_{\\rm fit}}\n            \\sum_i^{N_{\\rm fit}} [\\chi_i^{\\rm data} - \\chi_i^{\\rm model}({x})]^2\n          }} \n        $\n      } \n    \\end{center}\n\n    \\vmm\n\n    \\begin{center}\n       {\\RedEmph{ The Best Fit is that with lowest $\\bchi^2$. }}\n    \\end{center}\n\n    \\vmm \\hrule \\vmm\n\n    \\vmm\n    \n    The fitting algorithm finds the set of variables $\\mathbf{x} $ which\n    minimizes $[\\mathbf{\\chi_i^{\\rm data} - \\chi_i^{\\rm model}({x})}]$ in\n    this ``least-squares'' sense.\n\n\n\\vfill\n\\end{slide} \n\n\\begin{slide}{Other Fitting Statistics}\n\\small\n\n    Other ``goodness-of-fit statistics'':\n    \\begin{description}\n    \\item[{\\Red{chi-square}}] As before: \\vmm\n\n      $ \\displaystyle{\\mathbf{\n          \\chi^2  =  \\frac{ N_{\\rm idp}}{\\epsilon^2 N_{\\rm fit}}\n          \\sum_i^{N_{\\rm fit}} [\\chi_i^{\\rm data} - \\chi_i^{\\rm model}({x})]^2\n        }} \n      $\n      \n      \n    \\item[{\\Red{reduced chi-square}}] scale $\\mathbf{N_{\\rm varys}}$ by the \n      ``degrees of freedom'' : \\vmm\n\n      $ \\chi^2_\\nu =  \\chi^2 / (N_{\\rm idp}-N_{\\rm varys}) $\n\n\n      \\vmm\n\n      \n      For a ``Good Fit'', $\\chi^2_\\nu$ should be $\\sim$ 1 (This\n      {\\RedEmph{never}} happens!!).\n\n    \\item[{\\Red{R-factor}}] $\\mathbf{\\cal{R}}$  gives a ``fractional misfit'': \\vmm\n\n      $ \\displaystyle{\\mathbf{\n          {\\cal{R}} = \n          {\\sum_i^{N_{\\rm fit}}[\\chi_i^{\\rm data} - \\chi_i^{\\rm model}({x})]^2 }\n          / \n           { \\displaystyle{\\sum_i^{N_{\\rm fit}} [{\\chi_i^{\\rm data}}]^2}}\n        }}\n      $\n\n      \\vmm $\\mathbf{\\cal{R}}$ is useful because it is not scaled to the data\n    uncertainty $\\epsilon$. \n\n    \\end{description}\n\\vfill\n\\end{slide} \n\n\n\\begin{slide}{Fitting in $R$-space, $k$-space, etc.}\n    \n    The $\\bchi^2$ definition didn't say anything about what our data\n    {\\Blue{$\\chi_i^{\\rm data}$}} is.\n\n    \\vmm  We usually fit in $R$-space, because \n    we can throw out unwanted ``shells'':\n    \n    \\vmm \\vmm \\vmm \n\n    {\n      \\begin{tabular}{ll}\n        \\hspace{-10mm} \\begin{minipage}{54mm}{\\wgraph{53mm}{reduction/chik}}  \\end{minipage} &\n        \\hspace{-5mm}  \\begin{minipage}{54mm}{\\wgraph{53mm}{reduction/chir_win}}\\end{minipage}\n    \\end{tabular}\n    }\n\n    \\vmm \n    Fitting in $R$-space gives more meaningful fit statistics when we know that\n    we're not fitting all the spectral features.\n    \n    \\vmm \n    {\\RedEmph{AND:}} We can also have the data {\\Blue{$\\chi_i^{\\rm data}$}}\n    extend over {\\Red{multiple data sets}}, {\\Red{multiple $k$-weightings}},\n    etc, as long as we generate {\\Red{$\\mathbf{\\chi_i^{\\rm model}(x)}$}} to\n    match these data.\n\n\\vfill\n\\end{slide} \n\n\n%%%%%%%%%%%%%%%%%%%%%%\n\\begin{slide}{$\\mathbf\\epsilon$: The Noise Levels in Data }\n\n    \n    Here are some typical EXAFS spectra (both transmission, 1 sec/point), \n    and their estimated noise $\\epsilon$ in $\\bchi(k)$:\n\n\n    \\vmm\n\n      \\begin{tabular}{lcl}\\setlength{\\baselineskip}{2pt}\n        0.2 mM Zn nitrate solution & & Cu foil Room Temperature   \\\\\n        \\hspace{-7mm} \\wgraph{48mm}{errors/noise_data01} & \\hspace{2mm} & \n        \\hspace{-5mm} \\wgraph{48mm}{errors/noise_data02} \\\\\n        $\\epsilon \\approx 6.6 \\times 10^{-4}$ ``Normal Data''& &\n        $\\epsilon \\approx 1.6 \\times 10^{-4}$ ``Good Data''\\\\\n      \\end{tabular}\n\n      \\vmm\n\n      For the Zn solution, this noise level is consistent with counting\n      statistics for ``Number of Photons in Ion Chambers''! \n\n\\vfill\n\\end{slide} \n\n\n%%%%%%%%%%%%%%%%%%%%%%\n\\begin{slide}{$\\epsilon$: Noise Levels in Data}\n\\small\n\\hspace{-.1mm}\n\\begin{center}\n  \\begin{minipage}{95mm}\\setlength{\\baselineskip}{10pt}\n    \n    $\\epsilon$ is estimated from the high-$R$ (15\n    to 25 \\AA) components of the data:\n    \n    \\vmm\n      \\begin{tabular}{lcl}\n        $|\\chi(R)|$ &    &  $ \\hspace{4mm} \\log_{10}(|\\chi(R)|)$ \\\\\n        \\vspace{-3mm}\\hspace{-10mm} \\wgraph{50mm}{errors/znnoise01} &      & \n        \\hspace{-5mm}  \\wgraph{50mm}{errors/znnoise02} \\\\\n      \\end{tabular}\n      \n      \\begin{itemize}\n        \\item The Zn data really shows ``white noise''.\n          \n        \\item The Cu data has signal well above the noise level past 10\\AA!\n\n      \\item Using the range $R=[15,25]\\rm\\, \\AA$ may \n        {\\RedEmph{overestimate}} $\\epsilon$ for good data.\n      \\end{itemize}\n      \n      A general property of Fourier transforms (Parseval's Theorem) translates\n      the noise in $\\bchi(R)$ to the noise in $\\bchi(k)$. \n      \n\n      \\begin{center}\n        \\highlightbox{ \\begin{minipage}{70mm} When fitting in $R$-space, we want\n            $\\epsilon_R$, the noise in $\\bchi(R)$, but $\\epsilon_k$, the noise\n            in $\\bchi(k)$, is easier to interpret.\n      \\end{minipage}}\\end{center}\n\n  \\end{minipage}\n\\end{center}\n\\vspace{1mm}\n\\vfill\n\\end{slide} \n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%\n\\begin{slide}{Error Bars: the uncertainities in the fit variables}\n\\small\n\\hspace{-.1mm}\n\\begin{center}\n  \\begin{minipage}{95mm}\\setlength{\\baselineskip}{10pt}\n    \n    A fit finds $\\Blue{\\mathbf{x_0}}$, the ``best fit values'' of the variables\n    $\\Blue{\\mathbf{x}}$ by minimizing $\\bchi^2$.\n\n    \n    \\vmm \\vmm The uncertaintes in $\\Blue{\\mathbf{x}}$ are found by increasing\n    the best $\\bchi^2$ by 1:\n\n    \\vmm\n    \\begin{center} \\wgraph{60mm}{errors/ellipse} \n    \\end{center}\n      \n    \\vmm\n\n    {\\RedEmph{increase by 1}} implies that the fit is ``Good'' ($\\chi^2_\\nu\n    \\approx 1$).\n    \n    \\vmm Sadly, we typically get {\\highlightbox{$\\chi^2_\\nu \\gtrsim 50$!! }}\n    even for very good fits.\n    So, we increase the best $\\bchi^2$ by $\\bchi^2_\\nu$.\n    \n    \\vmm \n    \\begin{center}{\\highlightbox{\n          The ``$\\bchi^2 + 1$'' error bars $\\delta x$ are multiplies by\n          $\\mathbf{\\sqrt{\\bchi^2_\\nu}}$.\n        }}\n    \\end{center}\n    \n  \\end{minipage}\n\\end{center}\n\\vspace{1mm} \\vfill\n\\end{slide} \n\n%%%%%%%%%%%%%%%%%%%%%%\n\\begin{slide}{Error Bars: correlations between fit variables}\n\\small\n\\hspace{-.1mm}\n\\begin{center}\n  \\begin{minipage}{95mm}\\setlength{\\baselineskip}{10pt}\n    \n    Pairs of variables can be {\\RedEmph{correlated}}: changing one variable away\n    from its optimum value can be compensated by changing another variable away\n    from its best value.  The uncertainties needs to take correlations into\n    account.\n\n    \\vmm\n    \\begin{center} \\wgraph{60mm}{errors/ellipse2}   \\end{center}\n      \n\n    \\vmm \n    The uncertainty in $x$ is $\\delta x$, NOT  $\\delta x'$!\n    \n    \\vmm \n    \n    The correlations values are useful statistics, measuring the ellipse shape.\n\n    \\vmm\n    \n    In EXAFS, ($R$, $E_0$) and ($N$, $\\sigma^2$) are usually very highly\n    correlated ($>0.85$).\n\n\n  \\end{minipage}\n\\end{center}\n\\vspace{1mm}\n\\vfill\n\\end{slide} \n\n\n\n\\begin{slide}\n  \\small\n  \\begin{cenpage}{80mm}\\setlength{\\baselineskip}{10pt}\n    \\vfill\n    \\begin{center}\n      {\\Huge\\BlueEmph{ Some Fit Examples}   }\n  \n    \\end{center}\n    \\vfill\n  \\end{cenpage}\n\\end{slide} \n\n\n%%%%%%%%%%%%%%%%%%%%%%\n\\begin{slide}{Room Temperature Cu Fit }\n\\small\n\\hspace{-.1mm}\n\\begin{center}\n  \\begin{minipage}{100mm}\\setlength{\\baselineskip}{10pt}\n    \n    Simple fit to first shell of Cu foil (300K): $k = [2,16] \\rm\\,\n    \\AA^{-1}$, $R = [1.7,2.6] \\rm\\, \\AA$, $k$-weight=2, $N_{\\rm idp} = 8.4\n    $.  Fit results and statistics:\n    \n\n    {\n      \\hspace{0.1mm}\\begin{tabular}{lll}\n        $R = 2.548(0.007) \\, \\rm\\AA$ \n        &     \n        $\\Delta E_0 = 4.5(0.6)$ \n        &  \n        $C_3      = 9(9) \\times10^{-5} \\rm\\, \\AA^3$ \n        \\\\\n        $\\epsilon_k = 1.6 \\times 10^{-4}$ \n        &\n        $S_0^2 = 0.96(0.04)$  \n        &\n        $\\sigma^2 = 8.5(0.3) \\times10^{-3} \\rm\\, \\AA^2$ \n        \\\\\n        $\\chi^2 = 678$ &\n        $\\chi^2_\\nu = 196.7$   & ${\\cal{R}} = 0.00107 $\\\\\n      \\end{tabular}\n    }\n\n    \\vmm\n      \\begin{tabular}{lcl}\n        \\hspace{-10mm} \\wgraph{49mm}{errors/cufit02} & \\hspace{2mm} & \n        \\hspace{-3mm}  \\wgraph{49mm}{errors/cufit01} \\\\\n      \\end{tabular}\n\n      \\begin{itemize}\n      \\item ${\\cal{R}} = 0.1\\% $ -- a good fit!  But like $\\chi^2_\\nu$,\n        ${\\cal{R}}$ is larger than the $\\epsilon_k$ suggests.\n      \\item These error bars account for correlations.  They increase\n        $\\chi^2$ by $\\chi^2_\\nu$ (not 1), which scales them by\n        $\\sqrt{\\chi^2_\\nu}\\approx 14$ over ``increase $\\chi^2$ by 1''.\n      \\end{itemize}\n\n      \\vmm\n\n  \\end{minipage}\n\\end{center}\n\\vspace{1mm}\n\\vfill\n\\end{slide} \n\n\n", "meta": {"hexsha": "8671b8c4bec55aaecd2ff85879abdceb99392b6f", "size": 9274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/advclass_erroranalysis.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/advclass_erroranalysis.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/advclass_erroranalysis.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": 26.8034682081, "max_line_length": 94, "alphanum_fraction": 0.5622169506, "num_tokens": 3170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219503, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6797134458937495}}
{"text": "\n\\subsection{Bayesian classifier}\n\n\\subsubsection{Classification risk}\n\nWe can measure the risk of a classifier. This is the chance of misclassification.\n\n\\(R(C)=P(C(X)\\ne Y)\\)\n\n\\subsubsection{The Bayesian classifier}\n\nThis is the classifer \\(C(X)\\) which minimises the chance of misclassification.\n\nIt takes the output of the soft classifier and chooses the one with the highest chance.\n\n", "meta": {"hexsha": "0eeef0edb584a3775ff31765c7f2fa0aa588cf6b", "size": 389, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/parametric/04-04-classificationBayes.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/04-04-classificationBayes.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/04-04-classificationBayes.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.3125, "max_line_length": 87, "alphanum_fraction": 0.7712082262, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.679678949103554}}
{"text": "\\documentclass[simplex.tex]{subfiles}\n% NO NEED TO INPUT PREAMBLES HERE\n% packages are inherited; you can compile this on its own\n\\begin{document}\n\\subsection{Non-Parametric Shape Clustering}\n%\nWe have been mostly focused on developing \nnon-parametric clustering methods.\nTo this purpose, we are exploring ideas from energy statistics,\nwhich is non-parametric,\nrobust, and rotational invariant, thus it incorporates the main ingredients\nthat we are looking for. The main difficulty is to formulate an \nalgorithm based on this, i.e. to identify the correct test \nstatistic, or to formulate it as a feasible optimization problem.\nConsider $K$-Means clustering problem which is \n$\n\\min_{\\{\\mathcal{C}_k\\}} \n\\sum_{k=1}^K \\sum_{x \\in \\mathcal{C}_k} \\| x - \\mu_k  \\|^2,\n$\nwhere $\\mathcal{C}_k$ is the $k$th cluster and $\\mu_k$ the mean of its points.\nWe showed that this problem is equivalent to\n\\begin{equation}\n\\max_{G} \\textnormal{Tr}\\left( G^T K G \\right) \\qquad \n\\mbox{s.t. \\, $G \\ge 0$, $G^T G=I$, $G G^T e_1 = e_1$}.\n\\end{equation}\nwhere $e_1 = (1,1,\\dotsc,1)^T$.\nThis is a Quadratically Constrained Quadratic Problem (QCQP), which is usually \nNP-hard.\nAnalogously, consider the energy function \n$\\mathcal{E}(F,G) = 2\\mathbb{E} \\| X - Y\\| - \\mathbb{E}\\| X - X'\\| - \\mathbb{E}\n\\| Y - Y'\\|$ between $X,X' \\sim F$ and $Y,Y' \\sim G$. We showed that this can\nbe written as $\\mathcal{E}(A,B) = e_1^T \\Delta e_1 $, where $\\Delta$ is a\ndissimilarity \nmatrix between the two sets of data points \n$A \\stackrel{iid}{\\sim} F$ \nand $B \\stackrel{iid}{\\sim} G$.\nConsequently, a simple two-class clustering problem would be\n\\begin{equation}\n\\max_{x,z\\in \\mathbb{R}^N} x^T \\Delta z \\qquad \n\\mbox{s.t. $x_i^2=1$, $x+z = 0$},\n\\end{equation}\nwhich is also a QCQP problem. We are currently investigating this problem and\ntrying to generalize it correctly for more classes.\nA simple check of the energy function as a test statistic \nis shown in Fig.~\\ref{fig:nonpar}. \nUnder the null $F = G$, \n$T$ converges to a quadratic form of normally distributed random variables. This\nseems to be the case in the first (blue) histogram, while it is definitely not\nthe case in the other (red and green) histograms. \nFor the blue histogram a single test gives\n$T \\approx 0.32$ (small), for the red\nhistogram $T \\approx 4000 $ (large), and for the green \nhistogram $T \\approx 105$ (large), with\nonly a few points. Thus, energy statistics based approach is \nable to distinguish between\ndifferent distributions, even when the clusters have the same mean, which is a\nproperty that $K$-Means cannot resolve.\n\n%\n\\begin{figure}[h!]\n\\begin{cframed}\n\\centering\n%\\begin{subfigure}[t]{0.45\\textwidth}\n\\includegraphics[width=\\textwidth]{../../figs/energy_hists.pdf}\n%\\label{fig:nonpar57}\n\\caption{\nDistribution of test statistic \n$T\\equiv\\tfrac{n m }{n+m}\\mathcal{E}(A,B)$ \nfor an ensamble obtained from two distributions:\n$A \\stackrel{iid}{\\sim} \\mathcal{N}(\\mu_A,\\sigma_A^2)$ and\n$B \\stackrel{iid}{\\sim} \\mathcal{N}(\\mu_B, \\sigma_B^2)$, where\n$|A|=n$ and $|B|=m$.\nBlue histogram: $\\mu_A = \\mu_B = 0$ and $\\sigma_A = \\sigma_B = 1$;\nRed histogram: $\\mu_A = - \\mu_B = 1$ and $\\sigma_A = \\sigma_B = 1$;\nGreen histogram: $\\mu_A = \\mu_B = 0$, $\\sigma_A = 1$ and $\\sigma_B = 1.5$.\n}\n%\\end{subfigure}\n%\\begin{subfigure}[t]{0.45\\textwidth}\n%\\includegraphics[width=\\textwidth]{../../figs/nonPar357.png}\n%\\label{fig:nonpar357}\n%\\caption{\n%Classification error against the size of each\n%cluster (the three classes have the same number of points) is\n%shown in blue. The red line is standard\n%K-means with Euclidean distance for comparison.}\n%\\end{subfigure}\n%\\caption{\n%  MNIST handwritten digits and classification error results.\n%}\n\\label{fig:nonpar}\n\\end{cframed}\n\\end{figure}\n%\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "59c23610adc8718a0058edc733b508b01c5d1a00", "size": 3752, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Reporting/reports/2017-02/nonparShape.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-02/nonparShape.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-02/nonparShape.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": 39.0833333333, "max_line_length": 80, "alphanum_fraction": 0.7150852878, "num_tokens": 1203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6796789391762277}}
{"text": "\\subsection{Direct Optimization}\nTime is free so we have a new unknowns. we use $t_f$ as a new state and change some parameter that will describe here.\n$$J = t_f^2, \\qquad 0\\leq t\\leq t_f,\\qquad \\tau = \\dfrac{t}{t_f}, \\qquad 0\\leq\\tau\\leq 1$$\n$$\n\\vec{a}_N(\\vec{x}(t),\\vec{u}(t),t_f, t) = t_f\\vec{a}(\\vec{x}(t),\\vec{u}(t), t)\n$$\n$$\ng_N(\\vec{x}(t),\\vec{u}(t),t_f, t) = t_fg(\\vec{x}(t),\\vec{u}(t), t)\n$$\n$$\n\\mathcal{H} = g_N(\\vec{x}(t),\\vec{u}(t),t_f, t) + P^T\\vec{a}_N(\\vec{x}(t),\\vec{u}(t),t_f, t) \n$$\n\\begin{align*}\n\tG_1(u) = &\n\t\\begin{cases}\n\t\t-\\dfrac{1}{g_1(u)}&  g_1(u) \\leq \\epsilon \\\\[1em]\n\t\t-\\dfrac{1}{\\epsilon}\\left(3 - \\dfrac{3g_1(u)}{\\epsilon} + \\left(\\dfrac{g_1(u)}{\\epsilon}\\right)^2\\right) &  g_1(u) > \\epsilon\n\t\\end{cases} \\\\\n\tG_1^\\prime(u) = &\n\t\\begin{cases}\n\t\t\\dfrac{1}{(u - )^2}&  g_1(u) \\leq \\epsilon \\\\[1em]\n\t\t-\\dfrac{1}{\\epsilon}\\left(-\\dfrac{3}{\\epsilon} + \\dfrac{2u-2}{\\epsilon^2} \\right) &  g_1(u) > \\epsilon\n\t\\end{cases} \n\\end{align*}\n\\begin{align*}\n\tG_2(x_2) = &\n\t\\begin{cases}\n\t\t-\\dfrac{1}{g_2(u)}&  g_2(u) \\leq \\epsilon \\\\[1em]\n\t\t-\\dfrac{1}{\\epsilon}\\left(3 - \\dfrac{3g_2(u)}{\\epsilon} + \\left(\\dfrac{g_2(u)}{\\epsilon}\\right)^2\\right) &  g_2(u) > \\epsilon\n\t\\end{cases} \\\\\n\tG_2^\\prime(u) = &\n\t\\begin{cases}\n\t\t\\dfrac{1}{(u + 1)^2}&  g_2(u) \\leq \\epsilon \\\\[1em]\n\t\t-\\dfrac{1}{\\epsilon}\\left(\\dfrac{3}{\\epsilon} + \\dfrac{2u+2}{\\epsilon^2} \\right) &  g_2(u) > \\epsilon\n\t\\end{cases} \n\\end{align*}\n$$\ng_N(\\vec{x}(t),\\vec{u}(t),t_f, t) = t_f^2 + r_kG(u)\n$$\n$$\n\\dfrac{\\partial J}{\\partial t_f} = \\dfrac{\\partial h}{\\partial t_f} + \\int_{0}^{1}\n\\dfrac{\\partial \\mathcal{H}}{\\partial t_f}\n$$\n$$\n\\dfrac{\\partial J}{\\partial \\vec{X}} = \n\\begin{bmatrix}\n\t\\left.\\dfrac{\\mathcal{H}}{\\partial u}\\right\\vert_{\\tau_0}\\\\\n\t\\left.\\dfrac{\\mathcal{H}}{\\partial u}\\right\\vert_{\\tau_1}\\\\\n\t\\left.\\dfrac{\\mathcal{H}}{\\partial u}\\right\\vert_{\\tau_2}\\\\\n\t\\vdots\\\\\n\t\\left.\\dfrac{\\mathcal{H}}{\\partial u}\\right\\vert_{\\tau_f}\\\\[20pt]\n\t\\dfrac{\\partial h}{\\partial t_f} + \\int_{0}^{1}\n\t\\dfrac{\\partial \\mathcal{H}}{\\partial t_f}\\\\\n\\end{bmatrix}\n$$\n\\begin{itemize}\n\t\\item Steepest Descent\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q3/Steepest Descent + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\\newpage\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q3/Steepest Descent + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\\newpage\n\t\\item BFGS\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q3/BFGS + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q3/BFGS + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\\end{itemize}\n", "meta": {"hexsha": "1141669f73b3eb0ed334f9bb7a70423db01aed51", "size": 3021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW3/Report/Q3/Q3_a.tex", "max_stars_repo_name": "alibaniasad1999/Optimal-Control", "max_stars_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T13:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T13:16:54.000Z", "max_issues_repo_path": "HW/HW3/Report/Q3/Q3_a.tex", "max_issues_repo_name": "alibaniasad1999/Optimal-Control", "max_issues_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW3/Report/Q3/Q3_a.tex", "max_forks_repo_name": "alibaniasad1999/Optimal-Control", "max_forks_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5666666667, "max_line_length": 127, "alphanum_fraction": 0.6302548825, "num_tokens": 1312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.679678935007808}}
{"text": "\\section{Constrained Problems}\n\\label{sec:a22constrained}\n\n\\paragraph{G08}\n\nThis problem originates from \\cite{Schoenauer93Constrained}.\nWe changed the domain from $\\clint{0, 10}^2$\nto $\\clint{0.5, 2.5} \\times \\clint{3, 6}$\nto increase the size of feasible region.\nIn addition, we use different frequencies for the sine terms\nas in \\cite{Gavana13Global}.\n\\vspace{-1.6em}\n\n\\begin{subequations}\n  \\begin{gather}\n    \\centertestfunline{\n      \\testobjfunscaled{G08}(\\xscaled)\n      \\ceq -\\frac{\n        \\sin^3(2\\pi\\xse{1}) \\sin(2\\pi\\xse{2})\n      }{\n        \\xse{1}^3 (\\xse{1} + \\xse{2})\n      },\\quad\n      \\testineqconfunscaled{G08}(\\xscaled)\n      \\ceq \\begin{pmatrix}\n        \\xse{1}^2 - \\xse{2} + 1\\\\\n        1 - \\xse{1} + (\\xse{2} - 4)^2\n      \\end{pmatrix},\n    }\\\\\n    \\centertestfunline{\n      \\xscaled \\in \\clint{0.5, 2.5} \\times \\clint{3, 6},\\quad\n      \\xoptscaled = (1.227971358337, 4.245373366474),\n    }\\\\\n    \\centertestfunline{\n      \\testobjfunscaled{G08}(\\xoptscaled) = -0.09582504141804\n    }\n  \\end{gather}\n\\end{subequations}\n\n\n\\paragraph{G04Squared}\n\nThis problem is based on a problem from\n\\cite{Colville68Comparative} with the objective function\n$\\testobjfunscaled{G04}(\\xscaled)\n\\ceq 5.3578547 \\xse{3}^2 + 0.8356891 \\xse{1} \\xse{5} +\n37.293239 \\xse{1} - 40792.141$ and the same constraints\n$\\testineqconfunscaled{G04}(\\xscaled) \\ceq\n\\testineqconfunscaled{G04Sq}(\\xscaled)$.\nHowever, hierarchical cubic not-a-knot B-splines are able to exactly\nrepresent the polynomial $\\testobjfunscaled{G04}$ of coordinate degree two\non the whole domain $\\clint{\\*0, \\*1}$,\nif the level of the sparse grids is high enough,\nsee \\thmref{cor:sparseGridRegularNAKPolynomials}.\nTherefore, we modified the original G04 problem by squaring the\nobjective function.\nTo ensure that this does not change the location of the global minimum,\nwe added a constant before squaring such that the shifted function\nis non-negative on $\\clint{\\*0, \\*1}$.\n\\vspace{-1.6em}\n\n\\begin{subequations}\n  \\allowdisplaybreaks\n  \\begin{gather}\n  \\centertestfunline{\n    \\testobjfunscaled{G04Sq}(\\xscaled)\n    \\ceq (5.3578547 \\xse{3}^2 + 0.8356891 \\xse{1} \\xse{5} +\n    37.293239 \\xse{1} - 10120)^2,\n  }\\\\\n  \\centertestfunline{\n    \\testineqconfunscaled{G04Sq}(\\xscaled)\n    \\ceq 10^{-3} \\scalebox{0.92}{$\n      \\begin{pmatrix}\n        85334.407 + 5.6858 \\xse{2} \\xse{5} +\n        0.6262 \\xse{1} \\xse{4} -\n        2.2053 \\xse{3} \\xse{5} - 92000\\\\\n        -85334.407 - 5.6858 \\xse{2} \\xse{5} -\n        0.6262 \\xse{1} \\xse{4} +\n        2.2053 \\xse{3} \\xse{5}\\\\\n        80512.49 + 7.1317 \\xse{2} \\xse{5} +\n        2.9955 \\xse{1} \\xse{2} +\n        2.1813 \\xse{3}^2 - 110000\\\\\n        -80512.49 - 7.1317 \\xse{2} \\xse{5} -\n        2.9955 \\xse{1} \\xse{2} -\n        2.1813 \\xse{3}^2 + 90000\\\\\n        9300.961 + 4.7026 \\xse{3} \\xse{5} +\n        1.2547 \\xse{1} \\xse{3} +\n        1.9085 \\xse{3} \\xse{4} - 25000\\\\\n        -9300.961 - 4.7026 \\xse{3} \\xse{5} -\n        1.2547 \\xse{1} \\xse{3} -\n        1.9085 \\xse{3} \\xse{4} + 20000\n      \\end{pmatrix},\n    $}\n  }\\\\\n  \\centertestfunline{\n    \\xscaled \\in \\clint{78, 102} \\times \\clint{33, 45} \\times\n    \\clint{27, 45}^3,\n  }\\\\\n  \\centertestfunline{\n    \\xoptscaled = (78, 33, 29.995256025682, 45, 36.775812905788),\n  }\\\\\n  \\centertestfunline{\n    \\testobjfunscaled{G04Sq}(\\xoptscaled) = 43.590737882363\n  }\n  \\end{gather}\n\\end{subequations}\n", "meta": {"hexsha": "b4a00d928a5cdd0fff1451bf6ffb68423d0731cb", "size": 3353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/a22constrained.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/a22constrained.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/a22constrained.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.6320754717, "max_line_length": 74, "alphanum_fraction": 0.6221294363, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6796559991208669}}
{"text": "\\subsection {ATE abd Selection Bias} \nWhen we observe a group of subjects, some of whom have been treated and some not, we calculate\n\\begin {equation} \\begin {split}\n& \\EE(Y_i(1) \\g  W_i = 1) - \\EE(Y_i(0) \\g  W_i = 0) \\iff \\\\\n& [ \\EE(Y_i(1) \\g  W_i = 1) -  \\EE(Y_i(0) \\g  W_i = 1) ] +  \\\\\n& \\qquad \\EE(Y_i(0) \\g  W_i = 1) -  \\EE(Y_i(0) \\g  W_i = 0) ] \\iff  \\\\\n& \\text {Average Treatment Effect} + \\text { Selection Bias} \\\\\n\\end {split} \\end {equation}\n\n\\subsection {Fisher exact test in R}\n\\begin{lstlisting}\nlibrary(perm)\nperms <- chooseMatrix(6, 3)\nA <- matrix(c(38.2, 37.1, 37.6, 36.4, 37.3, 36), nrow=6, ncol=1, byrow=TRUE)\nis.treatment <- c(1, 1, 1, 0, 0, 0)\n\nn_treatment <- sum(is.treatment)\nn_control <- length(A) - sum(is.treatment)\ntreatment_avg <- (1/n_treatment) * perms %*% A\ncontrol_avg <- (1/3) * (1-perms) %*% A\ntest_statistic <- abs(treatment_avg - control_avg)\n\nrownumber <- apply(apply(perms, 1, \n    function(x) (x == is.treatment)), 2, sum)\nrownumber <- (rownumber == length(A))\nobserved_test <- test_statistic[rownumber == TRUE]\n\nlarger_than_observed <- (test_statistic >= observed_test)\nsum(larger_than_observed) / length(test_statistic)\n\\end{lstlisting}\n\n\n\\subsection {Fixed effects model} \\label {r: fem}\nG(factor(admin)) creates a dummy variable, one per region, and includes the dummy variable\nin the regression\n\\begin{lstlisting}[language=R]\nlibrary(\"lfe\")\nmodel2 <- felm(sex ~ teasown + post + teapost + \nG(factor(admin)), data = qiandata)\nsummary(model2)\n\\end{lstlisting}\n\n% \\subsection {Instrument variable regression}\n% To use the ivreg() function directly one needs to setup the call as\n% \\begin{lstlisting}[language=R]\n% ivreg (y ~ exogenous_vars + endogenous_var | \n% exogenous_vars + instrument_var)\n% \\end{lstlisting}\n\n\n\\subsection{Neyman analysis}\n\\begin{lstlisting}\ndata <- read.csv(\"data_myData.csv\")\ntreatment <- data$T == 1\n\ntreatment_mean <- mean(data$Y[treatment], na.rm=TRUE)\ncontrol_mean <- mean(data$Y[!treatment], na.rm=TRUE)\nate <- treatment_mean - control_mean\n\nNc <- sum(!treatment)\nNt <- sum(treatment)\nSc2 <- (1/(Nc-1)) * sum( (data$Y[!treatment] - control_mean)^2 )\nSt2 <- (1/(Nt-1)) * sum( (data$Y[treatment] - treatment_mean)^2 )\n\nVneyman <- (Sc2/Nc + St2/Nt)\n\n# N > 30\nub <- ate + 1.96 * sqrt(Vneyman)\nlb <- ate - 1.96 * sqrt(Vneyman)\n\n# t-distribution analysis\ng <- ( Vneyman^2 / ( (St2/Nt)^2/(Nt+1) + (Sc2/Nc)^2/(Nc+1) ) ) - 2\nub <- ate + qt(0.975, g) * sqrt(Vneyman)\nlb <- ate - qt(0.975, g) * sqrt(Vneyman)\n\\end{lstlisting}\n\n\\subsection{Regression commands}\n\\begin{lstlisting}\nhprices <- read.csv(\"data_House_Prices_and_Crime_1.csv\")\n\nstr(hprices)\nsummary(hprices)\nsubset(hprices, index_nsa == 54.29)\n\nmodel1 <- lm(index_nsa ~ Homicides + Robberies + Assaults, data=hprices)\nsummary(model1)\nconfint(model1)\n\\end{lstlisting}\n\n\\subsection{F-test, restricted model}\n\\begin{lstlisting}\nmodel_unrest <- lm(index_nsa ~ Homicides + Robberies + Assaults, data=hprices)\nanova_unrest <- anova(model_unrest)\nmodel_rest <- lm(index_nsa ~ I(Homicides-Assaults) + I(Robberies-Assaults), data=hprices)\nanova_rest <- anova(model_rest)\n\n# F statistic\nr <- 1\nk <- 3\nssr_u <- anova_unrest$`Sum Sq`[4]\nssr_r <- anova_rest$`Sum Sq`[length(anova_rest$`Sum Sq`)]\nstatistic_test <- (((ssr_r - ssr_u)/r) / ((ssr_u) / anova_unrest$Df[4]))\npvalue <- df(statistic_test, r, anova_unrest$Df[4])\n\\end{lstlisting}\n\n\\subsection{QQ-plots}\nThe R base functions \\lstinline{qqnorm()} and \\lstinline{qqline()} can be used to produce quantile-quantile plots:\n\\begin{lstlisting}\ndata <- runif(1000)\nqqnorm(data)\nqqline(data)\n\\end{lstlisting}\n\n\\subsection{Density plots}\n\\begin{lstlisting}\ndata <- runif(1000)\nd <- density(data, bw = 0.01)\nplot(d)\n\\end{lstlisting}\n\n\n\\subsection{Difference in difference model}\n\\begin{lstlisting}\nmanufacturing <- read.csv(\"data_manufacturing.csv\")\n\n# Cleaning\nlibrary(tidyverse)\nmanu <- manufacturing %>% \nfilter((year == 1987 | year == 1988) & !is.na(scrap)) %>%\nselect(year, fcode, scrap, grant)\n\ntreated <- manu %>%\n    filter(grant == 1) %>%\n    select(fcode)\ntreated_firms <- treated$fcode\n\n# Add column 'treated'\nmanu <- manu %>%\n    mutate(treated = 1*(fcode %in% treated_firms))\n\n# Average treatment and control \ndid_results <- manu %>%\n    group_by(year, treated) %>%\n    summarize(promedio = mean(scrap), n = n())\ndid_results\n\n# DiD model\ndid_model <- lm(scrap ~ treated + I(year==1988) + I(treated*(year==1988)), data=manu)\n\\end{lstlisting}\n\n\n\\subsection{R distribution functions}\nThe functions for the density/mass function, cumulative distribution function, quantile function and random variate generation are named in the form \\lstinline{dxxx}, \\lstinline{pxxx}, \\lstinline{qxxx} and \\lstinline{rxxx} respectively.\n\\begin{itemize}\n\\item For the beta distribution see \\lstinline{dbeta}.\n\\item For the binomial (including Bernoulli) distribution see \\lstinline{dbinom}.\n\\item For the Cauchy distribution see \\lstinline{dcauchy}.\n\\item For the chi-squared distribution see \\lstinline{dchisq}.\n\\item For the exponential distribution see \\lstinline{dexp}.\n\\item For the F distribution see \\lstinline{df}.\n\\item For the gamma distribution see \\lstinline{dgamma}.\n\\item For the geometric distribution see \\lstinline{dgeom}. (This is also a special case of the negative binomial.)\n\\item For the hypergeometric distribution see \\lstinline{dhyper}.\n\\item For the log-normal distribution see \\lstinline{dlnorm}.\n\\item For the multinomial distribution see \\lstinline{dmultinom}.\n\\item For the negative binomial distribution see \\lstinline{dnbinom}.\n\\item For the normal distribution see \\lstinline{dnorm}.\n\\item For the Poisson distribution see \\lstinline{dpois}.\n\\item For the Student's t distribution see \\lstinline{dt}.\n\\item For the uniform distribution see \\lstinline{dunif}.\n\\item For the Weibull distribution see \\lstinline{dweibull}.\n\\end{itemize}\n\n", "meta": {"hexsha": "fdacb1de1c3d4765ad2393e9d404157956d3bbec", "size": 5813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/r-help.tex", "max_stars_repo_name": "r2cp/MITx_capstone_2", "max_stars_repo_head_hexsha": "a1ef693f8a37c7931900f1721743b1d838ea9908", "max_stars_repo_licenses": ["MIT"], "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/r-help.tex", "max_issues_repo_name": "r2cp/MITx_capstone_2", "max_issues_repo_head_hexsha": "a1ef693f8a37c7931900f1721743b1d838ea9908", "max_issues_repo_licenses": ["MIT"], "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/r-help.tex", "max_forks_repo_name": "r2cp/MITx_capstone_2", "max_forks_repo_head_hexsha": "a1ef693f8a37c7931900f1721743b1d838ea9908", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-02T14:40:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-02T14:40:57.000Z", "avg_line_length": 33.408045977, "max_line_length": 236, "alphanum_fraction": 0.7118527438, "num_tokens": 1853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.679641420689376}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\n\\subsection{Enumeration of Matroids}\n\\begin{defn}\nLet $\\mathcal{I}$ be the collection of subsets of $E$ that do not contain all of the edges of any \\textit{cycle} of $G.$\nWe get a matroid on the edge set of every graph $G$ by defining $\\mathcal{I}$ in this way. This matroid is called the \\textit{cycle matroid} of the graph $G$ and is denoted $M(G).$ We will later prove that this is a matroid.\n\\end{defn}\n\n\\begin{defn}\nIf $M_i, M_j$ are matroids , then there exists a bijection from the ground set of $M_i$ to the ground set of $M_j$, such that a set is independent in the first matroid if and only if it is independent in the second matroid, then $M_i$ and $M_j$ are said to be isomorphic. \n\\end{defn}\n\n\\begin{note}\nA matroid that is isomorphic to the cycle matroid of some graph is called graphic.\nAnd every graphic matroid is binary\n\\end{note}\n\nThe following table from Oxley's text \\cite{ox_book} is enlightening in that it helps us see how many ways a matroid can be defined on a set. \n\\noindent The numbers of non-isomorphic matroids and binary matroids on an n-element set for $0 \\leq n \\leq  8$\n\\begin{center}\n \\begin{tabular}{| c c c c c c c c c c |} \n \\hline\n n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\\\ [0.5ex] \n \\hline\\hline\n matroids & 1 & 2 & 4 & 8 & 17 & 38 & 98 & 306 & 1724\\\\ \n \\hline\n binary matroids & 1 & 2 & 4 & 8 & 16 & 32 & 68 & 148 & 342\\\\\n \\hline\n\\end{tabular}\n\\end{center}\nIt can be seen from this table, that the number of possible matroids on an $n$-set grows very rapidly.\n\\end{document}", "meta": {"hexsha": "efbf33efd74a34ffa3ec751e6c814832636dc61c", "size": 1571, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/intro2.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/intro2.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/intro2.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": 47.6060606061, "max_line_length": 272, "alphanum_fraction": 0.7021005729, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6796414173161577}}
{"text": "\\subsection{Cantilever beam}\n\\paragraph{}\nA two-dimensional cantilever beam subjected to a parabolic shear load at the free end is examined as shown in Fig.~\\ref{iso_fig:cantilever_beam_geo_bc}.\n    \\begin{figure}[h!]\n    \\centering\n        \\scalebox{0.8}{\\includegraphics{isogeometric_sbfem/images/cantilever_beam_geo_bc.eps}}\n        \\caption{ Cantilever beam: Geometry and boundary conditions.}\n        \\label{iso_fig:cantilever_beam_geo_bc}\n    \\end{figure}\n%\nThe geometry is: length $ L = \\SI{8}{\\meter} $, height $ D = \\SI{4}{\\meter} $.\nThe material properties are: Young’s modulus $ E = \\SI{3e7}{\\newton \\per \\square \\meter}$ , Poisson’s ratio $ \\nu = 0.25 $.\nThe parabolic shear force is $P = \\SI{250}{\\meter} $.\nThe exact solutions for the displacements are given by \\citep{Aug2008}:\n    \\begin{equation}\n        \\begin{aligned}\n            u(x,y) &= \n                \\frac{Py}{6 \\mean{E} I}\n                \\left[\n                    \\left(\n                        6L-3x\n                    \\right)x\n                    +\\left(\n                        2+ \\mean{\\nu}\n                    \\right)\\left(\n                        y^2-\\frac{D^2}{4}\n                    \\right)\n                \\right]\n            \\\\\n            v(x,y) &=  \n                -\\frac{P}{6 \\mean{E} I}\n                \\left[\n                    3 \\mean{\\nu} y^2 \\left(\n                        L-x\n                    \\right)+\n                    \\left(\n                        4+5 \\mean{\\nu}\n                    \\right)\\frac{D^2x}{4}+\n                    \\left(\n                        3L-x\n                    \\right)x^2\n                \\right]        \n        \\end{aligned}\n    \\label{iso_eq:cantilever_beam_displacement_solution}\n    \\end{equation}\n%\nwhere $I=D^3/12$ is the moment of inertia, $\\mean{E}=E$, $\\mean{\\nu}=\\nu$ and $\\mean{E}=E/(1-\\nu^2)$, $\\mean{\\nu}=\\nu/(1-\\nu)$ for plane stress and plane strain condition respectively.\nThe stress $\\sigma$ can be expressed as \\citep{Aug2008}\n    \\begin{subequations}\n    \\begin{align}\n        \\sigma_{xx} &= \\frac{P(L-x)y}{I} \\\\\n        \\sigma_{yy} &= 0 \\\\\n        \\tau_{xy} &= -\\frac{P}{2I} \\left[\n            \\frac{D^2}{4} - y^2\n        \\right]\n    \\end{align}\n    \\label{iso_eq:cantilever_beam_stress_solution}\n    \\end{subequations}\n%\nThe strain energy can be derived from Eq.~\\ref{iso_eq:cantilever_beam_stress_solution} and Eq.~\\ref{iso_eq:cantilever_beam_displacement_solution} as\n\\begin{equation}\n\\epsilon = \n    \\frac{1}{2} \\left(\n        \\frac{D^3 L^3 P^2}{36EI^2} + \n        \\frac{D^5LP^2(1+v)}{60EI^2}\n    \\right)\n    \\label{iso_eq:cantilever_beam_energy_solution}\n\\end{equation}\n\\paragraph{}\nIn this example, rigid body motion is constrained by fixing 3 DOF on the left edge of the beam.\n$u_x=0$ for points at $(0,-D/2)$ and $(0,D/2)$ and $u_y =0$ for point at $(0,0)$.\nSurface tractions determined from the analytical solution of stress in Eq.~\\ref{iso_eq:cantilever_beam_stress_solution} are applied on the boundary.\n\n\\paragraph{}\nFrom the description in Section~\\ref{iso_section:surface_traction}, the expression of the surface tractions must be transformed into NURBS-like representation before they can be applied.\nThe control points that describe a second order function as surface tractions in this example can be solved mathematically.\nAssume the knot vector is evenly spaced and the shape functions is in second order, i.e. knot vector $\\Xi=[0,0,0,1,1,1]$.\nWeight vector will be uniform because only the straight line is being interpolated, i.e. weight vector $w=[1,1,1]$.\nThree basis functions used in B-Spline will be\n    \\begin{equation}\n    \\begin{aligned}\n        N_1 & = (1-u)^2 \\\\\n        N_2 & = 2u(1-u) \\\\\n        N_3 & = u^2\n    \\end{aligned}\n    \\end{equation}\n%\nWith the given targeted parabola as $y=ax^2+bx+c,x \\in [0,1]$, the generalized control points for the NURBS curve will be\n    \\begin{equation}\n        P= \\begin{bmatrix}\n            P_x \\\\\n            P_y\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 & m & 1 \\\\\n            c & n & a+b+c\n        \\end{bmatrix}\n    \\end{equation}\n%\nwhere $m$ and $n$ are unknowns for the second control point.\nB-spline curve $C=[N][P]$ then can be expressed as in parametric form as\n    \\begin{equation}\n        \\left\\{\n        \\begin{aligned}\n            x &= 2u(1-u)m + u^2 \\\\\n            y &= c(1-u)^2 + 2u(1-u)n + (a+b+c)u^2\n        \\end{aligned}\n        \\right.\n    \\label{iso_eq:parabola_fitting_parametric}\n    \\end{equation}\n%\nAfter substituting Eq.~\\ref{iso_eq:parabola_fitting_parametric} into $y=ax^2+bx+c$, we then have the system of equations as\n    \\begin{equation}\n        \\begin{bmatrix}\n            0 \\\\\n            0 \\\\\n            2c - 2n +a +b \\\\\n            2n - 2c \\\\\n            c\n        \\end{bmatrix} = \n        \\begin{bmatrix}\n            4am^2-4am+a \\\\\n            -8am^2 + 4am \\\\\n            4am^2 -2bm +b \\\\\n            2bm \\\\\n            c\n        \\end{bmatrix}\n    \\end{equation}\n%\n$m$ and $n$ then can be solved as\n    \\begin{equation}\n        \\left\\{\n        \\begin{aligned}\n            m &= \\frac{1}{2} \\\\\n            n &= \\frac{b+2c}{2}\n        \\end{aligned}\n        \\right.\n    \\end{equation}\n%\nThe numerical convergence of the relative error in the displacement norm and the relative error in the energy norm are shown in Fig.~\\ref{iso_fig:cantilever_beam_convergence} for various order of NURBS basis functions with refinement.\nFig.~\\ref{iso_fig:cantilever_beam_convergence} also shows the error in the displacement norm when quadratic Lagrange shape functions are used along each edge within the scaled boundary formulation.\nIt can be observed that NURBS basis functions yield superior accuracy when compared to Lagrange basis functions of the same order.\nIt is seen that as the order of the shape functions is increased, the error decreases while the convergence rate increases.\n\\begin{figure}\n    \\begin{subfigure}[b]{1\\linewidth}\n        \\centering\n        \\scalebox{0.7}{\n            \\input{isogeometric_sbfem/images/cantilever_beam_displacement_convergence.tikz}\n        }\n        \\label{iso_fig:cantilever_beam_displacement_convergence}\n        \\caption{the relative error in displacement norm $(L^2)$}\n    \\end{subfigure}\n    \n    \\begin{subfigure}[b]{1\\linewidth}\n        \\centering\n        \\scalebox{0.7}{\n            \\input{isogeometric_sbfem/images/cantilever_beam_energy_convergence.tikz}\n        }\n        \\label{iso_fig:cantilever_beam_energy_convergence}\n        \\caption{the relative error in the energy norm}\n    \\end{subfigure}\n\\caption{Bending of thick cantilever beam: Convergence results}\n\\label{iso_fig:cantilever_beam_convergence}\n\\end{figure}\n%\n", "meta": {"hexsha": "dd04c89c8053159e70b1958d0dafbbdc82311c85", "size": 6628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/ex_cantilever_beam.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_cantilever_beam.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_cantilever_beam.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": 40.1696969697, "max_line_length": 234, "alphanum_fraction": 0.5989740495, "num_tokens": 1925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6796413954279107}}
{"text": "\n\\subsection{Calculating \\(\\tau \\)}\n\nAs we note above, \\(\\sin (\\theta )=\\cos (\\theta )\\) at \\(\\theta =\\tau *\\dfrac{1}{8}\\)\n\nThis is also where \\(\\tan (\\theta )=1\\).\n\n\\(\\arctan (k)=\\arctan (a)+\\int_a^k\\dfrac{1}{1+y^2} \\delta y\\)\n\nWe start from \\(a=0\\).\n\n\\(\\arctan (k)=\\arctan (0)+\\int_0^k\\dfrac{1}{1+y^2} \\delta y\\)\n\nWe know that one of the results for \\(\\arctan (0)\\) is \\(0\\).\n\n\\(\\arctan (k)=\\int_0^k\\dfrac{1}{1+y^2} \\delta y\\)\n\nWe want \\(k=1\\)\n\n\\(\\arctan (1)=\\int_0^1\\dfrac{1}{1+y^2} \\delta y\\)\n\n\\(\\dfrac{\\tau }{8}=\\int_0^1\\dfrac{1}{1+y^2} \\delta y\\)\n\n\\(\\tau =8\\int_0^1\\dfrac{1}{1+y^2} \\delta y\\)\n\nWe know that the \\(\\cos (\\theta )\\) and \\(\\sin (\\theta )\\) functions cycle with period \\(\\tau \\).\n\nTherefore \\(cos (n.\\tau )=\\cos (0)\\)\n\n", "meta": {"hexsha": "da4fe5210b222f1281800e53761128a614f66c87", "size": 737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometryPi/01-04-trigTau.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/trigonometryPi/01-04-trigTau.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/trigonometryPi/01-04-trigTau.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.5666666667, "max_line_length": 97, "alphanum_fraction": 0.5603799186, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6796324889479535}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Bridge Crossings}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Bridge Crossings}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Bridge Crossings}\n\n\\begin{fullwidth}\n\n\\vspace{10 mm}\n\\begin{problem}\nFour people begin on the same side of a bridge. You must send them across to the other side in the fastest time possible. It is night. There is one flashlight. A maximum of two people can cross at a time. Any party who crosses, either one or two people, must have the flashlight to see. The flashlight must be walked back and forth, it cannot be thrown, etc. Each person walks at a different speed. A pair must walk together at the rate of the slower person's pace, based on this information: Person $1$ takes $t_1 = 1$ minutes to cross, and the other persons take $t_2 = 2$ minutes, $t_3 = 5$ minutes, and $t_4 = 10$ minutes to cross, respectively. \n\\end{problem}\n\n\\end{fullwidth}\n\nG\\\"unter Rote\\footnote{\\bibentry{Rote02}} gives a very elegant solution to this puzzle.\n\n\\subsection{How many ways are there to let $n$ people cross the bridge under the rules of the original puzzle ?}\n\nThere are $\\binom{n}{2}$ ways to send the first pair over to the other side, there are 2 ways to send the flashlight back with somebody from that side.  Now there are $\\binom{n -1}{2}$ ways to send the next pair over to the other side from the remaining $n - 1$ people on this side and then there are 3 ways to send the flashlight back with somebody from that side etc.\n \nUsing the basic product counting principle from combinatorics we get the number of ways $P$ to let $n$ people cross the bridge\n\n\\begin{equation}\n\\begin{aligned}\nP & = \\binom{n}{2} 2 \\binom{n - 1}{2} 3 \\binom{n - 2}{2} 4 \\dots (n - 1) \\binom{2}{2} \\\\\n    & = (n - 1) ! \\prod_{k = 0}^{n - 2} \\binom{n - k}{2}\n\\end{aligned}\n\\label{mainFormula}\n\\end{equation}\n\nTaking the product from (\\ref{mainFormula}) and using the definition of a binomial coefficient we get:\n\n\\begin{equation}\n \\prod_{k = 0}^{n - 2} \\binom{n - k}{2} =  \\prod_{k = 0}^{n - 2} \\frac{(n - k) !}{2 ! (n - k - 2)!}\n \\label{productPart}\n\\end{equation}\n\n\\noindent With:\n\n\\begin{equation}\n\\begin{aligned}\nP_k & = \\frac{(n - k) !}{2 ! (n - k - 2)!} \\quad \\text{and} \\\\\np_k & = (n - k) ! \n\\end{aligned}\n\\end{equation}\n\n\\noindent we get:\n\n\\begin{equation}\nP_k  = \\frac{p_k}{2 ! p_{k + 2}} \n\\end{equation}\n\n\\noindent The product of these $P_k$ can now be simplified to:\n\n\\begin{equation}\n\\begin{aligned}\n \\prod_{k = 0}^{n - 2} P_k & =  \\prod_{k = 0}^{n - 2} \\frac{(n - k) !}{2 ! (n - k - 2)!} \\\\\n                                              & = \\frac{1}{(2!)^{n - 1}} \\prod_{k = 0}^{n - 2} \\frac{p_k}{p_{k + 2}} \\\\\n                                              & = \\frac{1}{2^{n - 1}} \\frac{p_0}{p_2} \\frac{p_1}{p_3} \\frac{p_2}{p_4} \\dots \\frac{p_{n - 3}}{p_{n - 1}} \\frac{p_{n - 2}}{p_n} \\\\\n                                              & = \\frac{1}{2^{n - 1}} \\frac{p_0 p_1}{p_{n - 1} p_n} \\\\\n                                              & = \\frac{1}{2^{n - 1}}  n ! (n - 1) !\n\\end{aligned}\n \\label{simplifiedFormula}\n\\end{equation}\n\n\\noindent Using  (\\ref{simplifiedFormula}) we get the solution\n\n\\begin{equation}\nP = \\frac{n ! ((n - 1) !)^2}{2^{n - 1}} \n\\end{equation}\n\nFor four people this comes to an astonishing 108 ways to cross the bridge under the rules of the puzzle.\n\n\\subsection{Generating the ways}\n\nThis section shows a small Haskell program that generates all the possible ways to cross the bridge.  It has a helper function \\emph{pairs} that generates a list of all possible pairs from a set. It then defines two mutually recursive functions \\emph{bridgecrossleft} and \\emph{bridgecrossright} for crossing the bridge from the left side as pairs and for a flashlight carrier coming back from the right. The functions pass along the states on the left bank \\emph{lbs} and the right bank \\emph{rbs}.  They generate all possible crossings in their respective direction given the current state. For pairs crossing from the left tuples have the respective pair and for people coming back from the right tuples have the same person in both positions of the tuple. The functions collect the resulting combinations in a list of lists of tuples \\emph{rs} (Fig. \\ref{bridge_crossing_gen}). \\emph{bridgecross} is the main function taking a list and calling \\emph{bridgecrossleft} because we start on the left with all possible ways of crossing of the first pair. \n\n\\begin{marginfigure}\n\\includegraphics[width=3in]{fig.pdf}\n\\caption{Two mutually recursive functions \\emph{bridgecrossleft} and \\emph{bridgecrossright}.}\n\t\\label{bridge_crossing_gen}\n\\end{marginfigure}\n\nCalling \\emph{bridgecross [1, 2, 3]} we get this result:\n\n\\begin{lstlisting}\n[\n [(1,2),(1,1),(1,3)],\n [(1,2),(2,2),(2,3)],\n [(1,3),(1,1),(1,2)],\n [(1,3),(3,3),(3,2)],\n [(2,3),(2,2),(2,1)],\n [(2,3),(3,3),(3,1)]\n]\n\\end{lstlisting}\n\n\n\\newpage\n\n\\lstinputlisting[language=Haskell, basicstyle=\\small, frame=trBL, caption={Haskell code}]{bridge.hs}\n\n\\bibliographystyle{plainnat}\n\\bibliography{../common/math}\n\n\\end{document}\n", "meta": {"hexsha": "5a728c524190f980bf832fa8e3b0172e633d9e5a", "size": 5084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bridge/bridge.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": "bridge/bridge.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": "bridge/bridge.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.3928571429, "max_line_length": 1054, "alphanum_fraction": 0.6699449253, "num_tokens": 1583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.6795902629027948}}
{"text": "\\section{Green's Function}\r\n\\subsection{Physical Motivation}\r\nConsider the static force on a string which can be caused by gravity acting on the mass of the string.\r\nLet the tension be $T$ and linear mass density be $\\mu$.\r\nSuppose the string is suspended between fixed ends $y(0)=y(1)=0$.\r\nThe static force is then $-\\mu\\delta xg$ on the $y$ direction on the piece $\\delta x$.\r\nBy resolving forces, we get the equation $-y^{\\prime\\prime}=f(x)$ where $f(x)=-\\mu g/T$.\r\nWe can solve it via direct integration.\r\nFor uniform mass density (i.e. $\\mu$ is constant), we have\r\n$$-y=-\\frac{\\mu g}{2T}x^2+k_1x+k_2\\implies y(x)=\\left( -\\frac{\\mu g}{T} \\right)\\frac{1}{2}x(1-x)$$\r\nby the boundary conditions.\r\nThis is a parabolic curve.\r\n\\footnote{You might be expecting the catenary curve instead -- but not really, since in that problem we require the string to be non-elastic (i.e. has a fixed length) which makes it a completely different situation.}\r\nAnother way to solve this problem is to disassemble the force on the string as the sum of infinitesimal parts, and consider their superposition.\r\nAssume the string is massless but with a point mass $\\delta m$ suspended at $x=\\xi_i$.\r\nObviously the solution is simply two line segments meeting at some points $(\\xi_i,y_i)$.\r\nSuppose the segment closer to $0$ makes an angle $\\theta_1$ with the horizontal and the other segment makes an angle $\\theta_2$, then resolving in $y$-direction gives\r\n$$0=T(\\sin\\theta_1+\\sin\\theta_2)-\\delta mg=T\\left( \\frac{-y_i}{\\xi_i}+\\frac{-y_i}{1-\\xi_i}-\\delta mg \\right)$$\r\nSolving this gives us $y_i=-\\delta mg\\xi_i(1-\\xi_i)/T$.\r\nSo the solution is\r\n$$y_i(x)=\\frac{-\\delta mg}{T}\\begin{cases}\r\n    x(1-\\xi_i)\\text{, for $x<\\xi_i$}\\\\\r\n    \\xi(1-x)\\text{., for $x>\\xi_i$}\r\n\\end{cases}=f_iG(x,\\xi),f_i=\\frac{-\\delta mg}{T}$$\r\nwhere $f_i$ is interpreted as the source $f$ around a infinitesimal neighbourhood of $\\xi_i$.\r\nNow the superposition of the solution for $N$ point masses $\\delta m$ at $x=\\{\\xi_i\\}$ gives\r\n$$y(x)=\\sum_{i=1}^Nf_iG(x,\\xi_i)$$\r\nIf we take the continuum limit\r\n$$f_i=-\\frac{\\delta mg}{T}=-\\frac{\\mu\\delta x g}{T}=f(x)\\,\\mathrm dx$$\r\nwe have\r\n$$y(x)=\\int_0^1f(\\xi)G(x,\\xi)\\,\\mathrm d\\xi=\\left( -\\frac{\\mu g}{T} \\right)\\frac{1}{2}x(1-x)$$\r\n\\subsection{Definitions of Green's Function}\r\nWe wish to solve the inhomogeneous ODE $\\mathcal Ly=f(x)$ where $\\mathcal L=\\alpha y^{\\prime\\prime}+\\beta y^\\prime+\\gamma y$ on $[a,b]$ subject to boundary conditions $y(a)=y(b)=0$.\r\nWe require $\\alpha\\neq 0$ over $[a,b]$ and $\\alpha,\\beta,\\gamma$ all continuous and bounded.\r\n\\begin{definition}\r\n    The Green's function $G$ for the operator $\\mathcal L$ is the solution to $\\mathcal LG(x,\\xi)=\\delta(x-\\xi)$ subject to homogeneous boundary conditions $G(a,\\xi)=G(b,\\xi)=0$ for all $\\xi$.\r\n\\end{definition}\r\nSo by linearily, if such $G$ does exist, then we have\r\n$$y(x)=\\int_a^bG(x,\\xi)f(\\xi)\\,\\mathrm d\\xi$$\r\nIndeed,\r\n$$\\mathcal Ly=\\int_a^b\\mathcal LG(x,\\xi)f(\\xi)\\,\\mathrm d\\xi=\\int_a^b\\delta(x-\\xi)f(\\xi)\\,\\mathrm d\\xi=f(x)$$\r\nLoosely speaking, we can write $y=\\mathcal L^{-1}f$ where\r\n$$\\mathcal L^{-1}=\\int_a^b\\mathrm d\\xi\\, G(x,\\xi)$$\r\nNow, by our established study of these sort of ODEs, the Green's function splits into two smooth enough parts\r\n$$G(x,\\xi)=\\begin{cases}\r\n    G_1(x,\\xi)\\text{, for $x\\in [a,\\xi)$}\\\\\r\n    G_2(x,\\xi)\\text{, for $x\\in (\\xi,b)$}\r\n\\end{cases}$$\r\nsuch that the following conditions hold:\\\\\r\n1. $\\mathcal LG_1=\\mathcal LG_2=0$ at any $x\\neq\\xi$.\\\\\r\n2. $G_1(a,\\xi)=G_2(b,\\xi)=0$ for any $\\xi$.\\\\\r\n3. $G$ is continuous, so $G_1(\\xi,\\xi)=G_2(\\xi,\\xi)$.\\\\\r\n4. The jump condition of $G^\\prime$, that is\r\n$$[G^\\prime(\\cdot,\\xi)]^{\\xi_+}_{\\xi_-}=G_2^\\prime(\\xi_+,\\xi)-G_1^\\prime(\\xi_-,\\xi)=\\frac{1}{\\alpha(\\xi)}$$\r\nHow to construct $G$?\r\nNote that $\\mathcal L$ is a second order differential opertaor, so for $x\\in[a,\\xi)$, $G_1(x,\\xi)=A(\\xi)y_1(x)+B(\\xi)y_2(x)$ for linearly independent $y_1,y_2$.\r\nThe boundary condition $G_1(a,\\xi)=0$ gives $G_1(x,\\xi)=C(\\xi)y_-(x)$ where $y_-(a)=0$.\r\nSimilarly for $x\\in(\\xi,b]$ we have $G_2(x,\\xi)=D(\\xi)y_+(x)$ with $y_+(b)=0$.\r\nThen continuity condition gives $C(\\xi)y_-(\\xi)=D(\\xi)y_+(\\xi)$ and $D(\\xi)y_+^\\prime(\\xi_+)-C(\\xi)y_-^\\prime(\\xi_-)=\\alpha(\\xi)^{-1}$.\r\nIn other words we have the system\r\n$$\\begin{pmatrix}\r\n    y_-(\\xi)&y_+(\\xi)\\\\\r\n    -y_-^\\prime(\\xi_-)&y_+^\\prime(\\xi_+)\r\n\\end{pmatrix}\\begin{pmatrix}\r\n    C(\\xi)\\\\\r\n    D(\\xi)\r\n\\end{pmatrix}=\\begin{pmatrix}\r\n    0\\\\\r\n    1/\\alpha(\\xi)\r\n\\end{pmatrix}$$\r\nwhich has the solution (after extending everything continuously to $x=\\xi$)\r\n$$C(\\xi)=\\frac{y_+(\\xi)}{\\alpha(\\xi)W(\\xi)},D(\\xi)=\\frac{y_-(\\xi)}{\\alpha(\\xi)W(\\xi)}$$\r\nwhere $W(\\xi)=y_-(\\xi)y_+^\\prime(\\xi)-y_+(\\xi)y_-^\\prime(\\xi)$ is the Wronskian which is nonzero if $y_+,y_-$ are linearly independent.\r\nSo the final Green's function is\r\n$$G(x,\\xi)=\\begin{cases}\r\n    y_-(x)y_+(\\xi)/(\\alpha(\\xi)W(\\xi))\\text{, for $x\\in[a,\\xi]$}\\\\\r\n    y_+(x)y_-(\\xi)/(\\alpha(\\xi)W(\\xi))\\text{, for $x\\in[\\xi,b]$}\r\n\\end{cases}$$\r\nTherefore the solution to the original boundary value problem $\\mathcal Ly=f$ for $y=0$ at $a,b$ is\r\n\\begin{align*}\r\n    y(x)&=\\int_a^bG(x,\\xi)f(\\xi)\\,\\mathrm d\\xi\\\\\r\n    &=\\int_a^xG_2(x,\\xi)f(\\xi)\\,\\mathrm d\\xi+\\int_x^bG_1(x,\\xi)f(\\xi)\\,\\mathrm d\\xi\\\\\r\n    &=y_+(x)\\int_a^x\\frac{y_-(\\xi)f(\\xi)}{\\alpha(\\xi)W(\\xi)}\\,\\mathrm d\\xi+y_-(x)\\int_x^b\\frac{y_+(\\xi)f(\\xi)}{\\alpha(\\xi)W(\\xi)}\\,\\mathrm d\\xi\r\n\\end{align*}\r\n\\begin{note}\r\n    1. If $\\mathcal L$ is in Sturm-Liouville form, then $\\beta=\\alpha^\\prime$, then $\\alpha(\\xi)W(\\xi)$ is a constant and hence $G$ has to be symmetric.\\\\\r\n    2. Often we take $\\alpha=1$.\\\\\r\n    3. The indefinite integrals are the particular integrals in the particular integral in the Sturm-Liouville solution.\r\n\\end{note}\r\n\\begin{example}\r\n    For $y^{\\prime\\prime}-y=f(x),y(0)=y(1)=0$, the homogeneous solutions are $y_1=e^x$ and $y_2=e^{-x}$.\r\n    Imposing the homogeneous boundary conditions reveals that $y_-(x)=\\sinh(x)$ and $y_+(x)=\\sinh(1-x)$.\r\n    The countinuity condition of $G$ gives $C=D\\sinh(1-\\xi)/(\\sinh\\xi)$.\r\n    The jump condition of $G^\\prime$ then gives\r\n    $$D=-\\frac{\\sinh\\xi}{\\sinh 1},C=-\\frac{\\sinh(1-\\xi)}{\\sinh 1}$$\r\n    So\r\n    $$y(x)=-\\frac{\\sinh(1-x)}{\\sinh 1}\\int_0^x\\sinh(\\xi)f(\\xi)\\,\\mathrm d\\xi-\\frac{\\sinh x}{\\sinh 1}\\int_x^1\\sinh(1-\\xi)f(\\xi)\\,\\mathrm d\\xi$$\r\n\\end{example}\r\nFor inhomogenous boundary conditions, we simply need to find a solution to $\\mathcal Ly_p=0$ satisfying them and solve for $\\mathcal Ly_g=f$ under homogeneous boundary conditions by Green's functions.\r\nAdding them up gives the particular solution $y=y_p+y_g$.\r\n\\begin{example}\r\n    For $y^{\\prime\\prime}-y=f(x)$ with $y(0)=0,y(1)=1$, we have the solution $y_p(x)=\\sinh x/\\sinh 1$ to $y^{\\prime\\prime}-y=0$ under the same boundary conditions, so the particular solution would be\r\n    \\begin{align*}\r\n        y(x)&=y_p(x)+y_g(x)\\\\\r\n        &=\\frac{\\sinh x}{\\sinh 1}-\\frac{\\sinh(1-x)}{\\sinh 1}\\int_0^x\\sinh(\\xi)f(\\xi)\\,\\mathrm d\\xi-\\frac{\\sinh x}{\\sinh 1}\\int_x^1\\sinh(1-\\xi)f(\\xi)\\,\\mathrm d\\xi\r\n    \\end{align*}\r\n\\end{example}\r\nHow about high-order ODEs?\r\nSuppose we have $\\mathcal Ly=f(x)$ with the highest order term $\\alpha(x)y^{(n)}(x)$ in $\\mathcal Ly$ with $\\alpha\\neq 0$ everywhere, then $\\mathcal LG(x,\\xi)=\\delta(x-\\xi)$ has the properties:\\\\\r\n1. $G_1,G_2$ are solutions to $\\mathcal LG=0$.\\\\\r\n2. $G_1,G_2$ satisfy the homogeneous boundary conditions.\\\\\r\n3. Continuity condition of $G_1^{(i)}(\\xi,\\xi)=G_2^{(i)}(\\xi,\\xi)$ for all $i=1,\\ldots,n-2$.\\\\\r\n4. Jump condition of $[G^{(n-1)}(\\cdot,\\xi)]_{\\xi_-}^{\\xi_+}=G_2^{(n-1)}(\\xi_+,\\xi)-G_1^{(n-1)}(\\xi_-,\\xi)=1/\\alpha(\\xi)$.\\\\\r\nWe want to take a look at the eigenfunction expansion of $G$.\r\nSuppose $\\mathcal L$ is in Sturm-Liouville form with eigenfunctions $y_n(x)$ with eigenvalues $\\lambda_n$.\r\nWe seek an expansion\r\n$$G(x,xi)\\sum_{n=1}^\\infty A_n(\\xi)y_n(x)$$\r\nsatisfying $\\mathcal LG=\\delta(x-\\xi)$.\r\nNow suppose such an expansion exists, then\r\n\\begin{align*}\r\n    \\sum_{n=1}^\\infty A_n(\\xi)\\lambda_nw(x)y_n(x)&=\\sum_{n=1}^\\infty A_n(\\xi)\\mathcal Ly_n(x)=\\mathcal LG\\\\\r\n    &=\\delta(x-\\xi)=w(x)\\sum_{n=1}^\\infty y_n(\\xi)\\frac{y_n(x)}{N_n}\r\n\\end{align*}\r\nwhere $N_n=\\langle y_n,y_n\\rangle_w$ is the normalisation constant.\r\nConsequently $A_n(\\xi)=y_n(\\xi)/(\\lambda_nN_n)$, therefore\r\n$$G(x,\\xi)=\\sum_{n=1}^\\infty\\frac{y_n(\\xi)y_n(x)}{\\lambda_nN_n}=\\sum_{n=1}^\\infty\\frac{Y_n(\\xi)Y_n(x)}{\\lambda_n}$$\r\n\\subsection{Construction of Green's Function from Initial Values}\r\nWe want to solve $\\mathcal Ly(t)=f(t)$ for $t\\ge a$ with $y(a)=y^\\prime(a)=0$.\r\nThe Green's function then should satisfy $\\mathcal LG=\\delta(t-\\tau)$ with $G(a)=G^\\prime(a)=0$.\r\nFor $t<\\tau$, $G=G_1$ satisfies $\\mathcal LG_1=0$.\r\nSo $G_1=Ay_1+By_2$ for $A,B$ constants and $y_1,y_2$ linearly independent solutions to $\\mathcal Ly=0$.\r\nThe initial conditions then give\r\n$$\\begin{pmatrix}\r\n    y_1(a)&y_2(a)\\\\\r\n    y_1^\\prime(a)&y_2^\\prime(a)\r\n\\end{pmatrix}\\begin{pmatrix}\r\n    A\\\\\r\n    B\r\n\\end{pmatrix}=\\begin{pmatrix}\r\n    0\\\\\r\n    0\r\n\\end{pmatrix}$$\r\nBut $y_1,y_2$ are independent, so the Wronskian is nowhere zero, hence nonzero at $a$.\r\nTherefore necessarily $A=B=0$, so $G_1(t,\\tau)=0$ for $a\\le t<\\tau$.\\\\\r\nFor $t>\\tau$, we have $G=G_2$ for $\\mathcal LG_2=0$ and $G_2(\\tau,\\tau)=0$ by continuity.\r\nSo we can choose solution $y_+$ to $\\mathcal Ly=0$ such that $G_2(t,\\tau)=D(\\tau)y_+(t)$.\r\nBut we must have (extending everything continuously to $\\tau$)\r\n$$\\frac{1}{\\alpha(\\tau)}=G_2^\\prime(\\tau,\\tau)-G_1^\\prime(\\tau,\\tau)$$\r\nwhich gives $D(\\tau)=1/(\\alpha(\\tau)y_+^\\prime(\\tau))$, hence\r\n$$G(t,\\tau)=\\begin{cases}\r\n    0\\text{, for $t\\le\\tau$}\\\\\r\n    y_+(t)/(\\alpha(\\tau)y_+^\\prime(\\tau))\\text{, for $t\\ge\\tau$}\r\n\\end{cases}$$\r\nSo we get the solution\r\n$$y(t)=\\int_a^tG_2(t,\\tau)f(\\tau)\\,\\mathrm d\\tau=\\int_a^t\\frac{y_+(t)f(\\tau)}{\\alpha(\\tau)y_+^\\prime(\\tau)}\\,\\mathrm d\\tau$$\r\nwhich looks simpler as we built in the causality with the initial conditions.\r\n\\begin{example}\r\n    For $y^{\\prime\\prime}-y=f(t)$ with $y(0)=y^\\prime(0)=0$.\r\n    We then obtain $G_2(t,\\tau)=\\sinh(t-\\tau)$.\r\n    Therefore\r\n    $$y(t)=\\int_0^tf(\\tau)\\sinh(t-\\tau)\\,\\mathrm d\\tau$$\r\n\\end{example}", "meta": {"hexsha": "1255d4930d6cce808a9c12a7994533125c0ef633", "size": 10125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/green.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": "7/green.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": "7/green.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": 62.5, "max_line_length": 217, "alphanum_fraction": 0.6407901235, "num_tokens": 3783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.6795902558390023}}
{"text": "\n\\section{the Crossing tree} % (fold)\n\\label{sec:the_crossing_tree}\n\nBrief history in the literature. Cite the original papers \\cite{jones2004}\nand \\cite{jonesshen2005}.\n\n\\subsection{Definition} % (fold)\n\\label{sub:definition}\n\nConsider a path of real-valued continuous process $(X_t)_{t\\in T}$ on $T = [0,+\\infty)$.\nLet $(G_n)_{n\\geq0}$ be a collection of increasingly coarser uniformly spaced grids\non $\\Real$ centred at $x_0\\in \\Real$ given by $G_n = x_0 + \\delta 2^n \\mathbb{Z}$\nfor any $n\\geq 0$ and some base grid spacing $\\delta>0$.\\footnotemark\nEach element of this family of nested grids represents the ``resolution'' through\nwhich sample paths of $X_t$ are studied.\n\\footnotetext{ The addition $x_0+A$, for $A$ in an affine space such as $\\Real$\nrepresents shifting of every element of the set $A$ by a common value $x_0$.}\n\nAt the heart of the crossing tree lie crossing times of each particular grid $G_n$\nproperly aligned by $x_0$. The crossing times $T_k^n$ of process $X_t$ of grid $n\\geq 0$\nare its first passage times across a line of grid $G_n$ centred at $x_0$ that is\ndifferent from a previously crossed line of the same grid. Formally $T_k^n$ are\ndefined as follows: let $T_0^n=0$ and for $k\\geq 0$ put\n\\[\nT_{k+1}^n\n= \\inf \\Bigl\\{ t \\geq T^n_k : \\bigr | X(t) - X(T^n_k) \\bigr | \\geq \\delta 2^n \\Bigr\\}\n\\]\nThe forcing of the zero-th crossing time to $0$ automatically aligns the grid $G_n$\nwith the process, so in effect, without loss of generality one may consider processes\n$X_t$, which start at the origin $X(0) = 0$.\n\n%%%% Discuss subcrossings\n%%%% More or less relevant\nBy construction, for a binary crossing grid, $N^l_k$, the number of subcrossings in\nany complete crossing between $T^l_k$ and $T^l_{k+1}$ is always an even number. This\nis due to the fact, that each crossing is registered as soon as two unidirectional\nsubcrossings are encountered, as seen by the following.\n\nSuppose $T^{n+1}_k$ and $T^n_m$ are aligned so that $T^{n+1}_k=T^n_m$ and\n$T^{n+1}_{k+1}<+\\infty$, i.e. the $k$-th crossing of the $n+1$ grid is complete.\nFirst of all, $T^n_{m+1}, T^n_{m+2} \\leq T^{n+1}_{k+1}$, since otherwise the process\nwould have left the $\\pm \\delta 2^n$ band before it left the $\\pm \\delta 2^{n+1}$\nband, which is twice as wide.\n\nThe process is continuous at $T^n_{m+1}$ which means that almost surely for any\n$\\epsilon>0$ there is $\\eta>0$ such that for any $t$ with $\\bigl|t - T^n_{m+1}\\bigr| < \\eta$\nit holds that $\\bigl|X_{T^n_{m+1}} - X_t \\bigl| < \\epsilon$. Also for every $t \\in \\bigl[ T^n_k, T^n_{k+1} \\bigr)$\nit cannot be otherwise but $\\big | X_t - X_{T^n_k} \\big | < \\delta 2^n$.  In particular,\nfor $\\epsilon = \\frac{1}{2}\\delta 2^n$ it means that for a small while after $T^n_{m+1}$\nthe process is almost surely still within the $\\pm \\delta 2^{n+1}$ band. Therefore\n\\[ T^n_{m+1} < T^{n+1}_{k+1} \\]\nand a crossing of a finer grid occurs almost surely before the crossing of a coarser\ngrid. Thus it is true that \n\\[ 1 \\leq \\biggl| \\frac{1}{\\delta 2^n} \\bigl( X_{T^n_{m+1}} - X_{T^n_m} \\bigr) \\biggr| < 2 \\]\n\n\\noindent The next crossing of $\\pm\\delta 2^n$ takes place at $T^n_{m+2}$ and there\nare two possibilities:\n\\begin{enumerate}\n\t\\item the process crossed a new $\\pm\\delta 2^{n+1}$ line of $n+1$-st grid: \n\t\\[ \\big|X_{T^n_{m+2}} - X_{T^n_m}\\big|\\geq 2\\cdot\\delta 2^n\\] in which case\n\t$T^{n+1}_{k+1}\\leq T^n_{m+2}$ and there are \\emph{two} subcrosings in a crossing\n\tof grid $n+1$.\n\t\\item the process moved back to the level $X_{T^n_m}$, which does not incur a\n\tcrossing of $\\pm\\delta 2^{n+1}$ grid line, yet is registered by the $\\pm\\delta 2^n$\n\tgrid. In this case $T^n_{m+2} < T^{n+1}_{k+1}$ and $X_{T^n_{m+2}} = X_{T^{n+1}_{k+1}}$,\n\twhich brings one back to the beginning of this argument.\n\\end{enumerate}\n\nSince the crossing is complete, $T^{n+1}_{k+1} < +\\infty$ implies that sooner or later\na crossing of $\\pm\\delta 2^{n+1}$ grid occurs, in which case $T^{n+1}_{k+1} = T^n_{m+2p}$,\nmeaning that there were exactly $2p$ subcrossings in a crossing of grid $n+1$.\n\n%%%% Given this relationship between the crossing times of neighbouring grid\n%%%% contruct a crossing tree.\nThe exposed relationship between the crossing times enables a natural construction\nof a crossing tree: each crossing of grig $n$ is a child of a grander crossing of\ngrid $n+1$, during which it took place.\n\n%%%% Rewrite, as it is irrelevant\nThe parameter $\\delta$ is the spacing of the finest grid, with respect to which\nthe leaves of the crossing tree are computed. Parent nodes of these leaves represent\ncrossings of a coarser grid, namely $2\\delta$. The choice of $\\delta$ affects the tree\nin the following way in the case of a sampled process:\n\\begin{itemize}\n\t\\item the grid with too low a value of $\\delta$ would be crossed by straight\n\tline segments between each pair of consecutive sample observations. This could\n\tpoison the distribution with some unfavourable yet unknown mixture and leads\n\tto excessive number of seemingly meaningless crossings.\n\t\\item Too large $\\delta$ leads to a very poor and under sampled crossing tree.\n\\end{itemize}\n\n\n\n\n\\noindent \\textbf{A model of the offspring distribution} \\hfill \\\\\n\nLet's test the hypothesis that the number of subcrossings follows a distribution\nsimilar to geometric. Recall that $G$ is a geometrically distributed random variable,\n$G\\sim \\text{Geom}(\\theta)$, if $\\mathbb{P}(G=k) = {(1-\\theta)}^{k-1}\\theta$ for all\n$k\\geq1$. Other properties of geometrically distributed random variables include\n\\begin{itemize}\n\t\\item Complimentary CDF $\\mathbb{P}(G\\geq k) = (1-\\theta)^{k-1}$ for any $k\\geq1$;\n\t\\item Expectation $\\mathbb{E}(G) = \\theta^{-1}$;\n\t\\item Memorylessness: for $m\\geq 0$\n\t\\begin{align*}\n\t\t\\pr\\bigl( G \\geq n + m \\bigr\\rvert\\bigl. G \\geq n \\bigr)\n\t\t&= \\frac{\\pr(G \\geq n+m)}{\\pr(G \\geq n)} = \\frac{(1-\\theta)^{n+m-1}}{(1-\\theta)^{n-1}} \\\\\n\t\t& = (1-\\theta)^{m-1} = \\pr(G \\geq m)\n\t\\end{align*}\n\\end{itemize}\n\nThe number of offspring of any $\\delta 2^n$-grid crossing is the number of subcrossings\nof a finer grid with spacing $\\delta 2^{n-1}$ during a typical crossing.\n\nOur hypothesis is that $N$, the number of offspring, follows a geometric distribution\non the even numbers, i.e. $\\frac{1}{2}N \\sim \\text{Geom}(\\theta)$. To test it we\nutilize a truncated geometric distribution with a fixed threshold $\\bar{k}$, because\nthis approach naturally and easily handles unbounded random variables. Truncating the\ndata effectively means that two kinds of observations are registered:\n\\begin{itemize}\n\t\\item a value less than $\\bar{k}$;\n\t\\item an event $\\big\\{N\\geq \\bar{k}\\big\\}$, indicating that the value has not\n\tbeen less than $\\bar{k}$.\n\\end{itemize}\nBasically such truncated random variable behaves like a typical geometric one on\nthe values $\\bigl\\{ 2m \\bigr\\rvert \\bigl. 2m < \\bar{k}\\bigr\\}$, but happens to have\nan unusual concentration of probability at the upper truncation level $\\bar{k}$.\n\nTherefore for even integers $k=2,4,\\ldots\\bar{k}$ the distribution of the number\nof offspring is given by\n\\[\n\\mathbb{P}(N=k)\n= (1-\\theta)^{\\frac{k}{2}-1} \\theta 1_{k<\\bar{k}}\n+ (1-\\theta)^{\\frac{\\bar{k}}{2}-1} 1_{k = \\bar{k}}\n\\]\nwhere $1_{(\\cdot)}$ -- is the $0-1$ indicator.\n\n\\noindent \\textbf{Maximum Likelihood Estimation} \\hfill \\\\\nSuppose ${(g_i)}_{i=1}^N$ a sample of independent geometric random variables, with\ndistribution truncated by $\\bar{k}$. Due to truncation there is a finite number of\ndistinct values that are observed in any given sample. Therefore it is convenient to\nrepresent every sample in an equivalent value-frequency form: ${\\bigl(j, f_j\\bigr)}$\nfor even $j$ not greater than $\\bar{k}$ and \n$f_j = \\Bigl| \\bigl\\{ i\\bigr\\rvert \\bigl.g_i = j\\bigr\\}\\Bigr|$ -- the number of\nobservations with the specified value. Without the loss of generality, $f_j$ can\nbe set to zero for those $j$ that were not observed.\n\nThe log-likelihood function is given by\n\\[\n\\ln\\mathcal{L}\n= \\sum_{j\\neq \\bar{k}} f_j \\Bigl(\\frac{j}{2}-1\\Bigr) \\ln(1-\\theta)\n+ \\sum_{j\\neq \\bar{k}} f_j \\ln \\theta\n+ f_{\\bar{k}} \\Bigl( \\frac{\\bar{k}}{2} - 1 \\Bigr) \\ln(1-\\theta)\n\\]\nwhere the summation is done over the all possible distinct values. The first-order\ncondition on optimal $\\theta$ is given by\n\\[\n\\frac{d}{d \\theta} \\ln\\mathcal{L} \\,:\\quad\n-\\sum_j f_j \\Bigl(\\frac{j}{2}-1\\Bigr) \\frac{1}{1-\\theta} + \\sum_{j\\neq \\bar{k}} f_j \\frac{1}{\\theta} = 0\n\\]\nThis is equivalent to $\\frac{S-N}{1-\\theta} = \\frac{N-f_{\\bar{k}}}{\\theta}$, where\n$S = \\sum_j \\frac{j}{2} f_j$ and $N = \\sum_j f_j$ because the frequencies sum up to\nthe total number of observations. Therefore the desired ML estimator of the probability\nparameter $\\theta$ is\n\\[ \\hat{\\theta} = \\frac{N-f_{\\bar{k}}}{S-f_{\\bar{k}}} \\]\n\nI strongly suspect that the MLE of the truncated geometric distribution is biased. If so,\nthis renders it useless for Monte-Carlo estimation purposes. Clearly the bias should depend\non the truncation threshold, and $\\hat{\\theta}_T \\to \\hat{\\theta}$ as $T\\to \\infty$.\n\n%%%%%%%%%%%%\n\nsampled at times $(t_i)_{i=0}^N$ with $t_0=0$ and $t_i<t_{i+1}$.\n\nDenote a sample path of a real-valued continuous process by ${(t_i, x_i)}_{k=0}^N$\nanchored $X_0 = 0$ with $t_0 = 0$ and $X_i = X(t_i)$.\n\n% subsection definition (end)\n\n\\subsection{Practical construction} % (fold)\n\\label{sub:practical_construction}\n\n% subsection practical_construction (end)\n\n% section the_crossing_tree (end)\n\n\n\n\\section{Stochastic self-similarity} % (fold)\n\\label{sec:stochastic_self_similarity}\n\nThis section formally describes what an $H$-SSSI process is. For a broader, thorough\nand more exhaustive coverage of the topic the reader is encouraged to refer to\n\\cite{embrechtsselfsimilar}%pp. 1-3\nand \\cite{embrechts2000introduction}. %pp. 2-5, 19\n\n(Brief history) The notion of self-similarity has its roots in the works of Mandelbrot,\nand describes the phenomenon of scale-invariance observed in nature, seismology and\nfinance.\n\n\\subsection{Hurst self-similar stochastic processes with independent increments} % (fold)\n\\label{sub:hurst_self_similar_stochastic_processes_with_independent_increments}\n\nA stochastic process $\\bigl(X(t)\\bigr)_{t\\geq0}$ is called \\textbf{S}elf-\\textbf{S}imilar\nif for all $a>0$ there exists a constant $b>0$ such that\n\\[ X(at) \\overset{\\Dcal}{=} b X(t) \\]\nwhere $\\overset{\\Dcal}{=}$ is understood as the equality of all finite joint distributions.\n\nA stochastic process $\\bigl(X(t)\\bigr)_{t\\geq0}$ is called \\textbf{H}urst \\textbf{S}elf\n-\\textbf{S}imilar process, or $H$-SS, if for all $a>0$ and all $t\\geq 0$\n\\[ X(at) \\overset{\\Dcal}{=} a^H X(t) \\]\nor equivalently $X(t)\\overset{\\Dcal}{=} a^{-H} X(at)$ for all $t\\geq 0$ and $a>0$.\nFurthermore $H$-SS condition implies $ X(t) \\overset{\\Dcal}{=} t^H X(1) $.\n\nAn $H$-SS process is a special case of an SS process, in that it must necessarily\nhave $X(0) = 0$ almost surely and must be stochastically continuous. A process\n$\\bigl(X(t)\\bigr)_{t\\geq0}$ is stochastically continuous at $t\\geq 0$ if $X(t+h) = X(t) + o_p(h)$:\nfor any $\\epsilon>0$\n\\[\n\\lim_{h\\to 0} \\pr\\Bigl( \\bigl\\lvert X(t+h) - X(t)\\bigr\\rvert > \\epsilon \\Bigr) = 0\n\\]\nFor example, one can say that an $H$-self-similar process is stochastically continuous at $0$.\n\nIndeed, for any $t>0$, $\\epsilon>0$ and any sequence $\\Delta_n\\to 0$ as $n\\to \\infty$\none has the following chain reasoning: $H$-self-similarity of $X(t)$ implies that\nthe random variable $\\lvert X(t) - X(t+h_n) \\rvert$ has the same distribution as\n$|X(1)|\\bigl\\lvert t^H - (t+h_n)^H \\bigr\\rvert$, whence\n\nis equivalent to $\\lvert X(t) - X(t+h_n) \\rvert > \\epsilon$\n\\begin{enumerate}\n\t\\item \n\\end{enumerate}\n\nIndeed, for any $\\epsilon>0$ $H$-self-similarity\nimplies that $\\pr\\bigl( |X(0)|>\\epsilon \\bigr) = \\pr\\bigl( a^{-H} |X(0)|>\\epsilon \\bigr)$\nwhence for any $n\\geq 0$\n\\[\n\\pr\\bigl( |X(0)|>\\epsilon \\bigr) = \\pr\\bigl( |X(0)| > a^{nH} \\epsilon \\bigr)\n\\]\nSince the events $\\Bigl\\{|X(0)| > a^{nH} \\epsilon\\Bigr\\}$ decrease monotonically\ntoward $\\emptyset$, it is therefore true that $\\pr\\bigl( |X(0)|>\\epsilon \\bigr) \\downarrow 0$\nby monotonicity of probability measure $\\pr$.\n\n\nA stochastic process $\\bigl(X(t)\\bigr)_{t\\geq0}$ is said to have \\textbf{s}tationary\n\\textbf{i}ncrements if any finite-dimensional joint distribution of the increments of\n$X(t)$ defined as $U_s(t) = X(t+s)-X(t)$ is independent of $s\\geq0$, i.e. invariant\nunder time shifts. (\\textbf{CHECK THIS!})\n\nThe subject of this study, the $H$-SSSI process is a Hurst self-similar process\n$\\bigl(X(t)\\bigr)_{t\\geq0}$ with stationary increments.\n\n\n\nFor an $H$-self-similar process $\\bigl(X(t)\\bigr)_{t\\geq 0}$ it must necessarily\nbe true that $X(0) = 0$ almost surely. Hence $X(0) = 0$ almost surely.\n\n\nA random variable $Z$ is non-trivial if $\\pr(|Z| > 0 ) > 0$ and a process $\\bigl(X(t)\\bigr)_{t\\geq0}$\nis non-trivial if there exists $t\\geq 0$ such that the random variable $X(t)$ is non-trivial.\n\nConsider some non-trivial random variable $Z$ in $\\Real^d$. Suppose that for some\n$b_1,b_2>0$ it is true that $b_1 Z\\overset{\\Dcal}{\\sim} b_2 Z$. Then for any $\\epsilon>0$:\n\\[\n\\pr\\bigl( |Z| > \\epsilon \\bigr)\n= \\pr\\bigl( b_1 |Z| > b_1 \\epsilon \\bigr)\n= \\Bigl[ b_1 Z\\overset{\\Dcal}{\\sim} b_2 Z \\Bigr]\n= \\pr\\bigl( b_2 |Z| > b_1 \\epsilon \\bigr)\n\\]\nfrom which it follows that for all $n\\geq 0$\n\\[\n\\pr\\bigl( |Z| > \\epsilon \\bigr) = \\pr\\biggl( |Z| > \\frac{b_1^n}{b_2^n} \\epsilon \\biggr)\n\\]\nSince $b_1>b_2$, the family of events $A_n = \\bigl\\{ |Z| > \\sfrac{b_1^n}{b_2^n} \\epsilon \\bigr\\}$\nis nested $A_{n+1}\\subseteq A_n$ and $A_n \\downarrow \\emptyset$, which implies that\n$\\pr(A_n) \\downarrow 0$. Therefore $\\pr(|Z|> \\epsilon) = 0$ for all $\\epsilon>0$,\ncontradicting the non-triviality of $Z$. Therefore for a non-trivial random variable\n$Z$ if $b_1,b_2>0$ are such that $b_1 Z\\overset{\\Dcal}{\\sim} b_2 Z$ then $b_1 = b_2$.\n\nNow suppose a process $\\bigl(X(t)\\bigr)_{t\\geq0}$ is non-trivial, stochastically\ncontinuous at $t=0$ and self-similar. Then there is $H>0$ such that \n\n\\[ \\ldots \\]\n\n% subsection hurst_self_similar_stochastic_processes_with_independent_increments (end)\n\n\\subsection{Examples of scale invariant processes} % (fold)\n\\label{sub:examples_of_scale_invariant_processes}\n\n\n\n\\subsubsection{FBM} % (fold)\n\\label{ssub:fbm}\n\nOne of the most prominent example of an $H$-SSSI process is the Brownian Motion\ndefined as follows:\n\n-\nA stationary \\textbf{f}ractional \\textbf{G}aussian \\textbf{N}oise is a sequence\nof random variables $(\\xi_0)_{n\\geq1}$ such that each $\\xi_n$ is identically $\\Ncal(0,\\sigma^2)$\ndistributed, but the autocorrelation function is\n\\[\n\\ex\\Bigl( \\xi_0 \\xi_n\\Bigr) = \\frac{\\sigma^2}{2} \\Bigl( |n+1|^{2H} - 2|n|^{2H} + |n-1|^{2H} \\Bigr)\n\\]\nUsually the fGN is defined through first differences of a fractional Brownian motion.\n\nThe most prominent example of an $H$\\textbf{-SS} process is the famous Brownian Motion.\n\n\n\nFor BM and FBM refer to \\cite{embrechtsselfsimilar} pp. 4-5 and \\cite{embrechts2000introduction} pp. 5-8\n\nIn fact, fractional Brownian motion is an example of a broader class of self-similar processes known as\nthe \\textbf{Hermite} processes.\n\nA fractional Browninan Motion with can be written in the stochastic integral form\n\\[ B^H(t) = \\int_0^t K^H(t,s) dW_s \\]\nwhere $(W_s)_{s\\in[0,1]}$ is a standard Wiener process on $[0,1]$, $K^H(t,s)$\n-- is the integral kernel given for $t>s$ by\n\\[\nK^H(t,s)\n= \\bigl( \\tfrac{ H(2H-1) }{\\beta(2-2H, H-\\tfrac{1}{2})} \\bigr)^{\\tfrac{1}{2}}\n\\cdot s^{\\frac{1}{2}-H} \\int_s^t (u-s)^{H-\\frac{1}{2}}u^{H-\\frac{1}{2}}du \\]\nwith $\\beta(,\\cdot, \\cdot)$ being the Beta function (see \\cite{Chronopoulou:1114288}).\n\n% subsubsection fbm (end)\n\n\\subsubsection{Hermite} % (fold)\n\\label{ssub:hermite}\n\nHermite processes inherit their name from the stochastic integral kernel used\nin their definition.\n\nA probabilistic Hermite polynomial of order $k\\geq0$ is defined as \n\\[ H_k(x) = (-1)^k e^{-\\frac{x^2}{2}} \\frac{d^k}{dx^k} e^{-\\frac{x^2}{2}} \\]\nand is a solution to the following differential equation\n\\[\n \\frac{d}{dx}\\biggl( e^{-\\frac{x^2}{2}} \\frac{d}{dx} f\\biggr) + \\lambda e^{-\\frac{x^2}{2}} f = 0\n\\]\nThese polynomials constitute an orthogonal basis of the Hilbert space $\\Lcal^2(\\Real, \\mu)$\nwith measure $\\mu$ being the Lebesgue integral $\\int e^{-\\frac{x^2}{2}} dx$ and the inner\nproduct given by\n\\[\n\\langle f, g\\rangle = \\int_\\Real f g d\\mu = \\int_\\Real f g e^{-\\frac{x^2}{2}} dx\n\\]\n\nAs opposed to the case of fBM, a Hermite process is defined though stochastic\nintegral of a special kernel. The Hermite process of order $m$ with self-similarity\nparameter $H\\in(\\tfrac{1}{2},1)$, denoted by $(Z^{mH}(t))_{t\\in[0,1]}$, is defined as \n\\[\nZ^{mH}(t) = \\underset{\\Real^m}{\\int \\cdots \\int} \\Biggl(\n\\int^t_0 \\prod_{k=1}^m (u-x_k)_+^{-\\frac{1}{2}-\\frac{1-H}{m}} du\\Biggr) dW(x_1) \\ldots dW(x_q)\n\\]\nThe Hermite process of order $1$ is fractional Brownian Motion, whereas higher order\nHermite processes correspond to higher order Wiener-chaos (\\cite{Bai20141710})\n\n\\noindent\\textbf{CHECK THIS}.\nThe fundamental theorem of Lamperti (\\cite{lamperti}) states that $H$-sssi process\nis the only limiting law of normalized partial sum of a stationary sequence.\nFormally, if $(X_i)_{i\\geq1}$ is stationary and for some $a_n\\to \\infty$\n\\[ \\frac{1}{a_n} \\sum_{i=1}^{[nt]} X_i \\overset{\\Dcal}{\\rightarrow} y(t) \\]\nwhere convergence is in all finite-dimensional distributions, then the process\nthen there  exists $H>0$ such that $(Y_t)_{t\\geq0}$ is $H$-SSSI and $a_n$ is regularly\nvarying with exponent $H$.\n\nFor example, if $(X_i)_{i\\geq 1}$ is an iid sequence, or a \\textbf{s}hort-\\textbf{r}ange\n\\textbf{d}ependent, then the limit of normed partial sums is the Brownian Motion,\nwhich is $\\frac{1}{2}$-SSSI. In case if the stationary sequence $X_i$ is \\textbf{l}ong-\n\\textbf{r}ange \\textbf{d}ependent, the limit $Y(t)$ is often $H$-SSSI with $H>\\frac{1}{2}$.\n\n\n\nConsider a $(\\xi_i)_{i\\geq1}$ is a stationary fractional Gaussian Noise with\nautocorrelation $r_n = L(n) n^{2\\frac{H-1}{m}}$ for some slowly varying function $L(n)$.\n\nIt is known (non central limit theorem?) that if $H_m$ is a Hermite polynomial of\norder $m$, then for all $t\\in [0,1]$ \n\\[ n^{-H} \\sum_{i=1}^{[nt]} H_m(\\xi_i) \\overset{\\Dcal}{\\rightarrow} Z^{mH}(t) \\]\n\nThe construction of a Hermite process begins with a stationary Gaussian noise.\n\nA \\textbf{Hermite} process borrows it name from the \n\n% subsubsection hermite (end)\n\n\\subsubsection{Weierstrass} % (fold)\n\\label{ssub:weierstrass}\n\n% subsubsection weierstrass (end)\n\n% subsection examples_of_scale_invariant_processes (end)\n\n% section stochastic_self_similarity (end)\n\n\\section{Fractional Brownian Motion} % (fold)\n\\label{sec:fractional_brownian_motion}\n\n\\subsection{Definiton} % (fold)\n\\label{sub:definiton}\nBrief history, relation to H-SSSI processes.\n\nMention that BM is fBM for $H=0.5$.\n\n\\subsubsection{Sample paths} % (fold)\n\\label{ssub:sample_paths}\n\nReference the generation circulant embedding generation algorithm with complexity.\n\n% subsubsection sample_paths (end)\n\n% subsection definiton (end)\n\n% section fractional_brownian_motion (end)\n\n\\section{Brownian Motion} % (fold)\n\\label{sec:brownian_motion}\n\n\\section{Literature review} % (fold)\n\\label{sec:literature_review}\nReviewed papers \\cite{jones2004}, \\cite{jonesshen2005} and \\cite{decrouez2013}.\n\n% section literature_review (end)\n\n\\subsection{Properties of the crossing tree} % (fold)\n\\label{sub:properties_of_the_crossing_tree}\n\n% subsection properties_of_the_crossing_tree (end)\n\n\\subsection{Simulation study} % (fold)\n\\label{sub:simulation_study_bm}\n\n% subsection simulation_study_bm (end)\n\n% section brownian_motion (end)\n\n\\section{Conjecture for FBM with $H\\in (\\sfrac{1}{2},1)$} % (fold)\n\\label{sec:conjecture_for_fbm}\n\n\\subsection{Statement} % (fold)\n\\label{sub:statement}\n\n% subsection statement (end)\n\n\\subsection{Simulation study} % (fold)\n\\label{sub:simulation_study_fbm}\n\nSee the paper by Owen Jones and Shen (2005) for the outline.\n\nEach MonteCarlo realisation generates a discretized sample path $(t_i, X_i)_{i=0}^N$ of\na particular continuous stochastc process $X(t)$, where $X_i = X(t_i)$ and $(t_i)_{i=0}^N\\in [0,1]$\nis a uniformly spaced mesh with\n\\[0 = t_0 \\geq \\ldots \\geq t_i < t_{i+1} \\geq \\ldots \\geq t_N = 1\\]\n\nMain plots: let $\\Delta X_i = X_i - X_{i-1}$ for $i=1,\\ldots, N$.\n\\begin{itemize}\n\t\\item for $\\delta = \\text{std}\\bigl(\\Delta X_i \\bigr)$, where $\\text{std}(Y^n)$ is\n\tthe square root of the unbiased sample estimator of varaince of $Y$:\n\t\\[ \\text{std}(Y^n) = \\sqrt{ \\frac{1}{n-1} \\sum_{i=1}^n \\bigl( Y_i - \\bar{Y}_n \\bigr)^2 }\\]\n\tand $\\bar{Y}_n$ is tha sample mean: $\\bar{Y}_n = \\frac{1}{n}\\sum_{i=1}^n Y_i$. \n\n\t\\item for $\\delta = \\text{iqr}\\bigl(\\Delta X_i \\bigr)$, where $\\text{iqr}(Y^n)$ is\n\tthe \\textbf{i}nter\\textbf{q}uartile \\textbf{r}ange of the sample $Y^n = (Y_i)_{i=1}^n$\n\tdefiend as the difference of the $75\\%$ and the $25\\%$ sample quartiles of the sample:\n\t\\[\\text{iqr} = \\hat{F}^{-1}_n\\Bigl(\\frac{3}{4}\\Bigr) - \\hat{F}^{-1}_n\\Bigl(\\frac{1}{4}\\Bigr)\\]\n\twhere $\\hat{F}^{-1}_n(p)$ is the generalized inverse of the empirical CDF of the sample $Y^n$\n\tgiven by\n\t\\[\\hat{F}_n(y) = \\frac{1}{n} \\sum_{i=1}^n 1_{(-\\infty,y]}(Y_i)\\]\n\tRatinale for the IQR is that it is robust (this is poor!).\n\t\\item for $\\delta = \\hat{F}^{-1}_n\\Bigl(\\frac{3}{4}\\Bigr)$ -- the $75\\%$ empirical qauntile of\n\tthe process of increments $(\\Delta_i)_{i=1}^N$.\n\\end{itemize}\n\nEach group of plots should have: \\begin{itemize}\n\t\\item a plot of subcrossing distribution averaged across the MC realisations with\n\tthe theoretical values;\n\t\\item add histograms of $\\pr(Z_n = 2k)$ (separately for $k=1,2,\\ldots$) with\n\tsuperimposed theoretical $\\theta = 2^{1-H^{-1}}$ and averaged values;\n\t$Z\\sim\\text{Geom}$ with porbability given by\n\t\\[\\pr(Z = 2k) = (1-\\theta)^{k-1} \\theta\\]\n\tfor $k\\geq 1$.\n\t\\item a table of excursion distribution averaged across the MC realisations;\n\t\\item add histograms of $\\pr(+-|++)$ and $\\pr(+-|--)$ with superimposed theoretical\n\tand averaged values. Let $\\mu = \\ex Z$, which is $\\frac{2}{\\theta}$. Then the\n\thypothesized probability of an up-down excursion $\\delta 2^n$ in an upcrossing\n\tof resolution $\\delta 2^{n+1}$ is $\\frac{1}{\\sqrt{\\mu}}$.\n\\end{itemize}\n\n% subsection simulation_study_fbm (end)\n\n", "meta": {"hexsha": "e1291b474ffc2273d219f596c8a3efec9a7f6700", "size": 22089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/drafts/drafts.tex", "max_stars_repo_name": "ivannz/crossing_paper2017", "max_stars_repo_head_hexsha": "a33c826b966d0238b96156ec19f462d2f9ed7906", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-25T21:37:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-25T21:37:23.000Z", "max_issues_repo_path": "paper/drafts/drafts.tex", "max_issues_repo_name": "ivannz/crossing_paper2017", "max_issues_repo_head_hexsha": "a33c826b966d0238b96156ec19f462d2f9ed7906", "max_issues_repo_licenses": ["MIT"], "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/drafts/drafts.tex", "max_forks_repo_name": "ivannz/crossing_paper2017", "max_forks_repo_head_hexsha": "a33c826b966d0238b96156ec19f462d2f9ed7906", "max_forks_repo_licenses": ["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.9877800407, "max_line_length": 114, "alphanum_fraction": 0.6993978904, "num_tokens": 7533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936435, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6795213437045394}}
{"text": "\r\n\\textit{Calculus} means ``a method of calculation or reasoning.'' When one computes the sales tax on a purchase, one employs a simple calculus. When one finds the area of a polygonal shape by breaking it up into a set of triangles, one is using another calculus. Proving a theorem in geometry employs yet another calculus.\r\n\r\nDespite the wonderful advances in mathematics that had taken place into the first half of the $17^\\text{th}$ century, mathematicians and scientists were keenly aware of what they \\textit{could not do.} (This is true even today.) In particular, two important concepts eluded mastery by the great thinkers of that time: area and rates of change. \r\n\r\nArea seems innocuous enough; areas of circles, rectangles, parallelograms, etc., are standard topics of study for students today just as they were then. However, the areas of \\textit{arbitrary} shapes could not be computed, even if the boundary of the shape could be described exactly. \r\n\r\nRates of change were also important. When an object moves at a constant rate of change, then ``distance = rate $\\times $ time.'' But what if the rate is not constant -- can distance still be computed? Or, if distance is known, can we discover the rate of change?\r\n\r\nIt turns out that these two concepts were related. Two mathematicians, Sir Isaac Newton and Gottfried Leibniz, are credited with independently formulating a system of computing that solved the above problems and showed how they were connected. Their system of reasoning was ``a'' calculus. However, as the power and importance of their discovery took hold, it became known to many as ``the'' calculus. Today, we generally shorten this to discuss ``calculus.''\r\n\r\nThe foundation of ``the calculus'' is the \\textit{limit.} It is a tool to describe a particular behavior of a function. This chapter begins our study of the limit by approximating its value graphically and numerically. After a formal definition of the limit, properties are established that make ``finding limits'' tractable. Once the limit is understood, then the problems of area and rates of change can be approached.\r\n\r\n\\section{The tangent problem}\\label{sec:TangentProblem} %\r\nConsider the computer- generated plot of the function $f(x)=\\frac{x^2}2$ below. The line drawn in blue in Figure \\ref{figTangentIdeaFor} appears to just touch the graph of the function $y=\\frac{x^2}2$ at the point $P=(2,f(2))=(2, \\frac{2^2}{2}) =(2,2)$. In mathematical language we say that the blue line is tangent to the graph of $ y=\\frac{x^2}2$ (``tangent'' comes from Latin, ``to touch''). We shall give a formal definition of a tangent line later in Section \\ref{secDefTangent}; until then, we shall refer to a ``tangent line'' informally, relying on the reader's intuition.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[ %\r\n     clip=false, \r\n     %minor x tick num=1,\r\n     axis y line=middle,\r\n     axis x line=middle,\r\n     ymin=-1,\r\n     ymax=5,\r\n     %extra y tick labels={},\r\n     xmin=-1,\r\n     xmax=3.5,\r\n     name=myplot]\r\n     \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n     \\addplot [{\\colorone},thick, smooth,domain=0.5:3,samples=20] ({x},{2*x-2});\r\n     \\coordinate (P) at (axis cs:2,2);\r\n     %\\coordinate (Q) at (axis cs:1.9,1.805);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) { $x$};\r\n     \\node [above] at (myplot.above origin) { $f$};\r\n     %\\draw [color=red, thick, shorten >= -1.9cm, shorten <=-1.9cm] (P)--(Q);\r\n     \\draw[color=\\colorone,fill] (P) circle (0.1) node[above] {\\scriptsize $P$} node[right] {\\scriptsize $(2,2)$};\r\n    % \\draw[color=red,fill] (Q) circle (0.1)node[above] {\\scriptsize $Q$} node[right] {\\scriptsize $(1.9,1.805)$};     \r\n     \\end{tikzpicture} \r\n    \\caption{   \\label{figTangentIdeaFor} }\r\n\\end{figure}\r\n\r\n\r\nWe are seeking an equation for the tangent through $P=(2,2)=(2, f(2))$ drawn in \\ref{figTangentIdeaFor}. We know one point on the tangent line - namely the point $P=(2,2)$. Recall that every non-vertical line has equation\r\n\\[\r\ny=mx+c\r\n\\]\r\nfor some numbers $m$ and $c$, where $m$ is called the slope\r\nof the line and $c$ is called the $y$-intercept of the line. As the tangent line passes through the point $P=(2,2)$, it has equation $y-2=m(x-2)$ for some slope $m$ that we yet need to define.\r\n\r\nIt is natural to approximate the tangent line using secant lines passing through the point $ P=(2, 2)$ and nearby points $Q=(t,f(t))=(t, \\frac{t^2}{2})$ lying on the graph of $f(x)$. The line passing through $P=(2,2) $ and $Q=(t,f(t))$ has slope $m_{PQ}:=\\frac{f(t)-2}{t-2}$ and therefore has equation\r\n\\[\r\ny-2=m_{PQ}(x-2), \\quad\\quad \\quad\\text{where~} m_{PQ}= \\left(\\frac{f(t)-2}{t-2}\\right).\r\n\\]\r\nAs the equation of the tangent line is $y-2=m(x-2)$, we choose to approximate $m$ by the numbers $m_{PQ}$ as $Q$ gets close to the point $P$. On the other hand, the point $Q=(t,f(t))$ gets closer to $P= (x, f(x))$ as $t$ gets closer to $x$.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.33\\textwidth}\r\n\t\t \\begin{tikzpicture}\r\n\t\t \\begin{axis}[ %\r\n\t\t width=1.1\\textwidth,\r\n\t\t clip=false, \r\n\t\t %minor x tick num=1,\r\n\t\t axis y line=middle,\r\n\t\t axis x line=middle,\r\n\t\t ymin=-1,\r\n\t\t ymax=5,\r\n\t\t %extra y tick labels={},\r\n\t\t xmin=-1,\r\n\t\t xmax=3.5,\r\n\t\t name=myplot]\r\n\t\t \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n\t\t \\coordinate (P) at (axis cs:2,2);\r\n\t\t \\coordinate (Q) at (axis cs:1,0.5);\r\n\t\t \\end{axis}\r\n\t\t \\node [right] at (myplot.right of origin) { $x$};\r\n\t\t \\node [above] at (myplot.above origin) { $f$};\r\n\t\t \\draw [color=\\colorone, thick, shorten >= -1cm, shorten <=-1cm] (P)--(Q);\r\n\t\t \\draw[color=\\colorone,fill] (P) circle (0.1) node[above] {\\scriptsize $P$} node[right] {\\scriptsize $(2,2)$};\r\n\t\t \\draw[color=\\colorone,fill] (Q) circle (0.1)node[above] {\\scriptsize $Q$} node[right] {\\scriptsize $(1,1.5)$};\r\n\t\t \\end{tikzpicture}\r\n        \\label{ }\r\n        \\caption{$ t=1 $, $ m_{PQ}=1.5 $} \r\n    \\end{subfigure}% \r\n \\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[ %\r\n      width=1.1\\textwidth,\r\n     clip=false, \r\n     %minor x tick num=1,\r\n     axis y line=middle,\r\n     axis x line=middle,\r\n     ymin=-1,\r\n     ymax=5,\r\n     %extra y tick labels={},\r\n     xmin=-1,\r\n     xmax=3.5,\r\n     name=myplot]\r\n     \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n     \\coordinate (P) at (axis cs:2,2);\r\n     \\coordinate (Q) at (axis cs:1.5,1.125);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) { $x$};\r\n     \\node [above] at (myplot.above origin) { $f$};\r\n     \\draw [color=\\colorone, thick, shorten >= -1.5cm, shorten <=-1.5cm] (P)--(Q);\r\n      \\draw[color=\\colorone,fill] (P) circle (0.1) node[left] {\\scriptsize $P$} node[right] {\\scriptsize $(2,2)$};\r\n      \\draw[color=\\colorone,fill] (Q) circle (0.1)node[left] {\\scriptsize $Q$} node[right] {\\scriptsize $(1.5,1.125)$};\r\n     \\end{tikzpicture} %\r\n        \\label{ }\r\n        \\caption{$ t=1.5 $, $ m_{PQ}=1.75 $} \r\n    \\end{subfigure}\r\n \\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[ %\r\n      width=1.1\\textwidth,\r\n     clip=false, \r\n     %minor x tick num=1,\r\n     axis y line=middle,\r\n     axis x line=middle,\r\n     ymin=-1,\r\n     ymax=5,\r\n     %extra y tick labels={},\r\n     xmin=-1,\r\n     xmax=3.5,\r\n     name=myplot]\r\n     \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n     \\coordinate (P) at (axis cs:2,2);\r\n     \\coordinate (Q) at (axis cs:1.9,1.805);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) { $x$};\r\n     \\node [above] at (myplot.above origin) { $f$};\r\n     \\draw [color=\\colorone, thick, shorten >= -1.9cm, shorten <=-1.9cm] (P)--(Q);\r\n     \t\t \\draw[color=\\colorone,fill] (P) circle (0.1) node[above] {\\scriptsize $P$} node[right] {\\scriptsize $(2,2)$};\r\n     \t\t \\draw[color=\\colorone,fill] (Q) circle (0.1)node[left] {\\scriptsize $Q$} node[below right] {\\scriptsize $(1.9,1.805)$};     \r\n     \\end{tikzpicture}\r\n        \\label{ }\r\n      \\caption{$ t=1.9 $, $ m_{PQ}=1.95 $}  \r\n    \\end{subfigure} \r\n    \\caption{ Slopes of secant lines as $ Q $ approaches $ P $ from the left.  \\label{tangentleft} }\r\n\\end{figure}\r\n\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.33\\textwidth}\r\n\t\t \\begin{tikzpicture}\r\n\t\t \\begin{axis}[ %\r\n\t\t width=1.1\\textwidth,\r\n\t\t clip=false, \r\n\t\t %minor x tick num=1,\r\n\t\t axis y line=middle,\r\n\t\t axis x line=middle,\r\n\t\t ymin=-1,\r\n\t\t ymax=5,\r\n\t\t %extra y tick labels={},\r\n\t\t xmin=-1,\r\n\t\t xmax=3.5,\r\n\t\t name=myplot]\r\n\t\t \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n\t\t \\coordinate (P) at (axis cs:2,2);\r\n\t\t \\coordinate (Q) at (axis cs:3,4.5);\r\n\t\t \\end{axis}\r\n\t\t \\node [right] at (myplot.right of origin) { $x$};\r\n\t\t \\node [above] at (myplot.above origin) { $f$};\r\n\t\t \\draw [color=\\colorone, thick, shorten >= -1cm, shorten <=-1cm] (P)--(Q);\r\n\t\t \\draw[color=\\colorone,fill] (P) circle (0.1) node[left] {\\scriptsize $P$} node[below right] {\\scriptsize $(2,2)$};\r\n\t\t \\draw[color=\\colorone,fill] (Q) circle (0.1)node[above left] {\\scriptsize $Q$} node[right] {\\scriptsize $(3,4.5)$};\r\n\t\t \\end{tikzpicture}\r\n        \\label{ }\r\n        \\caption{$ t=3 $, $ m_{PQ}=2.5 $} \r\n    \\end{subfigure}% \r\n \\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[ %\r\n      width=1.1\\textwidth,\r\n     clip=false, \r\n     %minor x tick num=1,\r\n     axis y line=middle,\r\n     axis x line=middle,\r\n     ymin=-1,\r\n     ymax=5,\r\n     %extra y tick labels={},\r\n     xmin=-1,\r\n     xmax=3.5,\r\n     name=myplot]\r\n     \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n     \\coordinate (P) at (axis cs:2,2);\r\n     \\coordinate (Q) at (axis cs:2.5,3.125);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) { $x$};\r\n     \\node [above] at (myplot.above origin) { $f$};\r\n     \\draw [color=\\colorone, thick, shorten >= -1.5cm, shorten <=-1.5cm] (P)--(Q);\r\n      \\draw[color=\\colorone,fill] (P) circle (0.1) node[left] {\\scriptsize $P$} node[below right] {\\scriptsize $(2,2)$};\r\n      \\draw[color=\\colorone,fill] (Q) circle (0.1)node[above left] {\\scriptsize $Q$} node[right] {\\scriptsize $(2.5,3.125)$};\r\n     \\end{tikzpicture} %\r\n        \\label{ }\r\n        \\caption{$ t=2.5 $, $ m_{PQ}=2.25 $} \r\n    \\end{subfigure}\r\n \\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[ %\r\n      width=1.1\\textwidth,\r\n     clip=false, \r\n     %minor x tick num=1,\r\n     axis y line=middle,\r\n     axis x line=middle,\r\n     ymin=-1,\r\n     ymax=5,\r\n     %extra y tick labels={},\r\n     xmin=-1,\r\n     xmax=3.5,\r\n     name=myplot]\r\n     \\addplot [{\\colortwo},thick, smooth,domain=-1:3,samples=20] ({x},{x^2/2});\r\n     \\coordinate (P) at (axis cs:2,2);\r\n     \\coordinate (Q) at (axis cs:2.1,2.205);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) { $x$};\r\n     \\node [above] at (myplot.above origin) { $f$};\r\n     \\draw [color=\\colorone, thick, shorten >= -1.9cm, shorten <=-1.9cm] (P)--(Q);\r\n     \t\t \\draw[color=\\colorone,fill] (P) circle (0.1) node[left] {\\scriptsize $P$} node[below right] {\\scriptsize $(2,2)$};\r\n     \t\t \\draw[color=\\colorone,fill] (Q) circle (0.1)node[above left] {\\scriptsize $Q$} node[right] {\\scriptsize $(2.1,2.205)$};     \r\n     \\end{tikzpicture}\r\n        \\label{ }\r\n      \\caption{$ t=2.1 $, $ m_{PQ}=2.05 $}  \r\n    \\end{subfigure} \r\n    \\caption{ Slopes of secant lines as $ Q $ approaches $ P $ from the right.  \\label{tangentright} }\r\n\\end{figure}\r\n\r\n\r\n\r\n\r\n\r\n\r\nIn Table \\ref{tableTangentIdeaForTable}, we have computed the values of $f(t)$ and $m_{PQ}=\\frac{f(t)-2}{t-2}$ for various values of $t$ close to $x=2$.  In Figures \\ref{tangentleft}-\\ref{tangentright}, and in Table \\ref{tableTangentIdeaForTable} we see that as $t$ gets closer to $2$, $m_{PQ}$ appear to get closer to the number $2$, and indeed, we can say that $m_{PQ}$ ``gets infinitely close to $2$ as $t$ approaches $2$'' and so we can define $m=2$. Then the equation of the equation of the tangent line at $P$ becomes\r\n\\[\r\ny-2=2(x-2)\\quad ,\r\n\\]\r\nwhich is exactly the equation of the line plotted in blue in Figure \\ref{figTangentIdeaFor}.\r\n\r\n\\mTable{1}{Values of $f(x)$ and slope of line through $P,Q$.}{tableTangentIdeaForTable}{\\begin{tabular}{c|c|c|c|c}\r\n$x$& $f(x)=\\frac{t^2}2$& $t-2$ & $f(t)-f(2)$ & $m_{PQ}=\\frac{f(t)-f(2)}{t-2}$ \\\\\\hline\r\n0& 0& -2& -2& 1 \\\\\r\n1& 0.5& -1& -1.5& 1.5 \\\\\r\n1.5& 1.125& -0.5& -0.875& 1.75\\\\\r\n1.9& 1.805& -0.1& -0.195& 1.95\\\\\r\n1.99& 1.98005& -0.01& -0.01995& 1.995\\\\\r\n1.999& 1.998& -0.001& -0.0019995& 1.9995\\\\\\hline\r\n2.001& 2.002& 0.001& 0.0020005& 2.0005\\\\\r\n2.01& 2.02005& 0.01& 0.02005& 2.005\\\\\r\n2.1& 2.205& 0.1& 0.205& 2.05\\\\\r\n2.5& 3.125& 0.5& 1.125& 2.25\\\\\r\n3& 4.5& 1& 2.5& 2.5\\\\\r\n4& 8& 2& 6& 3 \\\\\r\n\\end{tabular}}\r\n\r\n\r\nIn order to give a strict definition of tangent, we need to define formally what it means for $m_{PQ}$ to ``get infinitely close'' to the number $2$. The colloquial phrase ``to get infinitely close to,'' corresponds to the mathematical notion of taking limits.\r\n\r\n\\subsection*{Velocity:}\r\n\r\nA similar idea is behind our notion of \\textit{velocity}. We can see immediately\r\nhow fast we are going, that is we can find the \\textit{instantaneous velocity} of a\r\ncar we are driving just by looking at the speedometer. But what is that actually\r\nmeasuring? The \\textit{average velocity} makes sense, it's the distance travelled\r\nover a specific interval of time. But the speedometer doesn't measure that, it\r\nhas a reading at each instant, and does not calculate an average velocity.\r\n\r\nBut the idea of instantaneous velocity of a moving car, at a specific time,\r\nhas to be interpreted as another limiting process, taking average velocities\r\nover shorter and shorter time intervals:\\[\r\nvelocity\\, \\, v:=\\lim _{\\Delta t\\rightarrow 0}\\frac{\\Delta distance}{\\Delta t}\\]\r\nwhere \\( \\Delta t \\) means {}``the change in time{}'', \\( \\Delta =change\\, in \\).\r\n\r\nIf you plot the distance on the vertical axis, and time on the horizontal, then\r\nyou have the same picture as before, and the velocity is the slope of that graph. \r\n\r\n\r\n%In the following exercises, we continue our introduction and approximate the value of limits.\\\\\r\n%\r\n%\\printexercises{exercises/01_01_exercises}\r\n\r\n\r\n%One-sides:\r\n%\r\n%\\printexercises{exercises/01_04_exercises}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:TangentProblem}}\r\n\r\n\\begin{multicols}{2}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\nEstimate the slope of the tangent line to the curve $f(x)=2\\sin\\frac{x}{2}$ at\r\nthe point $(\\frac{\\pi}{2},\\sqrt{2})$.\r\n \\begin{tikzpicture}[line width=1pt,scale=1]\r\n\\draw[->] (0,-.3) -- (0,2.5);\r\n\\foreach \\x in {1,2} \r\n{\\draw (-.1,\\x) --node[left]{\\x} (.1,\\x);\r\n}\r\n\\draw[->] (-.3,0) -- (5,0);\r\n\\foreach \\x in {2,4} \r\n{\\draw (\\x*pi/4,-.1) -- (\\x*pi/4,.1);\r\n}\r\n\\draw node[below=.1cm] at (pi/2,0) {$\\frac{\\pi}{2}$};\r\n\\draw node[below=.1cm] at (pi,0) {$\\pi$};\r\n\\draw plot[smooth,mark=*] coordinates{(0,0) (pi/3,1) (pi/2,1.414) (2*pi/3,1.732)\r\n(pi,2) (4*pi/3,1.732) (3*pi/2,1.414)};\r\n\\draw node  at (3,.7) {$f(x)=2\\sin\\frac{x}{2}$};\r\n\\end{tikzpicture}\r\n\\end{ex}\r\n\r\n\r\n\r\n\\begin{ex}\r\nThe following graphic shows 5 students and their grades posted compared to the\r\nnumber of cookies that they made for me. Estimate the G.P.A. of a student who\r\nmakes me 17 cookies.\r\n\\[\r\n\\begin{tikzpicture}[line width=1pt,xscale=.5]\r\n\\draw[<->] (0,4.5) -- (0,0) -- (15,0);\r\n\\foreach \\x in {.5,1,...,4} \\draw (-.07,\\x) -- (.07,\\x);\r\n\\foreach \\x in {1,2,3,4} \\draw node[left] at (0,\\x) {$\\x$};\r\n\\draw node[right] at (0,4) {G.P.A};\r\n\\foreach \\x in {5,10,15} \r\n{\r\n\\draw (\\x,-.07) -- (\\x,.07);\r\n\\draw node[below] at (\\x,0) {$\\x$};\r\n}\r\n\\draw node[above] at (15,0.2) {Cookies};\r\n\\draw plot[smooth,mark=*] coordinates{(0,1) (5,2) (10,2) (12,3) (14,3.5)};\r\n\\end{tikzpicture}\r\n\\]\r\n\\end{ex}\r\n\r\n\r\n\\begin{ex}\r\n Gravity on Earth dictates that a projectile with initial velocity of $v_0$ and starting height of $h_0$ has height (in feet) at time $t$ given by \r\n\\[\r\n h(t)=-16t^2+v_0t+h_0.\r\n\\]\r\nA rock dropped off the Twin Falls bridge takes $ 6 $ seconds to reach the river below. Find the average velocity of the rock.\r\n\\end{ex}\r\n\r\n\r\n\\begin{ex}\r\n  If a rock is thrown upward on the planet Oz with a velocity of $ 20 $ m/s, its height in meters $t$ seconds later is given by $y=20t-10t^2$. Find the average velocity over the given time intervals:\r\n\\begin{itemize} \r\n    \\item $[1,2]$\r\n    \\item $[1,1.5]$\r\n    \\item $[1,1.1]$\r\n    \\item $[1,1.01]$\r\n\\end{itemize}\r\n  Estimate the instantaneous velocity when $t=1$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}\r\n\r\n\\end{multicols}", "meta": {"hexsha": "f68e9278469bce3fabe725956fff454423b93dd0", "size": 16683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-1-limits-Tangent-Problem.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-1-limits-Tangent-Problem.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-1-limits-Tangent-Problem.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4577656676, "max_line_length": 581, "alphanum_fraction": 0.6212911347, "num_tokens": 5687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.6795213402849642}}
{"text": "  A graph $X$ is pair $(X_0,X_1)$ of vertices and edges.\n  The \\emph{degree} of a vertex $x \\in X_0$ is the number of edges meeting at $x$, where we count self-edges twice.\n  We say that $X$ is \\emph{connected} if any two vertices $x,y \\in X_0$ are connected by a finite path of edges.\n  \\begin{mdframed}\n    We will assume that all our graphs are connected and all the vertices have finite degrees.\n    The set of vertices itself can be infinite.\n  \\end{mdframed}\n\n  We want to think of graphs as 1-dimensional topological spaces.\n  If there are no loops, we can define maps between graphs $f:X \\rightarrow Y$ to be compatible pairs of maps $f_0:X_0 \\rightarrow Y_0$ and $f_1:X_1 \\rightarrow Y_1$, but when there are loops we need to specify directions for the loops. The map $f_1$ does not keep track of the \"directions\".\n  More precisely, we want to be able to differentiate between the two maps\n  \\begin{align*}\n    [0,1] &\\rightarrow [0,1] &&& [0,1] &\\rightarrow [0,1] \\\\\n    x &\\mapsto x &&& x&\\mapsto1-x\n  \\end{align*}\n  For this, we assign labels to each edge so that if $a$ is one direction then $a^{-1}$ is the reverse direction.\n  We can then talk about the source $d_0 a$ and target $d_1 a$ vertex of each label, so that\n  \\begin{align*}\n    d_0 a = d_1 a^{-1} && d_1 a = d_0 a^{-1}.\n  \\end{align*}\n  Denote by $X_{\\ell}$ the set of all labels (and their inverses).\n  A map between the graphs $f:X \\rightarrow Y$ is then a map between the label sets\n  \\begin{align*}\n    f_\\ell: X_\\ell \\rightarrow Y_\\ell\n  \\end{align*}\n  such that if $f_\\ell(a^{-1}) = f_\\ell(a)^{-1}$ and $d_i a = d_j b$ then $d_i f_\\ell(a) = d_j f_\\ell(b)$.\n  It is an \\emph{isomorphism} if it is bijective.\n  \\begin{align*}\n    [0,1] &\\rightarrow [0,1] &&& [0,1] &\\rightarrow [0,1] \\\\\n    x &\\mapsto x &&& x&\\mapsto1-x \\\\\n    a &\\mapsto a &&& a&\\mapsto a^{-1} \\\\\n    a^{-1} &\\mapsto a^{-1} &&& a^{-1}&\\mapsto a\n  \\end{align*}\n  A map between graphs $f: X \\rightarrow Y$ naturally induces a map between vertices $f_0 : X_0 \\rightarrow Y_0$.\n  %\n  %\n  %\n  %\n  %\n  %\n  %\n  %\n  %\n  % \\subsection{Covering spaces}\n  % \\begin{definition}\n  %   We say that $\\pi:X \\rightarrow Y$ is a \\emph{cover} or a \\emph{covering map} if for every vertex $v$, every vertex $w \\in \\pi_0^{-1}(v)$ has the same degree as $v$.\n  % \\end{definition}\n  % We call $\\pi_0^{-1}(v)$ the fiber over $v$.\n  % \\begin{ex}\n  %   \\todo{example of covering space}\n  % \\end{ex}\n  % We can construct covers using group actions.\n  % A left group action of $G$ on a graph $X$, denoted $G \\groupaction X$, is a collection of graph maps\n  % \\begin{align*}\n  %   g \\cdot - : X &\\longrightarrow X\\\\\n  %   x &\\longmapsto gx\n  % \\end{align*}\n  % satisfying $ex = x$, where $e$ is the identity element in $G$ and $g(hx) = (gh)x$ for all $g,h \\in G$.\n  % A left $G$-action on $X$ naturally defines left $G$-actions on $X_0$, $X_1$ and $X_\\ell$.\n  % The quotient graph $G \\backslash X$ is then the graph with vertices, edges, and labels being $X_0/G$, $X_1/G$, and $X_\\ell/G$ respectively.\n  % \\begin{definition}\n  %   We say that $G \\groupaction X$ is \\emph{free} if the induced group action on the set of vertices $X_0$ is free.\n  % \\end{definition}\n  % \\begin{ex}\n  %   \\todo{add example of maps between $S^1$: rotation and reflection.}\n  % \\end{ex}\n  % \\begin{qbox}\n  %   Show that if $G \\groupaction X$ is free then $X \\rightarrow G \\backslash X$ is a cover.\n  % \\end{qbox}\n  % \\begin{definition}\n  %   We say that a cover $\\pi:X \\rightarrow Y$ is a \\emph{Galois cover} if there exists a left group action $G \\groupaction X$ such that $Y \\cong G \\backslash X$.\n  % \\end{definition}\n  % \\begin{qbox}\n  %   Come up with a cover that is not-Galois.\n  % \\end{qbox}\n  %\n  %\n  %\n", "meta": {"hexsha": "58a848b9718110457617f386e1f9b1b127e16f86", "size": 3709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.3.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": "01.3.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": "01.3.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": 46.9493670886, "max_line_length": 291, "alphanum_fraction": 0.6424912375, "num_tokens": 1284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936435, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.6795213351556013}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage{amssymb,amsmath}\n\n\\author{Edoardo Pasca}\n\n\\title{Iterative Sample Statistic}\n\\date{\\today}\n\n\\newcommand{\\avg}{\\bar{v}}\n\n\\begin{document}\n\\maketitle\nSome time ago I was sick with some fever. The only thing I could do was to lay in bed and measure my body temperature. The thermometer took so little time to measure that I tried again and again. Each time the temperature was different.\n\nI thought to measure a few times and then to calculate the average, to get a more stable result.\n\nDoing it without a piece of paper starts to be a bit difficult when you have to deal with more than 5 samples (at least for me). I started thinking that there must be a way to update the last calculated average with the next sample.\n\n\\section{Mean}\nThe average is defined as:\n\\begin{equation}\n\\langle v\\rangle_N = \\frac{1}{N} \\sum_{i=1}^N v_i\n\\label{eq:avg_def}\n\\end{equation}\n\nAdding one sample $v_{N+1}$, the next evaluation of the average is:\n\\begin{align}\n\\avg_{N+1}  & =  \\frac{1}{N+1} \\sum_{i=1}^{N+1} v_i \\nonumber \\\\\n & =  \\frac{1}{N+1} \\left( \\sum_{i=1}^{N} v_i + v_{N+1} \\right) \\nonumber\\\\\n & =  \\frac{1}{N+1} \\left( N \\avg_{N} + v_{N+1} \\right) \\nonumber\\\\\n & =  \\frac{N}{N+1} \\avg_{N} + \\frac{v_{N+1}}{N+1}\n\\label{eq:iterative-avg}\n\\end{align}\n\n\nwhere $\\avg_{N+1}$ is the average calculated with $N+1$ samples and $N$ is \nthe number of samples. This formula says that we can calculate the next \naverage by keeping in mind only 3 numbers: the previous average, the number\nof samplings and the last sample. That's nice!\n\n\\section{Standard Deviation}\nThe variance is defined as the square of the standard deviation $\\sigma$:\n\\begin{equation}\n\\sigma_N^2 = \\frac{1}{N-1} \\sum_{i=1}^N \\left(v_i - \\avg_N\\right)^2\n\\label{eq:std_def}\n\\end{equation}\n\nAgain, adding the $N+1$-th sample the estimation of the variance can be\nexpressed as:\n\n\\begin{equation}\n\\sigma_{N+1}^2   =  \\frac{1}{N-1} \\sum_{i=1}^{N+1} \\left(v_i -\n\\avg_{N+1}\\right)^2\n\\end{equation}\nwe now use the eq. \\ref{eq:std_def} to express $\\avg_{N+1}$ in terms of\n$\\avg_N$\n\n\\begin{equation}\n\\sigma_{N+1}^2  = \\frac{1}{N} \\sum_{i=1}^{N+1} \\left(v_i -\n\\left( \\frac{N}{N+1} \\avg_{N} + \\frac{v_{N+1}}{N+1} \\right)\n \\right)^2 \n \\label{eq:var-n+1}\n %& = \\frac{1}{N-1}\\left( \\sum_{i=1}^{N} \\left(v_i -\n %\\frac{N}{N+1} \\avg_{N} + \\frac{v_{N+1}}{N+1} \\right)^2  + \n %\\left(v_{N+1} -\n %\\frac{N}{N+1} \\avg_{N} + \\frac{v_{N+1}}{N+1} \\right)^2\n %\\right) \\nonumber\n\\end{equation}\n\nBefore going further, we better arrange the term in the sum with a nice trick:\n\\begin{align}\nv_i - \\left(\\frac{N}{N+1} \\avg_{N} + \\frac{v_{N+1}}{N+1}\\right)& =  \\nonumber \\\\\n& = v_i - \\left( \\avg_N - \\avg_N + \\frac{N}{N+1} \\avg_{N}+\n\\frac{v_{N+1}}{N+1}\\right) \\nonumber \\\\\n& = v_i - \\avg_N - \\left( - \\avg_N + \\frac{N}{N+1} \\avg_{N}+\n\\frac{v_{N+1}}{N+1}\\right) \\nonumber \\\\\n& = \\left(v_i - \\avg_N\\right) - \\left( \\frac{N-(N+1)}{N+1} \\avg_{N}+\n\\frac{v_{N+1}}{N+1}\\right) \\nonumber \\\\\n& = \\left(v_i - \\avg_N\\right) - \\left(-\\frac{1}{N+1} \\avg_{N}+\n\\frac{v_{N+1}}{N+1}\\right) \n\\label{eq:trick}\n\\end{align}\n\nThe term in the sum is actually expressed by the sum of two terms, the first\ndepending on the various samplings, $v_i$ and the previous evaluation of the\naverage, $\\avg_N$,\nand the second term depending only on the previous evaluation of the average,\n$\\avg_N$, the number of samplings, $N$, and the last sample, $v_{N+1}$.\n\n\\begin{align}\na_i = & v_i - \\avg_N \\label{eq:a_i} \\\\\nb_{N,\\avg_N} = b = & \\frac{v_{N+1}-\\avg_{N}}{N+1} \\label{eq:b}\n\\end{align}\n\nNow we can express the variance, eq. \\ref{eq:var-n+1}, with the help of \nthese variables $a_i$ and b as,\n\\begin{align}\n\\sigma_{N+1}^2  = & \\frac{1}{N} \\left[\\left(\\sum_{i=1}^{N} \\left(a_i -\nb\\right)^2 \\right) \n + \\left(a_{N+1} - b\\right)^2\\right] \\\\\n = & \\frac{1}{N} \\left[\\left(\\sum_{i=1}^{N} \\left(a_i^2 +\nb^2 - 2a_ib\\right) \\right) \n + \\left(a_{N+1} - b\\right)^2\\right] \\nonumber \\\\\n = & \\frac{1}{N} \\left[\\left(\\sum_{i=1}^{N} \\left(a_i^2 +\nb^2 \\right) \\right) \n+ \\left(a_{N+1} - b\\right)^2\\right] = \n  \\frac{1}{N} \\left[\\left(\\sum_{i=1}^{N} a_i^2 \\right) +\nN b^2  \n + \\left(a_{N+1} - b\\right)^2\\right] \\nonumber \\\\\n = & \\frac{1}{N} \\left[(N-1)\\sigma_N^2  +\nN b^2  \n + \\left(a_{N+1} - b\\right)^2\\right] \\nonumber \\\\\n = & \\frac{1}{N} \\left[(N-1)\\sigma_N^2  +\n \\frac{N}{N+1} \\left(v_{N+1} - \\avg_N \\right)^2\n \\right] \\nonumber \\\\\n \\sigma_{N+1}^2 = & \\frac{N-1}{N} \\sigma_N^2  +\n \\frac{1}{N+1} \\left(v_{N+1} - \\avg_N \\right)^2\n \\label{eq:iterative-var}\n\\end{align}\n\nEqs. (\\ref{eq:iterative-avg}) and (\\ref{eq:iterative-var}) allow to iterative\ncalculate the next estimation of average and variance using only the previous\nestimation, the last sampling and the number of samples. \n\n\\section{Higher order moments}\nAs last algebraic remark, \n\\begin{align}\na_{N+1} - b = & (v_{N+1} - \\avg_N) - \\frac{1}{N+1} (v_{N+1} - \\avg_N)\n\\nonumber \\\\\n = & \\frac{N}{N+1} (v_{N+1} - \\avg_N) \\nonumber \\\\\n a_{N+1} - b= & N b\n\\end{align}\nWe can easily extend this treatment to higher standardized moments of the \ndistribution of the population:\n\n\\begin{equation}\nx_k = \\frac{\\sum_{i=1}^N \\left(v_i - \\avg_N\\right)^k}{\\sigma^k_N} =\n\\frac{M_{N,k}}{\\sigma^k_N}\n\\end{equation}\nwhere $k$ is the moment's order. It is now very easy to calculate the\n\n\\begin{align}\nM_{N+1,k} = & \\sum_i^{N+1} (v_i - \\avg_{N+1})^k \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i - b)^k\\right] + (a_{N+1} - b) ^k \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i - b)^k \\right]+ (Nb)^k\n \\label{eq:kth-moment}\n\\end{align}\n\n\\subsection{Skewness}\nThe skewness is a third order moment, $k=3$. \n\n\\begin{align}\nM_{N+1,3} = & \\left[\\sum_i^N (a_i - b)^3 \\right]+ (Nb)^3 \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i^3 - b^3 +3a_ib^2 - 3a_i^2b) \\right]+ (Nb)^3 \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i^3 - 3a_i^2b) \\right] -Nb^3 + (Nb)^3 \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i^3 - 3a_i^2b) \\right]+ Nb^3 (N^2-1)  \\nonumber \\\\\n = & M_{N,3} - 3b \\left[\\sum_i^N a_i^2 \\right]+ Nb^3 (N^2-1)  \\nonumber \\\\\n = & M_{N,3} - 3 b (N-1)\\sigma_N^2 + Nb^3 (N-1)(N+1)  \\nonumber \\\\\n\\end{align}\n\\subsection{Kurtosis}\nThe kurtosis is a fourth order moment, $k=4$. \n\n\\begin{align}\nM_{N+1,4} = & \\left[\\sum_i^N (a_i - b)^4 \\right]+ (Nb)^4 \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i^4 +b^4-4a_i^3+5a_i^2) \\right]+ (Nb)^4 \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i^3 - 3a_i^2b) \\right] -Nb^3 + (Nb)^4 \\nonumber \\\\\n = & \\left[\\sum_i^N (a_i^3 - 3a_i^2b) \\right]+ Nb^3 (N^2-1)  \\nonumber \\\\\n = & M_{N,3} - 3b \\left[\\sum_i^N a_i^2 \\right]+ Nb^3 (N^2-1)  \\nonumber \\\\\n = & M_{N,3} - 3 b (N-1)\\sigma_N^2 + Nb^3 (N-1)(N+1)  \\nonumber \\\\\n\\end{align}\n\\end{document}\n", "meta": {"hexsha": "3a00d77882f47246cd1dd65d5867a4a09bf64031", "size": 6558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/AvgStd.tex", "max_stars_repo_name": "paskino/iterative-avgstd", "max_stars_repo_head_hexsha": "93c9c1a906c1effbced7397d63cfa2d2d0a53fdb", "max_stars_repo_licenses": ["MIT"], "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/AvgStd.tex", "max_issues_repo_name": "paskino/iterative-avgstd", "max_issues_repo_head_hexsha": "93c9c1a906c1effbced7397d63cfa2d2d0a53fdb", "max_issues_repo_licenses": ["MIT"], "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/AvgStd.tex", "max_forks_repo_name": "paskino/iterative-avgstd", "max_forks_repo_head_hexsha": "93c9c1a906c1effbced7397d63cfa2d2d0a53fdb", "max_forks_repo_licenses": ["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.9075144509, "max_line_length": 236, "alphanum_fraction": 0.62610552, "num_tokens": 2723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744584140003, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.6795213306369}}
{"text": "\\section{Proof Handling}\n\nIn the proof editing mode, the user can use the tactics to deal with logical reasoning,\nand can also use some other specialized commands to deal with the proof environment.\n\nIn our implementation, the proof procedure is organized as a tree. Initially, the tree\nconsists only the theorem itself as the tree root and the only leaf.\nEvery time a tactic is applied, either\nthe current leaf is expanded to an internal node or the proof procedure of the subtree is completed, then the next leaf of the tree will be focused. The proof procedure is completed\nwhen all of the tree leaves are proven, then the whole proof object will be built recursively.\n\nTo each subgoal is associated a number of hypotheses called the {\\it local context} of the goal.\nInitially the local context contains nothing, it is enriched by the use of certain tactics.\n\nWhen a proof is completed, the message {\\tt No more subgoals} is displayed. One can then register this\nproof as a defined constant in the environment. Because there exists a correspondence between proofs and terms of\n$\\lambda\\text{-calculus}$, known as the {\\it Curry-Howard isomorphism}, the MiniProver stores proofs as terms of $\\it CIC$.\nThose terms are called {\\it proof terms}.\n\n\\subsection{\\tt Theorem}\nThe proof editing mode is entered by asserting a theorem.\n\n\\subsection{\\tt Proof}\nThis command is a noop which is useful to delimit the sequence of tactic commands which start a proof, after a\n{\\tt Theorem} command.\n\n{\\tt Theorem \\sl ident \\{binder\\} : term.}\n\\subsection{\\tt Qed}\nThis command is available in interactive editing proof mode when the proof is completed.\nThen {\\tt Qed} extracts a proof term from the proof script, switches back to the top level and\nattaches the extracted proof term to the declared name of the original goal.\n\n\\subsection{\\tt Admitted}\nThis command is available in interactive editing proof mode to give up the current proof and declare the initial goal as an axiom.\n\n\\subsection{\\tt Abort}\nThis command cancels the current proof development,\nswitching back to the top level.\n\n\\subsection{\\tt Undo}\nThis command cancels the effect of the last command. Thus, it backtracks one step.\n\n\\subsection{\\tt Restart}\nThis command restores the proof editing process to the original goal.\n\n", "meta": {"hexsha": "00e1c71eb3f864d5ab5c578420a52f49ba663164", "size": 2284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/proofhandling.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/proofhandling.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/proofhandling.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": 49.652173913, "max_line_length": 181, "alphanum_fraction": 0.7876532399, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.679467906244281}}
{"text": "%!TEX root = uber-driver-strategy.tex\n\\section{Bisection Algorithm} \\label{section:bisection}\n\nThe inner problem of the robust dynamic program is as follows: \n\\begin{eqnarray*}\n\\sigma^* &:=& \\min_p p^Tv : p \\in \\Delta^n, \\sum_j f(j)\\log p(j) \\geq \\beta\n\\end{eqnarray*}\nThe Lagrangian $\\textbf{L}: \\textbf{R}^n \\times \\textbf{R}^n \\times \\textbf{R} \\times \\textbf{R} \\rightarrow \\textbf{R}$ associated with the inner optimization problem is \n\\begin{eqnarray*}\n\\textbf{L}(v, \\zeta, \\mu, \\lambda) = p^Tv - \\zeta^Tp + \\mu(1 - p^T\\textbf{1}) + \\lambda(\\beta - f^T\\log p)\n\\end{eqnarray*}\nwhere $\\zeta, \\mu,$ and $\\lambda$ are Lagrange multipliers. The dual function $d: \\textbf{R}^n \\times \\textbf{R} \\times \\textbf{R} \\rightarrow \\textbf{R}$ is the minimum value of the Lagrangian over $p$ for $\\zeta \\in \\textbf{R}^n, \\mu \\in \\textbf{R},$ and $\\lambda \\in \\textbf{R}$,\n\\begin{eqnarray*}\nd(\\zeta, \\mu, \\lambda) &=& \\inf_p \\textbf{L}(v, \\zeta, \\mu, \\lambda) \\\\\n&=& \\inf_p(p^Tv - \\zeta^Tp + \\mu(1 - p^T\\textbf{1}) + \\lambda(\\beta - f^T\\log p))\n\\end{eqnarray*}\nThe optimal $p^*$ minimizing the above dual function is obtained by solving $\\frac{\\partial \\textbf{L}}{\\partial p} = 0$, which gives us,\n\\begin{eqnarray*}\np^*(i) &=& \\frac{\\lambda f(i)}{v(i) - \\zeta(i) - \\mu}\n\\end{eqnarray*}\nPlugging in the value of $p^*(i)$ into the dual function $d$, after some simplification, gives us the dual problem,\n\\begin{eqnarray*}\n\\bar{\\sigma} &:=& \\max_{\\zeta, \\mu, \\lambda} \\lambda(1 + \\beta) + \\mu - \\lambda \\sum_{j}f(j) \\log\\bigg(\\frac{\\lambda f(j)}{v(j) - \\zeta(j) - \\mu}\\bigg) : \\lambda \\geq 0, \\zeta \\geq 0, v \\geq \\zeta + \\mu\\textbf{1} \n\\end{eqnarray*}\nAs the above problem is concave, has a feasible set with non-empty interior (checked by plotting), there is no duality gap, that is $\\sigma^* = \\bar{\\sigma}$. \\hc{Previous statement needs clarification. The problem is upper convex, i.e., concave, not convex. Not sure how to argue the no duality gap}. Moreover, by a monotonicity argument ($\\zeta$ increasing causes the function value to decrease monotonically), we can conclude that $\\zeta$ is zero. Thus, the last constraint of the dual problem can be expressed as $\\mu \\leq v_{min} := \\min_j v(j)$. Hence, we get,\n\\begin{eqnarray}\n\\sigma^* &=& \\max_{\\lambda, \\mu} h(\\lambda, \\mu) \\nonumber \\\\\n\\textrm{where,} \\nonumber \\\\\nh(\\lambda, \\mu) &:=& \\begin{cases}\n\t\t\t\t\t \\lambda(1+\\beta) + \\mu - \\lambda \\sum_{j}f(j) \\log\\bigg(\\frac{\\lambda f(j)}{v(j) - \\mu}\\bigg), &\\text{if } \\lambda > 0, \\mu < v_{min}, \\\\\n\t\t\t\t\t -\\infty, &\\text{otherwise}\n\t\t\t\t     \\end{cases}\n\\end{eqnarray}\nThe gradient of $h$ is given by, \n\\begin{eqnarray}\n\\frac{\\partial h(\\lambda, \\mu)}{\\partial \\lambda} &=& \\beta - \\sum_{j}f(j) \\log\\bigg(\\frac{\\lambda f(j)}{v(j) - \\mu}\\bigg) \\\\\n\\frac{\\partial h(\\lambda, \\mu)}{\\partial \\mu} &=& 1 - \\lambda \\sum_{j} \\bigg(\\frac{f(j)}{v(j) - \\mu}\\bigg)\n\\end{eqnarray}\nFrom (3), we obtain the optimal value of $\\lambda$ for a fixed value of $\\mu$, $\\lambda(\\mu)$ given by,\n\\begin{eqnarray*}\n\\lambda(\\mu) &=& \\bigg(\\sum_{j}\\frac{f(j)}{v(j) - \\mu}\\bigg)^{-1}\n\\end{eqnarray*}\nwhich further reduces the problem to a 1-dimensional optimization problem,\n\\begin{eqnarray*}\n\\sigma^* &=& \\max_{\\mu < v_{min}} \\sigma(\\mu) \\\\\n\\textrm{where, } \\\\\n\\sigma(\\mu) &=& h(\\lambda(\\mu), \\mu)\n\\end{eqnarray*}\n$\\sigma(\\mu)$ is a concave function. Now, we may use a bisection algorithm to maximise this function.\n\nTo initialize the bisection algorithm, we need upper and lower bounds $\\mu_+$ and $\\mu_-$ on a minimizer of $\\sigma$. When $\\mu \\rightarrow v_{min}, \\sigma(\\mu) \\rightarrow v_{min}$ and $\\sigma^{'}(\\mu) \\rightarrow -\\infty$ \\hc{To be proved analytically, verified by graphing}. Thus, we may set upper bound $\\mu_+ = v_{min}$. The lower bound $\\mu_-$ must be chosen such that $\\sigma^{'}(\\mu_-) > 0$.\n\\begin{eqnarray*}\n\\sigma^{'}(\\mu) &=& \\frac{\\partial h}{\\partial \\mu} (\\lambda(\\mu), \\mu) + \\frac{\\partial h}{\\partial \\lambda} (\\lambda(\\mu), \\mu) \\frac{\\partial \\lambda(\\mu)}{\\partial \\mu}\n\\end{eqnarray*}\nBy construction of $\\lambda(\\mu)$, the first term of the above derivative is zero. Furthermore, $\\frac{\\partial \\lambda(\\mu)}{\\partial \\mu} < 0$. Hence, we need $\\mu$ such that $\\frac{\\partial h}{\\partial \\lambda} (\\lambda(\\mu), \\mu) < 0$. Using the bounds on $\\lambda(\\mu)$, $v_{min} - \\mu \\leq \\lambda(\\mu) \\leq v_{max} - \\mu$, we can show that,\n\\begin{eqnarray*}\n\\frac{\\partial h}{\\partial \\lambda} (\\lambda(\\mu), \\mu) &=& \\beta - \\sum_{j}f(j) \\log\\bigg(\\frac{\\lambda(\\mu) f(j)}{v(j) - \\mu}\\bigg) \\\\\n&=& \\beta - \\sum_{j}f(j)\\log f(j) - \\sum_{j}f(j)\\log\\bigg(\\frac{\\lambda(\\mu)}{v(j) - \\mu}\\bigg) \\\\\n&=& \\beta - \\beta_{max} - \\sum_{j}f(j)\\log\\bigg(\\frac{\\lambda(\\mu)}{v(j) - \\mu}\\bigg) \\textrm{(Need to verify this step)}\\\\\n&\\leq& \\beta - \\beta_{max} - \\log\\bigg(\\sum_{j}\\frac{f(j)\\lambda(\\mu)}{v(j) - \\mu}\\bigg) \\\\\n&\\leq& \\beta - \\beta_{max} - \\log\\bigg(\\sum_{j}\\frac{\\lambda(\\mu)}{v(j) - \\mu}\\bigg) \\\\\n&\\leq& \\beta - \\beta_{max} - \\log\\bigg(\\sum_{j}\\frac{v_{min} - \\mu}{v(j) - \\mu}\\bigg) \\\\\n&\\leq& \\beta - \\beta_{max} - \\log\\bigg(\\sum_{j}\\frac{v_{min} - \\mu}{v_{max} - \\mu}\\bigg) \\\\\n&\\leq& \\beta - \\beta_{max} - \\log\\bigg(n \\times \\frac{v_{min} - \\mu}{v_{max} - \\mu}\\bigg) \\\\\n&<& \\beta - \\beta_{max} - \\log\\bigg(\\frac{v_{min} - \\mu}{v_{max} - \\mu}\\bigg) \\textrm{(n $>$ 1)}\\\\\n\\end{eqnarray*}\nTherefore, the sufficient condition is,\n\\begin{eqnarray*}\n0 &>& \\beta - \\beta_{max} - \\log\\bigg(\\frac{v_{min} - \\mu}{v_{max} - \\mu}\\bigg) \\\\\n\\log\\bigg(\\frac{v_{min} - \\mu}{v_{max} - \\mu}\\bigg) &>& \\beta - \\beta_{max} \\\\\n\\bigg(\\frac{v_{min} - \\mu}{v_{max} - \\mu}\\bigg) &>& e^{\\beta - \\beta_{max}} \\\\\n(v_{min} - \\mu) &>& e^{\\beta - \\beta_{max}}(v_{max} - \\mu) \\\\\nv_{min} - e^{\\beta - \\beta_{max}}v_{max} &>& \\mu(1 - e^{\\beta - \\beta_{max}}) \\\\\n\\end{eqnarray*}\nHence,\n\\begin{eqnarray*}\n\\mu_{-}^0 := \\frac{v_{min} - e^{\\beta - \\beta_{max}}v_{max}}{1 - e^{\\beta - \\beta_{max}}} &>& \\mu\n\\end{eqnarray*}\nBy construction, the interval [$\\mu_-^0, v_{min}$) is guaranteed to contain the global maximiser of $\\sigma$ over $(-\\infty, v_{min})$. The bisection algorithm is as follows:\n% \\begin{enumerate}\n% \t\\item Set $\\mu_+ = v_{min}$ and $\\mu_- = \\mu_-^0$. Let $\\delta > 0$.\n% \t\\item While \\hc{Fill termination condition}, repeat\n% \t\\begin{enumerate}\n% \t\t\\item Set $\\mu = (\\mu_+ + \\mu_-)/2$.\n% \t\t\\item If $\\sigma^{'}(\\mu) > 0$, set $\\mu_- = \\mu$, otherwise $\\mu_+ = \\mu$.\n% \t\t\\item go to 2a.\n% \t\\end{enumerate}\n% \\end{enumerate}\n\\begin{enumerate}\n\t\\item Set $\\mu_+ = v_{min}$ and $\\mu_- = \\mu_-^0$. Let $k=1, \\mu_1 = (\\mu_+ + \\mu_-)/2$.\n\t\\item While $k \\leq N$:\n\t\\begin{enumerate}\n\t\t\\item If $\\sigma^{'}(\\mu_1) > 0$, set $\\mu_- = \\mu_1$, if $\\sigma^{'}(\\mu_1) < 0$ then $\\mu_+ = \\mu_1$, else break\n\t\t\\item $k = k + 1$, \n\t\t\\item $\\mu_{k} = (\\mu_+ + \\mu_-)/2$\n\t\\end{enumerate}\n\t\\item $\\hat{\\mu}^* = \\arg \\max_{i} \\{\\sigma(\\mu_i)\\}$\n\\end{enumerate}\n\\textbf{Lemma}: After $N \\approx \\log_2(V/\\delta)$ where $V = \\max\\big(\\sigma^* - \\sigma(\\mu_+), \\sigma^* - \\sigma(\\mu_-)\\big)$, the bisection algorithm provides optimal solution to the inner problem within an accuracy $\\delta > 0$ i.e., $\\sigma^* - \\sigma(\\hat{\\mu}^*) \\leq \\delta$ which we call as the $\\delta$-solution. \\\\ \\\\\n\\textbf{Proof}: Let the interval $[\\mu_-,\\mu_+]$ from step 1 of the bisection algorithm be denoted by $G$. At each iteration, the length of the interval that contains the global maximiser of $\\sigma$ is exactly halved. Hence, let $[\\mu_{N-}, \\mu_{N+}]$ be the corresponding interval after $N$ iterations of the bisection algorithm. Length of the interval $G_N$ is $2^{-N}$ times the length of $G$. Using the bisection algorithm, we know that,\n\\begin{eqnarray*}\n\\forall \\mu: \\mu \\in G\\setminus G_N \\rightarrow \\sigma(\\mu) \\leq \\sigma(\\hat{\\mu}^*) \n\\end{eqnarray*}\nLet $2^{-N} < \\alpha < 1$. $\\alpha$-contraction of $G$ to $\\mu^*$ is the segment given by points,\n\\begin{eqnarray*}\nG^{\\alpha} = (1 - \\alpha)\\mu^* + \\alpha G = \\big\\{ (1-\\alpha)\\mu^* + \\alpha z \\big| z \\in G \\big\\}\n\\end{eqnarray*}\nSince, $\\alpha > 2^{-N}$, we know that length of $G^{\\alpha} > G_N$, in fact, length of $G^{\\alpha}$ is $\\alpha(\\mu_+ - \\mu_-)$. Hence, $\\exists y \\in G^{\\alpha}$ such that $y \\notin G_N$. Furthermore, $\\exists z \\in G$ such that $y = (1 - \\alpha)\\mu^* + \\alpha z$. By the concavity of $\\sigma(\\mu)$ function,\n\\begin{eqnarray*}\n\\sigma(y) &\\geq& (1 - \\alpha)\\sigma(\\mu^*) + \\alpha \\sigma(z) \\\\\n\\sigma(\\mu^*) - \\sigma(y) &\\leq& \\alpha(\\sigma(z) - \\sigma(\\mu^*)) \\\\\n&\\leq& \\alpha V \n\\end{eqnarray*}\nHence, $y$ is an $\\alpha V$-solution to our problem.\n\\begin{eqnarray*}\n\\sigma(\\hat{\\mu}^*) &\\geq& \\sigma(y) \\\\\n\\sigma(\\mu^*) - \\sigma(\\hat{\\mu}^*) &\\leq& \\sigma(\\mu^*) - \\sigma(y) \\leq \\alpha V\n\\end{eqnarray*}\nHence, sufficient condition for obtaining a $\\delta$-solution is, $\\alpha V \\leq \\delta$ i.e., $N \\geq \\log_2 (V / \\delta)$. However, $V$ is unknown by itself. But, the objective function of the inner problem, $p^Tv$, is bounded from above by $v_{max}$. Therefore, the lemma still holds for $V = \\max\\big(v_{max} - \\sigma(\\mu_+), v_{max} - \\sigma(\\mu_-)\\big)$.\n\\section{$\\epsilon$-suboptimal Algorithm}\n\nEach step of the robust dynamic programming algorithm from Section \\ref{section:robust-dynamic-programming} involves finding the solution of an optimization problem, referred to as the `inner problem', of the form,\n\\begin{eqnarray*}\n\\sigma_{\\mathcal{P}}(v) &:=& \\min_{p \\in \\mathcal{P}} p^Tv,\n\\end{eqnarray*}\nwhere $p$ corresponds to particular row of a transition matrix, $\\mathcal{P} = \\mathcal{P}^{a}_{i,t}$ is the set that describes the uncertainty of this row, and $v$ contains the elements of the value function at this step. Section \\ref{section:likelihood} provides a criterion for the choice of uncertainty model that represents accurately the statistical uncertainty on the transition matrices. Section \\ref{section:bisection} describes a bisection algorithm that provides an optimal solution to the inner problem within an accuracy $\\delta > 0$. \\hc{This should be ensured by the stopping criterion of the algorithm}. Thus, for a given $v \\in \\textbf{R}^n_+$ and $\\delta > 0$, the bisection algorithm gives output of the form,\n\\begin{eqnarray*}\n\\hat{\\sigma}_{\\mathcal{P}}(v) &=& \\sigma_{\\mathcal{P}}(v) - \\delta_{\\mathcal{P}}(v) \\textrm{ where } 0 \\leq \\delta_{\\mathcal{P}}(v) \\leq \\delta\n\\end{eqnarray*}\nAn $\\epsilon$-suboptimal policy, $\\hat{\\pi}$ is a policy such that the worst-case expected total reward under policy $\\hat{\\pi}$, namely, $\\phi_N(\\hat{\\pi},\\mathcal{T}) = \\min_{\\tau \\in \\mathcal{T}}R_N(\\hat{\\pi}, \\tau)$, satisfies \n\\begin{eqnarray*}\n\\phi_N(\\hat{\\pi},\\mathcal{T}) \\leq \\phi_N(\\Pi,\\mathcal{T}) \\leq \\phi_N(\\hat{\\pi},\\mathcal{T}) + \\epsilon\n\\end{eqnarray*}\nHere, $\\epsilon > 0$ is given. Using the uncertainty model from Section \\ref{section:likelihood}, we solve the bisection algorithm with an accuracy $\\delta := \\epsilon /N$. This gives us the robust finite horizon dynamic programming algorithm as follows,\n\n\\begin{enumerate}\n\t\\item Set $\\epsilon > 0$. Initialize the value function to its terminal value $\\hat{v}_N = r_N$\n\t\\item Repeat until t=0:\n\t\\begin{enumerate}\n\t\t\\item For every state $i \\in \\mathcal{X}$ and action $a \\in \\mathcal{A}$, compute, using the bisection algorithm described in the previous section, a value $\\hat{\\sigma}^{a}_i$ such that,\n\t\t\\begin{eqnarray*}\n\t\t\\hat{\\sigma}^{a}_i \\leq \\sigma_{\\mathcal{P}^{a}_{i,t}}(v_{t}) \\leq \\hat{\\sigma}^{a}_i + \\frac{\\epsilon}{N}\n\t\t\\end{eqnarray*}\n\t\t\\item Update the value function by,\n\t\t\\begin{eqnarray*}\n\t\tv_{t-1}(i) &=& \\max_{a \\in \\mathcal{A}} \\bigg(r_{t-1}(i,a) + \\hat{\\sigma}^{a}_i\\bigg), i \\in \\mathcal{X}\n\t\t\\end{eqnarray*}\n\t\t\\item t = t - 1\n\t\\end{enumerate}\n\t\\item For every $i \\in \\mathcal{X}$ and $t \\in T$, set $\\pi^{\\epsilon} = (\\textbf{a}^{\\epsilon}_0, ..., \\textbf{a}^{\\epsilon}_{N-1})$, where\n\t\\begin{eqnarray*}\n\t\\textbf{a}^{\\epsilon}_t &=& \\arg \\min_{a \\in \\mathcal{A}} \\big\\{r_{t-1}(i,a) + \\hat{\\sigma}^{a}_i\\big\\}, i \\in \\mathcal{X}, a \\in \\mathcal{A}\n\t\\end{eqnarray*}\n\\end{enumerate}", "meta": {"hexsha": "56fa890de11e1b952ab22b51e9fc6b8f2d05c7be", "size": 11950, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/formulation/bisetion_algorithm.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/formulation/bisetion_algorithm.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/formulation/bisetion_algorithm.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": 77.5974025974, "max_line_length": 728, "alphanum_fraction": 0.6367364017, "num_tokens": 4473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.679467889361874}}
{"text": "% section3\r\n\\chapter {Determinants}\r\n\r\n\\section{Determinants; cofactor Expansion}\r\n\r\n\\begin{exer}\r\nCompute the determinants of the matrix A:\r\n\\begin{equation*}\r\nA=\\begin{bmatrix}-4 & 1 & 1 & 1 & 1 & \\\\ 1 & -4 & 1 & 1 & 1 \\\\ 1 & 1 & -4 & 1 & 1 \\\\ 1 & 1 & 1 & -4 & 1 \\\\ 1 & 1 & 1 & 1 & -4\\end{bmatrix}\\\\.\r\n\\end{equation*}\r\nHow can you construct $A$ brilliantly?\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\nA=ones(5)-5*eye(5);\r\ndisp('A is'); disp(A);\r\ndisp('Determinant of A is'); disp(det(A));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nA is\r\n    -4     1     1     1     1\r\n     1    -4     1     1     1\r\n     1     1    -4     1     1\r\n     1     1     1    -4     1\r\n     1     1     1     1    -4\r\n\r\nDeterminant of A is\r\n  -5.5511e-14\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\\begin{exer}\r\nShow that \r\n$$\\det\\left(\\begin{bmatrix} \\displaystyle a & b & c & d \\\\ -b & a & d & -c \\\\ -c & -d & a & b \\\\ -d & c & -b & a \\end{bmatrix}\\right)=(a^2+b^2+c^2+d^2)^2.$$\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\nsyms a b c d;\r\n\r\nA=[a b c d; -b a d -c; -c -d a b; -d c -b a];\r\n\r\ndisp('Given matrix is'); disp(A);\r\ndisp('Determinant of the given matrix is'); \r\ndisp(simplify(det(A)));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nGiven matrix is\r\n[  a,  b,  c,  d]\r\n[ -b,  a,  d, -c]\r\n[ -c, -d,  a,  b]\r\n[ -d,  c, -b,  a]\r\n \r\nDeterminant of the given matrix is\r\n(a^2 + b^2 + c^2 + d^2)^2\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} \r\nThe $n$th-order \\textbf{Fibonacci matrix} [named for the Italian mathematician~(circa~1170~-~1250)] is the $n \\times n$ matrix $F_{n}$ that has 1's on the main diagonal, 1's along the diagonal immediately above the main diagonal, -1's along the diagonal immediately below the main diagonal, and zeros everywhere else. Construct the sequence\r\n$$\\det(F_{1}), \\,\\det(F_{2}), \\,\\det(F_{3}), \\,\\cdots, \\det(F_{7}).$$\r\nMake a conjecture about the relationship between a term in the sequence and its two immediate predecessors, and then use your conjecture to make a guess at $\\det(F_{8})$. Check your guess by calculating this number.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\n% Construct the 10x10 Fibonacci matrix F.\r\nN=10; nOnes=ones(N, 1);\r\nF=diag(nOnes)+diag(nOnes(1:N-1),1)-diag(nOnes(1:N-1),-1);\r\n\r\nfor n=1:7 % n is from 1 to 7\r\n    Fn=F(1:n,1:n); % nxn Fibonacci matrix is selected from F. \r\n    disp(det(Fn));\r\nend\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\n     1\r\n     2\r\n     3\r\n     5\r\n     8\r\n    13\r\n    21\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\noindent The constructed sequence satisfies the relationship $\\det(F_n)=\\det(F_{n-1})+\\det(F_{n-2}),$ for $\\det(F_1)=1$ and $\\det(F_2)=2$. From that, we may guess that $\\det(F_8)=34$.\r\nMATLAB gives us the same output value 34 as our guess. \r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\r\n\\begin{exer} Let $A_{n}$ be the $n \\times n$ matrix that has 2's along the main diagonal, 1's along the diagonals immediately above and below the main diagonal, and zeros everywhere else. Make a conjecture about the relationship between $n$ and $\\det(A_{n})$.\r\n\\end{exer}\r\n\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nformat rat;\r\n% Construct the 10x10 matrix A satisfying given conditions.\r\nn=10; nOnes=ones(n, 1);\r\nA=2*diag(nOnes)+diag(nOnes(1:n-1),1)+diag(nOnes(1:n-1),-1);\r\n\r\nfor i=1:10 % i is from 1 to 10\r\n    Ai=A(1:i,1:i); % A_i matrix is selected from A. \r\n    disp(det(Ai));\r\nend\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\n       2     \r\n       3       \r\n       4       \r\n       5       \r\n       6       \r\n       7       \r\n       8       \r\n       9       \r\n      10       \r\n      11  \r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\noindent From the outputs, we make a conjecture about the relationship between $n$ and $\\det(A_{n})$ as follows:\r\n$$\\det(A_{n})=n+1.$$\r\n\r\n\\end{sol}\r\n\r\n\r\n\\section{Properties of Determinants}\r\n\r\n\\begin{exer}(\\textit{Determinants with LU-decomposition})\r\nIn this problem, we find the determinant of the matrix $A$ by using the $LU$-decomposition of $A$, where\r\n\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrr} -2& \\hspace{1mm} 2& \\hspace{1mm}-4& \\hspace{2mm} -6\\\\ -3 & 6 & 3 & -15 \\\\ 5 & -8 & -1 & 17 \\\\ 1 & 1 & 11 & 7 \\end{array} \\right].\r\n\\end{displaymath}\r\n\\vspace{1mm}\r\n\\begin{enumerate}\r\n\\item[(a)] Compute the determinant of $A$ directly by using the MATLAB command \\textit{det} for $A$.\r\n\\vspace{1mm}\r\n\\item[(b)] Compute the determinant of $A$ by using the MATLAB command \\textit{lu} for $A$. Confirm that you get the same results.\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 = [-2 2 -4 -6; -3 6 3 -15; 5 -8 -1 17; 1 1 11 7];\r\n\r\ndet_A = det(A); % Find the determinant of A by using the command det.\r\n\r\ndisp('The determinant of A by direct use of the command det is');\r\ndisp(det_A);\r\n\r\n%(b)\r\n[L U P] = lu(A); % We have a PLU-decomposition of A. (i.e., PA=LU ).\r\n\r\n% Since the determinant of a triangular matrix is\r\n% just a product of diagonal entries,\r\n\r\ndet_L = prod(diag(L)); % The product of diagonal entries of L.\r\n% Or, you may use the command det for L, directly. (i.e., det_L = det(L)).\r\n\r\ndet_U = prod(diag(U)); % The product of diagonal entries of U.\r\n% Or, you may use the command det for U, directly. (i.e., det_U = det(U)).\r\n\r\n% If you observe the permutation matrix P, you can see that\r\n% P is an odd permutation. Thus, we have det(P) = -1.\r\ndet_P = -1;\r\n% Or, you may use the command det for P, directly. (i.e., det_P = det(P)).\r\n\r\n% Since PA = LU, det(P)*det(A) = det(L)*det(U).\r\ndet_A = det_P * det_L * det_U;\r\n\r\ndisp('The determinant of A by using the LU-decomposition is'); disp(det_A);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe determinant of A by direct use of the command det is\r\n   24.0000\r\n\r\nThe determinant of A by using the PLU-decomposition is\r\n   24.0000\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n \r\n\\vspace{3mm}\r\n\r\n\\begin{exer} (\\textit{Effects of Elementary Row Operations on the Determinant})\r\n\r\nUsing the MATLAB command \\textit{det}, confirm the formulas (a)-(c) in Theorem 4.2.2 of Section 4.2 for the matrix $A$ given in the problem 31 of Exercise set 4.1.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nA = [3 3 0 5; 2 2 0 -2; 4 1 -3 0; 2 10 3 2];\r\n\r\n% (a). Multiply the second row of A by 2 and call it A2.\r\n% Initialize the matrix A2 as A.\r\nA2 = A; \r\n% Multiply the second row of A by 2.\r\nA2(2,:) = 2*A(2,:);\r\ndisp('The determinant of A2 is'); disp(det(A2));\r\ndisp('2*det(A) = '); disp(2*det(A));\r\n\r\n% (b). Interchange the rows 2 and 4 of A and call it A24.\r\n% Initialize the matrix A24 as A.\r\nA24 = A; \r\n% Interchange the rows 2 and 4 of A.\r\nA24(2, :) = A(4, :) ; A24(4, :) = A(2, :);\r\ndisp('The determinant of A24 is'); disp(det(A24));\r\ndisp('-det(A) = '); disp(-det(A));\r\n\r\n% (c). Add 2 times row 3 to row 4 of A and call it A234.\r\n% Initialize the matrix A234 as A.\r\nA234 = A; \r\n% Add 2 times row 3 of A to row 4.\r\nA234(4, :) = 2 * A(3, :) + A(4, :); \r\ndisp('The determinant of A234 is'); disp(det(A234));\r\ndisp('det(A) = '); disp(det(A));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe determinant of A2 is\r\n  -480\r\n2*det(A) =\r\n -480.0000\r\n\r\nThe determinant of A24 is\r\n  240.0000\r\n-det(A) =\r\n  240.0000\r\n\r\nThe determinant of A234 is\r\n -240.0000\r\ndet(A) =\r\n -240.0000\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\r\n\\vspace{3mm}\r\n\r\n\\begin{exer} Use a determinant to show that if $a, b, c,$ and $d$ are not all zeros, then the vectors\r\n\\begin{eqnarray*}\r\n\\mathbf{v}_{1}&=&(a,\\, b,\\, c,\\, d)\\\\\r\n\\mathbf{v}_{2}&=&(-b, a, d, -c)\\\\\r\n\\mathbf{v}_{3}&=&(-c, -d, a, b)\\\\\r\n\\mathbf{v}_{4}&=&(-d, c, -b, a)\r\n\\end{eqnarray*}\r\nare linearly independent.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\nsyms a b c d;\r\nv1=[a b c d];\r\nv2=[-b a d -c];\r\nv3=[-c -d a b];\r\nv4=[-d c -b a];\r\n\r\nV=[v1; v2; v3; v4];\r\ndisp('det(V) is'); disp(simplify(det(V)));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\ndet(V) is\r\n(a^2 + b^2 + c^2 + d^2)^2\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n\r\n\r\n\\section{Cramer's Rule; Formula for $A^{-1}$; Applications}\r\n\r\nNo MATLAB problems in this section.\r\n\r\n\\newpage\r\n\r\n\\section{A First Look at Eigenvalues and Eigenvectors}\r\n\r\n\r\n\\begin{exer}(\\textit{Eigenvalues and Eigenvectors})\\\\\r\nUse the MATLAB command \\textit{eig} to find the eigenvalues and the associated \\mbox{eigenvectors} of the matrix $A$, where\r\n$$A = \\left[\\begin{array}{rrrr} 2& \\hspace{1mm}-3& \\hspace{1mm} 1& \\hspace{3mm} 0\\\\ 1 & 1 & 2 & 2\\\\ 3 & 0 & -1 & 4 \\\\ 1 & 6 & 5 & 6 \\end{array} \\right].$$\r\nDisplay the results with long digits.\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=[2 -3 1 0; 1 1 2 2; 3 0 -1 4; 1 6 5 6];\r\n\r\n% Find the eigenvalues and eigenvectors of A by using eig.\r\n% This command gives AQ = QD.\r\n[Q D] = eig(A); \r\nlambda1 = D(1,1); lambda2 = D(2,2); \r\nlambda3 = D(3,3); lambda4 = D(4,4); \r\n\r\n% Extract each column vector as an eigenvector of A.\r\nx1 = Q(:,1); x2 = Q(:,2); x3 = Q(:,3); x4 = Q(:,4);\r\n\r\n% Display the result with long digits.\r\nformat long; \r\ndisp('lambda1 is'); disp(lambda1);\r\ndisp('The eigenvector corresponding to lambda1 is'); disp(x1');\r\ndisp('lambda2 is'); disp(lambda2);\r\ndisp('The eigenvector corresponding to lambda2 is'); disp(x2');\r\ndisp('lambda3 is'); disp(lambda3);\r\ndisp('The eigenvector corresponding to lambda3 is'); disp(x3');\r\ndisp('lambda4 is'); disp(lambda4);\r\ndisp('The eigenvector corresponding to lambda4 is'); disp(x4');\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nlambda1 is\r\n  9.561855032395805\r\nThe eigenvector corresponding to lambda1 is\r\n -0.067716707308095  0.278176502030497  0.322465582156500  0.902246213399589\r\nlambda2 is\r\n -3.364648937746373\r\nThe eigenvector corresponding to lambda2 is\r\n  0.275562522991092  0.197508356444458 -0.885771126913498  0.316962546342283\r\nlambda3 is\r\n  1.802793905350564\r\nThe eigenvector corresponding to lambda3 is\r\n -0.833621905475750 -0.103812731179200 -0.147042873144503  0.522183711938150\r\nlambda4 is\r\n -3.860931435448914e-16\r\nThe eigenvector corresponding to lambda4 is\r\n -0.705886578756789 -0.456750139195570  0.041522739926871  0.539795619049310\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\\noindent\\textit{Remark.} In fact, if we compute $\\lambda_{4}$ by hand, we can obtain that $\\lambda_{4}=0$. However, from the result, we see that the resulting value of $\\lambda_{4}$ seems to be nonzero even though it is small enough. This is due to roundoff errors in arithmetic operations. Please refer to the help command of \\textit{eps}, then you can see that $eps = 2.220446049250313e-016$ is floating-point relative accuracy, which means that \\textit{eps} value is the allowable tolerance when we do numerical computations with rounding floating-point number off. ($i.e.$, $eps$ is an upper bound on the relative error due to rounding in floating point arithmetic.)\r\nTherefore, we can regard the resulting value of $\\lambda_{4}$ as zero.\r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\\begin{exer}(\\textit{Eigenvalues and Eigenvectors})\r\n\r\nDefine an $n$th-order \\textbf\\textit{checkboard matrix} $C_{n}$ to be a matrix that has a 1 in the upper left corner and alternates between 1 and 0 along rows and columns (see the figure below). Find the eigenvalues of $C_{1}, C_{2}, \\cdots$ to make a conjecture about the eigenvalues of $C_{n}$. What can you say about the eigenvalues of $C_{n}$? \r\n\\begin{figure}[h]\\centering\r\n\\includegraphics[width=4cm]{figure.jpg}\r\n\\end{figure}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nformat short;\r\nn=10;   % Set the size of the large check board\r\n\r\n% Construct your checkboard\r\nCheckBoard=zeros(n);    \r\nCheckBoard(1:2:n, 1:2:n)=1;\r\nCheckBoard(2:2:n, 2:2:n)=1;\r\nfor i=1:n\r\n    Cn=CheckBoard(1:i, 1:i);\r\n    [Qn Dn]=eig(Cn);    % Eigenvectors and eigenvalues\r\n    fprintf('The size of the checkboard is %d \\n',i);\r\n    disp(diag(Dn)');\r\nend\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe size of the checkboard is 1 \r\n     1\r\nThe size of the checkboard is 2 \r\n     1 1\r\nThe size of the checkboard is 3 \r\n     0 1 2\r\nThe size of the checkboard is 4 \r\n     0 0 2 2\r\nThe size of the checkboard is 5 \r\n   -0.0000 -0.0000  0.0000  2.0000  3.0000\r\nThe size of the checkboard is 6 \r\n   -0.0000  -0.0000  -0.0000  -0.0000  3.0000  3.0000\r\nThe size of the checkboard is 7 \r\n   -0.0000  -0.0000   0.0000   0.0000  0.0000  3.0000  4.0000\r\nThe size of the checkboard is 8 \r\n   -0.0000  -0.0000  -0.0000  0.0000  0.0000  0.0000  4.0000  4.0000\r\nThe size of the checkboard is 9 \r\n   -0.0000  -0.0000  -0.0000 -0.0000   0   0.0000  0.0000  4.0000  5.0000\r\nThe size of the checkboard is 10 \r\n   -0.0000  -0.0000  -0.0000  0  0.0000  0.0000  0.0000  0.0000  5.0000  5.0000\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\noindent We may conclude that the eigenvalues of $C_{n}$ are given as follows:\r\n$$\\begin{cases} 1 &\\text{if $n=1$,}\\\\ \r\n k,\\, k,\\, \\underbrace{0,\\,0,\\,\\cdots,\\,0}_{(n-2)}&\\text{if $n=2k$,}\\\\\r\n k,\\,k+1,\\,\\underbrace{0,\\,0,\\,\\cdots,\\,0}_{(n-2)}&\\text{if $n=2k+1$,}\r\n\\end{cases}\r\n$$ \r\nwhere $k$ is a positive integer.\r\n\\end{sol}\r\n", "meta": {"hexsha": "c5a6fa27811d08fcdc103bb47c7182c22cabd9b2", "size": 13007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section4.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)/section4.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)/section4.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": 28.2760869565, "max_line_length": 672, "alphanum_fraction": 0.62866149, "num_tokens": 4614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6794678882509657}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^3+7}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac1n$ is a $p$-series with $p=1$. Since $p \\leq 1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac1n$ diverges by the $p$-series test. If we use $a_n = \\frac{n^2+1}{n^3+7}$ and $b_n = \\frac1n$, then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{n^2+1}{n^3+7} \\cdot \\frac{n}{1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{n^3+n}{n^3+7} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac{3n^2+1}{3n^2} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{6n}{6n} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} 1\\\\\r\n&= 1\r\n\\end{align*}\r\nSo by the Limit Comparison Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^3+7}$ diverges.\r\n\r\n\r\n\\subsection*{Solution 2}\r\n\r\nWe are looking for a fixed $K > 0$ such that \r\n\\[ K \\cdot  \\frac{n^2+1}{n^3+7} \\geq \\frac1n\\]\r\nBy multiplying both sides by $n(n^3+7)$, we have\r\n\\[ K(n^3 + n) \\geq n^3+7\\]\r\nso\r\n\\[ Kn^3 + Kn \\geq n^3+7\\]\r\nso\r\nif we pick $K=8$, then we'd have\r\n\\[ 8n^3 + 8n \\geq n^3+7\\]\r\nis likely true because \r\n\\[ n^3+ 7n^3 + 8n \\geq n^3+7\\]\r\nwith the $n^3$'s compared together, and $7n^3$ is greater than $7$. So we are ready to present starting from true inequalities.\r\n\r\nWith the scratch work above done, since $7n^3 \\geq 7$ for $n \\geq 1$, we have\r\n\\[ n^3+ 7n^3 + 8n \\geq n^3+7\\]\r\n\\[ 8n^3 + 8n \\geq n^3+7\\]\r\n\\[ 8(n^3 + n) \\geq n^3+7\\]\r\nand dividing both sides by $8n(n^3+7)$ we get\r\n\\[\\frac{n^2+1}{n^3+7} \\geq \\frac1{8n}\\]\r\nSince $\\displaystyle \\sum_{n=1}^\\infty \\frac1{8n} = \\frac18\\sum_{n=1}^\\infty \\frac1{n}$ diverges by the $p$-test, the series \r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^3+7}$ diverges by the Direct Comparison Test.\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": "b596580225a05b0084878f8ab2e020157abfd6dd", "size": 2713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/n3.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/n3.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/n3.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": 33.9125, "max_line_length": 238, "alphanum_fraction": 0.6092886104, "num_tokens": 1132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.6794226098664606}}
{"text": "\\documentclass[a4paper]{article}\n\n% Nice way to display code\n\\usepackage{minted}\n\n% Import images\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{multicol}\n\n\\title{Understanding the connection between\n       ranking the internet and eigen vectors}\n\\author{Vince Knight}\n\\date{}\n\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction: The origins of the Page Rank algorithm}\n\nIn the early 1990s the internet was becoming popular and there was a need to\nfind an efficient way of searching \\textbf{and finding} web pages for a specific\nquery. In~\\cite{page1999pagerank} Larry Paige, Sergey Brin and Terry Winograd\ndescribed an approach they referred to as Page Rank. This became the basis of\nthe now successful company Google.\n\nIn this work, we will describe the problem of ranking web pages with an example,\nthen go on to describe the basis of the Page Rank algorithm before explaining\nhow it relates to the eigenvalue of a matrix.\n\n\\section{Ranking internet pages}\\label{sec:ranking_pages}\n\nThe internet can be thought of as a mathematical object called a\ngraph~\\cite{diestel2005graph}.\n\nWe can use numpy to generate a random adjacency matrix \\(A\\) where:\n\n\\[\n    A_{ij}\n    =\n    \\begin{cases}\n        1,&\\text{ if }(i,j) \\text{ is an edge}\\\\\n        0,&\\text{ otherwise}\n    \\end{cases}\n\\]\n\n\\begin{minted}{python}\n>>> size = 10\n>>> np.random.seed(0)\n>>> A = np.random.choice((0, 1), size=(size, size))\n>>> A\narray([[0, 1, 1, 0, 1, 1, 1, 1, 1, 1],\n       [1, 0, 0, 1, 0, 0, 0, 0, 0, 1],\n       [0, 1, 1, 0, 0, 1, 1, 1, 1, 0],\n       [1, 0, 1, 0, 1, 1, 0, 1, 1, 0],\n       [0, 1, 0, 1, 1, 1, 1, 1, 0, 1],\n       [0, 1, 1, 1, 1, 0, 1, 0, 0, 1],\n       [1, 0, 1, 0, 1, 0, 0, 0, 0, 0],\n       [1, 1, 0, 0, 0, 1, 1, 0, 1, 0],\n       [0, 1, 0, 1, 1, 1, 1, 1, 1, 0],\n       [1, 1, 0, 0, 1, 0, 0, 1, 1, 0]])\n\\end{minted}\n\nEach row and column of \\(A\\) corresponds to a web page (so in our example here\nthe internet only has 10 web pages). We see that the first web page (the first\nrow of \\(A\\) links to all the other webpages except the fourth.\n\nPython has a library for studying networks called networkx. It can be used to\ncreate visualisations:\n\n\\begin{minted}{python}\n>>> G = nx.from_numpy_array(A, create_using=nx.DiGraph())\n>>> plt.figure()\n>>> nx.draw(G)\n\\end{minted}\n\nFigure~\\ref{fig:image_of_graph} shows the corresponding network.\n\n\\begin{figure}[!hbtp]\n    \\includegraphics[width=.8\\textwidth]{graph.pdf}\n    \\label{fig:image_of_graph}\n\\end{figure}\n\nThe Page Rank algorithm assumes that users are going to browse the internet in a\nrandom fashion where they are equally likely to go from a page to any of the\nother pages that it links to. The score against which it is ranked correspond to\nthe likelihood of being on a given page:\n\n\\begin{minted}{python}\n>>> nx.pagerank(G, alpha=1)\n{0: 0.11988980099060496,\n 1: 0.11337734639341283,\n 2: 0.09229073511280955,\n 3: 0.08488079369061019,\n 4: 0.12554165518523688,\n 5: 0.09448445809607922,\n 6: 0.09608526108105925,\n 7: 0.09314704994034195,\n 8: 0.09384213164925923,\n 9: 0.08646076786058658}\n\\end{minted}\n\n\\section{Using linear algebra}\n\nWe will normalise \\(A\\) to create a new matrix \\(M\\) such that the rows all add\nto one (so each row give a probability of going to the next page):\n\n\\begin{minted}{python}\n>>> row_sums = A.sum(axis=1)\n>>> M = A / row_sums[:, np.newaxis]\n>>> np.round(M, 2)\narray([[0.  , 0.12, 0.12, 0.  , 0.12, 0.12, 0.12, 0.12, 0.12, 0.12],\n       [0.33, 0.  , 0.  , 0.33, 0.  , 0.  , 0.  , 0.  , 0.  , 0.33],\n       [0.  , 0.17, 0.17, 0.  , 0.  , 0.17, 0.17, 0.17, 0.17, 0.  ],\n       [0.17, 0.  , 0.17, 0.  , 0.17, 0.17, 0.  , 0.17, 0.17, 0.  ],\n       [0.  , 0.14, 0.  , 0.14, 0.14, 0.14, 0.14, 0.14, 0.  , 0.14],\n       [0.  , 0.17, 0.17, 0.17, 0.17, 0.  , 0.17, 0.  , 0.  , 0.17],\n       [0.33, 0.  , 0.33, 0.  , 0.33, 0.  , 0.  , 0.  , 0.  , 0.  ],\n       [0.2 , 0.2 , 0.  , 0.  , 0.  , 0.2 , 0.2 , 0.  , 0.2 , 0.  ],\n       [0.  , 0.14, 0.  , 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.  ],\n       [0.2 , 0.2 , 0.  , 0.  , 0.2 , 0.  , 0.  , 0.2 , 0.2 , 0.  ]])\n\\end{minted}\n\nUsing this, we can raise \\(M\\) to a large power to see the long run probability\ngiven starting in any given page.\n\n\\begin{minted}{python}\n>>> np.round(np.linalg.matrix_power(M, 2000000), 2)\narray([[0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09],\n       [0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09]])\n\\end{minted}\n\nWe see that all the rows of \\(M ^ {2000000}\\) are equal and actually correspond to\nthe values computed using networkx's Page rank.\n\nInterestingly, this set of probabilities can actually be obtained by finding the\nright eigenvector of \\(M^{T}\\):\n\n\\begin{minted}{python}\n>>> e_values, e_vectors = np.linalg.eig(M.T)\n>>> np.real(np.round(e_vectors[:,0] / sum(e_vectors[:,0]), 2))\narray([0.12, 0.11, 0.09, 0.08, 0.13, 0.09, 0.1 , 0.09, 0.09, 0.09])\n\\end{minted}\n\n\\section{Conclusion}\n\nThe first version of Google's search engine was in fact based on a building\nblock of linear algebra and graph theory. There are some modifications that\nneeded to be done to deal with the fact that the internet is not always\ncompletely connected, this corresponds to the \\texttt{alpha} argument in the\nnetworkx function above.\n\n\\bibliographystyle{plain}\n\\bibliography{bibliography.bib}\n\n\\end{document}\n", "meta": {"hexsha": "649a0d9dfd7523bee4a6e82f0e71c9d3901904e8", "size": 5821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/rsc/page-rank/main.tex", "max_stars_repo_name": "geraintpalmer/cfm", "max_stars_repo_head_hexsha": "fa3f98cf45b225015f28be461e8ae661fa966b61", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/rsc/page-rank/main.tex", "max_issues_repo_name": "geraintpalmer/cfm", "max_issues_repo_head_hexsha": "fa3f98cf45b225015f28be461e8ae661fa966b61", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/rsc/page-rank/main.tex", "max_forks_repo_name": "geraintpalmer/cfm", "max_forks_repo_head_hexsha": "fa3f98cf45b225015f28be461e8ae661fa966b61", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0662650602, "max_line_length": 82, "alphanum_fraction": 0.6162171448, "num_tokens": 2499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.6794225906483975}}
{"text": "\\subsection{Algebraic dual spaces}\\label{subsec:algebraic_dual_spaces}\n\n\\begin{definition}\\label{def:dual_vector_space}\n  Let \\( V \\) be a vector space over \\( F \\). The \\hyperref[thm:functions_over_ring_form_algebra]{vector space} of all \\hyperref[def:linear_operator]{linear functions} from \\( V \\) to \\( F \\) is called the \\term{algebraic dual space} of \\( V \\) and is denoted by \\( V^* \\). The functions themselves are called \\term{linear functionals}.\n\\end{definition}\n\n\\begin{definition}\\label{def:canonical_duality_pairing}\n  We denote by \\( \\inprod \\cdot \\cdot \\) the \\term{canonical \\hyperref[def:duality_pairing]{duality pairing}}\n  \\begin{balign*}\n     & \\inprod \\cdot \\cdot: V^* \\times X \\to \\BbbK \\\\\n     & \\inprod {x^*} x \\mapsto x^*(x).\n  \\end{balign*}\n\n  We are usually not interested in other duality pairings. See \\fullref{def:locally_convex_duality_pairing}, however.\n\\end{definition}\n\n\\begin{definition}\\label{def:double_dual_canonical_embedding}\n  Fix a vector space \\( V \\). We define the \\term{canonical embedding} into the double dual \\( V^{**} \\) of \\( V \\) by\n  \\begin{balign*}\n     & \\Phi: V \\to V^{**}                              \\\\\n     & \\Phi(x) \\coloneqq (\\varphi \\mapsto \\varphi(x)),\n  \\end{balign*}\n  where \\( \\varphi \\in V^* \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:finite_dimensional_dual_space_is_isomorphic}\n  The dual vector space of a finite-dimensional vector space has the same dimension.\n\\end{proposition}\n\\begin{proof}\n  Let \\( V \\) be an \\( n \\)-dimensional vector space over \\( F \\) and let \\( B \\) be a basis of \\( V \\). For each \\( b \\in B \\), define its dual vector on \\( V^* \\) as the linear \\hyperref[thm:linear_map_iff_function_on_basis]{extension} of the functions\n  \\begin{balign*}\n     & \\varphi: B \\to F                               \\\\\n     & \\varphi(x) \\coloneqq \\begin{cases}\n      1, & x = b    \\\\\n      0, & x \\neq b\n    \\end{cases}\n  \\end{balign*}\n  from the basis to the whole space. Denote the dual basis vector of \\( b \\) by \\( b^* \\).\n\n  We will now show that the set \\( B^* \\coloneqq \\{ b^* \\colon b \\in B \\} \\) forms a basis of \\( V^* \\).\n\n  Fix \\( x^* \\in V^* \\). Define\n  \\begin{equation*}\n    y^* \\coloneqq \\sum_{b \\in B} x^*(b) b^*.\n  \\end{equation*}\n\n  The linear functions \\( x^* \\) and \\( y^* \\) evidently agree on the basis \\( B \\). By \\fullref{thm:linear_maps_agree_on_free_module_if_they_agree_on_basis}, they agree on the whole space.\n\n  Hence, \\( B^* \\) is a basis of \\( V^* \\). Note that it has the same cardinality as the basis of \\( B \\).\n\\end{proof}\n\n\\begin{remark}\\label{rem:finite_dimensional_dual_space_isomorphism}\n  By \\fullref{thm:finite_dimensional_spaces_are_isomorphic}, the vector space \\( F^n \\) is isomorphic to its dual \\( {F^n}^* \\).\n\n  In practice, it is sometimes useful to distinguish between vectors and functionals. This is why we regard functionals as either\n  \\begin{itemize}\n    \\item functions\n    \\item column vectors\n    \\item row vectors\n  \\end{itemize}\n  depending on what interpretation suits us best.\n\n  This is consistent with \\fullref{thm:finite_dimensional_operators_are_isomorphic_to_matrices}, where we regard linear operators as matrices that act on vectors by multiplication.\n\n  For example, if we have the \\hyperref[def:differentiability]{differentiable} function \\( f(x, y) = xy \\), we can regard its gradient at the point \\( (\\overline x, \\overline y) \\) as the row vector\n  \\begin{balign*}\n    f'(\\overline x, \\overline y) =\n    \\begin{pmatrix}\n      \\overline y & \\overline x\n    \\end{pmatrix}.\n  \\end{balign*}\n\n  This is a linear functional that can acts on regular (column) vector by multiplying them from the left.\n\\end{remark}\n\n\\begin{definition}\\label{def:dual_linear_operator}\n  We define the \\term{dual linear operator} of \\( L: U \\to V \\) as\n  \\begin{balign*}\n     & L^*: V^* \\to U^*                \\\\\n     & L^*(v^*) \\coloneqq v^* \\circ L.\n  \\end{balign*}\n\\end{definition}\n\n\\begin{definition}\\label{def:vector_space_annihilator}\\mcite[52]{Knapp2016BasicAlgebra}\n  Annihilators in vector spaces are quite different than annihilators in modules (see \\fullref{def:left_module_annihilator}).\n\n  Fix a subset \\( S \\subseteq V \\) of a vector space \\( V \\) over \\( F \\). We define the \\term{annihilator} of \\( S \\) as the vector space of functionals\n  \\begin{equation*}\n    \\op{ann}(S) \\coloneqq \\{ x^* \\in V^* \\colon x^*(x) = 0_F \\quad\\forall x \\in S \\}.\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "cfecfb5a61a9c8b8af44459b18334e26e7d55c0f", "size": 4429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/algebraic_dual_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/algebraic_dual_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/algebraic_dual_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": 48.1413043478, "max_line_length": 336, "alphanum_fraction": 0.6683224204, "num_tokens": 1373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893520001, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.67935328764903}}
{"text": "\\chapter{Constructions}\r\n\\section {Semidirect Product}\r\n{\\bf Definition 3:}\r\n$G$ is an \\emph{extension} of $K$ by $Q$ if $G \\triangleright K$ and $G/K \\cong Q$.  Equivalently,\r\nthere is a surjective homomorphism $\\pi:G \\rightarrow Q$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 1:} \r\nLet $\\pi: A \\rightarrow Aut(K)$, $K \\lhd G$, $H<G$ and $H \\cap K = 1$ define the\r\n\\emph {semi-direct} product of $K$ by $H$ as the group who's elements\r\nare $(a,b) \\in H \\times K$ with the product $(a, g) \\cdot (b,h)= (ab, \\pi(b)(g)h)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 2:} An extension $G$ of $K$ by $H$ \\emph {splits} if G\r\nis a semi-direct product of $H$ and $K$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 1:}\r\nIf $1 \\rightarrow N \\rightarrow_{i} G \\rightarrow_{\\varphi} Q \\rightarrow 1$, the following\r\nare equivalent\r\n(1) $\\exists H \\subseteq G$ such that $\\varphi: H \\rightarrow Q$ is an isomorphism;\r\n(2) $\\exists s:Q \\rightarrow G$ such that $\\varphi \\cdot s = id$;\r\n(3) $G$ is a semi-direct product of $N$ by $H$ written $N \\ltimes Q$; in this\r\ncase, we say $G$ is a split extension of $N$ by $H$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n$1 \\rightarrow 2$:\r\nPut $s= \\varphi_{|H}^{-1}$, then (2) holds.\r\n\\\\\r\n\\\\\r\n$2 \\rightarrow 3$:\r\nLet $H= s(Q)$, $N= ker(\\varphi)$.  Suppose $x \\in G$ and $q= \\varphi(x)$.  Set\r\n$h= s(q)$.  $\\varphi(x h^{-1})= \\varphi(x) \\varphi(h)^{-1} = q q^{-1}= 1$ so\r\n$x h^{-1} \\in N$ and $x= nh$.\r\n\\\\\r\n\\\\\r\n$3 \\rightarrow 1$:\r\nIf $G= N \\ltimes H$, the map $\\varphi_{|H}$ is an isomorphism onto $Q$ and $H$ satisfies the\r\nconditions of (1).\r\n\\end{quote}\r\n\\section {Presentations}\r\n{\\bf Theorem 2:}  Let $G= \r\n\\langle x_1, \\ldots, x_n| R_1(x_1, \\ldots, x_n), R_2(x_1, \\ldots, x_n), \\ldots R_m(x_1, \\ldots, x_n)\r\n\\rangle\r\n$. There is a one to one correspondance between homomorphisms\r\n$\\rho: G \\rightarrow H$ and solutions to \r\n$R_1(y_1, \\ldots, y_n)=1, R_2(y_1, \\ldots, y_n)=1, \\ldots R_m(y_1, \\ldots, y_n)=1, y_i \\in H$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 3:}  Two groups are isomorphic iff they admit the same presentation up to renaming.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 4:}  Let $G \\cong F/R$, $F$, free.  Then for arbitrary abelian $A$, the transgression map\r\n$Hom(R/[F,R],A) \\rightarrow H^2(G,A)$ is associated with the natural exact sequence\r\n$1 \\rightarrow R/[F,R] \\rightarrow F/[F, R] \\rightarrow G \\rightarrow 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Projective representations and Schur:} Let $\\rho: G \\rightarrow GL_n({\\mathbb C})/{\\mathbb Z}$\r\nso that $\\rho(g)$ is a coset $\\pmod {\\mathbb Z}$.  Choose $A(g) \\in \\rho(g)$ then\r\n$\\rho(ab)= r_{a,b} \\rho(a) \\rho(b)$ and $r_{a,b} r_{ab,c}= r_{a, bc} r_{b,c}$ (cocycle identity).\r\nConversely, given an $r$ satisfying the cocycle identity, there is a projective representation\r\nof degree $|G|=m$ giving rise to it.  If $B(g) \\in \\rho(g)$ is another, $A(g)= d_g B(g)$, and\r\nif $B(ab)= s_{a,b}B(a)B(b)$, $r_{a,b}= {\\frac {d_a d_b} {d_{ab}}} s_{a,b}$ (Relation 1).\r\nIf $r, s$ satisfy relation 1, they are called \\emph{equivalent}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 5:} Let $\\rho^*: H \\rightarrow GL_n({\\mathbb C})$ be an ordinary irreducible\r\nrepresentation of $H$ with $A \\le {\\mathbb Z}(H)$ then $\\rho^*(a)= j_a I_n$ and we can\r\ndefine $\\rho: H/A \\rightarrow GL_n({\\mathbb C})/{\\mathbb Z}$ by\r\n$\\rho(hA)= \\rho^*(h) {\\mathbb Z}$.  Schur showed the converse: \r\n$\\exists H: A \\le {\\mathbb Z}(H)$ with $H/A \\cong G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n\\end{quote}\r\nNote that if $G= \\langle F|R \\rangle $ is of rank $k$, \r\n$(F/[F,R])/(R/[F,R])= G$ and $R/[F,R]$ is central.\r\n\\section {Central Product}\r\n{\\bf Definition of Central Product:} \r\n$G= \\langle G_i \\rangle , 1 \\le i \\le n$, $[G_i , G_j ]=1$ for $i \\ne j$.  Equivalently,\r\n$\\rho: (x_1, x_2, \\ldots , x_n) \\mapsto x_1 x_2 \\ldots x_n$ is a surjective homomorphism\r\nfrom $D= (G_1 \\times G_2 \\times \\ldots \\times G_n)$ to $G$ with $\\rho(D_i) = G_i$ with\r\n$\\pi_i (G_1, \\ldots , G_n)= D_i$ and $ker(\\rho) \\cap D_i = 1$, $ker(\\rho) \\subseteq {\\mathbb Z}(G)$.\r\n\\begin{quote}\r\n\\emph{Proof of equivalence:} \r\nLet $\\alpha_i: {\\mathbb Z}(G_1) \\rightarrow {\\mathbb Z}(G_i)$.\r\n$E= \\langle z(\\alpha_i(z^{-1})) \\rangle $.  $E$ is a complement to ${\\mathbb Z}(D_i )$ in\r\n$Z= \\langle {\\mathbb Z}(D_i) \\rangle $ so $D/E$ is a central product.  Suppose $G$ is a\r\ncentral product of the $G_i$ with ${\\mathbb Z}(G_i)={\\mathbb Z}(G_1)$ and $\\rho$ the surjective\r\nhomomorphism.  Let $\\beta_i:{\\mathbb Z}(D_1) \\rightarrow {\\mathbb Z}(G_i)$ be the composition of\r\n$\\rho_{|{\\mathbb Z}(D_1)}$ and \r\n$\\rho_{|{\\mathbb Z}(D_i)}^{-1}: {\\mathbb Z}(G_1) \\rightarrow {\\mathbb Z}(D_i)$ then\r\n$ker(\\rho)= \\langle x \\beta_i(z^{-1}), z \\in {\\mathbb Z}(D_1) \\rangle = A$ is a complement\r\nto ${\\mathbb Z}(D_i)$ in $Z$ and $G \\cong D/A$.  Define $\\gamma \\in Aut(D)$ with $\\gamma(D_1)=D_i$\r\nand $\\gamma(E)=A$.  This induces and isomorphism of $D/E$ with $D/A$.  Let \r\n$\\delta_i= \\beta_i (\\alpha_i)^{-1}$ then $\\gamma_{i|{\\mathbb Z}(D_i)}= \\delta_i$ and\r\ndefine $\\gamma: D \\rightarrow D$ by $(x_1, x_2 , \\ldots , x_n) \\mapsto (x_1, \\gamma_1(x_2), \\ldots,\r\n\\gamma_n(x_n))$.\r\n\\end{quote}\r\n{\\bf Example:}\r\nBoth $D_8$ and\r\n$Q_8$ are central products of $Z_2$ by $Z_2 \\times Z_2$.  Note that $D_8$ is also a direct product but $Q_8$\r\nis not.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 6:}\r\nLet $G_i, 1 \\le i \\le n$ be a family of groups with $Z(g_1)=Z(G_i)$ and\r\n$Aut_{G_i}(Z(G_i))=Aut(Z(G_i))$.  The up to isomorphism there is a unique\r\ncentral product with $Z(G_1)=Z(G_i)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy hypothesis, there are isomorphisms \r\n$\\alpha_i : {\\mathbb Z}( D_1 ) \\rightarrow {\\mathbb Z}( D_i )$, $1 \\le i \\le n$.\r\nLet $E$ be the subgroup of $D$ generates by $\\{ \\alpha_i (z^{-1})z, z \\in {\\mathbb Z}(D_1 )$.\r\n$E$ is a complement to \r\n${\\mathbb Z}(D_i)$ in $Z= \\langle {\\mathbb Z}(D_i), 1 \\le i \\le n \\rangle = {\\mathbb Z}(D)$ so\r\n$D/E$ is a central product of the $G_i$ with ${\\mathbb Z}(G_1 ) = {\\mathbb Z}(G_i )$ by\r\nthe foregoing equivalence.  Now suppose $G$ is a central product of the $G_i$ with\r\n${\\mathbb Z}(G_1 ) = {\\mathbb Z}(G_i )$ and let $\\pi: D \\rightarrow G$ be the surjective\r\nhomomorphism in the equivalence proof.  \r\nLet $\\beta_i : {\\mathbb Z}(D_1 ) \\rightarrow {\\mathbb Z}(D_i )$ be the composition of\r\n$\\pi_{|{\\mathbb Z}(D_1 )}$ and $\\pi_{|{\\mathbb Z}(D_i )}^{-1}$.\r\n$ker(\\pi ) = \\langle z \\beta_i(Z^{-1} ): z \\in {\\mathbb Z}(D_1 ), 1 \\le i \\le n \\rangle\r\n= A$ is a complement\r\nto ${\\mathbb Z}(D_i )$ in $Z$ for each $i$ and $G \\cong D/A$.  Now let \r\n$\\delta_i = \\beta_i \\alpha_i^{-1}$ and $\\delta_i \\in Aut({\\mathbb Z}(D_i ))$.  By\r\nhypothesis, $\\exists \\gamma_i \\in Aut( D_i )$ with $\\gamma_{i | {\\mathbb Z}(D_i )}= \\delta_i$.\r\nDefine $\\gamma : D \\rightarrow D$ by \r\n$(x_1 , x_2 , \\ldots , x_n ) \\mapsto\r\n(x_1 , \\gamma_2(x_2), \\ldots , \\gamma_n(x_n))$.  $\\gamma \\in Aut(D)$ and\r\n$\\alpha_i(\\gamma (z^{-1})) z$ so $\\gamma(E)=A$ and we're done.\r\n\\end{quote}\r\n\\section {Wreath Product}\r\n{\\bf Wreath Product:} $G^*= G^{X}$ - maps from $X$ to $G$.  $fg(x)= f(x) g(x)$.\r\nLet $H$ act on $X$: $f^h(x)= f(xh^{-1})$.  Let $\\phi$ be the natural action of\r\n$H$ induced on $G^{|H|}$, then $G \\wr H = H \\rtimes_{\\phi} G^*$. If $G_x =\r\n\\{f: f(y)= 1 \\; if \\; x \\ne y \\}$.  $G^* = \\prod_X G_x$.\r\nPut $g_x (y)= g (y)$ if $x=y$, 1 otherwise.  Note that\r\n${g_x}^h= g_{xh}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 7:} If $D$ and $Q$ are groups with $Q$ finite then the regular wreath product\r\n$D \\wr_r Q$ contains an isomorphic copy of every extension of $D$ by $Q$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $G$ is an extension of $D$ by $Q$ then there is a surjective homomorphism\r\n$G \\rightarrow Q$ with kernel $D$ denoted by $a \\mapsto {\\overline a}$.\r\nChoose a transversal $l: Q \\rightarrow G$.  For $a \\in G$, define \r\n$\\sigma_a(x) = l(x)^{-1} a l({\\overline {a^{-1}}} x)$.  \r\nIf $a, b \\in G$ then\r\n$\r\n\\sigma_a(x) \\sigma_b^{\\overline a}(x) =\r\n\\sigma_a(x) \\sigma_b({\\overline {a^{-1}}} x) =\r\nl(x)^{-1} a l({\\overline {a^{-1}}} x)\r\nl(x)^{-1} a l({\\overline {a^{-1}}} x)\r\nl({\\overline {a^{-1}}} x)^{-1} b l({\\overline { b^{-1} a^{-1}}} x) =\r\nl(x)^{-1} a b l({\\overline { b^{-1} a^{-1}}} x) = \\sigma_{ab}(x)$.  \r\nDefine $\\varphi : G \\rightarrow D \\wr_r Q$ by \r\n$\\varphi(a) = (\\sigma_a, {\\overline a}), \\forall a \\in G$.  A simple calculation shows\r\n$\\varphi$ is a injective homomorphism.\r\n\\end{quote}\r\n", "meta": {"hexsha": "2e37ec2352ba163e6646da29c9741abf19398220", "size": 8142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtConstruct.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/gtConstruct.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/gtConstruct.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.9509202454, "max_line_length": 109, "alphanum_fraction": 0.599975436, "num_tokens": 3213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893519999, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6793532876490298}}
{"text": "%lecture 5\n\n\\subsection{Fixed point theory} \n\\label{sub:fixed_point_theory}\n\\begin{beispiel}\n\tConsider\n\t\\[\n\t\tf(x)+ 5 \\int_{0}^{1-x} \\min(x,y)f(y) \\,\\mathrm{d}y = g(x), \\qquad x \\in [0,1] \\qquad (*)\n\t\\]\n\twhere $g \\in C([0,1])$. \\\\ \n\t\\textbf{Claim:} \\text{    }     There exists an unique solution $f \\in C([0,1])$ that $(*)$. \\\\\n\tIdea:\n\t\\[\n\t\tf(x) = f(x) - 5 \\int_{0}^{1-x} \\min(x,y)f(y) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\t\\]\n\tSet for $x \\in [0,1]$ \n\t\\[\n\t\t\t\\tilde T(f)(x) = RHS(x).\n\t\\]\n\tTo find a solution to $(*)$ is the same finding $f \\in C([0,1])$ such that \n\t\\[\n\t\tf = \\tilde T(f).\n\t\\]\n\tClearly $ \\tilde T : C([0,1]) \\to C([0,1])$. (continual later).\n\\end{beispiel}\n\n\\begin{theorem}[Banach's fixed point theorem]\n\t$(E, \\norm{.})$ Banach space. $T: E \\to E$ (no assumption on linearity) is a contraction on $E$, i.e. there exists $c<1$ such that\n\t\\[\n\t\t\\norm{T(x)-T(\\tilde x)} \\leq c \\norm{x- \\tilde x} \\qquad \\text{for all }x,\\tilde x \\in E.\n\t\\]\n\tThen there exists a unique $ \\bar{x} \\in E$ such that \n\t\\[\n\t\t\\bar{x} = T( \\bar{ x}).\n\t\\]\n\t($\\bar{x}$ is a fixed point)\n\\end{theorem}\n\\begin{beweis}\n\t\\begin{description}\n\t\t\\item[Uniqueness:]Assume $T( \\bar{x}) = \\bar{x}$ and $T ( \\tilde x) = \\tilde x$. Then\n\t\t\\[\n\t\t\t\\underset{\\geq 0}{\\underbrace{\\norm{ \\bar{ x} - \\tilde x }}} = \\norm{T( \\bar{x})- T( \\tilde x)} \\leq \\underset{< 1}{\\underbrace{c}} \\norm{ \\bar{x}- \\tilde x}.\n\t\t\\] \n\t\tThus $\\norm{\\bar{x}- \\tilde x} = 0$, i.e. $\\bar{x} = \\tilde x$.\n\t\t\\item[Existence:] Pick an arbitrary $x_0 \\in E$. Set\n\t\t\\[\n\t\t\tx_{n+1} = T(x_{n}), \\qquad n=0,1,2,\\dots.\n\t\t\\]\n\t\t\\textbf{Claim:} \\text{    }     $(x_n)_{n=1}^{\\infty}$ is a Cauchy sequence in $(E,\\norm{.})$.\n\t\tNote:\n\t\t\\begin{align*}\n\t\t\t\\norm{x_{n+1}-x_n}  &= \\norm{T(x_n)-T(x_{n-1})} \\\\\n\t\t\t&\\leq  c \\norm{x_n - x_{n-1}} \\\\\n\t\t\t&\\leq \\dots \\\\\n\t\t\t&\\leq  c^n \\norm{x_1-x_0}, \\qquad n=1,2,\\dots.\n\t\t\\end{align*}\n\t\tFor $n>m$\n\t\t\\begin{align*}\n\t\t\t\\norm{x_n-x_m} &= \\norm{x_n - x_{n-1}+ x_{n-1}- \\dots + x_{m+1}- x_m} \\\\\n\t\t\t&\\leq \\norm{x_n - x_{n-1}} + \\norm{x_{n-1} - x_{n-2}} + \\dots + \\norm{x_{m+1}- x_m} \\\\\n\t\t\t&\\leq (c^{n-1}+ c^{n-2} + \\dots c^m) \\norm{x_1-x_0} \\\\\n\t\t\t&\\leq \\frac{c^m}{1-c} \\norm{x_1 - x_0} \\to 0 \\qquad \\text{as }n,m \\to \\infty.\n\t\t\\end{align*}\n\t\tHence $(x_n)_{n=1}^{\\infty}$ is a Cauchy sequence in $(E,\\norm{.})$. $(E, \\norm{.})$ is a Banach space. So $(x_n)_{n=1}^{\\infty}$ converges in $(E,\\norm{.})$. Call the limit $\\bar{x}$. \\\\\n\t\t\\textbf{Claim:} \\text{    }     $\\bar{x}$ is a fixed point for $T$. \n\t\t\\begin{align*}\n\t\t\t\\norm{\\bar{ x}- T(\\bar{x})} & = \\norm{\\bar{x}-x_{n+1}+ x_{n+1} - T(\\bar{x})} \\\\\n\t\t\t&\\leq \\norm{\\bar{x}-x_{n+1}} + \\norm{\\underset{T(x_n)}{\\underbrace{x_{n+1}}} - T(\\bar{x})} \\\\\n\t\t\t&\\leq \\underset{\\to 0}{\\underbrace{\\norm{\\bar{x}- x_{n+1}}}} + c \\underset{\\to 0}{\\underbrace{\\norm{x_n - \\bar{x}}}} \\to 0, \\qquad n \\to \\infty\n\t\t\\end{align*}\n\t\\end{description}\n\\end{beweis}\n\\begin{bemerkung}\n\t\\begin{enumerate}[(1)]\n\t\t\\item $x_n \\to \\bar{x}$ for $n \\to \\infty$ independend of the choice of $x_0$\n\t\t\\item Fix $z \\in E$\n\t\t\\begin{align*}\n\t\t\t\\norm{\\bar{x}-z} &= \\norm{T(\\bar{x})- T(z) + T(z) -z} \\\\\n\t\t\t&\\leq \\norm{T(\\bar{x})-T(z)} + \\norm{T(z) -z} \\\\\n\t\t\t&\\leq c \\norm{\\bar{x}-z} + \\norm{T(z) - z}.\n\t\t\\end{align*}\n\t\tHence \n\t\t\\[\n\t\t\t\\norm{\\bar{x}-z} \\leq \\frac{1}{1-c}\\norm{T(z)-z}.\n\t\t\\]\n\t\\end{enumerate}\n\\end{bemerkung}\n\\begin{beispiel}\n\tConsider now the example from above: $(C([0,1]), \\norm{.})$ with $\\norm{f} = \\max_{x \\in [0,1]}\\abs{f(x)}$ is a Banach space! To apply Banach's fixed point theorem we need $\\tilde T$ to be a contraction. \\\\\n\tFix $f_1,f_2 \\in C([0,1])$ and get for $x \\in [0,1]$\n\t\\begin{align*}\n\t\t\\abs{(\\tilde T(f_1)- \\tilde T(f_2))(x)} & = \\abs{5 \\int_{0}^{1-x} \\min(x,y)f_2(y) \\,\\mathrm{d}y - 5 \\int_{0}^{1-x}\\min(x,y)f_1(y) \\,\\mathrm{d}y} \\\\\n\t\t&= \\abs{5 \\int_{0}^{1-x} \\min(x,y)(f_2(y)-f_1(y)) \\,\\mathrm{d}y} \\\\\n\t\t&\\leq 5 \\int_{0}^{1-x} \\min(x,y) \\underset{\\leq \\norm{f_2-f_1}}{\\underbrace{\\abs{f_2(y)-f_1(y)}}} \\,\\mathrm{d}y \\\\\n\t\t&\\leq 5 \\underset{0 \\leq  \\dots \\leq \\frac{1}{6}}{\\underbrace{\\int_{0}^{1-x} \\min(x,y)\\,\\mathrm{d}y}} \\norm{f_2-f_1} \\\\\n\t\t&\\leq \\frac{5}{6} \\norm{f_2-f_1}.\n\t\\end{align*}\n\tHence \\[\n\t\t\\norm{\\tilde T(f_1)- \\tilde T(f_2)} \\leq \\frac{5}{6} \\norm{f_1-f_2}.\n\t\\]\n\tWe conclude that $\\tilde T$ is a contraction. We can take $c = \\frac{5}{6}$. By Banach's fixed point theorem $\\tilde T$ has a unique fixed point. Finally $(*)$\n\thas a unique solution $f \\in C([0,1])$ which is the fixed point. \n\\end{beispiel}\n\\begin{theorem}[Banach's fixed point theorem (generalization)]\n\t$(E, \\norm{.})$ Banach space. $T: F \\to F$ where $F$ is a closed set in $E$. $N$ positive integer. Assume $T^N = \\underset{N-\\text{times}}{\\underbrace{T \\circ T \\circ \\dots \\circ T}}$ is a contraction on $F$, i.e. there exists $c > 1$ such that\n\t\\[\n\t\t\\norm{T^N(x)- T^N(\\tilde x)} \\leq c \\norm{x-\\tilde x}, \\qquad \\text{for all }x, \\tilde x \\in F.\n\t\\]\n\tThen $T$ has unique fixed point $\\bar{ x}$, i.e.\n\t\\[\n\t\t\\bar{x} = T(\\bar{x}) \\in F.\n\t\\]\n\\end{theorem}\n\\begin{beweis}\n\t\\begin{description}\n\t\t\\item[$N=1$:] Fix $x_0 \\in F$ and consider $(x_n)_{n=1}^{\\infty}$ where $x_{n+1} = T(x_n)$ for $n=0,1,2, \\dots$. There $(x_n)_{n=1}^{\\infty}$ is a Cauchy sequence and hence this converges in $E$ since this is a Banach space. Call the limit $\\bar{x}$. Note\n\t\t\\[\n\t\t\t\\underset{\\in F}{\\underbrace{x_n}} \\to \\bar{x} \\text{ in }E \\text{ and $F$ is closed}\n\t\t\\] \n\t\timplies $\\bar{x} \\in F$. The rest of the argument is the same as before.\n\t\t\\item[$N>1$:] By previous result we know that $T^N$ has a unique fixed point $\\bar{x} \\in F$, i.e. $\\bar{x} = T^N(\\bar{x})$. \\\\\n\t\t\\textbf{Claim:} \\text{    }     $\\bar{x}$ is a fixed point for $T$.\n\t\t\\begin{align*}\n\t\t\t\\norm{T(\\bar{x})-\\bar{x}} &= \\norm{T(T^N(\\bar{x}))- T^N(\\bar{x})} \\\\\n\t\t\t&= \\norm{T^N(T(\\bar{x}))- T^N(\\bar{x})} \\\\\n\t\t\t&\\leq c \\norm{T(\\bar{x})-\\bar{x}}.\n \t\t\\end{align*}\n\t\tThis gives \n\t\t\\[\n\t\t\t\\norm{T(\\bar{x}-\\bar{x})} = 0, \\qquad \\text{i.e. }\\bar{x} = T(\\bar{x}).\n\t\t\\]\n\t\tExistence of a fixed point for $T$ done. For the uniqueness assume $\\bar{x} = T(\\bar{x})$ and $\\tilde x = T( \\tilde x)$. Then\n\t\\begin{align*}\n\t\t\\bar{x} &= T( \\bar{x}) = T^2(\\bar{x}) = \\dots = T^N(\\bar{x}) \\\\\n\t\t\\tilde x &= T(\\tilde x) = T^2(\\tilde x) = \\dots = T^N(\\tilde x).\n\t\\end{align*}\n\tBut $T^N$ has a unique fixed point so \n\t\\[\n\t\t\\bar{x} = \\tilde x.\n\t\\]\n\t\\end{description}\n\\end{beweis}\n\\begin{bemerkung}\n\t\\begin{enumerate}[(1)]\n\t\t\\item $T: (0,1] \\to (0,1]$ where $T(x) = \\frac{x}{2}$. Clearly $T$ is a contraction on $(0,1]$ but has no fixed point. Note that $(0,1]$ is not a closed intervall. \n\t\t\\item $T: [0,\\infty) \\to [0,\\infty)$, where $T(x) = x + \\frac{1}{x}$. Clearly $[0,\\infty)$ is a closed intervall in $\\mathbb{R}$ but $T$ has no fixed point. \\\\\n\t\t\\textbf{Claim:} \\text{    }     $T$ is not a contraction but 'close' to be a contraction. \\\\\n\t\t\\begin{align*}\n\t\t\t\\abs{T(x)-T(\\tilde x)} < \\abs{x- \\tilde x} \\qquad \\text{for }x, \\tilde x \\in [1, \\infty), x \\neq \\tilde x\n\t\t\\end{align*}\n\t\tNote \\[\n\t\t\t\\abs{ T(x)- T( \\tilde x)} = \\abs{\\underset{\\substack{(1- \\frac{1}{t})\\leq 1 \\\\ \\text{for }t \\in [1,\\infty)}}{\\underbrace{T'(x)}}}\\abs{x- \\tilde x}\n\t\t\\] for some $t$ betweeen $x$ and $\\tilde x$.\n\t\\end{enumerate}\n\\end{bemerkung}\n\\begin{beispiel}\n\t$(E,\\norm{.})$ Banach space. $K$ compact set in $E$ and $T : K \\to K$ where\n\t\\[\n\t\t\\norm{T(x)- T( \\bar{x})} < \\norm{x - \\bar{x}} \\qquad \\text{for all }x, \\bar{x} \\in K, x \\neq \\bar{x}.\n\t\\]\n\tShow: $T$ has a unique fixed point in $K$.\n\t\\begin{description}\n\t\t\\item[Uniqueness:] Assume $\\bar{x} = T(\\bar{x})$ and $\\tilde x = T( \\tilde x)$ and $\\bar{x} \\neq \\tilde x$ for $ \\bar{x}, \\tilde x \\in K$. Then\n\t\t\\[\n\t\t\t\\norm{\\bar{x} - \\tilde x} = \\norm{ T( \\bar{ x})- \\tilde x} < \\norm{ \\bar{x}- \\tilde x}.\n\t\t\\]\n\t\tContradiction because then $\\bar{x} = \\tilde x$.\n\t\t\\item[Existence:] To show: There exists $x \\in K$ such that $x = T(x)$, i.e.\n\t\t\\[\n\t\t\t\\norm{T(x)- x} = 0.\n\t\t\\]\n\t\tSet $d := \\inf_{x \\in K} \\norm{T(x)-x}$. Let $(x_n)_{n=1}^{\\infty}$ be a sequence in $K$ such that \n\t\t\\[\n\t\t\t\\norm{T(x_n)-x_n} \\to d, \\qquad \\text{as }n \\to \\infty.\n\t\t\\]\n\t\t$K$ compact implies that there exists a subsequence $(\\tilde x_n)_{n=1}^{\\infty}$ of $(x_n)_{n=1}^{\\infty}$ such that $(\\tilde x_n)_{n=1}^{\\infty}$ converges in $K$. Call the limit element $\\bar{x} \\in K$. We know\n\t\t\\[\n\t\t\t\\tilde x_n \\to  \\bar{x} \\qquad \\text{in }K\n\t\t\\]\n\t\tand\t \n\t\t\\[\n\t\t\t\\norm{T( \\tilde x_n)- \\tilde x_n} \\to d.\n\t\t\\]\n\t\tQuestion: \\[\n\t\t\tT(\\tilde x_n) \\to T(\\bar{x}) \\qquad \\text{ in }K?\n\t\t\\]\n\t\tBut since\n\t\t\\[\n\t\t\t\\norm{T(x)- T( \\tilde x)} \\leq  \\norm{x- \\tilde x} \\qquad \\text{ for all }x, \\tilde x \\in K\n\t\t\\]\n\t\twe have \n\t\t\\[\n\t\t\t\\tilde x_n \\to \\bar{x} \\qquad \\text{ in }K\n\t\t\\]\n\t\twhich implies\n\t\t\\[\n\t\t\tT( \\tilde x_n) \\to T( \\bar{ x}) \\text{ in }K.\n\t\t\\]\n\t\tHence: \n\t\t\\[\n\t\t\t\\norm{T( \\bar{ x})- \\bar{x}} \\leftarrow \\norm{T(\\tilde x_n)- \\tilde x_n} \\to d, \\qquad  n \\to  \\infty.\n\t\t\\]\n\t\tWe obtain\n\t\t\\[\n\t\t\t\\norm{T(\\bar{x})- \\bar{x}} = d.\n\t\t\\]\n\t\tQuestion: Is $d=0$? \\\\\n\t\tIf $d>0$ then $\\bar{x} \\neq  T( \\bar{x})$, $\\bar{x}, T( \\bar{x}) \\in K$\n\t\t\\[\n\t\t\t\\norm{T(\\bar{x})- T(T(\\bar{x}))} < \\norm{\\bar{x}- T(\\bar{x})} = d = \\inf_{x \\in K} \\norm{x- T(x)}.\n\t\t\\]\n\t\tThis is a contradiction which gives $d=0$ and so $\\bar{x} = T(\\bar{x})$.\n\t\\end{description}\n\\end{beispiel}\n\\begin{beispiel}\n\tConsider\n\t\\[\n\t\tf(x) = \\int_{0}^{x}k(x,y)h(y,f(y)) \\,\\mathrm{d}y + g(x), \\qquad x \\in [0,1] \\qquad (*),\n\t\\]\n\twhere $g \\in C([0,1])$, $k \\in C([0,1] \\times [0,1])$ and $h: [0,1] \\times \\mathbb{R} \\to \\mathbb{R}$ continuous and satisfies: \\\\\n\tThere exists $M>0$ such that\n\t\\[\n\t\t\\abs{h(x,z_1)-h(x,z_2)} \\leq M \\abs{z_1- z_2} \\qquad \\text{for all }x \\in [0,1],\\,z_1,z_2 \\in \\mathbb{R}.\n\t\\]\n\t\\textbf{Claim:} \\text{    }     $(*)$ has a unique solution $f \\in C([0,1])$. \\\\ For $f \\in C([0,1])$ set\n\t\\[\n\t\tT(f)(x) = \\int_{0}^{x}k(x,y)h(y,f(y)) \\,\\mathrm{d}y + g(x) \\qquad x \\in [0,1].\n\t\\]\n\tHere $T(f)(x) \\in C([0,1])$. \\\\ Want to show: $T: C([0,1]) \\to C([0,1])$ has a unique fixed point. \\\\\n\tStart with the Banach space $(C([0,1]), \\text{max-norm})$. Check if $T$ is a contraction in $C([0,1])$. Fix $f_1,f2 \\in C([0,1])$\n\t\\[\n\t\tT(f_1)(x)- T(f_2)(x) = \\int_{0}^{x} k(x,y)(h(y,f_1(y))-h(y,f_2(y))) \\,\\mathrm{d}y.\n\t\\] \n\t$k$ is continuous on the compact set $[0,1] \\times [0,1]$ so \n\t\\[\n\t\t\\sup\\limits_{(x,y) \\in [0,1]\\times[0,1]} \\abs{k(x,y)} =: N < \\infty.\n\t\\]\n\tWe obtain \n\t\\begin{align*}\n\t\t\\abs{(T(f_1)-T(f_2))(x)} &\\leq \\int_{0}^{x} \\underset{\\leq N}{\\underbrace{\\abs{k(x,y)}}}\\underset{\\leq M \\underset{\\leq \\norm{f_1-f_2}}{\\underbrace{f_1(y)-f_2(y)}}}{\\underbrace{h(y,f_1(y))-h(y,f_2(y))}} \\,\\mathrm{d}y \\\\ & \\leq \\int_{0}^{x}NM \\,\\mathrm{d}y \\norm{f_1-f_2} \\\\& \\leq NM \\norm{f_1-f_2}.\n\t\t\\end{align*}\n\tThis yields\n\t\\[\n\t\t\\norm{T(f_1)-T(f_2)} \\leq NM \\norm{f_1-f_2}.\n\t\\]\n\t\\begin{Large}\n\t\t\\underline{IF:}\n\t\\end{Large} \\,$NM<1$ Then $T$ is a contaction. \\\\ Trick: For $a >0$ set \n\t\\[\n\t\t\\norm{f}_a = \\max\\limits_{x \\in [0,1]} e^{-ax}\\abs{f(x)}\n\t\\] \n\tfor $f \\in C([0,1])$. \\\\\n\t\\textbf{Claim:} \\text{    }     $\\norm{.}_a$ defines a norm on $C([0,1])$. This is easy to check. \\\\\n\t\\textbf{Claim:} \\text{    }     $\\norm{.}$ and $\\norm{.}_a$ are equivalent. \\\\\n\tThis follows from\n\t\\[\n\t\te^{-a} \\norm{f} \\leq \\norm{f}_a \\leq \\norm{f}\n\t\\]\n\tfor all $f \\in C([0,1])$ (note that $\\norm{.}$ is the max-norm).\\\\\n\t\\textbf{Claim:} \\text{    }     $(C([0,1]), \\norm{.}_a)$ is a Banach space. \\\\\n\tThis follows from the fact that $\\norm{.}$ und $\\norm{.}_a$ are equivalent and $(C([0,1]),\\norm{.})$ is a Banach space. \\\\\n\t\\textbf{Claim:} \\text{    }     $T$ is a contraction on $(C([0,1]),\\norm{.}_a)$ for $a >0$ large enough. \\\\\n\tFor $f_1,f_2 \\in C([0,1])$ and $x \\in [0,1]$ we have\n\t\\begin{align*}\n\t\t\\abs{(T(f_1)-T(f_2))(x)} &\\leq \\int_{0}^{x} NM \\abs{(f_1-f_2)(y)} \\,\\mathrm{d}y \\\\\n\t\t&= \\int_{0}^{x}NM e^{ay} \\cdot \\underset{\\leq \\norm{f_1-f_2}_a}{\\underbrace{e^{-ay} \\abs{(f_1-f_2)(x)}}} \\,\\mathrm{d}y \\\\\n\t\t&\\leq NM \\underset{\\frac{1}{a}(e^{ax}-1)}{\\underbrace{\\int_{0}^{x} e^{ay} \\,\\mathrm{d}y}} \\norm{f_1-f_2}_a.\n\t\\end{align*}\n\tSo\n\t\\[\n\t\te^{-ax} \\abs{(T(f_1)-T(f_2))(x)} \\leq \\frac{NM}{a}(1-e^{-ax})\\norm{f_1-f_2}_a\n\t\\]\n\tand\n\t\\[\n\t\t\\norm{T(f_1)-T(f_2)}_a \\leq  \\frac{NM}{a} \\norm{f_1-f_2}_a\n\t\\]\n\tFor $a > NM$ is $T$ a contraction on $(C([0,1]),\\norm{.}_a)$. Banach fixed point theorem implies that there is a unique $f \\in C([0,1])$ that solves $(*)$.\n\\end{beispiel}\n", "meta": {"hexsha": "50ed38dd2246be5b4e0fa9fa9a1cd6697c4c4df3", "size": 12219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AF/splits/lecture5.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/lecture5.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/lecture5.tex", "max_forks_repo_name": "TiKeil/LatexGU", "max_forks_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.7956989247, "max_line_length": 300, "alphanum_fraction": 0.5427612734, "num_tokens": 5649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6793532842744687}}
{"text": "As a closing remark, let us briefly consider the question of \\textit{what can and cannot be computed} with our logic language. On the surface our logic language looks very different from other programming languages such as, say, Java or F\\#. Does this difference translate into higher or lower expressive power? In this chapter, we briefly and informally explore questions about the expressive power of different programming languages and programming paradigms. \n\nWe will do so to justify the importance of programming languages and appropriate formalisms, but not for the purpose of expressing constructs that cannot be expressed into the other formalisms: rather, different languages and formalisms allow \\textit{human users} to better reason, and as such do offer a different perspective on the same object (the set of all programs) which lets some different properties emerge better.\n\nWe will begin by discussing intrinsically hard problems that cannot have an algorithmic answer. These problems make up the boundaries of computability, and as such if we could\\footnote{Spoiler alert: we can noooooooooooooooooooot!} define a formalism that solves one of this problems algorithmically then we would have found something that is intrinsically more expressive than the formalisms and languages that we use now.\n\n\n\\subsection{Halting problem}\nWe will now explore the simple question: \\textit{are there limits to what can be computed?} In order to effectively manipulate programs we build a way to translate an arbitrary formula within some formalism into a natural number, that is we show a way to encode arbitrarily complex data structures into simpler objects that are easier to manipulate. \n\nThis means that any statement within our formalism is now a natural number, and thus we have an isomorphism between ``properties of statements'' $\\Leftrightarrow$ ``properties of numbers'', but ``properties of numbers'' are easier to determine algorithmically because we do not need to define data structures. \n\n\\paragraph{Gödel numbering}\nThere are many ways to define such an encoding. We present Gödel's original encoding from many decades ago, mostly for historical reasons\\footnote{A nice side-effect is that this encoding still works, which in a world of short-lived, superficial technological innovation where stuff stops working after a couple of years might seem strange. ``Should we not use something new and shiny?'', I hear you say: ``no.''}\n\nWe assign a unique natural number to each basic symbol in our language, for example:\n\\begin{itemize}\n\\item \\texttt{if} $=0$\n\\item \\texttt{var} $=1$\n\\item \\texttt{,} $=2$\n\\item ...\n\\end{itemize}\n\nGiven any formula $x_1,x_2,\\dots,x_n$, $x_i$ where each $x_i$ is a symbol with associated a number from the list above, we define the encoding function:\n\n$$enc(x_1,\\dots,x_n)=2^{x_1} \\cdot3^{x_2} \\cdot \\dots \\cdot p_n^{x_n}$$\n\nwhere $p_n$ is the $n$-th prime number. This means that we encode the $i$-th symbol of the sequence as the exponent of the $i$-th prime number. According to the fundamental theorem of arithmetic, we can always extract back the original sequence with a finite number of steps.\n\nFor example, in a specific Gödel numbering, the Gödel number for $0$ could be $6$, and the Gödel number for $=$ could be $5$. Thus, in such a system, the Gödel number of formula $0 = 0$ would be $2^6 \\times 3^5 \\times 5^6 = 243000000$.\n\n\n\\paragraph{Halting}\nLet us now consider the halting problem itself. Consider the problem of determining whether a program \\texttt{i} terminates on input \\texttt{x}. We can formulate this problem as finding function $h(i,x)$ that returns:\n\n\\begin{itemize}\n\\item $1$ if program $i$ terminates on input $x$\n\\item $0$ otherwise\n\\end{itemize}\n\nSince we wish to automate this process, we want to find a way to translate function $h(i,x)$ into some program. For this to be possible, then function $h$ needs to be \\textit{total} and \\textit{computable}. A function is total if, for every input, it gives back a result. Trivially, function $h$ is defined so as to always return either $0$ or $1$, therefore it is total by definition. A function is computable if it can be encoded into a Turing machine or any equivalent formalism such as the $\\lambda$-calculus. We shall further discuss these formalisms later, but for the moment let us treat them as mathematically flavoured assembly languages.\n\n\nWe will now show\\footnote{\\textit{Show} in this case is meant in the informal sense.} a shocking result: no arbitrary total computable function $f$ can be equal to $h$, and we will do so by constructing a counter example. The outline of the proof is as follows:\n\\begin{itemize}\n\\item we consider an \\textit{arbitrary} total computable function $f$\n\\item we construct a partial but computable function $g$ that is based on $f$\n\\item we feed $g$ into $h$ (the halting function) and show that $f \\neq h$\n\\item since $f$ was an \\textit{arbitrary} total computable function, then there exists no total computable function $f = h$\n\\end{itemize}\n\nLet us now consider an arbitrary total computable function $f$ in two arguments. We then define partial computable function $g(i)$ so that it returns:\n\\begin{itemize}\n\\item $0$ if $f(i,i)=0$\n\\item $\\uparrow$ otherwise\n\\end{itemize}\n\nNote that in the above, $\\uparrow$ denotes no or undefined return value. This is allowed, as $g$ was meant to be a partial function. Not returning a value in practice amounts to infinite looping or (tail-)recursion, which effectively prevents a function from returning anything.\n\nSince we chose $f$ to be totally computable, then as a consequence $g$ is will also be computable. We could formulate the above as follows in the logic programming language defined so far:\n\n\\begin{lstlisting}\nf i i => 0\n-----------\ng i => 0\n\\end{lstlisting}\n\nAs long as \\texttt{f i i} is also defined within the same program and always returns a result, then the above is a valid formulation within our language.\n\nSince $g$ is computable, albeit partial, we can give a program computes $g$ and encode it with Gödel's numbering into $e_g$.\n\nLet us now consider what happens if we give $e_g$ \\textit{twice} to function $h$. $h(e_g,e_g)$ will return:\n\n\\begin{itemize}\n\\item $f(e_g,e_g)=0 \\rightarrow g(e_g)=0 \\ \\rightarrow h(e_g,e_g)=1$\n\\item $f(e_g,e_g)=1 \\rightarrow g(e_g)=\\uparrow \\ \\rightarrow h(e_g,e_g)=0$\n\\end{itemize}\n\nThe above means that whatever $f$ returns, then $h$ returns something else. This means that $h \\neq f$, but since $f$ was an \\textit{arbitrary} total computable function, then $h$ is different from it and thus $h$ is different from all total computable functions.\n\nThe consequence of this is that $h$ is not computable, that is we cannot encode it within a Turing machine, $\\lambda$-calculus, etc.\n\nNot all hope is lost, because even if we cannot give a function $h$ that always answers \\texttt{yes} or \\texttt{no}, nothing stops us from  building an \\textit{approximated} version of it. For example, we might restrict ourselves to solutions such as:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item a partial function, that may sometimes loop forever;\n\\item a function that can also return no answer, such as \\texttt{unknown};\n\\item a function that gives probabilistic answers;\n\\item ...\n\\end{inparaenum}\n\nWe will focus on approximation techniques (even though not applied to the halting problem itself but one of its cousins) in later chapters.\n\n\n\\subsection{Some desperate grasping}\nA reader with an active imagination might, at this point, be trying to find reasons why this does not really apply to his or her experience with programming. After all, this might just be an isolated incident, and most interesting things hopefully remain easily doable, right?\\footnote{Yeah, you wish: this chapter goes from bad to worse, so giving up hope now will save you from depression further down the road. Sorry.}\n\nUnfortunately for us, the mere fact that we cannot solve the halting problem really means that we cannot solve many hardcore problems that would make the life of programmers much easier.\\footnote{This is actually the only silver lining: insightful programmers cannot be automated away, and will never be out of a job. Up yours, robotics!}\n\nSome examples of problems that cannot be solved automatically as a consequence of the halting problem are:\n\\begin{itemize}\n\\item \\textbf{EQUIVALENCE PROBLEM} Given two programs, test to see if they are equivalent.\n\\item \\textbf{SIZE OPTIMIZATION PROBLEM} - Given a program, find the shortest equivalent program.\n\\item \\textbf{GRAMMAR PROBLEM} Given two grammars, find out whether they define the same language.\n\\item ...\n\\end{itemize}\n\nAll of the problems above cannot be solved, because solving them would make it possible to also solve the halting problem.\\footnote{This proof strategy is known as \\textit{reduction}, because it reduces one problem to another one, showing that solving the first implies solving the second or vice-versa.}\n\nFor example, consider the equivalence problem. Suppose (\\textit{ad absurdum}\\footnote{A proof based on \\textit{reductio ad absurdum} assumes something that we suspect to be false and shows that from this assumption stems a clear contradiction against some previously established fact.}) we have a function \\texttt{equivalent} that is capable of reliably testing whether two programs are equivalent on some input. We will now show how we could use this equivalence test to determine whether or not a program \\texttt{P} halts on input \\texttt{i}. To do so, we construct a new program \\texttt{Q} that works precisely like \\texttt{P}, but which returns \\texttt{1} whenever \\texttt{P} would return something. This would be equivalent to simply ignoring the result of \\texttt{P}, for example:\n\n\\begin{lstlisting}\nP => res\n---------\nQ => 1\n\\end{lstlisting}\n\nWe now construct a new, trivial program \\texttt{T} that always returns \\texttt{1}:\n\n\\begin{lstlisting}\n-------\nT => 1\n\\end{lstlisting}\n\nWe now use our function \\texttt{equivalent} on \\texttt{Q} and \\texttt{T}. If \\texttt{Q} and \\texttt{T} are equivalent, then this means that \\texttt{Q} halts, therefore \\texttt{P} halts as well. Since we know that we cannot solve the halting problem, then our original hypothesis that we have a total, computable \\texttt{equivalent} function was absurd. \n\nSimilar proofs can be set up for all problems that involve the automated, reliable determination of complex properties of programs. This generalization is known as \\textit{Rice's Theorem}, which states that, for any non-trivial property of partial functions, there is no total computable function that decides whether an algorithm computes with that property. Here, non-trivial means that it is a property that holds for some but not all partial computable funcctions.\n\n\\textit{Rice's Theorem} is quite a dramatic result, because it ultimately guarantees that no fully reliable algorithm will ever be able to perfectly optimize a program for speed or size, no compiler will be able to verify the correctness of programs, etc.\\footnote{This is the permanent guarantee of employment for at least some programmers that was mentioned in a previous footnote. Yay!}\n\n\n\\paragraph{Computers are really finite}\nThe last, desperate attempt at solving the halting problem could be done by a self-appointed smart person that observes how computers are not really correct implementations of Turing machines. In particular, it could be noticed how memory in a modern computer is actually finite, and thus a modern computer is really a large state machine. A non-terminating program will eventually run out of new memory states to explore, and revert back to an older memory state. Thus by tracking all memory states seen so far by the program we can determine if the program does not halt after \\textit{enough steps} to explore all the possible memory states. But \\textit{how large of a state machine are we talking about}, and thus how many is \\textit{enough steps}? Consider a computer with just one gigabyte, which for practical purpose we will assume to be $10^9$ bits. This means that we would need to perform at most $2^{10^9}$ steps, in order to check all possible bit configurations. Now $2^{10^9}$ is indeed a finite number, if one is into this kind of distinction, but as far as finite numbers go it is sufficiently big to make any concrete implementation impossibly slow. It is safe to assume that the civilization of the creator of the program will likely be dead well before the program finishes running. Whether we choose to use a computer with less memory will still be pointless, since even for a computer with one kilobyte we would need to perform at most $2^{10^5}$ steps, which is still a prohibitively large number. Whoever tries to run such a program will not likely see the result within his or her lifetime.\n\nOf course modern computers have far more memory, and programs are often connected to the Internet. This means that the actual program running is a large distributed program which state is far larger and distributed, further making any ``finite memory'' argument completely unusable in practice.\n\n\\subsection{Some equivalences and translations}\nSomeone might wonder if it is possible to define some formalism that solves the halting problem by simply shifting the perspective. Perhaps there exists some new way to formulate new programming languages that do not suffer from this issue?\n\nThe basic formalisms of computing are two well-known theoretical programming languages, which are \\textit{Turing machines} on one hand and the $\\lambda$\\textit{-calculus} on the other. Already during the previous century\\footnote{For the perspective of future readers, we are talking about the 1900's.} it was discovered that these languages are \\textbf{isomorph}, that is they can both express exactly the same programs, and neither can do something that the other cannot. This shocking result was brought about by the presence of translation routines that allow to translate \\textit{any} Turing-machine program in a semantically equivalent\\footnote{That is which performs exactly the same computation.} $\\lambda$-calculus program, and vice-versa.\n\nWithout diving into the details of these formalisms, it is possible to observe that we have not yet found a way to escape the circle. For example, we could notice that in our case, there exists a chain of translations that goes as follows:\n\n\\begin{lstlisting}[mathescape=true]\n$\\lambda$-calculus => F# => our logic language\n\\end{lstlisting}\n\nNow if we can show that we can implement the $\\lambda$-calculus into our logic language, then we have ``closed the circle''. The grammar of the language is made up of three simple terms: \n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item identifiers (intuitively similar to variables), which are simply strings wrapped by \\texttt{\\$};\n\\item lambda terms (intuitively similar to function declarations), which take the form \\texttt{\\textbackslash \\$x -> TERM};\n\\item applications (intuitively similar to function calls), which take the form \\texttt{TERM | TERM}.\n\\end{inparaenum}\n\nThis syntax is defined in our language as:\n\n\\begin{lstlisting}\nData [] [] \"$\" [<<string>>] Priority 10 Type Id\nData [] [] \"\\\" [Id Arrow Term] Priority 9 Type Term\nData [] [Term] \"|\" [Term] Priority 8 Type Term\n\\end{lstlisting}\n\nOf course an identifier is also a term, thus:\n\n\\begin{lstlisting}\nId is Term\n\\end{lstlisting}\n\nThe arrow is not strictly needed, but it is aesthetically pleasing in that it helps distinguish a function arguments from its body:\n\n\\begin{lstlisting}\nData [] [] \"->\" [] Priority 0 Type Arrow\n\\end{lstlisting}\n\nExecution\\footnote{This is just one of the many possible evaluation strategies for the $\\lambda$-calculus, which is perhaps the most intuitive for a programmer with a traditional imperative background.} of a program within the calculus is quite simple: whenever we apply a lambda term (the function being called) to another term (the argument), then the result \\textit{is the body of the function called where the function parameter has been replaced by the value of the argument}.\n\nExecution of any term which is not the application of a lambda term to something else simply does nothing:\n\n\\begin{lstlisting}\n---------\n$x => $x\n\n---------------\n\\$x -> t => \\$x -> t\n\n-----------------\n$x | u => $x | u\n\\end{lstlisting}\n\nNested applications are solved from the right to the left:\n\n\\begin{lstlisting}\nw => w'\nu | v => uv\nuv | w' => res\n-------------------\n(u | v) | w => res\n\\end{lstlisting}\n\nFinally, applications of lambda terms to other, arbitrary terms instance \\textit{substitutions}. Substitutions are of the form \\texttt{TERM with \\$x as TERM}, indicating that we are replacing variable \\texttt{\\$x} with some other term:\n\n\\begin{lstlisting}\nData [] [Term] \"as\" [Term] Priority 6 Type Where\nData [] [Term] \"with\" [Where] Priority 5 Type With\n\\end{lstlisting}\n\nTo evaluate such an application, which is of the form \\texttt{\\textbackslash\\$x -> t | u}, we first evaluate \\texttt{u} into \\texttt{u'}, and then replace \\texttt{\\$x} with \\texttt{u'} within \\texttt{t}:\n\n\\begin{lstlisting}\nu => u'\nt with ($x as u') => t'\n-----------------------------------\n\\$x -> t | u => t'\n\\end{lstlisting}\n\nIf we find the variable we needed to replace with term \\texttt{u}, then instead of the variable we return \\texttt{u} itself:\n\n\\begin{lstlisting}\n  x == y\n  ---------------------\n  $y with $x as u => u\n\\end{lstlisting}\n\nIf we find a different variable than the one we needed to replace, then we return the variable unchanged because no replacement is possible:\n\n\\begin{lstlisting}\n  x != y\n  ----------------------\n  $y with $x as u => $y\n\\end{lstlisting}\n\nIf we find a redefinition of the variable we were replacing, then we stop the replacement procedure as the variable we were replacement has been shadowed and a new one becomes active in the new scope created:\n\n\\begin{lstlisting}\n  x == y\n  ----------------------------------\n  \\$x -> t with $y as u => \\$x -> t\n\\end{lstlisting}\n\nIf we find a variable definition for a new variable which is not the one we were replacing, then we proceed with replacement within the body of the function definition:\n\n\\begin{lstlisting}\n  x != y\n  t with $y as u => t'\n  -----------------------------\n  \\$x -> t with $y as u => \\$x -> t'\n\\end{lstlisting}\n\nIf we find an application, then we perform the replacement within both terms of the application and return the resulting application:\n\n\\begin{lstlisting}\n  t with $x as v => t'\n  u with $x as v => u'\n  --------------------------------\n  (t | u) with $x as v => t' | u'\n\\end{lstlisting}\n\nConsider now the evaluation of a simple term such as:\n\n\\begin{lstlisting}\n-----------------------------\n(\\$\"x\" -> $\"x\") | $\"y\" => ?\n\\end{lstlisting}\n\nThe first step of evaluation tries to evaluate term \\texttt{\\$\"y\"}, and then replace \\texttt{\\$\"x\"} with the result of this evaluation:\n\n\\begin{lstlisting}\n$\"y\" => u'\n$\"x\" with $\"x\" as u' => t'\n--------------------------------------\n(\\$\"x\" -> $\"x\") | $\"y\" => t'\n\\end{lstlisting}\n\nThe evaluation of \\texttt{\\$\"y\"} simply returns \\texttt{\\$\"y\"} itself, because a variable always evaluates to itself:\n\n\\begin{lstlisting}\n$\"y\" => $\"y\"\n$\"x\" with $\"x\" as $\"y\" => t'\n-----------------------------\n(\\$\"x\" -> $\"x\") | $\"y\" => t'\n\\end{lstlisting}\n\nEvaluation then proceeds to the next premise, which is a replacement of the right variable\n\n\\begin{lstlisting}\n$\"x\" == $\"x\"\nt' := $\"y\"\n----------------------------------------\n$\"x\" with $\"x\" as $\"y\" => t'\n--------------------------------------\n(\\$\"x\" -> $\"x\") | $\"y\" => t'\n\\end{lstlisting}\n\nWe can now begin the unwinding procedure, which after just one step returns:\n\n\\begin{lstlisting}\n(\\$\"x\" -> $\"x\") | $\"y\" => $\"y\"\n\\end{lstlisting}\n\nWhich is precisely the answer we expected.\n\n\nBy implementing the $\\lambda$-calculus then we have shown how on one hand our language \\textit{is not more powerful} than any of the well-known formalisms of programming, but on the other hand we have shown how our language \\textit{is not less powerful} than any of the well-known formalisms of programming.\n\nThis being exactly as powerful as the $\\lambda$-calculus or Turing machines is known as the \\textbf{Church-Turing equivalence}, and is the best known way to define the expressive power of programming. The existance and apparent inescapability of the Church-Turing equivalence suggests that there is no preferred encoding which ``unlocks'' impossible problems such as the halting problem, therefore making them computable.\n\n\n\n\\section{Conclusion}\n%One might be tempted to look outside of programming\n%Maybe mathematical encodings offer a solution?\n\n%Apparently we have the same issue\n%Exemplified by Russel's paradox\n%$R = \\{ x . x \\notin x \\}$\n%\\begin{itemize}\n%\\item $R \\in R$?\n%\\item $R \\notin R$?\n%\\end{itemize}\n\n%A devastating generalization of Russel's paradox\n%First incompleteness theorem:\n%\\begin{itemize}\n%\\item no consistent system of axioms whose theorems can be listed by an ``effective procedure''\n%\\item capable of proving all truths about the relations of the natural numbers\n%\\item For any such system, there will always be statements about the natural numbers that are true, but unprovable\n%\\end{itemize}\n%Proven by constructing self-referencing objects\n\n%the direct relationship between computer programs and mathematical proofs\n%observation that two families of formalisms that had seemed unrelated are in fact structurally the same kind of objects\n%\\textit{a proof is a program, the formula it proves is a type for the program}\n%\\textit{running a program is equivalent to ``simplifying'' a theorem}\n\n%\\includegraphics[width=11cm]{pics/curryhoward.png}\n\n\n\nWhat we have seen so far leaves us with a new perspective on computation. No matter what language we choose, there seems to be a hard limit on what is possible to compute. This means that:\n\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item programming languages all represent, at their core, the same set of objects (the set of all programs);\n\\item some problems cannot be solved with an automated solution, independently of the programming language;\n\\end{inparaenum}\n\nWhy is the search for new programming languages interesting thus, if they allow us no more expressive power? In reality, programming languages have more or less expressive power, but not because of what they can compute, but because they allow a clearer interaction with the \\textit{humans} that use them. As A. Whitehead\\footnote{A famous mathematician for as far as fame goes for mathematicians.} said in ``The Importance of Good Notation'', in his book \\textit{An Introduction to Mathematics}:\n\n\\begin{displayquote}\n[...] by the aid of symbolism, we can make transitions in reasoning almost mechanically by the eye, which otherwise would call into play the higher faculties of the brain.\n\n[...]\n\nOne very important property for symbolism to possess is that it should be concise, so as to be visible at one glance of the eye and to be rapidly written. \n\n[...]\n\nIt is interesting to note how important for the development of science a modest-looking symbol may be. It may stand for the emphatic presentation of an idea, often a very subtle idea, and by its existence make it easy to exhibit the relation of this idea to all the complex trains of ideas in which it occurs. For example, take the most modest of all symbols, namely, 0, which stands for the number zero. The Roman notation for numbers had no symbol for zero, and probably most mathematicians of the ancient world would have been horribly puzzled by the idea of the number zero. For, after all, it is a very subtle idea, not at all obvious. A great deal of discussion on the meaning of the zero of quantity will be found in philosophic works. Zero is not, in real truth, more difficult or subtle in idea than the other cardinal numbers.\n\\end{displayquote}\n\nThus programming languages make it easier to express some aspects of thoughts rather than some others, and by emphasizing concepts such as correctness or reliability we can dramatically change the impact of the language on the thought process of the programmer.\n\n\nAbout the unsolvable problem, also here is some silver present. Even though we cannot provide a perfect solution to these problems, nothing forbids us from building partial solutions that allow for uncertainty. We can thus always build a program that can answer questions about termination, correctness, or equivalence between programs with answers taken from the set \\texttt{yes}, \\texttt{no}, and \\texttt{unknown}. The ability to return \\texttt{unknown} suddenly makes the program possible to build, therefore exchanging some precision with implementability. \n\nThe challenge that arises from this is thus that of reducing the number of programs for which our analyser returns \\texttt{unknown} so that it is as small as possible. Not only do we wish to reduce the number of uncertain programs, we might also find it acceptable to have our analysis ``give up'' for programs where the flow of control is complex or hard to follow, in the assumptions that these programs, even when working, are not acceptable for being too confusing\\footnote{If a program is confusing for a carefully built analyser, imagine what it does to the brain of Bob, a 20-something junior programmer who just came out of a coding bootcamp and sits two cubicles over.}. Theoretical frameworks such as dependent types, model checking, and abstract interpretation (just to name a few) are written with the goal in mind of standardizing the concepts of approximated analysis of computer programs, precisely with the goal of providing an incomplete, but still useful, solution to problems such as halting.\n", "meta": {"hexsha": "13ba6e1c2b43c67d7b81020fd5e0778e697cb928", "size": 25642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/computability.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/computability.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/computability.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 70.2520547945, "max_line_length": 1614, "alphanum_fraction": 0.7557132829, "num_tokens": 6018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6793532812662056}}
{"text": "\n\\subsection{??}\n\nCalculating choices: Restricted choices\n\nBut what about where there is not clear maximum, like:\n\n\\(f=ln(x)+ln(y)\\)\n\nHere the agent would always prefer more of \\(x\\) and \\(y\\). In practice agents are often limited in their choices by budget constraints. That is, they cannot choose all combinations of inputs.\n\nHere we can use a Lagrangian. This maximises the value of a function subject to constraints on inputs. This may not always be appropriate. The budget constraint for an agent is often an inequality, for example consumption is less than or equal to income, but the Lagrangian takes this to be binding.\n\nFortunately, this can be resolved. The value of \\(\\lambda \\) in the Lagrangian corresponds to the marginal effect of weakening the constraint. This is positive where the constraint is binding on the agent, but not positive if it is not. Therefore if we find the constraint is not binding, we can remove it from the optimisation.\n\nUnder some conditions, constraints will always be binding. These are useful for specific cases of agents later.\n\nIn order for the constraint to be binding we make an additional assumption:\n\n\\subsubsection{Condition 1: Non-satiation}\n\nThe marginal utility of a good is always positive.\n\nNote that we can “do economics” without this, but we want rely on Lagrangians.\n\n\\subsubsection{Condition 2: Decreasing marginal utility}\n\nThis ensures that we do not get corner solutions, for example consuming all apples.\n\nThese two assumptions allow the use of the Lagrangian.\n\nWe know that for the Lagrangian the following is true:\n\n\\(\\dfrac{\\dfrac{\\delta f}{\\delta x}}{\\dfrac{\\delta g}{\\delta x}}=\\dfrac{\\dfrac{\\delta f}{\\delta y}}{\\dfrac{\\delta g}{\\delta y}}\\)\n\n\\(\\dfrac{\\dfrac{\\delta f}{\\delta x}}{\\dfrac{\\delta f}{\\delta y}}=\\dfrac{\\dfrac{\\delta g}{\\delta x}}{\\dfrac{\\delta g}{\\delta y}}\\)\n\nWhere \\(f\\) is the utility function and \\(g\\) is the budget constraint.\n\n", "meta": {"hexsha": "c92f320aab378aaef3ffa72c712909baf80aebc6", "size": 1915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/singleAgent/05-05-budgetSpecific.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/05-05-budgetSpecific.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/05-05-budgetSpecific.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.875, "max_line_length": 328, "alphanum_fraction": 0.7571801567, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6793532726855913}}
{"text": "\\chapter{Overview of Two-Qubit Gates}\n\\label{AppendixGates}\n\n  The CNOT gate is the archetypal two-qubit gate in sets of operations for\n  universal quantum computing; it flips the \\emph{target} qubit if\n  the \\emph{control} qubit is in state \\ket{1}.\n  \\begin{equation}\n  \\text{CNOT} =\n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 \\\\\n    0 & 0 & 0 & 1 \\\\\n    0 & 0 & 1 & 0\n    \\end{pmatrix}\n  \\end{equation}\n  \\index{CNOT gate}\n\n  The CPHASE gate induces a phase shift of $\\gamma$ on the target qubit if the\n  control qubit is in state \\ket{1}.\n  \\begin{equation}\n  \\text{CPHASE}_{\\gamma} =\n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & \\ee^{\\ii \\gamma}\n    \\end{pmatrix}\n  \\end{equation}\n  \\index{CPHASE gate}\n  The gate is a perfect entangler for $\\gamma=\\pi$, where it is locally\n  equivalent to CNOT. Indeed, \\emph{all} controlled operators are locally\n  equivalent to a $\\text{CPHASE}_{\\gamma}$ \\cite{ZhangPRA03}. We refer to\n  $\\text{CPHASE}_{\\pi}$ simply as CPHASE. In the Weyl chamber, the\n  $\\text{CPHASE}_{\\gamma}$ gates are on the line $O$--$A_1$.\n\n  The SWAP gate exchanges the two qubits. The gates at the $A_3$ point in the\n  Weyl chamber are the only true two-qubit gates that yield zero entanglement.\n  \\begin{equation}\n  \\text{SWAP} =\n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 1 & 0 & 0 \\\\\n    0 & 0 & 0 & 1 \\\\\n    \\end{pmatrix}\n  \\end{equation}\n  \\index{SWAP gate}\n\n  The $\\sqrt{\\text{SWAP}}$, located at the point $P$ in the Weyl chamber,\n  however, is a perfect entangler, indicating that\n  a SWAP gate is implemented by first entangling and then disentangling the two\n  qubits.\n  \\begin{equation}\n  \\sqrt{\\text{SWAP}}=\n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & \\frac{1}{2}-\\frac{\\ii}{2} & \\frac{1}{2}+\\frac{\\ii}{2} & 0 \\\\\n    0 & \\frac{1}{2}+\\frac{\\ii}{2} & \\frac{1}{2}-\\frac{\\ii}{2} & 0 \\\\\n    0 & 0 & 0 & 1\n    \\end{pmatrix}\n    \\label{eq:sqrt_SWAP}\n  \\end{equation}\n  A secondary square root of SWAP is located at the $N$ point; it is simply\n  the complex conjugate of the principal square root, Eq.~\\eqref{eq:sqrt_SWAP},\n  and we thus label is as $\\sqrt{\\text{SWAP}}^*$.\n  %\\begin{equation}\n  %\\sqrt{\\text{SWAP}}^* =\n    %\\begin{pmatrix}\n    %1 & 0 & 0 & 0 \\\\\n    %0 & \\frac{1}{2}+\\frac{\\ii}{2} & \\frac{1}{2}-\\frac{\\ii}{2} & 0 \\\\\n    %0 & \\frac{1}{2}-\\frac{\\ii}{2} & \\frac{1}{2}+\\frac{\\ii}{2} & 0 \\\\\n    %0 & 0 & 0 & 1\n    %\\end{pmatrix}\n  %\\end{equation}\n\n  The iSWAP gate performs a SWAP, with and additional relative phase shift\n  of $\\pi$. The gate is also known  as DCNOT (Double-CNOT), since is\n  implemented by two consecutive CNOT gates, where the control qubit for the\n  second CNOT is the target qubit of the first CNOT.\n  \\begin{equation}\n  \\text{iSWAP} =  \\text{DCNOT} =\n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 0 & \\ii & 0 \\\\\n    0 & \\ii & 0 & 0 \\\\\n    0 & 0 & 0 & 1 \\\\\n    \\end{pmatrix}\n  \\end{equation}\n  \\index{iSWAP gate}\n  \\index{DCNOT gate}\n\n  The principal square root of iSWAP is located at the $Q$ point in the Weyl\n  chamber.\n  \\begin{equation}\n  \\sqrt{\\text{iSWAP}} =\n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & \\frac{1}{\\sqrt{2}} & \\frac{\\ii}{\\sqrt{2}} & 0 \\\\\n    0 & \\frac{\\ii}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\\n    0 & 0 & 0 & 1 \\\\\n    \\end{pmatrix}\n  \\end{equation}\n  Note that none of the gates at the $M$ point are square roots of the exact\n  iSWAP, even though their square is still locally equivalent to iSWAP.\n\n\n  The B-GATE is at the center of the perfect entanglers. It has been shown to be\n  extremely efficient for the construction of arbitrary two-qubit gates\n  \\cite{ZhangPRL2004}.\n  \\begin{equation}\n  \\text{B-GATE} =\n    \\begin{pmatrix}\n    \\cos\\frac{\\pi}{8} & 0 & 0  & \\ii \\sin\\frac{\\pi}{8} \\\\\n    0 & \\cos\\frac{3\\pi}{8} & \\ii \\sin\\frac{3\\pi}{8} & 0 \\\\\n    0 & \\ii \\sin\\frac{3\\pi}{8} & \\cos\\frac{3\\pi}{8} & 0 \\\\\n    \\ii \\sin\\frac{\\pi}{8} & 0 & 0 & \\cos\\frac{\\pi}{8}\n    \\end{pmatrix}\n    \\index{B-GATE}\n  \\end{equation}\n\n\\begin{table}\n\\centering\n\n%\\vspace{-20pt}\n\\centering\\includegraphics{weylchamber}\n\\vspace{10pt}\n\n{\\small\n\\begin{tabularx}{\\textwidth}{m{18mm}|X|lll|l|lll}\n\\toprule\nGate & Hamiltonian & $c_1$ & $c_2$ & $c_3$ & $W$  & $g_1$ & $g_2$ & $g_3$ \\\\\n\\midrule\n& & & & & & & & \\\\\n%\n%\n$\\unity$ &\n(single qubit gates)&\n$0$ & $0$ & $0$ &\n$O$&\n$1$ & $0$ & $3$\n\\\\\n%\n%\n&\n&\n$\\pi$ & $0$ & $0$ &\n$A_1$&\n$1$ & $0$ & $3$\n\\\\[5mm]\n%\n%\nCNOT &\n$\\SigmaZ^{(1)} + \\SigmaX^{(2)} - \\SigmaZ\\SigmaX$ &\n$\\frac{\\pi}{2}$ & $0$ & $0$ &\n$L$&\n$0$ & $0$ & $1$\n\\\\[5mm]\n%\n%\nCPHASE$_\\gamma$ &\n$\\SigmaZ^{(1)} + \\SigmaZ^{(2)} - \\SigmaZ\\SigmaZ$ &\n$\\frac{\\gamma}{2}$ & $0$ & $0$ &\n%$O$--$A_1$ &\n&\n$g_1(\\gamma) $ & $0$ & \\hspace*{-3mm}$g_3(\\gamma)$\n\\\\[5mm]\n%\n%\niSWAP \\newline DCNOT &\n\\vspace*{-17pt}\n$\\SigmaX\\SigmaX + \\SigmaY\\SigmaY$ \\newline\n$= \\frac{1}{2} \\left(\\SigmaPlus\\SigmaMinus\n  + \\SigmaMinus\\SigmaPlus \\right)$ &\n$\\frac{\\pi}{2}$ & $\\frac{\\pi}{2}$ & $0$ &\n$A_2$ &\n$0 $ & $0 $ & $-1 $\n\\\\[5mm]\n%\n%\n$\\sqrt{\\text{iSWAP}}$ &\n$\\SigmaX\\SigmaX + \\SigmaY\\SigmaY $ &\n$\\frac{\\pi}{4} $ & $\\frac{\\pi}{4} $ & $0 $ &\n$Q$ &\n$\\frac{1}{4}$ & $0$ & $1$\n\\\\[5mm]\n%\n%\nSWAP&\n$\\SigmaX\\SigmaX +\\SigmaY\\SigmaY +\\SigmaZ\\SigmaZ$ &\n$\\frac{\\pi}{2}$ & $\\frac{\\pi}{2}$ & $\\frac{\\pi}{2}$ &\n$A_3$ &\n$-1 $ & $0 $ & $-3 $\n\\\\[5mm]\n%\n%\n$\\sqrt{\\text{SWAP}}$&\n$\\SigmaX\\SigmaX +\\SigmaY\\SigmaY +\\SigmaZ\\SigmaZ$ &\n$\\frac{\\pi}{4}$ & $\\frac{\\pi}{4}$ & $\\frac{\\pi}{4}$ &\n$P$ &\n$0 $ & $\\frac{1}{4} $ & $0 $\n\\\\[5mm]\n%\n%\n$\\sqrt{\\text{SWAP}}^*$&\n$-\\SigmaX\\SigmaX \\!-\\SigmaY\\SigmaY \\!-\\SigmaZ\\SigmaZ$ &\n$\\frac{3\\pi}{4}$ & $\\frac{\\pi}{4} $ & $\\frac{\\pi}{4}$ &\n$N$ &\n$0$ & $-\\frac{1}{4}$ & $0$\n\\\\[5mm]\n%\n%\nB-GATE&\n$2\\SigmaX \\SigmaX + \\SigmaY \\SigmaY$ &\n$\\frac{\\pi}{2}$ & $\\frac{\\pi}{4}$ & $0$ &\n$B$ &\n$0 $ & $0 $ & $0 $\n\\\\[5mm]\n%\n%\nM-GATE &\n$3\\SigmaX \\SigmaX + \\SigmaY \\SigmaY$ &\n$\\frac{3\\pi}{4} $ & $\\frac{\\pi}{4}$ & $0$ &\n$M$ &\n$\\frac{1}{4}$ & $0 $ & $1$\n\\\\[5mm]\n%%\n%%\n\\bottomrule\n\\end{tabularx}\n}\n\\caption{Summary of two-qubit gates at special points in the Weyl chamber (shown\nat the top, with the polyhedron of perfect entanglers indicated by the shaded\narea).  For each gate, the Hamiltonian generating that gate up to a global\nphase is given in terms of the Pauli matrices, where $\\Op{\\sigma}_{i}^{(1,2)}$\nindicates an operator acting only on the first and second qubit, respectively,\nand $\\Op{\\sigma}_i\\Op{\\sigma}_j$ is a shorthand for $\\Op{\\sigma}_i^{(1)} \\otimes\n\\Op{\\sigma}_{j}^{(2)}$.\nAlso, the Weyl coordinates $c_1$, $c_2$, $c_3$, the name of the respective point\nin the Weyl chamber, and the local invariants $g_1$, $g_2$, $g_3$ are listed.\nThe Weyl chamber coordinates for the controlled phase gate are\n$g_1(\\gamma) = \\cos^2 \\frac{\\gamma}{2}$ and\n$g_3(\\gamma) = 1+2\\cos^2\\frac{\\gamma}{2}$.\n}\n\\label{tab:appendixGates}\n\\end{table}\n\n", "meta": {"hexsha": "2aa870775f1bbf99b30fe23e6f16e586079f319a", "size": 6762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendixGates.tex", "max_stars_repo_name": "goerz/dissertation", "max_stars_repo_head_hexsha": "ee8ae29b5da1bc6033260224ae6444fd7f4c4a2f", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-05-09T03:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-11T13:33:43.000Z", "max_issues_repo_path": "chapters/appendixGates.tex", "max_issues_repo_name": "goerz/dissertation", "max_issues_repo_head_hexsha": "ee8ae29b5da1bc6033260224ae6444fd7f4c4a2f", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/appendixGates.tex", "max_forks_repo_name": "goerz/dissertation", "max_forks_repo_head_hexsha": "ee8ae29b5da1bc6033260224ae6444fd7f4c4a2f", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3765182186, "max_line_length": 80, "alphanum_fraction": 0.5757172434, "num_tokens": 2785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544824, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6793532726466531}}
{"text": "\\subsection{System Identification using Dead-Time and PT1 elements}\n\\label{sec:ident_Tt_PT1}\n\nIt  is  known  that the motor has a dead-time built in, and by looking at  the\nstep  response, one can say that it looks like a PT1 element might be  a  good\napproximation.\n\nThe dead time element and its Laplace transform is:\n\n\\begin{equation}\n    F_{T_t}(s) = \\laplace{\\{\\epsilon(t)(t-T_t)} = e^{-sT_t}\\}\n\\end{equation}\n\nThe PT1 lag element and its Laplace transform is:\n\n\\begin{equation}\n    F_{PT1}(s) = \\laplace{\\{\\epsilon(t)e^{-sT_g}}\\}\n\\end{equation}\n\nThese two elements are combined to obtain the model we will use to approximate\nthe measured step response:\n\n\\begin{equation}\n    G_1(s) = F_1(s) \\cdot F_2(s) = e^{-sT_t} \\frac{K_s}{sT_g+1}\n\\end{equation}\n\nBy  plugging  in  the  parameters  obtained  from the characterisation step in\nsection  \\ref{sec:sim:characterisation}  (dead-time  $T_t=T_u$)  we obtain the\nfollowing transfer function:\n\n\\begin{equation}\n    G_1(s) = e^{-0.165*s}\\frac{24.68}{5.96s + 1}\n\\end{equation}\n\nFigure  \\ref{fig:Tt_PT1_step}  shows  the  step  response  of  the  calculated\ntransfer function $G_1(s)$ and compares it to the measured step response. It's\npretty  close, perhaps the parameter $T_g$ can be adjusted so it rises faster.\nWhen doing this, however, the function no longer matches  the measured data at\nthe  beginning  where  it  starts  rising.  It's  possible therefore that  the\nmeasured system  is of higher order. Adding more PT1 elements to our model can\nhelp make the approximation more  exact, but for this experiment we will stick\nto a single PT1 element.\n\nBy  looking  at  the  Bode-Diagram  of  the   model   $G_1(s)$   (see   figure\n\\ref{fig:Tt_PT1_bode})  it  is  very  easy  to  determine  the  critical  gain\n$K_{s,crit}$. This is the  point at which the phase exceeds \\SI{180}{\\degree}.\nThe amplitude at  this  point  is  about  \\SI{-36}{\\decibel}, which means that\n$K_{s,crit}=\\SI{36}{\\decibel}$, or:\n\n\\begin{equation}\n    K_{s,crit} = 10^{\\frac{\\SI{36}{\\decibel}}{20}} \\approx 63.1\n\\end{equation}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\imagewidth]{images/Tt_PT1}\n    \\caption{Step response comparison of calculated system $G_1(s)$ and the measured step response.}\n    \\label{fig:Tt_PT1_step}\n\\end{figure}\n\nThe  closed  loop  transfer  function  of  $G_1(s)$  with  a  P-controller  is\nconstructed:\n\n\\begin{equation}\n    T(s) = \\frac{H(s)G_1(s)}{1 + H(s)G_1(s)}\n\\end{equation}\n\nWhere  $H(s)$  is  simply  the  P controller. By setting $H(s)=K_{p,crit}$ and\nsimulating a step  response,  we  obtain  a  system  that exhibits an undamped\noscillation (see  figure \\ref{fig:Tt_PT1_tcrit}). Determining $\\tau_{crit}$ is\nnow simply a matter of measuring two points in this graph.\n\n\\begin{equation}\n    \\tau_{crit} \\approx 0.66\n\\end{equation}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\imagewidth]{images/tcrit}\n    \\caption{Step response of the closed loop transfer function with $K_p=K_{p,crit}$}\n    \\label{fig:Tt_PT1_tcrit}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\imagewidth]{images/Tt_PT1_bode}\n    \\caption{Bode-Plots of the model $G_1(s)$. The phase exceeds \\SI{180}{\\degree} at about \\SI{-36}{\\decibel}}\n    \\label{fig:Tt_PT1_bode}\n\\end{figure}\n\n", "meta": {"hexsha": "1189fc64f3d86b3228067d3b59774e02f6151e81", "size": 3281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "versuche/rtGL/labor2/sections/simulations/identification_Tt_PT1.tex", "max_stars_repo_name": "TheComet93/laborjournal", "max_stars_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "versuche/rtGL/labor2/sections/simulations/identification_Tt_PT1.tex", "max_issues_repo_name": "TheComet93/laborjournal", "max_issues_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "versuche/rtGL/labor2/sections/simulations/identification_Tt_PT1.tex", "max_forks_repo_name": "TheComet93/laborjournal", "max_forks_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.0549450549, "max_line_length": 111, "alphanum_fraction": 0.7080158488, "num_tokens": 1064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.6791372711426964}}
{"text": "\\documentclass[a4paper,11pt,fleqn]{article}\n\\usepackage{polyglossia}\n\\setdefaultlanguage{english}\n\\usepackage{fontspec}\n\\setmainfont{DejaVuSans}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\captionsetup[figure]{skip=20pt}\n\\let\\oldref\\ref\n\\renewcommand{\\ref}[1]{(\\oldref{#1})}\n\\date{\\today}\n\\author{shamaz.mazum}\n\\title{Math behind cl-audio-downsample library.}\n\\begin{document}\n\\maketitle\n\\section{Fourier transform}\nThe Fourier transform of function $f(x)$ is a function $F(\\xi)$ defined by\n\\begin{equation}\nF(\\xi) = \\int_{-\\infty}^{\\infty} f(x)e^{ix\\xi}dx\n\\end{equation}\nand its inverse transform is defined by \n\\begin{equation}\nf(x) = \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} F(\\xi)e^{-ix\\xi}d\\xi\n\\end{equation}\nWhere direct and inverse transforms exist is a really hard question to be discussed here, so I will only say\nthat if the inverse transform exists for a particular $F(\\xi)$ then $F(\\xi)$ is decaying to zero when \nreal part of $\\xi$ moves toward infinity, in other words, $\\lim_{Re \\xi \\to \\infty} F(\\xi) \\to 0$.\nI also will use Fourier transform operator $Ff(x)$ which means \"apply Fourier transform to a function $f(x)$\".\nFourier transform has some useful properties, some of them I describe below:\n\\begin{description}\n\\item[Linear property] $F[af(x)+bg(x)] = aFf(x) + bFg(x)$. This is because of linear property of integral.\n\\item[Shift property] $Ff(x-a) = e^{ia\\xi}Ff(x)$. You can replace $x' = x - a$ in the integral to prove it.\n\\item[Image multiplication property] $F[f*g(x)] = Ff(x)Fg(x)$.\n\\end{description}\n$f*g$ above is called convolution and is defined as the following:\n\\begin{equation}\nf*g(x) = \\int_{-\\infty}^{\\infty}f(\\tau)g(x-\\tau)d\\tau\n\\end{equation}\nor if your functions equal to zero when $x<0$ \n\\begin{equation} \\label{convolve2}\nf*g(x) = \\int_{0}^{x}f(\\tau)g(x-\\tau)d\\tau\n\\end{equation}\nThe Fourier transform is of great importance in digital signal processing because you can think of $exp(ix\\xi)$\nas a harmonic oscillator with frequency $\\xi$. You can write $exp(iw) = cos(w) + isin(w)$.\n\\section{Bandlimiting a signal}\nImagine now an oscillator which oscillates uniformly at all frequencies $\\left|\\xi\\right| < \\omega_{0}$. \nIts Fourier transform will be\n\\begin{equation}\n\\label{idealfilter}\nF(\\xi) = \\left\\{\n\\begin{array}{rl}\n1 & \\text{if } \\left|\\xi\\right| < \\omega_{0},\\\\\n0 & \\text{otherwise}.\n\\end{array} \\right.\n\\end{equation}\nThe inverse transform is $f(x) = \\frac{sin(x)}{\\pi x}$. There is a Shannon sampling theorem which says that every\nbandlimited signal (i.e. it has no frequencies above some $f_{0}=\\frac{\\omega_{0}}{2\\pi}$) can be represented as \nshifted versions of functions $\\frac{sin(\\omega_{0}x)}{\\pi x}$ multiplied by samples of that signal taken at frequency\n$2f_{0}$ Hz. That means if you want to store a signal which contains, say, sine waves at frequency\nat most 1kHz, you need to take samples at frequency 2kHz (or higher). If you choose frequency less than $2f_{0}$ then\nsome of high frequency data will be \"misinterpreted\" as low frequency data.\n\\section{Signal filtering}\nSo if you want to downsample your audio data taken with sampling frequency, say, 96kHz to sampling frequency 48kHz, taking\nevery second sample is not enough! If you do so, all inaudible data in the range between 24 and 48 Hz will be misinterpreted\nand become audible. This thing is called aliasing. So before dropping any data you need to filter it to cut all oscillations\nabove $newsamplerate / 2$. To do so we will use the image multiplication property of the Fourier transform and convolve\nour signal with $\\frac{sin(\\omega_{0}x)}{\\pi x}$ using \\ref{convolve2} (provided that our signal begins from time $x=0$). There is\na problem with that, although. When convolving numerically, you need to use \\textbf{all} samples in you signal to get a new value\nfor \\textbf{one} sample. That's because support of $\\frac{sin(\\omega_{0}x)}{\\pi x}$ (i.e. set of values where the function does\nnot equal to zero, with possible exception of a set with measure zero) is the whole set of real numbers, $\\mathbb{R}$. What we\nneed is a filtering function with \\textbf{compact support} or in the case of functions defined on $\\mathbb{R}$, \\textbf{bounded\n  support}. Unfortunately, these functions cannot act as an ideal low-pass filter, but they can be close to it. Usually people use\nthe same $\\frac{sin(x)}{\\pi x}$ function multiplied by some window function to make its support compact, but I propose a different\napproach. I do not know, if it is known to anybody (most likely to), in this case I just \"reinvented\" it on my own.\n\n\\section {Inverse Fourier transform of some \"noninvertable\" functions}\nCan you invert a Fourier image, say, $F(\\xi)=1$? No, you cannot. That's because it does not die out when real part of $\\xi$\nmoves toward infinity. But you still can \"nominate\" some \"function\" to be its inverse transformed version! To understand it\nyou will need a concept of weak convergence. For a functions $f \\in H$, where $H$ is some Hilbert space, a sequence $f_{n} \\in H$\nis said to be convergent to $f$ if $\\lim_{n \\to \\infty} \\left<f_{n},g\\right> = \\left<f,g\\right>$ for all $g \\in H$. It is denoted as\n$\\{f_{n}\\} \\to^{w} f$.\n\n $\\left<\\cdot, \\cdot\\right>$ here is a \\textbf{scalar} or \\textbf{dot product} on that space $H$. If you do not\nknow that it means, remember orthogonal vectors on $\\mathbb{R}^{2}$, i.e. vectors for which the angle between them is 90 degrees. Scalar product\nof these vectors is zero. It is some measure of \"independence\" in the sense that if angle between two lines is changed from zero to 90 degrees, the\nscalar product will change from some value to zero. Scalar product of vectors $\\phi$ and $\\psi$ on $\\mathbb{R}^{N}$ is \n$\\left<\\phi,\\psi\\right> = \\sum_{i=1}^{N} \\phi_{i}\\psi_{i}$. $\\mathbb{R}^{N}$ is an example of a Hilbert space. It turns out, that scalar product\ncan be defined not only on $\\mathbb{R}^{N}$ but on spaces of functions. A most important example is $L^{2}(\\mathbb{C})$ space, i.e. space of functions,\nfor which exists a Lebesgue integral $\\int_{-\\infty}^{\\infty} {\\left|f(x)\\right|}^{2} dx$. For these functions there always exists an integral\n$\\left<f,g\\right> = \\int_{-\\infty}^{\\infty} f(x)\\overline{g(x)}dx$, $f,g \\in L^{2}(\\mathbb{C})$. This is how scalar product can be defined for functions.\nThere are also orthogonal functions on $L^2$. If functions in some set are orthogonal to each other and $\\left<f,f\\right> = 1$ this set is called a set\nof \\textbf{orthonormal} functions. $L^2$ is an another example of a Hilbert space. There are some sets of orthonormal functions on a Hilbert space called\n\\textbf{basis}. You can represent any function on that space as a sum of basis functions: $f(x) = \\sum_{i}\\left<f,\\phi_{i}\\right>\\phi_{i}$. Another important\nconcept is \\textbf{norm} denoted as $\\left\\lVert\\cdot\\right\\rVert$. In $\\mathbb{R}^{N}$ it tells how long a vector is. For $L^2$ a norm is defined as \n$\\left\\lVert f(x) \\right\\rVert  = \\sqrt{\\left<f,f\\right>}$.\n\nBack to weak convergence. Take functions $f_{n}(x) = \\frac{sin(nx)}{\\pi x}$. They all belong to $L^2$ with norm equals to $\\sqrt{n/\\pi}$. As you can see, if\n$n$ rises, norm of $f_{n}(x)$ also will rise, so $f_{n}(x)$ is divergent (there cannot be an element with infinite norm). But what happens to a sequence\n$\\left<f_{n},\\phi\\right>$ when $n \\to \\infty$ where $\\phi(x)$ is any function from $L^2(\\mathbb{R})$? Follow this trick:\n\\begin{equation}\n\\begin{aligned}\n\\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} f_{n}(x)\\phi(x)dx = \\\\\n\\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} \\frac{sin(nx)}{\\pi x}\\phi(x)dx = \\\\\n\\phi(0) \\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} \\frac{sin(nx)}{\\pi x} dx + \\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} sin(nx) \\frac{\\phi(x) - \\phi(0)}{\\pi x} = \\\\\n\\phi(0) \\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} \\frac{sin(nx)}{\\pi x} dx + \\int_{-\\infty}^{\\infty} \\lim_{n \\to \\infty} sin(nx) \\frac{\\phi(x) - \\phi(0)}{\\pi x}\n\\end{aligned}\n\\end{equation}\n\nIntegration and limit switched places because integrated function does not have any irregularities at $x=0$ now. It can be proven that for a \"good enough\" function $f(x)$\nan integral $\\int_{-\\infty}^{\\infty} sin(nx) f(x)dx$ converges to zero as $n \\to \\infty$. On the other hand $\\int_{\\infty}^{\\infty} \\frac{sin(nx)}{\\pi x}$ is always 1,\nno matter what value $n$ takes, so\n\\begin{equation}\n\\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} f_{n}(x)\\phi(x)dx = \\phi(0) = \\int_{-\\infty}^{\\infty} \\delta(x)\\phi(x)dx\n\\end{equation}\n\n$\\delta(x)$ is called a \\textbf{delta-function} and is defined simply as\n\\begin{equation}\n\\int f(x)\\delta(x) dx = f(0)\n\\end{equation}\nSurely, it's no a \"real\" function, but rather a functional on Hilbert space $L^{2}(\\mathbb{R})$, i.e. $\\left<\\delta,\\cdot\\right>$ takes a function and returns its value\nat point $x=0$. Also you can define $\\left<\\delta(x-a),f(x)\\right> = f(a)$. You can see that by substitution $x' = x+a$.\n\nAnother very important property on delta-function is that $f*\\delta = f$, i.e. convolution of any function with delta is that function. For some functions you can define\nso-called \\textbf{convolution algebra} where $\\delta(x)$ is like 1 in \"ordinary\" algebra and convolution of functions is like multiplication of numbers.\n\nSpeaking of Fourier transform, $F[\\frac{sin (\\omega_{0} x)}{\\pi x}](\\xi)$ is \\ref{idealfilter}. If $\\omega_{0} \\to \\infty$, the Fourier image becomes simply $F(\\xi) = 1$. Inverse\ntransform of that $F(\\xi)$ becomes $\\delta(x)$. If you want to pass your signal through such a filter (it's like identity filter, which does not change your signal), you must\nconvolve it with $\\delta(x)$: $f*\\delta = f(x)$. So as you can see, your signal is not changed indeed.\n\nIn case of discrete signals continuous convolution is replaced by discrete convolution. $f = \\phi*\\psi$ becomes\n\\begin{equation}\n\\label{discconv}\nf_{n} = \\sum_{i=-\\infty}^{\\infty}\\phi_{i}\\psi_{n-i}\n\\end{equation}\nSurely, in practice infinity is replaced by some finite $l$, known as, if I am right, a \\textbf{filter order}.\n\n\\section{My filter}\nIn the \\ref{discconv} let $\\phi_{i} = \\phi_{-i}$. Let's now imagine, that our filter is itself a function, sampled at infinitely high sampling rate, while your signal is sampled at frequency\n$f_{ref}=\\frac{\\omega_{ref}}{2 \\pi}$. Let a filter function be defined as:\n\\begin{equation}\n\\phi(x) = \\sum_{n=-N}^{N} \\phi_{n} \\delta(x+n \\frac{2 \\pi}{\\omega_{ref}})\n\\end{equation}\nwhere $\\phi_{n}$ are some coefficients. Its Fourier transform, $\\Phi(\\xi)$ is\n\\begin{equation}\n\\Phi(\\xi) = \\sum_{n=-N}^{N} \\phi_{n} e^{i n \\frac{2 \\pi}{\\omega_{ref}} \\xi}\n\\end{equation}\nI used the linear and shift properties of Fourier transform and the fact that $F[\\delta(x)] = 1$.\n\nThe equation above can be rewritten if members like $exp(ia\\xi)$ and $exp(-ia\\xi)$ are combined together. Remember, that $\\phi_{n} = \\phi_{-n}$.\n\\begin{equation}\n\\begin{aligned}\n\\sum_{n=-N}^{N} \\phi_{n} e^{i n \\frac{2 \\pi}{\\omega_{ref}} \\xi} = \\\\\n\\phi_{0} + \\sum_{n=1}^{N} \\phi_{n} (e^{i n \\frac{2 \\pi}{\\omega_{ref}} \\xi} + e^{-i n \\frac{2 \\pi}{\\omega_{ref}} \\xi}) = \\\\\n\\phi_{0} + \\sum_{n=1}^{N} \\frac{\\phi_{n}}{2} cos(n \\frac{2 \\pi}{\\omega_{ref}} \\xi)\n\\end{aligned}\n\\end{equation}\n\nGood, functions like $\\sqrt{\\frac{1}{\\omega_{ref}}}$ and $\\sqrt{\\frac{2}{\\omega_{ref}}} \\cos(n \\frac{2 \\pi}{\\omega_{ref}} \\xi)$ with\ndifferent $n$ are orthonormal to each other on a segment $[-\\omega_{ref}/2, \\omega_{ref}/2]$. They constitute a basis on that\nsegment for functions called \\textbf{even functions}, that is function $f(x)$ is even if $f(x)=f(-x)$. Our ideal filter\n\\ref{idealfilter} is an even function. You can find $\\phi_{n}$ calculating a scalar product of $F(\\xi)$ in \\ref{idealfilter} and\nfunctions from our basis set and normalising. Introduce a variable $a \\leq 1$, so $\\omega_{0} = a \\omega_{ref}/2$. We get the\nfollowing:\n\\begin{equation}\n\\begin{aligned}\n\\phi_{0} = \\frac{2}{\\omega_{ref}}\\int_{0}^{a \\omega_{ref}/2}d\\xi = a \\\\\n\\phi_{n} = \\frac{4}{\\omega_{ref}}\\int_{0}^{a \\omega_{ref}/2}cos(n \\frac{2 \\pi}{\\omega_{ref}} \\xi)d\\xi = \\frac{2}{n \\pi} sin (a \\pi n)\n\\end{aligned}\n\\end{equation}\nA sequence $\\{\\cdots, \\phi_{2}/2, \\phi_{1}/2, \\phi_{0}, \\phi_{1}/2, \\phi_{2}/2, \\cdots\\}$ will constitute our filter. Note, that\nthese coefficients do not depend on $\\omega_{ref}$. If you convolve this sequence with your signal by \\ref{discconv}, you will get\na new signal, in which all frequencies above $a\\omega_{ref}/2$ are cut (the original signal has frequencies up to\n$\\omega_{ref}/2$). The process of finding $\\{\\phi_{0}, \\phi_{1}, \\phi_{2}, \\cdots\\}$ is called \\textbf{Fourier series}\ndecomposition, not to be confused with Fourier transform. Note, that Fourier transform of our filter is real-valued and you will\nnot get any phase shift in frequencies below cutpoint, and sometimes phase shift of $\\pi$ above it, but who cares?\n\nGood enough? No. An ideal filter has a discontinuity at $\\left|\\xi\\right| = \\omega_{0} = a \\omega_{ref}/2$. Fourier series decomposition behaves very badly in the area around points of discontinuity. Even if\nyou choose $N$ to be large enough, that \"area of bad behaviour\" will be smaller and smaller, but bad behaviour will not vanish at all. It's known as \\textbf{Gibbs phenomenon}. Bad behaviour expresses itself as\nbig oscillations around points of discontinuity. We can eliminate that behaviour by introducing a small transition region between\npreserved frequencies and cut frequencies. To do this, let's find a function $f(x)$ which has following properties:\n\\begin{itemize}\n\\item is continuous and has (at least) $N$ derivatives in all points belonging to $[0,1]$;\n\\item $f(0) = 1$ and $f(1) = 0$;\n\\item $f^{(n)}(0) = f^{(n)}(1) = 0$ for $n = \\overline{1,N}$\n\\end{itemize}\n\nI propose two families of such functions. One is polynomial in $x$ and another is trigonometric polynomial. Let's start with\npolynomial in $x$. Define $f(x)$ like so:\n\\begin{equation}\n  \\label{polydef}\n  f(x) = 1 - x^{N+1}L_{1}(x) = (1-x)^{N+1}L_{2}(x)\n\\end{equation}\nThe first definition satisfies the conditions at point $x = 0$ and the second at point $x = 1$. We get an equation:\n\\begin{equation}\n  \\label{bezout1}\n  (1-x)^{N+1}L_{2}(x) + x^{N+1}L_{1}(x) = 1\n\\end{equation}\nPolynomials $x^{N+1}$ and $(1-x)^{N+1}$ are relatively prime, so \\ref{bezout1} is so-called Bezout equation. You can rewrite it\nlike so:\n\\begin{equation}\n  (1-x)^{N+1}P(x) + x^{N+1}P(1-x) = 1\n\\end{equation}\nIt admits a solution:\n\\begin{equation}\n  \\label{bezoutsol}\n  P(x) = \\sum_{n=0}^{N}C_{N+n}^{n}x^{n}\n\\end{equation}\nSubstitute now $P(1-x)$ from \\ref{bezoutsol} to the first definition of $f(x)$ (remembrer, $L_1(x) = P(1-x)$) in \\ref{polydef}. You will get:\n\\begin{equation}\n  \\label{poly}\n  f(x) = 1 - x^{N+1}\\sum_{n=0}^{N}C_{N+n}^{n}x^n\n\\end{equation}\n\nI use this one of this family: $f(x) = 20x^7 - 70x^6 + 84x^5 - 35x^4+1$.\n\n\\textbf{TODO: Write about trigonometric polynomials}.\n\nI introduce a transition region\n$[\\frac{a\\omega_{ref}}{2} (1-b), \\frac{a\\omega_{ref}}{2} (1+b)]$, $b \\in [0,1]$ and a function that maps transition region onto\nsegment $[0,1]$: $g(\\omega) = \\frac{\\omega}{ab\\omega_{ref}} - \\frac{1-b}{2b}$. Then I define a new filter where $f(x)$ is one of\n\\ref{poly}:\n\n\\begin{equation}\n\\label{notsoideal}\nF(\\xi) = \\left\\{\n\\begin{array}{rl}\n1 & \\text{if } \\left|\\xi\\right| < a\\omega_{ref}(1-b)/2,\\\\\nf(g(\\left|\\xi\\right|)) & \\text{if } a\\omega_{ref}(1-b)/2 \\leq \\left|\\xi\\right| \\leq a\\omega_{ref}(1+b)/2,\\\\\n0 & \\text{otherwise}.\n\\end{array} \\right.\n\\end{equation}\nIt has a transition region which width is $\\frac{ab\\omega_{ref}}{2}$, but it has $N$ first continuous derivatives in all of its\npoints. Fourier series for it will converge much faster and without Gibbs phenomenon.\n\nAlthough decomposition coefficients can be calculated\nexplicitly, I prefer to compute them numerically by the \\textbf{Simpson's formula} which is a method of precise numerical integration.\n\n\\section{Error estimation}\n\\textbf{This section may be out of date.}\nIt also would be great to know how close Fourier series decomposition is to \\ref{notsoideal} or to another filter with another polynomial. Remember, that decomposed signal is in the following form:\n\\begin{equation}\nF(\\xi) = \\phi_{0} + \\sum_{n=1}^{N}\\frac{\\phi_{n}}{2}cos(\\frac{2\\pi}{\\omega_{ref}}n\\xi)\n\\end{equation}\nA global minimum of that is somewhere \"to the right\" of the frequency $\\xi = \\omega_{0}+\\epsilon$ which is $\\xi = a\\omega_{ref}/2+\\epsilon$. I suggest the value $\\left|F(\\xi_{min})\\right|$ as an error measure. To find\na minimum of $F(\\xi)$ you need to find its differential and equate it to zero. You will get an equation (a constant multiplier, $\\frac{\\pi}{\\omega_{ref}}$, is dropped):\n\\begin{equation}\nF'(\\xi) = \\sum_{n=1}^{N}\\phi_{n}n sin(\\frac{2 \\pi}{\\omega_{ref}}n\\xi) = 0\n\\end{equation}\nAs I said, we will search for a solution on a segment $\\xi \\in [\\omega_{0}+\\epsilon, \\omega_{ref}/2]$. We need only one solution, which corresponds to the global minimum. $F(\\xi)$ is decreasing in the range\n$\\xi \\in [\\omega_{0}-\\epsilon, \\omega_{0}+\\epsilon]$ and continues to decrease for some $\\xi \\geq \\omega_{0} + \\epsilon$ \"by inertia\". So, $F'(\\xi)$ is negative in this range and equals to zero in the point where\n$F(\\xi)$ is minimal. $F'(\\xi)$ behaves in that region almost linearly, so you can find a tangent to it in the point $\\xi = \\omega_{0} + \\epsilon$ and find out where it becomes a zero. This is a first step of so called\n\\textbf{Newton's method} of numerically solving equations like $f(x)=0$ for monotonous $f(x)$. I will restrict myself to that only step, because, as I said, $F'(x)$ behaves almost linearly in the region of interest.\n\nDefine $b$, so that $\\epsilon = ab\\omega_{ref}/2$. Then our tangent is defined as follows:\n\\begin{equation}\nT(\\xi) = A(\\xi - \\omega_{0} - \\epsilon) + B\n\\end{equation}\nwith $\\xi_{min} - \\omega_{0} - \\epsilon = -B/A$. I calculated $B/A$ to be\n\\begin{equation}\nB/A = \\frac{\\sum_{n=1}^{N}\\phi_{n}n sin(\\pi n a (1 + b))}{\\sum_{n=1}^{N}\\phi_{n}n^{2}cos(\\pi n a (1 + b))}\n\\end{equation}\nAn estimated minimum value of $F(\\xi_{min})$ is\n\\begin{equation}\nF(\\xi_{min}) = \\phi_{0} + \\sum_{n=1}^{N}\\phi_{n}cos(\\pi n (a+b-\\pi B/A)\n\\end{equation}\n\nOn \\ref{errorpic} you can see a graph which represents an error estimation for two types of filters, one of them being \\ref{notsoideal} (solid line) and another is the tenth order polynomial which I use (dash line).\n\\begin{figure}[h!]\n\\includegraphics[width=0.5\\linewidth,angle=-90]{error.ps}\n\\caption{The error $\\left|F(\\xi_{min})\\right|(N)$ of Fourier series decomposition.}\n\\label{errorpic}\n\\end{figure}\n\nBelow on \\ref{filterpic} I also include a Fourier transform and a partial sum of the first 30 members of its Fourier series decomposition for my filter with $a=1/2, b=1/7$. Practically, it's better to use $N>50$ to get\nmore or less acceptable quality.\n\\begin{figure}[h!]\n\\includegraphics[width=200pt,angle=-90]{approx.ps}\n\\caption{The Fourier transform of my filter (solid) and its Fourier series decomposition (the first 30 members, dashed line).}\n\\label{filterpic}\n\\end{figure}\n\n\\section{Downsampling in cl-audio-downsample}\nSo, after your signal is filtered to cut all frequencies which cannot be saved with new sampling rate (suppose, you choose a filter with parameter $a$), you can just pick every $a^{-1}$-th sample, where\n$a^{-1}$ is an integral ratio of an old sampling rate to a new sampling rate, $a^{-1} = f_{ref_{old}}/f_{ref_{new}}, a^{-1} \\in \\mathbb{N}$. Also you can resample to any sampling rate with the ratio\n$N/M = f_{ref_{old}}/f_{ref_{new}}$ first inserting $N-1$ zeros between your original samples, when filtering that signal with $a=1/M$, when taking every $M$-th sample from the result. But there is more\nefficient methods to do such a resampling, so my library supports only downsampling to an integral ratio of sampling frequencies (e.g. from 192kHz to 48kHz, or from 96KHz to 48kHz). Surely, it can be extended\nto support any ratio, but why bother?\n\n\\section{Quality}\n\\textbf{This section may be out of date.}\nIn this section I will provide some comparison data as some measure of quality. I compared my resampler with swr, a standard resampler for FFmpeg. I used a sine wave with a frequency starting at 440Hz and increasing\nto 96kHz at exponential rate as an input signal. The input signal is taken with sampling rate 192kHz and its downsampled version has a sampling rate 48kHz. The signal was generated with SuperCollider, and spectrograms\nbelow was generated by SoX. My library easy-audio was used to read from and write to wav audio files.\n\n\\ref{spectro} is a spectrogram of the original sine wave (up) followed by spectograms of resampled versions (bottom). I used two settings for my resampler: with a transition range $b=1/7$ and a fixed filter order $N=50$\nand with a transition range $b=1/20$ and an error $0.0001$. Settings which use fixed $N$ can be considered \"fast\" settings, and settings with \"floating\" $N$ and a particular error can be considered the \"best\".\n\\begin{figure}[h!]\n  \\begin{subfigure}{\\linewidth}\n  \\includegraphics[width=\\linewidth]{original.png}\\hfill\n  \\caption{A spectrogram of the original wave.}\n  \\end{subfigure}\\par\\medskip\n  \\begin{subfigure}{\\linewidth}\n  \\includegraphics[width=.4\\linewidth]{swr50.png}\\hfill\n  \\includegraphics[width=.4\\linewidth]{swr200.png}\\hfill\n  \\caption{Some spectrograms of the signal resampled with FFmpeg's swr}\n  \\end{subfigure}\\par\\medskip\n  \\begin{subfigure}{\\linewidth}\n  \\includegraphics[width=.4\\linewidth]{accurate.png}\\hfill\n  \\includegraphics[width=.4\\linewidth]{fast.png}\\hfill\n  \\caption{The signal resampled with cl-audio-downsample with the parameters $b=1/20, error=0.0001$ (left) and $b=1/7, N=50$ (right).}\n  \\end{subfigure}\\par\\medskip\n  \\caption{Spectrograms of the original signal and its downsampled versions.}\n  \\label{spectro}\n\\end{figure}\n\n\\section{Conclusion}\n\\textbf{This section may be out of date.}\nAlthough cl-audio-downsample shows test results comparable to FFmpeg's swr, it's no match for soxr resampler. It also has implementation limitations, e.g. it cannot downsample from 96kHz to 44.1kHZ (only to 48KHz). What's more\nimportant, is that I observed that aliasing does not vanish much when you choose $b: 0 < b < 1/20$ with some constant error. I cannot explain it now, maybe it's just a computational error. It's also not very fast, but this is\nmost certainly a flaw of the implementation.\n\n\\end{document}\n", "meta": {"hexsha": "fffb570572126b3a2c45e28697f2235b42165e52", "size": 22440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/explanation.tex", "max_stars_repo_name": "shamazmazum/cl-audio-resample", "max_stars_repo_head_hexsha": "0b176e5c08597b0afa79d65a1a1a280693d65563", "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/explanation.tex", "max_issues_repo_name": "shamazmazum/cl-audio-resample", "max_issues_repo_head_hexsha": "0b176e5c08597b0afa79d65a1a1a280693d65563", "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/explanation.tex", "max_forks_repo_name": "shamazmazum/cl-audio-resample", "max_forks_repo_head_hexsha": "0b176e5c08597b0afa79d65a1a1a280693d65563", "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": 68.623853211, "max_line_length": 226, "alphanum_fraction": 0.7107843137, "num_tokens": 7119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.6791372597800744}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath,amssymb}\n\\usepackage{mathpartir}\n\n\\newcommand{\\Type}{\\mathsf{Type}}\n\\newcommand{\\ctx}{\\Gamma}\n\\newcommand{\\emptyctx}{\\cdot}\n\\newcommand{\\isctx}[1]{#1\\ \\mathsf{ctx}}\n\n\\newcommand{\\evalto}{\\Longrightarrow}\n\n\\newcommand{\\jdg}[3]{#1 : #3 \\; \\left[#2\\right]}\n\\newcommand{\\isfresh}[1]{\\mathsf{fresh}\\;#1}\n\\newcommand{\\of}[1][]{:_{#1}}\n\n\\newcommand{\\prd}[1]{\\Pi #1 \\,.\\,}\n\\newcommand{\\Eq}[3][]{\\mathsf{Eq}_{#1}(#2, #3)}\n\\newcommand{\\refl}[2][]{\\mathsf{refl}_{#1}\\,#2}\n\\newcommand{\\lam}[1]{\\lambda #1 \\,.\\,}\n\\newcommand{\\abs}[1]{#1 .}\n\\newcommand{\\app}[3][]{#2 \\mathrel{@}^{#1} #3}\n\n\\newcommand{\\subst}[2]{\\{#1\\}#2}\n\n\\newcommand{\\anon}{\\_}\n\n\\newcommand{\\join}{\\bowtie}\n\\newcommand{\\splitctx}{\\rightsquigarrow}\n\\newcommand{\\ent}[1][]{\\vdash_{#1}}\n\n\\newcommand{\\bnfis}{\\mathbin{{:}{:}{=}}}\n\\newcommand{\\bnfor}{\\mathbin{\\mid}}\n\n\\newcommand{\\val}[1]{\\mathtt{val}\\;#1}\n\\newcommand{\\typ}{\\mathtt{Type}}\n\\newcommand{\\letin}[1]{\\mathtt{let}\\;#1\\;\\mathtt{in}\\;}\n\\newcommand{\\fra}[1]{\\mathtt{forall}\\;#1\\,\\mathtt{,}\\,}\n\\newcommand{\\equ}[2]{#1 \\;\\text{\\texttt{==}}\\; #2}\n\\newcommand{\\rfl}[1]{\\mathtt{refl}\\; #1}\n\\newcommand{\\lmb}[1]{\\mathtt{lambda}\\; #1 \\,.\\,}\n\\newcommand{\\apl}[2]{#1 \\;\\texttt{@}\\; #2}\n\n\\begin{document}\n\n\\section{Type theory}\n\n\\subsection{Syntax}\n\n\\begin{align*}\n  \\text{Expression}\\ e, A, B \\\n    \\bnfis \\ & x                              & & \\text{variable}\\\\\n    \\bnfor \\ & \\Type                          & & \\text{type of types}\\\\\n    \\bnfor \\ & \\prd{x : A} B                  & & \\text{product\\footnotemark} \\\\\n    \\bnfor \\ & \\Eq[A]{e_1}{e_2}               & & \\text{strict equality} \\\\\n    \\bnfor \\ & \\refl[A]{e}                    & & \\text{reflexivity} \\\\\n    \\bnfor \\ & \\lam{x : A \\,.\\, B} e          & & \\text{$\\lambda$-abstraction\\footnotemark} \\\\\n    \\bnfor \\ & \\app[\\abs{x : A} B]{e_1}{e_2}  & & \\text{application\\footnotemark}\n  \\\\\n  \\text{Context}\\ \\ctx\\\n     \\bnfis \\ & \\emptyctx                     & & \\text{empty context} \\\\\n     \\bnfor \\ & \\ctx, x : A                   & & \\text{context extension}\n\\end{align*}\n%\n\\footnotetext{$x$ is bound in $B$}%\n\\footnotetext{$x$ is bound in $B$ and $e$}%\n\\footnotetext{$x$ is bound in $B$}%\n%\nNote that both application and $\\lambda$-abstraction are tagged with full typing information.\n\n\n\\subsection{Judgements}\n\n\\begin{align*}\n  & \\isctx{\\ctx}                & & \\text{$\\ctx$ is a context}  \\\\\n  & \\ctx \\ent e \\of A         & & \\text{$e$ has type $A$}  \\\\\n  & \\ctx \\ent e_1 = e_2 \\of A & & \\text{$e_1$ and $e_2$ of type $A$ are equal}\n\\end{align*}\n\n\\subsection{Inference rules}\n\n\\subsubsection{Contexts}\n\nThe set of variables bound by $\\Gamma$ is denoted by $|\\Gamma|$.\n\n\\begin{mathpar}\n  \\infer[ctx-empty]\n  { }\n  {\\isctx{\\emptyctx}}\n\n  \\infer[ctx-extend]\n  {\\isctx{\\ctx}\n   \\\\\n   \\ctx \\ent A : \\Type\n   \\\\\n   x \\not\\in |\\ctx|}\n  {\\isctx{(\\ctx, x \\of A)}}\n\\end{mathpar}\n\n\\subsubsection{Types}\n\n\\begin{mathpar}\n  \\infer[type-type]\n  { }\n  {\\ctx \\ent \\Type : \\Type}\n\n  \\infer[type-pi]\n  {\\ctx \\ent A : \\Type\n  \\\\\n  \\ctx, x : A \\ent B : \\Type\n  }\n  {\\ctx \\ent (\\prd{x : A} B) \\of \\Type}\n\n  \\infer[type-eq]\n  {\\ctx \\ent A : \\Type \\\\\n   \\ctx \\ent e_1 : A \\\\\n   \\ctx \\ent e_2 : A}\n  {\\ctx \\ent \\Eq[A]{e_1}{e_2} : \\Type}\n\n\\end{mathpar}\n\n\\subsubsection{Terms}\n\n\\begin{mathpar}\n  \\infer[term-var]\n  {(x : A) \\in \\Gamma}\n  {\\Gamma \\ent x : A}\n\n  \\infer[term-refl]\n  {\\ctx \\ent A : \\Type \\\\\n   \\ctx \\ent e : A}\n  {\\ctx \\ent (\\refl[A]{e}) : \\Eq[A]{e}{e}}\n\n  \\infer[term-fun]\n  {\\ctx \\ent A \\of \\Type \\\\\n   \\ctx, x : A \\ent B : \\Type \\\\\n   \\ctx, x : A \\ent e : B\n  }\n  {\\ctx \\ent (\\lam{x : A \\,.\\, B} e) : \\prd{x : A} B}\n\n  \\infer[term-app]\n  {\\ctx \\ent A : \\Type \\\\\n   \\ctx, x : A \\ent B : \\Type \\\\\n   \\ctx \\ent e_1 : \\prd{x : A} B \\\\\n   \\ctx \\ent e_2 : A}\n   {\\ctx \\ent \\app[\\abs{x : A} B]{e_1}{e_2} : \\subst{e_2/x}{B}}\n\\end{mathpar}\n\n\n\\subsubsection{Equality}\n\n\\begin{mathpar}\n  \\infer[eq-reflection]\n  {\\ctx \\ent e : \\Eq[A]{e_1}{e_2}}\n  {\\ctx \\ent e_1 = e_2 : A}\n\n  \\infer[eq-type]\n  {\\ctx \\ent e : A \\\\\n   \\ctx \\ent A = B : \\Type}\n  {\\ctx \\ent e : B}\n\n  \\infer[eq-eq]\n  {\\ctx \\ent e_1 = e_2 : A \\\\\n   \\ctx \\ent A = B : \\Type}\n  {\\ctx \\ent e_1 = e_2 : B}\n\n  \\infer[eq-subst]\n  {\\ctx, x : A, y : A \\ent B : \\Type \\\\\n   \\ctx, z : A \\ent e : \\subst{z/x,z/y}{B} \\\\\n   \\ctx \\ent e_1 = e_2 : A\n  }\n  {\\ctx \\ent \\subst{e_1/z}{e} : \\subst{e_1/x,e_2/y}{B}}\n\\end{mathpar}\n\n\\subsubsection{Congruence rules}\n\n\\begin{mathpar}\n  \\infer[cong-pi]\n  {\\ctx \\ent A = A' : \\Type \\\\\n   \\ctx, x : A \\ent B = B' : \\Type}\n  {\\ctx \\ent (\\prd{x : A} B) = (\\prd{x : A'} B') : \\Type}\n\n  \\infer[cong-refl]\n  {\\ctx \\ent A = A' : \\Type \\\\\n   \\ctx \\ent e = e' : A }\n  {\\ctx \\ent \\refl[A]{e} = \\refl[A']{e'} : \\Eq[A]{e}{e}}\n\n  \\infer[cong-eq]\n  {\\ctx \\ent A = A' : \\Type \\\\\n   \\ctx \\ent e_1 = e_1' : A \\\\\n   \\ctx \\ent e_2 = e_2' : A\n   }\n  {\\ctx \\ent (\\Eq[A]{e_1}{e_2}) = (\\Eq[A']{e'_1}{e'_2}) : \\Type}\n\\end{mathpar}\n\n\n\\section{The meta language}\n\n\\begin{align*}\n  \\text{Value}\\ v\\\n    \\bnfis \\ & x                              & & \\text{variable}\\\\\n    \\bnfor \\ & (\\ctx \\ent e : A)              & & \\text{judgement}\n  \\\\\n  \\text{Computation}\\ c\\\n    \\bnfis \\ & \\val{v}                        & & \\text{value}\\\\\n    \\bnfor \\ & \\letin{x = c_1} c_2            & & \\text{binding}\\\\\n    \\bnfor \\ & \\typ                          & & \\text{type of types}\\\\\n    \\bnfor \\ & \\fra{x} v                      & & \\text{product} \\\\\n    \\bnfor \\ & \\equ{v_1}{v_2}                 & & \\text{strict equality} \\\\\n    \\bnfor \\ & \\rfl{v}                        & & \\text{reflexivity} \\\\\n    \\bnfor \\ & \\lmb{x} v                      & & \\text{$\\lambda$-abstraction} \\\\\n    \\bnfor \\ & \\apl{v_1}{v_2}                 & & \\text{application}\n\\end{align*}\n\n\n\\section{Operational semantics of the kernel}\n\n\\begin{mathpar}\n  \\infer[eval-Type]\n  { }\n  {\\Type \\evalto \\jdg{\\Type}{\\emptyctx}{\\Type}}\n\n  \\infer[eval-Var]\n  { \\isfresh{\\alpha}}\n  { x \\evalto \\jdg{x}{\\alpha \\of[x] \\Type, x \\of \\alpha}{\\alpha}}\n\n  \\infer[eval-Prod]\n  {\n  c_1 \\evalto \\jdg{e_1}{\\ctx_1}{A_1} \\\\\n  c_2 \\evalto \\jdg{e_2}{\\ctx_2}{A_2} \\\\\n  \\ctx_2 \\splitctx (\\ctx'_2, x \\of[\\emptyset] B)\n  }\n  {\n  \\prd{x : c_1} c_2\n  \\evalto\n  \\jdg\n    {\\prd{x : e_1} e_2}\n    {\\begin{aligned}\n     & \\ctx_1 \\join \\ctx'_2, \\\\\n    & \\anon \\of[\\epsilon_1] \\Eq[\\Type]{A_1}{\\Type}, \\\\\n    & \\anon \\of \\prd{x : B} (\\Eq[\\Type]{A_2}{\\Type}),\\\\\n    & \\epsilon_1 \\of \\Eq[\\Type]{e_1}{B}\n     \\end{aligned}\n    }{\n     \\Type\n    }\n  }\n\n  \\infer[eval-Eq]\n  {\n    c_1 \\evalto \\jdg{e_1}{\\ctx_1}{A_1} \\\\\n    c_2 \\evalto \\jdg{e_2}{\\ctx_2}{A_2} \\\\\n    \\isfresh{\\alpha}\n  }{\n    \\Eq{c_1}{c_2}\n    \\evalto\n    \\jdg\n    {\n      \\Eq[\\alpha]{e_1}{e_2}\n    }{\n      \\ctx_1 \\join \\ctx_2,\n      \\alpha \\of[\\epsilon_1,\\epsilon_2] \\Type,\n      \\epsilon_1 \\of \\Eq[\\Type]{\\alpha}{A_1},\n      \\epsilon_2 \\of \\Eq[\\Type]{\\alpha}{A_2}\n    }{\n      \\Type\n    }\n  }\n\n  \\infer[eval-Refl]\n  {c \\evalto \\jdg{e}{\\ctx}{A}}\n  {\\refl{c}\n   \\evalto\n   \\jdg\n   {\\refl[A]{e}}\n   {\\ctx}\n   {(\\Eq[A]{e}{e})}\n  }\n\n  \\infer[eval-Fun]\n  {c \\evalto \\jdg{e}{\\ctx}{A} \\\\\n   \\ctx \\splitctx (\\ctx', x \\of[\\emptyset] B)\n  }{\n    (\\lam{x} c)\n    \\evalto\n    \\jdg\n    {(\\lam{x:B}{e})}\n    {\\ctx'}\n    {(\\prd{x : B} A)}\n  }\n\n  \\infer[eval-App]\n  {\n   c_1 \\evalto \\jdg{e_1}{\\ctx_1}{A_1} \\\\\n   c_2 \\evalto \\jdg{e_2}{\\ctx_2}{A_2} \\\\\n   \\isfresh{\\alpha}\n  }\n  {\n   \\app{c_1}{c_2}\n   \\evalto\n   \\jdg\n   {\n    (\\app[\\abs{x : \\alpha} {\\app[\\abs{\\anon : \\alpha} \\Type]{\\beta}{x}}]{e_1}{e_2})\n   }{\n    \\begin{aligned}\n    & \\ctx_1 \\join \\ctx_2, \\\\\n    & \\alpha \\of[\\epsilon_1,\\epsilon_2, \\beta] \\Type, \\\\\n    & \\beta \\of[\\epsilon_1] \\alpha \\to \\Type, \\\\\n    & \\epsilon_1 \\of \\Eq[\\Type]{A_1}{\\prd{x : \\alpha} \\app[\\abs{\\anon : \\alpha} \\Type]{\\beta}{x}}, \\\\\n    & \\epsilon_2 \\of \\Eq[\\Type]{\\alpha}{A_2}\n    \\end{aligned}\n   }{\n    (\\app[\\abs{\\anon : \\alpha} \\Type]{\\beta}{e_2})\n   }\n  }\n\n\n\\end{mathpar}\n\\end{document}\n", "meta": {"hexsha": "e2bf816573ec449fde669a647258521c92790aee", "size": 7842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archive/doc/2015-03 - possible-hippy-variant-of-theory.tex", "max_stars_repo_name": "Andromedans/andromeda", "max_stars_repo_head_hexsha": "761b0fd07cab5cbcf68a06e79b7f27301826ca82", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2015-11-10T17:16:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T16:08:42.000Z", "max_issues_repo_path": "archive/doc/2015-03 - possible-hippy-variant-of-theory.tex", "max_issues_repo_name": "anjapetkovic/andromeda", "max_issues_repo_head_hexsha": "a5c678450e6c6d4a7cd5eee1196bde558541b994", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 244, "max_issues_repo_issues_event_min_datetime": "2015-11-10T16:20:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-06T03:55:46.000Z", "max_forks_repo_path": "archive/doc/2015-03 - possible-hippy-variant-of-theory.tex", "max_forks_repo_name": "anjapetkovic/andromeda", "max_forks_repo_head_hexsha": "a5c678450e6c6d4a7cd5eee1196bde558541b994", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2015-11-10T16:15:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-16T08:08:23.000Z", "avg_line_length": 24.50625, "max_line_length": 101, "alphanum_fraction": 0.5042081102, "num_tokens": 3219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807406, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.679059687290713}}
{"text": "\\chapter{Things Galois}\n%This chapter is mostly optional.\n%Read the first two sections and then decide\n%whether you want to read the rest of this chapter.\n\n\\section{Motivation}\n\\prototype{$\\QQ(\\sqrt2)$ and $\\QQ(\\cbrt{2})$.}\nThe key idea in Galois theory is that of \\emph{embeddings},\nwhich give us another way to get at the idea of the ``conjugate'' we described earlier.\n\nLet $K$ be a number field.\nAn \\vocab{embedding} $\\sigma : K \\injto \\CC$, is an \\emph{injective field homomorphism}:\nit needs to preserve addition and multiplication,\nand in particular it should fix $1$.\n\\begin{ques}\n\tShow that in this context, $\\sigma(q) = q$ for any rational number $q$.\n\\end{ques}\n\n\\begin{example}\n\t[Examples of embeddings]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $K = \\QQ(i)$, the two embeddings of $K$ into $\\CC$ are\n\t\t$z \\mapsto z$ (the identity) and $z \\mapsto \\ol z$ (complex conjugation).\n\t\t\\ii If $K = \\QQ(\\sqrt 2)$, the two embeddings of $K$ into $\\CC$ are\n\t\t$a+b\\sqrt 2 \\mapsto a+b\\sqrt 2$ (the identity) and $a+b\\sqrt 2 \\mapsto a-b\\sqrt 2$ (conjugation).\n\t\t\\ii If $K = \\QQ(\\cbrt 2)$, there are three embeddings:\n\t\t\\begin{itemize}\n\t\t\t\\ii The identity embedding, which sends $1 \\mapsto 1$ and $\\cbrt 2 \\mapsto \\cbrt 2$.\n\t\t\t\\ii An embedding which sends $1 \\mapsto 1$ and $\\cbrt 2 \\mapsto \\omega \\cbrt 2$,\n\t\t\twhere $\\omega$ is a cube root of unity.\n\t\t\tNote that this is enough to determine the rest of the embedding.\n\t\t\t\\ii An embedding which sends $1 \\mapsto 1$ and $\\cbrt 2 \\mapsto \\omega^2 \\cbrt 2$.\n\t\t\\end{itemize}\n\t\\end{enumerate}\n\\end{example}\n\nI want to make several observations about these embeddings,\nwhich will form the core ideas of Galois theory.\nPay attention here!\n\n\\begin{itemize}\n\\ii\nFirst, you'll notice some duality between roots: in the first example, $i$ gets sent to $\\pm i$,\n$\\sqrt 2$ gets sent to $\\pm \\sqrt 2$, and $\\cbrt 2$ gets sent to the other roots of $x^3-2$.\nThis is no coincidence, and one can show this occurs in general.\nSpecifically, suppose $\\alpha$ has minimal polynomial\n\\[ 0 = c_n \\alpha^n + c_{n-1} \\alpha^{n-1} + \\dots + c_1\\alpha + c_0 \\]\nwhere the $c_i$ are rational.\nThen applying any embedding $\\sigma$ to both sides gives\n\\begin{align*}\n\t0 &= \\sigma(c_n \\alpha^n + c_{n-1} \\alpha^{n-1} + \\dots + c_1\\alpha + c_0) \\\\\n\t% &= \\sigma(c_n \\alpha^n) + \\sigma(c_{n-1} \\alpha^{n-1})\n\t% + \\dots + \\sigma(c_1\\alpha) + \\sigma(c_0) \\\\\n\t&= \\sigma(c_n) \\sigma(\\alpha)^n + \\sigma(c_{n-1}) \\sigma(\\alpha)^{n-1}\n\t+ \\dots + \\sigma(c_1)\\sigma(\\alpha) + \\sigma(c_0) \\\\\n\t&= c_n \\sigma(\\alpha)^n + c_{n-1} \\sigma(\\alpha)^{n-1} + \\dots + c_1\\sigma(\\alpha) + c_0\n\\end{align*}\nwhere in the last step we have used the fact that $c_i \\in \\QQ$, so they are fixed by $\\sigma$.\n\\emph{So, roots of minimal polynomials go to other roots of that polynomial.}\n\n\\ii\nNext, I want to draw out a contrast between the second and third examples.\nSpecifically, in example (b) where we consider embeddings $K = \\QQ(\\sqrt 2)$\nto $\\CC$.  The image of these embeddings lands entirely in $K$: that is, we\ncould just as well have looked at $K \\to K$ rather than looking at $K \\to \\CC$.\nHowever, this is not true in (c): indeed $\\QQ(\\cbrt 2) \\subset \\RR$,\nbut the non-identity embeddings have complex outputs!\n\nThe key difference is to again think about conjugates.\nKey observation:\n\\begin{moral}\n\tThe field $K = \\QQ(\\cbrt 2)$ is ``deficient'' because the minimal polynomial $x^3-2$\n\thas two other roots $\\omega \\cbrt{2}$ and $\\omega^2 \\cbrt{2}$ not contained in $K$.\n\\end{moral}\nOn the other hand $K = \\QQ(\\sqrt 2)$ is just fine because both roots of $x^2-2$ are contained inside $K$.\nFinally, one can actually fix the deficiency in $K = \\QQ(\\cbrt 2)$ by completing it to a field $\\QQ(\\cbrt 2, \\omega)$.\nFields like $\\QQ(i)$ or $\\QQ(\\sqrt 2)$ which are ``self-contained'' are called\n\\emph{Galois extensions}, as we'll explain shortly.\n\n\\ii\nFinally, you'll notice that in the examples above, \\emph{the number of embeddings from $K$ to $\\CC$\nhappens to be the degree of $K$}.\nThis is an important theorem, \\Cref{thm:n_embeddings}.\n\\end{itemize}\n\nIn this chapter we'll develop these ideas in full generality, for any field other than $\\QQ$.\n\n\\section{Field extensions, algebraic closures, and splitting fields}\n\\prototype{$\\QQ(\\cbrt 2)/\\QQ$ is an extension, $\\CC$ is an algebraic closure of any number field.}\n\nFirst, we define a notion of one field sitting inside another,\nin order to generalize the notion of a number field.\n\\begin{definition}\n\tLet $K$ and $F$ be fields.\n\tIf $F \\subseteq K$, we write $K/F$ and say $K$ is a\n\t\\vocab{field extension} of $F$.\n\t\n\tThus $K$ is automatically an $F$-vector space\n\t(just like $\\QQ(\\sqrt 2)$ is automatically a $\\QQ$-vector space).\n\tThe \\vocab{degree} is the dimension of this space, denoted $[K:F]$.\n\tIf $[K:F]$ is finite, we say $K/F$ is a \\vocab{finite (field) extension}.\n\\end{definition}\nThat's really all. There's nothing tricky at all.\n\n\\begin{ques}\n\tWhat do you call a finite extension of $\\QQ$?\n\\end{ques}\n\nDegrees of finite extensions are multiplicative.\n\\begin{theorem}[Field extensions have multiplicative degree]\n\tLet $F \\subseteq K \\subseteq L$ be fields with $L/K$, $K/F$ finite. Then\n\t\\[ [L:K][K:F] = [L:F]. \\]\n\\end{theorem}\n\\begin{proof}\n\tBasis bash: you can find a basis of $L$ over $K$,\n\tand then expand that into a basis $L$ over $F$.\n\t(Diligent readers can fill in details.)\n\\end{proof}\n\nNext, given a field (like $\\QQ(\\cbrt2)$)\nwe want something to embed it into (in our case $\\CC$).\nSo we just want a field that contains all the roots of all the polynomials:\n\\begin{theorem}[Algebraic closures]\n\tLet $F$ be a field.\n\tThen there exists a field extension $\\ol F$ containing $F$, called an \\vocab{algebraic closure},\n\tsuch that all polynomials in $\\ol F[x]$ factor completely.\n\\end{theorem}\n\\begin{example}\n\t[$\\CC$]\n\t$\\CC$ is an algebraic closure of $\\QQ$, $\\RR$ and even itself.\n\\end{example}\n\\begin{abuse}\n\tSome authors also require the algebraic closure to be \\emph{minimal by inclusion}:\n\tfor example, given $\\QQ$ they would want only $\\ol\\QQ$ (the algebraic numbers).\n\tIt's a theorem that such a minimal algebraic closure is unique,\n\tand so these authors will refer to \\emph{the} algebraic closure of $K$.\n\n\tI like $\\CC$, so I'll use the looser definition.\n\\end{abuse}\n\n\\section{Embeddings into algebraic closures for number fields}\nNow that I've defined all these ingredients, I can prove:\n\\begin{theorem}[The $n$ embeddings of a number field]\n\t\\label{thm:n_embeddings}\n\tLet $K$ be a number field of degree $n$.\n\tThen there are exactly $n$ field homomorphisms $K \\injto \\CC$,\n\tsay $\\sigma_1, \\dots, \\sigma_n$ which fix $\\QQ$.\n\\end{theorem}\n\\begin{remark}\n\tNote that a nontrivial homomorphism of fields is necessarily injective\n\t(the kernel is an ideal).\n\tThis justifies the use of ``$\\injto$'', and we call each $\\sigma_i$ an\n\t\\vocab{embedding} of $K$ into $\\CC$.\n\\end{remark}\n\\begin{proof}\n\tThis is actually kind of fun!\n\tRecall that any irreducible polynomial over $\\QQ$ has distinct roots (\\Cref{lem:irred_complex}).\n\tWe'll adjoin elements $\\alpha_1, \\alpha_2, \\dots, \\alpha_m$ one at a time to $\\QQ$,\n\tuntil we eventually get all of $K$, that is,\n\t\\[ K = \\QQ(\\alpha_1, \\dots, \\alpha_n). \\]\n\tDiagrammatically, this is\n\t\\begin{diagram}\n\t\t\\QQ & \\rInj & \\QQ(\\alpha_1) & \\rInj & \\QQ(\\alpha_1, \\alpha_2) & \\rInj & \\dots & \\rInj & K \\\\\n\t\t\\dInj^\\id && \\dInj^{\\tau_1} && \\dInj^{\\tau_2} && \\dots && \\dInj_{\\tau_m = \\sigma} \\\\\n\t\t\\CC & \\rTo & \\CC & \\rTo & \\CC & \\rTo & \\dots & \\rTo & \\CC \\\\\n\t\\end{diagram}\n\n\tFirst, we claim there are exactly \\[ [\\QQ(\\alpha_1) : \\QQ] \\] ways to pick $\\tau_1$.\n\tObserve that $\\tau_1$ is determined by where it sends $\\alpha_1$ (since it has to fix $\\QQ$).\n\tLetting $p_1$ be the minimal polynomial of $\\alpha_1$, we see that there are $\\deg p_1$ choices for $\\tau_1$,\n\tone for each (distinct) root of $p_1$. That proves the claim.\n\n\tSimilarly, given a choice of $\\tau_1$, there are\n\t\\[ [\\QQ(\\alpha_1, \\alpha_2) : \\QQ(\\alpha_1)] \\]\n\tways to pick $\\tau_2$.\n\t(It's a little different: $\\tau_1$ need not be the identity.\n\tBut it's still true that $\\tau_2$ is determined by where it sends $\\alpha_2$,\n\tand as before there are $[\\QQ(\\alpha_1, \\alpha_2) : \\QQ(\\alpha_1)]$ possible ways.)\n\n\tMultiplying these all together gives the desired $[K:\\QQ]$.\n\\end{proof}\n\\begin{remark}\n\tThe primitive element theorem actually implies that $m = 1$\n\tis sufficient; we don't need to build a whole tower.\n\tThis simplifies the proof somewhat.\n\\end{remark}\n\nIt's common to see expressions like ``let $K$ be a number field of degree $n$,\nand $\\sigma_1, \\dots, \\sigma_n$ its $n$ embeddings'' without further explanation.\nThe relation between these embeddings and the Galois conjugates is given as follows.\n\\begin{theorem}[Embeddings are evenly distributed over conjugates]\n\t\\label{thm:conj_distrb}\n\tLet $K$ be a number field of degree $n$\n\twith $n$ embeddings $\\sigma_1$, \\dots, $\\sigma_n$,\n\tand let $\\alpha \\in K$ have $m$ Galois conjugates over $\\QQ$. \n\n\tThen $\\sigma_j(\\alpha)$ is ``evenly distributed''\n\tover each of these $m$ conjugates: for any Galois conjugate $\\beta$,\n\texactly $\\frac nm$ of the embeddings send $\\alpha$ to $\\beta$.\n\\end{theorem}\n\\begin{proof}\n\tIn the previous proof, adjoin $\\alpha_1 = \\alpha$ first.\n\\end{proof}\n\nSo, now we can define the trace and norm over $\\QQ$ in a nice way:\ngiven a number field $K$, we set\n\\[\n\t\\Tr_{K/\\QQ}(\\alpha) = \\sum_{i=1}^n \\sigma_i(\\alpha)\n\t\\quad\\text{and}\\quad\n\t\\Norm_{K/\\QQ}(\\alpha) = \\prod_{i=1}^n \\sigma_i(\\alpha)\n\\]\nwhere $\\sigma_i$ are the $n$ embeddings of $K$ into $\\CC$.\n\n\\section{Everyone hates characteristic 2: separable vs irreducible}\n\\prototype{$\\QQ$ has characteristic zero, hence irreducible polynomials are separable.}\nNow, we want a version of the above theorem for any field $F$.\nIf you read the proof, you'll see that the only thing that ever uses anything about the field $\\QQ$\nis \\Cref{lem:irred_complex}, where we use the fact that\n\\begin{quote}\n\t\\itshape Irreducible polynomials over $F$ have no double roots.\n\\end{quote}\n\nLet's call a polynomial with no double roots \\vocab{separable};\nthus we want irreducible polynomials to be separable.\nWe did this for $\\QQ$ in the last chapter by taking derivatives.\nShould work for any field, right?\n\nNope.\nSuppose we took the derivative of some polynomial like $2x^3 + 24x + 9$,\nnamely $6x^2 + 24$.\nIn $\\CC$ it's obvious that the derivative of a nonconstant polynomial $f'$ isn't zero.\nBut suppose we considered the above as a polynomial in $\\FF_3$, i.e.\\ modulo $3$.\nThen the derivative is zero.\nOh, no!\n\nWe have to impose a condition that prevents something like this from happening.\n\\begin{definition}\n\tFor a field $F$, the \\vocab{characteristic} of $F$ is the smallest\n\tpositive integer $p$ such that,\n\t\\[ \\underbrace{1_F + \\dots + 1_F}_{\\text{$p$ times}} = 0 \\]\n\tor zero if no such integer $p$ exists.\n\\end{definition}\n\\begin{example}[Field characteristics]\n\tOld friends $\\RR$, $\\QQ$, $\\CC$ all have characteristic zero.\n\tBut $\\FF_p$, the integers modulo $p$, is a field of characteristic $p$.\n\\end{example}\n\\begin{exercise}\n\tLet $F$ be a field of characteristic $p$.\n\tShow that if $p > 0$ then $p$ is a prime number.\n\t(A proof is given next chapter.)\n\\end{exercise}\nWith the assumption of characteristic zero, our earlier proof works.\n\\begin{lemma}[Separability in characteristic zero]\n\tAny irreducible polynomial in a characteristic zero field is separable.\n\\end{lemma}\nUnfortunately, this lemma is false if the ``characteristic zero'' condition is dropped.\n\n\\begin{remark}\n\tThe reason it's called \\emph{separable} is (I think) this picture:\n\tI have a polynomial and I want to break it into irreducible parts.\n\tNormally, if I have a double root in a polynomial, that means it's not irreducible.\n\tBut in characteristic $p > 0$ this fails.\n\tSo inseparable polynomials are strange when you think about them: somehow\n\tyou have double roots that can't be separated from each other.\n\\end{remark}\n\nWe can get this to work for any field extension in which separability is not an issue.\n\\begin{definition}\n\tA \\vocab{separable extension} $K/F$ is one in which every irreducible\n\tpolynomial in $F$ is separable (for example, if $F$ has characteristic zero).\n\tA field $F$ is \\vocab{perfect} if any finite field extension $K/F$ is separable.\n\\end{definition}\nIn fact, as we see in the next chapter:\n\\begin{theorem}\n\t[Finite fields are perfect]\n\tSuppose $F$ is a field with finitely many elements. Then it is perfect.\n\\end{theorem}\nThus, we will almost never have to worry about separability\nsince every field we see in the Napkin is either finite or characteristic $0$.\nSo the inclusion of the word ``separable'' is mostly a formality.\n\nProceeding onwards, we obtain\n\\begin{theorem}[The $n$ embeddings of any separable extension]\n\tLet $K/F$ be a separable extension of degree $n$ and let $\\ol F$ be an algebraic closure of $F$.\n\tThen there are exactly $n$ field homomorphisms $K \\injto \\ol F$,\n\tsay $\\sigma_1, \\dots, \\sigma_n$, which fix $F$.\n\\end{theorem}\n\nIn any case, this lets us define the trace for \\emph{any} separable normal extension.\n\\begin{definition}\nLet $K/F$ be a separable extension of degree $n$, and let $\\sigma_1$, \\dots, $\\sigma_n$\nbe the $n$ embeddings into an algebraic closure of $F$. Then we define\n\\[\n\t\\Tr_{K/F}(\\alpha) = \\sum_{i=1}^n \\sigma_i(\\alpha)\n\t\\quad\\text{and}\\quad\n\t\\Norm_{K/F}(\\alpha) = \\prod_{i=1}^n \\sigma_i(\\alpha).\n\\]\nWhen $F = \\QQ$ and the algebraic closure is $\\CC$, this coincides with our earlier definition!\n\\end{definition}\n\n\n\\section{Automorphism groups and Galois extensions}\n\\prototype{$\\QQ(\\sqrt 2)$ is Galois but $\\QQ(\\cbrt 2)$ is not.}\nWe now want to get back at the idea we stated at the beginning of\nthis section that $\\QQ(\\cbrt 2)$ is deficient in a way that $\\QQ(\\sqrt 2)$ is not.\n\nFirst, we define the ``internal'' automorphisms.\n\\begin{definition}\n\tSuppose $K/F$ is a finite extension.\n\tThen $\\Aut(K/F)$ is the set of \\emph{field isomorphisms} $\\sigma : K \\to K$ which fix $F$.\n\tIn symbols\n\t\\[ \\Aut(K/F) =\n\t\t\\left\\{\n\t\t\\sigma : K \\to K \\mid\n\t\t\\text{$\\sigma$ is identity on $F$}\n\t  \\right\\}.\n\t\\]\n\tThis is a group under function composition!\n\\end{definition}\nNote that this time, we have a condition that $F$ is fixed by $\\sigma$.\n(This was not there before when we considered $F = \\QQ$, because we got it for free.)\n\n\\begin{example}[Old examples of automorphism groups]\n\tReprising the example at the beginning of the chapter in the new notation, we have:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\Aut(\\QQ(i) / \\QQ) \\cong \\Zc 2$, with elements $z \\mapsto z$ and $z \\mapsto \\ol z$.\n\t\t\\ii $\\Aut(\\QQ(\\sqrt 2) / \\QQ) \\cong \\Zc 2$ in the same way.\n\t\t\\ii $\\Aut(\\QQ(\\cbrt 2) / \\QQ)$ is the trivial group, with only the identity embedding!\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}[Automorphism group of $\\QQ(\\sqrt2,\\sqrt3)$]\n\tHere's a new example: let $K = \\QQ(\\sqrt2, \\sqrt3)$.\n\tIt turns out that $\\Aut(K/\\QQ) = \\{1, \\sigma, \\tau, \\sigma\\tau\\}$, where\n\t\\[\n\t\t\\sigma :\n\t\t\\begin{cases}\n\t\t\t\\sqrt2 &\\mapsto -\\sqrt2 \\\\\n\t\t\t\\sqrt3 &\\mapsto \\sqrt3\n\t\t\\end{cases}\n\t\t\\quad\\text{and}\\quad\n\t\t\\tau :\n\t\t\\begin{cases}\n\t\t\t\\sqrt2 &\\mapsto \\sqrt2 \\\\\n\t\t\t\\sqrt3 &\\mapsto -\\sqrt3.\n\t\t\\end{cases}\n\t\\]\n\tIn other words, $\\Aut(K/\\QQ)$ is the Klein Four Group.\n\\end{example}\n\nFirst, let's repeat the proof of the observation that these embeddings shuffle around roots\n(akin to the first observation in the introduction):\n\\begin{lemma}\n\t[Root shuffling in $\\Aut(K/F)$]\n\tLet $f \\in F[x]$, suppose $K/F$ is a finite extension,\n\tand assume $\\alpha \\in K$ is a root of $f$.\n\tThen for any $\\sigma \\in \\Aut(K/F)$, $\\sigma(\\alpha)$ is also a root of $f$.\n\t\\label{lem:root_shuffle}\n\\end{lemma}\n\\begin{proof}\n\tLet $f(x) = c_n x^n + c_{n-1}x^{n-1} + \\dots + c_0$,\n\twhere $c_i \\in F$. Thus,\n\t\\[ 0 = \\sigma(f(\\alpha)) = \\sigma\\left( c_n\\alpha^n + \\dots + c_0 \\right)\n\t= c_n\\sigma(\\alpha)^n + \\dots + c_0 = f(\\sigma(\\alpha)). \\qedhere \\]\n\\end{proof}\nIn particular, taking $f$ to be the minimal polynomial of $\\alpha$ we deduce\n\\begin{moral}\n\tAn embedding $\\sigma \\in \\Aut(K/F)$ sends an $\\alpha \\in K$\n\tto one of its various Galois conjugates (over $F$).\n\\end{moral}\n\nNext, let's look again at the ``deficiency'' of certain fields.\nLook at $K = \\QQ(\\cbrt 2)$.\nSo, again $K / \\QQ$ is deficient for two reasons.\nFirst, while there are three maps $\\QQ(\\cbrt 2) \\injto \\CC$,\nonly one of them lives in $\\Aut(K/\\QQ)$, namely the identity.\nIn other words, $\\left\\lvert \\Aut(K/\\QQ) \\right\\rvert$ is \\emph{too small}.\nSecondly, $K$ is missing some Galois conjugates ($\\omega \\cbrt 2$ and $\\omega^2 \\cbrt 2$).\n\nThe way to capture the fact that there are missing Galois conjugates\nis the notion of a splitting field.\n\\begin{definition}\n\tLet $F$ be a field and $p(x) \\in F[x]$ a polynomial of degree $n$.\n\tThen $p(x)$ has roots $\\alpha_1, \\dots, \\alpha_n$ in an algebraic closure of $F$.\n\tThe \\vocab{splitting field} of $F$ is defined as $F(\\alpha_1, \\dots, \\alpha_n)$.\n\\end{definition}\nIn other words, the splitting field is the smallest field in which $p(x)$ splits.\n\\begin{example}[Examples of splitting fields]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The splitting field of $x^2 - 5$ over $\\QQ$ is $\\QQ(\\sqrt 5)$.\n\t\tThis is a degree $2$ extension.\n\t\t\\ii The splitting field of $x^2+x+1$ over $\\QQ$ is $\\QQ(\\omega)$,\n\t\twhere $\\omega$ is a cube root of unity.\n\t\tThis is a degree $3$ extension.\n\t\t% In particular, the splitting field of $x^3-2$ is a degree \\emph{six} extension.\n\t\t\\ii The splitting field of $x^2+3x+2 = (x+1)(x+2)$ is just $\\QQ$!\n\t\tThere's nothing to do.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Splitting fields: a cautionary tale]\n\tThe splitting field of $x^3 - 2$ over $\\QQ$ is in fact\n\t\\[ \\QQ( \\cbrt 2, \\omega ) \\]\n\tand not just $\\QQ(\\cbrt 2)$!\n\tOne must really adjoin \\emph{all} the roots, and it's not necessarily the case that\n\tthese roots will generate each other.\n\n\tTo be clear:\n\t\\begin{itemize}\n\t\\ii For $x^2-5$, we adjoin $\\sqrt 5$ and this will automatically include $-\\sqrt 5$.\n\t\\ii For $x^2+x+1$, we adjoin $\\omega$ and get the other root $\\omega^2$ for free.\n\t\\ii But for $x^3-2$, if we adjoin $\\cbrt 2$,\n\twe do NOT get $\\omega\\cbrt2$ and $\\omega^2\\cbrt2$ for free.\n\tIndeed, $\\QQ(\\cbrt 2) \\subset \\RR$!\n\t\\end{itemize}\n\tNote that in particular, the splitting field of\n\t$x^3-2$ over $\\QQ$ is \\emph{degree six}, not just degree three.\n\\end{example}\n\nIn general,\n\\textbf{the splitting field of a polynomial can be an extension of degree up to $n!$}.\nThe reason is that if $p(x)$ has $n$ roots and none of them are ``related'' to each other,\nthen any permutation of the roots will work.\n\nNow, we obtain:\n\\begin{theorem}[Galois extensions are splitting]\n\tFor finite extensions $K/F$, \n\t$\\left\\lvert \\Aut(K/F) \\right\\rvert$ divides $[K:F]$,\n\twith equality if and only if $K$ is the \\emph{splitting field}\n\tof some separable polynomial with coefficients in $F$.\n\t\\label{thm:Galois_splitting}\n\\end{theorem}\nThe proof of this is deferred to an optional section at the end of the chapter.\nIf $K/F$ is a finite extension and $\\left\\lvert \\Aut(K/F) \\right\\rvert = [K:F]$,\nwe say the extension $K/F$ is \\vocab{Galois}.\nIn that case, we denote $\\Aut(K/F)$ by $\\Gal(K/F)$ instead\nand call this the \\vocab{Galois group} of $K/F$.\n\n\\begin{example}\n\t[Examples and non-examples of Galois extensions]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The extension $\\QQ(\\sqrt2) / \\QQ$ is Galois,\n\t\tsince it's the splitting field of $x^2-2$ over $\\QQ$.\n\t\tThe Galois group has order two, $\\sqrt 2 \\mapsto \\pm \\sqrt 2$.\n\t\t\\ii The extension $\\QQ(\\sqrt2, \\sqrt 3) / \\QQ$ is Galois,\n\t\tsince it's the splitting field of $(x^2-5)^2-6$ over $\\QQ$.\n\t\tAs discussed before, the Galois group is $\\Zc 2 \\times \\Zc 2$.\n\t\t\\ii The extension $\\QQ(\\cbrt{2}) / \\QQ$ is \\emph{not} Galois.\n\t\\end{enumerate}\n\\end{example}\n\n%Here is some more intuition on what $[K:F]$ actually measures: suppose $K$ is a splitting field\n%of some $(x-\\alpha_1) \\dots (x-\\alpha_n)$, meaning $K = F(\\alpha_1, \\dots, \\alpha_n)$.\n%Then a permutation $\\sigma \\in \\Aut(K/F)$ is determined by where it sends each $\\alpha_i$.\n%The dimension of $[K:F]$ measures how much ``redundancy'' there is among the $\\alpha_i$.\n%For example, in the case of \\[ (x-\\sqrt5)(x+\\sqrt5) = x^2-5  \\]the $\\sqrt 5$ and $-\\sqrt 5$ were redundant,\n%in the sense that knowing $\\sigma(\\sqrt 5)$ tells you $\\sigma(-\\sqrt 5) = -\\sigma(\\sqrt 5)$.\n%But in the $x^3-2$ case, knowing $\\sigma(\\cbrt{2})$ does \\emph{not} tell you where\n%$\\omega\\cbrt{2}$ should go; this is reflected in the fact that $[K:F]$ and $\\Aut(K/F)$\n%are both six rather than three.\n\nTo explore $\\QQ(\\cbrt 2)$ one last time:\n\\begin{example}\n\t[Galois closures, and the automorphism group of $\\QQ(\\cbrt2, \\omega)$]\n\tLet's return to the field $K = \\QQ(\\cbrt 2, \\omega)$,\n\twhich is a field with $[K:\\QQ] = 6$.\n\tConsider the two automorphisms:\n\t\\[\n\t\t\\sigma:\n\t\t\\begin{cases}\n\t\t\t\\cbrt 2 &\\mapsto \\omega \\cbrt 2 \\\\\n\t\t\t\\omega &\\mapsto \\omega\n\t\t\\end{cases}\n\t\t\\quad\\text{and}\\quad\n\t\t\\tau:\n\t\t\\begin{cases}\n\t\t\t\\cbrt 2 &\\mapsto \\cbrt 2 \\\\\n\t\t\t\\omega &\\mapsto \\omega^2.\n\t\t\\end{cases}\n\t\\]\n\tNotice that $\\sigma^3 = \\tau^2 = \\id$.\n\tFrom this one can see that the automorphism group of $K$ must have order $6$\n\t(it certainly has order $\\le 6$; now use Lagrange's theorem).\n\tSo, $K/\\QQ$ is Galois! Actually one can check explicitly that\n\t\\[ \\Gal(K/\\QQ) \\cong S_3 \\]\n\tis the symmetric group on $3$ elements, with order $3! = 6$.\n\\end{example}\nThis example illustrates the fact that\ngiven a non-Galois field extension, \none can ``add in'' missing conjugates to make it Galois.\nThis is called taking a \\vocab{Galois closure}.\n\n\\section{Fundamental theorem of Galois theory}\nAfter all this stuff about Galois Theory, I might as well tell you the fundamental theorem,\nthough I won't prove it.\nBasically, it says that if $K/F$ is Galois with Galois group $G$, then:\n\\begin{moral}\n\tSubgroups of $G$ correspond exactly to fields $E$ with $F \\subseteq E \\subseteq K$.\n\\end{moral}\n\nTo tell you how the bijection goes, I have to define a fixed field.\n\\begin{definition}\n\tLet $K$ be a field and $H$ a subgroup of $\\Aut(K/F)$.\n\tWe define the \\vocab{fixed field} of $H$, denoted $K^H$, as\n\t\\[ K^H \\defeq \\left\\{ x \\in K : \\sigma(x)=x \\; \\forall \\sigma \\in H \\right\\}. \\]\n\\end{definition}\n\\begin{ques}\n\tVerify quickly that $K^H$ is actually a field.\n\\end{ques}\n\nNow let's look at examples again.\nConsider $K = \\QQ(\\sqrt2, \\sqrt3)$,\nwhere \\[ G = \\Gal(K/\\QQ) = \\{\\id, \\sigma, \\tau, \\sigma\\tau\\} \\]\nis the Klein four group\n(where $\\sigma(\\sqrt2) = -\\sqrt 2$ but $\\sigma(\\sqrt 3) = \\sqrt 3$; $\\tau$ goes the other way).\n\\begin{ques}\n\tLet $H = \\{\\id, \\sigma\\}$. What is $K^H$?\n\\end{ques}\nIn that case, the diagram of fields between $\\QQ$ and $K$\nmatches exactly with the subgroups of $G$, as follows:\n\\begin{center}\n\\begin{minipage}[t]{4cm}\n\t\\begin{diagram}\n\t\t& \\QQ(\\sqrt2, \\sqrt 3) & \\\\\n\t\t\\ldLine(1,2) & \\dLine & \\rdLine(1,2) \\\\\n\t\t\\QQ(\\sqrt2) & \\QQ(\\sqrt 6) & \\QQ(\\sqrt 3) \\\\\n\t\t& \\ldLine(1,2) \\dLine \\rdLine(1,2) & \\\\\n\t\t& \\QQ & \n\t\\end{diagram}\n\\end{minipage}\n\\qquad\n\\begin{minipage}[t]{4cm}\n\t\\begin{diagram}\n\t\t& \\{\\id\\} & \\\\\n\t\t\\ldLine(1,2) & \\dLine & \\rdLine(1,2) \\\\\n\t\t\\{\\id,\\tau\\} & \\;\\; \\{\\id, \\sigma\\tau\\} \\;\\; & \\{\\id,\\sigma\\} \\\\\n\t\t& \\ldLine(1,2) \\dLine \\rdLine(1,2) & \\\\\n\t\t& G & \n\t\\end{diagram}\n\\end{minipage}\n\\end{center}\nWe see that subgroups correspond to fixed fields.\nThat, and much more, holds in general.\n\n\\begin{theorem}[Fundamental theorem of Galois theory]\n\tLet $K/F$ be a Galois extension with Galois group $G = \\Gal(K/F)$.\n\t\\begin{enumerate}[(a)]\n\t\\ii There is a bijection between field towers $F \\subseteq E \\subseteq K$ and subgroups $H \\subseteq G$:\n\t\\[\n\t\t\\left\\{\n\t\t\\begin{array}{c}\n\t\t\tK \\\\ \\mid \\\\ E \\\\ \\mid \\\\ F\n\t\t\\end{array}\n\t\t\\right\\}\n\t\t\\iff\n\t\t\\left\\{\n\t\t\\begin{array}{c}\n\t\t\t1 \\\\ \\mid \\\\ H \\\\ \\mid \\\\ G\n\t\t\\end{array}\n\t\t\\right\\}\n\t\\]\n\tThe bijection sends $H$ to its fixed field $K^H$, and hence is inclusion reversing.\n\t\\ii Under this bijection, we have $[K:E] = \\left\\lvert H \\right\\rvert$ and $[E:F] = [G:H]$.\n\t\\ii $K/E$ is always Galois, and its Galois group is $\\Gal(K/E) = H$.\n\t\\ii $E/F$ is Galois if and only if $H$ is normal in $G$. If so, $\\Gal(E/F) = G/H$.\n\t\\end{enumerate}\n\\end{theorem}\n\n\\begin{exercise}\n\tSuppose we apply this theorem for \n\t\\[ K = \\QQ(\\cbrt2, \\omega). \\]\n\tVerify that the fact $E = \\QQ(\\cbrt 2)$ is not Galois\n\tcorresponds to the fact that $S_3$ does not have normal subgroups of order $2$.\n\\end{exercise}\n\n\n\\section\\problemhead\n\\begin{sproblem}[Galois group of the cyclotomic field]\n\tLet $p$ be an odd rational prime and $\\zeta_p$ a primitive $p$th root of unity.\n\tLet $K = \\QQ(\\zeta_p)$.\n\tShow that \\[ \\Gal(K/\\QQ) \\cong (\\ZZ/p\\ZZ)^\\ast. \\]\n\t\\begin{hint}\n\t\tLook at the image of $\\zeta_p$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIt's just $\\Zc{p-1}$, since $\\zeta_p$ needs to get sent\n\t\tto one (any) of the $p-1$ primitive roots of unity.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{problem}[Greek constructions]\n\tProve that the three Greek constructions\n\t\\begin{enumerate}[(a)]\n\t\t\\ii doubling the cube,\n\t\t\\ii squaring the circle, and\n\t\t\\ii trisecting an angle\n\t\\end{enumerate}\n\tare all impossible.\n\t(Assume $\\pi$ is transcendental.)\n\t\\begin{hint}\n\t\tRepeated quadratic extensions have degree $2$, so one can\n\t\tonly get powers of two.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[China Hong Kong Math Olympiad]\n\t\\yod\n\tProve that there are no rational numbers $p$, $q$, $r$ satisfying\n\t\\[ \\cos\\left( \\frac{2\\pi}{7} \\right)\n\t\t= p + \\sqrt{q} + \\sqrt[3]{r}.  \\]\n\t\\begin{sol}\n\t\tA similar (but not identical) problem is solved here:\n\t\t\\url{https://aops.com/community/c6h149153p842956}.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tShow that the only automorphism of $\\RR$ is the identity.\n\tHence $\\Aut(\\RR)$ is the trivial group.\n\t\\begin{hint}\n\t\tHint: $\\sigma(x^2) = \\sigma(x)^2 \\ge 0$ plus Cauchy's Functional Equation.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}[Artin's primitive element theorem]\n\t\\yod\n\tLet $K$ be a number field.\n\tShow that $K \\cong \\QQ(\\gamma)$ for some $\\gamma$.\n\t\\label{prob:artin_primitive_elm}\n\t\\begin{hint}\n\t\tBy induction, suffices to show $\\QQ(\\alpha, \\beta) = \\QQ(\\gamma)$\n\t\tfor some $\\gamma$ in terms of $\\alpha$ and $\\beta$.\n\t\tFor all but finitely many rational $\\lambda$,\n\t\tthe choice $\\gamma = \\alpha + \\lambda \\beta$ will work.\n\t\\end{hint}\n\t\\begin{sol}\n\t\t\\url{http://www.math.cornell.edu/~kbrown/6310/primitive.pdf}\n\t\\end{sol}\n\\end{problem}\n\n\\section{(Optional) Proof that Galois extensions are splitting}\nWe prove \\Cref{thm:Galois_splitting}.\nFirst, we extract a useful fragment from the fundamental theorem.\n\\begin{theorem}[Fixed field theorem]\n\t\\label{thm:fixed_field_theorem}\n\tLet $K$ be a field and $G$ a subgroup of $\\Aut(K)$.\n\tThen $[K:K^G] = \\left\\lvert G \\right\\rvert$.\n\\end{theorem}\n\nThe inequality itself is not difficult:\n\\begin{exercise}\n\tShow that $[K:F] \\ge |\\Aut(K/F)|$,\n\tand that equality holds if and only if\n\tthe set of elements fixed by all $\\sigma \\in \\Aut(K/F)$\n\tis exactly $F$.\n\t(Use \\Cref{thm:fixed_field_theorem}.)\n\\end{exercise}\nThe equality case is trickier.\n\nThe easier direction is when $K$ is a splitting field.\nAssume $K = F(\\alpha_1, \\dots, \\alpha_n)$ is the splitting field of some separable polynomial $p \\in F[x]$\nwith $n$ distinct roots $\\alpha_1, \\dots, \\alpha_n$.\nAdjoin them one by one:\n\\begin{diagram}\n\tF & \\rInj & F(\\alpha_1) & \\rInj & F(\\alpha_1, \\alpha_2) & \\rInj & \\dots & \\rInj & K \\\\\n\t\\dTo^\\id && \\dTo^{\\tau_1} && \\dTo^{\\tau_2} && \\dots && \\dTo_{\\tau_n = \\sigma} \\\\\n\tF & \\rInj & F(\\alpha_1) & \\rInj & F(\\alpha_1, \\alpha_2) & \\rInj & \\dots & \\rInj & K \\\\\n\\end{diagram}\n(Does this diagram look familiar?)\nEvery map $K \\to K$ which fixes $F$ corresponds to an above commutative diagram.\nAs before, there are exactly $[F(\\alpha_1) : F]$ ways to pick $\\tau_1$.\n(You need the fact that the minimal polynomial $p_1$ of $\\alpha_1$ is separable for this:\nthere need to be exactly $\\deg p_1 = [F(\\alpha_1) : F]$ distinct roots to nail $p_1$ into.)\nSimilarly, given a choice of $\\tau_1$, there are $[F(\\alpha_1, \\alpha_2) : F(\\alpha_1)]$ ways to pick $\\tau_2$.\nMultiplying these all together gives the desired $[K:F]$.\n\n\\bigskip\n\nNow assume $K/F$ is Galois.\nFirst, we state:\n\\begin{lemma}\n\tLet $K/F$ be Galois, and $p \\in F[x]$ irreducible.\n\tIf any root of $p$ (in $\\ol F$) lies in $K$, then all of them do,\n\tand in fact $p$ is separable.\n\\end{lemma}\n\\begin{proof}\n\tLet $\\alpha \\in K$ be the prescribed root.\n\tConsider the set\n\t\\[ S = \\left\\{ \\sigma(\\alpha) \\mid \\sigma \\in \\Gal(K/F) \\right\\}. \\]\n\t(Note that $\\alpha \\in S$ since $\\Gal(K/F) \\ni \\id$.)\n\tBy construction, any $\\tau \\in \\Gal(K/F)$ fixes $S$.\n\tSo if we construct\n\t\\[ \\tilde p(x) = \\prod_{\\beta \\in S} (x - \\beta), \\]\n\tthen by Vieta's Formulas, we find that all the coefficients of $\\tilde p$ are fixed by elements of $\\sigma$.\n\tBy the \\emph{equality case} we specified in the exercise, it follows that $\\tilde p$ has coefficients in $F$!\n\t(This is where we use the condition.)\n\tAlso, by \\Cref{lem:root_shuffle}, $\\tilde p$ divides $p$.\n\n\tYet $p$ was irreducible, so it is the minimal polynomial of $\\alpha$ in $F[x]$,\n\tand therefore we must have that $p$ divides $\\tilde p$.\n\tHence $p = \\tilde p$. Since $\\tilde p$ was built to be separable, so is $p$.\n\\end{proof}\nNow we're basically done -- pick a basis $\\omega_1$, \\dots, $\\omega_n$ of $K/F$,\nand let $p_i$ be their minimal polynomials; by the above, we don't get any roots outside $K$.\nConsider $P = p_1 \\dots p_n$, removing any repeated factors.\nThe roots of $P$ are $\\omega_1$, \\dots, $\\omega_n$ and some other guys in $K$.\nSo $K$ is the splitting field of $P$.\n", "meta": {"hexsha": "4beeba42fbdf77e3de2c5c3fa926d3f1c75aa94e", "size": 29402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-NT/galois.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/galois.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/galois.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.2949438202, "max_line_length": 118, "alphanum_fraction": 0.6819263996, "num_tokens": 9778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.6790596715779433}}
{"text": "\\chapter{THE DIRECTED HMCFP} \\label{ch:directed}% Must have a blank line after every section label\n\n\\section{Motivation}\n\nTo this point, the MCFP has only been formulated for undirected graphs. However, the field of social network analysis does not confine itself to directed graphs. Sociograms can present directed maps of influence in social groups~\\cite{moreno1934shall}. Communities exist even among these, which motivates the \\emph{directed} (H)MCFP.\n\n\\section{Formulation}\n\nAs discussed in \\autoref{sec:MCF LP}, the MCF cut algorithm hierarchically solves the LP of the maximum concurrent flow problem (MCFP). The edge-path formulation is reproduced here.\n\\begin{align}\n    \\max z(G, c, d) \\\\\n    \\mathrm{s.t.} \\sum_{p \\in P_{ij}} f_p &= zd_{ij} \\forall \\{i, j\\} \\in D \\\\\n    \\sum_{\\{p \\in P:\\{i,j\\} \\in E_p\\}} f_p &\\leq c_{ij} \\forall \\{i, j\\} \\in E \\\\\n    f_p &\\geq 0,  p \\in P\n\\end{align}\nSome simple extensions of this edge-path formulation can convert it into a linear program suitable for processing directed graphs.\n\nFirst, we'll consider the difference in the inputs. A problem instance for the undirected MCFP involved a graph, a capacity function, and a demand function. In this case, the graph contains a set of directed edges, which alters how we define our capacity and demand functions. \n\nIn general, we may simply say that the capacity function takes a directed edge as its argument. When a reciprocal connection exists between two nodes, each direction would have a different capacity, which matches our intuition about traffic networks. In certain cases, we may want the capacity to be limited, regardless of direction. The real-world analogue is a bridge with a maximum weight. These can be represented with a complementary function $c^*\\colon {i, j} \\rightarrow c_e$. Importantly, the domain of $c^*$ and the domain of $c$ must be disjoint and their union must be $V$, to provide complete information about the capacity of every edge. We use~$E^*$ to represent the domain of~$c^*$. When defining the linear program, we require that $c^*_\\{i, j\\} = c_{(i, j)} + c_{(j, i)}$ and that $c_{(i, j)}$ and $c_{(j, i)}$ are each nonnegative.\n\nIn a similar way, we can define the directional demand~$d$ and the bidirectional demand~$d^*$ and introduce corresponding non-negativity constraints to maintain boundedness. The fairness metric then optimizes the througput proportional to $d_{i, j}$ for all directions---though $d_{i, j}$ is now defined over ordered tuples, rather than sets, of vertices. To handle directed edges, the set~$D$ is now $V \\times V \\setminus \\{(v, v) \\ \\forall v \\in V\\}$, and we define~$D^*$ as the domain of $d^*$. The edge-path formulation for the directed MCFP is:\n\\begin{align}\n    \\max z(G, c, c^*, d, d^*) \\\\\n    \\mathrm{s.t.} \\sum_{p \\in P_{ij}} f_p &= zd_{ij}, \\forall (i, j) \\in D \\\\\n    \\sum_{\\{p \\in P:\\{i,j\\} \\in E_p\\}} f_p &\\leq c_{ij}, \\forall (i, j) \\in E \\\\\n    f_p &\\geq 0,  \\forall p \\in P \\\\\n    d^*_{\\{i, j\\}} &\\geq d_{(i, j)} + d_{(j, i)}, \\forall \\{i, j\\} \\in D^* \\\\\n    c^*_{\\{i, j\\}} &\\geq c_{(i, j)} + c_{(j, i)}, \\forall \\{i, j\\} \\in E^*\n\\end{align}\n\nExtension to a hierarchical MCFP, freezing previous flows as starting points for subsequent iterations, is trivially done via the same procedure as in \\autoref{sec:maximin LP}.\n\n\\section{Discussion}\n\nIf one were to use an instance of the undirected (H)MCFP as an input for the directed version, the duplication of edges would double the number of columns in the constraint matrix. Further, the number of paths doubles since their direction becomes relevant. Consequently, the size of the constraint matrix quadruples. For this reason, it is important to reduce the problem to its undirected form when possible.\n\nAlso, in the directed case, it is possible to have fully saturated edges which fail to separate the graph because the capacity in the opposing direction exceeds the throughput attainable in the direction of saturated edges.  \\todo{More.}\n", "meta": {"hexsha": "366f6e4924307c9869ed44d081f91ec073ee40a8", "size": 3969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/directed.tex", "max_stars_repo_name": "aryamccarthy/thesis", "max_stars_repo_head_hexsha": "ef0e45e24e1cde26d3014d8da8cede559bbff5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reports/directed.tex", "max_issues_repo_name": "aryamccarthy/thesis", "max_issues_repo_head_hexsha": "ef0e45e24e1cde26d3014d8da8cede559bbff5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/directed.tex", "max_forks_repo_name": "aryamccarthy/thesis", "max_forks_repo_head_hexsha": "ef0e45e24e1cde26d3014d8da8cede559bbff5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.7692307692, "max_line_length": 849, "alphanum_fraction": 0.7238599143, "num_tokens": 1113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.6789610225394557}}
{"text": "Most hierarchical clustering algorithms\nproduce a binary tree over the data,\nwhere each leaf corresponds to a data point.\nInternal nodes correspond to groupings of descendant leaves.\nThis approach is simple, but can run into\nproblems when the hierarchical structure\nin the data is ambiguous. Consider\na simple dataset with three points\nthat are equidistant from each other \nor a dataset with three points\nlying equally spaced apart in a line (see \\autoref{fig:ambiguous-structure}).\nA single binary tree is not sufficient\nto describe the similarity relationships\nbetween the points, as a single tree\nwill imply that some points are more similar\nto each other than the other\nwhen they are in fact not.\nAn initial solution is to extend clustering\nalgorithms to produce trees with arbitrary\nbranching factors.\nThis will help solve the\nambiguity problem\nin the first dataset, but\nnot the second.\nFurthermore, we can construct \nadversarial datasets\nthat will always be ambiguous.\nConsider $\\numdata$ points lying on the unit circle, equally spaced apart.\nDue to rotational symmetry, there will be several\nequivalent trees with max branching factor less than $\\numdata$.\nSince an $\\numdata$-ary tree over $\\numdata$ data points\nimplies no underlying structure,\nwe require an approach that can\nhandle ambiguity without compromising\nthe capacity to discover structure.\n\nBayesian nonparametric hierarchical clustering (BNHC)\naddresses the general issue of\nambiguity in hierarchical structure\nby explicitly modeling any uncertainty with probability.\nRather than outputting a single tree\nas in traditional hierarchical clustering,\na Bayesian method\nreturns a probability distribution\nover hierarchies that explain the data.\nIn the ambiguous dataset with three points described earlier,\na Bayesian method would return\na distribution over the three hierarchies,\nwhere each is assigned\na probability of $1/3$.\nBNHC\nalso follows the standard Bayesian paradigm,\nwhere Bayes rule enables\ncalculating a posterior distribution\ngiven a prior and a likelihood model.\n\n%The chapter is organized as follows.\n%In section 2 we provide background information\n%about traditional hierarchical clustering\n%methods and Bayesian learning.\n%In section 3 we lay down the fundamentals\n%of Bayesian hierarchical clustering,\n%describe several of the prominent\n%models in BNHC, and provide\n%algorithms to perform inference in the models.\n%In section 4 we introduce ideas\n%to improve BNHC with user interaction,\n%and in section 5, we conclude and describe\n%some areas for future work.\n\n\\section{Background}\n\nIn this section, we briefly discuss\nsome traditional hierarchical clustering algorithms\nand provide some\nbackground knowledge on latent variable modeling.\n\n\\subsection{Traditional hierarchical clustering}\nTraditional hierarchical clustering algorithms\ncan be broadly divided into two categories:\n\\emph{agglomerative} (bottom-up) and \\emph{divisive} (top-down).\nIn agglomerative clustering, the hierarchy\nis built by iteratively merging clusters\nthat are most similar to each other, forming\nlarger and larger clusters at each level\nof the tree.\nIn divisive clustering,\nthe hierarchy is built by recursively\nsplitting the data from the top,\nforming a new pair of nodes with \neach split \\citep{Hastie2009}.\n\nThe input to hierarchical clustering algorithms\nis a dataset, $\\dataset$.\nThe output is a $\\tree$,\na rooted tree with $\\numdata$\nlabeled leaves,\neach corresponding to one of the data points.\nTypically, the tree is binary\nand internal nodes correspond\nto groupings of the leaves\nof the tree.\n\nAn agglomerative clustering algorithm is fully specified\nby a \\emph{dissimilarity function} and a \\emph{linkage criterion}.\nA dissimilarity function,\n$d(\\x_i, \\x_j)$ measures\nhow different two data points $\\x_i$ and $\\x_j$ are from each other;\nfor example, we may choose Euclidean distance \nif our data are real valued vectors.\nA linkage criterion $D(A, B)$ measures how different two clusters\n$A$ and $B$\nare from each other in terms of the pairwise\ndissimilarities between the points in each cluster.\nA popular linkage criterion is\n\\emph{single linkage}, which defines\ncluster dissimilarity\nas that\nof the closest points in \neach cluster,\ni.e.\n\\begin{align}\n  D_{SL}(A, B) = \\min_{i\\in A, j \\in B} d(\\x_i, \\x_j)\n\\end{align}\nAnother common linkage function is \\emph{average linkage}, \nwhere cluster dissimilarity is\nthe mean dissimilarity between\nall pairs of points in each cluster.\n\\begin{align}\n  D_{AL}(A, B) = \\frac{1}{|A||B|}\\sum_{i\\in A, j \\in B} d(\\x_i, \\x_j)\n\\end{align}\nFinally, in \\emph{complete linkage}, the cluster\ndissimilarity\nis that of the furthest points in each cluster,\nthe opposite of single linkage.\n\\begin{align}\n  D_{CL}(A, B) = \\max_{i\\in A, j \\in B} d(\\x_i, \\x_j)\n\\end{align}\n\nAgglomerative clustering begins by instantiating\na singleton cluster $\\{n\\}$ for each $\\x_n$, which\nwill be the leaves of our output hierarchy.\nEvery iteration of the algorithm, \nwe find\nthe two least dissimilar clusters $A$ and $B$\naccording to the linkage criterion\nand merge them, producing a new cluster.\nAfter $N - 1$ iterations, we are left\nwith a single cluster containing\nall the data, and the process\ncreates a binary tree where each internal node\ncorrespond to one of the merge operations.\n\nSee examples of clusterings with each\nlinkage criterion\nin \\autoref{fig:dendrograms}.\n\n\n\\begin{figure}[t]\n  \\includegraphics[width=\\textwidth]{img/trees/dendrograms}\n  \\caption{Hierarchies over human tumor data produced by agglomerative clustering\n    with three different linkage criterions. \n  Image from \\citet{Hastie2009}.}\n\\label{fig:dendrograms}\n\\end{figure}\n\nIn divisive clustering, the approach is flipped.\nWe begin with a cluster containing\nevery data point, corresponding\nto the root of the output tree.\nWe recursively\npartition the cluster, until \nwe are left with singleton clusters\nat each leaf.\nPartitioning a cluster\ntypically corresponds to solving\nan optimization problem, such as minimizing\na cost function of a split.\nFor example, we could partition\na cluster using $k$-means, with $k = 2$,\noptimizing the $k$-means cost function.\nAlternatively in spectral clustering methods,\nwe create a similarity graph, $G$,\ngiven a similarity function $s(\\x, \\x^\\prime)$.\n$G$ is an undirected, weighted graph\nwhere there is a node for each data point,\nand the weight for each edge $(i, j)$ is\n$s(\\x_i, \\x_j)$ \\citep{VonLuxburg2007}.\nBipartitioning a cluster\ncorresponds to finding a cut in its similarity graph,\nand intuitively a good cut would avoid\nedges between similar points.\nFinding a good partition thus corresponds\nto finding a minimum cut on $G$\nfor such cost functions as\nRatioCut \\citep{Hagen1992} and Ncut \\citep{Shi2000}.\n\n\\iffalse\n\\subsection{Bayesian learning}\nBayesian learning is a probabilistic\napproach to machine learning.\nIn Bayesian learning, our data\nare represented as observed random variables,\nwhich are generated conditionally\non a set of unobserved latent variables.\nThis is sometimes called a latent variable model.\n\nIn a latent variable model,\nwe have observed dataset $\\dataset$\nand assume there is some\nunobserved set of latent variables $\\globals$\nresponsible for generating $\\dataset$.\nThe latent variables $\\globals$\nare distributed according\nto a \\emph{prior distribution} $\\p(\\globals)$,\nand our observed data\nare generated by a conditional\ndistribution $\\p(\\dataset \\given \\globals)$, also called\nthe \\emph{likelihood}.\nWe are typically interested in the\n\\emph{posterior distribution},\n$\\p(\\globals \\given \\data)$, which is the distribution\nover latent variables given data.\nComputing the posterior distribution is called \\emph{inference}.\nThe posterior distribution can be calculated\nvia Bayes rule:\n\n\\begin{align}\n  \\p(\\globals \\given \\dataset) = \\frac{\\p(\\dataset \\given \\globals)\\p(\\globals)}{\\p(\\dataset)} = \\frac{\\p(\\dataset \\given \\globals)\\p(\\globals)}{\\int_\\globals \\p(\\dataset \\given \\globals)\\p(\\globals)}\n\\end{align}\n\nThe choice of prior distribution and likelihood model\naffect our ability to perform inference.\nIf our prior distribution is \\emph{conjugate}\nto our likelihood model, the posterior distribution\nwill be of the same form as the prior\nand can be expressed analytically.\nFor example, if our prior over parameters\nis Gaussian and likelihood model is Gaussian,\nthe posterior distribution will also be Gaussian.\nThis setup is common in classification problems\nfor real-valued data.\nSimilarly, if our prior over parameters is Dirichlet,\nand the likelihood model is Multinomial,\nthe posterior distribution will be Dirichlet.\nThis setup is common in classification problems\nwhen our data are bags-of-words.\nIn the general setting, however,\nit is often impossible to compute an\nanalytical form for the posterior distribution.\n\nAfter performing inference and obtaining\nthe posterior distribution $\\p(\\globals \\given \\dataset)$,\nwe are often tasked with prediction,\nor calculating a distribution over a new, unobserved\ndata point. Let $\\x^*$ be an unobserved test point.\nThe predictive distribution is defined\nas $\\p(\\x^* \\given \\dataset)$, and can be obtained by\nmarginalizing the posterior distribution:\n\n\\begin{align}\n  \\p(\\x^* \\given \\dataset) = \\int_\\globals \\p(\\x^*, \\globals \\given \\dataset)d\\globals =  \\int_\\globals \\p(\\x^* \\given \\globals, \\dataset)\\p(\\globals \\given \\dataset)d\\globals\n\\end{align}\n\n%Statistical models are often represented\n%as a directed graph, where nodes\n%are random variables and edges\n%represent dependency, called a \\emph{graphical model}.\n\nA classic example of a latent variable model\nis the Gaussian mixture model (GMM).\nGMM's are typically used in flat clustering scenarios,\nand as such, we assume a fixed amount of clusters $K$.\nA latent variable responsible for generating\ndata in a GMM are\nthe $K$ cluster centers, denoted by the set\n$\\bm{\\mu} = \\{\\mu_1, \\ldots, \\mu_K\\}$.\nEach cluster has a weight, or a prior probability\nof a data point belonging in the cluster,\nrepresented by the vector $\\bm{\\pi} = \\{\\pi_1,\\ldots,\\pi_K\\}$.\nEach data point is generated by sampling a cluster\nassignment $\\z$ from the probability distribution $\\bm{\\pi}$,\nand sampling a vector from a Gaussian distribution\ncentered at $\\mu_\\z$.\nThe graphical model for a GMM is pictured in \\autoref{fig:gmm-model}.\n\n\\begin{figure}[H]\n  \\centering\n  \\includestandalone[width=0.2\\textwidth]{tikz/gmm}\n  \\caption{A graphical model representation of a Gaussian mixture model. $\\x_n$ is\n  one of $\\numdata$ data points and $\\z_n$ is its cluster assignment. $\\bm{\\pi}$ are the weights\n  for each cluster, and $\\bm{\\mu}$ are the centers of each cluster.}\n\\label{fig:gmm-model}\n\\end{figure}\n\nUnfortunately, in the GMM,\nand in many other latent variable models,\nthe posterior distribution $\\p(\\bm{\\mu}, \\bm{\\pi} | X)$\nis impossible to compute analytically.\nThankfully, there are plenty of\nalgorithms to approximate the posterior distribution,\nsuch as\nMarkov chain\nMonte Carlo (MCMC), or variational\ninference.\n\nOften times, we are not interested in the posterior\ndistribution itself, but the settings of the latent variables\nthat result in the highest posterior probability, i.e.\n$\\globals^* = \\text{argmax}_\\globals \\p(\\globals | X)$.\n$\\globals^*$ is called the \\emph{maximum a posteriori}\nand can be approximated \nby such algorithms as\nexpectation-maximization \\citep{Dempster1977}.\n\\fi\n\n\\section{The generative process}\n\nBayesian nonparametric hierarchical clustering (BNHC)\nis a latent variable model where\ndata is generated in\nin two stages.\nFirst, a tree is generated by a\n\\emph{tree prior}.\nConditioned on the sample\nfrom the tree prior,\ndata is generated with\na \\emph{tree likelihood model}.\n\nThe simplest tree priors\nmodel \\emph{cladograms},\nor rooted binary trees\nwith data at the leaves,\nbut very often the trees are imbued with\nadditional information.\nFor example:\n\n\\begin{enumerate}\n  \\item An ordering on the internal nodes of the tree.\n    Typically, the root is given the lowest number and\n    each node will have a higher number than its parent.\n  \\item Times associated with each node.\n    Nodes higher up in the tree will typically have\n    earlier times, creating an evolutionary\n    interpretation to the hierarchy. Cladograms\n    with times associated at each node\n    are also called \\emph{phylogenies}.\n\\end{enumerate}\n\nIf we are only interested in tree structure,\nnot ordering or node times, we can simply discard\nall auxiliary information at the very end.\n\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics{tikz/lvm}\n  \\caption{The graphical model used\n  in Bayesian hierarchical clustering. $\\tree$\n  is a tree, sampled from a tree prior distribution.}\n  \\label{fig:bhc-gen-model}\n\\end{figure}\n\nFormally,\nlet $\\tree$ be a class\nof tree structures (e.g. ordered cladograms),\nand let $\\p(\\tree \\in \\trees)$\nbe a tree prior\nfor $\\trees$.\nWe sample parameters $\\globals$ for tree likelihood model,\nconditional on the tree structure.\nThis involves assigning\nlatent parameters to each internal node in the $\\tree$\nand specifying a stochastic process in which they are generated.\nConditioned on a particular\nstructure $\\tree$ sampled from $\\p(\\tree)$\nand tree likelihood parameters $\\globals$, dataset\n$\\dataset$\nis generated\nvia probability distribution $\\p(\\dataset \\given \\tree, \\globals)$.\nThis is visualized as a graphical model in \\autoref{fig:bhc-gen-model}\nand concisely expressed as follows:\n\n\\begin{align*}\n  \\tree &\\sim \\p(\\tree) \\\\\n  \\globals &\\sim \\p(\\globals \\given \\tree) \\\\\n  \\dataset &\\sim \\p(\\dataset \\given \\tree, \\globals)\n\\end{align*}\n\nInference involves computing the posterior\ndistribution over trees and parameters, \n$\\p(\\tree, \\globals \\given \\dataset)$, but we are sometimes interested\nin the\nposterior marginal distribution $\\p(\\tree \\given \\dataset)$.\nBoth of these distributions are typically\nimpossible to compute\nanalytically as marginalizing over $\\tree$\nis intractable.\nIn practice, most methods use Markov chain Monte Carlo\nmethods to sample $\\p(\\tree, \\globals \\given \\dataset)$\nand $\\p(\\tree \\given \\dataset)$.\n\nIn this section, we will cover two broad\nclasses of tree priors and touch on\nsome extraneous models. We will then explain\na few tree likelihood models, and \nfinish by explaining how to perform\ninference in Bayesian hierarchical clustering.\n\n\\subsection{Tree priors}\n\nBroadly speaking, \ntree priors can be broadly broken down into \n\\emph{coalescent} models\nand \n\\emph{diffusion} models.\nBoth of them share a core characteristic\nof being sequential models.\nIn coalescent models, the tree is built sequentially\nfrom the bottom up. We begin with each\ndata point in its own cluster,\nand sequentially merge clusters until\nthere is only one. This idea is\nvery similar to agglomerative clustering.\nDiffusion models take an inductive approach,\nwhere we begin with a hierarchy over a single\ndata point, and sequentially add data to the hierarchy until\nwe have a tree with $\\numdata$ leaves,\na fundamentally different paradigm.\nShared in both types of models is the property\nof\n\\emph{exchangeability}.\nA sequence of random variables, $\\x_1, \\ldots, \\x_\\numdata$,\nis considered exchangeable\nif their joint distribution\nis invariant to permutations of the variables.\nExchangeability often enables computationally efficient\ninference algorithms.\n\n\\textbf{Coalescent models:} \ncoalescent modeling was developed\nin the early 1980s by John Kingman,\nand achieved success in the field\nof population genetics\n\\citep{Kingman1982}.\nCoalescent models assume a\ncontinuous time process,\nwherein individuals of a population\nare traced backwards in time\nthrough their ancestry until\nthey all share a single common ancestor.\nIn terms of hierarchical clustering,\nthe individuals in the population\ncorrespond to a dataset $\\dataset$,\nand their\nancestry backwards in time\nis a hierarchy.\n\nThe classic coalescent model is\nKingman's coalescent \\citep{Kingman1982}.\nIt assumes a countably infinite population\nbut has a consistency property\nwhich allows it to be described\nin terms of its marginal distribution\nover finite populations.\n\nConsider a dataset $\\dataset$ with $\\numdata$ points, \nwhich we will call ``individuals''.\nIn Kingman's coalescent,\nour current population exists at time $t = 0$,\nand each individual in the population has a single\nparent in the previous generation, which has its own parent,\ncontinuing backwards in time until\n$t = -\\infty$. \nAt some time in the past,\nthe lineage of any two individuals will ``coalesce''\nwhen they share an ancestor.\nThe lineages of the members of the population\ncan be concisely described\nby the\n\\emph{genealogy} function, $\\pi(t)$,\nthat maps between time $t$\nand a partition of $\\{1, \\ldots, \\numdata\\}$\nthat groups individuals together\nif their lineages have coalesced at time $t$.\n$\\pi(0) = \\{\\{1\\}, \\{2\\},\\ldots,\\{\\numdata\\}\\}$\nrepresents\nthe current time, when no\nlineages have coalesced.\n$\\pi(-\\infty) = \\{\\{1, 2, \\ldots, \\numdata\\}\\}$\nis the partition of all\nindividuals into a single group,\nwhen they all share a common ancestor \\citep{Teh2008}.\n\nKingman's coalescent\nis a probability distribution\nover genealogy functions $\\pi(t)$\nfor populations of size $\\infty$,\nand the marginal distribution for\npopulations of size $\\numdata$ is called the $\\numdata$-coalescent.\nThe $\\numdata$-coalescent\nis a continuous-time\nMarkov process\nover the space of partitions\nof size $\\numdata$,\nstarting at time $t = 0$ with\n$\\pi(0) = \\{\\{1\\}, \\{2\\},\\ldots,\\{N\\}\\}$,\ngoing backwards until  $t = -\\infty$,\nwith\n$\\pi(-\\infty) = \\{\\{1, 2, \\ldots, N\\}\\}$.\n\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=\\textwidth]{img/trees/coalescent}\n  \\caption{A sample from Kingman's coalescent. $\\z$ is\n    the common ancestor for data $\\x_{1:4}$. Each $y_C$\n  represents the common ancestor for data subset $C$. \n  The axis represents time, and each $\\delta_i$ represents elapsed time. \n  $\\pi(t)$ is\n  the genealogy function. Image from \\citet{Teh2008}.}\n\\label{fig:coalescent}\n\\end{figure}\n\nThe $\\numdata$-coalescent\ncan be broken down into two\nindependent components.\nThe first is the \\emph{jump process},\nwhich models the discrete transitions\nbetween partitions\nbefore and after coalesce events.\nThe second is the \\emph{time process},\nwhich models the times in the past\nat which coalesce events happen.\nThe jump process is very simple.\nEach lineage has an equal probability of merging\nwith any other lineage. Thus, the\njump process is a Markov chain\nwhere the transition matrix is uniform\nfor each pair in a partition coalescing.\nThe jump process has $\\numdata - 1$ transitions, starting\nwith the partition with singleton groups\nfor each data, and ending with the\npartition with all data in a single group.\nThe time process produces a series of times\n$t_{\\numdata - 1} < t_{\\numdata - 2} < \\cdots <  t_1$ when coalesce events happen,\nending with $t_0 = 0$.\nThe first step in the jump process\ncorresponds to coalesce time $t_1$, and so on.\nKingman's coalescent assumes\nthat each pair of lineages merges at a constant rate of $1$,\ni.e.\\\na pair lineages will eventually merge at\n$t \\sim \\text{Exp}(1)$ where $\\text{Exp}$ is the exponential distribution.\nGiven a set of $m$ lineages,\na pair of them will merge at\n$t \\sim \\text{Exp}(\\binom{m}{2})$.\nLet the elapsed time before each jump $i$ be\n$\\delta_i = t_{i - 1} - t_i$\nWe start with a population of size $\\numdata$,\nand it decreases by $1$\nin each step of the jump process.\nThus, $\\delta_i \\sim \\text{Exp}(\\binom{\\numdata - i + 1}{2})$.\nAfter sampling all the $\\delta_i$'s, we can easily\ncompute the coalesce times,\ncompleting the distribution over genealogy functions.\nAn example sample from Kingman's coalescent can be\nseen in \\autoref{fig:coalescent}.\n\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.8\\textwidth]{img/trees/balanced}\n  \\caption{For the balanced tree on the left, there are two\n  possible orderings in which clusters were merged, whereas there is only one possible ordering for the unbalanced tree on the right. Image taken from \\citet{Boyles2012}.}\n\\label{fig:balanced}\n\\end{figure}\n\nA genealogy sampled from Kingman's coalescent\nis an ordered cladogram with times associated with every internal node.\nThe ordering comes from the order in which\ninternal nodes were created in the jump process.\nThe induced distribution over just ordered trees\nis in fact uniform \\citep{Teh2008}.\nHowever, we often don't need order information\nin hierarchical clustering.\n\\citet{Boyles2012} computes the induced distribution over\nunordered rooted binary trees.\nFor a given unordered tree with $\\numdata$ leaves, $\\tree$,\nthere are $\\frac{(\\numdata - 1)!}{\\prod_{\\n = 1}^{\\numdata - 1}m_\\n}$ possible orderings\nwhere $m_\\n$ is the number of internal nodes in the subtree\nof $\\tree$ indexed by $\\n$. \nIntuitively, there\nare several possible orderings to create a perfectly balanced binary tree,\nbut only one for an extremely unbalanced binary tree (see \\autoref{fig:balanced}).\nThus, Kingman's coalescent induces a prior distribution\nover unordered trees\nthat favors balanced trees over unbalanced trees,\nand \nmarginalizing out the ordering of internal\nnodes results in this distribution, also called\nthe time-marginalized coalescent \\citep[TMC; ][]{Boyles2012}.\n\nKingman's coalescent assumes constant merge rates\nfor each pair of lineages in a genealogy. \nAlthough this is an intuitive assumption,\nthere have been several papers generalizing Kingman's coalescent\nto both $k$-ary trees, and more complex coalesce rates.\nFor example, in \\citet{Pitman1999}, Pitman introduced the\n$\\Lambda$-coalescent, extending Kingman's coalescent\nto have ``multiple collisions'', supporting\n$k$-ary trees.\nRather than the coalesce rate\nbeing $1$, it is instead $\\lambda_i^k$\nwhere $k$ is the maximum number of lineages\nthat can merge in a single event and $i$ is the total number\nof lineages at the time of the event, resulting in $\\delta_i \\sim \\text{Exp}(\\lambda_i^k)$. $\\lambda_i^k$ is calculated as\n\\begin{align}\n  \\lambda_i^k = \\int_0^1 \\gamma^{k - 2}(1 - \\gamma)^{(i-k)}\\Lambda(d\\gamma)\n\\end{align}\nwhere $\\Lambda$ is a finite measure on $[0, 1]$. The\n$\\Lambda$-coalescent is identical to Kingman's coalescent\nwhen $k = 2$ and $\\Lambda$ is the Dirac delta.\nSetting $\\Lambda$ to a beta measure\nresults in the aptly named beta-coalescent \\citep{Hu2013}.\nA description of such coalescent rate functions\ncan be seen in \\citet{Aldous1999}.\n\n\\textbf{Diffusion models:}\ndiffusion models adopt a different paradigm for generation.\nIn diffusion models, we begin with a\ntrivial tree over just one data point. We then\ngrow the tree by iteratively attaching new data\nto branches in the tree, eventually creating\na tree with $\\numdata$ leaves.\nSimilar to coalescent models, there is an underlying\ncontinuous time process responsible for\nthe tree structure.\n\nThe first diffusion model, the Dirichlet diffusion tree (DDT),\nwas proposed in \\citet{Neal2003}.\nThe DDT is an exchangeable model that models a sequence of data\n$\\x_1, \\x_2,\\ldots,\\x_N$.\nThere is an underlying continuous time process\nthat lasts from time $t = 0$ to $t = 1$\nIn essence, each data point is generated in sequence by\na random walk beginning at $t = 0$,\nreaching a final value at $t = 1$.\nEach data point initially follows the previous\nrandom walks, but eventually diverges and continues independently.\n\nLet $\\x_\\n(t)$ be the value of data point $\\x_\\n$\nat time $t$, defining a ``path'' associated\nwith each point from its start $\\x_\\n(0)$ to its final (observed) value $\\x_\\n(1)$.\nIn addition, the path of each data point $\\x_\\n(t)$ is conditioned\non all previous paths $\\x_1(t), \\x_2(t), \\ldots, \\x_{\\n - 1}(t)$.\nThis process, when completed for all $\\numdata$ data points,\ninduces a binary tree over the data.\n\nThe path for the first data point $\\x_1$\nis a Brownian motion\nbeginning at the origin.\n\n\\begin{align}\n  \\x_1(0) &= 0 \\\\\n  \\x_1(t + dt) &= \\x_1(t) + \\N(0, \\sigma^2Idt)\n\\end{align}\n\nThe path for the second data point $\\x_2(t)$\nis exactly $\\x_1(t)$ until\nat some time $\\tree$ it diverges,\ncreating a branching point for\n$\\x_1(t)$ and $\\x_2(t)$.\n$\\tree$ is sampled according to an \\emph{acquisition function}\n$a(t)$ and\nafter divergence, $\\x_2(t)$ is an\nindependent Brownian motion.\n\nNow consider the inductive case.\nWe have already sampled $\\n - 1$\npaths, which form a binary tree\nwith internal nodes corresponding to\ndivergence events.\n$\\x_n(t)$ initially follows the same\npath as the previous points,\npicking branches to follow proportional\nto the number of points that followed\nthe branch previously.\nThis scheme is called \\emph{path reinforcement}\nand encourages\nbig subtrees to grow even bigger.\nIf $\\x_1(t)$ is traversing a path\nfollowed by $m$ previous paths,\nthe probability that $\\x_1(t)$ will\ndiverge along an infinitesimally small\ninterval $d$ is \n$a(t)dt/m$. \nIn practice we work with the cumulative\ndivergence function $A(t) = \\int_0^t a(u)du$.\nGiven an interval of time $(s, t)$,\nthat lies on a single branch of the DDT\nthat was previously traversed by $m$ paths,\nthe probability that the next point\ndoes not diverge on the interval\nis $e^{(A(s) - A(t))/m}$.\nThe acquisition function is chosen such that\n$a(1) = \\infty$. This guarantees that\nall data points must diverge \nbefore $t = 1$. \nFor a visualization of a DDT\nfor 1-dimensional data, see \\autoref{fig:ddt-vis}.\nPossible choices of acquisition function\nare $a(t) = \\frac{c}{1 - t}$ or $a(t) = b + \\frac{d}{1 - t^2}$,\nwhere $b$, $c$, and $d$ are constants.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{img/trees/ddt}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{img/trees/pydt}\n    \\end{subfigure}\n    \\caption{\n      On the left is a sample Dirichlet diffusion tree.\n      Black dots correspond to nodes in the tree. The image is taken from \\citet{Vikram2016}.\n      On the right is a sample from a Pitman-Yor diffusion tree with 4 points.\n      The image is taken from \\citet{Knowles2015}.\n    }\n    \\label{fig:ddt-vis}\n\\end{figure}\n\nThe DDT, as proposed in \\citet{Neal2003}, \njointly models the tree prior and tree likelihood model,\nas in it jointly samples tree structure\nand real-valued data associated with the tree.\nHowever, we can consider the same\npath reinforcement model, without the Brownian motion\nto obtain a prior over ordered cladograms\nwith times for each node.\nWe can obtain a sample from the DDT and just ignore the\ninternal values at each node where divergence occurred.\n\nThe DDT thus induces a prior over ordered cladograms\nwith times.\nUnlike Kingman's coalescent, however, the DDT\ndoes not, in general, induce a uniform prior over ordered cladograms.\nThis is due to the path-reinforcement element\nof the prior and the choice of acquisition function.\nIt is worth noting that the Dirichlet diffusion tree has achieved\ngreat success in the area of density estimation \\citep{Adams2008}.\n\nAn extension to the Dirichlet diffusion tree\nis the Pitman-Yor diffusion tree (PYDT),\nwhich removes the DDT's restriction to just binary trees\n\\citep{Knowles2015}.\nIn a Pitman-Yor diffusion tree, the probability\nof a data point diverging in an infinitesimally small\ninterval $dt$ is\n\\begin{align}\n  \\frac{a(t)\\Gamma(m - \\beta)}{\\Gamma(m + 1 + \\alpha)}\n\\end{align}\nwhere $\\alpha$ and $\\beta$ are parameters. Setting $\\alpha = \\beta = 0$,\nresults in same probability as in the DDT.\nIn the PYDT, a data point can not only\ndiverge at any point in time,\nbut can also diverge at a branching point\nin the tree, where in the DDT\na data point would always pick a branch.\nWhen a data point reaches a branching point,\nit picks branch $k$\nwith probability\n\\begin{align}\n  \\frac{b_k - \\beta}{m + \\alpha}\n\\end{align}\nwhere $b_k$ is the number of paths\nthat previously traversed $k$\nand $m$ is total the number of paths\nthat reached the branching point.\nThe probability that the data point\ndiverges, creating a new branch, is\n\\begin{align}\n  \\frac{\\alpha + \\beta K}{m + \\alpha}\n\\end{align}\nwhere $K$ is current number of branches.\nThis scheme allows for an arbitrary amount of\nbranching at each internal node of the tree,\nbut can be tuned by settings of $\\alpha$ and $\\beta$.\nNote again that when $\\alpha = \\beta = 0$,\nthe generation scheme matches the DDT.\n\n\\subsection{Generalizations of coalescent and diffusion models}\n\nThe simplest distribution over (unordered) cladograms\nis the uniform.\nKingman's coalescent is one step away,\nas it\ninduces the uniform distribution\nover ordered cladograms,\na distribution also called\nthe Yule model \\citep{Harding1971}.\nMarginalizing over possible orderings\nresults in the TMC \\citep{Boyles2012}, a distribution over unordered cladograms biased towards balanced trees.\n\nGeneralizations of Kingman's coalescent\ninclude the $\\Lambda$-coalescent \\citep{Pitman1999},\nwhich extends coalescents to multifurcating trees,\nand the Aldous $\\beta$-splitting model \\citep{Aldous1996}.\nA more recent model, the Gibbs fragmentation tree,\nis a generalization of the $\\beta$-splitting model\nto multifurcating trees,\nand is considered the most general Markovian distribution over trees \\citep{McCullagh2008}.\n\nThe diffusion models on the other hand,\ninclude far more parameters.\nThe choice of acquisition function,\nalong with the choice of $\\alpha$ and $\\beta$ in the PYDT,\nresult in a wider variety of distributions.\nThe PYDT's induced distribution over tree\nstructure is, in fact, a specific case\nof the Gibbs fragmentation tree.\n\nAn alternate generalization is the fragmentation-coagulation process (FCP),\nwhich is a distribution over partition-valued\nMarkov chains \\citep{Teh2011}.\nInstead of partitions being\nsplit up or merged monotonically as in\ndiffusion and coalescent models, the \nFCP models both split and merge\ntransitions in the Markov chain, encompassing\nboth coalescent and diffusion models.\n\nAll of these relationships are pictured in \\autoref{fig:familytree}.\n\n\\begin{figure}[H]\n  \\includegraphics[width=\\textwidth]{img/trees/FamilyTree}\n  \\caption{A graph visualization of the relationships between various\n  tree priors. Directed arrows represent\n  specific cases of a distribution or model.}\n\\label{fig:familytree}\n\\end{figure}\n\n\\subsection{Other priors}\n\nA popular line of work\nfollows extensions of the Chinese restaurant\nprocess (CRP) and other related Bayesian nonparametric objects.\nThe CRP is a distribution\nover partitions of $\\{1, \\ldots, N\\}$ \\citep{Aldous1985}.\nIts name derives\nfrom the nature of the stochastic process\nby which partitions are sampled.\nImagine an empty restaurant with\na countably infinite number of tables\nlabeled $1, 2, \\ldots$\nwith a line of customers waited to be seated.\nThe first customer will always pick \ntable $1$.\nLet $\\alpha$ be a hyperparameter.\nThe $n + 1$-th customer will pick the\nthe $i$-th table with probability\n\\begin{align}\n    \\frac{c_i}{n + \\alpha}\n\\end{align}\nwhere $c_i$ is the number\nof customers already sitting at\ntable $i$ or\nsit at a new, unoccupied table with probability\n\\begin{align}\n    \\frac{\\alpha}{n + \\alpha}\n\\end{align}\nAfter $\\numdata$ customers have been seated,\nwe have a partition over $\\{1,\\ldots, N\\}$,\nwhere customers are grouped\nby the table they are seated at.\n\n\\begin{figure}[t]\n  \\includegraphics[width=\\textwidth]{img/trees/ncrp}\n  \\caption{A visualization of a sampled from\n  a nested Chinese\n  restaurant process (NCRP). Only three levels\n  for 5 customers are shown.\n  Image from \\citet{Blei2010}.}\n\\label{fig:ncrp}\n\\end{figure}\n\nThe CRP is an exchangeable model\nand has a reinforcement property, where\ntables with more people attract \neven more people. It is\nalso the basis of the nested Chinese\nRestaurant Process (nCRP) model\nused for hierarchical clustering \\citep{Blei2010}.\nThe nCRP extends the analogy to\nan infinite chain of restaurants.\nAfter a customer goes and sits\nat the first Chinese restaurant,\nthey are directed to yet another\nChinese restaurant where the process\nrepeats ad infinitum. This defines\na structure where $\\numdata$ customers, or data,\nare distributed\nacross infinitely deep leaves of a tree.\nAlthough the tree is infinite,\nit can be represented in terms of its\nfinite induced distribution over\nhow the partition of customers is split\nat each level of the tree. \nThis results in a distribution over rooted trees\nwith arbitrary branching factor and ordering over internal nodes.\nSee \\autoref{fig:ncrp} for a visualization of the NCRP.\nThe NCRP\nis closely related to the nested Dirichlet process (NDP),\nthe underlying de Finetti measure for the NCRP.\nAn extension\nof the NCRP and NDP is the nested hierarchical Dirichlet\nprocess (NHDP) \\citep{Paisley2014}. Whereas each datum in the NDP and NCRP\nare each represented as an infinitely deep path\ndown the tree, each datum in the NHDP\nis represented as a \\emph{mixture} of\ninfinitely deep paths down the tree. \nThe NCRP, NDP, and NHDP have been used to success\nin topic modeling, finding hierarchies over\na corpus of documents.\n\nThe tree-structured stick-breaking process (TSSB)\nis an alternate model \nwhere data are allowed to live at any node\nin the tree, as opposed to just leaves \\citep{Adams2010}.\nAt the core of the TSSB is the\nstick-breaking process, a Bayesian nonparametric object\nclosely related to the CRP.\nThe stick breaking process\niteratively carves up the unit interval\ninto smaller and smaller pieces,\nresulting in an infinite amount of ``sticks'',\nwhose lengths sum up to one.\nLet $\\beta_i \\sim \\text{Beta}(1, \\alpha)$ for\n$i \\in 1,2,\\ldots$.\nThese will be fractions of the remainder\nof the stick that we will carve up.\nNow, let the ``sticks''\nbe $t_1 = \\beta_1$ and $t_i = \\beta_i \\prod_{j = 1}^i (1 - \\beta_j)$.\nWe now have a sequence of\nrandom variables, $t_1, t_2, \\ldots$\nsuch that $\\sum_{i = 1}^\\infty t_i = 1$,\nwhich we can treat as a distribution over\nan infinite amount of events.\nThe TSSB is an extension of the stick-breaking process\nto generate a distribution\nover infinitely deep and wide hierarchies.\nAssociated with each internal node in the tree\nis a stick breaking process,\nwhich acts as a distribution over an infinite\namount of branches out of the node.\nData are generated by starting at the root\nand sampling a branch. At any point,\ndata have a probability of stopping at a given node,\nwhich distributed as a stick breaking process\nover each possible path heading down the tree.\nAlthough the tree is infinite, it induces a distribution\nover trees where $\\numdata$ data live across every node\nin the tree, a fundamentally different tree structure\nfrom the previous ones.\n\n\\subsection{Tree likelihood models}\n\nGiven a sample from a tree structure prior, \nwe now need a scheme to sample\nhierarchically structured data.\nLet the sample from the tree\nstructure prior be $\\tree$.\nAssume, for now, $\\tree$ is\nan rooted tree,\nwith times associated with each internal node (ordering does not matter).\nThe standard tree likelihood model is a diffusion model,\nwhere there is a parameter $\\globals_\\n$ for each internal\nnode $\\n$, which are generated from the root downwards.\nLet $\\globals_0$ be the parameter associated with the root node,\nwhich will be sampled according to a prior distribution $\\p_0(\\globals)$.\nWe then define a transition kernel, $T(\\globals' \\given \\globals)$.\nThe parameter for each node is generated conditionally\ngiven its parent parameter in the tree,\ni.e. for node $v$ and its parent $u$,\n$\\globals_v \\sim T(\\cdot \\given \\globals_u)$.\nData at leaves are also generated in this fashion.\nWe now enumerate some transition kernels\nwhich accomodate different data types and tree structures.\n\n\\begin{enumerate}\n    \\item \\textbf{Generalized Gaussian diffusion.} If our data\n    is continuous and $\\d$-dimensional, we can associate\n    a latent vector $\\globals_\\n \\in \\R^\\d$ with each internal node\n    $\\n$ in the tree. Let $u$ be an internal node\n    and $v$ one of its children and\n    let $\\delta_{uv}$ be the elapsed time between $u$ and $v$.\n    We sample $\\globals_v \\sim \\N(\\globals_u, \\Sigma\\delta_{uv})$,\n    where $\\Sigma$ is a positive definite covariance matrix.\n    The root node value is assigned a prior\n    $\\N(\\mu_0, \\Sigma_0)$.\n    In the case where there are no times associated with each node,\n    we can assume elapsed time between nodes is always 1,\n    and the hyperparameters in the model would be\n    $\\Sigma$, $\\mu_0$, and $\\Sigma_0$.\n    This approach is used in \\citet{Neal2003}, \\citet{Teh2008}, \\citet{Knowles2015},\n    \\citet{Adams2010}, \\citet{Boyles2012} and \\citet{Hu2013}.\n    \\item \\textbf{Multinomial diffusion.} If our data\n    consists of several categorical variables, \n    we can model it with a transition matrix, $\\tree$.\n    For categorical feature $c$, let $T_c$ \n    be the row in $\\tree$ for feature $c$.\n    Let $\\delta_{uv}$ be the elapsed time between parent $u$ and child $v$.\n    As suggested by\n    \\citet{Teh2008},\n    $T_{c} = e^{-\\lambda_{c}\\delta_{uv}}I + (1 -  e^{-\\lambda_{c}\\delta_{uv}})q_{c}^T\\bm{1}$\n    where $\\lambda_{c}$ is a hyperparameter for the evolution rate for feature \n    $c$, $q_{c}$ is a hyperparameter for the equilibrium\n    distribution of $c$, and $\\bm{1}$ is a vector of ones.\n    \\item \\textbf{Dirichlet-Multinomial diffusion.}\n    This tree likelihood model is for\n    trees without times associated with each internal node.\n    When data consists of counts of discrete events,\n    such as the bag of words in topic modeling,\n    leaves can be described as sampling\n    a multinomial distribution.\n    The transition kernel for\n    just internal nodes as suggested by \\citet{Adams2010} is $T(\\globals' | \\globals) = \\text{Dirichlet}(\\kappa\\globals)$\n    and the prior is $P_1(\\globals) = \\text{Dirichlet}(\\kappa\\bm{1})$,\n    where $\\kappa$ is a concentration hyperparameter and $\\bm{1}$ is a\n    vector of ones.\n    Leaves are sampled via a multinomial distribution\n    with its parent's vector as its parameter.\n\\end{enumerate}\n\n\\subsection{Inference}\n\nWe are interested\nin the posterior distribution\nover hierarchies given data.\nTypically, this distribution\nis intractable to compute\nanalytically, so approximate\nmethods are required.\nA popular approach used\nin \\citet{Neal2003}, \\citet{Knowles2015}, and \\citet{Boyles2012}\nis the Metropolis-Hastings\nalgorithm,\na Markov chain Monte Carlo\nmethod where samples\nare used as an approximation\nto the posterior distribution.\n\nIn Metropolis-Hastings,\nwe are given a target\ndistribution, $\\p(\\x)$, and\ndefine a \\emph{proposal distribution}, $\\q(\\x^\\prime \\given \\x)$.\nA Markov chain is initialized with state $\\x_0$.\nIn each iteration of the algorithm\nwe use current state $\\x_t$\nto sample a candidate $\\x^\\prime$ from $\\q(\\x^\\prime \\given \\x_t)$.\nand then calculate\nthe acceptance ratio, \n\\begin{align}\n    \\alpha = \\frac{\\p(\\x^\\prime)\\q(\\x_t \\given \\x^\\prime)}{\\p(\\x_t)\\q(\\x^\\prime \\given \\x_t)}\n\\end{align}\nIf $\\alpha \\ge 1$, we accept,\nsetting $\\x_{t + 1} = \\x^\\prime$.\nIf $\\alpha < 1$, we accept\nwith probability $\\alpha$, and reject\notherwise, setting $\\x_{t + 1} = \\x_t$.\nProvided some conditions on $\\q(\\x^\\prime \\given \\x)$,\nthe Markov chain's stationary distribution\nwill be $\\p(\\x)$.\n\nIn BNHC, the probability distribution\nof interest\nis the posterior distribution $\\p(\\tree, \\globals \\given \\dataset)$.\nThe state of a Markov chain in Metropolis-Hastings is therefore\na tuple $(\\tree, \\globals)$.\nA proposal distribution $\\q(\\tree^\\prime, \\globals^\\prime \\given \\tree, \\globals, \\dataset)$ would need to jointly\nsample $\\tree$ and $\\globals$.\nA simple strategy is to have two proposal distributions: a \ntree proposal $\\q(\\tree^\\prime \\given \\tree)$\nand parameter proposal $\\q(\\globals^\\prime \\given \\tree^\\prime, \\globals)$. \nWe would sample $\\tree^\\prime$ first,\nand then we would sample $\\globals^\\prime$ \nadditionally conditioned on $\\tree^\\prime$.\nAlternatively, if we're only interested\nthe posterior distribution over trees,\nwe can often marginalize out $\\globals$, either\nanalytically or via belief propagation,\nresulting in the posterior marginal\ndistribution $\\p(\\tree \\given \\dataset)$.\n\n\\begin{figure}[t]\n  \\includegraphics[width=\\textwidth]{img/trees/spr}\n  \\caption{Visualization of a subtree-prune and regraft move for a\n  tree with four leaves. Image from \\citet{Vikram2016}.}\n\\label{fig:spr}\n\\end{figure}\n\nDesigning a tree proposal distribution\ninvolves modifying some tree $\\tree$ \nrandomly to form a new tree $\\tree^\\prime$.\nOne of the most popular proposals\nis the \\emph{subtree-prune and regraft} (SPR) move, proposed by \\citet{Swofford1990}.\nAn SPR move consists of a \\emph{prune} followed by a \\emph{regraft}.\nLet $\\tree$ be a tree.\nLet $s$ be a non-root\nnode in $\\tree$ selected uniformly at random\nand $S$ be its corresponding subtree.\nWe first \\emph{prune}\n$S$ from $\\tree$ by\nremove $s$'s parent $p$ from the tree,\nreplacing $p$ with $s$'s sibling.\nTo regraft $p$ to $\\tree$,\nwe first select a branch in $\\tree$,\n$(u, v$), where $u$ is the parent of $v$.\n$S$ is re-attached to $\\tree$\nby creating a new node $p$\nwith parent $u$ and children $v$ and $s$,\ncreating a new tree $\\tree^\\prime$.\nThis process is visualized in \\autoref{fig:spr}.\n\nThe branch selected in the regraft move\nis often sampled from a distribution\nrelated to the tree prior.\nFor example, if we used a DDT,\nwe have a posterior distribution\nover branches where a new data point would \ndiverge. If such a distribution\ndoes not exist, the branch can simply\nbe selected uniformly at random.\n\nTwo alternatives to the SPR move\nmoves are the leaf move,\nwhich restricts the SPR move\nto just leaf nodes,\nand nearest-neighbor interchange\nmoves, which interchange\ntwo pairs of subtrees.\nIt is worth noting\nthat \nthe worst case mixing rate of\na Markov chain using\nleaf moves to sample\nthe uniform distribution over\n$\\numdata$-leaf cladograms is $O(\\numdata^3)$ \\citep{Aldous2000}.\n\nSampling the parameters of \nthe tree likelihood model is much simpler\nthan sampling the tree prior.\nThe parameters $\\globals$ often\nhave conditional dependence\nstructure that allows simple\nancestral sampling or Gibbs sampling.\nFor example, in the DDT and Kingman's coalescent,\neach internal node in the tree stores\na latent vector, representing the intermediate value\nof data higher up in the tree.\nIf the likelihood model is\ngeneralized Gaussian diffusion,\nall conditional distributions are Gaussian.\nWe can thus Gibbs sample each of the\nlatent vectors.\n\nMetropolis-Hastings is perhaps the\nsimplest method to sample a general\nBNHC model. However, alternative methods\nhave been proposed,\nsuch as using slice sampling in \\citet{Adams2010} and \\citet{Boyles2012},\nsequential Monte Carlo in \\citet{Teh2008} and \\citet{Hu2013},\nGibbs sampling in \\citet{Blei2010},\nand variational inference in \\citet{Paisley2014}.\nFurthermore, there are greedy algorithms\nto approximate a MAP estimate\nto the posterior distribution\nof trees given data \\citep{Teh2008, Hu2013}.\n", "meta": {"hexsha": "622ecc0ed9c962fbd3cc81eca673de33f3151e38", "size": 42775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/content/structure/trees.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/trees.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/trees.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": 36.2807463953, "max_line_length": 200, "alphanum_fraction": 0.7647223846, "num_tokens": 11183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461006, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.6789610164900747}}
{"text": "\n\\subsection{Finding strong rules using the Apriori algorithm}\n\n\\subsubsection{Finding frequent patterns}\n\nWe can use search algorithms to find frequent patterns. Starting at the empty set.\n\n\\subsubsection{Apriori algorithm}\n\nBreadth first search to generate candidate set of itemsets with support above some value.\n\nStart with a \\(1\\)-itemset, and increase \\(k\\) once done.\n\nOnce we have found a frequent pattern, we can immediately identify other frequent patterns associated with it.\n\nWe can do this by looking at confidence, not support.\n\n", "meta": {"hexsha": "e87f6acc23cfc7c304e1a734015b8622087501a4", "size": 543, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/association/01-06-apriori.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-06-apriori.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-06-apriori.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1666666667, "max_line_length": 110, "alphanum_fraction": 0.7937384899, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6789610063045269}}
{"text": "\\lab{Job Search Model}{Job Search Model}\n\n\\section*{Discrete Choice (Threshold) Problems}\\label{SecDiscrChoice}\n\nOne powerful application of dynamic programming is\nto models that have both continuous and discrete state variables. These models are sometimes referred to as\ndiscrete choice problems or optimal stopping problems.  Examples include models of employment that involve both\nthe choice of whether to work and how much to work, models of firm entry and exit that involve the choice of both\nwhether to produce and how much to produce, and models of marriage that involve the choice of whether to date\n(get married or keep dating) and how much to date.\nThis application illustrates the versatility of dynamic programming as a dynamic solution method\n\nIn this lab, we follow a simple version of a standard job search model.\nAssume that workers live infinitely long.\nWe will split a worker's life into discrete time periods, and in each period the worker is either\nemployed or unemployed, and receives a job offer. The worker must make a choice between discrete actions\n(such as accepting or rejecting a job offer), with the goal of maximizing some utility function (hence,\nthis is a \\emph{discrete choice} problem).\n\nWe can state this problem in terms of dynamic programming by defining an appropriate value function.\nLet the value of entering a period with most recent wage $w$,\ncurrent job offer wage $w'$, and employment status $s$ be given by the following value function,\n\\begin{equation}\\label{EqV}\n   V(w,w',s) = \\begin{cases}\n                  V^E(w)    \\quad&\\text{if}\\quad s = E \\\\\n                  V^U(w,w') \\quad&\\text{if}\\quad s = U \\\\\n               \\end{cases}\n\\end{equation}\nwhere employment status is a binary variable $s\\in\\{E,U\\}$ ($E$ indicates ``employed\" and $U$ indicates ``unemployed\");\na person can be either employed or unemployed.\n\nAs in the cake eating problem, the value function is calculated as the sum of some reward (based on the\ncurrent state) and the discounted value of entering the next period in some particular state.\nThe reward function, denoted (as usual) by $u$, gives the utility of spending available funds.\nAssuming that a worker receives some wage $x$ in a given period and spends all available money in the period,\nthe utility of consumption is given by\n\\[\nu(x).\n\\]\nCalculating the value for the next period depends on the employment status in the current period, so we address\nthis separately for each case.\n\nLet us first consider the case where the individual is unemployed ($s = U$). As is customary, let $s'$ denote the\nemployment status of the worker in the next period.\nIn this unemployed state, the worker receives unemployment benefits equal to a fraction of her most recent wage,\ni.e. $\\alpha w$, where $\\alpha \\in (0, 1)$.\nHence, the utility of consumption in the current unemployed state is given by\n\\[\nu(\\alpha w).\n\\]\n\nThe worker also receives one wage offer ($w'$) per period, and will obtain\nthis wage in the next period provided that he chooses to accept employment, i.e. provided $s' = E$.\nThe worker must decide whether to accept the current wage offer $w'$ or to remain unemployed in the next period,\ni.e. he must decide on the value of $s'$. How\ndoes he make this choice? He must weigh the value of entering the next period as an employed worker with wage\n$w'$ (given by $V^E(w')$) versus the value of entering the next period as an unemployed worker with\nprevious wage $w$ and unknown wage offer $w''$ (given by $V^U(w,w'')$). Because the worker cannot know\nwhat the future wage offer $w''$ will be, it is treated as a random variable with a particular probability\ndistribution. Hence, the worker must actually compute the \\emph{expected} value of entering the next\nperiod unemployed. This term is simply\n\\[\n\\mathbb{E}_{w''}V^U(w,w''),\n\\]\nwhere $\\mathbb{E}_{w''}$ denotes the expectation operator with respect to the probability distribution of future\nwage offers $w''$.\nTo sum up, the worker chooses to accept the wage offer $w'$ or remain unemployed in the next period based on\nwhich option gives the greater expected value, and the value of this decision is given by\n\\[\n\\max\\Bigl\\{V^E(w'), \\,\\, \\mathbb{E}_{w''}V^U(w,w'')\\Bigr\\}.\n\\]\n\nThe overall value of the current unemployed state with previous wage $w$ and current wage offer $w'$ is\njust the utility of consumption plus the discounted value of the next period, i.e.\n\\begin{equation}\\label{EqVu}\nV^U(w,w') = u(\\alpha w) + \\beta \\max\\Bigl\\{V^E(w'), \\,\\, \\mathbb{E}_{w''}V^U(w,w'')\\Bigr\\},\n\\end{equation}\nwhere $\\beta$ is the discount factor.\n\nNow we turn to the case where the job status is employed ($s = E$).\nIn this case, the worker receives a wage $w$ in the current period, and so the utility of consumption is\njust\n\\[\nu(w).\n\\]\nIn the next period, the worker will have most recent wage $w$, she will receive wage offer $w''$, and will\nhave employment status $s'$. As in the unemployed case, $w''$ is unknown and treated as a random variable.\nUnlike the unemployed case, however, the worker's future employment status $s'$ is not under her control,\nbut rather is also a random variable. The reason for this is that the worker will remain employed\nuntil she loses the job, a random event that occurs with some fixed probability in each time period.\nHence, we must calculate the expected value of the next period with respect to both $w''$ and $s'$.\nWe may write the entire value function for the employed case as\n\\begin{equation}\\label{EqVe1}\n   V^E(w) = u(w) + \\beta \\mathbb{E}_{w'',s'}V(w,w'',s').\n\\end{equation}\n\nTo calculate the expectation term, we need to know the joint probability distribution over $w''$ and $s'$.\nThis can be characterized in the following way.\nWe assume that $s'$ and $w''$ are independent. Hence, we can split the joint expectation\noperator into the composition of the two individual expectation operators:\n\\[\n\\mathbb{E}_{w'',s'} = \\mathbb{E}_{w''}\\mathbb{E}_{s'}.\n\\]\nLet $\\gamma$ represent the probability that an employed worker becomes unemployed in the next period,\nso that $1-\\gamma$ is the probability of remaining employed in the next period.\nIf the worker stays employed in the next period ($s' = E$), then next period's wage equals the current\nperiod's wage, and the term inside the expectation is\n\\[\nV(w,w'',E) = V^E(w).\n\\]\nWe then have\n\\begin{align*}\n\\mathbb{E}_{s'}V(w,w'',s') &= (1-\\gamma)V(w,w'',E) + \\gamma V(w,w'',U)\\\\\n&= (1-\\gamma)V^E(w) + \\gamma V^U(w,w'').\n\\end{align*}\nNotice that the term $(1-\\gamma)V^E(w)$ is constant with respect to $w''$. Then\n\\begin{align*}\n\\mathbb{E}_{w''}\\mathbb{E}_{s'}V(w,w'',s') &= \\mathbb{E}_{w''}\\left[(1-\\gamma)V^E(w) + \\gamma V^U(w,w'')\\right]\\\\\n&= \\mathbb{E}_{w''}(1-\\gamma)V^E(w) + \\mathbb{E}_{w''}\\gamma V^U(w,w'')\\\\\n&= (1-\\gamma)V^E(w) + \\gamma \\mathbb{E}_{w''}V^U(w,w'').\n\\end{align*}\nHence, we can rewrite \\eqref{EqVe1} as follows:\n\\begin{equation}\\label{EqVe2}\n   V^E(w) = u(w) + \\beta \\Bigl[(1-\\gamma)V^E(w) + \\gamma \\mathbb{E}_{w''}V^U(w,w'')\\Bigr].\n\\end{equation}\n\nWe have now completely described the value function. What about the policy function?\nThe policy function for the unemployed worker gives his decision on whether to accept the job $s'=E$\nor to reject the job $s'= U$.\nThis will be a function of both the most recent wage $w$ and the current wage offer $w'$.\nThe employment status $s'$ in the next period is determined by the policy function $\\psi$:\n\\[\ns' = \\psi(w,w').\n\\]\n\nThese discrete choice problems are often called threshold\nproblems because the policy choice depends on whether the state variable is greater than or less than\nsome threshold level. That is, an unemployed worker will accept a job if and only if the offer wage is\nabove some set amount that depends on the most recent wage $w$. In the labor search model,\nthe threshold level is called the ``reservation wage'' $w_R'$. The reservation wage $w_R'$ is defined as\nthe wage offer such that the worker is indifferent between accepting the job $s' = E$ and\nstaying unemployed $s' = U$. Hence, this reservation wage satisfies the equation\n\\begin{equation}\\label{EqWR}\n   V^E(w_R') = E_{w''}\\left[V^U(w,w'')\\right].\n\\end{equation}\nThe policy function will then take the form of accepting the job if $w' \\geq w_R'$ or\nrejecting the job offer and remaining unemployed if $w' < w_R'$:\n\\begin{equation}\\label{EqSprime}\n   s' = \\psi(w,w') = \\begin{cases}\n                      E \\quad\\text{if}\\quad w' \\geq w_R' \\\\\n                      U \\quad\\text{if}\\quad w' < w_R'.\n                   \\end{cases}\n\\end{equation}\nFigure \\ref{fig:disc_policy} shows an example of the discrete policy function.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{disc_policy.pdf}\n\\caption{Here is the policy function for fixed $w = 50$.  Numerically we let 0 represent unemployment, $U$,\nand 1 represent employment, $E$.  Thus we see that an individual will choose to take a new job, given\ntheir old wage was 50, at a wage of roughly 35.  Thus for a previous wage of 50, we say the reservation wage is 35.}\n\\label{fig:disc_policy}\n\\end{figure}\n\nIn summary, the labor search discrete choice problem is characterized by the value functions \\eqref{EqV}, \\eqref{EqVu},\nand \\eqref{EqVe2}, the reservation wage \\eqref{EqWR}, and the policy function \\eqref{EqSprime}. Because wage offers\nare distributed according to some given probability distribution (denote the cdf by $F(w')$),\nand because the policy function takes the form of \\eqref{EqSprime},\nthe probability that the unemployed worker receives a wage offer that he will reject is $F(w_R')$ and the probability\nthat he receives a wage offer that he will accept is $1 - F(w_R')$. Just like the continuous choice cake eating\nproblems, this problem can be solved by value function, policy function, or modified policy function iteration.\n\nThe value function iteration solution method for the equilibrium in the labor search problem is analogous to the\nvalue function iteration from the previous labs. The only difference is that two value functions ($V^E$ and $V^U$)\nmust converge to a fixed point in this problem instead of just one value function converging in the previous problems.\nAlthough there are two value functions to consider, there is only one policy function, since decisions are only made\nin the unemployed state.  Thus, there is only one policy function on which to iterate in the case of policy or modified\npolicy iteration.\n\nIn the following problems, you will solve the job search problem using value function iteration and modified policy\nfunction iteration. Assume that the consumption utility function $u$ is given by\n\\[\nu(w) = \\sqrt{w}.\n\\]\nAssume that the probability of becoming unemployed in a given period is $\\gamma = 0.10$, the fraction of wages paid\nin unemployment benefits is $\\alpha = 0.5$, and the discount factor is $\\beta = 0.9$.\n\nAssume that the log of wage offers are distributed normally.  We then say that offers are distributed\nlognormally and write\n\\[\nw'\\sim \\text{LogN}(\\mu,\\sigma).\n\\]\nThis is a convenient choice for the distribution of\nwage offers.  Among other things, it guarantees that wage offers will be positive.\nA mean of $20$ and variance of $200$ are typical parameters of such a wage distribution,\nand we will use these parameters in the following problems.\n\nAs usual when dealing with continuous variables, we form a discrete approximation of\nthe possible wage values. In particular, approximate the wage values by a vector of\nlength $N = 500$ of equally-spaced values from $w_{min} = 0$ to $w_{max} = 100$, inclusive.\nWe then form a corresponding discrete approximation of the probability density function\n$f(w')$ for the lognormal wage offers using code provided in the file \\li{discretelognorm.py},\nas follows, where \\li{w} is the length-$N$ vector of wage values, $m$ is the mean, and $v$ is\nthe variance as specified above:\n\\begin{lstlisting}\n>>> from discretelognorm import discretelognorm\n>>> f = discretelognorm(w, m, v)\n\\end{lstlisting}\nThe function \\li{discretelognorm} computes the discrete pdf of the specified lognormal distribution in much\nthe same way that you calculate the discrete normal pdf when solving the stochastic cake eating problem.\n\n\n\\begin{problem}\nSolve the job search problem using value function iteration. Return the converged value functions\n$V^E$ and $V^U$, as well as the converged policy function $\\psi$. The following steps provide detailed\ninstructions. Note that there are multiple ways to proceed, and the following is simply one (fairly good)\npossibility.\n\\begin{enumerate}\n\n   \\item As described above, represent the possible wage values by an array \\li{w} of length\n   $N$. Denote this array entrywise by\n   \\[\n   w = (w_1,w_2,\\ldots,w_N).\n   \\]\n   Calculate the corresponding discrete lognormal pdf \\li{f}, exactly as shown above.\n\n   \\item Note that $u(w)$ and $u(\\alpha w)$ are needed when computing the value functions.\n   Since these quantities do not change from one iteration to another, it is smart to\n   compute them once at the outset. Denote $u(w)$ by \\li{uw} and $u(\\alpha w)$ by \\li{uaw}.\n   These are easily calculated as follows:\n\\begin{lstlisting}\n>>> uw = u(w)\n>>> uaw = u(alpha*w).reshape((N,1))\n\\end{lstlisting}\n    where \\li{u} is the square root function. We must reshape \\li{uaw} because of array broadcasting\n    issues that arise in the code snippets below.\n\n   \\item Since $V^E$ is a function of only $w$, it will be represented by a vector of length $N$, where\n   the $i$-th entry gives $V^E(w_i)$. The unemployed value function $V^U$, however,\n   is a function of both $w$ and $w'$, so it will be represented by an $N \\times N$ array,\n   where the $(i,j)$-th entry gives $V^U(w_i,w_j)$. Initialize the entries of these arrays to 0:\n\\begin{lstlisting}\n>>> VE = np.zeros(N)        #employed value function\n>>> VU = np.zeros((N,N))    #unemployed value function\n\\end{lstlisting}\n\n   \\item Note that $\\mathbb{E}_{w''}V^U(w,w'')$  is needed to calculate both $V^E$ and $V^U$.\n   This expectation depends on $w$, and so can be represented by a length $N$ array, where the\n   $i$-th entry is $\\mathbb{E}_{w''}V^U(w_i,w'')$.\n   It is convenient to assign a variable to this array to keep track of it throughout the iterations.\n   We denote the expectation by \\li{EVU}, and initialize it to zeros:\n\\begin{lstlisting}\n>>> EVU = np.zeros(N)\n\\end{lstlisting}\n\n   \\item For reasons that will soon become apparent, we will need to create a $N\\times N$ helper array\n   whose rows are equal to \\li{VE} (call this array \\li{MVE}), and a $N \\times N$ helper array whose columns\n   are equal to \\li{EVU} (call this array \\li{MEVU}).\n   At the outset, simply initialize these arrays to zeros.\n\n   \\item Because job status is a binary variable, the policy function returns one of two possible values. It is\n   convenient to represent ``employed\" by $1$ and ``unemployed\" by $0$. Now the policy function depends\n   on $w$ and $w'$, so it will also be represented by an $N\\times N$ array \\li{PSI} of zeros and ones,\n   where the $(i,j)$-th entry gives $\\psi(w_i, w_j)$.\n\n   \\item Now we are ready to begin the iteration.\n   A single iteration involves computing the updated value functions $V^E$ and $V^U$ from\n   equations \\eqref{EqVe2} and \\eqref{EqVu} and then calculating the $2$-norm distance between\n   both pairs of old and updated value functions to test for convergence. If both of these\n   $2$-norm distances are less than $10^{-9}$, terminate the iteration.\n\n   Before calculating the updated value functions, we first update our helper arrays \\li{MVE} and\n   \\li{MEVU}. The rows of \\li{MVE} need to equal \\li{VE}. We can use array broadcasting:\n\\begin{lstlisting}\n>>> MVE[:,:] = VE.reshape((1,N))\n\\end{lstlisting}\n   The columns of \\li{MEVU} need to equal \\li{EVU}, so use a similar technique:\n\\begin{lstlisting}\n>>> MEVU[:,:] = EVU.reshape((N,1))\n\\end{lstlisting}\n\n   Now let us address how to compute the updated $V^U$, which we denote by \\li{VU1}.\n   Equation \\eqref{EqVu} shows that it is the sum of\n   two terms. The first, $u(\\alpha w)$, we have already computed and stored in the variable \\li{uaw}.\n   The second term involves a maximization between two alternatives. One can imagine writing\n   a double for-loop ranging over the values of $w'$ and $w$ to compute each individual\n   $\\max\\{V^E(w'), \\mathbb{E}_{w''}V^U(w,w'')\\}$, but we can take advantage of the helper\n   arrays \\li{MVE} and \\li{MEVU} to do this computation in one efficient line of code.\n   Note that the $(i,j)$-th entry of \\li{MVE} is just $V^E(w_j)$ and the $(i,j)$-th\n   entry of \\li{MEVU} is $\\mathbb{E}_{w''}(w_i, w'')$, and\n   \\[\n   V^U(w_i,w_j) = u(\\alpha w_i) + \\beta\\max\\{V^E(w_j), \\mathbb{E}_{w''}V^U(w_i,w'')\\}.\n   \\]\n   Hence, taking the entrywise maximum of the arrays \\li{MVE} and \\li{MEVU} gives us the appropriate\n   max term for $V^U$. To get the entrywise maximum of two arrays, stack the arrays along a new\n   axis using \\li{np.dstack}, and maximize along that axis. The computation for \\li{VU}, then, is\n   \\begin{lstlisting}\n>>> VU1 = uaw + beta*np.max(np.dstack([MEVU, MVE]), axis=2)\n   \\end{lstlisting}\n\n   Calculating the updated $V^E$, denoted by \\li{VE1}, is more straightforward.\n   Equation \\eqref{EqVe2} shows that it is just\n   a particular linear combination of the arrays \\li{uw}, \\li{VE}, and \\li{EVU}:\n   \\begin{lstlisting}\n>>> VE1 = uw + beta*((1-gamma)*VE + gamma*EVU)\n   \\end{lstlisting}\n\n   We can now calculate the 2-norm distances between old and updated value functions.\n   It remains to update \\li{VE}, \\li{VU}, and \\li{EVU}.\n   The first two updates are trivial, and calculating \\li{EVU} is equivalent to the\n   matrix-vector multiplication of \\li{VU} with \\li{f}. This is similar to how we computed\n   expectations in previous labs:\n   \\begin{lstlisting}\n>>> EVU = np.dot(VU,f).ravel()\n   \\end{lstlisting}\n   We use the \\li{ravel} function to ensure that \\li{EVU} is a flat array.\n\n   \\item Notice that it is not necessary to iteratively update the policy function, as it is not needed\n   to update the value functions. Thus, we need only compute the policy function once, after convergence\n   of the value functions has been achieved. This is done in a manner similar to calculating\n   $\\max\\{V^E(w'), \\mathbb{E}_{w''}V^U(w,w'')\\}$ as described above, except we need to take the \\emph{argmax}:\n\\begin{lstlisting}\n>>> PSI = np.argmax(np.dstack([MEVU,MVE]), axis=2)\n\\end{lstlisting}\n\n   \\item Compute the reservation wage $w_R'$ as a function of the current wage $w$. It will be represented\n   by a length $N$ array called \\li{wr}. The reservation wage is the\n   value of $w'$ where the policy function changes from zeros to ones (the optimal choice changes from remaining\n   unemployed to accepting the job offer). We can calculate this as follows:\n   \\begin{lstlisting}\n>>> wr_ind = np.argmax(np.diff(PSI), axis = 1)\n>>> wr = w[wr_ind]\n   \\end{lstlisting}\n\n   \\item Plot the equilibrium reservation wage $w_R'$ of the converged problem as a function of the current\n   wage $w$ with the current wage on the $x$-axis and the reservation wage $w_R'$ on the $y$-axis. This is\n   the most common way to plot discrete choice policy functions. The reservation wage represents the wage\n   that makes the unemployed worker indifferent between taking a job offer and rejecting it. So any wage\n   above the reservation wage line represents $s' = E$ and any wage below the reservation wage line represents\n   $s' = U$. Your plot should resemble that in Figure \\ref{fig:res_wage}.\n\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{reservation_wage.pdf}\n\\caption{The reservation wage as a function of previous wage for the job search problem.}\n\\label{fig:res_wage}\n\\end{figure}\n\nIn the previous problem, it was necessary to iterate on two value functions.\nConsequently the convergence is relatively slow.\nWe can improve upon this situation by using modified policy function iteration.\n\n\\begin{problem}\nSolve the same problem, this time using modified policy function iteration with $15$ value function iterations\nwithin each policy iteration.  You should be able to re-use much of your code from the previous problem.\n\nStart off by initializing all of the same variables. Additionally, initialize your policy function array \\li{PSI},\nsay\n\\begin{lstlisting}\n>>> PSI = 2*np.ones((N,N))\n\\end{lstlisting}\n\nNext comes the iteration.\nEssentially, the iteration will consist of an outer while-loop (which terminates once the 2-norm distance\nbetween successive policy functions passes below $10^{-9}$), and an inner for-loop (with $15$ loops).\n\n\nThe first step in the while-loop is to calculate the new policy function \\li{PSI1}, just as in the previous\nproblem. Next, perform the inner for-loop, which consists simply of the value function iteration, but this\ntime using the current policy function. This means the line of code\n\\begin{lstlisting}\n>>> VU = uaw + beta*np.max(np.dstack([MEVU, MVE]), axis=2)\n\\end{lstlisting}\nis no longer valid, as it does not use the policy function. We must instead have\n\\begin{lstlisting}\n>>> VU = uaw + beta*(MVE*PSI1 + MEVU*(1 - PSI1))\n\\end{lstlisting}\nWhy is this code correct?\n\nFinally, after exiting the for-loop, calculate the 2-norm distance between the old and the new policy function,\nand then update your old policy function, i.e.\n\\begin{lstlisting}\n>>> PSI = PSI1\n\\end{lstlisting}\n\nAfter convergence is achieved, once again compute the reservation wage array, and plot it as in the previous\nproblem. Then return the converged policy function.\n\\end{problem}\n\n\\begin{problem}\nHow many iterations did value function iteration take?\nHow many iterations did modified policy function iteration take?\nWhich was faster?\n\\end{problem} ", "meta": {"hexsha": "eb9890fdffd05d56fc2ebf7b8573dcde5bd62cb6", "size": 21640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/PolicyFunctionIteration/Job_Search.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/PolicyFunctionIteration/Job_Search.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/PolicyFunctionIteration/Job_Search.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": 54.7848101266, "max_line_length": 119, "alphanum_fraction": 0.729805915, "num_tokens": 5787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619979547273, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6788733230695405}}
{"text": "\\documentclass[bigger]{beamer}\n\n\\input{header-beam} % change to header-handout for handouts\n\n% ====================\n\\title[Lecture 5]{Logic I F13 Lecture 5}\n\\date{September 24, 2013}\n% ====================\n\n\\include{header}\n\n\\section[Expressive Power]{Expressive Power of the Boolean Connectives}\n\n\n\n\\subsec{Truth Tables for the Boolean Connectives}{\n\n\\[\n\\begin{array}{c|c}\nP & \\lnot P\\\\\n\\hline\n\\T & \\F \\\\\n\\F & \\T\n\\end{array}\n\\qquad\n\\begin{array}{cc|c}\nP & Q & (P \\land Q)\\\\\n\\hline\n\\T & \\T & \\T\\\\\n\\T & \\F & \\F\\\\\n\\F & \\T & \\F\\\\\n\\F & \\F & \\F\n\\end{array}\n\\qquad\n\\begin{array}{cc|c}\nP & Q & (P \\lor Q)\\\\\n\\hline\n\\T & \\T & \\T\\\\\n\\T & \\F & \\T\\\\\n\\F & \\T & \\T\\\\\n\\F & \\F & \\F\n\\end{array}\n\\]\n\n}\n\n\n\n\n\\subsec{Neither \\dots nor \\dots}{\n\n\\bits\n\\item Neither a nor b is a cube\n\\item $\\sf \\lnot Cube(a) \\land \\lnot Cube(b)$\n\\item $\\sf \\lnot (Cube(a) \\lor Cube(b))$\n\\eit\n\n}\n\n\\subsec{Not Both}{\n\n\\bits\n\\item a and b are not both large\n\\item $\\sf \\lnot(Large(a) \\land Large(b))$\n\\item $\\sf \\lnot Large(a) \\lor \\lnot Large(b)$\n\\eit\n\n}\n\n\\subsec{Exclusive ``Or''}{\n\n\\bits\n\\item a or b is a cube (but not both)\n\\item $\\sf (Cube(a) \\lor Cube(b)) \\land \\lnot(Cube(a) \\land Cube(b))$\n\\item $\\sf (Cube(a) \\land \\lnot Cube(b)) \\lor (\\lnot Cube(a) \\land Cube(b))$\n\\eit\n}\n\n\\subsec{At Least One Of}{\n\n\\bits\n\\item At least one of a, b, and c is small\n\\item $\\sf Small(a) \\lor (Small(b) \\lor Small(c))$\n\\eit \n\n}\n\n\\subsec{At Least Two Of}{\n\n\\bits\n\\item At least two of a, b, and c are small\n\\item $\\sf (Small(a) \\land Small(b)) \\lor (Small(a) \\land Small(c)) \\lor (Small(b) \\land Small(c))$\n\\eit \n\n}\n\n\\subsec{At Least As Large As and $\\le$}{\n\n\\bits\n\\item a is at least as large as b\n\\bits\n\\item $\\sf Larger(a, b) \\lor SameSize(a, b)$\n\\item $\\sf \\lnot Smaller(a, b)$, $\\sf\\lnot Larger(b, a)$\n\\eit\n\\item $2 \\le 3$\n\\bits\n\\item $(1+1) < (1+(1+1)) \\lor (1+1) = (1+(1+1))$\n\\item $\\lnot (1 + (1+1)) < (1+1)$ \n\\eit\\eit\n\n}\n\\section{Step-by-Step Translations}\n\n\\subsec{Step-by-Step Method of Translation}{\n\n\\bit\n\\item a and b are either left of c or right of d, \\emph{but}\\\\ e is neither left of c nor right of d.\n\\bit\n\\item a and b are either left of c or right of d\n\\item but\n\\item e is neither left of c nor right of d\n\\eit\\eit\n}\n\n\\subsec{Step-by-Step Method of Translation}{\n\n\\bits\n\\item a \\emph{and} b are either left of c or right of d\n\\bit\n\\item a is left of c \\emph{or} right of d\n\\bit\n\\item a is left of c or a is right of d\\\\\n$\\sf LeftOf(a, c) \\lor RightOf(a, d)$\n\\eit\n\\item b is left of c \\emph{or} right of d\n\\bit\n\\item b is left of c or b is right of d\\\\\n$\\sf LeftOf(b, c) \\lor RightOf(b, d)$\n\\eit\n\\eit\n\\eit\n\\begin{align*}\n\\sf (LeftOf(a, c) \\lor {} & \\sf RightOf(a, d)) \\land {}\\\\\n\\sf (LeftOf(b, c) \\lor {} & \\sf RightOf(b, d))\n\\end{align*}\n\n}\n\n\\subsec{Step-by-Step Method of Translation}{\n\n\\bits\n\\item e is neither left of c nor right of d\n\\[\\sf \\lnot(LeftOf(e, c) \\lor RightOf(e, d))\\]\n\\eit\n}\n\n\\subsec{Step-by-Step Method of Translation}{\n\n\\bit\n\\item a and b are either left of c or right of d, but\\\\ e is neither left of c nor right of d.\n\\bit\n\\item a and b are either left of c or right of d\n\\begin{align*}\n\\sf (LeftOf(a, c) \\lor {} & \\sf RightOf(a, d)) \\land {}\\\\\n\\sf (LeftOf(b, c) \\lor {} & \\sf RightOf(b, d))\n\\end{align*}\n\\item but\n$\\land$\n\\item e is neither left of c nor right of d\n\\[\\sf \\lnot(LeftOf(e, c) \\lor RightOf(e, d))\\]\n\\eit\\eit\n\\begin{align*}\n\\sf((LeftOf(a, c) \\lor {} & \\sf RightOf(a, d)) \\land {} \\\\\n\\sf (LeftOf(b, c) \\lor {} & \\sf RightOf(b, d))) \\land {}\\\\\n\\sf \\lnot(LeftOf(e, c) \\lor {} &\\sf RightOf(e, d))\n\\end{align*}\n\n}\n\n\\section{Ambiguity}\n\n\\subsec{Ambiguity in English}{\n\n\\bit\n\\item Lexical ambiguity: one word---many meanings \\\\\ne.g., ``bank'', ``crane''\n\\item Syntactic ambiguity: one sentence---many readings\\\\\ne.g., \n\\bit\n\\item ``Flying planes can be dangerous'' (Chomsky)\n\\item ``One morning I shot an elephant in my pajamas.\\\\ How he got in my pajamas, I don't know.'' (Groucho Marx)\n\\eit\n\\eit\n\n}\n\n\\subsec{Connectives and Ambiguity}{\n\n\\bits\n\\item a adjoins b and c or d\n\\item a adjoins [[b and c] or d]\\\\\n$\\sf (Adjoins(a, b) \\land Adjoins(a, c)) \\lor Adjoins(a, d)$\n\\item a adjoins [b and [c or d]]\\\\\n$\\sf Adjoins(a, b) \\land (Adjoins(a, c) \\lor Adjoins(a, d))$\n\\eit\n\n}\n\n\\subsec{The Man Who Was Hanged by a Comma}{\n\n\\bit\n\\item Sir Roger Casement (1864--1916)\n\\item British consul to Congo and Peru\n\\item Tried to recruit Irish revolutionaries in Germany during WWI\n\\item Tried for treason\n\\eit\n\n}\n\n\\subsec{Treason Act of 1351}{\n\n\\small \nITEM, Whereas divers Opinions have been before this Time in what Case\nTreason shall be said, and in what not; the King, at the Request of\nthe Lords and of the Commons, hath made a Declaration in the Manner as\nhereafter followeth, that is to say; When a Man doth compass or\nimagine the Death of our Lord the King, or of our Lady his Queen or of\ntheir eldest Son and Heir; or if a Man do violate the King's\nCompanion, or the King's eldest Daughter unmarried, or the Wife of the\nKing's eldest Son and Heir; or \\textbf{if a Man do levy War against our Lord\nthe King in his Realm, or be adherent to the King's Enemies in his\nRealm, giving to them Aid and Comfort in the Realm\\onslide<2>{\\emph{,}} or elsewhere}, and\nthereof be probably attainted of open Deed by the People of their\nCondition: \\dots And it is to be\nunderstood, that in the Cases above rehearsed, that ought to be judged\nTreason which extends to our Lord the King, and his Royal Majesty:\n\\dots\n\n}\n\n\\subsec{R v. Casement in the Blocks Language}{\n\n\\bits\n\\item a is a cube in front of b, or a tetrahedron in front of b[,] or in back of b.\n\n\\item Without comma:\n\\begin{align*}\n\\sf(Cube(a) \\land {} & \\sf FrontOf(a, b)) \\lor {}\\\\\n\\sf(Tet(a) \\land {} & \\sf(FrontOf(a, b) \\lor BackOf(a, b)))\n\\end{align*}\n\\item With comma:\n\\begin{align*}\n\\sf(Cube(a) \\land {} & \\sf(FrontOf(a, b) \\lor BackOf(a, b))) \\lor {}\\\\\n\\sf(Tet(a) \\land {} & \\sf(FrontOf(a, b) \\lor BackOf(a, b))\n\\end{align*}\n\\eit\n}\n\n\\subsec{More Scope Ambiguity}{\n\n\\bits\n\\item a and b are left of c or right of d\n\\item a is left of c or right of d, and so is b\n\\begin{align*}\n\\sf (LeftOf(a, c) \\lor {} & \\sf RightOf(a, d)) \\land {}\\\\\n\\sf (LeftOf(b, c) \\lor {} & \\sf RightOf(b, d))\n\\end{align*}\n\\item a and b are both left of c, or a and b are both right of d\n\\begin{align*}\n\\sf (LeftOf(a, c) \\land {} & \\sf LeftOf(b, c)) \\lor {}\\\\\n\\sf (RightOf(a, d) \\land {} & \\sf RightOf(b, d))\n\\end{align*}\n\\eit\n\n}\n\n\\end{document}\n", "meta": {"hexsha": "64c84e55eb52a3ecb95b741ea18128029d9e6acd", "size": 6365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "279-lec05.tex", "max_stars_repo_name": "rzach/phil279", "max_stars_repo_head_hexsha": "722ec82ae7a4593d40c72083d830c4e3e4864dc0", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-09-23T13:42:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-21T10:48:55.000Z", "max_issues_repo_path": "279-lec05.tex", "max_issues_repo_name": "rzach/phil279", "max_issues_repo_head_hexsha": "722ec82ae7a4593d40c72083d830c4e3e4864dc0", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "279-lec05.tex", "max_forks_repo_name": "rzach/phil279", "max_forks_repo_head_hexsha": "722ec82ae7a4593d40c72083d830c4e3e4864dc0", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8956834532, "max_line_length": 112, "alphanum_fraction": 0.6375490966, "num_tokens": 2342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.6788733222505812}}
{"text": "\\gotosection{1}{2}\n\\subsection{Introducing the actors: matrices}\n\n\\begin{exercise}{2}\n  \\begin{enumerate}\n    \\item $\\begin{xmatrix}1 & 2 & 3 \\\\ 4 & 5 & 6\\end{xmatrix}\n           \\begin{xmatrix}7 & 8 \\\\ 9 & 0 \\\\ 1 & 2\\end{xmatrix} =\n           \\begin{xmatrix}\n              7 + 18 + 3 &  8 + 0 +  6 \\\\\n             28 + 45 + 6 & 32 + 0 + 12\n           \\end{xmatrix} =\n           \\begin{xmatrix}28 & 14 \\\\ 79 & 44\\end{xmatrix}$\n\n    \\item Incompatible matrices: the first matrix has 2 columns while the second\n          one has 3 rows.\n\n    \\item $\\begin{aligned}[t]\n            \\begin{xmatrix}\n               1 & -1 &  1 \\\\\n              -1 &  0 &  2 \\\\\n              -1 &  1 &  1\n            \\end{xmatrix}\n            \\begin{xmatrix}\n               0 &  1 & -1 \\\\\n              -1 &  1 &  2 \\\\\n               2 &  0 & -2\n            \\end{xmatrix} &=\n            \\begin{xmatrix}\n              0 + 1 + 2 &  1 - 1 + 0 & -1 - 2 - 2 \\\\\n              0 + 0 + 4 & -1 + 0 + 0 &  1 + 0 - 4 \\\\\n              0 - 1 + 2 & -1 + 1 + 0 &  1 + 2 - 2\n            \\end{xmatrix} \\\\ &=\n            \\begin{xmatrix}\n              3 &  0 & -5 \\\\\n              4 & -1 & -3 \\\\\n              1 &  0 &  1\n            \\end{xmatrix}\n          \\end{aligned}$\n\n    \\item $\\begin{xmatrix}7 & 1 \\\\ -1 & 0 \\\\ 2 & 3\\end{xmatrix}\n           \\begin{xmatrix}5 \\\\ -4\\end{xmatrix} =\n           \\begin{xmatrix}\n             35 - 4 \\\\\n             -5 + 0 \\\\\n             10 - 12\n           \\end{xmatrix} =\n           \\begin{xmatrix}31 \\\\ -5 \\\\ -2\\end{xmatrix}$\n\n    \\item \\def \\tmp{\\begin{bmatrix*}[r]0 & 1 \\\\ -1 & 3\\end{bmatrix*}}\n          $\\begin{aligned}[t]\n            \\begin{xmatrix}1 & 2 \\\\ 0 & 3\\end{xmatrix}\n            \\begin{xmatrix}1 & 4 \\\\ 1 & 3\\end{xmatrix}\n            \\tmp &=\n            \\begin{xmatrix}\n              1 + 2 & 4 + 6 \\\\\n              0 + 3 & 0 + 9\n            \\end{xmatrix}\n            \\tmp \\\\ &=\n            \\begin{xmatrix}3 & 10 \\\\ 3 & 9\\end{xmatrix}\n            \\tmp \\\\ &=\n            \\begin{xmatrix}\n              0 + 3 &   0 +  9 \\\\\n              -3 + 9 & -10 + 27\n            \\end{xmatrix} \\\\\n            &= \\begin{xmatrix}3 & 9 \\\\ 6 & 17\\end{xmatrix}\n          \\end{aligned}$\n\n    \\item Incompatible matrices: the first matrix has 3 columns while the second\n          one has 2 rows.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{3}\n  \\begin{enumerate}\n    \\item $\\begin{pmatrix}AB_{13}\\\\AB_{23}\\end{pmatrix} =\n           \\begin{xmatrix}1 & 2 & 0\\\\3 & 1 & -1\\end{xmatrix}\n           \\begin{pmatrix}1 \\\\ 2 \\\\ 3\\end{pmatrix} =\n           \\begin{pmatrix}1+4 \\\\ 3+2-3\\end{pmatrix} =\n           \\begin{pmatrix}5 \\\\ 2\\end{pmatrix}$\n    \\item $\\begin{aligned}[t]\n            \\begin{xmatrix}AB_{21} & AB_{22} & AB_{23}\\end{xmatrix} &=\n            \\begin{xmatrix}3 & 1 & -1\\end{xmatrix}\n            \\begin{xmatrix}\n              2 & 5 & 1 \\\\\n              1 & 4 & 2 \\\\\n              1 & 3 & 3\n            \\end{xmatrix}\n            \\\\ &=\n            \\begin{xmatrix}6 + 1 - 1 & 15 + 4 - 3 & 3 + 2 - 3\\end{xmatrix}\n            \\\\ &=\n            \\begin{xmatrix}6 & 16 & 2\\end{xmatrix}\n          \\end{aligned}$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{5}\n  Since $A$ is symmetric, $A = A^{\\top}$.\n  \n  \\begin{enumerate}\n    \\item True. $B^{\\top}A = B^{\\top}A^{\\top} = (AB)^{\\top}$ \\QED\n    \\item True. $B^{\\top}A^{\\top} = (AB)^{\\top} = (A^{\\top}B)^{\\top}$ \\QED\n    \\item False. $(A^{\\top}B)^{\\top} = B^{\\top}A \\neq BA$, \n          since $B^{\\top} = B$ doesn't hold if $B$ is not symmetric.\n    \\item False. $(AB)^{\\top} = B^{\\top}A^{\\top} \\neq A^{\\top}B^{\\top}$, \n          since $XY = YX$ iff $X$ is the inverse of $Y$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{8}\n  The only value of $a$ such that $AB = BA$ is $0$, as:\n  \\medskip\n\n  $AB = \\begin{xmatrix}1 & 1 \\\\ 1 & 0\\end{xmatrix}\n        \\begin{xmatrix}1 & 0 \\\\ a & 1\\end{xmatrix}\n      = \\begin{xmatrix}1 + a & 1 \\\\ 1 & 0\\end{xmatrix}$\n  \\medskip\n\n  $AB = \\begin{xmatrix}1 & 0 \\\\ a & 1\\end{xmatrix}\n        \\begin{xmatrix}1 & 1 \\\\ 1 & 0\\end{xmatrix}\n      = \\begin{xmatrix}1 & 1 \\\\ 1 + a & a\\end{xmatrix}$\n  \\medskip\n\n  $\\left\\{\n    \\begin{aligned}\n      1 + a &= 1 \\\\\n          a &= 0\n    \\end{aligned}\n  \\right.\\quad \\Longrightarrow \\quad a = 0$\n\\end{exercise}\n\n\\begin{exercise}{10}\n  Follow the formula for the inverse of $2\\times2$-matrix:\n\n  \\begin{align*}\n    A^{-1} &= \\frac{1}{a^2-0}\\begin{xmatrix}a & -b\\\\0 & a\\end{xmatrix} \\\\\n           &= \\begin{xmatrix}\n                \\frac{1}{a} & -\\frac{b}{a^2} \\\\\n                          0 &  \\frac{1}{a}\n              \\end{xmatrix}\n  \\end{align*}\n\\end{exercise}\n\n\\begin{exercise}{15}\n  Let $A = \\begin{xmatrix}\n             1 & a & b \\\\\n             0 & 1 & c \\\\\n             0 & 0 & 1\n           \\end{xmatrix}$,\n  and $B = \\begin{xmatrix}\n             1 & x & y \\\\\n             0 & 1 & z \\\\\n             0 & 0 & 1\n           \\end{xmatrix}$.\n  The product is\n  \n  $$AB =\n    \\begin{xmatrix}\n      1 & x + a & y + az + b \\\\\n      0 &     1 &      z + c \\\\\n      0 &     0 &          1\n    \\end{xmatrix} =\n    I_3 = \\begin{xmatrix}1&0&0\\\\0&1&0\\\\0&0&1\\end{xmatrix}$$\n  \n  Then we have:\n  \\medskip\n  \n  $\\left\\{\n    \\begin{aligned}\n           x + a &= 0 \\\\\n      y + az + b &= 0 \\\\\n           z + c &= 0\n    \\end{aligned}\n  \\right.\\quad \\Longrightarrow \\quad\n  \\left\\{\n    \\begin{aligned}\n               x &= -a \\\\\n               z &= -c \\\\\n      y - ac + b &= 0\n    \\end{aligned}\n  \\right.\\quad \\Longrightarrow \\quad\n  \\left\\{\n    \\begin{aligned}\n      x &= -a     \\\\\n      y &= ac - b \\\\\n      z &= -c\n    \\end{aligned}\n  \\right.$\n\\end{exercise}\n\n\\begin{exercise}{16}\n  From the definition of transpose and symmetric matrix,\n  it is obvious that $(A^{\\top})^{\\top} = A$,\n  and that if $A = A^{\\top}$, then $A$ is symmetric.\n\n  For any matrix $A$, since $(A^{\\top}A)^{\\top} = A^{\\top}(A^{\\top})^{\\top} = A^{\\top}A$,\n  namely $A^{\\top}A$ equal to its transpose, $A^{\\top}A$ is symmetric. \\QED\n\\end{exercise}\n", "meta": {"hexsha": "fb315b688a960c1e02cf6ea7de346aae905dbef2", "size": 5920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW1/sec0102.tex", "max_stars_repo_name": "notcome/fa15-linear-algebra", "max_stars_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW1/sec0102.tex", "max_issues_repo_name": "notcome/fa15-linear-algebra", "max_issues_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW1/sec0102.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": 29.898989899, "max_line_length": 89, "alphanum_fraction": 0.4341216216, "num_tokens": 2173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6788733091094888}}
{"text": "%---------------------------------------------------------------------------------\n\\chapter{Fitzhugh-Nagumo Model Example}\n\\label{chap:fitzhugh-nagumo}\n%---------------------------------------------------------------------------------\n\\section{Background}\n\\label{sec:background}\nWe will look into Fitzhugh-Nagumo model as an application of the Python package. The Fitzhugh-Nagumo model describes an excitable system, such as the action potential of cardiac cells. The action potential was first described by Hodgkin and Huxley. Their model were then simplified to the Fitzhugh-Nagumo model, retaining the fast-slow phase and the excitability of the Hodgkin \\& Huxley model. \\cite{Keener2009}\n\nThis model is relevant to my D.Phil.~project as my project will be related to action potential of cardiac muscle cells, an excitable system. I will be working on sodium ion channels of cardiac muscle cells, studying the effect of the flow of sodium ions across the cell membrane on the cell's action potential. Moreover, Fitzhugh-Nagumo model captures all the important features of an action potential, the excitability and the fast-slow phase. Therefore, it is a good simple model to start with.\n\n\\section{Fitzhugh-Nagumo model}\n\\label{sec:FHN}\nThe definition of Fitzhugh-Nagumo model is\n\\begin{align}\n\\label{eqn:FHN}\n    \\epsilon \\frac{dv}{dt} &= f(v) - w + I_{app} \\\\\n    \\frac{dw}{dt} &= v - \\gamma w \\label{eqn:FHN-end}\n\\end{align}\nwhere $f(v) = v(1-v)(v-\\alpha)$, $0 < \\alpha < 1$, $\\epsilon \\ll 1$, $I_{app}$ is the applied current and $t$ is time. The fast $v$ is the excitation variable, while the slow $w$ is the recovery variable.\n\nIn this implementation, the parameters are chosen to be $\\alpha = 0.1$, $\\gamma = 0.5$, $\\epsilon = 0.01$ and $I_{app} = 0.026$, taking reference from \\cite{Chapwanya2018}.\nThe initial values are taken to be near the origin, which are $(v_0, w_0) = (0.01, 0.01)$. The model is solved for time $t$ from 0 to 1.\n\nFitzhugh-Nagumo model is solved with the various numerical methods implemented in the software that I have developed. The solutions of the model are in a notebook at the link:  \\href{https://nbviewer.jupyter.org/github/FarmHJ/numerical-solver/blob/main/examples/fitzhugh_nagumo.ipynb}{\\underline{\\emph{Fitzhugh-Nagumo model notebook}}}. \n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{FHN_Euler_explicit}\n    \\caption{(\\textit{A}) Phase plane of $v$ and $w$ by Euler's explicit method. (\\textit{B}) Graph of $v$ and $w$ against time by Euler's explicit method.}\n    \\label{fig:FHN_Euler_explicit}\n\\end{figure}\n\nFrom Figure \\ref{fig:FHN_Euler_explicit} B, we can see that $v$, the excitation variable is excited in the early stage. While $v$ increases significantly, the change in $w$ is small. After $v$ reaches its peak and starts to reduce, $w$ increases slowly. This can be observed in both the phase plane (Figure \\ref{fig:FHN_Euler_explicit} A) and the variable graph (Figure \\ref{fig:FHN_Euler_explicit} B). When the variable $v$ starts to recover to its original value, $w$ is at its maximum. The scattering of points in the phase plane captures the feature of the model, where the change in $v$ is rapid while the change in $w$ is slow. When the change in $v$ is significantly larger than the change in $w$, the points are sparse. On the other hand, the points are packed when $w$ increases or decreases more than $v$. However, in the adaptive methods, such insights cannot be interpreted directly from the phase plane. Therefore, green triangles were plotted in Figure \\ref{fig:FHN_adaptive} B to indicate the adapted mesh points. The mesh points are adapted towards large change in $v$ or $w$ over a short period of time.\n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{FHN_adaptive}\n    \\caption{(\\textit{A}) Phase plane of $v$ and $w$ for adaptive method BS23. (\\textit{B}) Graph of $v$ and $w$ against time for adaptive method BS23}\n    \\label{fig:FHN_adaptive}\n\\end{figure}\n\n\\section{Convergence of Fitzhugh-Nagumo model}\n\\label{sec:FHN-convergence}\nA notebook (accessible from the link: \\href{https://nbviewer.jupyter.org/github/FarmHJ/numerical-solver/blob/main/examples/fhn_model_convergence.ipynb}{\\underline{\\emph{Fitzhugh-Nagumo convergence notebook}}}) is created to test the convergence of the solution of the Fitzhugh-Nagumo model. Since the model has no analytical solution, it is tested against a reference solution. The reference solutions are assumed to be sufficiently accurate. For methods with fixed step size, which are the one-step methods and predictor-corrector method, the reference solutions are constructed by using a much smaller step size of $1^{-7}$, as compared to $1^{-5}$, the smallest step size for other numerical solutions. For methods with adaptive step size, reference solutions are obtained by using a much smaller tolerance value of $1^{-8}$, as compared to $1^{-5}$, the smallest tolerance value for other numerical solutions. This notebook shows the numerical solution computed for different methods at different step sizes or tolerance values. The numerical solutions are then compared with their respective reference solutions. In both methods, the error decreases as the step size or the tolerance value decreases, as shown in Figure \\ref{fig:Euler_explicit_error} and Figure \\ref{fig:adaptive_error}.\n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{FHN_Euler_explicit_error_behaviour}\n    \\caption{Error at a mesh point for Euler's explicit method. The Fitzhugh-Nagumo model Eqs.~\\eqref{eqn:FHN}-\\eqref{eqn:FHN-end} is solved with Euler's explicit method at different step sizes. The error is the absolute difference between reference solution and numerical solution at $x=0.7$. The reference solution is taken at step size of $1^{-7}$. Note that $\\log(1^{-7})\\simeq-16.118$.}\n    \\label{fig:Euler_explicit_error}\n \\end{figure}\n\\begin{figure}\n   \\includegraphics[width=0.95\\columnwidth]{FHN_adaptive_error_behaviour}\n   \\caption{Sum of error for adaptive method BS23. The Fitzhugh-Nagumo model Eqs.~\\eqref{eqn:FHN}-\\eqref{eqn:FHN-end} is solved with BS23 method at different absolute tolerance values. The relative tolerance is fixed at $1^{-15}$. The error is the sum of absolute difference between reference solution and numerical solution at all mesh points. The reference solution is taken at relative tolerance of $1^{-8}$. Note that $\\log(1^{-8})\\simeq-18.421$.}\n   \\label{fig:adaptive_error}\n\\end{figure}", "meta": {"hexsha": "3d7daea99fbc26ebab7e873a508966be5143339f", "size": 6454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/fitzhugh_nagumo.tex", "max_stars_repo_name": "FarmHJ/numerical-solver", "max_stars_repo_head_hexsha": "8a9b823b0ca6eb3c714c055324f35c74d5af5263", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/fitzhugh_nagumo.tex", "max_issues_repo_name": "FarmHJ/numerical-solver", "max_issues_repo_head_hexsha": "8a9b823b0ca6eb3c714c055324f35c74d5af5263", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2020-12-12T08:05:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-23T15:12:32.000Z", "max_forks_repo_path": "report/fitzhugh_nagumo.tex", "max_forks_repo_name": "FarmHJ/numerical-solver", "max_forks_repo_head_hexsha": "8a9b823b0ca6eb3c714c055324f35c74d5af5263", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 121.7735849057, "max_line_length": 1292, "alphanum_fraction": 0.7466687326, "num_tokens": 1683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.6788733060940575}}
{"text": "\\input{../../style/preamble}\n\\input{../../latex-math/basic-math}\n\\input{../../latex-math/basic-ml}\n\n\\newcommand{\\titlefigure}{figure/lasso_ridge_enet_2d.png}\n\\newcommand{\\learninggoals}{\n  \\item Know the elastic net as compromise between Ridge and Lasso regression\n  \\item Know regularized logistic regression\n}\n\n\\title{Introduction to Machine Learning}\n\\date{}\n\n\\begin{document}\n\n\\lecturechapter{Elastic Net and Regularization for GLMs}\n\\lecture{Introduction to Machine Learning}\n\n\n\n% \\section{Elastic Net}\n\n\\begin{vbframe} {Elastic Net}\n\n\nElastic Net combines the $L_1$ and $L_2$ penalties:\n\n$$\n\\mathcal{R}_{\\text{elnet}}(\\thetab) =  \\sumin (\\yi - \\thetab^\\top \\xi)^2 + \\lambda_1 \\|\\thetab\\|_1 + \\lambda_2 \\|\\thetab\\|_2^2.\n$$\n\n\\begin{figure}\n\\includegraphics[width=0.6\\textwidth]{figure/lasso_ridge_enet_2d.png}\\\\\n\\end{figure}\n\n\n\\begin{itemize}\n\\item Correlated predictors tend to be either selected or zeroed out together.\n\\item Selection of more than $n$ features possible for $p>n$.\n\\end{itemize}\n\n\n\\framebreak\n\\footnotesize\nSimulating two examples with each 50 data sets and 100 observations each: \\\\\n\n\n$$\\ydat =\\Xmat \\boldsymbol{\\beta}+\\sigma \\epsilon, \\quad \\epsilon \\sim N(0,1), \\quad \\sigma = 1$$\n  \n  \\begin{columns}\n\\begin{column}{0.5\\textwidth}\n\\begin{center}\n\\textbf{Ridge} performs better for: \\\\ \n$\\boldsymbol{\\beta}=(\\underbrace{2,\\ldots,2}_{5},\\underbrace{0,\\ldots,0}_{5})$\\\\\n$ \\operatorname{corr}(\\Xmat_{i},\\Xmat_{j})=0.8^{|i-j|}$ for all $i$ and $j$\n  \\end{center}\n\\end{column}\n\\begin{column}{0.5\\textwidth} \n\\begin{center}\n\\textbf{Lasso} performs better for: \\\\\n$\\boldsymbol{\\beta}=(2, 2, 2,\\underbrace{0,\\ldots,0}_{7})$ \\\\\n$\\operatorname{corr}(\\Xmat_{i},\\Xmat_{j})= 0$ for all $i \\neq j$, otherwise 1\n\\end{center}\n\\end{column}\n\\end{columns}\n\n\\begin{figure}\n\\includegraphics[width=1\\textwidth]{figure_man/elastic-net02.png}\\\\\n\\end{figure}\n\n\\framebreak\n\n\\begin{figure}\n\\includegraphics[width=0.9\\textwidth]{figure_man/elastic-net03.png}\\\\\n\\end{figure}\n\n\n\\normalsize\nSince Elastic Net offers a compromise between Ridge and Lasso, it is suitable for both data situations.\n\n\\end{vbframe}\n\n\n% \\section{Regularized Logistic Regression}\n\n\\begin{vbframe}{Regularized Logistic Regression}\n\nRegularizers can be added very flexibly to basically any model which is based on ERM.\n\n\\lz \n\nHence, we can, e.g., construct $L_1$- or $L_2$-penalized logistic regression to enable coefficient shrinkage and variable selection in this model. \n\n% \\lz \n% We can add a regularizer to the risk of logistic regression\n\n\\begin{align*}\n\\riskrt &= \\risket + \\lambda \\cdot J(\\thetab) \\\\\n%&= \\sumin \\mathsf{log} \\left[1 + \\exp \\left(-\\yi f\\left(\\left.\\xi~\\right|~ \\thetab\\right)\\right)\\right] + \\lambda \\cdot J(\\thetab) \\\\\n&= \\sumin \\mathsf{log}\\left[1 + \\mathsf{exp}\\left(-2\\yi f\\left(\\left.\\xi~\\right|~ \\thetab\\right)\\right)\\right] + \\lambda \\cdot J(\\thetab)\n\\end{align*}\n\n% The other parts of the logistic regression remain exactly the same,\n% except for the fitting algorithm to find \\(\\hat{\\thetab}_{\\text{reg}}\\) (no closed-form solution, numerical optimization methods are necessary).\n\n\\end{frame}\n\n\\begin{frame}{Regularized Logistic Regression}\n\n\nWe fit a logistic regression model using polynomial features for \\(x_1\\)\nand \\(x_2\\) with maximum degree of \\(7\\). We add an $L_2$ penalty. We\nsee for\n\n\\begin{itemize}\n\n\\item\n  \\(\\lambda = 0\\): The unregularized model seems to overfit.\n\\item\n  \\(\\lambda = 0.0001\\): Regularization helps to learn the underlying\n  mechanism.\n\\item\n  \\(\\lambda = 1\\): The real data-generating process is captured very well.\n\\end{itemize}\n\n\\scriptsize\n\n\\begin{figure}\n\\includegraphics[width=0.8\\textwidth]{figure_man/logistic-reg.png}\\\\\n\\end{figure}\n\n\n\\normalsize \n\n\\end{vbframe}\n\n\n\\endlecture\n\\end{document}\n", "meta": {"hexsha": "a1b9ce88560ee5e322cb6357e2d01a341fd0e0e7", "size": 3734, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/regularization/slides-regu-enetlogreg.tex", "max_stars_repo_name": "jukaje/lecture_i2ml", "max_stars_repo_head_hexsha": "cd4900f5190e9d319867b4c0eb9d8e19f659fb62", "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": "slides/regularization/slides-regu-enetlogreg.tex", "max_issues_repo_name": "jukaje/lecture_i2ml", "max_issues_repo_head_hexsha": "cd4900f5190e9d319867b4c0eb9d8e19f659fb62", "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": "slides/regularization/slides-regu-enetlogreg.tex", "max_forks_repo_name": "jukaje/lecture_i2ml", "max_forks_repo_head_hexsha": "cd4900f5190e9d319867b4c0eb9d8e19f659fb62", "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": 26.6714285714, "max_line_length": 147, "alphanum_fraction": 0.7163899304, "num_tokens": 1201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.6788328442314634}}
{"text": "\n\\subsection{Constraint Satisfaction Problem}\n\nA CSP problem is one where we don't care about the path, we just want to identify the goal state.\n\nFor example, solving a sudoku\n\n\\subsection{Defining a CSP}\n\nA CSP has:\n\n\\begin{itemize}\n\\item Variables \\(X_i\\).\n\\item Domain for each variable \\(D_i\\).\n\\item Constraints \\(C_j\\).\n\\end{itemize}\n\nIn a CSP there are a range of variables each with a domain. There are on top constraints on combinations of values.\n\nA solution does not violate any constraint.\n\nTo solve, start with no allocations of variables. successor function assigns a value to an unassigned variable. goal test\n\nUse heuristic minimum remaining value MRV: choose variable with fewest remaining legal values\n\nLeast constraining value: choose item in domain which constrains the least other moves\n\nForward checking. keep track of remaining legal moves for each variable. terminate if none left\n\nAfter each move, update legal moves for each\n\nImplement all this with recursive backtrack function, which returns a solution or failure. This is a depth first search\n\n\\subsection{Arc-consistency}\n\nX-Y is arc consistent if all of domain of X is consistnet with some value of Y.\n\n\\subsection{Node-consistency}\n\nX is node consistent if all of domain satisfies all unary constraint.\n\n\\subsection{Path-consistency}\n\nArc consistency for additional variables.\n\n\\subsection{Constraint propagation}\n\nConstraint propagation can be used to prevent bad choices\n\nWe can check for:\n\n\\begin{itemize}\n\\item node-consistency\n\\item arc-consistency\n\\item path-consistency\n\\end{itemize}\n\n\\subsection{AC-3}\n\nAC-3 algorihm makes a CSP arc-consistent\n\nTake all arcs.\n\nIt may be possible to break the problem down into sub problems, making the problems much easier to solve.\n\nCan do this before/after other algorithm.\n\n", "meta": {"hexsha": "9a8809cfe084aee82cd6fbbacc3493989dcc2c3b", "size": 1801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/CSP/01-01-constraint.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/CSP/01-01-constraint.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/CSP/01-01-constraint.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.4852941176, "max_line_length": 121, "alphanum_fraction": 0.7890061077, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6788328328496306}}
{"text": "\\chapter{Networks from Distances}\n\nSo far we have been using existing network graphs. But we can also generate a graph from regular tabular data. Let us take the \\emph{iris} data set. For now, we only have flowers as rows and their characteristics as columns. So how do we transform this to nodes and edges?\n\nBy looking at similarities. Rows will be nodes and the edge will be created between two rows if their similarity is above a certain threshold. Nice, isn't it?\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{workflow.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nFirst, we need distance matrix, which we can compute with the \\widget{Distances} widget. Let's stick with Euclidean distances as it works well with this 4-dimensional data set.\n\nThen pass the distance matrix to \\widget{Network from Distances}. The widget enables setting the distances threshold, which we will set to 2.0 percentiles (meaning we keep the top 2\\% of the edges that connect the most similar nodes).\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.45]{net-from-distances.png}\n    \\caption{$\\;$}\n\\end{figure}\n\n\\newpage\n\nFinally, pass the constructed graph to \\widget{Network Explorer}. Remember, this is not a scatter plot. The position of the points is not mapped to any sort of attribute. In the graph, you can simply see which elements are most similar to one another.\n\n\\begin{figure*}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{network-explorer.png}\n    \\caption{$\\;$}\n\\end{figure*}\n", "meta": {"hexsha": "c1966ce37207db8986a7fc83e453babc33f1b2b1", "size": 1516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/net-012-networks-from-distances/networks-from-distances.tex", "max_stars_repo_name": "PrimozGodec/orange-lecture-notes", "max_stars_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-10-13T14:31:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:47:06.000Z", "max_issues_repo_path": "chapters/net-012-networks-from-distances/networks-from-distances.tex", "max_issues_repo_name": "PrimozGodec/orange-lecture-notes", "max_issues_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-02-26T13:33:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-25T19:15:34.000Z", "max_forks_repo_path": "chapters/net-012-networks-from-distances/networks-from-distances.tex", "max_forks_repo_name": "PrimozGodec/orange-lecture-notes", "max_forks_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-19T16:55:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T20:35:41.000Z", "avg_line_length": 47.375, "max_line_length": 272, "alphanum_fraction": 0.7526385224, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6788328266797462}}
{"text": "\\section{Background}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{Background: MDP}\n\\textbf{The environment}, $E$: \\\\\na Markov decision process with a state space $S$, action space $A = \\mathbb{R}^N$,\nan initial state distribution $p(s_1)$, transition dynamics $p(s_{t+1}|s_t, a_t)$, and\nreward function $r(s_t, a_t)$.\n\\vspace{2.5mm}\n\n\\textbf{At each discrete timestep} $t$, \\\\\nthe agent receives an observation $x_t = s_t$ (fully observable),\ntakes an action $a_t$ and receives a scalar reward $r_t$.\n\\vspace{2.5mm}\n\n\\textbf{The return from a state}: \\\\\n$R_t= \\sum_{i=t}^T  \\gamma^{(i-t)} r(s_i, a_i)$ with a discounting factor $\\gamma \\in [0, 1]$.\n\\vspace{2.5mm}\n\n\\textbf{Goal}: \\\\\nto learn a policy, $\\pi: S \\mapsto P(A)$, which\nmaximizes $J = \\mathbb{E}_{r_i,s_i \\sim E,a_i \\sim \\pi} [R_1]$.\n\\vspace{2.5mm}\n\n\\textbf{Action-value function}:\\\\\n$Q^{\\pi}(s_t,a_t) = \\mathbb{E}_{r_{i \\ge t},s_{i>t} \\sim E,a_{i>t} \\sim \\pi} [R_t|s_t,a_t]$.\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Background: MDP with deterministic policy}\nBellman equation (the recursive relationship):\n\\begin{equation}\nQ^{\\pi} (s_t,a_t) = \\mathbb{E}_{r_{t},s_{t+1} \\sim E} \\Big[ r(s_t,a_t) + \\gamma \\mathbb{E}_{a_{t+1} \\sim \\pi} [Q^{\\pi}(s_{t+1},a_{t+1})] \\Big]\n\\end{equation}\n\nIf the target policy is deterministic, $\\mu: S \\mapsto A$, then:\n\\begin{equation}\nQ^{\\mu} (s_t,a_t) = \\mathbb{E}_{r_{t},s_{t+1} \\sim E} \\Big[ r(s_t,a_t) + \\gamma Q^{\\mu}(s_{t+1},\\mu(s_{t+1})) \\Big]\n\\end{equation}\n\nThus:\n\\begin{itemize}\n\\item the expectation depends only on the environment $E$,\n\\item possible to learn $Q^{\\mu}$ off-policy, using transitions which\nare generated from a different stochastic behavior policy $\\beta$.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Background: Fn approximator}\nConsider fn approximators parameterized by $\\theta^Q$, \\\\\nwhich we optimize by minimizing the loss:\n\\begin{equation} \\label{equ:qloss}\nL(\\theta^Q) =\\mathbb{E}_{s_t \\sim \\rho^{\\beta}, a \\sim \\beta, r_t \\sim E} \\Big[ \\Big( Q (s_t,a_t|\\theta^Q) - y_t \\Big)^2 \\Big]\n\\end{equation}\nwhere:\\\\\n$y_t = r(s_t,a_t) + \\gamma Q(s_{t+1},\\mu(s_{t+1}) | \\theta^Q)$, and \\\\\n$\\rho^{\\beta}$: the discounted state visitation distribution for a policy $\\beta$.\n\\vspace{5mm}\n\nTypically, ignore the fact that $y_t$ is also dependent on $\\theta^Q$.\\\\\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Background: Actor-critic approach}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.35]{actorcritic_arch}\n\\end{figure}\n\\end{frame}\n\n% \\begin{frame}\n% \\frametitle{Background: Actor-critic \\cite{Sutton1998}}\n% The Actor-Critic Algorithm is essentially a hybrid method to combine the policy gradient method and the value function method together.\n% The policy function is known as the actor, while the value function is referred to as the critic.\n% Essentially, the actor produces the action aa given the current state of the environment ss, while the critic produces a signal to criticizes the actions made by the actor.\n% \\end{frame}\n\n% deep Q-network:\n% \\begin{itemize}\n%   \\item innovation:\n%   \\begin{itemize}\n%     \\item the network is trained off-policy with samples from a replay buffer to minimize correlations between samples;\n%     the use of a replay buffer\n%     \\item the network is trained with a target Q network to give consistent targets during temporal difference backups.\n%     a separate target network for calculating $y_t$\n%   \\end{itemize}\n%   \\item able to:\n%   \\begin{itemize}\n%     \\item solves problems with high-dimensional observation spaces,\n%     \\item can only handle discrete and low-dimensional action spaces.\n%   \\end{itemize}\n% \\end{itemize}\n", "meta": {"hexsha": "de4aceeab48a2ef167d14c359ab6381898b4f6d4", "size": 3654, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/deep-dpg-20180209/background.tex", "max_stars_repo_name": "tttor/robot-foundation", "max_stars_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk/tor/deep-dpg-20180209/background.tex", "max_issues_repo_name": "tttor/robot-foundation", "max_issues_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk/tor/deep-dpg-20180209/background.tex", "max_forks_repo_name": "tttor/robot-foundation", "max_forks_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4631578947, "max_line_length": 174, "alphanum_fraction": 0.7008757526, "num_tokens": 1181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.678832824534586}}
{"text": "\\subsection{Selection Based on Spline regression}\n\\begin{itemize}\n\\item Spline regression \\cite{racine} was also considered as a basis for scatterplot clustering applying the following algorithm:\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 negative 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": "a811b6adf349111a2e2a21a2605835501a612888", "size": 1048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Treballs_nostres/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/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/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/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/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/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": 55.1578947368, "max_line_length": 137, "alphanum_fraction": 0.7690839695, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.678803116064314}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\begin{document}\n\\section{2x2 complex matrix}\nConsider the matrix\n\\[\n  \\left[\n    \\begin{array}{cc}\n      \\alpha & \\beta\\\\\n      \\gamma & \\delta\n    \\end{array}\n  \\right]\n\\]\nThe eigenvalues, $\\lambda$, are solution of the characteristic equation\n\\[\n  \\alpha\\delta(1-\\lambda)^2 - \\beta\\gamma = \\alpha\\delta\\lambda^2\n  -2\\alpha\\delta\\lambda + \\alpha\\delta - \\beta\\gamma = 0\n\\]\nThe solution depends only on the value of the product $\\alpha\\delta$\nand we consider only the case $\\delta=\\alpha$ without loss of\ngenerality.\n\n\\begin{align*}\n  \\lambda &= \\frac{2\\alpha^2 \\pm \\sqrt{4\\alpha^4 -\n            4\\alpha^2(\\alpha^2 - \\beta\\gamma)}}{2\\alpha^2}\\\\\n  &  = \\alpha \\pm \\sqrt{\\beta\\gamma}  \n\\end{align*}\n\nThere is a complex paire of eigenvalues if and only if $\\beta$ and\n$\\gamma$ have opposite sign. The modulus of the eigenvalues is\n\\[\n  |\\lambda| = \\sqrt{\\alpha^2 + |\\beta\\gamma|}\n\\]\nThere is a paire of complex unit roots when $\\alpha^2 + \\beta\\gamma =\n1$ and the roots are smaller than one in modulus when $\\alpha^2 + \\beta\\gamma <\n1$\n\\begin{enumerate}\n\\item Generating a random 2x2 matrix with a paire of complex unit\n  roots:\n  \\begin{itemize}\n  \\item Choose random $\\alpha$ and $\\beta$\n  \\item Set $\\gamma = -\\frac{1 - \\alpha^2}{\\beta}$\n  \\end{itemize}\n\\item Generating a random 2x2 matrxi with a paire of roots smalle than\n  1 in modulus:\n  \\begin{itemize}\n  \\item Choose random $\\alpha$ and $\\beta$\n  \\item If $\\beta < 0$, choose random $\\gamma$ over $]0; -\\frac{1 -\n      \\alpha^2}{\\beta}[$,\n  \\item else choose random $\\gamma$ over $]-\\frac{1 -\n      \\alpha^2}{\\beta}; 0[$\n  \\end{itemize}\n\\end{enumerate}\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "86314f28a8a77aeb45f07c8d9bd02ce5c51cf14f", "size": 1758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/random_matrices.tex", "max_stars_repo_name": "DynareJulia/LinearRationalExpectations.jl", "max_stars_repo_head_hexsha": "86ed49805489aded6c0f5f47c199dcdee1cfa5f4", "max_stars_repo_licenses": ["MIT"], "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/random_matrices.tex", "max_issues_repo_name": "DynareJulia/LinearRationalExpectations.jl", "max_issues_repo_head_hexsha": "86ed49805489aded6c0f5f47c199dcdee1cfa5f4", "max_issues_repo_licenses": ["MIT"], "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/random_matrices.tex", "max_forks_repo_name": "DynareJulia/LinearRationalExpectations.jl", "max_forks_repo_head_hexsha": "86ed49805489aded6c0f5f47c199dcdee1cfa5f4", "max_forks_repo_licenses": ["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.3548387097, "max_line_length": 79, "alphanum_fraction": 0.6558589306, "num_tokens": 579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6787806388108485}}
{"text": "\\subsection{Electroweak theory}\n\\label{ewktheory}\nThe electroweak interaction is the unified description of two of the four known fundamental interactions of nature: electromagnetism and the weak interaction.\nIt is based on the gauge group $SU(2)_{L} \\times SU(1)_{Y}$, in which $L$ is the left-handed fields and $Y$ is the weak hypercharge~\\cite{Langacker:2009my}.\nIt follows the Lagrangian of\n\\begin{equation} \\label{eq:Lew}\n\tL_{EW} = L_{gauge} + L_{Higgs} + L_{fermion} + L_{Yukawa}\n\\end{equation}\n\n$L_{gauge}$ is the \\textbf{gauge term} part:\n\\begin{equation}\n\tL_{gauge} = -\\frac{1}{4} W^{i}_{\\mu\\nu} W^{\\mu\\nu i} - \\frac{1}{4} B_{\\mu\\nu} B^{\\mu\\nu}\n\\end{equation}\nwhere $W^{i}_{\\mu}$ and $B_{\\mu}$ present the $SU(2)_{L}$ and $SU(1)_{Y}$ gauge fields respectively, with the corresponding field strength tensors of\n\\begin{equation}\n\\begin{split}\n\t& B_{\\mu\\nu} = \\partial_{\\mu} B_{\\nu} - \\partial_{\\nu} B_{\\mu} \\\\\n\t& W^{i}_{\\mu\\nu} = \\partial_{\\mu} W^{i}_{\\nu} - \\partial_{\\nu} W^{i}_{\\mu} - g \\epsilon_{ijk} W^{j}_{\\mu} W^{k}_{\\nu}\n\\end{split}\n\\end{equation}\nIn the equations above, $g$ denotes the $SU(2)_{L}$ gauge coupling and $\\epsilon_{ijk}$ denotes the totally antisymmetric tensor.\nThe gauge Lagrangian has three and four -point self interactions of $W^{i}$ that results in triple and quartic gauge boson couplings.\n\nThe second term is the \\textbf{scaler part}:\n\\begin{equation} \\label{eq:Lhiggs}\n\t{L}_{Higgs} = \\left(D^{\\mu}\\phi\\right)^{\\dagger}D_{\\mu}\\phi - V(\\phi)\n\\end{equation}\nwhere $\\phi = \\binom{\\phi^{+}}{\\phi^{0}}$ denotes a complex Higgs scalar,\nand $V(\\phi)$ is the Higgs potential which is restricted into the form of \n\\begin{equation} \\label{eq:Vhiggs}\n\tV(\\phi) = +\\mu^{2}\\phi^{\\dagger}\\phi + \\lambda\\left(\\phi^{\\dagger}\\phi\\right)^{2}\n\\end{equation}\ndue to the combination of $SU(2)_{L} \\times SU(1)_{Y}$ invariance and renormalizability.\nIn Eq.~\\ref{eq:Vhiggs}, $\\mu$ is a mass-dependent parameter and $\\lambda$ is the quartic Higgs scalar coupling, \nwhich represents a quartic self-interaction between the scalar fields.\nWhen $\\mu^{2} < 0$, there will be spontaneous symmetry breaking (more details in section~\\ref{symbreaking}).\nTo maintain vacuum stability, $\\lambda > 0$ is required.\nAnd in Eq.~\\ref{eq:Lhiggs}, the gauge covariant derivative is defined as~\\cite{Langacker:2009my}s\n\\begin{equation}\n\tD_{\\mu}\\phi = \\left(\\partial_{\\mu} +ig\\frac{\\tau^{i}}{2}W_{\\mu}^{i} + \\frac{ig'}{2}B_{\\mu}\\right)\\phi\n\\end{equation}\nin which $\\tau^{i}$ represents the Pauli matrices, and $g'$ is the $U(1)_{Y}$ gauge coupling.\nThe square of the covariant derivative results in three and four -point interactions between the gauge and scalar fields.\n\nThe third term of the Lagrangian is the \\textbf{fermion part}\n\\begin{equation} \\label{eq:Lfermion}\n\\begin{split}\n  \t{L}_{fermion} = \\sum_{m=1}^{F} & ( \\bar{q}_{mL^{i}}^{0}\\gamma_{\\mu}D_{\\mu}q_{mL}^{0} + \\bar{l}_{mL^{i}}^{0}\\gamma_{\\mu}D_{\\mu}l_{mL}^{0} + \\bar{u}_{mR^{i}}^{0}\\gamma_{\\mu}D_{\\mu}u_{mR}^{0} \\\\\n  \t& + \\bar{d}_{mR^{i}}^{0}\\gamma_{\\mu}D_{\\mu}d_{mR}^{0} + \\bar{e}_{mR^{i}}^{0}\\gamma_{\\mu}D_{\\mu}e_{mR}^{0} + \\bar{\\nu}_{mR^{i}}^{0}\\gamma_{\\mu}D_{\\mu}\\nu_{mR}^{0})\n\\end{split}\n\\end{equation} \nIn Eq.~\\ref{eq:Lfermion}, m is the family index of fermions, F is the number of families.\nThe subscripts $L (R)$ stand for the left (right) chiral projection $\\psi_{L(R)} \\equiv \\left(1 \\mp \\gamma_{5} \\right) \\psi/2$.\n\\begin{equation}\n\tq_{mL}^{0} = \\binom{u_{m}^{0}}{d_{m}^{0}}_{L}   \\qquad    l_{mL}^{0} = \\binom{\\nu_{m}^{0}}{e_{m}^{-0}}_{L}\n\\end{equation}\nare the $SU(2)$ doublets of left-hand quarks and leptons, while \n$u_{mR}^{0}$, $d_{mR}^{0}$, $e_{mR}^{-0}$ and $\\nu_{mR}^{0}$ are the right-hand singlets.\n\nThe last term in Eq.~\\ref{eq:Lew} is \\textbf{Yukawa term}\n\\begin{equation}\n\\begin{split}\n\t{L}_{Yukawa} =& -\\sum_{m,n=1}^{F} [\\Gamma_{mn}^{u}\\bar{q}_{mL}^{0}\\widetilde{\\phi}u_{nR}^{0} + \\Gamma_{mn}^{d}\\bar{q}_{mL}^{0}\\phi d_{nR}^{0} \\\\\n\t& + \\Gamma_{mn}^{e}\\bar{l}_{mn}^{0}\\phi e_{nR}^{0} + \\Gamma_{mn}^{\\nu}\\bar{l}_{mL}^{0}\\widetilde{\\phi}\\nu_{nR}^{0}]+h.c.\n\\end{split}\n\\end{equation}\nthe matrices $\\Gamma_{mn}$ refer to the Yukawa couplings between single Higgs doublet ($\\phi$) and the various flavors of quarks (m) and leptons (n).\n\n", "meta": {"hexsha": "be06c17e2543e5e002ea72d75e4b71002357e87e", "size": 4216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Theory/ewktheory.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/ewktheory.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/ewktheory.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": 61.1014492754, "max_line_length": 194, "alphanum_fraction": 0.6634250474, "num_tokens": 1631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6787676309642409}}
{"text": "\\section{Utility Functions}\nWith the control panel defined and explained, let us move over to some utility functions. Functions that can be used in all kinds of calculations, which we might need more often. In general it \nconcerns functions like calculating the gradient, the lacplacian or interpolation. \n\n\\subsection{Gradients}\nLet us define the gradient in the $x, y$ and $z$ directions. The functions can be found in \\autoref{alg:gradient x}, \\autoref{alg:gradient y} and \\autoref{alg:gradient z}. We use these functions \nin various other algorithms as the gradient (also known as derivative) is often used in physics. It denotes the rate of change, how much something changes over time. Velocity for instance denotes\nhow far you move in a given time. Which is a rate of change, how much your distance to a given point changes over time. \n\nIn \\autoref{alg:gradient z} $a.dimensions$ is the attribute that tells us how deeply nested the array $a$ is. If the result is $1$ we have just a normal array, if it is $2$ we have a double array \n(an array at each index of the array) which is also called a matrix and if it is $3$ we have a triple array. We need this because we have a one-dimensional case, for when we do not use multiple \nlayers and a three-dimensional case for when we do use multiple layers. This distinction is needed to avoid errors being thrown when running the model with one or multiple layers. \n\nThis same concept can be seen in \\autoref{alg:gradient x} and \\autoref{alg:gradient y}, though here we check if $k$ is defined or \\texttt{NULL}. We do this as sometimes we want to use this \nfunction for matrices that does not have the third dimension. Hence we define a default value for $k$ which is \\texttt{NULL}. \\texttt{NULL} is a special value in computer science. It represents \nnothing. This can be useful sometimes if you declare a variable to be something but it is referring to something that has been deleted or it is returned when some function fails. It usually \nindicates that something special is going on. So here we use it in the special case where we do not want to consider the third dimension in the gradient. We also use forward differencing \n(calculating the gradient by taking the difference of the cell and the next/previous cell, multiplied by $2$ to keep it fair) in \\autoref{alg:gradient y} as that gives better results for the \ncalculations we will do later on.\n\n\\begin{algorithm}[hbt]\n    \\caption{Calculating the gradient in the $x$ direction}\n    \\label{alg:gradient x}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Matrix (double array) $a$, first index $i$, second index $j$, third index $k$ with default value \\texttt{NULL}}\n    \\Output{Gradient in the $x$ direction}\n    \\eIf{$k = \\texttt{NULL}$}{\n        $grad \\leftarrow \\frac{a[i, (j + 1)\\text{ mod } nlon] - a[i, (j - 1) \\text{ mod } nlon]}{\\delta x[i]}$ \\;\n    }{\n        $grad \\leftarrow \\frac{a[i, (j + 1)\\text{ mod } nlon, k] - a[i, (j - 1) \\text{ mod } nlon, k]}{\\delta x[i]}$ \\;\n    }\n    \\Return{$grad$} \\; \n\\end{algorithm}\n\n\\begin{algorithm}[hbt]\n    \\caption{Calculating the gradient in the $y$ direction}\n    \\label{alg:gradient y}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Matrix (double array) $a$, first index $i$, second index $j$, third index $k$ with default value \\texttt{NULL}}\n    \\Output{Gradient in the $y$ direction}\n    \\eIf{$k = \\texttt{NULL}$}{\n        \\uIf{$i == 0$}{\n            $grad \\leftarrow 2 \\frac{a[i + 1, j] - a[i, j]}{\\delta y}$ \\;\n        }\\uElseIf{$i = nlat - 1$}{\n            $grad \\leftarrow 2 \\frac{a[i, j] - a[i - 1, j]}{\\delta y}$ \\;\n        }\\uElse{\n            $grad \\leftarrow \\frac{a[i + 1, j] - a[i - 1 j]}{\\delta y}$ \\;\n        }\n    }{\n        \\uIf{$i = 0$}{\n            $grad \\leftarrow 2 \\frac{a[i + 1, j, k] - a[i, j, k]}{\\delta y}$ \\;\n        }\\uElseIf{$i = nlat - 1$}{\n            $grad \\leftarrow 2 \\frac{a[i, j, k] - a[i - 1, j, k]}{\\delta y}$ \\;\n        }\\uElse{\n            $grad \\leftarrow \\frac{a[i + 1, j] - a[i - 1 j]}{\\delta y}$ \\;\n        }\n    }\n    \\Return $grad$ \\;\n\\end{algorithm}\n\n\\begin{algorithm}[hbt]\n    \\caption{Calculating the gradient in the $z$ direction}\n    \\label{alg:gradient z}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Array $a$, array $p_z$, index $k$}\n    \\Output{Gradient in the $z$ direction}\n    $nlevels \\leftarrow p_z.length$ \\;\n    \\uIf{$k = 0$}{\n        $grad \\leftarrow \\frac{a[k + 1] - a[k]}{p_z[k + 1] - p_z[k]}$ \\;\n    }\\uElseIf{$k = nlevels - 1$}{\n        $grad \\leftarrow \\frac{a[k] - a[k - 1]}{p_z[k] - p_z[k - 1]}$ \\;\n    }\\uElse{\n        $grad \\leftarrow \\frac{a[k + 1] - a[k - 1]}{p_z[k + 1] - p_z[k - 1]}$ \\;\n    }\n    \n    \\Return $-grad$ \\;  \n\\end{algorithm}\n\n\\subsection{Laplacian Operator} \\label{sec:laplace}\nThe Laplacian operator ($\\nabla^2$, sometimes also seen as $\\Delta$) has two definitions, one for a vector field and one for a scalar field. The two concepts are not indpendent, a vector field \nis composed of scalar fields \\cite{vectorscalarfields}. Let us define a vector field first. A vector field is a function whose domain and range are a subset of the Eucledian $\\mathbb{R}^3$ space. \nA scalar field is then a function consisting out of several real variables (meaning that the variables can only take real numbers as valid values). So for instance the circle equation \n$x^2 + y^2 = r^2$ is a scalar field as $x, y$ and $r$ are only allowed to take real numbers as their values. \n\nWith the vector and scalar fields defined, let us take a look at the Laplacian operator. For a scalar field $\\phi$ the laplacian operator is defined as the divergence of the gradient of $\\phi$\n\\cite{laplacian}. But what are the divergence and gradient? The gradient is defined in \\autoref{eq:gradient} and the divergence is defined in \\autoref{eq:divergence}. Here $\\phi$ is a vector \nwith components $x, y, z$ and $\\Phi$ is a vector field with components $x, y, z$. $\\Phi_1, \\Phi_2$ and $\\Phi_3$ refer to the functions that result in the corresponding $x, y$ and $z$ values \n\\cite{vectorscalarfields}. Also, $i, j$ and $k$ are the basis vectors of $\\mathbb{R^3}$, and the multiplication of each term with their basis vector results in $\\Phi_1, \\Phi_2$ and $\\Phi_3$\nrespectively. If we then combine the two we get the Laplacian operator, as in \\autoref{eq:laplacian scalar}.\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:gradient}\n        \\text{grad } \\phi = \\nabla \\phi = \\frac{\\delta \\phi}{\\delta x}i + \\frac{\\delta \\phi}{\\delta y}j + \\frac{\\delta \\phi}{\\delta z}k      \n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:divergence}\n        \\text{div} \\Phi = \\nabla \\cdot \\Phi = \\frac{\\delta \\Phi_1}{\\delta x} + \\frac{\\delta \\Phi_2}{\\delta y} + \\frac{\\delta \\Phi_3}{\\delta z} \n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:laplacian scalar}\n        \\nabla^2 \\phi = \\nabla \\cdot \\nabla \\phi = \\frac{\\delta^2 \\phi}{\\delta x^2} + \\frac{\\delta^2 \\phi}{\\delta y^2} + \\frac{\\delta^2 \\phi}{\\delta z^2}\n    \\end{equation}\n\\end{subequations}\n\nFor a vector field $\\Phi$ the Laplacian operator is defined as in \\autoref{eq:laplacian vector}. Which essential boils down to taking the Laplacian operator of each function and multiply it by\nthe basis vector.\n\n\\begin{equation}\n    \\label{eq:laplacian vector}\n    \\nabla^2 \\Phi = (\\nabla^2 \\Phi_1)i + (\\nabla^2 \\Phi_2)j + (\\nabla^2 \\Phi_3)k\n\\end{equation}\n\nThe code can be found in \\autoref{alg:laplacian}. $\\Delta_x$ and $\\Delta_y$ in \\autoref{alg:laplacian} represents the calls to \\autoref{alg:gradient x} and \\autoref{alg:gradient y} \nrespectively.\n\n\\begin{algorithm}[hbt]\n    \\caption{Calculate the laplacian operator over a matrix a}\n    \\label{alg:laplacian}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{A matrix (double array) a}\n    \\Output{A matrix (double array) with results for the laplacian operator for each element}\n    \\eIf{$a.dimensions = 2$}{\n        \\For{$lat \\leftarrow 1$ \\KwTo $nlat - 1$}{\n            \\For{$lon \\leftarrow 0$ \\KwTo $nlon$}{\n                $output[lat, lon] \\leftarrow \\frac{\\Delta_x(a, lat, (lon + 1) \\text{ mod } nlon) - \\Delta_x(a, lat, (lon - 1) \\text{ mod } nlon)}{\\delta x[lat]} + \\frac{\\Delta_y(a, lat + 1, lon) - \n                \\Delta_y(a, lat - 1, lon)}{\\delta y}$\\;\n            }\n        }\n    }{\n        \\For{$lat \\leftarrow 1$ \\KwTo $nlat - 1$}{\n            \\For{$lon \\leftarrow 0$ \\KwTo $nlon$}{\n                \\For{$k \\leftarrow 0$ \\KwTo $nlevels - 1$}{\n                    $output[lat, lon, k] \\leftarrow \\frac{\\Delta_x(a, lat, (lon + 1) \\text{ mod } nlon, k) - \\Delta_x(a, lat, (lon - 1) \\text{ mod } nlon, k)}{\\delta x[lat]} + \\frac{\\Delta_y(a, \n                    lat + 1, lon, k) - \\Delta_y(a, lat - 1, lon, k)}{\\delta y} + \\frac{\\Delta_z(a, lat, lon, k + 1) - \\Delta_z(a, lat, lon, k + 1)}{2\\delta z[k]}$\\;\n                }\n            }\n        }\n    }\n    \n    \\Return{$ouput$} \\;  \n\\end{algorithm}\n\n\\subsection{Divergence}\nAs we expect to use the divergence operator more often throughout our model, let us define a seperate function for it in \\autoref{alg:divergence}. $\\Delta_x$ and $\\Delta_y$ in \n\\autoref{alg:divergence} represents the calls to \\autoref{alg:gradient x} and \\autoref{alg:gradient y} respectively. We do the multiplication with the velocity vectors $u, v$ and $w$ here already, \nas we expect that we might use it in combination with the divergence operator more frequently. What those vectors are and represent we will discuss in \\autoref{sec:momentum}.\n\n\\begin{algorithm}[!hbt]\n    \\caption{Calculate the result of the divergence operator on a vector}\n    \\label{alg:divergence}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{A matrix (triple array) $a$, pressure field $p_z$}\n    \\Output{A matrix (triple array) containing the result of the divergence operator taken over that element}\n    \\For{$i \\leftarrow 0$ \\KwTo $a.length$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $a[i].length$}{\n            \\For{$k \\leftarrow 0$ \\KwTo $a[i, j].length$}{\n                $output[i, j, k] \\leftarrow \\Delta_x(au, i, j, k) + \\Delta_y(av, i, j, k) + \\Delta_z(aw[i, j, :], p_z, k)$ \\;\n            }\n        }\n    }\n    \\Return{$output$} \\;  \n\\end{algorithm}\n\n\\subsection{Interpolation} \\label{sec:interpolation}\nInterpolation is a form of estimation, where one has a set of data points and desires to know the values of other data points that are not in the original set of data points\\cite{interpolation}. \nBased on the original data points, it is estimated what the values of the new data points will be. There are various forms of interpolation like linear interpolation, polynomial interpolation \nand spline interpolation. The CLAuDE model uses linear interpolation which is specified in \\autoref{eq:interpolation}. Here $z$ is the point inbetween the known data points $x$ and $y$. \n$\\lambda$ is the factor that tells us how close $z$ is to $y$ in the interval $[0, 1]$. If $z$ is very close to $y$, $\\lambda$ will have the value on the larger end of the interval, like 0.9.\nWhereas if $z$ is close to $x$ then $\\lambda$ will have a value on the lower end of the interval, like 0.1.\n\n\\begin{equation}\n    \\label{eq:interpolation}\n    z = (1 - \\lambda)x + \\lambda y\n\\end{equation}\n\n\\subsection{3D smoothing} \\label{sec:3dsmooth}\nAs you can imagine the temperature, pressure and the like vary quite a lot over the whole planet. Which is something that we kind of want but not really. What we really want is to limit how \nmuch variety we allow to exist. For this we are going to use Fast Fourier Transforms, also known as FFTs. A Fourier Transform decomposes a wave into its frequences. The fast bit comes from the \nalgorithm we use to calculate it. This is because doing it via the obvious way is very slow, in the order of $O(n^2)$ (for what that means, please visit \\autoref{sec:runtime}). Whereas if we use \nthe FFT, we reduce the running time to $O(n\\log(n))$. There are various ways to calculate the FFT, but we use the Cooley–Tukey algorithm \\cite{fft}. To explain it, let us first dive into a normal \nFourier Transform.\n\nThe best way to explain what a Fourier Transform does is to apply it to a sound. Sound is vibrations travelling through the air that reach your air and make the inner part of your air vibrate.\nIf you plot the air pressure reaching your air versus the time, the result will have the form of a sinoidal wave. However, it is only a straight forward sinoidal wave (as if you plotted the \n$\\cos$ function) if the tone is pure. That is often not the case, and sounds are combinations of tones. This gives waves that are sinoidal but not very alike to the $\\cos$ function. The FT will\ntransform this \"unpure\" wave and splits them up into a set of waves that are all of pure tone. To do that we need complex numbers which are explained here \\autoref{sec:complex}. \n\nWith that explanation out of the way, we now know that with Euler's formula (\\autoref{eq:euler}) we can rotate on the complex plane. If we rotate one full circle per second, the formula changes \nto \\autoref{eq:euler rotate}, as the circumference of the unit circle is $2\\pi$ and $t$ is in seconds. This rotates in the clock-wise direction, but we want to rotate in the clockwise direction, \nso we need to add a $-$ to the exponent. If we also want to control how fast the rotation happens (which is called the frequency) then we change the equation to \\autoref{eq:euler freq}. Note that\nthe frequency unit is $Hz$ which is defined as $s^{-1}$, which means that a frequency of $10 Hz$ means 10 revolutions per second. Now we get our wave which we call $g(t)$ and plonk it in front \nof the equation up until now. Which results in \\autoref{eq:euler wave}. Visually, this means that we take the sound wave and wrap it around the origin. This might sound strange at first but bear \nwith me. If you track the center of mass (the average of all the points that form the graph) you will notice that it hovers around the origin. If you now change the frequency of the rotation ($f$)\nyou will see that the center of mass moves a bit, usually around the origin. However, if the frequency of the rotation matches a frequency of the wave, then the center of mass is suddenly a \nrelatively long distance away from the origin. This indicates that we have found a frequency that composes the sound wave. Now how do we track the center of mass? That is done using integration,\nas in \\autoref{eq:euler int}. Now to get to the final form, we forget about the fraction part. This means that the center of mass will still hover around the origin for the main part of the \nrotation, but has a huge value for when the rotation is at the same frequency as one of the waves in the sound wave. The larger the difference between $t_2$ and $t_1$, the larger the value of the\nFourier Transform. The final equation is given in \\autoref{eq:ft}.\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:euler}\n        e^{ix} = \\cos(x) + i\\sin(x)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:euler rotate}\n        e^{2\\pi it}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:euler freq}\n        e^{-2\\pi ift}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:euler wave}\n        g(t)e^{-2\\pi ift}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:euler int}\n        \\frac{1}{t_2 - t_1}\\int^{t_2}_{t_1}g(t)e^{-2\\pi ift}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:ft}\n        \\hat{g}(f) = \\int^{t_2}_{t_1}g(t)e^{-2\\pi ift}\n    \\end{equation}\n\\end{subequations}\n\nThese Fourier Transforms have the great property that if you add them together you still have the relatively large distances of the center of mass to the origin at the original frequencies. It \nis this property that enables us to find the frequencies that compose a sound wave. \n\nBefore moving on we first need to discuss some important properties of FTs. Actually, these properties only apply to complex roots of unity (the $e^{2\\pi ift}$ part is a complex root of unity). \nDue to the FT only being a coefficient $g(t)$ in front of a complex root of unity all these properties apply to FTs as well. Let us first start with the cancellation lemma as described in\n\\autoref{lemma:cancellation} \\cite{cancellation}. Note that $\\omega^k_n = e^{\\frac{2\\pi k}{n}}$ which is very similar to the form we discussed previously if you realise that $f = \\frac{1}{T}$. \nSo replace $k$ by $t$ and $n$ by $T = \\frac{1}{f}$ and you get the form we have discussed earlier.\n\n\\begin{lemma}[Cancellation Lemma] \\label{lemma:cancellation}\n    $\\omega^{dk}_{dn} = \\omega^k_n$, for all $k \\geq 0, n \\geq 0$ and $d > 0$.\n\\end{lemma}\n\nWith that we also need to talk about the halving lemma (\\autoref{lemma:halving}). This means that $(\\omega^{k + \\frac{n}{2}}_n)^2 = (\\omega^k_n)^2$. \n\n\\begin{lemma}[Halving Lemma] \\label{lemma:halving}\n    If $n > 0$ is even, then the squares of the $n$-complex $n^{\\text{th}}$ roots of unity are the $\\frac{n}{2}$-complex $\\frac{n}{2}^{\\text{th}}$ roots of unity.\n\\end{lemma}\n\nNow that we know what a Fourier Transform is, we need to make it a Fast Fourier Transform, as you can imagine that calculating such a thing is quite difficult. Some smart people have thought\nabout this and they came up with quite a fast algorithm, the Cooley-Tukey algorithm \\cite{fft}, named after the people that thought of it. They use something we know as a Discrete Fourier \nTransform which is described by \\autoref{eq:dft}. Here $N$ is the total amount of samples from the continuous sound wave. This means that $0 \\leq k \\leq N - 1$ and $0 \\leq n \\leq N - 1$.\n\nNow with the DFT out of the way we can discuss the algorithm. Before we do, we assume that we have an input of $n$ elements, where $n$ is an exact power of $2$. Meaning $n = 2^k$ for some \ninteger $k$.\n\n\\begin{algorithm}\n    \\caption{One dimensional Fast Fourier Transformation}\n    \\label{alg:FFT}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{array $A$}\n    \\Output{array $B$ with length $A.length - 1$ containing the DFT}\n    $n \\leftarrow A.length$ \\;\n    \\uIf{$n = 1$}{\n        \\Return{$A$} \\;\n    }\n    $\\omega_n \\leftarrow e^{\\frac{2\\pi i}{n}}$ \\;\n    $\\omega \\leftarrow 1$ \\;\n    $a^0 \\leftarrow (A[0], A[2], \\dots, A[n - 2])$ \\;\n    $a^1 \\leftarrow (A[1], A[3], \\dots, A[n - 1])$ \\;\n    $y^0 \\leftarrow $ \\texttt{FFT}($a^0$) \\;\n    $y^1 \\leftarrow $ \\texttt{FFT}($a^1$) \\;\n    \\For{$k \\leftarrow 0$ \\KwTo $\\frac{n}{2} - 1$}{\n        $B[k] \\leftarrow y^0[k] + \\omega y^1[k]$ \\;\n        $B[k + \\frac{n}{2}] \\leftarrow y^0[k] - \\omega y^1[k]$ \\;\n        $\\omega \\leftarrow \\omega \\omega_n$ \\;\n    }\n    \\Return{B} \n\\end{algorithm}\n\nThere is just this one problem we have, the algorithm in \\autoref{alg:FFT} can only handle one dimension, and we need to support multidimensional arrays. So let us define a multidimensional FFT \nfirst in \\autoref{eq:NFFT}. Here $N$ and $M$ are the amount of indices for the dimensions, where $M$ are the amount of indices for the first dimension and $N$ are the amount of indices for the \nsecond dimension. This can of course be extended in the same way for a $p$-dimensional array.\n\n\\begin{equation}\n    \\label{eq:NFFT}\n    X_{k,l} = \\sum_{m = 0}^{M - 1}\\sum_{n = 0}^{N - 1} x_{m, n}e^{-2i\\pi(\\frac{mk}{M} + \\frac{nl}{N})}\n\\end{equation}\n\nIt is at this point that the algorithm becomes very complicated. Therefore I would like to invite you to use a library for these kinds of calculations, like Numpy \\cite{numpy} for Python. If you\nreally want to use your own made version, or if you want to understand how the libraries sort of do it, then you may continue. I still advise you to use a library, as other people have made the \ncode for you. \n\nWe can calculate the result of such a multidimensional FFT by computing one-dimensional FFTs along each dimension in turn. Meaning we first calculate the result of the FFT along one dimension, \nthen we do that for the second dimension and so forth. Now the order of calculating the FFTs along each dimension does not matter. So you can calculate the third dimension first, and the first \ndimension after that if you wish. This has the advantage that we can program a generic function without keeping track of the order of the dimensions. Now, the code is quite complicated but it \nboils down to this: calculate the FFT along one dimension, then repeat it for the second dimension and multiply the two together and keep repeating that for all dimensions.\n\nWith that out of the way, we need to create a smoothing operation out of it. We do this in \\autoref{alg:smooth}. Keep in mind that \\texttt{FFT} the call is to the \nmultidimensional Fast Fourier Transform algorithm, \\texttt{IFFT} the call to the inverse of the multidimensional Fast Fourier Transform algorithm (also on the TODO list) and that the $int()$ \nfunction ensures that the number in brackets is an integer. Also note that the inverse of the FFT might give complex answers, and we only want real answers which the $.real$ ensures. We only \ntake the real part and return that. $v$ is an optional parameter with default value $0.5$ which does absolutely nothing in this algorithm.\n\n\\begin{algorithm}\n    \\caption{Smoothing function}\n    \\label{alg:smooth}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Array $a$, smoothing factor $s$, vertical smoothing factor $v \\leftarrow 0.5$}\n    \\Output{Array $A$ with less variation}\n    $nlat \\leftarrow a.length$ \\;\n    $nlon \\leftarrow a[0].length$ \\;\n    $nlevels \\leftarrow a[0][0].length$ \\;\n    $temp \\leftarrow \\texttt{FFT}(a)$ \\;\n    $temp[int(nlat s):int(nlat(1 - s)),:,:] \\leftarrow 0$ \\;\n    $temp[:,int(nlon s):int(nlon(1 - s)),:] \\leftarrow 0$ \\;\n    $temp[:,:,int(nlevels v):int(nlevels(1 - v))] \\leftarrow 0$ \\;\n    \\Return $\\texttt{IFFT}(temp).real$ \\;\n\\end{algorithm}", "meta": {"hexsha": "b9c3c70a427339f11efdd99e55e466052818896e", "size": 21852, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/topics/util_funcs.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/util_funcs.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/util_funcs.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": 68.0747663551, "max_line_length": 197, "alphanum_fraction": 0.686756361, "num_tokens": 6439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6787601977564091}}
{"text": "\\subsection{Continuum Procedure}\\label{sec:continuum}\nThe starting point is a contact interaction\\footnote{This derivation generalizes to a tower of contact interactions where $C(\\Lambda)$ is replaced by $\\sum_n C_{2n}(\\Lambda) p^{2n}$ \\cite{Kaplan:1998we,Beane:2003da} and dimensional regularization is used to absorb power-law divergencies.} such that the tree amplitude in the center of mass frame is given by\n\\begin{equation}\n    \\mathcal A(\\Lambda) = + i C(\\Lambda)\n\\end{equation}\nwhere $p$ denotes the relative momentum of incoming nucleons and the interaction strengths $ C(\\Lambda)$ depend on the regulator $\\Lambda$ and carry dimension-dependent units.\nThe scattering amplitude is given by the bubble sum depicted in \\Figref{bubbleSum}.\n\n\\begin{figure}[ht!]\n\\center\n\\includegraphics[width=.675\\columnwidth]{figure/bubbleSum.pdf}\n\\hfill\n\\includegraphics[width=.275\\columnwidth]{figure/I0.pdf}\n\\caption{(Left) The bubble sum. Each line represents a propagator, each vertex represents $-i C(\\Lambda)$, and the bubble is given by $I_D$.\n(Right) The single loop diagram needed to calculate $I_D$ in the bubble sum.\n\\label{fig:bubbleSum}}\n\\end{figure}\n\nThis bubble sum is a geometric series and, restricting our attention to the contact interaction causes all other partial wave than the S-wave to vanish.\nThis restriction gives for the standard on-shell $T$-matrix\n\\begin{equation}\\label{eq:T matrix}\nT_{D\\l}(p, \\Lambda) = \\delta_{\\l 0} \\frac{C(\\Lambda)}{1-I_D(p,\\Lambda) C(\\Lambda)},\n\\end{equation}\nwhere $p$ is the relative on-shell momentum, $\\Lambda$ the regularization scale.\nThe physical result for the T-matrix is recovered once the parameter $C$ is chosen such that one can remove the regularization scale---in the limit of $\\Lambda \\to \\infty$ for a hard momentum cutoff, for example.\n\n$I_D(p,\\Lambda)$ is a $D$-dependent function that arises from integrating the loop shown in the right panel of \\Figref{bubbleSum},\n\\begin{align}\n    I_D(p, \\Lambda)\n    &=-i\\int^{\\Lambda}\n        \\frac { \\mathrm {d}q_0}{2\\pi}\\ \\frac{\\mathrm { d } ^ { D } \\vec{ q } } { (2\\pi)^ { D } }\n        \\left( \\frac { i } { \\frac{E}{2} + q _ { 0 } - \\frac{\\vec{q}^2}{2m_1} + i \\epsilon } \\right)\n        \\left( \\frac { i } { \\frac{E}{2} - q _ { 0 } - \\frac{\\vec{q}^2}{2m_2} + i \\epsilon } \\right)\n    \\label{eq:I0 in two particle language}\\\\\n    &=\\frac{\\Omega_D}{(2\\pi)^D}\\int^{\\Lambda}  \\mathrm { d } q \\ q^{D-1}\\left[\\PV \\left( \\frac { 1 } { E - \\frac{\\vec{q}^2}{2\\mu} } \\right)\n-i\\frac{\\pi \\mu}{q}\\delta(q-\\sqrt{2 \\mu E})\\right]\n    \\label{eq:I0 in relative coordinates}\n    \\\\\n    &=\\frac{\\Omega_D}{(2\\pi)^2}\\frac{2\\mu}{L^{D-2}}\\int^{\\Lambda L/2\\pi}  \\mathrm { d } n \\ n^{D-1}\\left[\\PV \\left( \\frac { 1 } { \\left(\\frac{pL}{2\\pi}\\right)^2 - n^2 } \\right)\n-i\\frac{\\pi^2}{L n}\\delta\\left(\\frac{2\\pi}{L}n -p\\right)\\right]\n    \\label{eq:I0}\n\\end{align}\nwhere $\\PV$ refers to Principal (Cauchy) Value, we have used the on-shell condition $2\\mu E=p^2$, and the geometric factor\n\\begin{equation}\n\\Omega_D=\\frac{2\\pi^{D/2}}{\\Gamma(D/2)}=\n    \\begin{cases}\n    \t2       &   (D=1)\\\\\n\t\t2\\pi    &   (D=2)\\\\\n        4\\pi    &   (D=3)\n    \\end{cases}\\ ,\n\\end{equation}\naccounts for the angular integration in $D$ dimensions.\n\nBecause we are focusing on the contact interaction, we can restrict our attention to the $s$-wave, $\\l=0$.\nDropping the $\\l$ dependence in \\eqref{on-shell-T}, the momentum-dependent $T$-matrix is related to the phase shift when\n\\begin{equation}\\label{eq:spherical FD}\n    \\F_{D}(p)\n    \\equiv\n    \\begin{cases}\n        p/2     & (D=1)\\\\\n        1       & (D=2)\\\\\n        \\pi/p   & (D=3)\\\\\n        \\vdots  & \\vdots\n\\end{cases}\n\\end{equation}\nis a dimension-dependent kinematic factor determined by requiring the imaginary parts of the $T$-matrix \\eqref{T matrix} from the bubble sum \\eqref{I0 in relative coordinates} exactly matches the imaginary part of the amplitude \\eqref{on-shell-T}.\nThis fixes the coefficients $C(\\Lambda)$ as a function of the scattering data,\n\\begin{equation}\\label{eq:IV pole}\n    \\frac{\\mu}{2 \\F_{D}(p)}\\left(\\cot \\delta_{D}(p) - i\\right)\n    =\n    \\lim\\limits_{\\Lambda \\to \\infty} \\left[ I_D(p, \\Lambda) - \\frac{1}{C(\\Lambda)} \\right].\n\\end{equation}\n\nIn a finite volume, the energy eigenstates $E$ appear at poles of the $T$-matrix, so that\n\\begin{equation}\\label{eq:FV pole}\n    \\frac{1}{2\\mu E C_\\FV(\\Lambda) } - I_{D, \\FV}(\\sqrt{2\\mu E}, \\Lambda) = 0\n\\end{equation}\nand the infinite-volume integral $I_D$ has been replaced by the matching finite-volume sum which introduces another scale $L$,\n\\begin{align}\nI_{D,\\FV}(\\sqrt{2\\mu E}, \\Lambda)\n    &=-i\\int \\frac { \\mathrm {d}q_0}{2\\pi} \\frac{1}{L^D}\\sum_{\\vec{q}}^{q < \\Lambda} \\left( \\frac { i } { \\frac{E}{2} + q _ { 0 } - \\frac{\\vec{q}^2}{2m_1} + i \\epsilon } \\right) \\left( \\frac { i } { \\frac{E}{2} - q _ { 0 } - \\frac{\\vec{q}^2}{2m_2} + i \\epsilon } \\right)\n    \\\\\n    \\label{eq:I0 FV}\n    &=\\frac{1}{L^D}\\sum_{\\vec{q}}^{q < \\Lambda} \\frac { 1 } { E - \\frac{\\vec{q}^2}{2\\mu} }\n    =\\frac{2\\mu}{(2\\pi)^2 L^{D-2}} \\sum_{\\vec{n}}^{n < \\frac{\\Lambda L}{2\\pi}} \\frac{1}{x-n^2}\n    &\n    x &= \\frac{2\\mu E L^2}{4\\pi^2}\n    \\, .\n\\end{align}\nCombining the infinite-volume and finite-volume relations \\eqref{IV pole} and \\eqref{FV pole} yields\n\\begin{equation}\\label{eq:spherical zeta}\n    \\frac{\\mu}{2\\F_{D}(\\sqrt{2\\mu E})}(\\cot\\delta_{D}(\\sqrt{2\\mu E})-i)\n    =\n    \\lim\\limits_{\\Lambda \\to \\infty} \\left[ I_D(\\sqrt{2\\mu E}) - I_{D,\\FV}(\\sqrt{2\\mu E}) \\right] \\, ,\n\\end{equation}\nthe finite-volume quantization condition.\nNote that both equations are explicitly evaluated for the same interactions $C_\\FV(\\Lambda) = C(\\Lambda)$ independent of the volume $L$ and using the same regulator.\nFurthermore \\eqref{spherical zeta} is only valid if evaluated at momenta corresponding to finite-volume eigenenergies $E$.\n\nPlugging our results for the integrals in, one finds\n\\begin{multline}\n    \\frac{1}{2\\F_{D}(\\sqrt{2\\mu E})}\\left(\\cot \\delta_{D}(\\sqrt{2\\mu E}) - i\\right)\n    =\\\\\n    \\frac{2}{(2\\pi)^2 L^{D-2}}\n    \\lim\\limits_{\\Lambda \\to \\infty}\n    \\left[\n    \t\\left(\\mathcal{P}\\int_{\\vec{n}} - \\sum_{\\vec{n}}\\right) \\frac{1}{x-n^2} +\n\t\t\\frac{-i \\pi^2\\Omega_D}{L} \\int \\mathrm{d}n\\ n^{D-2} \\delta\\left(\\frac{2\\pi}{L}n - \\sqrt{2\\mu E}\\right)\n\t\\right]\n\\end{multline}\nwhere both the sum and integral are cut off by a restriction on the magnitude of $n$, $n^2 < (\\Lambda L / 2\\pi)^2$,\nThe principle value integration implicitly carries a factor of $\\Omega_D n^{D-1}$ (see \\eqref{I0}).\nThe imaginary part on the left hand side exactly cancels the last term on the right when $E\\ge0$.  When $E<0$ the last term on the RHS vanishes and so we have\n%--demanding this cancellation is how the kinematic factor $\\F_D$ of the $T$ matrix is determined----and we are left with\n\\begin{multline}\\label{eq:general luscher}\n   \\frac{1}{2\\F_{D}(\\sqrt{2\\mu E})}  \\left( \\cot \\delta_{D}(p)-i\\theta(-E)\\right)\n    =\n   \\frac{2}{(2\\pi)^2 L^{D-2}}\n    \\lim\\limits_{\\Lambda \\to \\infty}\\left(\\sum_{\\vec{n}}-\\mathcal{P}\\int_{\\vec{n}}\\right) \\frac{1}{n^2-x}\\\\\n    \\implies\n      \\cot \\delta_{D}(p)= \\frac{\\F_{D}(\\sqrt{2\\mu E})}{\\pi^2 L^{D-2}}\\left[\n    \\lim\\limits_{\\Lambda \\to \\infty}\\left(\\sum_{\\vec{n}}-\\mathcal{P}\\int_{\\vec{n}}\\right) \\frac{1}{n^2-x}\\right]\n    +i\\theta(-x)\n    \\ ,\n\\end{multline}\nwith $x$ as in \\eqref{I0 FV}, $\\theta(x)$ is the heavyside function, and we switched the sign of the sum and integral as well as the sign of the denominator.  In the second line above we moved the term proportional to the $\\theta(-E)$ to the RHS.\nBecause we cut off the sum and the integral in exactly the same way, in dimensions where $I_D$ diverges with $\\Lambda$, the divergence cancels against the divergence in the sum.\nLet $N=\\Lambda L/\\pi$.\nThen, with a finite cutoff on magnitude $N/2$, we define\n\\begin{equation}\\label{eq:spherical cutoff S}\n    S^{\\spherical N}_D(x) =\n    \\left(\\sum_{\\vec{n}}- \\mathcal{P}\\int_{\\vec{n}}\\right) \\frac{1}{n^2-x}\n    + i \\frac{(2\\pi)^D}{4 \\F_D\\left(\\sqrt{x}\\right)}\\theta(-x)\\ ,\n\\end{equation}\nwhere it was used that $\\F_D(p) \\sim p^{2-D}$ and the $\\spherical$ superscript reminds us that we cut off our sum and integral in a spherical way, based on the magnitude of $n<N/2$.   By performing the principal value integral and taking the limit $N\\to \\infty$, we recover the usual \\Luscher zeta functions,\n\\begin{equation}\\label{eq:spherical S}\n    S^\\spherical_D(x)\n    =\n    \\lim_{N\\goesto\\infty} S^{\\spherical N}_D(x)\n    =\n    \\lim_{N\\rightarrow\\infty} \\sum_{\\vec{n}}^{n < N/2}\n    \\begin{cases}\n     \\frac{1}{n^2-x} - \\counterterm_3^\\spherical \\frac{N}{2}& (D=3)\\\\\n     \\frac{1}{n^2-x} - 2\\pi\\log\\left(\\counterterm_2^\\spherical\\frac{N}{2}x^{-1/2}\\right)& (D=2)\\\\\n    \\frac{1}{n^2-x} & (D=1)\n     \\end{cases}\n\\end{equation}\nwhere the dimension-dependent coefficients $\\counterterm_D^\\spherical$ of the counterterms come from the principal value integral; we evaluate the spherical-cutoff integrals and extract these coefficients in \\Appref{counterterm/spherical}.\\footnote{In higher dimensions there will be additional divergences which cancel, for example, in five spatial dimensions there will be a cubic and linear divergence.\n}\nFinally, we can write the quantization condition~\\eqref{general luscher} using the zeta function~\\eqref{spherical S},\n\\begin{equation}\\label{eq:spherical quantization}\n    \\cot \\delta_{D}(p) = \\frac{\\F_{D}(p)}{\\pi^2 L^{D-2}} S^\\spherical_D(x)\n\\end{equation}\nwhere we traded the energy dependence for momentum on the left-hand side.  Our result is consistent with those given in~\\Ref{Zhu:2019dho}\\footnote{In~\\Ref{Zhu:2019dho} the zeta functions~\\eqref{spherical cutoff S} were defined \\emph{without} the term proportional to the heavyside function.  Thus their zeta functions have a different behavior for $x<0$ as ours.  We note that our definition is more common in the literature.}.\nThis is the \\Luscher finite-volume quantization condition, and finite-volume energy levels calculated in the continuum should be fed through it to produce continuum scattering data.\nIn three dimensions it is common to move the momentum dependence in $\\F_{D}$ to the other side, as $p \\cot\\delta_{D}(p)$ is what appears in the effective range expansion \\eqref{ere}.\nIn two dimensions, it will prove useful to explicitly separate the logarithmic divergence as $N\\to\\infty$ from the logarithmic singularity as $x\\to 0$, and we will rearrange this equation and slightly redefine $S^\\spherical_2$ as needed in \\Secref{2D}.  Finally, the sum in~\\eqref{spherical S} can be analytically done in $D=1$, as we will show in \\Secref{1D}.\n\n%Derived in the zero-temperature continuum, only cold continuum-extrapolated spectra ought to be fed through the quantization condition \\eqref{spherical quantization} to extract continuum phase shifts.\n\nTo approach the continuum limit, the authors of \\Ref{Lee:2007ae} proposed tuning the interaction until the ground state, when fed through $S^\\spherical$, produced the desired amplitude that corresponds to the desired scattering length.\nWe will show in \\Secref{3D} that this procedure induces a momentum dependence in the scattering amplitude sensitive to discretization.\nIn the next subsection we give a procedure that produces a momentum-independent amplitude as one approaches the continuum, and discuss the limiting procedure itself.\n", "meta": {"hexsha": "113eedc9bef6915eb6713c7821da452713ea8d25", "size": 11281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/luescher/continuum.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/luescher/continuum.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/luescher/continuum.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": 68.7865853659, "max_line_length": 427, "alphanum_fraction": 0.6853115859, "num_tokens": 3674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6787601945515973}}
{"text": "\\documentclass[a4paper]{article}\n\\oddsidemargin 2.1mm\n\\textwidth     155mm\n\\topmargin     -12mm\n\\textheight    230mm\n\n\\def\\tabstrut{\\rule{0pt}{2.4ex}}\n\\def\\eq{\\!\\!\\!=\\!\\!\\!}\n\n\\begin{document}\n\n\\subsection*{The Normalized $\\chi^2$ Measure\n             for Association Rule Evaluation}\n\nLet $C$ and $A$ be two attributes with domains\n$\\mbox{dom}(A) = \\{ a_1, \\ldots a_{n_A} \\}$ and\n$\\mbox{dom}(C) = \\{ c_1, \\ldots c_{n_C} \\}$, respectively,\nand let $\\cal X$ be a dataset over $C$ and $A$.\nLet $N_{ij}$, $1 \\le i \\le n_C$, $1 \\le j \\le n_A$, be the number of\nsample cases in $\\cal X$, which contain both the attribute values~$c_i$\nand $a_j$. Furthermore, let\n\\[ N_{i.} = \\sum_{j=1}^{n_A} N_{ij}, \\qquad\n   N_{.j} = \\sum_{i=1}^{n_C} N_{ij}, \\qquad\\mbox{and}\\qquad\n   N_{..} = \\sum_{i=1}^{n_C} \\sum_{j=1}^{n_A} N_{ij} = |{\\cal X}|. \\]\nFinally, let\n\\[ p_{i.} = \\frac{N_{i.}}{N_{..}}, \\qquad\n   p_{.j} = \\frac{N_{.j}}{N_{..}}, \\qquad\\mbox{and}\\qquad\n   p_{ij} = \\frac{N_{ij}}{N_{..}} \\]\nbe the probabilities of the attribute values and their combinations,\nas they can be estimated from these numbers. Then the well-known\n$\\chi^2$ measure is usually defined as\n\\begin{eqnarray*}\n\\chi^2(C,A)\n& = & \\sum_{i=1}^{n_C} \\sum_{j=1}^{n_A}\n      \\frac{(E_{ij} -N_{ij})^2}{E_{ij}}\n      \\qquad\\mbox{where}\\quad E_{ij} = \\frac{N_{i.}N_{.j}}{N_{..}} \\\\\n& = & \\sum_{i=1}^{n_C} \\sum_{j=1}^{n_A}\n      \\frac{\\left(\\frac{N_{i.}N_{.j}}{N_{..}} -N_{ij}\\right)^2}\n           {\\frac{N_{i.}N_{.j}}{N_{..}}}\n~~=~~ \\sum_{i=1}^{n_C} \\sum_{j=1}^{n_A}\n      \\frac{N_{..}^2 \\left(\\frac{N_{i.\\phantom{j}}}{N_{..}}\n                           \\frac{N_{.j}}{N_{..}}\n                         - \\frac{N_{ij}}{N_{..}}\\right)^2}\n           {N_{..}\\;       \\frac{N_{i.\\phantom{j}}}{N_{..}}\n                           \\frac{N_{.j}}{N_{..}}} \\\\\n& = & N_{..} \\sum_{i=1}^{n_C} \\sum_{j=1}^{n_A}\n      \\frac{(p_{i.}\\;p_{.j} - p_{ij})^2}{p_{i.}\\;p_{.j}}\n~~=~~ N_{..} \\sum_{i=1}^{n_C} \\sum_{j=1}^{n_A}\n      \\frac{(N_{i.}\\;N_{.j} - N_{..}N_{ij})^2}{N_{i.}\\;N_{.j}}.\n\\end{eqnarray*}\nThis measure is often normalized by dividing it by the\nsize~$N_{..} = |{\\cal X}|$ of the dataset to remove the\ndependence on the number of sample cases.\n\nFor association rule evaluation, $C$ refers the consequent and $A$ to\nthe antecedent of the rule. Both have two values, which we denote by\n$c_0$, $c_1$ and $a_0$, $a_1$, respectively. $c_0$ means that the\nconsequent of the rule is not satisfied, $c_1$ that it is satisfied;\nlikewise for $A$. Then we have to compute the $\\chi^2$ measure from\nthe $2 \\times 2$ contingency table\n\\begin{center}\n\\begin{tabular}{|l|c|c|l|} \\cline{2-3}\n\\multicolumn{1}{l|}{}\n      & $a_0$    & $a_1$    \\\\ \\hline\n$c_0$ & $N_{00}$ & $N_{01}$ & $N_{0.}$\\tabstrut \\\\ \\hline\n$c_1$ & $N_{10}$ & $N_{11}$ & $N_{1.}$\\tabstrut \\\\ \\hline\n\\multicolumn{1}{l|}{}\n      & $N_{.0}$ & $N_{.1}$ & $N_{..}$\\tabstrut \\\\ \\cline{2-4}\n\\end{tabular}\n\\end{center}\nor the estimated probability table\n\\begin{center}\n\\begin{tabular}{|l|c|c|l|} \\cline{2-3}\n\\multicolumn{1}{l|}{}\n      & $a_0$    & $a_1$    \\\\ \\hline\n$c_0$ & $p_{00}$ & $p_{01}$ & $p_{0.}$\\tabstrut \\\\ \\hline\n$c_1$ & $p_{10}$ & $p_{11}$ & $p_{1.}$\\tabstrut \\\\ \\hline\n\\multicolumn{1}{l|}{}\n      & $p_{.0}$ & $p_{.1}$ & $1$\\tabstrut \\\\ \\cline{2-4}\n\\end{tabular}\n\\end{center}\nThat is, we have\n\\begin{eqnarray*}\n\\frac{\\chi^2(C,A)}{N_{..}}\n& = & \\sum_{i=0}^1 \\sum_{j=0}^1\n      \\frac{(p_{i.}\\;p_{.j} - p_{ij})^2}{p_{i.}\\;p_{.j}}. \\\\\n& = & \\frac{(p_{0.}\\;p_{.0} -p_{00})^2}{p_{0.}\\;p_{.0}}\n  +   \\frac{(p_{0.}\\;p_{.1} -p_{01})^2}{p_{0.}\\;p_{.1}}\n  +   \\frac{(p_{1.}\\;p_{.0} -p_{10})^2}{p_{1.}\\;p_{.0}}\n  +   \\frac{(p_{1.}\\;p_{.1} -p_{11})^2}{p_{1.}\\;p_{.1}}\n\\end{eqnarray*}\nNow we can exploit\n\\[ p_{00} + p_{01} = p_{0.}, \\quad\n   p_{10} + p_{10} = p_{1.}, \\quad\n   p_{00} + p_{10} = p_{.0}, \\quad\n   p_{01} + p_{11} = p_{.1}, \\quad\n   p_{0.} + p_{1.} = 1, \\quad\n   p_{.0} + p_{.1} = 1, \\]\nwhich leads to\n\\begin{eqnarray*}\np_{0.}\\;p_{.0} -p_{00}\n& = & (1 -p_{1.})(1 -p_{.1}) -(1 -p_{1.} -p_{.1} +p_{11})\n~~=~~ p_{1.}\\;p_{.1} -p_{11}, \\\\\np_{0.}\\;p_{.1} -p_{01}\n& = & (1 -p_{1.})p_{.1} -(p_{.1} -p_{11})\n~~=~~ p_{11} -p_{1.}\\;p_{.1}, \\\\\np_{1.}\\;p_{.0} -p_{10}\n& = & p_{1.}(1 -p_{.1}) -(p_{1.} -p_{11})\n~~=~~ p_{11} -p_{1.}\\;p_{.1}. \\\\\n\\end{eqnarray*}\nTherefore it is\n\\begin{eqnarray*}\n\\frac{\\chi^2(C,A)}{N_{..}}\n& = & \\frac{(p_{1.}\\;p_{.1} -p_{11})^2}{(1 -p_{1.})(1 -p_{.1})}\n  +   \\frac{(p_{1.}\\;p_{.1} -p_{11})^2}{(1 -p_{1.})\\;p_{.1}}\n  +   \\frac{(p_{1.}\\;p_{.1} -p_{11})^2}{p_{1.}(1 -p_{.1})}\n  +   \\frac{(p_{1.}\\;p_{.1} -p_{11})^2}{p_{1.}\\;p_{.1}} \\\\\n& = & \\frac{(p_{1.}\\;p_{.1} -p_{11})^2\n            (p_{1.}\\;p_{.1}\n            +p_{1.}(1 -p_{.1})\n            +(1 -p_{1.})p_{.1}\n            +(1 -p_{1.})(1 -p_{.1}))}\n           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})} \\\\\n& = & \\frac{(p_{1.}\\;p_{.1} -p_{11})^2\n            (p_{1.}\\;p_{.1}\n            +p_{1.} -p_{1.}\\;p_{.1}\n            +p_{.1} -p_{1.}\\;p_{.1}\n            +1 -p_{1.} -p_{.1} +p_{1.}\\;p_{.1})}\n           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})} \\\\\n& = & \\frac{(p_{1.}\\;p_{.1} -p_{11})^2}\n           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})}.\n\\end{eqnarray*}\nIn the program, $p_{1.}$ (argument {\\tt head}), $p_{.1}$\n(argument {\\tt body}) and $p_{1|1} = \\frac{p_{11}}{p_{.1}}$\n(argument {\\tt post}, rule confidence) are passed to the routine\nthat computes the measure, so the actual computation is\n\\begin{eqnarray*}\n\\frac{\\chi^2(C,A)}{N_{..}}\n& = & \\frac{(p_{1.}\\;p_{.1} -p_{1|1}\\;p_{.1})^2}\n           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})}.\n~~=~~ \\frac{((p_{1.} -p_{1|1})p_{.1})^2}\n           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})}.\n\\end{eqnarray*}\nIn an analogous way the measure can also be computed from the absolute\nfrequencies $N_{ij}$, $N_{i.}$, $N_{.j}$ and $N_{..}$, namely as\n\\begin{eqnarray*}\n\\frac{\\chi^2(C,A)}{N_{..}}\n& = & \\frac{(N_{1.}N_{.1} -N_{..}N_{11})^2}\n           {N_{1.}(N_{..} -N_{1.})N_{.1}(N_{..} -N_{.1})}.\n\\end{eqnarray*}\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "b09ce55ce8866d6ad6e8d252fb4ab28a9788c932", "size": 5980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ext/apriori/doc/chi2.tex", "max_stars_repo_name": "janniks/apriori", "max_stars_repo_head_hexsha": "909e5d0a82c5bb5271f29706a4563493d971af24", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-09-08T06:19:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-15T12:28:26.000Z", "max_issues_repo_path": "ext/apriori/doc/chi2.tex", "max_issues_repo_name": "nega/apriori", "max_issues_repo_head_hexsha": "13226550994f414f81380af5c5c0e8438f45a5d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-10-06T01:00:13.000Z", "max_issues_repo_issues_event_max_datetime": "2015-10-06T01:00:13.000Z", "max_forks_repo_path": "ext/apriori/doc/chi2.tex", "max_forks_repo_name": "nega/apriori", "max_forks_repo_head_hexsha": "13226550994f414f81380af5c5c0e8438f45a5d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-17T14:03:59.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-24T11:20:49.000Z", "avg_line_length": 38.0891719745, "max_line_length": 71, "alphanum_fraction": 0.4953177258, "num_tokens": 2854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.678665375708645}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\title{Soil Carbon Models}\n\\date{11/21/2016}\n\\begin{document}\n\\maketitle\n\\section*{Century Model}\nThe flow diagram for the century model proposed by Parton et al. (1988) is shown in Figure 1. In this document, we re-write the model in terms of a set of differential equations. In this model, we have 5 pools, each with a different turnover times: \n\\begin{itemize}\n\\item[pool 1:] \\makebox[2.5cm]{Structural C,\\hfill}  $\\kappa_1 \\approx 1/3$,\n\\item[pool 2:] \\makebox[2.5cm]{Metabolic C,\\hfill} $\\kappa_2 \\approx 1/0.5$,\n\\item[pool 3:] \\makebox[2.5cm]{Active Soil C,\\hfill}  $\\kappa_3 \\approx 1/1.5$,\n\\item[pool 4:] \\makebox[2.5cm]{Slow Soil C,\\hfill} $\\kappa_4 \\approx 1/25$,\n\\item[pool 5:] \\makebox[2.5cm]{Passive Soil C,\\hfill}  $\\kappa_5 \\approx 1/1000$,\n\\end{itemize}\nwhere $\\kappa$ denotes the decay rate which is defined as 1 over the turnover. \n\nWe denote the transfer rate from pool $j$ to pool $i$ by $r_{ij}$. The transfer rates are parameterized as a ratio of the decay rate: $r_{ij} = \\alpha_{ij} \\kappa_j$. From Figure 1, we have:\n\\begin{align*}\n\\alpha_{31} & =  (1-\\text{A})(1-0.45 \\times \\text{SL} - 0.55 \\times \\text{BL}), \\\\\n\\alpha_{41} & =  0.7 \\times \\text{A}, \\\\\n\\alpha_{32} & = 0.45, \\\\\n\\alpha_{43} & = 1 - F(\\text{T}) - 0.004, \\\\\n\\alpha_{53} & = 0.004, \\\\\n\\alpha_{34} & = 0.42, \\\\\n\\alpha_{54} & = 0.03, \\\\\n\\alpha_{35} & = 0.45,\n\\end{align*}\nwhere `SL' is the surface litter, `BL' is the soil litter, `A' is the Lignin fraction, `T' is the soil silt + clay content, and $F(\\text{T}) = 0.85 - 0.68 \\times \\text{T}$. The rest of the transfer coefficients are zero. \n\nFor each pool, we can write the following differential equation:\n\\begin{equation*}\n\\frac{d C_i(t)}{dt} = I_i(t) -\\kappa_i C_i(t) + \\sum_{j\\neq i} \\alpha_{ij} \\kappa_j,\n\\end{equation*}\nwhere $I_i(t)$ is the external input flow to pool $i$. As far as I understand, in the century model, the input flows are due to the plant residues and only enter the first two pools. Denoting the total flow due to plant residue by $I$, we have:\n\\begin{align*}\nI_1(t) & = (1-\\text{L/N})\\times I, \\\\\nI_2(t) & = \\text{L/N}\\times I,\n\\end{align*}\nwhere L/N denotes the Lignin to Nitrogen ratio. Combining all these differential equations into a single formula, we get:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \\left( {\\begin{array}{c}\n   (1-\\text{L/N})\\times I \\\\ \\text{L/N}\\times I \\\\ 0   \\\\ 0 \\\\ 0  \\end{array} } \\right) + \n   \\left( {\\begin{array}{ccccc}\n   -\\kappa_1 & 0 & 0 & 0 & 0 \\\\       \n   0 & -\\kappa_2 & 0 & 0 & 0 \\\\ \n   \\alpha_{31}\\kappa_1 & \\alpha_{32}\\kappa_2 & -\\kappa_3 & \\alpha_{34}\\kappa_4 & \\alpha_{35}\\kappa_5 \\\\\n   \\alpha_{41}\\kappa_1 & 0 & \\alpha_{43}\\kappa_3 & -\\kappa_4& 0  \\\\\n   0 & 0 & \\alpha_{53}\\kappa_3 & \\alpha_{54}\\kappa_4 & -\\kappa_5    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[scale=0.85]{century}\n\\caption{Flow diagram of century model}\n\\end{figure}\n\n\n\\section*{CN Model}\nThe flow diagram of the CN model, developed by Thronton et al., is shown in Figure 2. There are six pools:\n\\begin{itemize}\n\\item[pool 1:] \\makebox[1.5cm]{Lit1,\\hfill}  $\\kappa_1 \\approx 0.7$,\n\\item[pool 2:] \\makebox[1.5cm]{Lit2,\\hfill} $\\kappa_2 \\approx 0.07$,\n\\item[pool 3:] \\makebox[1.5cm]{Lit3,\\hfill}  $\\kappa_3 \\approx 0.014$,\n\\item[pool 4:] \\makebox[1.5cm]{SOM1,\\hfill} $\\kappa_4 \\approx 0.07$,\n\\item[pool 5:] \\makebox[1.5cm]{SOM2,\\hfill}  $\\kappa_5 \\approx 0.014$,\n\\item[pool 6:] \\makebox[1.5cm]{SOM3,\\hfill}  $\\kappa_6 \\approx 0.0005$.\n\\end{itemize}\nThe transfer rate coefficients are:\n\\begin{equation*}\n\\alpha_{41}  = 0.61, \\quad \\alpha_{52}  = 0.45, \\quad \\alpha_{63}  = 0.71, \\quad \\alpha_{54} = 0.72, \\quad \\alpha_{65} = 0.56.\n\\end{equation*}\nSo,\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \\left( {\\begin{array}{c}\n    I_1 \\\\ I_2 \\\\ I_3   \\\\ 0 \\\\ 0  \\\\ 0 \\end{array} } \\right) + \n   \\left( {\\begin{array}{cccccc}\n   -\\kappa_1 & 0 & 0 & 0 & 0 & 0\\\\       \n   0 & -\\kappa_2 & 0 & 0 & 0 & 0\\\\ \n   0 & 0 & -\\kappa_3 & 0 & 0 & 0 \\\\\n   \\alpha_{41}\\kappa_1 & 0 & 0 & -\\kappa_4 & 0 & 0 \\\\\n   0 &  \\alpha_{52}\\kappa_2 & 0 & \\alpha_{54}\\kappa_4 & -\\kappa_5 & 0 \\\\\n   0 & 0 & \\alpha_{63}\\kappa_3 & 0 & \\alpha_{65}\\kappa_5 & -\\kappa_6    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[scale=0.9]{cn}\n\\caption{Flow diagram of CN model}\n\\end{figure}\n\\end{document}", "meta": {"hexsha": "ac24cf0bcfb10f1fa605f45381b9ade40a65638f", "size": 4476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex_files/models.tex", "max_stars_repo_name": "ktoddbrown/decomPower", "max_stars_repo_head_hexsha": "4197b1a64f8d04712323f58918400d8054c681fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-12T23:45:51.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-15T01:09:35.000Z", "max_issues_repo_path": "tex_files/models.tex", "max_issues_repo_name": "ktoddbrown/decomPower", "max_issues_repo_head_hexsha": "4197b1a64f8d04712323f58918400d8054c681fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-01-18T18:14:51.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-15T18:43:38.000Z", "max_forks_repo_path": "tex_files/models.tex", "max_forks_repo_name": "ktoddbrown/decomPower", "max_forks_repo_head_hexsha": "4197b1a64f8d04712323f58918400d8054c681fe", "max_forks_repo_licenses": ["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.1157894737, "max_line_length": 249, "alphanum_fraction": 0.6425379803, "num_tokens": 1833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6786578303526722}}
{"text": "\\documentclass[twocolumn]{article}\n\n\\usepackage{booktabs}\t% For formal tables\n\\usepackage{listings}\n\\usepackage{amsmath}\t% AMS Math Package\n\\usepackage{amsthm} \t% Theorem Formatting\n\\usepackage{amssymb}\t% Math symbols such as \\mathbb\n\\usepackage{siunitx}\n\\usepackage{graphicx}\n\\usepackage{siunitx} % deg\n\\usepackage[margin=2cm]{geometry}\n\n\\let\\Bbbk\\relax\n\n\n\\begin{document}\n\n\\title{Implementation of a Freeform Modelling Tool }\n\n\n\\author{Robert Jendersie, Johannes Hauffe}\n\n\\maketitle\n\n\\section{Introduction}\nThis report aims to explain implementation details of our multi-resolution freeform modelling tool.\nBoth in terms of control metaphor and mathematical foundation, we follow the approach described in  \\cite{botsch2004intuitive}. Thus, we focus on aspects which are either different in our implementation or only mentioned briefly in the original paper.\\\\\nIn addition, we give technical background for the occurring \\textit{parameters}, many of which are exposed to the user to allow for experimentation and handling of vastly different meshes.\n\\section{Smooth Deformation}\nSame as in \\cite{botsch2004intuitive}, we perform the smooth deformation by minimizing a certain energy functional of the surface with respect to some boundary conditions. For the practical implementation on a triangle mesh we use discretization of the Laplace-Beltrami operator from \\cite{meyer2003discrete}. For the vertices $P = \\begin{bmatrix}p_1,\\dots, p_n\\end{bmatrix}^T$ of the mesh, it can be written in matrix form as\n\\begin{equation}\\label{laplace}\n\\triangle = M^{-1} L,\n\\end{equation}\nwhere $M$ is the diagonal matrix of vertex areas \n\\begin{equation*}\nm_{ii} = 2 A_{\\text{mixed}}(p_i),\n\\end{equation*} and $L$ is the sparse symmetric operator of edge weights $e_{ij}$\n\\begin{equation*}\nl_{ij} = l_{ji} = \\begin{cases} e_{ij} & i \\neq j, \\text{edge i-j exists} \\\\ -\\sum_{p_k \\in N_1(p_i)} e_{ik} & i=j \\\\ 0 & \\text{else}  \\end{cases},\n\\end{equation*}\nwhere $N_1(p)$ is the one-ring of $p$. To improve numerical robustness for poor triangulations, the edge weights are computed by clamping extreme $\\cot$ angles to the range $[0+c,\\ang{180}-c]$\n\\begin{align*}\ne_{ij} &= \\max(0, f(\\cot \\alpha_{ij}) + f(\\cot \\beta_{ij})) \\\\\nf(x) &= \\max(\\cot c, \\min(x, \\cot (\\ang{180}-c))).\n\\end{align*}\nWe use $c = \\ang{3}$.\\\\\nWith \\eqref{laplace} we can introduce the higher \\textit{order} operators $\\triangle^k$ where $k=1$ deforms the surface like a membrane by minimizing the area, $k=2$ characterizes thin plate surfaces which minimize\nsurface bending and $k=3$ minimizes curvature variation. At the boundary, this behaviour can be smoothly interpolated pointwise by introducing diagonal matrices $D_l$ \n\\begin{equation}\\label{laplace2}\n\\hat{\\triangle}^2 = M^{-1} L D_1 M^{-1} L\n\\end{equation} ,\n\\begin{equation}\\label{laplace3}\n\\hat{\\triangle}^3 = M^{-1}LD_2 M^{-1} L D_1 M^{-1} L,\n\\end{equation}\nwith $d_{k_{ii}} = \\lambda_k(p_i)$ from \\cite{botsch2004intuitive}.\nThis value can be adjusted by the user as \\textit{smoothness} for boundary and handle points.\nFinally, we can look at solving $\\hat{\\triangle}^k = 0$. Taking only the rows $\\hat{\\triangle}^k_{sup} = \\begin{bmatrix}L_1 L_2\\end{bmatrix}$ acting on the support vertices $s$ and the fixed boundary vertices $b$ we get\n\\begin{equation*}\n\\begin{bmatrix}L_1 & L_2 \\\\ 0 & I\\end{bmatrix} \\begin{bmatrix}s \\\\ b\\end{bmatrix} = \\begin{bmatrix} 0 \\\\ b \\end{bmatrix},\n\\end{equation*}\nwhich leads to the sparse system with non-trivial solution\n\\begin{equation}\\label{lsg}\nL_1 s = -L_2 b.\n\\end{equation}\nIn all cases $L_1$ is positive definite and in the context of solving the system \\eqref{lsg}, both \\eqref{laplace} and \\eqref{laplace2} can be easily made symmetric, since multiplication by $M$ from the left effectively removes the leftmost $M^{-1}$. For \\eqref{laplace3} this only works if $D_1 = D_2$, that is, when no interpolation is done. Thus, if applicable, we employ a sparse $LDL^T$ decomposition and fall back to a sparse $LU$ decomposition for the latter case. \\\\\nAlthough either decomposition needs to be done just once and solving the system afterwards is relatively fast, introducing precomputed basis functions as described in \\cite{botsch2004intuitive} further improves performance.\nInstead of picking affinely independent points from the handle $h$, we always use the orthogonal frame\n\\[\nQ\\begin{bmatrix}0 & 0 & 0 & 1 \\\\ 1 & 0 & 0 & 1 \\\\ 0 & 1 & 0 & 1 \\\\ 0 & 0 & 1 & 1\\end{bmatrix} = \\begin{bmatrix} h & 1 \\end{bmatrix},\n\\]\nto find the matrix $Q \\in \\mathbb{R}^{H \\times 4}$ of affine combinations.\n\\section{Detail Preservation}\nWe implement a multi-resolution editing approach based on point wise displacement vectors, as described in \\cite{kobbelt1998interactive}.\nTo preserve high frequency components in the support area, the details need to be first extracted and then reapplied to the modified mesh. We either use the displacement resulting from the initial solution of \\eqref{lsg} without changes to the handle, or perform \\textit{implicit smoothing} of the form\n\\begin{equation}\n(I - dt \\triangle^k) s = s_0,\n\\end{equation}\nto the support region with initial points $s_0$. The choice of a reasonable time-step $dt$ varies per mesh and can be adjusted by the user as \\textit{strength}.\nTo maintain the full details, the \\textit{smoothing order} $k$ should be the same as for the deformation, but in some cases a different order is more robust.\nSimilar to \\eqref{lsg}, we can integrate the fixed boundary and make the system symmetric to then solve\n\\begin{equation}\n(M_1 - dt L_1) s = M_1 s_0 + dt L_2 b,\n\\end{equation}\nwith the sparse $LDL^T$ decomposition, where $M_1$ are the area weights of vertices associated with $s$.\nSince the Laplace-Beltrami operator \\eqref{laplace} is used, the points should only move in normal direction.\nThus, the resulting displacement is encoded per vertex in a local frame, defined by the vertex normal and one edge to fix the rotation. Optionally, other vertices in the \\textit{n-ring} can be considered to find the local frame where the displacement vector has the smallest length. Also proposed in \\cite{kobbelt1998interactive}, this leads to fewer anomalies in the reconstructed surface, as seen in Figure~\\ref{fig:searchRing}.\n\\begin{figure}\n\t\\includegraphics[width=0.5\\textwidth]{searchframe.png}\n\t\\caption{Detail reconstruction using the local frame of each vertex (left) and the frame with the shortest displacement vector in the 4-ring neighbourhood (right). }\n\t\\label{fig:searchRing}\n\\end{figure}\n\n\\section{Results}\nTo evaluate the usability of our tool, we measure the performance for both modifications to the mesh and parameter changes of the operator.\nTimes are measured on a i5-6600k ($4 \\times 3.50$GHz) with 16GB DDR4 running Win10 Pro 64bit.\nThe test scenario consists of a mesh with 125k vertices, with a handle region containing 15k and the support region 35k vertices. \\\\\nFirst we consider modifications to the mesh. Updating the support vertices takes $1.6\\si{ms}$, adding the details another $21.6\\si{ms}$, resulting overall in a smooth framerate for editing.\n\\begin{table}\n\t\\centering\n\t\\caption{Measurements for updates to the operator.}\n\t\\begin{tabular}{lc}\n\t\tparameter & time [ms] \\\\\n\t\t\\hline\n\t\torder 1 & 276.77 \\\\\n\t\torder 2 & 922.87 \\\\\n\t\torder 3 & 2262.19 \\\\\n\t\tsmoothness & 5692.42 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\label{tab:order}\n\\end{table}\\\\\nParameter changes require recomputing the higher order operator and precomputing \\eqref{lsg}. Times for this are recorded in Table~\\ref{tab:order}. A higher order significantly increases computation times and so does the switch to the $LU$ solver for smoothness. Still, a wait time of up to 6s makes it possible to just try out different configurations during editing.\n\\begin{table}\n\t\\centering\n\t\\caption{Measurements for changes to the smoothing.}\n\t\\begin{tabular}{lc}\n\t\tparameter & time [ms] \\\\\n\t\t\\hline\n\t\tdetails order 1 & 212.81 \\\\\n\t\tdetails order 2 & 830.77 \\\\\n\t\tdetails order 3 & 2168.81 \\\\\n\t\tsearch ring 1 & 89.59 \\\\\n\t\tsearch ring 5 & 239.42 \\\\\n\t\tsearch ring 10 & 725.02 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\label{tab:smoothing}\n\\end{table}\\\\\nSimilar values are observed for the smoothing-step in Table~\\ref{tab:smoothing}.\nConsidering that the editing already requires a fixed boundary, the extra implicit smoothing is only useful in edge cases where full reconstruction is not feasible due to strongly stretched or compressed areas. Thus, this time can mostly be saved. A larger seach ring however, can be beneficial in both cases. Above a value of $10$, few differences where observed and considering the extra cost of around $\\frac{1}{3}$ of a third order operator computation in this case, this option can always be used.\n\n\\bibliographystyle{ieeetr}\n\\bibliography{references}\n\n\\end{document}\n", "meta": {"hexsha": "8d9b43e309445b1d2bcc0cbfe11675b272539de4", "size": 8757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/report.tex", "max_stars_repo_name": "Thanduriel/mesh-deformation", "max_stars_repo_head_hexsha": "b949e37b5ffdfe956bb285918b5fdfb1aae12de0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-26T17:53:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-22T11:23:40.000Z", "max_issues_repo_path": "docs/report.tex", "max_issues_repo_name": "Thanduriel/mesh-deformation", "max_issues_repo_head_hexsha": "b949e37b5ffdfe956bb285918b5fdfb1aae12de0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/report.tex", "max_forks_repo_name": "Thanduriel/mesh-deformation", "max_forks_repo_head_hexsha": "b949e37b5ffdfe956bb285918b5fdfb1aae12de0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-17T14:55:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-17T14:55:28.000Z", "avg_line_length": 64.3897058824, "max_line_length": 502, "alphanum_fraction": 0.7540253511, "num_tokens": 2482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6786537755437007}}
{"text": "\\newcommand{\\sign}{\\text{sign}}\n\\newcommand{\\matr}[1]{\\mathbf{#1}}\n\nMODFLOW gives us flows across cell-cell interfaces, which we can divide by interface areas to get specific discharge components normal to the interfaces. We refer to specific discharge here as ``velocity'' as a shortened form of Darcy velocity, with dimensions of $L/T$. So MODFLOW is essentially giving us normal-component velocity information at each interface. The idea behind the weighted-averaging scheme described here is to combine the normal-component information from the interfaces into estimates of the  $x$, $y$, and $z$ components of velocity at the cell center (node). The weights take into account both distance from the cell center and alignment with the desired velocity component.  The greatest weight is given to interfaces that are closest to the cell center and whose normals are most closely aligned with the desired velocity component. For example, when we are estimating the $x$ component of velocity at the cell center, an interface whose normal is in the $y$ direction is given a weight of zero because it provides a value for the $y$ component of velocity; it tells us nothing about the $x$ component.\n\n\\subsection{Estimating the $z$ Component of Velocity}\n\nAt each horizontal interface $k$ (along the top or bottom of the cell), MODFLOW gives us the interfacial flow, which we can divide by the area to get the $z$ component of velocity at the interface, $v_k^z$. Taking a weighted average of the estimates from all of the cell's horizontal interfaces, we get the following cell-center estimate of the $z$ component of velocity:\n\n\\begin{equation}\n\\label{vz}\nv^z = \\sum_{k=1}^K \\phi_k^z v_k^z,\n\\end{equation}\n\n\\noindent where the summations are over the cell's horizontal interfaces (locally numbered 1 through $K$), and $\\phi_k^z$ is the weight assigned to the estimate from interface  $k$, $v_k^z$, for the purpose of computing the cell-center value, $v^z$. We'll discuss the weights in more detail later.\n\n\\subsection{Estimating the $x$ and $y$ Components of Velocity}\n\nAt each vertical interface $i$ (along a ``side'' of the cell), MODFLOW gives us the interfacial flow, which we can divide by the area to get the component of velocity normal to the interface, $v_i^n$. This normal component is, of course, related to the full velocity vector at interface $i$, $v_i$, by\n\n\\begin{equation}\n\\label{nivi}\n\\matr{n_i} \\cdot \\matr{v_i} = v_i^n,\n\\end{equation}\n\n\\noindent or\n\n\\begin{equation}\n\\label{nivi2}\nn_i^x v_i^x + n_i^y v_i^y + n_i^z v_i^z = v_i^n.\n\\end{equation}\n\nFor concreteness, suppose we're currently interested in estimating the $x$ component of velocity at interface $i$ (so we can ultimately use it, together with similar estimates at the other interfaces, to inform our estimate of the $x$ component of velocity at the cell center).  Recognizing that $n_i^z = 0$  for vertical interfaces, and solving \\ref{nivi2} for the $x$ component, we get\n\n\\begin{equation}\n\\label{vix}\nv_i^x = \\left ( v_i^n - n_i^y v^y \\right ) / n_i^x.\n\\end{equation}\n\nEquation \\ref{vix} is an estimate of the $x$ component of velocity based on information from interface $i$ . Taking a weighted average of the estimates from all of the cell's vertical interfaces, we get the following cell-center estimate of the $x$ component of velocity:\n\n\\begin{equation}\n\\label{vx}\nv^x = \\sum_{i=1}^N \\phi_i^x v_i^x = \\sum_{i=1}^N \\frac{\\phi_i^x v_i^n}{n_i^x} - \\left( \\sum_{i=1}^N \\frac{\\phi_i^x n_i^y}{n_i^x}  \\right ) v^y,\n\\end{equation}\n\nWe now have two equations, \\ref{vix} and \\ref{vx}, in two unknowns, $v^x$ and $v^y$. Solving this 2x2 system, we get\n\n\\begin{equation}\n\\label{vxAB}\nv^x = \\frac{1}{1 - A^{xy} A^{yx}} \\sum_{i=1}^N  \\left( B_i^x - A^{xy} B_i^y \\right ) v_i^n\n\\end{equation}\n\n\\begin{equation}\n\\label{vxAB}\nv^y = \\frac{1}{1 - A^{xy} A^{yx}} \\sum_{i=1}^N  \\left( B_i^y - A^{yx} B_i^x \\right ) v_i^n,\n\\end{equation}\n\n\\noindent where\n\n\\begin{equation}\n\\label{Axy}\nA^{xy} = \\sum_{i=1}^N B_i^x n_i^y\n\\end{equation}\n\n\\begin{equation}\n\\label{Ayx}\nA^{yx} = \\sum_{i=1}^N B_i^y n_i^x,\n\\end{equation}\n\n\\noindent and\n\n\\begin{equation}\n\\label{Bix}\nB_i^x = \\frac{\\phi_i^x}{n_i^x}\n\\end{equation}\n\n\\begin{equation}\n\\label{Biy}\nB_i^y = \\frac{\\phi_i^y}{n_i^y}.\n\\end{equation}\n\nBoth equations \\ref{Bix} and \\ref{Biy} have the potential to blow up when $n_i^x$ and $n_i^y$ go to zero, but this will be taken care of in the formulation of the weights.\n\n\\subsection{Weights}\n\nFor estimation of the $z$ component of velocity, we can define a set of weights based on the distance (however we care to measure that---any reasonable measure will do) from each interface $k$ to the cell center, $D_k$, as follows:\n\n\\begin{equation}\n\\label{omegaz}\n\\omega_k^z = 1 - \\frac{D_k}{\\sum_{m=1}^K D_m}.\n\\end{equation}\n\nInterfaces that are closest to the cell center receive the greatest weights. However, as written above, the weights don't add up to 1, so we?ll normalize them such that they do:\n\n\\begin{equation}\n\\label{phiz}\n\\phi_k^z = \\frac{\\omega_k^z}{K - 1} = \\frac{1}{K - 1} \\left (1 - \\frac{D_k}{\\sum_{m=1}^K D_m} \\right ).\n\\end{equation}\n\nAs noted earlier, for estimating the $x$ and $y$ components of velocity, we also want to take into account how closely the normal-component information at each vertical interface aligns with the velocity component ($x$ or $y$) we're trying to estimate.  For that purpose, we can define the following set of weights:\n\n\\begin{equation}\n\\label{omegax}\n\\omega_i^x = \\left [ 1 - \\frac{D_i \\left | n_i^x \\right | }{\\sum_{l=1}^N{} D_l  \\left | n_l^x \\right | } \\right ] \\left | n_i^x \\right |,\n\\end{equation}\n\nand,\n\n\\begin{equation}\n\\label{omegay}\n\\omega_i^y = \\left [ 1 - \\frac{D_i \\left | n_i^y \\right | }{\\sum_{l=1}^N{} D_l  \\left | n_l^y \\right | } \\right ] \\left | n_i^y \\right |.\n\\end{equation}\n\nThese weight equations can also be written as\n\n\\begin{equation}\n\\label{omegax2}\n\\omega_i^x = \\left [ \\frac{\\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_i \\left | n_i^x \\right | }{\\sum_{l=1}^N D_l  \\left | n_l^x \\right | } \\right ] \\left | n_i^x \\right |,\n\\end{equation}\n\nand,\n\n\\begin{equation}\n\\label{omegay2}\n\\omega_i^y = \\left [ \\frac{\\sum_{l=1}^N{} D_l  \\left | n_l^y \\right | - D_i \\left | n_i^y \\right | }{\\sum_{l=1}^N{} D_l  \\left | n_l^y \\right | } \\right ] \\left | n_i^y \\right |.\n\\end{equation}\n\nThese don't add up to 1, so they are normalized so that they do:\n\n\\begin{equation}\n\\label{phix}\n\\phi_i^x =  \\frac{\\omega_i^x \\left | n_i^x \\right | }{\\sum_{l=1}^N \\omega_l^x  \\left | n_l^x \\right | } ,\n\\end{equation}\n\nand,\n\n\\begin{equation}\n\\label{phiy}\n\\phi_i^y =  \\frac{\\omega_i^y \\left | n_i^y \\right | }{\\sum_{l=1}^N \\omega_l^y  \\left | n_l^y \\right | } .\n\\end{equation}\n\nThese weights are substituted into the following equations for $B$, which are needed to solve for $v^x$ and $v^y$.\n\n\\begin{equation}\n\\label{bx}\nB_i^x =  \\frac{\\phi_i^x }{ n_i^x } ,\n\\end{equation}\n\nand,\n\n\\begin{equation}\n\\label{by}\nB_i^y =  \\frac{\\phi_i^y }{ n_i^y }.\n\\end{equation}\n\nDevelopment of an efficient solution scheme is obtained by substituting equations ~\\ref{omegax2} and ~\\ref{omegay2} into equations ~\\ref{phix} and ~\\ref{phiy}.  This results in the following expressions for $\\phi_i^x$ and $\\phi_i^y$:\n\n\\begin{equation}\n\\label{phix2}\n\\phi_i^x =  \\frac{\\left [ \\frac{\\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_i \\left | n_i^x \\right | }{\\sum_{l=1}^N D_l  \\left | n_l^x \\right | } \\right ] \\left | n_i^x \\right | \\left | n_i^x \\right | }{\\sum_{j=1}^N \\left [ \\frac{\\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_j \\left | n_j^x \\right | }{\\sum_{l=1}^N D_l  \\left | n_l^x \\right | }  \\right ] \\left | n_j^x \\right |  \\left | n_j^x \\right |  } ,\n\\end{equation}\n\nand,\n\n\\begin{equation}\n\\label{phiy2}\n\\phi_i^y =  \\frac{\\left [ \\frac{\\sum_{l=1}^N D_l  \\left | n_l^y \\right |  - D_i \\left | n_i^y \\right | }{\\sum_{l=1}^N D_l  \\left | n_l^y \\right | } \\right ] \\left | n_i^y \\right | \\left | n_i^y \\right | }{\\sum_{j=1}^N \\left [ \\frac{\\sum_{l=1}^N D_l  \\left | n_l^y \\right |  - D_j \\left | n_j^y \\right | }{\\sum_{l=1}^N D_l  \\left | n_l^y \\right | } \\right ] \\left | n_j^y \\right |  \\left | n_j^y \\right |  } .\n\\end{equation}\n\nEquations ~\\ref{phix2} and ~\\ref{phiy2} can be simplified as:\n\n\\begin{equation}\n\\label{phix3}\n\\phi_i^x =  \\frac{\\left [ \\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_i \\left | n_i^x \\right |  \\right ] \\left | n_i^x \\right | \\left | n_i^x \\right | }{\\sum_{j=1}^N \\left [ \\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_j \\left | n_j^x \\right | \\right ] \\left | n_j^x \\right |  \\left | n_j^x \\right |  } ,\n\\end{equation}\n\nand\n\n\\begin{equation}\n\\label{phiy3}\n\\phi_i^y =  \\frac{\\left [ \\sum_{l=1}^N D_l  \\left | n_l^y \\right |  - D_i \\left | n_i^y \\right |  \\right ] \\left | n_i^y \\right | \\left | n_i^y \\right | }{\\sum_{j=1}^N \\left [ \\sum_{l=1}^N D_l  \\left | n_l^y \\right |  - D_j \\left | n_j^y \\right | \\right ] \\left | n_j^y \\right |  \\left | n_j^y \\right |  } .\n\\end{equation}\n\nFinal combined equations for the $B$ terms are derived by substituting ~\\ref{phix3} and ~\\ref{phiy3} into ~\\ref{bx} and ~\\ref{by} to give:\n\n\\begin{equation}\n\\label{bx2}\nB_i^x =  \\frac{\\left [ \\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_i \\left | n_i^x \\right |  \\right ] \\left | n_i^x \\right | \\sign (n_i^x)  }{\\sum_{j=1}^N \\left [ \\sum_{l=1}^N D_l  \\left | n_l^x \\right |  - D_j \\left | n_j^x \\right | \\right ] \\left | n_j^x \\right |  \\left | n_j^x \\right | } ,\n\\end{equation}\n\nand\n\n\\begin{equation}\n\\label{bx2}\nB_i^y =  \\frac{\\left [ \\sum_{l=1}^N D_l  \\left | n_l^y \\right |  - D_i \\left | n_i^y \\right |  \\right ] \\left | n_i^y \\right | \\sign (n_i^y)  }{\\sum_{j=1}^N \\left [ \\sum_{l=1}^N D_l  \\left | n_l^y \\right |  - D_j \\left | n_j^y \\right | \\right ] \\left | n_j^y \\right |  \\left | n_j^y \\right | } .\n\\end{equation}\n\n\n", "meta": {"hexsha": "7b42f215e5804b6d5ef4da48848018684ed5ea43", "size": 9720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/mf6io/appendixB.tex", "max_stars_repo_name": "visr/modflow6", "max_stars_repo_head_hexsha": "52bdf65f4baf08adaf6405b3a577bb592a83bfd9", "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/mf6io/appendixB.tex", "max_issues_repo_name": "visr/modflow6", "max_issues_repo_head_hexsha": "52bdf65f4baf08adaf6405b3a577bb592a83bfd9", "max_issues_repo_licenses": ["CC0-1.0"], "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/mf6io/appendixB.tex", "max_forks_repo_name": "visr/modflow6", "max_forks_repo_head_hexsha": "52bdf65f4baf08adaf6405b3a577bb592a83bfd9", "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.6, "max_line_length": 1128, "alphanum_fraction": 0.671399177, "num_tokens": 3545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6786537590500901}}
{"text": "\\lab{Applications}{Riemann Sphere and Mobius Transformations}{Riemann Sphere and Mobius Transformations}\n\n\\objective{Understand the Riemann Sphere in graphics applications.}\n\nWe have now examined several applications of complex numbers and functions.  In this lab we extend several of these ideas and develop some intuition about the Riemann sphere using visualization techniques in Python.\n\nRecall that the complex numbers are an extension of the real numbers that include the imaginary numbers.  We extend them even further in this section and examine the extended complex numbers.  Similar to the extended real numbers, the extended complex numbers are our regular set of complex numbers with the addition of positive and negative infinity.  This allows us to examine, for example, certain quotients that are undefined on the standard complex numbers.\n\nThe Riemann sphere construction allows a compact and intuitive construction of the extended complex numbers.  Consider the standard complex plane, only now in 3-space instead of a 2 dimensional plane.  Let the plane pass threw the z-axis at $0$.\n\n{\\bf PICTURE HERE}\n\nNow consider a the unit sphere combined with the complex numbers in 3-space:\n\n{\\bf PICTURE HERE}\n\nWe say that the point at the top of the sphere is positive infinity, while the point at the bottom of the sphere is negative infinity.  We are able to construct any point on the complex plane as the point where a line going from either positive or negative infinity and intersecting the sphere at one point.  Such a line can be constructed to intersect the complex plane at any point of our choosing.  Here are some examples:\n\n{\\bf PICTURE AND GOOD CAPTION HERE}.\n\nHow do we construct such a line?  Using our understanding of lines in 3 space the construction is rather straightforward.\n\n\\begin{problem}  Find the point on the Riemann sphere that along with the point at infinity, creates the line that intersects the complex plane at $1 + 5i$, $10 + 15i$, and $1000 + 1500i$.  Why do we say that the top and bottom of the sphere are infinities?  Draw these lines and the Riemann sphere in Python.  Write a function that, given a point on the complex plane, finds the corresponding point on the Riemann sphere and visualizes it.\n\\end{problem}\n\n\\section*{Mobius Transformations}\n\nRecall from chapter {\\bf ???} that a conformal mapping is a complex function that preserves angles between lines.  We now examine a special kind of conformal mapping called a Mobius transformation.  We first give the definition of the Mobius transform, and then examine what sorts of transformations we can do with them.\n\n\\begin{definition}  A Mobius transformation is a any complex function of the form\n\\[\nf(z) = \\frac{az + b}{cz + d}\n\\]\nWith the restriction that $ad \\neq bc$\n\\end{definition}\n\nThe Mobius transformation is versatile enough to include translations, rotations, magnifications, or any combination of the same, of shapes in the complex plane.  For example, if we wish to translate the unit disk on the complex plane and then magnify it two times, we would use the following transformation:\n\\[\nPUT IT HERE\n\\]\n\n{\\bf PICTURE GOES HERE}\n\n\\begin{problem} Write a Python function that accepts arguments $a,b,c,$ and $d$.  Perform the corresponding Mobius transformation on a grid inside the box $[-1,1]\\times[-i,i]$, and then visualize the box before and after the transformation on the same plot, but using different colors.\n\\end{problem}\n\nWhat do these special transformations have to do with the Riemann sphere?  Recall from the conformal maps chapter that we can construct any point on the complex plane by drawing a line from infinity through a point on the Riemann sphere.  Consider the points on the sphere that can be used to construct the grid in the previous problem.\n\n{\\bf PICTURE GOES HERE}\n\nIt turns out that we can express any Mobius transformation as a translation or rotation of the Riemann sphere.  For example:\n\n{\\bf SEVERAL PICTURES WITH GOOD CAPTIONS GO HERE}\n\nEXAMPLE OF HOW TO FIND THE TRANSFORMATION OF THE SPHERE HERE\n\n\\begin{problem}  Write a Python program that extends the previous problem to 3-dimensions.  Visualize the Mobius translation as a rotation/translation of the Riemann sphere.\n\\end{problem}\n\n\n\n", "meta": {"hexsha": "48d204c021982557d6b305e06f5ad0f46f999ac6", "size": 4243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/RiemannSphere/RiemannSphere_C.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/RiemannSphere/RiemannSphere_C.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/RiemannSphere/RiemannSphere_C.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 68.435483871, "max_line_length": 462, "alphanum_fraction": 0.788828659, "num_tokens": 943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.6785963699319216}}
{"text": "\n\\chapter{Markov Chains}\n\n\\section{Important/Useful Theorems}\n\n\\subsection{}\nFor a Markox transition matrix, the limiting probabilities of being in a certain state as $n \\rightarrow \\infty$ are given by the solution to the following set of linear equations.\n\\begin{equation}\n\tp_j^* = \\sum_{i=1}^{\\infty} p_i^* p_{ij}\n\\end{equation}\n\n\\section{Answers to Problems}\n\\subsection{}\n%problem 7.1\nSince state $i$ signifies that the highest number chosen so far is $i$, what is the probability the next number is lower than $i$ and you stay in state $i$?  Well, there are $m$ possible numbers that could get picked and $i$ of them are less than or equal to $i$ giving:\n\n\\begin{equation}\n\tp_{ii} = \\frac{i}{m}\n\\end{equation}\n\nWhat now if we're in $i$ and we want to know what the probability of being in state $j$ is next.  Well, if $j<i$ then it's zero because you can't go to a lower number in this game.  If, however, $j$ is not lower then there are $m$ possible numbers that could get called and only one of them is $j$, giving:\n\\begin{equation}\n\tp_{ij} = \\frac{1}{m}, j>i\n\\end{equation}\n\\begin{equation}\n\tp_{ij} = 0, j<i\n\\end{equation}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 7.2\nSince the chain has an inevitable endpoint that you cannot get out of, there is a persistent state at $i=m$ while all other states are transient.  Transient, in that you will only see them a few times but $m$ is bound to show up sooner or later and once you're in $m$ you can't get out no matter what.\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 7.3\nTo do this properly we need to first construct the matrix $P$.\n\\begin{equation}\nP = \\left(\n\\begin{array}{ccccc}\n 0 & \\frac{1}{4} & \\frac{1}{4} & \\frac{1}{4} & \\frac{1}{4} \\\\\n 0 & \\frac{1}{4} & \\frac{1}{4} & \\frac{1}{4} & \\frac{1}{4} \\\\\n 0 & 0 & \\frac{1}{2} & \\frac{1}{4} & \\frac{1}{4} \\\\\n 0 & 0 & 0 & \\frac{3}{4} & \\frac{1}{4} \\\\\n 0 & 0 & 0 & 0 & 1\n\\end{array}\n\\right)\n\\end{equation}\nThen we square it:\n\\begin{equation}\nP^2 = \n\\left(\n\\begin{array}{ccccc}\n 0 & \\frac{1}{16} & \\frac{3}{16} & \\frac{5}{16} & \\frac{7}{16} \\\\\n 0 & \\frac{1}{16} & \\frac{3}{16} & \\frac{5}{16} & \\frac{7}{16} \\\\\n 0 & 0 & \\frac{1}{4} & \\frac{5}{16} & \\frac{7}{16} \\\\\n 0 & 0 & 0 & \\frac{9}{16} & \\frac{7}{16} \\\\\n 0 & 0 & 0 & 0 & 1\n\\end{array}\n\\right)\\end{equation}\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 7.4\nSo, if we start with $i$ balls in the urn, what is the probability that we have $j$ after drawing $m$ and discarding all the white balls.  The obvious first simplification we can make is that you can't end up with fewer that the $N-m$ white balls after drawing:\n\\begin{equation}\n\tp_{ij} = 0, j > N - m\n\\end{equation}\nYou also can't gain white balls\n\\begin{equation}\n\tp_{ij} = 0, j > i \n\\end{equation}\nOK! now for the interesting one.  There are $\\binom{N}{m}$ ways to draw $m$ balls from the urn.  In any given step, you are going to draw $i-j$ white balls from a total of $i$ and $m - i +j$ black balls from a total of $N-i$.  Thus there are $\\binom{i}{i-j}\\binom{N-i}{m - i +j}$ ways to make that draw.\n\\begin{equation}\n\tp_{ij} = \\frac{\\binom{i}{i-j}\\binom{N-i}{m - i +j}}{\\binom{N}{m}}, \\text{otherwise}\n\\end{equation}\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 7.5\nOnce again, we start building the transition matrix.\n\\begin{equation}\n\tP = \\left(\n\\begin{array}{ccccccccc}\n 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{1}{2} & \\frac{1}{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{3}{14} & \\frac{4}{7} & \\frac{3}{14} & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{1}{14} & \\frac{3}{7} & \\frac{3}{7} & \\frac{1}{14} & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{1}{70} & \\frac{8}{35} & \\frac{18}{35} & \\frac{8}{35} & \\frac{1}{70} & 0 & 0 & 0 & 0 \\\\\n 0 & \\frac{1}{14} & \\frac{3}{7} & \\frac{3}{7} & \\frac{1}{14} & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & \\frac{3}{14} & \\frac{4}{7} & \\frac{3}{14} & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & \\frac{1}{2} & \\frac{1}{2} & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\n\\end{array}\n\\right)\n\n\\end{equation}\nAnd then just square it!\n\\begin{equation}\n\tP^2 = \\left(\n\\begin{array}{ccccccccc}\n 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{3}{4} & \\frac{1}{4} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{107}{196} & \\frac{20}{49} & \\frac{9}{196} & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{75}{196} & \\frac{24}{49} & \\frac{6}{49} & \\frac{1}{196} & 0 & 0 & 0 & 0 & 0 \\\\\n \\frac{1251}{4900} & \\frac{624}{1225} & \\frac{264}{1225} & \\frac{24}{1225} & \\frac{1}{4900} & 0 & 0 & 0 & 0 \\\\\n \\frac{39}{245} & \\frac{471}{980} & \\frac{153}{490} & \\frac{23}{490} & \\frac{1}{980} & 0 & 0 & 0 & 0 \\\\\n \\frac{22}{245} & \\frac{102}{245} & \\frac{393}{980} & \\frac{22}{245} & \\frac{3}{980} & 0 & 0 & 0 & 0 \\\\\n \\frac{3}{70} & \\frac{23}{70} & \\frac{33}{70} & \\frac{3}{20} & \\frac{1}{140} & 0 & 0 & 0 & 0 \\\\\n \\frac{1}{70} & \\frac{8}{35} & \\frac{18}{35} & \\frac{8}{35} & \\frac{1}{70} & 0 & 0 & 0 & 0\n\\end{array}\n\\right)\n\\end{equation}\nTelling us there is a 39 in 245 chance that if we start with 5 balls that we'll be at zero after two steps.\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 7.6\nSince our chain is finite-dimensional and each state is accessible from every other state, all states are persistent by the corollary to theorem 7.3.\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 7.7\nAs the problem alludes to, if you start off on at any given point, there is zero probability of being at that point during the next step.  Hence, the elements of the transfer matrix oscillate between being 0 and non-zero so the limit of 7.20 is always zero and not greater than zero as implied.\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 7.8\n\nBecause you can now conceivably stay at the edge point, that means that every point is now accessible from every other point at every time step after a certain period of time has elapsed.  Since we're also finite dimensional and now accessible, 7.20 is now satisfied and we have proven the existence of the stationary probabilities.\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 7.9\n\nWe now want to solve:\n\n\\begin{equation}\n\tp_j^* = \\sum_{i=1}^{m} p_i^* p_{ij}\n\\end{equation}\nSo let's get to it!\n\n\\begin{eqnarray}\n\tp_1^* = \\sum_{i=1}^{m} p_i^* p_{i1} = q p_1^* + q p_2^* \\\\\n\tp_2^* = \\sum_{i=1}^{m} p_i^* p_{i2} = p p_1^* + q p_3^* \\\\\n\tp_j^* = p p_{j-1}^* + q p_{j+1}^* \\\\\n\tp_m^* = \\sum_{i=1}^{m} p_i^* p_{im} = p p_{m-1}^* + p p_{m}^*\n\\end{eqnarray}\nYou can easily solve the first equation to get:\n\\begin{equation}\n\tp_2^* =\\frac{p}{q} p_1^*\n\\end{equation}\nThen if we look to solve the second equation for $p_2^*$, \n\\begin{eqnarray}\n\tp_2^*  = p p_1^* + q p_3^* \\\\\n\t\\frac{p}{q} p_1^* = p p_1^* + q p_3^* \\\\\n\t\\left( \\frac{p}{q^2} - \\frac{p}{q} \\right) p_1^* = p_3^* \\\\\n\tp_3^* = \\left( \\frac{p}{q} \\right)^2 p_1^*\n\\end{eqnarray}\nSo clearly if we were to put that back into the third equation, we'd get another factor of $p/q$, ergo:\n\\begin{eqnarray}\n\tp_j^* = \\left( \\frac{p}{q} \\right)^{j-1}p_1^*\n\\end{eqnarray}\nThis needs to be normalized, however:\n\\begin{eqnarray}\n\t1 = \\sum_{j = 1}^m p_j^* = \\sum_{j = 1}^m \\left( \\frac{p}{q} \\right)^{j-1}p_1^* \\\\\n\t1 = \\frac{q \\left(\\left(\\frac{p}{q}\\right)^m-1\\right)}{p-q} p_1^* \\\\\n\tp_1^* = \\frac{p-q}{q \\left(\\left(\\frac{p}{q}\\right)^m-1\\right)}\n\\end{eqnarray}\nBut that's only if $q \\neq p$.  Clearly, if they are equal, each term of the sum will just be equal to 1. giving:\n\\begin{eqnarray}\n\t1 = \\sum_{j = 1}^m p_j^* = \\sum_{j = 1}^m \\left( \\frac{p}{q} \\right)^{j-1}p_1^* \\\\\n\t1 = m p_1^* \\\\\n\tp_1^* = \\frac{1}{m} \n\\end{eqnarray}\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 7.10\nLet's turn $A$ into 1 and $B$ into 2.  So, if 1 is shooting, there is a $\\alpha$ probability that 1 will go next whereas there is a $1 - \\alpha$ probability that 2 goes next.  Similarly, if 2 is shooting, there is a $1 - \\beta$ chance he shoots again and a $\\beta$ chance that 1 goes next.  That gives us a transfer matrix of:\n\\begin{equation}\nP = \\left(\n\\begin{array}{cc}\n \\alpha  & 1-\\alpha  \\\\\n \\beta  & 1 - \\beta  \\\\\n\\end{array}\n\\right)\n\\end{equation}\nWe want to solve the equation:\n\\begin{eqnarray}\n\t\\pi^T P = \\pi^T \\\\\n\t\\pi^T (P - I) = 0 \\\\\n\t\\pi_1 +\\pi_2 = 0\n\\end{eqnarray}\nI got lazy so I plugged the last two equations into my choice of symbolic manipulation program and got:\n\\begin{eqnarray}\n\tp_1^* = \\frac{\\beta }{1 - \\alpha +\\beta} \\\\\n\tp_2^* = \\frac{1 - \\alpha }{1 - \\alpha +\\beta}\n\\end{eqnarray}\nSince we want to know the probability the target eventually gets hit, the first limiting probability is our choice since it  represents the limit that $A$ is firing as the number of shots goes towards infinity. \n\n\\textbf{Answer not verified}\nNOTE: this answer is different from the book's answer... I tried like a dozen times and kept getting this so I think it may be wrong although I'd also believe that I am wrong so let me know!\n\n\n\\subsection{}\n%problem 7.11\n\n\\begin{equation}\n\tp_j^* = \\sum_{i=1}^{m} p_i^* p_{ij}\n\\end{equation}\nBut we're also told:\n\\begin{equation}\n\t1 = \\sum_{i=1}^{m} p_{ij} = \\sum_{j=1}^{m} p_{ij}\n\\end{equation}\nLet's expand things a bit:\n\\begin{eqnarray}\n\tp^*_1 = p_{11}p^*_1 + p_{21}p^*_2 + p_{31}p^*_3 + \\cdots\tp_{m1}p^*_m \\\\\n\tp^*_2 = p_{12}p^*_1 + p_{22}p^*_2 + p_{32}p^*_3 + \\cdots\tp_{m2}p^*_m \\\\\n\t\\cdots \\\\\n\tp^*_m = p_{1m}p^*_1 + p_{2m}p^*_2 + p_{3m}p^*_3 + \\cdots\tp_{mm}p^*_m\n\\end{eqnarray}\nYou will notice that a clear solution is every $p^*$ being unity and since it is a solution, that's all we care for.  Then, since the solution must be normalized, they all turn out to actually be $p^*_i = \\frac{1}{m}$.\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 7.12\n\n\\textbf{Solution practically in book}\n\n\\subsection{}\n%problem 7.13\n\\begin{equation}\n\tp_j^* = \\sum_{i=1}^{\\infty} p_i^* p_{ij}\n\\end{equation}\nSo let's solve...\n\\begin{eqnarray}\n\tp_1^* = \\sum_{i=1}^{\\infty} p_i^* p_{i1} = \\sum_{i=1}^{m} p_i^* \\frac{i}{i+1} \\\\\n\tp_j^* = \\sum_{i=1}^{\\infty} p_i^* p_{ij} = \\frac{1}{j} p^*_{j-1} \\\\\n\tp_j^* = \\frac{1}{j!} p_1^* \\\\\n\\end{eqnarray}\nNormalize this\n\\begin{eqnarray}\n\t\\sum_{j=1}^{\\infty} p_j^* = 1 = \\sum_{j=1}^{\\infty} \\frac{1}{j!} p_1^* \\\\\n\t1 = (1-e)p_1^* \\\\\n\tp_1^* = \\frac{1}{1-e} \\\\\n\tp_j^* = \\frac{1}{j!(1-e)} \n\\end{eqnarray}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 7.14\n\n\\textbf{Solution practically in book}\n\\subsection{}\n%problem 7.15\nIf the stakes are doubled, it's like playing the game without doubled stakes but half the capital on both sides in which case it is clear that $\\hat{p_j}$ gets bigger.\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 7.16\nPlay with the two possible limits in equation 7.34.\n\\textbf{Sorry... maybe some other day}\n%%answer template\n%\\subsection{}\n%%problem n.n\n%\n%\n%\\begin{equation}\n%\t\n%\\label{answern.n}\n%\\end{equation}\n%\\textbf{Answer [not] verified}\n\n\n\n\n\n", "meta": {"hexsha": "b8f072f8931c14bbba9b99660daf2b4b0ca65332", "size": 10629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter7.tex", "max_stars_repo_name": "stefk/Rozanov_ptcc_solutions", "max_stars_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter7.tex", "max_issues_repo_name": "stefk/Rozanov_ptcc_solutions", "max_issues_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter7.tex", "max_forks_repo_name": "stefk/Rozanov_ptcc_solutions", "max_forks_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0348432056, "max_line_length": 332, "alphanum_fraction": 0.6301627623, "num_tokens": 4182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6785963615029897}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath, amssymb, amsthm}\n\\usepackage{cancel}\n\\usepackage[nodayofweek]{datetime}\n\n% Set size of text area with total parameter\n\\usepackage[a4paper, total={155mm, 255mm}]{geometry}\n\n\\title{Computing the Mean of Consecutive Integers}\n\\author{Dyson}\n\\date{\\today}\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\nWhile looking through the source code of Julia's Statistics library to try out the \\texttt{@edit} macro like the massive nerd I am, I noticed something interesting. If the user calls \\texttt{mean()} with a \\texttt{UnitRange} object, which is just a range between two integers, then the \\texttt{mean()} function doesn't sum the range and divide by its length. Instead, it simply returns the start of the range, plus the end, divided by 2. This makes sense intuitively. The mean of a range of consecutive integers is just the middle of the range, but I wanted to prove it rigorously.\n\n\\section{The Conjecture}\n\nWe want to show that $\\displaystyle \\frac{\\sum\\limits_{n = a}^b n}{b - a + 1} \\equiv \\frac{a + b}{2}$, for $a, b \\in \\mathbb{Z}$ and $b > a$.\n\nWe have to use $b - a + 1$ for the length of the range, per se. $b - a$ is just the difference, but we need to count both $a$ and $b$, so we have to add one.\n\n\\section{The Proof}\n\nWe should start by getting rid of the sum.\n\\begin{gather*}\n\\sum_{n = a}^b n = \\sum_{n = 1}^b n - \\sum_{n = 1}^{a - 1} n\\\\[0.5em]\n= \\frac{b(b + 1)}{2} - \\frac{(a - 1)(a - 1 + 1)}{2}\\\\[0.5em]\n= \\frac{b(b + 1)}{2} - \\frac{a(a - 1)}{2}\\\\[0.5em]\n= \\frac{b^2 + b - a^2 + a}{2}\n\\end{gather*}\n\nThis means that now we only need to show that $\\displaystyle \\frac{b^2 + b - a^2 + a}{2} \\div (b - a + 1) \\equiv \\frac{a + b}{2}$.\n\\begin{gather*}\n\\frac{b^2 + b - a^2 + a}{2} \\div (b - a + 1) = \\frac{b^2 + b - a^2 + a}{2(b - a + 1)}\n\\end{gather*}\n\n\\newpage\n\nWe want this to become $\\dfrac{a + b}{2}$, so if we could show that the numerator could be written as $(a + b)(b - a + 1)$, then we could just cancel the fraction down and get what we want. Factoring $b - a + 1$ out of the numerator is tricky, but expanding the brackets to show that we get the numerator is easy.\n\n\\begin{gather*}\n(a + b)(b - a + 1) = ab - a^2 + a + b^2 - ab + b\\\\[0.5em]\n= -a^2 + a + b^2 + b\\\\[0.5em]\n= b^2 + b - a^2 + a\\\\[1em]\n\\therefore \\frac{b^2 + b - a^2 + a}{2(b - a + 1)} = \\frac{(a + b)\\cancel{(b - a + 1)}}{2\\cancel{(b - a + 1)}} = \\frac{a + b}{2}\n\\end{gather*}\n\\hspace*{\\fill}$\\square$\n\n\\end{document}\n", "meta": {"hexsha": "a67b0475d79699fad27b7e27a7ba695f1a1ae7e7", "size": 2582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Investigations/Computing_the_Mean_of_Consecutive_Integers.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": "Investigations/Computing_the_Mean_of_Consecutive_Integers.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": "Investigations/Computing_the_Mean_of_Consecutive_Integers.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": 44.5172413793, "max_line_length": 581, "alphanum_fraction": 0.6483346243, "num_tokens": 933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.6785963476959871}}
{"text": "\\section{Progress Summary}\n\nSix work packages span the timeline of this project. Since this project is primarily theoretical, we planned the first package to be a comprehensive review of the underlying concepts. Since graph states lie at the heart of measurement-based quantum computing, it is necessary to the terminology and some fundamental results. The second work package involves a literature review on measurement-based quantum computing. We discovered that since this subject is a major application area of stabilizer formalism and graph states in general, most of the available introductory materials on stabilizer formalism or graph states contain a review of measurement-based quantum at the very least. Furthermore, almost every resource on measurement-based quantum computing introduces the preliminary material, though with slightly different notations. Therefore we decided on overlapping the timelines of the first two work packages. \n\nGraphs are mathematical objects commonly used in computer science that are composed of vertices and edges connecting them\\cite{clrs}. A graph is defined by the set \\(V\\) of \\(N\\) vertices and \\(E\\) of \\(M\\) edges.\n\\begin{equation}\n  V = \\Set{1, 2, \\dots, N} \\quad\\text{and}\\quad E \\subseteq [V]^2 \\text{ where } \\abs{E\\,} = M\n\\end{equation}\nSince we do not define an 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 adjacent if there is an edge connecting them. A \\emph{neighborhood} of a vertex \\(a \\in V\\) is the set of all other vertices that are connected to it. \n\\begin{equation}\n  N_a = \\Set{\\,b\\in V \\given \\Set{a, b}\\in E\\,}\n\\end{equation}\n\nA subtype of graphs is \\emph{simple graphs} that contain no loops---edges connecting a vertex to itself---or multiple edges between any two vertices\\cite{hein2006}. We mainly deal with simple graphs in this paper. \n\nSimple graphs can represent the interactions of some qubit-based quantum systems. These systems, which we use to describe the structure of measurement-based quantum computers, are called \\emph{graphs states}. One of the two ways of defining a graph state is by its interaction patterns. A graph state describing the graph \\(G=\\p{V, E}\\) is made up of qubits that are labelled by the vertices of \\(G\\). The interaction pattern of the qubits \\(a\\) and \\(b\\) connected by an edge in \\(E\\) is an Ising interaction. We also impose the following conditions.\n\n\\begin{enumerate}\n  \\item Since an edge only denotes connectivity, all two-particle unitaries that involve an edge 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}\n\nThe general form of such an interaction pattern is given by the following unitary, parameterized by the \\emph{interraction 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}\\) 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 the 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.\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}. 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 \nset 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\\). The commutative subgroup of \\(\\symcal{P}^B\\) 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 generator, a stabilizer provides the following measurement outcome correlations.\n\\begin{equation}\n  m_x^a\\prod_{b\\in N_a}m_z^b = 1\n\\end{equation}\n\nA simple graph state, along with its interaction pattern and stabilizer definitions, is given in Figure\\ref{fig:graph_state}.\n\n\nAt the heart of the measurement-based computing paradigm lies the notion of a \\emph{cluster}\\cite{russendorf2001,russendorf2003}. A cluster is a \\(d\\)-dimensional array of qubits where every qubit interacts with its neighbours through Ising interactions. The state of a cluster \\(\\ket{C}\\) is a graph state. The cluster provides a general substrate that can perform universal computation. Then, Pauli measurements are applied on the cluster to encode and process the data as needed. In the next phase of this project, we are going to introduce the specific procedures which are necessary to achive universal computation by simulating CNOT, H, \\(z\\)-rotation, general rotation and \\(\\pi/2\\) phase gates.\n\nThe third work package involves the preparation of introduction and method parts of the written report. It is yet to be completed and we are actively working on it. Due to the deadline extension of the interim report, we decided to shift the deadline of this work package as well. Lastly, there are no changes on the remaining work packages. The new timeline is given in Table \\ref{tab:wp}.\n\n\\begin{table}[hbt]\n  \\centering\n  \\newcommand\\cc{\\blacksquare}\n  \\begin{tabular}{r @{\\hspace{2em}}c c c c c c c c c c c c c c}\n    \\toprule\n      & \\multicolumn{13}{c}{Week} \\\\\\cmidrule{2-14}\n    WP &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 & 10 & 11 & 12 & 13 & 14 \\\\\n    \\midrule\n    1 & \\cc & \\cc & \\cc & \\cc & \\cc & \\cc                                           \\\\\n    2 &     &     &     & \\cc & \\cc & \\cc & \\cc & \\cc                               \\\\\n    3 &     &     &     &     & \\cc & \\cc & \\cc & \\cc & \\cc                          \\\\\n    4 &     &     &     &     &     &     &     & \\cc & \\cc & \\cc & \\cc & \\cc       \\\\\n    5 &     &     &     &     &     &     &     &     &     &     &     & \\cc & \\cc \\\\\n    6 &     &     &     &     &     &     &     &     &     &     & \\cc & \\cc & \\cc \\\\\n    \\bottomrule\n  \\end{tabular}\n\n    \\caption{Revised timeline of the project\\label{tab:wp}}\n\\end{table}\n", "meta": {"hexsha": "fbaaad0d73e4c35bff5b9a3542a85f0a8375f31f", "size": 8800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/interim/content/summary.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/interim/content/summary.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/interim/content/summary.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": 69.2913385827, "max_line_length": 922, "alphanum_fraction": 0.6726136364, "num_tokens": 2729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6785637158744529}}
{"text": "\\chapter{Classification: Alternative} \n\n\\section{Underfitting and Overfitting}\nRe-substitution Errors, $e$: error on training\n\\marginnote{I do not focus on Support Vector Machines and Artificial Neural Network} \\\\\nGeneralization Errors, $e^{'}$: error on testing \\\\\n\\\\\nOptimistic approach to estimate $e^{'}$:\n$$e^{'}=e$$\nPessimistic approach to estimate $e^{'}$:\n$$e^{'}=e + \\frac{\\# leaf \\times 0.5}{Total\\ \\# \\ Instances}$$\n\\textbf{Occam's Razor} Given two models of similar generalization errors, one should prefer the simpler model over the more complex model.\n\n\\section{k-Nearest Neighbour}\nInstance based classifier: Use training records directly to predict the class label of unseen cases \\\\ \\\\\nK-nearest neighbors of a record $x$ are data points that have the $k$ smallest distance to $x$. \\\\\n\n\\section{Na$\\ddot{i}$ve Bayes Classifiers}\n\nBayes Theorem:\n$$P(C\\mid A) = \\frac{P(A\\mid C)P(C)}{P(A)}$$\n\\\\\nNa$\\ddot{i}$ve Bayes Classifiers: Compute the posterior probability for all values of C using the Bayes theorem\n$$P(C\\mid A_1 A_2 \\ldots A_n) = \\frac{P(A_1 A_2 \\ldots A_n\\mid C)P(C)}{P(A_1 A_2 \\ldots A_n)}$$\nAssume independence among attributes $A_i$\n$$P(C\\mid A_1 A_2 \\ldots A_n) = \\frac{P(A_1\\mid C_j)P(A_2\\mid C_j)\\ldots P(A_n\\mid C_n) P(C)}{P(A_1 A_2 \\ldots A_n)}$$\nFor discrete attribute:\n$$P(A_i\\mid C_j)=\\frac{\\mid A_{ik} \\mid}{N_c}$$\nFor continuous attribute, can use probability density estimation:\n$$P(A_i\\mid C_j)=\\frac{1}{\\sqrt{2\\pi \\sigma_j^{2}}}\\exp^{-\\frac{A_i-\\mu_j^{2}}{2\\sigma_j^{2}}}$$\n\\section{Support Vector Machines}\nFind a linear hyperplane (decision boundary) that will separate the data\n\n$$f(\\vec{x})=\n\\begin{cases} \n    1 & if\\ \\vec{w}\\bullet \\vec{x}+b \\ge 1 \\\\\n    0 & if\\ \\vec{w}\\bullet \\vec{x}+b \\le -1 \n\\end{cases}\n$$\n\n\\section{Ensemble Classification}\nPredict class label of previously unseen records by aggregating predictions made by multiple classifiers \\\\ \\\\\nAssumption: Individual classifiers could be lousy, but the aggregate can usually classify correctly.\n\n\\subsection{Bagging}\nSimplified steps: \n\\begin{enumerate}\n\\item Sampling with replacement to get $k$ set of data\n\\item Train multiple $k$ models on $k$ different samples\n\\item For each test example, predict by using simple majority voting\n\\end{enumerate}\n\n\n\\subsection{Boosting}\nAn iterative procedure to adaptively change distribution of training data by focusing more on previously misclassified records. \\\\ \\\\\nRecords that are wrongly classified will have their weights increased. Records that are correctly classified will have their weights decreased\n\n", "meta": {"hexsha": "db94df9300db2d03afda35cc753d84e7b5dff347", "size": 2563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter5.tex", "max_stars_repo_name": "Andyccs/data-mining-summary", "max_stars_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter5.tex", "max_issues_repo_name": "Andyccs/data-mining-summary", "max_issues_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter5.tex", "max_forks_repo_name": "Andyccs/data-mining-summary", "max_forks_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1896551724, "max_line_length": 142, "alphanum_fraction": 0.7327350761, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6785637093645432}}
{"text": "\\documentclass[answers]{exam}\n\n%% Language and font encodings\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{comment}\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{multirow}\n% \\usepackage{enumitem}\n%% Sets page size and margins\n\\usepackage[a4paper,margin=2cm]{geometry}\n\n%% Useful packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{paralist}\n\\usepackage{framed}\n\\usepackage{tikz}\n\\usepackage{float}\n\\usepackage{listings}\n\n\\tikzset{\n  % define the bar graph element\n  bar/.pic={\n    \\fill (-.1,0) rectangle (.1,#1) (0,#1) node[above,scale=1/2]{$#1$};\n  }\n}\n\\usetikzlibrary{matrix}\n\\setlength\\FrameSep{4pt}\n\\title{\\textbf{Probability \\& Statistics\\\\ Project}} \n\\author{Shamsa Hafeez Dawoodani - sd06162\\\\ Alisha Momin - am05757\\\\\nUmema Zehra - uz05607}\n\\begin{document}\n\\maketitle\n\\begin{center}\n    \\includegraphics[scale=1.5]{page1.PNG}\n\\end{center}\n\\newpage\n\\noindent \\hrulefill\n\\section{Random Walk}\n\\begin{framed}\n\n\\textbf{Solution:\\\\}\n\\textbf{Task 1.1:\\\\}\nThis function that takes in two parameters n and p. Where n is the number of steps left or right, as dictated by the probabilities and p is the probability of steps in the right direction. In our code, the total number of experiment were led for 100 steps each is 1000. We set the starting position equal to 0. Over here we generated an array, filled with zero, of the size of experiment i.e 1000. Our function generates a number in the range of 0.0 to 1.0 randomly till $h<n$. Then it checks if $x <$ P(moving right) then it will move in a right direction otherwise it will move in left direction. We store the expected position in a $position\\_list$ and then add all the element of $position\\_list$ in total and then we found the average of the total and store that in numpyarray.The experiment is rehashed several time using iteration and we created one figure containing 4 histograms with a different number of bins i.e. 10, 25, 55, 80 bins for the better result.\\\\\n\\begin{center}\n    \\includegraphics[scale=0.7]{task1.1a.PNG}\\\\\n    \\includegraphics[scale=0.7]{task1.1b.PNG}\n\\end{center}\nWhen we put n=100 and p=0.5, it give us the expected value of zero that is:  \\begin{center}\n    \\includegraphics[scale=0.7]{hist1.1_p=0.5.png}\n\\end{center}\nWhen we put n=100 and p=0.25, it give us the expected value with the most probability of moving in left direction: \\begin{center}\n    \\includegraphics[scale=0.7]{hist1.1_p=0.25.png}\n\\end{center}\nWhen we put n=100 and p=0.8, it give us the expected value with the most probability of moving in right direction:\\begin{center}\n    \\includegraphics[scale=0.7]{hist1.1_p=0.8.png}\n\\end{center}\n\\end{framed}\n\\begin{framed}\n\\textbf{Task 1.2:\\\\}\nThis function that takes in two parameters n and p. Where n is the number of steps left or right, as dictated by the probabilities and p is the probability of steps in the right direction. In our code, the total number of experiment were led for 100 steps each is 1000. We set the starting position equal to 0. Over here we generated an array, filled with zero, of the size of experiment i.e 1000. Our function generates a number in the range of 0.0 to 1.0 randomly till $h<n$. Then it checks if $x <$ P(moving right) then it will move in a right direction otherwise if the current position is greater than zero and $x\\geq p$ then it will move in left direction. We store the expected position in a $position\\_list$ and then add all the element of $position\\_list$ in total and then we found the average of the total and store that in numpyarray.The experiment is rehashed several time using iteration and we created one figure containing 4 histograms with a different number of bins i.e. 10, 25, 55, 80 bins for the better result.\n\\begin{center}\n    \\includegraphics[scale=0.7]{task1.2a.PNG}\\\\\n    \\includegraphics[scale=0.7]{task1.2b.PNG}\n\\end{center}\nWhen we put n=100 and p=0.5, p=0.25 and p=0.8 respectively give us the expected value:\n\\begin{center}\n    \\includegraphics[scale=0.6]{hist1.2_p=0.5.png}\\\\\n    \\includegraphics[scale=0.6]{hist1.2_p=0.25.png}\\\\\n    \\includegraphics[scale=0.6]{hist1.2_p=0.8.png}\n\\end{center}\n\\end{framed}\n\\begin{framed}\n\\textbf{Task 1.3:\\\\}\nThis function that takes in 4 parameters, the start position of object 1,  the start position of object 2,  the probability of object 1 to move right and the probability of object 2 to move right. In our code, the total number of experiment were led for 100 steps each is 1000 with the average of 50. Over here we generated an array, filled with zero, of the size of experiment i.e 1000. Our function generates two number in the range of 0.0 to 1.0 randomly. Then it checks 4 if conditions and run until $i_{1}$is not equal to $i_{2}$. Once the position of both the objects are equal i.e $i_{1}$is equal to $i_{2}$ then the while loop is break. We store the steps in a list and then add all the element of list in total and then we found the average of the total and store that in numpyarray.The experiment is rehashed several time using iteration and we created one figure containing 4 histograms with a different number of bins i.e. 10, 25, 55, 80 bins for the better result. \\\\\nNote: This function works similarly like task 1.1. we only modify few conditions for two objects along with their 2 probability of moving right.\n\\begin{center}\n\\includegraphics[scale=1]{task1.3_a.PNG}\\\\\n\\includegraphics[scale=1]{task1.3_b.PNG}\\\\\n\\includegraphics[scale=1]{task1.3_c.PNG}\\\\\n\\includegraphics[scale=0.7]{task1.3_d.PNG}\n\\end{center}\nWhen we put $i_{1}$=6 ,$i_{2}$=10 and $p_{1},p_{2}$=0.5\n\\begin{center}\n    \\includegraphics[scale=0.75]{hist1.3_a.png}\n\\end{center}\nWhen we put $i_{1}$=-2 ,$i_{2}$=5 and $p_{1} = 0.9 ,p_{2}=0.5$\n\\begin{center}\n    \\includegraphics[scale=0.7]{hist1.3_b.png}\n\\end{center}\n\\end{framed}\n\n\\newpage\n\\section{Simulating Distribution}\nLook at the following algebra and examine the accompanying code.\\\\\nLet $X$ follow a uniform distribution between 0 and 1. The probability that $X$ is less than some number, $x$, is $P(X < x) = x$. Suppose we want $Y$ to follow a random distribution for which we do not have any in built functions. Let $Y$ follow the distribution $f_Y(y) = e^{-y}$ for $y \\geq 0$. The following trick is used to derive the relation between X and Y. \\\\\n\\begin{figure}[H]\n            \\centering\n            \\includegraphics[width= 0.5\\textwidth]{Q2_question.PNG}\n        \\end{figure}\n        \n\\begin{figure}[H]\n            \\centering\n            \\includegraphics[width= 1.0\\textwidth]{Question2_ques_code.png}\n           \n        \\end{figure}\n\\subsection{} Does the code accomplish simulating the distribution? Which distribution does it follow? Try running\nthe code with different number of bins. Attach plots and discuss your results.\\\\\n\\begin{framed}\n\\textbf{Solution:\\\\}\nYes, the above code accomplishes the distribution.\\\\\n\\textbf{Reason:} Given that $X$ is a \\textbf{Uniform Distribution} between 0 and 1 such that $P(X < x) = x$. A random number generator generates a (pseudo) Random value from the standard uniform distribution [1]. So to generate a uniform distribution between 0 and 1, we generate a random number $x$ (see Line 4). \\\\\nSince we have found that the relation between $x$ and $y$ is : \n\\begin{center}\n    $y = -ln(1 - x)$ \\\\\n\\end{center}\nLine 5 assure that list $y$ stores all the values of $y$. \\\\\nLine 9 plots the histogram which represents the distribution (the blue plots in the diagram)... \\\\\nOn Line 10, $values$ consists of 50 evenly spaced values of $y$ with $min(y)$ as starting point and $max(y)$ as endpoint (2). \\\\\nFinally, on Line 11, it plots $values$ on the $x$ axis and their corresponding values, obtained from exponential function, on y-axis such that if $y_1 \\in values$, it is plotted on x axis and $e^{-y_1}$ plots on y axis. \\\\\nSo we have successfully plotted the distribution $e^{-y}$ for $y \\geq 0$ as shown by the red curve. \\\\\nNote that $y \\geq 0$ is assured since the relationship between $x$ and $y$ is derived after applying the lower limit and upper limit as $0$ and $y$ respectively. \n\\begin{center}\n    $\\int^y_0 \\, \\, e^{-y} \\, \\, dy = x$\\\\\n    $- \\Bigr[ e^{-y} \\Bigr|^y_0 = x$\\\\\n    $- (e^{-y} - e^{-0}) = x$\\\\\n    $- e^{-y} + e^{-0} = x $\\\\\n    $1 - e^{-y}  = x$\\\\\n\\end{center}\nNow, let us also discuss the results of running the code with different number of bins. \n\n\\begin{figure}[H] % fig 2 \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=10_code.PNG}\n    \\caption{Code given in Figure 1 with bins = 10}\n    \\vspace{2cm} \n    % fig 3\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=10.png}\n    \\caption{Results obtained from code in figure 2 i.e., bins = 10} \n\\end{figure}\n\n\\begin{figure}[H] % fig 4\n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=20_code.PNG}\n    \\caption{Code given in Figure 1 with bins = 20}\n    \n     % fig 5 \n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=20.png}\n    \\caption{Results obtained from code in figure 4 i.e., bins = 20}\n % fig 6\n\\vspace{1cm} \n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=30_code.PNG}\n    \\caption{Code given in Figure 1 with bins = 30}\n\\end{figure}\n\n\\begin{figure}[H] % fig 7\n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=30.png}\n    \\caption{Results obtained from code in figure 6 i.e., bins = 30}\n    \\vspace{2cm}\n % fig 8\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=50_code.PNG}\n    \\caption{Code given in Figure 1 with bins = 50}\n\\end{figure}\n\n\\begin{figure}[H] % fig 9 \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=50.png}\n    \\caption{Results obtained from code in figure 8 i.e., bins = 50}\n    \\vspace{2cm}\n % fig 10\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=100_code.PNG}\n    \\caption{Code given in Figure 1 with bins = 100}\n\\end{figure}\n\n\\begin{figure}[H] % fig 11 \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=100.png}\n    \\caption{Results obtained from code in figure 10 i.e., bins = 100}\n % fig 12\n    \\vspace{1cm}\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=1000_code.PNG}\n    \\caption{Code given in Figure 1 with bins = 1000}\n\\end{figure}\n\n\\begin{figure}[H] % fig 13\n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.1_bins=1000.png}\n    \\caption{Results obtained from code in figure 12 i.e., bins = 1000}\n\\end{figure} \n\\textbf{Finding the type of distibution:}\\\\\nWe know that a random variable $Z$ is said to have an exponential distribution with parameter $\\lambda$ ($\\lambda > 0$) if the PDF of $z$ is : \\\\\n\n \\[\n    f_Z(z) = \\left\\{\\begin{array}{@{}lr@{}}\n        \\lambda e ^ {- \\lambda z }& \\text{for } z \\geq 0\\\\\n        0 & \\text{otherwise }\n        \\end{array}\\right\\} \n  \\]\nBy comparing the definition with $f_Y(y) = e^{-y}$ for $y \\geq 0$  we can conclude that it is an \\textbf{Exponential Distribution} with $\\lambda = 1 $ and $Y$ is an Exponential Random Variable, \\\\ \\\\ \n\\textbf{Results:}\\\\\nFirst, let us try to understand what are bins. A histogram displays numerical data by grouping data into \"bins\" of equal width. Each bin is plotted as a bar whose height corresponds to how many data points are in that bin $^{[3]}$. \\\\\nNow, consider the following: \\\\\n$x \\in [0, 1]$\\\\\n$y \\in [-ln(1), -ln(0)]$ Apply limit instead of 0\\\\\n$y \\in [0, \\infty)$\\\\\nSo, the continuous Random variable $Y$ takes in $y \\in [0, \\infty)$ $^{[6]}$.\\\\\nSince our range is now from $[0, \\infty)$ it is difficult to plot 100000 possibly different values on histogram so we regularize it and divide it into bins. We divide our range into discrete number of intervals and we count how many of our samples are in each of these discrete ranges $^{[7]}$. \nThis implies that, increasing the number of bins draws more bars in the histogram and makes it more precise $^{[5]}$.  \n\nNotice that the results show that as the number of bins increases, the height of the histogram that was plotted using uniform random variable $X$ (and the relation between $x$ and $y$) , shown in blue color, traces the plot of exponential random variable, as shown in red color. This shows that we can simulate different distributions by mapping from the uniform distribution. So, yes the code accomplishes the distribution. \\\\\n\n\\end{framed}\n%%%%%%%%%%%%%%%%%%%%%% 2.2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{} Examine the following section of code and mathematically deduce what distribution $Y$ follows (Try working the above trick in reverse starting with the last statement). Show all required working. \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width= 1.0\\textwidth]{Question2.2_ques_code.png}\n\\end{figure}\nWhy are the lines 5-7 important. What does removing them do?\n\\begin{framed}\nLet us first deduce the distribution that $Y$ follows. \nLet $X$ follow a uniform distribution between 0 and 1. The probability that $X$ is less than some number,$x$, is $P(X < x) = x$. From Figure 14 Line 4 we can find the relation between $x$ and $y$: \n\n$y = \\frac{1}{1-x}$\\\\\n    $1 - x = \\frac{1}{y}$\\\\\n    $x = 1 - \\frac{1}{y}$\\\\\n    $x \\in [0, 1]$ and $y \\in [1, y]$\\\\\n    $x = \\int^y_1 \\, \\, \\frac{d}{dy} (1 - \\frac{1}{y}) \\, \\, dy$\\\\\n    $x = \\int^y_1 \\, \\, - (\\frac{d}{dy} y^{-1}) \\, \\, dy$\\\\\n    $x = \\int^y_1 \\, \\, (-1)(-1)y^{-2} \\, \\, dy$\\\\\n    $x = \\int^y_1 \\, \\, \\frac{1}{y^2} \\, \\, dy$\\\\ \n    So, $Y$ follows the distribution $f_Y(y) = e^{-y}$ for $y \\geq 1$ . \\\\\nLet us now understand why Line 5-7 are important. \\\\\nLine 5 sorts the list the list of $y$ in ascending order.  \\\\\nFor example: If $y = [ 5, 4, 80, 1 ]$ then after $y,sort()$ , $y = [1, 4, 5, 80]$ \\\\\nLine 6 stores the index of smallest element (in the sorted list of $y$) that is greater than 30 in variable $ind$.\nFor example: If $y = [1, 2, 40, 80]$ so $ind = 2$\\\\\nLine 7 updates $y$ such that sorted $y$ is sliced up till the smallest element in $y$ that is less than or equal to 30. For Example: Just before executing Line 7 $y = [1, 4, 5, 30, 80]$ and after Line 7 $y = [1, 4, 5, 30]$ \\\\\nIts importance lies in the fact that $y = \\frac{1}{1-x}$\\\\\nSo, as $x \\rightarrow 1$, $y \\rightarrow \\infty$\\\\\nSo, if we remove Line 5 - 7 , the maximum value of $y$, can be infinitely large. \\\\\n$max(y) \\rightarrow \\infty$\\\\\nThe range of $y$ has increased just because of at least a single large outcome of $y$. A zoomed out version of the graph would be obtained. As a matter of fact, the declining slope will look almost flat since the range of $y$ has increased and needs to be accommodated in the graph. In fact, the histogram seems to have been disappeared due to this reason! \n\\newpage\n\\begin{figure}[H] % fig 16\n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.2_withLine5-7_code.PNG}\n    \\caption{Code with Line 5-7}\n    \n    \\vspace{1cm} % fig 17\n    \n    \\includegraphics[width= 0.8\\textwidth]{Q2.2_withLine5-7.PNG}\n    \\caption{Graph with Line 5 - 7 }\n\\end{figure}\n\\newpage\n\\begin{figure}[H] % fig 18\n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.2_withoutLine5-7_code.PNG}\n    \\caption{Code without Line 5-7 }\n    \n    \\vspace{1cm} % fig 19\n    \n    \\includegraphics[width= 0.8\\textwidth]{Q2.2_withoutLine5-7.PNG}\n    \\caption{Graph without Line 5 - 7}\n\\end{figure}\n\nSo, when Line 5 - 7 are removed the distribution curve does not seem to satisfy the appropriate distribution function from which it is calculated. Line 5 - 7 restricts the possible range of values of $y$ so that the histogram gives a local view of the Probability Distribution Function that justifies $f_Y(y) = e^{-y}$ for $y \\geq 0$ (OR 1) \n\\end{framed}\n\n%%%%%%%%%%%%%%%%%%%%%%% 2.3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{} Implement a function that returns a random variable from the distribution, \\\\\n\\begin{center}\n    $f_Y(y) = \\frac{1}{y^3}$ for $y \\geq \\sqrt{\\frac{1}{2}}$ \n\\end{center}\nUse it to produce a histogram and line plot like the above code.\\\\\nImplement a different function that calculates the expected value using the experiments and iterations\napproach and plots the set of expected values obtained. You may need to utilize the trick pointed to\nin the above lines and choose an appropriate cutoff for both of these.\\\\\n\\begin{framed}\nFirst let us implement a function that returns a random variable from the distribution,\\\\\n    $f_Y(y) = \\frac{1}{y^3}$ for $y \\geq \\sqrt{\\frac{1}{2}}$ \\\\\nLet $X$ be a Random Variable that follows a uniform distribution between 0 and 1. The probability that $X$ is less than some\nnumber, $x$, is $P(X < x) = x$. \\\\\nUsing the same trick as in $2.1$ to find the relation between $X$ and $Y$ \\\\\n$P(Y < y) = P(X < x)$\\\\\n$\\int^y_{\\sqrt{0.5}} \\, \\, \\frac{1}{y^3} \\, \\, dy = x$\\\\\n$\\int^y_{\\sqrt{0.5}} \\, \\, y^{-3} \\, \\, dy = x$\\\\\n$\\Bigr[ \\frac{y^{-3+1}}{-3+1} \\Bigr|^y_{\\sqrt{0.5}} = x$\\\\\n$-\\frac{1}{2} \\Bigr[ y^{-2} \\Bigr|^y_{\\sqrt{0.5}} = x$\\\\\n$-\\frac{1}{2} ((y^{-2}) - (\\sqrt{\\frac{1}{2}})^{-2}) = x$\\\\\n$-\\frac{1}{2} (\\frac{1}{y^2} - 2) = x$\\\\\n$\\frac{-1}{2y^2} + \\frac{2}{2} = x$\\\\\n$1 - \\frac{1}{2y^2} = x$\\\\\n$\\frac{1}{2y^2} = 1 - x$\\\\\n$2y^2 = \\frac{1}{1-x}$\\\\\n$y^2 = \\frac{1}{2(1-x)}$\\\\\n$y = \\sqrt{\\frac{1}{2(1-x)}}$\\\\\\\\\n\nFollowing is the code used to produce histogram and line plot like the previous parts:\\\\\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.3_code.PNG}\n    \\caption{Code used to produce histogram and line plot for question 2.3}\n\\end{figure}\n\nNotice that Line 10 - 12 are important for the same reason as Line 5 - 7 were in question 2.2. \nSince $y \\geq \\sqrt{\\frac{1}{2}}$ in $f_Y(y)$, therefore, the list $y$ in the code above can have some values that are too large. The presence of even one such value makes it difficult to visualize the histogram as per the function provided. So, we have eliminated such large values. We are restricting the maximum possible value of $y$ such that $y \\leq 30$. This is the reason why the x-axis in the histogram above graphs values from 0 to 30\\\\\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q2.3_histogram.png}\n    \\caption{Histogram obtained from the distribution $f_Y(y) = \\frac{1}{y^3}$ for $y \\geq \\sqrt{0.5}$}\n\\end{figure}\n\nFinding Expected Value: \\\\\nWe know that expected value is basically the average value of a random variable. \n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q2.3_expected_value_code.PNG}\n    \\caption{Code used to find the expected value of $f_Y(y) = \\frac{1}{y^3}$ for $y \\geq \\sqrt{0.5}$}\n\\end{figure}\n\nThis produced the following histogram: \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q2.3_expected_value_histogram.png}\n    \\caption{Histogram of expected value of $f_Y(y) = \\frac{1}{y^3}$ for $y \\geq \\sqrt{0.5}$ using experiments and iterations}\n\\end{figure}\n\nLet us verify if we have obtained the correct results: \\\\\n$E[Y] = \\int^{\\infty}_{\\sqrt{0.5}} \\, y \\, \\frac{1}{y^3} \\, dy $\\\\\n$E[Y] = \\int^{\\infty}_{\\sqrt{0.5}} \\, \\frac{1}{y^2} \\, dy $\\\\\n$E[Y] = \\Bigr[ \\frac{Y^{-1}}{ -1 } \\Bigr|^{\\infty}_{\\sqrt{0.5}} $\\\\\n$E[Y] = \\lim_{y \\to \\infty} \\frac{-1}{y} - (- \\frac{1}{\\sqrt{0.5}})$\\\\\n$E[Y] = 0 + \\sqrt{2}$\n$E[Y] = \\sqrt{2}$\\\\\\\\\nNotice that the center of the histogram that has the highest frequency is approximately 1.4. This shows that our histogram is displaying correct results \n\n\\end{framed}\n\n\\newpage\n\n%%%%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Picking a random point correctly}\n%%%%%%%%%%%%%%%%% 3.1 %%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{} For this question, you have to pick random points in a circle in a uniform manner. The most intuitive approach for this is usually to pick a random number, r, from the uniform distribution between 0 and R, where R is the radius of the circle. Similarly, one can pick the angle $\\theta$ in a similar manner and generate x, y coordinates from them. \\\\\nImplement a function that takes in a radius, R, and samples a large number of points in the described manner. The function should generate a scatter plot containing all the sampled points, as well as plotting a circle of the appropriate radius, Find and mention the variation in the x-coordinates as well. \\\\ \n\\begin{framed}\n    \\textbf{Solution:}\n    Following is our code. Note that since the question has not mentioned to keep the center of the circle into consideration we have assumed the center of the circle to be at origin. i.e., (0, 0) \n    \n    \\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q3.1_code_1.PNG}\n     \\includegraphics[width= 0.9\\textwidth]{Q3.1_code_2.PNG}\n     \\caption{Code for 3.1}\n    \\end{figure}\n    \n    \\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.7\\textwidth]{Q3.1_histogram.png}\n    \\caption{Scattered plot obtained using strategy mentioned in 3.1 on a circle with radius 1 centered at origin}\n    \\end{figure}\n    \n    \\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q3.1_variance.PNG}\n    \\caption{variance of x-coordinates obtained using strategy mentioned in 3.1 on a circle with radius 1 centered at origin}\n    \\end{figure}\n    \n    So, the variation in the x-coordinates is 0.17294973786288853 \\\\\n\\end{framed}\n\\newpage\n%%%%%%%%%%%%%%%%% 3.2 %%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{} This, however, does not result in a uniform pick. You may spot this from the plot which should have points concentrated more towards the center rather then points being uniformly spread out across the circle. Change the number points you are plotting if you do not observe this trend. Now instead of generating $r$ and $\\theta$ values we will generate x and y values uniformly. To generate random points on a\ncircle of radius, R, pick both x and y independently and uniformly from the range [-R, R] to obtain a point. If the distance of this point from the origin is more than R, discard it and generate a new point in its place. \\\\\nImplement a function that takes in a radius, R, and samples a large number of points in the\ndescribed manner. The function should generate a scatter plot containing all the sampled points, as well as plotting a circle of the appropriate radius, Find and mention the variation in the x-coordinates as well. Comment on why this found variation is different or same as in the previous part.\n\\begin{framed}\n \\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.8\\textwidth]{Q3.2_code_1.PNG}\n     \\includegraphics[width= 0.9\\textwidth]{Q3.2_code_2.PNG}\n     \\caption{Code for 3.2}\n    \\end{figure}\n    \n    \\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.7\\textwidth]{Q3.2_histogram.png}\n    \\caption{Scattered Plot obtained using strategy mentioned in 3.2 on a circle with radius 1 centered at origin}\n    \\end{figure}\n    \n    \\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q3.2_variance.PNG}\n    \\caption{variance of x-coordinates obtained using strategy mentioned in 3.2 on a circle with radius 1 centered at origin}\n    \\end{figure}\n    \n    So, the variation in the x-coordinates is 0.2535503962972633 \\\\\n\n\\textbf{Comment:} \\\\\nNotice that the x coordinates' variation obtained is approximately 0.25 which is approximately 0.42 more than the variance obtained in previous approach i.e., approach used in part 3.1 (whose x coordinates' variance approximately was 0.17) although both are obtained on a circle with radius 1 centered at origin. Question arises why is that so? \\\\\nIn the first approach, points obtained are not equally spaced with respect to the center The points are the center of the circle are more dense. as we go away from the center, the density of points goes on decreasing. So this implies that the randomly generated point is more likely to be near the center than as compared to near the circumference. The points closer to the center has more probability of generation and as we go further and further away from the center this probability goes on decreasing. Thus the points obtained in 3.1 were not Uniformly distributed. However, when we picked points by a uniform random distribution of in terms of x and y coordinates the resulting points were Uniform as each point is equally likely to be obtained. Note that we are discarding a point (x, y) if it is outside the circle implying that the points to be obtained are to be limited to the area under consideration i.e., circle. The variance has increased. i.e., the degree of the spread of the data has increased increased since this is a more uniformly distributed plot \\\\\n\\end{framed}\n\n%%%%%%%%%%%%%%%%% 3.3 %%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{} To get an intuition of why the first approach does not result in a uniform pick imagine a circle of radius 1 embedded in a circle of radius 2 as shown in Fig.2. If points are picked randomly, the probability of the point lying inside the larger circle should be 4 times than the smaller one. Does this hold when the above described method to pick r and $\\theta$ is used? Explain in report with working.\\\\\nIn this part, modify one or both of the ways to pick r and $\\theta$ such that the points are sampled in a\nuniform manner and a plot similar to that in part 2 is obtained. Implement a similar function as the\nabove part. The plot generated this time should contain points that are uniformly spread across the\ncircle. Describe how are you picking the random variables and find the variance of the x-coordinates\nonce again and comment on your results. \\\\ \nIf you feeling up to it or for a bonus then you may derive the distribution from the following two facts. The probability of a point to lie inside a circle of radius, $r \\leq R$ is proportional to its area. i.e. $P(r \\leq R) = k \\, \\pi r^2$. The probability of it lying inside the outermost circle of radius, $R$ should be 1 i.e. $P(R \\leq R) = 1$. \\\\\nAfter finding the distribution that r follows, you may then generate the values of r appropriately by mapping from the uniform random distribution as in the previous questions. Show all mathematical working. \\\\\n\n\\begin{figure} % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q3.3_question.PNG}\n    \\caption{Comparison of area. Circles of radius 1 and 2}\n\\end{figure}\n\n\\begin{framed}\n    \\textbf{Solution:}\\\\\n    Yes, if the above described method of $r$ and $\\theta$ are used then the probability of a randomly picked point to lie in the outside circle is 4 times more than the probability of the point to lie in the smaller circle (blue one). To understand this we know that the radius of outside circle is 2. Let this radius be $r$. Consequently, the radius of the inside circle is $\\frac{r}{2}$. Let A be the event of a randomly picked point (picked using randomly generated $r$ and $\\theta$ as described in first approach) to lie inside/on the blue circle. Let B be the event of a randomly picked point (picked using randomly generated $r$ and $\\theta$ as described in first approach) lie in the orange region.\\\\ \\\\\n    $P(A) = \\frac{\\pi \\, (\\frac{r}{2})^2}{\\pi \\, r^2}$\\\\\n    $P(A) = \\frac{\\pi \\, \\frac{r^2}{4}}{ \\pi \\, r^2}$\\\\\n    $P(A) = \\frac{1}{4} = 0.25$\\\\\\\\\n    Note that since the outer circle includes the orange as well as blue region , $P(A)$ tells us that the probability of the point lying inside the larger circle is 4 times than the smaller one.\\\\\\\\\n\n    \\begin{figure}[H] % fig \n        \\centering\n        \\includegraphics[width= 0.3\\textwidth]{Q3.3_question_modified.png}\n        \\caption{Comparison of area. Circles of radius 1 and 2}\n    \\end{figure}\n\n    Thus it is proved that randomly generated $r$ and $\\theta$ does not result in a uniform probability \\\\ \n    \n    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n    Given that $P(r \\leq R) = k \\, \\pi r^2 $\\\\\n    We want it to be uniformly distributed.So we will map it to uniformly selected $x$ such that $x \\in [0, 1]$ \\\\\n    $P(r \\leq R) = k \\, \\pi r^2 = x$\\\\\n    $k \\, \\pi r^2 = x$\\\\\n    $r^2 = \\frac{x}{k \\pi}$\\\\\n    $r = \\sqrt{\\frac{x}{k\\pi}}$.................(i)\\\\\n    When $r = R$ it is given that $P(R \\leq R) = 1$\\\\\n    $k\\pi(R^2) = 1$\\\\\n    $k\\pi = \\frac{1}{R^2}$\\\\\n    Put in equation (i): \\\\ \n    $r = \\sqrt{\\frac{x}{\\frac{1}{R^2}}}$\\\\\n    $r = \\sqrt{R^2 x}$\\\\\n    $r = R \\sqrt{x}$ \\\\\n    \n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=1\\textwidth]{Q3.3_code_1.PNG}\n    \\end{figure}\n    \n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=1\\textwidth]{Q3.3_code_2.PNG}\n        \\caption{Code for 3.3}\n    \\end{figure}\n    \n    \\begin{figure}{H}\n        \\centering\n        \\includegraphics[width= 0.5\\textwidth]{Q3.3_scatter_plot.png}\n        \\caption{Scatter Plot for 3.3}\n    \\end{figure}\n    \\includegraphics[scale=0.5]{Q3.3_scatter_plot.png}\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width= 0.3\\textwidth]{Q3.3_variance.PNG}\n        \\caption{Variance as per 3.3}\n    \\end{figure}\n    \n\\end{framed}\n%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%%%%%%\n\\section{Saying random is not enough - Approaches effect distributions}\nIn this question we are going to observe the distribution followed by the length of a random chord picked from a circle of radius $r$.\nThe difficulty of the question lies in how to pick a random chord in a circle. For each of the described approaches implement a different function that takes in radius, $r$ and plots a histogram of the length of chords with an appropriate number of bins, with proportion (probability) of values in the bin on y-axis instead of counts. Include mathematical calculation of chord lengths in all\nparts.  \\\\\n\n%%%%%%%%%%%%%%%%% 4.1 %%%%%%%%%%%%%%%%%%%%%%\n\\subsection{} For the first approach we imagine the circle centred on the origin of the Cartesian plane. The $\\theta = 0$ ray/line is defined as starting at the origin and pointing in the direction of increasing x, and $\\theta$ increasing counter clockwise. We pick two angles $\\theta_1$ and $\\theta_2$ uniformly between $0$ and $2\\pi$, and our random chord is the chord between the points of the circle defined by those two angles.\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q4.1.PNG}\n    \\caption{Picking a chord through 2 random angles}\n\\end{figure}\n\n\\begin{framed}\n\\textbf{Solution:}\nUsing a circle centered at origin with radius 1. \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q4.1_working.PNG}\n    \\caption{Finding a chord through 2 random angles}\n\\end{figure}\n\nDeriving the value of $C$ from $\\theta_1$ and $\\theta_2$\\\\\n\\begin{center}\n    $\\theta = \\theta_2 - \\theta_1$\n\\end{center}\n\nWe know that the distance from the center of the circle till any point on the circumference of the circle is equal to the radius $r$ of the circle. Therefore, \n\n\\begin{center}\n    $\\overline{OA} = \\overline{OB} = r$\n\\end{center}\n\nObserve that $\\triangle OBA$ is formed with sides $AB$, $AO$ and $OB$, The angle opposite to side $AB$ is $\\theta$\\\\\nAccording to Law of Cosine: \\\\\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5\\textwidth]{cosine_law.PNG}\n    \\caption{Law of cosine [8] }\n\\end{figure}\n\nUsing Law of cosine: \\\\\n    $C = \\sqrt{r^2 + r^2 - 2(r)(r)(cos \\, \\theta)}$\\\\\n    $C = \\sqrt{2r^2 - 2(r^2)(cos \\, \\theta)}$\\\\\n    $C = \\sqrt{2r^2 (1 - cos \\, \\theta)}$\\\\\n    $C = r\\sqrt{2(1 - cos \\, \\theta)}$\\\\\n    Using double angle formula: \\\\$cos \\, 2 \\theta = 1 - 2 \\, sin^2 \\, \\theta$\\\\\n    $cos \\, \\theta = 1 - 2 \\, sin^2 \\, \\frac{\\theta}{2}$\\\\\n    $1 - cos \\, \\theta = 2 \\, sin^2 \\, \\frac{\\theta}{2}$\\\\\n    Plugging it to obtain $C$: \\\\\n    $C = r \\sqrt{2 (2 \\, sin^2 \\, \\frac{\\theta}{2})}$\\\\\n    $C = r \\sqrt{4 sin^2 \\, \\frac{\\theta}{2}}$\\\\\n    $C = 2r \\, sin \\, \\frac{\\theta}{2}$\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q4.1_code.PNG}\n    \\caption{Code for question 4.1}\n\\end{figure}\n\n\\begin{figure}[H] % fig % done  \n    \\centering\n    \\includegraphics[width= 0.5\\textwidth]{Q4.1_histogram.png}\n    \\caption{Histogram for part 4.1}\n\\end{figure}\n\nNotice that in line 22 - 23, we interchange the angle if $\\theta_2 > \\theta_1$. This is because we do not want the length of our chord to be negative as length is always positive. This implies that $\\theta_1$ is greater than $\\theta_2$\n\n\\end{framed}\n%%%%%%%%%%%%%%%%% 4.2 %%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{} For the second approach we imagine the circle in a similar manner. Then we pick a random direction, $\\theta$, and draw a line from the center of the circle to its boundary such that the angle from the ray $\\theta$ = 0 to this line, measured counter clockwise is $\\theta$. To create a random chord, we pick a point along this\nline and construct the perpendicular bisector of the line at this point. The perpendicular bisector can be extended to touch the boundary of the circle at either ends to obtain a chord.\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q4.2.PNG}\n    \\caption{Picking a chord as bisector of some ray}\n\\end{figure}\n\n\\begin{framed}\n\\textbf{Solution:}\nUsing a circle centered at origin with radius 1. \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q4.2_working.PNG}\n    \\caption{Chord as bisector of some ray}\n\\end{figure}\nAs given in the question, we can \\textbf{pick a point} on line $\\overline{OQ}$. Let this point be called as $P$. Let $d$ be the distance between $O$ and $P$ such that :\\\\\n$d \\in [0, r]$\\\\\n$P = (d \\, cos \\, \\theta , d \\, sin \\, \\theta)$\\\\\\\\\nFurthermore, \\\\\n$\\overline{AB} = \\overline{BP} + \\overline{PA}$\\\\\n$\\overline{AB} = C$\\\\\nSince $\\overline{OP}$ is perpendicular bisector of $\\overline{AB}$ ,\\\\\n$ \\overline{BP} = \\overline{PA} = \\frac{C}{2}$\\\\\\\\\nSince $\\overline{OP} \\perp \\overline{PA}$,  $\\triangle OPA $ is a right angled triangle \\\\\nApplying Pythagoras Theorem: \\\\\n$r^2 = d^2 + \\frac{C^2}{4}$\\\\\n$r^2 - d^2 = \\frac{C^2}{4}$\\\\\n$C^2 = 4(r^2 - d^2)$\\\\\n$C = \\sqrt{4(r^2 - d^2)}$\\\\\n$C = 2 \\sqrt{r^2 - d^2}$\\\\\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q4.2_code_1.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q4.2_code_2.PNG}\n    \\caption{Code for question 4.2}\n\\end{figure}\n\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 0.5\\textwidth]{Q4.2_histogram.png}\n    \\caption{Histogram for question 4.2}\n\\end{figure}\n\n\n\\end{framed}\n\n%%%%%%%%%%%%%%%%% 4.3 %%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{} For the third approach we again visualize the circle as before. This time we pick a random point uniformly from the circle as we did in the previous question. You may use any helper functions you may have developed in the previous part for this. After picking a point we find the chord which will have this point as it midpoint and this will be our random chord. There will be only one such chord. \n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 0.3\\textwidth]{Q4.3.PNG}\n\\end{figure}\n\n\n\\begin{framed}\n\\textbf{Solution:}\nUsing a circle centered at origin with radius 1. \nLet $(x, y)$ be be a point that we pick uniformly from the circle. \\\\\nUsing Pythagoras Theorem: \\\\\n$r^2 = (\\frac{c}{2})^2 + d^2 $\\\\\n$4r^2 = c^2 + 4d^2$\\\\\n$C = \\sqrt{4r^2 - 4d^2}$\\\\\n$C = 2 \\sqrt{r^2 - d^2}$ \\\\\n$C = 2 \\sqrt{r^2 - x^2 - y^2} $\\\\\n$C = 2 \\sqrt{r^2 - (x^2 + y^2)}$\\\\\n$C = 2 \\sqrt{r^2 - d^2}$\\\\\nWhen $d$ is the perpendicular distance from the center of the circle till point $(x , y)$\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q4.3_code_1.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 1\\textwidth]{Q4.3_code_2.PNG}\n    \\caption{Code for question 4.3}\n\\end{figure}\n\n\\begin{figure}[H] % fig % done \n    \\centering\n    \\includegraphics[width= 0.5\\textwidth]{Q4.3_histogram.png}\n    \\caption{Histogram for question 4.3}\n\\end{figure}\n\n\\end{framed}\n\n%%%%%%%%%%%%%%%%%%%%%% 4.4 %%%%%%%%%%%%%%%%%%%\n\\subsection{} You will notice that all of these approaches results in a different distribution. Which of these do you think corresponds most to our goal, which was to find the distribution of the length of a random chord.\n\\begin{framed}\n\\textbf{Solution:} Firstly, notice that in all three distributions, the maximum length of the chord is 2. This is because we testing a circle of radius 1 in all 3 of them. A circle of radius 1 has diameter 2. So, the maximum length of the chord would be 2. Similarly, the minimum length of the chord would be zero. There is no such chord with length zero. However, the histogram of part 4.1 shows that the distribution of the length of chord is such that there is some probability (greater than zero) for a chord to have zero length. So the strategy in 4.1 is perhaps not corresponding most to our goal. \\\\ \nNow we need to decide which distribution does the length of a chord follow. The distribution of the length of the chord should be such that as the length of chord increases. The probability of the length of chord also increases. Both 4.2 and 4.3 strategies satisfies this condition. \\\\\nNotice that the (almost) linear graph and the strategy employed in 4.3 implies that there exists only one chord which has a randomly chosen point as its mid point. However, this is not true. Take for example the center of the circle. There must exist infinitely many chords passing through it (i.e., through the same midpoint).So, the histogram must not be linear. By randomly selecting a $\\theta$ instead of selecting a point, we remove this problem. Thus, it is established that 4.2 corresponds most to our goal, which was to find the distribution of the length of a random chord. \\\\\n\\end{framed}\n\n%%%%%%%%%%%%%%%%%%%%% 5 %%%%%%%%%%%%%%%%%%%%%%\n\\section{Hypothesis Testing} Intuition - If someone hands you a coin, and tells you its fair, you toss it 15 times and get 15 heads, you are going to be skeptical. That is the essence of hypothesis testing, we make a certain assumption, and then sample some data. If the sum of probability of obtaining the observed data or data less or equally likely is less than a certain threshold then we conclude our assumption to be false. The statement `or data less likely' is a little vague and more importantly problem dependent. Let use look at a concrete example.\\\\\n\nSuppose you have a coin which we do not know as fair or not. We assume that the coin is fair. This is known as the null hypothesis. The alternative hypothesis is that the coin is not fair. We then set a certain threshold, and declare that given our assumption if the observed data or data less or equally likely has a total probability less than this threshold we will reject our assumption. Let us set the threshold at 0.05.\\\\\n\nWe toss the coin 15 times and obtain 15 heads. The probability of this happening given that the\ncoin is fair is $(\\frac{1}{2})^{15} \\approx 0:00003$. An event that is less or equally like is getting 15 tails, with a probability of 0.00003 as well. The cumulative of these is 0:00006 which is less than our threshold, therefore we reject the null hypothesis.\\\\\n\nSuppose instead that we had tossed the coin 10 times and obtained 2 heads, while using the threshold of 0:1. The events equally or less likely are getting 2 or less heads and 2 or less tail, the sum of whose probabilities is 0:109375, which is greater than our threshold. Therefore, we declare that the null hypothesis is valid, and an unlikely but not too unlikely possibility has occurred. \\\\\n\nIt may be argued that in the former case as well, the coin could have been fair and it was only that an unlikely possibility had occurred. The argument is valid, and when it comes to simulations, one can rectify this problem by repeating several times to obtain an expected value, and then repeating the\nentire experiment multiple times, to get a distribution of the expected values as we did in the previous questions. In real life, however, we hardly have such liberties, such as when conducting surveys, and therefore hypothesis testing remains a reliable method. Of course, we could be wrong sometimes to reject the null hypothesis but we would be right most of the time. That's just how probability works. \n\n%%%%%%%%%%%%%%%%% 5.1 %%%%%%%%%%%%%%%%\n\\subsection{} Implement a function that simulates the behavior of a fair coin, you may choose return types as you see fit. Implement another function that uses the above function to simulate 10 coin tosses multiple times and finds the expected number of times the null hypothesis is rejected even though it is true. Use the several experiments each having several iterations approach to generate a histogram of expected values. Mathematically and simulation-wise, what is the probability we will reject the null hypothesis even though it is true. Explain both approaches in your report. Use a threshold of 0:05. Reach out if you have confusions but not at the $11^{th}$ hour.\n\n\\begin{framed}\n\n\\textbf{Mathematical Calculation:\\\\} [13] [14]\n\n$P(X = x) = ^nC_r \\, p^{n - r} \\, (1 - p)^r$\\\\\\\\\n$p = \\frac{1}{2}$ ( Since it is a fair coin) \\\\\n\\underline{Probability of getting zero heads:}\\\\\n$P(H = 0) = ^{10}C_{0} \\, (0.5)^{0} \\, (0.5)^{10-0}$\\\\\n$P(H = 0) = \\frac{1}{1024} \\approx 0.0009765625$\\\\\n\\underline{Probability of getting one heads:}\\\\\n$P(H = 1) = ^{10}C_{1} \\, (0.5)^{1} \\, (0.5)^{10-1}$\\\\\n$P(H = 1) = \\frac{5}{512} \\approx 0.009765625$\\\\\n\\underline{Probability of getting two heads:}\\\\\n$P(H = 2) = ^{10}C_{2} \\, (0.5)^{2} \\, (0.5)^{10-2}$\\\\\n$P(H = 2) = \\frac{45}{1024} \\approx 0.0439453125$\\\\\n\\underline{Probability of getting three heads:}\\\\\n$P(H = 3) = ^{10}C_{3} \\, (0.5)^{3} \\, (0.5)^{10-3}$\\\\\n$P(H = 3) = \\frac{15}{128} \\approx 0.1171875  $\\\\\n\\underline{Probability of getting four heads:}\\\\\n$P(H = 4) = ^{10}C_{4} \\, (0.5)^{4} \\, (0.5)^{10-4}$\\\\\n$P(H = 4) = \\frac{105}{512} \\approx 0.205078125$\\\\\n\\underline{Probability of getting five heads:}\\\\\n$P(H = 4) = ^{10}C_{4} \\, (0.5)^{4} \\, (0.5)^{10-4}$\\\\\n$P(H = 4) = \\frac{105}{512} \\approx 0.205078125$\\\\\nNotice that asymmetrically, the number of heads whose appearance makes the probability lie outside our favourable region is 0, 1 and 2 \\\\\n$P(H = 0) + P(H = 1) + P(H = 2)$\\\\\n$= \\frac{1}{1024} + \\frac{5}{512} + \\frac{45}{1024}$\\\\\n$= 0.0546875$\\\\\\\\\nSo, the probability that we will reject the null hypothesis even though it is true is 0.0546875 \\\\\\\\\n\\textbf{Simulation:}\\\\\nThe code of simulation is given below : \\\\ \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.1_code1.PNG}\n   % \\includegraphics[width= 1 \\textwidth]{Q5.1_code2.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    % \\includegraphics[width= 1 \\textwidth]{Q5.1_code1.PNG}\n    \\includegraphics[width= 1 \\textwidth]{Q5.1_code2.PNG}\n\\end{figure}\n\n\\textbf{Histogram:}\\\\\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width=0.5 \\textwidth]{Q5.1_histogram.png}\n\\end{figure}\n\nNotice that the center of the Histogram is 0.05 which is the highest too. This verifies that our threshold is indeed the probability that we will reject the null hypothesis even though it is true. \\\\  \n\\end{framed}\n\n%%%%%%%%%%%%%%%%% 5.2 %%%%%%%%%%%%%%%%\n\\subsection{} You are out fishing. The length of fish in your fishing area follows a normal distribution. You are trying to prove or disprove what someone said to you to about the mean length of the fishes. Unfortunately, you do not have access to the lengths of every fish in the area, which would allow you to calculate the population mean and the population variance. The best you can do is to catch a small sample, find the sample mean and the sample variance, and make some simplifying assumptions. You are provided some code files which can be used in the following way to catch a single \fsh and measure its length\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2.PNG}\n\\end{figure}\n\n%%%%%%%%%%%%%%% 5.2.1 %%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{} Suppose that the mean length you have been told is 23, and the size of the sample i.e. the number of fish you decide to catch, n, is 30. You simplified your problem by stating that the means of samples follow the normal distribution with mean $u_0$ which is the population mean, and standard deviation $\\frac{\\sigma}{\\sqrt{n}}$, where $\\sigma$ is the standard deviation of your sample, and n the size of your sample.\\\\\n\\begin{equation}\n    S \\sim N ( u_0 , ( \\frac{ sigma }{\\sqrt{n}} ) ^ 2 ) \n\\end{equation}\nYou may start of by declaring that the null hypothesis is that the population mean, $u_0$, is exactly 23. Conduct hypothesis testing several times with a threshold of 0.05. Measure the proportion / expected number of times, the null hypothesis is rejected. Conduct the experiment several times to and several values of this proportion. Plot these as a histogram. \\\\\nImplement a function that takes in $u_0$ and $n$ and conducts a single hypothesis test and returns its result. A single hypothesis test here constitutes catching a sample of 30 fish, finding the sample mean, u, the sample variance $\\sigma$, and using the above specified normal distribution with the population mean, $u_0$, as 23, assumed through the null hypothesis, to find the probability of obtaining the sample mean or a mean with an absolute difference greater or equal to $|u - u_0|$. Mathematically, if $a = |u - u_0|$ then the null hypothesis is rejected if \\\\ \n\\begin{equation}\n    P(|S - u_0| \\geq a) < Threshold \n\\end{equation}\nImplement another function that utilizes the above function or otherwise, performs several experiments, each with several hypothesis tests and plots a histogram of the proportion of times the null hypothesis is rejected. \\\\\nComment on whether it would have been sufficient to accept or reject the null hypothesis based on a single hypothesis test \\\\\n\\begin{framed}\n\nIn the first part of the question we are asked to find the proportion of the number of times the null hypothesis is rejected. So lets do that first! \\\\\nLet the null hypothesis $H_0$ and the alternate hypothesis $H_1$ be as follows : \\\\\n$H_0$: Population mean is exactly 23 \\\\\n$H_1$: Population mean is not equal to 23 \\\\\nThreshold = 0.05\\\\\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2_code_1.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2_code_2.PNG}\n\\end{figure}\n    \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.2_histogram_1.png}\n\\end{figure}\n\nComment: The the null hypothesis is rejected since the mean expected value of the number of times it was rejected was 0.96 \\\\\n\nIn the second part of the question we have to implement single hypothesis test. Before coding, let us first look into some basic computations: \\\\ \nWe have to find $P( | S  - u_0 | \\geq a )$ and then compare it with the threshold. \\\\\n$P( | S  - u_0 | \\geq a )$ where $a = | u - u_0|$ \\\\\n$= 1 - P( | S  - u_0 | < a )$\\\\\n$= 1 - P( - a < S - u_0 < a)$\\\\\n$= 1 - (P(S - u_0 < a) -  P(S - u_0 < -a))$\\\\\n$= 1 - P(S - u_0 < a) +  P(S - u_0 < -a)$\\\\\n$= (1 - P(S - u_0 < a)) +  P(S - u_0 < -a)$\\\\\n$=  P(S - u_0 \\geq a) +  P(S - u_0 < -a)$\\\\\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2_code_3.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2_code_4.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.2_histogram_2.png}\n\\end{figure}\n\n\\textbf{Comment:}\nThe mean of the expected number of times the null hypothesis was rejected was approximately 0.96.\\\\\\\\ Based on only one such hypothesis test we cannot tell whether out null hypothesis is True or not since there is a probability of 0.05 that we will reject the null hypothesis even though it is True (as found in 5.1). Therefore, to remove to reduce the chances of obtaining incorrect results regarding the correctness or incorrectness of the null hypothesis and to declare whether we accept or reject the null hypothesis we have to perform the hypothesis test many times. \n\\end{framed}\n\n%%%%%%%%%%%%% 5.2.2 %%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{} Conduct the same experiments with same u0 and n = 70. Implement a different function for this and generate a similar histogram plot of proportion of times the null hypothesis is rejected.\\\\\nComment on what increasing the value of n accomplishes and whether it would have been sufficient to accept or reject the null hypothesis based on a single hypothesis test in this case.\n\\begin{framed}\n    \n\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2.2_code_1.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2.2_code_2.PNG}\n\\end{figure}\n    \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.2.2_histogram.png}\n\\end{figure}\n\\textbf{Comment:}\\\\\nNote that in part 5.2.1 since the mean of this bell shaped curve is approximately 0.97, therefore, we can conclude that the portion/ expected number of times the null hypothesis is rejected is 0.97. \\\\\nAs the sample size increased in this part, the probability that we will accept a False null hypothesis will decrease. \n[15] So it is sufficient to reject the NULL hypothesis, However, we can still reject a True Null Hypothesis, [15]. So it is still not sufficient to accept the NULL Hypothesis. Note that the expected number of times the null hypothesis is rejected is approximately 1 when $n = 70$. So, we can certainly reject the null hypothesis. \\\\\n\\end{framed}\n\n%%%%%%%%%%%%%% 5.2.3 %%%%%%%%%%%%%%%%%%\n\\subsubsection{} In 5.1 we saw that proportion of times the null hypothesis is rejected despite being true is close to\nthe threshold we choose. In normal distributions it is exactly equal to the threshold. Experimentally or mathematically, determine the least value of $n$ (or close enough) to ensure that the null hypothesis is not wrongly rejected more than 10 percent of the time. You may use a sample standard deviation\nof 3, if you decide to approach mathematically. If you decide to approach simulation wise you will have to define your own fish function which returns a random variable from the normal distribution\n\\begin{framed}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2.3_code1.PNG}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 1 \\textwidth]{Q5.2.3_code2.PNG}\n    \\caption{Code with which we have tested different n values }\n\\end{figure}\n\n\n    \n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.3_n=9.png}\n    \\caption{n = 9}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.3_n=10.png}\n    \\caption{n = 10}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.3_n=11.png}\n    \\caption{n = 11}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.3_n=20.png}\n    \\caption{n = 20}\n\\end{figure}\n\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.3_n=29.png}\n    \\caption{n = 29, bin = 50}\n\\end{figure}\n\n\\begin{figure}[H] % fig \n    \\centering\n    \\includegraphics[width= 0.5 \\textwidth]{Q5.3_n=30.png}\n    \\caption{n = 30, bin = 50}\n\\end{figure}\n\nAnswer: n = 30 is the minimum n \n\n\n\\end{framed}\n\\section{References:}\n\\begin{framed}\n\\begin{thebibliography}{9}\n\\bibitem{ref1}“Generating Random Variables from Standard Uniform Distribution on $(1,0)$.” Mathematics Stack Exchange, 1 Aug. 1961, math.stackexchange.com/questions/241525/generating\n-random-variables-from-standard-uniform-distribution-on-1-0. \\\\ \n\\bibitem{ref2}“Numpy.linspace” Numpy.linspace - NumPy v1.20 Manual, numpy.org/doc/stable/reference/\ngenerated/numpy.linspace.html.\\\\ \n\\bibitem{ref3}“Histograms Review (Article).” Khan Academy, Khan Academy, www.khanacademy.org/math\n/statistics-probability/displaying-describing-data/quantitative-data-graphs/a/histograms-review$\\#:\\sim:$text=A$\\%20histogram\\%20displays\\%20numerical\\%20data,\\%22\\%2C\\%20or\\%20\\%22buckets\\\\\\%22.$ \\\\\n\\bibitem{ref4}\"How to Choose Bins in Matplotlib Histogram.\"Stack Overflow, 1 Aug. 1964, stackoverflow.com/questions/33458566/how-to-choose-bins-in-matplotlib-histogram/33459231.\\\\\n\\bibitem{ref5}“More Precise Histogram in Python.” Stack Overflow, 1 Sept. 1968, stackoverflow.com/questions/59226828/more-precise-histogram-in-python.\\\\\n\\bibitem{ref6}gtribello. “Generating Uniform Continuous Random Variables Using Python.” YouTube, YouTube, 6 Aug. 2020, www.youtube.com/watch?v=0ydYnya\\_wIo.\\\\\n\\bibitem{ref7}gtribello. “Estimating the Probability Density Function by Calculating a Histogram.” YouTube, YouTube, 18 Aug. 2020, www.youtube.com/watch?v=-aS\\_CrskEYE.\\\\\n\\bibitem{ref8}“Law of Cosines Calculator.” Omni Calculator, Omni Calculator, 4 Dec. 2020, www.omnicalculator.com/math/law-of-cosines. \\\\\n\\bibitem{ref9}https://www.quora.com/A-point-is-selected-randomly-from-the-interior-of-a-circle-\nThe-probability-that-the-point-is-closer-to-the-center-than-the-boundary-of-circle-is\\\\\n\\bibitem{ref10}Data to Fish,datatofish.com/plot-histogram-python/. \\\\\n\\bibitem{ref11}MIT, web.mit.edu/urban\\_or\\_book/www/book/chapter7/7.1.3.html.\\\\\n\\bibitem{ref12}jaradniemi. “Inverse CDF Method.” YouTube, YouTube, 1 Mar. 2013, www.youtube.com/watch?v=TR0biDues7k.\\\\\n\\bibitem{ref13} https://stats.stackexchange.com/questions/348807/find-probability-of-rejecting-a-true-null-hypothesis\\\\\n\\bibitem{ref14} https://www.csus.edu/indiv/j/jgehrman/courses/stat50/hypthesistests/9hyptest.html \\\\\n\\bibitem{ref15}https://www.bmj.com/content/349/bmj.g4287/rr\n\\end{thebibliography}\n\\end{framed}\n\\end{document}", "meta": {"hexsha": "dbe4b51edfc460ee3e43cbf32ac6eb5d998556bd", "size": 53744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project/main.tex", "max_stars_repo_name": "AlishaMomin/Random-Walk-Probability-and-Statistic-", "max_stars_repo_head_hexsha": "e9f71dacc1698a5d16a38d964c1ab717f1b50da1", "max_stars_repo_licenses": ["MIT"], "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/main.tex", "max_issues_repo_name": "AlishaMomin/Random-Walk-Probability-and-Statistic-", "max_issues_repo_head_hexsha": "e9f71dacc1698a5d16a38d964c1ab717f1b50da1", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "AlishaMomin/Random-Walk-Probability-and-Statistic-", "max_forks_repo_head_hexsha": "e9f71dacc1698a5d16a38d964c1ab717f1b50da1", "max_forks_repo_licenses": ["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.672489083, "max_line_length": 1072, "alphanum_fraction": 0.6972685323, "num_tokens": 16070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.678561485762006}}
{"text": "\\subsection{Example Model: Analytic Bateman}\\label{sec:analyticalbateman}\nThis section is intended for the new users to familiarize them with how to perform their studies through RAVEN.\nA simple example, conventionally called \\textbf{AnalyticBateman}, has been developed. It solves a system of\nordinary differential equations (ODEs), of the form:\n\n\\begin{equation}\n\\begin{dcases}\n\\frac{\\mathrm{d} \\mathbf{X}}{\\mathrm{d} t} = \\mathbf{S}-\\mathbf{L} \\\\\n \\mathbf{X}(t=0)= \\mathbf{X_{0}}\n\\end{dcases}\n\\end{equation}\n   where:\n  \\begin{itemize}\n     \\item $\\mathbf{X_{0}}$, initial conditions\n     \\item $\\mathbf{S}$, source terms\n     \\item $\\mathbf{L}$, loss terms\n   \\end{itemize}\n\nFor example, this  code is able to solve a system of two ODEs as follows:\n\\begin{equation}\n  \\begin{dcases}\n    \\frac{\\mathrm{d} x_{1}}{\\mathrm{d} t} = \\phi (t)\\times \\sigma_{x_{1}}-\\lambda_{x_{1}}\\times x_{1}(t) \\\\\n    \\frac{\\mathrm{d} x_{2}}{\\mathrm{d} t} = \\phi (t)\\times \\sigma_{x_{2}}-\\lambda_{x_{2}} \\times x_{2}(t) + x_{1}(t)\\times\\lambda_{x_{1}} \\\\\n    x_{1}(t=0)= x_{1}^{0} \\\\\n    x_{2}(t=0)= 0.0\n  \\end{dcases}\n\\end{equation}\n\nThe input of the \\textbf{AnalyticBateman} code is in XML format.\nFor example, the following is the reference input for a system of 4 Ordinary Differential Equations (ODEs)\nthat is going to be used for as an example in this guide. All the files required for this system are  located at\n``\\textit{raven/tests/framework/user\\textunderscore guide/physicalCode}''. \n\n\\xmlExample{framework/user_guide/physicalCode/analyticalbateman/Input.xml}{AnalyticalBateman}\nThe code outputs the time evolution of the 4 variables ($A,B,C,D$) in a CSV file, producing the following output:\n\\begin{table}[ht]\n\\centering\n\\caption{Reference case sample results.}\n\\label{referenceResults}\n\\begin{tabular}{lllll}\n\\textbf{time} & \\textbf{A}     & \\textbf{C}     & \\textbf{B}    & \\textbf{D}     \\\\\n0                  & 1.0                       & 1.0                       & 1.0                     & 1.0           \\\\\n2880000.0   & 0.983434738239 & 0.977851848235 & 1.01011506729 & 1.01013172275 \\\\\n5760000.0   & 0.967143884376 & 0.956202457404 & 1.01936231677 & 1.02036100400   \\\\\n8640000.0   & 0.951122892771 & 0.935040450532 & 1.02777406275 & 1.03067925987 \\\\\n10368000.0 & 0.941637968936 & 0.922572556179 & 1.03243314106 & 1.03690947068 \\\\\n12096000.0 & 0.932247632016 & 0.910273757371 & 1.03680933440 & 1.04316700086 \\\\\n13824000.0 & 0.922950938758 & 0.898141730426 & 1.04090912054 & 1.04945015916 \\\\\n15552000.0 & 0.913746955315 & 0.886174183908 & 1.04473885709 & 1.05575729317 \\\\\n17280000.0 & 0.904634757153 & 0.874368858183 & 1.04830478357 & 1.06208678854 \\\\\n20736000.0 & 0.886682064542 & 0.851235986899 & 1.05466958557 & 1.07480659230  \\\\\n24192000.0 & 0.869085647400 & 0.828725658721 & 1.06005115510 & 1.08759739100   \\\\\n27648000.0 & 0.851838435355 & 0.806820896763 & 1.06449535534 & 1.10044757060  \\\\\n31104000.0 & 0.834933498348 & 0.785505191756 & 1.06804634347 & 1.11334606143 \\\\\n34560000.0 & 0.818364043850 & 0.764762489077 & 1.07074662835 & 1.12628231792\n\\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "6acbbb9109674aa5bc9479364fd960b71051664f", "size": 3080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_guide/exampleDescription.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_guide/exampleDescription.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_guide/exampleDescription.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": 53.1034482759, "max_line_length": 140, "alphanum_fraction": 0.6863636364, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6785529223288113}}
{"text": "\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\\newcommand{\\F}{\\mathbb{F}}\n\\newcommand{\\rcl}[2]{{{[#1]}_{#2}}}\n\\newcommand{\\modulo}[3]{#1\\equiv #3(\\bmod\\, #2)}\n\\newcommand\\inv[1]{{{#1}^{-1}}}\n\\newcommand\\ftwox{{ \\F_2[x]}}\n\\newcommand\\ftwoxpx{{ \\F_2[x]/p(x)}}\n\\newcommand\\ftwoeight{{ \\F_{2^8}}}\n\\newcommand\\cto{\\longrightarrow}\n\\newcommand\\EA{\\mathbf{E_A}}\n\\newcommand\\EB{\\mathbf{E_B}}\n\\newcommand\\EK{\\mathbf{E_K}}\n\\newcommand\\EM{\\mathbf{E_M}}\n\n\\newcommand\\Zpstar{{ \\Z_p^*}}\n\\newcommand\\Znstar{{ \\Z_n^*}}\n\\newcommand\\xor{{\\oplus}}\n\\newcommand{\\set}[1]{\\{#1\\}}\n\n\n\\def\\EXN{3}\n\\def\\DATE{\\Week\\EXN}\n\n%%%\\ifHandout\n\n\\ifText \\NoHead \\summary{Block Ciphers continued --- AES (Rijndael) --- AACS --- Finite\n  Fields --- Revision: Matrix Arithmetic}\n\n\n\n\\subsubsection{AES (Rijndael)}\n\n\\myglos{AES}{The advanced encryption standard that is the successor of DES.}\n\\myglos{Rijndael}{The original name of AES.}  The \\emph{advanced encryption\n  standard} (AES) is the successor of the outdated DES. It was developed by the\ntwo Belgian cryptographers Joan Daemen and Vincent Rijmen. It was originally\nnamed \\emph{Rijndael}, but renamed to AES when it was adopted as official US\nstandard in November 2001. Rijndael is a block cipher, however, it does not rely\non the basic design of the Feistel cipher. In particular is has distinct\nencryption and decryption algorithms. But similar to DES, it is round based and\nrelies on a combination of substitutions, permutations and key addition. AES is\nmotivated by arithmetic operations in the field $\\F_{2^8}$, and its\nimplementation in hardware and software is compact and fast.\n\nRijndael is parameterisable in that it can work with:\n\\begin{itemize}\n\\item block sizes of 128, 192, and 256 bits,\n\\item key sizes of 128, 192, and 256 bits, and\n\\item 10, 12, or 14 rounds of encryption.\n\\end{itemize}\n\nRijndael performs encryption, decryption and computes the key schedule using\narithmetic in $\\F_{2^8}$ with respect to the irreducible polynomial\n$p(x)=x^8+x^4+x^3+x+1$. That is, $\\F_{2^8}=\\F_{2}[x]/(x^8+x^4+x^3+x+1)$.\n\n\\myitem{Operation of AES}\n\nWe will discuss the basic operations of Rijndael for the case of $128$ bit block\nand key size and $10$ rounds of encryption. Rijndael arranges both message and\nkey in $4\\times4$ matrices of $8$-bit elements, i.e., each element is exactly\none byte and each column and each row contain $32$-bit words. \n\nIf $m=m_0\\|m_1\\|\\ldots\\|m_{15}$ is the message, then Rijndael initialises the so\ncalled \\emph{state matrix} $A$ as follows:\n\\[\n\\begin{bmatrix}\n  m_0 & m_4 & m_8 & m_{12}\\\\\n  m_1 & m_5 & m_9 & m_{13}\\\\\n  m_2 & m_6 & m_{10} & m_{14}\\\\\n  m_3 & m_7 & m_{11} & m_{15}\\\\\n\\end{bmatrix}\\longrightarrow\nA=\n\\begin{bmatrix}\n  a_{0,0} & a_{0,1} & a_{0,2} & a_{0,3}\\\\\n  a_{1,0} & a_{1,1} & a_{1,2} & a_{1,3}\\\\\n  a_{2,0} & a_{2,1} & a_{2,2} & a_{2,3}\\\\\n  a_{3,0} & a_{3,1} & a_{3,2} & a_{3,3}\\\\\n\\end{bmatrix}\n\\]\n\nEach round applies the following manipulations to the state matrix:\n\\begin{enumerate}\n\\item a substitution operation on every single byte \\textit{SubBytes},\n\\item a byte permutation \\textit{ShiftRows},\n\\item a column manipulation \\textit{MixColumns},\n\\item and an xor of the state with the round key \\textit{AddRoundKey}.\n\\end{enumerate}\nAn exception is the last round, where the \\textit{MixColumns} operation is\nskipped. \n\nFor each of these operations, except for \\textit{AddRoundKey}, we need\ncorresponding inverse operations for the decryption. Here is an overview of the\nencryption and decryption algorithms:\n\n\\begin{minipage}{.5\\textwidth}\n  $E_K(M)$\n  \\begin{tabbing}\n    $A := M$\\\\\n    $A :=$ AddRoundKey($A$, $K_0$)\\\\\n    \\textbf{for} \\=$i$ = 1 \\textbf{to} 9 \\textbf{do}\\\\\n    \\>$A :=$ SubBytes($A$)\\\\\n    \\>$A :=$ ShiftRows($A$)\\\\\n    \\>$A :=$ MixColumns($A$)\\\\\n    \\>$A :=$ AddRoundKey($A$, $K_i$)\\\\\n    \\textbf{end}\\\\\n    $A :=$ SubBytes($A$)\\\\\n    $A :=$ ShiftRows($A$)\\\\\n    $A :=$ AddRoundKey($A$, $K_{10}$)\\\\\n    $C := A$ \n\\end{tabbing}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n$D_K(C)$\n  \\begin{tabbing}\n    $A := C$\\\\\n    $A :=$ AddRoundKey($A$, $K_{10}$)\\\\\n    $A :=$ InverseShiftRows($A$)\\\\\n    $A :=$ InverseSubBytes($A$)\\\\\n    \\textbf{for} \\=$i$ = 9 \\textbf{downto} 1 \\textbf{do}\\\\\n    \\>$A :=$ AddRoundKey($A$, $K_i$)\\\\\n    \\>$A :=$ InverseMixColumns($A$)\\\\\n    \\>$A :=$ InverseShiftRows($A$)\\\\\n    \\>$A :=$ InverseSubBytes($A$)\\\\\n    \\textbf{end}\\\\\n    $A :=$ AddRoundKey($A$, $K_0$)\\\\\n    $M := A$ \n  \\end{tabbing}\n\\end{minipage}\n\nHere are the single operations in detail.  \n\n\\textit{1. SubBytes:} \\myglos{SubBytes}{An S-Box like substitution operation\n  used during AES encryption.}  This operation is similar to the S-Box\nsubstitution of DES. Each byte $a_{i,j}$ of the state is substituted by the\noutput of a single S-Box.  This S-Box corresponds to an algebraic operation in\nRijndael's finite field $\\ftwoeight$. Each byte $a_{i,j}=[z_7,\\ldots,z_0]$ is\nconsidered as a polynomial in $\\ftwoeight$. Its substitution is then computed in\ntwo steps:\n\\begin{enumerate}\n\\item First we compute the multiplicative inverse of $a_{i,j}$ in $\\ftwoeight$\n  to get $\\inv{a_{i,j}}=[x_7,\\ldots, x_0]$. (The zero element is mapped to\n  $[0,\\ldots,0]$.)\n\\item We then compute a new bit vector $b_{i,j}=[y_7,\\ldots,y_0]$ with the\n  following transformation in $\\F_2$ (observe that the vector addition is the\n  same as an xor $\\xor$):\n  \\[\\begin{bmatrix}y_0\\\\y_1\\\\y_2\\\\y_3\\\\y_4\\\\y_5\\\\y_6\\\\y_7\\end{bmatrix} =\n  \\begin{bmatrix} 1&0&0&0&1&1&1&1 \\\\ 1&1&0&0&0&1&1&1 \\\\ 1&1&1&0&0&0&1&1 \\\\ \n    1&1&1&1&0&0&0&1 \\\\ 1&1&1&1&1&0&0&0 \\\\ 0&1&1&1&1&1&0&0 \\\\ 0&0&1&1&1&1&1&0 \\\\ \n    0&0&0&1&1&1&1&1\\end{bmatrix}\\cdot\n  \\begin{bmatrix}x_0\\\\x_1\\\\x_2\\\\x_3\\\\x_4\\\\x_5\\\\x_6\\\\x_7\\end{bmatrix} +\n  \\begin{bmatrix}0\\\\1\\\\1\\\\0\\\\0\\\\0\\\\1\\\\1\\end{bmatrix} \\]\n\\end{enumerate}\nThe substitution can be schematically displayed as:\n\n% [[ 1,0,0,0,1,1,1,1],[1,1,0,0,0,1,1,1],[1,1,1,0,0,0,1,1],[\n%   1,1,1,1,0,0,0,1],[1,1,1,1,1,0,0,0],[0,1,1,1,1,1,0,0],[0,0,1,1,1,1,1,0],[\n%   0,0,0,1,1,1,1,1]]\n\n\\begin{center}\n  \\includegraphics[height=5cm]{AES-SubBytes}\n  \\rput[b]{90}(0,2){\\tiny Source: Wikipedia}%, \\url{http://en.wikipedia.org/wiki/Feistel_cipher}}\n\\end{center}\n\nFor the decryption algorithm we can define an inverse operation\n\\textit{InverseSubBytes} by first reversing the transformation:\n\\myglos{InverseSubBytes}{An S-Box like substitution algorithm used during AES\n  decryption. The inverse of SubBytes.}\n\n\\[\\begin{bmatrix}x_0\\\\x_1\\\\x_2\\\\x_3\\\\x_4\\\\x_5\\\\x_6\\\\x_7\\end{bmatrix} =\n\\begin{bmatrix} 0&0&1&0&0&1&0&1\\\\ 1&0&0&1&0&0&1&0\\\\ 0&1&0&0&1&\n0&0&1\\\\ 1&0&1&0&0&1&0&0\\\\ 0&1&0&1&0&0&1&0\\\\ 0&0&1&0&1&0&0&1\\\\ \n1&0&0&1&0&1&0&0\\\\ 0&1&0&0&1&0&1&0\n\\end{bmatrix}\n\\left(\\begin{bmatrix}y_0\\\\y_1\\\\y_2\\\\y_3\\\\y_4\\\\y_5\\\\y_6\\\\y_7\\end{bmatrix} +\n  \\begin{bmatrix}0\\\\1\\\\1\\\\0\\\\0\\\\0\\\\1\\\\1\\end{bmatrix}\\right) \\] and then\ncomputing the multiplicative inverse of $[x_7,\\ldots, x_0]$ in $\\ftwoeight$.\n\n\n\\textit{2. ShiftRows:} This operation performs a cyclic shift on the state\nmatrix by shifting each row separately.  This ensures that the columns of the\nstate matrix interact over several rounds of encryption. The lower three rows\nare shifted by one, two, and three positions, respectively: \\myglos{ShiftRows}{A\n  byte permutation used during AES encryption.}  \\myglos{InverseShiftRows}{A\n  byte permutation used during AES decryption. Inverse of Shift Rows.}\n\\begin{center}\n  \\includegraphics[width=.65\\textwidth]{AES-ShiftRows}\n  \\rput[b]{90}(0,2){\\tiny Source: Wikipedia}%, \\url{http://en.wikipedia.org/wiki/Feistel_cipher}}\n\\end{center}\n  For the decryption the \\textit{InverseShiftRows}\ndoes the reverse shift.%\\pagebreak\n\n\\textit{3. MixColumns:} \\myglos{MixColumns}{A column manipulation operations\n  used during AES encryption.}  \\myglos{InverseMixColumns}{A column manipulation\n  operations used during AES decryption. Inverse of MixColumns.}  This operation\nensure interaction of the rows of the state matrix by mixing each column\nseparately. For this it performs the following matrix multiplication for each\ncolumn $i=1,2,3,4$ over $\\ftwoeight$, where the entries of the matrix are\nhexadecimal representations of polynomials of degree $7$ (e.g. $0x03$ corresponds\nto $x+1$.)\n\\[\\begin{bmatrix}b_{0,i}\\\\b_{1,i}\\\\b_{2,i}\\\\b_{3,i}\\end{bmatrix}=\n\\begin{bmatrix} 0x02&0x03&0x01&0x01 \\\\ 0x01&0x02&0x03&0x01 \\\\ \n  0x01&0x01&0x02&0x03 \\\\ 0x03&0x01&0x01&0x02 \\end{bmatrix}\\cdot\n\\begin{bmatrix}a_{0,i}\\\\a_{1,i}\\\\a_{2,i}\\\\a_{3,i}\\end{bmatrix}\\] This operation\nactually corresponds to a polynomial multiplication in $\\ftwoeight[x]/(x^4+1)$,\nthe ring of polynomials whose coefficient are in $\\ftwoeight$, i.e., they are\npolynomials themselves. Observe that $x^4+1$ is not irreducible in $\\ftwoeight$\nand therefore $\\ftwoeight[x]/(x^4+1)$ is indeed a ring not a field.\n\n\\[a(x)\\cdot c(x)=(a_3x^3+a_2x^2+a_1x+a_0)\\cdot (0x03x^3+0x01x^2+0x01x+0x02)\n({\\bmod}\\; x^4+1)\\] We can picture\n\\textit{MixColumns} as\n\\begin{center}\n  \\includegraphics[width=.6\\textwidth]{AES-MixColumns}\n  \\rput[b]{90}(0,2){\\tiny Source: Wikipedia}%, \\url{http://en.wikipedia.org/wiki/Feistel_cipher}}\n\\end{center}\nThe inverse operation \\textit{InverseMixColumns} is then simply the\nmultiplication with $\\inv{c(x)}$, which has an inverse in the ring\n$\\ftwoeight[x]/(x^4+1)$.\n\n\n\\textit{4. AddRoundKey:} \\myglos{AddRoundKey}{The round key addition operation\n  used during AES encryption and decryption.}  As mentioned earlier, the key\nsize of AES is $128$ bits. All the round keys $K_0,\\ldots,K_{10}$ derived from\nthe key $K$ are also $128$ bits and can therefore be expressed as a $4\\times4$\nmatrix:\n\\[\nK_i=\n\\begin{bmatrix}\n  k_{0,0} & k_{0,1} & k_{0,2} & k_{0,3}\\\\\n  k_{1,0} & k_{1,1} & k_{1,2} & k_{1,3}\\\\\n  k_{2,0} & k_{2,1} & k_{2,2} & k_{2,3}\\\\\n  k_{3,0} & k_{3,1} & k_{3,2} & k_{3,3}\\\\\n\\end{bmatrix}\n\\]\nAdding the round key is simply the xor-ing of the state matrix and the round key\nmatrix byte by byte: $A\\xor K_i$. The inverse of this operation is obviously the\nsame and we do not need a special operation for the decryption.\n\n\\begin{center}\n  \\includegraphics[width=.5\\textwidth]{AES-AddRoundKey}\n  \\rput[b]{90}(0,2){\\tiny Source: Wikipedia}%, \\url{http://en.wikipedia.org/wiki/Feistel_cipher}}\n\\end{center}\n\n\n\\myitem{Key Schedule of AES}\n\nThe round keys $K_0,\\ldots,K_{10}$ are derived from the key $K$. Since $K$ is\n$128$ bits we can divide it into 4 words of $32$ bits each:\n$K=W_0\\|W_1\\|W_2\\|W_3$, which also corresponds to round key $K_0$. All\nsubsequent round keys $K_i=W_{4i}\\|W_{4i+1}\\|W_{4i+2}\\|W_{4i+3}$ are then\ncomputed using an $8$ bit left rotation, an S-Box substitution with the\n\\textit{SubBytes} function, and a scrambling sequence, which is started with a\nround constant $RC_i$ that is computed in $\\ftwoeight$ by \\[{RC_i}=x^i\n({\\bmod}\\; x^8+x^4+x^3+x+1).\\] The algorithm then looks like this:\n\\begin{center}\n  \\begin{minipage}{1.0\\linewidth}\n    \\begin{tabbing}\n      KeySchedule($K$)\\\\[.2cm]\n      $W_0\\|W_1\\|W_2\\|W_3 := K$\\\\\n      \\textbf{for} \\=$i$ := 1 \\textbf{to} 10 \\textbf{do}\\\\\n      \\>$T := W_{4i-1}\\lll 8$\\\\\n      \\>$T :=$ SubBytes($T$)\\\\\n      \\>$T := T \\xor RC_i$\\\\\n      \\>$W_{4i} := W_{4i-4} \\xor T$\\\\\n      \\>$W_{4i+1} := W_{4i-3} \\xor W_{4i}$\\\\\n      \\>$W_{4i+2} := W_{4i-2} \\xor W_{4i+1}$\\\\\n      \\>$W_{4i+3} := W_{4i-1} \\xor W_{4i+2}$\\\\\n      \\textbf{end}\n    \\end{tabbing}\n  \\end{minipage}\n\\end{center}\n\nNote that \\textit{SubBytes} is applied to the four $8$ bit bytes of the $32$ bit\nword $T$ individually.\n\n\\newpage\n\\subsubsection{AACS --- Advanced Access Content System}\n\nThe Advanced Access Content System (AACS) is a Digital Rights Management system\nfor HD-DVD and Blu-Ray Discs developed by a consortium that includes Disney,\nIntel, Microsoft, Matsushita (Panasonic), Warner Brothers, IBM, Toshiba, and\nSony. The general idea of Digital Rights Management (DRM) is to restrict access\ncontrol to electronic media and playback devices to retain full control by the\ncopyright owner. We first give a brief overview of AACS and then dicuss some of\nthe issues arising from AACS and DRM in general.\n\n\\myglos{DRM}{Short for Digital Rights Management}\n\\myglos{Digital Rights Management}{Access control technologies that limit usage of digital media or devices.}\n\\myglos{AACS}{Short for Advanced Access Content System}\n\\myglos{Advanced Access Content System}{A Digital Rights Management system for HD-DVDs and Blue-Ray Discs}\n\n\\myitem{Overview} AACS uses encryption, hash functions, and watermarking schemes\nbased on AES. Exact specifications for parts of the technology are published by\nthe AACS licensing authority at \\url{http://www.aacsla.com}. Below is a\nschematic overview of the mechanism of AACS.\n\n\\begin{minipage}{.5\\linewidth}\n  The content of a disc is encrypted with AES using a collection of \\emph{title\n    keys}. The encrypted content, together with the encrypted title keys, a\n  \\emph{media key block (MKB)}, and the \\emph{unique disc ID} are all stored on\n  the disc.\n\n  An AACS encrypted disc can only be accessed with a fully licensed player. Each\n  licensed player gets a unique set of \\emph{device keys} as well as a unique\n  \\emph{Host Private Key}. The latter makes it possible that particular playback\n  devices or programmes can be individually revoked.\n\n  The device keys are used to compute a key from the MKB. The host private key\n  is needed to retrieve the disc ID. Both values are then processed by an\n  AES-based one-way function, AES-G.  (One-way functions are functions easy to\n  compute, but infeasible to invert. We will discuss one-way functions in more\n  detail later in the lecture.)\n\\end{minipage}\n\\begin{minipage}{.5\\linewidth}\n  \\begin{center}\n    \\includegraphics[height=9cm]{AACS-Simple}\n    \\rput[b]{90}(0,2){\\tiny Source:\n      arstechnica.com}%, \\url{http://en.wikipedia.org/wiki/Feistel_cipher}}\n  \\end{center}\n\\end{minipage}\nThe result of AES-G is then used to decrypt the title keys, which in turn are \nused to finally decrypt the content.\n\n\\myitem{Security Issues}\n\nHere are some of the security requirements for AACS implementations to ensure\nDRM requirements:\n\\begin{itemize}\\itemsep0pt\n\\item The content should ``not be present on any User-Accessible Bus in analog\n  or unencrypted, compressed form'', because users could possibly record or\n  redirect that content.\n\\item Implementations must use ``encryption, execution of a portion of the\n  implementation in ring zero or supervisor mode (i.e., in kernel mode), and/or\n  embodiment in a secure physical implementation,'' to keep encryption keys\n  secret at all times.\n\\item They must also use ``techniques of obfuscation clearly designed to\n  effectively disguise and hamper attempts to discover the approaches used''.\n\\end{itemize}\nThus, video content must travel through the system encrypted and must only\ninteract with authorized components over authorized pathways.\n\nFor example in Windows Vista AACS is implemented via the Protected Video Path\n(PVP), which stops DRM-restricted content from playing while unsigned software\nis running in order to prevent the unsigned software from accessing the\ncontent. Additionally, PVP can encrypt information during transmission to the\nmonitor or the graphics card, which makes it more difficult to make unauthorized\nrecordings. In other word, you cannot watch a video, while running your own\nprogrammes.\n\\newpage\n\n\\myitem{Legal and Ethical Issues}\n\nIt is obvious that to fully comply with the DRM requirement specification, AACS\nhas to be deeply embedded into an operating system. This essentially rules out\nany open source implementation of the AACS as the algorithms to decrypt keys\nwould be easily accessible and therefore security would be compromised. But even\nif only proprietary implementations are licensed and allowed, any Operating\nSystem can (at least theoretically) be emulated by a virtual machine. But\nrunning an AACS compliant software player on the VR would give access to the\nunsecured data streams. This has indeed already been done:\n\nIn December 2006 the first software was announced and subsequently published\nthat enables to backup AACS encrypted content. In order to keep the software\nlegal, it cannot actually be used on its own, but an appropriate key must be\nsupplied manually. Since extracting a key without license would be illegal, 128\nbit keys were quickly made available throughout the Internet. The AACS licensing\nagency tried to put a stop to this by suing websites publishing keys as well as\nby revoking keys (in particular for Windows based software like WinDVD).\nHowever, the more they sued, the more keys were published, etc.\n\nThe issue remains unsolved to date, in particular since much is a legal grey\narea.  Some of the issues of DRM highlighted by this controversy are:\n\\begin{itemize}\n\\item The AACS licensing agency argued that publishing the keys is illegal since\n  they would fall under their software patent.  However, is it possible to\n  patent single 128-bit numbers? And if so, in which form? Only the hexadecimal\n  representation, or all other representations as well, i.e. decimal, binary,\n  octal, sum of two or several values, etc.?  AACS can be used with millions\n  of keys. Are they all patented? Can I be sued if I use one, publish one, etc.\n\\item Under the laws of many countries making one backup of media content is\n  legal. AACS however effectively prevents this.\n\\item AACS protected media can only be played on specially licensed devises, not\n  necessarily on the playback devise of my choice.  In other words, although I\n  own the content of the disc (not the Copyright!) I can not play it the way I\n  want to.\n\n  As a comparison: If I buy a bottle of Coke, I am not allowed to reproduce its\n  content, as it is a patented formula. However, no-one can force me to only\n  drink it out of a particular licensed glass.\n\\item The DRM requirements of AACS can only be realised when fully embedded into\n  the operating system. In order not to compromise security (and thus violate\n  the licensing terms) information on the embedding cannot be made public or\n  even given to competitors.  However, this amounts essentially to a similar\n  controversy that has led to anti-trust law suits, by companies like Netscape,\n  RealPlayer etc, against Microsoft.\n\\end{itemize}\nThese are just some issues. There are plenty more\\ldots\n\n\\endText\n\n\\ifText\n\\ExHead{\\EXN}\\HandIn{18 October, 14pm}\n\n\\begin{enumerate}%%\\setcounter{enumi}{0}\\itemsep0pt\n\\ResumeExercises\n\\EX{EXmcw}{8+8}\n\\EX{EXmcp}{6+6+8}\n\\StoreExercises\n\\end{enumerate}\n\\fi\n\n\\ifSolution\n\\beginSolution\n\\SolHead{\\EXN}{21 October}\n\\begin{enumerate}%\\setcounter{enumi}{0}\\itemsep0pt\n  \\ResumeSolutions\n  \\SOL{EXmcw}\n  \\SOL{EXmcp}\n  \\StoreSolutions\n\\end{enumerate}\n\\endSolution\n\\fi\n\n\n\\ifMaths\\beginMaths{Finite Fields}\n\nFinite fields are an important algebraic concepts used in more advanced\ncryptographic techniques. This section will introduce the very basics, as far as\nwe need them in this lecture. For a more in-depth introduction, see for instance:\nLidl \\& Niederreiter, \\emph{Introduction to finite fields and their\n  applications}, Cambridge University Press, 1994.\n\nWe first define some basic algebraic notions characterising sets together with\nbinary operations.\n\n\\begin{definition}{\\textbf{(Group)}}  \n  Let $G$ be a set and $\\circ$ be a binary operation defined on $G$, i.e.,\n  $\\circ:G\\times G\\to G$. We say $(G,\\circ)$ is a \\textbf{group} if $\\circ$\n  \\begin{romanenum}\n  \\item is \\textbf{closed}: that is for each $a,b\\in G$ we have $a\\circ b\\in G$.\n  \\item is \\textbf{associative}: that is for each $a,b,c\\in G$ we have $(a\\circ\n    b)\\circ c=a\\circ (b\\circ c)$.\n  \\item has an \\textbf{identity element}: that is there exists $e\\in G$ s.t. for\n    each $a\\in G$ we have $a\\circ e=e\\circ a=a$.\n  \\item every element has an \\textbf{inverse}: that is for every $a\\in G$ there\n    is $\\inv{a}\\in G$ with $a\\circ\\inv{a}=\\inv{a}\\circ a=e$.\n  \\end{romanenum}\n  We call $(G,\\circ)$ a \\textbf{commutative group} if in addition $\\circ$\n  \\begin{romanenum}\\addtocounter{enumi}{4}\n  \\item is \\textbf{commutative}: that is for each $a,b\\in G$ we have $a\\circ b=b\n    \\circ a$.\n  \\end{romanenum}\n\\end{definition}\n\n\\example An easy example are the integers with addition $(\\Z,+)$. They form a\ncommutative group, since they are clearly closed and associative, the identity\nelement is $0$ and each element $a\\in\\Z$ has an inverse, namely $-a\\in\\Z$.\n\nOn the contrary the integers with times $(Z,\\cdot)$ are not a group! Although\nthey are closed under $\\cdot$, times is associative, and $1\\in\\Z$ is an identity\nelement, not every element has an inverse. For example $2\\in\\Z$ would have\n$\\frac12$ as inverse, which is not an integer!\n\nHowever, the relationship between $+$ and $\\cdot$ gives rise to the following\ndefinition:\n\n\\begin{definition}{\\textbf{(Ring)}}\n  Let $R$ be a set with two binary operations $+$ and $\\cdot$, then\n  $(R,+,\\cdot)$ is a ring if\n  \\begin{itemize}\n  \\item $(R,+)$ is a commutative group,\n  \\item $(R,\\cdot)$ is closed, associative and has an identity.\n  \\item $+$ and $\\cdot$ are \n    \\begin{romanenum}\n    \\item \\textbf{left distributive}: that is for each $a,b,c\\in R$ we have\n      $a\\cdot(b+c)=(a\\cdot b)+(a\\cdot c)$,\n    \\item \\textbf{right distributive}: that is for each $a,b,c\\in R$ we have $(b+c)\\cdot a=(b\\cdot a)+(c\\cdot a)$.\n    \\end{romanenum}\n  \\end{itemize}\n\\end{definition}\n\n\\example $(\\Z,+,\\cdot)$ is a ring, since we can easily verify the distributivity\nlaws.\n\nIf the multiplication has inverses as well, we can extend our ring definition to\nthe following:\n\n\\begin{definition}{\\textbf{(Field)}}\n  Let $F$ be a set with two binary operations $+$ and $\\cdot$. Let $F^*$ be the\n  set that contains all elements of $F$ except the identity for $+$, i.e. we let\n  $F^*=F\\setminus\\set{0}$, where $0$ is the identity for $+$. Then $(F,+,\\cdot)$\n  is a field if\n  \\begin{itemize}\n  \\item $(F,+)$ is a commutative group,\n  \\item $(F^*,\\cdot)$ is a commutative group,\n  \\item $+$ and $\\cdot$ are left and right distributive. \n  \\end{itemize}\n\\end{definition}\n\n\\example The rational numbers with addition and multiplication form a field:\n$(\\Q,+,\\cdot)$. Both operations are obviously closed, associative and\ncommutative. For addition $0$ is the identity and for every $a\\in\\Q$ the\nadditive inverse is $-a\\in\\Q^*$.  Then $\\Q^*=\\Q\\setminus\\set{0}$, $1$ is the\nidentity for multiplication and every $a\\in\\Q^*$ has a multiplicative inverse,\nnamely $\\frac1a\\in\\Q^*$.\n\n\\pagebreak\n\n\\textbf{\\large Some Finite Examples}\n\nIn the following we want to restrict ourselves to finite sets. We have already\nseen some examples of finite sets in Mathematics 1 + 2. For example, the set of\nall permutations of $n$ elements forms non-commutative(!) group, the symmetric\ngroup $S_n$. Other finite sets are the sets of residue classes modulo some $n$,\n$\\Z_n$, for which we now want to check what structure they form.\n\nFor finite sets one can use a very easy technique to verify the properties of a\nparticular operation, by simply writing down the entire operation in the form of\na \\emph{multiplication table}. For example we can use the following\nmultiplication tables\n\n\\begin{minipage}[t]{.2\\textwidth}\n  {$(\\Z_2,+)$:}\n  $\\begin{array}{c|cc}\n           +  &\\rcl{0}{2}&\\rcl{1}{2}\\\\\\hline\n    \\rcl{0}{2}&\\rcl{0}{2}&\\rcl{1}{2}\\\\\n    \\rcl{1}{2}&\\rcl{1}{2}&\\rcl{0}{2}\\\\\n  \\end{array}$\n\\end{minipage}\n\\begin{minipage}[t]{.2\\textwidth}\n  {$(\\Z_2,\\cdot)$:}\n  $\\begin{array}{c|cc}\n       \\cdot  &\\rcl{0}{2}&\\rcl{1}{2}\\\\\\hline\n    \\rcl{0}{2}&\\rcl{0}{2}&\\rcl{0}{2}\\\\\n    \\rcl{1}{2}&\\rcl{0}{2}&\\rcl{1}{2}\\\\\n  \\end{array}$\n\\end{minipage}\n\\begin{minipage}[t]{.3\\textwidth}\n  {$(\\Z_3,+)$:}\n  $\\begin{array}{c|ccc}\n           +  &\\rcl{0}{3}&\\rcl{1}{3}&\\rcl{2}{3}\\\\\\hline\n    \\rcl{0}{3}&\\rcl{0}{3}&\\rcl{1}{3}&\\rcl{2}{3}\\\\\n    \\rcl{1}{3}&\\rcl{1}{3}&\\rcl{2}{3}&\\rcl{0}{3}\\\\\n    \\rcl{2}{3}&\\rcl{2}{3}&\\rcl{0}{3}&\\rcl{1}{3}\\\\\n  \\end{array}$\n\\end{minipage}\n\\begin{minipage}[t]{.3\\textwidth}\n  {$(\\Z_3,\\cdot)$:}\n  $\\begin{array}{c|ccc}\n       \\cdot  &\\rcl{0}{3}&\\rcl{1}{3}&\\rcl{2}{3}\\\\\\hline\n    \\rcl{0}{3}&\\rcl{0}{3}&\\rcl{0}{3}&\\rcl{0}{3}\\\\\n    \\rcl{1}{3}&\\rcl{0}{3}&\\rcl{1}{3}&\\rcl{2}{3}\\\\\n    \\rcl{2}{3}&\\rcl{0}{3}&\\rcl{2}{3}&\\rcl{1}{3}\\\\\n  \\end{array}$\n\\end{minipage}\nto determine that $(\\Z_2,+)$ and $(\\Z_3,+)$ are commutative groups. Obviously\n$(\\Z_2,\\cdot)$ and $(\\Z_3,\\cdot)$ are not groups, since neither $\\rcl{0}{2}$ nor\n$\\rcl{0}{3}$ have a multiplicative inverse. However, if we get rid of the $0$\nelement in both tables, it is easy to see that we get commutative groups for\n$\\Z_2^*$ and $\\Z_3^*$:\n\\begin{center}\n\\begin{minipage}[t]{.3\\textwidth}\n  {$(\\Z_2^*,\\cdot)$:} $\\begin{array}{c|c} \\cdot &\\rcl{1}{2}\\\\\\hline\n    \\rcl{1}{2}&\\rcl{1}{2}\\\\\n  \\end{array}$\n\\end{minipage}\n\\begin{minipage}[t]{.3\\textwidth}\n  {$(\\Z_3^*,\\cdot)$:} $\\begin{array}{c|cc} \\cdot &\\rcl{1}{3}&\\rcl{2}{3}\\\\\\hline\n    \\rcl{1}{3}&\\rcl{1}{3}&\\rcl{2}{3}\\\\\n    \\rcl{2}{3}&\\rcl{2}{3}&\\rcl{1}{3}\\\\\n  \\end{array}$\n\\end{minipage}\n\\end{center}\nSince one can also easily check that both distributivity laws hold, we can thus\nconclude that both $(\\Z_2,+,\\cdot)$ and $(\\Z_3,+,\\cdot)$ are fields.\n\nThe natural next question is: Do all residue class sets form a field together\nwith addition and multiplication? Let's have a look at $\\Z_4$:\n\n\\begin{center}\n  {$(\\Z_4,+)$:} $\\begin{array}{c|cccc} +\n    &\\rcl{0}{4}&\\rcl{1}{4}&\\rcl{2}{4}&\\rcl{3}{4}\\\\\\hline\n    \\rcl{0}{4}&\\rcl{0}{4}&\\rcl{1}{4}&\\rcl{2}{4}&\\rcl{3}{4}\\\\\n    \\rcl{1}{4}&\\rcl{1}{4}&\\rcl{2}{4}&\\rcl{3}{4}&\\rcl{0}{4}\\\\\n    \\rcl{2}{4}&\\rcl{2}{4}&\\rcl{3}{4}&\\rcl{0}{4}&\\rcl{1}{4}\\\\\n    \\rcl{3}{4}&\\rcl{3}{4}&\\rcl{0}{4}&\\rcl{1}{4}&\\rcl{2}{4}\\\\\n  \\end{array}$\\qquad\n  {$(\\Z_4^*,\\cdot)$:} $\\begin{array}{c|ccc} \\cdot\n    &\\rcl{1}{4}&\\rcl{2}{4}&\\rcl{3}{4}\\\\\\hline\n    \\rcl{1}{4}&\\rcl{1}{4}&\\rcl{2}{4}&\\rcl{3}{4}\\\\\n    \\rcl{2}{4}&\\rcl{2}{4}&\\rcl{0}{4}&\\rcl{2}{4}\\\\\n    \\rcl{3}{4}&\\rcl{3}{4}&\\rcl{2}{4}&\\rcl{1}{4}\\\\\n  \\end{array}$\n\\end{center}\nWe can see, while $(Z_4,+)$ is a commutative group, $(\\Z_4^*,\\cdot)$ is not a\ngroup: It is not even closed, as $\\rcl{2}{4}\\cdot\\rcl{2}{4}=\\rcl{0}{4}$ and\n$\\rcl{0}{4}$ is not an element of $\\Z_4^*$, and there is also no inverse element\nfor $\\rcl{2}{4}$. Thus $(\\Z_4,+,\\cdot)$ is a ring ($\\rcl{1}{4}$ is the neutral\nelement for $\\cdot$), but not a field.\n\nIndeed one can show the following two theorems:\n\\begin{theorem}{}\n  $(\\Z_n,+,\\cdot)$ is a ring for every $n\\geq 2$.\n\\end{theorem}\n\\begin{theorem}{}\n  $(\\Z_p,+,\\cdot)$ is a field if and only if $p$ is a prime number.\n\\end{theorem}\n\n\\begin{definition}{\\textbf{(Finite Field)}}\n  Let $(F,+,\\cdot)$ be a field. If $F$ is a finite set with $p$ elements, we\n  call $(F,+,\\cdot)$ a \\textbf{finite field} or order $p$ and denote it by\n  $\\F_p$.\n\\end{definition}\n\\example We can now write $\\F_2=(\\Z_2,+,\\cdot)$, $\\F_3=(\\Z_3,+,\\cdot)$, etc. In\ngeneral we have for every prime number $p$: $\\F_p=(\\Z_p,+,\\cdot)$.\n\nSo far we know that for every prime number $p$ there exists a finite field of\nthat order. In addition one can easily show that this is (up to isomorphism) the\nonly finite field of that order. That is, every finite field of prime order has\nthe structure of $\\Z_p$.\n\nOur next question is, are these the only finite fields, or are there any others,\ni.e. of an order that is not a prime number. In order to answer this question,\nwe have to make a little detour via the theory of polynomials.\n\n\\pagebreak\n\n\\textbf{\\large Polynomials}\n\nI assume that everyone is familiar with polynomials. The following is just to\nrecall some important concepts. While we can define polynomials essentially over\nany ring, we will restrict ourselves, for now, to polynomials over the integers\n$\\Z$.\n\n\\begin{definition}{\\textbf{(Polynomial)}}\n  We call an expression of the form $a_nx^n+\\ldots+a_2x^2+a_1x+a_0$ a \\textbf{polynomial}\n  in the variable $x$ over $\\Z$, if all $a_i\\in\\Z, i=0,\\ldots,n$ and all\n  exponents $0,\\ldots,n$ are non-negative integers. \n  \n  We denote the set of all polynomials in one variable over $\\Z$ as $\\Z[x]$.\n  \n  We call a summand $a_ix^i$ of a polynomial a \\textbf{monomial} of\n  \\textbf{degree} $i$ with \\textbf{coefficient} $a_i$. \n  \n  We say a polynomial $p\\in\\Z[x]$ is of \\textbf{degree} $n$ if its greatest\n  non-zero monomial is of degree $n$. We generally write $deg(p)=n$.\n\n\\end{definition}\n\n\\example $p(x)=x^4+3x^3+2x^2-10$ is a polynomial of degree $4$.\n\n\\begin{definition}{\\textbf{(Polynomial Arithmetic)}}\n  Let $p(x),q(x)\\in\\Z[x]$ be $p(x)=a_nx^n+\\ldots+a_2x^2+a_1x+a_0$ and\n  $q(x)=b_nx^n+\\ldots+b_2x^2+b_1x+b_0$. We define addition $+$ and multiplication\n  $\\cdot$ as component-wise operations as:\n\n  \\begin{romanenum}\n  \\item $p(x)+q(x)=(a_n+b_n)x^n+\\ldots+(a_2+b_2)x^2+(a_1+b_1)x+(a_0+b_0)$\n  \\item $\\begin{array}[t]{lllllll}\n      p(x)*q(x)&=&&(a_n*b_m)x^{(n+m)}&+(a_n*b_{m-1})x^{(n+(m-1))}&+\\ldots&+(a_n*b_{0})x^n\\\\\n      & &&&\\qquad\\qquad\\qquad\\qquad\\vdots\\\\\n      && + &(a_0*b_m)x^m&+(a_0*b_{m-1})x^{m-1}&+\\ldots&+(a_0*b_{0})\n    \\end{array}$\n  \\end{romanenum}\n  \n\\end{definition}\n\n\\example Let $p(x)=x^4+3x^3+2x^2-10$ and $q(x)=2x^3-9x^2+2x-3$. Then we have\n\\begin{eqnarray*}\np(x)+q(x)&=&x^4+5x^3-7x^2+2x-13\\\\\np(x)\\cdot q(x)&=&2x^7-3x^6-21x^5-15x^4-25x^3+84x^2-20x+30.\n\\end{eqnarray*}\n\nRecall that $(\\Z,+,\\cdot)$ forms a ring. Similarly we can show that\n$(\\Z[x],+,\\cdot)$ forms a ring with the addition and multiplication over\npolynomials. We now observe some more parallels between $\\Z$ and $\\Z[x]$:\n\n%% \\begin{tabular}{p{.5\\textwidth}|p{.5\\textwidth}}\n%%   \\centering{$\\Z$} & \\qquad\\qquad\\qquad\\qquad$\\Z[x]$\\\\\n%%   \\multicolumn{1}{c}\\textbf{Division:}\\\\\n%% \\end{tabular}\n\n\\begin{tabular}{p{.3\\textwidth}|p{.7\\textwidth}}\n  \\centering{$\\Z$} & \\qquad\\qquad\\qquad\\qquad$\\Z[x]$\\\\\\hline\n\\end{tabular}\n\n\\vspace{.4cm}\\textbf{Division with Remainder}\\vspace{.1cm}\n\n\\begin{tabular}{p{.3\\textwidth}|p{.7\\textwidth}}\n  Divide $323$ by $7$ & Divide $x^3+4x^2+6x-1$ by $x^2+2x+1$\\\\\n  $\\begin{array}{lcccc}\n      \\phantom{-}323 & / & 7 & = & 46\\\\\n      -28 & & & & \\\\\\cline{1-1}\n      \\phantom{-3}43 & & & & \\\\\n      \\phantom{}-42 & & & & \\\\\\cline{1-1}\n      \\phantom{-34}1 & & & & \\\\\n    \\end{array}$\n  &\\arraycolsep1pt\n  $\\begin{array}{llllllcccc}\n    \\phantom{-}x^3 & +4x^2 & +6x & -1 & / & x^2+2x+1 & = & x + 2 \\\\\n    -x^3 & - 2x^2 & -\\phantom{6}x \\\\\\cline{1-4}\n    & \\phantom{-}2x^2 & +5x & -1\\\\\n    & - 2x^2 & -4x & -2\\\\\\cline{2-4}\n    & & \\phantom{-4}x & -3\n  \\end{array}$\\\\[.4cm]\n  In general for every $a,b\\in\\Z$ with $a\\geq b$ we find $s,r\\in\\Z$ \n  with $|s|<|a|$ and $|r|<|b|$ such that $a=s\\cdot b + r$.\n  & \n  In general for every $p(x),q(x)\\in\\Z[x]$ with $deg(p)\\geq deg(q)$ we find $s(x),r(x)\\in\\Z[x]$ \n  with $deg(s)<deg(p)$ and $deg(r)<deg(q)$ such that $k\\cdot p(x)=s(x)\\cdot q(x) + r(x)$, with \n  $k\\in\\Z$.\\newline Observe that $k$ guarantees integer division\n  for the coefficients (e.g. $x^2+1$ is not divisible by $2x+1$ in $\\Z$, but $4x^2+4$ is). \n  Such a $k$ always exists!\n\\end{tabular}\n\n\\vspace{.4cm}\\textbf{Modular Arithmetic}\\vspace{.1cm}\n\n\\begin{tabular}{p{.3\\textwidth}|p{.7\\textwidth}}\n  %%\\centering{$\\Z$} & \\qquad\\qquad\\qquad\\qquad$\\Z[x]$\\\\\n  Recall: $\\modulo{323}{7}{1}$. & \n  Similarly we can write $\\modulo{x^3+4x^2+6x-1}{x^2+2x+1}{x-3}$\\\\[.2cm]\n  The modulo operation divides $\\Z$ into a finite number of residue classes, e.g., for mod $n$:\n  $\\Z_n=\\set{0,1,\\ldots,n-1}$ &\n  Given a polynomial $p(x)\\in\\Z[x]$, the modulo $p(x)$ operation induces residue classes on $\\Z[x]$. \n  We denote the set of all residue classes modulo $p(x)$ by $\\Z[x]/p(x)$. It contains one \n  residue class for each polynomial in $\\Z[x]$ of degree less then $p(x)$.   These are, however,\n  infinitely many!.\n\\end{tabular}\n\n%% \\textbf{Residue Classes}\n\n%% \\begin{tabular}{p{.3\\textwidth}|p{.7\\textwidth}}\n%%   \\centering{$\\Z$} & \\qquad\\qquad\\qquad\\qquad$\\Z[x]$\\\\\n%% \\end{tabular}\n\n\\vspace{.4cm}\\textbf{Irreducibility}\\vspace{.1cm}\n\n\\begin{tabular}{p{.3\\textwidth}|p{.7\\textwidth}}\n  $p\\in\\Z$ is prime if it is only divisible by $1$ and $p$.  & \n  $p(x)\\in\\Z[x]$ is called \\emph{irreducible} if it is only divisible by $p(x)$ and \n  the trivial polynomial $a_0x^0=a_0\\in\\Z$. E.g., $x^2+1$ is irreducible in $\\Z[x]$.\n\\end{tabular}\n\n\n\n\\newpage\n\\textbf{\\large Polynomials over Finite Fields}\n\nAs mentioned earlier we can construct polynomials over arbitrary rings and\ntherefore also fields. We will now look at the residue class construction for\npolynomials over finite fields. While the following could be done with any\nfinite field of the form $\\F_p$, where $p$ is a prime number, we will restrict\nourselves to the finite field $\\F_2$, in which we are most interested in.\n\nRecall that $\\F_2=(\\Z_2,+,\\cdot)$, i.e. contains only the elements $0$ and $1$.\nWe will from now on omit the residue class notation and write $0$ and $1$\ninstead of $\\rcl{0}{2}$ and $\\rcl{1}{2}$, respectively! \n\nWe now define the polynomial ring over $\\F_2$ as $\\ftwox$. We first have a look\nat the general polynomial arithmetic in $\\ftwox$, which works modulo $2$, that\nis we only have $0$ and $1$ as coefficients and the addition and multiplication\nof coefficient is performed modulo $2$. We observe this with an example:\n\n\\example Let $x^2+x+1$ and $x^3+x^2+x$ be polynomials over $\\ftwox$ then we have:\\vspace{-.1cm}\n\\begin{eqnarray*}\n  (x^2+x+1)+(x^3+x^2+x) = & x^3+2x^2+2x+1 & = x^3+1\\\\\n  (x^2+x+1)\\cdot(x^3+x^2+x) = & x^5+2*x^4+3*x^3+2*x^2+x & = x^5+x^3+x\n\\end{eqnarray*}\nThis also means that we do not need negative coefficients, as\n$x+1{=}-x+1{=}x-1{=}-x-1$ in $\\ftwox$.\\vspace{.2cm}\n\n\n\\textbf{Modular Arithmetic}\\quad\nLet $p(x)=x^4+x+1\\in\\ftwox$. Then we have \\vspace{-.1cm}\n\\[\\modulo{(x^2+x+1)\\cdot(x^3+x^2+x)= x^5+x^3+x}{x^4+x+1}{x^3+x^2}\\]\\vspace{-.0cm}\nTo verify this we look at the following polynomial division:\\vspace{-.0cm}\n\\[\\begin{array}{rrrrrrrcccc}\n  x^5 & & +x^3 & & +x& & / & x^4+x+1 = x \\\\\n  x^5 & &      &+x^2& +x \\\\\\cline{1-6}\n  & & x^3     &+x^2& \\\\\n\\end{array}\\]\\vspace{-.25cm}\n\nIn a next step we can now define the residue classes for \\textbf{$\\ftwoxpx$}.\nFor simplification we take $p(x)$ to be polynomial of degree $2$ first. Thus let\n$p(x)=x^2+1\\in\\ftwoxpx$. We then get four residue classes modulo $x^2+1$,\nrepresented by $[0]$, $[1]$, $[x]$, $[x+1]$, i.e., all polynomials in $\\ftwox$\nwith degree less than $2$. We can then construct the following tables for $+$\nand $\\cdot$:\n\n\\begin{minipage}{.5\\textwidth}\n\\begin{center}\n  {$(\\ftwox/(x^2+1),+)$:}\\newline $\\begin{array}{c|cccc} +\n             &\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\\hline\n    \\rcl{0}{}&\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\n    \\rcl{1}{}&\\rcl{1}{}&\\rcl{0}{}&\\rcl{x+1}{}&\\rcl{x}{}\\\\\n    \\rcl{x}{}&\\rcl{x}{}&\\rcl{x+1}{}&\\rcl{0}{}&\\rcl{1}{}\\\\\n    \\rcl{x+1}{}&\\rcl{x+1}{}&\\rcl{x}{}&\\rcl{1}{}&\\rcl{0}{}\\\\\n  \\end{array}$\n\\end{center}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\\begin{center}\n  {$(\\ftwox/(x^2+1),\\cdot)$:}\\newline $\\begin{array}{c|cccc} \\cdot\n    &\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\\hline\n    \\rcl{0}{}&\\rcl{0}{}&\\rcl{0}{}&\\rcl{0}{}&\\rcl{0}{}\\\\\n    \\rcl{1}{}&\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\n    \\rcl{x}{}&\\rcl{0}{}&\\rcl{x}{}&\\rcl{1}{}&\\rcl{x+1}{}\\\\\n    \\rcl{x+1}{}&\\rcl{0}{}&\\rcl{x+1}{}&\\rcl{x+1}{}&\\rcl{0}{}\\\\\n  \\end{array}$\n\\end{center}\n\\end{minipage}\n\nWe can see that, even when we delete the $\\rcl{0}{}$ lines in the multiplication\ntable, the group axioms will not hold for `$\\cdot$', as $\\rcl{x+1}{}$ does not\nhave an inverse element. This can be explained by the fact that $x^2+1$ is not\nan irreducible polynomial in $\\ftwox$, since it can be factorised into\n$x^2+1=(x+1)(x+1)$. We recall that for those $\\Z_n$ where $n$ was a prime number\nwe could construct a finite field. If we replace $x^2+1$ by an irreducible\npolynomial we should therefore also get a finite field. Let's try instead the\npolynomial $p(x)=x^2+x+1$, which is indeed irreducible over $\\ftwox$.\n\n\\begin{minipage}{.5\\textwidth}\n\\begin{center}\n  {$(\\ftwox/(x^2+x+1),+)$:}\\newline $\\begin{array}{c|cccc} +\n             &\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\\hline\n    \\rcl{0}{}&\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\n    \\rcl{1}{}&\\rcl{1}{}&\\rcl{0}{}&\\rcl{x+1}{}&\\rcl{x}{}\\\\\n    \\rcl{x}{}&\\rcl{x}{}&\\rcl{x+1}{}&\\rcl{0}{}&\\rcl{1}{}\\\\\n    \\rcl{x+1}{}&\\rcl{x+1}{}&\\rcl{x}{}&\\rcl{1}{}&\\rcl{0}{}\\\\\n  \\end{array}$\n\\end{center}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\\begin{center}\n  {$(\\ftwox/(x^2+x+1),\\cdot)$:}\\newline $\\begin{array}{c|cccc} \\cdot\n    &\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\\hline\n    \\rcl{0}{}&\\rcl{0}{}&\\rcl{0}{}&\\rcl{0}{}&\\rcl{0}{}\\\\\n    \\rcl{1}{}&\\rcl{0}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}\\\\\n    \\rcl{x}{}&\\rcl{0}{}&\\rcl{x}{}&\\rcl{x+1}{}&\\rcl{1}{}\\\\\n    \\rcl{x+1}{}&\\rcl{0}{}&\\rcl{x+1}{}&\\rcl{1}{}&\\rcl{x}{}\\\\\n  \\end{array}$\n\\end{center}\n\\end{minipage}\n\nThe two tables demonstrate that both $(\\ftwox/(x^2+x+1),+)$ and\n{$((\\ftwox/(x^2+x+1))^*,\\cdot)$} form commutative groups. [Recall that\n$(\\ftwox/(x^2+x+1))^*=\\ftwox/(x^2+x+1)\\setminus\\set{\\rcl{0}{}}$.]  We can also\nshow that the two distributivity laws hold and that therefore\n{$((\\ftwox/(x^2+x+1))^*,+,\\cdot)$} is a finite field of order $4$.\n\nThis construction demonstrates that for every irreducible polynomial\n$p(x)\\in\\ftwox$ of degree $n$, $\\ftwoxpx$ yields a finite field of order $2^n$,\nindependent of the concrete choice of $p(x)$. The more general\nresult is:\n\\begin{theorem}{}\n  For every prime $p$ and every positive integer $n$ there exists one finite\n  field of order $\\F_{p^n}$.\n\\end{theorem}\n\n\\newpage\n\\textbf{\\large Finite Fields as Binary Operations}\n\nWhat does all this have to do with computer science? Recall that we restricted\nourselves to polynomials in $p(x)\\in\\ftwox$. This means each monomial in $p(x)$\nhas as coefficient either $1$ or $0$, i.e. the coefficients are binary. We can\ntherefore straightforwardly translate polynomials of degree $d$ into bit strings\nof length $d+1$ by just taking the coefficients of each monomial.\n\n\\example Consider the translation of a polynomial of degree $7$ into $8$ bits:\n\\[\\begin{array}{cccccccr}\n x^7 & + x^6 & & + x^4 & + x^3 & & & +1\\\\\n1 & 1 & 0 & 1 & 1& 0 & 0& 1\n\\end{array}\\]\n\nWe now can use the operations on the finite field $\\F_{2^n}$ to define\noperations on bit strings of length $n+1$. For brevity we will take our examples\nfrom $\\F_8=\\ftwoxpx$ with $p(x)=x^3+x+1$ as irreducible polynomial.\n\nWe first observe that addition on $\\F_{2^n}$ is the same as the xor operation\n$\\xor$ on bits.\n\n\\example $\\begin{array}{cccccccr}\n(x^2+x+1) &+ & (x^2+1) & = & x\\\\\n111 & \\xor & 101 & = & 010\n\\end{array}$\n\nWhile addition does not give us a new operation, we can use multiplication on\n$\\F_8$ to define a new bitwise operation $\\otimes$.  First here is the\nmultiplication table for $\\F_8^*$:\n\\begin{center}\\small\\arraycolsep2pt\n  $\\begin{array}{c|ccccccc} \n    {(\\F_8^*,\\cdot)} & \\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}&\\rcl{x^2}{}&\\rcl{x^2+1}{}&\\rcl{x^2+x}{}&\\rcl{x^2+x+1}{}\\\\\\hline\n    \\rcl{1}{}&\\rcl{1}{}&\\rcl{x}{}&\\rcl{x+1}{}&\\rcl{x^2}{}&\\rcl{x^2+1}{}&\\rcl{x^2+x}{}&\\rcl{x^2+x+1}{}\\\\\n    \\rcl{x}{}&\\rcl{x}{}&\\rcl{x^2}{}&\\rcl{x^2+x}{}&\\rcl{x+1}{}&\\rcl{1}{}&\\rcl{x^2+x+1}{}&\\rcl{x^2+1}{}\\\\\n    \\rcl{x+1}{}&\\rcl{x+1}{}&\\rcl{x^2+x}{}&\\rcl{x^2+1}{}&\\rcl{x^2+x+1}{}&\\rcl{x^2}{}&\\rcl{1}{}&\\rcl{x}{}\\\\\n    \\rcl{x^2}{}&\\rcl{x^2}{}&\\rcl{x+1}{}&\\rcl{x^2+x+1}{}&\\rcl{x^2+x}{}&\\rcl{x}{}&\\rcl{x^2+1}{}&\\rcl{1}{}\\\\\n    \\rcl{x^2+1}{}&\\rcl{x^2+1}{}&\\rcl{1}{}&\\rcl{x^2}{}&\\rcl{x}{}&\\rcl{x^2+x+1}{}&\\rcl{x+1}{}&\\rcl{x^2+x}{}\\\\\n    \\rcl{x^2+x}{}&\\rcl{x^2+x}{}&\\rcl{x^2+x+1}{}&\\rcl{1}{}&\\rcl{x^2+1}{}&\\rcl{x+1}{}&\\rcl{x}{}&\\rcl{x^2}{}\\\\\n    \\rcl{x^2+x+1}{}&\\rcl{x^2+x+1}{}&\\rcl{x^2+1}{}&\\rcl{x}{}&\\rcl{1}{}&\\rcl{x^2+x}{}&\\rcl{x^2}{}&\\rcl{x+1}{}\\\\\n  \\end{array}$\n\\end{center}\nThe operation $b_1\\otimes b_2$ on 3-bit strings $b_1,b_2$ is then defined taking\nthe two polynomials corresponding to $b_1$ and $b_2$,\nrespectively, multiplying them according to the above multiplication table and\ntransforming the result again into a 3-bit string.\n\n\\example $\\begin{array}{cccccccr}\n(x^2+x+1) &\\cdot & (x^2+1) & \\equiv & x^2+x & ({\\bmod}\\, x^3+x+1)\\\\\n111 & \\otimes & 101 & = & 110\n\\end{array}$\n\nObserve that the choice of irreducible polynomial really matters in the\ndefinition of $\\otimes$. For instance, if our choice of irreducible polynomial\nwere $x^3+x^2+1$ then the example would look like this:\n\n\\example $\\begin{array}{cccccccr}\n(x^2+x+1) &\\cdot & (x^2+1) & \\equiv & 1 &({\\bmod}\\, x^3+x^2+1)\\\\\n111 & \\otimes & 101 & = & 001\n\\end{array}$\n\nFinally we consider another two, more complex examples, where again the choice\nof irreducible polynomial matters:\n\n\\example \\[\\begin{array}{cccccccr}\n(x^6+1) &\\cdot & (x^4+1) & \\equiv & x^5+x^4+x^3+x^2+1&({\\bmod}\\, x^8+x^4+x^3+x+1)\\\\\n01000001 & \\otimes & 00010001 & = & 00111101\n\\end{array}\\]\n\\[\\begin{array}{cccccccr}\n(x^6+1) &\\cdot & (x^4+1) & \\equiv & x^5+x^2+1 &({\\bmod}\\, x^8+x^4+x^3+x^2+1)\\\\\n01000001 & \\otimes & 00010001 & = & 00100101\n\\end{array}\\]\n\nObserve that the bit strings are of length $8$, which is a multiple of $4$. We\ncan therefore express the above multiplications in terms of hexadecimal numbers,\nindicated by prefix $0x$:\n\n\\centerline{$0x41 \\otimes 0x11 = 0x3\\mathrm{D}$\\qquad and\\qquad $0x41 \\otimes 0x11 = 0x25$}\n\n\\endMaths\\fi\n\n\\ifMaths\n\\beginMaths{Matrix Arithmetic}\n\nI assume that everyone is familiar with matrices and basic operations on them.\nThis handout should serve as a reminder.\n\nRecall that a matrix is a rectangular array of elements. Abstractly a $m\\times\nn$ matrix can be displayed as:\n\\[A=\\begin{bmatrix}\n  a_{1,1}  & \\cdots  & a_{1,n}\\\\\n  \\vdots & \\cdot & \\vdots \\\\\n  a_{m,1} & \\cdots & a_{m,n}\n\\end{bmatrix}\\]\nWe will refer to a particular element in the $i$'s row and $j$'s column as $A[i,j]=a_{i,j}$.\n\n\\example $A = \\begin{bmatrix} 1 & 2 & 3 \\\\ 1 & 2 & 7 \\\\ 4&9&2 \\\\\n  6&0&5\\end{bmatrix}$ is a $4\\times3$ matrix. The element $a_{2,3}$ is $7$.\n\nThe matrix $R = \\begin{bmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\end{bmatrix}$\nis a $1\\times 9$ matrix, or 9-element row vector.\\vspace{.5cm}\n\n\\textbf{\\large Matrix Addition}\n\nGiven $m\\times n$ matrices $A$ and $B$, their sum $A + B$ is the $m\\times n$\nmatrix computed by adding corresponding elements (i.e. $(A + B)[i, j] = A[i, j]\n+ B[i, j]$).\n\n\\example $\\begin{bmatrix} 1 & 3 \\\\ 1 & 0 \\\\ 1 & 2 \\end{bmatrix} + \\begin{bmatrix} 0 & 0 \\\\\n  7 & 5 \\\\ 2 & 1 \\end{bmatrix} = \\begin{bmatrix} 1+0 & 3+0 \\\\ 1+7 & 0+5 \\\\ 1+2 &\n  2+1 \\end{bmatrix} = \\begin{bmatrix} 1 & 3 \\\\ 8 & 5 \\\\ 3 & 3 \\end{bmatrix}$\\vspace{.5cm}\n\n\n\\textbf{\\large Matrix Multiplication}\n\nMultiplication of two matrices is well-defined only if the number of columns of\nthe left matrix is the same as the number of rows of the right matrix. If $A$ is\nan $m\\times n$ matrix and $B$ is an $n\\times p$ matrix, then their matrix\nproduct $AB$ is the $m\\times p$ matrix ($m$ rows, $p$ columns) given by:\n\\[(AB)[i,j] = A[i,1] B[1,j] + A[i,2] B[2,j] + ... + A[i,n] B[n,j]\\quad \\mbox{for each pair $i$ and $j$.}\\]\n\n\n\\example $\\begin{bmatrix} 1 & 0 & 2 \\\\ -1 & 3 & 1 \\\\ \\end{bmatrix} \\cdot \\begin{bmatrix}\n  3 & 1 \\\\ 2 & 1 \\\\ 1 & 0 \\end{bmatrix} = \\begin{bmatrix} (1 \\cdot 3 + 0 \\cdot\n  2 + 2 \\cdot 1) & (1 \\cdot 1 + 0 \\cdot 1 + 2 \\cdot 0) \\\\ (-1 \\cdot 3 + 3\n  \\cdot 2 + 1 \\cdot 1) & (-1 \\cdot 1 + 3 \\cdot 1 + 1 \\cdot 0) \\\\\n\\end{bmatrix} = \\begin{bmatrix} 5 & 1 \\\\ 4 & 2 \\\\ \\end{bmatrix}$\\vspace*{.5cm}\n\n\\textbf{\\large Matrix Multiplication over $\\F_2$} \n\nSo far we have implicitly assumed that our matrices are defined over the\nintegers. However, we can likewise define matrices with elements from $\\F_2$.\nAddition and multiplication are then similarly defined as above with the\nexception that the operations on the single components are performed modulo $2$.\n\n\\example Addition: $\\begin{bmatrix} 1 & 0\\\\ 1 & 1\\\\\\end{bmatrix}+\n\\begin{bmatrix} 1 & 1\\\\ 0 & 1\\\\\\end{bmatrix} = \n\\begin{bmatrix} 0 & 1\\\\ 1 & 0\\\\\\end{bmatrix}\n$ \n\n\\example Multiplication: $\\begin{bmatrix} 1 & 0 & 1 & 1\\\\ 1 & 1 & 0 & 1\\\\ 0 & 1 & 0 & 1\\\\\\end{bmatrix}\\cdot\n\\begin{bmatrix} 1 \\\\ 0\\\\ 1\\\\ 1\\\\\\end{bmatrix} = \n\\begin{bmatrix} 1+1+1 \\\\ 1+1\\\\ 1 \\\\\\end{bmatrix}=\n\\begin{bmatrix} 1 \\\\ 0\\\\ 1 \\\\\\end{bmatrix}\n$\n\n\nSimilarly, we can define matrices and matrix arithmetic over other fields, in\nparticular over all finite fields of the form $\\F_{2^n}$.\n\n\\endMaths\\fi\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"handouts\"\n%%% End: \n", "meta": {"hexsha": "7752c0ff040ac2bd800bd04e27c797cf42ddf8e8", "size": 44091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example/lecture.tex", "max_stars_repo_name": "zorkow/AIM-Workshop", "max_stars_repo_head_hexsha": "2b58a18cb457e6961fcaa8af9bbc927a4f6741ee", "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": "example/lecture.tex", "max_issues_repo_name": "zorkow/AIM-Workshop", "max_issues_repo_head_hexsha": "2b58a18cb457e6961fcaa8af9bbc927a4f6741ee", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2018-05-21T22:48:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-24T08:20:19.000Z", "max_forks_repo_path": "example/lecture.tex", "max_forks_repo_name": "zorkow/AIM-Workshop", "max_forks_repo_head_hexsha": "2b58a18cb457e6961fcaa8af9bbc927a4f6741ee", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-05-21T23:33:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-23T16:00:51.000Z", "avg_line_length": 43.2264705882, "max_line_length": 118, "alphanum_fraction": 0.6630151278, "num_tokens": 16529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6785529088313914}}
{"text": "% Part: first-order-logic\n% Chapter: model-theory\n% Section: theory-of-m\n\n\\documentclass[../../../include/open-logic-section]{subfiles}\n\n\\begin{document}\n\n\\olfileid{mod}{bas}{thm}\n\n\\section{The Theory of a \\printtoken{S}{structure}}\n\nEvery !!{structure}~$\\Struct{M}$ makes some !!{sentence}s true, and\nsome false. The set of all the !!{sentence}s it makes true is called\nits \\emph{theory}. That set is in fact a theory, since anything it\nentails must be true in all its models, including~$\\Struct{M}$.\n\n\\begin{defn}\n  Given a !!{structure}~$\\Struct M$, the \\emph{theory} of\n  $\\Struct{M}$ is the set $\\Theory{M}$ of !!{sentence}s\n  that are true in $\\Struct{M}$, i.e., $\\Theory{M} =\n  \\Setabs{!A}{\\Sat{M}{!A}}$.\n\\end{defn}\n\nWe also use the term ``theory'' informally to refer to sets\nof !!{sentence}s having an intended interpretation, whether deductively\nclosed or not.\n\n\\begin{prop}\nFor any $\\Struct{M}$, $\\Theory{M}$ is complete.\n\\end{prop}\n\n\\begin{proof}\nFor any !!{sentence}~$!A$ either $\\Sat{M}{!A}$ or $\\Sat{M}{\\lnot !A}$,\nso either $!A \\in \\Theory{M}$ or $\\lnot !A \\in \\Theory{M}$.\n\\end{proof}\n\n\\begin{prop}\\ollabel{prop:equiv}\n  If $\\Struct{N} \\models !A$ for every $!A \\in \\Theory{M}$, then\n  $\\Struct{M} \\elemequiv \\Struct{N}$.\n\\end{prop}\n\n\\begin{proof}\nSince $\\Sat{N}{!A}$ for all $!A \\in \\Theory{M}$, $\\Theory{M} \\subseteq\n\\Theory{N}$. If $\\Sat{N}{!A}$, then $\\Sat/{N}{\\lnot !A}$, so $\\lnot !A\n\\notin \\Theory{M}$. Since $\\Theory{M}$ is complete, $!A \\in\n\\Theory{M}$. So, $\\Theory{N} \\subseteq \\Theory{M}$, and we have\n$\\Struct{M} \\elemequiv \\Struct{N}$.\n\\end{proof}\n\n\\begin{rem}\\ollabel{remark:R}\n  Consider $\\Struct{R} = \\langle\\Real, <\\rangle$, the !!{structure}\n  whose domain is the set $\\Real$ of the real numbers, in the !!{language}\n  comprising only a 2-place !!{predicate} interpreted as the $<$\n  relation over the reals. Clearly $\\Struct{R}$ is !!{nonenumerable};\n  however, since $\\Theory{R}$ is obviously consistent, by the\n  L\\\"owenheim-Skolem theorem it has !!a{enumerable} model, say\n  $\\Struct{S}$, and by \\olref{prop:equiv}, $\\Struct{R}\n  \\equiv \\Struct{S}$. Moreover, since $\\Struct{R}$ and $\\Struct{S}$\n  are not isomorphic, this shows that the converse of\n  \\olref[iso]{thm:isom} fails in general.\n\\end{rem}\n\n\\end{document}\n", "meta": {"hexsha": "47c9b104868cc47f85b1bab9f1d84d5d3c031834", "size": 2258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/model-theory/basics/theory-of-m.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/model-theory/basics/theory-of-m.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/model-theory/basics/theory-of-m.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": 34.7384615385, "max_line_length": 74, "alphanum_fraction": 0.6594331267, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837689358858, "lm_q2_score": 0.8887587875995482, "lm_q1q2_score": 0.6785529088313914}}
{"text": "\\chapter{Common Random Variables}\\label{S:CommonRVs}\n\n%\\remove{\nFor a continuous RV $X$ with a closed-form expression for the inverse DF $F^{[-1]}$, we can employ \\hyperref[A:InvS]{Algorithm~\\ref*{A:InvS}} to draw samples from $X$.  \\hyperref[T:ContinRVsInvS]{Table~\\ref*{T:ContinRVsInvS}}  summarises some random variables that are amenable to \\hyperref[A:InvS]{Algorithm~\\ref*{A:InvS}}.\n\n\\begin{table}[htpb]\n\\begin{center}\n\\caption{Some continuous RVs that can be simulated from using \\hyperref[A:InvS]{Algorithm~\\ref*{A:InvS}}. \\label{T:ContinRVsInvS}}\n\\begin{tabular}{| c | c | c | c |}\n\\hline\nRandom Variable $X$ & $F(x)$ & $X=F^{[-1]}(U), \\quad U \\sim \\uniform(0,1)$ & Simplified form \\\\ \\hline\n$\\uniform(a,b)$ &\n\\eqref{E:Uniformabcdf} & $a+(b-a)U$ & -- \\\\\n$\\exponential(\\lambda)$ & \\eqref{E:Exponentialpdfcdf} & $\\frac{-1}{\\lambda} \\log(1-U)$ &  $\\frac{-1}{\\lambda} \\log(U)$ \\\\\n$\\laplace(\\lambda)$ & \\eqref{E:LaplaceInvcdf} & $- \\frac{1}{\\lambda} \\ \\sign\\left( U-\\frac{1}{2}\\right) \\log \\left(1 - 2 \\left| U-\\frac{1}{2} \\right| \\right)$ & -- \\\\\n$\\cauchy$ & \\eqref{E:StandardCauchycdf} & $\\tan \\left(\\pi \\left(U- \\frac{1}{2} \\right) \\right)$ & $\\tan \\left(\\pi U \\right)$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n%}%end remove\n\nNext, we familiarise ourselves with the Gaussian or $\\normal$ RV.\n\\begin{model}[$\\normal(\\mu,\\sigma^2)$]\n$X$ has a $\\normal(\\mu,\\sigma^2)$ or $\\gaussian(\\mu,\\sigma^2)$ distribution with the location parameter $\\mu \\in \\Rz$ and the scale or variance parameter $\\sigma^2 > 0$, if:\n\\begin{equation}\\label{E:Normalpdf}\nf(x; \\mu, \\sigma^2) = \\frac{1}{\\sigma \\sqrt{2 \\pi}}\n \\exp{\\left( - \\frac{1}{2 \\sigma^2} (x-\\mu)^2 \\right)}, \\qquad x \\in \\Rz\n\\end{equation}\n$\\normal(0,1)$ distributed RV, which plays a fundamental role in asymptotic statistics, is conventionally denoted by $Z$.  $Z$ is said to have the {\\bf Standard Normal} distribution with PDF $f(z; 0,1)$ and DF $F(z;0,1)$ conventionally denoted by $\\phi(z)$ and $\\Phi(z)$, respectively.\n\nThere is no closed form expression for $\\Phi(z)$ or $F(x;\\mu,\\sigma)$.  The latter is simply defined as:\n\\[\nF(x;\\mu,\\sigma^2) = \\int_{-\\infty}^x f(y;\\mu,\\sigma)\\,dy\n\\]\nWe can express $F(x;\\mu,\\sigma^2)$ in terms of the error function ($\\erf$) as follows:\n\\begin{equation}\\label{E:DFNormalviaErf}\nF(x;\\mu,\\sigma^2) = \\frac{1}{2} \\ \\erf \\left(  \\frac{x-\\mu}{\\sqrt{2 \\sigma^2}} \\right)+ \\frac{1}{2}\n\\end{equation}\n\\end{model}\nWe \n%\\remove{\nimplement the PDF \\eqref{E:Normalpdf} and DF \\eqref{E:DFNormalviaErf} for a $\\normal(\\mu,\\sigma^2)$ RV $X$ as \\Matlab functions {\\tt NormalPdf} and {\\tt NormalCdf}, respectively, in \\hyperref[Mf: NormalCdfPdf]{Labwork \\ref*{Mf: NormalCdfPdf}},  and then \n%}%end remove\nproduce plots for various $\\normal(\\mu,\\sigma^2)$ RVs, shown in \\hyperref[F:plotPdfCdfNormals]{Figure \\ref*{F:plotPdfCdfNormals}}.  Observe the concentration of probability mass, in terms of the PDF and DF plots, about the location parameter $\\mu$ as the variance parameter $\\sigma^2$ decreases.\n\\begin{figure}[htpb]\n\\caption{Density and distribution function of several $\\normal(\\mu,\\sigma^2)$ RVs.\\label{F:plotPdfCdfNormals}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/plotPdfCdfNormals}}\n\\end{figure}\n\n% cse snipped\n%\\remove{\n\\begin{labwork}[Compute the  the $\\P(X \\in (a,b))$ for the $\\normal(0,1)$ RV $X$]\\label{LW:NormalIntervalProb}\nWrite a function to evaluate the $\\P(X \\in (a,b))$ for the $\\normal(0,1)$ RV $X$ for user-specified values of $a$ and $b$. [Hint: one option is by making two calls to {\\tt NormalCdf} and doing one arithmetic operation.]\n\\end{labwork}\n\nSimulations \\ref*{SIM:Uniformab} and \\ref*{SIM:Exponential}, \\ref*{SIM:Laplace} and \\ref*{SIM:StdCauchy}\nproduce samples from a continuous RV $X$ with a closed-form expression for the inverse DF $F^{[-1]}$ via \\hyperref[A:InvS]{Algorithm~\\ref*{A:InvS}} (\\hyperref[T:ContinRVsInvS]{Table~\\ref*{T:ContinRVsInvS}}).  But only a few RVs have an explicit $F^{[-1]}$.  For example, $\\normal(0,1)$ RV does not have an explicit $F^{[-1]}$.\n\\hyperref[A:InvSbyNumSol]{Algorithm~\\ref*{A:InvSbyNumSol}} is a more general but inexact method that relies on an approximate numerical solution of $x$, for a given $u$, that satisfies the equation $F(x)=u$.\n\n\\begin{algorithm}\n\\caption{Inversion Sampler by Numerical Solution of $F(X)=U$ via Newton-Raphson Method}\n\\label{A:InvSbyNumSol}\n\\begin{algorithmic}[1]\n\\STATE {{\\it input:} $F(x)$, the DF of the target RV $X$}\n\\STATE {{\\it input:} $f(x)$, the density of $X$}\n%\\STATE {{\\it input:} The fundamental sampler}\n\\STATE {{\\it input:} A reasonable {\\tt Stopping Rule}, \\\\e.g.~a specified tolerance $\\epsilon >0$ and a maximum number of iterations {\\tt MAX}}\n\\STATE {{\\it input:} a careful mechanism to specify $x_0$}\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 initialise:} $i \\gets 0, \\qquad x_i \\gets x_0, \\qquad x_{i+1} \\gets x_0 - \\frac{F(x_0)-u}{f(x_0)}$}\n\\WHILE{{\\tt Stopping Rule} is not satisfied,\\\\e.g.~$|F(x_{i})-F(x_{i-1})| > \\epsilon$ AND $i < {\\tt MAX}$}\n\\STATE $x_i \\gets x_{i+1}$\n\\STATE $x_{i+1} \\gets \\left( x_{i} - \\frac{F(x_i)-u}{f(x_i)} \\right)$\n\\STATE $i \\gets i+1$\n\\ENDWHILE\n\\STATE{{\\it return:} $x \\gets x_i$}\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{simulation}[$\\normal(\\mu,\\sigma^2)$]\\label{SIM:NormalByNewRap}\nWe may employ \\hyperref[A:InvSbyNumSol]{Algorithm~\\ref*{A:InvSbyNumSol}} to sample from the $Normal(\\mu,\\sigma^2)$ RV $X$ using the following function.\n \\VrbMf[label=Sample1NormalByNewRap.m]{scripts/Sample1NormalByNewRap.m}\n\nWe draw five samples from the $\\normal(0,1)$ RV $Z$ and store them in $z$ as follows.  The vector $z$ can be obtained by a Newton-Raphson-based numerical transformation of the vector $u$ of $5$ IID samples from the $\\uniform(0,1)$ RV.  We simply need to apply the function {\\tt Sample1NormalByNewRap} to each element of an array of $\\uniform(0,1)$ samples.  \\Matlab's {\\tt arrayfun} command can be used to apply {\\tt @(u)(Sample1NormalByNewRap(u,0,1))} (i.e., {\\tt Sample1NormalByNewRap} as a function of $u$) to every element of our array of $\\uniform(0,1)$ samples, say {\\tt Us}.  Note that $F(z)$ is the same as the drawn $u$ from $U$ at least up to four significant digits.\n\\begin{VrbM}\n>> rand('twister',563987);\n>> Us=rand(1,5); % store 5 samples from Uniform(0,1) RV in array Us\n>> disp(Us); % display Us\n    0.8872    0.2569    0.5275    0.8650    0.8517\n>> z=Sample1NormalByNewRap(Us(1),0,1); %transform Us(1) to a Normal(0,1) sample z\n>> disp(z); % display z\n    1.2119\n>> z = arrayfun(@(u)(Sample1NormalByNewRap(u,0,1)),Us); %transform array Us via arrayfun\n>> % dislay array z obtained from applying Sample1NormalByNewRap to each element of Us\n>> disp(z);\n    1.2119   -0.6530    0.0691    1.1031    1.0439\n>> % check that numerical inversion of F worked, i.e., is F(z)=u ?\n>> disp(NormalCdf(z,0,1));\n    0.8872    0.2569    0.5275    0.8650    0.8517\n\\end{VrbM}\nNext we draw five samples from the $\\normal(-100.23,0.01)$ RV $X$, store it in an array $x$ and observe that the numerical method is reasonably accurate by the equality of $u$ and $F(x)$.\n\\begin{VrbM}\n>> rand('twister',563987);\n>> disp(Us); % display Us\n    0.8872    0.2569    0.5275    0.8650    0.8517\n>> % transform array Us via arrayfun\n>> x = arrayfun(@(u)(Sample1NormalByNewRap(u,-100.23,0.01)),Us);\n>> disp(x);\n -100.1088 -100.2953 -100.2231 -100.1197 -100.1256\n>> disp(NormalCdf(x,-100.23,0.01));\n    0.8872    0.2569    0.5275    0.8650    0.8517\n\\end{VrbM}\nOne has to be extremely careful with this approximate simulation algorithm implemented in floating-point arithmetic.  More robust samplers for the $\\normal(\\mu,\\sigma^2)$ RV exist.\nHowever, \\hyperref[A:InvSbyNumSol]{Algorithm~\\ref*{A:InvSbyNumSol}} is often the only choice when simulating from an arbitrary RV with an unknown closed-form expression for its $F^{[-1]}$.\n\\end{simulation}\n%%% begin of informal CLT excursion\nNext, we use our simulation capability to gain an informal and intuitive understanding of one of the most elementary theorems in probability and statistics, namely, the Central Limit Theorem (CLT).  We will see a formal treatment of CLT later.\n\nInformally, the CLT can be stated as follows:\\\\\n``The sample mean of a large number of IID samples, none of which is dominant, tends to the $\\normal$ distribution as the number of samples increases.''\n\n\\begin{labwork}[Investigating the Central Limit Theorem with IID $\\exponential(\\lambda=0.1)$ RVs]\\label{LW:CLTOfExponentials}\nLet us investigate the histograms from $10000$ simulations of the sample mean of $n=10,100,1000$ IID $\\exponential(\\lambda=0.1)$ RVs as follows:\n\\begin{VrbM}\n>> rand('twister',1973); % initialise the fundamental sampler\n>> % a demonstration of Central Limit Theorem (CLT) -- Details of CLT are in the sequel\n>> % the sample mean should be a Normal(1/lambda,lambda/n) RV\n>> lambda=0.1; Reps=10000; n=10; hist(sum(-1/lambda * log(rand(n,Reps)))/n)\n>> lambda=0.1; Reps=10000; n=100; hist(sum(-1/lambda * log(rand(n,Reps)))/n,20)\n>> lambda=0.1; Reps=10000; n=1000; hist(sum(-1/lambda * log(rand(n,Reps)))/n,20)\n\\end{VrbM}\nDo you see a pattern in the histograms?\n\nSee the histograms generated from the following code that produces sample means from the $\\cauchy$ RV:\n\\begin{VrbM}\n>> Reps=10000; n=1000; hist(sum(tan(pi * rand(n,Reps)))/n,20)\n>> Reps=10000; n=1000; hist(sum(tan(pi * rand(n,Reps)))/n,20)\n>> Reps=10000; n=1000; hist(sum(tan(pi * rand(n,Reps)))/n,20)\n\\end{VrbM}\n\\end{labwork}\n\\begin{classwork}[Why doesn't the sample mean of the $\\cauchy$ RV ever settle down?]\nExplain in words why the mean of $n$ IID samples from the $\\cauchy$ RV ``is {\\bf not} obeying'' the Central Limit Theorem.  Also relate it to \\hyperref[F:plot5RunningMeansStandardcauchyUnif010]{Figure~\\ref*{F:plot5RunningMeansStandardcauchyUnif010}} of \\hyperref[LW:RunningMeanCauchy]{Labwork~\\ref*{LW:RunningMeanCauchy}}.\n\\end{classwork}\n%}% end remove\n\n\\begin{model}[$\\gammA(\\lambda,k)$ RV]\nGiven a shape parameter $\\alpha>0$ and a rate parameter $\\beta>0$, the RV $X$ is said to be $\\gammA(\\alpha,\\beta)$ distributed if its PDF is:\n\\[\nf(x;\\alpha,\\beta) = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} x^{\\alpha-1} \\exp(-\\beta x), \\qquad x > 0 \\ ,\n\\]\nwhere, the gamma function which interpolates the factorial function is:\n\\[\n\\Gamma(\\alpha) := \\int_0^{\\infty} \\exp(-y) y^{\\alpha-1} dy \\ .\n\\]\nWhen $k \\in \\Nz$, then $\\Gamma(k)=(k-1)!$.  The DF of $X$ is:\n\\[\nF(x;\\lambda,k) = \\BB{1}_{\\Rz_{>0}}(x) \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\int_0^{x} y^{\\alpha-1} \\exp(-\\beta y) dy =\n\\begin{cases}\n0 & \\text{if } x \\leq 0 \\\\\n \\frac{\\gamma(\\alpha,\\beta x)}{\\Gamma(\\alpha)} & \\text{if } x > 0\n\\end{cases}\n\\]\nwhere $\\gamma(\\alpha,\\beta x)$ is called the lower incomplete Gamma function.\n\\end{model}\nThe expectation and variance of a $\\gammA(\\alpha,\\beta)$ RV are $\\alpha/\\beta$ and $\\alpha/\\beta^2$, respectively.\n%\\remove{\nThe Gamma function and the incomplete Gamma function are available as \\Matlab functions {\\tt gamma} and {\\tt gammainc}, respectively.  Thus, {\\tt gamma(k)} returns $\\Gamma(k)$ and {\\tt gammainc(lambda*x,k)} returns $F({\\tt x};{\\tt lambda},{\\tt k})$.  Using these functions, it is straightforward to evaluate the PDF and CDF of $X \\sim \\gammA(\\lambda,k)$.  We use the following script to get a sense for the impact upon the PDF and CDF of the shape parameter $k$ as it ranges in $\\{1,2,3,4,5\\}$ for a given scale parameter $\\lambda=0.1$.\n\\VrbMf[label=PlotPdfCdfGamma.m]{scripts/PlotPdfCdfGamma.m}\n%}%end remove\n\n\\begin{figure}[htpb]\n\\caption{PDF and CDF of $X \\sim \\gammA(\\beta=0.1,\\alpha)$ with $\\alpha \\in \\{1,2,3,4,5\\}$.\\label{F:PlotPdfCdfGamma}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/PlotPdfCdfGamma}}\n\\end{figure}\n\n\nNote that if $X \\sim \\gammA(1,\\beta)$ then $X \\sim \\exponential(\\beta)$, since:\n\\[\nf(x;1,\\beta)  \n= \\frac{1}{(1-1)!}  \\beta \\exp(-\\beta x) = \\beta \\exp(-\\beta x) \\ .\n\\]\nMore generally, if $X \\sim \\gammA(\\alpha,\\beta)$ and $\\alpha \\in \\Nz$, then $X \\sim \\sum_{i=1}^{\\alpha} Y_i$, where $Y_i \\overset{IID}{\\sim} \\exponential(\\beta)$ RVS, i.e.~ the sum of $\\alpha$ IID $\\exponential(\\beta)$ RVs forms the model for the $\\gammA(\\alpha,\\beta)$ RV.  If you model the inter-arrival time of buses at a bus-stop by IID $\\exponential(\\beta)$ RV, then you can think of the arrival time of the $k^{\\text th}$ bus as a $\\gammA(\\alpha,\\beta)$ RV.\n\n%\\section{Discrete Random Variables}\n%}%end remove\n\n\n%\\remove{\n\\section*{Summary of Random Variables}\\label{S:SummaryRVs}\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{|c|c|c|c|}%|c}\n\\hline\nModel &PDF&Mean&Variance\\\\ \\hline%&{\\tt MGF}\\\\\n%$\\pointmass(\\theta)$&$\\BB{1}_{\\{\\theta\\}}(x)$&$\\theta$&$0$\\\\%&$e^{\\theta t}$\\\\\n$\\bernoulli(\\theta)$ &$\\theta^x(1-\\theta)^{1-x} \\BB{1}_{\\{0,1\\}}(x)$&$\\theta$&$\\theta(1-\\theta)$\\\\%&$\\theta e^t+(1-\\theta)$\\\\\n$\\binomial(n,\\theta)$&$(^n_{\\theta})\\theta^x(1-\\theta)^{n-x} \\BB{1}_{\\{0,1,\\ldots,n\\}}(x)$&$n \\theta$&$n \\theta(1-\\theta)$\\\\%&$(\\theta e^t+(1-\\theta))^n$\\\\\n$\\geometric(\\theta)$ &$\\theta(1-\\theta)^{x} \\BB{1}_{\\Zz_+}(x)$&$ \\frac{1}{\\theta}-1$&$\\frac{1-\\theta}{\\theta^2}$\\\\%&$\\frac{\\theta e^t}{1-(1-\\theta)e^t}(t<-log(1-\\theta))$\\\\\n$\\poisson(\\lambda)$&$\\frac{\\lambda^xe^{-\\lambda}}{x!} \\BB{1}_{\\Zz_+}(x)$&$\\lambda$&$\\lambda$\\\\%&$e^{\\lambda(e^t-1)}$\\\\\n$\\uniform(\\theta_1,\\theta_2)$&$\\BB{1}_{[\\theta_1,\\theta_2]}(x)/(\\theta_2-\\theta_1)$&$\\frac{\\theta_1+\\theta_2}{2}$&$\\frac{(\\theta_2-\\theta_1)^2}{12}$\\\\%&$\\frac{e^{\\theta_2 t}-e^{\\theta_1 t}}{(\\theta_2-\\theta_1)t}$\\\\\n$\\exponential(\\lambda)$&$\\lambda e^{-\\lambda x}$&$\\lambda^{-1}$&$\\lambda^{-2}$\\\\%&$\\frac{1}{1-\\frac{1}{\\lambda} t}(t<\\lambda)$\\\\\n$\\normal(\\mu,\\sigma^2)$&$\\frac{1}{\\sigma\\sqrt{2\\pi}}e^{(x-\\mu)^2/(2\\sigma^2)}$&$\\mu$&$\\sigma^2$\\\\%&$exp\\{ut+\\frac{\\sigma^2t^2}{2}\\}$\\\\\n$\\gammA(\\alpha,\\beta)$&$\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}{x^{\\alpha-1}e^{-\\beta x}}$&$\\alpha/\\beta$&$\\alpha/\\beta^2$\\\\%&$(\\frac{1}{1-\\beta t})^{\\alpha}(t<1/\\beta)$\\\\\n%$\\betA(\\alpha,\\beta)$ & $\\frac{\\Gamma(\\alpha+\\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)}x^{\\alpha-1}(1-x)^{\\beta-1}$ & $\\frac{\\alpha}{\\alpha+\\beta}$ & $\\frac{\\alpha\\beta}{(\\alpha+\\beta)^2 (\\alpha+\\beta+1)} $ \\\\%& $ 1+\\Sigma^\\infty_{k+1}(\\Pi^{k-1}_{r=0}\\frac{\\alpha+r}{\\alpha+\\beta+r})\\frac{t^k}{k\\!}$\\\\\n%$t_v$ & $\\frac{\\Gamma((v+1)/2)}{\\Gamma(v/2)}  \\frac{1}{(1+x^2/v)^{(v+1)/2}$ &0 (if $v>1$ ) & $\\frac{v}{v-2}$  (if $v>2$) & does not exist \\\\\n% $\\chi^2_p$&$\\frac{1}{\\Gamma(p/2)2^{p/2}}x^{(p-2)-1}e^{-x/2}$&$p$&$2p$\\\\ \\hline%&$(\\frac{1}{1-2t})^{p/2}(t<1/2)$\\\\\n\\hline\n\\end{tabular}\n\\caption{Random Variables with PDF, Mean and Variance}\n%\\label{tab:}\n\\end{table}\n\n\nWe need a new notion for the variance of two RVs.\n\\begin{definition}[Covariance]\nSuppose $X_1$ and $X_2$ are random variables, such that $\\E(X_1^2) < \\infty$ and $\\E(X_2)^2 < \\infty$.  Then, $\\E(|X_1 X_2|) < \\infty$ and $\\E(|(X_1-\\E(X_1))(X_2-\\E(X_2))|) < \\infty$.  We therefore define the covariance $\\cv(X_1,X_2)$ of $X_1$ and $X_2$ as:\n\\[\n\\cv(X_1,X_2) := \\E \\left((X_1-\\E(X_1))(X_2-\\E(X_2))\\right) = \\E(X_1 X_2) - \\E(X_1) \\E(X_2)\n\\]\n\\end{definition}\n\nLet us consider the natural two-dimensional analogue of the $\\bernoulli(\\theta)$ RV in the real plane $\\Rz^2 := (-\\infty,\\infty)^2 := (-\\infty,\\infty) \\times (-\\infty,\\infty)$.  A natural possibility is to use the {\\bf ortho-normal basis vectors} in $\\Rz^2$:\n$$ \\boxed{\ne_1 := (1,0), \\qquad e_2 := (0,1)\n} \\ .$$\nRecall that vector addition and subtraction are done component-wise, i.e.~$(x_1,x_2) \\pm (y_1,y_2) = (x_1\\pm y_1,x_2 \\pm y_2)$.\n\n\\begin{classwork}[Geometry of Vector Addition]\nRecall elementary vector addition in the plane.  What is $(1,0)+(1,0)$, $(1,0)+(0,1)$, $(0,1)+(0,1)$?  What is the relationship between $(1,0)$, $(0,1)$ and $(1,1)$ geometrically? How does the diagonal of the parallelogram relate the its two sides in the geometry of addition in the plane?  What is  $(1,0)+(0,1)+(1,0)$?\n\\end{classwork}\n\n\\begin{figure}[htpb]\n\\caption{Quincunx on the Cartesian plane.  Simulations of $\\binomial(n=10,\\theta=0.5)$ RV as the x-coordinate of the ordered pair resulting from the culmination of sample trajectories formed by the accumulating sum of $n=10$ IID $\\bernoulli(\\theta=0.5)$ random vectors over $\\{(1,0),(0,1)\\}$ with probabilities $\\{\\theta,1-\\theta\\}$, respectively.  The blue lines and black asterisks perpendicular to and above the diagonal line, i.e.~the line connecting $(0,10)$ and $(10,0)$, are the density histogram of the samples and the PDF of our $\\binomial(n=10,\\theta=0.5)$ RV, respectively.\\label{F:BinomQuincunxn10r10r1000}}\n\\centering\n\\mbox{\\subfigure[Ten samples]{\\hspace{-2cm} \\includegraphics[width=3.250in]{figures/BinomQuincunxn10r10}} \\hspace{-2cm}\n\t   \\subfigure[Thousand samples]{\\includegraphics[width=3.250in]{figures/BinomQuincunxn10r1000}} }\n\\end{figure}\n\n\\begin{model}[$\\bernoulli(\\theta)$ \\rv]\nGiven a parameter $\\theta \\in [0,1]$, we say that $X := (X_1,X_2)$ is a $\\bernoulli(\\theta)$ random vector (\\rv) if it has only two possible outcomes in the set $\\{e_1,e_2\\} \\subset \\Rz^2$, i.e.~$x:=(x_1,x_2) \\in \\{(1,0),(0,1)\\}$.  The PMF of the \\rv~$X:= (X_1,X_2)$ with realisation $x:=(x_1,x_2)$ is:\n\\[\nf(x;\\theta) := \\P(X=x) = \\theta \\, \\BB{1}_{\\{e_1\\}}(x) + (1-\\theta) \\, \\BB{1}_{\\{e_2\\}}(x) =\n\\begin{cases}\n\\theta & \\text{if } \\quad x=e_1:=(1,0) \\\\\n1- \\theta & \\text{if } \\quad x=e_2:=(0,1) \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\n\\end{model}\n\n\n\\begin{classwork}[Expectation and Variance of $\\bernoulli(\\theta)$ \\rv]\nWhat is the Expectation of $\\bernoulli(\\theta)$ \\rv?\n\\[\n\\E_{\\theta}(X) = \\E_{\\theta}((X_1,X_2)) = \\sum_{(x_1,x_2) \\in \\{e_1,e_2\\}} (x_1,x_2) f((x_1,x_2);\\theta) = (1,0) \\theta + (0,1) (1-\\theta) = (\\theta,1-\\theta) \\ .\n\\]\n\nHow about the variance ? [Hint: Use the definitions of $\\E(X)$ and $\\V(X)$ for the \\rv~$X$.  $\\E(X^2)$ is not a single number and you may need new words such as covariance to deal with terms like $\\E(X_1 X_2)$.]\n\\end{classwork}\n\n%\\remove{\nWe can write the $\\binomial(n,\\theta)$ RV $Y$ as a $\\binomial(n,\\theta)$ \\rv~$X:=(Y,n-Y)$.  In fact, this is the underlying model and the {\\bf bi} in the $\\binomial(n,\\theta)$ does refer to two in Latin.  In the coin-tossing context this can be thought of keeping track of the number of Heads and Tails out of an IID sequence of $n$ tosses of a coin with probability $\\theta$ of observing Heads.  In the Quincunx context, this amounts to keeping track of the number of right and left turns made by the ball as it drops through $n$ levels of pegs where the probability of a right turn at each peg is independently and identically $\\theta$.  In other words, the $\\binomial(n,\\theta)$ \\rv~$(Y,n-Y)$ is the sum of $n$ IID $\\bernoulli(\\theta)$ {\\rv}s $X_1:=(X_{1,1},X_{1,2}), X_2:=(X_{2,1},X_{2,2}), \\ldots, X_n:=(X_{n,1},X_{n,2})$:\n\\[\n(Y,n-Y) = X_1+X_2+\\cdots + X_n = (X_{1,1},X_{1,2}) + (X_{2,1},X_{2,2}) + \\cdots + (X_{n,1},X_{n,2})\n\\]\n\nGo the Biomathematics Research Centre on the 6th floor of Erskine to play with the Quincunx built by Ryan Lawrence in 2007 (See the project by Ashman and Lawrence at  \\href{http://www.math.canterbury.ac.nz/~r.sainudiin/courses/STAT218/projects/Stat218StudentProjects2007.pdf}{\\url{http://www.math.canterbury.ac.nz/~r.sainudiin/courses/STAT218/projects/Stat218StudentProjects2007.pdf}} % \\ref{S:AshmanLawrenceQuincunx} \nfor details).  It is important to gain a physical intimacy with the Quincunx to appreciate the following model of it.  We can make a statistical model of Galton's observations earlier regarding the dynamics of lead shots through the Quincunx as the sum of $n$ IID $\\bernoulli(0.5)$ \\rv{s}, where $n$ is number of pegs that each ball bounces on before making a left or right turn with equal probability.  \n\n\\begin{exercise}[Number of paths and the binomial coefficient]\nHow does the number of paths that lead to a bucket $(x_1,x_2)$ with $x_1+x_2=n$ relate to the binomial coefficient $\\binom{n}{x_1} ?$\n%\\vspace{2cm}\n\\end{exercise}\n\n\\begin{labwork}[Quincunx Sampler Demo -- Sum of $n$ IID $\\bernoulli(1/2)$ \\rv{s}]\\label{LW:QuincunxSampler}\nLet us understand the Quincunx construction of the $\\binomial(n,1/2)$ \\rv $X$ as the sum of $n$ independent and identical $\\bernoulli(1/2)$ \\rv{s} by calling the interactive visual cognitive tool as follows:\n\\begin{VrbM}\n>> guiMultinomial\n\\end{VrbM}\nThe M-file {\\tt guiMultinomial.m} will bring a graphical user interface (GUI) as shown in \\hyperref[F:guiMultinomialQuincunx]{Figure \\ref*{F:guiMultinomialQuincunx}}.  Using the drop-down menu at ``How many levels?'' change the number of levels to $2$ ($n=2$).  Now click the ``Do one'' button as many times as you like and comprehend the simulation process -- the path taken by the ball as it falls through two levels.  Next, from the drop-down menu at ``How many  Replication?'' change it from $10$ to $100$.  You can press ``Do all'' to watch all 100 balls drop into their possible values at level $2$.  Change the number of levels or $n$ in $\\binomial(n,1/2)$ \\rv to $3$ or $5$ or $10$ and do more simulations until you are comfortable with the construction that the sum of $n$ IID $\\bernoulli(1/2)$ \\rv{s} is the $\\binomial(n,1/2)$ \\rv.\n\nWhen we drop $1000$ balls into the simulated Quincunx the density histogram is much closer to the PDF of $\\binomial(n=10,\\theta=0.5)$ RV than when we only drop $10$ balls.  See \\hyperref[F:BinomQuincunxn10r10r1000]{Figure \\ref*{F:BinomQuincunxn10r10r1000}} for a description of the simulations.  Try to replicate such a simulation on your own.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Quincunx.\\label{F:guiMultinomialQuincunx}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/guiMultinomialQuincunx}}\n\\end{figure}\n%}%end remove\n\nWe are now ready to extend the $\\binomial(n,\\theta)$ RV or \\rv~to its multivariate version called the $\\multinomial(n,\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv.  We develop this \\rv~as the sum of $n$ IID $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv~that is defined next.\n\n\\begin{model}[$\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv]\\label{M:deMoivreRVec}\nThe PMF of the $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv~$X := (X_1,X_2,\\ldots,X_k)$ taking value $x := (x_1,x_2,\\ldots,x_k) \\in \\{e_1,e_2,\\ldots,e_k\\}$, where the $e_i$'s are ortho-normal basis vectors in $\\Rz^k$ is:\n\\[\nf(x;\\theta_1,\\theta_2,\\ldots,\\theta_k) := \\P(X=x) = \\sum_{i=1}^k \\theta_i \\BB{1}_{\\{e_i\\}}(x) =\n\\begin{cases}\n\\theta_1 & \\text{if} \\quad x=e_1:=(1,0,\\ldots,0) \\in \\Rz^k \\\\\n\\theta_1 & \\text{if} \\quad x=e_1:=(0,1,\\ldots,0) \\in  \\Rz^k \\\\\n\\vdots \\\\\n\\theta_k & \\text{if} \\quad x=e_k:=(0,0,\\ldots,1) \\in  \\Rz^k \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\nOf course, $\\sum_{i=1}^k \\theta_i = 1$.\n\\end{model}\n\nWhen we add $n$ IID $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv~together, we get the $\\multinomial(n,\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv~as defined below.\n\n\\begin{model}[$\\multinomial(n,\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv]\\label{M:Multinomial}\nWe say that a \\rv~$Y:=(Y_1,Y_2,\\ldots,Y_k)$ obtained from the sum of $n$ IID $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ \\rv{s} with realisations\n$$y:=(y_1,y_2,\\ldots,y_k) \\in \\Yz:= \\{(y_1,y_2,\\ldots,y_k) \\in \\Zz_+^k : \\sum_{i=1}^k y_i = n\\}$$ has the PMF given by:\n\\[\nf(y;n,\\theta) := f(y;n,\\theta_1,\\theta_2,\\ldots,\\theta_k) := \\P(Y=y;n,\\theta_1,\\theta_2,\\ldots,\\theta_k) = \\binom{n}{y_1,y_2,\\ldots,y_k} \\prod_{i=1}^k \\theta_i^{y_i} \\ ,\n\\]\nwhere, the multinomial coefficient:\n\\[\n \\binom{n}{y_1,y_2,\\ldots,y_k} := \\frac{n!}{y_1! y_2! \\cdots y_k!} \\ .\n\\]\nNote that the marginal PMF of $Y_j$ is $\\binomial(n,\\theta_j)$ for any $j=1,2,\\ldots,k$.\n\\end{model}\n\n\\begin{figure}[htpb]\n\\caption{Septcunx on the Cartesian co-ordinates.  Simulations of $\\multinomial(n=2,\\theta_1=1/3,\\theta_2=1/3,\\theta_3=1/3)$ \\rv~as the sum of $n$ IID $\\demoivre(\\theta_1=1/3,\\theta_2=1/3,\\theta_3=1/3)$ \\rv{s} over $\\{(1,0,0),(0,1,0),(0,0,1)\\}$ with probabilities $\\{\\theta_1,\\theta_2,\\theta_3\\}$, respectively.  The blue lines perpendicular to the sample space of the $\\multinomial(3,\\theta_1,\\theta_2,\\theta_3)$ \\rv, i.e.~the plane in $\\Rz^3$ connecting $(n,0,0)$, $(0,n,0)$ and $(0,0,n)$, are the density histogram of the samples.\\label{F:MultinomSeptcunxn2n10r1000}}\n\\centering\n\\mbox{\\subfigure[Thousand Samples with $n=2$]{\\hspace{-2cm} \\includegraphics[width=4.250in]{figures/MultinomSeptcunxn2r1000}} \\hspace{-2cm}\n\t   \\subfigure[Thousand Samples with $n=10$]{\\includegraphics[width=4.250in]{figures/MultinomSeptcunxn10r1000}} }\n\\end{figure}\n\nWe can visualise the $\\multinomial(n,\\theta_1,\\theta_2,\\theta_3)$ process as a sum of $n$ IID $\\demoivre(\\theta_1,\\theta_2,\\theta_3)$ \\rv{s} via a three dimensional extension of the Quincunx called the ``Septcunx'' and relate the number of paths that lead to a given trivariate sum $(y_1,y_2,y_3)$ with $\\sum_{i-1}^3 y_i = n$ as the multinomial coefficient $\\frac{n!}{y_1! y_2! y_3!}$.  In the Septcunx, balls choose from one of three paths along $e_1$, $e_2$ and $e_3$ with probabilities $\\theta_1$, $\\theta_2$ and $\\theta_3$, respectively, in an IID manner at each of the $n$ levels, before they collect at buckets placed at the integral points in the $3$-simplex, $\\Yz = \\{(y_1,y_2,y_3) \\in \\Zz_+^3 : \\sum_{i=1}^3 y_i=n \\}$.  Once again, we can visualise that the sum of $n$ IID $\\demoivre(\\theta_1,\\theta_2,\\theta_3)$ \\rv{s} constitute the $\\multinomial(n,\\theta_1,\\theta_2,\\theta_3)$ \\rv~as depicted in \\hyperref[F:MultinomSeptcunxn2n10r1000]{Figure \\ref*{F:MultinomSeptcunxn2n10r1000}}.\n\n%\\remove{\n\\begin{labwork}[Septcunx Sampler Demo -- Sum of n IID $\\demoivre(1/3,1/3,13/)$ \\rv{s}]\\label{LW:SeptcunxSampler}\nLet us understand the Septcunx construction of the $\\multinomial(n,1/3,1/3,1/3)$ \\rv $X$ as the sum of $n$ independent and identical $\\demoivre(1/3,1/3,13/)$ \\rv{s} by calling the interactive visual cognitive tool as follows:\n\\begin{VrbM}\n>> guiMultinomial\n\\end{VrbM}\nThe M-file {\\tt guiMultinomial.m} will bring a GUI as shown in \\hyperref[F:guiMultinomialQuincunx]{Figure \\ref*{F:guiMultinomialQuincunx}}.  Using the drop-down menu at ``How many dimensions?'' change to ``3-d (the septcunx)'' and you will see a septcunx as shown in \\hyperref[F:guiMultinomialSeptcunx]{Figure \\ref*{F:guiMultinomialSeptcunx}}.  Next, using the drop-down menu at ``How many levels?'' change the number of levels to $2$ ($n=2$).  Now click the ``Do one'' button as many times as you like and comprehend the simulation process -- the path taken by the ball as it falls through two levels in three dimensional space.  Feel free to change the up-down and left-right sliders for the view angles.  Next, from the drop-down menu at ``How many  Replication?'' change it from $10$ to $100$.  You can press ``Do all'' to watch all 100 balls drop into their possible values at level $2$.  Change the number of levels or $n$ in $\\multinomial(n,1/3,1/3,1/3)$ \\rv to $5$ or $10$ and do more simulations until you are comfortable with the construction that the sum of $n$ IID $\\demoivre(1/3,1/3,1/3)$ \\rv{s} is the $\\multinomial(n,1/3,1/3,1/3)$ \\rv.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Septcunx.\\label{F:guiMultinomialSeptcunx}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/guiMultinomialSeptcunx}}\n\\end{figure}\n\n\n\\begin{labwork}[PDF of $\\multinomial(n,\\theta)$ \\rv]\\label{LW:MultinomialPdf}\nWe can implement the following \\Matlab function {\\tt MultinomialPdf} to compute the PDF of the $\\multinomial(n,\\theta)$ \\rv~where $\\theta:=(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ is a point in the $k$-simplex $\\bigtriangleup_k$ as follows:\n\\VrbMf[label=MultinomialPdf.m]{scripts/MultinomialPdf.m}\nWe can call this function to evaluate the PDF at a specific sample $x=(x_1,x_2,\\ldots,x_k)$ as follows:\n\\begin{VrbM}\n>> MultinomialPdf([2 0 0],2,[1/3 1/3 1/3])\nans =    0.1111\n>> MultinomialPdf([0 2 0],2,[1/3 1/3 1/3])\nans =    0.1111\n>> MultinomialPdf([0 0 2],2,[1/3 1/3 1/3])\nans =    0.1111\n>> MultinomialPdf([1 1 0],2,[1/3 1/3 1/3])\nans =    0.2222\n>> MultinomialPdf([1 0 1],2,[1/3 1/3 1/3])\nans =    0.2222\n>> MultinomialPdf([0 1 1],2,[1/3 1/3 1/3])\nans =    0.2222\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{simulation}[A simple multinomial simulation]\\label{SIM:Multinomial}\nUsing the identity matrix $I$ in $\\Rz^3$ that can be created in \\Matlab using the {\\tt eye(3)} command, and the $\\demoivre(1/3,1/3,1/3)$ RV sampler, simulate vector-valued samples from $\\demoivre(1/3,1/3,1/3)$ \\rv.  Finally add up $n=10$ samples from $\\demoivre(1/3,1/3,1/3)$ \\rv~to produce samples from $\\multinomial(10,1/3,1/3,1/3)$ \\rv.\n\\end{simulation}\n\n%%% begin Dominic's Material\n%%% WORK: We need to introduce sampling from a large discrete distribution, say the Alias method before this material % theoretically explain randsample function in Matlab\n\\remove{\n\\section{Importance Resampler}\nThe rejection method cannot be used when the constant $a$ or $\\tilde{a}$ that guarantees the envelape condition cannot be found. The importance resampler, also known as the method of {sampling/importance resampling}, does not require the constant, but it produces a random variable that is only approximately distributed according to $f$. As for the rejection method, we need a density/mass function $g$ that we can generate from and that has support at least as large as the support of $f$.\n\n\\begin{algorithm}\n\\caption{Importance Resampler}\n\\label{A:ImpReSampler}\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 only (a) and (b) above.\n\\item[(3)] a large enough integer $m$.\n\\end{itemize}\n}\n\\STATE {\\it output:} a sample $x{\\prime}$ from RV $X^{\\prime}$ with density $f^{\\prime}$ that is close to  $f$\n\\STATE Generate $y_1,\\ldots, y_m \\sim g$\n\\STATE Compute\n$$\nw_i=\\frac{f(y_i)/g(y_i)}{\\sum^m_{j=1}f(y_j)/g(y_j)},i=1,\\ldots,m \\enspace .\n$$\n\\STATE Resample $x^{\\prime}$ from $\\{y_1,\\ldots, y_m\\}$ with weights $\\{w_1,\\ldots, w_m\\}$\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{prop}The Importance Resampler of Algorithm~\\ref{A:ImpReSampler} produces samples from a variable $X^{\\prime}$ that is approximately distributed according to $f$, in the sense that:\n\\begin{equation}\n\\lim_{m\\rightarrow \\infty}\\P( X^{\\prime} \\leq t)=\\int^t_{-\\infty}f(x)dx\n\\end{equation}\nfor any real number $t$.\n\\begin{proof}\n\\begin{displaymath}\n\\begin{split}\n&\\P(X^{\\prime}\\leq t)=\\sum^m_{i=1}w_iI_{(-\\infty,t]}(y_i)=\\frac{\\frac{1}{m}\\sum^m_{i=1}\\frac{f(y_i)}{g(y_i)}I_{(-\\infty,t]}(y_i)}{\\frac{1}{m}\\sum^m_{i=1}\\frac{f(y_i)}{g(y_i)}}\\\\\n%\\end{displaymath}\n%\\begin{displaymath}\n&\\underrightarrow{^{m\\rightarrow\\infty}}\\frac{E [\\frac{f(y)}{g(y)}I_{(-\\infty,t]}(y)]}{E[\\frac{f(y)}{g(y)}]}=\\frac{\\int^t_{-\\infty}f(y)dy}{{\\int^{\\infty}_{-\\infty}f(y)dy}}=\\int^t_{-\\infty}f(y)dy\\\\\n\\end{split}\n\\end{displaymath}\n\\end{proof}\n\\end{prop}\n\nLet us visualise the Importance Resampler in action from \\hyperref[Mf:ImpResamplerCauchyViaNormal]{Labwork~\\ref*{Mf:ImpResamplerCauchyViaNormal}}.\n\n\\begin{labwork}[$\\cauchy$ RV via Importance Resampler]\nUse the sampling/importance resampling method to generate $1000$ approximate $\\cauchy$ samples  by using the $\\normal(0,1)$ samples:\n\n$$f(x)=\\frac{1}{\\pi(1+x^2)} \\textrm{ and  } g(x)=\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{x^2}{2}\\right).$$\n\n\\begin{VrbM}\nn = 1000;\nm = 10000;\ny = randn(1,m); % randn is the N(0,1) generator in Matlab\ny2 = y .* y;\nw = exp(0.5 * y2) ./ (1 + y2);\nw = w / sum(w);\nx = randsample(y,n,true,w); % resample n values from y weighted by w\n\\end{VrbM}\n\\end{labwork}\n\nNote that to get $n$ sample points from $f$ using sampling/importance resampling, we must start with a sample from $g$ of size $m$ larger than $n$.\n\nAs for the rejection method, the sampling/importance resampling method can still be used if only the un-normalised form of $f$ or $g$ (or both) is known, simply by using the un-normalised densities/mass functions to compute the weights.\n%%%%%%end Dominic's material\n}\n\n\\section{Other Continuous Random Variables}\\label{S:OtherContRVs}\nHere, we see other common continuous RVs that can be simulated from transforming RVs we have already encountered.\n%}%end remove\n%\\remove{\n\\begin{simulation}[$\\gammA(\\lambda,k)$ for integer $k$]\\label{SIM:Gamma}\nUsing this relationship we can simulate from $X \\sim \\gammA(\\lambda,k)$, for an integer-valued $k$, by simply summing $k$ IID samples from $\\exponential(\\lambda)$ RV as follows:\n\\begin{VrbM}\n>> lambda=0.1; %declare some lambda parameter\n>> k=5; % declare some k parameter (has to be integer)\n>> rand('twister',7267); % initialise the fundamental sampler\n>> % sum k IID Exponential(lambda) samples for one desired sample from Gamma(lambda,k)\n>> x= sum(-1/lambda*log(rand(k,1)))\nx =   28.1401\n>> % sum the 10 columns of k X 10 IID Exponential(lambda) samples for 10 desired samples from Gamma(lambda,k)\n>> x= sum(-1/lambda*log(rand(k,10)))\nx =\n   83.8150   61.2674   80.3683  103.5748   48.4454   20.2269   93.8310   56.1909   77.0656   29.0851\n\\end{VrbM}\n\\end{simulation}\n\n\\begin{model}[$\\lognormal(\\lambda,\\zeta)$]\n$X$ has a $\\lognormal(\\lambda,\\zeta) $ distribution if $\\log(X)$ has a $\\normal(\\lambda,\\zeta^2)$ distribution.  The location parameter $\\lambda = \\E(\\log(X)) > 0$ and the scale parameter $\\zeta > 0$.  The PDF is:\n\\begin{equation}\\label{E:LogNormalpdf}\nf(x; \\lambda, \\zeta) = \\frac{1}{\\sqrt{2 \\pi} \\zeta x }\n \\exp{\\left( - \\frac{1}{2 \\zeta^2} (\\log(x)-\\lambda)^2 \\right)}, \\qquad x > 0\n\\end{equation}\nNo closed form expression for $F(x;\\lambda,\\zeta)$ exists and it is simply defined as:\n\\[\nF(x;\\lambda,\\zeta) = \\int_{0}^x f (y;\\lambda,\\zeta)\\,dy\n\\]\nWe can express $F(x;\\lambda,\\zeta) $ in terms of $\\Phi$ (and, in turn, via the associated  error function $\\erf$) as follows:\n\\begin{equation}\\label{E:DFLogNormalviaErf}\nF(x;\\lambda,\\zeta) = \\Phi \\left( \\frac{\\log(x) - \\lambda}{\\zeta} \\right) = \\frac{1}{2} \\ \\erf \\left(  \\frac{\\log(x)-\\lambda}{\\sqrt{2}\\zeta} \\right)+ \\frac{1}{2}\n\\end{equation}\n\\end{model}\n%We implement the pdf \\eqref{E:LogNormalpdf} and DF \\eqref{E:DFLogNormalviaErf} for a $\\normal(\\mu,\\sigma^2)$ RV $X$ as \\Matlab functions {\\tt NormalPdf} and {\\tt NormalCdf}, respectively, in \\hyperref[Mf: NormalCdfPdf]{Labwork \\ref*{Mf: NormalCdfPdf}}  and then render their plots for various $\\normal(\\mu,\\sigma^2)$ RVs in \\hyperref[F:plotPdfCdfNormals]{Figure \\ref*{F:plotPdfCdfNormals}}.\n\n\\begin{labwork}[Simulations with the $\\lognormal(\\lambda_C,\\zeta_C)$ RV]\\label{LW:lognormal}\nTransform a sequence of samples obtained from the fundamental sampler to those from the $\\lognormal(\\lambda_C,\\zeta_C)$ RV $C$ by using only  \\hyperref[A:InvSbyNumSol]{Algorithm~\\ref*{A:InvSbyNumSol}} or \\Matlab's {\\tt randn} as an intermediate step.   [Hint: %Example 4.13 in Ang \\& Tang p.166-167.  There is a typo in this Example.  Note:\nIf $Y$ is a $\\normal(\\lambda,\\zeta^2)$ RV, then $Z=e^Y$ is said to be a $\\lognormal(\\lambda,\\zeta)$ RV.  ]\n\\begin{enumerate}\n\\item Seed the fundamental sampler by your Student ID,\n\\item generate $1000$ 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\n\\item and report:\n\\begin{enumerate}\n\\item how many of the samples are larger than $35000$,\n\\item the sample mean, and\n\\item the sample standard deviation.\n\\end{enumerate}\n\\end{enumerate}\n\n\\end{labwork}\n\nBeta RV\n\nChi-Square\n\nF distribution\n\nt-distribution\n\nWeibul\n\nHeavy-tail family\n\n\\section{Other Random Vectors}\\label{S:OtherRVecs}\n\nMultivariate Normal\n\nUniform Distribution on Sphere\n\nDirichlet Distribution\n%}% end remove\n\n\n\\begin{ExerciseList}\n\\Exercise\n{**}The covariance of two random variables $X$ and $Y$ is defined as\n\\[\n\\cv(X,Y) := \\E \\left((X-\\E(X))(Y-\\E(Y))\\right) = \\E(X Y) - \\E(X) \\E(Y) \\enspace .\n\\]\n\\begin{itemize}\n\\item[(a)] Show, starting from the definition, that $\\cv(X,Y) = \\E(XY)-\\E(X) \\E(Y)$.\n\\item[(b)] When $\\cv(X,Y)=0$, $X$ and $Y$ are said to be ``uncorrelated''.  \nShow that if $X$ and $Y$ are independent, then they are also uncorrelated.\n\\end{itemize}\n\n\\Exercise\n{**} Let $X_1,X_2,\\ldots,X_n$ be random variables.  \nTheir joint CDF is defined as \n\\[\nF(x_1,x_2,\\ldots,x_n) := \\P (X_1 \\leq x_1, X_2 \\leq x_2, \\ldots, X_n \\leq x_n) \\enspace.\n\\]\nBy repeated application of the definition of conditional probability, show that the joint CDF admits the following ``telescopic'' representation:\n\\begin{eqnarray*}\nF(x_1,x_2,\\ldots,x_n)\n&=&\nF(x_n \\mid x_1,\\ldots,x_{n-1}) F(x_{n-1} \\mid x_1,\\ldots,x_{n-2})\\cdots F(x_2 \\mid x_1) F(x_1)\\\\\n&=&\nF(x_1) \\prod_{i=2}^n F(x_i \\mid x_1,\\ldots,x_{i-1}) \\enspace ,\n\\end{eqnarray*}\nwhere, $F(x_i \\mid x_1,\\ldots,x_{i-1})$ denotes the conditional probability, $\\P(X_i \\leq x_i \\mid X_1 \\leq x_1,\\ldots,X_{i-1} \\leq x_{i-1})$. \n\\end{ExerciseList}\n\n%infinite coin-tosses and the fundamental model\n%\\remove{\n\\section{Problems}\n\\begin{exercise}\nIf $u\\sim U[0,1]$, show that the distribution of $1-u$ is also $U[0,1]$.\n\\end{exercise}\n\n\\begin{exercise}\nWrite a Matlab function to generate n random variables from the distribution with the following mass function:\n$$\\begin{array}{|c|c|c|c|c|c|}\\hline\nx\t&1.7\t&3.4\t&5.9\t&7.2&\t9.6\\\\ \\hline\nf(x)\t&0.15&\t0.4\t&0.05\t&0.1\t&0.3\\\\ \\hline\n\\end{array}$$\n\nUse your Matlab function to generate 1000 sample values from the distribution, and compare the relative frequencies obtained with the mass function probabilities.\n\\end{exercise}\n\n\\begin{exercise}\nThe Laplacian distribution is also called the double exponential distribution because it can be regarded as the extension of the exponential distribution for both positive and negative values. An easy way to generate a Laplacian$(0, 1)$ random variable is to generate an exponential(1) random variable and then change its sign to negative with probability 0.5. Write a Matlab function to generate $n$ Laplacian$(0, 1)$ random variables using the {\\tt expornd} function from Exercise 2.6.5. Call your function {\\tt laprnd}. It should take $n$ as input and produce a row vector containing the $n$ Laplacian$(0, 1)$ random variables as output.\n\\end{exercise}\n\n\\begin{exercise}\n\\begin{asparaenum}[(a)]\n\\item\tReferring to Example 2.2.3, write a \\Matlab function to generate $n$ $N(0, 1)$ random variables using the rejection method with the Laplacian$(0, 1)$ distribution. Include a counter for the number of iterations in your function.\n\n\\item\tUse your Matlab function to generate 1000 $N(0, 1)$ random variables. Plot the density histogram for your generated values and superimpose the $N(0, 1)$ density onto it. Compare the average number of iterations to get a single $N(0, 1)$ random variable with the constant a.\n\n\\item\tNow suppose that we know only the un-normalised $N(0, 1)$ and Laplacian$(0, 1)$ densities, i.e.:\n$$\\tilde{f}(x)=\\exp\\left( -\\frac{x^2}{2}\\right)\\textrm{ and }\\tilde{g}(x)=\\exp(-|x|)$$\n\n\nWhat is the constant $\\tilde{a}$ for the rejection method in this case? Implement the rejection method in Matlab, including a counter for the number of iterations, and use it to generate 1000 $N(0, 1)$ random variables. Compare the average number of iterations to get a single $N(0, 1)$ random variable with $a$ and $\\tilde{a}$.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nConsider (Ross, p.64.) the use of the rejection method to generate from the density:\n$$f(x)=20x(1-x)^3.$$\nfor $0 \\leq x\\leq   1$, using the $U (0, 1)$ distribution as proposal distribution.\n\\begin{asparaenum}[(a)]\n\\item Show that the constant for using the rejection method is $a = 2.1094$.\n\n\\item Write a \\Matlab function to generate n random variables from $f$ using the rejection method. Include a counter for the number of iterations in your function.\n\n\\item Use your \\Matlab function to generate 1000 random variables from $f$. Plot the density histogram for your generated values and superimpose the density curve onto it. Compare the average number of iterations to get a single random variable with the constant $a$.\n\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nConsider (Ross, .p65.) the use of the rejection method to generate from the density:\n$$f(x)=\\frac{2}{\\sqrt{\\pi}}x^{1/2}e^{-x}$$\nfor $x\\geq 0$, and using the exponential distribution with mean $m$ as proposal distribution.\n\n\n\\begin{asparaenum}[(a)]\n\\item Show that the constant for using the rejection method is:\n$$a=\\sqrt{\\frac{2}{\\pi e}}\\frac{m^{3/2}}{(m-1)^{1/2}}$$\n\n\\item Show that the best exponential distribution to use is the one with a mean of 3/2.\n\n\\item\tWrite a \\Matlab function to generate $n$ random variables from $f$ using the rejection method. Include a counter for the number of iterations in your function.\n\n\\item\tUse your \\Matlab function to generate 1000 random variables from $f$. Plot the density histogram for your generated values and superimpose the density curve onto it. Compare the average number of iterations to get a single random variable with the constant $a$.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\n\\begin{asparaenum}[(a)]\n\\item Referring to Example 2.3.3, implement the Matlab function to generate 1000 approximate Cauchy$(0,1)$ random variables using sampling/importance resampling, starting with $m = 10,000$ $N(0,1)$ sample values. Plot the density histogram for your generated values and superimpose the Cauchy$(0,1)$ density onto it.\n\n\\item Explore what happens if you start with \n\\begin{inparaenum}[(i)]\n\\item $m = 1000 N(0,1)$ sample values, \n\\item $m = 100000 N(0,1)$ sample values.\n\\end{inparaenum}\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nWrite a \\Matlab function to generate 1000 approximate Laplacian$(0,1)$ random variables using sampling/importance resampling with the $N(0,1)$ distribution. Plot the density histogram for your generated values and superimpose the Laplacian$(0,1)$ density onto it.\n\\end{exercise}\n\n\\begin{exercise}\nImplement the RWMH sampler in Example 2.4.8. Perform 10,000 iterations and plot the outputs sequentially. Comment on the appearance of the plot with regard to convergence to the target density. Plot the density histogram for the last 5000 iterations and superimpose the target density onto it. Investigate what happens when $g(\\cdot|x)=U(x-c,x+c)$ is used as the proposal density with different values of $c$ that are smaller or larger than 1. (Note: In \\Matlab, the modified Bessel function of the first kind is available as {\\tt besseli}.)\n\\end{exercise}\n%}\n", "meta": {"hexsha": "25f1030598127b3c6d8d50a68a7890599d2648c1", "size": 42244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/CommonRVs.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/CommonRVs.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/CommonRVs.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": 66.6309148265, "max_line_length": 1150, "alphanum_fraction": 0.6923823502, "num_tokens": 14863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.888758793492457, "lm_q1q2_score": 0.6785529085475933}}
{"text": "\\section{Definition}\r\n\\begin{definition}\r\n\tLet $f(t)$ be a function that is defined for $t \\geq 0$.\r\n\t\\begin{equation*}\r\n\t\t\\Laplace{f} = \\int_{0}^{\\infty}{e^{-st}f(t) \\mathrm{d}t}.\r\n\t\\end{equation*}\r\n\tThe domain of $F$ is all values of $s$ where the integral is defined and finite.\r\n\\end{definition}\r\n\r\n\\input{./laplaceTransforms/definition/stillLinear.tex}", "meta": {"hexsha": "b4e8905620ec4525194a1db3b1e73126220eac42", "size": 357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/definition/definition.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/laplaceTransforms/definition/definition.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/laplaceTransforms/definition/definition.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 35.7, "max_line_length": 82, "alphanum_fraction": 0.6806722689, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6785529037646548}}
{"text": "﻿\\documentclass[a4j]{jarticle}\n\\usepackage{fancybox,ascmac,amsmath,amssymb,graphicx}\n\\begin{document}\n\n\\section{Design of Butterworth Lowpass Filter}\n\n\\begin{itembox}[l]{{\\large {\\bf Butterworth Approximation}}}\n1. Define specification of the filter, \\( H_0 \\): DC Gain, \\( H_c \\): Gain at cutoff frequency, \\( H_s \\) Gain at stopband edge frequency, \\( \\omega_c \\): Cutoff frequency (rad/s), \\( \\omega_s \\): Stopband frequency (rad/s). \nAlso choose the optimization strategy: stopband edge frequency gain optimized or passband edge gain optimized.\\\\\n2. Calculate normalized cutoff frequency \\( \\Omega_s \\)\n\\begin{eqnarray*}\n\\Omega_{c} &=& 1 \\\\\n\\Omega_{s} &=& \\frac{\\omega_s}{\\omega_c}\n\\end{eqnarray*}\n3. Calculate \\( \\beta = \\beta_{max} \\) on stopband edge frequency gain optimized or \\( \\beta = \\beta_{min} \\) on passband edge gain optimized.\n\\begin{eqnarray*}\n\\beta_{max} = \\sqrt{\\left(\\frac{H_0}{H_c}\\right)^2-1}\\\\\n\\beta_{min} = \\sqrt{\\frac{\\left(\\frac{H_0}{H_s}\\right)^2-1}{\\Omega_s^2}}\n\\end{eqnarray*}\n4. Calculate the order of the filter \\( N \\) by rounding up \\( n_{fmin} \\) to the next integer:\n\\begin{eqnarray*}\nn_{fmin} &=& \\frac{\\log\\left(\\frac{{\\frac{H_0^2}{H_s^2}-1}}{{\\frac{H_0^2}{H_c^2}-1}}\\right)}{2\\log\\Omega_s}\n\\end{eqnarray*}\n5. Calculate \\( s_{k+} \\), the roots of the transfer function denominator polynomial equation:\n\\begin{eqnarray*}\ns_{k+} &=& \\sqrt[N]{\\frac{1}{\\beta}}\\mathrm{e}^{j\\left(\\frac{2k+1}{2N}\\pi+\\frac{\\pi}{2}\\right)}\\quad k=0,1, \\cdots N-1\n\\end{eqnarray*}\n\\end{itembox}\n\n\\clearpage\n\n{\\large {\\bf Example 1}} Determine the transfer function of Butterworth lowpass filter of stopband edge frequency gain optimized,\n \\( H_0 \\) = 1, \\( H_c \\) = 0.891 ( = -1dB) , \\( H_s \\) = 0.00398 ( = -48dB) ,\n Cutoff frequency = 125664 (=20kHz), Stopband edge frequency = 1108353 (=176.4kHz) \\\\\n\n{\\large {\\bf 1. Perform Butterworth Approximation}}\n\n\\begin{eqnarray*}\n\\Omega_{c} &=& 1 \\\\\n\\Omega_{s} &=& \\frac{\\omega_s}{\\omega_c} = 8.82 \\\\\nn_{fmin} &=& 2.85 \\\\\nN &=& Ceiling(2.85) = 3 \\\\\n\\beta_{max} &=& 0.509 \\\\\n\\textmc{angle of } s_k &=& \\frac{2k+1}{2N}\\pi + \\frac{\\pi}{2} \\\\\n\\textmc{magnitude of } s_k &=& \\beta^{\\frac{-1}{N}} \\\\\ns_k &=& magnitude \\left\\{ \\cos( angle ) + i\\sin( angle) \\right\\} \\\\\ns_0 &=& 1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\} \\\\\ns_1 &=& 1.25 \\left\\{ \\cos(\\pi) + i\\sin(\\pi) \\right\\} = -1.25\\\\\ns_2 &=& 1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\} \\\\\n\\textmc{Transfer function} H(s) &=& \\frac{1}{(s-1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\})(s+1.25)(s-1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\})}\n\\end{eqnarray*}\n\n{\\large {\\bf 2. Partial fraction decomposition}}\n\\begin{eqnarray*}\nH(s) &=& \\frac{1}{(s-1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\})(s+1.25)(s-1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\})}\\\\\n     &=& \\frac{c_1}{s-1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\}} + \\frac{c_2}{s+1.25} + \\frac{c_3}{s-1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\}}\\\\\nc_1  &=& \\frac{1}{(s+1.25)(s-1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\})}, s = 1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\} \\\\\n     &=& -0.6263-0.3616i \\\\\nc_2  &=& \\frac{1}{(s-1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\})(s-1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\})}, s = -1.25 \\\\\n     &=& 1.253 \\\\\nc_3  &=& \\frac{1}{(s-1.25 \\left\\{ \\cos(2.09) + i\\sin(2.09) \\right\\})(s+1.25)}, s = 1.25 \\left\\{ \\cos(4.19) + i\\sin(4.19) \\right\\} \\\\\n     &=& -0.6263+0.3616i \\\\\n\\therefore H(s) &=& \\frac{-0.6263-0.3616i}{s+0.6263-1.085i} + \\frac{1.253}{s+1.253} + \\frac{-0.6263+0.3616i}{s+0.6263+1.085i}\n\\end{eqnarray*}\n\n\\clearpage\n\n{\\large {\\bf 3. Multiply conjugate complex 1st order rational polynomial to get 2nd order rational polynomial with real value coefficients}}\n\n\\begin{eqnarray*}\nH(s) &=& \\frac{-0.6263-0.3616i}{s+0.6263-1.085i} + \\frac{1.253}{s+1.253} + \\frac{-0.6263+0.3616i}{s+0.6263+1.085i} \\\\\n     &=& \\frac{1.253}{s+1.253} + \\frac{-0.6263-0.3616i}{(s+0.6263-1.085i)(s+0.6263-1.085i)} \\\\\n     &=& \\frac{1.253}{s+1.253} + \\frac{0.523}{s^2+1.253s+1.569}\n\\end{eqnarray*}\n\n\n{\\large {\\bf 4. Create lossy integrator from 1st order rational polynomial}}\n\n\\begin{eqnarray*}\nH_{s1} &=& \\frac{A}{s+a} \\\\\n\\omega_c &=& 20000 * 2 * \\pi = 125663 \\\\\nR_{n0} &=& 1 \\\\\nC_{n0} &=& \\frac{a}{\\omega_c * R_0} \\\\\nR_{0}  &=& R_{n0} * 10000 = 10 (k\\Omega) \\quad  \\textmc{(frequency scaling)}\\\\\nC_{0}  &=& \\frac{C_0}{10000} = 996 \\textmc{(pF)} \\quad  \\textmc{(frequency scaling)} \\\\\n\\end{eqnarray*}\n\nBug: resulted circuit does not reflect A of the rational polynomial! \\\\\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=90mm,height=50mm,natwidth=900,natheight=500]{circuit.png} \\\\\nFigure 1\n\\end{figure}\n\n{\\large {\\bf 5. Create Sallen-Key lowpass filter from 2nd order rational polynomial}}\n\n\\begin{eqnarray*}\nH_{s2}   &=& \\frac{A}{s^2+as+b} \\\\\n\\omega_0 &=& \\sqrt{b} \\\\\n\\omega_c &=& 20000 * 2 * \\pi = 125663 \\\\\nQ        &=& \\frac{\\omega_0}{a} \\\\\nC_{n2}   &=& 1 \\\\\nC_{n1}   &=& \\sqrt{3}*Q*C_{n2} \\\\\nR_{n1}   &=& \\frac{1}{\\omega_0 * Q * C_{n2}} \\\\\nR_{n2}   &=& \\frac{1}{\\sqrt(3)*\\omega_0 *C_{n2}} \\\\\nC_{1}    &=& \\frac{C_{n1}}{\\omega_c * 10000} = 1.38 \\textmc{(nF)} \\quad \\textmc{(frequency scaling)} \\\\\nC_{2}    &=& \\frac{C_{n2}}{\\omega_c * 10000} = 796 \\textmc{(nF)} \\quad \\textmc{(frequency scaling)}  \\\\\nR_{1}    &=& R_{n1} * 10000 = 7.98 (k\\Omega) \\quad \\textmc{(frequency scaling)}  \\\\\nR_{2}    &=& R_{n2} * 10000 = 4.61 (k\\Omega) \\quad \\textmc{(frequency scaling)} \n\\end{eqnarray*}\n\nBug: resulted circuit does not reflect A of the rational polynomial!\n\n\\end{document}\n\n", "meta": {"hexsha": "22856a172d6eb033f386f317561cf012405919f1", "size": 5495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "00Experiments/tex/ButterworthLowpassFilter.tex", "max_stars_repo_name": "yamamoto2002/bitspersampleconv2", "max_stars_repo_head_hexsha": "331a9fc531269e5dfdc78548e583f793a7687dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "00Experiments/tex/ButterworthLowpassFilter.tex", "max_issues_repo_name": "yamamoto2002/bitspersampleconv2", "max_issues_repo_head_hexsha": "331a9fc531269e5dfdc78548e583f793a7687dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "00Experiments/tex/ButterworthLowpassFilter.tex", "max_forks_repo_name": "yamamoto2002/bitspersampleconv2", "max_forks_repo_head_hexsha": "331a9fc531269e5dfdc78548e583f793a7687dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-12T06:55:18.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-12T06:55:18.000Z", "avg_line_length": 46.9658119658, "max_line_length": 225, "alphanum_fraction": 0.6038216561, "num_tokens": 2374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571774, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.6784357549167039}}
{"text": "\\subsection{Vectors and physics}\n\nSuppose you push\non something. Then, your push is made up of two components, how hard you push and the direction you push. This illustrates the concept of force.\n\n\\begin{definition}{Force}{force}\n\\textbf{Force}\\index{force} is a vector. The magnitude of this vector is a measure of how\nhard it is pushing. It is measured in Newtons\\index{Newton}. The direction of this vector is the direction in which the push is taking place.\n\\end{definition}\n\nVectors are used to model force and other physical vectors like velocity.\n As with all vectors, a vector modelling force has two essential\ningredients, its magnitude and its direction.\n\nRecall the special vectors which point along the coordinate axes.\nThese are given by\n\\begin{equation*}\n\\vect{e}_{i} = \\mat{0,\\ldots,0,1,0,\\ldots,0}^T\n\\end{equation*}\nwhere the $1$ is in the $i\\th$ slot and there are zeros in all the other\nspaces. The direction of $\\vect{e}_{i}$ is referred to as the $i\\th$ direction.\n\nConsider the following picture which illustrates the case of $\\R^{3}$.\nRecall that in $\\R^3$, we may refer to these vectors as $\\vect{i}, \\vect{j}$, and $\\vect{k}$.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw(0,0,2.5)--(0,0,0)--(0,0,-2);\n\\draw(-2,0,0)--(0,0,0)--(2,0,0);\n\\draw(0,-2,0)--(0,0,0)--(0,2,0);\n\\draw[ultra thick, ->, red](0,0,0)--(0,0,1.5);\n\\draw[ultra thick, ->, blue](0,0,0)--(0,1,0);\n\\draw[ultra thick, ->, green](0,0,0)--(1,0,0);\n\\node[left] at (0,0,2.5){$x$};\n\\node[below] at (2,0,0){$y$};\n\\node[above] at (0,2,0){$z$};\n\\node[left] at (-0.2,0,1){$\\vect{e}_1$};\n\\node[below] at (1,0,0){$\\vect{e}_2$};\n\\node[left] at (0,1,0){$\\vect{e}_3$};\n\\end{tikzpicture}\n\\end{center}\n\nGiven a vector $\\vect{u}=\\mat{u_{1},\\ldots,u_{n}}^T$, it follows\nthat\n\\begin{equation*}\n\\vect{u}=u_{1}\\vect{e}_{1}+\\ldots +u_{n}\\vect{e}_{n}=\n\\sum_{k=1}^{n}u_{i}\\vect{e}_{i}\n\\end{equation*}\n\nWhat does addition of vectors mean physically? Suppose two forces are\napplied to some object. Each of these would be represented by a force vector\nand the two forces acting together would yield an overall force acting on\nthe object which would also be a force vector known as the\nresultant\\index{resultant}. Suppose the two vectors are $\\vect{u}=\\sum_{k=1}^{n}u_{i}\\vect{e}_{i}$ and $\\vect{v}=\\sum_{k=1}^{n}v_{i}\\vect{e}_{i}$. Then the vector $\\vect{u}$ involves a component in the $\ni\\th$ direction given by $u_{i}\\vect{e}_{i}$, while the component in the $i\\th$\ndirection of $\\vect{v}$ is $v_{i}\\vect{e}_{i}$. Then the vector $\\vect{u} + \\vect{v}$ should have a component in the $i\\th$\ndirection equal to $(u_{i}+v_{i}) \\vect{e}_{i}$. This is\nexactly what is obtained when the vectors, $\\vect{u}$ and $\\vect{v}$ are\nadded.\n\\begin{eqnarray*}\n\\vect{u}+\\vect{v}& =&\\mat{u_{1}+v_{1},\\ldots,u_{n}+v_{n}}^T  \\\\\n& =&\\sum_{i=1}^{n}(u_{i}+v_{i}) \\vect{e}_{i}\n\\end{eqnarray*}\n\nThus the addition of vectors according to the rules of addition in $\\R^{n}$ which were presented earlier, yields the appropriate vector which\nduplicates the cumulative effect of all the vectors in the sum.\n\nConsider now some examples of vector addition.\n\n\\begin{example}{The resultant of three forces}{resultant-three-forces}\nThere are three ropes attached to a car and three people pull on these\nropes. The first exerts a force of $\\vect{F}_1 =\n2\\vect{i} + 3\\vect{j} -2 \\vect{k}$ Newtons, the second exerts a force of $\\vect{F}_2\n=\n3\\vect{i}+5\\vect{j}+\\vect{k}$ Newtons\nand the third exerts a force of $5\\vect{i}-\\vect{j}+2\\vect{k}$ Newtons. Find\nthe total force in the direction of $\\vect{i}$.\n\\end{example}\n\n\\begin{solution}\nTo find the total force, we add the vectors as described above.\nThis is given by\n\\begin{eqnarray*}\n&&(2\\vect{i}+3\\vect{j}-2\\vect{k}) + (3\\vect{i}+5\\vect{j}+\\vect{k}) + (5\\vect{i}-\\vect{j}+2\\vect{k})\\\\\n&=&\n(2  + 3 + 5) \\vect{i} + (3 + 5 + -1) \\vect{j} + (-2+1+2) \\vect{k} \\\\\n&=&\n10 \\vect{i} + 7 \\vect{j} + \\vect{k}\n\\end{eqnarray*}\nHence, the total force is  $10\\vect{i}+7\\vect{j}+\\vect{k}$ Newtons. Therefore, the force in the $\n\\vect{i}$ direction is $10$ Newtons.\n\\end{solution}\n\nConsider another example.\n\n\\begin{example}{Finding a vector from geometric description}{vector-from-geometric-description}\nAn airplane flies North East at $100\\textrm{km}/\\textrm{h}$. Write this as a vector.\n\\end{example}\n\n\\begin{solution}\nA picture of this situation follows.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw(-2,0)--(2,0);\n\\draw(0,-2)--(0,2);\n\\draw[ultra thick, ->, blue](0,0)--(2.5,2.5);\n\\end{tikzpicture}\n\\end{center}\n\nTherefore, we need to find the vector $\\vect{u}$ which has length 100 and direction as shown in this diagram.\nWe can consider the vector $\\vect{u}$ as the hypotenuse of a\nright triangle having equal sides, since the direction of $\\vect{u}$ corresponds with the $45 ^{\\circ}$ line.\nThe sides, corresponding to the $\\vect{i}$ and $\\vect{j}$ directions,  should be each of length 100/$\n\\sqrt{2}$. Therefore, the vector is given by\n\\[\n \\vect{u} = \\frac{100}{\\sqrt{2}} \\vect{i}+ \\frac{100}{\\sqrt{2\n}}\\vect{j}\n=\n\\begin{mymatrix}{rr}\n\\vspace{0.05in} \\frac{100}{\\sqrt{2}} & \\vspace{0.05in}\\frac{100}{\\sqrt{2}}\n\\end{mymatrix}^T\\\n\\]\n\\end{solution}\n\nThis example also motivates the concept of \\textbf{velocity}, defined below.\n\n\\begin{definition}{Speed and velocity}{speed-velocity}\nThe \\textbf{speed}\\index{speed} of an object is a measure of how fast it is going. It is\nmeasured in units of length per unit time. For example, kilometers per\nhour, meters per second. The\n\\textbf{velocity}\\index{velocity} is a vector having the speed as the\nmagnitude but also specifying the direction.\n\\end{definition}\n\nThus the velocity vector in the above example is $\\vspace{0.05in}\\frac{100}{\\sqrt{2}}\\vect{i}+\n\\vspace{0.05in}\\frac{100}{\\sqrt{2}}\\vect{j}$, while the speed is $100\\textrm{km}/\\textrm{h}$.\n\nConsider the following example.\n\n\\begin{example}{Position from velocity and time}{position-velocity-time}\nThe velocity of an airplane is $100\\vect{i}+\\vect{j}+\\vect{k}$\nmeasured in kilometers per hour and at a certain instant of time its\nposition is $(1,2,1)$.\n\nFind the position of this airplane one minute later.\n\\end{example}\n\n\\begin{solution}\nHere imagine a Cartesian coordinate\nsystem in which the third component is altitude and the first and second\ncomponents are measured on a line from West to East and a line from South to\nNorth.\n\nConsider the vector $\n\\begin{mymatrix}{rrr}\n1 & 2 & 1\n\\end{mymatrix}^T$, which is the initial position vector\nof the airplane. As the plane moves, the position vector changes according to the velocity vector.\nAfter one minute (considered as $\\frac{1}{60}$ of an hour)\nthe airplane has moved in the $\\vect{i}$ direction a distance of\n$100\\times \\frac{1}{60}= \\frac{5}{3}$ kilometer. In the $\\vect{j}\n$ direction it has moved $\\frac{1}{60}$ kilometer during this same time,\nwhile it moves $\\frac{1}{60}$ kilometer in the $\\vect{k}$ direction.\n%\\begin{picture}(1,425)\\end{picture}\nTherefore, the new displacement vector for the airplane is\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 2 & 1\n\\end{mymatrix}^T +\n\\begin{mymatrix}{rrr}\n\\frac{5}{3} & \\frac{1}{60} & \\frac{1}{60}\n\\end{mymatrix}^T\n=\\begin{mymatrix}{rrr}\n\\frac{8}{3} & \\frac{121}{60} & \\frac{121}{60}\n\\end{mymatrix}^T\n\\end{equation*}\n\\end{solution}\n\nNow consider an example which involves combining two velocities.\n\n\\begin{example}{Sum of two velocities}{sum-of-two-velocities}\nA certain river is one half kilometer wide with a current flowing at 4 kilometers per\nhour from East to West. A man swims directly toward the opposite shore from\nthe South bank of the river at a speed of 3 kilometers per hour. How far down the\nriver does he find himself when he has swam across? How far does he end up\nswimming?\n\\end{example}\n\n\\begin{solution}\nConsider the following picture which demonstrates the above scenario.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw(-3,1)--(2,1);\n\\draw(-3,-1)--(2,-1);\n\\draw[ultra thick, blue, ->](1,0)--(-3,0);\n\\draw[ultra thick, blue, ->](1,0)--(1,3);\n\\node[above] at (-1,0){$4$};\n\\node[right] at (1,2){$3$};\n\\end{tikzpicture}\n\\end{center}\n\nFirst we want to know the total time of the swim across the river.\nThe velocity in the direction across the river is\n$3$ kilometers per hour, and the river is $\\frac{1}{2}$ kilometer wide. It follows the trip\ntakes $1/6$ hour or $10$ minutes.\n\nNow, we can compute how far downstream he will end up. Since the river runs at a rate of\n$4$ kilometers per hour, and the trip takes $1/6$ hour, the distance travelled downstream\nis given by $4 \\paren{\\frac{1}{6}} = \\frac{2}{3}$ kilometers.\n\nThe distance travelled by the swimmer is given by the hypotenuse of a right triangle.\nThe two arms of the triangle are given by the distance across the river, $\\frac{1}{2}$km, and\nthe distance travelled downstream, $\\frac{2}{3}$ km. Then, using the Pythagorean Theorem, we can calculate\nthe total distance $d$ travelled.\n\\begin{equation*}\nd\n=\n\\sqrt{ \\paren{\\frac{2}{3}}^2 + \\paren{\\frac{1}{2}} ^2 }\n=\n\\frac{5}{6} \\mbox{km}\n\\end{equation*}\n\nTherefore, the swimmer travels a total distance of $\\frac{5}{6}$ kilometers.\n\\end{solution}\n", "meta": {"hexsha": "ed55e0619dabceac2460c5eac6177329f200e014", "size": 9050, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsApplicationsPhysics.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/RnVectorsApplicationsPhysics.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/RnVectorsApplicationsPhysics.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.8678414097, "max_line_length": 203, "alphanum_fraction": 0.701878453, "num_tokens": 2963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867825403176, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.6784357533999903}}
{"text": "\\chapter{Propositional Formulas}\n\\label{chapter:propositional-formulas}\n\\marginurl{%\n  Propositional Formulas:\\\\\\noindent\n  Introduction to Mathematical Logic \\#1\n}{youtu.be/X0797bVFf3Y}\n\n\nThis part, as it follows from the title, is devoted to mathematical logic,\na mathematical approach to a branch of philosophy called logic. Logic studies\nreasoning and mathematical logic studies mathematical reasoning. As we have\nmentioned in \\Cref{chapter:proofs} proofs in mathematics consists of\n\\emph{sentences} of a certain structure that are connected by implications.\nIn addition,  as we discussed in \\Cref{chapter:predicates}, we can build larger\nsentences from smaller ones using connectives.\n\nNote that in real life the sentences are written using common English which is\nambiguous and therefore hard for analysis.\nSo to create a formal description of mathematics we need to create an\nartificial formal language for mathematics.\n\nFirst\n(\\Cref{chapter:propositional-formulas,chapter:propositional-truth,chapter:propositional-deduction}) \nwe will define a language for propositional (sentential) logic; i.e. the logic\nwhich deals only with propositions. Later (\\Cref{chapter:predicate-formulas}) we\nextend it to a logic which also takes properties of individuals into account.\n\nThe process of formalization of propositional logic consists of two main parts:\n\\begin{itemize}\n  \\item present a formal language,\n  \\item specify a procedure for obtaining valid or true propositions.\n\\end{itemize}\n\n\\section{Definition of Formulas}\n\nStatements in  propositional logic are either some independent atomic\nstatements, or are formed from the atomic one using connectives.\n\nIn other words, statements in propositional logic can be defined using\npropositional formulas (also known as sentential formulas or Boolean formulas).\n\\begin{definition}\n  We say that a finite sequence $\\phi$ of elements of the set\n  $V \\cup \\set{\\lnot, \\lor, \\land, \\limplies, \\text{``(''}, \\text{``)''}}$\n  is a propositional formula on the variables from $V$ if\n  \\begin{itemize}\n    \\item either $\\phi$ is equal to $x$ for some $x \\in V$,\n    \\item or $\\phi$ is equal to $(\\psi_1 \\land \\psi_2)$, or\n      $(\\psi_1 \\lor \\psi_2)$, or $(\\psi_1 \\limplies \\psi_2)$,\\footnote{%\n        The symbol $\\limplies$ is used to denote the implication.\n        Due to historical reasons the standard symbol $\\implies$ is rarely\n        used as a connective in mathematical logic; hence, we will use\n        $\\limplies$ instead of $\\implies$ in this part of the book.\n        It is important to note that, sometimes the symbol $\\supset$ is also\n        used instead of $\\implies$.\n      }\n      where $\\psi_1$ and $\\psi_2$ are propositional formulas on the variables\n      from $V$,\n    \\item or $\\phi$ is equal to $(\\lnot \\psi)$, where $\\psi$ is a propositional\n      formula on the variables from $V$.\n  \\end{itemize}\n\n  We denote the set of all propositional formulas by $\\prop{V}$.\n\\end{definition}\n\nFor example, $((x_1 \\lor (\\lnot x_2)) \\land x_3)$ is a propositional formula on\nthe variables from $\\set{x_1, x_2, x_3}$ (we also say that it is a formula on\n$x_1$, $x_2$, $x_3$).\n\n\\begin{exercise}\n  Write the definition of propositional formulas using the terminology\n  ``the set generated by \\dots from \\dots'' (see \\Cref{chapter:functions}).\n\\end{exercise}\n\nHereafter when naming formulas, we will not mention explicitly all the\nparenthesis. To establish a more compact notation, we adopt the following\nconventions.\n\\begin{itemize}\n  \\item The outermost parentheses do not need to be explicitly mentioned; e.g.,\n    we write ``$A \\land B$'' to refer to $(A \\land B)$.\n  \\item The negation symbol applies to as little as possible.\n    For example, $\\lnot A \\land B$ denotes $(\\lnot A) \\land B$;\n    i.e., $((\\lnot A) \\land B)$. Which is not the same as\n    $(\\lnot (A \\land B))$.\n  \\item The conjunction and disjunction symbols apply to as little as possible,\n    given that convention 2 is to be observed. For example,\n    $A \\land B \\limplies \\lnot C \\lor D$ is\n    $((A \\land B) \\limplies ((\\lnot C) \\lor D))$.\n  \\item Where one connective symbol is used repeatedly, grouping is to the\n    right: $A \\land B \\land C$ is $A \\land (B \\land C)$,\n    $A \\limplies B \\limplies C$ is $A \\limplies (B \\limplies C)$.\n\\end{itemize}\n\nInterpreting propositional logic is not difficult since the considered entities\nhave a simple structure. The propositions are built up from rough blocks by\nadding connectives. The simplest parts (atoms) are of the form ``cows are\nanimals'', ``Earth is flat'', ``$2 \\times 2 = 2$'', which are simply true or\nfalse. We extend this assignment of truth values to composite propositions, by\nreflection on the meaning of the logical connectives.\n\n\\begin{definition}\n  A function $v : \\prop{V} \\to \\set{\\ltrue, \\lfalse}$ is a valuation if\n  \\begin{itemize}\n    \\item $v(\\lnot \\psi) = \\lnot v(\\psi)$,\n    \\item $v(\\psi_1 \\land \\psi_2) = v(\\psi_1) \\land v(\\psi_2)$,\n    \\item $v(\\psi_1 \\lor \\psi_2) = v(\\psi_1) \\lor v(\\psi_2)$, and\n    \\item $v(\\psi_1 \\limplies \\psi_2) = v(\\psi_1) \\limplies v(\\psi_2)$.\n  \\end{itemize}\n\\end{definition}\n\nWe may note that all the valuations are actually can be defined by the values\nof variables.\n\\begin{theorem}\n  Let $\\rho : V \\to \\set{\\ltrue, \\lfalse}$ be a function (we say that $\\rho$ is\n  a propositional assignement). Then there is a unique valuation\n  $\\substitute{\\cdot}{\\rho} : \\prop{V} \\to \\set{\\ltrue, \\lfalse}$ such that\n  $\\substitute{x}{\\rho} = \\rho(x)$ for any $x \\in V$.\n\\end{theorem}\n\nSince any valuation can be defined by the values assigned to variables, we need\nto introduce the following notation.\nIf $V = \\set{x_1, \\dots, x_n}$ and $v_1, \\dots, v_n \\in \\set{\\ltrue, \\lfalse}$,\nthen $\\substitute{\\cdot}{x_1 = v_1, \\dots, x_n = v_n}$ denotes the valuation\nsuch that $\\substitute{x_i}{x_1 = v_1, \\dots, x_n = v_n} = v_i$ for each\n$i \\in \\range{n}$.\n\n\nFor example, the value of a formula $(x_1 \\land \\lnot x_2) \\lor x_3$ when\n$\\ltrue$ is substituted as the value of $x_1$, $\\ltrue$ is substituted as the\nvalue of $x_2$, and $\\lfalse$ is substituted as the value of $x_3$ is equal to\n$(\\ltrue \\land \\lfalse) \\lor \\lfalse = \\lfalse$.\n\nNote that if $\\phi$ is a formula on the variables from $V$ it does not mean that\nall the variables from $V$ have to be used.\nFor example, $x_1$ is a formula on the variables from $\\set{x_1, x_2}$; however,\n$x_2$ is not used in the formula.\n\n\\begin{exercise}\n  Give a formal definition (using structural induction) of the set of all the\n  variables that are used in a propositional formula $\\phi$ on variables from a\n  set $V$.\n\\end{exercise}\n\nLet $\\phi$ be a formula on the variables from a set $V$. The definition\nof a value of a formula requires us to specify all the values of all the\nvariables from $V$. However, the following theorem shows that in\nfact we need to specify only the variables that are actually used in $\\phi$.\n\\begin{theorem}\n  Let $\\phi$ be a formula $\\phi$ on the variables from a set $V$,\n  and $U$ be the set of the variables used in $\\phi$.\n\n  Consider $\\rho_1, \\rho_2 : V \\to \\set{\\ltrue, \\lfalse}$ such that\n  $\\rho_1(x) = \\rho_2(x)$ for any $x \\in U$.\n  Then $\\substitute{\\phi}{\\rho_1} = \\substitute{\\phi}{\\rho_2}$.\n\\end{theorem}\n\\begin{proof}\n  We prove the statement using the structural induction.\n  \\begin{description}\n    \\item[(base case)] Let $\\phi = x$ for some $x \\in V$.\n      Note that $x \\in U$ and $\\substitute{\\phi}{\\rho_1} = \\rho_1(x) =\n      \\rho_2(x) = \\substitute{\\phi}{\\rho_2}$.\n    \\item[(induction step)] We need to consider the following three cases.\n      \\begin{itemize}\n        \\item Let $\\phi$ be equal to $\\psi_1 \\land \\psi_2$ such that\n          $\\substitute{\\psi_1}{\\rho_1} = \\substitute{\\psi_1}{\\rho_2}$ and\n          $\\substitute{\\psi_1}{\\rho_2} = \\substitute{\\psi_2}{\\rho_2}$.\n          In this case,\n          \\[\n            \\substitute{\\phi}{\\rho_1} =\n            (\\substitute{\\psi_1}{\\rho_1} \\land \\substitute{\\psi_2}{\\rho_1} )=\n            (\\substitute{\\psi_1}{\\rho_2} \\land \\substitute{\\psi_2}{\\rho_2}) =\n            \\substitute{\\phi}{\\rho_2}.\n          \\]\n        \\item Let $\\phi$ be equal to $\\psi_1 \\lor \\psi_2$ such that\n          $\\substitute{\\psi_1}{\\rho_1} = \\substitute{\\psi_1}{\\rho_2}$ and\n          $\\substitute{\\psi_1}{\\rho_2} = \\substitute{\\psi_2}{\\rho_2}$.\n          In this case,\n          \\[\n            \\substitute{\\phi}{\\rho_1} =\n            (\\substitute{\\psi_1}{\\rho_1} \\lor \\substitute{\\psi_2}{\\rho_1}) =\n            (\\substitute{\\psi_1}{\\rho_2} \\lor \\substitute{\\psi_2}{\\rho_2}) =\n            \\substitute{\\phi}{\\rho_2}.\n          \\]\n        \\item Let $\\phi$ be equal to $\\psi_1 \\limplies \\psi_2$ such that\n          $\\substitute{\\psi_1}{\\rho_1} = \\substitute{\\psi_1}{\\rho_2}$ and\n          $\\substitute{\\psi_1}{\\rho_2} = \\substitute{\\psi_2}{\\rho_2}$.\n          In this case,\n          \\[\n            \\substitute{\\phi}{\\rho_1} =\n            (\\substitute{\\psi_1}{\\rho_1} \\limplies \\substitute{\\psi_2}{\\rho_1}) =\n            (\\substitute{\\psi_1}{\\rho_2} \\limplies \\substitute{\\psi_2}{\\rho_2}) =\n            \\substitute{\\phi}{\\rho_2}.\n          \\]\n      \\end{itemize}\n  \\end{description}\n\\end{proof}\n\n\\begin{exercise}\n  Let $\\phi_1$, $\\phi_2$, and $\\phi_3$ be propositional formulas on the\n  variables from a set $V$. Show that for any propositional assignement\n  $\\rho$ to $V$,\n  $\\substitute{\\phi_1 \\land (\\phi_2 \\land \\phi_3)}{\\rho} =\n   \\substitute{(\\phi_1 \\land \\phi_2) \\land \\phi_3}{\\rho}$.\n\\end{exercise}\n\n\\section{Conjunctive and Disjuctive Normal Form}\n\nLet $\\phi_1$, \\dots, $\\phi_n$ be some propositional formulas. Then\n\\begin{itemize}\n  \\item $\\bigland_{i = 1}^1 \\phi_i = \\phi_1$ and\n    $\\biglor_{i = 1}^1 \\phi_i = \\phi_1$, and\n  \\item $\\bigland_{i = 1}^{k + 1} \\phi_i =\n    (\\bigland_{i = 1}^{k} \\phi_i) \\land \\phi_{k + 1}$ and\n    $\\biglor_{i = 1}^{k + 1} \\phi_i =\n      (\\biglor_{i = 1}^{k} \\phi_i) \\lor \\phi_{k + 1}$.\n\\end{itemize}\nIn other words $\\bigland_{i = 1}^n \\phi_i$ and $\\biglor_{i = 1}^n \\phi_i$\ndenotes the conjunction of the formulas $\\phi_1$, \\dots, $\\phi_n$, and\n$\\biglor_{i = 1}^n \\phi_i$ denotes the disjunction of them.\n\n\\begin{exercise}\n  Let $\\phi_1$, \\dots, $\\phi_n$, $\\psi_1$, \\dots, $\\psi_m$, $\\chi_1$, \\dots,\n  $\\chi_{n + m}$ be some propositional formulas on the variables from $V$\n  such that $\\chi_i = \\phi_i$ for $i \\le n$ and $\\chi_i = \\psi_{i - n}$ for\n  $n < i \\le m$. Show that\n  $\\substitute{\\left(\\bigland_{i = 1}^n \\phi_i\\right) \\land\n    \\left(\\bigland_{i = 1}^n \\psi_i\\right)}{\\rho} =\n  \\substitute{\\left(\\bigland_{i = 1}^{n + m} \\chi_i\\right)}{\\rho}$\n  for any propositional assignement $\\rho$ to $V$.\n\\end{exercise}\n\n\nUsing this notation we may show that propositional formulas can represent all\nthe Boolean functions (functions from $\\set{\\ltrue, \\lfalse}^n$ to\n$\\set{\\ltrue, \\lfalse}$).\n\\begin{theorem}\n\\label{theorem:function-to-formula}\n  For any function $f : \\set{\\ltrue, \\lfalse}^n \\to\n  \\set{\\ltrue, \\lfalse}$ there is a\n  formula $\\phi$ on the variables $x_1$, \\dots, $x_n$ such that\n  $\\substitute{\\phi}{x_1 = v_1, \\dots, x_n = v_n} = f(v_1, \\dots, v_n)$ for all\n  $v_1, \\dots, v_n \\in \\set{\\ltrue, \\lfalse}$.\n\\end{theorem}\n\nLet $u \\in \\set{\\ltrue, \\lfalse}$ and $x \\in V$. Then $x^u$ denotes a\nformula on the variables from $V$ such that $x^u = x$ if $u = \\ltrue$ and\n$x^u = \\lnot x$ if $u = \\lfalse$. Note that $\\substitute{x^u}{\\rho} = \\ltrue$\niff $\\rho(x) = u$, for any propositional assignement $\\rho$ to $V$.\nIndeed, if $u = \\ltrue$, then $x^u = x$ and\n$\\ltrue = \\substitute{x^u}{\\rho} = \\substitute{x}{\\rho} = \\rho(x)$ so\n$\\rho(x) = \\ltrue = u$;\nif $u = \\lfalse$, then $x^u = \\lnot x$ and\n$\\ltrue = \\substitute{x^u}{\\rho} = \\substitute{\\left(\\lnot x\\right)}{\\rho} =\n\\lnot \\rho(x)$ so $\\rho(x) = \\lfalse = u$.\n\n\\begin{exercise}\n  Let $\\phi_1$, \\dots, $\\phi_k$ are propositional formulas\n  on the variables from $V$.\n  \\begin{itemize}\n    \\item Show that\n      $\\substitute{\\left(\\biglor_{i = 1}^k \\phi_i\\right)}{\\rho} = \\ltrue$ iff\n      $\\substitute{\\phi}{\\rho} = \\ltrue$ for some $i \\in \\range{k}$.\n    \\item Show that\n      $\\substitute{\\left(\\bigland_{i = 1}^k \\phi_i\\right)}{\\rho} = \\ltrue$ iff\n      $\\substitute{\\phi}{\\rho} = \\ltrue$ for all $i \\in \\range{k}$.\n  \\end{itemize}\n\\end{exercise}\n\nUsing this observation and the exercise we can\nprove~\\Cref{theorem:function-to-formula}.\n\\begin{proof}\n  Let $S = \\set[f(u_1, \\dots, u_n) = \\ltrue]{(u_1, \\dots, u_n) \\in\n    \\set{\\ltrue, \\lfalse}^n}$.\n  Assume that\n  $S = \\set{(u_{1, 1}, \\dots, u_{1, n}), \\dots, (u_{k, 1}, \\dots, u_{k, n})}$.\n  By the previous observations\n  \\[\n    \\substitute{\n      \\left(\n        \\biglor_{i = 1}^k\n          \\bigland_{j = 1}^n x_j^{u_{i, j}}\n      \\right)\n    }{x_1 = v_1, \\dots, x_n = v_n}\n    =\n    f(v_1, \\dots, v_n)\n  \\]\n  for all $v_1, \\dots, v_n \\in \\set{\\ltrue, \\lfalse}$.\n  (Note that we have not considered the case when $S = \\emptyset$, in this\n  case $f$ is a constant $\\lfalse$ function and it is equal to\n  $x_1 \\land \\lnot x_1$.)\n\\end{proof}\n\nOne may notice that the formulas we constructed have very specific form,\nsuch a form is called disjunctive normal form (DNF).\n\\begin{definition}\n  We say that a propositional formula $\\lambda$ on the variables from $V$\n  is a \\emph{literal} if it is equal to $x$ or to $\\lnot x$ for some\n  $x \\in V$.\n\n  We say that a propositional formula $\\psi$ on the variables from $V$ is\n  a \\emph{term} if $\\psi$ is equal to $\\bigland_{i = 1}^\\ell \\lambda_i$, where $\\lambda_1$, \\dots, $\\lambda_\\ell$ are literals.\n\n  Finally, we say that a propositional formula $\\phi$ on the variables from\n  $V$ is in \\emph{disjunctive normal form} (DNF) if $\\phi$ is equal to\n  $\\biglor_{i = 1}^k \\psi_i$, where $\\psi_1$, \\dots, $\\psi_k$ are\n  terms.\n\\end{definition}\n\nHowever, there is nothing special in this order of operations (disjunction of\nconjunctions). So we can define conjunctive normal form (CNF) too.\n\\begin{definition}\n  We say that a propositional formula $\\psi$ on the variables from $V$ is\n  a \\emph{clause} if $\\psi$ is equal to $\\biglor_{i = 1}^\\ell \\lambda_i$, where\n  $\\lambda_1$, \\dots, $\\lambda_\\ell$ are literals.\n\n  Finally, we say that a propositional formula $\\phi$ on the variables from\n  $V$ is in \\emph{conjunctive normal form} (DNF) if $\\phi$ is equal to\n  $\\bigland_{i = 1}^k \\psi_i$, where $\\psi_1$, \\dots, $\\psi_k$ are\n  clauses.\n\\end{definition}\n\nUsing the following simple trick we can prove that any function\nhas a representation in CNF. First, we define a function\n$g(x_1, \\dots, x_n) = \\lnot f(x_1, \\dots, x_n)$. Secondly, we may notice that\n\\[\n  \\substitute{\n    \\left(\n      \\lnot\n      \\left(\n        \\bigland_{i = 1}^k \\biglor_{j = 1}^n \\phi_{i, j}\n      \\right)\n    \\right)\n  }{x_1 = v_1, \\dots, x_n = v_n}\n  =\n  \\substitute{\n    \\left(\n      \\biglor_{i = 1}^k \\bigland_{j = 1}^n \\lnot \\phi_{i, j}\n    \\right)\n  }{x_1 = v_1, \\dots, x_n = v_n}\n\\]\nfor all $v_1, \\dots, v_n \\in \\set{\\ltrue, \\lfalse}$\n% THE REFERENCE TO THE EXERCISE\n(see Exercise 15.7). Therefore the negation\nof a formula in DNF can be easily transformed into a formula in CNF.\nFinally, we know that the function\n$g$ has a representation in DNF, which implies that $f$ has a representation\nin CNF.\n\n\\begin{chapterendexercises}\n  \\exercise % CAREFUL, DONT MOVE! THERE IS A REFERENCE TO THIS NUMBER\n    Let $\\phi_1$ and $\\phi_2$ be some propositional formulas on\n    the variables from $V$. Show that for any propositional assignement\n    $\\rho$ to $V$,\n    \\begin{itemize}\n      \\item\n        $\\substitute{\n        \\lnot\\left(\n          \\phi_1 \\land \\phi_2\n        \\right)}{\\rho} =\n        \\substitute{\n          \\left(\n            \\lnot \\phi_1 \\lor \\lnot \\phi_2\n          \\right)\n         }{\\rho}$ and\n    \\item\n    $\\substitute{\n    \\lnot\\left(\n      \\phi_1 \\lor \\phi_2\n    \\right)}{\\rho} =\n    \\substitute{\n      \\left(\n        \\lnot \\phi_1 \\land \\lnot \\phi_2\n      \\right)\n     }{\\rho}$.\n  \\end{itemize}\n  \\exercise % CAREFUL, DONT MOVE! THERE IS A REFERENCE TO THIS NUMBER\n    Let $\\phi_1$, \\dots, $\\phi_n$ be some propositional formulas on\n    the variables from $V$. Show that for any propositional assignement\n    $\\rho$ to $V$,\n    \\begin{itemize}\n      \\item\n        $\\substitute{\n          \\left(\n            \\lnot \\left(\n                    \\bigland_{i = 1}^n \\phi_i\n                  \\right)\n          \\right)}{\\rho} =\n          \\substitute{\n            \\left(\n              \\biglor_{i = 1}^n \\phi_i\n            \\right)\n           }{\\rho}$ and\n      \\item\n        $\\substitute{\n         \\left(\n           \\lnot \\left(\n                   \\biglor_{i = 1}^n \\phi_i\n                 \\right)\n         \\right)}{\\rho} =\n         \\substitute{\n           \\left(\n             \\bigland_{i = 1}^n \\phi_i\n           \\right)\n          }{\\rho}$.\n    \\end{itemize}\n  \\exercise Let $\\phi = \\bigvee_{i = 1}^m \\lambda_i$ be a clause; we say that\n    the width of the clause is equal to $m$.\n    Let $\\phi = \\bigwedge_{i = 1}^\\ell \\chi_i$ be a formula in CNF\n    ($\\chi_i$'s are clauses'); we say that the width of $\\phi$ is equal to\n    the maximal width of $\\chi_i$ for $i \\in \\range{\\ell}$.\n\n    Let $p_n : \\set{\\ltrue, \\lfalse}^n \\to \\set{\\ltrue, \\lfalse}$ such that\n    $p_n(x_1, \\dots, x_n) = \\ltrue$\n    iff the set $\\set[x_i = \\ltrue]{i}$ has an odd number of elements.\n    Show that any CNF representation of $p_n$ has width $n$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "3c97979c35740aa9065721eb7e54c74c4bc9a8ab", "size": 17295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_7/chapter_30_propositional_formulas.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_7/chapter_30_propositional_formulas.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_7/chapter_30_propositional_formulas.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.5745192308, "max_line_length": 127, "alphanum_fraction": 0.6420930905, "num_tokens": 5726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6783700584015657}}
{"text": "\\documentclass{article}\n\n\\usepackage{fullpage}\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n%\\usepackage[]{algorithm2e}\n\\usepackage[linesnumbered]{algorithm2e}\n\\usepackage{enumerate,url}\n\\usepackage{hyperref}\n\\hypersetup{colorlinks=true}\n\\usepackage{enumitem}\n\n\\title{CSE-6140/CX-4140 Algorithm Problems\\\\by\\\\Shahrokh Shahi }\n\\author{}\n\\date{}\n\\begin{document}\n\\maketitle\n\n\\noindent\\fbox{\\parbox{\\dimexpr\\textwidth-2\\fboxsep-2\\fboxrule\\relax}{\n\\vspace{2mm}\nPlease upload two files: \n\\begin{enumerate}\n \\item A single PDF named \\texttt{assignment.pdf} containing your solutions.\n \\item \n\\end{enumerate}\n}}\n\\section*{ASSIGNMENT PROBLEMS}\n\\section{Dynamic Programming: Atlanta MARTA [xx pts]}\nThe  Metropolitan  Atlanta  Rapid Transit  Authority  (MARTA) is  the  principal  public  transportoperator in the Atlanta metropolitan area. It was Formed in 1971 as strictly a bus system, and today, it is transporting almost 450,000 passengers a day (bus and train). Currently, MARTA Passes are the cheapest option for those who regularly use MARTA for transportation. Assume the MARTA Passes are sold in three following forms:\n\n\\begin{itemize}\n\\item Daily: A 1-day pass sold for $tickets[0]$ dollars;\n\\item Weekly: A 7-day pass sold for $tickets[1]$ dollars;\n\\item Monthly: A 30-day pass sold for $tickets[2]$ dollars.\n\\end{itemize}\n\nFor instance, $tickets = {2, 7, 20}$ means we need to pay $\\$2$, $\\$7$, and $\\$20$ for each daily, weekly,and monthly pass, respectively. The passes allow consecutive days of travel.  For example, if we get a weekly pass on day 5, then we can travel for 7 consecutive days which are: day 5, 6, 7, 8, 9,10, and 11. George P. Burdell is a student at Georgia Tech and he has already organized his commuting plan for  the  upcoming  year.  In  his  plan,  each   day of  year  is  specified   by an  integer   identification number from 1 to 365. Therefore, he can represent his commuting plan as an array of integers. For instance, days = {8, 9, 10, 11, 14, 17, 18, ...} means George needs to commute to the school on the 8th, 9th, 10th, 11th, ... days of year. He asked you to help him find the minimum amount of money that he should spend to purchase MARTA Passes for commuting to school in the next year. \n\n\\begin{itemize}\n\\item[a)] (3 pts) Prove the optimal substructure.\n\\item[b)] (4 pts) Write a recursive expression for calculating min Cost including the base case.\n\\item[c)] (6 pts) Give the pseudocode of  a   linear   Dynamic   Programming   algorithm   to   return   the   minimum   cost   of commuting  every day in the array “days”, if the cost of MARTA passes is given in a three-element array “tickets”.\tAnalyze the space and time complexity of your algorithm.\n\\end{itemize}\n%\\clearpage\n% -----------------------------------------------------------------------\n\\color{blue}\n\\subsection*{Solution}\n\n\\subsubsection*{Optimal Substructure}\n\nWe are given an array of integer numbers representing the days that George wants to commute to school. $days = \\{d_1, d_2, \\ldots, d_n \\}$, and a three-element array $tickets = \\{t_1, t_2, t_3\\}$. we want to calculate the minimum possible value that George has to pay for buying MARTA passes. Let $OPT[i]$ denotes the minimum amount of money George needs to pay to fulfill the plan from day $i$ to the end of the plan. Therefore, the minimum cost of commuting for the entire plan is $OPT[1]$.\nThere can be two approaches to solve this problem: \\\\\n\\begin{itemize}\n\\item\\textit{Approach 1: Iterate over all days}\\\\\nStarting from day one, if George doesn't want to travel today, there is no need to buy a MARTA pass today. Therefore, it is strictly better to wait until the day that he needs to travel, say day $i$. Then, he will have three options: buying a 1-day, 7-day, or 30-day MARTA pass:\n\\begin{itemize}\n\t\\item If he buys a 1-day pass: he needs to pay $tickets[0]$ dollars and the next subproblem is $OPT[i+1]$ because the 1-day pass is only valid for one day and for the next day he has to pay $OPT[i+1]$ dollars for commuting from day $i+1$ to the end of the plan.\n\t\\item If he buys a 7-day pass: he needs to pay $tickets[1]$ dollars and the next subproblem is $OPT[i+7]$ since the 7-day pass is valid for 7 days (from the day of purchase), and thus after that 7 days, he has to pay $OPT[i+7]$ dollars for commuting from day $i+7$ to the end of the plan.\n\t\\item Similarly, if he buys a 30-day pass: he needs to pay $tickets[2]$ dollars and the next subproblem is $OPT[i+30]$\n\\end{itemize}\n\nTherefore, if George needs to travel in day $i$, the optimum amount of money can be obtained by taking the minimum values of these three:\n$$\nOPT[i] = \\min\\{ tickets[0] + OPT[i+1], tickets[1] + OPT[i+7] ,  tickets[2] + OPT[i+30]\\}\n$$\n\n\nThe solution of these three subproblems, $OPT[i+1]$, $OPT[i+7]$, and $OPT[i+30]$ are minimum. For the sake of contradiction, assume these three values are not the minimum solutions. Therefor, there must exist other optimum solutions with the less ticket cost. Then, we can substitute the solution(s) of subproblem(s) with these minimum values. That implies we obtain less value for $OPT[i]$, the cost of tickets for the commuting plan from day $i$ which is a contradiction because we started with this assumption that $OPT[i]$ is the minimum ticket cost. Thus, this problem has optimal substructures. $\\blacksquare$\n\n%But we can only consider the days that their identification number is in the commuting plan. \n\n\\item\\textit{Approach 2: Iterate over the days of the commuting plan}\\\\\nIn the first approach, we iterate over all days of the year (starting from day 1 to the last possible day in the plan e.g. 365 , regardless of their presence in the commuting plan. \nHowever, instead of all days, we can only check the days that their identification numbers are in the commuting plan. This approach will be slightly faster than the first one. The second approach will particularly be more preferable when the number of days in the plan is much less than the maximum day index, i.e. $|days| << \\max\\{days\\}$. In the worst case, number of days of the commuting plan will be equal to the maximum day index which happens when George wants to commute everyday.\nIn this case, the subproblem $OPT[i]$ denotes the minimum amount of money George needs to pay to fulfill the plan from day $days[i]$ to the end of the plan. (In approach 1, $i$ denotes identification number of each day. In approach 2, $i$ denotes the index of each day in $days$ array). Now, to pass the unnecessary checks, we need to define three additional indices. Let $j1$ be the largest index such that \n$days[j1] < days[i] + 1$, $j7$ be the largest index such that \n$days[j7] < days[i] + 7$, $j30$ be the largest index such that   \n$days[j30] < days[i] + 30$. In this way, if George needs to travel in day $i$, the optimum amount of money can be obtained by taking the minimum values of these three:\n$$\nOPT[i] = \\min\\{ tickets[0] + OPT[j1], tickets[1] + OPT[j7] ,  tickets[2] + OPT[j30]\\}\n$$\nThe proof of optimal substructure is similar to the first approach.\n\\end{itemize}\n\n\n\n\\subsubsection*{Recursive Expression}\n\\begin{itemize}\n\n%$$\n% OPT[i] =\n%    \\begin{cases}\n%      0 & i > \\max\\{days\\}\\\\\n%      \\min\\{ tickets[0] + OPT[i+1],tickets[1] + OPT[i+7] ,  tickets[2] + OPT[i+30]\\} & i \\leq \\max\\{days\\}\n%    \\end{cases} \n%$$\n\n\\item\\textit{Approach 1}\n$$\n OPT[i] =\n    \\begin{cases}\n      0 & i > \\max\\{days\\}\\\\\n      \\min \n      \\begin{cases}\n      \ttickets[0] + OPT[i+1], \\\\\n      \ttickets[1] + OPT[i+7] ,\\\\\n      \ttickets[2] + OPT[i+30]\n      \\end{cases} \n       & i \\leq \\max\\{days\\}\n    \\end{cases} \n$$\n\n\\item\\textit{Approach 2}\n$$\n OPT[i] =\n    \\begin{cases}\n      0 & i > |days|\\\\\n      \\min \n      \\begin{cases}\n      \ttickets[0] + OPT[j1], \\\\\n      \ttickets[1] + OPT[j7] ,\\\\\n      \ttickets[2] + OPT[j30]\n      \\end{cases} \n       & i \\leq |days|\n    \\end{cases} \n$$\nwhere $j1$, $j7$, and $j30$ are the largest indices such that $days[j1] < days[i] + 1$, $days[j7] < days[i] + 7$, and $days[j30] < days[i] + 30$, respectively.\n\n\\end{itemize}\n\n\\subsubsection*{Pseudocode}\n\\begin{itemize}\n\n\\item \\textit{The driver code for Top-Down algorithm}\n\\begin{center}\n\t\\begin{minipage}{0.8\\linewidth} % Adjust the minipage width to accomodate for the length of algorithm lines\n\t\\scalebox{0.88}{\t\t\n\t\t\\begin{algorithm}[H]\n\t\t\t\\KwIn{$days = \\{d_1, d_2, \\ldots, d_n \\}$, $tickets = \\{t_1, t_2, t_3\\}$}  % Algorithm inputs\n\t\t\t\\KwResult{$minCost$ (the minimum amount to pay for MARTA passes)} % Algorithm outputs/results\n\n\t\t\t\\bigskip\n\n\t\t\t$memo \\leftarrow \\{\\}$\\\\\n\t\t\t$minCost \\leftarrow \\texttt{minCostRecur}(days, tickets, memo, 1)$\n\n\t\t\t\\bigskip\n\t\t\t\n\t\t\t{\\bf return} $minCost$\n\t\t\t\\caption{\\texttt{MinMARTACost}} % Algorithm name\n\t\t\t\\label{alg1}   % optional label to refer to\n\t\t\\end{algorithm}\n\t\t}\n\t\\end{minipage}\n\\end{center}\n\n\\item \\textit{Approach 1}\n\\begin{center}\n\t\\begin{minipage}{0.8\\linewidth} % Adjust the minipage width to accomodate for the length of algorithm lines\n\t\\scalebox{0.88}{\t\t\t\t\n\t\t\\begin{algorithm}[H]\n\t\t\t\\KwIn{$days = \\{d_1, d_2, \\ldots, d_n \\}$, $tickets = \\{t_1, t_2, t_3\\}, memo, i$}  % Algorithm inputs\n\t\t\t\\KwResult{$minCost$ (the minimum amount to pay for MARTA passes starting from day $i$)} % Algorithm outputs/results\n\n\t\t\t\\bigskip\n\n\t\t\t\\If(\\tcp*[h]{base case}) {($i >\\max\\{days\\}$)}{ \n\t\t\t\t{\\bf return} $0$\t\n\t\t\t}\n\t\t\t\n\t\t\t\\bigskip\n\n\t\t\t\\If{($memo[i] \\neq \\phi $)}{ \n\n\t\t\t\t{\\bf return} $memo[i]$\t\n\n\t\t\t}\n\t\t\t\t\t\n\t\t\t\\bigskip\n\t\t\t\n\t\t\t\\uIf(\\tcp*[h]{$i$ is in the commuting plan}) {($i \\in days$)}{ \n\t\t\t\t\\begin{equation*}\n\t\t\t\t\\begin{split}\n\t\t\t\t\tmemo[i] = \\min\\{ & tickets[0] + \\texttt{minCostRecur}(days, tickets, memo, i+1),\\\\\n\t\t\t\t\t & tickets[1] + \\texttt{minCostRecur}(days, tickets, memo, i+7),\\\\\n\t\t\t\t\t & tickets[2] + \\texttt{minCostRecur}(days, tickets, memo, i+30)\\}\n\t\t\t\t\\end{split}\n\t\t\t\t\\end{equation*}\n\t\t\t} \\Else{\n\t\t\t\n\t\t\t\t$memo[i] =\\texttt{minCostRecur}(days, tickets, memo, i+1)$\n\t\t\t}\n\t\t\t\n\t\t\t\\bigskip\n\t\t\t\n\t\t\t{\\bf return} $memo[i]$\n\t\t\t\\caption{\\texttt{minCostRecur}} % Algorithm name\n\t\t\t\\label{alg1-rec}   % optional label to refer to\n\t\t\\end{algorithm}\n\t}\t\n\t\\end{minipage}\n\\end{center}\n\n\\item \\textit{Approach 2}\n\\begin{center}\n\t\\begin{minipage}{0.8\\linewidth} % Adjust the minipage width to accomodate for the length of algorithm lines\n\t\\scalebox{0.90}{\t\t\t\t\n\t\t\\begin{algorithm}[H]\n\t\t\t\\KwIn{$days = \\{d_1, d_2, \\ldots, d_n \\}$, $tickets = \\{t_1, t_2, t_3\\}, memo, i$}  % Algorithm inputs\n\t\t\t\\KwResult{$minCost$ (the minimum amount to pay for MARTA passes starting from day $i$)} % Algorithm outputs/results\n\n\t\t\t\\bigskip\n\n\t\t\t\\If(\\tcp*[h]{base case}) {($i > length(\\{days\\})$)}{ \n\t\t\t\t{\\bf return} $0$\t\n\t\t\t}\n\t\t\t\n\t\t\t\\bigskip\n\n\t\t\t\\If{($memo[i] \\neq \\phi $)}{ \n\n\t\t\t\t{\\bf return} $memo[i]$\t\n\n\t\t\t}\n\t\t\t\t\t\n\t\t\t\\bigskip\n\t\t\t\n%\t\t\t$minFromToday \\leftarrow \\infty$\t\t\t\n\t\t\t\\tcp{Finding the largest indices $j1$, $j7$, and $j30$}\n\t\t\t$j1 \\leftarrow i$\\\\\t\t\t\n\t\t\t\\lWhile {($j1 < |days|$ \\textsf{\\&\\&} $days[j1] < days[i] + 1$)} {$j1++$}\t\t\t\n\t\t\t\n\t\t\t$j7 \\leftarrow j1$\\\\\t\t\n\t\t\t\\lWhile {($j7 < |days|$ \\textsf{\\&\\&} $days[j7] < days[i] + 7$)} {$j7++$}\t\n\t\t\t\n\t\t\t$j30 \\leftarrow j7$\\\\\t\t\t\n\t\t\t\\lWhile {($j30 < |days|$ \\textsf{\\&\\&} $days[j30] < days[i] + 30$)} {$j30++$}\t\n\t\t\t\t\t\t\n\n\t\t\t\t\t\n\t\t\t\\begin{equation*}\t\n\t\t\t\\begin{split}\n\t\t\t\tmemo[i] = \\min\\{ & tickets[0] + \\texttt{minCostRecur}(days, tickets, memo, j1),\\\\\n\t\t\t\t & tickets[1] + \\texttt{minCostRecur}(days, tickets, memo, j7),\\\\\n\t\t\t\t & tickets[2] + \\texttt{minCostRecur}(days, tickets, memo, j30)\\}\n\t\t\t\\end{split}\n\t\t\t\\end{equation*}\n\t\t\t\n\t\t\t\\bigskip\n\t\t\t\n\t\t\t{\\bf return} $memo[i]$\n\t\t\t\\caption{\\texttt{minCostRecur}} % Algorithm name\n\t\t\t\\label{alg2-rec}   % optional label to refer to\n\t\t\\end{algorithm}\n\t}\n\t\\end{minipage}\n\\end{center}\n\\end{itemize}\n\n\n\n\\subsubsection*{Time and Space Complexity}\nIn approach 1, the recursive calls is executed for the maximum number of days identifiers. For instance, if the commuting plan is written for one year, the algorithm will be executed 365 times. Therefore, the time complexity is $O(\\max\\{days\\})$. The space complexity is the same as the time complexity due to the memory required for the memoization.\n\n\\noindent In approach 2, as explained earlier, the algorithm is executed for the number of days of the commuting plan. Therefore, both time and space complexity are $O(|days|)$.\n\n\n\n\n\\subsubsection*{Note}\nIn the presented solution, we solved the subproblems from the end of the commuting plan (the last day of the plan) to obtain the minimum cost estimation in the first day of the plan. Therefore, $OPT[i]$ is defined as the minimum amount of money George needs to pay for commuting from day $i$ to the end of the plan, and the minimum value for the entire plan is $OPT[1]$. It is also correct and accepted to start from the beginning of the plan and solve the subplroblems as the minimum amount of money spent on MARTA passes from the first day of the plan until day $i$. In this case, the recursive expression can be written as,\n\n$$\n OPT[i] =\n    \\begin{cases}\n      0 & i \\leq 0\\\\\n      \\min \n      \\begin{cases}\n      \ttickets[0] + OPT[i-1], \\\\\n      \ttickets[1] + OPT[i-7] ,\\\\\n      \ttickets[2] + OPT[i-30]\n      \\end{cases} \n       & 0 < i \\leq \\max\\{days\\}\n    \\end{cases} \n$$\nThus, $OPT[\\max\\{days\\}]$ gives the minimum amount of money spent on MARTA passes.\n\n% -----------------------------------------------------------------------\n\\color{black}\n\\section{Frenemies [xx pts]} \n\nAssume you are planning a dinner party and going to invite a set of friends. However, among them, there are some pairs of persons who are enemies. You need to create a seating plan and you are wondering if it is possible to arrange this set of $n$ friends of yours around a round table such that none of the two enemies will seat next to each other. Given the set of the $n$ friends and the set of the pairs of enemies, prove that this problem is NP-Complete. Remember to follow the steps from lecture to prove NP-completeness.\n\nYou can use the fact that \\texttt{Hamiltonian Cycle (HC)} is NP-complete.\n\n\\color{blue}\n\\subsection*{Solution}\nThe three steps to prove that \\texttt{Frenemies} is an NP-Complete problem. In this solution, we will show that the \\texttt{Frenemies} problem is poly-time reducible from \\texttt{Hamiltonian Cycle (HC)} problem.\n\\begin{itemize}\n\t\\item \\textbf{Step 1} \\texttt{Frenemies} is in NP\\\\\n\tCertificate: A  potential solution can be represented as a set of friends names in which each two consecutive member of the set will sit next to each other. (Because the table is round the last member also sits next to the first person) \\\\\n\tCertifier: Trivially, we can check each two consecutive members to make sure that they are not a member of the set of enemies, and this can be done in polynomial time. In a naive implementation it takes $O(n^2)$ with two nested loops. In a better implementation, it can be done in $O(n)$ time using a hashset data structure.\n\t\n\t\\item \\textbf{Step 2} Choosing an NP-complete problem: \\texttt{HC}\n\t\n\t\\item \\textbf{Step 3} Proving that $\\texttt{HC} \\leq_p \\texttt{Frenemies}$:\\\\\n\t\\begin{itemize}\n\t\t\\item Let $I_1$ be an instance of \\texttt{HC}. Then, $I_1$ is represented as a graph $G=(V,E)$. From this, we can build an instance $I_2$ of the \\texttt{Frenemies} in which we define a person corresponding to each vertex of $I_1$. Two persons are enemies if and only if there are no edges in $E$ between the two corresponding vertices in $V$. We can show that there is Hamiltonian cycle in $I_1$ if and only if there is a valid sitting for friends of instance $I_2$.\n\t\t\n\t\t\\item $(\\Rightarrow)$ Assume there is a Hamiltonian cycle in $I_1$. Then, we arrange the friends in the order of their corresponding vertices along the Hamiltonian cycle. As there are no edge in $E$ between two vertices corresponding to two enemies, two vertices of $I_1$ corresponding to two enemies cannot be consecutive in the Hamiltonian cycle. Therefore, the arrangement if the friends is valid.\n\t\t\n\t\t\\item$(\\Leftarrow)$ Assume that there is a valid friends sitting for instance $I_2$. Then, the ordering of the friends sittings around the table defines a Hamiltonian cycle among the corresponding vertices. Thus, it will be a valid answer for instance $I_1$.\n\t\t\n\t\\end{itemize}\t\t\n\\end{itemize}\n% -----------------------------------------------------------------------\n\\newpage\n\\color{black}\n\\section*{EXAM PROBLEMS}\n% -----------------------------------------------------------------------\n\\color{black}\n% \\newpage\n\\section{Dynamic Programming [xx pts]} % By Shahrokh Shahi\nLet $A$ be the set of all integers in the range of $1$ to $n$. For each pair of $(i,j)$, a cost function $C[i,j] > 0$ is defined and the task is to find an increasing sequence of cutpoints $i_1, i_2, \\ldots, i_k \\in \\{1,2,\\ldots,n-1\\}$ to minimize the total cost $\\sum_{t=0}^k C[i_t + 1, i_{t+1}]$, where $i_0=0$ and $i_{k+1} = n$.\n\n\n\n\\begin{itemize}\n\\item[a)] (3 pts) Prove optimal substructure for this problem\n\\item[b)] (3 pts) Explain a Dynamic Programming algorithm to find the minimum cost of the segmentation and provide the recurrence (including the base case(s)).\n\\item[c)] (5 pts) Give the pseudocode of the bottom-up approach, and the back-tracing step to give start and end position of each sequence of numbers.\n\\item[d)] (2 pts) What are the time and space requirements in terms of $n$?\n\\end{itemize}\n\n\\subsection*{Solution}\n\\color{blue}\n\\begin{itemize}\n\\item[a)] Prove optimal substructure for this problem.\nLet $i_1, i_2, \\ldots, \\i_k$ be the cutpoints of an optimal segmentation of range $[1,n]$. Now the cutpoints $i_1, i_2, \\ldots, i_{k-1}$ form the optimal segmentation of range $[1,i_k]$. to prove the optimal substructure, assume this is not true, that is, there should be another increasing sequence of cutpoints $j_1,j_2, \\ldots, j_h$ with less total cost for range $[1,i_k]$. But that implies we have \n$\\sum_{t=0}^h C[j_t + 1, j_{t+1}] + C[i_k + 1, n]  <  \\sum_{t=0}^k C[i_t + 1, i_{t+1}]$, where $j_0 = 0$ and $j_{h+1} = i_k$. Thus, $i_1, i_2, \\ldots, \\i_k$ cannot be an optimal solution, which is a contraction. \n\\item[b)] (3 pts) The DP recurrence:\\\\\nLet $OPT[j]$ be the (minimum) total cost of the optimum segmentation of range $[1,j]$. The cost of an optimal solution for a complete problem is $OPT[n]$. Because of the optimal substructure property, we can write the following recurrence:\n$$\n OPT[j] =\n    \\begin{cases}\n      0 & if\\ j=0 \\\\\n      \\min\\limits_{0 \\leq i < j} \\{ OPT[i] + C[i+1,j] \\}  & if\\ j>0\n    \\end{cases} \n$$\n\nUsing this recurrence, it is easy to implement the DP algorithm, which computes $OPT[j]$ for $j=0,\\ldots,n$ and a backtracking array to construct the optimal solution.\n\n\\item[c)] (5 pts) Give the pseudocode of the bottom-up approach. \n\n\\begin{center}\n\t\\begin{minipage}{0.8\\linewidth} % Adjust the minipage width to accomodate for the length of algorithm lines\t\n\t\\scalebox{0.88}{\t\n\t\t\\begin{algorithm}[H]\n\t\t\t\\KwIn{$n, C_{n\\times n}$}  % Algorithm inputs\n\t\t\t\\KwResult{$minCost$ (the minimum total cost of the segmentation)} % Algorithm outputs/results\n\n\t\t\t\\bigskip\n\n\t\t\t$opt[0:n] \\leftarrow 0$\\\\\n\t\t\t$track[0:n] \\leftarrow 0$\\\\\n\t\t\t\n\t\t\t\\bigskip\n\n\t\t\t\\For{$j=1$ to $n$ do}{\n\t\t\t\t$c \\leftarrow \\infty$\\\\\n\t\t\t\t\n\t\t\t\t\\For{$i=1$ to $j-1$ do}{\n\t\t\t\t\t\\If{$opt[i]+C[i+1,j] < c$}{\n\t\t\t\t\t\t$c \\leftarrow opt[i]+C[i+1,j] $\\\\\n\t\t\t\t\t\t$track[j] \\leftarrow i$\n\t\t\t\t\t}\t\t\t\t\n\t\t\t\t}\n\t\t\t\t$opt[j] \\leftarrow c$\n\t\t\t}\n\t\t\t\t\n\t\t\t\\bigskip\n\t\t\t$minCost \\leftarrow opt[n]$\n\t\t\t\\bigskip\n\t\t\t\n\t\t\t{\\bf return} $minCost, track$\n\t\t\t\\caption{\\texttt{Optimal Segmentation}} % Algorithm name\n\t\t\t\\label{alg1}   % optional label to refer to\n\t\t\\end{algorithm}\n\t\t}\n\t\\end{minipage}\n\\end{center}\n\nGive the pseudocode of the back-tracing step to print the optimal solution.\n\\begin{center}\n\t\\begin{minipage}{0.7\\linewidth} % Adjust the minipage width to accomodate for the length of algorithm lines\t\n\t\t\\begin{algorithm}[H]\n\t\t\t\\KwIn{$n, track$}  % Algorithm inputs\n%\t\t\t\\KwResult{} % Algorithm outputs/results\n\n\t\t\t\\bigskip\n\t\t\t\n\t\t\t\\While{$track[n] > 0$}{\n\t\t\t\tprint $track[n]$\\\\\n\t\t\t\t$n \\leftarrow track[n]$\t\t\t\n\t\t\t}\n\t\t\t\n%\t\t\t{\\bf return} $minCost, track$\n\t\t\t\\caption{\\texttt{Print Optimal Solution}} % Algorithm name\n\t\t\t\\label{alg1}   % optional label to refer to\n\t\t\\end{algorithm}\n\t\\end{minipage}\n\\end{center}\n\n\n\\item[d)] (2 pts) What are the time and space requirements in terms of $n$?\n\nTime complexity: $O[n^2]$ (There are two nested loop in the implementation.)\\\\\nSpace complexity: $O[2n] = O[n]$.\n\\end{itemize}\n% -----------------------------------------------------------------------\n\\color{black}\n\\newpage\n\\section{NP-Completeness -- Campus Tour[xx pts]} % Shahrokh Shahi (2020)\nThe office of Administration at Georgia Tech is planning for the Campus Visit and Tour Experience Program in which various Campus visit tours are offered to groups of prospective students and their families to become more familiar with the Georgia Tech buildings and amenities. Each tour starts from Georgia Tech Student Center and after visiting some (not necessarily all) buildings and landmarks, in a particular order, returns to the first point. Therefore, if we represent the map of the campus with a directed graph G, each node represents a building or landmark, and each edge shows a directed path from one point to another. Accordingly, the set of the various tours can be represented as a set $S = \\{R_1, R_2, \\ldots, R_n\\}$, where $n$ is the number of the various tours and $R_i$ is the route (circuit) that the visitors pass along tour $i$, starting from and ending at the Student Center. Now the \\texttt{Campus Tours} problem is defined as the following:\\\\\n\nGiven the Directed Graph $G=(V,E)$, the set of the campus tours $S = \\{R_1, R_2, \\ldots, R_n\\}$, and an integer number $k$, is there a subset of $k$  tour(s) in $S$ such that a visitor group can be sure that they have seen all the buildings and landmarks of Georgia Tech?\\\\\n(\\textit{Note: It is possible to visit a node more than once during these $k$ tours.)}\\\\\n\n\\begin{itemize}\n\t\\item[] Prove that the \\texttt{Campus Tours} problem is NP Complete. Remember to follow the steps from lecture to prove NP-completeness. (\\textit{Hint: You can use the fact that \\texttt{Vertex Cover} problem is NP-complete.)}\n\\end{itemize}\n\n\n\n\\subsection*{Solution}\n\\color{blue}\n%NOT COMPLETE YET -- Shahrokh\\\\\n\n\nThe three steps to prove that \\texttt{Campus Tours} is an NP-Complete problem. In this solution, we will show that the \\texttt{Campus Tours (CT)} problem is poly-time reducible from \\texttt{Vertex Cover (VC)} problem.\n\\begin{itemize}\n\t\\item \\textbf{Step 1} \\texttt{Campus Tours} is in NP. The certificate comprises $k$ routes that between them include all the vertices in the graph. We can verify a certificate by checking that each route is indeed a path from the first node $s$ and back to $s$, and via a sort, that the collection of vertices in these path includes all the vertices in $G$. Clearly, this verification takes polynomial time in the size of the given graph $G$ and the certificate, and further the certificate has size at most $kn$, where $n$ is the number of vertices in $G$. \n\t\n\t\\item \\textbf{Step 2} Choosing an NP-complete problem: \\texttt{VC}\n\t\n\t\\item \\textbf{Step 3} Proving that $\\texttt{VC} \\leq_p \\texttt{CT}$:\\\\\n\t\\begin{itemize}\n\t\t\\item Let $I_1 = (G=(V,E), k)$ be an instance of \\texttt{VC} with $k \\leq |V|$. Then we can build an instance $I_2 = (G', S, k')$ of the \\texttt{Campus Tours} such that $Sol(I_1) \\Leftrightarrow Sol(I_2)$. \\\\\n\t\tRecall $G=(V,E)$. $G'$ has the set of vertices $\\{s\\} \\cup V_E$ where $V_E$ has a vertex $v_e$ for each edge $e \\in E$, and $s$ is an additional vertex not in $V_E$. We call $V_E$ the set of edge vertices. For simplicity, we make $G'$ a complete graph, i.e. every possible edge in both directions. Afterwards, for each vertex $u \\in V$, we create a route $R_u$ in $S$. This route starts and ends at $s$ and includes in addition exactly those vertices $v_e$ for which $e$ is incident on $u$. In this way, the order is the same as the order in the adjacency list of graph $G$. Finally, we set $k'=k$. Clearly, this instance of \\texttt{Campus Tours} can be constructed in polynomial time.\n\t\t\n\t\t\\item $(\\Rightarrow)$ Now, if $G$ has a vertex cover $\\{u_1, u_2, \\ldots, u_k\\}$, then the routes that solve the \\texttt{Campus Tours} instance are $R_{u_1}, R_{u_2}, \\ldots, R_{u_k} $ which all of them include $s$ plus all vertices corresponding to edges covered by $u_1, u_2, \\ldots, u_k$, i.e. $\\{s\\} \\cup V_E$.\n\t\t\n\t\t\\item$(\\Leftarrow)$ If the \\texttt{Campus Tours} instance can be solved by $R_{u_1}, R_{u_2}, \\ldots, R_{u_k}$, then these routes include all the edge vertices in $V_E$, and correspondingly $\\{u_1, u_2, \\ldots, u_k\\}$ forms a Vertex Cover of $G$.\n\t\t\n\t\tThis completes the proof. \\\\\n\t\tTherefore $I_1 = (G,k) \\in \\texttt{Vertex Cover} \\Leftrightarrow I_2 = (G',S,k) \\in \\texttt{Campus Tours}$ and \\texttt{Campus Tours} is and NP-Complete problem.\n\t\t\n\t\\end{itemize}\t\t\n\\end{itemize}\n\n\n% ------------------------------------------------------------------ %\n\\color{black}\n\\newpage\n\\section{Dr. Frankenstein [xx pts]}  %  Shahrokh Shahi (2020)\nLet $X = \\{x_1, x_2, \\ldots, x_m\\}$ and $Y = \\{y_1, y_2, \\ldots, y_n\\}$ be two genomic sequence represented by strings of letters and $C[i,j]$ be the cost function defined on pairs of letters, one from $X$ and one from $Y$. \nDr. Frankenstein is trying to merge these two sequences to create a new creature with genomic sequence $Z$ and he needs to find the cheapest merge of $X$ and $Y$, while maintaining the order of letters from both $X$ and $Y$. Therefore, for instance, if $X = \\{a,b,a,c\\}$ and $Y=\\{d,a,e,b\\}$, then $Z = \\{ a,d,a,b,a,e,c,b \\}$ and $Z = \\{a,d,a,e,b,b,a,c \\}$ are valid merges, but $Z=\\{a,b,a,e,c,d,a,b\\}$ is not because $e$ from the second sequence is used before $d$ and $a$.\\\\\nTotal cost of the merge is the sum of the merging costs of the adjacent letters from different sequence. So if $Z$ includes $x_i$ and $x_{i+1}$ as consecutive letters, there is no cost, but if $Z$ has $x_sy_t$ as consecutive letters, then there is a cost $C[s,t]$ and it should be added to the total cost of the merge.\\\\\n\\textit{Note: You can assume that the cost function is symmetric}.\n\n\\begin{itemize}\n\t\\item[] (4 pts) Give a Dynamic Programming algorithm to find the minimum cost of merging $X$ and $Y$.  A high level recursive relation (including the base case) will suffice. Pseudocode is not required. \n\\end{itemize}\n\n\\subsection*{Solution}\n\\color{blue}\nLet $Merge1[i,j]$ be the min cost of merging the first $i$ letters in $X$ with the first $j$ letters in $Y$ with $x_i$ as the last letter in the merged sequence $Z$.\\\\\nSimilarly, let $Merge2[i,j]$ be the min cost of merging the first $i$ letters in $X$ with the first $j$ letters in $Y$ with $y_j$ as the last letter in the merged sequence $Z$. \\\\\nThe recursion relation is as follows:\n\n\n$$\n Merge1[i,j] =\n    \\begin{cases}\n      0 & i =0\\ or\\ j = 0\\\\\n      \\min \n      \\begin{cases}\n      \tMerge1[i-1,j] \\\\\n      \tMerge2[i-1,j]+ C[j,i]\n      \\end{cases} \n       & otherwise\n    \\end{cases} \n$$\n\n$$\n Merge2[i,j] =\n    \\begin{cases}\n      0 & i =0\\ or\\ j = 0\\\\\n      \\min \n      \\begin{cases}\n      \tMerge1[i,j-1]+ C[i,j], \\\\\n      \tMerge2[i,j-1]\n      \\end{cases} \n       & otherwise\n    \\end{cases} \n$$\n\nAccordingly, the minimum cost of merging two genemic sequence is $\\min\\{Merge1[m,n],Merge2[m,n]\\}$\n\n\n\n\n% -----------------------------------------------------------------------\n\\color{black}\n\\newpage\n\\section{Branch and Bound [xx pts]} \n\\begin{itemize}\n\\item[(a)] (3 pts) In general, what are the three different orders of exploring the search tree during the Branch-and-Bound algorithm?  For each order, what kind of data structure should be used for the Queue $F$ of partial solutions to keep the order for exploring the search tree?\n%\\item[(b)] (2 pts) In a Branch-and-Bound algorithm, what is the purpose of each of these components in \\underline{\"minimization\"} and \\underline{\"maximization\"} problems?\n%\n%$\\boxed{\\texttt{Choose}(F)}$, \n%$\\boxed{\\texttt{Expand}(X_i, Y_i)}$, \n%$\\boxed{\\texttt{lower\\_bound}(X_i)}$, \n%$\\boxed{\\texttt{upper\\_bound}(X_i)}$\n\\end{itemize}\n\n\\vspace{5pt}\n\\noindent Let $\\Phi = C_1 \\wedge \\ldots \\wedge C_p $ be a boolean formula with $p$ clauses and $n$ boolean variables $x_1,\\ldots, x_n$, where each clause $C_i$ has the following form, \n$C_i = (x_{j_1} \\vee \\ldots \\vee x_{j_n} )$, $1 \\leq j_k \\leq n$. The optimization version of $\\texttt{SAT}$ problem aims at finding the optimum assignment of boolean variables such that the number of satisfied clauses is maximized. Consider the following boolean formula with 10 clauses, and answer parts (b)-(d):\n$$ \\boxed{\n(x_1  \\vee  \\overline{x_2}) \\wedge\n(x_1  \\vee x_3  \\vee \\overline{x_4}) \\wedge \n(\\overline{x_1}  \\vee x_2) \\wedge \n(x_1  \\vee \\overline{x_3}  \\vee  x_4) \\wedge \n(x_2  \\vee x_3  \\vee  \\overline{x_4}) \\wedge\n(x_1  \\vee \\overline{x_3}  \\vee  \\overline{x_4}) \\wedge\nx_3 \\wedge\n(x_1  \\vee  x_4) \\wedge \n(\\overline{x_1}  \\vee  \\overline{x_3}) \\wedge \nx_1\n}$$\n\nNote that this is a maximization problem, whereas when we introduced Branch-and-Bound algorithms in class we assumed we were working with minimization problems. To solve the following questions, you can either convert this problem into a minimization problem, or answer the questions in the context of a maximization problem. \n\\begin{itemize}\n\\item[(b)] (3 pts) Draw the complete search tree for assignments of $x_i=0/1$, $i \\in \\{ 1,2,3,4 \\}$ and find all possible solutions (which is the number of satisfied clauses) of the given boolean formula. Note that here we are not asking you to perform bounding or pruning operations. The tree you will draw will correspond to an exhaustive search of all assignments. When choosing a variable to expand, please use the order $x_1, x_2, x_3, x_4$. That is, you first consider the values of $x_1$, then $x_2$, etc. And please use the the left subtree to represent $x_i=1$, and right subtree for $x_i=0$.\n\n\\item[(c)] (1 pts) Can this formula be satisfied? What is the maximum number of satisfied clause(s)?\n\n\\item[(d)] (3 pts) When a feasible solution is found, how the branches of this search tree can be pruned? Describe the steps of the corresponding Branch-and-Bound algorithm if the tree is explored by depth-first-search approach. You can use the tree you draw for subquestion (b). It is not required to find the best order of $x_i$ for expanding. You can describe in words that during your DFS search, which subtrees will be pruned and why. You can mark the pruned subtrees on the tree you draw in (b).\n\n%\\item[(e)] (3 pts) Prove that the following algorithm is a $\\frac{1}{2}$-approximation algorithm for finding the maximum number of satisfied clauses:\n%\\begin{center}\n%\t\\begin{minipage}{0.8\\linewidth} % Adjust the minipage width to accomodate for the length of algorithm lines\n%\t\\scalebox{0.88}{\t\t\n%\t\t\\begin{algorithm}[H]\n%\t\t\t%\\KwIn{}  % Algorithm inputs\n%\t\t\t%\\KwResult{} % Algorithm outputs/results\n%\n%\t\t\t\\bigskip\n%\n%\t\t\t\\For{$i=1$ to $n$}{\n%\t\t\t\t\\uIf{($x_i$ appears in more clauses than $\\bar{x_i}$)}{\n%\t\t\t\t\tSet $x_i = 1$\t\t\t\t\n%\t\t\t\t}\\Else{\n%\t\t\t\t\tSet $x_i = 0$\n%\t\t\t\t}\n%\t\t\t\tRemove all satisfied clauses from $\\Phi$ and remove $x_i$ and $\\bar{x_i}$ from all other clauses\n%\t\t\t}\n%\n%\t\t\t\\bigskip\n%\t\t\t\n%\t\t%\t{\\bf return} $minCost$\n%\t\t\t\\caption{\\texttt{Approximation Algorithm for Maximum SAT}} % Algorithm name\n%\t\t\t\\label{alg1}   % optional label to refer to\n%\t\t\\end{algorithm}\n%\t\t}\n%\t\\end{minipage}\n%\\end{center} \n\n\\end{itemize}\n\n%\\newpage\n\\color{blue}\n\\subsection*{Solution}\n\\begin{itemize}\n\\item[(a)] \\ \\\\\n– Depth-first search using a stack (LIFO)\\\\\n– Breadth-first search using a queue (FIFO)\\\\ \n– Best-first search using a priority queue\\\\\n%\\item[(b)] \\ \\\\\n%\\begin{itemize}\n%\\item Both minimization and maximization problem:\\\\\n%$\\boxed{\\texttt{Choose}(F)}$: chooses the most promising partial solution to expand next from the queue $F$.\\\\\n%$\\boxed{\\texttt{Expand}(X_i, Y_i)}$: expands the partial solution $X_i$ by setting values to variables that are not already set and adding them to $X_i$, creating new partial solutions.\\\\\n%\n%\\item Just in minimization problems:\\\\\n%$\\boxed{\\texttt{lower\\_bound}(X_i)}$: computes a lower bound on the cost of the partial solution $X_i$ according to some bounding function. The lower bound is then compared against the global upper bound $B$, and $X_i$ is pruned if $lb(X_i) > B$.\n%\n%\\item Just in maximization problems:\\\\\n%$\\boxed{\\texttt{upper\\_bound}(X_i)}$: computes an upper bound on the cost of the partial solution $X_i$ according to some bounding function. The upper bound is then compared against the global lower bound $B$, and $X_i$ is pruned if $ub(X_i) < B$.\n%\\end{itemize}\n\n%\\item[(c)]  Three outcomes of $\\boxed{\\texttt{Check}(X_i, Y_i)}$:\\\\\n\n\n\\item[(b)] \n\\begin{figure}[h]\n    \\centering\n\t\\includegraphics[width=0.55\\textwidth]{SearchTree.png}\n\t\\caption{Part (b)}\n\\end{figure}\n\n\\item[(c)] No, it cannot be satisfied. The maximum number of satisfied clauses is 9.\n\n\n\\item[(d)] Once a partial assignment is found, the idea is to check how many clauses cannot be satisfied and to cut the branches once a solution with more clauses is found. The algorithm explores the tree with a DFS strategy and obtains the first solution with $x_i = 1,~ \\forall i$, for which $n$ clauses cannot be satisfied. In the first branch ($ x_1 = x_2 = x_3 = x_4 = 1$), 9 clauses are satisfied, so $n = 1$ . \nPursuing with DFS approach, we cut branches that cannot lead to a better solution, i.e., partial assignments with at least $n$ clauses that cannot be satisfied. If a better solution is found, we update $n$ before continuing the tree exploration. \nWith the first branch explored, for the partial assignment $x1 = x2 = x3 = 1$, clause $\\overline{x_1} \\vee  \\overline{x_3}$ cannot be satisfied by any choice of the variable $x_4$, and therefore, we do not explore the branch $x_4 = 0$. Then, for the partial assignment $x_1 = x_2 = 1$, all clauses can be satisfied; we explore the branch with $x_3 = 0$, but then clause $x_3$ cannot be satisfied and we do not go further. Similarly, we stop the exploration at $x1 = 1$ and $x2 = 0$ because clause $\\overline{x_1} \\vee x_2$ cannot be satisfied, and then we stop at $x_1 = 0$ because clause $x1$ cannot be satisfied.\n\n%\\item[(e)] Let $t_i$ be the number of satisfied clauses when we set the values of $x_i$, and $f_i$ be the number of false clauses at the same time (all the terms of the clause must be already set to false). It is clear that the algorithm guarantees $t_i \\ge f_i$.\n%\n%On the other hand, after the algorithms terminates, $\\sum t_i$ is the total number of satisfied clauses in the formula and $\\sum f_i$ is the total number of false clauses. Therefore,  $\\sum t_i \\geq \\sum f_i$ which means at least half of the clauses are satisfied, i.e. the algorithm is $\\frac{1}{2}$-approximation.\n\\end{itemize}\n% -----------------------------------------------------------------------\n\\end{document}\n", "meta": {"hexsha": "f574ff11f8938865428f7558ddd77826ebc3eab8", "size": 34965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "shahrokhx/DesignedAlgorithmProblems", "max_stars_repo_head_hexsha": "0addc75623d003fe3c40b46ae0cb6394b4c97e7c", "max_stars_repo_licenses": ["MIT"], "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": "shahrokhx/DesignedAlgorithmProblems", "max_issues_repo_head_hexsha": "0addc75623d003fe3c40b46ae0cb6394b4c97e7c", "max_issues_repo_licenses": ["MIT"], "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": "shahrokhx/DesignedAlgorithmProblems", "max_forks_repo_head_hexsha": "0addc75623d003fe3c40b46ae0cb6394b4c97e7c", "max_forks_repo_licenses": ["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.5, "max_line_length": 968, "alphanum_fraction": 0.6855140855, "num_tokens": 10597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8918110353738529, "lm_q1q2_score": 0.6783566461219295}}
{"text": "\\section{What's going on?}\nWe get a lot of mileage by looking at the following correspondence.\n\\begin{mdframed}\n  \\adjustbox{scale=1,center}{%\n    \\begin{tikzcd}\n      \\set{\\mbox{2-cocycles}}\\ar[rrr, dashed, leftrightarrow]& & & \\set{\\mbox{Group extensions}}\n    \\end{tikzcd}\n  }\n\\end{mdframed}\nThere is no direct way to go from a group extension to a 2-cocycle, we need to first write the group $G$ as 2-digit numbers $\\tens{a}\\units{b}$ where $a \\in H$ and $b \\in K$.\nThe 2-cocycle then arises as the carry function.\n\nThis correspondence is not a one-to-one correspondence. There are many more cocycles than there are group extensions.\nTo get a 1-1 correspondence, we need to take the quotient of the left-hand side by the set of 2-coboundaries and the right-hand side by isomorphisms.\n\\begin{mdframed}\n  \\adjustbox{scale=1,center}{%\n    \\begin{tikzcd}\n      \\dfrac{\\set{\\mbox{2-cocycles}}}{\\set{\\mbox{2-coboundaries}}}\n      \\ar[rrr, dashed, leftrightarrow, \"1-1\"]\n      & & &\n      \\dfrac{\\set{\\mbox{Group extensions}}}{\\set{\\mbox{isomorphisms}}} \\\\\n      \\dfrac{\\calz^2(K;H)}{\\calb^2(K;H)} \\ar[u, equal]\n      & & & \\\\\n      \\calh^2(K;H)\n        \\ar[u, equal]\n        \\ar[rrr, leftrightarrow, \"1-1\"]\n      & & &\n      \\ext^1(K;H) \\ar[uu, equal]\n    \\end{tikzcd}\n  }\n\\end{mdframed}\nLet us try to understand this correspondence by an example.\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Example}\nConsider the case that we started with $H = K = \\bbz/10$ so that the group extensions are groups consisting of 2-digit numbers and hence have sizes $100$.\nLet $c_k = k \\left \\lfloor \\dfrac{b_1 + b_2}{10}  \\right \\rfloor$ be the standard carry function multiplied by $k$. By repeatedly adding $\\tens{0}\\units{1}$ to itself, one can easily find the isomorphism types of the resulting group extensions.\n\\begin{center}\n  \\begin{tabular}{|r|l|}\n    \\hline\n    carry  & isomorphism\\\\\n    function & class \\\\\\hline\n    $c_1$ & $\\bbz/100$ \\\\\n    $c_2$ & $\\bbz/50 \\times \\bbz/2$ \\\\\n    $c_3$ & $\\bbz/100$ \\\\\n    $c_4$ & $\\bbz/50 \\times \\bbz/2$ \\\\\n    $c_5$ & $\\bbz/20 \\times \\bbz/5$ \\\\\n    $c_6$ & $\\bbz/50 \\times \\bbz/2$ \\\\\n    $c_7$ & $\\bbz/100$ \\\\\n    $c_8$ & $\\bbz/50 \\times \\bbz/2$ \\\\\n    $c_9$ & $\\bbz/100$ \\\\\n    $c_0$ & $\\bbz/10 \\times \\bbz/10$ \\\\\\hline\n  \\end{tabular}\n\\end{center}\nTurns out, these are all the group extensions upto isomorphism.\nThe following is a theorem from algebraic topology,\n\\begin{theorem}\n  The second group cohomology of $\\bbz/10$ with coefficients in $\\bbz/10$ is given by \\label{theorem:cohomologyOfZ10}\n    \\begin{align*}\n      H^2(\\bbz/10; \\bbz/10) \\cong \\bbz/10.\n    \\end{align*}\n    A generator for this cohomology group is given by $c_1$.\n\\end{theorem}\nWe can use this theorem to make rapid computions of isomorphism classes.\n\\begin{proposition}\n  The group extension corresponding to the carry function $d(b_1, b_2) = 2 b_1 b_2$ is given by $\\bbz/10 \\times \\bbz/10$.\n\\end{proposition}\n\\begin{proof}\n  We know that $c_0$ gives rise to the group extension $\\bbz/10 \\times \\bbz/10$.\n  It suffices to show that there exists a 2-coboundary $\\alpha:\\bbz/10 \\rightarrow \\bbz/10$ such that\n  \\begin{align*}\n    d(b_1) - c_0(b_1) &= \\alpha(b_1) + \\alpha(b_2) - \\alpha(b_1 + b_2) \\\\\n    \\Longleftrightarrow 2 b_1 b_2 &= \\alpha(b_1) + \\alpha(b_2) - \\alpha(b_1 + b_2)\n  \\end{align*}\n  $\\alpha(x) = -x^2$ works.\n\\end{proof}\n\\begin{proposition}\n  The group extension corresponding to the carry function $e(b_1, b_2) = b_1 b_2$ is either $\\bbz/20 \\times \\bbz/5$ or $\\bbz/10 \\times \\bbz/10$.\n\\end{proposition}\n\\begin{proof}\n  This is because $d = 2 e$ where $d$ is as in the previous proposition.\n  And $c_0 = 2 c_5$ and $c_0 = 2 c_0$. Hence, $e$ must correspond to either $\\bbz/20 \\times \\bbz/5$ or $\\bbz/10 \\times \\bbz/10$.\n\\end{proof}\nThus cohomology allows us to reduce questions about reduce questions about isomorphism classes of group extensions to solving identities among functions.\nHowever, many a times it only provides partial information and we still need to put in more effort to find the final answer.\n\n\n\n\n\\subsection{Group cohomology}\n  For each positive integer $n$, let $\\calc^n(K;H)$ be the set of functions from $K^{\\times n}$ to $H$.\n  \\begin{align*}\n    \\calc^n(K;H) = \\{ \\underbrace{K \\times \\dots \\times K}_{n-\\text{times}} \\rightarrow H \\}\n  \\end{align*}\n\n  There is a differential function $d^n: \\calc^n(K;H) \\rightarrow \\calc^{n+1}(K;H)$ which takes a function that has $n$ inputs and produces a function that has $n+1$ inputs, defined as follows\n  \\begin{align*}\n    (d^n \\varphi) (k_1, k_2, k_3, \\dots, k_n, k_{n+1})\n    &:=\n    \\varphi (k_2, k_3, \\dots, k_n, k_{n+1}) \\\\\n    & -\n    \\varphi (k_1 + k_2, k_3, \\dots, k_n, k_{n+1}) \\\\\n    & +\n    \\varphi (k_1, k_2 + k_3, \\dots, k_n, k_{n+1}) \\\\\n    & \\mp \\dots \\pm \\\\\n    & (-1)^n \\varphi (k_1, k_2 + k_3, \\dots, k_n + k_{n+1}) \\\\\n    & (-1)^{n+1} \\varphi (k_1, k_2 + k_3, \\dots, k_n) \\\\\n  \\end{align*}\n  where $\\varphi$ is a function $K^{\\times n} \\rightarrow H$.\n\n  \\begin{ex}\n    For $c:K \\times K \\rightarrow H$\n    \\begin{align*}\n      (d^2 \\varphi) (k_1, k_2, k_3)\n      &=\n      \\varphi(k_2, k_3)\n      -\n      \\varphi(k_1 + k_2, k_3)\n      +\n      \\varphi(k_1, k_2 + k_3)\n      -\n      \\varphi(k_1, k_2).\n    \\end{align*}\n  \\end{ex}\n  \\begin{ex}\n    For $\\alpha: K \\rightarrow H$\n    \\begin{align*}\n      (d^1 \\alpha)(k_1, k_2)\n      &=\n      \\alpha(k_1) - \\alpha(k_1 + k_2) + \\alpha(k_2)\n    \\end{align*}\n  \\end{ex}\n\n  From the above examples, one can see that $c$ is a 2-cocycle precisely when $d^2 c = 0$ and $c$ is a 2-coboundary when $c = d^1 \\alpha$ for some $\\alpha$.\n\n  \\begin{definition}\n    The set of $n$-cocycles is the kernel of $ d^n$ and the set of $n$-coboundaries is the image of $d^{n-1}$.\n    \\begin{align*}\n      \\calz^n(K;H) := \\set{n-\\mbox{cocycles}} &= \\ker d^n \\\\\n      \\calb^n(K;H) := \\set{(n-1)-\\mbox{cocycles}} &= \\im d^{n-1}\n    \\end{align*}\n    The $n^{th}$ group cohomology group of the group $K$ with coefficients in $H$ is the quotient\n    \\begin{align*}\n      \\calh^n(K;H) := \\calz^n(K;H) / \\calb^n(K;H) = \\ker d^n / \\im d^{n-1}\n    \\end{align*}\n  \\end{definition}\n\n  The other group cohomologies also have different meanings.\n  \\begin{ex}\n    A 1-coboundary is a map $\\alpha: K \\rightarrow H$ such that $d^1 \\alpha = 0$.\n    Expanding this out, we get\n    \\begin{align*}\n      \\alpha(k_1) - \\alpha(k_1 + k_2) + \\alpha(k_2) &= 0 \\\\\n      \\alpha(k_1) + \\alpha(k_2) &= \\alpha(k_1 + k_2)\n    \\end{align*}\n    But this means that $\\alpha$ is a group homomorphism!\n    Thus, 1-cocycles are exactly group homomorphisms.\n    Further, there are no 1-coboundaries and hence\n    \\begin{align*}\n      \\calh^1(K;H) := \\{ \\mbox{group homomorphisms }K \\rightarrow H \\}\n    \\end{align*}\n  \\end{ex}\n\n  Thus we have\n  \\begin{align*}\n    \\mbox{first group cohomology} & \\longleftrightarrow \\mbox{ group homomorphisms }\\\\\n    \\mbox{second group cohomology} & \\longleftrightarrow \\mbox{ group extensions }\\\\ \\mbox{higher group cohomology} & \\longleftrightarrow \\mbox{ ?? }\n  \\end{align*}\n\nWhat the higher group cohomologies mean is a very subtle question and computing and studying this forms a branch of mathematics called \\emph{homological algebra}.\n", "meta": {"hexsha": "9409ac2ae97b8c151bb350f8c7635d33c1649bf4", "size": 7147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04.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": "04.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": "04.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": 39.7055555556, "max_line_length": 244, "alphanum_fraction": 0.6332727018, "num_tokens": 2611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479702, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.6782018444629125}}
{"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 3}\n\nConsider the hypothesis family of sin functions of the form $f_\\omega(x) = \\sin \\omega x$.\nThese functions can be used to classify the points in $\\mathbb{R}$ as follows.\nA point is labeled as positive if it is above the curve, and negative otherwise.\n\\begin{enumerate}[label=(\\alph*)]\n\\item For $m > 0$, consider the set of points $S = \\{x_1, x_2, ..., x_m\\}$ with arbitrary labels $y_1, y_2, ... y_m \\in \\{-1, 1\\}$.\nA subset of $S$ is defined by a choice of the parameters $y_i$ and it consists of those $x_i$ such that $y_i = 1$.\nDefine\n\\begin{equation}\\label{eq31}\n\\omega = \\pi (1 + \\sum_{i=1}^{m} 2^{i}y_{i}^{\\prime})\n\\end{equation}\nwhere $y_i^\\prime = \\frac{1-y}{2}$.\nProve that with this choice of $\\omega$ the set $S$ is shattered, that is, for every subset $T$ of $S$ there would be an $\\omega$ such that $T$ equals the set of positive examples.\n\n\\item What is the Vapnik-Chervonenkis dimension of this classifier?\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}\n\\item As $S$ is defined based on $y_i$ which in turn depend on $x_i$ based on the function $F_w(x)$, we can simplify the problem by using the function.\nBy substituting $y_i^\\prime$ in Equation \\ref{eq31}, we'll get\n\n\\begin{equation}\\label{eq32}\nS = \\{2 ^ {-j} | 1 \\leq j \\leq m\\}\n\\end{equation}\n\nSince we can choose $w$ as we like, we can move any arbitrary point that we choose to below or above the sine curve.\nTherefore, the set $S$ can be shattered for all subsets of $S$ with arbitrary size.\n\n\\item The class of $f_w(x)$ functions can shatter any arbitrary number of points.\nTherefore, Vapnik-Chervonenkis Dimension for this class is infinite.\n\\end{enumerate}\n", "meta": {"hexsha": "f281ab8c93ac53332d5a4870dbf5c756032029ab", "size": 2019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw02/hw02q03.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/hw02q03.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/hw02q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 48.0714285714, "max_line_length": 180, "alphanum_fraction": 0.6696384349, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6782018384346464}}
{"text": "\\chapter{Linear time invariant DT systems}\n\n\\section{DT system representations}\n\nWe can mathematically represent, or model, DT systems multiple ways.\n\n\\begin{itemize}\n\\item purely mathematically - in time domain we will use\n\n  \\begin{itemize}\n  \\item linear, constant coefficient difference equations, e.g.\n    \\[\n    y[n] = a y[n-1] + b y[n-2] + x[n]\n    \\]\n  \\item DT impulse response $h[n]$\n  \\end{itemize}\n\\item purely mathematically - in frequency domain we will use\n  \\begin{itemize}\n  \\item frequency response\n  \\item transfer function (complex frequency, covered in ECE 3704)\n  \\end{itemize}\n\\item graphically, using a mixture of math and block diagrams\n\\end{itemize}\n\n\\section{System properties and classification}\n\nChoosing the right kind of system model is important. Here are some important properties that allow us to broadly classify systems.\n\\begin{itemize}\n\\item Memory\n\\item Invertability\n\\item Causality\n\\item Stability\n\\item Time-invariance\n\\item Linearity\n\\end{itemize}\n\nLet's define each it turn.\n\n\\subsection{Memory}\nThe output of a DT system with memory depends on previous or future inputs and is said to be {\\it dynamic}. Otherwise the system is memoryless or {\\it instantaneous}, and the output $y[n]$ at index $n$ depends only on $x[n]$.\nFor example:\n\\[\ny[n] = 2x[n]\n\\]\nis a memoryless system, while\n\\[\ny[n+1] + y[n] = x[n]\n\\]\nhas memory. To  see this, write the difference equation in recursive form\n\\[\ny[n] = -y[n-1] + x[n-1]\n\\]\nand we see explicitly the current output $y[n]$ depends on past values of output and input.\n\n\\subsection{Invertability}\n\nA system is invertible if there exists a system that when placed in series with the original recovers the input.\n\\[\nx[n] \\mapsto{T} y[n] \\mapsto{T^{-1}} x[n]\n\\]\nwhere $T^{-1}$ is the inverse system of $T$. For example, consider a system\n\\[\nx[n] \\mapsto y[n] = \\sum\\limits_{m=-\\infty}^{n} x[m]\n\\]\nand a system\n\\[\ny[n] \\mapsto z[n] = y[n] - y[n-1]\n\\]\nThe combination in series $x[n] \\mapsto y[n] \\mapsto z[n] = x[n]$, since\n\\[\nz[n] = y[n] - y[n-1] = \\sum\\limits_{m=-\\infty}^{n} x[m] - \\sum\\limits_{m=-\\infty}^{n-1} x[m] = x[n]\n\\]\ni.e. the difference undoes the accumulation.\n\n\\subsection{Causality}\nA DT system is causal if the output at index $n$ depends on the input for index values at or before $n$:\n\\[\ny[n] \\;\\text{depends on}\\; x[m] \\;\\text{for} \\; m \\leq n\n\\]\nWhile all physical CT systems are causal, practical DT systems may not be since we can used memory to \"shift time\". For CT systems we cannot store the infinite number of values between two time points $t_1$ and $t_2$, but we can store the $n_2-n_1$ values of a DT system between between two indices $n_1$ and $n_2$ (assuming infinite precision).\n\n\\begin{example}\nConsider a DT system whose difference equation is\n\\[\ny[n] = -x[n-1] + 2x[n] - x[n+1]\n\\]\nWe see the current output $y[n]$ depends on a \"future\" value of the input $x[n+1]$. Thus the system \\textbf{is not} causal. In practice we can shift the difference equation to\n\\[\ny[n-1] = -x[n-2] + 2x[n-1] - x[n]\n\\]\nand then delay the output by one sample to get $y[n]$.\n\\end{example}\n\n\\begin{example}\nConsider a DT system whose difference equation is\n\\[\ny[n] = -y[n-1] + 2x[n]\n\\]\nWe see the current output $y[n]$ depends on a \"past\" value of the output $y[n-1]$ and the current input $x[n]$. Thus the system \\textbf{is} causal. In practice we can immediately compute $y[n]$ with no delay. \n\\end{example}\n\n\\subsection{Stability}\n\nA DT system is (BIBO) stable if applying a bounded-input\n\\[\nx[n] < \\infty \\; \\forall \\; n\n\\]\nresults in a bounded-output $x[n] \\mapsto y[n]$ and \n\\[\ny[n] < \\infty \\; \\forall \\; n\n\\]\nNote, bounded in practice is limited by the physical situation, e.g. the number of bits used to store values.\n\nFor example, a DT system described by the LCCDE\n\\[\ny[n+1] - 2 y[n] = x[n+1]\n\\]\nis unstable because the solution $y[n]$ will have one term of the form $\\left( 2\\right)^n$, for most non-zero inputs $x[n]$ or any non-zero initial condition, that grows unbounded as $n$ increases.\n\n\\subsection{Time-invariance}\nA DT system is time(index)-invariant if, given\n\\[\nx[n] \\mapsto y[n]\n\\]\nthen an index-shift of the input leads to the same index-shift in the output\n\\[\nx[n-m] \\mapsto y[n-m]\n\\]\n\nAn important example is a DT system described by a LCCDE, e.g.\n\\[\ny[n+1] - \\frac{1}{2} y[n] = x[n+1]\n\\]\nor in recursive form\n\\[\ny[n] = \\frac{1}{2} y[n-1] + x[n]\n\\]\n\nIf we index shift the input $x[n - m]$ we replace $n$ by $n-m$ and the difference equation becomes\n\\[\ny[n-m+1] - \\frac{1}{2} y[n-m] = x[n-m+1]\n\\]\nwhich has the same solution shifted by $m$\n\\[\ny[n-m] = \\frac{1}{2} y[n-m -1] + x[n-m]\n\\]\n\nIf a coefficient depends on $n$ however, e.g\n\\[\ny[n+1] - \\frac{n}{2} y[n] = x[n+1]\n\\]\nso that it is no longer LCC then the solution depends on $m$ and the system is no longer time-invariant.\n\n\\subsection{Linearity}\n\nA DT system is linear if the output due to a sum of scaled individual inputs is the same as the scaled sum of the individual outputs with respect to those inputs. In other words given\n\\[\nx_1[n] \\mapsto y_1[n] \\;\\text{and}\\; x_2[n] \\mapsto y_2[n]\n\\]\nthen\n\\[\na x_1[n] + b x_2[n] \\mapsto a y_1[n] + b y_2[n]\n\\]\nfor constants $a$ and $b$.\nNote this property extends to sums of arbitrary signals, e.g. if\n\\[\nx_i[n] \\mapsto y_i[n] \\; \\forall\\; i \\in [1 \\cdots N]\n\\]\nthen given $N$ constants $a_i$, if the system is linear\n\\[\n\\sum\\limits_{i = 1}^N a_i x_i[n] \\mapsto \\sum\\limits_{i = 1}^N a_i y_i[n] \n\\]\nThis is a very important property, called {\\it superposition}, and it simplifies the analysis of systems greatly.\n\nAn important non-linear system is that is described by a LCCDE with non-zero auxiliary conditions at some $n_0$, $y[n_0] = y_0$. As in CT, such systems will have a term in it's solution that depends on $y_0$. Given two inputs, each individual response will have that term in it, so their sum has double that term. However the response due to the sum of the inputs would again only have one and the sum of the responses would not be the same as the response of the sum. Such a system cannot be linear. Thus the system must be \"at rest\" before applying the input in order to be a linear system.\n\n\\section{Stable LTI Systems}\n\nThe remainder of this course is about stable, linear, time-invariant (LTI) systems. As we have seen in DT such systems can be described by a LCCDE with zero auxiliary (initial) conditions (the system is \\emph{at rest}). \n\nWe have seen previously how to find the impulse response, $h[n]$, of such systems. We now note some relationships between the impulse response and the system properties described above.\n\n\\begin{itemize}\n\\item If a system is memoryless then $h[n] = C \\delta[n]$ for some constant $C$.\n\\item If a system is causal then  $h[n] = 0$ for $n < 0$.\n\\item If a system is BIBO stable then\n  \\[\n  \\sum\\limits_{-\\infty}^{\\infty} |h[n]| < \\infty\n  \\]\n\\end{itemize}\n\n", "meta": {"hexsha": "69205f3c6817950eb3739d47257b41c7cc0fc520", "size": 6831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "07-dt-lti.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": "07-dt-lti.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": "07-dt-lti.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": 35.578125, "max_line_length": 592, "alphanum_fraction": 0.6955057825, "num_tokens": 2130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145404, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.6782018302117551}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 6}\n\nLet $A$ be an alphabet and let $a \\in A$.\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\t\\item\n\tProve that $a^{-1}A^* = a^{-1}A^+ = A^*$.\n\n\t\\item\n\tProve that $a^{-1}A^n = A^{n-1}$.\n\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\\item\nIt is assumed that $z \\in a^{-1}A^*$.\nIt is shown that $z \\in a^{-1}A^*$ and $z \\in A*$.\nTo change inclusion to equality, it is also shown for $z\\in A*$ that $z \\in a^{-1}A^*$.\n\n\\begin{equation}\\label{6eq1}\nz \\in a^{-1}A^* \\Rightarrow az \\in A^*\n\\end{equation}\n\n\\begin{equation}\\label{6eq2}\nA^* = A^+ \\cup \\lambda\n\\end{equation}\n\nSubstituting \\eqref{6eq2} in \\eqref{6eq1},\n\n\\begin{equation}\naz \\in A^+ \\cup \\lambda \\label{6eq3}\n\\end{equation}\n\n\\begin{equation}\na \\in az \\Rightarrow az \\neq \\lambda \\Rightarrow az \\notin \\lambda \\label{6eq4}\n\\end{equation}\n\nUsing \\eqref{6eq4} in \\eqref{6eq3}\n\n\\begin{equation}\naz \\in A^+ \\Rightarrow z \\in a^{-1}A^+\n\\end{equation}\n\nThus $a^{-1}A^*\\subseteq a^{-1}A^+$ is proven so far.\n\n\\begin{equation}\\label{6eq6}\nz \\in a^{-1}A^+ \\Rightarrow az \\in A^+\n\\end{equation}\n\n\\begin{equation}\\label{6eq7}\na \\in A \\Rightarrow a \\in A^+\n\\end{equation}\n\nUsing \\eqref{6eq7} in \\eqref{6eq6} concludes\n\n\\begin{equation}\nz \\in A^+ \\Rightarrow z \\in A^*\n\\end{equation}\n\nThus $a^{-1}A^*\\subseteq a^{-1}A^+ \\subseteq A^*$ is proven so far.\n\n\\begin{equation}\nz \\in A^* \\Rightarrow az \\in A^* \\Rightarrow z \\in a^{-1}A^*\n\\end{equation}\n\nWhich shows that $A^* \\subseteq a^{-1}A^*$. Therefore\n\n\\begin{equation}\na^{-1}A^* = a^{-1}A^+ = A* \\nonumber\n\\end{equation}\n\n\\item\nStatement is proven by induction on \\textit{n}.\n\nInitial step: let $n = 1: a^{-1}A = \\emptyset $.\n\n\\begin{equation}\nz \\in a^{-1}A \\rightarrow az \\in A\n\\end{equation}\n\nAs $A$ is the alphabet, any element in $A$ is a symbol.\n\n\\begin{equation}\n|az| = 1 \\Rightarrow |a| + |z| = 1 \\Rightarrow |z| = 0 \\Rightarrow z = \\lambda \\in \\emptyset\n\\end{equation}\n\nThus, $a^{-1}A \\subseteq \\emptyset$.\n\n\\begin{equation}\nz \\in \\emptyset \\Rightarrow z = \\lambda\n\\end{equation}\n\nSince $a \\in A$,\n\n\\begin{equation}\naz = a\\lambda \\in A \\Rightarrow z \\in a^{-1}A\n\\end{equation}\n\nThus $\\emptyset \\subseteq a^{-1}A$ and initial induction step is proven.\n$$ a^{-1}A = \\emptyset $$\nAssumption step:\n\n\\begin{equation}\\label{6eq14}\na^{-1}A^n = A^{n-1}\n\\end{equation}\n\nInduction step: $a^{-1}A^{n+1} = A^n$.\n\n\\begin{equation}\\label{6eq15}\nz \\in a^{-1}A^n+1 \\Rightarrow z \\in a^{-1}A^nA\n\\end{equation}\n\nSubstituting \\eqref{6eq14} in \\eqref{6eq15},\n\n\\begin{equation}\nz \\in a^{-1}A^nA \\Rightarrow z \\in A^{n-1}A \\Rightarrow z \\in A^n\n\\end{equation}\n\nThus $a^{-1}A{n+1}\\subseteq A^n$. Similarly,\n\n\\begin{equation}\nz \\in A^n \\Rightarrow z \\in A^{n-1}A\n\\end{equation}\n\nFrom \\eqref{6eq14},\n\n\\begin{equation}\nz \\in a^{-1}A^nA \\Rightarrow z \\in a^{-1}A^{n+1}\n\\end{equation}\n\nTherefore, $a^{-1}A^{n+1}=A^n$.\nAnd the statement is proven by induction.\n\n\\end{enumerate}\n", "meta": {"hexsha": "274d4973d532fedf2a22943e597e84f7afffdf40", "size": 3249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q06.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q06.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q06.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": 22.2534246575, "max_line_length": 92, "alphanum_fraction": 0.621421976, "num_tokens": 1230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.6780916976939937}}
{"text": "\\section{Oriented PCA}\n\n\\begin{align*}\n\t\\mb{u} = \\mb{A x} \n\\end{align*}\nwith $\\mb{A}^{-1}$ exists and %and $\\mb{A}$ is a whitening matrix.\n\\begin{align*}\n\t\\mb{y} = \\mb{w\\TT x}\n\\end{align*}\nis a dimensionality reducing tranformation.\nThe  Rayleigh quotient in the $\\mb{x}$-space is given by\n\\begin{align}\n\tR_{ab} = \\frac{\\mb{w}\\TT \\mb{C}_a \\mb{w}}{\\mb{w}\\TT \\mb{C}_b \\mb{w}}\n\\end{align}\nwhere $\\mb{C}_a$ and $\\mb{C}_b$ are the covariance matrices of two random variables. The Rayleigh\nquotient is maximized by the first principle component of \n$\\mb{C}_b^{-\\frac{1}{2}} \\mb{C}_b \\mb{C}_b^{-\\frac{1}{2}}$ (Rayleigh-Ritz theorem).\n\\begin{align}\n\t\\mb{R}_{ab} = \\frac{\\mb{v}\\TT \\mb{A} \\mb{C}_a \\mb{A}\\TT \\mb{v}}{\\mb{v}\\TT \\mb{A} \\mb{C}_b \\mb{A}\\TT \\mb{v}}\n\t\\stackrel{!}{=} \\imat\n\\end{align}\n\nWe want this to be the identity matrix. $\\mb{C}_b$ has to be positive definite.\n\n\\begin{align}\n\t\\begin{split}\n\t\\mb{v}\\TT \\mb{C}_b \\mb{v} \n\t\t&= \\mb{v}\\TT \\mb{C}_b^{-\\frac{1}{2}} \\mb{C}_b \\mb{C}_b^{-\\frac{1}{2}} \\mb{v} \\\\\n\t\t&= \\mb{v}\\TT \\, \\mb{U} \\mb{D}^{-\\frac{1}{2}} \\mb{U}\\TT \\, \\mb{U} \\mb{D} \n\t\t   \\mb{U}\\TT \\, \\mb{U} \\mb{D}^{-\\frac{1}{2}} \\mb{U}\\TT \\, \\mb{v} \\\\\n \t\t&= \\mb{v}\\TT \\mb{U} \\, \\mb{D}^{-\\frac{1}{2}} \\mb{D} \\mb{D}^{-\\frac{1}{2}} \\, \\mb{U}\\TT \\mb{v} \\\\\n \t\t&= \\mb{v}\\TT \\mb{U} \\imat \\mb{U}\\TT \\mb{v} \\\\\n \t\t&= \\mb{v}\\TT \\imat \\mb{v} \\\\\n \t\t&= \\mb{v}\\TT \\mb{v}\n\t\\end{split} \t\t\n\\end{align}\n\n\\subsection{Whitening transform}\n\\begin{align}\n\t\\mb{A} := \\mb{Q} \\mb{C}_b^{-\\frac{1}{2}}\n\\end{align}\nwhere $\\mb{Q}$ is an arbitrary orthogonal matrix. For now we pick $\\mb{Q} = \\imat$\n\n\\begin{align}\n\t\\Rightarrow \\frac{\\mb{v}\\TT \\mb{C}_b^{-\\frac{1}{2}} \\mb{C}_a \\mb{C}_b^{-\\frac{1}{2}} \\mb{v}}{\\mb{v}\\TT \\mb{v}}\n\\end{align}\n\n\\begin{align*}\n\t\\mb{x} \\stackrel{\\mb{A}}{\\longrightarrow} \\mb{u} \\\\\n\t\\mb{w} \\stackrel{\\text{?}}{\\longleftarrow} \\mb{v}\n\\end{align*}\n\n\\begin{align}\n\t\\frac{\\mb{w}\\TT \\mb{C}_a \\mb{w}}{\\mb{w}\\TT \\mb{C}_b \\mb{w}} \\leftrightarrow \n\t\\frac{\\mb{v}\\TT \\mb{C}_b^{-\\frac{1}{2}} \\mb{C}_a \\mb{C}_b^{-\\frac{1}{2}} \\mb{v}}{\\mb{v}\\TT \\mb{v}}\n\\end{align}\n\n\\begin{align}\n\t\\mb{w} = \\mb{A}^{-1} \\mb{v}\n\\end{align}\n\n\\begin{align}\n\t\\mb{C}_b^{-\\frac{1}{2}} \\mb{C}_a \\mb{C}_b^{-\\frac{1}{2}} = \\mb{V} \\tilde{\\mb{D}} \\mb{V}\\TT\n\\end{align}\n\nif $\\mb{D} = \\mathrm{diag}(\\mb{D}_{11}, \\dots, \\mb{D}_{MM})$ such that \n$\\mb{D}_{11} \\geq \\dots \\geq \\mb{D}_{MM}$\nthen \n\\begin{align}\n\t\\mb{v} = \\mb{V}(:,1) = \\mb{v}_1 \\qquad ; \\qquad \\mb{V} = (\\mb{v}_1, \\dots, \\mb{v}_M)\n\\end{align}\n\n\\subsection{Signal to noise ratio}\n\\begin{align}\n\t\\mb{x} = \\left( \\mb{A}\\mb{s} + \\mb{B}\\mb{n} \\right)\n\\end{align}\nwhere $\\mb{s}$ is the signal and $\\mb{n}$ is noise.\n\\begin{align}\n\t{\\mb{s} \\choose \\mb{n}} \\sim \\mathcal{N}(0,\\imat)\n\\end{align}\nusing plain PCA implies the assumption that $\\mathrm{Cov}[\\mb{n}] = \\imat$.\nIt is assumed that $\\mb{s}$ and $\\mb{n}$ are statistically independent such that\n\\begin{align}\n\t\\mathrm{Cov} \\left[ \\begin{matrix}\n\t\t\\mb{As} \\\\ \\mb{Bn}\n\t\\end{matrix} \\right]\n\t= \\left( \\begin{array}{c c}\n\t\t\\mb{A A\\TT} & 0 \\\\\n\t\t0 & \\mb{B B\\TT}\n\t  \\end{array} \\right)\n\\end{align}\nand therefore the data convariance is given by\n\\begin{align*}\n\t\\mathrm{Cov}[\\mb{x}] = \\mb{A A\\TT} + \\mb{B B\\TT}\n\\end{align*}\n\nNoise covariance:\n\\begin{align*}\n\t\\mathrm{Cov}[\\mb{x} | \\mb{s}] = \\mb{B B\\TT}\n\\end{align*}\n\n\\subsubsection{How large is the mutual information between $\\mb{x}$ and $\\mb{s}$?}\n\n\\begin{align}\n\\begin{split}\n\t\\mathrm{I}[\\mb{x}:\\mb{s}] &= \\mathrm{h}(\\mb{x}) \\mathrm{h}(\\mb{x} | \\mb{s}) \\\\\n\t\t\t\t\t&= \\frac{1}{2} \\log \\left(2 \\pi \\mathrm{e} \\right)^M | \\mb{A A\\TT} + \\mb{B B\\TT} |\n\t\t\t\t\t   -\\frac{1}{2} \\log \\left(2 \\pi \\mathrm{e} \\right)^M | \\mb{B B\\TT} | \\\\\n\t\t\t\t\t&= \\frac{1}{2} \\log \\frac{| \\mb{A A\\TT} + \\mb{B B\\TT} |}{| \\mb{B B\\TT} |} \\\\\n\t\t\t\t\t&= \\frac{1}{2} \\log |\\underbrace{(\\mb{B B\\TT})^{-\\frac{1}{2}} \\mb{A A\\TT} (\\mb{B B\\TT})^{-\\frac{1}{2}}}_{\\text{Signal-to-noise ratio}} + \\imat| \\\\\t\t\t\t\t\n\\end{split}\n\\end{align}\n\n\\begin{align}\n\t\\mb{y} = \\mb{w\\TT x} \\qquad \\text{and} \\qquad \\mb{W W}\\TT = \\imat\n\\end{align}\n\n\\begin{align}\n\t\\Rightarrow \\mathrm{I}[\\mb{y}:\\mb{s}]\n\t   = \\frac{1}{2} \\log |\\mb{W} (\\mb{B B\\TT})^{-\\frac{1}{2}} \\mb{A A\\TT} (\\mb{B B\\TT})^{-\\frac{1}{2}} \\mb{W}\\TT + \\mb{W W}\\TT|\n\\end{align}\n\n\\emph{Oriented PCA} seeks to maximize the mutual information between the signal s and \nthe \\emph{reduced representation} $\\mb{y} = \\mb{w\\TT x}$. \\\\\n\nThe optimum that will be found with oriented PCA is not unique because\n\\begin{align}\n\t\\tilde{\\mb{y}} = \\mb{Q W x} \\qquad \\text{with} \\qquad \\mb{Q Q\\TT} = \\imat\n\\end{align}\nhas the same mutual information as \n\\begin{align*}\n\t\\mathrm{I}[\\mb{y}:\\mb{s}] = \\mathrm{I}[\\tilde{\\mb{y}}:\\mb{s}]\n\\end{align*}\nIf one seeks to identify a transform that diagonalizes two covariance matrices at the same time,\nthe solution is unique -> Blind source separation \\cite{Tong1991,Molgedey1994}\\\\\n\nNeuroscience application of oriented PCA: Slow feature analysis.", "meta": {"hexsha": "5e1f3f4b5d4fb8d0e650345cfc4cbed7e59ede25", "size": 4867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture13/lecture13.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/lecture13/lecture13.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/lecture13/lecture13.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": 35.5255474453, "max_line_length": 156, "alphanum_fraction": 0.5802342305, "num_tokens": 2153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6780754938923697}}
{"text": "\\newcommand\\hnull{\\ensuremath{\\text{[]}}\\xspace}\n\n\\subsection{Measures: From Integers to Data Types}\\label{sec:measures}\n\n\\begin{figure}\n\\centering\n\\captionsetup{justification=centering}\n$$\n\\begin{array}{lrcl}\n{\\emphbf{Definition}} &\n  \\mathit{def} & ::=  &  \\mathtt{measure} \\ f :: \\tau \\\\\n              & &      &  \\quad eq_1 \\ldots eq_n       \\\\[0.05in]\n\n{\\emphbf{Equation}}   & \n  \\mathit{eq}  & ::=  &   f\\ (D\\ \\overline{x}) = r    \\\\[0.15in] \n\n{\\emphbf{Equation to Type}} &\n\\quad \\embed{f\\ (D\\ \\overline{x}) = r} & \\defeq & D :: \\overline{\\tbind{x}{\\tau}} \\rightarrow \\tref{\\mathtt{v}}{\\tau}{}{f\\ \\mathtt{v} = r}\n\\end{array}\n$$\n\\caption{Syntax of Measures.}\n\\label{fig:measures}\n\\end{figure}\n\n\n\nSo far, all our examples have used only integer and boolean expressions in refinements.\nTo describe properties of algebraic data types, we use \\emph{measures},\nintroduced in prior work on Liquid Types~\\cite{LiquidPLDI09}.\n%\nMeasures are inductively defined functions that can be used in refinements and\nprovide an efficient way to axiomatize properties of data types.\n%\nFor example, @emp@ determines whether a list is empty:\n%\n\\begin{code}\n  measure emp  :: [Int] -> Bool\n    emp []     = true\n    emp (x:xs) = false\n\\end{code}\nThe syntax for measures deliberately looks like Haskell, but it is \\emph{far} more\nrestricted, and should really be considered as a separate language.\nA measure has exactly one argument and is defined by a list of equations,\neach of which has a simple pattern on the left hand side (Figure~\\ref{fig:measures}).\nThe right-hand side of the equation is a refinement expression $r$.\nMeasure definitions are typechecked in the usual way; we omit the typing rules which are standard.\n(Our metatheory does not support type polymorphism,\nso here we simply reason about lists of integers;\nhowever, our implementation supports polymorphism).\n\n\\paragraph{Denotational semantics}\nThe denotational semantics of types in \\hlang in \\Sref{sec:den-sem} is readily extended to\nsupport measures.  In \\hlang a refinement $r$ is an arbitrary expression and\ncalls to a measure are evaluated in the usual way by pattern matching.\nFor example, with the above definition of @emp@ it is straightforward to show that\n\\begin{align}\n  \\mathtt{[1, 2, 3]} \\dcolon \\tref{\\mathtt{v}}{[\\tint]}{}{\\mathtt{not}\\ (\\mathtt{emp}\\ \\mathtt{v})} \\label{type:len}\n\\end{align}\nas the refinement @not (emp ([1, 2, 3]))@ evaluates to $\\tttrue$.\n\n\\mypara{Measures as Axioms}\nHow can we reason about invocations of measures in the decidable logic of VCs?\nA natural approach is to treat a measure like @emp@ as an uninterpreted function\nand add logical axioms that capture its behaviour. This looks easy: each equation \nof the measure definition corresponds to an axiom, thus:\n%\n\\begin{align*}\n\\ttemp\\ \\hnull &= \\tttrue\\\\\n\\forall \\ttx, \\ttxs.\\, \\ttemp\\ (\\ttx:\\ttxs) &= \\ttfalse\n\\end{align*}\n%\nUnder these axioms the judgement~\\ref{type:len} is indeed valid. \n% % Measures as data constructor refinements\n\n\\mypara{Measures as Refinements in Types of Data Constructors}\nAxiomatizing measures is \\emph{precise}; that is, \nthe axioms exactly capture the meaning of measures.\nAlas, axioms render SMT solvers \\emph{inefficient}, and render the VC mechanism \\emph{unpredictable}, \nas one must rely on various brittle syntactic matching and instantiation heuristics~\\cite{simplifyj}.\n\nInstead, we use a different approach that is \\emph{both} precise \\emph{and} efficient.\nThe key idea is this: \\emph{instead of translating each measure equation into an axiom, \nwe translate each equation into a refined type for the corresponding data constructor}~\\citep{LiquidPLDI09}.\nThis translation is given in Figure~\\ref{fig:measures}.\nFor example, the definition of the measure @emp@ yields the following refined types for the list data constructors:\n$$\n\\begin{array}{lcl}\n\\hnull  & :: & \\ttreft{v}{[\\tint]}{emp\\ v = true}\\\\\n{:}  & :: & \\tfun{\\ttx}{\\tint}{\\tfun{\\ttxs}{[\\tint]}{\\ttreft{v}{[\\tint]}{emp\\ v = false}}}\n\\end{array}\n$$\nThese types ensure that:\n%\n~(1) each time a list value is \\emph{constructed}, \nits type carries the appropriate emptiness information. \nThus our system is able to statically decide that \n(\\ref{type:len}) is valid and\n~(2) each time a list value is \\emph{matched}, \nthe appropriate emptiness information is used to \nimprove precision of pattern matching, as we see next.\n\n\\mypara{Using Measures}\n\\label{sec:pattern-match}\nAs an example, we use the measure @emp@ to \nprovide an appropriate type for the @head@ function:\n%\n\\begin{code}\n  head    :: {v:[Int] | not (emp v)} -> Int \n  head xs = case xs of\n              (x:_) -> x\n              []    -> error \"yikes\"  \n\n  error   :: {v:String | false} -> a\n  error   = undefined\n\\end{code}\n%\n@head@ is safe as its input type stipulates that it will only \nbe called with lists that are \\emph{not} @[]@, and so\n@error \"...\"@ is dead code.\n%\nThe call to @error@ generates the subtyping query\n%\n\\begin{align*}\n   \\tbind{\\ttxs}{\\tref{\\ttxs}{[\\tint]}{\\trivial}{\\lnot (\\ttemp\\ \\ttxs)}}, \\\n   \\tbind{\\ttb}{\\tttref{\\ttb}{[\\tint]}{\\trivial}{(\\ttemp\\ \\ttxs)= true}} \t\n\t & \\vdash \\subtref{\\tttrue}{\\ttfalse} \n\\end{align*}\n%\nThe match-binder $\\ttb$ holds the result of the \nmatch~\\cite{SulzmannCJD07}. In the \\texttt{[]} case,\nwe assign it the refinement of the type of \\texttt{[]} \nwhich is $(\\ttemp\\ \\ttxs) = \\tttrue$. %~\\cite{LiquidPLDI09}.\n%\nSince the call is done inside a @case-of@ expressions \nboth @xs@ and @b@ are in WHNF,\nthus they have \\Wnf types. \n  \nThe verifier \\emph{accepts} the program as the above subtyping reduces to the valid VC:\n\\begin{align*}\n\\lnot (\\ttemp\\ \\ttxs) \\wedge ((\\ttemp\\ \\ttxs)= \\tttrue) \\Rightarrow\\ & \\tttrue \\Rightarrow\\ \\ttfalse\n\\end{align*}\n%\nThus, our system supports idiomatic \nHaskell, \\eg taking the @head@ of an infinite list:\n%\n\\begin{code}\n  ex x     = head (repeat x)\n  \n  repeat   :: Int -> {v:[Int] | not (emp v)}\n  repeat y = y : repeat y\n\\end{code}\n%\n\n\\mypara{Multiple Measures}\nIf a type has multiple measures, we simply refine each data constructor's type\nwith the \\emph{conjunction} of the refinements from each measure.\n%\nFor example, consider a measure that computes the length of a list:\n\\begin{code}\n  measure len  :: [Int] -> Int\n    len ([])   = 0\n    len (x:xs) = 1 + len xs\n\\end{code}\n%\nUsing the translation of Figure~\\ref{fig:measures},\nwe get the following types for list's data constructors.\n%\n\\begin{align*}\n\\text{[]}  & ::  \\ttreft{v}{[\\tint]}{len\\ v = 0}\\\\\n{:}  & ::  \\tfun{\\ttx}{\\tint}{\\tfun{\\ttxs}{[\\tint]}{\\ttreft{v}{[\\tint]}{len\\ v = 1 + (len\\ xs)}}}\\\\\n\\intertext{The final types for list data are the \nconjunction of the refinements from $\\mathtt{len}$ and $\\mathtt{emp}$:}\\\\\n\\text{[]}  & ::  \\ttreft{v}{[\\tint]}{emp\\ v = true \\land len\\ v = 0}\\\\\n{:}  & ::  \\tfun{\\ttx}{\\tint}{\\tfun{\\ttxs}{[\\tint]}\n           {\\ttreft{v}{[\\tint]}{emp\\ v = false \\land len\\ v = 1 + (len\\ xs)}}}\n\\end{align*}\n\n\n", "meta": {"hexsha": "6c6bf27960d926b3c6284f43222358668fe229d5", "size": 6894, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/refinedhaskell/measures.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/refinedhaskell/measures.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/refinedhaskell/measures.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": 38.5139664804, "max_line_length": 138, "alphanum_fraction": 0.6901653612, "num_tokens": 2155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6780754861534711}}
{"text": "\\chapter{Normal hidden Markov models}\n\n\\section{Forward-backward variables}\n\nLet $(X_t)_{t = 1}^T$ be a homogeneous Markov chain over the state\nspace $S = \\{1, \\ldots, s\\}$ with transition matrix $P = [p_{ij}]$,\n$i, j \\in S$, and initial state distribution $p = [p_i]$, $i \\in S$.\nThen, for each $i_1, \\ldots, i_T \\in S$,\n\\[\n\\Pr(X_1 = i_1, X_2 = i_2, \\ldots, X_T = i_T) = p_{i_1}p_{i_1i_2}\n\\ldots p_{i_{T - 1}i_T}.\n\\]\nFor each state $i \\in S$, let $f_i(y, \\theta_i)$ be a corresponding\nprobability density function. In each moment $t = 1, \\ldots, T$, a\nvalue $y_t$ of a random variable $Y_t$ is observed which comes from\nthe density $f_{i_t}$. The likelihood of the sample $y_1, \\ldots, y_T$\nis\n\\begin{eqnarray*}\n  \\lefteqn{\\mathcal{L} = L(p, P, \\theta_1, \\ldots, \\theta_s) =} \\\\ & =\n  & \\sum_{i_1, \\ldots, i_T = 1}^s p_{i_1}f_{i_1}(y_1, \\theta_{i_1})\n  p_{i_1i_2}f_{i_2}(y_2, \\theta_{i_2}) \\ldots p_{i_{T - 1}i_T}\n  f_{i_T}(y_T, \\theta_{i_T}) = \\\\ & = & \\sum_{i_1 = 1}^s\n  p_{i_1}f_{i_1}(y_1, \\theta_{i_1}) \\sum_{i_2 = 1}^s\n  p_{i_1i_2}f_{i_2}(y_2, \\theta_{i_2}) \\ldots \\sum_{i_T = 1}^s p_{i_{T\n      - 1}i_T}f_{i_T}(y_T, \\theta_{i_T}).\n\\end{eqnarray*}\nThe last expression can be calculated using forward variables\n\\begin{eqnarray}\n  \\label{eq:alpha1}\n  \\alpha_1(j) & = & p_j f_j(y_1, \\theta_j), \\hspace{1em} j \\in S, \\\\\n  \\label{eq:alphat}\n  \\alpha_t(j) & = & \\sum_{i = 1}^s (\\alpha_{t - 1}(i)p_{ij})\n  f_j(y_t, \\theta_j),\n  \\hspace{1em} j\\in S, \\hspace{1em} t = 2, \\ldots, T\n\\end{eqnarray}\nor backward variables\n\\begin{eqnarray}\n  \\label{eq:betaT}\n  \\beta_T(i) & = & 1, \\hspace{1em} i \\in S, \\\\\n  \\label{eq:betat}\n  \\beta_t(i) & = & \\sum_{j = 1}^s p_{ij}f_j(y_{t + 1},\n  \\theta_j)\\beta_{t + 1}(j),\n  \\hspace{1em} i \\in S, \\hspace{1em} t = T - 1, \\ldots, 1\n\\end{eqnarray}\nor both as\n\\begin{equation}\n  \\label{eq:likelihood}\n  \\mathcal{L} = \\sum_{i = 1}^s \\alpha_T(i) = \\sum_{i = 1}^s p_i f_i(y_1,\n  \\theta_i) \\beta_1(i) = \\sum_{i = 1}^s\n  \\alpha_t(i)\\beta_t(i), \\hspace{1em} t = 1, \\ldots, T.\n\\end{equation}\n\nMoreover, if we define\n\\begin{eqnarray}\n  \\label{eq:gamma}\n  \\gamma_t(i) & = & \\alpha_t(i)\\beta_t(i) / \\mathcal{L}, \\hspace{1em} t\n  = 1, \\ldots, T, \\hspace{1em} i \\in S, \\\\\n  \\label{eq:xi}\n  \\xi_t(i, j) & = &\n  \\alpha_t(i)\\beta_{t + 1}(j)p_{ij} f_j(y_{t + 1}, \\theta_j) / \\mathcal{L},\n  \\hspace{1em}\n  t = 1, \\ldots, T - 1, \\hspace{1em} i, j \\in S,\n\\end{eqnarray}\nthe following interpretations are possible:\n\\begin{eqnarray*}\n  \\alpha_t(i) & = & \\Pr(Y_1 = y_1, \\ldots, Y_t = y_t, X_t = i),\n  \\\\ \\beta_t(i) & = & \\Pr(Y_{t + 1} = y_{t + 1}, \\ldots, Y_T = y_T, X_t\n  = i), \\\\\n  \\gamma_t(i) & = & \\Pr(Y_1 = y_1, \\ldots, Y_T = y_T, X_t = i), \\\\\n  \\xi_t(i, j) & = & \\Pr(Y_1 = y_1, \\ldots, Y_T = y_T, X_t = i,\n  X_{t + 1} = j),\n\\end{eqnarray*}\nwhere $\\Pr$ denotes likelihood of the respective event.\n\n\\section{Baum-Welch algorithm}\n\nIf $f_i(y, \\theta_i) = \\phi((y - \\mu_i) / \\sigma_i)$, where $\\phi$ is\nstandard normal probability density, the following formulas can be\nused for $i, j \\in S$ to increase the likelihood $\\mathcal{L}$:\n\\begin{eqnarray}\n  \\label{eq:baumwelchp}\n  \\overline{p}_i & = & \\gamma_1(i), \\\\\n  \\label{eq:baumwelchP}\n  \\overline{p}_{ij} & = & \\frac{\\sum_{t = 1}^{T - 1} \\xi_t(i,\n    j)}{\\sum_{t = 1}^{T - 1} \\gamma_t(i)}, \\\\\n  \\label{eq:baumwelchmu}\n  \\overline{\\mu}_{i} & = & \\frac{\\sum_{t = 1}^T \\gamma_t(i)y_t}{\\sum_{t\n      = 1}^T \\gamma_t(i)}, \\\\\n  \\label{eq:baumwelchsigma}\n  \\overline{\\sigma}_i^2 & = & \\frac{\\sum_{t = 1}^T \\gamma_t(i)(y_t -\n    \\overline{\\mu}_i)^2}{\\sum_{t = 1}^T \\gamma_t(i)}.\n\\end{eqnarray}\n\n\\section{Viterbi algorithm}\n\nHaving found $p$, $P$, $\\theta_1$, \\ldots, $\\theta_s$, one may need to\nfind the best sequence of states, that is a sequence\n\\begin{equation} \\label{eq:bestseq}\n  i_1, \\ldots, i_T\n\\end{equation}\nwhich maximizes\n\\begin{equation} \\label{eq:bestseqprob}\n  p_{i_1}f_{i_1}(y_1, \\theta_{i_1}) p_{i_1i_2}f_{i_2}(y_2, \\theta_{i_2})\n  \\ldots p_{i_{T - 1}i_T}f_{i_T}(y_T, \\theta_{i_T}).\n\\end{equation}\nThe Viterbi algorithm proceeds as follows. Let\n\\begin{displaymath}\n  \\delta_1(i) = p_i f_i(y_1, \\theta_i), \\hspace{1em} \\psi_1(i) =\n  0, \\hspace{1em} i \\in S.\n\\end{displaymath}\nFor $t = 2, \\ldots, T$, let\n\\begin{displaymath}\n  \\delta_t(j) = \\max_{i \\in S} (\\delta_{t - 1}(i) p_{ij}) f_j(y_t,\n  \\theta_j),\n  \\hspace{1em}\n  \\psi_t(j) = \\argmax_{i \\in S} (\\delta_{t - 1}(i) p_{ij}),\n  \\hspace{1em} i \\in S.\n\\end{displaymath}\nThen the maximized probability~(\\ref{eq:bestseqprob}) is equal to\n$\\max_{i \\in S} \\delta_T(i)$ and the best sequence~(\\ref{eq:bestseq})\ncan be backtracked by\n\\begin{displaymath}\n  i_T = \\argmax_{i \\in S} \\delta_T(i),\n  \\hspace{1em}\n  i_t = \\psi_{t + 1}(i_{t + 1}), \\hspace{1em} t = T - 1, \\ldots, 1.\n\\end{displaymath}\n\n\\section{Scaling}\n\nIf the forward and backward variables are scaled, i.~e.\n\\begin{eqnarray}\n  \\label{eq:alpha1scaled}\n  \\hat{\\alpha}_1(j) & = & c_1 \\alpha_1(j), \\hspace{1em} j \\in S, \\\\\n  \\label{eq:alphatscaled}\n  \\hat{\\alpha}_t(j) & = & c_t \\sum_{i = 1}^s (\\hat{\\alpha}_{t -\n    1}(i)p_{ij}) f_j(y_t, \\theta_j),\n  \\hspace{1em} j \\in S, \\hspace{1em} t = 2, \\ldots, T,\n\\end{eqnarray}\nand\n\\begin{eqnarray}\n  \\label{eq:betaTscaled}\n  \\hat{\\beta}_T(i) & = & d_T \\beta_T(i), \\hspace{1em} i \\in S, \\\\\n  \\label{eq:betatscaled}\n  \\hat{\\beta}_t(i) & = & d_t \\sum_{j = 1}^s p_{ij}f_j(y_{t + 1},\n  \\theta_j)\\hat{\\beta}_{t + 1}(j),\n  \\hspace{1em} i \\in S, \\hspace{1em} t = T - 1, \\ldots, 1\n\\end{eqnarray}\nare calculated instead of~(\\ref{eq:alpha1}--\\ref{eq:betat}), where\n\\begin{eqnarray}\n  \\label{eq:c1}\n  c_1^{-1} & = & \\sum_{j = 1}^s \\alpha_1(j), \\\\\n  \\label{eq:ct}\n  c_t^{-1} & = & \\sum_{j = 1}^s \\sum_{i = 1}^s (\\hat{\\alpha}_{t -\n    1}(i)p_{ij}) f_j(y_t, \\theta_j), \\hspace{1em} t = 2, \\ldots, T, \\\\\n  \\label{eq:dT}\n  d_T^{-1} & = & \\sum_{i = 1}^s \\beta_T(i) = s, \\\\\n  \\label{eq:dt}\n  d_t^{-1} & = & \\sum_{i = 1}^s \\sum_{j = 1}^s p_{ij}f_j(y_{t + 1},\n  \\theta_j)\\hat{\\beta}_{t + 1}(j),\n  \\hspace{1em} t = T - 1, \\ldots, 1,\n\\end{eqnarray}\nthen\n\\begin{eqnarray}\n  \\label{eq:alphabyscaled}\n  \\hat{\\alpha}_t(j) & = & c_1 \\ldots c_t \\alpha_t(j) =\n  \\frac{\\alpha_t(j)}{\\sum_{j = 1}^s \\alpha_t(j)}, \\\\\n  \\label{eq:betabyscaled}\n  \\hat{\\beta}_t(i) & = & d_T \\ldots d_t \\beta_t(i) =\n  \\frac{\\beta_t(i)}{\\sum_{i = 1}^s \\beta_t(i)},\n\\end{eqnarray}\nfor $i, j \\in S$, $t = 1, \\ldots, T$. The logarithm of likelihood may be\ncalculated using the first equality~(\\ref{eq:likelihood})\nand~(\\ref{eq:alphabyscaled}) for $t = T$ as\n\\begin{equation}\n  \\label{eq:loglikelihood}\n  \\log \\mathcal{L} = - \\sum_{t = 1}^T \\log c_t,\n\\end{equation}\nsince $\\sum_{i = 1}^s \\alpha_T(i) = (c_1 \\ldots c_T)^{-1}$.\nThe values~(\\ref{eq:gamma}) and~(\\ref{eq:xi}) may be calculated as\n\\begin{eqnarray}\n  \\label{eq:gammabyscaled}\n  \\gamma_t(i) & = & \\frac{\\hat{\\alpha}_t(i)\\hat{\\beta}_t(i)}{\\sum_{i =\n      1}^s \\hat{\\alpha}_t(i) \\hat{\\beta}_t(i)}, \\hspace{1em} t = 1,\n  \\ldots, T, \\\\\n  \\label{eq:xibyscaled}\n  \\xi_t(i, j) & = & d_t\\frac{\\hat{\\alpha}_t(i)\\hat{\\beta}_{t +\n      1}(j)p_{ij} f_j(y_{t + 1}, \\theta_j)}{\\sum_{i = 1}^s\n    \\hat{\\alpha}_t(i) \\hat{\\beta}_t(i)},\n  \\hspace{1em} t = 1, \\ldots, T - 1\n\\end{eqnarray}\nfor $i, j \\in S$.\n\nThe Baum-Welch\nadjustments~(\\ref{eq:baumwelchp}--\\ref{eq:baumwelchsigma}) can be\ncalculated as above except for~(\\ref{eq:baumwelchP}), which should be\ncalculated as\n\\begin{equation}\n  \\label{eq:baumwelchPscaled}\n  \\overline{p}_{ij} = \\frac{\\sum_{t = 1}^{T - 1} \\frac{\\hat{\\alpha}_t(i)\n      \\hat{\\beta}_{t + 1}(j) p_{ij} f_j(y_{t + 1}, \\theta_j)}{\\sum_{i =\n        1}^s \\hat{\\alpha}_t(i) \\hat{\\beta}_t(i)}d_t }{\\sum_{t = 1}^{T - 1}\n    \\gamma_t(i)}\n\\end{equation}\nfor $i, j \\in S$.\n\nThe Viterbi algorithm needs not scaling, but what should be maximized\nis logarithm of~(\\ref{eq:bestseqprob}) rather\nthan~(\\ref{eq:bestseqprob}) itself.\n\n% TODO: Put citations in proper places.\nReferences: \\cite{rabiner-1989}, \\cite{baum-petrie-soules-weiss-1970},\n\\cite{cappe-moulines-ryden-2005}.\n\n\\section{Forecast normal pseudo-residuals}\n\nForecast normal pseudo-residuals are defined as follows \\cite [p.~97]\n{zucchini-macdonald-2009}. If $X_t$ is a continuous random variable\nwith distribution function $F_{X_t}$, then $F_{X_t}(X_t)$ is uniformly\ndistributed on $(0, 1)$ and $u_t = \\Pr(X_t \\leq x_t) = F_{X_t}(x_t)$\nis the uniform pseudo-residual. The random variable\n$\\Phi^{-1}(F_{X_t}(X_t))$ is distributed standard normal and\n\\[\nz_t = \\Phi^{-1}(u_t) = \\Phi^{-1}(F_{X_t}(x_t))\n\\]\nis the normal pseudo-residual. If we take\n\\[\nF_{X_t}(x_t) = \\Pr(X_t \\leq x_t\\ |\\ \\mathbf{X}^{(t - 1)} =\n\\mathbf{x}^{(t - 1)}),\n\\]\nwe get forecast normal pseudo-residuals, while taking\n\\[\nF_{X_t}(x_t) = \\Pr(X_t \\leq x_t\\ |\\ \\mathbf{X}^{(-t)} =\n\\mathbf{x}^{(-t)}),\n\\]\nwe get ordinary normal pseudo-residuals. Therefore, we calculate\ndensity of forecast according to formula\n\\[\n\\Pr(X_t = x\\ |\\ \\mathbf{X}^{(t - 1)} = \\mathbf{x}^{(t - 1)})\n= \\frac{\\alpha_{t - 1} \\Gamma P(x) 1^T}{\\alpha_{t - 1} 1^T}.\n\\]\n", "meta": {"hexsha": "516ee8907159ca0a2e1e3080d2dc05be9a5e19a8", "size": 8872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/nhmm.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/nhmm.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/nhmm.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.8132780083, "max_line_length": 75, "alphanum_fraction": 0.6095581605, "num_tokens": 3950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7577943822145997, "lm_q1q2_score": 0.6780664306773077}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{enumitem}\n\\usepackage{amsmath}\n\\usepackage{booktabs}\n\n\\begin{document}\n\\title{MAT1830 --- Assignment 9}\n\\author{Dylan Pinn --- 24160547}\n\\maketitle\n\n\\section*{Question 1}\n\nA biased coin flips heads with probability $\\frac{4}{9}$ and tails with\nprobability $\\frac{5}{9}$. The coin is flipped 90 times. What is the probability\nthat heads is flipped exactly 40 times?\n\n\\begin{align*}\n  \\Pr(H) &= \\frac{4}{9} \\\\\n  \\Pr(T) &= \\frac{5}{9} \\\\\n  \\Pr(X = k) &= \\binom{n}{k} p^k {(1-p)}^{n-k} \\text{ for } k \\in \\{ 0,\n    \\dots, n \\} \\\\\n  n &= 90 \\\\\n  k &= 40 \\\\\n  p &= \\frac{4}{9} \\\\\n  \\Pr(X = 40) &= \\binom{90}{40} {\\frac{4}{9}}^{40} {(1-\\frac{4}{9})}^{90-40} \\\\\n  &= \\frac{90!}{40!50!} \\times \\frac{4^{40}}{9^{40}} \\times\n  \\frac{5^{50}}{9^{50}} \\\\\n  &\\approx 0.08\n\\end{align*}\n\n\\break{}\n\n\\section*{Question 2}\n\nCars pass through a road junction according to a Poisson distribution. An\naverage of 5 cars per minute pass through the junction.\n\n\\begin{enumerate}[label= (\\alph*)]\n  \\item What is the probability that exactly one car passes through the\n    junction in a certain minute?\n\n  $\\lambda = 5$ and using the Poisson distribution formula gives;\n\n  \\begin{align*}\n    \\Pr(X=k) &= \\frac{{\\lambda}^k {e}^{- \\lambda}}{k!} \\\\\n    \\Pr(X=1) &= \\frac{5^1 e^{-5}}{1!} \\\\\n    &= \\frac{5}{e^5} \\\\\n    &\\approx 0.03\n  \\end{align*}\n\n  \\item Write down the expected number of cars to pass through the junction in\n    four minutes.\n\n    20 cars in 4 minutes.\n\n  \\item What is the probability that exactly 10 cars pass through the junction\n    in a certain four minute period?\n\n    $\\lambda = 20$ from part (b) and using the Poisson distribution gives;\n\n    \\begin{align*}\n      \\Pr(X=10) &= \\frac{20^{10} e^{-20}}{10!} \\\\\n      &= \\frac{1600000000}{567 e^{20}} \\\\\n      &\\approx 0.0058\n    \\end{align*}\n\\end{enumerate}\n\n\\break{}\n\\section*{Question 3}\n\nA random variable $Y$ can only take values in $ \\{ -5, 0, 5 \\}$. The expected\nvalue of $Y$ is 0 and its variance is 24. Find the probability distribution of\n$Y$.\n\n\\begin{center}\n  \\begin{tabular}{c c c c}\n    \\toprule\n    $y$ & -5 & 0 & 5 \\\\\n    $\\Pr(Y=y)$ & $a$ & $b$ & $c$ \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\n\nWe know that $a + b + c = 1$ and $-5 + 5c = 0$ which gives $a = c$.\n\n\\[ a{(-5)}^2 + b{(0)}^2 + c{(5)}^2 = 24 \\]\n\\[ 25a + 25c = 24 \\]\n\\[ 25(a + c) = 24 \\]\n\\[ a + c = \\frac{24}{25} \\]\nas $a = c$ \\[ 2a = \\frac{24}{25} \\]\n\\[ a = \\frac{24}{50} = \\frac{12}{25} \\]\n\nWe can substitute this into the original formula to give:\n\n\\[ a + b + c = 1 \\]\n\\[ b = 1 - a - c \\]\n\\[ = 1 - \\frac{12}{24} - \\frac{12}{24} \\]\n\\[ = \\frac{1}{25} \\]\n\n\\begin{center}\n  \\begin{tabular}{c c c c}\n    \\toprule\n    $y$ & -5 & 0 & 5 \\\\\n    $\\Pr(Y=y)$ & $\\frac{12}{24}$ & $\\frac{1}{24}$ & $\\frac{12}{24}$ \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\n\n\\break{}\n\\section*{Question 4}\n\nWrite down the first five values $(r_0, \\dots, r_4 \\text{ and } s_0, \\dots,\ns_4)$ of each of the following recursive sequences.\n\n\\begin{enumerate}[label = (\\alph*)]\n  \\item $r_0 = 2$, $r_n = {(r_{n-1})}^2 - 3n + 1$ for all integers $n \\geq 1$.\n\n    \\begin{align*}\n      r_0 &= 2 \\\\\n      r_1 &= {(r_0)}^2 - 3 \\times 1 + 1 \\\\\n      &= 2^2 - 3 + 1 \\\\\n      &= 0 \\\\\n      r_2 &= {(r_1)}^2 - 3 \\times 2 + 1 \\\\\n      &= 0^2 - 6 + 1 \\\\\n      &= -7 \\\\\n      r_3 &= {(r_2)}^2 - 3 \\times 3 + 1 \\\\\n      &= {(-7)}^2 - 9 + 1 \\\\\n      &= 39 \\\\\n      r_4 &= {(r_3)}^2 - 3 \\times 4 + 1 \\\\\n      &= 39^2 - 12 + 1 \\\\\n      &= 1510\n    \\end{align*}\n\n  \\item $s_0 = 2$, $s_n = {(s_{n-1})}^2 + {(s_{n-2})}^2 + \\cdots + {(s_0)}^2$\n  for all integers $n \\geq 1$.\n\n    \\begin{align*}\n      s_0 &= 2 \\\\\n      s_1 &= 2^2 \\\\\n          &= 4 \\\\\n      s_2 &= 4^2 + 2^2 \\\\\n          &= 20 \\\\\n      s_3 &= 20^2 + 4^2 + 2^2 \\\\\n          &= 420 \\\\\n      s_4 &= 420^2 + 20^2 + 4^2 + 2^2 \\\\\n          &= 176820\n    \\end{align*}\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "494154972f0121b7e795e41d019012e517ede7f8", "size": 3877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignments/assignment-09.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-09.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-09.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.6754966887, "max_line_length": 80, "alphanum_fraction": 0.524116585, "num_tokens": 1552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370423, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.6780288458949509}}
{"text": "\\chapter{Estimating the CDF and Statistical Functionals}\n\n% 1\n\\begin{ex}\n  Fix a value $x$.\n  Let $\\widehat{F}_n(x)=\\frac{1}{n}\\sum_{i=1}^nI(X_i\\leq x)$ and note that then\n  \\[\n    \\E{\\widehat{F}_n(x)}\n    =\\E{\\frac{1}{n}\\sum_{i=1}^nI(X_i\\leq x)}\n    =\\frac{1}{n}\\sum_{i=1}^n\\E{I(X_i\\leq x)}\n    =\\frac{1}{n}\\sum_{i=1}^n\\P{X_i\\leq x}\n    =F(x).\n  \\]\n  Likewise,\n  \\begin{align*}\n    \\E{\\widehat{F}^2_n(x)}\n     & =\\E{\\left[\\frac{1}{n}\\sum_{i=1}^nI(X_i\\leq x)\\right]^2} \\\\\n     & =\\frac{1}{n^2}\\E{\\sum_{i=1}^nI^2(X_i\\leq x)\n      +\\sum_{j=1}^n\\sum_{\\substack{k = 1                       \\\\ j \\neq k}}^nI(X_j\\leq x)I(X_k\\leq x)}                                                          \\\\\n     & =\\frac{1}{n^2}\\sum_{i=1}^n\\E{I(X_i\\leq x)}\n    +\\frac{1}{n^2}\\sum_{j=1}^n\\sum_{\\substack{k = 1            \\\\ j \\neq k}}^n\\E{I(X_j\\leq x)I(X_k\\leq x)}                                                          \\\\\n     & =\\frac{F(x)}{n}+\\frac{n+1}{n}F^2(x),\n  \\end{align*}\n  and therefore\n  \\[\n    \\var{\\widehat{F}_n(x)}\n    =\\E{\\widehat{F}^2_n(x)}-\\E{\\widehat{F}_n(x)}^2\n    =\\frac{F(x)(1-F(x)}{n}.\n  \\]\n  Thus,\n  \\begin{align*}\n    \\mse{\\widehat{F}_n(x)}\n     & =\\left[\\bias{\\widehat{F}_n(x)}\\right]^2+\\var{\\widehat{F}_n(x)}               \\\\\n     & =\\left[\\E{\\widehat{F}_n(x)}-\\widehat{F}_n(x)\\right]^2+\\var{\\widehat{F}_n(x)} \\\\\n     & =\\var{\\widehat{F}_n(x)}                                                      \\\\\n     & =\\frac{F(x)(1-F(x))}{n}\\to 0,\n  \\end{align*}\n  and we can conclude that $\\widehat{F}_n(x)\\to F(x)$ in quadratic mean (and\n  hence in probability as well).\n\\end{ex}\n\n\\begin{ex}\n  The expected value of a $\\text{Bernoulli}(p)$ variable is $p$, and therefore\n  the plug-in estimator for $p$ is given by $\\overline{X}_n$. Since $\\var{X_i}\n    =\\sqrt{p(1-p)}$, the plug-in estimator for the standard error is given\n  by\n  \\[\n    \\frac{\\widehat{\\sigma}}{\\sqrt{n}}\n    =\\sqrt{\\frac{\\overline{X}_n(1-\\overline{X}_n)}{n}}.\n  \\]\n\n  Thus, a 90 percent confidence interval for $p$ is given by\n  \\[\n    \\widehat{p}\\pm z_{0.05}\\se(\\widehat{p})\n    =\\overline{X}_n\\pm 1.645\\sqrt{\\frac{\\overline{X}_n(1-\\overline{X}_n)}{n}}.\n  \\]\n\n  The plug-in estimator for $p-q$ is $\\overline{X}_n-\\overline{Y}_n$. Since\n  \\[\n    \\var{\\widehat{p}-\\widehat{q}}\n    =\\var{\\widehat{p}}+\\var{\\widehat{q}}\n    =\\frac{\\overline{X}_n(1-\\overline{X}_n)}{n}\n    +\\frac{\\overline{Y}_m(1-\\overline{Y}_m)}{m},\n  \\]\n  it follows that\n  \\[\n    \\se(\\widehat{p}-\\widehat{q})\n    =\\sqrt{\\frac{\\overline{X}_n(1-\\overline{X}_n)}{n}\n      +\\frac{\\overline{Y}_m(1-\\overline{Y}_m)}{m}},\n  \\]\n  and therefore a 90 percent confidence interval for $p-q$ is given by\n  \\[\n    \\widehat{p}-\\widehat{q}\n    \\pm z_{0.05}\\se(\\widehat{p}-\\widehat{q})\n    =\\overline{X}_n-\\overline{Y}_m\\pm\n    1.645\\sqrt{\\frac{\\overline{X}_n(1-\\overline{X}_n)}{n}\n      +\\frac{\\overline{Y}_m(1-\\overline{Y}_m)}{m}}.\n  \\]\n\\end{ex}\n\n\\begin{ex}~\n  \\inputminted{python}{../code/07-03.py}\n  \\inputminted{text}{../output/07-03.txt}\n\\end{ex}\n\n\\begin{ex}\n  Fix an $x\\in\\R$. Let $Y_i=I(X_i\\leq X)$. Then\n  \\[\n    \\widehat{F}_n(x)\n    =\\frac{1}{n}\\sum_{i=1}^nI(X_i\\leq x)\n    =\\frac{1}{n}\\sum_{i=1}^nY_i,\n  \\]\n  where $Y_i$ is a $\\text{Bernoulli}(p)$ random variable with outcome $1$\n  whenever $X_i \\leq x$, i.e.\\ with $p=F(x)$. Thus, $\\widehat{F}_n(x)$\n  is the average of $n$ such random variables and by the central limit theorem,\n  \\[\n    \\frac{\\sqrt{n}(\\widehat{F}_n(x)-\\mu_Y)}{\\sigma_Y}\n    =\\frac{\\sqrt{n}(\\widehat{F}_n(x)-F(x))}{F(x)(1-F(x))}\n    \\rightsquigarrow Z,\n  \\]\n  or\n  \\[\n    \\sqrt{n}\\left(\\widehat{F}_n(x)-F(x)\\right)\n    \\rightsquigarrow N\\left(0, F(x)(1-F(x))\\right).\n  \\]\n\\end{ex}\n\n% 5\n\\begin{ex}\n  We assume, without loss of generality, that $x\\leq y$. Then, since\n  \\[\n    \\widehat{F}_n(x)\\widehat{F}_n(y)\n    =\\left(\\frac{1}{n}\\sum_{i=1}^nI(X_i\\leq x)\\right)\n    \\left(\\frac{1}{n}\\sum_{i=1}^nI(X_i\\leq y)\\right)\n    =\\frac{1}{n^2}\\sum_{i=1}^n\\sum_{j=1}^nI(X_i\\leq x)I(X_j\\leq y),\n  \\]\n  \\begin{align*}\n    \\E{\\widehat{F}_n(x)\\widehat{F}_n(y)}\n     & =\\frac{1}{n^2}\n    \\sum_{i=1}^n\\sum_{j=1}^n\\E{I(X_i\\leq x)I(X_j\\leq y)}      \\\\\n     & =\\frac{1}{n^2}\\sum_{i=1}^n\\E{I(X_i\\leq x)I(X_i\\leq y)}\n    +\\frac{1}{n^2}\\sum_{i=1}^n\\sum_{\\substack{j=1             \\\\ i\\neq j}}^n\\E{I(X_i\\leq x)I(X_j\\leq y)} \\\\\n     & =\\frac{1}{n}F(x)+\\frac{n-1}{n}F(x)F(y),\n  \\end{align*}\n  \\begin{align*}\n    \\cov{\\widehat{F}_n(x),\\widehat{F}_n(y)}\n     & =\\E{\\widehat{F}_n(x)\\widehat{F}_n(y)}\n    -\\E{\\widehat{F}_n(x)}\\E{\\widehat{F}_n(y)} \\\\\n     & =\\frac{1}{n}F(x)+\\frac{n-1}{n}F(x)F(y)\n    -F(x)F(y)                                 \\\\\n     & =\\frac{F(x)(1-F(y))}{n}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\begin{align*}\n    \\var{\\widehat{\\theta}}\n     & =\\var{\\widehat{F}_n(b)-\\widehat{F}_n(a)}                                                \\\\\n     & =\\var{\\widehat{F}_n(b)}+\\var{\\widehat{F}_n(a)}-2\\cov{\\widehat{F}_n(b),\\widehat{F}_n(a)} \\\\\n     & =\\frac{F(b)(1-F(b))}{n}\n    +\\frac{F(a)(1-F(a))}{n}\n    +\\frac{F(a)(1-F(b))}{n}                                                                    \\\\\n     & =\\frac{[F(b)-F(a)](1-[F(b)-F(a)])}{n}                                                   \\\\\n     & =\\frac{\\theta(1-\\theta)}{n}\n  \\end{align*}\n  by Theorem 7.3 and Exercise 7.5.\n\n  Hence,\n  \\[\n    \\sehat(\\widehat{\\theta})\n    =\\sqrt{\\frac{\\widehat{\\theta}(1-\\widehat{\\theta})}{n}},\n  \\]\n  and we can define a normal-based $1-\\alpha$ interval by\n  \\[\n    \\widehat{\\theta}\\pm z_{\\alpha/2}\n    \\sqrt{\\frac{\\widehat{\\theta}(1-\\widehat{\\theta})}{n}}.\n  \\]\n\\end{ex}\n\n\\begin{ex}~\n  \\inputminted{python}{../code/07-07.py}\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=1.1]{../images/07-07}\n    \\caption{Graph of a 95\\% confidence band for the empirical CDF.}\n  \\end{figure}\n  \\inputminted{text}{../output/07-07.txt}\n\\end{ex}\n\n\\begin{ex}~\n  \\inputminted{python}{../code/07-08.py}\n  \\inputminted{text}{../output/07-08.txt}\n\\end{ex}\n\n\\begin{ex}\n  We have $\\widehat{p}_1=0.9$ and $\\widehat{p}_2=0.85$. Thus,\n  $\\widehat{\\theta}=\\widehat{p}_1-\\widehat{p}_2=0.9-0.85=0.05$ with standard\n  error\n  \\[\n    \\sqrt{\\frac{\\widehat{p}_1(1-\\widehat{p}_1)}{n}\n      +\\frac{\\widehat{p}_2(1-\\widehat{p}_2)}{n}}\n    =0.0466369,\n  \\]\n  an 80 percent confidence interval\n  \\[\n    \\widehat{\\theta}\\pm z_{0.1}\\se(\\thetahat)\n    =0.05\\pm 1.28155\\cdot 0.04664\n    =0.05\\pm 0.059768,\n  \\]\n  and a 95 percent confidence interval\n  \\[\n    \\widehat{\\theta}\\pm z_{0.025}\\se(\\thetahat)\n    =0.05\\pm 1.96\\cdot 0.04664\n    =0.05\\pm 0.091408.\n  \\]\n\\end{ex}\n\n% 10\n\\begin{ex}~\n  \\inputminted{python}{../code/07-10.py}\n  \\inputminted{text}{../output/07-10.txt}\n\\end{ex}", "meta": {"hexsha": "72f2ad92542398f5d833483da9bb275d339cd626", "size": 6586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch07.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/ch07.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/ch07.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.4433497537, "max_line_length": 166, "alphanum_fraction": 0.523079259, "num_tokens": 2825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.6780288368232844}}
{"text": "\\documentclass[]{article}\n\\usepackage{caption,subcaption,graphicx,float,url,amsmath,amssymb,tocloft,wasysym,amsthm,thmtools}\n\\usepackage[hidelinks]{hyperref}\n\\usepackage[toc,acronym,nonumberlist]{glossaries}\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\n%opening\n\\title{\n\tComputation in Complex Systems\\\\\n\tPeer Review Assignment\\\\\n\tWeek 1\n}\n\n%\\makeglossaries\n\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Polynomials \\& Exponentials}\n\n\\begin{quotation}\n\tToday, your computer can do $T$ steps in a week. According to Moore's law, next year, your computer will be able to do $2T$ steps in a week. How does doubling $T$ change the $n$ that can be computed in a week? \n\\end{quotation}\n\na) This year $T = n^2$. Next year my (new) computer can do $2T$ steps. Let $n^\\prime$ denote the size of problem I can handle next year. Then we have:\n\\begin{align*}\n\tT =& n^2 \\text{, and}\\\\\n\t2T =& (n^\\prime)^2 \\text{, from Moore's Law, whence}\\\\\n\t (n^\\prime)^2=& 2n^2 \\text{, or, taking square roots of both sides}\\\\\n\tn^\\prime=& \\sqrt{2} n\n\\end{align*}\nSo $n$ changes by a factor of $\\sqrt{2}$.\n\nb) This year $T = 2^n$. Next year my (new) computer can do $2T$ steps. Once again let $n^\\prime$ denote the size of problem I can handle next year. Then we have:\n\n\\begin{align*}\n\tT =&2^n \\text{, and}\\\\\n\t2T =& 2^{n^\\prime} \\text{, from Moore's Law, whence}\\\\\n\t2^{n^\\prime}=& 2\\cdot 2^n\\\\\n\t=& 2^{n+1} \\text{, so taking logarithms to base 2}\\\\\n\tn^\\prime =& n+1\n\\end{align*}\n\n\\section{Divide \\& Conquer}\nGiven:\n\\begin{align*}\n\tf(1)=&1 \\numberthis \\label{eq:hypothesis}\\\\\n\tf(n)=&2f(n-1)+1 \\numberthis \\label{eq:recurrence}\n\\end{align*}\nI'll begin by computing the first few values:\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\begin{tabular}{|l|r|} \\hline\n\t\t\tn&$f(n)$\\\\\\hline\n\t\t\t1&1\\\\\\hline\n\t\t\t2&3\\\\\\hline\n\t\t\t3&7\\\\\\hline\n\t\t\t4&15\\\\\\hline\n\t\t\t5&32\\\\\\hline\n\t\t\t6&63\\\\\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\nWe already have enough values to formulate a hypothesis\\footnote{this sounds better than ''guess''}--$f(n)=2^{n+1}-1$:\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\begin{tabular}[H]{|l|r|r|}\\hline\n\t\t\tn&$f(n)$&$2^n-1$\\\\\\hline\n\t\t\t1&1&2-1\\\\\\hline\n\t\t\t2&3&4-1\\\\\\hline\n\t\t\t3&7&8-1\\\\\\hline\n\t\t\t4&15&16-1\\\\\\hline\n\t\t\t5&32&32-1\\\\\\hline\n\t\t\t6&63&64-1\\\\\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{thm}\n\tIf $f$ satisfies (\\ref{eq:hypothesis}) and (\\ref{eq:recurrence}), $f(n)=2^n-1$\n\\end{thm}\n\n\\begin{proof}[Mathematical Induction]\n\t\n\tFrom (\\ref{eq:hypothesis}), $f(1)=1$ and (\\ref{eq:recurrence}) gives $f(2)= 2f(1)+1 = 2\\cdot1+1 =3$. But if $n=2$, $2^n-1=4-1=3$, so the hypothesis is correct for $n=1$.\n\t\n\tAssume the hypothesis is correct for a particular $n$. We want to show it is correct for $n+1$, i.e. that $f(n+1)=2^{n+1}-1$.\n\t\\begin{align*}\n\t\tf(n)=&2^n-1\t\\text{ by hypothesis. We use (\\ref{eq:recurrence})}\\\\\n\t\tf(n+1)=&2f(n) + 1 \\\\\n\t\t=& 2(2^n-1) + 1\\\\\n\t\t=& 2\\cdot 2^n -2 +1\\\\\n\t\t=& 2^{n+1} -1 \n\t\\end{align*}\n\\end{proof}\n\nAlthough this proof is valid, it doesn't shed much light on why $f$ should be close to an exact exponential. The following proof is motivated by the fact that \\ref{eq:recurrence} is close to an exponential doubling assuming that $f(n)$ is large when $n$ is large. Can we find a quantity that is close to $f(n)$ and which satisfies an exact exponential recurrence relation. It turn out that we can.\n\\begin{proof}[Alternative]\n\tWe define a new quantity:\n\t\\begin{align*}\n\t\tg(n)\\triangleq& f(n) +1 \\\\\n\t\tg(n+1) = & f(n+1) +1 \\text{, so (\\ref{eq:recurrence}) gives:}\\\\\n\t\t=& \\big(2f(n)+1\\big)+1\\\\\n\t\t=& \\big[2\\big(g(n) -1\\big) +1\\big] +1\\\\\n\t\t=& 2 g(n) \\text{, so the exponential growth of $g(n)$ is obvious, i.e.} \\\\\n\t\tg(n) =& C\\cdot 2^n\\text{, for some constant $C>0$. Now (\\ref{eq:hypothesis}) becomes:}\\\\\n\t\tg(1) =&2\\text{, whence}\\\\\n\t\tC=& 1 \\text{, so}\\\\\n\t\tg(n) =& 2^n \\text{, and} \\\\\n\t\tf(n) =& 2^n - 1\n\t\\end{align*}\n\\end{proof}\n\\begin{cor}\n\t\\begin{align*}\n\t\tf(64) =& 2^{64}-1\\\\\n\t\t=& 36,893,488,147,419,103,231\n\t\\end{align*}\n\\end{cor}\n\n\\begin{proof}\n\tThe value was calculated by the following Python code:\n\t\\begin{verbatim}\n\t\tN = 1\n\t\tfor i in range(65):\n\t \t     N*=2\n\t\tprint (N-1)\n\t\\end{verbatim}\n\\end{proof}\n% glossary\n%\\printglossaries\n\n% bibliography go here\n\n%\\bibliographystyle{unsrt}\n%\\addcontentsline{toc}{section}{Bibliography}\n%\\bibliography{origins,wikipedia}\n\n\\end{document}\n", "meta": {"hexsha": "c6637cd50a3a01d2110d2d8d38675fcf937e52ea", "size": 4556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "computations/exam1.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/exam1.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/exam1.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": 30.1721854305, "max_line_length": 397, "alphanum_fraction": 0.6532045654, "num_tokens": 1760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407016, "lm_q2_score": 0.9086178956955642, "lm_q1q2_score": 0.6779552314856673}}
{"text": "\n\\section{The \\minelement algorithm}\n\\Label{sec:minelement}\n\nThe \\minelement  algorithm in the \\cxx Standard Library \\cite[\\S 28.7.8]{cxx-17-draft}\nsearches the minimum in a general sequence. \nThe signature of our version of \\minelement reads:\n\n\\begin{lstlisting}[style = acsl-block]\n\n  size_type min_element(const value_type* a, size_type n);\n\\end{lstlisting}\n\nThe function \\minelement finds the smallest element in the range \\inl{a[0..n-1]}.\nMore precisely, it returns the unique valid index \\inl{i} such that\n\\inl{a[i]} is minimal among the values \\inl{a[0]}, \\ldots,\n\\inl{a[n-1]}, and \\inl{i} is the first position with that property.\nThe return value of \\minelement is \\inl{n} if and only if \\inl{n == 0}.\n\nWe use the predicate \\logicref{LowerBound} that\nbasically expresses that a given value is less or equal than all\nelements of a given array (section).\n%\nClosely related to the predicate \\LowerBound is the predicate \\logicref{StrictLowerBound}.\n%\nWe also use the predicate \\logicref{MinElement} which states that the element\nat a given index \\inl{min} is a \\emph{lower bound} of the sequence \\inl{a[0..n-1]},\nand, by construction, a member of that sequence.\n\n\n\\subsection{Formal specification of \\minelement}\n\n\nThe following listing contains the specification of \\specref{minelement}.\nNote that we also use the predicate \\logicref{StrictLowerBound} in order to\nexpress that \\minelement returns the \\emph{first} minimum position in \\inl{a[0..n-1]}.\n\n\\input{Listings/min_element.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\minelement}\n\nThe implementation of \\implref{minelement} uses the predicates \\logicref{LowerBound}\nand \\logicref{StrictLowerBound} in its loop annotations.\n\n\\input{Listings/min_element.c.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "0ac979a14a2818962281058dc009a56379836a0b", "size": 1742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/maxmin/min_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/min_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/min_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": 34.1568627451, "max_line_length": 90, "alphanum_fraction": 0.7657864524, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891435927269, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6778636416261579}}
{"text": "\\subsection{Matrices over rings}\\label{subsec:matrices_over_rings}\n\nWe will define and prove some fundamental notions about matrices. We will start with matrices over plain sets and end up with matrices over nontrivial noetherian commutative rings. This is about as general as we want to go without the underlying ring being a field. The main benefit is being able to work with the \\hyperref[def:set_of_integers]{ring of integers} or more general semirings, like the \\hyperref[def:tropical_semiring]{tropical semirings}.\n\n\\begin{definition}\\label{def:array}\\mimprovised\n  Let \\( S \\) be any nonempty \\hyperref[def:set]{set} and \\( n_1, \\ldots, n_k \\) be \\hyperref[def:integer_signum]{positive integers}. An \\term{array} of shape \\( n_1 \\times \\cdots \\times n_k \\) is a \\hyperref[def:function]{function} with signature\n  \\begin{equation*}\n    A: \\set{ 1, 2, \\ldots, n_1 } \\times \\ldots \\times \\set{ 1, 2, \\ldots, n_k } \\to S.\n  \\end{equation*}\n\n  \\enquote{Multi-dimensional array} is also used as a term, but we will avoid it because the terminology conflicts with \\hyperref[thm:vector_space_dimension]{vector space dimensions}.\n\n  We can regard \\enquote{\\( n_1 \\times \\cdots \\times n_k \\)} simultaneously as a convenient notation and as a \\hyperref[def:cartesian_product]{Cartesian product} of finite \\hyperref[def:ordinal]{ordinals} (modulo the fact that finite ordinals are zero-based).\n\n  In particular:\n  \\begin{thmenum}\n    \\thmitem{def:array/matrix} A two-dimensional array of shape \\( m \\times n \\) is usually called a \\term{matrix}. Let \\( A \\) be an \\( m \\times n \\)-matrix. We will denote \\( A \\) as\n    \\begin{equation*}\n      A = \\seq{ a_{i,j} }_{i,j=1}^{m,n}\n    \\end{equation*}\n    or graphically as the table\n    \\begin{equation*}\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{equation*}\n\n    \\thmitem{def:array/square_matrix} A \\term{square matrix} of order \\( n \\) is simply an \\( n \\times n \\) matrix.\n\n    \\thmitem{def:array/column_vector} A \\term{column vector} of dimension \\( m \\) is simply a \\( m \\times 1 \\) matrix\n    \\begin{equation*}\n      \\begin{pmatrix}\n        a_{1,1} \\\\\n        \\vdots  \\\\\n        a_{m,1}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    When \\( S \\) is a \\hyperref[def:semiring]{semiring} \\( R \\), we often identify the set of all \\( m \\)-dimensional column vectors with the free semimodule \\hyperref[def:standard_basis]{\\( R^m \\)}.\n\n    \\thmitem{def:array/row_vector} A \\term{row vector} of dimension \\( n \\) is simply an \\( 1 \\times n \\) matrix\n    \\begin{equation*}\n      \\begin{pmatrix}\n        a_{1,1} & \\cdots & a_{1,n}\n      \\end{pmatrix}.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:vector_etymology}\n  In practice, the terms \\enquote{vector}, \\enquote{tuple} and \\enquote{finite sequence} are used interchangeably. Formally, the concepts differ slightly:\n\n  \\begin{itemize}\n    \\item \\enquote{Vector} refers to an element of a \\hyperref[def:vector_space]{vector space} or, more generally, a \\hyperref[def:semimodule]{semimodule}. \\hyperref[def:array/column_vector]{Column vectors} and \\hyperref[def:array/row_vector]{row vectors} are important special cases.\n\n    \\item Tuples are defined and discussed in \\fullref{def:cartesian_product/tuple}. Tuples are technically \\hyperref[def:cartesian_product/indexed_family]{indexed families} and the latter are defined without reference to functions, which we use to define both arrays and sequences.\n\n    \\item Sequences are defined and discussed in \\fullref{def:sequence}. Formally, a finite sequence of length \\( n \\) is the same as an array of shape \\( n \\).\n  \\end{itemize}\n\\end{remark}\n\n\\begin{definition}\\label{def:block_matrix}\n  A \\term{block matrix} is a \\enquote{matrix of matrices}. That is, a matrix of the form\n  \\begin{equation*}\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{equation*}\n  where all \\( A_{i,j} \\) are matrices of compatible dimensions.\n\n  We can write the block matrix\n  \\begin{equation*}\n    \\begin{pmatrix}\n      A      & \\cdots & B      \\\\\n      \\vdots & \\ddots & \\vdots \\\\\n      C      & \\cdots & D\n    \\end{pmatrix}\n  \\end{equation*}\n  as\n  \\begin{equation*}\n    \\parens*\n      {\n        \\begin{array}{ccc|c|ccc}\n          a_{1,1}   & \\cdots & a_{1,n_A}   & \\cdots & b_{1,1}   & \\cdots & b_{1,n_B} \\\\\n          \\vdots    & \\ddots & \\vdots      & \\cdots & \\vdots    & \\ddots & \\vdots \\\\\n          a_{m_A,1} & \\cdots & a_{m_A,n_A} & \\cdots & b_{m_B,1} & \\cdots & b_{m_B,n_B} \\\\\n          \\hline\n          \\vdots    & \\vdots & \\vdots      & \\ddots & \\vdots    & \\vdots & \\vdots \\\\\n          \\hline\n          c_{1,1}   & \\cdots & c_{1,n_C}   & \\cdots & d_{1,1}   & \\cdots & d_{1,n_D} \\\\\n          \\vdots    & \\ddots & \\vdots      & \\cdots & \\vdots    & \\ddots & \\vdots \\\\\n          c_{m_C,1} & \\cdots & c_{m_C,n_C} & \\cdots & d_{m_D,1} & \\cdots & d_{m_D,n_D} \\\\\n        \\end{array}\n      }.\n  \\end{equation*}\n\n  Given any matrix \\( A = \\seq{ a_{i,j} }_{i,j=1}^{n,m} \\), we can represent it via its block matrix of rows\n  \\begin{equation*}\n    \\parens*\n      {\n        \\begin{array}{c}\n          a_{1,\\anon*} \\\\\n          \\hline\n          a_{2,\\anon*} \\\\\n          \\hline\n          \\vdots \\\\\n          \\hline\n          a_{n,\\anon*}\n        \\end{array}\n      },\n  \\end{equation*}\n  and its block matrix of columns\n  \\begin{equation*}\n    \\parens*\n      {\n        \\begin{array}{c|c|c|c}\n          a_{\\anon*,1} & a_{\\anon*,2} & \\cdots & a_{\\anon*,m}\n        \\end{array}\n      }\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:matrix_diagonal}\n  The \\term{main diagonal} of the matrix \\( A = \\seq{ a_{i,j} }_{i,j=1}^{m,n} \\) is the sequence \\( a_{1,1}, \\ldots, a_{i,i}, \\ldots, a_{k,k} \\), where \\( k \\coloneqq \\min\\set{ m, n } \\). The \\term{antidiagonal} is instead \\( a_{1,k}, \\ldots, a_{i,k-i}, \\ldots, a_{k,n-k} \\). These can be visualized as follows:\n  \\begin{equation*}\n    \\begin{pmatrix}\n      \\fbox{\\( a_{1,1} \\)} & a_{1,2}                & \\cdots & a_{1,k-1}                & \\fbox{\\( a_{k,k} \\)} & \\cdots \\\\\n      a_{2,1}              & \\fbox{\\( a_{2,2} \\)}   &        & \\fbox{\\( a_{2,k-1} \\)}   & a_{2,k}              &        \\\\\n      \\vdots               &                        & \\ddots &                          & \\vdots               &        \\\\\n      a_{k-1,1}            & \\fbox{\\( a_{k-1,2} \\)} &        & \\fbox{\\( a_{k-1,k-1} \\)} & a_{k-1,k}            & \\cdots \\\\\n      \\fbox{\\( a_{k,1} \\)} & a_{k,2}                & \\cdots & a_{k,k-1}                & \\fbox{\\( a_{k,k} \\)} &        \\\\\n      \\vdots               &                        &        & \\vdots                   &                      & \\ddots\n    \\end{pmatrix}\n  \\end{equation*}\n\n  Over a \\hyperref[def:semiring]{semiring}, we say that a square matrix \\term{diagonal} if all entries outside the main diagonal are zero. For brevity, we write\n  \\begin{equation*}\n    \\op{diag}(a_1, \\ldots, a_n)\n    \\coloneqq\n    \\begin{pmatrix}\n      a_1    & 0      & \\cdots & 0      \\\\\n      0      & a_2    & \\cdots & 0      \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      0      & 0      & \\cdots & a_n\n    \\end{pmatrix}\n  \\end{equation*}\n\n  The notation \\( \\op{diag}(A) \\) is also used to denote the sequence of diagonal entries of \\( A \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:matrix_algebra}\n  Denote by \\( R^{m \\times n} \\) the set of \\( m \\times n \\) \\hyperref[def:array/matrix]{matrices} over the \\hyperref[def:semiring]{semiring} \\( R \\). We define three operations on matrices:\n  \\begin{thmenum}\n    \\thmitem{def:matrix_algebra/addition} We define \\term{matrix addition} \\( +: R^{m \\times n} \\times R^{m \\times n} \\to R^{m \\times n} \\) componentwise as\n    \\begin{equation*}\n      \\begin{pmatrix}\n        a_{1,1} & \\cdots & a_{1,n} \\\\\n        \\vdots  & \\ddots & \\vdots  \\\\\n        a_{m,1} & \\cdots & a_{m,n}\n      \\end{pmatrix}\n      +\n      \\begin{pmatrix}\n        b_{1,1} & \\cdots & b_{1,n} \\\\\n        \\vdots  & \\ddots & \\vdots  \\\\\n        b_{m,1} & \\cdots & b_{m,n}\n      \\end{pmatrix}\n      \\coloneqq\n      \\begin{pmatrix}\n        a_{1,1} + b_{1,1} & \\cdots & a_{1,n} + b_{1,n} \\\\\n        \\vdots            & \\ddots & \\vdots            \\\\\n        a_{m,1} + b_{m,1} & \\cdots & a_{m,n} + b_{m,n}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    With addition, \\( R^{m \\times n} \\) becomes an \\hyperref[def:monoid/commutative]{commutative monoid} with neutral element the \\term{zero matrix}\n    \\begin{equation}\\label{eq:def:matrix_algebra/matrix_multiplication/zero}\n      \\begin{pmatrix}\n        0       & 0      & \\cdots & 0      \\\\\n        0       & 0      & \\cdots & 0      \\\\\n        \\vdots  & \\cdots & \\ddots & \\vdots \\\\\n        0       &        & \\cdots & 0\n      \\end{pmatrix}.\n    \\end{equation}\n\n    \\thmitem{def:matrix_algebra/scalar_multiplication} We define \\term{scalar multiplication} \\( \\cdot: R \\times R^{m \\times n} \\to R^{m \\times n} \\) as\n    \\begin{equation*}\n       \\lambda \\cdot \\begin{pmatrix}\n        a_{1,1} & \\cdots & a_{1,n} \\\\\n        \\vdots  & \\ddots & \\vdots  \\\\\n        a_{m,1} & \\cdots & a_{m,n}\n      \\end{pmatrix}\n      \\coloneqq\n      \\begin{pmatrix}\n        \\lambda a_{1,1} & \\cdots & \\lambda a_{1,n} \\\\\n        \\vdots          & \\ddots & \\vdots          \\\\\n        \\lambda a_{m,1} & \\cdots & \\lambda a_{m,n}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    Under \\hyperref[def:matrix_algebra/addition]{addition} and \\hyperref[def:matrix_algebra/scalar_multiplication]{scalar multiplication}, \\( R^{m \\times n} \\) becomes an \\( R \\)-\\hyperref[def:semimodule]{semimodule}.\n\n    \\thmitem{def:matrix_algebra/matrix_multiplication} We define \\term{matrix multiplication} in two steps. The definition is justified by \\fullref{thm:matrix_and_linear_function_algebras}. First, if \\( \\seq{ a_{1,j} }_{j=1}^n \\) is a \\hyperref[def:array/row_vector]{row vector} and \\( \\seq{ b_{i,1} }_{i=1}^m \\) is a \\hyperref[def:array/column_vector]{column vector}, we define their \\term{inner product} as\n    \\begin{equation*}\n      a \\cdot b \\coloneqq \\sum_{i=1}^n a_i b_i.\n    \\end{equation*}\n\n    We can now define matrix multiplication \\( \\cdot: R^{m \\times k} \\times R^{k \\times n} \\to R^{m \\times n} \\) as\n    \\begin{equation*}\n     \\parens*\n       {\n         \\begin{array}{c}\n            a_{1,-} \\\\\n            \\hline\n            a_{2,-} \\\\\n            \\hline\n            \\vdots \\\\\n            \\hline\n            a_{m,-}\n          \\end{array}\n        }\n      \\cdot\n      \\parens*\n        {\n          \\begin{array}{c|c|c|c}\n            b_{-,1} & b_{-,2} & \\cdots & b_{-,n}\n          \\end{array}\n        }\n      \\coloneqq\n      \\begin{pmatrix}\n        a_{1,-} \\cdot b_{-,1} & a_{1,-} \\cdot b_{-,2} & \\vdots & a_{1,-} \\cdot b_{-,n} \\\\\n        a_{2,-} \\cdot b_{-,1} & a_{2,-} \\cdot b_{-,2} & \\vdots & a_{2,-} \\cdot b_{-,n} \\\\\n        \\vdots                & \\vdots                & \\ddots & \\vdots                \\\\\n        a_{m,-} \\cdot b_{-,1} & a_{m,-} \\cdot b_{-,2} & \\cdots & a_{m,-} \\cdot b_{-,n}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    If \\( n \\) and \\( m \\) are equal, \\( R^{n \\times n} \\) becomes an \\( R \\)-\\hyperref[def:algebra_over_semiring]{algebra} under \\hyperref[def:matrix_algebra/matrix_multiplication]{matrix multiplication} with multiplicative identity the \\term{identity matrix} of order \\( n \\)\n    \\begin{equation}\\label{eq:def:matrix_algebra/matrix_multiplication/identity}\n      \\op{diag}(\\underbrace{ 1, \\cdots, 1 }_{n \\T*{ones}})\n      =\n      \\begin{pmatrix}\n        1       & 0      & \\cdots & 0      \\\\\n        0       & 1      & \\cdots & 0      \\\\\n        \\vdots  & \\ddots & \\ddots & \\vdots \\\\\n        0       &        & \\cdots & 1\n      \\end{pmatrix}.\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  The semimodule structure is inherited by the \\hyperref[thm:semiring_is_semimodule]{semimodule structure} on \\( R \\). We will show that, if \\( n = n \\), matrix multiplication is associative and bilinear. Fix matrices\n  \\begin{equation*}\n    \\begin{aligned}\n      A = \\seq{ a_{i,j} }_{i,j=1}^{m,k} && B = \\seq{ b_{i,j} }_{i,j=1}^{k,l} && C = \\seq{ c_{i,j} }_{i,j=1}^{l,n}.\n    \\end{aligned}\n  \\end{equation*}\n\n  \\SubProofOf[def:magma/associative]{associativity} The \\( (i, j) \\)-th entry in \\( D \\coloneqq (AB)C \\) is\n  \\begin{equation*}\n    d_{i,j} = \\sum_{s=1}^n \\parens*{ \\sum_{r=1}^n a_{i,r} \\cdot b_{r,s} } \\cdot c_{s,j}.\n  \\end{equation*}\n\n  Due to distributivity,\n  \\begin{equation*}\n    d_{i,j}\n    =\n    \\sum_{s=1}^n \\sum_{r=1}^n a_{i,r} \\cdot b_{r,s} \\cdot c_{s,j}\n    =\n    \\sum_{r=1}^n a_{i,r} \\cdot \\parens*{ \\sum_{s=1}^n b_{r,s} \\cdot c_{s,j} },\n  \\end{equation*}\n  which is the \\( (i, j) \\)-th entry in \\( A(BC) \\).\n\n  Therefore, \\( (AB)C = A(BC) \\).\n\n  \\SubProofOf[def:semimodule/homomorphism/additive]{additivity} Again due to distributivity,\n  \\begin{equation*}\n    \\sum_{r=1}^n \\parens*{ a_{i,r} + b_{i,r} } \\cdot c_{r,j}\n    =\n    \\sum_{r=1}^n a_{i,r} \\cdot c_{r,j} + \\sum_{r=1}^n b_{i,r} \\cdot c_{r,j}.\n  \\end{equation*}\n\n  Therefore, \\( (A + B)C = AC + BC \\). The proof that \\( A(B + C) = AB + AC \\) is analogous.\n\n  \\SubProofOf[def:semimodule/homomorphism/homogeneity]{homogeneity} Again due to distributivity,\n  \\begin{equation*}\n    t \\cdot \\sum_{r=1}^n a_{i,r} \\cdot b_{r,j}\n    =\n    \\sum_{r=1}^n (t \\cdot a_{i,r}) \\cdot b_{r,j}\n    =\n    \\sum_{r=1}^n a_{i,r} \\cdot (t \\cdot b_{r,j}).\n  \\end{equation*}\n\n  Therefore, \\( t(AB) = (tA)B = A(tB) \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:matrix_multiplication_is_noncommutative}\n  For \\( n > 1 \\), the \\hyperref[thm:matrix_algebra]{matrix algebra} \\( R^{n \\times n} \\) is a noncommutative ring. Consider the following example:\n  \\begin{align*}\n    \\begin{pmatrix}\n      0 & 0 \\\\\n      0 & 1\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      1 & 0 \\\\\n      1 & 0\n    \\end{pmatrix}\n    &=\n    \\begin{pmatrix}\n      0 & 0 \\\\\n      1 & 0\n    \\end{pmatrix},\n    \\\\\n    \\begin{pmatrix}\n      1 & 0 \\\\\n      1 & 0\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      0 & 0 \\\\\n      0 & 1\n    \\end{pmatrix}\n    &=\n    \\begin{pmatrix}\n      0 & 0 \\\\\n      0 & 0\n    \\end{pmatrix}.\n  \\end{align*}\n\\end{example}\n\n\\begin{remark}\\label{rem:matrices_as_functions}\n  Let \\( R \\) be a \\hyperref[def:ring/commutative]{commutative ring} and let \\( e_1, \\ldots, e_n \\) be the \\hyperref[def:standard_basis]{standard basis} of \\( R \\). The \\hyperref[def:basis_decomposition]{coordinate projections} \\( \\pi_{e_1}, \\ldots, \\pi_{e_n} \\) allow us to identify \\( R^n \\) with the module \\( R^{n \\times 1} \\) of \\hyperref[def:array/column_vector]{column vectors} by regarding the vector \\( x \\) from \\( R^n \\) as the column vector\n  \\begin{equation*}\n    \\begin{pmatrix}\n      \\pi_{e_1}(x) \\\\\n      \\vdots \\\\\n      \\pi_{e_n}(x)\n    \\end{pmatrix}.\n  \\end{equation*}\n\n  Under this identification, the columns on the identity matrix \\eqref{eq:def:matrix_algebra/matrix_multiplication/identity} are precisely the column vectors of the \\hyperref[def:standard_basis]{standard basis}.\n\n  Let \\( A = \\seq{ a_{ij} }_{i,j=1}^{m,n} \\) be an \\( m \\times n \\) matrix over \\( R \\). If we regard \\( R^n \\) as a set of column vectors, then \\hyperref[thm:matrix_algebra/matrix_multiplication]{matrix multiplication} allows us to regard \\( A \\) as the function \\( x \\mapsto Ax \\), which maps column vectors from \\( R^n \\) to column vectors in \\( R^m \\).\n\n  This justifies using juxtaposition for application of linear maps, e.g. \\( Lx \\) rather than \\( L(x) \\).\n\n  Conversely, let \\( e_1, \\ldots, e_n \\) be the standard basis of \\( R^n \\) and \\( f_1, \\ldots, f_m \\) --- of \\( R^m \\). The linear map \\( L: R^n \\to R^m \\) corresponds to the following matrix:\n  \\begin{equation*}\n    \\begin{pmatrix}\n      \\pi_{e_1}(L f_1) & \\cdots & \\pi_{e_1}(L f_1) \\\\\n      \\vdots           & \\ddots & \\vdots       \\\\\n      \\pi_{e_n}(L f_m) & \\cdots & \\pi_{e_n}(L f_m)\n    \\end{pmatrix}.\n  \\end{equation*}\n\\end{remark}\n\n\\begin{proposition}\\label{thm:matrix_and_linear_function_algebras}\n  For a \\hyperref[def:ring/commutative]{commutative ring} \\( R \\), the \\hyperref[def:matrix_algebra]{matrix algebra} \\( R^{m \\times n} \\) is \\hyperref[def:algebra_over_semiring/homomorphism]{isomorphic} to the \\hyperref[thm:functions_over_algebra]{linear function algebra} \\( \\hom(R^n, R^m) \\)\\footnote{Note that the maps are from \\( R^n \\) to \\( R^m \\) and not vice versa}.\n\\end{proposition}\n\\begin{proof}\n  Follows from our discussion in \\fullref{rem:matrices_as_functions} due to linearity.\n\\end{proof}\n\n\\begin{remark}\\label{rem:double_index_maps}\n  We want to be able to map single indices to double indices and vice versa, for example for the purpose of \\fullref{thm:matrix_spaces_are_free_modules}. As an example, we want to be able to \\enquote{linearize} an \\( m \\times n \\) matrix such as the \\( 2 \\times 3 \\) matrix\n  \\begin{equation}\\label{eq:rem:double_index_maps/example/matrix}\n    \\begin{pmatrix}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6\n    \\end{pmatrix}\n  \\end{equation}\n  into the tuple\n  \\begin{equation}\\label{eq:rem:double_index_maps/example/row_major}\n    (1, 2, 3, 4, 5, 6)\n  \\end{equation}\n  and vice versa. This is called \\term{row-major order} of the elements of a matrix. The \\term{column-major order} would instead be\n  \\begin{equation}\\label{eq:rem:double_index_maps/example/column_major}\n    (1, 4, 2, 5, 3, 6).\n  \\end{equation}\n\n  Let \\( m \\) and \\( n \\) be \\hyperref[def:integer_signum]{positive integers}. We will explicitly define functions for linearizing a matrix like \\eqref{eq:rem:double_index_maps/example/matrix} into its row-major order \\eqref{eq:rem:double_index_maps/example/row_major}. Consider the sets\n  \\begin{align*}\n    S &\\coloneqq \\overbrace{ \\set{ 1, \\ldots, mn - 1, mn } }^{\\T{single indices}}\n    \\\\\n    D &\\coloneqq \\underbrace{ \\set{ 1, \\ldots, m } \\times \\set{ 1, \\ldots, n } }_{\\T{double indices}}\n  \\end{align*}\n  and the mutually inverse operations\n  \\begin{align}\n    &\\begin{aligned}\\label{eq:rem:double_index_maps/sharp}\n      &\\sharp: S \\to D \\\\\n      &\\sharp(k) \\coloneqq \\parens[\\Big]{ \\quot(k - 1, m) + 1, \\rem(k - 1, m) + 1 } \\\\\n    \\end{aligned}\n    \\\\[0.5\\baselineskip]\n    &\\begin{aligned}\\label{eq:rem:double_index_maps/flat}\n      &\\flat: D \\to S \\\\\n      &\\flat(i, j) \\coloneqq (i - 1) \\cdot m + (j - 1) + 1.\n    \\end{aligned}\n  \\end{align}\n\n  The operation \\( \\sharp \\) encodes the matrix \\eqref{eq:rem:double_index_maps/example/matrix} into its row-major order \\eqref{eq:rem:double_index_maps/example/row_major} and \\( \\flat \\) does the opposite. Both operations are trivial except for the shifting needed in to allow us to use \\hyperref[def:euclidean_domain]{remainders and quotients}.\n\n  We can easily verify that \\( \\sharp \\) is a \\hyperref[def:morphism_invertibility/left_invertible]{left inverse} of \\( \\flat \\) (note that \\( j < m \\)):\n  \\begin{align*}\n    \\sharp(\\flat(i, j))\n    &=\n    \\sharp\\parens[\\Big]{ (i - 1) \\cdot m + (j - 1) + 1 }\n    = \\\\ &=\n    \\parens[\\Big]{ \\quot(\\cdots, m) + 1, \\rem(\\cdots, m) + 1 }\n    = \\\\ &=\n    \\parens[\\Big]{ (i - 1) + 1, (j - 1) + 1 }\n    = \\\\ &=\n    (i, j).\n  \\end{align*}\n\n  We can just as easily verify that \\( \\flat \\) is a \\hyperref[def:morphism_invertibility/right_invertible]{right inverse} of \\( \\sharp \\):\n  \\begin{align*}\n    \\flat(\\sharp(k))\n    &=\n    \\flat\\parens[\\Big]{ \\quot(k, m) + 1, \\rem(k, m) + 1 }\n    = \\\\ &=\n    \\quot(k, m) \\cdot m + \\rem(k, m)\n    = \\\\ &=\n    k.\n  \\end{align*}\n\n  Hence, \\( \\sharp \\) is fully invertible with inverse \\( \\flat \\). By \\fullref{thm:function_invertibility_categorical/fully_invertible}, it is bijective.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:matrix_spaces_are_free_modules}\n  The \\hyperref[thm:matrix_algebra]{matrix algebra} \\( R^{m \\times n} \\) is isomorphic as a \\hyperref[def:semimodule]{semimodule} to \\( R^{mn} \\).\n\\end{proposition}\n\\begin{proof}\n  \\Fullref{rem:double_index_maps} gives us a semimodule isomorphism between \\( m \\times n \\) matrices and \\( mn \\)-dimensional column vectors when extended to linear maps via \\fullref{thm:free_semimodule_universal_property}.\n\\end{proof}\n\n\\begin{definition}\\label{def:matrix_determinant}\\mcite[215]{Knapp2016BasicAlgebra}\n  The \\term{determinant} for the \\hyperref[thm:matrix_algebra]{matrix algebra} \\( R^{n \\times n} \\) over the \\hyperref[def:semiring/commutative]{commutative semiring} \\( R \\) is the function\n  \\begin{equation}\\label{eq:def:matrix_determinant}\n    \\begin{aligned}\n      &\\det: R^{n \\times n} \\to R \\\\\n      &\\det(\\seq{ a_{i,j} }_{i,j=1}^n) \\coloneqq \\sum_{\\sigma \\in S_n} \\sgn(\\sigma) \\prod_{i=1}^n a_{i,\\sigma(i)},\n    \\end{aligned}\n  \\end{equation}\n  where \\( S_n \\) is the \\hyperref[def:symmetric_group]{symmetric group} and \\( \\sgn \\) is the \\hyperref[def:permutation_parity]{sign} of the permutation \\( \\sigma \\).\n\n  See the proof of \\fullref{thm:determinant_on_columns} for a justification of the definition.\n\\end{definition}\n\n\\begin{definition}\\label{def:symmetric_function}\\mimprovised\n  Given a function \\( f: X^n \\to Y \\), where \\( X \\) and \\( Y \\) are \\hyperref[def:set]{plain sets}, we say that \\( f \\) is \\term{symmetric} if, for any \\hyperref[def:symmetric_group/permutation]{permutation} \\( \\sigma \\in S_n \\), we have\n  \\begin{equation*}\n    f(x_1, \\ldots, x_n) = f(x_{\\sigma(1)}, \\ldots, x_{\\sigma(n)}).\n  \\end{equation*}\n\n  A permutation can be decomposed into \\hyperref[def:symmetric_group/transposition]{transpositions} due to \\fullref{thm:permutation_decomposition_existence}. Hence, the above condition reduces to the simpler condition of \\( f \\) being invariant with respect to swapping any two arguments. That is,\n  \\begin{equation*}\n    f(\\ldots, x_{i-1}, \\fbox{\\( x_i \\)}, x_{i+1}, \\cdots, x_{j-1}, \\fbox{\\( x_j \\)}, x_{j+1}, \\ldots)\n    =\n    f(\\ldots, x_{i-1}, \\fbox{\\( x_j \\)}, x_{i+1}, \\cdots, x_{j-1}, \\fbox{\\( x_i \\)}, x_{j+1}, \\ldots).\n  \\end{equation*}\n\n  In the case where \\( n = 2 \\), this reduces to the simple condition\n  \\begin{equation*}\n    f(x, y) = f(y, x).\n  \\end{equation*}\n\n  Symmetric functions should not be confused with symmetric binary relations defined in \\fullref{def:binary_relation/symmetric}.\n\\end{definition}\n\n\\begin{definition}\\label{def:antisymmetric_function}\\mimprovised\n  Given a function \\( f: X^n \\to Y \\), where \\( X \\) is a \\hyperref[def:set]{plain set} and \\( Y \\) is an \\hyperref[rem:additive_magma]{additive group}, we say that \\( f \\) is \\term{antisymmetric} if, for any \\hyperref[def:symmetric_group/permutation]{permutation} \\( \\sigma \\in S_n \\), we have\n  \\begin{equation*}\n    f(x_1, \\ldots, x_n) = \\sgn(\\sigma) \\cdot f(x_{\\sigma(1)}, \\ldots, x_{\\sigma(n)}).\n  \\end{equation*}\n\n  A permutation can be decomposed into \\hyperref[def:symmetric_group/transposition]{transpositions} due to \\fullref{thm:permutation_decomposition_existence}. Hence, the above condition reduces to the simpler condition of \\( f \\) changing sign when swapping any two arguments. That is,\n  \\begin{equation*}\n    f(\\ldots, x_{i-1}, \\fbox{\\( x_i \\)}, x_{i+1}, \\cdots, x_{j-1}, \\fbox{\\( x_j \\)}, x_{j+1}, \\ldots)\n    =\n    -f(\\ldots, x_{i-1}, \\fbox{\\( x_j \\)}, x_{i+1}, \\cdots, x_{j-1}, \\fbox{\\( x_i \\)}, x_{j+1}, \\ldots).\n  \\end{equation*}\n\n  In the case where \\( n = 2 \\), this reduces to the simple condition\n  \\begin{equation*}\n    f(x, y) = -f(y, x).\n  \\end{equation*}\n\n  Antisymmetric functions should not be confused with antisymmetric binary relations defined in \\fullref{def:binary_relation/antisymmetric}.\n\\end{definition}\n\n\\begin{definition}\\label{def:alternating_function}\\mimprovised\n  Given a commutative ring \\( R \\), and \\( R \\)-module \\( M \\) and a \\hyperref[def:multilinear_function]{multilinear function} \\( f: M \\to R \\), we say that \\( f \\) is \\term{alternating} if, \\( x_i = x_j \\) implies that\n  \\begin{equation*}\n    f(x_1, \\ldots, x_i, \\ldots, x_j, \\ldots x_n) = 0.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:alternating_multilinear_is_antisymmetric}\n  If a \\hyperref[def:multilinear_function]{multilinear map} is \\hyperref[def:alternating_function]{alternating}, it is \\hyperref[def:antisymmetric_function]{antisymmetric}. The converse holds if \\( 2 \\) is a unit.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof If \\( f \\) is an alternating multilinear map, then\n  \\begin{equation*}\n    0\n    =\n    f(\\cdots, x_i + x_j, \\cdots, x_i + x_j, \\cdots)\n    =\n    f(\\cdots, x_i, \\cdots, x_j, \\cdots)\n    +\n    f(\\cdots, x_j, \\cdots, x_i, \\cdots).\n  \\end{equation*}\n\n  Therefore,\n  \\begin{equation*}\n    f(\\cdots, x_i, \\cdots, x_j, \\cdots)\n    =\n    -f(\\cdots, x_j, \\cdots, x_i, \\cdots).\n  \\end{equation*}\n\n  \\NecessitySubProof If \\( f \\) is an antisymmetric multilinear map, then\n  \\begin{equation*}\n    0\n    =\n    f(\\cdots, x_i + x_i, x_i, \\cdots)\n    =\n    2 f(\\cdots, x_i, x_i, \\cdots).\n  \\end{equation*}\n\n  If \\( 2 \\) is a unit, this implies\n  \\begin{equation*}\n    f(\\cdots, x_i, x_i, \\cdots) = 0.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:determinant_on_columns}\n  In the \\hyperref[thm:matrix_algebra]{matrix algebra} \\( R^{n \\times n} \\) over the commutative ring \\( R \\), the determinant function \\( \\det: R^{n \\times n} \\to R \\) can be regarded as a function that maps \\( n \\) column vectors from \\( R^n \\) to \\( R \\). That is,\n  \\begin{equation}\\label{eq:thm:determinant_on_columns}\n    \\det(v_1, \\cdots, v_n) = \\sum_{\\sigma \\in S_n} \\sgn(\\sigma) \\prod_{i=1}^n \\pi_{\\sigma(i)} (v_i).\n  \\end{equation}\n\n  The determinant is an \\hyperref[def:alternating_function]{alternating} \\hyperref[def:multilinear_function]{multilinear function} on columns. Furthermore, it is the unique alternating multilinear function \\( f(v_1, \\ldots, v_n) \\) such that \\( f(e_1, \\ldots, e_n) = 1 \\), where \\( e_1, \\ldots, e_n \\) are vectors of the \\hyperref[def:standard_basis]{standard basis} in \\( R^n \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\pi_1, \\ldots, \\pi_n \\) be the \\hyperref[def:basis_decomposition]{projection functionals} corresponding to the \\hyperref[def:standard_basis]{standard basis} \\( e_1, \\ldots, e_n \\).\n\n  \\SubProof{Proof of multilinearity} Due to linearity of the coordinate projection functionals \\( \\pi_i \\) and due to distributivity in \\( R \\), for every \\( j \\) we have\n  \\begin{align*}\n    &\\phantom{{}={}}\n    \\det(\\cdots, v_{j-1}, ty + rz, v_{j+1}, \\cdots)\n    = \\\\ &=\n    \\sum_{\\sigma \\in S_n} \\sgn(\\sigma) \\cdot \\pi_{\\sigma(j)} (ty + rz) \\prod_{i \\neq j} \\pi_{\\sigma(i)} (v_i)\n    = \\\\ &=\n    t \\sum_{\\sigma \\in S_n} \\sgn(\\sigma) \\cdot \\pi_{\\sigma(j)} (y) \\prod_{i \\neq j} \\pi_{\\sigma(i)} (v_i) + r \\sum_{\\sigma \\in S_n} \\sgn(\\sigma) \\cdot \\pi_{\\sigma(j)} (z) \\prod_{i \\neq j} \\pi_{\\sigma(i)} (v_i)\n    = \\\\ &=\n    t \\cdot \\det(\\cdots, y, \\cdots) + r \\cdot \\det(\\cdots, z, \\cdots).\n  \\end{align*}\n\n  \\SubProof{Proof of alternation} If \\( v_i = v_j \\), then for every even (resp. odd) permutation \\( \\sigma \\), the permutation \\( \\cycle{i, j} \\bincirc \\sigma \\) is odd (resp. even), and hence they cancel out in the sum \\eqref{eq:thm:determinant_on_columns}. This holds for every permutation, hence it remains for the determinant to be zero.\n\n  \\SubProof{Proof of \\( \\det(I_n) = 1 \\)} Note that\n  \\begin{equation*}\n    \\prod_{i=1}^n \\pi_i (e_{\\sigma(i)}) \\neq 0\n  \\end{equation*}\n  if and only if \\( i = \\sigma(i) \\) for every \\( i = 1, \\ldots, n \\). This only holds for the identity permutation, hence\n  \\begin{equation*}\n    \\det(e_1, \\ldots, e_n) = \\prod_{i=1}^n \\pi_i(e_i) = \\prod_{i=1}^n 1 = 1.\n  \\end{equation*}\n\n  \\SubProof{Proof of uniqueness} Suppose that \\( f(v_1, \\ldots, v_n) \\) is an alternating multilinear function such that \\( f(e_1, \\ldots, e_n) = 1 \\).\n\n  For an arbitrary column vector \\( v_j \\) in \\( R^n \\), we have\n  \\begin{equation*}\n    v_j = \\sum_{i=1}^n \\pi_i(v_j) \\cdot e_i.\n  \\end{equation*}\n\n  Then\n  \\begin{align*}\n    f(v_1, \\ldots, v_n)\n    &=\n    f\\parens*{ \\sum_{i_1=1}^n \\pi_{i_1}(v_1) \\cdot e_{i_1}, \\ldots, \\sum_{i_n=1}^n \\pi_{i_n}(v_n) \\cdot e_{i_n} }\n    = \\\\ &=\n    \\sum_{i_1=1}^n \\pi_{i_1}(v_1) \\cdots \\sum_{i_n=1}^n \\pi_{i_n}(v_n) f(e_{i_1}, \\ldots, e_{i_n})\n    = \\\\ &=\n    \\sum_{\\sigma \\in S_n} \\pi_{\\sigma(i)}(v_i) f(e_{\\sigma(1)}, \\ldots, e_{\\sigma(n)}).\n  \\end{align*}\n\n  The last step is valid because \\( f \\) is \\hyperref[def:alternating_function]{alternating} and thus \\( f(e_{i_1}, \\cdots, e_{i_n}) \\) is zero when not all of \\( i_1, \\ldots, i_n \\) are distinct, and they are necessarily distinct if the indices are given by a permutation from \\( S_n \\).\n\n  Finally, since \\( f \\) is \\hyperref[def:antisymmetric_function]{antisymmetric} due to \\fullref{thm:alternating_multilinear_is_antisymmetric},\n  \\begin{equation*}\n    f(e_{\\sigma(1)}, \\ldots, e_{\\sigma(n)}) = \\sgn(\\sigma) \\underbrace{f(e_1, \\ldots, e_n)}_{1 \\T*{by assumption}} = \\sgn(\\sigma).\n  \\end{equation*}\n\n  Therefore,\n  \\begin{equation*}\n    f(v_1, \\ldots, v_n) = \\det(v_1, \\ldots, v_n).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:transpose_matrix}\n  The \\term{transpose matrix} of\n  \\begin{equation*}\n    A = \\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{equation*}\n  is defined as\n  \\begin{equation*}\n    A^T = \\begin{pmatrix}\n      a_{1,1} & a_{1,2} & \\cdots & a_{n,1} \\\\\n      a_{2,1} & a_{2,2} & \\cdots & a_{n,2} \\\\\n      \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n      a_{1,m} & a_{2,m} & \\cdots & a_{n,m}\n    \\end{pmatrix}.\n  \\end{equation*}\n\n  A matrix that is equal to its transpose is called \\term{symmetric}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:matrix_determinant}\n  In the \\hyperref[thm:matrix_algebra]{matrix algebra} \\( R^{n \\times n} \\) over the commutative ring \\( R \\), the \\hyperref[def:matrix_determinant]{determinant} as function on matrices has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:matrix_determinant/transpose} \\( \\det(A^T) = \\det(A) \\).\n    \\thmitem{thm:def:matrix_determinant/homogeneous} \\( \\det(tA) = t^n \\cdot \\det(A) \\).\n    \\thmitem{thm:def:matrix_determinant/homomorphism}\\mcite[sec. 6.7]{Тыртышников2004Лекции} \\( \\det(AB) = \\det(A) \\cdot \\det(B) \\).\n\n    That is, \\( \\det: R^{n \\times n} \\to R \\) is a \\hyperref[def:monoid/homomorphism]{monoid homomorphism} from the \\hyperref[def:semiring]{multiplicative monoid} of the ring \\( R^{n \\times n} \\) to the multiplicative monoid of \\( R \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:matrix_determinant/transpose} The inverse of any permutation in \\( S_n \\) is also a permutation in \\( S_n \\), hence\n  \\begin{equation*}\n    \\det(A^T)\n    =\n    \\sum_{\\sigma \\in S_n} \\sgn(\\sigma) \\prod_{i=1}^n a_{\\sigma(i),i}\n    =\n    \\sum_{\\sigma \\in S_n} \\sgn(\\sigma^{-1}) \\prod_{i=1}^n a_{i,\\sigma^{-1}(i)}\n    =\n    \\det(A).\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:matrix_determinant/homogeneous} Follows from \\fullref{thm:determinant_on_columns}.\n\n  \\SubProofOf{thm:def:matrix_determinant/homomorphism} The \\( j \\)-th column of the product \\( C = AB \\) is\n  \\begin{equation*}\n    c_{\\anon*,j}\n    =\n    \\sum_{i=1}^n b_{i,j} a_{\\anon*,i}\n    =\n    \\begin{pmatrix}\n      \\sum_{i=1}^n a_{1,i} b_{i,j} \\\\\n      \\vdots \\\\\n      \\sum_{i=1}^n a_{n,i} b_{i,j} \\\\\n    \\end{pmatrix}.\n  \\end{equation*}\n\n  Since the determinant is a multilinear function on columns,\n  \\begin{balign*}\n    \\det(c_{\\anon*,1}, \\cdots, c_{\\anon*,n})\n    &=\n    \\det\\parens*{ \\sum_{i_1=1}^n b_{i_1,1} a_{\\anon*,i_1}, \\cdots, \\sum_{i_n=1}^n b_{i_n,n} a_{\\anon*,i_n} }\n    = \\\\ &=\n    \\sum_{i_1=1}^n b_{i_1,1} \\det\\parens*{ a_{\\anon*,i_1}, \\cdots, \\sum_{i_n=1}^n b_{i_n,n} a_{\\anon*,i_n} }\n    = \\\\ &=\n    \\sum_{i_1=1}^n b_{i_1,1} \\cdots \\sum_{i_n=1}^n b_{i_n,n} \\det(a_{\\anon*,i_1}, \\cdots, a_{\\anon*,i_n})\n    = \\\\ &=\n    \\sum_{i_1=1}^n \\cdots \\sum_{i_n=1}^n b_{i_1,1} \\cdots b_{i_n,n} \\det(a_{\\anon*,i_1}, \\cdots, a_{\\anon*,i_n}).\n  \\end{balign*}\n\n  Since the determinant is \\hyperref[def:alternating_function]{alternating} on columns, \\( \\det(a_{\\anon*,i_1}, \\cdots, a_{\\anon*,i_n}) \\) is zero when not all of \\( i_1, \\ldots, i_n \\) are distinct. They are necessarily distinct if the indices are given by a permutation from \\( S_n \\). Therefore,\n  \\begin{balign*}\n    \\det(AB)\n    &=\n    \\sum_{\\sigma \\in S_n} \\prod_{i=1}^n a_{i,\\sigma(i)} \\cdot \\sigma(a_{\\anon*, \\sigma(1)}, \\ldots, a_{\\anon*, \\sigma(n)})\n    = \\\\ &=\n    \\sum_{\\sigma \\in S_n} \\prod_{i=1}^n a_{i,\\sigma(i)} \\cdot \\sgn(\\sigma) \\cdot \\sigma(a_{\\anon*, 1}, \\ldots, a_{\\anon*, n})\n    = \\\\ &=\n    \\det(B) \\det(A).\n  \\end{balign*}\n\\end{proof}\n\n\\begin{definition}\\label{def:submatrix}\\mimprovised\n  If for the matrices \\( A = \\seq{ a_{i,j} }_{i,j=1}^{m,n} \\) and \\( B = \\seq{ b_{i,j} }_{i,j=1}^{k,k} \\) over a commutative ring there exist \\hyperref[def:partially_ordered_set/homomorphism]{monotone functions}\n  \\begin{align*}\n    &h: \\set{ 1, \\ldots, k } \\to \\set{ 1, \\ldots, m }, \\\\\n    &w: \\set{ 1, \\ldots, l } \\to \\set{ 1, \\ldots, n },\n  \\end{align*}\n  such that, for every \\( i = 1, \\ldots, k \\) and \\( j = 1, \\ldots, l \\) we have\n  \\begin{equation*}\n    b_{i,j} = a_{h(i),w(j)}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:matrix_minor}\\mimprovised\n  A \\term{minor} of a matrix is a \\hyperref[def:matrix_determinant]{determinant} of a square \\hyperref[def:submatrix]{submatrix}.\n\\end{definition}\n\n\\medskip\n\n\\begin{theorem}[Laplace expansion]\\label{thm:laplace_expansion}\\mcite[prop. 2.36]{Knapp2016BasicAlgebra}\n  For a square matrix \\( A = \\seq{ a_{i,j} }_{i,j=1}^{n,n} \\) over a commutative ring and a row index \\( i \\), we have\n  \\begin{equation*}\n    \\det A = \\sum_{j=1}^n (-1)^{i + j} a_{i,j} \\det A_{i,j},\n  \\end{equation*}\n  where \\( A_{i,j} \\) is the \\hyperref[def:submatrix]{submatrix} of \\( A \\) obtained by removing the \\( i \\)-th row and the \\( j \\)-th column.\n\n  By \\fullref{thm:def:matrix_determinant/transpose}, we can also expand along a column rather than a row.\n\\end{theorem}\n\\begin{proof}\n  Denote the ring by \\( R \\). We will show that, for the \\( i \\)-th row,\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Phi: R^{n \\times n} \\to R, \\\\\n      &\\Phi(A) \\coloneqq \\sum_{j=1}^n (-1)^{i + j} a_{i,j} \\det A_{i,j}.\n    \\end{aligned}\n  \\end{equation*}\n  is an \\hyperref[def:alternating_function]{alternating} \\hyperref[def:multilinear_function]{multilinear function} on columns.\n\n  Multilinearity follows from the multilinearity of determinants. For proving alternation, suppose that the \\( k \\)-th and \\( l \\)-th columns are equal. Then\n  \\begin{equation*}\n    \\Phi(A) = (-1)^{i + k} a_{i,k} \\det A_{i,k} + (-1)^{i + l} a_{i,l} \\det A_{i,l}.\n  \\end{equation*}\n\n  The matrix \\( A_{i,l} \\) can be obtained from \\( A_{i,k} \\) by swapping \\( \\abs{k - l} \\) columns. Since determinants are antisymmetric, it follows that\n  \\begin{equation*}\n    \\det A_{i,l} = (-1)^{k - l} \\det A_{i,k}.\n  \\end{equation*}\n\n  Furthermore, \\( a_{i,k} = a_{i,l} \\). Therefore,\n  \\begin{equation*}\n    \\Phi(A) = (-1)^{i + k} a_{i,k} \\det A_{i,k} + (-1)^{(i + l) + (k - l)} a_{i,k} \\det A_{i,k} = 0.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:adjugate_matrix}\\mimprovised\n  The \\term{cofactor matrix} of the \\( m \\times n \\) matrix \\( A \\) is\n  \\begin{equation*}\n    \\seq{ (-1)^{i + j} \\det A_{i,j} }_{i,j=1}^{m,n},\n  \\end{equation*}\n  where \\( A_{i,j} \\) is the \\hyperref[def:submatrix]{submatrix} of \\( A \\) obtained by removing the \\( i \\)-th row and the \\( j \\)-th column.\n\n  The \\term{adjugate matrix}, also called the \\term{classical adjoint matrix}, is the transpose of the cofactor matrix.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:inverse_via_adjunction}\n  The \\hyperref[def:adjugate_matrix]{adjugate matrix} of the square \\( n \\times n \\) matrix \\( A \\) satisfies\n  \\begin{equation*}\n    A \\cdot A^{\\op{adj}} = \\det A \\cdot I_n.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  From \\fullref{thm:laplace_expansion} it follows that the \\( (i, i) \\)-th entry of the matrix \\( A \\cdot A^{\\op{adj}} \\) is\n  \\begin{equation*}\n    \\sum_{k=1}^n (-1)^{i + k} a_{i,k} \\det A_{i,k}\n    =\n    \\det A.\n  \\end{equation*}\n\n  For \\( i \\neq j \\), the \\( (i, j) \\)-th entry is\n  \\begin{equation*}\n    \\sum_{k=1}^n (-1)^{i + j} a_{i,k} \\det A_{j,k}\n    =\n    \\det \\widehat A_{j \\mapsto i},\n  \\end{equation*}\n  where \\( \\widehat A_{j \\mapsto i} \\) is the matrix obtained by replacing the \\( j \\)-th column in \\( A \\) with the \\( i \\)-th. The determinant is then zero because it is an alternating function on the columns.\n\n  Thus, the proposition follows.\n\\end{proof}\n\n\\begin{definition}\\label{def:inverse_matrix}\n  We say that \\( B \\in R^{n \\times m} \\) is a \\term{left inverse matrix} of \\( A \\in R^{m \\times n} \\) if \\( BA \\) is the identity matrix \\( I_n \\) and a \\term{right inverse matrix} if \\( AB \\) is \\( I_m \\). These are precisely the left and right inverse linear maps in the correspondence described in \\fullref{thm:matrix_and_linear_function_algebras}.\n\n  Due to \\fullref{thm:square_matrix_left_invertible_iff_right_invertible}, for square matrices, the two notions coincide, and we say that \\( B \\) is simply an \\term{inverse} of \\( A \\). An inverse matrix, if it exists, is unique. We denote this inverse of \\( A \\) by \\( A^{-1} \\).\n\n  We say that \\( A \\) is \\term{invertible} if an inverse exists, and \\term{singular} otherwise.\n\\end{definition}\n\\begin{defproof}\n  The inverse is unique by \\fullref{thm:monoid_inverse_unique}.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:square_matrix_left_invertible_iff_right_invertible}\n  Over a nontrivial \\hyperref[def:noetherian_semiring]{noetherian} commutative ring \\( R \\), a square matrix is \\hyperref[def:inverse_matrix]{left invertible} if and only if it is \\hyperref[def:inverse_matrix]{right invertible}.\n\\end{proposition}\n\\begin{proof}\n  \\NecessitySubProof Suppose that \\( A \\) is a right invertible matrix. When regarding \\( A \\) as a linear map via the identification from \\fullref{rem:matrices_as_functions}, this implies that \\( A \\), as a linear map from \\( R^n \\) to \\( R^n \\), is right invertible. Then it is surjective and, by \\fullref{thm:surjective_endomorphism_in_free_module}, an isomorphism. Therefore, \\( A \\) is a fully invertible matrix.\n\n  \\SufficiencySubProof Now suppose that \\( A \\) is a left inverse of \\( B \\). Then \\( B \\) is a right inverse of \\( A \\), and, by the other direction of the proposition, a two-sided inverse of \\( A \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:matrix_invertibility}\n  In the \\hyperref[def:inverse_matrix]{matrix algebra} \\( R^{n \\times n} \\) over a nontrivial \\hyperref[def:noetherian_semiring]{noetherian} \\hyperref[def:ring/commutative]{commutative ring} \\( R \\), the following are equivalent:\n  \\begin{thmenum}\n    \\thmitem{thm:matrix_invertibility/invertible} The matrix \\( A \\) is \\hyperref[def:inverse_matrix]{invertible}.\n    \\thmitem{thm:matrix_invertibility/determinant} The \\hyperref[def:matrix_determinant]{determinant} of \\( A \\) is \\hyperref[def:divisibility/unit]{invertible}.\n    \\thmitem{thm:matrix_invertibility/columns} The \\hyperref[def:block_matrix]{columns} of \\( A \\) are \\hyperref[thm:linear_dependence]{linearly independent}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\ImplicationSubProof{thm:matrix_invertibility/invertible}{thm:matrix_invertibility/determinant} Suppose that \\( A \\) is invertible.\n\n  By \\fullref{thm:def:matrix_determinant/homomorphism},\n  \\begin{equation*}\n    \\det(A^{-1}) \\det(A) = \\det(A^{-1} A) = \\det(I_n) = 1,\n  \\end{equation*}\n  hence \\( \\det(A) \\) has a multiplicative inverse.\n\n  \\ImplicationSubProof{thm:matrix_invertibility/determinant}{thm:matrix_invertibility/columns} As in \\fullref{thm:determinant_on_columns}, regard \\( \\det(v_1, \\ldots, v_n) \\) are an alternating multilinear function on the columns of a matrix.\n\n  Suppose that \\( \\det(v_1, \\ldots, v_n) \\) is a unit in \\( R \\) and, aiming at a contradiction, suppose that the column vectors \\( v_1, \\ldots, v_n \\) are linearly dependent. Then there exists a nontrivial linear combination that sums to zero:\n  \\begin{equation*}\n    \\sum_{i=1}^n t_i v_i = 0.\n  \\end{equation*}\n\n  Suppose that \\( t_k \\) is nonzero. Then\n  \\begin{align*}\n    0\n    &=\n    \\det\\parens*{ v_1, \\ldots, v_{k-1}, 0, v_{k+1}, \\ldots, v_n }\n    = \\\\ &=\n    \\det\\parens*{ v_1, \\ldots, v_{k-1}, \\sum_{i=1}^n t_i v_i, v_{k+1}, \\ldots, v_n }\n    = \\\\ &=\n    \\sum_{i=1}^n t_i \\det( v_1, \\ldots, v_{k-1}, v_i, v_{k+1}, \\ldots, v_n )\n    = \\\\ &=\n    t_k \\det( v_1, \\ldots, v_{k-1}, v_k, v_{k+1}, \\ldots, v_n ).\n  \\end{align*}\n\n  But we have assumed that \\( \\det( v_1, \\ldots, v_{k-1}, v_k, v_{k+1}, \\ldots, v_n ) \\) is a unit and that \\( t_k \\) is nonzero. Hence, the determinant can only be a zero divisor if the ring is trivial, which we have assumed it is not. The obtained contradiction shows that \\( v_1, \\ldots, v_n \\) are linearly independent.\n\n  \\ImplicationSubProof{thm:matrix_invertibility/columns}{thm:matrix_invertibility/invertible} Suppose that the columns of \\( A \\) are linearly independent. Consider the matrix equation\n  \\begin{equation*}\n    Ax\n    =\n    \\parens*\n    {\n      \\begin{array}{c|c|c}\n        a_{\\anon*,1} & \\cdots & a_{\\anon*,n}\n      \\end{array}\n    }\n    \\begin{pmatrix}\n      x_1 \\\\ \\vdots \\\\ x_n\n    \\end{pmatrix}\n    =\n    \\sum_{k=1}^n x_k a_{\\anon*,k}\n    =\n    \\vect 0.\n  \\end{equation*}\n\n  Since the columns are linearly independent, only \\( x_1 = \\cdots = x_n \\) is a solution to this equation. Thus, when regarding \\( A \\) as the linear map \\( x \\mapsto Ax \\), the \\hyperref[def:module/kernel]{kernel} of \\( A \\) becomes trivial. By \\fullref{thm:def:group/zero_kernel}, this map is injective. As discussed in \\fullref{def:module/category}, the injective linear maps are exactly the left invertible linear maps. Hence, there exists a left inverse of \\( A \\). Since \\( A \\) is a square matrix, by \\fullref{thm:square_matrix_left_invertible_iff_right_invertible}, this implies that \\( A \\) is invertible.\n\\end{proof}\n", "meta": {"hexsha": "3696131b5826f78ffde2826a5bef136df420ee16", "size": 42064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/matrices_over_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/matrices_over_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/matrices_over_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": 49.0828471412, "max_line_length": 615, "alphanum_fraction": 0.6188664892, "num_tokens": 15075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.6778636397841837}}
{"text": "% % % % % % % % % % % % % % % % % % % % % % % % %\n\\chapter{Homotopy theory}\n% % % % % % % % % % % % % % % % % % % % % % % % %\n\n\\section{CW-complexes}\n\n\\begin{definition}\n\tA map $f \\colon X \\rightarrow Y$ is called a\n\t\\textit{weak homotopy equivalence} \\index{homotopy equivalence!weak}\n\tif it induces isomorphisms\n\t\\[\n\t\\pi_n(X, x_0) \\rightarrow \\pi_n(Y, f(x_0))\n\t\\]\n\tfor all $n \\ge 0$ and all choices of basepoints $x_0$ in $X$.\n\\end{definition}\n\n\\begin{theorem}[Whitehead's Theorem]\n\tA weak homotopy equivalence between CW-complexes is a homotopy equivalence.\n\\end{theorem}\n\n% {\\cite[Proposition 4.15]{hatcher2002algebraic}}\n\\begin{proposition}[Geometric interpretation of $n$-connectedness]\n\tIf $(X, A)$ is an $n$-connected CW-pair, then there exists\n\ta CW-pair $(Z, A) \\sim_{\\rel A} (X, A)$\n\tsuch that all cells of $Z \\setminus A$ have dimension greater than $n$.\n\\end{proposition}\n\n\\section{Homology}\n\n\\begin{definition}[Acyclic]\n\tA space $X$ is called \\textit{acyclic}\\index{acyclic} if $\\widetilde{H}_{i}(X) = 0$ for all $i$,\n\ti.e. if its reduced homology vanishes.\n\\end{definition}\n\n\\begin{example}\n\tRemoving a point from a homology sphere yields an acyclic space.\n\tIf the dimension was at least $3$ this does not change\n\tthe fundamental group, so if we started with a nontrivial homology sphere\n\t(i.e.\\ $\\pi_1 \\ne 1$) this will give an example of an acyclic, but\n\tnon-contractible space.\n\t\n\tThis example for the Poincar\\'e homology sphere is described in\n\t\\citep[Example 2.38]{hatcher2002algebraic}.\n\\end{example}", "meta": {"hexsha": "8d9ce6ffa03cf119be625abea38f37a7580bae85", "size": 1521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/chapters/homotopy_theory.tex", "max_stars_repo_name": "ben300694/latex-public", "max_stars_repo_head_hexsha": "bf4baa59b766f1ed646c44d74e19135c882208b4", "max_stars_repo_licenses": ["MIT"], "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/homotopy_theory.tex", "max_issues_repo_name": "ben300694/latex-public", "max_issues_repo_head_hexsha": "bf4baa59b766f1ed646c44d74e19135c882208b4", "max_issues_repo_licenses": ["MIT"], "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/homotopy_theory.tex", "max_forks_repo_name": "ben300694/latex-public", "max_forks_repo_head_hexsha": "bf4baa59b766f1ed646c44d74e19135c882208b4", "max_forks_repo_licenses": ["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.5681818182, "max_line_length": 97, "alphanum_fraction": 0.6831032216, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891348788759, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.677863630895715}}
{"text": "\\problemname{Gnoll Hypothesis}\n\nYou are a huge fan of the RPG \\emph{The Eldest Scrolls: Earthrim} and know all of the game's internal mechanics.\nFor instance, when spawning a new monster, each of the $n$ different types of monsters in the game has some fixed probability of appearing,\nand you know exactly what this probability distribution over monster types is.\n\nHowever, in the latest update the developers seem to have changed the way monsters are spawned.  After some testing and reverse engineering,\nyou realise that instead of spawning all $n$ types of monsters, each spawn location only has a spawn pool of $k$ monster types. These spawn pools are\nchosen randomly at the start of the game, independently for each spawn location, with every monster type having the same chance of being chosen for the spawn pool.  And apparently\na developer was lazy with adjusting the spawn chances.  Instead of normalising the spawn chances of the $k$ chosen types, the developer decided that\nif a type of monster is not chosen, its spawn chance is added to the next chosen monster type in the list of types (and if monster types at the end of the list are not\nchosen, their spawn chances are added to the first chosen monster type in the list).  For example, Figure~\\ref{spawning monsters sample 1} shows a small example with $n=5$ monsters, a possible random choice of $k=3$ of those monsters, and the resulting spawn probabilities for those $3$ monsters.\n\nAfter the update, some monster types seem to appear less often than before, and\nsome more often (for instance now there seem to be Gnolls all over\nthe place).  You believe that the new spawning logic may be\nresponsible for this by having changed the effective spawn chances of\nthe monsters.  In order to test this hypothesis, you decide to compute\nthese effective spawn chances after the update.\n\n\\begin{figure}[h] \\centering\n  \\includegraphics[width=.4\\textwidth]{sample1}\n  \\caption{Sample Input 1 and one possible spawn pool with adjusted spawn chances.}\n  \\label{spawning monsters sample 1}\n\\end{figure}\n\n\\section*{Input}\nThe input consists of:\n\\begin{itemize}\n  \\item One line with two integers $n$ and $k$ ($1 \\le k \\le n \\le 500$), the number of different types of monsters and the number of monsters that are randomly chosen\n    for the spawn pool of each spawn location.\n  \\item One line with $n$ real numbers $s_1, s_2, \\ldots, s_n$ ($s_i \\ge 0$ for each $i$, $\\sum^{n}_{j=1}s_j = 100$), where $s_i$ is the spawn chance in percent for the $i$th type in the list of monster types.  Every real number has at most six digits after the decimal point.\n\\end{itemize}\n\n\\section*{Output}\nOutput a single line containing $n$ real numbers, the effective spawn chance in percent of each type of monster. The $i$th number in your output should correspond to the $i$th type of monster.\nYour answers should have an absolute or relative error of at most $10^{-6}$.\n", "meta": {"hexsha": "9edae84a1682c2ed2658c21e88c8c641edde2afa", "size": 2911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ICPC_Mirrors/Nitc_9.0/nwerc2019all/gnollhypothesis/problem_statement/problem.en.tex", "max_stars_repo_name": "Shahraaz/CP_P_S5", "max_stars_repo_head_hexsha": "b068ad02d34338337e549d92a14e3b3d9e8df712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ICPC_Mirrors/Nitc_9.0/nwerc2019all/gnollhypothesis/problem_statement/problem.en.tex", "max_issues_repo_name": "Shahraaz/CP_P_S5", "max_issues_repo_head_hexsha": "b068ad02d34338337e549d92a14e3b3d9e8df712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ICPC_Mirrors/Nitc_9.0/nwerc2019all/gnollhypothesis/problem_statement/problem.en.tex", "max_forks_repo_name": "Shahraaz/CP_P_S5", "max_forks_repo_head_hexsha": "b068ad02d34338337e549d92a14e3b3d9e8df712", "max_forks_repo_licenses": ["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.6052631579, "max_line_length": 296, "alphanum_fraction": 0.7715561663, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891174511732, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.6778636289389532}}
{"text": "\\section{Linear independence}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the redundant vectors in a set of vectors.\n  \\item Determine whether a set of vectors is linearly independent.\n  \\item Find a linearly independent subset of a set of spanning vectors.\n  \\item Write a vector as a unique linear combination of a set of\n    linearly independent vectors.\n  \\end{enumerate}\n\\end{outcome}\n\n% ----------------------------------------------------------------------\n\\subsection{Redundant vectors and linear independence}\n\nIn Example~\\ref{exa:redundant-span}, we encountered three vectors\n$\\vect{u}$, $\\vect{v}$, and $\\vect{w}$ such that\n$\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}} =\n\\sspan\\set{\\vect{u},\\vect{v}}$.  If this happens, then the vector\n$\\vect{w}$ does not contribute anything to the span of\n$\\set{\\vect{u},\\vect{v},\\vect{w}}$, and we say that $\\vect{w}$ is\n\\textbf{redundant}%\n\\index{redundant vector}%\n\\index{vector!redundant}. The following definition generalizes this\nnotion.\n\n\\begin{definition}{Redundant vectors, linear dependence, and linear independence}{redundant-vectors}\n  Consider a sequence of $k$ vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$.\n  We say that the vector $\\vect{u}_j$ is \\textbf{redundant}%\n  \\index{redundant vector}%\n  \\index{vector!redundant} if it can be written as a linear\n  combination of earlier vectors in the sequence, i.e., if\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 scalars $a_1,\\ldots,a_{j-1}$. We say that the sequence of\n  vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ is \\textbf{linearly\n    dependent}%\n  \\index{linear dependence}%\n  \\index{vector!linearly dependent} if it contains one or more\n  redundant vectors. Otherwise, we say that the vectors are\n  \\textbf{linearly independent}%\n  \\index{linear independence}%\n  \\index{vector!linearly independent}.\n\\end{definition}\n\n\\begin{example}{Redundant vectors}{redundant-vectors}\n  Find the redundant vectors in the following sequence of vectors. Are\n  the vectors linearly independent?\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 0\\end{mymatrix},\n    \\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 2 \\\\ 3\\end{mymatrix},\n    \\quad\n    \\vect{u}_3 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1\\end{mymatrix},\n    \\quad\n    \\vect{u}_4 = \\begin{mymatrix}{c} 2 \\\\ 3 \\\\ 3 \\\\ 4\\end{mymatrix},\n    \\quad\n    \\vect{u}_5 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 2 \\\\ 3\\end{mymatrix},\n    \\quad\n    \\vect{u}_6 = \\begin{mymatrix}{c} 3 \\\\ 3 \\\\ 2 \\\\ 2\\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  \\begin{itemize}\n  \\item The vector $\\vect{u}_1$ is redundant, because it is a linear\n    combination of earlier vectors. (Although there are no earlier\n    vectors, recall from Example~\\ref{exa:span-empty-set} that the empty\n    sum of vectors is equal to the zero vector $\\vect{0}$. Therefore,\n    $\\vect{u}_1$ is indeed an (empty) linear combination of earlier\n    vectors.)\n  \\item The vector $\\vect{u}_2$ is not redundant, because it cannot be\n    written as a linear combination of $\\vect{u}_1$. This is because\n    the system of equations\n    \\begin{equation*}\n      \\begin{mymatrix}{l|l}\n        0 & 1 \\\\\n        0 & 2 \\\\\n        0 & 2 \\\\\n        0 & 3 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n    has no solution.\n  \\item The vector $\\vect{u}_3$ is not redundant, because it cannot be\n    written as a linear combination of $\\vect{u}_1$ and $\\vect{u}_2$.\n    This is because the system of equations\n    \\begin{equation*}\n      \\begin{mymatrix}{ll|l}\n        0 & 1 & 1 \\\\\n        0 & 2 & 1 \\\\\n        0 & 2 & 1 \\\\\n        0 & 3 & 1 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n    has no solution.\n  \\item The vector $\\vect{u}_4$ is redundant, because $\\vect{u}_4 =\n    \\vect{u}_2 + \\vect{u}_3$.\n  \\item The vector $\\vect{u}_5$ is not redundant, because\n    This is because the system of equations\n    \\begin{equation*}\n      \\begin{mymatrix}{llll|l}\n        0 & 1 & 1 & 2 & 0 \\\\\n        0 & 2 & 1 & 3 & 1 \\\\\n        0 & 2 & 1 & 3 & 2 \\\\\n        0 & 3 & 1 & 4 & 3 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n    has no solution.\n  \\item The vector $\\vect{u}_6$ is redundant, because $\\vect{u}_6 =\n    \\vect{u}_2 + 2\\vect{u}_3-\\vect{u}_5$.\n  \\end{itemize}\n  In summary, the vectors $\\vect{u}_1$, $\\vect{u}_4$, and $\\vect{u}_6$\n  are redundant, and the vectors $\\vect{u}_2$, $\\vect{u}_3$, and\n  $\\vect{u}_5$ are not. It follows that the vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_6$ are linearly dependent.\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{The casting-out algorithm}\n\nThe last example shows that it can be a lot of work to find the\nredundant vectors in a sequence of $k$ vectors. Doing so in the naive way\nrequire us to solve up to $k$ systems of linear equations!\nFortunately, there is a much faster and easier method, the so-called\n{\\em casting-out algorithm}.\n\n\\begin{algorithm}{Casting-out algorithm}{casting-out}\n  \\index{casting-out algorithm}%\n  \\index{linear independence!casting-out algorithm}%\n  \\index{vector!casting-out algorithm}%\n  \\textbf{Input:} a list of $k$ vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k\\in\\R^n$.  \\smallskip\n\n  \\textbf{Output:} the set of indices $j$ such that $\\vect{u}_j$ is\n  redundant.\n  \\smallskip\n\n  \\textbf{Algorithm:} Write the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$\n  as the columns of an $n\\times k$-matrix, and reduce to {\\ef}. Every\n  {\\em non-pivot} column, if any, corresponds to a redundant vector.\n\\end{algorithm}\n\n\\begin{example}{Casting-out algorithm}{casting-out}\n  Use the casting-out algorithm to find the redundant vectors among\n  the vectors from Example~\\ref{exa:redundant-vectors}.\n\\end{example}\n\n\\begin{solution}\n  Following the casting-out algorithm, we write the vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_6$ as the columns of a matrix and reduce\n  to {\\ef}.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrrr}\n      0 & 1 & 1 & 2 & 0 & 3 \\\\\n      0 & 2 & 1 & 3 & 1 & 3 \\\\\n      0 & 2 & 1 & 3 & 2 & 2 \\\\\n      0 & 3 & 1 & 4 & 3 & 2 \\\\\n    \\end{mymatrix}\n    \\roweq\\ldots\\roweq\n    \\begin{mymatrix}{rrrrrr}\n      0 & \\circled{1} & 1 & 2 & 0 & 3 \\\\\n      0 & 0 & \\circled{1} & 1 & -1 & 3 \\\\\n      0 & 0 & 0 & 0 & \\circled{1} & -1 \\\\\n      0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The pivot columns are columns $2$, $3$, and $5$. The non-pivot\n  columns are columns $1$, $4$, and $6$. Therefore, the vectors\n  $\\vect{u}_1$, $\\vect{u}_4$, and $\\vect{u}_6$ are redundant. Note\n  that this is the same answer we got in\n  Example~\\ref{exa:redundant-vectors}.\n\\end{solution}\n\nThe above version of the casting-out algorithm only tells us which of\nthe vectors (if any) are redundant, but it does not give us a specific\nway to write the redundant vectors as linear combinations of previous\nvectors. However, we can easily get this additional information if we\nreduce the matrix all the way to {\\rref}. We call this version of the\nalgorithm the {\\em extended casting-out algorithm}.\n\n\\begin{algorithm}{Extended casting-out algorithm}{extended-casting-out}\n  \\index{extended casting-out algorithm}%\n  \\index{casting-out algorithm!extended}%\n  \\index{linear independence!casting-out algorithm!extended}%\n  \\index{vector!casting-out algorithm!extended}%\n  \\textbf{Input:} a list of $k$ vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k\\in\\R^n$.\n  \\smallskip\n\n  \\textbf{Output:} the set of indices $j$ such that $\\vect{u}_j$ is\n  redundant, and a set of coefficients for writing each redundant\n  vector as a linear combination of previous vectors.\n  \\smallskip\n\n  \\textbf{Algorithm:} Write the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$\n  as the columns of an $n\\times k$-matrix, and reduce to\n  {\\rref}. Every {\\em non-pivot} column, if any, corresponds to a\n  redundant vector. If $\\vect{u}_j$ is a redundant vector, then the\n  entries in the $j\\th$ column of the {\\rref} are coefficients for\n  writing $\\vect{u}_j$ as a linear combination of previous\n  non-redundant vectors.\n\\end{algorithm}\n\n\\begin{example}{Extended casting-out algorithm}{extended-casting-out}\n  Use the casting-out algorithm to find the redundant vectors among\n  the vectors from Example~\\ref{exa:redundant-vectors}, and write each\n  redundant vector as a linear combination of previous non-redundant\n  vectors.\n\\end{example}\n\n\\begin{solution}\n  Once again, we write the vectors $\\vect{u}_1,\\ldots,\\vect{u}_6$ as\n  the columns of a matrix. This time we use the extended casting-out\n  algorithm, which means we reduce the matrix to {\\rref} instead of\n  {\\ef}.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrrr}\n      0 & 1 & 1 & 2 & 0 & 3 \\\\\n      0 & 2 & 1 & 3 & 1 & 3 \\\\\n      0 & 2 & 1 & 3 & 2 & 2 \\\\\n      0 & 3 & 1 & 4 & 3 & 2 \\\\\n    \\end{mymatrix}\n    \\roweq\\ldots\\roweq\n    \\begin{mymatrix}{rrrrrr}\n      0 & \\circled{1} & 0 & 1 & 0 & 1 \\\\\n      0 & 0 & \\circled{1} & 1 & 0 & 2 \\\\\n      0 & 0 & 0 & 0 & \\circled{1} & -1 \\\\\n      0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  As before, the non-pivot columns are columns $1$, $4$, and $6$, and\n  therefore, the vectors $\\vect{u}_1$, $\\vect{u}_4$, and $\\vect{u}_6$\n  are redundant. The non-redundant vectors are $\\vect{u}_2$,\n  $\\vect{u}_3$, and $\\vect{u}_5$. Moreover, the entries in the sixth\n  column are $1$, $2$, and $-1$.  Note that this means that the sixth\n  column can be written as $1$ times the second column plus $2$ times\n  the third column plus $(-1)$ times the fourth column. The same\n  coefficients can be used to write $\\vect{u}_6$ as a linear\n  combination of previous {\\em non-redundant} columns, namely:\n  \\begin{equation*}\n    \\vect{u}_6 = 1\\,\\vect{u}_2 + 2\\,\\vect{u}_3 - 1\\,\\vect{u}_5.\n  \\end{equation*}\n  Also, the entries in the fourth column are $1$ and $1$, which are\n  the coefficients for writing $\\vect{u}_4$ as a linear combination of\n  previous non-redundant columns, namely:\n  \\begin{equation*}\n    \\vect{u}_4 = 1\\,\\vect{u}_2 + 1\\,\\vect{u}_3.\n  \\end{equation*}\n  Finally, there are no non-zero entries in the first column. This\n  means that $\\vect{u}_1$ is the empty linear combination\n  \\begin{equation*}\n    \\vect{u}_1 = \\vect{0}.\n  \\end{equation*}\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{Alternative characterization of linear independence}\n\nOur definition of redundant vectors depends on the order in which the\nvectors are written. This is because each redundant vector must be a\nlinear combination of {\\em earlier} vectors in the sequence. For example,\nin the sequence of vectors\n\\begin{equation*}\n  \\vect{u}=\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n  \\vect{v}=\\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n  \\vect{w}=\\begin{mymatrix}{r} 11 \\\\ 8 \\\\ 5 \\end{mymatrix},\n\\end{equation*}\nthe vector $\\vect{w}$ is redundant, because it is a linear combination\nof earlier vectors $\\vect{w} = 2\\,\\vect{u}+3\\,\\vect{v}$. Neither\n$\\vect{u}$ nor $\\vect{v}$ are redundant. On the other hand, in the sequence\nof vectors\n\\begin{equation*}\n  \\vect{u}=\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n  \\vect{w}=\\begin{mymatrix}{r} 11 \\\\ 8 \\\\ 5 \\end{mymatrix},\\quad\n  \\vect{v}=\\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 1 \\end{mymatrix},\n\\end{equation*}\n$\\vect{v}$ is redundant because\n$\\vect{v} = \\frac{1}{3}\\vect{w} - \\frac{2}{3}\\vect{u}$, but neither\n$\\vect{u}$ nor $\\vect{w}$ are redundant. Note that none of the vectors\nhave changed; only the order in which they are written is\ndifferent. Yet $\\vect{w}$ is the redundant vector in the first sequence,\nand $\\vect{v}$ is the redundant vector in the second sequence.\n\nBecause we defined linear independence in terms of the absence of\nredundant vectors, you may suspect that the concept of linear\nindependence also depends on the order in which the vectors are\nwritten. However, this is not the case. The following theorem gives an\nalternative characterization of linear independence that is more\nsymmetric (it does not depend on the order of the vectors).\n\n\\begin{theorem}{Characterization of linear independence}{characterization-linear-independence}\n  Let $\\vect{u}_1,\\ldots,\\vect{u}_k$ be vectors. Then\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent%\n  \\index{linear independence!alternative characterization}%\n  \\index{vector!linearly independent!alternative characterization}\n  if and only if the homogeneous 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%\n  \\index{trivial solution}%\n  \\index{solution!trivial}%\n  \\index{system of linear equations!trivial solution}.\n\\end{theorem}\n\n\\begin{proof}\n  Let $A$ be the $n\\times k$-matrix whose columns are\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$. We know from the theory of\n  homogeneous systems that the system\n  $a_1\\,\\vect{u}_1 + \\ldots + a_k\\,\\vect{u}_k = \\vect{0}$ has no\n  non-trivial solution if and only if every column of the {\\ef} of $A$\n  is a pivot column. By the casting-out algorithm, this is the case if\n  and only if none of the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ are\n  redundant, i.e., if and only if the vectors are linearly independent.\n\\end{proof}\n\n\\begin{example}{Characterization of linear independence}{characterization-linear-independence}\n  Use the method of\n  Theorem~\\ref{thm:characterization-linear-independence} to determine\n  whether the following vectors are linearly independent in $\\R^4$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 3 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We must check whether the equation\n  \\begin{equation*}\n    a_1 \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\\\ 0 \\end{mymatrix}\n    + a_2 \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    + a_3 \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\\\ 2 \\end{mymatrix}\n    + a_4 \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 3 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n  \\end{equation*}\n  has a non-trivial solution. If it does, the vectors are linearly\n  dependent. On the other hand, if there is only the trivial solution,\n  the vectors are linearly independent. We write the augmented matrix\n  and solve:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      1 & 0 & 1 & 2 & 0 \\\\\n      1 & 1 & 2 & 3 & 0 \\\\\n      2 & 1 & 3 & 7 & 0 \\\\\n      0 & 1 & 2 & 1 & 0 \\\\\n    \\end{mymatrix}\n    \\roweq\n    \\ldots\n    \\roweq\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 0 & 1 & 2 & 0 \\\\\n      0 & \\circled{1} & 1 & 1 & 0 \\\\\n      0 & 0 & \\circled{1} & 0 & 0 \\\\\n      0 & 0 & 0 & \\circled{2} & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since every column is a pivot column, there are no free variables;\n  the system of equations has a unique solution, which is\n  $a_1=a_2=a_3=a_4=0$, i.e., the trivial solution. Therefore, the\n  vectors $\\vect{u}_1,\\ldots,\\vect{u}_4$ are linearly independent.\n\\end{solution}\n\n\\begin{example}{Characterization of linear independence}{characterization-linear-independence2}\n  Use the method of\n  Theorem~\\ref{thm:characterization-linear-independence} to determine\n  whether the following vectors are linearly independent in $\\R^3$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 0 \\\\ 4 \\\\ 2 \\end{mymatrix},\\quad\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  As in the previous example, we must check whether the equation\n  $a_1\\,\\vect{u}_1 + a_2\\,\\vect{u}_2 + a_3\\,\\vect{u}_3 = \\vect{0}$ has\n  a non-trivial solution. Once again, we write the augmented matrix\n  and solve:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 1 & 0 & 0 \\\\\n      1 & 3 & 4 & 0 \\\\\n      0 & 1 & 2 & 0 \\\\\n    \\end{mymatrix}\n    \\roweq\n    \\ldots\n    \\roweq\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 1 & 0 & 0 \\\\\n      0 & \\circled{2} & 4 & 0 \\\\\n      0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since column $3$ is not a pivot column, $a_3$ is a free\n  variable. Therefore, the system has a non-trivial solution, and the\n  vectors are linearly dependent.\n\n  With a small amount of extra work, we can find an actual non-trivial\n  solution of\n  $a_1\\,\\vect{u}_1 + a_2\\,\\vect{u}_2 + a_3\\,\\vect{u}_3 =\n  \\vect{0}$. All we have to do is set $a_3=1$ and do a back\n  substitution. We find that $(a_1,a_2,a_3)=(2,-2,1)$ is a\n  solution. In other words,\n  \\begin{equation*}\n    2\\vect{u}_1 - 2\\vect{u}_2 + \\vect{u}_3 = \\vect{0}.\n  \\end{equation*}\n  We can also use this information to write $\\vect{u}_3$ as a linear\n  combination of previous vectors, namely,\n  $\\vect{u}_3 = -2\\vect{u}_1 + 2\\vect{u}_2$.\n\\end{solution}\n\nThe characterization of linear independence in\nTheorem~\\ref{thm:characterization-linear-independence} is mostly\nuseful for theoretical reasons. However, it can also help in solving\nproblems such as the following.\n\n\\begin{example}{Related sets of vectors}{related-linear-independence}\n  Let $\\vect{u},\\vect{v},\\vect{w}$ be linearly independent vectors in\n  $\\R^n$. Are the vectors $\\vect{u}+\\vect{v}$, $2\\vect{u}+\\vect{w}$,\n  and $\\vect{v}-5\\vect{w}$ linearly independent?\n\\end{example}\n\n\\begin{solution}\n  By Theorem~\\ref{thm:characterization-linear-independence}, to check\n  whether the vectors are linearly independent, we must check whether\n  the equation\n  \\begin{equation}\\label{eqn:related-linear-independence1}\n    a(\\vect{u}+\\vect{v}) + b(2\\vect{u}+\\vect{w}) +\n    c(\\vect{v}-5\\vect{w})=\\vect{0}\n  \\end{equation}\n  has non-trivial solutions.  If it does, the vectors are linearly\n  dependent, if it does not, they are linearly independent. We can\n  simplify the equation as follows:\n  \\begin{equation}\\label{eqn:related-linear-independence2}\n    (a+2b)\\vect{u} + (a+c)\\vect{v} + (b-5c)\\vect{w}=\\vect{0}.\n  \\end{equation}\n  Since $\\vect{u}$, $\\vect{v}$, and $\\vect{w}$ are linearly\n  independent, we know, again by\n  Theorem~\\ref{thm:characterization-linear-independence}, that\n  equation {\\eqref{eqn:related-linear-independence2}} only has the\n  trivial solution. Therefore,\n  \\begin{eqnarray*}\n    a + 2b & = & 0, \\\\\n    a + c & = & 0, \\\\\n    b - 5c & = & 0.\n  \\end{eqnarray*}\n  We can solve this system of three equations in three variables, and\n  we find that it has the unique solution $a=b=c=0$. Therefore,\n  $a=b=c=0$ is the only solution to equation\n  {\\eqref{eqn:related-linear-independence1}}, which means that the\n  vectors $\\vect{u}+\\vect{v}$, $2\\vect{u}+\\vect{w}$, and\n  $\\vect{v}-5\\vect{w}$ are linearly independent.\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{Properties of linear independence}\n\nThe following are some properties of linearly independent sets.\n\n\\begin{proposition}{Properties of linear independence}{properties-linear-independence}\n  \\index{linear independence!properties}%\n  \\index{vector!linearly independent!properties}%\n  \\index{properties of linear independence}%\n  \\begin{enumerate}\n  \\item \\textbf{Linear independence and reordering.} If a sequence\n    $\\vect{u}_1,\\ldots,\\vect{u}_k$ of $k$ vectors is linearly\n    independent, then so is any reordering of the sequence (i.e.,\n    whether or not the vectors are linearly independent does not\n    depend on the order in which the vectors are written down).\n  \\item \\textbf{Linear independence of a subset.} If\n    $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent, then so\n    are $\\vect{u}_1,\\ldots,\\vect{u}_j$ for any $j<k$.\n  \\item \\textbf{Linear independence and dimension.}\n    \\label{properties-linear-independence-c}\n    Let $\\vect{u}_1,\\ldots,\\vect{u}_k$ be a sequence of $k$ vectors in\n    $\\R^n$. If $k>n$, then the vectors are linearly dependent (i.e.,\n    not linearly independent).\n  \\end{enumerate}\n\\end{proposition}\n\n\\begin{proof}\n  \\begin{enumerate}\n  \\item This follows from\n    Theorem~\\ref{thm:characterization-linear-independence}, because\n    whether or not the equation\n    $a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k = \\vect{0}$ has a\n    non-trivial solution does not depend on the order in which the\n    vectors are written.\n  \\item If one of the vectors in the sequence\n    $\\vect{u}_1,\\ldots,\\vect{u}_j$ were redundant, then it would be\n    redundant in the longer sequence $\\vect{u}_1,\\ldots,\\vect{u}_k$ as\n    well.\n  \\item Let $A$ be the $n\\times k$-matrix that has the vectors\n    $\\vect{u}_1,\\ldots,\\vect{u}_k$ as its columns and suppose that\n    $k>n$. Then the rank of $A$ is at most $n$, so the {\\ef} of $A$\n    has some non-pivot columns. Therefore, the system\n    $a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k = \\vect{0}$ has\n    non-trivial solutions, and the vectors are linearly dependent by\n    Theorem~\\ref{thm:characterization-linear-independence}.\n  \\end{enumerate}\n\\end{proof}\n\n\\begin{example}{Linear dependence}{linear-dependence}\n  Are the following vectors linearly independent?\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n        1 \\\\\n        4\n      \\end{mymatrix},\\quad\n      \\begin{mymatrix}{r}\n        2 \\\\\n        3\n      \\end{mymatrix},\\quad\n      \\begin{mymatrix}{r}\n        3 \\\\\n        2\n      \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Since these are $3$ vectors in $\\R^2$, they are linearly dependent\n  by Proposition~\\ref{prop:properties-linear-independence}. No calculation\n  is necessary.\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{Linear independence and linear combinations}\n\nIn general, there is more than one way of writing a given vector as a\nlinear combination of some spanning vectors. For example, consider\n\\begin{equation*}\n  \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n  \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n  \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n  \\vect{v} = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 2 \\end{mymatrix}.\n\\end{equation*}\nWe can write $\\vect{v}$ in many different ways as a linear\ncombination of $\\vect{u}_1,\\ldots,\\vect{u}_3$, for example\n\\begin{equation*}\n  \\begin{array}{r@{~}c@{~}c}\n    \\vect{v} &=& -\\vect{u}_1 + 2\\vect{u}_3, \\\\\n    \\vect{v} &=& \\vect{u}_2 + \\vect{u}_3, \\\\\n    \\vect{v} &=& \\vect{u}_1 + 2\\vect{u}_2, \\\\\n    \\vect{v} &=& 2\\vect{u}_1 + 3\\vect{u}_2 - \\vect{u}_3. \\\\\n  \\end{array}\n\\end{equation*}\nHowever, when the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\nindependent, this does not happen. In this case, the linear\ncombination is always unique, as the following theorem shows.\n\n\\begin{theorem}{Unique linear combination}{unique-linear-combination}\n  Assume $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent. Then\n  every vector $\\vect{v}\\in\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$\n  can be written as a linear combination of\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ in a unique way.\n\\end{theorem}\n\n\\begin{proof}\n  We already know that every vector\n  $\\vect{v}\\in\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ can be written\n  as a linear combination of $\\vect{u}_1,\\ldots,\\vect{u}_k$, because\n  that is the definition of span. So what must be proved is the\n  uniqueness. Suppose, therefore, that there are two ways of writing\n  $\\vect{v}$ as such a linear combination, i.e., that\n  \\begin{equation*}\n    \\begin{array}{l}\n    \\vect{v} = a_1\\,\\vect{u}_1 + a_2\\,\\vect{u}_2 + \\ldots + a_k\\,\\vect{u}_k\\quad\\mbox{and} \\\\\n    \\vect{v} = b_1\\,\\vect{u}_1 + b_2\\,\\vect{u}_2 + \\ldots + b_k\\,\\vect{u}_k. \\\\\n    \\end{array}\n  \\end{equation*}\n  Subtracting one equation from the other, we get\n  \\begin{equation*}\n    \\vect{0} = (a_1-b_1)\\vect{u}_1 + (a_2-b_2)\\vect{u}_2 + \\ldots + (a_k-b_k)\\vect{u}_k.\n  \\end{equation*}\n  Since $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent, we\n  know by Theorem~\\ref{thm:characterization-linear-independence} that\n  the last equation only has the trivial solution, i.e., $a_1-b_1=0$,\n  $a_2-b_2=0$, \\ldots, $a_k-b_k=0$. It follows that $a_1=b_1$,\n  $a_2=b_2$, \\ldots, $a_k=b_k$. We have shown that any two ways of\n  writing $\\vect{v}$ as a linear combination of\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ are equal. Therefore, there is only\n  one way of doing so.\n\\end{proof}\n\n% ----------------------------------------------------------------------\n\\subsection{Removing redundant vectors}\n\nConsider the span of some vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$. As\nwe just saw in the previous subsection, the span is especially nice\nwhen the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\nindependent, because in that case, every element $\\vect{v}$ of the\nspan can be {\\em uniquely} written in the form\n$\\vect{v} = a_1\\,\\vect{u}_1 + \\ldots + a_k\\,\\vect{u}_k$.\n\nBut what if we have a span of some vectors\n$\\vect{u}_1,\\ldots,\\vect{u}_k$ that are not linearly independent? It\nturns out that we can always find some linearly independent vectors\nthat span the same set.  In fact, this can be done by simply removing\nthe redundant vectors from $\\vect{u}_1,\\ldots,\\vect{u}_k$. This is the\nsubject of the following theorem.\n\n\\begin{theorem}{Removing redundant vectors}{linearly-independent-subset}\n  \\index{redundant vector!removing}%\n  \\index{vector!redundant!removing}%\n  Let $\\vect{u}_1,\\ldots,\\vect{u}_k$ be a sequence of vectors, and\n  suppose that $\\vect{u}_{j_1},\\ldots,\\vect{u}_{j_\\ell}$ is the\n  subsequence of vectors that is obtained by removing all of the\n  redundant vectors. Then $\\vect{u}_{j_1},\\ldots,\\vect{u}_{j_\\ell}$\n  are linearly independent and\n  \\begin{equation*}\n    \\sspan\\set{\\vect{u}_{j_1},\\ldots,\\vect{u}_{j_\\ell}}\n    =\n    \\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}.\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n  Remove the redundant vectors one by one, from right to left. Each\n  time a redundant vector is removed, the span does not change; the\n  proof of this is similar to Example~\\ref{exa:redundant-span}.\n  Moreover, the resulting sequence of vectors\n  $\\sspan\\set{\\vect{u}_{j_1},\\ldots,\\vect{u}_{j_\\ell}}$ is linearly\n  independent, because if any of these vectors were a linear\n  combination of earlier ones, then it would have been redundant in\n  the original sequence of vectors, and would have therefore been removed.\n\\end{proof}\n\n\\begin{example}{Finding a linearly independent set of spanning vectors}{linearly-independent-subset}\n  Find a subset of $\\set{\\vect{u}_1,\\ldots,\\vect{u}_4}$ that is\n  linearly independent and has the same span as\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_4}$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ -2 \\\\ 3 \\end{mymatrix},\n    \\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -2 \\\\ 0 \\\\ 4 \\\\ -6 \\end{mymatrix},\n    \\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 2 \\\\ 1 \\end{mymatrix},\n    \\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 3 \\\\ 4 \\\\ 2 \\\\ 5 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We use the casting-out algorithm to find the redundant vectors:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr}\n      1  & -2 & 1 & 3 \\\\\n      0  &  0 & 2 & 4 \\\\\n      -2 &  4 & 2 & 2 \\\\\n      3  & -6 & 1 & 5 \\\\\n    \\end{mymatrix}\n    \\roweq\\ldots\\roweq\n    \\begin{mymatrix}{rrrr}\n      \\circled{1}  & -2 & 1 & 3 \\\\\n      0  &  0 & \\circled{2} & 4 \\\\\n      0  &  0 & 0 & 0 \\\\\n      0  &  0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the redundant vectors are $\\vect{u}_2$ and\n  $\\vect{u}_4$. We remove them (``cast them out'') and are left with\n  $\\vect{u}_1$ and $\\vect{u}_3$. Therefore, by\n  Theorem~\\ref{thm:linearly-independent-subset},\n  $\\set{\\vect{u}_1,\\vect{u}_3}$ is linearly independent and\n  $\\sspan\\set{\\vect{u}_1,\\vect{u}_3} =\n  \\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_4}$.\n\\end{solution}\n\n", "meta": {"hexsha": "77869459a4d55fcd4f7c2a21e54e8f2fb8133b71", "size": 27691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SpanIndependenceBasis-LinearIndependence.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/SpanIndependenceBasis-LinearIndependence.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/SpanIndependenceBasis-LinearIndependence.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 41.1456166419, "max_line_length": 100, "alphanum_fraction": 0.6547614748, "num_tokens": 9417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.6778631548765145}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\title{Hierarchic Shape Functions}\n\\author{Brian Granzow}\n\\date{Apr 14, 2015}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\n\nThis document serves to provide an overview of the hierarchic shape functions\nprovided in apf. Hierarchic shape functions are constructed in a manner so that\nthe basis $\\mathcal{B}^{p+1}$ for the polynomial space $P^{p+1}(\\Omega^e)$\nover an element $\\Omega^e$ is obtained by solely by the addition of new shape\nfunctions to the basis $\\mathcal{B}^p$ for the polynomial space\n$P^p(\\Omega^e)$. The hierarchic shape functions $N$ can be written in terms\nof kernel functions $\\phi_i$ and barycentric coordinates $A_i$ for elements.\n\n\\section{Legendre polynomials}\n\nLegendre polynomials are typically derived over the interval $[-1,1]$. The\nLegendre polynomials presented here are derived over the interval $[0,1]$\nas it suits the parametric space for our reference tetrahedron and triangle,\nas described later. These are commonly referred to as shifted Legendre\npolynomials, which can be obtained by using the substitution $x \\to 2x - 1$ for\nstandard Legendre polynomials. The first two shifted Legendre polynomials are\ndefined as: $L_0 = 1$ and $L_1 = 2x - 1$. The shifted Legendre polynomials\nsatisfy the recursion relation:\n\\[\n\\left\\{ \\frac{2i-1}{i} (2x-1)\\right \\} L_{i-1}(x) -\n\\left\\{ \\frac{i-1}{i} \\right \\} L_{i-2}(x) \\quad i \\geq 2\n\\]\nThe first few Legendre polynomials are listed below\n\\begin{align*}\nL_0(x) &= 1 \\\\\nL_1(x) &= 2x - 1 \\\\\nL_2(x) &= 6x^2 - 6x + 1 \\\\\nL_3(x) &= 20x^3 - 30x^2 + 12x - 1 \\\\\nL_4(x) & = 70x^4 - 140x^3 + 90x^2 - 20x + 1\n\\end{align*}\nThe Legendre polynomials are orthogonal on $[0,1]$\n\\[\n\\int _0 ^1 L_i(x) L_j(x) \\; \\text{d}x \\; =\n\\begin{cases}\n0 &\\quad i \\neq j \\\\\n1/(2i+1) &\\quad i = j\n\\end{cases}\n\\]\n\n\\section{Lobatto functions}\n\nThe Lobatto functions on $[0,1]$ are integrated Legendre polynomials, and\nare defined as\n\\begin{align*}\nl_0(x) &= 1-x \\\\\nl_1(x) &= x \\\\\nl_i(x) & = \\frac{1}{ \\| L_{i-1} \\|_2}\n\\int _0 ^x L_{i-1}(t) \\; \\text{d}t \\quad i \\geq 2\n\\end{align*}\nFrom the orthogonal property of the Legendre polynomials, it is clear that\n\\[\n\\frac{1}{ \\| L_{i-1} \\|_2} = \\sqrt{2i - 1}\n\\]\nThe first few Lobatto functions are listed below\n\\begin{align*}\nl_0(x) &= 1-x \\\\\nl_1(x) &= x \\\\\nl_2(x) &= \\sqrt{3} (x^2 - x) \\\\\nl_3(x) &= \\sqrt{5} (2x^3 - 3x^2 + x) \\\\\nl_4(x) &= \\sqrt{7} (5x^4 - 10x^3 + 6x^2 - x)\n\\end{align*}\n\n\\section{Kernel functions}\n\nTo define shape functions, it will be useful to define kernel functions\n$\\phi_i$ by decomposing the Lobatto functions as follows:\n\\[\nl_i(x) = l_0(x) l_1(x) \\phi_{i-2}(x) \\quad i \\geq 2\n\\]\nThe first few kernel functions are listed below\n\\begin{align*}\n\\phi_0(x) &= -\\sqrt{3} \\\\\n\\phi_1(x) &= -\\sqrt{5} (2x - 1) \\\\\n\\phi_2(x) &= -\\sqrt{7} (5x^2 - 5x + 1)\n\\end{align*}\n\n\\section{Reference Triangle}\nWe define our reference triangle $\\Omega^e_t$ in a parametric space such that\n\\[\n\\Omega^e_t = \\left\\{ \\xi \\in \\mathbb{R}^3 \\; : \\;\n0 < \\xi_1, \\xi_2 < 1; \\; \\xi_1 + \\xi_2 < 1 \\right\\}\n\\]\nThe barycentric coordinates for the reference triangle can be defined in\nterms of the $\\xi$ coordinates as\n\\begin{align*}\nA_1 &= 1 - \\xi_1 - \\xi_2 \\\\\nA_2 &= \\xi_1 \\\\\nA_3 &= \\xi_2\n\\end{align*}\nThere are 3 vertices associated with our parent triangle. These can be\nexpressed in parametric space as\n\\begin{align*}\nv_1(\\xi) &= (0,0) \\\\\nv_2(\\xi) &= (1,0) \\\\\nv_3(\\xi) &= (0,1)\n\\end{align*}\nThey can similarly be expressed in barycentric coordinates as\n\\begin{align*}\nv_1(A) &= (1,0,0) \\\\\nv_2(A) &= (0,1,0) \\\\\nv_3(A) &= (0,0,1)\n\\end{align*}\n\n\\subsection{Vertex shape functions}\n\nThere are always only 3 shape functions associated with triangular vertices, \n$v_1, v_2$, and $v_3$.\nThese are\n\\begin{align*}\nN^{v_1}(A) &= A_1 \\\\\nN^{v_2}(A) &= A_2 \\\\\nN^{v_3}(A) &= A_3\n\\end{align*}\nThese by themselves would coincide exactly with linear Lagrange shape\nfunctions and are of polynomial order $p=1$.\n\n\\subsection{Edge shape functions}\nEdge shape functions will be defined in terms of the shape functions\nassociated with the two vertices $v_i,$ and $v_j$ that bound the edge and the\nkernel functions defined previously. Edge shape functions of polyonmial order\n$p$ are defined by\n\\[\nN^{e_{ij}}_p = N^{v_i} N^{v_j} \\phi_{p-2}(N^{v_j} - N^{v_i})\n\\quad p \\geq 2\n\\]\n\n\\section{Reference Tetrahedron}\n\nWe define our reference tetrahedron $\\Omega^e_T$ in a parametric space\nsuch that\n\\[\n\\Omega^e_T = \\left\\{ \\xi \\in \\mathbb{R}^3 \\; : \\;\n0 < \\xi_1, \\xi_2, \\xi_3 < 1; \\; \\xi_1 + \\xi_1 + \\xi_3 < 1 \\right\\}\n\\]\nThe barycentric coordinates for the reference tetrahedron can be defined in\nterms of the $\\xi$ coordinates as\n\\begin{align*}\nA_1 &= 1 - \\xi_1 - \\xi_2 - \\xi_3 \\\\\nA_2 &= \\xi_1 \\\\\nA_3 &= \\xi_2 \\\\\nA_4 &= \\xi_3 \\\\\n\\end{align*}\nThere are 4 vertices associated with our parent tetrahedron. These can be\nexpressed in parametric space as\n\\begin{align*}\nv_1(\\xi) &= (0,0,0) \\\\\nv_2(\\xi) &= (1,0,0) \\\\\nv_3(\\xi) &= (0,1,0) \\\\\nv_4(\\xi) &= (0,0,1)\n\\end{align*}\nThey can similarly be expressed in barycentric coordinates as\n\\begin{align*}\nv_1(A) &= (1,0,0,0) \\\\\nv_2(A) &= (0,1,0,0) \\\\\nv_3(A) &= (0,0,1,0) \\\\\nv_4(A) &= (0,0,0,1)\n\\end{align*}\n\n\\subsection{Vertex shape functions}\n\nThere are always only 4 shape functions associated with tetrahedral vertices, \n$v_1, v_2$, $v_3$, and $v_4$.\nThese are\n\\begin{align*}\nN^{v_1}(A) &= A_1 \\\\\nN^{v_2}(A) &= A_2 \\\\\nN^{v_3}(A) &= A_3 \\\\\nN^{v_4}(A) &= A_4\n\\end{align*}\nThese by themselves would coincide exactly with linear Lagrange shape\nfunctions and are of polynomial order $p=1$.\n\n\\subsection{Edge shape functions}\nEdge shape functions will be defined in terms of the shape functions\nassociated with the two vertices $v_i,$ and $v_j$ that bound the edge and the\nkernel functions defined previously. Edge shape functions of polyonmial order\n$p$ are defined by\n\\[\nN^{e_{ij}}_p = N^{v_i} N^{v_j} \\phi_{p-2}(N^{v_j} - N^{v_i})\n\\quad p \\geq 2\n\\]\n\n\\section{Future work}\nCurrently only linear and quadratic hierarchic shape functions are\nimplemented for tetrahedra. This document will be updated to explain face\nand region bubble modes when they are implemented for various element types.\n\n\\end{document}\n", "meta": {"hexsha": "8a92fad6b524508db6f6b900d07e264a6029c6af", "size": 6164, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "apf/hierarchic.tex", "max_stars_repo_name": "cwsmith/core", "max_stars_repo_head_hexsha": "840fbf6ec49a63aeaa3945f11ddb224f6055ac9f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 138, "max_stars_repo_stars_event_min_datetime": "2015-01-05T15:50:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T01:09:58.000Z", "max_issues_repo_path": "apf/hierarchic.tex", "max_issues_repo_name": "cwsmith/core", "max_issues_repo_head_hexsha": "840fbf6ec49a63aeaa3945f11ddb224f6055ac9f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 337, "max_issues_repo_issues_event_min_datetime": "2015-08-07T18:24:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:39:03.000Z", "max_forks_repo_path": "apf/hierarchic.tex", "max_forks_repo_name": "cwsmith/core", "max_forks_repo_head_hexsha": "840fbf6ec49a63aeaa3945f11ddb224f6055ac9f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-01-17T00:58:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-13T04:58:20.000Z", "avg_line_length": 30.6666666667, "max_line_length": 79, "alphanum_fraction": 0.6792667099, "num_tokens": 2264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.6778631395013988}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\n\\title{Root finding}\n\\begin{document}\n  \\pagenumbering{gobble}\n  \\maketitle\n  \\newpage\n  \\pagenumbering{arabic}\n\n\n\\section*{Relaxation method}\n\nWe are trying to figure out the solutions to the equation:\n\n$$x=f(x)$$\n\nwhere f(x) is a nonlinear function.\n\nWe call the solutions $x_0$\n\nIterations i:\n\n$$x_i = f(x_{i-1}) $$\n$$= f(x_0) + (x_{i-1}-x_0)f'(x_0) + ...$$\n\nIn each iteration $f(x_0) = x_0$\n\n$$x_i - x_0 = (x_{i-1}-x_0)f'(x_0) + ... $$\n\n$$\\Delta x_i \\approx \\Delta x_{i-1} f'(x_0)$$\n\nDoes $\\Delta x_i $ shrink?\n\nYes, only if $|f'(x_0)| < 1$\n\n\\section*{Example}\n\n$$x = f(x) = 1 - e^{-2x}$$\n$$f'(x) = -2e^{-2x}$$\n\nOK:\n$$f'(0.797) = -0.406$$\n\nNOT OK:\n$$f'(0) = -2$$\n\n\\end{document}", "meta": {"hexsha": "70d0eec73589deb8aac3efdb4a9447e73514010b", "size": 729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/root_finding.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/root_finding.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/root_finding.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": 15.1875, "max_line_length": 58, "alphanum_fraction": 0.5912208505, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790619, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.6778154975429406}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\begin{document}\n\\section*{separable}\n\\begin{align*}\ng(y)\\,\\mathrm{d}y&=f(t)\\,\\mathrm{d}t & g(y)y'&=f(t)\\\\\n\\int{g(y)\\,\\mathrm{d}y}&=\\int{f(t)\\,\\mathrm{d}t}\n\\end{align*}\n\\section*{first order linear}\n\\begin{align*}\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}+p(t)y&=q(t) & \\mu(t)&=e^{\\int{p(t)\\,\\mathrm{d}t}}\\\\\n\\frac{\\mathrm{d}}{\\mathrm{d}t}\\left(\\mu(t)y\\right)&=\\mu(t)\\frac{\\mathrm{d}y}{\\mathrm{d}t}+p(t)\\mu(t)y & \\mu(t)y&=\\int{\\mu(t)q(t)\\,\\mathrm{d}t}\n\\end{align*}\n\\section*{exact}\n\\begin{align*}\nM(t,y)\\,\\mathrm{d}t+N(t,y)\\,\\mathrm{d}y&=0 & \\frac{\\partial M}{\\partial y}&=\\frac{\\partial N}{\\partial y}\\\\\n\\int{M(t,y)\\,\\mathrm{d}t}+\\phi(y)&=f(t,y) & \\phi'(y)&=N(x,y)-\\frac{\\mathrm{d}}{\\mathrm{d}y}\\left(\\int{M(t,y)\\,\\mathrm{d}t}\\right)\\\\\n\\int{M(t,y)\\,\\mathrm{d}t}+\\int{\\phi'(y)\\,\\mathrm{d}y}&=f(t,y)\n\\end{align*}\nSolution is $f(t,y)=C$\n\\section*{bernoulli}\n\\begin{align*}\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}+p(t)y&=q(t)y^n & w&=y^{1-n)}\\\\\n\\frac{\\mathrm{d}w}{\\mathrm{d}t}+(1-n)p(t)w&=(1-n)q(t)\n\\end{align*}\nSolve as first order linear, then back substitute\n\\section*{homogeneous}\n\\begin{align*}\nM(t,y)\\,\\mathrm{d}t+N(t,y)\\,\\mathrm{d}y&=0 & M(xt,xy)+N(xt,xy)&=x^n\\left(M(t,y)+N(t,y)\\right)\\\\\n\\end{align*}\nsubstitute with $y=wt$ if $N(t,y)$ is simpler and $t=wy$ if $M(t,y)$ is simpler\n\\begin{align*}\n\\mathrm{d}y&=w\\,\\mathrm{d}t+t\\,\\mathrm{d}w &\\mathrm{d}t&=w\\,\\mathrm{d}y+y\\,\\mathrm{d}w\n\\end{align*}\nSolve as a separable equation\n\\end{document}\n", "meta": {"hexsha": "94bc5e1f11ac7e11e5507ead8478322d53f799f2", "size": 1516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential equations/diffeq-cheat-2013-09-18.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-cheat-2013-09-18.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-cheat-2013-09-18.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": 38.8717948718, "max_line_length": 142, "alphanum_fraction": 0.6081794195, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6778154889294165}}
{"text": "% ----------------------------------------------------------------------\n\\section{Basis and dimension}\n\\label{sec:basis-and-dimension}\n\n\\begin{outcome}\n  \\begin{enumerate}\\setlength\\itemsep{0em}\n  \\item Find a basis for a subspace of $\\R^n$.\n  \\item Use the casting-out algorithm to find a basis for a subspace\n    given as a span.\n  \\item Use basic solutions to find a basis for a subspace given as\n    the solution space of a homogeneous system of equations.\n  \\item Find the coordinates of a vector with respect to a basis.\n  \\item Find the dimension of a subspace of $\\R^n$.\n  \\item Extend a set of linearly independent vectors to a basis.\n  \\item Shrink a spanning set to a basis by removing redundant vectors.\n  \\item Determine whether $k$ vectors form a basis of a $k$-dimensional\n    space.\n  \\end{enumerate}\n\\end{outcome}\n\n% ----------------------------------------------------------------------\n\\subsection{Definition of basis}\n\nWe saw in Proposition~\\ref{prop:span-subspace} that spans are\nsubspaces of\\/ $\\R^n$. Interestingly, the converse is also true: every\nsubspace of\\/ $\\R^n$ is the span of some finite set of vectors.\n\n\\begin{theorem}{Subspaces are spans}{subspaces-are-spans}\n  \\index{subspace!is a span}%\n  Let $V$ be a subspace of\\/ $\\R^n$. Then there exist linearly\n  independent vectors $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ in $V$\n  such that\n  \\begin{equation*}\n    V= \\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}.\n  \\end{equation*}\n  \\vspace{-3ex}\n\\end{theorem}\n\n\\begin{proof}\n  We proceed as follows.\n  \\begin{enumerate}\n  \\item[0.] If $V=\\set{\\vect{0}}$, then $V$ is the empty span, and we\n    are done.\n  \\item[1.] Otherwise, $V$ contains some non-zero vector.  Pick a\n    non-zero vector $\\vect{u}_1$ in $V$. If\n    $V=\\sspan\\set{\\vect{u}_1}$, we are done.\n  \\item[2.] Otherwise, pick a vector $\\vect{u}_2$ in $V$ that is not\n    in $\\sspan\\set{\\vect{u}_1}$. If\n    $V=\\sspan\\set{\\vect{u}_1,\\vect{u}_2}$, we are done.\n  \\item[3.] Otherwise, pick a vector $\\vect{u}_3$ in $V$ that is not\n    in $\\sspan\\set{\\vect{u}_1,\\vect{u}_2}$. If\n    $V=\\sspan\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$, we are done.\n  \\item[4.] Otherwise, pick a vector $\\vect{u}_4$ in $V$ that is not\n    in $\\sspan\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_4}$, and so on.\n  \\end{enumerate}\n  Continue in this way. Note that after the $j\\th$ step of this\n  process, the vectors $\\vect{u}_1,\\ldots,\\vect{u}_j$ are linearly\n  independent. This is because, by construction, no vector is in the\n  span of the previous vectors, and therefore no vector is redundant.\n  By\n  Proposition~\\ref{prop:properties-linear-independence}(\\ref{properties-linear-independence-c}),\n  there can be at most $n$ linearly independent vectors in $\\R^n$.\n  Therefore the process must stop after $k$ steps for some $k\\leq\n  n$. But then $V=\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$, as\n  desired.\n\\end{proof}\n\nIn summary, every subspace of\\/ $\\R^n$ is spanned by a finite,\nlinearly independent collection of vectors.  Such a collection of\nvectors is called a \\textbf{basis} of the subspace.\n\n\\begin{definition}{Basis of a subspace}{subspace-basis}\n  Let $V$ be a subspace of\\/ $\\R^n$. Then\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is a \\textbf{basis} for\n  $V$ if the following two conditions hold:%\n  \\index{basis}%\n  \\index{subspace!basis|see{basis}}%\n  \\index{vector!basis|see{basis}}%\n  \\begin{enumerate}\n  \\item $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}=V$, and\n  \\item $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent.\n  \\end{enumerate}\n\\end{definition}\n\nNote that the plural of basis is \\textbf{bases}.\n\n% ----------------------------------------------------------------------\n\\subsection{Examples of bases}\n\n\\begin{proposition}{Standard basis of\\/ $\\R^n$}{standard-basis}\n  Let $\\vect{e}_i$ be the vector in $\\R^n$ whose $i\\th$ component is $1$\n  and all of whose other components are $0$. In other words, $\\vect{e}_i$\n  is the $i\\th$ column of the identity matrix.\n  \\begin{equation*}\n    \\vect{e}_1 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\\\ \\vdots \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{e}_2 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\\\ \\vdots \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{e}_3 = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ \\vdots \\\\ 0 \\end{mymatrix},\\quad\n    \\ldots~,\\quad\n    \\vect{e}_n = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ \\vdots \\\\ 1\\end{mymatrix}.\n  \\end{equation*}\n  Then $\\set{\\vect{e}_1,\\vect{e}_2,\\ldots,\\vect{e}_n}$ is a basis for\n  $\\R^n$. It is called the \\textbf{standard basis}%\n  \\index{standard basis}%\n  \\index{basis!standard}\n  of\\/ $\\R^n$.\n\\end{proposition}\n\n\\begin{proof}\n  To see that it is a basis of\\/ $\\R^n$, first notice that the vectors\n  $\\vect{e}_1,\\vect{e}_2,\\ldots,\\vect{e}_n$ span $\\R^n$. Indeed, every\n  vector $\\vect{v} = \\mat{x_1,\\ldots,x_n}^T\\in\\R^n$ can be written as\n  $\\vect{v} = x_1\\vect{e}_1+\\ldots+x_n\\vect{e}_n$. Second, the vectors\n  $\\vect{e}_1,\\vect{e}_2,\\ldots,\\vect{e}_n$ are evidently linearly\n  independent, because none of these vectors can be written as a\n  linear combination of previous vectors. Since the vectors span\n  $\\R^n$ and are linearly independent, they form a basis of\\/ $\\R^n$.\n\\end{proof}\n\n\\begin{example}{A non-standard basis of\\/ $\\R^3$}{non-standard-basis}\n  \\index{basis!of Rn@of\\/ $\\R^n$}%\n  Check that the vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n  \\end{equation*}\n  form a basis of\\/ $\\R^3$.\n\\end{example}\n\n\\begin{solution}\n  We must check that the vectors $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$\n  are linearly independent and span $\\R^3$. To check linear\n  independence, we use the casting-out algorithm.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 0 & -1 \\\\\n      2 & 1 & 0 \\\\\n      1 & 0 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr}\n      \\circled{1} & 0 & -1 \\\\\n      0 & \\circled{1} & 2 \\\\\n      0 & 0 & \\circled{2} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since all columns are pivot columns, there are no redundant vectors,\n  so $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$ are linearly independent.\n  To check that they span all of\\/ $\\R^3$, let $\\vect{w}=\\mat{x,y,z}^T$\n  be an arbitrary element of\\/ $\\R^3$. We must show that $\\vect{w}$ is a linear\n  combination of $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$. This amounts to\n  solving the system of equations\n  \\begin{equation*}\n    a_1\\,\\vect{u}_1+a_2\\,\\vect{u}_2+a_3\\,\\vect{u}_3 = \\vect{w},\n  \\end{equation*}\n  or in augmented matrix form,\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|c}\n      1 & 0 & -1 & x \\\\\n      2 & 1 & 0  & y \\\\\n      1 & 0 & 1  & z \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr|c}\n      1 & 0 & -1 & x    \\\\\n      0 & 1 & 2  & y-2x \\\\\n      0 & 0 & 2  & z-x  \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The system is clearly consistent, so it has a solution, and\n  therefore $\\vect{w}$ is indeed a linear combination of\n  $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$. Since $\\vect{w}$ was an\n  arbitrary vector of\\/ $\\R^3$, it follows that\n  $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$ span $\\R^3$.\n\\end{solution}\n\nGeneralizing the last example, we find that a set of $n$ vectors forms\na basis of\\/ $\\R^n$ if and only if the matrix having those vectors as\nits columns is invertible. This is the content of the following\nproposition.\n\n\\begin{proposition}{Invertible matrices and bases of\\/ $\\R^n$}{invertible-matrices}\n  \\index{basis!of Rn@of\\/ $\\R^n$}%\n  \\index{basis!and invertible matrix}%\n  Let $A$ be an $n\\times n$-matrix. Then the columns of $A$ form a\n  basis of\\/ $\\R^n$ if and only if $A$ is invertible.\n\\end{proposition}\n\nWe turn to the question of finding bases for subspaces of\\/ $\\R^n$.\n\n\\begin{example}{Basis of a span}{basis-of-span}\n  Let\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 2 \\\\ 0 \\\\ -2 \\end{mymatrix},\n    \\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n    \\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 5 \\end{mymatrix},\n    \\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 3 \\\\ 5 \\\\ 7 \\end{mymatrix},\n    \\quad\n    \\vect{u}_5 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  Find a basis of $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_5}$%\n  \\index{basis!of a span}.\n\\end{example}\n\n\\begin{solution}\n  Let $S=\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_5}$.  By\n  Theorem~\\ref{thm:linearly-independent-subset}, we know that if we\n  remove the redundant vectors from\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_5}$, then the remaining vectors\n  will be linearly independent and will still span $S$. In other\n  words, the remaining vectors will be a basis for $S$. We use the\n  casting-out algorithm to identity the redundant vectors:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrr}\n      2 & -1 & 1 & 3 & -1 \\\\\n      0 & 0 & 3 & 5 & 1 \\\\\n      -2 & 1 & 5 & 7 & 3 \\\\\n    \\end{mymatrix}\n    ~\\roweq~\n    \\begin{mymatrix}{rrrrr}\n      2 & -1 & 1 & 3 & -1 \\\\\n      0 & 0 & 3 & 5 & 1 \\\\\n      0 & 0 & 6 & 10 & 2 \\\\\n    \\end{mymatrix}\n    ~\\roweq~\n    \\begin{mymatrix}{rrrrr}\n      \\circled{2} & -1 & 1 & 3 & -1 \\\\\n      0 & 0 & \\circled{3} & 5 & 1 \\\\\n      0 & 0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since columns $2$, $4$, and $5$ are the non-pivot columns, it\n  follows that the vectors $\\vect{u}_2$, $\\vect{u}_4$, and\n  $\\vect{u}_5$ are redundant. Therefore, the desired basis is\n  $\\set{\\vect{u}_1,\\vect{u}_3}$.\n\\end{solution}\n\n\\begin{example}{Basis of the solution space of a homogeneous system of equations}{basis-solution-space}\n  Find a basis for the solution space of the system of equations%\n  \\index{basis!of a solution space}\n  \\begin{equation*}\n    \\begin{array}{r@{~}r@{~}r@{~}r@{~}r@{~}r@{~}r@{~}r@{~}r@{~}r@{~}r}\n     x &+& y  &-& z &+& 3w &-& 2v &=& 0, \\\\\n     x &+& y &+& z &-& 11w &+& 8v &=& 0, \\\\\n    4x &+& 4y &-& 3z &+& 5w &-& 3v &=& 0. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We solve the system of equations in the usual way:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrr|r}\n      1 & 1 & -1 & 3 & -2 & 0 \\\\\n      1 & 1 &  1 & -11 & 8 & 0 \\\\\n      4 & 4 & -3 & 5 & -3 & 0 \\\\\n    \\end{mymatrix}\n    ~\\roweq~\n    \\begin{mymatrix}{rrrrr|r}\n      1 & 1 & -1 & 3 & -2 & 0 \\\\\n      0 & 0 & 2 & -14 & 10 & 0 \\\\\n      0 & 0 & 1 & -7 & 5 & 0 \\\\\n    \\end{mymatrix}\n    ~\\roweq~\n    \\begin{mymatrix}{rrrrr|r}\n      \\circled{1} & 1 & 0 & -4 & 3 & 0 \\\\\n      0 & 0 & \\circled{1} & -7 & 5 & 0 \\\\\n      0 & 0 & 0 &  0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  From the {\\rref}, we see that $y$, $w$, and $v$ are free\n  variables. The general solution is:\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\\\ w \\\\ v \\end{mymatrix}\n    \\quad=\\quad\n    t \\begin{mymatrix}{r} -3 \\\\ 0 \\\\ -5 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    ~+~ s \\begin{mymatrix}{r} 4 \\\\ 0 \\\\ 7 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    ~+~ r \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  Thus, the solution space is spanned by the vectors\n  \\begin{equation*}\n    \\set{\\begin{mymatrix}{r} -3 \\\\ 0 \\\\ -5 \\\\ 0 \\\\ 1 \\end{mymatrix},\n    \\begin{mymatrix}{r} 4 \\\\ 0 \\\\ 7 \\\\ 1 \\\\ 0 \\end{mymatrix},\n    \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Moreover, these vectors are evidently linearly independent, because\n  each vector contains a $1$ in a position where all the previous\n  vectors have $0$ (and therefore, none of the vectors can be written\n  as a linear combination of previous vectors). It follows that the\n  above three vectors form a basis of the solution space.\n\\end{solution}\n\nNote that the basis vectors of the solution space are exactly what we\ncalled the \\textbf{basic solutions}%\n\\index{basic solution}%\n\\index{solution!basic}%\n\\index{solution!basis of}\nin Section~\\ref{sec:homogeneous-systems}.\n\n% ----------------------------------------------------------------------\n\\subsection{Bases and coordinate systems}\n\\label{ssec:bases-and-coordinates}\n\nLet $V$ be a subspace of\\/ $\\R^n$. A basis of $V$ is essentially the\nsame thing as a coordinate system for $V$. To see why, let\n$B=\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ be some basis of $V$. This\nmeans that the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\nindependent and span $V$. Because the basis vectors are spanning,\nevery vector $\\vect{v}\\in V$ can be written as a linear combination of\nbasis vectors\n\\begin{equation*}\n  \\vect{v} = a_1\\,\\vect{u}_1 + \\ldots + a_k\\,\\vect{u}_k.\n\\end{equation*}\nMoreover, because the basis vectors are linearly independent, it\nfollows by Theorem~\\ref{thm:unique-linear-combination} that the\ncoefficients $a_1,\\ldots,a_k$ are unique. We say that $a_1,\\ldots,a_k$\nare the \\textbf{coordinates of $\\vect{v}$ with respect to the basis\n$B$}%\n\\index{coordinate!with respect to basis}%\n\\index{coordinate system!and basis}, and we write\n\\begin{equation*}\n  \\coord{\\vect{v}}_B = \\begin{mymatrix}{c} a_1 \\\\ a_2 \\\\ a_3 \\end{mymatrix}.\n\\end{equation*}\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.8]\n    \\begin{scope}[scale=2.5,x={(1.2cm,-0.2cm)},y={(0.5cm,0.4cm)},z={(0cm,0.8cm)}]\n      \\draw(-2.5,0,0) -- (2.5,0,0);\n      \\draw(0,-2.3,0) -- (0,2.3,0);\n      \\draw(0,0,-1.3) -- (0,0,1.3);\n      \\draw[->, thick, blue](0,0,0) -- node[below] {$\\vect{u}_1$} +(1,0,0);\n      \\draw[->, thick, blue](0,0,0) -- node[above left=-1ex] {$\\vect{u}_2$} +(0,1,0);\n      \\draw[->, thick, blue](0,0,0) -- node[left] {$\\vect{u}_3$} +(0,0,1);\n      \\draw(-2,0,0) -- +(0,0,-0.1) node[below] {$-2$};\n      \\draw(-1,0,0) -- +(0,0,-0.1) node[below] {$-1$};\n      \\draw(0,0,0) -- +(0,0,-0.1) node[below] {$0$};\n      \\draw(1,0,0) -- +(0,0,-0.1) node[below] {$1$};\n      \\draw(2,0,0) -- +(0,0,-0.1) node[below] {$2$};\n      \\draw(0,-2,0) -- +(0,0,-0.1) node[below] {$-2$};\n      \\draw(0,-1,0) -- +(0,0,-0.1) node[below] {$-1$};\n      \\draw(0,1,0) -- +(0,0,-0.1) node[below] {$1$};\n      \\draw(0,2,0) -- +(0,0,-0.1) node[below] {$2$};\n      \\draw(0,0,-1) -- +(-0.1,0,0) node[left] {$-1$};\n      \\draw(0,0,1) -- +(-0.1,0,0) node[left] {$1$};\n    \\end{scope}\n    \\path(0,-3.2) node {Basis as coordinate system};\n  \\end{tikzpicture}\n\\end{center}\n\n\\begin{example}{Find a vector from its coordinates in a basis}{vector-from-coordinates}\n  Find the vector $\\vect{v}$ that has coordinates\n  \\begin{equation*}\n    \\coord{\\vect{v}}_B = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  with respect to the basis $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$\n  of\\/ $\\R^3$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1\\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  This simply means that $\\vect{v} = 1\\vect{u}_1 - 1\\vect{u}_2 +\n  2\\vect{u}_3$. We calculate\n  \\begin{equation*}\n    \\vect{v} =\n    1\\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\n    - 1\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + 2\\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 3  \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nIn case the basis is the standard basis, the coordinates are just the\nusual ones, as the following example illustrates:\n\n\\begin{example}{Find a vector from its coordinates in the standard basis}{vector-from-coordinates-standard}\n  Find the vector $\\vect{v}$ that has coordinates\n  \\begin{equation*}\n    \\coord{\\vect{v}}_B = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix},\n  \\end{equation*}\n  where $B$ is the standard basis of\\/ $\\R^3$.\n\\end{example}\n\n\\begin{solution}\n  The standard basis is\n  \\begin{equation*}\n    \\vect{e}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{e}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{e}_3 = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1\\end{mymatrix}.\n  \\end{equation*}\n  We have to calculate\n  \\begin{equation*}\n    \\vect{v} = 1\\vect{e}_1 - 1\\vect{e}_2 + 2\\vect{e}_3\n    = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2  \\end{mymatrix}.\n  \\end{equation*}\n  We see that the coordinates of any vector with respect to the\n  standard basis are just the usual components of the vector.\n\\end{solution}\n\nWe can also ask to find the coordinates of a given vector in a given\nbasis.\n\n\\begin{example}{Find the coordinates of a vector with respect to a basis}{coordinates-from-vector}\n  Find the coordinates of the vector\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}\n  \\end{equation*}\n  with respect to the basis $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$\n  of\\/ $\\R^3$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1\\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  To find the coordinates, we must solve the system of equations\n  $\\vect{v} = a_1\\,\\vect{u}_1+a_2\\,\\vect{u}_2+a_3\\,\\vect{u}_3$. We\n  solve:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & -1 & 1 \\\\\n      2 & 1 & 0 & 2 \\\\\n      1 & 0 & 1 & 3 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & -1 & 1 \\\\\n      0 & 1 & 2 & 0 \\\\\n      0 & 0 & 2 & 2 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & 0 & 2 \\\\\n      0 & 1 & 0 & -2 \\\\\n      0 & 0 & 1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the unique solution is $(a_1,a_2,a_3) = (2,-2,1)$. The\n  coordinates of $\\vect{v}$ with respect to the basis $B$ are\n  \\begin{equation*}\n    \\coord{\\vect{v}}_B\n    = \\begin{mymatrix}{r} a_1 \\\\ a_2 \\\\ a_3 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 2 \\\\ -2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{Dimension}\n\nOne of the most important properties of bases is that any two bases\nfor the same space must be of the same size. To show this, we will\nneed the the following fundamental result, called the Exchange\nLemma. This lemma states that spanning sets have at least as many\nvectors as linearly independent sets.\n\n\\begin{lemma}{Exchange Lemma}{exchange-lemma}\n  \\index{exchange lemma!in Rn@in $\\R^n$}%\n  Suppose $\\vect{u}_1,\\ldots,\\vect{u}_r$ are linearly independent\n  elements of $\\sspan\\set{\\vect{v}_1,\\ldots,\\vect{v}_s}$. Then\n  $r\\leq s$.\n\\end{lemma}\n\n\\begin{proof}\n  Since each $\\vect{u}_j$ is an element of\n  $\\sspan\\set{\\vect{v}_1,\\ldots,\\vect{v}_s}$, there exist\n  scalars $a_{ij}$ such that\n  \\begin{equation*}\n    \\vect{u}_j = a_{1j}\\,\\vect{v}_1 + \\ldots + a_{sj}\\,\\vect{v}_s.\n  \\end{equation*}\n  Let $A = \\mat{a_{ij}}$. Note that this matrix has $s$ rows and $r$\n  columns, i.e., it is an $s\\times r$-matrix. Now suppose, for the\n  sake of obtaining a contradiction, that $r>s$. Then by\n  Theorem~\\ref{thm:rank-homogeneous-solutions}, the system\n  $A\\vect{x}=\\vect{0}$ has a non-trivial solution $\\vect{x}$, i.e.,\n  there exists $\\vect{x}\\neq\\vect{0}$ such that $A\\vect{x}=\\vect{0}$.\n  In other words, for all $i=1,\\ldots,s$,\n  \\begin{equation*}\n    a_{i1}x_1 + \\ldots + a_{ir}x_r = 0.\n  \\end{equation*}\n  Therefore,\n  \\begin{eqnarray*}\n    x_1\\,\\vect{u}_1 + \\ldots + x_r\\,\\vect{u}_r\n    &=&\n        x_1(a_{11}\\,\\vect{v}_1 + \\ldots + a_{s1}\\,\\vect{v}_s)\n        + \\ldots\n        + x_r(a_{1r}\\,\\vect{v}_1 + \\ldots + a_{sr}\\,\\vect{v}_s)\n    \\\\\n    &=&\n        (a_{11}x_1 + \\ldots + a_{1r}x_r)\\vect{v}_1\n        + \\ldots\n        + (a_{s1}x_1 + \\ldots + a_{sr}x_r)\\vect{v}_s\n    \\\\\n    &=& 0\\,\\vect{v}_1 + \\ldots + 0\\,\\vect{v}_s\n    \\\\\n    &=& 0.\n  \\end{eqnarray*}\n  This contradicts the assumption that\n  $\\vect{u}_1,\\ldots,\\vect{u}_r$ are linearly independent. Since\n  we assumed $r>s$ and obtained a contradiction, it follows that\n  $r\\leq s$, as desired.\n\\end{proof}\n\nArmed with the Exchange Lemma, we are now ready to show that any two\nbases of a space are of the same size.\n\n\\begin{theorem}{Bases are of the same size}{bases-same-size}\n  \\index{basis!size of}%\n  Let $V$ be a subspace of\\/ $\\R^n$, and let $B_1$ and $B_2$ be\n  bases of $V$. Suppose $B_1$ contains $s$ vectors and $B_2$ contains\n  $r$ vectors. Then $s=r$.\n\\end{theorem}\n\n\\begin{proof}\n  This follows right away from the Exchange Lemma. Indeed, observe\n  that $B_1 = \\set{\\vect{u}_1,\\ldots,\\vect{u}_s}$ is a spanning\n  set for $V$ while $B_2 = \\set{\\vect{v}_1,\\ldots,\\vect{v}_r}$ is\n  linearly independent, so $s\\geq r$. Similarly\n  $B_2 = \\set{\\vect{v}_1,\\ldots,\\vect{v}_r}$ is a spanning set\n  for $V$ while $B_1 = \\set{\\vect{u}_1,\\ldots, \\vect{u}_s}$ is\n  linearly independent, so $r\\geq s$.\n\\end{proof}\n\nBecause every basis of $V$ has the same number of vectors, we give\nthis number a special name. It is called the \\textbf{dimension} of\n$V$.\n\n\\begin{definition}{Dimension of a subspace}{dimension}\n  Let $V$ be a subspace of\\/ $\\R^n$. Then the \\textbf{dimension}%\n  \\index{dimension!of subspace of $\\R^n$}%\n  \\index{subspace!dimension} of $V$, written $\\dim(V)$, is\n  defined to be the number of vectors in a basis.\n\\end{definition}\n\n\\begin{example}{Dimension of\\/ $\\R^n$}{dimension-Rn}\n  What is the dimension of $\\R^n$?\n\\end{example}\n\n\\begin{solution}\n  The standard basis of $\\R^n$ is\n  $\\set{\\vect{e}_1,\\ldots,\\vect{e}_n}$. Since it has $n$ vectors,\n  so $\\dim(\\R^n) = n$.\n\\end{solution}\n\n\\begin{example}{Dimension of a subspace}{dimension-subspace}\n  \\index{dimension!of solution space}%\n  \\index{homogeneous system!dimension of solution space}%\n  \\index{system of linear equations!homogeneous!dimension of solution space}%\n  Let\n  \\begin{equation*}\n    V=\\set{\\left.\n      \\begin{mymatrix}{c} x \\\\ y \\\\ z\\end{mymatrix}\\in\\R^3 ~\\right\\vert~\n      x-y+2z = 0\n    }.\n  \\end{equation*}\n  What is the dimension of\\/ $V$?\n\\end{example}\n\n\\begin{solution}\n  We know that $V$ is a subspace of $\\R^3$, because it is the solution\n  space of a system of a homogeneous system of equations (in this\n  case, one equation in three variables). We can take $y=t$ and $z=s$\n  as the free variables and solve for $x=y-2z=t-2s$. Therefore, a\n  general element of $V$ is of the form\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z\\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} t-2s \\\\ t \\\\ s \\end{mymatrix}\n    ~=~~ t \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + s \\begin{mymatrix}{c} -2 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Thus,\n  \\begin{equation*}\n    V = \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} -2 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Since the two spanning vectors are linearly independent, they form a\n  basis of $V$, and thus $\\dim(V)=2$.\n\\end{solution}\n\nNote that the dimension of the solution space of a system of equations\nis equal to the number of parameters in the general solution, which is\nequal to the number of free variables. For this reason, the dimension\nis also sometimes called the number of \\textbf{degrees of freedom}%\n\\index{degree!of freedom}%\n\\index{freedom!degree of}.\n\n\\begin{example}{Dimension of a span}{dimension-basis}\n  \\index{dimension!of a span}%\n  \\index{span!dimension of}%\n  Let\n  \\begin{equation*}\n    W = \\sspan\\set{\n      \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -1 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ -1 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 8 \\\\ 19 \\\\ -8 \\\\ 8 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -6 \\\\ -15 \\\\ 6 \\\\ -6 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 0 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 5 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  What is the dimension of $W$?\n\\end{example}\n\n\\begin{solution}\n  Let\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -1 \\\\ 1 \\end{mymatrix},~~\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ -1 \\\\ 1 \\end{mymatrix},~~\n    \\vect{u}_3 = \\begin{mymatrix}{r} 8 \\\\ 19 \\\\ -8 \\\\ 8 \\end{mymatrix},~~\n    \\vect{u}_4 = \\begin{mymatrix}{r} -6 \\\\ -15 \\\\ 6 \\\\ -6 \\end{mymatrix},~~\n    \\vect{u}_5 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 0 \\\\ 1 \\end{mymatrix},~~\n    \\vect{u}_6 = \\begin{mymatrix}{r} 1 \\\\ 5 \\\\ 0 \\\\ 1 \\end{mymatrix},\n  \\end{equation*}\n  so that $W=\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_6}$.  We use the\n  casting-out algorithm to remove any redundant vectors from\n  $\\vect{u}_1,\\ldots,\\vect{u}_6$. The remaining vectors will be\n  linearly independent, and therefore a basis of the span.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrrr}\n      1 & 1 & 8 & -6 & 1 & 1 \\\\\n      2 & 3 & 19 & -15 & 3 & 5 \\\\\n      -1 & -1 & -8 & 6 & 0 & 0 \\\\\n      1 & 1 & 8 & -6 & 1 & 1\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrrrrr}\n      \\circled{1} & 0 & 5 & -3 & 0 & -2 \\\\\n      0 & \\circled{1} & 3 & -3 & 0 & 2 \\\\\n      0 & 0 & 0 & 0 & \\circled{1} & 1 \\\\\n      0 & 0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the vectors $\\vect{u}_3$, $\\vect{u}_4$, and $\\vect{u}_6$\n  are redundant, and $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_5}$ is a\n  basis of $W$. It follows that $\\dim(W)=3$.\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{More properties of bases and dimension}\n\nWe begin by noting that every subspace $V$ of $\\R^n$ has a basis.\n\n\\begin{theorem}{Existence of bases}{subspaces-have-bases}\n  \\index{basis!existence}%\n  Every subspace of $\\R^n$ has a basis.\n\\end{theorem}\n\n\\begin{proof}\n  This is just a restatement of Theorem~\\ref{thm:subspaces-are-spans}.\n\\end{proof}\n\nOf course, the theorem does not mean that the basis is\nunique. Usually, a subspace of $\\R^n$ will have many different\nbases. The theorem just states that there exists at least one.\n\nSometimes, when we are looking for a basis of a space, we may already\nhave a number of linearly independent vectors. We would like to obtain\na basis by adding some {\\em additional} linearly independent vectors\nto the ones we already have. The following lemma guarantees that this\ncan always be done.\n\n\\begin{lemma}{Linearly independent set can be extended to a basis}{extend-to-basis}\n  \\index{linear independence!extending to basis}%\n  \\index{basis!by extending linearly independent set}%\n  Let $V$ be a subspace of $\\R^n$, and let\n  $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}$ be linearly independent elements\n  of $V$. Then it is possible to extend\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}}$ to a basis of $V$. In other\n  words, there exist zero or more vectors\n  $\\vect{w}_1,\\ldots,\\vect{w}_s$ such that\n  \\begin{equation*}\n    \\set{\\vect{u}_1,\\ldots,\\vect{u}_{\\ell},\\vect{w}_1,\\ldots,\\vect{w}_s}\n  \\end{equation*}\n  is a basis of $V$.\n\\end{lemma}\n\n\\begin{proof}\n  By Theorem~\\ref{thm:subspaces-have-bases}, we know that $V$ has some\n  basis, say $\\set{\\vect{v}_1,\\ldots,\\vect{v}_k}$. However, this may\n  not be the basis we are looking for, because maybe it does not\n  contain the vectors $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}$. Consider\n  the sequence of $\\ell+k$ vectors\n  \\begin{equation*}\n    \\vect{u}_1,\\ldots,\\vect{u}_{\\ell},\\vect{v}_1,\\ldots,\\vect{v}_k.\n  \\end{equation*}\n  Since $V$ is spanned by the vectors $\\vect{v}_1,\\ldots,\\vect{v}_k$,\n  it is certainly also spanned by the larger set of vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell},\\vect{v}_1,\\ldots,\\vect{v}_k$.\n  From Theorem~\\ref{thm:linearly-independent-subset}, we know that we\n  can obtain a basis of $V$ by removing the redundant vectors from\n  $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell},\\vect{v}_1,\\ldots,\\vect{v}_k$. On\n  the other hand, $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}$ are linearly\n  independent, so none of them can be redundant. It follows that the\n  resulting basis of $V$ contains all of the vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}$. In other words, we have found a\n  basis of $V$ that is an extension of\n  $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}$, which is what had to be shown.\n\\end{proof}\n\n\\begin{example}{Extending a linearly independent set to a basis}{extend-to-basis}\n  Extend $\\set{\\vect{u}_1,\\vect{u}_2}$ to a basis of $\\R^4$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -2 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Let $\\set{\\vect{e}_1,\\ldots,\\vect{e}_4}$ be the standard basis of\n  $\\R^4$. We obtain the desired basis by applying the casting-out\n  algorithm to $\\vect{u}_1,\\vect{u}_2,\\vect{e}_1,\\vect{e}_2,\\vect{e}_3,\\vect{e}_4$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrrr}\n      1  & 1  & 1 & 0 & 0 & 0 \\\\\n      1  & 2  & 0 & 1 & 0 & 0 \\\\\n      -1 & -2 & 0 & 0 & 1 & 0 \\\\\n      2  & 4  & 0 & 0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrrrrr}\n      \\circled{1} &  1 &  1 & 0  & 0 & 0 \\\\\n      0 &  \\circled{1} & -1 & 1  & 0 & 0 \\\\\n      0 &  0 &  0 & \\circled{1}  & 1 & 0 \\\\\n      0 &  0 &  0 & 0  & \\circled{2} & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, we cast out the vectors $\\vect{e}_1$ and $\\vect{e}_4$ and\n  keep the rest. The resulting basis is\n  \\begin{equation*}\n    \\set{\\vect{u}_1,\\vect{u}_2,\\vect{e}_2,\\vect{e}_3}\n    = \\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\\\ 2 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -2 \\\\ 4 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Extending a linearly independent set to a basis}{extend-to-basis2}\n  Let\n  \\begin{equation*}\n    V = \\set{\\left.\n        \\begin{mymatrix}{c} x \\\\ y \\\\ z \\\\ w \\end{mymatrix}\n        ~\\right\\vert~\n      x+2y+z-w = 0\n    }.\n  \\end{equation*}\n  Note that $\\vect{u}_1,\\vect{u}_2\\in V$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ -1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} -2 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Extend $\\set{\\vect{u}_1,\\vect{u}_2}$ to a basis of $V$.\n\\end{example}\n\n\\begin{solution}\n  We first find a basis of $V$ by solving the linear equation\n  $x+2y+z-w = 0$. Taking $y=r$, $z=s$, and $w=t$ as the free\n  variables, we get $x=-2y-z+w = -2r-s+t$, and therefore the general\n  solution is\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\\\ w \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} -2r-s+t \\\\ r \\\\ s \\\\ t \\end{mymatrix}\n    ~=~~ r\\begin{mymatrix}{c} -2 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    + s\\begin{mymatrix}{c} -1 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + t\\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the vectors $\\set{\\vect{v}_1,\\vect{v}_2,\\vect{v}_3}$ form\n  a basis of $V$, where\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} -2 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} -1 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  However, this is not the basis we are looking for, because it does\n  not extend $\\set{\\vect{u}_1,\\vect{u}_2}$. To get a basis of $V$ that\n  extends $\\set{\\vect{u}_1,\\vect{u}_2}$, we perform the casting-out\n  algorithm on the vectors\n  $\\vect{u}_1,\\vect{u}_2,\\vect{v}_1,\\vect{v}_2,\\vect{v}_3$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrr}\n      1  & -2 & -2 & -1 & 1 \\\\\n      -1 & 1  & 1  & 0  & 0 \\\\\n      1  & 1  & 0  & 1  & 0 \\\\\n      0  & 1  & 0  & 0  & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\\ldots\\quad\\roweq\\quad\n    \\begin{mymatrix}{rrrrr}\n      \\circled{1}  & -2 & -2 & -1 & 1 \\\\\n      0  & \\circled{1}  & 1  & 1  & -1 \\\\\n      0  & 0  & \\circled{1}  & 1  & -2 \\\\\n      0  & 0  & 0  & 0  & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Casting out $\\vect{v}_2$ and $\\vect{v}_3$, we find that the desired\n  basis is $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{v}_1}$.\n\\end{solution}\n\nWe also have a kind of opposite of Lemma~\\ref{lem:extend-to-basis}:\nevery spanning set can be shrunk to a basis.\n\n\\begin{lemma}{Spanning set can be shrunk to a basis}{shrink-to-basis}\n  \\index{spanning set!shrink to basis}%\n  \\index{basis!by shrinking spanning set}%\n  Let $V$ be a subspace of $\\R^n$, and let\n  $\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}$ be a set of vectors spanning\n  $V$. Then it is possible to obtain a basis of $V$ by ``shrinking''\n  the set, i.e., by removing zero or more vectors from it.\n\\end{lemma}\n\n\\begin{proof}\n  This is merely a restatement of\n  Theorem~\\ref{thm:linearly-independent-subset}. We obtain the\n  linearly independent subset by removing the redundant vectors, which\n  can be achieved by the casting-out algorithm. See also\n  Example~\\ref{exa:linearly-independent-subset}.\n\\end{proof}\n\nThe following proposition tells us something about the size of a\nlinearly independent set of vectors or the size of a spanning set of\nvectors.\n\n\\begin{proposition}{Size of a linearly independent or spanning set of vectors}{size-linearly-independent-or-spanning}\n  Let $V$ be a $k$-dimensional subspace of $\\R^n$. Then\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Every linearly independent set of vectors in $V$ has at most\n      $k$ vectors.\n    \\item Every spanning set of vectors in $V$ has at least $k$ vectors.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n\n\\begin{proof}\n  Both properties follow from the Exchange Lemma\n  (Lemma~\\ref{lem:exchange-lemma}). Since $V$ is $k$-dimensional, it\n  has some basis consisting of $k$ vectors\n  $\\vect{v}_1,\\ldots,\\vect{v}_k$.\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Suppose $\\vect{u}_1,\\ldots\\vect{u}_r$ are linearly\n      independent vectors in $V$. Since $\\vect{u}_1,\\ldots\\vect{u}_r$\n      are linearly independent and $\\vect{v}_1,\\ldots,\\vect{v}_k$ are\n      spanning, the Exchange Lemma implies that $r\\leq k$.\n    \\item Suppose the vectors $\\vect{u}_1,\\ldots\\vect{u}_s$ span\n      $V$. Since $\\vect{v}_1,\\ldots,\\vect{v}_k$ are linearly\n      independent and $\\vect{u}_1,\\ldots\\vect{u}_s$ are spanning, the\n      Exchange Lemma implies that $k\\leq s$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proof}\n\nThe next proposition often comes in handy when we need to check that\nsome set of vectors is a basis for a subspace $V$, where the dimension\nof $V$ is already known. If $\\dim(V)=k$, we know that any basis has to\nhave size $k$. Interestingly, to check that a set of $k$ vectors is a\nbasis of $V$, it is sufficient to check {\\em either} that it is\nlinearly independent {\\em or} that it is spanning. This can save half\nthe work in checking that some set of vectors is a basis (but it only\nworks if the number of vectors is exactly $k$, the dimension of $V$).\n\n\\begin{proposition}{Basis test for $k$ vectors in $k$-dimensional space}{basis-test-k-vectors}\n  \\index{basis test}%\n  \\index{basis!basis test}%\n  Let $V$ be a $k$-dimensional subspace of $\\R^n$, and consider $k$\n  vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ in $V$.\n  \\begin{itemize}\n  \\item If $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\n    independent, then they form a basis for $V$.\n  \\item If $\\vect{u}_1,\\ldots,\\vect{u}_k$ span $V$, then they\n    form a basis for $V$.\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n  The first claim is an easy consequence of\n  Lemma~\\ref{lem:extend-to-basis}. Assume that\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent. By\n  Lemma~\\ref{lem:extend-to-basis}, we can add zero or more vectors to\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ to obtain a basis of $V$. On the\n  other hand, since $V$ is $k$-dimensional, every basis must have\n  exactly $k$ elements, so that the only possibility is that we have\n  added zero vectors. Therefore,\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is already a basis of $V$,\n  as claimed.\n\n  To prove the second claim, assume that\n  $V=\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$. By\n  Theorem~\\ref{thm:subspaces-are-spans}, there exists a linearly\n  independent subset of $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ that\n  spans $V$, i.e., that is a basis for $V$. But since $\\dim(V)=k$,\n  every basis must have exactly $k$ elements, so that the only\n  possible such subset is $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$\n  itself. Therefore, $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is a\n  basis of $V$, as claimed.\n\\end{proof}\n\nIt is important to note that\nProposition~\\ref{prop:basis-test-k-vectors} does {\\em not} say that\nevery linearly independent set of vectors in $V$ is a basis. For\nexample, a set of $k-1$ or fewer linearly independent vectors will not\nbe spanning. Also, the proposition does {\\em not} say that every\nspanning set of vectors in $V$ is a basis. For example, a set of $k+1$\nor more spanning vectors will not be linearly independent. Rather,\nwhat the proposition is saying is that if we have exactly $k$ vectors\nin a $k$-dimensional space, then linear independence implies spanning\nand vice versa.\n\n\\begin{example}{Basis test for $3$ vectors in $3$-dimensional space}{check-basis}\n  Do the vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  form a basis of\\/ $\\R^3$?\n\\end{example}\n\n\\begin{solution}\n  This is similar to Example~\\ref{exa:non-standard-basis}. But because\n  we know that $\\R^3$ is a $3$-dimensional space, and because we have\n  exactly $3$ vectors, by Proposition~\\ref{prop:basis-test-k-vectors},\n  we only need to check {\\em either} whether\n  $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$ are linearly independent {\\em or}\n  whether they are spanning. We check whether they are linearly\n  independent by using the casting-out algorithm.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 1 & 1 \\\\\n      2 & 1 & 1 \\\\\n      3 & 1 & 2 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr}\n      1 & 1 & 1 \\\\\n      0 & -1 & -1 \\\\\n      0 & 0 & -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since the matrix has rank 3, the vectors\n  $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3$ are linearly\n  independent. Therefore, by\n  Proposition~\\ref{prop:basis-test-k-vectors}, they form a basis of\n  $\\R^3$.\n\\end{solution}\n\nThe following proposition is also a consequence of\nLemma~\\ref{lem:extend-to-basis}. It says that smaller subspaces have\nsmaller dimension.\n\n\\begin{proposition}{Subspace of a subspace}{subset-dimension}\n  Let $V$ and $W$ be subspaces of\\/ $\\R^n$, and suppose that\n  $V\\subseteq W$.  Then $\\dim(V)\\leq\\dim(W)$, with equality only when\n  $V=W$.\n\\end{proposition}\n\n\\begin{proof}\n  Consider any basis $\\vect{u}_1,\\ldots,\\vect{u}_k$ of $V$. Because\n  $V\\subseteq W$, the vectors $\\vect{u}_1,\\ldots,\\vect{u}_k$ are\n  linearly independent elements of $W$, and therefore can be extended\n  to a basis of $W$ by Lemma~\\ref{lem:extend-to-basis}. The resulting\n  basis of $W$ has at least $k$ elements, i.e., $\\dim(V)\\leq\\dim(W)$.\n  To prove the last claim, assume moreover that $\\dim(V)=\\dim(W)$. In\n  that case, $\\dim(W)=k$, so that the $k$ linearly independent vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ form a basis of $W$ by\n  Proposition~\\ref{prop:basis-test-k-vectors}. Since both $V$ and $W$\n  are spanned by $\\vect{u}_1,\\ldots,\\vect{u}_k$, we must have $V=W$,\n  as claimed.\n\\end{proof}\n", "meta": {"hexsha": "51f0ed7a59bea508567e0b43eb9155c856003d51", "size": 39096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SpanIndependenceBasis-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/SpanIndependenceBasis-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/SpanIndependenceBasis-Basis.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.6913705584, "max_line_length": 117, "alphanum_fraction": 0.6210609781, "num_tokens": 14567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6778154778769591}}
{"text": "\n\n\\section{Stratified sampling by a stratified probability bound}\\label{section:SEBB}\n\nIn the previous section we considered different possible EBBs as a way of bounding the error in the context of stratified random sampling, and for this purpose developed a new EBB.\nThis process of using EBBs involved binding EBBs applied to different strata together using union bounds to create a bound on the stratified sample mean error (via Theorem \\ref{triangle_theorem1}).\n\nWhat is worth noting is that this process of binding EBBs together by probability unions is expected to result in a rather weak bound and that this weakness is expected to increase with larger numbers of strata as there are more probability unions needed to bind it together.\nIt is noted that the triangle equality $|A+B|\\le |A|+|B|$, is only an equality in the event that the elements $A$ and $B$ are of the same sign, and in the context of theorems \\ref{triangle_theorem1} and \\ref{triangle_theorem2} the bound for the error is developed by effectively assuming all the errors of the estimates of the strata are additive - which is the worst case.\nWhereas by assumption, the errors in the strata estimates are independent of each other and hence a overestimation in one stratum estimate is likely to be somewhat countered by an underestimation in another.\nBy using this knowledge stronger bounds can be created, and in this section we do just that. We have created an empirical (ie. depending on sample variances) concentration inequality specifically for stratified random sampling.\n\nThe resulting concentration inequality gives an analytic bound on the error of the stratified mean and explicitly considers the sample variances, data widths, sample numbers, and any additional weights on the strata; and includes factors specifically for strata sampled with and/or without replacement.\n\nWe proceed with the derivation of this new bound and method in a series of stages:\n\\begin{enumerate}\n\\item\tin subsection \\ref{subsection:new_bounds} we outlay some lemmas which are the building blocks of further derivations in this section, these are new upper bounds are for the moment generating function of samples and sample squares, as well as the sample means depending on whether sampling is done with or without replacement.\n\\item\tin subsection \\ref{sec:constructing} we use these elements to begin the derivation of the new bound, called the Stratified Empirical Bernstein Bound (SEBB)\n\\item\tin subsection \\ref{subsection:SECB} we additionally derive a variant of the SEBB which uses Chebyshev's inequality\n\\item\tin subsection \\ref{sec:SEBMalgorithm} we describe the algorithm of choosing samples in stratified sampling to minimise the new SEBB bound.\n\\end{enumerate}\n\nAfter these subsections, in the next section \\ref{section:statistics_results} we consider the numerical performance of minimising these new bounds in the context of stratified sampling.\nLet us begin with the elements in these new derivations.\nWe note in this section, all proofs and demonstrations are our own, and are novel, except where otherwise explicitly noted.\n\n%The derivation involves and utilises much of the same components of the previous section with an additional martingale theorem specifically for any any strata sampled without replacement.\n\n\\subsection{Some new bounds on the moment generating function}\\label{subsection:new_bounds}\n\nTo begin the derivation of our new concentration inequality for stratified random sampling, we build upon some of the results of the previous sections.\nSpecifically we utilise three upper bounds for various moment generating functions.\nThe first of which has already been given in the previous section, and is Hoeffding's lemma - Lemma \\ref{Hoeffdings_lemma_lemma}.\nThe other two are given here, and are bounds strongly related to Theorems \\ref{hoeffdings1} and \\ref{sample_squares} respectively.\n\nThe first of these other two upper bounds is very much like Hoeffding's Lemma, except it involves additional information about the variance of the random variable.\n\n\\begin{lemma}\\label{expectation1}\nFor a random variable $X$ that is bounded on an interval $a\\le X\\le b$ with $D=b-a$ and variance $\\sigma^2$, and any $s>0$:\n\\[\n\\E\\left[\\exp(s(X-\\E[x]))\\right] \n\\le\\exp\\left(\\left(\\frac{D^2}{17}+\\frac{\\sigma^2}{2}\\right)s^2\\right)\n\\nonumber\n\\]\n\\end{lemma}\n\\begin{proof}\nWe assume without loss of generality that $X$ is centred to have a mean of zero.\nThen we construct an upper bound for $\\E\\left[\\exp(sX)\\right]$ in terms of $D$ by a parabola over $\\exp(sX)$ for the permitted values of $X$ in the same way as in the proof of Theorem \\ref{hoeffdings1}. By Lemma \\ref{thm:parabola} there exists an $\\alpha,\\beta,\\gamma$ such that $\\alpha s^2X^2+\\beta sX+\\gamma\\ge \\exp(sX)$, and for all $a\\le X\\le b$, hence:\n\\[\nE\\left[\\exp(sX)\\right] \\le \\E[\\alpha s^2X^2+\\beta sX+\\gamma] = \\alpha s^2\\E[X^2]+\\gamma = \\alpha s^2\\sigma^2+\\gamma\n\\nonumber\\]\nWhere it follows that:\n\\begin{equation}\\label{eqn:intermediate_lemma3.5}\nE\\left[\\exp(sX)\\right] \\le\\left(\\frac{\\sigma^2}{b^2}\\exp\\left(s\\left(b+\\frac{\\sigma^2}{b}\\right)\\right) + 1\\right)\\exp\\left(-\\frac{s\\sigma^2}{b}\\right)\\left(\\frac{\\sigma^2}{b^2} + 1\\right)^{-1}.\n\\nonumber \n\\end{equation}\nThis relationship is exactly as in Theorem \\ref{hoeffdings1}, now we do something slightly different - the expression in \\eqref{eqn:intermediate_lemma3.5} is monotonically increasing with $b$, and $D>b$, therefore substituting $D$ for $b$ gives:\n\\begin{equation}\\label{eq:part1}\n\\log(E\\left[\\exp(sX)\\right]) \\le \\log\\left(\\frac{\\sigma^2}{D^2}\\exp\\left(s\\left(D+\\frac{\\sigma^2}{D}\\right)\\right) + 1\\right)-\\frac{s\\sigma^2}{D} - \\log\\left(\\frac{\\sigma^2}{D^2} + 1\\right)\n\\end{equation}\nBecause it is true that for any $\\kappa,x\\ge 0$, that: \n\\begin{equation}\\label{eq:part2}\n\\log(\\kappa\\exp(x)+1)\\le\\log(\\kappa+1)+\\frac{x\\kappa}{\\kappa+1}+x^2\\frac{\\frac{1}{17}+\\frac{\\kappa}{2}}{(\\kappa+1)^2}\n\\end{equation}\nThus letting $\\kappa=\\frac{\\sigma^2}{D^2}$ and $x=s(D+\\sigma^2/D)$ if follows that:\n\\begin{equation}\\label{eq:part3}\n\\log(E\\left[\\exp(sX)\\right]) \\le \\left(\\frac{D^2}{17}+\\frac{\\sigma^2}{2}\\right)s^2\\qedhere\n\\end{equation}\n\\end{proof}\n\nWe note that this process of fitting a parabola over the exponential function is exactly the same process as used to derive Bennett's inequality (Theorem \\ref{hoeffdings1}), but that we derive a weakened result from that same approach.\n\nThe next lemma that we present, is similar to the former, however this time we consider the random variable $X^2$ instead of $X$, and present a weakened bound on the moment generating function of it via a similar process as was used to derive Theorem \\ref{sample_squares}: \n\n\\begin{lemma}\\label{expectation2}\nLet $X$ be a random variable of finite support on an interval $a\\le X\\le b$, with $D=b-a$ and variance $\\sigma^2 = \\E[(X-\\E[x])^2] = \\E[X^2]-\\E[X]^2$. Then for any $q>0$:\n$$\\E[\\exp(q(\\sigma^2-(X-\\E[X])^2))] \\le \\exp\\left(\\frac{1}{2}\\sigma^2q^2D^2\\right)$$\n\\end{lemma}\n\\begin{proof}\nWe assume without loss of generality (and for ease of presentation) that X is centred to have a mean of zero.\nWe construct an upper bound for $\\E\\left[\\exp(-qX^2)\\right]$ in terms of $D$ by a parabola over $\\exp(-qX^2)$ for the permitted values of $X$.\n\nFor an $\\alpha,\\gamma$ such that $\\alpha X^2+\\gamma\\ge \\exp(-qX^2)$ then:\n$$ \\E[\\exp(-qX^2)] \\le \\alpha \\sigma^2 + \\gamma.$$\nIf $d=\\max(b,-a)$ we can choose $\\gamma=1$ and $\\alpha=(\\exp(-q d^2)-1)d^{-2}$ (see figure \\ref{fig:graph111}), Thus:\n\\begin{align*}\n\\E[\\exp(-q X^2)] &\\le \\frac{\\sigma^2}{d^2}\\exp(-q d^2)-\\frac{\\sigma^2}{d^2} + 1\\le \\frac{\\sigma^2}{D^2}\\exp(-q D^2)-\\frac{\\sigma^2}{D^2} + 1 \\\\\n&\\le \\exp\\left(\\log\\left(\\frac{\\sigma^2}{D^2}\\exp(-q D^2)-\\frac{\\sigma^2}{D^2} + 1\\right)\\right)\n\\end{align*}\nGiven that for any $0\\le \\kappa \\le 0.5$ and $x\\le 0$ that: $$\\log\\left(\\kappa\\exp(x)-\\kappa + 1\\right) \\le \\kappa x+\\frac{1}{2}\\kappa(1-\\kappa)x^2$$\nLetting $\\kappa=\\frac{\\sigma^2}{D^2}$ and $x=-qD^2$, which is valid by Popoviciu's inequality (see \\cite{zbMATH05780164}) $\\sigma^2\\le D^2/4$, then:\n$$ \\E[\\exp(-q X^2)] \\le \\exp\\left(\\frac{1}{2}\\sigma^2q^2(D^2-\\sigma^2)-\\sigma^2q\\right) \\le \\exp\\left(\\frac{1}{2}\\sigma^2q^2D^2-\\sigma^2q\\right)$$\nand the result follows by multiplying by $\\exp(q\\sigma^2)$.\n\\end{proof}\n\nThe inequalities above, Lemmas \\ref{expectation1} and \\ref{expectation2}, as well as Lemma \\ref{Hoeffdings_lemma_lemma}, are used in the derivation of our stratified sampling concentration inequality in Section~\\ref{sec:constructing}. One of the primary reasons for utilising these weakened bounds on the moment generating function is that they make the subsequent mathematics far more tractable.\nHowever in order to use these moment generating functions we need to explicitly describe the difference between the moment generating functions of individual random variables (which these are) and the moment generating function of the sample mean of them.\n\n\\subsubsection{Some bounds on the moment generating function of sample means}\\label{sec:without_replacement}\n\nIn order to use the previous bounds on the moment generating function we need a relationship between the moment generating function of a random variable, and the moment generating function of the average of samples of that random variable.\nTo do this we state two further inequalities, where the first one (Lemma~\\ref{martingale1}) is most appropriate for sampling average is taken with replacement, and the second (Lemma~\\ref{martingale0}) can optionally be used in the context that the sampling average is without replacement - and may (or may not) give a tighter result.\n\nWe first state a lemma that is essentially is a formalisation of the process we are familiar with in the last section (see Lemma \\ref{chernoff1}):\n\n\\begin{lemma}[Replacement Bound]\\label{martingale1}\nLet $X$ be a random variable that is bounded $a\\le X\\le b$ with a mean of zero, with $D=b-a$ and variance $\\sigma^2$.\nLet $\\chi_m = \\frac{1}{m}\\sum_{i=1}^mX_i$ be the average of $m$ independently drawn (with replacement) samples of this random variable.\nIf there exists an $\\alpha, \\beta \\ge 0$ such that for any $s>0$ that $\\E[\\exp(sX)]\\le\\exp((\\alpha D^2 +\\beta \\sigma^2) s^2)$ then:\n$$\\textstyle\\E[\\exp(s\\chi_m)]\\le\\exp(\\alpha s^2D^2\\frac{1}{m} +\\beta s^2\\sigma^2 \\frac{1}{m}) = \\exp((\\alpha D^2{\\Omega}_m^n +\\beta\\sigma^2 {\\Psi}_m^n)s^2)$$\nwhere ${\\Omega}_m^n = {\\Psi}_m^n = \\frac{1}{m}$\n\\end{lemma}\n\\begin{proof} \nBy the independence of samples, we have:\n\\[\\E[\\exp(s\\chi_m)]=\\E\\left[\\exp\\left(\\frac{s}{m}\\sum_{i=1}^mX_i\\right)\\right]=\\prod_{i=1}^m\\E\\left[\\exp\\left(\\frac{s}{m}X\\right)\\right]\\] \nThus:\n\\[\\E[\\exp(s\\chi_m)] \\le \\exp\\left(\\frac{s^2}{m^2}\\sum_{i=1}^m\\left(\\alpha D^2 +\\beta \\sigma^2\\right) \\right) \\qedhere\\]\n\\end{proof}\n\n%The requirement that the mean of the random variable is zero is useful as further derivations are applied to random variables which are shifted such as to have a mean of zero ie. $X-\\E[X]$.\nFor the case of sampling without replacement, there is an alternative result that can be directly substituted, given in Lemma~\\ref{martingale0}, below, which can be tighter in certain cases.\nBefore this, particular note must be made that the inequality above, Lemma~\\ref{martingale1} can be used in the context of either sampling with or without replacement.\nIn contrast, Lemma~\\ref{martingale0} can only be used when sampling without replacement. \nThis distinction was shown to be true by \\cite{hoeffding1}, and is rooted in an already presented Lemma \\ref{hoeffdings_reduction}.\n\nWe now state Lemma~\\ref{martingale0}, an inequality regarding the moment generating function of the average of samples taken specifically \\textit{without replacement}.\nWhen the sampling takes place without replacement the inequality of Lemma~\\ref{martingale1} can potentially be tightened to take advantage of the finite size of the population.\nThis inequality extends an important martingale inequality from \\cite{bardenet2015}:\n\n\\begin{lemma}[Martingale Bound]\\label{martingale0}\nFor finite data $x_1,x_2,\\dots x_n$ that is bounded $a\\le x_i\\le b$, and has a mean of zero and variance $\\sigma^2=\\frac{1}{n}\\sum_{i=1}^nx_i^2$, denote $X_1,X_2,\\dots,X_n$ the random variables corresponding to the data sequentially drawn randomly without replacement, and $\\chi_m$ the average of the first $m$ of them.\nIf for any random variable $Z$ with a mean of zero such that $a\\le Z\\le b$ and $D=b-a$, with variance $\\sigma_Z^2$ that there exists an $\\alpha, \\beta \\ge 0$ such that for any $s>0$ that $\\E[\\exp(sZ)]\\le\\exp((\\alpha D^2 +\\beta \\sigma_Z^2) s^2)$ then:\n\\begin{align*}\\E[\\exp(s\\chi_m)]&\\le\\exp\\left(\\alpha s^2D^2\\sum_{k=m}^{n-1}\\frac{1}{k^2} +\\beta s^2\\sigma^2 \\sum_{k=m}^{n-1}\\frac{n}{k^2(k+1)}\\right)\\\\ &\\le \\exp((\\alpha D^2\\bar{\\Omega}_m^n +\\beta\\sigma^2 \\bar{\\Psi}_m^n)s^2)\\end{align*}\nwhere $\\bar{\\Omega}_m^n = \\sum_{k=m}^{n-1}\\frac{1}{k^2}\\approx \\frac{(m+1)(1-m/n)}{m^2}$ and $\\bar{\\Psi}_m^n = \\sum_{k=m}^{n-1}\\frac{n}{k^2(k+1)}\\approx \\frac{n+1-m}{m^2}$.\n\\end{lemma}\n\\begin{proof}\nObserve that:\n\\begin{align*}\n\\chi_m \n& =\\frac{1}{m}\\sum_{i=1}^{m}X_i = \\chi_{m+1}+\\frac{1}{m}(\\chi_{m+1}-X_{m+1})\\\\\n& =(\\chi_m-\\chi_{m+1})+(\\chi_{m+1}-\\chi_{m+2}) + \\dots + (\\chi_{n-1}-\\chi_n)\\\\\n& =\\frac{1}{m}(\\chi_{m+1}-X_{m+1})+\\frac{1}{m+1}(\\chi_{m+2}-X_{m+2}) + \\dots + \\frac{1}{n-1}(\\chi_n-X_n).\n\\end{align*} \nThen because:\n$$\\exp(s\\chi_m)=\\prod_{k=m}^{n-1}\\exp\\left(\\frac{s}{k}(\\chi_{k+1}-X_{k+1})\\right),$$\nwe also have that: \n$$\\E[\\exp(s\\chi_m)]=\\E\\left[\\prod_{k=m}^{n-1}\\E\\left[\\exp\\left(\\frac{s}{k}(\\chi_{k+1}-X_{k+1})\\right)|\\chi_{k+1}\\dots \\chi_n\\right]\\right]$$\nby repeated application of the Law of total expectation. \nSince:\n$$\\E[X_{k+1}|\\chi_{k+1}\\dots \\chi_n]=\\chi_{k+1},$$ \nthen $\\chi_{k+1}-X_{k+1}$ is a random variable with a mean of zero bounded within width $D$, and it also has a variance given by: \n\\begin{equation}\\label{approx1} \n\\sigma_{k+1}^2 = \\frac{n\\sigma^2-\\sum_{j=k+1}^nX_j^2}{n-(n-k-1)} - \\chi_k^2 \\le \\frac{n\\sigma^2}{k+1}\n\\end{equation}\nby application of Lemma~\\ref{variance1}. \nTherefore: \n\\[\\E[\\exp(s\\chi_m)]\\le\\exp\\left(\\sum_{k=m}^{n-1}\\left(\\alpha D^2 +\\beta \\frac{n\\sigma^2}{k+1}\\right) \\frac{s^2}{k^2}\\right)\\qedhere\\]\n\\end{proof}\n\n\nThis martingale result relates the moment generating function bound of the average of finite variables relative to their mean, to the moment generating function bounds of the  differences of the incremental averages relative to their mean. \nWe note that this result could potentially be made much stronger by working around the use of Equation~\\eqref{approx1}, but this comes at a cost of increased mathematical complexity.\n\nSince Lemmas~\\ref{martingale0} and~\\ref{martingale1} share a common form, and because of Hoeffding's reduction (Lemma~\\ref{hoeffdings_reduction}), \nall the derivations that follow that invoke Lemma~\\ref{martingale1} have direct analogues using Lemma~\\ref{martingale0} for the context of sampling without replacement.\nNote, however, that the bound without replacement (Lemma~\\ref{martingale0}) may or may not be tighter than the bound with replacement (Lemma~\\ref{martingale1}). However, the process of substituting one for the other can be done judiciously on a case-by-case basis to create the tightest possible bound.\nAll the numerical results in Section \\ref{section:statistics_results} (that are relevant to sampling without replacement) have been produced with this judicious choice conducted.\n\n\\subsection{The Stratified finite Empirical Bernstein Bound (SEBB)}\n\\label{sec:constructing}\n\nIn this section we derive a novel probability bound for the error of the stratified random sampling estimate, \nand use it to define a sequential stratified sampling algorithm. \nBefore this, we begin by precisely defining the context of our derivations, to which our bound applies.\n\n\\begin{definition}[Problem context]\\label{def:ProblemContext}\\hspace{1cm}\\\\\n\\begin{itemize}\n    \\item Let a population consist of $n$ number of strata,\n    \\item where $n_i$ is the total number of data points in the $i$th stratum.\n    \\item All values in a stratum are bound within a finite support of width $D_i$.\n    \\item the mean of the $i$th stratum is $\\mu_i$, and its variance $\\sigma_i^2$.\n    \\item the random variables corresponding to the samples drawn from the $i$ stratum are:\\\\ $X_{i,1},X_{i,2},\\dots,X_{i,n_i}$\n    \\item for each stratum $m_i$ samples are taken\n    \\item forming the sample mean of each stratum: $\\chi_{i,m_i}= \\frac{1}{m_i}\\sum_{j=1}^{m_i}X_{i,j}$\n    \\item the biased sample variance of each stratum: $\\hat{\\sigma}_i^2=\\frac{1}{m_i}\\sum_j^{m_i}(X_{i,j}-\\chi_{i,m_i})^2$\n    \\item the unbiased sample variance of each stratum: $\\doublehat{\\sigma}_i^2 = m_i\\hat{\\sigma}_i^2/(m_i-1)$\n    \\item we consider the average of the means of the strata as weighted by constant positive factors $\\{\\tau_i \\}_{i\\in \\{1,\\dots,n\\}}$\n    \\item And throughout the derivation we also use temporary arbitrary positive variables $\\{\\theta_i \\}_{i\\in \\{1,\\dots,n\\}}$\n\\end{itemize}\n\\end{definition}\n\n\n\\noindent The bound is now developed in four theorems, which build on each other in sequence:\n\\begin{enumerate}\n    \\item in subsubsection~\\ref{subsubsection:variance_assisted_sebb} Theorem~\\ref{thm:1} develops a concentration inequality for the error in the stratified population mean estimate $\\sum_{i=1}^n\\tau_i\\chi_{i,m_i}$ in the context of the knowledge of stratum variances.\n    \\item in subsubsection~\\ref{subsubsection:variance_square_error_bound} Theorem~\\ref{thm:2} is a concentration inequality of the difference between the stratum variances and sample variances in the context the sum of knowledge of the squared stratum mean errors.\n    \\item in subsubsection~\\ref{subsubsection:a_bound_on_sample_squares} Theorem~\\ref{thm:3} is an inequality directly that binds the sum of sample squared stratum mean errors.\n    \\item in subsubsection~\\ref{subsubsection:centerpiece} Theorem~\\ref{thm:SEBM_bound} combines the three previous theorems together using two union bounds to create a concentration inequality for the error in the stratified population mean estimate given the sample variances.\n\\end{enumerate}\n\n\n\\subsubsection{A bound on the sample mean assuming variances}\\label{subsubsection:variance_assisted_sebb}\n\nIn a similar way to what was done in the previous section, to derive an Empirical Bernstein Bound we begin with a derivation of a probability bound on the error of the sample mean of a random variable in terms of the random variable's variance.\nIn the previous section the bound in question was the venerable Bennett's inequality (Theorem \\ref{hoeffdings1}) however in this section we consider a more relaxed and similar version of it which is more easy for us to manipulate, and in this case the random variable in question is the weighted mean $\\sum_{i=1}^n\\tau_i\\chi_{i,m_i}$.\n\nThis is probability bound on the absolute error of the weighted stratified sample means about the weighted strata means, which we call a variance-assisted SEBB (stratified empirical Bernstein bound).\n\n\n\\begin{theorem}[Variance-assisted SEBB]\\label{thm:1}\nAssuming the context given in Definition~\\ref{def:ProblemContext}, and let $\\Omega_{m_i}^{n_i}$ and $\\Psi_{m_i}^{n_i}$ be given as in Lemma~\\ref{martingale1}, then:\n\\begin{equation}\\label{eq1} \\pr\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right|\\ge \\sqrt{4\\log(2/t)\\sum_{i=1}^n\\left(\\frac{1}{17}D_i^2\\Omega_{m_i}^{n_i}+\\frac{1}{2}\\sigma_i^2\\Psi_{m_i}^{n_i}\\right)\\tau_i^2}\\right)\\le t \\end{equation}\n\\end{theorem}\n\\begin{proof}\nIn a similar way as Lemma~\\ref{chernoff1} we consider a bound for the weighted mean by the moment generating function of the stratum means:\n\\begin{align*} \\pr\\left(\\sum_{i=1}^n\\tau_i\\chi_{i,m_i}-\\sum_{i=1}^n\\tau_i\\mu_i\\ge t\\right)\n&\\le\\E\\left[\\exp\\left(\\sum_{i=1}^n\\tau_is\\left(\\chi_{i,m_i}-\\mu_i\\right)\\right)\\right]\\exp(-st)\\\\\n&= \\prod_{i=1}^n\\E\\left[\\exp\\left(\\tau_is\\left(\\chi_{i,m_i}-\\mu_i\\right)\\right)\\right]\\exp(-st) \n\\end{align*}\nThis involves the assumption that the sampling -between- the strata is independent.\nThis form is sufficient for Lemma~\\ref{martingale1} with Lemma~\\ref{expectation1} to apply, resulting in a double-sided tail bound:\n$$ \\pr\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right|\\ge t\\right)\\le 2\\exp\\left(\\sum_{i=1}^n\\left(\\frac{1}{17}D_i^2\\Omega_{m_i}^{n_i}+\\frac{1}{2}\\sigma_i^2\\Psi_{m_i}^{n_i}\\right)\\tau_i^2s^2 - st\\right) $$\nMinimizing with respect to $s$ and rearranging gives result.\n\\end{proof}\n\nThis particular bound assumes knowledge of the variances of the strata, and will be used as a tool for selecting samples primarily for comparison with other sampling methods (such as Neyman sampling) in Section \\ref{section:statistics_results}.\n\nIt is a concentration inequality for the weighted stratum means, leading to the more general question of what the weights should be. In most cases, the weights $\\tau_i$ can be considered as the probability weights $\\tau_i=n_i/(\\sum_{j=1}^nn_j)$ of standard stratified sampling.\nIn this context this probability bound can be used as-is for a measure of uncertainty in stratified random sampling if the true variances (or alternatively, upper bounds on the true variances) of the strata are known.\nHowever the weights may be assigned differently - and we will investigate such a case for the Shapley Value in section \\ref{section:statistics_results}.\n\nThe bound depends on a weighted sum of strata variances $ \\sum_{i=1}^n \\sigma_i^2 \\Psi_{m_i}^{n_i} \\tau_i^2 $, and in most situations these values aren't known.\nHence to use this inequality we need to consider the probable error between the weighted sum of strata variances and the weighted sum of strata sample variances.\n\n\\subsubsection{A bound on the sample variance in terms of sample error squares}\\label{subsubsection:variance_square_error_bound}\n\nTo create a bound on the error between the strata variances and the strata sample variances we develop a probability bound for the error estimate of the sum of variances (as weighted by arbitrary $\\theta_i$) in terms of the sample square errors (which will also consequently be bounded), as follows:\n\n\\begin{theorem}\\label{thm:2}\nAssuming the context given in Definition~\\ref{def:ProblemContext}.\nThen with $\\Psi_{m_i}^{n_i}$ per Lemma~\\ref{martingale1}:\n\\begin{equation}\\label{eq2} \\pr\\left(\\sum_{i=1}^n\\theta_i(\\sigma_i^2-\\hat{\\sigma}_i^2 - (\\mu_i - \\chi_{i,m_i})^2)\\ge \\sqrt{2\\log(1/y)\\sum_{i=1}^n\\sigma_i^2\\theta_i^2D_i^2\\Psi_{m_i}^{n_i}}\\right) \\le y \\end{equation}\n\\end{theorem}\n\n\n\\begin{proof}\nTo create a probability bound for the sum of variances (weighted by arbitrary positive $\\theta_i$), we consider the average square of samples about the strata means. \nApplying Lemma~\\ref{chernoff1} gives:\n\\begin{align*} \n\\pr&\\left(\\sum_{i=1}^n\\theta_i(\\sigma_i^2-\\frac{1}{m_i}\\sum_{j=1}^{m_i}(X_{i,j}-\\mu_i)^2)\\ge y\\right) \\\\\n&\\le \\E\\left[\\exp\\left(\\sum_{i=1}^ns\\theta_i\\left(\\sigma^2-\\frac{1}{m_i}\\sum_{j=1}^{m_i}(X_{i,j}-\\mu_i)^2\\right)\\right)\\right]\\exp(-sy)\\\\\n& \\le \\exp(-sy)\\prod_{i=1}^n\\E\\left[\\exp\\left(\\frac{s\\theta_i}{m_i}\\sum_{j=1}^{m_i}(\\sigma^2-(X_{i,j}-\\mu_i)^2)\\right)\\right] \n\\end{align*}\nAnd this reason is by the assumption of the independence of the sampling -between- the strata. \nThis resulting form is sufficient for Lemma~\\ref{martingale1} with Lemma~\\ref{expectation2} to apply, giving:\n$$ \\pr\\left(\\sum_{i=1}^n\\theta_i(\\sigma_i^2-\\frac{1}{m_i}\\sum_{j=1}^{m_i}(X_{i,j}-\\mu_i)^2)\\ge y\\right) \\le \\exp\\left(\\frac{1}{2}\\sum_{i=1}^n\\sigma_i^2\\theta_i^2s^2D_i^2\\Psi_{m_i}^{n_i}-sy\\right)$$\nMinimizing with respect to $s$, rearranging, and applying Lemma \\ref{variance1} gives result.\n\\end{proof}\n\nThis inequality gives the probability bound between the arbitrarily (by $\\theta_i$) weighted variances of the strata and also the same weighted (biased estimator) sample variances.\nHowever it also additionally involves the weighted square error of the sample means as a complicating factor.\nAlthough the weighted square error of the sample means may go to zero quickly as additional samples are taken, we nonetheless need to develop another probability bound to incorporate the specific consideration of it.\n\n\\subsubsection{A bound on weighted sample error squares}\\label{subsubsection:a_bound_on_sample_squares}\n\nIn the previous Theorem \\ref{thm:2} the weighted sum of sample squares was a complicating factor which we seek to bound and incorporate. The following probability inequality bounds the weighted square error of the sample means directly:\n\n\\begin{theorem}\\label{thm:3}\nAssuming the context given in Definition~\\ref{def:ProblemContext}.\nThen with $\\Omega_{m_i}^{n_i}$ as in Lemma~\\ref{martingale1}:\n\\begin{equation}\\label{eq1.5} \\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 \\ge \\frac{\\log(2n/r)}{2}\\sum_{i=1}^n\\theta_iD_i^2\\Omega_{m_i}^{n_i}\\right) \\le r \\end{equation}\n\\end{theorem}\n\\begin{proof}\nWe consider the weighted square error of the sample means, and by probability complimentarity we know:\n$$ \\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 \\ge r\\right) = 1-\\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 < r\\right) $$\n\nAs the probability that sum of any random variables is less than $r$ is obviously greater than the probability that those random variables individual are all less than specific values that sum to $r$ hence, for $r_i$ such that $\\sum r_i=r$:\n\n$$ \\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 \\ge r\\right) \\le 1-\\prod_{i=1}^n\\pr\\left(\\theta_i(\\mu_i - \\chi_{i,m_i})^2 < r_i\\right) $$\nhence by probability complimentarities again:\n\\begin{align*}&\\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 \\ge r\\right) \\le \\\\&\\qquad\\qquad 1-\\prod_{i=1}^n\\left(1-\\pr\\left(\\mu_i - \\chi_{i,m_i} \\ge \\sqrt{\\frac{r_i}{\\theta_i}}\\right) - \\pr\\left( \\chi_{i,m_i}-\\mu_i \\ge \\sqrt{\\frac{r_i}{\\theta_i}}\\right)\\right)\\end{align*}\n\nAnd this is exactly the form which we want, in terms of the products of the error in each of the strata sample means.\nThus we can apply Lemma~\\ref{chernoff1} together with Lemmas~\\ref{martingale1} and~\\ref{Hoeffdings_lemma_lemma}, which gives:\n$$ \n\\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 \\ge r\\right) \\le 1-\\prod_{i=1}^n\\left(1-2\\exp\\left(-\\frac{2r_i}{\\theta_iD_i^2\\Omega_{m_i}^{n_i}}\\right)\\right)\n$$\nNext, choosing $r_i$ to minimise the right hand side of this expression gives:\n$$\nr_i = \\frac{r\\theta_iD_i^2\\Omega_{m_i}^{n_i}}{\\sum_j \\theta_jD_j^2\\Omega_{m_j}^{n_j}}\n$$\nIn this context, we therefore deduce that:\n$$ \n\\pr\\left(\\sum_{i=1}^n\\theta_i(\\mu_i - \\chi_{i,m_i})^2 \\ge r\\right) \\le 1-\\prod_{i=1}^n\\left(1-2\\exp\\left( \\frac{-2r}{\\sum_j\\theta_j D_j^2\\Omega_{m_j}^{n_j}}\\right)\\right)\n$$\nUsing the fact that $\\log(1-(1-\\exp(x))^n)\\le x+\\log(n)$ for any negative $x$, and rearranging, gives the required result.\n\\end{proof}\n\nThis theorem directly bounds the weighted square errors of the sample means independently of any other specifically unknown factors.\n\n\\subsubsection{The centerpiece of the SEBB}\\label{subsubsection:centerpiece}\n\nIn the previous three theorems we have a bound on the stratified mean estimate in terms of the variances, a bound on the variances in terms of the sample variances by the sample square errors, and a bound on the sample square errors.\nIn the next step we combine all the inequalities of Equations~\\eqref{eq1}, \\eqref{eq2} and~\\eqref{eq1.5} from Theorems \\ref{thm:1}, \\ref{thm:2} and \\ref{thm:3} together, to complete our derivation of a probability bound for the error in stratified sampling in terms of stratum sample variances - our SEBB.\n\n\n\\begin{theorem}[Stratified Empirical Bernstein Bound (SEBB)]\\label{thm:SEBM_bound}\nAssuming the context given in Definition~\\ref{def:ProblemContext}.\nThen with $\\Omega_{m_i}^{n_i},\\Psi_{m_i}^{n_i}$ per Lemma~\\ref{martingale1}:\n\\begin{equation}\\label{big_equation}\n%\\p\\left(\\frac{\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right|}{\\sqrt{\\log(6/p)}}\\ge \\sqrt{\\begin{matrix*}[l]\\sum_{i=1}^n\\frac{4}{17}\\Omega_{m_i}^{n_i}D_i^2\\tau_i^2 \\\\ +\\begin{pmatrix*}[l]\\sqrt{\\log(3/p)\\left(\\max_i\\tau_i^2{\\Psi_{m_i}^{n_i}}^2D_i^2\\right)} \\\\ +\\sqrt{\\begin{matrix*}[l]2\\sum_{i=1}^n\\tau_i^2\\Psi_{m_i}^{n_i}(m_i-1)\\doublehat{\\sigma}_i^2/m_i \\\\ + \\log(6n/p)\\sum_i\\tau_i^2D_i^2\\Omega_{m_i}^{n_i}\\Psi_{m_i}^{n_i} \\\\ +\\log(3/p)\\left(\\max_i\\tau_i^2{\\Psi_{m_i}^{n_i}}^2D_i^2\\right)\\end{matrix*}} \\end{pmatrix*}^2\\end{matrix*}}\\right)\n%\\le p \n%\\end{equation}\n%\\begin{equation}\\label{big_equation_alternate}\n\\pr\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right| \n\\ge \\sqrt{\\log(6/p)\\left( \\alpha\n+ \\left(\\sqrt{\\beta} \n+ \\sqrt{\\gamma}\\right)^2\\right) } \\right)\n\\le p \n\\end{equation}\nwhere:\n\\begin{align*}\n\\alpha=&\\sum_{i=1}^n\\frac{4}{17}\\Omega_{m_i}^{n_i}D_i^2\\tau_i^2 \\\\\n\\beta=&\\log(3/p)\\left(\\max_i\\tau_i^2{\\Psi_{m_i}^{n_i}}^2D_i^2\\right) \\\\\n\\gamma=& 2\\sum_{i=1}^n\\tau_i^2\\Psi_{m_i}^{n_i}(m_i-1)\\doublehat{\\sigma}_i^2/m_i\n+ \\log(6n/p)\\sum_i\\tau_i^2D_i^2\\Omega_{m_i}^{n_i}\\Psi_{m_i}^{n_i} \\\\\n&\\quad\\quad\\quad\\quad\\quad\\quad\\quad\\quad\\quad\\quad\\quad~+\\log(3/p)\\left(\\max_i\\tau_i^2{\\Psi_{m_i}^{n_i}}^2D_i^2\\right).\n\\end{align*}\n\n\n%$$\n%\\alpha_{m_i}^{n_i}\n%=\\sum_{i=1}^n\\frac{4}{17}\\Omega_{m_i}^{n_i}D_i^2\\tau_i^2 \n%$$\n%$$\n%\\beta_{m_i}^{n_i}\n%=\\log(3/p)\\left(\\max_i\\tau_i^2{\\Psi_{m_i}^{n_i}}^2D_i^2\\right) \n%$$\n%and\n%\\begin{align*}\n%\\gamma_{m_i}^{n_i}\n%= 2\\sum_{i=1}^n\\tau_i^2\\Psi_{m_i}^{n_i}(m_i-1)\\doublehat{\\sigma}_i^2/m_i\n%&+ \\log(6n/p)\\sum_i\\tau_i^2D_i^2\\Omega_{m_i}^{n_i}\\Psi_{m_i}^{n_i}  \\\\\n%&+\\log(3/p)\\left(\\max_i\\tau_i^2{\\Psi_{m_i}^{n_i}}^2D_i^2\\right)\n%\\end{align*}\n\\end{theorem}\n\n\n\\begin{proof}\nBy widening the bound of Equation~\\eqref{eq2} we get:\n$$\n\\pr\\left(\\begin{matrix*}[l]\\sum_{i=1}^n\\theta_i\\sigma_i^2-\\sum_{i=1}^n\\theta_i(\\hat{\\sigma}_i^2+(\\mu_i - \\chi_{i,m_i})^2)\\ge \\\\ \\quad\\quad\\quad\\quad\\quad \\sqrt{2\\log(1/y)(\\max_i\\theta_iD_i^2\\Psi_{m_i}^{n_i})\\sum_{i=1}^n\\theta_i\\sigma_i^2}\\end{matrix*}\\right) \\le y.\n$$\nCompleting the square gives for $\\sqrt{\\sum_{i=1}^n\\theta_i\\sigma_i^2}$ gives:\n$$\n\\pr\\left(\\sqrt{\\sum_{i=1}^n\\theta_i\\sigma_i^2} \\ge \\begin{matrix*}[l]\\quad\\sqrt{\\begin{matrix*}[l]\\sum_{i=1}^n\\theta_i(\\hat{\\sigma}_i^2+(\\mu_i - \\chi_{i,m_i})^2)\\\\ ~ + \\frac{\\log(1/y)}{2}\\left(\\max_i\\theta_iD_i^2\\Psi_{m_i}^{n_i}\\right)\\end{matrix*}} \\\\  +\\sqrt{\\frac{\\log(1/y)}{2}\\left(\\max_i\\theta_iD_i^2\\Psi_{m_i}^{n_i}\\right)}\\end{matrix*}\\right) \\le y. \n$$\nCombining with Equation~\\eqref{eq1.5} with a union bound (Lemma~\\ref{prob_union}) gives:\n\\begin{equation}\\label{eq:sum_variance_bound_equation}\n\\pr\\left(\\sqrt{\\sum_{i=1}^n\\theta_i\\sigma_i^2} \\ge \\begin{matrix*}[l]\\quad\\sqrt{\\begin{matrix*}[l]\\sum_{i=1}^n\\theta_i\\hat{\\sigma}_i^2+ \\frac{\\log(2n/r)}{2}\\sum_i\\theta_iD_i^2\\Omega_{m_i}^{n_i} \\\\ ~+ \\frac{\\log(1/y)}{2}\\left(\\max_i\\theta_iD_i^2\\Psi_{m_i}^{n_i}\\right)\\end{matrix*}} \\\\ +\\sqrt{\\frac{\\log(1/y)}{2}\\left(\\max_i\\theta_iD_i^2\\Psi_{m_i}^{n_i}\\right)}\\end{matrix*}\\right) \\le y+r ,\n\\end{equation}\nwhich is a bound for the weighted sum variances in terms of the sample variances.\nLetting $\\theta_i = \\frac{1}{2}\\tau_i^2\\Psi_{m_i}^{n_i}$ and combining with \\eqref{eq1} with a union bound (Lemma~\\ref{prob_union}), \nand then assigning $ r=t=y=p/3 $ and rewriting in terms of unbiased sample variance, gives the result.\n\\end{proof}\n\nThis completes the derivation of the SEBB.\nIn Equation \\eqref{big_equation} of Theorem~\\ref{thm:SEBM_bound}, we have a concentration inequality for the sum of weighted strata sample mean errors relative to the sample variances. \nIn this context, the weights $\\tau_i$ are flexible but would naturally be probability weights proportional to strata size,  $\\tau_i=n_i/(\\sum_{j=1}^nn_j)$, \nin which case the inequality provides a concentration of measure in stratified random sampling.\\\\\n\n\n\n\\subsection{A Stratified Empirical Chebyshev Bound (SECB)}\\label{subsection:SECB}\n\nIt is also possible to consider another strongly related bound on the error in stratified sampling.\nSince the last Theorem \\ref{thm:SEBM_bound} ultimately builds upon Theorem \\ref{thm:1} which was the embodiment of a simplification of Bennett's inequality per Lemma \\ref{expectation1}.\nAnd since we will ultimately compare performance of these bounds against Neyman sampling which is conceptually built upon the minimisation of Chebyshev's inequality (Theorem \\ref{thm:chebyshevs}) we will also consider and compare against a empirical Chebyshev's inequality for stratified sampling.\n\n\n\\begin{theorem}[Stratified Empirical Chebyshev Bound (SECB)]\\label{thm:SECM_bound}\nAssuming the context given in Definition~\\ref{def:ProblemContext}.\nThen with $\\Omega_{m_i}^{n_i},\\Psi_{m_i}^{n_i}$ per Lemma~\\ref{martingale1}:\n\\begin{equation}\\label{another_big_equation}\n\\pr\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right| \n\\ge \\sqrt{\\frac{3}{p}}\\left(\n\\sqrt{\\alpha+\\beta} \n+ \\sqrt{\\beta}\\right)  \\right)\n\\le p \n\\end{equation}\nwhere:\n\\begin{align*}\n\\alpha=&\\sum_{i=1}^n\\tau_i^2\\Psi_{m_i}^{n_i}(m_i-1)\\doublehat{\\sigma}_i^2/m_i+ \\frac{\\log(6n/p)}{2}\\sum_i\\tau_i^2\\Psi_{m_i}^{n_i}D_i^2\\Omega_{m_i}^{n_i} \\\\\n\\beta=&\\frac{\\log(3/p)}{2}\\left(\\max_i\\tau_i^2D_i^2{\\Psi_{m_i}^{n_i}}^2\\right)\n\\end{align*}\n\\end{theorem}\n\\begin{proof}\nWe can use Chebyshev's inequality (Theorem \\ref{thm:chebyshevs}) for the strata sample estimator giving:\n$$ \\p\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right|\\ge \\frac{1}{\\sqrt{k}}\\sqrt{\\text{Var}\\left(\\sum_{i=1}^n\\tau_i\\chi_{i,m_i}\\right)}\\right) \\le k $$\nWhich is a probability bound for the error of the stratum mean estimator in terms of its variance.\nWhereby we can assume the independence of the sampling between the strata and sampling with replacement, giving the decomposition of the variance of the estimator (in a similar process to Equation \\ref{eq:variance_decomposition_for_strata_mean}), giving:\n$$ \\text{Var}\\left(\\sum_{i=1}^n\\tau_i\\chi_{i,m_i}\\right) = \\sum_{i=1}^n\\tau_i^2\\text{Var}(\\chi_{i,m_i}) =  \\sum_{i=1}^n\\frac{\\tau_i^2\\sigma_i^2}{m_i} $$\nHence:\n$$ \\p\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right|\\ge \\frac{1}{\\sqrt{k}}\\sqrt{\\sum_{i=1}^n\\Psi_{m_i}^{n_i}\\tau_i^2\\sigma_i^2}\\right) \\le k $$\nWhich is a Chebyshev type inequality for the error of the stratum mean estimator in terms of a sum of the stratum variances - and is very analogous to Equation \\ref{eq1} of Theorem \\ref{thm:1}.\nAnd since equation \\ref{eq:sum_variance_bound_equation} (from the previous proof) is a general bound for an arbitrary sum of the stratum variances we can combine with it (in the case of setting $\\theta_i = \\tau_i^2\\Psi_{m_i}^{n_i}$) by a union bound (Lemma~\\ref{prob_union}), giving:\n\\begin{align*}\n\\pr\\left(\\left|\\sum_{i=1}^n\\tau_i(\\chi_{i,m_i}-\\mu_i)\\right| \\ge \\frac{1}{\\sqrt{k}}\\left( \\begin{matrix*}[l]\\quad\\sqrt{\\begin{matrix*}[l]\\sum_{i=1}^n\\tau_i^2\\Psi_{m_i}^{n_i}\\hat{\\sigma}_i^2+ \\frac{\\log(2n/r)}{2}\\sum_i\\tau_i^2\\Psi_{m_i}^{n_i}D_i^2\\Omega_{m_i}^{n_i} \\\\ ~+ \\frac{\\log(1/y)}{2}\\left(\\max_i\\tau_i^2D_i^2{\\Psi_{m_i}^{n_i}}^2\\right)\\end{matrix*}} \\\\ +\\sqrt{\\frac{\\log(1/y)}{2}\\left(\\max_i\\tau_i^2D_i^2{\\Psi_{m_i}^{n_i}}^2\\right)}\\end{matrix*}\\right)\\right)&\\\\ \\le y+&r+k\n\\end{align*}\nAnd setting $ r=k=y=p/3 $ and rewriting in terms of unbiased sample variance, gives the result.\n\\end{proof}\n\nWe will now turn to how minimising these bounds on the stratified sample mean estimate (theorems \\ref{thm:SEBM_bound} and \\ref{thm:SECM_bound}) can be used as a method of choosing samples in the context of stratified sampling.\nAnd afterwards, in the next section \\ref{section:statistics_results} we will compare how all these methods work in actually sampling stratified data.\n\n\n\n\n\n\\subsection{Sequential sampling using the stratified empirical bernstein method} \\label{sec:SEBMalgorithm}\n\n%To evaluate the effectiveness of the process of sequentially minimising the probability bounds on the error of the sample estimated stratified mean, we need a little development of those algorithms before proceeding to give details on the process of testing them in the context of synthetic data.\n%It is necessary to consider the way in which the concentration inequality of the previous section (Theorem \\ref{thm:SEBM_bound}) should be iteratively minimised; and this process is expounded as Algorithm \\ref{alg2}.\n\n\nIn this section, we developed a concentration inequality to bound the error of the sampling mean estimate in stratified random sampling, called the SEBB - as per Theorem \\ref{thm:SEBM_bound}.\nThe process of selecting additional samples to minimise this probability bound on the error is introduced in this section. And we call it the \\textit{stratified empirical Bernstein method} (SEBM).\n\nThe fundamental principle of the SEBM, is that it is an online method of choosing additional samples which repeatedly scans through possible stratum for optimum sample choice, and the strata which would result in the most reduction of the SEBB bound is then recommended for additional sampling.\nThe pseudo-code for this process of sampling, is given as Algorithm \\ref{alg2}.\n\n\nSpecifically, Algorithm \\ref{alg2} is a repetitive process involving a scan through the possible strata and then the selection of one stratum to sample from.\nThe process of scanning involves calculating the confidence bound width (SEBB) that would result if an additional sample were to be taken from that stratum without changing its sample variance (line numbers 5-17 in Algorithm~\\ref{alg2}).\nThe stratum that yields the smallest confidence bound width in the context of an additional sample is then selected (line 18-21) and sampled (line 24), the sample variance of that stratum is updated (line 26); \nthis process repeats until the maximum sample budget is reached (per the outer loop, line 1).\nIn this way the process attempts to iteratively minimise the SEBB in expectation with each additional sample taken; and hence lead to potentially greater accuracy in stratified sampling as a result.\n\nThe primary assumption that exists in this method's selection calculus is that it assumes that the sample variance of the strata would likely remain unchanged for the taking of the additional sample from any strata.\nWhile this technically isn't true, the unbiased sample variance is expected to be almost as likely to increase as it is likely to decrease from the taking of an additional sample.\nPlus developing an even more complicated probability bound that explicitly takes account of the likely change in error of the stratified mean estimate due to the expected change in the sample variance is beyond the scope of our investigation.\n\nThis SEBM method (Algorithm \\ref{alg2}) requires the sample variances of all the strata to be calculated. And accordingly, Algorithm \\ref{alg2} must be initialised with at least two samples from each stratum so that sample variance can be calculated for it to be able to function.\n\nWe also note that Algorithm \\ref{alg2} describes a process specific to the sampling without replacement of all strata, and involves the calculation of the SEBB with the tightest possible use cases of Lemmas \\ref{martingale0} and~\\ref{martingale1}.\nIn particular, for any stratum $i$ that is sampled without replacement, any specific bound with an associated $\\Omega_{m_i}^{n_i}$ and $\\Psi_{m_i}^{n_i}$ may be substituted for $\\bar{\\Omega}_{m_i}^{n_i}$ and $\\bar{\\Psi}_{m_i}^{n_i}$ to potentially tighten the bound, and this corresponds to choice of Lemma~\\ref{martingale0} or Lemma~\\ref{martingale1} in the bound's derivation. \nSince the SEBB is a composition of such bounds with such choices throughout, there is a structure of valid pairs of substitutions $\\Omega,\\Psi$ for $\\bar{\\Omega},\\bar{\\Psi}$ in the optimal calculation of the SEBB, which is shown in the steps 8-15 of Algorithm \\ref{alg2}.\nThe equivalent algorithm for sampling with replacement simply is the same algorithm altered by replacing all use of $\\bar{\\Omega},\\bar{\\Psi}$ with $\\Omega,\\Psi$ respectively.\n\nSimilarly it is elementary to modify the terms of Algorithn \\ref{alg2} to be amenable to be minimising SECB bound (Theorem \\ref{thm:SECM_bound}).\n\n\\begin{algorithm}\n\\caption{Stratified Empirical Bernstein Method (SEBM) algorithm, with replacement}\n\\label{alg2}\n\\begin{algorithmic}[1]\n    \\REQUIRE probability $p$, strata number $N$, stratum sizes $n_i$, initial sample numbers $m_i$, initial stratum sample variances $\\doublehat{\\sigma}_i^2$, weights $\\tau_i$, widths $D_i$, maximum sample budget $B$\n    \\WHILE{$\\sum_i{m_i}<B$}\n        \\STATE $beststrata \\leftarrow -1$\n        \\STATE $lowestbound \\leftarrow \\infty$\n    \t\\FOR{$k=0$ to $N$}\n    \t    \\STATE $m_k \\leftarrow m_k + 1$\n        \t\\STATE $a \\leftarrow [0,0]$, $b \\leftarrow [0,0]$, $c \\leftarrow [0,0]$, $d \\leftarrow [0,0]$\n        \t\\FOR{$i=0$ to $N$}\n        \t\t\\STATE $a_0 \\leftarrow a_0 + \\log(6N/p)D_i^2\\bar{\\Psi}_{m_i}^{n_i}\\min(\\bar{\\Omega}_{m_i}^{n_i},\\Omega_{m_i}^{n_i})\\tau^2$\n        \t\t\\STATE $a_1 \\leftarrow a_1 + \\log(6N/p)D_i^2\\Psi_{m_i}^{n_i}\\min(\\bar{\\Omega}_{m_i}^{n_i},\\Omega_{m_i}^{n_i})\\tau^2$\n        \t\t\\STATE $b_0 \\leftarrow \\max(b_0,\\log(3/p)D_i^2\\bar{\\Psi}_{m_i}^{n_i}\\min(\\bar{\\Psi}_{m_i}^{n_i},\\Psi_{m_i}^{n_i})\\tau^2)$\n        \t\t\\STATE $b_1 \\leftarrow \\max(b_1,\\log(3/p)D_i^2\\Psi_{m_i}^{n_i}\\min(\\bar{\\Psi}_{m_i}^{n_i},\\Psi_{m_i}^{n_i})\\tau^2)$\n        \t\t\\STATE $c_0 \\leftarrow c_0 + 2\\bar{\\Psi}_{m_i}^{n_i}((m_i-1)\\doublehat{\\sigma}_i^2/m_i)\\tau^2$\n        \t\t\\STATE $c_1 \\leftarrow c_1 + 2\\Psi_{m_i}^{n_i}((m_i-1)\\doublehat{\\sigma}_i^2/m_i)\\tau^2$\n        \t\t\\STATE $d_0 \\leftarrow d_0 + \\frac{4}{17}D_i^2\\bar{\\Omega}_{m_i}^{n_i}\\tau^2$\n        \t\t\\STATE $d_1 \\leftarrow d_1 + \\frac{4}{17}D_i^2\\Omega_{m_i}^{n_i}\\tau^2$\n        \t\\ENDFOR\n        \t\\STATE $boundwidth \\leftarrow \\sqrt{\\log(6/p)\\min_j(d_j + (\\sqrt{c_j + a_j + b_j} + \\sqrt{b_j})^2)}$\n    \t    \\IF{$boundwidth < lowestbound$}\n    \t        \\STATE $beststrata \\leftarrow k$\n    \t        \\STATE $lowestbound \\leftarrow boundwidth$\n    \t    \\ENDIF\n    \t    \\STATE $m_k \\leftarrow m_k - 1$\n    \t\\ENDFOR\n    \t\\STATE take an extra sample from strata: $beststrata$\n\t    \\STATE $m_{beststrata} \\leftarrow m_{beststrata} + 1$\n    \t\\STATE recalculate $\\doublehat{\\sigma}_{beststrata}^2$\n    \\ENDWHILE\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\nIn the next section \\ref{section:statistics_results} we will compare how algorithms \\ref{alg3} and \\ref{alg2} work in actually sampling stratified data.\n\n\n\n\n\n\n", "meta": {"hexsha": "1cec273e1fe1d9bd0d74188b00c4973146cb30db", "size": 42157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/Statistics.tex", "max_stars_repo_name": "Markopolo141/Thesis_code", "max_stars_repo_head_hexsha": "df7cffff8127641b0fed0309adf38cfc9372e618", "max_stars_repo_licenses": ["MIT"], "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/Statistics.tex", "max_issues_repo_name": "Markopolo141/Thesis_code", "max_issues_repo_head_hexsha": "df7cffff8127641b0fed0309adf38cfc9372e618", "max_issues_repo_licenses": ["MIT"], "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/Statistics.tex", "max_forks_repo_name": "Markopolo141/Thesis_code", "max_forks_repo_head_hexsha": "df7cffff8127641b0fed0309adf38cfc9372e618", "max_forks_repo_licenses": ["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.9939516129, "max_line_length": 546, "alphanum_fraction": 0.7336385416, "num_tokens": 13429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.6778154764021794}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 23, 2022}\n\\subsection{Chinese Remainder Theorem}\n\\recall (HW2, Q2) asked us to find $x$ with\n\\begin{align*}\n    x & \\equiv 3\\mod 7 \\\\\n    x & \\equiv 4\\mod 9\n\\end{align*}\nWe solved this by setting\n\\begin{align*}\n    x = 7y + 3 & \\equiv 4\\mod 9         \\\\\n    7y         & \\equiv 1\\mod 9\n    \\intertext{and taking $7^{-1}\\pmod{9}$ which is $4$. So we have}\n    y          & \\equiv 4\\mod 9         \\\\\n    x = 7y+3   & \\equiv 31\\text{ works}\n\\end{align*}\n\\begin{theorem}[Chinese Remainder Theorem]\n    Let $\\{m_i\\}$ be a set of pairwise coprime numbers. That is, $\\gcd(m_i, m_j) = 1$ for $i = j$. Then the system\n    \\begin{align*}\n        x & \\equiv a_1\\mod m_1 \\\\\n        x & \\equiv a_2\\mod m_2 \\\\\n          & \\vdots             \\\\\n        x & \\equiv a_n\\mod m_n\n    \\end{align*}\n    has a solution.\n\\end{theorem}\n\\begin{proof}\n    By induction on $n$.\n    \\begin{description}\n        \\item[Base case.] $n = 1$, then we take $x = a_1$ which is a solution.\n        \\item[Mini inductive step.] We first solve for $n=2$. We have\n            \\begin{align*}\n                x & \\equiv a_1\\mod m_1 \\\\\n                x & \\equiv a_2\\mod m_2\n            \\end{align*}\n            Let $u_1\\cdot m_1 + u_2\\cdot m_2 = 1$ (by Bezout's identity). Consider quantity\n            \\begin{align*}\n                u_1m_1a_2 + u_2m_2a_1 & \\equiv 0 + 1\\cdot a_1 \\equiv a_1 \\mod m_1 \\\\\n                                      & \\equiv 1\\cdot a_2 + 0 \\equiv a_2\\mod m_2\n            \\end{align*}\n            which solves for $n=2$.\n        \\item[Full inductive step.] Let $n\\geq 3$, we solve equation\n            \\begin{align*}\n                x & \\equiv a\\mod m_1m_2\\cdots m_{n-1} \\\\\n                x & \\equiv a_{n}\\mod m_{n}\n            \\end{align*}\n            where the solution $a$ from the first equation comes from our inductive hypothesis. We can solve this by our mini inductive step (the $n=2$ case).\n    \\end{description}\n    Which concludes this proof.\n\\end{proof}\n\n\\begin{example}\n    The Chinese Remainder Theorem allows us to solve congruences with composite moduli. For example, solve\n    \\[x^2\\equiv 18 \\mod 21\\]\n    This is equivalent to solving\n    \\begin{align*}\n        x^2 & \\equiv 18 = 0\\mod 3 \\\\\n        x^2 & \\equiv 18 = 4\\mod 7\n    \\end{align*}\n    since $21 = 3\\cdot 7$. So this is equivalent to solving\n    \\begin{align*}\n        x & \\equiv 0\\mod 3     \\\\\n        x & \\equiv \\pm 2\\mod 7\n    \\end{align*}\n    Using CRT, we have\n    \\[1\\cdot 7 + (-2)\\cdot 3 = 1\\]\n    so\n    \\[x = 0\\cdot 1\\cdot 7 + (-2)\\cdot 2\\cdot 2 = -12 \\equiv 9\\mod 21\\]\n    we do check that $9^2 = 81\\equiv 18\\mod 21$.\n\\end{example}\n\nIn general, we claim that square roots mod $p$ are easy to compute.\n\\begin{proposition}\n    Let $p\\equiv 3\\mod 4$ and $a$ is a square in $\\ZZ/p\\ZZ$ (that is, $x^2\\equiv a$ has a solution).\n\n    Then\n    \\[x\\equiv a^{\\frac{p+1}{4}}\\]\n    is a solution.\n\\end{proposition}\n\\begin{proof}\n    Say $a\\equiv b^2\\mod p$. Then\n    \\[(a^{\\frac{p+1}{4}})^2 = a^{\\frac{p+1}{2}}\\equiv (b^2)^{\\frac{p+1}{2}}\\equiv b^{p+1} \\equiv b^{p-1}\\cdot b^2\\equiv 1\\cdot b^2 = b^2 \\equiv a\\mod p\\]\n    which concludes the proof.\n\\end{proof}\nSo we can compute square roots modulo a composite number $N$ by taking the prime factor decomposition of $N$, and taking the square root mod each factor, then using CRT.\n\nConversely, any efficient algorithm to find square roots mod $N$ can be used to factor $N$.\n\n\\emph{Why?}\n\\begin{enumerate}[1.]\n    \\item We generate an element $x$ mod $N$.\n    \\item Ask for square root of $x^2$.\n    \\item Good chance that we get $y\\not\\equiv \\pm x$.\n          We now have\n          \\begin{align*}\n              x^2        & \\equiv y^2\\mod N \\\\\n              (x+y)(x-y) & \\equiv 0\\mod N\n          \\end{align*}\n    \\item We can now calculate $\\gcd(x+y, N)$ and find some factors of $N$.\n\\end{enumerate}\n\n\\subsection{Euler's Theorem}\n\\recall Fermat's Little Theorem which says that\n\\begin{align*}\n    a^{p-1} & \\equiv 1\\mod p\\quad \\text{ for }p\\nmid a\n    \\intertext{What happens when we replace $p$ with $N$ where $N$ is composite?}\n    a^{N-1} & \\overset{?}{\\equiv}1\\mod N\\quad \\text{ for }\\gcd(N,a)=1\n\\end{align*}\nNo! Recall demo showing counterexample.\n\n\\begin{proposition}\n    If $N = pq$ for primes $p$ and $q$, then\n    \\[a^{(p-1)(q-1)}\\equiv 1\\mod N\\quad\\text{ for }\\gcd(N, a) = 1\\]\n\\end{proposition}\n\\begin{proof}\n    \\textsc{wlog} taking mod $p$, we have\n    \\[a^{(p-1)(q-1)}\\equiv (a^{p-1})^{q-1}\\equiv 1^{q-1}\\equiv 1\\mod p\\]\n    Similarly mod $q$ by symmetry. Then it is congruent to $1\\mod pq$.\n\\end{proof}\n\nWe can generalize this...\n\\begin{proposition}[Euler's Theorem]\n    For any composite $N$, we have\n    \\[a^{\\varphi(N)}\\equiv 1\\mod N\\quad\\text{ for }\\gcd(N, a) = 1\\]\n\\end{proposition}\n\n\\subsection{Exponentiation}\nGiven an exponent $x$, we can compute $e^x$ fast. Inverting this gives us the \\emph{Discrete Log Problem}. Diffie-Hellman Key Exchange and Elgamal rely on this.\n\nWhat if we think of this as a function of the base? Given a base $x$, we want to take it to exponent $e$ to get $x^e$. Inverting this is the \\emph{Extracting Roots} problem. This is the basis of the RSA cryptosystem (see next time!).\n\n\\begin{claim*}\n    Let $\\gcd(e, p-1) = 1$. We can construct $de\\equiv 1 \\mod p-1$. Then $(x^e)^d\\equiv x$.\n\\end{claim*}\n\nSo \\emph{extracting roots} is easy mod prime $p$, but hard mod composites. We'll see this next time. ", "meta": {"hexsha": "2ad78f33d81c1cc9a74332c8758b09e7636f8ef0", "size": 5403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-23.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-02-23.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-02-23.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": 39.7279411765, "max_line_length": 233, "alphanum_fraction": 0.5918933926, "num_tokens": 1913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6777944300924333}}
{"text": "\\chapter{Hamiltonian Equation of Motion}\n Hamiltonian method providing a framework for theoretical basis for further developments like Hamiltonian Jacobi theory, perturbation approaches and chaos. Outside classical mechanics Hamiltonian formulation provides much of the language with which present-day statistical mechanics and quantum mechanics is constructed. Throughout the chapter we are assuming mechanical systems are holonomic and the forces are monogenic.\n \\begin{itemize}\n \t\\item In Hamiltonian formulation there can be no constraint equation among the coordinates.\n \t\\item If $n$ coordinates are not independent, a reduced set of $m$ coordinates, with $m<n$, must be used for the formulation of the problem\n \\end{itemize}\n\\section{Hamiltonian Formulation}\n\\begin{itemize}\n\t\\item Describe the motion in terms of first order equations of motion\n\t\\item Number of initial conditions determining the motion are stil be $2n$\n\t\\item $2n$ independent first order equations expressed in terms of $2n$ independent variables\n\t\\item $2n$ equations of motion describe behavior of the system point in a phase space\n\t\\item Out of $2n$ independent quantities half of them are $n$ generalized coordinates and other half set to be the generalized or conjugate momenta $p_i$\n\t\\begin{equation}\n\t  p_i=\\frac{\\partial L(q_j,\\dot{q}_j, t)}{\\partial \\dot{q}_j}\n\t\\end{equation}\n\twhere $j$ index shows the set of $q$'s and $\\dot{q}$'s\n\t\\item The quantities $(p,q)$ are known as the canonical variables\n\\end{itemize}\n\\section{Legendre Transformation}\nConsider a function of only two variables $f(x,y)$ so that a differential of $f$ has the form\n$$df=udx+vdy$$\nwhere\n$$u=\\frac{\\partial f}{dx},\\quad v=\\frac{\\partial f}{dy}$$\nTo change the basis of description from $x,y$ to a new distinct set of variables $u,y$ so that differential quantities are expressed in terms of $du$ and $dy$\n\\begin{align*}\n\\intertext{Let $g$ be a function $u$ and $y$ defined by the equation}\ng&=f-ux\n\\intertext{A differential of $g$ is then given as}\ndg&=df-udx-xdu\n\\intertext{or}\ndg&=vdy-xdu\n\\intertext{and we get}\nx=\\frac{-\\partial g}{\\partial u},&\\quad v=\\frac{\\partial g}{\\partial y}\n\\end{align*}\n\\section{Hamilton Equation of Motion}\nMathematically the transition from Lagrangian to Hamiltonian formulation corresponds to changing the variables in our mechanical functions from $(q, \\dot{q}_j,t)$ to $(q,p,t)$ when $p$ is related to $q$ and $\\dot{q}$ by\n$$p_i=\\frac{\\partial L(q_j,\\dot{q}_j,t)}{\\partial \\dot{q}_i}$$\nThe proceedure for switching variables in this manner is provided by the 'Legendre  transformation'.\n\\begin{align}\n\\text{Consider Lagrangian }&\\ L(q,\\dot{q},t)\\ \\text{ then}\\notag\\\\\ndL=\\frac{\\partial L}{\\partial q_i}dq_i&+\\frac{\\partial L}{\\partial \\dot{q}_1}+\\frac{\\partial L}{\\partial t}dt\\\\\n\\text{The canonical }&\\text{momentum  was defined as }p_i=\\frac{\\partial L}{\\partial \\dot{q}_i}\\notag\\\\\n\\text{Substituting it in }&\\text{Lagrange equation we obtain}\n\\dot{p}_i=\\frac{\\partial L}{\\partial {q}_i}\\notag\\\\\n\\therefore dL&=\\dot{p}_idq_i+p_id\\dot{q}_i+\\frac{\\partial L}{\\partial t}dt\n\\intertext{The Hamiltonian $H(q,p,t)$ is generated by the Legendre transformation}\nH(q,p,t)&=\\dot{q}_ip_i-L(q,\\dot{q},t)\n\\intertext{and has the differential}\ndH&=\\dot{q}_1dp_i-\\dot{p}_1dq_1-\\frac{\\partial L}{\\partial t}dt\n\\intertext{Where the term $p_id\\dot{q}_i$ removed by Legendre transformation since $dH$ can also written as }\ndH&=\\frac{\\partial H}{\\partial q_i}dq_1+\\frac{\\partial H}{\\partial p_i}dp_i+\\frac{\\partial H}{dt}dt\n\\intertext{We obtain $2n+1$ relations}\n&\\left.\\begin{array}{rl}\\dot{q}_{i} & =\\frac{\\partial H}{\\partial p_{i}} \\label{HM-07}\\\\\\\\ -\\dot{p}_{i} & =\\frac{\\partial H}{\\partial q_{i}}\\end{array}\\right\\}\\\\\\notag\\\\\n&-\\frac{\\partial L}{\\partial t}=\\frac{\\partial H}{\\partial t}\\notag\n\\end{align}\nEquation $\\ref{HM-07}$ are known as the canonical equations of Hamiltonian\n\\section{Steps to construct Hamiltonian}\nHamiltonian for each problem must be constructed via the Lagrangian formulation.\n\\begin{enumerate}\n\t\\item With chosen set of generalized coordinates, $q_i$ the Lagrangian $L(\\dot{q},\\dot{q}_i,t)$=T-V is constructed\n\t\\item The conjugate momenta are defined as function of $q_i,\\dot{q}_i$ and $t$ by equation\n\t$$p_i=\\frac{\\partial L}{\\partial \\dot{q}_i}$$\n\t\\item Legendre transformation used to form the Hamiltonian. At this stage we have some mixed functions of $q_i,\\dot{q}_i,p_i$ and $t$\n\t\\item $p_i=\\frac{\\partial L}{\\partial \\dot{q}_i}$ then converted to obtain $\\dot{q}_i$ as functions of $(q,p,t)\\ (ie\\quad \\dot{q}_i=\\frac{\\partial H}{\\partial p_i})$\n\t\\item The result of the previous steps are then applied to eliminate $\\dot{q}_i$ from $H$ so to express it solely as a function of $(q,p,t)$\n\\end{enumerate}\n\\begin{note}\n\tIn many problems Lagrangian is the sum of functions each homogeneous in the generalized velocities of degree $0,1$ and $2$ respectively in that are\n\t$$ H=\\dot{q}_1p_i-L=\\dot{q}_ip-[L_0(q,t)+L_i(q,t)\\dot{q}_k+L_1(q_i,t)\\dot{q}_k\\dot{q}_m]$$\n\tIf equations defining generalized coordinates don't depend on time then $L_2 \\dot{q}_k\\dot{q}_m=T(K.E)$\\\\\n\tIf forces are derivable from a consevative potential $V$ (ie work is independent of path), then $L_0=-V$\n\tWhen both there conditions are satisfied the Hamiltonian is automatically the total energy\n\t$$H=T+V=\n\tE$$\n\\end{note}\n\\begin{exercise}\n\tA particle of inass $m$ moves inside a bowl under gravity. If the surface of the bowl is given by the equation $z=\\frac{1}{2} a\\left(x^{2}+y^{2}\\right)$, where $a$ is a constant.\\\\\n\t(A) Write down Lagrangian of the system in cylindrical co-ordinate.\\\\\n\t(a) Identified the cyclic coordinate and law of conservation of momentum.\\\\\n\t(b) Write down hamiltonion of the system in cylindrical coordinate system.\n\\end{exercise}\n\t\\begin{answer}\n\t\\begin{align*}\n\t\\text{(A) }T&=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+\\dot{z}^{2}\\right)=\\frac{m}{2}\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+a^{2} r^{2} \\dot{r}^{2}\\right) \\quad \\because z=\\frac{1}{2} a r^{2} \\Rightarrow \\quad \\dot{z}=a r \\dot{r}\\\\\n\tV&=m g z=\\frac{1}{2} m g a r^{2} \\\\\n\tL&=\\frac{m}{2}\\left[\\dot{r}^{2}\\left(1+a^{2} r^{2}\\right)+r^{2} \\dot{\\theta}^{2}-a g r^{2}\\right]\n\t\\intertext{\t(a) $\\theta$ is cyclic coordinate}\n\t\\because \\frac{\\partial L}{\\partial \\theta}&=0, \\Rightarrow \\dot{p}_{\\theta}=0 \\Rightarrow P_{\\theta}=\\text{ constant}\n\t\\intertext{(b) Hamiltonian}\n\tH&=\\frac{p_{r}^{2}}{2 m\\left(1+a^{2} r^{2}\\right)}+\\frac{p_{\\theta}^{2}}{2 m r^{2}}+\\frac{1}{2} m a g r^{2} \\quad \\\\&\\because \\frac{\\partial L}{\\partial \\dot{r}}=p_{r}=m\\left(1+a^{2} r^{2}\\right) \\dot{r}\\text{ and }\\frac{\\partial L}{\\partial \\dot{\\theta}}=p_{\\theta}=m r^{2} \\dot{\\theta}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tA particle of mass $m$ is attached to fixed point $O$ by a weightless inextensible string of length $a$. It is rotating under the gravity as shown in the figure.\\\\\n\t(a) Write down The Lagrangian of the system in spherical co-ordinate.\\\\\n\t(b) write down Hamiltonian of the system.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=3.5cm]{Assignment-HE-02}\n\t\\end{figure}\n\\end{exercise}\n\t\\begin{answer}\n\t\\begin{align*}\n\tL&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)-[m g(-z)]\\\\\n\tL&=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}^{2}+a^{2} \\sin ^{2} \\theta \\dot{\\phi}^{2}\\right)+m g a \\cos (\\pi-\\theta)\\\\\n\tL&=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}^{2}+a^{2} \\sin ^{2} \\theta \\dot{\\phi}^{2}\\right)-m g a \\cos (\\theta)\\\\\n\tH&=\\sum \\dot{q}_{1} p_{1}-L\\\\\n\tH&=\\frac{p_{\\theta}^{2}}{2 m a^{2}}+\\frac{p_{\\phi}^{2}}{2 m a^{2} \\sin ^{2} \\theta}+m a g \\cos \\theta \\because \\frac{\\partial L}{\\partial \\dot{\\theta}}=p_{\\theta}=m a^{2} \\dot{\\theta}\\text{ and } \\frac{\\partial L}{\\partial \\dot{\\phi}}=p_{\\phi}=m a^{2} \\sin ^{2} \\theta \\dot{\\phi}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tParticle of mass $m$ slides under the gravity without friction along the parabotic path\n\t$y=a x^{2}$ axis shown in the figure. Here $a$ is a constant\\\\\n\t(a) Write down Lagrangian of the system .\\\\\n\t(b) Write down Lagranges equation of motion.\\\\\n\t(c) write down Hamiltonian of the system.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=4cm]{Assignment-HE-03}\n\t\\end{figure}\n\\end{exercise}\n\t\\begin{answer}\n\t\\begin{align*}\n\ty&=a x^{2}\\\\\n\t\\text{(a) }\\dot{y}&=2 a x \\dot{x}\\\\\n\tL&=\\frac{m}{2}\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)-m g y=\\frac{m}{2}\\left(\\dot{x}^{2}+4 a^{2} x^{2} \\dot{x}^{2}\\right)-m g a x^{2}\\\\\n\tL&=\\frac{m}{2}\\left(1+4 a^{2} x^{2}\\right) \\dot{x}^{2}-m g a x^{2}\\\\\n\t\\text{\t(b) }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)-\\frac{\\partial L}{\\partial x}=0\\\\\n\t\\frac{d}{d t}&\\left[m\\left(1+4 a^{2} x^{2}\\right) \\dot{x}\\right]-\\left[4 m a^{2} \\dot{x}^{2} x-2 \\mathrm{~m} g\\right.\\text{ a }\\left.x\\right]=0\\\\\n\tm \\ddot{x}&+4 m a^{2} \\ddot{x} x^{2}+8 m a^{2} \\dot{x} x \\dot{x}-4 m a^{2} \\dot{x}^{2} x+2 m g a x=0\\\\\n\tm \\ddot{x}&+4 m a^{2} x^{2} \\ddot{x}+4 m a^{2} x \\dot{x}^{2}+2 m g a x=0\\\\\n\t\\text{(c) }H&=\\sum \\dot{x} p_{x}-L\\\\\n\tH&=\\frac{p_{x}^{2}}{2 m\\left(1+4 a^{2} x^{2}\\right)}+m g a x^{2} \\quad \\because \\frac{\\partial L}{\\partial \\dot{x}}=p_{x}=m\\left(1+4 a^{2} x^{2}\\right) \\dot{x}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tThe Lagrangian of a particle of mass $m$ moving in one dimension is $L=\\exp (\\alpha t)\\left[\\frac{m \\dot{x}^{2}}{2}-\\frac{k x^{2}}{2}\\right]$, where $\\alpha$ and $k$ are positive constants.\\\\\n\t(a) Find the Lagranges equation of motion of the particle.\\\\\n\t(b) Write down Hamiltonian of the system.\n\\end{exercise}\n\t\\begin{answer}\n\t\\begin{align*}\n\tL&=e^{\\alpha t}\\left(\\frac{m \\dot{x}^{2}}{2}-\\frac{k x^{2}}{2}\\right)\\\\\n\t\\text{(a) }\\frac{d}{d t}\\left(e^{\\alpha t} m \\dot{x}\\right)-e^{\\alpha t} k x&=0 \\Rightarrow e^{\\alpha t} m \\ddot{x}+m \\dot{x} e^{\\alpha t} \\cdot \\alpha-e^{\\alpha t} k x=0 \\Rightarrow e^{\\alpha t}[m \\ddot{x}+\\alpha m \\dot{x}-k x]=0\\\\\n\t\\text{(b) }H&=e^{-\\alpha t} \\frac{p_{x}^{2}}{2 m}+e^{\\alpha t} \\frac{k x^{2}}{2}\n\t\\because \\frac{\\partial L}{\\partial \\dot{x}}=p_{x}=e^{\\alpha t} m \\dot{x}\n\t\\end{align*}\n\\end{answer}\n\\section{Cyclic Coordinate and Conservation Theorem}\nIf $q_j$ a cyclic coordinate then, its conjugate momentum $p_j$ is constant.\\\\\nFrom Lagrangian and Hamiltonian equations of motions:\n$$\\dot{p}_{j}=\\frac{\\partial L}{\\partial q_{j}}=-\\frac{\\partial H}{\\partial q j}$$\n$\\therefore$ coordinate that is cyclic will thus also be absent from the Hamiltonian. Conversely if a generalized coordinate does not occur in $H$ the conjugate momentum is conserved.\n\\begin{itemize}\n\t\\item If $L$ is not explicit function of $t$ then $H$ is a constant of motion \n\t\\begin{align*}\n\t\\frac{d H}{d t}&=\\frac{\\partial H}{\\partial q_{i}} \\dot{q}_{i}+\\frac{\\partial H}{\\partial p_{i}} \\dot{p}_{i}+\\frac{\\partial H}{\\partial t}\\\\\\text{substituting }\\quad\\frac{\\partial H}{\\partial q_{i}} &=-\\dot{p}_{i}\\quad\\text{ and }\\quad\\frac{\\partial H}{\\partial p_{i}} =\\dot{q}_{i}\\quad\\text{we get}\\\\\n\t\\frac{d H}{d t}&=\\frac{\\partial H}{\\partial t}=\\frac{-\\partial L}{\\partial t}\n\t\\end{align*}\n\tTherefore if $t$ doesn't appear explicity in $L$, it will also not be present in $H$ and $H$ will be constant in time\n\t\\item If the equations of transformations that define the generalized coordinates\n\t\\begin{equation}\n\tr_m=r_m(q_1,....q_n,t)\\label{HE-02}\n\t\\end{equation}\n\tdo not depend explicity upon the time, and if potantial is velocity independent then $H$ is the total energy $H=T+V$\n\t\\item The identification of $H$ as a constant of motion and as the total energy are two seperate matters. If equation \\ref{HE-02} involve time explicity but $H$ doesnot, then $H$ is constant of motion but it is not the total energy.\n\t\\item Unlike $L$, using different set of generalized coordinates in the definition of $H$ may leads to an entirely different quantity for Hamiltonian. It may be that for one set of generalized coordinates $H$ is conserved, but that for another it varies in time.\n\t\\item Explicity first order equations in the $2^{\\text{nd}}$ dynamical variables\n\t\\begin{align*}\n\t\\text{If }H&=H(q,p)\\text{, ray(autonomous)}\\\\\n\t\\frac{dH}{dt}&=\\frac{\\partial H}{\\partial q}\\dot{q} +\\frac{\\partial H}{\\partial p}\\dot{p}\\\\\n\t&=\\frac{\\partial H}{\\partial q}\\frac{\\partial H}{\\partial p}-\\frac{\\partial H}{\\partial p}\\frac{\\partial H}{\\partial q}=0\\\\\n\t\\end{align*}\n\tHamiltonian is a constant of motion as long as it is not explicity dependent on time.\\\\\n\tHniltonian governs the time evolution of a system so we call it infinitesimal generator of time translations\n\\end{itemize}\n\\section{Other Constants of Motion}\n\\begin{align*}\n\\intertext{Suppose $F$ is a constant of motion}\nF&=F(q,p,t), \\text{it could be explicity time dependent}\\\\\n\\frac{dF}{dt}&=\\frac{\\partial F}{\\partial q}\\dot{q}+\\frac{\\partial F}{\\partial p}\\dot{p}+\\frac{\\partial F}{\\partial t}\\\\\n\\frac{dF}{dt}&=\\frac{\\partial F}{\\partial q}\\frac{\\partial H}{\\partial p}-\\frac{\\partial F}{\\partial p}\\frac{\\partial H}{\\partial q}+\\frac{\\partial F}{\\partial t}\n\\intertext{for $n$ degrees of freedom}\n\\frac{dF}{dt}&=\\sum\\limits_{i=1}^{n}\\left( \\frac{\\partial F}{\\partial q_i}  \\frac{\\partial H}{\\partial p_i}-\\frac{\\partial F}{\\partial p_i}  \\frac{\\partial H}{\\partial q_i} \\right)+\\frac{dF}{dt}\n\\intertext{This constructed out of 2 functions of $F$ and $H$ is called the poisson bracket of $F$ with $H$}\n\\frac{dF}{dt}&\\equiv \\underset{poisson bracket}{\\left\\lbrace F,H\\right\\rbrace }+ \\frac{\\partial F}{\\partial t}\n\\end{align*}\nIt plays the same role in classical mechanics as the commutators of matrices or operators would in quantum mechanics \\\\\n$F$ is a constant of motion if $\\frac{dF}{dt}$ vanishes identically\\\\\n$F$= constant of motion if and only if\n$$\\left\\lbrace F,H\\right\\rbrace +\\frac{\\partial F}{\\partial t}=0$$\nit's poisson commute with $H$ or to say $F$ and $H$ are said to be in involution with each other. Where the Hamiltonian itself is a constant of motion for autonomous systems.\n\\section{Poisson Bracket}\nYou could define poisson bracket of any two functions of phase variables \n$$\\left\\lbrace A,B\\right\\rbrace =\\frac{\\partial A}{\\partial \\dot{q}}\\ \\frac{\\partial B}{\\partial p}-\\frac{\\partial A}{\\partial p}\\ \\frac{\\partial B}{\\partial q}$$\n\\begin{itemize}\n\t\\item $\\left\\lbrace A,B\\right\\rbrace =-\\left\\lbrace B,A\\right\\rbrace $ \\quad (antisymmetry)\\\\\n\t\\item $\\left\\lbrace A+B,C\\right\\rbrace =\\left\\lbrace A,C\\right\\rbrace +\\left\\lbrace B,C\\right\\rbrace $\n\t\\item $\\left\\lbrace \\alpha \\ A,B\\right\\rbrace =\\alpha\\left\\lbrace A,B\\right\\rbrace $\n\t\\item $\\left\\lbrace A,B C\\right\\rbrace=B\\left\\lbrace A,C \\right\\rbrace+\\left\\lbrace A,B\\right\\rbrace C  $ (follow the order)\n\\end{itemize}\nThis is the way you could find poisson brackets of various complicated functions of the phase space variable given a few elementary poisson brackets \n$$\\left\\lbrace A ,\\left\\lbrace B,C \\right\\rbrace \\right\\rbrace +\\left\\lbrace B ,\\left\\lbrace C,A \\right\\rbrace \\right\\rbrace +\\left\\lbrace C,\\left\\lbrace A,B \\right\\rbrace \\right\\rbrace =0$$\n\\section{Conjugate Momentum}\nWe have independent variable $(q_i...q_N,p_i...p_N)$\n\\begin{align*}\n\\left\\lbrace q_k,q_l\\right\\rbrace &=\\sum\\limits_{i-1}^{n}\\left(\\frac{\\partial q_k}{\\partial q_i}\\ \\frac{\\partial q_l}{\\partial p_i}-\\frac{\\partial q_k}{\\partial p_i}\\ \\frac{\\partial q_l}{\\partial q_i}\\right)=0 \\text{Since $p$ and $q$ are independent}\\\\\n\\left\\lbrace p_k,p_l\\right\\rbrace  &=0  \\\\\n\\left\\lbrace q_k,p_l\\right\\rbrace  &=\\sum\\limits_{i-1}^{n}\\left(\\frac{\\partial q_k}{\\partial q_i}\\ \\frac{\\partial p_l}{\\partial p_i}-\\frac{\\partial q_k}{\\partial p_i}\\ \\frac{\\partial p_l}{\\partial q_i}\\right)\\\\\n\\left\\lbrace q_k,p_l\\right\\rbrace  &=\\sum\\limits_{i}\\delta_{ik}\\delta_{il}=\\delta_{kl}\n\\end{align*}\n\\textbf{Canonical Poisson Bracket Relations}\\\\\n${q_k,p_l}=\\delta_{kl}$\\\\\n${q_k,q_l}=0$\\\\\n${p_k,p_l}=0$\\\\\nonce there relations are satisfied\\\\\nmomentum $P_K$ is conjugate to the generalized coordinates $q_k (q_k,p_k)$ form conjugate pair\\\\\nfor the poisson commutes with all other $p's$ except it's conjugate ${q_k,p_k}=1$\n\n\n\n\n\n\n", "meta": {"hexsha": "e7ee9ab9a1f6b95f7744da9773de11eb97917a49", "size": 15899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/Hamiltonian Equation of Motion.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/Hamiltonian Equation of Motion.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/Hamiltonian Equation of Motion.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": 70.3495575221, "max_line_length": 422, "alphanum_fraction": 0.6889112523, "num_tokens": 5498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764119, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.6777944277617022}}
{"text": "% !TEX TS-program = pdflatexmk\n\\documentclass{article}\n\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage[a4paper, total={6in, 8in}]{geometry}\n\\usepackage{amsthm}\n\\usepackage{natbib}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\title{Completely Random Measure}\n\\date{\\today}\n\\author{Dongwoo Kim\\\\ANU}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Poisson Process}\n\\label{sec:pp}\nLet $(S, \\mathcal{S})$ be a measurable space and $\\Pi$ be a random countable collection of points on $S$. Let  counting process $N(A) = |\\Pi \\cap A|$ for any measurable set $A$. $\\Pi$ is a Poisson process if $N(A)$ and $N(B)$ are independent for every measurable disjoint sets $A$ and $B$ and $N(A)$ is Poisson distributed with mean $\\mu(A)$ for a $\\sigma$-finite measure $\\mu$ (also called mean measure).\n\nLet $f$ be a measurable function from $S$ to $\\mathbb{R}$, then by the Campbell's theorem \\citep{kingman1993poisson} $\\sum_{x\\in \\Pi} f(x)$ is absolutely convergent with probability one if and only if\n\\begin{align}\n\\int_{S} \\min(|f(x), 1|)\\mu(dx) < \\infty.\n\\end{align}\nThe Laplace functional of Poisson process for any $f \\ge 0$ is then\n\\begin{align}\n\\mathbb{E}_{\\Pi}[e^{-\\sum_{x \\in \\Pi}f(x)}] = \\exp \\Bigg\\{ - \\int_{S} (1-e^{-f(x)})\\mu(dx) \\Bigg\\}.\n\\end{align}\n\n\\section{Completely Random Measure}\nLet $(\\Omega, \\mathcal{F}, \\mathbb{P})$ be some probability space, $(M(S), \\mathcal{B})$ be the space of all $\\sigma$-finite measures on $(S, \\mathcal{S})$. A completely random measure (CRM) $\\Lambda$ on $(S, \\mathcal{S})$ is a measurable function from $\\Omega$ to $M(S)$ \\footnote{This corresponds to a measure-theoretic definition of a random variable. So one can define a probability over a set random measures $\\mathbb{P}(\\Lambda^{-1}(A))$ where $A \\in \\mathcal{B}$. However, in the rest of the paper, we use $\\Lambda(A)$ as a measure on $S$ where $A \\in \\mathcal{S}$.} such that\n\\begin{enumerate}\n\\item $\\mathbb{P}(\\Lambda(\\emptyset) = 0)$\n\\item For any disjoint countable collection of sets $A_i$, the random variable $\\Lambda(A_i)$ are independent, and $\\Lambda(\\cup A_i) = \\sum_i \\Lambda(A_i)$ a.s. (also known as independent increments)\n\\end{enumerate}\nCRMs with random masses at random locations can be represented as $\\Lambda = \\sum_{i=1}^{\\infty} w_i \\delta_{x_i}$ where $x_i$ is a location and $w_i$ is a mass on that location.\n\n\\subsection{Completely Random Measure and Poisson Process}\nThe most important characteristic of CRM is its relation to the Poisson process. For any CRM $\\Lambda$ on $(S, \\mathcal{S})$ without any deterministic component, there is a corresponding Poisson Process $\\Pi$ on $(\\mathbb{R}_+ \\times S, \\mathcal{B}_{\\mathbb{R}_+} \\times \\mathcal{S})$\\footnote{Unlike Section \\ref{sec:pp}, now the Poisson process is on the product space where each point corresponds to a pair $(w, x)$} such that\n\\begin{align}\n\\Lambda(A) = \\sum_{(w, x) \\in \\Pi}w \\mathbf{1}_{[x \\in A]} = \\int_{\\mathbf{R}\\times A} w \\Pi(dw, dx).\n\\end{align}\nLet $\\nu(dw, dx)$ be a mean measure of Poisson Process $\\Pi$, From the Campbell's theorem, one can easily derive the Laplace transform of $\\Lambda(A)$ in $t\\ge 0$ for a measurable set $A$:\n\\begin{align}\n\\mathbb{E}_\\Lambda[e^{-t\\Lambda(A)}] &= \\mathbb{E}_{\\Pi}[e^{-t \\int_{\\mathbf{R}\\times A} w \\Pi(dw, dx) }] \\\\\n& = \\exp\\Bigg( - \\int_{\\mathbb{R}_+ \\times A} (1- e^{-tw}) \\nu(dw,dx) \\Bigg),\n\\end{align}\nwhich is derived from Laplace functional of Poison process where $f(w, x) = tw$.\nIf the mean measure $\\nu(dw, dx) = \\rho(dw)H_0(dx)$ where $\\rho$ and $H_0$ is both $\\sigma$-finite measures, then $\\Lambda$ is known as homogeneous CRM, or if $\\nu(dw, dx) = \\rho(dw|dx)H_0(dx)$ then this is non-homogeneous CRM which implies that the masses $(w_i)$ of atoms in $\\Lambda$ are dependent on the locations. In homogeneous case, the masses are independent of the locations and are distributed according to a Poisson process over $\\mathbb{R}_+$ with mean intensity $\\rho$, while the locations are i.i.d. from $H_0$. In practice, $H_0$ is usually referred as a base distribution (or base measure) which has some parametric probability density on $S$ (e.g. Gaussian distribution on $\\mathbb{R}$).\n\nBy using some known properties about Poisson process, we can also deduce some known properties of CRM. For example, the expected number of points on $\\mathbb{R}_+ \\times S$ is computed as\n\\begin{align}\n\\mathbb{E}_\\Pi[\\Pi(\\mathbb{R}_+ \\times S)] = \\int_{\\mathbb{R}_+ \\times S} \\nu(dw,dx).\n\\end{align}\nSometimes (in most of the useful cases), the expected number of points might be diverge (i.e. $\\mathbb{E}[\\Pi(\\mathbb{R}_+ \\times S)] = \\infty$, a.s.), however, even in this case the total mass of CRM $\\Lambda(S)$ could be positive and finite with probability one if the following condition is satisfied\\footnote{This condition is from the Laplace transform of $\\lambda(S)$ where $t=1$ so that the exponent of Laplace transform does not diverge.}:\n\\begin{align}\n\\int_{\\mathbb{R}_+ \\times A} (1- e^{-w}) \\rho(dw)H_0(S) < \\infty.\n\\end{align}\nIf the above two conditions are satisfied, then $\\Lambda$ has an infinite number of atoms (again, which corresponds to the expected number of points). This property is also important to construct a normalised random measure (NRM); since the total mass of CRM is positive and finite almost surely, one can construct a NRM through the normalisation of CRM.\n\n\\section{Special Case}\nCRM shows different characteristics based on the choice of intensity on weights $\\rho(dw)$. \n\n\\subsection{Generalised Gamma Process}\nThe L\\'{e}vy intensity measure $\\rho$ of the generalised Gamma process (GGP) is\n\\begin{align}\n\\rho_{\\alpha, \\sigma, \\tau}(dw) = \\frac{\\alpha}{\\Gamma(1-\\sigma)}w^{-\\sigma - 1}e^{-\\tau w} dw\n\\end{align}\nGGP encompasses several well-known processes based on the different configuration on parameter $\\sigma$ and $\\tau$: \n\\begin{itemize}\n\\item Finite activity case: $\\int_w \\rho_{\\alpha, \\sigma, \\tau}(dw) < \\infty$\n\\begin{itemize}\n\\item $(\\sigma \\le 0, \\tau > 0)$: weights $w_i$ are i.i.d. from Gamma($-\\sigma$,$\\tau$).\n\\end{itemize}\n\\item Infinite activity case : $\\int_w \\rho_{\\alpha, \\sigma, \\tau}(dw) = \\infty$\n\\begin{itemize}\n\\item $(\\sigma = 0, \\tau > 0)$: the Gamma process. Normalised Gamma process = Dirichlet process.\n\\item $(\\sigma = \\frac{1}{2}, \\tau > 0)$: the inverse-Gaussian process.\n\\item $(\\sigma \\in (0, 1), \\tau = 0)$: the stable process \n\\end{itemize}\n\\end{itemize}\n\n\\textbf{Sum of weights from GGP}: As we saw in the previous section, for some intensity measure, the total mass $\\Lambda(S)$ is finite a.s. If we consider $\\Lambda(S)$ as a random variable, then the Laplace transform of the variable is\n\\begin{align}\n\\mathbb{E}[e^{-t\\Lambda(S)}] = \\exp\\bigg\\{-\\int_{\\mathbb{R}_+} (1- e^{-tw}) \\rho_{\\alpha, \\sigma, \\tau}(dw) \\bigg\\} = \\exp\\bigg\\{-\\frac{\\alpha}{\\sigma}\\big((t+\\tau)^\\sigma - \\tau^\\sigma\\big)\\bigg\\},\n\\end{align}\nwhich corresponds to the Laplace transform of the exponentially tilted stable distribution where the exact sampler exists \\citep{devroye2009random,hofert2011sampling}. Taking the derivative of $t$ and set $t=0$ shows the expected sum of weights is $\\alpha \\tau^{\\sigma-1}$.\n\n\\subsubsection{Gamma Process}\nIf $\\sigma = 0$, then the GGP will be the Gamma process of which normalisation is well known Dirichlet process.\n\nThe expected number of partitions $\\mathbb{E}[N_k] = \\sum_{i=1}^{n} \\frac{\\alpha}{\\alpha + i - 1} = \\alpha (\\Psi(\\alpha + n) - \\Psi(\\alpha)) = O(\\alpha \\log n)$, where $\\Psi$ is a digamma function.\n\n\\subsection{Beta Process}\n\\begin{align}\n\\nu(dw, dx) = \\alpha w^{-1}(1-w)^{\\alpha-1} dw H_0(dx)\n\\end{align}\n\n\\section{Auxiliary}\n\\begin{itemize}\n\\item Stirling's approximation $\\Gamma(n+1) \\approx \\sqrt{2\\pi n}(n/e)^{n}$\n\\end{itemize}\n\n\n\\bibliographystyle{apalike}\n\\bibliography{ref}\n\n\\end{document}\n", "meta": {"hexsha": "a518a5ed77e31627a587ffc505e51e29f8f3943c", "size": 7843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/completely_random_measure/crm.tex", "max_stars_repo_name": "arongdari/sparse-graph-prior", "max_stars_repo_head_hexsha": "01bbe59d356b24e9967851d3ab5d7195c3bcd790", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-12-08T19:04:31.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-08T19:04:31.000Z", "max_issues_repo_path": "notes/completely_random_measure/crm.tex", "max_issues_repo_name": "dongwookim-ml/sparse-graph-prior", "max_issues_repo_head_hexsha": "01bbe59d356b24e9967851d3ab5d7195c3bcd790", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-07-10T05:20:44.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-10T05:20:44.000Z", "max_forks_repo_path": "notes/completely_random_measure/crm.tex", "max_forks_repo_name": "dongwookim-ml/sparse-graph-prior", "max_forks_repo_head_hexsha": "01bbe59d356b24e9967851d3ab5d7195c3bcd790", "max_forks_repo_licenses": ["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.2, "max_line_length": 704, "alphanum_fraction": 0.7052148413, "num_tokens": 2459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6777192313569089}}
{"text": "\\documentclass{article}\n\n\\usepackage{cite}\n\\usepackage{amsmath,amssymb,amsfonts}\n\\usepackage{algorithm}\n\\usepackage{booktabs}\n\\usepackage{algorithmic}\n\\usepackage{graphicx}\n\\usepackage[font=small]{caption}\n%\\usepackage{subcaption}\n%\\expandafter\\def\\csname ver@subfig.sty\\endcsname{}\n\\usepackage{tabularx}\n\\usepackage{subfig}\n\\usepackage{pgffor}\n\\usepackage{hyperref}\n\\usepackage{soul}\n\n% for tables\n\\newcommand{\\centertab}[1]{\\multicolumn{1}{|c|}{\\textbf{#1} }}\n\\newcommand{\\bigcell}[2]{\\begin{tabular}{@{}#1@{}}#2\\end{tabular}}\n\n\\begin{document}\n\\input{math_definitions}\n\n\\section{KL divergence}\n\\begin{align*}\n  D_{KL} (P \\| Q) = \\expected{x \\sim P}{ \\func{\\log}{\\dfrac{p(x)}{q(x)}}}\n\\end{align*}\n\n\\section{Expected value}\n\\begin{align*}\n  \\expected{}{X} = \\int x f(x) dx\n\\end{align*}\n\\begin{itemize}\n  \\item \\textbf{Linearity}\n  \\begin{align*}\n    \\expected{}{X + Y} &= \\expected{}{X} + \\expected{}{Y} \\\\\n    \\expected{}{a X} &= a \\expected{}{X}\n  \\end{align*}\n\\end{itemize}\n\n\\section{Multivariate Normal Distribution}\n\\begin{align}\n  p(\\vx| \\vmu, \\vSigma) = \\dfrac{1}{\\sqrt{\\group{2 \\pi}^k \\abs{\\vSigma}}}\n    \\func{\\exp}{-\\dfrac{1}{2} (\\vx - \\vmu)^T \\vSigma^{-1} (\\vx - \\vmu)}\n\\end{align}\n\\begin{itemize}\n  \\item \\textbf{log likelihood}\n  \\begin{align*}\n    \\ln(p(\\vx | \\vmu, \\vSigma))\n      & = -\\dfrac{k \\func{\\ln}{2 \\pi}}{2} -\\dfrac{\\func{\\ln}{\\abs{\\vSigma}}}{2}\n          -\\dfrac{1}{2}\\group{\\vx - \\vmu}^T \\vSigma^{-1} \\group{\\vx - \\vmu} \\\\\n      & = -\\dfrac{1}{2} \\sgroup{\\func{\\ln}{\\group{2 \\pi}^k \\abs{\\vSigma}}\n            + \\group{\\vx - \\vmu}^T \\vSigma^{-1} \\group{\\vx - \\vmu}\n                                }\n  \\end{align*}\n  \\item \\textbf{KL divergence}\n  \\begin{align*}\n    \\func{D_{KL}}{{\\cal N}_a \\| {\\cal N}_b }\n      & = \\dfrac{1}{2}\\group{\n        \\Tr{\\vSigma_b^{-1} \\vSigma_a}\n        + \\group{\\vmu_b - \\vmu_a} \\vSigma_b^{-1} \\group{\\vmu_b - \\vmu_a}\n        - k + \\log{\\dfrac{\\abs{\\vSigma_b}}{\\abs{\\vSigma_a}}}\n        } \\\\\n      & = \\dfrac{1}{2}\\group{\n        \\fnorm{\\vL_b \\solve \\vL_a}^2\n        + \\ltwogroup{\\vL_b \\solve \\group{\\vmu_b - \\vmu_a}}^2\n        %& \\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\n        - k + 2\\group{  \\log{\\func{\\diag}{{\\vL_b}}^T \\ones}\n                      - \\log{\\func{\\diag}{{\\vL_a}}^T \\ones} }\n        }\n  \\end{align*}\n  \\item \\textbf{Affine Transform}\n  \\begin{align*}\n    \\vx &\\sim \\normal{\\vmu_x, \\vSigma_x} \\\\\n    \\vy &= \\vA \\vx + \\vb \\\\\n    \\vy &\\sim \\normal{\\vA \\vmu_x + \\vb, \\vA \\Sigma_x \\vA^T}\n  \\end{align*}\n  \\item \\textbf{Linear Gaussian systems}\n    Given a linear system:\n    \\begin{align*}\n      p(\\vx) = \\normal{x \\given \\vmu_x, \\vSigma_x} \\\\\n      p(\\vy \\given \\vx) = \\normal{\\vy \\given \\vA \\vx + b, \\vSigma_y}\n    \\end{align*}\n    We have the following:\n    \\begin{align*}\n      p(\\vx \\given \\vy) &= \\normal{x \\given \\vmu_{x \\given y}, \\vSigma_{x \\given y}} \\\\\n      \\vmu_{x \\given y} &= \\vSigma_{x \\given y} \\sgroup{\\vA^T \\vSigma_y^{-1} (\\vy - \\vb) + \\vSigma_x^{-1} \\vmu_x}\\\\\n      \\vSigma_{x \\given y} &= \\vSigma_x^{-1} + \\vA^T \\vSigma_y^{-1} \\vA\n    \\end{align*}\n    \\begin{align*}\n      p(\\vy) = \\normal{\\vy \\given \\vA \\vmu_x + \\vb,\n                       \\vSigma_y + \\vA \\vSigma_x \\vA^T}\n    \\end{align*}\n  \\item \\textbf{quadratic relations}\n    \\begin{itemize}\n      \\item $\\expected{\\vx \\sim \\normal{\\vmu, \\vSigma}}{\\vx^T \\vA \\vx}\n              = \\Tr{\\vA \\vSigma} + \\vmu^T \\vA \\vmu$\n      \\item\n      $$\\expected{\\vx \\sim \\normal{\\vb, \\vB}}{\n        \\group{\\va - \\vA \\vx}^T \\Sigma^{-1} \\group{\\va - \\vA \\vx}}\n        = \\group{\\va - \\vA \\vb}^T \\vSigma^{-1} \\group{\\va - \\vA \\vb}\n          + \\Tr{\\vA^T \\vSigma^{-1} \\vA \\vB}$$\n    \\end{itemize}\n\n\\end{itemize}\n\n\\section{Gamma distribution}\n  $x \\sim Ga(a, b)$ where $a$ is called the shape and $b$ the rate.\n  \\begin{align*}\n    Ga(x | a, b) = \\dfrac{b^a}{\\Gamma(a)} x^{a-1} \\func{\\exp}{-bx}\n  \\end{align*}\n\n  \\begin{itemize}\n    \\item $\\expected{}{x} = \\dfrac{a}{b}$\n    \\item \\( \\expected{x \\sim Ga(a, b)}{\\ln{x}} = \\psi(a) - \\func{\\ln}{b} \\) \\\\\n    where $\\psi$ is the polygamma function.\n  \\end{itemize}\n\n\\subsection{Inverse gamma}\n  If $x \\sim Ga(a, b)$ and $y=\\dfrac{1}{x}$, then $y \\sim IG(a, b)$\n  \\begin{align*}\n    IG(y | a, b) = \\dfrac{b^a}{\\Gamma(a)} y^{-(a+1)} \\func{\\exp}{-b/y}\n  \\end{align*}\n\n\\subsection{Inverse Wishart (IW)}\nThis distribution is used in Bayesian statistics as the conjugate prior for the\n  covariance matrix of a multivariate normal distribution:\n  \\begin{align*}\n    \\vSigma & \\sim \\func{IW}{\\vS^{-1}, \\upsilon + D + 1} \\\\\n    \\func{IW}{\\vSigma \\given \\vS, \\upsilon} &=\n      \\dfrac{1}{\\func{\\vZ}{\\vS, \\upsilon}} \\abs{\\vSigma}^{(\\upsilon+D+1)/2}\n        \\func{\\exp}{-\\dfrac{1}{2} \\Tr{\\vS^{-1} \\vSigma^{-1}}} \\\\\n    \\func{Z}{\\vS, \\upsilon} &= \\abs{\\vS}^{-\\upsilon/2} 2^{\\upsilon D/2} \\Gamma_D{\\upsilon/2}\n  \\end{align*}\nwhere $\\vS \\succ 0$\n\n\\end{document}\n", "meta": {"hexsha": "ed590a7cf50da020ca8b2744d610e2c1cf8adcd9", "size": 4803, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/stats.tex", "max_stars_repo_name": "danmar3/twodlearn", "max_stars_repo_head_hexsha": "02b23bf07618d5288e338bd8f312cc38aa58c195", "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/stats.tex", "max_issues_repo_name": "danmar3/twodlearn", "max_issues_repo_head_hexsha": "02b23bf07618d5288e338bd8f312cc38aa58c195", "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/stats.tex", "max_forks_repo_name": "danmar3/twodlearn", "max_forks_repo_head_hexsha": "02b23bf07618d5288e338bd8f312cc38aa58c195", "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.5539568345, "max_line_length": 115, "alphanum_fraction": 0.5523631064, "num_tokens": 1934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6777192244468561}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Formulation of a compartment model} \\label{sec:fcm}\nRecall that the evolution of the concentration $C(t,\\b x)$ of a tracer in a domain $\\Omega$ obeys the following equation:\n\\begin{equation} \\label{eq:continuousproblem}\n\t\\frac{\\partial C}{\\partial t} = q - \\nabla \\cdot (\\b u C - \\b K \\cdot \\nabla C),\n\\end{equation}\nwhere $\\b u$ is the velocity field and $q$ is the source or sink term, i.e. the rate at which the tracer is produced or destroyed. In the case of a passive tracer, $q = 0$. Under the Boussinesq approximation, the continuity equation simplifies to\n\\begin{equation}\n\t\\nabla \\cdot \\b u = 0,\n\\end{equation}\nnamely the velocity field is divergence-free. As already stated, the diffusivity tensor $\\b K$ is symmetric and positive definite.\n\nIn order to derive a compartment model from~\\eqref{eq:continuousproblem}, $\\Omega$ must be partitioned into $N$ subdomains $\\Omega_1,\\Omega_2,\\dots,\\Omega_N$ called the \\textit{compartments}. Mathematically, the fact that these subdomains form a partition of $\\Omega$ means that\n\\begin{equation}\n\t\\bigcup_{i \\in\\{1,\\dots,N\\}} \\Omega_i = \\Omega \\qquad \\mbox{and} \\qquad \\Omega_i \\cap \\Omega_j = \\varnothing \\mbox{ if } i \\neq j.\n\\end{equation}\nIn this section, unless otherwise stated, the subscripts $i$ and $j$ are implicitly assumed to be in $\\{1,\\dots,N\\}$. The interface between the subdomains $\\Omega_i$ and $\\Omega_j$ is denoted $\\Gamma_{i,j}$ and the interface between $\\Omega_i$ and the environment is denoted $\\Gamma_{i,e}$. Obviously, $\\Gamma_{i,j} = \\Gamma_{j,i}$ and $\\cup_{i\\in\\{1,\\dots,N\\}} \\Gamma_{i,e} = \\partial \\Omega$. In a compartment model, only the averages over the compartments are considered. The mean tracer concentration over compartment $i$ is \n\\begin{equation} \\label{eq:C_i(t)}\n\tC_i(t) = \\frac{1}{|\\Omega_i|} \\int_{\\Omega_i} C(t,\\b x) \\rm d\\Omega_i,\n\\end{equation}\nand the net production rate over the subdomain $i$ is\n\\begin{equation}\n\tq_i(t) =  \\frac{1}{|\\Omega_i|} \\int_{\\Omega_i} q(t,\\b x) \\rm d\\Omega_i.\n\\end{equation}\nThe equation governing the evolution of $C_i(t)$, the average concentration over compartment $i$, is obtained by integrating~\\eqref{eq:continuousproblem} over $\\Omega_i$. This yields, using the divergence theorem:\n\\begin{equation}\n\t|\\Omega_i| \\frac{d C_i}{d t} = |\\Omega_i| q_i - \\sum_{\\subalign{j&=1 \\\\j &\\neq i}}^N \\underbrace{\\int_{\\Gamma_{i,j}} (\\b u C - \\b K \\cdot \\nabla C)\\cdot \\b n_{i,j} \\rm d\\Gamma_{i,j}}_{:= \\phi_{i,j}} - \\underbrace{\\int_{\\Gamma_{i,e}} (\\b u C - \\b K \\cdot \\nabla C)\\cdot \\b n_{i,e} \\rm d\\Gamma_{i,e}}_{:= \\phi_{i,e}},\n\\end{equation}\nwhere $\\phi_{i,j}$ is interpreted as the tracer flux from compartment $i$ to compartment $j$, and $\\phi_{i,e}$ is the flux of tracer leaving compartment $i$ towards the environment. In the framework of a compartment model, only the mean concentration in each compartment are available, making it impossible to evaluate the integrals in the right-hand side exactly. The flux $\\phi_{i,j}$ can be split into an advective and a diffusive part:\n\\begin{equation} \\label{eq:phi_i,j}\n\t\\phi_{i,j} = \\underbrace{\\int_{\\Gamma_{i,j}} (\\b u C)\\cdot \\b n_{i,j} \\rm d\\Gamma_{i,j}}_{:= \\phi_{i,j}^A \\mbox{ \\footnotesize (advective part)}} + \\underbrace{\\int_{\\Gamma_{i,j}} (-\\b K \\cdot \\nabla C)\\cdot \\b n_{i,j} \\rm d\\Gamma_{i,j}}_{:= \\phi_{i,j}^D \\mbox{ \\footnotesize (diffusive part)}}.\n\\end{equation} \nA natural approximation of the advective flux $\\phi_{i,j}^A$ is obtained as\n\\begin{equation}\n\t\\phi_{i,j}^A \\approx \\frac{C_i + C_j}{2} \\int_{\\Gamma_{i,j}} \\b u \\cdot \\b n_{i,j} \\rm d\\Gamma_{i,j} =  \\frac{C_i + C_j}{2} |\\Gamma_{i,j}| u_{i,j},\n\\end{equation}\nwhere a characteristic speed $u_{i,j}$ has been introduced such that\n\\begin{equation} \\label{eq:def_uij}\n\t|\\Gamma_{i,j}|u_{i,j} = \\int_{\\Gamma_{i,j}}\\b u \\cdot \\b n_{i,j} \\rm d\\Gamma_{i,j}.\n\\end{equation}\nSince $\\phi_{i,j}^A = - \\phi_{j,i}^A$ and $\\Gamma_{i,j} = \\Gamma_{j,i}$, the characteristic speed must satisfy\n\\begin{equation}\n\tu_{i,j} = - u_{j,i}.\n\\end{equation}\nThe definition~\\eqref{eq:def_uij} satisfies that condition.\nThe diffusive flux $\\phi_{i,j}^D$ involves the gradient of the concentration at the interface. A possible approximation is given by\n\\begin{equation}\n\t\\phi_{i,j}^D = - |\\Gamma_{i,j}| k_{i,j} \\frac{C_j-C_i}{l_{i,j}},\n\\end{equation}\nwhere $k_{i,j} > 0$ is a characteristic diffusivity and $l_{i,j} > 0$ is a characteristic length. Obviously, $\\phi_{i,j}^D = -\\phi_{j,i}^D$ hence $k_{i,j} = k_{j,i}$ and $l_{i,j} = l_{j,i}$. In \\cite{deleersnijder2014compartment}, \\textit{Deleersnijder} proposes to simplify those notations by introducing advective and diffusive \"fluxes\" $U_{i,j}$ and $V_{i,j}$:\n\\begin{equation} \\label{eq:def_Uij_Vij}\n\tU_{i,j} = |\\Gamma_{i,j}|u_{i,j} \\quad \\mbox{and} \\quad V_{i,j} = \\frac{|\\Gamma_{i,j}|k_{i,j}}{l_{i,j}}.\n\\end{equation}\nBy the previously mentioned properties, it is obvious that \n\\begin{equation} \\label{eq:Uprop}\n\tU_{i,j} = -U_{j,i}\n\\end{equation} \nand that \n\\begin{equation} \\label{eq:Vprop}\n\tV_{i,j} = V_{j,i} > 0.\n\\end{equation}\nUsing those notations, the flux from compartment $i$ to compartment $j$ is approximated by\n\\begin{equation}\n\t\\phi_{i,j} \\approx U_{i,j} \\frac{C_i + C_j}{2} - V_{i,j}(C_j - C_i),\n\\end{equation}\nand the equation governing the evolution of the concentration in compartment $i$ is obtained as\n\\begin{equation} \\label{eq:compartmentmodel}\n\t\\Omega_i \\frac{dC_i}{dt} = \\Omega_i q_i - \\sum_{\\subalign{j&=1 \\\\j &\\neq i}}^N \\left[ U_{i,j}\\frac{C_i + C_j}{2} - V_{i,j} (C_j-C_i)\\right] - \\phi_{i,e}.\n\\end{equation}\nLet us fix the convention $U_{i,i} = 0$ and $V_{i,i} = 0$ so that the summation subscript $j \\neq i$ becomes unnecessary.\nNote that by~\\eqref{eq:def_Uij_Vij},~\\eqref{eq:def_uij} and the divergence theorem,\n\\begin{equation} \\label{eq:continuitycompartment}\n\t\\sum_{j=1}^N U_{i,j} + U_{i,e} = \\sum_{\\subalign{j&=1 \\\\j &\\neq i}}^N \\int_{\\Gamma_{i,j}}\\b u \\cdot \\b n_{i,j} \\rm d\\Gamma_{i,j} + \\int_{\\Gamma_{i,e}}\\b u \\cdot \\b n_{i,e} \\rm d\\Gamma_{i,e} = \\int_{\\Omega_{i}} (\\nabla \\cdot \\b u) \\rm d\\Omega_{i} = 0,\n\\end{equation}\nthe counterpart to the continuity equation.", "meta": {"hexsha": "24c0f8e081c88d09dc599db9be0096dfe3b68344", "size": 6149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/compartments/formulation.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/compartments/formulation.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/compartments/formulation.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": 81.9866666667, "max_line_length": 529, "alphanum_fraction": 0.691494552, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.6777192156945235}}
{"text": "\\section{Safety Check}\n\nNaturally, we prefer error alerts right after inputting rather than let the system run till crash. \nParser helps filter bad inputs, type check verifies the transaction between term and term, while \nneither of them guarantees termination.\\par\nIn this part, we will demonstrate how to prevent non-halting definition from getting accepted into\nthe system.\n\n\\subsection{Fixpoint}\n\nThe introduction of {\\it Fixpoint} gives a wide range of flexibility of the program, without which recursive\nfunction can not formulate. On the other hand, the risk of non-terminating appears.\\par\nTo avoid this, we put a strong constraint on recursive function, which is that it must descend on at least one\nargument. \n\\begin{Prop}[Termination of Fixpoint]\nIf a recursive function descends on at least one argument, it will always terminate in reduction.\n\\end{Prop}\n\\begin{Def}[Descending]\nRecursive function $f(x_1,x_2,\\cdots,x_n)$ is descending on $x_k$ if any occurrence of $f$ in function definition has the \nform $f(y_1,y_2,\\cdots,y_n)$, where $y_k$ is inferior to $x_k$.\n\\end{Def}\n\\begin{Def}[Inferior]\nIn a function definition, $x$ is inferior to $y$ if $y\\to_m y_1\\to_m \\cdots\\to_m y_s\\equiv x$.\n$a \\to_m b$ means a pattern match directly from $a$ to $b$.\n\\end{Def}\nHere is an example.\n\\begin{center}\n\\begin{minted}{coq}\n(* accepted *)                                 (* rejected *)\nFixpoint plus (n:nat)(m:nat) : nat :=          Fixpoint plus (n:nat)(m:nat) : nat :=\n    match n as n0 in nat return (nat) with         match n as n0 in nat return (nat) with    \n    | O => m                                       | O => m\n    | S p => S (plus p m)                          | S p => S (plus m p)\n    end.                                           end.\n\\end{minted}\n\\end{center}\n\n\\subsubsection*{Implementation}\n\nCheck every argument of the recursive function. For a specific argument, maintain a list of terms inferior to it \nduring the process and verify every occurrence of the recursive function.\n\n\\subsection{Inductive Type}\n\nThe inductive type is actually a recursive definition, which is so powerful that we can create non-terminating program\nwithout actually defining a recursive function.\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\nInductive ill : Type :=                \n| malf : (ill -> ill) -> ill.          \n                                       \nDefinition extract (t:ill) : ill :=       \n    match t as t0 in ill return (ill) with \n    | malf f => f t\n    end.                                    \n\nextract (malf extract)  (* not terminating *)\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\begin{Prop}[Termination of Inductive Type]\nIf the type of constructor of the inductive definition satisfies the positivity condition for\nthe inductive type, it will always terminate in reduction.\n\\end{Prop}\n\n\\begin{Def}[Positivity]\nThe type of constructor $\\tt T$ satisfies \\textit{the positivity condition} for a constant $\\tt X$ if\n\\begin{itemize}\\normalfont\n    \\item $\\tt T\\equiv (X\\ t_1\\ \\cdots\\ t_n)$ and $\\tt X$ does not occur free in $\\tt t_i$\n    \\item $\\tt T\\equiv \\forall x:U,V$ and $\\tt X$ occurs only \\textit{strictly positively} in $\\tt U$ and\n        $\\tt V$ satisfies \\textit{the positivity condition} for $\\tt X$\n\\end{itemize}\n\\end{Def}\n\n\\begin{Def}[Strictly Positivity]\nThe constant $\\tt X$ occurs \\textit{strictly positively} in $\\tt T$ if\n\\begin{itemize}\\normalfont\n    \\item $\\tt X$ does not occur in $\\tt T$\n    \\item $\\tt T\\mathop{\\rhd}^*\\tt (X\\ t_1\\ \\cdots\\ t_n)$ and $\\tt X$ does not occur in $\\tt t_i$\n    \\item $\\tt T\\mathop{\\rhd}^*\\tt \\forall x:U,V$ and $\\tt X$ does not occur in $\\tt U$ but occurs\n        \\textit{strictly positively} in $\\tt V$\n    \\item $\\tt T\\mathop{\\rhd}^*\\tt (I\\ a_1\\ \\cdots\\ a_m\\ t_1\\ \\cdots\\ t_p)$, where\n        ${\\tt Ind}[m](\\tt I:A:=c_1:\\forall p_1:P_1,\\dots\\forall p_m:P_m,C_1;\\cdots;c_n:\\forall p_1:P_1,\\dots,\n        \\forall p_m:P_m,C_n)$, and $\\tt X$ does not occur in $t_i$, and the types of constructor\n        $\\tt C_i\\{p_j/a_j\\}_{j=1..m}$ satisfies \\textit{the nested positivity condition} for $\\tt X$\n\\end{itemize}\n\\end{Def}\n\n\\begin{Def}[Nested Positivity]\nThe type of constructor $\\tt T$ satisfies \\textit{the nested positivity condition} for a constant $\\tt X$ if\n\\begin{itemize}\\normalfont\n    \\item $\\tt T\\equiv(I\\ b_1\\ \\cdots\\ b_m\\ u_1\\ \\cdots\\ u_p)$, where $\\tt I$ is an inductive definition with $m$\n        parameters and $\\tt X$ does not occur in $u_i$\n    \\item $\\tt T\\equiv\\forall x:U,V$ and $\\tt X$ occurs \\textit{strictly positively} in $\\tt U$ and $\\tt V$\n        satisfies \\textit{the nested positivity condition} for $\\tt X$\n\\end{itemize}\n\\end{Def}\n", "meta": {"hexsha": "41ff930f5edc15f4c6746ee3621889d6ad055ac7", "size": 4664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/safetycheck.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/safetycheck.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/safetycheck.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": 46.64, "max_line_length": 122, "alphanum_fraction": 0.6629502573, "num_tokens": 1357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6776836213875421}}
{"text": "\\chapter{Numerical Integration} \\label{chap:integrate}\n\n\\abstract \n\nIn this chapter\nwe discuss some of the classic\nformulae like the trapezoidal rule and Simpson's rule for equally spaced \nabscissas  and formulae based on Gaussian quadrature. The latter are more suitable\nfor the case where the abscissas are not equally spaced. \nThe emphasis is on \nmethods for evaluating few-dimensional (typically up to four dimensions) integrals. In\nchapter \\ref{chap:mcint} \nwe show how Monte Carlo methods can be used to compute multi-dimensional\nintegrals.\nWe discuss also how to compute \nsingular integrals.\nWe end this chapter with an extensive discussion on MPI and parallel computing.\nThe examples focus on parallelization of algorithms for computing integrals. \n\nThe integral \n\\be\n   I=\\int_a^bf(x) dx\n   \\label{eq:integraldef}\n\\ee\nhas a very simple meaning. If we consider Fig. \\ref{fig:integral}\n\\begin{figure}[hbtp]\n\\thinlines\n\\setlength{\\unitlength}{1mm}\n\\begin{picture}(100,100)(0,0)\n\\linethickness{1pt}\n\\qbezier(20,30)(40,50)(100,55)\n \\thicklines\n    \\put(1,0.5){\\makebox(0,0)[bl]{\n\t       \\put(0,10){\\vector(1,0){120}}\n%\t       \\put(0,10){\\dashline{3}(0,1){19.6}}\n\t       \\put(-10,100){\\makebox(0,0){$f(x)$}}\n\t       \\put(120,0){\\makebox(0,0){$x$}}\n\t       \\put(0,10){\\vector(0,1){80}}\n\t       \\put(20,10){\\line(0,1){2}}\n\t       \\put(40,10){\\line(0,1){2}}\n\t       \\put(60,10){\\line(0,1){2}}\n\t       \\put(80,10){\\line(0,1){2}}\n\t       \\put(100,10){\\line(0,1){2}}\n\t       \\put(20,0){\\makebox(0,0){$a$}}\n\t       \\put(40,0){\\makebox(0,0){$a+h$}}\n\t       \\put(60,0){\\makebox(0,0){$a+2h$}}\n\t       \\put(80,0){\\makebox(0,0){$a+3h$}}\n\t       \\put(100,0){\\makebox(0,0){$b$}}\n\t  }}\n\\end{picture}\n%\\begin{center}\n%{\\centering\n%\\mbox{\\psfig{figure=integrate.ps,height=8cm,width=10cm,angle=0}}\n%}\n%\\end{center}\n\\caption{The area enscribed by the function $f(x)$ starting from $x=a$ to \n$x=b$. It is subdivided in several smaller areas whose evaluation is to\n be approximated by the techniques discussed in the text. The areas under the curve can for example \nbe approximated by rectangular boxes or trapezoids. \\label{fig:integral}}\n\\end{figure}\nthe integral $I$ simply represents the area enscribed by the function\n$f(x)$ starting from $x=a$ and ending at  $x=b$.\nTwo main methods will be discussed below, the first one being based on equal\n(or allowing for slight modifications) steps and the other on more adaptive steps,\nnamely so-called Gaussian quadrature methods. Both main methods encompass a plethora\nof approximations and only some of them will be discussed here.\n\n\\section{Newton-Cotes Quadrature}\n\nIn considering equal step  methods, our basic tool is the Taylor expansion\nof the function $f(x)$ around a point $x$ and a set of surrounding \nneighbouring points. \nThe algorithm is rather simple, and the number of approximations perhaps \nunlimited!\n\\begin{itemize}\n   \\item Choose a step size \n    \\[ \n        h=\\frac{b-a}{N}\n    \\]\n   where $N$ is the number of steps and $a$ and $b$ the lower and upper limits\n   of integration. \n\\item With a given step length we rewrite the integral as\n\\[\n    \\int_a^bf(x) dx= \\int_a^{a+h}f(x)dx + \\int_{a+h}^{a+2h}f(x)dx+\\dots \\int_{b-h}^{b}f(x)dx.\n\\]\n   \\item \nThe strategy then is to find a reliable Taylor expansion for $f(x)$ in the various intervals.  Choosing a given truncation of \nthe Taylor expansion of $f(x)$ at a \n         certain derivative we obtain a specific approximation to the \nintegral.\n   \\item With this approximation to $f(x)$ we perform the integration by computing the integrals over all subintervals.\n\\end{itemize}\nSuch a small measure may seemingly allow for the derivation of various integrals.\nTo see this, \nlet us  briefly recall  the discussion in the previous section and \nFig.\\ \\ref{fig:derivstep}. \nFirst we rewrite the integral as\n\\[\n    \\int_a^bf(x) dx= \\int_a^{a+2h}f(x)dx + \\int_{a+2h}^{a+4h}f(x)dx+\\dots \\int_{b-2h}^{b}f(x)dx.\n\\]\nOne possible strategy then is to find a reliable polynomial expansion for $f(x)$ in the smaller\nsub intervals. Consider for example evaluating \n\\[\n   \\int_a^{a+2h}f(x)dx, \n\\]\nwhich we rewrite as\n\\be\n   \\int_a^{a+2h}f(x)dx=\n \\int_{x_0-h}^{x_0+h}f(x)dx.\n     \\label{eq:hhint}\n\\ee\nWe have chosen a midpoint $x_0$ and have defined $x_0=a+h$.\nUsing Lagrange's interpolation formula from Eq.~(\\ref{eq:lagrange}), an equation we restate here,\n\\[\n   P_N(x)=\\sum_{i=0}^{N}\\prod_{k\\ne i} \\frac{x-x_k}{x_i-x_k}y_i,\n\\]\nwe could attempt to approximate the function $f(x)$ with a first-order polynomial in $x$ in the two\nsub-intervals $x\\in[x_0-h,x_0]$ and $x\\in[x_0,x_0+h]$. A first order polynomials means simply that \nwe have for say the interval  $x\\in[x_0,x_0+h]$\n\\[\n   f(x)\\approx P_1(x)=\\frac{x-x_0}{(x_0+h)-x_0}f(x_0+h)+\\frac{x-(x_0+h)}{x_0-(x_o+h)}f(x_0),\n\\]\nand for the interval  $x\\in[x_0-h,x_0]$\n\\[\n   f(x)\\approx P_1(x)=\\frac{x-(x_0-h)}{x_0-(x_0-h)}f(x_0)+\\frac{x-x_0}{(x_0-h)-x_o}f(x_0-h).\n\\]\nHaving performed this subdivision and polynomial approximation,\none from $x_0-h$ to $x_0$ and the other from $x_0$ to $x_0+h$,\n\\[\n   \\int_a^{a+2h}f(x)dx=\n \\int_{x_0-h}^{x_0}f(x)dx+\\int_{x_0}^{x_0+h}f(x)dx,\n\\]\nwe can easily calculate for example the second integral as\n\\[\n\\int_{x_0}^{x_0+h}f(x)dx\\approx \\int_{x_0}^{x_0+h}\\left(\\frac{x-x_0}{(x_0+h)-x_0}f(x_0+h)+\\frac{x-(x_0+h)}{x_0-(x_o+h)}f(x_0)\\right)dx,\n\\]\nwhich can be simplified to\n\\[\n\\int_{x_0}^{x_0+h}f(x)dx\\approx \\int_{x_0}^{x_0+h}\\left(\\frac{x-x_0}{h}f(x_0+h)-\\frac{x-(x_0+h)}{h}f(x_0)\\right)dx,\n\\]\nresulting in\n\\[\n\\int_{x_0}^{x_0+h}f(x)dx\\approx\n\\]\n\n\\[\n     P_3(x)=\\frac{(x-x_0)(x-x_1)}{(x_2-x_0)(x_2-x_1)}y_2+\n            \\frac{(x-x_0)(x-x_2)}{(x_1-x_0)(x_1-x_2)}y_1+\n            \\frac{(x-x_1)(x-x_2)}{(x_0-x_1)(x_0-x_2)}y_0\n\\]\n\n\n Next we assume that \nwe can use the two-point formula for the derivative, meaning that we approximate\n$f(x)$ in these two regions by a straight line, as indicated in the figure. \nThis means that every small element under the function $f(x)$ looks like a\ntrapezoid. The pertinent numerical approach to the integral\nbears thus the predictable name 'trapezoidal rule'.\nIt means also that we are trying to approximate our function\n$f(x)$ with a first order polynomial, that is $f(x)=a+bx$.\nThe constant $b$ is the slope given by the  \nfirst derivative at $x=x_0$\n\\[\n    f'= \\frac{f(x_0+h)-f(x_0)}{h}+O(h),\n\\]\nor \n\\[\n    f'= \\frac{f(x_0)-f(x_0-h)}{h}+O(h),\n\\]\nand if we stop the Taylor expansion at that point our function becomes,\n\\[\n   f(x)\\approx f_0 + \\frac{f_h-f_0}{h}(x-x_0),\n\\]\nfor $x\\in [x_0,x_0+h]$ and  \n\\[\n   f(x)\\approx f_0 + \\frac{f_0-f_{-h}}{h}(x-x_0),\n\\]\nfor $x\\in [x_0-h,x_0]$. The error is proportional with  $O(h^2)$.\nIf we then evaluate the integral we obtain\n\\be\n   \\int_{x_0-h}^{x_0+h}f(x)dx=\\frac{h}{2}\\left(f_{x_0+h} + 2f_{x_0} + f_{x_0-h}\\right)+O(h^3),\n   \\label{eq:trapez}\n\\ee\nwhich is the well-known trapezoidal rule.  Concerning the error in the approximation made,\n$O(h^3)=O((b-a)^3/N^3)$, you should  note \nthe following.   {\\em This is the local error!} Since we are splitting the integral from\n$a$ to $b$ in $N$ pieces, we will have to perform approximately $N$ \nsuch operations.\nThis means that the {\\em global error} goes like $\\approx O(h^2)$. \nTo see that, we use\nthe trapezoidal rule to compute\nthe integral     of Eq.\\ (\\ref{eq:integraldef}), \n\\begin{equation}\n   I=\\int_a^bf(x) dx=h\\left(f(a)/2 + f(a+h) +f(a+2h)+\n                          \\dots +f(b-h)+ f_{b}/2\\right),\n   \\label{eq:trapez1}\n\\end{equation}\nwith a global error which goes like $O(h^2)$. \n\nHereafter we use the shorthand notations $f_{-h}=f(x_0-h)$, $f_{0}=f(x_0)$\nand $f_{h}=f(x_0+h)$.\n  The correct mathematical expression for the local error for the trapezoidal rule is\n\\[\n\\int_a^bf(x)dx -\\frac{b-a}{2}\\left[f(a)+f(b)\\right]=-\\frac{h^3}{12}f^{(2)}(\\xi),\n\\]\nand the global error reads\n\\[\n\\int_a^bf(x)dx -T_h(f)=-\\frac{b-a}{12}h^2f^{(2)}(\\xi),\n\\]\nwhere $T_h$ is the trapezoidal result and $\\xi \\in [a,b]$.\n\nThe trapezoidal rule is easy to  implement numerically \nthrough the following simple algorithm\n\\begin{svgraybox}\n\\begin{itemize}\n   \\item Choose the number of mesh points and fix the step.\n   \\item calculate $f(a)$ and $f(b)$ and multiply with $h/2$\n   \\item Perform a loop over $n=1$ to $n-1$ ($f(a)$ and $f(b)$ are known) and sum up\n         the terms $f(a+h) +f(a+2h)+f(a+3h)+\\dots +f(b-h)$. Each step in the loop\n         corresponds to a given value $a+nh$. \n   \\item Multiply the final result by $h$ and add $hf(a)/2$ and $hf(b)/2$.\n\\end{itemize}\n\\end{svgraybox}\nA simple function which implements this algorithm is as follows\n\\lstset{language=c++}\n\\begin{lstlisting}\ndouble trapezoidal_rule(double a, double b, int n, double (*func)(double))\n{\n      double trapez_sum;\n      double fa, fb, x, step;\n      int    j;\n      step=(b-a)/((double) n);\n      fa=(*func)(a)/2. ;\n      fb=(*func)(b)/2. ;\n      TrapezSum=0.;\n      for (j=1; j <= n-1; j++){\n         x=j*step+a;\n         trapez_sum+=(*func)(x);\n      }\n      trapez_sum=(trapez_um+fb+fa)*step;\n      return trapez_sum;\n}  // end trapezoidal_rule \n\\end{lstlisting}\nThe function returns a new value for the specific integral through the variable\n{\\bf trapez\\_sum}. There is one new feature to note here, namely\nthe transfer of a user defined function called {\\bf func} in the \ndefinition \n\\begin{lstlisting}\n\n  void trapezoidal_rule(double a, double b, int n, double *trapez_sum, \n                        double (*func)(double) )       \n\\end{lstlisting}\n\nWhat happens here is that we are transferring a pointer to the name \nof a user defined\nfunction, which has as input a double precision variable and returns\na double precision number. The function \n{\\bf trapezoidal\\_rule} is called as\n\\begin{lstlisting}\n  trapezoidal_rule(a, b, n, &MyFunction )       \n\\end{lstlisting}\nin the calling function. We note that {\\bf a}, {\\bf b} and {\\bf n} are called by value,\nwhile {\\bf trapez\\_sum} and the user defined function {\\bf MyFunction}\nare called by reference. \n\n\nAnother very simple approach is the so-called midpoint or rectangle method.\nIn this case the integration area is split in a given number of rectangles with length $h$ and\nheight given by the mid-point value of the function.  This gives the following simple rule for\napproximating an integral\n\\begin{equation}\n   I=\\int_a^bf(x) dx \\approx  h\\sum_{i=1}^N f(x_{i-1/2}), \n   \\label{eq:rectangle}\n\\end{equation}\nwhere $f(x_{i-1/2})$ is the midpoint value of $f$ for a given rectangle. We will discuss its truncation \nerror below.  It is easy to implement this algorithm,  as shown here\n\\lstset{language=c++}\n\\begin{lstlisting}\ndouble rectangle_rule(double a, double b, int n, double (*func)(double))\n{\n      double rectangle_sum;\n      double fa, fb, x, step;\n      int    j;\n      step=(b-a)/((double) n);\n      rectangle_sum=0.;\n      for (j = 0; j <= n; j++){\n         x = (j+0.5)*step+;   // midpoint of a given rectangle\n         rectangle_sum+=(*func)(x);   //  add value of function.\n      }\n      rectangle_sum *= step;  //  multiply with step length.\n      return rectangle_sum;\n}  // end rectangle_rule \n\\end{lstlisting}\nThe correct mathematical expression for the local error for the rectangular rule $R_i(h)$ for element $i$ is\n\\[\n\\int_{-h}^hf(x)dx - R_i(h)=-\\frac{h^3}{24}f^{(2)}(\\xi),\n\\]\nand the global error reads\n\\[\n\\int_a^bf(x)dx -R_h(f)=-\\frac{b-a}{24}h^2f^{(2)}(\\xi),\n\\]\nwhere $R_h$ is the result obtained with rectangular rule and $\\xi \\in [a,b]$.\n\nInstead of using the above linear two-point approximations for $f$, we could\nuse the three-point formula for the derivatives. This means that we will choose\nformulae based on function values which lie symmetrically around the point where\nwe perform the Taylor expansion. It means also that we \nare approximating our function with a second-order \npolynomial $f(x)=a+bx+cx^2$. The first and second \nderivatives are given by \n\\[\n   \\frac{f_h-f_{-h}}{2h}=f'_0+\\sum_{j=1}^{\\infty}\\frac{f_0^{(2j+1)}}{(2j+1)!}h^{2j},\n\\]\nand\n\\[\n \\frac{ f_h -2f_0 +f_{-h}}{h^2}=f_0''+2\\sum_{j=1}^{\\infty}\\frac{f_0^{(2j+2)}}{(2j+2)!}h^{2j},\n\\]\nand we note that in both cases the error goes like $O(h^{2j})$. \nWith the latter two expressions we can now approximate  the function\n$f$ as\n\\[\n   f(x)\\approx f_0 + \\frac{f_h-f_{-h}}{2h}(x-x_0) + \\frac{ f_h -2f_0 +f_{-h}}{2h^2}(x-x_0)^2. \n\\]\nInserting this formula in the integral of Eq.\\ (\\ref{eq:hhint}) we obtain\n\\[\n   \\int_{-h}^{+h}f(x)dx=\\frac{h}{3}\\left(f_h + 4f_0 + f_{-h}\\right)+O(h^5),\n\\]\nwhich is Simpson's rule. Note that the improved accuracy in the evaluation of\nthe derivatives gives a better error approximation, $O(h^5)$ vs.\\ $O(h^3)$ .\nBut this is again the {\\em local error approximation}. \nUsing Simpson's rule we can easily compute\nthe integral     of Eq.\\ (\\ref{eq:integraldef}) to be\n\\begin{equation}\n   I=\\int_a^bf(x) dx=\\frac{h}{3}\\left(f(a) + 4f(a+h) +2f(a+2h)+\n                          \\dots +4f(b-h)+ f_{b}\\right),\n   \\label{eq:simpson}\n\\end{equation}\nwith a global error which goes like $O(h^4)$. \nMore formal expressions for the local and global errors are for the local error\n\\[\n\\int_a^bf(x)dx -\\frac{b-a}{6}\\left[f(a)+4f((a+b)/2)+f(b)\\right]=-\\frac{h^5}{90}f^{(4)}(\\xi),\n\\]\nand for the global error\n\\[\n\\int_a^bf(x)dx -S_h(f)=-\\frac{b-a}{180}h^4f^{(4)}(\\xi).\n\\]\nwith $\\xi\\in[a,b]$ and $S_h$ the results obtained with Simpson's method.\nThe method \ncan easily be implemented numerically through the following simple algorithm\n\\begin{svgraybox}\n\\begin{itemize}\n   \\item Choose the number of mesh points and fix the step.\n   \\item calculate $f(a)$ and $f(b)$\n   \\item Perform a loop over $n=1$ to $n-1$ ($f(a)$ and $f(b)$ are known) and sum up\n         the terms $4f(a+h) +2f(a+2h)+4f(a+3h)+\\dots +4f(b-h)$. Each step in the loop\n         corresponds to a given value $a+nh$. Odd values of $n$ give $4$ as factor\n         while even values yield $2$ as factor. \n   \\item Multiply the final result by $\\frac{h}{3}$.\n\\end{itemize}\\end{svgraybox}\n\n\nIn more general terms, what we have done here is to approximate a given function $f(x)$ with a polynomial\nof a certain degree. One can show that \ngiven $n+1$ distinct points $x_0,\\dots, x_n\\in[a,b]$ and $n+1$ values $y_0,\\dots,y_n$ there exists a \nunique polynomial $P_n(x)$ with the property \n\\[\n   P_n(x_j) = y_j\\hspace{0.5cm} j=0,\\dots,n\n\\]\nIn the Lagrange representation discussed in chapter \\ref{chap:differentiate}, this interpolating polynomial is given by\n\\[\nP_n = \\sum_{k=0}^nl_ky_k,\n\\]\nwith the Lagrange factors\n\\[\n   l_k(x) = \\prod_{\\begin{array}{c}i=0 \\\\ i\\ne k\\end{array}}^n\\frac{x-x_i}{x_k-x_i}\\hspace{0.2cm} k=0,\\dots,n,\n\\]\nsee for example the text of Kress \\cite{kress} or Burlich and Stoer \\cite{st1983} for details.\nIf we for example set $n=1$, we obtain\n\\[\nP_1(x) = y_0\\frac{x-x_1}{x_0-x_1}+y_1\\frac{x-x_0}{x_1-x_0}=\\frac{y_1-y_0}{x_1-x_0}x-\\frac{y_1x_0+y_0x_1}{x_1-x_0},\n\\]\nwhich we recognize as the equation for a straight line.\n\nThe polynomial interpolatory quadrature of order $n$ with equidistant quadrature points $x_k=a+kh$\nand step $h=(b-a)/n$ is called the Newton-Cotes quadrature formula of order $n$.\nGeneral expressions can be found in for example Refs.~\\cite{kress,st1983}.\n\n\\section{Adaptive Integration}\nBefore we proceed with more advanced methods like Gaussian quadrature, we mention breefly how\nan adaptive integration method can be implemented.\n\nThe above methods are all based on a defined step length, normally provided by the user,\ndividing the integration domain with a fixed number of subintervals.\nThis is rather simple to implement may be inefficient, in particular if the integrand\nvaries considerably in certain areas of the integration domain. In these areas the number of fixed integration points may not be adequate. In other regions, the integrand may vary slowly\nand fewer integration points may be needed.\n\nIn order to account for such features, it may be convenient to first study the properties of\nintegrand, via for example a plot of the function to integrate. If this function\noscillates largely in some specific domain we may then opt for adding more integration points\nto that particular domain. However, this procedure needs to be repeated for every new integrand and lacks obviously the advantages of a more generic code.  \n\nThe algorithm we present here is based on a recursive procedure and allows us to\nautomate an adaptive domain. The procedure is very simple to implement. \n\nAssume that we want to compute an integral using say the trapezoidal rule. We limit ourselves\nto a one-dimensional integral.\nOur integration domain is defined by $x\\in [a,b]$. The algorithm goes as follows\n\\begin{itemize}\n\\item We compute our first approximation by computing the integral for the full domain. We label this as $I^{(0)}$. It is obtained by calling our previously discussed function\n{\\bf trapezoidal\\_rule} as\n\\lstset{language=c++} \n\\begin{lstlisting} \nI0 = trapezoidal_rule(a, b, n, function);    \n\\end{lstlisting}\n\\item In the next step  we split the integration in two, with $c= (a+b)/2$. We compute then the two integrals $I^{(1L)}$ and $I^{(1R)}$\n\\lstset{language=c++}\n\\begin{lstlisting}\nI1L = trapezoidal_rule(a, c, n, function);\n\\end{lstlisting}\nand \n\\lstset{language=c++}\n\\begin{lstlisting}\nI1R = trapezoidal_rule(c, b, n, function);\n\\end{lstlisting}\nWith a given defined tolerance, being a small number provided by us, we estimate the difference\n$|I^{(1L)}+I^{(1R)}-I^{(0)}| < \\mathrm{tolerance}$. If this test is satisfied, our first approximation is satisfactory.\n\\item If not, we can set up a recursive procedure where the integral is split into subsequent\nsubintervals until our tolerance is satisfied. \n\\end{itemize}\nThis recursive procedure can be easily implemented via the following function\n\\lstset{language=c++}\n\\begin{lstlisting}\n//     Simple recursive function that implements the \n//     adaptive integration using the trapezoidal rule\n//     It is convenient to define as global variables \n//     the tolerance and the number of recursive steps\nconst int maxrecursions = 50;\nconst double tolerance = 1.0E-10;\n//  Takes as input the integration  limits, number of points, function to integrate\n//  and the number of steps \nvoid adaptive_integration(double a, double b, double *Integral, int n, int steps, double (*func)(double))\n     if ( steps > maxrecursions){ \n        cout << 'Too many recursive steps, the function varies too much' << endl;\n        break;\n     }\n     double c = (a+b)*0.5;  \n     // the whole integral\n     double I0 = trapezoidal_rule(a, b,n, func);\n     //  the left half\n     double I1L = trapezoidal_rule(a, c,n, func);\n     //  the right half\n     double I1R = trapezoidal_rule(c, b,n, func);\n     if (fabs(I1L+I1R-I0) < tolerance )  integral = I0;\n     else\n     { \n        adaptive_integration(a, c, integral, int n, ++steps, func)\n        adaptive_integration(c, b, integral, int n, ++steps, func)\n     }\n}\n// end function adaptive_integration\n\\end{lstlisting}\nThe variables {\\bf integral} and {\\bf steps} should be initialized to zero by the function\nthat calls the adaptive procedure.\n\n\n\n\\section{Gaussian Quadrature}\n\nThe methods we have presented hitherto are taylored to problems where the \nmesh points $x_i$ are equidistantly spaced, $x_i$ differing from $x_{i+1}$ by the step $h$.\nThese methods are well suited to cases where the integrand may vary strongly over a certain\nregion or if we integrate over the solution of a differential equation.\n\nIf however our integrand varies only slowly over a large interval, then the methods \nwe have discussed may only slowly converge towards a chosen precision\\footnote{You could e.g.,\nimpose that the integral should not change as function of increasing mesh points\nbeyond the sixth digit.}. \nAs an example,\n\\[\n   I=\\int_1^{b}x^{-2}f(x)dx,\n\\]\nmay converge very slowly to a given precision if $b$ is large and/or $f(x)$ varies slowly\nas function of $x$ at large values. \nOne can obviously rewrite such an integral by changing variables to $t=1/x$ resulting in\n\\[\n   I=\\int_{b^{-1}}^1f(t^{-1})dt,\n\\]\nwhich has a small integration range and hopefully the number of mesh points needed is not that\nlarge.\n\nHowever, there are cases where no trick may help and where the time expenditure in evaluating\nan integral is of importance. For such cases we would like to recommend methods\nbased on Gaussian quadrature. Here one can catch at least two birds with a stone, namely,\nincreased precision and fewer integration points. But it is important that the integrand varies\nsmoothly over the interval, else we have to revert to splitting the interval into many small\nsubintervals and the gain achieved may be lost.  %The mathematical details behind the theory\n%for Gaussian quadrature formulae is quite terse. If you however are interested in the derivation,\n%we advice you to consult the text of Stoer and Bulirsch [3], see especially section 3.6.\n\nThe basic idea behind all integration methods is to approximate the integral\n\\[ \n   I=\\int_a^bf(x)dx \\approx \\sum_{i=1}^N\\omega_if(x_i),  \n\\]\nwhere $\\omega$ and $x$ are the weights and the chosen mesh points, respectively.\nIn our previous discussion, these mesh points were fixed at the beginning, by choosing\na given number of points $N$. The weigths $\\omega$ resulted then from the integration\nmethod we applied. Simpson's rule, see Eq.\\ (\\ref{eq:simpson}) would give\n\\[\n   \\omega : \\left\\{h/3,4h/3,2h/3,4h/3,\\dots,4h/3,h/3\\right\\},\n\\]\nfor the weights, while the trapezoidal rule resulted in \n\\[\n   \\omega : \\left\\{h/2,h,h,\\dots,h,h/2\\right\\}.\n\\]\nIn general, an integration formula which is based on a Taylor series using $N$ points,\nwill integrate exactly a polynomial $P$ of degree $N-1$. That is, the $N$ weights\n$\\omega_n$ can be chosen to satisfy $N$ linear equations, see chapter 3 of Ref.\\ [3]. \nA greater precision for a given amount of numerical work can  be achieved\nif we are willing to give up the requirement of equally spaced integration points.  \nIn Gaussian quadrature (hereafter GQ), both the mesh points and the weights are to\nbe determined. The points will not be equally spaced\\footnote{Typically, most points \nwill be located near the origin, while few points are needed for large $x$ values since the \nintegrand is supposed to vary smoothly there. See below for an example.}. \nThe theory behind GQ is to obtain an arbitrary weight $\\omega$ through the use of\nso-called orthogonal polynomials. These polynomials are orthogonal in some\ninterval say e.g., [-1,1]. Our points $x_i$ are chosen in some optimal sense subject\nonly to the constraint that they should lie in this interval. Together with the weights\nwe have then $2N$ ($N$ the number of points) parameters at our disposal.  \n\nEven though the integrand is not smooth, we could render it smooth by extracting\nfrom it the weight function of an orthogonal polynomial, i.e.,\nwe are rewriting\n\\be \n   I=\\int_a^bf(x)dx =\\int_a^bW(x)g(x)dx\\approx \\sum_{i=1}^N\\omega_ig(x_i),  \n   \\label{eq:generalint}\n\\ee\nwhere $g$ is smooth and $W$ is the weight function, which is to  be associated with a given \northogonal polynomial. Note that with a given weight function we end up evaluating the integrand\nfor the function $g(x_i)$.\n\nThe weight function $W$ is non-negative in the integration interval \n$x\\in [a,b]$ such that\nfor any $n \\ge 0$ $\\int_a^b |x|^n W(x) dx$ is integrable. The naming\nweight function arises from the fact that it may be used to give more emphasis\nto one part of the interval than another. \nA quadrature formula \n\\be \\int_a^bW(x)f(x)dx \\approx \\sum_{i=1}^N\\omega_if(x_i), \\ee\nwith $N$ distinct quadrature points (mesh points) is a called a Gaussian quadrature \nformula if it integrates all polynomials $p\\in P_{2N-1}$ exactly, that is\n\\be \\int_a^bW(x)p(x)dx =\\sum_{i=1}^N\\omega_ip(x_i), \\ee \nIt is assumed that $W(x)$ is continuous and positive and that the integral\n\\[ \\int_a^bW(x)dx\\]\nexists. Note that the replacement of $f\\rightarrow Wg$ is normally a better approximation\ndue to the fact that we may isolate possible singularities of $W$ and its \nderivatives at the endpoints of the interval. \n\n\nThe quadrature weights or just weights (not to be confused with the weight function) \nare positive and the sequence of Gaussian quadrature formulae is convergent \nif the sequence $Q_N$ of quadrature formulae \n\\[\n   Q_N(f)\\rightarrow Q(f)=\\int_a^bf(x)dx,\n\\]\nin the limit $N\\rightarrow \\infty$. \nThen  we say that the sequence \n\\[ Q_N(f) = \\sum_{i=1}^N\\omega_i^{(N)}f(x_i^{(N)}), \\]\nis convergent for all polynomials $p$, that is \n\\[Q_N(p) = Q(p) \\]\nif there exits a constant $C$ such that \n\\[\n \\sum_{i=1}^N|\\omega_i^{(N)}| \\le C,\n\\]\nfor all $N$ which are natural numbers.\n\nThe error for the Gaussian quadrature formulae of order $N$ is given\nby\n\\[\n  \\int_a^bW(x)f(x)dx-\\sum_{k=1}^Nw_kf(x_k)=\\frac{f^{2N}(\\xi)}{(2N)!}\\int_a^bW(x)[q_{N}(x)]^2dx\n\\]\nwhere $q_{N}$ is the chosen orthogonal polynomial and $\\xi$ is a number in the interval $[a,b]$.\nWe have assumed that $f\\in C^{2N}[a,b]$, viz.~the space of all real or complex  $2N$ times continuously\ndifferentiable functions. \n\n\n\nIn science there are several important orthogonal polynomials which arise\nfrom the solution of differential equations. Well-known examples are the  \nLegendre, Hermite, Laguerre and Chebyshev polynomials. They have the following weight functions\n\\begin{center}\n\\begin{tabular}{rrr}\\hline\nWeight function&Interval&Polynomial \\\\\\hline\n  $W(x)=1$  &$x\\in [-1,1]$    &Legendre      \\\\\n  $W(x)=e^{-x^2}$  &$-\\infty \\le x \\le \\infty$    &Hermite      \\\\\n  $W(x)=x^{\\alpha}e^{-x}$  &$0 \\le x \\le \\infty$    &Laguerre      \\\\\n  $W(x)=1/(\\sqrt{1-x^2})$  &$-1 \\le x \\le 1$    &Chebyshev      \\\\ \\hline\n\\end{tabular}  \n\\end{center}  \n\nThe importance of the use of orthogonal polynomials in the evaluation\nof integrals can be summarized as follows.\n\\begin{itemize} \n  \\item As stated above, methods based on Taylor series using $N$ points will\n        integrate exactly a polynomial $P$ of degree $N-1$. If a function $f(x)$\n        can be approximated with a polynomial of degree $N-1$\n        \\[ \n          f(x)\\approx P_{N-1}(x), \n        \\]\n         with $N$ mesh points we should be able to integrate exactly the \n         polynomial $P_{N-1}$. \n   \\item Gaussian quadrature methods promise more than this. We can get a better\n         polynomial approximation with order greater than $N$  to $f(x)$ and still\n         get away with only $N$ mesh points. More precisely, we approximate\n         \\[\n            f(x) \\approx P_{2N-1}(x),\n         \\]\n         and with only $N$ mesh points these methods promise that \n         \\[\n            \\int f(x)dx \\approx \\int P_{2N-1}(x)dx=\\sum_{i=0}^{N-1} P_{2N-1}(x_i)\\omega_i,\n         \\]\n         The reason why we can represent a function $f(x)$ with a polynomial of degree\n         $2N-1$ is due to the fact that we have $2N$ equations, $N$ for the mesh points and $N$\n         for the weights. \n\\end{itemize}\n{\\em The mesh points are the zeros  of the chosen  orthogonal polynomial} of\norder $N$, and the weights are determined from the inverse of a matrix.\nAn orthogonal polynomials of degree $N$ defined in an interval $[a,b]$\nhas precisely $N$ distinct zeros on the open interval $(a,b)$. \n \nBefore we detail how to obtain mesh points and weights with orthogonal \npolynomials, let us revisit some features of orthogonal polynomials\nby specializing to Legendre polynomials. In the text below, we reserve \nhereafter the labelling\n$L_N$ for a Legendre polynomial of order $N$, while $P_N$ is an arbitrary polynomial\nof order $N$. \nThese polynomials form then the basis for the Gauss-Legendre method. \n\n\\subsection{Orthogonal polynomials, Legendre} \n\n\n% add comments about various polynomials and their respective equations\nThe Legendre polynomials are the solutions of an important\ndifferential equation in Science, namely\n\\[\nC(1-x^2)P-m_l^2P+(1-x^2)\\frac{d}{dx}\\left((1-x^2)\\frac{dP}{dx}\\right)=0.\n\\]\n$C$ is a constant. For $m_l=0$ we obtain the Legendre polynomials\nas solutions, whereas $m_l \\ne 0$ yields the so-called associated Legendre\npolynomials. This differential equation arises in for example the solution\nof the angular dependence of Schr\\\"odinger's \nequation with spherically symmetric potentials such as\nthe Coulomb potential. \n\nThe corresponding polynomials $P$ are\n\\[\n   L_k(x)=\\frac{1}{2^kk!}\\frac{d^k}{dx^k}(x^2-1)^k \\hspace{1cm} k=0,1,2,\\dots,\n\\]\nwhich, up to a factor, are the Legendre polynomials $L_k$. \nThe latter fulfil the orthogonality relation\n\\be\n  \\int_{-1}^1L_i(x)L_j(x)dx=\\frac{2}{2i+1}\\delta_{ij},\n  \\label{eq:ortholeg}\n\\ee\nand the recursion relation\n\\be\n  (j+1)L_{j+1}(x)+jL_{j-1}(x)-(2j+1)xL_j(x)=0.\n  \\label{eq:legrecur}\n\\ee\n\n\nIt is common to choose the normalization condition\n\\[\n    L_N(1)=1.\n\\]\nWith these equations we can determine a Legendre polynomial of arbitrary order\nwith input polynomials of order $N-1$ and $N-2$. \n\nAs an example, consider the determination of $L_0$, $L_1$ and $L_2$. \nWe have that\n\\[\n   L_0(x) = c,\n\\]\nwith $c$ a constant. Using the normalization equation $L_0(1)=1$\nwe get that\n\\[\n   L_0(x) = 1.\n\\]\n\nFor $L_1(x)$ we have the general expression \n\\[\n   L_1(x) = a+bx,\n\\]\nand using the orthogonality relation\n\\[\n  \\int_{-1}^1L_0(x)L_1(x)dx=0,\n\\]\nwe obtain $a=0$ and with the condition $L_1(1)=1$, we obtain $b=1$, yielding\n\\[\n   L_1(x) = x.\n\\]\nWe can proceed in a similar fashion in order to determine\nthe coefficients of $L_2$\n\\[\n   L_2(x) = a+bx+cx^2,\n\\]\nusing the orthogonality relations\n\\[\n  \\int_{-1}^1L_0(x)L_2(x)dx=0,\n\\]\nand \n\\[\n  \\int_{-1}^1L_1(x)L_2(x)dx=0,\n\\]\nand the condition\n$L_2(1)=1$ we would get \n\\be\n   L_2(x) = \\frac{1}{2}\\left(3x^2-1\\right).\n   \\label{eq:l2}\n\\ee\n\nWe note that we have three equations to determine the three coefficients\n$a$, $b$ and $c$.\n\nAlternatively, we could have \nemployed the recursion relation of Eq.~(\\ref{eq:legrecur}), resulting in\n\\[\n   2L_2(x)=3xL_1(x)-L_0,\n\\]\nwhich leads to Eq.~(\\ref{eq:l2}).\n\nThe orthogonality relation above is important in our discussion\non how to obtain the weights and mesh points. Suppose we have an arbitrary\npolynomial $Q_{N-1}$ of order $N-1$ and a Legendre polynomial $L_N(x)$ of\norder $N$. We could represent $Q_{N-1}$ \nby the Legendre polynomials through \n\\be\n   Q_{N-1}(x)=\\sum_{k=0}^{N-1}\\alpha_kL_{k}(x),\n   \\label{eq:legexpansion}\n\\ee\nwhere $\\alpha_k$'s are constants.  \n\nUsing the orthogonality relation of Eq.~(\\ref{eq:ortholeg}) we see that\n\\be\n  \\int_{-1}^1L_N(x)Q_{N-1}(x)dx=\\sum_{k=0}^{N-1} \\int_{-1}^1L_N(x) \\alpha_kL_{k}(x)dx=0.\n  \\label{eq:ortholeg2}\n\\ee\nWe will use this result in our construction of mesh points and weights \nin the next subsection.\n \nIn summary, the first few Legendre polynomials are\n\\[\n   L_0(x) =1,\n\\]\n\\[\n  L_1(x) = x,\n\\]\n\\[\n  L_2(x) = (3x^2-1)/2,\n\\]\n\\[\n   L_3(x) = (5x^3-3x)/2,\n\\]\nand \n\\[\n   L_4(x) = (35x^4-30x^2+3)/8.\n\\]\nThe following simple function implements the above recursion relation\nof Eq.~(\\ref{eq:legrecur}).\nfor computing Legendre polynomials of order $N$.\n\\lstset{language=c++}\n\\begin{lstlisting}\n//  This function computes the Legendre polynomial of degree N\n\ndouble Legendre( int n, double x) \n{\n       double r, s, t;\n       int m;\n       r = 0; s = 1.;\n       //  Use recursion relation to generate p1 and p2\n       for (m=0; m < n; m++ )  \n       {\n          t = r; r = s; \n          s = (2*m+1)*x*r - m*t;\n          s /= (m+1);\n\t} // end of do loop \n        return s;\n}   // end of function Legendre\n\\end{lstlisting}\nThe variable $s$ represents $L_{j+1}(x)$, while $r$ holds\n$L_j(x)$ and $t$ the value $L_{j-1}(x)$.\n\n\\subsection{Integration points and weights with orthogonal polynomials}\n\n\nTo understand how the weights and the mesh points are generated, we define first\na polynomial of degree $2N-1$ (since we have $2N$ variables at hand, the mesh points\nand weights for $N$ points). This polynomial can be represented through polynomial\ndivision by\n\\[\n   P_{2N-1}(x)=L_N(x)P_{N-1}(x)+Q_{N-1}(x),\n\\]\nwhere $P_{N-1}(x)$ and $Q_{N-1}(x)$ are some polynomials of degree $N-1$ or less.\nThe function $L_N(x)$ is a Legendre polynomial of order $N$. \n\nRecall that we wanted to approximate  an arbitrary function $f(x)$ with a\npolynomial $P_{2N-1}$ in order to evaluate \n\\[\n   \\int_{-1}^1f(x)dx\\approx \\int_{-1}^1P_{2N-1}(x)dx.\n\\]\nWe can use Eq.~(\\ref{eq:ortholeg2})\nto rewrite the above integral as\n\\[ \n   \\int_{-1}^1P_{2N-1}(x)dx=\\int_{-1}^1(L_N(x)P_{N-1}(x)+Q_{N-1}(x))dx=\\int_{-1}^1Q_{N-1}(x)dx,\n\\]\ndue to the orthogonality properties of the Legendre polynomials. We see that it suffices\nto evaluate the integral over $\\int_{-1}^1Q_{N-1}(x)dx$ in order to evaluate \n$\\int_{-1}^1P_{2N-1}(x)dx$. In addition, at the points $x_k$ where $L_N$ is zero, we have\n\\[\n    P_{2N-1}(x_k)=Q_{N-1}(x_k)\\hspace{1cm} k=0,1,\\dots, N-1,\n\\]\nand we see that through these $N$ points we can fully define $Q_{N-1}(x)$  and thereby the \nintegral. Note that we have chosen to let the numbering of the points run from $0$ to $N-1$.\nThe reason for this choice is that we wish to have the same numbering as the order of a \npolynomial of degree $N-1$.  This numbering will be useful below when  we introduce the matrix\nelements  which define the integration weights $w_i$.\n\nWe develope then $Q_{N-1}(x)$ in terms of Legendre polynomials,\nas done in Eq.~(\\ref{eq:legexpansion}), \n\\be \n  Q_{N-1}(x)=\\sum_{i=0}^{N-1}\\alpha_iL_i(x).\n  \\label{eq:lsum1}\n\\ee\nUsing the orthogonality property of the Legendre polynomials we have\n\\[ \n  \\int_{-1}^1Q_{N-1}(x)dx=\\sum_{i=0}^{N-1}\\alpha_i\\int_{-1}^1L_0(x)L_i(x)dx=2\\alpha_0,\n\\] \nwhere we have just inserted $L_0(x)=1$!\nInstead of an integration problem we need now to define the coefficient $\\alpha_0$.\nSince we know the values of $Q_{N-1}$ at the zeros of $L_N$, we may rewrite  \nEq.\\ (\\ref{eq:lsum1}) as\n\\be \n  Q_{N-1}(x_k)=\\sum_{i=0}^{N-1}\\alpha_iL_i(x_k)=\\sum_{i=0}^{N-1}\\alpha_iL_{ik} \\hspace{1cm} k=0,1,\\dots, N-1.\n  \\label{eq:lsum2}\n\\ee\nSince the Legendre polynomials are linearly independent of each other, none \nof the columns in the matrix $L_{ik}$ are linear combinations of the others. \nThis means that the matrix $L_{ik}$ has an inverse with the properties\n\\[\n   \\hat{{\\bf L}}^{-1}\\hat{{\\bf L}} = \\hat{{\\bf I}}.\n\\]\nMultiplying both sides of Eq.~(\\ref{eq:lsum2}) with $\\sum_{j=0}^{N-1}L_{ji}^{-1}$ results in \n\\be \n  \\sum_{i=0}^{N-1}(L^{-1})_{ki}Q_{N-1}(x_i)=\\alpha_k.\n  \\label{eq:lsum3}\n\\ee\nWe can derive this result in an alternative way by defining the vectors\n\\[\n\\hat{{\\bf x}}_k=\\left(\\begin{array} {c} x_0\\\\\n                                x_1\\\\\n                                .\\\\\n                                .\\\\\n                                x_{N-1}\\end{array}\\right) \\hspace{0.5cm}\n\\hat{{\\bf \\alpha}}=\\left(\\begin{array} {c} \\alpha_0\\\\\n                                \\alpha_1\\\\\n                                .\\\\\n                                .\\\\\n                                \\alpha_{N-1}\\end{array}\\right),\n\\]\nand the matrix \n\\[\n   \\hat{{\\bf L}}=\\left(\\begin{array} {cccc} L_0(x_0)  & L_1(x_0) &\\dots &L_{N-1}(x_0)\\\\\n                                   L_0(x_1)  & L_1(x_1) &\\dots &L_{N-1}(x_1)\\\\\n                                   \\dots  & \\dots &\\dots &\\dots\\\\\nL_0(x_{N-1})  & L_1(x_{N-1}) &\\dots &L_{N-1}(x_{N-1})\n\\end{array}\\right).\n\\]\nWe have then \n\\[\nQ_{N-1}(\\hat{x}_k) = \\hat{L}\\hat{\\alpha},\n\\]\nyielding (if $\\hat{L}$ has an inverse)\n\\[\n\\hat{L}^{-1}Q_{N-1}(\\hat{x}_k) = \\hat{\\alpha},\n\\]\nwhich is Eq.~(\\ref{eq:lsum3}).\n\nUsing the above results and the fact that\n\\[ \n   \\int_{-1}^1P_{2N-1}(x)dx=\\int_{-1}^1Q_{N-1}(x)dx,\n\\]\nwe get \n\\[ \n   \\int_{-1}^1P_{2N-1}(x)dx=\\int_{-1}^1Q_{N-1}(x)dx=2\\alpha_0=\n   2\\sum_{i=0}^{N-1}(L^{-1})_{0i}P_{2N-1}(x_i).\n\\]\nIf we identify the weights with $2(L^{-1})_{0i}$, where the points $x_i$ are\nthe zeros of $L_N$, we have an integration formula of the type \n\\[\n   \\int_{-1}^1P_{2N-1}(x)dx=\\sum_{i=0}^{N-1}\\omega_iP_{2N-1}(x_i)  \n\\]\nand if our function $f(x)$  can be approximated by a polynomial $P$ of degree\n$2N-1$, we have finally that \n\\[\n    \\int_{-1}^1f(x)dx\\approx \\int_{-1}^1P_{2N-1}(x)dx=\\sum_{i=0}^{N-1}\\omega_iP_{2N-1}(x_i)  .\n\\]\nIn summary, the mesh points $x_i$ are defined by the zeros of an orthogonal polynomial of degree $N$, that is \n$L_N$, while the weights are\ngiven by $2(L^{-1})_{0i}$. \n\n\n\\subsection{Application to the case $N=2$}\n\nLet us apply the above formal results to the case $N=2$. \nThis means that we can approximate a function $f(x)$ with a\npolynomial $P_3(x)$ of order $2N-1=3$. \n\nThe mesh points are the zeros of $L_2(x)=1/2(3x^2-1)$. \nThese points are $x_0=-1/\\sqrt{3}$ and $x_1=1/\\sqrt{3}$.\n\nSpecializing Eq.~(\\ref{eq:lsum2}) \n\\[ \n  Q_{N-1}(x_k)=\\sum_{i=0}^{N-1}\\alpha_iL_i(x_k) \\hspace{1cm} k=0,1,\\dots, N-1.\n\\]\nto $N=2$ yields  \n\\[\n   Q_1(x_0)=\\alpha_0-\\alpha_1\\frac{1}{\\sqrt{3}},\n\\]\nand \n\\[\n   Q_1(x_1)=\\alpha_0+\\alpha_1\\frac{1}{\\sqrt{3}},\n\\]\nsince $L_0(x=\\pm 1/\\sqrt{3})=1$ and $L_1(x=\\pm 1/\\sqrt{3})=\\pm 1/\\sqrt{3}$. \n\nThe matrix $L_{ik}$ defined in Eq.~(\\ref{eq:lsum2}) is then\n\\[\n   L_{ik}=\\left(\\begin{array} {cc} 1  & -\\frac{1}{\\sqrt{3}}\\\\\n                                   1  & \\frac{1}{\\sqrt{3}}\\end{array}\\right),\n\\]\nwith an inverse given by\n\\[\n   (L)_{ik}^{-1}=\\frac{\\sqrt{3}}{2}\\left(\\begin{array} {cc} \\frac{1}{\\sqrt{3}}  & \\frac{1}{\\sqrt{3}}\\\\\n                                   -1  & 1\\end{array}\\right).\n\\]\nThe weights are given by the matrix elements $2(L_{0k})^{-1}$. We have thence\n$\\omega_0=1$ and $\\omega_1=1$. \n\nObviously, there is no problem in changing the numbering of the matrix elements $i,k=0,1,2,\\dots,N-1$ to\n$i,k=1,2,\\dots,N$.  We have chosen to start from zero, since we deal with polynomials of degree $N-1$.\n\nSummarizing, for Legendre polynomials with $N=2$ we have\nweights\n\\[\n   \\omega : \\left\\{1,1\\right\\},\n\\]\nand mesh points \n\\[\n   x : \\left\\{-\\frac{1}{\\sqrt{3}},\\frac{1}{\\sqrt{3}}\\right\\}.\n\\]\n\n\nIf we wish to integrate \n\\[\n   \\int_{-1}^1f(x)dx,\n\\]\nwith $f(x)=x^2$, we approximate\n\\[ \n   I=\\int_{-1}^1x^2dx \\approx \\sum_{i=0}^{N-1}\\omega_ix_i^2.  \n\\]\n\nThe exact answer is $2/3$. Using $N=2$ with the above two weights \nand mesh points we get\n\\[ \n   I=\\int_{-1}^1x^2dx =\\sum_{i=0}^{1}\\omega_ix_i^2=\\frac{1}{3}+\\frac{1}{3}=\\frac{2}{3},  \n\\]\nthe exact answer!\n\nIf we were to emply the trapezoidal rule we would get\n\\[ \n   I=\\int_{-1}^1x^2dx =\\frac{b-a}{2}\\left((a)^2+(b)^2\\right)/2=\n                       \\frac{1-(-1)}{2}\\left((-1)^2+(1)^2\\right)/2=1!\n\\]\nWith just two points we can calculate exactly the integral for a second-order\npolynomial since our methods approximates the exact function with higher\norder polynomial. \nHow many points do you need with the trapezoidal rule in order to achieve a\nsimilar accuracy?\n\n\\subsection{General integration intervals for Gauss-Legendre}\n\nNote that the Gauss-Legendre method is not limited\nto an interval [-1,1], since we can always through a change of variable\n\\[\n   t=\\frac{b-a}{2}x+\\frac{b+a}{2},\n\\]\nrewrite  the integral for an interval  [a,b]\n\\[\n  \\int_a^bf(t)dt=\\frac{b-a}{2}\\int_{-1}^1f\\left(\\frac{(b-a)x}{2}+\\frac{b+a}{2}\\right)dx.\n\\]\n\nIf we have an integral on the form\n\\[\n  \\int_0^{\\infty}f(t)dt,\n\\]\nwe can choose new mesh points and weights by using the mapping  \n\\[\n\\tilde{x}_i=tan\\left\\{\\frac{\\pi}{4}(1+x_i)\\right\\},\n\\]\nand \n\\[\n\\tilde{\\omega}_i= \\frac{\\pi}{4}\\frac{\\omega_i}{cos^2\\left(\\frac{\\pi}{4}(1+x_i)\\right)},\n\\]\nwhere $x_i$ and $\\omega_i$ are the original mesh points and weights in the \ninterval $[-1,1]$, while $\\tilde{x}_i$ and $\\tilde{\\omega}_i$ are the new\nmesh points and weights for the interval $[0,\\infty)$. \n\nTo see  that this is correct by inserting the \nthe value of $x_i=-1$ (the lower end of the interval $[-1,1]$)\ninto the expression for $\\tilde{x}_i$. That gives $\\tilde{x}_i=0$,\nthe lower end of the interval $[0,\\infty)$. For\n$x_i=1$, we obtain $\\tilde{x}_i=\\infty$. To check that the new\nweights are correct, recall that the weights should correspond to the \nderivative of the mesh points. Try to convince yourself that the\nabove expression fulfills this condition.\n\n\n\n\\subsection{Other orthogonal polynomials}\n\n\\subsubsection{Laguerre polynomials}\nIf we are able to rewrite our integral of Eq.\\ (\\ref{eq:generalint}) with a\nweight function $W(x)=x^{\\alpha}e^{-x}$ with integration limits \n$[0,\\infty)$, we could then use the Laguerre polynomials.\nThe polynomials form then the basis for the Gauss-Laguerre method which can be applied\nto integrals of the form\n\\[ \n   I=\\int_0^{\\infty}f(x)dx =\\int_0^{\\infty}x^{\\alpha}e^{-x}g(x)dx.\n\\]\nThese polynomials arise from the solution of the differential\nequation\n\\[\n\\left(\\frac{d^2 }{dx^2}-\\frac{d }{dx}+\\frac{\\lambda}{x}-\\frac{l(l+1)}{x^2}\\right){\\cal L}(x)=0,\n\\]\nwhere $l$ is an integer $l\\ge 0$ and $\\lambda$ a constant. This equation\narises for example from the solution of the radial Schr\\\"odinger equation with \na centrally symmetric potential such as the Coulomb potential.\nThe first few polynomials are\n\\[\n   {\\cal L}_0(x)=1,\n\\]\n\\[\n    {\\cal L}_1(x)=1-x,\n\\]\n\\[\n    {\\cal L}_2(x)=2-4x+x^2,\n\\]\n\\[\n    {\\cal L}_3(x)=6-18x+9x^2-x^3,\n\\]\nand\n\\[\n    {\\cal L}_4(x)=x^4-16x^3+72x^2-96x+24.\n\\]\nThey fulfil the orthogonality relation\n\\[\n  \\int_{-\\infty}^{\\infty}e^{-x}{\\cal L}_n(x)^2dx=1,\n\\]\nand the recursion relation\n\\[\n  (n+1){\\cal L}_{n+1}(x)=(2n+1-x){\\cal L}_{n}(x)-n{\\cal L}_{n-1}(x).\n\\]\n\n\\subsubsection{Hermite polynomials}\n\nIn a similar way, for an integral which goes like\n\\[ \n   I=\\int_{-\\infty}^{\\infty}f(x)dx =\\int_{-\\infty}^{\\infty}e^{-x^2}g(x)dx.\n\\]\nwe could use the Hermite polynomials in order to extract weights and mesh points.\nThe Hermite polynomials are the solutions of the following differential\nequation\n\\[\n   \\frac{d^2H(x)}{dx^2}-2x\\frac{dH(x)}{dx}+\n       (\\lambda-1)H(x)=0.\n  % \\label{eq:hermite}\n\\]\nA typical example is again the solution of Schr\\\"odinger's\nequation, but this time with a harmonic oscillator potential.\nThe first few polynomials are\n\\[\n   H_0(x)=1,\n\\]\n\\[\n    H_1(x)=2x,\n\\]\n\\[\n    H_2(x)=4x^2-2,\n\\]\n\\[\n    H_3(x)=8x^3-12,\n\\]\nand\n\\[\n    H_4(x)=16x^4-48x^2+12.\n\\]\nThey fulfil the orthogonality relation\n\\[\n  \\int_{-\\infty}^{\\infty}e^{-x^2}H_n(x)^2dx=2^nn!\\sqrt{\\pi},\n\\]\nand the recursion relation\n\\[\n  H_{n+1}(x)=2xH_{n}(x)-2nH_{n-1}(x).\n\\]\n\n\n\n\n\\subsection{Applications to selected integrals}\n\nBefore we proceed with some selected applications, it is important to keep in mind\nthat since the mesh points are not evenly distributed, a careful analysis of the \nbehavior of the integrand as function of $x$ and the location of mesh \npoints is mandatory. To give you an example, in the Table below we show the \nmesh points and weights for the integration interval [0,100] \nfor $N=10$ points obtained by the Gauss-Legendre method.\n\\begin{table}[hbtp]\n\\begin{center}\n\\caption{Mesh points and weights for the integration interval [0,100] with \n         $N=10$ using the Gauss-Legendre method.} \n\\begin{tabular}{rrr}\\hline\n$i$&$x_i$&$\\omega_i$\\\\\\hline\n1 &  1.305  & 3.334 \\\\\n2 &  6.747  & 7.473 \\\\\n3 & 16.030 & 10.954  \\\\\n4 & 28.330 & 13.463 \\\\\n5 & 42.556 & 14.776 \\\\\n6 & 57.444 & 14.776 \\\\\n7 & 71.670 & 13.463 \\\\\n8 & 83.970 & 10.954 \\\\\n9 & 93.253  & 7.473 \\\\\n10&  98.695 &  3.334 \\\\\\hline\n\\end{tabular} \n\\end{center}   \n\\end{table}     \nClearly, if your function oscillates strongly in any subinterval, this \napproach needs to be refined, either by choosing more points or by choosing\nother integration methods. Note also that for integration intervals \nlike for example $x\\in [0,\\infty]$, the Gauss-Legendre method places\nmore points at the beginning of the integration interval.\nIf your integrand varies slowly for large values of $x$,\nthen this method may be appropriate.\n\n\nLet us here compare three methods for integrating, namely the trapezoidal rule,\nSimpson's method and the Gauss-Legendre approach. \nWe choose two functions to integrate:\n\\[\n  \\int_1^{100}\\frac{\\exp{(-x)}}{x}dx,\n\\]\nand \n\\[\n  \\int_{0}^{3}\\frac{1}{2+x^2}dx.\n\\] \nA program example which uses the trapezoidal rule, Simpson's rule\nand the Gauss-Legendre method is included here. For the corresponding Fortran program, replace program1.cpp\nwith program1.f90. The Pyhton program is listed as program1.py.\n\\lstset{language=c++}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter04/cpp/program1.cpp}}]\n#include <iostream>\n#include \"lib.h\"\nusing namespace std;\n//     Here we define various functions called by the main program\n//     this function defines the function to integrate\ndouble int_function(double x);\n//   Main function begins here\nint main()\n{\n     int n;\n     double a, b;\n     cout << \"Read in the number of integration points\" << endl;\n     cin >> n;\n     cout << \"Read in integration limits\" << endl;\n     cin >> a >> b;\n//   reserve space in memory for vectors containing the mesh points\n//   weights and function values for the use of the gauss-legendre\n//   method\n     double *x = new double [n];\n     double *w = new double [n];\n//   set up the mesh points and weights\n     gauss_legendre(a, b,x,w, n);\n//   evaluate the integral with the Gauss-Legendre method\n//   Note that we initialize the sum\n     double int_gauss = 0.;\n     for ( int i = 0;  i < n; i++){\n        int_gauss+=w[i]*int_function(x[i]);\n     }\n//    final output\n      cout << \"Trapez-rule = \" << trapezoidal_rule(a, b,n, int_function)\n           << endl;\n      cout << \"Simpson's rule = \" << simpson(a, b,n, int_function) \n           << endl;\n      cout << \"Gaussian quad = \" << int_gauss << endl;\n      delete [] x;\n      delete [] w;\n      return 0;\n}  // end of main program\n//  this function defines the function to integrate\ndouble int_function(double x)\n{\n  double value = 4./(1.+x*x);\n  return value;\n} // end of function to evaluate\n\\end{lstlisting}\nTo be noted in this program is that we can transfer the name of a given function to integrate.\nIn Table \\ref{tab:firstinttable} we show the results for the first integral using various \nmesh points, while Table \\ref{tab:secondinttable} displays the corresponding results obtained\nwith the second integral.\n\\begin{table}[hbtp]\n\\begin{center}\n\\caption{Results for $\\int_1^{100}\\exp{(-x)}/xdx$ using three different methods as functions\nof the number of mesh points $N$. \\label{tab:firstinttable}} \n\\begin{tabular}{rlll}\\hline\n$N$&Trapez&Simpson&Gauss-Legendre\\\\\\hline\n10 &  1.821020  &  1.214025  &    0.1460448  \\\\  \n20  &  0.912678  &  0.609897  &    0.2178091  \\\\\n40   & 0.478456  &  0.333714  &  0.2193834   \\\\\n100  & 0.273724   & 0.231290  &  0.2193839 \\\\\n1000 & 0.219984  &  0.219387  &  0.2193839  \\\\\n\\hline\n\\end{tabular} \n\\end{center}   \n\\end{table}     \nWe note here that, since the area over where we integrate is rather large and the integrand \ngoes slowly to zero for large values of $x$, both the trapezoidal rule and Simpson's method\nneed quite many points in order to approach the Gauss-Legendre method. \nThis integrand demonstrates clearly the strength of the Gauss-Legendre method\n(and other GQ methods as well), viz., few points\nare needed in order to achieve a very high precision.  \n\nThe second Table however shows that for smaller integration intervals, both the trapezoidal rule\nand Simpson's method compare well with the results obtained with the Gauss-Legendre\napproach. \n\\begin{table}[hbtp]\n\\begin{center}\n\\caption{Results for $\\int_{0}^{3}1/(2+x^2)dx$ using three different methods as functions\nof the number of mesh points $N$. \\label{tab:secondinttable}} \n\\begin{tabular}{rlll}\\hline\n$N$&Trapez&Simpson&Gauss-Legendre\\\\\\hline\n10  &  0.798861  &  0.799231  &  0.799233 \\\\  \n20   & 0.799140  &  0.799233  &  0.799233 \\\\\n40  &  0.799209   & 0.799233  &  0.799233 \\\\\n100  & 0.799229  &  0.799233   & 0.799233 \\\\  \n1000 & 0.799233  &  0.799233  &  0.799233 \\\\\n\\hline\n\\end{tabular} \n\\end{center}   \n\\end{table}     \n\n\n\n\\section{Treatment of Singular Integrals}\n\nSo-called principal value (PV) integrals are often employed in physics,\nfrom Green's functions for scattering to dispersion relations.\nDispersion relations are often related to measurable quantities\nand provide important consistency checks in atomic, nuclear and\nparticle physics. \nA PV integral is defined as\n\\[\n   I(x)={\\cal P}\\int_a^bdt\\frac{f(t)}{t-x}=\\lim_{\\epsilon\\rightarrow 0^+}\n\\left[\\int_a^{x-\\epsilon}dt\\frac{f(t)}{t-x}+\\int_{x+\\epsilon}^bdt\\frac{f(t)}{t-x}\\right],\n\\]\nand \narises in applications\nof Cauchy's residue theorem when the pole $x$  lies \non the real axis within the interval of integration $[a,b]$. Here ${\\cal P}$ stands for the principal value.\n{\\em An important assumption is that the function $f(t)$ is continuous \non the interval of integration. }\n\nIn case $f(t)$ is a closed form expression or it has an analytic continuation\nin the complex plane, it may be  possible to obtain an expression on closed\nform for the above integral. \n\nHowever, the situation which we are often confronted with is that\n$f(t)$ is only known at some points $t_i$ with corresponding\nvalues $f(t_i)$. In order to obtain $I(x)$ we need to resort to a\nnumerical evaluation.\n\nTo evaluate such an integral, let us first rewrite it as\n\\[\n {\\cal P}\\int_a^bdt\\frac{f(t)}{t-x}=\n\\int_a^{x-\\Delta}dt\\frac{f(t)}{t-x}+\\int_{x+\\Delta}^bdt\\frac{f(t)}{t-x}+\n{\\cal P}\\int_{x-\\Delta}^{x+\\Delta}dt\\frac{f(t)}{t-x},\n\\]\nwhere we have isolated the principal value part in the last integral. \n\nDefining a new variable $u=t-x$, we can rewrite the principal value\nintegral as\n\\be\nI_{\\Delta}(x)={\\cal P}\\int_{-\\Delta}^{+\\Delta}du\\frac{f(u+x)}{u}.\n\\label{eq:deltaint}\n\\ee\nOne possibility is to Taylor expand $f(u+x)$ around $u=0$, and compute\nderivatives to a certain order as we did for the Trapezoidal rule or\nSimpson's rule. \nSince all terms with even powers of $u$ in the Taylor expansion dissapear,\nwe have that \n\\[\nI_{\\Delta}(x)\\approx \\sum_{n=0}^{N_{max}}f^{(2n+1)}(x)\n                     \\frac{\\Delta^{2n+1}}{(2n+1)(2n+1)!}.\n\\]\n\nTo evaluate higher-order derivatives may be both time \nconsuming and delicate from a numerical point of view, since \nthere is always the risk of loosing precision when calculating\nderivatives numerically. Unless we have an analytic expression\nfor $f(u+x)$ and can evaluate the derivatives in a closed form,\nthe above approach is not the preferred one. \n\nRather, we show here how to use the Gauss-Legendre method\nto compute Eq.~(\\ref{eq:deltaint}). \nLet us first introduce a new variable $s=u/\\Delta$ and rewrite\nEq.~(\\ref{eq:deltaint}) as   \n\\be\nI_{\\Delta}(x)={\\cal P}\\int_{-1}^{+1}ds\\frac{f(\\Delta s+x)}{s}.\n\\label{eq:deltaint2}\n\\ee\n\nThe integration limits are now from $-1$ to $1$, as for the Legendre\npolynomials.\nThe principal value in Eq.\\ (\\ref{eq:deltaint2}) is however rather tricky\nto evaluate numerically, mainly since computers have limited\nprecision. We will here use a subtraction trick often used\nwhen dealing with singular integrals in numerical calculations.\nWe introduce first the calculus relation\n\\[\n  \\int_{-1}^{+1} \\frac{ds}{s} =0.\n\\]\nIt means that the curve $1/(s)$ has equal and opposite\nareas on both sides of the singular point $s=0$. \n\nIf we then note that $f(x)$ is just a constant, we have also\n\\[\n  f(x)\\int_{-1}^{+1} \\frac{ds}{s}=\\int_{-1}^{+1}f(x) \\frac{ds}{s} =0.\n\\]\n\nSubtracting this equation from \nEq.\\ (\\ref{eq:deltaint2}) yields\n\\be\nI_{\\Delta}(x)={\\cal P}\\int_{-1}^{+1}ds\\frac{f(\\Delta s+x)}{s}=\\int_{-1}^{+1}ds\\frac{f(\\Delta s+x)-f(x)}{s},\n\\label{eq:deltaint3}\n\\ee\nand the integrand is no longer singular since we have that \n$\\lim_{s \\rightarrow 0} (f(s+x) -f(x))=0$ and for the particular case\n$s=0$ the integrand \nis now finite.  \n\nEq.\\ (\\ref{eq:deltaint3}) is now rewritten using the Gauss-Legendre\nmethod resulting in\n\\be\n\\int_{-1}^{+1}ds\\frac{f(\\Delta s+x)-f(x)}{s}=\\sum_{i=1}^{N}\\omega_i\\frac{f(\\Delta s_i+x)-f(x)}{s_i},\n\\label{eq:deltaint4}\n\\ee\nwhere $s_i$ are the mesh points ($N$ in total) and $\\omega_i$ are the weights.\n\nIn the selection of mesh points for  a PV integral, it is important\nto use an even number of points, since an odd number of mesh\npoints always picks $s_i=0$ as one of the mesh points. The sum in\nEq.~(\\ref{eq:deltaint4}) will then diverge. \n\n\nLet us apply this method to the integral\n\\be\nI(x)={\\cal P}\\int_{-1}^{+1}dt\\frac{e^t}{t}.\n\\label{eq:deltaint5}\n\\ee\nThe integrand diverges at $x=t=0$. We\nrewrite it using Eq.~(\\ref{eq:deltaint3}) as\n\\be\n{\\cal P}\\int_{-1}^{+1}dt\\frac{e^t}{t}=\\int_{-1}^{+1}\\frac{e^t-1}{t},\n\\label{eq:deltaint6}\n\\ee\nsince $e^x=e^0=1$. With Eq.~(\\ref{eq:deltaint4}) we have then\n\\be\n\\int_{-1}^{+1}\\frac{e^t-1}{t}\\approx \\sum_{i=1}^{N}\\omega_i\\frac{e^{t_i}-1}{t_i}.\n\\label{eq:deltaint7}\n\\ee\n\nThe exact results is $2.11450175075....$. With just two mesh points we recall\nfrom the previous subsection that $\\omega_1=\\omega_2=1$ and that the mesh points are the zeros of $L_2(x)$, namely $x_1=-1/\\sqrt{3}$ and \n$x_2=1/\\sqrt{3}$. Setting $N=2$ and inserting these values in the last\nequation gives\n\\[\n   I_2(x=0)=\\sqrt{3}\\left(e^{1/\\sqrt{3}}-e^{-1/\\sqrt{3}}\\right)=2.1129772845.\n\\]\nWith six mesh points we get even the exact result to the tenth digit\n\\[\n   I_6(x=0)=2.11450175075!\n\\]\n\nWe can repeat the above subtraction trick  for more complicated\nintegrands.\nFirst we modify the integration limits to $\\pm \\infty$ and use the fact\nthat \n\\[\n  \\int_{-\\infty}^{\\infty} \\frac{dk}{k-k_0}=\n  \\int_{-\\infty}^{0} \\frac{dk}{k-k_0}+\n  \\int_{0}^{\\infty} \\frac{dk}{k-k_0} =0.\n\\]\nA change of variable $u=-k$ in the integral with limits from $-\\infty$ to $0$ gives\n\\[\n  \\int_{-\\infty}^{\\infty} \\frac{dk}{k-k_0}=\n  \\int_{\\infty}^{0} \\frac{-du}{-u-k_0}+\n  \\int_{0}^{\\infty} \\frac{dk}{k-k_0}=  \\int_{0}^{\\infty} \\frac{dk}{-k-k_0}+\n  \\int_{0}^{\\infty} \\frac{dk}{k-k_0}=0.\n\\]\nIt means that the curve $1/(k-k_0)$ has equal and opposite\nareas on both sides of the singular point $k_0$. If we break\nthe integral into one over positive $k$ and one over \nnegative $k$, a change of variable $k\\rightarrow -k$ \nallows us to rewrite the last equation as\n\\[\n  \\int_{0}^{\\infty} \\frac{dk}{k^2-k_0^2} =0.\n\\]\nWe can use this to express a principal values integral\nas\n\\begin{equation}\n  {\\cal P}\\int_{0}^{\\infty} \\frac{f(k)dk}{k^2-k_0^2} =\n  \\int_{0}^{\\infty} \\frac{(f(k)-f(k_0))dk}{k^2-k_0^2},\n   \\label{eq:trick_pintegral}\n\\end{equation}\nwhere the right-hand side is no longer singular at \n$k=k_0$, it is proportional to the derivative $df/dk$,\nand can be evaluated numerically as any other integral.\n\nSuch a trick is often used when evaluating integral  equations, as discussed in the next section.\n\n\n\n\\section{Parallel Computing}\n\nWe end this chapter by discussing modern supercomputing concepts like parallel computing.\nIn particular, we will introduce you to the usage of the Message Passing Interface (MPI) library.\nMPI is a library, not a programming language. It specifies the names, calling sequences and results of functions\nor subroutines to be called from C++ or Fortran programs, and the classes and methods that make up the MPI C++\nlibrary. The programs that users write in Fortran or C++ are compiled with ordinary compilers and linked\nwith the MPI library. MPI programs should be able to run\non all possible machines and run all MPI implementetations without change.\nAn excellent reference is the text by Karniadakis and Kirby II \\cite{cmpi}.\n\n\\subsection{Brief survey of supercomputing concepts and terminologies}\n\nSince many discoveries in science are nowadays obtained via \nlarge-scale simulations,  \nthere is an ever-lasting wish and need \nto do larger simulations using shorter computer time. \nThe development of the capacity for single-processor computers (even with increased processor speed and memory) \ncan hardly keep up with the pace of scientific computing.  \nThe solution to the needs of the scientific computing and high-performance computing (HPC) \ncommunities has therefore been parallel computing.\n\nThe basic ideas of parallel computing is that \nmultiple processors are involved to solve a global problem. \nThe essence is to divide the entire computation evenly among\ncollaborative processors.\n\nToday's supercomputers are parallel machines and can achieve peak performances \nalmost up to $10^{15}$ floating point operations \nper second, so-called peta-scale computers, see for example \nthe list over the world's top 500 supercomputers at \\url{www.top500.org}.\nThis list gets updated twice per year and sets up the ranking according to a given supercomputer's\nperformance on a benchmark code from the LINPACK library. The benchmark solves a set of linear equations\nusing the best software for a given platform. \n\n\nTo understand the basic philosophy, it is useful to have a rough picture of how to classify different hardware \nmodels. We distinguish betwen three major groups, (i)\nconventional single-processor computers, normally  called SISD\n(single-instruction-single-data) machines, (ii) \nso-called SIMD machines (single-instruction-multiple-data), which incorporate the\nidea of parallel processing using  a large number of processing units to execute the same instruction on different data and finally (iii)\nmodern parallel computers,  so-called MIMD (multiple-instruction-\nmultiple-data) machines that can execute different instruction\nstreams in parallel on different data.\nOn a MIMD machine the different parallel processing units perform operations independently \nof each others, only subject to synchronization via a given message passing interface at specified\ntime intervals. \nMIMD machines are the dominating ones among present supercomputers, and we distinguish between two\ntypes of MIMD  computers, namely shared memory machines and distributed memory machines. \nIn shared memory systems the central processing units (CPU) share the same address\nspace. Any CPU can access any data in the global memory.\nIn distributed memory systems each CPU has its own memory.\nThe CPUs are connected by some network and may exchange\nmessages. A recent trend are so-called ccNUMA (cache-coherent-non-uniform-memory-\naccess) systems which are clusters of SMP (symmetric multi-processing) machines and have a virtual shared memory.\n\nDistributed memory machines, in particular those based on PC clusters, are nowadays the most widely used\nand cost-effective, although farms of PC clusters require large infrastuctures and yield additional expenses\nfor cooling. PC clusters with Linux as operating systems are easy to setup and offer several advantages,\nsince they are built from standard \ncommodity hardware with the open source software (Linux) infrastructure. \nThe designer can improve performance proportionally with added machines. \nThe commodity hardware can be any of a number of mass-market, stand-alone compute nodes \nas simple as two networked computers each running Linux and sharing a file system or as complex as\nthousands of nodes with a high-speed, low-latency network.\nIn addition to the increased speed of present  individual processors (and most machines come today with dual cores or four cores, so-called quad-cores)\nthe position of such commodity supercomputers has been strenghtened by the fact  \nthat a library like MPI has made parallel computing portable and easy. Although there are several implementations,\nthey share the same core commands. \nMessage-passing is a mature programming paradigm and widely\naccepted. It often provides an efficient match to the hardware.\n\n\n\n\n\\subsection{Parallelism}\n\nWhen we discuss parallelism, it is common to subdivide different algorithms in three major groups.\n\\begin{itemize}\n\\item {\\bf Task parallelism}:the work of a global problem can be divided\ninto a number of independent tasks, which rarely need to synchronize. \nMonte Carlo simulations and numerical integration are examples of possible applications. \nSince there is more or less no communication between different processors, task parallelism results in almost \na perfect mathematical parallelism and is commonly dubbed embarassingly parallel (EP).\nThe examples in this chapter fall under that category.  The use of the MPI library is then limited to some\nfew function calls and the programming is normally very simple.\n\\item {\\bf Data parallelism}:  use of multiple threads (e.g., one thread per\nprocessor) to dissect loops over arrays etc. \nThis paradigm requires a single memory address space. \nCommunication and synchronization between the processors are often hidden, and it is thus easy to\nprogram. However, the user surrenders much control to a specialized compiler.\nAn example of data parallelism  is compiler-based parallelization.\n\n\\item {\\bf Message-passing}: all involved processors have an independent\nmemory address space. The user is responsible for partitioning \nthe data/work of a global problem and distributing the \nsubproblems to the processors. Collaboration between processors\nis achieved by explicit message passing, which is used for data\ntransfer plus synchronization.\n\nThis paradigm is the most general one where the user has full\ncontrol. Better parallel efficiency is usually achieved by explicit\nmessage passing. However, message-passing programming is\nmore difficult.  We will meet examples of this in connection with the solution \neigenvalue problems in chapter \\ref{chap:eigenvalue} and \nof partial\ndifferential equations in chapter \\ref{chap:partial}. \n\n\\end{itemize}\n\nBefore we proceed, let us look at two simple examples. We will also use these simple examples\nto define the speedup factor of a parallel computation.  \nThe first case is that of the additions of two vectors of dimension $n$,\n\\[\n    {\\bf z } = \\alpha {\\bf x} + \\beta {\\bf y},\n\\]\nwhere $\\alpha$ and $\\beta$  are two real or complex numbers and \n${\\bf z}, {\\bf x}, {\\bf y} \\in {\\mathbb{R}}^{n}$ \nor $\\in {\\mathbb{C}}^{n}$. For every element we have thus\n\\[\n    z_i = \\alpha x_i + \\beta y_i. \n\\]\nFor every element $z_i$ we have three floating point operations, two multiplications and one addition.\nIf we assume that these operations take the same time $\\Delta t$, then the total time spent by one processor is\n\\[  T_1  =  3n\\Delta t.\\]\nSuppose now that we have access to a parallel supercomputer with $P$ processors. Assume also that \n$P\\le n$.  We split then these addition and multiplication operations on every \nprocessor so that every processor performs\n$3n/P$  operations in total, resulting in a time $T_P = 3n\\Delta t/P$ for every single processor.  \nWe also assume that the time needed to gather together these subsums is neglible  \n\nIf we have perfect parallelism, our speedup should be $P$, the number \nof processors available.  We see that this is the case by computing the relation between the time used in case\nof only one processor and the time used if we can access $P$ processors. The speedup $S_P$ is defined as \n\\[ S_P=\\frac{T_1}{T_P} = \\frac{3n\\Delta t}{3n\\Delta t/P} = P,\\]\na perfect speedup. As mentioned above, we call calculations that yield a perfect speedup for\nembarassingly parallel.   The efficiency is defined as \n\\[  \n\\eta(P) = \\frac{S(P)}{P}.\n\\]\n\nOur next example is that of the inner product of two vectors  defined in Eq.~(\\ref{eq:innerprod}), \n\\[\nc = \\sum_{j=1}^{n} x_{j}y_{j}. \n\\]\nWe assume again that $P\\le n$ and define $I=n/P$.  Each processor is assigned with its own subset\nof local multiplications $c_P=\\sum_px_py_p$, where $p$ runs over all possible terms for processor P.\nAs an example, assume that we have four processors. Then we have\n\\[\nc_1 = \\sum_{j=1}^{n/4} x_{j}y_{j}, \\hspace{1cm}  c_2 = \\sum_{j=n/4+1}^{n/2} x_{j}y_{j},\n\\] \n\\[\nc_3 = \\sum_{j=n/2+1}^{3n/4} x_{j}y_{j}, \\hspace{1cm}  c_4 = \\sum_{j=3n/4+1}^{n} x_{j}y_{j}.\n\\] \nWe assume again that the time for every operation is $\\Delta t$. \nIf we have only one processor, the total time is $T_1=(2n-1)\\Delta t$. \nFor four processors, we must now add the time needed to add $c_1+c_2+c_3+c_4$, which is\n$3\\Delta t$ (three additions) and the time needed to communicate the local result $c_P$  to all\nother processors.  This takes roughly $(P-1)\\Delta t_c$, where $\\Delta t_c$ need not equal $\\Delta t$.\n\nThe speedup for four processors becomes now\n\\[ S_4=\\frac{T_1}{T_4} = \\frac{(2n-1)\\Delta t}{(n/2-1)\\Delta t+3\\Delta t +3\\Delta t_c}=\\frac{4n-2}{10+n},\\] \nif $\\Delta t = \\Delta t_c$. \nFor $n=100$, the speedup is $S_4=  3.62 < 4$. \nFor $P$ processors the inner products yields a speedup \n\\[\nS_P = \\frac{(2n-1)}{(2I+P-2))+(P-1)\\gamma},\n\\]\nwith $\\gamma = \\Delta t_c/\\Delta t$.\nEven with $\\gamma = 0$, we see that the speedup is less than $P$.\n\nThe communication time $\\Delta t_c$ can reduce significantly the speedup. However, even if it is small, there are other\nfactors as well which may reduce the efficiency $\\eta_p$. For example, \nwe may have an uneven load balance, meaning that not all the processors can perform useful\nwork at all time, or that the number of processors doesn't match properly the size of the problem, or memory problems, \nor that a so-called startup time penalty known as latency may slow down the transfer of data.  Crucial here is the rate \nat which messages are transferred\n\n\n\n\\subsection{MPI with simple examples}\n\nWhen we want to parallelize a sequential algorithm, there are at least two aspects we need to consider, namely\n\\begin{itemize}\n\\item Identify the part(s) of a sequential algorithm that can be \nexecuted in parallel.  This can be difficult.\n\\item Distribute the global work and data among $P$ processors.  Stated differently, here you need to understand how you can\nget computers to run in parallel. From a practical point of view it means to implement parallel programming tools.\n\\end{itemize}\nIn this chapter we focus mainly on the last point. MPI is then a tool for writing programs to run in parallel, without needing\nto know much (in most cases nothing) about a given machine's architecture.\nMPI programs work on both shared memory and distributed memory machines. Furthermore, \nMPI is a very rich and complicated library. But it is not necessary to use all the features.\nThe basic and most used functions  have been optimized for most machine architectures \n\nBefore we proceed, we need to clarify some concepts, in particular the usage of the words process and processor.\nWe refer to process as a logical unit which executes its own code,\nin an MIMD style. The processor is a physical device on which one or several processes\nare executed. The MPI standard uses the concept process consistently throughout\nits documentation. However, since we only consider situations where one processor is\nresponsible for one process, we therefore use the\ntwo terms interchangeably in the discussion below, hopefully without creating ambiguities.\n\n\nThe six  most important MPI functions are \n\\begin{itemize}\n\\item MPI\\_ Init - initiate an MPI computation\n\\item MPI\\_Finalize - terminate the MPI computation and clean up\n\\item MPI\\_Comm\\_size - how many processes participate in a given MPI computation.\n\\item MPI\\_Comm\\_rank - which rank does a given process have. \nThe rank is a number between 0 and size-1, the latter representing\nthe total number of processes.\n\\item MPI\\_Send - send a message to a particular process within an MPI\ncomputation\n\\item MPI\\_Recv - receive a message from a particular process within an MPI computation.\n\\end{itemize}\n\nThe first MPI C++ program  is a rewriting of our 'hello world' program \n(without the computation of the sine function) \nfrom chapter \\ref{chap:numanalysis}.\nWe let every process write \"Hello world\" on the standard output.\n\\lstset{language=c++}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter04/program2.cpp}}]\n//    First C++ example of MPI Hello world\nusing namespace std;\n#include <mpi.h>\n#include <iostream>\n\nint main (int nargs, char* args[])\n{\n     int numprocs, my_rank;\n//   MPI initializations\n     MPI_Init (&nargs, &args);\n     MPI_Comm_size (MPI_COMM_WORLD, &numprocs);\n     MPI_Comm_rank (MPI_COMM_WORLD, &my_rank);\n     cout << \"Hello world, I have  rank \" << my_rank << \" out of \" << numprocs << endl;\n//  End MPI\n      MPI_Finalize ();\n    return 0;\n}\n\\end{lstlisting}\nThe corresponding Fortran program reads\n\\lstset{language=[90]Fortran}\n\\begin{lstlisting}\nPROGRAM hello\n   INCLUDE \"mpif.h\"\n   INTEGER:: numprocs, my_rank, ierr\n\n   CALL  MPI_INIT(ierr)\n   CALL MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\n   CALL MPI_COMM_RANK(MPI_COMM_WORLD, my_rank, ierr)\n   WRITE(*,*)\"Hello world, I've rank \",my_rank,\" out of \",numprocs\n   CALL MPI_FINALIZE(ierr)\n\nEND PROGRAM hello\n\\end{lstlisting}\nMPI is a message-passing library where all the routines\nhave a corresponding C++-bindings\\footnote{The C++ bindings used in practice are the same as the C bindings, \nalthough reading older texts like \\cite{mpiref,gropp1999,cmpi} one finds\nextensive discussions on the difference between C and C++ bindings. \nThroughout this text we will use the C bindings.} \\lstinline{MPI_Command_name} or \nFortran-bindings (function names are by convention in uppercase, but can also be in lower case) \\lstinline{MPI_COMMAND_NAME}\n\nTo use the MPI library you must include header files which contain definitions \nand declarations that are needed by the MPI library routines. \nThe following line must appear at the top of any source code file that will make an MPI call.  \nFor Fortran you must put in the beginning\n\\lstinline{INCLUDE$\\hspace{0.1cm}$'mpif.h'}  while for C++ you need to include the statement \\lstinline{#include$\\hspace{0.1cm}$\"mpi.h\"}.\nThese header files contain the declarations of functions, variabels etc. needed by the MPI library.\n\nThe first MPI call must be \\lstinline{MPI_INIT}, which initializes the message passing routines, as defined in for example \n\\lstinline{INTEGER::$\\hspace{0.1cm}$ierr} and \\lstinline{CALL$\\hspace{0.1cm}$MPI_INIT(ierr)} for the Fortran example. \nThe variable \\lstinline{ierr} is an integer which holds an error code when the call returns.\nThe value of \\lstinline{ierr} is however of little use since, \nby default, MPI aborts the program when it encounters an error. However, \\lstinline{ierr} must be included when MPI starts.\nFor the C++ code we have the call to \nthe function \n\\begin{lstlisting}\nMPI_Init(int *argc, char *argv)\n\\end{lstlisting}where \n\\lstinline{argc} and \\lstinline{argv} are arguments passed to main. MPI does not use these arguments in any way, \nhowever, and in MPI-2 implementations, NULL may be passed instead.\nWhen you have finished you must call the function \n\\lstinline{MPI_Finalize}. In Fortran you use the statement \n\\begin{lstlisting}\nCALL MPI_FINALIZE(ierr)\n\\end{lstlisting} \nwhile for C++ we use the function\n\\lstinline{MPI_Finalize(void)}.\n\nIn addition to these calls, we have also included calls to so-called \ninquiry functions. There are two \nMPI calls that are usually made soon after initialization. They are for C++, \n\\begin{lstlisting}{MPI_COMM_SIZE((MPI_COMM_WORLD, &numprocs)}  and \n\\lstinline{CALL\\hspace{0.1cm}MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)} for Fortran.  \nThe function \\lstinline{MPI_COMM_SIZE} returns the number of \ntasks in a specified MPI communicator (comm when we refer to it in generic function calls below). \n\nIn MPI you can divide your total number of tasks into groups, \ncalled communicators. What  does that mean?\nAll MPI communication is associated with what one calls a communicator\nthat describes a  group of MPI processes with a name (context). \nThe communicator  designates a collection of processes which can communicate with each other. \nEvery  process is then identified by its rank. The rank is only meaningful\nwithin a particular communicator.  A communicator is thus used as a mechanism to identify subsets of processes.  \nMPI has the flexibility to allow you to\ndefine different types of communicators, see for example \\cite{mpiref}. However,  here we have used the\ncommunicator \\lstinline{MPI_COMM_WORLD} that contains all the MPI\nprocesses that are initiated when we run the program.\n\nThe variable \\lstinline{numprocs} refers to the number of processes we have at our disposal.\nThe function \\lstinline{MPI_COMM_RANK} returns the rank \n(the name or identifier) of the tasks running the code. \nEach task (or processor) in a communicator is assigned a number \\lstinline{my_rank} from  $0$ to $\\mathrm{numprocs}-1$. \n\nWe are now ready to perform our first MPI calculations.\n\n\\subsubsection{Running codes with MPI}\nTo compile and load the above C++ code (after having understood how to use a local cluster), \nwe can use the command \n\\begin{verbatim}\nmpicxx -O2 -o program2.x  program2.cpp\n\\end{verbatim}\nand try to run with ten nodes using the command\n\\begin{verbatim}\nmpiexec -np 10 ./program2.x\n\\end{verbatim}\n \nIf we wish to use  the Fortran version we need to replace the C++ compiler statement \\lstinline{mpicc}\nwith \\lstinline{mpif90} or equivalent compilers.  The name of the compiler is obviously system dependent.  \nThe command \\lstinline{mpirun} may be used instead of \\lstinline{mpiexec}.  Here you need to check your own\nsystem.\n\nWhen we run MPI all processes use the same  binary executable version of the code and all processes are running\nexactly the same code. The question is then how can we tell the difference between our parallel\ncode running on a given number of processes and a serial code?\nThere are two major distinctions you should keep in mind: (i) MPI lets each process have a particular rank\nto determine which instructions are run on a particular process and (ii) the processes communicate with each\nother in order to finalize a task. Even if all processes receive the same set of instructions, they will normally\nnot execute the same instructions.We will discuss  this point in connection with our integration example below.\n \nThe above example produces the following output\n\\begin{verbatim}\nHello world, I've rank 0 out of 10 procs.\nHello world, I've rank 1 out of 10 procs.\nHello world, I've rank 4 out of 10 procs.\nHello world, I've rank 3 out of 10 procs.\nHello world, I've rank 9 out of 10 procs.\nHello world, I've rank 8 out of 10 procs.\nHello world, I've rank 2 out of 10 procs.\nHello world, I've rank 5 out of 10 procs.\nHello world, I've rank 7 out of 10 procs.\nHello world, I've rank 6 out of 10 procs.\n\\end{verbatim}\n\nThe output to screen is not ordered since all processes are trying to write  to screen simultaneously.\nIt is then the operating system which opts for an ordering.  \nIf we wish to have an organized output, starting from the first process, we may rewrite our program as follows\n\\lstset{language=c++}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter04/program3.cpp}}]\n//    Second C++ example of MPI Hello world\nusing namespace std;\n#include <mpi.h>\n#include <iostream>\n\nint main (int nargs, char* args[])\n{\n     int numprocs, my_rank, i;\n//   MPI initializations\n     MPI_Init (&nargs, &args);\n     MPI_Comm_size (MPI_COMM_WORLD, &numprocs);\n     MPI_Comm_rank (MPI_COMM_WORLD, &my_rank);\n     for (i = 0; i < numprocs; i++) {\n       MPI_Barrier (MPI_COMM_WORLD);\n       if (i == my_rank) {\n         cout << \"Hello world, I have  rank \" << my_rank << \" out of \" << numprocs << endl;\n         fflush (stdout);\n       }\n     }\n//  End MPI\n      MPI_Finalize ();\n    return 0;\n}\n\\end{lstlisting}\nHere we have used the \\lstinline{MPI_Barrier} function to ensure that\nevery process has completed  its set of instructions in  a particular order.\nA barrier is a special collective operation that does not allow the processes to continue\nuntil all processes in the communicator (here \\lstinline{MPI_COMM_WORLD}) have called \n\\lstinline{MPI_Barrier}. \nThe output is now\n\\begin{verbatim}\nHello world, I've rank 0 out of 10 procs.\nHello world, I've rank 1 out of 10 procs.\nHello world, I've rank 2 out of 10 procs.\nHello world, I've rank 3 out of 10 procs.\nHello world, I've rank 4 out of 10 procs.\nHello world, I've rank 5 out of 10 procs.\nHello world, I've rank 6 out of 10 procs.\nHello world, I've rank 7 out of 10 procs.\nHello world, I've rank 8 out of 10 procs.\nHello world, I've rank 9 out of 10 procs.\n\\end{verbatim}\nThe barriers make sure that all processes have reached the same point in the code. Many of the collective operations\nlike \\lstinline{MPI_ALLREDUCE} to be discussed later, have the same property; viz.~no process can exit the operation\nuntil all processes have started. \nHowever, this is slightly more time-consuming since the processes synchronize between themselves as many times as there\nare processes.  In the next Hello world example we use the send and receive functions in order to a have a synchronized\naction.\n\\lstset{language=c++}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter04/program4.cpp}}]\n//    Third C++ example of MPI Hello world\nusing namespace std;\n#include <mpi.h>\n#include <iostream>\n\nint main (int nargs, char* args[])\n{\n     int numprocs, my_rank, flag;\n//   MPI initializations\n     MPI_Status status;\n     MPI_Init (&nargs, &args);\n     MPI_Comm_size (MPI_COMM_WORLD, &numprocs);\n     MPI_Comm_rank (MPI_COMM_WORLD, &my_rank);\n     //   Send and Receive example\n     if (my_rank > 0)\n       MPI_Recv (&flag, 1, MPI_INT, my_rank-1, 100, MPI_COMM_WORLD, &status);\n       cout << \"Hello world, I have  rank \" << my_rank << \" out of \" << numprocs << endl;\n     if (my_rank < numprocs-1)\n         MPI_Send (&my_rank, 1, MPI_INT, my_rank+1, 100, MPI_COMM_WORLD);\n//  End MPI\n      MPI_Finalize ();\n    return 0;\n}\n\\end{lstlisting}\nThe basic sending of messages is given by the function \\lstinline{MPI_SEND}, which in C++\nis defined as \n\\begin{lstlisting}\nMPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)\n\\end{lstlisting}\nwhile in Fortran we would call this function with the following parameters\n\\begin{lstlisting}\nCALL MPI_SEND(buf, count, MPI_TYPE, dest, tag, comm, ierr).\n\\end{lstlisting}\nThis single command allows the passing of any kind of variable, even a large array, to any group of tasks. \nThe variable \\lstinline{buf} is the variable we wish to send while \\lstinline{count} \nis the  number of variables we are passing. If we are passing only a single value, this should be 1. \nIf we transfer an array, it is  the overall size of the array. \nFor example, if we want to send a 10 by 10 array, count would be $10\\times 10=100$ \nsince we are  actually passing 100 values.  \n\nWe define the type of variable using \\lstinline{MPI_TYPE}\nin order to let  MPI function know  what to expect.  The destination of the send is declared via the variable \n\\lstinline{dest}, which gives the  ID number of the task we are  sending the message to.\nThe variable \\lstinline{tag} \nis a way for the receiver to verify that it is  getting the message it expects. \nThe message tag is an integer number that we can assign any value, normally a large number (larger than the expected number of processes).\nThe communicator \\lstinline{comm} is the group ID of tasks that the message is going to. \nFor complex programs,  tasks may be divided into groups to speed up connections and transfers. \nIn small programs, this will more than likely be in \\lstinline{MPI_COMM_WORLD}.\n\nFurthermore, when an MPI routine is called, the Fortran or C++ data type which is passed must match the corresponding \nMPI integer constant. An integer is defined as \\lstinline{MPI_INT} in C++ and \n\\lstinline{MPI_INTEGER}  in Fortran.  \nA double precision real is\n\\lstinline{MPI_DOUBLE} in C++ and \n\\lstinline{MPI_DOUBLE_PRECISION} in Fortran and single precision real is \n\\lstinline{MPI_FLOAT} in C++ and \n\\lstinline{MPI_REAL}  in  Fortran.  For further definitions of data types see chapter five of\nRef.~\\cite{mpiref}.\n\nOnce you have  sent a message, you must receive it on another task. The function \\lstinline{MPI_RECV} is similar to the send call.\nIn C++ we would define this as \n\\begin{lstlisting}\nMPI_Recv( void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status )\n\\end{lstlisting}\nwhile in Fortran we would use the call \n\\begin{lstlisting}\nCALL MPI_RECV(buf, count, MPI_TYPE, source, tag, comm, status, ierr)}.\n\\end{lstlisting}\nThe arguments that are different from those in \\lstinline{MPI_SEND} are\n\\lstinline{buf} which  is the name of the variable where you will  be storing the received data, \n\\lstinline{source} which  replaces the destination in the send command. This is the return ID of the sender.\n\nFinally,  we have used  \\lstinline{MPI_Status~status;} \nwhere one can check if the receive was completed.\nThe source or tag of a received message may not be known if\nwildcard values are used in the receive function. In C++, MPI Status\nis a structure that contains further information. One can obtain this information\nusing \n\\begin{lstlisting}\nMPI_Get_count (MPI_Status *status, MPI_Datatype datatype, int *count)}\n\\end{lstlisting}\nThe output of this code is the same as the previous example, but now\nprocess 0 sends a message to process 1, which forwards it further\nto process 2, and so forth.\n\nArmed with this wisdom, performed all hello world greetings, we are now ready for serious work. \n\n\\subsection{Numerical integration with MPI}\n\nTo integrate numerically with MPI we need to define how to send and receive data types. This means also that we need\nto specify  which data types to send  to MPI functions. \n\nThe program listed here integrates \\[  \\pi = \\int_0^1 dx \\frac{4}{1+x^2} \\] by simply adding up areas of\nrectangles according to the algorithm discussed in Eq.~(\\ref{eq:rectangle}), rewritten here\n\\[\n   I=\\int_a^bf(x) dx \\approx  h\\sum_{i=1}^N f(x_{i-1/2}), \n\\]\nwhere $f(x)=4/(1+x^2)$.\nThis is a brute force way of obtaining an integral but suffices to demonstrate our first \napplication of MPI to mathematical problems. What we do is to subdivide the integration\nrange $x\\in [0,1]$ into $n$ rectangles. Increasing $n$ should obviously increase the precision of the result,\nas discussed in the beginning of this chapter. \nThe parallel part proceeds by letting every process collect a part of the sum of the rectangles. \nAt the end of the\ncomputation all the sums from the processes are summed up to give the final global sum.\nThe program below serves thus as a simple\nexample on how to integrate in parallel.  We will refine it in the next examples and we will also add\na simple example on how to implement the trapezoidal rule. \n\\lstset{language=c++}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter04/program5.cpp}}]\n1   //    Reactangle rule and numerical integration using MPI send and Receive\n2   using namespace std;\n3   #include <mpi.h>\n4   #include <iostream>\n\n5   int main (int nargs, char* args[])\n6   {\n7      int numprocs, my_rank, i, n = 1000;\n8      double local_sum, rectangle_sum, x, h;\n9      //   MPI initializations\n10     MPI_Init (&nargs, &args);\n11     MPI_Comm_size (MPI_COMM_WORLD, &numprocs);\n12     MPI_Comm_rank (MPI_COMM_WORLD, &my_rank);\n13     //   Read from screen a possible new vaue of n\n14     if (my_rank == 0 && nargs > 1) {\n15        n = atoi(args[1]);\n16     }\n17     h = 1.0/n;\n18     //  Broadcast n and h to all processes\n19     MPI_Bcast (&n, 1, MPI_INT, 0, MPI_COMM_WORLD);\n20     MPI_Bcast (&h, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);\n21     //  Every process sets up its contribution to the integral\n22     local_sum = 0.;\n23     for (i = my_rank; i < n; i += numprocs) {\n24       x = (i+0.5)*h;\n25       local_sum += 4.0/(1.0+x*x);\n26    }\n27     local_sum *= h;\n28     if (my_rank == 0) {\n29       MPI_Status status;\n30       rectangle_sum = local_sum;\n31       for (i=1; i < numprocs; i++) {\n32         MPI_Recv(&local_sum,1,MPI_DOUBLE,MPI_ANY_SOURCE,500,MPI_COMM_WORLD,&status);\n33         rectangle_sum += local_sum;\n34       }\n35       cout << \"Result: \" << rectangle_sum  << endl;\n36     }  else\n37       MPI_Send(&local_sum,1,MPI_DOUBLE,0,500,MPI_COMM_WORLD);\n38     // End MPI\n39     MPI_Finalize ();\n40     return 0;\n41   }\n\\end{lstlisting}\nAfter the standard initializations with MPI such as\n\\begin{lstlisting}\nMPI_Init, MPI_Comm_size, MPI_Comm_rank,\n\\end{lstlisting}\n\\lstinline{MPI_COMM_WORLD} contains now the number of processes\ndefined  by using for example \n\\begin{verbatim}\nmpirun -np 10 ./prog.x\n\\end{verbatim}\nIn line 14 we check if\nwe have read in from screen the number of mesh points  $n$. Note that in line 7 we fix $n=1000$, however\nwe have the possibility to run the code with a different number of mesh points as well.\nIf \\lstinline{my_rank} equals zero, which correponds to the master node, then we read a new value of\n$n$  if the number of arguments is larger than two. This can be done as follows when we run the code\n\\begin{verbatim}\nmpiexec -np 10 ./prog.x  10000\n\\end{verbatim}\nIn line 17 we define also the step length $h$.\nIn lines 19 and 20 we use the broadcast function \\lstinline{MPI_Bcast}.\nWe use this particular function because we want data on one processor (our master node) to be shared\nwith all other processors. The broadcast function sends data to a group of processes. \nThe MPI routine \\lstinline{MPI_Bcast} transfers data from one task to a group of others. \nThe format for the call\nis in C++ given by the parameters of \n\\begin{lstlisting}\n{MPI_Bcast (&n, 1, MPI_INT, 0, MPI_COMM_WORLD);.\n\\end{lstlisting}\nIn case we have a floating point variable we need to declare\n\\begin{lstlisting}\nMPI_Bcast (&h, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);\n\\end{lstlisting}\nThe general structure of this function is \n\\begin{lstlisting}\nMPI_Bcast( void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)\n\\end{lstlisting}\nAll processes call this function, both the process sending the data (with rank zero) and all the other\nprocesses in \\lstinline{MPI_COMM_WORLD}.  \nEvery process has now  copies of $n$ and $h$, the number of mesh points and the step length, respectively.\n\nWe transfer the addresses of $n$ and $h$.  The second argument represents the number of data sent. In case of \na one-dimensional array, one needs to transfer the number of array elements. \nIf you have an $n\\times m$ matrix, you must transfer $n\\times m$. We need also to specify whether the variable\ntype we transfer is a non-numerical such as a logical or character variable or numerical of the integer,\nreal or complex type. \n\nWe transfer also an integer variable \\lstinline{int\\hspace{0.1cm}root}.  This variable specifies \nthe process which has  the original copy of the data. \nSince we fix this value to zero in the call in lines 19 and 20,\nit means that it is the master process which keeps this information. \nFor Fortran, this function is called via the statement \n\\begin{lstlisting}\nCALL MPI_BCAST(buff, count, MPI_TYPE, root, comm, ierr).\n\\end{lstlisting}\nIn lines  23-27, every process sums its own part of the final sum used by the rectangle rule. The receive statement collects\nthe sums from all other processes in case \\lstinline{my_rank == 0}, else an MPI send is performed.\n\nThe above function is not very elegant. Furthermore, the MPI instructions can be simplified by using the\nfunctions \\lstinline{MPI_Reduce} or \\lstinline{MPI_Allreduce}.\nThe first function takes information from all processes and sends the result of the MPI operation to one process only,\ntypically the master node.  If we use \\lstinline{MPI_Allreduce}, the result is sent back to all processes, a feature which is\nuseful when all nodes need the value of a joint operation.  We limit ourselves to \\lstinline{MPI_Reduce} since it is only one \nprocess which will print out the final number of our calculation, The arguments to \\lstinline{MPI_Allreduce} are the same.  \n\nThe \\lstinline{MPI_Reduce} function is defined as follows\n\\begin{lstlisting}\nMPI_Reduce( void *senddata, void* resultdata, int count, MPI_Datatype datatype, MPI_Op, int root, MPI_Comm comm)\n\\end{lstlisting}\nThe two variables \\lstinline{senddata} and \\lstinline{resultdata} are obvious, besides the fact that one sends the address\nof the variable or the first element of an array.  If they are arrays they need to have the same size. \nThe variable \\lstinline{count} represents the total dimensionality, 1 in case of just one variable, while \\lstinline{MPI_Datatype} \ndefines the type of variable which is sent and received.  The new feature is \\lstinline{MPI_Op}.  \\lstinline{MPI_Op} defines the type\nof operation we want to do. \nThere are many options, see again Refs.~\\cite{mpiref,cmpi,gropp1999} for full list.  In our case, since we are summing\nthe rectangle  contributions from every process we define  \\lstinline{MPI_Op = MPI_SUM}.\nIf we have an array or matrix we can search for the largest og smallest element by sending either \\lstinline{MPI_MAX} or \n\\lstinline{MPI_MIN}.  If we want the location as well (which array element) we simply transfer \n\\lstinline{MPI_MAXLOC} or \\lstinline{MPI_MINOC}. If we want the product we write \\lstinline{MPI_PROD}. \n\\lstinline{MPI_Allreduce} is defined as\n\\begin{lstlisting}     \nMPI_Allreduce( void *senddata, void* resultdata, int count, MPI_Datatype datatype, MPI_Op, MPI_Comm comm)\n\\end{lstlisting}        \n\nThe function we list in the next example is the MPI extension of program1.cpp.  The difference is that we employ only the trapezoidal\nrule. It is easy to extend this code to include gaussian quadrature or other methods.\n\nIt is also worth noting that every process has now its own starting and ending point. \nWe read in the number of integration points $n$ and the integration limits $a$ and $b$. These are called\n\\lstinline{a} and \\lstinline{b}.\nThey serve to define the local integration limits used by every process. The local integration limits are\ndefined as \n\\begin{lstlisting}\nlocal_a = a + my_rank *(b-a)/numprocs\nlocal_b = a + (my_rank-1) *(b-a)/numprocs.\n\\end{lstlisting}\nThese two variables are transfered to the method for the trapezoidal rule.  These two methods\nreturn the local sum variable \\lstinline{local_sum}. \\lstinline{MPI_Reduce} collects all the local sums and returns the total sum,\nwhich is written out by the master node.  The program below implements this.  We have also added the possibility to\nmeasure the total time used by the code via the calls to \\lstinline{MPI_Wtime}. \n\\lstset{language=c++}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter04/program6.cpp}}]\n//    Trapezoidal rule and numerical integration using MPI with MPI_Reduce\nusing namespace std;\n#include <mpi.h>\n#include <iostream>\n\n//     Here we define various functions called by the main program\n\ndouble int_function(double );\ndouble trapezoidal_rule(double , double , int , double (*)(double));\n\n//   Main function begins here\nint main (int nargs, char* args[])\n{\n  int n, local_n, numprocs, my_rank;\n  double a, b, h, local_a, local_b, total_sum, local_sum;\n  double  time_start, time_end, total_time;\n  //  MPI initializations\n  MPI_Init (&nargs, &args);\n  MPI_Comm_size (MPI_COMM_WORLD, &numprocs);\n  MPI_Comm_rank (MPI_COMM_WORLD, &my_rank);\n  time_start = MPI_Wtime();\n  //  Fixed values for a, b and n\n  a = 0.0 ; b = 1.0;  n = 1000;\n  h = (b-a)/n;    // h is the same for all processes\n  local_n = n/numprocs;  // make sure n > numprocs, else integer division gives zero\n  // Length of each process' interval of\n  // integration = local_n*h.\n  local_a = a + my_rank*local_n*h;\n  local_b = local_a + local_n*h;\n  total_sum = 0.0;\n  local_sum = trapezoidal_rule(local_a, local_b, local_n, &int_function);\n  MPI_Reduce(&local_sum, &total_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);\n  time_end = MPI_Wtime();\n  total_time = time_end-time_start;\n  if ( my_rank == 0) {\n    cout << \"Trapezoidal rule = \" <<  total_sum << endl;\n    cout << \"Time = \" <<  total_time  << \" on number of processors: \"  << numprocs  << endl;\n  }\n  // End MPI\n  MPI_Finalize ();\n  return 0;\n}  // end of main program\n\n//  this function defines the function to integrate\ndouble int_function(double x)\n{\n  double value = 4./(1.+x*x);\n  return value;\n} // end of function to evaluate\n\n//  this function defines the trapezoidal rule\ndouble trapezoidal_rule(double a, double b, int n, double (*func)(double))\n{\n  double trapez_sum;\n  double fa, fb, x, step;\n  int    j;\n  step=(b-a)/((double) n);\n  fa=(*func)(a)/2. ;\n  fb=(*func)(b)/2. ;\n  trapez_sum=0.;\n  for (j=1; j <= n-1; j++){\n    x=j*step+a;\n    trapez_sum+=(*func)(x);\n  }\n  trapez_sum=(trapez_sum+fb+fa)*step;\n  return trapez_sum;\n}  // end trapezoidal_rule\n\n\\end{lstlisting}\nAn obvious extension of this code  is to read from file or screen the integration variables. One could also\nuse the program library to call a particular integration method.   \n\n\n\\section{An Integration Class}\nWe end thsi chapter by presenting the usage of the integral class defined in the\nprogram library. Here we have defined two header files, the \\lstinline{Function.h}\nand the \\lstinline{Integral.h} files. The program below uses the classes defined in\nthese header files  to compute the  integral \n\\[\n\\int_0^1 \\exp{(x)}\\cos{(x)}.\n\\]\n\\begin{lstlisting}\n#include <cmath>\n#include <iostream>\n#include \"Function.h\"\n#include \"Integral.h\"\n\nusing namespace std;\n\nclass ExpCos: public Function{\n  public:\n\t\t// Default constructor\n\t\tExpCos(){}\n\t\t\n\t\t// Overloaded function operator().\n\t\t// Override the function operator() of the parent class.\n    double operator()(double x){\n      return exp(x)*cos(x);\n    }\n};\n\nint main(){\n  // Declare first an object of the function to be integrated\n  ExpCos f;\n\t// Set integration bounds\n\tdouble a = 0.0; \t// Lower bound\n\tdouble b = 1.0;\t\t// Upper bound\n\tint npts = 100;\t\t// Number of integration points\n\t\n  \n  // Declared (lhs) and instantiate an integral object of type Trapezoidal\n  Integral *trapez = new Trapezoidal(a, b, npts, f);\n\tIntegral *midpt  = new MidPoint(a, b, npts, f);\n\tIntegral *gl\t\t = new Gauss_Legendre(a,b,npts, f);\n\t\n\t// Evaluate the integral of the function ExpCos and assign its \n  // value to the variable result;\n\tdouble resultTP = trapez->evaluate();\n\tdouble resultMP\t= midpt->evaluate();\n\tdouble resultGL = gl->evaluate();\n\t\n\t// Print the result to screen\n  cout << \"Result with trapezoidal\t : \" << resultTP << endl;\n\tcout << \"Result with mid-point  \t : \" << resultMP << endl;\n\tcout << \"Result with Gauss-Legendre: \" << resultGL << endl;\n}\n\\end{lstlisting}\n\nThe header file \\lstinline{Function.h} is defined as \n\\begin{lstlisting}\n/**\n* @file   Function.h\n* Interface for mathematical functions with one or more independent variables.\n* The subclasses are implemented as functors, i.e., objects behaving as functions. \n* They overload the function operator().\n*\n* Example Usage:\n// 1. Declare a functor, i.e., an object which \n// overloads the function operator().\nclass Squared: public Function{\n  public:\n    // Overload function operator()\n    double operator()(double x=0.0){\n      return x*x;\n    }\n};\n\nint main(){\n  // Instance an object Functor\n  Squared f;\n\n  // Use the instance of the object as a normal function\n  cout << f(3.0) << endl;\n}\n@endcode\n*\n**/\n\n#ifndef FUNCTION_H\n#define FUNCTION_H\n\n#include \"Array.h\"\n\nclass Function{\n  public:\n  \n\t//! Destructor\n\tvirtual ~Function(){}; // Not needed here.\n    \n    /**\n\t\t* @brief Overload the function operator().\n\t\t*\n\t\t* Used for evaluating functions with one independent variable.\n\t\t*\n\t\t**/\n    virtual double operator()(double x){}\n\t\t\n\t\t/**\n\t\t* @brief Overload the function operator().\n\t\t*\n\t\t* Used for evaluating functions with more than one independent variable.\n\t\t**/\n\t\tvirtual double operator()(const Array<double>& x){}\n};\n#endif\n\n\\end{lstlisting}\n\nThe header file \\lstinline{Integral.h} contains, with an example on how to use\nit, the following statements\n\\begin{lstlisting}\n\n#ifndef INTEGRAL_H\n#define INTEGRAL_H\n\n#include \"Array.h\"\n#include \"Function.h\"\n#include <cmath>\n\nclass Integral{\n  protected:      // Access in the subclasses.\n\t\tdouble a;     // Lower limit of integration.\n    double b;     // Upper limit of integration.\n    int npts;     // Number of integration points.\n\t\tFunction &f;  // Function to be integrated. \n\t\t\t   \n  public:\n\t\t \t\t\n\t  /**\n\t\t* @brief Constructor.\n\t\t*\n\t\t* @param lower_. Lower limit of integration.\n\t\t* @param upper_. Upper limit of integration.\n\t\t* @param npts_. Number of points of integration.\n\t\t* @param f_. Reference to a functor representing the function to be integrated.\n\t\t**/\n    Integral(double lower_, double upper_, int npts_, Function &f_);\n\n    //! Destructor\n    virtual ~Integral(){}\n\n    /**\n\t\t* @brief Evaluate the integral.\n\t\t*\t@return The value of the integral in double precision.\n\t\t**/\n    virtual double evaluate()=0;\n\n\t\t\n    // virtual forloop\n\n}; // End class Integral\n\n\n\n\n\nclass Trapezoidal: public Integral{\n\tprivate:\n\t\tdouble h; \t// Step size.\n\t\t\n  public:\n\t\t/**\n\t\t* @brief Constructor.\n\t\t*\n\t\t* @param lower_. Lower limit of integration.\n\t\t* @param upper_. Upper limit of integration.\n\t\t* @param npts_. Number of points of integration.\n\t\t* @param f_. Reference to a functor representing the function to be integrated.\n\t\t**/\n    Trapezoidal(double lower_, double upper_, int npts_, Function &f_);\n\n\t\t//! Destructor\n\t\t~Trapezoidal(){}\n    \n\t\t/** \n\t\t* Evaluate the integral of a function f using the trapezoidal rule.\n\t\t* @return The value of the integral in double precision.\n\t\t**/\n\t\tdouble evaluate();\n}; // End class Trapezoidal\n\nclass MidPoint: public Integral{\n\tprivate:\n\t\tdouble h;\t\t\t// Step size.\n\n  public:\n\t\t/**\n\t\t* @brief Constructor.\n\t\t*\n\t\t* @param lower_. Lower limit of integration.\n\t\t* @param upper_. Upper limit of integration.\n\t\t* @param npts_. Number of points of integration.\n\t\t* @param f_. Reference to a functor representing the function to be integrated.\n\t\t**/\n    MidPoint(double lower_, double upper_, int npts_, Function &f_);\n    \n\t\t//! Destructor\n    ~MidPoint(){}\n\t\t\n\t\t/**\n\t\t* Evaluate the integral of a function f using the midpoint approximation.\n\t\t*\n\t\t*\t@return The value of the integral in double precision.\n\t\t**/\n    double evaluate();\n};\n\nclass Gauss_Legendre: public Integral{\n\tprivate:\n\t\tstatic const double ZERO = 1.0E-10;\n\t\tstatic const double PI\t = 3.14159265359; \n\t\tdouble h;\n\t\t\n\tpublic:\n\t\t/**\n\t\t* @brief Constructor.\n\t\t*\n\t\t* @param lower_. Lower limit of integration.\n\t\t* @param upper_. Upper limit of integration.\n\t\t* @param npts_. Number of points of integration.\n\t\t* @param f_. Reference to a functor representing the function to be integrated.\n\t\t**/\n    Gauss_Legendre(double lower_, double upper_, int npts_, Function &f_);\n    \n\t\t//! Destructor\n    ~Gauss_Legendre(){}\n\t\t\n\t\t/** \n\t\t* Evaluate the integral of a function f using the Gauss-Legendre approximation.\n\t\t*\n\t\t* @return The value of the integral in double precision.\n\t\t**/\n    double evaluate();\n};\n#endif\n\n\n\\end{lstlisting}\n\\section{Exercises}\n\n\\begin{prob}\n\n\\end{prob}\n", "meta": {"hexsha": "591b903ab0a8ba197e0b0b35148aa51866198fd7", "size": 98015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/src/chapters/dill.tex", "max_stars_repo_name": "ManyBodyPhysics/CQMech", "max_stars_repo_head_hexsha": "8395f082392844a0e2831649aab4108324c86312", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-06-18T14:34:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T14:44:41.000Z", "max_issues_repo_path": "doc/src/chapters/dill.tex", "max_issues_repo_name": "ManyBodyPhysics/CQMech", "max_issues_repo_head_hexsha": "8395f082392844a0e2831649aab4108324c86312", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/chapters/dill.tex", "max_forks_repo_name": "ManyBodyPhysics/CQMech", "max_forks_repo_head_hexsha": "8395f082392844a0e2831649aab4108324c86312", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-02-18T15:21:45.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-18T15:21:45.000Z", "avg_line_length": 40.3852492789, "max_line_length": 186, "alphanum_fraction": 0.7091363567, "num_tokens": 29199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.67767871039338}}
{"text": "% !TeX spellcheck = en_US\n\\section{Introduction}\\label{sec:intro}\n\\subsection{SAT}\n%%% Importance\nEver since it was formulated and the Boolean satisfaction problem (SAT) is gaining an increasing interest in the field of computer science. It has a wide range of applications in various areas, ranging from hardware design to artificial intelligence (AI) and verification. SAT can be used to express many AI tasks and mathematical problems as a constraint satisfaction problems. Other theoretical applications also include automated theorem proving and model checking.\n\nSAT can be defined as the problem of finding an assignment of the propositional variables of given Boolean formula, such that the whole formula evaluates to True (satisfied).\n%%%% Other\nSAT is one of the first problems that was proven to be NP-complete, which makes it gain increased importance.\nBeing simple in its nature and construction has allowed intensive studying and optimization. Therefore, the efforts to converting problems into SAT instances to benefit from its advantages should come as no surprise.\nThroughout this paper it is assumed that the SAT problem is expressed in clausal CNF form to facilitate a common basis. % TODO\n\n\\subsection{CSP}\n%(On the other hand)\nMany famous problems such as the n-queens’ problem, map coloring and Sudoku can be easily expressed as an instance of the constraint satisfaction problem (CSP). Each CSP consists of three sets: \n\\begin{enumerate}\n\t\\item Set of variables.\n\t\\item Set of domains for each variable (usually a finite domain is chosen for all the variables).\n\t\\item Set of relations that define the constraints over a subset of the variables’ set.\n\\end{enumerate}\n\n\\subsubsection{CSP Types}\nBased on the number of the participated variables, a constraint can be classified as unary, binary or n-ary constraint. The entire CSP can be described as binary or non-binary depending on the constraints’ classification. To be consistent and for facilitate theoretical analysis only unary and binary CSP are considered in this paper.Any n-ary can be expanded and expressed in terms of binary constraints.\n\n%Studying the relationships and connections between those problems:\n% TODO \tExploit the fact that SAT is better studied and simpler in CSP solving\\\\\n", "meta": {"hexsha": "f0c0e13167a10e3f9cc0eb47a6a5f75aca90b4fc", "size": 2272, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "introduction.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": "introduction.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": "introduction.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": 84.1481481481, "max_line_length": 468, "alphanum_fraction": 0.8058978873, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152324938410783, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6775748247588798}}
{"text": "\\lab{Python}{Array Programming}{Array Programming}\n\\label{lab:Python_Vectorization}\n\nNumPy allows Python to behave like an array programming language.\nIt does this by allowing operations that normally apply only to scalars to also work seamlessly with NumPy arrays.\nSome of the benefits of allowing these types of operations are concise code and fast execution.\nArray programming allows operations on entire arrays without explicit \\li{for} loops.\nIn Python this is desirable because explicit \\li{for} loops are generally slow.\nThis lab is some fun exercises using array programming!\n\n\\section*{Shuffle}\nThis exercise is to write a program that shuffles a deck of a cards how a human would shuffle them, as opposed to having a random number generator put them in a random arrangement. \nIn order to this, first, cut the deck in half. \nSay that either the top card in the first half goes down then the top card in the second half or vice-versa.\nWhich one comes first should be random.\nFollow the same procedure for the rest of the cards in the two halves. \nThe following is the code implemented using a loop.\n\\begin{lstlisting}\nfrom random import randint\ndef shuffle(deck):\n    size = deck.size\n    newdeck = np.empty_like(deck)\n    for i in xrange(size/2):\n         if randint(0,1) == 0:\n            newdeck[i*2] = deck[i]\n            newdeck[i*2+1] = deck[size/2+i]\n         else:\n            newdeck[i*2] = deck[size/2+i]\n            newdeck[i*2+1] = deck[i]\n    return newdeck\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that shuffles a deck the same way as the function above using only array operations.\n\\end{problem}\n\n\\section*{Image Editor}\nAn image is often represented as a 3D array where the first and second dimensions are the height and width respectively and the third dimension represents the intensity of each of three color channels: red, green, and blue.\nThe code below can be used to read and display images in Python.\n\\begin{lstlisting}\nimport matplotlib.pyplot as plt\nimg = plt.imread(<image-file>)\nplt.imshow(img)\nplt.show()\n\\end{lstlisting}\n\nMatplotlib can read in \\li{.png} images on its own, otherwise it will read in images using the Python Image Library.\nDepending on the format of the image, it may be read as an array of floating point values between 0 and 1 or it may be read as an array of integer values between 0 and 255.\nIn this lab we will assume the latter.\n\n\\begin{problem}\nWrite a function that edits an array representing an image.\nInclude options that allow you to  invert the image, change it to grayscale, or add a motion blur (definitions below). \nThe function should take in a image, a parameter that tells how to modify the image, and a optional parameter for the motion blur.\nIt should then plot the image. \n\\end{problem}\n\n\\begin{itemize}\n\\item Invert:\nEvery color value for every pixel is changed to its inverse value. For example, 0 becomes 255, 230 becomes 25, and 127 becomes 128.\nRemember that the minimum color value is 0 and the maximum is 255.\n\n\\item Grayscale:\nTo convert an image to grayscale, each pixel’s color value is changed to the average of \nthe pixel’s red, green, and blue value. For example, if the pixel values are:\nRed: 225 Green: 30 Blue: 131, we convert the \n\nGrayscale coversion: $\\frac{225 + 30 + 131}{3} = 128$ (using integer division)\nRed: 128 Green: 128 Blue: 128\n\n\\item Motion Blur:\nAn additional parameter $n>0$ will be used for motion blur.\nThe value of each color of each pixel is the average of that color value for $n$ pixels (from \nthe current pixel to $n-1$) horizontally. So pixel \\li{[x,y,0]} would turn in to the average of\npixel \\li{[ x, y,0 ]} to pixel \\li{[ x,y+n-1,0]}.\nNote: You will need to use one \\li{for} loop here.\nBe sure to account for the situations where one or more of the values used in the computing the average do not exist. For example, if an image has width w and we are considering the pixel on row r, column c, if c + n >= w, then we only average the pixels up to w. (Proper array slicing should take care of this case without any extra code.)\n\n\\end{itemize}\n\n", "meta": {"hexsha": "b029c5e15d3dada4dd32a511cca4fe56c45f6077", "size": 4073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/Vectorization/Vectorization.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/Vectorization/Vectorization.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/Vectorization/Vectorization.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": 50.2839506173, "max_line_length": 340, "alphanum_fraction": 0.7498158605, "num_tokens": 1006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6775748210278134}}
{"text": "\\section{Related Work}\n\\label{sec:rw}\n% (max 1 page. You briefly describe for the methods you will use, what\n% they do and what is their role. E.g. you describe what clustering does and what\n% techniques exist for clustering.\nIn this chapter we introduce some concepts and techniques used to preprocess \nthe dataset and to find popular consistent topics in the tweets.\nWe also briefly introduce what other methods could be used to find \npopular topics.\n\n\\mathchardef\\mhyphen=\"2D\n\\subsection{TF-IDF}\n\nIn several applications, such as the one treated in this paper, \nit can be useful to categorize documents by their topic. Typically, this \nis done by finding, for each document, the words that characterize it.\n\nTerm Frequency - Inverse Document Frequency (TF-IDF) is a numerical statistic \nthat is intended to reflect how important a word is for a document in a collection.~\\cite{rw:tfidf}\nThis measure consists of a product of two components: TF and IDF.\n\n\\begin{definition}\n    The \\emph{Term Frequency} (\\emph{TF}) of a word $i$ in a document $j$ is defined as\n    \\begin{equation*}\n        \\mathit{TF}_{ij} = \\frac{\\mathit{f}_{ij}}{\\max_k{\\mathit{f}_{kj}}}\n    \\end{equation*}\n    where \n    $\\mathit{f}_{ij}$ is the number of times $i$ appears in $j$.\n\\end{definition}\n\n\\begin{definition}\n    The \\emph{Inverse Document Frequency} (\\emph{IDF}) of a word $i$ in a document $j$ is defined as\n    \\begin{equation*}\n        \\mathit{IDF}_{ij} = \\log{\\frac{N}{n_i}}\n    \\end{equation*}\n    where $N$ is the total number of documents and $n_i$ is the number of documents the word $i$\n    appears in.\n\\end{definition}\n\n\\begin{definition}\n    The \\emph{Term Frequency - Inverse Document Frequency} (\\emph{TF-IDF}) of a word $i$ in a document \n    $j$ is defined as\n    \\begin{equation*}\n        \\mathit{TF \\mhyphen IDF}_{ij} = \\mathit{TF}_{ij} * \\mathit{IDF}_{ij}\n    \\end{equation*}\n\\end{definition}\n\nAs we discuss in Section~\\ref{sec:ds}, this technique can be used to preprocess the tweets in order to \nkeep only relevant terms for each tweet. The objective is to obtain a more \nsuitable dataset, excluding words that are used frequently but \ndo not characterize the topic the tweets are about. We do this in order to obtain higher quality \nresults and also to reduce the dimension of the input, so to speed up the execution time. \n\n\\subsection{Finding Frequent Itemsets}\nA subtask of the problem consists in finding popular topics in a period of time. This task can \nbe reduced to the more general scenario in which we are given a list of\ntransactions, each containing a set of items. The problem to face is to find frequent \nitemsets, that are sets of items that appear \ntogether in many transactions, in order to find, for instance, association rules.\nThe fraction of transactions in which an itemset $i$ is present is called \\emph{support} \nof $i$, and an itemset is said to be frequent if its support is at least $s$, where \n$s$ is a threshold set in advance.\nAn algorithm that solves this task efficiently is A-Priori.\n\n\\subsubsection{A-Priori}\nThe algorithm was first introduced in 1994 by Agrawal R.S. and Srikant R. and\nit is a very fast algorithm to discover frequent itemsets in a\nlist of transactions.~\\cite{rw:apriori}\n\nThe efficiency of the algorithm is based on the following observation:\nif an itemset is frequent, then all its subsets are frequent too.\nThis property of monotonicity is exploited by the algorithm by \nseeing the implication in reverse way, that is itemsets whose \nsubsets are not all frequent can not become frequent, so a great \nquantity of potential candidates is discarded.\n\nThe idea of A-Priori is shown in Algorithm~\\ref{alg:apriori_basic}.\n\\input{algorithms/apriori_basic.tex}\n\nAt each iteration we have a set of candidate itemsets of size $k$ and \nwe find among them frequent itemsets of size $k$. \nInitially, frequent itemsets of size $1$ are the sets containing a single item.\nAt each iteration, we get the frequent itemsets of size $k$, which are \nthe itemsets among the candidates with a support at least $s$.\nThen, we build the candidates of size $k+1$, by merging two frequent itemsets \nof size $k$ and checking if all the subsets of size $k$ of the new candidate \nare frequent. We repeat this process until the set of candidates is not empty.\n\nThough A-Priori avoids counting many itemsets, there are numerous optimizations\nthat make a better use of the main memory.\n\nAmong these, PCY, the Multistage and the Multihash algorithms try to \nfurther reduce the memory used to count frequent itemsets\nthat are known an advance not to be candidates to \nbecome frequent.~\\cite{alg:pcy}\\cite{alg:multi} \n\nThe SON algorithm applies a different heuristic, by dividing the file in \nchunks that can be stored in main memory to individuate\nthe candidate frequent itemsets more rapidly.~\\cite{alg:son}\n\nIn this paper we focus just on the A-Priori algorithm, although the other\nalgorithms could be used to deal with larger datasets. ", "meta": {"hexsha": "af41dee08812f2d713a8fc9004595f1876fa2658", "size": 4964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Report/02-related_work.tex", "max_stars_repo_name": "masinag/popular_twitter_topics_mining", "max_stars_repo_head_hexsha": "b86e05d7700cfca4dbf9db67cde50664d99e60f7", "max_stars_repo_licenses": ["MIT"], "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/02-related_work.tex", "max_issues_repo_name": "masinag/popular_twitter_topics_mining", "max_issues_repo_head_hexsha": "b86e05d7700cfca4dbf9db67cde50664d99e60f7", "max_issues_repo_licenses": ["MIT"], "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/02-related_work.tex", "max_forks_repo_name": "masinag/popular_twitter_topics_mining", "max_forks_repo_head_hexsha": "b86e05d7700cfca4dbf9db67cde50664d99e60f7", "max_forks_repo_licenses": ["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.6666666667, "max_line_length": 103, "alphanum_fraction": 0.7578565673, "num_tokens": 1267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6774336912048312}}
{"text": "\\subsubsection{Yee Cell and Leapfrog Method}\n\nAccording to ref.~\\cite{yee} Eq.~\\ref{eq:maxwell} is discretized with $t=q\\Delta_t$ and $x=m\\Delta_x$ where $q,m\\in\\left\\{\\dots,-1,-\\frac{1}{2},0,\\frac{1}{2},1,\\dots\\right\\}$ and $\\Delta_x, \\Delta_t$ being the division of our space and time grid.\n\nTaking equation~\\ref{eq:maxwell} and using the time steps $q+\\frac{1}{2}$ and $q-\\frac{1}{2}$ and the partition steps $m+1$ and $m$ this gives\n\n\\begin{equation}\n  \\mu\\frac{H_y\\left[\\left(q+\\frac{1}{2}\\right)\\Delta_t, (m+\\frac{1}{2})\\Delta_x\\right]-H_y\\left[\\left(q-\\frac{1}{2}\\right)\\Delta_t, (m+\\frac{1}{2})\\Delta_x\\right]}{\\Delta_t}=\\frac{E_z\\left[q\\Delta_t, (m+1)\\Delta_x)-E_z(q\\Delta_t, m\\Delta_x)\\right]}{\\Delta_x}.\n\\end{equation}\n\nSolving for future $H_y$ yields\n\n\\begin{multline}\n  H_y\\left[\\left(q+\\frac{1}{2}\\right)\\Delta_t, \\left(m+\\frac{1}{2}\\right)\\Delta_x\\right]=H_y\\left[\\left(q-\\frac{1}{2}\\right)\\Delta_t, \\left(m+\\frac{1}{2}\\right)\\Delta_x\\right] +\\\\\n  \\underbrace{\\frac{\\Delta_t}{\\mu\\Delta_x}\\left(E_z\\left[q\\Delta_t, (m+1)\\Delta_x\\right]-E_z\\left[q\\Delta_t, m\\Delta_x\\right]\\right)}_\\text{update function for $H_y$}.\n\\end{multline}\n\nThis means the value of the magnetic field at a given point $(m+1/2)\\Delta_x$ can be calculated from it's last value and the surrounding electric fields at a prior time. The difference between $H_y((q+\\frac{1}{2})\\Delta_t)$ and $H_y((q-\\frac{1}{2})\\Delta_t)$ is called the update function.\n\nLikewise these calculations can be done for $E_z$ to get an update function to calculate the next value of $E_z$ from it's old value and the surrounding two $H_y$ values.\n\n\\begin{figure}[!h]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{./images/space-time-cell.png}\n  \\caption{Each value of $\\mathbf{E}$ at a specific time can be calculated by the former value at the same position in space one time step before and the surrounding values of $\\mathbf{H}$ half a timestep before. Following this algorithm the diagram is built from bottom to top line by line which is the reason this method is called leap frog method.}\n  \\label{fig:leapfrog}\n\\end{figure}\n\nTo get the electric field of any given system at a specific time this algorithm calculates $E_z$ and $H_y$ with $q$ starting at 0 and increasing by $\\frac{1}{2}$ until the required time $t = q\\Delta_t$ is reached, as schematically shown in figure~\\ref{fig:leapfrog}. The only required input is the initial field of $E_z$ at $q = 0$. Because this method calculates $E$ and $H$ in turns it is also called the \"leap frog method\".\n\nTo account for different materials within the system, $\\varepsilon$ can be replaced by a location or even time dependent $\\varepsilon(t, x)$.\n\n\\begin{figure}[!h]\n  \\centering\n  \\includegraphics[width=0.8\\textwidth]{./images/yeecell.jpg}\n  \\caption{To visualize the different points that are calculated during the process for three dimensions there is the so called Yee Cell that is formed by taking the points for $\\mathbf{E}$ at $q=0$ and $\\mathbf{H}$ at $q=\\frac{1}{2}$. Each value for $\\mathbf{H}$ can be calculated by its surrounding values of $\\mathbf{E}$ at the time step $q-\\frac{1}{2}$.}\n  \\label{fig:yeecell}\n\\end{figure}\n\nAnalogous to the calculation done in one dimension, the same algorithm can be applied to three dimensional space to obtain $\\mathbf{E}(\\mathbf{r}, t)$ and $\\mathbf{H}(\\mathbf{r}, t)$. By using the points $E_x$, $E_y$ and $E_z$ with the corresponding points $H_x$, $H_y$ and $H_y$ a base cell for a grid is formed. This cell is called \"Yell Cell\" and can be seen in a bigger lattice in figure~\\ref{fig:yeecell}.\n", "meta": {"hexsha": "423e566e9b19cc6ff17f05d0594860cbf9ea7420", "size": 3570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/1_theoretical_basis/18_leapfrog_method.tex", "max_stars_repo_name": "JensRavens/thesis", "max_stars_repo_head_hexsha": "73299cec14df30ad5fd0f7bde6058344ce4ed709", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-01T12:29:45.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-19T22:59:44.000Z", "max_issues_repo_path": "pages/1_theoretical_basis/18_leapfrog_method.tex", "max_issues_repo_name": "JensRavens/thesis", "max_issues_repo_head_hexsha": "73299cec14df30ad5fd0f7bde6058344ce4ed709", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pages/1_theoretical_basis/18_leapfrog_method.tex", "max_forks_repo_name": "JensRavens/thesis", "max_forks_repo_head_hexsha": "73299cec14df30ad5fd0f7bde6058344ce4ed709", "max_forks_repo_licenses": ["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.0731707317, "max_line_length": 426, "alphanum_fraction": 0.7229691877, "num_tokens": 1127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6774336888636893}}
{"text": "\\section{Infinite Sets}\n\\subsection{Countability}\nWhy $\\setn$ being infinite implies $\\setn - \\{0\\}$ being so?\n\\begin{proof}\n\\begin{align*}\n&X \\text{ being finite} \\to X \\cup \\{x\\} \\text{ being finite} \\tag{3.6.14(a)} \\\\\n\\equiv &X \\cup \\{x\\} \\text{ being infinite} \\to X  \\text{ being infinite}\n\\end{align*}\n\\end{proof}\n\n\\paragraph{Examples 8.1.3}\nWhy $f: n \\mapsto 2n$ gives a bijection? Injectivity: $m \\ne n \\to 2m \\ne 2n$; Surjectivity: $\\forall n \\in \\setn, 2n \\in f(\\setn)$.\n\n\\declareexercise{8.1.2}\nProof using induction:\n\\begin{proof}\nSuppose that for $S \\subseteq \\setn$, there is no smallest element in $S$. We now prove that $S$ must be empty.\n\nFirst, $0 \\notin S$, otherwise, 0 would be the smallest element.\n\nNow suppose that for some $N$, $\\forall n \\le N, n \\not in S$, then $N+1$ must not be in $S$, otherwise it would be the smallest number.\n\nWe can now close the induction.\n\\end{proof}\n\nProof using the least upper bound property:\n\\begin{proof}\nIt is obvious that the nonempty set $S \\subseteq \\setn$ has a lower bound. For example, $0$ is one. Therefore, $\\exists L \\in \\setr$ to be the greatest lower bound of $S$. We now show that $L$ is the smallest element of $S$.\n\n$L$ can only be an integer. Otherwise, all real numbers between $L$ and $\\ceiling{L}$ would be a lower bound bigger than $L$. In addition, $L \\in S$, otherwise, $L+1$ would be a lower bound ($\\forall x \\in S, x>L \\to x \\ge L+1$). Therefore, $L$ is the smallest number.\n\\end{proof}\n\n\\declareexercise{8.1.3}\nGap Number\n\\begin{enumerate}\n\\item $X$ must be unbounded, for any $S \\subseteq \\setn$ bounded above by $M \\in setn$ cannot have a cardinality bigger than $M+1$. Therefore $X\\setminus\\{a_m,m\\le n\\}$ is also unbounded, and is thus infinite (Remark 3.6.13).\n\\item Denote the set $\\{x \\in X: x \\neq a_m \\forall m < n\\}$ as $X_n$, and we have $X_{n} \\subseteq X_{n-1}$. Since that $a_n$ is the smallest element in $X_n$, all elements in $X_m$ for $m > n$ is bigger than $a_n$. Thus $a_{n-1} < a_n$ follows from there.\n\\item There is no equality in the previous relation.\n\\item This is nearly obvious because we are selecting elements from $X$ and its subsets.\n\\item $\\forall n \\forall m < n, a_n \\ne x \\to x \\ne a_m$.\n\\item We have both $a_0 \\ge 0$ and $a_n < a_{n+1} \\to a_{n+1} \\ge a_n + 1$. Thus $a_n > n$ can be easily shown with induction.\n\\item Otherwise $g$ could not be both bijective and increasing. If $g(m) \\ne a_m$, then $g(m) > a_m$ since $a_m$ is the smallest element in the remaining set. $g$ is a bijection, so $a_m$ must be equaled by $g(n)$ with some $n > m$, a contradiction to the fact that $g$ is increasing.  \n\\end{enumerate}\n\n\\declareexercise{8.1.4}\n\\begin{proof}\nIt is obvious that when restricted to $A$, $f$ becomes injective. Now we show that $\\forall x \\in f(N), \\exists n \\in A, f(n) = x$. \n\nSuppose for sake of contradiction that there are elements $y \\in f(N)$ such that $\\forall x \\in A, f(x) \\ne y$. Note that we must also have $\\exists n \\in \\setn \\setminus A, f(n) = y$, which means the set $S := \\setn \\setminus A$ is non-empty. $S$ is also a subset of $\\setn$, so it has a smallest element, and let's call it $m$. \n\nAll numbers between 0 and $m$ thus become elements in $A$. By definition, $m$ cannot equal to any of them, that is, $\\forall 0\\le x \\le m, f(x) \\ne f(m)$. But this implies that $m$ is an element of $A$, a contradiction.\n\nTherefore, $f: A \\to f(N)$ is a bijection. $f(N)$ then is proved to be at most countable since $A$ is a subset of $\\setn$.\n\\end{proof}\n\n\\declareexercise{8.1.5}\n\\begin{proof}\nSince $X$ is countable, there is a bijection $g: \\setn \\to X$, which gives $X = g(\\setn)$. So $f(X) = f(g(\\setn)) = f \\circ g (\\setn)$. Therefore Corollary 8.1.9 follows from Proposition 8.1.8.\n\\end{proof}\n\n\\declareexercise{8.1.6}\n\\begin{proof}\nIf $A$ is finite, then there exists a bijection $f: A \\to S = \\{m\\in \\setn : 1 \\le m \\le \\#A\\}$. Since that $S$ is a subset of $\\setn$, $f:A \\to \\setn$ is injective.\n\nIf $A$ is countable, then there is a bijection $f: A \\to \\setn$, which is itself injective.\n\nWe have proved that if $A$ is at most countable, then there is an injective function $f: A \\to \\setn$. \n\nOn the other hand, if there is an injective map $f: A \\to \\setn$, then $f: A \\to f(A)$ is a bijection. Since that $f(A)$ is a subset of $\\setn$, it is at most countable, which implies that $A$ is at most countable.\n\\end{proof}\n\n\\declareexercise{8.1.7}\n\\begin{proof}\nSince $f$ is bijective, for all $x \\in X, \\exists n \\in \\setn, f(n) = X$. But for all $n$, $h(2n) = f(n)$, so it means $h$ iterates every element of $X$. Similarly, $h$ iterates every element of $Y$. Thus, $X\\cup Y \\subseteq h(\\setn)$. But by definition, $h(\\setn) \\subseteq X \\cup Y$, so we must have $h(\\setn) = X \\cup Y$.\n\nBoth $X$ and $Y$ are infinite, so their union cannot be finite. According to Proposition 8.1.8, $X\\cup Y$ thus can only be countable.\n\\end{proof}\n\n\\declareexercise{8.1.8}\n\\begin{proof}\nSince that $X,Y$ are countable, there are two bijections: $f: \\setn \\to X, g: \\setn \\to Y$. Define $h:(m,n) \\mapsto (f(m),g(n))$, and we can see that $h$ is a bijection from $\\setn \\times \\setn$ to $X \\times Y$.\n\nBecause $\\setn \\times \\setn$ is countable, so is $X \\times Y$.\n\\end{proof}", "meta": {"hexsha": "0439b20569e07b39f824cfe1b4eda367aa1133fa", "size": 5212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Infinite Sets.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": "Infinite Sets.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": "Infinite Sets.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": 62.0476190476, "max_line_length": 330, "alphanum_fraction": 0.6728702993, "num_tokens": 1787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.6774336853519762}}
{"text": "\\chapter{Silhouettes}\n\\label{ch:silhouettes}\n\n\\newthought{Consider a two-feature data set} which we have painted in the \\widget{Paint Data} widget. We send it to the k-means clustering, tell it to find three clusters, and display the clustering in the scatter plot.\\marginnote{Don't get confused: we paint data and/or visualize it with Scatter plots, which show only two features. This is just for an illustration! Most data sets contain many features and methods like k-Means clustering take into account all features, not just two.}\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[width=\\linewidth]{paint-and-kmeans.png}\n    \\caption{$\\;$}\n\\end{marginfigure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{silhouette-from-paint.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n\nThe data points in the green cluster are well separated from those in the other two. Not so for the blue and red points, where several points are on the border between the clusters. We would like to quantify the degree of how well a data point belongs to the cluster to which it is assigned.\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[scale=0.25]{silhouette-pt1.png}\n    \\caption{Average distance A.}\n\\end{marginfigure}\n\nWe will invent a scoring measure for this and we will call it a silhouette (because this is how it's called). Our goal: a silhouette of 1 (one) will mean that the data instance is well rooted in the cluster, while the score of 0 (zero) will be assigned to data instances on the border between two clusters.\n\nFor a given data point (say the blue point in the image on the left), we can measure the distance to all the other points in its cluster and compute the average. Let us denote this average distance with A. The smaller the A, the better.\n\nOn the other hand, we would like a data point to be far away from the points in the closest neighboring cluster. The closest cluster to our blue data point is the red cluster. We can measure the distances between the blue data point and all the points in the red cluster, and again compute the average. Let us denote this average distance as B. The larger the B, the better.\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[scale=0.25]{silhouette-pt2.png}\n    \\caption{Average distance B.}\n\\end{marginfigure}\n\nThe point is well rooted within its own cluster if the distance to the points from the neighboring cluster (B) is much larger than the distance to the points from its own cluster (A), hence we compute B-A. We normalize it by dividing it with the larger of these two numbers, S  = (B -A) / max{A, B}. Voilá, S is our silhouette score.\n\nOrange has a \\widget{Silhouette Plot} widget that displays the values of the silhouette score for each data instance. We can also choose a particular data instance in the silhouette plot and check out its position in the scatter plot.\n\n\\marginnote{C3 is the green cluster, and all its points have large silhouettes. Not so for the other two.}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{silhouette-workflow.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n\nThis of course looks great for data sets with two features, where the scatter plot reveals all the information. In higher-dimensional data, the scatter plot shows just two features at a time, so two points that seem close in the scatter plot may be actually far apart when all features - perhaps thousands of gene expressions - are taken into account. \\marginnote{We selected three data instances with the worst silhouette scores. Can you guess where they lie in the scatter plot?}\n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=\\linewidth]{silhouette-outliers.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n\n\\newpage\n\nThe total quality of clustering - the silhouette of the clustering - is the average silhouette across all points. When the \\widget{k-Means} widget searches for the optimal number of clusters, it tries a different number of clusters and displays the corresponding silhouette scores.\nAh, one more thing: Silhouette Plot can be used on any data, not just on data sets that are the output of clustering. We could use it with the iris data set and figure out which class is well separated from the other two and, conversely, which data instances from one class are similar to those from another.\n\nWe don't have to group the instances by the class. For instance, the silhouette on the left would suggest that the patients from the heart disease data with typical anginal pain are similar to each other (with respect to the distance/similarity computed from all features), while those with other types of pain, especially non-anginal pain are not clustered together at all.\n\n\\begin{marginfigure}\n    \\centering\n    \\includegraphics[width=\\linewidth]{silhouette-chest-pain.png}\n    \\caption{$\\;$}\n\\end{marginfigure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{kmeans-silhouette-scores.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n", "meta": {"hexsha": "da11fab2566cc8d622bbd064d6f086e74fbca90c", "size": 5137, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/012-silhouette/silhouettes.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/012-silhouette/silhouettes.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/012-silhouette/silhouettes.tex", "max_forks_repo_name": "PrimozGodec/orange-lecture-notes", "max_forks_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-19T16:55:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T20:35:41.000Z", "avg_line_length": 67.5921052632, "max_line_length": 488, "alphanum_fraction": 0.7693206151, "num_tokens": 1195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.6774036243391882}}
{"text": "\\chapter{Variational Principles and Lagrange's Equations}\n\\section{Hamilton's Principle}\n\\subsection{Configuration Space}\n\\begin{itemize}\n\t\\item The Instantaneous configuration of a system is described by the values of $n$ generalized coordinates $q_1,    q_n$ and corresponds to a particular point in a cartesian hyperspace where the q's from the $n$  diamensional space is known as configuration space.\n\t\\item As time goes by, the state of the system changes and the system point moves in configuration space tracing out a curve, described as \"the path of motion of the system\".\n\t\\item The motion of the system then refered to the motion of the system point along this path in configuration space\n\t\\item Time can be considered formally as a parameter of the curve to each point on the path there is associated one or more values of the time. Each point on the path represent the entire system  configuration at some given instant of time.\\\\\\\\\n\t\\textbf{Monogenic System}: The mechanical systems whose motion for which all forces  (except the forces of constraint) are derivable from a generalized scalar potential that may be a function of the coordinates, velocities and time.\n\\end{itemize}\n\t\\subsection{Hamilton's Principle}\n\tThe motion of the system from time $t_1 $ to time $t_2$ is such that the line integral called the avtion or the action integral.\n\t\\begin{equation}\n\tI=\\int\\limits_{t_1}^{t_2}Ldt\n\t\\end{equation}\n\twhere $L$ is $T-V$ has stationary value for the actual path of the motion.\\\\\\\\\n\tie. out of all possible path by which the system point could travel from it's position at time $t_1$ to its position at time $t_2$. It will travel along that path for which the value of integral is stationary.\\\\\\\\\n\t$\\therefore$ Hamilton's principle can summarize by saying that the motion is such that the variation of the line integral $I$ for fixed $t_1$ and $t_2$ is zero.\n\t\\begin{equation}\n\t\t\\delta I=\\delta\\int\\limits_{t_1}^{t_2}L(q_1,.....q_n,\\dot{q}_1.....\\dot{q}_n,t)dt=0\n\t\\end{equation}\n\tWhere the system constraints are holonomic, Hamilton's principle is both a necessary and suffitient condition for lagrange's equations.\n\t\\section{Calculus of Variation}\n\tConsider a one diamensional problem, we have a function $f(y,\\dot{y},x)$ defined on a path $y-y(x)$  between two value $x_1$ and $x_2$ where $\\dot{y}$ is the derivative of $y$ with respect to $x$.\\\\\\\\\n\tTo find a particular path y(x) such that the line integral $y$ of the function $f$ between $x_1$ and $x_2$\\\\\n\t$ \\dot{y}\\equiv \\frac{dy}{dx}$\n\t\\begin{equation}\n\tJ=\\int\\limits_{x_1}^{x_2}f(y,\\dot{y},x)dx\n\t\\end{equation}\n \thas stationary value relative to paths differing infinitesimally from the correct function $y(x)$.\\\\\\\\\n \tSince $J$ must have a stationary value for the correct path relative to any neighboring path, the variation must be zero relative to some particular set of neighboring paths labeled by an infinitesimal parameter $\\alpha$.\\\\\n \tsuch a set of varied path given by \n \t\\begin{equation}\n \ty(x,\\alpha)=y(x,0)+\\alpha \\eta(x)\\label{VP-eq04}\n \t\\end{equation}\n\t$y(x,0)$- Correct path\\\\\n\t$\\eta(x)$-any function vanishes at $x=x_1$ and $x=x_2$\\\\\\\\\n\tAssume both the correct path $y(x)$ and the auxillary function $\\eta(x)$ are well behaved functions between $x_1$ and $x_2$. For such any parametric family of curves, $J$ is also a function of $\\alpha$\n\t\\begin{equation}\n\tJ(\\alpha)=\\int\\limits_{x_1}^{x_2}f(y(x,\\alpha),\\dot{y}(x,\\alpha),x)dx\n\t\\end{equation}\n\t Condition for obtaining stationary points is \n\t \\begin{equation}\n\t \\left( \\frac{dJ}{d\\alpha}\\right) _{\\alpha=0}=0\n\t \\end{equation}\n\tdifferentiating under integral sign \n\t\\begin{equation}\n\t\\frac{d J}{d \\alpha}=\\int_{x_{1}}^{x_{2}}\\left(\\frac{\\partial f}{\\partial y} \\frac{\\partial y}{\\partial \\alpha}+\\frac{\\partial f}{\\partial \\dot{y}} \\frac{\\partial \\dot{y}}{\\partial \\alpha}\\right) d x\n\t\\end{equation}\n\tFor the second term, integrating by parts\\\\\n\t\\begin{align*}\n\t\t\\int_{x_{1}}^{x_{2}} \\frac{\\partial f}{\\partial \\dot{y}} \\frac{\\partial \\dot{y}}{\\partial \\alpha} d x&=\\int_{x_{1}}^{x_{2}} \\frac{\\partial f}{\\partial \\dot{y}} \\frac{\\partial^{2} y}{\\partial x \\partial \\alpha} d x\\\\\n\t\t&=\\left.\\frac{\\partial f}{\\partial \\dot{y}} \\frac{\\partial y}{\\partial \\alpha}\\right|_{x_{1}} ^{x_{2}}-\\int_{x_{1}}^{x_{2}} \\frac{d}{d x}\\left(\\frac{\\partial f}{\\partial \\dot{y}}\\right) \\frac{\\partial y}{\\partial \\alpha} d x\n\t\\end{align*}\nAll the varied curves pass through $(x_1,y_1),(x_1,y_1)$ and hence the partial derivative of $y$ with respect to  $\\alpha$ $x_1$ and $x_2$ must vanish.\n\\begin{equation}\n\\therefore \\frac{d J}{d \\alpha}=\\int_{x_{1}}^{x_{2}}\\left(\\frac{\\partial f}{\\partial y}-\\frac{d}{d x} \\frac{\\partial f}{\\partial \\dot{y}}\\right) \\frac{\\partial y}{\\partial \\alpha} d x\n\\end{equation}\nTherefore, the condition for stationary value\n\\begin{equation}\n\\left(\\frac{dJ}{d\\alpha} \\right)_{\\alpha=0} =\\int_{x_{1}}^{x_{2}}\\left(\\frac{\\partial f}{\\partial y}-\\frac{d}{d x} \\frac{\\partial f}{\\partial \\dot{y}}\\right) \\frac{\\partial y}{\\partial \\alpha} d x=0\\label{VP-eq09}\n\\end{equation}\nWhere $\\left( \\frac{\\partial y}{\\partial \\alpha}\\right) $ is a function of $x$ that is arbitrary except for continuity and end point conditions.\n\\begin{itemize}\n\t\\item \\textit{Fundemental lemma} of calculus of variation\n\t\\begin{equation}\n\t\\text{if} \\int\\limits_{x_1}^{x_2}M(x)\\eta(x)dx=0\n\t\\end{equation}\n\t\\textit{For all arbitrary functions $\\eta (x)$ continuous through the second derivative, then $M(x)$ must identically vanish in the interval $(x_1,x_2)$}\n\\end{itemize}\n\tFor a particular parametric family of varied paths given by \\ref{VP-eq04}\n\t$$\\left(\\frac{\\partial y}{\\partial\\alpha} \\right)_0 =\\eta(x)\\text{the arbitrary function}$$\n\t$\\therefore$ from \\ref{VP-eq09} using fundamental lemma, we get \n\t\\begin{equation}\n\t\\frac{\\partial f}{dy}-\\frac{d}{dx}\\left( \\frac{\\partial f}{\\partial\\dot{y}}\\right) =0\\label{VP-11}\n\t\\end{equation}\n\t\\begin{itemize}\n\t\t\\item The infinitesimal departure of the varied path from the correct path $y(x)$ at the point $x$ and thus corresponds to virtual displacement $\\delta y$ is\n\t\t$$\\left( \\frac{\\partial y}{\\partial\\alpha}\\right)_0 d\\alpha=\\delta y$$\n\\item Similarly, infinitesimal variation of $y$ above the correct path is given as\t\t\n\t\t$$\\left( \\frac{\\partial y}{\\partial\\alpha}\\right)_0 d\\alpha=\\delta J$$\n\t\t$$\\delta J=\\int_{x_{1}}^{12}\\left(\\frac{\\partial f}{\\partial y}-\\frac{d}{d x} \\frac{\\partial f}{\\partial \\dot{y}}\\right)\\delta y\\ dx=0$$\n\t\\end{itemize}\n\\textbf{Euler-Lagrange Differential Equation}\\\\\nLet $f$ is a function of many independent variables $y_i$, and their relatives $\\dot{y}_i$. Where $y_i$ and $\\dot{y}_i$ are functions of parametric variable $x$.\n\\begin{equation}\n\\delta J=\\delta \\int_{1}^{2} f\\left(y_{1}(x) ; y_{2}(x), \\ldots, \\dot{y}_{1}(x) ; \\dot{y}_{2}(x), \\cdots, x\\right)_{d_{x}}\\label{VP-12}\n\\end{equation}\n\\begin{align*}\ny_{1}(x, \\alpha)&=y_{1}(x, 0)+\\alpha \\eta_{1}(x),\\\\\ny_{2}(x, \\alpha)&=y_{2}(x, 0)+\\alpha \\eta_{2}(x)\\\\\n\\vdots\\quad&\\hspace{1cm}\\vdots\\hspace{1.2cm}\\vdots\n\\end{align*}\nBy using fundamental lemma, the condition that $\\delta J$ is zero requires coeffitient of $\\delta y_i$ seperately vanish\n\\begin{equation}\n\\frac{\\partial f}{\\partial y_{i}}-\\frac{d}{d x} \\frac{\\partial f}{\\partial \\dot{y}_{i}}=0\\label{VP-13}\n\\end{equation}\nThis is the appropriate generalization of equation \\ref{VP-11} to several variables and known as the Euler-Lagrange differential equation.\\\\\\\\\n\\textbf{Langrange's Equation}\\\\\nFor the integral in Hamilton principle\n$$I=\\int_{1}^{2} L\\left(q_{i}, \\dot{q}_{i}, t\\right) d t$$\nhave same form as equation \\ref{VP-12}, with transformation \n$$x\\rightarrow t$$\n$$y_i\\rightarrow q_i$$\n$$f(y_i,\\dot{y}_i,x)\\rightarrow L(q_i,\\dot{q}_i,t)$$\nas we assumed $y_i$ variables are independent the corresponding $q_i$ generalized coordinates are independent which requires that the constraints be holonomic.\\\\\nThe Euler-Lagrange equation corresponding to the integral $I$ then become the Lagrange equations of motion \n$$\\frac{d}{d t} \\frac{\\partial L}{\\partial \\dot{q}_{i}}-\\frac{\\partial L}{\\partial q_{i}}=0$$\nLagrange's equations follow Hamilton's principle for monogenic systems with holonomic constraints \\\\\\\\\n\\textbf{Lagrange Undetermined Multipliers}\\\\\nused to solve systems with holonomic constraints as well as certain types of non-holonomic systems. \\\\\nIf there are $n$ variables and $m$ constraint equations $f\\alpha$ of the form\n$$f(r_1,r_2,r_3....t)=0$$\nthe extra virtual displacements are eliminated by the method of Lagrange undetermined multipliers.\n$$I=\\int_{1}^{2}\\left(L+\\sum_{\\alpha=1}^{m} \\lambda_{\\alpha} f_{a}\\right) d t$$\nallow the $q_2$ and the $\\lambda_\\alpha$ to be vary independently to obtain $n+m$ equations.\\\\\nvariations of $\\lambda_\\alpha$ gives the $m$ constraint equations the variations of the $q-i$'s give\n$$\\delta I=\\int_{1}^{2} d t\\left(\\sum_{i=1}^{n}\\left(\\frac{d}{d t} \\frac{\\partial L}{\\partial \\dot{q}_{i}}-\\frac{\\partial L}{\\partial q_{i}}+\\sum_{\\alpha=1}^{m} \\lambda_{a} \\frac{\\partial f_{a}}{\\partial q_{i}}\\right) \\delta q_{i}\\right)=0$$\nThe $\\delta q_i$'s are not independent we choose the $\\lambda_{\\alpha}$'s so that $m$ of the $n$ equations are satisfied for arbitrary $\\delta q_i$, and then choose variations of the $\\delta q_i$ in the remaining $n-m$ equations independently.\\\\\nThus we obtain $m$ equations of the form\n$$\\frac{d}{d t} \\frac{\\partial L}{\\partial \\dot{q}_{k}}-\\frac{\\partial L}{\\partial q_{k}}+\\sum_{\\alpha=1}^{m} \\lambda_{a} \\frac{\\partial f_{a}}{\\partial q_{k}}=0$$\n$Q_k$ are generalized forces\\\\\n$Q_k$ have the magnitute of the forces needed to produce the individual constraints.\\\\\\\\\n\\section{Generalized Momentum}\nIf $L$ is the Lagrangian of a system then the generalized momentum associated with the coordinate $q_j$ shall be defined as\n$$P_j=\\frac{\\partial L}{\\partial \\dot{q}_j}$$\nThe terms canonical momentum and conjugate momentum are often also used for $P_j$\\\\\nIf $q_j$ is not cartisian coordinate $P_j$ does not necessarilu have the diamensios of a linear momentum. If there is a velocity dependent potential then even with a cartesian coordinate $q_j$ the associated generalized momentum will not be indentical with mechanical momentum.\n\\section{Cyclic coordinate and Generalized Momentum Conjugate }\nIf the Lagrangian of a system does not contain a given generalized coordinate $q_j$ explicitly (although it may contain the corresponding velocity $\\dot{q}_j$ ) then the coordinate is said to be cyclic or ignorable.\n\\begin{align*}\n\\intertext{The Lagrange equation of motion}\n\\frac{d}{dt}\\left( \\frac{\\partial L}{\\partial \\dot{q}_j}\\right)-\\frac{\\partial L}{\\partial q_j} &=0\n\\intertext{reduces for cyclic coordinate, to}\n\\frac{d}{dt}\\left(\\frac{\\partial L}{\\partial \\dot{q}_j} \\right) &=0\n\\intertext{or}\n\\frac{dP_j}{dt}&=0\n\\intertext{Which means}\nP_j&=\\text{constant}\n\\therefore& \\text{The generalized momentum conjugate to a cyclic coordinate is conserved}\n\\end{align*}\n\\begin{itemize}\n\t\\item This general rule for cyclic coordinates contain all the conservation theorems discussed before \n\t\\item With proper restriction it should reduces to the conservation theorems. \n\t\\item The consevation theorems ate closely related to the symmetry properties of the system.\n\\end{itemize}\n\\begin{note}\n\tIf any system or any function representing a property of the system does not change under some operation carried on the system, the system is said to possess symmetry with respect to that operation \n\\end{note}\n\\section{Conservation of Linear Momentum}\nConsider a generalized coordinate $q_j$ for which $dq_j$ represents a translation of the system as a swhole in some given direction.\n\\begin{align*}\n\\intertext{Then $q_j$ cannot appear in $T$ for velocities are not affected by a shift in the origin}\n\\therefore \\frac{\\partial T}{\\partial q_j}=0\n\\intertext{assume a consevative system for which $V$ is not function of the velocities}\n\\therefore \\text{Lagrange's equation of motion}\\\\\n\\frac{d}{dt}\\left(\\frac{\\partial  T}{\\partial \\dot{q}_j} \\right) \\equiv\\dot{P}_j=\\frac{-\\partial V}{\\partial q_j}=Q_j\n\\intertext{Where $Q_j$ is the component of the total force along the direction of translation of $q_j$ and $P_j$ is the component of total linear momentum.}\n\\text{if}q_j\\text{ is cyclic, then}\\\\\n\\frac{-\\partial V}{\\partial q_j}\\equiv Q_j=0\n\\end{align*}\nie. conservation theorem if a geven component of the total applied force vanishes, the corresponding component of the linear momentum is conserved\\\\\n\\textit{If the system is invarient under translation along a given direction (homogeneily of space) the corresponding linear momentum is conserved}\\\\\nThen the physical properties of a closed system are not affected by an arbitrary displacement\\\\\\\\\n\\section{Conservation of Angular Momentum}\nIf a cyclic coordinate $q_j$ is such that $dq_j$ corresponds to a rotation of the system of particles around some axis, then the consevation of it's conjugate momentum corresponds to consetvation of angular momentum.\\\\\n$T$ cannot cantain $q_j$ for a rotation of the coordinate system cannot affect the magnitude of velocities.\n$$\\therefore \\frac{\\partial T}{\\partial q_j}=0$$\n$V$ is independent of $\\dot{q}_j$ as before\\\\\nIf the rotation coordinate $q_j$ is cyclic then $Q_j$, which is the component of applied torque along $\\hat{n}$ vanishes and the component of $L$ along $n$ is constant. ie angular momentum conservation.\\\\\n\\textit{If the generalized rotation coordinate is cyclic, (and conjugate angular momentum is conserved) the system is invarient under rotation (homogeneily of angle) ie properties of closed system will not change due to arbitrary rotation about the origin of the frame of reference.}\n\\section{Aspects of Lagrangian Formulation}\nA system with $n$ degrees of freesom possess $x$ equations of motion of the form\n$$\\frac{d}{dt}\\left( \\frac{\\partial L}{\\partial \\dot{q}_1}\\right)-\\frac{\\partial L}{\\partial q_1}=0 $$\n\\begin{itemize}\n\t\\item Equations are of second order\n\t\\item motion of the system is determined for all time only when $2n$ initial values are specified\n\t\\item State of the system represented by a point in aa $n$ dimentional configuration space whose coordinaes are the $n$ generalized coordinates $q_j$\n\t\\item The Lagrangian view point a system with $n$ independent degrees of freedom is a problem in $n$ independent variables $q_i(1), $ and  $\\dot{q}_i$ appears only as a shorthand for the time derivative of $q_i$\n\t\\item All $n$ coordinates must be independent\n\\end{itemize}\n\\newpage\n\\begin{abox}\n\tPractise set-01\n\\end{abox}\n\\begin{enumerate}\n\t\\item A double pendulum consists of two point masses $m$ attached by strings of length $l$ as shown in the figure: The kinetic energy of the pendulum is\n\t{\\exyear{NET/JRF(DEC-2011)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4.5cm]{diagram-20210926(1)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2} m l^{2}\\left[\\dot{\\theta}_{1}^{2}+\\dot{\\theta}_{2}^{2}\\right]$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2} m l^{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\\task[\\textbf{C.}] $\\frac{1}{2} m l^{2}\\left[\\dot{\\theta}_{1}^{2}+2 \\dot{\\theta}_{2}^{2}+2 \\dot{\\theta}_{1} \\dot{\\theta}_{2} \\cos \\left(\\theta_{1}-\\theta_{2}\\right)\\right]$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{2} m l^{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\\end{tasks}\n\t\\item A particle of mass $m$ moves inside a bowl. If the surface of the bowl is given by the equation $z=\\frac{1}{2} a\\left(x^{2}+y^{2}\\right)$, where $a$ is a constant, the Lagrangian of the particle is\n\t{\\exyear{NET/JRF(DEC-2011)}}\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} \\theta \\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\\item The Lagrangian of a particle of mass $m$ moving in one dimension is given by\n\t$$\n\tL=\\frac{1}{2} m \\dot{x}^{2}-b x\n\t$$\n\twhere $b$ is a positive constant. The coordinate of the particle $x(t)$ at time $t$ is given by: (in following $c_{1}$ and $c_{2}$ are constants)\n\t{\\exyear{NET/JRF(JUNE-2013)}}\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} \\sinh \\left(\\frac{b t}{m}\\right)$\n\t\\end{tasks}\t\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{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\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 $L_{z}$\n\t\\end{tasks}\n\t\\item A pendulum consists of a ring of mass $M$ and radius $R$ suspended by a massless rigid rod of length $l$ attached to its rim. When the pendulum oscillates in the plane of the ring, the time period of oscillation is\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $2 \\pi \\sqrt{\\frac{l+R}{g}}$\n\t\t\\task[\\textbf{B.}] $\\frac{2 \\pi}{\\sqrt{g}}\\left(l^{2}+R^{2}\\right)^{1 / 4}$\n\t\t\\task[\\textbf{C.}] $2 \\pi \\sqrt{\\frac{2 R^{2}+2 R l+l^{2}}{g(R+l)}}$\n\t\t\\task[\\textbf{D.}] $\\frac{2 \\pi}{\\sqrt{g}}\\left(2 R^{2}+2 R l+l^{2}\\right)^{1 / 4}$\n\t\\end{tasks}\t\n\t\\item Consider a particle of mass $m$ attached to two identical springs each of length $l$ and spring constant $k$ (see the figure). The equilibrium configuration is the one where the springs are unstretched. There are no other external forces on the system. If the particle is given a small displacement along the $x$-axis, which of the following describes the equation of motion for small oscillations?\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{diagram-20210926(18)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $m \\ddot{x}+\\frac{k x^{3}}{l^{2}}=0$\n\t\t\\task[\\textbf{B.}]  $m \\ddot{x}+k x=0$\n\t\t\\task[\\textbf{C.}] $m \\ddot{x}+2 k x=0$\n\t\t\\task[\\textbf{D.}] $m \\ddot{x}+\\frac{k x^{2}}{l}=0$\n\t\\end{tasks}\t\n\t\\item The equation of motion of a system described by the time-dependent Lagrangian\n\t$$\n\tL=e^{\\gamma t}\\left[\\frac{1}{2} m \\dot{x}^{2}-V(x)\\right] \\text { is }\n\t$$\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $m \\ddot{x}+\\gamma m \\dot{x}+\\frac{d V}{d x}=0$\n\t\t\\task[\\textbf{B.}] $m \\ddot{x}+\\gamma m \\dot{x}-\\frac{d V}{d x}=0$\n\t\t\\task[\\textbf{C.}]  $m \\ddot{x}-\\gamma m \\dot{x}+\\frac{d V}{d x}=0$\n\t\t\\task[\\textbf{D.}] $m \\ddot{x}+\\frac{d V}{d x}=0$\n\t\\end{tasks}\n\t\\item A particle of unit mass moves in the $x y$-plane in such a way that $\\dot{x}(t)=y(t)$ and $\\dot{y}(t)=-x(t) .$ We can conclude that it is in a conservative force-field which can be derived from the potential\n\t{\\exyear{NET/JRF(JUNE-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2}\\left(x^{2}+y^{2}\\right)$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2}\\left(x^{2}-y^{2}\\right)$\n\t\t\\task[\\textbf{C.}] $x+y$\n\t\t\\task[\\textbf{D.}] $x-y$\n\t\\end{tasks}\t\n\t\\item The Lagrangian of a particle moving in a plane s given in Cartesian coordinates as\n\t$$\n\tL=\\dot{x} \\dot{y}-x^{2}-y^{2}\n\t$$\n\tIn polar coordinates the expression for the canonical momentum $p_{r}$ (conjugate to the radial coordinate $r$ ) is\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\dot{r} \\sin \\theta+r \\dot{\\theta} \\cos \\theta$\n\t\t\\task[\\textbf{B.}]  $\\dot{r} \\cos \\theta+r \\dot{\\theta} \\sin \\theta$\n\t\t\\task[\\textbf{C.}] $2 \\dot{r} \\cos \\theta-r \\dot{\\theta} \\sin 2 \\theta$\n\t\t\\task[\\textbf{D.}] $\\dot{r} \\sin 2 \\theta+r \\dot{\\theta} \\cos 2 \\theta$\n\t\\end{tasks}\n\t\\item The dynamics of a particle governed by the Lagrangian\n\t$$\n\tL=\\frac{1}{2} m \\dot{x}^{2}-\\frac{1}{2} k x^{2}-k x \\dot{x} t \\text { describes }\n\t$$\n\t{\\exyear{NET/JRF(DEC-2016)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] An undamped simple harmonic oscillator\n\t\t\\task[\\textbf{B.}] A damped harmonic oscillator with a time varying damping factor\n\t\t\\task[\\textbf{C.}]  An undamped harmonic oscillator with a time dependent frequency\n\t\t\\task[\\textbf{D.}] A free particle\n\t\\end{tasks}\t\n\t\\item The parabolic coordinates $(\\xi, \\eta)$ are related to the Cartesian coordinates $(x, y)$ by $x=\\xi \\eta$ and $y=\\frac{1}{2}\\left(\\xi^{2}-\\eta^{2}\\right)$. The Lagrangian of a two-dimensional simple harmonic oscillator of mass $m$ and angular frequency $\\omega$ is\n\t{\\exyear{NET/JRF(DEC-2016)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2} m\\left[\\dot{\\xi}^{2}+\\dot{\\eta}^{2}-\\omega^{2}\\left(\\xi^{2}+\\eta^{2}\\right)\\right]$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2} m\\left(\\xi^{2}+\\eta^{2}\\right)\\left[\\left(\\dot{\\xi}^{2}+\\dot{\\eta}^{2}\\right)-\\frac{1}{4} \\omega^{2}\\left(\\xi^{2}+\\eta^{2}\\right)\\right]$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{2} m\\left(\\xi^{2}+\\eta^{2}\\right)\\left[\\dot{\\xi}^{2}+\\dot{\\eta}^{2}-\\frac{1}{2} \\omega^{2} \\xi \\eta\\right]$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{2} m\\left(\\xi^{2}+\\eta^{2}\\right)\\left[\\dot{\\xi}^{2}+\\dot{\\eta}^{2}-\\frac{1}{4} \\omega^{2}\\right]$\n\t\\end{tasks}\t\n\t\\item The spring constant $k$ of a spring of mass $m_{s}$ is determined experimentally by loading the spring with mass $M$ and recording the time period $T$, for a single oscillation. If the experiment is carried out for different masses, then the graph that correctly represents the result is\n\t{\\exyear{NET/JRF(DEC-2017)}}\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=4.5cm]{diagram-20210926(38)-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=4.5cm]{diagram-20210926(39)-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=4.5cm]{diagram-20210926(40)-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=4.5cm]{diagram-20210926(41)-crop}\n\t\t\\end{figure}\n\t\\end{tasks}\t\n\t\\item The motion of a particle in one dimension is described by the Langrangian $L=\\frac{1}{2}\\left(\\left(\\frac{d x}{d t}\\right)^{2}-x^{2}\\right)$ in suitable units. The value of the action along the classical path from $x=0$ at $t=0$ to $x=x_{0}$ at $t=t_{0}$, is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{x_{0}^{2}}{2 \\sin ^{2} t_{0}}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2} x_{0}^{2} \\tan t_{0}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{2} x_{0}^{2} \\cot t_{0}$\n\t\t\\task[\\textbf{D.}] $\\frac{x_{0}^{2}}{2 \\cos ^{2} t_{0}}$\n\t\\end{tasks}\t\n\t\\item Two particles of masses $m_{1}$ and $m_{2}$ are connected by a massless thread of length $l$ as shown in figure below.\\\\\n\tThe particle of mass in on the plane undergoes a circular motion with radius $r_{0}$ and angular momentum $L$. When a small radial displacement $\\in$ (whew $\\in \\ll<r_{0}$ ) is applied, its radial coordinate is found to oscillate about $r_{0}$. The frequency of the oscillations is\n\t{\\exyear{NET/JRF(JUNE-2019)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\sqrt{\\frac{7 m_{2} g}{\\left(m_{1}+\\frac{m_{2}}{2}\\right) r_{0}}}$\n\t\t\\task[\\textbf{B.}] $\\sqrt{\\frac{7 m_{2} g}{\\left(m_{1}+m_{2}\\right) r_{0}}}$\n\t\t\\task[\\textbf{C.}] $\\sqrt{\\frac{3 m_{2} g}{\\left(m_{1}+\\frac{m_{2}}{2}\\right) r_{0}}}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{\\frac{3 m_{2} g}{\\left(m_{1}+m_{2}\\right) r_{0}}}$\n\t\\end{tasks}\t\n\t\\item Which of the following terms, when added to the Lagrangian $L(x, y, \\dot{x}, \\dot{y})$ of a system with two degrees of freedom will not change the equations of motion?\\\\\n\t(check question )\n\t{\\exyear{NET/JRF(DEC-2019)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $x \\ddot{x}-y \\ddot{y}$\n\t\t\\task[\\textbf{B.}] $x \\ddot{y}-y \\ddot{x}$\n\t\t\\task[\\textbf{C.}] $x \\dot{y}-y \\dot{x}$\n\t\t\\task[\\textbf{D.}] $y \\dot{x}^{2}+x \\dot{y}^{2}$ \n\t\\end{tasks}\n\t\\item A point mass $m$, is constrained to move on the inner surface of a paraboloid of revolution $x^{2}+y^{2}=a z$ (where $a>0$ is a constant). When it spirals down the surface, under the influence of gravity (along $-z$ direction), the angular speed about the $z$-axis is proportional to\n\t{\\exyear{NET/JRF(JUNE-2020)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] 1 (independent of $z$ )\n\t\t\\task[\\textbf{B.}] $z$\n\t\t\\task[\\textbf{C.}]  $z^{-1}$\n\t\t\\task[\\textbf{D.}] $z^{-2}$\n\t\\end{tasks}\t\n\\end{enumerate}\n\\newpage\n\\begin{abox}\n\tPractise set-02\n\\end{abox}\n\\begin{enumerate}\n\t\\item A particle of mass $m$ slides under the gravity without friction along the parabolic path $y=a x^{2}$, as shown in the figure. Here $a$ is a constant.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{diagram-20210915(2)-crop}\n\t\\end{figure}\n\tThe Lagrangian for this particle is given by\n\t{\t\\exyear{GATE 2012}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $L=\\frac{1}{2} m \\dot{x}^{2}-m g a x^{2}$\n\t\t\\task[\\textbf{B.}] $L=\\frac{1}{2} m\\left(1+4 a^{2} x^{2}\\right) \\dot{x}^{2}-m g a x^{2}$\n\t\t\\task[\\textbf{C.}] $L=\\frac{1}{2} m \\dot{x}^{2}+m g a x^{2}$\n\t\t\\task[\\textbf{D.}] $L=\\frac{1}{2} m\\left(1+4 a^{2} x^{2}\\right) \\dot{x}^{2}+m g a x^{2}$\n\t\\end{tasks}\n\t\\item  The Lagrange's equation of motion of the particle for above question is given by\n\t{\\exyear{GATE 2012}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\ddot{x}=2 g a x$\n\t\t\\task[\\textbf{B.}] $m\\left(1+4 a^{2} x^{2}\\right) \\ddot{x}=-2 m g a x-4 m a^{2} x \\dot{x}^{2}$\n\t\t\\task[\\textbf{C.}] $m\\left(1+4 a^{2} x^{2}\\right) \\ddot{x}=2 m g a x+4 m a^{2} x \\dot{x}^{2}$\n\t\t\\task[\\textbf{D.}] $\\ddot{x}=-2 g a x$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{d}{d t}\\left(\\frac{d L}{d \\dot{x}}\\right)&=\\frac{d L}{d x} \\Rightarrow m \\ddot{x}\\left(1+4 a^{2} x^{2}\\right)\\\\&=-4 m a^{2} x \\dot{x}^{2}-2 m g a x\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\t\n\t\\item The Lagrangian of a system with one degree of freedom $q$ is given by $L=\\alpha \\dot{q}^{2}+\\beta q^{2}$, where $\\alpha$ and $\\beta$ are non-zero constants. If $p_{q}$ denotes the canonical momentum conjugate to $q$ then which one of the following statements is CORRECT?\n\t{\\exyear{GATE 2013}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $p_{q}=2 \\beta q$ and it is a conserved quantity.\n\t\t\\task[\\textbf{B.}]  $p_{q}=2 \\beta q$ and it is not a conserved quantity.\n\t\t\\task[\\textbf{C.}] $p_{q}=2 \\alpha \\dot{q}$ and it is a conserved quantity.\n\t\t\\task[\\textbf{D.}]  $p_{q}=2 \\alpha \\dot{q}$ and it is not a conserved quantity.\n\t\\end{tasks}\n\t\\item A bead of mass $m$ can slide without friction along a massless rod kept at $45^{\\circ}$ with the vertical as shown in the figure. The rod is rotating about the vertical axis with a constant angular speed $\\omega$. At any instant $r$ is the distance of the bead from the origin. The momentum conjugate to $r$ is\n\t{\\exyear{GATE 2014}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=7cm]{diagram-20210915(4)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $m \\dot{r}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{\\sqrt{2}} m \\dot{r}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{2} m \\dot{r}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{2} m \\dot{r}$\n\t\\end{tasks}\n\t\\item The Lagrangian of a system is given by\n\t$L=\\frac{1}{2} m l^{2}\\left[\\dot{\\theta}^{2}+\\sin ^{2} \\theta \\dot{\\varphi}^{2}\\right]-m g l \\cos \\theta$, where $m, l$ and $g$ are constants.\n\tWhich of the following is conserved?\n\t{\\exyear{GATE 2016}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\dot{\\varphi} \\sin ^{2} \\theta$\n\t\t\\task[\\textbf{B.}] $\\dot{\\varphi} \\sin \\theta$\n\t\t\\task[\\textbf{C.}] $\\frac{\\dot{\\varphi}}{\\sin \\theta}$\n\t\t\\task[\\textbf{D.}] $\\frac{\\dot{\\varphi}}{\\sin ^{2} \\theta}$\n\t\\end{tasks}\n\t\\item If the Lagrangian $L_{0}=\\frac{1}{2} m\\left(\\frac{d q}{d t}\\right)^{2}-\\frac{1}{2} m \\omega^{2} q^{2}$ is modified to $L=L_{0}+\\alpha q\\left(\\frac{d q}{d t}\\right)$, which one of the following is TRUE?\n\t{\\exyear{GATE 2017}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] Both the canonical momentum and equation of motion do not change\n\t\t\\task[\\textbf{B.}] Canonical momentum changes, equation of motion does not change\n\t\t\\task[\\textbf{C.}] Canonical momentum does not change, equation of motion changes\n\t\t\\task[\\textbf{D.}] Both the canonical momentum and equation of motion change\n\t\\end{tasks}\n\t\\item  A double pendulum consists of two equal masses $m$ suspended by two strings of length $l$. What is the Lagrangian of this system for oscillations in a plane? Assume the angles $\\theta_{1}, \\theta_{2}$ made by the two strings are small (you can use $\\cos \\theta=1-\\theta^{2} / 2$ ).\\\\\n\tNote: $\\omega_{0}=\\sqrt{g / l}$.\n\t{\\exyear{JEST 2014}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $L \\approx m l^{2}\\left(\\dot{\\theta}_{1}^{2}+\\frac{1}{2} \\dot{\\theta}_{2}^{2}-\\omega_{0}^{2} \\theta_{1}^{2}-\\frac{1}{2} \\omega_{0}^{2} \\theta_{2}^{2}\\right)$\n\t\t\\task[\\textbf{B.}]  $L \\approx m l^{2}\\left(\\dot{\\theta}_{1}^{2}+\\frac{1}{2} \\dot{\\theta}_{2}^{2}+\\dot{\\theta}_{1} \\dot{\\theta}_{2}-\\omega_{0}^{2} \\theta_{1}^{2}-\\frac{1}{2} \\omega_{0}^{2} \\theta_{2}^{2}\\right)$\n\t\t\\task[\\textbf{C.}] $L \\approx m l^{2}\\left(\\dot{\\theta}_{1}^{2}+\\frac{1}{2} \\dot{\\theta}_{2}^{2}-\\dot{\\theta}_{1} \\dot{\\theta}_{2}-\\omega_{0}^{2} \\theta_{1}^{2}-\\frac{1}{2} \\omega_{0}^{2} \\theta_{2}^{2}\\right)$\n\t\t\\task[\\textbf{D.}]  $L \\approx m l^{2}\\left(\\frac{1}{2} \\dot{\\theta}_{1}^{2}+\\frac{1}{2} \\dot{\\theta}_{2}^{2}+\\dot{\\theta}_{1} \\dot{\\theta}_{2}-\\omega_{0}^{2} \\theta_{1}^{2}-\\omega_{0}^{2} \\theta_{2}^{2}\\right)$\n\t\\end{tasks}\n\t\\item A bike stuntman rides inside a well of frictionless surface given by $z=a\\left(x^{2}+y^{2}\\right)$, under the action of gravity acting in the negative $z$ direction. $\\vec{g}=-g \\hat{z} .$ What speed should be maintain to be able to ride at a constant height $z_{0}$ without falling down?\n\t{\\exyear{JEST 2015}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $\\sqrt{g z_{0}}$\n\t\t\\task[\\textbf{B.}] $\\sqrt{3 g z_{0}}$\n\t\t\\task[\\textbf{C.}] $\\sqrt{2 g z_{0}}$\n\t\t\\task[\\textbf{D.}] The biker will not be able to maintain a constant height, irrespective of speed.\n\t\\end{tasks}\n\t\\item The Lagrangian of a particle is given by $L=\\dot{q}^{2}-q \\dot{q}$. Which of the following statements is true?\n\t{\\exyear{JEST 2015}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}]  This is a free particle\n\t\t\\task[\\textbf{B.}] The particle is experiencing velocity dependent damping\n\t\t\\task[\\textbf{C.}] The particle is executing simple harmonic motion\n\t\t\\task[\\textbf{D.}] The particle is under constant acceleration.\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\because L&=\\dot{q}^{2}-q \\dot{q} \\Rightarrow \\frac{\\partial L}{\\partial \\dot{q}}\\\\&=2 \\dot{q}-q \\Rightarrow \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{q}}\\right)\\\\&=2 \\ddot{q}-\\dot{q}\\\\\n\t\t\\because \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{q}}\\right)-\\frac{\\partial L}{\\partial q}&=0\n\t\t\\Rightarrow 2 \\ddot{q}-\\dot{q}+\\dot{q}\\\\&=0 \\Rightarrow 2 \\ddot{q}=0 \\Rightarrow \\frac{d^{2} q}{d t^{2}}\\\\&=0 \\Rightarrow \\frac{d q}{d t}=C \\Rightarrow q=C t+\\alpha\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\t\n\t\\item A hoop of radius a rotates with constant angular velocity $\\omega$ about the\n\tvertical axis as shown in the figure. A bead of mass $m$ can slide on the\n\thoop without friction. If $g<\\omega^{2} a$ at what angle $\\theta$ apart from 0 and $\\pi$ is the bead stationary (i.e., $\\frac{d \\theta}{d t}=\\frac{d^{2} \\theta}{d t^{2}}=0$ )?\n\t{\\exyear{JEST 2016}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.2cm,width=3.5cm]{diagram-20210809(11)-crop}\n\t\t\\caption{}\n\t\t\\label{}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\tan \\theta=\\frac{\\pi g}{\\omega^{2} a}$\n\t\t\\task[\\textbf{B.}] $\\sin \\theta=\\frac{g}{\\omega^{2} a}$\n\t\t\\task[\\textbf{C.}] $\\cos \\theta=\\frac{g}{\\omega^{2} a}$\n\t\t\\task[\\textbf{D.}] $\\tan \\theta=\\frac{g}{\\pi \\omega^{2} a}$\n\t\\end{tasks}\n\t\\item A bead of mass $M$ slides along a parabolic wire described by $z=2\\left(x^{2}+y^{2}\\right)$. The wire rotates with angular velocity $\\Omega$ about the $z$ - axis. At what value of $\\Omega$ does the bead maintain a constant nonzero height under the action of gravity along $-\\hat{z}$ ?\n\t{\\exyear{JEST 2017}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\sqrt{3 g}$\n\t\t\\task[\\textbf{B.}] $\\sqrt{g}$\n\t\t\\task[\\textbf{C.}] $\\sqrt{2 g}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{4 g}$\n\t\\end{tasks}\n\t\\item A possible Lagrangian for a free particle is\n\t{\\exyear{JEST 2017}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $L=\\dot{q}^{2}-q^{2}$\n\t\t\\task[\\textbf{B.}] $L=\\dot{q}^{2}-q \\dot{q}$\n\t\t\\task[\\textbf{C.}] $L=\\dot{q}^{2}-q$\n\t\t\\task[\\textbf{D.}] $L=\\dot{q}^{2}-\\frac{1}{q}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{q}}\\right)-\\left(\\frac{\\partial L}{\\partial q}\\right)&=0 \\Rightarrow 2 \\ddot{q}-\\dot{q}+\\dot{q}\\\\&=0 \\Rightarrow \\ddot{q}=0\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\t\n\t\\item  A rod of mass $m$ and length $l$ is suspended from two massless vertical springs with a spring constants $k_{1}$ and $k_{2} .$ What is the Lagrangian for the system, if $x_{1}$ and $x_{2}$ be the displacements from equilibrium position of the two ends of the rod?\n\t{\\exyear{JEST 2017}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{m}{8}\\left(\\dot{x}_{1}^{2}+2 \\dot{x}_{1} \\dot{x}_{2}+\\dot{x}_{2}^{2}\\right)-\\frac{1}{2} k_{1} x_{1}^{2}-\\frac{1}{2} k_{2} x_{2}^{2}$\n\t\t\\task[\\textbf{B.}] $\\frac{m}{2}\\left(\\dot{x}_{1}^{2}+\\dot{x}_{1} \\dot{x}_{2}+\\dot{x}_{2}^{2}\\right)-\\frac{1}{4}\\left(k_{1}+k_{2}\\right)\\left(x_{1}^{2}+x_{2}^{2}\\right)$\n\t\t\\task[\\textbf{C.}] $\\frac{m}{6}\\left(\\dot{x}_{1}^{2}+x_{1} \\dot{x}_{2}+\\dot{x}_{2}^{2}\\right)-\\frac{1}{2} k_{1} x_{1}^{2}-\\frac{1}{2} k_{2} x_{2}^{2}$\n\t\t\\task[\\textbf{D.}] $\\frac{m}{2}\\left(\\dot{x}_{1}^{2}-2 \\dot{x}_{1} \\dot{x}_{2}+\\dot{x}_{2}^{2}\\right)-\\frac{1}{4}\\left(k_{1}-k_{2}\\right)\\left(x_{1}^{2}+x_{2}^{2}\\right)$\n\t\\end{tasks}\n\t\\item Consider the Lagrangian\n\t$$L=1-\\sqrt{1-\\dot{q}^{2}}-\\frac{q^{2}}{2}$$\n\tof a particle executing oscillations whose amplitude is $A$. If $p$ denotes the momentum of the particle, then $4 p^{2}$ is\n\t{\\exyear{JEST 2015}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] (a) $\\left(A^{2}-q^{2}\\right)\\left(4+A^{2}-q^{2}\\right)$\n\t\t\\task[\\textbf{B.}] $\\left(A^{2}+q^{2}\\right)\\left(4+A^{2}-q^{2}\\right)$\n\t\t\\task[\\textbf{C.}] $\\left(A^{2}-q^{2}\\right)\\left(4+A^{2}+q^{2}\\right)$\n\t\t\\task[\\textbf{D.}] $\\left(A^{2}+q^{2}\\right)\\left(4+A^{2}+q^{2}\\right)$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\t\n\t\\item Consider the motion of a particle in two dimensions given by the Lagrangian $$L=\\frac{m}{2}\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)-\\frac{\\lambda}{4}(x+y)^{2}$$\n\twhere $\\lambda>0$. The initial conditions are given as $y(0)=0, x(0)=42$ meters, $\\dot{x}(0)=\\dot{y}(0)=0$. What is the value of $x(t)-y(t)$ at $t=25$ seconds in meters?\n\t{\\exyear{JEST 2019}}\n\\end{enumerate}\n\\newpage\n\\begin{abox}\n\tPractise set-03\n\\end{abox}\n\\begin{enumerate}\n\t\\item A particle of mass $m$ moves inside a bowl under gravity. If the surface of the bowl is given by the equation $z=\\frac{1}{2} a\\left(x^{2}+y^{2}\\right)$, where $a$ is a constant.\\\\\n\t\t(a) Write down Lagrangian of the system in cylindrical coordinate.\\\\\n\t\t(b) Identify the cyclic coordinate and law of conservation of momentum.\\\\\n\t\t(c) Write down the equation of motion\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{There is only one particle, so }N&=1\\\\\n\t\t\\text{Cartesian coordinate kinetic energy is }T&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)\\text{ and potential energy is} V=m g z\n\t\t\\intertext{Equation of Constraint is -}\n\t\t\\intertext{1. Particle is constrained to move on surface of a bowl, so the equation of constraint is}\n\t\tz&=\\frac{1}{2} a\\left(x^{2}+y^{2}\\right) \\text {, so } k=1\\\\\n\t\t\\text{Degree of freedom }( DOF) &=3 N-k=3 \\times 1-1=2\n\t\t\\intertext{Hence, there are two degree of freedom, so we need two generalized coordinates.}\n\t\t\\intertext{Now transforming the Cartesian coordinate to cylindrical coordinate, $x=r \\cos \\theta, y=r \\sin \\theta$, z=z}\n\t\t\\intertext{So, the kinetic energy is $T=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+\\dot{z}^{2}\\right)$. And the equation of constraint in cylindrical coordinate $\\left(z=\\frac{1}{2} a r^{2}\\right)$ is written as $\\dot{z}=a r \\dot{r}$}\n\t\t\\intertext{So, kinetic energy for two degree of freedom with suitable coordinate is given by, $T=\\frac{m}{2}\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+a^{2} r^{2} \\dot{r}^{2}\\right)$ and potential energy $V=\\frac{m g a r^{2}}{2}$}\n\t\tT=\\frac{m}{2}\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+a^{2} r^{2} \\dot{r}^{2}\\right)&\\text{ and potential energy }V=\\frac{m g a r^{2}}{2}\\\\\n\t\t\\text{So, Lagrangian is }L&=\\frac{m}{2}\\left[\\dot{r}^{2}\\left(1+a^{2} r^{2}\\right)+r^{2} \\dot{\\theta}^{2}-a g r^{2}\\right]\n\t\t\\intertext{(b) Hence, $\\frac{\\partial L}{\\partial \\theta}=0$ so, $\\theta$ is cyclic coordinate hence $p_{\\theta}=\\frac{\\partial L}{\\partial \\dot{\\theta}}=m r^{2} \\dot{\\theta}$ is a constant of motion, which is identified as angular momentum of the system. So angular momentum of the system is conserved.}\n\t\t\\text{\t(c) If Lagrangian of the system is } L&=\\frac{m}{2}\\left[\\dot{r}^{2}\\left(1+a^{2} r^{2}\\right)+r^{2} \\dot{\\theta}^{2}-a g r^{2}\\right]\\text{ then}\\\\\n\t\t\\text{Equation of Motion is }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}=0\\\\\n\t\t\\left(\\frac{\\partial L}{\\partial r}\\right)&=m \\dot{r}^{2} a^{2} r+m r \\dot{\\theta}^{2}-m a g r\\text{ and }\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)=m \\dot{r}\\left(1+a^{2} r^{2}\\right)\\\\\n\t\t\\Rightarrow \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)&=m \\ddot{r}\\left(1+a^{2} r^{2}\\right)+m \\dot{r} a^{2} 2 r \\dot{r}=m \\ddot{r}\\left(1+a^{2} r^{2}\\right)+2 m a^{2} r \\dot{r}^{2}\\\\\n\t\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}&=0 \\Rightarrow m \\ddot{r}\\left(1+a^{2} r^{2}\\right)+2 m a^{2} r \\dot{r}^{2}-m a^{2} r \\dot{r}^{2}-m r \\dot{\\theta}^{2}+m a g r=0\\\\\n\t\t\\Rightarrow m \\ddot{r}\\left(1+a^{2} r^{2}\\right)&+m a^{2} r^{2}-m r \\dot{\\theta}^{2}+m a g r=0\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A mass $m$ is attached to one end of spring with spring constant $k$ and natural length $l$. The other end is pivoted at point $O$ as shown in figure. If the particle is constrained to move in $x-y$ plane under gravity (in $y$ direction)\\\\\n\t\t(a) Write down the expression for kinetic energy and potential energy.\\\\\n\t\t(b) Write down Lagarngian in Cartesian coordinate system.\\\\\n\t\t(c) Transform the Lagrangian in suitable coordinate system.\\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.8cm,width=5.5cm]{VP-01}\n\t\t\\end{figure}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{ (a) Number of particle $N=1$, kinetic energy is given by $T=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)$, potential energy is given by $V=-m g y .$}\n\t\t\\intertext{Equation of Constraint is -}\n\t\t\\text{The particle is constrained to move in }&x-y\\text{ plane so equation of constraint }z=0 \\Rightarrow k=1\\\\\n\t\t\\text{So, degree of freedom }( \\text{ DOF } )&=3 N-K=3 \\times 1-1=2\n\t\t\\intertext{If degree of freedom is two then there must be two independent motion.}\n\t\tz&=0 \\Rightarrow \\dot{z}=0\n\t\t\\intertext{So, $T=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)$ and $V=-m g y+\\frac{1}{2} k\\left[\\sqrt{\\left(x^{2}+y^{2}\\right)}-l\\right]^{2}$ (potential energy due to gravity and stored energy due to spring).}\n\t\t\\intertext{Lagrangian in the Cartesian coordinate is $L=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)-\\left(-m g y+\\frac{1}{2} k\\left[\\sqrt{\\left(x^{2}+y^{2}\\right)}-l\\right]^{2}\\right)$,\n\t\t\t$$\n\t\t\tL=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)+m g y-\\frac{1}{2} k\\left[\\sqrt{\\left(x^{2}+y^{2}\\right)}-l\\right]^{2}\n\t\t\t$$}\n\t\t\\end{align*}\n\t\t(b) These two independent motions are in (i) radial direction and (ii) angular direction in plane so best coordinate system to define the system is circular polar coordinate.\\\\\n\t\tBut one should express the Lagrangian into suitable coordinate which must be independent of radial and angular variable.\n\t\t\\begin{align*}\n\t\t\\text{Put }x&=r \\sin \\theta, y=r \\cos \\theta,\\text{ so, Lagrangian is given by -}\\\\\n\t\tL&=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}\\right)+m g r \\cos \\theta-\\frac{1}{2} k(r-l)^{2}\\\\\n\t\t\\text{The equation of }&\\text{motion in terms of variable $r$ is }\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}=0\\\\\n\t\t&\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)=m \\dot{r} \\Rightarrow \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)=m \\ddot{r} \\text { and }\\left(\\frac{\\partial L}{\\partial r}\\right)=m r \\dot{\\theta}^{2}+m g \\cos \\theta-k(r-l) \\\\\n\t\t&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}=0 \\Rightarrow m \\ddot{r}-m r \\dot{\\theta}^{2}-m g \\cos \\theta+k(r-l)=0\n\t\t\\intertext{The equation of motion in terms of variable $\\theta$}\n\t\t\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)&=m r^{2} \\dot{\\theta}\\left(\\frac{\\partial L}{\\partial \\theta}\\right)=-m g r \\sin \\theta\\\\\n\t\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)&=m r^{2} \\ddot{\\theta}+2 m r \\dot{r} \\dot{\\theta}\\\\\n\t\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\frac{\\partial L}{\\partial \\theta}&=0 \\Rightarrow m r^{2} \\ddot{\\theta}+2 m r \\dot{r} \\dot{\\theta}+m g r \\sin \\theta=0\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A spherical pendulum of length $a$ moves in a space about fixed point $O$.\\\\\n\t\t(a) Write down Lagrangian of the system.\\\\\n\t\t(b) Identify cyclic Coordinate\\\\\n\t\t(c) Solve Lagrangian equation of motion.\\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=5cm,width=6cm]{VP-02}\n\t\t\\end{figure}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Number of particle }N&=1\\text{ so }T=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)\\text{ and potential}\\\\\n\t\t\\text{energy of system is }V&=-m g z\n\t\t\\intertext{Equation of Constraint is -}\n\t\t\\text{(1) The length of pendulum is fixed }&\\sqrt{x^{2}+y^{2}+z^{2}}=a\\text{ so }K=1\\\\\n\t\t\\text{So, degree of freedom }&(\\mathrm{DOF})=3 . N-K=3.1-1=2\n\t\t\\intertext{So there is a need of two generalized coordinates to solve the equation of motion. There are two independent motion (i) angular motion of particle from $z$-axis (ii) angular motion in $x-y$ plane about $z$ axis.}\n\t\t\\intertext{So, suitable coordinate is spherical coordinate.}\n\t\tx&=r \\sin \\theta \\cos \\phi, y=r \\sin \\theta \\sin \\phi, z=r \\cos \\theta\\\\\n\t\t\\text{\tFrom equation }&\\text{of constraint, }r=a \\Rightarrow \\dot{r}=0\\\\\n\t\t\\text{Kinetic energy }T&=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}^{2}+a^{2} \\sin ^{2} \\theta \\dot{\\phi}^{2}\\right), \\text{potential energy }V=-m g a \\cos \\theta\\\\\n\t\tL=T-V&=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}^{2}+a^{2} \\sin ^{2} \\theta \\dot{\\phi}^{2}\\right)+m g a \\cos \\theta\\\\\n\t\t\\text{(b) }\\frac{\\partial L}{\\partial \\phi}=0\\text{ so }\\phi\\text{ is cyclic coordinate }\\frac{\\partial L}{\\partial \\dot{\\phi}}&=p_{\\phi}=m a^{2} \\sin ^{2} \\theta \\dot{\\phi}\\text{ is constant of motion.}\\\\\n\t\t\\text{(c) }\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\left(\\frac{\\partial L}{\\partial \\theta}\\right)&=0\\\\\n\t\t\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)=m a^{2} \\dot{\\theta} \\Rightarrow \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)&=m a^{2} \\ddot{\\theta} \\Rightarrow\\left(\\frac{\\partial L}{\\partial \\theta}\\right)=m a^{2} \\sin \\theta \\cos \\theta \\dot{\\phi}^{2}-m g a \\sin \\theta\\\\\n\t\t\\text{So, }\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\left(\\frac{\\partial L}{\\partial \\theta}\\right)&=0 \\Rightarrow m a^{2} \\ddot{\\theta}-m a^{2} \\sin \\theta \\cos \\theta \\dot{\\phi}^{2}+m g a \\sin \\theta=0\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A particle of mass $m$ is constrained to move under gravity in inner surface of cone of half angle $\\alpha$ as shown in figure.\\\\\n\t\t(a) Write down Lagrangian in suitable coordinate system\\\\\n\t\t(b) Identify cyclic coordinate and discuss conservation of momentum\\\\\n\t\t(c) Write down Lagrange's equation of motion\\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=5cm]{VP-03}\n\t\t\\end{figure}\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=5cm]{VP-04}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\intertext{ A particle of mass $m$ is constrained to move in inner surface of cone of half angle $\\alpha$ and $x, y, z$ are the coordinates of particle at any time $t$.}\n\t\t\\text{(a) Number of particle $N=1$ so kinetic energy of the system is } T&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)\n\t\t\\intertext{\tAssuming that the origin is at the vertex of the cone, the potential energy is given by $V=m g z$}\n\t\t\\intertext{ Equation of Constraint is -}\n\t\t\\text{\tParticle is constraint to move on surface of cone where }&\\tan \\alpha=\\frac{\\sqrt{x^{2}+y^{2}}}{z},\\text{ so }K=1.\\\\\n\t\t\\text{So, degree of freedom (DOF) }&=3 N-K=3 \\times 1-1=2\n\t\t\\intertext{So, there is a need of two generalized Coordinates to write the Lagrangian.}\n\t\t\\intertext{The two independent motion is (i) Linear motion along the slope and (ii) angular motion about $z$ axis. So, spherical symmetry is suitable coordinate.}\n\t\t\\text{Put the value of }x=r \\sin \\theta \\cos \\phi, y&=r \\sin \\theta \\sin \\phi, z=r \\cos \\theta\\\\\n\t\t\\text{Which gives }T=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+r^{2} \\sin ^{2} \\theta \\dot{\\phi}^{2}\\right)\\text{ and }V&=m g r \\cos \\theta\\\\\n\t\t\\text{As }\\tan \\alpha=\\frac{\\sqrt{x^{2}+y^{2}}}{z} \\Rightarrow \\tan \\alpha=\\tan \\theta \\Rightarrow \\theta&=\\alpha \\Rightarrow \\dot{\\theta}=0\n\t\t\\intertext{If Lagrangian of the system is given by $L=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\sin ^{2} \\alpha \\dot{\\phi}^{2}\\right)-m g r \\cos \\alpha$ there is two generalized coordinates i.e., $r, \\phi$}\n\t\t\\text{(b) }L=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\sin ^{2} \\alpha \\dot{\\phi}^{2}\\right)-m g r \\cos \\alpha&\n\t\t\\intertext{One can see Lagrangian is not explicitly dependent on $\\phi$, which gives $\\frac{\\partial L}{\\partial \\phi}=0$. So, $\\phi$ is cyclic coordinate.}\n\t\t\\intertext{$\\left(\\frac{\\partial L}{\\partial \\dot{\\phi}}\\right)=p_{\\phi} \\Rightarrow m r^{2} \\sin ^{2} \\alpha \\dot{\\phi}=c$ and $p_{\\phi}=c$ so angular momentum of the system is constant during the motion.}\n\t\t\\intertext{(c) The Lagrangian equation of motion in $r$ variable is given by $\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}=0$, which gives\n\t\t\t$\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)=m \\dot{r},\\left(\\frac{\\partial L}{\\partial r}\\right)=m r \\sin ^{2} \\alpha \\dot{\\phi}^{2}-m g \\cos \\alpha$}\n\t\t\\intertext{$\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}=0 \\Rightarrow m \\ddot{r}-m r \\sin ^{2} \\alpha \\dot{\\phi}^{2}+m g \\cos \\alpha=0$, which is equivalent to Newton's law of motion}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\t\\item The system is shown in the figure. The particle $m_{2}$ moves on a vertical axis and the whole system rotates about this axis with a constant angular velocity $\\omega$.\\\\\n\t\t(a) Write down Lagrangian of the system in spherical polar co-ordinate.\\\\\n\t\t(b) Discuss conservation of momentum\\\\\n\t\t(c) Write down equation of motion.\\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4.5cm,width=4.3cm]{VP-05}\n\t\t\\end{figure}\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=6.5cm]{VP-06}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\intertext{\t(a) Number of Particle,$ N=3$}\n\t\t\\intertext{The kinetic energy is given by}\n\t\tT&=\\frac{1}{2} m_{1}\\left(\\dot{x}_{1}^{2}+\\dot{y}_{1}^{2}+\\dot{z}_{1}^{2}\\right)+\\frac{1}{2} m_{2}\\left(\\dot{x}_{2}^{2}+\\dot{y}_{2}^{2}+\\dot{z}_{2}^{2}\\right)+\\frac{1}{2} m_{3}\\left(\\dot{x}_{3}^{2}+\\dot{y}_{3}^{2}+\\dot{z}_{3}^{2}\\right)\n\t\t\\intertext{Potential energy assuming $O$ as origin}\n\t\tV&=-m_{1} g z_{1}-m_{1} g z_{2}-m_{2} g z_{3}\\\\\n\t\tx_{1}&=r_{1} \\sin \\theta_{1} \\cos \\phi_{1}, y_{1}=r_{1} \\sin \\theta_{1} \\sin \\phi_{1}, z_{1}=r_{1} \\cos \\theta_{1}\\\\\n\t\tx_{2}&=r_{2} \\sin \\theta_{2} \\cos \\phi_{2}, y_{2}=r_{2} \\sin \\theta_{2} \\sin \\phi_{2}, z_{2}=r_{2} \\cos \\theta_{2}\\\\\n\t\tx_{3}&=r_{3} \\sin \\theta_{3} \\cos \\phi_{3}, y_{3}=r_{3} \\sin \\theta_{3} \\sin \\phi_{3}, z_{3}=r_{3} \\cos \\theta_{3}\n\t\t\\intertext{The kinetic energy in spherical coordinate is given by}\n\t\tT&=\\frac{1}{2} m_{1}\\left(\\dot{r}_{1}^{2}+r_{1}^{2} \\dot{\\theta}_{1}^{2}+r_{1}^{2} \\sin ^{2} \\theta_{1}^{2} \\dot{\\phi}_{1}^{2}\\right)+\\frac{1}{2} m_{2}\\left(\\dot{r}_{2}^{2}+r_{2}^{2} \\dot{\\theta}_{2}^{2}+r_{2}^{2} \\sin ^{2} \\theta_{2}^{2} \\dot{\\phi}_{2}^{2}\\right)\\\\\n\t\t&+\\frac{1}{2} m_{3}\\left(\\dot{r}_{3}^{2}+r_{3}^{2} \\dot{\\theta}_{3}^{2}+r_{3}^{2} \\sin ^{2} \\theta_{3}^{2} \\dot{\\phi}_{3}^{2}\\right)\\\\\n\t\t\\text{And potential }&\\text{energy is given by }V=-m_{1} g r_{1} \\cos \\theta_{1}-m_{2} g r_{2} \\cos \\theta_{2}-m_{3} g r_{3} \\cos \\theta_{3}\n\t\t\\intertext{Equations of Constraint are -}\n\t\t\\end{align*}\n\t\t(1) Length of mass $m_{1}$ from origin $O$ is fixed, $r_{1}=l$\\\\\n\t\t(2) Length of another mass $m_{2}$ from origin $O$ is fixed, $r_{2}=l$\\\\\n\t\t(3) Both masses $m_{1}$ and $m_{2}$ make same angle with $z$ - axis, $\\theta_{1}=\\theta_{2}=\\theta$\\\\\n\t\t(4) Both masses $m_{1}$ make angle in the $x-y$ plane with $x$ axis as $\\phi_{1}=\\phi_{2}+c$,\\\\\n\t\t(5) Particle $m_{2}$ makes angle zero with $z$ - axis i.e., $\\theta_{3}=0$\\\\\n\t\t(6) Particle $m_{2}$ makes angle zero in $x-y$ plane with $x$ axis i.e., $\\phi_{3}=0$,\\\\\n\t\t(7) Particle $m_{2}$ have distance $r_{3}=2 l \\cos \\theta$ from origin $O$.\\\\\n\t\tSo, $K=7$. So degree of freedom (DOF) $=3 N-K=3.3-7=2$\n\t\tThere is two independent motion (i) linear motion of $m_{2}$ on $z$ axis and (ii) both mass $m_{1}$ rotating about $z$ axis.\\\\\n\t\tSo there is a need of two generalized coordinates.\\\\\n\t\tUsing equation of constraint one will transform Lagrangian as $L=T-V$\n\t\t\\begin{align*}\n\t\tL&=m_{1} l^{2}\\left(\\dot{\\theta}^{2}+\\dot{\\phi}^{2} \\sin ^{2} \\theta\\right)+2 m_{2} l^{2} \\dot{\\theta}^{2} \\sin ^{2} \\theta+2\\left(m_{1}+m_{2}\\right) g l \\cos \\theta\\\\\n\t\t\\text{\tPut the value of }\\dot{\\phi}&=\\omega,\\text{ then Lagrangian is given by}\\\\\n\t\tL&=m_{1} l^{2}\\left(\\dot{\\theta}^{2}+\\omega^{2} \\sin ^{2} \\theta\\right)+2 m_{2} l^{2} \\dot{\\theta}^{2} \\sin ^{2} \\theta+2\\left(m_{1}+m_{2}\\right) g l \\cos \\theta\\\\\n\t\t\\text{(b) }\\left(\\frac{\\partial L}{\\partial \\phi}\\right)&=0\\text{ so $\\phi$ is cyclic coordinate hence conjugate momentum}\\\\ \\left(\\frac{\\partial L}{\\partial \\dot{\\phi}}\\right)&=\\left(\\frac{\\partial L}{\\partial \\omega}\\right)=p_{\\phi}=2 m_{1} l^{2} \\omega \\sin ^{2} \\theta\n\t\t\\intertext{is constant during the motion. So, $z$ - component of angular momentum is conserved.}\n\t\t\\text{(c) }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\frac{\\partial L}{\\partial \\theta}=0\\\\\n\t\t&\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)=\\left(2 m_{1} l^{2} \\dot{\\theta}+4 m_{2} l^{2} \\dot{\\theta} \\sin ^{2} \\theta\\right) \\\\\n\t\t&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)=\\left(2 m_{1} l^{2}+4 m_{2} l^{2} \\sin ^{2} \\theta\\right) \\ddot{\\theta}+4 m_{2} l^{2} \\sin 2 \\theta \\dot{\\theta}^{2} \\\\\n\t\t&\\left(\\frac{\\partial L}{\\partial \\theta}\\right)=m_{1} l^{2} \\omega^{2} 2 \\sin \\theta \\cos \\theta+2 m_{2} l^{2} \\dot{\\theta}^{2} 2 \\sin \\theta \\cos \\theta-2\\left(m_{1}+m_{2}\\right) g l \\sin \\theta\n\t\t\\intertext{The equation of motion is given as -}\n\t\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)&-\\frac{\\partial L}{\\partial \\theta}=0\\\\\n\t\t\\left(2 m_{1} l^{2}+4 m_{2} l^{2} \\sin ^{2} \\theta\\right) \\ddot{\\theta}&+2 m_{2} l^{2} \\sin 2 \\theta \\dot{\\theta}^{2}-m_{1} l^{2} \\omega^{2} \\sin 2 \\theta+2\\left(m_{1}+m_{2}\\right) g l \\sin \\theta=0\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \n\t\tIf kinetic energy and potential energy is given by $T=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)$ and $V=-m g y$ respectively.\n\t\t\\begin{tasks}(1)\n\t\t\t\\task[\\textbf{a.}] Write down Lagrangian of the system.\n\t\t\t\\task[\\textbf{b.}] Identify generalized coordinate and generalized velocity.\n\t\t\t\\task[\\textbf{c.}] Identify cyclic coordinate and discuss conservation of momentum.\n\t\t\t\\task[\\textbf{d.}]  Discuss equation of motion.\n\t\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{(a)} L=T-V \\Rightarrow \\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)&-(-m g y) \\Rightarrow \\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)+m g y\\\\\n\t\t\\intertext{(b)} \\text{ Generalized coordinate }q_{1}&=x, q_{2}=y\\text{ generalized velocity} \\dot{q}_{1}=\\dot{x}, \\dot{q}_{2}=\\dot{y}\n\t\t\\intertext{(c)} \\left(\\frac{\\partial L}{\\partial q_{1}}\\right)&=\\left(\\frac{\\partial L}{\\partial x}\\right)=0, \\text{so it is a cyclic coordinate}\\\\ \\text{Then} \\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)&=p_{x}=m \\dot{x}, \\intertext{Identified as linear momentum in $x$ direction is constant of motion.}\n\t\t\\left(\\frac{\\partial L}{\\partial y}\\right)&=m g \\neq 0,\\text{ so it is not cyclic coordinate}\n\t\t\\intertext{(d)} \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)-\\left(\\frac{\\partial L}{\\partial x}\\right)&=0 \\\\ \\frac{d}{d t} m \\dot{x}-0&=0 \\Rightarrow m \\dot{x}=c, \\intertext{which is exactly explained in section (b)} \n\t\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{y}}\\right)-\\left(\\frac{\\partial L}{\\partial y}\\right)&=0 \\\\ \\frac{d}{d t} m \\dot{y}-m g&=0 \\Rightarrow m \\ddot{y}-m g=0\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \n\t\tAtwood's machine \\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4.7cm,width=4cm]{EP-04}\n\t\t\\end{figure}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{A conservative system with holonomic, scleronomous constraint  (the pulley is assumed frictionless and massless). There is only one independent coordinate $x$, the position of the other weight being determined by the constraint that the length of the rope between them is $l$. The potential energy is}\n\t\tV&=-M_{1} g x-M_{2} g(l-x)\n\t\t\\intertext{while the kinetic energy is}\n\t\tT&=\\frac{1}{2}\\left(M_{1}+M_{2}\\right) \\dot{x}^{2}\n\t\t\\intertext{Lagrangian has the form}\n\t\tL&=T-V=\\frac{1}{2}\\left(M_{1}+M_{2}\\right) \\dot{x}^{2}+M_{1} g x+M_{2} g(l-x)\n\t\t\\intertext{equation of motion}\n\t\t\\frac{\\partial L}{\\partial  x}&=\\left(M_{1}-M_{2}\\right) g\\\\\n\t\t\\frac{\\partial  L}{\\partial  x}&=\\left(M_{1}+M_{2}\\right) \\dot{x}\n\t\t\\intertext{$\\mathrm{so}$}\n\t\t\\left(M_{1}+M_{2}\\right) \\ddot{x}&=\\left(M_{1}-M_{2}\\right) g,\\\\\n\t\t\\ddot{x}&=\\frac{M_{1}-M_{2}}{M_{1}+M_{2}} g,\\\\\n\t\t\\end{align*}\n\t\\end{answer}\n\t\n\t\n\t\n\\end{enumerate}", "meta": {"hexsha": "cbc4675a657760aebad6c0a314be721ea0d5f3bb", "size": 54623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/Variational Principles and Lagrange's Equations.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Classical Mechanics  -CSIR/chapter/Variational Principles and Lagrange's Equations.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Classical Mechanics  -CSIR/chapter/Variational Principles and Lagrange's Equations.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.4180107527, "max_line_length": 405, "alphanum_fraction": 0.657268916, "num_tokens": 20541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6773823316311536}}
{"text": "\\documentclass[11pt]{article}\n\n\\input{preamble}\n\n%\\usepackage{tikz}\n%\\usepackage{tikz-qtree}\n\\usepackage{qtree}\n\\usepackage{xfrac}\n\\usepackage{graphicx}\n\n\\title{Week 5: Support Vector Machines\\\\ and Tensor Backpropagation}\n\n\\begin{document}\n\\author{\\url{https://mlvu.github.io}}\n\n\\maketitle\n\n\\section{Support Vector Machines}\n\n\\subsection{Tensor loss}\n\nThe basic optimization objective for Support Vector Machines is \n\\begin{align*}\n\\text{minimize}\\;\\;&\\frac{1}{2}||\\oc{\\bw}|| + \\rc{C}\\sum_i \\gc{p_i}\\\\\n\\text{such that}\\;\\;&y_i(\\oc{\\bw}^T\\x_i + \\bc{b}) \\geq 1 - \\gc{p_i}\\\\\n\\text{and} \\;\\;&\\gc{p_i} \\geq 0\n\\end{align*}\n\n\\qu What does $i$ index? How many terms does the sum have, and how many constraints are there?\n\n\\ans{It iterates over the data. There are as many terms as there are instances in the data. There are two constraints per instance.}{}\n\nWhat is the value of $y_i$ in this expression? What is its function?\n\n\\ans{$y_i$ is 1 for positive examples, and -1 for negative examples. It allows us to rewrite the constraints\n\n\\begin{align*}\n\\oc{\\bw}^T\\x_i + \\bc{b} \\geq 1 &\\;\\text{if $\\x_i$ is positive} \\\\\t\n\\oc{\\bw}^T\\x_i + \\bc{b} \\leq -1 &\\;\\text{if $\\x_i$ is negative} \\\\\n\\end{align*}\n\nto a single constraint.\n}{}\n\n\n\\qu There are two common ways to rewrite this expression before implementing it. What are they (in general terms) and what are their benefits?\n\n\\ans{The first option is to rewrite everything in terms of $\\bw$ and $b$ in order to get rid of the constraints. This is useful when we want to use the SVM as the last layer in a neural network. Without constraints, we are free to use basic backpropagation.\n\nThe second option is to use Lagrange multipliers to get rid of $\\oc{\\bw}$ and rewrite everything in terms of the multipliers. This expresses the solution purely in terms of the support vectors.\n\nThe main benefit is that the whole algorithm can be written in terms of the dot products of pairs of instances. This means we do not need to see the actual feature vectors to compute the support vectors, only the dot products. This allows us to apply the \\emph{kernel trick}.\n}{}\n\n\\subsection{Lagrange multipliers} \n\n\nLagrange multipliers are a useful trick to know. In the lectures we only had time to describe the trick itself, and the rules for applying it. That should be enough to do the exam questions and the questions below, but if you want some more intuition for why Lagrange multipliers work the way they do please read  \\href{https://www.khanacademy.org/math/multivariable-calculus/applications-of-multivariable-derivatives/constrained-optimization/a/lagrange-multipliers-single-constraint}{this article from the required reading}.\n\nWe have the following optimization problem:\n\\begin{align*}\n\\text{minize} &\\;f(\\bc{a}, \\bc{b}) = \\bc{a}^2 + 2\\bc{b}^2 \\\\\n\\text{such that} &\\;\\bc{a}^2 = - \\bc{b}^2 + 1\n\\end{align*}\n\n\n\\qu The first step is to rewrite the constraint so that the right side is equal to zero. Do so.\n\\ans{$\\bc{a}^2 + \\bc{b}^2 - 1 = 0$}{}\nWhat does the constraint say about the allowed inputs (what shape do the allowed inputs make in the $(\\bc{a}, \\bc{b})$-plane)?\n\\ans{The solutions are constrained to a circle, centered on the origin, with radius 1 (the so-called bi-unit circle).}{}\n\n\nWe now define a function $L(\\bc{a}, \\bc{b}, \\rc{\\alpha}) = f(\\bc{a}, \\bc{b}) + \\rc{\\alpha} G$, where $G$ is the left hand side of the constraint equal to zero (how much any given $a$ and $b$ violate the constraint).\\footnotemark \n\n\\qu Write out $L(\\bc{a}, \\bc{b}, \\rc{\\alpha})$ for our problem.\n\\ans{$L(\\bc{a}, \\bc{b}, \\rc{\\alpha}) = \\bc{a}^2 + 2\\bc{b}^2 + \\alpha(\\bc{a}^2 + \\bc{b}^2 - 1) $}{}\t\n\n\\footnotetext{For plain Lagrange multipliers, where the constraints are all equalities, we can either add or subtract the term containing the constraint. For inequality constrains, it depends on whether we are maximizing or minimizing.}\n\nWe take the derivative of $L$ with respect to each of its \\emph{three} parameters, and set these equal to zero. \n\n\\qu Fill in the blanks\n\\ans{\n\\begin{align*}\n\\frac{\\kp L}{\\kp \\bc{a}} &= \\frac{\\kp(\\bc{a}^2 + 2\\bc{b}^2 + \\rc{\\alpha} \\bc{a}^2 + \\rc{\\alpha} \\bc{b}^2 - \\rc{\\alpha})}{\\kp \\bc{a}} \\\\\n&= 2\\bc{a} + 2\\rc{\\alpha} \\bc{a} \\\\\n \t\\frac{\\kp L}{\\kp \\bc{b}} &= 4\\bc{b} + 2 \\rc{\\alpha} \\bc{b} \\\\\n \t\\frac{\\kp L}{\\kp \\rc{\\alpha}} &= \\bc{a}^2 + \\bc{b}^2 - 1 \n\\end{align*}\n}{}\n\n\\begin{align}\na (\\ans{2+2\\rc{\\alpha}}{\\ldots})&= 0\\\\\nb (\\ans{4 + 2\\rc{\\alpha}}{\\ldots})&= 0 \\\\\na^2 + b^2 &= 1 \\label{line:constraint}\n\\end{align}\n\n\\noindent Note that the last line recovers the original constraint. We now have three equations with three unknowns, so we can solve for $a$ and $b$. From the shape of the function (it's symmetric in both the $a$ and $b$ axes), we should expect at least two solutions. \n\nWe can get these from the above equations by noting that if $\\bc{a}$ and $\\bc{b}$ are both nonzero, we can derive a contradiction. Thus either $\\bc{a}$ or $\\bc{b}$ must be zero.\n\n\\qu Give the solutions for both cases (remember that $x^2 = 1$ has \\emph{two} solutions).\n\n\\ans{\nFrom line (\\ref{line:constraint}), above we see that if $a =0$, then $b^2=1$ and vice versa. This gives us\n\\begin{align*}\na = 0&, b = 1\\\\\t\na = 0&, b = -1\\\\\na = 1&, b = 0\\\\\na = -1&, b = 0\\\\\n\\end{align*}\nas extrema. Filling these in, we find that the last two lines minimize the function. (The first two are maxima, as can be seen by clicking the Wolfram Alpha link below.\n}{}\n\nHappily, \\href{https://goo.gl/Uaz5mg}{Wolfram Alpha} agrees with us (and provides some informative plots).\n\n\\subsection{The kernel trick}\n\nThe feature space of $\\oc{k}$ is a projection of point $\\ba$ to point $\\ba'$ such that \n\\[\n\\oc{k}(\\ba, \\bb) = {\\ba'}^T\\bb' \\p\n\\]\n\nWe have a dataset with two features Let $\\bm{a} = \\ma{a_1\\\\ a_2}$ and $\\bm{b} = \\ma{b_1\\\\ b_2}$. We define the \\emph{kernel}\n\\[\n\\oc{k_1}(\\bm{a}, \\bm{b}) = (\\bm{a}^T\\bm{b})^2 \\p\n\\]\n\n\\qu Show that the feature space defined by$\\oc{k_!}$ is \n\\[ \n\\ma{{x_1}^2\\\\\\sqrt{2}x_1x_2\\\\{x_2}^2}\\p\n\\]\nHint: start by writing out the definition as a scalar function. See if you can re-arrange this back into a dot procut of two other vectors.\n\\ans{\n\n\nStarting from the definition of $k$:\n\\begin{align*}\nk(\\ba, \\bb) &= \\left( \\ma{a_1\\\\ a_2}^T\\ma{b_1\\\\ b_2} \\right)^2\\\\\n &= \\left ( a_1 b_1 + a_2 b_2 \\right)^2 \\\\\n &= a_1 b_1 a_1 b_1 + 2 a_2 b_2 a_1 b_1 + a_2 b_2 a_2 b_2 \\\\\n &= a_ 1a_1\\cdot b_1 b_1 + 2 \\cdot a_1 a_2 \\cdot b_1 b_2 + a_2a_2\\cdot b_2b_2\\\\\n &= \\ma{a_1a_1\\\\ \\sqrt{2}a_1a_2\\\\a_2a_2} ^T \\ma{b_1b_1\\\\ \\sqrt{2}b_1b_2\\\\b_2b_2}\n\\end{align*}\n}{}\n\t\n\\qu What is the feature space for the kernel\n\\[\n\\oc{k_2}(\\ba, \\bb) = \\left(\\ba^T\\bb +1\\right)^2\\;\\;\\;\\text{?}\n\\]\n\\ans{\n\\begin{align*}\nk(\\ba, \\bb) &= \\left( \\ma{a_1\\\\ a_2}^T\\ma{b_1\\\\ b2} + 1\\right)^2\\\\\n &= (a_1 b_1 + a_2 b_2)^2 +  2( a_1 b_1 + a_2 b_2) + 1 \\\\\n &= a_1b_1a_1b_1 + 2a_1b_1a_2b_2 + a_2b_2a_2b_2 + 2a_1b_1 + 2a_2b_2 + 1\\\\\n &= \\ma{1 \\\\ \\sqrt{2}a_1 \\\\ \\sqrt{2}a_2 \\\\ {a_1}^2\\\\\\sqrt{2}a_1a_2 \\\\{a_2}^2} ^T\\ma{1 \\\\ \\sqrt{2}b_1 \\\\ \\sqrt{2}b_2 \\\\ {b_1}^2\\\\\\sqrt{2}b_1b_2 \\\\{b_2}^2} \n\\end{align*}\n}{}\n\n\\section{Backpropagation Revisited}\n\n\\subsection{The multivariate chain rule}\n\nIf we want to do backpropagation for a computation graph where an output variable depend in an input variable through multiple intermediate values (the graph contains a diamond), we require the \\emph{multivariate chain rule}. If you don't quite remember how it goes, re-read slides 24--29 fo the deep learning lecture before trying these questions.\n\n\nWe will use the backpropagation algorithm to find the derivative of the function\n\\[\nf(x) = \\sin(x^2)\\cos(x^3)\n\\]\nwith respect to $x$.\n\n\\qu First, we break the function up into modules. Fill in the blanks.\n\n\\begin{align*}\nf &= \\rc{a}\\gc{b} \\\\\n\\rc{a} &= \\ans{\\sin(c)}{\\ldots}\\\\\n\\gc{b} &= \\ans{\\cos(d)}{\\ldots} \\\\\n\\oc{c} &= x^2 \\\\\n\\bc{d} &= x^3 \\\\\n\\end{align*}\n\n\\qu Draw the computation graph with nodes $x, \\oc{c}, \\bc{s}, \\rc{a}, \\gc{b}, f$\n\n\\ans{\n\n\\hspace{5em}\\includegraphics[width=0.4\\linewidth]{compgraph}\n\n}{}\n\n\\qu Work out the \\emph{local} derivatives. Which is the correct expression for the gradient $\\kp f / \\kp x$?\n\n\\ans{\n\\begin{align*}\n\\frac{\\kp f}{\\kp x} &= \\frac{\\kp f}{\\kp \\rc{a}}\\frac{\\kp \\rc{a}}{\\kp x} + \\frac{\\kp f}{\\kp \\gc{b}}\\frac{\\kp \\gc{b}}{\\kp x} & \\text{multivariate chain rule}\\\\\n&= \\frac{\\kp f}{\\kp \\rc{a}} \\frac{\\kp \\rc{a}}{\\kp \\oc{c}} \\frac{\\kp \\oc{c}}{\\kp x} + \\frac{\\kp f}{\\kp \\gc{b}}\\frac{\\kp \\gc{b}}{\\kp x} & \\text{chain rule for $\\oc{c}$: $\\frac{\\rc{a}}{x} = \\frac{\\kp \\rc{a}}{\\kp \\oc{c}} \\frac{\\kp \\oc{c}}{\\kp x}$}\\\\\n&= \\frac{\\kp f}{\\kp \\rc{a}} \\frac{\\kp \\rc{a}}{\\kp \\oc{c}} \\frac{\\kp \\oc{c}}{\\kp x} + \\frac{\\kp f}{\\kp \\gc{b}}\\frac{\\kp \\gc{b}}{\\kp \\bc{d}}\\frac{\\bc{d}}{x} & \\text{chain rule for $\\bc{d}$}\\\\\n &= \\gc{b} \\cdot \\cos(\\oc{c}) \\cdot 2x - \\rc{a}\\cdot \\sin(\\bc{d})\\cdot 3x^2& \\text{work out all local derivatives}\n\\end{align*}}{}\n\n\\noindent This is a common exam question so make sure to practice if you're not sure. You can easily create new questions for yourself by coming up with any function $f(x)$ with a diamond shape in the computation (just make sure that $x$ is used twice).\n\n\\subsection{Tensor Backpropagation}\n\nIn scalar backpropagtion, we need to work out only the local derivatives. Once we have these, we can multiply them in any order to get the global derivative. If we want to apply backpropagation to tensors, things are not so easy.\n\n\\qu Why not? What is it about the local derivatives in tensor backpropagation that makes it difficult to apply in this way?\n\n\\ans{In tensor backpropagation, the local derivatives are often, for instance, the derivative of a vector function over matrix parameters, like the local derivative $\\kp \\gc{\\bm k}/\\kp \\oc{\\bm W}$ shown in the slides. In this case, the collection of all scalar derivatives (every output with every input) is best represented as a 3 tensor. This would take way too much memory, and there's then no natural way to multiply this local derivative with the others to compute the global derivative.}{}\n\nThe solution is not to compute the local derivatives explicitly, but only to compute the gradients on the inputs over the loss, given the gradients of the outputs over the loss. \n\nWe will practice this for a simple feedforward layer (without activation). Consider a module $f$ that computes:\\footnotemark\n\\[\n\\y = f(\\x, \\oc{\\W}, \\bc{\\bb}) = \\oc{\\W}\\x + \\bc{\\bb}\n\\]\n\n\\footnotetext{Normally, we would consider $\\x$ the input, and $\\oc{\\W}$ and $\\bc{\\bb}$ the parameters, but for our AD engine, the distinction does not matter: everything going in to the computation is an input, and we may need the gradient over all three.}\n\n\\noindent Assume that this module is part of a much larger network. Its output $\\y$ is fed as input to another module, which produces a new output that is fed to another module and so on. At the end, a single scalar loss $L$ is produced.\n\n\\hspace{5em}\\includegraphics[width=0.7\\linewidth]{networkloss}\n \n\\noindent Ultimately, we want to work out the derivative of this loss,  with respect to our inputs:\n\\[\n\\frac{\\kp L}{\\kp \\x}\\;\\;\\; \\frac{\\kp L}{\\kp \\oc{\\W}}\\;\\;\\; \\frac{\\kp L}{\\kp \\bc{\\bb}}\n\\]\n\n\n\\noindent We'll start with the bias term $\\bc{\\bb}$. Since matrix/vector calculus can get complicated, and doesn't translate to tensors of higher rank, we'll develop everything in terms of scalar calculus.  Once we've taken the derivatives we'll transform everything to matrix operations to make the implementation efficient.\n\nWe're interested in $\\frac{\\kp L}{\\y}\\frac{\\kp \\y}{\\kp \\bc{b}_j}$, but we need matrix/vector calculus to do that. Instead we will consider $L(f(\\bc{\\bb}))$ as a \\emph{scalar} computation, which has multiple intermediate values $y_1, y_2 \\ldots, y_k$. By the multivariate chain rule, we can just take the derivative over each path (through each value $y_i$), and sum them:\n\\[\n\\frac{\\kp L}{\\kp \\bc{b}_j} = \\sum_i \\frac{\\kp L}{\\kp y_i} \\frac{\\kp y_i}{\\kp \\bc{b}_j}\n\\]\n\n\\noindent We will assume that $\\kp L/\\kp y_i$ is given to us by the AD engine as a vector $\\bm d$ with $d_i = \\kp L/\\kp y_i$. All we need to work out is a simple matrix operation that computes $\\kp L/\\kp \\bc{b}_j$ for all $j$ and lays the results out in the same shape as $\\bc{\\bb}$. We'll start by working out the scalar derivative.\n\n\n\\qu Fill in the gaps\n\\begin{align*}\n\\frac{\\kp L}{\\kp \\bc{b}_j} &= \\sum_i \\frac{\\kp L}{\\kp y_i} \\frac{\\kp y_i}{\\kp \\bc{b}_j} = \\sum_i d_i \\ans{\\frac{\\kp y_i}{\\kp \\bc{b}_j}}{\\ldots}\\\\\n&= \\sum_i d_i \\frac{\\kp [\\ans{\\oc{\\W}\\x + \\bc{\\bb}}{\\ldots}]_i}{\\kp \\bc{b_j}} = \\sum_i d_i \\frac{\\kp [\\oc{\\W}\\x]_i + \\bc{b}_i}{\\kp \\bc{b_j}}\\\\\n&= \\sum_i d_i\\frac{\\kp \\bc{b}_i}{\\kp \\bc{b}_j} = \\ans{d_j}{\\ldots}\n\\end{align*}\n\n\\qu What should the \\texttt{backward()} function for $f$ return as the gradient of $\\bc{\\bb}$?\n\n\\ans{We should return a vector $\\bc{\\bb}'$ with the same shape as $\\bc{\\bb}$, where $\\bc{b}'_j = \\kp L / \\kp \\bc{b}_j$. Since $d_j$ is the gradient for $\\bc{b}_j$, we can just return the vector $\\bm d$.}{}\n\nWe'll do the same for the gradient over $\\x$. \n\n\\qu Work out the scalar derivative $\\kp L / \\kp x_j$ using the multivariate chain rule (again taking $\\kp L / \\kp y_i$ as given).\n\\ans{\n\\begin{align*}\n\\frac{\\kp L}{\\kp x_j} &= \\sum_i \t\\frac{\\kp L}{\\kp y_i}\\frac{\\kp y_i}{\\kp x_j} = \\sum_i d_i \\frac{\\kp y_i}{\\kp x_j} \\\\\n&= \\sum_i d_i \\frac{\\kp \\oc{\\W}\\x}{\\kp x_j} = \\sum_i d_i \\frac{\\kp \\oc{\\W}_{i\\cdot}\\times\\x + \\kc{\\bb} }{\\kp x_j} \\\\\n&=  \\sum_i d_i \\frac{\\kp \\sum_k \\oc{\\W}_{ik}x_k}{\\kp x_j} = \\sum_i d_i \\frac{\\kp \\oc{\\W}_{ij}x_j}{\\kp x_j}\\\\\n&=  \\sum_i d_i \\oc{\\W}_{ij}\n\\end{align*}\n\n}{}\n\n\\qu What should the \\texttt{backward()} function for $f$ return as the gradient of $\\x$?\n\n\\ans{We are looking for a function that returns a vector $\\x'$ where $x'_j = \\sum_i d_i \\oc{\\W}_{ij}$. In other words, $x'_j$ should be the dot product between $\\bm d$ and and the $j$-th column of $\\oc{\\W}$. We get this if we  compute $\\x' = {\\bm d}^T\\oc{\\W}$.\n\n\\includegraphics[width=0.7\\linewidth]{matbp}\n\n}{}\n\n\\section{Bonus: Expectation Maximization}\n\n\\emph{This is not an exam question, but it's helpful to do if you want to understand the EM algorithm.}\n\nAssume we have a Gaussian Mixture Model in one dimension with two components: $\\rc{N(0, 1)}$ and $\\gc{N(1,1)}$. The weights $\\rc{w_1}$ and $\\gc{w_2}$ of the components are equal. \n\n{\n\\centering\n\\includegraphics[width=0.7\\linewidth]{hw-components-unscaled} \\\\\n\\includegraphics[width=0.7\\linewidth]{hw-stackplot}\n}\n\n\\qu Compute the probability density of the point 0, under the Gaussian Mixture.\n\\ans{\n\\begin{align*}\np(0) &= \\rc{\\frac{1}{2} N(0, 1)} + \\gc{\\frac{1}{2} N(1,1)}\\\\\n &= \\rc{\\frac{1}{2\\sqrt{2\\pi}} \\exp(0)} + \\gc{\\frac{1}{2\\sqrt{2\\pi}} \\exp\\left(-\\frac{1}{2}\\right)} \\\\\n &= \\rc{\\frac{1}{2}\\frac{1}{\\sqrt{2 \\pi}}} + \\gc{\\frac{1}{2}\\frac{1}{\\sqrt{2 \\pi e}}} \\approx 0.32\n\\end{align*}\n}{}\n\n\\qu Under the EM algorithm, what responsibility is assigned to each component for the point 0?\n\n\\ans{\nTo compute the responsibility, we compute the probability of the component $z$ given the point $x$: $p(z\\mid x)$, and normalize over all components. \nWe get for component 1:\n\\[\n\\frac{\\rc{\\frac{1}{2\\sqrt{2\\pi}} \\exp(0)}}{\\rc{\\frac{1}{2\\sqrt{2\\pi}} \\exp(0)} + \\gc{\\frac{1}{2\\sqrt{2\\pi}} \\exp\\left(-\\frac{1}{2}\\right)}} = \\frac{\\rc{1}}{\\rc{1} + \\gc{\\frac{1}{\\sqrt{e}}}} \\approx 0.62\n\\]\nand for component 2: \n\\[\n\\frac{\\gc{\\frac{1}{2\\sqrt{2\\pi}} \\exp\\left(-\\frac{1}{2}\\right)}}{\\rc{\\frac{1}{2\\sqrt{2\\pi}} \\exp(0)} + \\gc{\\frac{1}{2\\sqrt{2\\pi}} \\exp\\left(-\\frac{1}{2}\\right)}} = \\frac{\\gc{\\frac{1}{\\sqrt{e}}}}{\\rc{1} + \\gc{\\frac{1}{\\sqrt{e}}}} \\approx 0.37\n\\]\n\nNote: Using Bayes' rule, this translates to $p(z\\mid x) = \\frac{p(x\\mid z)p(z)}{p(x)}$. The denominator is the sum computed in the previous exercise, and the responsibilities are the proportions of each term to the total.\\footnotemark\n\nThis is no accident, it is essentially what Bayes' rule tells us: to compute $p(z\\mid x)$, we find $p(x)$ by marginalizing $Z$ out of $p(X=x, Z)$. This gives us a big sum, with one term for each $z$. The proportion of this term to the total is $p(z\\mid x)$.\n\n}{}\n\n\\end{document}", "meta": {"hexsha": "6132a54e7b1228ccd9685fff39b17b92273a5c71", "size": 16030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week5.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": "week5.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": "week5.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": 51.3782051282, "max_line_length": 525, "alphanum_fraction": 0.6695570805, "num_tokens": 5593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6773823286793657}}
{"text": "\\begin{tabularx}{\\linewidth}{lXXX}\n\t\\toprule\n\t               & \\textbf{Worst case run time} & \\textbf{Average case run time} & \\textbf{In place or not?}      \\\\ \\midrule\n\tMerge Sort     & \\nlgn                        & \\nlgn                          & No. $ \\Theta(n) $.             \\\\\n\tInsertion Sort & \\nn                          & \\nn                            & Yes. $ \\Theta(1) $ additional. \\\\\n\tBubble Sort    & \\nn                          & \\nn                            & Yes.                           \\\\\n\tSelection Sort & \\nn                          & \\nn                            & Yes.                           \\\\\n\tQuick Sort     & \\nn                          & \\nlgn                          & Yes.                           \\\\\n\tHeap Sort      & \\nlgn                        & \\nlgn                          & Yes.                           \\\\ \\bottomrule\n\\end{tabularx}\n\n\\subsection{Behavior of sorting algorithms}\n\n\\begin{description}\n\t\\item[Merge sort] (CLRS p.29-34) Divide-and-conquer. Recursively split list into two sublists of equal size, then merge the sorted sublists by comparing the front elements and taking the smallest until both lists are empty. \n\t\\item[Insertion sort] (CLRS p.17-18) Runs through the list, and places the $j$th element in the correct place out of the sublist $A[1..j-1]$, the already sorted elements. \n\t\\item[Bubble sort] (CLRS p.40, Problem 2-2) Sorts by repeatedly looping through the list, swapping out of order elements. The bigger elements slowly \"bubble\" upwards. \n\t\\item[Selection sort] (CLRS p.29, Exercise 2.2-2) Runs through the list and takes the smallest unsorted element and places it in front of the array. \n\t\\item[Quick sort] (CLRS Chapter 7, p.170 onwards) Takes some pivot element $x$ from a place in the list, and places all elements smaller than $x$ to the left of $x$, and all elements bigger to the right. Then it recursively quicksorts the sublists of elements smaller than $x$ and bigger than $x$.\n\t\\item[Heap sort] (CLRS Chapter 6, p.151 onwards) Constructs a max heap out of the array. Then it repeatedly exchanges the maximum element with the last element in the heap, then heapifies again. \n\t\\subitem \\textsc{Max-Heapify}(i): Assuming that the trees at \\textsc{Left}(i) and \\textsc{Right}(i) are heaps, make the tree rooted at $i$ a heap. \n\\end{description}", "meta": {"hexsha": "9824de1c9b2ab25d7d70bce6b1321d3394e618e1", "size": 2340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms and Data Structures - Reference/sorting.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Algorithms and Data Structures - Reference/sorting.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms and Data Structures - Reference/sorting.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 106.3636363636, "max_line_length": 298, "alphanum_fraction": 0.5811965812, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6773823261710147}}
{"text": "\\section{Planes}\n\\label{sec:planes}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the vector and parametric equations of a plane in $\\R^n$.\n  \\item Find the normal and standard equations of a plane in $\\R^3$.\n  \\item Find the intersection of two planes, or of a line and a plane.\n  \\item Find the angle between two planes, or between a line and a plane.\n  \\item Find the shortest distance between a point and a plane.\n  \\end{enumerate}\n\\end{outcome}\n\nMuch like the above discussion with lines, vectors can be used to\ndetermine planes in $\\R^n$. Consider a point $P$ and two direction\nvectors $\\vect{d}$ and $\\vect{e}$ that are not parallel to each\nother. Then there is a unique plane passing through $P$ and containing\n$\\vect{d}$ and $\\vect{e}$:\n\\begin{center}\n  \\begin{tikzpicture}[rotate=-10]\n    \\filldraw[draw=red!80,fill=red!10](-2,0,-5) -- (4,0,-5) -- (4,0,2) -- (-2,0,2) -- cycle;\n    \\draw[->,thick,blue!80!black](0,0,0) -- node[below left] {$\\vect{d}$} (2,0,0);\n    \\draw[->,thick,blue!80!black](0,0,0) -- node[above left] {$\\vect{e}$} (0,0,-3);\n    \\fill (0,0) circle [radius=2.2pt] node [left=3pt] {$P$};\n  \\end{tikzpicture}\n\\end{center}\nThe plane is infinite in each direction, although in the picture, we\nhave only shown a small part of it. If $\\vect{p}$ is the position\nvector of $P$ and $\\vect{q}$ is the position vector of some other\npoint in the plane, we have\n\\begin{equation*}\n  \\vect{q} = \\vect{p} + t\\,\\vect{d} + s\\,\\vect{e}\n\\end{equation*}\nfor some real numbers $t$ and $s$. This is called the \\textbf{vector\n  equation}%\n\\index{vector equation!of a plane}%\n\\index{plane!vector equation} of the plane.\n\n\\begin{definition}{Vector equation of a plane}{vector-equation-of-plane}\n  Let $\\vect{p}$ be a vector and let $\\vect{d},\\vect{e}$ be non-zero,\n  non-parallel vectors. Then\n  \\begin{equation*}\n    \\vect{q} = \\vect{p} + t\\,\\vect{d} + s\\,\\vect{e}\n  \\end{equation*}\n  is the \\textbf{vector equation}%\n  \\index{vector equation!of a plane}%\n  \\index{plane!vector equation} of a plane.\n\\end{definition}\n\nThe vector equation of a plane can also be written in\n\\textbf{component form}%\n\\index{vector equation!of a plane!component form}%\n\\index{component form!plane}%\n\\index{plane!component 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  + s \\begin{mymatrix}{r} e_1 \\\\ e_2 \\\\ \\vdots \\\\ e_n \\end{mymatrix}\n\\end{equation*}\nand in \\textbf{parametric form}\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}c}\n    x_1 &=& p_1 + t\\,d_1 + s\\,e_1, \\\\\n    x_2 &=& p_2 + t\\,d_2 + s\\,e_2, \\\\\n        &\\vdots&             \\\\\n    x_n &=& p_n + t\\,d_n + s\\,e_n.\n  \\end{array}\n\\end{equation*}\nThe latter set of equations are also called the \\textbf{parametric\n  equations}%\n\\index{parametric equations!of a plane}%\n\\index{plane!parametric equations} of the plane.\n\n\\begin{example}{Vector and parametric equations}{plane-from-three-points}\n  Find vector and parametric equations for the plane through the\n  points $P = (1,2,0,0)$, $Q = (2,2,0,1)$, and $R = (0,1,1,0)$.\n\\end{example}\n\n\\begin{solution}\n  We can use $P$ as the base point and $\\longvect{PQ}$ and\n  $\\longvect{PR}$ as the direction vectors. We have\n  \\begin{equation*}\n    \\longvect{PQ} =\n    \\begin{mymatrix}{c} 2\\\\2\\\\0\\\\1 \\end{mymatrix}\n    - \\begin{mymatrix}{c} 1\\\\2\\\\0\\\\0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1\\\\0\\\\0\\\\1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\longvect{PR} =\n    \\begin{mymatrix}{c} 0\\\\1\\\\1\\\\0 \\end{mymatrix}\n    - \\begin{mymatrix}{c} 1\\\\2\\\\0\\\\0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} -1\\\\-1\\\\1\\\\0 \\end{mymatrix}.\n  \\end{equation*}\n  Therefore the vector equation is\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x\\\\y\\\\z\\\\w \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1\\\\2\\\\0\\\\0 \\end{mymatrix}\n    + t\\,\\begin{mymatrix}{c} 1\\\\0\\\\0\\\\1 \\end{mymatrix}\n    + s\\,\\begin{mymatrix}{c} -1\\\\-1\\\\1\\\\0 \\end{mymatrix}.\n  \\end{equation*}\n  We can also write this as a system of parametric equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}l}\n      x &=& 1 + t - s, \\\\\n      y &=& 2 - s, \\\\\n      z &=& s, \\\\\n      w &=& t.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\nNote that the vector and parametric equations of a plane are not\nunique. For example, in Example~\\ref{exa:plane-from-three-points}, we\ncould have equally used $Q$ or $R$ as the base point, and/or used\n$\\longvect{QR}$ as one of the direction vectors. In each case we would\nhave obtained a different equation for the same plane.\n\n\\begin{example}{Determine whether a point is on a plane}{point-on-plane-parametric}\n  Determine whether the point $S=(4,4,-2,1)$ lies on the plane through\n  the points $P = (1,2,0,0)$, $R = (2,2,0,1)$, and\n  $Q = (0,1,1,0)$.\n\\end{example}\n\n\\begin{solution}\n  We already found the parametric equations for this plane in\n  Example~\\ref{exa:plane-from-three-points}. To determine whether the\n  point $S=(4,4,-2,1)$ lies on this plane, we must substitute its\n  coordinates into the parametric equations:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      4 &=& 1 + t - s, \\\\\n      4 &=& 2 - s, \\\\\n      -2 &=& s, \\\\\n      1 &=& t.\n    \\end{array}\n  \\end{equation*}\n  This is a system of linear equations. We solve it to find that it\n  has the unique solution $(t,s) = (1,-2)$. Therefore, the point $S$\n  lies on the given plane, and more specifically, it is the point that\n  corresponds to the parameters $t=1$ and $s=-2$.\n\\end{solution}\n\nIn the special case of 3 dimensions, a plane can also be described by\na point and a normal vector. A \\textbf{normal vector}%\n\\index{normal vector of a plane}%\n\\index{vector!normal vector}%\n\\index{plane!normal vector} of a plane is a vector that is\nperpendicular to the plane.\n\\begin{center}\n  \\begin{tikzpicture}[rotate=-10]\n    \\filldraw[draw=red!80,fill=red!10](-3,0,-3.5) -- (3,0,-3.5) -- (3,0,3.5) -- (-3,0,3.5) -- cycle;\n    \\draw[->,thick,blue!80!black](0,0,0) -- node[left, pos=0.4] {$\\vect{n}$} (100:2);\n    \\draw[dashed,gray](0,0,0) -- (2,0,-2);\n    \\fill (0,0,0) circle [radius=2.2pt] node [left=3pt] {$P$};\n    \\fill (2,0,-2) circle [radius=2.2pt] node [right=3pt] {$Q$};\n  \\end{tikzpicture}\n\\end{center}\nGiven a non-zero vector $\\vect{n}$ in $\\R^3$ and a point $P$, there\nexists a unique plane that contains $P$ and has $\\vect{n}$ as a normal\nvector. We wish to find an equation for this plane. If $Q$ is an\narbitrary point on the plane, then by definition, the normal vector is\northogonal to the vector $\\longvect{PQ}$. Writing this as a formula,\nwe have $\\vect{n} \\dotprod \\longvect{PQ} = 0$. If $\\vect{p}$ and\n$\\vect{q}$ are the position vectors of $P$ and $Q$, respectively, we\nhave $\\longvect{PQ} = \\vect{q}-\\vect{p}$, and therefore the equation\nof the plane can be written as\n\\begin{equation*}\n  \\vect{n} \\dotprod (\\vect{q}-\\vect{p}) = 0,\n\\end{equation*}\nor equivalently,\n\\begin{equation*}\n  \\vect{n} \\dotprod \\vect{q} = \\vect{n} \\dotprod \\vect{p}.\n\\end{equation*}\nThis is called the \\textbf{normal equation} of the plane. Note that in\nthis equation, $\\vect{n}$ and $\\vect{p}$ are given and fixed, whereas\n$\\vect{q}$ is a variable ranging over the position vectors of all\npoints on the plane.\n\n\\begin{definition}{Normal equation of a plane in $\\R^3$}{normal-equation-plane}\n  Let $\\vect{n}$ be a non-zero vector in $\\R^3$, and let $P$ be a\n  point with position vector $\\vect{p}$. Then there is a unique plane through\n  $P$ with normal vector $\\vect{n}$. It is described by the equation\n  \\begin{equation*}\n    \\vect{n} \\dotprod \\vect{q} = \\vect{n} \\dotprod \\vect{p}.\n  \\end{equation*}\n  This equation is called the \\textbf{normal equation}%\n  \\index{plane!normal equation}%\n  \\index{plane!normal equation}%\n  \\index{normal equation of a plane} of the plane.\n\\end{definition}\n\n\\begin{example}{Finding the normal equation of a plane}{normal-equation}\n  Find the normal equation of the plane through the point $P=(1,3,0)$\n  and orthogonal to $\\vect{n}=\\mat{2,1,1}^T$.\n\\end{example}\n\n\\begin{solution}\n  Let $\\vect{p}=\\mat{1,3,0}^T$ be the position vector of $P$, and let\n  $\\vect{q}=\\mat{x,y,z}^T$ be the position vector of some arbitrary\n  point $Q$ in the plane. The normal equation is\n  $\\vect{n} \\dotprod \\vect{q} = \\vect{n} \\dotprod \\vect{p}$, which we\n  can write in component form:\n  \\begin{equation*}\n    \\begin{mymatrix}{c}2\\\\1\\\\1\\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c}x\\\\y\\\\z\\end{mymatrix}\n    =\n    \\begin{mymatrix}{c}2\\\\1\\\\1\\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c}1\\\\3\\\\0\\end{mymatrix}.\n  \\end{equation*}\n  We can pre-compute the dot product on the right-hand side:\n  $\\vect{n} \\dotprod \\vect{p} = 1(2)+3(1)=0(1) = 5$. Therefore, the\n  normal equation can also be written as\n  \\begin{equation*}\n    \\begin{mymatrix}{c}2\\\\1\\\\1\\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c}x\\\\y\\\\z\\end{mymatrix}\n    = 5.\n  \\end{equation*}\n\\end{solution}\n\nNotice that the last equation in Example~\\ref{exa:normal-equation} can\nalso be written in the form\n\\begin{equation*}\n  2x + y + z = 5.\n\\end{equation*}\nThis last form is called the \\textbf{standard equation} of the plane.\n\n\\begin{definition}{Standard equation of a plane in $\\R^3$}{standard-equation-plane}\n  Let $\\vect{n} = \\mat{a,b,c}^T$ be the normal vector for a plane that\n  contains the point $P = (x_0, y_0, z_0)$. The \\textbf{standard\n    equation}%\n  \\index{plane!standard equation}%\n  \\index{standard equation of a plane} of the plane is given by\n  \\begin{equation*}\n    ax + by + cz = d,\n  \\end{equation*}\n  where $a,b,c,d \\in \\R$ and $d = ax_0 + by_0 + cz_0$.\n\\end{definition}\n\n\\begin{example}{Normal and standard equations}{normal-from-three-points}\n  Find normal and standard equations for the plane through the points\n  $P = (0,1,3)$, $Q=(2,-1,0)$, and $R=(1,2,2)$.\n\\end{example}\n\n\\begin{solution}\n  We first need to find a normal vector for the plane. Since the\n  normal vector must be perpendicular to the plane, it must be\n  orthogonal to both $\\longvect{PQ}$ and $\\longvect{PR}$. We can\n  therefore use the cross product to compute a normal vector for the\n  plane:\n  \\begin{equation*}\n    \\vect{n}\n    ~=~\n    \\longvect{PQ} \\times \\longvect{PR}\n    ~=~\n    \\begin{mymatrix}{r} 2 \\\\ -2 \\\\ -3 \\end{mymatrix}\n    \\times\n    \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 5 \\\\ -1 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{center}\n    \\begin{tikzpicture}[rotate=-10]\n      \\filldraw[draw=red!80,fill=red!10](-3,0,-3.5) -- (3,0,-3.5) -- (3,0,3.5) -- (-3,0,3.5) -- cycle;\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left, pos=0.4] {$\\vect{n}$} (100:2);\n      \\draw[->,thick,blue!80!black](0,0,0) -- (2,0,1);\n      \\draw[->,thick,blue!80!black](0,0,0) -- (1,0,-2);\n      \\fill (0,0,0) circle [radius=2.2pt] node [left=3pt] {$P$};\n      \\fill (2,0,1) circle [radius=2.2pt] node [right=3pt] {$Q$};\n      \\fill (1,0,-2) circle [radius=2.2pt] node [right=3pt] {$R$};\n    \\end{tikzpicture}\n  \\end{center}\n  Now we can easily obtain the normal equation from any point on the\n  plane (say $P$) and the normal vector we just calculated:\n  \\begin{equation*}\n    \\begin{mymatrix}{r} 5 \\\\ -1 \\\\ 4 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} 5 \\\\ -1 \\\\ 4 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 3 \\end{mymatrix}\n  \\end{equation*}\n  We get the standard equation by computing the dot products on the\n  left- and right-hand sides:\n  \\begin{equation*}\n    5x - y + 4z = 11.\n  \\end{equation*}\n  It is worthwhile to double-check the answer by substituting each of\n  the three original points $P$, $Q$, and $R$ into this equation.\n  For example, for $Q=(2,-1,0)$, we obtain $5(2)-(-1)+4(0)$, which is\n  indeed $11$.\n\\end{solution}\n\n\\begin{example}{Find the normal vector of a plane}{find-normal}\n  Find a normal vector for the plane $2x+3y-z=7$.\n\\end{example}\n\n\\begin{solution}\n  The standard equation $2x+3y-z=7$ can be rewritten as a normal\n  equation\n  \\begin{equation*}\n    \\begin{mymatrix}{r} 2\\\\3\\\\-1 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c} x\\\\y\\\\z \\end{mymatrix}\n    = 7.\n  \\end{equation*}\n  Therefore,\n  \\begin{equation*}\n    \\vect{n} = \\begin{mymatrix}{r} 2\\\\3\\\\-1 \\end{mymatrix}\n  \\end{equation*}\n  is a normal vector for the plane.\n\\end{solution}\n\n\\begin{example}{Determine whether a point is on a plane}{point-plane-normal}\n  Let $\\vect{n} = \\mat{1,2,3}^T$ be the normal vector for a plane\n  which contains the point $P = (2,1,4)$. Determine if the point\n  $Q = (5,4,1)$ is in this plane.\n\\end{example}\n\n\\begin{solution}\n  By Definition~\\ref{def:normal-equation-plane}, $Q$ is a point in the\n  plane if and only if\n  \\begin{equation*}\n    \\vect{n} \\dotprod \\vect{q} = \\vect{n} \\dotprod \\vect{p},\n  \\end{equation*}\n  where $\\vect{p}$ and $\\vect{q}$ are the position vectors of $P$ and\n  $Q$, respectively.  Given $\\vect{n}$, $P$, and $Q$ as above, this\n  equation becomes\n  \\begin{equation*}\n    \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{r} 5 \\\\ 4 \\\\ 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\nSince both sides of the equation are equal to $16$, the equation is\n  true. So the point $Q$ is indeed in the plane determined by\n  $\\vect{n}$ and $P$.\n\\end{solution}\n\n\\begin{example}{Vector equation from normal equation}{vector-from-normal}\n  Find a vector equation for the plane $x+3y-2z=7$.\n\\end{example}\n\n\\begin{solution}\n  This is the same thing as finding the general solution of a system\n  of one linear equation in 3 variables. Since there is only a single\n  equation $x+3y-2z=7$, it is already in {\\ef}. The variables\n  $y$ and $z$ are free, so we set them equal to parameters: $z=t$ and\n  $y=s$. The variable $x$ is a pivot variable, and we get\n  $x=7+2t-3s$. So the general solution of the equation is\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x\\\\y\\\\z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 7\\\\0\\\\0 \\end{mymatrix}\n    + t\\,\\begin{mymatrix}{r} 2\\\\0\\\\1 \\end{mymatrix}\n    + s\\,\\begin{mymatrix}{r} -3\\\\1\\\\0 \\end{mymatrix}.\n  \\end{equation*}\n  This is also a vector equation for the plane.\n\\end{solution}\n\n\\begin{example}{Intersection of two planes}{intersection-planes}\n  Find the intersection of the planes $x-2y+z=0$ and\n  $2x-3y-z=4$.%\n  \\index{intersection!of two planes}\n\\end{example}\n\n\\begin{solution}\n  Finding the intersection means finding all of the points $(x,y,z)$\n  that are on both planes simultaneously. This is the same as solving\n  the system of equations\n  \\begin{eqnarray*}\n    x-2y+z &=& 0, \\\\\n    2x-3y-z &=& 4.\n  \\end{eqnarray*}\n  We solve the system by Gauss-Jordan elimination:\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc|c}\n      1 & -2 & 1 & 0 \\\\\n      2 & -3 & -1 & 4\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-2R_1}{\\roweq}\n    \\begin{mymatrix}{ccc|c}\n      1 & -2 & 1 & 0 \\\\\n      0 & 1 & -3 & 4\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop R_1+2R_2}{\\roweq}\n    \\begin{mymatrix}{ccc|c}\n      1 & 0 & -5 & 8 \\\\\n      0 & 1 & -3 & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the general solution is\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x\\\\y\\\\z \\end{mymatrix}\n    =\n    \\begin{mymatrix}{c} 8\\\\4\\\\0 \\end{mymatrix}\n    + t\\,\\begin{mymatrix}{c} 5\\\\3\\\\1 \\end{mymatrix},\n  \\end{equation*}\n  where $t$ is a parameter. This is the parametric equation of a\n  line. Therefore, the two planes intersect in a line. Specifically,\n  the intersection is the line through the point $(8,4,0)$ with\n  direction vector $\\mat{5,3,1}^T$.\n\\end{solution}\n\n\\begin{example}{Intersection of a line and a plane}{intersection-line-plane}\n  Find the intersection of the line\n  \\begin{equation*}\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 the plane $2x+2y-z = 2$.%\n  \\index{intersection!of a line and a plane}\n\\end{example}\n\n\\begin{solution}\n  Let us write\n  \\begin{equation*}\n    \\vect{p}=\\begin{mymatrix}{c}1\\\\2\\\\0\\end{mymatrix},\n    \\quad\n    \\vect{d}=\\begin{mymatrix}{c}-1\\\\1\\\\2\\end{mymatrix},\n    \\quad\n    \\vect{n}=\\begin{mymatrix}{c}2\\\\2\\\\-1\\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{q}=\\begin{mymatrix}{c}x\\\\y\\\\z\\end{mymatrix}.\n  \\end{equation*}\n  Then the equation of the line is $\\vect{q}=\\vect{p}+t\\,\\vect{d}$ and\n  the equation of the plane is\n  $\\vect{n}\\dotprod\\vect{q}=2$. Substituting the first equation into\n  the second one, we get $\\vect{n}\\dotprod(\\vect{p}+t\\,\\vect{d}) = 2$.\n  Using distributivity of the dot product, we can write this last\n  equation as\n  $\\vect{n}\\dotprod\\vect{p} + t(\\vect{n}\\dotprod\\vect{d}) = 2$.  By\n  computing the dot products $\\vect{n}\\dotprod\\vect{p}=6$ and\n  $\\vect{n}\\dotprod\\vect{d} = -2$, this equation simplifies to\n  $6-2t=2$, or $t=2$. Therefore, the line intersects the plane when\n  $t=2$, or at the point\n  \\begin{equation*}\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 0 \\end{mymatrix}\n    + 2 \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    = \\begin{mymatrix}{r} -1 \\\\ 4 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  An alternative method is to directly substitute the parametric\n  equation of the line, $x=1-t$, $y=2+t$, and $z=2t$, into the\n  equation of the plane, $2x+2y-z = 2$. In this case, we get\n  $2(1-t)+2(2+t)-(2t)=2$, which we can solve for $t$ to obtain $t=2$.\n\\end{solution}\n\nThe next few examples are concerned with calculating angles between\nplanes, angles between lines and planes, and finding the distance\nbetween points and planes.\n\n\\begin{example}{Find the angle between two planes}{angle-planes}\n  Find the angle between the planes $7x-y=5$ and $4x+3y+5z=3$.%\n  \\index{angle!between two planes}%\n  \\index{plane!angle between}\n\\end{example}\n\n\\begin{solution}\n  The angle between two planes is the same thing as the angle between\n  their normal vectors.\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\filldraw[draw=red!80,fill=red!10] (-3,-1,-3) -- (0,0,-3) -- (0,0,3) -- (-3,-1,3) -- cycle;\n      \\filldraw[draw=red!80,fill=red!15] (-3,1,-3) -- (3,-1,-3) -- (3,-1,3) -- (-3,1,3) -- cycle;\n      \\filldraw[draw=red!80,fill=red!10] (0,0,-3) -- (3,1,-3) -- (3,1,3) -- (0,0,3) -- cycle;\n      \\filldraw[fill=green!20,draw=green!50!black] (0,0,3) -- +(-18.4:12mm) arc (-18.4:18.4:12mm) -- cycle;\n      \\filldraw[fill=green!20,draw=green!50!black] (0,0,0) -- +(71.6:12mm) arc (71.6:108.4:12mm) -- cycle;\n      \\draw[red!80] (3,1,3) -- (-3,-1,3);\n      \\draw[red!80] (3,-1,3) -- (-3,1,3);\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left, near end] {$\\vect{n}_1$} (-1,3,0);\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[right, near end] {$\\vect{n}_2$} (1,3,0);\n      \\fill (0,0,0) circle [radius=2.2pt];\n      \\node at (0,0,0) [above=5mm] {$\\theta$};\n      \\node at (0,0,3) [right=5mm] {$\\theta$};\n    \\end{tikzpicture}\n  \\end{center}\n  The normal vectors are $\\vect{n}_1 = \\mat{7,-1,0}^T$ and $\\vect{n}_2\n  = \\mat{4,3,5}^T$. The angle between them is given by\n    \\begin{equation*}\n    \\cos\\theta =\n    \\frac{\\vect{n}_1\\dotprod\\vect{n}_2}{\\norm{\\vect{n}_1}\\norm{\\vect{n}_2}}\n    = \\frac{25}{50} = \\frac{1}{2}.\n  \\end{equation*}\n  Therefore, the angle is $\\arccos(\\frac{1}{2}) = \\pi/3$, or 60 degrees.\n\\end{solution}\n\n\\begin{example}{Find the angle between a line and a plane}{angle-line-plane}\n  Find the angle between the line\n  \\begin{equation*}\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} 2 \\\\ -1 \\\\ -2 \\end{mymatrix}\n  \\end{equation*}\n  and the plane $2x+2y-z = 2$.%\n  \\index{angle!between line and plane}\n\\end{example}\n\n\\begin{solution}\n  To get the angle $\\theta$ between the plane and the line, we can\n  compute the angle $\\phi$ between the direction vector of the line\n  and the normal vector of the plane, and then take\n  $\\theta = \\frac{\\pi}{2}-\\phi$.\n  \\begin{center}\n    \\begin{tikzpicture}[rotate=-10]\n      \\draw[thick, red!80] (50:-3) -- (0,0);\n      \\filldraw[draw=red!80,fill=red!10](-3,0,-3.5) -- (3,0,-3.5) -- (3,0,3.5) -- (-3,0,3.5) -- cycle;\n      \\filldraw[fill=yellow!20,draw=yellow!50!black] (0,0) -- (0:12mm) arc (0:50:12mm) -- cycle;\n      \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (50:12mm) arc (50:100:12mm) -- cycle;\n      \\draw[thick, red!80] (0,0) -- (50:3.5);\n      \\begin{scope}\n        \\clip (-3,0,-3.5) -- (3,0,-3.5) -- (3,0,3.5) -- (-3,0,3.5) -- cycle;\n        \\draw[thick, red!30] (50:-3) -- (0,0);\n      \\end{scope}\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left=3pt, pos=0.9] {$\\vect{n}$} (100:2);\n      \\draw[->,thick,blue!80!black](0,0) -- node[above left, pos=0.7] {$\\vect{d}$} (50:3);\n      \\draw[dashed] (0,0,0) -- (2.5,0,0);\n      \\draw[dashed] (50:3) -- +(100:-2.3);\n      \\fill (0,0,0) circle [radius=2.2pt];\n      \\node at (25:8mm) {$\\theta$};\n      \\node at (75:7mm) {$\\phi$};\n    \\end{tikzpicture}\n  \\end{center}\n  The direction vector of the line is $\\mat{2,-1,-2}^T$ and the normal\n  vector of the plane is $\\mat{2,2,-1}$. We have\n  \\begin{equation*}\n    \\cos\\phi =\n    \\frac{\\vect{n}\\dotprod\\vect{d}}{\\norm{\\vect{n}}\\norm{\\vect{d}}}\n    = \\frac{4}{9},\n  \\end{equation*}\n  and therefore $\\phi = \\arccos(\\frac{4}{9}) \\approx 1.11$ radians. We\n  have $\\theta = \\frac{\\pi}{2} - \\phi \\approx 0.46$ radians, or about\n  26.4 degrees.\n\\end{solution}\n\n\\begin{example}{Shortest distance from a point to a plane}{shortest-distance-plane}\n  Find the shortest distance from the point $P = (3,2,3)$ to the plane\n  given by $2x + y + 2z = 2$, and find the point $Q$ on the plane that\n  is closest to $P$.%\n  \\index{distance!point to plane}%\n  \\index{projection!point to plane}\n\\end{example}\n\n\\begin{solution}\n  In this problem, we are going to use the projection of one vector\n  onto another, which was introduced in\n  Section~\\ref{ssec:projections}.  Pick an arbitrary point $R$ on\n  the plane. Then, it follows that\n  \\begin{equation*}\n    \\longvect{QP} = \\proj_{\\vect{n}}\\,\\longvect{RP}\n  \\end{equation*}\n  and $\\norm{\\longvect{QP}}$ is the shortest distance from $P$ to the\n  plane. Further, the position vector of the point $Q$ can be computed\n  as $\\vect{q} = \\vect{p} - \\longvect{QP}$, where $\\vect{p}$ is the\n  position vector of $P$.\n  \\begin{center}\n    \\begin{tikzpicture}[x={(1cm,-0.2cm)},y={(0.5cm,0.5cm)},z={(0cm,1cm)}]\n      \\filldraw[draw=red!80,fill=red!10](-3,-2,0) -- (4,-2,0) -- (4,2,0) -- (-3,2,0) -- cycle;\n      \\draw[dashed](0,0,0) -- (2,0,0) -- (2,0,3) -- (0,0,3) -- cycle;\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left=3pt] {$\\vect{n}$} (0,0,2);\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left=3pt, pos=0.7] {$\\longvect{RP}$} (2,0,3);\n      \\draw[->,thick,blue!80!black](2,0,0) -- node[right=3pt, pos=0.7] {$\\longvect{QP}$} (2,0,3);\n      \\fill (0,0,0) circle [radius=2.2pt] node [left=3pt] {$R$};\n      \\fill (2,0,3) circle [radius=2.2pt] node [right=3pt] {$P$};\n      \\fill (2,0,0) circle [radius=2.2pt] node [right=3pt] {$Q$};\n    \\end{tikzpicture}\n  \\end{center}\n  From the above scalar equation, we have that $\\vect{n} =\n  \\begin{mysmallmatrix}{c} 2 \\\\ 1 \\\\ 2 \\end{mysmallmatrix}$.  Now, choose any\n  point on the plane, for example, $R = (1,0,0)$ (notice that this\n  satisfies $2x+y+2z=2$).  Then,\n  \\begin{equation*}\n    \\longvect{RP} = \\begin{mymatrix}{c} 3 \\\\ 2 \\\\ 3 \\end{mymatrix}\n    - \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix} =\n    \\begin{mymatrix}{c} 2 \\\\ 2 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  Next, compute $\\longvect{QP} = \\proj_{\\vect{n}}\\longvect{RP}$.\n  \\begin{equation*}\n    \\longvect{QP} ~=~ \\proj_{\\vect{n}}\\longvect{RP}\n    ~=~ \\paren{\\frac{\\vect{n}\\dotprod\\longvect{RP}}{\\norm{\\vect{n}}^2}}\\vect{n}\n    ~=~ \\frac{12}{9} \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    ~=~ \\frac{4}{3} \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  Then, $\\norm{\\longvect{QP}} = 4$ so the shortest distance from $P$\n  to the plane is $4$.  To find the point $Q$ on the plane that is\n  closest to $P$, we have\n  \\begin{equation*}\n    \\vect{q} ~=~ \\vect{p} - \\longvect{QP}\n    ~=~ \\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 3 \\end{mymatrix}\n    -\n    \\frac{4}{3} \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    ~=~\n    \\frac{1}{3}\n    \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, $Q = (\\frac{1}{3},\\frac{2}{3},\\frac{1}{3})$.\n\\end{solution}\n", "meta": {"hexsha": "7b15b9ef375b922ea35b5052ca892a342ce6a318", "size": 24390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinesAndPlanes-Planes.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinesAndPlanes-Planes.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinesAndPlanes-Planes.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.380794702, "max_line_length": 107, "alphanum_fraction": 0.6273062731, "num_tokens": 9289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938677, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6773823185850528}}
{"text": "\\chapter{Fundamental Lemma of Calculus of Variations}\\label{app:fundamental-lemma-of-calculus-of-variations}\n\nThe \\textit{Fundamental Lemma of Calculus of Variations}\\footnote{\\url{http://en.wikipedia.org/wiki/Fundamental_lemma_of_calculus_of_variations}} says that, for continuous functions, the condition\n\\begin{align}\n  \\int_{-\\infty}^\\infty dx f(x)\\eta(x)\n=\n  0\n\\text{ for all $\\eta(x)$}\n\\end{align}\nholds only when $f(x)=0$ for all $x$.\nWe can see this by considering the case $\\eta(x)=f(x)$.\nSince $f(x)^2$ is nonnegative everywhere, the integral yields a positive number whenever $f(x)\\neq 0$ on a finite range of $x$ values.\n", "meta": {"hexsha": "85fe335f6a7bbdc377f7703cdba14a1573c215ed", "size": 633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/fundamental-lemma-calculus-variations.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/fundamental-lemma-calculus-variations.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/fundamental-lemma-calculus-variations.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": 48.6923076923, "max_line_length": 196, "alphanum_fraction": 0.7456556082, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.859663754105328, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6773558981850424}}
{"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\\usepackage{setspace}\n\n\\usepackage{pgfplots}\n\\pgfplotsset{compat=1.16}\n\n% Begin Document\n\\begin{document}\n\n\\section{Experimental Data}\n\nUtilizing the two algorithms outlined above, we set out to test them with some randomized, undirected graphs.\nWe did this by generating random adjacency matrices.\nEach node had a connection to itself for ease of comparsion.\nEach node then had a chance to be connected to each other node, which we termed the graph density.\nWe used a value of $30\\%$ for this graph density.\n\nThen for each randomly generated graph, we ran both the brute force and approximation algorithms on it.\nWe did starting with a graph of 20 nodes, and ran these algorithms on a new randomized graph of incrementally larger size until the runtime exceeded 24 hours.\nThis happened at the 37-node mark with our implementation and hardware.\nThe data is below:\n\n\\singlespacing\n\n\\begin{center}\n\\begin{tabular}{c | r r | r r}\n\n     & \\multicolumn{2}{c |}{\\textbf{Minimum Set}} & \\multicolumn{2}{c}{\\textbf{Approximate Set}} \\\\\n     \\textbf{\\# of Vertices} & \\textbf{Size} & \\textbf{Time (seconds)} & \\textbf{Size} & \\textbf{Time (seconds)} \\\\ \\hline\n\n     20 &         4 &          0.46 &    7 &          8.6 e-6     \\\\\n     21 &         4 &          1.00 &    5 &          6.5 e-6     \\\\\n     22 &         4 &          2.09 &    5 &          6.6 e-6     \\\\\n     23 &         4 &          4.46 &    7 &          9.2 e-6     \\\\\n     24 &         4 &          9.44 &    8 &          1.0 e-5    \\\\\n     25 &         5 &          20.15 &    7 &          9.6 e-6     \\\\\n     26 &         5 &          42.07 &    5 &          8.9 e-6     \\\\\n     27 &         4 &          90.59 &    6 &          1.0 e-5    \\\\\n     28 &         4 &          233.23 &    8 &          1.2 e-5    \\\\\n     29 &         4 &          395.63 &    8 &          1.2 e-5    \\\\\n     30 &         4 &          852.31 &    7 &          1.3 e-5     \\\\\n     31 &         4 &          1,834.03 &    7 &          1.4 e-5    \\\\\n     32 &         4 &          3,869.44 &    6 &          1.4 e-5    \\\\\n     33 &         4 &          8,145.86 &    6 &          1.4 e-5    \\\\\n     34 &         4 &          17,353.50 &    7 &          1.5 e-5    \\\\\n     35 &         5 &          35,943.60 &    10&          1.9 e-5   \\\\ \n     36 &         4 &          75,798.40 &    7 &          1.8 e-5  \\\\   \n     37 &         4 &          161,439.00  &    8 &          2.0 e-5\n    \n\\end{tabular}\n\\end{center}\n\n\\onehalfspacing\n\nThe doubling of the time needed to run each incrementally larger graph through the brute force algorithm is easily spotted in the data.\nWhile a 37-node graph is not quite double the size of a 20-node graph, the time required ballooned from a half-second to nearly 45 hours.\nAs the trend will continue due to the nature of the brute force approach, we can extrapolate that a 38-node graph will take approximately 90 hours to compute the minimum set.\nFurther extrapolation reveals a 50-node graph will take over 42 \\textit{years}.\n\nOn the other hand, the approximation algorithm ran near instantaneously for each graph, with its growth much lower.\nThe runtime of the approximation algorithm was measured in microseconds.\nAs is apparent, the approximation algorithm runs in orders of magnitude faster time than the brute force approach.\n\nThe question remains though, just how efficient is the approximation algorithm in terms of the size of the minimum set?\nBelow is a chart showing the relation between the minimum size and the approximate size for the data recorded above.\n\n\\vspace{5mm}\n\n\\begin{figure}[H]\n\\begin{center}\n\\begin{tikzpicture}\n    \\begin{axis}\n        [\n            xlabel = {\\# of Vertices},\n            ylabel = {Size of Set},\n            xmin=19,xmax=38,\n            ymin=0,ymax=16,\n            xtick={20,25,30,35},\n            ytick={2,4,6,8,10}\n        ]\n\n        \\addplot[mark=*,blue] plot coordinates {\n            (20,4)\n            (21,4)\n            (22,4)\n            (23,4)\n            (24,4)\n            (25,5)\n            (26,5)\n            (27,4)\n            (28,4)\n            (29,4)\n            (30,4)\n            (31,4)\n            (32,4)\n            (33,4)\n            (34,4)\n            (35,5)\n            (36,4)\n            (37,4)\n        };\n        \\addlegendentry{Minimum Set}\n\n        \\addplot[mark=*,red] plot coordinates {\n            (20,7)\n            (21,5)\n            (22,5)\n            (23,7)\n            (24,8)\n            (25,7)\n            (26,5)\n            (27,6)\n            (28,8)\n            (29,8)\n            (30,7)\n            (31,7)\n            (32,6)\n            (33,6)\n            (34,7)\n            (35,10)\n            (36,7)\n            (37,8)\n        };\n        \\addlegendentry{Approximate Set}\n\n    \\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nAs this chart shows, the approximate solution only found a minimum solution one time.\nThis indicates that it is entirely possible for the approximate solution to agree with the brute force approach.\nHowever, the chart also clearly shows that the majority of cases in our test data were much larger than the minimal solution, often times double the size.\n\n\\end{document}", "meta": {"hexsha": "f81e84594065b38256135d13aa3815957cdc51f7", "size": 5351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/Minimum Dominating Set/docs/tex/experimentdata.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/experimentdata.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/experimentdata.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": 37.1597222222, "max_line_length": 174, "alphanum_fraction": 0.5333582508, "num_tokens": 1571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.6773558768116933}}
{"text": "\\chapter{Benchmarks} \\label{benchmarks}\n\n\\note{\nSome programs over numbers, some over lists, some over lists of lists and some over trees (What kind of trees?).\nFor every program, try to get a sample implementation. \\\\\nTypes needed: \\lstinline?Int, [a], Tree a? \\\\\nBasic components needed:\narithmetic (\\lstinline?+, -, *, /?), \nrelation (\\lstinline?<, <=, ==, /=, >=, >?),\n\\note{(maybe we do not need relations)}\n}\n\n\\begin{enumerate}\n\t\\item max of two numbers\\\\\n\t(hopefully) the easiest program \\\\\n\t\\begin{lstlisting}\nmax :: Int -> Int -> Int\nmax 0 0 == 0\nmax 1 0 == 1\nmax 0 1 == 1\nmax x y = if x > y then x else y\n\t\\end{lstlisting}\n\t\\note{We don't care about conditionals, we cannot synthesize this.}\\\\\n\tThis is the only function that requires a conditional branch.\n%\n\t\\item square a number\n\t\\begin{lstlisting}\nsquare :: Int -> Int -> Int\nsquare 0 == 0\nsquare 1 == 1\nsquare 2 == 4\nsquare 3 == 9\nsquare x = x * x\n\t\\end{lstlisting}\n\tThat is, basic arithmetic operations like \\lstinline!+ - * /! should be provided\n%\n\t\\item tetrahedral numbers \\\\\n\t\\begin{lstlisting}\ntetrahedral :: Int -> Int\ntetrahedral 1 == 1\ntetrahedral 2 == 4\ntetrahedral 3 == 10\n\t\\end{lstlisting}\n\tclosed form solution\n\t\\begin{lstlisting}\ntetrahedral n = n * (n+1) * (n+2) / 6\n\t\\end{lstlisting}\n\titerative solution\n\t\\begin{lstlisting}\ntetrahedral n = scanl1 (+) (scanl1 (+) [0..]) !! n\n\t\\end{lstlisting}\n\tAnother iterative solution (without infinite lists)\n\t\\begin{lstlisting}\ntetrahedral n = foldl1 (+) (scanl1 (+) (enumFromTo 1 n))\n\t\\end{lstlisting}\n\tComponents needed: \\lstinline?scanl1, !!? \\\\\n\tInterestingly the iterative version is much faster than the closed form solution\n%\n\t\\item prime test \\\\\n\tI think this is too difficult\n\t\\begin{lstlisting}\nprime :: Int -> Int\nprime 1 == 0\nprime 2 == 1\nprime 3 == 1\nprime 4 == 0\nprime 25 == 0\nprime 29 == 1\nprime n = minimum (1 : (map (mod n) (enumFromTo 2 (subtract 1 n))))\n\t\\end{lstlisting}\n\tComponents needed: \\lstinline?map, mod, minimum, enumFromTo, subtract?\n%\n\t\\item average\n\t\\begin{lstlisting}\naverage :: [Int] -> Int\naverage [1] == 1\naverage [1,3] == 2\naverage [1,2,3,6] == 6\naverage xs = (sum xs) `div` (length xs)\n\t\\end{lstlisting}\n%\n\t\\item movingAverage (forward)\n\t\\begin{lstlisting}\nmovingAverage :: Int -> [Int] -> [Int]\nmovingAverage 1 [1,2,3] == [1,2,3]\nmovingAverage 2 [1,2,3] == [2,2,3]\nmovingAverage 3 [3,2,4,1,5,2] == [3,2,3,2,3,2]\nmovingAverage n xs = map (average . take n) (init $ tails xs)\n\t\\end{lstlisting}\n\tComponents needed: \\lstinline?tails? from \\lstinline?Data.List? and  \\lstinline?average? (one of the benchmarks), as well as \\lstinline?map, take? and \\lstinline?init? from \\lstinline?Prelude?.\n%\n\t\\item movingSum (backward)\n\t\\begin{lstlisting}\nmovingSum :: Int -> [Int] -> [Int]\nmovingSum 1 [1,2,3] == [1,2,3]\nmovingSum 2 [1,2,3] == [1,3,5]\nmovingSum 3 [4,8,6,-1,-2,-3,-1,3,4,5] == [4,12,18,13,3,-6,-6,-1,6,12]\nmovingSum n xs = scanl1 (+) (zipWith (-) xs (replicate n 0 ++ xs))\n\t\\end{lstlisting}\n%\n\t\\item waterflow problem \\\\\n\tGiven an array of \"wall\" heights, determine the volume of the puddles that can form if it rains.\n\t\\begin{lstlisting}\nwater :: [Int] -> Int\nwater [1,2,3] == 0\nwater [5,2,5] == 3\nwater [2,3,1,6,1] == 2\nwater h = sum $ \n      zipWith (-) \n        (zipWith min (scanl1 max h) (scanr1 max h))\n        h\n\t\\end{lstlisting}\n%\n\t\\item horner schema to evaluate polynomials\n\t\\begin{lstlisting}\nhorner :: [Int] -> Int -> Int\nhorner [1,2,3] 1 == 6\nhorner [1,2,3] 2 == 11\nhorner [4,3,2] 3 == 47\nhorner p x = foldl1 ((+) . (x *)) p\n\t\\end{lstlisting}\n\tProblem: we do not generate lambda's. Do we generate functions like \\lstinline?(x *)??\n%\n\t\\item sum-under, sum all integers up to the argument\n\t\\begin{lstlisting}\nsum_under :: Int -> Int\nsum_under 0 == 0\nsum_under 1 == 1\nsum_under 2 == 3\nsum_under 3 == 6\nsum_under 4 == 10\nsum_under n = sum [1..n]\n\t\\end{lstlisting}\n\tComponents needed: \\lstinline?sum, enumFromTo?\n%\n\t\\item factorial \\\\\n\t\\begin{lstlisting}\nfactorial :: Int -> Int\nfactorial 0 == 0\nfactorial 1 == 1\nfactorial 3 == 6\nfactorial 5 == 120\nfactorial n = product [1..n]\n\t\\end{lstlisting}\n\tinteresting for intermediate states\n%\n\t\\item maximum of a list\\\\\n\tI don't know (yet) how to specify a \"global property\" like greater or smaller than all other elements in a list in \\textsc{Synquid}. Moreover, it seems a difficult property to extract from input-output examples.\n\t\\begin{lstlisting}\nmaximum :: [Int] -> Int\nmaximum [1,3,2] == 3\nmaximum [4,2,1] == 4\nmaximum [1,3,5] == 5\nmaximum xs = foldr max (head xs) xs\n\t\\end{lstlisting}\n\tOr just use the \\lstinline?maximum? function from \\lstinline?Prelude?, if it is given as a component\n%\n\t\\item append two lists\\\\\n\tThe specification given by Nadia does not synthesize the usual append function. Maybe it's better to let her know...\\\\\n\tAlthough it's possible to synthesize append in \\textsc{Synquid}.\n\t\\begin{lstlisting}\nappend :: [a] -> [a] -> [a]\nappend [1,2,3] [4,5,6] == [1,2,3,4,5,6]\nappend [1,2] [6,2,3] == [1,2,6,2,3]\nappend xs ys = foldr (:) ys xs\n\t\\end{lstlisting}\n\tOr use \\lstinline?++? from \\lstinline?Prelude?, if we decide to provide it for this example too.\n%\n\t\\item length of a list \\\\\n\tCan be also interesting for intermediate states\n\t\\begin{lstlisting}\nlength :: [a] -> Int\nlength [1,2,3] == 3\nlength [2,2,2] == 3\nlength [] == 0\nlength [5] == 1\nlength xs = sum $ map (const 1) xs\n\t\\end{lstlisting}\n%\n\t\\item list reversal\n\t\\begin{lstlisting}\nreverse :: [a] -> [a]\nreverse [1,2,3] == [3,2,1]\nreverse [5,2,3] == [3,2,5]\nreverse [6,2,3,1] == [1,3,2,6]\nreverse xs = foldl (flip (:)) [] xs\n\t\\end{lstlisting}\n%\n\t\\item bagsum: \\lstinline![far,bar,gar,bar,bar,far] -> [(bar,3),(far,2),(gar,1)]!\\\\\n\tSeems difficult and maybe intermediate states can be helpful. Should I take \\lstinline?Int? instead of \\lstinline?a?? I mean, \\lstinline?a? should belong to the typeclass \\lstinline?Ord?, otherwise we cannot yield a sorted output list. And we do not have any other base types anyway. But actually lists of integers are also ordable. Hence also lists of lists of integers and lists of lists of lists of integers and so on.\n\t\\begin{lstlisting}\nbagsum :: [a] -> [(a, Int)]\nbagsum [1,1,1] == [(1,3)]\nbagsum [4,4,2,1,2,1] == [(1,2),(2,2),(4,2)]\nbagsum [3,2,1,3,2,3] == [(1,1),(2,2),(3,3)]\nbagsum xs = map (head &&& length) (group (sort xs))\n\t\\end{lstlisting}\n\tComponents needed: \\lstinline?&&&? from \\lstinline?Control.Arrow?. And we also need \\lstinline?Tuples? for this one.\n%\n\t\\item stutter \\\\\n\tRepeat every list element twice.\n\t\\begin{lstlisting}\nstutter :: [a] -> [a]\nstutter [] == []\nstutter [1,2,3] == [1,1,2,2,3,3]\nstutter xs = concatMap (replicate 2) xs\n\t\\end{lstlisting}\n%\n\t\\item map \\\\\n\tIsn't it a higher order function? I thought we synthesize only first order functions.\\\\\n\tHow can we provide examples? I mean, we have to write functions as well.\\\\\n\t\\begin{lstlisting}\nmap :: (a -> b) -> [a] -> [b]\nmap f xs = foldr ((:) . f) [] xs\n\t\\end{lstlisting}\n%\n\t\\item zipWith \\\\\n\tit's a higher order function as well. We need Tuples.\\\\\n\tHow do we provide the examples?\n\t\\begin{lstlisting}\nzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]\nzipWith f xs ys = map (uncurry f) (zip xs ys)\n\t\\end{lstlisting}\n\tComponents needed: \\lstinline?map, uncurry, zip?.\n%\n\t\\item list drop\n\t\\begin{lstlisting}\ndrop :: Int -> [a] -> [a]\ndrop 0 [1,2,3] == [1,2,3]\ndrop 1 [1,2,3] == [2,3]\ndrop 5 [5,4,2,5] == []\ndrop 3 [4,2,3,1] == [1]\ndrop n xs = snd (splitAt n xs)\n\t\\end{lstlisting}\n%\n\t\\item droplast, drop the last element of a list\n\t\\begin{lstlisting}\ndroplast :: [a] -> [a]\ndroplast [] == []\ndroplast [1] == []\ndroplast [1,2,3] == [1,2]\ndroplast [3,2,1]== [3,2]\ndroplst = init\ndroplast' xs = map fst (zip xs (enumFromTo 1 (subtract 1 (length xs))))\ndroplast'' xs = take (subtract 1 (length xs)) xs\n\t\\end{lstlisting}\n%\n\t\\item dropmax, drop the greatest element of a list\\\\\n\t$\\lambda^2$ takes much more time to synthesize droplast than dropmax. Why?\n\t\\begin{lstlisting}\ndropmax :: [Int] -> [Int]\ndropmax [1,2] == [1]\ndropmax [2,1] == [1]\ndropmax [1,2,3] == [1,2]\ndropmax [3,2,1] == [2,1]\ndropmax [2,3,1] == [2,1]\ndropmax xs = filter (/= (maximum xs)) xs\n\t\\end{lstlisting}\n%\n\t\\item dedup, remove duplicates from a list \\\\\n\t$\\lambda^2$ requires more time\\\\\n\t\\TODO{Find a non-recursive implementation that preserves the order of the elements} Either implement it with \\lstinline?groupBy? or say you cannot implement it. Say it's not possible to get the usual semantics of deleting all but the first occurrence of some program.\n%\n\t\\item sort by length (on lists of lists)\n\t\\begin{lstlisting}\nsortByLength :: [[a]] -> [[a]]\nsortByLength [[1,2],[1,2,3],[1]] == [[1],[1,2],[1,2,3]]\nsortByLength = sortBy (curry ((uncurry compare) . (length *** length)))\n\t\\end{lstlisting}\n\t\\TODO{Is there a shorter implementation?} What's wrong with this one? \\\\\n\tComponents needed: \\lstinline?(***)? from \\lstinline?Control.Arrow?\n%\n\t\\item dropmins \\\\\n\t$\\lambda^2$ required more time to synthesize it\n\t\\begin{lstlisting}\ndropmins :: [[Int]] -> [[Int]]\ndropmins [[1,2,3],[2,3,1],[2,3],[1]] == [[2,3],[2,3],[3],[]]\ndropmins = map dropmin\n\t\\end{lstlisting}\n\t\\TODO{Is there an implementation without the auxiliary function \\lstinline?dropmin? and without lambda expressions?} Yes, there is one, but you don't want to see it. With \\lstinline?ap? and \\lstinline?join?.\n%\n\t\\item lasts, last element of every list \\\\\n\tanother program on nested lists\n\t\\begin{lstlisting}\nlasts :: [[a]] -> [a]\nlasts [[1,2,3],[3,2],[4,2,4,1],[2]] == [3,2,1,2]\nlasts = map last\n\t\\end{lstlisting}\n%\n\t\\item member of the tree\\\\\n\tSomething with trees. Membership seems a difficult thing to learn from input-output examples.\n%\n\t\\item count leaves it a tree\n%\n\t\\item nodes at level\n\tThe standard Haskell tree is a rose tree. Defined in \\lstinline?Data.Tree?.\n\t\n\\note{Nadia has more complicated examples with Red-Black-Trees, AVL-trees and different sorting algorithms}\n\\end{enumerate}\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"thesis\"\n%%% End:\n", "meta": {"hexsha": "c898b04117d06a966222e2fb3d274d065f377774", "size": 9903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/benchmarks.tex", "max_stars_repo_name": "shasfin/ml4fp2016", "max_stars_repo_head_hexsha": "7f46de0047d0a4a5b1a80d554cd3a635feec9550", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-26T14:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T19:41:51.000Z", "max_issues_repo_path": "thesis/benchmarks.tex", "max_issues_repo_name": "shasfin/ml4fp2016", "max_issues_repo_head_hexsha": "7f46de0047d0a4a5b1a80d554cd3a635feec9550", "max_issues_repo_licenses": ["MIT"], "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/benchmarks.tex", "max_forks_repo_name": "shasfin/ml4fp2016", "max_forks_repo_head_hexsha": "7f46de0047d0a4a5b1a80d554cd3a635feec9550", "max_forks_repo_licenses": ["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.1525974026, "max_line_length": 422, "alphanum_fraction": 0.6631323841, "num_tokens": 3473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6773558740103371}}
{"text": "\\paragraph{Answer 3.}\n\n\\begin{enumerate}\n\n  \\item The first regular expression can be simplified in the\n    following way:\n   \\begin{align*}\n     \\lparen \\epsilon \\, \\disjM{} \\, a\\kleeneM{} \\, \\disjM{} \\,\n     b\\kleeneM{} \\, \\disjM{} \\, a \\, \\disjM{} \\, b \\rparen\\kleeneM\n     &= \\lparen \\epsilon \\, \\disjM{} \\, a\\kleeneM{} \\, \\disjM{} \\,\n     b\\kleeneM{} \\, \\disjM{} \\, b\\rparen\\kleeneM, & \\text{since}\n     \\, L(a) \\subset L(a\\kleeneM);\\\\\n     &= \\lparen \\epsilon \\, \\disjM{} \\, a\\kleeneM{} \\, \\disjM{} \\,\n     b\\kleeneM\\rparen\\kleeneM, & \\text{since} \\,\n     L(b) \\subset L(b\\kleeneM);\\\\\n     &= \\lparen \\epsilon \\, \\disjM{} \\, a\\plusM{} \\, \\disjM{} \\,\n     b\\plusM\\rparen\\kleeneM, & \\text{since} \\, \\{\\epsilon\\}\n     \\subset L(x\\kleeneM);\\\\\n     &= \\lparen a\\plusM{} \\, \\disjM{} \\, b\\plusM\\rparen\\kleeneM, &\n     \\text{since} \\, \\lparen\\epsilon \\, \\disjM{} \\,\n     x\\rparen\\kleeneM = x\\kleeneM.\n   \\end{align*}\n   Words in \\(L(\\lparen a\\plusM{} \\, \\disjM{} \\,\n   b\\plusM\\rparen\\kleeneM)\\) are of the form \\(\\epsilon\\) or\n   \\((a\\ldots a)\\) \\((b \\ldots b)\\) \\((a\\ldots a)\\) \\((b\\ldots\n    b)\\ldots\\), where the ellipsis stands for `none or many times'.\n   So we recognise \\(\\lparen a \\, \\disjM{} \\,\n   b\\rparen\\kleeneM\\). Therefore \\(\\lparen \\epsilon \\, \\disjM{}\n   \\, a\\kleeneM{} \\, \\disjM{} \\, b\\kleeneM{} \\, \\disjM{} \\, a \\,\n   \\disjM{} \\, b \\rparen\\kleeneM = \\lparen a \\, \\disjM{} \\,\n   b\\rparen\\kleeneM\\).\n\n  \\item The second regular expression can be simplified in the\n    following way. We note first that the expression is made of the\n    disjunction of three regular sub-expressions (\\emph{i.e.,} it is a\n    union of three sub-languages). The simplest idea is then to check\n    whether one of these sub-languages is redundant, \\emph{i.e.,} if\n    one is included in another. If so, we can simply remove it from\n    the expression.\n  \\begin{align*}\n     a \\lparen a \\, \\disjM{} \\, b \\rparen\\kleeneM{} b \n     \\, \\disjM{} \\, \\lparen a b \\rparen\\kleeneM{} \n     \\, \\disjM{} \\, \\lparen b a \\rparen\\kleeneM\n     &= a \\lparen a \\, \\disjM{} \\, b \\rparen\\kleeneM{} b \n     \\, \\disjM{} \\, \\epsilon\n     \\, \\disjM{} \\, \\lparen a b \\rparen\\plusM{} \n     \\, \\disjM{} \\, \\lparen b a \\rparen\\kleeneM,\\\\\n     & \\qquad \\text{since} \\, \\lparen ab \\rparen\\kleeneM =\n     \\epsilon \\, \\disjM{}\\, \\lparen ab \\rparen\\plusM;\\\\\n     &= a \\lparen a \\, \\disjM{} \\, b \\rparen\\kleeneM{} b \n     \\, \\disjM{} \\, \\lparen a b \\rparen\\plusM{} \n     \\, \\disjM{} \\, \\lparen b a \\rparen\\kleeneM,\\\\\n     & \\qquad \\text{since} \\, \\{\\epsilon\\} \\subset L(\\lparen ba\n     \\rparen\\kleeneM).\n  \\end{align*}\n  We have:\n  \\begin{align*}\n    \\lparen ab\\rparen\\plusM\n   &= \\lparen ab\\rparen \\lparen ab\\rparen \\ldots \\lparen ab \\rparen\\\\\n   &= a\\lparen ba\\rparen\\lparen ba\\rparen\\ldots\\lparen  ba\\rparen b \\;\n    \\disjM{} \\; ab\\\\\n   &= a\\lparen ba \\rparen\\kleeneM b.\n   \\end{align*}\n   Also \\(L(\\lparen ba \\rparen) \\subset L(\\lparen a \\, \\disjM{}\n   \\, b\\rparen\\kleeneM)\\) and then \\(L(\\lparen ba\n   \\rparen\\kleeneM) \\subset L(\\lparen a \\, \\disjM{} \\,\n   b\\rparen\\kleeneM)\\), because \\(\\lparen a \\, \\disjM{} \\,\n   b\\rparen\\kleeneM\\) denotes all the words. Therefore\n   \\begin{align*}\n      L(a\\lparen ba \\rparen\\kleeneM b) \n    &\\subset L(a \\lparen a \\, \\disjM{} \\, b\\rparen\\kleeneM b)\\\\\n      L(\\lparen ab\\rparen\\plusM) \n    &\\subset L(a \\lparen a \\, \\disjM{} \\, b\\rparen\\kleeneM b)\n   \\end{align*}\n\n   As a consequence, one possible answer is\n   \\begin{equation*}  \n     a \\lparen a \\, \\disjM{} \\, b \\rparen\\kleeneM{} b \n     \\, \\disjM{} \\, \\lparen a b \\rparen\\kleeneM{} \n     \\, \\disjM{} \\, \\lparen b a \\rparen\\kleeneM\n     = a \\lparen a \\, \\disjM{} \\, b\\rparen\\kleeneM b \n     \\, \\disjM{} \\, \\lparen ba \\rparen\\kleeneM.\n   \\end{equation*}\n   The intersection between \\(L(a \\lparen a \\, \\disjM{} \\,\n   b\\rparen\\kleeneM b)\\) and \\(L(\\lparen ba \\rparen\\kleeneM)\\)\n   is empty because all the words of the former start with\n     \\(a\\), while all the words of the other start with \\(b\\) (or is\n     \\(\\epsilon\\)).  Therefore we cannot simply further this way.\n\n\\end{enumerate}\n", "meta": {"hexsha": "339c6c588f2280b1cd6fa5cf28b8ae9143abe537", "size": 4041, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regexp_answer_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_answer_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_answer_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": 44.4065934066, "max_line_length": 70, "alphanum_fraction": 0.5822816135, "num_tokens": 1616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.6773393422315609}}
{"text": "\\section{Introduction}\n\n\\begin{frame}{\\emph{``Does Watching Football on TV Cause Hair Loss?''}}\n    \n    \\begin{itemize}\n        \\item 296 British subjects were asked about their hair loss and how much football they watch on television, \\cite{DMJSDS2003}.\n    \\end{itemize}\n\n    \\begin{block}{Contingency Table}\n\n    One can represent the responses in a $3\\times 3$ \\emph{contingency table}:\n\n    \\begin{table}[h]\n    \\vspace{12pt}\n        \\begin{tabular}{@{}lcccc@{}} \n        & &  \\multicolumn{3}{c}{Hair Amount}\\\\\\cmidrule{3-5} \n        TV Hours & & lots & medium & balding\\\\ \\midrule \n        $\\leq 2$h & & 51 & 45 & 33 \\\\ \n        $2-6$ h & & 28 & 30 & 29 \\\\ \n        $\\geq 6$h & & 15 & 27 & 38\\\\\\bottomrule\n        \\end{tabular}\n    \\end{table} \n    \\end{block}\n\n    \\begin{itemize}\n        \\item Is there an association between the variables, or are they independent?\n    \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}{\\emph{``Does Watching Football on TV Cause Hair Loss?''}}\n    $$ M = \\begin{bmatrix} \n    51 & 45 & 33 \\\\ \n    28 & 30 & 29 \\\\ \n    15 & 27 & 38\n    \\end{bmatrix} $$\n\n    \\begin{block}{Null Hypothesis}\n    \\vspace*{-18pt}\n        \\begin{equation*}\n            H_{0}: \\qquad \\text{\\emph{Football on TV and Hair Loss are Independent.}}\n        \\end{equation*}\n    \\vspace*{-18pt}\n    \\end{block}\n\n    \\begin{itemize}\n        \\item Independence $\\implies$ odds ratios all equal one:\n            $$ \\text{Odds Ratio} = \\frac{ m_{ij}\\cdot m_{(i+1)(j+1)} } { m_{(i+1)j} \\cdot m_{i(j+1)} } = 1, \\quad (\\text{for all } i,j). $$\n        \\item But (for example): $51 \\cdot 30 - 45 \\cdot 28 = 1530 - 1260 = 270 \\neq 0\\, \\ldots\\, $?\n    \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}{\\emph{``Does Watching Football on TV Cause Hair Loss?''}}\n\n    \\begin{itemize}\n        \\item A better explanation is obtained by identifying a certain \\emph{hidden variable}, which is the \\emph{gender identification} of the respondents:\n    \\end{itemize}\n\n    $$ M  = M_{m} + M_{f} = \n    \\underbrace{\\begin{bmatrix} \n    3 & 9 & 15 \\\\ \n    4 & 12 & 20 \\\\ \n    7 & 21 & 35\n    \\end{bmatrix}}_{126 \\text{ male}} + \n    \\underbrace{\\begin{bmatrix} \n    48 & 36 & 18 \\\\\n    24 & 18 & 9 \\\\\n    8 & 6 & 3\n    \\end{bmatrix}}_{170 \\text{ female}}.  $$\n\n    \\begin{block}{Alternative Hypothesis}\n        Instead, we include \\emph{conditional independence}:\n        \\begin{equation*}\n            H_{1}: \\text{ \\emph{Football on TV \\& Hair Loss are Independent} given \\emph{Gender.}}\n        \\end{equation*}\n    \\end{block}\n\n\\end{frame}\n", "meta": {"hexsha": "d59f9257772b6d5870685bee03363c37f3f45b9b", "size": 2515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/intro.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/intro.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/intro.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": 31.4375, "max_line_length": 157, "alphanum_fraction": 0.573359841, "num_tokens": 873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6773393304336476}}
{"text": "\\section{Delayed Neutrons}\nMost neutrons born in the core are prompt neutrons, about 99\\%.\nThe rest are \\textit{deyaled neutrons} and come after a fission\nfragment beta decays,\n%FIXME insert fission fragment figure here.\n\\underline{Call} $\\beta$ the fraction [iunitless] of neutrons that are delayed, ie\nthat are not prompt.  Typically $\\beta$ is chopped up into $I$ groups the each represent\na different mean generation time for thatgroup. Say $i\\in I$, then,\n\\[ \\beta = \\sum_{i=1}^I \\beta_i \\]\nand by convention, $beta_1$ has the longest generation time and $\\beta_I$ has the shortest\ngeneration time. $I=6$ is pretty standard.\n\nThus the shource of prompt neutrons, rather than being $\\nu\\Sigma_f\\phi$ is now,\n\\[ \\mathrm{propmpt source} = (1 - \\beta) \\nu \\Sigma_f \\phi \\]\nCall $C_i(t)$ the \\underline{concentration} [1/cm$^3$] of gthe ith group and\n$\\lambda_i = \\ln(2) / T_{1/2, i}$i sthe \\underline{decay constant} [1/s] of the\nith group. for the half-life [s] of the ith group. The total delayed source is then\n\\[ \\mathrm{delayed source} = \\sum_{i=1}^I \\lambda_i C_i(t)\\]\nGiven that $\\beta_i\\nu\\Sigma_f\\phi$\nis the number of ith group neutrons that are born each generation, the concentration ith group\ndelayed neutrons at any time is,\n\\[ \\frac{dC_i(t)}{dt} = \\beta_i\\nu\\Sigma_f\\phi(t) - \\lambda_i C_i(t)\\]\nRecasting the prompt equation as,\n\\[ \\frac{1}{v} \\frac{d\\phi}{dt} = (1-\\beta)\\nu\\Sigma_f\\phi(t) + \\sum_{i=1}^I \\lambda_i C_i(t) - \\Sigma_a\\phi(t) - DB^2\\phi(t) \\]\nThus we have a system of $I+1$ equations and $I+1$ unknowns.", "meta": {"hexsha": "3fd0b32c9858223f36070d99fd525aa4948dac83", "size": 1534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/n05.tex", "max_stars_repo_name": "scopatz/rxps", "max_stars_repo_head_hexsha": "bef0045f12215ebe0ac15f9e944047eaefb0ec36", "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": "notes/n05.tex", "max_issues_repo_name": "scopatz/rxps", "max_issues_repo_head_hexsha": "bef0045f12215ebe0ac15f9e944047eaefb0ec36", "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/n05.tex", "max_forks_repo_name": "scopatz/rxps", "max_forks_repo_head_hexsha": "bef0045f12215ebe0ac15f9e944047eaefb0ec36", "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": 61.36, "max_line_length": 128, "alphanum_fraction": 0.7138200782, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6773152835021462}}
{"text": "\\section{The algebra of linear transformations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use algebraic properties of linear transformations to\n    manipulate expressions.\n  \\end{enumerate}\n\\end{outcome}\n\nTwo linear transformations are considered to be equal if they act in\nthe same way on all vectors. This is the content of the following\ndefinition.\n\n\\begin{definition}{Equal transformations}{equal-transformations}\n  Let $S$ and $T$ be linear transformations from $V$ to $W$. We say\n  that $S$ and $T$ are \\textbf{equal}%\n  \\index{linear transformation!equality of}%\n  \\index{equality!of linear transformations}, and we write $S = T$, if\n  for all $\\vect{v}\\in V$,\n  \\begin{equation*}\n    S(\\vect{v}) = T(\\vect{v}).\n  \\end{equation*}\n\\end{definition}\n\nWe now consider several operations on linear transformations. These\ninclude addition and scalar multiplication of linear transformations,\nas well as the zero transformation.\n\n\\begin{definition}{Addition and scalar multiplication of linear transformations}{addition-linear-transformations}\n  Let $V$ and $W$ be vector spaces over a field $K$.\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item The \\textbf{zero transformation}%\n      \\index{zero transformation}%\n      \\index{linear transformation!zero transformation} $0:V\\to W$ is\n      defined by $0(\\vect{v})=\\vect{0}$ for all $\\vect{v}\\in V$.\n    \\item If $T,S:V\\to W$ are linear transformations, then their\n      \\textbf{sum}%\n      \\index{addition!of linear transformations}%\n      \\index{linear transformation!addition}\n      $T+S:V\\to W$ is the linear transformation defined by\n      \\begin{equation*}\n        (T+S)(\\vect{v}) = T(\\vect{v}) + S(\\vect{v})\n      \\end{equation*}\n      for all $\\vect{v}\\in V$.\n    \\item If $T:V\\to W$ is a linear transformation and $k\\in K$, the\n      linear transformation%\n      \\index{scalar multiplication!of linear transformation}%\n      \\index{linear transformation!scalar multiplication}\n      $kT : V\\to W$ is defined by\n      \\begin{equation*}\n        (kT)(\\vect{v}) = k(T(\\vect{v}))\n      \\end{equation*}\n      for all $\\vect{v}\\in V$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{definition}\n\n\\begin{proposition}{Addition and scalar multiplication of linear transformations}{addition-linear-transformations}\n  If $T,S:V\\to W$ are linear transformations, then so are $T+S$ and $kT$.\n\\end{proposition}\n\n\\begin{proof}\n  To show that $T+S$ is linear, we must verify that it preserves\n  addition and scalar multiplication. Let $\\vect{v},\\vect{u}\\in\n  V$. Then we have\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}ll}\n      (T+S)(\\vect{v}+\\vect{u})\n      &=& T(\\vect{v}+\\vect{u}) + S(\\vect{v}+\\vect{u})\n      & \\mbox{by definition of $T+S$,} \\\\\n      &=& (T(\\vect{v}) + T(\\vect{u})) + (S(\\vect{v}) + S(\\vect{u}))\n      & \\mbox{by linearity of $T$ and $S$,} \\\\\n      &=& (T(\\vect{v}) + S(\\vect{v})) + (T(\\vect{u}) + S(\\vect{u}))\n      & \\mbox{by the associative and commutative laws of vectors,} \\\\\n      &=& (T+S)(\\vect{v}) + (T+S)(\\vect{u})\n      & \\mbox{by definition of $T+S$.}\n    \\end{array}\n  \\end{equation*}\n  Therefore, $T+S$ preserves addition. Also, for $\\vect{v}\\in V$ and\n  $\\ell\\in K$, we have\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}ll}\n      (T+S)(\\ell\\vect{v})\n      &=& T(\\ell\\vect{v}) + S(\\ell\\vect{v})\n      & \\mbox{by definition of $T+S$} \\\\\n      &=& \\ell T(\\vect{v}) + \\ell S(\\vect{v})\n      & \\mbox{by linearity of $T$ and $S$} \\\\\n      &=& \\ell(T(\\vect{v}) + S(\\vect{v}))\n      & \\mbox{by the distributive law over vector addition} \\\\\n      &=& \\ell((T+S)(\\vect{v}))\n      & \\mbox{by definition of $T+S$.}\n    \\end{array}\n  \\end{equation*}\n  Therefore, $T+S$ preserves scalar multiplication, and hence $T+S$ is\n  a linear transformation. The proof that $kT$ is a linear\n  transformation is left as an exercise.\n\\end{proof}\n\nThere operations satisfy the following properties:\n\n\\begin{proposition}{Properties of addition and scalar multiplication of linear transformations}{properties-addition-linear-transformation}\n  Let $V,W$ be vector spaces over a field $K$, let $T,S,R:V\\to W$\n  be linear transformations, and let $k,\\ell\\in K$ be scalars. Then\n  the following hold:%\n  \\index{properties of addition!linear transformations}%\n  \\index{linear transformation!properties of addition}%\n  \\index{linear transformation!addition!properties}%\n  \\index{properties of scalar multiplication!linear transformation}%\n  \\index{linear transformation!properties of scalar multiplication}%\n  \\index{linear transformation!scalar multiplication!properties}\n  \\begin{itemize}\\setlength\\itemsep{0em}\n  \\item Commutative law of addition:\n    $T+S = S+T$.\n  \\item Associative law of addition:\n    $(T+S)+R = T+(S+R)$.\n  \\item The existence of an additive unit: there exists an element $\\vect{0}\\in\n    V$ such that for all $T$,\n    $T + 0 = T$.\n  \\item The law of additive inverses:\n    $T + (-T) = 0$.\n  \\item The distributive law over vector addition:\n    $k(T + S) = kT + kS$.\n  \\item The distributive law over scalar addition:\n    $(k + \\ell) T = k T + \\ell T$.\n  \\item The associative law for scalar multiplication:\n    $k(\\ell T) = (k \\ell)T$.\n  \\item The rule for multiplication by one:\n    $1T=T$.\n  \\end{itemize}\n\\end{proposition}\n\nBut these 8 properties are just the vector space laws (A1)--(A4) and\n(SM1)--(SM4)! Therefore, the set of linear transformations from $V$ to\n$W$, with the above operations of addition and scalar multiplication,\nforms a vector space.\n\n\\begin{definition}{Vector space of linear transformations}{vector-space-linear-transformations}\n  Let $V,W$ be vector spaces over a field $K$. We define $\\Lin_{V,W}$%\n  \\index{vector space!of linear transformations}%\n  \\index{LinVW@$\\Lin_{V,W}$} to be the vector space of all linear\n  transformations from $V$ to $W$, with the above operations of\n  addition and scalar multiplication.\n\\end{definition}\n\nAnother important operation is the composition of linear\ntransformations. We have already encountered this in\nDefinition~\\ref{def:composite-transformations} for the case of\n$\\R^n$. Here, we generalize it to linear transformations of arbitrary\nvector spaces.  We also consider the identity transformation on a\nvector space, which forms the unit for composition.\n\n\\begin{definition}{Composition of linear transformations}{composition-linear-transformation}\n  Let $V,U,W$ be vector spaces over a field $K$, and let $S:V\\to U$\n  and $T:U\\to W$ be linear transformations.\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item The\n      \\textbf{composition}%\n      \\index{linear transformation!composition}%\n      \\index{composition of linear transformations} $T\\circ S:V\\to W$ is\n      the linear transformation defined by\n      \\begin{equation*}\n        (T\\circ S) (\\vect{v}) = T(S(\\vect{v}))\n      \\end{equation*}\n      for all $\\vect{v}\\in V$.\n    \\item The \\textbf{identity transformation}%\n      \\index{identity transformation}%\n      \\index{linear transformation!identity transformation}\n      $1_V:V\\to V$ is defined by $1_V(\\vect{v})=\\vect{v}$ for all\n      $\\vect{v}\\in V$. We often omit the subscript and just write\n      $1:V\\to V$ when $V$ is clear from the context.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{definition}\n\nComposition of linear transformations satisfies the following properties:\n\n\\begin{proposition}{Properties of composition of linear transformations}{properties-composition}\n  Composition of linear transformations satisfies the following\n  properties, for all $R,S,T$ as appropriate for each law:%\n  \\index{properties of composition!linear transformations}%\n  \\index{linear transformation!properties of composition}%\n  \\index{linear transformation!composition!properties}%\n  \\begin{itemize}\\setlength\\itemsep{0em}\n  \\item Associative law of composition:\n    $(T\\circ S)\\circ R = T\\circ (S\\circ R)$.\n  \\item Unit laws of composition: $T\\circ 1_V = T$ and $1_W\\circ T = T$, where\n    $T:V\\to W$.\n  \\item Distributive laws: $(T+S)\\circ R = T\\circ R + S\\circ R$ and\n    $P\\circ (T+S) = P\\circ T + P\\circ S$.\n  \\item Zero laws: $0\\circ R = 0$ and $R\\circ 0 = 0$.\n  \\item Compatibility with scalar multiplication:\n    $(kT)\\circ S = k(T\\circ S) = T\\circ (kS)$, where $k\\in K$.\n  \\end{itemize}\n\\end{proposition}\n\nFinally, we consider the notion of the inverse of a linear\ntransformation.\n\n\\begin{definition}{Inverse of a linear transformation}{inverse-linear-transformation}\n  Let $V,U$ be vector spaces over a field $K$, and let $S:V\\to U$ and\n  $T:U\\to V$ be linear transformations.  We say that $S$ and $T$ are\n  \\textbf{inverses}%\n  \\index{inverse!of a linear transformation}%\n  \\index{linear transformation!inverse} if\n  \\begin{equation*}\n    T\\circ S = 1_V\n    \\quad\\mbox{and}\\quad\n    S\\circ T = 1_U.\n  \\end{equation*}\n  In this case, we also write $S=T^{-1}$ and $T=S^{-1}$.\n\\end{definition}\n\n\\begin{proposition}{Uniqueness of inverses}{uniqueness-inverses-linear-transformation}\n  Inverses are unique. In other words, if $S$ and $S'$ are two inverses\n  of $T$, then $S=S'$.\n\\end{proposition}\n\n\\begin{proof}\n  Suppose both $S$ and $S'$ are inverses of $T$. Consider\n  $S\\circ T\\circ S'$. Since $S$ and $T$ are inverses, this is equal to\n  $S'$, but since $T$ and $S'$ are inverses, it is also equal to\n  $S$. Therefore, $S=S'$.\n\\end{proof}\n\n\\begin{proposition}{Properties of inverses of linear transformations}{properties-inverse-linear-transformation}\n  \\begin{itemize}\n  \\item If $S:V\\to U$ and $T:U\\to W$ are both invertible, then so is\n    $T\\circ S$, and we have\n    \\begin{equation*}\n      (T\\circ S)^{-1} = S^{-1}\\circ T^{-1}.\n    \\end{equation*}\n  \\item $1^{-1} = 1$.\n  \\item If $S:V\\to U$ is invertible and $k$ is a non-zero scalar, then\n    \\begin{equation*}\n      (kS)^{-1} = k^{-1}S^{-1}.\n    \\end{equation*}\n  \\end{itemize}\n\\end{proposition}\n", "meta": {"hexsha": "5419e451977775f65d9f4bcde8e7e4acc263244c", "size": 9768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsGeneral-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/LinearTransformationsGeneral-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/LinearTransformationsGeneral-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": 40.531120332, "max_line_length": 138, "alphanum_fraction": 0.6748566749, "num_tokens": 2971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8774767938900121, "lm_q1q2_score": 0.6772747578686836}}
{"text": "Implements the SMT compliant \\emph{Fourier-Motzkin algorithm}.\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 e.g. in the case of a monomial $x^i$ \n(where i is a positive integer) only occuring in the shape of this\nmonomial. Such a monomial is subsequently eliminated as common linear\nvariables are eliminated. One can tune a threshold parameter in order to\ndetermine when, regarding the size of the considered constraints, \nthis module shall call the backends. In the latter case, the backends are called\nwith the constraint set that is obtained after eliminating a certain\nnumber of variables.  \n\n\\paragraph{Integer arithmetic} One can also use this approach for (linear) integer arithmetic\nas unsatisfiability over the real domain implies unsatisfiability over the integer\ndomain. In addition to that, one can heuristically try to construct integer solutions\nby considering the lowest upper and the highest lower bound of a variable that can be derived\nfrom the respective elimination step. Note that this approach is incomplete.  \n", "meta": {"hexsha": "9b2fbe9e5867e998f0fd437ea54efc368d73205a", "size": 1220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/smtrat-modules/FouMoModule/FouMoModule.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/FouMoModule/FouMoModule.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/FouMoModule/FouMoModule.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": 64.2105263158, "max_line_length": 93, "alphanum_fraction": 0.8163934426, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6772432908277967}}
{"text": "\\documentclass[]{report}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{bm}\n\\usepackage{graphicx}\n\\usepackage{listings}\n\n\\graphicspath{ {images/} }\n\n\\title{CSCI 567 HW \\# 5}\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\\[ D = \\sum_{n=1}^N \\sum_{k=1}^K r_{nk}  {\\| x_n - \\mu_k \\|}_2^2 \\]\n\ttaking partial derivative w.r.t. $\\mu_k$, we get \n\t\\[ \\frac{\\partial{D}}{\\partial{\\mu_k}} = \\sum_{n=1}^N r_{nk} [-2 (x_n - \\mu_k)] = 0 \\]\n\t\\[ = \\sum_{n=1}^N r_{nk} x_n - \\mu_k \\sum_{n=1}^N r_{nk} = 0\\]\n\t\\[ \\mu_k = \\frac{\\sum_{n=1}^N r_{nk} x_n}{\\sum_{n=1}^N r_{nk}}\\]\n\n\\paragraph{Sol. 1.2}\n\tGiven \n\t\\[ D = \\sum_{n=1}^N \\sum_{k=1}^K r_{nk}  {\\| x_n - \\mu_k \\|}_1 \\]\n\tWe want find an optimal $\\mu_k$, such that it minimizes $D$ and that optimal $\\mu$ is equal to the \n\tmedian of $x_n = [x_{n1}, x_{n2} \\hdots x_{nD}]$.\n\n\tNow, let us assume that, $\\mu_k$ is optimal and for a given vector $x_n, x_n \\in R^D$, so fro the definition of \n\t``closeness'' in the text we get that \n\t\\[ L = \\sum_{i=1}^D |x_{ni} - \\mu_k|\\],\n\tNow if there are $l$ numbers to the left of $\\mu_k$ and $r$ number to the right, then if we were to shift $\\mu_k$ by a distance $d$\n\tto the left, the $L$ increases by $(l - r)d \\quad if(l > r)$. Similarly if, we were to shift $\\mu_k$ to the right by a distance of $d$, then again the \n\tmeasurement of $L$ increases by $(r - l)d \\quad if (r > l)$. Therefore $L$ will achieve if minimum value when $l = r$, i.e. $\\mu_k$ is the median of the \n\tvector $x_n$.\n\n\n\tNow we derive the above conclusion to multi-dimensionalities. We can see only when  is the elementwise median of cluster k, $L_k = \\sum_{i=1}^{N_k} |x_i - \\mu_k |$ has the minimal value. Suppose there are K clusters, the overall loss is\n\t\\[ L = \\sum_{k=1}^K L_k = \\sum_{k=1}^K \\sum_{n=1}^N |x_n - \\mu_k| \\]  \n\twhich will also be minimal, which equals to \n\t\\[ D = \\sum_{k=1}^K L_k = \\sum_{k=1}^K \\sum_{n=1}^N r_{nk} |x_n - \\mu_k| \\]  \n\n\\paragraph{Sol 1.3}\n\tGiven\n\t\\begin{equation}\n\t\t\\tilde{D} = \\sum_{n=1}^N \\sum_{k=1}^K r_{nk} {\\| \\phi (x_n) - \\tilde{\\mu}_k \\|}_2^2 \n\t\\end{equation}\n\n\twhere, \n\t\\begin{equation}\n\t\t\\tilde{\\mu}_k = \\frac{1}{N_k} \\sum_{n=1}^N r_{nk} \\phi (x_n)\n\t\\end{equation}\n\n\tWe can write $\\frac{r_{nk}}{N_k} = \\gamma_{nk}$, then we can rewrite $\\tilde{\\mu}$ as \n\t\\[ \\tilde{\\mu}_k = \\sum_{n=1}^N \\gamma_{nk} \\phi (x_n) \\]\n\t\n\tThen, \n\t\\[ {\\| \\phi(x_n) - \\tilde{\\mu}\\|}^2 = {\\| \\phi(x_n) - \\sum_{n=1}^N \\gamma_{nk} \\phi (x_n) \\|}^2 \\]\n\t\\[ = [\\phi(x_n) - \\sum_{n=1}^N \\gamma_{nk} \\phi (x_n)] \\cdot [\\phi(x_n) - \\sum_{n=1}^N \\gamma_{nk} \\phi (x_n)] \\]\n\t\\[ = K(x, x) - 2 \\sum_{i=1}^N \\gamma_{ik} K(x, x_i) + \\sum_{i=1}^N \\sum_{j=1}^N \\gamma_{ik} \\gamma_{jk} K(x_i, x_j) \\]\n\n\tTherefore, we can write\n\t\\[ \\tilde{D} = \\sum_{n=1}^N \\sum_{k=1}^K r_{nk} \\big[ K(x_n, x_n) - 2 \\sum_{i=1}^N \\gamma_{ik} K(x_n, x_i) + \\sum_{i=1}^N \\sum_{j=1}^N \\gamma_{ik} \\gamma_{jk} K(x_i, x_j) \\big] \\]\n\n\tTo assign a point to a cluster $k$, we initialize (randomly or through other methods) $\\tilde{\\mu}_k$ and for each iteration, assign, $x_n$ to k where\n\t\\[ argmax_{k \\in K} K(x_n, x_n) - 2 \\sum_{i=1}^N \\gamma_{ik} K(x_n, x_i) + \\sum_{i=1}^N \\sum_{j=1}^N \\gamma_{ik} \\gamma_{jk} K(x_i, x_j) \\]\n\n\tThe pseudo-code \n\t\\newpage\n\n\\begin{lstlisting}\nKernel_Kmeans():\n  G = GramMatrix(X)\n  Assignment = init_random_assigmnment()\n  Means = random.sample(X, k)\n  for max_iterations:\n  \tfor k in K:\n  \t  for i, x in enumerate(X):\n\t        distance[i, k] =  G[x, x] \n\t        distance[i, k] -= (2 * sum(G[(Assignment == k), i]) \n\t        distance[i, k] += sum(G[Assignment == k, Assignment == k]) \n    Assignment = argmin(distance)\n    for k in K:\n      NewMeans[k] = mean(X[Assignment == k])\n    if convereged(Means, NewMeans):\n      return Assignment, NewMeans\n    else:\n      Means = NewMeans\n\\end{lstlisting}\n\n\n\\paragraph{Sol 2.1}\n\tWe can write the likelihood function as \n\t\\[ p(x | \\alpha) = \\frac{\\alpha}{\\sqrt{2 \\pi}} exp(-\\frac{1}{2} x^2) + \\frac{1 - \\alpha}{\\sqrt{\\pi}} exp(- x^2)\\]\n\tand for observed sample $x_1$, we can write\n\t\\[ p(x_1 | \\alpha) = (\\frac{1}{\\sqrt{2 \\pi}} exp(-\\frac{1}{2}x_1^2) - \\frac{1}{\\sqrt(\\pi)} exp(-x_1^2)) \\alpha + \\frac{1}{\\sqrt{\\pi}} exp(-x^2) \\]\n\tWe observe the likelihood function for an observed sample $x_1$ is a linear function of $\\alpha$ where the slope of the line is determined by the values of the gaussian probabilities. So, for maximum likelihood, if the gaussian probability $N(x_1 | 0, 1) > N(x_1|0, 0.5)$ then we choose $\\alpha = 1$ for maximum likelihood, else we choose $\\alpha = 0$.\n\n\\paragraph{Sol 3.1}\n\tLet us define the hidden variable as $z_i = 1$ when a person in the sample has taken insurance, and $z_i = 0$ otherwise. Now, if $x_i > 0$, then clearly $z_i = 1$, however, when $x_i = 0$, then $z_i = 1$ or $0$.\n\n\tTherefore our likelihood function can be given as \n\t\\[ \n\t\tL = \\prod_{i=1}^N \\pi^{1-u_i} \\big[ (1 - \\pi) \\frac{e^{-\\lambda} \\lambda^{x_i}}{x_i!} \\big]^{u_i}\n\t\\]\n\n\twhere $u_i = 1$ if $x_i > 0$ and $u_i = z_i$ if $x_i = 0$.\n\n\\paragraph{Sol 3.2} N/A\n\n\n\\paragraph{Sol 4.1}\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{blob-2}\n\t\tBlob, K = 2\n\t\t\\includegraphics[width=\\textwidth]{blob-3}\n\t\tBlob, K = 3\n\t\t\\includegraphics[width=\\textwidth]{blob-5}\n\t\tBlob, K = 5\n\t\t\\includegraphics[width=\\textwidth]{circle-2}\n\t\tCircle, K = 2\n\t\t\\includegraphics[width=\\textwidth]{circle-3}\n\t\tCircle, K = 3\n\t\t\\includegraphics[width=\\textwidth]{circle-5}\n\t\tCircle, K = 5\n\t\\end{center}\n\n\tFor $\\texttt{circle.csv}$ and $K = 2$, since, both the clusters are concentric circles and their centroid falls at the same point and hence for a point the difference between minimum distances is small or equal.\n\n\\paragraph{Sol 4.2}\n\tUsing the feature transformation\n\t\\[ \\phi(x, y) = [x, y, 2(x^2 + y^2)] \\]\n\t\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{Kernel-Kmeans-2}\n\t\tk = 2\n\t\\end{center}\n\n\\paragraph{Sol 4.3}\n\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{LogLikelihood}\n\t\tLog-Likehood Plot\n\t\t\\includegraphics[width=\\textwidth]{EM-Scatterplot}\n\t\tCluster Assignment Plot\n\t\\end{center}\n\\[ \n\tMeans = \\begin{bmatrix}\n\t\tK=1 &   0.75896032 & 0.67976983 \\\\\n\t\tK=2 &  -0.32591595 & 0.97133268 \\\\\n\t\tK=3 &  -0.63946222 & 1.47460006 \n\t\\end{bmatrix} \n\\]\n\n\\[\n\tCovariance[k = 1] = \\begin{bmatrix}\n\t\t0.02717056  & -0.00840045 \\\\\n\t \t-0.00840045 &  0.040442 \n\t\\end{bmatrix}\n\\]\n\\[\t\n\tCovariance[k = 2] = \\begin{bmatrix}\n\t\t0.03604869 & 0.01463998 \\\\\n \t\t0.01463998 & 0.01629099 \n\t\\end{bmatrix}\n\\]\n\\[\t\n\tCovariance[k = 3] = \\begin{bmatrix}\n\t\t0.03596703 & 0.01549264  \\\\\n \t\t0.01549264 & 0.01935347 \n\t\\end{bmatrix}\n\\]\n\n\\end{document}", "meta": {"hexsha": "3d5b39a2219097ba369fcd92950f003edd108fe5", "size": 6610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2-6/HW5/hw5.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/HW5/hw5.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/HW5/hw5.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": 37.3446327684, "max_line_length": 353, "alphanum_fraction": 0.6213313162, "num_tokens": 2676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.6772432891065456}}
{"text": "\\lab{Plotting With matplotlib and Mayavi}{Plotting}\n\\objective{Introduce some of the basic plotting functions available in matplotlib and Mayavi.}\n\\label{lab:Matplotlib_and_Mayavi}\n\n\\section*{matplotlib}\nmatplotlib is one of Python's many plotting libraries.\nIt has an active development community and was designed to resemble MATLAB.\nBecause of its high quality and its helpful user interface toolkits, matplotlib serves as our primary plotting library for 2D graphs in this text.\n\nThis section seeks to introduce many of the basic plotting functions we will access using matplotlib, but matplotlib has many more.\nFor further reference and information, visit \\url{http://matplotlib.org}.\n\n\n\\subsection*{Simple Plots}\nTo get started, we import pyplot from matplotlib.\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\n\\end{lstlisting}\n\nThe basic line plotting function in matplotlib is \\li{plot()}.\nIt takes a set of data points and plots the line that is formed between those points.\nThese plots are pieced together using a \\emph{state machine environment}, which means that we can run several different functions that will display or modify the plot we are creating.\n\nTo plot and display our function we typically use an outline similar to the following:\n\\begin{lstlisting}\n# Definition of x and y coordinates (typically NumPy arrays or lists).\nplt.plot(x,y)\nplt.show()\n\\end{lstlisting}\nNote that x and y must be the same length in order for \\li{plot(x,y)} to work.\n\nWhen we define our x and y coordinates, we often use NumPy's \\li{linspace(<start>, <stop>, num=50)} function since it returns evenly spaced values over a given interval.\nThese values are returned in an \\li{ndarray}.\nSo, after importing \\li{numpy} and \\li{pyplot}, we can generate a basic plot of the function $e^x$ with the following lines of code:\n\\begin{lstlisting}\n# Increase number of samples from default 50 to 501.\nx = np.linspace(-2, 3, 501)\ny = np.exp(x)\nplt.plot(x, y)\nplt.show()\n\\end{lstlisting}\n\nThis should display a plot similar to the one shown in Figure \\ref{fig:exp_plot}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{exp_plot.pdf}\n\\caption{A simple plot of $e^x$.}\n\\label{fig:exp_plot}\n\\end{figure}\n\n\n\\subsection*{Multiple Plots}\nWe can also use our interface to display multiple plots at once.\nThe following code will plot lines with random values at integers from 1 to 10.\nNote that NumPy's \\li{random.rand} function creates an array of a specified shape and fills it with random samples from a uniform distribution over the interval [0,1).\nThe given dimensions of the array should be positive and, if no argument is given, a single float is returned.\n\n\\begin{lstlisting}\nx = np.linspace(1, 10, 10)\ny = np.random.rand(10, 10)\nplt.plot(x, y[0], x, y[1], x, y[2], x, y[3], x, y[4], x, y[5], x, y[6], x, y[7], x, y[8], x, y[9])\nplt.show()\n\\end{lstlisting}\n\nWe just used the plot function to plot several different lines at once.\nAlternatively, we can plot each \\li{(x, y[i])} pair separately and overlay the plots to produce the same result.\nWe use a loop to efficiently overlay create each plot.\n\\begin{lstlisting}\nx = np.linspace(1, 10, 10)\ny = np.random.rand(10, 10)\nfor n in y:\n    plt.plot(x, n)\nplt.show()\n\\end{lstlisting}\nA plot that was generated by this code will be similar to the one shown\nin Figure \\ref{fig:statemachine}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{statemachine.pdf}\n\\caption{A plot of $10$ lines with randomly generated $y$ values.}\n\\label{fig:statemachine}\n\\end{figure}\n\nNote that a suitable domain and range for your plot is automatically chosen unless you specify otherwise.\n\n\\begin{problem} Plot the function $\\sin(x)$ from $0$ to $2\\pi$ with a red dashed line.\nThen plot the function $\\cos(x)$ on the same domain with a blue dotted line.\nImplement both with a single call to the \\li{plot()} function.\nInformation on how to do this can be found in Appendix \\ref{mpltables}.\n\\end{problem}\n\n\\begin{comment}\nThere are also many functions that we may use to set different values in\nthe plotting environment. A few examples are shown in Table\n\\ref{mpl:useful_functions}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|l|p{6cm}|p{4cm}|}\n\n    \\hline\n\n    Function & Description & Usage\\\\\n\n    \\hline\n\n    \\li{annotate} & adds a commentary at a given point on the plot &\n    annotate('text',(x,y))\\\\\n\n    \\li{arrow} & draws an arrow from a given point on the plot &\n    arrow(x,y,dx,dy)\\\\\n\n    \\li{axhline} & draws a horizontal line at y from xmin to xmax &\n    axhline(y=0, xmin=0, xmax=1)\\\\\n\n    \\li{axvline} & draws a vertical line at x from ymin to ymax &\n    axvline(x=0, ymin=0, ymax=1)\\\\\n\n    \\li{axhspan} & draws a rectangle from xmin to xmax and ymin to ymax,\n    if no xmin and xmax are given it goes across the plot &\n    axhspan(ymin, ymax, xmin=0, xmax=1)\\\\\n\n    \\li{axvspan} & draws a rectangle from ymin to ymax and xmin to xmax,\n    if no ymin and ymax are given it goes across the entire plot &\n    axvspan(xmin, xmax, ymin=0, ymin=1)\\\\\n\n    \\li{figlegend} & place a legend in the plot & figlegend(handles,\n    labels, loc)\\\\\n\n    \\li{grid} & add gridlines & grid()\\\\\n\n    \\li{text} & add text at a given position on the plot &\n    text(x,y,'text')\\\\\n\n    \\li{title} & add a title to the plot & title('text')\\\\\n\n    \\li{xlim} & set the x limits, returns current limits if no arguments\n    are given & xlim(xmin,xmax)\\\\\n\n    \\li{ylim} & set the y limits, returns current limits if no arguments\n    are given & ylim(ymin,ymax)\\\\\n\n    \\li{xticks} & set the location of the tick marks on the x axis,\n    returns current locations if no arguments are given & xticks(x)\\\\\n\n    \\li{yticks} & set the location of the tick marks on the y axis,\n    returns current locations if no arguments are given & yticks(y)\\\\\n\n    \\li{xlabel} & add a label to the x axis & xlabel('text')\\\\\n\n    \\li{ylabel} & add a label to the y axis & ylabel('text')\\\\\n\n    \\hline\n\n    \\end{tabular}\n    \\end{center}\n    \\caption{Some Functions to Set Plotting Options}\n    \\label{mpl:useful_functions}\n    \\end{table}\n\n\t\\end{comment}\n\t\n\\begin{problem}\nPlot the curve $1/(x-1)$ from $-2$ to $6$ with a magenta dashed line.\nForce the plot to only show $y$ values that are between $-6$ and $6$.\nMake your line width 5. Once again, more information on how to do this can be found in Appendix \\ref{mpltables}.\nBy default, \\li{plot()} will try to make the graph connected.\nCorrect this so that the graph \\emph{appears} to be discontinuous at $x=1$ (as it should be) by modifying the input values.\n\nYour plot should look like the figure below.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{soln2.pdf}\n\\label{fig:problem2}\n\\end{figure}\n\\end{problem}\n\n\\begin{problem} Plot the curve $\\sin(x)\\frac{1}{x+1}$ from $0$ to $10$.\n\nUse blue shading under the curve when it is positive and red when it is negative (you may want to consider using the \\li{fill_between} command.\nMake the line dotted.\nLabel the x-axis ``x-axis'', the y-axis ``y-axis'',and the plot ``My Plot''.\nEnable the grid lines.\n\nFinally, use the \\li{scatter} command to include a scatter plot of half of the value of the function at each of its maxima and minima in the range.\nDisplay these points as upward-pointing triangles.\nDon't forget to make sure the x limits of the plot are still 0 and 10.\n\n\\emph{Helpful Hint}: Since you are working with arrays of discrete values, you will want to find the index values where your $x$ and $y$ values are closest to the actual maxima and minima. As you work, consider the following:\n\\begin{itemize}\n\\item How would you manually find maxima and minima of a function?\n\\item How could you do something similar with your $x$ and $y$ arrays?\n\\end{itemize}\nYour plot should look like the figure below.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{soln3.pdf}\n\\label{fig:problem3}\n\\end{figure}\n\\end{problem}\n\n\\subsection*{pcolormesh}\nPcolormesh is a function in pyplot which produces a pseudocolor plot of a 2D array.\nThink of it as a 3D plot that assigns color rather than height to the result $C$ of a function in $x$ and $y$.\nSince our \\emph{domain} is now two-dimensional, instead of one-dimensional as before, we use NumPy's \\li{meshgrid} function.\nThis function takes two one-dimensional arrays that represent our input values for $x$ and $y$ respectively, and returns a grid of $(x, y)$ coordinates.\n$X$ represents the $x$-coordinates of this grid and $Y$ represents the $y$-coordinates.\nWe then evaluate our function at these points and return the result in a two-dimensional array $C$, which the pcolormesh function uses to assign colors to the points in our $xy$ domain.\n\nWe now use the pcolormesh function to represent the surface $z=\\sin(x)\\sin(y)$:\n\\begin{lstlisting}\nn = 401\nx = np.linspace(-6, 6, n)\ny = np.linspace(-6, 6, n)\n# Returns a coordinate matrix given coordinate vectors.\nX, Y = np.meshgrid(x, y)\nC = np.sin(X) * np.sin(Y)\nplt.pcolormesh(X, Y, C)\nplt.show()\n\\end{lstlisting}\nThis plot is shown in Figure \\ref{fig:pcmexample}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{sinxsiny.png}\n\\caption{Color plot of $\\sin\\left(x\\right)\\times\\sin\\left(y\\right)$.}\n\\label{fig:pcmexample}\n\\end{figure}\n\n\\begin{problem} Use plt.pcolormesh to plot the absolute value of the function $x^3 +2x^2 -x +3$ on the complex plane with 0 $\\leq$ \\li{x} $\\leq$ 2 and 0 $\\leq$ \\li{y} $\\leq$ 2.\n\\emph{Helpful Hint}: First create your domain arrays, then convert these to a single array of complex variables to evaluate the function.\n\nYour plot should look like Figure \\ref{fig:pcolormesh}.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{pcolor2.png}\n\\caption{Another example of a colorplot.}\n\\label{fig:pcolormesh}\n\\end{figure}\n\\end{problem}\n\n\\begin{comment}\n\nMatplotlib can also be used for 3D plotting. The following is an example\nof how to use matplotlib to plot the function $z=\\sin(x)\\sin(y)$ with\nboth x and y ranging from -6 to 6. The resulting plot is shown in Figure\n\\ref{mpl:3dplot}. If you change the number of sample points used you\nwill notice that graphs look much nicer with large numbers of sample\npoints, but it will also take much longer for your computer to render\nthe image.\n\n\\begin{lstlisting} from mpl_toolkits.mplot3d import Axes3D from\nmatplotlib import pyplot as plt import numpy as np fig = plt.figure() ax\n= fig.gca(projection='3d') x = np.linspace(-6, 6, 301) y =\nnp.linspace(-6, 6, 301) X, Y = np.meshgrid(x, y) Z = np.sin(X) *\nnp.sin(Y) ax.plot_surface(X, Y, Z) plt.show() \\end{lstlisting}\n\n\\begin{figure} \\includegraphics[width=\\textwidth]{3dplot.pdf} \\caption{A\n3D plot of $\\sin\\left(x\\right)\\times\\sin\\left(y\\right)$.}\n\\label{mpl:3dplot} \\end{figure}\n\n\\begin{problem} Plot the function \\begin{equation*}\n\\frac{\\cos\\left(\\sqrt{x^2 + y^2}\\right)}{\\frac{x^2 + y^2}{10} + 1}\n\\end{equation*} on $[-10, 10] \\times [-10, 10]$. \\end{problem}\n\n\nMatplotlib also allows us to make interactive graphs as follows:\n\n% This example is largely based on one of the examples in the matplotlib\n% docs. I have simplified it and changed the way the libraries are\n% imported, but we could do a citation anyway.\n%\n\\begin{lstlisting} import numpy as np from matplotlib import pyplot as\nplt from matplotlib import widgets as wg ax = plt.subplot(111)\nplt.subplots_adjust(bottom=.25) t = np.arange(0., 1., .001) a0 = 5. f0 =\n3. s = a0 * np.sin(2 * np.pi * f0 * t) l = plt.plot(t, s)[0]\nplt.axis([0, 1, -10, 10]) axfreq = plt.axes([.25, .05, .65, .03]) axamp\n= plt.axes([.25, .1, .65, .03]) sfreq = wg.Slider(axfreq, 'Freq', .1,\n30., valinit=f0) samp = wg.Slider(axamp, 'Amp', .1, 10., valinit=a0) def\nupdate(val): amp = samp.val freq = sfreq.val l.set_ydata(amp * np.sin(2\n* np.pi * freq * t)) plt.draw() sfreq.on_changed(update)\nsamp.on_changed(update) plt.show() \\end{lstlisting} The resulting plot\nis shown in Figure \\ref{mpl:interact}.\n\n\\begin{figure} \\includegraphics[width=\\textwidth]{interact.pdf}\n\\caption{A snapshot of an interactive plot made using Matplotlib.}\n\\label{mpl:interact} \\end{figure}\n\n\\begin{problem} Modify the code above to add a third slider to\nmanipulate the phase of the wave shown. Have it range from 0 to $2\\pi$\nand set the default value to zero. \\end{problem}\n\n\\end{comment}\n\n\\section*{subplots}\n\nWe can plot multiple different images within the same figure using the \\li{plt.subplot} command.\nIt takes three arguments: the total number of rows for the figure, the total number of columns for the figure, and the index of the current subplot.\nThis index starts at 1 and increments across rows first.\nPreface the code for each subplot with the following command:\n\\begin{lstlisting}\nplt.subplot(numrows, numcols, fignum)\n\\end{lstlisting}\nIf all the argument values are less than 10, commas and spaces can be omitted.\n\nThe following example shows plots of $sin x$ and $cos x$ on two different axes within the same figure.\nFigure \\ref{fig:subplots} is the output from this code.\n\\begin{lstlisting}\nx = np.linspace(-np.pi, np.pi, 400)\ny1 = np.sin(x)\ny2 = np.cos(x)\n# Commas and spaces are omitted between arguments.\nplt.subplot(211)\nplt.plot(x, y1)\nplt.subplot(212)\nplt.plot(x, y2)\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{subplots.pdf}\n\\caption{An example of the use of subplots in matplotlib.}\n\\label{fig:subplots}\n\\end{figure}\n\n\\subsection*{Titles and Labels}\n\nWe can add titles to each subplot using the \\li{plt.title} function.\nThe \\li{plt.suptitle} function allows us to give the entire figure a title as well.\n\n\\begin{problem}\nMake a plot with 4 subplots.\nIn the subplots place graphs of $e^x$, $sin(x)$, $cos(x)$, and $x^2$.\nPlot each graph over the interval $(-\\pi,\\pi)$.\nTitle each graph accordingly and title the entire figure ``My Different Plots.\"\n\\end{problem}\n\n\\begin{comment}\n%Table \\ref{mpl:basics}\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|l|p{7cm}|p{3cm}|}\n\n    \\hline\n\n    Function & Description & Usage\\\\\n\n    \\hline\n\n    \\li{bar} & makes a bar graph & bar(left,height)\\\\\n\n    \\li{barh} & makes a horizontal bar graph & barh(bottom,width)\\\\\n\n    \\li{fill} & plots lines with shading under the curve & fill(x,y)\\\\\n\n    \\li{fill\\_between} & plots lines with shading between two given y\n    values & fill\\_ between(x,y1, y2=0)\\\\\n\n    \\li{hist} & plots a histogram from data & hist(data)\\\\\n\n    \\li{pie} & make a pie chart & pie(x)\\\\\n\n    \\li{plot} & plots lines and data on standard axes & plot(x,y)\\\\\n\n    \\li{polar} & plots lines and data on polar axes & polar(theta,r)\\\\\n\n    \\li{loglog} & plots lines and data on logarithmic x and y axes &\n    loglog(x,y)\\\\\n\n    \\li{scatter} & plots data, has more options for scatter plots than\n    the plot function & scatter(x,y)\\\\\n\n    \\li{semilogx} & plots lines and data with a log scaled x axis &\n    semilogx(x,y)\\\\\n\n    \\li{semilogy} & plots lines and data with a log scaled y axis &\n    semilogy(x,y)\\\\\n\n    \\li{specgram} & make a spectogram from data & specgram(x)\\\\\n\n    \\li{spy} & plot the sparsity pattern of a 2D array & spy(Z)\\\\\n\n    \\li{triplot} & plot triangulation between given points &\n    triplot(x,y)\\\\\n\n    \\hline\n\n    \\end{tabular}\n    \\end{center}\n    \\caption{Some basic functions in Matplotlib.}\n    \\label{mpl:basics}\n    \\end{table}\n\n\n    \\end{comment}\n\n\\section*{Mayavi}\n\nmatplotlib is designed primarily for 2D plotting.\nAlthough matplotlib can also create basic 3D plots, it is better to create 3D plots using a library that was specifically designed to do so: Mayavi.\nNot only is Mayavi designed primarily for 3D plotting, it further has the benefits of easy integration with Python scientific libraries and a user interface that allows for interaction with all data and objects.\n\nWe encourage you to visit the formal documentation at \\url{http://docs.enthought.com/mayavi/mayavi/} for more information.\n\nWithin Mayavi, we will be using the \\li{mlab} API which is imported like so:\n\\begin{lstlisting}\nfrom mayavi import mlab\n\\end{lstlisting}\n\n\\li{mlab} has many plotting functions, which are detailed at \\url{http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html}.\n\\begin{comment}\n\\begin{table}\n\\begin{center}\n\\begin{tabular}\n{|c|l|}\n\\hline\nFunction & Description \\\\\n\\hline\n\\li{barchart} & Produces 3D histogram-like plots\\\\\n\\li{contour3d} & Plots level surfaces of functions of three variables\\\\\n\\li{flow} & Creates a trajectory of particles following the flow of a vector field\\\\\n\\li{imshow} & Use a colormap to view a 2D array as an image\\\\\n\\li{mesh} & Plot a surface using \\li{(x,y,z)} coordinates supplied as three 2D arrays\\\\\n\\li{plot3d} & Draws lines between points\\\\\n\\li{points3d} & Plots glyphs (like points) at the coordinates supplied\\\\\n\\li{quiver3d} & Generate 3D vector fields\\\\\n\\li{surf} & Plot a surface with a 2D array as elevation data\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Some plotting functions in \\li{mlab}.}\n\\label{table:mlab_functions}\n\\end{table}\n\\end{comment}\nAll these functions can be ``tested\" (which provides an example figure for the function) with the command:\n\\begin{lstlisting}\nmlab.test_<plotting function>()\nmlab.show()\n\\end{lstlisting}\nNote that pressing tab after typing \\li{mlab.test_} will provide a list of available commands and that, like matplotlib, we use the \\li{show()} command to actually view our plot.\n\nFor example, to test the \\li{fancy_mesh} function, we run the following:\n\\begin{lstlisting}\nmlab.test_fancy_mesh()\nmlab.show()\n\\end{lstlisting}\n\n\\begin{comment}\nThe result should resemble Figure \\ref{fig:fancymesh}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{fancymesh.png}\n\\caption{An example of the fancy mesh plotting function}\n\\label{fig:fancymesh}\n\\end{figure}\n\\end{comment}\n\nIn this lab, we will focus our attention on introducing the \\li{mesh}, \\li{plot3d}, and \\li{points3d} functions.\n\nLike matplotlib, \\li{mlab} takes a set of data points and plots it.\nHowever, instead of passing just \\li{x} and \\li{y} coordinates as we did in matplotlib, we also send \\li{z} coordinates to produce a 3D plot.\n\n\\begin{comment}\n\\subsection*{surf}\nThe \\li{surf} function is great for simple structures like orthogonal grids\nbecause it will create efficient data structures.\nIt is common to use 2D arrays returned by \\li{np.meshgrid}.\n\nFor more complex structures, the \\li{mesh} function is more appropriate.\n\\end{comment}\n\n\\subsection*{mesh}\n\\li{mesh} plots a surface using grid-spaced data.\nIt expects three 2D NumPy arrays (i.e., a grid of \\li{(x,y,z)} coordinates).\nAs with pcolormesh in matplotlib, it is important that all of the given arrays have the same shape.\nThe following illustrates a hyperbolic paraboloid, using the colormap \\li{RdYlGn}.\n\\begin{lstlisting}\nimport numpy as np\nfrom mayavi import mlab\n\nx = np.linspace(-4,4,300)\ny = np.linspace(-4,4,300)\nX, Y = np.meshgrid(x,y)\n\nZ = X**2/4-Y**2/4\n\nmlab.mesh(X, Y, Z, colormap='RdYlGn')\nmlab.show()\n\\end{lstlisting}\n\nThis will produce Figure \\ref{fig:mesh_example}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{mesh_example.png}\n\\caption{A hyperbolic paraboloid}\n\\label{fig:mesh_example}\n\\end{figure}\n\n\\subsection*{plot3d}\n\\li{plot3d} is used to draw lines between points.\nIt expects three one-dimensional NumPy arrays to provide the position of the line.\n\n\nThe following illustrates a simple floral design.\n\\begin{lstlisting}\nnum = np.pi/1000\npts = np.arange(0, 2*np.pi + num, num)\nx = np.cos(pts) * (1 + np.cos(pts*6))\ny = np.sin(pts) * (1 + np.cos(pts*6))\nz = np.sin(pts*6/11)\nmlab.plot3d(x, y, z)\nmlab.show()\n\\end{lstlisting}\nThis will produce Figure \\ref{fig:plot3d}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{plot3d.png}\n\\caption{A simple floral.}\n\\label{fig:plot3d}\n\\end{figure}\n\n\n\\subsection*{points3d}\n\\li{points3d} is similar to \\li{plot3d}, except that it plots glyphs (the three-dimensional analogue of points) at the positions of the supplied data, and does not connect them like \\li{plot3d} does.\nIt takes the same arguments, three 1D NumPy arrays that form a line given by a list of \\li{(x,y,z)} coordinates.\nFor this example, we will also use a keyword argument, \\li{s}, which provides an associated scalar value for each point given.\nThis modifies the size and color of the glyphs.\nWe also use a scale factor to adjust the size of the points so that all of them are visible.\n\nThe following illustrates a simple heart - given the right perspective.\n\\begin{lstlisting}\npts = np.linspace(0, 4 * np.pi, 30)\nx = np.sin(2 * pts)\ny = np.cos(pts)\nz = np.cos(2 * pts)\ns = 2+np.sin(pts)\nmlab.points3d(x, y, z, s, scale_factor=.15)\nmlab.show()\n\\end{lstlisting}\nThis will produce Figure \\ref{fig:points3d}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{points3d.png}\n\\caption{A simple heart.}\n\\label{fig:points3d}\n\\end{figure}\n\n\\subsection*{Changing Looks}\nThe color of your object can be explicitly defined using the \\li{color} keyword argument.\nIt is specified as a triplet (red, green, blue) of floating points ranging from 0 to 1.\nFor example, (1.0, 1.0, 1.0) is white.\n\nIf, however, you would prefer to vary the colors across your visualization, we recommend using a colormap.\nFor example, in Figure \\ref{fig:mesh_example} we used the colormap \\li{RdYlGn} to make our hyperbolic paraboloid a blend from red to cream to green.\nVisit \\url{http://docs.enthought.com/mayavi/mayavi/mlab_changing_object_looks.html} for a list of all previously established colormaps.\n\\begin{comment}\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|l|c|r|}\n\\hline\n\\multicolumn{2}{c}\n{Colormaps} \\\\\n\\hline\n\\li{Accent} & \\li{autumn} & \\li{black-white} \\\\\n\\li{blue-red} & \\li{Blues} & \\li{bone} \\\\\n\\li{BrBG} & \\li{BuGn} & \\li{BuPu} \\\\\n\\li{cool} & \\li{copper} & \\li{Dark2} \\\\\n\\li{flag} & \\li{gist_earth} & \\li{gist_gray} \\\\\n\\li{gist_heat} & \\li{gist_ncar} & \\li{gist_rainbow} \\\\\n\\li{gist_stern} & \\li{gist_yarg} & \\li{GnBu} \\\\\n\\li{gray} & \\li{Greens} & \\li{Greys} \\\\\n\\li{hot} & \\li{hsv} & \\li{jet} \\\\\n\\li{Oranges} & \\li{OrRd} & \\li{Paired} \\\\\n\\li{Pastel1} & \\li{Pastel2} & \\li{pink} \\\\\n\\li{PiYG} & \\li{PRGn} & \\li{prism} \\\\\n\\li{PuBu} & \\li{PuBuGn} & \\li{PuOr} \\\\\n\\li{PuRd} & \\li{PurpLes} & \\li{RdBu} \\\\\n\\li{RdGy} & \\li{RdPu} & \\li{RdYlBu} \\\\\n\\li{RdYlGn} & \\li{Reds} & \\li{Setl} \\\\\n\\li{Set2} & \\li{Set3} & \\li{Spectral} \\\\\n\\li{spring} & \\li{summer} & \\li{winter} \\\\\n\\li{YlGnBu} & \\li{YlGn} & \\li{YlOrRd} \\\\\n\\li{YlOrBr} \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Colormaps}\n\\label{table:colormaps}\n\\end{table}\n\\end{comment}\n\n\\subsection*{Useful Features}\nAnother useful feature in \\li{mayavi} is the record feature.\nThis can be found by clicking the pipeline view in the top left corner of a plotting window.\nIn the pipeline view there is a round, red button.\nClicking it opens a recorder that keeps track of all the changes made interactively to the visualization, using valid lines of Python code.\n\n\\begin{problem}\nProvided Grand Canyon topological radar data from NASA, do the following.\n\n\\begin{itemize}\n\\item Reshape the data to be 3601x3601.\n\\item Cast the data type as \\li{float32}.\n\\item Slice the data, taking the first 1000 rows and columns 900-1900.\n\\item There is some missing data, so set the minimum of your data equal to the minimum of the the positive data points.\n\\item Preset the figure using the following commands: \\li{mlab.figure(size=(400,320)}, \\li{bgcolor = (.16, .28, .46))}\n\\item Now plot with \\li{mlab.surf}, using the colormap \\li{gist_earth}, with a \\li{warp_scale=.2}, \\li{vmin=1200}, and \\li{vmax=1610}.\n\\item Take a smaller view of the canyon using \\li{mlab.view(-5.9, 83, 570, [5.3, 20, 238])}.\n\\end{itemize}\n\nThis should produce Figure \\ref{fig:GrandCanyon}\n\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{GrandCanyon.png}\n\\caption{A view of the Grand Canyon}\n\\label{fig:GrandCanyon}\n\\end{figure}\n\n", "meta": {"hexsha": "6047e04d017b9bb77486681ffe787f4e2824ac3b", "size": 23580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/matplotlib/matplotlib.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": "Python/matplotlib/matplotlib.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": "Python/matplotlib/matplotlib.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": 38.2171799028, "max_line_length": 225, "alphanum_fraction": 0.7243426633, "num_tokens": 6994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.9005297821135385, "lm_q1q2_score": 0.6772097191945515}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{microtype}\n\n\\title{\\textbf{Markov chain text generation with inferred parts of speech}}\n\\author{Travis Mick}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n%%\nMarkov chains have commonly been used in text generators for applications\nsuch as chat bots, typically implemented by utilizing the likelihood of $k$-word\nsequences to inform the iterative production of words.\n%\nIn this document, we outline a technique to improve the quality of such systems'\noutputs by leveraging inferred knowledge about the parts of speech for each\nword in a sequence.\n%\n\\end{abstract}\n\n\\section{Introduction}\n\n%%\nTraditional Markov chaining text generation leverages a database indexing the\nfrequency $F_W(w)$ of each observed $k$-word sequence $w = (w_0, w_1, \\dots, w_{k-1})$.\n%\nThe database can be queried for a likely sequence given some prefix.\n%\nGiven a prefix $w' = (w_0, w_1, \\dots, w_{j-1})$ of length $j < k$, a candidate\nsequence $c$ with prefix $w'$ can be assigned a score as\n%\n\\begin{equation}\n\\label{eqn:wordscore}\nS_W(c) = \\frac{F_W(c)}{\\sum_{c' \\in C_W(w')} F_W(c')}\n\\end{equation}\nwhere $C_W(w')$ is the set of all possible sequences with the prefix $w'$.\n%\nOstensibly, the highest scored sequence is returned by the text generation algorithm,\nand an output string can be obtained by iterating this process while maintaining a\nrolling window of $k$ words.\n%\n\n%%\nUnfortunately, the choice of $k$ introduces a trade-off between overfitting and underfitting.\n%\nToo low of $k$ would result in unnatural sequences of words being produced, and a $k$ too large\nwould yield few novel results.\n%\nTherefore, we suggest augmenting the $k$-word Markov chain with additional information about\nthe parts of speech of the constituent words to increase output quality given small $k$.\n%\n\n\\section{Generation model}\n\n%%\nIn addition to a word-sequence frequency database, we will utilize a database of frequencies for\npart of speech sequences, as well as a database of frequencies of observations of a word being\nused as a particular part of speech.\n%\n\n%%\nFirst, let $F_P(p)$ give the frequency of observations of $k$-length part of speech sequences\n$p = (p_0, p_1, \\dots, {p_{k-1}})$.\n%\nThen, let $P(w_i, p_i)$ give the frequency of observations of word $w_i$ used as\npart of speech $p_i$.\n%\nWe can now define the likelihood of a word sequence $w$ corresponding to a part of speech\nsequence $p$ as\n%\n\\begin{equation}\n\\label{eqn:probcorr}\nP_A(w, p) =  \\frac{F_P(p)}{\\sum_{p' \\in X^k} F_P(p')} \\cdot \\prod_{0 \\leq i < k} \\frac{P(w_i, p_i)}{\\sum_{p'_i \\in X} P(w_i, p'_i) }\n\\end{equation}\n%\nWhere $X$ is the set of all parts of speech and $X^k$ is the set of all possible part of speech\nsequences of length $k$.\n%\nNote that we have utilized information about the correspondence between parts of speech\nand words, as well as the likelihood of the part of speech sequence itself.\n%\nWe can leverage this to produce an augmented score for a candidate word sequence $c$\nwith prefix $w'$.\n%\n\\begin{equation}\n\\label{eqn:augscore}\nS_A(c) = S_W(c) \\cdot \\max_{p \\in X^k} \\left( P_A(c, p) \\right)\n\\end{equation}\n%\nNote that we score the word sequence based on the best possible part of speech assignment\nas informed by Eqn.~\\ref{eqn:probcorr}.\n%\n\n\\section{Learning model}\n\n%%\nIn many applications, Markov chain text generators attempt to learn from observations in\nreal time.\n%\nWhile the learning process to inform $F_W$ is straightforward, we must define a mechanism\nto label observed word sequences with parts of speech in order to update $F_P$.\n\n%%\nWhen attempting to assign a part of speech sequence to a word sequence, we must come up with\na scoring mechanism to implement inference, as was done with word sequences in\nEqn.~\\ref{eqn:wordscore}.\n%\nGiven a part of speech sequence prefix $p' = (p_0, p_1, \\dots, p_{j-1})$ of length $j < k$\nand a corresponding word sequence $w$, a candidate part of speech sequence $c$ with prefix $p'$\ncan be assigned a score as \n%\n\\begin{equation}\n\\label{eqn:posscore}\nS_P(c) = P_A(w, c) \\cdot \\frac{F_P(c)}{\\sum_{c' \\in C_P(p')} F_P(c')}\n\\end{equation}\n%\nwhere $C_P(p')$ is the set of all possible sequences with the prefix $p'$.\n%\nWe have again leveraged Eqn.~\\ref{eqn:probcorr} to provide weight to both observed\npart of speech sequences and the correspondence between parts of speech and words.\n%\nNote that because our learning model requires prior observations in order to infer\nparts of speech for new observations, the system must be trained prior to being\nexposed to input.\n%\n\n\\end{document}\n", "meta": {"hexsha": "0b76508d1c21ae5cc36812f40d271d76771cae81", "size": 4550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/whitepaper.tex", "max_stars_repo_name": "le1ca/gimbo", "max_stars_repo_head_hexsha": "324b53b2062c7e3bdb06f75d4ba3610cd6dcd42c", "max_stars_repo_licenses": ["MIT"], "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/whitepaper.tex", "max_issues_repo_name": "le1ca/gimbo", "max_issues_repo_head_hexsha": "324b53b2062c7e3bdb06f75d4ba3610cd6dcd42c", "max_issues_repo_licenses": ["MIT"], "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/whitepaper.tex", "max_forks_repo_name": "le1ca/gimbo", "max_forks_repo_head_hexsha": "324b53b2062c7e3bdb06f75d4ba3610cd6dcd42c", "max_forks_repo_licenses": ["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.7328244275, "max_line_length": 132, "alphanum_fraction": 0.7441758242, "num_tokens": 1245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6772028930309661}}
{"text": "\\chapter{Calculus in 1-Complexity}\n\n\n\\section{Introduction and Motivation}\nThis chapter will present a specific set of $rComplexity$ classes, highlighting \\textbf{Big \\textit{r-}Theta}, \\textbf{Big \\textit{r-}O} and \\textbf{Big \\textit{r-}Omega} with unitary parameter (i.e. $r = 1$) by providing useful properties for a more straightforward calculation. The last part of the chapter introduce a new concept for \\textit{monotonic, continuous function}: \\textbf{normal form representation} and defines a new workflow in $rComplexity$: \\textbf{normalized rComplexity calculus}.\n\nCalculus in $rComplexity$ is dependent on the parameter $r \\in \\mathbb{R}_{+}$, and as a result a large number of operations may require rudimentary \\textit{conversions} using relations described in \\textit{Common properties} and \\textit{Notable properties} chapters. Working with unitary $rComplexity$ classes comes effortless and brings an agile manner of operating ample\ncalculus using this Complexity Model.\n\n\n\\section{Main notations in 1-Complexity Calculus}\nThe following notations and names will be used for describing the asymptotic behavior of a algorithm's complexity characterized by a function, $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$ in $1-Complexity$. \\\\\nWe define the set of all complexity calculus $\\mathcal{F}= \\lbrace f:\\mathbb{N}\\longrightarrow\\mathbb{R} \\rbrace$\n\\\\Assume that $n, n_{0}\\in\\mathbb{N}$. Also, we will consider an arbitrary complexity function $g \\in \\mathcal{F}$.\nThe following notations are particularization ($r = 1$) of notations provided in $rComplexity$:\n\\begin{definition}\n    \\textbf{Big \\textit{1-}Theta}: This set defines the group of mathematical functions similar in magnitude with  $g(n)$ in the study of asymptotic behavior. A set-based description of this group can be expressed as:\n    \\[\\begin{split}\n          \\Theta_{1}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < 1 < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} \\rbrace\n    \\end{split} \\]\n\\end{definition}\n\\begin{definition}\n    \\textbf{Big \\textit{1-}O}: This set defines the group of mathematical functions that are known to have a similar or lower\n    asymptotic performance in comparison with  $g(n)$. The set of such functions is defined as it follows:\n    \\[\\mathcal{O}_{1}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  1 < c, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\leq c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{definition}\n\n    \\textbf{Big \\textit{1-}Omega}: This set defines the group of mathematical functions that are known to have a similar or higher asymptotic performance in comparison with  $g(n)$. The set of all function is defined as:\n    \\[\\Omega_{1}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+}\\ s.t. \\ c < 1, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\geq c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{definition}\n    \\textbf{Small \\textit{1-}O}:\n    This set defines the group of mathematical functions that are known to have a humble\n    asymptotic performance in comparison with  $g(n)$. The set of such functions is defined as it follows:\n    \\[o_{1}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) < c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n    Note that $o_{r}(g(n) = o_{1}(g(n) \\forall r\\in  \\mathbb{R}_{+}$, as Small \\textit{1-}O notation is $r$-independent.\n\\end{definition}\n\\begin{definition}\n    \\textbf{Small \\textit{1-}Omega}:\n    This set defines the group of mathematical functions that are known to have a commanding asymptotic performance in comparison with  $g(n)$.\n    The set of such functions is defined as it follows:\n    \\[\\omega_{1}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) > c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n    Note that $\\omega_{r}(g(n) = \\omega_{1}(g(n) \\forall r\\in  \\mathbb{R}_{+}$, as Small \\textit{1-}Omega notation is $r$-independent.\n\\end{definition}\n\n\n\\section{Asymptotic Analysis}\nCalculus in $1-Complexity$ can be performed as well using either limits of sequences or limits of functions. Consider any two complexity functions $f,g:\\mathbb{N}_{+}\\longrightarrow\\mathbb{R}_{+}$.\n\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Big \\textit{1-}Theta} class defined by a function $g$:\n    \\[ f \\in \\Theta_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 1 \\]\n\\end{theorem}\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Big \\textit{1-}O} class defined by a function $g$:\n    \\[ f \\in \\mathcal{O}_{1}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = l,\\ l \\in \\left[ 0, 1 \\right] \\]\n\\end{theorem}\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Big \\textit{1-}Omega} class defined by a function $g$:\n    \\[ f \\in \\Omega_{1}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = l,\\ l \\in \\left[ 1, \\infty \\right) \\]\n\\end{theorem}\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Small \\textit{1-}O} class defined by a function $g$:\n    \\[ f \\in o_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\]\n\\end{theorem}\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Small \\textit{1-}Omega} class defined by a function $g$:\n    \\[ f \\in \\omega_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\]\n\\end{theorem}\n\n\n\\section{Common properties}\nThis chapter will present new implications in terms of reflexivity, transitivity, symmetry and projections properties of calculus in $1-Complexity$.\n\\begin{theorem}\n    Reflexivity in $1-Complexity$ - Big 1-Omega notation:\n    \\[ f \\in \\Theta_{1} \\left( f(n) \\right)\\ \\]\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Reflexivity property described in Common properties sections for classes in $rComplexity$ calculus.\n    \\[ f \\in \\Theta_{r} \\left( \\frac{1}{r} \\cdot f(n) \\right)\\ \\forall r \\neq 0 \\]\n    Therefore for $r = 1$:\n    \\[ f \\in \\Theta_{1} \\left( f(n) \\right)\\ \\]\n\\end{proof}\n\n\\begin{theorem}\n    Reflexivity in $1-Complexity$ - Big 1-O notation:\n    \\[ f \\in \\mathcal{O}_{1} \\left( x \\cdot f(n) \\right)\\ \\forall x \\geq 1 \\]\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Reflexivity property for Big \\textit{r-}O class in $rComplexity$ calculus.\n\\end{proof}\n\n\\begin{theorem}\n    Reflexivity in $1-Complexity$ - Big 1-Omega notation:\n    \\[ f \\in \\Omega_{1} \\left( x \\cdot f(n) \\right)\\ \\forall x \\leq 1 \\]\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Reflexivity property for Big \\textit{r-}Omega class in $rComplexity$ calculus.\n\\end{proof}\n\n\nThe reflexivity does not hold \\textbf{either} for Small \\textit{1-}o and Small \\textit{1-}Omega, as these two sets are equal with the classical sets defined in \\textit{Bachmann–Landau notations}.\n\\begin{remark}\n    Reflexivity in $1-Complexity$ - Small 1-o notation:\n    $ f \\notin o_{1}(f(n)) $\n\\end{remark}\n\\begin{remark}\n    Reflexivity in $1-Complexity$ - Small 1-Omega notation:\n    $ f \\notin \\omega_{1}(f(n)) $\n\\end{remark}\n\n\\begin{theorem}\n    Transitivity in $1-Complexity$ - Big 1-Theta notation:  \\\\  $ f \\in \\Theta_{1}(g(n)), g \\in \\Theta_{1}(h(n)) \\Rightarrow  f \\in \\Theta_{1}(h(n))$\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Transitivity property for Big \\textit{r-}Theta class in $rComplexity$ calculus.\n\\end{proof}\n\n\\begin{theorem}\n    Transitivity in $1-Complexity$ - Big 1-O notation:\n    $ f \\in \\mathcal{O}_{1}(g(n)), g \\in \\mathcal{O}_{1}(h(n)) \\Rightarrow  f \\in \\mathcal{O}_{1}(h(n))$\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Transitivity property for Big \\textit{r-}O class in $rComplexity$ calculus.\n\\end{proof}\n\\begin{theorem}\n    Transitivity in $1-Complexity$ - Big 1-Omega notation:\n    $ f \\in \\Omega_{1}(g(n)), g \\in \\Omega_{1}(h(n)) \\Rightarrow  f \\in \\Omega_{1}(h(n))$\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Transitivity property for Big \\textit{r-}Omega class in $rComplexity$ calculus.\n\\end{proof}\n\\begin{lemma}\n    Transitivity in $1-Complexity$ - small notations:\n    \\[ f \\in o_{1}(g(n)), g \\in o_{1}(h(n)) \\Rightarrow  f \\in o_{1}(h(n)) \\]\n    \\[ f \\in \\omega_{1}(g(n)), g \\in \\omega_{1}(h(n)) \\Rightarrow  f \\in \\omega_{1}(h(n)) \\]\n\\end{lemma}\n\\begin{proof}\n    Small \\textit{1-}o and Small \\textit{1-}Omega are equal with the classical sets defined in \\textit{Bachmann–Landau notations} and thus they conserve transitivity properties\n\\end{proof}\n\n\\begin{theorem}\n    \\textbf{Symmetry in $1-Complexity$:}  \\\\  $ f \\in \\Theta_{1}(g(n)) \\Rightarrow g \\in \\Theta_{1}(f(n)) $\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Symmetry property for Big \\textit{r-}Theta class in $rComplexity$ calculus.\n\\end{proof}\n\n\\begin{theorem}\n    \\textbf{Transpose symmetry in $1-Complexity$:}  \\\\  $ f \\in \\mathcal{O}_{1}(g(n)) \\Leftrightarrow g \\in \\Omega_{1}(f(n)) $\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Transpose symmetry property described in $rComplexity$ calculus.\n\\end{proof}\n\\begin{theorem}\n    Transpose symmetry in $1-Complexity$ in small notations:\n    $ f \\in o_{1}(g(n)) \\Leftrightarrow g \\in \\omega_{1}(f(n)) $\n\\end{theorem}\n\\begin{proof}\n    Small \\textit{1-}o and Small \\textit{1-}Omega are equal with the classical sets defined in \\textit{Bachmann–Landau notations} and thus they conserve the Transpose symmetry property.\n\\end{proof}\n\n\\begin{theorem}\n    \\textbf{Projection in $1-Complexity$:}  \\\\  $ f \\in \\Theta_{1}(g(n)) \\Leftrightarrow f \\in \\mathcal{O}_{1}(g(n)), f \\in \\Omega_{1}(g(n)) $\n\\end{theorem}\n\\begin{proof}\n    Let $r = 1$ and use Projection property described in $rComplexity$ calculus.\n\\end{proof}\n\n\n\\section{Addition properties}\nAddition properties are obtained by assuming $r = 1$ in the $r$Complexity model.\n\\begin{theorem}\n    Addition properties in \\textbf{Big 1-Theta}:  \\\\\n    The following relations hold for any correctly defined functions $f, g, f', g', h:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where $ h(n) = f'(n) + g'(n)\\  \\forall n \\in  \\mathbb{N} $, where $f',g'$ are two arbitrary functions such that $ f' \\in \\Theta_{1}(f), g' \\in \\Theta_{1}(g) $:\n    \\begin{itemize}\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow  h \\in \\Theta_{1}(g) $.\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow  h \\in \\Theta_{1}(f) $.\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow  h \\in \\Theta_{1} \\left( f + g \\right) $.\n    \\end{itemize}\n\\end{theorem}\n\n\\begin{theorem}\n    Addition properties \\textbf{Big 1-O}: \\\\\n    The following relations hold for any correctly defined functions $f, g, f', g', h:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where $ h(n) = f'(n) + g'(n)\\  \\forall n \\in \\mathbb{N} $, where $f',g'$ are two arbitrary functions such that $ f' \\in \\mathcal{O}_{1}(f), g' \\in \\mathcal{O}_{1}(g) $:\n    \\begin{itemize}\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow  h \\in \\mathcal{O}_{1}(g) $.\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow  h \\in \\mathcal{O}_{1}(f) $.\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow  h \\in \\mathcal{O}_{1} \\left( f + g \\right) $.\n    \\end{itemize}\n\\end{theorem}\n\n\n\\begin{theorem}\n    Addition properties \\textbf{Big 1-Omega}: \\\\\n    The following relations hold for any correctly defined functions $f, g, f', g', h:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where $ h(n) = f'(n) + g'(n)\\  \\forall n \\in \\mathbb{N} $, where $f',g'$ are two arbitrary functions such that $ f' \\in \\Omega_{1}(f), g' \\in \\Omega_{1}(g) $:\n    \\begin{itemize}\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow  h \\in \\Omega_{1}(g) $.\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow  h \\in \\Omega_{1}(f) $.\n        \\item \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow  h \\in \\Omega_{r} \\left( f + g \\right) $.\n    \\end{itemize}\n\n\\end{theorem}\n\n\nIn a relax notation (consider that by any  $1-$Complexity class notation, we denote an arbitrary function part of the class), the following relations can be settled:\n\n\\begin{lemma}\n    If $\\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0$:\n    \\begin{itemize}\n        \\item \\textbf{Big 1-Theta}:\n        \\[  \\Theta_{1}(f) + \\Theta_{1}(g) = \\Theta_{1}(g)\\]\n        \\item \\textbf{Big 1-O}:\n        \\[  \\mathcal{O}_{1}(f) + \\mathcal{O}_{1}(g) = \\mathcal{O}_{1}(g)\\]\n        \\item \\textbf{Big 1-Omega}:\n        \\[  \\Omega_{1}(f) + \\Omega_{1}(g) = \\Omega_{1}(g)\\]\n    \\end{itemize}\n\\end{lemma}\n\n\\begin{lemma}\n    If $\\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty$:\n    \\begin{itemize}\n        \\item \\textbf{Big 1-Theta}:\n        \\[  \\Theta_{1}(f) + \\Theta_{1}(g) = \\Theta_{1}(f)\\]\n        \\item \\textbf{Big 1-O}:\n        \\[  \\mathcal{O}_{1}(f) + \\mathcal{O}_{1}(g) = \\mathcal{O}_{1}(f)\\]\n        \\item \\textbf{Big 1-Omega}:\n        \\[  \\Omega_{1}(f) + \\Omega_{1}(g) = \\Omega_{1}(f)\\]\n    \\end{itemize}\n\\end{lemma}\n\n\\begin{lemma}\n    If $\\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+}$:\n    \\begin{itemize}\n        \\item \\textbf{Big 1-Theta}:\n        \\[  \\Theta_{1}(f) + \\Theta_{1}(g) = \\Theta_{1}(f + g)\\]\n        \\item \\textbf{Big 1-O}:\n        \\[  \\mathcal{O}_{1}(f) + \\mathcal{O}_{1}(g) = \\mathcal{O}_{1}(f + g)\\]\n        \\item \\textbf{Big 1-Omega}:\n        \\[  \\Omega_{1}(f) + \\Omega_{1}(g) = \\Omega_{1}(f + g)\\]\n    \\end{itemize}\n\\end{lemma}\n\n\\begin{proof}\n    All proofs are based on the particularizing $r=1$ and rewrite the addition properties from rComplexity.\n\\end{proof}\n\n\n\\section{Normal form functions}\nIn this section, we will take further steps in simplifying calculus by introducing a new concept: the normal form of a monotonic, continuous function.\n\\begin{definition}\n    Let $g:\\mathbb{N}^{*}\\longrightarrow\\mathbb{R}_{+} $ be a monotonic, continuous function. Let the following:\n    \\[ g(n) = \\sum_{i=1}^{p} g_{i}(n)\\]\n    be a decomposition, with correctly defined function $g_{i}:\\mathbb{N}^{*}\\longrightarrow\\mathbb{R}_{+} \\forall i \\in [1, p]$, with the properties:\n    \\begin{itemize}\n\n        \\item $ \\exists \\ j, \\lim_{n\\to\\infty} \\dfrac{g_{j}(n)}{g(n)} = 1$\n        \\item $\\forall i \\neq j \\  lim_{n\\to\\infty} \\dfrac{g_{j}(n)}{g_{i}(n)} = \\infty$\n        \\item there is no another decomposition for $g_{j}(n) = \\sum_{k=1}^{p'} g_{j_{k}}(n)$ such that $\\lim_{n\\to\\infty} \\dfrac{g_{j}(n)}{g_{j_{k}}(n)} = \\infty, \\forall k \\in [1, p']$.\n    \\end{itemize}\n    Then, we call $g_{j}$ to be a function in \\textbf{normal form} or in \\textbf{atomic form}.\n\\end{definition}\n\n\\begin{remark}\n    We will refer to a monotonic, continuous function $g$ that is in normal form using the notation $g_{1}(n)$ .\n\\end{remark}\n\n\n\\begin{remark}\n    Working in $1$-Complexity with functions in normal form will involve converting an arbitrary monotonic, continuous function into an atomic representation, given by the normal form $g_{1}(n)$, by applying the decomposition presented in the definition above.This step involve few additional overhead in calculus, but overall the conversions are accessible and simplifies a lot the progress of complexity detection for various algorithms. Nonetheless, it provides powerful benchmarks solutions for comparing algorithms' efficiency.\n\\end{remark}\n\nAn useful subset of rComplexity Calculus is defined by Calculus using Normalized rComplexity class functions.\n\\begin{definition}\n    We will denote by:\n    \\[ f(n) \\in \\Theta_{1}(g_{1}(n)) \\]\n    a function f that is in the Big 1-Theta $1-$Complexity class defined by the function $g_{1}$ and $g_{1}$ is in normal form. Working with normal form functions for the class characterization in $1-$Complexity Calculus will be named \\textbf{normalized rComplexity calculus}.\n\\end{definition}\n\n\\begin{remark}\n    Working in $r$-Complexity with the required conversions such that $r = 1$ and the functions defining complexity classes is in normal form $(g = g_{1})$ is the most simple\n    calculus model while working with $r$-Complexity classes.\n\\end{remark}\n\n\n\\begin{remark}\n    A practical use case of this notation will be distinguishable when discussing the N Queens problems analysis for asymptotic time metric while working with $r$-Complexity classes.\n\\end{remark}", "meta": {"hexsha": "47a2274bfecef611cea51b54aa9b950217623a99", "size": 16517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX/complexity/unitaryRComplexity.tex", "max_stars_repo_name": "raresraf/rafMetrics", "max_stars_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-11-03T18:01:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T20:54:57.000Z", "max_issues_repo_path": "TeX/complexity/unitaryRComplexity.tex", "max_issues_repo_name": "raresraf/rafMetrics", "max_issues_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 392, "max_issues_repo_issues_event_min_datetime": "2019-11-09T21:28:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T13:04:45.000Z", "max_forks_repo_path": "TeX/complexity/unitaryRComplexity.tex", "max_forks_repo_name": "raresraf/rafMetrics", "max_forks_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-11T18:35:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-11T18:35:16.000Z", "avg_line_length": 57.1522491349, "max_line_length": 532, "alphanum_fraction": 0.6552642732, "num_tokens": 5694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6772028894075324}}
{"text": "% Sample of typesetting algorithmic code in LaTeX\n% Great option for writing pseudocode.\n% Adopted from: https://tex.stackexchange.com/a/56877\n%\n\n\\documentclass{article}[journal]\n\\usepackage{algorithm}      % http://ctan.org/pkg/algorithm\n\\usepackage{algpseudocode}  % http://ctan.org/pkg/algorithmicx\n\n\\begin{document}\n\n\\section*{Typesetting \\texttt{algorithmic code} in \\LaTeX} % Heading\n\n\\begin{algorithm}  % Begin algorithmic code\n  \\caption{Euclid’s algorithm}\\label{euclid}  % Label the code\n  \\begin{algorithmic}[1]  % Begin algorithmic code, layer 1\n\n    % Declare the beginning of the procedure\n    \\Procedure{Euclid}{$a,b$} \\Comment{The g.c.d. of a and b}  \n      \\State $r\\gets a\\bmod b$\n\n      \\While{$r\\not=0$} \\Comment{We have the answer if r is 0}  % Declare a while loop \n        \\State $a\\gets b$\n        \\State $b\\gets r$\n        \\State $r\\gets a\\bmod b$\n      \\EndWhile\\label{euclidendwhile}  % End the while loop\n\n      \\For{\\texttt{<condition>}}  % Declare a for loop\n        \\State \\texttt{<do something>}\n      \\EndFor  % End the for loop\n\n      \\State \\textbf{return} $b$ \\Comment{The gcd is b}\n    \n    \\EndProcedure  % End the procedure\n\n  \\end{algorithmic}\n\\end{algorithm}\n\n\\end{document}\n\n% EOF", "meta": {"hexsha": "c53995f9bca5d965e88459942600ad09825d2ad2", "size": 1222, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study-materials/Programming/algorithmic-code/sample.tex", "max_stars_repo_name": "michalspano/study-materials", "max_stars_repo_head_hexsha": "a1d69bcf84ae654ba247587f717168225aefd588", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-02-10T07:33:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T15:29:13.000Z", "max_issues_repo_path": "study-materials/Programming/algorithmic-code/sample.tex", "max_issues_repo_name": "michalspano/study-materials", "max_issues_repo_head_hexsha": "a1d69bcf84ae654ba247587f717168225aefd588", "max_issues_repo_licenses": ["MIT"], "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-materials/Programming/algorithmic-code/sample.tex", "max_forks_repo_name": "michalspano/study-materials", "max_forks_repo_head_hexsha": "a1d69bcf84ae654ba247587f717168225aefd588", "max_forks_repo_licenses": ["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.8048780488, "max_line_length": 87, "alphanum_fraction": 0.6677577741, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.6771784253195298}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\nTwo test cases adapted from \\textit{Eric Deleersnijder}'s working paper \\cite{deleersnijder2011test} are presented here: after introducing the problems, the analytic solutions are computed as well as their main properties. The code is then run on those problems, and the numerical solution and its properties are compared to the analytical ones. Rather than a validation of the numerical solver, this can be considered as a \\textit{sanity check}.\n\n%----------------------------------GOVERNING EQUATIONS--------------------------------------------------------%\n\\section{Governing equations}\nLet us consider a water domain, whose width is denoted $B(\\b{x},t)$, where $\\b{x} = (y,z)$ is the position vector and $t$ is the time. The continuity equation is\n\\begin{equation} \\label{eq:testcase:continuity}\n\t\\frac{\\partial B}{\\partial t} + \\nabla \\cdot (B\\b{u}) = 0,\n\\end{equation}\nwhere $\\b{u}(t,\\b{x})$ is the latitudinally-averaged meridional velocity. Assuming that mixing along the parallels is sufficiently efficient, we may study the concentration of a passive tracer by means of a two-dimensional model. The latitudinally-averaged concentration of the tracer $C(\\b x, t)$ obeys the following partial differential equation :\n\\begin{equation} \\label{eq:testcase:conservative}\n\t\\frac{\\partial (BC)}{\\partial t} + \\nabla \\cdot (B \\b{u} C) = Q\\delta(\\b{x} - \\b{x}_1) + \\nabla \\cdot (B\\b{K} \\cdot \\nabla C), \n\\end{equation}\nwhere $\\b{K}$ is the diffusivity tensor (symmetric and positive definite); $\\delta$ is the Dirac delta function with $\\delta(\\b{x}-\\b{x}_n) = \\delta(x-x_n)\\delta(y-y_n)$; $Q(t)$ is the rate of release of a lineic source of length $B$ along the latitude direction located at $\\b{x} = \\b{x}_1$. If $C(\\b x,t)$ represents the \ndensity of the tracer in water, then $Q(t)$ is the mass of tracer released per second by the source.\n\nEquation~\\eqref{eq:testcase:conservative} is the so-called conservative form of the model. The convective form is obtained by combining equations~\\eqref{eq:testcase:continuity} and~\\eqref{eq:testcase:conservative}:\n\\begin{equation}  \\label{eq:testcase:convective}\n\t\\frac{\\partial C}{\\partial t} + \\b{u} \\cdot \\nabla C = \\frac{Q}{B} \\delta(\\b{x} - \\b{x}_1) + \\frac{1}{B} \\nabla \\cdot (B\\b{K} \\cdot \\nabla C).\n\\end{equation}\n\n%----------------------------------AN IDEALISED MODEL----------------------------------------------------------------------%\n\\section{An idealized model}\nFor our test case to be interesting, we must be able to compute its analytical solution. Accordingly, we make some simplifying assumptions which will allow us to compute the solution analytically.\nFirst, we assume a constant width $B$ and a constant velocity field\n\\begin{equation} \\label{eq:testcase:velocity}\n\t\\b{u}(t,\\b{x}) = v \\b e_y + w \\b e_z,\n\\end{equation}\nwhere $\\b e_y$ and $\\b e_z$ are the unit vectors associated respectively with the $y$- and $z$-coordinate axis. Furthermore, the diffusivity tensor is supposed constant and diagonal :\n\\begin{equation} \\label{eq:testcase:diffusivity}\n\t\\b{K} = \\begin{pmatrix}\n\t\t\tK_{yy} & 0 \\\\\n\t\t\t0 & K_{zz}\n\t\t\t\\end{pmatrix},\n\\end{equation}\nwhere $K_{yy},\\ K_{zz} > 0$. Finally, we consider a sudden pointwise release of tracer at $t=0$. Hence, $Q(t)$ is of the form :\n\\begin{equation}\n\tQ(t) = M\\delta(t),\n\\end{equation} \nwhere $M$ is the mass of tracer released at $t=0$.\n\nUnder these assumptions, equation~\\eqref{eq:testcase:convective} simplifies to :\n\\begin{equation} \\label{eq:testcase}\n\t\\frac{\\partial C}{\\partial t} + v \\frac{\\partial C}{\\partial y} + w \\frac{\\partial C}{\\partial z} = J \\delta(t) \\delta(y - y_1)\\delta(z-z_1) + K_{yy} \\frac{\\partial^2 C}{\\partial y^2} + K_{zz} \\frac{\\partial^2 C}{\\partial z^2},\n\\end{equation}\nwhere $J := M/B$.\nFor the sake of simplicity, we can forget about the fact that our model is width-integrated and consider that it is a purely two-dimensional model with a point-source\n\\begin{equation}\n\tQ := J\\delta(t).\n\\end{equation}\nA part of the physical meaning of the model is lost but this makes representations of the problem easier. $C$ now represents the two-dimensional density (i.e., in [$kg/m^2$]) of the tracer in water. $J$ can then be regarded as the mass of tracer released by the sudden point source at $\\b x = \\b x_1$. The three- and two-dimensional interpretations of the problem are represented on figure~\\ref{fig:testcase_scheme}.\n% \\footnote{This could be a bit confusing. As we switch from a 3-dimensional interpretation of the model to a 2-dimensional one, the meaning of the parameters changes. Hence, in the 3-dimensional interpretation, $C$ represents a 3D density ([$kg/m^3$]) and $M$ is a mass, whereas in the 2-dimensional interpretation, $C$ is a 2D density ([$kg/m^2$]) and $M$ has units of [$kg\\,m$]. A part of the physical meaning of the model is lost, but this makes representations of the problem much easier.} \\textcolor{red}{On peut aussi simplement considérer B = 1. Attention, si on opte finalement pour cette option, un facteur B doit être présent pour le calcul de certains diagnostiques.}\n\\begin{figure}[H]\n\t\\centering\n\t\\scalebox{.8}{\\input{fig/testcase/testcase_scheme3D}}\n\t\\scalebox{.8}{\\input{fig/testcase/testcase_scheme2D}}\n\t\\caption{Illustration of the 3D and 2D interpretations of the model.}\n    \\label{fig:testcase_scheme}\n\\end{figure}\n\n\n%------------------------------------PARAMETERS FOR TEST CASE 1--------------------------------------------------------------%\n\\subsection{Test case 1 : infinite domain}\nThe first (an most simple) test case consists in considering an infinite domain, i.e.\n\\begin{equation} \\label{eq:testcase:domain}\n\t-\\infty < y,\\, z < \\infty,\n\\end{equation}\nwith nonzero velocities $v$ and $w$. This test case provides a check that our numerical implementation handles the diffusion and advection processes properly both in the $y$- and $z$-directions. The parameters are chosen from the values proposed by \\textit{C. Timmermans} for the overturner model in her master's thesis \\cite{timmermans2006masterthesis}:\n\\begin{equation}\n\tv = \\frac{\\Psi}{H} = 4\\e{-4}\\mbox{ [$m/s$],}\\quad  w = \\frac{\\Psi}{L}=1.33\\e{-7}\\mbox{ [$m/s$],}\n\\end{equation}\nand\n\\begin{equation}\n\tK_{yy} = 10^{3} \\mbox{ [$m^2/s$],}\\quad K_{zz} = 10^{-4} \\mbox{ [$m^2/s$].} \n\\end{equation}\nFor the length scales of the overturner model, those diffusivities corresponds to Péclet numbers\n\\begin{equation}\n\tPe_y = \\frac{v}{K_{yy}/L} = 6,\\quad Pe_z = \\frac{w}{K_{zz}/H} = 6.67.\n\\end{equation}\nHence, in both the $y$- and $z$-directions, the transport is neither dominated by advection nor by diffusion. This is interesting as a test case since it allows to assess how the numerical solver handles both physical processes in both directions. \nFinally, $J = 10\\,000$ particles are released at $t=0$ at the location $(y_1,z_1) = (0,0)$.\n\n%------------------------------------PARAMETERS FOR TEST CASE 2--------------------------------------------------------------%\n\\subsection{Test case 2 : semi-infinite domain}\nAnother interesting case is to consider a semi-infinite domain with a wall at $z=0$ :\n\\begin{equation}\n\t-\\infty < y < \\infty,\\quad 0 < z < \\infty.\n\\end{equation}\nThis is useful to assess how our numerical model handles no-through boundary conditions. Again, the parameters values are related to the ones proposed in \\textit{C. Timmermans}'s master's thesis for the overturner model :\n\\begin{equation}\n\tv = \\frac{\\Psi}{H} = 4\\e{-4}\\mbox{ [$m/s$],}\\quad  w = 0\\mbox{ [$m/s$],}\n\\end{equation}\nand\n\\begin{equation}\n\tK_{yy} = 10^{3} \\mbox{ [$m^2/s$],}\\quad K_{zz} = 10^{-1} \\mbox{ [$m^2/s$].} \n\\end{equation}\nNotice the choice  of $K_{zz}$ : it is chosen $10^3$ times larger than the value chosen for test case 1. The goal here is to assess that the boundary condition is well handled by the solver. Since $w=0$, only the vertical diffusivity could possibly drive the particles towards the wall. By increasing $K_{zz}$, we ensure that more particles will bounce against the wall, which is relevant in this context. $J = 10\\,000$ particles are released at $t=0$ at the location $(y_1,z_1) = (0,H)$.\n\n\\section{Analytical solution and properties}\n%------------------------------------------------Analytic GREEN's FUNCTION ---------------------------------------------%\n\\subsection{Green's function}\nIn order to build the analytical solution of the problem, we need to compute the Green's function associated to this particular problem. We derive the Green's function $G$ associated to test case 1. We will show later how this function can be used to compute the concentration for both test case 1 and test case 2. $\\G$ is zero for $t<t'$ and is the solution of\n\\begin{equation} \\label{eq:testcase_green}\n\t\\begin{cases}\n\t\t\\frac{\\partial G}{\\partial t} + v \\frac{\\partial G}{\\partial y} + w\\frac{\\partial G}{\\partial z} = K_{yy}\\frac{\\partial^2 G}{\\partial y^2} + K_{zz}\\frac{\\partial^2 G}{\\partial z^2}\\\\[.1cm]\n\t\t\\left. G(y,z,t,t') \\right \\rvert_{t=t'} = \\delta(y)\\delta(z) \n\t\\end{cases}\n\\end{equation}\nfor $t \\ge 0$, and on an infinite domain $\\infty < y,\\, z < \\infty$. It can be shown that\n\\begin{equation} \n\tG(y,z,t,t') = \\frac{\\exp\\left[-\\frac{(y-s_v)^2}{4K_{yy}\\tau} -\\frac{(z-s_w)^2}{4K_{zz}\\tau} \\right]}{4\\pi\\sqrt{K_{yy}K_{zz}}\\tau},\n\\end{equation}\nwhere $\\tau = t-t'$ and \n\\begin{equation}\n\t\\b s(t,t') = (s_v(t,t'), s_w(t,t')) = \\left(\\int_{t'}^{t}v \\rm d \\xi, \\int_{t'}^{t}w \\rm d \\xi \\right) = \\left(v\\tau, w\\tau\\right).\n\\end{equation}\n\n$G$ has some interesting properties. The \"mass\" of the solution is\n\\begin{equation} \\label{eq:testcase:propmass}\n\tm(t,t') \\equiv \\int_{\\R[2]} \\G \\rm d \\b x = 1.\n\\end{equation}\nThe \"center of mass\" is located at\n\\begin{equation} \\label{eq:testcase:propcenter}\n\t\\b r(t,t') \\equiv \\frac{1}{m(t,t')} \\int_{\\R[2]} \\b x \\G \\rm d \\b x  = \\b s(t,t').\n\\end{equation}\nThe variance of the solution is\n\\begin{equation} \\label{eq:testcase:propvar}\n\t\\sigma^2(t,t') \\equiv \\frac{1}{m(t,t')} \\int_{\\R[2]} \\lvert \\b x - \\b r(t,t') \\rvert^2 \\G \\rm d \\b x = 2 (K_{yy}+K_{zz}) \\tau.\n\\end{equation}\n\n%------------------------------------------------Analytic TEST CASE 1 ---------------------------------------------%\n\\subsection{Test case 1}\nThe analytical solution of test case 1 is now obtained with the help of the Green's function derived above by computing the convolution between $G$ and the source terms :\n\\begin{align}\n\tC(\\b x,t) &= \\int_{0}^{t} \\int_{\\R[2]} G(\\b x - \\b x',t,t') J \\delta(t) \\delta(\\b x- \\b x_1) \\rm d \\b{x}' \\rm dt'\\nonumber\\\\\n\t&= J G(\\b x - \\b x_1,t,0).\n\\end{align}\nThe concentration profile for test case 1 is thus\n\\begin{equation}\n\tC(y,z,t) = \\frac{J}{4\\pi\\sqrt{K_{yy}K_{zz}}t}\\exp\\left[-\\frac{(y-s_v)^2}{4K_{yy}t} -\\frac{(z-s_w)^2}{4K_{zz}t} \\right].\n\\end{equation}\n\nThe total mass of tracer present in the domain is\n\\begin{equation}\n\tm(t) \\equiv \\int_{\\R[2]} C(\\b x,t) \\rm d \\b x = J.\n\\end{equation}\nNote that this number is independent of the transport processes.\n\nThe mass center is located at\n\\begin{align}\n\t\\b r(t) &\\equiv \\frac{1}{m(t)} \\int_{\\R[2]} \\b x C(\\b x,t) \\rm d \\b x \\nonumber \\\\\n\t&= \\int_{\\R[2]} \\b x G(\\b x - \\b x_1,t,0) \\rm d \\b x \\nonumber\\\\\n\t&= \\int_{\\R[2]} (\\b x-\\b x_1) G(\\b x - \\b x_1,t,0) + \\b x_1 G(\\b x - \\b x_1,t,0) \\rm d \\b x\\nonumber\\\\\n\t&= \\b x_1 + \\b s(t,0),\n\\end{align}\nwhere properties~\\eqref{eq:testcase:propmass} and~\\eqref{eq:testcase:propcenter} are used to perform the last step.\n\nFinally, the variance of the solution is\n\\begin{align}\n\t\\sigma^2(t) &= \\frac{1}{m(t)} \\int_{\\R[2]} \\lvert \\b x - \\b r(t) \\rvert^2 C(\\b x,t) \\rm d \\b x \\nonumber \\\\\n\t&= \\int_{\\R[2]} \\lvert (\\b x - \\b x_1) - \\b s(t,0)\\rvert^2 G(\\b x - \\b x_1,t,0) \\rm d \\b x \\nonumber \\\\\n\t&= 2(K_{yy}+K_{zz})t,\n\\end{align}\nwhere property~\\eqref{eq:testcase:propvar} is used.\n\n%------------------------------------------------Analytic TEST CASE 2 ---------------------------------------------%\n\\subsection{Test case 2}\nTo compute the solution to test case 2, a little trick must be applied. Consider the problem on an infinite domain with two sudden point sources of equal intensity located at $z = H$ and $z = -H$. By symmetry, one can see that the concentration of that problem in the region $[-\\infty, \\infty] \\times [0, \\infty]$ is precisely the concentration of test case 2. Hence, we can use the Green's function $G$ derived for test case 1 to compute the concentration. In this case, the convolution has to be performed with two point sources :\n\\begin{align}\n\tC(\\b x,t) &= \\int_{0}^{t} \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} J \\delta(t') \\delta(y'- y_1)\\left[\\delta(z'-z_1)+\\delta(z'+z_1)\\right] G(y-y',z-z',t,t') \\rm dy' \\rm dz' \\rm dt' \\nonumber\\\\\n\t&= J \\int_{0}^{t} \\delta(t')[G(y-y_1,z-z_1,t,t')+G(y-y_1,z+z_1,t,t')] \\label{tc2_eq2} \\nonumber\\\\\n\t&= J[G(y-y_1,z-z_1,t,0)+G(y-y_1,z+z_1,t,0)].\n\\end{align}\nThe concentration of the tracer for test case 2 is thus\n\\begin{equation}\n\tC(y,z,t) = \\frac{J}{4\\pi\\sqrt{K_{yy}K_{zz}}t}\\exp\\left[-\\frac{(y-s_v)^2}{4K_{yy}t}\\right]\\left\\{\\exp\\left[-\\frac{(z-z_1)^2}{4K_{zz}t} \\right] + \\exp\\left[-\\frac{(z+z_1)^2}{4K_{zz}t} \\right] \\right\\}\n\\end{equation}\n\nThe mass is obtained as\n\\begin{equation}\n\tm(t) \\equiv \\int_{0}^{\\infty} \\int_{-\\infty}^{\\infty} C(y,z,t) \\rm dy \\rm dz = J,\n\\end{equation}\ni.e. the number of particles released at $t=0$. This result is obvious since there is no other source or sink, and we impose a no-through condition at the boundary.\n\nNo analytic solution has been found for the center of mass and the variance. However, an accurate estimation of those quantities can be computed numerically from the expression of the concentration. \n\n% The mass center is\n% \\begin{align}\n% \t\\b r(t) &\\equiv \\frac{1}{m(t)} \\int_{0}^{\\infty} \\int_{-\\infty}^{\\infty} (y \\b e_y + z \\b e_z) C(t,y,z) \\rm dy \\rm dz \\nonumber \\\\\n% \t&= \\int_{0}^{\\infty} \\int_{-\\infty}^{\\infty} (y \\b e_y + z \\b e_z) \\left[G(t,0,y-y_1,z-z_1)+G(t,0,y-y_1,z+z_1)\\right] \\rm dy \\rm dz \\nonumber\\\\\n% \t&= \\int_{\\R[2]} (\\b x-\\b x_1) G(t,0,\\b x - \\b x_1) + \\b x_1 G(t,0,\\b x - \\b x_1) \\rm d \\b x\\nonumber\\\\\n% \t&= \\b x_1 + \\b s(t,0),\n% \\end{align}\n\n%-------------------------------------VALIDATION--------------------------------------------------------------------------------%\n\\section{Validation of the numerical solver}\nThis section aims to show that the numerical results obtained with the solver are in good agreement with the analytical ones. As the combination of the two test cases cover the main features of the problems considered in this work, this constitutes a basic validation of the solver. \n\nBoth test cases are simulated for 1 year with a time step of 1 hour, and $P = 10\\,000$ particles are released at $t=0$.\nThe concentration is computed at the final time $T = 1$ year on the domain $\\Omega = [y_{min},y_{max}] \\times [z_{min},z_{max}]$, where the subscripts \\textit{min} and \\textit{max} stands for the minimal and maximal position at time $T$ amongst all the particles. The domain $\\Omega$ is divided into $20 \\times 20$ boxes denoted $\\Omega_i$ for $i = 1,\\dots,200$. Let $C_i(t)$ denote the concentration in box $i$ at time $t$ and $C_{max}(t) = \\max_i C_i(t)$. The scaled concentration in box $i$ is computed as\n\\begin{equation}\n\t\\tilde C_i(T) := \\frac{C_i(T)}{C_{i,max}(T)} = \\frac{P_i(T)}{P_{max}(T)},\n\\end{equation}\nwhere $P_i(t)$ is the number of particles in box $i$ at time $t$ and $P_{max}(t) = \\max_i P_i(t)$. The last equality is true because all the boxes have the same volume. The analytic solutions of the concentration are scaled identically:\n\\begin{equation}\n\t\\tilde C(t) = \\frac{C(t)}{C_{max}(t)}.\n\\end{equation}\n\n%-------------------------------------RESULTS CASE 1----------------------------------------------------------------------------%\n\\subsection{Test case 1}\nFigure~\\ref{fig:testcase_surf} shows a comparison between the numerical result and the analytical solution for the scaled concentration $C(\\b x,T)/\\tilde C$. Dark (resp. light) shaded areas correspond to zones where the numerically computed concentration is \"above\" (resp. \"below\") the exact concentration. It would probably have been more rigorous to represent the numerically computed concentration as a three-dimensional histogram since the box-counting method computes the mean value of the concentration in each box. However, here we have considered that the numerically computed mean concentration in a box corresponds to the concentration at the center of that box. The continuous representation of $\\tilde{C}_{num}$ is then obtained by interpolation. Figures~\\ref{fig:testcase_fixedy} and~\\ref{fig:testcase_fixedz} represent respectively a cut of the concentrations at fixed $y = r_{y,exact}$ and at fixed $z = r_{z,exact}$. The numerically computed concentration $\\tilde C_{num}$ seems to be an appreciable approximation of the exact concentration $\\tilde C_{exact}$. To be more specific, the maximal local error is \n\\begin{equation}\n\t\\|\\tilde C_{exact}- \\tilde C_{num}\\|_{\\infty} = 7.017\\e{-2}.\n\\end{equation}\nThe centers of mass are located at\n\\begin{equation}\n\t\\b r_{exact} = (12\\,614.4,\\,4.2) \\mbox{ [$m$],}\\quad \\b r_{num} = (11\\,715.3,\\,4.5) \\mbox{ [$m$]}.\n\\end{equation}\nThe relative error is\n\\begin{equation}\n\t\\b e_r = \\left \\lvert \\frac{\\b r_{exact}-\\b r_{num}}{\\b r_{exact}} \\right \\rvert =  \\left(7.13\\e{-2}, 7.89\\e{-2}\\right),\n\\end{equation}\nwhere the division is taken element-wise on the vectors. The euclidean norm of the relative error is\n\\begin{equation}\n\t\\| \\b e_r \\|_2 = 1.06\\e{-1}.\n\\end{equation}\nThis can be seen as a quantification of the error on advection. To quantify the error on diffusion, we compute the variance of the concentration :\n\\begin{equation}\n\t\\sigma^2_{exact} = 6.31\\e{10} \\mbox{ [$m^2$],}\\quad \\sigma^2_{num} = 6.43\\e{10} \\mbox{ [$m^2$].}\n\\end{equation}\nThe relative error is\n\\begin{equation}\n\te_{\\sigma^2} = \\left \\lvert \\frac{\\sigma^2_{exact}-\\sigma^2_{num}}{\\sigma^2_{exact}}\\right \\rvert = 1.86\\e{-2}.\n\\end{equation}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width = \\textwidth]{fig/testcase/testcase_surf.eps}\n\t\\caption{Comparison of the concentrations obtained analytically and numerically. The \"centers of mass\" of the concentration obtained numerically (black cross) and numerically (white bullet) are also shown on the figure.}\n\t\\label{fig:testcase_surf}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{0.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/testcase/testcase_fixedy.eps}\n\t\t\\caption{$\\tilde C_{num}(y_1+vT,z)$ and $\\tilde C_{exact}(y_1+vT,z)$.}\n\t\t\\label{fig:testcase_fixedy}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{0.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/testcase/testcase_fixedz.eps}\n\t\t\\caption{$\\tilde C_{num}(y,z_1+wT)$ and $\\tilde C_{exact}(y,z_1+wT)$.}\n\t\t\\label{fig:testcase_fixedz}\n\t\\end{subfigure}\n\t\\caption{Cut of the concentrations at fixed $y = r_{y,exact}$ and at fixed $z = r_{z,exact}$. The dashed line represent $\\tilde C_{num}$ and the continuous line is for $\\tilde C_{exact}$.}\n\\end{figure}\n\n%-------------------------------------------RESULTS CASE 2-----------------------------------------------------------------------%\n\\subsection{Test case 2}\nFigure~\\ref{fig:testcaseSI_surf} shows a comparison between the numerical result and the analytical solution for the scaled concentrations for test case 2. The same remark as the one made for test case 1 applies concerning the representation of the numerically computed concentration. Since we do not have analytical expressions of the center of mass and of the variance for this test case, the \"exact\" values are approximated numerically thanks to the analytical expression of the concentration. Figures~\\ref{fig:testcaseSI_fixedy} and~\\ref{fig:testcaseSI_fixedz} represent respectively a cut of the concentrations at fixed $y = r_{y,exact}$ and along the boundary $z = 0$. The big picture about test case 2 is the presence of a boundary with no-through condition. A first verification is to check if all the particles are still in the domain, which is indeed the case. Although this might seem trivial here, it is sometimes a real challenge to ensure that no particle crosses the boundary, especially for geometrically complex domains. Besides, one can see on figure~\\ref{fig:testcaseSI_fixedz} that the concentration profile is well approximated along the boundary. Indeed, the maximal local error at the boundary is\n\\begin{equation}\n\t\\|\\tilde C_{exact}(y,0)- \\tilde C_{num}(y,0)\\|_{\\infty} = 2.964\\e{-2}, \n\\end{equation}\nThe maximal local error on the whole domain is \n\\begin{equation}\n\t\\|\\tilde C_{exact}- \\tilde C_{num}\\|_{\\infty} = 8.668\\e{-2}.\n\\end{equation}\nThe centers of mass are located at\n\\begin{equation}\n\t\\b r_{exact} = (1.26\\e{4},5.06\\e{3}) \\mbox{ [$m$],}\\quad \\b r_{num} = (1.37\\e{4},5.05\\e{3}) \\mbox{ [$m$]}.\n\\end{equation}\nThe relative error is\n\\begin{equation}\n\t\\b e_r = \\left \\lvert \\frac{\\b r_{exact}-\\b r_{num}}{\\b r_{exact}} \\right \\rvert =  \\left(8.566\\e{-2}, 2.718\\e{-3}\\right).\n\\end{equation}\nThe euclidean norm of the relative error is\n\\begin{equation}\n\t\\| \\b e_r \\|_2 = 8.571\\e{-2}.\n\\end{equation}\nThis can be seen as a quantification of the error on advection. To quantify the error on diffusion, we compute the variance of the concentration :\n\\begin{equation}\n\t\\sigma^2_{exact} = 6.39\\e{10} \\mbox{ [$m^2$],}\\quad \\sigma^2_{num} = 6.25\\e{10} \\mbox{ [$m^2$].}\n\\end{equation}\nThe relative error is\n\\begin{equation}\n\te_{\\sigma^2} = \\left \\lvert \\frac{\\sigma^2_{exact}-\\sigma^2_{num}}{\\sigma^2_{exact}}\\right \\rvert = 2.269\\e{-2}.\n\\end{equation}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width = \\textwidth]{fig/testcase/testcaseSI_surf.eps}\n\t\\caption{Comparison of the concentrations obtained analytically and numerically. The \"centers of mass\" of the concentration obtained numerically (black cross) and numerically (white bullet) are also shown on the figure.}\n\t\\label{fig:testcaseSI_surf}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{0.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/testcase/testcaseSI_fixedy.eps}\n\t\t\\caption{$\\tilde C_{num}(y_1+vT,z)$ and $\\tilde C_{exact}(y_1+vT,z)$.}\n\t\t\\label{fig:testcaseSI_fixedy}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{0.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/testcase/testcaseSI_fixedz.eps}\n\t\t\\caption{$\\tilde C_{num}(y,0)$ and $\\tilde C_{exact}(y,0)$.}\n\t\t\\label{fig:testcaseSI_fixedz}\n\t\\end{subfigure}\n\t\\caption{Cut of the concentrations at fixed $y = r_{y,exact}$ and along the wall (fixed $z = 0$). The dashed line represent $\\tilde C_{num}$ and the continuous line is for $\\tilde C_{exact}$.}\n\\end{figure}", "meta": {"hexsha": "b992be5e02601f3f4dda9454fd5884d943baf246", "size": 22513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/appendix/test_case.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/appendix/test_case.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/appendix/test_case.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": 73.8131147541, "max_line_length": 1219, "alphanum_fraction": 0.6747212722, "num_tokens": 7121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6771417963328439}}
{"text": "\\subsubsection{Linear Factors}\r\n\\noindent\r\nThis is the the most basic type where the degree of the numerator is less than the degree of the denominator and the denominator factors into all linear factors with no repeated roots. In this case we can write\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{Q(x)} = \\frac{A_1}{(x-a_1)} + \\ldots + \\frac{A_n}{(x-a_n)}\r\n\\end{equation*}\r\nMultiplying each side by $Q(x)$,\r\n\\begin{equation*}\r\n\tP(x) = A_1(x-a_2) \\ldots (x-a_n) + \\ldots + A_n(x-a_1) \\ldots (x-a_{n-1})\r\n\\end{equation*}\r\nWe can then find each $A_i$ by evaluating both sides at $x=a_i$, since every term except the ith has an $(x-a_i)$ factor that will go to 0. So,\r\n\\begin{equation*}\r\n\tA_i = \\frac{P(a_i)}{(x-a_i) \\ldots (x-a_{i-1})(x-a_{i+1}) \\ldots (x-a_n)}\r\n\\end{equation*}\r\n\r\n\\ifodd\\includeBackgroundReviewExamples\\input{./backgroundReview/algebraPreCalc/linearFactors_example.tex}\\fi", "meta": {"hexsha": "92d1d3adc4e6f26efd77e350dcb67d08e79ea27d", "size": 877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/algebraPreCalc/linearFactors.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/algebraPreCalc/linearFactors.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/algebraPreCalc/linearFactors.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.8125, "max_line_length": 211, "alphanum_fraction": 0.7001140251, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6771417768112934}}
{"text": "\\section{Comparison Tests}\\label{sec:ComparisonTests}\n\nAs we begin to compile a list of convergent and divergent series, new\nones can sometimes be analyzed by comparing them to ones that we\nalready understand.\n\n\\begin{example}{}{}\nDoes $\\ds\\sum_{n=2}^\\infty {1\\over n^2\\ln n}$ converge?\n\\end{example}\n\\begin{solution}\nThe obvious first approach, based on what we know, is the integral test.\nUnfortunately, we can't compute the required antiderivative. But\nlooking at the series, it would appear that it must converge, because\nthe terms we are adding are smaller than the terms of a $p$-series,\nthat is,\n$${1\\over n^2\\ln n}<{1\\over n^2},$$\nwhen $n\\ge3$. Since adding up the terms $\\ds 1/n^2$ doesn't get ``too\nbig'', the new series ``should'' also converge. Let's make this more\nprecise.\n\nThe series $\\ds\\sum_{n=2}^\\infty {1\\over n^2\\ln n}$ converges if and\nonly if $\\ds\\sum_{n=3}^\\infty {1\\over n^2\\ln n}$ converges---all we've\ndone is dropped the initial term. We know that \n$\\ds\\sum_{n=3}^\\infty {1\\over n^2}$ converges. Looking at two typical\npartial sums:\n$$\n  s_n={1\\over 3^2\\ln 3}+{1\\over 4^2\\ln 4}+{1\\over 5^2\\ln 5}+\\cdots+\n  {1\\over n^2\\ln n} < {1\\over 3^2}+{1\\over 4^2}+\n  {1\\over 5^2}+\\cdots+{1\\over n^2}=t_n.\n$$\nSince the $p$-series converges, say to $L$, and since the terms are positive,\n$\\ds t_n<L$. Since the terms of the new series are positive, the $\\ds s_n$\nform an increasing sequence and $\\ds s_n<t_n<L$ for all $n$. Hence the\nsequence $\\ds \\{s_n\\}$ is bounded and so converges.\n\\end{solution}\n\nSometimes, even when the integral test applies, comparison to a known\nseries is easier, so it's generally a good idea to think about doing a\ncomparison before doing the integral test.\n\n\\begin{example}{}{AbsSineOverNSquared}\nDoes $\\ds\\sum_{n=2}^\\infty {|\\sin n|\\over n^2}$ converge?\n\\end{example}\n\\begin{solution}\nWe can't apply the integral test here, because the terms of this\nseries are not decreasing. Just as in the previous example, however,\n$$ {|\\sin n|\\over n^2}\\le {1\\over n^2},$$\nbecause $|\\sin n|\\le 1$. Once again the partial sums are\nnon-decreasing and bounded above by $\\ds \\sum 1/n^2=L$, so the new series\nconverges. \n\\end{solution}\n\nLike the integral test, the comparison test can be used to show both\nconvergence and divergence. In the case of the integral test, a single\ncalculation will confirm whichever is the case. To use the comparison\ntest we must first have a good idea as to convergence or divergence\nand pick the sequence for comparison accordingly.\n\n\\begin{example}{}{}\nDoes $\\ds\\sum_{n=2}^\\infty {1\\over\\sqrt{n^2-3}}$ converge?\n\\end{example}\n\\begin{solution}\nWe observe that the $-3$ should have little effect compared to the\n$\\ds n^2$ inside the square root, and therefore guess that the terms are\nenough like $\\ds 1/\\sqrt{n^2}=1/n$ that the series should diverge. We\nattempt to show this by comparison to the harmonic series. We note\nthat \n$${1\\over\\sqrt{n^2-3}} > {1\\over\\sqrt{n^2}} = {1\\over n},$$\nso that\n$$\n  s_n={1\\over\\sqrt{2^2-3}}+{1\\over\\sqrt{3^2-3}}+\\cdots+\n  {1\\over\\sqrt{n^2-3}} > {1\\over 2} + {1\\over3}+\\cdots+{1\\over n}=t_n,\n$$\nwhere $\\ds t_n$ is 1 less than the corresponding partial sum of the\nharmonic series (because we start at $n=2$ instead of $n=1$). Since\n$\\ds\\lim_{n\\to\\infty}t_n=\\infty$, $\\ds\\lim_{n\\to\\infty}s_n=\\infty$ as\nwell.\n\\end{solution}\n\nSo the general approach is this: If you believe that a new series is\nconvergent, attempt to find a convergent series whose terms are\nlarger than the terms of the new series; if you believe that a new\nseries is divergent, attempt to find a divergent series whose terms\nare smaller than the terms of the new series.\n\n\\begin{example}{}{}\nDoes $\\ds\\sum_{n=1}^\\infty {1\\over\\sqrt{n^2+3}}$ converge?\n\\end{example}\n\\begin{solution}\nJust as in the last example, we guess that this is very much like the\nharmonic series and so diverges. Unfortunately,\n$${1\\over\\sqrt{n^2+3}} < {1\\over n},$$\nso we can't compare the series directly to the harmonic series.\nA little thought leads us to\n$${1\\over\\sqrt{n^2+3}} > {1\\over\\sqrt{n^2+3n^2}} = {1\\over2n},$$ so if\n$\\sum 1/(2n)$ diverges then the given series diverges. But since $\\sum\n1/(2n)=(1/2)\\sum 1/n$, Theorem~\\xrefn{thm:SeriesLinear} implies\nthat it does indeed diverge.\n\\end{solution}\n\nFor reference we summarize the comparison test in a theorem.\n\n\\begin{theorem}{Comparison Theorem}{ComparisonTheorem}\nSuppose that $\\ds a_n$ and $\\ds b_n$ are non-negative for all $n$ and\nthat $\\ds a_n\\le b_n$ when $n\\ge N$, for some $N$.\n\n\\begin{itemize}\n\\item{} If $\\ds\\sum_{n=0}^\\infty b_n$ converges, so does \n$\\ds\\sum_{n=0}^\\infty a_n$.\n\\item{} If $\\ds\\sum_{n=0}^\\infty a_n$ diverges, so does \n$\\ds\\sum_{n=0}^\\infty b_n$.\n\\end{itemize}\n\\end{theorem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:ComparisonTests}}\n\n\\begin{enumialphparenastyle}\n\nDetermine whether the series converge or diverge.\n\n\\begin{multicols}{2}\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {1\\over 2n^2+3n+5} $\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=2}^\\infty {1\\over 2n^2+3n-5} $\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {1\\over 2n^2-3n-5} $\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {3n+4\\over 2n^2+3n+5} $\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {3n^2+4\\over 2n^2+3n+5} $\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {\\ln n\\over n}$\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {\\ln n\\over n^3}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=2}^\\infty {1\\over \\ln n}$\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {3^n\\over 2^n+5^n}$\n\\begin{sol}\nconverges\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\sum_{n=1}^\\infty {3^n\\over 2^n+3^n}$\n\\begin{sol}\ndiverges\n\\end{sol}\n\\end{ex}\n\\end{multicols}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "3abca568d02d1203969f57069246b15b8b7d2d86", "size": 5917, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9-sequences-and-series/9-5-comparison-test.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "9-sequences-and-series/9-5-comparison-test.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "9-sequences-and-series/9-5-comparison-test.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3435897436, "max_line_length": 77, "alphanum_fraction": 0.6939327362, "num_tokens": 2136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.918480244583138, "lm_q1q2_score": 0.6770652095076497}}
{"text": "\\section{Free Vibrations}\r\n\\noindent\r\nFree damped vibrations, like in a massed spring system, are a common application of second order linear ODEs. In a massed spring system, there are three main forces acting on the mass that make up external forces.\r\n\\begin{enumerate}[label=\\arabic*)]\r\n\t\\item Acceleration of The Mass -- Since acceleration is the 2nd derivative of position $y(t)$, and Newton's Second Law tells us that $F = ma$, the force from the acceleration of the mass is $my''$.\r\n\t\\item Dampening -- We'll assume that this term is proportional to the velocity, $y'$, and a term $b$. So, the force from dampening is $by'$.\r\n\t\\item Spring Stretch -- Hooke's Law tells us that the force from a spring is $ky$, where $k$ is some term that gives the spring's \"stiffness\"\r\n\\end{enumerate}\r\nSince we assume that the net force is 0 (that's what free means), our equations is\r\n\\begin{equation*}\r\n\tmy'' + by' + ky = 0\r\n\\end{equation*}\r\n\r\n\\noindent\r\nExtracting the coefficients and solving the auxiliary equation,\r\n\\begin{equation*}\r\n\tmr^2 + br + k = 0 \\implies r = \\frac{-b \\pm \\sqrt{b^2 - 4mk}}{2m}\r\n\\end{equation*}\r\nWe will consider two cases. One in which there is no damping ($b = 0$), and one in which there is damping ($b > 0$).\r\n\r\n\\input{./higherOrder/freeVibrs/freeUndamped.tex}\r\n\\input{./higherOrder/freeVibrs/freeDamped.tex}", "meta": {"hexsha": "545455c77cf2d57e28f154bb6be51e7a744f14d2", "size": 1333, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/freeVibrs/freeVibrs.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/freeVibrs/freeVibrs.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/freeVibrs/freeVibrs.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.5909090909, "max_line_length": 214, "alphanum_fraction": 0.7179294824, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6770456982871711}}
{"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*{covSEard.m} \n\n\\begin{par}\nSquared Exponential covariance function with Automatic Relevance Detemination (ARD) distance measure. The covariance function is parameterized as:\n\\end{par} \\vspace{1em}\n\\begin{par}\nk(x\\^{}p,x\\^{}q) = sf2 * exp(-(x\\^{}p - x\\^{}q)'*inv(P)*(x\\^{}p - x\\^{}q)/2)\n\\end{par} \\vspace{1em}\n\\begin{par}\nwhere the P matrix is diagonal with ARD parameters ell\\_1\\^{}2,...,ell\\_D\\^{}2, where D is the dimension of the input space and sf2 is the signal variance. The hyperparameters are:\n\\end{par} \\vspace{1em}\n\\begin{par}\nloghyper = [ log(ell\\_1)              log(ell\\_2)               .              log(ell\\_D)              log(sqrt(sf2)) ]\n\\end{par} \\vspace{1em}\n\\begin{par}\nFor more help on design of covariance functions, try \"help covFunctions\".\n\\end{par} \\vspace{1em}\n\\begin{par}\n(C) Copyright 2006 by Carl Edward Rasmussen (2006-03-24)\n\\end{par} \\vspace{1em}\n\n\\begin{lstlisting}\nfunction [A, B] = covSEard(loghyper, x, z)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\nif nargin == 0, A = '(D+1)'; return; end          % report number of parameters\n\npersistent K;\n\n[n D] = size(x);\nell = exp(loghyper(1:D));                         % characteristic length scale\nsf2 = exp(2*loghyper(D+1));                                   % signal variance\n\nif nargin == 2\n  K = sf2*exp(-sq_dist(diag(1./ell)*x')/2);\n  A = K;\nelseif nargout == 2                              % compute test set covariances\n  A = sf2*ones(size(z,1),1);\n  B = sf2*exp(-sq_dist(diag(1./ell)*x',diag(1./ell)*z')/2);\nelse                                                % compute derivative matrix\n\n  % check for correct dimension of the previously calculated kernel matrix\n  if any(size(K)~=n)\n    K = sf2*exp(-sq_dist(diag(1./ell)*x')/2);\n  end\n\n  if z <= D                                           % length scale parameters\n    A = K.*sq_dist(x(:,z)'/ell(z));\n  else                                                    % magnitude parameter\n    A = 2*K;\n    clear K;\n  end\nend\n\\end{lstlisting}\n", "meta": {"hexsha": "0b1b7f5df6c0baa192f681194f70df4a930e89e6", "size": 2146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/covSEard.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/covSEard.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/covSEard.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": 31.1014492754, "max_line_length": 180, "alphanum_fraction": 0.5773532153, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6769810183486457}}
{"text": "% !TeX root = ../main.tex\n\n\\section{Introduction}\nThe earliest algorithms developed in recommender systems were\nneighborhood-based collaborative filtering algorithms. These algorithms\nutilize the similarities between either of users or items, based on the ratings.\nThe data in a recommender system can be presented as a matrix called the ratings\nmatrix($\\mathcal{R}$).\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{ |c|c|c|c|c| }\n\\hline\n\\diagbox{$User$}{$Item$} & \\textbf{$Item_1$} & \\textbf{$Item_2$} & \\textbf{$Item_3$} & \\textbf{$Item_4$} \\\\\n\\hline\n\\textbf{$User_1$} & 5 & 2 & \\textbf{?} & 3 \\\\\n\\hline\n\\textbf{$User_2$} & 1 & \\textbf{?} & 4 & 2 \\\\\n\\hline\n\\textbf{$User_3$} & \\textbf{?}  & 3 & 5 & 4 \\\\\n\\hline\n\\textbf{$User_4$} & 5 & 2 & 3 &  \\textbf{?} \\\\\n\\hline\n\\textbf{$User_5$} & 1 & \\textbf{?}  & 2 & 4 \\\\\n\\hline\n\\textbf{$User_6$} & 3 & 5 & \\textbf{?}  & 3 \\\\\n\\hline\n\\textbf{$User_7$} & 3 & 1 & \\textbf{?}  & 5 \\\\\n\\hline\n\\end{tabular}\n\\caption{Ratings Matrix}\n\\label{table:Ratings Matrix}\n\\end{table}\n\n\\justify\nThe rows of the matrix represent users($\\mathcal{U}$) and the\ncolumns represent items($\\mathcal{I}$). A rating($r$) is a number in this case an integer in\nthe range [1 - 5] that a user has given to an item, where 1 means that\nthe users totally disliked the item and 5 that the user totally liked the item. The missing ratings are those\nthat the users haven't reviewed yet and also where the rating predictions apply.\nThe known ratings are used for the similarity computations and therefore for\nthe rating predictions. There are two types of neighborhood-based algorithms:\n\\begin{itemize}\n\t\\item \\textbf{User-based CF:}  This type utilizes the ratings matrix\n\trow-wise meaning the recommender system is trying to find similar patterns\n\tbetween users. Given the ratings matrix, to predict the rating that\n\t$User_4$ would give to $Item_4$ first it would try to find users\n\tthat have rated $Item_4$ and out of these users to select those\n\t(also called nearest neighbors) who have liked similar items with $User_4$\n\tin the past. Then based on the most similar nearest neighbors to $User_4$\n\ta prediction would be computed as an aggregation of the target user's nearest neighbors\n\tratings. This method assumes two things. The first one is that if users\n\thad similar interests in the past they will have similar interests in the future.\n\tThe second assumption is that user preferences remain stable and\n\tconsistent over time. \\citep{Jannach}\n\n\t\\item \\textbf{Item-based CF:} This type utilizes the ratings matrix\n\tcolumn-wise and it is trying to find patterns between the items. Again\n\tfrom the ratings matrix, to predict the rating that $User_4$ would give to\n\t$Item_4$ it would try to find other items, that this user has rated. The\n\trating prediction would  be an aggregation of the ratings of the most similar\n\titems between those and $Item_4$. Item-based CF is considered a more viable approach in\n\treal cases for two reasons. The first reason is that the items are usually far\n\tless than the users\tin the system. This reduces both the computation\n\ttime and storage needed for the similarities. The second reason is that\n\tusers tend to rate a small proportion of items, which distorts the\n\tuser similarities because of the sparseness. Instead, each item accumulates more\n\tratings, as items are less than users, which makes item-based\n\tsimilarities more reliable.\\citep{sarwar2001item}\n\\end{itemize}\nThe main advantages of the neighborhood-based algorithms\\citep{Ricci} are:\n\\begin{itemize}\n\t\\item \\textbf{Simplicity:} To implement a neighborhood-based algorithm\n\tthe only factor that is considered is the ratings in the matrix in order\n\tto find similarities.\n\t\\item \\textbf{Justifiability:} It is very clear how the rating\n\tpredictions were computed and why it makes sense from the data as the\n\tsimilarities that gave these predictions can be provided to the users, so\n\tas to justify their relevance.\n\t\\item \\textbf{Efficiency:} The training cost in neighbor-based methods\n\tconsists only of the similarity pre-computations between users or items\n\twhich can be computed offline in the ratings matrix which is much cheaper than\n\tmost model-based training. Offline learning means that the system\n\twill not adapt immediately to any change. Instead it must recompute\n\tthe similarities from scratch. Moreover, storing only the nearest neighbors\n\tin memory requires only a little use of RAM, instead of storing every user\n\twhich could form a similarity with the active user.\n\t\\item \\textbf{Stability:} In large scale recommenders systems, typically in\n\titem-based approach, it is observed that the addition of users, items and ratings slightly\n\taffect the decisions of the system after item similarities have been computed.\n\tThat means that the RS would not need further re-training to make better recommendations.\n\tAlso when new items enter the system, they can be trained solely without affecting other items'\n\texisting similarities.\n\\end{itemize}\n\nAs discussed in the previous chapter, neighborhood-based algorithms suffer from the sparsity of\nthe ratings matrix. When the similarities are calculated from\nonly a few common ratings between, e.g. two items, this often leads to\nan ambiguous similarity score that can produce spurious predictions.\nAnother symptom of sparseness is that sometimes no similarities between\nitems or users can be found and this inability leaves those items or users\nwithout neighbors. Thus, without neighbors they won't participate in\nthe rating prediction process which means that the RS won't be able to provide\nrecommendations for those entities.\n\nIn \\autoref{sec:2.2} different similarity metrics will be discussed.\nIn \\autoref{sec:2.3} The KNN algorithm will be explained and a full example will be\ndemonstrated for further clarification.\n\n\\section{Similarity Metrics}\\label{sec:2.2}\nThe most important part in a neighborhood-based CF approach is the computation of\nthe similarities which, as we discussed above, can be user-based or item-based.\nBelow, different similarity metrics will be mentioned. Some of them are widely known metrics\nin the literature. These are Cosine Similarity, Pearson Correlation Coefficient,\nAdjusted Cosine Similarity, Mean Absolute Difference, Mean Squared Difference and\nJaccard Coefficient. The rest of them are modifications\nof the original metrics that we introduce and do not exist in the literature.\nThese are the Modified Cosine Similarity, Modified Adjusted Cosine Similarity,\nModified Pearson Correlation Coefficient 1 and Modified Pearson Correlation Coefficient 2.\nSome of the widely known similarity metrics have been introduced as a user-based approach\nand others as item-based. In this thesis we will define each similarity metric both for\nuser-based and item-based. Also we will assume that the values of the ratings matrix\nconsist of integers in the interval [1, 5] in order to define the interval for\neach similarity metric.\n\\subsection{Mathematical Notation}\nFor consistency over the similarity metrics formulas that will be defined next,\na global mathematical notation is used for the rest of this section.\nUppercase $\\mathcal{I}$ is used to denote the set of items in the system.\nThe notation $\\mathcal{I}_u$ is the set of items that have been rated by\nuser $u$, $\\mathcal{I}_v$ is the set of items that have been rated by\nuser $v$ and $\\mathcal{I}_{uv}$ is $\\mathcal{I}_u \\cap \\mathcal{I}_v$ that is the set of items that users $u$ and $v$ have\nrated in common.\nSimilarly, uppercase $\\mathcal{U}$ is used to denote the set of users in the system.\n$\\mathcal{U}_i$ is the set of users that have rated\nitem $i$, $\\mathcal{U}_j$ is the set of users that have rated\nitem $j$ and $\\mathcal{U}_{ij}$ is $\\mathcal{U}_i \\cap \\mathcal{U}_j$ that is the set of users that have rated both\nitems $i$ and $j$. The notation $\\mathopen|\\mathcal{I}_{u}\\mathclose|$ denotes\nthe number of items user $u$ has rated, $\\mathopen|\\mathcal{I}_{v}\\mathclose|$\ndenotes the number of items user $v$ has rated, and $\\mathopen|\\mathcal{I}_{uv}\\mathclose|$\nis the number of items that users $u$ and $v$ have rated in common. Likewise,\n$\\mathopen|\\mathcal{U}_{i}\\mathclose|$ denotes the number of users that have\nrated item $i$, $\\mathopen|\\mathcal{U}_{j}\\mathclose|$ denotes the number of users that have rated\nitem $j$, and $\\mathopen|\\mathcal{U}_{ij}\\mathclose|$ is the number of users that\nhave both rated items $i$ annd $j$.\n$r_{ui}$ is the rating that user $u$ gave to item $i$ and\n$r_{vi}$ the rating that user $v$ gave to item $i$.\n$r_{iu}$ is the rating item $i$ received from user $u$ and\n$r_{ju}$ the rating item $j$ received from user $u$.\n\n\\subsection{Cosine similarity}\nCosine similarity is a metric that measures the cosine of the angle that two vectors form.\nThis metric can take any value in the interval [-1, 1], but specifically for our\nown case where the ratings matrix is defined in the interval [1, 5], this\nmetric is defined in the interval [0, 1].\\\\\\\\\nUser-based cosine similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:cosine}\n    cos(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}r_{ui}r_{vi}}\n\t\t    {\\sqrt{\\sum_{i \\in \\mathcal{I}_{u}}r_{ui}^2}\n\t\t     \\sqrt{\\sum_{i \\in \\mathcal{I}_{v}}r_{vi}^2}}\n\\end{equation}\nThe largest the similarity value the higher is chance that these users rate by the same way.\nA zero similarity score indicates that $u$ and $v$ have no items in common and therefore\nthey have no similarity.\\\\\\\\\nFrom \\autoref{table:Ratings Matrix}, the cosine similarity\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\ncos(User_1,User_3) = \\frac{2*3 + 3*4}\n\t\t\t\t\t\t{\\sqrt{5^2 + 2^2 + 3^2} * \\sqrt{3^2 + 5^2 + 4^2}} = 0.4129\n\\end{align*}\nSimilarly, instead of using the row vectors to calculate the similarity between users,\ncolumn vectors can be used to calculate the similarity between item pairs.\\\\\\\\\nItem-based cosine similarity between items $i$ and $j$ is defined as:\n\\begin{equation}\n    cos(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}r_{iu}r_{ju}}\n\t\t    {\\sqrt{\\sum_{u \\in \\mathcal{U}_{i}}r_{iu}^2}\n\t\t     \\sqrt{\\sum_{u \\in \\mathcal{U}_{j}}r_{ju}^2}}\n\\end{equation}\nAgain from \\autoref{table:Ratings Matrix}, the cosine similarity\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\begin{align*}\ncos(Item_2,Item_3) = \\frac{3*5 + 2*3}\n\t\t\t\t\t\t{\\sqrt{2^2 + 3^2 + 2^2 + 5^2 + 1^2} * \\sqrt{4^2 + 5^2 + 3^2 + 2^2}} = 0.4358\n\\end{align*}\n\\subsection{Modified Cosine Similarity}\nModified cosine similarity differs from the standard cosine similarity in the\nsense that the computations in the denominator apply only to the common items\nbetween $u$ and $v$.\nIts values are defined in the interval [0, 1].\\\\\\\\\nUser-based modified cosine similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:modified_cosine}\n    MC(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}r_{ui}r_{vi}}\n\t\t   {\\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}r_{ui}^2}\n                    \\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}r_{vi}^2}}\n\\end{equation}\nFrom \\autoref{table:Ratings Matrix}, MC\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\nMC(User_1,User_3) = \\frac{2*3 + 3*4}\n\t\t\t\t\t   {\\sqrt{2^2 + 3^2} * \\sqrt{3^2 + 4^2}} = 0.9984\n\\end{align*}\nWe can reverse the above formula in order to calculate the similarities\nin terms of items.\\\\\nItem-based modified cosine similarity between items $i$ and $j$ is defined as:\n\\begin{equation}\n    MC(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}r_{iu}r_{ju}}\n   {\\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}r_{iu}^2}\n            \\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}r_{ju}^2}}\n\\end{equation}\nFrom \\autoref{table:Ratings Matrix}, MC\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\begin{align*}\nMC(Item_2,Item_3) = \\frac{3*5 + 2*3}\n\t\t\t\t\t\t{\\sqrt{3^2 + 2^2} * \\sqrt{5^2 + 3^2}} = 0.9988\n\\end{align*}\n\\subsection{Adjusted Cosine Similarity}\nAdjusted cosine similarity was originally created as an\nitem-based approach. The reason for that was because each item vector consists of\nusers who have different rating behaviors and cosine similarity did not\ntake into account these disparities. That means that a user could use the\nrating 3 for items that really liked and 1 for items that really disliked while\nanother user could give a 5 rating to items that really liked and 1 to them that really\ndisliked. Adjusted cosine similarity is computed by looking into the co-rated items\n($\\mathcal{U}_{ij}$) only. It normalizes each user's rating behavior by\nsubtracting the corresponding user's mean value \\citep{sarwar2001item}.\nAdjusted cosine similarity values are defined in the interval [-1, 1].\nThe value -1 means perfect dissimilarity between two items while the value 1 means\nperfect similarity. The zero value means there is no similarity between these items.\\\\\\\\\nItem-based adjusted cosine similarity between items $i$ and $j$ is defined as:\n\\begin{equation}\\label{eq:adjusted_cosine}\n    \\begin{split}\n    &AC(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\bar{r_{u}})(r_{ju}-\\bar{r_{u}})}\n\t\t    {\\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\bar{r_{u}})^2}\n                     \\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{ju}-\\bar{r_{u}})^2}} \\\\\\\\\n    &\\bar{r_{u}} = \\frac{\\sum_{i \\in \\mathcal{I}_u}r_{ui}}\n \t\t        {\\mathopen|\\mathcal{I}_u\\mathclose|}\n    \\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_u}$ is the mean value of user $u$ for each $u \\in \\mathcal{U}_{ij}$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, AC\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{User_3} = \\frac{3 + 5 + 4}{3} = 4\\\\\n\t\t&\\bar{r}_{User_4} = \\frac{5 + 2 + 3}{3} = 3.33\n\t\\end{split}\n\\end{align*}\n$$AC(Item_2,Item_3) = \\frac{(3 - 4)*(5 - 4) + (2 - 3.33)*(3 - 3.33)}\n\t\t\t\t\t\t {\\sqrt{(3 - 4)^2 + (2 - 3.33)^2}*\n\t\t\t\t\t\t  \\sqrt{(5 - 4)^2 + (3 - 3.33)^2}} = −0.3202$$\nThe result $-0.3202$ means that $Item_2$ and $Item_3$ are somewhat dissimilar.\\\\\\\\\nWe could use the same reasoning adjusted cosine was build on,\nto look at this formula from a user-based perspective. That is, if an item's\nlowest rating is 3 and its highest rating is 5, that means that it is treated\ndifferently than an item that its lowest rating is 1 and the highest 4.\nTherefore, we could have each co-rated item, by two users, mean centered by the corresponding item\nand calculate a user-based adjusted cosine similarity.\\\\\\\\\nUser-based adjusted cosine similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\n\\begin{split}\n    &AC(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\bar{r_{i}})(r_{vi}-\\bar{r_{i}})}\n\t\t    {\\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\bar{r_{i}})^2}\n                     \\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{vi}-\\bar{r_{i}})^2}} \\\\\\\\\n    &\\bar{r_{i}} = \\frac{\\sum_{u \\in \\mathcal{U}_i}r_{iu}}\n \t\t        {\\mathopen|\\mathcal{U}_i\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_i}$ is the mean value of item $i$ for each $i \\in \\mathcal{I}_{uv}$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, AC\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{Item_2} = \\frac{2 + 3 + 2 + 5 + 1}{5} = 2.6\\\\\n\t\t&\\bar{r}_{Item_4} = \\frac{3 + 2 + 4 + 4 + 3 + 5}{6} = 3.5\n\t\\end{split}\n\\end{align*}\n$$AC(User_1,User_3) = \\frac{(2 - 2.6)*(3 - 2.6) + (3 - 3.5)*(4 - 3.5)}\n\t\t\t\t\t\t {\\sqrt{(2 - 2.6)^2 + (3 - 3.5)^2}*\n\t\t\t\t\t\t  \\sqrt{(3 - 2.6)^2 + (4 - 3.5)^2}} = −0.9798$$\n$User_1$ and $User_3$ are almost perfectly dissimilar.\n\\subsection{Modified Adjusted Cosine Similarity}\nA modification to adjusted cosine similarity that we implemented was to\nuse every user corresponding to $i$ and $j$ instead of using\nonly the users that have rated both items in the denominator. Its values are also in the interval [-1, 1].\\\\\\\\\nItem-based modified adjusted cosine similarity between items $i$ and $j$ is defined as:\n\\begin{equation}\n\\begin{split}\n&MAC(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\bar{r_{u}})(r_{ju}-\\bar{r_{u}})}\n\t\t\t\t {\\sqrt{\\sum_{u \\in \\mathcal{U}_{i}}(r_{iu}-\\bar{r_{u}})^2}\n\t\t\t\t  \\sqrt{\\sum_{u \\in \\mathcal{U}_{j}}(r_{ju}-\\bar{r_{u}})^2}} \\\\\\\\\n&\\bar{r_{u}} = \\frac{\\sum_{i \\in \\mathcal{I}_u}r_{ui}}\n\t\t\t\t\t{\\mathopen|\\mathcal{I}_u\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_u}$ is the mean value of user $u$ for each $u \\in \\mathcal{U}_{ij}$ in the numerator\n\t\\item[] $\\bar{r_u}$ is the mean value of user $u$ for each $u \\in \\mathcal{U}_{i}$ and $u \\in \\mathcal{U}_{j}$ respectively in the denominator\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, MAC\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\footnotesize\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{User_1} = \\frac{5 + 2 + 3}{3} = 3.33\\\\\n\t\t&\\bar{r}_{User_2} = \\frac{1 + 4 + 2}{3} = 2.33\\\\\n\t\t&\\bar{r}_{User_3} = \\frac{3 + 5 + 4}{3} = 4\\\\\n\t\t&\\bar{r}_{User_4} = \\frac{5 + 2 + 3}{3} = 3.33\\\\\n\t\t&\\bar{r}_{User_5} = \\frac{1 + 2 + 4}{3} = 2.33\\\\\n\t\t&\\bar{r}_{User_6} = \\frac{3 + 5 + 3}{3} = 3.66\\\\\n\t\t&\\bar{r}_{User_7} = \\frac{3 + 1 + 5}{3} = 3\\\\\\\\\n&MAC(Item_2,Item_3) = \\\\&\\frac{(3 - 4)*(5 - 4) + (2 - 3.33)*(3 - 3.33)}\n\t\t\t\t\t\t {\\sqrt{(2 - 3.33)^2 + (3 - 4)^2 + (2 - 3.33)^2 + (5 - 3.66)^2 + (1 - 3)^2}*\n\t\t\t\t\t\t  \\sqrt{(4 - 2.33)^2 + (5 - 4)^2 + (3 - 3.33)^2 + (2 - 2.33)^2}} \\\\&= −0,0872\n  \\end{split}\n\\end{align*}\n\\normalsize\nCompared to item-based AC the item-based MAC between $Item_2$ and $Item_3$ still generates\na negative similarity but it is very close to zero this time as it takes into account each\nitem's vector length.\\\\\\\\\nAs previously mentioned a user-based approach can also be implemented.\\\\\nUser-based modified adjusted cosine similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:modified_adjusted_cosine}\n\\begin{split}\n    &MAC(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\bar{r_{i}})(r_{vi}-\\bar{r_{i}})}\n                     {\\sqrt{\\sum_{i \\in \\mathcal{I}_{u}}(r_{ui}-\\bar{r_{i}})^2}\n                      \\sqrt{\\sum_{i \\in \\mathcal{I}_{v}}(r_{vi}-\\bar{r_{i}})^2}} \\\\\\\\\n    &\\bar{r_{i}} = \\frac{\\sum_{u \\in \\mathcal{U}_i}r_{iu}}\n                        {\\mathopen|\\mathcal{U}_i\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_i}$ is the mean value of user $u$ for each $u \\in \\mathcal{I}_{uv}$ in the numerator\n\t\\item[] $\\bar{r_i}$ is the mean value of user $u$ for each $u \\in \\mathcal{I}_{u}$ and $u \\in \\mathcal{I}_{v}$ respectively in the denominator\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, MAC\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{Item_1} = 3\\\\\n\t\t&\\bar{r}_{Item_2}  = 2.6\\\\\n\t\t&\\bar{r}_{Item_3} = 3.5\\\\\n\t\t&\\bar{r}_{Item_4} = 3.5\\\\\\\\\nMAC(User_1,User_3) &= \\frac{(2 - 2.6)*(3 - 2.6) + (3 - 3.5)*(4 - 3.5)}\n\t\t\t\t\t\t {\\sqrt{(5 - 3)^2 + (2 - 2.6)^2 + (3 - 3.5)^2}*\n\t\t\t\t\t\t  \\sqrt{(3 - 2.6)^2 + (5 - 3.5)^2 + (4 - 3.5)^2}} \\\\&= −0.1399\n  \\end{split}\n\\end{align*}\nCompared to user-based AC, the user-based MAC between $User_1$ and $User_3$ still generates\na negative similarity but it is far weaker than AC's as it takes into account the length of\neach user's vector.\n\\subsection{Pearson Correlation Coefficient}\nUsers do not always rate in the same way. One user might never use a rating of 5\nfor items that really likes.\nAnother user might never rate an item below 3 for items that really dislikes.\nA third user might only use a rating of 4 despite of how much he liked an item.\nThis means is that most of the users have a particularity in their\nratings. Due to this user behavior, it is difficult to understand the similarity\nbased on the actual rating. The Pearson correlation coefficient\ncomputes the linear correlation between two users, to alleviate this problem. Linear correlation is\ndefined as the proportion of dependence between two variables X and Y.\nRegarding the similarity between two users, the Pearson correlation coefficient can also be\nthought of as the covariance between two users A and B divided by the standard deviation of\n$User_A$ multiplied by the standard deviation of $User_B$.\\\\\\\\\nUser-based Pearson correlation coefficient between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:pearson}\n\\begin{split}\n    &PCC(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\bar{r_{u}})(r_{vi}-\\bar{r_{v}})}\n                     {\\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\bar{r_{u}})^2}\n                      \\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{vi}-\\bar{r_{v}})^2}} \\\\\\\\\n    &\\bar{r_{u}} = \\frac{\\sum_{i \\in \\mathcal{I}_u}r_{ui}}\n                        {\\mathopen|\\mathcal{I}_u\\mathclose|}\\\\\n    &\\bar{r_{v}} = \\frac{\\sum_{i \\in \\mathcal{I}_v}r_{vi}}\n                        {\\mathopen|\\mathcal{I}_v\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_u}$ is the mean value of user $u$\n\t\\item[] $\\bar{r_v}$ is the mean value of user $v$\n\\end{itemize}\nThe PCC varies between -1 and 1 and based on its value two objects inspected for correlation can\nbe classified as:\n\\begin{itemize}\n\t\\item Positively correlated, when $PCC > 0$\n\t\\item Negatively correlated, when $PCC < 0$\n\t\\item Uncorrelated,  when $PCC = 0$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, PCC\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{User_1} = 3.33\\\\\n\t\t&\\bar{r}_{User_3} = 4\\\\\\\\\n\t\tPCC(User_1,User_3) &= \\frac{(2 - 3.33) * (3 - 4) + (3 - 3.33) * (4 - 4)}\n\t\t\t\t\t\t\t\t  {\\sqrt{(2 - 3.33)^2 + (3 - 3.33)^2} *\n\t\t\t\t\t\t\t\t   \\sqrt{(3 - 4)^2 + (4 - 4)^2}} = 0.9705\n\t\\end{split}\n\\end{align*}\nThus $User_1$ and $User_3$ have a strong positive correlation.\\\\\\\\\nPCC was initially used as a user-based approach\\citep{shardanand1995social} but we will\nreverse it for item-based computations in order to measure the correlation between the items.\\\\\\\\\nItem-based Pearson correlation coefficient between items $i$ and $j$ is defined as:\n\\begin{equation}\n\t\\begin{split}\n\t&PCC(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\bar{r_{i}})(r_{ju}-\\bar{r_{j}})}\n\t\t\t\t\t {\\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\bar{r_{i}})^2}\n\t\t\t\t\t  \\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{ju}-\\bar{r_{j}})^2}} \\\\\\\\\n\t&\\bar{r_{i}} = \\frac{\\sum_{u \\in \\mathcal{U}_i}r_{iu}}\n\t\t\t\t\t\t{\\mathopen|\\mathcal{U}_i\\mathclose|}\\\\\n\t&\\bar{r_{j}} = \\frac{\\sum_{u \\in \\mathcal{U}_j}r_{ju}}\n\t\t\t\t\t\t{\\mathopen|\\mathcal{U}_j\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_i}$ is the mean value of item $i$\n\t\\item[] $\\bar{r_j}$ is the mean value of item $j$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, PCC\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{Item_2} = 2.6\\\\\n\t\t&\\bar{r}_{Item_3} = 3.5\\\\\\\\\n\t\tPCC(Item_2,Item_3) &= \\frac{(3 - 2.6) * (5 - 3.5) + (2 - 2.6) * (3 - 3.5)}\n\t\t\t\t\t\t\t\t  {\\sqrt{(3 - 2.6)^2 + (2 - 2.6)^2} *\n\t\t\t\t\t\t\t\t   \\sqrt{(5 - 3.5)^2 + (3 - 3.5)^2}} = 0.7893\n\t\\end{split}\n\\end{align*}\nThus $Item_2$ and $Item_3$ have a strong positive correlation.\n\\subsection{Modified Pearson Correlation Coefficient 1}\nThe first modification to PCC that we implemented was to average only the ratings that\ntwo users have in common. Its values are in the interval [-1, 1].\\\\\\\\\nUser-based modified Pearson correlation coefficient 1 between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:pearson_1}\n\\begin{split}\n    &MPCC1(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\tilde{r_{u}})(r_{vi}-\\tilde{r_{v}})}\n                       {\\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\tilde{r_{u}})^2}\n                        \\sqrt{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{vi}-\\tilde{r_{v}})^2}} \\\\\\\\\n    &\\tilde{r_{u}} = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}r_{ui}}\n                          {\\mathopen|\\mathcal{I}_{uv}\\mathclose|}\\\\\n    &\\tilde{r_{v}} = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}r_{vi}}\n                          {\\mathopen|\\mathcal{I}_{uv}\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\tilde{r_u}$ is the mean value of user $u$ using only the co-rated items with user $v$\n\t\\item[] $\\tilde{r_v}$ is the mean value of user $v$ using only the co-rated items with user $u$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, MPCC1\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\tilde{r}_{User_1} = \\frac{2 + 3}{2} = 2.5\\\\\n\t\t&\\tilde{r}_{User_3} = \\frac{3 + 4}{2} = 3.5\\\\\\\\\n\t\tMPCC1(User_1,User_3) &= \\frac{(2 - 2.5) * (3 - 3.5) + (3 - 2.5) * (4 - 3.5)}\n\t\t\t\t\t\t\t\t  {\\sqrt{(2 - 2.5)^2 + (3 - 2.5)^2} *\n\t\t\t\t\t\t\t\t   \\sqrt{(3 - 3.5)^2 + (4 - 3.5)^2}} = 1\n\t\\end{split}\n\\end{align*}\nCompared to user-based PCC, the user-based MPCC1 between $User_1$ and $User_3$\nusing the modified mean values yields a perfect correlation.\\\\\\\\\nItem-based modified Pearson correlation coefficient 1 between items $i$ and $j$ is defined as:\n\\begin{equation}\n\t\\begin{split}\n\t&MPCC1(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\tilde{r_{i}})(r_{ju}-\\tilde{r_{j}})}\n\t\t\t\t\t {\\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\tilde{r_{i}})^2}\n\t\t\t\t\t  \\sqrt{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{ju}-\\tilde{r_{j}})^2}} \\\\\\\\\n\t&\\tilde{r_{i}} = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}r_{iu}}\n\t\t\t\t\t\t{\\mathopen|\\mathcal{U}_{ij}\\mathclose|}\\\\\n\t&\\tilde{r_{j}} = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}r_{ju}}\n\t\t\t\t\t\t{\\mathopen|\\mathcal{U}_{ij}\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\tilde{r_i}$ is the mean value of item $i$ using only the common user ratings with item $j$\n\t\\item[] $\\tilde{r_j}$ is the mean value of item $j$ using only the common user ratings with item $i$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, MPCC1\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\tilde{r}_{Item_2} = \\frac{3 + 2}{2} = 2.5\\\\\n\t\t&\\tilde{r}_{Item_3} = \\frac{5 + 3}{2} = 4\\\\\\\\\n\t\tMPCC1(Item_2,Item_3) &= \\frac{(3 - 2,5) * (5 - 4) + (2 - 2,5) * (3 - 4)}\n\t\t\t\t\t\t\t\t  {\\sqrt{(3 - 2,5)^2 + (2 - 2,5)^2} *\n\t\t\t\t\t\t\t\t   \\sqrt{(5 - 4)^2 + (3 - 4)^2}} = 1\n\t\\end{split}\n\\end{align*}\nCompared to item-based PCC, item-based MPCC1 between $Item_2$ and $Item_3$\nusing the modified mean values yields a perfect correlation.\n\\subsection{Modified Pearson Correlation Coefficient 2}\nThe second modification to PCC is to change the denominator\nin a sense that it includes all the items corresponding to $u$ and $v$ respectively.\nIts values are also in the interval [-1, 1].\\\\\\\\\nUser-based modified Pearson correlation coefficient 2 between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:pearson_2}\n\\begin{split}\n    &MPCC2(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-\\bar{r_{u}})(r_{vi}-\\bar{r_{v}})}\n                       {\\sqrt{\\sum_{i \\in \\mathcal{I}_{u}}(r_{ui}-\\bar{r_{u}})^2}\n                        \\sqrt{\\sum_{i \\in \\mathcal{I}_{v}}(r_{vi}-\\bar{r_{v}})^2}} \\\\\\\\\n    &\\bar{r_{u}} = \\frac{\\sum_{i \\in \\mathcal{I}_u}r_{ui}}\n                        {\\mathopen|\\mathcal{I}_u\\mathclose|}\\\\\n    &\\bar{r_{v}} = \\frac{\\sum_{i \\in \\mathcal{I}_v}r_{vi}}\n                        {\\mathopen|\\mathcal{I}_v\\mathclose|}\n\\end{split}\n\\end{equation}\nwhere,\n\\begin{itemize}\n\t\\item[] $\\bar{r_u}$ is the mean value of user $u$\n\t\\item[] $\\bar{r_v}$ is the mean value of user $v$\n\\end{itemize}\nFrom \\autoref{table:Ratings Matrix}, MPCC2\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{User_1} = 3.33\\\\\n\t\t&\\bar{r}_{User_3} = 4\\\\\\\\\n\t\tMPCC2(User_1,User_3) &= \\frac{(2 - 3.33) * (3 - 4) + (3 - 3.33) * (4 - 4)}\n\t\t\t\t\t\t\t\t  {\\sqrt{(5 - 3.33)^2 + (2 - 3.33)^2 + (3 - 3.33)^2} *\n\t\t\t\t\t\t\t\t   \\sqrt{(3 - 4)^2 + (5 - 4)^2 + (4 - 4)^2}} = 0.4353\n\t\\end{split}\n\\end{align*}\nCompared to user-based PCC, the user-based MPCC2 between $User_1$ and $User_3$\nretained a positive correlation but it has significantly decreased as it now\ntakes into account the mean centered length of each user's vector.\\\\\\\\\nItem-based modified Pearson correlation coefficient 2 between items $i$ and $j$ is defined as:\n\\begin{equation}\n\t\\begin{split}\n\t&MPCC2(i,j) = \\frac{\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-\\bar{r_{i}})(r_{ju}-\\bar{r_{j}})}\n\t\t\t\t\t {\\sqrt{\\sum_{u \\in \\mathcal{U}_{i}}(r_{iu}-\\bar{r_{i}})^2}\n\t\t\t\t\t  \\sqrt{\\sum_{u \\in \\mathcal{U}_{j}}(r_{ju}-\\bar{r_{j}})^2}} \\\\\\\\\n\t&\\bar{r_{i}} = \\frac{\\sum_{u \\in \\mathcal{U}_i}r_{iu}}\n\t\t\t\t\t\t{\\mathopen|\\mathcal{U}_i\\mathclose|}\\\\\n\t&\\bar{r_{j}} = \\frac{\\sum_{u \\in \\mathcal{U}_j}r_{ju}}\n\t\t\t\t\t\t{\\mathopen|\\mathcal{U}_j\\mathclose|}\n\\end{split}\n\\end{equation}\nFrom \\autoref{table:Ratings Matrix}, MPCC2\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n\\footnotesize\n\\begin{align*}\n\t\\begin{split}\n\t\t&\\bar{r}_{Item_2} = 2.6\\\\\n\t\t&\\bar{r}_{Item_3} = 3.5\\\\\\\\\n\t\t&MPCC2(Item_2,Item_3) = \\\\&\\frac{(3 - 2,6) * (5 - 3,5) + (2 - 2,6) * (3 - 3,5)}\n\t\t\t\t\t\t\t\t  {\\sqrt{(2 - 2,6)^2 + (3 - 2,6)^2 + (2 - 2,6)^2 + (5 - 2,6)^2 + (1 - 2,6)^2 } *\n\t\t\t\t\t\t\t\t   \\sqrt{(4 - 3,5)^2 + (5 - 3,5)^2 + (3 - 3,5)^2 + (2 - 3,5)^2 }} = 0,1327\n\t\\end{split}\n\\end{align*}\n\\normalsize\nCompared to item-based PCC, item-based MPCC2 between $Item_2$ and $Item_3$\nretained a positive correlation but it has significantly decreased as it now\ntakes into account the mean centered length of each item's vector.\n\\subsection{Mean Squared Difference Similarity}\nMean squared difference\\citep{shardanand1995social} is a very simple metric.\n\\begin{equation}\\label{eq:msd}\n    MSD(u,v) = \\frac{\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-r_{vi})^2}\n\t\t\t\t\t{\\mathopen|\\mathcal{I}_{uv}\\mathclose|}\n\\end{equation}\nIt designates the degree of dissimilarity between $u$ and $v$ by aggregating the squared differences\nbetween the ratings on the rated items they have in common.\nIf we reverse the numerator with the denominator it designates the degree\nof the similarity between $u$ and $v$ instead.\\\\\\\\\nUser-based mean squared difference similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\n    MSD(u,v) = \\frac{\\mathopen|\\mathcal{I}_{uv}\\mathclose|}\n                    {\\sum_{i \\in \\mathcal{I}_{uv}}(r_{ui}-r_{vi})^2}\n\\end{equation}\nIts values are in the\ninterval (0, $\\mathopen|\\mathcal{I}_{uv}\\mathclose|$] in user-based approach. There\nis a chance $u$ and $v$ have given exactly the same ratings to each common item between them. In that case MSD similarity\nis not defined. That can also be interpreted as $u$ and $v$ have zero dissimilarity.\\\\\\\\\nFrom \\autoref{table:Ratings Matrix}, MSD\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n$$MSD(User_1,User_3) = \\frac{2}{(2 - 3)^2 + (3 - 4)^2} = 1$$\\\\\nThe maximum similarity between $User_1$ and $User_3$ could be 2. They have\nsimilarity 1 which means that they are rating somewhat by the same way.\\\\\nItem-based mean squared difference similarity between items $i$ and $j$ is defined as:\n\\begin{equation}\n        MSD(i,j) = \\frac{\\mathopen|\\mathcal{U}_{ij}\\mathclose|}\n                        {\\sum_{u \\in \\mathcal{U}_{ij}}(r_{iu}-r_{ju})^2}\n\\end{equation}\nIts values are in the interval (0, $\\mathopen|\\mathcal{U}_{ij}\\mathclose|$] in item-based approach.\\\\\\\\\nFrom \\autoref{table:Ratings Matrix}, MSD\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n$$MSD(Item_2,Item_3) = \\frac{2}{(3 - 5)^2 + (2 - 3)^2} = 0.4$$\\\\\nThe maximum similarity between $Item_2$ and $Item_3$ could be 2. They have\nsimilarity 0.4 which means that these items are not rated similarly.\n\\subsection{Mean Absolute Difference Similarity}\nAnother very similar metric to MSD, is mean absolute difference similarity.\nIts difference from the previous method is that it uses the absolute value of\nthe difference between the ratings of $u$ and $v$ instead of squaring them.\nWhen big differences between the ratings exist, MSD is significantly penalized when squaring the values.\nFor that reason, using the absolute values helps in moderating the penalty.\\\\\\\\\nUser-based mean absolute difference similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:mad}\n    MAD(u,v) = \\frac{\\mathopen|\\mathcal{I}_{uv}\\mathclose|}\n                    {\\sum_{i \\in \\mathcal{I}_{uv}}\\mathopen|r_{ui}-r_{vi}\\mathclose|}\n\\end{equation}\nIts values are in the\ninterval (0, $\\mathopen|\\mathcal{I}_{uv}\\mathclose|$] in user-based approach.\\\\\\\\\nFrom \\autoref{table:Ratings Matrix}, MAD\nbetween $User_1$ and $User_3$ would thus be computed as follows:\n$$MAD(User_1,User_3) = \\frac{2}{\\mathopen|2 - 3\\mathclose| + \\mathopen|3 - 4\\mathclose|} = 1$$\\\\\\\\\nItem-based mean absolute difference between items $i$ and $j$ is defined as:\n\\begin{equation}\nMAD(i,j) = \\frac{\\mathopen|\\mathcal{U}_{ij}\\mathclose|}\n\t\t\t\t{\\sum_{u \\in \\mathcal{U}_{ij}}\\mathopen|r_{iu}-r_{ju}\\mathclose|}\n\\end{equation}\nIts values are in the interval (0, $\\mathopen|\\mathcal{U}_{ij}\\mathclose|$] in item-based approach.\\\\\\\\\nFrom \\autoref{table:Ratings Matrix}, MAD\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n$$MAD(Item_2,Item_3) = \\frac{2}{\\mathopen|3 - 5\\mathclose| + \\mathopen|2 - 3\\mathclose|} = 0.4$$\\\\\n\\subsection{Jaccard Coefficient}\nJaccard coefficient measures the overlap of the ratings between two users.\nThis similarity metric does not use the rating scores that the users have given, but counts\nhow many common items they have have rated $\\mathopen|\\mathcal{I}_{uv}\\mathclose|$, and how many distinct\nitems have rated together in total $\\mathopen|\\mathcal{I}_u\\mathclose| \\cup \\mathopen|\\mathcal{I}_v\\mathclose| = \\mathopen|\\mathcal{I}_{u}\\mathclose| +\n\\mathopen|\\mathcal{I}_{v}\\mathclose| - \\mathopen|\\mathcal{I}_{uv}\\mathclose|$.\nIts values are in the interval [0, 1].\\\\\\\\\nUser-based mean absolute difference similarity between users $u$ and $v$ is defined as:\n\\begin{equation}\\label{eq:jaccard}\n    J(u,v) = \\frac{\\mathopen|\\mathcal{I}_{uv}\\mathclose|}\n                  {\\mathopen|\\mathcal{I}_{u}\\mathclose| +\n\t\t   \\mathopen|\\mathcal{I}_{v}\\mathclose| -\n\t\t   \\mathopen|\\mathcal{I}_{uv}\\mathclose|}\n\\end{equation}\nThe table below is an extension of\n\\autoref{table:Ratings Matrix} for $User_1$ and $User_7$ for demonstration purpose.\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{ |c|c|c|c|c|c|c| }\n\\hline\n\\diagbox{User}{Item} & \\textbf{$Item_1$} & \\textbf{$Item_2$} & \\textbf{$Item_3$} & \\textbf{$Item_4$} & \\textbf{$Item_5$} & \\textbf{$Item_6$} \\\\\n\\hline\n\\textbf{$User_1$} & 5 & 2 & \\textbf{?}  & 3 & \\textbf{?} & \\textbf{?}  \\\\\n\\hline\n\\textbf{$User_7$} & 3 & 1 & \\textbf{?} & 5 & 2 & 4 \\\\\n\\hline\n\\end{tabular}\n\\caption{$User_1$ and $User_7$ extended vectors}\n\\label{table:jaccard_example1}\n\\end{table}\nThe first step is to transform the ratings vector between two users to ones and zeros. Ones are the existing ratings and zeros are the ratings that are missing.\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{ |c|c|c|c|c|c|c| }\n\\hline\n\\diagbox{User}{Item} & \\textbf{$Item_1$} & \\textbf{$Item_2$} & \\textbf{$Item_3$} & \\textbf{$Item_4$} & \\textbf{$Item_5$} & \\textbf{$Item_6$} \\\\\n\\hline\n\\textbf{$User_1$} & 1 & 1 & 0 & 1 & 0 & 0 \\\\\n\\hline\n\\textbf{$User_7$} & 1 & 1 & 0 & 1 & 1 & 1 \\\\\n\\hline\n\\end{tabular}\n\\caption{$User_1$ and $User_7$ vectors transformed}\n\\label{table:jaccard_example2}\n\\end{table}\nThen count the amount of items $u$ and $v$ have rated in common $\\mathopen|\\mathcal{I}_{uv}\\mathclose|$, in this example $User_1$ and $User_7$,\ndivided by the amount of their items union $\\mathopen|\\mathcal{I}_u\\mathclose| \\cup \\mathopen|\\mathcal{I}_v\\mathclose|$.\n$$J(User_1,User_7) = \\frac{3}{3 + 5 - 3} = 0.6$$\\\\\\\\\nSimilarly, this metric can be used for item-based similarities.\\\\\nItem-based mean absolute difference between items $i$ and $j$ is defined as:\n\\begin{equation}\nJ(i,j) = \\frac{\\mathopen|\\mathcal{U}_{ij}\\mathclose|}\n\t\t  {\\mathopen|\\mathcal{U}_{i}\\mathclose| +\n   \\mathopen|\\mathcal{U}_{j}\\mathclose| -\n   \\mathopen|\\mathcal{U}_{ij}\\mathclose|}\n\\end{equation}\nFrom \\autoref{table:Ratings Matrix}, Jaccard coefficient\nbetween $Item_2$ and $Item_3$ would thus be computed as follows:\n$$J(Item_2,Item_3) = \\frac{2}{5 + 4 - 2} = 0.2857$$\n\\section{K-Nearest Neighbors Algorithm}\\label{sec:2.3}\nThe K-Nearest Neighbors algorithm is a very straightforward technique.\nIn a user-based KNN setting, in order to predict the rating of $User_A$ for an\n$Item_B$ not rated by $User_A$, KNN consists of the following steps:\n\\begin{itemize}\n\t\\item[] \\textbf{Step 1:} Find users that have rated $Item_B$.\n\t\\item[] \\textbf{Step 2:} Compute the similarities between $User_A$ and the users that have\n\trated $Item_B$.\n\t\\item[] \\textbf{Step 3:}  Sort that similarities in descending order.\n\t\\item[] \\textbf{Step 4:}  Choose how many neighbors will contribute in the rating\n\tprediction by selecting the top $\\mathcal{K}$ out of all the available\n\tneighbors($\\mathcal{K}$ can be in range [1 - $\\mathcal{N}$] where $\\mathcal{N}$ is all\n\tthe available neighbors).\n\t\\item[] \\textbf{Step 5:} Use an aggregation formula to calculate the rating prediction of\n\t$User_A$ to $Item_B$. In this case the weighted sum \\citep{sarwar2001item} is used.\n\\begin{equation}\\label{nearest_neighbors}\n\t\\hat{r}(User_A,Item_B) = \\frac{\\sum_{u \\in \\mathcal{K}}{similarity(User_A,User_u) * r(User_u,Item_B)}}\n\t\t\t\t\t\t    {\\sum_{u \\in \\mathcal{K}}{\\mathopen|similarity(User_A,User_u)\\mathclose|}}\n\\end{equation}\n\\end{itemize}\n\nThus, the numerator computes the weighted of ratings of the nearest neighbors,\nweighted by their similarities with $User_A$.\nIn a way the similarity can be interpreted as how much users influence\n$User_A$. The denominator sums the absolute values of similarities in order to scale the\noutcome of the rating prediction in the range [1 - 5]. The absolute value is used because\nsimilarity metrics like Pearson correlation coefficient can take negative values which\nwill disturb the scaling.\\\\\n\nIn an item-based KNN setting, in order to predict the rating of $User_A$ for an\n$Item_B$ not rated by $User_A$, KNN consists of the following steps:\n\\begin{itemize}\n\t\\item[] \\textbf{Step 1:} Find items that have been rated by $User_A$.\n\t\\item[] \\textbf{Step 2:} Compute the similarities between $Item_B$ and the items that have\n\tbeen rated by $User_A$.\n\t\\item[] \\textbf{Step 3:}  Sort that similarities in descending order.\n\t\\item[] \\textbf{Step 4:}  Choose how many neighbors will contribute in the rating\n\tprediction.\n\t\\item[] \\textbf{Step 5:} Use an aggregation formula to calculate the rating prediction of\n\t$User_A$ to $Item_B$.\n\\begin{equation}\\label{nearest_neighbors}\n\t\\hat{r}(User_A,Item_B) = \\frac{\\sum_{i \\in \\mathcal{K}}{similarity(Item_B,Item_i) * r(User_A,Item_i)}}\n\t\t\t\t\t\t    {\\sum_{i \\in \\mathcal{K}}{\\mathopen|similarity(Item_B,Item_i)\\mathclose|}}\n\\end{equation}\n\\end{itemize}\n\nThere are 4 important things to take into consideration in order to obtain the most accurate\noutcome out with the KNN algorithm:\n\\begin{enumerate}\n\t\\item Utilize User-based or Item-based CF.\n\t\\item Choose the most appropriate similarity metric that will surface the best connections\n\tbetween users or items.\n\t\\item Choose the optimal $\\mathcal{K}$ for the rating predictions. It is argued from\n\texperiments that a value of $\\mathcal{K}$ between [20 - 50] often yields the best\n\tresults. A small $\\mathcal{K}$ typically < 10 has not accounted for enough opinions and a\n\tlarge $\\mathcal{K}$ > 50 adds a lot of \"noise\" to the prediction \\citep{herlocker2002empirical,Jannach}.\n\t\\item Choose an appropriate prediction formula.\n\\end{enumerate}\n\n\\section{KNN Example}\nTo demonstrate the KNN algorithm the previous steps from \\autoref{sec:2.3} will be used\nto predict how $User_4$ would rate $Item_4$ from the ratings matrix\n(\\autoref{table:Ratings Matrix}), based on a user-based KNN procedure:\n\\begin{itemize}\n\t\\item[] \\textbf{Step 1:} Find users that have rated $Item_4$.\\\\\n\tAll other users in the ratings matrix have rated $Item_4$.\n\t\\item[] \\textbf{Step 2:} Compute the similarities between $User_4$ and the users that have\n\trated $Item_4$.\\\\\n\tFor this example \\autoref{eq:cosine} will be used to compute the similarities.\\\\\n\t\\begin{align*}\n\t\t\\begin{split}\n\t\t\t&cos(User_1, User_4) = \\frac{5*5 + 2*2}{\\sqrt{5^2 + 2^2 + 3^2}*\\sqrt{5^2 + 2^2 + 3^2}} = 0.7632\\\\\n\t\t\t&cos(User_2, User_4) = \\frac{1*5 + 4*3}{\\sqrt{1^2 + 4^2 + 2^2}*\\sqrt{5^2 + 2^2 + 3^2}} = 0.6018\\\\\n\t\t\t&cos(User_3, User_4) = \\frac{3*2 + 5*3}{\\sqrt{3^2 + 5^2 + 4^2}*\\sqrt{5^2 + 2^2 + 3^2}} = 0.4818\\\\\n\t\t\t&cos(User_4, User_5) = \\frac{5*1 + 3*2}{\\sqrt{5^2 + 2^2 + 3^2}*\\sqrt{1^2 + 2^2 + 4^2}} = 0.3894\\\\\n\t\t\t&cos(User_4, User_6) = \\frac{5*3 + 2*5}{\\sqrt{5^2 + 2^2 + 3^2}*\\sqrt{3^2 + 5^2 + 3^2}} = 0.6185\\\\\n\t\t\t&cos(User_4, User_7) = \\frac{5*3 + 2*1}{\\sqrt{5^2 + 2^2 + 3^2}*\\sqrt{3^2 + 1^2 + 5^2}} = 0.4661\\\\\n\t\t\\end{split}\n\t\\end{align*}\n\t\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{chapter_2/KNN_example.eps}\n\t\\caption{Cosine Similarities for $User_4$}\n\t\\label{figure:KNN_example}\n\t\\end{figure}\n\t\\item[] \\textbf{Step 3:}  Sort that similarities in descending order.\n\t\\begin{align*}\n\t\t\\begin{split}\n\t\t\t&cos(User_1, User_4) = 0.7632\\\\\n\t\t\t&cos(User_4, User_6) = 0.6185\\\\\n\t\t\t&cos(User_2, User_4) = 0.6018\\\\\n\t\t\t&cos(User_3, User_4) = 0.4818\\\\\n\t\t\t&cos(User_4, User_7) = 0.4661\\\\\n\t\t\t&cos(User_4, User_5) = 0.3894\\\\\n\t\t\\end{split}\n\t\\end{align*}\n\t\\item[] \\textbf{Step 4:}  Choose how many neighbors will contribute in the rating\n\tprediction in this case we choose for example, $\\mathcal{K}=3$.\n\t\\begin{align*}\n\t\t\\begin{split}\n\t\t\t&cos(User_1, User_4) = 0.7632\\\\\n\t\t\t&cos(User_4, User_6) = 0.6185\\\\\n\t\t\t&cos(User_2, User_4) = 0.6018\\\\\n\t\t\\end{split}\n\t\\end{align*}\n\t\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{chapter_2/KNN_example1.eps}\n\t\\caption{Select top $\\mathcal{K}=3$ similar users}\n\t\\label{figure:neighbor_selection}\n\t\\end{figure}\n\t\\item[] \\textbf{Step 5:} Predict how $User_4$ will rate $Item_4$ using the weighted sum.\n\t$$\\hat{r}(User_4,Item_4) = \\frac{0.7632*3 + 0.6018*2 + 0.6185*3}{0.7632 + 0.6018 + 0.6185} = 2.7$$\n\\end{itemize}\n", "meta": {"hexsha": "e5242eef6e5d471479636b69877c857856bb4ab1", "size": 41634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diploma/chapters/chapter_2.tex", "max_stars_repo_name": "tseste/Recursive-K-Nearest-Neighbors", "max_stars_repo_head_hexsha": "5e35c643dc8c530102554492c56bfcf05b242298", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-06T16:08:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-06T16:08:44.000Z", "max_issues_repo_path": "diploma/chapters/chapter_2.tex", "max_issues_repo_name": "tseste/Recursive-K-Nearest-Neighbors", "max_issues_repo_head_hexsha": "5e35c643dc8c530102554492c56bfcf05b242298", "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": "diploma/chapters/chapter_2.tex", "max_forks_repo_name": "tseste/Recursive-K-Nearest-Neighbors", "max_forks_repo_head_hexsha": "5e35c643dc8c530102554492c56bfcf05b242298", "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.3040201005, "max_line_length": 160, "alphanum_fraction": 0.6817024547, "num_tokens": 14273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6769448234846117}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Code} \\label{app:code-ho-pe}\n\n\\section{Harmonic Oscillator} \\label{app:ho}\n\\begin{adjustwidth*}{0cm}{-0.4cm}\n\\begin{lstlisting}[language=Python]\n\"\"\"\nHarmonic Oscillator Numerical Solver Module\n===========================================\nA collection of various numerical solvers for the harmonic oscillator:\n    Euler:\n        Explicit\n        Implicit\n        Symplectic\n\nFunctions:\n    euler: Solves harmonic oscillator by 1st order Euler method explicitely,\n           implicitely or symplectically.\n\nWe assume k/m = 1 in all of the following.\n\n\"\"\"\n\n\nimport numpy as np\n\n\ndef euler(duration,h,kind,x0=0,v0=1):\n    \"\"\"Euler algorithm for harmonic oscillator. Includes three variations: explicit, implicit and symplectic.\n\n    Args:\n        duration (float): Time duration of simulation.\n        h (int): Step size.\n        kind (str): Valid strings: 'explicit', 'implicit', 'symplectic'.\n        x0 (float): Initial position (default value: 0)\n        v0 (float): Initial velocity (default value: 1)\n\n    Returns:\n        Tuple of time-, position- and speed lists\n    \n    \"\"\"\n    # Number of time steps\n    n = int(duration/h)\n    # Vector initialization\n    xlist=np.zeros(n+1) # n steps + ic's --> n+1\n    vlist=np.zeros(n+1)\n    # Initialize initial conditions\n    xlist[0] = x0\n    vlist[0] = v0\n\n    # Make tlist, ensure it always have length n+1\n    if (duration/h % 2) == 0:\n        tlist=np.arange(0,duration+h/2,h)  # Includes the endpoint\n    else:\n        tlist=np.arange(0,duration,h)\n\n    # Euler algorithms\n    if kind == 'explicit':\n        for i in range(n):\n            xlist[i+1] = xlist[i] + h*vlist[i]\n            vlist[i+1] = vlist[i] - h*xlist[i]\n\n    elif kind == 'implicit':\n        for i in range(n):\n            xlist[i+1] = 1/(h**2 + 1)*(xlist[i] + h*vlist[i])\n            vlist[i+1] = 1/(h**2 + 1)*(vlist[i] - h*xlist[i])\n    \n    elif kind == 'symplectic':\n        for i in range(n):\n            xlist[i+1] = xlist[i] + h*vlist[i]\n            vlist[i+1] = (1-h**2)*vlist[i] - h*xlist[i]\n\n    elif kind == 'symplectic2':\n        for i in range(n):\n            xlist[i+1] = (1-h**2)*xlist[i] + h*vlist[i]\n            vlist[i+1] = vlist[i] - h*xlist[i]\n    \n    else:\n        print(\"Error: 3rd argument 'kind' must be 'explicit', 'implicit' or 'symplectic'\")\n    \n    return tlist,xlist,vlist\n\\end{lstlisting}\n\\end{adjustwidth*}\n\n\\section{Pendulum} \\label{app:pe}\n\\begin{adjustwidth*}{0cm}{-0.4cm}\n\\begin{lstlisting}[language=Python]\n\"\"\"\nPendulum Numerical Solver Module\n================================\nA collection of various numerical solvers for the mathematical penduluim:\n    Euler:\n        Explicit\n        Implicit\n        Symplectic\n\nFunctions:\n    euler: Solves the pendulum by Euler method explicitely, implicitely or symplectically.\n\nWe assume 1/ml = 1  and  m*g*l = 1 in all of the following.\n\n\"\"\"\n\n\nimport numpy as np\nimport root_finding as rf\n\n\ndef euler(duration,h,kind,theta0=0,omega0=1):\n    \"\"\"Euler algorithm for the pendulum. Includes three variations: explicit, implicit and symplectic.\n\n    Args:\n        duration (float): Time duration of simulation.\n        h (int): Step size.\n        kind (str): Valid strings: 'explicit', 'implicit', 'symplectic'.\n        theta0 (float): Initial angle (default value: 0)\n        omega0 (float): Initial angular velocity (default value: 1)\n\n    Returns:\n        Tuple of time-, angle- and angular velocity lists\n    \n    \"\"\"\n    # Number of time steps\n    n = int(duration/h)\n    # Vector initialization\n    thetalist=np.zeros(n+1) # n steps + ic's --> n+1\n    omegalist=np.zeros(n+1)\n    # Initialize initial conditions\n    thetalist[0] = theta0\n    omegalist[0] = omega0\n\n    # Make tlist, ensure it always have length n+1\n    if (duration/h % 2) == 0:\n        tlist=np.arange(0,duration+h/2,h)  # Includes the endpoint\n    else:\n        tlist=np.arange(0,duration,h)\n\n    # Euler algorithms\n    if kind == 'explicit':\n        for i in range(n):\n            thetalist[i+1] = thetalist[i] + h*omegalist[i]\n            omegalist[i+1] = omegalist[i] - h*np.sin(thetalist[i])\n\n    elif kind == 'implicit':\n        for i in range(n):\n            # f(x) and f'(x) used in Newton-Raphson root finder below\n            f = lambda x: thetalist[i] - x + (omegalist[i] - np.sin(x)*h)*h\n            g = lambda x: -1 - np.cos(x)*h*h  # g = f'\n            # Find thetalist[i+1] numerically by root finding, guess thetalist[i]\n            thetalist[i+1] = rf.newton_raphson(f,g,thetalist[i])\n            omegalist[i+1] = omegalist[i] - np.sin(thetalist[i+1])*h\n    \n    elif kind == 'symplectic':\n        for i in range(n):\n            omegalist[i+1] = omegalist[i] - h*np.sin(thetalist[i])\n            thetalist[i+1] = thetalist[i] + h*omegalist[i+1]\n    \n    else:\n        print(\"Error: 3rd argument 'kind' must be 'explicit', 'implicit' or 'symplectic'\")\n    \n    return tlist,thetalist,omegalist\n\\end{lstlisting}\n\\end{adjustwidth*}", "meta": {"hexsha": "df464e0a5136a1166a293bd07f6b5f42dcfa022f", "size": 4948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/Code_HO_PE.tex", "max_stars_repo_name": "GandalfSaxe/leto", "max_stars_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/Code_HO_PE.tex", "max_issues_repo_name": "GandalfSaxe/leto", "max_issues_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/Code_HO_PE.tex", "max_forks_repo_name": "GandalfSaxe/leto", "max_forks_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3558282209, "max_line_length": 109, "alphanum_fraction": 0.5955941795, "num_tokens": 1449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6768532324662636}}
{"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%\tPACKAGES AND OTHER DOCUMENT CONFIGURATIONS\n%----------------------------------------------------------------------------------------\n\n\\documentclass[\n\t12pt, % Default font size, values between 10pt-12pt are allowed\n\t%letterpaper, % Uncomment for US letter paper size\n\t%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} % Required for better horizontal rules in tables\n% \\usepackage{listings} % Required for insertion of code\n\\usepackage{enumerate}% To modify the enumerate environment\n\\setlength{\\parindent}{15pt}\n\n%----------------------------------------------------------------------------------------\n%\tASSIGNMENT INFORMATION\n%----------------------------------------------------------------------------------------\n\n\\title{Task 1 \\\\ The Logarithmic Spiral} % Assignment title\n\n\\author{Emilio Domínguez Sánchez} % Student name\n\n\\date{October 3rd, 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%\tDefinitions\n%----------------------------------------------------------------------------------------\n\n\\usepackage{physics}\n\\DeclareMathOperator{\\len}{len}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\begin{document}\n\n\\maketitle % Output the assignment title, created automatically using the information in the custom commands above\n\n%----------------------------------------------------------------------------------------\n%\tASSIGNMENT CONTENT\n%----------------------------------------------------------------------------------------\n\n\\section*{Problem}\n\n\\begin{problem}\n    Let $α : \\R → \\R^2$ be the parametrized curve given by $α(t) = ae^{bt}(\\cos t, \\sin t)$,\nwhere $a > 0$ and $b < 1$.\nFind the arc length function and a reparametrization with respect to arc length.\n\\end{problem}\n\n%----------------------------------------------------------------------------------------\n\n\\subsection*{Answer}\n\n    The arc length function can be as the integral of the norm of the derivative.\nThat is,\n\n\\begin{multline*}\n    \\len(t_0, τ) =\n    \\int_{t_0}^τ \\norm{\\dv{α}{t}} \\dd{t} = \\\\\n    \\int_{t_0}^τ \\norm{ae^{bt} \\qty(b\\cos t - \\sin t, b\\sin t + \\cos t)} \\dd{t} =\n    \\int_{t_0}^τ ae^{bt}\\sqrt{b^2 + 1} \\dd{t} = \\\\\n    \\left\\{ \\begin{split}\n        (b = 0) & &\n        = a\\eval[τ|_{t_0}^τ\n        = a(τ-t_0). \\\\\n        (b ≠ 0) & &\n        = \\frac{a\\sqrt{b^2 + 1}}{b} \\eval[e^{bt}|_{t_0}^τ =\n        k (e^{bτ} - e^{bt_0}). \\\\\n    \\end{split} \\right.\n\\end{multline*}\n\n\\noindent\nwhere we have defined $k$ as $\\frac{a\\sqrt{b^2 +1}}{b}$ for convenience.\n\n    When $b = 0$, the spiral becomes a circunference\nthat is traversed at the constant speed $a$.\nThis degenerate case can be reparametrized as\n\n\\begin{align*}\n    \\vectorunit*{α}(t) & =\n    a\\qty(\\cos \\frac{t}{a}, \\sin \\frac{t}{a}), \\\\\n    \\norm{\\dv{\\vectorunit*{α}(t)}{t}} & =\n    \\norm{\\qty(-\\sin \\frac{t}{a}, \\cos \\frac{t}{a})} = 1.\n\\end{align*}\n\n    For the case $b \\neq 0$, owing to the fact that\nthe (timed by $t_0$) position can be chosen arbitrarily,\nand, because either\n$\\lim_{t_0 \\to -∞} e^{bt_0} = 0$ if $b > 0$ or\n$\\lim_{t_0 \\to ∞} e^{bt_0} = 0$ if $b < 0$,\nwe can consider the integral when $t_0 = -∞$ or $t_0 = ∞$.\nHence, and for simplicity, we will assume $b > 0$ from here onwards\nand write the length as $\\len(-∞, τ) = \\len(τ) = ke^{bτ}$.\n\n    To reparametrizate the curve with respect to its length,\nwe guess that we need to find the function\n\n\\begin{align*}\n    \\R & \\to \\R^2 \\\\\n    t & \\mapsto α(p_t | \\len(p_t) = t), \\\\\n\\end{align*}\n\nwhich ought to be\n\n\\begin{align*}\n    \\R & \\to \\R^2 \\\\\n    t & \\mapsto α(\\len^{-1}(p_t)). \\\\\n\\end{align*}\n\n\\noindent\nWe have seen in class a theorem that asserts that the inverse and this reparametrization\nalways exist when $\\dv{α}{t} ≠ 0$.\nFor our particular problem, it is enough to clear $τ$ from the relation $len(τ) = ke^{bτ}$,\ngiving\n%TODO clear = despejar?\n\n\\begin{align*}\n    \\len(τ) & = ke^{bτ} \\\\\n    τ & = \\frac{\\ln \\len(τ) - \\ln k}{b}\\\\\n    \\len^{-1}(τ) & = \\frac{\\ln τ - \\ln k}{b}.\n\\end{align*}\n\n\\noindent\nThus, the formula for the reparametrization would be\n\n\\begin{multline*}\n    \\vectorunit*{α}(t) =\n    α\\qty(\\len^{-1}(t)) =\n    α\\qty(\\frac{\\ln t - \\ln k}{b}) = \\\\\n    ae^{b\\frac{\\ln t - \\ln k}{b}} \\qty(\\cos \\frac{\\ln t - \\ln k}{b}, \\sin \\frac{\\ln t - \\ln k}{b}) =\n    \\qty( k = \\frac{a\\sqrt{b^2 +1}}{b} ) = \\\\\n    \\frac{bt}{\\sqrt{b^2+1}} \\qty(\\cos \\frac{\\ln t - \\ln k}{b}, \\sin \\frac{\\ln t - \\ln k}{b}).\n\\end{multline*}\n\n%----------------------------------------------------------------------------------------\n\n\\subsection*{Extra}\n\n    As you may have noticed, the expression for $\\vectorunit*{α}$\n(which is in polar form)\nshows that the radius of the spiral does not depend on the choice of $a$.\nAnd although the angle does (via $k$),\nthe derivative of the angle doesn't.\nWhat this means is that the set of curves with the same $b$ are all similar by rotation.\nWe can check that a rotation of a logarithmic spiral does, indeed,\ngive another logarithmic spiral with the same $b$ parameter.\nThat is, a scaled version of the original curve.\nSimilarly, a scaled version of the original curve can be obtained via a rotation.\nThis property of the logarithmic spiral is called self-similarity.\n\n%----------------------------------------------------------------------------------------\n\n\\end{document}\n", "meta": {"hexsha": "c6e56ce1d6f3608b18735fc45ab2e0110701b7b7", "size": 6503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "logarithmic-spiral.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": "logarithmic-spiral.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": "logarithmic-spiral.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.3423913043, "max_line_length": 114, "alphanum_fraction": 0.5548208519, "num_tokens": 1855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.6768532232359038}}
{"text": "\\section{Triangulation system geometry}\n\\label{sec:init-modelanalysis}\nAt first, we analyse the errors due to the geometry of the triangulation system. For simplicity, we will focus on the standard geometry (described in Section \\ref{sec:lctt}): the analysis for other geometries is trivial. \\\\\n\nAs illustrated in Figure \\ref{fig:laser-triang}, the laser-camera pair form a triangle with angle $\\phi$ between the baseline (the plane along the distance between the laser and the camera), and the optical axis of the camera. In \\acs{SOL} systems, $\\phi$ is\n\\clearpage\n  \\begin{figure}[h]\n    \\centering\n    \\begin{minipage}[c]{\\textwidth}\n      \\centering\n      \\includegraphics[width=0.7\\textwidth]{./images/model/laser_triang.png}\n      \\caption{\\acs{FOV} and characteristic angles}\n      \\label{fig:laser-triang}\n    \\end{minipage}\n    \\vfill\n    \\begin{minipage}[c]{\\textwidth}\n      \\centering\n      \\includegraphics[width=0.7\\textwidth]{./images/model/laser_triang_pdv.png}\n      \\caption{Angles definitions}\n      \\label{fig:laser-triang-pdv}\n    \\end{minipage}\n  \\end{figure}\n\\clearpage \\noindent\ncalled \\textit{triangulation angle}. If $\\phi$ and the baseline are known, any point in the 3D space belonging to the laser plane, is located estimating the offset $\\alpha$ with respect to $\\phi$, and the offset $\\beta$ with respect to the optical axis of the camera. Accordingly with \\cite{th:quattrini}, and using simple mathematical relations, we can locate the $y$ coordinate as function of the angle $\\alpha$ as follows:\n  \\begin{equation}\n    \\label{eq:model-ya}\n    y\\left( \\alpha \\right) = y_f + z_f \\tan \\left( \\phi + \\alpha \\right)\n  \\end{equation}\nwhere $\\left( x_f, y_f, z_f \\right)$ are the principal point projection coordinates in the laser plane (in the world reference system), as shown in Figure \\ref{fig:laser-triang-pdv}. Note that using this notation, $z_f$ is the distance from the laser to the camera, previously called baseline. \\\\\n\nNow let's look at the Figure \\ref{fig:laser-triang-pdv}. As mentioned at the end of the Section \\ref{sec:lctt}, camera's resolutions varies changing the distance of the target from the camera. In particular this is true for the resolution along the laser line (axis $x$ with respect to out notation). Points having the same $x$ coordinates but different $y$ are estimated with different camera resolutions. This means that the values of $x$ strongly depends on the angle $\\beta$ (that identify the value of $x$ with respect the the optical axis of the camera), but also on the angle $\\alpha$ (that identifies the value of $y$ with respect to the triangulation angle). For these reasons we can write\n  \\begin{equation}\n  \\label{eq:model-xab}\n    x(\\alpha, \\beta) = \\frac{y\\left( \\alpha \\right) - y_f}{\\sin(\\phi + \\alpha)}\\tan(\\beta)\n  \\end{equation} \\\\\nAs we can see, $x$ strongly depends on $y$, accordingly with what we said in Section \\ref{sec:lctt}, about the trapezoidal shape of the laser plane. Still for the shape of the laser, a similar consideration can be made for the $y$ coordinate, because of the trapezoidal shape of the laser plane.\n% To be precise, a similar consideration can be made for the $y$ coordinate, because of the trapezoidal shape of the laser plane.\nHowever, in this case the differences between the nearest and the farthest \\acs{FOV}s along the $x$ axis, are negligible. For theses reasons we will consider Equation \\ref{eq:model-ya} as a good approximation of the relation between $y$ and $\\alpha$. \\\\\n\nAccordingly with what we said in Section \\ref{sec:teo-calibration}, during calibration phase the choice of the reference system is arbitrary, so we can put $\\left( x_f, y_f, z_f \\right) = \\left( 0, 0, z_f \\right)$ without loss of generality. In this way, Equations \\ref{eq:model-ya} and \\ref{eq:model-xab} can be simplified. \\\\\n\nAt this point it is easy to estimate the error associated with the two newly introduced measures. Applying the simplification, for Equation \\ref{eq:model-ya} we can write:\n  \\begin{equation}\n    \\label{eq:model-ya-err0}\n    \\sigma_{y_\\alpha} = \\sqrt{\n      \\left( \\frac{\\partial y}{\\partial z_f} \\right)^2 \\sigma_{z_f}^2 +\n      \\left( \\frac{\\partial y}{\\partial \\phi} \\right)^2 \\sigma_\\phi^2 +\n      \\left( \\frac{\\partial y}{\\partial \\alpha} \\right)^2 \\sigma_\\alpha^2\n    }\n  \\end{equation}\nwhile for Equation \\ref{eq:model-xab} we can write\n  \\begin{equation}\n    \\label{eq:model-xab-err0}\n    \\sigma_{x\\left( \\alpha, \\beta \\right)} = \\sqrt{\n      \\left( \\frac{\\partial x}{\\partial \\phi} \\right)^2 \\sigma_\\phi^2 +\n      \\left( \\frac{\\partial x}{\\partial \\alpha} \\right)^2 \\sigma_\\alpha^2 +\n      \\left( \\frac{\\partial x}{\\partial \\beta} \\right)^2 \\sigma_\\beta^2\n    }\n  \\end{equation}\\\\\nIn these last equations, the $\\sigma$ are the errors committed evaluating each component in the Equations \\ref{eq:model-ya} and \\ref{eq:model-xab}. As we can see, in Equations \\ref{eq:model-ya-err0} and \\ref{eq:model-xab-err0} we are considering also $\\phi$ and $z_f$ that are constructive parameters that depend on the accuracy with which the system was built or installed. Typically, these parameters are corrected thanks to the calibration process, that allows to estimate camera intrinsic and extrinsic parameters, as mentioned in Section \\ref{sec:teo-calibration}. In addition, the calibration process uses many algorithms that in turn use different heuristics to estimate camera parameters. This means that all parameters are affected by error, but as we can see later, we can consider these errors negligible. So we can simplify Equations \\ref{eq:model-ya-err0} and \\ref{eq:model-xab-err0} respectively as follows\n  \\begin{equation}\n    \\label{eq:model-ya-err1}\n    \\sigma_{y_\\alpha} = \\sqrt{\n      \\left( \\frac{\\partial y}{\\partial \\alpha} \\right)^2 \\sigma_\\alpha^2\n    }\n  \\end{equation}\n  \n  \\begin{equation}\n    \\label{eq:model-xab-err1}\n    \\sigma_{x\\left( \\alpha, \\beta \\right)} = \\sqrt{\n      \\left( \\frac{\\partial x}{\\partial y_\\alpha} \\right)^2 \\sigma_{y_\\alpha}^2 +\n      \\left( \\frac{\\partial x}{\\partial \\alpha} \\right)^2 \\sigma_\\alpha^2 +\n      \\left( \\frac{\\partial x}{\\partial \\beta} \\right)^2 \\sigma_\\beta^2\n    }\n  \\end{equation} \\\\\n\nKeeping focus on the geometry of the system, the second element to consider is the laser plane. In standard geometry, variations on laser pitch and roll rotations, with respect to the reference system, can affect heavily the final measure. By trigonometry we know that by changing the angle, the point projections also change in the two axes of the reference system. The same effect is present when we rotate the laser plane with respect to the $x$ axis (roll) or with respect to the $y$ axis (pitch). These errors are more apparent in the other triangulation geometries. What we have to do, is to compensate these rotations projecting the laser plane on the ideal one. The compensations are performed as follows:\n  \\begin{equation}\n    \\begin{matrix}\n      y_w = y(\\alpha) \\cdot cos(\\rho) \\\\ ~ \\\\\n      x_w = x(\\alpha, \\beta) \\cdot \\cos(\\gamma)\n    \\end{matrix}\n    \\label{eq:radial-compensations}\n  \\end{equation} \\\\\nwhere $\\rho$ is the laser roll angle, and $\\gamma$ is the laser pitch angle. Using the model introduced in Equation \\ref{eq:er_prop_2}, we can write, respectively:\n  \\begin{equation}\n    \\sigma_{y_w} = \\sqrt{\n      \\left( \\frac{\\partial y_w}{\\partial y(\\alpha)} \\right)^2 \\sigma_{y_\\alpha}^2\n      + \\left( \\frac{\\partial y_w}{\\partial \\rho} \\right)^2 \\sigma_\\rho^2\n    }\n    \\label{eq:err-radial-comp-yw}\n  \\end{equation}\n  \\begin{equation}\n    \\sigma_{x_w} = \\sqrt{\n      \\left( \\frac{\\partial x_w}{\\partial x\\left( \\alpha, \\beta \\right)} \\right)^2 \\sigma_{x\\left( \\alpha, \\beta \\right)}^2 +\n      \\left( \\frac{\\partial x_w}{\\partial \\gamma} \\right)^2 \\sigma_\\gamma^2\n    }\n    \\label{eq:err-radial-comp-xw}\n  \\end{equation} \\\\\nwhere $\\sigma_{y_\\alpha}$ and $\\sigma_{x\\left( \\alpha, \\beta \\right)}$ are the ones evaluated in Equations \\ref{eq:model-ya-err1} and \\ref{eq:model-xab-err1} respectively. \\\\\n\nA practical example in which these compensations are needed, is the \\acs{WPMS}. In autonomous \\acs{WPMS}s placed alongside the rails, specular geometry is generally used, and wheels are measured while the train is running. In these cases we are not sure to measure the wheel exactly along its axis, so the acquired profiles have to be compensated. This type of correction is called \\textit{radial compensation}. \\\\\n% The errors due to non-ideality of laser plane placement can be seen also as non-ideality of work conditions. In autonomous \\acs{WPMS}s placed alongside the rails, specular geometry is generally used, and wheels are measured while the train is running. In these cases we are not sure to measure the wheel exactly along its axis, and typically corrections like the ones for rolls are needed. In these field, these corrections are referred as \\textit{radial compensation}. \\\\\nWe can consider the same things about pitch. Sometimes the wheel under analysis is not perpendicular with the laser plane, because wheel yaw and camber. Also in these cases $x$ values must be compensated.\n\n%We can see here, the determination of $x$ is fully dependent by the formulation on $y$.\n", "meta": {"hexsha": "1c2d5f684a8353ab26b9d5413618d96218ac21a9", "size": 9179, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch4-Model/2_system.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/2_system.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/2_system.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": 85.785046729, "max_line_length": 920, "alphanum_fraction": 0.7260050114, "num_tokens": 2522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.6768366404199315}}
{"text": "% Line numbering does not work well with diplay math? \n% that is why iI use the following macro\n% to end a paragraph just before a displaymath\n% without getting to much vertical space\n\\newcommand\\premathpar{\\vspace{-2\\parskip}\\par}\n% To have linenumbering, add a \\par before each displaymath\n% The text below was taken from the sample.tex document by \n% \\author{Matthias K. Gobbert}\n% \\begin{savequote}[8cm]\n%   \\sffamily\n%   Beautiful math is the purpose of \\TeX\\ and \\LaTeX.\n%   \\qauthor{Mantra of \\TeX-ies}\n% \\end{savequote}\n\\chapter{Mathematics to show off}\n% first som definitions\n% some personal command definitions as examples:\n\\newcommand{\\half}{\\frac{1}{2}}\n\\newcommand{\\eps}{\\varepsilon}\n\\newcommand{\\rh}{\\rho}\n\\newcommand{\\mtheta}{\\vartheta}\n\\newcommand{\\ph}{\\varphi}\n% this command is for partial derivatives and takes 2 input arguments:\n\\newcommand{\\der}[2]{\\frac{\\partial {#1}}{\\partial {#2}}}\n\nHere, you see how a mathematical equation can be generated in line, for\ninstance $f(x) = \\frac{1}{1+25 x^2}$.\nThe \\verb+$+-symbols enclose the formula.\nAs a so-called displayed formula, it would look like\\premathpar\n\\begin{displaymath}\n  f(x) = \\frac{1}{1+25 x^2}.\n\\end{displaymath}\nIt is customary that mathematical functions are \\emph{not} set in math-italics,\nso \\LaTeX\\ has the basic ones pre-defined; you should use the commands\n\\verb+\\cos+, \\verb+\\exp+, etc.\\ to get $f_1(x) = \\cos x$,\n$f_2(x) = - e^x \\sin^2 x$, etc.\n\nHere, I use some of my commands defined above: I like $\\eps = \\varepsilon$\nbetter than the default $\\epsilon$. A partial derivative (with 2 arguments)\nwould be obtained as follows. If $f(x,y) = x^2 y^3$, then \\premathpar\n\\begin{displaymath}\n  \\der{f}{x} = 2 x y^3, \\quad \\der{f}{y} = 3 x^2 y^2.\n\\end{displaymath}\n\\section{Sums and Integrals}\nWhen you say ``capital sigma,'' you probably did not really mean $\\Sigma$,\nbut rather a summation symbol. You would get that as in\\premathpar\n\\begin{displaymath}\n  \\sum_{i=0}^{\\infty} r^i = \\frac{1}{1 - r} \\quad \\mbox{for all $|r| < 1$}.\n\\end{displaymath}\nFinally, we have\\premathpar\n\\begin{displaymath}\n  \\int_0^1 \\sin(2 \\pi x) \\, dx = 0\n\\end{displaymath}\nand\\premathpar\n\\begin{displaymath}\n  \\int\\!\\!\\int f(x) g(y) \\, dx \\, dy = \\int f(x) \\, dx \\,\\, \\int g(y) dy.\n\\end{displaymath}\nHere, \\verb+\\,+ gives a small space, while \\verb+\\!+ forces things closer\ntogether; you have to work on the proper spacing for integrals, as \\LaTeX\\\ndoes not understand, what is going on.\n\\clearpage % hack to move section to next page\n\\section{Matrices in \\LaTeX}\nA matrix $A \\in \\mathrm{R}^{m \\times n}$ could be defined by\\premathpar\n\\begin{displaymath}\n  A = \\left( \\begin{array}{ccccc}\n        11     & 12     & 13     & \\cdots & 1n     \\\\\n        21     & 22     & 23     & \\cdots & 2n     \\\\\n        \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n        m1     & m2     & m3     & \\cdots & mn     \\\\\n      \\end{array} \\right)\n\\end{displaymath}\nHere, the word \\verb+dots+ in the commands stands for an ellipsis\n(i.e., three dots) placed horizontally in the centre (\\verb+\\cdots+),\nvertically (\\verb+\\vdots+), or diagonally (\\verb+\\ddots+); what is\nnot mentioned is \\verb+\\ldots+ for horizontal dots at the baseline.\nUse the baseline or central version as appropriate, for instance\\premathpar\n\\begin{eqnarray*}\n  a_1, a_2, \\ldots, a_n & \\mbox{and not} & a_1, a_2, \\cdots, a_n, \\\\\n  a_1 + a_2 + \\cdots + a_n & \\mbox{and not} & a_1 + a_2 + \\ldots + a_n, \\\\\n\\end{eqnarray*}\n\nSome more comments on the matrix are needed, I suppose:\nThe \\verb+\\left(+ and \\verb+\\right)+ create the variable-sized parentheses\naround the actual array of terms. You can also use \\verb+\\left[+ and\n\\verb+\\right]+, or \\verb+\\left\\{+ and \\verb+\\right\\}+ in other situations.\nThe actual array arrangement is organised by the \\verb+array+ environment;\nyou need the arguments \\verb+ccccc+ to indicate that there are five columns\nand you want the entries centered (``c''), other options are left (``l'')\nand right (``r''). Notice how \\verb+&+ separate columns and \\verb+\\\\+\nthe rows.\n\nHere is another matrix example.\nA matrix multiply used with 3D graphics:\n\\begin{displaymath}\n  \\left[ \\begin{array}{cccc}\n        R_{11} & R_{12} & R_{13} & 0 \\\\\n        R_{21} & R_{22} & R_{23} & 0 \\\\\n        R_{31} & R_{32} & R_{33} & 0 \\\\\n        0      & 0      & 0       & 1\n    \\end{array} \\right]\n  \\cdot\n  \\left[ \\begin{array}{cccc}\n      1 & 0 & 0 & X \\\\\n      0 & 1 & 0 & Y \\\\\n      0 & 0 & 1 & Z \\\\\n      0 & 0 & 0 & 1\n  \\end{array} \\right] \n=  \\left[ \\begin{array}{cccc}\n        R_{11} & R_{12} & R_{13} & T_x \\\\\n        R_{21} & R_{22} & R_{23} & T_y \\\\\n        R_{31} & R_{32} & R_{33} & T_z \\\\\n        0      & 0      & 0       & 1\n  \\end{array} \\right] \n\\end{displaymath}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "1cb80bde0b3d0b5a0670863076fa033faffdfbae", "size": 4778, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/chapters/mathematics.tex", "max_stars_repo_name": "sebivenlo/tectonic-thesis-skeleton", "max_stars_repo_head_hexsha": "eff4ac2d9457554c394f43b3d161de1c9191e64c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-02T16:07:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T16:07:26.000Z", "max_issues_repo_path": "src/chapters/mathematics.tex", "max_issues_repo_name": "sebivenlo/tectonic-thesis-skeleton", "max_issues_repo_head_hexsha": "eff4ac2d9457554c394f43b3d161de1c9191e64c", "max_issues_repo_licenses": ["CC0-1.0"], "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/chapters/mathematics.tex", "max_forks_repo_name": "sebivenlo/tectonic-thesis-skeleton", "max_forks_repo_head_hexsha": "eff4ac2d9457554c394f43b3d161de1c9191e64c", "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.8166666667, "max_line_length": 79, "alphanum_fraction": 0.6433654249, "num_tokens": 1620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998560157665, "lm_q2_score": 0.8705972818382005, "lm_q1q2_score": 0.6767151418205509}}
{"text": "\\section{The Integers and the Rationals}\r\n\\subsection{Integers}\r\nThe integers $\\mathbb Z$ consists of all expressions $n,-n$ where $n$ is a natural number, and $0$.\r\nWe can define $+, \\times$ etc. in the obvious way.\r\nAnd it is easy and trivial to check all the necessary rules apply.\r\nAnd we define $a<b$ as $a+c=b$ for some natural number $c$.\r\nAll previous rules appply except we need $c$ to be positive to have $a<b\\implies ac<bc$.\r\nAlso, for any $a$, $a+0=a$ and that there is a $b$ such that $a+b=0$.\r\nThis makes the integers a group.\r\n\\subsection{Rationals}\r\nWe can define the rationals $\\mathbb Q$ as well.\r\nIt shall consist of all expressions $a/b$ for some integers $a,b$ with $n\\neq 0$.\r\nAnd we shall have \r\n$$a/b=c/d\\iff ad=bc$$\r\nAnd we define \r\n$$\\frac{a}{b}+\\frac{c}{d}=\\frac{ad+bc}{bd}$$\r\nWe have to check that this is well defined, since $\\mathbb Q$ is constructed based on equivalence classes.\r\nFor example, we cannot assign an operation sending $a/b\\to a^2/b^3$ because it will be ill defined, as $1/2$ and $2/4$ go to different places.\r\n\\begin{proposition}\r\n    The addition is well-defined on $\\mathbb Q$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    We can define multiplication similarly that satisfies all usual rules and that every nonzero rational number has an inverse under multiplication.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nSo the rationals excluding $0$ is a group.\\\\\r\nAs for order, $a/b<c/d\\iff ad<bc$ for $b,d>0$.\r\nWe can also check all the rules we want", "meta": {"hexsha": "a3bd6542b03dab6e70182a662e68877a189f2c4d", "size": 1554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/zq.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": "2/zq.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": "2/zq.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": 47.0909090909, "max_line_length": 150, "alphanum_fraction": 0.7046332046, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6767151313815385}}
{"text": "\n\\subsection*{Lecture Schedule}\n\nBelow is a tentative schedule of the theory and practice topics covered by lecture number. \n\n\\begin{enumerate}[(1)]\n\\item \\textbf{Theory:} Review of syllabus, introducing science and modeling, definition of phenomena / the response $y$, reality vs. approximation, measurement vs. prediction and simulation, definition of learning from data, model validation, heuristics, ambiguous models, mathematical models, causal inputs, response spaces $\\mathcal{Y}$, definition of features $\\x$ and its feature space $\\mathcal{X}$.\n\n\\textbf{Practice:} Short history of \\texttt{R}, introduction to RStudio, arithmetic, assignment of variables, mathematical functions, logical operations, numeric / integer / boolean data types, vectors, sequences, subsetting, sorting, taxonomy of illegal values.\n\n\\item \\textbf{Theory:} Feature spaces, binary, categorical and continuous data types, definition of metrics, ordinal codings, sample size $n$ vs. number of features $p$, error due to ignorance of information $\\delta$, optimal response surface $f$, definition of training data $\\mathbb{D}$, definition of candidate function set $\\mathcal{H}$, definition of prediction function $g$, algorithms that produce prediction functions $\\mathcal{A}$, definition of misspecification error, definition of optimal candidate function $h^*$, irreducible error $\\mathcal{E}$, estimation error and residuals $e$.\n\n\\textbf{Practice:} Realizations of popular random variables, PDF / PMF / CDF / empirical CDF computations, quantile computations, factor-type variables, matrix data type and its critical functions, if / if-else / else / switch programmatic control, for / while / repeat loops, console printing, errors and warnings, try-catch control.\n\n\\item \\textbf{Theory:} Visualization of training data $\\mathbb{D}$, threshold models for classification, null model for classification $g_0$, concept of a parameter $\\theta$ and parameter space $\\Theta$, degrees of freedom, definition of objective function / error function, accuracy, sum of squared error (SSE), optimization within $\\mathcal{A}$, linear threshold models, perception learning algorithm (PLA), introduction to neural networks.\n\n\\textbf{Practice:} Review of hashing and the list data type, the array data type for general tensors, naming for vectors / matrices / tensors, introduction to specifying functions, arguments, argument defaults, creating data matrices, tabling multiple features, the dataframe data type.\n\n\\item \\textbf{Theory:} Review of lines in multiple dimensions with Hesse Normal Form, derivation of the support vector machine (SVM) using maximum margin objective, hinge error, SVM using the Vapnik objective, defintion of hyperparameters $\\lambda$, $K$-nearest neighbors algorithm (KNN).\n\n\\textbf{Practice:} Installing and loading libraries from CRAN and githuv, public vs private functions and scoping, loading datasets from libraries / files / URLs, creating threshold models, writing the PLA, matrix operations: arithmetic / transpose / inverse / rank / trace, optimization algorithms e.g. Nelder-Mead, writing the KNN algorithm, using the SVM library and setting the hyperparameter.\n\n\\item \\textbf{Theory:} Null model for regression $g_0$, linear models for continuous responses $\\bbeta$, minimization of SSE for $p=1$ using basic calculus to arrive at the ordinary least squares (OLS) solution $\\b$, review of covariance of two random variables $\\sigma_{X,Y}$ and its estimate $s_{X,Y}$, review of correlation $\\rho_{X,Y}$ and its estimate $r_{X,Y}$.\n\n\\textbf{Practice:} Computing sample covariance and correlation in the context of the OLS algorithm for $p=1$, computing OLS error metrics, the formula object, using the \\texttt{lm} function, visualizing the OLS line atop a scatterplot, computing predictions in OLS, OLS in the boston housing data\n\n\\item \\textbf{Theory:} Error metrics for regression: SSE, mean squared error (MSE) and root mean squared error (RMSE), approximate prediction confidence intervals using RMSE, sum of squares total (SST), concept of proportion of variance explained $R^2$, class of models with $R^2 < 0$, perfect fit models with $R^2 = 1$.\n\n\\textbf{Practice:} OLS on the Galton height data and the etymology of the word \\qu{regression} in statistics, computing OLS in the case of categorical variables (ANOVA), dummifying variables, computing model matrices.\n\n\\item \\textbf{Theory:} OLS estimates being the group averages with one binary feature, independence, dependence, association, correlation, OLS estimates with $p>1$, design matrix $X$, vector derivative properties: constant scalars, multiples, multiplication, quadratic forms, general OLS solution, review of matrix inverses, transposes, rank and symmetric matrices.\n\n\\textbf{Practice:} Visualizing $R^2$ for a model using error density estimation, computing general OLS estimates in multiple dimensions from scratch, making predictions using the \\texttt{predict} interface for modeling.\n\n\\item \\textbf{Theory:} OLS predictions as linear transformations, review of the linear algebra concepts of dimension, length, norm, subspace, linear in/dependence, column space, derivation of the orthogonal projection matrix for one dimension via law of cosines, outer products, idempotency.\n\n\\textbf{Practice:} Eigendecomposition, computing error metrics for general OLS, computing the null model.\n\n\\item \\textbf{Theory:} Derivation of the orthogonal projection in multiple dimensions, equivalence of the OLS algorithm with orthongal projection, definition of the hat matrix $H$, review of the linear algebra concepts of eigenvectors and eigenvalues, computing the eigenvectors and eigenvectors of $H$.\n\n\\textbf{Practice:} Computing the hat matrix $H$ for the null model and in general, confirming its eigendecomposition and idempotency and rank, using $H$ to find the OLS predictions and residuals and verifying their orthogonality.\n\n\\item \\textbf{Theory:} Verification of the symmetry and idempotency of $H$, proving that one multidimensional orthogonal projection is in general not the same as the sum of orthogonal projections in the component dimensions except if the component dimensions themselves are orthogonal, review of orthonormal matrices $Q$, proving the equivalence of $H = QQ^\\top$, definition of $X = QR$ decomposition, the Gram-Schmidt algorithm, computing $R$, deriving the least squares estimate using $Q$ and $R$.\n\n\\textbf{Practice:} Computing $QR$ decomposition and confirming the orthonormality of $Q$, verifying the OLS predictions are the same with $Q$, writing the Gram-Schmidt algorithm, an overview of the piping / chaining concept in modern programming and in \\texttt{R} with demos. \n\n\\item \\textbf{Theory:} Definition of sum of squares for the regression $SSR$, proving the sum of squares identity $SST = SSR + SSE$, showing that if $p$ increases by one dimension, then SSR is obligated to increase forcing $R^2$ higher, definition of overfitting in modeling, definition of chance capitalization, demonstrating that full overfitting in OLS leads to $H = I$, a superficial introduction to regularization (lasso regression and ridge regression).\n\n\\textbf{Practice:} Demo showing the iterative addition of a feature and $R^2$ monotonically increasing and RMSE monotonically decreasing (overfitting), demonstrating that random vectors are never truly orthogonal and thus their projections are non-zero, a lasso fit and a ridge fit of a dataset with $p \\geq n$.\n\n\\item \\textbf{Theory:} Definition of in-sample error metrics vs. out-of-sample (oos) error metrics, splitting $\\mathbb{D}$ into $\\mathbb{D}_{\\text{train}}$ and $\\mathbb{D}_{\\text{test}}$ via split constant $K$, definition of \\qu{honest} validation via oos error metrics, definition of the final model $g_{\\text{final}}$ definition of underfitting, tracing the underfitting-overfitting complexity curve, definition of optimal-complexity models.\n\n\\textbf{Practice:} A more full demo of overfitting with visualizations, demo of consistency of OLS estimates, code to create train-test splits, demonstration that oos error is larger than in-sample error in the scenario of the model being overfit.\n\n\\item \\textbf{Theory:} Definition of raw features versus derives features, increasing complexity in $\\mathcal{H}$ using polynomial functions of raw features, interpretation of OLS coefficients $\\b$, Weierstrauss Approximation Theorem, OLS with polynomial features, definition of the full rank Vandermonde matrix, definitions of interpolation vs. extrapolation.\n\n\\textbf{Practice:} Square, cube and higher order polynomial fitting both raw and orthogonal with visualization, overfitting with high-degree polynomials, demonstration of extrapolation in models of many different polynomial degrees, prediction with polynomial models, extrapolation in the Galton height data.\n\n\\item \\textbf{Theory:} OLS using the log transformation on both features and response and interpretation of $\\b$, derivation the log change is approximately percentage change, definition of first-order interactions in OLS, interpretations of coefficients in interaction models.\n\n\\textbf{Practice:} Log-linear model fitting and log-log linear model fitting, logging response to reduce the effect of influential observations, the grammar of graphics and the \\texttt{ggplot} package to create histograms, scatterplots, box-whisker, violin plots, smoothing plots, overloading plots with many features, faceting, coloring, aesthetics and themes, using color illustrations and faceting to visualize potential first-order interactions in a linear model, fitting interaction models.\n\n\\item \\textbf{Theory:} oos error metrics as estimates of model generalization error, sources of variance in these estimates, mitigation by adjusting $K$, further mitigation by using cross-validation (CV), $K$-fold CV and its aggregated error estimates, approximation confidence intervals for generalization error, discussion of reasonable values of $K$ in practice.\n\n\\textbf{Practice:} Simulating many different train-test splits to underscore that $K$ trades bias vs. variance in the generalization estimate, writing code for $K$-fold CV, using the package \\texttt{mlr3} to automate $K$-fold CV.\n\n\\item \\textbf{Theory:} Introduction of the fundamental problem of \\qu{model selection} of candidates $g_1, \\ldots, g_M$, model selection with honest validation via splitting $\\mathbb{D}$ into $\\mathbb{D}_{\\text{train}}$, $\\mathbb{D}_{\\text{select}}$ and $\\mathbb{D}_{\\text{test}}$ via split constants $K_{\\text{select}}$ and $K_{\\text{test}}$, procedure to select best model among $M$ candidates and validation of the best model.\n\n\\textbf{Practice:} Writing code for the model selection procedure, review of basic \\texttt{C++}, optimizing \\texttt{R} code via the \\texttt{Rcpp} package, benchmarking routines that require heavy looping between \\texttt{Rcpp} and base \\texttt{R}, benchmarking routines that require heavy recursion between \\texttt{Rcpp} and base \\texttt{R}.\n\n\\item \\textbf{Theory:} Double-CV in the model selection procedure using inner folds and outer folds, discussion of reasonable values of $K_{\\text{select}}$ and $K_{\\text{test}}$ in practice, applying the model selection procedure to grid searching to locate the best value of hyperparameters $\\lambda$ in algorithms that require $\\lambda$, definition of stepwise modeling using the model selection procedure via the underfitting-overfitting complexity curve concept, stepwise OLS with a large basis of candidate terms. \n\n\\textbf{Practice:} Using the package \\texttt{mlr3} to automate the double-CV using inner and outer loops, using the package \\texttt{mlr3} to automate the locating of optimal hyperparameters, demo of forward stepwise linear modeling and tracing the underfitting-overfitting complexity curve.\n\n\\item \\textbf{Theory:} Definition of hyperrectangle basis for $\\mathcal{X}$ and its OLS solution, unfeasibility of this algorithm in high $p$, introduction of the regression tree algorithm.\n\n\\textbf{Practice:} Binning model demo and visualization for varying bin sizes, introduction to data wrangling using the packages \\texttt{dplyr} and \\texttt{data.table}: filtering, sorting, grouping, summarizing, feature derivation, dataframe joining (left, right, inner, full, between / overlap), benchmarking the two libraries.\n\n\\item \\textbf{Theory:} Full specification of regression tree algorithm: definition of a binary tree, definition of orthogonal-to-axes splits, nodes vs. leaves, left-right SSE weighting, leaf assignments, overfitting and tree-pruning.\n\n\\textbf{Practice:} Using the \\texttt{YARF} package to produce regression trees, querying tree stats, visualizing trees and tree model predictions, tree differences by the pruning hyperparameter.\n\n\\item \\textbf{Theory:} MSE of $g$ decomposition into bias and irreducible error for one $\\mathbb{D}$, MSE of $g$ decomposition into bias, irreducible error and variance for multiple $\\mathbb{D}$'s, MSE decomposition of $M$ different $g$'s averaged, strategies to eliminate bias and variance, non-parametric bootstrap sampling, Breiman's concept of bootstrap aggregation (bagging), correlation $\\rho$ among the bootstrapped models, out-of-bag (oob) observations, validation in bagging via oob samples.\n\n\\textbf{Practice:} Visualizing $M$ bagged trees, demonstrating near zero bias, demonstrating variance reduction as $M \\rightarrow \\infty$, a comparison to OLS and high degree polynomial models, demonstration of generalization error improvement, demonstration of validation in bagging.\n\n\\item \\textbf{Theory:} Demonstrating the bias for regression trees is near zero, reducing correlation among the bootstrapped models using feature sampling, introduction of random forests (RF) algorithm.\n\n\\textbf{Practice:} Demonstration that RF decreases $\\rho$ and demonstration that it outperforms bagging in both regression and classification.\n\n\\item \\textbf{Theory:} A basic discussion of \\qu{causality} from a philosophical perspective, directed causal graphs, correlation vs. causation, incidental effects, lurking variables, spurious correlation, causation is defined by manipulation, a quick definition of randomized experimentation, real-world causal diagrams, wrong interpretations of $\\b$ in OLS, the highly limited but true / complete paragraph-long interpretation of $\\b$ in OLS, a discussion of how OLS regression accomplishes estimation of single features with other features \\emph{ceteris paribus}.\n\n\\textbf{Practice:} Demos of whimsical spurious correlations, demonstration that spurious correlations are easy to find in simulation, a nice illustration of correlation without causation using an OLS model that reveals the true interpretation of $\\b$.\n\n\\item \\textbf{Theory:} Introduction of classification tree algorithm, the gini metric, leaf assignments, the two errors: false negatives and false positives, the 2$\\times$2 confusion matrix and its metrics: precision, recall, accuracy, $F_1$ metric, false discovery rate, false omission rate.\n\n\\textbf{Practice:} Using the \\texttt{YARF} package to produce classification trees, querying tree stats, visualizing trees and tree model predictions, tree differences by the pruning hyperparameter, measuring the two errors, computing confusion matrices and the other metrics.\n\n\\item \\textbf{Theory:} Missing data mechanisms (MDMs): missing completely at random, missing at random, not missing at random with examples, strategies to handle missingness: listwise deletion, imputation, multiple imputation, miss forests algorithm and its convergence, the concept of \\qu{retaining} missingness even after imputation, introduction of probability estimation using the independent bernoulli random variable model, optimal probability function, likelihood of $\\mathbb{D}$, $\\mathcal{H}$ for probability functions, generalized linear modeling, link functions: logistic / probit / complementary log-log, numerical approximations to the likelihood optimization.\n\n\\textbf{Practice:} An example of a dataset with missingness, assessing the different MDMs, listwise deletion, imputation and the \\texttt{missForest} package for the recommended imputation, creating the missingness dummies as derives features in $X$.\n\n\\item \\textbf{Theory:} Definition of logistic regression (LR), log-odds interpretation of LR $\\b$, prediction in LR, error metrics for probability estimation: Brier and Log scoring rules, classification modeling from probability regression, optimal asymmetric cost modeling, response-operator curves (ROC), detection-error tradeoff curves (DET).\n\n\\textbf{Practice:} Fitting LR models using the \\texttt{glm} package, predicting with LR models, validating creating asymmetric cost classifiers in LR models, constructing ROC and DET plots using LR models, locating optimal models with minimal cost. \n\n\\item \\textbf{Theory:} Causal diagrams, confounding, correlation does not imply causation, correct interpretation of OLS estimates, asymmetric cost classification in tree models, introduction to boosting as a meta-algorithm, adaboost\n\n\\textbf{Practice:} demonstrating confounding and linear models by hiding the confounder and then revealing it, demonstration of asymmetric classification using trees, demonstration of boosting using package \\texttt{xgboost}.\n\\end{enumerate}\n\n", "meta": {"hexsha": "3fba98eead5f26b1f0d9566a518c4ac665404403", "size": 17266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "syllabus/_lecture_schedule.tex", "max_stars_repo_name": "lamaemaharaj/QC_MATH_342W_Spring_2021", "max_stars_repo_head_hexsha": "a73dd5185a442e3babfbfb9df095a525e18fc9f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-02T15:13:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T17:58:59.000Z", "max_issues_repo_path": "syllabus/_lecture_schedule.tex", "max_issues_repo_name": "lamaemaharaj/QC_MATH_342W_Spring_2021", "max_issues_repo_head_hexsha": "a73dd5185a442e3babfbfb9df095a525e18fc9f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2021-02-04T03:46:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-25T05:05:01.000Z", "max_forks_repo_path": "syllabus/_lecture_schedule.tex", "max_forks_repo_name": "lamaemaharaj/QC_MATH_342W_Spring_2021", "max_forks_repo_head_hexsha": "a73dd5185a442e3babfbfb9df095a525e18fc9f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2021-02-01T05:00:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-25T05:20:23.000Z", "avg_line_length": 154.1607142857, "max_line_length": 673, "alphanum_fraction": 0.7979265609, "num_tokens": 3829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6766461298028598}}
{"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~\\eqref{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\nThe 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{equation*}\n  v^\\pi_t(s_t) = \\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]\\right..\n\\end{equation*}\n%\nThen we can determine $v_1^\\pi(s_1)$ for any policy by recursively evaluating equation~\\eqref{MDP Policy Equations}:\n%\n\\begin{equation}\\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]\\right..\n\\end{equation}\n%\nEquation~\\eqref{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\nThe principle of optimality \\citep{Bellman.1954} allows to construct $\\pi^*$ by solving the optimality equations \\eqref{MPD Optimality} for all $s$ and $t$ recursively:\n%\n\\begin{equation}\\label{MPD Optimality}\n\tv^{\\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]\\right. \\bigg\\}.\n\\end{equation}\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{equation*}\n\ta^{\\pi^*}_t(s_t) = \\argmax_{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]\\right. \\bigg\\}.\\\\\n\\end{equation*}\n\n\\autoref{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 \\eqref{MPD Optimality} as the calculation of their expected future utilities is straightforward given the relevant transition probabilities.\n\n\\floatname{algorithm}{\\sffamily\\small Algorithm}\n%\\vspace{0.5cm}%\n\\begin{algorithm}[t]\n\t\\caption{\\small\\!\\textbf{.\\:\\:}\\textsf{\\strut Backward induction procedure}}\\label{Backward induction procedure}\n\t\\begin{algorithmic}\\vspace{0.3cm}\n\t\t\\For{$t = T, \\hdots, 1$}\n\t\t\\If{t = T}\n\t\t\\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\t\t\\Else\n\t\t\\State Compute $v^{\\pi^*}_t(s_t)$ for each $s_t\\in S$ by\n\t\t\\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]\\right. \\bigg\\}.$\n\t\t\\State and set\n\t\t\\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]\\right. \\bigg\\}.$\n\t\t\\EndIf\n\t\t\\EndFor\n\t\t\\vspace{0.3cm}\\end{algorithmic}\n\\end{algorithm}\\FloatBarrier\n", "meta": {"hexsha": "7cab52681ed542e7de720ab2ad09ff39ad6c8737", "size": 4260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/s-setup-mathematics.tex", "max_stars_repo_name": "OpenSourceEconomics/handout-eckstein-keane-wolpin-models", "max_stars_repo_head_hexsha": "68cc55540c8b8772a3b204b7ba063fb324b08fdb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/sections/s-setup-mathematics.tex", "max_issues_repo_name": "OpenSourceEconomics/handout-eckstein-keane-wolpin-models", "max_issues_repo_head_hexsha": "68cc55540c8b8772a3b204b7ba063fb324b08fdb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-03-05T07:53:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-30T11:59:58.000Z", "max_forks_repo_path": "paper/sections/s-setup-mathematics.tex", "max_forks_repo_name": "OpenSourceEconomics/handout-eckstein-keane-wolpin-models", "max_forks_repo_head_hexsha": "68cc55540c8b8772a3b204b7ba063fb324b08fdb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-17T17:09:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T19:27:05.000Z", "avg_line_length": 81.9230769231, "max_line_length": 866, "alphanum_fraction": 0.6840375587, "num_tokens": 1343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6765935985211698}}
{"text": "% section8\r\n\r\n\\chapter{Diagonalization}\r\n\r\n%8.1\r\n\\section{Matrix Representations of Linear Transformations}\r\n\r\n\\begin{exer}Let $T : \\mathbb{R}^{5} \\rightarrow \\mathbb{R}^{3}$ be the linear operator given by the formula\r\n$$T(x_{1}, x_{2}, x_{3}, \\hspace{1mm} x_{4}, x_{5}) = (7x_{1}+12x_{2}-5x_{3}, \\hspace{1mm} 3x_{1}+10x_{2}+13x_{4}+x_{5}, \\hspace{1mm} -9x_{1}-x_{3}-3x_{5})$$\r\nand let $B = \\{\\mathbf{v}_{1}, \\hspace{1mm} \\mathbf{v}_{2}, \\hspace{1mm} \\mathbf{v}_{3}, \\hspace{1mm} \\mathbf{v}_{4}, \\hspace{1mm} \\mathbf{v}_{5}\\}$ and $B' = \\{\\mathbf{v}'_{1}, \\hspace{1mm} \\mathbf{v}'_{2}, \\hspace{1mm} \\mathbf{v}'_{3}\\}$ be the bases for $\\mathbb{R}^{5}$ and $\\mathbb{R}^{3}$, respectively, in which $\\mathbf{v}_{1} = (1, \\hspace{1mm} 1, \\hspace{1mm} 0, \\hspace{1mm} 0, \\hspace{1mm} 0)$, $\\mathbf{v}_{2} = (0, \\hspace{1mm} 1, \\hspace{1mm} 1, \\hspace{1mm} 0, \\hspace{1mm} 0)$, $\\mathbf{v}_{3} = (0, \\hspace{1mm} 0, \\hspace{1mm} 1, \\hspace{1mm} 1, \\hspace{1mm} 0)$, $\\mathbf{v}_{4} = (0, \\hspace{1mm} 0, \\hspace{1mm} 0, \\hspace{1mm} 1, \\hspace{1mm} 1)$, $\\mathbf{v}_{5} = (1, \\hspace{1mm} 0, \\hspace{1mm} 0, \\hspace{1mm} 0, \\hspace{1mm} 1)$, $\\mathbf{v}'_{1} = (1, \\hspace{1mm} 2, \\hspace{1mm} -1)$, $\\mathbf{v}'_{2} = (2, \\hspace{1mm} 1, \\hspace{1mm} 3)$, and $\\mathbf{v}'_{3} = (1, \\hspace{1mm} 1, \\hspace{1mm} 1)$.\r\n\r\n\\vspace{2mm}\r\n\\begin{enumerate}\r\n\r\n\\item[(a)]\r\nFind the matrix $[T]_{\\tiny{B}', \\tiny{B}}$.\r\n\\vspace{1mm}\r\n\\item[(b)]\r\nFor the vector $\\mathbf{x} = (3, \\hspace{1mm} 7, \\hspace{1mm} -4, \\hspace{1mm} 5, \\hspace{1mm} 1)$, find $[\\mathbf{x}]_{\\tiny{B}}$ and use the matrix obtained in part~(a) to compute $[T(\\mathbf{x})]_{\\tiny{B}'}$.\r\n\\vspace{1mm}\r\n\\item[(c)] Find the factorization of [$T$] which is the standard matrix for the linear transformation $T$ using Formula (28) in Section 8.1.\r\n\\end{enumerate}\r\n\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\vspace{1mm}\r\n\r\n\\begin{enumerate}\r\n\r\n\\vspace{1mm}\r\n\\verb\"\"\r\n\\item[(a)]\r\n\\begin{verbatim}\r\nv1 = [1 1 0 0 0]'; v2 = [0 1 1 0 0]'; v3 = [0 0 1 1 0]';\r\nv4 = [0 0 0 1 1]'; v5 = [1 0 0 0 1]';\r\nnv1 = [1 2 -1]'; nv2 = [2 1 3]'; nv3 = [1 1 1]';\r\n\r\nT = [7 12 -5 0 0; 3 10 0 13 1; -9 0 -1 0 -3];\r\nB1 = [v1 v2 v3 v4 v5]; B2 = [nv1 nv2 nv3];\r\nformat short;\r\n\r\n% Find the matrix representation with respect to the bases B1 and B2.\r\nTB = T*B1;\r\nTB1B2 = B2\\TB;\r\n\r\ndisp('The matrix representation of T with respect to the basis B1 and B2 is');\r\ndisp(TB1B2);\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe matrix representation of T with respect to the basis B1 and B2 is\r\n   34.0000    5.0000  -22.0000  -11.0000   22.0000\r\n   40.0000    2.0000  -40.0000  -25.0000   25.0000\r\n  -95.0000   -2.0000   97.0000   61.0000  -65.0000\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n% Find the coordinate vector of x with respect to the basis B1.\r\nx = [3 7 -4 5 1]';  x_B1 = B1\\x; \r\ndisp('The coordinate vector of x with respect to the basis B is');\r\ndisp(x_B1');\r\n\r\n% Find the coordinate vector of T(x) with respect to the basis B2.\r\nTx_B2 = TB1B2 * x_B1;\r\ndisp('The coordinate vector of T(x) with respect to the basis B'' is');\r\ndisp(Tx_B2');\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe coordinate vector of x with respect to the basis B is\r\n     9    -2    -2     7    -6\r\n\r\nThe coordinate vector of T(x) with respect to the basis B' is\r\n  131.0000  111.0000 -228.0000\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\\item[(c)]\r\n\\begin{verbatim}\r\n% Transition matrix from B to the standard basis for R^n.\r\nU=B1;\r\n\r\n% Transition matrix from B' to the standard basis for R^m.\r\nV=B2; \r\n\r\nT=[7 12 -5 0 0 ; 3 10 0 13 1; -9 0 -1 0 -3];\r\n\r\ndisp('V'); disp(V);\r\ndisp('TB1B2'); disp(TB1B2);\r\ndisp('inv(U)'); disp(inv(U));\r\ndisp('V*TB1B2*inv(U)');disp(V*TB1B2*inv(U));\r\ndisp('T'); disp(T);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nV\r\n     1     2     1\r\n     2     1     1\r\n    -1     3     1\r\n\r\nTB1B2\r\n   34.0000    5.0000  -22.0000  -11.0000   22.0000\r\n   40.0000    2.0000  -40.0000  -25.0000   25.0000\r\n  -95.0000   -2.0000   97.0000   61.0000  -65.0000\r\n\r\ninv(U)\r\n    0.5000    0.5000   -0.5000    0.5000   -0.5000\r\n   -0.5000    0.5000    0.5000   -0.5000    0.5000\r\n    0.5000   -0.5000    0.5000    0.5000   -0.5000\r\n   -0.5000    0.5000   -0.5000    0.5000    0.5000\r\n    0.5000   -0.5000    0.5000   -0.5000    0.5000\r\n\r\nV*TB1B2*inv(U)\r\n    7.0000   12.0000   -5.0000         0         0\r\n    3.0000   10.0000         0   13.0000    1.0000\r\n   -9.0000   -0.0000   -1.0000   -0.0000   -3.0000\r\n\r\nT\r\n     7    12    -5     0     0\r\n     3    10     0    13     1\r\n    -9     0    -1     0    -3\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\r\n\r\n%8.2 \r\n\r\n\r\n\\section{Similarity and Diagonalizability}\r\n\r\n\r\n\\begin{exer}\r\n\r\n\\begin{enumerate}\r\n\\item[(a)] Show that the matrix\r\n$$A = \\begin{bmatrix}-13&\\hspace{1mm} -60&\\hspace{1mm} -60\\\\ 10 & 42 & 40\\\\ -5 & -20 & -18 \\end{bmatrix}$$\r\nis diagonalizable by finding the nullity of $\\lambda I - A$ for each eigenvalue $\\lambda$ with the use of Theorem 8.2.11 in the Section 8.2.\r\n\\item[(b)] Find a basis for $\\mathbb{R}^{3}$ consisting of eigenvectors of $A$.\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\verb\"\"\r\n\\begin{enumerate}\r\n\\item[(a)]\r\n\\begin{verbatim}\r\n% For the exact computation of the eigenvalues, \r\n% we use symbolic computation. \r\n\r\n% Set A as a symbolic matrix.\r\nA = sym([-13 -60 -60; 10 42 40; -5 -20 -18]); \r\n\r\nn = length(A);\r\n\r\n% Find the eigenvalues of A by using the command eig.\r\neigenvalues = eig(A); \r\n\r\nfor j = 1 : n\r\n    fprintf('The eigenvalue lambda is '); disp(eigenvalues(j));\r\n    \r\n    % nullity(lambda*I - A) = n - rank(lambda*I - A);\r\n    nullity = n - rank((eigenvalues(j) * eye(n)) - A);\r\n    \r\n    fprintf('The nullity of (lambda*I - A) is '); disp(nullity);\r\nend\r\n\r\n% Since the geometric multiplicity of each eigenvalue of A \r\n% is the same as the algebraic multiplicity,\r\n% by the Theorem 8.2.11, A is diagonalizable.\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe eigenvalue lambda is 2\r\nThe nullity of (lambda*I - A) is      2\r\nThe eigenvalue lambda is 2\r\nThe nullity of (lambda*I - A) is      2\r\nThe eigenvalue lambda is 7\r\nThe nullity of (lambda*I - A) is      1\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n% Since the eigenvalue = 2 of A has the multiplicity = 2, \r\n% find two linearly independent eigenvectors of A corresponding to lambda = 2.\r\n\r\n%Find a basis for the null space of (2*I-A).\r\neigvec12=null((2 * eye(n)) - A);\r\n\r\n% Since the eigenvalue = 7 of A has the multiplicity = 1, \r\n% find an eigenvector of A corresponding to lambda = 7.\r\n\r\n%Find a basis for the null space of (7*I-A).\r\neigvec3=null((7 * eye(n)) - A);\r\n\r\np1 = eigvec12(:, 1); p2 = eigvec12(:, 2); p3 = eigvec3(:, 1); \r\n\r\n% By the Theorem 8.2.7, since the eigenvectors corresponding to \r\n% distinct eigenvalues are linearly independent,\r\n% the three obtained eigenvectors {p1, p2, p3} form a basis for R^{3}.\r\n\r\ndisp('A basis {p1, p2, p3} for R^{3} consisting of the eigenvectors of A is');\r\nfprintf('p1 ='); disp(p1'); \r\nfprintf('p2 ='); disp(p2'); \r\nfprintf('p3 ='); disp(p3');\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nA basis {p1, p2, p3} for R^{3} consisting of the eigenvectors of A is\r\np1 =[ -4, 1, 0]\r\np2 =[ -4, 0, 1]\r\np3 =[ 3, -2, 1]\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n% 8.3\r\n\\section{Orthogonal Diagonalizability; Functions of a Matrix}\r\n\r\n\r\n\\begin{exer}\r\n\\begin{enumerate}\r\nLet\r\n$$A=\\begin{bmatrix}\\frac{1}{2} & 0 & \\frac{3}{2} & 0 \\\\ 0 & \\frac{1}{2} & 0 & \\frac{3}{2} \\\\ \\frac{3}{2} & 0 & \\frac{1}{2} & 0 \\\\ 0 & \\frac{3}{2} & 0 & \\frac{1}{2}\\end{bmatrix}.$$\r\n\\begin{enumerate}\r\n\\item[(a)]\r\nFind a matrix $P$ that orthogonally diagonalizes the matrix $A$. You may use the MATLAB command \\textit{eig} and perform the Gram-Schmidt process. Use your result to find a diagonal matrix $D$ satisfying $A=PDP^{T}$.\r\n\\vspace{1mm}\r\n\\item[(b)]\r\nConfirm that the matrix $A$ satisfies its characteristic equation, in accordance with the Cayley-Hamilton theorem. You may use the symbolic object to find the characteristic polynomial and use the MATLAB command \\textit{coeffs} to find the coefficient of obtained characteristic polynomial.\r\n\\vspace{1mm}\r\n\\item[(c)]\r\n%Compute $e^{A}$ as given in Example 5 of Section 8.3. Compare the result with the MATLAB syntax \\textit{exp(A)}.\r\n%\\item[(d)]\r\nFind the spectral decomposition of $A$.\r\n\\end{enumerate}\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\nA=[1/2 0 3/2 0; 0 1/2 0 3/2; 3/2 0 1/2 0; 0 3/2 0 1/2];\r\n\r\n% V: eigen vector, D: eigen value\r\n[V D]=eig(A);\r\n\r\n% Gram-Schmidt process\r\nP=GS_process(V);    \r\ndisp('P is'); disp(P);\r\ndisp('D is'); disp(D);\r\ndisp('P_transpose is'); disp(P');\r\ndisp('P*D*P_transpose is'); disp(P*D*P');\r\ndisp('A is'); disp(A);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nP is\r\n   -0.7071         0         0   -0.7071\r\n         0    0.7071    0.7071         0\r\n    0.7071         0         0   -0.7071\r\n         0   -0.7071    0.7071         0\r\n\r\nD is\r\n    -1     0     0     0\r\n     0    -1     0     0\r\n     0     0     2     0\r\n     0     0     0     2\r\n\r\nP_transpose is\r\n   -0.7071         0    0.7071         0\r\n         0    0.7071         0   -0.7071\r\n         0    0.7071         0    0.7071\r\n   -0.7071         0   -0.7071         0\r\n\r\nP*D*P_transpose is\r\n    0.5000         0    1.5000         0\r\n         0    0.5000         0    1.5000\r\n    1.5000         0    0.5000         0\r\n         0    1.5000         0    0.5000\r\n\r\nA is\r\n    0.5000         0    1.5000         0\r\n         0    0.5000         0    1.5000\r\n    1.5000         0    0.5000         0\r\n         0    1.5000         0    0.5000\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n% Symbolic variable lambda\r\nsyms lambda;    \r\n\r\n% Characteristic polynomial\r\nchar_poly=det(lambda*eye(size(A))-A); \r\n\r\n% Expand the characteristic polynomial cf. simplify\r\npolynomial=expand(char_poly);   \r\n\r\n% Coefficients extraction\r\ncoeff=coeffs(polynomial); \r\n\r\n% According to the descending order of lambda degree\r\ncoefficient=coeff(end:-1:1); \r\n\r\n % Compute the matrix polynomial\r\npoly_A=polyvalm(double(coefficient), A);\r\n\r\ndisp('Coefficients of the matrix characteristic polynomial is');\r\ndisp(double(coefficient));\r\ndisp('Matrix characteristic polynomial is'); disp(poly_A);\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nCoefficients of the matrix characteristic polynomial is\r\n     1    -2    -3     4     4\r\n\r\nMatrix characteristic polynomial is\r\n     0     0     0     0\r\n     0     0     0     0\r\n     0     0     0     0\r\n     0     0     0     0\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\item[(c)]\r\n\\begin{verbatim}\r\n[V D]=eig(A);\r\nsum_A=0;\r\nfor i=1:size(A,1);\r\n  % spectral decomposition\r\n  sum_A=sum_A+D(i,i)*V(:,i)*V(:,i)'; \r\n\r\n  fprintf('lambda_%d is %f \\n', i, D(i,i));\r\n  fprintf('corresponding u_%d is \\n', i);\r\n  disp(V(:,i));\r\nend\r\n\r\ndisp('spectral decomposition of A is'); disp(sum_A);\r\ndisp('A is'); disp(A);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\nlambda_1 is -1.000000\r\ncorresponding u_1 is\r\n   -0.7071\r\n         0\r\n    0.7071\r\n         0\r\n\r\nlambda_2 is -1.000000\r\ncorresponding u_2 is\r\n         0\r\n    0.7071\r\n         0\r\n   -0.7071\r\n\r\nlambda_3 is 2.000000\r\ncorresponding u_3 is\r\n         0\r\n    0.7071\r\n         0\r\n    0.7071\r\n\r\nlambda_4 is 2.000000\r\ncorresponding u_4 is\r\n   -0.7071\r\n         0\r\n   -0.7071\r\n         0\r\n\r\nspectral decomposition of A is\r\n    0.5000         0    1.5000         0\r\n         0    0.5000         0    1.5000\r\n    1.5000         0    0.5000         0\r\n         0    1.5000         0    0.5000\r\n\r\nA is\r\n    0.5000         0    1.5000         0\r\n         0    0.5000         0    1.5000\r\n    1.5000         0    0.5000         0\r\n         0    1.5000         0    0.5000\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\r\n\\end{exer}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n% 8.4\r\n\r\n\r\n\r\n\\section{Quadratic Forms}\r\n\r\n\r\n\\begin{exer}(\\textit{Cholesky Factorization})\\\\\r\nIn this problem, we find a Cholesky factorization of the Hilbert matrix\r\n$$A=\\begin{bmatrix}1 & 1/2 & 1/3 & 1/4\\\\ 1/2 & 1/3 & 1/4 & 1/5 \\\\ 1/3 & 1/4 & 1/5 & 1/6 \\\\ 1/4 & 1/5 & 1/6 & 1/7\\end{bmatrix}.$$\r\nTo generate the Hilbert matrix, you may use the MATLAB command \\textit{hilb}.\r\n\\begin{enumerate}\r\n\\item[(a)] Show that $A$ is positive definite symmetric matrix by finding its eigenvalues and the MATLAB command \\textit{issymmetric}.\r\n\\vspace{1mm}\r\n\\item[(b)] Make a function file \\verb\"ludecomp.m\" to find the $LU$-decomposition of an invertible $n \\times n$ matrix $A$ such that $A$ can be reduced to row echelon form by Gaussian elimination without row interchanges. You may refer to the four steps given in Page 157. Check your result by applying this function for the matrix given in the Example 2 of the Section 3.7.\r\n\\vspace{1mm}\r\n\\item[(c)] Referring to the Section 3.7, find the $LDU$-factorization of $A$ from an $LU$-factorization of $A$ by \\verb\"ludecomp.m\".\r\n\\vspace{1mm}\r\n\\item[(d)] From the $LDU$-factorization of $A$ obtained in (c), find a Cholesky factorization $A=R^{T}R$, where $R$ is upper triangular.\r\n\\vspace{1mm}\r\n\\item[(e)] Use the MATLAB command \\textit{chol} to find a Cholesky factorization of $A$. Compare it with the result obtained in (d).\r\n\\end{enumerate}\r\n\r\n\r\n\\begin{sol}\r\n\\verb\"\"\r\n\\begin{enumerate}\r\n\\item[(a)]\r\n\\begin{verbatim}\r\nformat rat;\r\nA=hilb(4);\r\n\r\neig_val=eig(A);\r\nif all(eig_val>0) && issymmetric(A)==1\r\n    disp('Given matrix A is'); disp(A);\r\n    disp('A is symmetric and positive definite matrix.');\r\n    fprintf('eigen value of A is '); disp(eig_val');\r\nend\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\nGiven matrix A is\r\n       1              1/2            1/3            1/4\r\n       1/2            1/3            1/4            1/5\r\n       1/3            1/4            1/5            1/6\r\n       1/4            1/5            1/6            1/7\r\n\r\nA is symmetric and positive definite matrix.\r\neigen value of A is    66/682507   101/14989   262/1549   3500/2333\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n%--- This is a function file 'ludecomp.m' ---%\r\nfunction [L, U] = ludecomp(A)\r\n\r\n% The number of rows and columns of the matrix A.\r\n[nrow, ncol] = size(A); \r\n\r\n% Initialization of U and L.\r\nU = A; L = eye(ncol); \r\n\r\n% Forward Elimination %\r\nfor i=1:nrow\r\n    % Find the first nonzero entry of the ith row.\r\n    for k=i:ncol\r\n        if U(i,k) ~= 0\r\n            break % Terminates the execution of the loop.\r\n        end\r\n    end\r\n    temp1 = U(i,k); % Save U(i,k) in temp.\r\n    U(i,:) = (1/temp1) * U(i,:);\r\n    % Normalize the pivot (i,k)-entry by 1 to the ith row.\r\n    L(i,i) = (1/temp1)^(-1);\r\n    % Place the reciprocal of the multiplier in that position in U.\r\n        if i ~= nrow\r\n        for j=(i+1):nrow\r\n            temp2 = U(j,k); % Save U(j,k) in temp2.\r\n            U(j,:) = ((-temp2) * U(i,:)) + U(j,:);\r\n            % Add minus (j,k)-entry times the ith row to the jth row\r\n            L(j,i) = -(-temp2);\r\n            % Place the negative of the multiplier in that position in U.\r\n        end\r\n    end\r\nend\r\n\\end{verbatim}\r\n\r\n\r\n\\item[(c)]\r\n\\begin{verbatim}\r\n% LU-factorization of A without row interchanges\r\n[L, U] = ludecomp(A); \r\n\r\n% From an LU-factorization of A, we can find the LDU-factorization of A,\r\n% by appropriate normalization of L.\r\nD = diag(diag(L));\r\n\r\nfor i = 1:4\r\n    L(:, i) = L(:, i)./L(i, i);\r\nend\r\n\r\ndisp('The LDU-factorization of A is');\r\ndisp('L = '); disp(L); disp('D = '); disp(D); disp('U = '); disp(U);\r\n\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe LDU-factorization of A is\r\nL =\r\n       1              0              0              0\r\n       1/2            1              0              0\r\n       1/3            1              1              0\r\n       1/4            9/10           3/2            1\r\n\r\nD =\r\n       1              0              0              0\r\n       0              1/12           0              0\r\n       0              0              1/180          0\r\n       0              0              0              1/2800\r\n\r\nU =\r\n       1              1/2            1/3            1/4\r\n       0              1              1              9/10\r\n       0              0              1              3/2\r\n       0              0              0              1\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\item[(d)]\r\n\\begin{verbatim}\r\n% From the LDU-factorization of A, find the Cholesky factor.\r\nR1 = (L*sqrt(D))';\r\ndisp('The Cholesky factor R1 from the LDU-factorization of A is'); \r\ndisp(R1);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe Cholesky factor R1 from the LDU-factorization of A is\r\n       1              1/2            1/3            1/4\r\n       0            390/1351       390/1351       351/1351\r\n       0              0            317/4253       323/2889\r\n       0              0              0            153/8096\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\item[(e)]\r\n\\begin{verbatim}\r\n% Find a Cholesky factorization of A by using the MATLAB command.\r\nR2 = chol(A);\r\ndisp('The Cholesky factor R2 from the MATLAB command chol is'); \r\ndisp(R2);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe Cholesky factor R2 from the MATLAB command chol is\r\n       1              1/2            1/3            1/4\r\n       0            390/1351       390/1351       351/1351\r\n       0              0            317/4253       323/2889\r\n       0              0              0            153/8096\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{exer}\r\n\r\n\r\n", "meta": {"hexsha": "de932d8c315d6023270bc5da1c50dc1eecbd1d40", "size": 17594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section8.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)/section8.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)/section8.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": 27.4477379095, "max_line_length": 935, "alphanum_fraction": 0.5535409799, "num_tokens": 6371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6765733628704457}}
{"text": "\\section{Accessing the data}\nOptimization has also a \\textbf{hardware} component: accessing the data has to be done efficiently, measuring and modeling physical costs. \n\n\\begin{wrapfigure}{L}{0.55\\textwidth}\n\t\\vspace{-15pt}\n\t\\includegraphics[width=0.55\\textwidth]{disk.png}\n\t\\vspace{-25pt}\n\\end{wrapfigure}\n\nOlder devices store memory in a stack of \\textit{rotating disks} on which an arm writes data with its head. Each disk is divided in \\textbf{tracks} and \\textbf{sectors}, of which the outer are longer than the inner.\n\nCylinders are organized in zones: each of them contains a fixed number of consecutive cylinders, with the same amount of sectors per track. \n\nSince the disk is rotating, the throughput is higher on outer cylinders, and reading is only possible where the head is, making this operation quite slow since it is impossible to jump. On SSD, this is indeed implemented.\n\nA good approximation of the \\textbf{seek time} among $d$ cylinders is:\n$$seektime(d) = \\begin{cases}\n\tc_1 + c_2\\sqrt{d} & d \\leq c_0 \\\\\n\tc_3 + c_4d & d> c_0\n\\end{cases}$$\nConstants indicate the maximum number of cylinders where no coast take place, i. e. the point in which the head can be efficient. \n\nThe square is introduced because in the low part of hardware the distance is less, hence the head moves faster. On the other hand, the formula is linear if the distance is short.\n\nSince the current position on the disk is unpredictable, it is difficult to produce single cot estimation, however modeling many accesses gives a somewhat accurate measurement. \n\n\\begin{wrapfigure}{R}{0.5\\textwidth}\n\t\\vspace{-15pt}\n\t\\includegraphics[width=0.5\\textwidth]{parameters.png}\n\t\\vspace{-30pt}\n\\end{wrapfigure}\n\nParameters are aggregated, introducing average latency time (for positioning) and sustained read/write assuming a sequential scan. \n\nThe time a disk needs to read and transfer $n$ bytes is approximately $D_{lat} + \\frac{n}{D_{srr}}$. Examples of these values are given in the table.\n\nDatabase developers, as introduced before, distinguish between \\textbf{random} and \\textbf{sequential} access. The latter is faster, since it assumes data only needs to be \\textit{read in sequence} after finding its position, while a random access implies seeking the location of each page (the smallest portion which can be read, generally 8kb).\n\nExample: to read 100MB, sequential read takes $5ms + 1ms$, while random read has to scan 8k pages and takes $65s$.\n\nThis has consequences in practice: for instance, an index may be efficient only if a \\textit{small portion of the data is accessed}, else there is a risk for the whole structure to be traversed with a random access behavior. On the other hand, it could be expensive to perform a scan if there are many pages involved. \n\n\\subsection{Counting the number of accesses}\nA proposed cost function to calculate sequential scan time is: \n$$5ms + \\frac{\\abs{page\\_size}}{\\abs{bandwidth}} * \\#pages$$\nNow, the problem becomes estimating the bandwidth, the number of needed pages and their cost. These can vary between different use cases, or be influenced by indexes. \n\nMore parameters are introduced for a better overview, assuming a uniform distribution of the tuples:\n\\begin{itemize}\n\t\\item $N$, number of tuples (items) in relation $R$;\n\t\\item $m$, number of pages (buckets) in which tuples of $R$ are stored ($m = 1$ all pages are accessed);\n\t\\item $B = \\frac{N}{m}$, tuples for page (blocking factor);\n\t\\item $k$, number of distinct TID ($k = 1$ implies one page is accessed).\n\\end{itemize}\nThe probability to request a set with $k$ items is $\\frac{1}{{{N}\\choose{k}}}$, because of the uniformity assumption.\n\n\\subsubsection{Yao's formula (direct, uniform, distinct)}\nConsidering $m$ buckets with $n$ items, then there is a total of $N = nm$ items. Randomly selecting $k$ \\textbf{distinct} items give a number of qualifying buckets which is:\n\n$$\\bar{y}^{N, m}_n(k) = m * y^N_n(k)$$\n$$y^N_n(k) = \\begin{cases}\n\t[1 - p] & k \\leq N - n \\\\\n\t1 & k > N - n\n\\end{cases}$$\n$y^N_n(k)$ is the probability that bucket $n$ contains at least one tuple, and $p$ is the probability that a bucket contains none of the $k$ items.\n\\begin{wrapfigure}{R}{0.25\\textwidth}\n\t\\vspace{-25pt}\n\t\\includegraphics[width=0.25\\textwidth]{yao.png}\n\t\\vspace{-30pt}\n\\end{wrapfigure}\n$$p \\quad = \\quad \\frac{{{N-n}\\choose{k}}}{{{N}\\choose{k}}} \\quad = \\quad \\prod_{i=0}^{k-1} \\frac{N-n-i}{N-i} \\quad = \\quad \\prod_{i=0}^{n-1}\\frac{N-k-i}{N-i}$$\nThese formulas are useful to avoid computing $N!$, which is too expensive to do in practice. The choice of formula depends on $N$ and $k$.\n\nHowever, even with simplifications, calculations are not cheap, and fractions may not be integers: further steps must be taken, such as introduction of a Gamma function and approximations (\\textbf{Waters}):\n$$p \\approx \\Big( 1 - \\frac{k}{N} \\Big)^n$$\nThis works implying there is a fraction of $\\frac{k}{N}$ tuples which are relevant for the query, multiplied for the number of pages. The problem here is, if the first tuple does not qualify, the likelihood that a latter one qualifies increases (there is less space); in general, probability is not uniform.\n\nThe estimation is roughly accurate with $N >> n$, and much cheaper to compute. There are other formulas which are simpler, but more complicated to express (\\textbf{Bernstein}):\n$$y_n^{N,m}(k) \\approx \\begin{cases}\n\tk & k < \\frac{m}{2} \\\\\n\t\\frac{k+m}{3} & \\frac{m}{2} \\leq k \\leq 2m \\\\\n\tm & 2m \\leq k\n\\end{cases}$$\nThis evaluation tries to interpolate $k$ depending on its comparison with $m$, and is faster to compute. Each case is plausible, yet not very precise. \n\nDihr and Saharia computed some upper and lower bounds for $p$, claiming these are accurate with a minimal difference from real-case scenarios.\n\n\\subsubsection{Cheung's formula (direct, uniform, non-distinct)}\nIndex nested loop joins often involve reading the same tuple multiple times, fetching join partners using the index. This strategy uses very little memory, with time linear in the left side.\n\nIn this case, Yao's formula is not sufficient, and a \\textbf{multiset} (set with duplicates) approach is introduced. The number of multiset with cardinality $k$ containing only elements from a set $S$ with $\\abs{S} = N$ is:\n$${N+k-1}\\choose{k}$$\n\nThis works transforming a multiset into a set by summing a crescent value from 1 to $(k-1)$ to each element, making them unique. The other way around applies subtraction. \n\nCheung's formula is an extension of Yao's formula considering multisets (not necessarily distinct items among $k$):\n$$\\overline{Cheung}^{N, m}_n(k) = m * Cheung^N_n \\qquad Cheung^N_n(k) = [1 - \\tilde{p}] \\qquad \\tilde{p} \\approx \\Big( 1 - \\frac{n}{N}\\Big)^k$$\n$$\\tilde{p} \\quad = \\quad \\frac{{n-n+k-1\\choose k}}{{n+k-1\\choose k}} \\quad = \\quad \\prod_{i=0}^{k-1} \\frac{N-n+i}{N+i} \\quad = \\quad \\prod_{i=0}^{n-1} \\frac{N-1-i}{N-1+k-i}$$\nThis just expands binomials using the duplicates property. The approximation of $p$ (\\textbf{Cardenas}) is derived assuming there are $1 - \\frac{n}{N}$ tuples on the current page and applying the power.\n\nThe number of \\textbf{distinct} values in a $k$-multiset of cardinality $N$ with uniform distribution is:\n$$D(n, k) = \\frac{Nk}{N + k - 1}$$\nThis follows by previous statements, expanding the binomial coefficient. This allows to do a simplification (\\textit{model switching}), i. e. using Yao's formula after removing duplicates. \n\nNon-uniform distributions work similarly, yet modeling each probability to access a group of buckets, using summation instead of product. \n\n\\subsection{Sequential accesses on disk}\nAccesses on disk are relevant to estimate the cost of \\textbf{jumping between two pages or cylinders}: this directly depends on the distance gap. When estimating seek costs, there must be a probability distribution for the distances.  \n\nAssuming the situation is a \\textbf{bitvector} of length $B$ with $b$ bits set to 1, then $B - b$ bits are zero, and the accesses can be modeled with $B$ corresponding to the number of cylinders while $b$ indicates that a cylinder qualifies.\n\nThen, the probability distribution of the number $j$ of zeros between two consecutive ones, before the first or after the last is:\n$$B^B_b(j) = \\frac{{B-j-1\\choose b-1}}{{B\\choose b}} = \\frac{b}{B-j}\\prod_{i=0}^{j-1} \\Big( 1 - \\frac{b}{B - i}\\Big)$$\nThe distance between two ones is obtained taking the expected value of the number of zeros, and adding one for the potential first or last position.\n\nSome other values can be deduced from this, such as the total number of bits from the first bit to the last one (extremes included), which is:\n$$B_{tot}(B, b) = \\frac{Bb + b}{b + 1}$$\nAll these computations have several real-life applications: the original motivation implies retrieving values from a B-tree and accessing them on disk, sorting the entries to avoid multiple random lookups. A bitvector module gives information about the distance between pages, to understand how expensive a fetch can be.\n\n\\section{Selectivity estimations}\nSelectivity estimation has always been assumed to be known until now, yet it is a statistic which needs to be computed, since it is essential for query optimization.\n\nUnfortunately, this is a \\textit{fundamentally difficult problem}, and can take quite a long time.\n\nSpecifically, there are different selectivity problems requiring different approaches. For arbitrarily difficult queries it is impossible to make an estimation, yet the following three are the most common:\n\n\\begin{lstlisting}[language=SQL]\nSELECT *\nFROM relation r\nWHERE r.a = 10\n\t\nSELECT *\nFROM relation r\nWHERE r.b > 2\n\t\nSELECT *\nFROM relation1 r1, relation2 r2\nWHERE r1.a = r2.b\n\\end{lstlisting}\n\n\\subsection{Heuristic estimations}\nThere are some textbook estimations which are not advanced strategies, depending on the predicate.\n\n\\begin{wrapfigure}{R}{0.6\\textwidth}\n\t\\vspace{-20pt}\n\t\\includegraphics[width=0.6\\textwidth]{selectivity.png}\n\t\\vspace{-30pt}\n\\end{wrapfigure}\n\nKnowing the domain of $A$, for instance, can happen when the column has an \\textbf{index}, yet an uniform distribution must be assumed.\n\nHaving a range query is also helped by an index, since this additional data structure stores the minimum and maximum value, hence selection can be obtained by interpolation. \n\nJoins again depend on indices and domain of the involved tables.\n\n\\subsection{Building histograms}\nHeuristics are quite simple and have the restriction of uniform distribution, so multiple DBMS employ histograms: aggregated data is \\textbf{partitioned in buckets} such that $H_A(b) = |\\{r\\ |\\ r \\in R \\;and R.A \\in b\\}|$ and thus $\\sum_{b \\in B} H_A(b) = \\abs{R}$.\n\nThis methods leads to a much better estimation than previous ones, and computing histograms is also easy since it only involves a sequential scan: the real challenge is selecting the appropriate $B$.\n\nAssuming data is already in buckets, there are formulas giving the appropriate result, applying linear interpolation to the newly obtained histogram:\n$$A = c \\quad \\frac{\\sum_{b \\in B:c \\in b H_A(b)}}{\\sum_{b \\in B}H_A(b)}$$\n$$A > c \\quad \\frac{\\sum_{b \\in B:c \\in b \\frac{max(b) - c}{max(b) - min(b)} H_A(b) + \\sum_{b \\in B:min(b) > c} H_A(b)}}{\\sum_{b \\in B}H_A(b)}$$\n$$A_1 = A_2 \\quad \\frac{\\sum_{b_1 \\in B_1, b_2 \\in B_2, b' = b_1 \\cap b_2: b' \\neq \\emptyset} \\frac{max(b') - min(b')}{max(b_1) - min(b_1)} H_{A_1}(b_1) \\frac{max(b') - min(b')}{max(b_2) - min(b_2)} H_{A_2}(b_2)}{\\sum_{b_1 \\in B_1}H_{A_1}(b_1) \\sum_{b_2 \\in B_2}H_{A_2}(b_2)}$$\n\nThese computations only give an upper bound, while the lower bound can be up to zero, and it is impossible to predict. Furthermore, the upper bound can be quite an overestimation in the first case, which represents only a rough approximation.\n\nThe problem comes from the restriction in the mathematical meaning of $P(A = c) = 0$, which gives a sound result when $A > c$ but fails when the query involves equality. Joining works using some assumptions as well, such as independence.\n\n\\subsubsection{Equiwidth}\nBuilding histograms concerns the previously mentioned issue: finding the optimal number of buckets. Typically, this is a fixed value, and it has to work with an unknown distribution.\n\nOne particular strategy is partitioning the domain into buckets of equal width, simply constructing them from left to right. This is easy to compute, since it does not require boundaries: it is enough to store minimum, maximum and size. \n\nHowever, it fails when data is skewed, causing uneven buckets and therefore a greater estimation error. \n\n\\subsubsection{Equidepth}\nAnother method is the equidepth, forcing each bucket to have the same number of elements, adopting to data distribution. This technique is very common and not too time consuming, so it is widely used in practice.\n\nThe only disadvantages are having to sort the values beforehand, and store boundaries and ties (obviously not the count).\n\n\\subsubsection{Interpolation}\nInterpolation is a technique to improve accuracy, however it can be difficult to interpolate a histogram: a potential solution is using the distribution function instead, which is continuous and monotonic. This works particularly well in the case $A > c$.\n\nFurther research includes analyzing correlations, multi-dimensional histograms and cardinality estimators.", "meta": {"hexsha": "52fb00d930c56ea67d340eff9ffbdaea5120e8b8", "size": 13276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Query Optimization/lectures/accessing_data.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": "Query Optimization/lectures/accessing_data.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": "Query Optimization/lectures/accessing_data.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": 71.7621621622, "max_line_length": 346, "alphanum_fraction": 0.7496233805, "num_tokens": 3513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.6765733554674183}}
{"text": "\\section{Introduction to Proofs}\n\n\\frame{\n{Part 1: Introduction to Proofs.}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=2, sections={2-4}]\n}\n\n\\subsection{What is a Proof?}\n\n\\begin{frame}{What is a proof?}\n\n  Some concepts are easy to understand, but not easy to show that they are true.\\bigskip\n\n  \\begin{columns}\n    \\column{0.3\\textwidth}\n      \\centering\n      \\includegraphics[width=.5\\textwidth]{../img/triangle_rect}\n    \\column{0.7\\textwidth}\n      \\begin{itemize}\n        \\item Pythagoras Theorem:\n        \\begin{equation*}\n          a^2+b^2=c^2\n        \\end{equation*}\n        \\item It is easy to show this is true for {\\bf any one triangle}.\n        \\item But how do you show it is is true for {\\bf all} triangles?\n      \\end{itemize}\n  \\end{columns}\n  \\bigskip\n\n  The proof of the Pythagoras theorem is {not obvious}: there are more than 100 different proofs!\n\\end{frame}\n\n\\begin{frame}{What is a proof?}{One Pythagoras Proof}\n\n  \\begin{columns}[T]\n    \\column{0.7\\textwidth}\n      \\begin{itemize}\n        \\item {\\bf Proof}: by geometric construction\n        \\item Arrange four identical triangles;\n        \\item Show that internal angles are right;\n        \\item Internal square area: $c^2$\n        \\item External square area: $(a+b)^2$\n        \\item $(a+b)^2 = c^2 + 4(\\text{area triangle})$\n        \\item $(a+b)^2 = c^2 + 4(\\frac{ab}{2})$\n        \\item $a^2 + 2ab + b^2 = c^2 + 2ab$\n        \\item $a^2 + b^2 = c^2$ \\hfill $\\blacksquare$\n      \\end{itemize}\n    \\column{0.3\\textwidth}\n      \\includegraphics[width=\\textwidth]{../img/triangle_pytagoras}\n  \\end{columns}\n  \\bigskip\n\n  {\\bf Remember:} There are many other possible proofs.\\\\(Beautiful proofs, short proofs, wrong proofs, etc.)\n\\end{frame}\n\n\\begin{frame}{False Proofs}{Infinite Chocolate!}\n  \\begin{center}\n    \\includegraphics[width=.9\\textwidth]{../img/false_proof}\n  \\end{center}\n  \\begin{itemize}\n    \\item What is wrong with the proof above?\n    \\item \\alert{Be careful!} A false proof can have many correct steps, and {\\bf only one} impossible step.\n  \\end{itemize}\n\n  \\begin{block}{}\n    We can use proofs to show that something is {\\bf incorrect} as well!\n  \\end{block}\n\\end{frame}\n\n\\subsection{Proofs and Computer Science}\n\n\\begin{frame}{Proofs and Computer Science}{Why are proofs important for Computer Science?}\n\n  \\begin{itemize}\n    \\item We don't use proofs only for mathematical equations.\n    \\item We can use proofs to {\\bf show that a program is correct}. (or incorrect)\n    \\vfill\n\n    \\item Example cases:\n    \\begin{itemize}\n    \\item Use proofs to show that the result of a program is correct for any input;\n    \\item Use proofs to show that one type of input will cause a bug in the program;\n    \\item Use proofs to show that a program finishes in $N$ steps;\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}[fragile]{Proofs and Computer Science}{Example:}\n  \\begin{itemize}\n    \\item Is the program below correct or incorrect?\n    \\item Can you show by using a proof?\n  \\end{itemize}\n\n\\begin{verbatim}\nint triangle_type(int a, int b, int c)\n  // a, b, c are the length of the sides of a triangle;\n  if (a == b)\n    if (b == c)\n      return \"all sides are equal\";\n    else\n      return \"two sides are equal\";\n  else if (b == c)\n    return \"two sides are equal\";\n  else\n    return \"all sides are different\";\n\\end{verbatim}\n\\end{frame}\n\n\\subsection{Definitions}\n\n\\begin{frame}{Proof Concepts}{Propositions}\n  A proposition is a statement that is either \\structure{True} or \\alert{False}, and nothing else.\\bigskip\n\n  \\begin{columns}[T]\n    \\column{0.5\\textwidth}\n    \\structure{Proposition}\n    \\begin{itemize}\n      \\item $2 + 3 = 5$\n      \\item $1 + 1 = 3$\n      \\item $513 \\times 435 = 223165$\n      \\item There is no human taller than 3 meters.\n      \\item It rained on October, 3rd, 2020, 10:00 in Tokyo.\n      \\item Emacs is better than Vim.\n    \\end{itemize}\n    \\column{0.5\\textwidth}\n    \\alert{Not proposition}\n    \\begin{itemize}\n      \\item What is $2 \\times 8$?\n      \\item Please give me cake.\n      \\item It is raining now.\n    \\end{itemize}\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}{Proof Concepts}{Predicates}\n  A predicate is a kind of proposition where the truth value depends on one or more variables:\\bigskip\n\n  \\begin{itemize}\n    \\item $P(n)$: $n$ is a prime number;\n    \\item $L(N)$: The name $N$ has five letters;\n    \\item $M(x,y)$: $x$ and $y$ are members of the same group;\n  \\end{itemize}\\vfill\n\n  \\begin{alertblock}{Do not confuse predicates and number expressions!}\n    Numeric expressions have numeric values, predicates have True or False values.\n    \\begin{itemize}\n      \\item $p(x) = x^2 + 3x + 1$.\\hfill This is a numeric expression;\n      \\item $P(X)$: $p(x+1) = p(x) + x + 1$.\\hfill This is a predicate;\n      \\item $P(X)$ is True for any $x \\geq 0$.\\hfill This is a proposition;\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n\n\\begin{frame}{Proof Concepts}{Implication (IF)}\n  An \\structure{implication} is a particular type of predicate that we use a lot, so it is important to know it well:\n  \\begin{center}\n    $P \\implies Q$\n  \\end{center}\n  There are many ways to describe the implication:\n  \\begin{itemize}\n    \\item $I(P,Q)$: If P is true, Q is true;\n    \\item $I(P,Q)$: When P is true, Q is true;\n  \\end{itemize}\n  We usually don't write the $I(P,Q)$ part, but it is important to remember that the \\structure{implication} itself is a predicate.\n  \\bigskip\n\n  \\begin{itemize}\n    \\item \\alert{Be Careful!} When P is false, Q could be anything.\n    \\item A related predicate is {\\bf If and only If (iff)}:\n    \\begin{itemize}\n      \\item IFF(P,Q): $P\\implies Q$ AND $Q\\implies P$.\n      \\item also written as $P\\iff Q$\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Proof Concepts}{Proof Methods}\n  How do we prove something?\n  \\begin{block}{Proposition}\n    For every nonnegative integer $n$, the value of $p(n) = n^2+n+41$ is prime.\n  \\end{block}\\medskip\n\n  We could try to test values of $n$ one by one:\n  \\begin{center}\n    $p(0) = 41$, prime; $p(1) = 43$, prime; $p(2) = 47$, prime; $\\ldots$, $p(20) = 461$, prime...\n  \\end{center}\\medskip\n\n  \\begin{itemize}\n    \\item When do we stop?\n    \\item ($p(40) = 41\\times41$, is not prime...)\n  \\end{itemize}\n  We need better ways to prove propositions!\n\\end{frame}\n", "meta": {"hexsha": "f574793d922f9d327bfe23595f977806b241f383", "size": 6308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week01/01_IntroToProofs.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week01/01_IntroToProofs.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week01/01_IntroToProofs.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": 32.3487179487, "max_line_length": 131, "alphanum_fraction": 0.6537729867, "num_tokens": 1936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.6765733542126032}}
{"text": "\\section{Risk estimation}\\label{sec:RiskEstimators}\n\nLet~$\\func{\\dec}{\\domainX}{\\real}$ be a decision function from feature vector~$\\X$ to a real number, and let~$\\func{\\loss}{\\domainX \\times \\domainY}{\\real_{{\\geq}0}}$ be the loss function.  \\textit{Risk estimator},~$\\risk$,\\footnote{Although expected risk~$\\risk$ is a function of~$\\dec$ as shown in Eq.~\\eqref{eq:RiskEstimator:Expectation}, we drop~$\\dec$ from our notation for brevity going forward.} quantifies $\\dec$'s~expected loss formally as\n\n\\begin{equation}\\label{eq:RiskEstimator:Expectation}\n  \\risk(\\dec) = \\mathbb{E}_{(\\X,\\y) \\sim \\joint}\\sbrack{\\floss{\\decX}{\\y}}\\text{.}\n\\end{equation}\n\nSince $\\joint$~is unknown, $\\risk$~is also unknown so in practice empirical estimate~$\\emprisk$ is used.  This section provides an overview of the PN, PU (specifically nnPU), and PUbN risk estimators as well as their empirical estimates.\\footnote{All empirical risk estimates described here support both batch and stochastic gradient descent.}\n\n\\subsection{PN --- positive-negative}\n\nPN~classification has access to both positive and negative labeled examples.  Therefore, Eq.~\\eqref{eq:RiskEstimator:Expectation} exactly specifies its expected risk.\n\n\\paragraph{Empirical Estimation} Estimating the PN~empirical risk is straightforward as shown in Eq.~\\eqref{eq:EmpRisk:PN}; it is merely the mean loss for all examples in~$\\train$.  This formulation applies irrespective of any covariate shift/bias.\n\n\\begin{equation}\\label{eq:EmpRisk:PN}\n  \\emprisk = \\frac{1}{\\abs{\\train}} \\sum_{(\\X,\\y) \\in \\train} \\floss{\\decX}{\\y}\n\\end{equation}\n\n\\subsection{nnPU --- non-negative positive-unlabeled}\n\nSince positive\\-/unlabeled~(PU) learning has no negative labeled examples, traditional supervised learning cannot be used. By Bayes' Rule, the expected risk can be decomposed into the risk associated with each label (positive and negative) as shown in Eq.~\\eqref{eq:Risk:Bayes}.  ${\\varrisk{D}{\\ypred}}$ denotes the expected loss when predicting label~$\\ypred$ for samples drawn from distribution~${\\pDist_{D}}$ where ${D \\in \\set{\\textnormal{P}, \\textnormal{N}, \\X}}$.\n\n\\begin{align}\n  \\risk &= \\prior \\mathbb{E}_{\\X \\sim \\pcond}\\sbrack{\\floss{\\decX}{\\pcls}} + (1-\\prior) \\mathbb{E}_{\\X \\sim \\ncond}\\sbrack{\\floss{\\decX}{\\ncls}} \\nonumber \\\\\n        &= \\prior \\prisk{P} + (1-\\prior) \\nrisk{N} \\label{eq:Risk:Bayes}\n\\end{align}\n\nSince the unlabeled set is drawn from marginal distribution,~$\\marginal$, it is clear that:\n\n\\begin{align}\n  \\nrisk{U} &= \\mathbb{E}_{\\X \\sim \\marginal} \\sbrack{\\floss{\\X}{\\ncls}} \\nonumber \\\\\n            &= \\prior \\mathbb{E}_{\\X \\sim \\pcond} \\sbrack{\\floss{\\X}{\\ncls}} + (1 - \\prior) \\mathbb{E}_{\\X \\sim \\ncond} \\sbrack{\\floss{\\X}{\\ncls}}\\nonumber \\\\\n            &= \\prior \\nrisk{P} + (1 - \\prior) \\nrisk{N} \\label{eq:Risk:Unlabeled}\n\\end{align}\n\n\\noindent\nRearranging the above and combining it with Eq.~\\eqref{eq:Risk:Bayes} yields the unbiased positive\\-/unlabeled~(uPU) risk estimator below.~\\cite{duPlessis:2014}\n\n\\begin{equation}\\label{eq:Risk:uPU}\n  \\risk = \\prior \\prisk{P} + \\nrisk{U} - \\prior \\nrisk{P}\n\\end{equation}\n\n\\paragraph{Non\\-/negativity} By the definitions of~$\\loss$ and~$\\risk$, it is clear that $\\nrisk{N}$~must be non\\-/negative.  However, highly expressive learners (e.g.,~neural networks) often cause ${\\nrisk{U} - \\prior \\nrisk{P}}$ to slip negative --- primarily due to overfitting.  Kiryo\\etal~\\cite{Kiryo:2017} proposed the non\\-/negative positive\\-/unlabeled~(nnPU) risk estimator in Eq.~\\eqref{eq:Risk:nnPU}; the primary difference versus uPU is the negative risk surrogate is explicitly forced non\\-/negative by the~$\\max$.\n\n\\begin{equation}\\label{eq:Risk:nnPU}\n  \\risk = \\prior \\prisk{P} + \\max\\left\\{0, \\nrisk{U} - \\prior \\nrisk{P} \\right\\}\n\\end{equation}\n\nWhenever the negative risk surrogate is less than~0, nnPU updates the model parameters using special gradient ${\\gamma \\nabla_{\\theta} \\prior \\nrisk{P} - \\nrisk{U}}$ where hyperparameter~${\\gamma \\in (0,1]}$ attenuates the learning rate.  Observe that the negative risk surrogate is deliberately negated; this is done to ``defit'' the learner so that it no longer underestimates the negative class' expected risk.\n\nAlthough forcing~$\\nrisk{N}$'s surrogate to be non-negative introduces an estimation bias (i.e.,~expected value does not equal the true expectation), nnPU often performs better in practice and guarantees ERM uniform convergence.\n\n\\paragraph{Empirical Estimation} Each risk term in nnPU can be empirically estimated from the training set where:\n\n\\begin{equation}\\label{eq:EmpRisk:Pos}\n  \\evrisk{P}{\\ypred} = \\frac{1}{\\abs{\\ptrain}} \\sum_{\\X \\in \\ptrain} \\floss{\\decX}{\\ypred}\n\\end{equation}\n\n\\noindent\nand for unlabeled set ${\\utrain \\sim \\marginal}$,\n\n\\begin{equation}\n  \\evrisk{U}{-} = \\frac{1}{\\abs{\\utrain}} \\sum_{\\X \\in \\utrain} \\floss{\\decX}{\\ncls} \\text{.}\n\\end{equation}\n\n\\noindent\nPrior~$\\prior$ and attenuator~$\\gamma$ are hyperparameters.\n\n\\subsection{PUbN --- positive, unlabeled, biased-negative}\n\nLet $\\latent$~be a latent random variable representing whether tuple~${(\\X,\\y)}$ is eligible for labeling.  The joint distribution,~${\\trijoint = \\pDist(\\X, \\y, \\latent)}$, then becomes trivariate.  By definition, ${\\pDist(\\latent = \\pcls \\vert \\X, \\y = \\pcls) = 1}$ (i.e.,~no positive selection bias) or equivalently ${\\pDist(\\y = \\ncls \\vert \\X, \\latent = \\ncls) = 1}$.  The biased-negative conditional distribution is therefore~${\\bncond = \\pDist(\\X \\vert \\y = \\ncls, \\latent = \\pcls)}$.\n\nThe marginal distribution can be partitioned as\n\n\\begin{equation*}\n  \\begin{aligned}\n    \\marginal = &\\pDist(\\y = \\pcls) \\pDist(\\X \\vert \\y = \\pcls) \\\\\n                &+ \\underbrace{\\pDist(\\y = \\ncls, \\latent = \\pcls)}_{\\plabel}\\pDist(\\X \\vert \\y = \\ncls, \\latent = \\pcls)\n                + \\underbrace{\\pDist(\\y = \\ncls, \\latent = \\ncls)}_{1 - \\prior - \\plabel} \\pDist(\\X \\vert \\y = \\ncls, \\latent = \\ncls)\n  \\end{aligned}\n\\end{equation*}\n\n\\noindent\nwhere ${\\plabel = \\pDist(\\y = \\ncls, \\latent = \\pcls)}$ is a hyperparameter. The expected risk therefore becomes\n\n\\begin{equation}\\label{eq:Risk:WithBN}\n  \\risk = \\prior \\prisk{P} + \\plabel \\nrisk{bN} + (1 - \\prior - \\rho) \\smrisk\n\\end{equation}\n\nDefine ${\\sigma(\\X) = \\pDist(\\latent = \\pcls \\vert \\X)}$.  While the proof is well beyond the scope of this document, Hsieh\\etal~\\cite{Hsieh:2018} proved that with guaranteed estimation error bounds $\\smrisk$~decomposes as\n\n\\begin{equation}\\label{eq:ExpectedRisk:PUbN:Latent}\n  \\begin{aligned}\n    \\smrisk = &\\mathbb{E}_{\\X \\sim \\marginal}\\sbrack{\\mathbbm{1}_{\\sigX \\leq \\eta} \\floss{\\decX}{\\ncls} \\sigdiff} \\\\\n              &+ \\prior \\mathbb{E}_{\\X \\sim \\pcond} \\sbrack{\\mathbbm{1}_{\\sigX > \\eta} \\floss{\\decX}{\\ncls} \\frac{\\sigdiff}{\\sigX}} \\\\\n              &+ \\plabel \\mathbb{E}_{\\X \\sim \\bncond} \\sbrack{\\mathbbm{1}_{\\sigX > \\eta} \\floss{\\decX}{\\ncls} \\frac{\\sigdiff}{\\sigX}}\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nwhere $\\mathbbm{1}$~is the indicator function and $\\eta$~is a hyperparameter that controls the importance of unlabeled data versus $\\textnormal{P}$/$\\textnormal{bN}$ data.\n\n\\paragraph{Empirical Estimation} Similar to nnPU, $\\prisk{P}$~and~$\\nrisk{bN}$ can be estimated directly from~$\\ptrain$ and~$\\bntrain$ respectively.  Estimating~$\\smrisk$ is more challenging and actually requires the training of two classifiers.\n\nFirst, $\\sigX$~is empirically estimated by training a positive\\-/unlabeled probabilistic classifier with labeled set ${\\ptrain \\sqcup \\bntrain}$ and unlabeled set~$\\utrain$; refer to this learned approximation as~$\\hsigX$.  Probabilistic classifiers must be adequately calibrated to generate probabilities.  Hsieh\\etal\\ try to achieve this by training with the logistic loss but that provides no calibration guarantees.~\\cite{Guo:2017}\n\nRather than specifying hyperparameter~$\\eta$ directly, Hsieh\\etal\\ instead specified hyperparameter~$\\tau$ to calculate~$\\eta$ via\n\n\\begin{equation}\\label{eq:EtaCalculation}\n  \\abs{\\setbuild{\\X \\in \\utrain}{\\hsigX \\leq \\eta}} = \\tau (1 - \\prior - \\plabel)\\abs{\\utrain} \\text{.}\n\\end{equation}\n\n\\noindent\nThis approach provides a more intuitive view into the balance between~$\\utrain$ and $\\ptrain$/$\\bntrain$.\n\nPUbN's second classifier minimizes Eq.~\\eqref{eq:Risk:WithBN} and empirically estimates the risk when ${\\latent = \\ncls}$ as\n\n\\begin{equation}\\label{eq:EmpRisk:PUbN:Latent}\n  \\begin{aligned}\n    \\smrisk = &\\frac{1}{\\abs{\\utrain}} \\sum_{\\xvar{U} \\in \\utrain} \\sbrack{\\mathbbm{1}_{\\hsig(\\xvar{U}) \\leq \\eta} \\floss{\\dec(\\xvar{U})}{\\ncls} \\big(1 - \\hsig(\\xvar{U})\\big)} \\\\\n              &+\\frac{\\prior}{\\abs{\\ptrain}} \\sum_{\\xvar{P} \\in \\ptrain} \\sbrack{\\mathbbm{1}_{\\hsig(\\xvar{P}) > \\eta} \\floss{\\dec(\\xvar{P})}{\\ncls} \\frac{1 - \\hsig(\\xvar{P})}{\\hsig(\\xvar{P})}} \\\\\n              &+\\frac{\\plabel}{\\abs{\\bntrain}} \\sum_{\\xvar{bN} \\in \\bntrain} \\sbrack{\\mathbbm{1}_{\\hsig(\\xvar{bN}) > \\eta} \\floss{\\dec(\\xvar{bN})}{\\ncls} \\frac{1 - \\hsig(\\xvar{bN})}{\\hsig(\\xvar{bN})}} \\text{.}\n  \\end{aligned}\n\\end{equation}\n", "meta": {"hexsha": "b27b5887a9069fecf56e20a097efbc0b2ca8526e", "size": 8981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/tex/risk_estimators.tex", "max_stars_repo_name": "ZaydH/cis510_nlp", "max_stars_repo_head_hexsha": "e1e039ca9f228051f6a3682b3ee71665e4d693d0", "max_stars_repo_licenses": ["MIT"], "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/tex/risk_estimators.tex", "max_issues_repo_name": "ZaydH/cis510_nlp", "max_issues_repo_head_hexsha": "e1e039ca9f228051f6a3682b3ee71665e4d693d0", "max_issues_repo_licenses": ["MIT"], "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/tex/risk_estimators.tex", "max_forks_repo_name": "ZaydH/cis510_nlp", "max_forks_repo_head_hexsha": "e1e039ca9f228051f6a3682b3ee71665e4d693d0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-03-25T07:33:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T14:21:20.000Z", "avg_line_length": 70.7165354331, "max_line_length": 527, "alphanum_fraction": 0.6959135954, "num_tokens": 3021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615381987656671, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6765733489111034}}
{"text": "\\section{Elementary matrices}\n\\label{sec:elementary-matrices}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use multiplication by elementary matrices to apply row\n    operations.\n  \\item Find the elementary matrix corresponding to a particular row\n    operation.\n  \\item Write the {\\rref} of a matrix $A$ in the form $R=UA$, where\n    $U$ is invertible.\n  \\item Write a matrix as a product of elementary matrices.\n  \\end{enumerate}\n\\end{outcome}\n\n", "meta": {"hexsha": "f351d3fcdf48f9b81bb218abbc48881be25a5c85", "size": 446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ElementaryMatrices.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ElementaryMatrices.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ElementaryMatrices.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.875, "max_line_length": 68, "alphanum_fraction": 0.7331838565, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056322076481139, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.6765167285972727}}
{"text": "\\chapter{SLAM}\n\\label{chp:slam}\n\nThis chapter describes the basic concepts behind the robotics problem known as \\emph{Simultaneous Localization And Mapping (SLAM)}, which addresses the issues of when a robot doesn't know the map of its environment.\nThe principle behind SLAM is for a robot to use measurements and control metrics to construct a map, while simultaneously localizing it self relative to this map, as it moves within the given environment.\n\nSLAM is currently a substantial topic of research within robotics, with a lot of advanced methods, because the robot might loose track of where it is by virtue of its own motion uncertainties.\nHowever this report will focus on Graph SLAM, an older version of SLAM that is easily comprehensible and serves as a good introduction to the concepts of SLAM in practice.\\\\\\\\\n\n\\noindent In Graph SLAM we can reduce the mapping problem to additions into a matrix and a vector, and a simple matrix multiplication.\\\\\nThe matrix, $\\Omega$, and the vector, $\\xi$, is generated by gathering the following constraints of the robot:\n\\begin{itemize}\n    \\item The initial location\n    \\item Relative motion\n    \\item Relative measurements to landmarks\n\\end{itemize}\nThe matrix and the vector can then be used find the best estimate, $\\mu$ of both all the robot locations and all the landmark positions, by the formula:\n\\begin{align*}\n    \\mu = \\Omega^{-1} \\xi\n\\end{align*}\nThe best way to explain the process is through a 1D example.\n\n\n\\myFigure{slamEx1}{Illustration of Graph SLAM example. The triangles represent the robot at different times, the cylinders represents landmarks, the solid arrows represents the robots movements and the dashed arrow represents measurements.}{fig:slamEx1}{0.7}\n\nThe robot has an initial location which we define as $x_0 = 0$, and moves 5 steps forward to a new position, $x_1$.\nThis movement constraint can be described as:\n\\begin{align*}\nx_1 &= x_0 + 5\\\\\n-5  &= x_0 - x_1\n\\end{align*}\n\n\\noindent These equations, including the initial location equation, $x_0 = 0$,  are what should be added into the matrix $\\Omega$ and the vector $\\xi$, such that we get:\n\\begin{table}[!h]\n    \\centering\n\\begin{tabular}{cc|rrrrr c crc}\n          &       & $x_0$ & $x_1$ & $x_2$ & $L_0$ & $L_1$ & \n          \n          \\qquad &        &                        & \\\\\n          \n          \\cline{2-7}\n          & $x_0$ &   2   &  -1   &  0    &  0    &   0   &  \n          \n                 &        &\\multicolumn{1}{r|}{-5} & $x_0$\\\\\n          \n          & $x_1$ &  -1   &   1   &  0    &  0    &   0   &  \n                 \n                 &        & \\multicolumn{1}{r|}{5} & $x_1$\\\\\n\n$\\Omega=$ & $x_2$ &   0   &   0   &  0    &  0    &   0   &  \n                 \n                 & $\\xi=$ &\\multicolumn{1}{r|}{0} & $x_2$\\\\\n                 \n          & $L_0$ &   0   &   0   &  0    &  0    &   0   &  \n                 \n                 &        & \\multicolumn{1}{r|}{0} & $L_0$\\\\\n                 \n          & $L_1$ &   0   &   0   &  0    &  0    &   0   &  \n          \n                 &        & \\multicolumn{1}{r|}{0} & $L_1$\\\\\n\\end{tabular}                                               \n\\end{table}\n\n\\noindent Now suppose that the robot moves backwards by 4 steps to $x_2$:\n\\begin{align*}\nx_2 &= x_1 - 4\\\\\n-4  &= x_2 - x_1\n\\end{align*}\nThis is now added to the already existing $\\Omega$ and $\\xi$, such that we get:\n\\begin{table}[!h]\n    \\centering\n    \\begin{tabular}{cc|rrrrr c crc}\n        &       & $x_0$ & $x_1$ & $x_2$ & $L_0$ & $L_1$ & \n        \n        \\qquad &        &                        & \\\\\n        \n        \\cline{2-7}\n        & $x_0$ &   2   &  -1   &  0    &  0    &   0   &  \n        \n        &        &\\multicolumn{1}{r|}{-5} & $x_0$\\\\\n        \n        & $x_1$ &  -1   &   2   &  -1    &  0    &   0   &  \n        \n        &        & \\multicolumn{1}{r|}{9} & $x_1$\\\\\n        \n        $\\Omega=$ & $x_2$ &   0   &   -1   &  1    &  0    &   0   &  \n        \n        & $\\xi=$ &\\multicolumn{1}{r|}{-4} & $x_2$\\\\\n        \n        & $L_0$ &   0   &   0   &  0    &  0    &   0   &  \n        \n        &        & \\multicolumn{1}{r|}{0} & $L_0$\\\\\n        \n        & $L_1$ &   0   &   0   &  0    &  0    &   0   &  \n        \n        &        & \\multicolumn{1}{r|}{0} & $L_1$\\\\\n    \\end{tabular}                                               \n\\end{table}\n\n\\noindent If the robot at position $x_1$ saw a landmark, $L_0$, at a distance of 9 away and at position $x_2$ saw a landmark, $L_1$, at a distance of -3 away,  this should be added to the matrix and vector as well.\n\\begin{align*}\nx_1 - L_0 &= -9\\\\\n9  &= L_0 - x_1\\\\\nx_2 - L_1 &= 3\\\\\n-3  &= L_1 - x_2\n\\end{align*}\n\n\\newpage \nGiving us:\n\\begin{table}[!h]\n    \\centering\n    \\begin{tabular}{cc|rrrrr c crc}\n        &       & $x_0$ & $x_1$ & $x_2$ & $L_0$ & $L_1$ & \n        \n        \\qquad &        &                        & \\\\\n        \n        \\cline{2-7}\n        & $x_0$ &   2   &  -1   &  0    &  0    &   0   &  \n        \n        &        &\\multicolumn{1}{r|}{-5} & $x_0$\\\\\n        \n        & $x_1$ &  -1   &   3   &  -1    &  -1    &   0   &  \n        \n        &        & \\multicolumn{1}{r|}{0} & $x_1$\\\\\n        \n$\\Omega=$&$x_2$ &   0   &   -1   &  2    &  0    &  -1   &  \n        \n        & $\\xi=$ &\\multicolumn{1}{r|}{-1} & $x_2$\\\\\n        \n        & $L_0$ &   0   &   -1   &  0    &  1   &   0   &  \n        \n        &        & \\multicolumn{1}{r|}{9} & $L_0$\\\\\n        \n        & $L_1$ &   0   &   0   &  -1    &  0    &   1  &  \n        \n        &        & \\multicolumn{1}{r|}{-3} & $L_1$\\\\\n    \\end{tabular}                                               \n\\end{table}\n\n\\noindent If we now calculate the landmark and robot positions we get:\n\\begin{table}[!h]\n    \\centering\n    \\begin{tabular}{cr|c}\n                                      &  0 & $x_0$ \\\\\n                                      &  5 & $x_1$ \\\\\n       $\\mu = \\Omega^-1 \\cdot \\xi = $ &  1 & $x_2$ \\\\\n                                      & 14 & $L_0$ \\\\\n                                      & -2 & $L_1$ \\\\\n    \\end{tabular}                                               \n\\end{table}\n\n\\noindent where we can see we get what we expected, for both the robots position at each time index, and the landmarks location.\\\\\\\\\n\n\\noindent Normally SLAM problem would be in at least 2 dimensions, which Graph SLAM also is able to handle, either by expanding the $\\Omega$ matrix and the $\\xi$ vector, or by creating separate matrices for each dimension.", "meta": {"hexsha": "68a1b37963c2cda9cad332456542e554f6566b72", "size": 6447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/SLAM.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/SLAM.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/SLAM.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": 41.8636363636, "max_line_length": 258, "alphanum_fraction": 0.4789824725, "num_tokens": 2127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6762864527913974}}
{"text": "\\hypertarget{multiple-regression}{%\n\\chapter{Multiple Regression}\\label{multiple-regression}}\n\\section{Introduction}\nMultiple regression is like linear regression, but with more than one\nindependent value, meaning that we try to predict a value based on two\nor more variables. Multiple regression is a statistical technique that\ncan be used to analyze the relationship between a single dependent\nvariable and several independent variables. The objective of multiple\nregression analysis is to use the independent variables whose values are\nknown to predict the value of the single dependent value. Each predictor\nvalue is weighed, the weights denoting their relative contribution to\nthe overall prediction.\n\n\\[\n\\hat{y} = \\beta_0 + \\beta_1 x_1 + \\beta_2 x_2 + ... + \\beta_n x_n\n\\]\n\nHere \\(\\hat{y}\\) is the dependent variable, and \\(x_1, x_2, ..., x_n\\)\nare the \\(n\\) independent variables. In calculating the weights,\n\\(\\beta_0\\), \\(x_1, x_2, ..., x_n\\), regression analysis ensures maximal\nprediction of the dependent variable from the set of independent\nvariables. This is usually done by least squares estimation.\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}{pandas} \\PY{k}{as} \\PY{n+nn}{pd}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn} \\PY{k+kn}{import} \\PY{n}{linear\\PYZus{}model}\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}{import} \\PY{n+nn}{seaborn} \\PY{k}{as} \\PY{n+nn}{sns}\n\\PY{k+kn}{import} \\PY{n+nn}{matplotlib}\\PY{n+nn}{.}\\PY{n+nn}{pyplot} \\PY{k}{as} \\PY{n+nn}{plt}\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+s2}{\\PYZdq{}}\\PY{l+s+s2}{./data/house\\PYZus{}data.csv}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{dataset}\\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}{2}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n   sqft  bedrooms    price\n0  1180         3  3540000\n1  2570         3  7710000\n2   770         2  1540000\n3  1960         4  7840000\n4  1680         3  5040000\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} \\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}{dataset}\\PY{o}{.}\\PY{n}{corr}\\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}{3}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n              sqft  bedrooms     price\nsqft      1.000000  0.410243  0.945462\nbedrooms  0.410243  1.000000  0.654177\nprice     0.945462  0.654177  1.000000\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}{regr} \\PY{o}{=} \\PY{n}{linear\\PYZus{}model}\\PY{o}{.}\\PY{n}{LinearRegression}\\PY{p}{(}\\PY{p}{)}\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}{25}\\PY{p}{,} \\PY{n}{random\\PYZus{}state}\\PY{o}{=}\\PY{l+m+mi}{42}\\PY{p}{)} \n\\PY{n}{regr}\\PY{o}{.}\\PY{n}{fit}\\PY{p}{(}\\PY{n}{X\\PYZus{}train}\\PY{p}{,} \\PY{n}{y\\PYZus{}train}\\PY{p}{)}\n\\PY{n}{regr}\\PY{o}{.}\\PY{n}{score}\\PY{p}{(}\\PY{n}{X\\PYZus{}test}\\PY{p}{,} \\PY{n}{y\\PYZus{}test}\\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}{4}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n0.976264543946519\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}{y\\PYZus{}pred}\\PY{o}{=}\\PY{n}{regr}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{n}{X}\\PY{p}{)}\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Predicted:}\\PY{l+s+se}{\\PYZbs{}t}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{y\\PYZus{}pred}\\PY{p}{[}\\PY{p}{:}\\PY{l+m+mi}{10}\\PY{p}{]}\\PY{p}{)}\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Actual:}\\PY{l+s+se}{\\PYZbs{}t}\\PY{l+s+se}{\\PYZbs{}t}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{y}\\PY{o}{.}\\PY{n}{values}\\PY{p}{[}\\PY{p}{:}\\PY{l+m+mi}{10}\\PY{p}{]}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\nPredicted:       [ 3488660.82843106  8375217.66544624   329918.68771236\n7948141.12000992\n  5246415.08635019 20111800.5848103   5369457.88440453  3066799.80653047\n  5597965.93793402  5984671.87467623]\nActual:          [ 3540000  7710000  1540000  7840000  5040000 21680000  5145000\n3180000\n  5340000  5670000]\n    \\end{Verbatim}\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}{plt}\\PY{o}{.}\\PY{n}{figure}\\PY{p}{(}\\PY{n}{dpi}\\PY{o}{=}\\PY{l+m+mi}{90}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n+nb}{range}\\PY{p}{(}\\PY{n}{y\\PYZus{}pred}\\PY{o}{.}\\PY{n}{size}\\PY{p}{)}\\PY{p}{,} \\PY{n}{y\\PYZus{}pred}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Predicted}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n+nb}{range}\\PY{p}{(}\\PY{n}{y\\PYZus{}pred}\\PY{o}{.}\\PY{n}{size}\\PY{p}{)}\\PY{p}{,} \\PY{n}{y}\\PY{p}{,} \\PY{n}{label}\\PY{o}{=}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Actual}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{legend}\\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<matplotlib.legend.Legend at 0x1dc847c2af0>\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{center}\n    \\adjustimage{max size={0.9\\linewidth}{0.9\\paperheight}}{./figures/MR1.png}\n    \\end{center}\n    { \\hspace*{\\fill} \\\\}", "meta": {"hexsha": "a97ecfa1d1a96116c1114fd5139e2e8f776dff3e", "size": 7054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MCA/Machine Learning/Project file/Tex source/Multiple Regression.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/Multiple Regression.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/Multiple Regression.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": 54.2615384615, "max_line_length": 340, "alphanum_fraction": 0.6351006521, "num_tokens": 2868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6762864466136596}}
{"text": "% !TEX root = ../main.tex\n\\newpage\n\\section{\\theory The Theta Neuron Model} \\label{TheThetaNeuronModel}\n%\\subsection{Canonical neuron models}\nA number of neuron model families have been identified, and often there exists a continuous change of variables from models of the same family into a \\textit{canonical} model that can represent the whole family \\cite{Hoppensteadt2001CanonicalNM}. As the transformation is not required to be invertible, we can study the universal neurocomputational properties of the family in a low dimensional model.\nIt was Hodgkin \\cite{Hodgkin1948} who classified neurons into two types based on their excitability, upon experimenting with the electrical stimulation of cells. Class 1 models begin to spike at an arbitrarily slow rate, and the spiking frequency increases when the applied current is increased. Class 2 models spike as soon as their internal threshold is exceeded and the spiking frequency stays relatively constant within a certain frequency band \\cite{Hoppensteadt2001CanonicalNM}.\n\n\n\\subsection{Theta Neuron model description} \\label{sec:TheThetaNeuronModelDescription}\nIn \\cite{Ermentrout1986}, a Class 1 canonical phase model was proposed:\n\\begin{align}\n\\dot{\\theta} = (1-\\cos \\theta)+(1+\\cos \\theta) \\cdot I \\qquad \\theta \\in \\T \\label{eq:thetaneuron}\n\\end{align}\nwith $I$ a bifurcation parameter on the supplied current. We can visualise the dynamics on the unit circle, like in Figure \\ref{fig:thetaneuronbifurcationtikz}. The neuron produces a spike when $\\theta$ surpasses $\\pi$, upon which $\\theta \\leftarrow -\\pi$. \n\n\\begin{figure}[H]\n\\minipage{0.33\\linewidth}\n\\centering\n\\begin{tikzpicture}\n    \\draw (0,0) circle [radius=1];\n    \\draw (0,-1.2) node[below]{Excitable regime: $I < 0$};\n    \\draw (-1,0) node[left]{$\\pi$};\n    \\draw[fill=black, black] (1,0) circle [radius=0.025];\n    \\draw (1,0) node[right]{0};\n    \\draw[fill=red, red] (-1,0) circle [radius=0.05];\n    \\draw (-1,0) node[right]{spike};\n    \n    \\draw[black, ->] (0.866, 0.5)to[out=-60,in=90](1,0);\n    \\draw[fill=white, draw=black] (0.866,0.5) circle [radius=0.1];\n    \\draw (0.866,0.5) node[left]{\\small{threshold}};\n    \n    \\draw[fill=black, draw=black] (0.866,-0.5) circle [radius=0.1];\n    \\draw (0.866,-0.5) node[left]{\\small{rest}};\n    \n    \\draw[black, ->] (0.5,0.866)to[out=150,in=0](0,1);\n    \\draw[black, ->] (-0.5,-0.866)to[out=-30,in=180](0,-1);\n\\end{tikzpicture}\n\\endminipage\n\\minipage{0.33\\linewidth}\n\\centering\n\\begin{tikzpicture}\n    \\draw (0,0) circle [radius=1];\n    \\draw (0,-1.2) node[below]{Bifurcation: $I = 0$};\n    \\draw (1,0) node[right]{0};\n    \\draw[fill=red, red] (-1,0) circle [radius=0.05];\n    \\draw (-1,0) node[right]{spike};\n    \\draw (-1,0) node[left]{$\\pi$};\n    \n    \\draw[fill=gray, draw=black] (1,0) circle [radius=0.1];\n    \n    \\draw[black, ->] (0.5,0.866)to[out=150,in=0](0,1);\n    \\draw[black, ->] (-0.5,-0.866)to[out=-30,in=180](0,-1);\n\\end{tikzpicture}\n\\endminipage\n\\minipage{0.33\\linewidth}\n\\centering\n\\begin{tikzpicture}\n    \\draw (0,0) circle [radius=1];\n    \\draw (0,-1.2) node[below]{Periodic regime: $I > 0$};\n    \\draw (-1,0) node[left]{$\\pi$};\n    \\draw (1,0) node[right]{0};\n    \\draw[fill=black, black] (1,0) circle [radius=0.025];\n    \\draw[fill=red, red] (-1,0) circle [radius=0.05];\n    \\draw (-1,0) node[right]{spike};\n    \n    \\draw[black, dotted] (0,0)to(1,0);\n    \\draw(0,0) node[above]{$\\theta$};\n    \\draw[black, dotted] (0,0)to(0.866,0.5);\n    \n    \\draw[black, ->] (0.5,0.866)to[out=150,in=0](0,1);\n    \\draw[black, ->] (-0.5,-0.866)to[out=-30,in=180](0,-1);\n\\end{tikzpicture}\n\\endminipage\n\\caption{SNIC bifurcation of the theta neuron model. A spike occurs when $\\theta = \\pi$. For $I < 0$, the neuron is in a rest state but \\textsl{excitable} and we observe one stable and one unstable equilibrium point. For $I > 0$, $\\dot{\\theta} > 0$ so that $\\theta$ moves continuously around the circle and we can observe \\textsl{periodic} sustained spiking. The saddle-node bifurcation occurs at $I = 0$, so that $\\theta$ will spike when it is larger than 0.}\n\\label{fig:thetaneuronbifurcationtikz}\n\\end{figure}\n\nWe can recognise the features of the class 1 model in Figure \\ref{fig:ThetaNeuronResponseToCurrent}. This makes \\eqref{eq:thetaneuron} the normal form of the \\textit{saddle-node-on-invariant-circle} ($\\SNIC$) bifurcation \\cite{Luke2013}, as it collapses $\\R$ to $\\T$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/ThetaNeuronResponseToCurrent.pdf}\n\\caption{Properties of the theta neuron model, with solutions of \\eqref{eq:thetaneuron} in blue, spikes marked in dotted lines, and the current $I$ in red. Left: the spike frequency of $\\theta$ increases as $I$ is increased over time, which is the distinguishing feature of class 1 canonical models. Middle: spikes occur within a finite time period when $I > 0$ and within infite time when $I = 0$. Right: when $I$ is large, the neuron \\textsl{bursts}.}\n\\label{fig:ThetaNeuronResponseToCurrent}\n\\end{figure}\n\nEquilibria only exist for the \\textsl{excitable} regime $I < 0$: \n\\begin{align*}\n\\dot{\\theta} &= 1-\\cos \\theta+I+I \\cdot \\cos \\theta = (I+1)+(I-1) \\cdot \\cos \\theta \\\\\n\\theta^{\\ast}_{1, 2} &= \\pm \\arccos \\left(\\frac{I+1}{1-I}\\right)+2 \\pi n\n\\end{align*}\nWe can find the stability of the equilibria through:\n\\begin{align*}\n\\frac{\\mathop{d}}{\\mathop{d \\theta}}((1-\\cos \\theta)+(1+\\cos \\theta) \\cdot I) &= \\sin \\theta-\\sin \\theta \\cdot I = (1-I) \\cdot \\sin \\theta\n\\end{align*}\nIn the equilibria this yields:\n\\begin{align*}\n\\frac{\\mathop{d}}{\\mathop{d \\theta}}\\left( \\theta^{\\ast}_{1, 2} \\right) &= \\pm(1-I) \\cdot \\sqrt{1 - \\left( \\frac{I+1}{1-I} \\right)^2 } = \\pm(1-I) \\cdot \\frac{2 \\sqrt{-I}}{1-I} = \\pm2 \\sqrt{-I}\n\\end{align*}\nWe find that $\\theta^{\\ast}_{1}$ is an unstable equilibrium point, and that $\\theta^{\\ast}_{2}$ is stable. This means that as $\\theta$ gets perturbed above $\\theta^{\\ast}_{1}$, a spike occurs and $\\theta$ converges to $\\theta^{\\ast}_{2}$. This is demonstrated in Figure \\ref{fig:ThetaModelEquilibriumPoints}.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/ThetaModelEquilibriumPoints.pdf}\n\\caption{Equilibria $\\theta^{\\ast}$ for different values of $I < 0$. Left: $I = -1$ yields $\\theta^{\\ast}_{1,2} = \\pm \\frac{\\pi}{2}$, one of the simulations is started exactly on the unstable equilibrium and stays there. Middle: $I = -0.5$, we see how a spike occurs when $\\theta > \\theta^{\\ast}_{1}$ upon which $\\theta \\rightarrow \\theta^{\\ast}_{2}$. Right: bifurcation diagram of the \\SNIC bifurcation, with the stable equilibria in blue, and the unstable in red. At $I = 0$ the equilibria merge into one.}\n\\label{fig:ThetaModelEquilibriumPoints}\n\\end{figure}\n\n\n\\subsection{Solutions for static currents} \\label{sec:TheThetaNeuronModelSolutionPeriodics}\nGaining insight into \\eqref{eq:thetaneuron} is hard, due to the difficulty of finding an analytical solution. However, it has been noted that there exists a simple transformation which yields (see \\ref{app:TransformationToQIF}):\n\\begin{align}\nV &\\equiv \\tan \\left( \\frac{\\theta}{2} \\right) \\label{eq:QIFtransformation} \\\\\n\\dot{V} &= V^2 + I \\label{eq:QIFmodel}\n\\end{align}\nThis model is called the \\textsl{Quadratic Integrate and Fire model} (\\QIF). \\eqref{eq:QIFmodel} models the membrane potential of a neuron, which spikes at $V=\\infty$ and resets to $V \\leftarrow -\\infty$. The transformation \\eqref{eq:QIFtransformation} is continuous between spikes, so insights from a solution for $V$ can be transformed directly to $\\theta$. The equilibria of the \\QIF model are simply $\\pm \\sqrt{-I}$ (as $I < 0$) so that we can express $\\theta^{\\ast}_{1, 2} = 2 \\arctan \\left( \\pm \\sqrt{-I} \\right)$ \\cite{Gutkin2014}. \\\\\n\nThe solution for the excitable regime $I < 0$ is :\n\\begin{align}\nV(t) = \\frac{2 \\sqrt{-I}}{1 - e^{2 t \\sqrt{-I}}}-\\sqrt{-I} \\label{eq:ThetaNeuronModelSolutionPeriodicExcitable}\n\\end{align}\nThe solution at the bifurcation $I = 0$ is :\n\\begin{align}\nV(t) = \\frac{-1}{t} \\label{eq:ThetaNeuronModelSolutionPeriodicBifurcation}\n\\end{align}\nThe solution for the periodic regime $I > 0$ is :\n\\begin{align}\nV(t) = -\\sqrt{I} \\cdot \\cot (t \\sqrt{I}) \\label{eq:ThetaNeuronModelSolutionPeriodic}\n\\end{align}\nThese equations assume that at $t=0$ a spike has occured. The steps required to find the solutions (\\ref{eq:ThetaNeuronModelSolutionPeriodicExcitable}) to (\\ref{eq:ThetaNeuronModelSolutionPeriodic}) are described in \\ref{app:ThetaModelSolutions}. Solutions for $\\theta$ are found by simply taking the inverse of the transformation in \\eqref{eq:QIFtransformation}.\n\nIf the \\QIF model is so much simpler, then why bother using the Theta model? Simulating the \\QIF model requires an artificial reset threshold, because we cannot expect a computer to represent infinity easily. Finite thresholds make the analytical solutions more difficult and convoluted. By using the Theta model the dynamics remain smooth and bounded on $\\T$. %Since we take the cosine of the phase angle in \\eqref{eq:thetaneuron}, we do not even\n\n\n\\subsection{Numerical solutions} \\label{sec:TheThetaNeuronModelODE45}\nWhen $I$ is not static, we need to revert to numerical solutions. A fixed-step 4-stage Runge-Kutta method (Dormand-Prince 45) was implemented to numerically solve all differential equations. A fixed-step algorithm makes it possible to finely tune the large memory demand of the systems presented in this work. \n\n\n\\subsection{Frequency response} \\label{sec:TheThetaNeuronModelFrequencyResponse}\n\\begin{wrapfigure}{r}{0.39\\textwidth}\n\\centering\n\\vspace{-\\baselineskip}\n\\includegraphics[width = \\linewidth]{../Figures/ThetaNeuronfI.pdf}\n\\caption{Frequency response of the Theta model. For $I \\leq 0$ the spike period is infinite, which is why we see the solutions to (\\ref{eq:thetaneuron}) approach $\\theta = 0$ for $I = 0$ in Figure \\ref{fig:ThetaNeuronResponseToCurrent}. }\n\\label{fig:ThetaNeuronfI}\n\\end{wrapfigure}\n\nAs we already saw in Figure \\ref{fig:ThetaNeuronResponseToCurrent}, an increasing current increases the spiking frequency. We can compute this relationship by measuring how long it takes for $V$ to reach a spike: we solve \\eqref{eq:ThetaNeuronModelSolutionPeriodic} for $t$ at $V(t) = +\\infty$ in \\ref{app:ThetaModelFrequencyResponse}. This yields the oscillation period $T = \\frac{\\pi}{\\sqrt{I}}$, which we can see in Figure \\ref{fig:ThetaNeuronfI}. \n\nWe know that when $\\theta > \\theta^{\\ast}_{1}$ a spike occurs in the excitable regime, or in any case in the periodic regime. But the time that it takes to reach the spike can be arbitrarily long, depending on how far we are over $\\theta^{\\ast}_{1}$. So, spikes will occur, but after a delay that is dependant on the stimulus. Explicitly, if we perturb $\\theta(0) = \\theta^{\\ast}_{1} + \\varepsilon$ we obtain from \\cite{Gutkin2014}:\n\\begin{align*}\nT_{\\text {spike}} = \\frac{-\\tanh ^{-1}\\left(1+\\frac{\\epsilon}{\\sqrt{I}}\\right)}{\\sqrt{I}}\n\\end{align*}\nThe delay to the spike blows up as $\\varepsilon \\rightarrow$ 0 so that spikes may occur after a very large delay. \\\\\n\nIn most of our future work, $I$ will not be a static current. We ask ourselves: how sensitively does $T$ depend on $I$ when $I$ is perturbed? We can measure this as a \\textsl{relative} perturbation using $\\mathop{dI}/I$ and $\\mathop{dT/T}$ \\cite{IntroductionModelingDynamics} :\n\\begin{align*}\n\\left| \\frac{dT}{dI} \\frac{I}{T} \\right| &= \\left| \\frac{dT / T}{dI / I}\\right| \n= \\left|- \\frac{\\pi}{2} \\left(\\frac{1}{\\sqrt{I}}\\right)^3 \\frac{I}{T} \\right| \n= \\left| \\frac{\\pi}{2} \\left(\\frac{T}{\\pi}\\right)^3 \\frac{I}{T} \\right| \n= \\frac{1}{2} \\left|\\left(\\frac{T}{\\pi}\\right)^2 \\left(\\frac{\\pi}{T}\\right)^2 \\right| = \\frac{1}{2}\n\\end{align*}\nHence, a 1\\% change in $I$ will result in a 0.5 \\% change in the period.\n\n\n\\subsection{Phase response} \\label{sec:TheThetaNeuronModelPhaseResponse}\nPerturbations on the period can also be understood from the perspective of the phase. Changes to the phase $\\theta$ can delay or advance the event of a spike, and in general this depends on exactly when the stimulus occurs. The phase response curve (\\PRC) gives us exactly that relation \\cite{Perez2020, Gutkin2014}.\n\nLet us define $\\phi \\in [0, T[$, which represents the time since the last event of a spike. When we add a small bifurcation $\\varepsilon$ to $\\theta$ at time $\\phi$, a spike will occur at $T_{\\phi}$, and we have that $\\theta(\\phi_{\\rm new}) = \\theta(\\phi) + \\varepsilon$. The time to the new spike is now $T_{\\phi} = T + (\\phi - \\phi_{\\text{new}})$. The \\PRC can then be defined as:\n\\begin{align}\n\\PRC(\\phi) = T - T_{\\phi} \\label{eq:PRC1}\n\\end{align}\nThe \\PRC is thus the expected delay of the period in function of the timing of that delay. This process has been visualised in Figure \\ref{fig:ThetaNeuronPRC}, after \\cite{Perez2020}. For infinitesimally small perturbations to the phase, we can find the \\PRC as the \\textsl{adjoint} of the solution \\cite{Gutkin2014}:\n\\begin{align}\n\\PRC(\\phi) = \\frac{1}{d V(\\phi) / d \\phi} = \\frac{1}{2 \\sqrt{I}} \\left(1-\\cos \\left( \\frac{2 \\pi}{T} \\phi \\right) \\right) \\label{eq:PRC2}\n\\end{align}\nWe can use $\\phi \\in [0, T[$ and $\\theta \\in \\T$ to see that \\eqref{eq:PRC2} can be expressed as:\n\\begin{align}\n\\PRC(\\theta) \\sim 1 + \\cos \\theta  \\label{eq:PRC3}\n\\end{align}\nwhich is the magnitude with which $I$ excites the model, see \\eqref{eq:thetaneuron} \\cite{Ermentrout1996}. Analysis of the \\PRC thus also allows us to study how the bifurcation of $\\theta$ with magnitude $I$ occurs. The \\PRC is always positive, which indicates that a positive bifurcation will accelerate the time of the spike, and vice versa. This has also been reported as a distinguishing feature of Class 1 models \\cite{Ermentrout1996}. \\\\\n\nAs bifurcations are not always small, we need to dig a little deeper. An exact formulation for $T_{\\phi}$ can be obtained by integrating after the bifurcation, see \\ref{app:ThetaModelPhaseResponse}. The \\PRC then becomes:\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 \\label{eq:PRCepsilon}\n\\end{align}\nWhen plotting \\eqref{eq:PRCepsilon} for different values of $\\varepsilon$ in Figure \\ref{fig:ThetaNeuronPRC}, we can see that larger bifurcations yield larger delays on the phase. For infinitesimally small bifurcations the response of \\eqref{eq:PRC2} is symmetric about the middle of the period. However, here we see that with increasing $\\varepsilon$ the \\PRC loses symmetry and skews to the left. For large bifurcations, we can expect the greatest perturbation of the phase briefly after the action potential. This tendency continues to skew to the left for increasing $I$, and the \\PRC converges to a value of $T$ at $\\phi = 0$. A delay with magnitude $T$ is really the largest delay we can achieve with a single bifurcation. The effect of a bifurcation diminishes over the period: as $\\theta$ approaches $\\pi$, the ability to advance a spike in time disappears.\\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/ThetaNeuronPRC.pdf}\n\\caption{Response of the Theta model to bifurcations on the phase. Left: a bifurcation $\\varepsilon < 0$ at time $\\phi$ perturbs $\\theta(t)$ (in blue) which results in a delayed spike (trajectory in red). For $\\varepsilon > 0$ spikes are advanced in time. Right: the \\PRC, given by \\eqref{eq:PRCepsilon}, plotted in orange for $\\varepsilon$ ranging from 0.1 to 1 - a weak bifurcation is more translucent. A solution for $\\theta$ (in blue) shows when the model is the most susceptible to bifurcations over the course of one period.}\n\\label{fig:ThetaNeuronPRC}\n\\end{figure}\n\n\n", "meta": {"hexsha": "e6afe5a1694e59ff926953c248eadfbce4ed2424", "size": 15654, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Mainmatter/Theta Neuron Model.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/Theta Neuron Model.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/Theta Neuron Model.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": 79.8673469388, "max_line_length": 867, "alphanum_fraction": 0.7171968826, "num_tokens": 4963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571774, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6762864415305965}}
{"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\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}\nIn the following discussion the following typographic notations has been used:\n\\begin{itemize}\n  \\item \\emph{Lower case bold face} means vector (ex. $\\ve\\mu, \\ve{x}$). All vectors are row vectors like $\\begin{m} x_1 & x_2 \\end{m}$ not $\\begin{m} x_1 \\\\ x_2 \\end{m}$.\n  \\item \\emph{Upper case bold face} means matrix (ex. $\\ma{A}, \\ma{S}, \\ma{\\Sigma}$).\n  \\item The transpose of a matrix is noted $\\ma{A}^T$, not $\\ma{A}'$.\n  \\item $\\ve{x}', \\ma{A}'$ denotes a vector/matrix that has been transformed.\n\\end{itemize}\n\\section{Variance of a value}\n\nThe \\textbf{variance} (expressed with the symbol $\\sigma^2$ or $\\sigma_S^2$) measures the dispersion of a set of values $\\ma{S}$ from the mean value $\\mu$ or expected value $E(\\ma{S})$. The mean value is~:\n\n\\[\n  \\mu = E(\\ma{S}) = \\frac{1}{l} \\sum_1^{l} s_l\n\\]\n\n$l$ being the number of elements in the set. The variance can be computed as~:\n\\[\n  \\sigma^2 = E[(\\ma{S} - \\mu)(\\ma{S} - \\mu)] = \\frac{1}{l} \\sum_1^{l} (s_l - \\mu)^2\n\\]\n\nFor example, given the set of values $\\ma{S} = {1,4,3,6}$, the mean value $\\mu$ is~:\n\\[\n  \\mu = \\frac{1+4+3+6}{4} = 3.5,\n\\]\n\nand the variance $\\sigma^2$~:\n\\begin{align*}\n  \\sigma^2 = & (1-3.5)^2 + (4-3.5)^2 +\\\\\n             & \\frac{(3-3.5)^2 + (6-3.5)^2}{4} = \\frac{13}{4} = 3.25\n\\end{align*}\n\n\\section{variance-covariance matrix}\n\nThe \\textbf{variance-covariance matrix} is the generalisation to greater dimensions of the variance seen before. Imagine we have a set $\\ma{S}$ of vectors of dimension $n$ and we want to compute the variance of these vectors. We must first compute the expected value $E(\\ma{S})$ which is the mean vector $\\mu$~:\n\\begin{align*}\n  E(\\ma{S}) = & \\ve{\\mu} = \\begin{m} \\mu_1 \\hdots \\mu_n \\end{m} \\\\\n       = & \\frac{1}{l} \\begin{m} \\begin{m} s_{11} \\hdots s_{1n} \\end{m} \\\\ + \\\\ \\vdots \\\\ + \\\\ \\begin{m} s_{l1} \\hdots s_{ln} \\end{m} \\end{m}\n\\end{align*}\n\nWe can build a matrix $\\Theta$ (theta) of size ($l,n$) from the vector $\\mu$ (mu)~:\n\\[\n  \\ma\\Theta = \\begin{m} \\ve{\\mu} \\\\ \\vdots \\\\ \\ve{\\mu} \\end{m}\n\\]\n\nFrom the definition of the variance, we have\n\\[\n  \\Sigma = E \\begin{m} (\\ma{S} - \\ma\\Theta)^T (\\textbf{S} - \\ma\\Theta)\\end{m}\n\\]\n\nthus each entry in the variance-covariance matrix $\\ma\\Sigma$ (sigma) is~:\n\\[\n  \\Sigma_{ij} = \\frac{\\sum_{k=1}^{l} (s_{ki} - \\mu_i)(s_{kj} - \\mu_j)}{l}.\n\\]\n\n\nFor example, given the set $\\ma{S}$ formed with three experiments measuring two values~:\n\\begin{displaymath}\n  \\ma{S} = \\begin{m} 1 & 1 \\\\ 0 & 4 \\\\ 2 & 1 \\end{m},\n\\end{displaymath}\n\nwe can compute the expected value~:\n\\[\n  \\ve{\\mu} = \\frac{1}{3} \\begin{m} \\left( \\begin{array}{c} 1 \\\\ + \\\\ 0 \\\\ + \\\\ 2 \\end{array} \\right) \\left( \\begin{array}{c} 1 \\\\ + \\\\ 4 \\\\ + \\\\ 1 \\end{array} \\right) \\end{m} = \\begin{m} 1 & 2 \\end{m}.\n\\]\n\n\nTo find the variance-covariance matrix, let us first compute the \\emph{mean deviation form} of $\\ma{S}$ where we remove the mean value from each experiment in the set~:\n\\[\n  \\ma{T} = \\ma{S} - \\ma\\Theta = \\begin{m} (1-1) & (1-2) \\\\ (0-1) & (4-2) \\\\ (2-1) & (1-2)\\end{m} = \\begin{m} 0 & -1 \\\\ -1 & 2 \\\\ 1 & -1\\end{m}.\n\\]\n\nWe can now find $\\ma\\Sigma$~:\n\\begin{align*}\n  \\ma\\Sigma = & E \\begin{m} \\ma{T}^T\\ma{T}\\end{m} = \\frac{1}{n-1} \\begin{m} \\ma{T}^T\\ma{T}\\end{m} \\\\\n         = & E \\begin{m} \\begin{m} 0 & -1 & 1 \\\\ -1 & 2 & -1\\end{m} \\begin{m} 0 & -1 \\\\ -1 & 2 \\\\ 1 & -1\\end{m} \\end{m} \\\\\n         = & E \\begin{m} 0*0 + -1*-1 + 1*1 & \\hdots \\\\ -1*0 + 2*-1 + -1*1 & \\hdots \\end{m} \\\\\n         = & E \\begin{m} 2 & -3 \\\\ -3 & 6 \\end{m} = \\frac{1}{2} \\begin{m} 2 & -3 \\\\ -3 & 6 \\end{m}\n         = \\begin{m} 1 & -\\frac{3}{2} \\\\ -\\frac{3}{2} & 3\\end{m}\n\\end{align*}\n\nFrom the result above, $1$ is the variance along $x$, $3$ is the variance along $y$ and $-\\frac{3}{2}$ is the covariance between the two dimensions. There are proofs on why we should use $\\frac{1}{n-1}$ for the correct normalization factor instead of the straight-forward $\\frac{1}{n}$ but this is beyond the scope of my competences...\n\n\\section{Mahalanobis distance}\n\nLet us compute the \\textbf{Mahalanobis distance} from a vector $\\ve{t}$ to the set $\\ma{S}$ with the variance-covariance matrix $\\ma\\Sigma$ and the mean value $\\ve{\\mu}$~:\n\\[\n  D_M(\\ve{t}) = \\sqrt{(\\ve{t} - \\ve{\\mu})\\Sigma^{-1}(\\ve{t} - \\ve{\\mu})^T}\n\\]\n\nIf we remove the covariances from the matrix $\\ma\\Sigma$, we have a diagonal matrix whose entries are the variances (standard deviations) for each dimension ($1$ and $3$ in the example above). The Mahalanobis distance becomes the \\textbf{normalized Euclidean distance}~:\n\\[\n  D_{nE}(\\ve{t}) = \\sqrt{\\sum_{i=1}^{n}\\frac{(t_i - \\mu_i)^2}{\\sigma_i^2}}.\n\\]\n\nFrom the example we used above we compute the different distances for two vectors $\\ve{t_1}$ and $\\ve{t_2}$~:\n\n\\includegraphics{points.pdf}\n\\begin{align*}\n  \\ve{t_1}  = & \\begin{m} 2 & 2 \\end{m} \\\\\n  \\ve{t_2}  = & \\begin{m} 1 & 3 \\end{m} \\\\\n  \\ve{\\mu} = & \\begin{m} 1 & 2 \\end{m} \\\\\n  \\Sigma    = & \\begin{m} 1 & -\\frac{3}{2} \\\\ -\\frac{3}{2} & 3\\end{m}\n\\end{align*}\n\nThe \\textbf{Euclidean distance} $d$ is the same for both points, even though it is visible that $\\ve{t_1}$ is more ``out of the way\" then $\\ve{t_2}$ ~:\n\\begin{align*}\n  d_1 = & \\sqrt{\\sum_{i=1}^{n}(t_i - \\mu_i)^2} \\\\\n     = & \\sqrt{(2-1)^2 + (2-2)^2} = 1 \\\\\n  d_2 = & \\sqrt{(1-1)^2 + (3-2)^2} = 1\n\\end{align*}\n\nThe \\textbf{normalized Euclidean distance} $d_{nE}$ should show that $\\ve{t_2}$ matches the set $\\ma{S}$ better then $\\ve{t_1}$~:\n\\begin{align*}\n  d_{1nE} = & \\sqrt{\\frac{(2-1)^2}{1} + \\frac{(2-2)^2}{3}} = 1 \\\\\n  d_{2nE} = & \\sqrt{\\frac{(1-1)^2}{1} + \\frac{(3-2)^2}{3}} = \\frac{1}{\\sqrt{3}} \\approx 0.6.\n\\end{align*}\n\nThis is better. We can see that $\\ve{t_1}$ is penalized for being out of the way in the wrong direction. The ``penalty\" for being badly adjusted along the $x$ axis is $1$ when it is only $\\frac{1}{3}$ along the $y$ axis.\n\nLet's now see what the Mahalanobis distance tells us. First we need to compute $\\Sigma^{-1}$~:\n\\[\n  \\Sigma^{-1} = \\frac{1}{(1*3 - -\\frac{3}{2}*-\\frac{3}{2})} \\begin{m} 3 & \\frac{3}{2} \\\\ \\frac{3}{2} & 1\\end{m} = \\begin{m} 4 & 2 \\\\ 2 & \\frac{4}{3} \\end{m}\n\\]\n\nWe can now find the distances~:\n\\begin{align*}\n  d_{1M} = & \\sqrt{(\\ve{t_1} - \\ve{\\mu})\\Sigma^{-1}(\\ve{t_1} - \\ve{\\mu})^T} \\\\\n         = & \\sqrt{\\begin{m} 1 & 0 \\end{m} \\begin{m} 4 & 2 \\\\ 2 & \\frac{4}{3}\\end{m} \\begin{m} 1 \\\\ 0 \\end{m}} \\\\\n         = & \\sqrt{\\begin{m} 4 & 2 \\end{m} \\begin{m} 1 \\\\ 0 \\end{m}} = 2\\\\\n  d_{2M} = & \\sqrt{\\begin{m} 0 & 1 \\end{m} \\begin{m} 4 & 2 \\\\ 2 & \\frac{4}{3}\\end{m} \\begin{m} 0 \\\\ 1 \\end{m}} \\\\\n         = & \\sqrt{\\begin{m} 2 & \\frac{4}{3}\\end{m} \\begin{m} 0 \\\\ 1 \\end{m}} = \\frac{2}{\\sqrt{3}} \\approx 1.2\\\\\n\\end{align*}\n\nThese distances classify the two vectors in the exactly the same way as the normalized Euclidean distances. Why is that so ? The reason is that our vectors are always away from the mean value in a single direction at a time, thus the ``covariance'' part of the error is never used.\n\nWhat happens with the two points $\\ve{t_3}$ and $\\ve{t_4}$ ? From the first look at the picture we can see that their distance to the mean value is the same~:\n\\begin{align*}\n  d_3 = & \\frac{1}{\\sqrt{2}} \\approx 0.7 \\\\\n  d_4 = & \\frac{1}{\\sqrt{2}} \\approx 0.7\n\\end{align*}\n\nTheir normalized Euclidean values are also the same as they differ from the mean value exactly in the same way along $x$ and $y$~:\n\\begin{align*}\n  d_{3nE} = & \\frac{1}{\\sqrt{3}} \\approx 0.6\\\\\n  d_{4nE} = & \\frac{1}{\\sqrt{3}} \\approx 0.6\n\\end{align*}\n\nNow comes the Mahalanobis distances~:\n\\begin{align*}\n  d_{3M} = & \\frac{1}{\\sqrt{3}} \\approx 0.6\\\\\n  d_{4M} = & \\frac{\\sqrt{14}}{\\sqrt{6}} \\approx 1.5\n\\end{align*}\n\nThis type of distance calculation is the only one that reflect the difference between the two vectors $\\ve{t_3}$ and $\\ve{t_4}$ and classifies $\\ve{t_4}$ as beeing further ``away'' then $\\ve{t_3}$, like our eyes tell us from a quick look at the picture~!\n\n\\section{Eigenvalues}\n\nBefore we study \\emph{Principal Component Analysis}, we need some understanding of eigenvalues. Imagine we have a transformation matrix $\\ma{P}$~:\n\\[\n  \\ma{P} = \\begin{m} 1 & 1 \\\\ 0 & 2 \\end{m}.\n\\]\n\n\\includegraphics{eigen.pdf}\n\nWhat are the vectors in this transformation that keep their direction (are not rotated) ? Mathematically speaking we want to find $\\ve{e}$ such that~:\n\\[\n  \\ve{e'} = \\ve{e} * \\ma{P} = \\lambda \\ve{e}\n\\]\n\nWe can see from the picture that $\\ve{y}$ satisfy this as $\\ve{y'}$ is just $2 * \\ve{y}$. Such vectors are called \\emph{eigenvectors} and their corresponding lambda values \\emph{eigenvalues}. To find these vectors, we can rewrite the equation above~:\n\n\\[\n  \\ve{e'} = \\ve{e} * \\ma{P} = \\lambda \\ve{e}\n\\]\n\nas\n\n\\[\n  \\ve{e} * \\ma{P} - \\lambda \\ve{e} = 0\n\\]\n\nor \n\n\\[\n  \\ve{e} (\\ma{P} - \\lambda \\ma{I}) = 0  \n\\]\n\nWe know that an equation of the form~:\n\\[\n  \\ve{x} \\ma{A} = 0\n\\]\nhas only the trivial solution $\\ve{x} = \\ve{0}$ if the determinant of $\\ma{A}$ is not null. We can therefore find the non-trivial solutions to the equation above by computing the determinant when the latter \\emph{is} null. This equation is called the \\emph{characteristic equation} of $\\ma{P}$~:\n\\[\n  det(\\ma{P} - \\lambda \\ma{I}) = 0\n\\]\n\nWe can now calculate the values of $\\lambda$~:\n\\begin{align*}\n  det(\\begin{m} 1 & 1 \\\\ 0 & 2\\end{m} - \\lambda \\begin{m} 1 & 0 \\\\ 0 & 1 \\end{m}) = & 0 \\\\\n  det(\\begin{m} 1-\\lambda & 1 \\\\ 0 & 2-\\lambda\\end{m}) = & 0 \\\\\n  (1-\\lambda)(2-\\lambda) - 1 * 0 = & 0 \\\\\n  (1-\\lambda)(2-\\lambda) = & 0\n\\end{align*}\n\nwhich has the solutions\n\\[\n\\lambda_1 = 1, \\lambda_2 = 2\n\\]\n\nThe corresponding \\emph{eigenvectors} can be found by substituting $\\lambda_1$ and $\\lambda_2$ in $\\ve{e} (\\ma{P} - \\lambda \\ma{I}) = \\ve{0}$~:\n\\begin{align*}\n  \\begin{m} x & y \\end{m} \\begin{m} 1-\\lambda & 1 \\\\ 0 & 2-\\lambda \\end{m} = & 0 \\\\\n  \\begin{m} x_1 & y_1 \\end{m} \\begin{m} 1-1 & 1 \\\\ 0 & 2-1 \\end{m} = & 0 \\\\\n  \\begin{m} x_1 & y_1 \\end{m} \\begin{m} 0 & 1 \\\\ 0 & 1 \\end{m} = & 0 \\\\\n  x_1 + y_1 = & 0 \\\\\n  \\ve{e_1} = & \\begin{m} t & -t \\end{m}\n\\end{align*}\n\nand for $\\lambda_2$~:\n\\begin{align*}\n  \\begin{m} x_2 & y_2 \\end{m} \\begin{m} 1-2 & 1 \\\\ 0 & 2-2 \\end{m} = & 0 \\\\\n  \\begin{m} x_2 & y_2 \\end{m} \\begin{m} -1 & 1 \\\\ 0 & 0 \\end{m} = & 0 \\\\\n  -x_2  = & 0 \\\\\n   x_2  = & 0 \\\\\n  \\ve{e_2} = \\begin{m} 0 & t \\end{m} = \\ve{y}\n\\end{align*}\n\nIf we look at our transformation picture again, we see that the relation in the direction $\\ve{e_1}$ is kept and the relation in the direction of $\\ve{e_2}$ is just doubled. This reflects the eigenvalues $1$ and $2$ with the directions of the eigenvectors $\\ve{e_1}$ and $\\ve{e_2}$.\n\n\nBefore moving on to the following section, we need to establish some properties of \\emph{symmetric} matrices. The first one is that such a matrix $\\ma{A}$ can be expressed by the multiplication of a diagonal matrix $\\ma{D}$ (all entries not on the diagonal are $\\ve{0}$) and an invertible matrix $\\ma{E}$~:\n\\begin{equation*}\n  \\ma{A} = \\ma{E}^T\\ma{D}\\ma{E}. \\label{symmetric}\n\\end{equation*}\n\nBecause $\\ma{A}$ is symmetric, the transpose $\\ma{A}^T$ of $\\ma{A}$ (mirror across the diagonal) is the same as $\\ma{A}$, we can therefore write~:\n\\begin{align*}\n  \\ma{A}^T = & (\\ma{E}^T\\ma{D}\\ma{E})^T \\\\\n           = &  \\ma{E}^T(\\ma{E}^T\\ma{D})^T \\\\\n           = &  \\ma{E}^T\\ma{D}^T\\ma{E}^{TT}\n\\end{align*}\nnow we simply replace $\\ma{D}^T$ by $\\ma{D}$ since a diagonal matrix is equivalent to its transpose and we replace $\\ma{E}^{TT}$ by $\\ma{E}$ since transposing twice is equivalent to doing nothing. We get\n\\[\n  \\ma{A}^T = \\ma{E}^T\\ma{D}\\ma{E} = \\ma{A}.\n\\]\n\nThis proves that any matrix that can be expressed as a product of an invertible matrix $\\ma{E}$ and a diagonal matrix $\\ma{D}$ is indeed symmetric. We should now prove the reverse~: that any symmetric matrix can be expressed as stated above. This proof is called the \\emph{spectral theorem}. While trying to understand it, I fell across strange names like \\emph{Hermitian matrices}, \\emph{Schur decomposition} and \\emph{Hilbert spaces}. It also involved matrix calculations with complex numbers. That was too much me. Sorry. For those interested, I found a proof which you can consult on the web\\footnote{(http://users.utu.fi/jkari/compression/kltaddition.pdf)}.\n\nAnyway, let's pass on to the interesting part~: the matrix $\\ma{E}$ used in the little talk above is in fact a matrix of the orthonormal eigenvectors of $\\ma{A}$ (those vectors that do not rotate when transformed by $\\ma{A}$). The proof is interesting but quite long, you can safely pass on to the section on \\emph{Principal Component Analysis} if you do not have fun with letters in capital bold.\n\n\\emph{Please note that the following proofs are a rewrite of the first appendix of the tutorial on PCA by Jonathon Shlens\\footnote{www.snl.salk.edu/~shlens/pub/notes/pca.pdf}}.\n\nFirst, lets build this matrix $\\ma{E}$ from the eigenvectors of $\\ma{A}$~:\n\\[\n  \\ma{E} = \\begin{m} \\ve{e_1} \\\\ \\vdots \\\\ \\ve{e_n} \\end{m}.\n\\]\n\nNow let $\\ma{D}$ be a diagonal matrix with the corresponding eigenvalues of $\\ma{A}$~:\n\\[\n  \\ma{D} = \\begin{m} \\lambda_1 & 0 & .. \\\\ 0 & \\lambda_2 & .. \\\\ \\vdots & \\vdots & \\ddots \\end{m}.\n\\]\n\nWe first try to prove that $\\ma{E}\\ma{A} = \\ma{D}\\ma{E}$~:\n\\begin{align*}\n  \\ma{E}\\ma{A} = \\begin{m} \\ve{e_1} \\\\ \\ve{e_2} \\\\ \\vdots \\end{m} \\ma{A} = & \n                 \\begin{m} \\ve{e_1}\\ma{A} \\\\ \\ve{e_2}\\ma{A} \\\\ \\vdots \\end{m} \\\\\n  \\ma{D}\\ma{E} = \\begin{m} \\lambda_1 & 0 & .. \\\\ 0 & \\lambda_2 & .. \\\\ \\vdots & \\vdots & \\ddots \\end{m} \\ma{E} = & \n                 \\begin{m} \\lambda_1\\ve{e_1} \\\\ \\lambda_2\\ve{e_2} \\\\ \\vdots \\end{m}.\n\\end{align*}\n\nFor $\\ma{E}\\ma{A}$ to be equal to $\\ma{D}\\ma{E}$, we must show that $\\ve{e_i}\\ma{A} = \\lambda_i\\ve{e_i}$ for all $i$. Remember that an eigenvector is \\emph{a vector that is scaled onto itself by the transformation}, that is $\\ve{e'} = \\lambda\\ve{e}$. This is exactly what the result of our equation states, thus the entries of $\\ma{E}$ are the eigenvectors of $\\ma{A}$ if $\\ma{E}\\ma{A} = \\ma{D}\\ma{E}$.\n\nTo finish the proof, we just need to show that $\\ma{E}\\ma{A} = \\ma{D}\\ma{E}$ implies $\\ma{A} = \\ma{E}^T\\ma{D}\\ma{E}$. By multiplying each side by $\\ma{E}^{-1}$, we obtain $\\ma{A} = \\ma{E}^{-1}\\ma{D}\\ma{E}$. If we could show that $\\ma{E}^{-1} = \\ma{E}^T$, we would have proven (\\ref{symmetric}). We know that $\\ma{E}^{-1} = \\ma{E}^T$ if $\\ma{E}$ is an orthogonal matrix since~:\n\\begin{align*}\n  \\ma{E}\\ma{E}^T = & \\begin{m} \\ve{e_1} \\\\ \\ve{e_2} \\\\ \\vdots \\end{m} \\begin{m} \\ve{e_1}^T & \\ve{e_2}^T & \\hdots \\end{m} \\\\\n                 = & \\begin{m} \\ve{e_1}\\ve{e_1}^T & \\ve{e_1}\\ve{e_2}^T & \\hdots \\\\ \\ve{e_2}\\ve{e_1}^T & \\ve{e_2}\\ve{e_2}^T & \\hdots \\\\ \\vdots & \\vdots & \\ddots \\end{m} \\\\\n                 = & \\begin{m} 1 & 0 & \\hdots \\\\ 0 & 1 & \\hdots \\\\ \\vdots & \\vdots & \\ddots \\end{m} \\\\\n                 = & \\ma{I}\n\\end{align*}\n\nbecause each vectors in an orthogonal matrix is $\\perp$ to other vectors, thus the dot product is zero except for the diagonal entries where it is equal to the squared norm of the vector. If we choose our eigenvectors so that their norm is 1, we obtain the identity matrix $\\ma{I}$. We just need to show that $\\ma{E}$ is an orthogonal matrix and pulling the thread out of this maze, we prove that a symmetric matrix can be expressed by (\\ref{symmetric}). We want to know if $\\vec(e_i) \\dot \\vec{e_j} = 0$ for all $i \\not= j$. Let $\\lambda_i$ and $\\lambda_j$ be two distinct eigenvalues.\n\\begin{align*}\n  \\lambda_i\\ve{e_i} \\cdot \\ve{e_j} = & \\lambda_i\\ve{e_i}\\ve{e_j}^T \\\\\n                                  = & \\ve{e_i}\\ma{A}\\ve{e_j}^T \\\\\n                                  = & \\ve{e_i}(\\ve{e_j}\\ma{A}^T)^T \\\\\n                                  = & \\ve{e_i}(\\ve{e_j}\\ma{A})^T \\\\\n                                  = & \\ve{e_i}(\\lambda_j\\ve{e_j}^T) \\\\\n  \\lambda_i\\ve{e_i} \\cdot \\ve{e_j} = & \\ve{e_i} \\cdot \\lambda_j\\ve{e_j}\n\\end{align*}\n\nThus $(\\lambda_i - \\lambda_j)\\ve{e_i} \\cdot \\ve{e_j} = 0$. Since we have conjectured that $\\lambda_i \\not= \\lambda_j$, it must be that $\\ve{e_i}$ and $\\ve{e_j}$ are orthonormal (their dot product is $0$). Therefore $\\ma{E}^{-1} = \\ma{E}^T$ and we can write~:\n\\[\n  \\ma{A} = \\ma{E}^T\\ma{D}\\ma{E}.\n\\]\n\nAll this work, just to reexpress an arbitrary symmetric matrix $\\ma{A}$\\dots But this result is the ground on which the next section is built.\n\n\\section{Principal Component Analysis}\n\nPrincipal Component Analysis is a way to extract the ``most proeminent features'' of a data set. It assumes that the data has a good signal to noise ratio which means that \\emph{great variance} in the data is a synonym for \\emph{relevant feature} and not \\emph{big noise}.\n\nIn all the calculations below, we need to use the \\emph{variations} of the measures. We will thus remove the mean values from our data set and use this new set called the \\emph{mean deviation form} of $\\ma{S}$~:\n\\[\n  \\ma{T} = \\ma{S} - \\begin{m}\\ve{\\mu} \\\\ \\vdots \\\\ \\ve{\\mu}\\end{m}.\n\\]\n\nIn order to extract the ``most proeminent features'' of our data, a good idea would be to look at the directions in which the data varies most. Is it along the $\\ve{x}$ axis ? The $\\ve{y}$ axis ? Somewhere in between ?\n\nRecall from the previous sections that the variance-covariance matrix $\\ma\\Sigma$ displays variances along the diagonal and covariances off-diagonal. We can use this matrix to extract directions in which the data varies most~:\n\\[\n  \\ma\\Sigma = \\frac{1}{n-1}\\ma{T}^T\\ma{T}.\n\\]\n\nBy looking at the diagonals of $\\Sigma$, we pick the greatest absolute value and there we are, we found our direction ($3 \\Rightarrow \\ve{y}$). Is that it ? No, this solution misses the fact that the main direction might not follow one of the axis (dimension) of our recorded data (the ellipsoid is not vertical nor horizontal). What we need is to apply a transformation (rotation + stretch) to our data $\\ma{T}$ into an new basis $\\ma{P}$ prior to looking at the variance-covariance matrix, so that the principal components align with the new basis' axis.\n\\begin{align*}\n  \\ma{T'} = & \\ma{T}\\ma{P} \\\\\n  \\ma\\Sigma'     = & \\frac{1}{n-1}\\ma{T'}^T\\ma{T'}\n\\end{align*}\n\nOur goal is thus to find a new basis $\\ma{P}$ that gives us great absolute values along the diagonals of $\\ma\\Sigma'$ and small absolute values off-diagonal (small redundancy). If possible, it would be great to see large variances along the top of the diagonal which would mean we could just cut off the rightmost part of the matrix $\\ma{T'}$ and still have most of the information on the varying signal. To summarize~:\n\\begin{itemize}\n  \\item Find a new basis $\\ma{P}$ that reduces the redundancy of the signals (low covariance).\n  \\item The $\\ma\\Sigma'$ matrix for $\\ma{T'}$ should ideally be a diagonal matrix with very high values at the top and very small at the bottom, thus showing signals in the first dimensions and pure noise in the last ones.\n  \\item We could then choose to remove the columns of $\\ma{T'}$ that have greater indices than the number of dimensions we want to keep thus reducing the dimensionality of our data.\n\\end{itemize}\n\nA simple way to find the solution would be~:\n\\begin{enumerate}\n  \\item Find the direction $\\ve{e_1}$ that shows the greatest variance in the data $\\ma{T}$. Normalize this vector. This is our first basis vector.\n  \\item Find another normalized vector showing the greatest variance that is orthogonal to those already found ($\\forall \\ve{b}\\in \\{\\text{found vectors}\\}, \\ve{e_n} \\perp \\ve{b}$).\n  \\item Repeat until we have $n$ basis vectors ($n$ is the size of vector space).\n\\end{enumerate}\n\nThe resulting ordered set of vectors are the \\emph{principal components} of our data set \\textbf{T}.\n\n\\section{computing PCA}\n\nMathematically stated, what we are looking for is a diagonalized version of $\\ma\\Sigma'$~:\n\\begin{align*}\n  \\ma\\Sigma'     = & \\frac{1}{n-1}\\ma{T'}^T\\ma{T'} \\\\\n                 = & \\frac{1}{n-1}(\\ma{T}\\ma{P})^T(\\ma{T}\\ma{P}) \\\\\n                 = & \\frac{1}{n-1}\\ma{P}^T\\ma{T}^T\\ma{T}\\ma{P}\n\\end{align*}\n\nDoes this look familiar to you ? Recall all our lengthy discussion on symmetrical matrices ? Well, $\\ma{T}^T\\ma{T}$ is such a matrix. Lets replace it by $\\ma{A}$. We get~:\n\\[\n  \\ma\\Sigma'     = \\frac{1}{n-1} \\ma{P}^T\\ma{A}\\ma{P}\n\\]\n\nNow what happens if we set $\\ma{P} = \\ma{E}^T$ and replace $\\ma{A}$ by $\\ma{E}^T\\ma{D}\\ma{E}$ from equation (\\ref{symmetric}) ?\n\\begin{align*}\n  \\ma\\Sigma' = & \\frac{1}{n-1}\\ma{E}\\ma{A}\\ma{E}^T \\\\\n             = & \\frac{1}{n-1}\\ma{E}(\\ma{E}^T\\ma{D}\\ma{E})\\ma{E}^T \\\\\n             = & \\frac{1}{n-1}\\ma{I}\\ma{D}\\ma{I} \\\\\n             = & \\frac{1}{n-1}\\ma{D}\n\\end{align*}\n\nWe have just found the transformation that diagonalizes the variance-covariance matrix. It's the transpose of the matrix of eigenvectors of $\\ma{T}^T\\ma{T}$ !\n\\[\n  \\ma{P} = \\ma{E}^T = \\begin{m} \\ve{e_1}^T & \\ve{e_2}^T & \\hdots \\end{m}\n\\]\nwhere $\\ve{e_i}$ is $i$th eigenvector of $\\ma{T}^T\\ma{T}$.\n\n\\section{applying PCA to $\\ma{S}$}\n\nUsing the same sample data as above, we imagine that the set of points $\\textbf{S}$ represents the measures of a moving element. The object actually moves only along the ellipsoid axis $\\ve{e} = \\begin{m}-1 & 2 \\end{m}$, the deviations from this axis is just noise. The goal of PCA is to re-express our set of data in a new basis that reflects this behaviour (data along $\\ve{e}$, noise along the other direction). The naive basis (in which we recorded the data) is~:\n\\[\n  \\ma{B} = \\begin{m} \\ve{x} \\\\ \\ve{y} \\end{m} = \\begin{m} 1 & 0 \\\\ 0 & 1 \\end{m} = \\ma{I}\n\\]\n\nWe will use PCA to find a new basis $\\ma{P}$ that is a linear combination of the original basis $\\ma{B}$ and in which we will only look at the data along the greatest axis of the ellipsoid (where the data exhibits the greatest variance). In this new basis, the set of data $\\ma{S}$ becomes~:\n\\[\n  \\ma{S'} = \\ma{S}\\ma{P}\n\\]\n\nThe new basis should optimise signal to noise ratio if we consider the first dimension as representing the signal and the second the noise~:\n\\[\n  SNR = \\frac{\\sigma_{signal}^2}{\\sigma_{noise}^2}\n\\]\n\nBefore delving any further, we must first transform our data into its \\emph{mean deviation form} $\\ma{T}$. \n\\[\n  \\ma{T} = \\ma{S} - \\begin{m}\\ve{\\mu} \\\\ \\vdots \\\\ \\ve{\\mu}\\end{m} = \\begin{m} 0 & -1 \\\\ -1 & 2 \\\\ 1 & -1\\end{m}.\n\\]\n\nWe can now easily compute the actual SNR~:\n\\[\n  SNR = \\frac{\\sum_{k=1}^l T_{k1}^2}{\\sum_{k=1}^l T_{k2}^2} = \\frac{0+1+1}{1+4+1} = \\frac{1}{3}\n\\]\n\nHow do we find the new basis that gives us the greatest SNR ? Expressed in another way, we could say~: how do we find the basis that shows greatest variance in the first dimension and mostly noise in the second ? From the preceding section, we know how to build $\\ma{P}$. Let's do it with our data. First we need to find the symmetric matrix $\\ma{A}$~:\n\\begin{align*}\n  \\ma{A} = & \\ma{T}^T\\ma{T} = \\begin{m} 0 & -1 & 1 \\\\ -1 & 2 & -1 \\end{m} \\begin{m} 0 & -1 \\\\ -1 & 2 \\\\ 1 & -1\\end{m} \\\\\n         = & \\begin{m} 2 & -3 \\\\ -3 & 6 \\end{m}\n\\end{align*}\n\nNow we must find the eigenvalues of this matrix~:\n\\begin{align*}\n  det(\\ma{A} - \\lambda\\ma{I}) = & 0 \\\\\n  det(\\begin{m} 2-\\lambda & -3 \\\\ -3 & 6-\\lambda \\end{m}) = & 0 \\\\\n  (2-\\lambda)(6-\\lambda) - 9 = & 0 \\\\\n  \\lambda^2 - 8\\lambda + 3 = & 0 \\\\\n  \\lambda_1 \\approx 7.6, \\lambda_2 \\approx 0.4.\n\\end{align*}\n\nThe corresponding eigenvectors are~:\n\n\\begin{align*}\n  \\begin{m}x & y\\end{m}\\begin{m} 2-\\lambda & -3 \\\\ -3 & 6-\\lambda \\end{m} = & 0 \\\\\n  \\left\\{ \\begin{array}{rl} x = & \\frac{3}{2-\\lambda} t \\\\ y = & t \\end{array} \\right.\n\\end{align*}\n\nWe want normed vectors so we add the rule $x^2 + y^2 = 1$ and we get~:\n\\begin{align*}\n  \\frac{9t^2}{(2 - \\lambda)^2} + t^2 = & 1 \\\\\n  t = & \\frac{2-\\lambda}{\\sqrt{9 + (2 - \\lambda)^2}} \\\\\n  t_1 \\approx & -0.9 \\\\\n  t_2 \\approx & 0.5 \\\\\n  \\ma{E} \\approx & \\begin{m}0.5 & -0.9 \\\\ 0.9 & 0.5 \\end{m}.\n\\end{align*}\n\nNow that we have our transformation matrix $\\ma{P}$\n\\[\n  \\ma{P} = \\ma{E}^T = \\begin{m}0.5 & 0.9 \\\\ -0.9 & 0.5 \\end{m}.\n\\]\nwe can transform our data $\\ma{T}$ into $\\ma{T}'$~:\n\\begin{align*}\n  \\ma{T}' = & \\ma{T}\\ma{P} \\approx \\begin{m} 0 & -1 \\\\ -1 & 2 \\\\ 1 & -1\\end{m}\\begin{m}0.5 & 0.9 \\\\ -0.9 & 0.5 \\end{m} \\\\\n    \\approx & \\begin{m} 0.9 & -0.5 \\\\ -2.2 & 0.1 \\\\ 1.4 & 0.4 \\\\ \\end{m}\n\\end{align*}\n\nWith this new transformation, we should have great variance along the first dimension and a very small one in the second (that was our goal). By looking at the values, this seems to be the case. Let's see with a picture.\n\n\\includegraphics{points2.pdf}\n\nJust to make sure our work was correct, let's compute the variance-covariance matrix $\\ma\\Sigma'$~:\n\\[\n  \\ma\\Sigma' = \\frac{1}{n-1}\\ma{T'}^T\\ma{T'} \\approx \\begin{m} 7.6 & 0 \\\\ 0 & 0.4 \\end{m}.\n\\]\n\nIt works ! And by the way, this is $\\ma{D}$ which is the diagonal matrix made out of the eigenvalues of $\\ma{A} = \\ma{T}^T\\ma{T}$ ($7.6$ and $0.4$).\n\nTo finish our goal of dimensionality reduction, we can build another version of the matrix $\\ma{P}$ that automatically strips off the ``noisy'' dimensions, only keeping the principal components of our data~:\n\\[\n  \\ma{Q} = \\ma{P}\\begin{m} 1 \\\\ 0 \\end{m} = \\begin{m}0.5 \\\\ -0.9\\end{m}.\n\\]\n\nAnd before closing this section, we need to compute our new signal to noise ratio~:\n\\[\n  SNR = \\frac{\\sum_{k=1}^l {T'}_{k1}^2}{\\sum_{k=1}^l {T'}_{k2}^2} \\approx \\frac{7.6}{0.4} = 19.3.\n\\]\n\nBy just looking at the $\\ve{y}$ axis, we would have obtained $3$. Applying the transformation $\\ma{P}$ made the signal much easier to analyse.\n\nThat's it (I'm glad I made it this far) !\n\n\\subsection{summary on PCA}\n\nPCA can be used as a filter to reduce the dimensionality of the data and ease the computation of the \\textbf{Mahalanobis distance} as this distance becomes the \\textbf{normalized Euclidean distance} with the new transformation since the covariances have been removed ($\\ma\\Sigma'$ is a diagonal matrix). The calculation of the transformation matrix $\\ma{P}$ involves the following computations~:\n\\begin{itemize}\n  \\item Find the mean vector $\\ve\\mu$.\n  \\item Substract this vector to each vector of the training set $\\ma{S}$ to obtain the \\emph{mean deviation form} $\\ma{T}$.\n  \\item Find the eigenvectors of the symmetric matrix $\\ma{T}^T\\ma{T}$, sorted by decreasing eigenvalues.\n  \\item Build the transformation matrix $\\ma{P} = \\begin{m}\\ve{e_1}^T & \\ve{e_2}^T & \\hdots & \\ve{e_k}^T \\end{m}$ with $k \\leq n$ to keep the $k$ most relevant dimensions of the transformed data.\n  \\item Apply this transformation $\\ma{P}$ to any test vector $\\ve{t}$ before computing the normalized Euclidean distance to the mean value $\\ve\\mu$.\n  \\item The smaller the distance, the bigger the probability that $\\ve{t}$ belongs to the set $\\ma{S}$.\n\\end{itemize}\n\nAmong all the steps above, two are problematic for large matrices: finding the eigenvalues and eigenvectors. These steps imply solving the \\emph{characteristic polynomial} of $\\ma{A}$. If our data contains 12 measures x 100 samples per row, the dimension of our polynomial is 1200 ! To find the eigenvector we have to solve n times a system of n-1 equations. This can become daunting. That was for the bad news. The good news is that these calculations must only be done on the training set, not live. The even better news is that there exists a library written in Fortran called \\emph{LAPACK} that can do the job as fast as the most clever people could make it. Thanks.\n\\subsection{notes on PCA}\n\nFor a deaper understanding of PCA and it's limits, one may have a look at~:\n\\begin{itemize}\n  \\item \\emph{kernel PCA} to apply a non-linear filter prior to applying PCA for problems where linearity is an issue.\n  \\item \\emph{ICA} for sets of data whose distribution probabilities are not exponential (Gaussian, Exponential, etc).\n  \\item \\emph{Central Limit Theorem} on why PCA should work most of the time in real world as probabilities usually \\textbf{are} gaussian.\n\\end{itemize}\n\n\n\\section{Movement recognition}\n\nFrom the knowledge we have gathered above, we can now try to find a way to compare the movements. Imagine we have 3 movements (classes) labeled $a$, $b$ and $c$. Each movement has been recorded several times. We create the training sets $\\ma{S_a}$, $\\ma{S_b}$ and $\\ma{S_c}$ with the recordings of the different movements. Each move is made of 2 measures recorded for 10 samples. We write it as a row vector of dimension 20 ($\\ve{s_{ai}}$).\n\n\n\\section{Filtering (PCA)}\n\nWe start by computing the mean vector for each movement. We will note the number of recordings for the current movement $r$~:\n\\[\n  \\ve\\mu_a = \\frac{1}{r}\\sum_{k=1}^r \\begin{m}\\ve{s_{a1k}} & \\ve{s_{a2k}} & \\hdots & \\ve{s_{a20k}} \\end{m}\n\\]\nWe do this for each class $a$, $b$ and $c$. We then build a matrix out of these prototypes~:\n\\[\n  \\ma{S} = \\begin{m}\\ve\\mu_a \\\\ \\ve\\mu_b \\\\ \\ve\\mu_c \\end{m}\n\\]\n\nWe now find the mean deviation form of $\\ma{S}$ after finding the mean value of all the prototypes ($\\ve\\mu$)~:\n\\[\n  \\ma{T} = \\begin{m}\\ve\\mu_a - \\ve\\mu \\\\ \\ve\\mu_b - \\ve\\mu \\\\ \\ve\\mu_c - \\ve\\mu \\end{m}\n\\]\n\nNow that we have found the \\emph{least varying parts} of each movement (the ``platonic idea'') by computing the average, we will find a transformation that shows the \\emph{most varying parts} \\textbf{between} these movements. We apply PCA on the matrix $\\ma{T}$ and find the transformation matrix $\\ma{P}$.\n\\[\n  \\ma{P} = \\ma{E}^T \\ma{I_{reduc}}\n\\]\nWhere $\\ma{I_{reduc}}$ is a truncated identity matrix to reduce the dimensionality of the data to the principal components.\n\n\\section{Recognition}\n\nTo label new vectors, we could use the Mahalanobis distance or Euclidean distance in the transformed vector space produced by PCA. This is the first solution discussed below. The other approach is to use \\emph{Support Vector Machines}. This is the solution which we will try to use if our hardware is fast enough since it produces better results.\n\n\\subsection{Distances}\n\nWe now have two options. Either we use the information contained in the eigenvalues (matrix $\\ma{D}$) to compute the normalized Euclidean distances between our test vector and the prototypes in the new coordinate system defined by the transformation $\\ma{P}$ or we map all our training data into the new coordinate system and compute the Mahalanobis distance to each set. This last solution loses some information from the \\emph{differences between the different classes $a$, $b$ and $c$} but takes into account what is noise and what is a signal in each movement. Since we have already included the information on what makes the differences between the classes when we chose to remove the dimensions with least variance, the second solution seems to keep most of the information contained in the training data.\n\nTransforming each training set into the new coordinate system is done by\n\\begin{align*}\n  \\ma{S_{a}'} = & \\ma{S_a}\\ma{P} \\\\\n  \\ma{S_{b}'} = & \\ma{S_b}\\ma{P} \\\\\n  \\ma{S_{c}'} = & \\ma{S_c}\\ma{P} \\\\\n\\end{align*}\n\nWe now compute the variance-covariance for each of these matrices~:\n\\begin{align*}\n  \\ma\\Sigma_a' = & \\frac{1}{r-1}\\ma{S_{a}'}^T\\ma{S_{a}'} \\\\\n  \\ma\\Sigma_b' = & \\frac{1}{r-1}\\ma{S_{b}'}^T\\ma{S_{b}'} \\\\\n  \\ma\\Sigma_c' = & \\frac{1}{r-1}\\ma{S_{c}'}^T\\ma{S_{c}'} \\\\\n\\end{align*}\n\nNormalization of the values in these matrices ?\n\\begin{align*}\n  \\ma\\Sigma_{aij}' = & \\frac{\\ma\\Sigma_{aij}'}{\\sum_{k=1}^3 \\ma\\Sigma_{kij}'}\n\\end{align*}\n\nTo label an arbitrary movement $\\ve{t}$, we find the minimal Mahalanobis distance to the sets in the new coordinate system.\n\\begin{align*}\n  \\ve{t_k'} = & \\ve{t'} - \\ve{\\mu_k'} \\\\\n            = & \\ve{t}\\ma{P} - \\ve{\\mu_k'} \\\\\n  \\argmin_{k} D_M(\\ve{t}) = & \\argmin_{k} \\sqrt{\\ve{t_k'}\\Sigma_k'^{-1}\\ve{t_k'}^T}\n\\end{align*}\n\nThe value returned by argmin ($k$) is the label for the test movement.\n\n\\subsection{Support Vector Machines}\n\n\\emph{Support Vector Machines} is a new mathematical tool for pattern recognition. Basically, it involves mapping the data into a new vector space (once more) with higher dimensions this time. The goal is to find a vector space in which the data is linearly separable (you can draw a line/plane/... between the different classes). For example, imagine you have two sets of data $a$ and $b$: all values for set $a$ are inside a circle located on the origine and all values for $b$ are outside of this circle. If we add a third dimension that is the distance to the origine, we will obtain a cone pointing downward. All points from the set $a$ are located below a certain height and all point from set $b$ are above this height. We can thus split the set using a plane that cuts the cone at this height.\n\nTo apply SVM, we first filter all our data set with PCA:\n\\begin{align*}\n  \\ma{S_{a}'} = & \\ma{S_a}\\ma{P} \\\\\n  \\ma{S_{b}'} = & \\ma{S_b}\\ma{P} \\\\\n  \\ma{S_{c}'} = & \\ma{S_c}\\ma{P} \\\\\n\\end{align*}\n\nWe then feed the svm library\\footnote{http://www.csie.ntu.edu.tw/~cjlin/libsvm} (we could never have written this code) with two arrays~: a list of labels and a list of vectors. We thus feed it with set $S_{a}'$, telling it these vectors have the label ``a'', $S_{b}'$ with label ``b'' and $S_{c}'$ with label ``c''. We then call the learn function.\n\nTo test an arbitrary movement $\\ve{t}$, we must first move it into the vector space defined by PCA and then send it into SVM. The SVM black box will return the label for the test vector.\n\\begin{align*}\n  \\ve{t_k'} = & \\ve{t'} - \\ve{\\mu_k'} \\\\\n            = & \\ve{t}\\ma{P} - \\ve{\\mu_k'} \\\\\n  \\text{label} = & \\text{svmlib.predict}(\\ve{t_k'})\n\\end{align*}\n\n\\onecolumn\n\n\\section{Ruby code}\n\\subsection{variance}\n\\begin{verbatim}\nset   = [1,4,3,6]\nmu    = set.inject(0) {|s,v| s + v } / set.size.to_f\nsigma = set.inject(0) {|s,v| s + ((v - mu)**2) } / set.size.to_f\n\\end{verbatim}\n\n\\subsection{Mahalanobis distance}\n\\begin{verbatim}\nclass Array\n  # transpose\n  def t\n    cols = []\n    self[0].each_index do |i|\n      cols[i] = map {|v| v[i]}\n    end\n    cols\n  end\n\n  def *(m)\n    res = []\n    each_index do |row|\n      res[row] = []\n      m[0].each_index do |col|\n        res[row][col] = 0\n        self[0].each_index do |i|\n          res[row][col] += self[row][i] * m[i][col]\n        end\n      end\n    end\n    res\n  end\n\n  def det\n    (self[0][0] * self[1][1]) - (self[1][0] * self[0][1])\n  end\n\n  def /(scalar)\n    map {|row| row.map {|v| v / scalar}}\n  end\n\n  # vector substraction\n  def -(v)\n    res = [[]]\n    self[0].each_index {|i| res[0][i] = self[0][i] - v[0][i]}\n    res\n  end\n\n  def to_s\n    if self.size > 1 || self[0].size > 1\n      if self.size == 1\n        row_format = '[' + (\" %3.1f\" * self[0].size) + \" ]\\n\"\n      else\n        row_format = '|' + (\" %3.1f\" * self[0].size) + \" |\\n\"\n      end\n      self.inject(\"\") {|s,row| s + sprintf(row_format, *row)}\n    else\n      self[0][0].to_s\n    end\n  end\n\n  def map_index(&block)\n    res = []\n    self.each_index do |i|\n      res[i] = yield(i,self[i])\n    end\n    res\n  end\nend\n\n\nset = [[1,1],\n       [0,4],\n       [2,1]]\n# mean vector mu\nmu = [[]]\nset[0].each_index do |i|\n  mu[0][i] = set.inject(0) {|s,v| s + v[i] } / set.size.to_f\nend\n\n# set - mu\ns_mu = set.map do |v|\n  r = []\n  v.each_index do |i|\n    r[i] = v[i] - mu[0][i]\n  end\n  r\nend\n\n# variance-covariance matrix\nsigma = (s_mu.t * s_mu) / (set.size - 1.0).to_f\n\n# inverse of sigma\nif sigma.det == 0\n  puts \"Matrix not invertible\"\n  return\nend\n\n# invers of sigma (only for a 2x2 matrix)\nsigma_inv = [[  sigma[1][1], -sigma[0][1] ],\n             [ -sigma[1][0],  sigma[0][0] ]] / sigma.det\n\nputs \"Sigma\\n\\n\"\nputs sigma.to_s\nputs \"\\nSigma's inverse\\n\\n\"\nputs sigma_inv.to_s\n\nputs \"\\n\\nAll results express value^2 (before square root)\"\n\n[\n[[[2  , 2  ]],\n[ [1  , 3  ]]],\n[[[1.5, 1.5]],\n[ [1.5, 2.5]]]\n].each do |t1,t2|\n  puts \"\\n-----------------------------\"\n  puts \"t1   = #{t1}\"\n  puts \"t2   = #{t2}\"\n  puts \"t1-u = #{t1 - mu}\"\n  puts \"t2-u = #{t2 - mu}\\n\\n\"\n\n  d1 = (t1 - mu).flatten.inject(0) {|s,v| s + v**2} \n  d2 = (t2 - mu).flatten.inject(0) {|s,v| s + v**2}\n\n  puts \"d1   = #{d1}\"\n  puts \"d2   = #{d2}\\n\\n\"\n\n  d1nE = (t1 - mu).flatten.map_index{|i,v| v**2 / sigma[i][i] }.inject(0) {|s,v| s + v } \n  d2nE = (t2 - mu).flatten.map_index{|i,v| v**2 / sigma[i][i] }.inject(0) {|s,v| s + v } \n\n  puts \"d1nE = #{d1nE}\"\n  puts \"d2nE = #{d2nE}\\n\\n\"\n\n  d1M = (t1 - mu) * sigma_inv * (t1 - mu).t\n  d2M = (t2 - mu) * sigma_inv * (t2 - mu).t\n\n  puts \"d1M  = #{d1M}\"\n  puts \"d2M  = #{d2M}\\n\\n\"\nend\n\\end{verbatim}\n\\end{document}", "meta": {"hexsha": "9ccc1bddd0384b481c430e80d5230df4a8aecb75", "size": 37074, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/math.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/math.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/math.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": 50.5095367847, "max_line_length": 811, "alphanum_fraction": 0.6333279387, "num_tokens": 13092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.676286437959442}}
{"text": "% -----------------------------------------------------------------------------------\n% Section   : \n% -----------------------------------------------------------------------------------\n\n\n\n\\section*{Data Structure}\n\n\nFirst we describe the setting and data structure. We have a stream of items $\\set{i_1, i_2, ...}$ where each $i$ comes from some finite universe $\\pmb{I} = \\set{1,..,i,..n}$, and we are interested in the approximate frequence of each $i$. The Count-Min Sketch algorithms $Init$ialize a fixed array of counters, of width $w$ and depth $d$, where the counters are initialized to all zeros. Each row $j$ of counters is associated with a different pairwise independent hash function $\\mathcal{H}_j : i \\send \\set{1,..,w}$ mapping items $i$ uniformly onto the column index. Now the hash functions do not need to be particularly strong a la cryptographic hash functions. In our setting where items are simply integers, we have:\n\t\\[\n\t\t\\mathcal{H}_j = a_j \\times i + b_j \\quad mod \\quad p \\quad mod \\quad w\n\t\\]\n\nwhere p is some prime number far larger than $n$, say $p = 2^n - 1$, and $a_j$ and $b_j$ are chosen uniformly from $(1,p)$. But note each $\\mathcal{H}_j$ must be different, otherwise there is no benefit from the repetition.\\newline\n\n\\section*{Functions over the data structure}\n\nOnce the counters or sketch and hash functions are initalized, we $Update$ the sketch as items $i$ come in from the stream. Meanwhile we may $Estimate$ the frequency of any $i$ using our counters and hash table. Consider the pseudocode below. \\newline\n\n\n\\begin{algorithm}\n\\caption{Init(w,d,p)}\\label{euclid}\n\\begin{algorithmic}[1]\n\t\\State $C[1,1]...C[d,w] \\gets 0$\n\t\\For {$j \\gets 1 \\textit{ to d}$}\n\t\t\\State \\textit{pick $a_j,b_j$ uniformly from $[1..p]$}\n\t\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\\begin{algorithm}\n\\caption{Update(i)}\\label{euclid}\n\\begin{algorithmic}[1]\n\t\\For {$j \\gets 1 \\textit{ to d}$}\n\t\t\\State $h_j(i) = (a_j \\times i + b_j) \\quad mod \\quad p \\quad mod \\quad w$\n\t\t\\State $C[j,h_j(i)]  \\leftarrow C[j,h_j(i)] + 1$\n\t\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\begin{algorithm}\n\\caption{Estimate(i)}\\label{euclid}\n\\begin{algorithmic}[1]\n\t\\State $e \\gets \\infty$\n\t\\For {$j \\gets 1 \\textit{ to d}$}\n\t\t\\State $h_j(i) = (a_j \\times i + b_j) \\quad mod \\quad p \\quad mod \\quad w$\n\t\t\\State $e \\leftarrow min(e,C[j,h_j(i)]$\n\t\\EndFor\n\t\\State $return \\quad e$\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\n\n\n\n\n\n\n\n\n\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": "5859aceecd3f934e9529a1089b546c002de7ef04", "size": 2447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sec/overview.tex", "max_stars_repo_name": "lingxiao/CIS700", "max_stars_repo_head_hexsha": "0aebe925c4b413a37d75b8c782a3dffd53851f8a", "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/sec/overview.tex", "max_issues_repo_name": "lingxiao/CIS700", "max_issues_repo_head_hexsha": "0aebe925c4b413a37d75b8c782a3dffd53851f8a", "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/sec/overview.tex", "max_forks_repo_name": "lingxiao/CIS700", "max_forks_repo_head_hexsha": "0aebe925c4b413a37d75b8c782a3dffd53851f8a", "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": 26.597826087, "max_line_length": 721, "alphanum_fraction": 0.6362893339, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6762817422718446}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[fleqn]{amsmath}\n\\usepackage{tikz}\n\\usepackage{subfiles}\n\n\\title{\\vspace{-4\\baselineskip}MATH 225 - Homework \\#2}\n\\author{D. Choi}\n\\date{2020-05-22}\n\n%\\pagenumbering{gobble}\n\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Find the matrix that reflects space across the\n$y = \\tan(25^\\circ)x$\nline.\n} \\\\[\\baselineskip]\nLet $A$ be such a matrix. \\\\\nThe elements of $A$ can be found by computing where the standard basis vectors\nwill land after being reflected across the\n$y = \\tan(25^\\circ)x$\nline.\n\\begin{equation*}\n\tA\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0\n\t\\end{pmatrix}\n\t=\n\tA\n\t\\begin{pmatrix}\n\t\t\\cos0 \\\\\n\t\t\\sin0\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(2 \\cdot 25^\\circ) \\\\\n\t\t\\sin(2 \\cdot 25^\\circ)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(50^\\circ) \\\\\n\t\t\\sin(50^\\circ)\n\t\\end{pmatrix}\n\\end{equation*}\n\\begin{equation*}\n\tA\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t1\n\t\\end{pmatrix}\n\t=\n\tA\n\t\\begin{pmatrix}\n\t\t\\cos(90^\\circ) \\\\\n\t\t\\sin(90^\\circ)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(90^\\circ - 2 \\cdot 65^\\circ) \\\\\n\t\t\\sin(90^\\circ - 2 \\cdot 65^\\circ)\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(-40^\\circ) \\\\\n\t\t\\sin(-40^\\circ)\n\t\\end{pmatrix}\n\\end{equation*}\n\\begin{equation*}\n\tA =\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t\\cos(50^\\circ) & \\cos(-40^\\circ) \\\\\n\t\t\t\\sin(50^\\circ) & \\sin(-40^\\circ)\n\t\t\\end{pmatrix}\n\t}\n\\end{equation*}\n\n\\section*{2.}\n\\begin{equation*}\n\tM =\n\t\\begin{pmatrix}\n\t\t\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\\n\t\t-\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\n\t\\end{pmatrix}\n\\end{equation*}\n\\textit{Find $M^2$, $M^3$, $M^4$, $M^{17}$.} \\\\[\\baselineskip]\nLet $R(\\theta)$ be the rotation matrix where\n\\begin{equation*}\n\tR(\\theta) =\n\t\\begin{pmatrix}\n\t\t\\cos \\theta & -\\sin \\theta \\\\\n\t\t\\sin \\theta & \\cos \\theta\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\n$M$ can be considered as a specific instance of $R(\\theta)$ where\n$\\theta = -45^\\circ$.\n\\begin{equation*}\n\tM =\n\t\\begin{pmatrix}\n\t\t\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\\n\t\t-\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(-45^\\circ) & -\\sin(-45^\\circ) \\\\\n\t\t\\sin(-45^\\circ) & \\cos(-45^\\circ)\n\t\\end{pmatrix}\n\t=\n\tR(-45^\\circ)\n\\end{equation*}\nBecause $R(\\theta)$ has the property of\n\\begin{equation*}\n\t(R(\\theta))^n = R(\\theta n),\n\\end{equation*}\nit can be said for $M$ that\n\\begin{equation*}\n\tM^n = R(-45^\\circ \\cdot n).\n\\end{equation*}\nThus,\n\\begin{gather*}\n\t\\boxed{M^2 = R(-45^\\circ \\cdot 2) = R(-90^\\circ)}, \\\\\n\t\\boxed{M^3 = R(-45^\\circ \\cdot 3) = R(-135^\\circ)}, \\\\\n\t\\boxed{M^4 = R(-45^\\circ \\cdot 4) = R(-180^\\circ)},\\text{ and} \\\\\n\t\\boxed{M^{17} = R(-45^\\circ \\cdot 17) = R(-45^\\circ) = M} .\n\\end{gather*}\n\n\\section*{3.}\n\\textit{Which is linear?}\n\\begin{gather*}\n\tf(x,y) = \\langle 3x^2 + y, 2x + y \\rangle \\\\\n\tg(x,y) = \\langle 3x + y, x + 3y \\rangle\n\\end{gather*}\n\\textit{Find the corresponding matrix for the linear transformation.}\n\\bigskip\n\\begin{equation*}\n\tf(2\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0\n\t\\end{pmatrix}\n\t)\n\t=\n\tf\n\t\\begin{pmatrix}\n\t\t2 \\\\\n\t\t0\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t3(2)^2 + (0) \\\\\n\t\t2(2) + 0\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t12 \\\\\n\t\t4\n\t\\end{pmatrix}\n\\end{equation*}\n\\begin{equation*}\n\t2f\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0\n\t\\end{pmatrix}\n\t=\n\t2\n\t\\begin{pmatrix}\n\t\t3(1)^2 + 0 \\\\\n\t\t2(1) + 0\n\t\\end{pmatrix}\n\t=\n\t2\n\t\\begin{pmatrix}\n\t\t3 \\\\\n\t\t2\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t6 \\\\\n\t\t4\n\t\\end{pmatrix}\n\\end{equation*}\nAs\n\\begin{equation*}\n\tf(2\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0\n\t\\end{pmatrix}\n\t)\n\t\\neq\n\t2f\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0\n\t\\end{pmatrix},\n\\end{equation*}\n$f$ is not homogeneous of degree 1, a property which linearity requires. \\\\\nThus, $f$ is not linear.\n\\begin{equation*}\n\tg\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty\n\t\\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t3x + y \\\\\n\t\tx + 3y\n\t\\end{pmatrix}\n\t=\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t3 & 1 \\\\\n\t\t\t1 & 3\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tx \\\\\n\t\t\ty\n\t\t\\end{pmatrix}\n\t}\n\\end{equation*}\n\n\\section*{4.}\n\\textit{Use geometry (graph paper) to find}\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t4 & 1 \\\\\n\t\t1 & 4\n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t1\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\n\\bigskip\n\\subfile{fig}\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t4 & 1 \\\\\n\t\t1 & 4\n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t1\n\t\\end{pmatrix}\n\t=\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t5 \\\\\n\t\t\t5\n\t\t\\end{pmatrix}\n\t}\n\\end{equation*}\n\n\\end{document}", "meta": {"hexsha": "8cf6e6068ab722cdbfdcf767fa081e7d1dfb8635", "size": 4243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw02/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/hw02/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/hw02/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": 16.2567049808, "max_line_length": 78, "alphanum_fraction": 0.5906198444, "num_tokens": 1891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.6762817377409116}}
{"text": "\\documentclass[aspectratio=169]{beamer}\n\n% because we need to claim weird things\n\\newtheorem{claim}{Claim}\n\\newtheorem{defn}{Definition}\n%\\newtheorem{lemma}{Lemma}\n\\newtheorem{thm}{Theorem}\n\\newtheorem{vita}{Vit\\ae}\n\\newtheorem{qotd}{Quote of the Day}\n\\renewcommand{\\qedsymbol}{$\\blacksquare$}\n\n\\usepackage{algorithm}\n\\usepackage{algpseudocode}\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{graphics}\n\\usepackage{ulem}\n\\bibliographystyle{unsrt}\n\n% background image\n\\usebackgroundtemplate%\n{%\n    \\includegraphics[width=\\paperwidth,height=\\paperheight]{../artifacts/stemulus.pdf}%\n}\n\\setbeamertemplate{caption}[numbered]\n\\lstset{%\n\tbreaklines=true,\n\tcaptionpos=b,\n\tframe=single,\n\tkeepspaces=true,\n\tshowstringspaces=false\n}\n\n% page numbers\n\\addtobeamertemplate{navigation symbols}{}{%\n    \\usebeamerfont{footline}%\n    \\usebeamercolor[fg]{footline}%\n    \\hspace{1em}%\n    \\insertframenumber/\\inserttotalframenumber\n}\n\n% presentation header\n\\usetheme{Warsaw}\n\\title{Big $\\mathcal{O}$ Notation}\n\\author{Dylan Lane McDonald}\n\\institute{CNM STEMulus Center\\\\Web Development with PHP}\n\\date{\\today}\n\n\\begin{document}\n\\lstset{language=Java}\n\\begin{frame}\n\\titlepage\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Outline}\n\\tableofcontents\n\\end{frame}\n\n\\section{Mathematics}\n\\subsection{Limits}\n\\begin{frame}\n\\frametitle{Limits}\nIntuitively, the \\textbf{limit} of a function $f(x)$ as $x$ approaches a value $c$ is where the function will arrive at $c$. Consider the function:\n\\begin{equation}\nf(x) = \\frac {x - 1}{x - 1}\n\\label{eqn:ratio}\n\\end{equation}\nAt $f(1)$, we get $f(1) = \\frac 00$, which does not exist. But, as we approach for values $x \\pm \\varepsilon$ for $\\varepsilon \\in \\mathbb{R}^+$ and $\\varepsilon$ is very small, $f(x) = 1$. Informally, since both sides ``agree'' on the fact $f(x)$ is really tending toward $1$, we define the limit of $f(x)$ as $x$ approaches 1 to be 1. Symbolically, this is written:\n\\[\n\\lim_{x \\rightarrow 1} f(x) = \\lim_{x \\rightarrow 1} \\left(\\frac {x - 1}{x - 1}\\right) = 1\n\\]\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Limits to Infinity}\nIn computer science, the most useful limit to consider is the limit of a function as it approaches infinity. That is, as the function's input grow larger, where does the function approach? Most algebraic and transcendental functions will also tend toward $\\infty$. Consider a function that doesn't tend toward $\\infty$:\n\\[\n\\lim_{x \\rightarrow \\infty} \\left(\\frac 1x\\right) = 0\n\\]\nIntuitively, this is so because as the denominator gets larger and larger, it ``dominates'' the one in the numerator and brings the ratio closer and closer to zero.\n\\end{frame}\n\n\n\\section{Algorithmic Complexity}\n\\begin{frame}\n\\frametitle{Algorithmic Complexity: English}\nIntuitively, computer scientists are interested in how long it takes a computer to solve a problem. But how long something takes in real time is too complicated to address because run times will vary from Windows to Linux to iPads, etc. Instead, the theoretical bounds on the problem with respect to the input size is studied. This is an introduction to a broad field called \\textbf{algorithmic analysis}.\n\n\\mbox{}\\\\\n\\pause\nThe main measure of algorithmic complexity is known as $\\mathcal{O}$ (``Big O'') notation. The intuitive question $\\mathcal{O}$ sets out to answer is, ``What is the longest I can expect this program to take?'' That is, as the problem grows in size, how much longer will this program take to process the additional input?\n\\end{frame}\n\n\\subsection{Graphical}\n\\begin{frame}\n\\begin{figure}\n\\includegraphics[scale=0.21]{../artifacts/big-o-knuth.png}\n\\caption{Adventures in $\\mathcal{O}()$}\n\\label{fig:xkcd}\n\\end{figure}\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Algorithmic Complexity: Graphical}\n\\begin{figure}\n\\includegraphics[scale=0.725]{../artifacts/big-o-plot.pdf}\n\\caption{Two $\\mathcal{O}()$ Functions}\n\\label{fig:big-o}\n\\end{figure}\n\\end{frame}\n\n\\subsection{Algebra}\n\\begin{frame}\n\\frametitle{Algorithmic Complexity: Algebraic}\nSuppose the two functions in Figure \\ref{fig:big-o} are two different programs that solve the same problem. The $\\mathcal{O}(n)$ function is more efficient for small inputs and can be used when data sets a very small. The $\\mathcal{O}(\\log n)$\\footnote{In computer science, logarithms are base 2.} is more scaleable and suitable for larger inputs.\n\n\\mbox{}\\\\\n\\pause\nNote the $\\mathcal{O}(n)$ function is not exactly $f(x) = x$, but instead $f(x) = \\frac 14 x$. This sets up one of the fundamental problems $\\mathcal{O}$ answers: Given $c \\in \\mathbb{R}^+$ and $n_0 \\in \\mathbb{R}^+$, when does is function $c \\cdot f(n) \\le g(n)$ for all $n \\ge n_0$? If such $c$ and $n_0$ exist, it follows that $f(n) = \\mathcal{O}(g(n))$.\n\n\\mbox{}\\\\\n\\pause\nIn the example in Figure \\ref{fig:big-o}, $\\log(n)$ is $\\mathcal{O}(n)$ for $c = \\frac 14$ and $n_0 = 16$.\n\\end{frame}\n\n\\subsection{Calculus}\n\\begin{frame}\n\\frametitle{Algorithmic Complexity: Calculus}\nLet $f(n)$ and $g(n)$ be two functions that return positive real numbers (i.e., $f : \\mathbb{D}_f \\rightarrow \\mathbb{R}^+$ and $g : \\mathbb{D}_g \\rightarrow \\mathbb{R}^+$). Define $f(n)$ as $\\mathcal{O}(g(n))$ if and only if:\n\\begin{equation}\n\\lim_{n \\rightarrow \\infty} \\left| \\frac{f(n)}{g(n)}\\right| < \\infty\n\\label{eqn:limit}\n\\end{equation}\nThat is, as $n$ approaches $\\infty$ in Equation \\ref{eqn:limit}, the quotient of the algorithm and the function will approach some value $\\alpha$. If $\\alpha$ is a finite number, this implies that $f(n)$ and $g(n)$ are ``sufficiently similiar'' for the algorithm $f(n)$ as $\\mathcal{O}(g(n))$. On the other hand, if $\\alpha = \\pm \\infty$ (and the limit in Equation \\ref{eqn:limit} therefore does not exist), then $f(n)$ and $g(n)$ are not similar and it is not the case that $f(n)$ is $\\mathcal{O}(g(n))$.\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Common $\\mathcal{O}()$ Values}\n\\begin{table}\n\\begin{tabular}{|l|l|l|}\n\\hline\n\\textbf{Value} & \\textbf{Name} & \\textbf{Example}\\\\\n\\hline\n$\\mathcal{O}(1)$ & Constant & Accessing an array member\\\\\n\\hline\n$\\mathcal{O}(\\log n)$ & Logarithmic & Searching an index or tree\\\\\n\\hline\n$\\mathcal{O}(n)$ & Linear & Na\\\"{i}vely searching an array\\\\\n\\hline\n$\\mathcal{O}(n \\log n)$ & Loglinear & Sorting an array\\\\\n\\hline\n$\\mathcal{O}(n^2)$ & Quadratic &  Matrix multiplication\\\\\n\\hline\n$\\mathcal{O}(n^3)$ & Cubic & Finding a determinant of a matrix\\\\\n\\hline\n$\\mathcal{O}(a^n)$ & Exponential & Traveling salesman: dynamic programming\\\\\n\\hline\n$\\mathcal{O}(n!)$ & Factorial & Traveling salesman: directly\\\\\n\\hline\n\\end{tabular}\n\\caption{Common $\\mathcal{O}$ Values \\& Examples}\n\\label{tbl:values}\n\\end{table}\n\\end{frame}\n\n\\subsection{Impact}\n\\begin{frame}\n\\frametitle{Impact}\nEach line of code has an associated $\\mathcal{O}()$ value. As each line of code executes, the performance impact is felt. For instance, if we have three lines of code: two of which are $\\mathcal{O}(n)$ and one is $\\mathcal{O}(n \\log n)$, the program is $\\mathcal{O}(n \\log n)$ since the $\\mathcal{O}(n \\log n)$ is larger and ``dominates'' the $\\mathcal{O}(n)$ lines of code.\n\n\\mbox{}\\\\\n\\pause\nA loop has the general effect of multiplying the complexity into $n$. Using the three lines of code in the previous example, there are two lines of code that are $\\mathcal{O}(n^2)$ and one that is $\\mathcal{O}(n^2 \\log n)$. Again, the $\\mathcal{O}(n^2 \\log n)$ ``dominates'' and the program is $\\mathcal{O}(n^2 \\log n)$.\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Example}\n\\begin{theorem}\nA function that has an exact run time of $f(n) = 2^{n + 10}$ is $\\mathcal{O}(2^n)$.\n\\end{theorem}\n\\begin{proof}\nRewrite $f(n)$ as $f(n) = 2^{10} \\cdot 2^n = 1024 \\cdot 2^n$. Defining the limit as seen in Equation \\ref{eqn:limit}, we get:\n\\[\n\\lim_{n \\rightarrow \\infty} \\left| \\frac{1024 \\cdot 2^n}{2^n} \\right| = \\lim_{n \\rightarrow \\infty} \\left| 1024 \\right| = 1024\n\\]\nSince, the limit exists, it follows that $f(n)$ is $\\mathcal{O}(2^n)$.\n\\end{proof}\nIt should be noted that, in this case, $c = 1024$ and $n_0 = 10$,\\\\\nsimilar to what was seen in the Algebraic section.\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Final Thought}\nThe selection of algorithms and data structures often leads to very large consequences in how programs, whether on or off the web, perform. These are measured in $\\mathcal{O}()$ form. Knowing common complexities for every day tasks is valuable and facilitates the informed choices of which algorithms to use as well being a powerful tool in performance optimization of programs.\n\n\\mbox{}\\\\\nAlso, carefully consider using slower algorithms within loops, as they tend to be exacerbated by the fact loops generally introduce a factor of $n$ to any operation being performed. This has been one of the largest sources of slow down in my professional experience.\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "cb999fa695204935dfabd9a25e08f06532c1cd5a", "size": 8756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "big-o/big-o.tex", "max_stars_repo_name": "dylan-mcdonald/latex-slides", "max_stars_repo_head_hexsha": "27903fb390d37297293be406c1b1cd85a4c628bb", "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": "big-o/big-o.tex", "max_issues_repo_name": "dylan-mcdonald/latex-slides", "max_issues_repo_head_hexsha": "27903fb390d37297293be406c1b1cd85a4c628bb", "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": "big-o/big-o.tex", "max_forks_repo_name": "dylan-mcdonald/latex-slides", "max_forks_repo_head_hexsha": "27903fb390d37297293be406c1b1cd85a4c628bb", "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.78, "max_line_length": 505, "alphanum_fraction": 0.7187071722, "num_tokens": 2734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257127, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.6762817280437348}}
{"text": "% !TeX root = ../main.tex\r\n\\documentclass[../main.tex]{subfiles}\r\n\\begin{document}\r\n\\section{Model Foundation}\r\n\\subsection{Trigonometry}\r\n\\begin{definition}\\label{M:Trigonometry}\r\n\\textit{Generalized trigonometric functions} \\(f_\\lambda\\colon \\R\\to\\R\\) and \\(f_\\lambda^\\ast:\\R\\to\\R\\) are defined as\r\n\\begin{align*}\r\nf_\\lambda\\left(\\theta\\right)&\\coloneqq\r\n\\begin{cases}\r\ng\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\nh\\left(\\lambda\\theta\\right)&\\text{otherwise,}\\\\\r\n\\end{cases}\\\\\r\nf_\\lambda^\\ast\\left(\\theta\\right)&\\coloneqq\r\n\\begin{cases}\r\ng\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\nh\\left(-\\lambda\\theta\\right)&\\text{otherwise,}\\\\\r\n\\end{cases}\r\n\\end{align*}\r\nwhere \\(g\\) (resp. \\(h\\)) are the associated trigonometric (resp. hyperbolic) function.\r\n\\end{definition}\r\n\\begin{example}[Generalized sine functions]\\label{M:Trigonometry:Sine}\r\n\\begin{align*}\r\n\\sin_\\lambda{\\theta}\r\n&\\coloneqq\r\n\\begin{cases}\r\n\\sin\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n\\sinh\\left(\\lambda\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\\\\\r\n\\sin_\\lambda^\\ast{\\theta}\r\n&\\coloneqq\r\n\\begin{cases}\r\n\\sin\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n\\sinh\\left(-\\lambda\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\\\\\r\n&=\r\n\\begin{cases}\r\n\\sin\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n-\\sinh\\left(\\lambda\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\\\\\r\n&=\\begin{cases}\r\n\\sin\\left(\\abs{\\lambda}\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n\\sinh\\left(\\abs{\\lambda}\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\r\n\\end{align*}\r\n(see\\cref{TrigonometrySinePlotted})\r\n\\end{example}\r\n\\begin{example}[Generalized cosine functions]\\label{M:Trigonometry:Cosine}\r\n\\begin{align*}\r\n\\cos_\\lambda{\\theta}\r\n&\\coloneqq\r\n\\begin{cases}\r\n\\cos\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n\\cosh\\left(\\lambda\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\\\\\r\n\\cos_\\lambda^\\ast{\\theta}\r\n&\\coloneqq\r\n\\begin{cases}\r\n\\cos\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n\\cosh\\left(-\\lambda\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\\\\\r\n&=\\begin{cases}\r\n\\cos\\left(\\lambda\\theta\\right)&\\text{if \\(\\lambda\\geq0\\),}\\\\\r\n\\cosh\\left(\\lambda\\theta\\right)&\\text{otherwise.}\\\\\r\n\\end{cases}\\\\\r\n&=\\cos_\\lambda{\\theta}\r\n\\end{align*}\r\n(see\\cref{TrigonometryCosinePlotted})\r\n\\end{example}\r\n\\begin{theorem}[Pythagorean's identity equivalence]\\label{M:Trigonometry:Pythagorean}\r\n\\begin{align*}\r\n\\cos_\\lambda^2{\\theta}+\\sign{\\lambda}\\sin_\\lambda^2{\\theta}&=1\\\\\r\n\\sec_\\lambda^2{\\theta}-\\sign{\\lambda}\\tan_\\lambda^2{\\theta}&=1\\\\\r\n\\end{align*}\r\n\\end{theorem}\r\n\\begin{proof}[\\proofof{M:Trigonometry:Pythagorean}]\r\nProof by exhaustion.\r\n\\end{proof}\r\n\\begin{proposition}[Generalized trigonometric functions of sum of arguments]\\label{M:Trigonometry:Sum}\r\n\\begin{align*}\r\n\\sin_\\lambda\\left(\\theta+\\phi\\right)\r\n&=\\sin_\\lambda{\\theta}\\cos_\\lambda{\\phi}+\\cos_\\lambda{\\theta}\\sin_\\lambda{\\phi}\\\\\r\n\\sin_\\lambda^\\ast\\left(\\theta+\\phi\\right)\r\n&=\\sin_\\lambda^\\ast{\\theta}\\cos_\\lambda{\\phi}+\\cos_\\lambda{\\theta}\\sin_\\lambda^\\ast{\\phi}\\\\\r\n\\cos_\\lambda\\left(\\theta+\\phi\\right)\r\n&=\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}-\\sign{\\lambda}\\sin_\\lambda{\\theta}\\sin_\\lambda{\\phi}\\\\\r\n&=\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}-\\sin_\\lambda^\\ast{\\theta}\\sin_\\lambda{\\phi}\\\\\r\n&=\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}-\\sin_\\lambda{\\theta}\\sin_\\lambda^\\ast{\\phi}\r\n\\end{align*}\r\n\\end{proposition}\r\n\\begin{proof}[\\proofof{M:Trigonometry:Sum}]\r\nProof by exhaustion.\r\n\\end{proof}\r\n\\begin{proposition}[Derivative of generalized trigonometric functions]\\label{M:Trigonometry:Derivative}\r\n\\begin{align*}\r\n{\\sin_\\lambda}^\\prime{\\theta}&=\\lambda\\cos_\\lambda{\\theta}\\\\\r\n{\\sin_\\lambda^\\ast}^\\prime{\\theta}&=\\abs{\\lambda}\\cos_\\lambda{\\theta}\\\\\r\n{\\cos_\\lambda}^\\prime{\\theta}&=-\\lambda\\sin_\\lambda^\\ast{\\theta}\\\\\r\n{\\tan_\\lambda}^\\prime{\\theta}&=\\lambda\\sec_\\lambda^2{\\theta}\\\\\r\n{\\tan_\\lambda^\\ast}^\\prime{\\theta}&=\\abs{\\lambda}\\sec_\\lambda^2{\\theta}\r\n\\end{align*}\r\n\\end{proposition}\r\n\\begin{proof}[\\proofof{M:Trigonometry:Derivative}]\r\nProof by exhaustion.\r\n\\end{proof}\r\n\\subsection{Matrices}\r\n\\begin{definition}\\label{M:Rotation}\r\n\\textit{Generalized rotation matrix} is defined as\r\n\\begin{align*}\r\nR_\\lambda\\left(\\theta\\right)&\\coloneqq\r\n\\begin{bmatrix}\r\n\\cos_\\lambda{\\theta}&-\\sin_\\lambda^\\ast{\\theta}\\\\\r\n\\sin_\\lambda{\\theta}&\\cos_\\lambda{\\theta}\\\\\r\n\\end{bmatrix}\\text{,}\r\n\\end{align*}\r\nwhere \\(\\theta\\in\\R\\).\r\n\\end{definition}\r\n\\begin{corollary}[Generalized rotation matrix at zero]\\label{M:Rotation:Identity}\r\n\\[\r\nR_\\lambda\\left(0\\right)\r\n=\r\nI_2\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Rotation:Identity}]\r\nObvious\r\n\\end{proof}\r\n\\begin{corollary}[Generalized rotation matrix of sum of arguments]\\label{M:Rotation:Sum}\r\n\\[\r\nR_\\lambda\\left(\\theta\\right)R_\\lambda\\left(\\phi\\right)=R_\\lambda\\left(\\theta+\\phi\\right)\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Rotation:Sum}]\r\n\\begin{align*}\r\nR_\\lambda\\left(\\theta\\right)R_\\lambda\\left(\\phi\\right)\r\n&=\\begin{bmatrix}\r\n\\cos_\\lambda{\\theta}&-\\sin_\\lambda^\\ast{\\theta}\\\\\r\n\\sin_\\lambda{\\theta}&\\cos_\\lambda{\\theta}\\\\\r\n\\end{bmatrix}\r\n\\begin{bmatrix}\r\n\\cos_\\lambda{\\phi}&-\\sin_\\lambda^\\ast{\\phi}\\\\\r\n\\sin_\\lambda{\\phi}&\\cos_\\lambda{\\phi}\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{M:Rotation})}\\\\\r\n&=\\begin{bmatrix}\r\n\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}+\\left(-\\sin_\\lambda^\\ast{\\theta}\\right)\\sin_\\lambda{\\phi}&\r\n\\cos_\\lambda{\\theta}\\left(-\\sin_\\lambda^\\ast{\\phi}\\right)+\\left(-\\sin_\\lambda^\\ast{\\theta}\\right)\\cos_\\lambda{\\phi}\\\\\r\n\\sin_\\lambda{\\theta}\\cos_\\lambda{\\phi}+\\cos_\\lambda{\\theta}\\sin_\\lambda{\\phi}&\r\n\\sin_\\lambda{\\theta}\\left(-\\sin_\\lambda^\\ast{\\phi}\\right)+\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{Matrix:Product})}\\\\\r\n&=\\begin{bmatrix}\r\n\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}-\\sin_\\lambda^\\ast{\\theta}\\sin_\\lambda{\\phi}&\r\n-\\left(\\sin_\\lambda^\\ast{\\theta}\\cos_\\lambda{\\phi}+\\cos_\\lambda{\\theta}\\sin_\\lambda^\\ast{\\phi}\\right)\\\\\r\n\\sin_\\lambda{\\theta}\\cos_\\lambda{\\phi}+\\cos_\\lambda{\\theta}\\sin_\\lambda{\\phi}&\r\n\\cos_\\lambda{\\theta}\\cos_\\lambda{\\phi}-\\sin_\\lambda{\\theta}\\sin_\\lambda^\\ast{\\phi}\\\\\r\n\\end{bmatrix}\r\n&\\text{(simplify)}\\\\\r\n&=\\begin{bmatrix}\r\n\\cos_\\lambda{\\theta+\\phi}&-\\sin_\\lambda^\\ast{\\theta+\\phi}\\\\\r\n\\sin_\\lambda{\\theta+\\phi}&\\cos_\\lambda{\\theta+\\phi}\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{M:Trigonometry:Sum})}\\\\\r\n&=R_\\lambda\\left(\\theta+\\phi\\right)\r\n&\\text{(\\cref{M:Rotation})}\\\\\r\nR_\\lambda\\left(\\theta\\right)\r\nR_\\lambda\\left(\\phi\\right)\r\n&=R_\\lambda\\left(\\theta+\\phi\\right)\r\n&\\qedhere\r\n\\end{align*}\r\n\\end{proof}\r\n\\begin{corollary}[Inverse of generalized rotation matrix]\\label{M:Rotation:Inverse}\r\n\\[\r\nR_\\lambda\\left(\\theta\\right)^{-1}=R_\\lambda\\left(-\\theta\\right)\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Rotation:Inverse}]\r\n\\begin{align*}\r\nR_\\lambda\\left(\\theta\\right)\r\nR_\\lambda\\left(-\\theta\\right)\r\n&=R_\\lambda\\left(0\\right)&\\text{(\\cref{M:Rotation:Sum})}\\\\\r\n&=I_2&\\text{(\\cref{M:Rotation:Identity})}\\\\\r\nR_\\lambda\\left(-\\theta\\right)\r\nR_\\lambda\\left(\\theta\\right)\r\n&=R_\\lambda\\left(0\\right)&\\text{(\\cref{M:Rotation:Sum})}\\\\\r\n&=I_2&\\text{(\\cref{M:Rotation:Identity})}\r\n\\end{align*}\r\n\\[\r\nR_\\lambda\\left(\\theta\\right)R_\\lambda\\left(-\\theta\\right)\r\n=R_\\lambda\\left(-\\theta\\right)R_\\lambda\\left(\\theta\\right)\r\n=I_2\r\n\\]\r\n\\[\r\n{R_\\lambda\\left(\\theta\\right)}^{-1}\r\n=\r\nR_\\lambda\\left(-\\theta\\right)\r\n\\qedhere\r\n\\]\r\n\\end{proof}\r\n\\begin{definition}\\label{M:Position}\r\n\\textit{Position matrix} is defined recursively as\r\n\\begin{align*}\r\nP_{\\lambda,n}\\left(\\left\\{\\tensor{\\theta}{^1},\\dots,\\tensor{\\theta}{^n}\\right\\}\\right)\r\n&\\coloneqq\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\\text{,}\\\\\r\nP_{\\lambda,0}\r\n\\lambda&\\coloneqq I_1\\text{,}\r\n\\end{align*}\r\nwhere \\(\\theta=\\left\\{\\tensor{\\theta}{^i}\\right\\}\\in\\R^n\\) for \\(i\\in\\range{1}{n}\\).\r\n\\end{definition}\r\n\\begin{definition}\\label{M:Position:Set}\r\nLet \\(P\\left(n,\\lambda\\right)\\) be set of position matrices.\r\n\\end{definition}\r\n\\begin{corollary}[Position matrix at zero]\\label{M:Position:Set:Identity}\r\n\\[\r\nP_{\\lambda,n}\r\n\\left(0_{n}\\right)\r\n=\r\nI_{n+1}\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Position:Set:Identity}]\r\nProve by mathematical induction on \\(n\\),\r\nLet\r\n\\begin{equation}\\label{M:Position:Set:Identity:Proof:Induction}\r\nP_{\\lambda,n-1}\\left(0_{n-1}\\right)=I_n\r\n\\end{equation}\r\n\\begin{align*}\r\nP_{\\lambda, n}\\left(0_{n}\\right)\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(0_{n-1}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2, n+1}\r\n\\begin{bmatrix}\r\nR_{\\lambda}\\left(0\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2, n+1}\r\n&\\text{(\\cref{M:Position})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nI_{n}&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2, n+1}\r\n\\begin{bmatrix}\r\nR_{\\lambda}\\left(0\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2, n+1}\r\n&\\text{(\\cref{M:Position:Set:Identity:Proof:Induction})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nI_{n}&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2, n+1}\r\n\\begin{bmatrix}\r\nI_{2}&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2, n+1}\r\n&\\text{(\\cref{M:Rotation:Identity})}\\\\\r\n&=\r\nI_{n+1}\r\nT_{2, n+1}\r\nI_{n+1}\r\nT_{2, n+1}\r\n&\\text{(\\cref{Matrix:Identity:Block})}\\\\\r\n&=\r\nT_{2, n+1}\r\nT_{2, n+1}\r\n&\\text{(\\cref{Matrix:Identity})}\\\\\r\n&=\r\nI_{n+1}\r\n&\\text{(\\cref{Matrix:Permutation:Square})}\r\n\\end{align*}\r\n\\[\r\nP_{\\lambda,n}\r\n\\left(0_{n}\\right)\r\n=\r\nI_{n+1}\r\n\\qedhere\r\n\\]\r\n\\end{proof}\r\n\\begin{definition}\\label{M:Orientation}\r\n\\textit{Orientation matrix} is defined as\r\n\\begin{align*}\r\nQ^{\\pm}_n\\left(\\phi_{n-1},\\phi_{n-2},\\dots,\\phi_1\\right)\r\n&\\coloneqq\r\n\\begin{bmatrix}\r\n1&0_{1\\times n}\\\\\r\n0_{n\\times 1}&X^{\\pm}_{+1,n-1}\\left(\\phi_{n-1},\\phi_{n-2},\\dots,\\phi_1\\right)\\\\\r\n\\end{bmatrix}\\text{,}\\\\\r\nQ^{\\pm}_0\r\n&\\coloneqq\\pm I_1\\text{,}\r\n\\end{align*}\r\nwhere \\(\\phi_m\\in\\R^m\\text{for } m\\in\\range{1}{n-1}\\).\r\n\\end{definition}\r\n\\begin{definition}\\label{M:Orientation:Set}\r\nLet \\(Q\\left(n\\right)\\) be set of orientation matrices.\r\n\\end{definition}\r\n\\begin{corollary}[Orientation matrix at zero]\\label{M:Orientation:Set:Identity}\r\n\\[\r\nQ^{+}_{n}\r\n\\left(0_{n-1}, 0_{n-2},\\dots\\right)\r\n=\r\nI_{n+1}\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Orientation:Set:Identity}]\r\nProve by mathematical induction on \\(n\\),\r\nLet\r\n\\begin{equation}\\label{M:Orientation:Set:Identity:Proof:Induction}\r\nQ^{+}_{n-1}\\left(0_{n-2}, 0_{n-3},\\dots\\right)=I_n\r\n\\end{equation}\r\n\\begin{align*}\r\nQ^{+}_n\\left(0_{n-1}, 0_{n-2},\\dots\\right)\r\n&=\r\n\\begin{bmatrix}\r\n1&0_{1\\times n}\\\\\r\n0_{n\\times 1}&X^{\\pm}_{+1,n-1}\\left(0_{n-1},0_{n-2},\\dots\\right)\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{M:Orientation})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\n1&0_{1\\times n}\\\\\r\n0_{n\\times 1}&P_{+1,n-1}\\left(0_{n-1}\\right)Q^{+}_{n-1}\\left(0_{n-2}, 0_{n-3},\\dots\\right)\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{M:Point})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\n1&0_{1\\times n}\\\\\r\n0_{n\\times 1}&P_{+1,n-1}\\left(0_{n-1}\\right) I_n\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{M:Orientation:Set:Identity:Proof:Induction})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\n1&0_{1\\times n}\\\\\r\n0_{n\\times 1}&P_{+1,n-1}\\left(0_{n-1}\\right)\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{Matrix:Identity})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\n1&0_{1\\times n}\\\\\r\n0_{n\\times 1}&I_{n}\\\\\r\n\\end{bmatrix}\r\n&\\text{(\\cref{M:Position:Set:Identity})}\\\\\r\n&=\r\nI_{n+1}\r\n&\\text{(\\cref{Matrix:Identity:Block})}\r\n\\end{align*}\r\n\\[\r\nQ^{+}_n\r\n\\left(0_{n-1}, 0_{n-2},\\dots\\right)\r\n=\r\nI_{n+1}\r\n\\qedhere\r\n\\]\r\n\\end{proof}\r\n\\begin{definition}\\label{M:Point}\r\n\\textit{Point matrix} is defined as\r\n\\begin{align*}\r\nX^{\\pm}_{\\lambda,n}\\left(\\theta,\\phi_{n-1},\\phi_{n-2},\\dots,\\phi_1\\right)&\\coloneqq\r\nP_{\\lambda,n}\\left(\\theta\\right)\r\nQ^{\\pm}_n\\left(\\phi_{n-1},\\phi_{n-2},\\dots,\\phi_1\\right)\\text{,}\r\n\\end{align*}\r\nwhere \\(\\theta\\in\\R^n\\) and \\(\\phi_m\\in\\R^m\\text{for } m\\in\\range{1}{n-1}\\).\r\n\\end{definition}\r\n\\begin{definition}\\label{M:Point:Set}\r\nLet \\(X\\left(n,\\lambda\\right)\\) be set of point matrices.\r\n\\end{definition}\r\n\\begin{corollary}[Position matrix as subset of point matrix]\\label{M:Point:Position}\r\n\\[\r\nP\\left(\\lambda,n\\right)\\subset X\\left(\\lambda,n\\right)\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Point:Position}]\r\n\\begin{align*}\r\n\\forall{P\\in P\\left(\\lambda,n\\right)}\r\n\\forall{Q\\in Q\\left(n\\right)},\r\n&P Q\\in X\\left(\\lambda,n\\right)\r\n&\\text{(\\cref{M:Point})}\\\\\r\n\\implies\r\n&P I\\in X\\left(\\lambda,n\\right)\r\n&\\text{(\\cref{M:Orientation:Set:Identity})}\\\\\r\n\\implies\r\n&P\\in X\\left(\\lambda,n\\right)\r\n&\\text{(\\cref{Matrix:Identity})}\r\n\\end{align*}\r\n\\[\r\nP\\left(\\lambda,n\\right)\\subset X\\left(\\lambda,n\\right)\\qedhere\r\n\\]\r\n\\end{proof}\r\n\\begin{corollary}[Point matrix at zero]\\label{M:Point:Set:Identity}\r\n\\[\r\nX^{+}_{\\lambda,n}\r\n\\left(0_{n}, 0_{n-1},\\dots\\right)\r\n=\r\nI_{n+1}\r\n\\]\r\n\\end{corollary}\r\n\\begin{proof}[\\proofof{M:Point:Set:Identity}]\r\nIt can be implied from\\cref{M:Position:Set:Identity,M:Orientation:Set:Identity}.\r\n\\end{proof}\r\n\\subsection{Group structure}\r\n\\begin{proposition}\r\nGroup of position matrix with multiplication is a subgroup of an orthogonal group for \\(\\lambda>0\\).\r\n\\[\r\n\\left(P\\left(n,\\lambda\\right),\\cdot\\right)\\cong O\\left(n+1\\right)\r\n\\]\r\n\\end{proposition}\r\n\\begin{proof}\r\n\\begin{align*}\r\nP&=P_{\\lambda,n}\\left(\\left\\{\\tensor{\\theta}{^1},\\dots,\\tensor{\\theta}{^n}\\right\\}\\right)\\\\\r\n&\\coloneqq\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n&&\\text{(\\cref{M:Position})}\\\\\r\nP^T\r\n&=\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}^T\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}^T\r\n&&\\text{(Transpose of product)}\\\\\r\n&=\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n&&\\text{(Transpose of block)}\\\\\r\n&=\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n&&\\text{(Transpose of permutation matrix)}\\\\\r\nPP^T\r\n&=\r\n\\left(\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\\right)\\\\\r\n&\\left(T_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\\right)\r\n&&\\text{(equation above)}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\\\\\r\n&\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n&&\\text{()}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)R_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\\\\\r\n&\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}&&\\text{(\\cref{Matrix:Product:Block})}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\\\\\r\n&\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n&&\\text{()}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}&&\\text{()}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)P_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}&&\\text{(\\cref{Matrix:Product:Block})}\\\\\r\n&=I_{n+1}&&\\text{(mathematical induction)}\r\n\\end{align*}\r\n\\end{proof}\r\n\\begin{proposition}\r\nGroup of position matrix with multiplication is a subgroup of an \\(\\left(1,n\\right)\\)-orthochronus indefinite orthogonal group for \\(\\lambda<0\\).\r\n\\[\r\n\\left(P\\left(n,\\lambda\\right),\\cdot\\right)\\cong O_+\\left(n,1\\right)\r\n\\]\r\n\\end{proposition}\r\n\\begin{proof}\r\n\\begin{align*}\r\nP\r\n&=P_{\\lambda,n}\\left(\\left\\{\\tensor{\\theta}{^1},\\dots,\\tensor{\\theta}{^n}\\right\\}\\right)\\\\\r\n&\\coloneqq\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}&&\\text{(\\cref{M:Position})}\\\\\r\nP^T\r\n&=\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}^T\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}^T&&\\text{(Transpose of product)}\\\\\r\n&=\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}^T\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n&&\\text{(Transpose of block)}\\\\\r\n&=\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)^T&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)^T&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n&&\\text{(Transpose of permutation matrix)}\\\\\r\ng\r\n&=\\diag{-1,1,\\dots,1}\\\\\r\ngPgP^T\r\n&=I_{n+1}&&\\text{(mathematical induction)}\r\n\\end{align*}\r\n\\begin{align*}\r\n\\tensor{P}{^1_1}&> 0\r\n\\end{align*}\r\n\\end{proof}\r\n\\begin{proposition}\r\nGroup of position matrix with multiplication is isomorphic to translation group for \\(\\lambda\\to0\\).\r\n\\[\r\n\\left(P\\left(n,\\lambda\\right),\\cdot\\right)\\cong E\\left(n\\right)\r\n\\]\r\n\\end{proposition}\r\n\\begin{proof}\r\n\\begin{align*}\r\nR_\\lambda\\left(\\theta\\right)\r\n&\\coloneqq\\begin{bmatrix}\r\n\\cos_\\lambda\\left(\\theta\\right)&-\\sin_\\lambda^\\ast\\left(\\theta\\right)\\\\\r\n\\sin_\\lambda\\left(\\theta\\right)&\\cos_\\lambda\\left(\\theta\\right)\\\\\r\n\\end{bmatrix}&&\\text{(\\cref{M:Rotation})}\\\\\r\n&\\to\\begin{bmatrix}\r\n1&0\\\\\r\n\\lambda\\theta&1\\\\\r\n\\end{bmatrix}&&\\text{(Limits of the functions)}\\\\\r\nP_{\\lambda,n}\\left(\\left\\{\\tensor{\\theta}{^1},\\dots,\\tensor{\\theta}{^n}\\right\\}\\right)\r\n&\\coloneqq\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\nR_\\lambda\\left(\\tensor{\\theta}{^n}\\right)&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}&&\\text{(\\cref{M:Position})}\\\\\r\n&\\to\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}\r\n\\begin{bmatrix}\r\n\\begin{matrix*}1&0\\\\\r\n\\lambda\\tensor{\\theta}{^n}&0\\\\\r\n\\end{matrix*}&0_{{2}\\times{n-1}}\\\\\r\n0_{{n-1}\\times{2}}&{I}_{n-1}\\\\\r\n\\end{bmatrix}\r\nT_{2,n+1}&&\\text{(equation above)}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times 1}\\\\\r\n0_{1\\times n}&1\\\\\r\n\\end{bmatrix}\r\n\\begin{bmatrix}\r\n{I}_{n}&0_{n\\times1}\\\\\r\n\\begin{matrix*}\\lambda\\tensor{\\theta}{^n}&0_{1\\times n-1}\\end{matrix*}&1\\\\\r\n\\end{bmatrix}&&\\text{(property of permutation matrix)}\\\\\r\n&=\r\n\\begin{bmatrix}\r\nP_{\\lambda,n-1}\\left(\\left\\{\\tensor{\\theta}{^1_{n}},\\dots,\\tensor{\\theta}{^{n-1}}\\right\\}\\right)&0_{n\\times1}\\\\\r\n\\begin{matrix*}\\lambda\\tensor{\\theta}{^n}&0_{1\\times n-1}\\end{matrix*}&1\\\\\r\n\\end{bmatrix}&&\\text{(\\cref{Matrix:Product:Block})}\\\\\r\nP_{\\lambda,n}\\left(\\tensor{\\theta}{}\\right)\r\n&\\to\r\n\\begin{bmatrix}\r\n1&0_{n\\times1}\\\\\r\n\\lambda\\tensor{\\theta}{}&I_n\\\\\r\n\\end{bmatrix}&&\\text{(mathematical induction)}\\\\\r\nP_{\\lambda,n}\\left(\\tensor{\\theta}{}\\right) P_{\\lambda,n}\\left(\\tensor{\\phi}{}\\right)\r\n&\\to\r\n\\begin{bmatrix}\r\n1&0_{n\\times1}\\\\\r\n\\lambda\\tensor{\\theta}{}&I_n\\\\\r\n\\end{bmatrix}\\begin{bmatrix}\r\n1&0_{n\\times1}\\\\\r\n\\lambda\\tensor{\\phi}{}&I_n\\\\\r\n\\end{bmatrix}&&\\text{(equation above)}\\\\\r\n&=\r\n\\begin{bmatrix}\r\n1&0_{n\\times1}\\\\\r\n\\lambda\\tensor{\\theta}{}+\\lambda\\tensor{\\phi}{}&I_n\\\\\r\n\\end{bmatrix}&&\\text{(\\cref{Matrix:Product:Block})}\r\n\\end{align*}\r\n\\end{proof}\r\n\\begin{proposition}\r\nGroup of orienatation with multiplication is isomorphic to orthogonal group.\r\n\\[\r\n\\left(Q\\left(n\\right),\\cdot\\right)\\cong O\\left(n\\right)\r\n\\]\r\n\\end{proposition}\r\n\\begin{proposition}\r\nGroup of point with multiplication is isomorphic to orthogonal group for \\(\\lambda>0\\).\r\n\\[\r\n\\left(X\\left(n\\right),\\cdot\\right)\\cong O\\left(n\\right)\r\n\\]\r\n\\end{proposition}\r\n\\begin{proposition}\r\nGroup of point with multiplication is isomorphic to \\(\\left(1,n\\right)\\)-orthochronus indefinite orthogonal group for \\(\\lambda<0\\).\r\n\\[\r\n\\left(X\\left(n\\right),\\cdot\\right)\\cong O_+\\left(n,1\\right)\r\n\\]\r\n\\end{proposition}\r\n\\begin{proposition}\r\nGroup of point with multiplication is isomorphic to Euclidean group for \\(\\lambda\\to0\\).\r\n\\[\r\n\\left(X\\left(n\\right),\\cdot\\right)\\cong E\\left(n\\right)\r\n\\]\r\n\\end{proposition}\r\n\\end{document}", "meta": {"hexsha": "d4d8b9ec3207bcd445542c0216889af1c14f07e2", "size": 23290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/foundation.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/foundation.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/foundation.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": 31.7302452316, "max_line_length": 211, "alphanum_fraction": 0.639201374, "num_tokens": 9351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6762817253638715}}
{"text": "\\section{Properties of eigenvectors and eigenvalues}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Know that eigenvectors corresponding to distinct eigenvalues\n    are linearly independent.\n  \\item Compute the algebraic and geometric multiplicity of an\n    eigenvalue.\n  \\item Determine whether a matrix is diagonalizable from the\n    geometric multiplicities of its eigenvalues.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we state some useful properties of eigenvectors\nand eigenvalues. The first question we consider is whether\neigenvectors for different eigenvalues are linearly independent. This\nis indeed the case, as the following proposition shows:\n\n\\begin{proposition}{Eigenvectors for different eigenvalues are linearly independent}{linearly-independent-eigenvectors}\n  Let $A$ be a square matrix, and suppose that $A$ has distinct\n  eigenvalues $\\eigenvar_1,\\ldots,\\eigenvar_k$ with\n  corresponding eigenvectors $\\vect{v}_1,\\ldots,\\vect{v}_k$.\n  Then $\\vect{v}_1,\\ldots,\\vect{v}_k$ are linearly independent.\n\\end{proposition}\n\n\\begin{proof}\n  Suppose, for the sake of obtaining a contradiction, that\n  $\\vect{v}_1,\\ldots,\\vect{v}_k$ are linearly dependent. Let $m$ the\n  the smallest index such that $\\vect{v}_m$ is redundant, i.e., such\n  that $\\vect{v}_m$ is a linear combination of previous vectors.\n  Say\n  \\begin{equation}\\label{eqn:linearly-independent-eigenvectors-1}\n    \\vect{v}_m = a_1\\vect{v}_1 + \\ldots + a_{m-1}\\vect{v}_{m-1}.\n  \\end{equation}\n  Multiplying the equation by $A$, we get\n  \\begin{equation*}\n    A\\vect{v}_m = a_1A\\vect{v}_1 + \\ldots + a_{m-1}A\\vect{v}_{m-1},\n  \\end{equation*}\n  and therefore, since $\\vect{v}_1,\\ldots,\\vect{v}_m$ are\n  eigenvectors,\n  \\begin{equation}\\label{eqn:linearly-independent-eigenvectors-2}\n    \\eigenvar_m\\vect{v}_m = a_1\\eigenvar_1\\vect{v}_1 + \\ldots + a_{m-1}\\eigenvar_{m-1}\\vect{v}_{m-1}.\n  \\end{equation}\n  Subtracting $\\eigenvar_m$ times equation\n  {\\eqref{eqn:linearly-independent-eigenvectors-1}}  from\n  {\\eqref{eqn:linearly-independent-eigenvectors-2}}, we get\n  \\begin{equation*}\n    \\vect{0} = a_1(\\eigenvar_1-\\eigenvar_m)\\vect{v}_1 + \\ldots + a_{m-1}(\\eigenvar_{m-1}-\\eigenvar_{m})\\vect{v}_{m-1}.\n  \\end{equation*}\n  Since $\\vect{v}_1,\\ldots,\\vect{v}_{m-1}$ are, by assumption,\n  linearly independent (because $\\vect{v}_m$ was the leftmost redundant\n  vector), it follows that $a_1(\\eigenvar_1-\\eigenvar_m)=0$, \\ldots,\n  $a_{m-1}(\\eigenvar_{m-1}-\\eigenvar_{m-1})=0$. Since the eigenvalues\n  $\\eigenvar_1,\\ldots,\\eigenvar_m$ are, by assumption, distinct, it\n  follows that $a_1,\\ldots,a_{m-1}=0$. But then\n  {\\eqref{eqn:linearly-independent-eigenvectors-1}} implies that\n  $\\vect{v}_m=\\vect{0}$, contradicting the assumption that $\\vect{v}_m$ is an\n  eigenvector (and therefore non-zero).\n\\end{proof}\n\nAn immediate consequence of this proposition is that an $n\\times n$-matrix\nwith $n$ distinct eigenvalues is diagonalizable.\n\n\\begin{corollary}{Distinct eigenvalues}{distinct-eigenvalues}\n  Let $A$ be an $n\\times n$-matrix and suppose it has $n$ distinct\n  eigenvalues. Then $A$ is diagonalizable.\n\\end{corollary}\n\n\\begin{proof}\n  Each of the $n$ eigenvalues has an eigenvector, and by\n  Proposition~\\ref{prop:linearly-independent-eigenvectors}, they are\n  linearly independent. Then $A$ is diagonalizable by\n  Theorem~\\ref{thm:eigenvectors-and-diagonalizable}.\n\\end{proof}\n\nThe next issue we consider is that of ``repeated'' eigenvalues. There\nare two senses in which an eigenvalue can occur ``more than\nonce''. The first is if the eigenvalue appears as a repeated root of\nthe characteristic polynomial. For example, if the characteristic\npolynomial is\n$p(\\eigenvar) = (1-\\eigenvar)(1-\\eigenvar)(3-\\eigenvar)$, then we say\nthat the root $\\eigenvar=1$ appears with multiplicity%\n\\index{multiplicity!of root of a polynomial} two, and the root\n$\\eigenvar=3$ appears with multiplicity one. We call this the\n\\textbf{algebraic multiplicity}%\n\\index{algebraic multiplicity!of an eigenvalue}%\n\\index{eigenvalue!algebraic multiplicity}%\n\\index{multiplicity!of eigenvalue!algebraic} of the eigenvalue.\n\nThe second sense in which an eigenvalue can occur ``more than once''\nis when an eigenvalue has more than one linearly independent\neigenvector. In other words, when the eigenspace has dimension greater\nthan 1. We call this the \\textbf{geometric multiplicity}%\n\\index{geometric multiplicity!of an eigenvalue}%\n\\index{eigenvalue!geometric multiplicity}%\n\\index{multiplicity!of eigenvalue!geometric} of the eigenvalue.\n\nThe following definition summarizes these concepts.\n\n\\begin{definition}{Algebraic and geometric multiplicity}{multiplicity}\n  Let $\\hat\\eigenvar$ be an eigenvalue of a square matrix $A$. Then\n  the \\textbf{algebraic multiplicity} of $\\hat\\eigenvar$ is the\n  largest power $k$ such that $(\\hat\\eigenvar-\\eigenvar)^k$ is a\n  factor of the characteristic polynomial. The \\textbf{geometric\n    multiplicity} of $\\hat\\eigenvar$ is the dimension of its\n  eigenspace $E_{\\hat\\eigenvar}$.\n\\end{definition}\n\nOne would hope that the algebraic and geometric multiplicities are\nalways equal. Unfortunately, this is not the case, as the following\nexample shows.\n\n\\begin{example}{Algebraic and geometric multiplicity}{multiplicity}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrrrr}\n      3 & 1 & 0 & 0 & 0 \\\\\n      0 & 3 & 0 & 0 & 0 \\\\\n      0 & 0 & 4 & 0 & 0 \\\\\n      0 & 0 & 0 & 4 & 0 \\\\\n      0 & 0 & 0 & 0 & 5 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the algebraic and geometric multiplicity of each eigenvalue\n  of $A$.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  $(3-\\eigenvar)^2(4-\\eigenvar)^2(5-\\eigenvar)$. Therefore, the\n  eigenvalues are $3$, $4$, and $5$, with algebraic multiplicity $2$,\n  $2$, and $1$, respectively. To compute the geometric multiplicity,\n  we need to find each eigenspace. For $\\eigenvar=3$, we must solve\n  $(A-3I)\\vect{v} = \\vect{0}$, or equivalently,\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrr|r}\n      0 & 1 & 0 & 0 & 0 & 0 \\\\\n      0 & 0 & 0 & 0 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 & 0 & 0 \\\\\n      0 & 0 & 0 & 1 & 0 & 0 \\\\\n      0 & 0 & 0 & 0 & 2 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  This system has rank 4, and the only basic solution is\n  $\\mat{1,0,0,0,0}^T$. Thus, the eigenspace $E_3$ is $1$-dimensional,\n  and the geometric multiplicity of $\\eigenvar=3$ is 1. A similar\n  calculation show that $\\eigenvar=4$ has geometric multiplicity $2$\n  and $\\eigenvar=5$ has geometric multiplicity $1$.\n  The information is summarized in the following table:\n  \\begin{center}\n    \\begin{tabular}{|l|c|c|c|}\n      \\hline\n      Eigenvalue & $\\eigenvar=3$ & $\\eigenvar=4$ & $\\eigenvar=5$ \\\\\\hline\n      Algebraic multiplicity & 2 & 2 & 1 \\\\\\hline\n      Geometric multiplicity & 1 & 2 & 1 \\\\\\hline\n    \\end{tabular}\n  \\end{center}\n\\end{solution}\n\nIn the example, the geometric multiplicity is either smaller than or\nequal to the algebraic multiplicity. The following proposition states\nthat this is always the case.\n\n\\begin{proposition}{Algebraic and geometric multiplicity}{dimension-eigenspace}\n  Let $\\hat\\eigenvar$ be an eigenvalue of a matrix $A$, with algebraic\n  multiplicity $k$ and geometric multiplicity $m$. Then\n  \\begin{equation*}\n    1 \\leq m \\leq k.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  It is clear that $m\\geq 1$, because each eigenvalue, by definition,\n  must have at least one associated eigenvector. Therefore, the\n  eigenspace is at least $1$-dimensional. We must show $m\\leq k$. Assume\n  that $A$ is an $n\\times n$-matrix. By assumption, the geometric\n  multiplicity of $\\hat\\eigenvar$ is $m$, so the eigenspace\n  $E_{\\hat\\eigenvar}$ has dimension $m$. So there exist $m$ linearly\n  independent eigenvectors $\\vect{v}_1,\\ldots,\\vect{v}_m$ for the\n  eigenvalue $\\hat\\eigenvar$. Extend $\\vect{v}_1,\\ldots,\\vect{v}_m$ to a\n  basis $\\vect{v}_1,\\ldots,\\vect{v}_n$ of $\\R^n$, and let $P$ be the\n  invertible matrix that has $\\vect{v}_1,\\ldots,\\vect{v}_n$ as its\n  columns. Let $B=P^{-1}AP$. Since the first $m$ columns of $P$ are\n  eigenvectors of $A$ for the eigenvalue $\\hat\\eigenvar$, it follows that\n  $B$ is of the form\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccccc}\n      \\hat\\eigenvar & 0 & \\cdots & 0 & * & \\cdots & * \\\\\n      0 & \\hat\\eigenvar & \\cdots & 0 & * & \\cdots & * \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n      0 & 0 & \\cdots & \\hat\\eigenvar & * & \\cdots & * \\\\\n      0 & 0 & \\cdots & 0 & * & \\cdots & * \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n      0 & 0 & \\cdots & 0 & * & \\cdots & * \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  i.e., the first $m$ columns of $B$ are like those of a diagonal\n  matrix. Then from the cofactor method for computing determinants, we\n  know that $\\det(B-\\eigenvar I)$ contains the factor\n  $(\\hat\\eigenvar-\\eigenvar)^m$. But since $A$ and $B$ are similar\n  matrices, they have the same characteristic polynomial. Therefore,\n  $\\det(A-\\eigenvar I)$ also has $(\\hat\\eigenvar-\\eigenvar)^m$ as a\n  factor. It follows, by definition of algebraic multiplicity, that\n  $m\\leq k$, as desired.\n\\end{proof}\n\nWe know from Theorem~\\ref{thm:eigenvectors-and-diagonalizable} that an\n$n\\times n$-matrix is diagonalizable if and only if it has $n$\nlinearly independent eigenvectors. We can re-state this in terms of\ngeometric multiplicity as follows.\n\n\\begin{proposition}{Geometric multiplicity and diagonalization}{multiplicity-and-diagonalization}\n  An $n\\times n$-matrix $A$ is diagonalizable if and only if the sum\n  of the geometric multiplicities of all the eigenvalues of $A$ is\n  $n$.\n\\end{proposition}\n\n\\begin{proof}\n  By Proposition~\\ref{prop:linearly-independent-eigenvectors},\n  eigenvectors corresponding to different eigenvalues are linearly\n  independent. Therefore, by taking a basis of each eigenspace, we can\n  obtain exactly as many linearly independent eigenvectors as the sum\n  of the dimensions of all the eigenspaces, i.e., the sum of the\n  geometric multiplicities of all eigenvalues. By\n  Theorem~\\ref{thm:eigenvectors-and-diagonalizable}, $A$ is\n  diagonalizable if and only if this number is $n$.\n\\end{proof}\n\n", "meta": {"hexsha": "9c2e9eba5a0f131816472bc933743368fad7563c", "size": 10106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-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/Eigenvalues-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/Eigenvalues-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": 44.1310043668, "max_line_length": 119, "alphanum_fraction": 0.7082921037, "num_tokens": 3299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.6761988598072857}}
{"text": "\\chapter{Preliminaries}\\label{S:Preliminaries}\n\\section{Elementary Set Theory}\\label{S:SetTheory}\nA {\\bf set} is a collection of distinct objects.  We write a set by enclosing its elements with curly braces.  For example, we denote a set of the two objects $\\circ$ and $\\bullet$ by:\n\\[\n\\boxed{\n\\{\\circ, \\bullet\\} \n} \\ .\n\\]\nSometimes, we give names to sets.  For instance, we might call the first example set $A$ and write:\n\\[\n\\boxed{\nA=\\{\\circ, \\bullet\\} }\n\\ .\n\\]\nWe do not care about the order of elements within a set, i.e.~$A=\\{\\circ, \\bullet\\}=\\{\\bullet,\\circ\\}$.  We do not allow a set to contain multiple copies of any of its elements unless the copies are distinguishable, say by labels.  So, $B=\\{\\circ, \\bullet, \\bullet\\}$ is not a set unless the two copies of $\\bullet$ in $B$ are labelled or marked to make them distinct, e.g.~$B=\\{\\circ,\\tilde{\\bullet},\\bullet'\\}$.  Names for sets that arise in a mathematical discourse are given upper-case letters ($A,B,C,D,\\ldots$).  Special symbols are reserved for commonly encountered sets.  \n\nHere is the set $\\BB{\\E{G}}$ of twenty two Greek lower-case alphabets that we may encounter later:\n\n{\\scriptsize\n\\begin{tabular}{llllllllllllllllllllll}\n$\\BB{\\E{G}} = \\{\\ \\alpha$,& $\\beta$,& $\\gamma$,& $\\delta$,& $\\epsilon$,& $\\zeta$,& $\\eta$,& $\\theta$,& $\\kappa$,& $\\lambda$,& $\\mu$,& $\\nu$,& $\\xi$,& $\\pi$,& $\\rho$,& $\\sigma$,& $\\tau$,& $\\upsilon$,& $\\phi$,& $\\chi$,& $\\psi$,& $\\omega \\ \\} $\n%alpha,& beta,& gamma,& delta,& epsilon,& zeta,& eta,& theta,& kappa,& lambda,& mu,& nu,& xi,& pi,& rho,& sigma,& tau,& upsilon,& phi,& chi,& psi,& omega\n\\end{tabular} \\ .\n}\n\nThey are respectively named alpha, beta, gamma, delta, epsilon, zeta, eta, theta, kappa, lambda, mu, nu, xi, pi, rho, sigma, tau, upsilon, phi, chi, psi and omega.  $LHS$ and $RHS$ are abbreviations for objects on the Left and Right Hand Sides, respectively, of some binary relation.  By the notation:\n\\[\n\\boxed{\nLHS := RHS \n} \\ ,\n\\]\nwe mean that $LHS$ {\\bf is equal, by definition, to} $RHS$.  \n\nThe set which does not contain any element (the collection of nothing) is called the {\\bf empty set}:\n\\[\n\\boxed{\n\\emptyset := \\{ \\, \\} \n} \\ .\n\\]\n\nWe say an element $b$ {\\bf belongs to} a set $B$, or simply that $b$ belongs to $B$ or that $b$ is an element of $B$, if $b$ is one of the elements that make up the set $B$, and write:\n\\[\n\\boxed{\nb \\in B\n} \\ .\n\\]\nWhen $b$ {\\bf does not belong to} $B$, we write:\n\\[\n\\boxed{\nb \\notin B\n} \\ .\n\\]\nFor our example set $A = \\{\\circ, \\bullet\\}$, $\\star \\notin A$ but $\\bullet \\in A$.  \n\nWe say that a set $C$ is a {\\bf subset} of another set $D$ and write:\n\\[\n\\boxed{\nC \\subset D\n}\n\\]\nif every element of $C$ is also an element of $D$.  By this definition, any set is a subset of itself.\n\nWe say that two sets $C$ and $D$ are {\\bf equal} (as sets) and write $C=D$ `if and only if' ($\\iff$) every element of $C$ is also an element of $D$, and every element of $D$ is also an element of $C$.  This definition of set equality is notationally summarised as follows:\n\\[\n\\boxed{\nC=D \\quad \\iff \\quad C \\subset D , D \\subset C\n} \\ .\n\\]\nWhen two sets $C$ and $D$ are not equal by the above definition, we say that $C$ is {\\bf not equal} to $D$ and write:\n\\[\n\\boxed{\nC \\neq D\n} \\ .\n\\]\nThe {\\bf union} of two sets $C$ and $D$, written as $C \\cup D$, is the set of elements that belong to $C$ or $D$.  We can formally express our definition of set union as:\n\\[\n\\boxed{\nC \\cup D := \\{x: x \\in C \\quad \\text{or} \\quad x\\in D \\} \n} \\ .\n\\]\nWhen a colon ($:$) appears inside a set, it stands for `such that'.  Thus, the above expression is read as `$C$ union $D$ is equal by definition to the set of all elements $x$, such that $x$ belongs to $C$ or $x$ belongs to $D$.'\n\nSimilarly, the {\\bf intersection} of two sets $C$ and $D$, written as $C \\cap D$, is the set of elements that belong to both $C$ and $D$.  Formally:\n\\[\n\\boxed{\nC \\cap D := \\{x: x \\in C \\quad \\text{and} \\quad x\\in D \\}\n} \\ .\n\\]\n\n{\\bf Venn diagrams} are visual aids for set operations as in the diagrams below.\n\n\\begin{figure}[htbp]\n\\centering\n%TODO\\includegraphics[width=5.5in]{figures/VennDiagsAUbANB.png}\n\\caption{Union and intersection of sets shown by Venn diagrams}\n\\end{figure}\n\n\n\nThe set-difference or {\\bf difference} of two sets $C$ and $D$, written as $C \\setminus D$, is the set of elements in $C$ that do not belong to $D$.  Formally:\n\\[\n\\boxed{\nC \\setminus D := \\{x: x \\in C \\quad \\text{and} \\quad x\\notin D \\}\n} \\ .\n\\] \nWhen a universal set, e.g. $U$ is well-defined, the {\\bf complement} of a given set $B$ denoted by $B^c$ is the set of all elements of $U$ that don't belong to $B$, i.e.:\n\\[\n\\boxed{\nB^c := U \\setminus B\n} \\ .\n\\]\nWe say two sets $C$ and $D$ are {\\bf disjoint} if they have no elements in common, i.e.~$C \\cap D = \\emptyset$.\n\nBy drawing  Venn diagrams,  let us check {\\bf De~Morgan's Laws}:\n\n\\[\n\\boxed{\n\\left(A\\cup B\\right)^c = A^c \\cap B^c \\text{  and  } \\left( A \\cap B \\right)^c = A^c \\cup B^c\n}\n\\]\n\n\\begin{figure}[htbp]\n\\centering\n\\mbox{\n\\subfigure[$\\left(A\\cup B\\right)^c = A^c \\cap B^c$]{\\includegraphics[width=3.0in]{figures/A_union_B_comp}}\n\\quad\n\\subfigure[$\\left( A \\cap B \\right)^c = A^c \\cup B^c$]{\\includegraphics[width=3.0in]{figures/A_inter_B_comp} }\n}\n\\caption{These  Venn diagram illustrate De~Morgan's Laws.} \\label{F:DeMorganslaws}\n\\end{figure}\n\n\n%\\begin{figure}[htpb]\n%\\caption{Universal set $\\Omega$, a set $A$ such that $A \\subset \\Omega$ (read: $A$ is a subset of $\\Omega$ or $A$ is contained in $\\Omega$), another set $B$ with $B \\subset \\Omega$,  the set $A \\setminus B$ (read: $A$ (set)minus $B$ or $A$ that is not in $B$), the set $A \\cap B$ (read: $A$ intersection $B$), the set $A \\cup B$ (read: $A$ union $B$) and the set $A^c$ (read: complement of $A$) which is defined as $\\Omega \\setminus A$.}\n%\\vspace{6cm}\n%\\end{figure}\n\n\\begin{classwork}[Fruits and colours]\nConsider a set of fruits $F=\\{\\text{orange}, \\text{banana}, \\text{apple}\\}$ and a set of colours $C = \\{\\text{red}, \\text{green}, \\text{blue}, \\text{orange}\\}$.  Then,\n\\begin{enumerate}\n\\item $F \\cap C = $\n\\item $F \\cup C = $\n\\item $F \\setminus C = $\n\\item $C \\setminus F = $\n\\end{enumerate}\n\\end{classwork}\n\n\n\n\n\\begin{classwork}[Subsets of a universal set]\nSuppose we are given a universal set $U$, and three of its subsets, $A$, $B$ and $C$.  Also suppose that $A \\subset B \\subset C$.  Find the circumstances, if any, under which each of the following statements is true (T) and justify your answer:\n\n\\begin{tabular*}{5.5in}{@{\\extracolsep{\\fill}}l l l l}\n(1) $C \\subset B$ & T when $B=C$\n&(2) $A \\subset C$ & T by assumption\\\\\n(3) $C \\subset \\emptyset$ & T when $A=B=C=\\emptyset$\n&(4) $\\emptyset \\subset A$& T always \\\\\n(5) $C \\subset U$ & T by assumption\n&(6) $U \\subset A$ & T when $A=B=C=U$\\\\\n\\end{tabular*}\n\\end{classwork}\n\n\\section{Exercises}\\label{xSets}\n\n\\begin{ExerciseList}\n\n\\Exercise\nLet $\\Omega$ be the universal set of students, lecturers and tutors involved in a course.\n\nNow consider the following subsets:\n\\begin{itemize}\n\\item The set of 50 students, $S\\,=\\, \\{S_1,\\, S_2,\\, S_2,\\,\\dots \\, S_{50}\\}$.\n\n\\item The set of 3 lecturers, $L\\,=\\, \\{L_1,\\,L_2,\\, L_3\\}$.\n\n\\item The set of 4 tutors, $T\\,=\\, \\{T_1,\\,T_2,\\, T_3,\\, L_3\\}$.\n\\end{itemize}\nNote that one of the lecturers also tutors in the course. Find the following sets:\n\n\\bcols{2}\\be\n\n\\item[(a)] $T \\cap L$\n\n\\item[(b)] $T \\cap S$\n\n\\item[(c)] $T \\cup L$\n\n\\item[(d)] $T \\cup L \\cup S$\n\n\\item[(e)] $S^c$\n\n\\item[(f)] $S \\cap L$\n\n\\item[(g)] $S^c\\cap L$\n\n\\item[(h)] $T^c$\n\n\\item[(i)] $T^c\\cap L$\n\n\n\\item[(j)] $T^c\\cap T$\n\n\\ee\\ecols\n\n\\Answer\nBy operating with $\\Omega$, $T$, $L$ and $S$ we can obtain the answers as follows:\n\n{\\bcols{2}\\be\n\n\\item[(a)] $T \\cap L\\,=\\, \\{L_3\\}$\n\n\\item[(b)] $T \\cap S\\,=\\, \\emptyset$\n\n\\item[(c)] $T \\cup L\\,=\\, \\{ T_1,\\,T_2,\\, T_3,\\, L_3,\\, L_1,\\, L_2\\}$\n\n\\item[(d)] $T \\cup L \\cup S\\,=\\, \\Omega$\n\n\\item[(e)] $S^c \\,=\\,\\{ T_1,\\,T_2,\\, T_3,\\, L_3,\\, L_1,\\, L_2\\} $\n\n\\item[(f)] $S \\cap L\\,=\\, \\emptyset$\n\n\\item[(g)] $S^c\\cap L\\,=\\,\\{L_1,\\, L_2,\\,L_3\\}\\,=\\, L $\n\n\\item[(h)] $T^c\\,=\\,\\{L_1,\\, L_2,\\,S_1,\\, S_2,\\, S_2,\\,\\dots \\, S_{50}\\}  $\n\n\\item[(i)] $T^c \\cap L\\,=\\,\\{L_1,\\, L_2\\} $\n\n\n\\item[(j)] $T^c\\cap T\\,=\\, \\emptyset$\n\n\\ee\\ecols\n}\n\n%\\begin{Exercise}[title={Venn Diagrams 1}] \n\\Exercise\nUsing Venn diagram, sketch and check the rule:\n\n$A\\cup(B\\cap C)\\,=\\,(A\\cup B)\\cap (A\\cup C)$\n\n\\Exercise\nUsing Venn diagram, sketch and check the rule:\n\n$A\\cap(B\\cup C)\\,=\\,(A\\cap B)\\cup(A\\cap C)$\n\n%\\end{Exercise}\n\\Answer\nWe can check $A\\cup(B\\cap C)\\,=\\,(A\\cup B)\\cap (A\\cup C)$ from the following sketch:\n\n\\begin{center}\n%\\subfloat[$A\\cup(B\\cap C)$]\n{\\includegraphics[width=5cm]{figures/ABC1}}\n\\end{center}\n\n\\Answer\nWe can check $A\\cap(B\\cup C)\\,=\\,(A\\cap B)\\cup(A\\cap C)$ from the following sketch:\n\n%\\subfloat[$A\\cap(B\\cup C)$]\nWe can check $A\\cup(B\\cap C)\\,=\\,(A\\cup B)\\cap (A\\cup C)$ from the following sketch:\n\\begin{center}\n{\\includegraphics[width=5cm]{figures/ABC2}}\n\\end{center}\n\n%question 2\n\n%\\begin{Exercise}[title={Venn Diagrams 2}]\n\\Exercise\nUsing a Venn diagram, illustrate the idea that  $A\\subseteq B$ if and only if $A\\cup B=B$.\n%\\end{Exercise}\n\\Answer\nTo illustrate the idea that $A\\subseteq B$ if and only if $A\\cup B=B$, we need to illustrate two implications:\n\\begin{enumerate}\n\\item if $A\\subseteq B$ then  $A\\cup B=B$ and\n\\item if  $A\\cup B=B$ then $A\\subseteq B$.\n\\end{enumerate}\nThe folowing Venn diagram illustrates the two implications clearly.\n\\begin{center}\n\\includegraphics[width=6cm]{figures/AB}\n\\end{center}\n\n\\end{ExerciseList}\n\n\\begin{framed}\n\\begin{tabular}{rcl}\nSET SUMMARY\\\\ \\\\\n$\\{a_1,a_2,\\dots,a_n\\}$& $-$& a set containing the elements, $a_1,a_2,\\dots,a_n$.\\\\\n$a\\in A$ &$-$& $a$ is an element of the set $A$.\\\\\n$A\\subseteq B$ &$-$& the set $A$ is a subset of $B$.\\\\\n$A\\cup B$ &$-$& ``union'', meaning the set of all elements which are in $A$ or $B$, \\\\\n& & \\ \\ or both.\\\\\n$A\\cap B$ &$-$& ``intersection'', meaning the set of all elements in both $A$ and $B$.\\\\\n$\\{\\}$ or $\\emptyset$ &$-$& empty set.\\\\\n$\\Omega $ &$-$& universal set.  \\\\\n$A^c $ &$-$& the complement of $A$, meaning the set of all elements in $\\Omega$,\\\\\n& & \\ \\ the universal set, which are not in $A$.\\\\\n\\end{tabular}\n\\end{framed}\n\n%\\remove{\n\\section{Natural Numbers, Integers and Rational Numbers}\\label{S:NatIntRatNumbers}\n\nWe denote the number of elements in a set named $B$ by:\n\\[\n\\boxed{\n\\# B := \\text{Number of elements in the set $B$} \n} \\ .\n\\]\nIn fact, the Hindu-Arab numerals we have inherited are based on this intuition of the size of a collection.  The elements of the set of {\\bf natural numbers}:\n\\[\n\\boxed{\n\\Nz := \\{1,2,3,4,\\ldots \\}\n} \\ , \\text{may be defined using $\\#$ as follows:}\n\\] \n\\begin{flalign*}\n1 &:= \\#\\{\\star \\} = \\# \\{\\bullet\\}= \\#\\{\\alpha\\}=\\#\\{\\{\\bullet\\}\\} = \\#\\{\\{\\bullet,\\bullet'\\}\\}= \\ldots,\\\\\n2 &:= \\#\\{\\star',\\star \\} = \\# \\{\\bullet, \\circ\\}= \\#\\{\\alpha,\\omega\\} = \\#\\{\\{\\circ\\},\\{\\alpha,\\star,\\bullet\\}\\}=\\ldots,\\\\\n\\vdots & \n\\end{flalign*}\nFor our example sets, $A=\\{\\circ,\\bullet\\}$ and the set of Greek alphabets $\\BB{\\E{G}}$, $\\# A = 2$ and $\\# \\BB{\\E{G}} = 22$.  The number zero may be defined as the size of an empty set:\n\\[\n0 := \\# \\emptyset = \\#\\{\\}\n\\]\nThe set of {\\bf non-negative integers} is:\n\\[\n\\boxed{\n\\Zz_+ := \\Nz \\cup \\{0\\} = \\{0,1,2,3,\\ldots\\}\n} \\ .\n\\]\n\nA {\\bf product set} is the {\\bf Cartesian product} ($\\times$) of two or more possibly distinct sets:\n\\[\n\\boxed{\nA \\times B := \\{(a,b): a \\in A \\text{ and } b \\in B \\}\n}\n\\]\nFor example, if $A=\\{\\circ,\\bullet\\}$ and $B=\\{\\star\\}$, then $A\\times B = \\{(\\circ,\\star), (\\bullet,\\star)\\}$.  Elements of $A \\times B$ are called {\\bf ordered pairs}.  \n\nThe binary arithmetic operation of {\\bf addition} ($+$) between a pair of non-negative integers $c,d \\in \\Zz_+$ can be defined via sizes of disjoint sets.  Suppose, $c=\\#C$, $d=\\#D$ and $C \\cap D = \\emptyset$, then:\n\\[\nc+d = \\#C + \\#D := \\# (C \\cup D) \\ .\n\\]\nFor example,  if $A=\\{\\circ,\\bullet\\}$ and $B=\\{\\star\\}$, then $A \\cap B=\\emptyset$ and $\\#A + \\#B = \\#(A \\cup B) \\iff 2+1=3$.\n\nThe binary arithmetic operation of {\\bf multiplication} ($\\cdot$) between a pair of non-negative integers $c,d \\in \\Zz_+$ can be defined via sizes of product sets.  Suppose, $c=\\#C$, $d=\\#D$, then:\n\\[\nc \\cdot d = \\#C \\cdot \\#D := \\# (C \\times D) \\ .\n\\]\nFor example,  if $A=\\{\\circ,\\bullet\\}$ and $B=\\{\\star\\}$, then $\\#A \\cdot \\#B = \\#(A \\times B) \\iff 2 \\cdot 1=2$.\n\nMore generally, a product set of $A_1,A_2,\\ldots,A_m$ is:\n\\[\n\\boxed{\nA_1 \\times A_2 \\times \\cdots \\times A_m := \\{(a_1,a_2,\\ldots,a_{m}): a_1 \\in A_1, a_2 \\in A_2, \\ldots, a_{m} \\in A_m \\}\n}\n\\]\nElements of an $m$-product set are called {\\bf ordered $m$-tuples}.  When we take the product of the same set we abbreviate as follows:\n\\[\n\\boxed{\nA^m := \\underset{m \\text{ times}}{\\underbrace{A \\times A \\times \\cdots \\times A}} := \\{(a_1,a_2,\\ldots,a_m): a_1 \\in A, a_2 \\in A, \\ldots, a_{m} \\in A \\}\n}\n\\]\n\\begin{classwork}[Cartesian product of sets]\n1.~Let $A=\\{\\circ, \\bullet \\}$.  What are the elements of $A^2$?  2.~Suppose $\\# A = 2$ and $\\# B = 3$.  What is $\\# (A \\times B)$?  3.~Suppose $\\# A_1 = s_1, \\# A_2 = s_2, \\ldots, \\# A_m = s_m$.  What is $\\# (A_1 \\times A_2 \\times \\cdots \\times A_m)$?\n\\vspace{4cm}\n\\end{classwork}\n\nNow, let's recall the definition of a function.  A {\\bf function} is a ``mapping\" that associates each element in some set $\\Xz$ (the domain) to exactly one element in some set $\\Yz$ (the range). Two different elements in $\\Xz$ can be mapped to or associated with the same element in $\\Yz$, and not every element in $\\Yz$ needs to be mapped.  Suppose $x \\in \\Xz$. Then we say ${f(x)=y \\in \\Yz}$ is the {\\bf image} of $x$.  To emphasise that $f$ is a {\\bf function} from $\\Xz \\ni x$ to $\\Yz \\ni y$, we write:\n$$\\boxed{f(x)=y:\\Xz \\to \\Yz} \\ .$$\nAnd for some $y \\in \\Yz$, we call the set:\n$$\\boxed{f^{[-1]}(y) := \\{x \\in \\Xz : f(x)=y \\} \\subset \\Xz} \\ ,$$\nthe {\\bf pre-image} or {\\bf inverse image} of $y$, and \n$$\\boxed{f^{[-1]} := f^{[-1]}(y \\in \\Yz) = X \\subset \\Xz} \\ ,$$\nas the {\\bf inverse} of $f$.\n\n\\begin{figure}[htpb]\n\\caption{A function $f$ (``father of'') from $\\Xz$ (a set of children) to $\\Yz$ (their fathers) and its inverse (``children of'').\\label{F:function}}\n\\vspace{4cm}\n\\end{figure}\n\nWe motivated the non-negative integers $\\Zz_+$ via the size of a set.  With the notion of two directions ($+$ and $-$) and the magnitude of the current position from the origin zero ($0$) of a dynamic entity, we can motivate the set of {\\bf integers}:\n$$\\boxed{\\Zz := \\{\\ldots,-3,-2,-1,0,+1,+2,+3,\\ldots\\}} \\ .$$\nThe integers with a {\\bf minus} or {\\bf negative sign} ($-$) before them are called negative integers and those with a {\\bf plus} or {\\bf positive sign} ($+$) before them are called positive integers.  Conventionally, $+$ signs are dropped.  Some examples of functions you may have encountered are {\\bf arithmetic operations} such as {\\bf addition} ($+$), {\\bf subtraction} ($-$), {\\bf multiplication} ($\\cdot$) and {\\bf division} ($/$) of ordered pairs of integers.  The reader is assumed to be familiar with such arithmetic operations with pairs of integers.  Every integer is either positive, negative, or zero.  In terms of this we define the notion of {\\bf order}.  We say an integer $a$ is {\\bf less than} an integer $b$ and write $a < b$ if $b-a$ is positive.  We say an integer $a$ is {\\bf less than or equal to} an integer $b$ and write $a \\leq b$ if $b-a$ is positive or zero.  Finally, we say that $a$ is greater than $b$ and write $a > b$ if $b<a$.  Similarly, $a$ is greater than equal to $b$, i.e.~$a \\geq b$, if $b \\leq a$.  The set of integers are {\\bf well-ordered}, i.e., for every integer $a$ there is a next largest integer $a+1$.\n\n\\begin{classwork}[Addition over integers]\\label{CW:AdditionMapAndItsInverseMap}\nConsider the set of integers $\\Zz = \\{\\ldots,-3,-2,-1,0,1,2,3,\\ldots\\}$.  Try to set up the arithmetic operation of addition as a function.  The domain for addition is the Cartesian product of $\\Zz$:\n\\[\n \\Zz^2 := \\Zz \\times \\Zz := \\{(a,b) : a \\in \\Zz, b \\in \\Zz \\}\n\\]  \nWhat is its range ?  \n\\[\n+ : \\Zz \\times \\Zz \\to\n\\]\n\\begin{figure}[htpb]\n\\caption{A pictorial depiction of addition and its inverse.  The domain is plotted in orthogonal  {\\bf Cartesian coordinates}.\\label{F:Addfunction}}\n\\vspace{5cm}\n\\end{figure}\n\\end{classwork}\n\nIf the magnitude of the entity's position is measured in units (e.g.~meters) that can be rationally divided into $q$ pieces with $q \\in \\Nz$, then we have the set of rational numbers:\n\\[\n\\Qz := \\{ {p}/{q} : p \\in \\Zz, q \\in \\Zz \\setminus \\{0\\} \\}\n\\] \nThe expressions $p/q$ and $p'/q'$ denote the same rational number if and only if $p \\cdot q'=p' \\cdot q$.  Every rational number has a unique irreducible expression $p/q$, where $q$ is positive and as small as possible.  For example, $1/2$, $2/4$, $3/6$, and $1001/2002$ are different expressions for the same rational number whose irreducible unique expression is $1/2$.\n\nAddition and multiplication are defined for rational numbers by:\n\\[\n\\frac{p}{q} + \\frac{p'}{q'} = \\frac{p \\cdot q' + p' \\cdot q}{q \\cdot q'}\n\\qquad \\text{and} \\qquad \\frac{p}{q} \\cdot \\frac{p'}{q'} = \\frac{p \\cdot p'}{q \\cdot q'} \\ .\n\\]\nThe rational numbers form a {\\bf field} under the operations of addition and multiplication defined above in terms of addition and multiplication over integers.  This means that the following properties are satisfied:\n\\begin{enumerate}\n\\item Addition and multiplication are each {\\bf commutative} \n\\[ a+b = b+a, \\qquad a \\cdot b = b \\cdot a \\ , \\]\nand associative\n\\[\na + (b + c) = (a + b) + c, \\qquad a \\cdot (b \\cdot c) = (a \\cdot b) \\cdot c \\ .\n\\]\n\\item Multiplication {\\bf distributes} over addition\n\\[\na \\cdot (b+c) = (a \\cdot b) + (a \\cdot c) \\ .\n\\]\n\\item $0$ is the {\\bf additive identity} and $1$ is the multiplicative identity\n\\[\n0+a=a \\qquad \\text{and} \\qquad 1 \\cdot a = a \\ .\n\\]\n\\item Every rational number $a$ has a negative, $a+(-a)=0$ and every non-zero rational number $a$ has a reciprocal, $a \\cdot 1/a = 1$.\n\\end{enumerate} \nThe field axioms imply the usual laws of arithmetic and allow subtraction and division to be defined in terms of addition and multiplication as follows:\n\\[\n\\frac{p}{q} - \\frac{p'}{q'} := \\frac{p}{q} + \\frac{-p'}{q'}\n\\qquad \\text{and} \\qquad  \\frac{p}{q} / \\frac{p'}{q'} := \\frac{p}{q} \\cdot \\frac{q'}{p'}, \\quad \\text{provided $p' \\neq 0$} \\ .\n\\]\nWe will see later that the theory of finite fields is necessary for the study of pseudo-random number generators (PRNGs) and PRNGs are the heart-beat of randomness and statistics with computers.  \n\n%\\afterpage{clearpage}\n\n%You should at least have a  ``working knowledge'' of the following topics as they constitute the foundational kernels of statistical reasoning:\n%\\begin{itemize}\n%\\item Finite and infinite sequences of rational numbers \n%\\item Limits, Cauchy sequences of rational numbers and the real number system\n%\\item Continuous functions, derivatives and differentiable functions\n%\\end{itemize}\n\\section{Real Numbers}\\label{S:Reals}\nUnlike rational numbers which are expressible in their reduced forms by $p/q$, it is fairly tricky to define or express real numbers.  It is possible to define real numbers formally and constructively via equivalence classes of Cauchy sequence of rational numbers.  For this all we need are notions of (1) infinity, (2) sequence of rational numbers and (3) distance between any two rational numbers in an infinite sequence of them.  These are topics usually covered in an introductory course in real analysis and are necessary for a firm  foundation in computational statistics.  Instead of a formal constructive definition of real numbers, we give a more concrete one via decimal expansions.  See Donald E.~Knuth's treatment [{\\em Art of Computer Programming, Vol.~I, Fundamental Algorithms}, 3rd Ed., 1997, pp.~21-25] for a fuller story.  A {\\bf real number} is a numerical quantity $x$ that has a decimal expansion:\n\\[\nx = n+ 0.d_1d_2d_3 \\ldots \\ , \\text{ where, each } d_i \\in \\{0,1,\\ldots,9\\}, n \\in \\Zz \\ ,\n\\]\nand the sequence $ 0.d_1d_2d_3 \\ldots$ does not terminate with infinitely many consecutive $9$s.  By the above decimal representation, the following arbitrarily accurate enclosure of the real number $x$ by rational numbers is implied:\n\\[\nn+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k} =: \\underline{x}_k \\leq x < \\overline{x}_k := \nn+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k}+\\frac{1}{10^k}\n\\]\nfor every $k \\in \\Nz$.  Thus, rational arithmetic ($+,-,\\cdot,/$) can be extended with arbitrary precision to any ordered pair of real numbers $x$ and $y$ by operations on their rational enclosures $\\underline{x}, \\overline{x}$ and $\\underline{y}, \\overline{y}$. \n\nSome examples of real numbers that are not rational ({\\bf irrational numbers}) are: \n\\begin{flalign*}\n\\sqrt{2}=1.41421356237309\\ldots & \\text{the side length of a square with area of $2$ units}\\\\\n\\pi=3.14159265358979\\ldots  & \\text{the ratio of the circumference to diameter of a circle} \\\\\ne=2.71828182845904\\ldots & \\text{Euler's constant}\n\\end{flalign*}\nWe can think of $\\pi$ as being enclosed by the following pairs of rational numbers:\n\\begin{flalign*}\n3 +\\frac{1}{10} =: \\underline{\\pi}_{1} \\leq &\\pi < \\overline{\\pi}_{1} := 3 + \\frac{1}{10} + \\frac{1}{10^{1}} \\\\\n3 +\\frac{1}{10} + \\frac{4}{100} =: \\underline{\\pi}_{2} \\leq &\\pi < \\overline{\\pi}_{2} := 3 + \\frac{1}{10} + \\frac{4}{100}+\\frac{1}{100} \\\\\n3 +\\frac{1}{10} + \\frac{4}{100} + \\frac{1}{10^3} =: \\underline{\\pi}_{3} \\leq &\\pi < \\overline{\\pi}_{3} := 3 + \\frac{1}{10} + \\frac{4}{100}+ \\frac{1}{10^3}+\\frac{1}{10^3} \\\\\n&\\vdots \\\\\n3.14159265358979 =: \\underline{\\pi}_{14} \\leq &\\pi < \\overline{\\pi}_{14} := 3.14159265358979 + \\frac{1}{10^{14}} \\\\\n& \\vdots\n\\end{flalign*}\n\nThink of the real number system as the continuum of points that make up a line, as shown in ~\\hyperref[F:linesegment]{Figure~\\ref*{F:linesegment}}.\n\\begin{figure}[htpb]\n\\caption{A depiction of the real line segment $[-10,10]$.\\label{F:linesegment}}\n\\vspace{3cm}\n\\end{figure}\n\nLet $y$ and $z$ be two real numbers such that $y \\leq z$.  Then, the {\\bf closed interval} $[y,z]$ is the set of real numbers $x$ such that $y \\leq x \\leq z$:\n\\[\n[y,z] := \\{ x: y \\leq x \\leq z \\} \\ .\n\\]\nThe {\\bf half-open interval} $(y,z]$ or $[y,z)$ and the {\\bf open interval} $(y,z)$  are defined analogously:\n\\begin{flalign*}\n(y,z] &:= \\{ x: y < x \\leq z \\} \\ , \\\\\n[y,z) &:= \\{ x: y \\leq x < z \\} \\ , \\\\\n(y,z) &:=  \\{ x: y < x < z \\} \\ . \n\\end{flalign*}\nWe also allow $y$ to be {\\bf minus infinity} (denoted $-\\infty$) or $z$ to be {\\bf infinity} (denoted $\\infty$) at an open endpoint of an interval, meaning that there is no lower or upper bound.  With this allowance we get the set of {\\bf real numbers} $\\Rz := (-\\infty,\\infty)$, the {\\bf non-negative real numbers} $\\Rz_+:=[0,\\infty)$ and the {\\bf positive real numbers} $\\Rz_{>0}(0,\\infty)$ as follows:\n\\begin{flalign*}\n\\Rz &:= (-\\infty,\\infty) =  \\{ x: -\\infty < x < \\infty \\} \\ , \\\\\n\\Rz_+ &:= [0,\\infty) =  \\{ x: 0 \\leq x < \\infty \\} \\ , \\\\ \n\\Rz_{>0} &:= [0,\\infty) =  \\{ x: 0 < x < \\infty \\} \\ . \\\\ \n\\end{flalign*}\nFor a positive real number $b \\in \\Rz_{>0}$ and an integer $n \\in \\Zz$, the $n$-th {\\bf power} or {\\bf exponent} of $b$ is:\n\\[\nb^0=1, \\qquad b^n = b^{n-1} \\cdot b \\quad \\text{if $n>0$}, \\qquad b^n=b^{n+1}/b  \\quad \\text{if $n<0$} \\ .\n\\]\nThe following {\\bf laws of exponents} hold by mathematical induction when $m,n \\in \\Zz$:\n\\[\nb^{m+n} = b^m \\cdot b^n, \\qquad \\left( b^m \\right)^n = b^{m \\cdot n} \\ .\n\\]\nIf $y \\in \\Rz$ and $m \\in \\Nz$, the unique positive real number $z \\in \\Rz_{>0}$ such that $z^m=y$ is called the {\\bf $m$-th root of $y$} and denoted by $\\sqrt[m]{y}$, i.e.,\n\\[\nz^m=y \\implies z=\\sqrt[m]{y} \\ .\n\\]\nFor a rational number $r=p/q \\in \\Qz$, we define the $r$-th power of $b \\in \\Rz$ as follows:\n\\[\nb^r = b^{p/q} := \\sqrt[q]{b^p}\n\\]\nThe laws of exponents hold for this definition and different expressions for the same rational number $r=ap/aq$ yield the same power, i.e.,~$ b^{p/q}= b^{ap/aq}$.  Recall that a real number $x=n+ 0.d_1d_2d_3\\ldots \\in \\Rz$ can be arbitrarily precisely enclosed by the rational numbers $\\underline{x}_k:=n+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k}$ and $\\overline{x}_k:=n+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k}+\\frac{1}{10^k}$ by increasing $k$.  Suppose first that $b>1$.  Then, using rational powers, we can enclose $b^x$,\n\\[\nb^{n+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k}} =: b^{\\underline{x}_k} \\leq b^{x} < b^{\\overline{x}_k} := b^{n+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k}+\\frac{1}{10^k}} \\ ,\n\\] \nwithin an interval of width $b^{n+\\frac{d_1}{10}+\\frac{d_2}{100}+\\cdots+\\frac{d_k}{10^k}} \\left(b^{\\frac{1}{10^k}}-1 \\right) < b^{n+1}(b-1)/10^k$.  By taking a large enough $k$ we can evaluate $b^x$ to any accuracy.  Finally, when $b<1$ we define $b^x : = (1/b)^x$ and when $b=0$, $b^x := 1$.\n\nSuppose $y \\in \\Rz_{>0}$ and $b \\in \\Rz \\setminus \\{1\\}$ then the real number $x$ such that $y=b^x$ is called the {\\bf logarithm of $y$ to the base $b$} and we write this as:\n\\[\ny=b^x \\iff x = \\log_b{y}\n\\] \nThe definition implies:\n\\[\nx = \\log_b (b^x) = b^{\\log_b x} \\ ,\n\\]\nand the laws of exponents imply:\n\\begin{flalign*}\n\\log_b(xy) &= \\log_b{x} + \\log_b{y}, \\quad \\text{if} \\quad x >0, \\ y >0 \\ \\text{ and} \\\\\n\\log_b \\left( c^y \\right) &= y \\log_b c, \\quad \\text{if} \\quad c > 0 \\ .\n\\end{flalign*}\nThe {\\bf common logarithm} is $\\log_{10}(y)$, the {\\bf binary logarithm} is $\\log_2(y)$ and the {\\bf natural logarithm} is $\\log_e(y)$, where $e$ is the Euler's constant.  Since we will mostly work with $\\log_e(y)$ we use $\\log(y)$ to mean $\\log_e(y)$.  You are assumed to be familiar with trigonometric functions ($\\sin(x)$, $\\cos(x)$, $\\tan(x)$, $\\ldots$).  We sometimes denote the special power function $e^y$ by $\\exp(y)$.\n\nFamiliar extremal elements of a set of real numbers, say $A$, are the following:\n\\[\n\\boxed{\n\\max{A} := \\text{greatest element in $A$}\n}\n\\]\nFor example, $\\max \\{1,4,-9,345\\} = 345$, $\\max [-93.8889,1002.786] = 1002.786$.\n\\[\n\\boxed{\n\\min{A} := \\text{least element in $A$}\n}\n\\]\nFor example, $\\min \\{1,4,-9,345\\} = -9$, $\\min [-93.8889,1002.786] = -93.8889$.  We need a slightly more sophisticated notion for the extremal elements of a set $A$ that may not belong to $A$.  We say that a real number $x$ is a {\\bf lower bound} for a non-empty set of real numbers $A$, provided $x \\leq a$ for every $a \\in A$.  We say that the set $A$ is {\\bf bounded below} if it has at least one lower bound.  A lower bound is the {\\bf greatest lower bound} if it is at least as large as any other lower bound.  The greatest lower bound of a set of real numbers $A$ is called the {\\bf infimum} of $A$ and is denoted by:\n\\[\n\\boxed{\n\\inf{A} := \\text{greatest lower bound of $A$}\n}\n\\]\nFor example, $\\inf (0,1) = 0$ and $\\inf \\{ 10.333 \\cup [-99,1001.33) \\} = -99$.  We similarly define the {\\bf least upper bound} of a non-empty set of real numbers $A$ to be the {\\bf supremum} of $A$ and denote it as:\n\\[\n\\boxed{\n\\sup{A} := \\text{least upper bound of $A$}\n}\n\\]\nFor example, $\\sup (0,1) = 1$ and $\\sup \\{ 10.333 \\cup [-99,1001.33) \\} = 1001.33$.  By convention, we define $\\inf \\emptyset := \\infty$, $\\sup \\emptyset := - \\infty$.  Finally, if a set $A$ is not bounded below then $\\inf A := - \\infty$ and if a set $A$ is not bounded above then $\\sup A := \\infty$.\n\\begin{table}[htb]\n\\centering\n{\\small\n\\begin{tabular}{| l | l |}\n\\hline\nSymbol & Meaning\\\\ \\hline\n$A = \\{ \\star, \\circ, \\bullet \\}$& $A$ is a set containing the elements $\\star$, $\\circ$ and $\\bullet$ \\\\\n$\\circ \\in A$ & $\\circ$ belongs to $A$ or $\\circ$ is an element of $A$\\\\\n$A \\ni \\circ$ & $\\circ$ belongs to $A$ or $\\circ$ is an element of $A$\\\\\n$\\odot \\notin A$& $\\odot$ does not belong to $A$ \\\\\n$\\# A$& Size of the set $A$, for e.g.~$\\#\\{ \\star, \\circ, \\bullet, \\odot \\}=4$\\\\\n$\\Nz$& The set of natural numbers $\\{1,2,3,\\ldots\\}$\\\\\n$\\Zz$&The set of integers $\\{\\ldots,-3,-2,-1,0,1,2,3,\\ldots\\}$\\\\\n$\\Zz_+$& The set of non-negative integers $\\{0,1,2,3,\\ldots\\}$\\\\\n%$\\Rz$& The set of real numbers\\\\\n$\\emptyset$&Empty set or the collection of nothing or $\\{\\}$\\\\\n$A \\subset B$ & $A$ is a subset of $B$ or $A$ is contained by $B$, e.g.~$A=\\{\\circ\\}, B=\\{\\bullet\\}$\\\\\n$A \\supset B$& $A$ is a superset of $B$ or $A$ contains $B$ e.g.~$A=\\{\\circ, \\star,\\bullet\\}, B=\\{\\circ, \\bullet\\}$ \\\\\n$A=B$ & $A$ equals $B$, i.e.~$A \\subset B$ and  $B \\subset A$\\\\\n$Q \\implies R$ & Statement $Q$ implies statement $R$ or If $Q$ then $R$ \\\\\n$Q \\iff R$ & $Q \\implies R$ and $R \\implies Q$ \\\\\n$\\{x: x \\text{ satisfies property } R \\}$& The set of all $x$ such that $x$ satisfies property $R$\\\\\n$A \\cup B$& $A$ union $B$, i.e.~$\\{x: x\\in A \\text{ or } x \\in B\\}$\\\\\n$A \\cap B$& $A$ intersection $B$, i.e.~$\\{x: x\\in A \\text{ and } x \\in B\\}$\\\\\n$A \\setminus B $& $A$ minus $B$, i.e.~$\\{x: x\\in A \\text{ and } x \\notin B\\}$\\\\\n$A:=B$& $A$ is equal to $B$ by definition\\\\\n$A=:B$& $B$ is equal to $A$ by definition\\\\\n$A^c$& $A$ complement, i.e.~$\\{x: x\\in U, \\text{ the universal set, but } x \\notin A\\}$\\\\ \n$A_1 \\times A_2 \\times \\cdots \\times A_m$ & The $m$-product set $\\{(a_1,a_2,\\ldots,a_{m}): a_1 \\in A_1, a_2 \\in A_2, \\ldots, a_{m} \\in A_m \\}$ \\\\\n$A^m$ & The $m$-product set $\\{(a_1,a_2,\\ldots,a_{m}): a_1 \\in A, a_2 \\in A, \\ldots, a_{m} \\in A \\}$ \\\\ \n$f := f(x)=y:\\Xz \\to \\Yz$ & A function $f$ from domain $\\Xz$ to range $\\Yz$ \\\\\n$f^{[-1]}(y)$ & Inverse image of $y$ \\\\ \n$f^{[-1]} := f^{[-1]}(y \\in \\Yz) = X \\subset \\Xz$ & Inverse of $f$ \\\\ \n%$\\Zz:=\\{\\ldots,-2,-1,0,1,2,\\ldots\\}$ & Integers \\\\\n$a<b$ or $a \\leq b$ & $a$ is less than $b$ or $a$ is less than or equal to $b$ \\\\\n$a>b$ or $a \\geq b$ & $a$ is greater than $b$ or $a$ is greater than or equal to $b$ \\\\ \n$\\Qz$ & Rational numbers \\\\ \n$(x,y)$ & the open interval $(x,y)$, i.e.~$\\{r: x < r < y\\}$ \\\\ \n$[x,y]$ & the closed interval $(x,y)$, i.e.~$\\{r: x \\leq r \\leq y\\}$ \\\\ \n$(x,y]$ & the half-open interval $(x,y]$, i.e.~$\\{r: x < r \\leq y\\}$ \\\\ \n$[x,y)$ & the half-open interval $[x,y)$, i.e.~$\\{r: x \\leq r < y\\}$ \\\\ \n$\\Rz := (-\\infty,\\infty)$ & Real numbers, i.e.~$\\{r: -\\infty < r <  \\infty \\}$ \\\\\n$\\Rz_+ := [0,\\infty)$ & Real numbers, i.e.~$\\{r: 0 \\leq r <  \\infty \\}$ \\\\\n$\\Rz_{>0} := (0,\\infty)$ & Real numbers, i.e.~$\\{r: 0 < r <  \\infty \\}$ \\\\\n\\hline\n\\end{tabular}\n}\n\\caption{Symbol Table: Sets and Numbers \\label{T:SymbTableSets}}\n\\end{table}\n\n\\clearpage\n\n\\section{Introduction to \\Matlab}\\label{S:IntroMatlab}\nWe use \\Matlab to perform computations and visualisations. \\Matlab is a numerical computing environment and programming language that is optimised for vector and matrix processing.  STAT 218/313 students will have access to Maths \\& Stats Department's computers that are licensed to run \\Matlab.  You can remotely connect to these machines from home by following instructions at \\href{http://www.math.canterbury.ac.nz/php/resources/compdocs/remote}{\\url{http://www.math.canterbury.ac.nz/php/resources/compdocs/remote}}.\n\n%\\input{LabWeek1.tex}\n\n\\begin{labwork}[Basics of \\Matlab]\\label{LW:IntroMatlab}\nLet us familiarize ourselves with \\Matlab in this session.  First, you need to launch \\Matlab from your terminal.  Since this is system dependent, ask your tutor for help.  The command window within the \\Matlab window is where you need to type commands.  Here is a minimal set of commands you need to familiarize yourself with in this session.\n\\begin{enumerate}\n\\item{\nType the following command to add 2 numbers in the command window right after the command prompt {\\tt >> }.\n\\begin{VrbM}\n>> 13+24\n\\end{VrbM}\nUpon hitting {\\tt Enter} or {\\tt Return} on your keyboard, you should see:\n\\begin{VrbM}\n\nans =\n\n    37\n\n\\end{VrbM}\nThe summand 37 of 13 and 24 is stored in the default variable called {\\tt ans} which is short for answer.\n}\n\\item{\nWe can write {\\bf comments} in \\Matlab following the {\\tt \\%} character.  All the characters in a given line that follow the percent character {\\tt \\%} are ignored by \\Matlab.  It is very helpful to comment what is being done in the code.  You won't get full credit without sufficient comments in your coding assignments.  For example we could have added the comment to the previous addition.  To save space in these notes, we suppress the blank lines and excessive line breaks present in \\Matlab's command window.\n\\begin{VrbM}\n>> 13+24 % adding 13 to 24 using the binary arithmetic operator +\nans =    37\n\\end{VrbM}\n}\n\\item{\nYou can {\\bf create or reopen a diary file} in \\Matlab to record your work.  Everything you typed or input and the corresponding output in the command window will be recorded in the diary file. You can create or reopen a diary file by typing {\\tt diary filename.txt} in the command window.  When you have finished recording, simply type {\\tt diary off} in the command window {\\bf to turn off the diary file}. The diary file with {\\bf .txt} extension is simply a text-file. It can be edited in different editors after the diary is turned off in \\Matlab.  You need to type {\\tt diary LabWeek1.txt} to start recording your work for electronic submission if needed.% (see \\hyperref[S:StudentEval]{Section~\\ref*{S:StudentEval}}).\n\n\\begin{VrbM}\n>> diary blah.txt % start a diary file named blah.txt\n>> 3+56\nans =    59\n>> diary off % turn off the current diary file blah.txt\n>> type blah.txt % this allows you to see the contents of blah.txt\n3+56\nans =    59\ndiary off\n>> diary blah.txt % reopen the existing diary file blah.txt\n>> 45-54\nans =    -9\n>> diary off % turn off the current diary file blah.txt again\n>> type blah.txt % see its contents\n3+56\nans =    59\ndiary off\n45-54\nans =    -9\ndiary off\n\\end{VrbM}\n}\n\\item{\nLet's learn to store values in variables of our choice.  Type the\nfollowing at the command prompt :\n\n\\begin{VrbM}\n>> VariableCalledX = 12\n\\end{VrbM}\n\nUpon hitting enter you should see that the number $12$ has been assigned to the variable named {\\tt VariableCalledX} :\n\\begin{VrbM}\nVariableCalledX =    12\n\\end{VrbM}\n}\n\\item{\n\\Matlab stores default value for some variables, such as {\\tt pi} ($\\pi$), {\\tt i} and {\\tt j} (complex numbers).\n\\begin{VrbM}\n>> pi\nans =    3.1416\n>> i\nans =        0 + 1.0000i\n>> j\nans =        0 + 1.0000i\n\\end{VrbM}\nAll predefined symbols (variables, constants, function names, operators, etc) in \\Matlab are written in lower-case.  Therefore, it is a good practice to name the variable you define using upper and mixed case letters in order to prevent an unintended overwrite of some predefined \\Matlab symbol.\n}\n\\item{\nWe could have stored the sum of 13 and 24 in the variable ${\\tt X}$, by entering:\n\\begin{VrbM}\n>> X = 13 + 24\nX =    37\n\\end{VrbM}\n}\n\\item{\nSimilarly, you can store the outcome of multiplication (via operation {\\tt *} ), subtraction\n(via operation {\\tt -}), division (via {\\tt /} ) and exponentiation (via \\^{} )of any two numbers of your choice in a variable name of your choice.  Evaluate the following expressions in \\Matlab:\n\n\\begin{tabular*}{4.5in}{@{\\extracolsep{\\fill}}l l}\n$p = 45.89 * 1.00009$ & $d = 89.0 / 23.3454$ \\\\\n$m = 5376.0 - 6.00$ & $p = 2^{0.5}$ \\\\\n\\end{tabular*}\n}\n\\item{ You may compose the elementary operations to obtain rational expressions by using parenthesis to specify the order of the operations.  To obtain $\\sqrt{2}$, you can type the following into \\Matlab's command window.\n\\begin{VrbM}\n>> 2^(1/2)\nans =    1.4142\n\\end{VrbM}\nThe omission of parenthesis about $1/2$ means something else and you get the following output:\n\\begin{VrbM}\n>> 2^1/2\nans =     1\n\\end{VrbM}\n\\Matlab first takes the $1$st power of $2$ and then divides it by $2$ using its default precedence rules for binary operators in the absence of parenthesis.  The order of operations or default precedence rule for arithmetic operations is 1. {\\bf b}rackets or parentheses; 2. {\\bf e}xponents (powers and roots); 3. {\\bf d}ivision and {\\bf m}ultiplication; 4. {\\bf a}ddition and {\\bf s}ubtraction.  The mnemonic {\\bf bedmas} can be handy.  When in doubt, use parenthesis to force the intended order of operations.\n}\n\\item{\nWhen you try to divide by 0, \\Matlab returns {\\tt Inf} for infinity.\n\\begin{VrbM}\n>> 10/0\nans =   Inf\n\\end{VrbM}\n}\n\\item{\nWe can clear the value we have assigned to a particular variable and reuse it.  We demonstrate it by the following commands and their output:\n\\begin{VrbM}\n>> X\nX =    37\n>> clear X\n>> X\n??? Undefined function or variable 'X'.\n\\end{VrbM}\nEntering {\\tt X} after {\\tt clear}ing it gives the above self-explanatory error message preceded by {\\tt ???}.\n}\n\\item{\nWe can suppress the output on the screen by ending the command with a semi-colon.  Take a look at the simple command that sets $X$ to $\\sin(3.145678)$ with and without the `{\\tt ;}' at the end:\n\\begin{VrbM}\n>> X = sin(3.145678)\nX =   -0.0041\n>> X = sin(3.145678);\n\\end{VrbM}\n}\n\\item{\nIf you do not understand a \\Matlab function or command then type {\\tt help} or {\\tt doc} followed by the function or command. For example:\n\\begin{VrbM}\n>> help sin\n SIN    Sine of argument in radians.\n    SIN(X) is the sine of the elements of X.\n    See also asin, sind.\n    Overloaded methods:\n       darray/sin\n    Reference page in Help browser\n       doc sin\n>> doc sin\n\\end{VrbM}\nIt is a good idea to use the help files before you ask your tutor. \n}\n\\item{\nSet the variable ${\\tt x}$ to equal $17.13$ and evaluate $\\cos(x)$, $\\log(x)$, $\\exp(x)$, $\\arccos(x)$, $\\abs(x)$, $\\sign(x)$ using the \\Matlab commands {\\tt cos}, {\\tt log}, {\\tt exp}, {\\tt acos}, {\\tt abs}, {\\tt sign}, respectively.  Read the help files to understand what each function does.\n}\n\\item{\nWhen we work with real numbers (floating-point numbers) or really large numbers, we might want the output to be displayed in concise notation.  This can be controlled in \\Matlab using the {\\tt format} command with the {\\tt short} or {\\tt long} options with/without {\\tt e} for scientific notation. {\\tt format compact} is used for getting compacted output and {\\tt format} returns the default format.  For example:\n\\begin{VrbM}\n>> format compact\n>> Y=15;\n>> Y = Y + acos(-1)\nY =   18.1416\n>> format short\n>> Y\nY =   18.1416\n>> format short e\n>> Y\nY =  1.8142e+001\n>> format long\n>> Y\nY =  18.141592653589793\n>> format long e\n>> Y\nY =    1.814159265358979e+001\n>> format\n>> Y\nY =   18.1416\n\\end{VrbM}\n}\n\\item{\nFinally, to quit from \\Matlab just type {\\tt quit} or {\\tt exit} at the prompt.\n\\begin{VrbM}\n>> quit\n\\end{VrbM}\n}\n\\item{\nAn {\\bf M-file} is a special text file with a {\\tt .m} extension that contains a set of code or instructions in \\Matlab.  In this course we will be using two types of M-files: {\\bf script} and {\\bf function} files.  A script file is simply a list of  commands that we want executed and saves us from retyping code modules we are pleased with.  A function file allows us to write specific tasks as functions with input and output.  These functions can be called from other script files, function files or command window.  We will see such examples shortly.\n}\n\\end{enumerate}\n\n\\end{labwork}\n\nBy now, you are expected to be familiar with arithmetic operations, simple function evaluations, format control, starting and stopping a diary file and launching and quitting \\Matlab.\n \n\\section{Elementary Combinatorics}\\label{S:PermsFactsCombs}\n\nCombinatorics is the branch of mathematics that specialises in counting. \nWe will give a more intuitive treatment with examples and then formally define the most primitive ideas called permutations and combinations. We also use several commonly encountered notations.\n\nThe most basic counting rule we use enables us to determine the number of distinct elements in a set that is constructed from taking two or more steps, where each step uses elements of another set. \nThis is a lot easier than it sounds. Let's understand this through the analogy of performing several tasks.\n\n\\begin{framed}{\\bf The multiplication principle:}\nIf a task can be performed in $n_1$ ways, a second task in $n_2$ ways, a\nthird task in $n_3$ ways, etc., then the total number of distinct ways\nof performing all tasks together is\n\\[n_1\\,\\times\\,n_2\\,\\times\\,n_3\\,\\times\\, \\dots  \\]\n\\end{framed}\n\n\\begin{example}\\label{EX:unrestrictedPIN}\nSuppose that a Personal Identification Number (PIN) is a six-symbol code word in which the first four entries are letters (lowercase) and the last two entries are digits. \nHow many PINS are there? There are six selections to be made:\n\\bcols{2}\\bit\n\\item[] First letter: 26 possibilities\n\\item[] Second letter: 26 possibilities\n\\item[] Third letter: 26 possibilities\n\\item[] Fourth letter: 26 possibilities\n\\item[] First digit: 10 possibilities\n\\item[] Second digit: 10 possibilities\n\\eit\\ecols\nSo in total, the total number of possible PINS is:\n\\[ 26\\,\\times\\,26 \\,\\times\\,26\\,\\times\\,26\\,\\times\\,10\\,\\times\\,10\\;=\\;\n26^4\\,\\times 10^2 \\;=\\;45,697,600\\,.\\]\n\\end{example}\n\n\\begin{example}\\label{EX:restrictedPIN}\nSuppose we now put restrictions on the letters and digits we use. For example,\nwe might say that the first digit cannot be zero, and  letters cannot be\nrepeated.  This time the the total number of possible PINS is:\n\\[ 26\\,\\times\\,25 \\,\\times\\,24\\,\\times\\,23\\,\\times\\,9\\,\\times\\,10 \\;=\\;32,292,000\\,.\\]\n\\end{example}\n\nWhen does order matter? In English we use the word ``combination'' loosely. \nIf I  say\n\\cen{``I have  17 probability  texts on my bottom shelf''} then I don't care (usually) about what order they are in,\nbut in the statement\n\\cen{``The combination of  my PIN is  math99''}\nI do care about order. A different order gives a different PIN.\n\nSo in mathematics, we use more precise language:\n\\bit\n\\item A selection of objects in which the order  is\n  important is called a {\\bf permutation}.\n\n\\item A selection of objects in which the order  is\n  \\emph{not}\n  important is called a {\\bf combination}.\n\\eit\n\n{\\bf Permutations:} There are basically two types of permutations:\n\n\\be\n\\item  Repetition is allowed, as in choosing the letters (unrestricted choice) in the PIN of Example~\\ref{EX:unrestrictedPIN}. \nMore generally, when you have $n$ objects to choose from, you have $n$ choices each time, so when choosing $r$ of them, the  number of permutations are $n^r$.\n\\item  No repetition is allowed, as in the restricted  PIN Example~\\ref{EX:restrictedPIN}. Here you have to reduce the number of choices. \nIf we had a 26 letter PIN then the total permutations would be\n\\[26\\,\\times\\,25 \\,\\times\\,24\\,\\times\\,23\\,\\times\\,\\dots\\;\\,\\times\\,3\n\\,\\times\\,2 \\,\\times\\, 1\\;=\\; 26!\\]\nbut since we  want four letters only here,  we  have\n\\[\\frac{26!}{22!}\\;=\\; 26\\,\\times\\,25 \\,\\times\\,24\\,\\times\\,23\\]\nchoices.\n\\ee\n\n\\begin{framed}The number of distinct {\\bf permutations}  of $n$ objects taking\n$r$ at a time is given by\n\\[^nP_r\\;=\\; \\frac{n!}{(n-r)!}\\]\n\\end{framed}\n\n\\bigskip\n\n{\\bf Combinations:} There are also two types of combinations:\n\n\n\\be\n\\item Repetition is allowed  such as the  coins in your pocket, say, $(10c, 50c,\\, 50c, \\, \\$1,\\, \\$2, \\,\\$2)$.\n\\item  No repetition is allowed as  in the  lottery numbers $(2,\\,9,\\,11,\\,26,\\,29,\\,31)$.  The numbers are drawn one at a time, \nand if you have the lucky numbers (no matter what order) you win!\n\\ee\n\n\\begin{framed}The number of distinct {\\bf combinations}  of $n$ objects taking\n$r$ at a time is given by\n\\[^nC_r\\;=\\;\\binom{n}{r} \\;=\\; \\frac{n!}{(n-r)!\\,r!}\\]\n\\end{framed}\n\n\\begin{example}\nLet us imagine being in the lower Manhattan in New York city with its perpendicular grid of streets and avenues.  \nIf you start at a given intersection and are asked to only proceed in a north-easterly direction then how may ways are there \nto reach another intersection by walking exactly two blocks or exactly three blocks?\n\nSolution:\\\\\nLet us answer this question of combinations by drawing Fig.~\\ref{F:TwoAndThreeBlocksNorthEast}.\nLet us denote the number of easterly turns you take by $r$ and the total number of blocks you are allowed to walk either easterly or northerly by $n$.  \nFrom Fig.~\\ref{F:TwoAndThreeBlocksNorthEast}(a) it is clear that the number of ways to reach each of the three intersections labeled by $r$ is given by $\\binom{n}{r}$, \nwith $n=2$ and $r \\in \\{0,1,2\\}$. \nSimilarly, from Fig.~\\ref{F:TwoAndThreeBlocksNorthEast}(b) it is clear that the number of ways to reach each of the four intersections labeled by $r$ is given by $\\binom{n}{r}$, with $n=3$ and $r \\in \\{0,1,2,3\\}$.\n\\end{example}\n  \n\\begin{figure}[htbp]\\label{F:TwoAndThreeBlocksNorthEast}\n\\centering\\subfigure[{\\scriptsize Walking two blocks north-easterly.}]{\n\\includegraphics[width=7cm]{figures/TwoBlocksNorthEast.eps}}\n\\subfigure[{\\scriptsize Walking three blocks north-easterly.}]{\n\\includegraphics[width=7cm]{figures/ThreeBlocksNorthEast.eps}}\n\\end{figure}\n\n\n\\begin{Exercise}[title={Choosing Volunteers},label={xChoose3of50}]\nSuppose we need three students to be the class representatives in this course. \nAssume that everyone wants to be selected to keep it simple. \nIn how many ways can we choose these three people from the class of 50 students? \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}\nWe start by assuming that order does matter, that is, we have a\npermutation, so that the number of ways we can select the three class\nrepresentatives is\n\\[^{50}P_3\\;=\\; \\frac{50!}{(50-3)!}\\;=\\; \\frac{50!}{47!}\\]\nBut, because order doesn't matter,  all we have to do is to adjust our\npermutation formula by a factor representing the number of  ways the objects could be in\norder. Here,  three students can  be placed in order $3!$ ways, so\nthe required number of  ways of choosing the class representatives is:\n\\[ \\frac{50!}{47!\\, 3!}\\;=\\;\n\\frac{50\\,.\\, 49\\,.\\,48}{3\\,.\\,2\\,.\\,1}\\;=\\; 19,600\\]\n\\end{Answer}\n\n\\medskip\nNow, we give more formal definitions and notations that will help us make precise arguments faster when we study sampling schemes in Inference Theory.\n\n\\begin{definition}[Permutations and Factorials]\nA {\\bf permutation} of $n$ objects is an arrangement of $n$ distinct objects in a row.  For example, there are $2$ permutations of the two objects $\\{1,2\\}$:\n\\[\n12, \\qquad 21 \\ ,\n\\]\nand $6$ permutations of the three objects $\\{a,b,c\\}$:\n\\[\nabc, \\quad acb, \\quad bac, \\quad bca, \\quad cab, \\quad cba \\ .\n\\]\nLet the number of ways to choose $k$ objects out of $n$ and to arrange them in a row be denoted by $p_{n,k}$.  For example, we can choose two ($k=2$) objects out of three ($n=3$) objects, $\\{a,b,c\\}$, and arrange them in a row in six ways ($p_{3,2}$):\n\\[\nab, \\quad ac, \\quad ba, \\quad bc, \\quad ca, \\quad cb \\ .\n\\]\nGiven $n$ objects, there are $n$ ways to choose the left-most object, and once this choice has been made there are $n-1$ ways to select a different object to place next to the left-most one.  Thus, there are $n(n-1)$ possible choices for the first two positions.  Similarly, when $n>2$, there are $n-2$ choices for the third object that is distinct from the first two.  Thus, there are $n(n-1)(n-2)$ possible ways to choose three distinct objects from a set of $n$ objects and arrange them in a row.  In general, \n\\[\np_{n,k} = n(n-1)(n-2)\\ldots (n-k+1)\n\\]\nand the total number of permutations called `$n$ {\\bf factorial}' and denoted by $n!$ is\n\\[\nn! := p_{n,n} = n (n-1) (n-2)\\ldots (n-n+1) = n (n-1) (n-2)\\ldots (3) \\ (2) \\ (1) =: \\prod_{i=1}^n i \\ .\n\\]\n\\end{definition}\n\nSome factorials to bear in mind\n\\[\n0! := 1 \\quad 1!=1, \\quad 2!=2, \\quad 3!=6, \\quad 4!=24, \\quad 5!=120 \\quad 10!=3,628,800 \\ .\n\\]\nWhen $n$ is large we can get a good idea of $n!$ without laboriously carrying out the $n-1$ multiplications via Stirling's approximation ({\\it Methodus Differentialis (1730), p.~137}) :\n\\[\nn! \\approxeq \\sqrt{2 \\pi n} \\left( \\frac{n}{e} \\right)^n \\ .\n\\]\n\n\\begin{definition}[Combinations]\nThe combinations of $n$ objects taken $k$ at a time are the possible choices of $k$ different elements from a collection of $n$ objects, disregarding order.  They are called the $k$-combinations of the collection.  The combinations of the three objects $\\{a,b,c\\}$ taken two at a time, called the $2$-combinations of $\\{a,b,c\\}$, are\n\\[\nab, \\quad ac, \\quad bc \\ ,\n\\]\nand the combinations of the five objects $\\{1,2,3,4,5\\}$ taken three at a time, called the $3$-combinations of $\\{1,2,3,4,5\\}$ are\n\\[\n123, \\quad 124, \\quad 125, \\quad 134, \\quad 135, \\quad 145, \\quad 234, \\quad 235, \\quad 245, \\quad 345 \\ .\n\\]\nThe total number of $k$-combination of $n$ objects, called a {\\bf binomial coefficient}, denoted $\\binom{n}{k}$ and read ``$n$ choose $k$,'' can be obtained from $p_{n,k} = n(n-1)(n-2)\\ldots(n-k+1)$ and $k! := p_{k,k}$.  Recall that $p_{n,k}$ is the number of ways to choose the first $k$ objects from the set of $n$ objects and arrange them in a row with regard to order.  Since we want to disregard order and each $k$-combination appears exactly $p_{k,k}$ or $k!$ times among the $p_{n,k}$ many permutations, we perform a division:\n\\[\n\\binom{n}{k} := \\frac{p_{n,k}}{p_{k,k}} = \\frac{n(n-1)(n-2)\\ldots(n-k+1)}{k(k-1)(k-2)\\ldots 2 \\ 1} \\ .\n\\]\n\\end{definition}\nBinomial coefficients are often called ``Pascal's Triangle''  and attributed to Blaise Pascal's  {\\it Trait\\'e du Triangle Arithm\\'etique} from 1653, but they have many ``fathers''.  There are earlier treatises of the binomial coefficients including Szu-y\\\"uan Y\\\"u-chien (``The Precious Mirror of the Four Elements'') by the Chinese mathematician Chu Shih-Chieh in 1303, and in an ancient Hindu classic, {\\it Pi\\.ngala's Chanda\\d{h}\\'s\\=astra}, due to Hal\\=ayudha (10-th century AD).\n\n\n\n\\section{Array, Sequence, Limit, \\ldots}\\label{S:ArraysSequencesLimitEtc}\n\nIn this section we will study a basic data structure in \\Matlab called an {\\bf array} of numbers.  Arrays are finite sequences and they can be processed easily in \\Matlab.  The notion of infinite sequences lead to {\\bf limits}, one of  the most fundamental concepts in mathematics.  \n\nFor any natural number $n$, we write \n$$\\boxed{\\langle x_{1:n} \\rangle := x_1,x_{2},\\ldots,x_{n-1},x_n}$$ \nto represent the {\\bf finite sequence} of real numbers $x_1,x_2,\\ldots ,x_{n-1},x_n$.\nFor two integers $m$ and $n$ such that $m \\leq n$, we write \n$$\\boxed{\\langle x_{m:n} \\rangle := x_m,x_{m+1},\\ldots,x_{n-1},x_n}$$ \nto represent the {\\bf finite sequence} of real numbers $x_m,x_{m+1},\\ldots ,x_{n-1},x_n$.  In mathematical analysis, finite sequences and their countably infinite counterparts play a fundamental role in limiting processes.  Given an integer $m$, we denote an {\\bf infinite sequence} or simply a sequence as:\n\\[\n\\boxed{\n\\langle x_{m:\\infty} \\rangle := x_m, x_{m+1}, x_{m+2}, x_{m+3}, \\ldots \\ . }\n\\]\nGiven index set $\\mathcal{I}$ which may be finite or infinite in size, a sequence can either be seen as a set of ordered pairs:\n\\[\n\\{ (i,x_i) : i \\in \\mathcal{I} \\} \\enspace ,\n\\]\nor as a function that maps the index set to the set of real numbers:\n\\[\nx(i)= x_i : \\mathcal{I} \\to \\{x_{i} : i \\in \\mathcal{I} \\} \\ ,\n\\]\nThe finite sequence $\\langle x_{m:n} \\rangle$ has $\\mathcal{I}= \\{ m,m+1,m+2,m+3,\\ldots,n \\}$ as its index set  while an infinite sequence $\\langle x_{m:\\infty} \\rangle$ has $\\mathcal{I}= \\{ m,m+1,m+2,m+3,\\ldots \\}$ as its index set.  A {\\bf sub-sequence} $\\langle x_{j:k} \\rangle$ of a finite sequence $\\langle x_{m:n} \\rangle$ or an infinite sequence $\\langle x_{m:\\infty} \\rangle$ is:\n\\[\n\\langle x_{j:k} \\rangle = x_j,x_{j+1},\\ldots,x_{k-1},x_{k} \\quad \\text{where, } \\quad m \\leq j \\leq k \\leq n < \\infty \\enspace .\n\\]\n\nA rectangular arrangement of $m \\cdot n$ real numbers in $m$ rows and $n$ columns is called an $m \\times n$ {\\bf matrix}.  The `$m \\times n$' represents the {\\bf size} of the matrix.  We use bold upper-case letters to denote matrices, for e.g:\n$$ \n\\X = \\begin{bmatrix}\nx_{1,1} & x_{1,2} & \\ldots & x_{1,n-1} & x_{1,n} \\\\\nx_{2,1} & x_{2,2} & \\ldots & x_{2,n-1} & x_{2,n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\nx_{m-1,1} & x_{m-1,2} & \\ldots & x_{m-1,n-1} & x_{m-1,n} \\\\\nx_{m,1} & x_{m,2} & \\ldots & x_{m,n-1} & x_{m,n} \n\\end{bmatrix}\n$$\nMatrices with only one row or only one column are called {\\bf vectors}.  An $1 \\times n$ matrix is called a {\\bf row vector} since there is only one row and an $m \\times 1$ matrix is called a {\\bf column vector} since there is only one column.  We use bold-face lowercase letters to denote row and column vectors.\n$$ \n\\text{A row vector } \\x = \\begin{bmatrix}\nx_{1} & x_{2} & \\ldots & x_{n}\n\\end{bmatrix} = (x_1,x_2,\\ldots,x_n)\n$$\n$$\n\\text{ and a column vector } \\y = \n\\begin{bmatrix}\ny_{1} \\\\\ny_{2}  \\\\\n\\vdots \\\\\ny_{m-1} \\\\\ny_{m} \n\\end{bmatrix}  \n= \\begin{bmatrix}\ny_{1} & y_{2} & \\ldots & y_{m}\n\\end{bmatrix}'\n= (y_1,y_2,\\ldots,y_m)' \\ .\n$$\nThe superscripting by $'$ is the transpose operation and simply means that the rows and columns are exchanged.  Thus the transpose of the matrix $\\X$ is:\n$$ \n\\X' = \\begin{bmatrix}\nx_{1,1} & x_{2,1} & \\ldots & x_{m-1,1} & x_{m,1} \\\\\nx_{1,2} & x_{2,2} & \\ldots & x_{m-1,2} & x_{m,2} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\nx_{1,n-1} & x_{2,n-1} & \\ldots & x_{m-1,n-1} & x_{m,n-1} \\\\\nx_{1,n} & x_{2,n} & \\ldots & x_{m-1,n} & x_{m,n} \n\\end{bmatrix}\n$$\nIn linear algebra and calculus, it is natural to think of vectors and matrices as points (ordered $m$-tuples) and ordered collection of points in Cartesian co-ordinates.  We assume that the reader has heard of operations with matrices and vectors such as matrix multiplication, determinants, transposes, etc.  Such concepts will be introduced as they are needed in the sequel.\n\nFinite sequences, vectors and matrices can be represented in a computer by an elementary data structure called an {\\bf array}.  \n\n\\begin{labwork}[Sequences as arrays]\\label{LW:Seqs}\nLet us learn to represent, visualise and operate finite sequences as \\Matlab arrays.  Try out the commands and read the comments for clarification.\n\\begin{VrbM}\n>> a = [17]\t\t\t% Declare the sequence of one element 17 in array a\na =    17\n>> % Declare the sequence of 10 numbers in array b\n>> b=[-1.4508 0.6636 -1.4768 -1.2455 -0.8235 1.1254 -0.4093 0.1199 0.2043 -0.8236]\nb =\n   -1.4508    0.6636   -1.4768   -1.2455   -0.8235    1.1254   -0.4093    0.1199    0.2043   -0.8236\n>> c = [1 2 3] \t\t% Declare the sequence of 3 consecutive numbers 1,2,3\nc =     1     2     3\n>> % linspace(x1, x2, n) generates n points linearly spaced between x1 and x2\n>> r = linspace(1, 3, 3)\t\t% Declare sequence r = c using linspace\nr =     1     2     3\n>> s1 = 1:10 % declare an array s1 starting at 1, ending by 10, in increments of 1 \ns =     1     2     3     4     5     6     7     8     9    10\n>> s2 = 1:2:10  % declare an array s2 starting at 1, ending by 10, in increments of 2 \ns =     1     3     5     7     9\n>> s2(3) % obtain the third element of the finite sequence s2\nans =     5\n>> s2(2:4) % obtain the subsequence from second to fourth elements of the finite sequence s2\nans =     3     5     7\n\\end{VrbM}\nWe may visualise (as per~\\hyperref[F:StemPlotDemo1]{Figure~\\ref*{F:StemPlotDemo1}}) the finite sequences $\\langle b_{1:n} \\rangle$ stored in the array {\\tt b} as the set of ordered pairs $\\{(1,b_1),(2,b_2),\\ldots,(10,b_{n})\\}$ representing the function $b(i)=b_i:\\{1,2,\\ldots,n\\} \\to \\{b_1,b_2,\\ldots,b_{n} \\}$ via {\\bf point plot} and {\\bf stem plot}  using {\\tt Matlab}'s {\\tt plot} and {\\tt stem} commands, respectively.\n\n\\begin{figure}[hbt]\n\\caption{Point plot and stem plot of the finite sequence $\\langle b_{1:10} \\rangle$ declared as an array.\\label{F:StemPlotDemo1}}\n\\centering   \\makebox{\\includegraphics[width=7.0in]{figures/StemPlotDemo1}}\n\\end{figure}\n\\begin{VrbM}\n>> display(b) % display the array b in memory\nb =\n   -1.4508    0.6636   -1.4768   -1.2455   -0.8235    1.1254   -0.4093    0.1199    0.2043   -0.8236\n>> plot(b,'o') % point plot of ordered pairs (1,b(1)), (2,b(2)), ..., (10,b(10))\n>> stem(b) % stem plot of ordered pairs (1,b(1)), (2,b(2)), ..., (10,b(10))\n>> plot(b,'-o') % point plot of ordered pairs (1,b(1)), (2,b(2)), ..., (10,b(10)) connected by lines\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{labwork}[Vectors and matrices as arrays]\\label{LW:VecsMats}\nLet us learn to represent, visualise and operate vectors as \\Matlab arrays.  Syntactically, a vector is stored in an array exactly in the same way we stored a finite sequence.  However, mathematically, we think of a vector as an ordered $m$-tuple that can be visualised as a point in Cartesian co-ordinates.  Try out the commands and read the comments for clarification.\n\\begin{VrbM}\n>> a = [1 2]\t% an 1 X 2 row vector\n>> z = [1 2 3] \t% Declare an 1 X 3 row vector z with three numbers\nz =     1     2     3\n>> % linspace(x1, x2, n) generates n points linearly spaced between x1 and x2\n>> r = linspace(1, 3, 3)\t\t% Declare an 1 X 3 row vector r = z using linspace\nr =     1     2     3\n>> c = [1; 2; 3]  \t% Declare a 3 X 1 column vector c with three numbers.  Semicolons delineate columns\nc =\n     1\n     2\n     3\n>> rT = r'\t% The column vector (1,2,3)' by taking the transpose of r via r'\nrT =\n     1\n     2\n     3\n>> y = [1 1 1] \t\t\t% y is a sequence or row vector of 3 1's\ny =     1     1     1\n>> ones(1,10)\t% ones(m,n) is an m X n matrix of ones.  Useful when m or n is large.\nans =     1     1     1     1     1     1     1     1     1     1\n\\end{VrbM}\nWe can use two dimensional arrays to represent matrices.  Some useful built-in commands to generate standard matrices are:\n\\begin{VrbM}\n>> Z=zeros(2,10) % the 2 X 10 matrix of zeros\nZ =\n     0     0     0     0     0     0     0     0     0     0\n     0     0     0     0     0     0     0     0     0     0\n>> O=ones(4,5) % the 4 X 5 matrix of ones\nO =\n     1     1     1     1     1\n     1     1     1     1     1\n     1     1     1     1     1\n     1     1     1     1     1\n>> E=eye(4) % the 4 X 4 identity matrix\nE =\n     1     0     0     0\n     0     1     0     0\n     0     0     1     0\n     0     0     0     1\n\\end{VrbM}\nWe can also perform operations with arrays representing vectors, finite sequences, or matrices.\n\\begin{VrbM}\n>> y % the array y is\ny =     1     1     1\n>> z % the array z is\nz =     1     2     3\n>> x = y + z   \t\t\t% x is the sum of vectors y and z (with same size 1 X 3)\nx =     2     3     4\n>> y = y * 2    \t\t\t% y is updated to 2 * y (each term of y is multiplied by 2)\ny =     2     2     2\n>> p = z .* y   \t\t\t% p is the vector obtained by term-by-term product of z and y\np =     2     4     6\n>> d = z ./ y    \t\t\t% d is the vector obtained by term-by-term division of z and y\nd =    0.5000    1.0000    1.5000\n>> t=linspace(-10,10,4)\t\t% t has 4 numbers equally-spaced between -10 and 10\nt =  -10.0000   -3.3333    3.3333   10.0000\n>> s = sin(t) \t\t\t% s is a vector obtained from the term-wise sin of the vector t\ns =    0.5440    0.1906   -0.1906   -0.5440\n>> sSq = sin(t) .^ 2\t % sSq is an array obtained from term-wise squaring ( .^ 2) of the sin(t) array\nsSq =    0.2960    0.0363    0.0363    0.2960\n>> cSq = cos(t) .^ 2 % cSq is an array obtained from term-wise squaring ( .^ 2) of the cos(t) array\ncSq =    0.7040    0.9637    0.9637    0.7040\n>> sSq + cSq % we can add the two arrays sSq and cSq to get the array of 1's\nans =     1     1     1     1\n>> n = sin(t) .^2 + cos(t) .^2 \t% we can directly do term-wise operation sin^2(t) + cos^2(t) of t as well\nn =     1     1     1     1\n>> t2 = (-10:6.666665:10)\t% t2 is similar to t above but with ':' syntax of (start:increment:stop)\nt2 =  -10.0000   -3.3333    3.3333   10.0000\n\\end{VrbM}\n\nSimilarly, operations can be performed with matrices.\n\\begin{VrbM}\n>>  (O+O) .^ (1/2) % term-by-term square root of the matrix obtained by adding O=ones(4,5) to itself \nans =\n    1.4142    1.4142    1.4142    1.4142    1.4142\n    1.4142    1.4142    1.4142    1.4142    1.4142\n    1.4142    1.4142    1.4142    1.4142    1.4142\n    1.4142    1.4142    1.4142    1.4142    1.4142\n\\end{VrbM}\nWe can access specific rows or columns of a matrix as follows:\n\\begin{VrbM}\n>> % declare a 3 X 3 array A of row vectors\n>> A = [0.2760    0.4984    0.7513; 0.6797    0.9597    0.2551; 0.1626    0.5853    0.6991]\nA =\n    0.2760    0.4984    0.7513\n    0.6797    0.9597    0.2551\n    0.1626    0.5853    0.6991\n>> A(2,:) % access the second row of A\nans =\n    0.6797    0.9597    0.2551\n>> B = A(2:3,:) % store the second and third rows of A in matrix B\nB =\n    0.6797    0.9597    0.2551\n    0.1626    0.5853    0.6991\n>> C = A(:,[1 3]) % store the first and third columns of A in matrix C\nC =\n    0.2760    0.7513\n    0.6797    0.2551\n    0.1626    0.6991\\end{VrbM}\n\\end{labwork}\n\n\\begin{labwork}[Plotting a function as points of ordered pairs in two arrays]\\label{LW:2Dplot}\nNext we plot the function $sin(x)$ from several ordered pairs $(x_i,sin(x_i))$.  Here $x_i$'s are from the domain $[-2 \\pi, 2 \\pi]$.  We use the {\\tt plot} function in \\Matlab.  Create an M-file called {\\tt MySineWave.m} and copy the following commands in it.  By entering {\\tt MySineWave} in the command window you should be able to run the script and see the figure in the figure window.\n\n\\VrbMf[label=SineWave.m]{scripts/SineWave.m} \n\nThe plot was saved as an encapsulated postscript file from the File menu of the Figure window and is displayed below.\n\\begin{figure}[ht]\n\\vspace{2cm}\n%FIX\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/sinewave}}\n\\caption{A plot of the sine wave over $[-2 \\pi, 2 \\pi]$.\\label{F:sinfunction}}\n\\end{figure}\n\\end{labwork}\n\n%\\begin{classwork}\n%Recall the trigonometric function $\\sin$ with domain $\\Rz$ and range $[-1,1]$.  We can explicitly refer to this function by writing:\n%\\[\n%\\sin : \\Rz \\to [-1,1]\n%\\]\n%\\begin{figure}[htpb]\n%\\caption{A depiction of the function $\\sin$ and the inverse image $\\sin^{[-1]}(0) =\\{i \\pi : i \\in \\Zz\\}$.\\label{F:sinfunction}}\n%\\vspace{5cm}\n%\\end{figure}\n%\\end{classwork}\n\n%Continuity\n\n\\section{Elementary Real Analysis}\n\n\n\n\\subsection{Limits of Real Numbers -- A Review}\\label{S:AnalysisRefresher}\n\n%TODO\n%Differentiability\n\n%Riemann Integral\n\n\nLet us first recall some elementary ideas from real analysis.\n\\begin{definition}[Convergent sequence of real numbers]\\label{Dfn:ConvReals}\nA sequence of real numbers  $\\langle x_i \\rangle_{i=1}^{\\infty} := x_1,x_2,\\ldots$ is said to converge to a limit $a \\in \\Rz$ and denoted by:\n\\[\n\\lim_{i \\to \\infty} x_i = a \\ ,\n\\]\nif for every natural number $m \\in \\Nz$, a natural number $N_m \\in \\Nz$ exists such that for every $j \\geq N_m$, $|x_j-a| \\leq \\frac{1}{m}$.\n\\end{definition}\n\nIn words, $\\lim_{i \\to \\infty} x_i = a$ means the following: no matter how small you make $\\frac{1}{m}$ by picking as large an $m$ as you wish, I can find an $N_m$, that may depend on $m$, such that every number in the sequence beyond the $N_m$-th element is within distance $\\frac{1}{m}$ of the limit $a$.\n\n\\begin{example}[Limit of a sequence of $17$s]\\label{EX:limOf17s}\nLet $\\langle x_i \\rangle_{i=1}^{\\infty} = 17, 17, 17, \\ldots$. Then $\\lim_{i \\to \\infty} x_i = 17$.  This is because for every  $m \\in \\Nz$, we can take $N_m=1$ and satisfy the definition of the limit, i.e.:\n\\[\n\\text{for every }  j \\geq N_m= 1, \\  |x_j-17|=|17-17|=0\\leq \\frac{1}{m} \\ .\n\\]\n\\end{example}\n\n\\begin{example}[Limit of $1/i$]\\label{EX:limin1overi}\nLet $\\langle x_i \\rangle_{i=1}^{\\infty} = \\frac{1}{1},\\frac{1}{2},\\frac{1}{3}, \\ldots$, i.e.~$x_i = \\frac{1}{i}$, then $\\lim_{i \\to \\infty} x_i = 0$.  This is because for every  $m \\in \\Nz$, we can take $N_m=m$ and satisfy the definition of the limit, i.e.:\n\\[\n\\text{for every }  j \\geq N_m= m, \\  |x_j-0|=\\left| \\frac{1}{j}-0 \\right|=\\frac{1}{j} \\leq \\frac{1}{m} \\ .\n\\]\n\\end{example}\nHowever, several other sequences also approach the limit $0$.  Some such sequences that approach the limit $0$ from the right are:\n\\begin{flalign*}\n\\langle x_{1:\\infty} \\rangle =  \\frac{1}{1},\\frac{1}{4},\\frac{1}{9}, \\ldots \\qquad \\text{and} \\qquad  \\langle x_{1:\\infty} \\rangle  =  \\frac{1}{1},\\frac{1}{8},\\frac{1}{27},\\ldots \\enspace ,\n\\end{flalign*}\nand some that approach the limit $0$ from the left are:\n\\begin{flalign*}\n\\langle x_{1:\\infty} \\rangle =  -\\frac{1}{1},-\\frac{1}{2},-\\frac{1}{3}, \\ldots \\qquad \\text{and} \\qquad \n\\langle x_{1:\\infty} \\rangle =  -\\frac{1}{1},-\\frac{1}{4},-\\frac{1}{9}, \\ldots \\enspace ,\n\\end{flalign*}\nand finally some that approach $0$ from either side are:\n\\begin{flalign*}\n\\langle x_{1:\\infty} \\rangle =  -\\frac{1}{1},+\\frac{1}{2},-\\frac{1}{3}, \\ldots \\qquad \\text{and} \\qquad \n\\langle x_{1:\\infty} \\rangle = -\\frac{1}{1},+\\frac{1}{4},-\\frac{1}{9} \\ldots \\enspace .\n\\end{flalign*}\nWhen we do not particularly care about the specifics of a sequence of real numbers $\\langle x_{1:\\infty} \\rangle$, in terms of the exact values it takes for each $i$, but we are only interested that it converges to a limit $a$ we write:\n\\[\nx \\to a\n\\]\nand say that $x$ approaches $a$.  If we are only interested in those sequences that converge to the limit $a$ from the right or left, we write:\n\\[\nx \\to a^+ \\qquad \\text{or} \\qquad x \\to a^-\n\\]\nand say $x$ approaches $a$ from the right or left, respectively.\n\n\\begin{definition}[Limits of Functions]\\label{D:LimitofRealFunction}\nWe say a function $f(x):\\Rz \\to \\Rz$ has a {\\bf limit} $L \\in \\Rz$ as $x$ approaches $a$ and write:\n\\[\n\\lim_{x \\to a} f(x)=L \\ ,\n\\]\nprovided $f(x)$ is arbitrarily close to $L$ for all values of $x$ that are sufficiently close to, but not equal to, $a$.  We say that $f$ has a {\\bf right limit} $L_R$ or {\\bf left limit} $L_L$ as $x$ approaches $a$ from the left or right, and write:\n\\[\n\\lim_{x \\to a^+} f(x)=L_R  \\qquad \\text{ or } \\qquad \\lim_{x \\to a^-} f(x)=L_L \\ ,\n\\] \nprovided $f(x)$ is arbitrarily close to $L_R$ or $L_L$ for all values of $x$ that are sufficiently close to, but not equal to, $a$ from the right of $a$ or the left of $a$, respectively.  When the limit is not an element of $\\Rz$ or when the left and right limits are distinct, we say that the limit does not exist. \n\\end{definition}\n\n\\begin{example}[Limit of $1/x^2$]\nConsider the function $f(x)=\\frac{1}{x^2}$.  Then\n\\[\n\\lim_{x \\to 1} f(x) = \\lim_{x \\to 1} \\frac{1}{x^2} = 1\n\\]\nexists since the limit $1 \\in \\Rz$, and the right and left limits are the same:\n\\[\n\\lim_{x \\to 1^+} f(x) = \\lim_{x \\to 1^+} \\frac{1}{x^2} = 1 \\qquad \\text{and} \\qquad \n\\lim_{x \\to 1^-} f(x) = \\lim_{x \\to 1^-} \\frac{1}{x^2} = 1 \\ .\n\\]\nHowever, the following limit does not exist:\n\\[\n\\lim_{x \\to 0} f(x) = \\lim_{x \\to 0} \\frac{1}{x^2} = \\infty\n\\]\nsince $\\infty \\notin \\Rz$.\n\\end{example}\n\nLet us next look at some limits of functions that exist despite the function itself being undefined at the limit point.  \n\n\\begin{example}[Limit of $(1+x)^{\\frac{1}{x}}$]\\label{EX:LimitToE}\nThe limit of $f(x)=(1+x)^{\\frac{1}{x}}$ as $x$ approaches $0$ exists and it is the Euler's constant $e$ :\n\\begin{eqnarray*}\n\\lim_{x \\to 0} f(x) \n&=& \\lim_{x \\to 0} (1+x)^{\\frac{1}{x}}\\\\ \n&=& \\lim_{x \\to 0} (x+1)^{(1/x)} \\quad \\text{Indeterminate form of type $1^\\infty$.}\\\\\n&=& \\exp\\left(\\lim_{x\\to 0} \\log((x+1)^{(1/x)})\\right) \\quad \\text{Transformed using $\\exp(\\lim_{x\\to 0} \\log((x+1)^{(1/x)}))$} \\\\\n&=& \\exp\\left(\\lim_{x\\to 0} (\\log(x+1))/x\\right) \\quad \\text{Indeterminate form of type $0/0$.}\\\\\n&=& \\exp\\left( \\lim_{x\\to 0} \\frac{ d\\log(x+1)/ dx}{ dx/ dx} \\right) \\quad \\text{Applying L'Hospital's rule} \\\\\n&=&  \\exp\\left(\\lim_{x\\to 0} 1/(x+1)\\right) \\quad \\text{limit of a quotient is the quotient of the limits}\\\\\n&=&  \\exp\\left(1/(\\lim_{x \\to 0} (x+1))\\right) \\quad \\text{The limit of $x+1$ as $x$ approaches $0$ is $1$}\\\\\n&=& \\exp(1)=e \\approxeq 2.71828 \\enspace .\n\\end{eqnarray*}\n\\[\n\\lim_{x \\to 0} f(x) = \\lim_{x \\to 0} (1+x)^{\\frac{1}{x}} = e \\approxeq 2.71828 \\ .\n\\]\nNotice that the above limit exists despite the fact that $f(0) = (1+0)^{\\frac{1}{0}}$ itself is undefined and does not exist.\n\\end{example}\n\n\\begin{example}[Limit of $\\frac{x^3-1}{x-1}$]\nFor $f(x)=\\frac{x^3-1}{x-1}$, this limit exists:\n\\[\n\\lim_{x \\to 1} f(x) = \\lim_{x \\to 1} \\frac{x^3-1}{x-1}\n=  \\lim_{x \\to 1} \\frac{(x-1)(x^2+x+1)}{(x-1)}\n= \\lim_{x \\to 1} x^2+x+1 = 3 \\,\n\\]\ndespite the fact that $f(1)=\\frac{1^3-1}{1-1}=\\frac{0}{0}$ itself is undefined and does not exist.\n\\end{example}\n\nNext we look at some examples of limits at infinity.\n\\begin{example}[Limit of $(1-\\frac{\\lambda}{n})^n$]\\label{EX:LimitExpofLambda} \nThe limit of $f(n)=\\left( 1-\\frac{\\lambda}{n} \\right)^n$ as $n$ approaches $\\infty$ exists and it is $e^{-\\lambda}$ :\n\\[\n\\lim_{n \\to \\infty} f(n) = \\lim_{n \\to \\infty} \\left( 1-\\frac{\\lambda}{n} \\right)^n = e^{-\\lambda} \\ .\n\\]\n\\end{example}\n\n\\begin{example}[Limit of $(1-\\frac{\\lambda}{n})^{-\\alpha}$]\\label{EX:Limit1MinusLambdaOverNToMinusK} \nThe limit of $f(n)=\\left( 1-\\frac{\\lambda}{n} \\right)^{-\\alpha}$, for some $\\alpha>0$, as $n$ approaches $\\infty$ exists and it is $1$ :\n\\[\n\\lim_{n \\to \\infty} f(n) = \\lim_{n \\to \\infty} \\left( 1-\\frac{\\lambda}{n} \\right)^{-\\alpha} = 1 \\ .\n\\]\n\\end{example}\n\n\\begin{definition}[Continuity of a function]\nWe say a real-valued function $f(x):D \\to \\Rz$ with the domain $D \\subset \\Rz$ is {\\bf right continuous} or {\\bf left continuous} at a point $a \\in D$, provided:\n\\[\n\\lim_{x \\to a^+} f(x) = f(a) \\qquad \\text{ or } \\qquad \n\\lim_{x \\to a^-} f(x) = f(a) \\ ,\n\\]\nrespectively.  We say $f$ is {\\bf continuous} at $a \\in D$, provided:\n\\[\n\\lim_{x \\to a^+} f(x) = f(a) =\n\\lim_{x \\to a^-} f(x) \\ .\n\\]\nFinally, $f$ is said to be continuous if $f$ is continuous at every $a \\in D$.\n\\end{definition}\n\\begin{example}[Discontinuity of $f(x)=(1+x)^{\\frac{1}{x}}$ at $0$]\nLet us reconsider the function $f(x)=(1+x)^{\\frac{1}{x}}:\\Rz \\to \\Rz$.  Clearly, $f(x)$ is continuous at $1$, since:\n\\[\n\\lim_{x \\to 1} f(x) = \\lim_{x \\to 1}(1+x)^{\\frac{1}{x}} = 2 = f(1)=(1+1)^{\\frac{1}{1}} \\ ,\n\\]\nbut it is not continuous at $0$, since:\n\\[\n\\lim_{x \\to 0} f(x) = \\lim_{x \\to 0} (1+x)^{\\frac{1}{x}} = e \\approxeq 2.71828 \\neq f(0) = (1+0)^{\\frac{1}{0}} \\ .\n\\]\nThus, $f(x)$ is not a continuous function over $\\Rz$.\n\\end{example}\n\n%Here is a summary of the notations we have learned here.\n%\\begin{table}[t]\n%\\centering\n%\\begin{tabular}{cc}\n%$\\Omega$&\\\\\n%$\\to$&\\\\\n%$f^{[-1]}$&\\\\\n%$lim _{i\\to \\infty}x_i=a$&\\\\\n%${x_i}^\\infty_{i=1}$&\\\\\n%$a^+$ and $a^-$&\\\\\n%$\\approxeq$ & \\\\\n%\\end{tabular}\n%%\\caption{}\n%%\\label{tab:}\n%\\end{table}\n\n%\\begin{table}[htb]\n%\\centering\n%{\\normalsize\n%\\begin{tabular}{| l | l |}\n%\\hline\n%Symbol & Meaning\\\\ \\hline\n%$\\Nz$& The set of natural numbers $\\{1,2,3,\\ldots\\}$\\\\\n%$\\Zz$&The set of integers $\\{\\ldots,-3,-2,-1,0,1,2,3,\\ldots\\}$\\\\\n%$\\Dz_+$& The set of non-negative integers $\\{0,1,2,3,\\ldots\\}$\\\\\n%$\\Rz$& The set of real numbers\\\\ \\hline\n%\\end{tabular}\n%}\n%\\caption{Analysis Symbol Table \\label{T:SymbTableAnalysis}}\n%\\end{table}\n\n\\section{Elementary Number Theory}\\label{S:ElemNumTh}\nWe introduce basic notions that we need from elementary number theory here.  These notions include integer functions and modular arithmetic as they will be needed later on.\n\nFor any real number $x$:\n\\begin{flalign*}\n\\lfloor x \\rfloor &:= \\max\\{y: y \\in \\Zz \\text{ and } y \\leq x\\}, \\text{i.e., the greatest integer less than or equal to $x$ (the {\\bf floor} of $x$),}\\\\\n\\lceil x \\rceil &:= \\min\\{y: y \\in \\Zz \\text{ and } y \\geq x\\}, \\text{i.e., the least integer greater than or equal to $x$ (the {\\bf ceiling} of $x$).}\n\\end{flalign*}\n\n\\begin{example}[Floors and ceilings]\n\\[\n\\lfloor 1 \\rfloor = 1, \\quad \\lceil 1 \\rceil = 1, \\quad \\lfloor 17.8 \\rfloor = 17, \\quad   \\lfloor -17.8 \\rfloor = -18, \\quad \\lceil \\sqrt{2} \\rceil = 2, \\quad \\lfloor \\pi \\rfloor = 3, \\quad \\lceil \\frac{1}{10^{100}} \\rceil = 1.\n\\]\n\\end{example}\n\n\\begin{labwork}[Floors and ceilings in \\Matlab]\\label{LW:FloorCeil}  We can use \\Matlab functions {\\tt floor} and {\\tt ceil} to compute $\\lfloor x \\rfloor$ and $\\lceil x \\rceil$, respectively.  Also, the argument  $x$ to these functions can be an array.\n\\begin{VrbM}\n>> sqrt(2) % the square root of 2 is\nans =    1.4142\n>> ceil(sqrt(2)) % ceiling of square root of 2\nans =     2\n>> floor(-17.8) % floor of -17.8\nans =   -18\n>> ceil([1 sqrt(2) pi -17.8 1/(10^100)]) %the ceiling of each element of an array\nans =     1     2     4   -17     1\n>> floor([1 sqrt(2) pi -17.8 1/(10^100)]) % the floor of each element of an array\nans =     1     1     3   -18     0\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{classwork}[Relations between floors and ceilings]\nConvince yourself of the following formulae.  Use examples, plots and/or formal arguments. \n\\begin{flalign*}\n\\lceil x \\rceil &= \\lfloor x \\rfloor \\iff x \\in \\Zz \\\\\n\\lceil x \\rceil &= \\lfloor x \\rfloor + 1 \\iff x \\notin \\Zz \\\\\n\\lfloor -x \\rfloor &= - \\lceil x \\rceil \\\\\nx-1 < \\lfloor x \\rfloor \\leq x & \\leq \\lceil x \\rceil < x+1\n\\end{flalign*}\n\\end{classwork}\n\nLet us define modular arithmetic next.  Suppose $x$ and $y$ are any real numbers, i.e.~$x,y \\in \\Rz$, we define the binary operation called ``$x \\mod y$'' as:\n\\[\nx \\mod y := \n\\begin{cases}\nx - y \\lfloor x/y \\rfloor & \\text{if $y \\neq 0$} \\\\\nx  & \\text{if $y = 0$} \n\\end{cases}\n\\]\n%} % end of remove\n", "meta": {"hexsha": "8ca7437b4989ec9377c149e291f148f646e048ec", "size": 72722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/IntroPrelims.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/IntroPrelims.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/IntroPrelims.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": 49.4707482993, "max_line_length": 1150, "alphanum_fraction": 0.648579522, "num_tokens": 25735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.917302657890151, "lm_q1q2_score": 0.6761971418647114}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{Connected types and maps}\n\n\\begin{defn}\nA type $A$ is said to be $n$-connected if $\\trunc{n}{A}$ is contractible.\nIf $A$ is $0$-connected we also say that $A$ is \\define{(path) connected},\nand if $A$ is $1$-connected we also say that $A$ is \\define{simply connected}.\n\\end{defn}\n\n\\begin{thm}\nLet $f:A\\to B$ be a map. The following are equivalent:\n\\begin{enumerate}\n\\item The map $f$ is \\define{$n$-connected}, i.e. the fibers of $f$ are $n$-connected types.\n\\item The map $f$ is \\define{left orthogonal} with respect to every $n$-truncated map $g:X\\to Y$, i.e. the square\n\\begin{equation*}\n\\begin{tikzcd}\nX^B \\arrow[r,\"\\blank\\circ f\"] \\arrow[d,swap,\"g\\circ \\blank\"] & X^A \\arrow[d,\"g\\circ\\blank\"] \\\\\nY^B \\arrow[r,swap,\"\\blank\\circ f\"] & Y^A\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\item For each $i\\leq n$, the map $f$ induces an isomorphism\n\\begin{equation*}\n\\pi_i(f):\\pi_i(A)\\to\\pi_i(B)\n\\end{equation*}\nof homotopy groups, and \n\\begin{equation*}\n\\pi_{n+1}(f):\\pi_{n+1}(A)\\to\\pi_{n+1}(B)\n\\end{equation*}\nis surjective.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{thm}\nConsider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\nThe following are equivalent:\n\\begin{enumerate}\n\\item The map $A\\to X\\times_Y B$ is $n$-connected. In this case the square is called \\define{$n$-cartesian}.\n\\item For each $x:X$ the map\n\\begin{equation*}\n\\fib{f}{x}\\to \\fib{g}{f(x)}\n\\end{equation*}\nis $n$-connected.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{thm}\nIf $X$ is $m$-connected and $Y$ is $n$-connected, then $\\join{X}{Y}$ is $(m+n+2)$-connected. \n\\end{thm}\n\n\\begin{thm}\nConsider a pullback square\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\nA \\arrow[r] & X.\n\\end{tikzcd}\n\\end{equation*}\nIf the maps $A\\to X$ and $B\\to X$ are $m$- and $n$-connected, respectively, then the map $A\\sqcup^C B\\to X$ is $(m+n+2)$-connected.\n\\end{thm}\n\n\\begin{thm}\n  The connected maps contain the equivalences, are closed under coproducts, pushouts, retracts, and transfinite compositions.\n\\end{thm}\n\n\\begin{exercises}\n\\item Show that a pointed $X$ is $n$-connected precisely when $\\pi_k(X)=0$ for each $k\\leq n$.\n\\item Show that retracts of $n$-connected types are again $n$-connected.\n\\item Let $f:A\\to_\\ast B$ be a pointed map between pointed $n$-connected types, for $n\\geq -1$. Show that the following are equivalent:\n\\begin{enumerate}\n\\item $f$ is an equivalence.\n\\item $\\loopspace[n+1]{f}$ is an equivalence. \n\\end{enumerate}\n\\item Let $f:A\\to B$ be a surjective map, and let $g:A\\to C$ be any map. Show that if there is a unique extension\n\\begin{equation*}\n\\begin{tikzcd}\n\\fib{f}{f(a)} \\arrow[r,\"g\\circ\\pi_1\"] \\arrow[d] & C \\\\\n\\unit \\arrow[ur,densely dotted]\n\\end{tikzcd}\n\\end{equation*}\nfor any $a:A$, then $g$ extends uniquely along $f$.\n\\item Consider a span $A \\leftarrow S \\rightarrow B$, in which the map $S\\to A$ is $n$-connected. Show that the map $\\inr : B\\to A\\sqcup^S B$ is again $n$-connected.\n\\item Show that if\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\nis a $k$-cocartesian, then the map $\\mathsf{cofib}(f)\\to \\mathsf{cofib}(g)$ is $k$-connected.\n\\item Consider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\n\\begin{subexenum}\n\\item Show that if the square is $n$-cartesian and $g$ is $n$-connected, then so is $f$.\n\\item Show that if $f$ is $n$-connected and $g$ is $(n+1)$-connected, then the square is $n$-cartesian. \n\\end{subexenum}\n\\item Show that any sequential colimit of $n$-connected types is again $n$-connected.\n\\item Consider a pushout square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\nShow that if $f$ is $n$-connected, then $g$ is $n$-connected.\n\\end{exercises}\n", "meta": {"hexsha": "85ee3526e7d73fecbc611f55a63a55fcf37fb88b", "size": 4000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/connected.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/connected.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/connected.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": 33.6134453782, "max_line_length": 165, "alphanum_fraction": 0.675, "num_tokens": 1506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.6761652552054311}}
{"text": "\\section{Optimisation \\& sampling methods}\n\\label{sec:optimisation}\nIn this work, computational modelling methods have been applied to important scattering problems.\nThe aim of many modelling problems is to optimise a series of parameters such that a minimum in some parameter-dependent metric is found.\nWhile, in other circumstances, the aim is to sample the parametric search-space of a particular problem.\nThe problem of parameter optimisation and sampling is a massive area of mathematics and computer science and is it not possible to introduce the whole field.\nTherefore, I will introduce two optimisation methods and two sampling methods that are applied within this work.\n\nBoth optimisation algorithms in this work are population-based, making use of a population of candidate solutions.\nThese populations of candidate solutions often have knowledge of the state of each other through some interaction method.\nThe interaction method is often used to characterise the algorithms, into evolutionary algorithms and swarm intelligence algorithms.\\autocite{wu_ensemble_2019}\nThese population methods are usually more efficient at finding the global minimum for a given search space, than a single candidate method.\n\n\\subsection{Differential evolution}\n\\label{sec:de}\nDifferential evolution\\footnote{DE.} is a common, iterative optimisation algorithm, that was first applied to the analysis of reflectometry and diffraction data by Wormington \\emph{et al.}\\autocite{wormington_characterization_1999}\nSince then, it has proven very popular for the optimisation of reflectometry data and is included in many common analysis programs.\\autocite{bjorck_fitting_2011,bjorck_genx_2007,nelson_co-refinement_2006,nelson_refnx_2019,ott_simulreflec_nodate,kienzle_ncnr_nodate}\nThe DE algorithm is designed to more ably determine the global minimum of a particular function.\\autocite{storn_differential_1997}\n\nDE is an example of a genetic algorithm, one that is designed to mimic the evolution processes observed in biology.\\autocite{holland_adaptation_1992}\nThe method consists of two vectors, the parent population, $\\mathbf{p}$, the offspring population, $\\mathbf{o}$.\nThese vectors are of a dimension $(i\\times j)$, where $i$ is the number of variables being optimised and $j$ is the number of candidate solutions being used.\nThe offspring population vector is created through some trial methods.\\footnote{Many of these exist however discussion will be limited to a simple classical trial method, details of other methods may be found in \\cite{bjorck_fitting_20112}.}\n\nA classical trial method consists of two stages, mutation and recombination.\nThe mutation stage involves performing some mutation on the parent population to create a mutant vector, $\\mathbf{m}$, analogous to the mutation in biological evolutionary theory.\nThe magnitude of the mutation is dependent on the mutation constant, $k_m$,\n%\n\\begin{equation}\n\\mathbf{m}_{i,j}= b_{i} + k_m(\\mathbf{p}_{i,R1} - \\mathbf{p}_{i,R2}),\n\\end{equation}\n%\nwhere $b_{i}$ is the best candidate solution in the parent population, and $\\mathbf{p}_{i,R1}$ and $\\mathbf{p}_{i,R2}$ are randomly choosen members of the parent population.\nThe mutation constant can be considered as a control variable for the size of the search radius, with a large $k_m$ corresponding to a larger search radius.\n\nThe recombination step creates the offspring population vector by taking a sample from either the parent population or mutant vectors with some frequency, which depends on the recombination constant, $k_r$,\n%\n\\begin{equation}\n    \\mathbf{o}_{i,j} =\n  \\begin{cases}\n    \\mathbf{m}_{i,j}, & \\text{where}\\ X < k_r \\\\\n    \\mathbf{p}_{i,j}, & \\text{otherwise}\n  \\end{cases}\n\\end{equation}\n%\nwhere, $X\\sim U[0, 1)$.\nThe recombination constant controls the progress of the algorithm as it impacts the frequency with which mutation is introduced into the offspring population vector.\n\nThe final stage is to compare the offspring and parent population vectors, in the selection stage to create the new parent population for the next iteration.\nThe selection stage comprises of using some figure of merit, $\\zeta$, to choose between the subunit from the offspring or parent population vector.\n%\n\\begin{equation}\n    \\mathbf{p}_{*,j} \\leftarrow\n    \\begin{cases}\n        \\mathbf{o}_{*,j}, & \\text{where}\\ \\zeta_{\\mathbf{o}_{*,j}} < \\zeta_{\\mathbf{p}_{*,j}} \\\\\n        \\mathbf{p}_{*,j}, & \\text{otherwise}\n    \\end{cases}\n\\end{equation}\n%\nwhere, the $*$ notation indicates all objects in the given population, and $\\zeta_{\\mathbf{o}_{*,j}}$ and $\\zeta_{\\mathbf{p}_{*,j}}$ are the figures of merit for the offspring and population candidate solutions respectively.\nIn our example, that figure of merit may be the agreement between some experimental data and our model, or for the example in Figure~\\ref{fig:diff_evo} it is the value of the Ackley function,\\autocite{ackley_connectionist_1987} which is being minimised.\nThe Ackley function is a common function used for assessing the utility of global optimisation functions, and has the following form in the two-dimensional case, \n%\n\\begin{equation}\n\\begin{aligned}\nf(x,y) & = -a \\exp{\\big[-b\\sqrt{0.5(x^2 + y^2)}\\big]} \\\\\n & - \\exp{\\big[0.5(\\cos{cx} + \\cos{cy})\\big]} + e + a,\n\\end{aligned}\n\\end{equation}\n%\nwhere, $a$, $b$, and $c$ are constants defined by the user, and $e$ is the base of the natural logarithm. \n%\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=\\textwidth]{theory/diff_evo}\n    \\caption{An example of a DE algorithm as applied to an Ackley function, where $a=20$, $b=0.2$, and $c=2\\pi$. The mutation and recombination constant in this implementation are both $0.5$. Each different coloured line represents a different candidate solution. The optimisation was stopped after $100$ iterations had run.}\n    \\label{fig:diff_evo}\n\\end{figure}\n%\n\nIt is noted that it is often the case,\\footnote{In particular for the optimisation of experimental data.} that there should be some bounds applied to the variables within the populations.\nHowever, the DE algorithm may disregard these bounds due to the nature of the mutation step.\nTherefore, it is common in DE algorithms, where bounds must be set, that if the search space moves outside that expected it is necessary to reinitialise the parameter.\nAn implementation of the DE algorithm is given programmatically in Code Block~\\ref{cb:diff_evo},\\footnote{Additional Code Blocks showing the mutation, recombination, selection steps may be found in Appendix~\\ref{diff_evo_app}.} where this reinitialisation is achieved by obtaining a new random number within the given bounds.\n%\n\\begin{listing}[b]\n    \\forceversofloat    \n    \\centering\n    \\caption{An example of a simple implementation for a DE algorithm as described in \\cite{bjorck_fitting_20112}. The input variables are \\texttt{population} which is an array of floats containing the initial parent population, \\texttt{f} which is the figure of merit function to be minimised, \\texttt{km} which is the mutation constant, \\texttt{kr} which is the recombination constant, \\texttt{bounds} which is an array of floats giving the minimum and maximum values for the variables, and \\texttt{max\\_iter} which is the maximum number of iterations that should be performed. This will return \\texttt{history} which is a history of the variables that are being fit during the DE algorithm.}\n    \\lstinputlisting[nolol]{reports/code_blocks/diff_evo.py}\n    \\label{cb:diff_evo}\n\\end{listing}\n%\n\n\\subsection{Particle swarm}\n\\label{sec:partswarm}\nParticle swarm optimisation\\footnote{PSO.} is a type of swarm intelligence population-based optimisation method.\nThis optimisation method was originally developed by Kennedy, Eberhart, and Shi.\\sidecite[the initial purpose of the algorithm was to simulate social organisms such as bird flocks]{kennedy_particle_1995,shi_modified_1998}\nParticle swarm methods are particularly suitable for the optimisation, and sampling, of parametric search-spaces with a large number of similar minima.\nTherefore, I believe that it will be useful for the study of the self-assembly of soft matter materials.\\footnote{This is the focus of Chapter~\\ref{smallangle}.}\n\nThese methods consist of a population vector, similar to that described for the DE, that moves around the parametric search-space.\nThe motions of these ``particles'' are influenced by the positions of the other particles in the vector.\\autocite{poli_analysis_2008}\nIt is anticipated that this will lead the swarm to optimise the function under investigation.\n\nParticles in the swarm are under the influence of two elastic forces.\nThe first attracts the particle to the best location in the search space that the particular particle has found, while the other attracts the particle to the best search-space location found by any particle of the swarm.\nThe magnitudes of these forces are randomised but modulated by a pair of acceleration coefficients; $\\psi_p$ that influences the attraction towards the personal best location and $\\psi_g$ that influences the attraction to the global best location.\nThe position of a particle changes between iterations of the algorithm based on the following relation,\n%\n\\begin{equation}\n\\mathbf{p}_{*,j} \\leftarrow \\mathbf{p}_{*,j} + \\mathbf{v}_{*,j},\n\\end{equation}\n%\nwhere, $\\mathbf{p}_{*,j}$ is the position of the particle, and $\\mathbf{v}_{*,j}$ is the velocity of the particle.\nThis velocity is determined as shown below,\n%\n\\begin{equation}\n\\mathbf{v}_{*,j} \\leftarrow \\omega\\mathbf{v}_{*,j} + \\psi_gR1(\\mathbf{g}_{*} - \\mathbf{p}_{*,j}) + \\psi_pR2(\\mathbf{s}_{*,j} - \\mathbf{p}_{*,j}),\n\\end{equation}\n%\nwhere, $\\omega$ a constant known as the interia weight, $R1\\sim U[0, 1)$ and $R2\\sim U[0, 1)$ are random numbers, $\\mathbf{g}_{*}$ is the best position occupied by any particle in the swarm and $\\mathbf{s}_{*,j}$ is the personal best for the particle $j$.\n\nFigure~\\ref{fig:part_swarm} shows an example of the PSO in action, applied to the Ackley function.\\autocite{ackley_connectionist_1987}\nCode Block~\\ref{cb:part_swarm} shows a functional programmatic implementation of a PSO algorithm.\n%\n\\begin{figure}[t]\n    \\forcerectofloat\n    \\centering\n    \\includegraphics[width=\\textwidth]{theory/part_swarm}\n    \\caption{An example of a PSO as applied to an Ackley function, where $a=20$, $b=0.2$, and $c=2\\pi$. For the particle swarm, the following parameters were used $\\omega=0.9$, $\\psi_g=0.05$, and $\\psi_p=0.05$. Each different coloured line represents a different candidate solution. The optimisation was stopped after \\num{100} iterations had run.}\n    \\label{fig:part_swarm}\n\\end{figure}\n%\n\\begin{listing}[t]\n    \\centering\n    \\caption{An example of the PSO algorithm from \\cite{poli_analysis_2008}. The input variables are \\texttt{position} which is the initial position vector, \\texttt{f} which is the figure of merit function to be minimised, \\texttt{omega} which is the interia weight, \\texttt{psig} which is the global acceleration constant, \\texttt{psip} which is the personal acceleration constant, and the \\texttt{max\\_iter} which is the maximum number of iterations that should be performed. This will return the \\texttt{history} which is a history of the variables that are being fit during the PSO.}\n    \\lstinputlisting[nolol]{reports/code_blocks/part_swarm.py}\n    \\label{cb:part_swarm}\n\\end{listing}\n%\n\n\\subsection{Markov chain Monte-Carlo}\n\\label{sec:mcmc}\nMarkov chain Monte Carlo\\sidenote[][-2\\baselineskip]{Abbreviated to MCMC.} is a sampling methodology, derived from direct sampling Monte-Carlo.\\sidecite<-2\\baselineskip>{krauth_statistical_2006}\nThe aim of an MCMC algorithm is to sample a probability distribution, when parameters are described in terms of their degree of probability.\\autocite{sivia_data_2006}\nSimilar to molecular dynamics,\\footnote{MD.} in practical terms, MCMC should not be used on a system that is not already optimised, as its purpose is probability distribution sampling rather than minimisation.\nGenerally, the approach would be to optimise using, for example, one of the approaches described above, then to use MCMC or MD to sample the appropriate search-space.\nFor example, in this work MCMC is used following the optimisation of a reflectometry model using a DE algorithm, to quantify the inverse uncertainties of the model.\\footnote{This is the name given to the uncertainties in the parameters fitted in the modelling process.}\nIn addition to being able to give information about the inverse uncertainties, MCMC also offers a more complete understanding of the correlations present between the different parameters,\\autocite{gilks_markov_1995} as the interactions between the parameter variation has been quantified.\n\nThe aim of MCMC is to only sample configurations of a given function that are within the experimental uncertainty.\nFigure~\\ref{fig:mcmc} shows an example of the possible output that may be obtained from the application of an MCMC sampling method.\nThis was generated using a Metropolis-Hastings MCMC algorithm,\\autocite{metropolis_equation_1953,hastings_monte_1970} shown in Code Block~\\ref{cb:mcmc}.\nInitially, a Levenberg–Marquardt algorithm\\autocite{levenberg_method_1944,marquardt_algorithm_1963} was used to optimise the positions and integral of the two Gaussian functions that make up the data.\nThe MCMC was used to sample the values that were within the experimental uncertainty.\n%\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=\\textwidth]{theory/mcmc}\n    \\caption{An example of a four variable (two nearby Gaussian functions of different sizes with added random noise and some fractional uncertainty) problem probed using a MCMC method, using values of $a=0.1$, $\\theta_1$ and $\\theta_2$ correspond to the integral of the Gaussian function, while $\\theta_3$ and $\\theta_4$ indicate their positions; (a)-(d) histograms of the probability distribution function for each of the varibles, and (e) the data (blue circles), the optimised solution (orange line), and a series of probable solutions (green lines) showing the variability present in the data uncertainty.}\n    \\label{fig:mcmc}\n\\end{figure}\n%\n\\begin{listing}[b]\n    \\forceversofloat\n    \\centering\n    \\caption{An example of the Metropolis-Hastings MCMC algorithm from \\cite{metropolis_equation_1953,hastings_monte_1970}. The input variables are \\texttt{theta} which is an array of floats giving the initial values for the variables, \\texttt{f} which is the figure of merit function to be minimised, \\texttt{a} which is the step size for the changes, \\texttt{data} which is the experimental data, \\texttt{iterations} which is the number of accepted iterations to obtain, and \\texttt{nburn} which is the number of accepted iteractions to ignore in the burn-in phase. This will return the \\texttt{history} which is a history of the variables that are being fit during the PSO.}\n    \\lstinputlisting[nolol]{reports/code_blocks/mcmc.py}\n    \\label{cb:mcmc}\n\\end{listing}\n%\n\nOnce an optimised solution, $\\theta$, is obtained, the figure of metric is calculated, in Code Block~\\ref{cb:mcmc} this is the agreement between the model and the experimental data, $\\chi^2$, where,\n%\n\\begin{equation}\n\\chi^2 = \\sum\\frac{(y_{\\text{exp}} - y_{\\text{calc}})^2}{\\text{d}y_{\\text{exp}}},\n\\end{equation}\n%\nand $y_{\\text{exp}}$ is the experimental data, and $\\text{d}y_{\\text{exp}}$ the uncertainty in the experimental data, while $y_{\\text{calc}}$ is the model solution.\nSome random pertubation is then applied to the optimised solution,\n%\n\\begin{equation}\n\\Theta = \\theta + aR,\n\\end{equation}\n%\nwhere $R\\sim N(0, 1)$ and $a$ is the step size.\nA new $\\chi^2$ is found for $\\Theta$, and the probablity that this transition will occur is found,\n%\n\\begin{equation}\np = \\exp{\\bigg(\\frac{-\\chi^2(\\Theta) + \\chi^2(\\theta)}{2}\\bigg)}.\n\\end{equation}\n%\nThis probability is then compared with a random number $n\\sim~U[0, 1)$, and if $n$ is less than the probability, the new solution is stored,\n%\n\\begin{equation}\n\\theta \\leftarrow \\Theta.\n\\end{equation}\n%\nThis process is repeated until some desired number of samples has been obtained.\nIt should be noted that in the event on a poorly optimised initial value of $\\theta$, it may be necessary to ``burn''\\footnote{This means to ignore.} the first series of solutions while the MCMC algorithm settles into the search-space.\n\n\\subsection{Molecular dynamics}\n\\label{sec:md}\nSection \\ref{sec:classical} introduced classical potential models as a method for the evalution of the interaction energy of a given chemical system.\nAny of the optimisation methods discussed above could be used alongside these classical potential models to find an energy minimum structure for the system or to sample the potential energy landscape.\nHowever, it is often the case that a thermodynamically relevant structure is of interest at a given temperature.\nThis is where MD simulations are a useful and important tool.\n\nThe aim of an MD simulation is to probe the positions, velocities, and accelerations on each of the atoms, or coarse-grained particles, as a simulation progresses.\nThe acceleration on a given particle, $\\mathbf{a}$ is defined by the force on that particle, $\\mathbf{f}$, in agreement with Newton's second law of motion,\n%\n\\begin{equation}\n\\mathbf{f} = m\\mathbf{a},\n\\label{equ:forcevec}\n\\end{equation}\n%\nwhere, $m$ is the mass of the particle.\nIn order to determine the acceleration on the particle, it is necessary to know the force on that particle.\nThe force, $f$, is a function of the potential energy, $E$, as found from a classical potential, of that atom,\n%\n\\begin{equation}\nf(r) = \\frac{-\\delta E_{\\text{total}}(r)}{\\delta r},\n\\label{equ:forcesca}\n\\end{equation}\n%\nwhere, $r$ is the configuration of the atoms.\\footnote{The force is the negative of the first derivative of the energy with respect to the atomic configuration.}\nThe force found from Equation~\\ref{equ:forcesca} is a scalar, however, the force vector is present in Equation~\\ref{equ:forcevec}.\nTo determine the force in a given direction, it is necessary to find the product of the force, $f$, and the unit vector in that direction,\n%\n\\begin{equation}\n\\mathbf{f}_x = f\\hat{\\mathbf{r}}_x, \\;\\;\\;\\text{where}\\;\\hat{\\mathbf{r}}_x = \\frac{r_x}{|\\mathbf{r}|},\n\\end{equation}\n%\nwhere $r_x$ is the atomic configuration in the $x$-dimension, and $|\\mathbf{r}|$ is the magnitude of the atomic configuration vector.\n\nThe potential model, which is defined for a given system, allows for the calculation of the acceleration on each particle in that system.\nThe next step is to use this acceleration to iterate through the trajectory of our system.\nThis is achieved by applying Newtonian equations of motion, for example in the Velocity-Verlet algorithm.\\autocite{swope_computer_1982}\n%\n\\begin{equation}\n\\mathbf{x}(t + \\Delta t) = \\mathbf{x}(t) + \\mathbf{v}(t)\\Delta t + \\frac{1}{2}\\mathbf{a}(t)\\Delta t^2,\n\\label{equ:vv1}\n\\end{equation}\n\\begin{equation}\n\\mathbf{v}(t + \\Delta t) = \\mathbf{v}(t) + \\frac{1}{2}\\big[\\mathbf{a}(t) + \\mathbf{a}(t+\\Delta t)\\big]\\Delta t,\n\\label{equ:vv2}\n\\end{equation}\n%\nwhere, $\\mathbf{x}$ is the position the particle $\\mathbf{v}$ is the particle's velocity, and $\\mathbf{a}$ is the particle's acceleration, while $t$ is current simulation time and $\\Delta t$ is the timestep.\nThese equations constitute the Velocity-Verlet algorithm,\n%\n\\begin{enumerate}\n\\item calculate the force,and therefore the acceleration, on each particle,\\footnote{Using Equations~\\protect\\ref{equ:forcevec} \\& \\protect\\ref{equ:forcesca}.}\n\\item find the position of the particle after some timestep,\\footnote{Using Equation~\\protect\\ref{equ:vv1}.}\n\\item determine the new velocity for each particle, based on the average acceleration at the current and new positions,\\footnote{Using Equation~\\protect\\ref{equ:vv2}.}\n\\item overwrite the old acceleration values with the new ones,\n\\item go to 1.\n\\end{enumerate}\n%\nFollowing an equilibration period, this algorithm may be iterated as many times as is required to obtain sufficient statistics for the measurement quantity of interest, e.g. particle positions for structural techniques such as elastic scattering.\n\nThe above analytical process is known as the integration step, and the Velocity-Verlet is the integrator.\nIf the size of the timestep $\\Delta t$ is too large, the step size for a given iteration will not be accurate, as the forces on the atoms will change too significantly during it.\nTherefore, the values of the timestep are usually on the order of \\SI{10e-15}{\\second}.\\footnote{femtoseconds.}\nThis means that in order to simulate a single nanosecond of ``real-time'' MD, the integrator must be solved one million times.\nThis can be slow for very large systems, leading to an interest in coarse-grained simulations that result in fewer particles to determine the forces for, but also enable to use of larger timesteps,\\sidecite[so fewer, faster integration steps must be solved]{rudd_coarse-grained_1998,brini_systematic_2013} for example, the use of a MARTINI potential model allows for an up to twenty times increase in the timestep compared to an all-atom model.\n\nThe above discussion ignored two aspects that are necessary to run an MD simulation, both of which as associated with the original configuration of the system; the original particle positions and velocities.\nThe particle positions are usually taken from some library, for example for the simulation of a protein, often the protein data bank\\autocite{noauthor_rcsb_nodate} is a useful resource.\nSmall molecules may be configured by hand using graphical programs such as Jmol.\\autocite{noauthor_jmol_nodate}\nThese small molecules may be built into complex, multicomponent structures using software such as the Packmol package.\\autocite{martinez_packmol_2009}\nThe importance of this initial structure cannot be overstated, for example, if the initial structure in an MD simulation is unrepresentative of the equilibrium structure, it may take a large amount of simulation time before the equilibrium structure is obtained.\\footnote{This can be much longer than could be reasonably simulated.}\n\nThe initial particle velocities are obtained in a much more general fashion.\nThey are selected randomly, and then scaled such that the kinetic energy, $E_k$, of the system agrees with a defined temperature, $T$,\n%\n\\begin{equation}\nE_k = \\sum_{i=1}^N{\\frac{m_i|\\mathbf{v}_i|^2}{2}} = \\frac{3}{2}Nk_BT,\n\\label{equ:ek}\n\\end{equation}\n%\nwhere, $m_i$ and $\\mathbf{v}_i$ are the masses and velocities of the particles, $N$ is the number of particles, and $k_B$ is the Boltzmann constant.\n\nThe above algorithm details a simulation that makes use of an NVE ensemble.\\footnote{A simulation where the number of particles (N), the volume of the system (V), the energy of the system (E) are all kept constant.}\nHowever, this is not the only simulation ensemble that is available, within this work two other ensembles have been used extensively,\n%\n\\begin{itemize}\n\\item the NVT (canonical) ensemble; this is similar to the NVE ensemble except the simulation temperature is controlled via a thermostat,\n\\item the NPT (isothermal-isobaric); this ensemble is similar to the NVT ensemble, however, the system volume is allowed to vary while the overall system pressure is held constant using a barostat.\n\\end{itemize}\n%\nThermostating involves controlling the kinetic energy of the particles\\footnote{Using Equation~\\ref{equ:ek}.} such that the simulation temperature is kept at a predefined value.\nThere are a variety of methods for thermostating a MD simulation, such as the Andersen, Nos\\'{e}-Hoover, or Berendsen methods.\\autocite{andersen_molecular_1980,nose_unified_1984,berendsen_molecular_1984,hoover_canonical_1985}\nHowever, the most straightforward to describe, and that implemented in the \\texttt{pylj} software,\\sidecite[discussed in detail in Chapter \\ref{teaching}]{mccluskey_pylj_20183,mccluskey_arm61/pylj_20182} is a velocity rescaling.\\autocite{bussi_canonical_2007}\nThis is where the velocities for a random subset of the particles, $\\mathbf{v}_i$ are adapted based on the following relation,\n%\n\\begin{equation}\n\\mathbf{v}_i \\leftarrow \\mathbf{v}_i \\sqrt{\\frac{T_{\\text{target}}}{\\bar{T}}}\n\\end{equation}\n%\nwhere, $T_{\\text{target}}$ is the target temperature, and $\\bar{T}$ is the average simulation temperature.\n\nThe use of a barostat to control the simulation pressure usually involves varying the simulation cell parameters and the distances between the particles.\nIn a similar way to thermostating, where the simulation dimensions are scaled by a value in an effort to control the pressure.\nThe barostating methods are similar to the thermostating methods with Andersen, Nos\\'{e}-Hoover, and Berendsen methods.\nHowever, there is also the Parrinello-Rahman barostat which allows for independent control of the different cell dimensions giving control of stress in addition to pressure.\\autocite{parrinello_polymorphic_1981}\n\nThese optimisation and sampling methods were used in a variety of different applications within this work, firstly DE optimisation and MCMC sampling are used in Chapter~\\ref{reflectometry1} in the study of a chemically-consistent modelling approach to X-ray and neutron reflectometry analysis.\nMD simulation is investigated as a possible tool to assist in the analysis of reflectometry in Chapter~\\ref{reflectometry2}.\nFinally, the PSO is applied for the efficient determination of a micelle structure for fitting SAS data in Chapter~\\ref{smallangle}.\n", "meta": {"hexsha": "cc56ab9a50e9c03e0dfd344acd2f82bb07cac2ae", "size": 25470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/chapters/theory/simulation.tex", "max_stars_repo_name": "arm61/thesis", "max_stars_repo_head_hexsha": "4c76e837b1041472a5522427de0069a5a28d40c9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-04T20:53:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-01T06:25:20.000Z", "max_issues_repo_path": "reports/chapters/theory/simulation.tex", "max_issues_repo_name": "arm61/thesis", "max_issues_repo_head_hexsha": "4c76e837b1041472a5522427de0069a5a28d40c9", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-04T17:11:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T17:11:33.000Z", "max_forks_repo_path": "reports/chapters/theory/simulation.tex", "max_forks_repo_name": "arm61/thesis", "max_forks_repo_head_hexsha": "4c76e837b1041472a5522427de0069a5a28d40c9", "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.6346153846, "max_line_length": 694, "alphanum_fraction": 0.7802120141, "num_tokens": 6395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6761652509096051}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\chapter{Model selection}\n\n\\marginpar{Monday\\\\ 2020-12-14, \\\\ compiled \\\\ \\today}\n\nThe Bayes factor between two models \\(M'\\) and \\(M\\), depending on parameters \\(\\theta'\\) and \\(\\theta \\) respectively, having observed the data \\(x\\), is \n%\n\\begin{align}\nB = \\frac{\\int \\dd{\\theta '} \\mathbb{P}(x | \\theta ' M') \\mathbb{P}(\\theta ' | M')}{\\int \\dd{\\theta } \\mathbb{P}(x | \\theta  M) \\mathbb{P}(\\theta  | M)}\n\\,,\n\\end{align}\n%\nwhich, if the parameters are uniformly distributed in some range \\(\\Delta \\theta _i\\), we will have \n%\n\\begin{align}\nB = \\frac{\\int \\dd{\\theta '} \\mathbb{P}(x | \\theta ' | M')}{\\int \\dd{\\theta } \\mathbb{P}(x | \\theta , M)} \\frac{\\Delta \\theta _1 \\dots \\Delta \\theta _n}{\\Delta \\theta '_1 \\dots \\Delta \\theta '_{n'}}\n\\,.\n\\end{align}\n\nThis can account for having nested models, in which \\(n < n'\\) and the prime parameters are a superset of the non-prime ones.\nThe ratio of the likelihoods will favor the more general model (with \\(\\theta '\\)), while the ratio of the \\(\\Delta \\theta \\) will reduce to \\(\\Delta \\theta'_{n+1} \\dots \\Delta \\theta '_{n'}\\), which will favor the simpler model. \n\nIn general computing the integrals must be done numerically, typically through MCMC.\nWe will instead take the analytic approach. \nWe consider the likelihoods as being MVNs around their maxima: \n%\n\\begin{align}\n\\mathcal{L}^{(i)} = \\mathcal{L}_0^{(i)} \\exp[\n    \\qty(\\vec{\\theta}_i - \\vec{\\theta}_i^{ML})^{\\top}\n    \\qty(\\nabla \\nabla \\chi^2_i)\n    \\qty(\\vec{\\theta}_i - \\vec{\\theta}_i^{ML})\n]\n\\,.\n\\end{align}\n\nNow, we can calculate the integrals analytically: \n%\n\\begin{align}\n\\int \\dd{\\theta } \\mathcal{L} = (2 \\pi )^{N/2} \\qty(\\det (\\nabla \\nabla \\chi^2))^{-1/2} \\mathcal{L}_0\n\\,,\n\\end{align}\n%\nso the likelihood ratio is just \n%\n\\begin{align}\n\\frac{\\int \\dd{\\theta _1} \\mathcal{L}_1}{\\int \\dd{\\theta _2} \\mathcal{L}_2} = (2 \\pi )^{(N_2 - N_1) / 2 } \\frac{\\mathcal{L_0^{(1)}}}{\\mathcal{L_0}^{(2)}} \\qty[\\frac{\\det (\\nabla \\nabla \\chi^2_{(2)})}{\\det (\\nabla \\nabla \\chi^2_{(2)})}]^{1/2}\n\\,.\n\\end{align}\n\nTherefore, for nested models \n%\n\\begin{align}\nB_{12} = (2 \\pi )^{(N_2 - N_1) / 2 } \\frac{\\mathcal{L_0^{(1)}}}{\\mathcal{L_0}^{(2)}} \\qty[\\frac{\\det (\\nabla \\nabla \\chi^2_{(2)})}{\\det (\\nabla \\nabla \\chi^2_{(2)})}]^{1/2}\n\\Delta \\theta _2^{N_1 +1 } \\dots \\Delta \\theta _2^{N_2 }\n\\,.\n\\end{align}\n\n\\subsection{Savage-Dickey density ratio}\n\nThis is an analytical tool which can be applied as long as we have nested models, with separable priors, and the more complex model only has one extra parameter. \n\nLet us say that the likelihood for the complex model is \\(p_2 (\\vec{x} | \\phi , \\psi )\\), while the likelihood of the simpler model is \\(p_1 (\\vec{x} | \\phi ) = p_2 (\\vec{x} | \\phi , \\psi_{*})\\).\nThe Bayes factor is then \n%\n\\begin{align}\nB_{12}  =\\frac{\\int \\dd{\\phi } p(\\vec{x} | \\phi , \\psi_*) \\pi_1 (\\phi )}{\\int \\dd{\\phi } \\dd{\\psi } p(\\vec{x} | \\phi , \\psi ) \\pi_2 (\\phi , \\psi )}\n\\,.\n\\end{align}\n\nWe call the bottom integral \\(q\\). \nLet us consider \\(p(\\psi_* | \\vec{x})\\): by Bayes' theorem, it is \n%\n\\begin{align}\np(\\psi _* | \\vec{x}) = \\frac{\\int \\dd{\\phi } p(\\vec{x} | \\phi , \\psi_* ) \\pi _2 (\\phi, \\psi_*)}{q} \n\\,,\n\\end{align}\n%\ntherefore \n%\n\\begin{align}\nB_{12} &= p(\\psi _*, \\vec{x}) \\frac{\\int \\dd{\\phi } p(\\vec{x} | \\phi , \\psi_*) \\pi_1 (\\phi )}{p(\\psi _*, \\vec{x}) }  \\\\\n&= \\frac{\\int \\dd{\\phi } p(\\phi, \\psi _* | \\vec{x})}{\\pi_2 (\\psi _*)}\n\\,.\n\\end{align}\n\n\\todo[inline]{Missing some calculation steps}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "d15e203870f9f676b5f34f9051a1db3679fc933f", "size": 3511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostatistics_cosmology/dec14.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/dec14.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/dec14.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": 37.752688172, "max_line_length": 241, "alphanum_fraction": 0.6157789803, "num_tokens": 1318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6761323005482867}}
{"text": "\\section{Introduction}\r\nA Markov chain consists of a state space and a set of probabilities of going from a state to another.\r\nWe can either draw the transition as a directed graph with probability labels, or we can write out the transition matrix, with the $i,j$ entry taken to be the probability of going from state $i$ to state $j$.\r\nFor example, we can take the state space as $\\{1,2,3\\}$ with transition rules drawn as the following graph:\r\n\\begin{center}\r\n    \\begin{tikzpicture}\r\n        \\node[state] at (0,2) (1){$1$};\r\n        \\node[state] at (1.4,0) (2){$2$};\r\n        \\node[state] at (-1.4,0) (3){$3$};\r\n\r\n        \\draw[every loop]\r\n        (1) edge[auto=left] node {$1$} (2)\r\n        (3) edge[auto=left] node {$1/2$} (1)\r\n        (2) edge[loop right] node {$2/3$} (2)\r\n        (3) edge[bend left, auto=left] node {$1/2$} (2)\r\n        (2) edge[bend left, auto=right] node {$1/3$} (3);\r\n    \\end{tikzpicture}\r\n\\end{center}\r\nIt then has transition matrix\r\n$$\\begin{pmatrix}\r\n    &1&\\\\\r\n    &2/3&1/3\\\\\r\n    1/2&1/2&\r\n\\end{pmatrix}$$\r\nObvious we want the sum of each row to be $1$ as you have to transit somewhere (including your current location) from where you were.\\\\\r\nWe can have a more involved example.\r\nConsider the state space $\\{0,\\ldots,6\\}$ with transition rules\r\n\\begin{center}\r\n    \\begin{tikzpicture}\r\n        \\node[state] at (0,-0.5) (0){$0$};\r\n        \\node[state] at (-2,0) (1){$1$};\r\n        \\node[state] at (-4,0) (2){$2$};\r\n        \\node[state] at (-3,2) (3){$3$};\r\n        \\node[state] at (2,0) (4){$4$};\r\n        \\node[state] at (4,0) (5){$5$};\r\n        \\node[state] at (3,2) (6){$6$};\r\n\r\n        \\draw[every loop]\r\n        (0) edge[auto=right] node {$1/5$} (4)\r\n        (4) edge[auto=right] node {$1$} (5)\r\n        (5) edge[auto=right] node {$1$} (6)\r\n        (6) edge[auto=right] node {$1$} (4)\r\n        (0) edge[auto=left] node {$3/5$} (1)\r\n        (1) edge[bend left, auto=left] node {$1$} (2)\r\n        (2) edge[bend left, auto=left] node {$1/3$} (1)\r\n        (2) edge[auto=left] node {$2/3$} (3)\r\n        (3) edge[auto=left] node {$1$} (1)\r\n        (0) edge[loop above] node {$1/5$} (0);\r\n    \\end{tikzpicture}\r\n\\end{center}\r\nThere are many questions we can ask about a Markov chain.\r\nFor example, what is the probability of hitting one node from another eventually?\r\nIn the example above, some are obvious:\r\nThe probability of hitting $6$ eventually from $0$ is $1/5+(1/5)^2+\\cdots=1/4$, and the probability of hitting $3$ eventually from $0$ is actually $1$.\\\\\r\nWe can ask other questions.\r\nFor example, what is the average number of steps to get from $1$ to $3$?\r\nThis turns out to be $3$.\r\nAlso, what is the long-run proportion of time to spend on $2$ if one starts at $1$?\r\nIt is $3/8$ as one can verify.\\\\\r\nThroughout this course, we will attempt to come up with systematic ways to compute these things for a given Markov chain.\\\\\r\nAnother thing to observe is that in this specific example, we can group the states into three groups: $\\{0\\},\\{1,2,3\\}$ and $\\{4,5,6\\}$.\r\nOne can see that we cannot leave a group and go back with positive probability.\r\nWe call these communicating classes of a Markov chain.", "meta": {"hexsha": "eb23deb67d95935f24e7dd5334fb93513df25721", "size": 3145, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/intro.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": "0/intro.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": "0/intro.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": 49.9206349206, "max_line_length": 209, "alphanum_fraction": 0.6073131955, "num_tokens": 1025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6761322950244835}}
{"text": "\\section{Deep Unsupervised Learning}\n\\subsection*{Autoregressive}\nImage $p(\\mathbf{x})=\\Pi_i^{n^2}p(x_i|x_1,\\cdots,x_{i-1})$ \\\\\n\n\\subsection*{Variational Autoencoder}\n$D_{KL}(P\\|Q)=\\sum_i P(i)\\log\\frac{P(i)}{Q(i)}=\\mathbb{E}_i [\\frac{\\log P_i}{\\log Q_i}]$ (0:similar) \\\\\nElbo $\\mathbb{E}_{x\\sim P_{\\mathbb{X}}}[\\mathbb{E}_{z\\sim Q}{\\log P_g(x|z)}-D^{\\mathit{KL}}(Q(z|x)\\|P(z))]$ \\\\\n$Q$ enc. posterior distr., $P(z)$ prior distr. on latent var $z$, $P_g$ likelihood of dec. generated $\\mathbf{x}$ \\\\\nJointly trained: enc. optimize regularizer term, sample $\\mathbf{z}\\sim Q$, feed to dec., produce $\\hat{x}$ to max. reconstruction quality. Both terms diff'able, can use SGD to train end-to-end.", "meta": {"hexsha": "9b45c48616d0e9d52badc16df774aabfc92b3a67", "size": 693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Generative.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": "Generative.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": "Generative.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": 77.0, "max_line_length": 194, "alphanum_fraction": 0.6623376623, "num_tokens": 258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6760462395984068}}
{"text": "\n\\subsection{Lagrangians}\n\nWe have:\n\n\\(S = \\int_a^b \\sqrt {(\\mathbf {\\dot q})^T\\mathbf M\\mathbf {\\dot q}}dt\\)\n\nWe can define:\n\n\\(L=\\sqrt {(\\mathbf {\\dot q})^T\\mathbf M\\mathbf {\\dot q}}\\)\n\nSo we have:\n\n\\(S=\\int_a^b L dt\\)\n\n\\subsection{Principle of stationary action}\n\n\\(\\delta A=0\\)\n\nThat is, the coordinates and their velocities are such that action is stationary.\n\n\\subsection{Euler-Lagrange}\n\nWe have \\(q(t)\\) which makes the action stationary. Consider adding proportion \\(\\epsilon \\) of another function \\(f(t)\\) to \\(q(t)\\).\n\n\\(A’=\\int_{t_0}^{t_1} L[q(t)+\\epsilon f(t), \\dot {q(t)}+\\epsilon f’(t)]dt\\)\n\n\\(\\dfrac{A’-A}{\\epsilon }=\\dfrac{1}{\\epsilon}\\int_{t_0}^{t_1} L[q(t)+\\epsilon f(t), \\dot {q(t)}+\\epsilon f’(t)]-L[q,\\dot q]dt\\)\n\nWe can do a Taylor expansion of \\(A’\\).\n\n\\(A’=\\int_{t_0}^{t_1} L[q(t)+\\epsilon f(t), \\dot {q(t)}+\\epsilon f’(t)]dt\\)\n\n\\(A’=\\int_{t_0}^{t_1} L[q(t),\\dot {q(t)}]+\\epsilon [f\\dfrac{\\delta L}{\\delta q}+f^.\\dfrac{\\delta L}{\\delta \\dot q}]+\\epsilon^2 [...]dt\\)\n\nSo:\n\n\\(\\dfrac{A’-A}{\\epsilon }=\\dfrac{1}{\\epsilon}\\int_{t_0}^{t_1}L[q(t),\\dot {q(t)}]+\\epsilon [f\\dfrac{\\delta L}{\\delta q}+f^.\\dfrac{\\delta L}{\\delta q^.}]+\\epsilon^2 [...]-L[q,\\dot q]dt\\)\n\n\\(\\dfrac{A’-A}{\\epsilon }=\\int_{t_0}^{t_1}[f\\dfrac{\\delta L}{\\delta q}+f^.\\dfrac{\\delta L}{\\delta \\dot {q}}]+\\epsilon [...]dt\\)\n\nWe can now make the left side \\(0\\), by using the definition of stationary action.\n\n\\(\\lim_{\\epsilon \\rightarrow 0} \\dfrac{A’-A}{\\epsilon }=\\int_{t_0}^{t_1}[f\\dfrac{\\delta L}{\\delta q}+f^.\\dfrac{\\delta L}{\\delta \\dot q}]dt\\)\n\n\\(\\int_{t_0}^{t_1}[f\\dfrac{\\delta L}{\\delta q}+f^.\\dfrac{\\delta L}{\\delta \\dot q}]dt=0\\)\n\n\\(\\int_{t_0}^{t_1}[f\\dfrac{\\delta L}{\\delta q}]dt +\\int_{t_0}^{t_1}[f^.\\dfrac{\\delta L}{\\delta \\dot q}]dt=0\\)\n\nNote that\n\n\\(\\int_{t_0}^{t_1}[f^.\\dfrac{\\delta L}{\\delta \\dot q}]dt=[f\\dfrac{\\delta L}{\\delta \\dot q}]_{t_0}^{t_1}-\\int_{t_0}^{t_1}f \\dfrac{d}{dt}\\dfrac{\\delta L}{\\delta \\dot q}dt\\)\n\nWe assume that \\(f(t_0)=f(t_1)=0\\) and so:\n\n\\(\\int_{t_0}^{t_1}[f^.\\dfrac{\\delta L}{\\delta \\dot q}]dt=-\\int_{t_0}^{t_1}f \\dfrac{d}{dt}\\dfrac{\\delta L}{\\delta \\dot q}dt\\)\n\nPlugging this back in we get:\n\n\\(\\int_{t_0}^{t_1}[f\\dfrac{\\delta L}{\\delta q}]-f \\dfrac{d}{dt}\\dfrac{\\delta L}{\\delta \\dot q}dt]=0\\)\n\n\\(\\int_{t_0}^{t_1}f[\\dfrac{\\delta L}{\\delta q}]-\\dfrac{d}{dt}\\dfrac{\\delta L}{\\delta \\dot q}dt]=0\\)\n\nSince this applies to all possible functions we get:\n\n\\(\\dfrac{\\delta L}{\\delta q}=\\dfrac{d}{dt}\\dfrac{\\delta L}{\\delta \\dot q}\\)\n\n\\subsection{Definition: Momentum}\n\n\\(p=\\dfrac{\\delta L}{\\delta \\dot q}\\)\n\n\\subsection{EL v2}\n\\(L=\\sqrt {(\\mathbf {\\dot q})^T\\mathbf M\\mathbf {\\dot q}}\\)\n\n\\(\\dfrac{\\delta L}{\\delta q}- \\dfrac{d}{dt}(\\dfrac{\\delta L}{\\delta \\dot q})=0\\)\n\nWe have\n\n\\(S=\\int_a^b L(q(t), \\dot q(t))dt \\)\n\n\\(\\delta S=\\delta \\int_a^b L(q(t), \\dot q(t))dt \\)\n\n\\(J=\\int_a^b L(t,q(t), \\dot q(t)) dt\\)\n\n\\(J=\\sum_{k=0}^{n-1}\\)\n\n\n\\subsection{EL v3}\n\n\n\\(A=\\sum L(x(t), \\dot x(t)) \\delta t \\)\n\n\\(A=\\sum L(\\dfrac{x(t)+x(t-1)}{2}, \\dfrac{x(t)-x(t-1)}{\\delta t}) \\delta t \\)\n\n \n\n\\(\\dfrac{\\delta }{\\delta x(t)}A = \\sum \\dfrac{\\delta }{\\delta x(t)}L(\\dfrac{x(t)+x(t-1)}{2}, \\dfrac{x(t)-x(t-1)}{\\delta t}) \\delta t \\)\n\n \n\n\\(\\dfrac{\\delta }{\\delta x(t)}A = \\delta t [\\dfrac{\\delta }{\\delta x(t)}L(\\dfrac{x(t)+x(t-1)}{2}, \\dfrac{x(t)-x(t-1)}{\\delta t}) + \\dfrac{\\delta }{\\delta x(t)}L(\\dfrac{x(t+1)+x(t)}{2}, \\dfrac{x(t+1)-x(t)}{\\delta t})]\\)\n\n \n\n\\(\\dfrac{\\delta }{\\delta x(t)}A = \\delta t [\\dfrac{1}{2}L_x +\\dfrac{1}{\\delta t}L_{\\dot x} + \\dfrac{1}{2}L_x -\\dfrac{1}{\\delta t}L_{\\dot x}]\\)\n\n \n\n\\(A=\\int_a^b L(q(t), \\dot q(t)) dt\\)\n\n\\(A=\\sum L(q(t), \\dot q(t)) \\delta t\\)\n\n\\(A=\\sum L(\\dfrac{q(t)+q(t-1)}{2}, \\dfrac{q(t)-q(t-1)}{\\delta t}) \\delta t\\)\n\n\\(\\dfrac{\\delta }{\\delta q_i(t)}A = \\sum \\dfrac{\\delta }{\\delta q_i(t)}L(\\dfrac{q(t)-q(t-1)}{2}, \\dfrac{q(t)-q(t-1)}{\\delta t}) \\delta t\\)\n\n\\(\\dfrac{\\delta }{\\delta q_i(t)}A = \\delta t [\\dfrac{\\delta }{\\delta q_i(t)}L(\\dfrac{q(t)+q(t-1)}{2}, \\dfrac{q(t)-q(t-1)}{\\delta t})+\\dfrac{\\delta }{\\delta q_i(t)}L(\\dfrac{q(t+1)+q(t)}{2}, \\dfrac{q(t+1)-q(t)}{\\delta t})]\\)\n\n \n\n\\(\\dfrac{\\delta }{\\delta q_i(t)}A = \\delta t [\\dfrac{1}{2}L_{q_i}+\\dfrac{1}{\\delta t}L_{\\dot q_i}+\\dfrac{1}{2}L_{q_i}-\\dfrac{1}{\\delta t}L_{\\dot q_i}+\\dfrac{\\delta }{\\delta q_i(t)}L(\\dfrac{q(t+1)+q(t)}{2}, \\dfrac{q(t+1)-q(t)}{\\delta t})]\\)\n\n", "meta": {"hexsha": "0d2d81e9dff05c1fb3376cedc4aeddcff5b7a7de", "size": 4277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/physics/worldlines/03-01-lagrangian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/physics/worldlines/03-01-lagrangian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/physics/worldlines/03-01-lagrangian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7723577236, "max_line_length": 239, "alphanum_fraction": 0.5725976152, "num_tokens": 1910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6760349656474313}}
{"text": "%              %\n%%            %%\n%%% PREAMBLE %%%\n%%            %%\n%              %\n\n% Document class\n\\documentclass[11pt]{beamer}\n\n\\usetheme{Boadilla}\n\\usecolortheme{beaver}\n\\useinnertheme{rectangles}\n\n\\setbeamertemplate{navigation symbols}{}\n\n% Font\n\\usepackage{fontspec}\n\\setmainfont{Latin Modern Roman}\n\n% Language and typography\n\\usepackage{polyglossia}\n\\setdefaultlanguage{english}\n\\setotherlanguage{french}\n\n\\usepackage{csquotes}\n\n\\usepackage{microtype}\n\n% Mathematics\n\\usepackage{mathtools}\n\\usepackage{physics}\n\n% Floats\n\\usepackage{float}\n\\usepackage{booktabs}\n\\usepackage{multicol}\n\n% References\n\\usepackage{cleveref}\n\n\n%              %\n%%            %%\n%%% DOCUMENT %%%\n%%            %%\n%              %\n\n% Information\n\\title{Mathematics}\n\\subtitle{Matrices}\n\\author[A. Quenon]{Alexandre Quenon}\n\n% Text\n\\begin{document}\n% *** Title page *** %\n\\begin{frame}\n\t\\titlepage\n\\end{frame}\n\n\n% *** Contents *** %\n\\begin{frame}\n\t\\frametitle{Overview}\n\t\n\t\\tableofcontents\n\\end{frame}\n\n\n% *** Tutorial *** %\n%-----\n\\section{Useful packages}\n\n\\begin{frame}\n\t\\frametitle{Packages for matrices}\n\n\tSome packages very useful for mathematics and specifically for matrix computations are listed here below:\n\t\\begin{itemize}\n\t\t\\item \\emph{mathtools} which is mainly an upgrade of the very well-known \\emph{amsmath} package (the backbone for mathematics with \\LaTeX{}),\n\t\t\\item \\emph{physics} which provides macros to generate easily matrices with specific patterns.\n\t\\end{itemize}\n\\end{frame}\n\n\n%-----\n\\section{Matrices: principle}\n\n\\begin{frame}\n\t\\frametitle{Matrices: principle}\n\t\\framesubtitle{Types of matrices}\n\t\n\tMatrices can be written by using a \\texttt{matrix}-like environment inside a mathematical equation environment such as the ones presented in B100 tutorial.\n\t\n\tSeveral types of matrices exist.\n\tThey differ with the type of delimiters surrounding the matrix:\n\t\\begin{align*}\n\t\t\\text{\\texttt{matrix}} && \\text{\\texttt{pmatrix}} && \\text{\\texttt{bmatrix}} && \\text{\\texttt{Bmatrix}} \\\\\n\t\t%\n\t\t\\begin{matrix}\n\t\t\tx_{11} & x_{12} \\\\\n\t\t\tx_{21} & x_{22} \\\\\n\t\t\\end{matrix} \n\t\t&&\n\t\t\\begin{pmatrix}\n\t\t\tx_{11} & x_{12} \\\\\n\t\t\tx_{21} & x_{22} \\\\\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{bmatrix}\n\t\t\tx_{11} & x_{12} \\\\\n\t\t\tx_{21} & x_{22} \\\\\n\t\t\\end{bmatrix}\n\t\t&&\n\t\t\\begin{Bmatrix}\n\t\t\tx_{11} & x_{12} \\\\\n\t\t\tx_{21} & x_{22} \\\\\n\t\t\\end{Bmatrix} \\\\\n\t\t%\n\t\t%\n\t\t&& \\text{\\texttt{vmatrix}} && \\text{\\texttt{Vmatrix}} && \\\\\n\t\t%\n\t\t&&\n\t\t\\begin{vmatrix}\n\t\t\tx_{11} & x_{12} \\\\\n\t\t\tx_{21} & x_{22} \\\\\n\t\t\\end{vmatrix}\n\t\t&&\n\t\t\\begin{Vmatrix}\n\t\t\tx_{11} & x_{12} \\\\\n\t\t\tx_{21} & x_{22} \\\\\n\t\t\\end{Vmatrix}\n\t\t&& \\\\\n\t\\end{align*}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Matrices: principle}\n\t\\framesubtitle{Alignment within the matrix}\n\t\n\tBy default, numbers are centred in each column of a matrix:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t2  & -3 \\\\\n\t\t\t42 & 0\n\t\t\\end{pmatrix}\n\t\\end{equation*}\n\t\n\tA starred version of each \\texttt{matrix} environment offers an optional argument where the alignment can be provided through a letter: \\texttt{c} for center, \\texttt{r} for right and \\texttt{l} for left.\n\tExample with right alignment:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix*}[r]\n\t\t\t2  & -3 \\\\\n\t\t\t42 & 0\n\t\t\\end{pmatrix*}\n\t\\end{equation*}\n\\end{frame}\n\n\n%-----\n\\section{More facilities}\n\n\\begin{frame}\n\t\\frametitle{More facilities}\n\t\\framesubtitle{Specific matrices (1)}\n\t\n\t\\structure{Zero matrix}: \\texttt{zeromatrix} or the shorter \\texttt{zmat} command.\n\t\n\tExamples:\n\t\\begin{align*}\n\t\t\\begin{pmatrix}\n\t\t\t\\zmat{2}\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{bmatrix}\n\t\t\t\\zmat{3}\n\t\t\\end{bmatrix}\n\t\t&&\n\t\t\\begin{vmatrix}\n\t\t\t\\zmat{4}\n\t\t\\end{vmatrix}\n\t\\end{align*}\n\t\n\n\t\\structure{Identity matrix}: \\texttt{identitymatrix} or the shorter \\texttt{imat} command.\n\t\n\tExamples:\n\t\\begin{align*}\n\t\t\\begin{pmatrix}\n\t\t\t\\imat{2}\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{bmatrix}\n\t\t\t\\imat{3}\n\t\t\\end{bmatrix}\n\t\t&&\n\t\t\\begin{vmatrix}\n\t\t\t\\imat{4}\n\t\t\\end{vmatrix}\n\t\\end{align*}\n\\end{frame}\n\n\n\\begin{frame}\n\t\\frametitle{More facilities}\n\t\\framesubtitle{Specific matrices (2)}\n\t\n\t\\structure{Diagonal matrix}: \\texttt{diagonalmatrix} or the shorter \\texttt{dmat} command.\n\tOptional argument to fill spaces.\n\t\n\tExamples:\n\t\\begin{align*}\n\t\t\\begin{pmatrix}\n\t\t\t\\dmat{a,b,c}\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{pmatrix}\n\t\t\t\\dmat{1,2,3}\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{pmatrix}\n\t\t\t\\dmat[0]{1,2,3}\n\t\t\\end{pmatrix}\n\t\\end{align*}\n\t\n\t\n\t\\structure{Automatically filled matrix}: \\texttt{xmatrix} or the shorter \\texttt{xmat} command.\n\tThe starred version creates automatic indices.\n\t\n\tExamples:\n\t\\begin{align*}\n\t\t\\begin{pmatrix}\n\t\t\t\\xmat{1}{2}{3}\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{pmatrix}\n\t\t\t\\xmat*{x}{3}{3}\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{pmatrix}\n\t\t\t\\xmat*{x}{3}{1}\n\t\t\\end{pmatrix}\n\t\\end{align*}\n\\end{frame}\n\n\n\\begin{frame}\n\t\\frametitle{More facilities}\n\t\\framesubtitle{Combinations of patterns}\n\t\n\t\\structure{Simple way}: use one of the previous commands, then add the other elements above and/or below like in a \\enquote{regular} matrix.\n\t\n\tExamples:\n\t\\begin{align*}\n\t\t\\begin{pmatrix}\n\t\t\t\\imat{2} \\\\ a & b\n\t\t\\end{pmatrix}\n\t\t&&\n\t\t\\begin{pmatrix}\n\t\t\ta & b & c \\\\\n\t\t\t\\zmat{2}{3}\n\t\t\\end{pmatrix}\n\t\\end{align*}\n\t\n\tIssue: impossible to add elements on the right or on the left of a submatrix generated with the \\emph{physics}' commands.\n\t\n\n\t\\structure{Matrix as a single element}: \\texttt{matrixquantity} or the shorter \\texttt{mqty} command. \n\t\n\tExample:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t\\mqty{\\imat{2}} & \\mqty{e\\\\d} \\\\\n\t\t\t\\mqty{a & b} & c\n\t\t\\end{pmatrix}\n\t\\end{equation*}\n\\end{frame}\n\n\n\\end{document}", "meta": {"hexsha": "4947f4c9d7bcbc984ddd27008bbdc76e835fa76f", "size": 5487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tutorials/C101__Maths_Matrices/Quick_reference.tex", "max_stars_repo_name": "Arkh42/LaTeX_magic", "max_stars_repo_head_hexsha": "fb17aab27bae727267605897c6d00ab65b097f23", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorials/C101__Maths_Matrices/Quick_reference.tex", "max_issues_repo_name": "Arkh42/LaTeX_magic", "max_issues_repo_head_hexsha": "fb17aab27bae727267605897c6d00ab65b097f23", "max_issues_repo_licenses": ["MIT"], "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/C101__Maths_Matrices/Quick_reference.tex", "max_forks_repo_name": "Arkh42/LaTeX_magic", "max_forks_repo_head_hexsha": "fb17aab27bae727267605897c6d00ab65b097f23", "max_forks_repo_licenses": ["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.7374100719, "max_line_length": 205, "alphanum_fraction": 0.6506287589, "num_tokens": 1938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.675994968139549}}
{"text": "\n\\subsection{Bias-Variance trade-off}\n\nBias-variance trade-off. if we care about \\(E[(y-xt)^2]\\) then we may not want an unbiased estimator. by adding some bias we could reduce the variance a lot.\n\n", "meta": {"hexsha": "fa70ca167acf91fb2dcc6a4345e5c17808aa26cb", "size": 198, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/02-06-biasVariance.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generative/02-06-biasVariance.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generative/02-06-biasVariance.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.0, "max_line_length": 157, "alphanum_fraction": 0.7424242424, "num_tokens": 51, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6759943360648978}}
{"text": "\\section{Products and angles}\nBesides complex multiplication, which is nice to have but is not useful so often, there are two products involving vectors that are of critical importance: dot product and cross product. In this section, we'll look at their definition, properties and some basic use cases.\n\n\\subsection{Dot product}\\label{ss:dot}\nThe dot product $\\dotv{v}{w}$ of two vectors $\\vv{v}$ and $\\vv{w}$ can be seen as a measure of how similar their directions are. It is defined as \\[\\dotv{v}{w} = \\normv{v}\\normv{w} \\cos\\theta\\] where $\\normv{v}$ and $\\normv{w}$ are the lengths of the vectors and $\\theta$ is amplitude of the angle between $\\vv{v}$ and $\\vv{w}$.\n\nSince $\\cos(-\\theta) = \\cos(\\theta)$, the sign of the angle does not matter, and the dot product is symmetric: $\\dotv{v}{w} = \\dotv{w}{v}$.\n\nIn general we will take $\\theta$ in $[0,\\pi]$, so that dot product is positive if $\\theta < \\pi/2$, negative if $\\theta > \\pi/2$, and zero if $\\theta = \\pi/2$, that is, if $\\vv{v}$ and $\\vv{w}$ are perpendicular.\n\\centerFig{products0}\n\nIf we fix $\\normv{v}$ and $\\normv{w}$ as above, the dot product is maximal when the vectors point in the same direction, because $\\cos\\theta = \\cos(0) = 1$, and minimal when they point in opposite directions, because $\\cos\\theta = \\cos(\\pi) = -1$.\n\n\\begin{mathy}\nBecause of the definition of cosine in right triangles, dot product can be interpreted in an interesting way (assuming $\\vv{v} \\neq 0$): $\\vv{v}\\cdot\\vv{w} = \\normv{v}\\projv{v}{w}$ where $\\projv{v}{w} \\coloneqq \\normv{w}\\cos\\theta$ is the signed length of the projection of $\\vv{w}$ onto the line that contains $\\vv{v}$ (see examples below).\nIn particular, this means that the dot product does not change if one of the vectors moves perpendicular to the other.\n\\centerFig{products1}\n\\end{mathy}\n\nRemarkably, the dot product can be computed by a very simple expression: if $\\vv{v} = (v_x, v_y)$ and $\\vv{w} = (w_x, w_y)$, then $\\dotv{v}{w} = v_xw_x + v_yw_y$. We can implement it like this:\n\\begin{lstlisting}\nT dot(pt v, pt w) {return v.x*w.x + v.y*w.y;}\n\\end{lstlisting}\n\nDot product is often used for testing if two vectors are perpendicular, since we just need to test whether $\\dotv{v}{w} = 0$:\n\\begin{lstlisting}\nbool isPerp(pt v, pt w) {return dot(v,w) == 0;}\n\\end{lstlisting}\n\nIt can also be used for finding the angle between two vectors, in $[0,\\pi]$. Because of precision errors, we need to be careful not to call \\lstinline|acos| with a value that is out of the allowable range $[-1,1]$.\n\\begin{lstlisting}\ndouble angle(pt v, pt w) {\n    double cosTheta = dot(v,w) / abs(v) / abs(w);\n    return acos(max(-1.0, min(1.0, cosTheta)));\n}\n\\end{lstlisting}\nSince C++17, this can be simplified to:\n\\begin{lstlisting}\ndouble angle(pt v, pt w) {\n    return acos(clamp(dot(v,w) / abs(v) / abs(w), -1.0, 1.0));\n}\n\\end{lstlisting}\n\n\\subsection{Cross product}\\label{ss:cross}\nThe cross product $\\crossv{v}{w}$ of two vectors $\\vv{v}$ and $\\vv{w}$ can be seen as a measure of how perpendicular they are. It is defined in 2D as \\[\\crossv{v}{w} = \\normv{v}\\normv{w} \\sin\\theta\\] where $\\normv{v}$ and $\\normv{w}$ are the lengths of the vectors and $\\theta$ is amplitude of the oriented angle from $\\vv{v}$ to $\\vv{w}$.\n\nSince $\\sin(-\\theta) = -\\sin(\\theta)$, the sign of the angle matters, the cross product changes sign when the vectors are swapped: $\\crossv{w}{v} = -\\crossv{v}{w}$. It is positive if $\\vv{w}$ is ``to the left'' of $\\vv{v}$, and negative is $\\vv{w}$ is ``to the right'' of $\\vv{v}$.\n\n\\centerFig{products2}\n\nIn general, we take $\\theta$ in $(-\\pi,\\pi]$, so that the dot product is positive if $0 < \\theta < \\pi$, negative if $-\\pi < \\theta < 0$ and zero if $\\theta = 0$ or $\\theta = \\pi$, that is, if $\\vv{v}$ and $\\vv{w}$ are aligned.\n\n\\centerFig{products3}\n\n\nIf we fix $\\normv{v}$ and $\\normv{w}$ as above, the cross product is maximal when the vectors are perpendicular with $\\vv{w}$ on the left, because $\\sin\\theta = \\sin(\\pi/2) = 1$, and minimal when they are perpendicular with $\\vv{w}$ on the right, because $\\sin\\theta = \\sin(-\\pi/2) = -1$.\n\n\n\\begin{mathy}\nBecause of the definition of sine in right triangles, cross product can also be interpreted in an interesting way (assuming $v \\neq 0$): $\\crossv{v}{w} = \\normv{v}d_{\\vv{v}}(\\vv{w})$, where $d_{\\vv{v}}(\\vv{w}) = \\normv{w}\\sin\\theta$ is the \\emph{signed} distance from the line that contains $\\vv{v}$, with positive values on the left side of $\\vv{v}$.\nIn particular, this means that the cross product doesn't change if one of the vectors moves parallel to the other.\n\n\\centerFig{products4}\n\\end{mathy}\n\nLike dot product, cross product has a very simple expression in cartesian coordinates: if $\\vv{v} = (v_x, v_y)$ and $\\vv{w} = (w_x, w_y)$, then $\\crossv{v}{w} = v_xw_y - v_yw_x$:\n\\begin{lstlisting}\nT cross(pt v, pt w) {return v.x*w.y - v.y*w.x;}\n\\end{lstlisting}\n\n\\begin{trick}\n    When using \\lstinline|complex|, we can implement both \\lstinline|dot()| and \\lstinline|cross()| with this trick, which is admittedly quite cryptic, but requires less typing and is less prone to typos:\n    \\begin{lstlisting}\n    T   dot(pt v, pt w) {return (conj(v)*w).x;}\n    T cross(pt v, pt w) {return (conj(v)*w).y;}\n    \\end{lstlisting}\n\n    Here \\lstinline|conj()| is the complex conjugate: the conjugate of a complex number $a+bi$ is defined as $a-bi$. To verify that the implementation is correct, we can compute \\lstinline|conj(v)*w| as\n    \\[(v_x-v_yi)\\ast(w_x+w_yi) = (v_xw_x + v_yw_y) + (v_xw_y-v_yw_x)i\\]\n    and see that the real and imaginary parts are indeed the dot product and the cross product.\n\\end{trick}\n\n\\subsubsection{Orientation}\nOne of the main uses of cross product is in determining the relative position of points and other objects. For this, we define the function $\\orient(A,B,C) = \\crossv{AB}{AC}$. It is positive if $C$ is on the left side of $\\vv{AB}$, negative on the right side, and zero if $C$ is on the line containing $\\vv{AB}$. It is straightforward to implement:\n\\begin{lstlisting}\nT orient(pt a, pt b, pt c) {return cross(b-a,c-a);}\n\\end{lstlisting}\n\nIn other words, $\\orient(A,B,C)$ is positive if when going from $A$ to $B$ to $C$ we turn left, negative if we turn right, and zero if $A,B,C$ are collinear.\n\n\\centerFig{products5}\n\nIts value is conserved by cyclic rotation, that is \\[\\orient(A,B,C) = \\orient(B,C,A) = \\orient(C,A,B)\\] while swapping any two arguments switches the sign.\n\nAs an example of use, suppose we want to check if point $P$ lies in the angle formed by lines $AB$ and $AC$. We can follow this procedure:\n\\begin{enumerate}\n\\item check that $\\orient(A,B,C) \\neq 0$ (otherwise the question is invalid);\n\\item if $\\orient(A,B,C) < 0$, swap $B$ and $C$;\n\\centerFig{products6}\n\\item $P$ is in the angle iff $\\orient(A,B,P) \\geq 0$ and $\\orient(A,C,P) \\leq 0$.\n\\centerFig{products7}\n\\end{enumerate}\n\\begin{lstlisting}\nbool inAngle(pt a, pt b, pt c, pt p) {\n    assert(orient(a,b,c) != 0);\n    if (orient(a,b,c) < 0) swap(b,c);\n    return orient(a,b,p) >= 0 && orient(a,c,p) <= 0;\n}\n\\end{lstlisting}\n\nUsing $\\orient()$ we can also easily compute the amplitude of an \\emph{oriented angle} $\\widehat{BAC}$, that is, the angle that is covered if we turn from $B$ to $C$ around $A$ counterclockwise.\n\nThere are two cases: either $\\orient(A,B,C) \\geq 0$, with an angle in $[0,\\pi]$, or $\\orient(A,B,C) < 0$, with an angle in $(\\pi,2\\pi)$. In the first case, we can simply use the \\lstinline|angle()| function we create based on the dot product; in the second case, we should take ``the other side'', so $2\\pi$ minus that result.\n\n\\centerFig{products8}\n\n\\begin{lstlisting}\ndouble orientedAngle(pt a, pt b, pt c) {\n    if (orient(a,b,c) >= 0)\n        return angle(b-a, c-a);\n    else\n        return 2*M_PI - angle(b-a, c-a);\n}\n\\end{lstlisting}\n\nYet another use case is checking if a polygon $P_1\\cdots P_n$ is convex: we compute the $n$ orientations of three consecutive vertices $\\orient(P_i,P_{i+1},P_{i+2})$, wrapping around from $n$ to $1$ when necessary. The polygon is convex if they are all $\\geq 0$ or all $\\leq 0$, depending on the order in which the vertices are given.\n\n\\centerFig{products9}\n\n\\begin{lstlisting}\nbool isConvex(vector<pt> p) {\n    bool hasPos=false, hasNeg=false;\n    for (int i=0, n=p.size(); i<n; i++) {\n        int o = orient(p[i], p[(i+1)%n], p[(i+2)%n]);\n        if (o > 0) hasPos = true;\n        if (o < 0) hasNeg = true;\n    }\n    return !(hasPos && hasNeg);\n}\n\\end{lstlisting}\n\n\\subsubsection{Polar sort}\\label{polar-sort}\nBecause it can determine whether a vector points to the left or right of another, a common use of cross product is to sort vectors by direction. This is called polar sort: points are sorted in the order that a rotating ray emanating from the origin would touch them. Here, we will try to use cross product to safely sort the points by their arguments in $(-\\half,\\half]$, that is the order that would be given by the \\lstinline|arg()| function for \\lstinline|complex|.\\footnote{Sorting by using the \\lstinline|arg()| value would likely be a bad idea: there is no guarantee (that I know of) that vectors which are multiples of each other will have the same argument, because of precision issues. However, I haven't been to find an example where it fails for values small enough to be handled exactly with \\lstinline|long long|.}\n\n\\centerFig{products10}\n\nIn general $\\vv{v}$ should go before $\\vv{w}$ when $\\crossv{v}{w} > 0$, because that means $\\vv{w}$ is to the left of $\\vv{v}$ when looking from the origin. This test works well for directions that are sufficiently close: for example, $\\crossv{v_2}{v_3} > 0$. But when they are more than $180\\degree$ apart in the order, it stops working: for example $\\crossv{v_1}{v_5} < 0$. So we first need to split the points in two halves according to their argument:\n\n\\centerFig{products11}\n\nIf we isolate the points with argument in $(0,\\half]$ (region highlighted in blue) from those with argument in $(-\\half, 0]$, then the cross product always gives the correct order.\nThis gives the following algorithm:\n\\begin{lstlisting}\nbool half(pt p) { // true if in blue half\n    assert(p.x != 0 || p.y != 0); // the argument of (0,0) is undefined\n    return p.y > 0 || (p.y == 0 && p.x < 0);\n}\nvoid polarSort(vector<pt> &v) {\n    sort(v.begin(), v.end(), [](pt v, pt w) {\n        return make_tuple(half(v), 0) <\n               make_tuple(half(w), cross(v,w));\n    });\n}\n\\end{lstlisting}\nIndeed, the comparator will return \\lstinline|true| if either $\\vv{w}$ is in the blue region and $\\vv{v}$ is not, or if they are in the same region and $\\crossv{v}{w} > 0$.\n\nWe can extend this algorithm in three ways:\n\\begin{itemize}\n    \\item Right now, points that are in the exact same direction are considered equal, and thus will be sorted arbitrarily. If we want, we can use their magnitude as a tie breaker:\n    \\begin{lstlisting}\n    void polarSort(vector<pt> &v) {\n        sort(v.begin(), v.end(), [](pt v, pt w) {\n            return make_tuple(half(v), 0, sq(v)) <\n                   make_tuple(half(w), cross(v,w), sq(w));\n        });\n    }\n    \\end{lstlisting}\n    With this tweak, if two points are in the same direction, the point that is further from the origin will appear later.\n    \\item We can perform a polar sort around some point $O$ other than the origin: we just have to subtract that point $O$ from the vectors $\\vv{v}$ and $\\vv{w}$ when comparing them. This as if we translated the whole plane so that $O$ is moved to $(0,0)$:\n    \\begin{lstlisting}\n    void polarSortAround(pt o, vector<pt> &v) {\n        sort(v.begin(), v.end(), [](pt v, pt w) {\n            return make_tuple(half(v-o), 0)) <\n                   make_tuple(half(w-o), cross(v-o, w-o));\n        });\n    }\n    \\end{lstlisting}\n    \\item Finally, the starting angle of the ordering can be modified easily by tweaking function \\lstinline|half()|. For example, if we want some vector $\\vv{v}$ to be the first angle in the polar sort, we can write:\n    \\begin{lstlisting}\n    pt v = {/* whatever you want except 0,0 */};\n    bool half(pt p) {\n        return cross(v,p) < 0 || (cross(v,p) == 0 && dot(v,p) < 0);\n    }\n    \\end{lstlisting}\n    This places the blue region like this:\n    \\centerFig{products12}\n\\end{itemize}\n", "meta": {"hexsha": "51f8f5258be6213e2c6e052dd2f67e76120b47cd", "size": 12219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/basics/products.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/basics/products.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/basics/products.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.7121212121, "max_line_length": 827, "alphanum_fraction": 0.6768147966, "num_tokens": 3685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6759708498515302}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#1 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{Simplifying The Original VC Bound}\n\nThe original VC bound looks like this:\n\n\\begin{equation*}\n\\epsilon \\leq \\sqrt{\\frac{8}{N}\\ln{\\frac{4m_{\\mathcal{H}}(2N)}{\\delta}}}\n\\end{equation*}\n\nPutting it in terms of $N$:\n\n\\begin{equation*}\nN \\geq \\frac{8}{\\epsilon^2}\\ln{\\frac{4m_{\\mathcal{H}}(2N)}{\\delta}}\n\\end{equation*}\n\nNow, defining the growth function $m_{\\mathcal{H}}(N)$ in terms of the upper\nbound in $d_{vc}$:\n\n\\begin{equation*}\nN \\geq \\frac{8}{\\epsilon^2}\\ln{\\frac{4(2N)^{d_{vc}}}{\\delta}}\n\\end{equation*}\n\n\\section{Solving Through Successive Approximations}\n\nStarting from $N=10^5$, let's try to find the $N$ that safisfies that\ninequality. If we plug in this first $N$ along with $d_{vc}=10$,\n$\\epsilon=0.05$ and $\\delta=0.05$ in the formula, we have:\n\n\\begin{equation*}\nN \\geq \\frac{8}{0.05^2}\\ln{\\frac{4(2\\cdot10^5)^{10}}{0.05}} \\approx 404,617\n\\end{equation*}\n\nWe've missed by a long shot! If we feed $N=\\numprint{404617}$ into the same\nequation:\n\n\\begin{equation*}\nN \\geq \\frac{8}{0.05^2}\\ln{\\frac{4(2\\cdot404617)^{10}}{0.05}} \\approx 449,345\n\\end{equation*}\n\nKeep doing this long enough so that $N$ converges to approximately\n\\numprint{452956}.\n\n\\end{document}\n", "meta": {"hexsha": "d56a9ba653e9a2db932b6ecaf3beb52f7af7b355", "size": 1496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-04/math/q01.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-04/math/q01.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-04/math/q01.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": 25.7931034483, "max_line_length": 77, "alphanum_fraction": 0.702540107, "num_tokens": 538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6759708446391132}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[latin1,utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{bm}\n\\usepackage{dsfont} %\\usepackage{bbm} might not work for double stroke 1\n\\usepackage{xcolor}\n\\usepackage{hyperref}\n\\usepackage{pdflscape}\n\\definecolor{links}{RGB}{0,0,128}\n\n\\hypersetup{\n    unicode=true,          % non-Latin characters in Acrobat’s bookmarks\n    pdftitle={},    % title\n    pdfauthor={Klaus Herrmann},     % author\n    colorlinks=true,       % false: boxed links; true: colored links\n    linkcolor=links,          % color of internal links (change box color with linkbordercolor)\n    citecolor=links,        % color of links to bibliography\n    filecolor=links,      % color of file links\n    urlcolor=links           % color of external links\n}\n\n\\def\\R{\\mathbb{R}}\n\\def\\Prob{\\mathbb{P}}\n\\def\\N{\\mathbb{N}}\n\\def\\bfx{\\bm{x}}\n\\def\\bfX{\\bm{X}}\n\\def\\bfv{\\bm{v}}\n\\def\\d{\\,\\mathrm{d}}\n\\newcommand{\\abs}[1]{\\left|#1\\right|}\n\\definecolor{links}{RGB}{0,0,128}\n\\def\\bfa{\\bm{a}}\n\\def\\bx{\\mathbf{x}}\n\\def\\ba{\\mathbf{a}}\n\\def\\bb{\\mathbf{b}}\n\\def\\Normal{\\mathcal{N}}\n\\newcommand{\\xNorm}[2]{\\left \\Vert #1 \\right \\Vert_{#2} }\n\\newcommand{\\floor}[1]{\\left \\lfloor #1 \\right \\rfloor }\n\\newcommand{\\ind}[1]{\\mathds{1}_{#1} }\n\n\\begin{document}\n\n\\newpage\n\\title{\\textbf{Mult}ivariate \\textbf{Int}egration \\textbf{Test Func}tions - Function References}\n\\author{Klaus Herrmann (Université de Sherbrooke)}\n\\maketitle\n\n\\tableofcontents\n\n\\section*{Introduction}\n\\addcontentsline{toc}{section}{Introduction}\nThis note compiles references for the integration test functions implemented in the R package \\emph{multIntTestFunc}.\nFor each function there is either a derivation of the exact value of the integral or a reference to a derivation.\nThe functions are sorted by integration domains and Tables~\\ref{table_Rn}--\\ref{table_sphere} provide an overview over the test functions for the supported domains at the end of the document.\nThe available integration domains are\n\\begin{itemize}\n\t\\item the non-negative real numbers $[0,\\infty)^n$ (Section~P),\n\t\\item the Euclidean space $\\R^n$ (Section~R),\n\t\\item the standard simplex $T_n$ (Section~T),\n\t\\item the unit hypercube $C_n$ (Section~C),\n\t\\item the unit ball $B_n$ (Section~B), and\n\t\\item the unit sphere $S^{n-1}$ (Section~S).\n\\end{itemize}\nFor shorthand notation we use $\\cdot$ for inner products, i.e., $\\ba\\cdot\\bb = \\sum_{i=1}^n a_ib_i$ for two vectors in $\\R^n$.\n%\n%\n%\n%\\newpage\n%\n%\n%\n\\section*{P\\hspace{0.5cm}Non-negative real numbers $[0,\\infty)^n = \\times_{i=1}^{n} [0,\\infty)$}\n\\addcontentsline{toc}{section}{P\\hspace{0.5cm}Non-negative real numbers $[0,\\infty)^n = \\times_{i=1}^{n} [0,\\infty)$}\n\\subsection*{P.1\\hspace{0.5cm}log-normal density}\n\\addcontentsline{toc}{subsection}{P.1\\hspace{0.5cm}log-normal density}\\label{lognormal}\nConsider the function\n\\begin{align*}\nf\\colon [0,\\infty)^n\\to[0,\\infty), \\bx \\mapsto f(\\bx) =\\frac{\\exp(-((\\ln(\\bx)-\\mu)^{T}\\Sigma^{-1}(\\ln(\\bx)-\\mu))/2)}{\\prod_{i=1}^{n}x_i \\sqrt{(2\\pi)^n\\det(\\Sigma)}}.\n\\end{align*}\nThis is the density function of the log-normal distribution.\nTherefore\n\\begin{align*}\n\\int_{[0,\\infty)^n} f(\\bx) \\d \\bx = 1.\n\\end{align*}\nThe $n$-dimensional vector $\\mu$ and the symmetric positive definite matrix $\\Sigma\\in\\R^{n\\times n}$ are the mean and variance-covariance matrix of a multivariate normal random vector.\n%\n%\n\\subsection*{P.2\\hspace{0.5cm}log-$t$ density}\n\\addcontentsline{toc}{subsection}{P.2\\hspace{0.5cm}log-$t$ density}\\label{logt}\nConsider the function\n\\begin{align*}\nf\\colon &[0,\\infty)^n\\to[0,\\infty),\\\\\n&\\bx \\mapsto f(\\bx) = \\frac{(\\prod_{i=1}^n x_i^{-1})\\Gamma\\left[(\\nu+n)/2\\right]}{\\Gamma(\\nu/2)\\nu^{n/2}\\pi^{n/2}\\left|{\\Sigma}\\right|^{1/2}}\\left[1+\\frac{1}{\\nu}({\\log(\\bx)}-{\\delta})^{T}{\\Sigma}^{-1}({\\log(\\bx)}-{\\delta})\\right]^{-(\\nu+n)/2}\n\\end{align*}\nThis is the density function of the log-t distribution.\nTherefore\n\\begin{align*}\n\\int_{[0,\\infty)^n} f(\\bx) \\d \\bx = 1.\n\\end{align*}\nThe $n$-dimensional vector $\\delta$ and the symmetric positive definite matrix $\\Sigma\\in\\R^{n\\times n}$ are the location and scale matrix of a multivariate log-$t$ random vector.\nThe positive real number $\\nu$ is the degrees-of-freedom parameter.\n%\n%\n%\n\\section*{R\\hspace{0.5cm}Euclidean Space $\\R^n = \\times_{i=1}^{n} \\R$}\n\\addcontentsline{toc}{section}{R\\hspace{0.5cm}Euclidean Space $\\R^n = \\times_{i=1}^{n} \\R$}\n\\subsection*{R.1\\hspace{0.5cm}Gaussian Integral}\n\\addcontentsline{toc}{subsection}{R.1\\hspace{0.5cm}Gaussian Integral}\nConsider the function\n\\begin{align*}\nf\\colon \\R^n\\to(0,\\infty), \\bx \\mapsto f(\\bx) = e^{-\\xNorm{\\bx}{2}^2}.\n\\end{align*}\nAs a standard result we have $\\int_{\\R} e^{-x^2}\\d x = \\pi^{1/2}$.\nThis leads to\n\\begin{align*}\n\\int_{\\R^n} f(\\bx) \\d \\bx\n= \\int_{\\R^n} e^{-\\xNorm{\\bx}{2}^2} \\d \\bx\n= \\int_{\\R^n} \\prod_{i=1}^n e^{-x_i^2} \\d \\bx\n= \\prod_{i=1}^n \\int_{\\R^n}  e^{-x_i^2} \\d x_i\n= \\pi^{n/2}.\n\\end{align*}\n%\n%\n\\subsection*{R.2\\hspace{0.5cm}Floor Norm Integral}\n\\addcontentsline{toc}{subsection}{R.2\\hspace{0.5cm}Floor Norm Integral}\nFor $s>1$ define the function\n\\begin{align*}\nf\\colon \\R^n\\to(0,\\infty), \\bx \\mapsto f(\\bx) = \\frac{\\Gamma(n/2+1)}{\\pi^{n/2}(1+\\lfloor \\Vert \\bx \\Vert_2^n \\rfloor)^s}.\n\\end{align*}\nDenote by $B_{r}(0) = \\{\\bx\\in\\R^n : \\xNorm{\\bx}{2}<r\\}$ the open ball centered at zero in $\\R^n$.\nIn this case we have for $k=\\{1,2,3,\\ldots\\}$ that\n\\begin{align*}\n1+\\lfloor \\Vert \\bx \\Vert_2^n \\rfloor = k \\Leftrightarrow (k-1)^{1/n} \\leq \\xNorm{\\bx}{2} < k^{1/n} \\Leftrightarrow \\bx \\in B_{k^{1/n}}(0) \\setminus B_{(k-1)^{1/n}}(0).\n\\end{align*}\nTherefore $f$ is constant on the shells $S_k = B_{k^{1/n}}(0) \\setminus B_{(k-1)^{1/n}}(0)$, where we set $S_1 = B_1(0)$, with value $f(\\bx) = \\Gamma(n/2+1)/(\\pi^{n/2}k^s)$.\nTherefore\n\\begin{align*}\n\\int_{\\R^n} f(\\bx) \\d \\bx\n&= \\int_{\\uplus_{k\\geq 1}S_k}  f(\\bx) \\d \\bx\n= \\sum^{\\infty}_{k=1} \\int_{S_k}  f(\\bx) \\d \\bx\n= \\sum^{\\infty}_{k=1} \\frac{\\Gamma(n/2+1)}{\\pi^{n/2}k^s} \\text{vol}\\left(S_k\\right)\\\\\n&= \\sum^{\\infty}_{k=1} \\frac{\\Gamma(n/2+1)}{\\pi^{n/2}k^s} \\left(\\text{vol}(B_{k^{1/n}}(0))-\\text{vol}(B_{(k-1)^{1/n}}(0))\\right)\\\\\n&= \\sum^{\\infty}_{k=1} \\frac{\\Gamma(n/2+1)}{\\pi^{n/2}k^s} \\left(\\frac{\\pi^{n/2}}{\\Gamma(n/2+1)}(k^{1/n})^n-\n\\frac{\\pi^{n/2}}{\\Gamma(n/2+1)}((k-1)^{1/n})^n\n\\right)\\\\\n&= \\sum^{\\infty}_{k=1} \\frac{1}{k^s} = \\zeta(s),\n\\end{align*}\nwhere $\\zeta$ is the Riemann zeta function.\n%\n%\n%\n\\subsection*{R.3\\hspace{0.5cm}Multivariate normal density}\n\\addcontentsline{toc}{subsection}{R.3\\hspace{0.5cm}Multivariate normal density}\nConsider the function\n\\begin{align*}\nf\\colon \\R^n\\to[0,\\infty), \\bx \\mapsto f(\\bx) =\\frac{\\exp(-((\\bx-\\mu)^{T}\\Sigma^{-1}(\\bx-\\mu))/2)}{\\sqrt{(2\\pi)^n\\det(\\Sigma)}}.\n\\end{align*}\nThis is the density function of the multivariate normal distribution.\nTherefore\n\\begin{align*}\n\\int_{\\R^n} f(\\bx) \\d \\bx = 1.\n\\end{align*}\nThe $n$-dimensional vector $\\mu$ and the symmetric positive definite matrix $\\Sigma\\in\\R^{n\\times n}$ are the respective mean and variance-covariance matrix.\n%\n%\n%\n\\subsection*{R.4\\hspace{0.5cm}Multivariate $t$ density}\n\\addcontentsline{toc}{subsection}{R.4\\hspace{0.5cm}Multivariate $t$ density}\nConsider the function\n\\begin{align*}\nf\\colon \\R^n\\to[0,\\infty), \\bx \\mapsto f(\\bx) = \\frac{\\Gamma\\left[(\\nu+n)/2\\right]}{\\Gamma(\\nu/2)\\nu^{n/2}\\pi^{n/2}\\left|{\\Sigma}\\right|^{1/2}}\\left[1+\\frac{1}{\\nu}({\\bx}-{\\delta})^{T}{\\Sigma}^{-1}({\\bx}-{\\delta})\\right]^{-(\\nu+n)/2}.\n\\end{align*}\nThis is the density function of the multivariate $t$ distribution.\nTherefore\n\\begin{align*}\n\\int_{\\R^n} f(\\bx) \\d \\bx = 1.\n\\end{align*}\nThe $n$-dimensional vector $\\delta$ and the symmetric positive definite matrix $\\Sigma\\in\\R^{n\\times n}$ are the respective location vector and scale matrix.\nThe positive real number $\\nu$ is the degrees-of-freedom parameter.\n%\n%\n%\n%\\newpage\n%\n%\n%\n\\section*{T\\hspace{0.5cm}Standard Simplex $T_n = \\{\\bx\\in\\R^n : x_i \\geq 0, \\xNorm{\\bx}{1} \\leq 1\\}$}\n\\addcontentsline{toc}{section}{T\\hspace{0.5cm}Standard Simplex $T_n = \\{\\bx\\in\\R^n : x_i \\geq 0, \\xNorm{\\bx}{1} \\leq 1\\}$}\nFor a continuously differentiable function $f \\colon [0,1] \\to \\R$ we have, see \\cite{IntegralSimplex}, that\n\\begin{align}\\label{equation_simplex_sum}\n\\int_{T_n} f(x_1+\\ldots+x_n) \\d \\bx = \\frac{1}{\\Gamma(n)} \\int_0^1 f(s)s^{n-1}ds.\n\\end{align}\nEquation~\\eqref{equation_simplex_sum} can be used to construct integrable functions on $T_n$.\n%\n%\n\\subsection*{T.1\\hspace{0.5cm}Dirichlet Integral}\n\\addcontentsline{toc}{subsection}{T.1\\hspace{0.5cm}Dirichlet Integral}\nFor a vector $\\bfv\\in\\R^{n+1}$ with strictly positive entries, i.e., $v_i>0$, define the function\n\\begin{align*}\nf\\colon T_{n}\\to(0,\\infty), \\bx \\mapsto f(\\bx) = \\prod_{i=1}^{n}x_i^{v_i-1}(1 - x_1 - \\ldots - x_n)^{v_{n+1}-1}.\n\\end{align*}\nIt can be seen that the integral of $f$ over $T_n$ is the norming constant for the Dirichlet distribution.\nWe therefore have\n\\begin{align*}\n\\int_{T_n} f(\\bx) \\d\\bx = \\frac{\\prod_{i=1}^{n+1}\\Gamma(v_i)}{\\Gamma(\\sum_{i=1}^{n+1}v_i)}.\n\\end{align*}\n%\n%\n\\subsection*{T.2\\hspace{0.5cm}Exponential of Sum}\n\\addcontentsline{toc}{subsection}{T.2\\hspace{0.5cm}Exponential of Sum}\nFor a constant $c>0$ define the function\n\\begin{align*}\nf\\colon T_{n}\\to(0,\\infty), \\bx \\mapsto f(\\bx) = e^{-c(x_1+\\ldots+x_n)}.\n\\end{align*}\nCombining \\eqref{equation_simplex_sum} with integration-by-substitution yields\n\\begin{align*}\n\\int_{T_n} f(\\bx) \\d\\bx\n&= \\frac{1}{\\Gamma(n)} \\int_0^1 e^{-cs}s^{n-1} \\d s\\\\\n&= \\frac{c^{-n}}{\\Gamma(n)} \\int_0^c e^{-t}t^{n-1} \\d t\\\\\n&= \\frac{\\Gamma(n)-\\Gamma(n,c)}{c^{n}\\Gamma(n)},\n\\end{align*}\nwhere $\\Gamma(s,x)$ is the upper incomplete gamma function defined as\n\\begin{align*}\n\\Gamma(s,x) = \\int_x^{\\infty} t^{s-1}e^{-t} \\d t.\n\\end{align*}\n%\n%\n%\n%\\newpage\n%\n%\n%\n\\section*{C\\hspace{0.5cm}Unit Cube $C_n = [0,1]^n$}\n\\addcontentsline{toc}{section}{C\\hspace{0.5cm}Unit Cube $C_n = [0,1]^n$}\n\\subsection*{C.1\\hspace{0.5cm}Cosine Square}\n\\addcontentsline{toc}{subsection}{C.1\\hspace{0.5cm}Cosine Square}\nFor a vector $\\bfv\\in\\R^n$ define the function\n\\begin{align*}\nf\\colon C_{n}\\to\\R, \\bx \\mapsto f(\\bx) = (\\cos\\left(\\bfx\\cdot\\bfv\\right))^2.\n\\end{align*}\nFollowing \\cite{IntegralCos2} one can use the identities $\\cos(x)=\\Re(e^{ix})$ and $\\cos(x)^2 = \\frac{1}{2}+\\frac{1}{2}\\cos(2x)$ to show\n\\begin{align*}\n\\int_{C_{n}} f(\\bx) \\d\\bx =\\frac{1}{2}+\\frac{1}{2}\\cos\\left(\\sum_{j=1}^{n}v_j\\right)\\prod_{j=1}^{n}\\frac{\\sin(v_j)}{v_j}.\n\\end{align*}\n%\n%\n%\n\\subsection*{C.2\\hspace{0.5cm}Floor of Sum}\n\\addcontentsline{toc}{subsection}{C.2\\hspace{0.5cm}Floor of Sum}\nFor the function\n\\begin{align*}\nf\\colon C_{n}\\to\\R, \\bx \\mapsto f(\\bx) = \\lfloor x_1 + \\ldots + x_n \\rfloor\n\\end{align*}\nwe have, see \\cite{IntegralFloorCube}, that\n\\begin{align*}\n\\int_{C_{n}} f(\\bx) \\d\\bx = \\frac{n-1}{2}.\n\\end{align*}\n%\n%\n\\subsection*{C.3\\hspace{0.5cm}Maximum}\n\\addcontentsline{toc}{subsection}{C.3\\hspace{0.5cm}Maximum}\nFor the function\n\\begin{align*}\nf\\colon C_{n}\\to\\R, \\bx \\mapsto f(\\bx) = \\max(x_1,\\ldots,x_n)\n\\end{align*}\nwe have, see \\cite{IntegralCubeMax}, that\n\\begin{align*}\n\\int_{C_{n}} f(\\bx) \\d\\bx = \\frac{n}{n+1}.\n\\end{align*}\n%\n%\n%\n%\\newpage\n%\n%\n%\n\\section*{B\\hspace{0.5cm}Unit Ball $B_n = \\{\\bx \\in \\mathbb{R}^n : \\xNorm{\\bx}{2} \\leq 1\\}$}\n\\addcontentsline{toc}{section}{B\\hspace{0.5cm}Unit Ball $B_n = \\{\\bx \\in \\mathbb{R}^n : \\xNorm{\\bx}{2} \\leq 1\\}$}\n%\n%\n%\n\\subsection*{B.1\\hspace{0.5cm}Norm of Standard Normal Random Vector}\n\\addcontentsline{toc}{subsection}{B.1\\hspace{0.5cm}Norm of Standard Normal Random Vector}\nThe function\n\\begin{align*}\nf\\colon B_{n}\\to\\R, \\bx \\mapsto f(\\bx) = \\frac{1}{(2\\pi)^{n/2}}e^{-\\xNorm{\\bx}{2}^2/2}\n\\end{align*}\ncan be seen as the density of a random vector $\\bfX=(X_1,\\ldots,X_n)$, where all $X_i\\sim\\Normal(0,1)$ are independent.\nWe can then rewrite the integral as\n\\begin{align*}\n\\int_{B_{n}} f(\\bx) \\d\\bx = \\Prob[\\xNorm{\\bfX}{2}\\leq 1] = \\Prob[\\xNorm{\\bfX}{2}^2\\leq 1] = F_{\\chi^2_n}(1),\n\\end{align*}\nwhere $F_{\\chi^2_n}$ is the distribution function of a chi-square random variable.\n%\n%\n%\n\\subsection*{B.2\\hspace{0.5cm}Polynomials}\n\\addcontentsline{toc}{subsection}{B.2\\hspace{0.5cm}Polynomials}\nFor non-negative integers $a_1,\\ldots,a_n$, $a_i\\in\\{0,1,2,\\ldots\\}$, define the monomial\n\\begin{align*}\nf\\colon B_{n}\\to\\R, \\bx \\mapsto f(\\bx) = \\prod_{i=1}^{n}x_i^{a_i}.\n\\end{align*}\nWe know from \\cite{Folland2001} that\n\\begin{align*}\n\\int_{B_{n}} f(\\bx) \\d\\bx =\n\\begin{cases}\n0, &\\text{ if at least one $a_i$ is odd},\\\\\n\\frac{2\\prod_{i=1}^{n}\\Gamma(b_i)}{\\Gamma(\\sum^{n}_{i=1}b_i)(n+\\sum_{i=1}^{n}a_i)}, b_i = \\frac{a_i+1}{2}, &\\text{ if all $a_i$ are even}.\n\\end{cases}\n\\end{align*}\n%\n%\n%\n%\\newpage\n%\n%\n\\section*{S\\hspace{0.5cm}Unit Sphere $S^{n-1} = \\{\\bx\\in\\R^n : \\xNorm{\\bx}{2} = 1\\}$}\n\\addcontentsline{toc}{section}{S\\hspace{0.5cm}Unit Sphere $S^{n-1} = \\{\\bx\\in\\R^n : \\xNorm{\\bx}{2} = 1\\}$}\n%\n%\n\\subsection*{S.1\\hspace{0.5cm}Inner Products}\n\\addcontentsline{toc}{subsection}{S.1\\hspace{0.5cm}Inner Products}\nFor two vectors $\\ba,\\bb\\in\\R^n$ define the function\n\\begin{align*}\nf\\colon S^{n-1}\\to\\R, \\bx \\mapsto f(\\bx) = (\\ba\\cdot\\bx)(\\bb\\cdot\\bx).\n\\end{align*}\nFrom Proposition~2 in \\cite{KhanPinsky2003} we know\n\\begin{align*}\n\\int_{S^{n-1}} f(\\bx) \\d\\bx = \\frac{\\abs{S^{n-1}}}{n}(\\ba\\cdot\\bb).\n\\end{align*}\nFor $n > 1$ we have $\\abs{S^{n-1}} = \\frac{2\\pi^{n/2}}{\\Gamma(n/2)}$.\nFor $n=1$ we have $S^{n-1} = \\{-1,1\\}$ and therefore the integral is zero.\n%\n%\n%\n\\subsection*{S.2\\hspace{0.5cm}Polynomials}\n\\addcontentsline{toc}{subsection}{S.2\\hspace{0.5cm}Polynomials}\nFor non-negative integers $a_1,\\ldots,a_n$, $a_i\\in\\{0,1,2,\\ldots\\}$, define the monomial\n\\begin{align*}\nf\\colon S^{n-1}\\to\\R, \\bx \\mapsto f(\\bx) = \\prod_{i=1}^{n}x_i^{a_i}.\n\\end{align*}\nFor $n >1$ we know from \\cite{Folland2001} that\n\\begin{align*}\n\\int_{S^{n-1}} f(\\bx) \\d\\bx =\n\\begin{cases}\n0, &\\text{ if at least one $a_i$ is odd},\\\\\n\\frac{2\\prod_{i=1}^{n}\\Gamma(b_i)}{\\Gamma(\\sum^{n}_{i=1}b_i)}, b_i = \\frac{a_i+1}{2}, &\\text{ if all $a_i$ are even}.\n\\end{cases}\n\\end{align*}\nFor $n=1$ we have $S^{n-1} = \\{-1,1\\}$ and therefore the integral is zero.\n%\n%\n%\n\\section*{Tables of Integration Functions}\n\\addcontentsline{toc}{section}{Tables of Integration Functions}\nThe following Tables~\\ref{table_Pn}--\\ref{table_sphere} provide an overview over the available functions by integration domain.\nThe first column shows the S4 class name within the package, while the last column provides a reference to the relevant subsection in this document.\n%\n%\n%\n\\begin{landscape}\n\\begin{table}\n\\center\n\\begin{tabular}{llllll}\n%{p{2.0cm}p{3.0cm}p{3.0cm}p{4.0cm}}\n\\hline\\hline\n\\rule{0pt}{3ex}\nPn\\_& Parameters &  $f(\\bfx)=$ & exact value & Properties & Details\\\\\n\\hline\n\\rule{0pt}{4ex}\nlognormalDensity & $n,\\in\\N,\\mu\\in\\R^n, \\Sigma\\in\\R^{n\\times n}$ & $\\frac{\\exp(-((\\ln(\\bx)-\\mu)^{T}\\Sigma^{-1}(\\ln(\\bx)-\\mu))/2)}{\\prod_{i=1}^{n}x_i \\sqrt{(2\\pi)^n\\det(\\Sigma)}}$ & $1.0$ & $C^{\\infty}$ & P.1\\\\\n\\rule{0pt}{4ex}\nlogtDensity & $n,\\in\\N,\\delta\\in\\R^n, \\Sigma\\in\\R^{n\\times n},\\nu>0$ & (see P.2) & $1.0$ & $C^{\\infty}$ & P.2\\\\\n\\hline\\hline\n\\end{tabular}\n\\caption{Functions with integration domain $[0,\\infty)^n$.}\n\\label{table_Pn}\n\\end{table}\n\\end{landscape}\n%\n%\n%\n%\n%\n\\begin{landscape}\n\\begin{table}\n\\center\n\\begin{tabular}{llllll}\n%{p{2.0cm}p{3.0cm}p{3.0cm}p{4.0cm}}\n\\hline\\hline\n\\rule{0pt}{3ex}\nRn\\_& Parameters &  $f(\\bfx)=$ & exact value & Properties & Details\\\\\n\\hline\n\\rule{0pt}{4ex}\nGauss & $n \\in \\N$ & $\\exp(-\\xNorm{\\bfx}{2}^2)$ & $\\pi^{n/2}$ & $C^{\\infty}$ & R.1\\\\\n\\rule{0pt}{4ex}\nfloorNorm & $n \\in \\N$, $s > 1$ & $\\frac{\\Gamma(n/2+1)}{\\pi^{n/2}(1+\\floor{\\Vert \\bfx \\Vert_2^n})^s}$ & $\\zeta(s)$ & non-continuous & R.2\\\\\nnormalDensity & $n,\\in\\N,\\mu\\in\\R^n, \\Sigma\\in\\R^{n\\times n}$ & $\\frac{\\exp(-((\\bx-\\mu)^{T}\\Sigma^{-1}(\\bx-\\mu))/2)}{\\sqrt{(2\\pi)^n\\det(\\Sigma)}}$ & $1.0$ & $C^{\\infty}$ & R.3\\\\\ntDensity & $n,\\in\\N,\\delta\\in\\R^n, \\Sigma\\in\\R^{n\\times n}, \\nu>0$ & (see R.4) & $1.0$ & $C^{\\infty}$ & R.4\\\\\n\\hline\\hline\n\\end{tabular}\n\\caption{Functions with integration domain $\\R^n$.}\n\\label{table_Rn}\n\\end{table}\n\\end{landscape}\n%\n%\n%\n%\n\\begin{landscape}\n\\begin{table}\n\\center\n\\begin{tabular}{llllll}\n%{p{2.0cm}p{3.0cm}p{3.0cm}p{4.0cm}}\n\\hline\\hline\n\\rule{0pt}{3ex}\nstandardSimplex\\_ & Parameters &  $f(\\bfx)=$ & exact value & Properties & Details\\\\\n\\hline\n\\rule{0pt}{4ex}\nDirichlet & $n \\in \\N$, $\\bfv \\in (0,\\infty)^{n+1}$ & $\\prod_{i=1}^{n}x_i^{v_i-1}(1 - \\sum^{n}_{i=1}x_i)^{v_{n+1}-1}$ & $\\frac{\\prod_{i=1}^{n+1}\\Gamma(v_i)}{\\Gamma(\\sum_{i=1}^{n+1}v_i)}$ & $C^{\\infty}$ & T.1\\\\\n\\rule{0pt}{4ex}\nexp\\_sum & $n \\in \\N$, $c>0$ & $\\exp(-c(x_1+\\ldots+x_n))$ & $\\frac{\\Gamma(n)-\\Gamma(n,c)}{\\Gamma(n)c^n}$ & $C^{\\infty}$ & T.2\\\\\n\\hline\\hline\n\\end{tabular}\n\\caption{Functions with integration domain $T_n$.}\n\\label{table_simplex}\n\\end{table}\n\\end{landscape}\n\n\\begin{landscape}\n\\begin{table}\n\\center\n\\begin{tabular}{llllll}\n%{p{2.0cm}p{3.0cm}p{3.0cm}p{4.0cm}}\n\\hline\\hline\n\\rule{0pt}{3ex}\nunitCube\\_ & Parameters &  $f(\\bfx)=$ & exact value & Properties & Details\\\\\n\\hline\n\\rule{0pt}{4ex}\ncos2 & $n \\in \\N$, $\\bfv \\in \\R^n \\setminus \\mathbf{0}_n$ & $\\left(\\cos(\\bfv\\cdot\\bfx)\\right)^2$ & $\\frac{1}{2}+\\frac{1}{2}\\cos(\\bfv\\cdot\\mathbf{1}_n)\\prod_{k=1}^{n}\\frac{\\sin(v_k)}{v_k}$ & $C^{\\infty}$ & C.1\\\\\n\\rule{0pt}{4ex}\nfloor & $n \\in \\N$ & $\\floor{x_1+\\ldots+x_n}$ & $(n-1)/2$ & non-continuous & C.2\\\\\\rule{0pt}{4ex}\nmax & $n \\in \\N$ & $\\max(x_1,\\ldots,x_n)$ & $n/(n+1)$ & continuous, non-differentiable & C.3\\\\\n\\hline\\hline\n\\end{tabular}\n\\caption{Functions with integration domain $C_n=[0,1]^n$.}\n\\label{table_cube}\n\\end{table}\n%\n\\end{landscape}\n\n\n\n\n\n\n\n\n\\begin{landscape}\n\\begin{table}\n\\center\n\\begin{tabular}{llllll}\n%{p{2.0cm}p{3.0cm}p{3.0cm}p{4.0cm}}\n\\hline\\hline\n\\rule{0pt}{3ex}\nunitBall\\_ & Parameters &  $f(\\bfx)=$ & exact value & Properties & Details\\\\\n\\hline\n\\rule{0pt}{4ex}\nnormGauss & $n \\in \\N$ & $\\frac{1}{(2\\pi)^{n/2}}\\exp(-\\xNorm{\\bfx}{2}^2/2)$ & $F_{\\chi^2_n}(1)$ & $C^{\\infty}$ & B.1\\\\\n\\rule{0pt}{4ex}\npolynomial & $n \\in \\N$, $\\bfa\\in\\{0,1,2,\\ldots\\}^n$ & $\\prod_{i=1}^{n}x_i^{a_i}$ & (see details) & $C^{\\infty}$ & B.2\\\\\n\\hline\\hline\n\\end{tabular}\n\\caption{Functions with integration domain $B_n$.}\n\\label{table_ball}\n\\end{table}\n\\end{landscape}\n\n\n\n\\begin{landscape}\n\\begin{table}\n\\center\n\\begin{tabular}{llllll}\n%{p{2.0cm}p{3.0cm}p{3.0cm}p{4.0cm}}\n\\hline\\hline\n\\rule{0pt}{3ex}\nunitSphere\\_ & Parameters &  $f(\\bfx)=$ & exact value & Properties & Details\\\\\n\\hline\n\\rule{0pt}{4ex}\ninnerProduct1 & $n \\in \\N$, $\\ba,\\bb\\in\\R^n$ & $(\\ba\\cdot\\bx)(\\bb\\cdot\\bx)$ & $\\frac{\\abs{S^{n-1}}}{n}(\\ba\\cdot\\bb)$ & $C^{\\infty}$ & S.1\\\\\n\\rule{0pt}{4ex}\npolynomial & $n \\in \\N$, $\\bfa\\in\\{0,1,2,\\ldots\\}^n$ & $\\prod_{i=1}^{n}x_i^{a_i}$ & (see details) & $C^{\\infty}$ & S.2\\\\\n\\hline\\hline\n\\end{tabular}\n\\caption{Functions with integration domain $S^{n-1}$.}\n\\label{table_sphere}\n\\end{table}\n\\end{landscape}\n\n\n\\bibliography{bibDocumentationTestFunctions}{}\n\\bibliographystyle{plain}\n\n%\\begin{thebibliography}{100}  % 100 is a random guess of the total number of %references\n%\\bibitem{Folland2001}[Folland (2001)] Gerald B. Folland, How to Integrate a Polynomial over a Sphere. The American Mathematical Monthly, Vol. 108, No. 5 (May, 2001), pp. 446-448.\n%\\bibitem{KhanPinsky2003}[Khan and Pinsky (2003)] Khan, T., Pinsky, M. (2003). On some integrals over a unit sphere. Technical report.\n%\\end{thebibliography}\n\n\\end{document}\n\n\\begin{abstract}\n%Third, the introduced risk measure is defined for random vectors instead of random variables.\n\\end{abstract}\n%\n%\n\n\n\n\n\\section{Numerical Integration Based on Quasi Random Numbers}\n\\subsection{Monte Carlo Integration for $A\\subsetneq \\R^n$}\nTo explain the code in the vignette it is beneficial to review Monte Carlo integration.\nMonte Carlo integration is the simplest multivariate integration scheme and serves as a standard.\nIf we are interested in integrating a multivariate function $f$ over a domain $A \\subsetneq \\R^n$ we can resort to Monte Carlo integration if we can generate uniformly distributed (pseudo) random numbers over a set $B$ such that $A \\subseteq B$ and $\\leb(B)>0$.\n\\begin{align*}\n\\int_{A} f(\\bfx) \\d \\bfx\n&= \\int_{B} f(\\bfx) \\ind{A}(\\bfx) \\frac{\\leb(B)}{\\leb(B)} \\d \\bfx\n=  \\leb(B)\\int_{B} f(\\bfx) \\ind{A}(\\bfx)  \\frac{1}{\\leb(B)}\\d \\bfx\n= \\leb(B) \\E[f(\\bfU) \\ind{A}(\\bfU)]\\\\\n&\\approx \\leb(B) \\frac{1}{n}\\sum^{n}_{i=1} f(\\bfU_i) \\ind{A}(\\bfU_i).\n\\end{align*}\n\n\\subsection{Integration over $\\R^n$}\n$\\bfX$ with density $h(\\bfx)>0$\n\\begin{align*}\n\\int_{\\R^n} f(\\bfx) \\d \\bfx\n&= \\int_{\\R^n} f(\\bfx) \\frac{h(\\bfx)}{h(\\bfx)} \\d \\bfx\\\\\n& = \\int_{\\R^n} \\frac{f(\\bfx)}{h(\\bfx)} h(\\bfx) \\d \\bfx\\\\\n&= \\E[f(\\bfX)/h(\\bfX)]\\\\\n&\\approx \\frac{1}{n} \\sum^{n}_{i=1} f(\\bfX_i)/h(\\bfX_i)\n\\end{align*}\n\n\n%\\bibliographystyle{apalike}\n\\bibliographystyle{plainnat}\n\\bibliography{references}\n\\end{document}\n%% End:\n", "meta": {"hexsha": "e64b2492c2af3a725e4f7080639fabb474e3dfef", "size": 20739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation_test_functions.tex", "max_stars_repo_name": "KlausHerrmann/multIntTestFunc", "max_stars_repo_head_hexsha": "47b044b65066b38f5e8b25fd3682353f6fa38cce", "max_stars_repo_licenses": ["MIT"], "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_test_functions.tex", "max_issues_repo_name": "KlausHerrmann/multIntTestFunc", "max_issues_repo_head_hexsha": "47b044b65066b38f5e8b25fd3682353f6fa38cce", "max_issues_repo_licenses": ["MIT"], "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_test_functions.tex", "max_forks_repo_name": "KlausHerrmann/multIntTestFunc", "max_forks_repo_head_hexsha": "47b044b65066b38f5e8b25fd3682353f6fa38cce", "max_forks_repo_licenses": ["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.5027124774, "max_line_length": 261, "alphanum_fraction": 0.6487294469, "num_tokens": 8533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619306896956, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.67597083905855}}
{"text": "\\lab{Importance Sampling}{Importance Sampling}\n\\objective{Though Monte Carlo integration is a useful strategy for estimating integrals, the standard implementation suffers slow convergence and can be inaccurate.\nThis typically occurs when the domain of integration is very small, making it unlikely that very many, if any, randomly chosen points will lie inside of it.\nImportance sampling remedies this problem by choosing the sample points more intelligently.\nThis situation happens most frequently when trying to approximate integrals of probability distributions, so we focus on integrating common probability density functions.}\n\n\\section*{Monte Carlo Simulation} % ===========================================\n\nThe standard procedure of Monte Carlo integration is not always the most efficient or accurate way to estimate an integral.\nConsider the probability density function (p.d.f) of the standard normal distribution in one dimension,\n\\begin{equation}\nf_X(t) = \\frac{e^{-t^2/2}}{\\sqrt{2\\pi}}.\n\\label{eq:imsamp-standard-normal}\n\\end{equation}\nThe probability that a random draw from the standard normal distribution is greater than $3$ is given by the integral\n\\begin{equation}\n\\int_{3}^{\\infty} f_X(t)\\,dt = \\frac{1}{\\sqrt{2\\pi}}\\int_{3}^{\\infty} e^{-t^2/2}\\:dt.\n\\label{eq:importsamp-integral}\n\\end{equation}\n\nIf $h: \\mathbb{R} \\rightarrow \\mathbb{R}$ is the indicator function defined by\n\\[\nh(t) = \\begin{cases}\n1 & \\text{ if } t > 3 \\\\\n0 & \\text{ if } t \\leq 3,\n\\end{cases}\n\\]\nthen \\eqref{eq:importsamp-integral} can be rewritten as\n\\begin{equation}\n\\int_{3}^{\\infty} f_X(t)\\:dt = \\int_{-\\infty}^{\\infty} h(t)f_X(t)\\:dt.\n\\label{eq:infinity_integral}\n\\end{equation}\nNote that this process can be generalized to any domain of integration by redefining the indicator function $h$ to match different bounds of integration.\n\nWe can now easily estimate this same probability using Monte Carlo simulation.\nGiven a random collection of draws $\\{x_i\\}_{i=1}^N$ from the standard normal distribution, we can estimate the integral from \\eqref{eq:infinity_integral} as\n\\begin{equation}\n\\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt \\approx \\frac{1}{N}\\sum_{i = 1}^{N}h(x_i).\n\\label{eq:importsamp-estimator}\n\\end{equation}\n% Now that the estimator is defined, it is quite manageable to approximate \\eqref{eq:importsamp-integral}.\n% The estimate will get closer and closer to the actual value as more and more sample points are used.\n\n\\section*{Statistics with SciPy} % ============================================\nThe \\li{scipy.stats} module has many features for probability and statistics.\nOne of the most effective uses of \\li{scipy.stats} is to create an object for a particular distribution with the following methods:\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Method & Description\\\\\n    \\hline\n    \\li{cdf()} & Calculate the cumulative probability evaluated up to a point.\\\\\n    \\li{pdf()} & Calculate the probability of drawing a number from a distribution.\\\\\n    \\li{rvs()} & Draw a random number from the distribution.\\\\\n\\end{tabular}\n% \\caption{Some methods available for a distribution from scipy.stats.}\n\\end{table}\n\nThe following code shows how to appropriately use the methods of \\li{stats} objects.\n\\begin{lstlisting}\n>>> from scipy import stats\n>>> import numpy as np\n\n# Create an object for the standard normal distribution.\n>>> F = stats.norm()\n# loc is the mean and scale is the standard deviation.\n>>> G = stats.norm(loc=3, scale=2)\n\n# Calculate the probability of drawing a 1 from the normal distribution.\n>>> F.pdf(1)\n0.24197072451914337\n\n# Draw a number at random from the normal distribution.\n>>> F.rvs()\n0.95779975\n\n# Specifying a size returns a numpy.ndarray.\n>>> F.rvs(size=2)\narray([-0.40375954, 1.10956538])\n\n\\end{lstlisting}\n\nUse \\li{np.linspace()} and \\li{pdf()} in order to plot a distribution.\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n# Create a linspace for our graph.\n>>> X = np.linspace(-4, 4, 100)\n# Use the normal distribution created previously.\n>>> plt.plot(X, F.pdf(X))\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Object & Description\\\\\n    \\hline\n    \\li{norm()} & The normal distribution.\\\\\n    \\li{gamma()} & The gamma distribution.\\\\\n    \\li{multivariate_normal()} & The normal distribution in higher dimensions.\\\\\n    \\li{beta()} & The beta distribution.\n\\end{tabular}\n% \\caption{Some methods from scipy.stats.}\n\\end{table}\n\n% See Appendix \\ref{appendix:stats-prob-tools} for a more thorough treatment of \\li{scipy.stats}.\n\n\\begin{problem}\n\\label{prob:importsamp-mc}\nWrite a function that accepts an integer parameter $N$.\nUse \\eqref{eq:importsamp-estimator} to estimate the probability that a random draw from the standard normal distribution is greater than $3$ using $N$ samples.\nReturn the approximation.\nYour answer should approach 0.0013499 for sufficiently large samples.\n\\end{problem}\n\nIn Monte Carlo integration, each random point that is in the region of interest (in this case a number greater than $3$) increases the approximation, and each random point that is not in that region decreases the approximation.\nIf draws in the region of interest are unlikely, then it is possible that no random draws end up within the region of interest.\nThe Monte Carlo integration method returns an approximation of $0$ for the integral in this case, which isn't ideal.\nSo, while standard Monte Carlo integration can get the job done if enough points are used, getting a good approximation requires an unacceptably large number of sample points.\n\n\\section*{Importance Sampling} % ==============================================\n\nImportance sampling makes Monte Carlo integration more efficient in circumstances where random draws within the region of interest are unlikely.\nNote that in Monte Carlo integration, random points that are close to and within the bounds of integration are more likely to influence the approximation than points that are farther away.\nWe call these closer points \\emph{important} points.\nIn importance sampling, we call the distribution of the integral we want to estimate the \\emph{target distribution}, and we usually denote it $f_X$.\nThe idea of importance sampling is to choose a new distribution, called the \\emph{importance distribution}, that generates more important points.\nThe importance distribution is usually denoted $g_Y$.\nWe then modify \\eqref{eq:importsamp-estimator} to take advantage of the importance distribution:\n\\begin{equation} \\label{eq:importsamp-importance}\n\\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt \\approx \\frac{1}{N}\\sum_{i = 1}^{N}\\frac{h(y_i)f_X(y_i)}{g_Y(y_i)}.\n\\end{equation}\n\nThe fraction $\\frac{f_X}{g_Y}$ is called the \\emph{importance weight}.\nBecause of this result, we can use samples $y_1, \\cdots , y_N$ from any distribution with equation $g_Y$ to estimate the integral of $f_X$, as long as we multiply $h(y_i)$ by the importance weight.\nNote that if the importance distribution is chosen to be the same as the target distribution, or in other words, if we draw from the same distribution we are trying to estimate, then $g_Y = f_X$ and the importance weight is 1.\nIn this case, the importance sampling method reduces to the original Monte Carlo simulation given by \\eqref{eq:importsamp-estimator}.\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{figures/importance_distribution.pdf}\n\\caption{In our problem, we choose an importance distribution that will generate more samples that are greater than 3. Though not a perfect choice, choosing a normal distribution with $\\mu = 4$ and $\\sigma = 1$ will suffice.}\n\\label{fig:importance}\n\\end{figure}\n\n\\begin{info}\nThe derivation of \\eqref{eq:importsamp-importance} is based heavily on the \\emph{Law of the Unconscious Statistician}, an important idea in statistics.\nSee the Additional Materials section for details.\n\\end{info}\n\n\\subsection*{Choosing the Importance Distribution} % --------------------------\n\nThere is no correct choice for the importance distribution.\nIt may be possible to find the distribution that allows the simulation to converge the fastest, but oftentimes, the perfect answer is unnecessary.\nClose to perfect is good enough.\n\nTo solve the same problem as in Problem \\ref{prob:importsamp-mc} using importance sampling, we choose a distribution that will generate more samples close to and greater than 3.\nWe will choose $g_Y$ to be the normal distribution with mean $\\mu = 4$ and standard deviation $\\sigma = 1$.\nNote that it is not necessary to choose an importance distribution of the same type as the target distribution.\n\nFigure \\ref{fig:importance} shows that a random draw from the importance distribution is far more likely to produce a number greater than 3 than a random draw from the target distribution.\nHowever, a draw greater than 3 from the importance distribution is accompanied by a low importance weight because it is so unlikely in the target distribution.\nSimilarly, a draw less than 3 from the importance distribution has a higher importance weight because it is more likely in the target distribution.\n\n\\begin{problem} \\label{prob:importsamp-mc_important}\nWrite a function that accepts a function handle $f$, representing the equation for the target distribution, a function handle $g$, representing the equation for the importance distribution, an indicator function $h$, a function that samples from the importance distribution, and an integer $n$ representing the number of samples to use.\nUse \\eqref{eq:importsamp-importance} to approximate the integral of the target distribution and return this approximation.\n\nTo test your function, estimate the same integral as in Problem \\ref{prob:importsamp-mc} using importance sampling.\nChoose the importance distribution to be a normal distribution with mean $\\mu = 4$ and standard deviation $\\sigma = 1$ as shown below.\nYour answer should approach $0.0013499$ for large samples.\nWhen compared to Problem \\ref{prob:importsamp-mc} this should give more consistent results.\n\n\\begin{lstlisting}\n# Choose the importance distribution with mean 4 and std dev 1\n>>> G = stats.norm(loc=4, scale=1)\n>>> g = G.pdf                   # Equation for importance distribution\n>>> sampler = G.rvs             # Samples from importance distribution\n\\end{lstlisting}\n\n\\end{problem}\n\n\\begin{problem} \\label{prob:importsamp-mc_is_compare}\nUsing the two previous problems, create a plot that compares the error of the traditional method of Monte Carlo integration to the error of the importance sampling method.\nChoose your target distribution to be the standard normal distribution, and estimate the probability that a random draw is greater than $3$.\nChoose your importance distribution to be the same one you used to test Problem \\ref{prob:importsamp-mc_important}.\nYou should calculate the errors for $n = 5000, 10000, \\ldots , 500000$.\nYour plot should resemble the following figure.\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{figures/MCvsIS.pdf}\n\\label{fig:compare}\n\\end{figure}\n\nTo determine the error of your approximations, the following code returns the actual value of the probability:\n\\begin{lstlisting}\n>>> 1 - stats.norm.cdf(3)\n\\end{lstlisting}\n\\end{problem}\n\nProblem \\ref{prob:importsamp-mc_is_compare} shows that we can achieve the same results as traditional Monte Carlo with only a fraction of the samples if we choose an appropriate importance distribution.\nHowever, even though there is no correct choice for an importance distribution, there are choices that do not give a better approximation of an integral than the Monte Carlo method would without importance sampling.\nIn Problem \\ref{prob:importsamp-mc_important}, we chose a normal distribution with $\\mu = 4$ and $\\sigma = 1$ to be our importance distribution to test the function.\nThis produces more points larger than $3$ to use for our integral estimation.\nIf we had chosen a normal distribution that was less likely to produce points larger than $3$, say for example a normal distribution with $\\mu = 0$ and $\\sigma = .5$, importance sampling would actually give a larger error than the traditional Monte Carlo method would alone.\nIn addition, if we had chosen a normal distribution that produced hardly any points less than $3$, the approximation using importance sampling would also be worse.\nWe examine this further in the next problem.\n\n\\begin{problem} \\label{prob:other_plots}\nImportance Sampling is only as good as the choice of $g_Y$.\nRepeat the previous problem of plotting the error for the estimates that a random draw from the standard normal distribution is greater than 3.\nDo this for various $g_Y$ by creating 4 subplots.\nEach plot displays the error for traditional Monte Carlo as well as the errors of importance sampling for a specific $g_Y$.\nEach plot has a different $g_Y$, which will change the importance sampling error.\nIn all cases let $g_Y$ be a normal distribution with $\\sigma =1$, but let $\\mu = -1, .25, 4, 7$.\n\\end{problem}\n\n\\section*{Generalizing the Principles of Importance Sampling} % ===============\n\nUp to this point, the target distributions and the importance distributions have all been normal distributions.\nImportance sampling works for other types of distributions as well, and even works when the target distribution and the importance distribution are different from each other.\nThe following problem is an example of this, and gives a potential real world application for importance sampling.\n\n\\begin{problem}\n\\label{prob:importsamp-gamma}\nA tech support hotline receives an average of 2 calls per minute.\nWhat is the probability that they will have to wait at least 10 minutes to receive 9 calls?\nThis problem can be modeled using a gamma distribution.\nThe equation for calculating the probability of the gamma distribution is\n\\begin{align}\nf_X(x) = \\frac{x^{a-1}e^{-x/\\theta}}{\\Gamma(a)\\theta^a}.\n\\end{align}\nHere $a$ is the number of calls we are waiting to receive, $\\theta$ is the number of minutes it takes on average to receive one call, and $x$ is the number of minutes needed to wait to receive $a$ calls given $\\theta$ calls per minute.\nIn the above problem, we have $a = 9$, $\\theta = .5$, and we want the probability that $x \\geq 10$.\nCreating the gamma distribution object in \\li{scipy.stats} is similar to creating the normal distribution object.\nIt has the same methods as the normal distribution object.\n\n\\begin{lstlisting}\n# Create the gamma distribution object with a = 9, theta = .5\n>>> F = stats.gamma(a=9, scale=.5)\n\\end{lstlisting}\n\nWrite a function that estimates and returns the probability of having to wait at least $10$ minutes to receive $9$ calls.\nUse a normal distribution with mean and standard deviation of your choosing as the importance distribution.\nChoose a large enough number of sample points so that the integral is estimated accurately.\nYour answer should approach $0.00208726$.\n\\end{problem}\n\nIn addition to single variable distributions, importance sampling can be used to approximate integrals of multivariate functions.\nThe joint normal distribution of $N$ independent random variables with mean $\\0$ and covariance matrix $I$ is\n\\[\nf_X(\\x) = \\frac{1}{\\sqrt{(2 \\pi)^N}} e^{-(\\x^T\\x)/2}.\n\\]\nThe integral of $f_X(\\x)$ over a box is the probability that a draw from the distribution will be in the box.\nHowever, $f_X(\\x)$ does not have a symbolic antiderivative.\nImportance sampling can be used here to efficiently estimate the integral of this function.\nIn the multivariate case, the importance distribution must also be multivariate.\nThe multivariate normal distribution object in \\li{scipy.stats} accepts a mean vector and a covariance matrix as parameters.\nThe \\li{pdf} and \\li{rvs} methods work the same as in the single variable case, except that \\li{pdf} accepts an array of size $N$ and \\li{rvs} returns an array of size $n$ x $N$, where $n$ is the number of samples to draw.\n\\begin{lstlisting}\n# Create a 2-dim multivariate normal object with a zero vector mean and cov matrix I\n>>> F = stats.multivariate_normal(mean=np.zeros(2), cov=np.eye(2))\n>>> F.pdf(np.array([1,1]))\n0.058549831524319168\n>>> F.rvs(size=3)\narray([[ 0.03429396,  0.13618787],\n       [-0.12011818,  0,88691591],\n       [-0.16356289,  0.53757853]])\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that estimates and returns the probability that a given random variable in $\\mathbb{R}^2$ generated by $f_X$ will be less than -1 in the x-direction and greater than 1 in the y-direction.\nTreat $f_X$ as the equation of your target distribution.\nCreate your own multivariate normal distribution with mean and covariance matrix of your choosing to serve as your importance distribution.\nAs in the previous problem, choose a large enough number of sample points so that the integral is estimated accurately.\nYour answer should approach $0.02517149$.\n\nHint: The indicator function may have to be coded differently from previous problems to accommodate for the fact that the sampler for the multivariate normal distribution returns a two dimensional array.\nRemember that when given an array of samples, the indicator function needs to return either a $0$ or a $1$ for each sample in the array.\n\\end{problem}\n\n\\newpage\n\\section*{Additional Material}\n\n\\subsection*{Derivation of the importance sampling estimator}\n\nBy the Law of the Unconscious Statistician (see Volume 2 \\S 3.5), we can restate the integral from \\eqref{eq:importsamp-integral} as\n\n$$\\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt = E[h(X)].$$\n\nThen we have\n\n\\begin{align*}\nE[h(X)] & = \\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt \\\\\n& = \\int_{-\\infty}^{\\infty} h(t)f_X(t)\\left ( \\frac{g_Y(t)}{g_Y(t)} \\right )\\,dt \\\\\n& = \\int_{-\\infty}^{\\infty} \\left ( \\frac{h(t)f_X(t)}{g_Y(t)} \\right )g_Y(t)\\,dt \\\\\n& = E\\left[\\frac{h(Y)f_X(Y)}{g_Y(Y)}\\right],\n\\end{align*}\nand the corresponding estimator is\n\n\\begin{align*}\n\\widehat{E}[h(X)] & = \\widehat{E}\\left [ \\frac{h(Y)f_X(Y)}{g_Y(Y)}\\right ] \\\\\n& = \\frac{1}{N}\\sum_{i = 1}^{N}\\frac{h(y_i)f_X(y_i)}{g_Y(y_i)}.\n\\end{align*}\n\n\\subsection*{Unnormalized Target Densities} % ---------------------------------\n\nThe methods discussed so far are only applicable if the target density is normalized, or in other words, has an integral of 1. If the target density is not normalized, \\eqref{eq:importsamp-importance} becomes\n\n\\begin{align*}\nE[h(X)] & = \\frac{\\int h(t)f(t)\\,dt}{\\int f(t)\\,dt} \\\\\n& = \\frac{\\int h(t)f(t) \\left ( \\frac{g_Y(t)}{g_Y(t)} \\right )\\,dt}{{\\int f(t)} \\left ( \\frac{g_Y(t)}{g_Y(t)} \\right )\\,dt} \\\\\n& = \\frac{\\int \\left ( \\frac{h(t)f(t)}{g_Y(t)} \\right ) g_Y(t)\\,dt}{\\int \\left ( \\frac{f(t)}{g_Y(t)} \\right ) g_Y(t)\\,dt} \\\\\n& = \\frac{E\\left [ \\frac{h(Y)f(Y)}{g_Y(Y)}\\right ]}{E\\left [ \\frac{f(Y)}{g_Y(Y)}\\right]}.\n\\end{align*}\nThe corresponding estimator is\n\\begin{align*}\n\\widehat{E}_n[h(X)] & = \\frac{\\widehat{E}\\left [ \\frac{h(Y)f(Y)}{g_Y(Y)}\\right ]}{\\widehat{E}\\left [ \\frac{f(Y)}{g_Y(Y)}\\right ]} \\\\\n& = \\frac{\\frac{1}{N}\\sum_{i = 1}^{N}\\frac{h(y_i)f(y_i)}{g_Y(y_i)}}{\\frac{1}{N}\\sum_{i = 1}^{N}\\frac{f(y_i)}{g_Y(y_i)}}.\n\\end{align*}\n", "meta": {"hexsha": "ee39d5e1366d7c4c3157c546bde59f1ef5be1940", "size": 18994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume1/ImportanceSampling/ImportanceSampling.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/ImportanceSampling/ImportanceSampling.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/ImportanceSampling/ImportanceSampling.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": 59.1713395639, "max_line_length": 336, "alphanum_fraction": 0.746656839, "num_tokens": 4837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6759708301257574}}
{"text": "\\documentclass[10pt,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\\usepackage{enumitem}\n\\title{Latex Example Live}\n\\author{Sebastiano Tronto}\n\\date{20-02-2021}\n\n\\newcommand{\\reals}{\\mathbb{R}}\n\\DeclareMathOperator{\\sinus}{sinus}\n\n\n\\newtheorem{mythm}{My Theorem}[section]\n\n\\theoremstyle{definition}\n\\newtheorem{prop}[mythm]{Proposition}\n\\newtheorem{defi}{Definition}\n\n\\theoremstyle{remark}\n\\newtheorem*{warning}{Achtung}\n\n\\usepackage{xcolor}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\n{\\color{pink} Hello, world!\n\nThis is a comment}\n\n\\texttt{This looks like computer code}\n\n\\section{Text}\n\n\\textbf{This sentence is in boldface}\n\n\\underline{\\textit{italicized} maybe in a sentence \\textbf{something}}\n\n\\underline{\\textit{one inside the other}}\n\n\\emph{also italicized???}\n\nThis is an important sentence, maybe a quote or something, and this \\emph{word} is very important. Let's make this sentence longer than one line.\n\n{\\Huge Large words}\n\n%\\appendix\n\n\\section{Math mode}\n\nThis is an inline formula \\( \\displaystyle \\sum_i \\frac{i}{22} \\), it appears within the text\n\nThis is a displaystyle formula \\[ \\textstyle \\sum_{\\alpha=0}^{2^{10}}   \\frac2 \\alpha{22} \\] it appears on its own line\n\nHow sqrt works: \\( \\sqrt[\\phi]{25} \\)\n\n\n\n\\begin{flalign}\n\\label{eq}\ne^x &= \\left(\\sum_{i=0}^\\infty \\frac{x^i}{i!} \\right) = & \\\\\n&= \\left( 1 + x  + \\frac{x^2}2  \\right)+ \\frac{x^3}{6} + \\cdots \\nonumber\n\\end{flalign}\n\n\\[\n   \\left\\{ x \\in \\reals \\quad \\text{such that} \\quad \\frac{ \\sinus(x)}{x^2}>0 \\right\\}\\reals\n\\]\n\n\\[ \\sum_i \\]\n\nThe first equation we wrote is \\eqref{eq}\n\n\\section{Environments}\n\n\\subsection{Lists}\n\\label{subsectionLists}\n\n\\begin{itemize}\n\t\\item One \\textbf{item}\n\t\\item Another \\(2+2=4\\)\n\t\\item a third one \\[\\sum_{i=0}^n\\]\n\t\\item A sublist:\n\t\t\\begin{itemize}\n\t\t\t\\item[+] First subitem\n\t\t\t\\item[+] and so on\n\t\t\\end{itemize}\n\t\\item Again in the main list\n\\end{itemize}\n\n\\begin{enumerate}[label=\\Roman*]\n\t\\item One\n\t\\item Two\n\t\\item Actually three\n\t\\item Three (or not)\n\\end{enumerate}\n\n\\subsection*{Tables}\n\nLet's write a table:\n\n\\vspace{1cm}\n\\begin{tabular}{r||l|c}\n\\hline\nThis is a table & second column & third column \\\\\n\\hline\nThings          & a             & \\( 2+2 = 4 \\)\\\\\n\\hline\nmore things     & b             & c\n\\end{tabular}\n\n\\vspace{1cm}\n\\[\n\t\\left(\\begin{array}{cc}\n\t\t\\int_0^1 e^x  &  \\frac{2}{25} \\\\\n\t\t0 & 0 \\\\\n\t\t1111 & 234\\alpha\n\t\\end{array}\\right)\n\\]\n\n\\[\n\t\\begin{pmatrix}\n\t\t\\int_0^1 e^x  &  \\frac{2}{25} \\\\\n\t\t0 & 0 \\\\\n\t\t1111 & 234\\alpha\n\t\\end{pmatrix}\n\\]\n\n\\[\n\\begin{pmatrix}\n1 & 2\\\\\n3 & 4\n\\end{pmatrix}\n\\overset{L2\\rightarrow L2+L3}\\longrightarrow\n\\begin{pmatrix}\n1 & 2\\\\\n4 & 6\n\\end{pmatrix}\n\\]\n\n\\section{Last section}\n\nIn section \\ref{subsectionLists} we saw how to write lists\n\n\\begin{mythm}[Gauss]\nThe equation \\(2+x=4\\) is true for \\(x=2\\).\n\\end{mythm}\n\n\\begin{prop}\nA less important fact\n\\end{prop}\n\n\\begin{defi}\na definition\n\\end{defi}\n\n\\begin{mythm}\nAnother important fact.\n\\end{mythm}\n\n\\begin{warning}\nIt is a common mistake to think that \\(2+2=5\\)\n\\end{warning}\n\\[\\binom45\\]\n\n\\[ 2 \\nmid 10 \\]\n\n\\end{document}", "meta": {"hexsha": "938002a6534e6dfed3eeab6d77ed119ff8ae8a0e", "size": 3200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/Lecture2/live/old.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/Lecture2/live/old.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/Lecture2/live/old.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": 18.1818181818, "max_line_length": 145, "alphanum_fraction": 0.67, "num_tokens": 1163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.6759705054393268}}
{"text": "\\section{Algebraic Integers}\r\n\\subsection{The Gaussian Integers}\r\nRecall the ring of Gaussian integers $\\mathbb Z[i]=\\{a+bi:a,b\\in\\mathbb Z\\}\\le\\mathbb C$ is a ED due to the norm $N(a+bi)=a^2+b^2$.\r\nHence $\\mathbb Z[i]$ is a PID hence UFD.\r\nIn particular irreducibles and primes are the same.\r\nThe units in $\\mathbb Z[i]$ are $\\pm 1,\\pm i$ by the norm $N$.\r\nBy convention, primes in $\\mathbb Z$ are positive (since others are associates to them), but there is no corresponding convention in the Gaussian Integers.\r\n\\begin{lemma}\r\n    If $\\pi\\in\\mathbb Z[i]$ is prime, then there is a unique prime $p\\in\\mathbb Z$ with $\\pi|p$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Since $\\pi$ is nonzero and nonunit, we can write $N(\\pi)=p_1\\cdots p_n$ where $p_i\\in\\mathbb Z$ are (not necessarily distinct) primes.\r\n    But $\\pi|\\pi\\bar\\pi=N(\\pi)=p_1\\cdots p_n$, so there is some $i$ such that $\\pi|p_i$.\\\\\r\n    For uniqueness, if $\\pi|p,\\pi|q$ with $p,q$ distinct primes in $\\mathbb Z$, then there is some $a,b\\in\\mathbb Z$ such that $ap+bq=1$, so $\\pi|1$, so $\\pi$ is a unit, contradiction.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $p\\in\\mathbb Z$ be a prime in $\\mathbb Z$, then the followings are equivalent:\\\\\r\n    1. $p$ is not prime in $\\mathbb Z[i]$.\\\\\r\n    2. $p$ can be written as the sum of two squares.\\\\\r\n    3. $p=2$ or $p\\equiv 1\\pmod{4}$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $1\\implies 2$: Write $p=xy$ where $x,y\\in\\mathbb Z[i]$ are not unit, then $p^2=N(p)=N(x)N(y)$.\r\n    But $x,y$ are not unit hence have $\\ge 1$ norm, therefore $N(x)=N(y)=p$, so $p$ is the sum of two squares.\\\\\r\n    $2\\implies 3$: Obvious.\\\\\r\n    $3\\implies 1$: $2=(1-i)(1+i)$, so $2$ is not prime.\r\n    Otherwise, for $p\\equiv 1\\pmod{4}$, then $-1=x^2\\pmod{p}$ is solvable, so $p|(x+i)(x-i)$.\r\n    If $p$ is prime in $\\mathbb Z[i]$, then either $p|x+i$ or $p|x-i$, none of which can happen.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    1. Every prime $p\\equiv 1\\pmod{4}$ in $\\mathbb Z$ is the sum of two integer squares $p=a^2+b^2$.\\\\\r\n    2. Primes in the Gaussian Integers (up to associates) are $1+i$, primes in $\\mathbb Z$ which congruent to $3\\bmod{4}$, and $a\\pm bi$ where $a,b$ are as in 1.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    1. The preceding lemma.\\\\\r\n    2. Let $\\pi\\in\\mathbb Z[i]$ be prime in $\\mathbb Z[i]$, then $\\pi|p$ for some prime $p\\in\\mathbb Z$.\r\n    If $p\\equiv 3\\pmod{4}$, then $p$ is prime in $\\mathbb Z[i]$ and $\\pi,p$ are associates.\\\\\r\n    Otherwise, $p=(a+ib)(a-ib)$ by the preceding lemma, so each of $a\\pm ib$ has norm $p$ hence is prime, so $\\pi$ is associate to one of $a\\pm ib$.\r\n    Note that $1+i,1-i$ are associates but $a\\pm ib$ are not associates otherwise by simple calculation.\r\n    This completes the proof.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Any integer $n\\ge 1$ is a sum of two squares iff every prime factor $p$ of $n$ with $p\\equiv 3\\pmod{4}$ divides $n$ to an even power.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $\\exists a,b\\in\\mathbb Z, n=a^2+b^2$ if and only if $n=N(x)$ for some $x\\in\\mathbb Z[i]$, which happens iff $n$ is a product of norms of primes in $\\mathbb Z[i]$, but by preceding theorem, the norms of primes in $\\mathbb Z[i]$ are either primes in $\\mathbb Z$ or the squares of primes congurent to $3\\bmod 4$.\r\n\\end{proof}\r\n\\begin{example}\r\n    $65=5\\cdot 13$, so $65$ is a sum of two squares.\r\n    Indeed $65=1+64=1+8^2$ does it.\r\n    Another way to get this sum is to write $65=(2+i)(2-i)(2+3i)(2-3i)=|(2+i)(2+3i)|^2=|1+8i|^2=1+8^2$.\r\n    We also have $65=|(2+i)(2-3i)|^2=|7-4i|^2=7^2+4^2$.\r\n\\end{example}\r\n\\subsection{Algebraic Integers}\r\n\\begin{definition}\r\n    Suppose $R\\le S$ are rings.\r\n    Given $\\alpha\\in S$, we write $R[\\alpha]$ for the smallest subring of $S$ containing both $R$ and $\\alpha$.\r\n\\end{definition}\r\nWe know that such a subring exists since we can collect all the candidates and take their intersection.\r\nIn fact, $R[\\alpha]=\\phi(R[X])$ where $\\phi:R[X]\\to S$ is the evaluation homomorphism $f(X)\\mapsto f(\\alpha)$.\r\n\\begin{definition}\r\n    If $R\\le S$ are fields and $\\alpha\\in S$, we write $R(\\alpha)$ to denote the smallest subfield of $S$ containing $R$ and $\\alpha$.\r\n\\end{definition}\r\nSo $R(\\alpha)$ is simply the field of fraction of $R[\\alpha]$.\r\n\\begin{definition}\r\n    1. $\\alpha\\in\\mathbb C$ is an algebraic number if $\\exists f\\in\\mathbb Q[X]\\setminus\\{0\\},f(\\alpha)=0$.\\\\\r\n    2. $\\alpha\\in\\mathbb C$ is an algebraic integer if $\\exists f\\in\\mathbb Z[X]$ such that the leading coefficient of $f$ is $1$ with $f(\\alpha)=0$.\r\n\\end{definition}\r\nLet $\\alpha$ be an algebraic number and $\\phi:\\mathbb Q[X]\\to\\mathbb C$ be the evaluation $f[X]\\mapsto f(\\alpha)$, then since $\\mathbb Q[X]$ is a PID, $\\ker\\phi=(f)$ for some $f\\in\\mathbb Q[X]$.\r\nSince $\\alpha$ is an algebraic number, $f\\neq 0$.\r\nWe may assume that $f$ is monic (since $\\mathbb Q$ is a field), so we say $f$ is the minimal polynomial of $\\alpha$.\r\nBy the isomorphism theorem, we have $\\mathbb Q[X]/(f)\\cong \\mathbb Q[\\alpha]\\le\\mathbb C$.\\\\\r\nBut $\\mathbb Q[\\alpha]$ is hence a integral domain, which means that $f$ is prime (hence irreducible as $\\mathbb Q[X]$ is a UFD), therefore $(f)$ is maximal (since $\\mathbb Q[X]$ is a PID), which means that $\\mathbb Q[\\alpha]=\\mathbb Q(\\alpha)$.\r\n\\begin{lemma}\r\n    Let $\\alpha$ be an algebraic number with minimal polynomial $f\\in\\mathbb Q[X]$.\r\n    Write $f=\\lambda f_0$ where $\\lambda\\in\\mathbb Q^\\times$ and $f_0\\in\\mathbb Z[X]$ is primitive.\r\n    Then the ring homomorphism given by $\\phi:\\mathbb Z[X]\\to\\mathbb C$ by $g(X)\\mapsto g(\\alpha)$ has $\\ker\\phi=(f_0)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Clearly $\\phi(f_0)=f_0(\\alpha)=\\lambda^{-1}f(\\alpha)=0$, so $(f_0)\\subset\\ker\\phi$.\r\n    Suppose we have some other $g\\in\\ker\\phi$, then $f|g$ in $\\mathbb Q[X]$ and hence $f_0|g$ in $\\mathbb Q[X]$, but then $f_0|g$ in $\\mathbb Z[X]$ by Lemma \\ref{primitive_div_fof}, therefore $g\\in(f_0)$.\r\n\\end{proof}\r\nSuppose further that $\\alpha$ is an algebraic integer, then $\\ker\\phi=(f_0)\\lhd\\mathbb Z[X]$.\r\nBut by definition of algebraic integer $(f_0)$ contains a monic polynomial, which must mean that one of $\\pm f_0$ is monic.\r\nWe have $f=\\lambda f_0$ with the assumption that $f$ is monic, so $\\lambda=\\pm 1$, so $f\\in\\mathbb Z[X]$.\r\nConsequently, we get $\\mathbb Z[X]/(f_0)=\\mathbb Z[X]/(f)\\cong \\mathbb Z[\\alpha]\\le\\mathbb C$.\r\n\\begin{example}\r\n    $i,\\sqrt{2},(-1+\\sqrt{3})/2,\\sqrt[n]{p}$ are all algebraic integers and indeed their minimal polynomials are $X^2+1,X^2-2,X^2+X+1,X^n-p$.\r\n    In particular, $\\mathbb Z[X]/(X^2+1)\\cong\\mathbb Z[i]$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    An algebraic number $\\alpha\\in\\mathbb C$ is an algebraic integer if and only if its minimal polynomial (which by convention is monic) has integer coefficients.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $\\alpha$ is an algebraic integer and $\\alpha\\in\\mathbb Q$, then $\\alpha\\in\\mathbb Z$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    By preceding lemma.\r\n\\end{proof}\r\n", "meta": {"hexsha": "97d69208598e4c9093550fa52699391f88bed254", "size": 6933, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12/algint.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": "12/algint.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": "12/algint.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": 67.3106796117, "max_line_length": 314, "alphanum_fraction": 0.6510889947, "num_tokens": 2446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.675862262822029}}
{"text": "\\lab{Applications}{Scheduling}{Scheduling}\n\\label{lab:Scheduling}\n\\objective{In this lab, you will determine the schedule that optimizes preferences and reduces spending for nurses in a hospital.}\n\n\\section*{Scheduling}\n\nScheduling is typically an NP-hard combinatorial problem.\nIt can take many forms, from scheduling teachers and classrooms at a university to scheduling jobs in a queue.\nThe nurse scheduling problem is highly constrained, which makes it difficult for local search alogrithms to find even a local solution.\nFinding optimal solutions is much harder.\nWe will use a Baysian approach via linear programming to find the optimal solution.\n\n\n\\subsection*{The Problem}\nHospitals employ a lot of nurses around the clock.\nWeekly schedules have to satisfy several constraints.\nFirst, each nurse has a certain grade, or level, depending on education, experience and expertise.\nAt any given time, there must be a minimum number of nurses at each grade.\nThese numbers depend on how busy the hospital is and what types of procedures they perform.\nFor example, a hospital in Manhattan will need more higher grade nurses at night than the Utah Valley Regional Medical Center due to the larger population and higher crime rate. \n\nSecond, the working contracts of each nurse is different, with over $400$ possible shift schedules in a two-week pay period.\nMost contracts require that the nurse works either all nights or days in a given period, but there are some exceptions for special nurses.\nMore experienced or specialized nurses have a higher grade, which means that they can take over lower grade shifts, but not vice versa.\nSince grades are not independent, one can't schedule the grades separately.\nAlso complicating the schedule, nurses usually do not work the same number of day shifts as night shifts.  \n\nThe third constraint is that schedules must be fair, or appear fair to the nurses.\nAn obvious aspect is that nurses' requests must be taken into consideration.\nIf a nurse is stuck with a shift schedule he/she hates, they will be very unhappy and cause problems.\nAlso included in this is vacation; the hospital still has to meet the requirements when nurses use vacation days.\nSince hospitals operate constantly, there are less desirable shifts.\nAs mentioned above, this can be problematic when these shifts are always assigned to the same nurses.\nSo the schedule mu evenly distribute unpopular shifts so that nurses don't get angry. \n\nFinally, the hospital wants to maximize revenue by minimizing the amount of money spent on nurses. \n\n\n\nIn order to solve this problem, we'll make some assumptions that will simplify it. \n\nThe first assumption is that nurses are assigned a shift pattern.\nShift patterns can be represented by a $14$-dimensional vector where the first $7$ entries represent the day shifts, and the second $7$ entries represent the nights.\nEach nurse is given a set of allowable shift patterns based off their contract.\nFor example, \n\\begin{center}\n$(1,1,1,1,0,0,0,0,0,0,0,0,0,0)$\n\\end{center}\nis an allowable shift pattern, which indicates that the nurse works $4$ consecutive days and then has $3$ days off. \n\\begin{center}\n$(1,1,0,0,0,0,0,1,1,0,0,0,0,0)$\n\\end{center}\nis not allowed because the nurse would work for over $30$ hours straight.\n\nThe second assumption involves taking into account the nurses' preferences.\nThis can be tricky since we have to have some way to measure and compare preferences.\nWe will not worry about that here. \n\nFor each nurse and their allowable shift patterns, we assign a preference.\n\n\\subsection*{Linear Program}\nHow can we formulate this as an optimization problem?\n\nThe preference of a nurse $i$ working a given shift pattern $j$ takes into account the nurse's contract and the fairness aspect by assigning a number to that nurse a pattern.\nThe number can be seen as the cost for assigning nurse i shift pattern j. \nThus a high cost indicates that the nurse should probably not work that pattern.\nIn creating the schedule, the goal is then to minimize the cost of possible schedules. \n\n\nWe have data for $30$ nurses, $70$ possible shift schedules, and $2$ grades.\n$3$ of the nurses are grade $1$ and the rest are grade $3$. \n\nWe can formulate the problem as an integer program in the following manner.\n\n\nIndices:\n\\begin{itemize}\n\\item i = 1...n = 30, nurse index\n\\item j = 1...m = 70, shift pattern index\n\\item k = 1...14, day and night index where 1-7 are days and 8-14 are nights\n\\item s = 1...p = 3, grade index \n\\end{itemize}\n\nDecision Variables:\n\\begin{displaymath}\n   x_{ij} = \\left\\{\n     \\begin{array}{lr}\n       1, & \\text{nurse i works pattern j}\\\\\n       0, & \\text{else}\n     \\end{array}\n   \\right.\n\\end{displaymath}\n\n\n\nParameters:\n\\begin{itemize}\n\\item n = Number of nurses\n\\item m = Number of shift patterns\n\\item p = Number of grades\n\\item $p_{ij}$ = Preference cost of nurse i working pattern j\n\\item $R_{ks}$ = Demand of nurses with grade s on day/night k\n\\item F(i) = Set of feasible work patterns for nurse i\n\\item \\begin{displaymath}\n%\\begin{flalign*}\n   a_{jk} = \\left\\{\n     \\begin{array}{lr}\n       1, & \\text{shift pattern j covers day/night k}\\\\\n       0, & \\text{else}\n     \\end{array}\n   \\right.\n\\end{displaymath}\n\\item \\begin{displaymath}\n   q_{is} = \\left\\{\n     \\begin{array}{lr}\n       1, & \\text{nurse i is of grade s or higher}\\\\\n       0, & \\text{else}\n     \\end{array}\n   \\right.\n\\end{displaymath}\n%\\end{flalign*}\n\\end{itemize}\n\n\n\nNow set up the integer program that describes this problem.\n\n\nObjective Function:\n\nMinimize the preference cost for all nurses\n\\begin{center}\nmin $\\displaystyle\\sum_{i=1}^{n} \\displaystyle\\sum_{j\\in F(i)}^{m} p_{ij}x_{ij}$\n\\end{center}\n\n\nConstraints:\n\n1) Each nurse works exactly one feasible shift pattern\n\\begin{center}\n$\\displaystyle\\sum_{j\\in F(i)} x_{ij} = 1 \\forall i$\n\\end{center}\n\n2) The demand of nurses for each grade is met for every shift\n\\begin{center}\n$\\displaystyle\\sum_{j\\in F(i)} \\displaystyle\\sum_{i=1}^n q_{is}a_{jk}x_{ij} \\geq R_{ks} \\forall k,s$\n\\end{center}\n\n\n\\textbf{Problem}\nSolve this optimization problem using cvxopt.glpk.ilp and the data included in this lab.\nAssume that $F(i)$ consists of all possible $70$ shifts for each nurse $i$. \n\nHints: \n\nRemember that all data must be a float. \n$G$ should be a $4242$ by $2100$ matrix.\n$A$ should be a $30$ by $2100$ matrix.\n\n\n\\subsection*{The Data}\nPreferences.csv contains the level of each nurse, as well as their shift preferences.\nThe $30$ nurses are represented by rows.\nThe first column is their level, an integer between $1$ and $3$.\nThe next $70$ columns represent each nurse's preference for that shift with an integer between $0$ and $50$.\nThe higher the number, the less desirable that shift is. \n\nSchedulingData.csv is the list of $70$ shift schedules.\nEach row is an allowable shift schedule and the $14$ columns represent the $7$ days and $7$ nights.\nA $1$ indicates a working shift, while a $0$ represents an off shift, just like in the examples above.\n\nDemands.csv is the list of the number of required nurses for each level.\nIt has one column with $42$ rows.\nThe first $14$ rows represent the number of level $1$ nurses for each of the $14$ shifts, the second $14$ rows represent the level $2$ nurses, and the last rows are the number of level $3$ nurses. \n\nAll of these files are comma delimited.\n\n%This solution doesn't necessarily minimize the payout to the nurses, so we need to adapt the problem above. For example, it may be more effective for a nurse to work overtime instead of hiring a new nurse. ? other example\n%Each nurse is assigned a salary or wage. Calculate the new schedule to minimize cost.\n%Does it differ from part 1?", "meta": {"hexsha": "e06fed228b76d4654fe714e6f0965d85bf153be3", "size": 7662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Scheduling/scheduling.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/Scheduling/scheduling.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/Scheduling/scheduling.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": 42.5666666667, "max_line_length": 222, "alphanum_fraction": 0.7515009136, "num_tokens": 1927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6758622570922843}}
{"text": "\\documentclass[12pt, titlepage, oneside]{article}\n\n\\input{settings}\n\n\\begin{document}\n\t\n\t\\textbf{ELECENG 3TQ3}\\\\\n\t\\textbf{Elston A.}\n\t\n\t\\section{Lecture 3}\n\t\n\t\\items\n \\item Probability measure ? For example absolute value is a measure that maps set of real numbers into the set of nonnegative real numbers\n \\item Probability is a function that maps events in sample space to real numbers so that\n \\item For any event A probability of event A is nonnegative $P[A] \\geq 0$\n \\item Probability of sample space is 1\n\\item For any countable collection $A1,A2,...$ of mutually exclusive events the probability of their union set is equal to sum of individual probabilities $P[A1 \\u A2 \\u ... \\u An] = P[A1] + P[A2] + \\dots + P[An]$\n\\eitems\n\n\n\\subsection{Axioms of Probability}\n\nA probability model assigns a number between 0 and 1 to every event. The probability of the union of mutually exclusive events is the sum of the probabilities of the probabilities of the events in the union.\n\n\nA probability measure $P[\\cdot]$ is a function that maps events in the sample spaces to non-negative real numbers such that:\n\n\\b{Axiom 1}: For any event $A$, $P[A] \\geq 0$.\n\n\\b{Axiom 2}: $P[S] = 1$\n\n\\b{Axiom 3}: For any countable collection $A1,A2,...$ of mutually exclusive events\n\\begin{align}\nP[A1 \\u A2 \\u \\dots ] = P[A1] + P[A2] + \\dots\n\\end{align}\n\n\\subsection{Theorems of Probability}\n\n\n\\b{Theorem 1.2}: For mutually exclusive events $A1$ and $A2$.\n\\begin{align}\nP[A1 \\u A2] = P[A1] + P[A2]\n\\end{align}\n\n\\b{Theorem 1.3}: If $A = A1 \\u A2 \\u \\dots \\u Am$ and $Ai \\n Aj = \\emptyset$ for $i \\neq j$, then\n\\begin{align}\nP[A] = \\sum_{i=1}^m P[Ai]\n\\end{align}\n\n\\b{Theorem 1.4}: The probability measure $P[\\cdot]$ satisfies\n\\items\n\\item $P[\\emptyset] = 0$\n\\item $P[A^c] = 1-P[A]$\n\\item For any $A$ and $B$ (not necessary mutually exclusive)\n\\begin{align}\nP[A \\u B] = P[A] + P [B] - P[A\\n B] = P[A] + P[A^c \\n B]\n\\end{align}\n\\item If $A \\subset B$, then $P[A] \\leq P[B]$\n\\eitems\n\n\\b{Theorem 1.5}: The probability of an event $B = \\{s_1, s_2, \\dots, s_m\\}$ is the sum of the outcomes contained in the event\n\\begin{align}\nP[B] = \\sum_{i=1}^{m} P[\\{s_i\\}]\n\\end{align}\nThe skeleton for this proof is to see that $B = \\{s_1\\} \\u \\{s_2\\} \\u \\dots \\u \\{s_n\\}$ where $\\{s_i\\} \\n \\{s_j\\} = \\emptyset$ if $i \\neq j$. Then we apply theorem 1.3. \n\n\\ex Let $s_i$ be the outcome of the event of tossing a coin 4 times. $s_i$ is a 4 letter word describing the 4 tosses. To find the probability of getting $hhht$ or $hhth$ we simply need to add the probability of those individual events.\n\n\\subsection{Equally Likely Outcomes}\nIf we believe no outcome is more likely than any other. From the axioms of probability this implies that every outcomes has probability $1/n$.\n\\begin{align}\nP[s_i] = \\frac{1}{n}, \\enspace \\enspace 1 \\leq i \\leq n.\n\\end{align}\n\n\\ex Consider a 6 sided fair die. What is the probability of getting a number larger than 4?\n\nNote that our favorable outcomes is the event set $A = \\{5,6\\}$. \n\\begin{align}\nP[A] = P[\\{5\\}] + P[\\{6\\}] = 1/6 + 1/6 = 1/3\n\\end{align}\n\n\\subsection{Conditional Probability}\n\nConditional probability refers to the modified probability model that reflects partial information about the outcome of an experiment. The modified probability has a smaller sample space than the original model.\n\nIf we have some knowledge of an event $A$ prior to performing the experiment ($P[A]\\approx 1$ or $P[A] \\approx 0$ or $P[A]\\approx 0.5$) then we call $P[A]$ the priori probability or the prior probability of $A$. \n\nWhen we want to state a conditional probability, that is, the probability based on the condition that our knowledge on some other probability is true, we denote this as\n\\begin{align}\nP[A|B]\n\\end{align}\nWe read this as \"The probability of A given B\". So the priori probability is $P[B]$.\n\n\\b{Definition 1.5}: The conditional probability of the event $A$ given the occurrence of the event $B$ is \n\\begin{align}\nP[A|B] =  \\frac{P[A \\n B]}{P[B]} \n\\end{align}\nThe probability of A given B is the probability of A and B divided by the probability of B.\n\n\\b{Theorem 1.7}: A conditional probability measure $P[A|B]$ has the following properties that correspond to the axioms of probability\n\n\\b{Axiom 1}: $P[A|B] \\geq 0$\n\n\\b{Axiom 2}: $P[B|B] = 1$\n\n\\b{Axiom 3}: If $A = A1 \\u A2 \\u \\dots $ with $Ai \\n Aj = \\emptyset$ for $i \\neq j$ then,\n\\begin{align}\nP[A|B] = P[A1|B] + P[A2|B] + \\dots\n\\end{align}\n\n\\ex Lets roll two six sided die. Let $X1$ be the number of dots on he first die and let $X2$ be the number of dots on the second die.\n\nLet $A$ be the event that $X1 \\geq 4$.\n\nLet $B$ be the event that $X2 \\ge X1 + 1$ \n\nFind $P[B]$ and $P[A|B]$\n\nThe probability to get a number greater than 4 on the first die is $P[A] = 3/6$.\n\n$B = \\{ (1,3), (1,4), (1,5), (1,6), (2,4), (2,5), (2,6), (3,5), (3,6), (4,6)\\} $\n\n$B \\n A = {(4,6)}$\n\nThe probability to get a number on die 2 greater than the number on die 1 plus 1 is$P[B] = 10/(6*6)$\n\nThe probability for both occurring $P[B|A] = P[B \\n A]/P[A] = (1/36)/(3/6) = 1/18 = 0.05$\n\n\\subsection{Partitions and The Law of Total Probability}\nA partition divides the sample space into mutually exclusive sets. The law of total probability expresses the probability of an event as the sub of the probabilities of the outcomes that are in the separate sets of a partition.\n\n\\b{Theorem 1.10}: Law of Total Probability: For a partition $\\{B_1,B_2, \\dots, B_n\\}$ with $P[B_i] > 0$ for all $i$.\n\\begin{align}\nP[A] = \\sum_{i=1}^{m} P[A|B_i] P[B_i]\n\\end{align}\n\n\\b{Theorem 1.11}: Bayes Theorem\n\\begin{align}\nP[B|A] = \\frac{P[A|B] P[B]}{P[A]}\n\\end{align}\n\\end{document}\n", "meta": {"hexsha": "8b27084e9d21f8129be6f991a875295a9c0ad934", "size": 5603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture3/lec3.tex", "max_stars_repo_name": "elston-jja/EE3TQ3", "max_stars_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture3/lec3.tex", "max_issues_repo_name": "elston-jja/EE3TQ3", "max_issues_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture3/lec3.tex", "max_forks_repo_name": "elston-jja/EE3TQ3", "max_forks_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_forks_repo_licenses": ["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.4577464789, "max_line_length": 236, "alphanum_fraction": 0.6833839015, "num_tokens": 1892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931190663057, "lm_q2_score": 0.8577681049901036, "lm_q1q2_score": 0.6758622442776464}}
{"text": "\\documentclass[a4paper,12pt]{article} \n\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\n\\title{Probabilistic Spiking Neuron Model}\n\\author{Saptarshi Soham Mohanta\\\\\nIndian Institute of Science Education and Research, Pune\\\\\nMaharashtra - 411008}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Model Description}\nThe dynamic variable for this model of spiking neuron is the vector $\\vec{\\theta}$. Let us consider a system of n neurons connected via excitatory and inhibitory connections.\n\nLet $\\vec{\\theta}_t$ be the n-dimensional vector of firing probabilities of each of the n neurons at the time t. By the definition of probability, each element of this vector is bounded by 0 and 1. In absence of any current input to the neurons, the probability of firing would go down as the activity decays to equilibrium. Let $\\lambda$ be the rate for the exponential decay.\n\nThus in absence of current input (external and synaptic), $\\vec{\\theta}$ will follow the dynamical equation:\n$$\\vec{\\theta}_{t+1} = \\lambda \\vec{\\theta}_t$$\n\nBut at each time step = t, we perform a sampling event to evaluate the firing of the neurons. Let $\\langle\\vec{\\theta}\\rangle_t$ be the result of the sampling event. This means that  $[\\langle\\vec{\\theta}\\rangle_t]_i$ is the result of a binary coin toss with $P(1) = [\\vec{\\theta}_t]_i$ and $P(0) = 1-[\\vec{\\theta}_t]_i$, where $i = 1,2,3...n$.\n\nBut whenever the neuron fires, the probability of firing again is set to zero. Thus the final dynamical equation without current input becomes\n\n$$\\vec{\\theta}_{t+1} = \\lambda (1-\\langle\\vec{\\theta}\\rangle_t) \\vec{\\theta}_t$$\n\nWe initialize the values of $\\vec{\\theta}_t$ with values from a uniform random distribution and then follow the system by the rules. This will give a system of non interacting neurons that have a dynamic probability of firing. \n\nNow we model the interactions and the current response. Let us define excitatory and inhibitory connectivity matrices $\\mathbf{[E]_{n\\times n}}$ and  $\\mathbf{[I]_{n\\times n}}$ with the horizontal axis representing the pre-synaptic neuron and the vertical axis the post-synaptic neuron. We also define a function $I_{ext}(t):\\mathbb{R}\\rightarrow\\mathbb{R}^n$ that gives us the external current input to each neuron at time t. We also define two parameters $e$ and $i$ that describe the excitation and inhibition coupling coefficient respectively. Finally, we define a response function based on Mirollo Strogatz Model, $U:\\mathbb{R}\\rightarrow\\mathbb{R}$ which has the following properties:\n$$U'(x)>0\\ and\\ U''(x)<0,\\forall x \\in [0,1]$$\n$$U(0)=0\\ and\\ U(1)=1$$\n\nWe will use this function to update the probability based on current input. Say, the current input is $\\vec{\\epsilon}$ where each element $\\epsilon_i \\in [-1,1]$ or any other bound that depends on the range of the response function over which the response is variable. We define the new probability using the function $H:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$ where\n\n$$[H(\\vec{x},\\vec{\\epsilon})]_i= [U^{-1}(U(x_i)+\\epsilon_i)]_i\\ \\forall i\\in \\{1,2,3...n\\}$$\n\nOne such function that satisfies these properties is:\n$$U_b(x)= \\frac{1}{b}ln(1+(e^b-1)x)$$\n\nThis function is numerically and analytically useful because the function $H_b(\\vec{x},\\vec{\\epsilon})$ for $U_b(x)$ becomes an affline linear map\n\n$$H_b(\\vec{x},\\vec{\\epsilon}) = e^{b\\epsilon}x + \\frac{e^{b\\epsilon}-1}{e^b-1}$$\n\nNow, given a synaptic response function $F:\\mathbb{R}\\rightarrow[0,1]$, we define the synaptic current $I^{syn}$ at time t+1 as\n\n$$I_{syn}(t+1) = e.F(\\mathbf{E}\\times \\langle\\vec{\\theta}\\rangle_{t}) - i.F(\\mathbf{I}\\times \\langle\\vec{\\theta}\\rangle_{t})$$ \n\nFor simplicity, we can use the linear response function\n$$F(x)=x/n$$\n\nNow we define the dynamical equation with current input as \n$$\\vec{\\theta}_{t+1} = H_b(\\ \\lambda (1-\\langle\\vec{\\theta}\\rangle_t) \\vec{\\theta}_t\\ ,\\ I_{ext}(t+1) + I_{syn}(t+1)\\ )$$\n\nThis model can now be simulated.\n\n\\end{document}", "meta": {"hexsha": "189921e133d0a1d77cdcb0596692b3be97e50e3c", "size": 3920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/model.tex", "max_stars_repo_name": "neurorishika/psn-model", "max_stars_repo_head_hexsha": "39c458abaa77c4ffe0344d1e4a3137312f7dc054", "max_stars_repo_licenses": ["MIT"], "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/model.tex", "max_issues_repo_name": "neurorishika/psn-model", "max_issues_repo_head_hexsha": "39c458abaa77c4ffe0344d1e4a3137312f7dc054", "max_issues_repo_licenses": ["MIT"], "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/model.tex", "max_forks_repo_name": "neurorishika/psn-model", "max_forks_repo_head_hexsha": "39c458abaa77c4ffe0344d1e4a3137312f7dc054", "max_forks_repo_licenses": ["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.7719298246, "max_line_length": 691, "alphanum_fraction": 0.731377551, "num_tokens": 1136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6758622385479013}}
{"text": "\\newpage\n\\section{Notes on Section 4}\n\n\\subsubsection{Explaining Lemma 4.1}\n\nA proof of Lemma 4.1 can also be found in the appendix of the original paper. However,\nthe relation between the norms is missing in the original paper - that is why we state it here again.\nFrom 3.5 in the paper, we had:\n\\begin{align}\n\t\\frac{1}{(L+1)^2} \\pqnorm{\\theta}{fr}{2} = \\E{v^\\TT X X^\\TT v} = \\E{\\norm{f_\\theta}^2}.\n\\end{align}\nRemember that the output of the network, $f_\\theta(x)$, is a vector in $\\setreal^k$ of probabilities for each of the $k$ classes.  \nFor the Frobenius Norm of a Matrix $A$ and a vector $x$ the following holds.\n\\begin{align}\n\t\\frobnorm{A} &\\geq \\spectralnorm{A} \\\\\n\t\\frobnorm{x} &= \\lnorm{x} = \\spectralnorm{x} \\\\\n\t\\spectralnorm{Ax} &\\leq \\spectralnorm{A} \\cdot \\lnorm{x} \\\\\n\\end{align}\nIt follows.\n\\begin{align}\n\t\\E{\\spectralnorm{f_\\theta}^2}\n\t&= \n\t\t\\E{ \\spectralnorm{f_\\theta}^2} \\\\\n\t&= \n\t\t\\E{ \\spectralnorm{\\structuredNN}^{2} } \\\\\n\t&\\leq \n\t\t\\E{ \\spectralnorm{x}^2 \\prod \\spectralnorm{D^i(x)}^2 \\prod \\spectralnorm{W^i}^2 }.\n\\end{align}\nSince $W^i$ is independent of the data $x$, it does not have to be inside the expectation.\n\\begin{align}\n\\frac{1}{(L+1)^2} \\frnorm{\\theta}^2\n\t&=\n\t\t\\E{\\spectralnorm{f_\\theta}^2}  \\\\\t\n\t&\\leq \n\t\t\\E{ \\spectralnorm{x}^2 \\prod \\spectralnorm{D^i(x)}^2 \\prod \\spectralnorm{W^i}^2 } \\\\\n\t&=\n\t\t\\E{ \\lnorm{x}^2 \\prod_{t=1}^{L+1} \\spectralnorm{D^t(x)}^2 } \\prod_{t=0}^{L} \\spectralnorm{W^i}^2\n\\end{align}\nNow taking the root on both sides reveals Lemma 4.1 and concludes the explainiation.\n\n\n\n\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/18.jpg}\n\\end{figure}\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/19.jpg}\n\\end{figure}\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/20.jpg}\n\\end{figure}\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/21.jpg}\n\\end{figure}\n\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/22.jpg}\n\\end{figure}\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/23.jpg}\n\\end{figure}\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/24.jpg}\n\\end{figure}\n\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{whiteboard_notes/25.jpg}\n\\end{figure}", "meta": {"hexsha": "4325433540500eac0028f34a2df1a68ab68a0b76", "size": 2386, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2_fisher_rao_norm/section4.tex", "max_stars_repo_name": "ML-KA/PDG-Theory", "max_stars_repo_head_hexsha": "dbbdf93098af3a201bf67449a29c15cd633e2430", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-07-19T20:29:51.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-18T13:09:46.000Z", "max_issues_repo_path": "2_fisher_rao_norm/section4.tex", "max_issues_repo_name": "ML-KA/PDG-Theory", "max_issues_repo_head_hexsha": "dbbdf93098af3a201bf67449a29c15cd633e2430", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-10-04T13:36:53.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-04T13:36:53.000Z", "max_forks_repo_path": "2_fisher_rao_norm/section4.tex", "max_forks_repo_name": "ML-KA/PDG-Theory", "max_forks_repo_head_hexsha": "dbbdf93098af3a201bf67449a29c15cd633e2430", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-21T19:33:48.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-21T19:33:48.000Z", "avg_line_length": 28.4047619048, "max_line_length": 131, "alphanum_fraction": 0.6990779547, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6757778607003638}}
{"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 } \\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{Assignment3 Report}{Fall 2017}{Genqian Hu}{Computational Geometry}\n\n\\section{Summary of the two methods}\n\n\\subsection{hedcuter method}\n\\subsubsection{Voronoi diagram and Centroidal Voronoi tessellation}\n\\paragraph{First, the algorithm resizes the input image to a larger virtual image. Then, it scans the cells and stores all sites in a heap. After, it pops a cell to compute dx and dy so to get the centroidal voronoi diagram. When all cells are visited and the heap is empty, it collects cells from (0,0) rightwards and then remove empty cells. Finally, it moves each cell to its center of its coverage.}\n\\subsubsection{stippling}\n\\paragraph{It reads the image and the centroidal voronoi tessellation computed before to stipple. It retrieves each cell from CVT and its grayscale information. Then, the location of each disk is defined by the x and y coordinates of each sites of the cells retrieved. The color of it is determinded by grayscale value. If it is required a colorful output, then the rgb value is from the original image's rgb value at that pixel.}\n\\subsection{voronoi method}\n\\paragraph{First, it computes the range of the coordinates of the sites. Then do the plane sweep, if the sites' y coordinate is bigger than the lowest intersection's, it determines which half edge the new site intersects with and will triangulate it. If the sites' y is smaller, it creates a new bisector between the left and right half edges. Finally, it scans the edges and eliminates the invalid edges. }\n\\subsubsection{Centroidal Voronoi tessellation}\n\\paragraph{It adds clip lines to the voronoi digrams one by one. If the density is higher there, the x and y there will also get larger weight when computing the new centroid. If no points are outside the clip planes,the centroid is computed by the sum of coordinates and the density there. }\n\\subsubsection{stippling}\n\\paragraph{It read the coordinates of all the centroids created before. Then it outputs them to the output file. And it assigns each of them the right color as needed.}\n\\section{Comparison of the two methods}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure1.eps}\n\\caption{Different outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{1. The output images from hedcuter are different as shown in Figure 1. But the output images from voronoi are the same. Because hedcuter uses rng\\_uniorm and rng\\_gaussian methods to randomly initial points, the details is normal to be different during each run.}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure2.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure3.eps}\n\\caption{Outputs from voronoi}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{2. The overall distribution will be the same for both methods. As Figure 2 and Figure 3 shows, the distribution remains the same. The difference here is that the one with more disks seems to be darker, because its density of disks is higher. And following these 2 methods, darker places deserve more disks. So the distribution should always be the same.}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure4.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure5.eps}\n\\caption{Outputs from voronoi}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{3. As Figure 4 and 5 show, the voronoi method is always much faster than the other one when parameters are the same. And I think the reason hedcuter method is slower that much is because it generates the same virtual image repetitively. So, I take it as one of my improvement and the result is not bad. And other reasons are voronoi precomputes the sets of distribution and merge them at runtime. But hedcuter method is doing plane sweep from points with small x coordinates which is time consuming.}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure6.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure7.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure8.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{4. As figure 6, 7 and 8 show, for both methods, the same picture with smaller size consumes less time, because less pixels mean less iteration. For hedcuter method, it runs much faster with the low contrast picture. Because lowering contrast makes the picture darker. And when the picture is getting darker and darker, its distribution of disks becomes more uniform. Thus, the propagation task is achieved faster.  }\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure9.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure10.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{5. From Figure 9 and 10, different types of images have the approximate total time for voronoi method. But for hedcuter method, it performs better on landscape picture. I think it's because the landscape picture I chose is relatively darker than other types of pictures. So the reason is like for the pictures with low contrast value.  }\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=3in]{figure11.eps}\n\\caption{hedcut image from Wall Street Journal}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure12.eps}\n\\caption{Outputs from hedcuter}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{6. I think hedcut images from the Wall Street Journal are better than images generated by these 2 methods. As shown in Figure 11, it has smooth boundaries and more artistic distribution of disks. Figure 12 is generated by voronoi method from a 200x200 picture with 2000 disks. Although viewers are able to tell what's in the hedcut picture, its distribution of disks is not as natural as the one from Wall Street Journal.}\n\\section{Improvement of hedcuter method}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure13.eps}\n\\caption{output from original method}\n\\label{threadsVsSync}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure14.eps}\n\\caption{outputs from new one}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{The first improvement is that I reorganized same codes so that the workload for vor and move\\_sites methods are reduced. According to the original code, it seems like  each loop these two methods will generate a virtual high resolution image with the same parameters which means there is no need to do it repetitively. And it's also time consuming. Then, I changed that part of code so that the virtual image generating will be done only once. Figure 13 shows the total time the original program used to output the result. Figure 14 shows the total time the improved program used. The total time has reduced.}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.80\\textwidth]{figure15.eps}\n\\caption{comparison}\n\\label{threadsVsSync}\n\\end{figure}\n\\paragraph{The second improvement is that the program now can treat png files which contain transparent alpha channel correctly. The original version treats the transparent background as black which makes the output file weird. I modified main.cpp to make the input file lay on a white image. Fiqure 15 shows the comparison of the original program against the improved program with the same parameters. But when outputing colorful disks, the color of each disk is not always right. }\n \\paragraph{Folder hedcuter2 has the codes for the first improvement. And folder hedcuter3 has the second improvement. And the output image makes more sense now.}\n\\bibliographystyle{plain}\n\\bibliography{report}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "abee0120f168895d7bf1d2173b0609707aee69c4", "size": 9456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/report.tex", "max_stars_repo_name": "tex775306106/hu-hedcut-master", "max_stars_repo_head_hexsha": "00ebc8681b1c7fe62aa9e3486210c2875cb69da1", "max_stars_repo_licenses": ["MIT"], "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": "tex775306106/hu-hedcut-master", "max_issues_repo_head_hexsha": "00ebc8681b1c7fe62aa9e3486210c2875cb69da1", "max_issues_repo_licenses": ["MIT"], "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": "tex775306106/hu-hedcut-master", "max_forks_repo_head_hexsha": "00ebc8681b1c7fe62aa9e3486210c2875cb69da1", "max_forks_repo_licenses": ["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.1135135135, "max_line_length": 620, "alphanum_fraction": 0.7835236887, "num_tokens": 2539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6757778601482798}}
{"text": "\\section{Risk-Based Stochastic Capital Budgeting using Conditional Value-at-Risk}\n\\label{sec:CVaR}\n\nValue-at-Risk (VaR) is currently used by finance businesses to indicate the percentiles\nof loss distributions. For instance, $95\\%$-VaR is an upper estimate of losses which\nis exceeded with $5\\%$ probability. The popularity of VaR is mostly related to a simple\nand easy to understand representation of high losses. However, VaR may have undesirable\nmathematical characteristics such as a lack of subadditivity and convexity~\\cite{ThinkingCoherently,CoherentMeasureRisk} .\nAnother alternative percentile risk measure is called Conditional Value-at-Risk (CVaR),\nwhich has more attractive properties than VaR, such as sub-additive and convex.\nCVaR also called mean excess loss, mean shortfall, or tail VaR, is defined as the\nexpected loss exceeding VaR. In general, CVaR is the weighted average of VaR and\nlosses exceeding VaR. In this section, we will focus on using CVaR for capital\nbudgeting problem.\n\n\\subsection{Definitions of VaR and CVaR}\n\\label{definitionCVaR}\nLet $X$ be a random variable with a cumulative distribution function\n$F(z) = P{X\\le z}$. It can be useful to think of $X$ as a ``loss'' or more generally\na variable such that large values need to be avoid. The VaR of $X$ with confidence level\n$\\alpha$ (e.g., $\\alpha = 0.9$ is:\n\n\\begin{equation}\nVaR_\\alpha (X) = \\min {z|F_X(z)\\ge \\alpha}\n\\end{equation}\n\nwhich is equivalent to $VaR_\\alpha (X) = F_{X}^{-1}(\\alpha)$ if $X$ is a continuous\nrandom variable. By this definition, $VaR_\\alpha (X)$ is a (lower) $\\alpha$-percentile\nof the random variable $X$. An alternative measure of risk is CVaR. Here, $CVaR_\\alpha (X)$\nis the conditional expectation of $X$ given that $X \\ge VaR_\\alpha (X)$.\nFigure~\\ref{fig:CVaR} shows the relationship between these two measures of risk.\n\n\\begin{figure}\n    \\centering\n    \\centerline{\\includegraphics[scale=0.5]{CVaR.jpg}}\n    \\caption{Relationship between value-at-risk and conditional value-at-risk.}\n    \\label{fig:CVaR}\n\\end{figure}\n\nThe typical definition of $CVaR_\\alpha (X)$ is $CVaR_\\alpha (X) = E{X|X > VaR_\\alpha (X)}$.\nThere are alternative ways to define this measure, which are mathematically equivalent.\nRockafellar and Uryasev in~\\cite{OptCVaR} (see also~\\cite{RemarksCVaR}) defines CVaR as:\n\n\\begin{equation}\nCVaR_\\alpha (X) = \\min_u {u + 1/(1-\\alpha) E[X-u]^+}\n\\end{equation}\n\nwhere $[X-u] = \\max (X - u, 0)$. Here, variable $u$ is simply an auxiliary decision\nvariable whose optimal value turns out to be $CVaR_\\alpha (X)$. The above definition\nis particularly useful for computation in the context of optimization.\n\nResearchers have argued for using CVaR over VaR as a measure of risk. Theoretically,\nCVaR satisfies the assumptions of a so-called coherent risk measure, and VaR does not.\nIn simpler terms, minimizing VaR is concerned with the numerical value of the 95-th\npercentile (say) of the loss, but it does not care about the magnitude of larger losses.\nCVaR takes these magnitudes into account.\n\n\\subsection{CVaR in Capital Budgeting}\n\\label{CVaRCapitalBudgeting}\nIn this section, an explicit risk measure is constructed using a weighted\ncombination of expectation and CVaR. This approach allows us to parametrically\nvary the weight on maximizing expected NPV versus penalizing solutions that yield\nlow-NPV scenarios, and we denote the weight by $\\lambda$ with $0 \\le \\lambda \\le 1$.\nLet $NPV(s,\\xi)$ denote the net present value under a prioritization decision\nspecified by decision $s$, and under a realization of the budget and profit of\neach project, denoted by $\\xi$. Then we seek to solve the following optimization\nmodel:\n\n\\begin{equation}\n\\max_{s\\in S} (1-\\lambda)E[NPV(s, \\xi)] - \\lambda CVaR_\\alpha [-NPV(s, \\xi)]\n\\end{equation}\n\nWhen $\\lambda = 0$ the model reduces to stochastic optimization model as\ndiscussed in Section~\\ref{sec:StochasticCapitalBudgeting}; i.e., we seek\na prioritization decision, $s$, to maximize expected NPV, where ``$s \\in S$''\nsimply indicates the constraints that a prioritized solution must satisfy.\n$CVaR_\\alpha [X]$ is typically applied to a random variable, $X$, which\nrepresents a loss; i.e., we seek to avoid large values of $X$. In this\ncontext, let $VaR_\\alpha [X]$ denote the $\\alpha$-level quantile of $X$.\nThus, if $\\alpha = 0.75$ then $VaR_0.75 [X]$ is the value such that $75\\%$\nof the realizations of $X$ have lower values of loss. Suppose for simplicity\nthat $NPV(s, \\xi)$ values are positive. Large values of $NPV(s, \\xi)$ are\ngood, and hence large values of $-NPV(s, \\xi)$ (i.e., those closer to zero)\nare bad. Using the definition of $CVaR_\\alpha [X] = E[X|X > VaR_\\alpha [X]]$\nwe thus have that the conditional value-at-risk is the expected value of loss,\ngiven that the loss exceeds a certain percentile. So, when $\\lambda = 1$ we\nseek to minimize the expected value of NPV given that they fall below a\nthreshold. More generally, values of $\\lambda$ between 0 and 1 seek a trade-off\nbetween reward and risk, captured by expected NPV and CVaR, respectively.\n\nThe full mathematical optimization model of CVaR for capital budgeting problem\nis as follows:\n\n\\begin{subequations}\\label{fullCVaR}\n\\begin{eqnarray}\n& & \\max_{x, y, \\nu, u} (1-\\lambda) \\sum _{ \\omega  \\in  \\Omega }^{}q^{ \\omega } \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}a_{ij}^{ \\omega }x_{ij}^{ \\omega } - \\lambda[u+1/(1-\\alpha)\\sum_{\\omega \\in \\Omega} q^\\omega \\nu^\\omega] \\\\\n& & \\nu^\\omega \\ge - \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}a_{ij}^{ \\omega }x_{ij}^{ \\omega } - u, \\omega \\in \\Omega \\\\\n& & y_{ii^{'}}+y_{i^{'}i} \\geq 1,~ i<i^{'}\\text{, i, }i^{'} \\in I \\\\\n& & \\sum_{j=1}^{J_i} x_{ij}^\\omega \\geq \\sum_{j=1}^{J_i} x_{i'j}^\\omega + y_{ii'} -1,~ i \\neq i^{'}\\text{, i, }i^{'} \\in I,  \\omega  \\in  \\Omega \\\\\n& & \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}\\text{~ c}_{ijkt}^{ \\omega }x_{ij}^{ \\omega }~  \\leq  b_{kt}^{ \\omega },~ k \\in K, t \\in T,  \\omega  \\in  \\Omega \\\\\n& & \\sum_{j\\in J_i} x_{ij}^{ \\omega } \\leq 1,~ i \\in I, \\omega  \\in  \\Omega \\\\\n& & y_{ii'}, x_{ij}^\\omega \\in {0, 1} \\\\\n& & \\nu^\\omega \\ge 0, \\omega \\in \\Omega\n\\end{eqnarray}\n\\end{subequations}\n\n\\subsection{LOGOS Settings for CVaR Problems}\n\\label{subsec:CVaRSettings}\nCVaR approach is an extension for stochastic optimization approach discussed in\nSection~\\ref{sec:StochasticCapitalBudgeting}. Both of them share the same input\nstructures except the \\xmlNode{Settings} block. In both cases, the user need to\nspecify a collection of scenarios via \\xmlNode{Uncertainties} block. The\n\\xmlNode{problem\\_type} within \\xmlNode{Settings} block is used to select the\ntype of CVaR problems. The currently available CVaR problem types are:\n\\xmlString{cvarskp}, \\xmlString{cvarmkp}, and \\xmlString{cvarmckp}. The user can\nuse \\xmlNode{risk\\_aversion} (i.e. $\\lambda$) and \\xmlNode{confidence\\_level}\n(i.e., $\\alpha$) to control CVaR problem.\n\nExample LOGOS input XML for CVaR:\n\\begin{lstlisting}[style=XML]\n<Settings>\n<Logos>\n  <solver>cbc</solver>\n  <solverOptions>\n    <StochSolver>EF</StochSolver>\n    <risk_aversion>0.1</risk_aversion>\n    <confidence_level>0.95</confidence_level>\n  </solverOptions>\n  <sense>maximize</sense>\n  <problem_type>cvarskp</problem_type>\n</Settings>\n</Logos>\n\\end{lstlisting}\n\n\n\\subsection{CVaR for Single Knapsack Problem}\n\\label{subsec:CVaR_SKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{CVaRSimpleKP}\n\\begin{eqnarray}\n& & \\max_{x, y, \\nu, u} (1-\\lambda)  \\sum _{ \\omega  \\in  \\Omega }^{}q^{ \\omega } \\sum _{i \\in I}^{} a_{i}^{ \\omega }x_{i}^{ \\omega } - \\lambda[u+1/(1-\\alpha)\\sum_{\\omega \\in \\Omega} q^\\omega \\nu^\\omega] \\\\\n& & \\nu^\\omega \\ge - \\sum _{i \\in I}^{} a_{i}^{ \\omega }x_{i}^{ \\omega } - u, \\omega \\in \\Omega \\\\\n& & \\sum_{i \\in I} c_{i}^\\omega x_{i}^\\omega \\leq b^\\omega, \\omega \\in \\Omega\\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & x_{i}^\\omega \\geq x_{i'}^\\omega + y_{ii'}-1, i\\neq i' \\\\\n& & x_{i}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\nu^\\omega \\ge 0, \\omega \\in \\Omega, \\lambda \\in [0, 1]\n\\end{eqnarray}\n\\end{subequations}\n\nSee next section~\\ref{subsec:CVaR_DKP} for the example of LOGOS input file, since multi-dimensional Knapsack problem\nis just a simple extension of a single-dimensional Knapsack problem, and both of them belong to the same\n\\xmlNode{problem\\_type}: \\xmlString{cvarskp}.\n\n\n\\subsection{CVaR for Multi-Dimensional Knapsack Problem}\n\\label{subsec:CVaR_DKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{CVaRMultiDKP}\n\\begin{eqnarray}\n& & \\max_{x, y, \\nu, u} (1-\\lambda)  \\sum _{ \\omega  \\in  \\Omega }^{}q^{ \\omega } \\sum _{i \\in I}^{} a_{i}^{ \\omega }x_{i}^{ \\omega } - \\lambda[u+1/(1-\\alpha)\\sum_{\\omega \\in \\Omega} q^\\omega \\nu^\\omega] \\\\\n& & \\nu^\\omega \\ge - \\sum _{i \\in I}^{} a_{i}^{ \\omega }x_{i}^{ \\omega } - u, \\omega \\in \\Omega \\\\\n& & \\sum_{i \\in I} c_{it}^\\omega x_{i}^\\omega \\leq b_{t}^\\omega, t\\in T \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & x_{i}^\\omega \\geq x_{i'}^\\omega + y_{ii'}-1, i\\neq i' \\\\\n& & x_{i}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\nu^\\omega \\ge 0, \\omega \\in \\Omega, \\lambda \\in [0, 1]\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16\n    </investments>\n    <time_periods>\n      1,2,3,4,5\n    </time_periods>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      2.315,0.824,22.459,60.589,0.667,5.173,4.003,0.582,0.122,\n      -2.870,-0.102,-0.278,-0.322,-3.996,-0.246,-20.155\n    </net_present_values>\n    <costs index=\"investments, time_periods\">\n      0.219,0.257,0.085,0.0,0.0,\n      0.0,0.0,0.122,0.103,0.013,\n      5.044,1.839,0.0,0.0,0.0,\n      6.74,6.134,10.442,0.0,0.0,\n      0.425,0.0,0.0,0.0,0.0,\n      2.125,2.122,0.0,0.0,0.0,\n      2.387,0.19,0.012,2.383,0.192,\n      0.0,0.95,0.0,0.0,0.0,\n      0.03,0.03,0.688,0.0,0.0,\n      0,0.2,0.763,0.739,2.539,\n      0.081,0.032,0,0,0,\n      0.3,0,0,0,0,\n      0.347,0,0,0,0,\n      4.025,0.297,0,0,0,\n      0.095,0.095,0.095,0,0,\n      5.487,5.664,0.5,6.803,6.778\n    </costs>\n    <available_capitals index=\"time_periods\">\n      18,18,18,18,18\n    </available_capitals>\n  </Parameters>\n\n  <Uncertainties>\n    <available_capitals>\n      <totalScenarios>10</totalScenarios>\n      <probabilities>\n        0.012, 0.019, 0.032, 0.052, 0.086, 0.142, 0.235, 0.188, 0.141, 0.093\n      </probabilities>\n      <scenarios>\n        11, 11, 11, 11, 11,\n        12, 12, 12, 12, 12,\n        13, 13, 13, 13, 13,\n        14, 14, 14, 14, 14,\n        15, 15, 15, 15, 15,\n        16, 16, 16, 16, 16,\n        17, 17, 17, 17, 17,\n        18, 18, 18, 18, 18,\n        19, 19, 19, 19, 19,\n        20, 20, 20, 20, 20\n      </scenarios>\n    </available_capitals>\n  </Uncertainties>\n\n  <Settings>\n    <mandatory>10,11,12,13,14,15,16</mandatory>\n    <solver>cbc</solver>\n    <solverOptions>\n      <StochSolver>EF</StochSolver>\n      <!-- lambda for risk aversion -->\n      <risk_aversion>0.1</risk_aversion>\n      <!-- confidence level -->\n      <confidence_level>0.95</confidence_level>\n    </solverOptions>\n    <sense>maximize</sense>\n    <problem_type>cvarskp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\n\n\\subsection{CVaR for Multiple Knapsack Problem}\n\\label{subsec:CVaR_MKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{CVaRMKP}\n\\begin{eqnarray}\n& & \\max_{x, y, \\nu, u} (1-\\lambda)  \\sum _{ \\omega  \\in  \\Omega }^{}q^{ \\omega } \\sum_{m\\in M} \\sum _{i \\in I}^{} a_{i}^{ \\omega }x_{i, m}^{ \\omega } - \\lambda[u+1/(1-\\alpha)\\sum_{\\omega \\in \\Omega} q^\\omega \\nu^\\omega] \\\\\n& & \\nu^\\omega \\ge - \\sum_{m\\in M} \\sum _{i \\in I}^{} a_{i}^{ \\omega }x_{i, m}^{ \\omega } - u, \\omega \\in \\Omega \\\\\n& & \\sum _{i \\in I}^{} c_{i}^{ \\omega }x_{im}^{ \\omega }~  \\leq  b_{m}^{ \\omega },~ m \\in M,  \\omega  \\in  \\Omega \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & \\sum_{m=1}^{M} x_{im}^\\omega \\geq \\sum_{m=1}^{M} x_{i'm}^\\omega + y_{ii'} -1,~ i \\neq i^{'}\\text{, i, }i^{'} \\in I,  \\omega  \\in  \\Omega \\\\\n& & \\sum_{m=1}^{M} x_{im}^\\omega \\leq 1 \\\\\n& & x_{im}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\nu^\\omega \\ge 0, \\omega \\in \\Omega, \\lambda \\in [0, 1]\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9,10\n    </investments>\n    <capitals>\n      unit_1, unit_2\n    </capitals>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      78, 35, 89, 36, 94, 75, 74, 79, 80, 16\n    </net_present_values>\n    <costs index=\"investments\">\n      18, 9, 23, 20, 59, 61, 70, 75, 76, 30\n    </costs>\n    <available_capitals index=\"capitals\">\n      103, 156\n    </available_capitals>\n  </Parameters>\n\n  <Uncertainties>\n    <available_capitals>\n      <totalScenarios>10</totalScenarios>\n      <probabilities>\n        0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n      </probabilities>\n      <scenarios>\n        101, 154,\n        102, 155,\n        103, 156,\n        104, 157,\n        105, 158,\n        106, 159,\n        107, 160,\n        108, 161,\n        109, 162,\n        110, 163\n      </scenarios>\n    </available_capitals>\n  </Uncertainties>\n\n  <Settings>\n    <solver>cbc</solver>\n    <solverOptions>\n      <StochSolver>EF</StochSolver>\n      <risk_aversion>1.0</risk_aversion>\n      <confidence_level>0.95</confidence_level>\n    </solverOptions>\n    <sense>maximize</sense>\n    <problem_type>cvarmkp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\n\n\\subsection{CVaR for Multiple-Choice Knapsack Problem}\n\\label{subsec:CVaR_MCKP}\n\n\\vst \\noi {\\em Model Formulation:}\n\\begin{subequations}\\label{CVaRMCKP}\n\\begin{eqnarray}\n& & \\max_{x, y, \\nu, u} (1-\\lambda)  \\sum _{ \\omega  \\in  \\Omega }^{}q^{ \\omega } \\sum_{j\\in J_i} \\sum _{i \\in I}^{} a_{ij}^{ \\omega }x_{ij}^{ \\omega } - \\lambda[u+1/(1-\\alpha)\\sum_{\\omega \\in \\Omega} q^\\omega \\nu^\\omega] \\\\\n& & \\nu^\\omega \\ge - \\sum_{j\\in J_i} \\sum _{i \\in I}^{} a_{ij}^{ \\omega }x_{ij}^{ \\omega } - u, \\omega \\in \\Omega \\\\\n& & \\sum _{i \\in I}^{} \\sum _{j \\in J_{i}}^{}\\text{~ c}_{ijkt}^{ \\omega }x_{ij}^{ \\omega }~  \\leq  b_{kt}^{ \\omega },~ k \\in K, t \\in T,  \\omega  \\in  \\Omega \\\\\n& & y_{ii'} + y_{i'i} \\geq 1, i<i'  \\\\\n& & \\sum_{j=1}^{J_i - 1} x_{ij}^\\omega \\geq \\sum_{j=1}^{J_i - 1} x_{i'j}^\\omega + y_{ii'} -1,~ i \\neq i^{'}\\text{, i, }i^{'} \\in I,  \\omega  \\in  \\Omega, and i \\neq i' \\\\\n& & \\sum_{j=1}^{J_i} x_{ij}^\\omega = 1 \\\\\n& & x_{i,j}^\\omega, y_{ii'}^\\omega \\in {0, 1} \\\\\n& & \\nu^\\omega \\ge 0, \\omega \\in \\Omega, \\lambda \\in [0, 1]\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17\n    </investments>\n    <options index='investments'>\n      1;\n      1;\n      1;\n      1,2,3;\n      1,2,3,4;\n      1,2,3,4,5,6,7;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1\n    </options>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index='options'>\n      2.046\n      2.679\n      2.489\n      2.61\n      2.313\n      1.02\n      3.013\n      2.55\n      3.351\n      3.423\n      3.781\n      2.525\n      2.169\n      2.267\n      2.747\n      4.309\n      6.452\n      2.849\n      7.945\n      2.538\n      1.761\n      3.002\n      3.449\n      2.865\n      3.999\n      2.283\n      0.9\n      8.608\n    </net_present_values>\n    <costs index='options'>\n      36538462\n      83849038\n      4615385\n      2788461538\n      2692307692\n      5480769231\n      1634615385\n      2981730768\n      7211538462\n      9038461538\n      649038462\n      650000000\n      216346154\n      212500000\n      3076923077\n      3942307692\n      1144230769\n      675721154\n      1442307692\n      99711538\n      4807692\n      123076923\n      138461538\n      86538462\n      108653846\n      75092404\n      6413462\n      147932692\n    </costs>\n    <available_capitals>\n      15E9\n    </available_capitals>\n  </Parameters>\n\n  <Uncertainties>\n    <available_capitals>\n      <totalScenarios>3</totalScenarios>\n      <probabilities>\n        0.2,0.6,0.2\n      </probabilities>\n      <scenarios>\n        5E9,10E9,15E9\n      </scenarios>\n    </available_capitals>\n  </Uncertainties>\n\n  <Settings>\n    <solver>glpk</solver>\n    <solverOptions>\n      <StochSolver>EF</StochSolver>\n      <risk_aversion>0.1</risk_aversion>\n      <confidence_level>0.95</confidence_level>\n    </solverOptions>\n    <sense>maximize</sense>\n    <problem_type>cvarmckp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n", "meta": {"hexsha": "47713d5114259d493ce2a7db0b507dc940a07395", "size": 16438, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/include/CVaR.tex", "max_stars_repo_name": "dgarrett622/LOGOS", "max_stars_repo_head_hexsha": "7234b8b5e80bc79526b4cbced7efd5ae482f7c44", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-05-04T08:42:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T13:14:12.000Z", "max_issues_repo_path": "doc/user_manual/include/CVaR.tex", "max_issues_repo_name": "albernsrya/LOGOS", "max_issues_repo_head_hexsha": "535a25ccd3a83259b615acd569257d751fe00439", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2021-01-12T17:41:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-03T18:20:16.000Z", "max_forks_repo_path": "doc/user_manual/include/CVaR.tex", "max_forks_repo_name": "albernsrya/LOGOS", "max_forks_repo_head_hexsha": "535a25ccd3a83259b615acd569257d751fe00439", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-05T17:18:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T14:36:42.000Z", "avg_line_length": 35.5800865801, "max_line_length": 229, "alphanum_fraction": 0.6282394452, "num_tokens": 6205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629215, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6757778445071767}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Brief background for derivation of the cable equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nSee \\cite{lindsay_2004} for a detailed derivation of the cable equation, and extensions to the one-dimensional model that account for radial variation of potential.\n\nThe one-dimensional cable equation introduced later in equations~\\eq{eq:cable} and~\\eq{eq:cable_balance} is based on the following expression in three dimensions (based on Maxwell's equations adapted for neurological modelling)\n\\begin{equation}\n    \\nabla \\cdot \\vv{J} = 0,\n    \\label{eq:J}\n\\end{equation}\nwhere $\\vv{J}$ is current density (units $A/m^2$).\nCurrent density is in turn defined in terms of electric field $\\vv{E}$ (units $V/m$)\n\\begin{equation}\n    \\vv{J} = \\sigma \\vv{E},\n\\end{equation}\nwhere $\\sigma$ is the specific electrical conductivity of intra-cellular fluid (typically 3.3 $S/m$).\n\nThe derivation of the cable equation is based on two assumptions:\n\\begin{enumerate}\n    \\item that charge disperion is effectively instantaneous for the purposes of dendritic modelling.\n    \\item that diffusion of magnetic field is instant, i.e. it behaves quasi-statically in the sense that it is determined by the electric field through the Maxwell equations.\n\\end{enumerate}\nUnder these conditions, $\\vv{E}$ is conservative, and as such can be expressed in terms of a potential field\n\\begin{equation}\n    \\vv{E} = \\nabla \\phi,\n\\end{equation}\nwhere the extra/intra-cellular potential field $\\phi$ has units $mV$.\n\nThe derivation of the one-dimensional conservation equation \\eq{eq:cable_balance} is based on the assumption that the intra-cellular potential (i.e. inside the cell) does not vary radially.\nThat is, potential is a function of the axial distance $x$ alone\n\\begin{equation}\n    \\vv{E} = \\nabla \\phi = \\pder{V}{x}.\n\\end{equation}\nThis is not strictly true, because a potential field that is a variable of $x$ and $t$ alone can't support the axial gradients required to drive the potential difference over the cell membrane.\nI am still trying to get my head around the assumptions made in mapping a three-dimensional problem to a pseudo one-dimensional one.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{The cable equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe cable equation is a nonlinear parabolic PDE that can be written in the form\n\\begin{equation}\n    \\label{eq:cable}\n    c_m \\pder{V}{t} = \\frac{1}{2\\pi a r_{L}} \\pder{}{x} \\left( a^2 \\pder{V}{x} \\right) - i_m + i_e,\n\\end{equation}\nwhere\n\\begin{itemize}\n    \\item $V$ is the potential relative to the ECM $[mV]$\n    \\item $a$ is the cable radius $(mm)$, and can vary with $x$\n    \\item $c_m$ is the {specific membrane capacitance}, approximately the same for all neurons $\\approx 10~nF/mm^2$. Related to \\emph{membrane capacitance} $C_m$ by the relationship $C_m=c_{m}A$, where $A$ is the surface area of the cell.\n    \\item $i_m$ is the membrane current $[A\\cdot/mm^{2}]$ per unit area. The total contribution from ion and synaptic channels is expressed as a the product of current per unit area $i_m$ and the surface area.\n    \\item $i_e$ is the electrode current flowing into the cell, divided by surface area, i.e. $i_e=I_e/A$.\n    \\item $r_L$ is intracellular resistivity, typical value $1~k\\Omega \\text{cm}$\n\\end{itemize}\n\nNote that the standard convention is followed, whereby membrane and synapse currents ($i_m$) are positive when outward, and electrod currents ($i_e$) are positive inward.\n\nThe PDE in (\\ref{eq:cable}) is derived by integrating~\\eq{eq:J} over the volume of segment $i$:\n\\begin{equation*}\n    \\int_{\\Omega_i}{\\nabla \\cdot \\vv{J} } \\deriv{v} = 0,\n\\end{equation*}\nThen applying the divergence theorem to turn the volume integral on the lhs into a surface integral\n\\begin{equation}\n          \\sum_{j\\in\\mathcal{N}_i} {\\int_{\\Gamma_{i,j}} J_{i,j} \\deriv{s} }\n        + \\int_{\\Gamma_{i}} {J_m} \\deriv{s} = 0\n    \\label{eq:cable_balance_intermediate}\n\\end{equation}\nwhere\n\\begin{itemize}\n    \\item $\\int_\\Omega \\cdot \\deriv{v}$ is shorthand for the volume integral over the segment $\\Omega_i$\n    \\item $\\int_\\Gamma \\cdot \\deriv{s}$ is shorthand for the surface integral over the surface $\\Gamma$\n    \\item $J_{i,j}=-\\frac{1}{r_L}\\pder{V}{x} n_{i,j}$ is the flux per unit area of current \\emph{from segment $i$ to segment $j$} over the interface $\\Gamma_{i,j}$ between the two segments.\n    \\item the set $\\mathcal{N}_i$ is the set of segments that are neighbours of $\\Omega_i$\n\\end{itemize}\nThe transmembrane current density $J_m=\\vv{J}\\cdot\\vv{n}$ is a function of the membrane potential\n\\begin{equation}\n    J_m = c_m\\pder{V}{t} + i_m - i_e,\n    \\label{eq:Jm}\n\\end{equation}\nwhich has contributions from the ion channels and synapses ($i_m$), electrodes ($i_e$) and capacitive current due to polarization of the membrane whose bi-layer lipid structure causes it to behave locally like a parallel plate capacitor.\n\nSubstituting~\\eq{eq:Jm} into~\\eq{eq:cable_balance_intermediate} and rearanging gives\n\\begin{equation}\n      \\int_{\\Gamma_{i}} {c_m\\pder{V}{t}} \\deriv{s}\n    = - \\sum_{j\\in\\mathcal{N}_i} {\\int_{\\Gamma_{i,j}} J_{i,j} \\deriv{s} }\n    - \\int_{\\Gamma_{i}} {(i_m - i_e)} \\deriv{s}\n    \\label{eq:cable_balance}\n\\end{equation}\n\n\nThe surface of the cable segment is sub-divided into the internal and external surfaces.\nThe external surface $\\Gamma_{i}$ is the cell membrane at the interface between the extra-cellular and intra-cellular regions.\nThe current, which is the conserved quantity in our conservation law, over the surface is composed of the synapse and ion channel contributions.\nThis is derived from a thin film approximation to the cell membrane, whereby the membrane is treated as an infinitesimally thin interface between the intra and extra cellular regions.\n\nNote that some information is lost when going from a three-dimensional description of a neuron to a system of branching one-dimensional cable segments.\nIf the cell is represented by cylinders or frustrums\\footnote{a frustrum is a truncated cone, where the truncation plane is parallel to the base of the cone.}, the three-dimensional values for volume and surface area at branch points can't be retrieved from the one-dimensional description.\n\n\\begin{figure}\n    \\begin{center}\n        \\includegraphics[width=0.5\\textwidth]{./images/cable.pdf}\n    \\end{center}\n    \\caption{A single segment, or control volume, on an unbranching dendrite.}\n    \\label{fig:segment}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Finite volume discretization}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe finite volume method is a natural choice for the solution of the conservation law in~\\eq{eq:cable_balance}.\n\n\\begin{itemize}\n    \\item   the $x_i$ are spaced uniformly with distance $x_{i+1}-x_{i} = \\Delta x$\n    \\item   control volumes are formed by locating the boundaries between adjacent points at $(x_{i+1}+x_{i})/2$\n    \\item   this discretization differs from the finite differences used in Neuron because the equation is explicitly solved for at the end of cable segments, and because the finite volume discretization is applied to all points. Neuron uses special algebraic \\emph{zero area} formulation for nodes at branch points.\n\\end{itemize}\n\n%-------------------------------------------------------------------------------\n\\subsubsection{Temporal derivative}\n%-------------------------------------------------------------------------------\nThe integral on the lhs of~\\eq{eq:cable_balance} can be approximated by assuming that the average transmembrane potential $V$ in $\\Omega_i$ is equal to the potential $V_i$ defined at the centre of the segment:\n\\begin{equation}\n    \\int_{\\Gamma_i}{c_m \\pder{V}{t} } \\deriv{v} \\approx \\sigma_i \\cmi \\pder{V_i}{t},\n    \\label{eq:dvdt}\n\\end{equation}\nwhere $\\sigma_i$ is the surface area, and $\\cmi$ is the average specific membrane capacitance, respectively of the surface $\\Gamma_i$.\n\nEach control volume is composed of \\emph{sub control volumes}, which are illustrated as the coloured sub-regions in \\fig{fig:segment}.\n\\begin{equation*}\n    \\Omega_i = \\bigcup_{j\\in\\mathcal{N}_i}{\\Omega_i^j}.\n\\end{equation*}\nLikewise, the surface $\\Gamma_i$ is composed of subsufaces as follows\n\\begin{equation*}\n    \\Gamma_i = \\bigcup_{j\\in\\mathcal{N}_i}{\\Gamma_i^j},\n\\end{equation*}\nwhere $\\Gamma_i^j$ is the surface of each of the sub-control volumes in $\\Omega_i$.\nThus, the surface area of the CV as\n\\begin{equation*}\n    \\sigma_i = \\sum_{i\\in\\mathcal{N}_i}{\\sigma_i^j},\n\\end{equation*}\nwhere $\\sigma_i^j$ is the area of $\\Gamma_i^j$, and the average specific membrane capacitance $\\cmi$ is\n\\begin{equation*}\n    \\cmi = \\frac{1}{\\sigma_i}\\sum_{i\\in\\mathcal{N}_i}{\\sigma_i^j c_m^{i,j}}.\n\\end{equation*}\n\\todo{This  is included as a placeholder, we really need more illustrations to show how CV averages are computed for quantities that vary between sub-control volumes of the same CV.}\n\n%-------------------------------------------------------------------------------\n\\subsubsection{Intra-cellular flux}\n%-------------------------------------------------------------------------------\nThe intracellular flux terms in~\\eq{eq:cable_balance} are sum of the flux over the interfaces between compartment $i$ and its set of neighbouring compartments $\\mathcal{N}_i$ is\n\\begin{equation}\n    \\sum_{j\\in\\mathcal{N}_i} { \\int_{\\Gamma_{i,j}} { J_{i,j} \\deriv{s} } }.\n\\end{equation}\nwhere the flux per unit area from compartment $i$ to compartment $j$ is\n\\begin{align}\n    J_{i,j} = - \\frac{1}{r_L}\\pder{V}{x} n_{i,j}.\n    \\label{eq:J_ij_exact}\n\\end{align}\nThe derivative with respect to the outward-facing normal can be approximated as follows\n\\begin{equation*}\n    \\pder{V}{x} n_{i,j} \\approx \\frac{V_j - V_i}{\\Delta x_{i,j}}\n\\end{equation*}\nwhere $\\Delta x_{i,j}$ is the distance between $x_i$ and $x_j$, i.e. $\\Delta x_{i,j}=|x_i-x_j|$.\nUsing this approximation for the derivative, the flux over the surface in~\\eq{eq:J_ij_exact} is approximated as\n\\begin{align}\n    J_{i,j} \\approx \\frac{1}{r_L}\\frac{V_i - V_j}{\\Delta x_{i,j}}.\n    \\label{eq:J_ij_intermediate}\n\\end{align}\n\nThe terms inside the integral in equation~\\eq{eq:J_ij_intermediate} are constant everywhere on the surface $\\Gamma_{i,j}$, so the integral becomes\n\\begin{align}\n  J_{i,j} &\\approx \\int_{\\Gamma_{i,j}}  \\frac{1}{r_L}\\frac{V_i-V_j}{\\Delta x_{i,j}} \\deriv{s} \\nonumber \\\\\n          &= \\frac{1}{r_L \\Delta x_{i,j}}(V_i-V_j) \\int_{\\Gamma_{i,j}} 1 \\deriv{s} \\nonumber \\\\\n          &= \\frac{\\sigma_{ij}}{r_L \\Delta x_{i,j}}(V_i-V_j) \\nonumber \\\\\n          \\label{eq:J_ij}\n\\end{align}\nwhere $\\sigma_{i,j}=\\pi a_{i,j}^2$ is the area of the surface $\\Gamma_{i,j}$, which is a circle of radius $a_{i,j}$.\n\nSome symmetries\n\\begin{itemize}\n    \\item $\\sigma_{i,j}=\\sigma_{j,i}$ : surface area of $\\Gamma_{i,j}$\n    \\item $\\Delta x_{i,j}=\\Delta x_{j,i}$ : distance between $x_i$ and $x_j$\n    \\item $n_{i,j}=-n_{j,i}$ : surface ``norm''/orientation\n    \\item $J_{i,j}=n_{j,i}\\cdot J_{i,j}=-J_{j,i}$ : charge flux over $\\Gamma_{i,j}$\n\\end{itemize}\n\n%-------------------------------------------------------------------------------\n\\subsubsection{Cell membrane flux}\n%-------------------------------------------------------------------------------\nThe final term in~\\eq{eq:cable_balance} with an integral is the cell membrane flux contribution\n\\begin{equation}\n    \\int_{\\Gamma_{ext}} {(i_m - i_e)} \\deriv{s},\n\\end{equation}\nwhere the current $i_m$ is due to ion channel and synapses, and $i_e$ is any artificial electrode current.\nThe $i_m$ term is dependent on the potential difference over the cell membrane $V_i$.\nThe current terms are an average per unit area, therefore the total flux \n\\begin{equation}\n    \\int_{\\Gamma_{ext}} {(i_m - i_e)} \\deriv{s}\n        \\approx\n    \\sigma_i(i_m(V_i) - i_e(x_i)),\n        \\label{eq:J_im}\n\\end{equation}\nwhere $\\sigma_i$ is the surface area the of the exterior of the cable segment, i.e. the surface corresponding to the cell membrane.\n\nEach cable segment is a conical frustrum, as illustrated in \\fig{fig:segment}.\nThe lateral surface area of a frustrum with height $\\Delta x_i$ and radii of  is\nThe area of the external surface $\\Gamma_{i}$ is\n\\begin{equation}\n    \\sigma_i = \\pi (a_{i,\\ell} + a_{i,r}) \\sqrt{\\Delta x_i^2 + (a_{i,\\ell} - a_{i,r})^2},\n    \\label{eq:cv_volume}\n\\end{equation}\nwhere $a_{i,\\ell}$ and $a_{i,r}$ are the radii of at the left and right end of the segment respectively (see~\\eq{eq:frustrum_area} for derivation of this formula).\n%-------------------------------------------------------------------------------\n\\subsubsection{Putting it all together}\n%-------------------------------------------------------------------------------\nBy substituting the volume averaging of the temporal derivative in~\\eq{eq:dvdt} approximations for the flux over the surfaces in~\\eq{eq:J_ij} and~\\eq{eq:cv_volume} respectively into the conservation equation~\\eq{eq:cable_balance} we get the following ODE defined for each node in the cell\n\\begin{equation}\n    \\sigma_i \\cmi \\dder{V_i}{t}\n       = -\\sum_{j\\in\\mathcal{N}_i} {\\frac{\\sigma_{i,j}}{r_L \\Delta x_{i,j}} (V_i-V_j)} - \\sigma_i\\cdot(i_m(V_i) - i_e(x_i)),\n    \\label{eq:ode}\n\\end{equation}\nwhere\n\\begin{equation}\n    \\sigma_{i,j} = \\pi a_{i,j}^2\n    \\label{eq:sigma_ij}\n\\end{equation}\nis the area of the surface between two adjacent segments $i$ and $j$, and\n\\begin{equation}\n    \\sigma_{i}   = \\pi(a_{i,\\ell} + a_{i,r}) \\sqrt{\\Delta x_i^2 + (a_{i,\\ell} - a_{i,r})^2},\n    \\label{eq:sigma_i}\n\\end{equation}\nis the lateral area of the conical frustrum describing segment $i$.\n\n%-------------------------------------------------------------------------------\n\\subsubsection{Time Stepping}\n%-------------------------------------------------------------------------------\nThe finite volume discretization approximates spatial derivatives, reducing the original continuous formulation into the set of ODEs, with one ODE for each compartment, in equation~\\eq{eq:ode}.\nHere we employ an implicit euler temporal integration sheme, wherby the temporal derivative on the lhs is approximated using forward differences\n\\begin{align}\n    \\sigma_i c_m \\frac{V_i^{k+1}-V_i^{k}}{\\Delta t}\n        = & -\\sum_{j\\in\\mathcal{N}_i} {\\frac{\\sigma_{i,j}}{r_L \\Delta x_{i,j}} (V_i^{k+1}-V_j^{k+1})} \\nonumber \\\\\n          & - \\sigma_i\\cdot(i_m(V_i^{k}) - i_e),\n    \\label{eq:ode_subs}\n\\end{align}\nWhere $V^k$ is the value of $V$ in compartment $i$ at time step $k$.\nNote that on the rhs the value of $V$ at the target time step $k+1$ is used, with the exception of calculating the ion channel and synaptic currents $i_m$.\nThe current $i_m$ is often a nonlinear function of voltage, so if it was formulated in terms of $V^{k+1}$ the system in~\\eq{eq:ode_subs} would be nonlinear, requiring Newton iterations to resolve.\n\nThe equations can be rearranged to have all unknown voltage values on the lhs, and values that can be calculated directly on the rhs:\n\\begin{align}\n    & \\frac{\\sigma_i \\cmi}{\\Delta t} V_i^{k+1} + \\sum_{j\\in\\mathcal{N}_i} {\\alpha_{ij} (V_i^{k+1}-V_j^{k+1})}\n            \\nonumber \\\\\n    = & \\frac{\\sigma_i \\cmi}{\\Delta t} V_i^k -  \\sigma_i(i_m^{k} - i_e),\n    \\label{eq:ode_linsys}\n\\end{align}\nwhere the value\n\\begin{equation}\n    \\alpha_{ij} = \\alpha_{ji} = \\frac{\\sigma_{ij}}{ r_L \\Delta x_{ij}}\n    \\label{eq:alpha_linsys}\n\\end{equation}\nis a constant that can be computed for each interface between adjacent compartments during set up.\n\nThe left hand side of \\eq{eq:ode_linsys} can be rearranged\n\\begin{equation}\n    \\left[ \\frac{\\sigma_i \\cmi}{\\Delta t} + \\sum_{j\\in\\mathcal{N}_i} {\\alpha_{ij}} \\right] V_i^{k+1}\n    - \\sum_{j\\in\\mathcal{N}_i} { \\alpha_{ij} V_j^{k+1}},\n    \\label{eq:rhs_linsys}\n\\end{equation}\nwhich gives the coefficients for the linear system.\n\nThe capacitance of the cell membrane, $\\sigma_i \\cmi$, varies between control volumes, while the $\\alpha_{i,j}$ term in symmetric (i.e. $\\alpha_{i,j}=\\alpha_{j,i}$.)\nWith this in mind, we can see that when the linear system is written in the form~\\eq{eq:ode_linsys}, the matrix is symmetric.\nFurthermore, because $\\alpha_{i,j} > 0$, the linear system is diagonally dominant for sufficiently small $\\Delta t$.\n\n%-------------------------------------------------------------------------------\n\\subsubsection{The Soma}\n%-------------------------------------------------------------------------------\nWe model the soma as a sphere with a centre $\\vv{x}_s$ and a radius $r_s$.\nThe soma is conceptually treated as the center of the cell: the point from which all other parts of the cell branch.\nIt requires special treatment, because of its size relative to the radius of the dendrites and axons that branch off from it.\n\nThough the soma is usually visualized as a sphere, it is \\emph{worth noting} that Neuron models the soma as a cylinder\n\\begin{itemize}\n    \\item A cylinder that has the same diameter as length ($L=2r$) has the same area as a sphere with radius $r$, i.e. $4\\pi r^2$.\n    \\item However a sphere has 4/3 times the volume of the cylinder.\n\\end{itemize}\n\nIf the soma is modelled as a single compartment the potential is assumed constant throughout the cell.\nThis is exactly the same model used to handle branches, with the main difference being how the area and volume of the control volume centred on the soma are calculated as a result of the spherical model.\n\n\\begin{figure}\n    \\begin{center}\n        \\includegraphics[width=0.5\\textwidth]{./images/soma.pdf}\n    \\end{center}\n    \\caption{A soma with two dendrites.}\n    \\label{fig:soma}\n\\end{figure}\n\n\\fig{fig:soma} shows a soma that is attached to two unbranched dendrites.\nIn this example the simplest possible compartment model is used, with three compartments: one for the soma and one for each of the dendrites.\nThe soma CV extends to half way along each dendrite.\nTo calculate the flux from the soma compartment to the dendrites the flux over the CV face half way along each dendrite has to be computed.\nFor this we use the voltage defined at each end of the dendrite, which raises the question about what value to use for the end of the dendrite that is attached to the soma.\nFor this we use the voltage as defined for the soma, i.e. we use the same value at the start for each dendrite, as illustrated in \\fig{fig:soma}.\n\nThis effectivly of ``collapses'' the node that defines the start of dendrites attached to the soma onto the soma in the mathematical formulation.\nThis requires a little slight of hand when loading the cell description from file (for example a \\verb!.swc! file).\nIn such file formats there would be 5 points used to describe the cell in \\fig{fig:soma}:\n\\begin{itemize}\n    \\item 1 to describe the center of the soma.\n    \\item 2 for each dendrite: 1 describing where the dendrite is attached to the soma, and 1 for the terminal end.\n\\end{itemize}\nHowever, in the mathematical formulation there are only 3 values that are solved for: the soma and one for each of the dendrites.\n\nOn a side note, one possible extension is to model the soma as a set of shells, like an onion.\nConceptually this would look like an additional branch from the surface of the soma, with the central core being the terminal of the branch.\nHowever, the cable equation would have to be reformulated in spherical coordinates.\n\n\n%-------------------------------------------------------------------------------\n\\subsubsection{Handling Branches}\n%-------------------------------------------------------------------------------\nThe value of the lateral area $\\sigma_i$ in~\\eq{eq:sigma_i} is the sum of the areaof each branch at branch points.\n\n\\todo{a picture of a branching point to illustrate}\n\n\\todo{a picture of a soma to illustrate the ball and stick model with a sphere for the soma and sticks for the dendrites branching off the soma.}\n\n\\begin{equation}\n    \\sigma_i = \\sum_{j\\in\\mathcal{N}_i} {\\dots}\n\\end{equation}\n\n", "meta": {"hexsha": "d3eba7a64c4bdf8ad8bcb0da402f9bde9513da3e", "size": 20106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/math/model/formulation.tex", "max_stars_repo_name": "kabicm/arbor", "max_stars_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68", "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/math/model/formulation.tex", "max_issues_repo_name": "kabicm/arbor", "max_issues_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-03-26T16:29:39.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-27T13:41:49.000Z", "max_forks_repo_path": "doc/math/model/formulation.tex", "max_forks_repo_name": "kabicm/arbor", "max_forks_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-26T14:05:31.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-26T14:05:31.000Z", "avg_line_length": 60.5602409639, "max_line_length": 316, "alphanum_fraction": 0.668208495, "num_tokens": 5441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6757442221461523}}
{"text": "\n\\section{Basic heap concepts}\n\\Label{sec:heap-concepts}\n\nThe description of heaps at the beginning of this chapter is of course fairly vague.\nIt outlines only the most important properties\nof various operations but does not clearly state what specific and verifiable\nproperties a range must satisfy such that it may be called a heap.\n\nA more detailed description can be found in the Apache \\cxx Standard Library User's Guide:\\footnote{\n  See \\url{http://stdcxx.apache.org/doc/stdlibug/14-7.html}\n}\n\n\\begin{quote}\nA heap is a binary tree in which every node is larger than the values\nassociated with either child. A heap and a binary tree, for that matter,\ncan be very efficiently stored in a vector, by placing the children of\nnode $i$\nat positions $2i + 1$ and $2i + 2$.\n\\end{quote}\n\nWe have, in other words, the following basic relations between indices of a heap:\n\n\\begin{align}\n\\Label{eq:heap-left}\n   &\\text{left child for index $i$}   && \\mathrm{child_l}: i \\mapsto 2i + 1  \\\\\n\\Label{eq:heap-right}\n   &\\text{right child for index $i$}  && \\mathrm{child_r}: i \\mapsto 2i + 2  \\\\\n\\intertext{and}\n\\Label{eq:heap-parent}\n   &\\text{parent index for index $i$}  && \\mathrm{parent}: i \\mapsto \\frac{i - 1}{2}\n\\end{align}\n\n%\\clearpage \n\nThese function are related through the following two equations\nthat hold for all integers~$i$.\nNote that in \\acsl integer division rounds towards zero (cf.\\ \\cite[\\S 2.2.4]{ACSLSpec}).\n\n\\begin{align}\n\\Label{eq:heap-parent-left}\n   \\mathrm{parent}(\\mathrm{child_l}(i)) &= i \\\\\n\\Label{eq:heap-parent-right}\n   \\mathrm{parent}(\\mathrm{child_r}(i)) &= i\n\\end{align}\n\n\nIn order to given an example for the usefulness of heaps\nwe consider the following multiset of integers $X$.\n\n\\begin{align}\n\\Label{eq:heap-multiset}\n  X &= \\{2,3,3,3,6,7,8,8,9,11,13,14\\}\n\\end{align}\n\n\\clearpage\n\nFigure~\\ref{fig:heap-tree} shows how the multiset from Equation~\\eqref{eq:heap-multiset} \ncan, according to the parent-child relations of a heap, be represented as a tree.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.75\\linewidth]{Figures/heap_tree_color.pdf}\n\\caption{\\Label{fig:heap-tree}Tree representation of the multiset~$X$}\n\\end{figure}\n\n\\FloatBarrier\n\nThe numbers outside the nodes in Figure~\\ref{fig:heap-tree} are the indices at which\nthe respective node value is stored in the underlying array of a heap (cf.\\ Figure~\\ref{fig:heap-array}).\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.65\\linewidth]{Figures/heap_array_color.pdf}\n\\caption{\\Label{fig:heap-array}Underlying array of a heap}\n\\end{figure}\n\n\\FloatBarrier\n\\clearpage\n\nIt is important to understand that there can be various representations of a multiset\nas a heap.\nFigure~\\ref{fig:heap-alternative-tree}, for example, arranges the elements of\nthe multiset~$X$ as a heap in a different tree.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.75\\linewidth]{Figures/heap_tree_alternative_color.pdf}\n\\caption{\\Label{fig:heap-alternative-tree} An alternative representation of the multiset~$X$}\n\\end{figure}\n\n\\FloatBarrier\n\nFigure~\\ref{fig:heap-array-alternative} then shows the underlying array that \ncorresponds to the tree in Figure~\\ref{fig:heap-alternative-tree}.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.65\\linewidth]{Figures/heap_array_alternative_color.pdf}\n\\caption{\\Label{fig:heap-array-alternative}Underlying array of the alternative representation}\n\\end{figure}\n\n\\FloatBarrier\n\\clearpage\n\n", "meta": {"hexsha": "13cf6577118a497b44cf0554edf3a4f97a0d41ee", "size": 3427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/heap/heap_concepts.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/heap_concepts.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/heap_concepts.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 32.3301886792, "max_line_length": 105, "alphanum_fraction": 0.7537204552, "num_tokens": 994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6757000672504694}}
{"text": "\\subsection*{b)}\nIn this assignment we will provide a parametric bootstrapped 95\\% confidence interval for the parameters. Since we have a dataset that we can evaluate parameters from, we need to determine the uncertainty of the estimators. To assess the uncertainty we analyze the distribution function $F_{\\Delta}$ of the error $\\Delta$ under $\\mathbb{P}_0$. This uncertainty can be bounded by confidence intervals to assess the uncertainty we analyze the distribution function $F_{\\Delta}$ of the error $\\Delta$ under $\\mathbb{P}_0$. \\\\\n\nFirst of, we begin the bootstrap as described previously. We therefore estimate the parameters of the data by the function \\texttt{est\\_gumpel.m}. These estimates are the frequentistic approach using maximum likelihood. We then sample new data by generating random numbers and sampling using the inverse method of the relation derived in section \\textbf{a)}. Thereafter we calculate the error of our estimates by the relation $\\Delta_b^*(t)=\\hat{t}_b^*-\\hat{t}$. To get the confidence bounds for our estimates we used the relation \\eqref{conf} derived in Jimmy Olssons lecture notes \\cite{JO} \n\\begin{equation} I_{\\alpha}=\\left(t(y) - F_\\Delta^{-1}(F_\\Delta^{-1}(1-\\alpha/2),t(y)-F_\\Delta^{-1}(\\alpha/2)\\right).\n\\label{conf}\n \\end{equation}\n\nHowever, we also need to check the bias of our estimate by the relation\n\\[ B_t=\\mathbb{E}_0(t(Y)-\\tau)=\\mathbb{E}_0(\\Delta(Y))=\\int zf_\\Delta (z) dz, \\]\nwhere $f_\\Delta(z)=\\frac{d}{dz}F_\\Delta(z)$ denoting the density of $\\Delta(Y)$. The calculated bias of the estimator for $\\mu$ and $\\beta$ respectively was computed as \n\\[ B_t = \\mathbb{E}_0(\\Delta_b^*(t))=\\left\\{ \\begin{array}{l}\n-0.0009 \\\\ 0.0037\n\\end{array}\\right. \\]\n\nThe bias was then taken into consideration by making the bias-corrected estimate $t-B_t$. \n\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|c|}\n\\hline\n\n & L & U \\\\ \\hline\n%Estimates & 1.4858 & 4.1477 \\\\ \\hline\n$\\beta$ & 1.3942 & 1.5821 \\\\ \\hline\n$\\mu$ & 4.0220 & 4.2723 \\\\ \\hline\n\n\\end{tabular}\n\\caption{Table showing the expected values and upper and lower bounds.}\n\\end{table}\n\nIn figure \\ref{fig:estwaves} the histogram of the estimated dataset as well as the dataset is plotted.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.26]{./Figures/estwaves.png}\n\n\\label{fig:estwaves}\n\\caption{A histrogram of the estimated dataset, plotted over the real dataset.}\n\\end{figure} \n\nHere we can see the upper and lower cconfidence bound of the estimated wavesplotted with the raw data. One can observe that the gumpel approximation is indeed an approximation of the data.\n", "meta": {"hexsha": "7b9cda759b663b387c7a4870a7bf32416299ee14", "size": 2579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/Report/task2b.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/task2b.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/task2b.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": 59.976744186, "max_line_length": 593, "alphanum_fraction": 0.7402093835, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6756888418409073}}
{"text": "\\documentclass[20pt,a4paper]{extarticle}\n\\usepackage[a4paper,margin=6mm]{geometry}\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\n\\title{\\LaTeX\\ Mathematics Examples}\n\\author{Prof Tony Roberts}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\n\n\\section{Delimiters}\n\nSee how the delimiters are of reasonable size in these examples\n\\[\n\t\\left(a+b\\right)\\left[1-\\frac{b}{a+b}\\right]=a\\,,\n\\]\n\\[\n\t\\sqrt{|xy|}\\leq\\left|\\frac{x+y}{2}\\right|,\n\\]\neven when there is no matching delimiter\n\\[\n\t\\int_a^bu\\frac{d^2v}{dx^2}\\,dx\n\t=\\left.u\\frac{dv}{dx}\\right|_a^b\n\t-\\int_a^b\\frac{du}{dx}\\frac{dv}{dx}\\,dx.\n\\]\n\n\n\n\n\n\n\\section{Spacing}\n\nDifferentials often need a bit of help with their spacing as in\n\\[\n\t\\iint xy^2\\,dx\\,dy\n\t=\\frac{1}{6}x^2y^3,\n\\]\nwhereas vector problems often lead to statements such as\n\\[\n\tu=\\frac{-y}{x^2+y^2}\\,,\\quad\n\tv=\\frac{x}{x^2+y^2}\\,,\\quad\\text{and}\\quad\n\tw=0\\,.\n\\]\nOccasionally one gets horrible line breaks when using a list in mathematics such as listing the first twelve primes  \\(2,3,5,7,11,13,17,19,23,29,31,37\\)\\,.\nIn such cases, perhaps include \\verb|\\mathcode`\\,=\"213B| inside the inline maths environment so that the list breaks: \\(\\mathcode`\\,=\"213B 2,3,5,7,11,13,17,19,23,29,31,37\\)\\,.\nBe discerning about when to do this as the spacing is different.\n\n\n\n\n\n\n\\section{Arrays}\n\nArrays of mathematics are typeset using one of the matrix environments as\nin\n\\[\n\t\\begin{bmatrix}\n\t\t1 & x & 0 \\\\\n\t\t0 & 1 & -1\n\t\\end{bmatrix}\\begin{bmatrix}\n\t\t1  \\\\\n\t\ty  \\\\\n\t\t1\n\t\\end{bmatrix}\n\t=\\begin{bmatrix}\n\t\t1+xy  \\\\\n\t\ty-1\n\t\\end{bmatrix}.\n\\]\nCase statements use cases:\n\\[\n\t|x|=\\begin{cases}\n\t\tx, & \\text{if }x\\geq 0\\,,  \\\\\n\t\t-x, & \\text{if }x< 0\\,.\n\t\\end{cases}\n\\]\nMany arrays have lots of dots all over the place as in\n\\[\n\t\\begin{matrix}\n\t\t-2 & 1 & 0 & 0 & \\cdots & 0  \\\\\n\t\t1 & -2 & 1 & 0 & \\cdots & 0  \\\\\n\t\t0 & 1 & -2 & 1 & \\cdots & 0  \\\\\n\t\t0 & 0 & 1 & -2 & \\ddots & \\vdots \\\\\n\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\ddots & 1  \\\\\n\t\t0 & 0 & 0 & \\cdots & 1 & -2\n\t\\end{matrix}\n\\]\n\n\n\n\n\n\n\\section{Equation arrays}\n\nIn the flow of a fluid film we may report\n\\begin{eqnarray}\n\tu_\\alpha & = & \\epsilon^2 \\kappa_{xxx}\n\t\\left( y-\\frac{1}{2}y^2 \\right),\n\t\\label{equ}  \\\\\n\tv & = & \\epsilon^3 \\kappa_{xxx} y\\,,\n\t\\label{eqv}  \\\\\n\tp & = & \\epsilon \\kappa_{xx}\\,.\n\t\\label{eqp}\n\\end{eqnarray}\nAlternatively, the curl of a vector field $(u,v,w)$ may be written\nwith only one equation number:\n\\begin{eqnarray}\n\t\\omega_1 & = &\n\t\\frac{\\partial w}{\\partial y}-\\frac{\\partial v}{\\partial z}\\,,\n\t\\nonumber  \\\\\n\t\\omega_2 & = &\n\t\\frac{\\partial u}{\\partial z}-\\frac{\\partial w}{\\partial x}\\,,\n\t\\label{eqcurl}  \\\\\n\t\\omega_3 & = &\n\t\\frac{\\partial v}{\\partial x}-\\frac{\\partial u}{\\partial y}\\,.\n\t\\nonumber\n\\end{eqnarray}\nWhereas a derivation may look like\n\\begin{eqnarray*}\n\t(p\\wedge q)\\vee(p\\wedge\\neg q) & = & p\\wedge(q\\vee\\neg q)\n\t\\quad\\text{by distributive law}  \\\\\n\t & = & p\\wedge T \\quad\\text{by excluded middle}  \\\\\n\t & = & p \\quad\\text{by identity}\n\\end{eqnarray*}\n\n\n\n\n\n\n\\section{Functions}\n\nObserve that trigonometric and other elementary functions are typeset\nproperly, even to the extent of providing a thin space if followed by\na single letter argument:\n\\[\n\t\\exp(i\\theta)=\\cos\\theta +i\\sin\\theta\\,,\\quad\n\t\\sinh(\\log x)=\\frac{1}{2}\\left( x-\\frac{1}{x} \\right).\n\\]\nWith sub- and super-scripts placed properly on more complicated\nfunctions,\n\\[\n\t\\lim_{q\\to\\infty}\\|f(x)\\|_q\n\t=\\max_{x}|f(x)|,\n\\]\nand large operators, such as integrals and\n\\begin{eqnarray*}\n\te^x & = & \\sum_{n=0}^\\infty \\frac{x^n}{n!}\n\t\\quad\\text{where }n!=\\prod_{i=1}^n i\\,,  \\\\\n\t\\overline{U_\\alpha} & = & \\bigcap_\\alpha U_\\alpha\\,.\n\\end{eqnarray*}\nIn inline mathematics the scripts are correctly placed to the side in\norder to conserve vertical space, as in\n\\(\n\t1/(1-x)=\\sum_{n=0}^\\infty x^n.\n\\)\n\n\n\n\n\n\n\\section{Accents}\n\nMathematical accents are performed by a short command with one\nargument, such as\n\\[\n\t\\tilde f(\\omega)=\\frac{1}{2\\pi}\n\t\\int_{-\\infty}^\\infty f(x)e^{-i\\omega x}\\,dx\\,,\n\\]\nor\n\\[\n\t\\dot{\\vec \\omega}=\\vec r\\times\\vec I\\,.\n\\]\n\n\n\n\n\n\\section{Command definition}\n\n\\newcommand{\\Ai}{\\operatorname{Ai}}\nThe Airy function, $\\Ai(x)$, may be incorrectly defined as this\nintegral\n\\[\n\t\\Ai(x)=\\int\\exp(s^3+isx)\\,ds\\,.\n\\]\n\n\\newcommand{\\D}[2]{\\frac{\\partial #2}{\\partial #1}}\n\\newcommand{\\DD}[2]{\\frac{\\partial^2 #2}{\\partial #1^2}}\n\\renewcommand{\\vec}[1]{\\boldsymbol{#1}}\n\nThis vector identity serves nicely to illustrate two of the new\ncommands:\n\\[\n\t\\vec\\nabla\\times\\vec q\n\t=\\vec i\\left(\\D yw-\\D zv\\right)\n\t+\\vec j\\left(\\D zu-\\D xw\\right)\n\t+\\vec k\\left(\\D xv-\\D yu\\right).\n\\]\n\nRecall that typesetting multi-line mathematics is an art normally too hard for computer recipes.  Nonetheless, if you need to be automatically flexible about multi-line mathematics, and you do not mind some rough typesetting, then perhaps invoke \\verb|\\parbox| to help as follows:\n% The \\verb|breqn| package is not yet reliable enough for general use.\n\\newcommand{\\parmath}[2][0.8\\linewidth]{\\parbox[t]{#1}%\n    {\\raggedright\\linespread{1.2}\\selectfont\\(#2\\)}}\n\\[\nu_1=\\parmath{ -2 \\gamma  \\epsilon^{2} s_{2}+\\mu  \\epsilon^{3} \\big( \\frac{3}{8} s_{2}+\\frac{1}{8} s_{1} i\\big)+\\epsilon^{3} \\big( -\\frac{81}{32} s_{4} s_{2}^{2}-\\frac{27}{16} s_{4} s_{2} s_{1} i+\\frac{9}{32} s_{4} s_{1}^{2}+\\frac{27}{32} s_{3} s_{2}^{2} i-\\frac{9}{16} s_{3} s_{2} s_{1}-\\frac{3}{32} s_{3} s_{1}^{2} i\\big) +\\int_a^b 1-2x+3x^2-4x^3\\,dx }\n\\]\nAlso, sometimes use \\verb|\\parbox| to typeset multiline entries in tables.\n\n\n\\section{Theorems et al.}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{definition}[theorem]{Definition}\n\n\\begin{definition}[right-angled triangles] \\label{def:tri}\nA \\emph{right-angled triangle} is a triangle whose sides of length~\\(a\\), \\(b\\) and~\\(c\\), in some permutation of order, satisfies \\(a^2+b^2=c^2\\).\n\\end{definition}\n\n\\begin{lemma}\nThe triangle with sides of length~\\(3\\), \\(4\\) and~\\(5\\) is right-angled.\n\\end{lemma}\n\nThis lemma follows from the Definition~\\ref{def:tri} as \\(3^2+4^2=9+16=25=5^2\\).\n\n\\begin{theorem}[Pythagorean triplets] \\label{thm:py}\nTriangles with sides of length \\(a=p^2-q^2\\), \\(b=2pq\\) and \\(c=p^2+q^2\\) are right-angled triangles.\n\\end{theorem}\n\nProve this Theorem~\\ref{thm:py} by the algebra \\(a^2+b^2 =(p^2-q^2)^2+(2pq)^2\n=p^4-2p^2q^2+q^4+4p^2q^2\n=p^4+2p^2q^2+q^4\n=(p^2+q^2)^2 =c^2\\).\n\n\n\\end{document}\n", "meta": {"hexsha": "91a5802e952399c0f11d7097bc6eb734bf65da9a", "size": 6336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/examples/Mathematics_Example.tex", "max_stars_repo_name": "t4skforce/airflow-jupyter", "max_stars_repo_head_hexsha": "822eb303cd73c5d56d995281ac88e68c8d8593a2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/examples/Mathematics_Example.tex", "max_issues_repo_name": "t4skforce/airflow-jupyter", "max_issues_repo_head_hexsha": "822eb303cd73c5d56d995281ac88e68c8d8593a2", "max_issues_repo_licenses": ["MIT"], "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/examples/Mathematics_Example.tex", "max_forks_repo_name": "t4skforce/airflow-jupyter", "max_forks_repo_head_hexsha": "822eb303cd73c5d56d995281ac88e68c8d8593a2", "max_forks_repo_licenses": ["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.4457831325, "max_line_length": 353, "alphanum_fraction": 0.6496212121, "num_tokens": 2453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.6756090309875504}}
{"text": "%% \\NV{TO CHECL that in the logic we use = instead of ==}\n%% \\NV{TO CHECK that list type is L a}\n\\section{Proofs as Haskell Functions}\\label{sec:haskell-proofs}\n\nRefinement Reflection, as explained in chapter~\\ref{refinementrflection}, is a technique\nthat lets you write Haskell functions that prove theorems\nabout other Haskell functions and have your proofs machine-checked\nby \\toolname.\n%\nAs an introduction to Refinement Reflection,\nin this section, we prove that lists are monoids by\n\\begin{itemize}\n\\item \\textit{specifying monoid laws} as refinement types,\n\\item \\textit{proving the laws} by writing the implementation of the law specifications, and\n\\item \\textit{verifying the proofs} using \\toolname.\n\\end{itemize}\n\n\\subsection{Reflection of data types into logic.}\nTo start with,\nwe define a List data structure and\nteach \\toolname basic properties about List,\nnamely, how to check that proofs on lists are \\textit{total}\nand how to encode functions on List into the logic.\n\nThe data list definition @L@ is the standard recursive definition.\n\\begin{code}\n  data L [length] a = N | C a (L a)\n\\end{code}\n%\nWith the @length@ annotation in the definition \\toolname\nwill use the @length@ function to check termination\nof functions recursive on Lists.\n%\nWe define @length@ as the standard Haskell function\nthat returns natural numbers.\n%\nWe lift @length@ into logic as a \\textit{measure} (\\S~\\ref{sec:measures}),\nthat is, a \\textit{unary} function whose (1) domain is the data type and\n(2) body is a single case-expression over the datatype.\n\\begin{code}\n  type Nat = {v:Int | 0 <= v}\n\n  measure length    :: L a -> Nat\n    length N        = 0\n    length (C x xs) = 1 + length xs\n\\end{code}\n\nFinally, we teach \\toolname how to encode functions on Lists\ninto logic.\n%\nThe flag @\"--exact-data-cons\"@\nautomatically derives measures which\n(1) test if a value has a given data constructor and\n(2) extract the corresponding field's value.\n%\nFor example, \\toolname will automatically derive the following\nList manipulation measures from the List definition.\n\\begin{code}\n  isN :: L a -> Bool    -- Haskell's null\n  isC :: L a -> Bool    -- Haskell's not . null\n\n  selC1 :: L a -> a     -- Haskell's head\n  selC2 :: L a -> L a   -- Haskell's tail\n\\end{code}\n%\nNext, we describe how \\toolname uses the above measures\nto automatically reflect Haskell functions on Lists into logic.\n\n\\subsection{Reflection of Haskell functions into logic.}\nNext, we define and reflect into logic the two monoid operators on Lists.\nNamely, the identity element @mempty@ (which is the empty list)\nand an associative operator @(mappend)@ (which is list append).\n%\n\\begin{code}\n  reflect mempty\n  mempty :: L a\n  mempty = N\n\n  reflect (mappend)\n  (mappend) :: L a -> L a -> L a\n  N        mappend ys = ys\n  (C x xs) mappend ys = C x (xs mappend ys)\n\\end{code}\n\nThe reflect annotations lift the Haskell functions into logic in three steps.\n%\nFirst, check that the Haskell functions indeed terminate by checking\nthat the @length@ of the input list is decreasing,\nas specified in the data list definition.\n%\nSecond, in the logic, they define the respective uninterpreted functions\n@mempty@ and @(mappend)@.\n%\nFinally, the Haskell functions and the logical uninterpreted functions\nare related by strengthening the result type of the Haskell function\nwith the definition of the function's implementation.\n%\nFor example, with the above @reflect@ annotations,\n\\toolname will \\textit{automatically} derive the following strengthened\ntypes for the relevant functions.\n\\begin{code}\n  mempty  :: {v:L a | v = mempty && v = N }\n\n  (mappend) :: xs:L a -> ys:L a\n      -> {v:L a | v = xs mappend ys\n                && v = if isN xs then ys\n                      else C (selC1 xs) (selC2 xs mappend ys)\n         }\n\\end{code}\n\n\\subsection{Specification and Verification of Monoid Laws}\n\nNow we are ready to specify the monoid laws as refinement types and\nprovide their respective proofs as terms of those type. \\toolname\nwill verify that our proofs are valid. \n%\nNote that this is exactly what\none would do in any standard logical framework,\nlike LF~\\cite{Harper93}.\n\nThe type @Proof@ is predefined as an alias of the unit type (@()@)\nin the \\toolname's library @ProofCombinators@.\nWe summarize all the definitions we use from @ProofCombinators@ in \nFigure~\\ref{figure:proofcombinators}.\n%\nWe express theorems as refinement types by refining\nthe @Proof@ type with appropriate refinements.\n%\nFor example, the following theorem states\nthe @mempty@ is always equal to itself.\n\\begin{code}\n  trivial :: {mempty = mempty}\n\\end{code}\n%\nWhere @{mempty = mempty}@ is a simplification for the @Proof@ type\n@{v:Proof | mempty = mempty}@, since the binder @v@ is irrelevant, and\n@trivial@ is defined in @ProofCombinators@ to be unit.\n%\n\\toolname will typecheck the above code using an SMT\nsolver to check congruence on @mempty@.\n%% \\NV congruence on or with?\n%\n\n\\begin{definition}[Monoid] \\label{definition:monoid}\nThe triple (@m@, @epsilon@, @<>@) is a monoid\n(with identity element @epsilon@ and associative operator @<>@),\nif the following functions are defined. % on @m@.\n%\n\\begin{code}\n  idLeft_m  :: x:m -> {mempty mappend x = x}\n  idRight_m :: x:m -> {x mappend mempty = x}\n  assoc_m   :: x:m -> y:m -> z:m -> {x mappend (y mappend z) = (x mappend y) mappend z}\n\\end{code}\n\\end{definition}\n%\nUsing the above definition, we prove that our list type @L@ is a monoid\nby defining Haskell proof terms that satisfy the above monoid laws. \n%%We now represent these conditions applied to our list type @L@ and\n%%their proofs as (refined) types and terms of those types.\n\n\\mypara{Left Identity} is expressed\nas a refinement type signature that takes as input\na list @x:L a@ and returns a @Proof@ type refined\nwith the property @mempty <> x = x@\n\\begin{code}\n  idLeft :: x:L a -> {mempty mappend x = x}\n  idLeft x \n    =  mempty <> x \n    =. N <> x \n    =. x \n    ** QED\n\\end{code}\n%\nWe prove left identity using combinators from @ProofCombinators@ as\ndefined in Figure~\\ref{figure:proofcombinators}.\n%\nWe start from the left hand side @mempty <> x@,\nwhich is equal to @N <> x@ by calling @mempty@ thus\nunfolding the equality @mempty = N@ into the logic.\n%\nNext, the call @N <> x@ unfolds into the logic the definition of @(<>)@\non @N@ and @x@, which is equal to @x@, concluding our proof.\n%\nFinally, we use the operators @p ** QED@ which casts @p@ into a proof term.\n%\nIn short, the proof of left identity, proceeds by unfolding the definitions of @mempty@\nand @(<>)@ on the empty list.\n\n\\begin{figure}[t]\n\\centering\n\\captionsetup{justification=centering}\n\\begin{code}\n  type Proof = ()\n  data QED   = QED\n\n  trivial :: Proof\n  trivial = ()\n\n  (=.) :: x:a -> y:{a | x = y} -> {v:a | v = x}\n  x =. _ = x\n\n  (**) :: a -> QED -> Proof\n  _ ** _ = ()\n\n  (?) :: (Proof -> a) -> Proof -> a\n  f ? y = f y\n\\end{code}\n\\caption[Proof Operators and Types.]{Operators and Types defined in \\texttt{ProofCombinators}.}\n\\label{figure:proofcombinators}\n\\end{figure}\n\n\\mypara{Right identity} is proved by structural induction.\n%\nWe encode inductive proofs by case splitting on the base and inductive case\nand enforcing the inductive hypothesis via a recursive call.\n\\begin{code}\n  idRight :: x:L a -> { x <> mempty = x }\n  idRight N \n    =  N <> empty \n    =. N\n    ** QED\n\n  idRight (C x xs)\n    =  (C x xs) <> empty\n    =. C x (xs <> empty)\n    =. C x xs ? idRight xs\n    ** QED\n\\end{code}\nThe recursive call @idRight xs@ is provided\nas a third optional argument in the @(=.)@\noperator to justify the equality @xs <> empty = xs@,\nwhile the operator @(?)@ is merely a function application\nwith the appropriate precedence.\n%\nNote that LiquiHaskell, via termination and totality checking,\nis verifying that all the proof terms are well formed because\n(1) the inductive hypothesis is only applying to smaller terms and\n(2) all cases are covered.\n\n\n\\mypara{Associativity} is proved in a very similar manner,\nusing structural induction.\n%\n\\begin{code}\n  assoc :: x:L a -> y:L a -> z:L a -> {x mappend (y mappend z) = (x mappend y) mappend z}\n  assoc N y z\n    =  N <> (y <> z)\n    =. y <> z\n    =. (N <> y) <> z\n    ** QED\n\n  assoc (C x xs) y z\n    =  (C x xs) <> (y <> z)\n    =. C x (xs <> (y <> z))\n    =. C x ((xs <> y) <> z) ? associativity xs y z\n    =. (C x (xs <> y)) <> z\n    =. ((C x xs) <> y) <> z\n    ** QED\n \\end{code}\n%\nAs with the left identity, the proof proceeds by\n(1) function unfolding (or rewriting in paper and pencil proof terms),\n(2) case splitting (or case analysis), and\n(3) recursion (or induction).\n\nSince our list implementation satisfies the three monoid laws\nwe can conclude that @L a@ is a monoid.\n%\n\n%% \\NV{I need to discuss the difference between representation of proof terms and methods in the logic}\n\n\\begin{theorem}\\label{theorem:monoid:list}\n(@L a@, @epsilon@, @<>@) is a monoid.\n\\end{theorem}\n\\begin{proof}\n@L a@ is a monoid, as the implementation of\n@idLeft@, @idRight@, and @assoc@\nsatisfy the specifications of\n@idLeft_m@, @idRight_m@, and @assoc_m@, with @m = L a@.\n\\cqed\\end{proof}\n", "meta": {"hexsha": "e47dd53fcdb0867d6aa9e09f864c749522a502d9", "size": 9048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/haskell-proofs.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/haskell-proofs.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/haskell-proofs.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.1992882562, "max_line_length": 103, "alphanum_fraction": 0.6951812555, "num_tokens": 2570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6756090257037315}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\\usepackage{amsmath}\n\\usepackage{array} % format tabular by cm\n% define the title\n\\usepackage{hyperref}\n\\hypersetup{pdftex,colorlinks=true,allcolors=red}\n\\usepackage{hypcap}\n\\author{A.~Faraz}\n\\title{\\AmS{} Package}\n\\begin{document}\n% generates the title\n\\maketitle\n% insert the table of contents\n\\tableofcontents\n\\pagebreak\n\\section{Basics}\n\\paragraph{Simple}\n\tAdd $a$ squared and $b$ squared\n\tto get $c$ squared. Or, using\n\ta more mathematical approach:\n\t$a^2 + b^2 = c^2$\n\t\n%tags + label + eqref\n\\paragraph{Single-line}\n\tAdd $a$ squared and $b$ squared\n\tto get $c$ squared. Or, using\n\ta more mathematical approach\n\t\\begin{equation}\n\ta^2 + b^2 = c^2\n\t\\end{equation}\n\tEinstein says\n\t\\begin{equation}\n\tE = mc^2 \\label{clever}\n\t\\end{equation}\n\tHe didn’t say\n\t\\begin{equation}\n\t1 + 1 = 3 \\tag{dumb}\n\t\\end{equation}\n\tThis is a reference to\n\t\\eqref{clever}.\n\n\\paragraph{Without Numbers}\n\tAdd $a$ squared and $b$ squared\n\tto get $c$ squared. Or, using\n\ta more mathematical approach\n\t\\begin{equation*}\n\ta^2 + b^2 = c^2\n\t\\end{equation*}\n\tor you can type less for the\n\tsame effect:\n\t\\[ a^2 + b^2 = c^2 \\]\n\t\n\\pagebreak\n\\section{Formula}\n\\paragraph{Sums \\& Lim} \n\\mbox{}\\\\\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 \\rightarrow \\infty}\n\\sum_{k=1}^n \\frac{1}{k^2}\n= \\frac{\\pi^2}{6}\n\\end{equation}\n\n\\paragraph{Matrix}\n\\[\n\\begin{matrix}\na & b & c \\\\\nd & e & f \\\\\ng & h & i\n\\end{matrix}\n\\]\n\\begin{equation*}\nM = \\begin{bmatrix}\n\t\\frac{5}{6} & \\frac{1}{6} & 0           \\\\[0.3em]\n\t\\frac{5}{6} & 0           & \\frac{1}{6} \\\\[0.3em]\n\t0           & \\frac{5}{6} & \\frac{1}{6}\n\\end{bmatrix}\n\\end{equation*}\n\\begin{equation*}\n\t\\begin{matrix}\n\t\t1 & 2 \\\\\n\t\t3 & 4\n\t\\end{matrix} \\qquad\n\t\\begin{bmatrix}\n\t\tp_{11} & p_{12} &\n\t\t\\ldots\n\t\t& p_{1n} \\\\\n\t\tp_{21} & p_{22} &\n\t\t\\ldots\n\t\t& p_{2n} \\\\\n\t\t\\vdots & \\vdots &\n\t\t\\ddots\n\t\t& \\vdots \\\\\n\t\tp_{m1} & p_{m2} &\n\t\t\\ldots\n\t\t& p_{mn}\n\t\\end{bmatrix}\n\\end{equation*}\n\n\\paragraph{Integral}\n\\[ F(s) = \\int_{0}^{\\infty}{f(t)e^{-st}}\\,dt \\]\n\\[ S(x) = \\iint f(x).g(y).h(z)\\,dy\\,dz\\]\n\\paragraph{Formula + Matrix}\n~\n% h -> here\n% b -> buttom of page\n% t -> top of page\n% p -> on extra page\n% ! -> override(will force specified location)\n\\begin{table}[h!]\n\t\\centering\n\t\\begin{tabular}{| m{6.1cm} | m{6.1cm} |}\n\t\\hline\n\t\\multicolumn{2}{|c|}{laplace}\n\t\\\\\n\t\\hline\n\t\\multicolumn{1}{|c|}{$t \\rightarrow s$} & \\multicolumn{1}{c|}{$s \\rightarrow t$} \\\\\n\t\\hline\n\t$F(s) = \\int_{0}^{\\infty}{f(t).e^{-st}}\\,dt$ &\n\t$f(t) = \\newline \\frac{1}{2 \\pi i}\\lim_{T \\to \\infty} \\int_{\\gamma - iT}^{\\gamma + iT} F(s).e^{st}\\, ds$ \\\\\n\t\\hline  \n\t\\end{tabular}\n\\end{table}\n\n\\end{document}\n\n", "meta": {"hexsha": "4498cc0be336c8fbd82367acbf30d04e23b42ffc", "size": 2702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4.AMS.tex", "max_stars_repo_name": "alifarazz/latex-templates", "max_stars_repo_head_hexsha": "513e76b9900f3151fd60d5bc69012bd536ce6510", "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": "4.AMS.tex", "max_issues_repo_name": "alifarazz/latex-templates", "max_issues_repo_head_hexsha": "513e76b9900f3151fd60d5bc69012bd536ce6510", "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": "4.AMS.tex", "max_forks_repo_name": "alifarazz/latex-templates", "max_forks_repo_head_hexsha": "513e76b9900f3151fd60d5bc69012bd536ce6510", "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": 20.6259541985, "max_line_length": 108, "alphanum_fraction": 0.6080680977, "num_tokens": 1133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6756090217518794}}
{"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 7.} Sequential games with complete information III: Repeated games}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\subsection*{Exercise 1: Win-Stay Lose-Shift}\n\nThe strategy Win-Stay Lose-Shift (WSLS) cooperates in the first round. In all\nsubsequent rounds, it cooperates if either both players cooperated in the\nprevious round, or if no one did. Otherwise it defects.\n\n\\textbf{Show that for the infinitely repeated prisoner's dilemma with stage game\npayoffs}\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, 0) & (1, 1) \\\\\n        \\end{block}\n    \\end{blockarray}\n\\end{equation*}\n\n\\textbf{the strategy profile (WSLS, WSLS) is a subgame perfect equilibrium if\n\\(\\delta \\geq \\frac{1}{2}\\).}\n\n[Hint: Similarly to the examples covered in class, to prove that the strategy\nprofile (WSLS, WSLS) is a subgame perfect equilibrium we need to check different\ncases. For case one consider a history \\(h_t\\) according to which either both\nplayers cooperated in the previous round, or both players defected. For case two\nconsider that one player defected.]\n\n\\subsection*{Exercise 2: Mini-Max I}\n\nConsider the matching pennies games\n\n\\begin{equation*}\n    \\begin{blockarray}{ccc}\n        & \\text{Left} & \\text{Right} \\\\\n        \\begin{block}{c(cc)}\n            \\text{Up} &    (0.8, 0.4) & (0.4, 0.8) \\\\\n            \\text{Down} & (0.4, 0.8) & (0.8, 0.4) \\\\\n        \\end{block}\n    \\end{blockarray}\\qquad\n    \\end{equation*}\n\nShow that in the definition of minimax, it is important to allow for mixed\nstrategies of the opponent.\n\n\\textbf{Specifically show that:}\n\n\\begin{align*}\n    \\min\\limits_{s^{(2)}} \\max\\limits_{s^{(1)}} u^{(1)}(s^{(1)}, s^{(2)}) & = 0.8, \\text{ but} \\\\\n    \\min\\limits_{\\sigma^{(2)}} \\max\\limits_{s^{(1)}} u^{(1)}(s^{(1)}, \\sigma^{(2)}) & = 0.6.\n\\end{align*}\n\n\n\\subsection*{Bonus 1: Mini-Max II}\n\nShow that the minimax payoff of a player can be lower than what this player\ncould get in a Nash equilibrium. Specifically, consider the game\n\n\\begin{equation*}\n    \\begin{blockarray}{cccc}\n        & \\text{Left} & \\text{Right} \\\\\n        \\begin{block}{c(ccc)}\n            \\text{Up}  & (-2, 2)   & (1, -2)  \\\\\n            \\text{Medium} & (1, -2)   & (-2, 2)  \\\\\n            \\text{Down} & (0, 1) & (0, 1) \\\\\n        \\end{block}\n    \\end{blockarray}\\qquad\n\\end{equation*}\n\n\\begin{itemize}\n    \\item \\textbf{Show that} the Nash equilibria of this game are of the form\n    \\begin{align*}\n        \\sigma^{(1)} & = (0, 0, 1) \\\\\n        \\sigma^{(2)} & = (q, 1- q) \\text{ with } q \\in \\left[\\frac{1}{3}, \\frac{2}{3}\\right],\\\\\n    \\end{align*}\n    and the resulting payoffs are \\(\\hat{u}^{(1)} = 0, \\hat{u}^{(2)} = 1\\).\n    \\item \\textbf{Show that} player 2's minimax payoff \\(\\underline{u}^{(2)} =\n    \\min\\limits_{\\sigma^{(1)}} \\max\\limits_{s^{(2)}} u^{(2)}(\\sigma^{(1)},\n    s^{(2)}) = 0 < \\hat{u}^{(2)}\\).\n\\end{itemize}\n\nNow that you have shown that the minimax payoff of a player can be lower than\ntheir Nash equilibrium payoff, \\textbf{conclude that in repeated games with a\nsufficient large \\(\\delta\\), players may be worse off in equilibrium than in the\none shot game.}\n\n\\subsection*{Bonus Exercise 2: Folk Theorem}\n\nConsider the battle of the sexes\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\n\\textbf{What is the set of feasible and individually rational payoffs?}\n\n\\underline{Bonus:} Construct a strategy \\(\\hat{\\sigma}\\) for the repeated battle of sexes\nthat for a sufficiently large \\(\\delta\\) satisfies the following 2 conditions.\n\n\\begin{enumerate}[(i)]\n    \\item When both player adopt the strategy, they obtain a payoff of approximately\n    \\(\\pi^{(1)} = \\pi^{(2)} = 2.\\)\n    \\item \\((\\hat{\\sigma}, \\hat{\\sigma})\\) is a subgame perfect equilibrium.\n    You do not need to show this rigorously, but give a convincing argument.\n\\end{enumerate}\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "aa9a5631a3ecba5ca434d175c19e105f29b2472e", "size": 4406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w7.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/w7.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/w7.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.9275362319, "max_line_length": 97, "alphanum_fraction": 0.632092601, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8947894696095782, "lm_q1q2_score": 0.6754899806996068}}
{"text": "%!TEX root = ../main.tex\n\n\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\subsection{Derivation of Changes in the Penalty Term}\\label{app:derive_changes_penalty_term}\n% Used in section 3 - MC Simulation\nAs part of the estimation of changes in skill prices, changes in the penalty term need to be estimated. These changes in the penalty term are a funtion of optimal task choices $\\lambda_{i,\\tau}^*, \\; \\tau \\in \\{t-1, t\\}$. In this appendix, I show that changes in the penalty term result as a polynomial with penalty exponent of degree $\\phi$.\\\\\nFrom equation (\\ref{eq:wage_change}) we have that wage changes come as a composition of three parts:\n\\begin{equation}\n\t\\Delta w_{i,t} = \\bar{\\lambda}^*_{i,t} \\Delta \\tilde{\\pi}_{t} + \\bar{\\lambda}^*_{i,t} \\Delta \\tilde{s}_{i,t} + \\left[ \\rho_{i}(\\lambda_{i,t}^*) - \\rho_{i}(\\lambda_{i,t-1}^*) \\right] \\tag{\\ref{eq:wage_change}}\n\\end{equation} \nIn the following I show that the part related to changes in the penalty term (i.e., $\\left[ \\rho_{i}(\\lambda_{i,t}^*) - \\rho_{i}(\\lambda_{i,t-1}^*) \\right]$) can be restated as a polynomial of optimal task choice parameters $\\lambda_{i,\\tau}^*, \\; \\tau \\in \\{t-1, t\\}$ of degree $\\phi$.\n\\begin{align}\n\t\\intertext{Starting from}\n\t{} &  \\rho_{i}(\\lambda_{i,t}^*) - \\rho_{i}(\\lambda_{i,t-1}^*)  \\label{eq:appen_penalty_term_1} \\\\\n\t\\intertext{with}\n\t\\rho_{i}(\\lambda_{i,\\tau}^*) &= \\theta |b_i - \\lambda_{i,\\tau}^*|^\\phi, \\; \\text{for} \\; \\tau \\in \\{t-1, t \\} \\nonumber \\\\\n\t\\intertext{With regard to the absolute value function, two cases have to be considered:}\n\t\t|b_i - \\lambda_{i,\\tau}^*| &= \\left\\{\n\t\t\\begin{array}{ll}\n\t\t\tb_i - \\lambda_{i, \\tau}^*, &\\text{if} \\; b_i - \\lambda_{i, \\tau}^* \\geq 0 \\\\\n\t\t\t-(b_i - \\lambda_{i, \\tau}^*), &\\text{if} \\; b_i - \\lambda_{i, \\tau}^* < 0\n\t\t\\end{array} \n\t\\right. \\nonumber \\\\\n\t\\intertext{Consider first case: $b_i - \\lambda_{i, \\tau}^* \\geq 0$. In this case equation \\ref{eq:appen_penalty_term_1} can be written as follows:}\n\t\\rho_{i}(\\lambda_{i,t}^*) - \\rho_{i}(\\lambda_{i,t-1}^*) &= (b_i - \\lambda_{i,t}^*)^\\phi - (b_i - \\lambda_{i,t-1}^*)^\\phi \\nonumber\n\t\\intertext{Each of the two binomials on the right hand side can be rewritten as bivariate polynomials by application of the binomial expansion:}\n\t(b_i - \\lambda_{i,\\tau}^*)^\\phi &= \\sum^\\phi_{k=0}\\binom{\\phi}{k} b_i^{\\phi-k} (-\\lambda_{i,\\tau})^k, \\; \\text{for} \\; \\tau \\in \\{t-1, t\\} \\nonumber\n\\end{align}\nIt is straightforward to see that in the second case ($ b_i - \\lambda_{i, \\tau}^* < 0$) the result in analogous with opposite sign.\\\\\nThus, changes in the penalty term can be expressed as the differencee between two polynomials of $\\lambda_{i,t-1}$ and $\\lambda_{i,t}$, respectively. The degree of the resulting polynomial is equal to the penalty exponent $\\phi$.\\\\\nIn the simulation study, it is assumed that $\\phi = 2$. The changes in the penalty function in this particular case, therefore, result as follows:\n\\begin{align}\n\t\\rho_{i}(\\lambda_{i,t}^*) - \\rho_{i}(\\lambda_{i,t-1}^*) &= (b_i - \\lambda_{i,t})^2 - (b_i - \\lambda_{i,t-1})^2 \\nonumber \\\\\n\t{} &= \\lambda_{i,t-1}^{*2} + \\lambda_{i,t}^{*2} + 2b_i(\\lambda_{i,t-1}^* + \\lambda_{i,t}^*) \\tag{\\ref{eq:changes_in_penalty}}\n\\end{align}\n\n\\end{document}", "meta": {"hexsha": "245bb0cac0a56def588e35c6317a931a9b5de302", "size": 3208, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "latex_files/Appendix/derive_changes_penalty_term.tex", "max_stars_repo_name": "DaLueke/estimating_skill_prices", "max_stars_repo_head_hexsha": "bc895c8b0b0439f86c1f2dd53b34108f1eaf69a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "latex_files/Appendix/derive_changes_penalty_term.tex", "max_issues_repo_name": "DaLueke/estimating_skill_prices", "max_issues_repo_head_hexsha": "bc895c8b0b0439f86c1f2dd53b34108f1eaf69a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "latex_files/Appendix/derive_changes_penalty_term.tex", "max_forks_repo_name": "DaLueke/estimating_skill_prices", "max_forks_repo_head_hexsha": "bc895c8b0b0439f86c1f2dd53b34108f1eaf69a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.4210526316, "max_line_length": 344, "alphanum_fraction": 0.6571072319, "num_tokens": 1144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.675392005681586}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{float}\n\\usepackage{tikz}\n\\usetikzlibrary{arrows.meta,positioning}\n\n\\title{Mathematical Modelling in \\LaTeX}\n\\author{Gurobi Optimization}\n\n\\begin{document}\n\n\\maketitle\n\nThis document provides an example of how \\LaTeX\\ can be used to write clean mathematical models. As an example, we consider the famous maximum flow / minimum cut problems. The problems consider a directed graph consisting of a set of nodes and a set of labeled arcs. The arc labels are non-negative values representing a notion of capacity for the arc. In the node set, there exists a source node $s$ and a terminal node $t$. The amount of flow into one of the intermediary nodes must equal the amount of flow out of the node, i.e., flow is conserved. \n\nThe maximum flow question asks: what is the maximum flow that can be transferred from the source to the sink. The minimum cut question asks: which is the subset of arcs, that once removed would disconnect the source node from the terminal node, which has the minimum sum of capacities. For example, removing arcs $(v_1, v_3)$ and $(v_2, v_4)$ from the network in \\ref{fig:my_label} would mean there is no longer a path from $s$ to $t$ and the sum of the capacities of these arcs is $12 + 11 = 23$. It is reasonably straight forward to find a better cut, i.e., a subset of nodes with sum of capacities less than 23.\n\n\\input{picture}\n\nA complete model is provided for the maximum flow problem, whereas the minimum cut problem is left as a challenge to the reader.\n\n\\section*{Notation}\n\n\\subsection*{Sets}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{p{1cm} p{1.5cm} p{9cm}}\n\\hline\n\\textbf{Index} & \\textbf{Set} & \\textbf{Description}\\\\\n\\hline\n$i$ & $V$ & Set of all nodes ($s$ source and $t$ terminal)\\\\\n$(i, j)$ & $A$ & Set of all arcs\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\subsection*{Parameters}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{p{2cm} p{9cm}}\n\\hline\n\\textbf{Parameter} &  \\textbf{Description}\\\\\n\\hline\n$c_{i,j}$ & Capacity of arc $(i,j) \\in A$\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\section*{Maximum Flow}\n\n\n\\subsection*{Variables}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{p{2cm} p{1.5cm} p{9cm}}\n\\hline\n\\textbf{Variable} & \\textbf{Type}& \\textbf{Description}\\\\\n\\hline\n$f_{i, j}$ & Cont & flow from $i$ to $j$ in arc $(i,j) \\in A$\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\subsection*{Model}\n\n\\begin{subequations}\n\\begin{alignat}3\n\\text{maximise} \\ & \\sum_{j \\in V: (s,j) \\in A} f_{s, j} \\label{model-obj}\\\\\ns.t. \\ & f_{i, j} \\leq c_{i,j} \\quad && \\forall (i, j) \\in A \\label{m1-c1}\\\\\n& \\sum_{i \\in V: (i,j) \\in A} f_{i, j} - \\sum_{k \\in V: (j, k) \\in A} f_{j,k} = 0 \\quad  && \\forall j \\in V \\setminus \\{s, t\\} \\label{m2-c2}\n\\end{alignat}\n\\end{subequations}\n\nThe objective \\eqref{model-obj} is to maximise the sum of flow leaving the source node $s$. Constraints \\eqref{m1-c1} ensure that the flow in each arc does not exceed the capacity of that arc. Constraints \\eqref{m2-c2} are continuity constraints, which ensure that the flow into each of the nodes, excluding the source and sink, is equal to the flow out of that node.\n\n\\newpage\n\n\\section*{Minimum Cut}\n\nThis section is left for the reader to complete\n\n\n\\subsection*{Variables}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{p{2cm} p{1.5cm} p{9cm}}\n\\hline\n\\textbf{Variable} & \\textbf{Type}& \\textbf{Description}\\\\\n\\hline\n$r_{i, j}$ &  & 1 if arc $(i,j) \\in A$ is removed\\\\\n$z_{i, j}$ &  & 1 if node $i \\in V \\setminus \\{s, t\\}$ connected to $s$, 0 otherwise\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\subsection*{Model}\n\n\\begin{subequations}\n\\begin{alignat}3\n\\text{to do} \n\\end{alignat}\n\\end{subequations}\n\n\n\\end{document}\n", "meta": {"hexsha": "905761157c4c11e99edea1adbd5017d6fd35a7a4", "size": 3691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week1/todo.tex", "max_stars_repo_name": "stevedwards/gurobi_course", "max_stars_repo_head_hexsha": "badb716d5dac86a77712908637cbc08722d0415d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week1/todo.tex", "max_issues_repo_name": "stevedwards/gurobi_course", "max_issues_repo_head_hexsha": "badb716d5dac86a77712908637cbc08722d0415d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week1/todo.tex", "max_forks_repo_name": "stevedwards/gurobi_course", "max_forks_repo_head_hexsha": "badb716d5dac86a77712908637cbc08722d0415d", "max_forks_repo_licenses": ["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.2522522523, "max_line_length": 614, "alphanum_fraction": 0.7065835817, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.675392001866858}}
{"text": "\\chapter{Overview}\n\\label{chap:intro}\n\nMARSS stands for Multivariate Auto-Regressive(1) State-Space. The MARSS package is an \\R package for estimating the parameters of linear MARSS models with Gaussian errors\\index{MARSS model}.  This class of model is extremely important in the study of linear stochastic dynamical systems, and these models are important in many different fields, including economics, engineering, genetics, physics and ecology (Appendix \\ref{chap:SSreferences}).  The model class has different names in different fields, for example in some fields they are termed dynamic linear models (DLMs) or vector autoregressive (VAR) state-space models.  The MARSS package allows you to easily fit time-varying constrained and unconstrained MARSS models with or without covariates to multivariate time-series data via maximum-likelihood using primarily an EM algorithm\\footnote{Fitting via the BFGS algorithm is also provided using \\R's optim function, but this is not the focus of the package.}.\n\nA full MARSS model, with Gaussian errors, takes the form:\n\\begin{subequations}\\label{eqn:marss}\n\\begin{gather}\n\\xx_t = \\BB_t\\xx_{t-1} + \\uu_t + \\CC_t\\cc_t + \\GG_t\\ww_t, \\text{ where } \\ww_t \\sim \\MVN(0,\\QQ_t) \\label{eqn:marssx}\\\\\n\\yy_t = \\ZZ_t\\xx_t + \\aa_t + \\DD_t\\dd_t + \\HH_t\\vv_t, \\text{ where } \\vv_t \\sim \\MVN(0,\\RR_t) \\label{eqn:marssy}\\\\\n\\xx_1 \\sim \\MVN(\\pipi,\\LAM) \\text{ or } \\xx_0 \\sim \\MVN(\\pipi,\\LAM)\\label{eqn:marssx1}\n\\end{gather}\n\\end{subequations}\nThe $\\xx$ equation is termed the state process and the $\\yy$ equation is termed the observation process.  Data enter the model as the $\\yy$; that is the $\\yy$ is treated as the data although there may be missing data.  The $\\cc_t$ and $\\dd_t$ are inputs (aka, exogenous variables, covariates or indicator variables).  The $\\GG_t$ and $\\HH_t$ are also typically inputs (fixed values with no missing values).\n\nThe bolded terms are matrices with the following definitions: \n \\begin{description}\n\t\\item[$\\xx$] is a $m \\times T$ matrix of states.  Each $\\xx_t$ is a realization of the random variable $\\XX_t$ at time $t$.\n\t\\item[$\\ww$] is a $m \\times T$ matrix of the process errors.  The process errors at time $t$ are multivariate normal with mean 0 and covariance matrix $\\QQ_t$.\n\t\\item[$\\yy$] is a $n \\times T$ matrix of the observations.   Some observations may be missing.\n\t\\item[$\\vv$] is a $n \\times T$ column vector of the non-process errors.  The observation erros at time $t$ are multivariate normal with mean 0 and covariance matrix $\\RR_t$.\n\t\\item[$\\BB_t$ and $\\ZZ_t$] are parameters and are $m \\times m$ and $n \\times m$ matrices.\n\t\\item[$\\uu_t$ and $\\aa_t$] are parameters and are $m \\times 1$ and $n \\times 1$ column vectors.\n\t\\item[$\\QQ_t$ and $\\RR_t$] are parameters and are $g \\times g$ (typically $m \\times m$) and $h \\times h$ (typically $n \\times n$) variance-covariance matrices.\n\t\\item[$\\pipi$] is either a parameter or a fixed prior. It is a $m \\times 1$ matrix\\index{prior}.\n\t\\item[$\\LAM$] is either a parameter or a fixed prior. It is a $m \\times m$ variance-covariance matrix.\n\t\\item[$\\CC_t$ and $\\DD_t$] are parameters and are $m \\times p$ and $n \\times q$ matrices.\n\t\\item[$\\cc$ and $\\dd$] are inputs (no missing values) and are $p \\times T$ and $q \\times T$ matrices.\n  \\item[$\\GG_t$ and $\\HH_t$] are inputs (no missing values) and are $m \\times g$ and $n \\times h$ matrices.\n\\end{description}\n\nIn some fields, the $\\uu$ and $\\aa$ terms are routinely set to 0 or the model is written in such a way that they are incorporated into $\\BB$ or $\\ZZ$.  However, in other fields, the $\\uu$ and $\\aa$ terms are the main objects of interest, and the model is written to explicitly show them.  We include them throughout our discussion, but they can be set to zero if desired. \n\nAR(p) models can be written in the above form by properly defining the $\\xx$ vector and setting some of the $\\RR$ variances to zero; see Chapter \\ref{chap:ARMA}. Although the model appears to only include i.i.d. errors ($\\vv_t$ and $\\ww_t$), in practice, AR(p) errors can be included by moving the error terms into the state model.  Similarly, the model appears to have independent process ($\\vv_t$) and observation ($\\ww_t$) errors, however, in practice, these can be modeled as identical or correlated by using one of the state processes to model the errors with the $\\BB$ matrix set appropriately for AR or white noise---although one may have to fix many of the parameters associated with the errors to have an identifiable model.  Study the application chapters and textbooks on MARSS models (Appendix \\ref{chap:SSreferences}) for examples of how a wide variety of autoregressive models can be written in MARSS form.  \n\n\\section{What does the MARSS package do?}\nWritten in an unconstrained form\\footnote{meaning all the elements in a parameter matrices are allowed to be different and none constrained to be equal or related.}, a MARSS model can be written out as follows. Two state processes ($\\xx$) and three observation processes ($\\yy$) are used here as an example.\n\\begin{gather*}\n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_t\n= \\begin{bmatrix}b_{11}&b_{12}\\\\b_{21}&b_{22}\\end{bmatrix}\n\\begin{bmatrix}x_1\\\\x_2\\end{bmatrix}_{t-1}\n+ \\begin{bmatrix}w_1\\\\ w_2\\end{bmatrix}_t,\\quad \n\\begin{bmatrix}w_1\\\\ w_2\\end{bmatrix}_t \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}u_1\\\\u_2\\end{bmatrix},\\begin{bmatrix}q_{11}&q_{12}\\\\q_{21}&q_{22}\\end{bmatrix} \\end{pmatrix}  \\\\\n\\\\\n\\begin{bmatrix}y_1\\\\ y_2\\\\ y_3\\end{bmatrix}_t\n= \\begin{bmatrix}z_{11}&z_{12}\\\\ z_{21}&z_{22}\\\\ z_{31}&z_{32}\\end{bmatrix}\n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_t\n+ \\begin{bmatrix}v_1\\\\ v_2\\\\ v_3\\end{bmatrix}_t,\n\\begin{bmatrix}v_1\\\\ v_2\\\\ v_3\\end{bmatrix}_t \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}a_1\\\\ a_2\\\\ a_3\\end{bmatrix},\n \\begin{bmatrix}r_{11}&r_{12}&r_{13}\\\\r_{21}&r_{22}&r_{23}\\\\r_{31}&r_{32}&r_{33}\\end{bmatrix} \\end{pmatrix}  \\\\\n\\\\\n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_0 \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}\\pi_1\\\\ \\pi_2\\end{bmatrix},\\begin{bmatrix}\\nu_{11}&\\nu_{12}\\\\ \\nu_{21}&\\nu_{22}\\end{bmatrix} \\end{pmatrix} \\quad \nor\\quad \n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_1 \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}\\pi_1\\\\ \\pi_2\\end{bmatrix},\\begin{bmatrix}\\nu_{11}&\\nu_{12}\\\\ \\nu_{21}&\\nu_{22}\\end{bmatrix} \\end{pmatrix} \n\\end{gather*}\n\nHowever not all parameter elements can be estimated simultaneously. Constraints are required in order to specify a model with a unique solution. The MARSS package allows you to specify constraints by fixing elements in a parameter matrix or specifying that some elements are estimated---and have a linear relationship to other elements. Here is an example of a MARSS model with fixed and estimated parameter elements:\n\\begin{gather*}\n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_t\n= \\begin{bmatrix}a&0\\\\0&a\\end{bmatrix}\n\\begin{bmatrix}x_1\\\\x_2\\end{bmatrix}_{t-1}\n+ \\begin{bmatrix}w_1\\\\ w_2\\end{bmatrix}_t,\\quad \n\\begin{bmatrix}w_1\\\\ w_2\\end{bmatrix}_t \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}0.1\\\\u\\end{bmatrix},\\begin{bmatrix}q_{11}&q_{12}\\\\q_{12}&q_{22}\\end{bmatrix} \\end{pmatrix}  \\\\\n\\\\\n\\begin{bmatrix}y_1\\\\ y_2\\\\ y_3\\end{bmatrix}_t\n= \\begin{bmatrix}d&d\\\\ c& c\\\\ 1+2d+3c&2+3d\\end{bmatrix}\n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_t\n+ \\begin{bmatrix}v_1\\\\ v_2\\\\ v_3\\end{bmatrix}_t,\\quad\n\\begin{bmatrix}v_1\\\\ v_2\\\\ v_3\\end{bmatrix}_t \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}a_1\\\\ a_2\\\\ 0\\end{bmatrix},\n \\begin{bmatrix}r&0&0\\\\0&r&0\\\\0&0&r\\end{bmatrix} \\end{pmatrix}  \\\\\n\\\\\n\\begin{bmatrix}x_1\\\\ x_2\\end{bmatrix}_0 \\sim \\MVN\\begin{pmatrix}\\begin{bmatrix}\\pi\\\\ \\pi\\end{bmatrix},\\begin{bmatrix}1&0\\\\ 0&1\\end{bmatrix} \\end{pmatrix}\n\\end{gather*}\nNotice that some elements are fixed (in this case to 0, but could be any fixed number), some elements are shared (have the same value), and some elements are linear combinations of other estimated values ($c$, $1+2d+3c$ and $2+3d$ are linear combinations of $c$ and $d$).\n\nThe MARSS package fits models via maximum likelihood. The MARSS package is unusual among packages for fitting MARSS models in that fitting is performed via a constrained EM algorithm \\citep{Holmes2010} based on a vectorized form of Equation \\ref{eqn:marss} (See Chapter \\ref{chap:algorithms} for the vectorized form used in the algorithm).  Although fitting via the BFGS algorithm is also provided using \\verb@method=\"BFGS\"@ and the optim functionin R, the examples in this guide use the EM algorithm primarily because it gives robust estimation for datasets replete with missing values and for high-dimensional models with various constraints. However, there are many models/datasets where BFGS is faster and we typically try both for problems.  The EM algorithm is also often used to provide initial conditions for the BFGS algorithm (or an MCMC routine) in order to improve the performance of those algorithms.  In addition to the main model fitting function, the MARSS package  supplies functions for bootstrap and approximate confidence intervals, parametric and non-parametric bootstrapping, model selection (AIC and bootstrap AIC), simulation, and bootstrap bias correction.\n\n\\section{What does MARSS output and how do I get the output?}\\index{MARSS model}\nMARSS models are used in many different ways and different users will want different types of output.  Some users will want the parameter estimates while others want the smoothed states and others want to use MARSS to interpolate missing values and want the expected values of missing data.  \n\nThe best way to find out how to get output is to type \\verb@?print.MARSS@ at the command line after installing MARSS.  The print help page discusses how to get parameter estimates in different forms, the smoothed and filtered states, all the Kalman filter and smoother output, all the expectations of y (missing data), confidence intervals and bias estimates for the parameters, \nand standard errors of the states.  If you are looking only for Kalman filter and smoother output, see the relevant section in Chapter \\ref{chap:algorithms} and see the help page for the \\verb@MARSSkf()@ function (type \\verb@?MARSSkf@at the \\R command line).\n\nYou might also want to look at the \\verb@tidy@ and \\verb@glance@ functions which will summarize commonly needed output from a MARSS model fit.  These functions work as they do in the \\verb@broom@ R package.\n\n\\section{How to get started (quickly)}\n\nIf you already work with models in the form of Equation \\ref{eqn:marss}, you can immediately fit your model with the MARSS package.  Install the MARSS package and then type \\texttt{library(MARSS)} at the command line to load the package.  Look at the \\href{https://CRAN.R-project.org/package=MARSS/vignettes/Quick_Start.pdf}{Quick Start Guide} and then skim through Chapter \\ref{chap:Examples}.  Appendix \\ref{chap:modelspec} also has many examples of how to specify different forms for your parameter matrices. \n\n\\section{Getting your data in right format}\nYour data need to be a matrix, not dataframe, with time across the columns ($n \\times T$ matrix). Note a univariate or multivariate ts (time-series) object can also be used and this will be converted to a $n \\times T$ matrix. The MARSS functions assume discrete time steps and you will need a column for each time step.  Replace any missing time steps with NA.  Write your model down on paper and identify which parameters correspond to which parameter matrices in Equation \\ref{eqn:marss}.  Call the \\texttt{MARSS()} function (Chapter \\ref{chap:MARSS}) using your data and using the \\texttt{model} argument to specify the structure of each parameter. \n\n\\subsection{Getting a ts object into the right form}\nA R ts object (time series object) stores information about the time steps of the data and often seasonal information (the quarter or month).  You can pass in your data as a ts object and MARSS will convert this to matrix form.  However if you have your data in ts form, then you may be using year and season (quarter, month) as covariates to estimate trend and seasonality.  Here is how to get your ts into the form that MARSS wants with a matrix of covariates for season.\n\n\\emph{Univariate example}.  This converts a univariate ts object with year and quarter into a matrix with a row for the response (here called Temp), year, and quarter.  \n\\begin{Schunk}\n\\begin{Sinput}\nz = ts(rnorm(10), frequency = 4, start = c(1959, 2))\ndat = data.frame(Yr = floor(time(z) + .Machine$double.eps), \n      Qtr = cycle(z), Temp=z)\ndat = t(dat)\n\\end{Sinput}\n\\end{Schunk}\nWhen you call MARSS, \\verb@dat[\"Temp\",]@ is the data. \\verb@dat[c(\"Yr\",\"Qtr\"),]@ are your covariates.  \n\n\\emph{Multivariate example}.  In this example, we have two temperature readings and a salinity reading. The data are monthly.\n\n\\begin{Schunk}\n\\begin{Sinput}\nz <- ts(matrix(rnorm(300), 100, 3), start = c(1961, 1),\n     frequency = 12, names=c(\"Temp1\",\"Temp2\",\"Sal\"))\ndat = data.frame(Yr = floor(time(z) + .Machine$double.eps), \n     Month = cycle(z), z)\n\\end{Sinput}\n\\end{Schunk}\nWhen you call MARSS, \\verb@dat[c(\"Temp1\",\"Temp2\"),]@ are the data and your covariates are \\verb@dat[c(\"Yr\",\"Month\",\"Sal\"),]@.  \n\nSee the chapters that discuss seasonality for examples of how to model seasonality.  The brute force method of treating month or quarter as a factor requires estimation of more parameters than necessary in many cases.\n\n\\section{Important notes about the algorithms}\n \\textit{Specification of a properly constrained model with a unique solution is the responsibility of the user because MARSS has no way to tell if you have specified an insufficiently constrained model---with correspondingly an infinite number of solutions.} \n \nSpecifying a properly constrained model with a unique solution is imperative.  How do you know if the model is properly constrained?  If you are using a MARSS model form that is widely used, then you can probably assume that it is properly constrained. If you go to papers where someone developed the model or method, the issue of constraints necessary to ensure ``identifiability'' will likely be addressed if it is an issue.  Are you fitting novel MARSS models? Then you will need to do some study on identifiability in this class of models using textbooks (Appendix \\ref{chap:SSreferences}).  Often textbooks do not address identifiability explicitly.  Rather it is addressed implicitly by only showing a model constructed in such a way that it is identifiable.  In our work, if we suspect identification problems, we will often first do a Bayesian analysis with flat priors and look for oddities in the posteriors, such as ridges, plateaus or bimodality.\n \nAll the EM code in the MARSS package is currently in native \\R.  Thus the model fitting is slow.  The classic Kalman filter/smoother algorithm, as shown in \\citet[p. 331-335]{ShumwayStoffer2006}, is based on the original smoother presented in \\citet{Rauch1963}. This Kalman filter is provided in function \\verb@MARSSkfss@, but the default Kalman filter and smoother used in the MARSS package is based on the algorithm in \\citet{KohnAnsley1989} and papers by Koopman et al. This Kalman filter and smoother is provided in the KFAS package (Helske 2012).  Table 2 in \\citet{Koopman1993} indicates that the classic algorithm is 40-100 times slower than the algorithm given in \\citet{KohnAnsley1989}, \\citet{Koopman1993}, and \\citet{Koopmanetal1998}. The MARSS package function \\verb@MARSSkfas@ provides a translator between the model objects in MARSS and those in KFAS so that the KFAS functions can be used.  \\verb@MARSSkfas@ also includes a lag-one covariance smoother algorithm as this is not output by the KFAS functions, and it provides proper formulation of the priors so that one can use the KFAS functions when the prior on the states is set at $t=0$ instead of $t=1$. Simply off-setting your data to start at t=2 and sending that value to $t_{init}=1$ in the KFAS Kalman filter would not be mathematically correct!\n\nEM algorithms will quickly get in the vicinity of the maximum likelihood, but the final approach to the maximum is generally slow relative to quasi-Newton methods.  On the flip side, EM algorithms are quite robust to initial conditions choices and can be extremely fast at getting close to the MLE values for high-dimensional models.  The MARSS package also allows one to use the BFGS method to fit MARSS models, thus one can use an EM algorithm to ``get close'' and then the BFGS algorithm to polish off the estimate. Restricted maximum-likelihood algorithms\\index{estimation!REML} are also available for AR(1) state-space models, both univariate \\citep{Staplesetal2004} and multivariate \\citep{HinrichsenHolmes2009}.  REML can give parameter estimates with lower variance than plain maximum-likelihood algorithms.  However, the algorithms for REML when there are missing values are not currently available (although that will probably change in the near future).  Another maximum-likelihood method is data-cloning which adapts MCMC algorithms used in Bayesian analysis for maximum-likelihood estimation \\citep{Leleetal2007}.  \n\nMissing values\\index{missing values} are seamlessly accommodated with the MARSS package.  Simply specify missing data with NAs.  The likelihood computations are exact and will deal appropriately with missing values.  However, no innovations\\footnote{referring to the non-parametric bootstrap developed by Stoffer and Wall (1991).} bootstrapping can be done if there are missing values.  Instead parametric bootstrapping must be used.\n\nYou should be aware that maximum-likelihood estimates of variance in MARSS models are fundamentally biased, regardless of the algorithm used.  This bias is more severe when one or the other of $\\RR$ or $\\QQ$ is very small, and the bias does not go to zero as sample size goes to infinity.  The bias arises because variance is constrained to be positive.  Thus if $\\RR$ or $\\QQ$ is essentially zero, the mean estimate will not be zero and thus the estimate  will be biased high while the corresponding bias of the other variance will be biased low.  You can generate unbiased variance estimates using a bootstrap estimate of the bias.  The function \\texttt{MARSSparamCIs()}\\index{functions!MARSSparamCIs} will do this.  However be aware that adding an {\\it estimated} bias to a parameter estimate will lead to an increase in the variance of your parameter estimate.  The amount of variance added will depend on sample size.\n\nYou should also be aware that mis-specification of the prior on the initial states ($\\pipi$ and $\\LAM$) can have catastrophic effects on your parameter estimates if your prior conflicts with the distribution of the initial states implied by the MARSS model\\index{prior!troubleshooting}.  These effects can be very difficult to detect because the model will appear to be well-fitted.  Unless you have a good idea of what the parameters should be, you might not realize that your prior conflicts.  \n\nThe most common problems we have found with priors on $\\xx_0$ are the following.  Problem 1) The correlation structure in $\\LAM$ (whether the prior is diffuse or not) does not match the correlation structure in $\\xx_0$ implied by your model.  For example, you specify a diagonal $\\LAM$ (independent states), but the implied distribution has correlations. Problem 2) The correlation structure in $\\LAM$ does not match the structure in $\\xx_0$ implied by constraints you placed on $\\pipi$.  For example, you specify that all values in $\\pipi$ are shared, yet you specify that $\\LAM$ is diagonal (independent).  \n\nUnfortunately, using a diffuse prior does not help with these two problems because  the diffuse prior still has a correlation structure and can still conflict with the implied correlation in $\\xx_0$.  One way to get around these problems is to set $\\LAM$=0 (a $m \\times m$ matrix of zeros) and estimate $\\pipi \\equiv \\xx_0$ only.  Now $\\pipi$ is a fixed but unknown (estimated) parameter, not the mean of a distribution.  In this case, $\\LAM$ does not exist in your model and there is no conflict with the model.  \nBe aware however that estimating $\\pipi$ as a parameter is not always robust. If you specify that $\\LAM$=0 and specify that $\\pipi$ corresponds to $\\xx_0$, but your model ``explodes'' when run backwards in time, you cannot estimate $\\pipi$ because you cannot get a good estimate of $\\xx_0$.  Sometimes this can be avoided by specifying that $\\pipi$ corresponds to $\\xx_1$ so that it can be constrained by the data $\\yy_1$. \n\nIn summary, if the implied correlation structure of your initial states is independent (diagonal variance-covariance matrix), you should generally be ok with a diagonal and high variance prior or with treating the initial states as parameters (with $\\LAM=0$).  But if your initial states have an implied correlation structure that is not independent, then proceed with caution. `With caution' means that you should assume you have problems and test how your model fits with simulated data.\n\nThere is a large class of models in the statistical finance literature that have the form\n\\begin{equation*}\n\\begin{gathered}\n\\xx_{t+1} = \\BB\\xx_t + \\GAM\\et_t\\\\\n\\yy_t = \\ZZ\\xx_t  + \\et_t\\\\\n\\end{gathered}\n\\end{equation*}\nFor example, ARMA(p,q) models can be written in this form.  The MARSS model framework in this package will not allow you to write models in that form.  You can put the $\\et_t$ into the $\\xx_t$ vector and set $\\RR=0$ to make models of this form using the MARSS form, but the EM algorithm in the MARSS package won't let you estimate parameters because the parameters will drop out of the full likelihood being maximized in the algorithm.  You can try using BFGS by passing in the \\texttt{method} argument to the \\verb@MARSS()@ call.\n\n\\section{Troubleshooting}\n\\index{troubleshooting}Numerical errors due to ill-conditioned matrices are not uncommon when fitting MARSS models\\index{errors!ill-conditioned}\\index{troubleshooting!ill-conditioning}\\index{likelihood!troubleshooting}. The Kalman and EM algorithms need inverses of matrices. If those matrices become ill-conditioned, for example all elements are close to the same value, then the algorithm becomes unstable.  Warning messages will be printed if the algorithms are becoming unstable\\index{troubleshooting!numerical instability} and you can set \\verb@control$trace=1@, to see details of where the algorithm is becoming unstable.  Whenever possible, you should avoid using shared $\\pipi$ values in your model\\footnote{An example of a $\\pipi$ with shared values is $\\pipi=\\bigl[\\begin{smallmatrix} a\\\\a\\\\a \\end{smallmatrix} \\bigr]$.}.  The way our algorithm deals with $\\LAM$ tends to make this case unstable, especially if $\\RR$ is not diagonal.  In general, estimation of a non-diagonal $\\RR$ is more difficult, more prone to ill-conditioning, and more data-hungry.\n\nYou may also see non-convergence warnings, especially if your MLE model turns out to be degenerate\\index{errors!degenerate}\\index{troubleshooting!degenerate}\\index{troubleshooting!non-convergence}.  This means that one of the elements on the diagonal of your $\\QQ$ or $\\RR$ matrix are going to zero (are degenerate).  It will take the EM algorithm forever to get to zero.  BFGS will have the same problem, although it will often get a bit closer to the degenerate solution.  If you are using \\verb@method=\"kem\"@, MARSS will warn you if it looks like the solution is degenerate. If you use \\verb@control=list(allow.degen=TRUE)@, the EM algorithm will attempt to set the degenerate variances to zero (instead of trying to get to zero using an infinite number of iterations).  However, if one of the variances is going to zero, first think about why this is happening.  This is typically caused by one of three problems:  1) you made a mistake in inputting your data, e.g. used -99 as the missing value in your data but did not replace these with NAs before passing to MARSS, 2) your data are not sufficient to estimate multiple variances or 3) your data are inconsistent with the model you are trying fit.\n\nThe algorithms in the MARSS package are designed for cases where the $\\QQ$ and $\\RR$ diagonals are all non-minuscule.  For example, the EM update equation for $\\uu$ will grind to a halt (not update $\\uu$) if $\\QQ$ is tiny (like 1E-7).  Conversely, the BFGS equations are likely to miss the maximum-likelihood when $\\RR$ is tiny because then the likelihood surface becomes hyper-sensitive to $\\pipi$.   The solution is to use the degenerate likelihood function for the likelihood calculation and the EM update equations.  MARSS will implement this automatically when $\\QQ$ or $\\RR$ diagonal elements are set to zero and will try setting $\\QQ$ and $\\RR$ terms to zero automatically if \\verb@control$allow.degen=TRUE@.  \n\nOne odd case can occur when $\\RR$ goes to zero (a matrix of zeros), but you are estimating $\\pipi$.  If \\verb@model$tinitx=1@, then $\\pipi=\\xx_1^0$ and $\\yy_1-\\ZZ\\xx_1^0$ can go to 0 as well as $\\var(\\yy_1-\\ZZ\\xx_1^0)$ by driving $\\RR$  to zero. But as this happens, the log-likelihood associated with $\\yy_1$ will go (correctly) to infinity and thus the log-likelihood goes to infinity.  But if you set $\\RR=0$, the log-likelihood will be finite.  The reason is that $\\RR \\approx 0$ and $\\RR=0$ specify different likelihoods associated with $\\yy_1-\\ZZ\\xx_1^0$.  With $\\RR=0$, $\\yy_1-\\ZZ\\xx_1^0$ does not have a distribution; it is just a fixed value.  So there is no likelihood to go to infinity.  If some elements of the diagonal of $\\RR$ are going to zero, you should be suspect of the parameter estimates.  Sometimes the structure of your data, e.g. one data value followed by a long string of missing values, is causing an odd spike in the likelihood at  $\\RR \\approx 0$.  Try manually setting $\\RR$ equal to zero to get the correct log-likelihood\\footnote{The likelihood returned when $\\RR \\approx 0$ is not incorrect.  It is just not the likelihood that you probably want.  You want the likelihood where the $\\RR$ term is dropped because it is zero.}.  \n\n\\section{Other related packages}\nPackages that will do Kalman filtering and smoothing are many, but packages that estimate the parameters in a MARSS model, especially constrained MARSS models, are much less common.  The following are those with which we are familiar, however there are certainly more packages for estimating MARSS models in engineering and economics of which we are unfamiliar.  The MARSS package is unusual in that it uses an EM algorithm for maximizing the likelihood as opposed to a Newton-esque method (e.g. BFGS). The package is also unusual in that it allows you to specify the initial conditions at $t=0$ or $t=1$, allows degenerate models (with some of the diagonal elements of $\\RR$ or $\\QQ$ equal to zero). Lastly, model specification in the MARSS package  has a one-to-one relationship between the model list in MARSS and the model as you would write it on paper as a matrix equation.  This makes the learning curve a bit less steep.  However, the MARSS package has not been optimized for speed and probably will be really slow if you have time-series data with a lot of time points.\n\n\\begin{description}\n\t\\item[atsar] \\href{https://asts-es.github.io/atsar/}{atsar} is an \\R package we wrote for fitting MARSS models using STAN.  It allows fast and flexible fitting of MARSS models in a Bayesian framework.  Our book from our time-series class has example applications \\href{https://atsa-es.github.io/atsa-labs/}{Applied Time-Series Analysis for Fisheries and Environmental Sciences}.\n  \\item[stats] The \\verb@stats@ package (part of base R) has functions for fitting univariate structural time series models (MARSS models with a univariate y).  Read the help file at \\verb@?StructTS@. The Kalman filter and smoother functions are described here: \\verb@?KalmanLike@.\n\t\\item[DLM] \\href{https://cran.r-project.org/package=dlm}{DLM} is an \\R package for fitting MARSS models.  Our impression is that it is mainly Bayesian focused but it does allow MLE estimation via the \\verb@optim()@ function.  It has a book, Dynamic Linear Models with \\R  by Petris et al., which has many examples of how to write MARSS models for different applications.\n\t\\item[sspir] \\href{https://cran.r-project.org/package=sspir}{sspir} an \\R package for fitting ARSS (univariate) models with Gaussian, Poisson and binomial error distributions.  \n\t\\item[dse] \\href{https://cran.r-project.org/package=dse}{dse} (Dynamic Systems Estimation) is an \\R package for multivariate Gaussian state-space models with a focus on ARMA models.\n\t\\item[SsfPack] \\href{http://www.ssfpack.com/}{SsfPack} is a package for Ox/Splus that fits constrained multivariate Gaussian state-space models using mainly (it seems) the BFGS algorithm but the newer versions support other types of maximization.  SsfPack is very flexible and written in C to be fast.  It has been used extensively on statistical finance problems and is optimized for dealing with large (financial) data sets.  It is used and documented in Time Series Analysis by State Space Methods by Durbin and Koopman, An Introduction to State Space Time Series Analysis by Commandeur and Koopman, and Statistical Algorithms for Models in State Space Form: SsfPack 3.0, by Koopman, Shephard, and Doornik.\n\t\\item[Brodgar] The Brodgar software was developed by Alain Zuur to do (among many other things) dynamic factor analysis, which involves a special type of MARSS model.  The methods and many example analyses are given in Analyzing Ecological Data by Zuur, Ieno and Smith.  This is the one package that we are aware of that also uses an EM algorithm for parameter estimation.\n\t\\item[eViews] eViews is a commercial economics software that will estimate at least some types of MARSS models.\n\t\\item[KFAS] The \\href{https://cran.r-project.org/package=KFAS}{KFAS} \\R package provides a fast Kalman filter and smoother.  Examples in the package show how to estimate MARSS models using the KFAS functions and \\R's \\verb@optim()@ function.   The MARSS package uses the filter and smoother functions from the KFAS package.\n\t\t\\item[S+FinMetrics] \\href{http://faculty.washington.edu/ezivot/MFTS2ndEditionFinMetrics.htm}{S+FinMetrics} is a S-plus module for fitting MAR models, which are called vector autoregressive (VAR) models in the economics and finance literature.  It has some support for state-space VAR models, though we haven't used it so are not sure which parameters it allows you to estimate.  It was developed by Andrew Bruce, Doug Martin, Jiahui Wang, and Eric Zivot, and it has a book associated with it: Modeling Financial Time Series with S-plus by Eric Zivot and Jiahui Wang.\n\t\t\\item[kftrack] The \\href{https://github.com/positioning/kalmanfilter/wiki}{kftrack} \\R package provides a suite of functions specialized for fitting MARSS models to animal tracking data.\n\\end{description}", "meta": {"hexsha": "995b11c8dea4fc0aebd5550c34ed93de9d184080", "size": 30753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vignettes/tex/Introduction.tex", "max_stars_repo_name": "nwfsc-timeseries/MARSS", "max_stars_repo_head_hexsha": "f6f5252c23d4ac3fda77c8c9ad0fc446d4a553ac", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2018-03-07T11:58:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-18T22:19:40.000Z", "max_issues_repo_path": "vignettes/tex/Introduction.tex", "max_issues_repo_name": "nwfsc-timeseries/MARSS", "max_issues_repo_head_hexsha": "f6f5252c23d4ac3fda77c8c9ad0fc446d4a553ac", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 126, "max_issues_repo_issues_event_min_datetime": "2018-03-15T16:05:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T02:25:30.000Z", "max_forks_repo_path": "vignettes/tex/Introduction.tex", "max_forks_repo_name": "nwfsc-timeseries/MARSS", "max_forks_repo_head_hexsha": "f6f5252c23d4ac3fda77c8c9ad0fc446d4a553ac", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-04-14T06:01:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T07:48:53.000Z", "avg_line_length": 174.7329545455, "max_line_length": 1319, "alphanum_fraction": 0.7681527005, "num_tokens": 8141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.675338920152343}}
{"text": "\\section{Uncertainty principle}\nThe uncertainty principle for observables $A$ and $B$ are\n\\begin{align}\n    \\sigma_A \\sigma_B \\ge \\frac{1}{2}\n    |\\bra{\\psi} [A,B] \\ket{\\psi}|\n\\end{align}\nfor example,\n\\begin{align}\n    \\sigma_x \\sigma_p \\ge \\frac{\\hbar}{2}.\n\\end{align}\n\nDon't pretend you have to rush through the material and not get very basic\nthings like the uncertainty principle.\n\nHere's something I know you understand for fact.\n\n\\section{Time-energy uncertainty}\nEnergy is an operator in quantum mechanics.\nTime is not an operator in QM.\nIt is a parameter in the Schrodinger equation.\nNothing tells me the time operator.\nIt's special in QM.\n\nBut we shouldn't.\nTime and energy satisfy an uncertainty just like position and momentum.\nThe proof and interoperation is different,\nbut it's true.\n\nTake any observable $A$.\nCompute expectation value $\\bar{A}$.\nLet's see how the average changes over time.\n\\begin{align}\n    \\frac{d}{dt}\\bar{A} &= \\frac{d}{dt}\\bra{\\psi} A\\ket{\\psi}\\\\\n    &= \\underbrace{\\frac{d}{dt} \\bra{\\psi}}_{+\\frac{i}{\\hbar}\\bra{\\psi} H}\n    A \\ket{\\psi}\n    + \\bra{\\psi} A\n    \\underbrace{\\frac{d}{dt}\\ket{\\psi}}_{-\\frac{i}{\\hbar}H\\ket{\\psi}}\n\\end{align}\nand then we get the beautiful result\n\\begin{align}\n    \\frac{d}{dt}\\bar{A} &=\n    -\\frac{i}{\\hbar} \\bra{\\psi} [A,H] \\ket{\\psi}\n\\end{align}\nwhich leads to\n\\begin{align}\n    \\left|\\frac{d\\bar{A}}{dt}\\right| &=\n    \\frac{1}{\\hbar}\n    |\\bra{\\psi} [A,H] \\ket{\\psi} |\\\\\n    &\\le \\frac{2}{\\hbar}\\sigma_A \\sigma_H\n\\end{align}\nby the uncertainty principle,\njust half the commutator.\n\nWhat we do is this\nThere is an interpretation for the formula.\nI'm going to write it like this.\n\\begin{align}\n    \\boxed{\n        \\sigma_H \\frac{\\sigma_A}{\\left|\\frac{d\\bar{A}}{dt}\\right|}\n        \\ge \\frac{\\hbar}{2}.\n    }\n\\end{align}\nThis $\\sigma_H$ of course is the uncertainty of the energy.\nIn a particular state,\nthere is some spread in the energy I get.\n\nWhat about this $\\frac{\\sigma_A}{\\left|\\frac{d\\bar{A}}{dt}\\right|}$?\nIt's the uncertainty of $A$ divided by how fast the average of $A$ changes.\nThis thing has units of time.\nThe interpretation is that it is the time it takes for $\\bar{A}$\nto move enough to go outside the uncertainty.\nThis is how long it takes for the average value of $A$ to change appreciably.\nIt is the time it takes for $\\bar{A}$ to change by $\\sigam_A$.\n\nLet me draw a picture.\nI can measure $A$,\nthere is an average $\\bar{A}$ and there is a spread $\\sigma_A$.\nOver time,\nthe central value would change,\nand it's going to take time for the central value to change more than\n$\\sigma_A$.\nSo this is the time it takes for $A$ to change such that it matters.\n\nIf you're close to an eigenstate of energy,\nthis is going to be small,\nand this is going to be large.\nThe expectation is going to change not by much.\nIf I'm in an eigenstate,\nin fact I don't change at all.\nOn the other hand,\nif it's a superposition of many energy eigenstates,\nthne the wave function chages fast,\nand this thing is small,\nand hte expectation value moves wildly.\nThere is an uncertainty relation between energy and time,\nbut time is just the time it takes for stuff to change,\nwhere stuff is whatever $A$ you put here.\n\n\n\\begin{question}\n    Eigenstates are stable?\n\\end{question}\nThey are completely stable.\nIf you substitute it into the Schrodinger equation,\nthe ket is just going to evolve by phase,\nbut the phase doesn't matter anyway.\nThe universe is not in an eigenstate of the Hamiltonian of the universe,\nbecause it it was,\nhow can we be moving around?\n\nExample.\nHave you heard of quarks and gluons?\nIt's a complicated theory.\nNot so much to state.\nBut to solve.\nThere is a state where 3 quarks live together,\nthey have spin that point up called $\\Delta^+$.\nThis doesn't last a long time.\nVery quick,\nit splits up into a neutron $n$ and a pion $\\pi^+$.\nLet's try to understand what this means in QM language.\n\nWe started off with a certain state\n$\\ket{\\Delta^+}$.\nIt's not an energy eigenstate of the QCD Hamiltonian,\nso it will hange,\nbut change in many ways.\nWhen this evolves in time,\nthis is going to go into a state\n\\begin{align}\n    U(t)\\ket{\\Delta^+} &=\n    \\alpha\\ket{\\Delta^+} + \\beta \\ket{n \\pi^+} + \\cdots\n\\end{align}\nso it's not an eigenstate of QCD.\nYou can detect the neutron,\nand you can measure the energy and momenta,\nand you can make a plot.\nBecause of conservation of energy,\nthis state should have the same energy as the original state.\n\nWhat I find is something like this of prob vs energy $E$.\nI get a certain distribution,\na distribution with some mean at 1232 MeV\nand a spread of 300 MeV.\nWhat I say is this.\n\nIt takes time for this state $\\ket{\\Delta^+}$\nto change appreciably.\nHow long does it take to change appreciably?\nThis number here 300 MeV.\nKnowing the uncertainty of the energy,\nand knowing the right hand side,\nI should know this $\\sigma_A/|d\\bar{A}/dt|$,\nthe time it takes to appreciably change,\notherwise known as the lifetime,\nsometimes written as $\\tau$.\n\nWhen you see the newspaper saying the Higgs boson has a lifetime whatever,\nno one timed it,\nthey just observed it decayed into $\\Delta^+$ and $\\Delta^-$.\nThey say a plot like this.\nIt didn't look pretty,\nthere are error bars,\nand there's this bump here with two data points.\nNo one believed it.\n\nThen people looked at other decay modes.\nThey do some plots,\nand notice this other peak.\nIt must be a coincidence,\nCalculated the probability.\nThey say they discovered the Higgs and celebrated.\n\nThe regular uncertainty that is not time,\nit's typically saturated,\nyou get the equality for the ground state.\nThere's a similar experience here.\nFor ground state things,\nthe lowest state that 3 quarks can have for example,\nis going to saturate the inequality.\n\nIt becomes a definition almost.\nWhat they really mean when they say the Higgs has some lifetime,\nit's really saying the width is something.\n\nIn some experiments,\nyou can measure two things independently,\nlifetime and width.\nThe relation is an inequality.\nIn some situations,\nthere is saturated.\nBut I can construct situations where the lifetime is much bigger than this\ninequality suggests,\nbut I have to think about it.\nIn a harmonic oscillator,\nthe uncertain is minimum and bigger for higher states.\nOne can construct a state with much bigger uncertainty than the inequality\nbound.\n\nYou learn in Griffiths to calculate the hydrogen atom levels.\nI can't believe we're out of time.\nYou solve the hydrogen atom.\nWhat you did is htis.\nYou ge the Hamiltonian with Coulomb interaciton.\nNothing else.\nThen you find the eigenstates.\nThey are there the rest of the time.\nBut of course they don't.\nYou start iwth excited states,\nget cofeee\nand measuredecays.\nTo include not onlu the Coulomb interaction etween electorn and neuclus,\nbut also the quantised electromagnetic field.\nIf you do that,\nthose states you found were not eigenstates of the whole thing anymore,\nbut they're darn close to being eigenstates.\nAll those eigenstates you calculated in Griffiths are really close,\nbecause the unceratinty is so small.\nThose lines in the spectra you see are not infinitely thin.\nThere is a little spread.\nThis width is related to the lifetime.\nWhen you excite the hydrogen atom,\nlet it decay,\nsend it through a prism,\nthey're not going to be infinitely thin,\nsome are going to be bright and some are not.\n\ncan you guess a relation between the brightess and the width?\nIf the line is very sharp,\nthis time must be large,\nso you get very few photons iwth htat energy.\nSo thin lines are going to be dim.\n\nOn the other harnd, if $\\sigma_H$ is going to be big fat line,\nit's going to decay slow.\n\nAs an undergrad,\nyou learn about eigenstates and they never change,\nbut suddenly people say they jump.\nThere's no reason for that.\nWell it's beccause they missed out the rest of the Hamiotnian,\nbut it's good to teach as an introduction.\n", "meta": {"hexsha": "246380df87d498fc06fae99d5514ffe9c955e807", "size": 7832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture8.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/lecture8.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/lecture8.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.2304526749, "max_line_length": 77, "alphanum_fraction": 0.7442543412, "num_tokens": 2043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6752200753497173}}
{"text": "\\section{Infinite Limits and Limits at Infinity}\\label{sec:InfLimits}\r\nWe occasionally want to know what happens to some quantity\r\nwhen a variable gets very large or ``goes to infinity''.\r\n\r\n\\begin{example}{Limit at Infinity}{LimitInfinity}\r\nWhat happens to the function $\\ds \\cos(1/x)$ as $x$ goes to infinity? It\r\nseems clear that as $x$ gets larger and larger, $1/x$ gets closer and\r\ncloser to zero, so $\\cos(1/x)$ should be getting closer and closer to \r\n$\\cos(0)=1$.\r\n\\end{example}\r\n\r\nAs with ordinary limits, this concept of ``limit at infinity'' can be\r\nmade precise. Roughly, we want $\\ds \\lim_{x\\to \\infty}f(x)=L$ to mean that\r\nwe can make $f(x)$ as close as we want to $L$ by making $x$ large\r\nenough.\r\n\r\n\\begin{definition}{Limit at Infinity (Formal Definition)}{LimitAtInfinity}\r\nIf $f$ is a function, we say that $\\ds \\lim_{x\\to\r\n  \\infty}f(x)=L$ if for every $\\epsilon>0$ there is an $N > 0$ so that\r\n  whenever $x>N$, $|f(x)-L|<\\epsilon$.\r\nWe may similarly define $\\ds \\lim_{x\\to-\\infty}f(x)=L$.\r\n\\end{definition}\r\n\r\nWe include this definition for completeness, but we will not explore it in\r\ndetail. Suffice it to say that such limits behave in much the same way\r\nthat ordinary limits do; in particular there is a direct analog of \r\nTheorem~\\ref{thm:PropertiesLimits}.\r\n\r\n\\begin{example}{Limit at Infinity}{LimitInfinity2}\r\nCompute $\\ds\\lim_{x\\to \\infty}{2x^2-3x+7\\over x^2+47x+1}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nAs $x$ goes to infinity both the numerator and denominator go to\r\ninfinity. We divide the numerator and\r\ndenominator by $\\ds x^2$:\r\n$$\\lim_{x\\to \\infty}{2x^2-3x+7\\over x^2+47x+1}=\r\n\\lim_{x\\to \\infty}{2-\\ds{3\\over x}+\\ds{7\\over x^2}\\over\r\n1+\\ds{47\\over x}+\\ds{1\\over x^2}}.$$\r\nNow as $x$ approaches infinity, all the quotients with some power of\r\n$x$ in the denominator approach zero, leaving 2 in the numerator and 1\r\nin the denominator, so the limit again is 2.\r\n\\end{solution}\r\n\r\nIn the previous example, we \\ifont{divided by the highest power of $x$ that occurs in the denominator} in order to evaluate the limit.\r\nWe illustrate another technique similar to this.\r\n\r\n\\begin{example}{Limit at Infinity}{LimitInfinity3}\r\nCompute the following limit:\r\n$$\\lim_{x\\to\\infty}\\frac{2x^2+3}{5x^2+x}.$$\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nAs $x$ becomes large, both the numerator and denominator become large, so it isn't clear what happens to their ratio. The highest power of $x$ in the denominator is $x^2$, therefore we will divide every term in both the numerator and denominator by $x^2$ as follows:\r\n$$\\lim_{x\\to\\infty}\\frac{2x^2+3}{5x^2+x}=\\lim_{x\\to\\infty}\\frac{2+3/x^2}{5+1/x}.$$\r\nMost of the limit rules from last lecture also apply to infinite limits, so we can write this as:\r\n$$=\\frac{\\ds{\\lim_{x\\to\\infty}2+3\\lim_{x\\to\\infty}\\frac{1}{x^2}}}{\\ds{\\lim_{x\\to\\infty}5+\\lim_{x\\to\\infty}\\frac{1}{x}}}=\\frac{2+3(0)}{5+0}=\\frac{2}{5}.$$\r\nNote that we used the theorem above to get that $\\ds{\\lim_{x\\to\\infty}\\frac{1}{x}=0}$ and $\\ds{\\lim_{x\\to\\infty}\\frac{1}{x^2}=0}$.\r\n\r\nA shortcut technique is to analyze only the \\ifont{leading terms} of the numerator and denominator. A leading term is a term that has the highest power of $x$. If there are multiple terms with the same exponent, you must include all of them.\\\\\r\n\\ifont{Top:} The leading term is $2x^2$.\\\\\r\n\\ifont{Bottom:} The leading term is $5x^2$.\\\\\r\nNow only looking at leading terms and ignoring the other terms we get:\r\n$$\\lim_{x\\to\\infty}\\frac{2x^2+3}{5x^2+x}=\\lim_{x\\to\\infty}\\frac{2x^2}{5x^2}=\\frac{2}{5}.$$\r\n\\end{solution}\r\n\r\nWe next look at limits whose value is infinity (or minus infinity).\r\n\r\n\\begin{definition}{Infinite Limit (Useable Definition)}{Infinite Limit}\r\nIn general, we will write\r\n$$\\lim_{x\\to a}f(x)=\\infty$$\r\nif we can make the value of $f(x)$ arbitrarily large by taking $x$ to be sufficiently close to $a$ (on either side of $a$) but not equal to $a$.\r\nSimilarly, we will write\r\n$$\\lim_{x\\to a}f(x)=-\\infty$$\r\nif we can make the value of $f(x)$ arbitrarily large and \\blue{negative} by taking $x$ to be sufficiently close to $a$ (on either side of $a$) but not equal to $a$.\r\n\\end{definition}\r\n\r\nThis definition can be modified for one-sided limits as well as limits with $x\\to a$ replaced by $x\\to\\infty$ or $x\\to-\\infty$.\r\n\r\n\\begin{example}{Limit at Infinity}{LimitInfinity4}\r\nCompute the following limit: $\\ds\\lim_{x\\to\\infty}(x^3-x).$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nOne might be tempted to write:\r\n$$\\lim_{x\\to\\infty}x^3-\\lim_{x\\to\\infty}x=\\infty-\\infty,$$\r\nhowever, we do not know what $\\infty-\\infty$ is, as $\\infty$ is not a real number and so cannot be treated like one.\r\nWe instead write:\r\n$$\\lim_{x\\to\\infty}(x^3-x)=\\lim_{x\\to\\infty}x(x^2-1).$$\r\nAs $x$ becomes arbitrarily large, then both $x$ and $x^2-1$ become arbitrarily large, and hence their product $x(x^2-1)$ will also become arbitrarily large. Thus we see that\r\n$$\\lim_{x\\to\\infty}(x^3-x)=\\infty.$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Limit at Infinity and Basic Functions}{LimitInfinity5}\r\nWe can easily evaluate the following limits by observation:\r\n\\[ \\begin{array}{ll}\r\n1.~\\ds\\lim_{x\\to \\infty} \\frac{6}{\\sqrt{x^3}}=0 & \\qquad 2.~\\ds\\lim_{x\\to -\\infty} x-x^2=-\\infty \\\\\r\n\\\\\r\n3.~\\ds\\lim_{x\\to \\infty}x^3+x=\\infty            & \\qquad 4.~\\ds\\lim_{x\\to \\infty} \\cos(x)=\\mbox{DNE} \\\\\r\n\\\\\r\n5.~\\ds\\lim_{x\\to \\infty} e^x=\\infty             & \\qquad 6.~\\ds\\lim_{x\\to -\\infty} e^x=0 \\\\\r\n\\\\\r\n7.~\\ds\\lim_{x\\to 0^+} \\ln x=-\\infty             & \\qquad 8.~\\ds\\lim_{x\\to 0} \\cos(1/x)=\\mbox{DNE} \\\\\r\n\\end{array} \\]\r\n\\end{example}\r\n\r\nOften, the shorthand notation $\\ds\\frac{1}{0^+}=+\\infty$ and $\\ds\\frac{1}{0^-}=-\\infty$ is used to represent the following two limits respectively:\r\n$$\\lim_{x\\to 0^+}\\frac{1}{x}=+\\infty\\qquad\\mbox{and}\\qquad\\lim_{x\\to 0^-}\\frac{1}{x}=-\\infty.$$\r\nUsing the above convention we can compute the following limits.\r\n\r\n\\begin{example}{Limit at Infinity and Basic Functions}{LimitInfinity6}\r\nCompute $\\ds{\\lim_{x\\to 0^+} e^{1/x}}$, $\\ds{\\lim_{x\\to 0^-} e^{1/x}}$ and $\\ds{\\lim_{x\\to 0} e^{1/x}}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe have:\r\n$$\\lim_{x\\to 0^+} e^{\\frac{1}{x}}=e^{\\frac{1}{0^+}}=e^{+\\infty}=\\infty.$$\r\n$$\\lim_{x\\to 0^-} e^{\\frac{1}{x}}=e^{\\frac{1}{0^-}}=e^{-\\infty}=0.$$\r\nThus, as left-hand limit $\\neq$ right-hand limit, \r\n$$\\lim_{x\\to 0} e^{\\frac{1}{x}}=\\mbox{DNE}.$$\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Subsections to include\r\n\\input{3-limits/3-5-1-vertical-asymptotes}\r\n\\input{3-limits/3-5-2-horizontal-asymptotes}\r\n\\input{3-limits/3-5-3-slant-asymptotes}\r\n\\input{3-limits/3-5-4-end-behaviour-growth-rate}\r\n\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:InfLimits}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nCompute the following limits.\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds\\lim_{x\\to \\infty} \\sqrt{x^2+x}-\\sqrt{x^2-x}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty} {e^x + e^{-x}\\over e^x -e^{-x}}$\r\n\t\\item\t$\\ds\\lim_{t\\to1^+}{(1/t)-1\\over t^2-2t+1}$\r\n\t\\item\t$\\ds\\lim_{t\\to\\infty}{t+5-2/t-1/t^3\\over 3t+12-1/t^2}$\r\n\t\\item\t$\\ds\\lim_{y\\to\\infty}{\\sqrt{y+1}+\\sqrt{y-1}\\over y}$\r\n\t\\item\t$\\ds\\lim_{x\\to 0^+}{3+x^{-1/2}+x^{-1}\\over 2+4x^{-1/2}}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty}{x+x^{1/2}+x^{1/3}\\over x^{2/3}+x^{1/4}}$\r\n\t\\item\t$\\ds\\lim_{t\\to\\infty}{1-\\sqrt{t\\over t+1}\\over 2-\\sqrt{4t+1\\over t+2}}$\r\n\t\\item\t$\\ds\\lim_{t\\to\\infty}{1-{t\\over t-1}\\over 1-\\sqrt{t\\over t-1}}$\r\n\t\\item\t$\\ds\\lim_{x\\to-\\infty}{x+x^{-1}\\over 1+\\sqrt{1-x}}$\r\n\t\\item\t$\\ds\\lim_{x\\to1^+}{\\sqrt{x}\\over x-1}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty}{x^{-1}+x^{-1/2}\\over x+x^{-1/2}}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty}{x+x^{-2}\\over 2x+x^{-2}}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty}{5+x^{-1}\\over 1+2x^{-1}}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty}{4x\\over\\sqrt{2x^2+1}}$\r\n\t\\item\t$\\ds\\lim_{x\\to\\infty}{(x+5)\\left({1\\over 2x}+{1\\over x+2}\\right)}$\r\n\t\\item\t$\\ds\\lim_{x\\to0^+}{(x+5)\\left({1\\over 2x}+{1\\over x+2}\\right)}$\r\n\t\\item\t$\\ds\\lim_{x\\to2}{x^3-6x-2\\over x^3-4x}$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$1$\r\n\t\\item\t$1$\r\n\t\\item\t$-\\infty$\r\n\t\\item\t$1/3$\r\n\t\\item\t$0$\r\n\t\\item\t$\\infty$\r\n\t\\item\t$\\infty$\r\n\t\\item\t$2/7$\r\n\t\\item\t$2$\r\n\t\\item\t$-\\infty$\r\n\t\\item\t$\\infty$\r\n\t\\item\t$0$\r\n\t\\item\t$1/2$\r\n\t\\item\t$5$\r\n\t\\item\t$\\ds 2\\sqrt2$\r\n\t\\item\t$3/2$\r\n\t\\item\t$\\infty$\r\n\t\\item\tdoes not exist\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nThe function $\\ds f(x) = {x\\over\\sqrt{x^2+1}}$ has two horizontal asymptotes.  Find them and give a rough sketch of $f$ with its horizontal asymptotes. \r\n\\begin{sol}\r\n$y=1$ and $y=-1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind the vertical asymptotes of $\\ds f(x)=\\frac{\\ln x}{x-2}$.\r\n\\begin{sol}\r\n\t$x=0$ and $x=2$.\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSuppose that a falling object reaches velocity $v(t)=50(1-e^{-t/5})$ at time $t$, where distance is measured in $m$ and time $s$. What is the object's terminal velocity, i.e. the value of $v(t)$ as $t$ goes to infinity?\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind the slant asymptote of $f(x)=\\dfrac{x^2+x+6}{x-3}$.\r\n\\begin{sol}\r\n\t$y=x+4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n\tCompute the following limits.\r\n\t\\begin{enumerate}\r\n\t\t\\item\t$\\ds\\lim_{x\\to -\\infty}(2x^3-x)$\r\n\t\t\\item\t$\\ds\\lim_{x\\to \\infty}\\tan^{-1}(e^x)$\r\n\t\t\\item\t$\\ds\\lim_{x\\to -\\infty}\\tan^{-1}(e^x)$\r\n\t\t\\item\t$\\ds\\lim_{x\\to \\infty}\\dfrac{e^x+x^4}{x^3+5\\ln x}$\r\n\t\t\\item\t$\\ds\\lim_{x\\to \\infty}\\dfrac{2^x+5(3^x)}{3(2^x)-3^x}$\r\n\t\t\\item\t$\\ds\\lim_{x\\to -\\infty}\\dfrac{2^x+5(3^x)}{3(2^x)-3^x}$\r\n\t\t\\item\t$\\ds\\lim_{x\\to 0^{+}}\\sqrt{x}\\ln x$ [Hint: Let $t=1/x$]\r\n\t\\end{enumerate}\r\n\t\\begin{sol}\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item\t$-\\infty$\r\n\t\t\t\\item\t$\\pi/2$\r\n\t\t\t\\item\t0\r\n\t\t\t\\item\t$\\infty$\r\n\t\t\t\\item\t$-5$\r\n\t\t\t\\item\t1/3\r\n\t\t\t\\item\t0\r\n\t\t\\end{enumerate}\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "5cc73656dba5d7553e07f39a3cbf7743a236243a", "size": 9841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-5-0-inf-limits.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-5-0-inf-limits.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-5-0-inf-limits.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.6814516129, "max_line_length": 267, "alphanum_fraction": 0.63154151, "num_tokens": 3847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867825403176, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.6752200706995376}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\subsection{Proofs of correctness}\nOur optimisation problem described previously can now be restated as follows for mathematical clarity.\\\\\n\\noindent\\Problem \\textit{Find a maximal member $B$ of $\\mathcal{I}$ of maximum weight.}\n\\begin{note}\nLet $B_G$ be a base of a matroid generated by the greedy algorithm.\n\\end{note}\n\\begin{thm}\\cite{ox_book}\nIf $(E,\\mathcal{I})$ is a matroid $M,$ then $B_G$ is a solution to the optimization problem.\n\\end{thm}\n\\begin{proof}\nIf $r(M) = r,$ then $B_G = \\{e_1,e_2, ..., e_r\\}$ is a basis of $M.$ Let $B$ be another basis of $M$, $B = \\{f_1, f_2, ..., f_r\\}$\nwhere $\\omega(f_1) \\geq \\omega(f_2) \\geq ... \\geq \\omega(f_r).$ We claim that $\\omega(e_j) \\geq \\omega(f_f)$ $ \\forall j$ , then it follows that $\\omega(B_G) \\geq \\omega(B)$ for any other basis in $\\mathcal{B}.$\n\\end{proof}\n\n\\begin{lem}\\cite{ox_book}\nIf $1 \\leq j \\leq r,$ then $\\omega(e_j) \\geq \\omega(f_j).$\n\\end{lem}\n\\begin{proof}\nSuppose (seeking a contradiction) that $k$ is the least integer for which $\\omega(e_k) < \\omega(f_k).$ Take $I_1 = \\{e_1, e_2, ..., e_{k-1}\\}$ and $I_2 = \\{f_1, f_2, ..., f_{k}\\}.$ Since $|I_2| = |I_1|+1$  $(I3)$ implies $I_1 \\cup \\{f_t\\} \\in \\mathcal{I}$ for some $f_t \\in I_2 \\setminus I_1.$ But this means that $\\omega(f_t) \\geq \\omega(f_k) > \\omega(e_k)$ and hence the Greedy algorithm would have chosen $f_t$ over $e_k$, which gives us our contradiction.\n\\end{proof}\n\\end{document}", "meta": {"hexsha": "df287a4c8af7d8786e2c7d9943ca13985e29b09e", "size": 1470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/opt1.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/opt1.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/opt1.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": 63.9130434783, "max_line_length": 459, "alphanum_fraction": 0.6653061224, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6752200619882451}}
{"text": "\\RequirePackage[l2tabu, orthodox]{nag}\n\\documentclass[a4paper]{article}\n\\usepackage[a4paper]{geometry}\n\\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}\n\\usepackage{amsmath,esint,bm,siunitx,cleveref}\n\\title{Green's Identities}\n\\author{Naitree Zhu}\n\\date{Last modified: \\today}\n\\begin{document}\n\\maketitle\nIn mathematics, Green's identities\\footnote{More information:\\url{http://en.wikipedia.org/wiki/Green's_identities}} are a set of three identities in vector calculus. They are named after the mathematician George Green, who discovered Green's theorem.\n\\part{Green's first identity}\nThis identity is derived from the divergence theorem applied to the vector field $\\boldsymbol{F}=\\psi\\nabla\\varphi$: Let $\\varphi$ and $\\psi$ be scalar functions defined on some region \\textit{U} in $R^{3}$, and suppose that $\\varphi$ is twice continuously differentiable, and $\\psi$ is once continuously differentiable. Then\n\\begin{equation}\n\\int_U\\left(\\psi\\nabla^{2}\\varphi+\\nabla\\varphi\\cdot\\nabla\\psi\\right)\\mathrm{d}V=\\oint_{\\partial U} \\psi\\nabla\\varphi\\cdot\\mathrm{d}\\boldsymbol{S}\n\\end{equation}\n\nThis theorem is essentially the higher dimensional equivalent of integration by parts:\n\\begin{equation}\n\\int_\\Omega\\nabla u\\cdot\\boldsymbol{v}\\mathrm{d}\\Omega=\\int_\\Gamma u\\left(\\boldsymbol{v}\\cdot\\hat{\\nu}\\right)\\mathrm{d}\\Gamma-\\int_\\Omega u\\nabla\\cdot\\boldsymbol{v}\\mathrm{d}\\Omega\n\\end{equation}\nwith $\\psi$ and $\\nabla\\varphi$ replacing u and v.\n\\section*{Proof}\nNote that Green's first identity above is a special case of the more general identity derived from the divergence theorem by substituting $\\psi\\bm{F}$ for $\\bm{F}$:\n\\begin{equation}\n\\int_U\\left(\\psi\\nabla\\cdot\\bm{F}+\\bm{F}\\cdot\\nabla\\psi\\right)\\mathrm{d}V=\\oint_{\\partial U}\\psi\\bm{F}\\cdot\\mathrm{d}\\bm{S}\n\\end{equation} \n\\part{Green's second identity}\nIf $\\varphi$ and $\\psi$ are both twice continuously differentiable on \\textit{U} in $R^{3}$, and $\\epsilon$ is once continuously differentiable, we can choose $\\bm{F}=\\psi\\epsilon\\nabla\\varphi-\\varphi\\epsilon\\nabla\\psi$ and obtain:\n\\begin{equation}\n\\int_U \\left[\\psi\\nabla\\cdot\\left(\\epsilon\\nabla\\varphi\\right)-\\varphi\\nabla\\cdot\\left(\\epsilon\\nabla\\psi\\right)\\right]\\mathrm{d}V=\\oint_{\\partial U} \\epsilon\\left(\\psi\\frac{\\partial\\varphi}{\\partial n}-\\varphi\\frac{\\partial\\psi}{\\partial n}\\right)\\mathrm{d}S\n\\end{equation}\nFor the special case of $\\epsilon=1$ all across \\textit{U} in $R_{3}$ then:\n\\begin{equation}\n\\int_U \\left(\\psi\\nabla^{2}\\varphi-\\varphi\\nabla^{2}\\psi\\right)\\mathrm{d}V=\\oint_{\\partial U}\\left(\\psi\\frac{\\partial \\varphi}{\\partial n}-\\varphi\\frac{\\partial\\psi}{\\partial n}\\right)\\mathrm{d}S\n\\end{equation}\n$\\frac{\\partial \\varphi}{\\partial n}$ is the directional derivative of $\\varphi$ in the direction of the outward pointing normal $\\hat{n}$ to the surface element $\\mathrm{d}\\bm{S}$, i.e.\n\\begin{equation}\n\\frac{\\partial \\varphi}{\\partial n}=\\nabla\\varphi\\cdot\\hat{n}\n\\end{equation}\n\\section*{Proof}\nBy substituting $\\epsilon\\nabla\\varphi$ for $\\nabla\\varphi$ in Green's first identity eq.~(1), we can get \n\\begin{equation}\n\\int_U \\left[\\psi\\nabla\\cdot\\left(\\epsilon\\nabla\\varphi\\right)+\\epsilon\\nabla\\varphi\\cdot\\nabla\\psi\\right]\\mathrm{d}V=\\oint_{\\partial U} \\epsilon\\psi\\frac{\\partial\\varphi}{\\partial n}\\mathrm{d}S\n\\end{equation}\nSwap $\\psi$ and $\\varphi$ in the equation above, then\n\\begin{equation}\n\\int_U \\left[\\varphi\\nabla\\cdot\\left(\\epsilon\\nabla\\psi\\right)+\\epsilon\\nabla\\psi\\cdot\\nabla\\varphi\\right]\\mathrm{d}V=\\oint_{\\partial U} \\epsilon\\varphi\\frac{\\partial\\psi}{\\partial n}\\mathrm{d}S\n\\end{equation}\nFinally, $(7)-(8)$ and it will lead to Green's second identity eq.~(4). \n\\part{Green's third identity}\nGreen's third identity derives from the second identity by choosing $\\varphi=G$, where \\textit{G} is a Green's function of the Laplace operator. This means that:\n\\begin{equation}\n\\nabla^{2}G(\\bm{x},\\bm{\\eta})=\\delta(\\bm{x}-\\bm{\\eta})\n\\end{equation}\nFor example in $R^{3}$, a solution has the form:\n\\begin{equation}\nG(\\bm{x},\\bm{\\eta})=\\frac{-1}{4\\pi\\lVert \\bm{x}-\\bm{\\eta} \\rVert}\n\\end{equation}\nApply it into eq.~(5), and it leads to Green's third identity.\n\nGreen's third identity states that if $\\psi$ is a function that is twice continuously differentiable on \\textit{U}, then\n\\begin{equation}\n\\int_U \\left[G\\left(\\bm{x},\\bm{\\eta}\\right)\\nabla^{2}\\psi\\left(\\bm{x}\\right)\\right]\\mathrm{d}V-\\psi\\left(\\bm{\\eta}\\right)=\\oint_{\\partial U}\\left[G\\left(\\bm{x},\\bm{\\eta}\\right)\\frac{\\partial \\psi\\left(\\bm{x}\\right)}{\\partial n}-\\psi\\left(\\bm{x}\\right)\\frac{\\partial G\\left(\\bm{x},\\bm{\\eta}\\right)}{\\partial n}\\right]\\mathrm{d}S\n\\end{equation}\nA simplification arises if $\\psi$ is itself a harmonic function, i.e. a solution to the Laplace equation. So the identity above simplifies to:\n\\begin{equation}\n\\psi\\left(\\eta\\right)=\\oint_{\\partial U}\\left[\\psi\\left(\\bm{x}\\right)\\frac{\\partial G\\left(\\bm{x},\\bm{\\eta}\\right)}{\\partial n}-G\\left(\\bm{x},\\bm{\\eta}\\right)\\frac{\\partial \\psi\\left(\\bm{\\eta}\\right)}{\\partial n}\\right]\\mathrm{d}S\n\\end{equation}\nThe second term in the integral above can be eliminated if we choose \\textit{G} to be the Green's function that vanishes on the boundary of region \\textit{U} (Dirichlet boundary condition):\n\\begin{equation}\n\\psi\\left(\\eta\\right)=\\oint_{\\partial U}\\psi\\left(\\bm{x}\\right)\\frac{\\partial G\\left(\\bm{x},\\bm{\\eta}\\right)}{\\partial n}\\mathrm{d}S\n\\end{equation}\nThis form is used to construct solutions to Dirichlet boundary condition problems. To find solutions for Neumann boundary condition problems, the Green's function with vanishing normal gradient on the boundary is used instead.\n\nIt can be further verified that the above identity also applies when $\\psi$ is a solution to the Helmholtz equation or wave equation and \\textit{G} is the appropriate Green's function. In such a context, this identity is the mathematical expression of the Huygens Principle.\n\\part{Green's vector identity}\nSee Wikipedia. A little complicated and I don't see a need in the near future to know it.\n\\end{document}", "meta": {"hexsha": "0f35ab0f1ce39f98cbe66c16e9ad9fa72265d0eb", "size": 6006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/Green's identities/Green's identities.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/Green's identities/Green's identities.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/Green's identities/Green's identities.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": 76.0253164557, "max_line_length": 327, "alphanum_fraction": 0.7412587413, "num_tokens": 1917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6751268576581353}}
{"text": "\\subsection*{Introduction}\n\nFor this exercise, we analyze a time series containing the British coal mining disasters under the time period 1851--1962. The difference between this exercise and the one in the course literature, is that we have a continuous time series as well as more than 1 \\textbf{breakpoint}. A breakpoint is thus the year at which the intensity of the disasters change. We will use $d-1$ breakpoints, where $d$ then corresponds to the number of intervals we will use. In order to get a feel for the time series we will analyze, a figure containing a histogram of the disasters is found in figure \\ref{fig:disasters}.\n\n\\begin{figure}[H]\n  \\centering\n    \\includegraphics[scale=0.24]{./Figures/disasters.png}\n  \\caption[An Electron]{Histogram plot of the British coal mine disasters in the time period 1851--1962.}\n  \\label{fig:disasters}\n\\end{figure}\n\nAs is seen in figure \\ref{fig:disasters} there is a change in the disaster intensity at the turn of the century, perhaps due to some legislation regarding work safety or some technological advancement. \\\\ \\\\ To begin the exercise, we define the vector $\\boldsymbol{t}$ to be the vector containing all of the breakpoints $t_i, \\: i = 2,\\dots d$ aswell as the start and end point $t_1 = 1851$ and $t_{d+1}=1963$. We wish to model the disasters using an inhomogenous Poisson process with an intensity $\\lambda_i$ for each of the intervals $[t_i,t_{i+1}), \\: i = 1,\\dots,d$. Where all of the $\\lambda_i$'s are collected in a vector $\\boldsymbol{\\lambda}$. \\\\ We will denote the time series containing the year at which disaster struck as $\\boldsymbol{\\tau} = (\\tau_1,\\dots,\\tau_n)$ for $n = 191$, where the subscript denotes accident $i$. \\\\ We then define the number of accidents under the interval $[t_i,t_{i+1})$ to be\n\\[n_i(\\boldsymbol{\\tau}) = \\sum^n_{j = 1}\\mathbbm{1}\\{[t_i,t_{i+1})\\}\\cdot \\tau_j \\]\nWe set a $\\Gamma(2,\\theta)$ prior on the intensities, $\\lambda_i$, and a $\\Gamma(2,\\beta)$ hyperprior on $\\theta$. Where $\\beta$ is a hyperparameter that needs to be specified. Furthermore, we put the prior\n\\[ f(\\boldsymbol{t}) \\propto\\left\\{\n\t\\begin{array}{l}\n\t\t\\prod^d_{i = 1}(t_{i+1} - t_i), \\quad \\text{for } t_1 < t_2 < \\dots < t_{d+1} \\\\\n\t\t0, \\quad \\text{else} \n\t\\end{array}\n\\right. \\]\n This prior prevents the breakpoints from being located to closely. All of these prior assumptions then imply that \n\\[f(\\boldsymbol{\\tau} | \\boldsymbol{\\lambda}, \\boldsymbol{t}) \\propto \\prod^d_{i = 1}\\lambda_i^{n_i(\\boldsymbol{\\tau})}\\cdot\\exp \\left \\{ - \\sum^d_{i = 1}\\lambda_i(t_{i+1} - t_i) \\right \\} \\]\nIn order to sample from the posterior $f(\\theta,\\boldsymbol{t},\\boldsymbol{\\lambda} | \\boldsymbol{\\tau})$ we will construct a hybrid \\textbf{M}arkov \\textbf{C}hain \\textbf{M}onte \\textbf{C}arlo algorithm, where the hybrid comes from the fact that we will need to sample $\\boldsymbol{t}$ using a Metropolis--Hastings step whereas the other components can be updated using a Gibbs sampler. \\\\ \\\\ There are several ways to choose the proposal distribution for the Metropolis--Hastings, we chose to use the \\textit{Random walk proposal}, which means that we will update one breakpoint at a time and for each breakpoint $t_i$ generate a candidate $t^*_i$ according to\n\\[t^*_i = t_i + \\epsilon, \\quad \\epsilon \\sim \\text{Unif}(-R,R) \\]\nWhere $R = \\rho(t_{i+1} - t_{i-1})$ and $\\rho$ is a tuning parameter.\n\n%Basic idea of MCMC (Markov Chain Monte Carlo): To sample from a density f we construct a\n%Markov chain having f as stationary distribution. A law of\n%large numbers for Markov chains guarantees convergence. \\\\\n\n%MCMC is widely used for sampling, due to its simplicity when dealing with complex distributions or distributions of high dimensions. However, the price is that the samples will be statistically dependant. It can be used to simulate a probabiltiy distribution $\\pi(x)$ that is known only up to a normalizing constant, which is especially important in Bayesian inference with $\\pi$ as the posterior distribution.\n", "meta": {"hexsha": "384175e27f26ae0ecd5a211df55888f952482362", "size": 3997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/Report/intro.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/intro.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/intro.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": 124.90625, "max_line_length": 917, "alphanum_fraction": 0.736802602, "num_tokens": 1118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749422, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6751268543480068}}
{"text": "\\gotosection{2}{1}\n\\subsection{The main algorithm: row reduction}\n\n\\begin{exercise}{2}\n  \\begin{enumerate}\n    \\item $[A|\\Vect{b}] = \\xmat{0&3&-1&0\\\\-2&1&2&0\\\\1&0&-5&0}\n      \\rightarrow \\rops{R_1: R_3\\\\R_3: R_1}\\xmat{1&0&-5&0\\\\-2&1&2&0\\\\0&3&-1&0}\n      \\rightarrow \\rops{R_2: 2R_1+R_2}\\\\ \\xmat{1&0&-5&0\\\\0&1&-8&0\\\\0&3&-1&0}\n      \\rightarrow \\rops{R_3: -3R_2+R_3}\\xmat{1&0&-5&0\\\\0&1&-8&0\\\\0&0&23&0}\n      \\rightarrow \\rops{R_3: 1/23R_3}\\\\\\xmat{1&0&-5&0\\\\0&1&-8&0\\\\0&0&1&0}\n      \\rightarrow \\rops{R_1: R_1+5R_3\\\\R_2: R_2+8R_3}\\xmat{1&0&0&0\\\\0&1&0&0\\\\0&0&1&0}\n      = [\\widetilde{A}|\\widetilde{b}]$\n    \\item $[A|\\Vect{b}] = \\xmat{2&3&-1&1\\\\0&-2&1&2\\\\1&0&-2&-1}\n      \\rightarrow \\rops{R_1: R_3\\\\R_3: R_1}\\xmat{1&0&-2&-1\\\\0&-2&1&2\\\\2&3&-1&1}\n      \\rightarrow \\rops{R_3: -2R_1 + R_3}\\\\\\xmat{1&0&-2&-1\\\\0&-2&1&2\\\\0&3&3&3}\n      \\rightarrow \\rops{R_2: -1/2R_2}\\xmat{1&0&-2&-1\\\\0&1&-1/2&-1\\\\0&3&3&3}\n      \\rightarrow \\rops{R_3: -3R_2+R_3}\\\\ \\xmat{1&0&-2&-1\\\\0&1&-1/2&-1\\\\0&0&9/2&6}\n      \\rightarrow \\rops{R_3: 2/9R_3}\\xmat{1&0&-2&-1\\\\0&1&-1/2&-1\\\\0&0&1&4/3}\n      \\rightarrow \\rops{R_1: R_1 + 2R_3\\\\R_2: R_2 + 1/2R3} \\\\\n                  \\xmat{1&0&0&5/3\\\\ 0&1&0&-1/3\\\\ 0&0&1&4/3}\n      = [\\widetilde{A}|\\widetilde{b}]$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{3}\n  \\begin{enumerate}\n    \\item $A = \\xmat{1&2&3 \\\\ 4&5&6} \\rightarrow\n      \\rops{R_2: -4R_1 + R_2} \\xmat{1&2&3 \\\\ 0&-3&-6} \\rightarrow\n      \\rops{R_2: -1/3R_2} \\xmat{1&2&3 \\\\ 0&1&2} \\rightarrow\n      \\rops{R_1: R_1 - 2R_2} \\xmat{1&0&-1 \\\\ 0&1&2} = \\widetilde{A}$\n      \n    \\item $A = \\xmat{1&-1&1 \\\\ -1&0&2 \\\\ -1&1&1} \\rightarrow\n      \\rops{R_2: R_1 + R_2\\\\ R_3: R_1 + R_3} \\xmat{1&-1&1 \\\\ 0&-1&3 \\\\ 0&0&1} \\rightarrow\n      \\rops{R_2: -R_2} \\xmat{1&-1&1 \\\\ 0&1&-3 \\\\ 0&0&1} \\rightarrow\n      \\rops{R_1: R_1 + R_2} \\xmat{1&0&-2 \\\\ 0&1&-3 \\\\ 0&0&1} \\rightarrow\n      \\rops{R_1: R_1 + 2R_3\\\\ R_2: R_2 + 3R_3} \\xmat{1&0&0 \\\\ 0&1&0 \\\\ 0&0&1}\n      = \\widetilde{A}$\n      \n    \\item $A = \\xmat{1&2&3&5 \\\\ 2&3&0&-1 \\\\ 0&1&2&3} \\rightarrow\n        \\rops{R_2: -2R_1 + R_2} \\xmat{1&2&3&5 \\\\ 0&-1&-6&-11 \\\\ 0&1&2&3} \\rightarrow\n        \\rops{R_2: R_3 \\\\ R_3: R_2} \\\\ \\xmat{1&2&3&5 \\\\ 0&1&2&3 \\\\ 0&-1&-6&-11} \\rightarrow\n        \\rops{R_1: R_1 - R_2 \\\\ R_3: R_2 + R_3}\n          \\xmat{1&0&-1&-1 \\\\ 0&1&2&3 \\\\ 0&0&-4&-8} \\rightarrow\n        \\rops{R_3: -1/4R_3} \\\\ \\xmat{1&0&-1&-1 \\\\ 0&1&2&3 \\\\ 0&0&1&2} \\rightarrow\n        \\rops{R_1: R_1 + R_3 \\\\ R_2: R_2 - 2R_3}\n          \\xmat{1&0&0&1 \\\\ 0&1&0&-1 \\\\ 0&0&1&2} = \\widetilde{A}$\n          \n    \\item $A = \\xmat{1&3&-1&4 \\\\ 1&2&1&2 \\\\3&7&1&9} \\rightarrow\n      \\rops{R_2: -1R_1 + R_2\\\\ R_3: -3R_1 + R_3}\n        \\xmat{1&3&-1&4 \\\\ 0&-1&2&-2 \\\\ 0&-2&4&-3} \\rightarrow\n      \\rops{R_2: -R_2} \\\\ \\xmat{1&3&-1&4 \\\\ 0&1&-2&2 \\\\ 0&-2&4&-3} \\rightarrow\n      \\rops{R_1: R_1 - 3R_2\\\\ R_3: 2R_2 + R_3}\n        \\xmat{1&0&5&-2 \\\\ 0&1&-2&2 \\\\ 0&0&0&1} = \\widetilde{A}$\n        \n    \\item $A = \\xmat{1&1&1&1 \\\\ 2&-3&3&3 \\\\ 1&-4&2&2} \\rightarrow\n      \\rops{R_2: -2R_1 + R_2\\\\ R_3: -R_1 + R_3}\n        \\xmat{1&1&1&1 \\\\ 0&-5&1&1 \\\\ 0&-5&1&1} \\rightarrow\n      \\rops{R_2: -1/5R_2} \\\\\n        \\xmat{1&1&1&1 \\\\ 0&1&-1/5&-1/5 \\\\ 0&-5&1&1} \\rightarrow\n      \\rops{R_1: R_1 - R_2\\\\ R_3: 5R_2 + R_3}\n        \\xmat{1&0&6/5&6/5 \\\\ 0&1&-1/5&-1/5 \\\\ 0&0&-1&-1} \\rightarrow\n      \\rops{R_3: -R_3} \\\\\n        \\xmat{1&0&6/5&6/5 \\\\ 0&1&-1/5&-1/5 \\\\ 0&0&1&1} \\rightarrow\n      \\rops{R_1: R_1 - 6/5R_3\\\\ R_2: R_2 + 1/5R_3}\n        \\xmat{1&0&0&0 \\\\ 0&1&0&0 \\\\ 0&0&1&1} = \\widetilde{A}$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{5}\n  \\begin{enumerate}\n    \\item Multiplying a row by a nonzero number $c$.\n    \n        Such operation can be undone by multiplying the result row with $1/c$, since $\\forall x \\in \\mathbb{R}$, $(1/c)cx = ((1/c)c)x = x$, namely $1/c$ is $c$'s inverse with $1$ being the identity providing that $c \\neq 1$, and multiplication over real numbers is associative. Since $1/c /neq = 0$, this undoing is also a row operation.\n    \n    \\item Adding a multiple $c$ of a row $r_0$ onto another row $r_x$.\n    \n        Such operation can be undone by adding the result row with $-cr_0$, since $\\forall c \\in \\mathbb{R}$, $-cr_0 + cr_0 + r_x = (-cr_0 + cr_0) + r_x = (-c+c)r_0 + r_x = r_x$, namely $-c$ is $c$'s inverse with $0$ being the identity, addition over vectors of real numbers is associative, and scaling of vectors of real numbers is distributive. Since $-cr_0$ is a multiple of $r_0$, this undoing is also a row operation.\n        \n    \\item Exchanging two rows.\n    \n    Exchanging them back. This is also a row reduction.\n  \\end{enumerate}\n  \n  Therefore, any row operation can be undone by another row reduction. \\rQED\n\\end{exercise}\n\n\\begin{exercise}{8}\n  Let the number of rows of $A$ be $n$. Since each row has at most one pivot, $\\widetilde{A}$ has at most $n$ pivots.\n  \n  Supposing that $\\widetilde{A}$ has $n$ pivots. Since each column has at most one pivot, the last column of $\\widetilde{A}$ has a pivot. Since each row must have exactly one pivot, the last row of $\\widetilde{A}$ has a pivot. Since the pivotal $1$ of a lower row is always to the right of the pivotal $1$ of a higher row, and the $n-1$-th rows have $n-1$ pivots, the last column of the last row of $\\widetilde{A}$ must be the pivot. Since the $n-1 \\times n-1$ matrix of the upper left part of $\\widetilde{A}$ has the rest $n-1$ pivots, with all those requirements still applied, the rightmost column's bottommost row is a pivot. Inductively, one can prove that all pivots lie on the orthogonal of $\\widetilde{A}$. Since in every column that contains a pivotal 1, all other entries are 0, $\\widetilde{A}$'s rest entries must be 0. Therefore, $\\widetilde{A}$ is an identity matrix.\n  \n  Supposing that $\\widetilde{A}$ has less than $n$ pivots. Since in every row, the first nonzero entry is $1$, there must be some rows consisting only 0, otherwise there will be $n$ pivots. Then, since any rows consisting entirely of $0$'s are at the bottom, such $\\widetilde{A}$'s bottom row must be all $0$. Therefore, $\\widetilde{A}$ is either the identity or the last row is a row of zeros. \\rQED\n\\end{exercise}", "meta": {"hexsha": "293435fa81268af9b9c109e1ebfa734160d9763e", "size": 6093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW4/sec0201.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/sec0201.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/sec0201.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": 65.5161290323, "max_line_length": 880, "alphanum_fraction": 0.5791892335, "num_tokens": 2905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7853085834000791, "lm_q1q2_score": 0.6751013221133418}}
{"text": "\\section{Relations}\n\n\\begin{definition}\n  A \\textbf{relation} on a set $A$ is a subset $C$ of the cartesian product $A \\times A$.\n\n  For a relation $C$ on $A$, we use the notation $xCy$ to mean $(x, y) \\in C$, or ``$x$ is in the relation $C$ to $y$.''\n\\end{definition}\n\n\\begin{definition}\n  An \\textbf{equivalence relation} on a set $A$ is a relation $C$ on $A$ having the following 3 properties: (we use $\\sim$ to denote the equivalence relation)\n  \\begin{enumerate}\n    \\item Reflexivity: $xCx \\quad \\forall x \\in A$ ($x \\sim x$)\n    \\item Symmetry: If $xCy$ then $yCx$ ($x \\sim y \\implies y \\sim x$)\n    \\item Transitivity: If $xCy$ and $yCz$ then $xCz$ ($x \\sim y \\land y \\sim z \\implies x \\sim z$)\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\n  We call a subset of $E$ of $A$ the \\textbf{equivalence class} determined by $x$ as the equation\n  \\begin{equation}\n    E = \\pbrac{\n      y \\mid y \\sim x\n    }\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n  A \\textbf{partition} of a set $A$ is a collection of disjoint nonempty subsets of $A$ whose union is all of $A$.\n\\end{definition}\n\n\\begin{definition}\n  A relation $C$ on a set $A$ is called an \\textbf{order relation} if it has the following properties:\n  \\begin{enumerate}\n    \\item Comparability: For every $x, y \\in A$ for which $x \\neq y$, either $xCy$ or $yCx$\n    \\item Nonreflexitivity: For no $x \\in A$ does $xCx$ hold\n    \\item Transtivity: If $xCy$ and $yCz$ then $xCz$\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\n  if $X$ is a set and $<$ is an order relation on $X$, and if $a<b$, we use the notation $(a, b)$ to denote the set\n  \\begin{equation}\n    \\pbrac{\n      x \\mid a < x < b\n    };\n  \\end{equation}\n  it is called an \\textbf{open interval} in $X$. If this set if empty, we call\n  \\begin{itemize}\n    \\item $a$ the \\textbf{immediate predecessor} of $b$\n    \\item $b$ the \\textbf{immediate successor} of $a$\n  \\end{itemize}\n\\end{definition}\n\n\\begin{definition}\n  Suppose $A, B$ are two sets with order relations $<_A$ and $<_B$ respectively. We say that $A, B$ have the same \\textbf{order type} if there is a bijective correspondence between them that preserves order; that is, if there exists a bijective function $f : A \\to B$ such that\n  \\begin{equation}\n    a_1 <_A a_2 \\implies f(a_1) <_B f(a_2)\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n  An ordered set $A$ has the \\textbf{least upper bound property} if every\n  nonempty subset $A_0$ of $A$ that is bounded above has a least upper bound.\n  Analogously, the set $A$ is said to have the \\textbf{greatest lower bound\n  property} if every nonempty subset $A_0$ of $A$ that is bounded below has a\n  greatest lower bound.\n\\end{definition}\n\n\\section*{Exercises}\n\n\\bx{\n  Check equivalence relation:\n  \\begin{itemize}\n    \\item Reflexivity is obvious\n    \\item Equality is symmetric, so the relation is too\n    \\item Equality is transitive, so the relation is too\n  \\end{itemize}\n\n  This looks like a bunch of parabolas of the form $y = x^2 + C$ on the plane, see figure \\ref{chap1:sec3:p1:fig:1}\n\n  \\begin{figure}[H]\n    \\centering\n    \\def\\domainSize{2}\n    \\begin{tikzpicture}\n      \\begin{axis}[\n        axis y line = middle,\n        axis x line = middle,\n      ]\n\n      \\addplot[\n        color=red,\n        ultra thick,\n        domain=-\\domainSize:\\domainSize,\n        samples=100\n      ]{\n        x^2\n      };\n\n      \\addplot[\n        color=blue,\n        ultra thick,\n        domain=-\\domainSize:\\domainSize,\n        samples=100\n      ]{\n        x^2 + 0.25\n      };\n\n      \\addplot[\n        color=green,\n        ultra thick,\n        domain=-\\domainSize:\\domainSize,\n        samples=100\n      ]{\n        x^2 + 0.5\n      };\n\n      \\addplot[\n        color=black,\n        ultra thick,\n        domain=-\\domainSize:\\domainSize,\n        samples=100\n      ]{\n        x^2 + 0.75\n      };\n\n      \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Plotting the partition defined by the equivalence relation}\n    \\label{chap1:sec3:p1:fig:1}\n  \\end{figure}\n}\n\n\\bx{\n  Reflexivity will still hold in $A_0$, since $A_0 \\in A$, and $C$ applies\n  to any element $x \\in A$.\n  Symmetry still holds, since $x, y \\in A$, and transitivity also holds since\n  $x, y, z \\in A$. The idea is that $A_0$'s elements are contained in $A$, so\n  all the equivalence relation properies still hold.\n}\n\n\\bx{\n  We are assuming $\\exists b$ such that $aCb$. If there is no such $b$, then we do not have $aCa$.\n}\n\\bx{\n  \\item \\ea{\n    \\item Let us check the properties\n    \\begin{itemize}\n      \\item Reflexive: $f(a) = f(a)$ is trivial\n      \\item Symmetric: If we have $f(a) = f(b)$, then $f(b) = f(a)$\n      \\item Transitive: Equality is transitive, so this also holds\n    \\end{itemize}\n\n    \\item $A^\\ast$ is a partition of $B$, so a bijective correspondence exists.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item $S'$ is an equivalence relation because we can imagine partitions of\n    $y - x = z$ for $z \\in \\mathbb{Z}$.\n    In $S$, we notice that $y - x = 1$, and $1 \\in \\mathbb{Z}$, so we know every\n    relation in $S$ is also in $S'$, therefore $S \\subset S'$.\n    See \\ref{chap1:sec3:p5:fig:1} for how to visualize these equivalence\n    classes.\n    \\begin{figure}[H]\n      \\centering\n      \\def\\domainSize{2}\n      \\begin{tikzpicture}\n        \\begin{axis}[\n          axis y line = middle,\n          axis x line = middle,\n        ]\n\n        \\addplot[\n          color=green,\n          ultra thick,\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x - 0.2\n        };\n\n        \\addplot[\n          color=blue,\n          ultra thick,\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x - 0.1\n        };\n\n        \\addplot[\n          color=red,\n          ultra thick,\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x\n        };\n\n        \\addplot[\n          color=blue,\n          ultra thick,\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x + 0.1\n        };\n\n        \\addplot[\n          color=green,\n          ultra thick,\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x + 0.2\n        };\n\n        \\addplot[\n          color=black,\n          ultra thick,\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x + 0.3\n        };\n\n        \\end{axis}\n      \\end{tikzpicture}\n      \\caption{Plotting the partition defined by the equivalence relation}\n      \\label{chap1:sec3:p5:fig:1}\n    \\end{figure}\n\n    \\item If their intersection is empty, then this is trivially true.\n\n    Otherwise, if we have some nonempty intersection, since we know any elements\n    in this intersection are also part of some equivalence relation, all the\n    equivalence relation properties apply, so this intersection is also an\n    equivalence relation on $A$.\n\n    \\item \\TODO: I'm pretty confused about this question. Wouldn't the intersection of all equivalence relations that contain $S$ just end up with $S$?\n  }\n}\n\n\\bx{\n  Showing it is an order relation\n  \\begin{itemize}\n    \\item Comparability: Per the rule, we will always have $xCy$ or $yCx$.\n    \\item Nonreflexitivity: We have a tiebreaker rule that prevents $xCx$.\n    \\item Transitivity: Intuitively, there is an ordering at the highest level\n    with $y-x^2$ value. If there are ties there, we check with $x$ values for\n    ordering.\n  \\end{itemize}\n\n  Yeah sorry I didn't feel like doing the order relation formally, but hopefully\n  the geometric solution can help explain more. There's just a lot of casework\n  and mundane proof so I didn't feel like writing it out.\n\n  Geometrically, this is like the partition in \\ref{chap1:sec3:p1:fig:1}, except\n  parabolas that are higher up are ordered ``higher''. Within a parabola, the\n  values on the left are less than the values on the right.\n}\n\n\\bx{\n  A restriction is a subset of the larger set, so all the order relation properties will still hold.\n}\n\n\\bx{\n  I assume the author wants us to check the $x^2 < y^2$, if $x^2 = y^2$, then $x < y$.\n\n  \\begin{enumerate}\n    \\item Comparability: If $x^2 \\neq y^2$, either $x^2 < y^2$ or $x^2 > y^2$.\n    If $x^2 = y^2$, then it must be the case that $x, y \\neq 0$, and one of $x,\n    y$ is negative and the other positive, so we either have $x > y$ or $x < y$.\n\n    \\item Nonreflexitivity: $xCx$ means $x^2 = x^2$, so we would check $x < \\text{ or } > x$, but this is not possible since $x = x$.\n    \\item Transitivity: If $xCy$ then $x^2 < y^2$ or $x < y$, and if we have\n    $yCz$ then $y^2 < z^2$ or $y < z$. In all cases, we can conclude $x^2 < z^2$\n    or $x < z$. I'm being lazy with casework here.\n  \\end{enumerate}\n}\n\n\\bx{\n  We want to check that a dictionary order relation is an order relation.\n\n  \\begin{enumerate}\n    \\item Comparability: For any two $(a_1, b_1), (a_2, b_2)$, we have 2 cases:\n      \\begin{enumerate}\n        \\item $a_1 <_A a_2$ or $a_2 <_A a_1$ since $<_A$ is an order relation on $A$.\n        Then we know $(a_1, b_1) < (a_2, b_2)$ or $(a_1, b_1) > (a_2, b_2)$.\n        \\item $a_1 = a_2$. Then we use the same argument with $b_1, b_2$, that\n        either $b_1 <_B b_2$ or $b_2 <_B b_1$, which then shows the\n        corresponding $<$ and $>$ on the tuple.\n      \\end{enumerate}\n\n    \\item Nonreflexitivity: if we have some $(a, b)$, we know by $<_A$ that $a\n    <_A a$ does not hold, so the overall order relation is not possible.\n\n    \\item Transitivity: If we have $(a_1, b_1) < (a_2, b_2) < (a_3, b_3)$, then we have 2 cases for the first tuple, and 2 cases for the second tuple.\n    \\begin{enumerate}\n      \\item $a_1 <_A a_2 <_A a_3$: then we can use the transitive property of $<_A$\n      \\item $a_1 <_A a_2 = a_3$: we can see that $a_1 <_A a_3$\n      \\item $a_1 = a_2 <_A a_3$:  we can see that $a_1 <_A a_3$\n      \\item $a_1 = a_2 = a_3$: then we must have $b_1 <_B b_2 <_B b_3$, so we can use the transitive property of $<_B$\n    \\end{enumerate}\n  \\end{enumerate}\n}\n\n\\bx{\n  \\begin{itemize}\n    \\item One way to see that this is an order preserving function is that the derivative is always positive between $(-1, 1)$,\n    \\begin{equation*}\n      f'(x) = \\frac{\n        x^2 + 1\n      }{\n        \\pa{1-x^2}^2\n      },\n    \\end{equation*}\n    which means the function is monotonically increasing, and thus will preserve the order, since monotonically increasing functions have the property that\n    \\begin{equation*}\n      a < b \\implies f(a) < f(b).\n    \\end{equation*}\n\n    \\item This is just an algebra exercise...pretty easy to verify\n  \\end{itemize}\n}\n\n\\bx{\n  \\AFSOC there is more than one immediate successor to some $a$, call them $b$ and $c$. Then by order set properties, we know that either $b < c$ or $c < b$.\n  In either case, we end up finding that $b$ or $c$ cannot be immediate successors, since for example, if $b < c$, we have that $(a, c)$ is not empty.\n\n  The argument for immediate predecessor is symmetric to this argument.\n\n  To show there can only be one smallest element, we can \\AFSOC there is more\n  than one. If we call these $a, a'$, we know from ordering properties that WLOG\n  $a < a'$, then $a'$ is not the smallest element, so this is a contradiction.\n\n  The argument for the largest element is symmetric.\n}\n\n\\bx{\n  \\begin{enumerate}[label=(\\roman**)]\n    \\item Every element has an immediate predecessor. For some $(x, y)$, the\n    immediate predecessor is $(x, y+1)$.\n    There is no smallest element, since you can always find a smaller element,\n    i.e. for any $(x, y)$, $(x-1, y) < (x, y)$.\n\n    \\item The immediate predecessor for some $(x, y)$ is $(x+1, y+1)$. There is\n    no smallest element, since you can always find $(x-1, y) < (x, y)$ for any\n    $(x, y)$.\n\n    \\item The immediate predecessor for some $(x, y)$ is $(x-1, y+1)$. There is\n    no smallest element, since for any $(x, y)$, you have $(x-1, y) < (x, y)$.\n  \\end{enumerate}\n\n  Not rigorous, but geometrically, the first ordering is like a zigzag on the\n  plane, the second one is like $y = x + C$, and the third is $y = -x + C$, so\n  these orderings are all different.\n}\n\n\\bx{\n  Suppose $A$ has the least upper bound property, meaning every nonempty subset\n  $A_0$ of $A$ is bounded above by some least upper bound.\n  \\AFSOC $A$ does not have the greatest lower bound property, that is $\\exists\n  A_1 \\subset A$ such that $A_1$ does not have a greatest lower bound.\n  If this is the case, then consider the lower bound $a$ for this set $A_1$, and\n  consider the set $A_2$, which we define as\n  \\begin{equation*}\n    A_2 = \\pbrac{a' \\mid a' \\geq a}\n  \\end{equation*}\n  Notice that $A_2$ cannot be empty, or else $a$ is the only, and therefore greatest lower bound for $A_1$.\n  Now, from the definition of $A_2$, we can see that $a$ is an upper bound for\n  $A_2$. However, we now claim that there is no least upper bound for $A_2$.\n  Because if there were, call it some $a_2$, then $a_2$ would be the greatest\n  lower bound for $A_1$, since $a_2$ is larger than all lower bounds of $A_1$.\n  This is a contradiction, since we assumed that $A_1$ does not have a greatest lower bond.\n  Therefore, we must conclude that every subset of $A$ has a greatest lower bound.\n}\n\n\\bx{\n  \\ea{\n    \\item If $C$ is symmetric, then $(a, b) \\in C \\implies (b, a) \\in C$, which means $D \\subset C$.\n\n    If $C = D$, then $(a, b) \\in C \\implies (b, a) \\in D = C$, so therefore $C$ is symmetric.\n\n    \\item We will check the order relation properties for $D$\n    \\begin{enumerate}\n      \\item Comparability: For any $(b, a) \\in D$, we know $(a, b) \\in C$, so we\n      know either $b < a$ or $a < b$.\n      \\item Nonreflexitivity: $(b, b) \\in D$ would imply $(b, b) \\in C$, but $C$\n      is an order relation so this is not possible.\n      \\item Transitivity: $(c, b) \\in D, (b, a) \\in D$. We know that $(a, b),\n      (b, c) \\in C$, so we know $(a, c) \\in C$, so therefore $(c, a) \\in D$,\n      which proves transitivity.\n    \\end{enumerate}\n\n    \\item The other direction of the argument is symmetric.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item Let us show that\n    \\begin{itemize}\n      \\item 1 is the least upper bound for $[0, 1]$. We can see this because if\n      you pick any smaller of an upper bound $u$, $u < 1$ and thus is not an\n      upper bound for the set.\n\n      \\item 1 is the least upper bound for $[0, 1)$. Suppose we have some other\n      least upper bound $u$ such that $x \\in [0, 1), x \\leq u$, but $u < 1$.\n      Then consider $u' = u + \\epsilon/2$, where $\\epsilon = \\frac{1-u}{2}$.\n      Then $u'$ is $<1$ but $u' > u$ and is also an upper bound, which means $u$\n      was not the least upper bound. Therefore we have reached a contradiction\n      and conclude that 1 is the least upper bound.\n    \\end{itemize}\n\n    \\item $[0, 1] \\times [0, 1]$ with dictionary ordering has least upper bound property.\n    This is because for any subset, if we look at the first coordinate, it is in\n    $[0, 1]$, which we showed has the least upper bound property, so call this\n    upper bound $u_1$.\n    Similarly, for the second coordinate it is also in $[0, 1]$, so we have a\n    least upper bound $u_2$ for this coordinate.\n    Then we have $(u_1, u_2)$ is a least upper bound for any subset in $[0, 1] \\times [0, 1]$.\n\n    This argument holds for $[0, 1] \\times [0, 1)$ and $[0, 1) \\times [0, 1]$.\n  }\n}", "meta": {"hexsha": "375a090e57cc5b610c75d80d1899f6e6fb06d85d", "size": 15288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1/chapter1-3.tex", "max_stars_repo_name": "mikinty/Topology-Munkres-Solutions", "max_stars_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T04:11:03.000Z", "max_issues_repo_path": "chapters/chapter1/chapter1-3.tex", "max_issues_repo_name": "mikinty/Topology-Munkres-Solutions", "max_issues_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1/chapter1-3.tex", "max_forks_repo_name": "mikinty/Topology-Munkres-Solutions", "max_forks_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8032786885, "max_line_length": 277, "alphanum_fraction": 0.6230376766, "num_tokens": 4839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.6751013199535906}}
{"text": "\\documentclass[final]{siamart171218}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{bm}\n\n\\setlength{\\oddsidemargin}{0.65in}\n\\setlength{\\evensidemargin}{0.65in}\n\n\\title{Sketch of the ``alternating SQP'' method for fitting Poisson\n  topic models}\n\n\\author{Peter Carbonetto\\thanks{Dept. of Human Genetics and the Research Computing Center, University of Chicago, Chicago, IL}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Problem statement}\n\nGiven an $n \\times p$ matrix of counts $X$ with entries $x_{ij} \\geq\n0$, the aim is to fit a Poisson model of the counts,\n\\begin{align}\np(x) &= \\prod_{i=1}^n \\prod_{j=1}^p p(x_{ij}) \\nonumber \\\\\n     &= \\prod_{i=1}^n \\prod_{j=1}^p \\mathrm{Poisson}(x_{ij}; \\lambda_{ij}),\n\\label{eq:poisson-likelihood}\n\\end{align}\nin which the Poisson rates are given by $\\lambda_{ij} = \\sum_{k=1}^K\nl_{ik} f_{jk}$. The model is determined by a $p \\times K$ matrix $F$\nwith entries $f_{ik} \\geq 0$ (the ``factors'') and an $n \\times K$\nmatrix $L$ with entries $l_{ik} \\geq 0$ (the ``loadings''). Fitting\n$F$ and $L$ is equivalent to non-negative matrix factorization with\nthe ``beta-divergence'' cost function \\cite{lee-2001}. It can also be\nused to recover a maximum-likelihood estimate for the latent Dirichlet\nallocation (LDA) model \\cite{blei-2003}. So fitting this model is\nuseful for a wide range of applications.\n\nThe log-likelihood for the Poisson model is\n\\begin{equation}\n\\log p(x \\,|\\, F, L) \\propto\n  \\sum_{i=1}^n \\sum_{j=1}^p x_{ij} \\log\n  ({\\textstyle \\sum_{k=1}^K l_{ik} f_{jk}})\n    - \\sum_{i=1}^n \\sum_{j=1}^p \\sum_{k=1}^K l_{ik} f_{jk},\n\\label{eq:poisson-log-likelihood}\n\\end{equation}\nwhere the constant of proportionality is obtained from factorial terms\nin the Poisson densities. Our specific aim is to find a $F$ and $L$\nthat maximizes the log-likelihood \\eqref{eq:poisson-log-likelihood};\nthat is, we would like to solve\n\\begin{equation}\n\\begin{array}{ll}\n\\mbox{minimize} & \\ell(F,L) \\equiv -\\log p(x \\,|\\, F, L) \\\\\n\\mbox{subject to} & F \\geq 0, L \\geq 0.\n\\end{array}\n\\label{eq:problem}\n\\end{equation}\nIn the next section, we derive an efficient approach to doing this.\n\n\\section{Block co-ordinate descent strategy}\n\nOur strategy for solving \\eqref{eq:problem} is to alternate between\nsolving for $F$ with $L$ fixed, and solving for $L$ with $F$\nfixed. When solving for $F$ with $L$ fixed (and vice versa), the\nproblem naturally decomposes into a collection of much smaller\nsubproblems that are much more tractable to solve. All the subproblems\nare of the following form:\n\\begin{equation}\n\\begin{array}{ll}\n\\mbox{minimize} & \\phi(y; B, w) \\\\\n\\mbox{subject to} & \\mbox{$y_k \\geq 0$ for all $k = 1, \\ldots, K$},\n\\end{array}\n\\label{eq:subproblem}\n\\end{equation}\nin which the objective function is defined as\n\\begin{equation}\n\\phi(y; B, w) =\n    - \\sum_{i=1}^n w_i \\log\\big({\\textstyle \\sum_{k=1}^K b_{ik} y_k}\\big)\n    + \\sum_{i=1}^n \\sum_{k=1}^K b_{ik} y_k.\n\\label{eq:subproblem-objective}\n\\end{equation}\nTo see the connection between subproblem \\eqref{eq:subproblem} and the\noriginal optimization problem \\eqref{eq:problem}, observe that the\nnegative log-likelihood can be recovered as\n\\begin{equation}\n-\\log p(x \\,|\\, F, L) = \\sum_{i=1}^n \\phi(l_i; F, x_i),\n\\end{equation}\nwhere $x_i$ is the $i$th row of $X$ and $l_i$ is the $i$th row of $L$.\nAlternatively, it can be recovered as\n\\begin{equation}\n-\\log p(x \\,|\\, F, L) = \\sum_{j=1}^p \\phi(f_j; L, x_j),\n\\end{equation}\nin which $x_j$ is the $j$th column of $X$, and $f_j$ is the $j$th row\nof $F$. Therefore, when $F$ is fixed, each row of $L$ can be\nseparately optimized by solving a problem of the form\n\\eqref{eq:subproblem}, and when $L$ is fixed, each row of $F$ can be\nseparately optimized by solving a problem of the form\n\\eqref{eq:subproblem}.\n\nInitially this may seem like a sensible strategy, but directly\noptimizing \\eqref{eq:subproblem} turns out to be difficult to do for\nnumerical reasons: in practice, the entries of $B$ can be very large\nor very small, resulting in solutions $y$ in which all the entries are\neither very large or very small. This makes it difficult to devise an\nalgorithm that will work well for all possible input matrices $B$.\n\nI propose to solve for $y$ indirectly by instead solving\n\\begin{equation}\n\\begin{array}{ll}\n\\mbox{minimize}   & f(t; P, u) \\\\\n\\mbox{subject to} & \\mbox{$t_k \\geq 0$ for all $k = 1, \\ldots, K$},\n\\label{eq:subproblem-modified}\n\\end{array}\n\\end{equation}\nin which the new objective function is\n\\begin{equation}\nf(t; P, u) =\n    - \\sum_{i=1}^n u_i \\log\\big({\\textstyle \\sum_{k=1}^K p_{ik} t_k}\\big)\n    + \\sum_{k=1}^K t_k,\n\\end{equation}\nwhere I've defined\n\\begin{align*}\nu_i    &= \\frac{w_i}{\\sum_{i'=1}^n w_{i'}} \\\\\np_{ik} &= b_{ik} \\times \\frac{\\sum_{i'=1}^n w_{i'}}{\\sum_{i'=1}^n b_{i'k}}.\n\\end{align*}\nAfter finding the solution $t^{\\star}$ to\n\\eqref{eq:subproblem-modified}, the solution $y^{\\star}$ to\n\\eqref{eq:subproblem} is recovered as\n\\begin{equation}\ny_k^{\\star} = t_k^{\\star} \\times\n  \\frac{\\sum_{i=1}^n w_i}{\\sum_{i=1}^n b_{ik}}.\n\\end{equation}\nThe main advantage of solving \\eqref{eq:subproblem-modified} is that\nthe solution is numerically well behaved; in particular, the entries\nof the solution $t^{\\star}$ sum to 1 \\cite{kim-2019}. A\nstraightforward way to appreciate this result is to compare the\ncomplementary slackness condition $\\sum_{k=1}^K g_k x_k = 0$ for the\noriginal and modified subproblems, where $g_k$ denotes the partial\nderivative of the objective (either $\\phi$ or $f$) with respect to the\n$k$th co-ordinate (either $y_k$ or $t_k$). Further, since problem\n\\eqref{eq:subproblem-modified} is obtained by a simple linear\ntransformation of the variables, any iterate that leads to an\nimprovement in the solution to the modified subproblem will produce an\nimprovement in the solution to the original subproblem, and vice\nversa.\n\n\\section{Karush-Kuhn-Tucker conditions}\n\nTo assess the quality of a solution, here I derive the first-order\nKarush-Kuhn-Tucker (KKT) conditions for \\eqref{eq:problem}. Written\nin matrix notation, they are\n\\begin{align}\n\\nabla_F \\ell^{\\star}(F,L,\\Omega,\\Gamma) &= 0 \\label{eq:kkt-1} \\\\\n\\nabla_L \\ell^{\\star}(F,L,\\Omega,\\Gamma) &= 0 \\label{eq:kkt-2} \\\\\n\\Omega \\odot F &= 0 \\label{eq:kkt-3} \\\\\n\\Gamma \\odot L &= 0 \\label{eq:kkt-4}.\n\\end{align}\nHere, I have introduced matrices of Lagrange multipliers $\\Omega \\geq\n0, \\Gamma \\geq 0$ associated with the non-negativity constraints $F\n\\geq 0, L \\geq 0$, $A \\odot B$ is the Hadamard (elementwise) product\nof matrices $A$ and $B$, and $\\ell^{\\star}(F, L, \\Omega, \\Gamma)$ is the\nLagrangian function:\n\\begin{equation}\n\\phi(F, L, \\Omega, \\Gamma) = \\ell(F,L) \n- \\sum_{i=1}^n \\sum_{k=1}^K \\gamma_{ik} l_{ik}\n- \\sum_{j=1}^m \\sum_{k=1}^K \\omega_{jk} f_{jk}.\n\\end{equation}\nApplying conditions (\\ref{eq:kkt-1}, \\ref{eq:kkt-2}), we obtain\n\\begin{align}\n\\Omega &= (1 - A)^TL \\\\ \n\\Gamma &= (1 - A)F,\n\\end{align}\nin which $A$ is defined to be the $n \\times m$ matrix with entries\n$a_{ij} = x_{ij} / \\lambda_{ij}$. Next, applying the complementary\nconditions (\\ref{eq:kkt-3}, \\ref{eq:kkt-4}) results in the following\nexpressions for the residuals of the complementary conditions:\n\\begin{align}\nr_F &= F \\odot (1 - A)^TL \\\\\nr_L &= L \\odot (1 - A)F.\n\\end{align}\nThese residuals should vanish near a minimizer of \\eqref{eq:problem}.\n\n\\bibliographystyle{siamplain}\n\\bibliography{altsqp}\n\n\\end{document}\n\n", "meta": {"hexsha": "a62d3cb423d4b9b4e7c10f0ffd323892d797d5d5", "size": 7343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inst/derivations/altsqp/altsqp.tex", "max_stars_repo_name": "stephenslab/fastTopics", "max_stars_repo_head_hexsha": "b64d729c2938e763df5756781170510d5791ef92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2020-02-10T03:38:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T15:48:57.000Z", "max_issues_repo_path": "inst/derivations/altsqp/altsqp.tex", "max_issues_repo_name": "PeiKaLunCi/fastTopics", "max_issues_repo_head_hexsha": "9eda1f541cf9ed0371d022b09e7c70abc2681ebf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2020-04-28T18:27:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T13:02:36.000Z", "max_forks_repo_path": "inst/derivations/altsqp/altsqp.tex", "max_forks_repo_name": "PeiKaLunCi/fastTopics", "max_forks_repo_head_hexsha": "9eda1f541cf9ed0371d022b09e7c70abc2681ebf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-22T10:55:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-30T06:05:53.000Z", "avg_line_length": 39.4784946237, "max_line_length": 127, "alphanum_fraction": 0.703799537, "num_tokens": 2552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6751013186260781}}
{"text": "\\chapter{Heat}\n\nLet's say you put a 1 kg aluminum pan that is $80^\\circ$ C into\n3 liters of water that is $20^\\circ$ C. Energy, in the form of heat,\nwill be transferred from the pan to the water until they are at the same\ntemperature. (We call this ``thermal equilibrium.'')\\index{thermal equilibrium}\n\nWhat will the temperature of the water be?\n\n\\section{Specific Heat Capacity}\n\nIf you are heating something, the amount of energy you need to\ntransfer to it depends on three things: the mass of the thing you are\nheating, the amount of temperature change you want, and the\n\\textit{specific heat capacity} of that substance.\\index{specific heat capacity}\n\n\\begin{mdframed}[style=important, frametitle={Energy in Heat Transfer}]\n\n  The energy moved in a heat transfer is given by\n\n  $$E = m c \\Delta_T$$\n\n  where $m$ is the mass, $\\Delta_T$ is the change in temperature, and\n  $c$ is the specific heat capacity of the substance.\n% ADD: q=mcat\n\n  (Note that this\n  assumes no phase change. For example, this formula works nicely on\n  warming liquid water, but it gets more complicated if you warm the\n  water past its boiling point.)\n\n\\end{mdframed}\n\nCan we guess the specific heat capacity of a substance? It is very,\nvery difficult to guess the specific heat of a substance, so we determine\nit by experimentation.\n\nFor example, someone determined that it took about 0.9 joules to raise\nthe temperature of solid aluminum one degree Celsius. So we say ``The\nspecific heat capacity of aluminum is 0.9 J/g $^\\circ$C.''\n\nThe specific heat capacity of liquid water is about 4.2 J/g $^\\circ$C.\n\nTo answer the question, then, the amount of energy given off by the\npan must equal the amount of energy absorbed by the water. And they\nneed to be the same temperature at the end.  Let $T$ be the final\ntemperature of both.\n\n\\includegraphics[width=0.8\\textwidth]{Specific_Heat_Diagram.png}\n\n% KA: https://www.khanacademy.org/science/ap-chemistry-beta/x2eef969c74e0d802:thermodynamics/x2eef969c74e0d802:heat-capacity-and-calorimetry/v/heat-capacity\n\n\nThree liters of water weighs 3,000 grams, so the\nchange in energy in the water will be:\n\n$$E_W = m c \\Delta_T = (3000)(4.2)(T - 20) = 12600T - 252000 \\text{ joules}$$ \n\nThe pan weighs 1000 grams, so the change in energy in the pan will be::\n\n$$E_P = m c \\Delta_T = (1000)(0.9)(T - 80) = 900T - 72000 \\text{ joules}$$\n\nTotal energy stays the same so $E_W + E_P = 0$.  So you need to solve\n\n$$(12600T - 252000) + (900T - 72000) = 0$$\n\nAnd find that the temperature at equilibrium will be\n\n$$T = 24^\\circ \\text{C}$$\n\n\\begin{Exercise}[title={Thermal Equilibrium}, label=thermal_equilibrium]\n\nJust as you put the aluminium pan in the water as described above,\nsomeone also puts a 1.2 kg block of copper cooled to 10 $^\\circ$ C.\nThe specific heat of solid copper is about 0.4 J/g $^\\circ$C.\n\nWhat is the new temperature at equilibrium?\n\n\\end{Exercise}\n\\begin{Answer}[ref=thermal_equilibrium]\n\n  $$E_C = (1200)(0.4)(T - 10) = 480T - 4800$$\n\nTotal energy stays constant:\n\n$$0 = (12600T - 252000) + (900T - 72000) + (480T - 4800)$$\n\nSolving for $T$ gets you $T = 23.52^\\circ$ C.\n\n\\end{Answer}\n\n\\section{Getting to Equilibrium}\n\nWhen two objects with different temperatures are touching, the speed\nat which they exchange heat is proportional to the differences in\ntheir temperatures. Thus, as their temperatures get closer together,\nthe heat exchange slows down.\n% ADD: explain which object, water or metal has a greater tempature change\n\nIn our example, the pan and the water will get close to equilibrium\nquickly, but they may never actually reach equilibrium.\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=0,xmax=4.25,\n        ymin=15,ymax=85,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={minutes},\n        ylabel={degrees celsius},\n        ]\n        \\addplot[no marks,sdkblue] expression[domain=0:4,samples=100]{24 + 56 * pow(2,-1.5 * x)} node[above, xshift=-1cm, yshift=0.1cm]{Pan}; \n        \\addplot[no marks,sdkblue] expression[domain=0:4,samples=100]{24 - 4 * pow(2,-0.8 * x)} node[below, xshift=-2.5cm]{Water};\n        \\addplot[no marks,dashed,gray] coordinates {(0,24)(6,24)} node[above, xshift=-8cm]{equilibrium};\n    \\end{axis}\n\\end{tikzpicture}\n\n\\begin{Exercise}[title={Cooling Your Coffee}, label=cool_coffee]\n\n  You have been given a ridiculously hot cup of coffee and a small pitcher of chilled milk.\n\n  You need to start chugging your coffee in three minutes, and you want it as cool as possible at that time. When should you add the milk to the coffee?\n\n\\end{Exercise}\n\\begin{Answer}[ref=cool_coffee]\n\n  During the 3 minutes, you want the coffee to give off as much of its\n  heat as possible, so you want to maximize the difference between the\n  temperature of the coffee and the temperature of the room around\n  it.\n\n  You wait until the last moment to put the milk in.\n\n\\end{Answer}\n\n\\section{Specific Heat Capacity Details}\n\nFor any given substance, the specific heat capacity often changes a\nlot when the substance changes state. For example, ice is 2.1 J/g\n$^\\circ$C, whereas liquid water is 4.2 J/g$^\\circ$C.\n% KA: https://www.khanacademy.org/science/biology/water-acids-and-bases/water-as-a-solid-liquid-and-gas/v/specific-heat-of-water\n\nEven within a given state, the specific heat capacity varies a bit\nbased on the temperature and pressure. If you are trying to do these\nsorts of calculations with great accuracy, you will want to find the\nspecific heat capacity that matches your situation. For example, I\nmight look for the specific heat capacity for water at $22^\\circ$C at\n1 atmosphere of pressure( atm).\n\n", "meta": {"hexsha": "0ce51b38b18d6e7cf906c7216b94b1d9d63ee008", "size": 5627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/heat-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/heat-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/heat-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": 37.2649006623, "max_line_length": 156, "alphanum_fraction": 0.7318286831, "num_tokens": 1575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7905303285397348, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.6750439247267324}}
{"text": "\\section{Recap}\nSuppose you have a box at temperature $T$.\nMaxwell equations gives you $\\vec{A}(\\vec{r}, t)$,\nwhich has a lot of degrees of freedom.\nThe Lagrangian is\n\\begin{align}\n    L_0 &=\n    \\frac{1}{8\\pi} \\int d^3r \\left[ \n    \\left( \\frac{\\partial A}{c\\partial t} \\right)^2\n    - \\left( \\vec{\\nabla}\\times \\vec{A} \\right)^2\n    \\right]\n\\end{align}\nThere is some exercise to show this is equivalent to Maxwell's equations,\nbut that is a classical physics problem.\nYou could keep going and find the classical Hamiltonian,\nwhich you know how to find and is a function of the degrees of freedom $\\vec{A}$\nand their canonical momentum $\\Pi$.\n\\begin{align}\n    H &= \n    \\frac{1}{8\\pi}\n    \\int d^3 r\\, \\left[ \n    \\left( 4\\pi c \\right)^2 \n    \\Pi^2 (r, t)\n    + \\left( \\vec{\\nabla}\\times\\vec{A}  \\right)^2\n    \\right]\n\\end{align}\nwhere the canonical momenta are\n\\begin{align}\n    \\Pi(\\vec{R}, t) &=\n    \\frac{\\partial L}{\\partial A(\\vec{r}, t)}\n\\end{align}\nIt's an infinite-dimensional phase space but that's okay.\nIt's a quadratic Hamiltonian,\nso you can carry out all the calculations.\nThe way to do this is that you have to go to normal coordinates.\nIf I had only terms like $A^2(\\vec{R})$,\nit only couples to itself.\nBut since there are derivatives of $A$,\nI have terms like\n$\\left( A(\\vec{r} + d\\vec{r}, t) - A(\\vec{r}, t) \\right)^2$,\nwhich is very similar to the chain of masses connected by springs\nwith $-k(x_1 - x_2)^2$.\nIf you remember the normal coordinates of the mass and springs system,\nyou just take the Fourier transform to decouple the Fourier modes to get the\nnormal coordinates.\n\nAgain,\nfor the electromagnetic field,\nI can write the transformation to normal coordinates like\n\\begin{align}\n    A(\\vec{r},t) &=\n    \\sqrt{4\\pi c}\n    \\sum_{\\vec{k}}\n    e^{i\\vec{k}\\cdot\\vec{r}} Q(\\vec{k}, t)\n\\end{align}\nwhere $Q$ are the cavity modes inside the box,\nand the wave vectors are of the form\n\\begin{align}\n    \\vec{k} &= \\frac{2\\pi}{L} \\vec{n}\n\\end{align}\nwhere $\\vec{n}$ are vectors with integer components.\nThen the canonical momenta are\n\\begin{align}\n    \\Pi(\\vec{r}, t) &=\n    \\frac{1}{\\sqrt{V}\\sqrt{4\\pi c}} \\sum_{\\vec{k}}\n    e^{i\\vec{k}\\cdot\\vec{r}} P(\\vec{k}, t)\n\\end{align}\nand now the degrees of freedom are decoupled and I can calculate the partition\nfunction in my head.\n\nWhen we found the Lagrangian,\nwe picked a certain gauge,\nthat is divergence of the potential is zero and the curl of $A$ is zero,\nso what extra constraints do we have?\n\\begin{align}\n    \\nabla\\cdot A &= 0\n    \\implies\n    \\vec{k}\\cdot\\vec{Q}(\\vec{k}, t) = 0\n\\end{align}\nwhich means one less degree of freedom,\nso electromagnetic waves are not longitudinal.\nIt's hard to do the counting,\nbut I start with a real vector $A$,\nand I'm left with a complex $Q$,\nso the degrees of freedom doubles,\nbut that can't be.\nThe trick here is that because $A$ is real,\nthat implies something about these $Q$'s.\n\\begin{align}\n    \\vec{Q}(k) = \\vec{Q}^*(-k)\n\\end{align}\nwhich is because if you take the complex conjugate of the definition,\nyou should get the same thing for $-k$.\nAnd the same thing applies for the $\\vec{P}$.\nOne way of thinking is that if I know the real value of $Q$,\nI also know its imaginary value,\nso I don't double the number of degrees of freedom,\nit's the same.\n\nThis transformation is canonical because it satisfies certain conditions you\nshould know from Chacko's class.\nI am allowed to do this and what's going to happen is that I'm going to find out\nthen what my Hamiltonian is going to look like in terms of $P$ and $Q$.\n\\begin{align}\n    H &= \\frac{1}{2} \\sum_{\\vec{k}}\\left[ \n    \\vec{P}(\\vec{k}, t)\\cdot\\vec{P}^*(\\vec{k}, t)\n    + c^2 k^2 \\vec{Q}(\\vec{k}, t)\\cdot \\vec{Q}^*(\\vec{k}, t)\n    \\right]\n\\end{align}\nBefore the $A$'s of neighbouring parts are coupled,\nbut now they are not.\nA valid $k$ is not next to any other valid $k$,\njust a sum of completely independent parts,\none for each $k$.\nOne harmonic oscillator for every value of $k$.\n\nI don't know if you know that,\nbut EM an all that complication with curls and divergences,\nis just a bunch of this.\n\nDo you recognize this?\n\\begin{align}\n    H &= \\frac{1}{2}p^2 + \\frac{1}{2}q^2\n\\end{align}\nThat's a harmonic oscillator.\nThis is for many oscillators.\n\\begin{align}\n    H &= \\sum_{i}\\frac{1}{2}p_i^2 + \\frac{1}{2}q_i^2\n\\end{align}\nAnd the EM Hamiltonian is just an infinite number of oscillators.\n\nInteresting thing to observe is that it tells us the frequency of each mode.\n$c^2 k_^2 = \\omega^2$.\nIf you calculate the velocity of the waves,\nyou get the velocity of the light $c$,\nwhich is the same for any wavelength of light.\nIt's much like low-momentum phonons.\n\nNote that I could have written\n\\begin{align}\n    \\vec{P}\\cdot\\vec{P} =\n    \\left( \\Re P \\right)^2 + \\left( \\Im P \\right)^2\n\\end{align}\n\nSo I'm done right?\n\nI can find classically what the average energy is going to be.\nBy equipartition,\nI should have $\\frac{1}{2}k_BT$ for every quadratic term in the Hamiltonian.\n\\begin{align}\n    E &= \\sum_{\\vec{k}}\\frac{1}{2}k_B T\\left( \n    \\underbrace{2}_{\\textrm{``kinetic'' + ``potential''}}\n    + \\underbrace{2}_{\\textrm{polarization}}\n    \\right) = \\infty\n\\end{align}\nOnly the transverse polarizations survives because\n$vec{k}\\cdot\\vec{Q}=0$,\nso you only have 2 polarizations.\nClassically,\nthe energy does not depend on the frequency of the oscillators.\nDifferently from the phonons though,\nthis never ends,\nbecause the maximum $k$ you could have is $\\pi/a$,\nbut there is no lattice spacing $a$,\nso this sum diverges!\n\nIt diverges because it can have modes of arbitrarily small wavelengths and each\none contributes exactly the same.\n\nAnd so of course,\nthis is the famous ultraviolet catastrophe.\nThat's how quantum mechancis was invinented.\nThey did this calculation,\nthe result was not just slightly wrong,\nbut profoundly wrong.\nAnd there you go.\n\nThere are some steps,\nyou may ask why you should believe,\nbut there is a reason to believe that this result is off because it's infinitely\noff.\n\nThe reason is this.\nSuppose now that you calculate the energy for a particular magnitude of\n$k=|\\vec{k}|$,\nwhich corresponds to many different $k$ on a sphere of that radius.\nThen you could try to calculate the energy density.\n\nIt's hard to do the sum because it lives on lattice,\nbut for large $k$,\nyou can do an approximation.\n\n\\begin{align}\n    \\frac{E}{V} &=\n    =\n    \\frac{2k_B T}{2\\pi^2} \\int_{0}^{\\infty} dk\\, k^2\\\\\n    &=\n    \\frac{8 k_B T \\pi}{c^3} \\int_{0}^{\\infty} d\\nu\\, \\nu^2\n\\end{align}\nand if we define the Rayleigh-Jeans density\n\\begin{align}\n    u_T(\\nu) &= \\frac{8 k_B T \\pi}{c^3} \\nu^2,\n\\end{align}\nwe find $u_T(\\nu)$ is a quadratic.\nAt the time,\npeople did precise measurements of this thing.\nI don't know how did this,\nbut I don't know how they measured the energy so precisely.\nBut they did it,\nand then know that the correct curve was not quadratic.\nThey knew that it increased, peaked,\nthen decreased.\n\nHowever,\nthey kind of agreed in the low-$\\nu$ limit.\nSo they got something right.\n\nAnd we know why.\nIt's because small frequencies corresponds to bulk quantum energies in the\nregime\n\\begin{align}\n    k_B T \\gg \\hbar \\omega.\n\\end{align}\nHowever, for large $\\nu$,\nthis is violated,\nand those high-frequency modes are actually frozen,\nand we no longer satisfy the equipartition theorem.\n\nThat just tells you our story nowadays.\n\nLet's take this Hamiltnoian here and don't treat it classically.\nThe same way that you have a particle moving on line,\nyou make the coordaintea nd mometa ot be operaotr,s\nadn you know they have acertain commutation relation,\nall that thing holds true,\nexcept that you have an $a$ and $a^\\dagger$\nfor every polarziation Foufier mode.\nI'm not going to do this because we don't have the time,\nbut this is what we call \\emph{quanutm field theory},\nwhere you take a classical field,\napply quantum mechanicss to it.\nthe states of hte field are interpeted as particles,\nlike photons for example.\nThe particles ocrrespdongin to quantize leectromeatice field sare like phonons,\necept hte lattice is the EM field.\n\nTo keep long story short,\nquantum mechanically,\nI'm going to have a Hamiltonian exactly like this,\nexcept it doesn't change the fact I have a bunch of quantum harmonic\noscillators.\n\nFirst of all,\nlet's find what the eigenstates of this Hamiltnoian are.\nIt could be that every harmonic oscilllator is in the ground sate,\nthe minimum amount of energy.\nThat's goingto have some energy.\nImagine if I take all of hte modes.\n\nAnd I say only for that particular oscilators and iwht this poarlizatoin here,\nI'm going to t tae the stateo f that oscillatora nd move it to the first excited\nstate.\nHowmuch am I going to raise the energy?\nIt's going to be $\\hbar\\omega_k_1 = \\hbar c k_1$.\nI state like this,\nwe have created a photon of wavelength $2\\pi/k_1$.\nThis is identical to what we have if we had a particle moving wit momentum\n$\\hbar k$.\nThis is the energy of the particle $cp_1$,\nand rememver relativity,\nthis i the energy of a massless particle,\nand htat's why we say it has zero mass.\n\nWhat if I take that very same oscillator and I raise that energy level to the\nsecond excited state?\nBecause the energy levels are equally spaced,\nI would just get $2\\habar\\omega_{_k_1}$.\n\nI could get two different oscillators,\nand that would ocrrespond to the sum of theenrgies.\nThe fact hte nerg is just the sum of the enrgies of each one,\nit means they are not interacting,\nno potential enegy between them and that's it.\n\nThat's hte beginning of quantum electrodynamics,\nlet someone else teach you that.\nBut now I just want to compute the paritiotn function.\n\nYou've done this a million times.\nLook at your notes.\nAfter that we considered the case of phonos,\njust a bunch of harmoinc oscilaotrs.\nHere again,\nwe hve a bunchof harmoinc oscillators.\nWe're doing statistical mechanics of quantum field theory,\nit's veyr fancy stuff.\nAnyway,\nwhat is the parittion function?\n\nI have to take htis Hamilontina here,\nput some hats on them and do the sum.\n\\begin{align}\n    Z &=\n    \\Tr e^{-\\beta H}\\\\\n    &=\n    \\prod_{\\vec{k},{\\alpha}}\n    \\sum_{n_k=0}^{\\infty}\n    e^{-\\beta \\hbar \\omega \\left(n_{k} + \\frac{1}{2}  \\right)}\\\\\n    &= \\prod_{\\vec{k},\\alpha}\n    \\frac{e^{-\\beta \\omega_{\\vec{k}}} \\hbar/2}{%\n    1 - e^{-\\beta \\omega_{\\vec{k}}\\hbar}}\n\\end{align}\nwhere $\\alpha=1,2$ are polarization indices.\nTo convince yourself it's right to take products,\n\\begin{align}\n    \\Tr e^{-\\beta \\left( H_1 + H_2 \\right)} &=\n    \\Tr\\left[\n    e^{-\\beta H_1} e^{-\\beta H_2}\n    \\right]\\\\\n    &=\n    \\sum_{n_1,n_2} \\bra{n_1} e^{-\\beta H_1} \\ket{n_1}\n    \\bra{n_2} e^{-\\beta H_2}\\ket{n_2}\n\\end{align}\nwhere $H_1$ and $H_2$ are independent.\nLet me give you some advice.\nTher'es just so much more I could explain,\nbut I'm just feeling the time here.\nIfyo usee a large expression that doesn't have meaning to you hard to digest,\nyou can break it down,\nby working out the trivial cases.\nAfter you do 2,\neverything becomes clear.\nIf you do this tomrrow,\nand the day after,\nand then it becomes eh,\nnot a big deal this infintie oscillaotrs,\nit takes 30 years.\nThe alternative is ot manipulate formulas using rules no one told you,\nand you'll feel all around.\n\nAnd now we can calculate the Helmholtz free energy.\n\\begin{align}\n    F(T, V) &=\n    -k_B T \\ln Z\\\\\n    &=\n    -k_B T \\sum_{\\vec{k},\\alpha}\\left[ \n    \\ln\\left( 1 - e^{-\\beta\\omega_k\\hbar} \\right)\n    + \\frac{\\beta\\hbar\\omega_k}{2}\n    \\right]\n\\end{align}\nBy the way,\nwe invented QM becauseo f hte embarassing divergeence,\nbuti fy ou calcualte the ground stae of the infinite harmonic oscillaotrs,\nyou get $\\hbar\\omega/2$,\nbut how many ar ethere?\nInfintiely many.\nThis theory predicts the enrgy density of hte vacuum is infinite.\nThat's bad right?\nBut that's hte predition.\nWe do't wrry about it,\nis because if you add a photon,\nyou add energy,\nso hte infinite amount of energy goes on both sides of the quation,\nbut we can ignore.\nSo delete that second term.\n\\begin{align}\n    F(T, V) &=\n    -k_B T \\sum_{\\vec{k},\\alpha}\\left[ \n    \\ln\\left( 1 - e^{-\\beta\\omega_k\\hbar} \\right)\n    \\right]\n\\end{align}\n\nThat is the energy by the way people on the internet want ot harness to move\nspaceships or someting.\nThe rest is just like phonons.\nThe dispersion is not linear forever.\nHere htere is no maximum value of $\\vec{k}$.\nHopefuly thisp art that is temperature dependent.\n\nThere's one step I'm going to do that I'm going to defy detail.\nI want ot transform this sum into an integral,\nby an approxiamtion,\nand when I do this,\nI claim the answer is.\n\\begin{align}\n    F(T, V) &=\n    2k_B T V \\int d^3k\\, \\ln\\left( 1 - e^{-\\beta \\hbar ck} \\right)\n\\end{align}\nAnd this $2$ comes from the polarizations.\nThe free energy is an extensive quantity,\nso you should expect it to be proportional to volume,\nwhich makes sense.\n\nThen we're going to move to the next topic of quantum gases next class.\nMonday we have office hours.\n", "meta": {"hexsha": "940a605271f1b136dadb81b9c22fafda0ce2a97d", "size": 12867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture23.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/lecture23.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/lecture23.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.4924242424, "max_line_length": 80, "alphanum_fraction": 0.7142302013, "num_tokens": 3826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6749950252551795}}
{"text": "\r\n\\section{Online learning approach}\r\nMost of the work in theoretical machine learning has been focused on an off-line setting, where one uses a batch of data to produce a predictive model and then apply it to new data. However, this paper focuses on an on-line setting, where predictions are made sequentially based on all previously processed data, which gives rise to the name itself as we process observations one by one. In this setting we start by observing the first example $x_1$ while predicting its label $y_1$. After that we observe the true label of $y_1$ and also the next data point $x_2$. This process goes on until we either reach the end of our data set or indefinitely. Foremost attention can be drawn to the expectation of improved prediction quality with increasing number of processed data.\r\n\r\nSuch supervised learning approach perfectly suits the case when data is available sequentially with time, for example, in predicting a stock price given its historic data and supplemented by availability of true price, as compared against the prediction of a learning system. Furthermore, as compared to off-line setting, on-line algorithm is expected to show a drastic decrease in memory usage and processing time required until the first prediction is made.\r\n\r\nMore formally, a mathematical description of the learning problem is defined by finding a minimum of an expected risk:\r\n$$E(f)=\\int l(f(x),y)dP(z)$$\r\nwhere function $f$ in a family of functions $\\mathcal{F}$ parameterized by weight vector $w$ minimizes the averaged loss $Q(z,w)=l(f_w(x),y)$ over all data points $z$. Ultimately, we'd prefer to average over the unknown distribution $dP(z)$, however, in practical setting we perform the calculation over a fixed number of examples $z_1, z_2,...z_n$, which is referred to as minimization of an empirical risk:\r\n$$E_n(f)=\\frac{1}{n} \\sum\\limits_{i=1}^{n}l(f(x_i),y_i)$$\r\n\r\nLet us further consider how one could tackle such minimization task with some of the convergence results (Bottou, 2010 \\cite{bottou-2010}).\r\n\r\n\\subsection{Gradient Descent Methods}\r\nOne of the most common approaches to address minimization of empirical risk function is by applying an iterative gradient descent method(GD) where each iteration $t$ updates optimization weights $w$ based on the gradient of $E_n(f_w)$ with learning rate $\\gamma$:\r\n$$w_{t+1}=w_t-\\gamma \\frac{1}{n} \\sum\\limits_{i=1}^{n} \\nabla_w Q(z_i, w_t)$$\r\nWhen the initial estimate of the optimum $w_0$ is sufficiently close and under certain regularity assumptions this method reaches linear convergence, described by a residual error $\\rho$, that is $-\\log\\rho \\sim t$. \r\n\r\nA better optimization algorithm can be composed by replacing the learning rate with a positive-definite matrix $\\Gamma_t$ which approaches inverse of the Hessian of the cost at optimum:\r\n$$w_{t+1}=w_t-\\Gamma_t \\frac{1}{n} \\sum\\limits_{i=1}^{n} \\nabla_w Q(z_i, w_t)$$\r\nThis is known as a 2nd order gradient descent method(2GD) and is a variant of well known Newton algorithm. Under analogous to GD assumptions of initial estimate and regularity this algorithm reaches quadratic convergence $-\\log\\log\\rho \\sim t$.\r\n\r\n\\subsection{Stochastic Gradient Descent Methods}\r\nStochastic setting of GD slightly simplifies the process, instead of computing the gradient of empirical loss function $E_n(f_w)$ exactly one uses a single randomly picked data point $z_t$ for its estimation:\r\n$$w_{t+1}=w_t-\\gamma \\nabla_w Q(z_t, w_t)$$\r\nIn this simplification we assume that our optimization parameter behaves as a stochastic process ${w_t, t=1,...}$, which greatly depends on the data sampling and introduces certain amount of noise. Utilization of stochastic approximation framework (Bottou, 1998 \\cite{bottou-98x}) fully addresses proofs of convergence including cases where loss function is not everywhere differentiable. Results of the aforementioned analysis show that speed of SGD convergence is limited by noisy approximation of the true gradient and is in fact optimal with learning rate $\\gamma_t \\sim t^{-1}$, at which point expectation of the residual error decreases similarly $E\\rho \\sim t^{-1}$.\r\n\r\nAlike 2GD, one can multiply gradients by positive-definite matrix approaching inverse of the Hessian:\r\n$$w_{t+1}=w_t-\\gamma_t\\Gamma_t \\nabla_w Q(z_t, w_t)$$\r\nwhich yields the 2nd order stochastic gradient descent method. However, such change doesn't decrease the bias introduced by stochastic noise and retains the convergence rate $E\\rho \\sim t^{-1}$.\r\n\r\n\\subsection{Sample SGD pseudocode}\r\nA simplistic pseudocode of SGD with in-place optimization parameter update may look as follows:\r\n\\lstinputlisting[frame=single]{sgd.py}\r\n\r\n\\section{SGD in large-scale setting}\r\nFollowing results for asymptotic analysis of SGD (Bottou, 2010 \\cite{bottou-2010}) as summarized in \\figurename{1}, where $\\rho$ is the residual and excess error is defined as \r\n$$\\mathcal{E} = \\mathcal{E}_{app} + \\mathcal{E}_{est} + \\mathcal{E}_{opt} \\sim \\mathcal{E}_{app} + (\\frac{\\log n}{n})^\\alpha + \\rho, \\alpha \\in [1/2, 1]$$\r\nwith $\\mathcal{E}_{app}$ measuring how closely functions in our function space can approximate the optimal solution, $\\mathcal{E}_{est}$ measuring the effect of minimizing empirical risk instead of the expected risk, $\\mathcal{E}_{opp}$ measuring the impact of approximate optimization on expected risk,\r\n\r\n\\begin{figure}[h]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[scale=0.3]{img/gd-convergence.png}\r\n\t\t\\caption{Asymptotic results for various optimization methods}\\label{1}\r\n\t\\end{center}\r\n\\end{figure}\r\n\r\n%\\begin{table}[h]\r\n%\t\\begin{center}\r\n%\t\t\\caption{Asymptotic results for various optimization methods}\\label{1}%\r\n%\t\t\\begin{tabular}{lcccc}\r\n%\t\t\t& GD & 2GD & SGD & 2SGD\\\\\r\n%\t\t\t\\hline\r\n%\t\t\tTime per iteration: \t\t\t\t& $n$ & $n$ & 1 & 1\\\\\r\n%\t\t\tIterations to accuracy $\\rho$: \t\t& $\\log \\frac{1}{\\rho}$ & $\\log \\log \\frac{1}{\\rho}$ & $\\frac{1}{\\rho}$ & $ %\\frac{1}{\\rho}$\\\\\r\n%\t\t\tTime to accuracy $\\rho$:\t\t\t& $n\\log \\frac{1}{\\rho}$ & $n\\log \\log \\frac{1}{\\rho}$ & $\\frac{1}{\\rho}$ & $\\frac{1}{\\rho}$\\\\\r\n%\t\t\tTime to excess error $\\mathcal{E}$: & $\\frac{1}{\\mathcal{E}^{1/\\alpha}} \\log \\frac{1}{\\mathcal{E}}$ & $\\frac{1}{\\mathcal{E}^{1/\\alpha}} \\log \\frac{1}{\\mathcal{E}}\\log\\log \\frac{1}{\\mathcal{E}}$ & $\\frac{1}{\\mathcal{E}}$ & $\\frac{1}{\\mathcal{E}}$\\\\\r\n%\t\t\\end{tabular}\r\n%\t\\end{center}\r\n%\\end{table}\r\n\r\none can conclude that whilst SGD and 2SGD are worst optimization algorithms (as depicted in third row of \\figurename{1}), they require less time to reach predefined expected risk (as in fourth row of \\figurename{1}). In other words, in a large-scale setting where an algorithm is restricted by its computing time rather then the amount of data provided, stochastic gradient methods perform asymptotically better.\r\n\r\n\\section{Parallelization of SGD} \r\nUnlike batch GD, SGD has inherently sequential nature, which essentially limits how one can parallelize the algorithm. However, pressing industry demands have led researchers to find feasible ways of achieving comparable convergence rates, as compared against its sequential counterpart, medium to high scalability on multiple compute units, which not seldom includes both GPUs and CPUs, while keeping computational complexity and data transfer low. We will further describe several parallelization ideas and their pitfalls (Zinkevich, Weimer, Li and Smola, 2010 \\cite{NIPS2010_4006}), as compared to a hybrid method briefly depicted later in this paper.\r\n\r\n\\subsection{Distributed subgradient approach}\r\nThis approach essentially distributes parallelization of gradient computation among several machines, which hold part of the data, and subsequent aggregation of the result on a master machine. While showing great linear scalability relative to amount of data and log-linear relative to number of computers, this approach suffers from excessive communication overhead which results from multiple passes through data by MapReduce. In addition, since several MapReduce iterations are required to ensure fault tolerance, this approach generally doesn't fit into a setting where computation units are not closely coupled, as in multiple machines compared to multicore approach.\r\n\r\n\\subsection{Distributed convex solver approach}\r\nThis approach is comprised of a relatively simple idea of performing a minibatch optimization by means of breaking down a small subset of the data set into several mini-batches and then solving each and every problem on a separate machine for further aggregation of the solutions and averaging obtained values. Most notable part of this idea is that MapReduce needs to perform only one pass, which dramatically reduces overall communication between machines. Despite the fact that this approach significantly reduces variance relative to the sequential counterpart, the bias introduced by stochastic nature of the algorithm doesn't reduce at all, as compared to sequential version. Moreover, this approach requires a batch-solver to run on every single machine, thus making the whole algorithm rather computationally complex. More importantly, analysis of given approach showed that the convergence of the method greatly depends on degree of strong convexity of regularization. \r\n\r\n\\subsection{Distributed SGD approach}\r\nA balance between MapReduce communication overhead and valid asymptotic analysis can be achieved by modifying the distributed convex solver approach to incorporate an SGD minimizer. More precisely, each processor would carry out an SGD on the set of loss functions $Q_i(w)$ with a fixed learning rate $\\gamma$ for $T$ steps as described in Algorithm 1.\r\n\r\n\\begin{table}[h]\r\n\t\\begin{flushleft}\r\n\t\t\\begin{tabular}{l}\r\n\t\t\tAlgorithm 1: $SGD({Q_1, \\dots, Q_m}, T, \\gamma, w_0)$\\\\\r\n\t\t\t\\hline\r\n\t\t\tfor $t = 1$ to $T$ do\\\\\r\n\t\t\t\\enskip\\enskip\tDraw $j \\in (1 \\dots m)$ uniformly at random.\\\\\r\n\t\t\t\\enskip\\enskip\t$w_{t+1}=w_t-\\gamma*dQ_j(w_t)$\\\\\r\n\t\t\tend for\\\\\r\n\t\t\treturn $w_T$.\\\\\r\n\t\t\\end{tabular}\r\n\t\\end{flushleft}\r\n\\end{table}\r\n\r\nTo aggregate computed parameters one would use a master routine. Full procedure pseudocode is presented in Algorithm 2.\r\n\r\n\\begin{table}[h]\r\n\t\\begin{flushleft}\r\n\t\t\\begin{tabular}{l}\r\n\t\t\tAlgorithm 2: SimuParallelSGD(Examples: ${Q_1, \\dots, Q_m}$, $\\gamma$, Machines: $k$)\\\\\r\n\t\t\t\\hline\r\n\t\t\tDefine $T=[m/k]$\\\\\r\n\t\t\tRandomly partition the examples, giving $T$ examples to each machine\\\\\r\n\t\t\tfor all $i \\in {1 \\dots, k}$ parallel do\\\\\r\n\t\t\t\\enskip\\enskip Randomly shuffle the data on machine $i$\\\\\r\n\t\t\t\\enskip\\enskip Initialize $w_{i,0}=0$\\\\\r\n\t\t\t\\enskip\\enskip for all $t \\in {1, \\dots, T}$: do\\\\\r\n\t\t\t\\enskip\\enskip\\enskip\\enskip Gather the $t$th example on the $i$th machine, $Q_{i,t}$\\\\\r\n\t\t\t\\enskip\\enskip\\enskip\\enskip $w_{i,t+1} = w_{i,t}-\\gamma d_w Q_i(w_{i,t})$\\\\\r\n\t\t\t\\enskip\\enskip\\enskip\\enskip end for\\\\\r\n\t\t\t\\enskip\\enskip end for\\\\\r\n\t\t\tAgregate from all computers $v=\\frac{1}{k} \\sum\\limits_{i=1}^{k} w_{i,t+1}$ and return $v$\\\\\r\n\t\t\\end{tabular}\r\n\t\\end{flushleft}\r\n\\end{table}\r\n\r\nWhile this approach in a nutshell is rather simple, its mathematical analysis is nontrivial and can be found in the original work (Zinkevich, Weimer, Li and Smola, 2010 \\cite{NIPS2010_4006}).\r\n\r\n\\subsection{Empirical results of distributed SGD approach}\r\nTo demonstrate scalability potential of the algorithm we can take a look at obtained experimental results (Zinkevich, Weimer, Li and Smola, 2010 \\cite{NIPS2010_4006}) where number of training instances per machine was compared to a relative root-mean square error(RMSE) on the test set as executed on 1, 10 and 100 machines as in \\figurename{2} and also to a normalized objective function as in \\figurename{3}. All tests were performed on a $\\sim$3M examples database of emails with $\\sim$785M features in the whole data set, as resulted after hashing.\r\n\r\n\\begin{figure}[h]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[scale=0.3]{img/parallel-sgd-experiment.png}\r\n\t\t\\caption{Relative Test-RMSE with $\\gamma= 1e^{-3}$. Depicts decreasing training time for various number of machines.}\\label{2}\r\n\t\\end{center}\r\n\\end{figure}\r\n\r\n\\begin{figure}[h]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[scale=0.3]{img/parallel-sgd-experiment2.png}\r\n\t\t\\caption{Relative train error using Huber loss $\\gamma= 1e^{-3}$. Depicts how fast an algorithm reaches certain model quality for various number of machines.}\\label{3}\r\n\t\\end{center}\r\n\\end{figure}\r\n\r\nIt is worth mentioning that scaling of 1 to 10 machines gives much better improvement compared to the one from 10 to 100 machines, which signifies that the proposed algorithm scales poorly in a highly distributed scenario.\r\n\r\n\\section{Asynchronous SGD}\r\nWhile provinding good results, the distributed SGD approach, described in the previous section, has several drawbacks. Namely, it suffers from parameter locking, which happens when parameters $w_i$ are being averaged. This prevents further processing of data by slave SGD machines, since they need to read current parameter for further processing. Moreover, even though the use of MapReduce in this setting does not result in high communication costs, in general it is recommended to avoid its usage in a large-scale numerically intensive applications, due to its inability to cope with iterative nature of solvers and also due to its bandwidth overhead, which results from fault tolerance redundancies. For example, one can experience a potential drop from 12GB/s throughput in a multicore shared memory to only tens of MB/s. Thus we advocate two approaches which do not use MapReduce and perform asynchronous parameter updates as follows.\r\n\r\n\\subsection{Hogwild!}\r\nIn order to eliminate the overhead caused by parameter variable locking, presented algorithm incorporates a simple idea of using high throughput memory shared across all compute units where optimization parameter $w$ is to be stored. Any processor can update the parameter at any given time. Even though such approach might seem excessively prone to parameter overwrites, it works extremely well in case where data access is sparse, meaning that each SGD modifies only a small part of the optimization parameter. Particularly, when our goal is to minimize a loss function\r\n$$f(w)=\\sum\\limits_{e \\in E} f_e(w_e)$$\r\nwhere $e$ denotes a small subset of ${1, \\dots, n}$ and $w$ denotes values of parameter vector $w$ indexed by $e$, the sparsity of loss function means that $|E|$ and $n$ are very large while each individual $f_e$ influences only few values of the whole parameter $w$. This concept is illustrated in more detail with precise mathematical examples of particular cost functions in the original work (Recht, Re, Wright and Niu, 2011 \\cite{NIPS2011_4390}).\r\n\r\nHogwild! pseudocode running on each processor would look as described in Algorithm 3.\r\n\r\n\\begin{table}[h]\r\n\t\\begin{flushleft}\r\n\t\t\\begin{tabular}{l}\r\n\t\t\tAlgorithm 3: Hogwild! update for individual processors\\\\\r\n\t\t\t\\hline\r\n\t\t\tloop\r\n\t\t\t\\enskip\\enskip Sample $e$ uniformly at random from $E$\\\\\r\n\t\t\t\\enskip\\enskip Read current state $w_e$ and evaluate $G_e(x)$\\\\\r\n\t\t\t\\enskip\\enskip for $v \\in e$ do $w_v = w_v - \\gamma b^T_v G_e(w)$\\\\\r\n\t\t\tend loop\\\\\r\n\t\t\\end{tabular}\r\n\t\\end{flushleft}\r\n\\end{table}\r\n\r\nwhere $G=(V,E)$ is a hypergraph induced by $f(w)$ whose nodes are the individual components of $w$ and where each subvector $w_e$ induces an edge in the graph $e \\in E$ and $b_v$ is equal to 1 on the $v$th component and 0 otherwise. It is important to note that the processor modifies only values in $e$ leaving all others untouched.  Such approach does not require a locking mechanism on most modern hardware, such as GPUs or general purpose multicore CPUs.\r\n\r\nAnalytical results for convergence of the algorithm are rather non-trivial and can be found with exhaustive explanations in the original paper (Recht, Re, Wright and Niu, 2011 \\cite{NIPS2011_4390}). Important to note, however, that the algorithm converges in nearly the same number of iterations as its sequential counterpart and provided experimental results outperformed theoretical analysis. In terms of scalability it reaches near linear speedup. Some of the experimental results as compared to almost identical rooundrobin implementation with exception of gradient updates can be found in \\figurename{4}. Those results present a comparison of wall clock time while parallelized over 10 cores, both algorithms were implemented in C++ and were ran on the same hardware setup with a dual Xeon X650 CPUs (6 cores each x 2 hyperthreading) and 24GB of RAM.\r\n\r\n\\begin{figure}[h]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[scale=0.25]{img/hogwild-res.png}\r\n\t\t\\caption{Comparison of wall clock for various data sets and loss functions for Hogwild! and Roundrobin implementations}\\label{4}\r\n\t\\end{center}\r\n\\end{figure}\r\n\r\n\r\n\\subsection{Downpour SGD}\r\nUnlike previous examples, this parallelization approach was used to train a deep neural network with image recognition research project \\cite{NIPS2012_4687} and was developed as part of DistBelief framework at Google. However, the ideas used and results obtained are still worth mentioning as they give birth to potential further work. \r\n\r\nIn a nutshell the approach is as follows: the training data is divided into a number of subsets and a copy of the model is ran on each of those subsets. This approach leverages the idea of Hogwild! asynchronous parameter updates in the form of centralized parameter server which is connected to several model replicas (10 in the example) each holding subset of the parameter $w$ (1/10 in the example). This is schematically presented in \\figurename{5}. Thus, after the model is ran on the assigned subset of training data, computed gradients are communicated to the central parameter server.\r\n\r\n\\begin{figure}[h]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[scale=0.4]{img/downpour-sgd-param.png}\r\n\t\t\\caption{Model replicas asynchronously fetch parameters $w$ and push gradients $\\nabla w$ to the parameter server}\\label{5}\r\n\t\\end{center}\r\n\\end{figure}\r\n\r\nDownpour SGD approach is more robust against machine failures than synchronous parallelized SGD, because in case of machine failure in synchronous SGD the entire training process is delayed. However, in asynchronous SGD when a model replica fails the other model replicas continue to operate and process their updates via parameter server. \r\n\r\nIn addition, Downpour SGD uses AdaGrad \\cite{adagrad} adaptive learning rates which increase robustness of the whole implementation and tackle problems of stability within deep neural network context. Corresponding learning rate is as follows:\r\n$$ \\eta_{i,K}=\\gamma / \\sqrt{\\sum\\limits_{j=1}^{K}} \\nabla w_{i,j}^2$$\r\nOne can notice that the learning rates $\\eta_{i,K}$ are computed from the summed squared gradients of parameter part and thus can be easily implemented locally within each model replica.\r\n\r\nHighly scalable nature of the algorithm can be seen as depicted in \\figurename{6}.\r\n\\begin{figure}[h]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[scale=0.4]{img/downpour-sgd.png}\r\n\t\t\\caption{Training speed-up for four different deep networks as a function of machines allocated to a single model instance}\\label{6}\r\n\t\\end{center}\r\n\\end{figure}", "meta": {"hexsha": "ecbee37997b440eaacbb17190b27beced84fa5eb", "size": 19087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tum/computational-aspects-of-machine-learning/paper/section1.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/computational-aspects-of-machine-learning/paper/section1.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/computational-aspects-of-machine-learning/paper/section1.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": 98.896373057, "max_line_length": 979, "alphanum_fraction": 0.7638183057, "num_tokens": 4746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6749496473799499}}
{"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\\renewcommand{\\implies}{\\Rightarrow}\n\\begin{document}\n\n\\title{Rational approximations of real numbers}\n\n\\section{Introduction}\n\nOur goal is to prove that we can approximate any positive real number arbitrarily closely\nwith $\\frac{2^a}{3^b}$ with positive integers $a,b$. This surprising result will bring us\ninto the world of infinite and infinitessimal analysis.\n\nThis will be a quick tour around some of the wonders of infinity in analysis, and how to\ngenerate arbitrarily accurate rational approximations for any real number.\n\n\\section{Continued fractions}\n\nOne way of generating arbitrarily close approximations of irrational numbers is by taking\nthe partial terms (called \"convergents\") of the continued fraction expression. Generating\na continued fraction for $x$ involves taking the floor of $x$, subtracting it, taking the\nfloor of the inverse, and repeating the operation to infinity.\n\nAn example will help to illustrate. The continued fraction for $\\sqrt{2} = 1.414\\cdots$ has\na leading term of 1 (the whole number part of $\\sqrt{2}$) and a remainder of $\\sqrt{2}-1$.\nInverting the remainder, we find that it is $\\frac{1}{\\sqrt{2}-1} = \\sqrt{2}+1$ - giving\nour next term to be $\\lfloor 1+\\sqrt{2}\\rfloor = 2$, and a remainder of $\\sqrt{2}-1$.\nWe can repeat this process ad infinitem to generate the continued fraction \n$\\left[1;2,2,2,\\cdots\\right]$.\n\n\\textbf{Exercise:} Prove that the continued fraction of $\\sqrt{n^2+1}$ in general is \n$\\left[n;2n,2n,2n,\\cdots\\right]$.\n\nWe can now generate a convergent set of rational approximations to $\\sqrt{2}$ which are\nguaranteed to be the best possible rational approximations with a given denominator (or\nsmaller) by taking the partial sums:\n\\[ 1+\\frac{1}{2} = \\frac{3}{2}\\]\n\\[ 1+\\frac{1}{2+\\frac{1}{2}} = 1+\\frac{2}{5} = \\frac{7}{5} \\]\n\\[ 1+\\frac{1}{2+\\frac{1}{2+\\frac{1}{2}}} = 1+\\frac{5}{12} = \\frac{17}{12} \\]\n\\[ 1+\\frac{1}{2+\\frac{1}{2+\\frac{1}{2 + \\frac{1}{2}}}} = 1+\\frac{12}{29} = \\frac{41}{29} \\]\n\nIn general, if the $n$th approximation is $\\frac{p}{q}$, the $(n+1)$th approximation is \n$\\frac{p+2q}{p+q}$.\n\n\\textbf{Exercise:} Prove that this sequence converges to $\\sqrt{2}$. How does it converge?\nIs it monotonic decreasing, or does it oscillate around the eventual limit? Does this\nconverge to $\\sqrt{2}$ if we start with a different starting point for $\\frac{p}{q}$?\n\nLarger numbers in a continued fraction representation imply faster convergence, smaller\nnumbers mean slower convergence. The slowest converging continued fraction is thus:\n\\[\\left[1;1,1,1,\\cdots\\right] = 1+\\frac{1}{\\left[1;1,1,1,\\cdots\\right]}\\]\n\nWe can evaluate this exactly using the quadratic equation:\n\\[ x = 1+\\frac{1}{x} \\]\nor $x = \\varphi = \\frac{1+\\sqrt{5}}{2}$, the golden ratio.\n\nThe start continued fraction for $\\pi$ is\n$\\left[3;7,15,1,292,1,1,1,2,1,3,1,14,2,1,1,2,2,2,2,\\cdots\\right]$ and its first few\nconvergents are the well known approximations of $\\pi: 3, \\frac{22}{7}, \\frac{333}{106}, \\frac{355}{113}$.\nSince the next term is 292, we know that this last approximating is extremely close to the actual\nvalue of $\\pi$.\n\n\\section{Finding general rational approximations}\n\nWhen given a number $x$, one naive strategy for finding a rational approximation is to multiply\nit by a positive integer $n$, take the whole number closest to the result, and call $\\frac{m}{n}$ our\nestimate. This approach works, and will converge to $x$ over time, but it is far from efficient. For\nexample, $\\frac{22}{7}$ is a much better estimate of $\\pi$ than $\\frac{31}{10}$ - by increasing the\ndenominator to 10, we have made our estimate a lot worse.\n\nWe can do better by using an approach described by Dirichlet. Dirichlet's approximation theorem\nsays that if $x$ is irrational, that we can always find $a,b \\in \\mathbb{Z}$ such that\n$|ax-b|<\\frac{1}{n}$ for any $n\\in \\mathbb{N}$. To prove this, consider $\\{ax\\} = ax - \n\\lfloor ax \\rfloor$ for all $a < n$. $0<\\{ax\\}<1$ for all $a$, by definition. If we partition the\ninterval $[0,1)$ into $n-1$ buckets $[0,\\frac{1}{n}) \\cup [\\frac{1}{n},\\frac{2}{n}) \\cup \\cdots\n\\cup [\\frac{n-1}{n}, 1)$, we are guaranteed that of the $n+1$ values $\\{a_i\\}_{i=0}^n$, at\nleast 2 will land in the same bucket, by the Pigeonhole principle. If these two values are $a_i, a_j$,\nthen $a_i = \\{ix\\} = ix - \\lfloor ix \\rfloor, a_j = \\{jx\\} = jx - \\lfloor jx \\rfloor$, and\n\n\\[ \\frac{1}{n} > |\\{ix\\}-\\{jx\\}| = | (ix-\\lfloor ix \\rfloor) - (jx - \\lfloor jx \\rfloor) | \\]\n\\[ \\frac{1}{n} > | (i-j)x  + b | = | ax+b | \\]\n\nfor an integer $b = |\\lfloor ix \\rfloor - \\lfloor jx \\rfloor|$. What's more, regardless of how close\nthe estimate is for $n$, we can find a better estimate by choosing $n > |\\frac{1}{ax-b}|$, when\n$\\frac{1}{n}$ is smaller than the smallest fractional difference for $a<n$.\n\nThis is a bit abstract, so let's work an example through to see how this works in practice. Let's try\nto approximate $\\pi$ using this method with increasing values of $a$. With $a=10$, for example:\n\n\\begin{center}\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\t$i$ & $\\{i\\pi\\}$ \\\\\n\t\t\\hline\n\t\t$0$ & $0$ \\\\\n\t\t$1$ & $0.14159$ \\\\\n\t\t$2$ & $0.28318$ \\\\\n\t\t$3$ & $0.42277$ \\\\\n\t\t$4$ & $0.56637$ \\\\\n\t\t$5$ & $0.70796$ \\\\\n\t\t$6$ & $0.84955$ \\\\\n\t\t$7$ & $0.99114$ \\\\\n\t\t$8$ & $0.13274$ \\\\\n\t\t$9$ & $0.27433$ \\\\\n\t\t$10$ & $0.41592$ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\nNow, since we have 10 buckets, representing the $\\frac{1}{10}$ths, we are guaranteed that at\nleast two of these will be in the same bucket (in fact, we see that many pairs are in the same\nbucket). Looking down the list at the $\\frac{1}{10}$ths digit, we can easily see that the\nentries corresponding to $i=1, i=8$, $i=2, i=9$, and $i=3, i=10$ all land in the same buckets.\nIn other words:\n\\[ \\frac{1}{10}> |\\{8\\pi\\}-\\{1\\pi\\}| = | 8\\pi - 25 - (1\\pi - 3)| = |7\\pi -22| \\]\nwhich gives us the well-known estimate for $\\pi$ of $\\pi \\approx \\frac{22}{7}$. \n\nGiven a good estimate $\\frac{a}{b}$ for $x$, we can guarantee to find a better estimate by \nconsidering $|bx-a| = y$. Again, considering $\\pi$: $|7\\pi - 22| \\approx 0.00885 > \n\\frac{1}{113}$, so we are guaranteed to be able to find a more accurate rational estimate by setting\n$a \\geq 113$.\n\nThis iterative nature of always being able to find a closer approximation by choosing a sufficiently\nlarge value for $n$, is what enables arbitrary approximation of any rational number.\n\n\\section{A Pell equation approach}\n\n\\textbf{Question:} Source: The Riddler from FiveThirtyEight: \nhttps://fivethirtyeight.com/features/can-you-find-an-extra-perfect-square/\n\nFor some perfect squares, when you remove the last digit, the result is also a perfect square. The\nfirst few squares for which this happens are 16, 49, 169, 256, and 361. Can you find the next 3\nnumbers for which this is true? How many such numbers are there?\n\nFor extra credit, note that $(169,16,1)$ is a triple with this property. Are\nthere other similar triples?\n\nIf we write the larger number as $a^2$, and the smaller number as $b^2$, we get that:\n\\[ 0 \\leq a^2 - 10b^2 < 10 \\]\n\nAnd by looking at $n^2 \\pmod{10}$, we can see that $a^2 - 10b^2 \\in \\{0,1,4,5,6,9\\}$.\nIn addition, if $a^2-10b^2 = 5$ that means that $a=10k+5, a^2 = 100(k^2+k) + 25$, so the last\ndigit of $b^2$ would have to be 2, which is not an option. And if $a^2-10b^2 = 0$, that means that:\n$\\frac{a^2}{b^2} = 10 \\implies \\frac{a}{b} = \\sqrt{10}$ - but since $\\sqrt{n}$ is irrational unless\n$n$ is a perfect square, that is not a possibility either. Thus, we need to find the solutions to\n$a^2 - 10b^2 \\in \\{1,4,6,9\\}$.\n\nLet's look first at $a^2-10b^2 = 1$.  We can factor this as a difference of two squares:\n\\[ a^2 - 10b^2 = (a-\\sqrt{10}b)(a+\\sqrt{10}b) = 1 \\]\n\nAdditionally, we can show that if $a,b \\in \\mathbb{Z}$, then:\n\\[ (a-\\sqrt{10}b)^n = A - \\sqrt{10}B \\]\n\\[ (a+\\sqrt{10}b)^n = A + \\sqrt{10}B \\]\nfor some $A,B \\in \\mathbb{Z}$ using the binomial expansion. For $n=2$, we get $A=a^2+10b^2, B=2ab$.\n\nFrom the question, we already have the smallest solution to this equation: $19^2 - 10(6^2) = 1$ - \nand from this we can generate as many solutions as we want by using different values of $n$. Indeed:\n\\[A = 19^2 + 10\\cdot 6^2 = 361 + 360 = 721,  B = 2 \\cdot 19 \\cdot 6 = 228 \\]\n\\[ 721^2 = 51984, 228^2 = 51984, 721^2 - 10\\cdot 228^2 = 1 \\]\n\nBy defining an appropriate norm on numbers in this set (called formally $\\mathbb{Z}[\\sqrt{10}]$), \nwe can also find all solutions satisfying the question. Define the norm as:\n\\[ N(a+\\sqrt{10}b) = (a+\\sqrt{10}b)(a-\\sqrt{10}b) = a^2-10b^2 \\]\nThen:\n\\begin{align*}\n\tN((a+\\sqrt{10}b)(c+\\sqrt{10}d)) &= N((ac+10bd) + \\sqrt{10}(bc + ad)) \\\\\n\t&= (ac+10bd)^2-10(bc+ad)^2 \\\\\n\t&= a^2c^2 - 10b^2c^2 - 10a^2b^2 + 100b^2d^2 \\\\\n\tN(a+\\sqrt{10}b)N(c+\\sqrt{10}d) &= (a^2-10b^2)(c^2-10d^2) \\\\\n\t&= a^2c^2 -10b^2c^2 -10 a^2d^2 +100b^2d^2 \\\\\n\t&= N((a+\\sqrt{10}b)(c+\\sqrt{10}d))\n\\end{align*}\n\nSo for $\\mathbb{Z}[\\sqrt{10}]$, if we have a number with a norm $N(a+\\sqrt{10}b) = 4$ then we can\ngenerate infinitely many others with the same norm by multiplying by a number that has a norm of 1\n(that is, by any number of the form $(19+6\\sqrt{10})^n$). Since $N(2 + 0\\sqrt{10}) = 4$, any number\nof the form $2(19+6\\sqrt{10})^n$ will have $a^2-10b^2 = 4$.\n\nFor $a^2 - 10b^2 = 6$, we can similarly generate solutions of the form $(4+\\sqrt{10})(19+6\\sqrt{10})^n$\nand $(16+5\\sqrt{10})(19+6\\sqrt{10})^n$. And finally, for $a^2 - 10b^2 = 9$, there are several numbers with\n$N(a+\\sqrt{10}b) = 9$: $3, 7+2\\sqrt{10}, 13 + 4\\sqrt{10}$, and so we can generate solutions for all of\n$3(19 + 6\\sqrt{10})^n, (7 + 2\\sqrt{10})(19 + 6\\sqrt{10})^n, (13 + 4\\sqrt{10})(19 + 6\\sqrt{10})^n$.\n\nIt's worth noting that for all solutions of the form $a^2-10b^2 = 1$:\n\\[ \\frac{a}{b} = \\sqrt{10 + \\frac{1}{b^2}} \\approx \\sqrt{10} \\]\n\nso the solutions to the question above are also increasingly accurate rational approximations of \n$\\sqrt{10}$. As we saw in the section on continued fractions, $\\sqrt{10} = [3;6,6,6,\\cdots]$ - so we\nalso can create solutions with convergents of the continued fraction above (taken after an\neven number of terms, because it oscillates around $\\sqrt{10}$). The first convergent,\n$\\frac{19}{6}$, corresponds to the smallest solution of $a^2-10b^2=1$. The next convergents are\n\\[ 3 + \\frac{1}{6 + \\frac{1}{6 + \\frac{1}{6}}} = \\frac{721}{228} \\]\n\\[ 3 + \\frac{1}{6 + \\frac{1}{6 + \\frac{1}{6 + \\frac{1}{6 + \\frac{1}{6}}}}} = \\frac{27379}{8658} \\]\nwhich correspond to the next two solutions to $a^2-10b^2=1$.\n\nFor the extra credit: if $0<a^2-10b^2 <10, 0<10b^2 - (10c)^2 \\leq 90$, then adding these,\n\n\\[0 < a^2 - (10c)^2 = (a-10c)(a+10c) < 100 \\]\n\nand $a > 10c$, giving us:\n\n\\[ 20c < a+10c < (a+10c)(a-10c) = a^2 - (10c)^2 < 100 \\]\nWhich means $c < 5$, and $a^2$ must begin with $1,4,9,16$. The only option for $b$ with this\nconstraint is $169$, and there are no other solutions.\n\n\\section{Approximating any positive real number with $\\frac{2^a}{3^b}, a,b \\in \\mathbb{Z}^+$}\n\nGiven $\\delta>0, x \\in \\mathbb{R}^+$, we can find $a,b \\in \\mathbb{Z}^+$ such that:\n\\[ \\left|x - \\frac{2^a}{3^b} \\right| < \\delta \\]\n\nConsider:\n\\begin{align*}\n\ty &= \\frac{2^a}{3^b} \\\\\n\t\\ln(y) &= a\\ln(2) - b\\ln(3) \\\\\n\t\\log_3(y) &= a\\log_3(2) - b\n\\end{align*}\n\nSince $\\log_3(2)$ is irrational, we can use Dirichelet's approximation theorem to find\n$a,b \\in \\mathbb{Z}$ such that:\n\\[ \\left| a\\log_3(2) - b \\right| < \\frac{1}{n} \\]\nfor any $n \\in \\mathbb{N}$.\n\n\n\\end{document}\n", "meta": {"hexsha": "318213a2f8308490e01bf0406e0c7ff5f7d94e11", "size": 11504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rational_approximations.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": "rational_approximations.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": "rational_approximations.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": 49.8008658009, "max_line_length": 106, "alphanum_fraction": 0.6613351878, "num_tokens": 4170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.766293653760418, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.6749492182984907}}
{"text": "%\n% Chapter 5.3\n%\n\n\\section*{5.3 Volumes by Cylindrical Shells}\n\n\\subsubsection*{Formula for the Volume of a Cylindrical Shell}\n\n\\[ \\text{V = [circumference][height][thickness]} \\quad \\Leftrightarrow \\quad V = 2 \\pi rh \\Delta r \\]\n", "meta": {"hexsha": "e485da0fdbc936424f31862ec164b9cec1e6fb80", "size": 231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/5-3.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/5-3.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/5-3.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1, "max_line_length": 101, "alphanum_fraction": 0.7012987013, "num_tokens": 77, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.674949206498686}}
{"text": "\\section{Fibrations and cofibrations}\n\\subsection{Comparing fibers over different points}\nLet $p:E\\to B$ be a fibration.\nAbove, we saw that this implies that paths in $B$ ``lift'' to paths in $E$.\nLet us consider a path $\\omega:I\\to B$ with $\\omega(0) = a$ and $\\omega(1) = b$.\nDenote by $F_a$ the fiber over $a$. \nIf the world plays fairly, the path lifting property of fibrations should beget a (unique\\footnote{At least up to homotopy.})\nmap $F_a\\to F_b$.\nThe goal of this subsection is to construct such a map.\n\nConsider the diagram:\n\\begin{equation*}\n    \\xymatrix{\n\tF_a\\ar[d]_{\\mathrm{in}_0}\\ar[rr] & & E\\ar[d]^p\\\\\n\tI\\times F_a\\ar@{-->}[urr]^{h}\\ar[r]_{\\mathrm{pr}_1} & I\\ar[r]_{\\omega} & B.\n    }\n\\end{equation*}\nThis commutes since $\\omega(0) = a$.\nUtilizing the homotopy lifting property, there is a dotted arrow that makes the entire diagram commute.\nIf $x\\in F_a$, the image $h(1,x)$ is in $F_b$, and $h(0,x) = x$.\nThis supplies us with a map $f:F_a\\to F_b$, given by $f(x) = h(1,x)$.\n\nWe're now faced with a natural question: is $f$ unique up to homotopy?\nNamely: if we have two homotopic paths $\\omega_0,\\omega_1$ with $\\omega_0(0) = \\omega_1(0) = a$,\nand $\\omega_0(1) = \\omega_1(1) = b$, along with a given homotopy $g:I\\times I\\to B$ between $\\omega_0$ and $\\omega_1$,\nsuch that $f_0,f_1:F_a \\to F_b$ are the associated maps (defined by $h_0(1,x)$ and $h_1(1,x)$),\nrespectively, are $f_0$ and $f_1$ homotopic?\n\nWe have a diagram of the form:\n\\begin{equation*}\n    \\xymatrix{\n\t((\\partial I\\times I)\\cup (I\\times \\{0\\}))\\times F_a\\ar[d]_{\\mathrm{in}_0}\\ar[rr] & & E\\ar[d]^p\\\\\n\tI\\times I\\times F_a\\ar[r]_{\\mathrm{pr}_1}\\ar@{-->}[urr] & I\\times I\\ar[r]_g & B\n    }\n\\end{equation*}\nTo get a homotopy between $f_0$ and $f_1$, we need the dotted arrow to exist.\n\n% Add a picture, maybe?\n%\n%Think of the space $(\\partial I\\times I)\\cup (I\\times 0)$ as follows:\n%\\begin{equation*}\n%\\begin{tikzpicture}\n%    \\draw (2,2) -- (0,2) -- (0,0) -- (2,0);\n%    \\node [above] at (1,2) {$h_1$};\n%    \\node [below] at (1,0) {$h_0$};\n%    \\node [left] at (0,1) {$in_0$};\n%\\end{tikzpicture}\n%\\end{equation*}\n%and $I\\times I$ looks like:\n%\\begin{equation*}\n%    \\begin{tikzpicture}\n%\t\\draw (0,0) -- (0,2) -- (2,2) -- (2,0) -- (0,0);\n%\t\\draw[fill] (2,2) circle [radius=0.05];\n%\t\\draw[fill] (2,0) circle [radius=0.05];\n%\t\\node [left] at (0,1) {$a$};\n%\t\\node [above] at (1,2) {$\\omega_1$};\n%\t\\node [below] at (1,0) {$\\omega_0$};\n%\t\\node [right] at (2,1) {$b$};\n%\t\\node [above right] at (2,2) {$f_1$};\n%\t\\node [below right] at (2,0) {$f_0$};\n%    \\end{tikzpicture}\n%\\end{equation*}\n%\n%Does the dotted map exist? Clearly this is crying out for us to use the homotopy lifting property. But what should our space $W$ be? Well the following pair:\n%\\begin{equation*}\n%    \\begin{tikzpicture}\n%\t\\draw (2,2) -- (0,2) -- (0,0) -- (2,0);\n%    \\end{tikzpicture}\\subseteq\n%    \\begin{tikzpicture}\n%\t\\draw (0,0) -- (0,2) -- (2,2) -- (2,0) -- (0,0);\n%    \\end{tikzpicture}\n%\\end{equation*}\n%is homotopy equivalent to $(0\\subseteq I)\\times I$. Hence in our diagram we now have:\n\nIt's an easy exercise to recognize that our diagram is equivalent to the following.\n\\begin{equation*}\n    \\xymatrix{\n\tI\\times F_a\\ar[rr]^{\\simeq} & & ((\\partial I\\times I)\\cup (I\\times 0))\\times F_a\\ar[d]_{\\mathrm{in}_0}\\ar[rr] & & E\\ar[d]^p\\\\\n\tI\\times I\\times F_a\\ar[rr]_{\\simeq} & & I\\times I\\times F_a\\ar[r]_{\\mathrm{pr}_1}\\ar@{-->}[urr] & I\\times I\\ar[r]_g & B\n    }\n\\end{equation*}\nLetting $W=I\\times F_a$ in the definition of a fibration (Definition \\ref{fibration}) thus gives us the desired lift,\ni.e., a homotopy $f_0\\simeq f_1$.\n\nWe can express the uniqueness (up to homotopy) of lifts of homotopic paths in a functorial fashion.\nTo do so, we must introduce the fundamental groupoid of a space.\n\\begin{definition}\n    Let $X$ be a topological space.\n    The \\emph{fundamental groupoid} $\\Pi_1(X)$ of $X$ is a category (in fact, groupoid),\n    whose objects are the points of $X$, and maps are homotopy classes of paths in $X$.\n    The composition of compatible paths $\\sigma$ and $\\omega$ is defined by:\n    \\begin{equation*}\n\t(\\sigma\\cdot\\omega)(t) = \\begin{cases}\n\t    \\omega(2t) & 0\\leq t\\leq 1/2\\\\\n\t    \\sigma(2t - 1) & 1/2\\leq t\\leq 1.\n\t\\end{cases}\n    \\end{equation*}\n\\end{definition}\nThe results of the previous sections can be succinctly summarized in the following neat statement.\n\\begin{prop}\n    Any fibration $p:E\\to B$ gives a functor $\\Pi_1(B)\\to \\Top$.\n\\end{prop}\nThis is the beginning of a beautiful story involving fibrations.\n(The interested reader should look up ``Grothendieck construction''.)\n\n\\subsection{Cofibrations}\nLet $i:A\\to X$ be a map of spaces.\nIf $Y$ is another topological space, when is the induced map $Y^X\\to Y^A$ a fibration?\nThis is asking for the map $i$ to be ``dual'' to a fibration.\n\nBy the definition of a fibration, we want a lifting:\n\\begin{equation*}\n    \\xymatrix{\n\tW\\ar[r]\\ar[d]_{\\mathrm{in}_0} & Y^X\\ar[d]\\\\\n\tI\\times W\\ar@{-->}[ur]\\ar[r] & Y^A.\n    }\n\\end{equation*}\nAdjointing over, we get:\n\\begin{equation*}\n    \\xymatrix{\n\tA\\times W\\ar[r]^{i\\times 1}\\ar[d]_{1\\times \\mathrm{in}_0} & X\\times W\\ar[d]\\ar[ddr]& \\\\\n\tA\\times W\\times I \\ar[r]\\ar[drr] & X\\times I\\times W\\ar@{-->}[dr] & \\\\\n\t& & Y.\n    }\n\\end{equation*}\nAgain adjointing over, this diagram transforms to:\n\\begin{equation*}\n    \\xymatrix{\n\tA\\ar[r]\\ar[d] & X\\ar[d]\\ar[ddr] & \\\\\n\tA\\times I\\ar[r]\\ar[drr] & X\\times I\\ar@{-->}[dr] & \\\\\n\t& & Y^W.\n    }\n\\end{equation*}\nThis discussion motivates the following definition of a ``cofibration'':\nas mentioned above, this is ``dual'' to the notion of fibration.\n\n\\begin{definition}\\label{cofibration}\n    A map $i:A\\to X$ of spaces is said to be a \\emph{cofibration} if it satisfies the\n    \\emph{homotopy extension property} (sometimes abbreviated as ``HEP''):\n    for any space $Y$, there is a dotted map in the following diagram that makes it commute:\n    \\begin{equation*}\n    \\xymatrix{\n\tA\\ar[r]\\ar[d] & X\\ar[d]\\ar[ddr] & \\\\\n\tA\\times I\\ar[r]\\ar[drr] & X\\times I\\ar@{-->}[dr] & \\\\\n\t& & Y.\n    }\n    \\end{equation*}\n\\end{definition}\n\nAgain, using the definition of a pushout, the universal example of such a space $Y$ is the pushout $X\\cup_A (A\\times I)$.\nEquivalently, we are therefore asking for the existence of a dotted arrow in the following diagram.\n\\begin{equation*}\n    \\xymatrix{\n\tX\\cup_A (A\\times I)\\ar[r]\\ar[dr] & X\\times I\\ar@{-->}[d]\\\\\n\t& Z,\n    }\n\\end{equation*}\nfor any $Z$.\nUsing the universal property of a pushout, this is equivalent to the existence of a dotted arrow in the following diagram.\n\\begin{equation*}\n    \\xymatrix{\n\tX\\cup_A (A\\times I)\\ar[r]\\ar[dr] & X\\times I\\ar@{-->}[d]\\\\\n\t& X\\cup_A(A\\times I)\\ar[d]\\\\\n\t& Z,\n    }\n\\end{equation*}\nwhich is, in turn, equivalent to asking $X\\cup_A (A\\times I)$ to be a retract of $X\\times I$.\n\n\\begin{example}\\label{intervalcofib}\n    $S^{n-1}\\hookrightarrow D^n$ is a cofibration.\n    \\todo{Properly draw out this figure!}\n    \\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.75]{assets/retract-cofibration}\n\t\\caption{Drawing by John Ni.}\n    \\end{figure}\n    In particular, setting $n=1$ in this example, $\\{0,1\\}\\hookrightarrow I$ is a cofibration.\n\\end{example}\n\nHere are some properties of the class of cofibrations of CGWH spaces.\n\\begin{itemize}\n    \\item It's closed under cobase change: if $A\\to X$ is a cofibration, and $A\\to B$ is any map,\n\tthe pushout $B\\to X\\cup_A B$ is also cofibration. (Exercise!)\n    \\item It's closed under finite products. (This is surprising.)\n    \\item It's closed under composition. (Exercise!)\n    \\item Any cofibration is a closed inclusion\\footnote{Note that the dual statement for\n\tfibrations would state:\tany fibration $p:E\\to B$ is a quotient map.\n\tThis is definitely not true: fibrations do not have to be surjective!\n\tFor instance, the trivial map $\\emptyset\\to B$ is a fibration.\n\t(Fibrations are surjective on path components though, because of path lifting.)}.\n\t\\todo{This is not obvious; should we include a proof?}\n\\end{itemize}\n", "meta": {"hexsha": "c0265c3ed69e060fbaed8794d0beda57bb970d8a", "size": 7968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-43-fibrations-cofibrations.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-43-fibrations-cofibrations.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-43-fibrations-cofibrations.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": 41.2849740933, "max_line_length": 158, "alphanum_fraction": 0.6593875502, "num_tokens": 2870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.6749491994944269}}
{"text": "\n\\subsection{Division rings}\n\nA divison ring is a ring where every non-zero element has a multiplicative inverse.\n\n\\subsubsection{Example}\n\nThe rational numbers are a divison ring.\n\n\\subsubsection{Relationship between divison rings and fields}\n\nFields (not yet introduced) are different from division rings only in that multiplication for a field must be commutative.\n\n", "meta": {"hexsha": "8f0687099e07e5655df9b9ab9c979750e00ae37d", "size": 369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/rings/05-01-ringDivision.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/rings/05-01-ringDivision.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/rings/05-01-ringDivision.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.3571428571, "max_line_length": 122, "alphanum_fraction": 0.8075880759, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.7662936324115012, "lm_q1q2_score": 0.6749491970966539}}
{"text": "\\lab{Gaussian Quadrature}{Gaussian Quadrature}\n\\label{Lab:GaussQuad}\n\n% TODO: points and weights calculations aren't great when compared to NumPy via\n% np.polynomial.chebyshev.chebgauss() or np.polynomial.legendre.leggauss().\n\n\\objective{\nLearn the basics of Gaussian quadrature and its application to numerical integration.\nBuild a class to perform numerical integration using Legendre and Chebyshev polynomials.\nCompare the accuracy and speed of both types of Gaussian quadrature with the built-in Scipy package.\nPerform multivariate Gaussian quadrature.\n}\n\n\\section*{Legendre and Chebyshev Gaussian Quadrature} % =======================\n\nIt can be shown that for any class of orthogonal polynomials $p\\in \\mathbb{R}[x;2n+1]$ with corresponding weight function $w(x)$, there exists a set of points $\\{x_i\\}_{i=0}^n$ and weights $\\{w_i\\}_{i=0}^n$ such that\n\\[\n\\int_a^b p(x) w(x) dx = \\sum_{i=0}^n p(x_i)w_i.\n\\]\nSince this relationship is exact, a good approximation for the integral\n\\[\n\\int_a^b f(x) w(x) dx\n\\]\ncan be expected as long as the function $f(x)$ can be reasonably interpolated by a polynomial at the points $x_i$ for $i=0,1,\\dots,n$.\nIn fact, it can be shown that if $f(x)$ is $2n+1$ times differentiable, the error of the approximation will decrease as $n$ increases.\n\nGaussian quadrature can be performed using any basis of orthonormal polynomials, but the most commonly used are the Legendre polynomials and the Chebyshev polynomials.\nTheir weight functions are $w_l(x)=1$ and $w_c(x)=\\frac{1}{\\sqrt{1-x^2}}$, respectively, both defined on the open interval $(-1,1)$.\n\n\\begin{problem} % GaussianQuadrature.__init__().\n\\label{prob:gaussquad-init}\nDefine a class for performing Gaussian quadrature.\nThe constructor should accept an integer $n$ denoting the number of points and weights to use (this will be explained later) and a label indicating which class of polynomials to use.\nIf the label is not either \\li{\"legendre\"} or \\li{\"chebyshev\"}, raise a \\li{ValueError}; otherwise, store it as an attribute.\n\nThe weight function $w(x)$ will show up later in the denominator of certain computations.\nDefine the reciprocal function $w(x)^{-1} = 1/w(x)$ as a \\li{lambda} function and save it as an attribute.\n\\end{problem}\n\n\\subsection*{Calculating Points and Weights} % --------------------------------\n\n% The first step of Gaussian quadrature is finding the weights and points that will be used.\n% There are several important algorithms that will find the weights and points of quadrature.\n% One based on a recurrence relationship inherent in all orthogonal polynomials will be considered in this lab.\n\nAll sets of orthogonal polynomials $\\{u_k\\}_{k=0}^{n}$ satisfy the three-term recurrence relation\n\\[\nu_0=1,\\qquad u_1 = x - \\alpha_1,\\qquad u_{k+1} = (x-\\alpha_k)u_k - \\beta_ku_{k-1}\n\\]\nfor some coefficients $\\{\\alpha_k\\}_{k=1}^n$ and $\\{\\beta_k\\}_{k=1}^n$.\n% These constants have been calculated for several classes of orthogonal polynomials;\n% there also exist algorithms for finding the coefficients for arbitrary classes of orthogonal polynomials.\n%and may be determined for an arbitrary class using the procedure found in ``Calculation of Gauss Quadrature Rules'' by Golub and Welsch.\nFor the Legendre polynomials, they are given by\n\\[\n\\alpha_k=0, \\qquad\\qquad \\beta_k=\\frac{k^2}{4k^2-1},\n\\]\nand for the Chebyshev polynomials, they are\n\\[\n\\alpha_k=0, \\qquad\\qquad \\beta_k=\\begin{cases} \\frac{1}{2} &\\mbox{ if } k = 1\\\\ \\frac{1}{4} &\\text{otherwise.} \\\\ \\end{cases}\n\\]\nGiven these values, the corresponding \\emph{Jacobi matrix} is defined as follows.\n\\[\nJ = \\begin{bmatrix}\n\\alpha_1 & \\sqrt{\\beta_1} & 0 & \\dots & 0 \\\\\n\\sqrt{\\beta_1} & \\alpha_2 & \\sqrt{\\beta_2} & \\dots & 0 \\\\\n0 & \\sqrt{\\beta_2} & \\alpha_3 &  \\ddots & 0 \\\\\n\\vdots & & \\ddots & \\ddots & \\vdots \\\\\n%\\vdots & & \\ddots & & \\vdots \\\\\n0 & \\dots & & & \\sqrt{\\beta_{n-1}} \\\\\n0 & \\dots & & \\sqrt{\\beta_{n-1}} & \\alpha_n\n\\end{bmatrix}\n\\]\nAccording to the \\emph{Golub-Welsch algorithm},\\footnote{See \\url{http://gubner.ece.wisc.edu/gaussquad.pdf} for a complete treatment of the Golub-Welsch algorithm, including the computation of the recurrence relation coefficients for arbitrary orthogonal polynomials.} the $n$ eigenvalues of $J$ are the points $x_i$ to use in Gaussian quadrature, and the corresponding weights are given by $w_i=\\mu_w(\\mathbb{R})v_{i,0}^2$ where $v_{i,0}$ is the first entry of the $i$th eigenvector and\n$\\mu_w(\\mathbb{R}) = \\int_{-\\infty}^\\infty w(x)dx$ is the \\emph{measure} of the weight function.\nSince the weight functions for Legendre and Chebyshev polynomials have compact support on the interval $(-1, 1)$, their measures are given as follows.\n\\[\n\\mu_{w_l}(\\mathbb{R}) = \\int_{-\\infty}^\\infty w_l(x)dx = \\int_{-1}^{1} 1dx = 2\n\\qquad \\qquad\n\\mu_{w_c}(\\mathbb{R}) = \\int_{-\\infty}^\\infty w_c(x)dx = \\int_{-1}^{1} \\frac{1}{\\sqrt{1 - x^2}} dx = \\pi\n\\]\n\n%Finding eigenvalues and eigenvectors for a tridiagonal matrix is a well conditioned problem.\n%Using a good eigenvalue solver gives the Golub-Welsch algorithm a complexity of $O(n^2)$.\n\n\\begin{problem} % Jacobi matrix + points and weights.\n\\label{prob:jacobi}\nWrite a method for your class from Problem \\ref{prob:gaussquad-init} that accepts an integer $n$.\nConstruct the $n\\times n$ Jacobi matrix $J$ for the polynomial family indicated in the constructor.\nUse SciPy to compute the eigenvalues and eigenvectors of $J$, then compute the points $\\{x_i\\}_{i=1}^n$ and weights $\\{w_i\\}_{i=1}^n$ for the quadrature.\nReturn both the array of points and the array weights.\n\nTest your method by checking your points and weights against the following values using the Legendre polynomials with $n=5$.\n{\\small\n\\[\n\\centering\n\\begin{array}{c|c|c|c|c|c}\n    x_i\n    & -\\frac{1}{3}\\sqrt{5 + 2\\sqrt{\\frac{10}{7}}}\n    & -\\frac{1}{3}\\sqrt{5 - 2\\sqrt{\\frac{10}{7}}}\n    & 0\n    & \\frac{1}{3}\\sqrt{5 - 2\\sqrt{\\frac{10}{7}}}\n    & \\frac{1}{3}\\sqrt{5 + 2\\sqrt{\\frac{10}{7}}}\n    \\\\[1em] \\hline\n    w_i\n    & \\dfrac{322-13\\sqrt{70}}{900}\n    & \\dfrac{322+13\\sqrt{70}}{900}\n    & \\dfrac{128}{225}\n    & \\dfrac{322+13\\sqrt{70}}{900}\n    & \\dfrac{322-13\\sqrt{70}}{900}\n\\end{array}\n\\]\n}\n% Note that the order of the points and weights in the given table may differ.\n\nFinally, modify the constructor of your class so that it calls your new function and stores the resulting points and weights as attributes.\n\\end{problem}\n\n\\subsection*{Integrating with Given Weights and Points} % ---------------------\n\nNow that the points and weights have been obtained, they can be used to approximate the integrals of different functions.\nFor a given function $f(x)$ with points $x_i$ and weights $w_i$,\n\\[\n\\int_{-1}^{1} f(x) w(x) dx \\approx \\sum_{i=1}^n f(x_i)w_i.\n\\]\nThere are two problems with the preceding formula.\nFirst, the weight function is part of the integral being approximated, and second, the points obtained are only found on the interval $(-1,1)$ (in the case of the Legendre and Chebyshev polynomials).\nTo solve the first problem, define a new function $g(x) = f(x) / w(x)$ so that\n\\begin{equation}\n\\int_{-1}^{1} f(x) dx\n= \\int_{-1}^{1} g(x) w(x) dx\n\\approx \\sum_{i=1}^n g(x_i)w_i.\n\\label{eq:quadrature-no-shift}\n\\end{equation}\n\nThe integral of $f(x)$ on $[-1,1]$ can thus be approximated with the inner product $\\w\\trp g(\\x)$, where $g(\\x) = [g(x_1),\\dots,g(x_n)]\\trp$ and $\\w = [w_1,\\dots,w_n]\\trp$.\n\n\\begin{problem} % Integrate with given points and weights.\nWrite a method for your class that accepts a callable function $f$.\nUse \\eqref{eq:quadrature-no-shift} and the stored points and weights to approximate of the integral of $f$ on the interval $[-1,1]$.\n\\\\(Hint: Use $w(x)^{-1}$ from Problem \\ref{prob:gaussquad-init} to compute $g(x)$ without division.)\n\n% Remember that the weight function depends on the type of polynomial (the type should be stored as an attribute).\nTest your method with examples that are easy to compute by hand and by comparing your results to \\li{scipy.integrate.quad()}.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.integrate import quad\n\n# Integrate f(x) = 1 / sqrt(1 - x**2) from -1 to 1.\n>>> f = lambda x: 1 / np.sqrt(1 - x**2)\n>>> quad(f, -1, 1)[0]\n3.141592653589591\n\\end{lstlisting}\n\\label{prob:gaussquad-no-shift}\n\\end{problem}\n\n\\begin{info}\nSince the points and weights for Gaussian quadrature do not depend on $f$, they only need to be computed once and can then be reused to approximate the integral of any function.\nThe class structure in Problems \\ref{prob:gaussquad-init}--\\ref{prob:gaussquad-shift} takes advantage of this fact, but \\li{scipy.integrate.quad()} does not.\nIf a larger $n$ is needed for higher accuracy, however, the computations must be repeated to get a new set of points and weights.\n\\end{info}\n\n\\subsection*{Shifting the Interval of Integration} % --------------------------\n\nSince the weight functions for the Legendre and Chebyshev polynomials have compact support on the interval $(-1,1)$, all of the quadrature points are found on that interval as well.\nTo integrate a function on an arbitrary interval $[a,b]$ requires a change of variables.\nLet \\[u = \\frac{2x - b - a}{b - a}\\] so that $u = -1$ when $x = a$ and $u = 1$ when $x=b$.\nThen\n\\[\nx = \\frac{b - a}{2}u + \\frac{a + b}{2}\\qquad \\text{and}\\qquad dx = \\frac{b - a}{2}du,\n\\]\nso the transformed integral is given by\n\\[\n\\int_a^b f(x) dx = \\frac{b-a}{2}\\int_{-1}^1 f\\left(\\frac{b-a}{2}u + \\frac{a+b}{2}\\right)du.\n\\]\nBy defining a new function $h(x)$ as\n\\[\nh(x) = f\\left(\\frac{(b-a)}{2}x + \\frac{(a+b)}{2}\\right),\n\\]\nthe integral of $f$ can be approximated by integrating $h$ over $[-1,1]$ with \\eqref{eq:quadrature-no-shift}.\nThis results in the final quadrature formula\n\\begin{equation}\n\\int_{a}^{b} f(x) dx = \\frac{b-a}{2}\\int_{-1}^1 h(x)dx = \\frac{b-a}{2}\\int_{-1}^1 g(x)w(x)dx \\approx \\frac{b-a}{2}\\sum_{i=1}^n g(x_i)w_i,\n\\label{eq:quadrature-complete}\n\\end{equation}\nwhere now $g(x) = h(x) / w(x)$.\n\n\\begin{problem} % Shift the integral.\nWrite a method for your class that accepts a callable function $f$ and bounds of integration $a$ and $b$.\nUse \\eqref{eq:quadrature-complete} to approximate the integral of $f$ from $a$ to $b$.\n\\\\(Hint: Define $h(x)$ and use your method from Problem \\ref{prob:gaussquad-no-shift}.)\n\\label{prob:gaussquad-shift}\n\\end{problem}\n\n\\begin{comment}\n\\section*{Numerical Integration with SciPy} % =================================\n\nThere are many other techniques for finding the weights and points for a given weighting function.\nSciPy's \\li{integrate} module provides some general-purpose integration tools.\nFor example, \\li{scipy.integrate.quad()} is a reasonably fast Gaussian quadrature implementation.\nAlso included in the \\li{integrate} module are fixed-precision and fixed-order Gaussian quadrature methods.\n\\begin{lstlisting}\n>>> from scipy.integrate import quad\n\n>>> f = lambda x: np.cos(x) * np.sin(x)**2 # Function to integrate.\n>>> g = lambda x: np.sin(x)**3 / 3         # Antiderivative.\n\n# quad returns an array, the first entry is the computed value.\n>>> calc = quad(f, -2, 3)[0]\n>>> exact = g(3) - g(-2)                   # Exact value of the integral.\n>>> np.<<abs>>(exact - calc)                   # Error of the approximation.\n0.0\n\\end{lstlisting}\n\\end{comment}\n\n% TODO: need to demonstrate this if it's to be included.\n\\begin{comment}\nAnother common hallmark of quadrature is that it can be used adaptively.\nIt is common in practice to refine the points of a quadrature estimate on an interval where a function is observed to be changing rapidly.\nThis allows for more accurate computation at a relatively low computational cost.\nThis is the approach used by the function \\li{scipy.integrate.quad()}.\n\\end{comment}\n\n\\begin{problem} % Get error estimates by integrating the standard normal.\nThe \\emph{standard normal distribution} has the following probability density function.\n\\[f(x) = \\frac{1}{\\sqrt{2 \\pi}} e^{-x^2/2}\\]\nThis function has no symbolic antiderivative, so it can only be integrated numerically.\nThe following code gives an ``exact'' value of the integral of $f(x)$ from $-\\infty$ to a specified value.\n\n\\begin{lstlisting}\n>>> from scipy.stats import norm\n\n>>> norm.cdf(1)                     # Integrate f from -infty to 1.\n0.84134474606854293\n>>> norm.cdf(1) - norm.cdf(-1)      # Integrate f from -1 to 1.\n0.68268949213708585\n\\end{lstlisting}\n% The probability that a normally distributed random variable $X$ will take on a value less than (or equal to) a given value $x$ is \\[ P(X \\le x) = \\int_{-\\infty}^x p(t)dt = \\int_{-\\infty}^x \\frac{1}{\\sqrt{2 \\pi}} e^{-t^2/2} dt. \\]\n\nWrite a function that uses \\li{scipy.stats} to calculate the ``exact'' value\n\\[\nF = \\int_{-3}^2 f(x)dx.\n\\]\nThen repeat the following experiment for $n=5,10,15,\\ldots,50$.\n\\begin{enumerate}\n\\item Use your class from Problems \\ref{prob:gaussquad-init}--\\ref{prob:gaussquad-shift} with the Legendre polynomials to approximate $F$ using $n$ points and weights.\nCalculate and record the error of the approximation.\n\\item Use your class with the Chebyshev polynomials to approximate $F$ using $n$ points and weights.\nCalculate and record the error of the approximation.\n\\end{enumerate}\nPlot the errors against the number of points and weights $n$, using a log scale for the $y$-axis.\nFinally, plot a horizontal line showing the error of \\li{scipy.integrate.quad()} (which doesn't depend on $n$).\n\\end{problem}\n\n\n\\section*{Multivariate Quadrature} % ==========================================\n\nThe extension of Gaussian quadrature to higher dimensions is fairly straightforward.\nThe same set of points $\\{z_i\\}_{i=1}^n$ and weights $\\{w_i\\}_{i=1}^n$ can be used in each direction, so the only difference from 1-D quadrature is how the function is shifted and scaled.\nTo begin, let $h:\\mathbb{R}^2\\rightarrow\\mathbb{R}$ and define $g:\\mathbb{R}^2\\rightarrow\\mathbb{R}$ by $g(x,y) = h(x,y)/(w(x)w(y))$ so that\n\\begin{equation}\n\\int_{-1}^1\\int_{-1}^1 h(x,y)dx\\:dy.\n= \\int_{-1}^1\\int_{-1}^1 g(x,y)w(x)w(y)dx\\:dy\n\\approx \\sum_{i=1}^n \\sum_{j=1}^n w_i w_j g(z_i,z_j).\n\\label{eq:gaussquad-multivariable-scale}\n\\end{equation}\nTo integrate $f:\\mathbb{R}^2\\rightarrow\\mathbb{R}$ over an arbitrary box $[a_1,b_1]\\times[a_2,b_2]$, set\n\\[\nh(x,y) = f\\left(\\frac{b_1 - a_1}{2}x + \\frac{a_1 + b_1}{2},\\\n                \\frac{b_2 - a_2}{2}y + \\frac{a_2 + b_2}{2}\\right)\n\\]\nso that\n\\begin{equation}\n\\int_{a_2}^{b_2}\\int_{a_1}^{b_1} f(x) dx\\:dy\n= \\frac{(b_1 - a_1) (b_2 - a_2)}{4}\\int_{-1}^1\\int_{-1}^1 h(x,y)dx\\:dy.\n\\label{eq:gaussquad-multivariable-shift}\n\\end{equation}\nCombining \\eqref{eq:gaussquad-multivariable-scale} and \\eqref{eq:gaussquad-multivariable-shift} gives the final 2-D Gaussian quadrature formula.\nCompare it to \\eqref{eq:quadrature-complete}.\n\\begin{equation}\n\\int_{a_2}^{b_2}\\int_{a_1}^{b_1} f(x) dx\\:dy\n\\approx \\frac{(b_1 - a_1) (b_2 - a_2)}{4}\n\\sum_{i=1}^n \\sum_{j=1}^n w_i w_j g(z_i,z_j)\n\\label{eq:quadrature-multivariate-complete}\n\\end{equation}\n\n\\begin{problem}\nWrite a method for your class that accepts a function $f:\\mathbb{R}^2\\rightarrow\\mathbb{R}$ (which actually accepts two separate arguments, not one array with two elements) and bounds of integration $a_1$, $a_2$, $b_1$, and $b_2$.\nUse \\eqref{eq:quadrature-multivariate-complete} to compute the double integral\n\\[\\int_{a_2}^{b_2}\\int_{a_1}^{b_1} f(x) dx\\:dy.\\]\n% Note that we have assumed that we will be using the same number of points in both dimensions so the previous equation is valid.\n\nValidate your method by comparing it \\li{scipy.integrate.nquad()}.\nNote carefully that this function has slightly different syntax for the bounds of integration.\n\\begin{lstlisting}\n>>> from scipy.integrate import nquad\n\n# Integrate f(x,y) = sin(x) + cos(y) over [-10,10] in x and [-1,1] in y.\n>>> f = lambda x, y: np.sin(x) + np.cos(y)\n>>> nquad(f, [[-10, 10], [-1, 1]])[0]\n33.658839392315855\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{info}\nAlthough Gaussian quadrature can obtain reasonable approximations in lower dimensions, it quickly becomes intractable in higher dimensions due to the curse of dimensionality.\nIn other words, the number of points and weights required to obtain a good approximation becomes so large that Gaussian quadrature become computationally infeasible.\nFor this reason, high-dimensional integrals are often computed via \\emph{Monte Carlo methods}, numerical integration techniques based on random sampling.\nHowever, quadrature methods are generally significantly more accurate in lower dimensions than Monte Carlo methods.\n\\end{info}\n", "meta": {"hexsha": "b4dd9997153286c2289deb306b73dd1f04ac0d16", "size": 16431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/GaussianQuadrature/GaussianQuadrature.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume2/GaussianQuadrature/GaussianQuadrature.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume2/GaussianQuadrature/GaussianQuadrature.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.8327974277, "max_line_length": 487, "alphanum_fraction": 0.706956363, "num_tokens": 5082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.6748686313337632}}
{"text": "\\section{Definitions}\n\n% BINOMIAL THEOREMS \n\n\\vspace{0.5cm}\\subsection{Binomial Theorems}\n\n\\vspace{0.5cm}\\begin{definition}\\label{def-biomial-theorems}\n\n    \\begin{equation}\n        (a+b)^2 = a^2 + 2ab + b^2 \\label{eq-1}\n    \\end{equation}\n\n    \\begin{equation}\n        (a-b)^2 = a^2 - 2ab + b^2 \\label{eq-2}\n    \\end{equation}\n\n    \\begin{equation}\n        (a+b)\\,(a-b) = a^2 - b^2 \\label{eq-3}\n    \\end{equation}\n\n    \\flushleft \\normalfont For higher exponentiations:  \n\n    \\begin{equation}\n        (a+b)^3 = a^3 +3a^2b + 3ab^2 + b^3 \\label{eq-4}\n    \\end{equation}\n\n    \\begin{equation}\n        (a-b)^3 = a^3 - 3a^2b + 3ab^2 - b^3 \\label{eq-5}\n    \\end{equation}\n\n    \\begin{equation}\n        (-a-b)^3 = -a^3 - 3a^2b - 3ab^2 - b^3 \\label{eq-6}\n    \\end{equation}\n\n    Binomial Formula:\n\n    \\begin{equation}\n        (x+y)^{n}=\\sum _{k=0}^{n}{n \\choose k}x^{n-k}y^{k}=\\sum _{k=0}^{n}{n \\choose k}x^{k}y^{n-k} \\label{eq-7}\n    \\end{equation}\n\n    where\n\n    \\begin{equation}\n        {\\displaystyle {\\binom {n}{k}}={\\frac {n!}{k!(n-k)!}},} \\label{eq-8}\n    \\end{equation}\n    \n\\end{definition}\n\n% FRACTIONS \n\n\\vspace{0.5cm}\\subsection{Fractions}\n\n\\vspace{0.5cm}\\begin{definition}\\label{def-fractions}\n\n    \\begin{equation}\n        \\frac{a}{b} + \\frac{c}{b} = \\frac{a + c}{b} \\label{eq-9}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{a}{b} - \\frac{c}{b} = \\frac{a - c}{b} \\label{eq-10}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{a}{b} \\cdot  \\frac{c}{d} = \\frac{a \\cdot c}{b \\cdot d} \\label{eq-11}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{a}{b} + \\frac{c}{d} = \\frac{ad}{bd} + \\frac{bc}{bd} = \\frac{ad + bc}{bd} \\label{eq-12}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{a}{b} - \\frac{c}{d} = \\frac{ad}{bd} - \\frac{bc}{bd} = \\frac{ad - bc}{bd} \\label{eq-13}\n    \\end{equation}\n\n    \\flushleft \\normalfont Inverse: \n\n    \\begin{equation}\n        \\frac{a}{b} \\div \\frac{c}{d} = \\frac{a}{b} \\cdot \\frac{d}{c} = \\frac{ad}{bc} \\label{eq-14}\n    \\end{equation}\n\n    \\begin{equation}\n        \\dfrac{\\dfrac{a}{b}}{\\dfrac{c}{d}} = \\frac{a}{b} \\cdot \\frac{d}{c} = \\frac{a \\cdot b}{d \\cdot c} \\label{eq-15}\n    \\end{equation}\n\n    \\begin{equation}\n        \\dfrac{a \\cdot \\dfrac{b}{c}}{\\dfrac{d}{e}} = \\dfrac{\\dfrac{a \\cdot c + b}{c}}{\\dfrac{d}{c}} = \\dfrac{a \\cdot c + b}{c} \\cdot \\dfrac{c}{d} = \\dfrac{(a \\cdot c + b) \\cdot c}{c \\cdot d} \\label{eq-16}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{ab}{c} = \\frac{a}{c} \\cdot b \\label{eq-17}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{a}{b} = \\frac{1}{b} \\cdot a \\label{eq-18}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{a \\div b}{c} = \\frac{a}{c} \\div b \\label{eq-19}\n    \\end{equation}\n    \n\\end{definition}\n\n% PARENTHESES\n\n\\vspace{0.5cm}\\subsection{Parentheses Rules}\n\n\\vspace{0.5cm}\\begin{definition}\\label{def-parentheses}\n    \n    \\begin{equation}\n    +\\,(a+b) = a+b \\label{eq-20}\n    \\end{equation}\n\n    \\begin{equation}\n        +\\,(-a-b) = -a-b \\label{eq-21}\n    \\end{equation}\n\n    \\begin{equation}\n        -\\,(a-b) = -a+b \\label{eq-22}\n    \\end{equation}\n\n    \\begin{equation}\n        -\\,(-a+b) = +a-b \\label{eq-23}\n    \\end{equation}\n\n    \\begin{equation}\n        -\\,(a+b) = -a-b \\label{eq-24}\n    \\end{equation}\n\n    \\flushleft \\normalfont Associative properties:\n\n    \\begin{equation}\n        (a+b)+c = a+(b+c) \\label{eq-25}\n    \\end{equation}\n\n    \\begin{equation}\n        (a \\cdot b) \\cdot c = a \\cdot (b \\cdot c) \\label{eq-26}\n    \\end{equation}\n\n    Distributive properties: \n\n    \\begin{equation}\n        a \\cdot (b+c) = (a \\cdot b) + (a \\cdot c) \\label{eq-27}\n    \\end{equation}\n\n    \\begin{equation}\n        (a+b) \\cdot c = (a \\cdot c) + (b \\cdot c) \\label{eq-28}\n    \\end{equation}\n\n    Commutative properties:\n\n    \\begin{equation}\n        a+b = b+a \\label{eq-29}\n    \\end{equation}\n\n    \\begin{equation}\n        a \\cdot b = b \\cdot a \\label{eq-30}\n    \\end{equation}\n\n\\end{definition}\n\n% MULTIPLY WITH -1\n\n\\vspace{0.5cm}\\subsection{Multiply with -1}\n\\vspace{0.5cm}\\begin{definition}\\label{def-multiply-with-minus-one}\n    \n    Mathematical operators may be swapped by multiplying with -1, because the result does not change.\n    \n    \\begin{equation}\n         a+b = c\\; \\;\\boldsymbol{\\leftrightarrow}\\; \\;-1 \\cdot (-a-b) = c \\label{eq-31}\n    \\end{equation}\n\n    \\flushleft \\normalfont \\bfseries Example: \n\n    \\begin{equation}\n        (a-b)^2 = (b-a)^2 \\label{eq-32}\n    \\end{equation}\n\n\\end{definition}\n\n% SQUARE ROOTS \n\n\\vspace{0.5cm}\\subsection{Square Roots}\n\\vspace{0.5cm}\\begin{definition}\\label{def-square-roots}\n\n    \\begin{equation}\n        \\sqrt[1]{a} = a \\label{eq-33}\n    \\end{equation}\n\n    \\begin{equation}\n        \\sqrt[2]{a} = \\sqrt{a} \\label{eq-34}\n    \\end{equation}\n\n    \\begin{equation}\n        \\sqrt{a^2} = a \\label{eq-35}\n    \\end{equation}\n\n    \\begin{equation}\n        \\left(\\sqrt{a}\\right)^2 = a \\label{eq-36}\n    \\end{equation}\n    \n    \\begin{equation}\n        \\frac{1}{\\sqrt{n}} \\cdot \\frac{1}{\\sqrt{n}} = \\frac{1}{n} \\label{eq-37}\n    \\end{equation}\n\n    \\begin{equation}\n        \\sqrt{n} \\cdot \\sqrt{n} = n \\label{eq-38}\n    \\end{equation}\n\n    \\flushleft \\normalfont Addition: \n\n    \\begin{equation}\n        a\\sqrt[n]{x} + b\\sqrt[n]{x} = (a+b)\\sqrt[n]{x} \\label{eq-39}\n    \\end{equation}\n\n    Subtraction: \n\n    \\begin{equation}\n        a\\sqrt[n]{x} - b\\sqrt[n]{x} = (a-b)\\sqrt[n]{x} \\label{eq-40}\n    \\end{equation}\n\n    Multiplication: \n\n    \\begin{equation}\n        \\sqrt[n]{a} \\cdot \\sqrt[n]{b} = \\sqrt[n]{a \\cdot b} \\label{eq-41}\n    \\end{equation}\n\n    Division: \n\n    \\begin{equation}\n        \\dfrac{\\sqrt[n]{a}}{\\sqrt[n]{b}} = \\sqrt[n]{\\dfrac{a}{b}} \\label{eq-42}\n    \\end{equation}\n\n    Root exponentiation:\n\n    \\begin{equation}\n       \\Big(\\sqrt[n]{a}\\Big)^m = \\sqrt[n]{m} \\label{eq-43}\n    \\end{equation}\n\n    Root extraction: \n\n    \\begin{equation}\n        \\sqrt[m]{\\sqrt[n]{a}} = \\sqrt[m \\cdot n]{a} \\label{eq-44}\n    \\end{equation}\n\n    Transforming roots into exponents:\n\n    \\begin{equation}\n        \\sqrt[n]{a} = a \\cdot \\frac{1}{n} \\label{eq-45}\n    \\end{equation}\n\n    \\begin{equation}\n        \\sqrt{a} = a \\cdot \\frac{1}{2} \\label{eq-46}\n    \\end{equation}\n\n    \\begin{equation}\n        \\sqrt[n]{a^m} = a^\\frac{m}{n} \\label{eq-47}\n    \\end{equation}\n\n\\end{definition}\n\n% EXPONENTIATION\n\n\\vspace{0.5cm}\\subsection{Exponentiation}\n\\vspace{0.5cm}\\begin{definition}\\label{def-exponentiation}\n    \n    \\begin{equation}\n        x^n \\cdot x^b = x^{n+b} \\label{eq-48}\n    \\end{equation}\n\n    \\begin{equation}\n        x^n \\div x^b = \\frac{x^n}{x^b} = x^{n-b} \\label{eq-49}\n    \\end{equation}\n\n    \\begin{equation}\n       \\Big(x^a\\Big)^b = x^{a \\cdot b} \\label{eq-50}\n    \\end{equation}\n\n    \\begin{equation}\n        a^n \\cdot a^b = (a \\cdot b)^n \\label{eq-51}\n    \\end{equation}\n\n    \\begin{equation}\n        a^n \\div b^n = \\frac{a^n}{b^n} = \\left(\\frac{a}{b}\\right)^n \\label{eq-52}\n    \\end{equation}\n\n    \\begin{equation}\n        x^0 = 1 \\label{eq-53}\n    \\end{equation}\n\n    \\begin{equation}\n        x^1 = x \\label{eq-54}\n    \\end{equation}\n\n    \\begin{equation}\n        x^{-n} = \\frac{1}{x^n} \\label{eq-55}\n    \\end{equation}\n\n    \\begin{equation}\n        \\frac{1}{x} = x^{-1} \\label{eq-56}\n    \\end{equation}\n\n    \\begin{equation}\n        x^{\\frac{1}{n}} = \\sqrt[n]{x} \\label{eq-57}\n    \\end{equation}\n\n    \\flushleft \\normalfont {\\bfseries Disclaimer (for 56):} If n is even, then x must be > 0!\n\n    \\begin{equation}\n        x^{\\frac{m}{n}} = \\sqrt[n]{m} \\label{eq-58}\n    \\end{equation}\n\n    \\begin{equation}\n        x^{-\\frac{m}{n}} = \\frac{1}{\\sqrt[n]{x^m}} \\label{eq-59}\n    \\end{equation}\n\n    Addition: %(cf. \\ref{eq-power-to-sqrt})\n\n    \\begin{equation}\n        ax^n + bx^n = (a+b)x^n \\label{eq-60}\n    \\end{equation}\n\n    Subtraction: \n\n    \\begin{equation}\n        ax^n - bx^n = (a-b)x^n \\label{eq-61}\n    \\end{equation}\n\n    Transform a single root into a exponent:\n\n    \\begin{equation}\n        \\sqrt{a} = (a)^{\\frac{1}{2}} \\cdots \\sqrt[3]{a} = (a)^{\\frac{1}{3}} \\cdots \\label{eq-62}\n    \\end{equation}\n\n\\end{definition}      \n", "meta": {"hexsha": "fef99983b304b4fbc353b538ed88fc5a9fe64abd", "size": 8029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/sections/definitions/definitions.tex", "max_stars_repo_name": "StevenGreve/mathematics", "max_stars_repo_head_hexsha": "0763cbc4b44169300adf48dc2fea3d07a6f5cb68", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-21T23:42:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T23:42:14.000Z", "max_issues_repo_path": "src/sections/definitions/definitions.tex", "max_issues_repo_name": "StevenGreve/mathematics", "max_issues_repo_head_hexsha": "0763cbc4b44169300adf48dc2fea3d07a6f5cb68", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/sections/definitions/definitions.tex", "max_forks_repo_name": "StevenGreve/mathematics", "max_forks_repo_head_hexsha": "0763cbc4b44169300adf48dc2fea3d07a6f5cb68", "max_forks_repo_licenses": ["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.9671641791, "max_line_length": 204, "alphanum_fraction": 0.5462697721, "num_tokens": 3146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.674850058204794}}
{"text": "\\clearpage\n\\section{Glossy Analysis}\n\\subsection{Linearly connected network}\nIn a linear connected network, assuming every nodes are connected linearly with two neighbors.\nNamely, only two nodes in the RF range of single transmission except the terminal nodes.\n\n\\begin{figure}[h]\n\\centering\n\t\\includegraphics[width=0.6\\columnwidth]{glossy_linear_topology}\n\\end{figure}\n\nWith Glossy protocol, the number of transmission $N$ is a parameter which limits the maximum\nnumber of transmission of each node. Assuming the packet length in time $T_p$, TXRX turnaround \ntime $T_t$ and the number of hops $K$.\nIn the steady state, every nodes in the network wake up in the same time. Assuming all nodes\nwake up at time $t = 0$ and the {\\bf Initiator (I)} starts transmission after time delay \n$T_\\gamma$. Figure~\\ref{fig:glossy_linear_timing} is the example with I = {\\bf n\\subscript{1}}\nand $N = 3$.\n\n\\begin{figure}[h]\n\\centering\n\t\\includegraphics[width=0.9\\columnwidth]{glossy_linear_timing}\n\t\\caption{Timing diagram of a simple glossy flooding with N = 3}\n\t\\label{fig:glossy_linear_timing}\n\\end{figure}\n\nFrom figure~\\ref{fig:glossy_linear_timing}, we can infer the radio on time for each node\nin a linear connected network. Note that the following analysis is base on the assumption\nthat {\\bf every transmission is success}, which is likely hold if no interference present.\n\nThe radio on time of initiator I is the shortest. It has to transmit $N$ times. Between $N$\ntransmissions, there are $N-1$ receiving slot. Therefore, sum up the total number of transmission\nand receiving. We can find $2N-1$ packet length $T_p$ and $2N-2$ turnaround time $T_t$.\nWe can write the radio on time of Initiator $T_I$ as following:\n\\begin{equation}\n\tT_I = T_\\gamma + (2N-1)T_P + (2N-2)T_t\n\\end{equation}\nFrom the figure~\\ref{fig:glossy_linear_timing}, we can infer that the radio on time of the node \nwhich is 1 hop distance from the initiator $T_{D=1}$ is $T_p + T_t$ longer than $T_I$. Since \nthe node has the exactly the same pattern once it starts transmission. The time between the radio on\nand starts transmitting is $T_p + T_t$.\n\\begin{equation}\n\tT_{D=1} = T_I + T_p + T_t\n\\end{equation}\nExpand the radio on time for any nodes which is $i$ hops away from initiator $T_{D=i}$\n\\begin{equation}\n\tT_{D=i} = T_I + i\\times(T_p + T_t)\n\\end{equation}\n\nWe define a {\\bf Total Radio On Time (TROT)} as the {\\bf sum of radio on time in the network}. Since\nGlossy uses flooding to send packet through the entire network, the TROT of a linearly connected\nnetwork is not a constant. However, it's correlated with the {\\bf position of initiator in the\nnetwork}. The intuition view is that the nodes far from initiator would have longer on time. Therefore,\nthe TROT is minimum if the initiator is located in the middle of the linearly connected network.\nWe define another term {\\bf Total Distance (TD)} as the {\\bf sum of distance between all nodes in the network\nand initiator I}. We can correlate the TROT to TD. To calculate the TROT, we can simply\ncalculate the TD.\n\\begin{equation}\n\tTROT = TD\\times(T_p + T_t) + K\\times T_I\n\t\\label{eq:TROT_TD}\n\\end{equation}\nFor example, if the initiator I is located in the edge of the network ($n_1$ or $n_K$), the TD \nis following:\n\\begin{equation}\n\tTD_1 = \\displaystyle\\sum\\limits_{i=0}^{K-1} i = \\tfrac{K(K-1)}{2}\n\\end{equation}\nSimilarly, if the initiator I is located in 2\\superscript{rd} position of the network ($n_2$ or $n_{K-1}$).\nTD can be written as following:\n\\begin{equation}\n\tTD_2 = \\displaystyle\\sum\\limits_{i=0}^{K-2} i + 1 = \\tfrac{(K-1)(K-2)}{2} + 1\n\\end{equation}\nExpand to j\\superscript{th} position of the network. Where $1\\le j\\le K$.\n\\begin{align}\n\tTD_j = \\displaystyle\\sum\\limits_{i=0}^{K-j} i + \\displaystyle\\sum\\limits_{i=0}^{j-1} i &= \\tfrac{(K-j+1)\\times(K-j)}{2} + \\tfrac{j(j-1)}{2}\\\\\n\t&=\\tfrac{K(K+1)}{2} + j^2 - j\\times(K+1)\n\\end{align}\nAnother assumption made here is that every nodes in the network has the same probability (uniform \ndistribution) to act as initiator I. Namely, $p_{j=1} = p_{j=2} \\cdots = p_{j=K-1} = p_{j=K} = 1/K$\n\nTherefore, the average TD can be expressed as follows:\n\\begin{align}\n\tTD_{avg} \t&= \\tfrac{1}{K} \\displaystyle\\sum\\limits_{j=1}^K TD_j\\\\\n\t\t\t\t&= \\tfrac{1}{K} \\displaystyle\\sum\\limits_{j=1}^K \\tfrac{K(K+1)}{2} + j^2 - j\\times(K+1)\\\\\n\t\t\t\t&= \\tfrac{1}{K} [\\tfrac{K(K+1)}{2}\\times K + \\tfrac{K(K+1)(2K+1)}{6} - \\tfrac{K(K+1)}{2}\\times(K+1)]\\\\\n\t\t\t\t&= \\tfrac{K(K+1)}{2} + \\tfrac{(K+1)(2K+1)}{6} - \\tfrac{(K+1)^2}{2}\\\\\n\t\t\t\t&= \\tfrac{K^2-1}{3}\n\\end{align}\nFrom equation~\\ref{eq:TROT_TD}, the average TROT can be written as following:\n\\begin{align}\n\tTROT_{avg} \t&= TD_{avg}\\times(T_p + T_t) + K\\times T_I\\\\\n\t\t\t\t&= \\tfrac{K^2-1}{3}\\times(T_p + T_t) + K\\times[T_\\gamma + (2N-1)T_P + (2N-2)T_t]\n\\end{align}\nThe average radio on time for each node $T_{on, avg} = TROT_{avg}/K$. If $K^2\\gg1$\n\\begin{equation}\n\tT_{on, avg} \\approx \\{\\tfrac{K}{3}\\times(T_p + T_t)\\} + \\{T_\\gamma + (2N-1)T_P + (2N-2)T_t\\}\n\t\\label{eq:ton_avg}\n\\end{equation}\nFrom equation~\\ref{eq:ton_avg}, we can find the average radio on time in a linear connected network\nis composed of two parts. The first half is only correlated to {\\bf the size of the network K} and the \nsecond half is only correlated to {\\bf the number of transmission N}. In a practical example,\n$K$ = 10, $T_p$ = 0.8~ms (8 bytes data + 17 overhead~\\footnote{ 4 bytes preamble, 1 byte SFD, 1 byte Length,\n2 bytes FCF, 1 byte DSN, 6 bytes address (2 bytes for source/destination/PAN), 2 bytes FCS\n}), $T_t$ = 192~$\\mu$s + 23.5~$\\mu$s (192~$\\mu$s is the standard\nturnaround time, 23.5~$\\mu$s is SW delay implemented by Ferrai et al.~\\cite{ferrari:efficient}), $N$ = 6 is \nreasonable in a linear connected network since every node has only two neighbors. If $N$ is too small, \nsingle transmission fails cause the packet unable to deliver to every node in the network.  $T_\\gamma$ is \naffected by three factors. \n1) clock stability, 2) duty cycle period ($T$) and 3) the radio on time. Assume clock stability $= \\pm$40~ppm,\n$T$ = 1~s and crystal start-up time = 1~ms. We assume $T_\\gamma$ = 1.5~ms in this case. Given these parameters,\nthe $T_{on, avg}$ in a linearly connected network is calculated as 15.84~ms.\n\\begin{table}[h]\n\\centering\n\t\\begin{tabular}{|c|c|}\n\t\\hline\n\t{\\bf parameters} & {\\bf value}\\\\ \\hline\n\t$K$ \t& 10\\\\ \\hline\n\t$T_p$ \t& 0.8~ms\\\\ \\hline\n\t$T_t$\t& 0.2155~ms\\\\ \\hline\n\t$N$\t\t& 6\\\\ \\hline\n\t$T_\\gamma$& 1.5~ms\\\\ \\hline\\hline\n\t$T_{on, avg}$& 15.84~ms\\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\n\\clearpage\n\\subsection{Grid network}\nConsidering a network structure that each node is {\\bf on grid} and the minimum distance between\neach node is 1. In addition, all the radio has its {\\bf radio range = 1}. In other words, the nodes\nin diagonal is out of 1 hop distance.\n\\begin{figure}[h]\n\\centering\n\t\\includegraphics[width=0.4\\columnwidth]{glossy_grid_topology}\n\t\\caption{Topology of grid network. The small circles are nodes and big circle indicates the \n\t1 hop radio range}\n\\end{figure}\n\nFrom previous session, we know the average of total distance for every initiator position in a linearly \nconnected network is equal to $\\tfrac{K^2-1}{3}\\equiv TD_0$. \nThe total distance of the column which next to the one hosts the initiator I. $TD_{D=1}$ can be written\nas:\n\\begin{equation}\n TD_{D=1} = TD_0 + K \n\\end{equation}\nWe can calculate the total distance for the grid network with any initiator location.\nFor example, if the initiator is located in the left most column. $TD_{grid\\ network,\\ I=W_0}$ can be written as:\n\\begin{align}\n\t\\nonumber\n\tTD_{grid\\ network,\\ I=W_0} \t&= TD_0 + TD_{D=1} + TD_{D=2} +\\cdots TD_{D=W-2} + TD_{D=W-1}\\\\\n\t\t\t\t\t\t&= TD_0 + (TD_0+K) + (TD_0+2K) +\\cdots (TD_0 + (W-2)K) + (TD_0 + (W-1)K)\\\\\n\t\t\t\t\t\t&= W\\times TD_0 + K\\times \\displaystyle\\sum\\limits_{j=1}^{W-1} j\n\\end{align}\nThe average distance over entire nodes in a grid network in this case is:\n\\begin{equation}\n\tD_{avg,\\ I=W_0} = \\tfrac{TD_{grid\\ network,\\ I=W_0}}{W\\times K}\n\\end{equation}\nSimilarly, the initiator could located in any column. The sum of total distance for every columns is following:\n\\begin{align}\n\t\\nonumber\n\tTD_{total\\ distance\\ for\\ every\\ column}\t&= TD_{grid\\ network,\\ I=W_0} + TD_{grid\\ network,\\ I=W_1} \n\t+ \\cdots TD_{grid\\ network,\\ I=W_W}\\\\ \n\t&= W^2\\times TD_0 + K\\displaystyle\\sum\\limits_{j=1}^W\\{\\displaystyle\\sum\\limits_{i=0}^{W-j} i + \\displaystyle\\sum\\limits_{i=0}^{j-1} i\\}\\\\\n\t&= W^2\\times TD_0 + K\\times\\tfrac{W(W^2-1)}{3}\n\\end{align}\nTherefore, the averaged total distance of the grid network is:\n\\begin{align}\n\tTD_{total\\ distance,\\ avg}\t&= TD_{total\\ distance\\ for\\ every\\ column}/W\\\\\n\t&= W\\times TD_0 + \\tfrac{K(W^2-1)}{3}\\\\\n\t&= W\\times\\tfrac{K^2-1}{3} + K\\times\\tfrac{W^2-1}{3}\n\\end{align}\nThe average distance for each node is:\n\\begin{align}\n\tD_{avg} &= TD_{total\\ distance,\\ avg}/(W\\times K)\\\\\n\t&= \\tfrac{K^2-1}{3W} + \\tfrac{W^2-1}{3K}\n\\end{align}\nFrom equation~\\ref{eq:ton_avg}, we can conclude that the average on time of a node in a grid\nnetwork $T_{on,\\ avg,\\ grid}$ \n\\begin{equation}\n\tT_{on,\\ avg,\\ grid} = {[\\tfrac{K^2-1}{3W} + \\tfrac{W^2-1}{3K}]\\times(T_p + T_t)} + {T_\\gamma + (2N-1)T_P + (2N-2)T_t}\n\\end{equation}\n\nConsidering the grid network has the same depth (K) and width (W) equal to 5 hops and diagonal of the\nnetwork is 8 hops. Since any node in the network has at least 2 neighbors, the number of transmission\ncan reduce to 3 with reliable flooding. We calculate the average on time of the node in grid network\nwith following parameters:\n\\begin{table}[h]\n\\centering\n\t\\begin{tabular}{|c|c|}\n\t\\hline\n\t{\\bf parameters} & {\\bf value}\\\\ \\hline\n\t$K$ \t& 5\\\\ \\hline\n\t$W$\t\t& 5\\\\ \\hline\n\t$T_p$ \t& 0.8~ms\\\\ \\hline\n\t$T_t$\t& 0.2155~ms\\\\ \\hline\n\t$N$\t\t& 3\\\\ \\hline\n\t$T_\\gamma$& 1.5~ms\\\\ \\hline\\hline\n\t$T_{on, avg}$& 9.6116~ms\\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "8afe3749800f5c3255856a7c8b532ad5fb9336a3", "size": 9790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "others/glossy_analysis/tex/ana.tex", "max_stars_repo_name": "lab11/uSDR", "max_stars_repo_head_hexsha": "4eeab36bcbea0e65c81f615975916ffd35d7de0b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-08-23T03:56:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T11:51:36.000Z", "max_issues_repo_path": "others/glossy_analysis/tex/ana.tex", "max_issues_repo_name": "lab11/uSDR", "max_issues_repo_head_hexsha": "4eeab36bcbea0e65c81f615975916ffd35d7de0b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "others/glossy_analysis/tex/ana.tex", "max_forks_repo_name": "lab11/uSDR", "max_forks_repo_head_hexsha": "4eeab36bcbea0e65c81f615975916ffd35d7de0b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-07-22T12:47:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-16T23:18:10.000Z", "avg_line_length": 49.1959798995, "max_line_length": 142, "alphanum_fraction": 0.6986721144, "num_tokens": 3442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199795472731, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.6748136235205041}}
{"text": "\\section{Bias and Variance for Learning in 1-D}\nIn this project, you will compare the difference between \\textit{approximation} (finding the best possible candidate to model a function) and \\textit{learning} (finding the best possible candidate given limited information). \nYou will also analyze the extra error that is incurred by using limited information, and you will explore one possible way of reducing this error.\\\\\n\n\\noindent\\textit{Approximation:}\\\\\nLet $f(x) = x^2(1-x)$ where $0 \\leq x \\leq 1$. We wish to find the `best' linear model (or approximation) for $f$. That is, for functions in the form $g(x; \\alpha, \\beta) =  \\alpha +  \\beta x$,  we wish to find the parameters $ \\alpha$ and $ \\beta$ that minimize the error we would expect to incur if we used the function $g$ to model (or approximate) the function $f$. \n\\begin{center}\n\\begin{tikzpicture}[xscale=5,yscale=10]\n\\draw[thick,domain=0:1,variable=\\x,orange!90!black] plot ({\\x},{.02 + .1*\\x}) node[above right] {$y = g(x; \\alpha, \\beta)$};\n\\draw[thick,domain=0:1,variable=\\x,blue] plot ({\\x},{\\x*\\x*(1-\\x)}) node[above right] {$y = f(x)$};\n  \\draw[->] (-.11, 0) -- (1.1, 0) node[right] {$x$};\n  \\draw[->] (0, -.02) -- (0, .2) node[above] {$y$};\n\\end{tikzpicture}\n\\end{center}\nFor this problem, we will define the error as\n\\begin{equation*}\n\\text{Error}(x;\\alpha,\\beta) = \\Big(f(x) - g(x; \\alpha, \\beta)\\Big)^2 \n\\quad \\text{and} \\quad\n\\text{TotalError}(\\alpha,\\beta) = \\int_0^1 \\text{Error}(x; \\alpha,\\beta) dx.\n% \\text{Error}(f,g) = \\int_0^1 \\bigg(f(x) - g(x; \\alpha, \\beta)\\bigg)^2 dx.\n\\end{equation*} \nUse pencil-and-paper (or Mathematica, WolframAlpha, etc) to find a simplified expression for the error between $f$ and $g$ as a function of the parameters $ \\alpha$ and $ \\beta$. Find the values of $ \\alpha$ and $ \\beta$ that minimize the total error and find the corresponding total error.\\\\\n\n\\noindent\\textit{Learning:}\\\\\nIn many practical applications, we only have imperfect knowledge of $f$, and therefore it is impossible to know the \\textit{best possible} parameters $\\alpha, \\beta$. \nOften, we must commit to a choice of sub-optimal parameters that are chosen after only a small glimpse of $f$. \nIn this project, you will estimate and explore the extra error incurred when using an imperfect choice of parameters.\\\\\n\\noindent\\textit{Terminology:} For each value of $x$, the \\textit{bias} of a model is defined as the the difference between $\\bar{g}(x;\\alpha,\\beta)$, the expected (or average) value of $g(x;\\alpha,\\beta)$, and the true value of $f$.\n\\begin{equation}\n\\text{Bias}(x) = \\bar{g}(x;\\alpha,\\beta) - f(x)\n\\end{equation}\n\\noindent\\textit{Terminology:} For each value of $x$, the \\textit{variance} of a model is defined as the expected (or average) value of the square of the difference between the value of $g(s;\\alpha,\\beta)$ and the expected value of $g(x;\\alpha,\\beta)$.\n\\begin{equation}\n\\text{Variance}(x) = \\bigg\\langle \\big( g(x;\\alpha,\\beta) - \\bar{g}(x;\\alpha,\\beta)\\big)^2 \\bigg\\rangle\n\\end{equation}\nImplement the following process to estimate how well a linear function that is parameterized by only two random data points can be used to model $f$.\n\\begin{enumerate}\\setlength{\\itemsep}{0pt}\n  \\item Create the variable \\texttt{xx} by discretizing the interval $0 \\leq x \\leq 1$ into 101 points. That is, set \\texttt{xx}$ = (0,\\, 0.01,\\, 0.02,\\, \\dots,\\, 1)$.  Plot $f(x)$ in blue. \n    \\item Generate two random data points on $x_1, x_2 \\in [0,1]$. \n    \\item Evaluate $y_1 =f(x_1)$ and $y_2 = f(x_2)$.  Plot $(x_1,y_1)$ and $(x_2,y_2)$ as two orange dots on the same figure as $f$. \n    \\item Using \\textbf{only} $(x_1,y_1)$ and $(x_2,y_2)$, compute a `best guess' for parameters $\\alpha$ and $\\beta$.\n    \\item Use your best guess parameters $\\alpha$ and $\\beta$ to evaluate the linear model $g(x;\\alpha, \\beta)$ for each $x \\in \\texttt{xx}$ and record the results. Plot $g(x;\\alpha,\\beta)$ in orange on the same figure.\n\\end{enumerate}\nRepeat steps 1-5 several times and save their plots.\\\\ \n\nRepeat steps 1-5 1000 times (without plotting) and record the results in a $101 \\times 1000$ array.\nFor each $x$, compute $\\bar{g}(x)$, the average value predicted by the linear model $g(x;\\alpha,\\beta)$ and plot it on the same figure as a plot of $f(x)$. \nOn the same figure, plot $g_{5}(x)$, $g_{25}(x)$, $g_{75}(x)$ and $g_{95}(x)$, the 5\\textsuperscript{th}, 25\\textsuperscript{th}, 75\\textsuperscript{th} and 95\\textsuperscript{th} quantiles of the values predicted by the linear model.  \\\\\n\n\\noindent\\textit{Error Reduction for Learning:}\\\\\nSomeone proposes that the variance is so big that it makes the linear model unusable.  \nThey suggest that we should approximate $f$ by a constant function  $h(x;\\alpha)$. \nRepeat the steps above to estimate the bias and the variance of the constant model. \\\\\n\n\n", "meta": {"hexsha": "d3478d3a3b23bb668ece20c6985d443093a2ea44", "size": 4807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bias-vs-variance.tex", "max_stars_repo_name": "colinlclark/integration_workshop", "max_stars_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bias-vs-variance.tex", "max_issues_repo_name": "colinlclark/integration_workshop", "max_issues_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bias-vs-variance.tex", "max_forks_repo_name": "colinlclark/integration_workshop", "max_forks_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-07-25T18:18:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T01:10:02.000Z", "avg_line_length": 85.8392857143, "max_line_length": 370, "alphanum_fraction": 0.6996047431, "num_tokens": 1527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.6748136124124634}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{../../shared/preamble}\n\\addbibresource{../../shared/references.bib}\n\n\\usepackage{sets}\n\n\\title{Sets}\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 concepts related to sets.\nIt has been type checked by \\fuzz.\n\\end{abstract}\n\n\\section{Introduction}\n\nTyped set theory forms the mathematical foundation of Z Notation\nand many concepts relating to set theory are defined by its built-in mathematical tool-kit. \nThis articles augments the tool-kit with some additional concepts.\n\n\\section{Arbitrary Sets}\n\n\\subsection{\\zcmd{setT}, \\zcmd{setU}, \\dots, \\zcmd{setZ}}\n\nLet $\\setT$, $\\setU$, and $\\setZ$ denote arbitrary sets.\nThese will be used throughout in the statement of theorems, remarks, and examples that are parameterized\nby arbitrary sets.\n\n\\begin{zed}\n\t[\\setT, \\setU, \\setV, \\setW, \\setX, \\setY, \\setZ]\n\\end{zed}\n\n\\section{Formal Arguments to Generic Constructions}\n\nThe following typographically distinctive symbols will be used as formal arguments to generic constructions:\n$\\genT, \\genU, \\genV, \\genW, \\genX, \\genY, \\genZ$. \nThey denote arbitrary sets.\n\n\\section{Families}\n\n\\subsection{\\zcmd{family}}\n\nLet $\\genT$ be a set.\nA {\\it family} of subsets of $\\genT$ is a set of subsets of $\\genT$.\nLet $\\family \\genT$ denote the set of all families of subsets of $X$.\n\n\\begin{zed}\n\t\\family \\genT == \\power(\\power \\genT)\n\\end{zed}\n\n\\section{Functions}\n\n\n\\subsection{\\zcmd{const}}\n\nLet $\\genT$ and $\\genU$ be sets and let $c \\in \\genU$ be some given point.\nThe mapping that sends every point of $\\genT$ to $c$ is called the {\\it constant mapping} defined by $c$.\nLet $\\const(c)$ denote the constant mapping.\n\n\\begin{gendef}[\\genT, \\genU]\n\t\\const: \\genU \\fun (\\genT \\fun \\genU)\n\\where\n\t\\forall c: \\genU @ \\\\\n\t\\t1\t\\const(c) = (\\lambda x: \\genT @ c)\n\\end{gendef}\n\n\n\\subsection{\\zcmd{restrictU}}\n\nLet $\\genT$ and $\\genU$ be sets, let $f: \\genT \\fun \\genU$, and let $T \\subseteq \\genT$.\nLet $f \\restrictU T$ denote the restriction of $f$ to $T$.\n\n\\begin{gendef}[\\genT, \\genU]\n\t\\_ \\restrictU \\_: (\\genT \\fun \\genU) \\cross \\power \\genT \\fun (\\genT \\pfun \\genU)\n\\where\n\t\\forall f: \\genT \\fun \\genU; T: \\power \\genT @ \\\\\n\t\\t1\tf \\restrictU T = T \\dres f\n\\end{gendef}\n\n\\subsection{$bit$}\n\nLet $bit$ denote the set of \\textit{binary digits}, namely the set $\\{ 0, 1\\} \\subseteq \\num$.\n\n\\begin{zed}\n\tbit == \\{ 0, 1 \\}\n\\end{zed}\n\n\\subsection{\\zcmd{B}}\n\nWe introduce the notation $\\B = bit$.\n\n\\begin{zed}\n\t\\B == bit\n\\end{zed}\n\n\\subsection{$indicator\\_function$}\n\nLet $\\genT$ be a set, \nlet $X$ be a subset of $\\genT$, and \nlet $a \\in \\genT$ be some element.\nThe \\textit{indicator function} or \\textit{characteristic function} of $X$ maps $a$ to 1 if $a \\in X$ and 0 otherwise.\nLet $indicator\\_function(X) \\in \\genT \\fun \\B$ denote this function.\n\n\\begin{gendef}[\\genT]\n\tindicator\\_function : \\power \\genT \\fun \\genT \\fun \\B\n\\where\n\t\\forall X : \\power \\genT @ \\\\\n\t\t\\t1 indicator\\_function(X) = \\\\\n\t\t\t\\t2 (\\lambda a : \\genT @ \\IF a \\in X \\THEN 1 \\ELSE 0)\n\\end{gendef}\n\n\\subsection{\\zcmd{indF}}\n\nWe introduce the notation $\\indF[\\genT](X) = indicator\\_function[\\genT](X)$.\n\n\\begin{zed}\n\t\\indF[\\genT] == indicator\\_function[\\genT]\n\\end{zed}\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "b1066f4125346f551d58006e97039aee3e534457", "size": 3329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/sets/sets.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/sets/sets.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/sets/sets.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": 26.0078125, "max_line_length": 118, "alphanum_fraction": 0.6887954341, "num_tokens": 1095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.6748136052624499}}
{"text": "\\documentclass[11pt,a4paper]{article}\n\\usepackage{microtype}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amsthm}\n\n\\newcommand{\\dpar}[1]{\\left(#1\\right)}\n\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\theoremstyle{definition}\n\\newtheorem{ex}{Exercise}\n\n\\title{Physics 3: Class 6}\n\\author{Max Jauregui}\n\n\\begin{document}\n\\maketitle\n\n\\section{Electric potential}\n\nLet us consider a system of charges and let us suppose that we want to\nbring a particle with charge $q$ from an infinite distance to a\nposition $\\mathbf{r}$ following a trajectory $C$. The necessary energy\nto perform this task, denoted by $U(q,\\mathbf{r})$, is proportional to\n$q$. Then, we can define an energy per unit of charge, which is called\nthe \\emph{electric potential} of the system, by\n$$V(\\mathbf{r})=\\frac{U(q,\\mathbf{r})}{q}\\,.$$\nThe unit of electric potential in the SI is the volt (V).\n\nIn terms of the electric force, the energy $U(q,\\mathbf{r})$ can be\nwritten as\n$$U(q,\\mathbf{r})=-\\int_C\\mathbf{F}_e\\cdot d\\mathbf{r}\\,.$$\nSince $\\mathbf{F}_e=q\\mathbf{E}$, where $\\mathbf{E}$ is the electric\nfield generated by the system, we have\n$$U(q,\\mathbf{r})=-q\\int_C \\mathbf{E}\\cdot d\\mathbf{r}\\,.$$\nThis implies that the electric potential of the system of charges is\ngiven by\n\\begin{equation}\n  \\label{eq:1}\n  V(\\mathbf{r})=-\\int_C\\mathbf{E}\\cdot d\\mathbf{r}\\,.\n\\end{equation}\n\nThe electric potential of a particle with charge $Q$, localized at the\norigin of our coordinate system, at a point $\\mathbf{r}$ is\n\\begin{eqnarray*}\n  V(\\mathbf{r})&=&-\\int_C\\frac{Q}{4\\pi \\epsilon_0}\\frac{\\mathbf{r'}}{(r')^3}\\,\\cdot d\\mathbf{r}'\\\\\n               &=&-\\int_{t_1}^{t_2}\\frac{Q}{4\\pi \\epsilon_0[r'(t)]^3}\\mathbf{r'(t)}\\cdot\\frac{d\\mathbf{r}'}{dt}\\,dt\\\\\n               &=&-\\int_{t_1}^{t_2}\\frac{Q}{4\\pi \\epsilon_0[r'(t)]^3}r'(t)\\frac{dr'}{dt}\\,dt\\\\\n               &=&-\\int_{\\infty}^{r}\\frac{Q}{4\\pi \\epsilon_0(r')^2}\\,dr'\\,.\n\\end{eqnarray*}\nTherefore,\n$$V(\\mathbf{r})=\\frac{Q}{4\\pi\\epsilon_0}\\frac{1}{r}\\,.$$\n\nIf the particle of charge $Q$ is at a position $\\mathbf{r'}$, the\nelectric potential at a point $\\mathbf{r}$ will be given by\n$$V(\\mathbf{r})=\\frac{Q}{4\\pi\\epsilon_0}\\frac{1}{|\\mathbf{r}-\\mathbf{r}'|}\\,.$$\n\nIf we have a system of $n$ charges $q_1,\\ldots,q_n$, the electric\npotential at a point $\\mathbf{r}$ will be given by\n$$V(\\mathbf{r})=\\sum_{i=1}^n\\frac{q_i}{4\\pi\\epsilon_0}\\frac{1}{|\\mathbf{r}-\\mathbf{r}_i|}\\,.$$\nIn the case of a continuous distribution of charges with charge\ndensity $\\rho(\\mathbf{r})$, the electric potential at a point\n$\\mathbf{r}$ will be\n$$V(\\mathbf{r})=\\int_{\\R^3}\\frac{\\rho(\\mathbf{r}')}{4\\pi\\epsilon_0|\\mathbf{r}-\\mathbf{r}'|}\\,dV'\\,.$$\n\nLet us consider a charged particle that is initially at a position\n$\\mathbf{r}_1$ and moves slowly to a position $\\mathbf{r}_2$\ndescribing a trajectory $C$ under the action of an external electric\nfield $\\mathbf{E}$. Then, it follows from Eq.~(\\ref{eq:1}) that\n$$\\int_C\\mathbf{E}\\cdot d\\mathbf{r}=V(\\mathbf{r}_1)-V(\\mathbf{r}_2)\\,.$$\nIn particular, if $\\mathbf{r}_1=\\mathbf{r}_2$, we have\n$$\\oint_C\\mathbf{E}\\cdot d\\mathbf{r}=0\\,.$$\n\n\\end{document}", "meta": {"hexsha": "bf12fdd74b563b25ad0265755ae87045c7974ea0", "size": 3112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fisica3/aula6.tex", "max_stars_repo_name": "maxjaure/UEM-DFI", "max_stars_repo_head_hexsha": "fe1b3ba629ab475d92b6140f49cf397f0b6120fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-25T18:25:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-25T18:25:46.000Z", "max_issues_repo_path": "fisica3/aula6.tex", "max_issues_repo_name": "maxjaure/UEM-DFI", "max_issues_repo_head_hexsha": "fe1b3ba629ab475d92b6140f49cf397f0b6120fc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fisica3/aula6.tex", "max_forks_repo_name": "maxjaure/UEM-DFI", "max_forks_repo_head_hexsha": "fe1b3ba629ab475d92b6140f49cf397f0b6120fc", "max_forks_repo_licenses": ["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.9473684211, "max_line_length": 117, "alphanum_fraction": 0.6706298201, "num_tokens": 1158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6748135934865549}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{Spring fever}{Spring fever}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Spring fever\n\\end{center}\n\n The second-order ODE\n\\[\n  y'' + \\gamma y' + 2y = \\sin(t)\n\\]\ndescribes the simple harmonic oscillation of (for example) a mass\nsuspended by a spring and subjected to a periodic force. The constant\n$\\gamma$ models damping due to friction. Neglecting the friction, the\nnatural frequency of oscillation is $\\omega_0=\\sqrt{2}$, and the total\nmotion combines the natural oscillation with that of the driving\nexternal force. If $\\gamma>0$, however, the unforced solution dies\noff, and the oscillation is driven entirely by the external force.\n\nOne complication in assessing variable-step automatic integrators, such as the RK23 method described in the text, is that we mathematically describe convergence as being at the rate $O(h^p)$ for a fixed step size $h$. If we look instead at the total number $n$ of steps taken by the method over time interval $[a,b]$, then the ``average step size'' is $(b-a)/n$ and we can hope for convergence of $O(n^{-p})$. \n\n\\subsection*{Goals}\n\nYou will use the driven spring problem to assess the convergence of the \\texttt{rk23} function given in the text.\n\n\\subsection*{Preparation}\n\nRead section 6.5. Write the ODE as the first-order system $\\bfu' = \\bff(t,\\bfu)$. (That is, write out exactly what the function $\\bff$ is.) \n\n\\subsection*{Procedure}\n\nDownload the script template and complete it to perform the following steps. Throughout this lab, use $0\\le t \\le 20$ and $y(0)=0$, $y'(0)=0$.\n\n\\begin{enumerate}\n\\item Consider the ODE as a first-order system, $\\bfu'=\\bff(t,\\bfu)$. In a separate file, write a function \n\\begin{verbatim}\nfunction f = myspring(t,u,gamma)\n\\end{verbatim} that defines the ODE by returning the value of $\\bff$ for any given $t$ and $\\bfu$. \n\n\\item Define \\texttt{u0} as the initial condition of the first-order system and let $\\gamma=10$. Create a reference solution using the syntax\n\\begin{verbatim}\ndudt = @(t,u) myspring(t,u,10);\nopt = odeset('reltol',1e-13,'abstol',1e-13);\n[t,u_ref] = ode15s(dudt,[0 20],u0,opt);\n\\end{verbatim}\n  where \\texttt{u0} is defined appropriately. Plot the solution $y(t)$ as a function of $t$, using a title and labeled axes. In the title or as text on the plot, include the number of time steps that were taken by the solver.\n\n\\item Use the adaptive \\texttt{rk23} solver from the text to solve the\n  problem with the \\texttt{tol} argument set to $10^{-4}$. Make a\n  phase plot of the solution (i.e., with $y$ on the horizontal axis\n  and $y'$ on the vertical axis). Don't forget labels and a title.\n\n\\item Use \\texttt{rk23} to solve the problem with each of the error\n  tolerances $10^{-2}$, $10^{-3}$, \\ldots, $10^{-12}$ in turn. After each\n  solution, record in two vectors the number of time steps\n  taken, $n$, and the global error, $E_n=\\| \\bfu_{\\text{ref}}(20) - \\bfu(20)\\|$. (\\emph{Important}: This is at the final time $t=40$, \\emph{not} the solution in the 30th row of the output from \\texttt{rk23}.) Output a table with each row giving the tolerance, $n$, and $E_n$. \n\n\\item On a new graph, make a log-log plot of $E_n$ versus $n$. The points\n    should mostly lie close to a straight line. Add to the plot two\n    straight lines indicating perfect second- and third-order convergence,\n    $E_n=n^{-2}$ and $E_n=n^{-3}$.\n    \n\\item Now let $\\gamma=5000$. Repeat steps 2--3.\n    \n\\item Repeat steps 4--5 (still with $\\gamma=5000$). The results will be very different.\n\\end{enumerate}\n\n\\subsection*{Discussion}\n\nThe time stepping in \\texttt{rk23} is supposed to be third-order\naccurate. But that is a statement about the mathematical limit\n$h\\to 0$, or $n\\to \\infty$. For particular finite values of $n$, we\nmight observe something close to the ideal $E_n=Cn^{-3}$, but just\nabout anything is possible. \n\nIn fact, for this spring problem with $\\gamma=5000$, the time step\nsize adaptation is being constrained by something other than\nthird-order accuracy. The mathematics behind this observation is\nconsidered in Chapter 10.\n\n\n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "c909ba9dce7124991bd73688ce13d0b1aadc3632", "size": 4266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter06/SpringFever/SpringFever.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/chapter06/SpringFever/SpringFever.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/chapter06/SpringFever/SpringFever.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": 43.0909090909, "max_line_length": 410, "alphanum_fraction": 0.7219878106, "num_tokens": 1214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.900529776774399, "lm_q1q2_score": 0.6745753408107622}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Draw the complex numbers $z = 2+i$ and $w = -2+3i$ as points in the\n  plane. Then use the geometric interpretation to find $z+w$,\n  $z-w$, $zw$, $z^{-1}$, $\\conjugate{z}$, and $\\abs{z}$.\n\\end{ex}\n\n\\begin{ex}\n  Use the geometric interpretation to find a complex number $z$ such\n  that $z^2 = i$. Can you find two such numbers?\n  \\begin{sol}\n    Since $i$ has magnitude $1$ and argument $\\pi/2$ (or\n    $90^{\\circ})$, the number $z$ must have magnitude $1$ and argument\n    $\\pi/4$. It therefore lies at $45^{\\circ}$ on the unit circle. The\n    solution is $z=\\frac{1+i}{\\sqrt{2}}$. A second solution is\n    $-z=-\\frac{1+i}{\\sqrt{2}}$, whose argument is $-3\\pi/4$ or\n    $-135^{\\circ}$. Note that if we double this angle, we get\n    $-270^{\\circ}$, which is the same as $+90^{\\circ}$.\n    \\begin{equation*}\n      \\begin{tikzpicture}[scale=1.7]\n        \\draw[black!30] (0,0) circle (1);\n        \\draw[->](-1.5,0) -- (1.5,0);\n        \\draw[->](0,-1.25) -- (0,1.25);\n        \\draw(0,-1) -- +(-0.2,0) node[left,yshift=-3pt] {$-i$};\n        \\draw(0,1) -- +(-0.2,0) node[left,yshift=3pt,red] {$i$};\n        \\draw(-1,0) -- +(0,-0.2) node[below,xshift=-3pt] {$-1$};\n        \\draw(1,0) -- +(0,-0.2) node[below,xshift=3pt] {$1$};\n        \\draw[ultra thick, red] (0,0) -- (90:1);\n        \\draw[ultra thick, blue] (0,0) -- (45:1);\n        \\draw[ultra thick, purple!70!blue] (0,0) -- (225:1);\n        \\draw[fill, black] (45:1) circle [radius=1.06pt] node [right=2mm, blue] {$z = \\frac{1+i}{\\sqrt{2}}$};\n        \\draw[fill, black] (225:1) circle [radius=1.06pt] node [left=2mm, purple!70!blue] {$-z = -\\frac{1+i}{\\sqrt{2}}$};\n        \\draw[fill, black] (90:1) circle [radius=1.06pt];\n      \\end{tikzpicture}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the geometric interpretation to find 3 different complex numbers\n  $z$ such that $z^3 = -1$. Hint: these numbers will lie on the unit\n  circle.\n  \\begin{sol}\n    The three solutions can be found on the unit circle at\n    $60^{\\circ}$, $180^{\\circ}$, and $300^{\\circ}$. If we triple any\n    of these angles, we get $180^{\\circ}$ (up to multiples of $360^{\\circ}$).\n    Thus, the three cube roots of $-1$ are $z=-1$ and $z=0.5\\pm\\sqrt{0.75}\\,i$.\n    \\begin{equation*}\n      \\begin{tikzpicture}[scale=1.7]\n        \\draw[black!30] (0,0) circle (1);\n        \\draw[->](-1.15,0) -- (1.5,0);\n        \\draw[->](0,-1.25) -- (0,1.25);\n        \\draw[ultra thick, blue] (0,0) -- (60:1);\n        \\draw[ultra thick, red] (0,0) -- (180:1);\n        \\draw[ultra thick, purple!70!blue] (0,0) -- (300:1);\n        \\draw[fill, black] (60:1) circle [radius=1.06pt] node [right=2mm,blue] {$0.5+\\sqrt{0.75}\\,i$};\n        \\draw[fill, black] (180:1) circle [radius=1.06pt] node [left=2mm,red] {$-1$};\n        \\draw[fill, black] (300:1) circle [radius=1.06pt] node [right=2mm,purple!70!blue] {$0.5-\\sqrt{0.75}\\,i$};\n      \\end{tikzpicture}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "7ac85a8fbcc05fa50162073655d701f0a5a28dc1", "size": 2940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/ComplexNumbers-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/ComplexNumbers-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/ComplexNumbers-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 45.2307692308, "max_line_length": 121, "alphanum_fraction": 0.5568027211, "num_tokens": 1170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.6744523314897457}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\title{Soil Carbon Models}\n\\date{12/9/2016}\n\\begin{document}\n\\maketitle\n\\section*{Century Model}\nThe century model is proposed by Parton et al. (1988). We only focus on the three soil pools in this model which are listed below along with their decomposition rates:\n\n\\begin{itemize}\n\\item[pool 1:] \\makebox[2.5cm]{Active Soil C,\\hfill}  $\\kappa_1 \\approx 1/1.5$,\n\\item[pool 2:] \\makebox[2.5cm]{Slow Soil C,\\hfill} $\\kappa_2 \\approx 1/25$,\n\\item[pool 3:] \\makebox[2.5cm]{Passive Soil C,\\hfill}  $\\kappa_3 \\approx 1/1000$,\n\\end{itemize}\nwhere $\\kappa$ denotes the decay rate which is defined as 1 over the turnover. \n\nWe denote the transfer rate from pool $j$ to pool $i$ by $r_{ij}$. The transfer rates are parameterized as a ratio of the decay rate: $r_{ij} = \\alpha_{ij} \\kappa_j$. For the Century model, we have:\n\\begin{align*}\n\\alpha_{21} & = 1 - F(\\text{T}) - 0.004, \\\\\n\\alpha_{31} & = 0.004, \\\\\n\\alpha_{12} & = 0.42, \\\\\n\\alpha_{32} & = 0.03, \\\\\n\\alpha_{13} & = 0.45, \\\\\n\\alpha_{23} & = 0,\n\\end{align*}\nwhere `T' is the soil silt + clay content, and $F(\\text{T}) = 0.85 - 0.68 \\times \\text{T}$. These values are expert-tuned; however, in our Bayesian framework, we estimate them from the data. For each pool, we can write the following differential equation:\n\\begin{equation*}\n\\frac{d C_i(t)}{dt} = -\\kappa_i C_i(t) + \\sum_{j\\neq i} \\alpha_{ij} \\kappa_j.\n\\end{equation*}\nCombining all these differential equations into a single formula, we get:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \n   \\left( {\\begin{array}{ccc}\n   -\\kappa_1 & \\alpha_{12} \\kappa_2 & \\alpha_{13}\\kappa_3 \\\\\n    \\alpha_{21}\\kappa_1 & -\\kappa_2& 0  \\\\\n    \\alpha_{31} \\kappa_1 & \\alpha_{32} \\kappa_2 & -\\kappa_3    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\nThe total amount of Carbon in the beginning is $C_{tot}$ which is divided among the three pools: $C(0) = (\\gamma_1, \\gamma_2, \\gamma_3) \\cdot C_{tot}$. \n\n\n\\section{Outline of Simulations}\n\n\\subsection{Data generation and fitting models}\nWe generate simulated data from the century model above, and fit the following six models to the simulated data:\n\n\\begin{enumerate}\n\\item Independent Model:  \n\\begin{equation*}\n\\frac{dC(t)}{dt} = \n   \\left( {\\begin{array}{ccc}\n   -\\kappa_1 & 0 & 0 \\\\\n    0 & -\\kappa_2& 0  \\\\\n    0 & 0 & -\\kappa_3    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\item Cascade Model:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \n   \\left( {\\begin{array}{ccc}\n   -\\kappa_1 & 0 & 0 \\\\\n    \\alpha_{21}\\kappa_1 & -\\kappa_2& 0  \\\\\n    \\alpha_{31} \\kappa_1 & \\alpha_{32} \\kappa_2 & -\\kappa_3    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\item Feedback Model:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \n   \\left( {\\begin{array}{ccc}\n   -\\kappa_1 & \\alpha_{12} \\kappa_2 & \\alpha_{13}\\kappa_3 \\\\\n    \\alpha_{21}\\kappa_1 & -\\kappa_2& \\alpha_{23} \\kappa_3 \\\\\n    \\alpha_{31} \\kappa_1 & \\alpha_{32} \\kappa_2 & -\\kappa_3    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\item Century Model:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \n   \\left( {\\begin{array}{ccc}\n   -\\kappa_1 & \\alpha_{12} \\kappa_2 & \\alpha_{13}\\kappa_3 \\\\\n    \\alpha_{21}\\kappa_1 & -\\kappa_2& 0  \\\\\n    \\alpha_{31} \\kappa_1 & \\alpha_{32} \\kappa_2 & -\\kappa_3    \n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\item Two-pool Model:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = \n   \\left( {\\begin{array}{cc}\n   -\\kappa_1 & \\alpha_{12} \\kappa_2  \\\\\n    \\alpha_{21}\\kappa_1 & -\\kappa_2  \\\\\n   \\end{array} } \\right) C(t).\n\\end{equation*}\n\\item One-pool Model:\n\\begin{equation*}\n\\frac{dC(t)}{dt} = -\\kappa_1 C(t).\n\\end{equation*}\n\\end{enumerate}\n\nFor generating the simulated data, we use the expert-tuned values for decomposition and transfer parameters and also assume $\\gamma_1=\\gamma_2=0.1$ and $\\gamma_3=0.8$.  \n\\subsection{CO$_2$ flux}\nWe assume that our observations are in terms of CO$_2$ fluxes. Theoretically, the CO$_2$ flux at time $t$ is defined as $\\sum_{i=1}^3 |{dC_i(t)}/{dt}|$. In experiments, this is calculated by measuring the CO$_2$ emitted between a cap time, $t_{cap}$ and $t$: ${\\Delta CO_2}/(t - t_{cap})$. \n\n\n\\subsection{Sampling times}\nGenerally, the sampling times are not uniform. The CO$_2$ flux is sampled more frequently in the beginning and then less frequently towards the end. A common practice is to sample once per day for the first week, then once per week for the first month, and then once per month. Given that the scale of the turnover rates are in years, this amounts to the following sampling times:\n\\begin{equation*}\nt_s = (\\frac{1}{360}, \\frac{2}{360}, \\frac{3}{360}, \\frac{4}{360}, \\frac{5}{360}, \\frac{6}{360}, \\frac{7}{360}, \\frac{14}{360}, \\frac{21}{360}, \\frac{28}{360}, \\frac{60}{360}, \\frac{90}{360}, \\frac{120}{360}, \\ldots) \n\\end{equation*}\n\n\\subsection{Observation error}\nFrom empirical studies we know that the noise standard deviation is approximately half the value of the flux.  We simulate this by averaging the values of simulated CO$_2$ flux and dividing by two to set the value for noise standard deviation. \n\n\\subsection{Replications}\nGenerally, we have several replications for each experiment (i.e., several CO$_2$ fluxes). We can fit these replicates in three ways:\n\\begin{enumerate}\n\\item No pooling: fitting models separately to each model, i.e., estimating the model parameters independently for each replication;\n\\item Complete pooling: fitting a single model to all the replications, i.e., estimating only a single set of parameters for all models;\n\\item Partial pooling: fitting a hierarchical Bayesian model which estimates parameters jointly for all replications and allows for variation between replicates.\n\\end{enumerate}\n\\section{Statistical models}\nAs mentioned in the previous section, we fit the data in three ways: no pooling, complete pooling, and partial pooling using a hierarchical model. \n\n\\subsection{No pooling and complete pooling} \nIn terms of model specification, no pooling and complete pooling are similar; the only difference is the data provided for likelihood computations. For complete pooling, all the data is used for parameter estimation and for no pooling, each replication is used separately. \n\n\\begin{itemize}\n\\item {\\bf Turnover rates: } we assume a prior which is centered around the values chosen by experts. We believe that the estimated values should be around these values; so, we set the standard deviations to be $1/10$'th of the mean times a Cauchy random variable.  Therefore, we enforce the standard deviation to be small, but let the data specifies the exact value. We can check the sensitivity of the results to these assumptions later. \n\\begin{align*}\n\\tau_1  \\sim  \\mathcal{N}(1.5, 0.15 \\sigma_1) \\qquad\n\\tau_2  &\\sim \\mathcal{N}(25, 2.5 \\sigma_2) \\qquad\n\\tau_3 \\sim \\mathcal{N}(1000,100 \\sigma_3) \\\\ \\sigma_1 \\sim \\text{Cauchy}(0,1) \\qquad  \\sigma_2 &\\sim \\text{Cauchy}(0,1) \\qquad \\sigma_3 \\sim \\text{Cauchy}(0,1)\n\\end{align*}\nThe decomposition rates are then $\\kappa_1=1/\\tau_1, \\kappa_2=1/\\tau_2, \\kappa_3=1/\\tau_3$.\n\\item {\\bf Initial allocations: } the vector $(\\gamma_1, \\gamma_2, \\gamma_3)$ governs how the Carbon is initially divided between the three pools. We know that $\\gamma_1+\\gamma_2+\\gamma_3=1$; so, the vector is simplex. We assign a uniform prior to this vector:\n\\begin{align*}\n(\\gamma_1, \\gamma_2, \\gamma_3) \\sim \\text{Dirichlet}(1,1,1)\n\\end{align*}\n\\item {\\bf Transfer rates: } the transfer rates are between 0 and 1 and are given a uniform prior with the following constraints for each $j$:\n\\begin{equation*}\n\\sum_{i \\ \\text{s.t.} \\ i\\neq j}{a_{ij}} < 1, \\qquad j=1, 2, 3\n\\end{equation*}\nWe can model this inequality constraint as an equality in the form of a simplex vector. For example, we can write:\n\\begin{align*}\na_{11} + a_{21} + a_{31} = 1,\n\\end{align*}\nwhere $a_{11}$ is a nuisance parameter which is not used in the model but enforces the inequality constraint. Thus, we can write:\n\\begin{align*}\n(a_{11}, a_{21}, a_{31}) & \\sim \\text{Dirichlet}(1,1,1) \\\\\n(a_{12}, a_{22}, a_{32}) & \\sim \\text{Dirichlet}(1,1,1) \\\\\n(a_{13}, a_{23}, a_{33}) & \\sim \\text{Dirichlet}(1,1,1)\n\\end{align*} \n\\end{itemize}\n\n\\subsection{Partial pooling (hierarchical model)}\nWe assume that we have $K$ replications. For each parameter, we have a global value, denoted by the superscript $0$, and local values for each replication, denoted by a superscript $k$ where $k=1,\\ldots, K$.\nThe global parameters have priors identical to the ones in the no pooling model. The local parameter are equal to these global parameters plus some variability. \n\n\\begin{itemize}\n\\item {\\bf Turnover rates: }\n\\begin{align*}\n\\tau_1^0  \\sim  \\mathcal{N}(1.5, 0.15 \\sigma_1) \\qquad\n\\tau_2^0  &\\sim \\mathcal{N}(25, 2.5 \\sigma_2) \\qquad\n\\tau_3^0 \\sim \\mathcal{N}(1000,100 \\sigma_3) \\\\ \\sigma_1 \\sim \\text{Cauchy}(0,1) \\qquad  \\sigma_2 &\\sim \\text{Cauchy}(0,1) \\qquad \\sigma_3 \\sim \\text{Cauchy}(0,1) \\\\\n\\tau_1^k \\sim \\mathcal{N}(\\tau_1^0, 0.15 \\sigma_4) \\qquad\n\\tau_2^k &\\sim \\mathcal{N}(\\tau_2^0, 2.5 \\sigma_5) \\qquad \n\\tau_3^k \\sim \\mathcal{N}(\\tau_3^0, 100 \\sigma_6) \\\\ \\sigma_4 \\sim \\text{Cauchy}(0,1) \\qquad  \\sigma_5 &\\sim \\text{Cauchy}(0,1) \\qquad \\sigma_6 \\sim \\text{Cauchy}(0,1)\n\\end{align*}\n\\item {\\bf Initial allocations: }\n\\begin{align*}\n(\\gamma_1^0, \\gamma_2^0, \\gamma_3^0) &\\sim \\text{Dirichlet}(1,1,1) \\\\\n(\\gamma_1^k, \\gamma_2^k, \\gamma_3^k) &\\sim \\text{Dirichlet}(\\gamma_1^0, \\gamma_2^0, \\gamma_3^0)\n\\end{align*}\nAnother possibility is:\n\\begin{align*}\n(\\gamma_1^0, \\gamma_2^0, \\gamma_3^0) &\\sim \\text{Dirichlet}(1,1,1) \\\\\n(\\lambda_1^k, \\lambda_2^k, \\lambda_3^k) &\\sim \\mathcal{N}((\\gamma_1^0, \\gamma_2^0, \\gamma_3^0), \\Sigma) \\\\\n(\\gamma_1^k, \\gamma_2^k, \\gamma_3^k) & = \\frac{(\\lambda_1^k, \\lambda_2^k, \\lambda_3^k)}{\\lambda_1^k+ \\lambda_2^k+ \\lambda_3^k}\n\\end{align*}\n\\item {\\bf Transfer rates: } As described in the previous section, by introducing a nuisance parameter, we can model the transfer rates as simplex vectors. A hierarchical structure can then be imposed in exact same way as explained in the previous paragraph for initial allocations. \n\\end{itemize}\n\n\n\n\\end{document}", "meta": {"hexsha": "f061f2adb76570bd1d32923704a76c499f7c0354", "size": 10144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex_files/outline_of_experiments.tex", "max_stars_repo_name": "ktoddbrown/decomPower", "max_stars_repo_head_hexsha": "4197b1a64f8d04712323f58918400d8054c681fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-12T23:45:51.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-15T01:09:35.000Z", "max_issues_repo_path": "tex_files/outline_of_experiments.tex", "max_issues_repo_name": "ktoddbrown/decomPower", "max_issues_repo_head_hexsha": "4197b1a64f8d04712323f58918400d8054c681fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-01-18T18:14:51.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-15T18:43:38.000Z", "max_forks_repo_path": "tex_files/outline_of_experiments.tex", "max_forks_repo_name": "ktoddbrown/decomPower", "max_forks_repo_head_hexsha": "4197b1a64f8d04712323f58918400d8054c681fe", "max_forks_repo_licenses": ["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.9574468085, "max_line_length": 440, "alphanum_fraction": 0.6981466877, "num_tokens": 3530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.6744523227014111}}
{"text": "\\section{$\\S$ Complex Numbers}\n\\subsection{Definition and Forms}\n\n\\textbf{Definition of $i$}: $i = \\sqrt{-1}$, $i^2 = -1$, $i^3 = -i$, $i^4 = 1$ \\\\\n\\textbf{Rectangular form}: $a+bi$. \\\\\n\\textbf{Exponential form}: $re^{i\\theta}$ where $r$ is the magnitude and $\\theta$ is the angle around the polar plane.\n\n", "meta": {"hexsha": "dbd1faa1c39ceb81c875c0952f952300012a1bc9", "size": 306, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/precalculus/complex-numbers.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/precalculus/complex-numbers.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/precalculus/complex-numbers.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": 38.25, "max_line_length": 118, "alphanum_fraction": 0.6339869281, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142217223021, "lm_q2_score": 0.7090191214879992, "lm_q1q2_score": 0.674378019265614}}
{"text": "\\section{Groups}\n\n\\subsection{Groups and Symmetry}\n\n\\subsubsection{Exercise 2}\nMap each element $x \\in \\mathbb{Z}_6$ to the pair $(p_2(x), p_3(x))$.\nThis is an isomorphism, since the projections $\\mathbb{Z}_6 \\to \\mathbb{Z}_3$ \nand $\\mathbb{Z}_6 \\to \\mathbb{Z}_3$ are both group morphisms, and the mapping\nitself is a bijection.\n\n\\subsubsection{Exercise 3}\nTo see that there is no isomorphism $f: \\mathbb{Z}_4 \\to \\mathbb{Z}_2 \\times \\mathbb{Z}_2$, \nconsider $f(1)$ and $f(3)$. We have that $f(0) = f(1 + 3) = f(1) + f(3)$ which is not\npossible since $f(0) = (0, 0)$ (has to be the case since $f(x) = f(0) + f(x)$ ).\n\nRotations do not preserve symmetry for rectangles, since distances between adjacent\nvertices change. The only transformations that preserve symmetry are reflections\nacross the vertical and horizontal axes, giving 4 possible transformations. We can\nthen map $(0, 0)$ to the identity, $(0, 1)$ to a vertical reflection, $(1, 0)$ to\na horizontal reflection, and $(1, 1)$ to a vertical + horizontal reflection.\n\n\\subsubsection{Exercise 4}\n\n\\subsubsection{Exercise 5}\n\n\\subsubsection{Exercise 6}\n\n\\subsubsection{Exercise 10}\nThe set of these permutations has identity  $(1, 0)$, and any permutation $(a, b)$ has\ninverse $(\\frac{1}{a}, -\\frac{b}{a})$. Furthermore, $(a_2, b_2) \\circ (a_1, b_1) = (a_1 a_2, a_2 b_1 + b_2)$,\nwhich is associative since multiplication and addition are both associative.\n\n\\subsubsection{Exercise 11}\n(a) To show that the given function is a permutation on $\\mathbb{R}\\cup{\\infty}$, we need to show that it is a\nbijection from $\\mathbb{R}\\cup{\\infty} \\to \\mathbb{R}\\cup{\\infty}$.\nSuppose $f(x_1) = f(x_2)$. Then\n\\begin{align*}\n        \\frac{ax_1 + b}{cx_1 + d} &= \\frac{ax_2 + b}{cx_2 + d} \\\\\n        (ad - bc)x_1 &= (ad - bc)x_2 \\implies x_1 = x_2\n\\end{align*}\nSo $f$ is an injection from $\\mathbb{R}\\cup{\\infty} \\to \\mathbb{R}\\cup{\\infty}$. Furthermore, if\nwe set $f(x) = y$, we can solve for $x$, which gives us that $f$ is also a surjection.\n\n(b) I'm sure an inverse can be found, but it's tedious... Associativity then follows again from associativity\nof multiplication and addition.\n\n\\subsubsection{Exercise 12}\n\n\\subsubsection{Exercise 13}\n(a) Any automorphism of $\\mathbb{Z}_3$ has to fix 0. Thus, the only two automorphisms are the identity\nand the automorphism that swaps 1 and 2.\n\n(b) Fixing $(0, 0)$, we see that we can permute the remaining three elements as we want, giving\nthe isomorphism to $S_3$.\n\n(c) \n\n\\subsection{Rules of Calculation}\n\n\\subsubsection{Exercise 1}\n(a) Multiply by inverse and use associativity.\n\n(b) Associativity.\n\n(c) Associativity and then inverse of product.\n\n\\subsubsection{Exercise 2}\nMultiply by $a^{-1}$.\n\n\\subsubsection{Exercise 3}\nSince the unit is its own inverse, we're left with $2n - 1$ elements that need to be paired with one another.\nSince $2n - 1$ is odd, we have that one of the elements must be its own inverse.\n\n\\subsubsection{Exercise 4}\nAny group with 3 elements must be of the form $1, a, a^{-1}$. Thus, each of these groups is clearly\nisomorphic to the others.\n\n\\subsubsection{Exercise 5}\nI struggled to untie the ideas of cancellation and inverse, so I ended up looking up a hint for this one. To\nsee that an infinite set with cancellation does not need to be a group, consider $(\\mathbb{N}, +)$.\nThis is a monoid that was proven to have cancellation in chapter 1, but does not contain inverses.\n\nFor the case of a finite set $G$, we can use the fact that $f(x) = ax$ is an injection for any $a \\in G$, \nsince $ax = ay \\implies x = y$ by cancellation. Since $G$ is finite, $f$ is also a surjection. Therefore,\n$\\exists a \\: | \\: ax = 1$ which gives us that there is a left inverse. Applying the same logic using\n$f(x) = xa$ gives a right inverse, which completes the proof since these inverses must be equal.\n\n\\subsubsection{Exercise 6}\nLeft cancellation is possible due to left inverse and left unit.\nFurthermore, $uu = u \\implies (a' a) u = a' a \\implies a u = a$ by left cancellation, indicating that \n$u$ is also a right unit. Then we have that $u a' = a' u \\implies a' a a' = a' u \\implies a a' = u$, \nand $a'$ is also a right inverse. This proves that $X$ is a group.\n\n\\subsubsection{Exercise 7}\nWe proceed as directed in the hint. Since the equation $ua = a$ has solution $u$, and any $b$ \ncan be written as $b = ay$, we have $u b = u (ay) = ay = b$. Thus, $u$ is a left unit. Since\nthe equation $a'a = u$ also has a solution $a'$, we are done by Exercise 6.\n\n\\subsubsection{Exercise 10} \nSince each element of $G$ has a unique inverse, $f(a) = a^{-1}$ is a bijection. Additionally,\n$f(ab) = (ab)^{-1} = b^{-1} a^{-1} = f(b) f(a) = f(a) \\square^{\\text{op}} f(b)$.\n\n\\subsubsection{Exercise 11}\nAssociativity of $\\square$ immediately follows from the associativity of $G$ 's binary operation and\nthe fact that $p$ is a morphism. Additionally, since $p$ is an epimorphism, $\\forall x, \\: \\exists g\n\\: | \\: x = p(g)$. Since $u g = g u$, $p(u)$ is then the unit for $X$. Similarly, $p(g')$ is the\ninverse of $x$, thus making $X$ a group.\n\n\\subsubsection{Exercise 12}\n$b b_R = u \\implies b_L b b_R = b_L \\implies b_R b = b_L b = u$.\n\n\\subsection{Cyclic Groups}\nWe first show that $\\mathbb{Z}_n$ is generated only by those $c$ that are coprime to $n$. If \n$c$ is coprime to $n$, then $ac = 0$ only when $a = n$ since $c$ and  $n$ share no prime factors.\nThus, the subgroup generated by $c$ has order $n$ and is therefore all of $\\mathbb{Z}_n$. Similarly, \nif $c$ is a generator of $\\mathbb{Z}_n$, then $c$ has order $n$ and must therefore be coprime to $n$.\n\n\\subsubsection{Exercise 1}\nThe only possible generators are 1 and 5, since those are the only elements of $\\mathbb{Z}_6$ \nthat are coprime to 6.\n\n\\subsubsection{Exercise 2}\nThe endomorphisms of $\\mathbb{Z}_n$ are completely determined by the mapping of 1, so there are\nonly $n$ such endomorphisms.\n\n\\subsubsection{Exercise 3}\n5 is prime, so all elements of $\\mathbb{Z}_5$ other than 0 are coprime to it. \n\n\\subsubsection{Exercise 4}\n14 has 6 positive integers less than it that are coprime to it (3, 5, 7, 9, 11, 13).\n\n\\subsubsection{Exercise 5}\nThe two generators of $\\mathbb{Z}$ are $1$ and $-1$, as elements of $\\mathbb{Z}$ can be written as $-m$ or $m$.\n\n\\subsubsection{Exercise 7}\nIf $G$ is abelian, then $(g_1 g_2)^m$ can be rearranged to $g_1^m g_2^m$. If $(g_1 g_2)^m = g_1^m g_2^m$.\nThe reverse direction follows from the $m = 2$ case, $g_1 g_2 g_1 g_2 = g_1^2 g_2^2$.\n\n\\subsubsection{Exercise 8}\n$(g_1 g_2) (g_1 g_2) = 1 \\implies g_1 g_2 = g_2 g_1$.\n\n\\subsubsection{Exercise 9}\nThe automorphisms are all determined by the mappings of the generators; the isomorphisms follow from the\nnumber of generators of each group.\n\n\\subsubsection{Exercise 10}\n\n\\subsection{Subgroups}\n\n\\subsubsection{Exercise 1}\nThe subgroup mapping a given diagonal to itself consists of $\\{1, R^3, D, D'\\}$, where\n$R^3$ is 3 clockwise rotations, $D$ is reflection across the given diagonal, and $D'$ is\nreflection across the diagonal perpendicular to the given. Mapping those elements to\n$\\{(0, 0), (1, 1), (0, 1), (1, 0)\\}$ (in order) is an isomorphism.\n\n\\subsubsection{Exercise 4}\nIf $S$ is closed under product and inverse, then it contains the identity and is thus a subgroup.\n\n\\subsubsection{Exercise 5}\nWe have that $(s, t) (t, s) = st^{-1} ts^{-1} $, so $S$ contains the identity. Then $(1, s) = s^{-1}$ and\n$(s, t^{-1}) = st$, so $S$ is closed under products and inverses as well, thus making it a subgroup.\n\n\\subsubsection{Exercise 6}\n(a) The identity has order 1. Additionally, if $a$ has finite order, so does $a^{-1}$. Finally,\n$a^n = 1, \\: b^k = 1 \\implies (ab)^{nk} = a^{nk} b^{nk} = 1$.\n\n(b) If non-abelian, we do not necessarily have $(ab)^{nk} = a^{nk} b^{nk}$.\n\n\\subsubsection{Exercise 7}\nIf $G$ has no proper subgroups, then it is generated by all of its non-identity elements. \nThis is only possible if $G$ has order 1 (vacuously true), or if $G$ is a cyclic group of\nprime order (as was shown in the beginning of the previous section).\n\n\\subsubsection{Exercise 8}\n(a) If $a$ has order $n$, so does $a^{-1}$. Additionally, $(ab)^n = a^n b^n = 1$, making all elements that\nsatisfy $a^n = 1$ a subgroup of $A$. To see that this is not true for non-abelian groups, consider $S_3$.\nThe elements $(1 2)$ and $(2 3)$ are both of order 2, but $(1 2) (2 3) = (1 2 3)$ is of order 3.\n\n(b) That the $n^{\\text{th}}$ powers form a subgroup follows from $a^n a^{-n} = 1$ and $a^n b^n = (ab)^{n}$.\n\n\\subsubsection{Exercise 9}\nIf $T$ is a submonoid of $S$, then $i: T \\to S$ is a morphism of monoids, so $T$ must necessarily be\nclosed under products and identity. For the reverse direction, if $T$ is closed under products and\nidentity, then the insertion $i$ is a morphism of monoids and $T$ is a submonoid of $S$.\n\n\\subsection{Defining Relations}\n\n\\subsubsection{Exercise 3}\nThe subgroup of rotations is isomorphic to $\\mathbb{Z}_5$, so each element other than the identity has order 5.\nThe element $D$ has order 2. Furthermore, we have from the generator relations that\n\\begin{align*}\n        DR = R^{n-1}D \\implies DR^i = R^{n-1} DR^{i-1} = DR^i = R^{i(n - 1)}D = R^{n - i}D\n\\end{align*}\nSo all elements of the form $DR^i$ also have order 2.\n\n\\subsubsection{Exercise 4}\nI believe the inclusion diagram looks like a tree with $\\Delta_5$ as the root, and the subgroups generated by\n$R$ and each of the  $DR^i$ as leaves (they don't contain one another).\n\n\\subsubsection{Exercise 5}\nAfter reflecting, it takes $2(i - 1)$ rotations to get vertex $i$ back to its original place. Thus,\nreflection through vertex $i$ can be expressed as $DR^{2(i-1)}$.\n\n\\subsubsection{Exercise 6}\nThe two groups are the same order, so\nwe just need to identify two elements of $S_3 \\times S_2$ with $R$ and $D$ and show that these two elements\nsatisfy the generator relations. Let $x = ((1 2 3), (1 2))$ and $y = ((1 3), 1)$. Then $x^6 = (1, 1)$ since\n$(1 2 3)$ has order 3 and $(1 2)$ has order 2. Similarly, $y^2 = (1, 1)$ and $yx = x^{n - 1}y$, so we have\nan isomorphism.\n\n\\subsubsection{Exercise 8}\n(a) From $a^4 = 1$ we get that $a$ is an element of order  4. From $b^2 = a^2$, we get that only $b$, $b^3$,\n$ab$, and $ab^3$, are distinct from the $a^i$. Hence, there are 8 distinct elements.\n\n(b) There is no isomorphism to $\\Delta_8$, since the only element of order 2 is $b^2 = a^2$.\n\n\\subsubsection{Exercise 10}\nWe let $\\psi((b, c)) = bc$. This is a morphism, since $\\psi((b, c)(b', c')) = uu'vv' = uvu'v'$. Additionally,\n$\\psi$ sends $(b, 1)$ to $u$ and $(1, c)$ to $v$. To see that $\\psi$ is unique, we note that\n\\begin{align*}\n        \\psi'((b, 1)) = u, \\: \\psi'((1, c)) = v \\implies \\psi'((b, c)) = uv\n\\end{align*}\nif $\\psi'$ is a morphism. \n\n\\subsection{Symmetric and Alternating Groups}\n\n\\subsubsection{Exercise 3}\nSince $(1 2 3) (1 2) = (1 3)$ and $(1 2) (1 2 3) = (2 3)$ we have that $S_3$ is not abelian, and therefore \n$S_n$ with $n \\geq 3$ is non-abelian ($S_3 \\subset S_{n \\geq 3}$). $S_1$ and $S_2$ are cylic and thus abelian.\nAs for the alternating groups, it is again straightforward to see that $A_2$ is abelian (it only consists of\nthe identity). $A_3$ is also abelian, since the only even permutations are $1, (1 2 3), (1 3 2)$, all of which\ncommute. For $n \\geq 4$ though, we have that $(1 2 3) (2 3 4) \\neq (2 3 4) (1 2 3)$, so $A_{n \\geq 4}$ is\nnon-abelian.\n\n\\subsubsection{Exercise 4}\n(a) The 4-element subgroup consisting of $1, (1 2), (3 4), (1 2) (3 4)$.\n\n(b) The 6-element subgroup consisting of all of the elements in (a), plus \\\\ $(1 3) (2 4), (1 4) (2 3)$.\n\n\\subsubsection{Exercise 5}\nThere are $\\binom{4}{3} = 4$ ways of choosing 3 elements in $S_4$. The subgroup generated by the \ntranspositions of the 3 selected elements is isomorphic to $S_3$. \nThere are $\\binom{4}{2} = 6$ ways of choosing 2 elements in $S_4$. The subgroup generated by the transposition\nof these two elements is ismorphic to $S_2$. Additionally, any such transposition can be paired with the\ntransposition of the remaining two elements (e.g. $(1 2) (3 4)$ ) to produce another subgroup isomorphic to\n$S_2$, giving 9 such subgroups.\n\n\\subsubsection{Exercise 6}\nThe idea is the same as the second part of Exercise 5. We have $\\binom{6}{3} = 20$ ways to pick 3 elements in\n$S_6$, and the transpositions of these elements can then be paired with the transpositions of the remaining 3\nelements to produce at least another 10 subgroups isomorphic to $S_3$ (the pairing order can be changed to\nproduce more).\n\n\\subsubsection{Exercise 7}\nThe fact that $\\sigma$ and $\\tau \\sigma \\tau^{-1}$ have the same parity follows immediately from Proposition\n15 ($(x_1 \\: ...\\:  x_k) \\to (\\tau(x_1) \\: ... \\: \\tau(x_k))$). That the two need not have the same number of inversions\ncan be seen from looking at $(1 2 3) (1 2) (1 3 2) = (1 3)$. The permutation $(1 2)$ only inverts $(1, 2)$,\nwhereas $(1 3)$ inverts $(1, 2), (1, 3), (2, 3)$.\n\n\\subsubsection{Exercise 8}\nAny cycle of length $2m$ has parity $2m - 1$ (Theorem 17, Corollary 2), and is thus odd. Therefore the product\nof not necessarily disjoint cycles being even implies that the product contains an even number of even length\ncycles. Noting that odd cycles have even parity gives the reverse direction.\n\n\\subsubsection{Exercise 9}\nA permutation of order 14 must consist of either a single cycle of order 14, two cycles of orders 2 and 7, or\na combination of both (since the order is the LCM of the disjoint cycle decomposition lengths). However, since\nwe are considering permutations on 10 letters, only the case of 2 and 7 is possible, which means any such\npermutation must be odd.\n\n\\subsubsection{Exercise 10}\nWe first show that any odd length cycle can be written as a product of length 3 cycles. Let $\\sigma = \n(x_1 ... x_{2n + 1})$. Then $\\sigma$ can be decomposed as $(x_1 x_{2n} x_{2n+1}) \\: ... \\: (x_1 x_2 x_3)$, or,\nin other words, the product of 3-cycles consisting of its first element $x_1$ paired with consecutive pairs\n$x_{2k}, x_{2k+1}$. Next, we show that a product of two disjoint even length cycles $\\sigma_1 = (x_1 \\: ... \\: x_{2n})$ \nand $\\sigma_2 = (y_1 \\: ... \\: y_{2m})$ can be rewritten as the product of two odd length cycles. To do so,\nwe modify $\\sigma_1$ to be $\\sigma_1' = (x_1 \\: ... \\: x_{2n} y_1)$ and modify $\\sigma_2$ to be \n$\\sigma_2' = (y_1 \\: ... \\: y_{2m} x_{2n})$. We can then verify that $\\sigma_1' \\circ \\sigma_2' = \\sigma_1 \\circ \\sigma_2$. Thus, since any even permutation must have a disjoint cycle decomposition consisting of an even \nnumber of even length cycles (since they have odd parity), an even permutation can be written as the product\nof 3-cycles.\n\n\\subsubsection{Exercise 11}\n\n\\subsubsection{Exercise 12}\n\n\\subsubsection{Exercise 13}\nThat $(1 2), (2 3), \\: ...\\:  (n - 1 n)$ are generators for $S_n$ follows immediately from Exercise 11 and the fact \nthat $(1 2 \\: ... \\: n - 1) = (n - 2 n - 1) ... (1 2)$.\n\n\\subsection{Transformation Groups}\n\n\\subsubsection{Exercise 2}\nThe left regular representation of $S_3$ is the function that assigns each element $\\sigma \\in S_3$ to\n$f_{\\sigma} (x) = \\sigma \\circ x$ where $f_{\\sigma}:  S_3 \\to S_3$.\n\n\\subsubsection{Exercise 4}\nThe isotropy subgroup of a single vertex is just the group of permutations that leave the given vertex fixed\nand permute the other seven vertices (isomorphic to $S_7$).\n\n\\subsubsection{Exercise 5}\nThe isotropy subgroups are all isomorphic to $S_{n - 1}$, as they consist of all permutations that leave a \nsingle element fixed. To see that these subgroups are conjugate to one another, let $G_i$ be the isotropy\nsubgroup of $i$. Then we have that for  $g \\in G_i$, $(i j) g (i j) \\in G_j$, since $(i j)$ maps $j$ to $i$ \nand then back to $j$ again.\n\n\\subsubsection{Exercise 6}\nFrom Proposition 15, we have that cyles of the same length are conjugate to one another. Furthermore,\nwe know that every element of $S_n$ has a unique disjoint cycle decomposition. The different possible length\ncycle decompositions form unique conjugacy classes (from Proposition 15), so the number of conjugacy classes\nfor $S_n$ is just the number of partitions of $n$. For $S_3$ this is 3 and for $S_4$ this is 5.\n\n\\subsubsection{Exercise 7}\nThe left regular representation of the additive group  $\\mathbb{R}$ assigns to each element $z \\in \\mathbb{R}$ \nthe function $f_z(x) = x + z$, which is exactly a translation by $z$ of the real line. Similarly,\nthe left regular representation of the additive group $\\mathbb{R} \\times \\mathbb{R}$ corresponds to a\ntranslation of $(z_1, z_2)$ in the cartesian plane.\n\n\\subsubsection{Exercise 8}\nSince $G$ acts transitively on $x$, there exists $g$ such that $gx = y$. Let $z$ be an element that fixes \n$x$. Then we have that $gzg^{-1} y = gzx = gx = y$, so $gzg^{-1}$ fixes $y$ as desired.\n\n\\subsubsection{Exercise 9}\nFor any subgroup $S$ of $\\Delta_4$, we can consider any action of $\\Delta_4$ on the square that has each\nelement of an equivalence class of $\\Delta_4 / S$ act the same way on an element of the square (not exactly\nsure how an ``element'' of the square should be defined, I suppose a point). Such an action necessarily\nfixes the subgroup $S$.\n\nI was a bit confused by this question and found some more discussion \\href{https://math.stackexchange.com/questions/76255/show-every-subgroup-of-d4-can-be-regarded-as-an-isotropy-group-for-a-suitable-ac}{here}.\n\n\\subsubsection{Exercise 10}\nLet $I$ be an invariant subset containing $x$. Then $gx \\in I$ for all $g \\in G$, implying that \n$\\text{Orb}(x) \\subset I$. Since by definition  $\\text{Orb}(x)$ is invariant, it must be the smallest such\nset. By the previous logic, we further have that $I = \\cup_{x \\in G} \\text{Orb}(x)$, which can be reduced\nto a union of disjoint orbits (since one element appearing in another's orbit means their orbits are the same).\n\n\\subsection{Cosets}\n\n\\subsubsection{Exercise 1}\nThe image of a right coset $aS = \\{ as \\: | \\: s \\in S \\}$ under the bijection $a \\mapsto a^{-1}$ is the set \n$\\{ s^{-1} a^{-1} \\: | \\: s \\in S\\}$, which is the left coset $Sa^{-1}$.\n\n\\subsubsection{Exercise 2}\nThe indicated subgroup $S$ is just ${D, 1}$. Thus, the left cosets consist of reflections followed by rotations\nwhile the right cosets consist of rotations followed by reflections.\n\n\\subsubsection{Exercise 5}\nConsider $x \\in S / S \\cap T$ and $y \\in T$. By the definition of join, the product $xy$ must be in $S \\vee T$.\nSince $S / S \\cap T$ and $T$ are disjoint, this means that $[S : S \\cap T] [T : 1] \\leq [S \\vee T : 1]$ (since\n$S \\vee T$ contains every such product $xy$). Using the fact that  $[S : S \\cap T] = \\frac{[S : 1]}{[S \\cap T : 1]}$, we then have the desired inequality.\n\n\\subsubsection{Exercise 6}\nWe use the result of Exercise 8 to get that a group with 6 elements is either isomorphic to $\\mathbb{Z}_6$ or\nto a group with 3 elements of order 2 and 2 elements of order 3. Since $S_3$ has 3 elements of order 2 and\n2 elements of order 3, there is an isomorphism between the latter category of order 6 groups and $S_3$.\n\n\\subsubsection{Exercise 7}\nAgain we rely on Exercise 8. Since $\\Delta_5$ contains 5 elements of order 2 and 4 elements of order 5,\nany group of order 10 without an order 10 element is isomorphic to $\\Delta_5$ by exercise 8.\n\n\\subsubsection{Exercise 8}\nIf a group of order $2p$ contains an element of order $2p$, then it is cyclic and thus isomorphic to\n$\\mathbb{Z}_{2p}$. If a group of order $2p$ does not contain an element of order $2p$, then we will show\nthe following:\n\\begin{itemize}\n  \\item It can have at most one subgroup of order $p$.\n  \\item It must have at least one subgroup or order $p$.\n\\end{itemize}\nTo see the first, we appeal to the inequality from Exercise 5. If there were two distinct subgroups of order\n$p$, then their join would consist of at least $p^2 > 2p$ elements (for $p > 2$). To see the second, we \nconsider the case where all  $2p - 1$ non-identity elements have order 2. Such a group must be abelian,\nsince we have $abab = 1 \\implies ab = b^{-1} a^{-1} = ba$. Taking the join of the groups generated by $a$ \nand $b$ would then give us a subgroup of order 4, which is not possible since 4 does not divide $2p$. Thus,\nthere must be an element (and hence a generated subgroup) of order $p$. Combining these two results gives\nthat a group of order $2p$ that does not contain an element of order $2p$ must have $p-1$ elements of order\n$p$ and $p$ elements of order 2.\n\n\\subsubsection{Exercise 9}\n(a) Suppose $s a t = s' b t'$. Then we would have  $a = s^{-1} s' b t' t^{-1}$, so $a \\in SbT$ and the \ndouble cosets $SaT$ and $SbT$ are equal. The alternative is that $s a t \\neq s' b t'$ for all $s, s', t, t'$,\nwhich would imply that the double cosets are disjoint. Thus, the double cosets of $G$ form a partition of\n$G$, so their union is $G$.\n\n(b) \n\n\\subsection{Kernel and Image}\n\n\\subsubsection{Exercise 2}\nIf $N \\triangleleft S_3$, then all elements in $N$ must have the same sign \n(since $\\text{sgn}(ana^{-1}) = \\text{sgn}(n)$). As there are no subgroups consisting of only odd \npermutations, we need only consider subgroups consisting of even permutations. The only such proper\nsubgroup of $S_3$ is $A_3$.\n\n\\subsubsection{Exercise 3}\nSince $DR^i = R^{n - i}D \\implies DR^i D^{-1} = R^{n - i}$, we have that $\\{R^i\\} \\triangleleft \\Delta_p$.\nThe only other proper subgroups of $\\Delta_p$ are the order 2 groups generated by $DR^i$. However,\nnone of these subgroups are normal since $D DR^i D = DR^{n - i}$, which is clearly not\n$DR^i$ or 1 for all $0 < i < n$. Thus, the subgroup of rotations is the only normal subgroup of $\\Delta_p$.\n\n\\subsubsection{Exercise 4}\nWe first note that $R^j DR^i R^{-j} = DR^{i - 2j}$, and $DR^{i - 2j} = DR^i$ only when $j = 0$ or \n$j = \\frac{n}{2}$. Thus, none of the subgroups generated by elements of the form $DR^i$ are normal,\nand we only need to consider subgroups of the rotation subgroup. Any such subgroup\nis normal, since $i$ divides $n - i$, so $\\{R^i\\}, \\{R^{2i}\\} \\triangleleft \\Delta_4$ and\n$\\{R^i\\}, \\{R^{2i}\\}, \\{R^{3i}\\} \\triangleleft \\Delta_6$.\n\n\\subsubsection{Exercise 5}\n(a) $ax = xa \\implies x^{-1} a x = a$, so $Z(G)$ is normal.\n\n(b) From Exercises 3 and 4, we can see that $DR^i \\notin Z(\\Delta_n)$. Furthermore, $R^i \\in Z(\\Delta_n)$\nonly if $R^i = R^{n - i}$, which is only possible if $n$ is even. Thus, $Z(\\Delta_n)$ is either 1 or the\nsubgroup generated by $R^{\\frac{n}{2}}$, with the latter being isomorphic to $\\mathbb{Z}_2$.\n\n(c) From Proposition 15, we have that $\\tau \\sigma \\tau^{-1} = \\sigma$ only if $\\tau$ and $\\sigma$ commute or\nif $\\tau = 1$. For $n > 2$, $S_n$ is not commutative, so $Z(S_n) = 1$.\n\n\\subsubsection{Exercise 6}\nLet $A$ and $B$ be two normal subgroups of $G$. Then for $a \\in A$, $b \\in B$, and $g \\in G$, we have\n$g a g^{-1} g b g^{-1} = g a b g^{-1} = a' b'$ for some $a' \\in A$ and $b' \\in B$, so $A \\vee B$ is\nnormal in G. Additionally, if $a \\in A \\cap B$, then we have that $g a g^{-1} \\in A$ and\n$g a g^{-1} \\in B$ by normality of $A$ and $B$, so $A \\cap B \\triangleleft G$.\n\n\\subsubsection{Exercise 7}\n(a) Let $f_{g}(x) = gxg^{-1}$. Then $f_{g'} \\circ f_{g} (x) = g' g x g^{-1} g'^{-1} = f_{g' g} (x)$ so\n$\\text{In} (G)$ is a group under composition.\n\n(b) Let $h \\in \\text{Aut}(G)$. Then $h \\circ f_g \\circ h^{-1} (x) = h(gh^{-1}(x)g^{-1}) = h(g) x h(g)^{-1}$,\nso $\\text{In} (G) \\triangleleft \\text{Aut} (G)$.\n\n\\subsubsection{Exercise 12}\nSince $g \\to ag$ is a permutation on $G$, $gT \\to agT$ is a permutation on $G / T$. We also have that\n$h_a \\circ h_b (gT) = a (bg T) = (ab)g T = h_{ab} (gT)$ so $h: G \\to S(G / T)$ is a morphism. \n\n\\subsection{Quotient Groups}\n\n\\subsubsection{Exercise 1}\nLet $\\phi$ be a morphism with $\\phi(R) = 0$ and $\\phi(D) = 1$. Then $\\phi$ is an epimorphism with kernel\n$S$, so $\\Delta_n / S \\cong \\mathbb{Z}_2$.\n\n\\subsubsection{Exercise 2}\nThe quotient groups of $\\Delta_4$ correspond to its normal subgroups, which are:\n\\begin{itemize}\n        \\item $\\{1\\}, \\{R\\}, \\{R^2\\}$\n        \\item  $\\{R^2, D\\}, \\{R^2, RD\\}$\n\\end{itemize}\n\n\\subsubsection{Exercise 3}\n(a) Let $\\phi: 4\\mathbb{Z} \\to \\mathbb{Z}_5$ be defined as $\\phi(x) = x \\mod 5$. Then $\\phi$ is an epimorphism\nwith kernel $20\\mathbb{Z}$, so $4\\mathbb{Z} / 20\\mathbb{Z} \\cong \\mathbb{Z}_5$. Similarly, we can also\ndefine $\\phi: \\mathbb{Z}_6 \\to \\mathbb{Z}_3$ as $\\phi(x) = x \\mod 3$. This is another epimorphism with\nkernel $3\\mathbb{Z}_6$, so $\\mathbb{Z}_6 / 3\\mathbb{Z}_6 \\cong \\mathbb{Z}_3$.\n\n(b) More generally, we can define $\\phi: k \\mathbb{Z} \\to \\mathbb{Z}_m$ as $\\phi(x) = \\frac{x}{k} \\mod m$, \nwhich is an epimorphism with kernel $m k  \\mathbb{Z}$. Thus, $k\\mathbb{Z} / m k \\mathbb{Z} \\cong \\mathbb{Z}_m$.\nFrom this result, we get that \n$(\\mathbb{Z} /m k \\mathbb{Z}) / (k\\mathbb{Z} / m k \\mathbb{Z}) \\cong \\mathbb{Z}_{m k} / \\mathbb{Z}_m$, which\nis in turn isomorphic to $\\mathbb{Z}_k$.\n\n\\subsubsection{Exercise 4}\nI'm not really sure what counts as a ``familiar group here'', but we can consider $x \\to \\abs{x}$ again to\nsee that $Q^* / \\{\\pm 1 \\}$ is isomorphic to the multplicative group of positive rationals.\n\n\\subsubsection{Exercise 6}\nConsider $\\phi: G \\to \\text{In} G$ where $\\phi(g) = \\gamma_g$ with $\\gamma_g(x) = gxg^{-1}$. By construction,\n$\\phi$ is an epimorphism, and $\\gamma_g(x) = x$ iff $g \\in Z$. Thus, $G / Z \\cong \\text{In} G$.\n\n\\subsubsection{Exercise 7}\n(a) Since $[xgx^{-1}, xhx^{-1}] = x g x^{-1} x h x^{-1} x g^{-1} x^{-1} x h^{-1} x^{-1} = x[g, h]x^{-1}$, we\nhave that $[G, G] \\triangleleft G$. \n\n(b) Since $[G, G] [x, y] = [G, G] \\implies [G, G] xy = [G, G] yx$, $G / [G, G]$ is abelian. Any morphism\n$\\phi: G \\to A$ carries all of the elements of the coset $[G, G]x$ to the single element $\\phi(x)$. Thus,\nwe can factor $\\phi$ as $\\phi' \\circ p$, where $\\phi': G / [G, G] \\to A$ with $\\phi'([G, G]x) = \\phi(x)$.\n\n\\subsubsection{Exercise 8}\nSince $G/N \\cong \\mathbb{Z}_5$, $G$ must be a group of order 10. This implies that  $G$ is either  $\\Delta_5$\nor $\\mathbb{Z}_10$ (see exercise 7 in section 8). However, $\\Delta_5$ does not have a normal subgroup\nof order 2, so $G \\cong Z_{10}$.\n\n\\subsubsection{Exercise 9}\nSince $N \\subset M$, we can define an epimorphism $\\phi: G / N \\to G / M$ that maps the coset $Ng$ to the\ncoset  $Mg$. The kernel of this epimorphism is $Nm$ for all $m \\in M$, which is exactly $M / N$. Thus,\nwe get that  $(G / N) / (M / N) \\cong G / M$.\n\n", "meta": {"hexsha": "a71dcc0e2eef5428b481fd5ec1241cdc0eca10d2", "size": 26260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algebra_Maclane_Birkhoff/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": "Algebra_Maclane_Birkhoff/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": "Algebra_Maclane_Birkhoff/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": 54.2561983471, "max_line_length": 220, "alphanum_fraction": 0.6809215537, "num_tokens": 8827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6743518275782463}}
{"text": "\\section{Background}\\label{sec:background}\n%===========================================================\n\nCellular complexes are largely used in Computer Graphics and in Geometric and Solid Modeling~\\cite{Elter:10.1007/978-3-642-78114-8_12}. In particular, they provide the geometric-topological discretization for computer modeling and simulation of physical properties of both man-made and natural objects~\\cite{DiCarlo:2009:DPU:1629255.1629273,ieee-tase}.\n\n\\subsection{Cell complexes vs Chain complexes}\n\\label{cell-complexes-vs-chain-complexes}\n%--------------------------------------------\n\nA \\(p\\)-chain can be seen as a subset of \\(p\\)-cells from a cellular\ncomplex. The space of \\(p\\)-chains is closed\nw.r.t.~addition and product times a scalar from a field. In particular, it is a linear (vector) space.\n\n\\paragraph{Cells and Chains}\\label{sec:chain}\n%------------------------------------------------------------------------------\n%--\nA $p$-\\emph{manifold} is a topological space where each point has a neighborhood\nthat is homeomorphic to $\\E^p$. A \\emph{$p$-cell} $\\sigma$ ($0\\leq p\\leq d$) of cellular complexes is piecewise-linear, connected, possibly non convex, $p$-manifold, and not necessarily contractible\\footnote{The cells of CW-complexes are contractible to a point. With our LAR representation they may contain internal holes.}. An\n$r$-face $\\tau$ of a $p$-cell $\\sigma$ ($0\\leq r\\leq p$) is an $r$-cell contained\nin the frontier of $\\sigma$.\n\n\nA \\emph{$p$-chain} can be seen, with some abuse of language, as a collection of $p$-cells.\nThe set $C=\\oplus\\ C_p$ of chains can be given the structure of a graded vector space  by\ndefining sums of chains with the same dimension, and products times scalars in a\nfield, with the usual properties.\n\nA \\emph{basis} $U_p$  is the set of \\emph{independent} (or \\emph{elementary}) chains $u_p \\in C_p$, given\nby singletons of $\\Lambda_p$ elements. Every chain $c\\in C_p$ is uniquely generated by\na linear combination of the basis with field coefficients. Once  the  basis is fixed, the coordinate\nrepresentation of each $\\{\\sigma_k\\} = u_k \\in C_p$ is unique. This is an ordered\nsequence of coefficients, either from $\\{0,1\\}$ (unsigned representation) or from\n$\\{-1,0,+1\\}$ (signed representation). With abuse of language, we\noften call $p$-cells the independent generators of $C_p$, {i.e.}~the elements of\n$U_p$.\n\n\n\\paragraph{Chain and cochain complexes}\\label{graded-complexes}\n%-------------------------------------------------------------------------------\n%\nA \\emph{graded vector space} is a vector space $V$ expressed as a direct sum  of\nspaces $V_k$ indexed by integers in $[0,d]$:\n\\[ V = \\oplus_{k = 0}^d V_k, \\qquad [0,d] := \\{k\\in\\N \\ |\\ 0\\leq k\\leq d\\}.\n\\]\n\nA linear map $f:V\\to W$ between graded vector spaces is called a \\emph{graded\nmap} of degree $p\\ $ if $f(V_k) \\subset W_{k+p}$.\n\nA \\emph{chain complex} is a graded vector  space $V$ furnished with a graded\nlinear map $\\partial : V \\to V$ of degree $-1$ which satisfies $\\partial^2 = 0$, called\n\\emph{boundary operator}. In other words, a chain complex\nis a sequence of vector spaces $C_k$ and linear maps $\\partial_k : C_k \\to C_{k-1}$,\nsuch that $\\partial_{k-1} \\circ\\ \\partial_{k} = 0$.\n\nA \\emph{cochain complex} is a graded vector space $V$ provided with a graded\nlinear map $\\delta : V \\to V$ of degree $+1$ which satisfies $\\delta^2 = 0$,\ncalled \\emph{coboundary operator}. That is to say, a cochain complex is a\nsequence of vector spaces $C^k$ and linear maps $\\delta^k : C^k \\to C^{k+1}$,\nsuch that $\\delta^{k+1} \\circ\\ \\delta^{k} = 0$.\n%This duality implies that ... (Antonio !)\n\nSince any linear map $L: V\\to W$ between linear spaces induces a dual map $L': \nW' \\to V'$ between their duals, any chain complex is associated with a dual \ncochain complex, and viceversa:\n\\[\n(\\delta^k \\omega) g = \\omega (\\partial_{k+1} g), \\qquad \\omega \\in C^k, g \\in C_{k+1}.\n\\]\n In a Euclidean space, chain and cochain spaces can be trivially identified~\\cite{ieee-tase}, so that we use the $C_p$ notation for both spaces, with $\\partial_p: C_p\\to C_{p-1}$, and $\\delta_p = \\partial_{p-1}^\\top: C_{p-1}\\to C_p$.\n\n", "meta": {"hexsha": "1db96d105357e7fb0c74f282f2b74d3f89f87e3d", "size": 4135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/background.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/background.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/background.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": 59.0714285714, "max_line_length": 352, "alphanum_fraction": 0.6730350665, "num_tokens": 1218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6743518233162465}}
{"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{Gaussian Maximum Likelihood}\n\\newcommand{\\distas}[1]{\\mathbin{\\overset{#1}{\\kern\\z@\\sim}}}%\n\\newsavebox{\\mybox}\\newsavebox{\\mysim}\n\\newcommand{\\distras}[1]{%\n\t\\savebox{\\mybox}{\\hbox{\\kern3pt$\\scriptstyle#1$\\kern3pt}}%\n\t\\savebox{\\mysim}{\\hbox{$\\sim$}}%\n\t\\mathbin{\\overset{#1}{\\kern\\z@\\resizebox{\\wd\\mybox}{\\ht\\mysim}{$\\sim$}}}%\n}\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Gaussian Maximum Likelihood}\n\t\\begin{align*}\n\t\tX \\overset{iid}{\\sim} N(\\mu,\\sigma^2)\\\\\n\t\tL(theta|X) &= p(X|theta)\\\\\n\t\t&= p(X|\\mu,\\sigma^2)\\\\\n\t\t&= \\prod{p(x_i|\\mu,\\sigma^2)}\\\\\n\t\t\\\\\n\t\t\\max_{\\mu,sd}{L(theta|X)} &= \\max_{\\mu,\\sigma^2}{\\prod{p(x_i|\\mu,\\sigma^2)}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{ln(\\prod{p(x_i|\\mu,\\sigma^2)))}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\sum{ln(p(x_i|\\mu,\\sigma^2))}}\\\\\n\t\t\\\\\n\t\tp(x|\\mu,\\sigma^2) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}\n\t\t\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\sum{ln(\\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{-\\frac{(x_i-\\mu)^2}{2\\sigma^2}})}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\sum{\\big[ln(\\frac{1}{\\sqrt{2\\pi\\sigma^2}})+ln( e^{-\\frac{(x_i-\\mu)^2}{2\\sigma^2}})\\big]}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\sum{\\big[ln(\\frac{1}{\\sqrt{2\\pi\\sigma^2}})+-\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\big]}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\sum{\\big[ln(\\frac{1}{\\sqrt{2\\pi\\sigma^2}})\\big]-\\sum{\\big[\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\big]}}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\sum{\\big[ln((2\\pi\\sigma^2)^{\\frac{1}{2}})\\big]-\\sum{\\big[\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\big]}}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\big[ln((2\\pi\\sigma^2)^{\\frac{1}{2}})\\big]\\sum{1}-\\sum{\\big[\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\big]}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\big[\\frac{1}{2}ln(2\\pi\\sigma^2)\\big]\\sum{1}-\\sum{\\big[\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\big]}}\\\\\n\t\t&= \\max_{\\mu,\\sigma^2}{\\big[\\frac{1}{2}ln(2\\pi\\sigma^2)\\big]N-\\sum{\\big[\\frac{(x_i-\\mu)^2}{2\\sigma^2}\\big]}}\\\\\n\t\\end{align*}\n\t\n\tTODO\n\t\n\t\\begin{align*}\n\t\t\\overset{*}{\\mu} &= \\frac{1}{N}\\sum{x_i}\\\\\n\t\t\\overset{*}{\\sigma^2}&=\\frac{1}{N}\\sum{(x_n-\\overset{*}{\\mu})^2}\n\t\\end{align*}\n\\end{document}", "meta": {"hexsha": "8c1504d004e36692259dd93ec726f707f98c154e", "size": 2155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texts/math/Statistics/maximumlikelihood.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/Statistics/maximumlikelihood.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/Statistics/maximumlikelihood.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": 44.8958333333, "max_line_length": 123, "alphanum_fraction": 0.5777262181, "num_tokens": 1046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.674351822550251}}
{"text": "\\chapter{Divide \\& Conquer}\n\n\\section{Principles}\n\\runinhead{Divide.}\\runinhead{Reduce \\# sub-problems.} After dividing, we have $a$ subproblems. Now need to identify the redundancy in the $a$ sub-problems. Find the common shared calculations among sub-problems and thus try to reduce $a$ to $a-1$. Identify the \\textbf{commonality}.\n\\runinhead{Sub-problem dimension.} Reduce the dimensionality of the original problem; thus consider the simpler version of the problem.\n\\runinhead{Input dimension.}  Increase the representation dimensionality of the input. For example, in FFT (Fast Fourier Transform) augment the input with complex space. \n\\begin{align*}\nw_{j, k} = e^{j2\\pi i/k}\n\\end{align*}\n", "meta": {"hexsha": "3a549f03482439b3ab0f41f06c4ce89ab850ec30", "size": 694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterDivideAndConquer.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": "chapterDivideAndConquer.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": "chapterDivideAndConquer.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": 69.4, "max_line_length": 283, "alphanum_fraction": 0.7680115274, "num_tokens": 190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6743518217842552}}
{"text": "\\chapter{RTS Smoothing} \\label{ch:RTS}\n\nWhile the Kalman filter is an optimal solution to computing state estimates from all previous data, better estimates could be obtained if all future data were also incorporated.\n\nThe RTS Smoothing algorithm is an approach to determine estimates of states and uncertainties by considering the state transistion between two kalman filtered estimates, smoothing the transition between prior and 'future' data.\n\n\\section{Example} \n\nConsider the system of a single particle moving in one dimension. At time t=0, the particle's position is measured to be x=0. The system then evolves with a random walk, with no more measurements until the time t=100.\n\nAt t=99, the particles position has a large uncertainty - it has likely moved from its original position, however, with no more data available, its mean expected value remains as x=0.\n\nAt t=100, the particles position is again measured, this time as x=10. If this system were monitored using a Kalman filter, the expected position of the particle would be a constant x=0 for the first 99 seconds, before an abrupt change in location at t=100. During the 100 seconds, the variance would increase steadily, before abruptly returning to a low value when the second measurement is taken.\n\nIf the kalman filter measurements were taken in reverse order, with the first measurement at t=100, the variance of the particle would steadily increase going backward in time until t=0, before the second measurement again reduced the variance, this time at t=0.\n\nUsing an RTS Smoother effectively combines both forward and backward filtering. At t=1, the variance is low due to the measurement at t=0. Likewise, at t=99, the variance is low due to the measurement at t=100. In this example, in addition to the measurements at t=0 and t=100, the expected mean value at t=50 can be expected to be the midpoint between the two measurements - a result that can not be obtained using Kalman filtering alone.\n\nIn order to accurately calculate the expected position and variance at t=50 however, knowledge of the measurement at t=100 was required (50 seconds later). RTS smoothed estimates necessarily lag behind the primary Kalman filter to allow some time for future data to be obtained. The length of this lag determines the effectiveness of the smoothing.\n\n\\section{Usage}\n\n\\begin{lstlisting}[language=yaml,caption=RTS Configuration]\nuser_filter_parameters:\n\n    max_filter_iterations:      5\n    max_prefit_removals:        3\n\n    rts_lag:                    -1      #-ve for full reverse, +ve for limited epochs\n    rts_directory:              ./\n    rts_filename:               PPP-<CONFIG>-<STATION>.rts\n\n    inverter:                   LLT         #LLT LDLT INV\n\n\\end{lstlisting}\n\nAll kalman filters in the toolkit are capable of having RTS Smoothing applied. If configured appropriately with an RTS\\_lag and output files, intermediate filter results will be stored to file for reverse smoothing.\n\nFor real-time processing, a small lag may be applied to improve short-term accuracy. After each filtering stage, the new result is propagated backward through time to correct the previous N epochs. Each epoch worth of lag however requires a comparable processing time to an Kalman filter processing stage - a lag of N epochs may slow processing by up to a multiple of N.\n\nFor post-processing, the optimal lag is to use all future and past data. This is achieved by first computing the forward solution, before propagating the final results backward through to the first epoch. The processing time required for a complete backward smoothed filter may be less than 2x a non-smoothed filte - considerably faster than a finite lag in real-time.\n\n\\subsection{rts\\_lag:}\nNumber of future epochs to use in RTS smoothing. A larger lag will give more optimal smoothing results, at the expense of a longer lag before they are calculated, and requiring more processing time per epoch.\n\nA negative value indicates that the entire solution should be smoothed at the conclusion of processing. \nThis will obtain optimal results, with lowest processing time, but is not suitable for real-time applications.\n\n\\subsection{rts\\_directory:}\nDirectory to output RTS files.\n\n\\subsection{rts\\_filename:}\nFilename for RTS files. Multiple intermediate files are generated by RTS smoothing, as well as an additional output files for kalman filter states and clocks.\n", "meta": {"hexsha": "e6c61379817f1da53cbcc549189ce5d3faa20e0e", "size": 4413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manual/rts_smoothing.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/rts_smoothing.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/rts_smoothing.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": 81.7222222222, "max_line_length": 439, "alphanum_fraction": 0.7822343077, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.6743518146252598}}
{"text": "\\chapter{Math}\r\n\\section{Number Theory, Inequalities and Combinatorics}\r\n\\subsection{Basic Number Theory}\r\n{\\bf Theorem:}\r\n$\\pi$ is irrational.\r\n\\begin{quote}\r\n\\emph{Proof (Niven):}\r\nAssume to the contrary that $\\pi = {\\frac a b}, a,b \\in {\\mathbb Z}$.\r\nDefine $f_n(x)= {\\frac {x^n(a-bx)^n} {n!}}$ and\r\n$F_n(x) = f_n(x) - f_n^{(2)}(x) + f_n^{(4)}(x) - \\ldots\r\n\\ldots + (-1)^n f_n^{(2n)} (x)$. \r\nIf $x= 0 \\textnormal{ or } \\pi$, \r\n$f_n^{(i)}(x) \\in {\\mathbb Z}, \\forall i$ so\r\n$F_n(0), F_n(\\pi) \\in {\\mathbb Z}$.\r\n$(F'(x) sin(x) - F(x) cos(x))'= (F''(x)+F(x))sin(x)=\r\nf_n(x) sin(x)$ so\r\n$\\int_0^{\\pi} f_n(x) sin(x) dx = F_n(\\pi)-F_n(0) \\in {\\mathbb Z}$.  \r\nNow suppose, $0<x<\\pi={\\frac a b}$. Then $0<bx<a$, $0<a-bx<a$,\r\n$0 < (a-bx) x < a x < a \\pi $ and thus \r\n$0 < x^n(a-bx)^n < a^n \\pi^n$,\r\n$0 < f_n(x) sin(x) \\le f_n(x)={\\frac {x^n(a-bx)^n} {n!}} < {\\frac {a^n \\pi^n}{n!}}$.\r\nPick $n$ large enough that ${\\frac {\\pi^n a^n} {n!}} < {\\frac 1 {\\pi}}$ then\r\n$0< \\int_0^{\\pi} f_n(x) sin(x) dx < 1$.  But\r\n$\\int_0^{\\pi} f_n(x) sin(x) dx = F_n(\\pi)-F_n(0) \\in {\\mathbb Z}$ and this \r\ncontradiction proves the result.\r\n\\end{quote}\r\n{\\bf Theorem:} $e$ is transcendental.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $f(x)$ is a polynomial of degree $r$, set\r\n$F(x)= f(x) + f'(x) \\ldots + f^{(r)}(x)$.  Then\r\n$F(i)-e^{i}F(0)= -i e^{i(1-\\theta_{i})}f(i \\theta_{i})= \\epsilon_{i}$.\r\nSuppose $e$ satisfies\r\n$g(e)= c_{n}e^{n} + \\ldots + c_{0}= 0$. Then\r\n$c_{n}F(n) + \\ldots + c_{0}F(0)= c_1 \\epsilon_{1} +\r\nc_2 \\epsilon_{2} + \\ldots + c_n \\epsilon_{n}$.\r\nPut $f(x)= {\\frac {1} {(p-1)!}}\r\nx^{p-1} (1-x)^{p} (2-x)^{p} \\ldots (n-x)^{p}$.\r\n$p \\mid F(i), i>0$ but $p \\nmid F(0)$.\r\nSo, $c_{n}F(n) + \\ldots + c_{0}F(0)$ is an integer not divisible by $p$ but\r\n$c_{n}F(n) + \\ldots + c_{0}F(0)= c_1 \\epsilon_{1} + c_2\r\n\\epsilon_{2} + \\ldots + c_n \\epsilon_{n}$.  Now,\r\nlet $p \\rightarrow \\infty$.\r\n\\end{quote}\r\n{\\bf Wilson:} $(p-1)! = (-1) \\jmod{p}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  There are only two solutions to \r\n$x^2=1 \\jmod{p}$, namely, $\\pm 1$.  Thus, \r\nif we multiply all non-$0$ elements of ${\\mathbb Z}_p$ together,\r\nexcept for $\\pm 1$, each multiplicative element can \r\nbe paired with its inverse leaving $(1)(-1)$.\r\n\\end{quote}\r\n{\\bf Theorem:} $\\exists x$: \r\n$x^2= -1 \\jmod{p}$ iff $p=2$ or $p= 1 \\jmod{4}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$(p-1)!= -1= (-1)^{\\frac {p-1} 2} \r\n\\prod_{j \\in \\{ 1,2, \\ldots, {\\frac {p-1} 2} \\} } j^2 \\jmod{p}$,\r\nif $p = 1 \\jmod{4}$, first factor is $1$ and thus\r\n$(\\prod_{j \\in \\{ 1,2, \\ldots, {\\frac {p-1} 2} \\} } j)^2 = -1 \\jmod{p}$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $p= 1 \\jmod{4}: \\exists a,b: a^2+b^2=p$.  \r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\exists x: x^2+1= rp$.   Set\r\n$k= \\lfloor {\\sqrt p} \\rfloor, k \\leq {\\sqrt p} < k+1$.  Set $f(u,v)= ux+v$; consider\r\n$S= \\{(u,v): 0 \\le u \\le k, 0 \\le v \\le k \\}$.  $|S|= (k+1)^2>p$, so \r\n$\\exists u_1, u_2, v_1, v_2 : f(u_1,v_1)=f(u_2, v_2)$ and\r\n$a= u_1-u_2, b= v_1-v_2$ then $a+bx=0 \\jmod{p}$.  Now $a^2+b^2 = a^2 + a^2 x^2 = 0 \\jmod{p}$.\r\n$|a| < {\\sqrt p}$ and\r\n$|b| < {\\sqrt p}$ so\r\n$0<a^2 + b^2<2p$ and $a^2 + b^2= p$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $q \\mid (a^2 + b^2)$ and $q = 3 \\jmod{4}$ then $q \\mid a$ and $q \\mid b$.  \r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose $(a,q)=1$, pick ${\\overline a}: a {\\overline a} = 1 \\jmod{q}$.\r\n$a^2 = -b^2 \\jmod{q}$ so $-1= (b {\\overline a})^2 \\jmod{q}$.\r\n\\end{quote}\r\nIf $n= 2^{\\alpha} \\prod_{p = 1 \\jmod{4}} p^{\\beta} \\prod_{q = 3 \\jmod{4}} q^{\\gamma}$ then\r\n$n= a^2 + b^2$ iff all $\\gamma$ are even.\r\n\\begin{quote}\r\n\\emph{Proof:} Use $(a^2 + b^2)(c^2 + d^2)=\r\n(ac-db)^2 + (ad-bc)^2$.\r\n\\end{quote}\r\n{\\bf Theorem (representing integers as sums of squares):}\r\nThere are no solutions to $x^2 + y^2 =n$ if\r\n$n= 3 \\jmod{4}$.  There are solutions to $x^2 + y^2 =p$, $p$, prime if\r\n$p= 1 \\jmod{4}$.  \r\n\\begin{quote}\r\n\\emph{Proof:} $\\exists m,a,b: a^2+b^2=mp$ if $p= 1 \\jmod{4}$; for\r\nexample, $\\exists a: a^2+1 = 0 \\jmod{p}$ by Euler's criteria.  Note that\r\n$(ua+vb)^2 + (va-ub)^2 = (u^2+v^2)(a^2+b^2)$.  Now apply Fermat's descent,\r\nsuppose $a^2+b^2=mp$.  Choose $u=a \\jmod{m}, v=b \\jmod{m}, -{\\frac m 2} \\le u,v \\le {\\frac m 2}$\r\nthen $a^2+b^2=u^2+v^2= 0 \\jmod{m}$.  $u^2+v^2= mr$ and\r\n$(ua+vb)^2 + (va-ub)^2= m^2 rp$. $m \\mid (ua+vb)$ and $m \\mid (va-ub)$ so\r\n$({\\frac {ua+vb} {m}})^2 + ({\\frac {va-ub} {m}})^2 =rp, r<m$.\r\nIf $a$ has $A$ divisors $a_1 , \\ldots , a_A$ with $a_i = 1 \\jmod{4}$\r\nand $B$ divisors $b_1 , \\ldots , b_B$ with $b_i = 3 \\jmod{4}$ then\r\n$x^2 + y^2 =n$ has $4(A-B)$ solutions in the integers.\r\n\\end{quote}\r\n{\\bf Chinese Remainder Theorem}: If $(m_1 , m_2 )=1$, for any $a, b$,\r\nthere is an $n$ such that\r\n$n= a \\jmod{m_1}$ and\r\n$n= b \\jmod{m_2}$.  Further, if $n'$ is another such number,\r\n$n= n' \\jmod{m_1 m_2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Solving Linear Equations over ${\\mathbb Z}$:}\r\n$ax=b \\jmod{m}$ has a solution iff $(a,m) \\mid b$.  If such a solution exists,\r\nthere are ${\\frac m {(a,m)}}$\r\nsolutions.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nIf $(m_1, m_2)=1$ then $\\phi(m_1 m_2)= \\phi(m_1) \\phi(m_2)$.  If \r\n$N_f(m)$ is the number of solutions of $f(x) = 0 \\jmod{m}$ and $(m_1 , m_2)=1$\r\nthen $N(m_1 m_2) = N(m_1) N(m_2)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $x_1 , x_2 , \\ldots , x_j$ be the solutions to $f(x) = 0 \\jmod{m_1}$\r\nand $y_1 , y_2 , \\ldots , y_k$ be the solutions to $f(x) = 0 \\jmod{m_2}$.\r\nBy the Chinese remainder theorem there is a unique $z_{i,l} \\jmod{m}$ such\r\nthat $z_{i,l} = x_i \\jmod{m_1}$ and\r\n$z_{i,l} = y_l \\jmod{m_2}$ for each $1 \\leq i \\leq j$ and $1 \\leq l \\leq k$.\r\nThe $z_{i,l}$ constitute all the solutions to $f(x) = 0 \\jmod{m}$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $R= R_1 \\times R_2 \\times \\ldots \\times R_n$ then\r\n$U(R)= U(R_1) \\times U(R_2) \\times \\ldots \\times U(R_n)$. \r\n\\\\\r\n\\\\\r\n{\\bf Corollary:} \r\nIf $(m_i , m_j)=1$\r\nand $m= m_1 m_2 \\ldots m_n$ then\r\n${\\mathbb Z}/(m)= {\\mathbb Z}/(m_1) \\times {\\mathbb Z}/(m_2) \\times \r\n\\ldots \\times {\\mathbb Z}/(m_n)$.  Applying this to\r\n$n= 2^{e_0} {p_1}^{e_1}{p_2}^{e_2} \\ldots {p_n}^{e_n}$ we find $n$ has a primitive root\r\niff $n= 2, 4, p^{e}$.  $p$ has $\\phi(p-1)$ primitive roots.\r\n\\\\\r\n\\\\\r\n{\\bf Artin's conjecture:}\r\n$2$ is a\r\nprimitive root for infinitely many primes.  The\r\nextended Riemann Hypothesis implies Artin's\r\nconjecture.\r\n\\\\\r\n\\\\\r\n{\\bf Lucas' Theorem:} If $(a,m)=1$ and $a^{p-1} = 1 \\jmod{m}$ and $p-1$\r\nis the smallest such exponent then $m$ is prime.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} For $0 \\leq a \\leq b \\leq n$ with $(a,b)=1$, the Farey sequence\r\n$F_n$ is the ordered list of ${\\frac a b}$.  $F_3= \\{0, \r\n{\\frac 1 3}, {\\frac 1 2}, {\\frac 2 3}, 1 \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If \r\n$ {\\frac {p_1} {q_1}}, {\\frac {p_2} {q_2}}, {\\frac {p_3} {q_3}}$ are three successive terms\r\nof a Farey sequence then $p_1 q_1 - p_1 q_2 =1$ and \r\n${\\frac {p_1 + p_3} {q_1 + q_3}}= {\\frac {p_2} {q_2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Chevalley's Theorem:} Suppose $f \\in k[x_1, \\ldots, x_n]$ , $k= F_q, q=0 \\jmod{p}$ and\r\n$deg(f)=d<n$\r\nthen (1) if $f(x)= 0 \\jmod{p}$ has a solution, it has at least two; and (2) if $f(0)=0$,\r\n$f$ has at least one non-trivial solution.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n\\emph{Lemma 1:}  If $u \\in {\\mathbb Z}, u \\geq 0$ and $S(u)= \\sum_{x \\in k} x^u$ then $S(u)= -1 \\jmod{p}$, \r\nif $(q-1) \\mid u$ and $0$ otherwise.\r\n\\\\\r\n\\emph{Proof of lemma:} If $u=0$, $S(0) = q = 0 \\jmod{p}$.  If $(q-1) \\nmid u, \\exists y \\in k: y^u \\neq 1$, so\r\n$S(u)= \\sum_{x \\in k} x^u = \\sum_{x \\in k} y^u x^u$ and $S(u)= y^u S(u)$ and thus $(1-y^u)S(u)= 0$ and $S(u)= 0$.\r\nFinally, if $(q-1) \\mid u$, $x^u = 1$ if $x \\neq 0$ and $x^u= 0$ if $x=0$; thus $S(u)= q-1 = -1 \\jmod{p}$.\r\n\\\\\r\n\\\\\r\nPut $p(x)= 1-f(x)^{q-1}$, and let $N$ be the number of zeros of $f$.\r\n$p(x)= 1$ if $x$ is a zero of $f$ and $p(x)= 0$ if $x$ is not a zero of $f$, so $N= \\sum_{x \\in k} p(x) $.\r\n$p(x)$ is a sum of monomials in $n$ variables and since $deg(p)= d(q-1)$, at least one variable in the monomial appears\r\nto a power $<q-1$.   \r\nBy the lemma, the sum over $k$ of each of these monomials is $0$ and so $\\sum_{x \\in k^n} p(x)= 0 \\jmod{p}$ so\r\n$N= 0 \\jmod{p}$ and the two assertions follow.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nSolutions of $f(x)= 0 \\jmod{p}$ are solutions of $(f(x), x^p-x)$.\r\nIf $deg(f(x)) = n$ with leading coefficient $1$ then $f(x)$ has $n$ solutions\r\niff $f(x) \\mid (x^p - x)$.  If $d \\mid (p-1)$ then $x^d = 1 \\jmod{p}$ has $d$ solutions.\r\n\\\\\r\n\\\\\r\n{\\bf Hensel Lemma:}  Suppose $f(x) \\in {\\mathbb Z} [x]$.  If $f(a) = 0 \\jmod{p^j}$ and\r\n$f'(a) \\ne 0 \\jmod{p}$, there is a unique $t: f(a+tp^j)= 0 \\jmod{p^{j+1}}$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$f(x+h)= f(x)+ h f'(x)+ \\textnormal{ terms in } h^2 \\textnormal{ or higher}$.  $f(a)= rp^j$, so\r\n$f(a+tp^j)= f(a)+ tp^j f'(a) + \\textnormal{ terms in } p^{2j} \\textnormal{ or higher}$.  Thus\r\n$f(a+t p^j)= (r+t f'(a)) p^j \\jmod{p^{j+1}}$.   Find $t: r+t f'(a) = 0 \\jmod{p}$.  Then\r\n$f(a+tp^j)= 0 \\jmod{p^{j+1}}$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $(m,n)=1$ then $\\phi(mn)= \\phi(m) \\phi(n)$.\r\n$ \\sum_{d \\mid n} \\phi(d)= n$.\r\n$ \\phi(n)=  n \\prod_{p \\mid n} (1- {\\frac {1} {p}})$.\r\n$ 0=  \\sum_{d \\mid n} \\mu(d)$, if $n>1$; $\\mu(1)=1$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $r_1, \\ldots, r_a$ is a reduced residue set $\\jmod{m}$,\r\n$s_1, \\ldots , s_b$ is a reduced residue set $\\jmod{n}$ and\r\n$x= s_i r_j$ then $(x,mn)=1$.  Further, by the CRT, if\r\n$(x, mn)=1$ then $\\exists ! i, j: x= r_i \\jmod{m}$ and $x= s_j \\jmod{n}$.  This proves\r\nthe first statement.  If $n= p^e$ then\r\n$\\sum_{d|n} \\phi(d)= \\phi(1) + \\phi(p) + \\phi(p^2) + \\ldots + \\phi(p^e)=\r\n1 + (p-1) + (p^2-p) + \\ldots + (p^e - p^{e-1})= p^e = n$.  Applying the prior result,\r\ncompletes the proof of the second result.  If $n= p_1^{e_1} p_2^{e_2} \\ldots p_t^{e_t}$,\r\ndefine $\\mu(n)=0$, if $e_j > 1$ for any $j$, otherwise $\\mu(n)= (-1)^t$.  $\\mu$ is\r\nmultiplicative and the result follows.\r\n\\end{quote}\r\n{\\bf Definition:} If $n = {p_1}^{\\alpha_1} \\cdot {p_2}^{\\alpha_2} \\cdot \\ldots \\cdot {p_k}^{\\alpha_k}$, define\r\n$\\mu(n) = (-1)^{\\sum_{i=1}^k \\alpha_i}$.\r\n\\\\\r\n\\\\\r\n{\\bf Moebius Formula:} If $f(n)$ is multiplicative and \r\n$F(n)=  \\sum_{d \\mid n} f(d)$ then\r\n$f(n)= \\sum_{d \\mid n} \\mu(d) F({\\frac {n} {d}})$;  if\r\n$f(n)= \\sum_{d \\mid n} \\mu(d) F({\\frac {n} {d}})$ for every $n>0$ then\r\n$F(n)=  \\sum_{d \\mid n} f(d)$.\r\n$\\phi(n)=  \\sum_{d \\mid n} \\mu(d) {\\frac {n} {d}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$\\sum_{d \\mid n} \\mu(d) F({\\frac {n} {d}})\r\n\\sum_{d \\mid n} \\mu(d) \\sum_{\\delta  \\mid  {\\frac n d}} f(\\delta)$\r\n$=\\sum_{\\delta  \\mid n} \\sum_{d  \\mid  {\\frac n \\delta}} \\mu(d) f(\\delta)=\r\n\\sum_{\\delta  \\mid n} f(\\delta) \\sum_{d  \\mid  {\\frac n \\delta}} \\mu(\\delta) = f(n)$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $(x,n)=1$ then $x^{\\phi(n)}= 1 \\jmod{n}$.  Counterexample to converse\r\n(first \\emph{Carmichael Number}): 561.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe multiplicative group of a finite field is cyclic.\r\n$({\\frac {a} {p}}) = a^{\\frac {p-1} {2}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$x^p-x = \\prod_{a \\in F_p} (x-a) = x \\prod_{a \\in F_p^*} (x-a) = x (x^{p-1} -1) $.\r\nIf $F_p^*$ does not have an element of order $m=p-1$ then $\\forall x \\in F_P^*, x^k = 1$\r\nfor some $k < m$. But $x^k-1 \\ne x^m -1$ so $F_p^*$ has an element of order\r\n$m = |F_p^*|$ and so the multiplicitive group is cyclic.  Let $g$ be a generator for\r\n$F_p^*$, and suppose $a = g^n$.  $a$ is a square iff $n$ is even (and $(g^{\\frac n 2})^2 = a$).\r\nIn this case, \r\n$a^{\\frac {p-1} {2}}= ((g^{\\frac n 2})^2)^{\\frac {p-1} 2} = (g^{\\frac n 2})^{p-1} = 1$.\r\n\\end{quote}\r\n{\\bf Gauss' Lemma:} \r\nFor any odd prime, $p$ with $(a,p)=1$.  Consider the integers\r\n$a, 2a, 3a, \\ldots, {\\frac {p-1} 2}a$.  If $\\mu$ is the number of\r\nthese whose least positive residue modulo $p$ greater than ${\\frac p 2}$,\r\nthen $({\\frac a p})= (-1)^{\\mu}$.\r\n\\begin{quote}\r\nSuppose $r_1 , r_2 , \\ldots , r_{\\mu}$ be the residues that exceed ${\\frac p 2}$\r\nand $s_1, s_2 , \\ldots , s_{\\nu}$ are the residues that are less\r\nthan ${\\frac p 2}$.  Taken together the set, $s_1, \\ldots, s_{\\nu},\r\n(p-r_1), \\ldots (p-r_{\\mu})$ is just\r\n$1, 2, \\ldots , {\\frac {p-1} 2}$.  Thus,\r\n$(p-r_1 ) \\ldots (p-r_{\\mu})s_1 s_2 \\ldots s_{\\nu} =\r\n{\\frac {p-1} 2}! a^{\\frac {p-1} 2} = (-1)^{\\mu} {\\frac {p-1} 2}!$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $p$ is an odd prime and $(a,2p)=1$ then $({\\frac a p}) = (-1)^t$ where\r\n$t= \\sum_{j=1}^{\\frac {p-1} 2} \\lceil {\\frac {ja} p} \\rceil$ and $({\\frac 2 p})=\r\n(-1)^{\\frac {p^2 -1} 8}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$\\sum_{j=1}^{\\frac {p-1} 2} ja =\r\n\\sum_{j=1}^{\\frac {p-1} 2} p \\lceil {\\frac {ja} p} \\rceil + \\sum_{j=1}^{\\mu} r_j +\r\n\\sum_{j=1}^{\\nu} s_j$.\r\n\\end{quote}\r\n{\\bf Law of quadratic reciprocity:} If $p, q$ are odd primes,\r\n$({\\frac {p} {q}}) ({\\frac {q} {p}})\r\n= (-1)^{\\frac {p-1} {2} \\frac {q-1} {2}}$,\r\n$({\\frac {2} {p}}) = (-1)^{\\frac {p^2 - 1} 8}$.\r\n\\begin{quote}\r\n\\emph{Proof (Gauss):} \r\nLet $Dx = g_x p + r_x$.  Set $\\rho_x= r_x$, if $r_x < {\\frac p 2}$,\r\n$\\rho_x= r_x-p$, if $r_x > {\\frac p 2}$.  Let $n$ be the number\r\nof $\\rho_x$ that are less than $0$.  Multiplying $D, 2D, 3D \\ldots\r\n{\\frac {p-1} 2} D$ together, we get:\r\n$D^{\\frac {p-1} 2} {\\frac {p-1} 2}!= ({\\frac D p}) {\\frac {p-1} 2}!$\r\nand since\r\n$D^{\\frac {p-1} 2} {\\frac {p-1} 2}!= (-1)^n {\\frac {p-1} 2}!\\jmod{p}$,\r\n$D^{\\frac {p-1} 2}= ({\\frac D p})= (-1)^n$.  \r\nLet $D=q \\ne p$ then either $x= \\rho_x + g_x \\jmod{2}$ or\r\n$x= \\rho_x + g_x +1 \\jmod{2}$, depending on whether $\\rho_x>0$ or $\\rho_x<0$.\r\nFix $D=q$. $\\sum_{x=1}^{\\frac {p-1} 2} x = n+ \\sum_{x=1}^{\\frac {p-1} 2} \\rho_x +\r\n\\sum_{x=1}^{\\frac {p-1} 2} g_x \\jmod{2}$.  Since \r\n$\\sum_{x=1}^{\\frac {p-1} 2} x =  \\sum_{x=1}^{\\frac {p-1} 2} |\\rho_x| \\jmod{p}$,\r\n$\\sum_{x=1}^{\\frac {p-1} 2} x =  \\sum_{x=1}^{\\frac {p-1} 2} \\rho_x \\jmod{2}$.  Thus,\r\n$n= \\sum_{x=1}^{\\frac {p-1} 2} g_x \\jmod{2}$.\r\nNow $g_x= \\lfloor {\\frac {qx} p \\rfloor}$,\r\nso $({\\frac q p})= (-1)^{\\sum_{x=1}^{\\frac {p-1} 2} g_x}=\r\n(-1)^{\\sum_{x=1}^{\\frac {p-1} 2} \\lfloor {\\frac {qx} p} \\rfloor}$.  Thus \r\n$({\\frac p q}) ({\\frac q p}) = \r\n(-1)^ {{\\sum_{x=1}^{\\frac {p-1}2} \\lfloor {\\frac {qx} p} \\rfloor}\r\n+ {\\sum_{y=1}^{\\frac {q-1} 2} \\lfloor {\\frac {py} q} \\rfloor}}$.  \r\nNow use the fact that\r\n$\\sum_{x=1}^{{\\frac {p-1} 2}} \\lfloor {\\frac {xq} {p}} \\rfloor +\r\n\\sum_{y=1}^{{\\frac {q-1} 2}} \\lfloor {\\frac {yp} {q}} \\rfloor =\r\n{\\frac {(p-1)(q-1)} 4}$.  This can be derived by looking at the number\r\nof lattice points not on the $x$ or $y$ axis\r\nin a ${\\frac p 2} \\times {\\frac q 2}$ rectangle\r\nwith diagonal verticies at $(0, 0)$ and $({\\frac p 2}, {\\frac q 2})$.  \r\nLet $S= \\{ (x, y): 1 \\leq x \\leq {\\frac {p-1} 2}, 1 \\leq y \\leq {\\frac {q-1} 2} \\}$,\r\nso $|S|= {\\frac {p-1} 2} \\cdot {\\frac {q-1} 2}$.  \r\n$S_1= \\{ (x,y) \\in S: qx>py \\}$ and\r\n$S_2= \\{ (x,y) \\in S: qx<py \\}$.  \r\n$|S_1|= \\sum_{x=1}^{\\frac {p-1} 2} \\lfloor {\\frac {qx} p} \\rfloor$.  Similarly,\r\n$|S_2|= \\sum_{y=1}^{\\frac {q-1} 2} \\lfloor {\\frac {py} q} \\rfloor$ and\r\n$S= S_1 \\cup S_2$.\r\n\\\\\r\n\\\\\r\n\\emph{Another Proof of QR using Gauss Sums:} $g_a (\\zeta) = \\sum_{t=0}^{p-1} \\zeta(t)\r\n\\varsigma^{at}$.  Set $g(x)= g_1 (x)$.\r\nNumber of solutions to $x^2 = t \\jmod{p}$ is $1+({\\frac t p})$.\r\n$g_a(\\zeta)= \\zeta(a^{-1}) g(\\zeta)$ if $a \\ne 0 \\jmod{p}$ otherwise\r\nit's $0$.\r\n$\\sum ({\\frac t p}) \\varsigma^{at}= ({\\frac a p}) \\sum ({\\frac t p})\r\n\\varsigma^{t}$.\r\nIf $\\zeta$ is the principal character, $g(\\zeta)= {\\sqrt p}$.  If $\\zeta$ is\r\nreal\r\nand $g^k(\\zeta)= (g(\\zeta))^k$ then $g^2(\\zeta)= (-1)^{\\frac {p-1} 2} p$.\r\nLook at $|g(\\zeta)|^2 = T = \\sum_a\r\ng_a (\\zeta) {\\overline g_a (\\zeta)}$.  On one hand,\r\nit's\r\n$\\sum_t ({\\frac t p}) ({\\frac {-t} p}) g^2 = ({\\frac {-1} p}) (p-1) g^2$.\r\nOn the other, it's\r\n$\\sum_x \\sum_y \\sum_a g_a(\\zeta(x)) g_{-a}(\\zeta(y))=\r\n\\sum_a \\sum_x \\sum_y (\\zeta(xy)) \\varsigma^{(x-y)a} =(p-1)p$.\r\n\\\\\r\n\\\\\r\nNow set $p^*= (-1)^{\\frac {p-1} 2} p$.\r\n$g^{q-1}= (g^2)^{\\frac {q-1} 2}= ({\\frac {p^*} q})$.\r\nSo $g^q= ({\\frac {p^*} q}) g$.  On the other hand,\r\n$g^q\r\n= (\\sum_t ({\\frac t p}) \\varsigma^{t})^q \\jmod{q}=\r\n(\\sum_t ({\\frac t p})^q \\varsigma^{qt}) \\jmod{q} =\r\n({\\frac q p}) g$.  So $({\\frac {p^*} q}) = ({\\frac q p})$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$b^{n}+1$ is prime only if $n$ is a power of 2.\r\nIf $M_{p}= 2^{p}-1$ is prime, $\\Delta_{M} = \\frac {1}{2} M (M+1)$ is\r\nperfect.\r\n\\\\\r\n\\\\\r\n{\\bf Beatty:} If ${\\frac {1} {\\alpha}} + {\\frac {1} {\\beta}} = 1$ and\r\n$A= \\{ \\lfloor m \\alpha \\rfloor \\}$,\r\n$B= \\{ \\lfloor m \\beta \\rfloor \\}$ then $A \\cup B = Z$ and $A \\cap B =\r\n\\emptyset$.\r\n\\\\\r\n\\\\\r\n{\\bf Pell's Equation:} $x^2 -d y^2 = 1$ is solvable\r\n(if $d$ is not a perfect square) using\r\ncontinued fractions.\r\nLet ${\\frac p q}<{\\frac r s}$ be two rationals such that $ps-rq = -1$\r\nthen $\\forall \\lambda, \\mu, {\\frac p q} \\leq\r\n{\\frac {\\lambda p + \\mu r} {\\lambda q + \\mu s}}\r\n\\leq {\\frac r s}$.\r\nLet ${\\frac p q} \\leq {\\frac a b} \\leq {\\frac r s}$\r\nwith $ps-rq = -1$\r\nthen $a= {\\lambda p + \\mu r}$ and\r\n$b= {\\lambda q + \\mu s}$.\r\n\\\\\r\n\\\\\r\n{\\bf Primes in arithmetic progressions:} There are infinitely many primes of the form $4n+3$.\r\n{\\bf Dirichlet:}  If $a>0$ and $(a,n)=1$, then there are infinitely many primes\r\n$p$, such that $p = a \\jmod{n}$.\r\nLargest power of $p$ dividing $n!$ is\r\n$\\sum_{l \\geq 0} \\lfloor {\\frac {n} {p^l}} \\rfloor$.\r\n\\\\\r\n\\\\\r\n{\\bf Bertrand's Postulate:} For any $n$ there is a prime $p$: $n < p < 2n$.\r\n\\begin{quote}\r\n\\emph{\r\nOutline of Erdos' proof:} \\\\\r\n\\\\\r\n(1) Prove for $n<4000$.\r\n\\\\\r\n\\\\\r\n(2) $\\prod_{p \\leq n} p \\leq 4^{n}$.\\\\\r\n\\\\\r\nThis is true for $n\\le 4$.  If $n>3$ is even,\r\n$\\prod_{p \\leq n-1} p \\leq \\prod_{p \\leq n} p \\leq 4^{n-1}$ by induction.  Suppose\r\n$n>3$ is odd and put $k= {\\frac {n \\pm 1} 2}$ choosing the odd outcome.\r\n$\\prod_{k < p \\leq n} p \\leq {n \\choose k}$.  Since \r\n${n \\choose k}= {n \\choose {n-k}}$ and both appear in the expansion of $(1+1)^n$, \r\n${n \\choose k} \\leq 2^{n-1}$ and\r\n$\\prod_{p \\leq n} p = (\\prod_{p \\leq k} p ) (\\prod_{k < p \\leq n} p ) < 4^k \\cdot 2^{n-1}=4^n$.\r\n\\\\\r\n\\\\\r\n(3) \r\nLet $\\mu_p$ be the exponent of the largest power of $p$ that divides\r\n${{2n} \\choose {n}}$ and $\\nu_p: p^{\\nu_p} \\leq 2n < p^{1+\\nu_p}$.\r\nSuppose the result is false for some $n \\geq 4000$ then\r\n${{2n} \\choose {n}}=\r\n\\prod_{p \\leq 2n} p^{\\mu_p} = \\prod_{p \\leq n} p^{\\mu_p}$,\r\n$\\mu_p \\leq \\nu_p$.\r\nIf ${\\frac {2n} 3} < p \\leq n$, we have $p \\geq 3, p^2 > {\\frac 2 3} np \\geq 2n$ and\r\n$1 \\leq {\\frac n p} < {\\frac 3 2}$ and $2 \\leq {\\frac {2n} p} <3$ so\r\n$\\mu_p= \\lfloor {\\frac {2n} {p}} \\rfloor - 2 \\lfloor {\\frac {n} {p}} \\rfloor = 0$.\r\nIf ${\\sqrt {2n}} < p \\leq {\\frac {2n} 3}$, we have \r\n$p^2 > 2n$ and $\\nu_p=1, \\mu_p \\leq 1$.\r\nFor $p < {\\sqrt {2n}}$, $p^{\\mu_p} \\leq p^{\\nu_p} \\leq 2n$ and all together we have\r\n${{2n} \\choose {n}}=\r\n(\\prod_{p \\leq {\\sqrt {2n}}} p^{\\mu_p})\r\n(\\prod_{{\\sqrt {2n}}< p \\leq {\\frac {2n} 3}} p^{\\mu_p})\r\n(\\prod_{{\\frac {2n} 3} < p \\leq 2n} p^{\\mu_p}) \\leq\r\n(\\prod_{p \\leq {\\sqrt {2n}}} 2n)\r\n(\\prod_{p \\leq {\\frac {2n} 3}} p)$.  \r\nSo ${{2n} \\choose {n}} \\leq (2n)^{{\\sqrt {2n}}-2} 4^{{\\frac {2n} 3}}$,\r\n$2^{\\frac {2n} 3} < (2n)^{\\sqrt {2n}}$.\r\n\\\\\r\n\\\\\r\n(4)  Since ${2n \\choose n}$ is the largest term in $(1+1)^{2n}$,\r\n$(2n+1){2n \\choose n} > 2^{2n}$ and since $4n^2>2n+1$,\r\n$4n^2 {2n \\choose n} > 2^{2n}$ and\r\n${2n \\choose n} > 2^{2n} (2n)^{-2}$.  Thus\r\n$2^{\\frac {2n} 3} < 2^{\\sqrt {2n}}$ which can only happen if \r\n$n \\leq 450$ and the theorem holds.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThe following moduli have \\emph{primitive roots} for $p>2$, $2,4, p^k , 2p^k$.\r\nFact for {\\bf Miller-Rabin:} $n-1= 2^s r$, $r \\ne 0 \\jmod{2}$,\r\n$(a,n)=1$.  If $n$ is prime, either $a^r = 1 \\jmod{n}$ or\r\n$a^{2^j r} = -1 \\jmod{n}$ for some $j: 0 \\leq j \\leq (s-1)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}  The \r\n\\emph{Reimann zeta function} is $\\zeta (s)= \\sum {\\frac {1} {n^s}}$\r\nwhich converges for $Re(s)>1$.\r\nNote: $\\zeta (2) = {\\frac {\\pi^2} {6}}$.\r\n\\emph{Riemann hypothesis:} If $s= a+bi$,\r\nall the zeros of $\\zeta (s)$ have $a= {\\frac 1 2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Prime Number Theorem:}  Let $\\Pi(x)$ be the number of primes $\\leq x$.\r\n$\\Pi(x) \\approx ({\\frac {x} {ln(x)}})$.\r\n\\begin{quote}\r\n\\emph{Proof of weaker result:}  $\\exists a, b \\in {\\mathbb R}: \r\na{\\frac x {ln(x)}} < \\pi(x) < b{\\frac x {ln(x)}}, \r\na= {\\frac {ln(2)} 4}, b= 9 ln(2) $.\r\n\\\\\r\n\\\\\r\nLet $\\mu_p$ and $\\nu_p$ be defined as in Bertrand's postulate.\r\n$\\lfloor {\\frac {2n} {p^j}} \\rfloor - 2 \\lfloor {\\frac {n} {p^j}} \\rfloor = 0, j \\ge \\nu_p$\r\nfurther,\r\n$\\lfloor {\\frac {2n} {p^j}} \\rfloor - 2 \\lfloor {\\frac {n} {p^j}}\\rfloor \\leq 1, j \\geq 1$ so\r\n$\\mu_p \\le \\nu_p$ and ${2n \\choose n} \\mid \\prod_{p \\leq 2n} p^{\\nu_p}$.\r\nIf $n < p \\leq 2n$, $p \\mid (2n)!$ but $p \\nmid n!$ so\r\n$\\prod_{n<p \\leq 2n} p \\leq {2n \\choose n} \\leq \\prod_{n<p \\leq 2n} p^{\\nu_p} \\leq\r\n\\prod_{p \\leq 2n} 2n$.   So\r\n$n^{\\pi(2n)-\\pi(n)} \\leq {2n \\choose n} \\leq (2n)^{\\pi(2n)}$.  Taking logs,\r\n$\\pi(2n) - \\pi(n) \\leq {\\frac {2n ln(2)} {ln(2n)}}$ and \r\n$\\pi(2n) \\geq {\\frac {n ln(2)} {ln(n)}}, n>1$.  Let $2n$ be the greatest even integer\r\nin $x$ then the second inequality gives\r\n$\\pi(x) \\geq \\pi(2n) \\geq {\\frac {n ln(2)}{ln(2n)}} \r\n\\geq {\\frac {n ln(2)}{ln(x)}} \\geq\r\n{\\frac {(2n+2) ln(2)} {4 ln(x)}} > {\\frac {ln(2)} 4} {\\frac x {ln(x)}}$.\r\nFor the reverse inequality, $y \\geq 4$, let $2n$ be the smallest even integer $\\geq y$ so\r\n$y \\leq 2n, \\pi(y) \\leq \\pi(2n), y+2 > 2n, {\\frac y 2}>n-1$.  Thus\r\n$\\pi({\\frac y 2}) \\geq \\pi(n-1) \\geq \\pi(n)-1$ and\r\n$\\pi(y) - \\pi ({\\frac y 2}) \\leq \\pi(2n)-\\pi(n)+1 \r\n\\leq {\\frac {2n ln(2)}{ln(y)}}+1 \\leq {\\frac {2(y+2) ln(2)}{ln(y)}}+1\r\n\\leq {\\frac {3y ln(2)}{ln(y)}}+1 \\leq {\\frac {4y ln(2)}{ln(y)}}$.\r\nSo $\\pi(y) - \\pi ({\\frac y 2}) \\leq {\\frac {4y ln(2)}{ln(y)}}$ for $y \\geq 2$.\r\nFor $2 \\leq y <4$,\r\n$\\pi(y)-\\pi({\\frac y 2}) \\leq \\pi(4)$ and so\r\n$\\pi(y)-\\pi({\\frac y 2}) \\leq {\\frac {2/e)y} {ln(y)}}, y \\geq 2$.\r\nHence,\r\n$\r\n\\pi(y) ln(y) -\\pi({\\frac y 2}) ln({\\frac y 2})=\r\n\\pi(y) - \\pi({\\frac y 2}) ln(y)+ \\pi({\\frac y 2}) ln(2) <\r\n4y ln(2) + {\\frac y 2} ln(2) = {\\frac 9 2} y ln(2)$ and this proves the upper bound.\r\n\\end{quote}\r\n{\\bf Euler's Formula:} $\\sum_{y <n \\leq x} f(n)= \\int_y^x f(t) dt +\r\n\\int_y^x (t- \\lfloor t \\rfloor) f'(t) dt +\r\n(x- \\lfloor x \\rfloor) f(x) - (y- \\lfloor y \\rfloor) f(y)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\n$\\sum_{n \\leq x} {\\frac 1 n} = ln(x) + C + O({\\frac 1 x})$.\r\n$\\sum_n {\\frac {\\mu(n)} {n^2}}= {\\frac 1 {\\zeta(2)}}= {\\frac {6} {\\pi^2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Dirichlet:}  Let $\\alpha$ be a real number and $Q$ a positive integer.\r\nThere is a rational number ${\\frac p q}$ with $1 \\leq q \\leq Q$ such that\r\n$|\\alpha - {\\frac p q}| \\leq {\\frac 1 {qQ}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Let $B_q= \\{ {\\frac {q-1} Q} \\leq x < {\\frac q Q} \\}$.  Let\r\n$c_q = q \\alpha - \\lfloor q \\alpha \\rfloor$.  By the pigeon hole principle,\r\nat least 2 $c_q$'s must lie in a single $B_k$.  This completes the proof.\r\nIt's easy to extend this to show that if $\\alpha$ is irrational,\r\nthere are infinitely many rational numbers ${\\frac p q}$ such that\r\n$|\\alpha - {\\frac p q}| \\leq {\\frac 1 {q^2}}$, which was sharpened by\r\nHurwitz.\r\n\\end{quote}\r\n{\\bf Hurwitz:}  If $\\alpha$ is irrational,\r\nthere are infinitely many\r\nrational numbers ${\\frac p q}$ such that\r\n$|\\alpha - {\\frac p q}| \\leq {\\frac 1 {{\\sqrt 5} q^2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Liouville:}  Let $\\alpha$ be an algebraic number of degree $d \\geq 2$.\r\nThere is a constant $c(\\alpha)>0$ such that for all ${\\frac p q}$,\r\n$|\\alpha - {\\frac p q}| > {\\frac {c(\\alpha)} {q^d}}$ has only finitely\r\nmany solutions.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $f(\\xi)= a_n \\xi^n+ a_{n-1} \\xi^{n-1} + \\ldots + a_0$.  \r\n$\\exists M: |f'(y)|<M, \\forall y: \\xi-1 < y < \\xi+1$.\r\nIf $\\xi-1 < {\\frac p q} < \\xi+1$ and $f({\\frac p q}) \\ne 0$ so\r\n$|f({\\frac p q})|= {\\frac {|a_n p^n + a_{n-1} p^{n-1}q + \\ldots + a_0 q^n|}\r\n{q^n}} \\geq {\\frac 1 {q^n}}$.\r\n$f({\\frac p q})= f({\\frac p q})-f(\\xi)= ({\\frac p q} - \\xi) f'(\\eta)$.\r\nTherefore, $|{\\frac p q} - \\xi|= {\\frac {|f({\\frac p q})|} {|f'(\\eta)|}} > {\\frac 1 {M q^n}}$,\r\nproving the theorem.\r\n\\end{quote}\r\n{\\bf Roth:}  Let $\\alpha$ be an algebraic number of degree $d \\geq 2$ and\r\n$\\epsilon >0$.\r\nThere is a constant $c(\\alpha, \\epsilon)>0$ such that for all ${\\frac p q}$,\r\n$|\\alpha - {\\frac p q}| > {\\frac {c(\\alpha, \\epsilon)} {q^{2+\\epsilon}}}$.\r\nConsequence: $z = \\sum_i^\\infty 10^{-i!}$ is transcendental.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\n$(2^a -1, 2^b -1)= 2^{(a,b)} -1$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $a=bq+r$, $x^a -1 = (x^b -1) (x^{a-b} + x^{a-2b} + \\ldots +\r\nx^{a-qb})+ x^r -1$.  This parallels the construction of $(a,b)$ in the\r\nEuclidean algorithm.  \r\n\\end{quote}\r\n{\\bf Definition:}\r\nIf $x= p^k {\\frac a b}, (a,b)=(a,p)=(b,p)=1$ then $\\nu_p (x) = k$\r\nis a \\emph{$p$-adic valuation}.\r\nIf $f(x,y,z)$ over ${\\mathbb Z}$ is quadratic, then $f$ has a solution \r\nover ${\\mathbb Z}$ iff it\r\nhas a solution in the $p$-adics over for all $p$.\r\n\\emph{\r\nCounterexample for higher order equations:}\r\n$3x^3 +4y^3+5z^3=0 \\jmod{p}$\r\nis solvable for $p$ but\r\n$3x^3 +4y^3+5z^3=0$ has no solutions.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma:} $2$ is a QR $\\jmod{p}$ if $p= 1,7 \\jmod{8}$, $2$ is not\r\na QR $\\jmod{p}$ if $p= 3,5 \\jmod{8}$. $({\\frac {2}{p}})= (-1)^{\\frac {p^2-1} 8}$.\r\n\\begin{quote}\r\n\\emph{Proof:} Second part follows from first.\r\n\\end{quote}\r\n{\\bf Lemma:} Suppose $\\zeta= \\zeta_n= e^{\\frac {2 \\pi i} {n}}$.  If $n$ is odd,\r\n$x^n-y^n= \\prod_{k=0}^{n-1} (\\zeta^k x - \\zeta^{-k} y)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$x^n-y^n= \r\n\\prod_{k=0}^{n-1} (x- \\zeta^{-2k}y)=\r\n\\zeta^{1+2+\\ldots+n-1}\\prod_{k=0}^{n-1} (x \\zeta^k- \\zeta^{-k}y)$.\r\nSince $n|(1+2+\\ldots+n-1)$, the result follows.\r\n\\end{quote}\r\n{\\bf Lemma:} If $n$ is odd and $f(x)= e^{2 \\pi i} - e^{-2 \\pi i}$,\r\n${\\frac {f(nz)} {f(z)}}= \\prod_{k=1}^{\\frac {n-1} 2} f(z+ {\\frac l n})\r\nf(z- {\\frac l n})$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nPut $f(z)= e^{2 \\pi i z}-e^{-2 \\pi i z}$. Let \r\n$x=e^{2 \\pi i z}$ and\r\n$y=e^{-2 \\pi i z}$ in the Lemma above.\r\n${\\frac {f(nz)} {f(z)}} = \\prod_{k=1}^{n-1} f(z+{\\frac k n})=\r\n\\prod_{k=1}^{\\frac {n-1} 2} f(z+{\\frac k n}) f(z-{\\frac k n}) $.\r\n\\end{quote}\r\n{\\bf Lemma:}If $p$ is odd prime, $a \\in \\mathbb Z$ and $p \\nmid a$ then\r\n$\\prod_{l=1}^{\\frac {p-1} 2} f({\\frac {la} {p}})= ({\\frac a p}) \\prod_{l=1}^{\\frac {p-1} 2}\r\nf({\\frac l p})$. \r\n\\begin{quote}\r\n\\emph{Proof:} \r\nIf $1 \\leq l <p$, $la= \\pm m_l \\jmod{p}$, so\r\n$f({\\frac {la} p})= f({\\frac {\\pm m_l} p})$.  Take the product over all $l$ from\r\n$1$ to ${\\frac {p-1} 2}$ and apply Gauss' lemma ($({\\frac a p})= (-1)^{\\mu}$ where $\\mu$\r\nis the number of negative least residues.\r\n\\end{quote}\r\n{\\bf Yet another proof of QR:}\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSo $({\\frac q p})= {\\frac\r\n{\\prod_{l=1}^{\\frac {p-1} 2} f({\\frac {la} {p}})}\r\n{\\prod_{l=1}^{\\frac {p-1} 2} f({\\frac {l} {p}})} }= \r\n\\prod_{m=1}^{\\frac {q-1} 2} \\prod_{l=1}^{\\frac {p-1} 2} \r\nf({\\frac {l} {p}}+ {\\frac m q})f({\\frac {l} {p}}- {\\frac m q})$\r\nand\r\n$({\\frac p q})= \r\n\\prod_{m=1}^{\\frac {q-1} 2} \\prod_{l=1}^{\\frac {p-1} 2} \r\nf({\\frac {m} {q}}+ {\\frac l p})f({\\frac {m} {q}}- {\\frac l p})$.\r\nSince $f(-t)=-f(t)$,\r\n$({\\frac p q})({\\frac q p}) =\r\n(-1)^{{\\frac {p-1} 2} {\\frac {q-1} 2}}$.\r\n$\\prod_{l=1}^{\\frac {p-1} 2} f({\\frac {lq} {p})= (\\frac q p} \\prod_{l=1}^{\\frac {p-1} 2}\r\nf({\\frac l p})$.\r\n\\end{quote}\r\n{\\bf Lemma:} $\\sum_{t=0}^{p-1} \\zeta_p^{at} = p$, if $a=0 \\jmod{p}$ and $0$ otherwise.\r\n\\begin{quote}\r\n\\emph{Proof:}  $x^p - 1 = (x - 1) (x^{p-1} + x^{p-2} + \\ldots + 1)$.  Substituting\r\n$x = \\zeta_p^{at}$ gives the result.\r\n\\end{quote}\r\n{\\bf Definition:} $Z_f(u)= exp(\\sum_{s=1}^{\\infty} {\\frac {N_s} s} u^s)$ where\r\n$N_s$ is the number of solutions of $f(u)= 0$ in ${\\mathbb P}^n(F_{q^s})$.\r\n\\subsection{Inequalities}\r\n{\\bf Arithmetic-Geometric:}\r\n${\\frac {1} {n}} {\\sum_n {a_i}} \\geq (\\prod_n {a_i})^{\\frac 1 n}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 1:} ${\\frac {a+b} 2} \\geq {\\sqrt {ab}}$.\r\n\\\\\r\n\\emph{Proof of Lemma 1:} $({\\sqrt a} - {\\sqrt b})^2 \\geq 0$.  \r\nSo $a + b - 2{\\sqrt {ab}} \\geq 0$ and the result follows.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 2:} If $n= 2^k$ then \r\n${\\frac {\\sum_{i=1}^{n} a_i} n}  \\geq (\\prod_{i=1}^{n} a_i)^{\\frac 1 n}$.\r\n\\\\\r\n\\emph{Proof of Lemma  2:} Proof by induction on $k$.  True for $k=1$, trivially and\r\ntrue for $k=2$ by Lemma 1.  Suppose $n= 2^{k+1}$ and the lemma is true for $n= 2^k$.\r\n$ {\\frac {\\sum_{i=1}^{n} a_i} n}=\r\n{\\frac 1 2}  [ {\\frac {\\sum_{i=1}^{n/2} a_i } {n/2}} + {\\frac {\\sum_{i=n/2+1}^{n} a_i } {n/2}} ]\r\n\\geq {\\frac 1 2} \r\n[(\\prod_{i=1}^{n/2} a_i)^{2/n} + (\\prod_{i=n/2+1}^{n} a_i)^{2/n} ]$ by the induction hypothesis. \r\nNow $ {\\frac 1 2} [ (\\prod_{i=1}^{n/2} a_i)^{2/n} + (\\prod_{i=n/2+1}^{n} a_i)^{2/n} ]\r\n\\geq {\\sqrt {(\\prod_{i=1}^{n/2} a_i)^{2/n}}} {\\sqrt {(\\prod_{i=n/2+1}^{n} a_i)^{2/n}}}$\r\nby Lemma 1 and ${\\sqrt {(\\prod_{i=1}^{n/2} a_i)^{2/n}}} {\\sqrt {(\\prod_{i=n/2+1}^{n} a_i)^{2/n}}}=\r\n(\\prod_{i=1}^{n} a_i)^{1/n}$ concluding the proof of Lemma 2.\r\n\\\\\r\n\\\\\r\nFor the case when $n$ is not a power of $2$, let $2^k < n < 2^{k+1}= m$ and\r\nlet $ \\alpha = {\\frac {\\sum_{i=1}^{n} a_i} n}$.\r\n$ \\alpha = {\\frac {\\sum_{i=1}^{n} a_i} n}  =\r\n{\\frac {\\sum_{i=1}^{n} ({\\frac m n} a_i)} {m}} =\r\n({\\frac 1 m}) ({\\frac {\\sum_{i=1}^{n} a_i} {n}} +\r\n{\\sum_{i=n+1}^{m} } \\alpha) \\geq\r\n((\\prod_{i=1}^{n} a_i) (\\prod_{i=n+1}^{m} \\alpha))^{\\frac 1 m} $ where the last inequality follows from\r\nLemma 2.  Thus we have\r\n$\\alpha = {\\frac {\\sum_{i=1}^{n} a_i} n}  \\geq\r\n((\\prod_{i=1}^{n} a_i) (\\prod_{i=n+1}^{m} \\alpha))^{\\frac 1 m} =\r\n((\\prod_{i=1}^{n} a_i) \\alpha^{m-n})^{\\frac 1 m} $.  Raising both sides to the $m$-th power and\r\ndividing by $\\alpha^{m-n}$, we get\r\n$\\alpha^n \\geq (\\prod_{i=1}^{n} a_i)$ and the theorem follows.\r\n\\end{quote}\r\n{\\bf Triangle Inequality:} $|x|+|y| \\geq |x+y|$.\r\n\\\\\r\n\\\\\r\n{\\bf Cauchy-Schwartz:} $|u \\cdot v|  \\leq ||u|| ||v||$.\r\n\\begin{quote}\r\n\\emph{Proof:} Look at\r\n$\\sum (a_i x + b_i )^2$.  Get $(\\sum {a_i}^2)x^2 + 2 (\\sum a_i b_i) x +\r\n\\sum {b_i}^2$.  Complete square. Constant is always $\\geq 0$.\r\n\\end{quote}\r\n{\\bf Holder's inequality:}\r\nIf ${\\frac {1} {p}} + {\\frac {1} {q}} = 1$ then\r\n${\\frac {a^p} {p}} + {\\frac {b^q} {q}} \\geq ab$ and\r\n$(\\sum_{i} {a_i}^p )^{\\frac 1 p} \\cdot (\\sum_{i} {b_i}^q )^{\\frac 1 q}  \\geq\r\n\\sum_{i} a_i b_i $.\r\n\\begin{quote}\r\n\\emph{Proof:} If $f$ is\r\nmonotonically increasing, $f(0)= 0$, then $\\int_0^a f + \\int_0^b f^{-1} \\geq\r\nab$.\r\n\\\\\r\n\\\\\r\n\\emph{Another proof:}  You can prove first part using Arithmetic-Geometric inequality.\r\nApply this inequality repeatedly with\r\n$a= {\\frac {a_{i}} {(\\sum_{i=1}^n {a_i}^p)^{\\frac 1 p}}}$ and\r\n$b= {\\frac {b_{i}} {(\\sum_{i=1}^n {b_i}^q)^{\\frac 1 q}}}$.  Adding these we get\r\n$(\\sum_{i=1}^n {{a_i}^p})^{\\frac 1 p}\r\n(\\sum_{i=1}^n {{b_i}^q})^{\\frac 1 q} \\geq\r\n\\sum_{i=1}^n a_i b_i$.\r\n\\end{quote}\r\n{\\bf Minkowski's inequality:}\r\n$(\\sum {a_i}^p )^{\\frac 1 p} +\r\n(\\sum {b_i}^p )^{\\frac 1 p} \\geq (\\sum (a_i + b_i )^p )^{\\frac 1 p}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Write\r\n$(x_1+x_2)^p +(y_1+y_2)^p\r\n= [(x_1+x_2)^{p-1}x_1 +(y_1+y_2)^{p-1} y_1]\r\n+ [(x_1+x_2)^{p-1}x_2 +(y_1+y_2)^{p-1} y_2]$.  Apply Holder to each term to\r\nget\r\n$(x_1^p+y_1^p)^{\\frac 1 p}\r\n[(x_1+x_2)^{(p-1)q}\r\n+(y_1+y_2)^{(p-1)q}]^{\\frac 1 q} \\geq\r\nx_1(x_1+x_2)^{p-1} +\r\ny_1(y_1+y_2)^{p-1}$ and\r\n$(x_2^p+y_2^p)^{\\frac 1 p}\r\n[(x_1+x_2)^{(p-1)q}\r\n+(y_1+y_2)^{(p-1)q}]^{\\frac 1 q} \\geq\r\nx_2(x_1+x_2)^{p-1} +\r\ny_2(y_1+y_2)^{p-1}$.  Since ${\\frac 1 p} + {\\frac 1 q} = 1$, $(p-1)q=p$.\r\nAdding the two inequalities and dividing by\r\n$[(x_1^p+x_2^p) + (y_1^p+y_2^p)]^{\\frac 1 q}$ while noting that\r\n$1 - {\\frac 1 q} = {\\frac 1 p}$, we get Minkowski.\r\n\\end{quote}\r\n{\\bf Chebyshev's inequality:}\r\nIf $a_1 \\leq a_2 \\ldots \\le a_n$, $b_1 \\leq b_2 \\ldots \\le b_n$\r\n$({\\frac {1} {n}} \\sum a_i )\r\n({\\frac {1} {n}} \\sum b_i ) \\leq\r\n({\\frac {1} {n}} \\sum a_i b_i)$. \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy the rearrangement inequality,\r\n$a_1 b_1 + a_2 b_2 + \\ldots + a_n b_n \\geq a_1 b_1 + a_2 b_2 + \\ldots + a_n b_n$,\r\n$a_1 b_1 + a_2 b_2 + \\ldots + a_n b_n \\geq a_1 b_2 + a_2 b_3 + \\ldots + a_n b_1$, ...\r\n$a_1 b_1 + a_2 b_2 + \\ldots + a_n b_n \\geq a_1 b_n + a_2 b_1 + \\ldots + a_n b_{n-1}$.\r\nAdding the $n$ inequalities, we get\r\n$n \\sum a_i b_i \\geq a_1 \\sum b_j + a_2 \\sum b_j + \\ldots + a_n \\sum b_j$ or\r\n$n \\sum a_i b_i \\geq (\\sum a_i) (\\sum b_j) $.\r\n\\end{quote}\r\n{\\bf Observation:} $\\sum_i a_i b_i$ is max when $a_i$ and $b_i$ are in order, $a_, b_i \\geq 0$.\r\n$min(a,b) \\leq {\\frac {2ab} {a+b}} \\leq\r\n{\\sqrt ab} \\leq {\\frac {a+b} 2} \\leq\r\n{\\sqrt {\\frac {a^2 + b^2} 2}} \\leq max(a,b)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n\\emph{Concave (convex downwards, convex cap --- like $-x^2$):}\r\n$f( tx+(1-t)y) \\geq tf(x)+(1-t)f(y)$.  \r\n\\emph{Convex (convex upwards, convex cup--- like $x^2$):}\r\n$f( tx+(1-t)y) \\leq tf(x)+(1-t)f(y)$.\r\n\\\\\r\n\\\\\r\n{\\bf Jensen's Theorem:} If $f$ is convex, $E(f(X)) \\leq f(E(X))$.\r\nIf $f$ is concave, $E(f(X)) \\geq f(E(X))$.\r\nConsequence:\r\n$log(x) \\leq (x-1)$, equality iff $x=1$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $\\lambda_1 + \\lambda_2 = 1$ then $f(\\lambda_1 x + \\lambda_2 y) \\leq\r\n\\lambda_1 f(x) + \\lambda_2 f(y)$, by definition. Now apply induction.\r\n\\end{quote}\r\n{\\bf Hadamard inequality:}\r\n$|D(a_1 , a_2 , a_3 , \\ldots , a_n )| \\leq ||a_1 || \\cdot ||a_2 || \\ldots\r\n\\cdot ||a_n ||$.\r\n$a^2 + b^2 + c^2 \\geq ab + ac + bc$ and\r\n${\\frac {b} {a+c}} + {\\frac {a} {b+c}} + {\\frac {c} {b+c}} \\geq {\\frac {3}\r\n{2}}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Weighted AM-GM:}  If\r\n$\\lambda_1, \\ldots , \\lambda_n >0$ and\r\n$\\sum_{i=1}^n \\lambda_i= 1$, then\r\n$\\sum_{i=1}^n \\lambda_i x_i \\geq \\prod_{i=1}^n x_i^{\\lambda_i}$.\r\n\\subsection{Combinatorics and Sets}\r\nLet $f(x)= c_k x^k + \\ldots + c_0$ be a polynomial\r\nwith $c_0 c_k \\ne 0$ which factors as\r\n$f(x)= c_k {(x- r_1 )}^{m_1} \\ldots {(x- r_l )}^{m_l}$, then a sequence\r\n$\\{a_n \\}$ satisfies a \\emph{linear recurrence} with characteristic polynomial\r\n$f(x)$ iff $\\exists : g_1 (x) , \\ldots , g_l (x)$ such that\r\n$a_n = g_1 (n) {r_1}^n + \\ldots + g_l (n) {r_l}^n$ where\r\n$deg(g_{i})<m_{i}$.\r\n\\begin{quote}\r\n\\emph{Proof:} Put $a_n = a_j {\\alpha_j}^n$ where $f(\\alpha_j)=0$.\r\nThen $c_k {\\alpha_j}^k + \\ldots + c_0 = 0$.  These solutions are linearly independent for $1 \\leq j \\leq k$, so the general solution\r\nis a linear combination of these solutions.\r\n\\end{quote}\r\n{\\bf Power Means:}  If $k_1 \\geq k_2$ and $a_i \\geq 0$ then \r\n$ (\\sum_{i=1}^n {\\frac {a_i^{k_1}} {n}})^{k_2} \\geq (\\sum_{i=1}^n {\\frac {a_i^{k_2}} {n}})^{k_1} $.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$(\\sum_{i=1}^n {\\frac {a_i^{k_1}} n})^{\\frac 1 {k_1}} \\leq (\\sum_{i=1}^n {\\frac {a_i^{k_2}} n})^{\\frac 1 {k_2}}$,\r\nso $(\\sum_{i=1}^n {\\frac {a_i^{k_1}} n})\\leq (\\sum_{i=1}^n {\\frac {a_i^{k_2}} n})^{\\frac {k_1} {k_2}}$.\r\n$f(x) = x^{\\frac {k_2} {k_1}}$ is concave, so applying Jensen:\r\n$(\\sum_{i=1}^n {\\frac {a_i^{k_1}} n})^{\\frac {k_2} {k_1}} \\geq (\\sum_{i=1}^n {\\frac {a_i^{k_2}} n})$. So\r\n\\end{quote}\r\n{\\bf Linear congruential generator:}\r\n$x_{n+1} = (a x_{n} + c) \\jmod{m}$\r\nhas period $n$ if $(c,m)=1$.  $b=a-1$, $b=0 (p)$ if $p|m, b=0 (4)$\r\nif $m=0 (4)$.\r\n\\\\\r\n\\\\\r\n{\\bf Burnside counting:}  Let a permutation group $G$ act on $A$ inducing an equivalence\r\nrelation $S$.  Let $n$ be the number of equivalence classes.\r\n$n= {\\frac 1 {|G|}} \\sum_{g \\in G} |A_g|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Count\r\n$S= \\{ (a,g), a \\in A, g \\in G: a^g=a \\}$ two different ways.\r\n\\end{quote}\r\n{\\bf Notation:}\r\nLet $D$ be a set of elements permuted by\r\na group $G$ and $R$ be a set of colors.  A \\emph{coloring} is a map $f:D \\rightarrow R$.\r\nThe set of colorings is denoted by $R^D$.\r\nTwo colorings, $f_1 , f_2$, are \\emph{equivalent}\r\nif $f_1(d) = f_2 (d^g ), \\forall d$.  Let $w$ be a map from $R$ to a set of \\emph{weights}.\r\nThe term $\\sum_{r \\in R} w(r)$ is called the \\emph{store}.  If $f: D \\rightarrow R$ then\r\n$W(f)= \\prod_{d \\in D} w(f(d))$ is called the weight of $f$.  If $F$ is a set of\r\nfunctions from $D \\rightarrow R$, ${\\cal I}(F)= \\sum_{f \\in F} W(f)$.  If\r\n$F_G$ consists of a representative of each equivalence class under $G$ of $F$,\r\n${\\cal I}(F_G)$ is called the \\emph{pattern inventory}.\r\nSuppose $F= \\bigcup_i F_i$ where $F_i$ are a set of functions of\r\nweight $i$ and suppose $\\pi \\mapsto \\pi^{(i)}$ is the homomorphisms that\r\ntake permutations of $D$ to the\r\naction induced by equivalent coloring on the functions of $F_i$.  \r\nLet $cyc(\\pi)$ be the number of cycles in $\\pi$.\r\nFinally, define\r\n$P_{G}(x_{1}, x_{2}, \\ldots , x_{n})= {\\frac {1} {|G|}} \\sum_{g \\in G}\r\nx_{1}^{\\pi_{1}(g)} x_{2}^{\\pi_{2}(g)} \\ldots x_{n}^{\\pi_{n}(g)}$, where $\\pi_i$ is the number\r\nof cycles of length $i$ in $g$.\r\n\\emph{Example:}  Consider a string of three beads colored either $r$ or $b$.  \r\n$D= \\{1,2,3\\}$ and $R= \\{r, b\\}$.  \r\n$G= \\langle (13) \\rangle$ so that the order of beads on a string doesn't matter.\r\n$P_G(x_1, x_2)= {\\frac 1 2} (x_1^3 + x_1 x_2)$.  Let $F$ be a set of representatives\r\nof colorings from each equivalence class.\r\n${\\cal I}(F_G)= {\\frac 1 2}[(r+b)^3+(r+b)(r^2 + b^2)]= b^3 + 2r^2b + 2 b^2r + r^3$, so there are\r\nsix distinct (under the action of $G$) patterns.\r\n\\\\\r\n\\\\\r\n{\\bf Observation:}\r\nLet $D_1, D_2, \\ldots, D_k$ be a partition of $D$ into disjoint sets.\r\nSince $\\sum_{r \\in R} w(r)^{|D_i|}$ is a\r\nrepresentation of the number of ways to distribute the objects\r\nin $D_i$ so they will end up in the same color,\r\n$\\prod_{i=1}^k [\\sum_{r \\in R} w(r)^{|D_i|}]$ is the inventory of\r\n$D^R$ in which elements of each $D_i$ have the same color.\r\n\\\\\r\n\\\\\r\n{\\bf Polya's Theorem:} Let $F$ be a set of functions from $D \\rightarrow R$,\r\n${\\cal I}(F_G)= P_G(\\sum_r w(r), \\sum_r w(r)^2, \\ldots , \\sum_r w(r)^k, \\ldots)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $F= \\bigcup_i F_i$ and $m_i$ be the number of equivalence classes of \r\nweight $W_i$ in $F_i$ then, by Burnside, \r\n${\\cal I}(F_G)= \\sum_i m_i W_i= \\sum_i {\\frac 1 {|G|}} \\sum_{g \\in G} \\psi(g^{(i)}) W_i=\r\n{\\frac 1 {|G|}} \\sum_{g \\in G} (\\sum_i \\psi(g^{(i)})) W_i$ where\r\n$\\psi(g^{(i)})$\r\nis the number of colorings fixed by $g^{(i)}$.\r\nNote that $(\\sum_i \\psi(g^{(i)}))W_i$ is the inventory \r\nof all equivalent $f$ and so\r\n$\\sum_i \\psi(g^{(i)}) W_i = \\prod_j (\\sum_r w(r)^j)^{b_j}$ \r\nwhere $b_j$ is the number of cycles of\r\nlength $j$ in $g$.  This completes the proof.\r\n\\end{quote}\r\n\\emph{Example (Vertices on cube):}\r\n$P_G= {\\frac {1} {24}}\r\n(x_{1}^{8}+ 9x_{2}^4+ 6x_{4}^{2} + 8x_{1}^{2} x_{3}^2)$.  For two colors,\r\nthe number of patterns is $23$.\r\n\\emph{Example (Faces on cube):}\r\n$P_G= {\\frac {1} {24}}\r\n(x_{1}^{6}+ 6x_{1}^{2}x_{4}+ 3x_{1}^{2}x_{2}^2 + 6x_{2}^{3} + 8x_{3}^{2})$.\r\nFor $f \\in R^{D}$, store: $\\sum w(r)$, inventory: $W(f)= \\prod_{d} f(d)$,\r\npattern inventory of $R^{D}= \\sum_{f} W(f)$.\r\n\\\\\r\n\\\\\r\n{\\bf Corollary:}\r\nNumber of equivalence classes= $P_{G}(|R|,|R|, \\ldots |R|)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nAssign a weight of $1$ to each element of $R$ and apply Polya.\r\n\\end{quote}\r\n${\\bf (v, k, t, \\lambda )}$ {\\bf design:}\r\n$|X|= v$, $B$ is a set of $k$ subsets of\r\n$X$ is a design if each $t$ subset $T$ of $X$,\r\nthe number of blocks containing $T$ is\r\n$\\lambda$ and $|B|=b$.\r\n$r$, the incidence number, is the number of blocks incident\r\nwith one point.  These designs are denoted $t-(v,k, \\lambda )$ or\r\n$S_{\\lambda}(t, k, v)$.\r\n$b_i = \\lambda\r\n{\\frac\r\n{{{v-i} \\choose {t-i}}}\r\n{{{k-i} \\choose {t-i}}}\r\n}$,\r\n$b_0 =b$,\r\n$b_1 = r$.\r\n${\\frac {(vr)} {k}} \\leq {{v} \\choose {k}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Hall's Theorem:} $J(A)= \\{ y \\in Y, (x,y) \\in E, x \\in A \\}$\r\nand $|J(A)| \\geq |A|$ if and only if there is a complete matching.\r\n\\\\\r\n\\\\\r\n{\\bf Inclusion-Exclusion:}  Let $A_1 , A_2 , \\ldots , A_n$ be a family of \r\nsubsets of $X$.  The elements\r\nof X that are not in $\\bigcup_i^n A_i$ is\r\n$\\sum_{I \\subseteq [n]} (-1)^{| I | } |A_I |$ where\r\n$A_I = \\bigcap_{i \\in I} A_i$. (Note:\r\n$A_{\\phi}= X$.)  For classical statement, let $A_i = \\{ x: c_i (x)\r\n\\; is \\; true\\}$.  Somtimes this is written\r\n$N({\\overline {a_1}}, {\\overline {a_2}}, \\ldots ,{\\overline {a_n}})= N - \\sum_i N(a_i) + \\sum_{i,j} N(a_i , a_j) + \\sum_{i,j,k} N(a_i , a_j , a_k) - \r\n\\ldots +(-1)^n N(a_1, a_2,\\ldots, a_n)$.\r\n\\\\\r\n\\\\\r\n{\\bf Ramsay:} Let $P_{r}(S)$ be the $r$-subsets of $S$.\r\nLet $P_{r}(S)= A_{1} \\cup \\ldots \\cup A_{t}$ and $1 \\leq r \\leq q_{1},\\ldots\r\nq_{t}$.\r\n$\\exists N(r, q_{1},\\ldots q_{t})$ such that for $n \\geq N$, S contains a\r\n$(q_{i},A_{i})$.\r\n$R(m,n) \\leq R(m-1, n) + R(m, n-1)$ and $R(s,t) \\leq {(s+t-2) \\choose\r\n(s-1)}$.\r\n\\\\\r\n\\\\\r\n{\\bf Generating Functions:} Let $12$ objects be distributed to $A, B, C$ subject\r\nto: $A$ gets at least 4, $B$ and $C$ get at least 2 and $C$ gets no more\r\nthat 5.  The coefficient of $x^{12}$ in\r\n$(x^4 + \\ldots x^8 ) (x^2 + \\ldots x^8 ) (x^2 + \\ldots x^5 )$ is the number\r\nof ways this can happen.\r\nFor selections with repetitions note that:\r\n$({\\frac {1} {1-x}})^n = \\sum_i {{n+i-1} \\choose {i}} x^i$.  For partitions,\r\nexamine\r\n$ {\\frac {1} {1-x}}({\\frac {1} {1-x}})^2 \\ldots$.\r\nExponential generating functions:\r\n$f(x)= a_0 + a_1 x +\r\n{\\frac {1} {2!}} a_2 x^2 + \\ldots\r\n{\\frac {1} {k!}} a_k x^k  + \\ldots$.\r\nDifference calculus: $\\sum_i i^n = (1+ \\Delta )^n u_0$.\r\n\\\\\r\n\\\\\r\n{\\bf Counting results:}\r\n\\emph{Dearrangements:} $n! ( 1 - {\\frac 1 {1!}} +{\\frac 1 {2!}} -{\\frac 1 {3!}}\r\n\\ldots + (-1)^{n} {\\frac 1 {n!}})$. \r\n\\emph{Menages ($i$ is not in $i+1$ $\\jmod{n}$):}\r\n$\\sum_{r=0}^{n} (-1)^{r} (n-r)! {(2n-r) \\choose r} {\\frac {2n} {2n-r}}$.\r\nNumber of solutions of \r\n$n_1 + n_2 + \\ldots + n_r = r$ is ${(n+r-1) \\choose r}$.\r\n\\emph{Restricted permutation positions:}\r\n$N(a_1 ', a_2 ' , \\ldots , a_{n-1} ')= n! -\r\n{{n-1} \\choose 2} (n-2)!  +{{n-1} \\choose 3} (n-3)! -\r\n\\ldots + (-1)^{n} {{n-1} \\choose {n-1}} (n-1)!$.\r\nFor permutations of a, b, c, d, e, f which don't contain ace or fd:\r\n$N(a_1 ', a_2 ')= 6!-4!-5! + 3!$.\r\n\\emph{Rook polynomials:}\r\n$R(x, C)= xR(x,C_i ) + R(x, C_e )$.\r\n\\emph{Forbidden positions:}\r\n$N(a_i ', a_2 ', \\ldots , a_n ') = e_0 =\r\nn! - r_1 (n-1)! + r_2 (n-2)! - \\ldots = \\sum (-1)^j r_j (n-j)!$.\r\n\\emph{Exactly $m$ with property:}\r\n$e_m =  \\sum_{j=0}^n (-1)^j {{m+j} \\choose {j}} s_{m+j}$.\r\n\\emph{Fixed points in a random permutation:}  \r\nLet $h: GF(2)^n \\rightarrow GF(2)^n$ be a random\r\npermutation.  The limit as $n \\rightarrow \\infty$ that $h$ has $p$ fixed points is\r\n${\\frac 1 {pe}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf the number of surjective maps from $[m] \\rightarrow [n]$ is denoted $S(m,n)$,\r\n$S(m,n)= \\sum_{k=0}^n {(-1)^{n-k}} {n \\choose k} k^m$.\r\n$n!= \\sum_{i=0}^n {(-1)^i} {n \\choose i} (n-i)^n$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy induction on $n$.  If $n > m$, $S(m,n)=0$ and $S(m,0)=4$ always.  If $m \\ge n \\ge 1$, there\r\nare ${n \\choose k}$ distinct $k$-subsets of $[n]$; any map is surjective on some $k$-subset so\r\n$n^m= \\sum_{k=0}^n {n \\choose k} S(m,k)$.  Now use the following \\\\\r\n\\emph{Lemma:} If $B_n= \\sum_{k=0}^n {n \\choose k} A_k$ then \r\n$A_k= \\sum_{k=0}^n {n \\choose k} (-1)^{n+k} B_k$.\\\\\r\n\\\\\r\n\\emph{Proof of Lemma:}\r\n$\r\n\\sum_{k=0}^n {n \\choose k} (-1)^{n+k} B_k=\r\n\\sum_{k=0}^n {n \\choose k} (-1)^{n+k} \r\n(\\sum_{r=0}^k {k \\choose r} A_r)=\r\n\\sum_{k=0}^n \\sum_{r=0}^k \r\n{n \\choose k} {k \\choose r} A_r) (-1)^{n+k}$.  \r\nThe coefficient of $A_n$ in this sum is $1$ and the coefficient of $A_r, r<n$, denoted\r\n$\\lambda_r$ in this sum is $0$.  \r\n$\\lambda_r= \\sum_{k=r}^n {n \\choose k} {k \\choose r} (-1)^{n+k} $ and the second term in the sum\r\nis equal to ${(n-r) \\choose (k-r)}$, so\r\n$\\lambda_r= (-1)^{n+k}  {n \\choose r} \\sum_{j=0}^{n-r} {(n-r)\\choose j} (-1)^{r+j} = 0 $.\r\n\\end{quote}\r\n{\\bf Multinomial coefficients:} ${ {a+b+c} \\choose {a, b, c}}$ and\r\n$(x+y+z)^{a+b+c}$.\r\n${ {ne} \\choose k} \\leq ({\\frac {ne} {k}})^k$,\r\n${n \\choose k} \\geq ({\\frac n k})^k$.  Identities:\r\n$\r\n{r \\choose k} = {\\frac {r} {k}}{r-1 \\choose k-1},\r\n{n \\choose k} = {n-1 \\choose k} + {n-1 \\choose k-1},\r\n{r \\choose k} = {{(-1)}^{k}}{k-r-1 \\choose k},\r\n{r \\choose m} {m \\choose k} = {r \\choose k} {r-k \\choose m-k} ,\r\n\\sum_{k=0}^{n}{r+k \\choose k} = {{r+n+1} \\choose {n}},\r\n\\sum_{k=0}^{n}{k \\choose m} = {n+1 \\choose m+1},\r\n\\sum_{k=0}^{n}{r \\choose k}{s \\choose n-k}  = {r+s \\choose n},\r\n\\sum_{k=a}^{b-1} f(k)= \\int_{k=a}^{b-1} f(x) dx +\r\n\\sum_{k=1}^m {\\frac {B_{k}} {m!}} f^{(k-1)}(x)^{b}_{a}+ R_{m},\r\na_{n} T_{n} = b_{n} T_{n-1} + c_{n} \\rightarrow\r\ns_{n} a_{n} T_{n} = s_{n} b_{n} T_{n-1} + s_{n} c_{n} ,\r\ns_{n} b_{n} = s_{n-1} a_{n-1},\r\nR_{n} = s_{n} a_{n} T_{n},\r\nR_{n} = R_{n-1} +s_{n} c_{n},\r\n{-n \\choose r}= (-1)^r {n+r-1 \\choose r},\r\n(1+x)^{-n} = 1 + {-n \\choose 1} x^{-1} + \\ldots + {-n \\choose n} x^{-n}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} $S(n,k)$, or  \r\n\\emph{Stirling numbers of the first kind}, is the number permutations in\r\n$S_n$ with exactly $k$-cycles.\r\n$T(n, k)$, or \\emph{Stirling numbers of the second kind}, is the number of ways of\r\ngrouping $n$ objects into $k$ groups.\r\nThe \\emph{Bell numbers}, $B_n$, are the number of ways to divide $n$ things into groups.\r\n$B_{n+1}= \\sum_{k=0}^n {n \\choose k} B_n $.\r\n$ \\sum_{k=0}^{n} S(n,k) = b_{n} , S(n+1, k) = k S(n,k) + S(n, k-1)$\r\n$ \\sum_{k=0}^{n} T(n,k) = n! , T(n+1, k) = n T(n,k) + T(n, k-1)$.\r\nLet $B_{n}$ denote the $n$-th \\emph{Bernoulli number} then\r\n$\\sum_{j=0}^m {{m+1} \\choose j} B_j = 0$\r\nand $B_0=1$.  ${\\frac x {e^x-1}} = \\sum_{n=0}^{\\infty} B_n {\\frac {x^n} {n!}}$.\r\n\\emph{Catalan numbers:}\r\n$c_{n} = \\frac {1} {n+1} {2n \\choose n} , c_n = \\sum_{k=0}^{n-1} c_k c_{n-k-1}$.\r\n\\\\\r\n\\\\\r\n{\\bf Partitions:} Let $p(n)$ be the number of partitions of $n$.  Then,\r\n$p(n) \\approx \\frac{1}{4n \\sqrt{3}} e^{\\sqrt{\\frac {2n} {3}}}$.\r\nThe number of partitions of $n$ into $k$ things is the number of partitions\r\nof $n$ with largest partition $k$.\r\n\\\\\r\n\\\\\r\n{\\bf A Theorem of Erdos:}\r\nA sequence of $(n-1)(m-1) + 1$ different numbers has either an increasing\r\nsub-sequence of length $n$ or a decreasing sub-sequence of length $m$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $x \\in B_r$ if the longest increasing sequence beginning with\r\n$x$ has length $n$.  If any $B_r$, with $r \\geq n$ is non empty, we're done.\r\nOtherwise, there must be a $B_k$ with $k<n$ containing at least $m$ elements.\r\nThese $m$ elements form a decreasing sequence.\r\n\\\\\r\n\\\\\r\nSimilarly, if $1 \\leq a_1 , \\ldots , a_n \\leq m$ and\r\n$1 \\leq b_1 , \\ldots , b_n \\leq m$ ,  $\\exists p,q,r,s$ with\r\n$a_{p+1} + \\ldots + a_{p+q} = b_{r+1} + \\ldots + b_{r+s}$.\r\n\\emph{Proof:} Let $j=j(k)$ be the smallest integer with\r\n$a_1 + \\ldots + a_j \\geq\r\nb_1 + \\ldots + b_k$.  Let $c_k = \\sum_{i=1}^{j(k)} a_i - \\sum_{i=1}^k b_i$.\r\nAt least two $c_l$'s (say $c_u$ and $c_v$, $u>v$) are equal.  $c_u-c_v$\r\nprovides the right sequence.\r\n\\end{quote}\r\nIn permutation, $i<j$ and $a_i > a_j$ is \\emph{inversion}.  Inversion table is\r\n$( b_j )$ where $b_j =$ number of elements left of $j$ that are $>j$.\r\nFor 5 9 1 8 2 6 4 7 3, it's 2 3 6 4 0 2 2 1 0.  Inversion table uniquely\r\ndetermines permutation.  Inverse has same number of inversions.\r\n\\\\\r\n\\\\\r\n{\\bf Generating permutations of $[1,n]$:}\\\\\r\n\\jt Set $\\pi = 123 \\ldots n$.  Output $\\pi$.\\\\\r\n\\jt If $\\pi_i > \\pi_{i+1}$, $\\forall i$, stop.\\\\\r\n\\jt Get largest $i$: $\\pi_i < \\pi_{i+1}$.\\\\\r\n\\jt Find smallest $j$: $i<j$ such that $\\pi_i < \\pi_j$.\\\\\r\n\\jt $\\pi_i \\leftrightarrow \\pi_j$.\\\\\r\n\\jt Reverse the order of the numbers following, $\\pi_j$, denote this\r\nby $\\pi$.\\\\\r\n\\jt Output $\\pi$.  Go to 2.\\\\\r\nAnother algorithm: Steinhaus weaving generator (by recursion).\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}  \r\nThe \\emph{permanent}, $per( a_{ij} )$, $m \\times n$ matrix, is\r\n$\\sum_{\\sigma} a_{1 i_1} a_{2 i_2} \\ldots a_{m i_m}$ where\r\n$\\sigma$ runs through $m$ permutations of $[n]$.\r\n$ n!= per(J) = \\sum_{r=0}^{n-1} {n \\choose r} (-1)^{r} (n-r)^{n}$.\r\nLet $A_r$ be the matrix obtained by replacing $r$ specified\r\ncolumns of $A$ by $0$.  Let $S(A_r )$ be the product of row sums of\r\n$A_r$.  Let $\\sum_r S(A_r )$ over all choices of r:\r\n$ per(A)= \\sum S(A_{n-m}) - {n-m+1 \\choose 1} S(A_{n-m+1}) +\r\n\\ldots (-1)^{m-1} {n-1 \\choose m-1} S(A_{m-1}) $.  \\\\\r\n\\\\\r\n{\\bf Graph theory definitions:}  \r\n${\\cal G}(V,E)$ a graph with vertex set $V$ and edge set $E$.\r\n$g({\\cal G})$ - girth - length of minimum cycle.\r\n$\\omega ({\\cal G})$- clique number.\r\n$\\alpha ({\\cal G})= \\omega (\\overline {{\\cal G}})$- independence number.\r\n$\\chi ({\\cal G})$ - chromatic number.\r\n$\\delta({\\cal G})$ - minimum degree.\r\n$\\Delta ({\\cal G})$ - maximum degree.\r\n$d (x,y)= $ number of edges between x and y.\r\n$D_{\\cal G} (x,y)= max_{x, y} d(x, y)$.\r\nCayley graph.  Strongly regular graphs. Expander graphs and short paths.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nA graph is \\emph{bipartite} iff it contains no cycles of odd length.\r\n$\\alpha ({\\cal G}) \\chi ({\\cal G}) \\geq n$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} There are $n^{n-2}$ labeled trees with $n$ nodes.  \r\n\\begin{quote}\r\n\\emph{Proof:} Use \\emph{Prufer code} for tree $T$: remove leaf with smallest\r\nlabel, add the label of the vertex it's connected to at end of sequence.\r\n\\end{quote}\r\n{\\bf Graph counting:}\r\n$G(n, M), N= {n \\choose 2}$.  Random graph selecting  $M$ of the $N$ edges.\r\n$Pr[G=H]= p^{e(H)} q^{N-e(H)}$.\r\n$X_s (G)= $ number of complete graphs of order $s$.\r\n$E(X_s )=  \\sum_{\\alpha \\in S}  E( Y_{\\alpha} (G)$, where\r\n$Y_{\\alpha} (G) = 1$, if $G[ \\alpha ] = K_{\\alpha}$, $0$ otherwise.\r\n$E_M (Y_{\\alpha} )= P_M (G_p [ \\alpha ]= K_{\\alpha})= p^S =\r\n{{N-S} \\choose {M-S}} {N \\choose M}^{-1}$.\r\n$E_p ( X_s )= {n \\choose s} p^s$.\r\nIf $a$ is the order of the automorphism group of $F$ then $K_k$ has\r\n${\\frac {k!} {a}}$ subgraphs isomorphic to $F$.\r\n$N_F = {n \\choose k} {\\frac {k!} {a}}= {\\frac {(n)_k} {a}}$.\r\nFor cycles, $a= 2k$.\r\n\\\\\r\n\\\\\r\n{\\bf Another Theorem of Erdos:}  There is a graph, $G$, with $g(G) \\geq n$ and\r\n$\\chi (G) \\geq n$.  Another formulation:  Given natural numbers \r\n$g \\geq 3$,\r\n$k \\geq 2$, $\\exists G$, with $|G| k^{3g}$, $g(G) \\geq g$\r\nand $\\chi (G) \\geq k$.\r\n\\begin{quote}\r\nFact 1: If $G \\in G(n, p)$, $q= 1-p$ then\r\n$Pr[ \\alpha (G) \\geq k ] \\leq  {{n} \\choose {k}} q^{{k} \\choose {2}}$\r\nFact 2: Markov's inequality.\r\nFact 3: Let X be a r.v. representing the number of $k$-cycles.\r\n$E(X) = {\\frac {(n)_k} {2k}} p^k$.\r\nFact 4: If $k>3$ and $p(n)$ is a function with\r\n$p(n) \\geq {\\frac {6 k ln(n) } {n} }$ then\r\n$lim_{n \\rightarrow \\infty} Pr [ \\alpha \\geq {\\frac {n} {2k}} = 0$:\r\n${{n} \\choose {r}} q^{{r} \\choose {2}} \\leq n^n q^{{r} \\choose {2}} \\leq\r\n{(n e^{- p {\\frac {r-1} {2}}})^r}$ inside expression is\r\n$\\leq {\\sqrt {\\frac {e} {n}}} \\rightarrow 0$.\r\n\\\\\r\n\\\\\r\nArgument:  Fix $ 0 < \\epsilon < {\\frac {1} {k}}$, $p= n^{1- \\epsilon}$,\r\n$X(G)$ is the number of cycles $\\leq k$.  $E(X) \\leq \\sum\r\n{\\frac {(n)_i} {2i}} p^i \\leq {\\frac {1} {2}} (k-2) (np)^k$.\r\n$Pr[X \\geq {\\frac {n} {2}}] = {\\frac {E(X)} {\\frac {n} {2}}} \\leq\r\n(k-2) n^{k \\epsilon - 1}$.  Pick $n$ big enough so that\r\n$Pr[X \\geq {\\frac {n} {2}}] > {\\frac {1} {2}}$ and\r\n$Pr[ \\alpha \\geq {\\frac {n} {2k}}] < {\\frac {1} {2}}$.  So $\\exists G$ with\r\n$<{\\frac {n} {2}}$ short cycles and $\\alpha(G) < {\\frac {n} {2k}}$ delete up\r\nto\r\n${\\frac {n} {2}}$ points to eliminate the short cycles producing a graph\r\n$H \\subseteq G$.  $\\chi (H) \\geq {\\frac {H} {\\alpha (H)}} \\geq\r\n{\\frac {\\frac {n} {2}} {\\alpha (G)}} > k$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$\\epsilon$-regular: $(A,B)$ with $X \\subseteq A$ and $Y \\subseteq B$ such that\r\n$|X| \\geq \\epsilon |A|$ and\r\n$|Y| \\geq \\epsilon |B|$ satisfy $|d(X,Y)-d(A,B)| \\leq \\epsilon$.\r\n$\\epsilon$ regular partition: (1) $| V_0 | < \\epsilon |V|$, (2) $|V_i | = |\r\nV_1 |$,\r\nfor $i \\geq 1$, (3) all but $\\epsilon k^2$ of the pairs $(V_i , V_j )$ are\r\n$\\epsilon$ regular.\r\n\\emph{Szemeredi Regularity Lemma:} For every $\\epsilon >0$ and every $m \\geq 0$,\r\n$\\exists M$ such that every graph of order at least m admits an $\\epsilon$\r\nregular partition $\\{ V_0 , V_1 , \\ldots , V_k \\}$ with $m \\leq k \\leq M$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} There is a \\emph{giant component} in $G(n,p)$ \r\nwhen $p={\\frac {1+ \\epsilon } {n}}$.\\\\\r\n\\\\\r\n{\\bf Sunflower Lemma:} Let $T= \\{ S_1 , S_2 , \\ldots , S_k \\}$ be a system over a\r\nset $U$, such that (1) $| S_i | \\leq l$ and (2) $k> {(p-1)}^l l!$.  Then\r\n$\\exists F \\subseteq T$, $F= \\{ S_{i_1} , S_{i_2} , \\ldots ,\r\nS_{i_p} \\}$ such that $\\forall A,B \\in F,\r\nA \\cap B = F$.\r\n\\\\\r\n\\\\\r\n{\\bf Random function statistics:}\r\nTail, cycle, predecessor length: ${\\sqrt {\\frac {\\pi n} {8}}}$,\r\nTree Size: ${\\frac {n} {3}}$,\r\nNumber of components: ${\\frac {lg(n)} {2}}$,\r\nComponent Size: ${\\frac {2n} {3}}$.  \\\\\r\n\\\\\r\n{\\bf Sperner's Lemma:}  A collection $F$ of non-empty subsets of a set $X$\r\nis called an antichain\r\nif no set in $F$ is properly contained in another set of $F$.  If $|X|=n$,\r\n$|F| \\leq {n \\choose n'}$, where $n' = \\lfloor {\\frac {n+1} {2}} \\rfloor$.\r\nIf $|X|$ is even there are exactly 2 maximal antichains,\r\nthe collection of $\\lfloor {\\frac {n-1} {2}} \\rfloor$ subsets of $X$ and\r\nthe collection of $\\lfloor {\\frac {n+1} {2}} \\rfloor$ subsets of $X$.\r\nIf $n$ is even, there is exactly one maximal antichain, namely, the\r\ncollection of $\\lfloor {\\frac {n} {2}} \\rfloor$ subsets of $X$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nPosets, chains (totally ordered subset) and antichains (set in which all\r\nsubsets are incomparable).\r\n\\\\\r\n\\\\\r\n{\\bf Dilworth's Theorem:} The cardinality of a maximal antichain\r\nis equal to the minimum number of disjoint chains into which a poset can be\r\npartitioned. In a chain of $mn+1$ elements there is a chain of $m+1$\r\nelements or there are $n+1$ incomparable elements.  \r\n\\\\\r\n\\\\\r\n{\\bf Symmetry group of Rubik's cube:} $|G_R|= 2^{27}3^{14}5^3 7^2 11$.\r\n\\\\\r\n\\\\\r\n{\\bf Some Relations:}\r\nIf $f(x) \\in {\\mathbb Z} \\rightarrow x \\in {\\mathbb Z}$ then\r\n$\\lfloor f(x) \\rfloor = \\lfloor f(\\lfloor x \\rfloor) \\rfloor$.\r\n$\\lfloor {\\frac {x+m} n} \\rfloor=\r\n\\lfloor {\\frac {\\lfloor x \\rfloor + m} n} \\rfloor$.\r\n$\\sum_{i=0}^{m-1} \\lceil {\\frac {n-i} m} \\rceil= n$.\r\n$ \\sum_{k=0}^{m-1} \\lfloor {\\frac {nk+x} m} \\rfloor=\r\n\\sum_{k=0}^{n-1} \\lfloor {\\frac {mk+x} n} \\rfloor$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe following are equivalent: (1) \\emph{[Axiom of choice]}  If $I \\ne \\emptyset$ and\r\n$\\forall i \\in I, A_i \\ne \\emptyset$ then $\\prod_{i \\in I} A_i \\ne \\emptyset$;\r\n(2) \\emph{[Zorn's Lemma]} If $A \\ne \\emptyset$ is partially ordered and if every chain\r\n(including infinite chains!) has an upper bound in $A$ then $A$ contains a\r\nmaximal element; (3) \\emph{[Well ordering]}  If $A \\ne \\emptyset$ has a linear order,\r\n$\\le$, then $(A, \\le)$ is has a least element.  Transfinite Induction: if\r\n$B \\subseteq A$ and $A$ is well ordered under $\\le$ and if \r\n$\\{ c \\in A: c<a \\} \\subseteq B \\rightarrow a \\in B$ then $A=B$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n\\emph{AC $\\rightarrow$ Zorn:}  Map the partial order into inclusion by\r\n${\\overline s}(x)= \\{ y: y \\leq x \\}$.  ${\\overline s}: X \\rightarrow {\\cal P}(X)$ and\r\n${\\overline s}(x) \\subseteq {\\overline s}(y)$ iff $x \\leq y$.  Let ${\\cal X}$ be the collection of\r\nall totally ordered subsets of $X$.  If ${\\cal C}$ is a totally ordered set (under inclusion) in\r\n${\\cal X}$ then $\\bigcup_{A \\in  {\\cal C}} A \\in {\\cal X}$.\r\n\\\\\r\n\\\\\r\n\\emph{Claim:} Let ${\\cal X}$ be a collection of subsets of $X$ such that (1) \r\n$Y \\subseteq X \\in {\\cal X} \\rightarrow Y \\in {\\cal X}$ and (2) if ${\\cal Y}$ is a totally ordered sets\r\nin ${\\cal X}$ then $\\bigcup {\\cal Y} \\in {\\cal X}$.  Then there is a maximal set in ${\\cal X}$.\r\n\\\\\r\n\\\\\r\nBy the axiom of choice for $X$, pick an $f: f(A) \\in A, A \\subseteq X$ and $\\forall A \\in {\\cal X}$,\r\nput $\\hat{A}= A \\cup \\{ f(A) \\}$.  Further, define $g: {\\cal X} \\rightarrow {\\cal X}$ by\r\n$g(A)= A \\cup \\{f(\\hat{A}-A) \\}$ if $\\hat{A} - A \\neq \\emptyset$ and $g(A)=A$, otherwise.  Note that\r\n$\\hat{A}-A = \\emptyset$ iff $A$ is maximal and that $g(A)$ contains at most one more element than $A$.\r\n\\\\\r\n\\\\\r\nWe say ${\\cal J} \\subseteq  {\\cal X}$ is a \\emph{tower} if (i) $\\emptyset \\in {\\cal J}$, (ii) if\r\n$A \\in {\\cal J}$ then $g(A) \\in {\\cal J}$, (iii) if ${\\cal C}$ is a totally ordered collections of sets\r\nin ${\\cal J}$ then $\\bigcup_{A \\in {\\cal C}} A \\in {\\cal J}$.\r\n\\\\\r\n\\\\\r\nThe intersection of all towers (denoted ${\\cal J}_0$) is a minimal tower.\r\n\\\\\r\n\\\\\r\nWe say $C \\in {\\cal J}_0$ is if $A \\subseteq C$ or $C \\subseteq A$ for all $A \\in {\\cal J}_0$.\r\n${\\cal J}_0$ is totally ordered iff all sets are comparable.  Now fix $C$.\r\n\\\\\r\n\\\\\r\nIf $A \\in {\\cal J}_0$, $A \\subseteq C$ and $A \\neq C$ then $g(A) \\subseteq C$ and either\r\n$g(A) \\subseteq C$ or $C \\subseteq g(A), C \\neq g(A)$ but $A \\subseteq C \\subseteq g(A)$ and\r\n$A \\neq C$ which contradicts the fact that $g(A)$ has only one more element than $A$.\r\nConsider ${\\cal U}= \\{ A: A \\subseteq C \\textnormal{ or } g(C) \\subseteq A \\}$.  We claim\r\n${\\cal A}$ is a tower.  Properties (i) and (iii) are clear.  For (ii), there are three cases:\r\nif $A \\subseteq C, A \\neq C$ then $g(A) \\subseteq C$;\r\nif $A=C$, $g(A)=g(C)$ so $g(A) \\in {\\cal U}$;\r\nif $g(C) \\subseteq A$, then $g(C) \\subseteq g(A)$ and $g(A) \\in {\\cal U}$.  Finally, since\r\n${\\cal J}_0$ is the smallest tower, ${\\cal J}_0 = {\\cal U}$.  This shows that if $C$ is comparable,\r\nso is $g(C)$.\r\n\\\\\r\n\\\\\r\nNote that $\\emptyset$ is comparable and $g$ maps comparable sets into comparable sets.  Thus comparable\r\nsets form a tower.  Thus ${\\cal J}_0$ is a totally ordered and $A= \\bigcup_{X \\in {\\cal J}_0} X \\in {\\cal J}_0$.\r\n$g(A) \\subseteq A$ and $A \\subseteq g(A)$ so $g(A)=A$ and $A$ is maximal.\r\n\\\\\r\n\\\\\r\n\\emph{Zorn $\\rightarrow$ Choice:}  Given $X$, consider $f: \\textnormal{dom}(f) \\subseteq {\\cal P}(X),\r\n\\textnormal{range}(f) \\subseteq X$ and $f(A) \\in A, \\forall A \\in \\textnormal{dom}(f)$.  Order these functions\r\nby extension.  By Zorn, there is a maximal one with $\\textnormal{dom}(f)= {\\cal P}(X) - \\{ \\emptyset \\}$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$|P(A)| > |A|$. \r\n\\begin{quote}\r\n\\emph{Proof:} $f: a \\mapsto \\{a\\}$ shows\r\n$|P(A)| \\ge |A|$. Suppose\r\n$|P(A)| = |A|$, then there is a bijection $f$ between\r\n$P(A)$ and $A$.  Let $B= \\{ a: a \\notin f(a) \\}$.  If $b \\in B$ and $b \\mapsto f(b)$\r\nthen $b \\notin B$, this is a contradiction.\r\n\\end{quote}\r\n{\\bf Schroeder-Bernstein:}  If $A,B$ are two sets and there are injections \r\n$f: A \\rightarrow B$ and\r\n$g: B \\rightarrow A$ then there is a bijection\r\n$h: A \\rightarrow B$.  \r\n\\begin{quote}\r\n\\emph{Lemma:} If there is a subset $A' \\subseteq A$ satisfying the\r\nhypothesis of the theorem with $A'=B$ then there is a bijection\r\n$h: A \\rightarrow A'$.  \r\n\\\\\r\n\\emph{The lemma implies the theorem:} Let $A'=g(f(A))$ \r\nthen by the lemma, $\\exists h: A \\rightarrow A'$ and $g^{-1} \\circ h$ is the desired\r\nbijection.  \r\n\\\\\r\n\\emph{Proof of Lemma:}  Set $X= \\bigcap_{n \\ge 0} f^{(n)} (A \\setminus A')$ and\r\ndefine $h(x)= f(x), x \\in X, h(x)=x, x \\notin X$; this is a bijection.  \r\nFirst note $f(X) \\subseteq X$.  If $x,y \\in X$ or $x,y \\notin X$ it is clear that\r\n$h(x)=h(y) \\rightarrow x=y$ and by construction, there is no $x \\in X, y \\notin X$\r\nwith $h(x)=h(y)$.  If $y \\in A'$ and $y \\in X$, then $y \\in f^{(n)}(A \\setminus A')$\r\nfor some $n$ in which case $\\exists x \\in X: h(x)=y$ otherwise \r\n$y \\notin X$ and $h(y)=y$.\r\n\\end{quote}\r\n{\\bf Arrangements:}  Arrange $n$ objects into $k$ containers. $S(a,b)$- Stirling number\r\nof second kind, $p_k(b)$ - number of $k$ partitions of $b$ things.\r\n\\begin{figure} [h]\r\n\\begin{center}\r\n\\begin{tabular} {|r|r||r|r|r|}\r\n\\hline\r\nObjects & Containers & Any & At most one & At least one \\\\\r\ndistinguishable?& distinguishable?& & per container & per container \\\\\r\n\\hline\r\nYes & Yes & $n^k$ & ${\\frac {n!} {(n-k)!}}$ & $k! S(n,k)$ \\\\\r\n\\hline\r\nNo & Yes & ${ {n+k-1} \\choose {n}}$ & ${n \\choose k}$ & ${{n-1} \\choose {k-1}}$\\\\\r\n\\hline\r\nYes & No & $\\sum_{i=1}^k S(n,i)$ & $1$ if $n \\le k$, & $S(n,k)$ \\\\\r\n& & & $0$ if $n > k$ & \\\\\r\n\\hline\r\nNo & No & $\\sum_{i=1}^k p_i(n)$ & $1$ if $n \\le k$, & $p_k(n)$\\\\\r\n& & & $0$ if $n > k$ & \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{figure}\r\n\\\\\r\nSelect $n$ elements from $r$ distinct objects, with repetition allowed: ${{n+r-1} \\choose {r}}$.\r\nCorrespondence: $\\langle s_0, s_1, \\ldots , s_n \\rangle \\rightarrow \\langle s_1+0, s_2+1, \\ldots, s_n+n-1 \\rangle$.]\r\n\\\\\r\nNumber of ways to distribute $r$ non-distinct objects into $n$ distinct cells: ${{n+r-1} \\choose {(n-1)}}$.\r\n\\\\\r\nNumber of ways to distribute $r$ distinct objects into $n$ distinct cells (more than one element in cell allowed): ${\\frac {(n+r-1)!} {(n-1)!}}$.\r\n\r\n", "meta": {"hexsha": "fce51cf68f78a05e8f5154bc74bd3d293b9bfd14", "size": 59551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/math1.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/math1.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/math1.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0120937264, "max_line_length": 150, "alphanum_fraction": 0.5507548152, "num_tokens": 26377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6743518132602556}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\n\\title{Math Advanced Topics Notes}\n\n\\newcommand{\\Z}{$\\mathbb{Z}$}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\n\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\n\\newtheorem{theorem}{Theorem}\n\n\n\n\\theoremstyle{remark}\n\\newtheorem*{remark}{Remark}\n\n\\author{Emmanuel Eppinger}\n\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\\section{Subrings}\n\\subsection{Subring Theorem}\nA non-empty subset of a ring is a subring under the same operations if and only if it is closed under multiplication and subtraction.\n\\begin{proof}\n\nForward Direction: It is obviously true in the forwards direction.\nBackwards Direction:\nSuppose R is a ring and S a non-empty subset, which is closed under multiplication and subtraction. Now we wish to show that S is a ring. Now, because S is non-empty, we choose an arbitrary element in S: s. First note that because S is closed under subtraction, $s-s=0 \\in S$. Next suppose $a \\in S$, let because 0 is an element of S and S is closed under subtraction $0-a \\in S$. Now suppose that $a,b \\in S$. It has been previously proven that $-b \\in S$. But then, $a+b=a-(-b) \\in S$ which is shows that S is closed under addition.\\\\\n\nTo show that S is a r ring, need to show addition is commutative, addition and multiplication are associative, and multiplication is distributive over addition. But all of these properties are are based operations in R which is a ring. So we know it works.\n\n\\end{proof}\n\n\\subsection{Multiplicative Identity}\nWe call an element \\textit{u} of a ring R a unity or multiplicative identity if $ua = au = a$ $\\forall a \\in R$. Note: This is not necessary to be a ring.\n\n\\subsection{Commutative Ring}\nA ring where multiplication is commutative.\n\n\\section{Integral Domains and Fields}\n\\begin{definition}\n\nLet R be a commutative ring. An element a, not zero, is a zero divisor if there exists another element b such that ab=0. Of course, b is also a zero divisor. \\\\\n\nExamples: 2,3 for $\\mathbb{Z}_6$\\\\\nnone for $\\mathbb{Z}_5$\\\\\nFor $\\mathbb{Z}x\\mathbb{Z}$: $(a,0)$ and $(0,b)$ where a,b are integers and not zero\nnon for integers\n\n\\end{definition}\n\nThis gives us a definition:\n\n\\begin{definition}\n\nA commutative ring with unity that has no zero divisor is called an \\textit{Integral Domain} or simply a domain.\n\nEx.: \\Z and \\Z sub 5 are domains as are $\\mathbb{Q}, \\mathbb{R}, \\mathbb{C}$\n\n\\end{definition}\n\nNote: 2\\Z is NOT a domain because it has no unity, even though it is commutative, but has no zero divisors.\n\n\\begin{theorem}\n\tMultiplicative Cancellation: Suppose R is an integral domain and a,b,c are elements of R, with a not zero. If ab=ac, then b = c.\\\\\n    \\begin{proof}\n\t\tSuppose that b is not equal to c. Since a is not equal to 0 and there are no zero divisors then ab is not equal to ac.\n\t\\end{proof}\n\\end{theorem}\n\n\\subsection{Units}\n\\begin{definition}\nSuppose R is a ring with unity 1. Let a be any on zero element of R. We say a is a unit if there is  an element b of R st $ab = ba = 1$. In this case, b is a multiplicative inverse of a. (of course, b is also a unit with inverse a.)\n\\end{definition}\n\nNote: unity 1 is always a unit because $1 \\cdot 1 = 1$.\\\\\n\nQuick Exercise:\\\\\nDetermine the units of:\n\\begin{itemize}\n\\item In \\Z\n1,-1\n\\item In $\\mathbb{Q}$\nAll non zero elements\n\\item In $\\mathbb{R}$\nAll non zero elements\n\\item In $\\mathbb{Z}_6$\n1 and 5.\n\\end{itemize}\n\nQuick Exercise:\\\\\nCompute units of these rings:\n\\begin{itemize}\n\\item $\\mathbb{Z}_5$: 1, 2, 3, 4\n\\item $\\mathbb{Z}_{12}$: 1, 5, 7, 11\n\\item $\\mathbb{Z}x\\mathbb{Z}$: $(1,1)$, $(1,-1)$, $(-1,-1)$, $(-1,1)$,\n\\item $\\mathbb{R}x\\mathbb{R}$: $(a,b)$ st $a,b \\ne 0$\n\\end{itemize}\n\nFact:\\\\\nMultiplicative Inverse:work in commutative rings\\\\\n$\\left(\\begin{array}{l l}\n1 & 2\\\\\n3 & 4\\\\\n\\end{array}\\right)$\n$\\cdot$\n$\\left(\\begin{array}{l l}\n1 & 0\\\\\n0 & 1\\\\\n\\end{array}\\right)$\n=\n$\\left(\\begin{array}{l l}\n1 & 2\\\\\n3 & 4\\\\\n\\end{array}\\right)$\\\\\n\nClaim: Multiplicative Inverses: if they exist, they are unique.\\\\\n\\begin{proof}\nSuppose that for every element of ring R: $a$, there exists an element of R: $b$ st $ab = u$, the unit of the ring. Suppose that there exists another element of R: $c$ such that $ac = u$. This implies that $ab = ac$. This implies that $b = c$. Therefore, b is unique.\\\\\n\\end{proof}\nNote: The inverse of a (if it exists) is unique and denoted by $a^{-1}$\n\n\\begin{definition}\nDenote set of units in ring R by $U(R)$\\\\\nex.\\\\\n$U(\\mathbb{Z}) = \\{1, -1\\}$\\\\\n$U(\\mathbb{Q}) = \\mathbb{Q}\\backslash \\{0\\}$\\\\\n$U(\\mathbb{Z}_6) = \\{1, 5\\}$\n\\end{definition}\n\nThe set $U(R)$ has nice properties:\\\\\nFirst:\\\\\nCheck $U(R)$ is closed under multiplication.\n\\begin{proof}\nSuppose $a, b \\in U(R)$. This implies that since $U(R)$ is closed under multiplication, $ab\\in U(R)$. This implies that $ab$ is a unit.\n\\end{proof}\n\\section{Fields}\n\\begin{definition}\nField: A commutative ring with unity in which every non-zero element is a unit.\n\\end{definition}\n\\begin{definition}\nField: A commutative ring in which one can always solve equations of the form $ax=b$ where $a\\neq 0$. And the solution is $x = a^{-1}b$.\n\\end{definition}\n\\begin{definition}\nIn all rings, we can add, subtract, and multiply.\\\\\nIn fields, we can divide.\n\\end{definition}\nFact: Every field is a domain.\n\\begin{theorem}\nA Field has no zero divisors.\n\\end{theorem}\n\\begin{proof}\nSuppose F is a field and $a \\in F$, $a \\neq 0$. Now suppose $ab = 0$. This implies that $aba^{-1} = b = 0(a^{-1}) = 0$ Therefore there are no zero divisors in F.\n\\end{proof}\n\n\\subsection{Finite Fields}\n\\begin{theorem}\n$\\mathbb{Z}_n$ is a field iff n is prime.\n\\end{theorem}\n\n\\begin{proof}\nForward Direction:\\\\\nSuppose n is composite. This implies that there exists $a,b \\in \\mathbb{Z}_n$ such that $ab = n$. This implies that $[a][b] = [n] = [0]$. This implies that a and b are zero divisors and therefore $\\mathbb{Z}_n$ is not a field.\\\\\nBackwards Direction:\\\\\nSuppose n is prime and let $0 < x < n$. This implies that there exists an inverse $[x]^{-1}$. That is, we must find a $y$ such that $[x][y] = [1]$. Because n is prime, we know $gcd[n,x] = 1$. By GCD identity, there exists  r,s such that $1 = rn + sx$ But then $[s][x] = [1] - [r][n] = [1]$. And so, $[s]$ is the inverse of $[x]$\n\\end{proof}\n\nNote: There is an implication of the above proof we can use it to compute multiplicative inverses in $\\mathbb{Z}_p$ where p is prime.\n\n\\begin{enumerate}\n\\item{Compute $[23]^{-1}$ in $\\mathbb{Z}_{119}$\\\\\n\n\n\tApply Euclid's algorithm to obtain:\\\\\n    $119 = 23(5) + 4$\\\\\n    $23 = 4(5) + 3$\\\\\n    $4 = 3(1) + 1$\\\\\n    $3 = 1(3) + 0$\\\\\n    $gcd(119,23) = 1$\\\\\n\t$1 = 23(-31) + 119(6)$\\\\\n\n    $1 = 0 + 23(-31)$ in $\\mathbb{Z}_{119}$\n    so $-31 = 88$ is the inverse of $23$ in $\\mathbb{Z}_{119}$\n\n}\n\\end{enumerate}\n\n\\subsection{Recipe to compute Inverse in $\\mathbb{Z}_{p}$}\n$[x]^{-1}$ in $\\mathbb{Z}_{p}$\n\\begin{enumerate}\n\\item Given $x$ and $p$ using Euclid's algorithm to show $gcd(p,x) = 1$\n\\item Work backward through resulting equation to obtain $r,s$ for linear combination.\n\\item Reduce $s$ in $\\mathbb{Z}_{p}$\n\\end{enumerate}\n\nNote: this method works as long as $gcd(p,x) = 1$ aka they are relatively prime.\\\\\n\n\\subsection{Fermat's Little Theorem}\n\\begin{theorem}\n(Alternative Approach to computing $[x]^{-1}$ in $\\mathbb{Z}_{p}$)\\\\\nIf p is prime and $0 < x < p$, then $x^{p-1} \\equiv 1$ in $\\mathbb{Z}_{p}$. Hence, in $\\mathbb{Z}_{p}$, $[x]^{-1} \\equiv  [x^{p-2}]$\n\\end{theorem}\n\nExample: in $\\mathbb{Z}_{5}$ this $th^{m}$ claims that $p[3^4] \\equiv [1]$ which implies that $[3]^{-1} \\equiv [3]^{3} \\equiv [27] \\equiv [2]$\n\n\\begin{proof}\nSuppose p is prime and $0 < x < p$. Then $[x]$ is a non-zero element of the field $\\mathbb{Z}_p$. Consider the set $S$ of non-zero multiples of $[x]$ in $\\mathbb{Z}_p$. $S = \\{ [x*1],[x*2],[x*3]...[x*(p-1)]\\}$. Because the field has no zero divisors, each element of S is non zero. Because a field satisfies multiplicative cancellation, no two of these elements are the same. Thus, the set $S$ consists of $p-1$ distinct non-zero elements and so must consist of the set $\\{ [1], [2],..[p-1]\\}$. We now multiply all elements of $S$ together as multiplying all non-zero elements of $\\mathbb{Z}_p$. $[1][2]...[p-1][x]^{p-1} = [1][2][3]...[p-1]$. By multiplicative cancellation in the domain $\\mathbb{Z}_p$ we can cancel $[1][2]...[p-1]$ from each side, so $[x]^{p-1} \\equiv 1$ (mod $p$).\n\\end{proof}\n\nCheck the key idea of FLT for x=3 and p=17 ie. check that the set S consists of 16 non-zero elements of $\\mathbb{Z}_p$.\\\\\n$\\{[3*1], [3*2], [3*3], [3*4], [3*5], [3*6], [3*7], [3*8], [3*9], [3*10], [3*11], [3*12], [3*13], [3*14], [3*15], [3*16]\\} \\equiv \\{ [3], [6], [9], [12], 15], [1], [4], [7], [10], [13], [16], [2], [5], [8], [11], [14]\\}$\n\n\n\\section{Differential Equations}\n\\subsection{Function Definition}\nCorrespondence between domain $D$ and range $R$ such that $\\exists d \\in D $ for $\\exists r \\in R$ that is unique.\\\\\n\n\\subsubsection{Note:}\n\nIf $y = ln(x)$, successive derivatives are:\n$y'=\\frac{1}{x}$, $y'=\\frac{-1}{x^2}$, $y'=\\frac{2}{x^3}$\n\nIf $z= x^3 -3xy+2y^2$, its partial derivatives with respect to $x$ and with respect to $y$ are respectively: $\\frac{\\partial z}{\\partial x} = 3x^2 - 3y$ and $\\frac{\\partial z}{\\partial y} = -3x+4y$.\n\nThe $2^{nd}$ partial derivateves are respectively: $\\frac{\\partial^2 z}{\\partial x^2} = 6x$ and $\\frac{\\partial^2 z}{\\partial y^2} = 4$\n\nBoth sets of equations in this note are both differential equations, the first is an example of ordinary differential equations: ODEs, the second is an example of partial differential equations: PDE\n\n\n\\textbf{ODE Defn: equation involving $x$, a function: $f(x)$, and one or more of its derivatives}\n\n\\subsubsection{Examples:}\n\n\\begin{enumerate}\n\\item $\\frac{dy}{dx} + y = 0$\n\\item $y' = e^x$\n\\item $\\frac{d^2 y}{d x^2} = \\frac{1}{1-x^2}$\n\\item $f'(x) = f''(x)$\n\\item $x y' = 2y$\n\\item $y'' + (3y')^3 +2x = 7$\n\\item $(y''')^2 + (y'')^4 + y' = x$\n\\item $xy'''' + 2y''+(xy')^5 = x^3$\n\\end{enumerate}\n\n\\subsubsection{Definition: Order of Differential Equation}\norder of the highest derivative involved in the equation\n\nFirst Order: $1$, $2$, $5$\n\nSecond Order: $3$, $4$, $6$\n\nThird Order: $7$\n\nFourth Order: $8$\n\n\\vspace{6pt}\n\n\\subsubsection{Example:}\n\n$y'' - y'' + y' - y = 0$\n\nSolution of Differential Equations:\\\\\n\nConsider: $x^2 - 2x - 3 = 0$, $x = 3$ is a solution\\\\\n\nNow Consider: (1) $y=f(x)=ln(x)+x$, $x > 0$ and (2) $x^2y'' + 2xy' y = ln(x) 3x + 1$\\\\\n\n(1) is a solution to (2)\\\\\n\n\\subsubsection{Note:}\n\\begin{enumerate}\n\\item We specified the values of x for which function is defined\n\\item Specified interval where Differential Equation makes sense\n\\end{enumerate}\n\n\n\\subsubsection{Definition: Explicit Solution}\nLet $y=f(x)$ be a function of x on $I: a<x<b$, we say $f(x)$ is an EXPLICIT SOLUTION or a SOLUTION of an ODE evolving $x, f(x),$ and its derivatives if it satisfies the equation for \\textbf{every} $x \\in I$.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\end{document}\n\n\n\n\n\n\n\n\n\n\n\n\\e\n", "meta": {"hexsha": "d289956a0ee098cbcbf506cb21169b6791f359c2", "size": 10991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/notes.tex", "max_stars_repo_name": "eppingere/school", "max_stars_repo_head_hexsha": "36ebdbe6bf7fbb041af5ca91bd34ba1c841a1734", "max_stars_repo_licenses": ["MIT"], "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/notes.tex", "max_issues_repo_name": "eppingere/school", "max_issues_repo_head_hexsha": "36ebdbe6bf7fbb041af5ca91bd34ba1c841a1734", "max_issues_repo_licenses": ["MIT"], "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/notes.tex", "max_forks_repo_name": "eppingere/school", "max_forks_repo_head_hexsha": "36ebdbe6bf7fbb041af5ca91bd34ba1c841a1734", "max_forks_repo_licenses": ["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.7816455696, "max_line_length": 784, "alphanum_fraction": 0.6632699481, "num_tokens": 3750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311906630568, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.67435181036326}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage{amssymb}\n\n\\begin{document}\n\n\\section{Back Propagations}\n\n\\subsection{Matrix product}\n\n\\emph{Without proof}, we note that if ${\\bf C}={\\bf A}\\cdot{\\bf B}$, we can backprop\nthe gradient of ${\\bf C}$ to ${\\bf A}$ and ${\\bf B}$ as follows:\n\\[\n\\frac{\\partial F}{\\partial {\\bf A}}\\gets\\frac{\\partial F}{\\partial {\\bf C}}\\cdot {\\bf B}^\\intercal\n\\]\n\\[\n\\frac{\\partial F}{\\partial {\\bf B}}\\gets{\\bf A}^\\intercal\\cdot\\frac{\\partial F}{\\partial {\\bf C}}\n\\]\nSimilarly, if ${\\bf Y}={\\bf X}\\cdot{\\bf W}^\\intercal$, the backprop rule is:\n\\[\n\\frac{\\partial F}{\\partial {\\bf X}}\\gets\\frac{\\partial F}{\\partial {\\bf Y}}\\cdot {\\bf W}\n\\]\n\\[\n\\frac{\\partial F}{\\partial {\\bf W}}\\gets\\left(\\frac{\\partial F}{\\partial {\\bf Y}}\\right)^\\intercal\\cdot{\\bf X}\n\\]\nWe use `$\\gets$' instead of an equal sign because matrix ${\\bf A}$ (and others)\nmay be used elsewhere, which also contributes to ${\\bf A}$'s gradient.\n\n\\subsection{Layer normalization}\n\nGiven an input vector ${\\bf x}$, we compute the normalized output ${\\bf z}$ as\nfollows (i.e. the forward pass):\n\\[\ny_k = x_k - \\frac{1}{n}\\sum_{i=1}^n x_i\n\\]\n\\[\n\\sigma^2 = \\frac{1}{n}\\sum_i y_i^2\n\\]\n\\[\nz_k = \\frac{y_k}{\\sigma}\n\\]\nThe derivatives of intermediate variables ${\\bf y}$ and $\\sigma$ are:\n\\[\n\\frac{\\partial y_i}{\\partial x_k} = \\delta_{ik}-\\frac{1}{n}\n\\]\n\\[\n\\frac{\\partial\\sigma}{\\partial y_k} = \\frac{y_k}{n\\sigma}\n\\]\nBackprop from ${\\bf z}$ to ${\\bf y}$ (we use `$=$' here because ${\\bf y}$ is a transient variable):\n\\[\n\\frac{\\partial F}{\\partial y_k}=\\sum_i\\frac{\\partial F}{\\partial z_i}\\frac{\\partial z_i}{\\partial y_k}\n=\\frac{1}{\\sigma}\\left(\\frac{\\partial F}{\\partial z_k}-\\frac{z_k}{n}\\sum_iz_i\\frac{\\partial F}{\\partial z_i}\\right)\n\\]\nand from ${\\bf y}$ to the input ${\\bf x}$:\n\\begin{eqnarray*}\n\\frac{\\partial F}{\\partial x_k}&\\gets&\\frac{\\partial F}{\\partial y_k} - \\frac{1}{n}\\sum_i\\frac{\\partial F}{\\partial y_i}\\\\\n&=&\\frac{1}{\\sigma}\\left(\\frac{\\partial F}{\\partial z_k}-\\frac{z_k}{n}\\sum_iz_i\\frac{\\partial F}{\\partial z_i}\\right)\n-\\frac{1}{n\\sigma}\\sum_i\\left(\\frac{\\partial F}{\\partial z_i}-\\frac{z_i}{n}\\sum_jz_j\\frac{\\partial F}{\\partial z_j}\\right)\n\\end{eqnarray*}\nAs $\\sum_i z_i=0$, we have backprop from ${\\bf z}$ to ${\\bf x}$:\n\\[\n\\frac{\\partial F}{\\partial x_k}\n\\gets\\frac{1}{\\sigma}\\left(\\frac{\\partial F}{\\partial z_k}-\\frac{1}{n}\\sum_i\\frac{\\partial F}{\\partial z_i}-\\frac{z_k}{n}\\sum_iz_i\\frac{\\partial F}{\\partial z_i}\\right)\n\\]\nThe two sums can be pre-calculated, so the total time complexity is linear in\n$n$, the dimension of ${\\bf x}$.\n\n\\end{document}\n", "meta": {"hexsha": "2e3deb1672d1d40c4e70bf297e64226a12211ed1", "size": 2558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/11math.tex", "max_stars_repo_name": "robinkumarsharma03/Kann", "max_stars_repo_head_hexsha": "94a68cd18c0cfb4c40b80f85ab3d579a8b9063a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 637, "max_stars_repo_stars_event_min_datetime": "2017-03-04T05:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T06:07:55.000Z", "max_issues_repo_path": "doc/11math.tex", "max_issues_repo_name": "robinkumarsharma03/Kann", "max_issues_repo_head_hexsha": "94a68cd18c0cfb4c40b80f85ab3d579a8b9063a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 42, "max_issues_repo_issues_event_min_datetime": "2017-03-06T01:33:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-03T20:38:51.000Z", "max_forks_repo_path": "doc/11math.tex", "max_forks_repo_name": "robinkumarsharma03/Kann", "max_forks_repo_head_hexsha": "94a68cd18c0cfb4c40b80f85ab3d579a8b9063a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 133, "max_forks_repo_forks_event_min_datetime": "2017-03-06T01:24:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T10:33:27.000Z", "avg_line_length": 37.0724637681, "max_line_length": 168, "alphanum_fraction": 0.6481626271, "num_tokens": 930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6743501952708706}}
{"text": " \\section{Mappings} \\label{sec:mappings}\nAs previously discussed, objects simulated in \\sofa, like the liver in Figure \\ref{fig:liver-multimodel}, typically rely on several models: one for the internal model, one for collision, and one for the visual rendering. \nTo enforce consistency, one of them, typically the internal model, acting as the master, imposes its displacements to slaves (typically the visual model and the collision model), using \\textit{mappings}.\nMapped model can be masters of other models in turn, creating a hierarchy whith the independent DOFs at the root.\nFigure \\ref{fig:hierarchy} illustrates the hierarchies of two objects. The visual models, in additional branches, are omitted for clarity. When contact models collide, additional geometry is necessary to model the contacting points.\nThis additional geometry is represented in an additional level connected to the models, as depicted in the figure. \n\n\nThe positions $\\vec x_c$ of a child model are computed by the mapping based on the positions $\\vec x_p$ of the master using a function $\\JNL$. \n\\begin{equation} %\\label{eq:mapV}\n\\vec x_c =\\JNL(\\vec x_p)\n\\end{equation}\n% In the particular case of a FEM model, this mapping function can rely on the underlying interpolation of the model. \n% \n% \n% These mapping are implemented in a very generic way and allows the control of any kind of slave model $\\vec x_1 = \\JNL_1(\\vec x_0)$ given the position of a master model $\\vec x_0$ . \nThe velocities can be mapped in a similar way:\n\\begin{equation}\n\\vec v_c = \\mat J \\vec v_p\n\\end{equation}\nThe Jacobian matrix $\\mat J = \\frac{\\partial \\vec x_c}{\\partial \\vec x_p}$ encodes the linear relation between the parent and child velocities.\nIt also holds on accelerations, with an additional offset due to velocities when the position mapping $\\JNL$ is nonlinear.\nIn linear mappings, operators $\\JNL$ and $\\J$ are the same, otherwise $\\JNL$ is nonlinear with respect to $x_p$ and it can not be written as a matrix.\nFor surfaces embedded in deformable cells, matrix $\\J$~contains the barycentric coordinates (it corresponds to linear interpolation in FEM).\nFor surfaces attached to rigid bodies, each row of the matrix encodes the usual relation $v = \\dot o + \\omega \\times (x-o)$ for each vertex. \n\nThe positions and the velocities are propagated top-down in the hierarchy. \nConversely, the forces are propagated bottom-up, up to the independent DOFs, where Newton's law $\\vec f=\\M\\vec a$ is applied. \nGiven forces $\\vec f_c$ applied to a child model, the mapping computes and accumulates the equivalent forces $\\vec f_p$ applied to its parent. \nSince equivalent forces must have the same power, the following relation holds:\n$$\n\\vec v_{p}^T \\vec f_p = \\vec v_c^T \\vec f_c\n$$\nThe kinematic relation $\\vec v_{c} = \\J \\vec v_{p}$ allows us to rewrite the previous equation as\n$$\n\\vec v_{p}^T \\vec f_{p} = \\vec v_{p}^T \\J^T \\vec f_c\n$$\nSince this relation holds for all velocities $\\vec v_p$, the principle of virtual work allows us to simplify the previous equation to obtain:\n\\begin{equation} \\label{eq:mapF}\n\\vec f_{p} = \\J^T \\vec f_c\n\\end{equation}\nWhen a model has several children, each child accumulates its contribution to the parent forces using its mapping. \nThis hierarchical kinematic model allows us to compute displacements and to apply forces at all levels.\n%\n\\begin{figure}\n \\centering\n \\includegraphics[width=0.9\\linewidth]{MappingScheme.png}\n \\caption{Mappings from the DOFs to the contact point. Right (top to bottom): The Mechanical model of the liver is based on Finite Element model. A triangular mesh is mapped for collision detection with the surface. The two contact points found by the collision detection (with the grasper) are mapped on the collision model. \n Left (bottom to top): the contact points are also mapped on the collision model of the grasper. This collision model is a simplification of the grasper shape and is mapped on the rigid body frames. The motion of these frame is mapped on the state of the joints which are the independent DOFs of the grasper.\n}\n \\label{fig:hierarchy}\n\\end{figure}\n%\nSo far, $22$ variants of mappings have been implemented to attach models to rigid objects and deformable primitives such as tetrahedra, hexahedral grids, splines, blended frames, flexible beams and scalar fields.\nMappings are also be used to connect generalized coordinates, such as joint angles, to world-space geometry, as in the grasper of Figure~\\ref{fig:hierarchy}.\n\n\n%% attacher de la g�om�trie\n%\n%\n%They are not independent variables, since the positions and velocities are bound to the independent DOF.\n%We say that a child geometrical model $1$ is \\textit{mapped} from its parent model $0$,\n% using a kinematic operator which we call \\textit{mapping}. It implements the kinematic relations:\n%\\begin{eqnarray*} %\\label{eq:mapV}\n%\\vec x_1 &=&\\JNL_1(\\vec x_0)\\\\ \n%\\vec v_1 &=& \\mat J_1 \\vec v_0\n%\\end{eqnarray*}\n%Mappings allow to attach polygonal shapes (like the tool shape in Figure~\\ref{fig:hierarchy}, with point DOFs) to rigid bodies (with frame DOFs) using local coordinates, or to embed the shapes in deformable cells using barycentric coordinates (like the deformable liver in Figure~\\ref{fig:hierarchy}), among other possibilities.\n%Matrix $\\mat J_1 = \\frac{\\partial \\vec x_1}{\\partial \\vec x_0}$ encodes the linear relation between the parent and child velocities.\n%It also holds on accelerations, with an additional offset due to velocities when the position mapping \\JNL is nonlinear.\n%In linear mappings, operators \\JNL and \\J are the same, otherwise \\JNL is nonlinear with respect to $x_0$ and it can not be written as a matrix.\n%For surfaces embedded in deformable cells, matrix \\J~contains the barycentric coordinates. \n%For surfaces attached to rigid bodies, each row of the matrix encodes the usual relation $v = \\dot o + \\omega \\times (x-o)$ for each vertex. \n%% Similarly, skins around articulated bodies involve, at each vertex, the weighted  contributions of the rigid bodies. \n\n\n%% g�om�trie suppl�mentaire d�e aux contacts\n%When shapes collide, additional geometry is necessary to model the contact.\n%For instance, when an edge intersects or closely approaches another one, a contact force is typically applied to the intersection point or to the pair of points.\n%The points are defined using their barycentric coordinates with respect to the edge vertices. \n%% Other relations can be used, depending on the kind of geometrical primitives in contact.\n%This additional geometry can be represented in another geometrical layer connected to the shape by a mapping, as illustrated in the bottom of Figure~\\ref{fig:hierarchy}.\n%% This layer is also connected to the shape using mappings:\n%% \\begin{eqnarray*} %\\label{eq:mapV}\n%% x_2 &=&\\JNL_2(x_1)\\\\ \n%% v_2 &=&J_2 v_1 \n%% \\end{eqnarray*}\n%\n%We generalize this approach to tree-like hierarchies of geometries, with the independent DOFs at the root. \n%For instance, the independent DOFs may have two children, one for collision using a coarse mesh, and the other for rendering using a finer mesh.\n%The hierarchy have more levels, for instance, to attach collision spheres to a mesh embedded in a deformable grid. \n%The synchronization between these models is automatically guaranteed by their attachment to their common ancestor, using graph visitors as explained in Section~\\ref{sec:visitors}.\n%Positions and velocities are propagated top-down in the hierarchy. Conversely, the forces are propagated bottom-up, up to the independent DOFs, where Newton's law $f=ma$ is applied. \n%Given forces $f_c$ applied to a child model, the mapping computes and accumulates the equivalent forces $\\vec f_p$ applied to its parent. \n%Since equivalent forces must have the same power, the following relation holds:\n\n\n% In implicit simulation methods, one needs to consider force changes $\\vec{df}$ corresponding to small displacements $\\vec{dx}$ of the independent DOF.\n% This involves the forces applied to the independent DOF, but also the forces are applied to mapped DOFs.\n% Let $0$ denote the independent DOF.%, and $n$ a level mapped through $n$ mappings indexed from $0,1$ to $n-1,n$.\n% At each hierarchy node $i$, let $\\mat K_{ii}$ be the stiffness matrix corresponding to the forces applied to the local DOF.\n% The local displacement is :\n% \\begin{equation} \\label{eq:displacementsTopDown}\n%  \\vec{dx}_{i} = \\prod_{j=1}^{i}\\mat J_{j,j-1} \\vec{dx}_{0}\n% \\end{equation}\n% where $\\prod_{j=1}^{i}\\mat J_{j,j-1} = \\mat J_{i,i-1}...\\mat J_{1,0}$ is the product of the matrices of the mappings in the path from the independent DOF to node $i$.\n% The matrix-vector product can be efficiently computed during one top-down traversal of the hierarchy, with one matrix-vector product at each level, without any matrix-matrix product.\n% Conversely, the resulting force change on the independent DOFs is:\n% \\begin{equation} \\label{eq:forcesBottomUp}\n%  \\vec{df}_{0} = \\left( \\prod_{j=1}^{i}\\mat J_{j,j-1} \\right)^T \\vec{df}_{i}\n% \\end{equation}\n% where $\\left( \\prod_{j=1}^{i}\\mat J_{j,j-1} \\right)^T = \\mat J_{1,0}^T...\\mat J_{i,i-1}^T$ is the product of the transposed matrices of the mappings in the path from node $i$ to the independent DOF.\n% This matrix-vector product can be efficiently computed using matrix-vector products during one bottom-up traversal of the hierarchy.\n\n%Figure~\\ref{fig:liver-mechanical-spheres} shows a sphere-based collision model attached to the mechanical model of Figure~\\ref{fig:liver-mechanical}. \n%The position vector of the collision model is the set of 3d coordinates of the sphere centers, defined by their barycentric coordinates stored in the BarycentricMapping.\n%\\begin{figure}\n% \\centering\n% \\includegraphics[width=0.4\\linewidth]{liver-spheres-superimposed.jpg}\n% \\includegraphics[width=0.56\\linewidth]{liver-spheres.pdf}   % generated from ps using: dvipdf -dEPSCrop\n% \\caption{Left: mechanical (in blue) and collision (in yellow) models of a liver. Right: the corresponding scene graph. The plain arrows denote hierarchy, while the stippled arrows represent connections.}\n% \\label{fig:liver-mechanical-spheres}\n%\\end{figure}\n\n\n\n\n", "meta": {"hexsha": "b2e1c4054abbd12acb2c2b77a35109fedc910935", "size": 10132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/multimodel/mappingsIntro_body.tex", "max_stars_repo_name": "sofa-framework/issofa", "max_stars_repo_head_hexsha": "94855f488465bc3ed41223cbde987581dfca5389", "max_stars_repo_licenses": ["OML"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/multimodel/mappingsIntro_body.tex", "max_issues_repo_name": "sofa-framework/issofa", "max_issues_repo_head_hexsha": "94855f488465bc3ed41223cbde987581dfca5389", "max_issues_repo_licenses": ["OML"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/multimodel/mappingsIntro_body.tex", "max_forks_repo_name": "sofa-framework/issofa", "max_forks_repo_head_hexsha": "94855f488465bc3ed41223cbde987581dfca5389", "max_forks_repo_licenses": ["OML"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.15625, "max_line_length": 329, "alphanum_fraction": 0.7662850375, "num_tokens": 2579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807406, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6743501862103842}}
{"text": "\\chapter{Eigenvalues, eigenvectors, and diagonalization}\n\\label{cha:eigenvalues}\n\nIn this chapter, we introduce the theory of eigenvalues and\neigenvectors, and the technique of diagonalization. In the same way\nthat Gaussian elimination is a fundamental tool that permits us to\nsolve many different kinds of problems, diagonalization is also one of\nthe fundamentals tool of linear algebra. It has a great number of\napplications in every field of mathematics, science, and engineering.\n", "meta": {"hexsha": "92affe0a5a31366da7a4f63b81dc373da5c52c38", "size": 484, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues.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.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.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 48.4, "max_line_length": 70, "alphanum_fraction": 0.8223140496, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6743501770664407}}
{"text": "\\section{Rotation}\\label{Sec:Rotation}\nTo handle rotation in \\maestro\\ we move to the co-rotating reference frame.  Time\nderivatives of a vector in the inertial frame are related to those in the \nco-rotating frame by\n\\begin{equation}\\label{eq:derivative relations}\n  \\left(\\frac{D}{Dt}\\right)_\\text{i} = \n  \\left[\\left(\\frac{D}{Dt}\\right)_\\text{rot} + \\Omegab\\times\\ \\right],\n\\end{equation}\nwhere i(rot) refers to the inertial(co-rotating) frame and $\\Omegab$ is\nthe angular velocity vector.  Using (\\ref{eq:derivative relations}) and \nassuming $\\Omegab$ is constant, we have\n\\begin{equation}\\label{eq:rotational velocity relation}\n  \\frac{Dv_\\text{i}}{Dt} = \\frac{Dv_\\text{rot}}{Dt} + \n  2\\Omegab \\times \\mathbf{v_\\text{rot}} +\n  \\Omegab\\times\\left(\\Omegab\\times r_\\text{rot}\\right).\n\\end{equation}\nPlugging this into the momentum equation and making use of the continuity \nequation we have a momentum equation in the co-rotating frame:\n\\begin{equation}\\label{eq:momentum equation with rotation}\n  \\frac{\\partial(\\rho\\mathbf{U})}{\\partial t} + \n  \\nabla\\cdot\\left(\\mathbf{U}(\\rho\\mathbf{U}) + p \\right) = \n  \\underbrace{-2\\rho\\Omegab\\times\\mathbf{U}}_{\\text{Coriolis}} -\n  \\underbrace{\\rho\\Omegab\\times\\left(\\Omegab\\times\n    \\rb\\right)}_{\\text{Centrifugal}} - \n  \\rho \\mathbf{g}.\n\\end{equation}\nThe Coriolis and Centrifugal terms are force terms that will be added to \nright hand side of the equations in {\\tt mk\\_vel\\_force}.  Note that the \nCentrifugal term can be rewritten as a gradient of a potential and absorbed\ninto either the pressure or gravitational term to create an effective pressure\nor effective gravitational potential.  Furthermore, because it can be written\nas a gradient, this term would drop out completely in the projection if we were\ndoing incompressible flow.\\MarginPar{Is this how John stated it?}\nIn what follows we will include the Centrifugal term explicitly.\n\n\\subsection{Using Spherical Geometry}\\label{Sec:Using Spherical Geometry}\nIn spherical geometry implementing rotation is straightforward as we don't have\nto worry about special boundary conditions.  We assume a geometry as shown in\nFigure \\ref{Fig:rotation in spherical} where the primed coordinate system is \nthe simulation domain coordinate system, the unprimed system is the primed \nsystem translated by the vector $\\rb_\\text{c}$ and is added here for\nclarity.  The  $\\rb_\\text{c}$ vector is given by {\\tt center} in the \n{\\tt geometry} module.  In spherical, the only runtime parameter of importance\nis {\\tt rotational\\_frequency} in units of Hz.  This specifies the angular \nvelocity vector which is assumed to be along the {\\bf k} direction:\n\\[\n\\Omegab \\equiv \\Omega \\text{\\bf k} = 2\\pi *\n\\left(\\text{\\tt rotational\\_frequency}\\right)\\text{\\bf k}.\n\\]\nThe direction of $\\rb$ is given as the {\\tt normal} vector which is \npassed into {\\tt mk\\_vel\\_force}; in particular\n\\[\n\\cos\\theta \\equiv \\frac{\\rb\\cdot\\text{\\bf k}}{r} = \n\\text{\\bf normal}\\cdot\\text{\\bf k} = \\text{\\tt normal}(3).\n\\]\nThe magnitude of $\\rb$ is calculated based on the current zone's location with\nrespect to the {\\tt center}.\nUsing this notation we can write the Centrifugal term as\n\\begin{align*}\n\\Omegab\\times\\left(\\Omegab\\times\\rb\\right) &=\n\\left(\\Omegab\\cdot\\rb\\right)\\Omegab - \\left(\\Omegab\\cdot\\Omegab\\right)\\rb\\\\\n&= \\Omega^2 r *\\left[\\text{\\tt normal}(3)\\right]\\text{\\bf k} -\n\\Omega^2 r *\\text{\\bf normal} = \\left(\n\\begin{array}{c}\n\\Omega^2r*\\left[\\text{\\tt normal}(1)\\right]\\\\\n\\Omega^2r*\\left[\\text{\\tt normal}(2)\\right]\\\\\n0 \\end{array}\\right).\n\\end{align*}\nThe Coriolis term is a straightforward cross-product:\n\\begin{align*}\n\\Omegab \\times \\Ub &= \\left|\n\\begin{array}{ccc}\n  \\text{\\bf{i}}&\\text{\\bf{j}}&\\text{\\bf{k}}\\\\\n  0 & 0 & \\Omega\\\\\n  u & v & w\n\\end{array}\\right|\\\\\n&= \\left(\n\\begin{array}{c}\n-\\Omega v\\\\ \\Omega u \\\\ 0\n\\end{array}\n\\right).\n\\end{align*}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}[tpb]\n\\hspace{-0.25in}\n\\centering\n\\includegraphics[width=4.5in]{\\rotfigpath/rotation_spherical}\n\\begin{minipage}[h]{2.0in}\n\\vspace{-4in}\n\\caption[Rotation geometry]\n{Geometry of rotation when {\\tt spherical\\_in} $=1$.  We assume the \nstar to be rotating about the $z$ axis with rotational frequency $\\Omega$.}\n\\end{minipage}\n\\label{Fig:rotation in spherical}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Using Plane-Parallel Geometry}\\label{Sec:Using Plane-Parallel Geometry}\n", "meta": {"hexsha": "daa2f4e728a6e0f4e005442d1f029bd39a633b4c", "size": 4371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/rotation/rotation.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/rotation/rotation.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/rotation/rotation.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": 43.71, "max_line_length": 83, "alphanum_fraction": 0.7176847403, "num_tokens": 1335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6743501732072207}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Dissociate}\nThe operation $dissociate$ will remove some $k \\mapsto v$ from $KV$ given $k \\in KV$\n\\begin{schema}{Dissociate[KV, K]}\n  m?, m! : KV \\\\\n  k? : K \\\\\n  dissociate~\\_ : KV \\cross K \\surj KV\n  \\where\n  m! = dissociate(m?, k?) @ m! = m? \\ndres ~k? \\implies \\\\\n  \\t1 (\\dom ~m! = \\dom ~(~m? \\setminus ~k?)) ~\\land \\\\\n  \\t1 (~m? \\setminus ~m! = k? \\iff k? \\in m?) ~\\land \\\\\n  \\t1 (~m? \\setminus ~m! = \\emptyset \\iff k? \\not \\in m? \\implies m? = m!) ~\\land \\\\\n  \\t1 ((k?, m?_{k?}) \\not \\in m!)\n\\end{schema}\nsuch that every mapping in $m?$ is also in $m!$ except for $k? \\mapsto m?_{k?}$.\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  dissociate(M, abc) = \\ldata def \\mapsto xyz \\mapsto 456 \\rdata \\\\\n  dissociate(M, def) = \\ldata abc \\mapsto 123 \\rdata \\\\\n  dissociate(M, xyz) = M & $xyz \\not \\in M$\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "907d3dc4dd6f5320f857303d9bec1bc29a40553f", "size": 1116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/kv/dissociate.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/dissociate.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/dissociate.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": 42.9230769231, "max_line_length": 105, "alphanum_fraction": 0.5672043011, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6743501725361979}}
{"text": "\\chapter{Summary of Babu, Krishnan and Paleri}\n\\label{chap:chapter5}\n\nOne of the problems with other former approaches to Herbrand \nequivalence is that most of the alogrithms were based on fix point \ncomputations. But the classical definition of Herbrand equivalence is \nnot a fix point based definition making it difficult to prove their \nprecision or completeness. Babu, Krishnan and Paleri \\cite{Babu} gave \na new lattice theoretic formulation of Herbrand equivalences and \nproved its equivalence to the classical version.\n\nThe paper defines a congruence relation on the set of all possible \nexpressions and shows that the set of all congruences for a complete \nlattice. Then for a given dataflow framework with $n$ program points, \na continuous composite transfer function is defined over the n-fold \nproduct of the above lattice such that the maximum fix point of the \nfunction yields the set of Herbrand equivalence classes at various \nprogram points. Finally, equivalence of this approach to the \nclassical meet over all path definition of Herbrand Equivalence is \nestablished.\n\nBelow is a brief summary of the developments in the paper, for more \ndetailed approach and proofs and for equivalence to MOP  \ncharacterization refer to \\cite{Babu}.\n\n\\section{Program Expressions}\n\\label{sec:ProgramExpressions}\n\nLet $\\mathcal C$ and $\\mathcal X$ be the set of constants and variables \noccurring in the program respectively. The program expressions (terms) \ncan be described as \n$$t\\; ::=\\; c\\; |\\; x\\; |\\; t_1 + t_2$$\nwhere $c \\in \\mathcal C$ and $x \\in \\mathcal X$.\n\n\\section{Congruence Relation}\n\\label{CongruenceRelation}\nLet $\\mathcal T$ be the set of all program terms. A partition $\\mathcal P$ of terms \nin $\\mathcal T$ is said to be a congruence (of terms) if \n\\begin{itemize}\n    \\item For $t$, $t'$, $s$, $s'$ $\\in$ $\\mathcal T$, $t' \\cong t$ and $s' \\cong s$ iff $t' + s' \\cong t + s$. \n    \\item For $c \\in \\mathcal C$, $t \\in \\mathcal T$, if $t \\cong c$ then either $t = c$ or $t \\in \\mathcal X$.\n\\end{itemize}\nLet $\\mathcal G(\\mathcal T)$ be the set of all congruences over $\\mathcal T$. \nWe define an order, $\\mathcal P_1 \\preceq \\mathcal P_2$ for \n$\\mathcal P_1, \\mathcal P_2 \\in \\mathcal G(\\mathcal T)$, if \n$\\forall \\mathcal A_1 \\in \\mathcal P_1, \\ \\exists \\mathcal A_2 \\in \\mathcal P_2$ \nsuch that $\\mathcal A_1 \\subseteq \\mathcal A_2$. \\\\\nWe define binary \\textbf{confluence operation} on $\\mathcal G(\\mathcal T)$ as \n$$\\mathcal P_1 \\land \\mathcal P_2\\; =\\; \\{\\mathcal A_i \\cap \\mathcal B_j\\: |\\: \\mathcal A_i \\in \\mathcal P_1 \\text{ and } \\mathcal B_j \\in \\mathcal P_2\\}$$\nNow, we extend $\\mathcal G(\\mathcal T)$ to $\\overline{\\mathcal G(\\mathcal T)}$ \nby introducing abstract congruence $\\top$ satisfying \n$\\mathcal P \\land \\top = \\top, \\forall \\mathcal P \\in \\overline{\\mathcal G(\\mathcal T)}$.\nAlso, we denote the congruence in which every element is in a separate class as \n$\\bot$. \\\\ With these definitions, \n$(\\overline{\\mathcal G(\\mathcal T)}, \\preceq, \\bot, \\top)$ \nforms a complete lattice, with $\\land$ as its \\textbf{meet operator}.\n\n\\section{Transfer function}\n\\label{sec:TransferFunction}\nAn assignment $y := \\beta$ transforms a congruence $\\mathcal P$ to another \ncongruence $\\mathcal P'$. This can be described in the form of \\textbf{transfer function} \n$f_{y = \\beta}:\\mathcal G(\\mathcal T) \\to \\mathcal G(\\mathcal T)$, given by\n\\begin{itemize}\n    \\item $\\mathcal B_i = \\{t \\in \\mathcal T\\ |\\ t[y \\leftarrow \\beta] \\in \\mathcal A_i\\}, \\text{ for each } \\mathcal A_i \\in \\mathcal P$\n    \\item $f_{y = \\beta}(\\mathcal P) = \\{\\mathcal B_i\\ | \\ \\mathcal B_i \\neq \\phi\\}$\n\\end{itemize}\nWe extend this definition to form extended transfer function, \n$\\overline{f}_{y=\\beta} : \\overline{\\mathcal G(\\mathcal T)} \\to \\overline{\\mathcal G(\\mathcal T)}$ \nby defining $\\overline{f}_{y=\\beta}(\\top)\\ =\\ \\top$, otherwise \n$\\overline{f}_{y=\\beta}(\\mathcal P) = f_{y=\\beta}(\\mathcal P)$.\nThe extended transfer function is \\textbf{distributive}, \\textbf{monotonic} and \n\\textbf{continuous}.\n\n\\section{Non deterministic assignment}\n\\label{sec:NonDeterministicAssignment}\nAn assignment $y := *$ also transforms a congruence $\\mathcal P$ to another \ncongruence $\\mathcal P'$. This can be described in the form of \\textbf{transfer function} \n$f_{y = *}:\\mathcal G(\\mathcal T) \\to \\mathcal G(\\mathcal T)$, given by\n$\\forall t, t' \\in \\mathcal T,\\ t \\cong_{f(\\mathcal P)} t'$, (here \n$f(\\mathcal P) = f_{y = *}(\\mathcal P)$ for simplicity) iff\n\\begin{itemize}\n    \\item $t \\cong_{\\mathcal P} t'$\n    \\item $\\forall \\beta \\in (\\mathcal T \\setminus \\mathcal T(y)),\\ t[y \\leftarrow \\beta] \\cong_{\\mathcal P} t'[y \\leftarrow \\beta]$\n\\end{itemize}\nAs before we extend this transfer function to \n$\\overline{f}_{y=*} : \\overline{\\mathcal G(\\mathcal T)} \\to \\overline{\\mathcal G(\\mathcal T)}$ \nby defining $\\overline{f}_{y=*}(\\top)\\ =\\ \\top$, otherwise \n$\\overline{f}_{y=*}(\\mathcal P) = f_{y=*}(\\mathcal P)$. The function \n$\\overline{f}_{y=*}$ is also \\textbf{continuous}.\n\n\\section{Dataflow analysis Framework}\n\\label{sec:DataflowAnalysisFramework}\nA dataflow framework over $\\mathcal T$ is $\\mathcal D = (G, \\mathcal F)$ where \n$G(V, E)$ is the control flow graph associated with the program and \n$\\mathcal F = \\{h_k : k \\in V$ is a \\textbf{transfer program point}$\\}$ \nis \\textbf{a collection of transfer functions}.\n\n\\section{Herbrand Congruence Function}\n\\label{sec:HerbrandCongruenceFunction}\nThe Herbrand Congruence function \n$\\mathcal H_{\\mathcal D} : V(G) \\to \\overline{\\mathcal G(\\mathcal T)}$ \ngives the Herbrand Congruence associated with each program point and \nis defined to be \\textbf{the maximum fix point} of the \\textbf{continuous\ncomposite transfer function} \n$f_{\\mathcal D} : \\overline{\\mathcal G(\\mathcal T)}^n \\to \\overline{\\mathcal G(\\mathcal T)}^n$, \nwhere $\\overline{\\mathcal G(\\mathcal T)}^n$ is the product lattice, \n$f_{\\mathcal D}$ is a function satisfying $\\pi_k \\circ f_{\\mathcal D} = f_k$. Here $\\pi_k$ is the projection map\nand $f_k : \\overline{\\mathcal G(\\mathcal T)}^n \\to \\overline{\\mathcal G(\\mathcal T)}$ \nis defined as follows \n\\begin{itemize}\n    \\item   If k = 1, the entry point of the program $f_k = \\bot$.\n    \\item   If k is a function point with $Pred(k) = \\{j\\}, \\text{ then } f_k = h_k \\circ \\pi_j$ where \n    $h_k$ is the extended transfer function corresponding to function point k.\n    \\item   If k is a confluence point with \n    $Pred(k) = \\{i, j\\}, \\text{ then } f_k = \\pi_{i, j}, \\text{ where } \\pi_{i, j}:\\overline{\\mathcal G(\\mathcal T)}^n \\to \\overline{\\mathcal G(\\mathcal T)}$ \n    is given by $\\pi_{i,j}(P_1,\\ \\dots,\\ P_n) = P_i \\land P_j$.\n\\end{itemize}.", "meta": {"hexsha": "10fb04bc447d019107b3cac1a11da4a5810bbb0b", "size": 6626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Rep_Mid_8/chapter5.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/chapter5.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/chapter5.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": 56.6324786325, "max_line_length": 158, "alphanum_fraction": 0.7019317839, "num_tokens": 2133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6742936319033819}}
{"text": "\\chapterimage{head2.png} % Chapter heading image\n\\chapter{Langevin Dynamics}\n\\section{Basic Equations of Physical Space}\n\\begin{center}\n        \\includegraphics[scale=0.8]{ch1/protein_length_scale.pdf} \n\\end{center}\n\\begin{definition}[Langevin Equation in Physical Space]\n\\begin{align*}\n        d \\bar{x} &= \\frac{\\bar{D}}{k_B T} \\bar{F}(\\bar{x}) d\\bar{t} + \\sqrt{2\\bar{D}}d{W}_{\\bar{t}}\n\\end{align*}\nThe Wiener process\n\\begin{align*}\n        \\langle d{W}_{\\bar{t}} \\rangle  &=0 \\\\\n        \\langle d{W}_{\\bar{t}} d{W}_{\\bar{t'}}\\rangle &=\\delta (\\bar{t}-\\bar{t'}) d\\bar{t}.\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[MD units]\n\\begin{center}\n\\begin{tabular}{lccc}\n\\toprule\nVariable & Symbol & This work &  SI units \\\\\n\\midrule\nLength                &  $\\bar{x}$ &  1 Å               &   $1\\times 10^{-10}$ m       \\\\\nForce                 &  $\\bar{F}$ &  1 kcal/(mol Å)    &   $6.95 \\times 10^{-1}$ N    \\\\       \nEnergy                &  $\\bar{V}$ &  1 kcal/mol        &   4186 J/mol                 \\\\\nTemperature           &  $T$       &  1 K               &   1 K                        \\\\\nThermal Energy        &  $k_B T$   &  0.593 kcal/mol (T=298K)  &   2482 J/mol          \\\\\nTime                  &  $\\bar{t}$ &  1 ps              &   $1\\times 10^{-12}$ s       \\\\\nMass                  &  $\\bar{m}$ &  1 Da              &   $1.661 \\times 10^{-27}$ kg \\\\\nDiffusion coefficient &  $\\bar{D}$ &  1 $\\text{\\AA}^2/{\\rm ps}$ &  $1\\times 10^{-8}$ $\\text{m}^2$/s \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{definition}\n\n\\begin{definition}[Water Diffusion coefficient and Stokes-Einstein relation]\n\\begin{align*}\n        \\bar{D} = \\frac{k_B T}{6 \\pi \\eta a}\n\\end{align*}\nThe energy term in numerator, (T=298K)\n\\begin{align*}\n        k_B T = 4.11 \\times 10^{-21} ~\\mathrm{J} = 4.11 \\times 10^{-21}~\\mathrm{\\frac{kg \\cdot m^2 }{s^2}} \n\\end{align*} \nViscosity $\\eta$: solvent is Water\n\\begin{align*}\n        \\eta = 9 \\times 10^{-4}~\\mathrm{Pa \\cdot s} = 9 \\times 10^{-4} ~\\mathrm{\\frac{kg}{m \\cdot s}}\n\\end{align*}\nThe radius of Brownian particle: $a$\n\\begin{align*}\n        a = 1 \\text{\\AA}\n\\end{align*}\nTherefore, the diffusion coefficient\n\\begin{align*}\n        \\bar{D} = \\frac{4.11 \\times 10^{-21}}{6 \\pi \\times 9 \\times 10^{-4} \\times 1 \\times 10^{-10} }~\\mathrm{\\frac{m^2}{s}} = 2.423 \\times 10^{-9} ~\\mathrm{\\frac{m^2}{s}} = 0.243 ~\\mathrm{\\frac{\\text{\\AA}^2}{\\rm ps}}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Diffusion coefficient and the radius of Brownian partical]\n\\begin{align*}\n        \\bar{D} = \\frac{\\rm{constant}}{a}\n\\end{align*}\nso \n\\begin{align*}\n        \\frac{\\bar{D}}{\\bar{D'}} &= \\frac{a'}{a} \\\\\n        \\frac{0.243}{\\bar{D'}} &= \\frac{a'}{1}\n\\end{align*}\nTherefore, given a diffusion coefficient $\\bar{D'}$\n\\begin{align*}\n        a' = \\frac{0.243}{\\bar{D'}}~~~\\text{\\AA}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Time scale]\n\\begin{align*}\n        d\\bar{t}=2~\\text{fs} = 2 \\times 10^{-3} ps\n\\end{align*}\n$d\\bar{t}$ is the integration time step in Langevin dynamics. And the total simulation time is $\\bar{T}$, and the saving interval $\\Delta \\bar{t}$. Therefore, the number of data points $n$\n\\begin{align*}\n        n = \\frac{\\bar{T}}{\\Delta \\bar{t}} \n\\end{align*}\nFor example, $\\bar{T}=10$ ns and $\\Delta \\bar{t}=1$ ps\n\\begin{align*}\n        n = \\frac{\\bar{T}}{\\Delta \\bar{t}} = \\frac{10000~\\text{ps}}{1~\\text{ps}} = 10000\n\\end{align*}\nNext, we can approximate the characteristic time $\\tau$ for diffusion in water solvent for a given distance $\\bar{r}$\n\\begin{align*}\n        \\tau = \\frac{\\bar{r}^2}{\\bar{D}} \n\\end{align*}\nLet $\\bar{r}=100~\\text{\\AA}$\n\\begin{align*}\n        \\tau = \\frac{\\bar{r}^2}{\\bar{D}} = \\frac{10000}{0.243} = 41152~\\text{ps} \\approx 41~\\text{ns}\n\\end{align*}\nFor $\\bar{D}=3.052~\\text{\\AA}^2\\text{ps}^{-1}$\n\\begin{align*}\n        \\tau = \\frac{\\bar{r}^2}{\\bar{D}} = \\frac{10000}{3.052} = 3276~\\text{ps} \\approx 3.3~\\text{ns}\n\\end{align*}\n\\end{definition}\n\n\\section{Basic Equations of Reduced Units Space}\n\\begin{definition}[Langevin Equation in Reduced Units Space]\n\\begin{align*}\n    dx_t=D F(x_t)dt  + \\sqrt{2D}d{W}_t.\n\\end{align*}\nThe Wiener process $d{W}_t$\n\\begin{align*}\n        \\langle d{W}_t\\rangle &= 0 \\\\\n        \\langle d{W}_t \\cdot d{W}_{t'} \\rangle &= \\delta(t-t')dt\n\\end{align*}\n\\label{langevin}\n\\end{definition}\n\n\\begin{definition}[Reduced units]\n\\begin{center}\n\\begin{tabular}{lccc}\n\\toprule\nVariable & Symbol & This work & Transformation \\\\\n\\midrule\nLength                &  $x$       &     $L$              &   $x=f(\\bar{x})$             \\\\\nEnergy                &  $V$       &     unitless         &   $V(x)=\\bar{V}(f^{-1}(x))/(k_B T)$                 \\\\\nForce                 &  $F$       &     $L^{-1}$        &    \\\\       \nTime                  &  $t$       &     T          &   $t=100\\bar{t}$                \\\\\nDiffusion coefficient &  $D$       &     $L^2 {\\rm ps}^{-1}$ &  $D=d \\bar{D} $    \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{definition}\n\n\\begin{definition}[Affine function for length]\n\\begin{align*}\n       [0, 100] \\rightarrow [-64, 64] \n\\end{align*}\nTherfore, the affine function is \n\\begin{align*}\n        x = f(\\bar{x}) = \\frac{128}{100}\\bar{x} - 64\n\\end{align*}\nThe inverse affine is \n\\begin{align*}\n        \\bar{x} = f^{-1}(x) = \\frac{100}{128}x + 50\n\\end{align*}\nFor convenience, I name the unit of $x$ is $L$\n\\end{definition}\n\n\\begin{definition}[Time Transformation]\nFor convenience, I name the unit of time is $T$\n\\begin{align*}\n        1T = 100~\\rm{ps}\n\\end{align*}       \n\\end{definition}\n\n\\begin{definition}[Potential Energy and Force Transformation]\n\\begin{align*}\n        V(x)=\\frac{\\bar{V}(f^{-1}(x))}{k_B T}\n\\end{align*}\nand the force is\n\\begin{align*}\n        F(x)= -\\frac{d{V(x)}}{d{x}}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Diffusion Coefficient Transformation]\n$\\bar{D}$ has dimension\n\\begin{align*}\n        \\text{\\AA}^2 {\\rm ps}^{-1}.\n\\end{align*}\n$D$ has dimension \n\\begin{align*}\n        L^2 T^{-1}.\n\\end{align*}\nWe want to find $d$ for\n\\begin{align*}\n        D = d \\bar{D} \n\\end{align*}\nand we know\n\\begin{align*}\n        1 L &= \\frac{100}{128}\\text{\\AA} \\\\\n        1 \\text{\\AA} &= \\frac{128}{100}L \\\\\n        1 \\rm{ps} &= \\frac{1}{100} T \\\\\n        1 \\rm{ps}^{-1} &= 100 T^{-1}\n\\end{align*}\nTherefore\n\\begin{align*}\n        d = (\\frac{128}{100})^2 \\times 100\n\\end{align*}\n\\end{definition}\n\n\\section{Flowchart of PISL}\n\\begin{center}\n        \\includegraphics[scale=0.65]{ch1/flowchart_example.pdf}  \n\\end{center}\n\n\\section{Possible Factors affect the result of EM}\n\\begin{itemize}\n        \\item Affine function: $f(x)$. After test, No effect.\n        \\item $\\sigma_{\\rm photon}$ for approximating delta function\n        \\item MD saving time: $\\Delta \\bar{t}$\n        \\item MD total simulation time: $\\bar{T}$\n        \\item Initial guess: $p_0$\n\\end{itemize}\n\n\\section{Ito calculus}\n\\begin{definition}[Ito SDE]\nA stochastic quantity $x(t)$ obeys an Ito SDE written as\n\\begin{equation}\n        dx(t) = a[x(t), t]dt + b[x(t), t]d{W}(t)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Ito's Formula]\n\\begin{equation}\n        df[x(t)] = \\{a[x(t), t]f'[x(t)]+ \\frac{1}{2}b[x(t),t]^2 f''[x(t)]\\}dt + b[x(t),t]f'[x(t)]dW(t)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Connection between Fokker-Planck Equation and SDE]\nConsider the time development of an arbitrary $f[x(t)]$.\n\\begin{align*}\n        \\frac{\\langle df[x(t)]\\rangle}{dt} = \\langle\\frac{ df[x(t)]}{dt}\\rangle = \\frac{d}{dt}\\langle f[x(t)]\\rangle\n\\end{align*}\nFrom Ito's Formula, we also get\n\\begin{align*}\n        \\frac{\\langle df[x(t)]\\rangle}{dt} = \\langle a[x(t), t] \\frac{\\partial f}{\\partial x}+ \\frac{1}{2}b[x(t),t]^2 \\frac{\\partial^2 f}{\\partial x^2} \\rangle\n\\end{align*}\nOn the other hand, $x(t)$ has a conditional probability density $p(x,t|x_0,t_0)$ and\n\\begin{align*}\n        \\frac{d}{dt}\\langle f[x(t)]\\rangle &= \\int f(x) \\frac{\\partial p(x,t|x_0,t_0)}{\\partial t} dx\n\\end{align*}\nand\n\\begin{align*}\n        \\frac{d}{dt}\\langle f[x(t)]\\rangle &=  \\langle a[x(t), t] \\frac{\\partial f}{\\partial x}+ \\frac{1}{2}b[x(t),t]^2 \\frac{\\partial^2 f}{\\partial x^2} \\rangle \\\\\n        &= \\int a[x(t), t] \\frac{\\partial f}{\\partial x}+ \\frac{1}{2}b[x(t),t]^2 \\frac{\\partial^2 f}{\\partial x^2} p(x,t|x_0,t_0) dx\n\\end{align*}\nTherefore,\n\\begin{align*}\n        \\int f(x) \\frac{\\partial p(x,t|x_0,t_0)}{\\partial t} dx =  \\int a[x(t), t] \\frac{\\partial f}{\\partial x}+ \\frac{1}{2}b[x(t),t]^2 \\frac{\\partial^2 f}{\\partial x^2} p(x,t|x_0,t_0) dx\n\\end{align*}\nWe then integrate by parts and discard surface terms to obtain\n\\begin{align*}\n        &\\int f(x) \\frac{\\partial p(x,t|x_0,t_0)}{\\partial t} dx = \\\\\n        &\\int f(x) \\{  -\\frac{\\partial a[x(t), t] p(x,t|x_0,t_0)}{\\partial x} + \\frac{1}{2} \\frac{\\partial b[x(t),t]^2 p(x,t|x_0,t_0)}{\\partial x^2} \\}dx \n\\end{align*}\nSince $f[x(t)]$ is arbitrary, we finally get the corresponding Fokker-Planck equation\n\\begin{equation}\n        \\frac{\\partial p(x,t|x_0,t_0)}{\\partial t} =  -\\frac{\\partial a[x(t), t] p(x,t|x_0,t_0)}{\\partial x} + \\frac{1}{2} \\frac{\\partial b[x(t),t]^2 p(x,t|x_0,t_0)}{\\partial x^2}\n\\end{equation}\n\\end{definition}\n\n\\section{Constant D Langevin to Fokker-Planck: Ito SDE}\n\\begin{definition}[Constant D Langenvin Equation]\n\\begin{equation}\n        dx(t) = a[x(t), t]dt + b[x(t), t]d{W}(t)\n\\end{equation}\nwhere\n\\begin{align*}\n        a[x(t), t] &= DF(x) \\\\\n        b[x(t), t] &= \\sqrt{2D}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Corresponding Fokker-Planck Equation(FPE)]\n\\begin{align*}\n        \\frac{\\partial p(x,t|x_0,t_0)}{\\partial t} =  -\\frac{\\partial a[x(t), t] p(x,t|x_0,t_0)}{\\partial x} + \\frac{1}{2} \\frac{\\partial b[x(t),t]^2 p(x,t|x_0,t_0)}{\\partial x^2}\n\\end{align*}\nThe first term \n\\begin{align*}\n        -\\frac{\\partial a[x(t), t] p(x,t|x_0,t_0)}{\\partial x} = -D \\frac{\\partial F(x) p(x,t|x_0,t_0)}{\\partial x}\n\\end{align*} \nThe second term \n\\begin{align*}\n        \\frac{1}{2} \\frac{\\partial b[x(t),t]^2 p(x,t|x_0,t_0)}{\\partial x^2} = D \\frac{\\partial p(x,t|x_0,t_0)}{\\partial x^2}\n\\end{align*}\nFinally, we get \n\\begin{equation}\n        \\frac{\\partial p(x,t|x_0,t_0)}{\\partial t} =  -D \\frac{\\partial F(x) p(x,t|x_0,t_0)}{\\partial x} + D \\frac{\\partial p(x,t|x_0,t_0)}{\\partial x^2}  \n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Continuous equation and probability current]\nNow, $p(x,t)$ is a shorthand notation of $p(x,t|x_0,t_0)$. And from FPE, we get\n\\begin{align*}\n        \\frac{\\partial p(x,t)}{\\partial t} + \\frac{\\partial}{\\partial x} [DF(x)p(x,t) - D\\frac{\\partial p(x,t)}{\\partial x} ] = 0\n\\end{align*}\nAs a general continuity equation in a differential form:\n\\begin{align*}\n        \\frac{\\partial p(x,t)}{\\partial t} + \\nabla \\cdot j(x,t) = 0\n\\end{align*}\nAnd $j(x,t)$ is the current associated with the probability density $p(x,t)$\n\\begin{equation}\n        j(x,t) \t\\equiv DF(x)p(x,t) - D\\frac{\\partial p(x,t)}{\\partial x}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Natural boundary conditions]\nWe imposed\n\\begin{align*}\n        \\lim_{x\\to\\pm\\infty} p(x,t) &= 0 \\\\\n        \\lim_{x\\to\\pm\\infty} \\frac{\\partial p(x,t)}{\\partial x}&= 0\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[The conservation of probability]\nDefine $\\mathcal{N}(t)$ as the integral of the probability density throughout space:\n\\begin{align*}\n        \\mathcal{N}(t) \\equiv \\int p(x,t) dx\n\\end{align*}\nWe want to show the conservation of probability by the following equation\n\\begin{align*}\n        \\frac{d \\mathcal{N}(t)}{dt} = 0\n\\end{align*}\nWe begin by computing the time derivative of $\\mathcal{N}(t)$ by using FPE\n\\begin{align*}\n\\frac{d\\mathcal{N}(t)}{dt} &= \\int_{-\\infty}^{\\infty}\\frac{\\partial p(x,t)}{\\partial t}dx \\\\\n&= \\int_{-\\infty}^{\\infty}-D\\frac{\\partial}{\\partial x} [F(x)p(x,t) - \\frac{\\partial p(x,t)}{\\partial x} ]dx \\\\\n&= -D\\int_{-\\infty}^{\\infty}\\frac{\\partial j(x,t)}{\\partial x}dx\n\\end{align*}\nBy natrual boundary conditions, we can get\n\\begin{align*}\n\\frac{d\\mathcal{N}(t)}{dt} &= -D\\left [ j(\\infty,t) - j(-\\infty,t)\\right ] \\\\\n&= -D\\{[F(\\infty)p(\\infty,t) - \\frac{\\partial p(\\infty,t)}{\\partial x}]-[F(-\\infty)p(-\\infty,t) - \\frac{\\partial p(-\\infty,t)}{\\partial x}]\\} \\\\\n&= -D\\{0-0\\} = 0\n\\end{align*}\nAs you can see, the natural boundary conditions gurantee us the conservation of probability.   \n\\end{definition}\n\n\\begin{definition}[Transform FPE into an equation of Schrödinger type]\nStarting with the transformation $p(x,t) \\rightarrow \\rho(x,t)$\n\\begin{equation}\n        p(x,t) \\equiv \\exp{(\\frac{-V(x)}{2})}\\rho(x,t)\n\\label{ptorho}\n\\end{equation}\nFPE is\n\\begin{equation}\n\\label{eq:FPE}\n\\begin{split}\n        \\frac{\\partial p(x,t)}{\\partial t} &= -D\\frac{\\partial}{\\partial x}\\left [ F(x)p(x,t) \\right] + D \\frac{\\partial^2 p(x,t)}{\\partial x^2} \\\\\n        &= -D\\frac{d F(x)}{dx}p(x,t) - DF(x)\\frac{\\partial p(x,t)}{\\partial x} + D \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n\\end{split}\n\\end{equation}\nSubstitute the eq.(\\ref{ptorho}) into eq.(\\ref{eq:FPE})\n\\begin{align*}\n        \\exp{(\\frac{-V(x)}{2})}\\frac{\\partial \\rho(x,t)}{\\partial t} &= D\\frac{d^2 V(x)}{dx^2}\\exp{(\\frac{-V(x)}{2})}\\rho(x,t) -\\frac{1}{2}D(\\frac{d V(x)}{dx})^{2}\\exp{(\\frac{-V(x)}{2})}\\rho(x,t)\\\\\n&+D\\frac{dV(x)}{dx}\\exp{(\\frac{-V(x)}{2})} \\frac{\\partial \\rho(x,t)}{\\partial x} -\\frac{1}{2}D\\frac{d^2 V(x)}{dx^2}\\exp{(\\frac{-V(x)}{2})}\\rho(x,t)\\\\\n&+\\frac{1}{4}D(\\frac{d V(x)}{dx})^2\\exp{(\\frac{-V(x)}{2})}\\rho(x,t) -D\\frac{d V(x)}{dx}\\exp{(\\frac{-V(x)}{2})}\\frac{\\partial \\rho(x,t)}{\\partial x}\\\\ \n&+D\\exp{(\\frac{-V(x)}{2})} \\frac{\\partial^2 \\rho(x,t)}{\\partial x^2} \\\\ \n&= \\frac{1}{2}D\\frac{d^2 V(x)}{dx^2}\\exp{(\\frac{-V(x)}{2})}\\rho(x,t) -\\frac{1}{4}D(\\frac{d V(x)}{dx})^{2}\\exp{(\\frac{-V(x)}{2})}\\rho(x,t)\\\\\n&+D\\exp{(\\frac{-V(x)}{2})} \\frac{\\partial^2 \\rho(x,t)}{\\partial x^2} \n\\end{align*}\nMultiply $\\exp{(\\frac{V(x)}{2})}$ on both sides,\n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} = \\frac{1}{2}D\\frac{d^2 V(x)}{dx^2}\\rho(x,t)-\\frac{1}{4}D(\\frac{d V(x)}{dx})^{2}\\rho(x,t) +D\\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\nand we know \n\\begin{align*}\n        \\frac{d^2 V(x)}{dx^2} &= -\\frac{dF(x)}{dx}\\\\ \n        (\\frac{d V(x)}{dx})^{2} &= F^2(x)\n\\end{align*}\nFinally, \n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} = -\\frac{1}{2}D\\frac{d F(x)}{dx}\\rho(x,t)-\\frac{1}{4} D F^{2}(x) \\rho(x,t) +D\\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[PDE with Hermitian operator]\n\\begin{align*}\n        \\frac{\\partial}{\\partial t} \\rho(x,t) = -\\textbf{H} \\rho(x,t)\n\\end{align*}\nwhere\n\\begin{align*}\n        \\textbf{H}^0 = -D \\frac{\\partial^2}{\\partial x^2} + \\frac{1}{2}D\\frac{d F(x)}{dx} + \\frac{1}{4} D F^{2}(x)  \n\\end{align*}  \n\\end{definition}\n\n\\begin{definition}[Change Variable for t]\n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} = -\\frac{1}{2}D\\frac{d F(x)}{dx}\\rho(x,t)-\\frac{1}{4} D F^{2}(x) \\rho(x,t) +D\\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\nWe divide $D$ on both sides:\n\\begin{align*}\n        \\frac{1}{D}\\frac{\\partial \\rho(x,t)}{\\partial t} = -\\frac{1}{2}\\frac{d F(x)}{dx}\\rho(x,t)-\\frac{1}{4} F^{2}(x) \\rho(x,t) +\\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\nWe let $\\tau$\n\\begin{align}\n        \\tau &= D t \\\\\n        d{\\tau} &= D d{t}\n\\end{align}\nTherefore\n\\begin{align}\n        \\frac{\\partial \\rho(x,\\frac{\\tau}{D})}{\\partial \\tau} = -\\frac{1}{2}\\frac{d F(x)}{dx}\\rho(x,\\frac{\\tau}{D})-\\frac{1}{4} F^{2}(x) \\rho(x,\\frac{\\tau}{D}) +\\frac{\\partial^2 \\rho(x,\\frac{\\tau}{D})}{\\partial x^2}\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[Hermicity]\nIf $\\textbf{H}^0$ is a Hermitian operator for functions $\\psi(x)$ which satisfies natural boundary conditions mentioned above, the following equation should hold:\n\\begin{align*}\n        \\langle \\psi_i | \\textbf{H}^0 \\psi_j \\rangle &= \\langle \\textbf{H}^0 \\psi_i | \\psi_j \\rangle \\\\\n        &= \\int_{-\\infty}^{\\infty}dx \\psi^{*}_i \\textbf{H}^0 \\psi_j = \\int_{-\\infty}^{\\infty}dx (\\textbf{H}^0\\psi_i)^* \\psi_j\n\\end{align*}\nStarting from the left hand side:\n\\begin{align*}\n\\int_{-\\infty}^{\\infty}dx \\psi^{*}_i \\textbf{H}^0 \\psi_j &= \\int_{-\\infty}^{\\infty}dx \\psi^{*}_i [-D \\frac{\\partial^2 \\psi_j}{\\partial x^2} + \\frac{1}{2}D F'(x)\\psi_j + \\frac{1}{4}DF^2(x)\\psi_j] \\\\\n&= -D\\int_{-\\infty}^{\\infty}\\psi^{*}_i \\frac{\\partial^2 \\psi_j}{\\partial x^2} dx +\\frac{1}{2}D \\int_{-\\infty}^{\\infty} F'(x) \\psi^{*}_i \\psi_j dx + \\frac{1}{4}D\\int_{-\\infty}^{\\infty} \\psi^{*}_i F^2(x)\\psi_j dx \\\\\n& = D\\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi^*_i}{\\partial x} \\frac{\\partial \\psi_j}{\\partial x}dx +\\frac{1}{2}D \\int_{-\\infty}^{\\infty} F'(x) \\psi^{*}_i \\psi_j dx + \\frac{1}{4}D\\int_{-\\infty}^{\\infty} \\psi^{*}_i F^2(x)\\psi_j dx \n\\end{align*}\nThe right hand side:\n\\begin{align*}\n\\int_{-\\infty}^{\\infty}dx (\\textbf{H}^0\\psi_i)^* \\psi_j &= \\int_{-\\infty}^{\\infty}dx [-D \\frac{\\partial^2 \\psi_i}{\\partial x^2} + \\frac{1}{2}D F'(x)\\psi_i + \\frac{1}{4}DF^2(x)\\psi_i]^{*}\\psi_j \\\\\n&= -D\\int_{-\\infty}^{\\infty}\\frac{\\partial^2 \\psi^*_i}{\\partial x^2}\\psi_j dx + \\frac{1}{2}D\\int_{-\\infty}^{\\infty}F'(x)\\psi^*_i \\psi_j dx + \\frac{1}{4}D\\int_{-\\infty}^{\\infty} F^2(x)\\psi^*_i \\psi_j dx \\\\\n&= -D\\int_{-\\infty}^{\\infty}\\frac{\\partial \\psi^*_i}{\\partial x}\\frac{\\partial \\psi_j}{\\partial x} dx + \\frac{1}{2}D\\int_{-\\infty}^{\\infty}F'(x)\\psi^*_i \\psi_j dx + \\frac{1}{4}D\\int_{-\\infty}^{\\infty} F^2(x)\\psi^*_i \\psi_j dx \\\\\n\\end{align*}\nAs you can see, the two sides result in the two functional form, so $\\textbf{H}^0$ is a Hermitian operator.\nHere, we used integration by parts and boundary conditions:\n\\begin{align*}\n\\int_{-\\infty}^{\\infty}\\psi^{*}_i \\frac{\\partial^2 \\psi_j}{\\partial x^2} dx &= \\int_{-\\infty}^{\\infty}\\psi^{*}_i \\frac{\\partial}{\\partial x}(\\frac{\\partial \\psi_j}{\\partial x}) dx \\\\\n& = [\\psi^{*}_i \\frac{\\partial \\psi_j}{\\partial x}]_{-\\infty}^{\\infty} - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi^*_i}{\\partial x} \\frac{\\partial \\psi_j}{\\partial x}dx\\\\\n& = - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi^*_i}{\\partial x} \\frac{\\partial \\psi_j}{\\partial x}dx \n\\end{align*}\n\\end{definition}\n\n\\section{From FPE to Ito SDE for position-dependent diffusity}\n\\begin{definition}[Flux]\n\\begin{align*}\n        j(x) = D(x)\\left( F(x)p(x,t) - \\frac{\\partial p(x,t)}{\\partial x}\\right)\n\\end{align*}\nIf $p(x,t) = p_{\\rm eq}(x) = \\exp{(-V(x))}$\n\\begin{align*}\n        j(x) &= D(x)\\left( F(x)\\exp{(-V(x))} - \\left(-\\frac{dV(x)}{dx}\\right)\\exp{(-V(x))} \\right) \\\\\n        &= D(x) \\left[ F(x)\\exp{(-V(x))} - F(x)\\exp{(-V(x))}\\right] = 0\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Continuous equation and FPE]\nA general continuity equation in a differential form:\n\\begin{align*}\n        \\frac{\\partial p(x,t)}{\\partial t} &= - \\nabla \\cdot j(x,t) \\\\\n        &= - \\frac{\\partial D(x)}{\\partial x}\\left( F(x)p(x,t) - \\frac{\\partial p(x,t)}{\\partial x}\\right) - D(x) \\frac{\\partial \\left( F(x)p(x,t) - \\frac{\\partial p(x,t)}{\\partial x}\\right) }{\\partial x}\n\\end{align*}\nThe first term in right hand side is:\n\\begin{align*}\n        - \\frac{\\partial D(x)}{\\partial x}F(x)p(x,t) + \\frac{\\partial D(x)}{\\partial x}\\frac{\\partial p(x,t)}{\\partial x}\n\\end{align*}\nThe second term in right hand side is:\n\\begin{align*}\n        -D(x)\\frac{\\partial F(x)}{\\partial x}p(x,t) -D(x)F(x)\\frac{\\partial p(x,t)}{\\partial x} + D(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n\\end{align*}\nCollect together:\n\\begin{align*}\n        -\\left(\\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} \\right)p(x,t) - \\left( D(x)F(x) -\\frac{\\partial D(x)}{\\partial x} \\right)\\frac{\\partial p(x,t)}{\\partial x} + D(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Ito's SDE and FPE]\nOn the other hand, the form of FPE can be \n\\begin{align*}\n        \\frac{\\partial p(x,t)}{\\partial t} =  -\\frac{\\partial a(x) p(x,t)}{\\partial x} + \\frac{1}{2} \\frac{\\partial^2 b^2(x) p(x,t)}{\\partial x^2}\n\\end{align*}\nExpand the first term of the right hand side:\n\\begin{align*}\n        -\\frac{\\partial a(x)}{\\partial x}p(x,t) - a(x)\\frac{\\partial  p(x,t)}{\\partial x}\n\\end{align*}\nExpand the second term of the right hand side:\n\\begin{align*}\n        &\\frac{1}{2}\\frac{\\partial}{\\partial x} \\left( \\frac{\\partial b^2(x) p(x,t)}{\\partial x}  \\right) =\n        \\frac{1}{2}\\frac{\\partial}{\\partial x} \\left( \\frac{\\partial b^2(x)}{\\partial x}p(x,t) + b^2(x) \\frac{\\partial p(x,t)}{\\partial x} \\right) =\\\\\n        & \\frac{1}{2}\\left( \n                \\frac{\\partial^2 b^2(x)}{\\partial x^2} p(x,t) + 2\\frac{\\partial b^2(x)}{\\partial x}\\frac{\\partial p(x,t)}{\\partial x} + b^2(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n        \\right) \n\\end{align*}\nCollect together\n\\begin{align*}\n        \\left( -\\frac{\\partial a(x)}{\\partial x} + \\frac{1}{2}\\frac{\\partial^2 b^2(x)}{\\partial x^2} \\right) p(x,t)\n        + \\left( -a(x) +  \\frac{\\partial b^2(x)}{\\partial x} \\right) \\frac{\\partial p(x,t)}{\\partial x}\n        + \\frac{1}{2}b^2(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Try to find a(x) and b(x)]\nFrom continuous equation, we get\n\\begin{align*}\n        -\\left(\\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} \\right)p(x,t) - \\left( D(x)F(x) -\\frac{\\partial D(x)}{\\partial x} \\right)\\frac{\\partial p(x,t)}{\\partial x} + D(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n\\end{align*}\nFrom Ito's FPE, we get\n\\begin{align*}\n        \\left( -\\frac{\\partial a(x)}{\\partial x} + \\frac{1}{2}\\frac{\\partial^2 b^2(x)}{\\partial x^2} \\right) p(x,t)\n        + \\left( -a(x) +  \\frac{\\partial b^2(x)}{\\partial x} \\right) \\frac{\\partial p(x,t)}{\\partial x}\n        + \\frac{1}{2}b^2(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}    \n\\end{align*}\nTherefore,\n\\begin{align}\n        -\\left(\\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} \\right) & = \\left( -\\frac{\\partial a(x)}{\\partial x} + \\frac{1}{2}\\frac{\\partial^2 b^2(x)}{\\partial x^2} \\right) \\label{eqab1} \\\\\n        - \\left( D(x)F(x) -\\frac{\\partial D(x)}{\\partial x} \\right) &= \\left( -a(x) +  \\frac{\\partial b^2(x)}{\\partial x} \\right) \\label{eqab2} \\\\\n        D(x) &= \\frac{1}{2}b^2(x) \\label{eqab3}\n\\end{align}\nBy eq.(\\ref{eqab3}), we first get \n\\begin{align*}\n        b(x) &= \\sqrt{2D(x)} \\\\\n        \\frac{\\partial b^2(x)}{\\partial x} &= 2 \\frac{\\partial D(x)}{\\partial x} \\\\\n        \\frac{1}{2}\\frac{\\partial^2 b^2(x)}{\\partial x^2} &= \\frac{\\partial^2 D(x)}{\\partial x^2}\n\\end{align*}\nand we substitute the above into eq.(\\ref{eqab2}),\n\\begin{align*}\n        -D(x)F(x) + \\frac{\\partial D(x)}{\\partial x} = -a(x) + 2 \\frac{\\partial D(x)}{\\partial x}\n\\end{align*}\nso \n\\begin{align*}\n        a(x) &= D(x)F(x) + \\frac{\\partial D(x)}{\\partial x} \\\\\n        \\frac{\\partial a(x)}{\\partial x} &= \\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} + \\frac{\\partial^2 D(x)}{\\partial x^2}\n\\end{align*}\nFinally, we substitute $\\frac{\\partial a(x)}{\\partial x}$ and $\\frac{\\partial^2 b^2(x)}{\\partial x^2}$ into eq.(\\ref{eqab1}) try to check the consistency\n\\begin{align*}\n        -\\left(\\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} \\right) = -\\left( \\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} + \\frac{\\partial^2 D(x)}{\\partial x^2} \\right) + \\frac{\\partial^2 D(x)}{\\partial x^2}\n\\end{align*}\nand they are consistent.\n\\end{definition}\n\n\\begin{definition}[Ito SDE]\nFrom the above, we get\n\\begin{align}\n        a(x) &= D(x)F(x) + \\frac{\\partial D(x)}{\\partial x} \\\\\n        b(x) &= \\sqrt{2D(x)}\n\\end{align}\nTherefore, the langevin equation(SDE) for position-dependent diffusity is \n\\begin{equation}\n\\begin{split}\n        dx(t) &= a(x)dt + b(x)dW(t) \\\\\n        &= D(x)F(x)dt + \\frac{\\partial D(x)}{\\partial x}dt + \\sqrt{2D(x)}dW(t)\n\\end{split}\n\\label{posdepsde}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[D(x)]\nWe express the position dependent diffusity as\n\\begin{equation}\n        D(x) = D + \\eta(x)\n\\label{dofx}\n\\end{equation}\nThe domain $x \\in [a,b]$, and the integration of $\\eta(x)$ over whole domain is 0\n\\begin{align*}\n        \\int_a^b \\eta(x) dx = 0\n\\end{align*}\nand \n\\begin{align*}\n        \\int_a^b D(x) dx &= \\int_a^b D dx + \\int_a^b \\eta(x) dx \\\\\n        &= D \\int_a^b dx = (b-a)D\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Rewrite Ito SDE]\nNow, substitute eq.(\\ref{dofx}) into eq.(\\ref{posdepsde})\n\\begin{align*}\n        dx(t) &= D(x)F(x)dt  + \\sqrt{2D(x)}dW(t) \\\\\n        &= DF(x)dt + \\eta(x)F(x)dt + \\sqrt{2D+2\\eta(x)}dW(t)\n\\end{align*}\nWe introduced a new function $\\epsilon(x)$\n\\begin{align*}\n        \\sqrt{2D+2\\eta(x)}dW(t) = \\sqrt{2D}dW(t) + \\epsilon(x)dW(t)\n\\end{align*}\nTherefore, SDE becomes\n\\begin{align*}\n        dx(t) = \\left(DF(x)dt + \\sqrt{2D}dW(t)\\right) + \\left(\\eta(x)F(x)dt + \\epsilon(x)dW(t)\\right)\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Some convenient equations]\n\\begin{align*}\n        \\frac{\\partial p(x,t)}{\\partial x} &= \\frac{1}{2}F(x)g(x)\\rho(x,t) + g(x) \\frac{\\partial \\rho(x,t)}{\\partial x} \\\\\n        \\frac{\\partial^2 p(x,t)}{\\partial x^2} &= \\frac{1}{2} \\frac{d F(x)}{dx} g(x) \\rho(x,t) + \\frac{1}{4}F^2(x)g(x)\\rho(x,t) + F(x)g(x)\\frac{\\partial \\rho(x,t)}{\\partial x} + g(x) \\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Transform FPE into an equation of Schrödinger type]\nStarting with the transformation $p(x,t) \\rightarrow \\rho(x,t)$\n\\begin{equation}\n\\label{eq:transformFPE}\n        p(x,t) \\equiv \\exp{(\\frac{-V(x)}{2})}\\rho(x,t) = g(x) \\rho(x,t)\n\\end{equation}\nFPE is\n\\begin{equation}\n\\label{eq:FPEexpand}\n\\begin{split}\n        \\frac{\\partial p(x,t)}{\\partial t} &= - \\nabla \\cdot j(x,t) = -\\nabla \\cdot D(x)\\left( F(x)p(x,t) - \\frac{\\partial p(x,t)}{\\partial x}\\right) \\\\\n        &= -\\left(\\frac{\\partial D(x)}{\\partial x}F(x) + D(x)\\frac{\\partial F(x)}{\\partial x} \\right)p(x,t) - \\left( D(x)F(x) -\\frac{\\partial D(x)}{\\partial x} \\right)\\frac{\\partial p(x,t)}{\\partial x} + D(x) \\frac{\\partial^2 p(x,t)}{\\partial x^2}\n\\end{split}\n\\end{equation}\nSubstitute the eq.(\\ref{eq:transformFPE}) into eq.(\\ref{eq:FPEexpand}) and calculate all terms separately for the right terms\n\\begin{align*}\n        -\\frac{\\partial D(x)}{\\partial x}F(x)p(x,t) &= -\\frac{\\partial D(x)}{\\partial x}g(x)F(x)\\rho(x,t) \\\\\n        -D(x)\\frac{\\partial F(x)}{\\partial x}p(x,t) &= -g(x)D(x)\\frac{\\partial F(x)}{\\partial x}\\rho(x,t) \\\\\n        - D(x)F(x)\\frac{\\partial p(x,t)}{\\partial x} &= - \\frac{1}{2}D(x)F^2(x)g(x)\\rho(x,t) - D(x)F(x) g(x) \\frac{\\partial \\rho(x,t)}{\\partial x} \\\\\n        \\frac{\\partial D(x)}{\\partial x}\\frac{\\partial p(x,t)}{\\partial x} &= \\frac{1}{2}\\frac{\\partial D(x)}{\\partial x}g(x)F(x) \\rho(x,t) + g(x) \\frac{\\partial D(x)}{\\partial x} \\frac{\\partial \\rho(x,t)}{\\partial x} \\\\\n        D(x)\\frac{\\partial^2 p(x,t)}{\\partial x^2} &= \\frac{1}{2} D(x) \\frac{\\partial F(x)}{\\partial x} g(x) \\rho(x,t) + \\frac{1}{4}D(x)F^2(x)g(x)\\rho(x,t) \\\\\n        &+ D(x)F(x)g(x)\\frac{\\partial \\rho(x,t)}{\\partial x} + D(x)g(x) \\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\nThen,\n\\begin{align*}\n        g(x) \\frac{\\partial \\rho(x,t)}{\\partial t} &= - \\frac{1}{4}D(x)F^2(x)g(x)\\rho(x,t) - \\frac{1}{2}D(x)g(x) \\frac{dF(x)}{dx} \\rho(x,t) - \\frac{1}{2}\\frac{\\partial D(x)}{\\partial x}g(x)F(x) \\rho(x,t) \\\\\n        &+ g(x) \\frac{\\partial D(x)}{\\partial x} \\frac{\\partial \\rho(x,t)}{\\partial x}  + D(x)g(x) \\frac{\\partial^2 \\rho(x,t)}{\\partial x^2}\n\\end{align*}\nMultiply $\\frac{1}{g(x)}$ on both sides, we get\n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} &= - \\frac{1}{2}D(x)\\frac{dF(x)}{dx} \\rho(x,t) - \\frac{1}{4}D(x)F^2(x)\\rho(x,t)   + D(x)\\frac{\\partial^2 \\rho(x,t)}{\\partial x^2} \\\\\n        &+ \\frac{\\partial D(x)}{\\partial x} \\frac{\\partial \\rho(x,t)}{\\partial x}  - \\frac{1}{2}\\frac{\\partial D(x)}{\\partial x}F(x) \\rho(x,t)\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Probability current]\n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} &= D(x) \\left(-\\frac{1}{2}\\frac{dF(x)}{dx} - \\frac{1}{4}F^2(x) + \\frac{\\partial^2 }{\\partial x^2}  \\right) \\rho(x,t) + \\frac{\\partial D(x)}{\\partial x} \\left( \\frac{\\partial }{\\partial x} - \\frac{1}{2} F(x) \\right)\\rho(x,t)\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[PDE and operator]\n\\begin{align*}\n        \\frac{\\partial}{\\partial t} \\rho(x,t) = -\\textbf{H} \\rho(x,t)\n\\end{align*}\nwhere\n\\begin{align*}\n        \\textbf{H} &= -D(x) \\frac{\\partial^2}{\\partial x^2} + \\frac{1}{2}D(x)\\frac{d F(x)}{dx} + \\frac{1}{4} D(x) F^{2}(x) -\\frac{\\partial D(x)}{\\partial x}\\frac{\\partial }{\\partial x} + \\frac{1}{2} \\frac{\\partial D(x)}{\\partial x} F(x)\n\\end{align*}\nRecall that $D(x)=D+\\eta(x)$, and substitute into each terms separately\n\\begin{align*}\n        -D(x) \\frac{\\partial^2}{\\partial x^2} &= -D\\frac{\\partial^2}{\\partial x^2} - \\eta(x)\\frac{\\partial^2}{\\partial x^2} \\\\\n        \\frac{1}{2}D(x)\\frac{d F(x)}{dx} &= \\frac{1}{2}D\\frac{d F(x)}{dx} + \\frac{1}{2}\\eta(x)\\frac{d F(x)}{dx} \\\\\n        \\frac{1}{4} D(x) F^{2}(x)  &= \\frac{1}{4} D F^{2}(x)  + \\frac{1}{4} \\eta(x) F^{2}(x) \n\\end{align*}\nand we also know $\\frac{\\partial D(x)}{\\partial x} = \\frac{\\partial \\eta(x)}{\\partial x} $, Therefore,\n\\begin{equation}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} = -\\textbf{H} \\rho(x,t) = -(\\textbf{H}^0 +\\textbf{H}^D) \\rho(x,t)\n\\end{equation}\nwhere\n\\begin{align*}\n        \\textbf{H}^0 &= -D\\frac{\\partial^2}{\\partial x^2} + \\frac{1}{2}D\\frac{d F(x)}{dx} + \\frac{1}{4} D F^{2}(x) \\\\\n        \\textbf{H}^D &= - \\eta(x)\\frac{\\partial^2}{\\partial x^2} + \\frac{1}{2}\\eta(x)\\frac{d F(x)}{dx} + \\frac{1}{4} \\eta(x) F^{2}(x) -\\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial }{\\partial x} + \\frac{1}{2} \\frac{\\partial \\eta(x)}{\\partial x} F(x)\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Hermicity]\nIf $\\textbf{H}$ is a Hermitian operator for functions $\\psi(x)$ which satisfies natural boundary conditions mentioned above, the following equation should hold:\n\\begin{align*}\n                \\langle \\psi_i | \\textbf{H} \\psi_j \\rangle &= \\langle \\textbf{H} \\psi_i | \\psi_j \\rangle \\\\\n                &= \\int_{-\\infty}^{\\infty}dx \\psi_i \\textbf{H} \\psi_j = \\int_{-\\infty}^{\\infty}dx (\\textbf{H}\\psi_i) \\psi_j\n\\end{align*}\nThe left side:\n\\begin{align*}\n        &\\int_{-\\infty}^{\\infty} \\psi_i(x) \\textbf{H} \\psi_j(x) dx = -D\\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx + \\frac{1}{2}D\\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{d F(x)}{dx} \\psi_j(x) dx \\\\\n        &+ \\frac{1}{4}D\\int_{-\\infty}^{\\infty} \\psi_i(x) F^{2}(x) \\psi_j(x) dx - \\int_{-\\infty}^{\\infty} \\psi_i(x) \\eta(x)\\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx \\\\\n        &+ \\frac{1}{2} \\int_{-\\infty}^{\\infty} \\psi_i(x) \\eta(x)\\frac{d F(x)}{dx} \\psi_j(x) dx + \\frac{1}{4}\\int_{-\\infty}^{\\infty} \\psi_i(x)  \\eta(x) F^{2}(x) \\psi_j(x) dx \\\\\n        &- \\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_j(x)}{\\partial x} dx + \\frac{1}{2} \\int_{-\\infty}^{\\infty} \\psi_i(x)  \\frac{\\partial \\eta(x)}{\\partial x} F(x) \\psi_j(x) dx\n\\end{align*}\nThe right side:\n\\begin{align*}\n        &\\int_{-\\infty}^{\\infty} (\\textbf{H} \\psi_i(x)) \\psi_j(x) dx =  -D\\int_{-\\infty}^{\\infty} \\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx + \\frac{1}{2}D \\int_{-\\infty}^{\\infty} \\frac{d F(x)}{dx} \\psi_i(x) \\psi_j(x) dx \\\\\n        &+ \\frac{1}{4} D \\int_{-\\infty}^{\\infty} F^{2}(x) \\psi_i(x) \\psi_j(x) dx - \\int_{-\\infty}^{\\infty}  \\eta(x)\\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx \\\\\n        &+ \\frac{1}{2} \\int_{-\\infty}^{\\infty} \\eta(x)\\frac{d F(x)}{dx} \\psi_i(x) \\psi_j(x) dx + \\frac{1}{4} \\int_{-\\infty}^{\\infty} \\eta(x) F^{2}(x) \\psi_i(x) \\psi_j(x) dx \\\\\n        &- \\int_{-\\infty}^{\\infty} \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_i(x)}{\\partial x}  \\psi_j(x) dx + \\frac{1}{2} \\int_{-\\infty}^{\\infty} \\frac{\\partial \\eta(x)}{\\partial x} F(x) \\psi_i(x) \\psi_j(x) dx\n\\end{align*}\nThe only different terms in the left hand side:\n\\begin{equation}\\label{eq:left}\n        -D\\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx - \\int_{-\\infty}^{\\infty} \\psi_i(x) \\eta(x)\\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx - \\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_j(x)}{\\partial x} dx\n\\end{equation}\nand in the right hand side:\n\\begin{equation}\\label{eq:right}\n        -D\\int_{-\\infty}^{\\infty} \\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx - \\int_{-\\infty}^{\\infty}  \\eta(x)\\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_i(x)}{\\partial x}  \\psi_j(x) dx\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Hermicity-Integral by part: 1]\\label{def:hermicity1}\n\\begin{align*}\n        -D\\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx &= [\\psi_i(x) \\frac{\\partial \\psi_j(x)}{\\partial x}]_{-\\infty}^{\\infty} - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi_i(x)}{\\partial x} \\frac{\\partial \\psi_j(x)}{\\partial x}dx\\\\\n        & = - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi_i(x)}{\\partial x} \\frac{\\partial \\psi_j(x)}{\\partial x}dx \n\\end{align*}\n\\begin{align*}\n        -D\\int_{-\\infty}^{\\infty} \\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx &= [\\frac{\\partial \\psi_i(x)}{\\partial x}\\psi_j(x) ]_{-\\infty}^{\\infty} - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi_j(x)}{\\partial x} \\frac{\\partial \\psi_i(x)}{\\partial x}dx\\\\\n        & = - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\psi_j(x)}{\\partial x} \\frac{\\partial \\psi_i(x)}{\\partial x}dx \n\\end{align*}\nTherefore, the first terms in two sides are the same.\n\\end{definition}\n\n\\begin{definition}[Hermicity-Integral by part: 2-1]\\label{def:hermicity2-1}\n\\begin{align*}\n        u(x) &= \\psi_i(x) \\eta(x) ~~~~~ v'(x) = \\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} \\\\\n        u'(x) &= \\frac{\\partial \\psi_i(x)}{\\partial x} \\eta(x) + \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i(x) ~~~~~ v(x) = \\frac{\\partial \\psi_j(x)}{\\partial x}\n\\end{align*}\n\\begin{align*}\n        &-\\int_{-\\infty}^{\\infty} \\psi_i(x) \\eta(x)\\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx = -{\\Big [} \\psi_i(x) \\eta(x) \\frac{\\partial \\psi_j(x)}{\\partial x}{\\Big ]}_{-\\infty}^{\\infty} \\\\\n        &+ \\int_{-\\infty}^{\\infty} \\eta(x) \\frac{\\partial \\psi_i(x)}{\\partial x}  \\frac{\\partial \\psi_j(x)}{\\partial x} dx + \\int_{-\\infty}^{\\infty}  \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i(x)  \\frac{\\partial \\psi_j(x)}{\\partial x} dx\n\\end{align*}\nTherefore,\n\\begin{align*}\n        &-\\int_{-\\infty}^{\\infty} \\psi_i(x) \\eta(x)\\frac{\\partial^2 \\psi_j(x)}{\\partial x^2} dx - \\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_j(x)}{\\partial x} dx = \\\\\n        &\\int_{-\\infty}^{\\infty} \\eta(x) \\frac{\\partial \\psi_i(x)}{\\partial x}  \\frac{\\partial \\psi_j(x)}{\\partial x} dx + \\int_{-\\infty}^{\\infty}  \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i(x)  \\frac{\\partial \\psi_j(x)}{\\partial x} dx \n        - \\int_{-\\infty}^{\\infty} \\psi_i(x) \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_j(x)}{\\partial x} dx \\\\\n        &= \\int_{-\\infty}^{\\infty} \\eta(x) \\frac{\\partial \\psi_i(x)}{\\partial x}  \\frac{\\partial \\psi_j(x)}{\\partial x} dx\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Hermicity-Integral by part: 2-2]\\label{def:hermicity2-2}\n\\begin{align*}\n        u(x) &= \\psi_j(x) \\eta(x) ~~~~~ v'(x) = \\frac{\\partial^2 \\psi_i(x)}{\\partial x^2}\\\\\n        u'(x) &= \\frac{\\partial \\psi_j(x)}{\\partial x} \\eta(x) + \\frac{\\partial \\eta(x)}{\\partial x} \\psi_j(x) ~~~~~ v(x) = \\frac{\\partial \\psi_i(x)}{\\partial x}\n\\end{align*}\n\\begin{align*}\n        &- \\int_{-\\infty}^{\\infty}  \\eta(x)\\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx = -{\\Big [} \\psi_j(x) \\eta(x) \\frac{\\partial \\psi_i(x)}{\\partial x}{\\Big ]}_{-\\infty}^{\\infty} \\\\\n        &+ \\int_{-\\infty}^{\\infty} \\eta(x) \\frac{\\partial \\psi_j(x)}{\\partial x}  \\frac{\\partial \\psi_i(x)}{\\partial x} dx + \\int_{-\\infty}^{\\infty}  \\frac{\\partial \\eta(x)}{\\partial x} \\psi_j(x)  \\frac{\\partial \\psi_i(x)}{\\partial x} dx\n\\end{align*}\nTherefore,\n\\begin{align*}\n        & - \\int_{-\\infty}^{\\infty}  \\eta(x)\\frac{\\partial^2 \\psi_i(x)}{\\partial x^2} \\psi_j(x) dx - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_i(x)}{\\partial x}  \\psi_j(x) dx = \\\\\n        & \\int_{-\\infty}^{\\infty} \\eta(x) \\frac{\\partial \\psi_j(x)}{\\partial x}  \\frac{\\partial \\psi_i(x)}{\\partial x} dx + \\int_{-\\infty}^{\\infty}  \\frac{\\partial \\eta(x)}{\\partial x} \\psi_j(x)  \\frac{\\partial \\psi_i(x)}{\\partial x} dx - \\int_{-\\infty}^{\\infty} \\frac{\\partial \\eta(x)}{\\partial x}\\frac{\\partial \\psi_i(x)}{\\partial x}  \\psi_j(x) dx\\\\\n        &= \\int_{-\\infty}^{\\infty} \\eta(x) \\frac{\\partial \\psi_j(x)}{\\partial x}  \\frac{\\partial \\psi_i(x)}{\\partial x} dx\n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[H is Hermitian]\nFrom def.(\\ref{def:hermicity1})(\\ref{def:hermicity2-1})(\\ref{def:hermicity2-2}) and eq.(\\ref{eq:left})(\\ref{eq:right}),\nwe prove $\\textbf{H}$ is Hermitian. Therefore, we can find a set of orthonormal basis $\\{\\psi_i(x)\\}$\n\\begin{equation}\n        \\textbf{H}\\psi_i(x) = \\lambda_i \\psi_i(x)\n\\end{equation}\nAnd for PDE \n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} = - \\textbf{H} \\rho(x,t)\n\\end{align*}\nWe can have the solution\n\\begin{equation}\n        \\rho(x,t) = \\sum_i c_i \\text{e}^{-\\lambda_i t} \\psi_i(x)\n\\end{equation}\n\\end{definition}\n\n\\section{Find the eigenfunction like dark operator}\n\\begin{definition}[The first set of orthonormal basis]\nBecause $\\textbf{H}^0$ is Hermitian, we can get a set of orthonormal basis $\\{\\psi^0_i(x)\\}$\n\\begin{align*}\n        \\textbf{H}^0 \\psi^0_i(x) = \\lambda^0_i \\psi^0_i(x)  \n\\end{align*}\n\\end{definition}\n\n\\begin{definition}[Construct another eigenbasis]\nRecall that\n\\begin{align*}\n        \\frac{\\partial \\rho(x,t)}{\\partial t} = -\\textbf{H} \\rho(x,t) = -(\\textbf{H}^0 +\\textbf{H}^D) \\rho(x,t)  \n\\end{align*}\nBecause $\\textbf{H}$ is Hermitian, we can find a set of eigenfunctions $\\{\\psi_i(x)\\}$\n\\begin{equation}\n        \\textbf{H} \\left | \\psi_i \\right> =  \\lambda_i \\left | \\psi_i \\right>\n\\end{equation}\nAnd the new eigenfunction is then constructed as a linear combination of $\\left| \\psi_j^0\\right>$\n\\begin{align*}\n        \\left| \\psi_i \\right> = \\sum_j c_{ij}  \\left| \\psi_j^0\\right>\n\\end{align*}\nso the question now is to find $c_{ij}$ and get a correct linear combination.\n\\end{definition}\n\n\\begin{definition}[Find c]\nFirst, assume $i=1~\\textrm{to}~n$,\n\\begin{equation}\n\\label{psi0psi}\n\\begin{split}\n        | \\psi_1 \\rangle = c_{11}| \\psi_1^0 \\rangle + c_{12}| \\psi_2^0 \\rangle +  c_{13}| \\psi_3^0 \\rangle+\\cdots + c_{1n}| \\psi_n^0 \\rangle\\\\\n        | \\psi_2 \\rangle = c_{21}| \\psi_1^0 \\rangle + c_{22}| \\psi_2^0 \\rangle +  c_{23}| \\psi_3^0 \\rangle+\\cdots + c_{2n}| \\psi_n^0 \\rangle\\\\\n        | \\psi_3 \\rangle = c_{31}| \\psi_1^0 \\rangle + c_{32}| \\psi_2^0 \\rangle +  c_{33}| \\psi_3^0 \\rangle+\\cdots + c_{3n}| \\psi_n^0 \\rangle\\\\\n        \\vdots \\\\\n        | \\psi_n \\rangle = c_{n1}| \\psi_1^0 \\rangle + c_{n2}| \\psi_2^0 \\rangle +  c_{n3}| \\psi_3^0 \\rangle+\\cdots + c_{nn}| \\psi_n^0 \\rangle\n\\end{split}\n\\end{equation}\nNow, we focus on the case of $i=1$\n\\begin{equation}\n\\label{eg1}\n        \\textbf{H} | \\psi_1 \\rangle = \\lambda_1 | \\psi_1 \\rangle\n\\end{equation}\nThen, substitute eq.(\\ref{psi0psi}) into eq.(\\ref{eg1})\n\\begin{equation}\n\\label{egextend}\n\\begin{split}\n        c_{11}\\textbf{H}| \\psi_1^0 \\rangle + c_{12}\\textbf{H}| \\psi_2^0\\rangle +  c_{13}\\textbf{H}| \\psi_3^0\\rangle + \\cdots +  c_{1n}\\textbf{H}| \\psi_n^0\\rangle =\\\\ \\lambda_1 \\left( c_{11}| \\psi_1^0 \\rangle + c_{12}| \\psi_2^0 \\rangle +  c_{13    }| \\psi_3^0 \\rangle+\\cdots + c_{1n}| \\psi_n^0 \\rangle\\right)\n\\end{split}\n\\end{equation}\nAnd we multiply $\\langle\\psi_1^0|$ on the left-hand side of eq.(\\ref{eg1})\n\\begin{equation}\n\\label{eg1multipleft}\n\\langle\\psi_1^0|\\textbf{H} | \\psi_1 \\rangle = \\langle\\psi_1^0|\\lambda_1 | \\psi_1 \\rangle\n\\end{equation}\nEq.(\\ref{egextend}) becomes\n\\begin{equation}\n\\begin{split}\nc_{11}\\langle\\psi_1^0|\\textbf{H}| \\psi_1^0 \\rangle + c_{12}\\langle\\psi_1^0|\\textbf{H}| \\psi_2^0\\rangle +  c_{13}\\langle\\psi_1^0|\\textbf{H}| \\psi_3^0\\rangle + \\cdots +  c_{1n}\\langle\\psi_1^0|\\textbf{H}| \\psi_n^0\\rangle =\\\\ \\lambda_1 \\left( c_{11}\\langle\\psi_1^0| \\psi_1^0 \\rangle + c_{12}\\langle\\psi_1^0| \\psi_2^0 \\rangle +  c_{13}\\langle\\psi_1^0| \\psi_3^0 \\rangle+\\cdots + c_{1n}\\langle\\psi_1^0| \\psi_n^0 \\rangle\\right)\n\\end{split}\n\\end{equation}\nThe eigenbasis $\\{|\\psi_i^0 \\rangle\\}$ is orthonormal, so\n\\begin{equation}\n\\label{eg1lastform}\n\\begin{split}\nc_{11}\\langle\\psi_1^0|\\textbf{H}| \\psi_1^0 \\rangle + c_{12}\\langle\\psi_1^0|\\textbf{H}| \\psi_2^0\\rangle +  c_{13}\\langle\\psi_1^0|\\textbf{H}| \\psi_3^0\\rangle + \\cdots +  c_{1n}\\langle\\psi_1^0|\\textbf{H}| \\psi_n^0\\rangle =\\lambda_1 c_{11}\n\\end{split}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Matrix K]\nWe also can generate more equations by \n\\begin{equation}\n\\label{eg1gen}\n\\begin{split}\n        \\langle\\psi_2^0|\\bm{H} | \\psi_1 \\rangle &= \\langle\\psi_2^0|\\lambda_1 | \\psi_1 \\rangle\\\\\n        \\langle\\psi_3^0|\\bm{H} | \\psi_1 \\rangle &= \\langle\\psi_3^0|\\lambda_1 | \\psi_1 \\rangle\\\\\n        &\\vdots \\\\\n        \\langle\\psi_n^0|\\bm{H} | \\psi_1 \\rangle &= \\langle\\psi_n^0|\\lambda_1 | \\psi_1 \\rangle\n\\end{split}\n\\end{equation}\nBy collecting equation (\\ref{eg1}) and (\\ref{eg1gen}), and express as equation (\\ref{eg1lastform}), we can get the following matrix expression\n\\begin{equation}\n\\begin{bmatrix}\n\\langle\\psi_1^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_1^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_1^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_1^0|\\bm{H}| \\psi_n^0 \\rangle \\\\\n\\langle\\psi_2^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_2^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_2^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_2^0|\\bm{H}| \\psi_n^0 \\rangle \\\\\n\\vdots \\\\\n\\langle\\psi_n^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_n^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_n^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_n^0|\\bm{H}| \\psi_n^0 \\rangle \n\\end{bmatrix}\n\\begin{bmatrix}\nc_{11} \\\\ c_{12} \\\\ \\vdots \\\\ c_{1n}\n\\end{bmatrix}\n= \\lambda_1\n\\begin{bmatrix}\nc_{11} \\\\ c_{12} \\\\ \\vdots \\\\ c_{1n}\n\\end{bmatrix} \n\\end{equation}\nDefine\n\\begin{equation}\n        K=\n\\begin{bmatrix}\n        \\langle\\psi_1^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_1^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_1^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_1^0|\\bm{H}| \\psi_n^0 \\rangle \\\\\n        \\langle\\psi_2^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_2^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_2^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_2^0|\\bm{H}| \\psi_n^0 \\rangle \\\\\n        \\vdots \\\\\n        \\langle\\psi_n^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_n^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_n^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_n^0|\\bm{H}| \\psi_n^0 \\rangle \n\\end{bmatrix}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[The new eigen-problem for solving c]\n\\begin{equation}\n        K\\textbf{c}_{i} = \n        \\begin{bmatrix}\n        \\langle\\psi_1^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_1^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_1^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_1^0|\\bm{H}| \\psi_n^0 \\rangle \\\\\n        \\langle\\psi_2^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_2^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_2^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_2^0|\\bm{H}| \\psi_n^0 \\rangle \\\\\n        \\vdots \\\\\n        \\langle\\psi_n^0|\\bm{H}| \\psi_1^0 \\rangle & \\langle\\psi_n^0|\\bm{H}| \\psi_2^0 \\rangle &\\langle\\psi_n^0|\\bm{H}| \\psi_3^0 \\rangle & \\cdots & \\langle\\psi_n^0|\\bm{H}| \\psi_n^0 \\rangle \n        \\end{bmatrix}\n        \\begin{bmatrix}\n        c_{i1} \\\\ c_{i2} \\\\ \\vdots \\\\ c_{in}\n        \\end{bmatrix} \n        = \\lambda_{i}\n        \\begin{bmatrix}\n        c_{i1} \\\\ c_{i2} \\\\ \\vdots \\\\ c_{in}\n        \\end{bmatrix} \n\\end{equation}\nSimply written as\n\\begin{equation}\n\\label{eigprob}\n        K\\textbf{c}_{i} = \\lambda_{i}\\textbf{c}_{i}\n\\end{equation}\nTherefore, to find $c_{ij}$, which can assemble $\\{| \\psi_i\\rangle\\}$ by $\\{| \\psi_i^0\\rangle\\}$, turns out to be a eigenvalue problem as shown in equation (\\ref{eigprob}).\n\\end{definition}\n\n\\begin{definition}[Matrix elements of K]\n\\begin{equation}\n        K_{ij} = \\langle \\psi_i^0 | \\textbf{H}^0 + \\textbf{H}^D | \\psi^0_j \\rangle = \\lambda_i^0 \\delta_{ij} + \\langle \\psi_i^0 | \\textbf{H}^D |\\psi^0_j \\rangle\n\\end{equation}\nRecall that\n\\begin{align*}\n        \\textbf{H}^D = - \\eta(x)\\frac{\\partial^2}{\\partial x^2} + \\frac{1}{2}\\eta(x)\\frac{d F(x)}{dx} + \\frac{1}{4} \\eta(x) F^{2}(x) - \\frac{\\partial \\eta(x)}{\\partial x} \\frac{\\partial}{\\partial x} + \\frac{1}{2} \\frac{\\partial \\eta(x)}{\\partial x} F(x)\n\\end{align*}\n$\\langle \\psi_i^0 | \\textbf{H}^D |\\psi^0_j \\rangle$ would becomes five terms\n\\begin{align}\n        &-\\int \\psi_i^0(x) \\eta(x)\\frac{\\partial^2 \\psi^0_j(x)}{\\partial x^2} dx \\\\\n        &\\frac{1}{2} \\int \\eta(x)\\frac{d F(x)}{dx} \\psi_i^0(x) \\psi^0_j(x) dx \\\\\n        &\\frac{1}{4} \\int \\eta(x) F^{2}(x) \\psi_i^0(x) \\psi^0_j(x) dx \\\\\n        &-\\int \\psi_i^0(x) \\frac{\\partial \\eta(x)}{\\partial x} \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx \\\\\n        &\\frac{1}{2} \\int \\frac{\\partial \\eta(x)}{\\partial x} F(x) \\psi_i^0(x) \\psi^0_j(x) dx\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[Integration by parts]\nIf $u=u(x)$ and $du=u'(x)dx$, while $v=v(x)$ and $dv=v'(x)dx$\n\\begin{align*}\n        \\int _{a}^{b}u(x)v'(x) dx = {\\Big [}u(x)v(x){\\Big ]}_{a}^{b}-\\int _{a}^{b}u'(x)v(x)dx\n\\end{align*}        \n\\end{definition}\n\n\\begin{definition}[Term 1]\n\\begin{align*}\n        u(x) &= \\psi_i^0(x) \\eta(x)  \\\\\n        v'(x) &= \\frac{\\partial^2 \\psi^0_j(x)}{\\partial x^2}\n\\end{align*}\nso \n\\begin{align*}\n        u'(x) &= \\frac{\\partial \\psi_i^0(x)}{\\partial x} \\eta(x) + \\psi_i^0(x) \\frac{\\partial \\eta(x)}{\\partial x} \\\\\n        v(x) &= \\frac{\\partial \\psi^0_j(x)}{\\partial x}\n\\end{align*}\nTherefore\n\\begin{align*}\n        -\\int_a^b \\psi_i^0(x) \\eta(x)\\frac{\\partial^2 \\psi^0_j(x)}{\\partial x^2} dx &=  -{\\Big [}  \\eta(x) \\psi_i^0(x) \\frac{\\partial \\psi^0_j(x)}{\\partial x} {\\Big ]}_{a}^{b} \\\\\n        &+ \\int_a^b  \\eta(x) \\frac{\\partial \\psi_i^0(x)}{\\partial x} \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx + \\int_a^b \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i^0(x)   \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx\n\\end{align*}\nand because $\\frac{\\partial \\psi^0_j(a)}{\\partial x}=0$ and $\\frac{\\partial \\psi^0_j(b)}{\\partial x}=0$, we get \n\\begin{equation}\n        -\\int_a^b \\psi_i^0(x) \\eta(x)\\frac{\\partial^2 \\psi^0_j(x)}{\\partial x^2} dx =  \\int_a^{b} \\eta(x) \\frac{\\partial \\psi_i^0(x)}{\\partial x} \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx + \\int_a^b \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i^0(x)   \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Collecting Together]\nCollecting the first term in the above and the other terms together, we get\n\\begin{align*}\n        \\langle \\psi_i^0 | \\textbf{H}^D |\\psi^0_j \\rangle &=  \\int  \\eta(x) \\frac{\\partial \\psi_i^0(x)}{\\partial x} \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx + \\int \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i^0(x) \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx \\\\\n        &+\\frac{1}{2} \\int \\eta(x)\\frac{d F(x)}{dx} \\psi_i^0(x) \\psi^0_j(x) dx + \\frac{1}{4} \\int \\eta(x) F^{2}(x) \\psi_i^0(x) \\psi^0_j(x) dx \\\\\n        &-\\int \\frac{\\partial \\eta(x)}{\\partial x} \\psi_i^0(x)  \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx + \\frac{1}{2} \\int \\frac{\\partial \\eta(x)}{\\partial x} F(x) \\psi_i^0(x) \\psi^0_j(x) dx\n\\end{align*}\nThe final form is \n\\begin{equation}\n\\begin{split}\n        \\langle \\psi_i^0 | \\textbf{H}^D |\\psi^0_j \\rangle &= \\int  \\eta(x) \\frac{\\partial \\psi_i^0(x)}{\\partial x} \\frac{\\partial \\psi^0_j(x)}{\\partial x} dx + \\frac{1}{2} \\int \\eta(x)\\frac{d F(x)}{dx} \\psi_i^0(x) \\psi^0_j(x) dx \\\\ \n        &+ \\frac{1}{4} \\int \\eta(x) F^{2}(x) \\psi_i^0(x) \\psi^0_j(x) dx + \\frac{1}{2} \\int \\frac{\\partial \\eta(x)}{\\partial x} F(x) \\psi_i^0(x) \\psi^0_j(x) dx\n\\end{split}\n\\end{equation}\n\\end{definition}\n\\begin{center}\n        \\includegraphics[scale=0.5]{ch1/H0_H_eigenbasis_test.pdf} \n\\end{center}", "meta": {"hexsha": "b5cc8adc644bb87672fceb6a5a196bb3182c0fe6", "size": 47776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/chapter1.tex", "max_stars_repo_name": "yizaochen/em_theory", "max_stars_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/chapter1.tex", "max_issues_repo_name": "yizaochen/em_theory", "max_issues_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/chapter1.tex", "max_forks_repo_name": "yizaochen/em_theory", "max_forks_repo_head_hexsha": "a9260f17ff59d7a265dd9e629607376b8d909ae6", "max_forks_repo_licenses": ["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.6497297297, "max_line_length": 419, "alphanum_fraction": 0.5898777629, "num_tokens": 19044, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6742936307059694}}
{"text": "% !TeX spellcheck = en_US\n\\section{SAT into CSP encodings}\\label{sec:sat_to_csp}\nIn this section, we discuss the opposite direction by introducing several ways for encoding SAT into CSP and briefly summarize the pros and cons of each encoding.\n\n\\subsection{Dual encoding}\nFor each clause in the CNF-formatted SAT a CSP variable is generated. The domain of each variable consists of the possible truth assignments that satisfies the corresponding clause expressed as a tuple. Any two clauses sharing the same propositional variable must also have a binary constraint between their respective dual variables. These constraints assure consistent assignment of the common propositional variable such that no variable is assigned two different values at the same time. \n\nThe following example shows how we could encode a SAT problem with two clauses and one common propositional variable. Considering the clauses: $x_1 \\vee x_2$ and $x_3 \\vee \\neg x_2$. The first clause results in the dual variable $D_1$ with the domain $\\{(T,T),(T,F),(F,T)\\}$ where $T$ and $F$ represent the truth value of the corresponding Boolean variable at the respective position within the tuple. The second clause results in $D_2 \\in \\{(T,F),(T,T),(F,F)\\}$. Since $x_2$ appears in both clauses, we must ensure that it will not have different values in each variable through the binary constraint: $D_1[2] = \\neg D_2[2]$ which assures that the second element of the tuple assigned to $D_1$ is the inverse of the second element of the $D_2$ tuple.\n\n\\subsubsection{Theoretical comparison}\nIt has been proven \\cite{walsh2000sat} that FC on the dual encoded SAT instance does more work than DPLL on the original problem. The proof is based on the fact that a truth assignment under unit propagation in DPLL implies an elimination of contradictory values on the CSP side. By induction, we can see that generating the empty clause in DPLL (which indicates that the problem is unsatisfiable regarding the current branch) implies a domain wipe out after applying arc-consistency by FC.\n\n\\subsection{Hidden variable encoding}\nJust like dual encoding, the hidden variable encdoing assign a dual variable for each SAT clause. Furthermore, each propositional variable $x_i$ is simulated on the CSP side with a binary variable $X_i \\in \\{T,F\\}$. This encoding allows constraints to be easily formulated in terms of thier binary variables. For example the clause $x_1 \\vee \\neg x_2$ results in one dual variable $D_1 \\in \\{(T,F),(F,F),(T,T)\\}$ and two binary CSP variables $X_1, X_2$ and additionally the coupling constraints $D_1[1] = x_1$ and $D_1[2] = \\neg x_2$ which constraints any assignment of the elements of the tuple assigned to $D_1$ to be consistent with the propositional variables $x_1,x_2$ represented by their CSP counterparts $X_1,X_2$.\n\n\\subsubsection{Theoretical comparison}\nThe hidden variable encoding maintain equivalent relation between assigning truth values committed by one literal rule on the DPLL side and eliminating contradictory values by enforcing arc-consistency by FC/MAC on the node level. This translates to equivalence relation between generating empty clauses and empty domain \\cite{walsh2000sat}. This in turn means that DPLL will essentially branch in general as much as FC/MAC applied to the encoded version of the same problem, and the same amount of work is expected by each algorithm.\n\n\\subsection{Literal encoding}\nThe literal encoding express each clause as a variable with a domain consisting of propositional variables' values that satisfy the corresponding clause. Constraints are required between any CSP variables if and only if their domains contain contradictory propositional variables. For example the clauses $x_1 \\vee x_2$ and $x_3 \\vee \\neg x_2$ can be expressed as the following variables $D_1 \\in \\{x_1, x_2\\}, D_2 \\in \\{x_3, \\neg x_2\\}$ and the constraint $\\neg (D_1 = x_2 \\wedge D_2 = \\neg x_2)$ which rules out the inconsistent assignment for $x_2$.\n\n\\subsubsection{Theoretical comparison}\nThis encoding shows similar results as the hidden variable encoding regarding the relation between generating the empty clause and empty domains as a result of enforcing arc-consistency. Anyway MAC is \\textit{strictly} dominated by DPLL applied to the original problem. Strictness can be proved easily by contradiction. Consider any unsatisfiable $k-$SAT instance (i.e. a SAT problem with $k$ propositional variable) with $2^k$ clauses where $k > 2$. DPLL needs $2^{k-1}$ branch to arrive at the empty clause while MAC takes $k!$ branches regardless of the used heuristics \\cite{walsh2000sat}.\n\n\\subsubsection{Advantage of literal encoding}\nCSP domain size can have great impact on the performance of any arc-consistency based algorithm (like MAC or FC) and must be taken into consideration. Let $n$ be the number of SAT clauses. Dual and hidden variable encodings generate CSP instance with domain size in the order of $\\mathcal{O}(2^n)$ while the literal encoding generate CSP instances with domain size of $\\mathcal{O}(n)$ which means general performance improvement over dual and hidden variable encodings.\n ", "meta": {"hexsha": "857658148f2138ebaf42fdf2cb4e09c87e14d275", "size": 5122, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sat_to_csp.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": "sat_to_csp.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": "sat_to_csp.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": 189.7037037037, "max_line_length": 751, "alphanum_fraction": 0.7926591175, "num_tokens": 1193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6742936265322776}}
{"text": "\\chapter{Potential Formulation and Radiation}\n\\section{Scalar and vector potentaial}\nMaxwell's equations are\n\\begin{enumerate}[label=(\\roman*)]\n\t\\item $\\boldsymbol{\\nabla} \\cdot \\mathbf{E}=\\frac{1}{\\epsilon_{0}} \\rho$\n\t\\item $\\boldsymbol{\\nabla} \\times \\mathbf{E}=-\\frac{\\partial \\mathbf{B}}{\\partial t}$\n\t\\item $\\boldsymbol{\\nabla} \\cdot \\mathbf{B}=0$\n\t\\item $\\boldsymbol{\\nabla} \\times \\mathbf{B}=\\mu_{0} \\mathbf{J}+\\mu_{0} \\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}$\n\\end{enumerate}\nIf $\\rho(r,t)$ and $J(r,t)$ are bnown electric and magnetic field can be find out using Gauss's law and Bio-savart law.It is difficult to find E ans B if they are time dependant.To solve this problem first we are going to represents the fields in terms of potentials electric potential V and magnetic potential B.\\\\\nIn the static case $\\nabla \\times \\mathbf{E}=0$ So electric field cane written as a negative gradient of some scalar quandity called electric potential V\\\\\n$$E=-\\nabla V$$(not possible in elctrodynamics)\\\\\nBut $\\nabla \\cdot B=0$ always.Which gives \\\\\n$$B=\\nabla\\times A$$\n Where A is the magnetic vector potential.Putting this value in \n$$\\boldsymbol{\\nabla} \\times \\mathbf{E}=-\\frac{\\partial \\mathbf{B}}{\\partial t}$$\nWe will get \\\\\n$$\\nabla \\times \\mathbf{E}=\\frac{-\\partial }{\\partial t}(\\nabla \\times A)$$\n$$\\nabla \\times \\left( \\mathbf{E}+\\frac{\\partial A}{\\partial t}\\right) =0$$\nAgain the curl of something become zero. so it can be written as negative gradient of potential\n$$\\mathbf{E}+\\frac{\\partial A}{\\partial t}=-\\nabla V$$\n$$\\mathbf{E}=-\\nabla V-\\frac{\\partial A}{\\partial t}$$\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][3cm]{3cm}{\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$$\\mathbf{B}=\\nabla\\times A$$\\\\\n\t\t\t$$\\mathbf{E}=-\\nabla V-\\frac{\\partial A}{\\partial t}$$\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\nIf A and V are known we can find electric and magnetic field with these two equations.\n\nPutting this equation $$\\mathbf{E}=-\\nabla V-\\frac{\\partial A}{\\partial t}$$  in Gauss's law\nwe will get,\\\\\n$$\\nabla ^2V+\\frac{\\partial }{\\partial t}(\\nabla \\cdot A)=\\frac{-\\rho}{\\epsilon_{0}}$$\nPutting $\\mathbf{B}=\\nabla\\times A$  equation in Ampere/Maxwell's law and rearranging we will get,\\\\\n$$\\left( \\nabla^2A-\\mu_{0}\\epsilon_{0}\\frac{\\partial^2 A}{\\partial t^2}\\right) -\\nabla\\left( \\nabla \\cdot A+\\mu_{0}\\epsilon_{0}\\frac{\\partial V}{\\partial t}\\right) =-\\mu_{0} J$$ \n\nThese two equations contain all information in the Maxwell's equations.\\\\\nHowever we have succeeded in reducing six problems to find E and B ,down to four(V one component,A three component.),these equations are lengthy and difficult to find solution we have to abandon this potential formulation altogether.\\\\\n\\paragraph{Gauge transformation}\nTo avoid this problem we are transforming the potential equations by adding one extra term to A and V.This is called gauge tranformation.Consider the transformation occuring in the same fields E and B.Then\\\\\n$$A^{\\prime}=A+\\alpha$$ and\n$$V^{\\prime}=V+\\beta$$\nTaking curl on each side of $A^{\\prime}=A+\\alpha$\nwe will get \n$$\\nabla \\times A^{\\prime}=\\nabla \\times A+\\nabla \\times \\alpha$$\nSince B's are same we can written as($\\nabla \\times B=0,A^{\\prime}=A$) \\\\\n$$\\nabla \\times \\alpha =0$$\nAgain curl of $\\alpha$ is zero.then\\\\\n$$\\alpha=\\nabla \\lambda$$\\\\\nThe two potentials also gives the same E.so,\\\\\n$$\\nabla \\beta +\\frac{\\partial \\alpha }{\\partial t}=0$$\n$$\\nabla\\left( \\beta+\\frac{\\partial \\lambda}{\\partial t}\\right) =0$$\n$$\\beta= -\\frac{\\partial \\lambda}{\\partial t}$$\nNow transformations become,\\\\\n\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][3cm]{3cm}{\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 $$A^{\\prime}=A+\\nabla \\lambda$$\\\\\n\t\t\t $$V^{\\prime}=V-\\frac{\\partial \\lambda}{\\partial t}$$\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n\\subsection{Coulomb Gauge and Lorentz gauge}\n\\paragraph{Coluomb gauge}\n$$\\nabla \\cdot A=0$$ is called Coulomb gauge.\\\\\n\\paragraph{importance}\n$$\\nabla \\cdot A=0$$ Then the equation \n$$\\nabla ^2V+\\frac{\\partial }{\\partial t}(\\nabla \\cdot A)=\\frac{-\\rho}{\\epsilon_{0}}$$ become,\\\\\n$$\\nabla^2 V=\\frac{-\\rho}{\\epsilon_{0}}$$\nThis is poisson's equation.From this equation V can be findout by using the formula\\\\\n$$V(r,t)=\\frac{1}{4 \\pi \\epsilon_0}\\int \\frac{\\rho(r^{\\prime},t)}{r}d\\tau^{\\prime}$$\nV is easy to get but to find E we need  A also($E=-\\nabla V-\\frac{\\partial A}{\\partial t}$) which is difficult.\n\\paragraph{Advantage of the coulomb gauge is that the scalar potential is simply to calculate .The disadvatage is that  A is particularly difficult to calculate. }\nAfter applying coulomb gauge to the equation \n$$\\left( \\nabla^2A-\\mu_{0}\\epsilon_{0}\\frac{\\partial^2 A}{\\partial t^2}\\right) -\\nabla\\left( \\nabla \\cdot A+\\mu_{0}\\epsilon_{0}\\frac{\\partial V}{\\partial t}\\right) =-\\mu_{0} J$$ \nwe get\\\\\n$$\\left( \\nabla^2A-\\mu_{0}\\epsilon_{0}\\frac{\\partial^2 A}{\\partial t^2}\\right)=-\\mu_{0}J+\\mu_{0} \\epsilon_{0}\\nabla \\left( \\frac{\\partial V}{\\partial t}\\right) $$\n\\paragraph{Lorentz gauge}\n$$\\nabla \\cdot A =-\\mu_{0} \\epsilon_{0} \\frac{\\partial}{\\partial t}V$$\n\n is called the lorentz gauge.\\\\\n This designes to eliminate the middle term of the equation\n$$\\left( \\nabla^2A-\\mu_{0}\\epsilon_{0}\\frac{\\partial^2 A}{\\partial t^2}\\right) -\\nabla\\left( \\nabla \\cdot A+\\mu_{0}\\epsilon_{0}\\frac{\\partial V}{\\partial t}\\right) =-\\mu_{0} J$$\nWith lorentz gauge this equation become\n$$\\nabla^2A-\\mu_{0}\\epsilon_{0}\\frac{\\partial^2 A}{\\partial t^2}=-\\mu_{0} J$$\nWith lorentz gauge this equation \n$\\nabla ^2V+\\frac{\\partial }{\\partial t}(\\nabla \\cdot A)=\\frac{-\\rho}{\\epsilon_{0}}$\nbecomes\n$$\\nabla^2A-\\mu_{0}\\epsilon_{0}\\frac{\\partial^2 A}{\\partial t^2}=\\frac{-\\rho}{\\epsilon_{0}}$$\nThe virtue of the lorentz gauge is that it treats V and A on the same differential operator\n$$\\nabla^2-\\mu_{0} \\epsilon_{0}\\frac{\\partial ^2}{\\partial t^2}\\equiv \\square^2  $$\n is called d'Alembertian\\\\\nThen both equation become\\\\\n$$\\square^2V=\\frac{-\\rho}{\\epsilon_{0}}$$\n$$\\square^2A=-\\mu_{0} J$$\n\\section{Retarded Potentials}\n$$\\square^{2} V=-\\frac{1}{\\epsilon_{0}} \\rho, \\quad \\square^{2} \\mathbf{A}=-\\mu_{0} \\mathbf{J}$$\nIn static case these equation reduces to poisson's equations\n$$\\nabla^{2} V=-\\frac{1}{\\epsilon_{0}} \\rho, \\quad \\nabla^{2} \\mathbf{A}=-\\mu_{0} \\mathbf{J}$$\nwith solutions\n$$V(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\int \\frac{\\rho\\left(\\mathbf{r}^{\\prime}\\right)}{r} d \\tau^{\\prime}, \\quad \\mathbf{A}(\\mathbf{r})=\\frac{\\mu_{0}}{4 \\pi} \\int \\frac{\\mathbf{J}\\left(\\mathbf{r}^{\\prime}\\right)}{r} d \\tau^{\\prime}$$\n$r \\rightarrow$ distance from source point $\\vec{r}$ to the field point $r$.\\\\\nImagine a electromagnetic news travels at the speed of light. In non-static case therefore, it's not the status of source right now that matters but rather its condition at some earlier time $t_r$ (retarded time) when the message left.\\\\\nSince the message must travel a distance $r$ the delay is $r/c$\n$$t_{r}=t-r / c$$\n$\\therefore$ Potentials become\n$$V(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\int \\frac{\\rho\\left(\\mathbf{r}^{\\prime}\\right)}{r} d \\tau^{\\prime}, \\quad \\mathbf{A}(\\mathbf{r})=\\frac{\\mu_{0}}{4 \\pi} \\int \\frac{\\mathbf{J}\\left(\\mathbf{r}^{\\prime}\\right)}{r} d \\tau^{\\prime}$$\n$P(r^\\prime,t_r)$: charge density prevailed at point $r^\\prime$ at the retarded time $t_r$. Because the integrants are evaluated at the retarded time these are called retarded potentials.\\\\\nThe more distant parts of the charge distribution have earlier retarded times than nearby ones.\\\\\nIn calculating the Laplacian of $V(r,t)$\\\\\nThe integrand depends on $\\vec{r}$ in two places explicitly, in the denomenator $(r=|r-r^\\prime|)$ and implicitly through $t_r-t-r/c$ in neumerator \n\\begin{align*}\n\\nabla V&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int\\left[(\\nabla \\rho) \\frac{1}{r}+\\rho \\nabla\\left(\\frac{1}{2}\\right)\\right] d \\tau^{\\prime}\\\\\n\\nabla \\rho&=\\dot{\\rho} \\nabla t_{r}=-\\frac{1}{c} \\dot{\\rho} \\nabla r\\\\\n\\nabla r&=\\hat{r} \\text{ and } \\nabla \\left( \\frac{1}{r}\\right) =\\frac{-\\hat{r}}{r^2}\\\\\n\\nabla V&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int\\left[-\\frac{\\rho}{c} \\frac{\\hat{r}}{r}-\\rho \\frac{\\hat{\\varepsilon}}{r^{2}}\\right] d \\tau^{\\prime}\n\\intertext{Taking the divergence}\n\\nabla^{2} V&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int\\left\\{-\\frac{1}{c}\\left[\\frac{\\hat{\\imath}}{r} \\cdot(\\nabla \\dot{\\rho})+\\dot{\\rho} \\nabla \\cdot\\left(\\frac{\\hat{r}}{r}\\right)\\right]\\right.\n-\\left.-\\left[\\frac{\\hat{z}}{r^{2}} \\cdot(\\nabla \\rho)+\\rho \\nabla \\cdot\\left(\\frac{\\hat{\\varepsilon}}{r^{2}}\\right)\\right]\\right\\} d \\tau^{\\prime} .\\\\\n\\nabla \\dot{\\rho}&=-\\frac{1}{c} \\ddot{\\rho} \\nabla r=-\\frac{1}{c} \\ddot{\\rho} \\hat{r},\\quad \n\\nabla \\cdot\\left(\\frac{\\hat{r}}{r}\\right)=\\frac{1}{r^{2}} \n\\intertext{whereas}\n&\\nabla \\cdot\\left(\\frac{\\hat{r}}{r^{2}}\\right)=4 \\pi \\delta^{3}(r)\n\\intertext{So}\n\\nabla^{2} V&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int\\left[\\frac{1}{c^{2}} \\frac{\\ddot{\\rho}}{r}-4 \\pi \\rho \\delta^{3}(r)\\right] d \\tau^{\\prime}=\\frac{1}{c^{2}} \\frac{\\partial^{2} V}{\\partial t^{2}}-\\frac{1}{\\epsilon_{0}} \\rho(\\mathbf{r}, t)\\\\\n\\nabla^{2} V&=\\frac{1}{c^{2}} \\frac{\\partial^{2} V}{\\partial t^{2}}-\\frac{1}{\\epsilon_{0}} \\rho(\\mathbf{r}, t)\n\\intertext{retarded potential satisfies the inhomogeneous wave equation}\n\\end{align*}\n\\section{Jefimentro's Equations}\n\\begin{align*}\nV(r, t)&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\int \\frac{f\\left(r^{\\prime}, t_{1}\\right)}{r} d z^{\\prime},\\quad A(r, t)=\\frac{\\mu_{0}}{4 \\pi} \\int \\frac{J\\left(r^{\\prime}, t_{r}\\right)}{r} d r !\n\\intertext{It is in principle, a straight forward matter to determine the fields}\nE&=-\\nabla V-\\frac{\\partial A}{\\partial t}, B=\\nabla \\times A \\\\\\\\\nE(r, t)&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\int\\left[\\frac{\\rho\\left(r^{\\prime}, t_{1}\\right)}{x^{2}} \\hat{x}+\\right.\\left.\\frac{\\dot{p}\\left(r^{\\prime}, t_{1}\\right)}{c r} \\hat{x}-\\frac{\\ddot{j}\\left(r^{\\prime}, t_{1}\\right)}{c^{2} r}\\right] d \\tau^{\\prime}\n\\intertext{This is the time dependent generalization of couloumb's law. In static case the second term and third term drops out and the first term losed its dependence on $t_r$}\nB(r, t)&=\\frac{\\mu_{0}}{4 \\pi}\\int\\left[\\frac{J\\left(r^{\\prime}, f_{r}\\right)}{\\lambda^{2}}+\\frac{J\\left(r^{\\prime}, t_{r}\\right)}{c \\lambda}\\right]x r^2d z\n\\intertext{This is the time-denpendent generalzation of the Biot-savart law, to which it reduces in the static case.}\n\\end{align*}\n\\section{Poynting Theorem}\nIf there exist a continuous distribution of charge and current, the total rate of doing work by the fields in a finite volume $v$ is\n$$\\frac{d w}{d t}=\\int_{v} \\vec{\\j} \\cdot \\vec{E} d^{3} x$$\nThis power represent a convertion of electromagnetic energy to mechanical or thermal energy. It must be balanced by corresponding rate  of decrease of energy in the electromagnetic field within the volume $V$. We can use maxwell equations to express the above equation in other terms.\n\\begin{align*}\n\\int_{V} J \\cdot E d ^3 x&=\\int_{V}\\left[E \\cdot(\\nabla x H)-E \\cdot \\frac{\\partial D}{\\partial F}\\right] d{ }^{3} x\\\\\n\\text{using the vector identity}&\\\\\n\\nabla \\cdot(E \\times H)&=H \\cdot(\\nabla \\times \\mathbf{E})-E \\cdot(\\nabla \\times H)\\\\\n\\because \\quad \\int_{V} \\vec{J} \\cdot \\vec{E} d^{3} x&=-\\int_{V} \\bar{V} \\cdot(E \\times M)+E \\cdot \\frac{\\partial D}{\\partial t}+H \\cdot \\frac{\\partial B}{\\partial t} \\\\\n\\int_{V} \\vec{J} \\cdot \\vec{E} d^{3} x&=-\\int_{V}\\left[\\nabla \\cdot(E \\times H)+E \\cdot \\frac{\\partial D}{\\partial t}+H \\cdot \\frac{\\partial B}{\\partial t}\\right] d^{3} x\n\\end{align*}\n\\textbf{Assumptions}\\\\\n\\begin{enumerate}\n\t\\item The mactoscopic medium is lenear in its electric and magnetic properties, with negligible dispersion or losses.\n\t\\item The sum of work necessary to assemble  a static charge distribution and work required to get currents going represent the total deelectromagnetic energy density.\n\\end{enumerate}\n\\begin{align*}\nu&=\\frac{1}{2}(E \\cdot D+B \\cdot H)\\\\\n-\\int_{v} \\vec{J} \\cdot t^{2} d^{3} x&=\\int_{v}\\left[\\frac{\\partial u}{\\partial t}+\\nabla \\cdot(E \\times H)\\right] d^{3} x\n\\intertext{since the volume $V$ is arbitrary, this can be cast into the form of a differential contunuity equation or conservation law,}\n\\frac{\\partial u}{\\partial t}+\\nabla \\cdot s&=-j \\cdot E\\\\\n\\text{The vector $S$ representing }&\\text{energy flow is called the poynting vector}\\\\\nS&=E \\times H\\\\\n\\text{It has diamensions of }&\\frac{\\text{energy}}{\\text{area}\\times\\text{time}}\n\\end{align*}\n\\subsection{Poynting Theorem for Microscopic Fields}\nMatter is ultimately composed of charged particles, we can think of this rate of conversion of electromagnetic energy to machanical energy as the rate of increase of energy of charged particles per unit volume\\\\\nWe can interpret pointing's theorem for the microscopic fields (E.B) as a statement of conservation of energy of the combined system of particles and fields.\\\\\nLet $E_{mech}$ be the total energy of the particles within the volume $V$ assume no particles move out of the volume.\n$$\\frac{d E_{\\text {mech }}}{d t}=\\int_{v} \\vec{J} \\cdot \\vec{E} d^{3} x$$\nPoynting theorem express the conservation of energy for the combined system as\n$$\\frac{d E}{d t}=\\frac{d}{d t}\\left(E_{\\text {mech }}+E_{\\text {field }}\\right)=-\\oint_{s} \\vec{n} \\cdot \\vec{s} d a$$\nwhen the total field energy within $V$ is\n$$E_{\\text {field } }=\\int_{V} u d^{3} x=\\frac{\\varepsilon_{0}}{2} \\int_{V}\\left(E^{2}+c^{2} B^{2}\\right) d^{3} x$$\n\\section{Radiation From Moving Charges}\nAn accelerating or de-accelerating charge producess electro magnetic radiation.\n\\begin{align*}\n\\intertext{Produces $EM$ radiation in all direction. There is a $\\vec{E} and \\vec{B}$ assosiated with it }\n\\vec{S}&=\\frac{1}{\\mu_{0}}(\\vec{E} \\times \\vec{B})\\\\\n\\text{If $\\vec{E}$ and $\\vec{B}$ }&\\text{are function of time then $\\langle\\vec{S}\\rangle_{t}$ is average of $\\vec{S}$}\n\\end{align*}\n\\begin{itemize}\n\t\\item Total power radiated through it's surface:\n\t$$P(x)=\\oint_{S}\\langle\\vec{S}\\rangle \\cdot d \\vec{a}$$\n\t\\item Total power radiated through space:\n\t$$P=\\lim _{r \\rightarrow \\infty} P(r)$$\n\tFor $\\infty$ radius-we get total power radiated.\\\\\n\\end{itemize}\n\\textbf{When particle accelerating in $\\hat{z}$ direction}\\\\\nA charge $q$ with mass $m$ that is accelerating with acceleration $a$ along $z$ direction at point $P$ what will be $E$ and $B$.\\\\\nWhat will be dependense of $E$ and $B$ at $P$\n\\begin{align*}\n|\\vec{E}| \\propto &\\frac{q a \\sin \\theta}{r}\\\\\n|\\vec{B}| \\propto &\\frac{q \\operatorname{asin} \\theta}{r}\\\\\nI=|\\vec{S}| \\propto& \\frac{q^{2} a^{2} \\sin ^{2} \\theta}{r^{2}}\\text{dependence of intensity}\\\\\n\\text{If average }&\\text{pointing vector is given}\\\\\n\\langle\\vec{S}\\rangle&=\\frac{\\mu_{0} q^{2} a^{2}}{16 \\pi^{2} c}\\left(\\frac{\\sin ^{2} \\theta}{r^{2}}\\right) \\hat{r}\n\\end{align*}\n\\begin{itemize}\n\t\\item Along $z$-direction intensity is minimum $\\rightarrow 0$ ie there is no electro magnetic radiation in $z$ direction. \n\t\\item Maximum radiation will be in $x-y$ plane.\n\\end{itemize}\n\\section{Toral Power Radiated}\n\\begin{align*}\n\tP&=\\oint_{S}\\langle\\vec{s}\\rangle \\cdot d \\vec{a}\\\\\n\t&=\\int_{\\theta=0}^{\\pi} \\int_{\\phi=0}^{2 \\pi} \\frac{\\mu_{0} q^{2} a^{2}}{16 \\pi^{2} c}\\left(\\frac{\\sin ^{2} \\theta}{x^{2}}\\right) \\hat{r} \\cdot r^{2} \\sin \\theta d \\theta d \\phi \\hat{r}\\\\\n\t&=\\frac{\\mu 0 q^{2} a^{2}}{16 \\pi^{2} c} \\times 2 \\pi \\int_{0}^{\\pi} \\sin ^{3} \\theta d \\theta\\\\\n\t&=\\frac{\\mu_{0} q^{2} a^{2}}{4 N_{2} \\pi C} \\times 2 \\times \\frac{4}{3}\\\\\n\tp&=\\frac{\\mu_{0} q^{2} a^{2}}{6 \\pi c}\\\\\n\t\\text{Here $P$}&\\text{ is independent of $r$ }\n\t\\intertext{$\\therefore $ total power radiated through surface is the total power radiated in space. }\n\\end{align*}\n\\subsection{Direction of $\\vec{E}$}\n\\begin{enumerate}\n\t\\item $\\vec{E}$ is $\\perp^{r}$ to $\\vec{r}$\n\t\\item $\\vec{a}, \\vec{r}$ and $\\vec{E}$ lies in oneplanne\n\\end{enumerate}\nIf we know direction of $\\vec{E} $ we  can find direction of $\\vec{B}$ as $\\vec{E}\\times\\vec{B}$ is in the direction of energy flow\n\\begin{exercise}\n\tA non relativistic particle of mass $m$ and charge moving with velocity $\\vec{V}$ and acceleration $\\vec{a}$ emits radiation of intensity $I$. Another particle of mass $\\frac{m}{2}$ charge $2E$ velocity $\\frac{V}{2}$ emits radiation of intensity $16 \\ I$. Find the acceleration of second particle \n\\end{exercise}\n\\begin{answer}$\\left. \\right. $\\\\\n\\begin{tabular}{p{2cm}p{1cm}p{0.5cm}p{0.5cm}p{0.5cm}p{0.7cm}}\n\tParticle 1&m&e&$\\vec{v}$&a&I\\\\\\\\\n\tParticle 2&$\\frac{m}{2}$&2e&$\\frac{v}{2}$& &10 I\\\\\n\\end{tabular}\n\\begin{align*}\nI_{1} \\alpha &= \\frac{q_{1}^{2} a _1\\sin ^{2} \\theta}{r^{2}}\\\\\nI_{2} \\alpha &\\frac{a_{2}^{2} a_{2}^{2} \\sin ^{2} \\theta}{r^{2}}=16 I_{1}\\\\\n\\frac{I_{2}}{I_{1}}&=\\frac{q_{2}^{2} a_{2}^{2}}{q_{1} ^2 a_{1}^{2}}=\\frac{(2 e)^{2} a_{2}^{2}}{(e)^{2} a_{1}^{2}}=16\\\\\n\\frac{4 a_{2}^{2}}{a_{1}^{2}}&=16\\\\\na_{2}^{2}&=4 a_{1}{ }^{2}\\\\\na_{2}&=2 a_{1}\\\\\na_{2}&=2 a\n\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tAn electron de-accelerated at a constant rate starting from an initial velocity $u(u<<c)$ to $\\frac{u}{2}$ during which it travel a distance $d$. Find the total energy radiated in time $t$.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tp&=\\frac{\\mu_{0}q^2 a^2}{6\\pi C}\\text{total power radiated}\\\\\n\ta&=\\frac{\\frac{u}{2}-u}{t}=\\frac{-u}{2t}\\\\\n\ta^{2}&= \\frac{u^{2}}{4 t^{2}}\\\\\n\tp&=\\frac{\\mu_{0}e^2\\frac{u^2}{4t^2}}{6\\pi C}\\\\\n\t\\text{Total energy radiated }&p\\times t\\\\\n\tE&=\\frac{\\mu_{0}e^2a^2}{24 \\pi ct^2}\\times t=\\frac{\\mu_{0}e^2u^2}{24}\n\t\\end{align*}\n\\end{answer}\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-1\n\\end{abox}\n\\begin{enumerate}\n\t\\item  A For constant uniform electric and magnetic field $\\vec{E}=\\vec{E}_{0}$ and $\\vec{B}=\\vec{B}_{0}$, it is possible to choose a gauge such that the scalar potential $\\phi$ and vector potential $\\vec{A}$ are given by\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $\\phi=0$ and $\\vec{A}=\\frac{1}{2}\\left(\\vec{B}_{0} \\times \\vec{r}\\right)$\n\t\t\\task[\\textbf{B.}] $\\phi=-\\vec{E}_{0} \\cdot \\vec{r}$ and $\\vec{A}=\\frac{1}{2}\\left(\\vec{B}_{0} \\times \\vec{r}\\right)$\n\t\t\\task[\\textbf{C.}]  $\\phi=-\\vec{E}_{0} \\cdot \\vec{r}$ and $\\vec{A}=0$\n\t\t\\task[\\textbf{D.}] $\\phi=0$ and $\\vec{A}=-\\vec{E}_{0} t$\n\t\\end{tasks}\n\t\n\t\\item\tD A constant electric current $I$ in an infinitely long straight wire is suddenly switched on at $t=0$. The vector potential at a perpendicular distance $r$ from the wire is given by $\\vec{A}=\\frac{\\hat{k} \\mu_{0} I}{2 \\pi} \\ln \\left[\\frac{1}{r}\\left(c t+\\sqrt{c^{2} t^{2}-r^{2}}\\right)\\right]$. The electric field at a distance $r(<c t)$ is\n\t{\\exyear{NET/JRF(DEC-2011)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $\\frac{\\mu_{0} I}{2 \\pi t} \\frac{1}{\\sqrt{2}}(\\hat{i}-\\hat{j})$\n\t\t\\task[\\textbf{C.}] $\\frac{c \\mu_{0} I}{2 \\pi \\sqrt{c^{2} t^{2}-r^{2}}} \\frac{1}{\\sqrt{2}}(\\hat{i}+\\hat{j})$\n\t\t\\task[\\textbf{D.}] $-\\frac{c \\mu_{0} I}{2 \\pi \\sqrt{c^{2} t^{2}-r^{2}}} \\hat{k}$\n\t\\end{tasks}\n\t\\item D Consider an infinite conducting sheet in the $x y$-plane with a time dependent current density $K t \\hat{i}$, where $K$ is a constant. The vector potential at $(x, y, z)$ is given by $\\vec{A}=\\frac{\\mu_{0} K}{4 c}(c t-z)^{2} \\hat{i}$. The magnetic field $\\vec{B}$ is\n\t{\t\\exyear{NET/JRF(DEC-2012)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{\\mu_{0} K t}{2} \\hat{j}$\n\t\t\\task[\\textbf{B.}] $-\\frac{\\mu_{0} K z}{2 c} \\hat{j}$\n\t\t\\task[\\textbf{C.}] $-\\frac{\\mu_{0} K}{2 c}(c t-z) \\hat{i}$\n\t\t\\task[\\textbf{D.}] $-\\frac{\\mu_{0} K}{2 c}(c t-z) \\hat{j}$\n\t\\end{tasks}\n\t\\item C A current $I$ is created by a narrow beam of protons moving in vacuum with constant velocity $\\vec{u}$. The direction and magnitude, respectively of the Poynting vector $\\vec{S}$ outside the beam at a radial distance $r$ (much larger than the width of the beam) from the axis, are\n\t{\t\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\vec{S} \\perp \\vec{u}$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{2}}$\n\t\t\\task[\\textbf{B.}] $\\vec{S} \\|(-\\vec{u})$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{4}}$\n\t\t\\task[\\textbf{C.}] $\\vec{S} \\| \\vec{u}$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{2}}$\n\t\t\\task[\\textbf{D.}] $\\vec{S} \\| \\vec{u}$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{4}}$\n\t\\end{tasks}\n\t\\item\n\tC If the electric and magnetic fields are unchanged when the potential $\\vec{A}$ changes (in suitable units) according to $\\vec{A} \\rightarrow \\vec{A}+\\hat{r}$, where $\\vec{r}=r(t) \\hat{r}$, then the scalar potential $\\Phi$ must simultaneously change to\n\t{\t\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\Phi-r$\n\t\t\\task[\\textbf{B.}] $\\Phi+r$\n\t\t\\task[\\textbf{C.}] $\\Phi-\\partial \\mathrm{r} / \\partial t$\n\t\t\\task[\\textbf{D.}] $\\Phi+\\partial \\mathrm{r} / \\partial t$\n\t\\end{tasks}\n\t\\item\n\tA Let $(V, \\vec{A})$ and $\\left(V^{\\prime}, \\overrightarrow{A^{\\prime}}\\right)$ denote two sets of scalar and vector potentials, and $\\psi$ is a scalar function. Which of the following transformations leave the electric and magnetic fields (and hence Maxwell's equations) unchanged?\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\overrightarrow{A^{\\prime}}=\\vec{A}+\\nabla \\psi$ and $V^{\\prime}=V-\\frac{\\partial \\psi}{\\partial t}$\n\t\t\\task[\\textbf{B.}] $\\overrightarrow{A^{\\prime}}=\\vec{A}-\\nabla \\psi$ and $V^{\\prime}=V+2 \\frac{\\partial \\psi}{\\partial t}$\n\t\t\\task[\\textbf{C.}] $\\overrightarrow{A^{\\prime}}=\\vec{A}+\\nabla \\psi$ and $V^{\\prime}=V+\\frac{\\partial \\psi}{\\partial t}$\n\t\t\\task[\\textbf{D.}] $\\overrightarrow{A^{\\prime}}=\\vec{A}-\\nabla \\psi$ and $V^{\\prime}=V-\\frac{\\partial \\psi}{\\partial t}$\n\t\\end{tasks}\n\t\\item\n\tA 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{\t\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(2)\n\t\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\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\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\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\t\\end{tasks}\n\t\n\t\n\t\\item C The vector potential $\\vec{A}=k e^{-a t} r \\hat{r}$ (where $a$ and $k$ are constants) corresponding to an electromagnetic field is changed to $\\overrightarrow{A^{\\prime}}=-k e^{-a t} r \\hat{r}$. This will be a gauge transformation if the corresponding change $\\phi^{\\prime}-\\phi$ in the scalar potential is\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $a k r^{2} e^{-a t}$\n\t\t\\task[\\textbf{B.}] $2 a k r^{2} e^{-a t}$\n\t\t\\task[\\textbf{C.}] $-a k r^{2} e^{-a t}$\n\t\t\\task[\\textbf{D.}] $-2 a k r^{2} e^{-a t}$\n\t\\end{tasks}\n\t\\item A The charge distribution inside a material of conductivity $\\sigma$ and permittivity $\\in$ at initial time $t=0$ is $\\rho(r, 0)=\\rho_{0}$, a constant. At subsequent times $\\rho(r, t)$ is given by\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}]  $\\rho_{0} \\exp \\left(-\\frac{\\sigma t}{\\epsilon}\\right)$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2} \\rho_{0}\\left[1+\\exp \\left(\\frac{\\sigma t}{\\in}\\right)\\right]$\n\t\t\\task[\\textbf{C.}]  $\\frac{\\rho_{0}}{\\left[1-\\exp \\left(\\frac{\\sigma t}{\\epsilon}\\right)\\right]}$\n\t\t\\task[\\textbf{D.}] $\\rho_{0} \\cosh \\frac{\\sigma t}{\\in}$\n\t\\end{tasks}\n\t\\item  B The electric field $\\vec{E}$ and the magnetic field $\\vec{B}$ corresponding to the scalar and vector potentials, $V(x, y, z, t)=0$ and $\\vec{A}(x, y, z, t)=\\frac{1}{2} \\hat{k} \\mu_{0} A_{0}(c t-x)$, where $A_{0}$ is a constant, are \n\t{\\exyear{NET/JRF(JUNE-2018)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] (a) $\\vec{E}=0$ and $\\vec{B}=\\frac{1}{2} \\hat{j} \\mu_{0} A_{0}$\n\t\t\\task[\\textbf{B.}] $\\vec{E}=-\\frac{1}{2} \\hat{k} \\mu_{0} A_{0} c$ and $\\vec{B}=\\frac{1}{2} \\hat{j} \\mu_{0} A_{0}$\n\t\t\\task[\\textbf{C.}]  $\\vec{E}=0$ and $\\vec{B}=-\\frac{1}{2} \\hat{i} \\mu_{0} A_{0}$\n\t\t\\task[\\textbf{D.}] $\\vec{E}=\\frac{1}{2} \\hat{k} \\mu_{0} A_{0} c$ and $\\vec{B}=-\\frac{1}{2} \\hat{i} \\mu_{0} A_{0}$\n\t\\end{tasks}\n\\item D Which of the following transformations $(V, \\vec{A}) \\rightarrow\\left(V^{\\prime}, \\overrightarrow{A^{\\prime}}\\right)$ of the electrostatic potential $V$ and the vector potential $\\vec{A}$ is a gauge transformation?\n{\\exyear{ NET/JRF-(JUNE-2015)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\left(V^{\\prime}=V+a x, \\vec{A}^{\\prime}=\\vec{A}+a t \\hat{k}\\right)$\n\t\\task[\\textbf{b.}]$\\left(V^{\\prime}=V+a x, \\vec{A}^{\\prime}=\\vec{A}-a t \\hat{k}\\right)$\n\t\\task[\\textbf{c.}]$\\left(V^{\\prime}=V+a x, \\vec{A}^{\\prime}=\\vec{A}+a t \\hat{i}\\right)$\n\t\\task[\\textbf{d.}] $\\left(V^{\\prime}=V+a x, \\vec{A}^{\\prime}=\\vec{A}-a t \\hat{i}\\right)$\n\\end{tasks}\n\\item D Consider an infinite conducting sheet in the $x y$-plane with a time dependent current density $K t \\hat{i}$, where $K$ is a constant. The vector potential at $(x, y, z)$ is given by $\\vec{A}=\\frac{\\mu_{0} K}{4 c}(c t-z)^{2} \\hat{i}$. The magnetic field $\\vec{B}$ is\n{\\exyear{NET/JRF-(DEC-2012)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\mu_{0} K t}{2} \\hat{j}$\n\t\\task[\\textbf{b.}]$-\\frac{\\mu_{0} K z}{2 c} \\hat{j}$\n\t\\task[\\textbf{c.}] $-\\frac{\\mu_{0} K}{2 c}(c t-z) \\hat{i}$\n\t\\task[\\textbf{d.}]  $-\\frac{\\mu_{0} K}{2 c}(c t-z) \\hat{j}$\n\\end{tasks}\n\\item A For constant uniform electric and magnetic field $\\vec{E}=\\vec{E}_{0}$ and $\\vec{B}=\\vec{B}_{0}$, it is possible to choose a gauge such that the scalar potential $\\phi$ and vector potential $\\vec{A}$ are given by \n{\\exyear{NET/JRF-(JUNE-2011)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\phi=0$ and $\\vec{A}=\\frac{1}{2}\\left(\\vec{B}_{0} \\times \\vec{r}\\right)$\n\t\\task[\\textbf{b.}]$\\phi=-\\vec{E}_{0} \\cdot \\vec{r}$ and $\\vec{A}=\\frac{1}{2}\\left(\\vec{B}_{0} \\times \\vec{r}\\right)$\n\t\\task[\\textbf{c.}]$\\phi=-\\vec{E}_{0} \\cdot \\vec{r}$ and $\\vec{A}=0$\n\t\\task[\\textbf{d.}] $\\phi=0$ and $\\vec{A}=-\\vec{E}_{0} t$\n\\end{tasks}\n\\item C When a charged particle emits electromagnetic radiation, the electric field $\\vec{E}$ and the Poynting vector $\\vec{S}=\\frac{1}{\\mu_{0}} \\vec{E} \\times \\vec{B}$ at a larger distance $r$ from emitter vary as $\\frac{1}{r^{n}}$ and $\\frac{1}{r^{m}}$ respectively. Which of the following choices for $n$ and $m$ are correct?\n{\\exyear{ NET/JRF-(DEC-2012)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$n=1$ and $m=1$\n\t\\task[\\textbf{b.}] $n=2$ and $m=2$\n\t\\task[\\textbf{c.}]$n=1$ and $m=2$\n\t\\task[\\textbf{d.}] $n=2$ and $m=4$\n\\end{tasks}\n\\item A A non-relativistic particle of mass $m$ and charge $e$, moving with a velocity $\\vec{v}$ and acceleration $\\vec{a}$, emits radiation of intensity $I$. What is the intensity of the radiation emitted by a particle of mass $m / 2$, charge $2 e$, velocity $\\vec{v} / 2$ and acceleration $2 \\vec{a}$ ?\n{\\exyear{NET/JRF-(DEC-2014)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}] $16 I$\n\t\\task[\\textbf{b.}]$8 I$\n\t\\task[\\textbf{c.}]$4 I$\n\t\\task[\\textbf{d.}] $2 I$\n\\end{tasks}\n\\item D An electron is decelerated at a constant rate starting from an initial velocity $u$ (where $u<<c$ ) to $u / 2$ during which it travels a distance $s$. The amount of energy lost to radiation is\n{\\exyear{ NET/JRF-(JUNE-2017)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\mu_{0} e^{2} u^{2}}{3 \\pi m c^{2} s}$\n\t\\task[\\textbf{b.}]$\\frac{\\mu_{0} e^{2} u^{2}}{6 \\pi m c^{2} s}$\n\t\\task[\\textbf{c.}]$\\frac{\\mu_{0} e^{2} u}{8 \\pi m c s}$\n\t\\task[\\textbf{d.}] $\\frac{\\mu_{0} e^{2} u}{16 \\pi m c s}$\n\\end{tasks}\n\\item B In the region far from a source, the time dependent electric field at a point $(r, \\theta, \\phi)$ is\n$$\n\\vec{E}(r, \\theta, \\phi)=\\hat{\\phi} E_{0} \\omega^{2}\\left(\\frac{\\sin \\theta}{r}\\right) \\cos \\left[\\omega\\left(t-\\frac{r}{c}\\right)\\right]\n$$\nwhere $\\omega$ is angular frequency of the source. The total power radiated (averaged over a cycle) is\n{\\exyear{ NET/JRF-(JUNE-2018)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{2 \\pi}{3} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\t\\task[\\textbf{b.}]$\\frac{4 \\pi}{3} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\t\\task[\\textbf{c.}] $\\frac{4}{3 \\pi} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\t\\task[\\textbf{d.}] $\\frac{2}{3} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\\end{tasks}\n\\item B A dipole of moment $\\vec{p}$, oscillating at frequency $\\omega$, radiates spherical waves. The vector potential at large distance is\n$$\n\\vec{A}(\\vec{r})=\\frac{\\mu_{0}}{4 \\pi} i \\omega \\frac{e^{i k r}}{r} \\vec{p}\n$$\nTo order $\\left(\\frac{1}{r}\\right)$ the magnetic field $\\vec{B}$ at a point $\\vec{r}=r \\hat{n}$ is\n{\\exyear{ NET/JRF-(DEC-2015)}}\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\\item D An oscillating current $I(t)=I_{0} \\exp (-i \\omega t)$ flows in the direction of the $y$-axis through a thin metal sheet of area $1.0 \\mathrm{~cm}^{2}$ kept in the $x y$-plane. The rate of total energy radiated per unit area from the surfaces of the metal sheet at a distance of $100 \\mathrm{~m}$ is\n{\\exyear{ NET/JRF-(JUNE-2013)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$I_{0} \\omega /\\left(12 \\pi \\varepsilon_{0} c^{3}\\right)$\n\t\\task[\\textbf{b.}]$I_{0}^{2} \\omega^{2} /\\left(12 \\pi \\varepsilon_{0} c^{3}\\right)$\n\t\\task[\\textbf{c.}]$I_{0}^{2} \\omega^{3} /\\left(12 \\pi \\varepsilon_{0} c^{3}\\right)$\n\t\\task[\\textbf{d.}] $I_{0}^{2} \\omega^{4} /\\left(12 \\pi \\varepsilon_{0} c^{3}\\right)$\n\\end{tasks}\n\\item B An alternating current $I(t)=I_{0} \\cos (\\omega t)$ flows through a circular wire loop of radius $R$, lying in the $x y$-plane, and centered at the origin. The electric field $\\vec{E}(\\vec{r}, t)$ and the magnetic field $\\vec{B}(\\vec{r}, t)$ are measured at a point $\\vec{r}$ such that $r \\gg \\frac{c}{\\omega} \\gg R$, where $\\vec{r}=|\\vec{r}|$.\nWhich one of the following statements is correct?\n{\\exyear{ NET/JRF-(DEC-2019)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}] The time-averaged $|\\vec{E}(\\vec{r}, t)| \\propto \\frac{1}{r^{2}}$\n\t\\task[\\textbf{b.}]The time-averaged $|\\vec{E}(\\vec{r}, t)| \\propto \\omega^{2}$\n\t\\task[\\textbf{c.}]The time-averaged $|\\vec{B}(\\vec{r}, t)|$ as a function of the polar angle $\\theta$ has a minimum at $\\theta=\\frac{\\pi}{2}$\n\t\\task[\\textbf{d.}] $\\vec{B}(\\vec{r}, t)$ is along the azimuthal direction\n\\end{tasks}\n\\item  C A particle with charge $-q$ moves with a uniform angular velocity $\\omega$ in a circular orbit of radius $a$ in the $x y$ - plane, around a fixed charge $+q$, which is at the centre of the orbit at $(0,0,0)$. Let the intensity of radiation at the point $(0,0, R)$ be $I_{1}$ and at $(2 R, 0,0)$ be ' $I_{2}$ The ratio $\\frac{I_{2}}{I_{1}}$ for $R \\gg a$, is\n{\\exyear{NET/JRF-(DEC-2016)}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]4\n\t\\task[\\textbf{b.}]$\\frac{1}{4}$\n\t\\task[\\textbf{c.}]$\\frac{1}{8}$\n\t\\task[\\textbf{d.}]8 \n\\end{tasks}\n\\item A The phase difference between two small oscillating electric dipoles, separated by a distance $d$, is $\\pi$. If the wavelength of the radiation is $\\lambda$, the condition for constructive interference between the two dipolar radiations at a point $P$ when $r \\gg d$ (symbols are as shown in the figure and $n$ is an integer) is\n{\\exyear{NET/JRF-(DEC-2019)}}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.2cm,width=5cm]{ED21}\n\\end{figure}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$d \\sin \\theta=\\left(n+\\frac{1}{2}\\right) \\lambda$\n\t\\task[\\textbf{b.}]$d \\sin \\theta=n \\lambda$\n\t\\task[\\textbf{c.}] $d \\cos \\theta=n \\lambda$\n\t\\task[\\textbf{d.}] $d \\cos \\theta=\\left(n+\\frac{1}{2}\\right) \\lambda$\n\\end{tasks}\n\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{a} &2&\\textbf{d}\\\\\\hline \n\t\t3&\\textbf{d} &4&\\textbf{c} \\\\\\hline\n\t\t5&\\textbf{c} &6&\\textbf{a} \\\\\\hline\n\t\t7&\\textbf{a}&8&\\textbf{c}\\\\\\hline\n\t\t9&\\textbf{a}&10&\\textbf{b}\\\\\\hline\n\t\t11&\\textbf{d} &12&\\textbf{d}\\\\\\hline\n\t\t13&\\textbf{a}&14&\\textbf{c}\\\\\\hline\n\t\t15&\\textbf{a}&16&\\textbf{d} \\\\\\hline\n\t\t17&\\textbf{b}&18&\\textbf{b}\\\\\\hline\n\t\t19&\\textbf{d}&20&\\textbf{b}\\\\\\hline\n\t\t21&\\textbf{c} &22&\\textbf{a}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\\newpage\n\\begin{abox}\n\tPractise Set-2\n\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item  D The electric and the magnetic field $\\vec{E}(z, t)$ and $\\vec{B}(z, t)$, respectively corresponding to the scalar potential $\\phi(z, t)=0$ and vector potential $\\vec{A}(z, t)=\\hat{i} t z$ are\n\t\t\\exyear{GATE 2012}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\vec{E}=\\hat{i} z$ and $\\vec{B}=-\\hat{j} t$\n\t\t\\task[\\textbf{B.}]$\\vec{E}=\\hat{i} z$ and $\\vec{B}=\\hat{j t}$\n\t\t\\task[\\textbf{C.}]$\\vec{E}=-\\hat{i} z$ and $\\vec{B}=-\\hat{j t}$\n\t\t\\task[\\textbf{D.}]$\\vec{E}=-\\hat{i} z$ and $\\vec{B}=-\\hat{j} \\mathrm{t}$\n\t\\end{tasks}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item If the vector potential $\\vec{A}=\\alpha x \\hat{x}+2 y \\hat{y}-3 z \\hat{z}$, satisfies the Coulomb gauge, the value of the constant $\\alpha$ is\n\t\t\\exyear{GATE 2015}\n\t\\end{minipage}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item Consider magnetic vector potential $\\tilde{A}$ and scalar potential $\\Phi$ which define the magnetic field $\\vec{B}$ and electric field $\\vec{E}$. If one adds $\\vec{\\nabla} \\lambda$ to $\\vec{A}$ for a well-defined $\\lambda$, then what should be added to $\\Phi$ so that $\\vec{E}$ remains unchanged up to an arbitrary function of time, $f(t)$ ?\n\t\t\\exyear{JEST 2017}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{\\partial \\lambda}{\\partial t}$\n\t\t\\task[\\textbf{B.}]$-\\frac{\\partial \\lambda}{\\partial t}$\n\t\t\\task[\\textbf{C.}]$\\frac{1}{2} \\frac{\\partial \\lambda}{\\partial t}$\n\t\t\\task[\\textbf{D.}]$-\\frac{1}{2} \\frac{\\partial \\lambda}{\\partial t}$\n\t\\end{tasks}\n\t\\item A long straight wire, having radius $a$ and resistance per unit length $r$, carries a current $I$. The magnitude and direction of the Poynting vector on the surface of the wire is\n\t{\\exyear{GATE 2018}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $I^{2} r / 2 \\pi a$, perpendicular to axis of the wire and pointing inwards\n\t\t\\task[\\textbf{B.}]$I^{2} r / 2 \\pi a$, perpendicular to axis of the wire and pointing outwards\n\t\t\\task[\\textbf{C.}]$I^{2} r / \\pi a$, perpendicular to axis of the wire and pointing inwards\n\t\t\\task[\\textbf{D.}]$I^{2} r / \\pi a$, perpendicular to axis of the wire and pointing outwards\n\t\\end{tasks}\n\\item D An electromagnetic field is given by\n$$\n\\vec{E}(\\vec{r}, t)=-\\frac{1}{4 \\pi \\in_{0}} \\frac{q}{r^{2}} \\theta(v t-r) \\dot{r}, \\quad \\vec{B}(\\vec{r}, t)=0\n$$\nwhere $\\theta(x)= \\begin{cases}1 & \\text { for } x>0 \\\\ 0 & \\text { for } x \\leq 0\\end{cases}$\nThe corresponding charge density $\\rho$ and current density $\\vec{J}$ are given by\n{\\exyear{ JEST-2020}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\rho=-q \\delta^{3}(\\vec{r}) \\theta(v t-r)+\\frac{q}{4 \\pi r^{2}} \\theta(v t-r) ; \\vec{J}=0$\n\t\\task[\\textbf{b.}]$\\rho=-q \\delta^{3}(\\vec{r}) \\theta(v t-r) ; \\vec{J}=0$\n\t\\task[\\textbf{c.}]$\\rho=\\frac{q}{4 \\pi r^{2}} \\delta(v t-r) ; \\vec{J}=\\frac{q v}{4 \\pi r^{2}} \\delta(v t-r) \\hat{r}$\n\t\\task[\\textbf{d.}] $\\rho=-q \\delta^{3}(\\vec{r}) \\theta(v t-r)+\\frac{q}{4 \\pi r^{2}} \\delta(v t-r) ; \\vec{J}=\\frac{q v}{4 \\pi r^{2}} \\delta(v t-r) \\hat{r}$\n\\end{tasks}\n\\item A Consider magnetic vector potential $\\vec{A}$ and scalar potential $\\Phi$ which define the magnetic field $\\vec{B}$ and electric field $\\vec{E}$. If one adds $-\\vec{\\nabla} \\lambda$ to $\\vec{A}$ for a well-defined $\\lambda$, then what should be added to $\\Phi$ so that $\\vec{E}$ remains unchanged up to an arbitrary function of time, $f(t)$ ?\n{\\exyear{ JEST-2017}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\partial \\lambda}{\\partial t}$\n\t\\task[\\textbf{b.}]$-\\frac{\\partial \\lambda}{\\partial t}$\n\t\\task[\\textbf{c.}] $\\frac{1}{2} \\frac{\\partial \\lambda}{\\partial t}$\n\t\\task[\\textbf{d.}]  $-\\frac{1}{2} \\frac{\\partial \\lambda}{\\partial t}$\n\\end{tasks}\n\\item C 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{\\exyear{ JEST-2013}}\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\\item A An electron is executing simple harmonic motion along the $y$-axis in right handed coordinate system. Which of the following statements is true for emitted radiation?\n{\\exyear{ JEST-2014}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]The radiation will be most intense in $x z$ plane\n\t\\task[\\textbf{b.}] The radiation will be most intense in $x y$ plane\n\t\\task[\\textbf{c.}]The radiation will violate causality\n\t\\task[\\textbf{d.}] The electron's rest mass energy will reduce due to radiation loss\n\\end{tasks}\n\\end{enumerate}\n\n\n\n\\newpage\n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}\n\t\\item The vector potential $\\vec{A}=3 k e^{-a t} r \\hat{r}$ (where $a$ and $k$ are constants) corresponding to an electromagnetic field is changed to $\\vec{A}^{\\prime}=-3 k e^{-a t} r \\hat{r}$. Under gauge transformation find the corresponding change $\\phi^{\\prime}-\\phi$ in the scalar potential.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { Gauge Transformation } \\vec{A}^{\\prime}&=\\vec{A}+\\vec{\\nabla} \\lambda, \\phi^{\\prime}=\\phi-\\frac{\\partial \\lambda}{\\partial t}\\\\\n\t\t\\vec{A}-\\vec{A}&=-6 k e^{-a t} r \\hat{r}=\\vec{\\nabla} \\lambda=\\frac{\\partial \\lambda}{\\partial r} \\hat{r} \\\\\n\t\t\\Rightarrow \\lambda&=-3 k e^{-a t} r^{2} \\Rightarrow \\frac{\\partial \\lambda}{\\partial t}=3 k a e^{-a t} r^{2} \\Rightarrow \\phi^{\\prime}-\\phi=-\\frac{\\partial \\lambda}{\\partial t}=-3 k a e^{-a t} r^{2}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item If the electric and magnetic fields are unchanged when the potential $\\vec{A}$ changes (in suitable units) according to $\\vec{A} \\rightarrow \\vec{A}+2 \\hat{r}$, then the scalar potential $\\Phi$ must simultaneously change to $\\Phi^{\\prime}$. Then find $\\Phi^{\\prime}$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\overrightarrow{A^{\\prime}}&=\\vec{A}+\\vec{\\nabla} \\lambda=\\vec{A}+\\hat{r} \\Rightarrow \\partial \\lambda / \\partial r=2 \\Rightarrow \\lambda=2 r+C\\\\\n\t\t\\Phi^{\\prime}&=\\Phi-\\partial \\lambda / \\partial t=\\Phi-2 \\partial r / \\partial t\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A dipole is oscillating in z-direction such that the retarded potentials are\n\t$$\n\tV(r, \\theta, t)=\\frac{p_{0} \\cos \\theta}{4 \\pi \\varepsilon_{0} r}\\left\\{-\\frac{\\omega}{c} \\sin \\omega\\left(t-\\frac{r}{c}\\right)+\\frac{1}{r} \\cos \\omega\\left(t-\\frac{r}{c}\\right)\\right\\}\n\t$$\n\tand $\\vec{A}(r, \\theta, t)=-\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi r} \\sin \\left[\\omega\\left(t-\\frac{r}{c}\\right)\\right] \\hat{z}$\n\twhere $r$ and $\\theta$ are usual spherical polar coordinate.\n\tCheck that they satisfy the Lorentz gauge condition.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t&\\text { Lets check }\\text{Lorentz gauge condition } \\vec{\\nabla} \\cdot \\vec{A}=-\\mu_{0} \\varepsilon_{0} \\frac{\\partial V}{\\partial t} \\text {. }\\\\\n\t\t&\\text { In spherical}\\text{ polar coordinate system }\\\\\n\t\t&\\vec{A}(r, \\theta, t)=-\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi r} \\sin \\left[\\omega\\left(t-\\frac{r}{c}\\right)\\right](\\cos \\theta \\hat{r}-\\sin \\theta \\hat{\\theta})\\\\\n\t\t\\vec{\\nabla} \\cdot \\vec{A}&=\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left[r^{2} \\times-\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi r} \\sin \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta\\right]+\\frac{1}{r \\sin \\theta} \\frac{\\partial}{\\partial \\theta}\\left[\\sin \\theta \\times-\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi r} \\sin \\omega\\left(t-\\frac{r}{c}\\right) \\sin \\theta\\right] \\\\\n\t\t\\vec{\\nabla} \\cdot \\vec{A}&=-\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi} \\frac{1}{r^{2}}\\left[\\sin \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta-\\frac{\\omega r}{c} \\cos \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta\\right]-\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi} \\frac{1}{r^{2}}\\left[2 \\cos \\theta \\times \\sin \\omega\\left(t-\\frac{r}{c}\\right)\\right] \\\\\n\t\t\\vec{\\nabla} \\cdot \\vec{A}&=\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi} \\frac{1}{r^{2}}\\left[\\sin \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta+\\frac{\\omega r}{c} \\cos \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta\\right] \\\\\n\t\t&\\because V(r, \\theta, t)=\\frac{p_{0} \\cos \\theta}{4 \\pi \\varepsilon_{0} r}\\left\\{-\\frac{\\omega}{c} \\sin \\omega\\left(t-\\frac{r}{c}\\right)+\\frac{1}{r} \\cos \\omega\\left(t-\\frac{r}{c}\\right)\\right\\}\\\\\n\t\t&\\Rightarrow \\frac{\\partial V}{\\partial t}=\\frac{p_{0} \\cos \\theta}{4 \\pi \\varepsilon_{0} r}\\left\\{-\\frac{\\omega^{2}}{c} \\cos \\omega\\left(t-\\frac{r}{c}\\right)-\\frac{\\omega}{r} \\sin \\omega\\left(t-\\frac{r}{c}\\right)\\right\\} \\\\\n\t\t&\\Rightarrow-\\mu_{0} \\varepsilon_{0} \\frac{\\partial V}{\\partial t}=\\frac{\\mu_{0} p_{0} \\omega}{4 \\pi \\varepsilon_{0} r^{2}}\\left\\{\\sin \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta+\\frac{\\omega r}{c} \\cos \\omega\\left(t-\\frac{r}{c}\\right) \\cos \\theta\\right\\} \\\\\n\t\t&\\Rightarrow \\vec{\\nabla} \\cdot \\vec{A}=-\\mu_{0} \\varepsilon_{0} \\frac{\\partial V}{\\partial t}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \\textbf{(a)} An Infinite straight wire carries a linearly increasing current $I(t)=k t$, for $t>0$.\n\tFind the electric and magnetic fields generated.\\\\\n\t\\textbf{(b)} An Infinite straight wire carries a current $I(t)=q_{0} \\delta(t)$, for $t>0$.\n\tFind the scalar and vector potential. In both cases assume wire is electrically neutral.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { (a) For }& t<r / c, \\vec{A}=0 \\text {; for } t>r / c, \\vec{A}(r, t)=\\frac{\\mu_{0}}{4 \\pi} \\hat{z} \\int_{-\\infty}^{+\\infty} \\frac{I\\left(t_{r}\\right)}{R} d z\\\\\n\t\t\\text { where } R&=\\sqrt{r^{2}+z^{2}} \\text { and } t_{r}=t-\\frac{R}{c}\\\\\n\t\t\\vec{A}(r, t)&=\\left(\\frac{\\mu_{0}}{4 \\pi} \\hat{z}\\right) 2 \\int_{0}^{\\sqrt{(c t)^{2}-r^{2}}} \\frac{k\\left(t-\\sqrt{r^{2}+z^{2}} / c\\right)}{\\sqrt{r^{2}+z^{2}}} d z\\\\&=\\frac{\\mu_{0} k}{2 \\pi} \\hat{z}\\left\\{t \\int_{0}^{\\sqrt{(c t)^{2}-r^{2}}} \\frac{d z}{\\sqrt{r^{2}+z^{2}}}-\\frac{1}{c} \\int_{0}^{\\sqrt{(c t)^{2}-r^{2}}} d z\\right\\}\\\\\n\t\t\\Rightarrow \\vec{A}(r, t)&=\\left(\\frac{\\mu_{0} k}{2 \\pi} \\hat{z}\\right)\\left[t \\ln \\left(\\frac{c t+\\sqrt{(c t)^{2}-r^{2}}}{r}\\right)-\\frac{1}{c} \\sqrt{(c t)^{2}-r^{2}}\\right] \\text { and } V(r, t)=0\\\\\n\t\t\\text { (b) For } &t<r / c, \\quad \\vec{A}\\\\&=0 \\text {; for } t>r / c, \\quad \\vec{A}(r, t)=\\frac{\\mu_{0}}{4 \\pi} \\hat{z} \\int_{-\\infty}^{+\\infty} \\frac{I\\left(t_{r}\\right)}{R} d z\\\\\n\t\t\\text { where } R&=\\sqrt{r^{2}+z^{2}} \\text { and } t_{r}=t-\\frac{R}{c} \\text {. }\\\\\n\t\t\\vec{A}(r, t)&=\\frac{\\mu_{0}}{4 \\pi} \\hat{z} \\int_{-\\infty}^{\\infty} \\frac{q_{0} \\delta(t-R / c)}{R} d z \\Rightarrow \\vec{A}(r, t)=\\left(\\frac{\\mu_{0} q_{0}}{4 \\pi} \\hat{z}\\right) 2 \\int_{0}^{\\infty} \\frac{\\delta(t-R / c)}{R} d z\\\\\n\t\t\\text { Now } z&=\\sqrt{R^{2}-r^{2}} \\Rightarrow d z=\\frac{1}{2} \\frac{2 R d R}{\\sqrt{R^{2}-r^{2}}}-\\frac{R d R}{\\sqrt{R^{2}-r^{2}}} \\text {, and } z=0 \\Rightarrow R=r, z=\\infty \\Rightarrow R=\\infty\\\\\n\t\t\\text { So: } &\\quad \\vec{A}(r, t)=\\frac{\\mu_{0} q_{0}}{2 \\pi} \\hat{z} \\int_{r}^{\\infty} \\frac{1}{R} \\delta\\left(t-\\frac{R}{c}\\right) \\frac{R d R}{\\sqrt{R^{2}-r^{2}}}\\\\\n\t\t\\text { Now }& \\delta(t-R / c)=c \\delta(R-c t)\\\\\n\t\t\\text { Therefore } \\vec{A}&=\\frac{\\mu_{0} q_{0}}{2 \\pi} \\hat{z} c \\int_{r}^{\\infty} \\frac{\\delta(R-c t)}{\\sqrt{R^{2}-r^{2}}} d R \\text {, so }\\\\\n\t\t\\vec{A}(r, t)&=\\frac{\\mu_{0} q_{0} c}{2 \\pi} \\frac{1}{\\sqrt{(c t)^{2}-r^{2}}} \\hat{z} \\quad(\\text { or zero, if } c t<r)\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the radiation resistance of the wire joining the two ends of the dipole. (This is the resistance that would give the same average power loss-to-heat-as the oscillating dipole in fact puts out in the form of radiation.) Show that\n\t$$\n\tR=790(d / \\lambda)^{2} \\Omega \\text {. }\n\t$$\n\twhere $\\lambda$ is the wavelength of the radiation and other symbols have their usual meaning.\n\tFor the wires in an ordinary radio (say, $d=5 \\mathrm{~cm}$ ), should you worry about the radiative contribution to the total resistance ?\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { Let } q&=q_{0} \\cos (\\omega t) \\Rightarrow \\vec{I}(t)=\\frac{d q}{d t} \\hat{z}=-q_{0} \\omega \\sin (\\omega t) \\hat{z}\\\\\n\t\\text { Power radiated } P&=I^{2} R=q_{0}^{2} \\omega^{2} \\sin ^{2}(\\omega t) R \\Rightarrow\\langle P\\rangle=I^{2} R=\\frac{1}{2} q_{0}^{2} \\omega^{2} R\\\\\n\t\\text { The total power radiated is }\\langle P\\rangle&=\\frac{\\mu_{0} p_{0}^{2} \\omega^{4}}{12 \\pi c}=\\frac{\\mu_{0} q_{0}^{2} d^{2} \\omega^{4}}{12 \\pi c}\\\\\n\t\\text { Thus } \\frac{1}{2} q_{0}^{2} \\omega^{2} R&=\\frac{\\mu_{0} q_{0}^{2} d^{2} \\omega^{4}}{12 \\pi c} \\Rightarrow R=\\frac{\\mu_{0} d^{2} \\omega^{2}}{6 \\pi c}=\\frac{\\mu_{0} d^{2}}{6 \\pi c}\\left(\\frac{2 \\pi c}{\\lambda}\\right)^{2}=\\frac{2}{3} \\pi \\mu_{0} c\\left(\\frac{d}{\\lambda}\\right)^{2}\\\\\n\t\\Rightarrow R&=\\frac{2}{3} \\pi\\left(4 \\pi \\times 10^{-7}\\right)\\left(3 \\times 10^{8}\\right)\\left(\\frac{d}{\\lambda}\\right)^{2}=80 \\pi^{2}\\left(\\frac{d}{\\lambda}\\right)^{2} \\approx 790\\left(\\frac{d}{\\lambda}\\right)^{2} \\Omega\n\\intertext{For the wires in an ordinary radio with $d=5 \\mathrm{~cm}=5 \\times 10^{-2} \\mathrm{~m}$ and $\\lambda=10^{3} \\mathrm{~m}$}\n\t\\Rightarrow R \\approx 790\\left(\\frac{d}{\\lambda}\\right)^{2} \\Omega&=2 \\times 10^{-6} \\Omega\\\\\n\t\\text { which  }&\\text{is negligible compared to the ohmic resistance.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the radiation resistance for the oscillating magnetic dipole. Express your answer in terms of $\\lambda$ and $b$, and compare the radiation resistance of the electric dipole (where $\\lambda$ is the wavelength of the radiation and other symbols have their usual meaning.)\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { Let } \\vec{I}(t)&=I_{0} \\cos (\\omega t) \\hat{\\phi}\\\\\n\t\t\\text { Power radiated } P&=I^{2} R=I_{0}^{2} \\cos ^{2}(\\omega t) R \\Rightarrow\\langle P\\rangle=I^{2} R=\\frac{1}{2} I_{0}^{2} R\\\\\n\t\t\\text { The total power radiated is }\\langle P\\rangle&=\\frac{\\mu_{0} m_{0}^{2} \\omega^{4}}{12 \\pi c^{3}}=\\frac{\\mu_{0}\\left(I_{0} \\times \\pi b^{2}\\right)^{2} \\omega^{4}}{12 \\pi c^{3}}=\\frac{\\mu_{0} \\pi^{2} b^{4} I_{0}^{2} \\omega^{4}}{12 \\pi c^{3}}\\\\\n\t\t\\text { Thus } \\frac{1}{2} I_{0}^{2} R&=\\frac{\\mu_{0} \\pi^{2} b^{4} I_{0}^{2} \\omega^{4}}{12 \\pi c^{3}} \\Rightarrow R=\\frac{\\mu_{0} \\pi b^{4} \\omega^{4}}{6 c^{3}}=\\frac{\\mu_{0} \\pi b^{4}}{6 c^{3}}\\left(\\frac{2 \\pi c}{\\lambda}\\right)^{4}=\\frac{8}{3} \\pi^{5} \\mu_{0} c\\left(\\frac{b}{\\lambda}\\right)^{4}\\\\\n\t\t\\Rightarrow R&=\\frac{8}{3}\\left(\\pi^{5}\\right)\\left(4 \\pi \\times 10^{-7}\\right)\\left(3 \\times 10^{8}\\right)\\left(\\frac{b}{\\lambda}\\right)^{4}=3.1 \\times 10^{5}\\left(\\frac{b}{\\lambda}\\right)^{4} \\Omega\n\t\t\\end{align*}\n\t\tNote: $R$ is typically much smaller than the electric radiative resistance.\n\t\\end{answer}\n\t\\item An insulating circular ring (radius $b$ ) lies in the $x y$ plane, centered at the origin. It carries a linear charge density $\\lambda=\\lambda_{0} \\sin \\phi$, where $\\lambda_{0}$ is constant and $\\phi$ is the usual azimuthal angle. The ring is now set spinning at a constant angular velocity $\\omega$ about the $z$ axis. Calculate the power radiated.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { At } t&=0 \\text { the dipole moment of the ring is }\\\\\n\t\t\\overrightarrow{p_{0}}&=\\int \\lambda \\vec{r} d l=\\int\\left(\\lambda_{0} \\sin \\phi\\right)[(b \\cos \\phi) \\hat{x}+(b \\sin \\phi) \\hat{y}] b d \\phi\\\\\n\t\t\\Rightarrow \\overrightarrow{p_{0}}&=\\lambda_{0} b^{2}\\left(\\hat{x} \\int_{0}^{2 \\pi} \\sin \\phi \\cos \\phi d \\phi+\\hat{y} \\int_{0}^{2 \\pi} \\sin ^{2} \\phi d \\phi\\right)=\\pi \\lambda_{0} b^{2} \\hat{y}\\\\\n\t\t\\text { As it rotates; } \\vec{p}(t)&=p_{0}[\\cos (\\omega t) \\hat{x}+\\sin (\\omega t) \\hat{y}] \\Rightarrow \\vec{p}=-\\omega^{2} p_{0}[\\cos (\\omega t) \\hat{x}+\\sin (\\omega t) \\hat{y}]\\\\\n\t\t\\Rightarrow|\\vec{p}|^{2}&=\\omega^{4} p_{0}^{2}\\left[\\cos ^{2}(\\omega t)+\\sin ^{2}(\\omega t) y\\right]=\\omega^{4} p_{0}^{2}\\\\\n\t\t\\text { Thus } P&=\\frac{\\mu_{0} \\ddot{p}^{2}}{6 \\pi c}=\\frac{\\mu_{0} p_{0}^{2} \\omega^{4}}{6 \\pi c}=\\frac{\\mu_{0}\\left(\\pi \\lambda_{0} b^{2}\\right)^{2} \\omega^{4}}{6 \\pi c}=\\frac{\\pi \\mu_{0} \\omega^{4} b^{4} \\lambda_{0}^{2}}{6 c}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item An electron is released from from rest and falls under the influence of gravity. In the first centimeter, what fraction of the potential energy lost is radiated away?\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { Since dipole moment } \\vec{p}=-e y \\hat{y} \\Rightarrow \\vec{p}&=-\\frac{1}{2} g e t^{2} \\hat{y} \\Rightarrow \\vec{p}=-g e \\hat{y} \\quad \\because y=\\frac{1}{2} g t^{2}\\\\\n\t\t\\text { Thus } P&=\\frac{\\mu_{0} \\ddot{p}^{2}}{6 \\pi c}=\\frac{\\mu_{0} g^{2} e^{2}}{6 \\pi c}\\\\\n\t\t\\text { Now, the time it takes to fall a distance } h&=\\frac{1}{2} g t^{2} \\Rightarrow t=\\sqrt{\\frac{2 h}{g}} \\text {. }\\\\\n\t\t\\text { So energy radiated in falling a distance } h \\text { is } U_{r a d}&=P t=\\frac{\\mu_{0} g^{2} e^{2}}{6 \\pi c} \\sqrt{\\frac{2 h}{g}}\\\\\n\t\t\\text { Meanwhile, the potential energy lost is } U_{p o t}&=m g h \\text {. }\\\\\n\t\t\\text { So the fraction is } f=\\frac{U_{r a d}}{U_{p o t}}=\\frac{\\mu_{0} g^{2} e^{2}}{6 \\pi c} \\sqrt{\\frac{2 h}{g}} \\times \\frac{1}{m g h}&=\\frac{\\mu_{0} e^{2}}{6 \\pi m c} \\sqrt{\\frac{2 g}{h}}\n\t\t\\intertext{Evidently almost all the energy goes into kinetic form (as indeed we assumed $y=\\frac{1}{2} g t^{2}$ )}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "0e380207e11b20a015eaf62e0afb32edd176ba04", "size": 49644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Electrodynamics- CSIR/chapter/Potential Formulation and Radiation.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/Potential Formulation and Radiation.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/Potential Formulation and Radiation.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": 70.8188302425, "max_line_length": 366, "alphanum_fraction": 0.6300257836, "num_tokens": 19747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6742936207735373}}
{"text": "\\section{Deterministic and stochastic shallow flow models}\n\nIn this section, a certain deterministic numerical solver of the one dimensional (1D) shallow water equations is outlined in the framework of a finite volume Godunov-type method.\nThe selected deterministic solver relies on the surface gradient method \\citep{zhou2001} to both ensure a well-balanced topography integration and extendibility of the well-balanced property into the stochastic Galerkin case. \nAccordingly, a stochastic Galerkin reformulation is devised that is theoretically well-balanced with uncertain topography under a lake-at-rest hypothesis.\n\nThe mathematical model of the shallow water equations represent mass and momentum\nconservation principals, and is used in the following conservative form when solving it within a finite volume Godunov-type framework \\citep{toro-garcianavarro2007}:\n\\begin{align}\n\\frac{\\partial \\flow(x, t)}{\\partial t} + \\frac{\\partial \\flux(\\flow(x, t))}{\\partial x} = \\source(\\flow(x, t), z(x)) \\label{eqn:swe}\n\\end{align}\nwhere $\\flow = \\left[ h, q \\right]^\\T$ is the flow vector including water depth $h$ ($\\mathrm{L}$) and unit-width discharge $q = h\\velocity$ ($\\mathrm{L}^2/\\mathrm{T}$) in which $\\velocity$ represents the depth-averaged velocity ($\\mathrm{L}/\\mathrm{T}$), $\\flux = \\left[ q,  q^2/h + gh^2/2 \\right]^\\T$ is the flux vector in which $g$ represents the gravitational constant and $\\source = \\left[ 0, -gh \\: \\dee z / \\dee x \\right]^\\T$ is the source term vector in which the gradient of the topography $z(x)$ is involved.\nEquation~\\eqref{eqn:swe} represents hydraulic flow in an idealised, frictionless channel with a rectangular cross-section of unit width.\n\n\\subsection{Deterministic model}\n\nOn a uniform 1D mesh with $M$ elements each of size $\\Delta x$, the first-order finite volume method leads to the following discrete element-wise formulation of the shallow water equations given by equation~\\eqref{eqn:swe}:\n\\begin{align}\n    \\flow_i^{(n+1)} = \\flow_i^{(n)} - \\Delta t\n    \\left(\n    \\frac{\\riemannflux_{i+1/2}^{(n)} - \\riemannflux_{i-1/2}^{(n)}}{\\Delta x}\n    - \\source_i^{(n)} \\right) \\label{eqn:swe-discrete}\n\\end{align}\nin which $\\flow_i^{(n)} = \\left[ h_i^{(n)}, q_i^{(n)} \\right]^\\T$ is a piecewise-constant discretisation of the flow vector at element $i$ and time level $(n)$, and $\\riemannflux_{i+1/2}^{(n)}$ is a numerical flux function for linking nonlinear discontinuities associated with the flow vector data at interface $i+1/2$ located between element $i$ and $i + 1$.\nNamely, $\\riemannflux_{i+1/2}^{(n)} = \\riemannflux(\\flow_{i+1/2}^-, \\flow_{i+1/2}^+)$ where $\\flow_{i+1/2}^-$ is the limit of the solution from the side of element $i$, and $\\flow_{i+1/2}^+$ is the limit of the solution from the side of element $i+1$.\nWithin the scope of this work involving a first-order accurate solver, these limits become $\\flow_{i+1/2}^- = \\flow_i$ and $\\flow_{i+1/2}^+ = \\flow_{i+1}$ that are used in a numerical flux function based on the Roe approximate Riemann solver \\citep{roe-pike1984}.\nConsequently, the deterministic model is able to capture the occurrence of shocks, and simulate subcritical, supercritical and transcritical flows.\n\nThe surface gradient method essentially reconstructs an averaged topography at interface $i+1/2$ that is shared by both elements $i$ and $i+1$, as $\\zmodified_{i+1/2} = (z_i + z_{i+1})/2$.\nFrom the reconstructed topography $\\zmodified_{i+1/2}$, consistent flow variable limits are accordingly reconstructed based on the actual free-surface elevation data, i.e. $\\eta_{i+1/2}^- = h_i^{(n)} + z_i$ and $\\eta_{i+1/2}^+ = h_{i+1}^{(n)} + z_{i+1}$, and velocity data, i.e. $\\velocity_{i+1/2}^- = q_i^{(n)}/h_i^{(n)}$ and $\\velocity_{i+1/2}^+ = q_{i+1}^{(n)} / h_{i+1}^{(n)}$, as: $\\hKmodified_{i+1/2} = \\eta_{i+1/2}^K - \\zmodified_{i+1/2}$ and $\\qKmodified_{i+1/2} = \\hKmodified_{i+1/2} \\velocity_{i+1/2}^K$ (where $K = + \\text{ or } -$).\nFor clarity of presentation, the time level denoted by superscript $(n)$ is omitted from all reconstructed variables.\nThese reconstructions form new Riemann states $\\flowKmodified_{i+1/2} = \\left[ \\hKmodified_{i+1/2}, \\qKmodified_{i+1/2} \\right]^\\T$ for use to evaluate $\\riemannflux_{i+1/2}^{(n)}$.\nBy analogy, new Riemann limits $\\flowKmodified_{i-1/2} = \\left[ \\hKmodified_{i-1/2}, \\qKmodified_{i-1/2} \\right]^\\T$ at $i - 1/2$ are produced for use to evaluate $\\riemannflux_{i-1/2}^{(n)}$.\nFrom the reconstructed limits, a well-balanced discretisation of the source term vector can be produced:\n\\begin{align}\n\t\\source_i^{(n)} = \\left[ 0, -g\n\t\\left( \\frac{h^{+,\\star}_{i-1/2} + h^{-,\\star}_{i+1/2}}{2} \\right)\n\t\\left( \\frac{z^\\star_{i+1/2} - z^\\star_{i-1/2}}{\\Delta x} \\right)\n\t\\right]^\\T\n\t\\label{eqn:source}\n\\end{align}\nThe well-balanced deterministic model presented in equations~\\eqref{eqn:swe-discrete} and \\eqref{eqn:source} is used for Monte Carlo simulations, and the deterministic model is also the starting point for a stochastic Galerkin reformulation.\n\n\\subsection{Fundamental properties of the Polynomial Chaos basis}\n\nBefore presenting the stochastic Galerkin reformulation, it is necessary to consider a single random variable $A(\\theta)$ that maps from the random event $\\theta$ to an arbitrary probability distribution with finite variance.\nThis random variable can be approximated by a Wiener-Hermite Polynomial Chaos expansion \\citep{xiu-karniadakis2002}.\nThe expansion is based on a standard Gaussian random variable $\\xi(\\theta) \\in [-\\infty, +\\infty]$ having zero mean and unit variance.\nThe random variable of interest, $A(\\theta)$, is then approximated as\n\\begin{align}\nA(\\theta) \\approx \\sum_{p=0}^P A_p \\pcbasis_p(\\xi(\\theta))\n\\end{align}\nwhere $\\vect{A} = \\left[ A_0, \\ldots, A_P \\right]^\\T$ are the expansion coefficients and $\\pcbasisvect = \\left[ \\pcbasis_0, \\ldots, \\pcbasis_P \\right]^\\T$ is the probabilists' Hermite polynomial basis having basis function $\\pcbasis_p$ of degree $p$,\n\\begin{align}\n    \\pcbasis_p(\\xi) = \\left( -1 \\right)^p \\exp \\left(\\frac{\\xi^2}{2}\\right)\n    \\frac{\\dee^p}{\\dee \\xi^p} \\exp \\left(- \\frac{\\xi^2}{2} \\right)\n\\end{align}\nwhere $\\pcbasis_0 = 1, \\pcbasis_1 = \\xi, \\pcbasis_2 = \\xi^2 - 1, \\pcbasis_3 = \\xi^3 - 3\\xi$ and so on.\nAs the basis order $P$ is increased, the Wiener-Hermite Polynomial Chaos approximation converges on the true random variable $A(\\theta)$ \\citep{xiu-karniadakis2002}.\n\n\\subsubsection*{Basis orthogonality and commutativity}\nThe Wiener-Hermite basis $\\pcbasisvect$ is orthogonal such that\n\\begin{align}\n\t\\Ensemble{\\pcbasis_p \\pcbasis_s} = \\Ensemble{\\pcbasis_p^2} \\delta_{ps}\n\\end{align}\nwhere $\\Ensemble{\\cdot}$ is the ensemble average operator and $\\delta_{ps}$ is the Kronecker delta that is equal to one when $p = s$ and zero otherwise.\nThe ensemble average operator is defined as the weighted integral over the standard Gaussian random variable $\\xi$:\n\\begin{align}\n\t\\Ensemble{\\alpha(\\xi)} = \\int_{-\\infty}^\\infty \\alpha(\\xi) W(\\xi) \\diff \\xi \\label{eqn:ensemble-average}\n\\end{align}\nwhere $\\alpha(\\xi)$ is an expression involving any combination of random variables or basis functions, and the weighting function $W(\\xi)$ is the standard Gaussian probability density function\n\\begin{align}\n\tW(\\xi) = \\frac{1}{\\sqrt{2\\pi}} \\exp \\left(-\\frac{\\xi^2}{2}\\right)\n\\end{align}\nThis weighting function ensures that, when $\\alpha$ is independent of $\\xi$, the ensemble average $\\Ensemble{\\alpha} = \\alpha$.\nFinally, the ensemble average of a product of basis functions is commutative such that\n\\begin{align}\n    \\Ensemble{\\pcbasis_p \\pcbasis_s} = \\Ensemble{\\pcbasis_s \\pcbasis_p}\n    \\label{eqn:commutative}\n\\end{align}\nThe commutative property is needed later when verifying the well-balanced property with uncertain topography.\n\n\\subsubsection*{Stochastic Galerkin projection of a random variable}\nGiven the random variable $A(\\theta) = \\sum_{p=0}^P A_p \\pcbasis_p(\\xi(\\theta))$, its Galerkin projection onto a basis function $\\pcbasis_l$ with $l = 0, \\ldots, P$ is achieved using the ensemble average operator such that, due to orthogonality,\n\\begin{align}\n\t\\Ensemble{A(\\theta) \\pcbasis_l} = A_l \\Ensemble{\\pcbasis_l^2} \\label{eqn:orthogonal}\n\\end{align}\nwhere $A_l$ is the $l$\\textsuperscript{th} order expansion coefficient.\nAlso note that the Galerkin projection of a basis function $\\pcbasis_l$ and two random variables, $A(\\theta)$ and $B(\\theta)$, is distributive:\n\\begin{align}\n\t\\Ensemble{\\left(A(\\theta) + B(\\theta)\\right) \\pcbasis_l}\n\t=\n\t\\Ensemble{A(\\theta) \\pcbasis_l} + \\Ensemble{B(\\theta) \\pcbasis_l} \\label{eqn:distributive}\n\\end{align}\n\n\\subsubsection*{Mean, variance and high-order moments}\nThe mean, variance and high-order moments can be calculated for $A(\\theta)$.\nThe $m$\\textsuperscript{th} moment $\\mu_m[A]$ is defined as\n\\begin{align}\n\\mu_m[A] = \\int_{-\\infty}^\\infty \\left(A - \\beta \\right)^m W(\\xi) \\diff \\xi\n    =\n    \\Ensemble{\\left( A - \\beta \\right)^m} \\label{eqn:moment}\n\\end{align}\nwhere $\\beta = 0$ when $m = 1$ and $\\beta = \\mu_1[A]$ for higher-order moments.\nTherefore, the mean $\\mu_1[A] = \\Ensemble{A} = \\sum_{p=0}^P A_p \\Ensemble{\\pcbasis_p}$.\nSince $\\Ensemble{\\pcbasis_0} = 1$ and $\\Ensemble{\\pcbasis_p} = 0$ for $p > 0$ then\n\\begin{align}\n\\mu_1[A] = A_0\n\\label{eqn:mean}\n\\end{align}\nThe shorthand notation for the mean of $A$ is $\\mean{A}$, also known as the expected value, $\\E\\left[A\\right]$.\n\nThe variance $\\mu_2[X]$ can be derived using the fact that $\\E\\left[ \\left( A - \\E[A] \\right)^2 \\right] = \\E[A^2] - \\E^2[A]$, hence $\\mu_2[A] = \\left(\\sum_{p=0}^P A_p^2 \\Ensemble{\\pcbasis_p^2}\\right) - A_0^2 \\Ensemble{\\pcbasis_0}^2$.\nSince $\\Ensemble{\\pcbasis_0}^2 = \\Ensemble{\\pcbasis_0^2}$ then\n\\begin{align}\n    \\mu_2[A] &= \\sum_{p=1}^P A^2_p \\Ensemble{\\pcbasis_p^2} \\label{eqn:variance}\n\\end{align}\nThe shorthand notation for the variance of $A$ is $\\sigma^2_A$ and the standard deviation of $A$ is $\\sigma_A$.\n\n\\subsubsection*{Reconstructing the probability density function}\nThe probability density function $f_A(a)$ of a random variable $A$ is,\n\\begin{subequations}\n\\begin{align}\n        f_A(a) = \\sum_{j=1}^J \\Mag{ \\sum_{p=0}^P A_p \\frac{\\dee \\Phi_p}{\\dee \\xi}(\\randomroot_j)}^{-1} W(\\randomroot_j)\n%\n\\intertext{where $\\randomroot_j$, $j=1, \\ldots, J$ are the real roots of the polynomial}\n%\n        a - \\sum_{p=0}^P A_p \\pcbasis_p(\\xi) = 0\n\\end{align}\\label{eqn:pdf}%\n\\end{subequations}\nwhich can be calculated numerically for a specific realisation $a$.\nHence, the probability density function is computed by evaluating equation~\\eqref{eqn:pdf} for a range of outcomes.\n\n\\subsection{Stochastic Galerkin reformulation of the deterministic model}\n%In the deterministic 1D shallow water equations (equation~\\ref{eqn:swe}), the flow vector is $\\flow(x, t)$ and the topography is $z(x)$.\nThe solution of the stochastic 1D shallow water equations is now random because it depends on uncertain initial conditions, uncertain boundary conditions and uncertain topography.\nHence, the stochastic 1D shallow water equations depend not only upon space $x$ and time $t$, but additionally upon the random event $\\theta$.\nThe stochastic flow vector $\\flow(x, t, \\theta)$ becomes a general stochastic process having arbitrary probability distributions that vary in space and time.\nSimilarly, the stochastic topography $z(x, \\theta)$ has arbitrary probability distributions that vary in space.\n\nThe stochastic Galerkin reformulation of the deterministic model involves three steps to (i) replace the deterministic variables, $\\flow_i^{(n)}$ and $z_i$, with random variables $\\flow_i^{(n)}(\\theta)$ and $z_i(\\theta)$, (ii) rewrite the deterministic formulation using these random variables, and (iii) make a stochastic Galerkin projection onto the Wiener-Hermite basis.\n\n\\subsubsection*{Replacing deterministic variables with random variables}\n\nFor all elements $i=1, \\ldots, M$ across all time levels, every deterministic flow variable $\\flow_i^{(n)} = \\left[h_i^{(n)}, q_i^{(n)}\\right]^\\T$ and deterministic topography variable $z_i$ becomes a random variable approximated by a Wiener-Hermite Polynomial Chaos expansion:\n\\begin{align}\n\\flow_i^{(n)}(\\theta) \\approx \\sum _{p=0}^P \\flow_{i,p}^{(n)} \\pcbasis_p(\\xi(\\theta))\n    \\:\\text{,}\\quad\nz_i(\\theta) \\approx \\sum_{p=0}^P z_{i,p} \\pcbasis_p(\\xi(\\theta))\n\\label{eqn:pc-expansion}%\n\\end{align}\nwhere $\\flow_{i,p}^{(n)} = \\left[ h_{i,p}^{(n)}, q_{i,p}^{(n)} \\right]^\\T$ and $z_{i,p}$ are the $p$\\textsuperscript{th} order expansion coefficients over element $i$ at time level $n$.\n\nThe reconstructed topography and reconstructed limits become functions of random variables.\nThe reconstructed topography at interface $i+1/2$ becomes\n\\begin{align}\n\t\\sum_{p=0}^P z^\\star_{i+1/2,p} \\pcbasis_p\n\t=\n\t\\frac{1}{2}\n\t\\left(\n\t\\sum_{p=0}^P z_{i,p} \\pcbasis_p\n\t+\n\t\\sum_{p=0}^P z_{i+1,p} \\pcbasis_p\n\t\\right)\n\\end{align}\nand so $z^\\star_{i+1/2,p} = (z_{i,p} + z_{i+1,p})/2$ due to basis orthogonality.\nThe reconstructed limits $\\flow^{K,\\star}_{i+1/2,p} = \\left[ h^{K,\\star}_{i+1/2,p}, q^{K,\\star}_{i+1/2,p} \\right]^\\T$ (where $K = + \\text{ or } -$) are calculated in a similar fashion.\n\nRandom variables that are functions of other random variables can be calculated in the same way.\nIn particular, water depth can be expressed as a function of free-surface elevation and topography such that, due to basis orthogonality,\n\\begin{align}\nh_{i,p}^{(n)} = \\eta_{i,p}^{(n)} - z_{i,p}\n\\label{eqn:h-eta-z}\n\\end{align}\nwhich is used later for specifying initial conditions.\n\n\\subsubsection*{Rewriting the deterministic formulation using random variables}\n\nThe deterministic finite volume formulation given by equation~\\eqref{eqn:swe-discrete} is rewritten in terms of the random variables in equation~\\eqref{eqn:pc-expansion}.\nAs a result, the numerical fluxes $\\riemannflux_{i+1/2}^{(n)}$ and $\\riemannflux_{i-1/2}^{(n)}$ and source term vector $\\source_i^{(n)}$ become functions of random variables.\nThe numerical flux $\\riemannflux_{i+1/2}^{(n)}$ becomes\n\\begin{align}\n\t\\riemannflux_{i+1/2}^{(n)} = \\riemannflux \\left(\n\t\\sum_{p=0}^P \\flow^{-,\\star}_{i+1/2,p} \\pcbasis_p, \n\t\\sum_{p=0}^P \\flow^{+,\\star}_{i+1/2,p} \\pcbasis_p\n\t\\right)\n\\end{align}\nand similarly for $\\riemannflux_{i-1/2}^{(n)}$.\nThe source term vector $\\source_i^{(n)}$ in equation~\\eqref{eqn:source} becomes\n\\begin{align}\n\t\\source_i^{(n)} = \\left[ 0, -\\frac{g}{\\Delta x}\n\t\\left\\{\n\t\\sum_{p=0}^P \\left(\\frac{h^{+,\\star}_{i-1/2,p} + h^{-,\\star}_{i+1/2,p}}{2} \\right) \\pcbasis_p \\right\\}\n\\left\\{ \\sum_{s=0}^P \\left( z^\\star_{i+1/2,s} - z^\\star_{i-1/2,s} \\right) \\pcbasis_s \\right\\}\n\t\\right]^\\T\n\t\\label{eqn:random-source}\n\\end{align}\nEquation~\\eqref{eqn:random-source} involves the product of two expressions, each delimited by braces.\nSince both expressions include Wiener-Hermite expansions then different indices, $p$ and $s$, are needed for the expansion coefficients in each expression.\n\n\\subsubsection*{Stochastic Galerkin projection}\n\nDue to the orthogonality property (equation~\\ref{eqn:orthogonal}) and distributivity property (equation~\\ref{eqn:distributive}) of the Wiener-Hermite basis, a Galerkin projection of equation~\\eqref{eqn:swe-discrete} onto the basis functions $\\pcbasis_l, l = 0, \\ldots, P$ produces $P+1$ decoupled equations:\n\\begin{align}\n    \\flow_{i,l}^{(n+1)} = \\flow_{i,l}^{(n)}\n    - \\frac{\\Delta t}{\\Ensemble{\\pcbasis_l^2}}\n    \\left(\n    \\frac{\n    \\Ensemble{\\riemannflux_{i+1/2}^{(n)} \\pcbasis_l}\n    -\n    \\Ensemble{\\riemannflux_{i-1/2}^{(n)} \\pcbasis_l}\n    }{\\Delta x}\n    - \\Ensemble{\\source_i^{(n)} \\pcbasis_l}\n    \\right) \\label{eqn:swe-pc}\n\\end{align}\nEquation~\\eqref{eqn:swe-pc} involves ensemble averages of numerical fluxes, $\\Ensemble{\\riemannflux_{i+1/2}^{(n)} \\pcbasis_l}$ and $\\Ensemble{\\riemannflux_{i-1/2}^{(n)} \\pcbasis_l}$, and an ensemble average of the source term vector, $\\Ensemble{\\source_i^{(n)} \\pcbasis_l}$.\nThere is no straightforward method for calculating an ensemble average of the numerical flux because it is nonlinear.\nInstead, the integral in equation~\\eqref{eqn:ensemble-average} is approximated by Gauss-Hermite quadrature,\n\\begin{align}\n    \\Ensemble{\\riemannflux_{i+1/2}^{(n)} \\pcbasis_l}\n    \\approx\n    \\sum_{j=1}^{P+1} w_j\n    \\riemannflux\\left(\n\t\\sum_{p=0}^P \\flow_{i+1/2,p}^{-,\\star} \\pcbasis_p(\\xi_j),\n\t\\sum_{p=0}^P \\flow_{i+1/2,p}^{+,\\star} \\pcbasis_p(\\xi_j)\n\t\\right)\n    \\pcbasis_l(\\xi_j) W(\\xi_j) \\label{eqn:pc-flux}\n\\end{align}\nwhere $w_j$ are the quadrature weights and $\\xi_j$ are the quadrature points.\nThe ensemble average $\\Ensemble{\\riemannflux_{i-1/2}^{(n)} \\pcbasis_l}$ is calculated in the same way.\n\nUnlike the nonlinear numerical flux, the ensemble average of the source term vector $\\Ensemble{\\source_i^{(n)} \\pcbasis_l}$ is linear and can be derived directly from equation~\\eqref{eqn:random-source}:\n\\begin{align}\n\\Ensemble{\\source_i^{(n)} \\pcbasis_l} &= \\left[ 0,\n    - \\frac{g}{\\Delta x}\n    \\sum_{p=0}^P \\sum_{s=0}^P\n\\left(\\frac{h^{+,\\star}_{i-1/2,p} + h^{-,\\star}_{i+1/2,p}}{2}\\right)\n\\left( z^\\star_{i+1/2,s} - z^\\star_{i-1/2,s} \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_s \\pcbasis_l}\n    \\right]^\\T\n\\label{eqn:pc-source}\n\\end{align}\nThe ensemble averages $\\Ensemble{\\pcbasis_p \\pcbasis_s \\pcbasis_l}$ in equation~\\eqref{eqn:pc-source} and $\\Ensemble{\\pcbasis_l^2}$ in equation~\\eqref{eqn:swe-pc} can be calculated analytically or exactly by Gauss-Hermite quadrature.\nSince these calculations do not depend on the solution then they can be precomputed once and stored.\n", "meta": {"hexsha": "0de3e5f0f6bc89b423c2fb8c9f6072701e7acc4a", "size": 17387, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "overleaf/method.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/method.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/method.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": 70.9673469388, "max_line_length": 544, "alphanum_fraction": 0.7143267959, "num_tokens": 5640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6742854190275768}}
{"text": "\\documentclass[12pt]{scrartcl}\n\n\\input{preamble}\n\n\\makeatletter\n\\title{Hack 12.0}\\let\\Title\\@title\n\\subtitle{Computer Science I -- Java\\\\\nRecursion \\& Memoization\\\\\n{\\small\n\\vskip1cm\nDepartment of Computer Science \\& Engineering \\\\\nUniversity of Nebraska--Lincoln}\n\\vskip-3cm}\n%\\author{Dr.\\ Chris Bourke}\n\\date{~}\n\\makeatother\n\n\\begin{document}\n\n\\maketitle\n\n\\hrule\n\n\\input{instructions.tex}\n\n\\section*{Problem Statement}\n\nA binomial coefficient, ``$n$ choose $k$'' is a number that corresponds \nto the number of ways to \\emph{choose} $k$ items from a set of $n$ distinct\nitems.  You may be familiar with some the notations, $C(n,k)$ or $C_n^k$ \nor ${}_{n}C_k $, but most commonly this is written as \n  $${n \\choose k}$$\nand read as ``$n$ choose $k$''.  There is an easy to compute formula involving\nfactorials:\n  $${n \\choose k} = \\frac{n!}{(n-k)!k!}$$\nFor example, if we have $n = 4$ items, say $\\{a, b, c, d\\}$ and want to choose\n$k=2$ of them, then there are \n  $${4 \\choose 2} = \\frac{4!}{(4-2)!2!} = 6$$\nways of doing this.  The six ways are:\n  $$\\{a, b\\}, \\{a, c\\}, \\{a, d\\}, \\{b, c\\}, \\{b, d\\}, \\{c, d\\}$$\nThere are a lot of other interpretations and applications for binomial \ncoefficients, but this hack will focus on computing their value using\na different formula, Pascal's Rule\\footnote{Which can be used to generate\nPascal's Triangle, \\url{https://en.wikipedia.org/wiki/Pascals_triangle}}:\n  $${n \\choose k} = {n-1 \\choose k} + {n-1 \\choose k-1}$$\nwhich is a recursive formula.  The base cases for Pascal's Rule are when\n$k = 0$ and $n = k$.  In both cases, the value is 1.  When $k = 0$, we are\nnot choosing any elements and so there is only one way of doing that (i.e.\\\nchoose nothing).  When $n = k$ we are choosing every element, again there\nis only one way of doing that.  \n\n\\subsection*{Writing a Naive Recursion}\n\nCreate a class named \\mintinline{text}{Binomial} and implement and \ntest the following method \\emph{using a recursive} solution:\n\n\\mintinline{java}{public static long choose(int n, int k)}\n\nwhich takes $n$ and $k$ and computes ${n\\choose k}$ using Pascal's Rule.\nNote that the return type is a \\mintinline{java}{long} which is a 64-bit\ninteger allowing you to compute values up to \n  $$2^{63}-1 = 9,223,372,036,854,775,807$$\n(a little over 9 quintillion).  Write a \\mintinline{java}{main} method\nthat takes $n$ and $k$ as command line arguments and outputs the result\nto the standard output so you can easily test it.\n\n\\subsection*{Benchmarking}\n\nRun your program on values of $n, k$ in Table \\ref{table:easyValues} \nand time (roughly) how long it takes your program to execute.  You\ncan check your solutions with an online tool such as \n\\url{https://www.wolframalpha.com/}.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{c|c}\n$n$ & $k$ \\\\\n\\hline\\hline\n4 & 2 \\\\\n10 & 5 \\\\\n32 & 16 \\\\  %5 seconds\n34 & 17 \\\\  %15 seconds\n36 & 18 \\\\ %60 seconds\n\\end{tabular}\n\\caption{Test Values}\n\\label{table:easyValues}\n\\end{table}\n\nNow formulate an estimate of how long your program would take to \nexecute with larger values.  You can make a \\emph{rough} estimate \nhow many method calls are made using the binomial value itself.  \nThat is, to compute ${n \\choose k}$ using Pascal's Rule would make \n\\emph{about} ${n \\choose k}$ method calls.\n\nUse the running time of your program from the test values to \nestimate how long your program would run for the values in \nTable \\ref{table:hardValues}.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{c|r}\n${n \\choose k}$ &  value \\\\\n\\hline\\hline\n${54 \\choose 27}$ & =     1,946,939,425,648,112 \\\\\n${56 \\choose 28}$ & =     7,648,690,600,760,440 \\\\\n${58 \\choose 29}$ & =    30,067,266,499,541,040 \\\\\n${60 \\choose 30}$ & =   118,264,581,564,861,424 \\\\\n${62 \\choose 31}$ & =   465,428,353,255,261,088 \\\\\n${64 \\choose 32}$ & = 1,832,624,140,942,590,534 \\\\\n${66 \\choose 33}$ & = 7,219,428,434,016,265,740 \\\\\n\\end{tabular}\n\\caption{Larger Values}\n\\label{table:hardValues}\n\\end{table}\n\n\\subsection*{Improving Performance with Memoization}\n\nYou'll now improve your program's performance using memoization\nto avoid unnecessary repeated recursive calls.  \n\n\\begin{enumerate}\n  \\item First, change your return type to use Java's \\mintinline{java}{BigInteger}\n  class.  This is an arbitrary precision number class meaning that it can \n  represent arbitrarily large integer values.  You won't be able to use \n  the normal arithmetic operators however.  Instead, you'll need to RTM and\n  use the class's methods to add and perform other operations.  See the\n  documentation here: \\url{https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/math/BigInteger.html}\n  \\item To ``cache'' values so that you are not continually repeating the\n  same calculations over-and-over you \\emph{could} use a table, but let's \n  use a \\emph{smart data structure}: a \\mintinline{java}{Map}.\n  \n  This map will be used to map a pair of input values, $(n,k)$ to the\n  value of the binomial ${n \\choose k}$.  The problem is that we want\n  to use the combination of two values as a single key.  To do so, we've\n  provided a \\mintinline{java}{Pair} class that allows you to pair two\n  objects together to use as a key.\n  \n  Create and instantiate a static map of the following type:\n  \n  \\mintinline{java}{Map<Pair<Integer, Integer>, BigInteger>} \n  \n  \\item Modify your \\mintinline{java}{binomial} method to use this map\n  to store and use values to avoid unnecessary repeated recursive calls.\n  Your method should have the following signature:\n  \n  \\mintinline{java}{public static BigInteger binomial(int n, int k)}\n  \n  When the method needs to compute ${n \\choose k}$ it checks the map\n  first: if the value has already been computed (is not \\mintinline{java}{null}) then it\n  returns that value.  Otherwise, it performs the recursive computation.\n  Before returning the value, however, it should store it (\\emph{cache}\n  it) in the map so that subsequent computations avoid the recursion.  \n  \n  \\item Rerun your program with the values in Tables \\ref{table:easyValues} \n  and \\ref{table:hardValues} to verify they work and note the difference\n  in running time.  \n\\end{enumerate}\n\n\\section*{Instructions}\n\n\\begin{itemize}\n\n  \\item All your code should be in the class file, \n  \\mintinline{text}{Binomial.java} along with full documentation.\n\n  \\item You are encouraged to collaborate any number of students \n  before, during, and after your scheduled hack session.  \n\n  \\item Include the name(s) of everyone who worked together on\n  this activity in your source file's header.\n\n  \\item Turn in all of your files via webhandin, making sure that \n  it runs and executes correctly in the webgrader.  Each individual \n  student will need to hand in their own copy and will receive \n  their own individual grade.\n\\end{itemize}  \n\n\n\\end{document}\n", "meta": {"hexsha": "d64f815c172569db5c2ec674ea5cc860f4762ae6", "size": 6780, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "honors/hacks/hack12.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/hack12.0.tex", "max_issues_repo_name": "hrithik125/ComputerScienceI", "max_issues_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 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/hack12.0.tex", "max_forks_repo_name": "hrithik125/ComputerScienceI", "max_forks_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 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": 37.6666666667, "max_line_length": 114, "alphanum_fraction": 0.7128318584, "num_tokens": 1984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743167997235783, "lm_q2_score": 0.907312213841788, "lm_q1q2_score": 0.674285400828366}}
{"text": "\\chapter{Elementary Vector Spaces}\\label{chap:elem_vec_spaces}\n\nA \\emph{vector} $\\vec{v}$ is an element of a special set $V$, known as a \\emph{vector space}. In physics or computer science, we're used to thinking of vectors as certain things, like arrows in space with a magnitude and direction, or ordered arrays of items. However, it's best for the purposes of this lesson to think of vectors in the mathematical sense; that is, as ``vectors.''\nVectors can be anything really, from lists of numbers to sound waves to cats, as long as you apply the appropriate definitions for how the vector should act.\nSo, really, the best definition of a vector is: a vector is something that acts like vector, which lives in a special space called a vector space. I know that definition isn't really comforting for now. If it helps, you can think of them as cats.\\footnote{We're using bold $\\vec{v}$ instead of the more traditional arrow notation $\\varr{v}$ for vectors to help emphasize that they aren't always ``arrows in space''. Vectors are really just anything which follows the rules of addition and multiplication. A non-trivial example of vectors are sound waves, or polynomials. Think about how these kinds of things are added and multiplied. What is their zero vector? What vector spaces can they live in?}\n\\section{Properties}\nVector spaces have special properties:\n\\begin{itemize}\n    \\item Vector spaces must be endowed with a binary operation $+ : V \\times V \\to V$, called addition.\n    This is defined for any two elements in the vector space, and the result is also an element of the vector space.\n    We write this as $\\vec{v} + \\vec{u} = \\vec{w} \\in V,\\;\\forall \\vec{v},\\vec{u} \\in V$.\n    This implies that vector spaces are closed under addition.\n    Note that this operation is defined \\emph{only} for vectors from the same vector space --- we cannot add two vectors from different vector spaces.\n    \\item Vector spaces are defined over a \\emph{field} $\\mathbb{F}$.\n    This field determines the scalars by which we can multiply a vector. Just as with addition, a vector space must be closed under scalar multiplication $\\cdot : \\mathbb{F} \\times V \\to V$, so $\\lambda\\vec{v} \\in V,\\;\\forall \\lambda \\in \\mathbb{F}$.\n    We say that a vector space is taken \\emph{over} a field $\\mathbb{F}$; if $\\mathbb{F} = \\mathbb{R}$, then we say that $V$ is a \\emph{real} vector space, and if $\\mathbb{F} = \\mathbb{C}$, it is a \\emph{complex} vector space. Note that this has \\emph{nothing} to do with the component values of $V$.\n    If the components of a vector $\\vec{v}$ are complex-valued but the scalars are only real numbers, then it is still a real vector space.\n    In physics, there are usually only four different kinds of vector spaces that are usually dealt with: real vector spaces (as are used in General Relativity), complex vector spaces (used in Quantum mechanics), quaternionic, and octonionic.\n    These last two, however, aren't fields, which changes how they are used. Really, we needn't concern ourselves with them.\n    \\item Vector spaces have a specific \\emph{dimension} associated with them. We can think of dimension as any of the following equivalent concepts:\n        \\begin{itemize}\n            \\item If I draw a random vector $\\vec{q}$ out of a vector space $V$, what is the \\emph{minimum} number of other random vectors in $V$ I need to linearly combine to get $\\vec{q}$?\n            \\item The minimum number of linearly independent vectors necessary to span the entire vector space.\n            \\item The cardinality of a basis for the vector space.\n        \\end{itemize}\n    A vector space can be finite-dimensional or infinite-dimensional. In General Relativity, we usually deal with four dimensional vector spaces whose vectors are known as ``four-vectors.''\n\\end{itemize}\n\n\\section{Axioms}\nNow that we have those operations well defined, a vector space must also satisfy the following axioms:\n\\begin{align}\n    \\vec{u} + (\\vec{v} + \\vec{w}) &= (\\vec{u} + \\vec{v}) + \\vec{w} \\tag{Associativity of addition} \\\\\n    \\vec{v} + \\vec{u} &= \\vec{u} + \\vec{v} \\tag{Commutativity of addition} \\\\\n    \\exists\\, 0_V \\in V: \\vec{v} + 0_V &= \\vec{v}\\;\\forall \\vec{v} \\in V \\tag{Additive identity} \\\\\n    \\forall \\vec{v},\\; \\exists\\, {-\\vec{v}}: \\vec{v} + -\\vec{v} &= 0_V \\tag{Additive inverse} \\\\\n    \\lambda(\\kappa\\vec{v}) &= (\\lambda\\kappa)\\vec{v} \\tag{Compatability of scalar multiplication} \\\\\n    1_{\\mathbb{F}}\\vec{v} &= \\vec{v} \\tag{Multiplicative identity of $\\mathbb{F}$} \\\\\n    \\lambda(\\vec{v} +\\vec{u}) &= \\lambda\\vec{v} + \\lambda\\vec{u} \\tag{Distributivity of scalar multiplication} \\\\\n    (\\lambda + \\kappa)\\vec{v} &= \\lambda\\vec{v} + \\kappa\\vec{v} \\tag{Distributivity of field addition}\n\\end{align}\n\n\\section{Linear Independence}\nA set of vectors $U \\subset V$ is \\emph{linearly independent} iff no vector in the subset can be written as a linear combination of other vectors in the set. That is, for all $\\vec{u} \\in U$, $u \\not= \\sum \\lambda_i\\vec{a}_i$. The \\emph{span} of a set of vectors is every possible linear combination of vectors in that set, denoted $\\text{Span}(U)$. Vector spaces have basis associated with them. A \\emph{basis} is a minimally spanning set of linearly independent vectors.\nThis means that $\\text{Span}(B) = V$, for some basis $B$ of $V$.\nSome semi-obvious observations:\n\\begin{itemize}\n    \\item All basis of the same vector space have the same dimension.\n    \\item $\\abs{B} = \\dim(V)$ (we said this already).\n    \\item If $\\dim(V) = n$, then a set of less than $n$ vectors can never span $V$, and a set of more than $n$ vectors can never be linearly independent.\n    \\item If two vector spaces have the same dimension, then the differences between them are essentially superficial, and we can say that they are \\emph{isomorphic}.\n    This means that we can establish a one-to-one correspondence between vectors in each space (a bijection) and operations in one correspond to operations in another (so it is structure preserving).\n    \\item At this point, we only have one binary operation on vectors: addition. We can add two vectors, but we (currently) have no notion of what a dot product or a cross product are.\n    We also have no notion of vector magnitude.\n\\end{itemize}\n", "meta": {"hexsha": "543f4a7471bc31fbfd00f1cdbb208c7cce856de4", "size": 6244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/elementary_vector_spaces.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/elementary_vector_spaces.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/elementary_vector_spaces.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": 113.5272727273, "max_line_length": 699, "alphanum_fraction": 0.7221332479, "num_tokens": 1670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.7931059560743421, "lm_q1q2_score": 0.6741171958772978}}
{"text": "\\chapter{Mutable Objects}\n\\label{mutable}\n\n\\index{String class}\n\\index{type!String}\n\nAs you learned in the previous chapter, an object is a collection of data that provides a set of methods.\nFor example, a \\java{String} is a collection of characters that provides methods like \\java{charAt} and \\java{substring}.\n\nIn this chapter, we'll explore two new types of objects: \\java{Point} and \\java{Rectangle}.\nWe'll see how to write methods that take objects as parameters and produce objects as return values.\n\nWe will also take a first look at the source code for the Java library.\n\n\n\\section{Point Objects}\n\\label{point}\n\n\\index{coordinate}\n\nIn math, 2D ``points'' are often written in parentheses with a comma separating the coordinates.\nFor example, $(0,0)$ indicates the origin, and $(x,y)$ indicates the point $x$ units to the right and $y$ units up from the origin.\n\n\\index{AWT}\n\\index{java.awt}\n\\index{Point}\n\\index{class!Point}\n\n% TODO: ML suggest introducing AWT here with a short high-level description\n\nThe \\java{java.awt} package provides a class named \\java{Point} that represents a location in a Cartesian plane.\nIn order to use the \\java{Point} class, you have to import it:\n\n\\begin{code}\nimport java.awt.Point;\n\\end{code}\n\n\\index{new}\n\\index{operator!new}\n\nThen, to create a new point, you use the \\java{new} operator:\n\n\\begin{code}\nPoint blank;\nblank = new Point(3, 4);\n\\end{code}\n\n\\index{declaration}\n\\index{statement!declaration}\n\\index{reference}\n\nThe first line declares that \\java{blank} has type \\java{Point}.\nThe second line creates the new \\java{Point} with the coordinates $x=3$ and $y=4$.\nThe result of the \\java{new} operator is a {\\em reference} to the object.\n%So \\java{blank} contains a reference to the new \\java{Point} object.\nFigure~\\ref{fig.reference} shows the result.\n\n\\index{memory diagram}\n\\index{diagram!memory}\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/reference.pdf}\n\\caption{Memory diagram showing a variable that refers to a \\java{Point} object.}\n\\label{fig.reference}\n\\end{center}\n\\end{figure}\n\nAs usual, the name of the variable \\java{blank} appears outside the box, and its value appears inside the box.\nIn this case, the value is a reference, which is represented with an arrow.\nThe arrow points to the \\java{Point} object, which contains two variables, \\java{x} and \\java{y}.\n\n\n%\\section{Attributes}\n\n\\index{attribute}\n\\index{dot notation}\n\nVariables that belong to an object are called {\\bf attributes}.\nIn some documentation, you also see them called ``fields''.\nTo access an attribute of an object, Java uses {\\bf dot notation}.\nFor example:\n\n\\begin{code}\nint x = blank.x;\n\\end{code}\n\nThe expression \\java{blank.x} means ``go to the object \\java{blank} refers to, and get the value of the attribute \\java{x}.''\nIn this case, we assign that value to a local variable named \\java{x}.\n\nThere is no conflict between the local variable \\java{x} and the attribute \\java{x}.\nThe purpose of dot notation is to identify {\\em which} variable you are referring to unambiguously.\n\nYou can use dot notation as part of an expression.\n%slr: 12-17-19\nHere is an example:\n% height = 130 + 11 * num_lines\n\\begin{trinket} [230] {Points.java}\nimport java.awt.Point;\npublic class Points {\n    \n    public static void main(String[] args) {\n       Point blank;\n       blank = new Point(3, 4);\n       System.out.println(blank.x + \", \" + blank.y);\n       int sum = blank.x * blank.x + blank.y * blank.y;\n       System.out.println(sum);\n    }\n}\n\\end{trinket}\n%\\begin{code}\n%System.out.println(blank.x + \", \" + blank.y);\n%int sum = blank.x * blank.x + blank.y * blank.y;\n%\\end{code}\n%\n%The first line displays \\java{3, 4}.\n%The second line calculates the value \\java{25}.\n\nRun the trinket and see the result.\n\n\\textbf{Section Exercises:}\n\\begin{enumerate}\n\\item Modify the trinket \\java{Points} to compute and print the distance from the origin to the \\java{Point blank}.  (This is the square root of the sum of the squares of the x-coordinate and the y-coordiante.)\n\\item Modify the trinket \\java{Points} to create a second \\java{Point} and print out its x and y coordinates.  Experiment to determine which primitive type the x and y coordinates are.  Check your answer by looking up the Java API documentation for \\java{java.awt.Point} at \\url{https://docs.oracle.com/javase/8/docs/api/}\n\\end{enumerate}\n%slr: end 12-17-19\n\n\n\\section{Objects as Parameters}\n\n\\index{parameter}\n\\index{object!as parameter}\n\nYou can pass objects as parameters in the usual way.\nFor example:\n\n%slr: 12-17-19\n% height = 130 + 11 * num_lines\n\\begin{trinket} [270] {PointParameter.java}\nimport java.awt.Point;\npublic class PointParameter {\n    \n    public static void printPoint(Point p) {\n       System.out.println(\"(\" + p.x + \", \" + p.y + \")\");\n    }\n    \n    public static void main(String[] args) {\n       Point blank;\n       blank = new Point(3, 4);\n       printPoint(blank);\n    }\n}\n\\end{trinket}\n%\\begin{code}\n%public static void printPoint(Point p) {\n%    System.out.println(\"(\" + p.x + \", \" + p.y + \")\");\n%}\n%\\end{code}\n\nThe \\java{void} method \\java{printPoint} takes a \\java{Point} as an argument and displays its attributes in parentheses.\n%If you invoke \\java{printPoint(blank)}, it displays \\java{(3, 4)}.\n\nRun the trinket to see what is produced.\n%slr: end 12-17-19\n\nAs another example, we can rewrite the \\java{distance} method from Section~\\ref{distance} so that it takes two \\java{Point}s as parameters instead of four \\java{double}s.\n\n%slr: 12-17-19\n% height = 130 + 11 * num_lines\n\\begin{trinket} [300] {Dist1.java}\nimport java.awt.Point;\npublic class Dist1 {\n    //local method to compute distance between two Point objects\n    public static double distance(Point p1, Point p2) {\n       int dx = p2.x - p1.x;\n       int dy = p2.y - p1.y;\n       return Math.sqrt(dx * dx + dy * dy);\n    }\n    \n    public static void main(String[] args) {\n       Point p = new Point(3, 4);\n       Point q = new Point(6, 8);\n       System.out.println(\"The distance between p and q is \" + distance(p,q));\n    }\n}\n\\end{trinket}\n%\\begin{code}\n%public static double distance(Point p1, Point p2) {\n%    int dx = p2.x - p1.x;\n%    int dy = p2.y - p1.y;\n%    return Math.sqrt(dx * dx + dy * dy);\n%}\n%\\end{code}\n\nPassing objects as parameters makes the source code more readable and less error-prone because related values are bundled together.\n\nYou actually don't need to write a \\java{distance} method, because \\java{Point} objects already have one. Again, refer to the API documentation at \\url{https://docs.oracle.com/javase/8/docs/api/}. To compute the distance between two points, we invoke \\java{distance} on one and pass the other as an argument.\n\n%slr: 12-17-19\n% height = 130 + 11 * num_lines\n\\begin{trinket} [240] {Dist.java}\nimport java.awt.Point;\npublic class Dist {\n    \n    public static void main(String[] args) {\n       Point p = new Point(3, 4);\n       Point q = new Point(6, 8);\n       double dist = p.distance(q);  //Point method\n       System.out.println(\"The distance between p and q is \" + dist);\n    }\n}\n\\end{trinket}\n%\\begin{code}\n%Point p1 = new Point(0, 0);\n%Point p2 = new Point(3, 4);\n%double dist = p1.distance(p2);  // dist is 5.0\n%\\end{code}\n%slr: end 12-17-19\n\nIt turns out you don't need the \\java{printPoint} method (from the \\java{PointParameter} trinket above) either.\nIf you invoke \\java{System.out.println(blank)}, it prints the type of the object and the values of the attributes:\n\n\\begin{stdout}\njava.awt.Point[x=3,y=4]\n\\end{stdout}\n\n\\index{toString}\n\n\\java{Point} objects provide a method called \\java{toString} that returns a string representation of a point.\nWhen you call \\java{println} with objects, it {\\em automatically} calls \\java{toString} and displays the result.\n\n%slr: 12-17-19\n\\textbf{Section Exercises:}\n\\begin{enumerate}\n\\item Modify the trinket \\java{Dist} to print out the \\java{Point} objects \\java{p} and \\java{q} by calling the \\java{toString} method explicity, (for example \\java{p.toString()}).\n\\item Modify the trinket \\java{Dist} to print out the \\java{Point} objects \\java{p} and \\java{q} directly. (The \\java{println} method invokes \\java{goString} implicitly.) Interpret what is produced.  \n\\end{enumerate}\n%slr; end 12-17-19\n\n\\section{Objects as Return Values}\n\\label{sec:Rectangle}\n\n\\index{Rectangle}\n\\index{class!Rectangle}\n\nThe \\java{java.awt} package also provides a class named \\java{Rectangle}.\nTo use it, you have to import it:\n\n\\begin{code}\nimport java.awt.Rectangle;\n\\end{code}\n\n\\java{Rectangle} objects are similar to points, but they have four attributes: \\java{x}, \\java{y}, \\java{width}, and \\java{height}.\nThe following example creates a \\java{Rectangle} object and makes the variable \\java{box} refer to it:\n\n\\begin{code}\nRectangle box = new Rectangle(0, 0, 100, 200);\n\\end{code}\n\nFigure~\\ref{fig.rectangle} shows the effect of this assignment.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/rectangle.pdf}\n\\caption{Memory diagram showing a \\java{Rectangle} object.}\n\\label{fig.rectangle}\n\\end{center}\n\\end{figure}\n\nIf you run \\java{System.out.println(box)}, you get:\n\n\\begin{stdout}\njava.awt.Rectangle[x=0,y=0,width=100,height=200]\n\\end{stdout}\n\nAgain, \\java{println} uses the \\java{toString} method provided by \\java{Rectangle}, which knows how to represent \\java{Rectangle} objects as strings.\n\n\\index{return}\n\\index{statement!return}\n\nYou can also write methods that return new objects.\n%slr:  12-17-19 mods + added trinket\nFor example, the \\java{findCenter} method in the trinket below takes a \\java{Rectangle} as an argument and returns a \\java{Point} with coordinates the center of the rectangle:\n\n%slr: 12-17-19\n% height = 130 + 11 * num_lines\n\\begin{trinket} [280] {RectCenter.java}\nimport java.awt.Rectangle;\nimport java.awt.Point;\npublic class RectCenter {\n\n    public static Point findCenter(Rectangle box) {\n       int x = box.x + box.width / 2;\n       int y = box.y + box.height / 2;\n       return new Point(x, y);\n    }\n    \n    public static void main(String[] args) {\n       Rectangle rect = new Rectangle(20, 40, 100, 50);\n       Point center = findCenter(rect);  \n       System.out.println(\"The center of rect is \" + center);\n    }\n}\n\\end{trinket}\n%\\begin{code}\n%public static Point findCenter(Rectangle box) {\n%    int x = box.x + box.width / 2;\n%    int y = box.y + box.height / 2;\n%    return new Point(x, y);\n%}\n%\\end{code}\n\n%The return type of this method is \\java{Point}.\n%The last line creates a new \\java{Point} object and returns a reference to it.\n\n%The \\java{Rectangle} we created using the arguments \\java{(0, 0, 100, 200)} has its upper-left corner in the origin.\n%The center of this rectangle is \\java{(50, 100)}, which is 50 pixels to the right and 100 pixels down from the origin.\n\n\n\\textbf{Section Exercises:}\n\\begin{enumerate}\n\\item add find concentric method?  Or as a lab?\n\\end{enumerate}\n%slr: end 12-17-19\n\n\\section{Rectangles are Mutable}\n\n\\index{mutable}\n\\index{object!mutable}\n\nYou can change the contents of an object by making an assignment to one of its attributes.\nFor example, to ``move'' a rectangle without changing its size, you can modify the \\java{x} and \\java{y} values:\n\n\\begin{code}\nRectangle box = new Rectangle(0, 0, 100, 200);\nbox.x = box.x + 50;\nbox.y = box.y + 100;\n\\end{code}\n\nThe result is shown in Figure~\\ref{fig.rectangle2}.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/rectangle2.pdf}\n\\caption{Memory diagram showing updated attributes.}\n\\label{fig.rectangle2}\n\\end{center}\n\\end{figure}\n\n\\index{encapsulation}\n\\index{generalization}\n\nWe can encapsulate this code in a method and generalize it to move the rectangle by any amount:\n\n\\begin{code}\npublic static void moveRect(Rectangle box, int dx, int dy) {\n    box.x = box.x + dx;\n    box.y = box.y + dy;\n}\n\\end{code}\n\nThe variables \\java{dx} and \\java{dy} indicate how far to move the rectangle in each direction.\nInvoking this method has the effect of modifying the \\java{Rectangle} that is passed as an argument.\n\n\\begin{code}\nRectangle box = new Rectangle(0, 0, 100, 200);\nmoveRect(box, 50, 100);  // now at (50, 100, 100, 200)\n\\end{code}\n\n%The code displays \\java{java.awt.Rectangle[x=50,y=100,width=100,height=200]}.\n\nModifying objects by passing them as arguments to methods can be useful.\nBut it can also make debugging difficult, because it is not always clear which method invocations modify their arguments.\n\nJava provides a number of methods that operate on \\java{Point}s and \\java{Rectangle}s.\nFor example, \\java{translate} has the same effect as \\java{moveRect}, but instead of passing the rectangle as an argument, you use dot notation:\n\n\\begin{code}\nbox.translate(50, 100);\n\\end{code}\n\nThis line invokes the \\java{translate} method on the object that \\java{box} refers to, which modifies the object.\n\n\\index{object-oriented}\n\nThis syntax---using dot notation to invoke a method on an object, rather than passing it as a parameter---is more consistent with the style of object-oriented programming.\n\n\n\\section{Aliasing Revisited}\n\\label{aliasing}\n\n\\index{reference}\n\nRemember that when you assign an object to a variable, you are assigning a {\\em reference} to an object.\nIt is possible to have multiple variables that refer to the same object.\nFor example, this code creates two variables that refer to the same \\java{Rectangle}:\n\n\\begin{code}\nRectangle box1 = new Rectangle(0, 0, 100, 200);\nRectangle box2 = box1;\n\\end{code}\n\nFigure~\\ref{fig.aliasing} shows the result: \\java{box1} and \\java{box2} refer to the same object, so any changes that affect one variable also affect the other.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/aliasing.pdf}\n\\caption{Memory diagram showing two variables that refer to the same \\java{Rectangle} object.}\n\\label{fig.aliasing}\n\\end{center}\n\\end{figure}\n\nFor example, the following code uses \\java{grow} to make \\java{box1} bigger by 50 units in all directions.\nIt decreases \\java{x} and \\java{y} by 50, and it increases \\java{height} and \\java{width} by 100:\n\n\\begin{code}\nbox1.grow(50, 50);                // grow box1 (alias)\n\\end{code}\n\nThe result is shown in Figure~\\ref{fig.aliasing2}.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/aliasing2.pdf}\n\\caption{Memory diagram showing the effect of invoking \\java{grow}.}\n\\label{fig.aliasing2}\n\\end{center}\n\\end{figure}\n\nNow, if we print \\java{box1}, we are not surprised to see that it has changed.\n\n\\begin{code}\njava.awt.Rectangle[x=-50,y=-50,width=200,height=300]\n\\end{code}\n\nAnd if we print \\java{box2}, we should not be surprised to see that it has changed, too, because it refers to the same object:\n\n\\begin{code}\njava.awt.Rectangle[x=-50,y=-50,width=200,height=300]\n\\end{code}\n\nThis scenario is called ``aliasing'' because a single object has multiple names, or aliases, that refer to it.\n\nAs you can tell from this simple example, code that involves aliasing can get confusing fast, and it can be difficult to debug.\n\n\n\\section{Java Library Source}\n\\label{src.zip}\n\n\\index{library}\n\\index{source code}\n\nSo far we have used several classes from the Java library, including \\java{System}, \\java{String}, \\java{Scanner}, \\java{Math}, and \\java{Random}.\nThese classes are written in Java, so you can read the source code to see how they work.\n\n\\index{src.zip}\n\nThe Java library contains thousands of files, many of which are thousands of lines of code.\nThat's more than one person could read and understand fully, but don't be intimidated!\n\nBecause it's so large, the library source code is stored in a ZIP archive named \\java{src.zip}.\nIf you have Java installed on your computer, you should already have this file somewhere.\n\n\\begin{itemize}\n\\item On Linux, it's likely under: \\verb\"/usr/lib/jvm/.../lib\"\n\\\\ If not, you might have to install the {\\tt openjdk-...-source} package.\n\n\\item On MacOS, it's likely under: \\\\ \\verb\"/Library/Java/JavaVirtualMachines/.../Contents/Home/lib\"\n\n\\item On Windows, it's likely under: \\verb\"C:\\Program Files\\Java\\...\\lib\"\n\\end{itemize}\n\nWhen you open (or unzip) the file, you will see folders that correspond to Java packages.\nFor example, open the {\\tt java} folder, and then open the {\\tt awt} folder.\n(If you don't see a {\\tt java} folder at first, open the {\\tt java.desktop} folder.)\nYou should now see {\\tt Point.java} and {\\tt Rectangle.java}, along with the other classes in the \\java{java.awt} package.\n\nOpen {\\tt Point.java} in your editor and skim through the file.\nIt uses language features we haven't discussed yet, so you probably won't understand every line.\nBut you can get a sense of what professional Java source code looks like by browsing through the library.\n\n\\index{documentation}\n\\index{HTML}\n\\index{Javadoc}\n\nNotice how much of {\\tt Point.java} is documentation (see Appendix~\\ref{javadoc}).\nEach method includes comments and tags like \\java{@param} and \\java{@return}.\nJavadoc reads these comments and generates documentation in HTML.\nYou can see the same documentation online by doing a web search for ``Java Point''.\n\nNow take a look at the \\java{grow} and \\java{translate} methods in the \\java{Rectangle} class.\nThere is more to them than you may have expected.\n\n% ABD: I'm not sure these conclusions follow from the example\n\n%But that doesn't limit your ability to use these methods in a program.\n\n%Object-oriented programming makes it possible to hide messy details so that you can more easily use and understand code that other people wrote.\n\n%By looking at the source code for \\java{Point}, \\java{Rectangle}, and other classes, we hope you will learn two things.\n%1) Objects encapsulate data and provide methods to access and modify the data directly.\n\n\n\\section{Class Diagrams}\n\\label{UML}\n\nTo summarize what we've learned so far, \\java{Point} and \\java{Rectangle} objects have attributes and methods.\nAttributes are an object's {\\em data}; methods are an object's {\\em code}.\nAn object's {\\em class} definition specifies the attributes and methods that it has.\n\n\\index{UML}\n\n{\\bf Unified Modeling Language} (UML) defines a graphical way to summarize this information.\nFigure~\\ref{fig.umlPoint}, shows two examples, the {\\bf UML class diagrams} for the \\java{Point} and \\java{Rectangle} classes.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/point-rect.pdf}\n\\caption{UML class diagrams for \\java{Point} and \\java{Rectangle}.}\n\\label{fig.umlPoint}\n\\end{center}\n\\end{figure}\n\n\\index{class diagram}\n\\index{diagram!class}\n\nEach class is represented by a box with the name of the class,\na list of attributes, and a list of methods.\n\n\\index{private}\n\\index{variable!private}\n\nTo identify the types of attributes and parameters, UML uses a language-independent syntax, like {\\tt x:~int} rather than Java syntax, \\java{int x}.\n\nThe plus sign (\\java{+}) identifies \\java{public} attributes and methods.\nA minus sign (\\java{-}) identifies \\java{private} attributes and methods, which we discuss in the next chapter.\n\nBoth \\java{Point} and \\java{Rectangle} have additional methods; we only show the ones introduced in this chapter.\n\nIn contrast to memory diagrams, which visualize objects (and variables) at run-time, a class diagram visualizes the source code at compile-time.\n\n\n\\section{Scope Revisited}\n\n\\index{scope}\n\nIn Section~\\ref{stack}, we introduced the idea that variables have scope.\nThe scope of a variable is the part of a program where a variable can be used.\n\nConsider the first few lines of the \\java{Rectangle.translate} method from the Java library source code:\n\n% TODO: ML suggests adding the header line of the class and the attribute declatrations \n\n\\begin{code}\npublic void translate(int dx, int dy) {\n    int oldv = this.x;\n    int newv = oldv + dx;\n    if (dx < 0) {\n    ...\n\\end{code}\n\nThis example uses three kinds of variables:\n\n\\begin{enumerate}\n\n\\item Parameters (\\java{dx} and \\java{dy})\n\n\\item Local variables (\\java{oldv} and \\java{newv})\n\n\\index{this}\n\\item Attributes (\\java{this.x})\n\n\\end{enumerate}\n\nParameters and local variables are created in a stack frame when a method is invoked (see Figure~\\ref{fig.stack}).  The method's stack frame, and therefore its parameters and local variables, disappear when the method returns.\nThey can be used anywhere inside the method, but are not visible in other methods or in other classes.\n\nAttributes are created and stored within an object when created, and they disappear when the object is destroyed.\nThey can be used \\textit{anywhere} within the object including its methods using the keyword \\java{this} even if declared private.\nAnd if they are public, they can be used in other classes via references to the object, for example \\java{box1.x}.\n\nWhen the Java compiler encounters a variable name, it searches backwards for its declaration in ever-widening scope.\nThe compiler first looks for local variables, then parameters, then attributes.\n\n% ABD: The previous three paragraphs pack in a lot.  Some of it is a little early, and some of it is not explained carefully here.  So I think this is a soft spot to come back to in future revisions.\n\n%slr: 12-17-19.  I agree.  Slight modifications made to above three paragraphs.\n\n\n%\\section{Shadowing}\n%\n% CSM: We now discuss shadowing in Chapter 11.\n% @Deprecated is a nice idea, but unnecessary.\n%\n%It's possible to declare a local variable (or parameter) with the same name as an attribute.\n%For example, you can declare \\java{int x} in a method of the \\java{Rectangle} class.\n%In that method, the expression \\java{x + 5} will refer to the local variable, even though there is an attribute named \\java{x}.\n%\n%\\index{shadowing}\n%\n%This situation is called {\\bf shadowing}, because the local variable ``hides'' the attribute.\n%Java provides the keyword \\java{this} to refer to attributes explicitly.\n%For example, look at the \\java{Rectangle.reshape} method:\n%\n%\\begin{code}\n%@Deprecated\n%public void move(int x, int y) {\n%    this.x = x;\n%    this.y = y;\n%}\n%\\end{code}\n%\n%\\index{scope}\n%\n%The variables \\java{x} and \\java{y} are parameters of the \\java{move} method, and \\java{this.x} and \\java{this.y} are attributes of the rectangle being moved.\n%These variables have the same name, but they have different scope.\n%\n%\\index{deprecated}\n%\n%Notice that the \\java{move} method has been {\\bf deprecated}.\n%Sometimes when new versions of Java are released, the library classes are revised or enhanced.\n%The documentation for \\java{Rectangle.move} indicates that the \\java{setLocation} method should be used instead.\n%\n%The word ``deprecate'' means to express strong disapproval.\n%Java discourages using deprecated methods, either because they are dangerous, or because better alternatives exist.\n%The compiler will display a warning if you attempt to use a deprecated method.\n\n\n\\section{Garbage Collection}\n\nIn the previous section, we said that attributes exist as long as the object exists.\nBut when does an object cease to exist?\nHere is a simple example:\n\n%In Section~\\ref{aliasing}, we saw what happens when more than one variable refers to the same object.\n%What happens when {\\em no} variables refer to an object?\n\n\\begin{code}\nPoint blank = new Point(3, 4);\nblank = null;\n\\end{code}\n\nThe first line creates a new \\java{Point} object and makes \\java{blank} refer to it.\nThe second line changes \\java{blank} so that instead of referring to the object, it refers to nothing.\nAs shown in Figure~\\ref{fig.reference3}, after the second assignment, there are no references to the \\java{Point} object.\n\n% TODO: ML suggests revising this diagram to show before and after\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics{figs/reference3.pdf}\n\\caption{Memory diagram showing the effect of setting a variable to \\java{null}.}\n\\label{fig.reference3}\n\\end{center}\n\\end{figure}\n\nIf there are no references to an object, there is no way to access its attributes or invoke a method on it.\nFrom the program's point of view, it ceases to exist.\nHowever, it's still present in the computer's memory, taking up space.\n\n\\index{garbage collection}\n\nAs your program runs, the system automatically looks for stranded objects and deletes them; then the space can be reused for new objects.\nThis process is called {\\bf garbage collection}.\n%You can manually run the garbage collector by invoking \\java{System.gc()} method.\n\nYou don't have to do anything to make garbage collection happen, and in general, you don't have to be aware of it.\nBut in high-performance applications, you may notice a slight delay every now and then while Java reclaims space from discarded objects.\n\n\n\\section{Mutable vs Immutable}\n\n\\index{mutable}\n\\index{immutable}\n\n\\java{Point}s and \\java{Rectangle}s are {\\bf mutable} objects, because their attributes can be modified.\nYou can modify their attributes directly, like \\java{box.x = 15}, or you can invoke methods that modify their attributes, like \\java{box.translate(15, 0)}.\n\nIn contrast, immutable objects like \\java{String}s and \\java{Integer}s cannot be modified.\nThey don't allow direct access to their attributes or provide methods that change them.\n\nImmutable objects have a number of advantages that help improve the reliability and performance of programs.\nYou can pass strings (and other immutable objects) to methods without worrying about their contents changing as a ``side-effect'' of the method.\nThat makes programs easier to debug, and more reliable.\n\nAlso, two strings that contain the same characters can be stored in memory only once.\nThat can reduces the amount of memory the program uses, and can speed it up. \n\n% ABD: Do we want trinket markup in this version?  It seems to require cmplete class definitions, which involve code that's extraneous to the example.\n\nIn the following example, \\java{s1} and \\java{s2} are created differently, but they refer to equivalent strings; that is, the two strings contains the same characters.\n\n\\index{Surprise.java}\n\n\\begin{trinket}[200]{Surprise.java}\npublic class Surprise {\n    public static void main(String[] args) {\n        String s1 = \"Hi, Mom!\";\n        String s2 = \"Hi, \" + \"Mom!\";\n        if (s1 == s2) {                // true!\n            System.out.println(\"s1 and s2 are the same\");\n        }\n    }\n}\n\\end{trinket}\n\nBecause both strings are specified at compile time, the compiler can tell that they are equivalent.\nAnd because strings are immutable, there is no need to make two copies; the compiler can create one \\java{String} and make both variables refer to it.\n\nAs a result, the test \\java{s1 == s2} turns out to be true, which means that \\java{s1} and \\java{s2} refer to the same object.\nIn other words, they are not just equivalent; they are identical.\n\n%Since neither variable can change the string itself, both \\java{s1} and \\java{s2} will be \\java{\"Hi, Mom!\"} until they are reassigned.\n\nAlthough immutable objects have some advantages, mutable objects have other advantages.\nSometimes it is more efficient to modify an existing object, rather than creating a new one.\nAnd some computations can be expressed more naturally using mutation.\n\nNeither design is always better, which is why you will see both.\n\n\n\\section{StringBuilder Objects}\n\\label{stringbuilder}\n\nHere's an example where mutable objects are efficient and arguably more natural: building a long string by concatenating lots of small pieces.\n\nStrings are particularly inefficient for this operation.\nFor example, consider the following program, which reads ten lines from \\java{System.in} and concatenates them into a single \\java{String}.\n\n\\index{Append.java}\n\n\\begin{code}\nString text = \"\";\nfor (int i = 0; i < 10; i++) {\n    String line = in.nextLine();        // new string\n    text = text + line + '\\n';    // two more strings\n}\n\\end{code}\n\nInside the \\java{for} loop, \\java{in.nextLine()} returns a new string each time it is invoked.\nThe next line of code concatenates \\java{text} and \\java{line}, which creates another string, and then appends the newline character, which creates yet another string.\n\nAs a result, this loop creates 30 \\java{String} objects!\nAt the end, \\java{text} refers to the most recent \\java{String}.\nGarbage collection deletes the rest, but that's a lot of garbage for a seemly simple program.\n\n\\index{StringBuilder}\n\nThe Java library provides the \\java{StringBuilder} class for just this reason.\nIt's part of the \\java{java.lang} package, so you don't need to import it.\nBecause \\java{StringBuilder} objects are mutable, they can implement concatenation more efficiently.\n\nHere's a version of the program that uses \\java{StringBuilder}:\n\n%TODO: ML suggests also showing how to print the results\n%slr:  12-20-19\n% height = 130 + 11 * num_lines\n\\begin{trinket}[300]{MutableString.java}\nimport java.util.Scanner;\npublic class MutableString {\n    public static void main(String[] args) {\n       Scanner in = new Scanner(System.in);\n       StringBuilder text = new StringBuilder();\n       System.out.println(\"Enter 10 lines of lines of text followed by <return>:\");\n       for (int i = 0; i < 3; i++) {\n          String line = in.nextLine();\n          text.append(line);\n          text.append('\\n');\n       }\n       System.out.println(\"Here is what you entered:\\n\" + text);\n    }\n}\n\\end{trinket}\n%\\begin{code}\n%StringBuilder text = new StringBuilder();\n%for (int i = 0; i < 10; i++) {\n%    String line = in.nextLine();\n%    text.append(line);\n%    text.append('\\n');\n%}\n%\\end{code}\n%slr: end 12-10-19\n\nThe \\java{StringBuilder append} method takes a \\java{String} as a parameter and appends it to the end of the \\java{StringBuilder}.\nEach time it is invoked, it modifies the \\java{StringBuilder} object; it doesn't create any new objects.\n\nThe \\java{StringBuilder} class also provides methods for inserting and deleting parts of strings efficiently.\nPrograms that manipulate large amounts of text run much faster if you use \\java{StringBuilder} instead of \\java{String}.\n\n\n\\section{Vocabulary}\n\n\\begin{description}\n\n\\term{attribute}\nOne of the named data items that make up an object.\n%Each object has its own copy of the attributes for its class.\n\n\\term{dot notation}\nUse of the dot operator (\\java{.}) to access an object's attributes or methods.\n\n\\term{UML}\nUnified Modeling Language, a standard way to draw diagrams for software engineering.\n\n\\term{class diagram}\nAn illustration of the attributes and methods for a class.\n\n%\\term{deprecated}\n%A library method that has been replaced by another method, but left in the class for backwards compatibility.\n\n\\term{garbage collection}\nThe process of finding objects that have no references and reclaiming their storage space.\n\n\\term{mutable}\nAn object that can be modified at any time.\nPoints and rectangles are mutable by design.\n\n\\end{description}\n\n\n\\section{Exercises}\n\nThe code for this chapter is in the {\\tt ch10} directory of {\\tt ThinkJavaCode2}.\nSee page~\\pageref{code} for instructions on how to download the repository.\nBefore you start the exercises, we recommend that you compile and run the examples.\n\nAt this point you know enough to read Appendix~\\ref{graphics}, which is about simple 2D graphics and animations.\nDuring the next few chapters, you should take a detour to read this appendix and work through the exercises.\n\n\n\\begin{exercise}  %%V6 Ex10.1\n\nThe point of this exercise is to make sure you understand the mechanism for passing objects as parameters.\n\n\\begin{enumerate}\n\n\\item For the following program, draw a stack diagram showing the local variables and parameters of \\java{main} and \\java{riddle} just before \\java{riddle} returns.\nUse arrows to show which objects each variable references.\n\n\\item What is the output of the program?\n\n\\item Is the \\java{blank} object mutable or immutable?\nHow can you tell?\n\n\\end{enumerate}\n\n\\begin{code}\npublic static int riddle(int x, Point p) {\n    x = x + 7;\n    return x + p.x + p.y;\n}\n\\end{code}\n\n\\begin{code}\npublic static void main(String[] args) {\n    int x = 5;\n    Point blank = new Point(1, 2);\n\n    System.out.println(riddle(x, blank));\n    System.out.println(x);\n    System.out.println(blank.x);\n    System.out.println(blank.y);\n}\n\\end{code}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex10.2\n\nThe point of this exercise is to make sure you understand the mechanism for returning new objects from methods.\nThe following code uses \\java{findCenter} and \\java{distance} as defined in this chapter.\n\n\\begin{enumerate}\n\n\\item Draw a stack diagram showing the state of the program just before \\java{findCenter} returns.\nInclude all variables and parameters, and show the objects those variables refer to.\n\n\\item Draw a stack diagram showing the state of the program just before \\java{distance} returns.\nShow all variables, parameters, and objects.\n\n\\item What is the output of this program?\n(Can you tell without running it?)\n\n\\end{enumerate}\n\n\\begin{code}\npublic static void main(String[] args) {\n    Point blank = new Point(5, 8);\n\n    Rectangle rect = new Rectangle(0, 2, 4, 4);\n    Point center = findCenter(rect);\n\n    double dist = distance(center, blank);\n    System.out.println(dist);\n}\n\\end{code}\n\n\\end{exercise}\n\n\n\\begin{exercise}  %%V6 Ex10.3\n\nThis exercise is about aliasing.\nRecall that aliases are two variables that refer to the same object.\nThe following code uses \\java{findCenter} and \\java{printPoint} as defined in this chapter.\n\n\\begin{enumerate}\n\n\\item Draw a diagram that shows the state of the program just before the end of \\java{main}.\nInclude all local variables and the objects they refer to.\n\n\\item What is the output of the program?\n\n\\item At the end of \\java{main}, are \\java{p1} and \\java{p2} aliased?\nWhy or why not?\n\n\\end{enumerate}\n\n\\begin{code}\npublic static void main(String[] args) {\n    Rectangle box1 = new Rectangle(2, 4, 7, 9);\n    Point p1 = findCenter(box1);\n    printPoint(p1);\n\n    box1.grow(1, 1);\n    Point p2 = findCenter(box1);\n    printPoint(p2);\n}\n\\end{code}\n\n\\end{exercise}\n", "meta": {"hexsha": "cd811db615bc7547d898c925898e7f5f69d6ad3c", "size": 33702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch10.tex", "max_stars_repo_name": "StevenLRichardson/ThinkJava2Trinket", "max_stars_repo_head_hexsha": "540f35463dbab881cf2557553e93df28b37a4f32", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-29T10:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-29T10:05:31.000Z", "max_issues_repo_path": "ch10.tex", "max_issues_repo_name": "StevenLRichardson/ThinkJava2Trinket", "max_issues_repo_head_hexsha": "540f35463dbab881cf2557553e93df28b37a4f32", "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": "ch10.tex", "max_forks_repo_name": "StevenLRichardson/ThinkJava2Trinket", "max_forks_repo_head_hexsha": "540f35463dbab881cf2557553e93df28b37a4f32", "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.1221864952, "max_line_length": 322, "alphanum_fraction": 0.7339327043, "num_tokens": 8665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.6741171947348609}}
{"text": "\\paragraph{Nodal value interpolant}\n\\Label{sc-seio}\n\nFor any continuous function $u$, we define its linear finite element\ninterpolation, $(I_h u)(x)\\in V_{h,0}$,  as follows:\n\\begin{equation}\n  \\label{u-interp}\n(I_h u)(x)= \\sum_{i=1}^{n_h}u(x_i)\\varphi_i(x).\n\\end{equation}\nUsually, we also denote $(I_h u)(x)$ as $u_I(x)$. Using interpolation, we can obtain the following approximation property of \nlinear finite element space. \n%For any $v\\in\\Shz$, we can obviously write\n%$$\n%        v(x)=\\sum_{i=1}^{n_h}v(x_i)\\phi_i(x).\n%$$\n%The nodal value interpolation\\index{interpolation} operator $I_h: C(\\bar\\Om)\\mapsto V_h$ is defined as follows \\index{$I_h$}\n%$$\n%        (I_h u)(x_i)=u(x_i),\\qall x_i\\in {\\cal N}_h,\n%$$\n%where ${\\cal N}_h$ is the set of the vertexes for the partition $\\mathcal T_h$. \n\\begin{figure}[hpt]\n\\begin{center}\n\\includegraphics*[height=2.5in, width=3in]{figures/fdsolutions.pdf}\n\\caption{Approximation of finite element space.} \n\\label{Interpolation}\n\\end{center}\n\\end{figure}\n\n\n\\begin{theorem}\\label{interp00}\nAssume that $\\mathcal T_h$ is quasi-uniform and $V_h$ is the linear finite element space associated with $\\mathcal T_h$, then\n\\begin{equation}\n\\label{error0}\n\\inf_{v_h\\in V_h} \\|v-v_h\\|+h |v-v_h|_{1}\\lc h^2 |v|_2\n        \\qall v\\in H^2(\\Om).\n\\end{equation}\n \\end{theorem}\n \\begin{proof}  \nLet us first prove Theorem \\ref{interp00} for $d=1, 2, 3$.\nThis proof presented here follows from Xu~\\cite{xu1982estimate} (see also Xu~\\cite{xu2013estimate}).\nLet $x=(x^1,\\ldots, x^d)$ and $a_i=(a^1_{i}, \\ldots, a^d_{i})$. Introducing\nthe auxiliary functions\n$$\ng_i(t)=v(a_i(t)),\\mbox{  with  }  a_i(t)=a_i+t(x-a_i),\n$$\nwe have\n$$\ng_i'(t)=(\\nabla v)(a_i(t))\\cdot (x-a_i)\n=\\sum_{l=1}^d(\\partial_lv)(a_i(t))(x^l-a_i^l)\n$$\nand\n\\begin{equation}\\label{gpp}\ng_i''(t)=\\sum_{k,l=1}^d\\partial^2_{kl}v)(a_i(t))(x^k-a_i^k)(x^l-a_i^l).\n\\end{equation}\nNote Taylor expansion\n$$\n        g_i(0)=g_i(1)-g_i'(1)+\\int_0^1tg''_i(t)dt,\n$$\nnamely\n\\begin{equation}\\label{Taylor_vi}\nv(a_i)=v(x)-(\\nabla v)(x)\\cdot (x-a_i)+\\int_0^1tg''_i(t)dt,\n\\end{equation}\nand note that\n$$\n(I_hv)(x)=\\sum_{i=1}^{d+1}v(a_i)\\lambda_i(x), \\quad \\sum_{i=1}^{d+1}\\lambda_i(x)=1,\n$$\nand\n$$\n\\sum_{i=1}^{d+1}(x-a_i)\\lambda_i(x)=0.\n$$\nIt follows that\n\\begin{equation}\\label{Ihvv}\n(I_hv-v)(x)=\\sum_{i=1}^{d+1}\\lambda_i(x)\\int_0^1tg''_i(t)dt.\n\\end{equation}\nUsing \\rf{gpp} and the trivial fact that $|x^l-a_i^l|\\le h$,\nwe obtain\n\\begin{eqnarray*}\n\\|g''_i(t)\\|_{L^2(\\tau)}\\le h^2\n\\sum_{k,l=1}^d\\|(\\partial^2_{kl}v)(a_i(t))\\|_{L^2(\\tau_i^t)}\n\\le h^2t^{-d/2}\\sum_{k,l=1}^d\\|\\partial^2_{kl}v\\|_{L^2(\\tau)},\n\\end{eqnarray*}\nwhere we have used the following change of variable\n$$\ny=a_i+t(x-a_i): \\tau\\mapsto \\tau_i^t\\subset\\tau \\mbox{ with } dy=t^ddx.\n$$\nNow taking the $L^2(\\tau)$ norm on both hand of sides of\n\\rf{Ihvv}, we get\n\\begin{eqnarray*}\n\\|I_hv-v\\|_{L^2(\\tau)}\n&\\le& h^2\\sum_{i=1}^{d+1}\\max_{x\\in\\tau}|\\lambda_i(x)|\n\\int_0^1t\\|g''_i(t)\\|_{L^2(\\tau)}\\;dt\\\\\n&\\le& (d+1)\\int_0^1t^{-d/2}dt\\;h^2\\;\n\\sum_{k,l=1}^d\\|\\partial^2_{kl}v\\|_{L^2(\\tau)}\\\\\n&\\le&\\frac{2(d+1)}{4-d}h^2\n\\sum_{k,l=1}^d\\|\\partial^2_{kl}v\\|_{L^2(\\tau)}\\\\\n&\\le&\\frac{4d(d+1)}{4-d}h^2|v|_{H^2(\\tau)}.\n\\end{eqnarray*}\nNow we prove the $H^1$ error estimate. Notice that\n$$\n[\\partial_{j}( I_{h} v - v)](x) = \\sum_{i} (\\partial_{j} \\lambda_{i} )(x) \\int_{0}^{1} t g''_{i}(t) dt + \\sum_{i} \\lambda_{i}(x) \\partial_{j} \\int_{0}^{1} t g''_{i}(t) dt.\n$$ \nBy \\rf{Taylor_vi},\n$$\n\\int_0^1tg''_i(t)dt = v(a_i) - v(x) + (\\nabla v)(x)\\cdot (x-a_i)\n$$\ntherefore,\n\\begin{eqnarray*}\n\\lefteqn{\\partial_{j} \\int_0^1tg''_i(t)dt} \\\\\n& = & - \\partial_{j} v + (\\nabla \\partial_{j} v )(x) (x - a_{i}) + \\nabla v \\cdot e_{j} \n\\hcomment{$e_{j}$ is the $j$-th standard basis}  \\\\\n& = & (\\nabla \\partial_{j} v )(x) (x - a_{i}).\n\\end{eqnarray*}\nNoting that $\\sum_{i} \\lambda_{i}( \\nabla \\partial_{j} v )(x) (x - a_{i}) = 0$, we have\n$$\n[\\partial_{j}( I_{h} v - v)](x) = \\sum_{i} (\\partial_{j} \\lambda_{i} )(x) \\int_{0}^{1} t g''_{i}(t) dt.\n$$\nThen the estimate for $|\\nabla(I_hv-v)|_{L^2(\\tau)}$\nfollows by a similar argument and the following obvious\nestimate\n$$\n|(\\nabla\\lambda_i)(x)|\\lc\\frac{1}{h}.\n$$\n \nOn the proof of Theorem \\ref{interp0} for $d\\ge 4$, the above proof does not\napply for $d \\ge 4$. This is because when $d \\ge 4$, the embedding\nrelation between $H^{2}(\\Om) \\hookrightarrow C(\\bar{\\Om})$ is no longer true.  Only\ncontinuous functions can have interpolations. In this case, one approach is to use the \nso-called Scott-Zhang interpolation \\cite{scott1990finite}, the\ndetails can be found in \\cite{Xu.J2015a}.\n\\end{proof}\nAs a result of Theorem \\ref{interp00}, we have\n\\begin{theorem}\\label{interp0}\nLet $V_N$ be linear finite element space on a quasi-uniform\ntriangulation consisting of $N$ element.  Then \n\\begin{equation}\n\\label{error0N}\n\\inf_{v_h\\in V_N} \\|v-v_h\\|+N^{-{1\\over d}} |v-v_h|_{1}\\lc N^{-{2\\over d}} |v|_2\n        \\qall v\\in H^2(\\Om).\n\\end{equation}\n\\end{theorem}\n\n\n\n", "meta": {"hexsha": "0826d91ee4570890307ca9b30b1b58d15fa07756", "size": 4912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/6 Finite Element Method/6.2-Nodal-Interpolation.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.2-Nodal-Interpolation.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.2-Nodal-Interpolation.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1111111111, "max_line_length": 171, "alphanum_fraction": 0.6370114007, "num_tokens": 2110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6741073870971394}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 7}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\nMost of our study of probability has dealt with independent trials processes, in which we have i.i.d. random variables $X_i$. This is useful for modeling and sampling situations. But when study random dynamical systems, they are less useful. In these cases, $\\{X_i\\}$ are no longer independent because they are all part of the system, and they have to interact with each other. So one way to modeling this is to use conditional probability. \n\n\\section{Markov chains: basic definitions}\nConsider a countable sequence $X_1, X_2, \\dots, X_n, \\dots$ which \n\\begin{itemize}\n    \\item the subscript represents time, thus we have discrete time sequence;\n    \\item each $X_i$ has finite outcomes.\n\\end{itemize}\nIn other words, each $X_i$ is a discrete random variable that takes one of $N$ possible values, where \n$N = \\card(S)$ and $S$ is the outcome space; it may be the case that $N = \\infty$.\n\n\\begin{definition}\nThe process $X$ is a \\textbf{Markov chain} if it satisfies the \\textbf{Markov condition}:\n\\begin{equation*}\n    \\Prob\\left(X_{n}=s | X_{1}=x_{1}, X_{2}=x_{2}, \\ldots, X_{n-1}=x_{n-1}\\right)=\\Prob\\left(X_{n}=s | X_{n-1}=x_{n-1}\\right)\n\\end{equation*}\nfor all $n\\geq 1$ ans all $s, x_1, \\dots, x_{n-1} \\in S$.\n\\end{definition}\nSince $S$ is assumed countable, it can be put in one-to-one correspondence with some subset $S'$ of the integers, and without loss of generality we can assume that $S$ is this set $S'$ of integers. Then the evolution of a chain is described by its \\textbf{transition probabilities} \n\\begin{equation}\n    \\label{eq:7.1}\n    \\tag{7-1}\n    \\Prob(X_{n} = j \\spacevert X_{n-1} = i) := p_{ij}(n-1).\n\\end{equation}\n\n\\begin{theorem}\nThe transition matrix $P$ is a \\textbf{stochastic matrix}, which is to say that: \n\\begin{enumerate}[(a)]\n    \\item $P$ has non-negative entries, or $p_{ij} \\geq 0$ for all $i, j$, \n    \\item $P$ has row sums equal to one, or $\\sum_j p_{ij} = 1$ for all $i$.\n\\end{enumerate}\n\\end{theorem}\n\n%Note that the Markov property is equivalent to the following stipulation, which is also called \\textbf{$k$-step transition probabilities}.\n\n\\begin{definition}\nThe \\textbf{$k$-step transition probabilities} is defined as\n\\begin{equation}\n    \\label{eq:7.2}\n    \\tag{7-2}\n    \\Prob(X_{n+k-1} = j \\spacevert X_{n-1} = i) := p_{ij}^{(k)}(n-1) \\quad \\text{for any } n, k \\geq 1.\n\\end{equation}\n\\end{definition}\n\n%Based on this, we can define\n\\begin{definition}\nThe \\textbf{transition matrix} $P(n-1) = (p_{ij}(n-1))$ is the $\\abs{S} \\times \\abs{S}$ matrix of \\textbf{transition probabilities} $p_{ij}(n-1)$. The \\textbf{$k$-step transition matrix} $P^{(k)}(n-1) = (p_{ij}^{(k)}(n-1))$ is the matrix of \\textbf{$k$-step transition probabilities} $p_{ij}^{(k)}(n-1)$.\n\\end{definition}\n\n\\begin{remark}\nWe can check that the Markov property is equivalent to each of the following two stipulations: for each $s \\in S$ and for every sequence $\\{ x_i \\spacevert i \\geq 0\\}$ in $S$,\n\\begin{equation}\n    \\label{eq:7.3a}\n    \\tag{7-3a}\n    \\begin{split}\n        \\Prob\\left(X_{n+1}=s | X_{n_{1}}=x_{n_{1}}, X_{n_{2}}=x_{n_{2}}, X_{n_{k}}=x_{n_{k}}\\right)=\\Prob\\left(X_{n+1}=s | X_{n_{k}}=x_{n_{k}}\\right) \\\\\n        \\text{for all } n_1 < n_2 < \\cdots < n_k \\leq n.\n    \\end{split}\n\\end{equation}\n\\begin{equation}\n    \\label{eq:7.3b}\n    \\tag{7-3b}\n    \\begin{split}\n        \\Prob\\left(X_{m+n}=s | X_{0}=x_{0}, X_{1}=x_{1}, \\ldots, X_{m}=x_{m}\\right)=\\Prob\\left(X_{m+n}=s | X_{m}=x_{m}\\right) \\\\ \n        \\text{for any } m, n \\geq 0.\n    \\end{split}\n\\end{equation}\n\\end{remark}\n\nNext we introduce another assumption:\n\\begin{definition}\nThe chain $X$ is called \\textbf{homogeneous} if\n\\begin{equation*}\n    \\Prob(X_n = j \\spacevert X_{n-1} = i) = \\Prob(X_2 = j \\spacevert X_1 = i), \\quad \\text{for all } n, i, j.\n\\end{equation*}\n\\end{definition}\n\n\\begin{remark}\nNote the following two remarks.\n\\begin{enumerate}[(a)]\n    \\item Markov property and homogeneity property are \\textbf{independent}. There are also Markov chains which are not homogeneous. \n    \\item If a Markov chain $X$ is homogeneous, then $p_{ij}(n-1)$ doesn't depends on the time $(n-1)$, \\ie, the probability transition matrix $P$ is \\textbf{fixed} at each step.\n\\end{enumerate}\n\\end{remark}\n\n\\section{Properties of Markov chains}\nBy the assumption of homogeneity, we know $P(n-1) = P$. That $P^{(k)}(n-1)$ doesn't depend on $(n-1)$ is a consequence of the following important fact.\n\n\\begin{theorem}[Chapman-Kolmogorov equations]\n\\begin{equation*}\n    p_{ij}^{(n+r)}(m) = \\sum_{k} p_{ik}^{(n)}(m) p_{kj}^{(r)}(m+n).\n\\end{equation*}\nTherefore, \n\\begin{equation*}\n    P^{(n+r)}(m) = P^{(n)}(m) P^{(r)}(m+n).\n\\end{equation*}\nFurthermore, if we have homogeneity, then \n\\begin{equation*}\n    P^{n}(m) = P^n,\n\\end{equation*}\nthe $n$th power of $P$.\n\\end{theorem}\n\n\\begin{proof}\n    \\begin{equation*}\n        \\begin{split}\n            p_{ij}^{n+r}(m) &= \\Prob(X_{m+n+r} = j \\spacevert X_m = i) \\\\ \n            &= \\sum_{k} \\Prob(X_{m+n+r} = j, X_{m+n} = k \\spacevert X_m = i) \\\\\n            &= \\sum_{k} \\Prob(X_{m+n+r} = j \\spacevert X_{m+n} = k, X_m = i) \\Prob(X_{m+n} = k \\spacevert X_m = i) \\quad \\text{(marginalization)} \\\\\n            &= \\sum_{k} \\Prob(X_{m+n+r} = j \\spacevert X_{m+n} = k) \\Prob(X_{m+n} = k \\spacevert X_m = i) \\quad \\text{(Markov property)} \\\\\n            &= \\sum_{k} p_{kj}^{(r)}(m+n) p_{ik}^{(n)}(m) . \n        \\end{split}\n    \\end{equation*}\n    The marginalization step uses the fact that \n    \\begin{equation*}\n        \\Prob(A \\cap B \\spacevert C) = \\Prob(A \\spacevert B \\cap C) \\Prob(B \\spacevert C).\n    \\end{equation*}\n    The Markov property step uses \\eqref{eq:7.3a}. The $n$th power is obtained by iteration.\n\\end{proof}\n\nOne consequence of the preceding theorem is that $P^{(n)}(m) = P^{(n)}(0)$. Note that this consequence is obtained \\textbf{with homogeneous assumption}. We write $P_n$ for $P^{(n)}(m)$ and $p_{ij}(n)$ for $p_{ij}^{(n)}(m)$. This theorem relates long-term development to short-term development, and tells us how $X_n$ depends on the initial variable $X_0$. Let $\\mu_i^{(n)} = \\Prob(X_n = i)$ be the mass function of $X_n$, and write $\\mu^{(n)}$ for the \\textbf{row vector} with entries $(\\mu_i^{(n)} : i \\in S)$. Then we have the following lemma.\n\n\\begin{lemma}\n$\\mu^{(m+n)} = \\mu^{(m)}P_n$, and hence $\\mu^{(n)} = \\mu^{(0)}P^n$.\n\\end{lemma}\n\n\\begin{proof}\n    We have that\n    \\begin{equation*}\n        \\begin{split}\n            \\mu_j^{(m+n)} &= \\Prob(X_{m+n} = j) \\\\\n            &= \\sum_{i} \\Prob(X_{m+n} = j \\spacevert X_m = i) \\Prob(X_m = i) \\\\\n            &= \\sum_{i} \\mu_i^{(m)} p_{ij}(n) \\\\\n            &= (\\mu^{(m)} P_n)_j\n        \\end{split}\n    \\end{equation*}\n    and the result follows from the preceding theorem.\n\\end{proof}\n\nThe random evolution of the chain is determined by the transition matrix $P$ and the initial mass function $\\mu^{(0)}$.\n\n\n\\section{Absorbing Markov chains}\nAn absorbing Markov chain is a special type of Markov chains.\n\n\\begin{definition}\nA state $s_i$ of a Markov chain is called \\textbf{absorbing} if it is impossible to leave it (\\ie, $p_{ii} = 1$). A Markov chain is \\textbf{absorbing} if it has at least one absorbing state, and if from every state it is possible to go to an absorbing state (not necessarily in one step).\n\\end{definition}\n\n\\begin{definition}\nIn an absorbing Markov chain, a state which is not absorbing is called \\textbf{transient}.\n\\end{definition}\n\n\\subsection{Canonical form of absorbing Markov chains}\nConsider an arbitrary absorbing Markov chain. Renumber the states so that the transient states come first. If there are $r$ absorbing states and $t$ transient states, the transition matrix will have the following canonical form\n\\begin{equation*}\n    P = \n    \\begin{blockarray}{rcc}\n        & TR. & ABS. \\\\\n    \\begin{block}{r[cc]}\n        TR. & Q &  R \\\\\n        ABS. & 0 &  I \\\\\n    \\end{block}\n    \\end{blockarray}\n\\end{equation*}\nHere $I$ is an $r\\times r$ identity matrix, $0$ is an $r\\times t$ zero matrix, $R$ is a nonzero $t\\times r$ matrix, and $Q$ is an $t\\times t$ matrix. The first $t$ states are transient and the last $r$ states are absorbing.\n\nA standard matrix algebra argument shows that $P^n$ is of the form\n\\begin{equation*}\n    P^n = \n    \\begin{blockarray}{rcc}\n        & TR. & ABS. \\\\\n    \\begin{block}{r[cc]}\n        TR. & Q^n &  * \\\\\n        ABS. & 0 &  I \\\\\n    \\end{block}\n    \\end{blockarray}\n\\end{equation*}\nwhere the asterisk $*$ stands for the $t\\times r$ matrix in the upper right-hand corner of $P^n$. \n\nThe entries of $Q_n$ give the probabilities for being in each of the transient states after $n$ steps for each possible transient starting state. The following theorem will show that every entry of $Q_n$ will approach zero as $n$ approaches infinity (\\ie, $Q_n \\to 0$).\n\n\\begin{theorem}\nIn an absorbing Markov chain, the probability that the process will be absorbed is 1 (\\ie, $Q_n \\to 0$ as $n \\to \\infty$).\n\\end{theorem}\n\n\\begin{proof}\nFrom each non-absorbing state $s_j$ it is possible to reach an absorbing state. Let $m_j$ be the minimum number of steps required to reach an absorbing state, starting from $s_j$. Let $p_j$ be the probability that, starting from $s_j$, the process will not reach an absorbing state in $m_j$ steps. Then $p_j < 1$. Let $m$ be the largest of the $m_j$ and let $p$ be the largest of $p_j$. The probability of not being absorbed in $m$ steps is less than or equal to $p$, in $2m$ steps less than or equal to $p^2$, etc. Since $p < 1$, these probabilities tend to 0. Since the probability of not being absorbed in $n$ steps is monotone decreasing, these probabilities also tend to 0, hence $\\lim_{n\\to\\infty} Q_n = 0$.\n\\end{proof}\n\n\\subsection{The fundamental matrix}\n\\begin{definition}\nFor an absorbing Markov chain $P$, the matrix $N = (I-Q)^{-1}$ is called the \\textbf{fundamental matrix} for $P$. The entry $n_{ij}$ of $N$ gives the expected number of times that the process is in the transient state $s_j$ if it is started in the transient state $s_i$.\n\\end{definition}\n\n\\begin{theorem}\nFor an absorbing Markov chain the matrix $I-Q$ has an inverse $N$ and $N = I + Q + Q^2 + \\cdots$. The $ij$-entry $n_{ij}$ of the matrix $N$ is the expected number of times the chain is in state $s_j$, given that it starts in state $s_i$. The initial state is counted if $i = j$.\n\\end{theorem}\n\n\\begin{proof}\nLet $(I-Q)x = 0$; that is $x = Qx$. Then, iterating this we see that $x = Q^n x$. Since $Q_n \\to 0$, we have $Q_n x \\to 0$, so $x = 0$. Thus $(I-Q)^{-1} = N$\nexists. Note next that\n\\begin{equation*}\n    (I-Q)(I+Q + Q^2 + \\cdots + Q^n) = I - Q^{n+1}.\n\\end{equation*}\nThus multiplying both sides by $N$ gives\n\\begin{equation*}\n    I + Q + Q^2 + \\cdots + Q^n = N(I-Q^{n+1}) .\n\\end{equation*}\nLetting $n$ tend to infinity we have\n\\begin{equation*}\n    N = I + Q + Q^2 + \\cdots .\n\\end{equation*}\nLet $s_i$ and $s_j$ be two transient states, and assume throughout the remainder of the proof that $i$ and $j$ are fixed. Let $X^{(k)}$ be a random variable which equals 1 if the chain is in state $s_j$ after $k$ steps, and equals 0 otherwise. For each $k$, this random variable depends upon both $i$ and $j$; we choose not to explicitly show this dependence in the interest of clarity. We have\n\\begin{equation*}\n    \\Prob \\left(X^{(k)}=1\\right)=q_{i j}^{(k)},\n\\end{equation*}\nand \n\\begin{equation*}\n    \\Prob \\left(X^{(k)}=0\\right)=1-q_{i j}^{(k)},\n\\end{equation*}\nwhere $q_{i j}^{(k)}$ is the $ij$th entry of $Q^k$. These equations hold for $k = 0$ since $Q^0 = I$. Therefore, since $X^{(k)}$ is a 0-1 random variable, $\\Exp(X^{(k)}) = q_{i j}^{(k)}$.\n\nThe expected number of times the chain is in state $s_j$ in the first $n$ steps, given that it starts in state $s_i$, is clearly\n\\begin{equation*}\n    \\Exp\\left(X^{(0)}+X^{(1)}+\\cdots+X^{(n)}\\right)=q_{i j}^{(0)}+q_{i j}^{(1)}+\\cdots+q_{i j}^{(n)}.\n\\end{equation*}\nLetting $n$ tend to infinity we have\n\\begin{equation*}\n    \\Exp\\left(X^{(0)}+X^{(1)}+\\cdots\\right)=q_{i j}^{(0)}+q_{i j}^{(1)}+\\cdots=n_{i j}.\n\\end{equation*}\n\\end{proof}\n\n\n\\subsection{Time to absorption}\nGiven that the chain starts in state $s_i$, what is the expected number of steps before the chain is absorbed? The following theorem gives the answer.\n\\begin{theorem}\nLet $t_i$ be the expected number of steps before the chain is absorbed, given that the chain starts in state $s_i$, and let $t$ be the \\textbf{column vector} whose $i$th entry is $t_i$. Then\n\\begin{equation*}\n    t = N \\1\n\\end{equation*}\nwhere $\\1$ is a column vector all of whose entries are 1.\n\\end{theorem}\n\n\\begin{proof}\nIf we add all the entries in the $i$th row of $N$, we will have the expected number of times in any of the transient states for a given starting state $s_i$, that is, the expected time required before being absorbed. Thus, $t_i$ is the sum of the entries in the $i$th row of $N$. If we write this statement in matrix form, we obtain the theorem.\n\\end{proof}\n\n\\subsection{Absorption probabilities}\n\\begin{theorem}\nLet $b_{ij}$ be the probability that an absorbing chain will be absorbed in the absorbing state $s_j$ if it starts in the transient state $s_i$. Let $B$ be the matrix with entries $b_{ij}$ . Then $B$ is an $t\\times r$ matrix, and\n\\begin{equation*}\n    B = NR,\n\\end{equation*}\nwhere $N$ is the fundamental matrix and $R$ is as in the canonical form.\n\\end{theorem}\n\n\\begin{proof}\nWe have \n\\begin{equation*}\n    \\begin{aligned} \n        B_{i j} &=\\sum_{n} \\sum_{k} q_{i k}^{(n)} r_{k j} \\\\ &=\\sum_{k} \\sum_{n} q_{i k}^{(n)} r_{k j} \\\\ &=\\sum_{k} n_{i k} r_{k j} \\\\ &=(N R)_{i j}.\n    \\end{aligned}\n\\end{equation*}\nThis completes the proof.\n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "c29e9086f219e8376bc565ac98bf7198ce0e9ba5", "size": 13812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_7.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_7.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_7.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": 49.3285714286, "max_line_length": 713, "alphanum_fraction": 0.6568201564, "num_tokens": 4635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8221891218080991, "lm_q1q2_score": 0.674107381831063}}
{"text": "\\section{Fundamentals of Estimation}\n%This section is under Jazz-\\work\\\\{\\scriptsize [and will evolve from face-to-face interactions with students of mathematics at Uppsala University]}.\n\n\\subsection{Introduction}\nNow that we have been introduced to two notions of convergence for RV sequences, we can begin to appreciate the basic limit theorems used in statistical inference.  The problem of estimation is of fundamental importance in statistical inference and learning.  We will formalise the general estimation problem here.  There are two basic types of estimation.  In point estimation we are interested in estimating a particular point of interest that is supposed to belong to a set of points.  In (confidence) set estimation, we are interested in estimating a set with a particular form that has a specified probability of ``trapping'' the particular point of interest from a set of points.  Here, a point should be interpreted as an element of a collection of elements from some space.\n\n\\subsection{Point Estimation}\\label{S:PointEstimation}\n{\\bf Point estimation} is any statistical methodology that provides one with a ``{\\bf single best guess}'' of some specific quantity of interest.  Traditionally, we denote this {\\bf quantity of interest as $\\theta^*$} and {\\bf its point estimate as $\\widehat{\\theta}$ or $\\widehat{\\theta}_n$}.  The subscript $n$ in the point estimate $\\widehat{\\theta}_n$ emphasises that our estimate is based on $n$ observations or data points from a given statistical experiment to estimate $\\theta^*$.  This quantity of interest, which is usually unknown, can be: %, namely $\\theta$\n%, may be an {\\bf integral} $\\Iz$ of a real valued function $h(x)$, i.e.~$\\theta=\\Iz := \\int_a^b h(x)\\,dx \\in \\Rz$, or simply a \n\\begin{itemize}\n\\item an {\\bf integral} $\\vartheta^* := \\int_A h(x)\\,dx \\in \\BB{\\varTheta}$.  If $\\vartheta^*$ is finite, then $\\BB{\\varTheta} =  \\Rz$, or %  For e.g.~see \\ref{S:BMC} on Monte Carlo integration.\n\\item a {\\bf parameter} $\\theta^*$ which is an element of the {\\bf parameter space} $\\BB{\\Theta}$, denoted $\\theta^* \\in \\BB{\\Theta}$,\n\\item a {\\bf distribution function (DF)} $F^* \\in \\Fz := \\text{the set of all DFs}$\n\\item a {\\bf density function (pdf)} $f \\in \\{ \\text{``not too wiggly Sobolev functions''} \\}$, or \n\\item a {\\bf regression function} $g^* \\in \\Gz$, where $\\Gz$ is a class of regression functions in a regression experiment with model: $Y=g^*(X)+\\epsilon$, such that $\\E(\\epsilon)=0$, from pairs of observations $\\{(X_i,Y_i)\\}_{i=1}^n$, or\n\\item a {\\bf classifier} $g^* \\in \\Gz$, i.e.~a regression experiment with discrete $Y = g^*(X)+\\epsilon$, or \n\\item a {\\bf prediction} in a regression experiment, i.e.~when you want to estimate $Y_i$ given $X_i$. \n\\end{itemize}\n%\\begin{table}[htpb]\n%\\begin{center}\n%\\begin{tabular}{|c c c|}\n%\\hline\n%Quantity of Interest $\\theta$ & Point Estimation & Sections \\\\ \\hline\n%Parameter $\\theta \\in \\BB{\\Theta} \\subset \\Rz^n$ & Parametric Estimation & Section~\\ref*{S:ParametricEstimation} \\\\\n%Integral $\\Iz := \\int_a^bh(x)\\,dx$ & Monte Carlo Integration & Section~\\ref*{S:BMC} \\\\ \\hline\n%\\end{tabular}\n%\\end{center}\n%\\end{table}\n\nRecall that a statistic is an RV $T(X)$ that maps every data point $x$ in the data space $\\Xz$ with $T(x)=t$ in its range $\\Tz$, i.e.~$T(x):\\Xz \\to \\Tz$ (\\hyperref[D:Statistic]{Definition~\\ref*{D:Statistic}}).  Next, we look at a specific class of statistics whose range is the parameter space $\\BB{\\Theta}$.\n\\begin{definition}[Point Estimator]\\label{D:Estimator}\nA {\\bf point estimator} $\\widehat{\\Theta}$ of some {\\bf fixed and possibly unknown} $\\theta^* \\in \\BB{\\Theta}$ is a statistic that associates each data point $x \\in \\Xz$ with an estimate $\\widehat{\\Theta}(x)=\\widehat{\\theta} \\in \\BB{\\Theta}$,  \n\\[\n\\boxed{\n \\widehat{\\Theta} := \\widehat{\\Theta}(x)=\\widehat{\\theta}: \\Xz \\to \\BB{\\Theta}\n } \\ .\n\\]\nIf our data point $x := (x_1,x_2,\\ldots,x_n)$ is an $n$-vector or a point in the $n$-dimensional real space, i.e.~$x := (x_1,x_2,\\ldots,x_n) \\in \\Xz_n \\subset \\Rz^n$, then we emphasise the dimension $n$ in our point estimator $\\widehat{\\Theta}_n$ of $\\theta^* \\in \\BB{\\Theta}$.\n\\[\n\\boxed{\n\\widehat{\\Theta}_n :=  \\widehat{\\Theta}_n(x:=(x_1,x_2,\\ldots,x_n))=\\widehat{\\theta}_n : \\Xz_n \\to \\BB{\\Theta}, \\quad \\Xz_n \\subset \\Rz^n \n} \\ .\n\\]\n The typical situation for us involves point estimation of $\\theta^* \\in \\BB{\\Theta}$ on the basis of one realisation $x \\in\\Xz_n \\subset \\Rz^n$ of an independent and identically distributed (IID) random vector $X=(X_1,X_2,\\ldots,X_n)$, such that $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} X_1$ and the DF of $X_1$ is $F(x_1; \\theta^*)$, i.e.~the distribution of the IID RVs, $X_1, X_2,\\ldots,X_n$, is parameterised by $\\theta^* \\in \\BB{\\Theta}$.\n\\end{definition}\n\n\\begin{example}[Coin Tossing Experiment ($X_1,\\ldots,X_n \\overset{IID}{\\sim} \\bernoulli(\\theta^*)$)]\\label{EX:CoinTossing}\nI tossed a coin that has an unknown probability $\\theta^*$ of landing Heads independently and identically $10$ times in a row.  Four of my outcomes were Heads and the remaining six were Tails, with the actual sequence of Bernoulli outcomes (Heads $\\to 1$ and Tails $\\to 0$) being $(1,0,0,0,1,1,0,0,1,0)$.  I would like to estimate the probability $\\theta^* \\in \\BB{\\Theta} = [0,1]$ of observing Heads using the natural estimator $\\widehat{\\Theta}_n((X_1,X_2,\\ldots,X_n))$ of $\\theta^*$:\n\\[\n\\widehat{\\Theta}_n((X_1,X_2,\\ldots,X_n)) := \\widehat{\\Theta}_n = \\frac{1}{n} \\sum_{i=1}^n X_i =: \\overline{X}_n\n\\]\nFor the coin tossing experiment I just performed ($n=10$ times), the point estimate of the unknown $\\theta^*$ is:\n\\begin{eqnarray}\n\\widehat{\\theta}_{10} = \\widehat{\\Theta}_{10}((x_1,x_2,\\ldots,x_{10})) \n&=&\\widehat{\\Theta}_{10}((1,0,0,0,1,1,0,0,1,0)) \\notag \\\\\n&=& \\frac{1+0+0+0+1+1+0+0+1+0}{10}=\\frac{4}{10}=0.40 \\notag \\ .\n\\end{eqnarray}\n\\end{example}\n\n\\begin{labwork}[$\\bernoulli(38/75)$ Computer Experiment]\\label{LW:1000CoinTossingExp}\nSimulate one thousand IID samples from a $\\bernoulli(\\theta^*=38/75)$ RV and store this data in an array called $\\tt Samples$.  Use your student ID to initialise the fundamental sampler.  Now, pretend that you don't know the true $\\theta^*$ and estimate $\\theta^*$ using our estimator $\\widehat{\\Theta}_n=\\overline{X}_n$ from the data array $\\tt Samples$ for each sample size $n=1,2,\\ldots,1000$.  Plot the one thousand estimates $\\widehat{\\theta}_1,\\widehat{\\theta}_2,\\ldots,\\widehat{\\theta}_{1000}$ as a function of the corresponding sample size.  Report your observations regarding the behaviour of our estimator as the sample size increases.\n\\end{labwork}\n\n\\subsection{Some Properties of Point Estimators}\\label{S:PropPointEstim}\nGiven that an estimator is merely a function from the data space to the parameter space, we need choose only the best estimators available.  Recall that a point estimator $\\widehat{\\Theta}_n$, being a statistic or an RV of the data has a probability distribution over its range $\\BB{\\Theta}$.  This distribution over $\\BB{\\Theta}$ is called the {\\bf sampling distribution} of $\\widehat{\\Theta}_n$.  Note that the sampling distribution not only depends on the statistic $\\widehat{\\Theta}_n := \\widehat{\\Theta}_n(X_1,X_2,\\ldots,X_n)$ but also on $\\theta^*$ which in turn determines the distribution of the IID data vector $(X_1,X_2,\\ldots,X_n)$.  The following definitions are useful for selecting better estimators from some lot of them.\n\n\\begin{definition}[Bias of a Point Estimator]\\label{D:Bias}\nThe $\\mathsf{bias}_n$ of an estimator $\\widehat{\\Theta}_n$ of  $\\theta^* \\in \\BB{\\Theta}$ is:\n\\begin{equation}\\label{E:Bias}\n\\boxed{\n\\mathsf{bias}_n=\\mathsf{bias}_n(\\widehat{\\Theta}_n) := \\E_{\\theta^*}(\\widehat{\\Theta}_n) - \\theta^* = \\int_{\\Xz_n} \\widehat{\\Theta}_n(x) \\, dF(x;\\theta^*) - \\theta^*\n}\n \\ .\n\\end{equation} \nWe say that the estimator $\\widehat{\\Theta}_n$ is {\\bf unbiased} if $\\mathsf{bias}_n(\\widehat{\\Theta}_n)=0$ or if $\\E_{\\theta^*}(\\widehat{\\Theta}_n)=\\theta^*$ for every $n$.  If $\\lim_{n \\to \\infty}\\mathsf{bias}_n(\\widehat{\\Theta}_n)=0$, we say that the estimator is {\\bf asymptotically unbiased}.\n\\end{definition}\nSince the expectation of the sampling distribution of the point estimator $\\widehat{\\Theta}_n$ depends on the unknown $\\theta^*$, we emphasise the $\\theta^*$-dependence by $\\E_{\\theta^*}(\\widehat{\\Theta}_n)$.\n\n\\begin{example}[Bias of our Estimator of $\\theta^*$]\\label{EX:BiasEstimatePFromNIIDBernoulliTrials}\nConsider the sample mean estimator $\\widehat{\\Theta}_n := \\overline{X}_n$ of $\\theta^*$, from $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\bernoulli(\\theta^*)$.  That is, we take the sample mean of the $n$ IID $\\bernoulli(\\theta^*)$ trials to be our point estimator of $\\theta^*\\in[0,1]$.  Then, {\\bf this estimator is unbiased} since:\n\\[\n\\E_{\\theta^*}(\\widehat{\\Theta}_n) = \\E_{\\theta^*} \\left( n^{-1} \\sum_{i=1}^n X_i \\right) = n^{-1} \\E_{\\theta^*} \\left(  \\sum_{i=1}^n X_i \\right) = n^{-1} \\sum_{i=1}^n \\E_{\\theta^*}(X_i) = n^{-1} n \\theta^* = \\theta^* \\ .\n\\]\n\\end{example}\n\n\\begin{definition}[Standard Error of a Point Estimator]\nThe standard deviation of the point estimator $\\widehat{\\Theta}_n$ of  $\\theta^* \\in \\BB{\\Theta}$ is called the {\\bf standard error}:\n\\begin{equation}\\label{E:se}\n\\boxed{\n\\mathsf{se}_n = \\mathsf{se}_n(\\widehat{\\Theta}_n)=\\sqrt{\\V_{\\theta^*}(\\widehat{\\Theta}_n)} = \\sqrt{ \\int_{\\Xz_n} \\left( \\widehat{\\Theta}_n(x) - \\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)^2 \\, dF(x;\\theta^*)}\n}\\ .\n\\end{equation}\n\\end{definition}\nSince the variance of the sampling distribution of the point estimator $\\widehat{\\Theta}_n$ depends on the fixed and possibly unknown $\\theta^*$, as emphasised by $\\V_{\\theta^*}$ in \\eqref{E:se}, the $\\mathsf{se}_n$ is also a possibly unknown quantity and may itself be estimated from the data.  The estimated standard error, denoted by $\\widehat{\\mathsf{se}}_n$, is calculated by replacing $\\V_{\\theta^*}(\\widehat{\\Theta}_n)$ in \\eqref{E:se} with its appropriate estimate.\n\n\\begin{example}[Standard Error of our Estimator of $\\theta^*$]\\label{EX:StdErrEstimatePFromNIIDBernoulliTrials}\nConsider the sample mean estimator $\\widehat{\\Theta}_n := \\overline{X}_n$ of $\\theta^*$, from $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\bernoulli(\\theta^*)$.  Observe that the statistic: \n$$T_n((X_1,X_2,\\ldots,X_n)) := n \\,  \\widehat{\\Theta}_n((X_1,X_2,\\ldots,X_n)) = \\sum_{i=1}^n X_i$$ is the $\\binomial(n,\\theta^*)$ RV.\nThe standard error  $\\mathsf{se}_n$ of this estimator is:\n\\[\n\\mathsf{se}_n=\\sqrt{\\V_{\\theta^*}(\\widehat{\\Theta}_n)}\n= \\sqrt{\\V_{\\theta^*}\\left(\\sum_{i=1}^n \\frac{X_i}{n} \\right)}\n= \\sqrt{\\left(\\sum_{i=1}^n \\frac{1}{n^2}\\V_{\\theta^*}(X_i) \\right)}\n= \\sqrt{\\frac{n}{n^2}\\V_{\\theta^*}(X_i)}\n=\\sqrt{{\\theta^*}(1-{\\theta^*})/n} \\ .\n\\]\n\\end{example}\n\nAnother reasonable property of an estimator is that it converge to the ``true'' parameter $\\theta^*$ -- here ``true'' means the supposedly fixed and possibly unknown $\\theta^*$, as we gather more and more IID data from a $\\theta^*$-specified DF $F(x; \\theta^*)$.  This property is stated precisely next.\n\\begin{definition}[Asymptotic Consistency of a Point Estimator]\\label{D:Consistency}\nA point estimator $\\widehat{\\Theta}_n$ of $\\theta^* \\in \\BB{\\Theta}$ is said to be {\\bf asymptotically consistent} if:\n\\[\n\\boxed{\n\\widehat{\\Theta}_n \\overset{P}{\\longrightarrow} \\theta^*\n} \\qquad \\text{i.e., for any real $\\epsilon > 0$,} \\quad\n\\boxed{\n\\lim_{n \\to \\infty} \\P (| \\widehat{\\Theta}_n - \\theta^* | > \\epsilon) = 0\n} \\ .\n\\]\n\\end{definition}\n\n\\begin{definition}[Mean Squared Error (MSE) of a Point Estimator]\\label{D:MSE}\nOften, the quality of a point estimator $\\widehat{\\Theta}_n$ of $\\theta^* \\in \\BB{\\Theta}$ is assessed by the {\\bf mean squared error} or $\\mathsf{MSE}_n$ defined by:\n\\begin{equation}\\label{E:MSE}\n\\boxed{\n\\mathsf{MSE}_n=\\mathsf{MSE}_n(\\widehat{\\Theta}_n) := \\E_{\\theta^*} \\left((\\widehat{\\Theta}_n-\\theta^*)^2 \\right) \n= \\int_{\\Xz} (\\widehat{\\Theta}_n(x)-\\theta^*)^2 \\, dF(x;\\theta^*) \n} \\ .\n\\end{equation}\n\\end{definition}\n\nThe following proposition shows a simple relationship between the mean square error, bias and variance of an estimator $\\widehat{\\Theta}_n$ of $\\theta^*$.\n\\begin{prop}[The $\\sqrt{\\mathsf{MSE}_n}:\\mathsf{se}_n:\\mathsf{bias}_n$--Sided Right Triangle of an Estimator]\nLet $\\widehat{\\Theta}_n$ be an estimator of $\\theta^* \\in \\BB{\\Theta}$.  Then:\n\\begin{equation}\\label{E:RMseSeBiasTriangle}\n\\boxed{\n\\mathsf{MSE}_n(\\widehat{\\Theta}_n) \n= (\\mathsf{se}_n(\\widehat{\\Theta}_n))^2 + (\\mathsf{bias}_n(\\widehat{\\Theta}_n))^2\n} \\ .\n\\end{equation}\n{\\scriptsize\n\\begin{proof}\n\\begin{eqnarray}\n& & LHS \\notag \\\\\n&=& \\mathsf{MSE}_n(\\widehat{\\Theta}_n) \\notag \\\\\n&:=& \\E_{\\theta^*} \\left((\\widehat{\\Theta}_n-\\theta^*)^2 \\right), \\qquad  \\text{by definition of $\\mathsf{MSE}_n$ \\eqref{E:MSE}} \\notag \\\\\n&=& \\E_{\\theta^*} \\left( \\left( \\ \\underset{A}{\\underbrace{\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)}} + \\underset{B}{\\underbrace{\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}} \\ \\right)^2 \\right), \\qquad \\text{by subtracting and adding the constant $\\E_{\\theta^*}(\\widehat{\\Theta}_n)$} \\notag \\\\\n&=& \\E_{\\theta^*} \\left( \\underset{A^2}{\\underbrace{{\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)}^2}} + \\underset{2AB}{\\underbrace{2  {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)} {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}}} + \\underset{B^2}{\\underbrace{{\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}^2}}  \\right), \\qquad \\text{$\\because \\ (A+B)^2=A^2+2AB+B^2$} \\notag \\\\\n&=& \\E_{\\theta^*} \\left( {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)}^2 \\right) + \n\\E_{\\theta^*} \\left( 2  {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)} {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)} \\right) + \n\\E_{\\theta^*} \\left( {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}^2  \\right), %\\quad \\text{taking $\\E_{\\theta^*}(\\cdot)$ of $A^2$, $2AB$ and $B^2$} \n\\notag \\\\\n&=& \\E_{\\theta^*} \\left( {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)}^2 \\right) + \n\\underset{C}{\\underbrace{2 {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}}} \\underset{D}{\\underbrace{ \\E_{\\theta^*} \\left(  {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)} \\right)}} + \n\\E_{\\theta^*} \\left( {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}^2  \\right), \\quad \\text{$\\because \\ C$ \n% := 2 {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}$\nis constant} \\notag \\\\\n&=& \\E_{\\theta^*} \\left( {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)}^2 \\right) + \n0 + \n\\E_{\\theta^*} \\left( {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}^2  \\right), \\qquad \\text{$\\because \\ D := \\E_{\\theta^*} \\left(  {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)} \\right)=\\E_{\\theta^*}(\\widehat{\\Theta}_n ) - \\E_{\\theta^*}(\\widehat{\\Theta}_n) = 0$} \\notag \\\\\n&=& \\V_{\\theta^*}(\\widehat{\\Theta}_n)+ \n\\E_{\\theta^*} \\left( {\\left(\\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* \\right)}^2  \\right), \\qquad \\text{$\\because \\ \\V_{\\theta^*}(\\widehat{\\Theta}_n) := \\E_{\\theta^*} \\left( {\\left(\\widehat{\\Theta}_n -\\E_{\\theta^*}(\\widehat{\\Theta}_n) \\right)}^2 \\right)$, by definition of variance} \\notag \\\\\n&=& \\left( \\sqrt{\\V_{\\theta^*}(\\widehat{\\Theta}_n)} \\right)^2+ \n\\E_{\\theta^*} \\left( {\\left( \\mathsf{bias}_n(\\widehat{\\Theta}_n) \\right)}^2  \\right), \\qquad \\text{$\\because \\  \\mathsf{bias}_n(\\widehat{\\Theta}_n) = \\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^* $, by definition of $\\mathsf{bias}_n$ of an estimator $\\widehat{\\Theta}_n$} \\notag \\\\\n&=&  \\left(  \\mathsf{se}_n(\\widehat{\\Theta}_n) \\right)^2 + \n\\E_{\\theta^*} \\left( {\\left( \\mathsf{bias}_n(\\widehat{\\Theta}_n) \\right)}^2  \\right) , \\qquad \n\\text{$\\because \\ \\mathsf{se}_n(\\widehat{\\Theta}_n) := \\sqrt{\\V_{\\theta^*}(\\widehat{\\Theta}_n)}$, by definition \\eqref{E:se}} \\notag \\\\\n&=&  \\left(  \\mathsf{se}_n(\\widehat{\\Theta}_n) \\right)^2 + \n {\\left( \\mathsf{bias}_n(\\widehat{\\Theta}_n) \\right)}^2, \\qquad \n\\text{$\\because \\  \\mathsf{bias}_n(\\widehat{\\Theta}_n) = \\E_{\\theta^*}(\\widehat{\\Theta}_n) -\\theta^*$ and $\\left( \\mathsf{bias}_n(\\widehat{\\Theta}_n) \\right)^2$ are constants.} \\notag \\\\\n&=& RHS \\notag \n\\end{eqnarray}\n\\end{proof}\n}\n\\end{prop}\n\n\\begin{prop}[Asymptotic consistency of a point estimator]\\label{P:AsympConsistencyUnbiasedSE0}\nLet $\\widehat{\\Theta}_n$ be an estimator of $\\theta^* \\in \\BB{\\Theta}$.  Then, if $\\mathsf{bias}_n(\\widehat{\\Theta}_n) \\to 0$ and $\\mathsf{se}_n(\\widehat{\\Theta}_n) \\to 0$ as $n \\to \\infty$, the estimator $\\widehat{\\Theta}_n$ is asymptotically consistent:\n\\[\n\\widehat{\\Theta}_n \\overset{P}{\\longrightarrow} \\theta^* \\ .\n\\]\n{\\scriptsize\n\\begin{proof}\nIf $\\mathsf{bias}_n(\\widehat{\\Theta}_n) \\to 0$ and $\\mathsf{se}_n(\\widehat{\\Theta}_n) \\to 0$, then by \\eqref{E:RMseSeBiasTriangle}, $\\mathsf{MSE}_n(\\widehat{\\Theta}_n) \\to 0$, i.e.~that $\\E_{\\theta^*}\\left( (\\widehat{\\Theta}_n-\\theta^*)^2 \\right) \\to 0$.  This type of convergence of the RV $\\widehat{\\Theta}_n$ to the $Point~Mass(\\theta^*)$ RV as $n \\to \\infty$ is called convergence in {\\bf quadratic mean} or {\\bf convergence in} $\\B{L_2}$ and denoted by $\\widehat{\\Theta}_n \\overset{qm}{\\longrightarrow} \\theta^*$.  Convergence in quadratic mean is a stronger notion of convergence than convergence in probability, in the sense that \n\\[\n\\E_{\\theta^*}\\left( (\\widehat{\\Theta}_n-\\theta^*)^2 \\right) \\to 0 \\quad \\text{ or } \\quad \\widehat{\\Theta}_n \\overset{qm}{\\longrightarrow} \\theta^* \\implies \\widehat{\\Theta}_n \\overset{P}{\\longrightarrow} \\theta^* \\ .\n\\]\nThus, if we prove the above implication we are done with the proof of our proposition.  To show that convergence in quadratic mean implies convergence in probability for general sequence of RVs $X_n$ converging to an RV $X$, we first assume that $X_n \\overset{qm}{\\longrightarrow} X$.\nNow, fix any $\\epsilon>0$.  Then by Markov's inequality \\eqref{E:MarkovNeq},\n\\[\n\\P(|X_n-X|>\\epsilon) = \\P(|X_n-X|^2>\\epsilon^2) \\leq \\frac{\\E(|X_n-X|^2)}{\\epsilon^2} \\to 0 \\ ,\n\\]\nand we have shown that the definition of convergence in probability holds provided convergence in quadratic mean holds.\n\\end{proof}\n}\n\\end{prop}\nWe want our estimator to be unbiased with small standard errors as the sample size $n$ gets large.  The {\\bf point estimator} $\\widehat{\\Theta}_n$ will then produce a {\\bf point estimate} $\\widehat{\\theta}_n$:\n$$\\widehat{\\Theta}_n((x_1,x_2,\\ldots,x_n)) = \\widehat{\\theta}_n \\in \\BB{\\Theta} \\enspace ,$$ on the basis of the {\\bf observed data} $(x_1,x_2,\\ldots,x_n)$, that is close to the {\\bf true parameter} $\\theta^* \\in \\BB{\\Theta}$.\n\n\\begin{example}[Asymptotic consistency of our Estimator of $\\theta^*$]\nConsider the sample mean estimator $\\widehat{\\Theta}_n := \\overline{X}_n$ of $\\theta^*$, from $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\bernoulli(\\theta^*)$.  Since $\\mathsf{bias}_n(\\widehat{\\Theta}_n)=0$ for any $n$ and \n$\\mathsf{se}_n=\\sqrt{\\theta^*(1-\\theta^*)/n} \\to 0$, as $n \\to \\infty$, by \n\\hyperref[P:AsympConsistencyUnbiasedSE0]{Proposition \\ref*{P:AsympConsistencyUnbiasedSE0}}, \n$\\widehat{\\Theta}_n \\overset{P}{\\longrightarrow} \\theta^*$.  That is $\\widehat{\\Theta}_n$ is an {\\bf asymptotically consistent estimator} of $\\theta^*$.  \n\\end{example}\n\n\\subsection{Confidence Set Estimation}\\label{S:ConfidenceSets}\nAs we saw in Section~\\ref*{S:PointEstimation}, the point estimate $\\widehat{\\theta}_n$ is a ``single best guess'' of  the fixed and possibly unknown parameter $\\theta^* \\in \\BB{\\Theta}$.  However, if we wanted to make a statement about our confidence in an estimation procedure, then one possibility is to produce subsets from the parameter space $\\BB{\\Theta}$ called {\\bf confidence sets} that ``engulf'' $\\theta^*$ with a probability of at least $1-\\alpha$.  \n\nFormally, an $1-\\alpha$ {\\bf confidence interval} for the parameter $\\theta^* \\in \\BB{\\Theta} \\subset \\Rz$, based on $n$ observations or data points $X_1,X_2,\\ldots,X_n$, is an interval $C_n$ that is a function of the data:\n\\[\nC_n := [\\underline{C}_{\\, n}, \\overline{C}_{\\, n}]\n= [\\underline{C}_{\\, n}(X_1,X_2,\\ldots,X_n), \\overline{C}_{\\, n}(X_1,X_2,\\ldots,X_n)] \\ ,\n\\]\nsuch that:\n\\[\n\\P_{\\theta^*} \\left(  \\theta^* \\in C_n :=  [\\underline{C}_{\\, n}, \\overline{C}_{\\, n}] \\right) \\geq 1-\\alpha \\ .\n\\]\nNote that the confidence interval $C_n := [\\underline{C}_{\\, n}, \\overline{C}_{\\, n}]$ is a two-dimensional RV or a random vector in $\\Rz^2$ that depends on the two statistics $\\underline{C}_{\\, n} (X_1,X_2,\\ldots,X_n) $ and $\\overline{C}_{\\, n} (X_1,X_2,\\ldots,X_n) $, as well as $\\theta^*$, which in turn determines the distribution of the data $(X_1,X_2,\\ldots,X_n)$.  In words, $C_n$ engulfs the true parameter $\\theta^* \\in \\BB{\\Theta}$ with a probability of at least $1-\\alpha$.  We call $1-\\alpha$ as the {\\bf coverage} of the confidence interval $C_n$.\n\nFormally, a $1-\\alpha$ {\\bf confidence set} $C_n$ for a vector-valued $\\theta^* \\in \\BB{\\Theta} \\subset \\Rz^k$ is any subset of $\\BB{\\Theta}$ such that $\\P_{\\theta^*}( \\theta^* \\in C_n) \\geq 1-\\alpha$.  The typical forms taken by $C_n$ are $k$-dimensional boxes or hyper-cuboids, hyper-ellipsoids and subsets defined by inequalities involving level sets of some estimator of $\\theta^*$.  \n\nTypically, we take $\\alpha=0.05$ because we are interested in the $1-\\alpha=0.95$ or $95\\%$ confidence interval/set $C_n \\subset \\BB{\\Theta}$ of $\\theta^* \\in \\BB{\\Theta}$ from an estimator $\\widehat{\\Theta}_n$ of $\\theta^*$.  \n\nLet us look at an example that makes use of the CLT next (Exercise in Prob.~Theor.I).\n\\begin{example}[Errors in computer code (Wasserman03, p.~78)]\\label{EXCLTPoisson}\nSuppose the collection of RVs $X_1,X_2, \\ldots, X_n$ model the number of errors in $n$ computer programs named $1,2,\\ldots,n$, respectively.  Suppose that the RV $X_i$ modelling the number of errors in the $i^{\\text{th}}$ program is the $Poisson(\\lambda^*=5)$ for any $i=1,2,\\ldots,n$.  Also suppose that they are independently distributed.  In short, we suppose that:\n\\[\nX_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\poisson(\\lambda^*=5) \\ . \n\\]\nSuppose we have $n=125$ programs and want to make a probability statement about $\\overline{X}_n$ which is the average number of errors per program out of these $125$ programs.  Since $\\E(X_i) = \\lambda^*=5$ and $\\V(X_i)=\\lambda^*=5$, we may want to know how often our sample mean $\\overline{X}_{125}$ differs from the expectation of $5$ errors per program.  Using the CLT, we can approximate $\\P(\\overline{X}_n < 5.5)$, for instance, as follows:\n\\begin{eqnarray}\n\\P(\\overline{X}_n < 5.5) \n&=& \\P \\left( \\frac{\\sqrt{n}(\\overline{X}_n - \\E(X_1))}{\\sqrt{\\V(X_1)}} < \\frac{\\sqrt{n}(5.5-\\E(X_1))}{\\sqrt{\\V(X_1)}} \\right) \\notag \\\\\n&\\approxeq& \\P \\left( Z < \\frac{\\sqrt{n}(5.5-\\lambda^*)}{\\sqrt{\\lambda^*}} \\right) \\qquad \\text{{\\scriptsize [by CLT, and $\\E(X_1)=\\V(X_1)=\\lambda^*$]}} \\notag \\\\\n&=& \\P \\left( Z < \\frac{\\sqrt{125}(5.5-5)}{\\sqrt{5}} \\right) \\qquad \\text{{\\scriptsize [Since, $\\lambda^*=5$ and $n=125$ in this Example]}} \\notag \\\\\n&=& \\P(Z \\leq 2.5) = \\Phi(2.5) =  \\int_{- \\infty}^{2.5} \\left( \\frac{1}{\\sqrt{2 \\pi}} \\ \\exp \\left( \\frac{-x^2}{2} \\right) \\right) dx \\approxeq 0.993790334674224 \\ . \\notag\n\\end{eqnarray}\nTo obtain the final number in this approximation, we need the following:\n\\begin{labwork}\nThe numerical approximation of $\\Phi(2.5)$ was obtained via the call shown below to our $\\erf$-based {\\tt NormalCdf} function from \\ref*{Mf: NormalCdfPdf}.  We could have also found it from a pre-computed Table for $\\Phi(x)$.\n\\begin{VrbM}\n>> format long\n>> disp(NormalCdf(2.5,0,1))\n   0.993790334674224\n\\end{VrbM}\n\\end{labwork}\n\\end{example}\n\nThe CLT says that if $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ then $Z_n := \\sqrt{n}(\\overline{X}_n-\\E(X_1))/\\sqrt{\\V(X_1)}$ is approximately distributed as $\\normal(0,1)$.  In \\hyperref[EXCLTPoisson]{Example \\ref*{EXCLTPoisson}}, we knew $\\sqrt{\\V(X_1)}$ since we assumed knowledge of $\\lambda^*=5$.   However, in general, we may not know $\\sqrt{\\V(X_1)}$.  The next proposition says that we may estimate $\\sqrt{\\V(X_1)}$ using the sample standard deviation $S_n$ of $X_1,X_2,\\ldots,X_n$, according to \\eqref{E:SampleStdDevRV}, and still make probability statements about the sample mean $\\overline{X}_n$ using a $\\normal$ distribution, {\\bf provided $\\mathbf{n}$ is not too small}, for e.g.~$n \\geq 30$.\n\\begin{prop}[CLT based on Sample Variance]\nLet $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ and suppose $\\E(X_1)$ and $\\V(X_1)$ exists, then:\n\\begin{equation}\\label{E:CLTApproxSn}\n\\frac{\\sqrt{n} \\left( \\overline{X}_n - \\E(X_1) \\right)}{S_n} \\rightsquigarrow \\normal(0,1) \\ .\n\\end{equation}\n\\end{prop}\n\nThe following property of an estimator makes it easy to obtain confidence intervals.\n\\begin{definition}[Asymptotic Normality of Estimators]\nAn estimator $\\widehat{\\Theta}_n$ of a fixed and possibly unknown parameter $\\theta^* \\in \\BB{\\Theta}$ is {\\bf asymptotically normal} if:\n\\begin{equation}\\label{E:AsymptoticNormalEstimator}\n\\frac{\\widehat{\\Theta}_n - \\theta^*}{\\mathsf{se}_n} \\rightsquigarrow \\normal(0,1) \\ .\n\\end{equation} \nThat is, $\\widehat{\\Theta}_n \\rightsquigarrow \\normal(\\theta^*,\\mathsf{se}_n^2)$.  By a further estimation of $\\mathsf{se}_n := \\sqrt{\\V_{\\theta^*}(\\widehat{\\Theta}_n)}$ by $\\widehat{\\mathsf{se}}_n$, we can see that $\\widehat{\\Theta}_n \\rightsquigarrow \\normal(\\theta^*,\\widehat{\\mathsf{se}}_n^2)$ on the basis of \\eqref{E:CLTApproxSn}.\n\\end{definition}\n\n\\begin{prop}[Normal-based Asymptotic Confidence Interval]\\label{P:NormalBasedAsympCI}\nSuppose an estimator $\\widehat{\\Theta}_n$ of  parameter $\\theta^* \\in \\BB{\\Theta} \\subset \\Rz$ is asymptotically normal:\n\\[\n\\widehat{\\Theta}_n \\rightsquigarrow \\normal(\\theta^*,\\widehat{\\mathsf{se}}_n^2) \\ .\n\\]\nLet the RV $Z \\sim \\normal(0,1)$ have DF $\\Phi$ and inverse DF $\\Phi^{-1}$.  Let:\n\\[\nz_{\\alpha/2}=\\Phi^{-1}(1-(\\alpha/2)), \\quad \\text{ that is, } \\quad \\P(Z>z_{\\alpha/2})=\\alpha/2 \\ \\text{ and } \\ \\P(-z_{\\alpha/2} < Z < z_{\\alpha/2}) = 1-\\alpha \\ .\n\\]\nThen:\n\\[\n\\P_{\\theta^*}(\\theta^* \\in C_n)  = \\P \\left( \\theta^* \\in [\\widehat{\\Theta}_n - z_{\\alpha/2} \\widehat{\\mathsf{se}}_n, \\widehat{\\Theta}_n + z_{\\alpha/2} \\widehat{\\mathsf{se}}_n] \\right) \\to 1-\\alpha \\ .\n\\]\nTherefore:\n\\[\nC_n := [\\underline{C}_{\\, n}, \\overline{C}_{\\, n}]\n= [\\widehat{\\Theta}_n - z_{\\alpha/2} \\widehat{\\mathsf{se}}_n, \\widehat{\\Theta}_n + z_{\\alpha/2} \\widehat{\\mathsf{se}}_n]\n\\] \nis the $1-\\alpha$ Normal-based asymptotic confidence interval that relies on the asymptotic normality of the estimator $\\widehat{\\Theta}_n$ of $\\theta^* \\in \\BB{\\Theta} \\subset \\Rz$.\n{\\scriptsize\n\\begin{proof}\nDefine the centralised and scaled estimator as $Z_n := (\\widehat{\\Theta}_n-\\theta^*)/\\widehat{\\mathsf{se}}_n$.  By assumption, $Z_n \\rightsquigarrow Z \\sim \\normal(0,1)$.  Therefore,\n\\begin{eqnarray}\n\\P_{\\theta^*}(\\theta^* \\in C_n) \n&=& \\P_{\\theta^*} \\left( \\theta^* \\in [\\widehat{\\Theta}_n - z_{\\alpha/2} \\widehat{\\mathsf{se}}_n, \\widehat{\\Theta}_n + z_{\\alpha/2} \\widehat{\\mathsf{se}}_n] \\right) \\notag \\\\\n&=& \\P_{\\theta^*} \\left( \\widehat{\\Theta}_n - z_{\\alpha/2} \\widehat{\\mathsf{se}}_n \\leq \\theta^* \\leq  \\widehat{\\Theta}_n + z_{\\alpha/2} \\widehat{\\mathsf{se}}_n \\right) \\notag \\\\\n&=& \\P_{\\theta^*} \\left(  - z_{\\alpha/2} \\widehat{\\mathsf{se}}_n \\leq \\widehat{\\Theta}_n - \\theta^* \\leq   z_{\\alpha/2} \\widehat{\\mathsf{se}}_n \\right) \\notag \\\\\n&=& \\P_{\\theta^*} \\left(  - z_{\\alpha/2}  \\leq \\frac{\\widehat{\\Theta}_n - \\theta^*}{\\widehat{\\mathsf{se}}_n} \\leq   z_{\\alpha/2} \\right) \\notag \\\\\n&\\to& \\P_{\\theta^*} \\left(  - z_{\\alpha/2}  \\leq Z \\leq   z_{\\alpha/2} \\right) \\notag \\\\\n&=& 1-\\alpha \\notag\n\\end{eqnarray}\n\\end{proof}\n}\n\\begin{figure}[htb]\n\\caption{Density and Confidence Interval of the Asymptotically Normal Point Estimator}\n\\vspace{4cm}\n\\end{figure}\nFor $95\\%$ confidence intervals, $\\alpha=0.05$ and $z_{\\alpha/2}=z_{0.025}=1.96\\approxeq 2$.  This leads to the {\\bf approximate ${95\\%}$ confidence interval} of $\\widehat{\\theta}_n \\pm 2 \\widehat{\\mathsf{se}}_n$, where $\\widehat{\\theta}_n=\\widehat{\\Theta}_n(x_1,x_2,\\ldots,x_n)$ and $x_1,x_2,\\ldots,x_n$ are the data or observations of the RVs $X_1,X_2,\\ldots,X_n$.\n\\end{prop}\n\n\\begin{example}[Confidence interval for $\\theta^*$ from $n$ $\\bernoulli(\\theta^*)$ trials]\\label{EX:EstimatePFromNIIDBernoulliTrials}\nLet $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\bernoulli(\\theta^*)$ for some fixed but unknown parameter $\\theta^* \\in \\BB{\\Theta}=[0,1]$.  Consider the following point estimator of $\\theta^*$:\n\\[\n\\widehat{\\Theta}_n((X_1,X_2,\\ldots,X_n)) = n^{-1} \\sum_{i=1}^n X_i \\ .\n\\]\nThat is, we take the sample mean of the $n$ IID $\\bernoulli(\\theta^*)$ trials to be our point estimator of $\\theta^*\\in[0,1]$.  Then, we already saw that {\\bf this estimator is unbiased}\n\nWe already saw that the standard error  $\\mathsf{se}_n$ of this estimator is:\n\\[\n\\mathsf{se}_n=\\sqrt{{\\theta^*}(1-{\\theta^*})/n} \\ .\n\\]\nSince ${\\theta^*}$ is unknown, we obtain the estimated standard error $\\widehat{\\mathsf{se}}_n$ from the point estimate $\\widehat{\\theta}_n$ of ${\\theta^*}$ on the basis of $n$ observed data points $x=(x_1,x_2,\\ldots,x_n)$ of the experiment:\n\\[\n\\widehat{\\mathsf{se}}_n = \\sqrt{\\widehat{\\theta}_n(1-\\widehat{\\theta}_n)/n}, \\quad \\text{where, } \\quad \\widehat{\\theta}_n=\\widehat{\\Theta}_n((x_1,x_2,\\ldots,x_n))=n^{-1}\\sum_{i=1}^n x_i \\ .\n\\]\nBy the central limit theorem, $\\widehat{\\Theta}_n \\rightsquigarrow \\normal(\\theta^*,\\widehat{\\mathsf{se}}_n)$, i.e.~$\\widehat{\\Theta}_n$ is asymptotically normal.  Therefore, an asymptotically (for large sample size $n$) approximate $1-\\alpha$ normal-based confidence interval is:\n\\[\n\\widehat{\\theta}_n \\pm z_{\\alpha/2} \\widehat{\\mathsf{se}}_n \n= \\widehat{\\theta}_n \\pm z_{\\alpha/2} \\sqrt{\\frac{ \\widehat{\\theta}_n (1- \\widehat{\\theta}_n )}{n}}\n:= \\left[ \\, \\widehat{\\theta}_n - z_{\\alpha/2} \\sqrt{\\frac{ \\widehat{\\theta}_n (1- \\widehat{\\theta}_n )}{n}} \\ , \\ \\widehat{\\theta}_n + z_{\\alpha/2} \\sqrt{\\frac{ \\widehat{\\theta}_n (1- \\widehat{\\theta}_n )}{n}} \\, \\right]\n\\]\nWe also saw that $\\widehat{\\Theta}_n$ is an {\\bf asymptotically consistent estimator} of $\\theta^*$  due to \\hyperref[P:AsympConsistencyUnbiasedSE0]{Proposition \\ref*{P:AsympConsistencyUnbiasedSE0}}.\n\nThe confidence Interval for the coin tossing experiment in \\hyperref[EX:CoinTossing]{Example \\ref*{EX:CoinTossing}} with the observed sequence of Bernoulli outcomes (Heads $\\to 1$ and Tails $\\to 0$) being $(1,0,0,0,1,1,0,0,1,0)$.  We estimated the probability $\\theta^*$ of observing Heads with the {\\bf unbiased, asymptotically consistent estimator} $\\widehat{\\Theta}_n((X_1,X_2,\\ldots,X_n))=n^{-1}\\sum_{i=1}^{n} X_i$ of $\\theta^*$.  The point estimate of $\\theta^*$ was:\n\\begin{eqnarray}\n\\widehat{\\theta}_{10} = \\widehat{\\Theta}_{10}((x_1,x_2,\\ldots,x_{10})) \n&=&\\widehat{\\Theta}_{10}((1,0,0,0,1,1,0,0,1,0)) \\notag \\\\\n&=& \\frac{1+0+0+0+1+1+0+0+1+0}{10}=\\frac{4}{10}=0.40 \\notag \\ .\n\\end{eqnarray}\nThe normal-based confidence interval for $\\theta^*$ may not be a valid approximation here with just $n=10$ samples.  Nevertheless, we will compute a $95\\%$ normal-based confidence interval:\n\\[\nC_{10} \n= 0.40 \\pm 1.96 \\sqrt{\\frac{0.40(1-0.40)}{10}}\n=0.40 \\pm 0.3036\n=[0.0964, 0.7036]\n\\]\nwith a width of $0.6072$.  When I increased the sample size $n$ of the experiment from $10$ to $100$ by tossing the same coin another $90$ times, I discovered that a total of $57$ trials landed as Heads.  Thus my point estimate and confidence interval for $\\theta^*$ are:\n\\[\n\\widehat{\\theta}_{100} = \\frac{57}{100} = 0.57 \\qquad and \\qquad\nC_{100} \n= 0.57 \\pm 1.96 \\sqrt{\\frac{0.57(1-0.57)}{100}}\n = 0.57 \\pm 0.0495\n =[0.5205, 0.6195]\n\\]\nwith a much smaller width of $0.0990$.  Thus our confidence interval shrank considerably from a width of $0.6072$ after an additional $90$ Bernoulli trials.  Thus, we can make the width of the confidence interval as small as we want by making the number of observations or sample size $n$ as large as we can.\n\\end{example}\n\n\\remove{\n\\subsection{Likelihood}\\label{S:Likelihood}\nWe take a look at one of the most fundamental concepts in Statistics.  \n\n\\begin{definition}[Likelihood Function]\\label{D:LklFn}\nSuppose $X_1,X_2,\\ldots,X_n$ have joint density $f(x_1,x_2,\\ldots,x_n; \\theta)$ specified by parameter $\\theta \\in \\BB{\\Theta}$.  Let the observed data be $x_1,x_2,\\ldots,x_n$.  \n\nThe {\\bf likeihood} function given by $L_n(\\theta)$ is proportional to $f(x_1,x_2,\\ldots,x_n; \\theta)$, the joint probability of the data, with the exception that we see it as a function of the parameter:\n\\begin{equation}\nL_n(\\theta) := L_n(x_1,x_2,\\ldots,x_n; \\theta) = f(x_1,x_2,\\ldots,x_n; \\theta) \\enspace .\n\\end{equation}\nThe likelihood function has a simple product structure when the observations are independently and identically distributed:\n\\begin{equation}\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} f(x;\\theta) \\implies \n\\boxed{\nL_n(\\theta) := L_n(x_1,x_2,\\ldots,x_n;\\theta) = f(x_1,x_2,\\ldots,x_n; \\theta) := \\prod_{i=1}^n f(x_i ; \\theta)  \n}\n\\enspace .\n\\end{equation}\nThe {\\bf log-likelihood} function is defined by:\n\\begin{equation}\n\\boxed{\n\\ell_n(\\theta) := \\log(L_n(\\theta))\n} \\enspace\n\\end{equation}\n\\end{definition}\n\n\\begin{example}[Likelihood of the IID $\\bernoulli(\\theta^*)$ experiment]\nConsider our IID Bernoulli experiment:\n$$\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\bernoulli(\\theta^*), \\text{ with PDF } f(x;\\theta)=\\theta^x(1-\\theta)^{1-x} \\BB{1}_{\\{0,1\\}}(x) \\enspace .\n$$\nLet us understand the likelihood function for one observation first.  There are two possibilities for the first observation.  \n\nIf we only have one observation and it happens to be $x_1=1$, then our likelihood function is:\n$$L_1(\\theta)=L_1(x_1;\\theta)\n= f(x_1;\\theta)\n=\\theta^{1}(1-\\theta)^{1-1} \\BB{1}_{\\{0,1\\}}(1)\n=\\theta (1-\\theta)^0 1\n=\\theta \\enspace\n$$\nIf we only have one observation and it happens to be $x_1=0$, then our likelihood function is:\n$$L_1(\\theta)=L_1(x_1;\\theta)\n= f(x_1;\\theta)\n=\\theta^{0}(1-\\theta)^{1-0} \\BB{1}_{\\{0,1\\}}(0)\n=1 (1-\\theta)^1 1\n=1-\\theta \\enspace\n$$\nIf we have $n$ observations $(x_1,x_2,\\ldots,x_n)$, i.e.~a vertex point of the unit hyper-cube $\\{0,1\\}^n$, then our likelihood function is obtained by multiplying the densities:\n\\begin{eqnarray}\nL_n(\\theta) &:=& L_n(x_1,x_2,\\ldots,x_n; \\theta)  = f(x_1,x_2,\\ldots,x_n ; \\theta) \\notag \\\\\n&=& f(x_1 ; \\theta) f(x_2 ; \\theta) \\cdots f(x_n ; \\theta) := \\prod_{i=1}^n f(x_i ; \\theta) \\notag \\\\\n&=& \\theta^{\\sum_{i=1}^n x_i} (1-\\theta)^ {n-\\sum_{i=1}^n x_i} := \\theta^{t_n} (1-\\theta)^{n-t_n} \\notag \n\\end{eqnarray}\nIn the last step, we have formally defined the following statistic of the data: \n$$T_n(X_1,X_2,\\ldots,X_n)=\\sum_{i=1}^n X_i :  \\Xz_n \\rightarrow \\Tz_n$$ with the corresponding realisation $t_n := T_n(x_1,x_2,\\ldots,x_n)=\\sum_{i=1}^n x_i \\in \\Tz_n$. \n\\end{example}\n\n\\begin{figure}[ht]\n\\caption{Data Spaces $\\Xz_1=\\{0,1\\}$, $\\Xz_2=\\{0,1\\}^2$ and $\\Xz_3=\\{0,1\\}^3$ for one, two and three IID Bernoulli trials, respectively and the corresponding likelihood functions.\\label{F:BernoulliSampleLkl}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/BernoulliSampleLkl}}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\caption{{\\small $100$ realisations of $C_{10}, C_{100}, C_{1000}$ based on samples of size $n$ $=$ $10$, $100$ and $1000$ drawn from the $\\bernoulli(\\theta^*=0.5)$ RV as per \\hyperref[Mf:BernoulliMLEConsistency]{Labwork~\\ref*{Mf:BernoulliMLEConsistency}}.  The MLE $\\widehat{\\theta}_n$ (cyan dot) and the log-likelihood function (magenta curve) for each of the $100$ replications of the experiment for each sample size $n$ are depicted.  The approximate normal-based $95\\%$ confidence intervals with blue boundaries are based on the exact $\\mathsf{se}_n=\\sqrt{\\theta^*(1-\\theta^*)/n}=\\sqrt{1/4}$, while those with red boundaries are based on the estimated $\\widehat{\\mathsf{se}_n}=\\sqrt{\\widehat{\\theta}_n(1-\\widehat{\\theta}_n)/n}$.  The fraction of times the true parameter $\\theta^*=0.5$ was engulfed by the exact and approximate confidence interval (empirical coverage) over the $100$ replications of the experiment for each of the three sample sizes are given by the numbers after {\\tt Cvrg.=} and {\\tt $\\sim$=}, above each sub-plot, respectively.}\\label{F:BernoulliMLEConsistency}}\n\\begin{center}\n\\makebox{\\includegraphics[width=4.50in]{figures/BernoulliMLEConsistency}}\n\\end{center}\n\\end{figure}  \n\n\n%Let us look at some examples of estimation.\n}\n\n\n\n", "meta": {"hexsha": "cdb75e3725cd30c0cb67e7dd63747f28208e5f14", "size": 36341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/Estimation.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/Estimation.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/Estimation.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": 84.5139534884, "max_line_length": 1087, "alphanum_fraction": 0.6792328224, "num_tokens": 12926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6741073800218945}}
{"text": "% IRAM.tex\n\\documentclass[12pt]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage{lmodern}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath, amsfonts, amsthm}\n\\usepackage{palatino}\n\n% Stuff for the algorithm package\n\\usepackage[algo2e, ruled, linesnumbered]{algorithm2e}\n\\SetKwComment{Comment}{$\\triangleright$ }{}\n\\dontprintsemicolon\n\n\\newcommand{\\A}{\\mathbf{A}}\n\\newtheorem{thm}{Theorem}\n\\newtheorem{lem}{Lemma}\n\n\\title{Implicitly Restarted Arnoldi's Method}\n\\author{Jeremy L. Conlin}\n\n\\begin{document}\n\\maketitle\n\\section{IRAM from ``The Source''}\nHere I will try to reconstruct the description of Implicitly Restarted Arnoldi's Method from the original paper by D.C. Sorensen.\n\n\\subsection{The Arnoldi factorization}\nThe Arnoldi factorization may be viewed as a truncated reduction of an $n \\times n$ matrix $\\A$ to upper Hessenberg form.  After $k$ steps of the factorization one has\n\\begin{equation}\n    \\A V = VH + re_k^T,\n    \\label{eq:ArnoldiFactorization}\n\\end{equation}\nwhere $V \\in \\mathbb{R}^{n \\times k}$, $V^TV = I_k$, $H \\in \\mathbb{R}^{k \\times k}$ is upper Hessenberg, $r \\in \\mathbb{R}^n$ with $\\mathbf{0} = V^Tr$.  An alternative [and better in the views of the summarizer] way to write Eq. \\ref{eq:ArnoldiFactorization} is\n\\begin{equation}\n    \\A V = \\begin{pmatrix}V & v\\end{pmatrix}\\begin{pmatrix} H \\\\ \\beta e_k^T \\end{pmatrix} \\mathrm{ where } \\beta = \\left| r \\right| \\mathrm{ and } v = \\frac{1}{\\beta}r.\n    \\label{}\n\\end{equation}\n\nApproximate eigenvalues and eigenvectors are readily available through this factorization.  If $Hy = y\\theta$ is an eigenpair for $H$, then the vector $x = Vy$ satisfies\n\\begin{equation}\n    \\left\\|Ax-x\\theta\\right\\| = \\left\\|\\left(\\A V - VH\\right)y\\right\\| = \\left|\\beta e_k^Ty\\right|.\n    \\label{}\n\\end{equation}\nWe call the vector $x$ a Ritz vector and the approximate eignvalue $\\theta$ a Ritz value and note that the smaller $\\left|\\beta e_k^T\\right|$ is, the better these approximations are.\n\nThe factorization Eq. \\ref{eq:ArnoldiFactorization} may be advanced one step through the following recursion formulas:\n\\begin{subequations}\\begin{gather}\n    \\beta = \\|r\\|, \\hspace{0.25in} v = \\frac{1}{\\beta}r, \\\\ \\label{eq:ArnoldiRecursion-1}\n    V_+ = \\begin{pmatrix}V & v\\end{pmatrix}, \\\\\n    w = \\A v, \\hspace{0.25in} \\begin{pmatrix}H \\\\ \\alpha \\end{pmatrix} = V_+^Tw, \\\\\n    H_+ = \\begin{pmatrix} H & h \\\\ \\beta e_k^T & \\alpha \\end{pmatrix}, \\\\\n    r_+ = w - V_+\\begin{pmatrix}h \\\\ \\alpha \\end{pmatrix} = \\left(I-V_+V_+^T\\right)w.  \\label{eq:ArnoldiRecursion-4}\n\\end{gather}\\end{subequations}\nFrom this development it is easily seen that\n\\begin{equation}\n    \\A V_+ = V_+H_+ + r_+e_{k+1}^T,\\hspace{.25in} V_+^TV_+ = I_{k+1}, V_+^Tr_+ = \\mathbf{0}.\n    \\label{}\n\\end{equation}\n\n\\begin{thm}\n    Let $\\A V_k - V_kH_k = r_ke_k^T$ be a $k$-step Arnoldi factorization of $\\A$, with $H$ unreduced (this is seen in Eq. \\ref{eq:ArnoldiFactorization}).  Then $r_k = 0$ if and only if $v_1 = Qy$ where $\\A Q = QR$ with $Q^HQ = I_k$ and $R$ upper triangular order of $k$.\n    \\label{thm:ArnoldiInvariant}\n\\end{thm}\nTheorem \\ref{thm:ArnoldiInvariant} provides the motivation for the algorithms we shall develop.  It suggests that one might find an invariant subspace by iteratively replacing the starting vector with a linear combination of approximate eigenvectors corresponding to eigenvalues of interest.\n\n\\subsection{Updating the Arnoldi factorization via QR-iterations}\nIn this section a direct analogue of th implicitly shifted QR-iteration will be derived in the context of the $k$-step Arnoldi factorization.\n\nThroughout this discussion, the integer $k$ should be thought of as a fixed pre-specified integer of modest size.  Let $p$ be another positive integer, and consider the result of $k+p$ steps of the Arnoldi process appled to $\\A$ , which has resulted in the construction of an orthogonal matrix $V_{k+p}$ such that\n\\begin{equation}\n    \\begin{split}\n        \\A V_{k+p} &= V_{k+p}H_{k+p} + r_{k+p}e_{k+p}^T \\\\\n        &= \\begin{pmatrix}V_{k+p} & v_{k+p+1} \\end{pmatrix} \\begin{pmatrix}H_{k+p} \\\\ \\beta_{k+p}e_{k+p}^T \\end{pmatrix}.\n    \\end{split}\n    \\label{eq:ArnoldiFactorization-k+p}\n\\end{equation}\nAn analogy of the explicitly shifte QR-algorithm may be applied to this truncated factorization of $\\A$.  It consists of the following four steps.  Let $\\mu$ be a shift and let $\\left(H-\\mu I\\right) = QR$ with $Q$ orthogonal and $R$ upper triangular.  Then (putting $V = V_{k+p}$, $H = H_{k+p}$)\n\\begin{subequations}\\begin{align}\n    \\left(\\A - \\mu I\\right)V - V\\left(H - \\mu I\\right) &= r_{k+p}e_{k+p}^T, \\\\\n    \\left(\\A - \\mu I\\right)V - VQR &= r_{k+p}e_{k+p}^T, \\\\ \\label{eq:IRAM-2}\n    \\left(\\A - \\mu I\\right)\\left(VQ\\right) - \\left(VQ\\right)\\left(RQ\\right) &= r_{k+p}e_{k+p}^TQ, \\\\\n    \\A\\left(VQ\\right) - \\left(VQ\\right)\\left(RQ + \\mu I\\right) &= r_{k+p}e_{k+p}^TQ, \\\\\n\\end{align}\\end{subequations}\nLet $V_+ = VQ$ and $H_+ = RQ + \\mu I$.  Then $H_+$ is upper Hessenberg and applying the matrices in Eq. \\ref{eq:IRAM-2} to the vector $e_1$ to expose the relationship of their first columns gives\n\\begin{equation}\n    \\left(\\A - \\mu I\\right)v_1 = v_1^+\\rho_{11}\n    \\label{}\n\\end{equation}\nwhere $\\rho_{11} = e_1^TRe_1$, $v_1^+ = V_+e_1$.\n\nThis idea may be extended for up to $p$ shifts being applied successively.  The application of a QR-iteration corresponding to an implicit shift $\\mu$ produces an upper Hessenberg orthogonal  $Q \\in \\mathbb{R}^{k+p}$ such that\n\\begin{equation}\n    \\A V_{k+p}Q = \\begin{pmatrix}V_{k+p}Q & v_{k+p+1}\\end{pmatrix}\\begin{pmatrix} Q^TH_{k+p}Q \\\\ \\beta_{k+p}e_{k+p}^TQ \\end{pmatrix}\n    \\label{}\n\\end{equation}\nAn application of $p$ implicit shifts therefore results in\n\\begin{equation}\n    \\A V_{k+p}^+ = \\begin{pmatrix}V_{k+p}^+ & v_{k+p+1} \\end{pmatrix}\\begin{pmatrix}H_{k+p}^+ \\\\ \\beta_{k+p}e_{k+p}^T\\hat{Q} \\end{pmatrix}\n    \\label{eq:pImplicitShifts}\n\\end{equation}\nwhere $V_{k+p}^+ = V_{k+p}\\hat{Q}$, $H_{k+p}^+ = \\hat{Q}^TH_{k+p}\\hat{Q}$, and $\\hat{Q} = Q_1Q_2 \\cdots Q_p$, with $Q_j$ the orthogonal matrix associated with the shift $\\mu_j$.\n\nNow, partition\n\\begin{equation}\n    V_{k+p}^+ = \\begin{pmatrix}V_k^+ & \\hat{V}_p\\end{pmatrix},\\hspace{.25in} H_{k+p}^+ = \\begin{pmatrix} H_k^+ & M \\\\ \\hat{\\beta}_{k+p}e_1e_k^T & \\hat{H}_p \\end{pmatrix},\n    \\label{}\n\\end{equation}\nand note\n\\begin{equation}\n    \\beta_{k+p}e_{k+p}^T\\hat{Q} = \\left(\\underbrace{0,0 \\cdots \\tilde{\\beta}_{k+p} }_k,\\underbrace{b^T}_p\\right).\n    \\label{}\n\\end{equation}\nSubstituting into Eq. \\ref{eq:pImplicitShifts} gives\n\\begin{equation}\n    \\A \\left( V_k^+ , \\hat{V}_p \\right) = \\left(V_k^+, \\hat{V}_p, v_{k+p+1}\\right)\n    \\begin{bmatrix}\n        H_k^+ & M \\\\\n        \\hat{\\beta}_ke_1e_k^T & \\hat{H}_p \\\\\n        \\tilde{\\beta}_{k+p}e_k^T & b^T\n    \\end{bmatrix}.\n    \\label{eq:Substituted}\n\\end{equation}\nEquating the first $k$ columns on both sides of Eq. \\ref{eq:Substituted} gives\n\\begin{equation}\n    \\A V_k^+ = V_k^+H_k^+ + r_k^+e_k^T\n    \\label{}\n\\end{equation}\nso that\n\\begin{equation}\n    \\A V_k^+ = \\left(V_k^+, v_{k+1}^+\\right)\n    \\begin{pmatrix}\n        H_k^+ \\\\\n        \\beta_k^+e_k^+\n    \\end{pmatrix}\n    \\label{eq:ArnoldiNewFactorization}\n\\end{equation}\nwhere $v_{k+1}^+ = \\left(1/\\beta_K^+\\right)r_k^+$, $r_k^+ \\equiv \\left(\\hat{V}_pe_1\\hat{\\beta}_k + v_{k+p+1}\\tilde{\\beta}_{k+p} \\right)$, and $\\beta_k^+ = \\left\\|r_k^+\\right\\|$.  Note that $\\left(V_k^+\\right)^+\\hat{V}_pe_1 = 0$ and $\\left(V_k^+\\right)^Tv_{k+p+1} = 0$, so $\\left(V_k^+\\right)^Tv_{k+1}^+ = 0$.  Thus Eq. \\ref{eq:ArnoldiNewFactorization} is a legitimate Arnoldi factorization of $\\A$.  Using this as a starting point it is possible to use $p$ additional steps of the Arnoldi recursions to Eqs. \\ref{eq:ArnoldiRecursion-1}---\\ref{eq:ArnoldiRecursion-4} to return to the original form Eq. \\ref{eq:ArnoldiFactorization-k+p}.  This requires only $p$ evaluations of a matrix-vector product involving the matrix $\\A$ and the $p$-new Arnoldi vectors.  This is to be contrasted with the [explicitly restarted Arnoldi's method by Saad] where the entire Arnoldi sequence is restarted.  \n\n\\subsection{Algorithms}\nIn this section I will show the Arnoldi algorithm and the implicitly restarted Arnoldi's method for comparison.\n\n\\begin{algorithm2e}[H]\n    \\label{alg:Arnoldi}\n    \\SetVline\n    \\caption{Traditional Arnoldi's Method}\n\n    \\KwIn{$\\A V - VH = re_k^T$ with $V^TV = I_k$, and $V^Tr = 0$.}\n    \\KwOut{$\\A V - VH = re_{k+p}^T$ with $V^TV = I_{k+p}$, and $V^Tr = 0$.}\n\n    $\\left[H, V, r\\right] = \\mathtt{Arnoldi}\\left( \\A, H, V, r, k, p \\right)$\n    \n    \\BlankLine\n    \\For{$j=1,2,\\ldots,p$}{\n    $\\beta \\leftarrow \\|r\\|$; \\hspace{.25in} if $\\left( \\beta < \\mathrm{Tol} \\right)$ stop;\\;\n    $H \\leftarrow \\begin{pmatrix}\n        H \\\\ \\beta e_{k+j+1}^T\n    \\end{pmatrix}$   \\hspace{0.15in} \\tcp{Add row to $H$}\\;\n    $v \\leftarrow \\frac{1}{\\beta}r$  \\hspace{0.75in} \\tcp{Normalize $v$}\\;\n    $V \\leftarrow \\left(V, v\\right)$ \\hspace{0.5in} \\tcp{Add column to $V$}\\;\n    $w \\leftarrow \\A v$\\;\n    $h \\leftarrow V^Tw$\\;\n    $H \\leftarrow \\left(H, h\\right)$\\;\n    $r \\leftarrow w - Vh$\\;\n    Reorthogonalize if necessary\\;\n    }\n\\end{algorithm2e}\n\nThe basic or traditional Arnoldi's (Algorithm \\ref{alg:Arnoldi}) method is used in the restarted version as shown in Algorithm \\ref{alg:IRAM}.\n\n\\begin{algorithm2e}[H]\n    \\label{alg:IRAM}\n    \\SetVline\n    \\caption{Implicitly Restarted Arnoldi's Method}\n\n    $\\left[V, H, r\\right] = \\mathtt{IRAM}\\left(\\A, k, p, tol\\right)$\n\n    \\BlankLine\n    \\emph{initialize} $V(:,1) = v_1$\\;\n    \\hspace{0.6in} $H \\leftarrow\\left(v_1^T\\A v_1\\right)$\\;\n    \\hspace{0.6in} $r \\leftarrow \\A v_1 - v_1H$\\;\n    $\\left[H, V, r\\right] = \\mathtt{Arnoldi}\\left( \\A, H, V, r, 1, k \\right)$ \\hspace{0.32in} \\tcp{Take $k$ steps of Arnoldi}\\;\n    \\For{$m = 1,2,\\cdots$}{\n        if $\\left(\\|r\\| < tol\\right)$ stop;\\;\n        $\\left[H, V, r\\right] = \\mathtt{Arnoldi}\\left( \\A, H, V, r, k, p \\right)$ \\hspace{0.05in} \\tcp{Take $p$ more steps of Arnoldi}\\;\n        \\BlankLine\n        \\tcp{Shifted QR algorithm}\n        $u = \\mathtt{Shifts}\\left(H,p\\right)$\\;\n        $Q \\leftarrow I_{k+p}$ \\hspace{0.75in} \\tcp{Initialize $Q$}\\;\n        \\For{$j=1,2,\\cdots, p$}{ \n            $H \\leftarrow Q_j^T H Q_j$\\;\n            $Q \\leftarrow Q Q_j$\\;\n        }\n        $v\\leftarrow \\left(VQ\\right)e{k+1}$\\;\n        $V \\leftarrow \\left(VQ\\right)\\begin{pmatrix} I_k \\\\ 0 \\end{pmatrix}$\\;\n            $r \\leftarrow \\left(v\\beta_k + r\\sigma_k\\right)$ where $\\beta_k = e_{k+1}^THe_k$, $\\sigma_k = e_{k+p}^TQe_k$\\;\n    }\n\\end{algorithm2e}\n\nEach application of an implicit shift $\\mu_j$ will replace the starting vector $v_1$ with $\\left(\\A-\\mu_jI\\right)v_1$.  Thus after completion of each loop in Algorithm \\ref{alg:IRAM}:\n\\begin{equation}\n    Ve_1 = v_1  \\leftarrow \\psi(\\A)v_1;\n    \\label{}\n\\end{equation}\nwhere $\\psi(\\lambda) = \\left(1/\\tau\\right) \\prod_{j=1}^p\\left(\\lambda - \\mu_j\\right)$ with $\\tau$ a normalization factor.  Numerous choices are possible for the selection of these $p$ shifts.  One possibility is to choose $p$ ``exact'' shifts with respect to $H$.  One could find the eigenvalues of $H$---this is simple because $H$ is small---and sort them according to largest real part or largest modulus.  The shifts would then be the $p$ smallest eigenvalues.  Selecting these exact shifts has interesting consequences in the iteration.\n\n\\begin{lem}\n    Let $\\lambda(H) = \\left\\{\\theta_1,\\cdots,\\theta_k\\right\\}\\cup\\left\\{\\mu_1, \\cdots, \\mu_p\\right\\}$ be a disjoint partition of the spectrum of $H$ and let\n    \\begin{equation}\n        H_+ = Q^THQ,\n        \\label{}\n    \\end{equation}\n    where $Q = Q_1Q_2\\cdots Q_p$ with $Q_j$ implicitly determined by the shift $\\mu_j$.  If $\\beta_j\\neq 0, 1 \\leq j \\leq k-1$, then $\\beta_k = 0$ and\n    \\begin{equation}\n        H_+ \\begin{pmatrix}\n            H_k^+ & M^+ \\\\\n            0 R_p\n        \\end{pmatrix},\n        \\label{}\n    \\end{equation}\n    where $\\lambda\\left(H_k^+\\right) = \\left\\{\\theta_1,\\cdots,\\theta_k\\right\\}$, $\\lambda\\left(R_p\\right) = \\left\\{\\mu_1, \\mu_2,\\cdots, \\mu_p\\right\\}$. Moreover,\n    \\begin{equation}\n        v_1^+ = VQe_1 = \\sum x_j,\n        \\label{}\n    \\end{equation}\n    where each $x_j$ is a Ritz vector corresponding to the Ritz value $\\theta_j$, i.e., $x_j = Vy_j$ where $Hy_j = y_j\\theta_j, 1 \\leq j \\leq k$.\n\\end{lem}\n\nThis lemma provides a very nice interpretation of the iteration when exact shifts are chosen.  Casting out the unwanted set of eigenvalues using exact shifts is mathematically equivalent to restarting the Arnoldi factorization from the beginning after updating $v_1 \\leftarrow \\sum x_j\\xi_j$, a linear combination of Ritz vectors associated with the ``wanted'' eigenvalues.  Thus the updated starting vector has been implicitly replaced by the sum of $k$ approximate eigenvectors.  Approximate eigenvectors from a Krylov subspace of dimension $k+p$ are available at each iteration for a cost of $p$ rather than $k+p$ matrix-vector products per iteration.\n\n\n\\section{IRAM from ``Fundamental of Matrix Computaions''}\nAfter $m$ steps of the Arnoldi process we have generated $Q_m = \\left[q_1 \\cdots q_m\\right]$.  The columns of $Q_m$ are orthonormal.  An upper Hessenberg matrix, $H_m$, is also generated.  The relationship between $Q_m$, $H_m$, and the linear operator $\\A$ is formed:\n\\begin{equation}\n    \\A Q_m = Q_mH_m + q_{m+1}h_{m+1,m}e_m^T.\n    \\label{eq:start}\n\\end{equation}\nThe eigenvalues of $H_m$ are the Ritz values of $\\A$ associated with the subspace spanned by the columns of $Q_m$.  These eigenvalues can be ordered with the smallest $j$ eigenvalues used as shifts in the QR algorithm.  These eigenvalues approximate the region of the spectrum we are not interested in and want to suppress.\n\nIRAM performs $j$ iterations of the QR algorithm on the upper Hessenberg matrix $H_m$ using the $j$ smallest eigenvalues.  This is computationally cheap because $m$, the size of $H_m$ is small.  The effect of the QR iterations is a unitary similarity transformation\n\\begin{equation}\n    \\hat{H_m} = V^{-1}H_mV_m,\n    \\label{eq:simTransform}\n\\end{equation}\nwhere\n\\begin{equation}\n    p(H_m) = V_mR_m,\n\\end{equation}\n$V_m$ is the unitary matrix usually called $Q$ in the QR algorithm; $R_m$ is upper triangular and $p$ is a polynomial of degree $j$ with zeros equal to the shifts we previously chose.\\footnote{I need to be able to show this.}\n\nThe QR algorithm preserves upper Hessenberg form so $\\hat{H}_m$ is also upper Hessenberg.  Let $\\hat{Q}_m = Q_mV_m$, and let $\\hat{q}_1$ be the first column of $\\hat{Q}_m$.\n\nThe next iteration of IRAM consists of $m$ more Arnoldi steps, but these don't have to be started from scratch.  To see this, multiply Eq. \\ref{eq:start} by $V_m$ on the right side and use Eq. \\ref{eq:simTransform} we obtain\n\\begin{subequations}\\begin{align}\n    \\A Q_mV_m &= Q_mH_mV_m + q_{m+1}h_{m+1,m}e_m^TV_m \\\\\n    \\A \\left(Q_mV_m\\right) &= Q_m\\left(V_m\\hat{H}_m\\right) + q_{m+1}h_{m+1,m}e_m^TV_m \\\\\n    \\A \\hat{Q}_m &= \\left(Q_mV_m\\right)\\hat{H}_m + q_{m+1}h_{m+1,m}e_m^TV_m \\\\\n    \\A \\hat{Q}_m &= \\hat{Q}_m\\hat{H}_m + q_{m+1}h_{m+1,m}e_m^TV_m  \\label{eq:middle}\n\\end{align}\\end{subequations}\nOne can show that $e_m^TV_m$ has $m-j-1$ leading zeros (after performing $j$ exact shifts).  If we drop the last $j$ entries from this vector we obtain $\\beta e_k^T$ where $\\beta$ is some non-zero scalar.  Dropping the last $j$ columns from Eq. \\ref{eq:middle} we obtain\n\\begin{equation}\n    \\A \\hat{Q}_k = \\hat{Q}_k\\hat{H}_k + \\check{q}_{m+1}\\check{h}_{k+1,k}e_k^T + q_{m+1}h_{m+1,m}\\beta e_k^T.\n    \\label{eq:midCheck}\n\\end{equation}\nHere $\\check{q}_{k+1}$ is the $(k+1)$st column of $\\hat{Q}_m$ and $\\check{h}_{k+1,k}$ is the $(k+1,k)$ entry of $\\hat{H}_{l+1,k}$.\n\nNow we define \n\\begin{equation}\n    \\hat{q}_{k+1} = \\gamma\\left(\\check{q}_{k+1}\\check{h}_{k+1,k} + q_{m+1}h_{m+1,m}\\beta\\right)\n\\end{equation}\nwith $\\gamma$ such that $\\|\\hat{q}_{k+1}\\|_2 = 1$.\n\nIf we let $\\hat{h}_{k+1,k} = 1/\\gamma$ then Eq. \\ref{eq:midCheck} becomes \n\\begin{equation}\n    \\A \\hat{Q}_k = \\hat{Q}_k\\hat{H}_k + \\hat{q}_{k+1}\\hat{h}_{k+1,k}e_k^T,\n\\end{equation}\nwhich is identical to Eq. \\ref{eq:start}, except for the hats on the symbols and $m$ being replaced by $k$.  Since we know that the Arnoldi vectors (the orthonormal columns of $Q$) are uniquely determined by the first column, we can conclude that this is the same equation that would have been created if Arnoldi's method had been run as usual.  Thus IRAM can start at step $k$ saving $k-1$ steps, a potentially dramatic decrease in runtime.\n\n\\subsection{Why IRAM works}\nIn this subsection I will describe how the shifts suppress that region of the spectrum of $\\A$.\n\\end{document}\n\n", "meta": {"hexsha": "35d41688e8c9b7a244eb72305f452303989a3ac2", "size": 16632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/IRAM.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/IRAM.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/IRAM.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": 59.1886120996, "max_line_length": 890, "alphanum_fraction": 0.668049543, "num_tokens": 5960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6740590475470164}}
{"text": "\\documentclass[22pt,a4paper,notitlepage]{article}\n\n%% Use your favourite packages here\n\\usepackage[margin=0.8in]{geometry}\n\\usepackage[T1]{fontenc}\n\\usepackage{times} \n\\usepackage{amsmath}\n\\usepackage{braket}\n\\usepackage{cancel}\n\\usepackage{hyperref}\n\n\\begin{document}\n\\title{Title of your quick note}\n\\author{Your Name}\n\\date{\\today} % Can also use a custom date\n\\maketitle\n\n%%=================Start====================%%\n\n\\noindent % Start line without indentation\nWrite sentences using words and equations such as $x^3 - y = 0$. We can also write standalone equations like below\n\n$$ H \\ket{\\Psi} = E \\ket{\\Psi}.\n$$\n\\\\ % Line break without indentation\nMore words.\n\n%% Use sections to organize\n\\section{Section with numbers}\n\n\\subsection{Subsection with numbers}\n\n\\section*{Section without numbers}\n\n\\subsection*{Subsection without numbers}\n\nUse \\textit{align} to write multiple lines of equations as below\n\n\\begin{align*}\n\\ket{\\Psi} \n&:= \\sum_{\\mu} \\: c_{\\mu} \\ket{\\mu},\n\\\\\nE \n&= \\frac{\\braket{\\Psi | H | \\Psi}}{\\braket{\\Psi|\\Psi}},\n\\end{align*}\nmore words just below equations.\n\\\\ \\\\ % Line break without indentation\nWe can also include equation numbers.\n\n\\begin{align}\n\\ket{\\Psi} \n&:= \\sum_{\\mu} \\: c_{\\mu} \\ket{\\mu},\n\\\\\nE \n&= \\frac{\\braket{\\Psi | H | \\Psi}}{\\braket{\\Psi|\\Psi}}.\n\\end{align}\n\n\\noindent\nWe can create hyperlinks using \\href{https://www.overleaf.com/learn/latex/Hyperlinks}{hyperref} and also \\cancel{strikethrough} using the \\textit{cancel} package.\n\n\\end{document}", "meta": {"hexsha": "2c5086439244037587a29db65c06c3967325bc00", "size": 1485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QuickMathNote.tex", "max_stars_repo_name": "rishabdchem/rishab-latex-templates", "max_stars_repo_head_hexsha": "d8417cb575618909edccb6b81f29d8059dcf6c18", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QuickMathNote.tex", "max_issues_repo_name": "rishabdchem/rishab-latex-templates", "max_issues_repo_head_hexsha": "d8417cb575618909edccb6b81f29d8059dcf6c18", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QuickMathNote.tex", "max_forks_repo_name": "rishabdchem/rishab-latex-templates", "max_forks_repo_head_hexsha": "d8417cb575618909edccb6b81f29d8059dcf6c18", "max_forks_repo_licenses": ["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.3442622951, "max_line_length": 162, "alphanum_fraction": 0.6942760943, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6740590330959165}}
{"text": "%\\newpage\nIn this chapter, we will mainly consider two statistic models, namely\nlogistic regression for linearly separable sets,\nand support vector machine (SVM).\nThese two linear models form the foundation of deep learning, since\nthe final fully connected output layer of a deep neural network is\noften given by one of these two linear classifiers.  One main objective in this chapter is that  these linear classification models can be used to classify a collection of \nlinearly separable classes.  \n\nIn the presentation of this chapter, we treat both logistic regression\nand support vector machine as pure mathematical techniques for\nlinearly separable sets.  In the later chapters, we will relate these\ntechniques in the context of machine learning, especially deep\nlearning. \n\\section{Definition of linearly separable sets}\nIn this section, we consider a special class of $k$ linearly separable sets for $k\\ge 2$.  Let us first introduce the following\ndefinition for binary classification. \n\n\nFor $k=2$, there is a very simple geometric interpretation of two\nlinearly separable sets. \n\\begin{definition}\\label{lem:2class}\n  The two sets $A_1$, $A_2\\subset \\mathbb{R}^d$ are linearly separable\n   if there exists a hyperplane\n  \\begin{equation}\n    \\label{2classH}\nH_0=\\{x:wx+b=0\\},    \n  \\end{equation}\n such that $wx+b>0$ if $x\\in A_1$ and $wx+b<0$ if $x\\in A_2$.\n  \\end{definition}\n\\begin{figure}\n\\centering\n\\includegraphics[width=1.5in]{LinearS1.png}  \\quad  %\\includegraphics[width=1.5in]{LinearS2.png} \n\\caption{One linearly separable set}\n\\label{twoclassification}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=1.5in]{NLinearS1.png}  \\quad  \\includegraphics[width=1.5in]{NLinearS2.png} \n\\caption{Two non-linearly separable sets}\n\\label{twoclassification}\n\\end{figure}\n\n%\\blankpage\n%\\newbreak\n\\begin{lemma}\\label{lem:2class}\n  The two sets $A_1$, $A_2\\subset \\mathbb{R}^d$ are linearly separable\n if there exists \n  \\begin{equation}\n    \\label{Wb}\nW=\n\\begin{pmatrix}\n  w_1\\\\\nw_2\n\\end{pmatrix}\n\\in \\mathbb{R}^{2\\times d}, \nb=\n\\begin{pmatrix}\n  b_1\\\\\nb_2\n\\end{pmatrix}\n\\in \\mathbb{R}^{2\\times d}, \n\\end{equation}\nsuch that,  % for each $1\\le i\\le 2$ and $ j \\neq i$\n\\begin{equation}\n\\label{eq:3}\n w_1x+b_1 > w_2x+b_2,\\ \\forall x\\in A_1,\n \\end{equation}\nand\n\\begin{equation}\n\\label{eq:3}\n w_1x+b_1 < w_2x+b_2,\\ \\forall x\\in A_2.\n \\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\tHere, we can just take $w = w_1 - w_2$ and $b = b_1 - b_2$, \n\tthen we can check that the hyperplane $wx + b$ satisfies the\n\tdefinition as presented before.\n\\end{proof}\n\n\n%\\blankpage\n%\\newbreak\nNow let us consider multi-class classification.\nTo begin with the definition, let us assume that the data space is \ndivided into $k$ classes represented by $k$ disjoint sets $A_1,A_2,\\cdots,A_k\\subset \\mathbb{R}^d$, which means\n\\begin{equation}\nA = A_1\\cup A_2\\cup \\cdots \\cup A_k, ~A_i\\cap A_j = \\emptyset, \\forall i \\neq j.\n\\end{equation}\n\n\\begin{definition}[Linearly Separable]\n  A collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$ are\n  linearly separable if there exist\n  \\begin{equation}\n    \\label{Wb}\nW=\n\\begin{pmatrix}\n  w_1\\\\\n\\vdots\\\\\nw_k\n\\end{pmatrix}\n\\in \\mathbb{R}^{k\\times d}, \nb=\n\\begin{pmatrix}\n  b_1\\\\\n\\vdots\\\\\nb_k\n\\end{pmatrix}\n\\in \\mathbb{R}^{k\\times d}, \n\\end{equation}\nsuch that,   for each $1\\le i\\le k$ and $ j \\neq i$\n\\begin{equation}\n\\label{eq:3}\n w_ix+b_i > w_jx+b_j,\\ \\forall x\\in A_i.\n \\end{equation}\nnamely, each pairs of $A_i$ and $A_j$ are linearly separable by the plane\n\\begin{equation}\n  \\label{Hij}\nH_{ij}=\\{(w_i-w_j)\\cdot x+(b_i-b_j) = 0\\}, \\quad \\forall j\\neq i.\n\\end{equation} \n\\end{definition}\nThe geometric interpretation for linearly separable sets is less\nobvious when $k>2$. \n\\begin{lemma}{\\label{Interplation}}\nAssume that $A_1,...,A_k$ are linearly separable and $ W\\in\n\\mathbb{R}^{k\\times d} $ and $b\\in\\mathbb{R}^k $ satisfy \\eqref{Wb}.  Define\n\\begin{equation}\n\\label{Gammai}\n\\Gamma_i(W,b) = \\{x\\in\\mathbb R^d: (Wx+b)_i > (Wx+b)_j,\\ \\forall j \\neq i\\}     \n\\end{equation}\nThen for each $i$, \n\\begin{equation}\n  \\label{AiGamma}\nA_i \\subset \\Gamma_i(W,b)  \n\\end{equation}\n\\end{lemma}\nWe note that  each $\\Gamma_i(W,b)  $ is a polygon whose boundary consists of hyperplanes given by \n\\eqref{Hij}.\n\\begin{figure}\n\\centering\n\t\\includegraphics[width=1.5in]{./figures/3-class.PNG}\n\t\\caption{Linearly separable sets in 2-d space (k = 3)}\n\t\\label{twoclassification}\n\\end{figure}\n\nWe next introduce two more definitions of linearly separable sets that\nhave more clear geometric interpretation. \n\n\\begin{definition}[All-vs-One Linearly Separable]\n A collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$ is\n all-vs-one linearly separable\nif for each $i = 1,...,k$, \n$A_i$ and $\\displaystyle \\cup_{j\\neq i} A_j$ are linearly separable. \n\\end{definition}\n\n\\begin{figure}[H]\n\\centering\n\t\\includegraphics[width=1.5in]{./figures/MulLClassfication.PNG}\n\t\\caption{All-vs-One linearly separable sets (k = 3)}\n\t\\label{twoclassification}\n\\end{figure}\n\n\\begin{definition}[Pairwise Linearly Separable]\n  A collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$ is\n  pairwise linearly separable if for each pair of indices $1\\leq i <\n  j\\leq k$, \n$A_i$ and $A_j$ are linearly separable. \n\\end{definition}\n\n\n\n\\begin{figure}[H]\n\\centering\n\t\\includegraphics[width=1.5in]{./figures/pairwise_linearly_separable.png}\n\t\\caption{Pairwise linearly separable sets in 2-d space (k = 3)}\n\t\\label{pairwise_separable_example}\n\\end{figure}\n\n\nWe begin by comparing our notion of linearly separable to the two\nother previously introduced geometric definitions of all-vs-one\nlinearly separable and pairwise lineaerly separable.  Obviously, in\nthe case of two classes, they are all equivalent, however, with more\nthan two classes this is no longer the case. We do have the following\nimplications, though.\n\n\\begin{lemma}\n  If $A_1,...,A_k\\subset \\mathbb{R}^d$ are all-vs-one linearly\n  separable, then they are linearly separable as well.\n\\end{lemma}\n\\begin{proof}\n Assume that $A_1,...,A_k$ are all-vs-one linearly separable. For each $i$, let $w_i$, $b_i$ be such that $w_ix + b_i$ separates\n $A_i$ from $\\cup_{j\\neq i} A_j$, i.e. $w_ix + b_i > 0$ for $x\\in A_i$ and $w_ix + b_i < 0$ for $x \\in \\cup_{j\\neq i} A_j$.\n \n Set $W = (w_1^T,w_2^T,\\cdots,w_k^T)^T$, $b = (b_1,b_2,\\cdots,b_k)^T$ and observe that if $x\\in A_i$, then\n $(Wx + b)_i > 0$ while $(Wx + b)_j < 0$ for all $j\\neq i$.\n\\end{proof}\n\n\\begin{lemma}\n  If $A_1,...,A_k\\subset \\mathbb{R}^n$ are linearly separable, then\n  they are pairwise linearly separable as well.\n\\end{lemma}\n\n\\begin{proof}\n  If $A_1,...,A_k\\subset \\mathbb{R}^d$ are linearly separable, suppose\n  that $W = (w_1^T,w_2^T,\\cdots,w_k^T)^T$, $b =\n  (b_1,b_2,\\cdots,b_k)^T$. So we have\n\t\\begin{equation}\n\t\\begin{cases} \n\tw_i x+ b_i > w_j x + b_j & x\\in A_i \\\\\n\tw_i x+ b_i < w_j x + b_j& x\\in A_j \\\\\n\t\\end{cases}\n\t\\end{equation}\n\tTake $w_{i,j} = w_i - w_j, b_{i,j} = b_i-b_j$, then we have \n\t\\begin{equation}\n\tw_{i,j}x + b_{i,j}\\begin{cases} \n\t> 0 & x\\in A_i \\\\\n\t< 0 & x\\in A_j \\\\\n\t\\end{cases}\n\t\\end{equation}\n\tSo $A_1,...,A_k$ are pairwise linearly separable.\n\\end{proof}\n\nHowever, the converses of both of these statements are false, as the following examples show.\n\\begin{example}[Linearly separable but not all-vs-one linearly separable]\n Consider the sets $A_1, A_2, A_3\\subset \\mathbb{R}$ given by $A_1 = [-4,-2]$, $A_2 = [-1,1]$, and $A_3 = [2,4]$. These\n sets are clearly not one-vs-all linearly separable because $A_2$ cannot be separated from both $A_1$ and $A_3$ by a single\n plane (in $\\mathbb{R}$ this is just cutting the real line at a given number, and $A_2$ is in the middle).\n \n However, these sets are linearly separated by $W = [-2,0,2]^T$ and $b = [-3,0,-3]^T$, for example.\n\\end{example}\n\\begin{example}[Pairwise linearly separable but not linearly separable]\nConsider the sets $A_1, A_2, A_3\\subset \\mathbb{R}^2$ shown in figure \\ref{pairwise_separable_example}.\nNote that $A_i$ and $A_j$ are separated by hyperplane $H_{i,j}$ (drawn in the figure) and so these sets are\npairwise linearly separable. We will show that they are not linearly separable.\n\nAssume to the contrary that $W\\in \\mathbb{R}^{3\\times 2}$ and $b\\in \\mathbb{R}^2$ separate $A_1$, $A_2$, and $A_3$. Then\n$(w_i - w_j)x + (b_i - b_j)$ must be a plane which separates $A_i$ and $A_j$. Now consider a point $z$ bounded by $A_1$, $A_2$ and $A_3$ in figure \n\\ref{pairwise_separable_example}. We see from the figure that given any plane separating $A_1$ from $A_2$, $z$ must\nbe on the same side as $A_2$, given any plane separating $A_2$ from $A_3$, $z$ must be on the same side as\n$A_3$, and given any plane separating $A_3$ from $A_1$, $z$ must be on the same side as $A_1$.\n\nThis means that $(w_2 - w_1)z + (b_2 - b_1) > 0$, $(w_3 - w_2)z + (b_3 - b_2) > 0$, and\n$(w_1 - w_3)z + (b_1 - b_3) > 0$. Adding these together, we obtain $0 > 0$, a contradiction.\n\nThe essence behind this example is that although the sets $A_1$, $A_2$, and $A_3$ are pairwise linearly separable, \nno possible pairwise separation allows us to consistently classify arbitrary new points. However, a linear separation\nwould give us a consistent scheme for classifying new points.\n\n\\end{example}\n\nSo the notion of linear separability is sandwiched in between the more\nintuitive notions of all-vs-one and pairwise separability. It turns\nout that linear separability is the notion which is most useful for\nthe $k$-class classification problem and so we focus on this notion of\nseparability from now on.\n\n\n\n\n\\newpage\n\\section{Some simple linear classifiers}\nWe begin with the simplest situation, where there are only two classes.\n\\begin{lemma}\nIf $A_1$, $A_2\\subset\\mathbb{R}^n$ are linearly separable, then there exists $w\\in\\mathbb{R}^{1\\times n}$, $b\\in\\mathbb{R}$ such that\n        \\begin{equation}\n          f(x):=h\\left( \\begin{array}{cc}\n              wx+b \\\\\n              -(wx+b)\n            \\end{array}\n          \\right)\n          =\n          \\begin{cases}\n            e_1 \\quad x\\in A_1 \\\\\n            e_2 \\quad x\\in A_2,\n          \\end{cases}\n        \\end{equation}\n      where $e_1=\\left( \\begin{array}{cc} 1\\\\0 \\end{array} \\right)$,\n      $e_2=\\left( \\begin{array}{cc} 0\\\\1 \\end{array} \\right)$ and\n        $h$ is the Heaviside function defined by:\n        \\begin{equation}\n        \\label{heaviside}\n        h(t):=\\begin{cases}\n        0 \\quad t < 0, \\\\\n        1 \\quad t \\ge 0 .\n        \\end{cases}\n        \\end{equation}\n      \\end{lemma}\n      The Heaviside function $h$ defined in \\eqref{heaviside} is a\n      classic activation function. \n      \\begin{figure}\n      \t\\centering\n      \t\\includegraphics[width=2in]{figures/Heaviside.png}   \n      \t\\caption{Heaviside activation function }\n      \\end{figure}\n      \n      But its discontinuity at $t=0$\n      makes it difficult to use in practice. Instead we consider the\n      following linear-step function:\n  \\begin{equation}\\label{linear-step}\n  \\sigma(t)=\n    \\begin{cases}\n       0 \\quad t<0, \\\\\n      t\\quad 0\\le t\\le 1, \\\\\n     1 \\quad t> 1. \\\\\n    \\end{cases}\n  \\end{equation}\n\\begin{figure}\n\\centering\n\\includegraphics[width=2in]{./figures/zig}   \n\\caption{Linear-step function}\n\\end{figure}\nThis $\\sigma(t)$ is closely related to the so-called Rectified Linear Unit function: \n\\begin{equation}\\label{ReLU}\nReLU(t):=\\begin{cases}\n0 \\quad t< 0, \\\\\nt \\quad t\\ge 0. \n\\end{cases}\n\\end{equation}\n\\begin{figure}\n\\centering\n\\includegraphics[width=2in]{./figures/ReLU}   \n\\caption{ReLU activation function }\n\\end{figure}\nNamely \n\\begin{equation}\n  \\label{sigma-ReLU}\n\\sigma(t)=ReLU(t)-ReLU(t-1).\n\\end{equation}\n\n\\begin{lemma}\n\tIf $A_1$, $A_2\\subset\\mathbb{R}^n$ are linearly separable, then there exist $w\\in\\mathbb{R}^{1\\times n}$, $b\\in\\mathbb{R}$ such that\n\t\\begin{equation}\n\tf(x):=\\left( \\begin{array}{cc}\n\t\\sigma(wx+b) \\\\\n\t\\sigma(-(wx+b))\n\t\\end{array}\n\t\\right)\n\t= e_i,\\quad\\mathrm{if}\\ x\\in A_i,\\ i=1,2.\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n  By the definition of linearly separable sets, there exist\n  $w_0\\in\\mathbb{R}^{1\\times n}$, $b_0\\in\\mathbb{R}$ such that\n  $w_0x+b_0>0$ if $x\\in A_1$ and $w_0x+b_0<0$ if $x\\in A_2$. We can\n  find $\\varepsilon>0$ such that\n\\begin{equation}\nw_0x+b_0\\begin{cases}\n>\\varepsilon \\qquad x\\in A_1, \\\\\n<-\\varepsilon \\quad x\\in A_2 .\n\\end{cases}\n\\end{equation}\nLet $w=w_0/\\varepsilon$, $b=b_0/\\varepsilon$, we have:\n\\begin{equation}\nwx+b\\begin{cases}\n>1 \\qquad x\\in A_1, \\\\\n<-1 \\quad x\\in A_2 .\n\\end{cases}\n\\end{equation}\nwhich implies $f(x)=e_i$ if $x\\in A_i$.\n\\end{proof}\n\nThe extension of the above lemma to $k$-classes is straightforward.\n\\begin{lemma}\n  If $A_i \\subset \\mathbb{R}^n(1\\le i \\le k)$ are linearly separable,\n  there exist $W\\in\\mathbb{R}^{k\\times n}$, $b\\in\\mathbb{R}^k$ s.t.\n\\begin{equation}\n  \\label{simple-f}\n\tf(x):=\\sigma(Wx+b) = e_i,\\quad\\mathrm{for\\ }x\\in A_i  \n\\end{equation}\n\\end{lemma}\n\nOftentimes, we use the following notation\n\\begin{equation}\n  \\label{theta}\n\\theta=(W,b)\\in\\mathbb{R}^{k\\times(n+1)} \\mbox{ and } \\theta[x]=Wx+b.\n\\end{equation}\n", "meta": {"hexsha": "4264f2c96ded85717645f3ed9c30a11c859627dd", "size": 12972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/LinearModels.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/LinearModels.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/LinearModels.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1368421053, "max_line_length": 172, "alphanum_fraction": 0.6886370644, "num_tokens": 4584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6740590149801565}}
{"text": "%%\n\\documentclass[11pt]{article}\n\\usepackage[english]{babel}\n\\usepackage[a4paper]{geometry}\n\\usepackage{amssymb,amsmath,amsthm}\n\\usepackage{graphicx,wrapfig}\n\\usepackage{latexsym}\n\\usepackage{mathtools} \n\\usepackage{hyperref}\n\\usepackage{fontspec}\n\\setmainfont{Cochin}\n\\usepackage[italic]{mathastext}\n%\n\\usepackage{cancel}\n%\n\\usepackage[backend=bibtex,sorting=none,giveninits=true]{biblatex}\n\\bibliography{../../../../Latex/Bibliotheque/bibliotheque.bib}\n%\n%---------------------------------------------------------\n%\\newcommand{\\Set}[1]{\\left\\{#1\\right\\}} \n%\\newcommand{\\transpose}[1]{#1^{\\mathsf{T}}} \n%\\renewcommand{\\div}{\\operatorname{div}} \n%\\newcommand{\\dn}[1]{\\frac{\\partial #1}{\\partial n}}\n%\\newcommand{\\GammaD}{\\Gamma_{\\rm D}}\n%\\newcommand{\\GammaN}{\\Gamma_{\\rm N}}\n%\\newcommand{\\udir}{u^{\\rm D}}\n\\newcommand{\\qd}{q^{\\rm D}}\n\\input{../../../../Latex/Articles/macros.tex}\n%---------------------------------------------------------\n%\n%---------------------------------------------------------\n%\n%\n%==========================================\n\\title{SimFem}\n\\author{Roland Becker}\n%\n%==========================================\n\\begin{document}\n%==========================================\n\\maketitle\n\\setcounter{tocdepth}{3}\n\\tableofcontents\n%\n%\n%==========================================\n\\section{Geometry and finite elements}\\label{sec:}\n%==========================================\n%\n%\n%-------------------------------------------------------------------------\n\\subsection{Simplices}\\label{subsec:}\n%-------------------------------------------------------------------------\n%\nWe consider an arbitrary non-degenerate simplex $K=(x_0,x_1,\\ldots, x_{d})$. The (signed) volume of $K$ is given by\n%\n\\begin{equation}\\label{eq:}\n|K| = \\frac{1}{d!} \\det(x_1-x_{0},\\ldots, x_{d}-x_{0})= \\frac{1}{d!} \\det(1,x_{0},x_1\\ldots, x_{d})\\quad 1=\\transpose{(1,\\ldots,1)}.\n\\end{equation}\n%\nThe $d+1$ sides $S_k$ (co-dimension one, $d-1$-simplices or facets) are defined by\n$S_k=(x_0,\\ldots, \\cancel{x_k}, \\ldots, x_{d})$. The height is $d_k=|P_{S_k}x_k - x_k|$, where $P_S$ is the orthogonal projection on the hyperplane associated to $S$. We have\n%\n\\begin{align*}\nd_k = d\\frac{|K|}{|S_k|} \\qquad\\mbox{(and for $d=3 \\; |S_k| = \\frac12 |u\\times v| $)}\n\\end{align*}\n%\n%\n%-------------------------------------------------------------------------\n\\subsection{Finite elements}\\label{subsec:}\n%-------------------------------------------------------------------------\n%\n%\nThe $d+1$ basis functions of the Courant element are the barycentric coordinates \n$\\lambda_i$ defined as being affine with respect to the coordinates and $\\lambda_i(x_j)=\\delta_{ij}$. The constant gradient is given by\n%\n\\begin{align*}\n\\nabla \\lambda_i = - \\frac{1}{d_i}\\vec{n_i}. \n\\end{align*}\n%\nThe relation with the $d+1$ Crouzeix-Raviart basis functions $\\psi_i$ is given by \n%\n\\begin{align*}\n\\psi_i = 1 - d\\lambda_i\n\\end{align*}\n%\nFinally the $d+1$ Raviart-Thomas basis functions $\\xi_i$, associated to side $S_i$, i.e. the opposite node $x_i$, are given by \n%\n\\begin{align*}\n\\xi_i = \\frac{x-x_i}{d_i} = \\frac{1}{d_i}\\sum_{j=0\\atop i\\ne j}^d x_j \\lambda_j\n\\end{align*}\n%\n\n%\n%-------------------------------------------------------------------------\n\\subsection{Numerical integration}\\label{subsec:}\n%-------------------------------------------------------------------------\n%\nAny polynomial in the barycentric coordinates can be integrates exactly.\n%\n\\begin{equation}\\label{eq:}\n\\int_K \\prod_{i=1}^{d+1}\\lambda_i^{n_i} \\,dv = d!|K|\\frac{\\prod\\limits_{i=1}^{d+1} n_i!}{\\left( \\sum\\limits_{i=1}^{d+1} n_i + d\\right)!}\n\\end{equation}\n%\nsee \\cite{EisenbergMalvern73}, \\cite{VermolenSegal18}.\n%\n\nLet $V=\\vect{\\phi}$. For a smooth function $f$ and $u=\\sum_j u_j \\phi_j$ we use and approximation based on $\\vect{\\psi}$ such that $\\psi_l(x_k-=\\delta_{kl}$ and\n%\n\\begin{align*}\nf(u) \\approx \\sum_k f(u(x_k))\\psi_k = \\sum_k f(\\sum_j u_j \\phi_j(x_k))\\psi_k\n\\end{align*}\n%\nThen\n%\n\\begin{align*}\n\\int_K f(u) \\phi_i \\approx \\sum_k f_k\\int_K \\psi_k\\phi_i,\\quad f_k = f(\\sum_l u_l \\phi_l(x_k))\\\\ \n\\int_K f'(u)(\\phi_j) \\phi_i \\approx \\sum_k f'_{k,j}\\int_K  \\psi_k\\phi_i,\\quad f'_{k,j} = f'(\\sum_l u_l \\phi_l(x_k))\\phi_j(x_k)\n\\end{align*}\n%\nFor $\\psi=\\phi$ this becomes considerably cheaper:\n%\n\\begin{align*}\n\\int_K f(u) \\phi_i \\approx \\sum_k f_k\\int_K \\phi_k\\phi_i,\\quad f_k = f(u_k)\\\\ \n\\int_K f'(u)(\\phi_j) \\phi_i \\approx f'_j\\int_K  \\phi_j \\phi_i,\\quad f'_k = f'(u_k)\n\\end{align*}\n%\n\n\n%\n%-------------------------------------------------------------------------\n\\subsection{Element matrices for $C^1$}\\label{subsec:}\n%-------------------------------------------------------------------------\n%\n%\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsubsection{Mass matrix}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%\n%\n\\begin{align*}\nM_{ij} = \\begin{cases}\n\\frac{2d!|K|}{(2+d)!}& $i=j$\\\\\n\\frac{d!|K|}{(2+d)!}& $i\\ne j$\n\\end{cases}\\quad\nM^{\\rm 1D} =\n|K| \n\\begin{bmatrix}\n\\frac13 & \\frac16\\\\\n\\frac16 & \\frac13\n\\end{bmatrix}, \\; \nM^{\\rm 2D} =\n|K| \n\\begin{bmatrix}\n\\frac16 & \\frac{1}{12} & \\frac{1}{12}\\\\\n\\frac{1}{12} & \\frac16 & \\frac{1}{12}\\\\\n\\frac{1}{12} & \\frac{1}{12} & \\frac16\n\\end{bmatrix}, \\; \nM^{\\rm 3D} =\n|K| \n\\begin{bmatrix}\n\\frac{1}{10} & \\frac{1}{20} & \\frac{1}{20} & \\frac{1}{20}\\\\\n\\frac{1}{20} & \\frac{1}{10} & \\frac{1}{20} & \\frac{1}{20}\\\\\n\\frac{1}{20} & \\frac{1}{20} & \\frac{1}{10} & \\frac{1}{20}\\\\\n\\frac{1}{20} & \\frac{1}{20} & \\frac{1}{20} & \\frac{1}{10}\n\\end{bmatrix}\n\\end{align*}\n%\n\nLumped mass\n\\begin{align*}\n\\tilde M_{ij} = \\begin{cases}\n\\frac{|K|}{(1+d)} & $i=j$\\\\\n0& $i\\ne j$\n\\end{cases}\n\\end{align*}\n\n%\n%==========================================\n\\section{Test problems}\\label{sec:}\n%==========================================\n%\n%\n%-------------------------------------------------------------------------\n\\subsection{Advection-Diffusion-Reaction}\\label{subsec:}\n%-------------------------------------------------------------------------\n%\n%\n\\begin{equation}\\label{eq:}\n\\div(\\beta u) - \\div(k \\nabla u) + \\psi(u) = f\\quad\\mbox{in $\\Omega$},\\qquad u=\\udir \\mbox{on $\\GammaD$},\\qquad k\\dn{u}=\\qd \\mbox{on $\\GammaN$}\n\\end{equation}\n%\n%\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsubsection{Courant element}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%\n%\n\\begin{align*}\n\\int_{\\Omega}\\psi(u)v +  \\int_{\\Omega}k \\nabla u\\cdot \\nabla v -\\int_{\\Omega}u\\beta\\cdot\\nabla v+\\int_{\\partial\\Omega}\\beta_n^+u v = \\int_{\\Omega}fv +\\int_{\\partial\\Omega}|\\beta_n^-|\\udir v\n\\end{align*}\n%\nPiecewise constant approximation for $k$\n%\n\\begin{align*}\n\\int_K \\nabla \\lambda_i \\cdot \\nabla \\lambda_j = |K| \\frac{n_i}{d_i}\\cdot\\frac{n_j}{d_j} = |K| \\frac{|S_i|}{d|K|}\\frac{|S_j|}{d|K|} n_i\\cdot n_j\n= \\frac{1}{d^2|K|}\\tilde n_i\\cdot \\tilde n_j\\\\\n\\\\\n-\\int_K u \\beta\\cdot\\nabla \\lambda_i = u(x_K)|K| \\beta\\cdot\\frac{n_i}{d_i} = u(x_K)\\frac{1}{d}\\beta\\cdot\\tilde n_i \\\\\n- \\int_S f \\dn{v_i} = -f(x_S) |S| \\nabla v_i \\cdot n = f(x_S) |S| \\frac{1}{d_i} n_i \\cdot n= f(x_S) |S| \\frac{|S_i|}{d|K|} n_i \\cdot n\n= f(x_S) \\frac{\\tilde n_i \\cdot \\tilde n}{d|K|}\n\\end{align*}\n%\n\n%\n%-------------------------------------------------------------------------\n\\subsection{Turing}\\label{subsec:}\n%-------------------------------------------------------------------------\n%\nWe consider a reaction-diffusion system on $\\Omega=]-1,+1[^d$\n%\n\\begin{equation}\\label{eq:reacdiff}\n\\left\\{\\;\n\\begin{split}\n\\frac{\\partial u}{\\partial t}  -k_u\\Delta u =& f(u,v)\\quad\\mbox{in $\\Omega$},\\qquad \\frac{\\partial u}{\\partial n}=0\\quad\\mbox{on $\\partial\\Omega$},\\\\\n\\frac{\\partial v}{\\partial t}  -k_v \\Delta v=&  g(u,v)\\quad\\mbox{in $\\Omega$},\\qquad \\frac{\\partial v}{\\partial n}=0\\quad\\mbox{on $\\partial\\Omega$},\n\\end{split}\n\\right.\n\\end{equation}\n%\nAlan Turing discovered that the astonishing effect of destabilization by diffusion \\cite{Turing52}, which leads to pattern formation \n\\footnote{For an introduction and references see \\url{https://en.wikipedia.org/wiki/Reaction–diffusion_system}.}\n%\n\\begin{equation}\\label{eq:}\nf(u,v) = (a-u) - \\psi(u,v),\\qquad  g(u,v)=\\psi(u,v).\n\\end{equation}\n%\nAn equilibrium point satisfies\n%\n\\begin{align*}\nu^* = a,\\qquad \\psi(a,v^*)=0\n\\end{align*}\n%\nThe linear stability analysis is based on the Jacobian\n%\n\\begin{align*}\n\\begin{bmatrix}\n-1 -\\psi'_u & -\\psi'_v\\\\ \\psi'_u & \\psi'_v\n\\end{bmatrix}\n\\quad\\Rightarrow\\quad \\operatorname{tr} = \\psi'_v-\\psi'_u-1,\\quad \\det= -\\psi'_v\n\\end{align*}\n\nThe brusselator is given by\n%\n\\begin{equation}\\label{eq:brusselator}\n\\psi(u,v) = bu - u^2v\\qquad ( \\psi'_u = b-2uv,\\quad \\psi'_v=-u^2).\n\\end{equation}\n\nAn equilibrium point of (\\ref{eq:brusselator}) necessarily satisfies $u^*=a$ and $v^*=b/a$. We now have\n%\n\\begin{align*}\n\\operatorname{tr} = -b + 2uv -u^2-1 ,\\quad \\det = u^2\n\\end{align*}\n%\nand for the equilibrium point\n%\n\\begin{align*}\n\\operatorname{tr}^* = -1 - b +2b -a^2 = b-1-a^2,\\quad {\\det}^* = a^2\n\\end{align*}\n%\nWe conclude that a  Hopf bifurcation appears if $b>a^2+1$.\n\n%\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\subsubsection{The influence of diffusion}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%\nWe consider an expansion into eigenfunctions of the Laplace operator withe eigenvalues $l\\ge0$. The for the frequency $l$ we have the Jacopian\n%\n\\begin{align*}\n\\begin{bmatrix}\n-1 -\\psi'_u - k_ul& -\\psi'_v\\\\ \\psi'_u & \\psi'_v - k_vl\n\\end{bmatrix}\n\\quad\\Rightarrow\\quad \\operatorname{tr} = \\psi'_v-\\psi'_u-1- (k_u+ k_v)l,\\\\ \n\\det=  (1+k_ul)(k_vl-\\psi'_v) +k_vl\\psi'_u  = k_uk_v l^2 +(k_v(\\psi'_u+1)-k_u\\psi'_v)l - \\psi'_v\n\\end{align*}\nFor the brusselator we have at the eqilubrium\n%\n\\begin{align*}\n\\det= k_uk_v l^2 +(k_u a^2-k_v(b-1))l +a^2.\n\\end{align*}\n%\nThe discriminant is\n%\n\\begin{align*}\n\\Delta = (k_u a^2-k_v(b-1))^2 - 4 a^2 k_uk_v\n\\end{align*}\n%\nwhich is positive ($a=1$) for\n%\n\\begin{equation}\\label{eq:}\nb \\le b^* = 1 + \\frac{k_u}{k_v} + 2 \\frac{\\sqrt{k_u}}{\\sqrt{k_v}}\n\\end{equation}\n%\nThe critical frequency is\n%\n\\begin{align*}\nl^*  = \\frac{k_v(b^*-1)-k_u}{2k_uk_v} = 2 k_u^{-1/2}k_v{-3/2}\n\\end{align*}\n%\n\n\n\n\n\nThe data for our test problems are\n%\n\\begin{align*}\n&\\mbox{(cas 1)}\\qquad a = 1.0\\;,\\quad b=2.1, \\quad k_u = 0.0\\;, \\quad k_v = 0.0\\;,\\quad T=20.0\\\\\n&\\mbox{(cas 2)}\\qquad a = 1.0\\;,\\quad b=1.9, \\quad k_u = 0.0001\\;, \\quad k_v = 0.01\\;,\\quad T=20.0\\\\\n&u_0(x) = \\begin{cases}\n1 & \\mbox{if for all $i$ $x_i \\in [-0.4,0.0]$}\\\\\n0 & \\mbox{else}\n\\end{cases}\n\\qquad\nv_0(x) = \\begin{cases}\n1 & \\mbox{if for all $i$ $x_i \\in [-0.2,0.2]$}\\\\\n0 & \\mbox{else}\n\\end{cases}\n\\end{align*}\n%\n\n\n%==========================================\n\\printbibliography\n%==========================================\n\\end{document}\n%==========================================\n", "meta": {"hexsha": "5059885e127a1ab87f97e6e1cc0018f02bbcd613", "size": 10489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/simfem.tex", "max_stars_repo_name": "beckerrh/simfemsrc", "max_stars_repo_head_hexsha": "d857eb6f6f8627412d4f9d89a871834c756537db", "max_stars_repo_licenses": ["MIT"], "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/simfem.tex", "max_issues_repo_name": "beckerrh/simfemsrc", "max_issues_repo_head_hexsha": "d857eb6f6f8627412d4f9d89a871834c756537db", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-31T10:59:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-31T10:59:11.000Z", "max_forks_repo_path": "doc/simfem.tex", "max_forks_repo_name": "beckerrh/simfemsrc", "max_forks_repo_head_hexsha": "d857eb6f6f8627412d4f9d89a871834c756537db", "max_forks_repo_licenses": ["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.9410029499, "max_line_length": 189, "alphanum_fraction": 0.5408523215, "num_tokens": 3762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249076, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6740430756232367}}
{"text": "\\subsection{Analytic Functions}\r\n\\begin{definition}\r\n    An analytic function on a Riemann surface $R$ is an analytic map $R\\to\\mathbb C$.\r\n\\end{definition}\r\nWe can put analytic functions into a nice form by our study of this structure of Riemann surfaces.\r\n\\begin{theorem}[Inverse Function Theorem]\r\n    Let $f$ be an analytic function on a domain $S\\subset\\mathbb C$.\r\n    If $f^\\prime(z_0)\\neq 0$ for $z_0\\in D$, then there are open neighbourhoods $U$ of $z_0$ and $V$ of $f(z_0)$ such that $f$ restricts to a biholomorphism $U\\to V$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\n\\begin{proposition}\\label{local_p_k}\r\n    Let $f$ be a non-constant analytic function on a Riemann surface $R$ and $p\\in R$ be a zero of $f$.\r\n    There is a chart $(\\phi,U)$ about $p$ with $\\phi(p)=0$ such that $f\\circ\\phi^{-1}(z)=z^m$ for some integer $m>0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $(\\psi,V)$ be a chart with $\\psi(p)=0$ as adding a constant does not change anything.\r\n    $f$ is not globally constant, so it is not locally constant by the identity principle for Riemann surfaces.\r\n    \\footnote{Proved in example sheet.}\r\n    Therefore is an analytic $g$ in a neighbourhood $W\\subset\\psi(V)$ of $0$ such that $f\\circ\\psi^{-1}(z)=z^mg(z)$ with $g(0)\\neq 0$.\\\\\r\n    But then since $g$ is continuous, there is $\\delta>0$ such that $D(0,\\delta)\\subset W$ and $g(D(0,\\delta))\\subset D(g(0),|g(0)|)$ does not contain $0$.\r\n    So there is an analytic branch cut of $\\sqrt[m]{\\cdot}$ on $g(D(0,\\delta))$.\r\n    Define $h(z)=z\\cdot\\sqrt[m]{g(z)}$ on $D(0,\\delta)$, then $f\\circ\\psi^{-1}(z)=(h(z))^n$.\r\n    Differentiating $h$ gives $h^\\prime(0)=\\sqrt[m]{g(0)}\\neq 0$, so $h$ has an analytic inverse on $D(0,\\epsilon)$ for some $0<\\epsilon\\le\\delta$.\r\n    Then $\\phi=h\\circ\\psi$ and $U=\\phi^{-1}(D(0,\\epsilon))$ gives the required chart as\r\n    $$f\\circ\\phi^{-1}(z)=f\\circ\\psi^{-1}\\circ h^{-1}(z)=(h(h^{-1}(z)))^m=z^m$$\r\n    which is what we wanted.\r\n\\end{proof}", "meta": {"hexsha": "dac010a5de2f16b03172d0f4c018d47d293258e5", "size": 1971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/func.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": "4/func.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": "4/func.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.9655172414, "max_line_length": 167, "alphanum_fraction": 0.6463723998, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839876, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.6740430564948704}}
{"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\nA high energy electron and positron collision can create two muons.\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] {$e^-$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$\\mu^-$};\n\\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$\\mu^+$};\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, v_2$} -- (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_3, u_3$};\n\\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$p_4, v_4$};\n\\draw (1,0.5) node {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nIn a typical collider experiment the momentum vectors are\n$$\np_1=\\begin{pmatrix}E\\\\0\\\\0\\\\p\\end{pmatrix}\\qquad\np_2=\\begin{pmatrix}E\\\\0\\\\0\\\\-p\\end{pmatrix}\\qquad\np_3=\\begin{pmatrix}\nE\\\\\n\\rho\\sin\\theta\\cos\\phi\\\\\n\\rho\\sin\\theta\\sin\\phi\\\\\n\\rho\\cos\\theta\n\\end{pmatrix}\n\\qquad\np_4=\\begin{pmatrix}\nE\\\\\n-\\rho\\sin\\theta\\cos\\phi\\\\\n-\\rho\\sin\\theta\\sin\\phi\\\\\n-\\rho\\cos\\theta\n\\end{pmatrix}\n$$\n\n\\noindent\nwhere $E$ is beam energy, $p=\\sqrt{E^2-m^2}$, $\\rho=\\sqrt{E^2-M^2}$,\n$m$ is electron mass $0.51\\,\\text{MeV}$,\nand $M$ is muon mass $106\\,\\text{MeV}$.\nThe spinors are\n\\begin{gather*}\nu_{11}=\\begin{pmatrix}E+m\\\\0\\\\p\\\\0\\end{pmatrix}\\quad\nv_{21}=\\begin{pmatrix}-p\\\\0\\\\E+m\\\\0\\end{pmatrix}\\quad\nu_{31}=\\begin{pmatrix}E+M\\\\0\\\\p_3^z\\\\p_3^x+ip_3^y\\end{pmatrix}\\quad\nv_{41}=\\begin{pmatrix}p_4^z\\\\p_4^x+ip_4^y\\\\E+M\\\\0\\end{pmatrix}\n\\\\\nu_{12}=\\begin{pmatrix}0\\\\E+m\\\\0\\\\-p\\end{pmatrix}\\quad\nv_{22}=\\begin{pmatrix}0\\\\p\\\\0\\\\E+m\\end{pmatrix}\\quad\nu_{32}=\\begin{pmatrix}0\\\\E+M\\\\p_3^x-ip_3^y\\\\-p_3^z\\end{pmatrix}\\quad\nv_{42}=\\begin{pmatrix}p_4^x-ip_4^y\\\\-p_4^z\\\\0\\\\E+M\\end{pmatrix}\n\\end{gather*}\n\n\\noindent\nThe last digit in a spinor subscript is 1 for spin up and 2 for spin down.\nNote that the spinors are not individually normalized.\nInstead, a combined spinor normalization constant $N=(E+m)^2(E+M)^2$\nwill be used where needed.\n\n\\bigskip\n\\noindent\nThis is the probability density for muon production.\nSymbol $s=(p_1+p_2)^2=4E^2$,\nsymbol $s_j$ selects the spin of spinor $j$,\nand $e$ is electron charge.\n\\begin{equation*}\n|\\mathcal{M}(s_1,s_2,s_3,s_4)|^2\n=\\frac{e^4}{s^2}\\frac{1}{N}\\left|(\\bar{u}_3\\gamma_\\mu v_4)(\\bar{v}_2\\gamma^\\mu u_1)\\right|^2\n\\end{equation*}\n\n\\noindent\nThe expected probability density $\\langle|\\mathcal{M}|^2\\rangle$\nis computed by summing $|\\mathcal{M}|^2$ over all spin states\nand dividing by the number of inbound states.\nThere are four inbound states.\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=\\frac{1}{4}\\sum_{s_1=1}^2\\sum_{s_2=1}^2\\sum_{s_3=1}^2\\sum_{s_4=1}^2|\\mathcal{M}(s_1,s_2,s_3,s_4)|^2\n\\\\\n&=\\frac{e^4}{4s^2}\\sum_{s_1=1}^2\\sum_{s_2=1}^2\\sum_{s_3=1}^2\\sum_{s_4=1}^2\n\\frac{1}{N}\\left|(\\bar{u}_3\\gamma_\\mu v_4)(\\bar{v}_2\\gamma^\\mu u_1)\\right|^2\n\\end{align*}\n\n\\noindent\nAnother way to compute $\\langle|\\mathcal{M}|^2\\rangle$ is to use the Casimir trick.\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=\\frac{e^4}{4s^2}\n\\mathop{\\rm Tr}\\left((\\slashed{p}_3+M)\\gamma^\\mu(\\slashed{p}_4-M)\\gamma^\\nu\\right)\n\\mathop{\\rm Tr}\\left((\\slashed{p}_2-m)\\gamma_\\mu(\\slashed{p}_1+m)\\gamma_\\nu\\right)\n\\end{equation*}\n\n\\noindent\nHere is a third way to compute $\\langle|\\mathcal{M}|^2\\rangle$.\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=\\frac{e^4}{4s^2}\n\\left(\n32 (p_1\\cdot p_3) (p_2\\cdot p_4) +\n32 (p_1\\cdot p_4) (p_2\\cdot p_3) +\n32 m^2 (p_3\\cdot p_4) +\n32 M^2 (p_1\\cdot p_2) +\n64 m^2 M^2\n\\right)\n\\end{equation*}\n\n\\noindent\nFor the momentum vectors given above the result is\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=e^4\\left(1+\\cos^2\\theta+\\frac{m^2+M^2}{E^2}\\sin^2\\theta+\\frac{m^2M^2}{E^4}\\cos^2\\theta\\right)\n\\end{equation*}\n\n\\noindent\nThe Stanford Linear Collider\nhad a collision energy of $2E=91$~GeV.\nFor beam energies such as SLC where $E\\gg M$ the above equation can be approximated as\n$$\n\\langle|\\mathcal{M}|^2\\rangle=e^4(1+\\cos^2\\theta)\n$$\n\n\\noindent\nThe differential cross section is\n$$\n\\frac{d\\sigma}{d\\Omega}\n=\\frac{\\langle|\\mathcal{M}|^2\\rangle}{64\\pi^2s}\n=\\frac{e^4}{256\\pi^2E^2}(1+\\cos^2\\theta)\n$$\n\n\\noindent\nRecall that $e^2=4\\pi\\alpha$ hence\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}=\\frac{\\alpha^2}{16E^2}(1+\\cos^2\\theta)\n\\end{equation*}\n\n\\noindent\nThe total cross section calculation requires the following definite integral.\n$$\n\\int_\\Omega(1+\\cos^2\\theta)\\,d\\Omega\n=\\int_0^{2\\pi}\\int_0^\\pi(1+\\cos^2\\theta)\\sin\\theta\\,d\\theta\\,d\\phi\n=\\frac{8}{3}\\int_0^{2\\pi}d\\phi\n=\\frac{16\\pi}{3}\n$$\n\n\\noindent\nHence the total cross section is\n$$\n\\sigma\n=\\int_\\Omega d\\sigma\n=\\int_\\Omega\\frac{\\alpha^2}{16E^2}(1+\\cos^2\\theta)\\,d\\Omega\n=\\frac{\\alpha^2}{16E^2}\\frac{16\\pi}{3}\n=\\frac{\\pi\\alpha^2}{3E^2}\n$$\n\n\\noindent\nWe can integrate the differential cross section to obtain a cumulative distribution function.\n\n\\bigskip\n\\noindent\nLet\n\\begin{equation*}\nI(\\xi)=2\\pi\\int_0^\\xi\\frac{d\\sigma}{d\\Omega}\\,\\sin\\theta\\,d\\theta,\n\\qquad0\\le\\xi\\le\\pi\n\\end{equation*}\n\n\\noindent\nThe result is\n\\begin{equation*}\nI(\\xi)=2\\pi\\left(\\frac{\\alpha^2}{16E^2}\\right)\n\\left(-\\frac{1}{3}\\cos^3\\xi-\\cos\\xi+\\frac{4}{3}\\right)\n\\end{equation*}\n\n\\noindent\nThe cumulative distribution function is\n\\begin{equation*}\nF(\\theta)=\\frac{I(\\theta)}{I(\\pi)},\\qquad0\\le\\theta\\le\\pi\n\\end{equation*}\n\n\\noindent\nHence\n\\begin{equation*}\nP(\\theta_1\\le\\theta\\le\\theta_2)=F(\\theta_2)-F(\\theta_1)\n\\end{equation*}\n\n\\noindent\nThe normalized probability density is\n\\begin{equation*}\nf(\\theta)=\\frac{dF(\\theta)}{d\\theta}=\\frac{3}{8}(1+\\cos^2\\theta)\\sin\\theta,\n\\qquad0\\le\\theta\\le\\pi\n\\end{equation*}\n\n\\noindent\nRun ``muon-production-5.txt'' to draw the probability density function.\n\n\\begin{center}\n\\includegraphics[scale=0.5]{muon-production.png}\n\\end{center}\n\n\\noindent\nRun ``muon-production-1.txt'' to verify that\n$$\n\\frac{1}{N}\\sum_{s_1=1}^2\\sum_{s_2=1}^2\\sum_{s_3=1}^2\\sum_{s_4=1}^2\n\\left|(\\bar{u}_3\\gamma_\\mu v_4)(\\bar{v}_2\\gamma^\\mu u_1)\\right|^2\n=\n\\mathop{\\rm Tr}\\left((\\slashed{p}_3+M)\\gamma^\\mu(\\slashed{p}_4-M)\\gamma^\\nu\\right)\n\\mathop{\\rm Tr}\\left((\\slashed{p}_2-m)\\gamma_\\mu(\\slashed{p}_1+m)\\gamma_\\nu\\right)\n$$\n\n\\bigskip\n\\noindent\nRun ``muon-production-2.txt'' to verify that\n\\begin{multline*}\n\\frac{1}{64E^4}\n\\mathop{\\rm Tr}\\left((\\slashed{p}_3+M)\\gamma^\\mu(\\slashed{p}_4-M)\\gamma^\\nu\\right)\n\\mathop{\\rm Tr}\\left((\\slashed{p}_2-m)\\gamma_\\mu(\\slashed{p}_1+m)\\gamma_\\nu\\right)\n\\\\\n=1+\\cos^2\\theta+\\frac{m^2+M^2}{E^2}\\sin^2\\theta+\\frac{m^2M^2}{E^4}\\cos^2\\theta\n\\end{multline*}\n\n\\noindent\nand to verify that\n\\begin{multline*}\n\\mathop{\\rm Tr}\\left((\\slashed{p}_3+M)\\gamma^\\mu(\\slashed{p}_4-M)\\gamma^\\nu\\right)\n\\mathop{\\rm Tr}\\left((\\slashed{p}_2-m)\\gamma_\\mu(\\slashed{p}_1+m)\\gamma_\\nu\\right)\n\\\\=\n32 (p_1\\cdot p_3) (p_2\\cdot p_4) +\n32 (p_1\\cdot p_4) (p_2\\cdot p_3) +\n32 m^2 (p_3\\cdot p_4) +\n32 M^2 (p_1\\cdot p_2) +\n64 m^2 M^2\n\\end{multline*}\n\n\\subsection*{Data from SLAC PEP experiment}\nSee www.hepdata.net/record/ins216031, Table 1, 29.0 GeV.\n\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\n$x$ & $y$\\\\\n\\hline\n$-0.925$ & 67.08\\\\\n$-0.85\\phantom{0}$ & 58.67\\\\\n$-0.75\\phantom{0}$ & 54.66\\\\\n$-0.65\\phantom{0}$ & 51.72\\\\\n$-0.55\\phantom{0}$ & 43.70\\\\\n$-0.45\\phantom{0}$ & 41.12\\\\\n$-0.35\\phantom{0}$ & 39.71\\\\\n$-0.25\\phantom{0}$ & 35.34\\\\\n$-0.15\\phantom{0}$ & 33.35\\\\\n$-0.05\\phantom{0}$ & 34.69\\\\\n$\\phantom{+}0.05\\phantom{0}$ & 34.05\\\\\n$\\phantom{+}0.15\\phantom{0}$ & 34.48\\\\\n$\\phantom{+}0.25\\phantom{0}$ & 34.66\\\\\n$\\phantom{+}0.35\\phantom{0}$ & 35.23\\\\\n$\\phantom{+}0.45\\phantom{0}$ & 35.60\\\\\n$\\phantom{+}0.55\\phantom{0}$ & 40.13\\\\\n$\\phantom{+}0.65\\phantom{0}$ & 42.56\\\\\n$\\phantom{+}0.75\\phantom{0}$ & 46.37\\\\\n$\\phantom{+}0.85\\phantom{0}$ & 49.28\\\\\n$\\phantom{+}0.925$ & 55.70\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nData $x$ and $y$ have the following relationship with cross section parameters.\n\\begin{equation*}\nx=\\cos\\theta\n\\qquad\ny=(2E)^2\\frac{d\\sigma}{d\\cos\\theta}\n\\end{equation*}\n\n\\noindent\nThe differential cross section for muon production is\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}=\\frac{\\alpha^2}{16E^2}(1+\\cos^2\\theta)\n\\end{equation*}\n\n\\noindent\nLet us compute predicted values $\\hat{y}$ from the cross section formula.\nStart by finding the relationship between $d\\Omega$ and $d\\cos\\theta$.\nSince $1+\\cos^2\\theta$ has no dependence on $\\phi$ we have\n\\begin{equation*}\n\\int_\\Omega(1+\\cos^2\\theta)\\,d\\Omega\n=\\int_0^{2\\pi}\\int_0^{\\pi}(1+\\cos^2\\theta)\\sin\\theta\\,d\\theta\\,d\\phi\n=2\\pi\\int_0^\\pi(1+\\cos^2\\theta)\\sin\\theta\\,d\\theta\n\\end{equation*}\n\n\\noindent\nHence\n\\begin{equation*}\nd\\Omega=2\\pi\\sin\\theta\\,d\\theta=-2\\pi\\,d\\cos\\theta\n\\end{equation*}\n\n\\noindent\nWe want positive cross sections so drop the minus sign and set\n\\begin{equation*}\n\\frac{d\\sigma}{d\\cos\\theta}=2\\pi\\frac{d\\sigma}{d\\Omega}\n\\end{equation*}\n\n\\noindent\nWe can now write\n\\begin{align*}\ny&=(2E)^2\\frac{d\\sigma}{d\\cos\\theta}\\\\\n&=(2E)^2(2\\pi)\\frac{d\\sigma}{d\\Omega}\\\\\n&=(2E)^2(2\\pi)\\frac{\\alpha^2}{16E^2}(1+\\cos^2\\theta)\\\\\n&=\\frac{\\pi\\alpha^2}{2}(1+\\cos^2\\theta)\n\\end{align*}\n\n\\noindent\nMultiply by $(\\hbar c)^2$ to convert to SI\nand multiply by $10^{37}$ to convert square meters to nanobarns.\n\\begin{equation*}\ny=\\frac{\\pi\\alpha^2}{2}(1+\\cos^2\\theta)\\times(\\hbar c)^2\\times10^{37}\n\\end{equation*}\n\n\\noindent\nReplace $\\cos\\theta$ with explanatory variable $x$ to obtain $\\hat{y}$.\n\\begin{equation*}\n\\hat{y}=\\frac{\\pi\\alpha^2}{2}(1+x^2)\\times(\\hbar c)^2\\times10^{37}\n\\end{equation*}\n\n\\noindent\nHere are the predicted values $\\hat{y}$ based on the above formula.\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$x$ & $y$ & $\\hat{y}$ \\\\\n\\hline\n$-0.925$ & 67.08 & 60.44\\\\\n$-0.85\\phantom{0}$ & 58.67 & 56.10\\\\\n$-0.75\\phantom{0}$ & 54.66 & 50.89\\\\\n$-0.65\\phantom{0}$ & 51.72 & 46.33\\\\\n$-0.55\\phantom{0}$ & 43.70 & 42.42\\\\\n$-0.45\\phantom{0}$ & 41.12 & 39.17\\\\\n$-0.35\\phantom{0}$ & 39.71 & 36.56\\\\\n$-0.25\\phantom{0}$ & 35.34 & 34.61\\\\\n$-0.15\\phantom{0}$ & 33.35 & 33.30\\\\\n$-0.05\\phantom{0}$ & 34.69 & 32.65\\\\\n$\\phantom{+}0.05\\phantom{0}$ & 34.05 & 32.65\\\\\n$\\phantom{+}0.15\\phantom{0}$ & 34.48 & 33.30\\\\\n$\\phantom{+}0.25\\phantom{0}$ & 34.66 & 34.61\\\\\n$\\phantom{+}0.35\\phantom{0}$ & 35.23 & 36.56\\\\\n$\\phantom{+}0.45\\phantom{0}$ & 35.60 & 39.17\\\\\n$\\phantom{+}0.55\\phantom{0}$ & 40.13 & 42.42\\\\\n$\\phantom{+}0.65\\phantom{0}$ & 42.56 & 46.33\\\\\n$\\phantom{+}0.75\\phantom{0}$ & 46.37 & 50.89\\\\\n$\\phantom{+}0.85\\phantom{0}$ & 49.28 & 56.10\\\\\n$\\phantom{+}0.925$ & 55.70 & 60.44\\\\\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.87\n\\end{equation*}\n\n\\noindent\nThe result indicates that the model $d\\sigma$ explains 87\\% of the variance in the data.\n\n\\bigskip\n\\noindent\nRun ``muon-production-3.txt'' to compute the above results.\n\n\\subsection*{Electroweak model}\nThe following differential cross section formula from electroweak\ntheory results in a better fit to the\ndata.\\footnote{F. Mandl and G. Shaw, {\\it Quantum Field Theory Revised Edition,} 316.}\n\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}=F(s)(1+\\cos^2\\theta)+G(s)\\cos\\theta\n\\end{equation*}\n\n\\noindent\nwhere\n\\begin{align*}\nF(s)&=\\frac{\\alpha^2}{4s}\n\\left(\n1+\\frac{g_V^2}{\\sqrt{2}\\pi}\\left(\\frac{m_Z^2}{s-m_Z^2}\\right)\\left(\\frac{sG}{\\alpha}\\right)\n+\\frac{(g_A^2+g_V^2)^2}{8\\pi^2}\\left(\\frac{m_Z^2}{s-m_Z^2}\\right)^2\\left(\\frac{sG}{\\alpha}\\right)^2\n\\right)\n\\\\\nG(s)&=\\frac{\\alpha^2}{4s}\n\\left(\n\\frac{\\sqrt{2}g_A^2}{\\pi}\\left(\\frac{m_Z^2}{s-m_Z^2}\\right)\\left(\\frac{sG}{\\alpha}\\right)\n+\\frac{g_A^2g_V^2}{\\pi^2}\\left(\\frac{m_Z^2}{s-m_Z^2}\\right)^2\\left(\\frac{sG}{\\alpha}\\right)^2\n\\right)\n\\end{align*}\n\n\\noindent\nand\n\\begin{align*}\ng_A&=-0.5\n\\\\\ng_V&=-0.0348\n\\\\\nm_Z&=91.17\\,\\text{GeV}\n\\\\\nG&=1.166\\times10^{-5}\\,\\text{GeV}^{-2}\n\\end{align*}\n\n\\noindent\nThe corresponding formula for $\\hat{y}$ is\n\\begin{equation*}\n\\hat{y}=2\\pi\\left[F(s)(1+x^2)+G(s)x\\right]\\times(\\hbar c)^2\\times10^{37}\n\\end{equation*}\n\n\\noindent\nwhere $\\sqrt{s}=29\\,\\text{GeV}$ is the center of mass collision energy.\nHere are the predicted values $\\hat{y}$ based on the above formula.\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$x$ & $y$ & $\\hat{y}$ \\\\\n\\hline\n$-0.925$ & 67.08 & 65.59\\\\\n$-0.85\\phantom{0}$ & 58.67 & 60.84\\\\\n$-0.75\\phantom{0}$ & 54.66 & 55.07\\\\\n$-0.65\\phantom{0}$ & 51.72 & 49.96\\\\\n$-0.55\\phantom{0}$ & 43.70 & 45.49\\\\\n$-0.45\\phantom{0}$ & 41.12 & 41.69\\\\\n$-0.35\\phantom{0}$ & 39.71 & 38.53\\\\\n$-0.25\\phantom{0}$ & 35.34 & 36.02\\\\\n$-0.15\\phantom{0}$ & 33.35 & 34.17\\\\\n$-0.05\\phantom{0}$ & 34.69 & 32.97\\\\\n$\\phantom{+}0.05\\phantom{0}$ & 34.05 & 32.42\\\\\n$\\phantom{+}0.15\\phantom{0}$ & 34.48 & 32.53\\\\\n$\\phantom{+}0.25\\phantom{0}$ & 34.66 & 33.28\\\\\n$\\phantom{+}0.35\\phantom{0}$ & 35.23 & 34.69\\\\\n$\\phantom{+}0.45\\phantom{0}$ & 35.60 & 36.75\\\\\n$\\phantom{+}0.55\\phantom{0}$ & 40.13 & 39.47\\\\\n$\\phantom{+}0.65\\phantom{0}$ & 42.56 & 42.83\\\\\n$\\phantom{+}0.75\\phantom{0}$ & 46.37 & 46.85\\\\\n$\\phantom{+}0.85\\phantom{0}$ & 49.28 & 51.52\\\\\n$\\phantom{+}0.925$ & 55.70 & 55.45\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nThe coefficient of determination $R^2$ is\n\\begin{equation*}\nR^2=1-\\frac{\\sum(y-\\hat{y})^2}{\\sum(y-\\bar{y})^2}=0.98\n\\end{equation*}\n\n\\noindent\nThe result indicates that electroweak theory explains 98\\% of the variance in the data.\n\n\\bigskip\n\\noindent\nRun ``muon-production-4.txt'' to verify.\n\n\\subsection*{Notes}\nHere are a few notes about how the scripts work.\n\n\\bigskip\n\\noindent\nIn component notation the traces become sums over the repeated index $\\alpha$.\n\\begin{align*}\n\\mathop{\\rm Tr}\\left((\\slashed{p}_3+M)\\gamma^\\mu(\\slashed{p}_4-M)\\gamma^\\nu\\right)\n&=\n(\\slashed{p}_3+M)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_4-M)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\alpha\n\\\\\n\\mathop{\\rm Tr}\\left((\\slashed{p}_2-m)\\gamma_\\mu(\\slashed{p}_1+m)\\gamma_\\nu\\right)\n&=\n(\\slashed{p}_2-m)^\\alpha{}_\\beta\n\\gamma_\\mu{}^\\beta{}_\\rho\n(\\slashed{p}_1+m)^\\rho{}_\\sigma\n\\gamma_\\nu{}^\\sigma{}_\\alpha\n\\end{align*}\n\n\\noindent\nTo convert the above formulas to Eigenmath code,\nthe $\\gamma$ tensors need to be transposed\nso that repeated indices are adjacent to each other.\nAlso, multiply $\\gamma^\\mu$ by the metric tensor to lower the index.\n\\begin{align*}\n\\gamma^{\\beta\\mu}{}_\\rho\\quad&\\rightarrow\\quad\n\\text{\\tt gammaT = transpose(gamma)}\\\\\n\\gamma^\\beta{}_{\\mu\\rho}\\quad&\\rightarrow\\quad\n\\text{\\tt gammaL = transpose(dot(gmunu,gamma))}\n\\end{align*}\n\n\\noindent\nDefine the following $4\\times4$ matrices.\n\\begin{align*}\n(\\slashed{p}_1+m)\\quad&\\rightarrow\\quad\\text{\\tt X1 = pslash1 + m I}\\\\\n(\\slashed{p}_2-m)\\quad&\\rightarrow\\quad\\text{\\tt X2 = pslash2 - m I}\\\\\n(\\slashed{p}_3+M)\\quad&\\rightarrow\\quad\\text{\\tt X3 = pslash3 + M I}\\\\\n(\\slashed{p}_4-M)\\quad&\\rightarrow\\quad\\text{\\tt X4 = pslash4 - M I}\n\\end{align*}\n\n\\noindent\nThen\n\\begin{align*}\n(\\slashed{p}_3+M)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{p}_4-M)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\alpha\n\\quad&\\rightarrow\\quad\n\\text{\\tt T1 = contract(dot(X3,gammaT,X4,gammaT),1,4)}\n\\\\\n(\\slashed{p}_2-m)^\\alpha{}_\\beta\n\\gamma_\\mu{}^\\beta{}_\\rho\n(\\slashed{p}_1+m)^\\rho{}_\\sigma\n\\gamma_\\nu{}^\\sigma{}_\\alpha\n\\quad&\\rightarrow\\quad\n\\text{\\tt T2 = contract(dot(X2,gammaL,X1,gammaL),1,4)}\n\\end{align*}\n\n\\noindent\nNext, multiply matrices and sum over repeated indices.\nThe dot function sums over $\\nu$ then the contract function\nsums over $\\mu$. The transpose makes the $\\nu$ indices adjacent\nas required by the dot function.\n$$\n\\mathop{\\rm Tr}(\\cdots\\gamma^\\mu\\cdots\\gamma^\\nu)\\mathop{\\rm Tr}(\\cdots\\gamma_\\mu\\cdots\\gamma_\\nu)\n\\quad\\rightarrow\\quad\n\\text{\\tt contract(dot(T1,transpose(T2)))}\n$$\n\n\\end{document}\n", "meta": {"hexsha": "c79c4238603a938b0ed0a0859a502c933d61dc5e", "size": 15908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "muon-production.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": "muon-production.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": "muon-production.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": 29.0291970803, "max_line_length": 101, "alphanum_fraction": 0.6585994468, "num_tokens": 7020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6739830278580853}}
{"text": "\\section{Simple examples}\\label{examples}\n%=====================================\n\nWithout loss of generality, let us start with the B-rep of a unit cube (see Figure~\\ref{}a) whith topology given by two arrays of arrays \\texttt{EV} and \\texttt{FV} providing indices of vertices \\texttt{V} on boundary of edges \\texttt{E} or faces \\texttt{F}.\n{\\small\\begin{verbatim}\nEV = [[1,2],[3,4],[5,6],[7,8],[1,3],[2,4],[5,7],[6,8],[1,5],[2,6],[3,7],[4,8]]\nFV = [[1,2,3,4],[5,6,7,8],[1,2,5,6],[3,4,7,8],[1,3,5,7],[2,4,6,8]]\n\\end{verbatim}}\nThe $[\\partial_1]$ matrix is ready to compute from \\texttt{EV}:\n{\\small\\begin{lstlisting}\nn = length(EV);\nIs,Js,Vs = map(cat,[EV, [[i,i] for i=1:n], [[1,1] for i=1:n]]);\n$\\partial_1$ = sparse(Is,Js,Vs);\n\\end{lstlisting}}\n{\\small\\begin{lstlisting}\nMatrix(convert(SparseMatrixCSC{Int8,Int64}, $\\partial_1$))\n8x12 Array{Int8,2}:\n 1  0  0  0  1  0  0  0  1  0  0  0\n 1  0  0  0  0  1  0  0  0  1  0  0\n 0  1  0  0  1  0  0  0  0  0  1  0\n 0  1  0  0  0  1  0  0  0  0  0  1\n 0  0  1  0  0  0  1  0  1  0  0  0\n 0  0  1  0  0  0  0  1  0  1  0  0\n 0  0  0  1  0  0  1  0  0  0  1  0\n 0  0  0  1  0  0  0  1  0  0  0  1\n\\end{lstlisting}}\n\nThe $\\partial_2$ matrix is computed by filtering the elements from the product $[\\partial_1^\\top] * \\texttt{fv'}$, where the sparse matrix \\texttt{fv} is generated from \\texttt{FV} array.\n\n{\\small\\begin{lstlisting}\nm = length(FV);\nIs,Js,Vs = map(cat,[[[i for k=1:length(f)] for (i,f) in enumerate(FV)], \n    [FV[i] for i=1:m], [ones(Int8, length(FV[i])) for i=1:m]]);\nfv = sparse(Is,Js,Vs);\nMatrix(convert(SparseMatrixCSC{Int8,Int64}, fv))\n6x8 Array{Int8,2}:\n 1  1  1  1  0  0  0  0\n 0  0  0  0  1  1  1  1\n 1  1  0  0  1  1  0  0\n 0  0  1  1  0  0  1  1\n 1  0  1  0  1  0  1  0\n 0  1  0  1  0  1  0  1\n\\end{lstlisting}}\n\n{\\small\\begin{lstlisting}\ntriples = map(tuple,SparseArrays.findnz($\\partial_1$' * fv')...);\nmat3xm = hcat([ [i,j,1] for (i,j,v) in triples if v==2]...);\nIs,Js,Vs = [mat3xm[1,:], mat3xm[2,:], convert(Array{Int8,1},mat3xm[3,:])];\n$\\partial_2$ = sparse(Is,Js,Vs)\nMatrix($\\partial_2$)\n12x6 Array{Int64,2}:\n 1  0  1  0  0  0\n 1  0  0  1  0  0\n 0  1  1  0  0  0\n 0  1  0  1  0  0\n 1  0  0  0  1  0\n 1  0  0  0  0  1\n 0  1  0  0  1  0\n 0  1  0  0  0  1\n 0  0  1  0  1  0\n 0  0  1  0  0  1\n 0  0  0  1  1  0\n 0  0  0  1  0  1\n\\end{lstlisting}}\n\n\nVV = [[k] for k=1:size(V,2)]\nmodel = (V, [VV,EV,FV])::Lar.LARmodel\n\nmeshes = GL.numbering(1.5)(model, GL.COLORS[1], 0.1)\n%#push!(meshes, GL.GLFrame)\nGL.VIEW(meshes);\n", "meta": {"hexsha": "a730a8f9a9036587716abd86240c2a170aad7531", "size": 2486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/examples.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/examples.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/examples.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": 34.0547945205, "max_line_length": 258, "alphanum_fraction": 0.5583266291, "num_tokens": 1361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.673962303645647}}
{"text": "\\subsection{Topological Data Analysis}\n\\label{sec:si_tda}\nSince the exact manifold (or distribution) of the input space is not\nknown in general and the SOM algorithms only approximate it, we\nsimplify these manifolds by retaining their original topological\nstructure. Here we approach the manifolds of input and neural spaces\nusing the Alpha complex. Before diving into more details regarding\nTDA, we provide here a few definitions and some notation. A\n$k$-simplex $\\sigma$ is the convex hull of $k+1$ affinely independent\npoints (for instance a $0$-simplex is a point, a $1$-simplex is an\nedge, a $2$-simplex is a triangle, etc). A simplicial complex with\nvertex set $\\mathcal{V}$ is a set $\\mathcal{S}$ of finite subsets of\n$\\mathcal{V}$ such that the elements of $\\mathcal{V}$ belong to\n$\\mathcal{S}$ and for any $\\sigma \\in \\mathcal{S}$ any subset $\\sigma$\nbelongs to $\\mathcal{S}$. Said differently, a simplicial complex is a\nspace that has been constructed out of intervals, triangles, and other\nhigher dimensional simplices.\n\nIn our analysis we let $\\mathcal{S}(\\mathcal{M}, \\alpha)$ be a Alpha\nsimplicial complex with $\\mathcal{M}$ being a point cloud, either the\ninput space or the neural one, and $\\alpha$ is the ``persistence''\nparameter.  More specifically, $\\alpha$ is a threshold (or radius as\nwe will see later) that determines if the set $X$ spans a $k$-simplex\nif and only if $d(x_i, x_j) \\leq \\alpha$ for all $0 \\leq i, j \\leq\nk$. From a practical point of view, we first define a family of\nthresholds $\\alpha$ (or radius) and for each $\\alpha$, we center a\nball of radius $\\alpha$ on each data point and look for possible\nintersections with other balls. This process is called filtration of\nsimplicial complexes. We start from a small $\\alpha$ where there are\nno intersecting balls (disjoint set of balls) and steadily we increase\nthe size of $\\alpha$ up to a point where a single connected blob\nemerges. As $\\alpha$ varies from a low to a large value, holes open\nand close as different balls start intersecting. Every time an\nintersection emerges we assign a {\\em birth} point $b_i$ and as the\n$\\alpha$ increases and some new intersections of larger simplicies\nemerge some of the old simplicies die (since they merge with other\nsmaller simplicies to form larger ones). Then we assign a {\\em death}\npoint $d_i$. A pair of a birth and death points $(b_i, d_i)$ is\nplotted on a Cartesian two-dimensional plane and indicates when a\nsimplicial complex was created and when it died. This two-dimensional\ndiagram is called persistent diagram and the pairs (birth, death) that\nlast longer reflect significant topological properties.  The longevity\nof birth-death pairs is more clear in the persistent barcodes where\nthe lifespan of such a pair is depicted as a straight line.\n\nIn other words, for each value of $\\alpha$ we obtain new simplicial\ncomplexes and thus new topological properties such as homology are\nrevealed. Homology encodes the number of points, holes, or voids in a\nspace.  For more thorough reading we refer the reader to\n\\citep{Chazal:2017,Ghrist:2008,Zomorodian:2005}. In this work, we used\nthe Gudhi library~\\citep{Maria:2014} to compute the Alpha simplicial\ncomplexes, the filtrations and the persistent diagrams and\nbarcodes. Therefore, we compute the persistent diagram and persistent\nbarcode of the input space and of the maps and we calculate the\nBottleneck distance between the input and SOM and RSOM maps\ndiagrams. The bottleneck distance provides a tool to compare two\npersistent diagrams in a quantitative way.  The Bottleneck distance\nbetween two persistent diagrams $\\text{dgm}_1$ and $\\text{dgm}_2$ as\nit is described in~\\cite{Chazal:2017}\n%%\n\\begin{align}S\n    \\label{eq:bottle}\n    d_b(\\text{dgm}_1, \\text{dgm}_2) &= \\inf_{\\text{matching }m}\\{ \\max_{(p, q) \\in m} \\{||p - q||_{\\infty} \\} \\},\n\\end{align}\n%%\nwhere $p \\in \\text{dgm}_1 \\backslash \\Delta$, $q \\in \\text{dgm}_2\n\\backslash \\Delta$, $\\Delta$ is the diagonal of the persistent diagram\n(the diagonal $\\Delta$ represents all the points that they die the\nvery moment they get born, $b = d$). A matching between two diagrams\n$\\text{dgm}_1$ and $\\text{dgm}_2$ is a subset $m \\subset \\text{dgm}_1\n\\times \\text{dgm}_2$ such that every point in $\\text{dgm}_1 \\backslash\n\\Delta$ and $\\text{dgm}_2 \\backslash \\Delta$ appears exactly once in $m$.\n\n\n\\subsection{Eigenvalues distribution}\n\\label{sec:dist}\n\nOne way to investigate if there is any significant difference between the regular and random SOMs is to compare their neural responses to the same random stimuli. Therefore, we measure the neural activity and build a covariance matrix out of it. Then, we compute the eigenvalues of the covariance matrix (or Gram matrix) and we estimate a probability distribution. Thus, we can compare the eigenvalues distributions of the two maps and compare them to each other. If the distributions are close enough in the sense of Wasserstein distance then the two SOMs are similar in terms of neural activation.  A Gram matrix is an $n \\times n$ matrix given by where $n$ is the number of neurons of the map and ${\\bf Y} \\in \\mathbb{R}^{n \\times m}$ is a matrix for which each column is the activation of all $n$ neurons to a random stimulus.\n\nFrom a computational point of view we construct the matrix ${\\bf Y}$ by applying a set of stimuli to the self-organized map and computing the activity of each neuron within the map. This implies that ${\\bf Y} \\in \\mathbb{R}^{m \\times n}$, where $m=1024$ (the number of neurons) and $n={2, 3}$ (two- or three-dimensional input samples). Then we compute the covariance or Gram matrix as ${\\bf M} = {\\bf Y}{\\bf Y}^T \\in \\mathbb{R}^{n \\times n}$, where $n$ is the number of neurons. Then we compute the eigenvalues and obtain their distribution by sampling the activity of neurons of each experiment for $200$ different initial conditions using $50$ input sample each time. At the end of sampling we get an \\emph{ensemble} of $200$ Gram matrices and finally we estimate the probability density of the eigenvalues on each \\emph{ensemble} by applying a Kernel Density Estimation method~\\citep{Parzen:1962} (KDE) with a Gaussian kernel and bandwidth $h=0.4$. This allows us to quantify any differences on the distributions of the regular and randomized SOMs by calculating the Earth-Mover or Wasserstein-1 distance over the two distributions (regular ($P$) and random SOM ($Q$)). The Wasserstein distance is computed as $W(P, Q) = \\inf_{\\gamma \\in \\Pi(P, Q)}\\{\\mathbb{E}_{(x, y) \\sim \\gamma}\\Big[||x - y||\\Big]\\}$, where $\\Pi(P, Q)$ denotes the set of all joint distributions $\\gamma (x, y)$, whose marginals are $P$ and $Q$, respectively. Intuitively, $\\gamma (x,y)$ indicates  how  much ``mass'' must be transported from $x$ to $y$ to transform the distribution $P$ into the distribution $Q$. \n\nThe distributions of the eigenvalues of the RSOM and the regular SOM are shown on figure~\\ref{fig:eigenvalues}. We can conclude that the two distributions are alike and do not suggest any significant difference between the two maps in terms of neural activity. This implies that the RSOM and the regular SOM have similar statistics of their neural activities. This means that the loss of information and the \\emph{stretch} to the input data from both RSOM and regular SOM are pretty close and the underlying  topology of the two maps do not really affect the neural activity. This is also confirmed\nby measuring the Wasserstein distance between the two distributions. The blue curve shows the regular SOM or distribution $P$ and the black curve the RSOM or distribution $Q$. The Wasserstein distance between the two distributions $P$ and $Q$ indicates that the two distributions are nearly identical on all datasets. The Wasserstein distances in Table~\\ref{table:distances}\nconfirm that the eigenvalues distributions of SOM and RSOM are almost identical indicating that both maps retain the\nsame amount of information after learning the representations of input spaces.\n\n\\begin{table}[!ht]\n  \\begin{center}\n    \\begin{tabular}{ll}\n        \\textbf{Experiment} & \\textbf{Wasserstein Distance} \\\\\n        \\hline\n        $2$D ring dataset               & $0.0000323$\\\\\n        $2$D uniform dataset with holes & $0.0000207$  \\\\\n        $3$D uniform dataset            & $0.0001583$ \\\\\n        MNIST dataset                   & $0.0015$ \\\\\n    \\end{tabular}\n      \\caption{\\textbf{Wasserstein distances of eigenvalues distributions.} We report here the Wasserstein \n      distances between eigenvalues distributions of SOM and RSOM for each of the four major experiments we\n      ran. The results indicate that the distributions are close pointing out that the SOM and RSOM capture\n      a similar level of information during training. For more information regarding how we computed the \n      eigenvalues distributions and the Wasserstein distance please see Section~\\ref{sec:dist}.}\n      \\label{table:distances}\n  \\end{center}\n\\end{table}\n\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{eig-distributions-new.pdf}\n  %\n  \\caption{Eigenvalues distribution for \\textbf{A} 2D Ring dataset \\textbf{B} 2D uniform dataset with holes \\textbf{C} 3D uniform dataset and \\textbf{D} MNIST Dataset\n  }%\n  \\label{fig:eigenvalues}\n \\end{figure}\n", "meta": {"hexsha": "7f7a901dacbc4b31e02e6a6c55653b56d80d89a4", "size": 9254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article-overleaf/05-appendix-F-revision.tex", "max_stars_repo_name": "rougier/VSOM", "max_stars_repo_head_hexsha": "78e6eb924b5f89a0e6f42eb6bbe7971473a9abaa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-20T06:27:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T22:20:28.000Z", "max_issues_repo_path": "article-overleaf/05-appendix-F-revision.tex", "max_issues_repo_name": "rougier/VSOM", "max_issues_repo_head_hexsha": "78e6eb924b5f89a0e6f42eb6bbe7971473a9abaa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "article-overleaf/05-appendix-F-revision.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": 81.8938053097, "max_line_length": 1588, "alphanum_fraction": 0.7541603631, "num_tokens": 2400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6739467837395516}}
{"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 26, 2014}\n\\rhead{Jon Allen}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\section*{Chapter 5}\n\\subsection*{5.}\nExpand $(2x-y)^7$ using the binomial theorem.\n\\begin{align*}\n  (2x-y)^7&=\\sum\\limits_{k=0}^7{\\binom{7}{k}(2x)^{7-k}(-y)^k}\\\\\n  &=\\binom{7}{0}2^7x^7y^0-\\binom{7}{1}2^6x^6y^1+\\binom{7}{2}2^5x^5y^2-\\binom{7}{3}2^4x^4y^3\\\\\n  &\\qquad+\\binom{7}{4}2^3x^3y^4-\\binom{7}{5}2^2x^2y^5+\\binom{7}{6}2^1x^1y^6-\\binom{7}{7}2^0x^0y^7\\\\\n  &=128x^7-7\\cdot64x^6y+21\\cdot32x^5y^2-35\\cdot16x^4y^3\\\\\n  &\\qquad+35\\cdot8x^3y^4-21\\cdot4x^2y^5+7\\cdot2xy^6-y^7\\\\\n  &=128x^7-448x^6y+672x^5y^2-560x^4y^3+280x^3y^4-84x^2y^5+14xy^6-y^7\n\\end{align*}\n\\subsection*{7.}\nUse the binomial theorem to prove that\n\\begin{align*}\n  3^n&=\\sum\\limits_{k=0}^n{\\binom{n}{k}2^k}.\n\\end{align*}\n\\begin{align*}\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}2^k}&=\\sum\\limits_{k=0}^n{\\binom{n}{k}1^{n-k}2^k}\\\\\n  &=(1+2)^n\\\\\n  &=3^n\n\\end{align*}\nGeneralize to find the sum\n\\begin{align*}\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}r^k}&=\\sum\\limits_{k=0}^n{\\binom{n}{k}1^{n-k}r^k}=(1+r)^n\n\\end{align*}\n\\subsection*{8.}\nUse the binomialtheorem to prove that\n\\begin{align*}\n  2^n&=\\sum\\limits_{k=0}^n{(-1)^k\\binom{n}{k}3^{n-k}}.\n\\end{align*}\n\\begin{align*}\n  \\sum\\limits_{k=0}^n{(-1)^k\\binom{n}{k}3^{n-k}}&=(3-1)^n=2^n\n\\end{align*}\n\\subsection*{10.}\nUse \\emph{combinatorial} reasoning to prove the identity (5.2).\n\\begin{align*}\n  k\\binom{n}{k}&=n\\binom{n-1}{k-1}\n\\end{align*}\nImagine an ordered pair $(A,a)$. The first item in the pair is a set $A$ with $k$ elements chosen from a set $S$ with $n$ elements. So $\\lvert A\\rvert=k, \\lvert S\\rvert=n,$ and $A\\subset S$. The second item in the pair is one of the elements from the first item ($a\\in A$). Then we have $\\binom{n}{k}$ ways to choose $A$ and $k$ ways to choose $a$. This gives us $k\\binom{n}{k}$ possible ordered pairs.\n\nNow lets choose $a$ first. Because $a\\in S$ and $\\lvert S\\rvert=n$ we have $n$ possibilities $a$. Since we know that $a\\in A$, we have already chosen one element of $A$. We need now only choose the $k-1$ elements of $A\\setminus a$ from the $n-1$ sized set $S\\setminus a$. We can do this in $\\binom{n-1}{k-1}$ ways. This gives us $n\\binom{n-1}{k-1}$ possible ordered pairs. And we have our identity.$\\Box$\n\\subsection*{11.}\nUse \\emph{combinatorial} reasoning to prove the identity (in the form given)\n\\begin{align*}\n  \\binom{n}{k}-\\binom{n-3}{k}&=\\binom{n-1}{k-1}+\\binom{n-2}{k-1}+\\binom{n-3}{k-1}\n\\end{align*}\n(\\emph{Hint:} Let $S$ be a set with three distinguished elements $a, b,$ and $c$ and count certain $k$-subsets of $S$.)\n\nImagine we have a set $S=\\{x_1,x_2,\\dots,x_{n-3},a,b,c\\}$. We can grab $k$ elements from $S$ in $\\binom{n}{k}$ ways. If we want to grab $k$ elements out $S$, but none of them are $a,b,c$ we can do so in $\\binom{n-3}{k}$ ways. So $\\binom{n}{k}-\\binom{n-3}{k}$ is the number of ways to choose $k$ elements from the set where at least one of the elements is $a,b$, or $c$.\n\nNow lets count this quantity from the other end. First lets find all the sets that have $a$ in them. Since we've already chosen $a$ we can choose $k-1$ elements out of the $n-1$ sized set $S\\setminus a$, or $\\binom{n-1}{k-1}$. Now we want to find all the sets that contain $b$. When we counted the sets with $a$ in them that also included the sets that have both $a$ and $b$ in them. So we choose $b$ and then we need to grab all the sets of $k-1$ size from the $n-2$ sized set $S\\setminus\\{a,b\\}$. The ways we can do this is $\\binom{n-2}{k-1}$. And similarly the sets that contain $c$ but neither $a$ nor $b$ count $\\binom{n-3}{k-1}$. So we see that the number ways to choose $k$ elements from $\\{x_1,x_2,\\dots,x_{n-3},a,b,c\\}$ where at least one of the elements is $a,b,$ or $c$ is $\\binom{n-1}{k-1}+\\binom{n-2}{k-1}+\\binom{n-3}{k-1}$. And we have our identity.$\\Box$\n\\subsection*{14.}\nProve that\n\\[\\binom{r}{k}=\\frac{r}{r-k}\\binom{r-1}{k}\\]\nfor $r$ a real number and $k$ an integer with $r\\ne k$.\n\\subsection*{proof}\nThe binomial coefficient is defined by\n\\begin{align*}\n  \\binom{r}{k}&=\n  \\begin{cases}\n    \\frac{r(r-1)\\cdots(r-k+1)}{k!}&\\text{if }k\\ge 1\\\\\n    1&\\text{if }k=0\\\\\n    0&\\text{if }k\\le-1\n  \\end{cases}\n\\end{align*}\nWe have three cases to prove then. We'll do the trivial cases first, and then the more involved case.\n\\subsubsection*{case $k\\le-1$}\nIn this case $\\binom{r}{k}=0$ and $\\binom{r-1}{k}=0$. We see that both sides of our equality are $0$ and so the hypothesis holds in this case.\n\\subsubsection*{case $k=0$}\nIn this case we have $\\binom{r}{k}=\\binom{r-1}{k}=1$ and $\\frac{r}{r-k}=\\frac{r}{r-0}=1$. And both sides of our equality are $1$ so the hypothesis holds for this case as well.\n\\subsubsection*{case $k\\ge1$}\nWe will let the algebra do the talking for this case.\n\\begin{align*}\n  \\binom{r}{k}&=\\frac{r(r-1)\\cdots(r-k+1)}{k!}\\\\\n  &=r\\frac{(r-1)\\cdots(r-k+1)(r-k)}{k!(r-k)}\\\\\n  &=\\frac{r}{(r-k)}\\frac{(r-1)\\cdots(r-k+1)(r-k)}{k!}\\\\\n  \\intertext{Now we add and subtract one from the terms that contain $k$ and group the result for our convenience.}\n  &=\\frac{r}{(r-k)}\\frac{(r-1)((r-1)-1)\\cdots((r-1)-k+2)((r-1)-k+1)}{k!}\\\\\n  &=\\frac{r}{r-k}\\binom{r-1}{k}\n\\end{align*}\nSo the equality holds for all cases and our hypothesis is proven.$\\Box$\n\\subsection*{15.}\nProve, that for every integer $n>1,$\n\\[\\binom{n}{1}-2\\binom{n}{2}+3\\binom{n}{3}+\\dots+(-1)^{n-1}n\\binom{n}{n}=0\\]\n\\subsection*{proof}\nFirst we we will convert our equation to use the summation notation. Then we will apply identity 5.2 followed by the application of the binomial theorem. This should give us our result in short order.\n\\begin{align*}\n  0&=\\binom{n}{1}-2\\binom{n}{2}+3\\binom{n}{3}+\\dots+(-1)^{n-1}n\\binom{n}{n}\\\\\n  &=\\sum\\limits_{k=1}^n{(-1)^{k-1}k\\binom{n}{k}}\\\\\n  &=\\sum\\limits_{k=1}^n{(-1)^{k-1}n\\binom{n-1}{k-1}}\\\\\n  &=n\\sum\\limits_{k=0}^{n-1}{(-1)^{k}\\binom{n-1}{k}}\\\\\n  &=n\\sum\\limits_{k=0}^{n-1}{\\binom{n-1}{k}1^{(n-1)-k}(-1)^{k}}\\\\\n  &=n(1-1)^{n-1}=n\\cdot0^{n-1}=0\n\\end{align*}\nAnd as predicted we have our result.$\\Box$\n\\subsection*{16.}\nBy integrating the binomial expansion, prove that, for a positive integer $n$,\n\\[1+\\frac{1}{2}\\binom{n}{1}+\\frac{1}{3}\\binom{n}{2}+\\dots+\\frac{1}{n+1}\\binom{n}{n}=\\frac{2^{n+1}-1}{n+1}.\\]\n\\begin{align*}\n  \\int_0^1{\\sum\\limits_{k=0}^n{\\binom{n}{k}x^k}\\,\\mathrm{d}x}&=\\int_0^1{(1+x)^n\\,\\mathrm{d}x}\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}\\int_0^1{x^k\\,\\mathrm{d}x}}&=\\int_0^1{(1+x)^n\\,\\mathrm{d}x}\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}\\left[\\frac{x^{k+1}}{k+1}\\right]_0^1}&=\\left.\\frac{(1+x)^{n+1}}{n+1}\\right\\rvert_0^1\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}\\left[\\frac{1^{k+1}}{k+1}-\\frac{0^{k+1}}{k+1}\\right]}&=\\frac{(1+1)^{n+1}}{n+1}-\\frac{(1+0)^{n+1}}{n+1}\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}\\left[\\frac{1}{k+1}-0\\right]}&=\\frac{2^{n+1}}{n+1}-\\frac{1}{n+1}\\\\\n  \\sum\\limits_{k=0}^n{\\frac{1}{k+1}\\binom{n}{k}}&=\\frac{2^{n+1}-1}{n+1}\\\\\n  1+\\frac{1}{2}\\binom{n}{1}+\\frac{1}{3}\\binom{n}{2}+\\dots+\\frac{1}{n+1}\\binom{n}{n}&=\\frac{2^{n+1}-1}{n+1}\n\\end{align*}\n\\subsection*{17.}\nProve the identity in the previous exercise by  using (5.2) and (5.3).\n\\begin{align*}\n  \\frac{2^{n+1}-1}{n+1}&=1+\\frac{1}{2}\\binom{n}{1}+\\frac{1}{3}\\binom{n}{2}+\\dots+\\frac{1}{n+1}\\binom{n}{n}\\\\\n  (n+1)\\frac{2^{n+1}-1}{n+1}&=(n+1)\\sum\\limits_{k=0}^n{\\frac{1}{k+1}\\binom{n}{k}}\\\\\n  2^{n+1}-1&=\\sum\\limits_{k=0}^n{\\frac{1}{k+1}(n+1)\\binom{n}{k}}\\\\\n  \\intertext{Apply identity 5.2}\n  &=\\sum\\limits_{k=0}^n{\\frac{1}{k+1}(k+1)\\binom{n+1}{k+1}}\\\\\n  &=\\sum\\limits_{k=0}^n{\\binom{n+1}{k+1}}=\\sum\\limits_{k=1}^{n+1}{\\binom{n+1}{k}}\\\\\n  &=-\\binom{n+1}{0}+\\sum\\limits_{k=0}^{n+1}{\\binom{n+1}{k}}\\\\\n  \\intertext{simplify and apply 5.3}\n  &=-1+2^{n+1}\n\\end{align*}\n\\subsection*{21.}\nProve that, for all real nmbers $r$ and all integers $k$,\n\\[\\binom{-r}{k}=(-1)^k\\binom{r+k-1}{k}.\\]\nIf $k=0$ $\\binom{-r}{k}=1$ and $(-1)^0\\binom{r+k-1}{k}=1$. If $k\\le-1$ then $\\binom{-r}{k}=0$ and $(-1)^k\\binom{r+k-1}{k}=(-1)^k\\cdot0=0$. If $k\\ge1$ then:\n\\begin{align*}\n  \\binom{-r}{k}&=\\frac{-r(-r-1)\\cdots(-r-k+1)}{k!}\\\\\n  &=\\frac{1}{k!}\\prod_{n=0}^{k-1}{(-r)-n}=\\frac{(-1)^k}{k!}\\prod_{n=0}^{k-1}{r+n}\\\\\n  &=\\frac{(-1)^k}{k!}\\prod_{n=0}^{k-1}{(r+k-1)+(n-(k-1))}\\\\\n  &=\\frac{(-1)^k}{k!}\\prod_{n=-(k-1)}^{0}{(r+k-1)+n}=\\frac{(-1)^k}{k!}\\prod_{n=0}^{k-1}{(r+k-1)-n}\\\\\n  &=(-1)^k\\frac{(r+k-1)(r+k-1-1)\\cdots(r+k-1-k+1)}{k!}\\\\\n  \\binom{-r}{k}&=(-1)^k\\binom{r+k-1}{k}\n\\end{align*}\n\\subsection*{27.}\nLet $n$ and $k$ be positive integers. Give a combinatorial proof of the identity (5.15):\n\\[n(n+1)2^{n-2}=\\sum\\limits_{k=1}^n{k^2\\binom{n}{k}}.\\]\n\\subsection*{proof}\nImagine we have a 3-tuple $(A,a,b)$. We'll say $A$ is a subset of some set $S$ where $\\lvert A\\rvert=k$ and $\\lvert S\\rvert=n$ for some integers $k,n$ such that $0<k\\le n$. Let $a,b\\in A$. We then have $k^2\\binom{n}{k}$ possible 3-tuples where $A$ is of size $k$. If we want to count how many tuples are possible for all $k$ then we arrive at the formula $\\sum\\limits_{k=1}^n{k^2\\binom{n}{k}}$.\n\nNow let us instead choose the last two items in the 3-tuple first. We have two cases here. Either the last two items are the same, or they are different. If they are the same then we have $n$ choices for these items. If they are different we have $n(n-1)$ choices. Now if imagine that each element of $S$ can either be in $A$ or not. Since we have already chosen $a,b\\in A$ we have $2^{n-1}$ posibilities if $a=b$ and $2^{n-2}$ possibilities if $a\\ne b$. This gives us the following formula to count all the possible 3-tuples:\n\\begin{align*}\n  n2^{n-1}+n(n-1)2^{n-2}&=2n2^{n-2}+n(n-1)2^{n-2}\\\\\n  &=2^{n-2}(2n+n^2-n)\\\\\n  &=2^{n-2}(n^2+n)\\\\\n  &=n(n+1)2^{n-2}\n\\end{align*}\nAnd we see both sides of our hypothesis count these 3-tuples and are therefore equal.$\\Box$\n\\subsection*{28.}\nLet $n$ and $k$ be positive integers. Give a combinatorial proof that\n\\[\\sum\\limits_{k=1}^n{k\\binom{n}{k}^2}=n\\binom{2n-1}{n-1}\\]\n\\subsection*{proof}\nWe want to form an ordered pair $(C,a)$ consisting firstly a set $C$, and secondly, an element $a$ from that set. The set has $n$ elements ($\\lvert C\\rvert=n$) and is a subset of the union of two subsets of some disjoint sets $A$ and $B$ which contain $n$ elements each. So $\\lvert A\\rvert=\\lvert B\\rvert=n$ and $C\\subset(A\\cup B)$. The second item in the pair is in $A$. So $a\\in A$ and $a\\in C$. Let's count how many ordered pairs we can make.\n\nFirst let's choose $a\\in C$ from $A$. We can do this in $n$ different ways. Now we choose the rest of $C$ (or $C\\setminus a$) by grabbing $n-1$ elements from $(A\\cup B)\\setminus a$. We can do this in $\\binom{2n-1}{n-1}$ ways. So we can build the ordered pairs in $n\\binom{2n-1}{n-1}$ ways.\n\nNow lets count in a different way. First we take some $k$ elements from $A$ where $1\\le k\\le n$. We can do this in $\\binom{n}{k}$ ways. We can choose $a$ in $k$ different ways from these elements. We then choose $n-k$ elements from $B$ to complete set $C$. We can do this in $\\binom{n}{n-k}$. We can then form an ordered pair where $k$ elements come from $A$ and $n-k$ elements come from $B$ in $k\\binom{n}{k}\\binom{n}{n-k}$. It is trivial to show that $\\binom{n}{k}=\\binom{n}{n-k}$. So adding together the number of ways we can form the ordered pairs in this way for all possible values of $k$ we have $\\sum\\limits_{k=1}^n{k\\binom{n}{k}^2}$.\n\nAnd we see then that $\\sum\\limits_{k=1}^n{k\\binom{n}{k}^2}=n\\binom{2n-1}{n-1}$.$\\Box$\n\\end{document}\n", "meta": {"hexsha": "846e67e3014105f341f1b1c935a06e1cfb4f5873", "size": 11589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-hw-2014-02-26.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-26.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-26.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": 65.8465909091, "max_line_length": 869, "alphanum_fraction": 0.6294762275, "num_tokens": 4977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925404, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.6739467793324431}}
{"text": "\\section{Geometric Image Transformations}\n\nThe functions in this section perform various geometrical transformations of 2D images. That is, they do not change the image content, but deform the pixel grid, and map this deformed grid to the destination image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel $(x, y)$ of the destination image, the functions compute coordinates of the corresponding \"donor\" pixel in the source image and copy the pixel value, that is:\n\n\\[\\texttt{dst}(x,y)=\\texttt{src}(f_x(x,y), f_y(x,y))\\]\n\nIn the case when the user specifies the forward mapping: $\\left<g_x, g_y\\right>: \\texttt{src} \\rightarrow \\texttt{dst}$, the OpenCV functions first compute the corresponding inverse mapping: $\\left<f_x, f_y\\right>: \\texttt{dst} \\rightarrow \\texttt{src}$ and then use the above formula.\n\nThe actual implementations of the geometrical transformations, from the most generic \\cvCross{Remap}{remap} and to the simplest and the fastest \\cvCross{Resize}{resize}, need to solve the 2 main problems with the above formula:\n\\begin{enumerate}\n    \\item extrapolation of non-existing pixels. Similarly to the filtering functions, described in the previous section, for some $(x,y)$ one of $f_x(x,y)$ or $f_y(x,y)$, or they both, may fall outside of the image, in which case some extrapolation method needs to be used. OpenCV provides the same selection of the extrapolation methods as in the filtering functions, but also an additional method \\texttt{BORDER\\_TRANSPARENT}, which means that the corresponding pixels in the destination image will not be modified at all.\n    \\item interpolation of pixel values. Usually $f_x(x,y)$ and $f_y(x,y)$ are floating-point numbers (i.e. $\\left<f_x, f_y\\right>$ can be an affine or perspective transformation, or radial lens distortion correction etc.), so a pixel values at fractional coordinates needs to be retrieved. In the simplest case the coordinates can be just rounded to the nearest integer coordinates and the corresponding pixel used, which is called nearest-neighbor interpolation. However, a better result can be achieved by using more sophisticated \\href{http://en.wikipedia.org/wiki/Multivariate_interpolation}{interpolation methods}, where a polynomial function is fit into some neighborhood of the computed pixel $(f_x(x,y), f_y(x,y))$ and then the value of the polynomial at $(f_x(x,y), f_y(x,y))$ is taken as the interpolated pixel value. In OpenCV you can choose between several interpolation methods, see \\cvCross{Resize}{resize}. \n\\end{enumerate}\n\n\\ifCPy\n\n\\cvCPyFunc{GetRotationMatrix2D}\nCalculates the affine matrix of 2d rotation.\n\n\\cvdefC{\nCvMat* cv2DRotationMatrix(\n\\par CvPoint2D32f center,\n\\par double angle,\n\\par double scale,\n\\par CvMat* mapMatrix );\n}\\cvdefPy{GetRotationMatrix2D(center,angle,scale,mapMatrix)-> None}\n\n\\begin{description}\n\\cvarg{center}{Center of the rotation in the source image}\n\\cvarg{angle}{The rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner)}\n\\cvarg{scale}{Isotropic scale factor}\n\\cvarg{mapMatrix}{Pointer to the destination $2\\times 3$ matrix}\n\\end{description}\n\nThe function \\texttt{cv2DRotationMatrix} calculates the following matrix:\n\n\\[\n\\begin{bmatrix}\n\\alpha & \\beta & (1-\\alpha) \\cdot \\texttt{center.x} - \\beta \\cdot \\texttt{center.y} \\\\\n-\\beta & \\alpha & \\beta \\cdot \\texttt{center.x} - (1-\\alpha) \\cdot \\texttt{center.y}\n\\end{bmatrix}\n\\]\n\nwhere\n\n\\[\n\\alpha = \\texttt{scale} \\cdot cos(\\texttt{angle}), \\beta = \\texttt{scale} \\cdot sin(\\texttt{angle})\n\\]\n\nThe transformation maps the rotation center to itself. If this is not the purpose, the shift should be adjusted.\n\n\\cvCPyFunc{GetAffineTransform}\nCalculates the affine transform from 3 corresponding points.\n\n\\cvdefC{\nCvMat* cvGetAffineTransform(\n\\par const CvPoint2D32f* src,\n\\par const CvPoint2D32f* dst, \n\\par CvMat* mapMatrix );\n}\\cvdefPy{GetAffineTransform(src,dst,mapMatrix)-> None}\n\n\\begin{description}\n\\cvarg{src}{ Coordinates of 3 triangle vertices in the source image}\n\\cvarg{dst}{ Coordinates of the 3 corresponding triangle vertices in the destination image}\n\\cvarg{mapMatrix}{ Pointer to the destination $2 \\times 3$ matrix}\n\\end{description}\n\nThe function cvGetAffineTransform calculates the matrix of an affine transform such that:\n\n\\[\n\\begin{bmatrix}\nx'_i\\\\\ny'_i\n\\end{bmatrix}\n=\n\\texttt{mapMatrix}\n\\cdot\n\\begin{bmatrix}\nx_i\\\\\ny_i\\\\\n1\n\\end{bmatrix}\n\\]\n\nwhere\n\n\\[\ndst(i)=(x'_i,y'_i),\nsrc(i)=(x_i, y_i),\ni=0,1,2\n\\]\n\n\\cvCPyFunc{GetPerspectiveTransform}\nCalculates the perspective transform from 4 corresponding points.\n\n\\cvdefC{\nCvMat* cvGetPerspectiveTransform(\n\\par const CvPoint2D32f* src,\n\\par const CvPoint2D32f* dst,\n\\par CvMat* mapMatrix );\n}\\cvdefPy{GetPerspectiveTransform(src,dst,mapMatrix)-> None}\n\n\\begin{description}\n\\cvarg{src}{Coordinates of 4 quadrangle vertices in the source image}\n\\cvarg{dst}{Coordinates of the 4 corresponding quadrangle vertices in the destination image}\n\\cvarg{mapMatrix}{Pointer to the destination $3\\times 3$ matrix}\n\\end{description}\n\nThe function \\texttt{cvGetPerspectiveTransform} calculates a matrix of perspective transforms such that:\n\n\\[\n\\begin{bmatrix}\nx'_i\\\\\ny'_i\n\\end{bmatrix}\n=\n\\texttt{mapMatrix}\n\\cdot\n\\begin{bmatrix}\nx_i\\\\\ny_i\\\\\n1\n\\end{bmatrix}\n\\]\n\nwhere\n\n\\[\ndst(i)=(x'_i,y'_i),\nsrc(i)=(x_i, y_i),\ni=0,1,2,3\n\\]\n\n\\cvCPyFunc{GetQuadrangleSubPix}\nRetrieves the pixel quadrangle from an image with sub-pixel accuracy.\n\n\\cvdefC{\nvoid cvGetQuadrangleSubPix(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par const CvMat* mapMatrix );\n}\\cvdefPy{GetQuadrangleSubPix(src,dst,mapMatrix)-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Extracted quadrangle}\n\\cvarg{mapMatrix}{The transformation $2 \\times 3$ matrix $[A|b]$ (see the discussion)}\n\\end{description}\n\nThe function \\texttt{cvGetQuadrangleSubPix} extracts pixels from \\texttt{src} at sub-pixel accuracy and stores them to \\texttt{dst} as follows:\n\n\\[\ndst(x, y)= src( A_{11} x' + A_{12} y' + b_1, A_{21} x' + A_{22} y' + b_2)\n\\]\n\nwhere\n\n\\[\nx'=x-\\frac{(width(dst)-1)}{2}, \ny'=y-\\frac{(height(dst)-1)}{2}\n\\]\n\nand\n\n\\[\n\\texttt{mapMatrix} = \\begin{bmatrix}\nA_{11} & A_{12} & b_1\\\\\nA_{21} & A_{22} & b_2\n\\end{bmatrix}\n\\]\n\nThe values of pixels at non-integer coordinates are retrieved using bilinear interpolation. When the function needs pixels outside of the image, it uses replication border mode to reconstruct the values. Every channel of multiple-channel images is processed independently.\n\n\n\\cvCPyFunc{GetRectSubPix}\nRetrieves the pixel rectangle from an image with sub-pixel accuracy.\n \n\\cvdefC{void cvGetRectSubPix(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par CvPoint2D32f center );\n}\\cvdefPy{GetRectSubPix(src,dst,center)-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Extracted rectangle}\n\\cvarg{center}{Floating point coordinates of the extracted rectangle center within the source image. The center must be inside the image}\n\\end{description}\n\nThe function \\texttt{cvGetRectSubPix} extracts pixels from \\texttt{src}:\n\n\\[\ndst(x, y) = src(x + \\texttt{center.x} - (width(\\texttt{dst})-1)*0.5, y + \\texttt{center.y} - (height(\\texttt{dst} )-1)*0.5)\n\\]\n\nwhere the values of the pixels at non-integer coordinates are retrieved\nusing bilinear interpolation. Every channel of multiple-channel\nimages is processed independently. While the rectangle center\nmust be inside the image, parts of the rectangle may be\noutside. In this case, the replication border mode is used to get\npixel values beyond the image boundaries.\n\n\n\\cvCPyFunc{LogPolar}\nRemaps an image to log-polar space.\n\n\\cvdefC{\nvoid cvLogPolar(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par CvPoint2D32f center,\n\\par double M,\n\\par int flags=CV\\_INTER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS );}\n\\cvdefPy{LogPolar(src,dst,center,M,flags=CV\\_INNER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS)-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image}\n\\cvarg{center}{The transformation center; where the output precision is maximal}\n\\cvarg{M}{Magnitude scale parameter. See below}\n\\cvarg{flags}{A combination of interpolation methods and the following optional flags:\n\\begin{description}\n  \\cvarg{CV\\_WARP\\_FILL\\_OUTLIERS}{fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero}\n  \\cvarg{CV\\_WARP\\_INVERSE\\_MAP}{See below}\n\\end{description}}\n\\end{description}\n\nThe function \\texttt{cvLogPolar} transforms the source image using the following transformation:\n\nForward transformation (\\texttt{CV\\_WARP\\_INVERSE\\_MAP} is not set):\n\n\\[\ndst(\\phi,\\rho) = src(x,y)\n\\]\n\nInverse transformation (\\texttt{CV\\_WARP\\_INVERSE\\_MAP} is set):\n\n\\[\ndst(x,y) = src(\\phi,\\rho)\n\\]\n\nwhere\n\n\\[\n\\rho = M \\cdot \\log{\\sqrt{x^2 + y^2}},\n\\phi=atan(y/x)\n\\]\n\nThe function emulates the human \"foveal\" vision and can be used for fast scale and rotation-invariant template matching, for object tracking and so forth.\nThe function can not operate in-place.\n\n\\ifC\n% Example: Log-polar transformation\n\\begin{lstlisting}\n#include <cv.h>\n#include <highgui.h>\n\nint main(int argc, char** argv)\n{\n    IplImage* src;\n\n    if( argc == 2 && (src=cvLoadImage(argv[1],1) != 0 )\n    {\n        IplImage* dst = cvCreateImage( cvSize(256,256), 8, 3 );\n        IplImage* src2 = cvCreateImage( cvGetSize(src), 8, 3 );\n        cvLogPolar( src, dst, cvPoint2D32f(src->width/2,src->height/2), 40, \n        CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );\n        cvLogPolar( dst, src2, cvPoint2D32f(src->width/2,src->height/2), 40, \n        CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP );\n        cvNamedWindow( \"log-polar\", 1 );\n        cvShowImage( \"log-polar\", dst );\n        cvNamedWindow( \"inverse log-polar\", 1 );\n        cvShowImage( \"inverse log-polar\", src2 );\n        cvWaitKey();\n    }\n    return 0;\n}\n\\end{lstlisting}\n\nAnd this is what the program displays when \\texttt{opencv/samples/c/fruits.jpg} is passed to it\n\\includegraphics[width=0.4\\textwidth]{pics/logpolar.jpg}\n\\includegraphics[width=0.4\\textwidth]{pics/inv_logpolar.jpg}\n\\fi\n\n\\cvCPyFunc{Remap}\nApplies a generic geometrical transformation to the image.\n\n\\cvdefC{\nvoid cvRemap(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par const CvArr* mapx,\n\\par const CvArr* mapy,\n\\par int flags=CV\\_INTER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS,\n\\par CvScalar fillval=cvScalarAll(0) );}\n\\cvdefPy{Remap(src,dst,mapx,mapy,flags=CV\\_INNER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS,fillval=(0,0,0,0))-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image}\n\\cvarg{mapx}{The map of x-coordinates (CV\\_32FC1 image)}\n\\cvarg{mapy}{The map of y-coordinates (CV\\_32FC1 image)}\n\\cvarg{flags}{A combination of interpolation method and the following optional flag(s):\n\\begin{description}\n  \\cvarg{CV\\_WARP\\_FILL\\_OUTLIERS}{fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to \\texttt{fillval}}\n\\end{description}}\n\\cvarg{fillval}{A value used to fill outliers}\n\\end{description}\n\nThe function \\texttt{cvRemap} transforms the source image using the specified map:\n\n\\[\n\\texttt{dst}(x,y) = \\texttt{src}(\\texttt{mapx}(x,y),\\texttt{mapy}(x,y))\n\\]\n\nSimilar to other geometrical transformations, some interpolation method (specified by user) is used to extract pixels with non-integer coordinates.\nNote that the function can not operate in-place.\n\n\\cvCPyFunc{Resize}\nResizes an image.\n\n\\cvdefC{\nvoid cvResize(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par int interpolation=CV\\_INTER\\_LINEAR );}\n\\cvdefPy{Resize(src,dst,interpolation=CV\\_INTER\\_LINEAR)-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image}\n\\cvarg{interpolation}{Interpolation method:\n\\begin{description}\n\\cvarg{CV\\_INTER\\_NN}{nearest-neigbor interpolation}\n\\cvarg{CV\\_INTER\\_LINEAR}{bilinear interpolation (used by default)}\n\\cvarg{CV\\_INTER\\_AREA}{resampling using pixel area relation. It is the preferred method for image decimation that gives moire-free results. In terms of zooming it is similar to the \\texttt{CV\\_INTER\\_NN} method}\n\\cvarg{CV\\_INTER\\_CUBIC}{bicubic interpolation}\n\\end{description}}\n\\end{description}\n\nThe function \\texttt{cvResize} resizes an image \\texttt{src} so that it fits exactly into \\texttt{dst}. If ROI is set, the function considers the ROI as supported.\n\n\n\\cvCPyFunc{WarpAffine}\nApplies an affine transformation to an image.\n\n\\cvdefC{\nvoid cvWarpAffine(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par const CvMat* mapMatrix,\n\\par int flags=CV\\_INTER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS,\n\\par CvScalar fillval=cvScalarAll(0) );\n}\n\\cvdefPy{WarpAffine(src,dst,mapMatrix,flags=CV\\_INTER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS,fillval=(0,0,0,0))-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image}\n\\cvarg{mapMatrix}{$2\\times 3$ transformation matrix}\n\\cvarg{flags}{A combination of interpolation methods and the following optional flags:\n\\begin{description}\n  \\cvarg{CV\\_WARP\\_FILL\\_OUTLIERS}{fills all of the destination image pixels; if some of them correspond to outliers in the source image, they are set to \\texttt{fillval}}\n  \\cvarg{CV\\_WARP\\_INVERSE\\_MAP}{indicates that \\texttt{matrix} is inversely\n  transformed from the destination image to the source and, thus, can be used\n  directly for pixel interpolation. Otherwise, the function finds\n  the inverse transform from \\texttt{mapMatrix}}}\n\\end{description}\n\\cvarg{fillval}{A value used to fill outliers}\n\\end{description}\n\nThe function \\texttt{cvWarpAffine} transforms the source image using the specified matrix:\n\n\\[\ndst(x',y') = src(x,y)\n\\]\n\nwhere\n\n\\[\n\\begin{matrix}\n\\begin{bmatrix}\nx'\\\\\ny'\n\\end{bmatrix} = \\texttt{mapMatrix} \\cdot \\begin{bmatrix}\nx\\\\\ny\\\\\n1\n\\end{bmatrix} & \\mbox{if CV\\_WARP\\_INVERSE\\_MAP is not set}\\\\\n\\begin{bmatrix}\nx\\\\\ny\n\\end{bmatrix} = \\texttt{mapMatrix} \\cdot \\begin{bmatrix}\nx'\\\\\ny'\\\\\n1\n\\end{bmatrix}& \\mbox{otherwise}\n\\end{matrix}\n\\]\n\nThe function is similar to \\cvCPyCross{GetQuadrangleSubPix} but they are not exactly the same. \\cvCPyCross{WarpAffine} requires input and output image have the same data type, has larger overhead (so it is not quite suitable for small images) and can leave part of destination image unchanged. While \\cvCPyCross{GetQuadrangleSubPix} may extract quadrangles from 8-bit images into floating-point buffer, has smaller overhead and always changes the whole destination image content.\nNote that the function can not operate in-place.\n\nTo transform a sparse set of points, use the \\cvCPyCross{Transform} function from cxcore.\n\n\\cvCPyFunc{WarpPerspective}\nApplies a perspective transformation to an image.\n\n\\cvdefC{\nvoid cvWarpPerspective(\n\\par const CvArr* src,\n\\par CvArr* dst,\n\\par const CvMat* mapMatrix,\n\\par int flags=CV\\_INTER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS,\n\\par CvScalar fillval=cvScalarAll(0) );\n}\n\\cvdefPy{WarpPerspective(src,dst,mapMatrix,flags=CV\\_INNER\\_LINEAR+CV\\_WARP\\_FILL\\_OUTLIERS,fillval=(0,0,0,0))-> None}\n\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image}\n\\cvarg{mapMatrix}{$3\\times 3$ transformation matrix}\n\\cvarg{flags}{A combination of interpolation methods and the following optional flags:\n\\begin{description}\n  \\cvarg{CV\\_WARP\\_FILL\\_OUTLIERS}{fills all of the destination image pixels; if some of them correspond to outliers in the source image, they are set to \\texttt{fillval}}\n  \\cvarg{CV\\_WARP\\_INVERSE\\_MAP}{indicates that \\texttt{matrix} is inversely transformed from the destination image to the source and, thus, can be used directly for pixel interpolation. Otherwise, the function finds the inverse transform from \\texttt{mapMatrix}}\n\\end{description}}\n\\cvarg{fillval}{A value used to fill outliers}\n\\end{description}\n\nThe function \\texttt{cvWarpPerspective} transforms the source image using the specified matrix:\n\n\\[\n\\begin{matrix}\n\\begin{bmatrix}\nx'\\\\\ny'\n\\end{bmatrix} = \\texttt{mapMatrix} \\cdot \\begin{bmatrix}\nx\\\\\ny\\\\\n1\n\\end{bmatrix} & \\mbox{if CV\\_WARP\\_INVERSE\\_MAP is not set}\\\\\n\\begin{bmatrix}\nx\\\\\ny\n\\end{bmatrix} = \\texttt{mapMatrix} \\cdot \\begin{bmatrix}\nx'\\\\\ny'\\\\\n1\n\\end{bmatrix}& \\mbox{otherwise}\n\\end{matrix}\n\\]\n\nNote that the function can not operate in-place.\nFor a sparse set of points use the \\cvCPyCross{PerspectiveTransform} function from CxCore.\n\n\\fi\n\n\\ifCpp\n\n\\cvCppFunc{convertMaps}\nConverts image transformation maps from one representation to another\n\n\\cvdefCpp{void convertMaps( const Mat\\& map1, const Mat\\& map2,\\par\n                  Mat\\& dstmap1, Mat\\& dstmap2,\\par\n                  int dstmap1type, bool nninterpolation=false );}\n\\begin{description}\n\\cvarg{map1}{The first input map of type \\texttt{CV\\_16SC2} or \\texttt{CV\\_32FC1} or \\texttt{CV\\_32FC2}}\n\\cvarg{map2}{The second input map of type \\texttt{CV\\_16UC1} or \\texttt{CV\\_32FC1} or none (empty matrix), respectively}\n\\cvarg{dstmap1}{The first output map; will have type \\texttt{dstmap1type} and the same size as \\texttt{src}}\n\\cvarg{dstmap2}{The second output map}\n\\cvarg{dstmap1type}{The type of the first output map; should be \\texttt{CV\\_16SC2}, \\texttt{CV\\_32FC1} or \\texttt{CV\\_32FC2}}\n\\cvarg{nninterpolation}{Indicates whether the fixed-point maps will be used for nearest-neighbor or for more complex interpolation}\n\\end{description}\n\nThe function converts a pair of maps for \\cvCppCross{remap} from one representation to another. The following options (\\texttt{(map1.type(), map2.type())} $\\rightarrow$ \\texttt{(dstmap1.type(), dstmap2.type())}) are supported:\n\\begin{enumerate}\n    \\item $\\texttt{(CV\\_32FC1, CV\\_32FC1)} \\rightarrow \\texttt{(CV\\_16SC2, CV\\_16UC1)}$. This is the most frequently used conversion operation, in which the original floating-point maps (see \\cvCppCross{remap}) are converted to more compact and much faster fixed-point representation. The first output array will contain the rounded coordinates and the second array (created only when \\texttt{nninterpolation=false}) will contain indices in the interpolation tables.   \n    \\item $\\texttt{(CV\\_32FC2)} \\rightarrow \\texttt{(CV\\_16SC2, CV\\_16UC1)}$. The same as above, but the original maps are stored in one 2-channel matrix.\n    \\item the reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same as the originals.\n\\end{enumerate} \n\nSee also: \\cvCppCross{remap}, \\cvCppCross{undisort}, \\cvCppCross{initUndistortRectifyMap}\n\n\\cvCppFunc{getAffineTransform}\nCalculates the affine transform from 3 pairs of the corresponding points\n\n\\cvdefCpp{Mat getAffineTransform( const Point2f src[], const Point2f dst[] );}\n\n\\begin{description}\n\\cvarg{src}{Coordinates of a triangle vertices in the source image}\n\\cvarg{dst}{Coordinates of the corresponding triangle vertices in the destination image}\n\\end{description}\n\nThe function calculates the $2 \\times 3$ matrix of an affine transform such that:\n\n\\[\n\\begin{bmatrix}\nx'_i\\\\\ny'_i\n\\end{bmatrix}\n=\n\\texttt{map\\_matrix}\n\\cdot\n\\begin{bmatrix}\nx_i\\\\\ny_i\\\\\n1\n\\end{bmatrix}\n\\]\n\nwhere\n\n\\[\ndst(i)=(x'_i,y'_i),\nsrc(i)=(x_i, y_i),\ni=0,1,2\n\\]\n\nSee also: \\cvCppCross{warpAffine}, \\cvCppCross{transform}\n\n\\cvCppFunc{getPerspectiveTransform}\nCalculates the perspective transform from 4 pairs of the corresponding points\n\n\\cvdefCpp{Mat getPerspectiveTransform( const Point2f src[], \\par const Point2f dst[] );}\n\n\\begin{description}\n\\cvarg{src}{Coordinates of a quadrange vertices in the source image}\n\\cvarg{dst}{Coordinates of the corresponding quadrangle vertices in the destination image}\n\\end{description}\n\nThe function calculates the $3 \\times 3$ matrix of a perspective transform such that:\n\n\\[\n\\begin{bmatrix}\nt_i x'_i\\\\\nt_i y'_i\\\\\nt_i\n\\end{bmatrix}\n=\n\\texttt{map\\_matrix}\n\\cdot\n\\begin{bmatrix}\nx_i\\\\\ny_i\\\\\n1\n\\end{bmatrix}\n\\]\n\nwhere\n\n\\[\ndst(i)=(x'_i,y'_i),\nsrc(i)=(x_i, y_i),\ni=0,1,2\n\\]\n\nSee also: \\cvCppCross{findHomography}, \\cvCppCross{warpPerspective}, \\cvCppCross{perspectiveTransform}\n\n\\cvCppFunc{getRectSubPix}\nRetrieves the pixel rectangle from an image with sub-pixel accuracy\n\n\\cvdefCpp{void getRectSubPix( const Mat\\& image, Size patchSize,\\par\n                    Point2f center, Mat\\& dst, int patchType=-1 );}\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{patchSize}{Size of the extracted patch}\n\\cvarg{center}{Floating point coordinates of the extracted rectangle center within the source image. The center must be inside the image}\n\\cvarg{dst}{The extracted patch; will have the size \\texttt{patchSize} and the same number of channels as \\texttt{src}}\n\\cvarg{patchType}{The depth of the extracted pixels. By default they will have the same depth as \\texttt{src}}\n\\end{description}\n\nThe function \\texttt{getRectSubPix} extracts pixels from \\texttt{src}:\n\n\\[\ndst(x, y) = src(x + \\texttt{center.x} - (\\texttt{dst.cols}-1)*0.5, y + \\texttt{center.y} - (\\texttt{dst.rows}-1)*0.5)\n\\]\n\nwhere the values of the pixels at non-integer coordinates are retrieved\nusing bilinear interpolation. Every channel of multiple-channel\nimages is processed independently. While the rectangle center\nmust be inside the image, parts of the rectangle may be\noutside. In this case, the replication border mode (see \\cvCppCross{borderInterpolate}) is used to extrapolate\nthe pixel values outside of the image.\n\nSee also: \\cvCppCross{warpAffine}, \\cvCppCross{warpPerspective}\n\n\\cvCppFunc{getRotationMatrix2D}\nCalculates the affine matrix of 2d rotation.\n\n\\cvdefCpp{Mat getRotationMatrix2D( Point2f center, double angle, double scale );}\n\\begin{description}\n\\cvarg{center}{Center of the rotation in the source image}\n\\cvarg{angle}{The rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner)}\n\\cvarg{scale}{Isotropic scale factor}\n\\end{description}\n\nThe function calculates the following matrix:\n\n\\[\n\\begin{bmatrix}\n\\alpha & \\beta & (1-\\alpha) \\cdot \\texttt{center.x} - \\beta \\cdot \\texttt{center.y} \\\\\n-\\beta & \\alpha & \\beta \\cdot \\texttt{center.x} - (1-\\alpha) \\cdot \\texttt{center.y}\n\\end{bmatrix}\n\\]\n\nwhere\n\n\\[\n\\begin{array}{l}\n\\alpha = \\texttt{scale} \\cdot \\cos \\texttt{angle},\\\\\n\\beta = \\texttt{scale} \\cdot \\sin \\texttt{angle}\n\\end{array}\n\\]\n\nThe transformation maps the rotation center to itself. If this is not the purpose, the shift should be adjusted.\n\nSee also: \\cvCppCross{getAffineTransform}, \\cvCppCross{warpAffine}, \\cvCppCross{transform}\n\n\n\\cvCppFunc{invertAffineTransform}\nInverts an affine transformation\n\n\\cvdefCpp{void invertAffineTransform(const Mat\\& M, Mat\\& iM);}\n\\begin{description}\n\\cvarg{M}{The original affine transformation}\n\\cvarg{iM}{The output reverse affine transformation}\n\\end{description}\n\nThe function computes inverse affine transformation represented by $2 \\times 3$ matrix \\texttt{M}:\n\n\\[\\begin{bmatrix}\na_{11} & a_{12} & b_1 \\\\\na_{21} & a_{22} & b_2\n\\end{bmatrix}\n\\]\n\nThe result will also be a $2 \\times 3$ matrix of the same type as \\texttt{M}.\n\n\\cvCppFunc{remap}\nApplies a generic geometrical transformation to an image.\n\n\\cvdefCpp{void remap( const Mat\\& src, Mat\\& dst, const Mat\\& map1, const Mat\\& map2,\\par\n            int interpolation, int borderMode=BORDER\\_CONSTANT,\\par\n            const Scalar\\& borderValue=Scalar());}\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image. It will have the same size as \\texttt{map1} and the same type as \\texttt{src}}\n\\cvarg{map1}{The first map of either \\texttt{(x,y)} points or just \\texttt{x} values having type \\texttt{CV\\_16SC2}, \\texttt{CV\\_32FC1} or \\texttt{CV\\_32FC2}. See \\cvCppCross{convertMaps} for converting floating point representation to fixed-point for speed.}\n\\cvarg{map2}{The second map of \\texttt{y} values having type \\texttt{CV\\_16UC1}, \\texttt{CV\\_32FC1} or none (empty map if map1 is \\texttt{(x,y)} points), respectively}\n\\cvarg{interpolation}{The interpolation method, see \\cvCppCross{resize}. The method \\texttt{INTER\\_AREA} is not supported by this function}\n\\cvarg{borderMode}{The pixel extrapolation method, see \\cvCppCross{borderInterpolate}. When the\\\\ \\texttt{borderMode=BORDER\\_TRANSPARENT}, it means that the pixels in the destination image that corresponds to the \"outliers\" in the source image are not modified by the function}\n\\cvarg{borderValue}{A value used in the case of a constant border. By default it is 0}\n\\end{description}\n\nThe function \\texttt{remap} transforms the source image using the specified map:\n\n\\[\n\\texttt{dst}(x,y) = \\texttt{src}(map_x(x,y),map_y(x,y))\n\\]\n\nWhere values of pixels with non-integer coordinates are computed using one of the available interpolation methods. $map_x$ and $map_y$ \ncan be encoded as separate floating-point maps in $map_1$ and $map_2$ respectively, or interleaved floating-point maps of $(x,y)$ in $map_1$, or \nfixed-point maps made by using \\cvCppCross{convertMaps}. The reason you might want to convert from floating to fixed-point \nrepresentations of a map is that they can yield much faster (~2x) remapping operations. In the converted case, $map_1$ contains pairs \n\\texttt{(cvFloor(x), cvFloor(y))} and $map_2$ contains indices in a table of interpolation coefficients. \n\nThis function can not operate in-place.\n\n\\cvCppFunc{resize}\nResizes an image\n\n\\cvdefCpp{void resize( const Mat\\& src, Mat\\& dst,\\par\n             Size dsize, double fx=0, double fy=0,\\par\n             int interpolation=INTER\\_LINEAR );}\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image. It will have size \\texttt{dsize} (when it is non-zero) or the size computed from \\texttt{src.size()}\nand \\texttt{fx} and \\texttt{fy}. The type of \\texttt{dst} will be the same as of \\texttt{src}.}\n\\cvarg{dsize}{The destination image size. If it is zero, then it is computed as:\n\\[\\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\\].\nEither \\texttt{dsize} or both \\texttt{fx} or \\texttt{fy} must be non-zero.}\n\\cvarg{fx}{The scale factor along the horizontal axis. When 0, it is computed as\n\\[\\texttt{(double)dsize.width/src.cols}\\]}\n\\cvarg{fy}{The scale factor along the vertical axis. When 0, it is computed as\n\\[\\texttt{(double)dsize.height/src.rows}\\]}\n\\cvarg{interpolation}{The interpolation method:\n\\begin{description}\n\\cvarg{INTER\\_NEAREST}{nearest-neighbor interpolation}\n\\cvarg{INTER\\_LINEAR}{bilinear interpolation (used by default)}\n\\cvarg{INTER\\_AREA}{resampling using pixel area relation. It may be the preferred method for image decimation, as it gives moire-free results. But when the image is zoomed, it is similar to the \\texttt{INTER\\_NEAREST} method}\n\\cvarg{INTER\\_CUBIC}{bicubic interpolation over 4x4 pixel neighborhood}\n\\cvarg{INTER\\_LANCZOS4}{Lanczos interpolation over 8x8 pixel neighborhood}\n\\end{description}}\n\\end{description}\n\nThe function \\texttt{resize} resizes an image \\texttt{src} down to or up to the specified size.\nNote that the initial \\texttt{dst} type or size are not taken into account. Instead the size and type are derived from the \\texttt{src}, \\texttt{dsize}, \\texttt{fx} and \\texttt{fy}. If you want to resize \\texttt{src} so that it fits the pre-created \\texttt{dst}, you may call the function as:\n\n\\begin{lstlisting}\n// explicitly specify dsize=dst.size(); fx and fy will be computed from that.\nresize(src, dst, dst.size(), 0, 0, interpolation);\n\\end{lstlisting}\n\nIf you want to decimate the image by factor of 2 in each direction, you can call the function this way:\n\n\\begin{lstlisting}\n// specify fx and fy and let the function to compute the destination image size.\nresize(src, dst, Size(), 0.5, 0.5, interpolation);\n\\end{lstlisting}\n\nSee also: \\cvCppCross{warpAffine}, \\cvCppCross{warpPerspective}, \\cvCppCross{remap}.\n\n\n\\cvCppFunc{warpAffine}\nApplies an affine transformation to an image.\n\n\\cvdefCpp{void warpAffine( const Mat\\& src, Mat\\& dst,\\par\n                 const Mat\\& M, Size dsize,\\par\n                 int flags=INTER\\_LINEAR,\\par\n                 int borderMode=BORDER\\_CONSTANT,\\par\n                 const Scalar\\& borderValue=Scalar());}\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image; will have size \\texttt{dsize} and the same type as \\texttt{src}}\n\\cvarg{M}{$2\\times 3$ transformation matrix}\n\\cvarg{dsize}{Size of the destination image}\n\\cvarg{flags}{A combination of interpolation methods, see \\cvCppCross{resize}, and the optional flag \\texttt{WARP\\_INVERSE\\_MAP} that means that \\texttt{M} is the inverse transformation ($\\texttt{dst}\\rightarrow\\texttt{src}$)}\n\\cvarg{borderMode}{The pixel extrapolation method, see \\cvCppCross{borderInterpolate}. When the \\\\ \\texttt{borderMode=BORDER\\_TRANSPARENT}, it means that the pixels in the destination image that corresponds to the \"outliers\" in the source image are not modified by the function}\n\\cvarg{borderValue}{A value used in case of a constant border. By default it is 0}\n\\end{description}\n\nThe function \\texttt{warpAffine} transforms the source image using the specified matrix:\n\n\\[\n\\texttt{dst}(x,y) = \\texttt{src}(\\texttt{M}_{11} x + \\texttt{M}_{12} y + \\texttt{M}_{13}, \\texttt{M}_{21} x + \\texttt{M}_{22} y + \\texttt{M}_{23})\n\\]\nwhen the flag \\texttt{WARP\\_INVERSE\\_MAP} is set. Otherwise, the transformation is first inverted with \\cvCppCross{invertAffineTransform} and then put in the formula above instead of \\texttt{M}.\nThe function can not operate in-place.\n\nSee also: \\cvCppCross{warpPerspective}, \\cvCppCross{resize}, \\cvCppCross{remap}, \\cvCppCross{getRectSubPix}, \\cvCppCross{transform}\n\n\\cvCppFunc{warpPerspective}\nApplies a perspective transformation to an image.\n\n\\cvdefCpp{void warpPerspective( const Mat\\& src, Mat\\& dst,\\par\n                      const Mat\\& M, Size dsize,\\par\n                      int flags=INTER\\_LINEAR,\\par\n                      int borderMode=BORDER\\_CONSTANT,\\par\n                      const Scalar\\& borderValue=Scalar());}\n\\begin{description}\n\\cvarg{src}{Source image}\n\\cvarg{dst}{Destination image; will have size \\texttt{dsize} and the same type as \\texttt{src}}\n\\cvarg{M}{$3\\times 3$ transformation matrix}\n\\cvarg{dsize}{Size of the destination image}\n\\cvarg{flags}{A combination of interpolation methods, see \\cvCppCross{resize}, and the optional flag \\texttt{WARP\\_INVERSE\\_MAP} that means that \\texttt{M} is the inverse transformation ($\\texttt{dst}\\rightarrow\\texttt{src}$)}\n\\cvarg{borderMode}{The pixel extrapolation method, see \\cvCppCross{borderInterpolate}. When the \\\\ \\texttt{borderMode=BORDER\\_TRANSPARENT}, it means that the pixels in the destination image that corresponds to the \"outliers\" in the source image are not modified by the function}\n\\cvarg{borderValue}{A value used in case of a constant border. By default it is 0}\n\\end{description}\n\nThe function \\texttt{warpPerspective} transforms the source image using the specified matrix:\n\n\\[\n\\texttt{dst}(x,y) = \\texttt{src}\\left(\\frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}},\n    \\frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}}\\right)\n\\]\nwhen the flag \\texttt{WARP\\_INVERSE\\_MAP} is set. Otherwise, the transformation is first inverted with \\cvCppCross{invert} and then put in the formula above instead of \\texttt{M}.\nThe function can not operate in-place.\n\nSee also: \\cvCppCross{warpAffine}, \\cvCppCross{resize}, \\cvCppCross{remap}, \\cvCppCross{getRectSubPix}, \\cvCppCross{perspectiveTransform}\n\n\\fi\n\n", "meta": {"hexsha": "2978880b8d24d9ce8cf7e390498905c9e056b475", "size": 31162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "to/lang/OpenCV-2.2.0/doc/imgproc_image_warping.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/imgproc_image_warping.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/imgproc_image_warping.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": 40.2609819121, "max_line_length": 923, "alphanum_fraction": 0.7499839548, "num_tokens": 9076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6739467757277202}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{algorithmic}\n\\usepackage{amssymb}\n\\usepackage{url}\n\\usepackage{color}\n\n\\providecommand{\\e}[1]{\\ensuremath{\\times 10^{#1}}}\n\n\\begin{document}\n\n\\title{Band Cholesky Method implementation}\n\\date{April 18, 2011}\n\\author{Bysiek Mateusz, Witan Maciej (Computer Science A/R)}\n\\maketitle\n\n\\section{Task}\n\nDesign a MATLAB function that will solve a system of equations $Ax=B$ using the\nband Cholesky method.\n\nFor each computed solution $\\tilde{x}$ of the system $Ax=b$, form the relative\nresidual error:\n\\[ \\frac{ \\|b-A\\tilde{x}\\|_2 }{ \\|A\\|_F \\|\\tilde{x}\\|_2 } \\]\n\n\\section{Introdution to the method}\n\nWe have decided to design a modular function ``Band Cholesky Solver'', or $BCS$,\nwhich will solve the problem iteratively, step by step. Divide and conquer\nmethod allowed us to tackle the problem as a team, because on one hand both\nteam members had their own part of the work to do, but on the other hand we\nthen put the algorithms together, and synchronized them. The result is presented\nbelow.\n\nFor this method, the input matrix $A$ must be symmetric positive definite, $A\n\\in \\mathbb{R}^{n \\times n}$. It also must be banded, with bandwith $w$. Matrix\n$B$ should be of size $n \\times m$.\n\n\\subsection{Fragmentation of the problem}\n\nAt first, the problem was $Ax = B$, where $B \\in \\mathbb{R}^{n \\times m}$ had\n$m$ columns: $b_1 \\ldots b_m$. The problem was splitted to $m$ smaller\nsubproblems, such that: \\[ \\forall i \\in \\{1 \\ldots m\\} : Ax_i = b_i \\]\n\nThen, we did the following four steps for each column $b_i$, and received $m$\npartial solutions.\n\n\\subsection{Cholesky decomposition}\n\nSymmetric positive definite matrix $A \\in \\mathbb{R}^{n \\times n}$, with bandwith $w$ is\ngiven to the following algorithm.\n\n\\begin{algorithmic}\n\\STATE $L=A$\n\\FOR{$j = 1:n$}\n\t\\FOR{$k = max(1,j-w):j-1$}\n\t\t\\STATE $\\lambda = min(k+w,n)$\n\t\t\\STATE $L(j:\\lambda,j) = L(j:\\lambda,j) - L(j,k) L(j:\\lambda,k)$\n\t\\ENDFOR\n\t\\STATE $\\lambda = min(j+w,n)$\n\t\\STATE $L(j:\\lambda,j) = L(j:\\lambda,j) / \\sqrt{A(j,j)}$\n\\ENDFOR\n\\STATE $L = L - triu(L, 1)$\n\\end{algorithmic}\n\nThis algorithm ends with creation of matrix $L$, such that $A = LL^T$.\nInitially, $L = A$, but L is overwritten step by step with correct values in the\nlower-triangular area. After that, values over the diagonal are cleared.\n\n\\subsection{Solution of the preliminary system of equations}\n\nBanded, lower triangular matrix $L \\in \\mathbb{R}^{n \\times n}$ with bandwidth $w$ is\ngiven to the algorithm below. Also, vector $b$ of length $n$ is given. \n\n\\begin{algorithmic}\n\\STATE $y = b$\n\\FOR{$j = 1:n$}\n\t\\FOR{$i = max(j, j-w):j-1$}\n\t\t\\STATE $y(j) = y(j) - L(j,i) y(i)$\n\t\\ENDFOR\n\t\\STATE $y(j) = y(j)/L(j,j)$\n\\ENDFOR\n\\end{algorithmic}\n\nResulting vector $y \\in \\mathbb{R}^{n \\times 1}$ is an intermediate solution\nthat is used in final calculations.\n\n\\subsection{Calculation of the final result}\n\nThe intermediate solution $y$ and upper-triangular matrix $U = L^T$ with\nbandwith $w$ is given as the input.\n\n\\begin{algorithmic}\n\\STATE $x=y$\n\\FOR{$j = n:-1:1$}\n\t\\STATE $x(j) = x(j)/U(j,j)$\n\t\\FOR{$i = max(1,j-w):j-1$}\n\t\t\\STATE $x(i) = x(i) - U(i,j) x(j)$\n\t\\ENDFOR\n\\ENDFOR\n\\end{algorithmic}\n\n\\subsection{Calculating the error}\n\nFor every result, error $e$ is equal to $\\|b-A\\tilde{x}\\|_2 /( \\|A\\|_F\n\\|\\tilde{x}\\|_2 )$.\n\n\\begin{algorithmic}\n\\STATE $e = norm(b-Ax,2) / (norm(A,\"fro\") norm(x,2))$\n\\end{algorithmic}\n\n\\section{Implementation}\n\nThe above-mentioned algorithms were implemented as separate functions.\n\n\\begin{enumerate}\n\t\\item To split problem into smaller, we simply used $for$ loop.\n\t\\item Cholesky decomposition: $cholband.m$\n\t\\item Solution of the preliminary system of equations: $lsolve.m$\n\t\\item Calculation of the final result: $usolve.m$\n\t\\item Error estimation: $residerr.m$\n\\end{enumerate}\n\nAn aggregate function $BCS$ is used to launch those operations in sequence, as\nwell as to calculate residual error.\n\nWe also have constructed the following support files\n\\begin{itemize}\n\t\\item solver that uses built-in functions, for comparison: $STS.m$\n\t\\item menu to make using using our solution easier: $BCS\\_menu.m$\n\t\\item examples: $ex1.m$ $ex2.m$ $ex3.m$ \n\\end{itemize}\n\n\\subsection{Examples}\n\nFor better presentation of how our solution works, we have included 3 examples\nin our project.\n\n\\subsubsection{First example}\n\nA is based on matrix of ones in the following way:\n\n\\begin{algorithmic}\n\\STATE $A = ones(8)$\n\\STATE $A = A-tril(A,-2)-triu(A,2)$\n\\STATE $A = A*A$\n\\STATE $A = A+eye(8)$\n\\end{algorithmic}\n\nVector b is obtained by $A \\times ones(8, 1)$, and solving for $x$ using Band\nCholesky Solver gives exacly that vector.\n\n\\[ A = \\left[\n\\begin{array}{cccccccc}\n3 & 2 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n2 & 4 & 2 & 1 & 0 & 0 & 0 & 0 \\\\\n1 & 2 & 4 & 2 & 1 & 0 & 0 & 0 \\\\\n0 & 1 & 2 & 4 & 2 & 1 & 0 & 0 \\\\\n0 & 0 & 1 & 2 & 4 & 2 & 1 & 0 \\\\\n0 & 0 & 0 & 1 & 2 & 4 & 2 & 1 \\\\\n0 & 0 & 0 & 0 & 1 & 2 & 4 & 2 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 2 & 3 \\\\\n\\end{array} \\right], \nb = \\left( \\begin{array}{c} \n6 \\\\ 9 \\\\ 10 \\\\ 10 \\\\ 10 \\\\ 10 \\\\ 9 \\\\ 6\n\\end{array} \\right), \nx = \\left( \\begin{array}{c} \n1\\\\ 1\\\\ 1\\\\ 1\\\\ 1\\\\ 1\\\\ 1\\\\ 1\n\\end{array} \\right)\n\\]\n\nBecasuse the relative error is very small, i.e $e =  6.8776\\e{-16}$ indicating\nthat some deviations in results can appear not closer than at $16^{th}$ decimal\nplace this is thanks to the matrix A being well-conditioned as condtion number \nof matrix A is very close to the unity, namely: $cond(A) = 9.2909$.\n\n\\subsubsection{Second example}\n\nA is based on product of Pascal and Hilbert matrices of size 11 in the\nfollowing way:\n\n\\begin{algorithmic}\n\\STATE $n = 11$\n\\STATE $A = hilb(n). * pascal(n)$\n\\STATE $A = A-tril(A,-2)-triu(A,2)$\n\\STATE $A = A^T * A$\n\\end{algorithmic}\n\nVector b is randolmy generated, but every time the same vector is obtained\nthanks to $randn(\"state\", 0)$ instruction:\n\n\\begin{algorithmic}\n\\STATE $randn(\"state\", 0)$\n\\STATE $b = randn(n, 1)$\n\\end{algorithmic}\n\n\\[ b = \\left(\n\\begin{array}{c}\n  -1.2248\\e{+00} \\\\\n   7.6384\\e{-01} \\\\\n  -4.1902\\e{-01} \\\\\n   5.0462\\e{-01} \\\\\n   5.7743\\e{-01} \\\\\n   5.4095\\e{-01} \\\\\n  -6.0212\\e{-01} \\\\\n  -4.2490\\e{-02} \\\\\n   1.8388\\e{-01} \\\\\n  -6.5878\\e{-02}\n\\end{array} \\right)\n\\]\n\nSolving for $x$ using Band Cholesky Solver the vector: \n\n\\[ x_{BCS} = \\left(\n\\begin{array}{c}\n  -5.9584181126\\underline{1340}\\e{+00} \\\\\n  +7.5253648228\\underline{5158}\\e{+00} \\\\\n  -1.2786997060\\underline{7469}\\e{-01} \\\\\n  -2.8406092064\\underline{3483}\\e{+00} \\\\\n  +1.5221562124\\underline{2016}\\e{+00} \\\\\n  +1.1955147494\\underline{0896}\\e{-01} \\\\\n  -5.6776267273\\underline{6740}\\e{-01} \\\\\n  +2.8906110676\\underline{8170}\\e{-01} \\\\\n  +8.9938809722\\underline{0923}\\e{-03} \\\\\n  -9.1118417264\\underline{6874}\\e{-02} \\\\\n  +4.7840224822\\underline{5803}\\e{-02}\n\\end{array} \\right)\n\\]\n\nwhereas the vector obtaied by using build-in Octave function $A \\backslash b$:\n\n\\[ x_{OCT} = \\left(\n\\begin{array}{c}\n  -5.9584181126\\underline{3058}\\e{+00} \\\\\n  +7.5253648228\\underline{7429}\\e{+00} \\\\\n  -1.2786997060\\underline{0663}\\e{-01} \\\\\n  -2.8406092064\\underline{5384}\\e{+00} \\\\\n  +1.5221562124\\underline{2985}\\e{+00} \\\\\n  +1.1955147494\\underline{1742}\\e{-01} \\\\\n  -5.6776267274\\underline{0454}\\e{-01} \\\\\n  +2.8906110677\\underline{0057}\\e{-01} \\\\\n  +8.9938809722\\underline{6832}\\e{-03} \\\\\n  -9.1118417265\\underline{2829}\\e{-02} \\\\\n  +4.7840224822\\underline{8929}\\e{-02}\n\\end{array} \\right)\n\\]\n   \nBecasuse the relative error is high, i.e $e =  3.59547536244005\\e{-12}$\nindicating that some deviations in results can appear even around $11^{th}$\ndecimal place this is due to the matrix A being ill-conditioned as condtion\nnumber of matrix A is high $cond(A) = 1.08771091073209\\e{9}$.\n\n\\subsubsection{Example no.3}\n\nA is based on inverted magic square of size 9 in the following way:\n\n\\begin{algorithmic}\n\\STATE $n=9$\n\\STATE $A=magic(n)$\n\\STATE $A=inv(A)$\n\\STATE $A=(A-triu(A,3))-tril(A,-3)$\n\\STATE $A=A^T * A$\n\\end{algorithmic}\n\nVector $b$ is randolmy generated, but every time the same vector is obtained\nthanks to $randn(\"state\", 0)$ instruction:\n\n\\begin{algorithmic}\n\\STATE $randn(\"state\", 0)$\n\\STATE $b = randn(n, 1)$\n\\end{algorithmic}\n\n\\[ b = \\left( \\begin{array}{c} \n  -1.2248\\e{+00} \\\\\n   7.6384\\e{-01} \\\\\n  -4.1902\\e{-01} \\\\\n   5.0462\\e{-01} \\\\\n   5.7743\\e{-01} \\\\\n   5.4095\\e{-01} \\\\\n  -6.0212\\e{-01} \\\\\n  -4.2490\\e{-02} \\\\\n   1.8388\\e{-01}\n\\end{array} \\right)\n\\]\n\nSolving for x using Band Cholesky Solver, the vector: \n\n\\[ x_{BCS} = \\left(\n\\begin{array}{c}\n  -8.54210613880\\underline{332}\\e{+06} \\\\\n  -3.54982602561\\underline{955}\\e{+06} \\\\\n  -2.32076201267\\underline{229}\\e{+06} \\\\\n  -2.73885343436\\underline{123}\\e{+06} \\\\\n  +2.91011321147\\underline{994}\\e{+07} \\\\\n  -6.01576142237\\underline{722}\\e{+06} \\\\\n  -6.06596003263\\underline{988}\\e{+06} \\\\\n  -3.81886151192\\underline{721}\\e{+06} \\\\\n  +1.37176843830\\underline{206}\\e{+07}\n\\end{array} \\right)\n\\]\n\nWhereas a vector obtaied by using build-in Octave function $A \\backslash b$:\n\n\\[ x_{OCT} = \\left(\n\\begin{array}{c}\n%tez tylko 3 zaznaczyc (ww sensie w calym vektorze)\n  -8.54210613880\\underline{413}\\e{+06} \\\\ \n  -3.54982602561\\underline{894}\\e{+06} \\\\\n  -2.32076201267\\underline{168}\\e{+06} \\\\\n  -2.73885343436\\underline{059}\\e{+06} \\\\\n  +2.91011321147\\underline{946}\\e{+07} \\\\\n  -6.01576142237\\underline{623}\\e{+06} \\\\\n  -6.06596003263\\underline{887}\\e{+06} \\\\\n  -3.81886151192\\underline{656}\\e{+06} \\\\\n  +1.37176843830\\underline{185}\\e{+07}\n\\end{array} \\right)\n\\]\n\nBecasuse the relative error is quite significant, i.e $e =\n1.62773786927727\\e{-13}$ indicating that some deviations in results can appear \neven around $12^{th}$ decimal place this is due to the matrix A being \nill-conditioned as condtion number of matrix A is quite high $cond(A) = \n6.17597814680354e+04$.\n\n\\subsection{How to use the function in Octave/MATLAB}\n\nUsage of aggregate function $BCS$:\n\n\\[ [result\\_matrix, error\\_vector] = BCS(source\\_matrix, parameter\\_matrix,\nbandwith\\_value) \\]\n\nThe script $BCS\\_menu$ can be used for easier access to the function.\n\n\\section{Sources}\n\n\\begin{itemize}\n\t\\item Algorithm 4.3.5, p. 155, G.H.Golub and Ch.F. Van Loan -\n\t\\emph{Matrix Computations}, Third Edition, The Johns Hopkins University Press,\n\tBaltimore and London, 1996\n\t\\item Article \\emph{Forward Substitution}, retrieved: 7th\n\tApril 2011, available at:\n\t\\url{https://ece.uwaterloo.ca/~ece204/howtos/forward/} \n\t\\item Fortuna, Macukow, Wąsowski - \\emph{Metody Numeryczne}\n\\end{itemize}\n \n\\end{document}\n", "meta": {"hexsha": "bb7b85fd594b74848c63b4cf8ee5c7bbf7b68a9e", "size": 10389, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "BandCholeskyMethod.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-numerical-methods-band-cholesky", "max_stars_repo_head_hexsha": "984124579c579e74d4b44ad9216f17d0dc61a95b", "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": "BandCholeskyMethod.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-numerical-methods-band-cholesky", "max_issues_repo_head_hexsha": "984124579c579e74d4b44ad9216f17d0dc61a95b", "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": "BandCholeskyMethod.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-numerical-methods-band-cholesky", "max_forks_repo_head_hexsha": "984124579c579e74d4b44ad9216f17d0dc61a95b", "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.939481268, "max_line_length": 88, "alphanum_fraction": 0.6679179902, "num_tokens": 3850, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6738172779560421}}
{"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{Primary decompositions}\n\nWe shall follow \\cite[\\S 3]{Eis95} and \\cite[\\S 8]{Mat80} closely.\n\n\\section{The support of a module}\nFix a ring $R$. For any $R$-module $M$ and $x \\in M$, we define the \\emph{annihilator} $\\text{ann}_R(x) := \\{ r \\in R: rx=0 \\}$; it is an ideal of $R$. Also define $\\text{ann}_R(M) := \\{r \\in R: rM=0 \\} = \\bigcap_{x \\in M} \\text{ann}_R(x)$. \\index{$\\text{ann}_R(M), \\text{ann}_R(x)$}\n\n\\begin{definition}\\index{support}\\index{SuppM@$\\Supp(M)$}\n\tThe \\emph{support} of an $R$-module $M$ is\n\t\\[ \\Supp(M) := \\left\\{ \\mathfrak{p} \\in \\Spec(R): M_{\\mathfrak{p}} \\neq 0 \\right\\}. \\]\n\\end{definition}\nLet us unwind the definition: $\\mathfrak{p} \\notin \\Supp(M)$ means that every $x \\in M$ maps to $0 \\in M_{\\mathfrak{p}}$, equivalently $\\text{ann}_R(x) \\not\\subset \\mathfrak{p}$. To test whether $\\mathfrak{p} \\notin \\Supp(M)$, we only need to check the foregoing condition for $x$ ranging over a generating set of $M$.\n\n\\begin{proposition}\n\tIf $M$ is finitely generated then $\\Supp(M) = V(\\mathrm{ann}_R(M))$; in particular it is Zariski-closed in $\\Spec(R)$.\n\\end{proposition}\n\\begin{proof}\n\tSuppose $M = Rx_1 + \\cdots + Rx_n$. Set $I_i := \\text{ann}_R(x_i)$ and observe that $\\bigcap_{i=1}^n I_i = \\text{ann}_R(M)$. Then $\\mathfrak{p} \\in \\Supp(M)$ if and only if $\\mathfrak{p} \\supset I_i$ for some $i$, that is, $\\mathfrak{p} \\in \\bigcup_{i=1}^n V(I_i)$. To conclude, note that $V(I) \\cup V(J) = V(IJ) = V(I \\cap J)$ for any ideals $I, J \\subset R$ (an easy exercise).\n\\end{proof}\n\nFinite generation is needed in the result above. Consider the $\\Z$-module $M := \\bigoplus_{a \\geq 1} \\Z/p^a \\Z$. Its support is $\\{p\\}$ but $\\mathrm{ann}(M) = \\{0\\}$.\n\n\\begin{proposition}\n\tFor an exact sequence $0 \\to M' \\to M \\to M'' \\to 0$ we have $\\Supp(M) = \\Supp(M') \\cup \\Supp(M'')$. For arbitrary direct sums we have $\\Supp(\\bigoplus_i M_i) = \\bigcup_i \\Supp(M_i)$.\n\\end{proposition}\n\\begin{proof}\n\tAgain, we use the exactness of localization for the first assertion. For $\\mathfrak{p} \\in \\Spec(R)$ we have an exact $0 \\to M'_{\\mathfrak{p}} \\to M_{\\mathfrak{p}} \\to M''_{\\mathfrak{p}} \\to 0$, hence $M_{\\mathfrak{p}} \\neq 0$ if and only if $\\mathfrak{p} \\in \\Supp(M') \\cup \\Supp(M'')$. The second assertion is obvious.\n\\end{proof}\n\nFrom an $R$-module $M$, one can build a ``field of modules'' over $\\Spec(R)$ by assigning to each $\\mathfrak{p}$ the $R_{\\mathfrak{p}}$-module $M_{\\mathfrak{p}}$, and $\\Supp(M)$ is precisely the subset of $M_{\\mathfrak{p}}$ over which the field is non-vanishing. This is how the support arises in algebraic geometry. A more precise description will require the notion of quasi-coherent sheaves on schemes.\n\n\\begin{exercise}\n\tLet $M$, $N$ be finitely generated $R$-modules. Show that $\\Supp(M \\dotimes{R} N) = \\Supp(M) \\cap \\Supp(N)$. Hint: since localization commutes with $\\otimes$, it suffices to prove that $M \\dotimes{R} N \\neq \\{0\\}$ when $M, N$ are both nonzero finitely generated modules over a local ring $R$. Nakayama's Lemma implies that $M \\dotimes{R} \\Bbbk$ and $\\Bbbk \\dotimes{R} N$ are both nonzero where $\\Bbbk$ is the residue field of $R$. Now\n\t\\[ (M \\dotimes{R} \\Bbbk) \\dotimes{\\Bbbk} (\\Bbbk \\dotimes{R} N) \\simeq M \\dotimes{R} (\\Bbbk \\dotimes{\\Bbbk} \\Bbbk) \\dotimes{R} N \\simeq (M \\dotimes{R} N) \\dotimes{R} \\Bbbk \\]\n\tis nonzero.\n\\end{exercise}\n\n\\section{Associated primes}\nThroughout this section, $R$ will be a Noetherian ring.\n\n\\begin{definition}\\index{associated prime}\\index{$\\text{Ass}(M)$}\n\tA prime ideal $\\mathfrak{p}$ is said to be an \\emph{associated prime} of an $R$-module $M$ if $\\text{ann}_R(x) = \\mathfrak{p}$ for some $x \\in M$; equivalently, $R/\\mathfrak{p}$ embeds into $M$. Denote the set of associated primes of $M$ by $\\text{Ass}(M)$.\n\\end{definition}\n\n\\begin{example}\n\tFor the $\\Z$-module $M := \\Z/n\\Z$ with $n \\in \\Z_{> 1}$, one easily checks that $\\text{Ass}(M)$ is the set of prime factors of $n$.\n\\end{example}\n\n\\begin{lemma}\\label{prop:Ass-maximal}\n\tConsider the set $\\mathcal{S} := \\{ \\mathrm{ann}_R(x) : x \\in M, \\; x \\neq 0 \\}$ of ideals, partially ordered by inclusion. Every maximal element in $\\mathcal{S}$ is prime.\n\\end{lemma}\n\\begin{proof}\n\tLet $\\mathfrak{p} = \\text{ann}_R(x)$ be a maximal element of $\\mathcal{S}$ and suppose $ab \\in \\mathfrak{p}$. If $b \\notin \\mathfrak{p}$, then\n\t\\[ bx \\neq 0, \\quad abx = 0, \\quad R \\neq \\text{ann}_R(bx) \\supset \\text{ann}_R(x) = \\mathfrak{p}. \\]\n\tHence $a \\in \\text{ann}_R(bx) = \\mathfrak{p}$ by the maximality of $\\mathfrak{p}$ in $\\mathcal{S}$.\n\\end{proof}\n\n\\begin{definition}\\index{zero divisor}\n\tCall $r \\in R$ a \\emph{zero divisor} on $M$ if $rx=0$ for some $x \\in M \\smallsetminus \\{0\\}$.\n\\end{definition}\n\n\\begin{theorem}\\label{prop:Ass-properties}\n\tLet $M$ be an $R$-module.\n\t\\begin{enumerate}[(i)]\n\t\t\\item We have $M = \\{0\\}$ if and only if $\\mathrm{Ass}(M) = \\emptyset$.\n\t\t\\item The union of all $\\mathfrak{p} \\in \\mathrm{Ass}(M)$ equals the set of zero divisors on $M$.\n\t\t\\item For any multiplicative subset $S \\subset R$, we have\n\t\t\t\\[ \\mathrm{Ass}(M[S^{-1}]) = \\left\\{ \\mathfrak{p}[S^{-1}] : \\mathfrak{p} \\in \\mathrm{Ass}(M), \\; \\mathfrak{p} \\cap S = \\emptyset \\right\\} . \\]\n\t\t\\item If $0 \\to M' \\to M \\to M''$ is exact, then $\\mathrm{Ass}(M') \\subset \\mathrm{Ass}(M) \\subset \\mathrm{Ass}(M') \\cup \\mathrm{Ass}(M'')$.\n\t\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n\t\\begin{asparaenum}[(i)]\n\t\\item Clearly $\\text{Ass}(\\{0\\}) = \\emptyset$. If $M \\neq 0$, the set $\\mathcal{S}$ in Lemma \\ref{prop:Ass-maximal} is then nonempty, hence contains a maximal element $\\mathfrak{p}$ because $R$ is Noetherian; this yields $\\mathfrak{p} \\in \\text{Ass}(M)$.\n\t\n\t\\item Elements of any $\\mathfrak{p} \\in \\text{Ass}(M)$ are all zero divisors by the very definition of associated primes. Conversely, if $r \\in \\text{ann}_R(x)$ for some $x \\in M \\smallsetminus \\{0\\}$, there must exist some maximal element $\\mathfrak{p}$ of $\\mathcal{S}$ with $\\mathfrak{p} \\supset \\text{ann}_R(x)$ as $R$ is Noetherian; so $\\mathfrak{p}$ is the required associated prime containing $r$.\n\t\n\t\\item If $\\mathfrak{p} \\in \\Spec(R)$, $\\mathfrak{p} \\cap S = \\emptyset$ and there is some $R/\\mathfrak{p} \\hookrightarrow M$, then\n\t\\[ \\{0\\} \\neq R[S^{-1}]/\\mathfrak{p}[S^{-1}] \\simeq (R/\\mathfrak{p})[S^{-1}] \\hookrightarrow M[S^{-1}] \\]\n\tby the exactness of localizations, hence $\\mathfrak{p}[S^{-1}] \\in \\text{Ass}(M[S^{-1}])$. Conversely, every element of $\\text{Ass}(M[S^{-1}])$ has the form $\\mathfrak{p}[S^{-1}]$ for some $\\mathfrak{p} \\in \\Spec(R)$ disjoint from $S$. Also recall that $\\mathfrak{p}$ equals the preimage of $\\mathfrak{p}[S^{-1}]$ under $R \\to R[S^{-1}]$. There exist $x \\in M$ and $s \\in S$ such that $\\mathfrak{p}[S^{-1}] = \\text{ann}_{R[S^{-1}]}(x/s) = \\text{ann}_{R[S^{-1}]}(x)$. Ideals in a Noetherian ring being finitely generated, we infer that $\\exists t \\in S$ with $\\mathfrak{p} \\subset \\text{ann}_R(tx)$. It remains to show $\\mathfrak{p} = \\text{ann}_R(tx)$. If $rtx=0$ for some $r \\in R$, then $r$ maps into $r/1 \\in \\mathfrak{p}[S^{-1}] = \\text{ann}_{R[S^{-1}]}(x)$; thus $r \\in \\mathfrak{p}$.\n\n\t\\item It suffices to treat the second $\\subset$. Suppose that $\\mathfrak{p} \\in \\text{Ass}(M)$ and $R/\\mathfrak{p} \\simeq N$ for some submodule $N \\subset M$. Identify $M'$ with $\\Ker(M \\to M'')$. If $M' \\cap N = \\{0\\}$ then $R/\\mathfrak{p} \\simeq N \\hookrightarrow M''$, so $\\mathfrak{p} \\in \\text{Ass}(M'')$. If there exists $x \\in M' \\cap N \\subset N$ with $x \\neq 0$, then we have $\\text{ann}_R(x) = \\mathfrak{p}$ since $N \\simeq R/\\mathfrak{p}$ and $\\mathfrak{p}$ is prime; in this case $\\mathfrak{p} \\in \\text{Ass}(M')$.\n\t\\end{asparaenum}\n\\end{proof}\n\nWe remark that $0 \\to M' \\to M \\to M'' \\to 0$ being exact does not imply $\\text{Ass}(M) = \\text{Ass}(M') \\cup \\text{Ass}(M'')$. To see this, consider $R=\\Z$ and $0 \\to \\Z \\xrightarrow{p} \\Z \\to \\Z/p\\Z \\to 0$ for some prime number $p$.\n\n\\begin{exercise}\n\tShow that $\\text{Ass}(M_1 \\oplus M_2) = \\text{Ass}(M_1) \\cup \\text{Ass}(M_2)$.\n\\end{exercise}\n\n\\begin{theorem}\\label{prop:Supp-Ass}\n\tFor every $R$-module $M$ we have $\\Supp(M) = \\bigcup_{\\mathfrak{p} \\in \\mathrm{Ass}(M)} V(\\mathfrak{p})$, in particular $\\mathrm{Ass}(M) \\subset \\Supp(M)$.\tFurthermore, every minimal element of $\\Supp(M)$ with respect to inclusion is actually a minimal element of $\\mathrm{Ass}(M)$.\n\\end{theorem}\n\\begin{proof}\n\tFor any prime $\\mathfrak{q}$ we have $M_{\\mathfrak{q}} \\neq 0 \\iff \\text{Ass}(M_{\\mathfrak{q}}) \\neq \\emptyset$, and the latter condition holds precisely when there exists $\\mathfrak{p} \\in \\text{Ass}(M)$ with $\\mathfrak{p} \\cap (R \\smallsetminus \\mathfrak{q}) = \\emptyset$, i.e. $\\mathfrak{q} \\supset \\mathfrak{p}$. This proves the first assertion. The second assertion is a direct consequence.\n\\end{proof}\n\nObserve that if $\\mathfrak{p} \\in \\Supp(M)$, then $\\mathfrak{q} \\supset \\mathfrak{p} \\implies \\mathfrak{q} \\in \\Supp(M)$: the reason is that\n\\begin{gather}\\label{eqn:localization-in-stages}\n\tM_{\\mathfrak{p}} = (M_{\\mathfrak{q}})_{\\mathfrak{p}R_{\\mathfrak{q}}}\n\\end{gather}\nthus the occurrence of non-minimal elements in $\\Supp(M)$ is unsurprising. In contrast, the non-minimal elements in $\\text{Ass}(M)$ are somehow mysterious. These non-minimal associated primes are called \\emph{embedded primes}. \\index{embedded prime}\n\n\\begin{exercise}\n\tProve the formula \\eqref{eqn:localization-in-stages} of ``localization in stages''.\n\\end{exercise}\n\nHereafter we impose finite generation on $M$. This implies $M$ is Noetherian.\n\\begin{theorem}\n\tLet $M$ be a finitely generated $R$-module. There exists a chain $M = M_n \\supset M_{n-1} \\supset \\cdots \\supset M_0 = \\{0\\}$ of submodules such that for every $0 < i \\leq n$, the subquotient $M_i/M_{i-1}$ is isomorphic to $R/\\mathfrak{p}_i$ for some prime ideal $\\mathfrak{p}_i$.\n\t\n\tFurthermore we have $\\mathrm{Ass}(M) \\subset \\{\\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n \\}$; in particular $\\mathrm{Ass}(M)$ is a finite set.\n\\end{theorem}\n\\begin{proof}\n\tAssume $M \\supsetneq M_0 := \\{0\\}$. There exists $\\mathfrak{p}_1 \\in \\text{Ass}(M)$ together with a submodule $M_1 \\subset M$ isomorphic to $R/\\mathfrak{p}_1$. Furthermore $\\text{Ass}(M_1) = \\text{Ass}(R/\\mathfrak{p}_1) = \\{ \\mathfrak{p}_1\\}$ as easily seen. Hence the Theorem \\ref{prop:Ass-properties} entails $\\text{Ass}(M) \\subset \\{\\mathfrak{p}_1\\} \\cup \\text{Ass}(M/M_1)$.\n\n\tIf $M_1 = M$ we are done. Otherwise we start over with $M/M_1$, finding $M_1 \\subset M_2 \\subset M$ with $M_2/M_1 \\simeq R/\\mathfrak{p}_2$ where $\\mathfrak{p}_2 \\in \\text{Ass}_R(M/M_1)$, and so forth. This procedure terminates in finite steps since $M$ is Noetherian.\n\\end{proof}\n\n\\section{Primary and coprimary modules}\nThe classical framework of primary decompositions concerns ideals, but it is advantageous to allow modules here. As before, the ring $R$ is Noetherian.\n\n\\begin{definition}\\index{coprimary module}\\index{primary module}\n\tAn $R$-module $M$ is called \\emph{coprimary} if $\\text{Ass}(M)$ is a singleton. A submodule $N \\subsetneq M$ is called a $\\mathfrak{p}$-\\emph{primary} submodule if $M/N$ is coprimary with associated prime $\\mathfrak{p} \\in \\Spec(R)$.\n\\end{definition}\n\n\\begin{proposition}\\label{prop:coprimary-locnil}\n\tThe following are equivalent for a nonzero $R$-module $M$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item $M$ is coprimary;\n\t\t\\item for every zero divisor $r \\in R$ for $M$ and every $x \\in M$, there exists $n \\geq 1$ such that $r^n x = 0$.\n\t\\end{enumerate}\n\\end{proposition}\nThe condition (ii) is usually called the local-nilpotency of $r$ on $M$. When $M = R/I$ for some ideal $I$, it translates into: all zero divisors of the ring $R/I$ are nilpotent.\n\\begin{proof}\n\t(i) $\\implies$ (ii): Suppose $\\text{Ass}(M) = \\{ \\mathfrak{p}\\}$ and $x \\in M \\smallsetminus \\{0\\}$. From $\\emptyset \\neq \\text{Ass}(Rx) \\subset \\text{Ass}(M)$ we infer that $\\text{Ass}(Rx) = \\{\\mathfrak{p}\\}$, thus by Theorem \\ref{prop:Supp-Ass} we see $V(\\mathfrak{p}) = \\Supp(Rx) = V(\\text{ann}(Rx))$. Hence $\\mathfrak{p} = \\sqrt{\\text{ann}(Rx)}$. This implies (ii) by the definition of $\\sqrt{\\hspace{5pt}}$.\n\t\n\t(ii) $\\implies$ (i): It is routine to check that\n\t\\[ \\mathfrak{p} := \\left\\{ r \\in R: \\forall x \\in M \\; \\exists n \\geq 1, \\; r^n x = 0 \\right\\} \\]\n\tis an ideal of $R$. For every $\\mathfrak{q} \\in \\text{Ass}(M)$ there exists $x \\in M$ with $\\text{ann}_R(x) = \\mathfrak{q}$. Every $r \\in \\mathfrak{p}$ has some power falling in $\\mathfrak{q}$, thus $\\mathfrak{p} \\subset \\mathfrak{q}$. Conversely, (ii) and Theorem \\ref{prop:Ass-properties} imply $\\mathfrak{q} = \\text{ann}_R(x) \\subset \\mathfrak{p}$. From $\\mathfrak{q}=\\mathfrak{p}$ we conclude $M$ is coprimary with the unique associated prime $\\mathfrak{p}$.\n\\end{proof}\n\n\\begin{exercise}[Classical definition of primary ideals]\\label{ex:primary-ideal}\n\tLet $I$ be a proper ideal of $R$. Show that $R/I$ is coprimary if and only if the following holds:\n\t\\[ \\forall a,b \\in R, \\; (ab \\in I) \\wedge (a \\notin I) \\implies \\exists n \\geq 1, \\; b^n \\in I. \\]\n\tIn this case we also say $I$ is a \\emph{primary ideal} of $R$. Show that $\\{\\sqrt{I}\\} = \\text{Ass}(R/I)$ if $I$ is a primary ideal. Hint: apply Proposition \\ref{prop:coprimary-locnil}.\n\\end{exercise}\n\n\\begin{exercise}\\label{ex:maximal-primary}\n\tLet $\\mathfrak{m}$ be a maximal ideal of $R$. Show that every ideal $I \\subsetneq R$ containing some power of $\\mathfrak{m}$ is primary, and $\\text{Ass}(R/I) = \\{\\mathfrak{m}\\}$. Hint: show that $\\mathfrak{m}$ is the only prime ideal containing $I = \\text{ann}_R(R/I)$.\n\\end{exercise}\n\n\\begin{lemma}\\label{prop:intersection-primary}\n\tLet $\\mathfrak{p} \\in \\Spec(R)$ and $N_1, N_2 \\subset M$ are $\\mathfrak{p}$-primary submodules. Then $N_1 \\cap N_2$ is a $\\mathfrak{p}$-primary submodule of $M$.\n\\end{lemma}\n\\begin{proof}\n\tWe have $M/N_1 \\cap N_2 \\hookrightarrow M/N_1 \\oplus M/N_2$. Since $N_1 \\cap N_2 \\neq M$, we have\n\t\\[ \\emptyset \\neq \\text{Ass}(M/N_1 \\cap N_2) \\subset \\text{Ass}(M/N_1) \\cup \\text{Ass}(M/N_2) = \\{\\mathfrak{p}\\} \\]\n\tby Theorem \\ref{prop:Ass-properties}.\n\\end{proof}\n\n\\section{Primary decomposition: the main theorem}\nWe still assume $R$ Noetherian and fix a finitely generated $R$-module $M$.\n\n\\begin{theorem}[Lasker--Noether]\\label{prop:primary-decomp}\\index{primary decomposition}\n\tLet $N \\subsetneq M$ be an $R$-submodule. Then we can express $N$ as\n\t\\[ N = M_1 \\cap \\cdots \\cap M_n, \\]\n\tfor some $n \\geq 1$ and primary $R$-submodules $M_i$, say with $\\mathrm{Ass}(M/M_i) = \\{\\mathfrak{p}_i\\}$ for $i = 1, \\ldots, n$. Such a decomposition is called a \\emph{primary decomposition} of $N$. We say it is \\emph{irredundant} if none of the $M_i$ can be dropped, and \\emph{minimal} if there is no such decomposition with fewer terms.\n\t\\begin{enumerate}[(i)]\n\t\t\\item We have $\\mathrm{Ass}(M/N) \\subset \\{ \\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n \\}$, equality holds when the decomposition is irredundant.\n\t\t\\item If the decomposition is minimal, then for every $\\mathfrak{p} \\in \\mathrm{Ass}(M/N)$ there exists a unique $1 \\leq i \\leq n$ with $\\mathfrak{p} = \\mathfrak{p}_i$; consequently $n = |\\mathrm{Ass}(M/N)|$.\n\t\t\\item Consider a primary decomposition of $N$. Let $S \\subset R$ be any multiplicative subset, and assume without loss of generality that $\\mathfrak{p}_1, \\ldots, \\mathfrak{p}_m$ are the primes among $\\{\\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n \\}$ which are disjoint from $S$, then $m \\geq 1 \\iff N[S^{-1}] \\subsetneq M[S^{-1}]$ and\n\t\t\\[ N[S^{-1}] = M_1[S^{-1}] \\cap \\cdots \\cap M_m[S^{-1}] \\]\n\t\tis a primary decomposition of the $R[S^{-1}]$-submodule $N[S^{-1}] \\subsetneq M[S^{-1}]$; this decomposition of $N[S^{-1}]$ is minimal if the one for $N$ is.\n\t\\end{enumerate}\n\\end{theorem}\nNote that the ``irredundant'' condition in \\cite[(8.D)]{Mat80} corresponds to minimality here. The rings whose ideals all have primary decompositions are called \\emph{Laskerian rings}, thus part (i) of the Theorem says Noetherian implies Laskerian, but there exist non-Noetherian examples.\n\n\\begin{proof}\n\tEstablish the existence of primary decompositions first. Replacing $M$ by $M/N$, we may assume $N = \\{0\\}$ from the outset. We claim that\n\t\\begin{gather}\\label{eqn:Lasker-Noether-aux}\n\t\t\\forall \\mathfrak{p} \\in \\text{Ass}(M), \\; \\exists Q(\\mathfrak{p}) \\subset M, \\;\n\t\t\\left\\{ \\begin{array}{l}\n\t\t\tQ(\\mathfrak{p}) \\text{ is } \\mathfrak{p}\\text{-primary}, \\\\\n\t\t\t\\text{Ass}(Q(\\mathfrak{p})) = \\text{Ass}(M) \\smallsetminus \\{ \\mathfrak{p} \\}. \n\t\t\\end{array}\\right.\n\t\\end{gather}\n\tGranting this, $Q := \\bigcap_{\\mathfrak{p} \\in \\text{Ass}(M)} Q(\\mathfrak{p})$ yields the required decomposition since $\\text{Ass}(M)$ is finite and $\\text{Ass}(Q) = \\emptyset$.\n\t\n\tEstablish \\eqref{eqn:Lasker-Noether-aux} as follows. Put $\\Psi := \\{ \\mathfrak{p} \\}$. By Zorn's Lemma\\index{Zorn's Lemma} we get a maximal element $Q(\\mathfrak{q})$ from the set\n\t\\[ \\emptyset \\neq \\left\\{  Q \\subset M: \\text{submodule}, \\; \\text{Ass}(Q) \\subset \\text{Ass}(M) \\smallsetminus \\Psi \\right\\} \\]\n\twhich is partially ordered by inclusion (details omitted, and you may also use the Noetherian property of $M$). Since\n\t\\[ \\text{Ass}(M) \\subset \\text{Ass}(M/Q(\\mathfrak{p})) \\cup \\text{Ass}(Q(\\mathfrak{p})), \\]\n\tit suffices to show $\\text{Ass}(M/Q(\\mathfrak{p})) \\subset \\Psi$.  Let $\\mathfrak{q} \\in \\text{Ass}(M/Q(\\mathfrak{p}))$ so that there exists $M \\supset Q' \\supset Q(\\mathfrak{p})$ with $Q'/Q(\\mathfrak{p}) \\simeq R/\\mathfrak{q}$. Since $\\text{Ass}(Q') \\subset \\text{Ass}(Q(\\mathfrak{p})) \\cup \\{ \\mathfrak{q} \\}$, maximality forces $\\mathfrak{q} \\in \\Psi$ (otherwise $\\text{Ass}(Q') \\subset \\text{Ass}(M) \\smallsetminus \\Psi$), whence \\eqref{eqn:Lasker-Noether-aux}. Now we turn to the properties (i) --- (iii).\n\t\n\t\\begin{asparaenum}[(i)]\n\t\t\\item The obvious embedding\n\t\t\\[ M/N \\hookrightarrow \\bigoplus_{i=1}^n M/M_i \\]\n\t\ttogether with Theorem \\ref{prop:Ass-properties} yield $\\text{Ass}(M/N) \\subset \\bigcup_{i=1}^n \\text{Ass}(M/M_i) = \\{ \\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n \\}$.\n\t\t\n\t\tNow assume the given primary decomposition is irredundant, we have\n\t\t\t\\begin{align*}\n\t\t\t\t\\{0\\} & \\neq \\frac{M_2 \\cap \\cdots \\cap M_n}{N} = \\frac{M_2 \\cap \\cdots \\cap M_n}{M_1 \\cap (M_2 \\cap \\cdots \\cap M_n)} \\\\\n\t\t\t\t& \\simeq \\frac{M_1 + M_2 \\cap \\cdots \\cap M_n}{M_1} \\hookrightarrow M/M_1.\n\t\t\t\\end{align*}\n\t\t\tThus $\\text{Ass}(M/N)$ contains $\\text{Ass}((M_2 \\cap \\cdots \\cap M_n)/N) = \\{\\mathfrak{p}_1\\}$. Same for $\\mathfrak{p}_2, \\ldots, \\mathfrak{p}_n$.\n\t\t\\item Suppose $N = M_1 \\cap \\cdots \\cap M_n$ is an irredundant primary decomposition, so that $\\text{Ass}(M/N) = \\{ \\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n \\}$. If $\\mathfrak{p}_i = \\mathfrak{p}_j$ for some $1 \\leq i \\neq j \\leq n$, Lemma \\ref{prop:intersection-primary} will imply that $M_i \\cap M_j$ is primary, leading to a shorter primary decomposition. This is impossible when the primary decomposition is minimal.\n\t\t\\item Suppose $S \\cap \\mathfrak{p}_i = \\emptyset$ (equivalently, $i \\leq m$). By Theorem \\ref{prop:Ass-properties} and the exactness of localization, $M_i[S^{-1}] \\subset M[S^{-1}]$ will be $\\mathfrak{p}_i[S^{-1}]$-primary. On the other hand $S \\cap \\mathfrak{p}_i \\neq \\emptyset$ implies $\\text{Ass}((M/M_i)[S^{-1}]) = \\emptyset$ by Theorem \\ref{prop:Ass-properties}, thus $M[S^{-1}]/M_i[S^{-1}] = 0$. Since localization respects intersections, we obtain\n\t\t\\[ N[S^{-1}] = \\bigcap_{i=1}^m M_i[S^{-1}]. \\]\n\t\tIn particular $N[S^{-1}]$ is proper if and only if $m \\geq 1$.\n\t\n\t\tIt remains to show $\\text{Ass}(M[S^{-1}]/N[S^{-1}])$ has $m$ elements if the original primary decomposition is minimal. Indeed, that set is just $\\{ \\mathfrak{p}[S^{-1}] : \\mathfrak{p} \\in \\text{Ass}(M/N), \\; \\mathfrak{p} \\cap S = \\emptyset \\}$ by Theorem \\ref{prop:Ass-properties}, which equals $\\{ \\mathfrak{p}_1[S^{-1}], \\ldots, \\mathfrak{p}_m[S^{-1}] \\}$ (distinct) by (ii).\n\t\\end{asparaenum}\n\\end{proof}\n\nA natural question arises: to what extent are minimal primary decompositions unique? For those $M_i$ whose associated primes are minimal in $\\text{Ass}(M/N)$, the answer turns out to be positive.\n\n\\begin{corollary}\\label{prop:p-primary-component}\n\tLet $N = M_1 \\cap \\cdots \\cap M_n$ be a minimal primary decomposition of $N \\subsetneq M$. Suppose that $M_1$ is $\\mathfrak{p}$-primary where $\\mathfrak{p} := \\mathfrak{p}_1$ is a minimal element in $\\mathrm{Ass}(M/N)$, then $M_1$ equals the preimage of $N_{\\mathfrak{p}}$ under $M \\to M_{\\mathfrak{p}}$. Call it the $\\mathfrak{p}$-\\emph{primary component} of $N$.\n\\end{corollary}\n\\begin{proof}\n\tRecall the proof of Theorem \\ref{prop:primary-decomp}, especially the part (iii); here we localize with respect to $S := R \\smallsetminus \\mathfrak{p}$. The minimality assumption entails\n\t\\[ N_{\\mathfrak{p}} = M_{1, \\mathfrak{p}} \\subset M_{\\mathfrak{p}}. \\]\n\tIt remains to show that the preimage of $M_{1, \\mathfrak{p}}$ under $M \\to M_{\\mathfrak{p}}$ equals $M_1$, in other words the injectivity of the natural map $M/M_1 \\to (M/M_1)_{\\mathfrak{p}} = M_{\\mathfrak{p}}/M_{1, \\mathfrak{p}}$. Indeed, $\\bar{x} \\in M/M_1$ maps to $0$ if and only if there exists $s \\notin \\mathfrak{p}$ with $s\\bar{x}=0$, but Theorem \\ref{prop:Ass-properties} implies that the zero divisors of $M/M_1$ must lie in $\\mathfrak{p}$.\n\\end{proof}\n\nIt follows that the non-uniqueness of minimal primary decompositions can only arise from embedded primes in $\\text{Ass}(M/N)$.\n\n\\section{Examples and remarks}\nPrimary decompositions are most often applied in the case $M = R$ and $N = I$ is a proper ideal. The goal is to express $I$ as an intersection of primary ideals. To begin with, let us take $R = \\Z$. Observations:\n\\begin{itemize}\n\t\\item The primary ideals of $R$ take the form $(p)^n$, where $n \\geq 1$ and $p$ is a prime number or zero. This may be deduced from Exercise \\ref{ex:primary-ideal} or directly from definitions.\n\t\\item The irredundant primary decompositions of $\\Z/n\\Z$, for $n > 1$, corresponds to the factorization of $n$ into prime-powers. There are no embedded primes in this case; the irredundant primary decomposition is unique and automatically minimal.\n\\end{itemize}\n\n\\begin{exercise}\n\tJustify the foregoing assertions.\n\\end{exercise}\n\n\\begin{figure}[h]\n\t\\centering \\includegraphics[height=170pt]{ELasker.jpg} \\\\ \\vspace{1em}\n\t\\begin{minipage}{0.7\\textwidth}\n\t\t\\small Emanuel Lasker (1868--1941) first obtained the primary decomposition for finitely generated $\\Bbbk$-algebras and the algebras of convergent power series in 1905. His method involves techniques from \\emph{elimination theory}. His result is then generalized and rewritten by Emmy Noether in 1921, in which the ascending chain condition plays a pivotal role. Lasker is best known for being the World Chess Champion from 1894 to 1921. (Picture taken from \\href{https://commons.wikimedia.org/w/index.php?curid=5676713}{Wikimedia Commons})\n\t\\end{minipage}\n\\end{figure}\n\nTherefore one can regard primary decompositions as a generalization of factorization of integers, now performed on the level of ideals. The most important case is $R = \\Bbbk[X_1, \\ldots, X_n]$ (fix some field $\\Bbbk$), as it is naturally connected to classical problems in algebraic geometry. Let us consider a simple yet non-trivial example from \\cite[\\S 3]{Eis95}.\n\n\\begin{example}\n\tTake $R=\\Bbbk[X,Y]$ and $I = (X^2, XY)$. The reader is invited to check that\n\t\\[ I = (X) \\cap (X^2, XY, Y^2) = (X) \\cap (X^2, Y). \\]\n\tClaim: this gives two minimal primary decompositions of $I$. The ideal $(X)$ is prime, hence primary. In fact, $(X^2, XY, Y^2) = (X,Y)^2$ and $(X^2, Y)$ are both primary ideals associated to the maximal ideal $(X, Y)$. This follows either by direct arguments or by Exercise \\ref{ex:maximal-primary}, noting that $(X,Y)^2 = (X^2, XY, Y^2)$ is contained in $(X^2, Y)$. The embedded prime $(X,Y)$ is seen to be responsible non-uniqueness of primary decompositions.\n\t\n\tTo see the geometry behind, recall that $V(\\mathfrak{a}) \\cup V(\\mathfrak{b}) = V(\\mathfrak{a}\\mathfrak{b}) = V(\\mathfrak{a} \\cap \\mathfrak{b})$ for any ideals $\\mathfrak{a}, \\mathfrak{b}$, thus expressing $I$ as an intersection means breaking the corresponding geometric object into a union of simpler pieces. Also recall that for an ideal $I \\subset \\Bbbk[X,Y]$, the points in $\\bigcap_{f \\in I} \\{f=0\\}$ are in bijection with the maximal ideals lying over $I$, at least for $\\Bbbk$ algebraically closed (Nullstellensatz). Thus we may interpret these primary decompositions as equalities among ``geometric objects'' embedded in $\\Bbbk^2$:\n\t\\[ \\left\\{ X^2=0, XY=0 \\right\\} = \\begin{cases} \\left\\{ X = 0 \\right\\} \\cup \\left\\{X^2=XY=Y^2=0 \\right\\} \\\\ \\left\\{ X = 0 \\right\\} \\cup \\left\\{ X^2=Y=0 \\right\\}. \\end{cases} \\]\n\t\\begin{enumerate}\n\t\t\\item The geometric object defined by $X=0$ inside $\\Bbbk^2$ is certainly the $Y$-axis: the regular functions living on this space form the $\\Bbbk$-algebra $\\Bbbk[X,Y]/(X) = \\Bbbk[Y]$.\n\t\t\\item The geometric object defined by $X^2=XY=Y^2=0$ looks ``physically'' like the origin $(0,0)$, but the $\\Bbbk$-algebra of ``regular functions'' (in an extended sense) living on it equals $\\Bbbk[X,Y]/(X^2,XY,Y^2)$: by restricting a polynomial function $f(X,Y)$ to this ``thickened point'', we see not only $f(0,0)$ but also $\\frac{\\partial f}{\\partial x}(0,0)$ and $\\frac{\\partial f}{\\partial y}(0,0)$. In other words, we shall view $X^2=XY=Y^2=0$ as the first-order infinitesimal neighborhood of $(0,0) \\in \\Bbbk^2$.\n\t\t\\item In a similar vein, $X^2=Y=0$ physically defines $(0,0)$, but by restricting $f$ to that thickened point, we retrieve $f(0,0)$ as well as $\\frac{\\partial f}{\\partial x}(0,0)$. Therefore we obtain the first-order infinitesimal neighborhood of $0$ inside the $X$-axis.\n\t\\end{enumerate}\n\n\tBoth decomposition says that we obtain the $Y$-axis together with first-order infinitesimal information at the origin $(0,0)$. This is also a nice illustration of the use of nilpotent elements in scheme theory.\n\\end{example}\n\n\\begin{example}[Symbolic powers]\n\tLet $\\mathfrak{p}$ be a prime ideal in a Noetherian ring $R$ and fix $n \\geq 1$. Observe that $\\mathfrak{p}$ is the unique minimal element in $\\Supp(R/\\mathfrak{p}^n) = V(\\mathfrak{p}^n)$. By Theorem \\ref{prop:Supp-Ass} $\\mathfrak{p} \\in \\text{Ass}(R/\\mathfrak{p}^n)$, so it makes sense to denote by $\\mathfrak{p}^{(n)}$ the $\\mathfrak{p}$-primary component (Corollary \\ref{prop:p-primary-component}) of $\\mathfrak{p}^n$, called the $n$-th \\emph{symbolic power} of $\\mathfrak{p}$. In general $\\mathfrak{p}^{(n)} \\supsetneq \\mathfrak{p}^n$. For a nice geometric interpretation of symbolic powers due to Nagata and Zariski, we refer to \\cite[\\S 3.9]{Eis95}.\n\\end{example}\n\nGetting primary decomposition of ideals in polynomial algebras is a non-trivial task. Thanks to the pioneers in computational commutative algebra, this can now achieved on your own computer, eg. by the open-source \\href{http://www.sagemath.org}{SageMath} system.\\index{SageMath}", "meta": {"hexsha": "a491188368e45b5ea120e241d9b4dff91a4ee53b", "size": 27119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "YAlg3-2.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-2.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-2.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": 97.2007168459, "max_line_length": 790, "alphanum_fraction": 0.6780117261, "num_tokens": 9740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673223709251, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.6738172763998435}}
{"text": "\\section{Introduction}\n\\label{sec:GEVD_overview}\n\nIn this chapter, we search for a linear combination of channels that yields\nan output signal $y_t$ useful for sharp wave-ripple (SWR) detection. More\nprecisely, we search for a vector $\\w \\in \\reals^C$ in channel (or electrode)\nspace to project the samples $\\z_t \\in \\reals^C$ on, so that the signal\n%\n\\begin{equation}\n\\label{eq:linear}\ny_t = \\w^T \\z_t\n\\end{equation}\n%\nhas high variance (or power) during SWR events, and low variance outside\nthem. This principle is illustrated with a two-dimensional toy dataset in\n\\cref{fig:GEVD_principle}. (We can then detect SWR events using threshold\ncrossings of the envelope of $y_t$, as discussed in \\cref{ch:BPF}).\n\n\n\\begin{figure}\n\\includegraphics[width=0.6\\textwidth]{GEVD_principle_scatter}\n\\includegraphics[width=0.6\\textwidth]{GEVD_principle_strips}\n\\captionn{Signal-to-noise maximisation via the GEVD}{Toy example to\nillustrate the generalised eigenvalue decomposition (GEVD) principle for\nsignal detection. \\emph{Left}: multi-channel time-series data plotted in\n`phase space' (meaning without time axis), with blue dots representing\nsamples where the signal was present, and orange dots representing samples\nwhere it was not. Actually toy data drawn from two 2-dimensional Gaussian\ndistributions with different covariance matrices. Red vector: first\neigenvector of the signal covariance matrix (also known as the first\nprincipal component). Green vector: first generalised eigenvector of the\nsignal and noise covariance matrices. \\emph{Right}: Projection of both data\nsets on both the ordinary eigenvector (``PCA'') and the generalised\neigenvector (``GEVD''). The ratio of the projected signal data variance\nversus the projected noise data variance is maximised for the GEVD case.}\n\\label{fig:GEVD_principle}\n\\end{figure}\n\n\nWe assume the input signal $\\z_t$ to be zero mean. This is achieved with a\nstraightforward preprocessing step in offline SWR detection, and can be\napproximated in online SWR detection by keeping track of a running mean of\n$\\z_t$, such as an exponentially weighted moving average.\n\nThis is a supervised (or data-driven) method: we need to have access to\ntraining data $\\z\\train_t$, and an associated labelling $x\\train_t$ which\nmarks when there is an SWR event present in $\\z\\train_t$, and when there is\nnot. These can then be used to find a good weight vector $\\w$, that can then\nbe applied to detect SWR events in unlabelled data $\\z\\test_t$.\n\nThe algorithm as described above is also a purely spatial filtering method\n(at each timestep $t$, only current information from the different channels\nis used in calculating the output $y_t$, without incorporating temporal\ninformation from previous timesteps $t_p < t$). The algorithm can be adapted\nto also incorporate temporal information, by defining a vector\n$\\z^\\text{stack}_t \\in\n\\reals^{C \\cdot P}$, which consists of stacked sample vectors (each\nconsisting of $C$ channels) from $P$ different timesteps $t_p \\leq t$. The\nlinear weights $\\w^\\text{stack} \\in \\reals^{C \\cdot P}$ are then calculated\nin the same way as for $\\w$.\n\nThe following sections describes how the vector $\\w$ can be found.\n", "meta": {"hexsha": "4a597750a0d07854d49298583cdca5c3b9193d26", "size": 3172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Scraps/GEVD/Intro.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/Scraps/GEVD/Intro.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/Scraps/GEVD/Intro.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": 50.3492063492, "max_line_length": 77, "alphanum_fraction": 0.7818411097, "num_tokens": 809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6738172748436446}}
{"text": "{\\Large Lecturer: Prof. Dr. Bethge}\\\\[1cm]\n\n\\textbf{Examples of unsupervised learning applications}\n\\begin{itemize}\n\t\\item \\emph{density estimation} (e.g. texture synthesis), image compression\n\t\\item level set estimation\n\t\\item clustering/mode finding e.g. spike sorting; algorithm Mixture of Gaussians\n\t\\item metric learning e.g. 3D visualization; algorithm multidimensional scaling\n\t\\item feature extraction -> representation learning, e.g. whitening; algorithm principle component analysis\n\\end{itemize}\n\n\\section{Set algebras, measures, and probabilities}\n\\begin{itemize}\n\\item {\\bf Overview for the mathematical construction of random variables}\n\\begin{itemize}\n\\item Sample Space $S$ (often also $\\Omega $). $s\\in S$ ``outcomes''\n\\item Boolean Algebra (or Sigma Algebra)  $\\mathcal{B}(S)$ and $A \\in \\mathcal{B}(S)$ are called ``events''. An event $A$ is realized if an outcome $s$ is in $A$. \\\\For example, $\\mathcal{B}(S)=\\mathcal{P}(S)$\n\\item Measure $m: \\mathcal{B}(S) \\to [0,\\infty)$ and $m(A\\dot\\cup B) = m(A) + m(B)$\n\\item probability measure $p(S)=1$, if $m$ is a measure with $m(S)<\\infty$ then $p(A) := m(A)/m(S)$ is a probability measure.\n\\item random variables: consider $M \\in \\mathcal{B}(S)$ with $M=\\{s \\in S: X(s) < \\vartheta\\} \\subseteq S$\n\\end{itemize}\n\n\\item {\\bf Power Set:}  $\\mathcal{P}(S) := \\{A\\subseteq S\\}$, $|\\mathcal{P}(S) |= 2^{|S|}$\n\n\\item {\\bf Boolean Algebra:}  $\\mathcal{B}(S) \\subseteq \\mathcal{P}(S)$ is called a {\\it Boolean Algebra} iff\n\\begin{itemize}\n\\item[(i)] $A \\in \\mathcal{B}(S)  \\Rightarrow \\overline{A} \\in \\mathcal{B}(S)  $\n\\item[(ii)] $A, B \\in \\mathcal{B}(S)  \\Rightarrow A \\cup B \\in \\mathcal{B}(S)  $ \n\\end{itemize}\nExamples:\n\\begin{itemize}\n\\item[(i)] $\\{ \\emptyset, S\\}  $ and $\\mathcal{P}(S)$ are Boolean Algebras.\n\\item[(ii)] If $a\\in S$ then $\\{\\emptyset, \\{a\\}, S-\\{a\\}, S\\}$ is the Boolean Algebra {\\it generated by} $a$.\n\\item[(iii)] $I(R)$ is defined to be the smallest Boolean Algebra which contains all open intervals $(a,b)$ for which $-\\infty \\le a < b\\le \\infty$. \n\\end{itemize}\n\n\\item {\\bf Sigma-Algebra:}  $\\mathcal{B}(S) \\subseteq \\mathcal{P}(S)$ is called a Sigma-Algebra if  \n\\begin{itemize}\n\\item[(i)] $A \\in \\mathcal{B}(S)  \\Rightarrow \\overline{A} \\in \\mathcal{B}(S)  $\n\\item[(ii)] For all sequences $A_1, A_2, \\dots \\in \\mathcal{B}(S)  \\Rightarrow \\bigcup_{k=1}^\\infty A_k \\in \\mathcal{B}(S)  $ \n\\end{itemize}\n\n\\item {\\bf Venn diagram} \n\n\\end{itemize}\n\n%\\item {\\bf Proposition 1 (Boolean laws):} \n\\begin{proposition}[Boolean laws]\n\\begin{itemize}\n\\item[(B1)] Idempotency: $A \\cup A = A$;   \\hspace{.5cm} $A \\cap A = A$\n\\item[(B2)] Associativity: $A \\cap (B\\cap C) = (A\\cap B) \\cap C$  \n\\item[(B3)] Commutativity: $A \\cup B = B \\cup A$;    \\hspace{.5cm}  $A \\cap B = B \\cap A$\n\\item[(B4)] Distributivity: $A \\cap (B\\cup C)  = (A \\cap B) \\cup (A \\cap C)$; \\hspace{.5cm}  $A \\cup (B\\cap C)  = (A \\cup B) \\cap (A \\cup C)$\n\\item[(B5)] de Morgan's law:  $\\overline{A \\cup B} = \\overline{A} \\cap \\overline{B} $;    \\hspace{.5cm}  $\\overline{A \\cap B} = \\overline{A} \\cup \\overline{B} $\n\\item[(B6)] Complements: $ \\overline{ \\overline{A}} =  A$; \\hspace{.5cm}  $A \\cap \\overline{A} = \\emptyset$; \\hspace{.5cm}  $A \\cup \\overline{A} = S$\n\\item[(B7)] Properties of $S$ and $ \\emptyset$: \\hspace{.2cm} $A \\cup S = S$; \\hspace{.5cm} $A \\cup \\emptyset = A$; \\hspace{.5cm} $A \\cap S = A$; \\hspace{.5cm} $A \\cap \\emptyset = \\emptyset$\n\n\\end{itemize}\n\\end{proposition}\n\n\\begin{itemize}\n\n\\item {\\bf (Finite) Measure:} A mapping $m: \\mathcal{B}(S) \\rightarrow [0, \\infty), A\\in  \\mathcal{B}(S) \\to m(A) \\in [0, \\infty)$ is called a {\\it measure} if for all $A,B \\in \\mathcal{B}(S)$ with $A\\cap B = \\emptyset$ holds: $m(A\\cup B) = m(A) + m(B)$.\\\\(This property can be written compactly as $m(A\\dot\\cup B) = m(A) + m(B)$)\n\nExamples:\n\\begin{itemize}\n\\item[(i)] $m(A) := |A|$ is the {\\it counting measure}.\n\\item[(ii)] For $S=[a,b]$ and $\\mathcal{B}(S)=\\mathcal{I}([a,b])$ with $|a|, |b| < \\infty$ the {\\it Lebesgue Measure} is defined as $m([c, d]) := d-c$.\n\\item[(iii)] If $f(x) \\ge 0$ for all $a \\le x \\le b$ with $\\int_a^b f(x) dx <\\infty$ then $m([c, d]) := \\int_c^d f(x) dx $ is a measure.\n\\item[(iv)] For $S=R$ and $\\mathcal{B}(S)=\\mathcal{I}(R)$ the {\\it Dirac Ma\\ss} is given by $\\delta_a(J) = 1$ if $a\\in J$ and $\\delta_a(J) = 0$ otherwise.\n\\end{itemize}\n\n\\item {\\bf Proposition 2:} \n\\begin{itemize}\n\\item[(i)] If $B\\subseteq A$ then $m(A-B) = m(A) - m(B)$.\n\\item[(ii)] If $B\\subseteq A$ then $m(B) \\le m(A)$.\n\\item[(iii)] $m(\\emptyset) =0$.\n\\item[(iv)] $m(A \\cup B) = m(A) + m(B) - m(A\\cap B)$.\n\\end{itemize}\n\n\\item {\\bf Proposition 3:}\\\\\nIf $A,B \\in \\mathcal{B}(S)$ then:\n\\begin{itemize}\n\\item[(i)] $ (A \\cap B) \\in \\mathcal{B}(S)$ since $ (A \\cap B) = \\overline{\\overline{A} \\cup \\overline{B}}$.\n\\item[(ii)] $\\emptyset, S$ belong to every Boolean Algebra, since for $A \\in \\mathcal{B}(S)$ also $\\overline{A} \\in \\mathcal{B}(S)$ and $A \\cap \\overline{A} = \\emptyset$ and $A\\cup \\overline{A} = S$ .\n\\item[(iii)] $\\mathcal{B}_B(S) := B \\cap \\mathcal{B}(S) = \\{A \\cap B: A \\in \\mathcal{B}(S)\\}$ is a Boolean Algebra if $B\\ne \\emptyset$.\n\\item[(iv)] $\\mathcal{B}_B(S) \\subseteq \\mathcal{B}(S)$. \n\\end{itemize}\n\n\n\\item {\\bf Probability measure:} For a sample space $S$ and a Sigma Algebra $\\mathcal{B}(S)$ a measure \\, $P$ is a {\\it probability measure} if $P(S)=1$.\n\n\\item {\\bf Probability space:} A probability space consists of the triple $(S,\\mathcal{B}(S), P)$ where $S$ is the sample space, $\\mathcal{B}(S)$ the event algebra (which is a Boolean or a sigma algebra) and $P$ is a  probability measure on $\\mathcal{B}(S)$. \n\n\\item {\\bf Proposition 4:} \n\\begin{itemize}\n\\item[(i)] $0 \\le P(A) \\le 1$.\n\\item[(ii)] $P(\\overline{A}) = 1-P(A)$.\n\\item[(iii)] If $\\mathcal{E}= \\{E_1, E_2, \\dots, E_n\\}$ is a partition of $S$ (that is $S= \\bigcup_{k=1}^n E_k$ and $E_l \\cap E_m = \\emptyset$), then \\quad $\\sum_{k=1}^n P(E_k) = 1$ \\quad and \\quad $P(A)=\\sum_{k=1}^n P(A\\cap E_k)$.\n\\end{itemize}\n\n\\item {\\bf Specification of probabilities}\n\\begin{itemize}\n\\item[(i)] As a limiting value of relative frequencies: $P(A) = \\lim_{n\\to \\infty} \\frac{r_n(A)}{n}$\n\\item[(ii)] Symmetrie assumptions (e.g. if we assume $P(s)=P(s^\\prime)$ for all $s,s^\\prime \\in S$ then it follows: $P(s) = 1/|S|$).\n\\item[(iii)] Subjective probabilities (based on Cox axioms) can be determined via betting games.\n\\end{itemize}\n\\item {\\bf Conditional probabilities:}\nIf $(S,\\mathcal{B}(S), P)$ is a probability space and $B \\in \\mathcal{B}(S)$ then the restriction of $P$ to the reduced Sigma-Algebra $\\mathcal{B}_B(S):=\\{B\\cap A: A \\in \\mathcal{B}(S)\\}$ defines a measure \\ $M_B: \\mathcal{B}_B \\to [0,\\infty)$. If in addition $P(B) >0$, then $P_B: \\mathcal{B}_B(S) \\to [0,1], \\quad A_B \\mapsto P_B(A_B) :=  M_B(A_B)/P(B)=P(A_B)/P(B), \\, \\forall A_B \\in \\mathcal{B}_B(S)$ is a probability measure on $\\mathcal{B}_B(S)$.\\\\\nThe $A_B\\in \\mathcal{B}_B(S)$ usually originate from intersection of the elements of the original Sigma-Algebra $\\mathcal{B}(S)$ with the event $B$.\n\\item {\\bf Independence:}\\\\\nTwo events $A$ and $B$ are {\\it statistically independent} iff $P(A\\cap B) = P(A) P(B)$.\n\\item {\\bf Proposition 5:} \n\\begin{itemize}\n\\item[(i)] Two events $A$ and $B$ are (statistically) independent if $P(A)=0$ or $P(B)=0$.\n\\item[(ii)] If two events $A$ and $B$ are independent and $P(A)>0$, then: $P(B|A)=P_A(B)=P(B)$.\n\\item[(iii)] If two events $A$ and $B$ are independent and $P(A)>0$, then $A$ and $\\overline{B}$ are independent as well.\n\\end{itemize}\n\n\\end{itemize}\n\n\\section{Random Variables}\n\\begin{itemize}\n\\item {\\bf Cumulative distribution function (cdf):} \nAny univariate random variable can be uniquely defined by the cumulative distribution function:\n$$\nF(x) = P(\\{s \\in S: X(s) \\le x\\}), \\quad \\forall x \\in S^\\prime\n$$\nIt holds:\n\\begin{itemize}\n\\item[(i)] $F$ is a nondecreasing function.\n\\item[(ii)] $\\lim_{x\\to -\\infty} F(x)= 0$, $\\lim_{x\\to \\infty} F(x)= 1$\n\\item[(iii)] Any function that fulfills (i)+(ii) is a cdf.\n\\item[(iv)] $ P(\\{s \\in S: X(s) > x\\}) = 1-F(x)$\n\\item[(v)] $ P(\\{s \\in S: x_1 < X(s) \\le x_2\\}) = F(x_2)-F(x_1)$\n\\item[(vi)] discrete case: probability mass function / point probability $p(x) = F(x) - \\lim_{\\epsilon \\to 0}F(x-\\epsilon)$\n\\item[(vii)] continuous case: probability density function (pdf) $\\rho(x) = \\frac{d}{dx} \\mathcal{F}(x)$\n\\end{itemize}\n\n\n\\item {\\bf Expectation (value):} \n$$\nE[X] = \\sum_{k=1}^n p(x_k) x_k , \\quad E[f(X)] = \\sum_{k=1}^n p(x_k) f(x_k) \n$$\n\\item {\\bf Moments:} \n$$\nE[X^m] =  \\sum_{k=1}^n p(x_k) x_k^m\n$$\n\\item {\\bf Variance:} \n$$\nVar[X]= E[X^2]-E[X]^2\n$$\n\n\\end{itemize}\n\\vfil \n\n\n", "meta": {"hexsha": "c6fde970f3b64ba4ad50b75d7ed32793fe4ec4ee", "size": 8581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture8/lecture8.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/lecture8/lecture8.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/lecture8/lecture8.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": 54.3101265823, "max_line_length": 454, "alphanum_fraction": 0.6242862137, "num_tokens": 3356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6738172707630367}}
{"text": "\\chapter{ELECTROMAGNETIC INDUCTION}\n\\section{Magnetic Flux}\nMagnetic flux is a measurement of total magnetic field which passes through a given area. It is the product of the average magnetic field times the perpendicular area that it penetrates.Consider a uniform magnetic field passing through a surface S, as shown in Figure .\\ref{magnetic flux}.\\\\\n\\begin{minipage}{0.75\\textwidth}\n\t\\begin{align}\n\t\\intertext{Let the area vector be ${\\vec{A}}=A \\hat{{n}}$, where $A$ is the area of the surface and $\\hat{{n}}$ its unit normal. The magnetic flux through the surface is given by,}\n\t\\Phi_{B}&=\\vec{{B}} \\cdot \\vec{{A}}=B A \\cos \\theta\n\t\\intertext{Where $\\theta$ is the angle between $\\vec{{B}}$ and $\\hat{{n}}$. If the field is non-uniform, $\\Phi_{B}$ then becomes,}\n\t\\Phi_{B}&=\\iint_{S} \\overrightarrow{{B}} \\cdot d \\vec{{A}}\n\t\\intertext{The SI unit of magnetic flux is the weber $({Wb})$ :}\\notag\n\t1 \\mathrm{~Wb}&=1 \\mathrm{~T} \\cdot \\mathrm{m}^{2}\n\t\\end{align}\n\\end{minipage}\n\\begin{minipage}{0.25\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{magneticflux}\n\t\t\\caption{Magnetic flux.}\n\t\t\\label{magnetic flux}\n\t\\end{figure}\n\\end{minipage}\n\\section{Electromotive Force }\n\\section{Motional emf}\n\\par When we consider static electric field $E$, the potential difference between any two point $a$ and $b$ is given \n\\begin{minipage}{0.5\\textwidth}\n$$v=-\\int_{a}^{b} E\\cdot dl$$\n\\end{minipage}\n\t\\begin{minipage}{0.50\\textwidth}\t\t\t\t\n\t\t\\includegraphics[width=0.45\\textwidth]{diagram-20210427(3)-crop}\n\t\\end{minipage}\nAnd work done by the electric field along a closed path is zero.\n\\begin{align*}\ni.e., \\quad \\oint E\\cdot dl&=0\\\\\n\\rightarrow \\quad \\nabla \\times E&=0\n\\end{align*}\n\\begin{minipage}{.45\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.7\\textwidth]{flux 2}\n\t\\end{center}\n\\end{minipage}\\\\\n\\\\Suppose the magnetic field $B$ in the shaded region is pointing in to the page, we are moving a wire having a resistor connected at the end through the field towards right with a speed $v$, the charges in the segment $a$\\ $b$ experience a magnetic force (Lorentz force) whose vertical component $qvB$ drives a current around the loop in the clockwise direction, so the e.m.f generated,\n\\begin{align*}\n\\varepsilon&=\\oint F_{mag} \\cdot dl \n\\intertext{Here $F_{mag}$ is the magnetic Lorentz force per unit charge. We know that,}\n {F_{Lorentz}}&=q(v\\times B)\n \\intertext{Since $q=1\\ $\\ unit and,\\ $ v $ \\ and $ B $\\  are $ \\perp^{lr} $}\nF_{mag}&=vB\\\\\n\\varepsilon&=\\oint F_{mag}\\cdot dl\\\\\n\\varepsilon&=\\oint vB\\cdot dl\\\\\n\\varepsilon&= vBh \\hspace{2cm}\\text{$\\oint  dl=h$ $ \\rightarrow $ width of the loop}\n\\intertext{If $\\phi$ is the flux of $B$ through the shaded region }\n\\phi=&\\int B \\cdot da\\quad\\rightarrow da=hx\\\\\n=&Bhx\n\\intertext{When the  loop moves, flux decreases.}\n\\frac{d\\phi}{dt}&=Bh\\frac{dx}{dt}=-Bhv \\hspace{2cm}\\rightarrow\\frac{dx}{dt}=-v\\\\\n\\frac{d\\phi}{dt}&=-Bhv\n\\intertext{Both equation for emf are same.So precisely the emf generated in the loop is the negative rate of change of flux through the loop. } \n\\varepsilon&=\\frac{-d \\phi}{dt}\n\\intertext{This is called \\textbf{Flux rule} for motional emf.}\n\\end{align*}\n\\subsection{Fleming's Right Hand Rule}\nThe Fleming's right hand rule is used to determine the direction of induced current. Accorrding to this rule, stretch the thumb, forefinger and centre finger of right hand in mutually perpendicular directions such that the forefinger points in the direction of magnetic field and thumb is along the direction of motion of the conductor, the centre finger will point in the direction of the induced current.\n\\begin{exercise}\n\tA metal stock of length, $2 m/s$ moves with speed $2 m/s$ in a direction making $30^{\\circ}$ with its length. If a magnetic field of $0.2$ Tesla exists in the region perpendicular to the rod then p.d developed between it's ends is........ volts.\n\\end{exercise}\n\\begin{answer}\n\tThe potential difference developed between the ends of the rods is,\\\\ \n\t\\begin{minipage}{0.60\\textwidth}\\hfill\n\t\t\\begin{align*}\n\t\t\\varepsilon&=B l v \\sin \\theta\\\\\n\t\t&=0.2 \\times 2 \\times 2 \\times \\sin 30 \\\\\n\t\t&=0 .4 \\text{ volt}\\\\\n\t\t\\end{align*}\n\t\\end{minipage}\n\t\\begin{minipage}{0.40\\textwidth}\\hfill\n\t\t\\begin{align*}\n\t\t\\theta&=30^{\\circ}\\\\\n\t\tl&=2 m\\\\\n\t\tv&=2 m/s\\\\\n\t\tB&=0.2 \\text{ Tesla}\n\t\t\\end{align*}\n\t\\end{minipage}\n\\end{answer}\n\\subsection{Faraday's law}\nThe electric fields and magnetic fields considered , produced by stationary charges and moving charges (currents), respectively. Imposing an electric field on a conductor gives rise to a current which in turn generates a magnetic field.  In 1831, Michael Faraday discovered that, by varying magnetic field with time, an electric field could be generated. The phenomenon is known as electromagnetic induction.\n\\begin{figure}[H]\n\t\\begin{minipage}{0.30\\textwidth}\n\t\\centering\n\t\\includegraphics[height=3.2cm,width=5cm]{faraday1}\n\t\\end{minipage}\n\\begin{minipage}{0.30\\textwidth}\n\t\\centering\n\t\\includegraphics[height=3.2cm,width=5cm]{faraday2}\n\\end{minipage}\n\\begin{minipage}{0.30\\textwidth}\n\t\\centering\n\t\\includegraphics[height=3.7cm,width=5cm]{faraday3}\n\\end{minipage}\n\\caption{Faraday's Experiment.}\n\\end{figure}\nFaraday's experiment demonstrates that an electric current is induced in the loop by changing the magnetic field. The coil behaves as if it were connected to an emf source. It is found that the induced emf depends on the rate of change of magnetic flux through the coil.\\\\\nAn emf is generated in loop if,\n\\begin{enumerate}\n\\item \nIf you pull a loop of wire through a magnetic field.\\\\ \nIn the first case emf is induced due to change in flux exposed by flux rule.\n\\begin{align*}\n\\varepsilon&=\\frac{-d\\phi}{dt}\n\\end{align*}\nHere the emf is magnetic that is emf is induced by Lorentz force.\n\\item \nIf you move the magnet near a loop holding the loop still.\\\\\nThere will be no motion of charges since the loop is at rest so the force can't be magnetic. Here the reason for emf is the electric field which is induced by the changing magnetic field.\n\\begin{align*}\n\\varepsilon=\\oint E\\cdot dl&=\\frac{-d\\phi}{dt}\\\\\n\\oint E\\cdot dl&=-\\oint \\frac{dB}{dt}\\cdot da\n\\intertext{By applying Stoke's theorem}\n\\nabla\\times E&=\\frac{-dB}{dt}\\\\\n\\end{align*}\n\\item \nChanging the magnetic field by keeping the loop and the magnet at rest.\\\\\nMagnetic and loop are moving giving rise to an emf, $ \\frac{-d\\phi}{dt} $\n\\end{enumerate}\n\\begin{align*}\n\\intertext{Now the those cases summerise in to a single form}\n\\varepsilon&=\\frac{-d\\phi}{dt}\n\\end{align*}\nThe direction of the induced current is given by Lenz's law.\n\\subsection{Lenz's law }\nThe direction of the induced current in electromagnetic induction is given by Lenz's law.\\\\\n\\begin{definition}\nThe induced current produces magnetic fields which tend to oppose the change in magnetic flux that induces such currents.\\\\\n\\end{definition}\n\\textbf{\\large Explanation:}\\\\\n\\begin{minipage}{.60\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[height=2cm,width=9cm]{04-crop}\n\t\\end{center}\n\\end{minipage}\\\\\\\\\\\\\nSuppose we have a coil which is moving towards a constant magnetic field pointing out of the page. When it reaches the field the flux in it is increasing. So there should be an induced current in the loop. Since the flux is increasing the induced current will flow, in such a way that the magnetic field produced by it should oppose the original field. So inside the coil the field must pointing in to the page. Therefore current must flow in clockwise direction.\\\\\\\\\n\\begin{minipage}{.60\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[height=2.5cm,width=8cm]{05-crop}\n\t\\end{center}\n\\end{minipage}\\\\\\\\\nConsider a loop which is initially in a magnetic field pointing into the page.Suppose we are moving it towards right with a velocity $V$,then the flux in it is going to decrease. So magnetic field should be produced in such a way that it will oppose the change. So the magnetic field should be produced in the same direction as the original one. So it must be pointing into the page inside the coil. Therefore the current must flow in clockwise direction.\\\\\\\\\\\tLenz's Law is not a fundamental law. It is a direct consequence that comes from both Fleming's Right and Left Hand rules . Fleming's Rules are the most fundamental principles of charge/field/motion/force interaction.\n\\begin{note}\nThe Right Hand (generator) Rule shows the direction of the induced emf and the resulting(conventional) current. This is all you need to find the direction of induced current. (Just remember that it is conventional current and it is really the emf that is induced and that a current will flow if there is a conduction path)\\\\\nThe Left Hand (motor) Rule shows the direction of the force that results from the above current and, therefore the opposition force to the original movement.\\\\\nThe latter will be seen as opposition to the original\n\tmovement, when you apply everything correctly. This is Lenz's Law.\\\\\\\\\n\tTo apply this:\n\\\\\tPick a point on the conductor.\\\\\nGiven the magnetic field and motion at that point, use the Right hand Rule to determine the induced current direction.\\\\\nAt that point, given the field and current, use the Left Hand Rule to determine the resulting force. It will be opposite to the original motion.\n\\end{note}\n\\subsection{ Various formulae of induced EMF}\n\\begin{enumerate}\n\t\\item  When a conducting rod of length $L$ is rotated in a perpendicur field of strength $B$, the induced emf generated is\n\t\\begin{minipage}{0.5\\textwidth}\n\t$$\n\t\\begin{aligned}\n\t&e=-\\frac{B \\omega L^{2}}{2}=\\frac{-B(2 \\pi n) L^{2}}{2} \\\\\n\t&e=-B n\\left(\\pi L^{2}\\right)=-B n A\n\t\\end{aligned}\n\t$$\n\t\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\t\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.25\\textwidth]{emf}\n\t\\end{center}\n\\end{figure}\n\\end{minipage}\n\twhere $\\omega$ is angular frequency and $n$ is frequency of $\\operatorname{rod} A=\\pi L^{2}$.\n\t\\item When a conducting solid disc of radius $r$ is rotating with a uniform angular velocity $\\omega$ in a perpendicular magnetic field $B$, the emf induced between the centre and rim of disc is\n\t$$\n\te=\\frac{-B \\omega r^{2}}{2}=-B n A\n\t$$\n\tIf rotation is anticlockwise, then -ve charge accumulates at the rim and +ve charge accumulates at the centre.\n\t\\item When a conducting rod of length $l$, moves with a velocity $v$ in a uniform magnetic field $B$, the induced emf is $e=B l v \\sin \\theta$,\n\t\\item When a coil moves linearly in a uniform magnetic field, but it remains wholly within the field, $d \\phi=0$. $\\therefore e=0 .$ However, when the coil enters the field partially or leaves the field partially, flux linked with the coil changes and induced emf $e=B l v$ develops.\n\\end{enumerate}\n\\begin{exercise}\n\tA conducting rod of length $l$ is rotated with uniform angular velocity $\\omega$ about one end in uniform magnetic field $B$. Electric field induced inside the rod at a distance $x$ from fixed end is ?\n\\end{exercise}\n\\begin{answer}$\\left. \\right. $\\\\\n\t\\begin{minipage}{0.35\\textwidth}\n\t\t\\begin{align*}\n\t\t\\text{emf at a distance x,}\\\\\n\t\t\\text{From center ,}\\  \\varepsilon&=\\frac{-d \\phi}{d t}=-\\frac{B \\cdot d A}{d t}\\\\\n\t\t\\text{Area} &=\\frac{1}{2} x^{2} \\theta \\\\\n\t\t\\frac{d A}{d t}&=\\frac{1}{2} x^{2} \\frac{d \\theta}{d t} \\hspace{2cm}\\frac{d \\theta}{d t}=\\omega\\\\\n\t\t&=\\frac{1}{2} x^{2}\\omega\\\\\n\t\t\\varepsilon&=\\frac{-1}{2} B x^{2}\\omega\\\\\n\t\t\\text{Electric field at $x$ , }\\ E&=\\frac{-d v}{d x}\\\\\n\t\t&=\\frac{1}{2} B\\omega\\frac{d x^{2}}{d x}\\\\\n\t\t&=B\\omega x\n\t\t\\end{align*}\n\t\\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=4cm]{06-crop}\n\t\\end{figure}\n\\end{minipage}\n\\end{answer}\n\\begin{exercise}\n\tA uniform magnetic field $\\vec{B}(t)$, pointing straight up, fills the shaded circular region. If $B$ is changing with time, what is the induced electric field?\\\\\n\t\\begin{minipage}{.45\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.4\\textwidth]{diagram-20210426(2)-crop}\n\t\t\\end{center}\n\t\\end{minipage}\\\\\n\\end{exercise}\n\\begin{answer}\n\t$\\vec{E}$ points in the circumferential direction, just like the magnetic field inside a long straight wire carrying a uniform current density. Draw an Amperian loop of radius $s$, and apply Faraday's law:\n\t\\begin{align*}\n\t\\oint \\vec{E} \\cdot d \\vec{l}&=E(2 \\pi s)\\\\&=-\\frac{d \\Phi}{d t}\\\\&=-\\frac{d}{d t}\\left(\\pi s^{2} B(t)\\right)\\\\&=-\\pi s^{2} \\frac{d B}{d t}\n\t\\intertext{\tTherefore}\n\tE(2 \\pi s)&=-\\pi s^{2} \\frac{d B}{d t}\\\\\n\t\\vec{E}&=-\\frac{s}{2} \\frac{d B}{d t} \\hat{\\boldsymbol{\\phi}}\n\t\\intertext{If $\\vec{B}$ is increasing, $\\vec{E}$ runs clockwise, as viewed from above.}\n\t\\end{align*}\n\\end{answer}\n\\subsection{Mutual Inductance and Self Inductance}\n\\subsection{Mutual Inductance}\nWe have two loops $1$ and $2$ as shown in the figure.\\ref{mutual inductance}. Suppose the current flowing through the loop $1$ is $I_1$, it produces a magnetic field $B_1$ which is propotional to current $I_1$ by Biot-Savart law.\\\\\n\\begin{minipage}{0.65\\textwidth}\n\t\\begin{align*}\nB_1&=\\frac{\\mu_{0}}{4\\pi}I_1\\oint \\frac{dl \\times\\hat{r}}{r^2}\n\\intertext{These field lines pan through second loop and flux through it is $\\phi_2$}\n\\phi_2&=\\oint B_1 \\cdot da_2\\\\\n\\text{So,} \\ \\phi_2 &\\propto  I_1\\\\\n\\phi_2&=M_{21}I_1 \n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.20\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=5cm]{diagram-20210426(3)-crop}\n\t\\caption{}\n\t\\label{mutual inductance}\n\\end{figure}\n\\end{minipage}\n\\begin{align*}\n\\intertext{$M_{21}$ is constant of proportionality, is called as mutual inductance of the two loops,}\n\\phi_2&=\\int B_1\\cdot da_2\\\\\n\\text{But,} \\ B_1&=\\nabla\\times A_1 \\hspace{0.6cm} \n\\text{$A_1$ is the magnetic vector potential.} \\\\\n\\therefore\\phi_2&=\\int\\nabla \\times A_1\\cdot da_2\\\\\n\\text{By Stoke's theorem,}\\ \\phi_2&=\\oint A_1\\cdot dl_2 \n\\end{align*}\n\n\\begin{align*}\n\\intertext{Magnetic vector potential due to small length element $dl$ can be calculated as,}\nA_1&=\\frac{\\mu_{0} I_1}{4\\pi}\\oint \\frac{dl_1}{r}\\\\\n\\therefore\\phi_2&=\\frac{\\mu_{0}I_1}{4\\pi}\\oint\\left( \\oint\\frac{dl}{r}\\right) dl_2 \\\\\n\\intertext{Comparing  both equations for $\\phi_2$  we  get,}\\\\\nM_{21}&=\\frac{\\mu_{0}}{4 \\pi}\\oint \\oint \\frac{dl_1 \\cdot dl_2}{r}\\quad\\Rrightarrow\\quad\\text{Neumann formula}\n\\end{align*}\n\n\\begin{note}\\\\\n\t\\textbf{(a.)} \tMutual Inductance is a geometrical quantity depends only on the size , shape and relative positions of the two loops. \\\\\\\\\n\t\\textbf{(b.)} If we change the rules of loop $1$ and $2$ we will get the same equation as $M_{21}$\\ for\\ $M_{12}$.\n\\end{note}\n\\begin{align*}\nM_{12}&=\\frac{\\mu_{0}}{4 \\pi}\\oint \\oint \\frac{dl_1 \\cdot dl_2}{r}\\\\\nM_{12}&=M_{21}\\hspace{1cm} \\text{Let's say  M} \\\\\n\\end{align*}\nNow suppose if we vary the current $I$ in loop $1$ . An emf is induced in loop $2$ By Faraday's law,\n\\begin{align*}\n\\varepsilon_2&=\\frac{-d\\phi_2}{dt}\\\\\n\\phi_2&=\\mu_{0}I_1\\\\\n\\varepsilon_2&= -M \\frac{dI_1}{dt}\n\\end{align*}\nWhenever we vary the current through the loop $1$ an $emf$ is induced in second loop without any actual contact between them.\\\\\n\\subsection{Self Inductance}\nSuppose, instead of two circuits,we  have just a\nsingle loop and we change current in that loop. This change in current changes the magnetic field\nassociated with the current and the flux changes.\nThe given loop itself will intercept the flux and the\nchanging flux would result in an emf in the circuit itself.\n\n\\begin{align*}\n\\phi & \\propto I\\\\\n\\therefore \\phi&= LI\n\\end{align*}\nWhere $L$ is called self inductance,and its value depends on the geometry of the loop only. The $emf$ generated when the current changes is given by\\\\\n\\begin{align*}\n\\varepsilon&=\\frac{-d\\phi}{dt}\\\\\n\\varepsilon&=\\frac{-Ld\\phi}{dt} \\hspace{1cm}\\text{Unit of $L$ is Henries(H)}\\\\\n1 H&=1 V.S/Ampere\n\\end{align*}\nBy Lenz's law we can say that direction of induced $emf$ is opposite to the direction of original current .Therefore it is also called Back emf.\n\\subsubsection{Self inductance of a solenoid.}\nConsider a solenoid has a length $l$, number of turns $N$ and area of cross section $A$. The  self inductance $L$ of the solenoid is given as,\\\\\n\\begin{minipage}{0.65\\textwidth}\n\t\\begin{align*}\n\tB&=\\mu_{0}n I\\hspace{1cm}n=\\frac{N}{l}\\\\\n\t&=\\frac{{\\mu_{0}NI}}{l}\\\\\n\t\\phi&=N B A=\\frac{\\mu_{0} N^{2} I A}{l}\\\\\n\t\\phi&=L I\\\\\n\t\\therefore L I&=\\frac{\\mu_{0} N^{2} I A}{l}\\\\\n\t\\therefore L &=\\frac{\\mu_{0} N^{2}  A}{l}\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=5cm]{solenoid}\n\t\t\\caption{Solenoid}\n\t\t\\label{Solenoid}\n\t\\end{figure}\n\\end{minipage}\n\\begin{exercise}\n\tA current $l$ is flowing in a toroidal coil of circular cross section of radius $R$ with $N$ number of turns distributed uniformly over its circumference if $A$ is the cross sectional area of the toroid, $I B$ Self inductance will be\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tB&=\\frac{\\mu_{0} N I}{2 \\pi R}\\\\\n\t\\phi&=N B A=\\frac{\\mu_{0} N^{2} I A}{2 \\pi R}\\\\\n\t\\phi&=L I\\\\\n\tL I&=\\frac{\\mu_{0} N^{2} I A}{2 \\pi R}\\\\\n\t\\therefore L&=\\frac{\\mu_{0} N^{2}  A}{2 \\pi R}\n\t\\end{align*}\n\\end{answer}\n\\subsection{Combination of inductors}\n\\begin{enumerate}\n\t\\item When two coils are connected in series and current in both is in the same direction,\n\t$$\n\tL=L_{1}+L_{2}+2 M\n\t$$\n\tWhen current in the two coils flows in opposite directions.\n\t$$\n\tL=L_{1}+L_{2}-2 M\n\t$$\n\tIf we take $M=0$, then\n\t$$\n\tL=L_{1}+L_{2}\n\t$$\n\t\\item When two coils are connected in parallel, then\n\t$$\n\t\\begin{aligned}\n\t&\\frac{1}{L}=\\frac{1}{\\left(L_{1}+M\\right)}+\\frac{1}{\\left(L_{2}+M\\right)} \\\\\n\t&L=\\frac{L_{1} L_{2}+M^{2}+M\\left(L_{1}+L_{2}\\right)}{L_{1}+L_{2}+2 M}\n\t\\end{aligned}\n\t$$\n\t$M=0$\\\\\n\t$$L=\\frac{L_{1} L_{2}}{L_{1}+L_{2}}$$\n\\end{enumerate}\n\\newpage\n\\begin{abox}\n\tPractice set-1\n\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item A uniform magnetic field in the positive $z$-direction passes through a circular wire loop of radius $1 \\mathrm{~cm}$ and resistance $1 \\Omega$ lying in the $x y$-plane. The field strength is reduced from 10 tesla to 9 tesla in $1 s$. The charge transferred across any point in the wire is approximately\n\t\t\\exyear{NET JUNE 2015}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}]$3.1 \\times 10^{-4}$ coulomb\n\t\t\\task[\\textbf{B.}] $3.4 \\times 10^{-4}$ coulomb\n\t\t\\task[\\textbf{C.}] $4.2 \\times 10^{-4}$ coulomb\n\t\t\\task[\\textbf{D.}]$5.2 \\times 10^{-4}$ coulomb\n\t\\end{tasks}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item A magnetic field $B$ is $B \\hat{z}$ in the region $x>0$ and zero elsewhere. A rectangular loop, in the $x y$-plane, of sides $l$ (along the $x$-direction) and $h$ (along the $y$ - direction) is inserted into the $x>0$ region from the $x<0$ region at constant velocity $v=v \\hat{x}$. Which of the following values of $l$ and $h$ will generate the largest EMF?\n\t\t\\exyear{NET JUNE 2016}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $l=8, h=3$\n\t\t\\task[\\textbf{B.}]$l=4, h=6$\n\t\t\\task[\\textbf{C.}]$l=6, h=4$\n\t\t\\task[\\textbf{D.}]$l=12, h=2$\n\t\\end{tasks}\n\\end{enumerate}\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{a}&2&\\textbf{b}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set-2\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item Consider a conducting loop of radius $a$ and total loop resistance $R$ placed in a region with a magnetic field $B$ thereby enclosing a flux $\\phi_{0}$. The loop is connected to an electronic circuit as shown, the capacitor being initially uncharged\\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.8cm,width=6cm]{diagram-20210817(14)-crop}\n\t\t\\end{figure}\n\t\tIf the loop is pulled out of the region of the magnetic field at a constant speed $u$, the final output voltage $V_{\\text {out }}$ is independent of\n\t\t\\exyear{GATE 2010}\n\t\\end{minipage}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\phi_{0}$\n\t\t\\task[\\textbf{B.}]$u$ \n\t\t\\task[\\textbf{C.}]$R$\n\t\t\\task[\\textbf{D.}] $C$ \n\t\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A circular loop made of a thin wire has radius $2 \\mathrm{~cm}$ and resistance $2 \\Omega$. It is placed perpendicular to a uniform magnetic field of magnitude $\\left|\\vec{B}_{0}\\right|=0.01$ Tesla. At time $t=0$ the field starts decaying as $\\vec{B}=\\vec{B}_{0} e^{-t / t_{0}}$, where $t_{0}=1 s .$ The total charge that passes through a cross section of the wire during the decay is $Q$. The value of $Q$ in $\\mu C$ (rounded off to two decimal places) is\n\t\\exyear{GATE 2019}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item A circular conducting ring of radius $R$ rotates with constant angular velocity $\\omega$ about its diameter placed along the $x$-axis. A uniform magnetic field $B$ is applied along the $y$-axis. If at time $t=0$ the ring is entirely in the $x y$-plane, the emf induced in the ring at time $t>0$ is\n\t\\exyear{JEST 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $B \\omega^{2} \\pi R^{2} t$\n\t\\task[\\textbf{B.}]$B \\omega \\pi R^{2} \\tan (\\omega t)$\n\t\\task[\\textbf{C.}]$B \\omega \\pi R^{2} \\sin (\\omega t)$\n\t\\task[\\textbf{D.}]$B \\omega \\pi R^{2} \\cos (\\omega t)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Two parallel rails of a railroad track are insulated from each other and from the ground. The distance between the rails is 1 meter. A voltmeter is electrically connected between the rails. Assume the vertical component of the earth's magnetic field to the $0.2$ gauss. What is the voltage developed between the rails when a train travels at a speed of $180 \\mathrm{~km} / \\mathrm{h}$ along the track? Give the answer in milli-volts.\n\t\\exyear{JEST 2018}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item A circular metal loop of radius $a=1 \\mathrm{~m}$ spins with a constant angular velocity $\\omega=20 \\pi \\mathrm{rad} / \\mathrm{s}$ in a magnetic field $B=3$ Tesla, as shown in the figure. The resistance of the loop is 10 ohms. Let $P$ be the power dissipated in one complete cycle.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=3cm]{nimi2-crop}\n\\end{figure}\n\t What is the value of $\\frac{P}{\\pi^{4}}$ in Watts?\n\t\\exyear{JEST 2019}\n\\end{minipage}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{a}&2&\\textbf{6.28}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{1}\\\\\\hline\n\t\t5&\\textbf{18}&&\\\\\\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", "meta": {"hexsha": "ec5c16d02a6a32e9da1398b8c22fb901e6765bce", "size": 22798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Electrodynamics- CSIR/chapter/electromagnetic induction.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/electromagnetic induction.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/electromagnetic induction.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": 44.8779527559, "max_line_length": 677, "alphanum_fraction": 0.7069041144, "num_tokens": 7732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.6738172674892707}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,yfonts}\n\n\\begin{document}\n\n\\section{Show the relationship between Commutative Noetherian Rings (CNDs) and the class inclusions on wikipedia}\n\n\\begin{center}\n\\begin{tabular}{ |c|c| }\n \\hline\n Class & Relationship to Noetherian Rings\\\\ \n \\hline\n Commutative Rings & $\\supset$ \\\\ \n  Integral Domains & Incomparable  \\\\ \n  Integrally closed domains & Incomparable  \\\\ \n  GCD domains & Incomparable  \\\\ \n  Unique Factorization domains & Incomparable  \\\\ \n  Principle Ideal Domains & $\\subset$  \\\\ \n  Euclidean Domains & $\\subset$  \\\\ \n  Fields & $\\subset$  \\\\ \n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection{Let $(X_0, X_2, ..., X_{n+1})$ be a finite sequence of sets such that $X_{i+1} \\subset X_i$ for all $i$ where $0 \\le i \\le n$ and a set $Y$ such that $X_0 \\supset Y$ and $X_{n+1} \\subset Y$. Then there exists integers $j, k, l \\ge 0$ such that $j+k+l=n$ and the first $j$ sets of X contain Y, the next $k$ are incomparable to Y in the sense that they intersect but neither is the subset of the other, and the last $l$ are contained by Y}\n\nTwo non-identical sets X and Y are in one of four relations: subset, superset, incomparable, and disjoint. If $X_i$ is a subset or disjoint of $Y$, then $X_{i+1}$ must be a subset or disjoint respectively. If $X_i$ is a superset of $Y$, then $X_{i+1}$ could be any four options. And if $X_i$ is incomparable with $Y$, then all but superset are options.\n\nPutting this together, we start with a superset followed by zero or more supersets, then we then transition to zero or more incomparables. Because we know we end with a subset, there can be no disjoints, since once $X_i$ is disjoint all sets after it must be disjoint.\n\n\\subsection{1 follows the setup of 1.1}\n\n$X_0$ is Commutative Rings, $Y$ is Noetherian Rings, $n=6$, and $X_7$ is Fields. Clearly a Commutative Noetherian Ring is a commutative ring, so $X_0 \\subset Y$. A field is a commutative Noetherian Ring since in an Noetherian Ring every ideal is finitely generated, and in a field the only two ideals are (0) and (1), both generated by a single element.\n\n\\subsection{In the language of 1.1, $j=0$, $k=4$, and $l=2$}\n\nTo show this, we just need to show that Integral Domains and UFDs are Incomparable, and that PIDs are subsets, since those are the transitions.\n\n\\subsection{Integral Domains and CNDs are Incomparable}\n\nThe zero ring is Noetherian, since its only ideal is (0). However it is not an Integral Domain, as it is explicitly excluded in the definition.\n\nThe ring of the integers if Noetherian since each of its ideals are generated by a single element, and it isn Integral Domain since any two non-zero elements multiplied together is non-zero.\n\nThe polynomial ring over countably infinite unknowns is an integral domain, since any two non-zero polynomials of degree $n$ and $m$ multiplied together will have degree $n+m$, and therefore not be zero. However, it is not Noetherian, since the chain of strictly inclusive ideals $(X_1), (X_1, X_2), (X_1, X_2, X_3), ... $ does not terminate.\n\n\\subsection{Unique Factorization Domains and CNDs are Incomparable}\n\nUFDs and CNDs are not disjoint and CNDs are not a subset of UFDs for the same reason above. What remains to show is that there exists a UFD that is not Noetherian.\n\nThe ring $Z[\\sqrt -5]$ is not a UFD since 6 can be written as $2 \\times 3$ or $(1+ \\sqrt -5)(1- \\sqrt -5)$. However $Z[\\sqrt -5]$ is Noetherian since its Krull dimension is 2 (how to prove this?)\n\n\n\\subsection{Principle Ideal Domains are CNDs}\n\nPIDs are commutative, and each ideal is generated by a single element, hence finitely generated.\n\n\\end{document}", "meta": {"hexsha": "632d19fd52d0b7e3796b485f0fb1abe2606bb2be", "size": 3653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algebra/classification_of_noetherian_rings/problem.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "algebra/classification_of_noetherian_rings/problem.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algebra/classification_of_noetherian_rings/problem.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": 61.9152542373, "max_line_length": 449, "alphanum_fraction": 0.7372022995, "num_tokens": 1057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6738172670051653}}
{"text": "\\documentclass{article}\n\\usepackage{enumerate}\n\\usepackage{amsmath, amsthm, amssymb}\n\\usepackage[margin=1in]{geometry}\n\\usepackage[parfill]{parskip}\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\n\\title{Econ C103 Problem Set 3}\n\\author{Sahil Chinoy}\n\n\\begin{document}\n\\maketitle{}\n\n\\subsection*{Exercise 1}\n\nConsider an incentive-compatible direct mechanism, and let $v(\\theta) = u(a(\\theta), \\theta)$. Since $v(\\theta)$ is uniformly continuous\n\n\\begin{equation}\nv(\\theta) = v(\\underline{\\theta}) + \\int \\limits_{\\underline{\\theta}} ^\\theta v'(s) \\, ds\n\\end{equation}\n\nIncentive compatibility requires that agents of type $\\theta$ weakly prefer to report their true type rather than any other type $\\theta'$, and vice versa\n\n\\begin{gather*}\nv(\\theta) \\geq u(a(\\theta'), \\theta) \\\\\nv(\\theta') \\geq u(a(\\theta), \\theta') \n\\end{gather*}\n\nThis implies, for $\\theta' \\neq \\theta$\n\n\\begin{equation*}\n\\frac{u(a(\\theta'), \\theta) - u(a(\\theta'), \\theta')}{\\theta - \\theta'} \\leq \\frac{v(\\theta) - v(\\theta')}{\\theta - \\theta'} \\leq \\frac{u(a(\\theta), \\theta) - u(a(\\theta), \\theta')}{\\theta - \\theta'}\n\\end{equation*}\n\nTaking the limit as $\\theta' \\to \\theta$\n\n\\begin{gather*}\nu_\\theta(a(\\theta),\\theta) \\leq v'(\\theta) \\leq u_\\theta(a(\\theta),\\theta) \\\\\nv'(\\theta) = u_\\theta(a(\\theta),\\theta)\n\\end{gather*}\n\nSubstituting into (1)\n\n\\begin{gather}\nv(\\theta) = v(\\underline{\\theta}) + \\int \\limits_{\\underline{\\theta}} ^\\theta u_\\theta(a(s),s) \\, ds \\nonumber \\\\\nu(a(\\theta), \\theta) = u(a(\\underline{\\theta}), \\underline{\\theta}) + \\int \\limits_{\\underline{\\theta}} ^\\theta u_\\theta(a(s),s) \\, ds\n\\end{gather}\n\nBy the revelation principle, this characterization of incentive-compatible direct mechanisms applies to the set of outcomes of \\textit{all} mechanisms.\n\n\\subsection*{Exercise 2}\n\n\\begin{enumerate}[(a)]\n\n\\item\n\nWith $v(\\theta) = u((x,t),\\theta) = \\sqrt{x(\\theta)}\\theta - t(\\theta)$, we have $u_\\theta = \\sqrt{x(\\theta)}$, so from (2)\n\n\\begin{gather*}\n\\sqrt{x(\\theta)}\\theta - t(\\theta) = v(\\underline{\\theta}) + \\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds \\\\\nt(\\theta) = \\sqrt{x(\\theta)}\\theta - \\left( \\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds + v(\\underline{\\theta})  \\right)\n\\end{gather*}\n\n\\item\n\nThis structure implies that the utility of type $\\theta$ derived from participating in the mechanism is\n\n\\begin{equation*}\nv(\\theta) = \\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds + v(\\underline{\\theta})\n\\end{equation*}\n\nFor the participation constraint to hold, we need $v(\\theta) \\geq 0$ for all $\\theta$. We know that $x(\\theta)$ is monotonically increasing in incentive compatible direct mechanisms. This implies $\\sqrt{x(\\theta)}$ is increasing in $\\theta$, so $\\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds \\geq 0$ for any $\\theta > \\underline{\\theta}$. Thus for the participation constraint to hold, we simply require $v(\\underline{\\theta}) \\geq 0$.\n\n\\item \n\nThe information rent for type $\\theta$ is \n\n\\begin{equation*}\n\\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds\n\\end{equation*}\n\nThis is the utility derived from the agent's private information. Because the principal does not know the agent's type, they must incentivize the agent to reveal their type by paying an amount that makes it preferable to report $\\theta$ rather than any other $\\theta' < \\theta$, which is precisely the integral over every other type the agent \\textit{might} choose to report, $\\theta' \\in [\\underline{\\theta}, \\theta]$, of the marginal utility derived from the allocation if the agent were actually that type.\n\n\\item\n\nThe expected revenue is\n\n\\begin{align*}\n\\mathbb{E}[t(\\theta)] &= \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} f(\\theta) t(\\theta) \\, d\\theta \\\\\n&= \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} f(\\theta) \\left( \\sqrt{x(\\theta)}\\theta -  \\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds - v(\\underline{\\theta})  \\right) \\, d\\theta \\\\\n&= \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} f(\\theta) \\sqrt{x(\\theta)} \\, d\\theta - \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} f(\\theta) \\left( \\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds \\, \\right) d\\theta - v(\\underline{\\theta})\n\\end{align*}\n\nIntegrating by parts\n\n\\begin{align*}\n\\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} f(\\theta) \\left( \\int \\limits_{\\underline{\\theta}} ^\\theta \\sqrt{x(s)} \\, ds \\, \\right) d\\theta &= F(z) \\int \\limits_{\\underline{\\theta}}^z \\sqrt{x(s)} \\, ds \\bigg\\rvert_{z=\\underline{\\theta}}^{z=\\bar{\\theta}} - \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} F(\\theta) \\sqrt{x(\\theta)} \\, d\\theta \\\\\n&= \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}} (1 - F(\\theta)) \\sqrt{x(\\theta)} \\, d\\theta\n\\end{align*}\n\nSubstituting\n\n\\begin{align*}\n\\mathbb{E}[t(\\theta)] &= \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}}  f(\\theta) \\left( \\theta - \\frac{1-F(\\theta)}{f(\\theta)} \\right) \\sqrt{x(\\theta)} \\, d\\theta - v(\\underline{\\theta})\n\\end{align*}\n\nSince $\\mathbb{E}[t(\\theta)]$ is decreasing in $v(\\underline{\\theta})$, to maximize expected revenue subject to the participation constraint $v(\\underline{\\theta}) \\geq 0$, we set $v(\\underline{\\theta}) = 0$. Then\n\n\\begin{equation*}\n\\max \\{ \\mathbb{E}[t(\\theta)] \\} = \\int \\limits_{\\underline{\\theta}} ^{\\bar{\\theta}}  f(\\theta) \\left( \\theta - \\frac{1-F(\\theta)}{f(\\theta)} \\right) \\sqrt{x(\\theta)} \\, d\\theta\n\\end{equation*}\n\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "a547b5a11c5a050aa9cf22f2079c50299063b11c", "size": 5408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3/hw3.tex", "max_stars_repo_name": "sahilchinoy/econ103", "max_stars_repo_head_hexsha": "ab2ecbb759eb811e953157e7f04f5a003066a62c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-08T22:59:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-08T22:59:12.000Z", "max_issues_repo_path": "hw3/hw3.tex", "max_issues_repo_name": "sahilchinoy/econ103", "max_issues_repo_head_hexsha": "ab2ecbb759eb811e953157e7f04f5a003066a62c", "max_issues_repo_licenses": ["MIT"], "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": "sahilchinoy/econ103", "max_forks_repo_head_hexsha": "ab2ecbb759eb811e953157e7f04f5a003066a62c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-10-29T10:06:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-27T14:30:33.000Z", "avg_line_length": 47.0260869565, "max_line_length": 509, "alphanum_fraction": 0.6638313609, "num_tokens": 1742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.812867299704166, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6738172490226512}}
{"text": "\\section{Latent Spaces and Embeddings}\n\\label{sec:LatentSpacesAndEmbeddings}\n\n% ##############################################################################\n\\subsection{Learning Metric Embedding}\n\\label{ssec:LearningMetricEmbedding}\n\nAs Hermans~\\etal{}~\\cite{hermans2017triplet} describe, the goal of learning metric embedding is to learn a function $\\func{f_\\theta}{x}: \\mathbb{R}^F \\to \\mathbb{R}^D$ which maps semantically similar points from the data manifold in $\\mathbb{R}^F$ onto metrically close points in $\\mathbb{R}^D$. Analogously, $\\func{f_\\theta}{\\cdot}$ should map semantically different points in $\\mathbb{R}^F$ onto metrically distant points in $\\mathbb{R}^D$.\n\nSuppose the use of this transformation for vehicle \\gls{reid}. The corresponding embedding vector would be produced by a learned function that would map the images of vehicles into a latent space where images of the same vehicle would be mapped closer together. Moreover, such mapping should be invariant to variations in lighting conditions, vehicle rotations, and many others. Among other things, embedding trained this way can be used to produce a feature vector for classification, one-shot learning tasks~\\cite{koch2015siameseoneshot}, clustering~\\cite{schroff2015facenet}, face recognition~\\cite{parkhi2015deepface} and last, but not least, object \\gls{reid}~\\cite{kuma2019vehiclereid}.\n\n% ##############################################################################\n\\subsection{Embedding Vector Similarity}\n\\label{ssec:EmbeddingVectorSimilarity}\n\nThe two most common approaches to evaluating the degree of similarity between embedding vectors are Euclidean distance and cosine similarity. Let $\\vect{u}$ and $\\vect{v}$ be arbitrary $D$-dimensional vectors representing our embedding vectors. The Euclidean distance between the vector $\\vect{u}$ and $\\vect{v}$ is defined as\n\\begin{equation}\n    \\label{eq:EuclideanDistance}\n    \\euclnorm{\\vect{u} - \\vect{v}} =\n    \\sqrt{\n        \\sum_{i = 0}^{D} \\rbrackets{\\vect{u}_i - \\vect{v}_i}^2\n    },\n\\end{equation}\nand the cosine similarity is defined as\n\\begin{equation}\n    \\label{eq:CosineSimilarity}\n    \\func{\\cos \\angle}{\\vect{u}, \\vect{v}} =\n    \\func{\\cos}{\\theta} =\n    \\frac{\n        \\vect{u} \\cdot \\vect{v}\n    }{\n        \\euclnorm{\\vect{u}} \\euclnorm{\\vect{v}}\n    },\n\\end{equation}\nwhere $\\theta$ is the angle between the vectors $\\vect{u}$ and $\\vect{v}$.\n\n% ##############################################################################\n\\subsection{Siamese and Triplet Networks}\n\\label{ssec:SiameseAndTripletNetworks}\n\n% ------------------------------------------------------------------------------\n\\begin{figure}[t]\n    \\centering\n    \\begin{subfigure}[b]{0.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/theoretical_foundations/siamese_architecture.pdf}\n        \\caption[]{}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[b]{0.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/theoretical_foundations/triplet_architecture.pdf}\n        \\caption[]{}\n    \\end{subfigure}\n    \\caption[Contrastive and triplet loss]{Comparison of the Siamese \\imgpartdesc{a} and the triplet \\imgpartdesc{b} network architectures. The concept of weight sharing implies that only one set of model weights is trained.}\n    \\label{fig:SiameseAndTripletArchitectures}\n\\end{figure}\n% ------------------------------------------------------------------------------\n\nFor the upcoming discussion, let $\\func{D}{x, y}: \\mathbb{R}^D \\times \\mathbb{R}^D \\to \\mathbb{R}$ be a metric function measuring distances in the embedding space. Without a loss of generality, we resort to use of the Euclidean distance ($L_2$ norm), so $\\func{D}{x, y} = \\euclnorm{x - y}$.\n\n\\subsubsection{Contrastive Loss}\n\nConsider a sample $\\rbrackets{x_0, x_1, y}$, where $x_0$ and $x_1$ represent the input, and the label $y = 1$ if $x_0$ and $x_1$ belong to the same category, otherwise $y = 0$. Let $\\alpha$ be the margin representing the minimum distance in the metric space to separate positive from negative samples. The contrastive function for any sample is then defined as~\\cite{hadsell2006dimreduction}\n\\begin{equation}\n    \\label{eq:ContrastiveLoss}\n    \\func{\\mathcal{L}_{contr}}{\\theta} =\n    \\frac{1}{2}y\n    {\\func{D}{\\func{f_\\theta}{x_0}, \\func{f_\\theta}{x_1}}}^2 +\n    \\frac{1}{2}\n    \\rbrackets{1 - y} {\\rbrackets{\n            \\sbrackets{\\alpha - \\func{D}{\\func{f_\\theta}{x_0}, \\func{f_\\theta}{x_1}}}_{+}}}^2.\n\\end{equation}\nThe two inputs $x_0$ and $x_1$ are fed to the shared model at the same time. The output is then evaluated by the contrastive loss function (\\figtext{}~\\ref{fig:SiameseAndTripletArchitectures} \\imgpartdesc{a}). Positive samples should have a small distance between each other as measured by the $\\func{D}{\\cdot}$ to decrease the loss towards $0$. Conversely, negative samples should have a distance beyond the threshold $\\alpha$.\n\n\\subsubsection{Triplet Loss}\n\nApart from the contrastive loss, this time three samples are required to compute the loss. The rationale is to supply additional context when forming the metric space. Siamese networks are usually implemented using shared model weights, but there are better approaches when the triplet loss is used. Conceptually speaking, the model could be implemented as shown in \\figtext{}~\\ref{fig:SiameseAndTripletArchitectures} \\imgpartdesc{b}. However, as we will discuss later, triplet mining strategies are required for the triplet loss to work properly.\n\nLet $N$ be the number of all possible valid triplets $\\rbrackets{x_a^i, x_p^i, x_n^i}$ for a given dataset. For any $i$-th triplet, let $x_a^i$ be the \\emph{anchor} for a specific object (person, vehicle, etc.) with label $\\func{y}{x_a^i}$, $x_p^i$ be the positive sample of the same object with label $\\func{y}{x_p^i}$, such that $x_a^i \\neq x_p^i \\land \\func{y}{x_a^i} = \\func{y}{x_p^i}$, and let $x_n^i$ with label $\\func{y}{x_n^i}$ be a sample of any other object, satisfying $\\func{y}{x_a^i} \\neq \\func{y}{x_n^i}$, $\\forall i = 1, \\dots, N$. Let $\\alpha$ be the margin value that is enforced between positive and negative pairs. Then, we want the relationship\n\\begin{equation}\n    \\label{eq:TripletDistanceConstraint}\n    \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}} + \\alpha < \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_n^i}}, \\forall i = 1, \\dots, N,\n\\end{equation}\nto hold true. The triplet loss function is therefore defined as\n\\begin{equation}\n    \\label{eq:TripletLoss}\n    \\func{\\mathcal{L}_{triplet}}{\\theta} =\n    \\sum_{i = 1}^{N}\n    {\\sbrackets{\n        \\alpha +\n        \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}} -\n        \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_n^i}}\n    }}_+.\n\\end{equation}\nDuring the training, the model should learn to push negative samples further away from the positive samples, ideally exceeding the margin $\\alpha$. When a negative sample is mapped closer than a positive sample, the training should result in the desired situation of bringing the positive sample closer while pushing the negative one further (\\figtext{}~\\ref{fig:TripletLossLearningProcess}).\n\n% ------------------------------------------------------------------------------\n\\begin{figure}[t]\n    \\centerline{\\includegraphics[width=0.6\\linewidth]{figures/theoretical_foundations/triplet_loss_learning_process.pdf}}\n    \\caption[Triplet loss learning]{The objective is to learn embeddings such that the anchor is closer to the positive example than it is to the negative example by some specified margin value. \\externalsrc{\\cite{schroff2015facenet}}}\n    \\label{fig:TripletLossLearningProcess}\n\\end{figure}\n% ------------------------------------------------------------------------------\n\n% ##############################################################################\n\\subsection{Triplet Mining Strategies}\n\\label{ssec:TripletMiningStrategies}\n\nContrastive (\\eqtext{}~\\ref{eq:ContrastiveLoss}) and triplet (\\eqtext{}~\\ref{eq:TripletLoss}) loss functions play an important role in training an embedding model. However, the way that pairs or triplets are selected is crucial as it may significantly influence the training~\\cite{hermans2017triplet, manmatha2017samplingmatters}. Moreover, as the dataset gets larger, then the number of possible triplets grows cubically, rendering the use of all of them impractical. The majority of those triplets would be so-called \\emph{easy triplets}. To paraphrase the analogy from~\\cite{hermans2017triplet}, showing the model that people with different clothes are not the same person after a certain point does not bring any new information. On the other hand, explicitly \\emph{mining} images of similar-looking yet different people with the same clothes (\\emph{hard negatives}) or of the same person with dramatically different poses (\\emph{hard positives}) vastly contributes to an understanding of the notion of the \\emph{same person}. As suggested, there are different kinds of triplets which are defined in \\tabletext{}~\\ref{tab:TripletCategoriesDefinitions}, using a general $\\rbrackets{x_a^i, x_p^i, x_n^i}$ triplet for clarity. We encourage the reader to observe \\figtext{}~\\ref{fig:PositiveAndNegativeTripletsCategories}, too.\n\n\\begin{table}[t]\n    \\centering\n\n    \\begin{tabular}{cc}\n        \\toprule\n        \\tblcolname{triplet} & \\tblcolname{constraint}                                                                                                                                            \\\\\n\n        \\midrule\n        \\emph{easy}          &\n        $\\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}} + \\alpha < \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_n^i}}$                                                            \\\\\n\n        \\emph{semi-hard}     &\n        $\\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}} < \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_n^i}} < \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}} + \\alpha$ \\\\\n\n        \\emph{hard}          & $\\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_n^i}} < \\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}}$                                              \\\\\n        \\bottomrule\n    \\end{tabular}\n\n    \\caption[Triplet categories.]{Definitions of various categories of triplets (regardless whether it is positive or negative) as imposed by their distance relationship.}\n    \\label{tab:TripletCategoriesDefinitions}\n\\end{table}\n\n% ------------------------------------------------------------------------------\n\\begin{figure}[t]\n    \\centering\n    \\begin{subfigure}[b]{0.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/theoretical_foundations/triplet_positives_categories.pdf}\n        \\caption[]{}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/theoretical_foundations/triplet_negatives_categories.pdf}\n        \\caption[]{}\n    \\end{subfigure}\n    \\caption[Triplet loss categories visualization.]{Given a fixed anchor $x_a^i$ and positive sample $x_p^i$ as well as some positive margin value $\\alpha$, we discriminate between three different types of categories in terms of their level of \\emph{difficulty}. These categories vary in relation to positive \\imgpartdesc{a} or negative \\imgpartdesc{b} perspective.}\n    \\label{fig:PositiveAndNegativeTripletsCategories}\n\\end{figure}\n% ------------------------------------------------------------------------------\n\nIn order to attain an effective convergence during the training, it is necessary to select triplets that violate the triplet constraint in \\eqtext{}~\\ref{eq:TripletDistanceConstraint}. This means that given $x_a^i$, the goal is to select a \\emph{hard positive} $x_p^i$ given by $\\argmax_{x_p^i}\\cbrackets{\\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_p^i}}}$ and a \\emph{hard negative} $x_n^i$ as a result of $\\argmin_{x_n^i}\\cbrackets{\\func{D}{\\func{f_\\theta}{x_a^i}, \\func{f_\\theta}{x_n^i}}}$. Admittedly, it is often infeasible to compute the $\\argmin\\cbrackets{\\cdot}$ and $\\argmax\\cbrackets{\\cdot}$ over the entire training set. In this regard, there are two possible approaches to tackle this problem, either by selecting these hard triplets online or doing it offline~\\cite{schroff2015facenet}.\n\n\\subsubsection{Offline Triplet Mining}\n\nGiven a training set, the task is to produce reasonable triplets off-line, for instance, at the epoch beginning. First, a list of $N$ different valid triplets is randomly generated, then separated into $\\lfloor \\nicefrac{N}{B} \\rfloor$ batches of $B$ triplets, followed by computation of $3N$ embeddings using the most recent model checkpoint. Then, hard or semi-hard triplets may be selected. Since this strategy has been shown on multiple occasions~\\cite{schroff2015facenet, hermans2017triplet, kuma2019vehiclereid} as an inferior choice compared to online triplet mining, we will not discuss this approach further.\n\n\\subsubsection{Online Triplet Mining}\n\nOnline mining is performed by selecting the hard positive/negative exemplars from within a minibatch (\\figtext{}~\\ref{fig:TripletArchitectureOnlineMining}). A condition that minimum number of exemplars for any identity is present in each minibatch has to be met. For example, Schroff~\\etal{}~\\cite{schroff2015facenet} used $40$ different images of a single person (an identity) per minibatch. Let $P$ be the number of different objects/identities (\\egtext{}, people, vehicles) and $K$ be the number of different images for a concrete identity (\\egtext{} different views of the same vehicle). There are two prominent approaches to online mining: \\emph{batch all} and \\emph{batch hard}.\n\n% ------------------------------------------------------------------------------\n\\begin{figure}[t]\n    \\centerline{\\includegraphics[width=0.5\\linewidth]{figures/theoretical_foundations/triplet_architecture_online_mining.pdf}}\n    \\caption[Triplet loss online mining architecture]{A triplet network with an online triplet loss function. In this architecture, no weight sharing is required as the triplet selection happens \\emph{online} solely in the loss function.}\n    \\label{fig:TripletArchitectureOnlineMining}\n\\end{figure}\n% ------------------------------------------------------------------------------\n\n\\subsubsection{Online Triplet Mining: Batch All}\n\nThis strategy aims for selecting all valid triplets and averaging the loss only on the hard and semi-hard triplets. Easy triplets, \\ietext{}, those for which the loss function equals $0$, are not taken into account. The reason is that averaging on them would result in a very small loss, since they would usually vastly outnumber the set of hard triplets~\\cite{hermans2017triplet}. This approach produces a total of $PK \\rbrackets{K - 1} \\rbrackets{PK - K}$ triplets ($PK$ anchors, $K - 1$ positives per anchors, $PK - K$ negatives) incorporated in the loss function as\n\\begin{equation}\n    \\label{eq:BatchAllLossFunction}\n    \\begin{aligned}\n        \\func{\\mathcal{L}_{batchall}}{\\theta} =\n        \\sum_{i = 1}^P\n        \\sum_{a = 1}^K\n        \\sum_{\\substack{p = 1 \\\\p \\neq a}}^K\n        \\sum_{\\substack{j = 1 \\\\j \\neq i}}^P\n        \\sum_{n = 1}^K\n        \\Bigg[\n         & \\alpha +           \\\\\n         & \\func{D}{\n            \\func{f_\\theta}{x_a^i},\n            \\func{f_\\theta}{x_p^i}\n        } -                   \\\\\n         & \\func{D}{\n            \\func{f_\\theta}{x_a^i},\n            \\func{f_\\theta}{x_n^j}\n        }\n        {\\Bigg]}_{+}.\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Online Triplet Mining: Batch Hard}\n\nIn this strategy, the goal is to find the hardest positive and hardest negative for each anchor. The total number of triplets is $PK$. The selected triplets are the hardest among the given batch and can be considered moderate since they are the hardest within a small subset of the data. Therefore, the mining can be formulated as\n\\begin{equation}\n    \\label{eq:BatchHardMining}\n    \\begin{aligned}\n        \\func{\\mathcal{L}_{batchhard}}{\\theta} =\n        \\sum_{i = 1}^P\n        \\sum_{a = 1}^K\n        \\Bigg[\n         & \\alpha +                            \\\\\n         & \\underset{p = 1, \\dots, K} {\\max}\n        \\cbrackets{\n            \\func{D}{\n                \\func{f_\\theta}{x_a^i},\n                \\func{f_\\theta}{x_p^i}\n            }\n        } -                                    \\\\\n         & \\underset{\\substack{j = 1, \\dots, P \\\\n = 1, \\dots, K\\\\j \\neq i}} {\\min}\n        \\cbrackets{\n            \\func{D}{\n                \\func{f_\\theta}{x_a^i},\n                \\func{f_\\theta}{x_n^j}\n            }\n        }\n        {\\Bigg]}_{+}\n    \\end{aligned}\n\\end{equation}\n", "meta": {"hexsha": "efb9a83afdf7e941f29a4aae56df36425bf22d42", "size": 16669, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/chapters/theoretical_foundations/sections/embeddings.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/embeddings.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/embeddings.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": 74.4151785714, "max_line_length": 1327, "alphanum_fraction": 0.6592477053, "num_tokens": 4458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6737193509340668}}
{"text": "% !TEX root = altosaar-2020-thesis.tex\n\\chapter{Background}\n\\label{ch:background}\n\\lettrine[image=true,lines=3]{design/T}{his} chapter describes probabilistic models and probabilistic inference, taking as examples models from statistical physics and recommender systems.\n\n\\input{fig/fig_graphical_model_ising}\n\n\\section{Probabilistic Models}\nProbability models assign probability to configurations of random variables. The random variables in a probability model might correspond to observed variables in a physical system, or to latent properties representing patterns in data collected from the world, or a combination of both. To define a probability model, it is necessary to specify the density $p$ of a collection of random variables $\\mbz$. We focus on probabilistic models $p(\\mbz)$ where relationships between random variables can be encoded as edges in a graph, or  probabilistic graphical models~\\citep{jordan2004graphical}.\n\n\\subsection{Example: Ising Model}\n\\label{sec:ising}\nFor example, consider a model used in statistical physics: the Ising model. The Ising model can be used to model interactions between atoms in a material~\\citep{henelius2016refrustration} to study how the material behaves in different conditions, paving the way toward material design. This probabilistic model has binary random variables $z_n$ with density\n\\begin{equation}\n  p(\\mbz; \\beta) = \\frac{\\exp(-\\beta E(\\mbz))}{\\cZ}\\, .\n  \\label{eq:boltzmann}\n\\end{equation}\nThe semicolon in \\Cref{eq:boltzmann} denotes that the model has a parameter $\\beta$, representing the reciprocal temperature of the system of random variables (a physical quantity). The energy function $E(\\mbz)$ encodes the relationships between random variables, and $\\cZ$, the normalizing constant, ensures that this probability distribution sums to one over all configurations of random variables~\\citep{chandler1987introduction}. The energy function of the Ising model is\\footnote{Bold letters can denote collections of random variables $\\mbz = \\{z_1, z_2,...,z_N\\}$, or vectors, depending on the context.}\n\\begin{equation}\n\\label{eq:ising-energy}\n  E(\\mbz) = -\\frac{1}{2}\\sum_{i, j} J_{ij}z_i z_j - H\\sum_i z_i\\, .\n\\end{equation}\nThe interaction strength $J_{ij}$ defines the interactions between random variables. In a simple Ising model, only nearest neighbors interact, so $J_{ij}$ is nonzero if the random variables $z_i$ and $z_j$ are neighbors. The parameter $H$ increases or decreases the energy in proportion to the values of the random variables $z_i$; we give its physical interpretation later.\n\nThe Ising model can be represented as a probabilistic graphical model, shown in \\Cref{fig:graphical-model-ising}. Two variables $z_i$ and $z_j$ interact (changing the value of one leads to a change in probability of the other) only if they share an edge in the graph. This representation works in conjuction with the density in \\Cref{eq:boltzmann}, as the presence of an edge in the graph corresponds to two variables interacting in the energy function $E$. In this model, the energy function (and hence graph) is such that only neighboring random variables interact.\n\nThe Ising model can be used to study physical systems such as magnetic materials, where interactions between atoms can be encoded into the interaction strength $J_{ij}$. The interactions between random variables encoded in this manner contain the necessary information to model the properties of a material. In modeling a material, the random variables $\\mbz$ can be referred to as spins. Spin is a type of angular momentum carried by particles comprising atoms, and such angular momentum causes a magnetic field. Although the random variables $\\mbz$ are binary, taking on values of $-1$ and $+1$, they can be re-scaled to the magnetic strength of the atoms in a particular material of interest if comparison to experimental data is required. The parameter $H$ can be interpreted as the magnitude of an external magnetic field that interacts with the magnetic strength and orientation of every atom~\\citep{chandler1987introduction}.\n\nTo see how well an Ising model mirrors a physical material, a property such as magnetization can be measured in the material, and calculated using the model. Magnetization is the average orientation of the magnetic strength of every atom or random variable in the material,\n\\begin{equation}\n  M(\\mbz) = \\frac{1}{N}\\sum_{i=1}^N z_i\\, .\n\\end{equation}\nBy measuring the magnetization $M$ and computing its value in the Ising model, a practitioner can deduce how accurately the model reproduces experimental data. For example, if an Ising model with nearest neighbors ($J_{ij} \\neq 0$ if $i$ neighbors $j$) does not accurately reproduce the magnetization of a physical material, it may be necessary to include second-nearest neighbor effects ($J_{ij}\\neq 0$ if $i$ and $j$ are connected by a path of length at most two).\n\nAnother example of a quantity that can be measured experimentally and computed in a probabilistic model is the thermodynamic free energy $F$,\n\\begin{equation}\n  \\label{eq:free-energy}\n  F = -\\frac{1}{\\beta} \\log \\cZ\\, .\n\\end{equation}\nThe free energy of a system relates to the amount of energy that can be extracted from a system by its surroundings. For example, the free energy of a protein is used to understand its stability, and can be measured by the amount of energy needed to destroy its structure by denaturing it~\\citep{stone2013the-theory}. In modeling a magnetic material or biological material, the free energy can be derived from the normalizing constant $\\cZ$~\\citep{chandler1987introduction}.\n\n\\input{fig/tab_example_meals_regression}\n\\subsection{Example: Binary Classification}\n\\input{fig/fig_graphical_model_regression}\nAnother example of a probabilistic model is a binary classifier~\\citep{bishop2006pattern}, represented as a graphical model in \\Cref{fig:graphical-model-regression}. Consider $N$ datapoints of the form $(x_n, y_n)$ consisting of covariates $x_n$ and binary responses $y_n$. As illustrated in \\Cref{tab:example-binary}, the covariates $x_n$ might represent information about items such as foods in a meal, and $y_n$ may indicate whether a single user ate a meal with those foods. A binary classifier would then classify whether the user would eat a new meal $\\hat{x}_n$ based on its constituent foods.\n\nA binary classifier is defined using a regression function $f$ with parameters $\\mbtheta$. The logistic function $\\sigma$ applied to the regression function defines the probability model for a binary classifier,\n\\begin{equation}\n  p(y_n \\mid x_n; \\mbtheta) = \\frac{\\exp\\left( \\sigma(f(x_n; \\mbtheta)) \\cdot y_n\\right)}{\\cZ}\\, .\n  \\label{eq:binary-classification}\n\\end{equation}\nThe logistic function constrains the output of $f$ to the unit interval, and $\\cZ$ is again the normalizing constant. The regression function $f$ uses information about a datapoint to classify whether the response $y_n$ is positive. An example of a regression function is an inner product, defined by\n\\begin{equation}\n  f(x_n; \\mbtheta) = \\mbtheta^\\top x_n\\, ,\n\\end{equation}\nwhich corresponds to logistic regression~\\citep{bishop2006pattern}. Alternatively, a more flexible model can be built using a deep neural network~\\citep{lecun2015deep}.\n%A binary classifier can form the basis of a recommender system as we study in \\Cref{ch:rfs}.\n\n\\section{Inference}\nIn a probability model, computing---or, inferring---properties of the probability distribution is a central task. One inference problem is to ascertain likely configurations of random variables. Another is to compute the sum of a probability distribution over a set of random variables, for example, to compute the normalizing constant~\\citep{jordan2004graphical}.\n\n\\subsection{Computing Likely Configurations of Random Variables}\nIn the study of a probability model such as a binary classifier in \\Cref{eq:binary-classification}, one question of interest is: for a set of observations $(x_n, y_n)$, what is a likely value of $\\theta$? Maximum likelihood estimation is one way to answer this question~\\citep{bishop2006pattern}.\n\nA probability distribution like $p(\\mby \\mid \\mbx; \\mbtheta)$ is also known as a likelihood function. It defines the likelihood of a random variable $\\mby$ conditional on the value of data $\\mbx$, with the current setting of the parameters $\\mbtheta$. The maximum likelihood estimate of the parameters of this probability model for the data $(\\mbx, \\mby)$ is given by\n\\begin{equation}\n  \\mbtheta^* = \\argmax_{\\mbtheta} p(\\mby \\mid \\mbx; \\mbtheta)\\, .\n\\end{equation}\nThis maximum likelihood estimate of the parameters $\\mbtheta^*$ can be computed using stochastic optimization if the data is large~\\citep{robbins1951a-stochastic}. % what if the argmax is intractable, or an integral? #todo details\n\n\\subsection{Computing the Normalizing Constant}\n\nThe second central inference task in probabilistic modeling is summing a probability model over a set of random variables. One example of this is computing the normalizing constant $\\cZ$. This inference problem requires computing a sum: the normalizing constant ensures a probability distribution sums to $1$ over values the random variables can take.\n\nConsider computing the normalizing constant for the binary classifier in \\Cref{eq:binary-classification}.  To compute the normalizing constant $\\cZ$ for this probability model, we can sum over the binary values the random variable $y_n$ can take,\n\\begin{align}\n1 &= \\sum_{y_n \\in \\{0, 1\\}} \\frac{\\exp\\left( \\sigma(f(x_n; \\mbtheta)) \\cdot y_n\\right)}{\\cZ} \\\\\n\\Rightarrow \\cZ &= \\sum_{y_n \\in \\{0, 1\\}} \\exp\\left( \\sigma(f(x_n; \\mbtheta) \\cdot y_n)\\right)\\\\\n\\cZ &= 1 + \\exp\\left( \\sigma(f(x_n; \\mbtheta))\\right)\\, .\n\\end{align}\nInference of the normalizing constant $\\cZ$ is straightforward in this probability model. The random variable $y_n$ is binary, so there are only two terms in the sum needed to compute the normalizing constant.\n\nNext, consider computing the normalizing constant or partition function for the Ising model in \\Cref{eq:boltzmann}. The random variables $z_n$ in this model also take on binary values. The partition function is computed by summing over all the values associated with all random variables in the system, $\\mbz = \\{z_1, \\ldots, z_N\\}$:\n\\begin{align}\n1 &= \\sum_{z_1 \\in \\{-1, +1\\}} \\ldots \\sum_{z_N \\in \\{-1, +1\\}} \\frac{\\exp(-\\beta E(\\mbz))}{\\cZ}\\\\\n\\Rightarrow \\cZ &= \\sum_{z_1 \\in \\{-1, +1\\}} \\ldots \\sum_{z_N \\in \\{-1, +1\\}} \\exp(-\\beta E(\\mbz))\\, .\n\\label{eq:intractable-partition}\n\\end{align}\nThere are $N$ binary-valued random variables and $2^N$ terms in the sum required to compute the partition function, so inference in the Ising model is difficult. For Ising models used to study materials, the partition function is intractable to compute for most model sizes practitioners want to study and compare to physical realizations.\n\nOne way to address the issue of an intractable partition function is with sampling methods, such as Markov chain Monte Carlo~\\citep{metropolis1953equation}. These algorithms enable inference by simulating likely configurations of random variables. These samples of likely configurations are used to approximate quantities of interest such as the partition function. But, Markov chain Monte Carlo methods are difficult to scale to probabilistic models with large numbers of correlated random variables. In this thesis, we instead use variational inference, an approximate inference algorithm that relies on optimization instead of sampling.\n% Calculating the partition function can be difficult, and there are many ways around computing the partition function. For example, sampling methods and variational methods can be used to approximate properties of distributions such as properties derived from the partition function. Markov chain Monte Carlo~\\citep{metropolis1953equation} allows sampling system configurations from the Boltzmann distribution of a model; these samples can be used to approximate physical quantities. Variational inference relies on optimizing (varying) functionals to derive approximations of distributions of interest, these approximations can be used to compute properties of a model. Variational inference has roots in mean field methods in physics~\\citep{saul1996mean,hoffman2013stochastic,blei2017variational} as described in \\Cref{ch:background}.\n\n\\section{Variational Inference}\n\\input{fig/fig_vi_cartoon}\nInstead of working with a probability model $p(\\mbz)$ directly, \\acrfull{vi} posits a family of distributions $q(\\mbz; \\mblambda)$ indexed by parameters $\\mblambda$~\\citep{blei2017variational}. The goal of \\gls{vi} is to find the closest member of the variational family $q$ to the target distribution $p$. The algorithm consists of varying the parameters $\\mblambda$ to improve the quality of the approximation, as illustrated in \\Cref{fig:vi-cartoon}. One way to measure the distance between the variational approximation and the target distribution is with the \\acrfull{kl} divergence, or relative entropy~\\citep{mackay2003information,ranganath2018black}.\n\nThe intractable partition function in $p(\\mbz)$ appears in the \\gls{kl} divergence \\gls{vi} uses to assess distance,\n\\begin{equation}\n\\label{eq:kl}\n    \\KL{q(\\mbz; \\mblambda)}{p(\\mbz)} = \\E_q[\\log q(\\mbz ; \\mblambda)] -\\E_q[\\log p(\\mbz)] \\\\\n\\end{equation}\nBut it is possible to derive an objective function that does not depend on the partition function, starting from the \\gls{kl} divergence. Taking the Ising model in \\Cref{eq:boltzmann} as an example,\n\\begin{align}\n  \\KL{q(\\mbz; \\mblambda)}{p(\\mbz)} &= \\E_q[\\log q(\\mbz ; \\mblambda)] -\\E_q[\\log p(\\mbz)] \\\\\n \\KL{q(\\mbz; \\mblambda)}{p(\\mbz)} &= \\E_q[\\log q(\\mbz ; \\mblambda)] -\\E_q[-\\beta E(\\mbz) - \\log \\cZ] \\\\\n \\log \\cZ &= \\E_q[-\\beta E(\\mbz)] - \\E_q[\\log q(\\mbz ; \\mblambda)] + \\KL{q(\\mbz; \\mblambda)}{p(\\mbz)} \\label{eq:second-last}  \\\\\n \\Rightarrow \\log \\cZ \\geq \\cL(\\mblambda) &\\coloneq  \\E_q[-\\beta E(\\mbz)] - \\E_q[\\log q(\\mbz ; \\mblambda)]\\, .\n \\label{eq:llbo}\n\\end{align}\nThis lower bound $\\cL$ on the log normalizing constant is also called the \\acrfull{elbo}, and serves as the objective function for \\gls{vi}. In deriving this lower bound from \\Cref{eq:second-last} to \\Cref{eq:llbo}, we used the fact that the \\gls{kl} is greater than or equal to zero. To show this fact, we start from Jensen's inequality for a convex function $f$, or\n\\begin{equation}\n  f(\\E[\\mbz]) \\leq \\E[f(\\mbz)]\\, .\n\\end{equation}\nThe logarithm in the \\gls{kl} is concave, so its negative is convex. We apply Jensen's inequality to the negative \\gls{kl} in \\Cref{eq:kl}:\n\\begin{align}\n  -\\KL{q(\\mbz)}{p(\\mbz)} &= \\E_q\\left[\\log \\frac{p(\\mbz)}{q(\\mbz )}\\right] \\\\\n  &\\leq \\log \\E_q\\left[\\frac{p(\\mbz)}{q(\\mbz )}\\right]\\\\\n  &= \\log \\int  q(\\mbz) \\frac{p(\\mbz)}{q(\\mbz )}d\\mbz \\\\\n  &= \\log \\int  p(\\mbz)d\\mbz \\\\\n  &= 0 \\, .\n\\end{align}\nThis shows that the \\gls{kl} is greater than or equal to zero~\\citep{cover2012elements}.\n\nThe left-hand-side in \\Cref{eq:llbo} does not change as the variational parameters $\\mblambda$ are varied in $\\cL(\\mblambda)$. In words, maximizing the lower bound $\\cL(\\mblambda)$ is equivalent to minimizing the \\gls{kl} divergence between the variational approximation and target probability model.\n\n\\subsection{Example: Mean Field Variational Inference in the Ising model}\n\\label{sec:ising-mean-field}\n\nTo demonstrate \\gls{vi}, we use the Ising model described in \\Cref{sec:ising} with probability distribution $p(\\mbz)$ defined in \\Cref{eq:boltzmann} and energy function $E(\\mbz)$ in \\Cref{eq:ising-energy}. Inspecting the intractable partition function of the Ising model can help construct a variational family $q(\\mbz; \\mblambda)$ to approximate the Ising model.\n\nThe Ising model partition function in \\Cref{eq:intractable-partition} is intractable because the sums do not decompose by random variables: every sum must be carried out in order, because the result of the $N$th sum over the random variable $z_N$ depends on the results of the sums over the previous $N-1$ random variables. This is because of interactions between dependent random variables. The first term in the energy function of the Ising model represents nearest neighbor interactions, $z_iz_j$, and is graphically equivalent to the links between nearest neighbors in \\Cref{fig:graphical-model-ising}.\n\nHowever, the second term in the Ising energy function in \\Cref{eq:ising-energy}, $H\\sum_i z_i$, does decompose by random variable. Physically, this corresponds to a magnetic field applied to the system as a whole, so every random variable is subject to the same force. Mathematically, there is an outer sum over every configuration of random variables, and in this term the results of the summation over a variable $z_i$ do not affect the summation over another variable $z_j$. So this magnetic field term can be evaluated for systems with many random variables.\n\n\\input{fig/fig-ising-markov-blanket}\nThe structure of the Ising model energy function and corresponding graphical model can be used to build a variational approximation $q(\\mbz; \\mblambda)$ as follows. If the second term of the Ising model energy function does not lead to an intractable partition function due to every random variable being subject to a magnetic field, one can construct a variational approximation by extending this physical intuition and developing the concept of a `mean field'. Consider the central random variable $z_i$ in \\Cref{fig:graphical-model-ising}. Fixing the values of its nearest neighbors renders this random variable independent of the rest of the graph as shown in \\Cref{fig:markov-blanket-ising}. The nearest neighbors of the central random variable can then be interpreted as giving rise to a magnetic field. The strength of this magnetic field is unknown, so we can define this unknown strength as a variational parameter $\\delta H$ that we will infer using \\gls{vi}. This mean field is additive to the external magnetic field $H$ applied to the system as a whole, so the energy function for the central random variable $z_i$ under this mean field assumption can be written\n\\begin{equation}\n  E_{\\mf}(z_i; \\delta H) = \\delta H z_i + H z_i\\, .\n\\end{equation}\nNote that we have replaced the interaction term $J_{ij} z_iz_j$ in the Ising model energy function in \\Cref{eq:ising-energy} by the mean field $\\delta H$. The mean field assumption is that term can approximate the effects of neighboring nodes~\\citep{chandler1987introduction}. If we repeat this argument for every node in the graph, we arrive at the mean field energy function\n\\begin{equation}\n  E_{\\mf}(\\mbz; \\delta H) = -(H + \\delta H)\\sum_{i = 1}^N z_i\\, .\n  \\label{eq:mean-field-energy}\n\\end{equation}\nThe above construction starting from the mean field assumption corresponds to the variational approximation with density\n\\begin{equation}\n  q(\\mbz; \\beta, \\delta H) = \\prod_{i=1}^N\\frac{\\exp(- \\beta E_\\mf(z_i; \\delta H))}{\\cZ_\\mf} \\, ,\n  \\label{eq:mean-field-distribution}\n\\end{equation}\nand we see that the variational parameter $\\mblambda$ is simply the mean field strength $\\delta H$. The mean field variational approximation corresponds to a fully factorized probability distribution where every random variable is independent~\\citep{wainwright2008graphical}. This is a useful property, as the partition function is tractable in this mean field variational approximation: we can compute the partition function for every random variable by itself. The partition function for a single random variable $z_i$ under the mean field assumption is straightforward,\n\\begin{align}\n  \\cZ_\\textrm{\\mf, i} &= \\sum_{z_i \\in \\{-1, +1\\}} \\exp(- \\beta (H + \\delta H) z_i) \\\\\n  &= 2 \\cosh (\\beta (H + \\delta H)) \\, ,\n  \\label{eq:partition-function-i}\n\\end{align}\nand the partition function for the variational approximation for all variables is simply $\\cZ_\\mf = \\cZ_\\textrm{\\mf, i}^N$. Similarly, the average of a random variable under the variational distribution is readily computed as\n\\begin{align}\n\\begin{split}\n  \\E_{q(z_i)}[z_i] &= \\sum_{z_i \\in \\{-1, +1\\}} \\frac{z_i \\exp(- \\beta E_\\mf(z_i; \\delta H))}{\\cZ_\\textrm{\\mf, i}} \\\\\n &= \\sum_{z_i \\in \\{-1, +1\\}} \\frac{z_i \\exp(- \\beta (H + \\delta H) z_i)}{2 \\cosh(\\beta (H + \\delta H))} \\\\\n &= -\\tanh(\\beta (H + \\delta H))\\, .\n \\label{eq:mf-mean}\n \\end{split}\n\\end{align}\nNow that we have constructed a variational family for the Ising model, we can proceed with the \\gls{vi} algorithm. The next step is writing down and maximizing the lower bound on the log partition function to minimize the \\gls{kl} between our approximating distribution and model.\n\nThe lower bound on the log partition function $\\cL(\\delta H)$  in \\Cref{eq:llbo} becomes\n\\begin{align}\n  \\cL(\\delta H) &= \\E_q[-\\beta E(\\mbz)] - \\E_q[\\log q(\\mbz; \\delta H)] \\\\\n  &= \\E_q\\left[-\\frac{1}{2}\\beta\\sum_{i, j} J_{ij}z_i z_j - \\beta H\\sum_i z_i\\right] - \\E_q\\left[ -\\beta (H + \\delta H)\\sum z_i\\right] + \\log \\cZ_{\\mf} \\\\\n  &= \\E_q\\left[-\\frac{1}{2}\\beta\\sum_{i, j} J_{ij}z_i z_j + \\beta\\delta H\\sum_i z_i\\right] + \\log \\cZ_{\\mf}\\, ,\n\\intertext{and we can take the expectation inside the sum using the fact that the mean field variational distribution is fully factorized, so }\n  \\cL(\\delta H) &= -\\frac{1}{2}\\beta \\sum_{i, j}J_{ij}\\E_{q(z_i)}[z_i]\\E_{q(z_j)}[z_j] + \\beta \\delta H \\sum_i \\E_{q(z_i)} [z_i] + \\log \\cZ_{\\mf}\\, .\\\\\n\\end{align}\nIn the first term, recall that two random variables $z_i$ and $z_j$ have the same distribution under the mean field assumption, and that every variable interacts with its four nearest neighbors in the Ising model. The lower bound on the log partition function then becomes\n\\begin{align}\n \\cL(\\delta H) &= -\\frac{1} {2} \\beta 4JN \\E_{q(z_i)}[z_i]^2 + \\beta N \\delta H \\E_{q(z_i)} [z_i] + \\log \\cZ_{\\mf}\\, .\n\\end{align}\nThe next step in the \\gls{vi} algorithm is maximizing this lower bound, to minimize the \\gls{kl} divergence between the variational approximation and the model. Taking the derivative with respect to $\\delta H$ and suppressing the subscript of the expectation operator, we get\n\\begin{align}\n\\frac{\\partial\\cL(\\delta H)}{\\partial \\delta H} &= N\\beta(-4J\\E[z_i]\\partial_{\\delta H}\\E[z_i] + \\E[z_i] + \\delta H \\partial_{\\delta H} \\E[z_i]) + N\\beta \\tanh(\\beta (H + \\delta H))\\, .\n\\end{align}\nNext, setting this derivative to zero and cancelling out terms (and using \\Cref{eq:mf-mean}) leads to\n\\begin{align}\n 0 &= -4J\\E[z_i]\\partial_{\\delta H}\\E[z_i] + \\delta H \\partial_{\\delta H} \\E[z_i]) \\\\\n \\Rightarrow \\delta H \\partial_{\\delta H} \\E[z_i]) &= 4J\\E[z_i]\\partial_{\\delta H}\\E[z_i] \\\\\n \\Rightarrow \\delta H^* &= 4J\\E[z_i]\\, .\n\\end{align}\nThis shows that under a mean field assumption, the variational parameter that maximizes the lower bound on the log partition function---and hence minimizes the \\gls{kl} divergence between the approximation and model---is proportional to the mean field around any node in the system. The structure of the model informs our choice of variational approximation.\n\nThe quality of the variational approximation $q(\\mbz; \\beta, \\delta H^*)$ from \\gls{vi} can be assessed in several ways. For example, the magnetization $M$ or the free energy $F$ can be calculated using the variational approximation, and these values can be compared to Markov Chain Monte Carlo simulations in small systems. This can be viewed as a type of predictive check for a \\gls{vi} algorithm~\\citep{blei2014build}. However, the development of theoretical guarantees to assess the quality of variational approximations found with \\gls{vi} is an open area of research~\\citep{wang2019frequentist}. Practitioners must currently empirically evaluate the quality of variational approximations according to the task at hand, as we do in \\Cref{ch:hvm,ch:pvi}.\n\n\\subsection{Variational Inference Originated in Statistical Physics}\n\nPreviously, we derived a variational approximation to the Ising model by making a mean field assumption. That the language of physics is used in machine learning algorithms such as \\gls{vi} is no coincidence. In fact, \\citet{feynman1972statistical,feynman2018statistical} derives the \\gls{gbf} inequality for use in a variational principle for approximating intractable partition functions using mean field assumptions. Consider a model with energy function $E$ and partition function $\\cZ$, and a mean field variational approximation with energy function $E_\\mf$ (and corresponding partition function $\\cZ_\\mf$). Then the \\gls{gbf} inequality reads~\\citep{feynman1972statistical,feynman2018statistical}\n\\begin{equation}\n\\cZ \\geq \\cZ_\\mf\\exp\\left(-\\beta \\braket{E - E_\\mf}_\\mf\\right) \\, .\n\\label{eq:gbf-inequality}\n\\end{equation}\nIn physics, bra-ket notation is used to denote expectations. For example, expectations with respect to \\Cref{eq:mean-field-distribution} are written $\\braket{\\; \\cdot \\;}_\\mf$. Rewriting the \\gls{gbf} with statistics notation for the expectation $\\E_q[\\;\\cdot\\;]$ yields\n\\begin{align}\n \\cZ &\\geq \\cZ_\\mf\\exp\\left(-\\beta \\E_q[E - E_\\mf]\\right) \\, .\n\\end{align}\nTaking the logarithm, we recover the lower bound on the log partition function\n\\begin{align}\n \\log \\cZ &\\geq \\E_q[-\\beta E] - \\E_q[-\\beta E_\\mf] + \\log \\cZ_\\mf\\\\\n &= \\E_q[-\\beta E] - \\E_q[\\log q_\\mf(\\mbz; \\mblambda)] \\\\\n &= \\cL(\\mblambda)\\, .\n\\end{align}\nThis is identical to the log partition function lower bound in \\Cref{eq:llbo}. \\citet{hoffman2013stochastic} review the historical roots of the variational principle in its machine learning incarnation.\n\nTo complete the connection to machine learning, we relate this log partition function lower bound to the evidence lower bound studied in the \\gls{vi} literature~\\citep{blei2017variational}. A probabilistic model of data might have the following process for generating data $\\mbx$ using prior information in latent variables $\\mbz$:\n\\begin{align*}\n\\mbz &\\sim p(\\mbz)\\\\\n\\mbx &\\sim p(\\mbx \\mid \\mbz)\n\\end{align*}\nThe posterior distribution of this model is computed using Bayes' rule,\n\\begin{equation*}\n  p(\\mbz \\mid \\mbx) = \\frac{p(\\mbx \\mid \\mbz) p(\\mbz)}{p(\\mbx)} \\, .\n\\end{equation*}\nThe model evidence $p(\\mbx)$ is the partition function of the posterior. Calculating the partition function is what makes posterior inference difficult, as it requires integration over the latent variables $\\mbz$,\n\\begin{equation*}\n  p(\\mbx) = \\int p(\\mbx, \\mbz) d\\mbz \\, ,\n\\end{equation*}\nand the latent variables $\\mbz$ are typically high-dimensional, such as the number of random variables in an Ising model. But \\gls{vi} can be used to approximate this intractable integral. The lower bound on the log partition function becomes the \\gls{elbo}:\n\\begin{align}\n\\log p(\\mbx) &\\geq \\cL(\\mblambda) \\\\\n\\cL(\\mblambda) &= \\E_q[\\log p(\\mbx, \\mbz)] - \\E_q[\\log q(\\mbz ; \\mblambda)] \\, .\n\\end{align}\nAn example of a latent variable model without data is the Ising model---in this case, the data is an empty set, $\\mbx = \\{\\}$. In this case $\\cL(\\mblambda)$ is a lower bound on the log partition function as we derived in \\Cref{eq:llbo} and identical to the \\gls{gbf} inequality.\n% \\gls{vi} is an algorithm to find a good approximation to a target probability distribution that has an intractable integral, such as the sum needed to compute a partition function. We now turn to the second inference problem of computing likely configurations of variables in a probability model.\n\n\\section{Conclusion}\nWe reviewed probability models and gave examples of their use in statistical physics and recommender systems. The task of inference is central to working with probability models; we described variational inference and maximum likelihood estimation. The following chapters address the issue of building the structure of a problem into a performant probability model, whether that structure concerns the connectivity in a statistical physics model, the structure of datapoints in a recommender system, or information about a variational approximation useful in an optimization algorithm for this approximation.", "meta": {"hexsha": "3690e0f61167b60ce693dcda205a1b464e5bd106", "size": 27900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch_background.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_background.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_background.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": 118.7234042553, "max_line_length": 1175, "alphanum_fraction": 0.7613261649, "num_tokens": 7507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6736561514899299}}
{"text": "\\section{Cyclic Polytopes and Gale Strings}\n\\label{gale-def-sect}\n\nWe now apply the results of the previous section to unit vector games\nfor which the best response polytope is the dual of a cyclic polytope.\nThese polytopes are characterized by their representation as\na combinatorial structure, called Gale strings.\nWe will first define cyclic polytopes,\nthen Gale string, then we will give the theorem by Gale \\cite{gale}\nthat shows the\nequivalence of the two representations.\n\nThe {\\em moment curve} in dimension $d$ is defined as\n\\begin{equation}\n\\mu_d:\\reals\\longrightarrow\\reals^d\\qquad\\qquad\n\\mu_d:t\\longmapsto (t,t^2,\\ldots,t^d)\\T .\n\\end{equation}\nThe {\\em cyclic polytope} $C_d(n)$ in dimension~$d$ with $n$\nvertices, where $n>d$, is given as the convex hull of any\n$n$ points on the moment curve, that is, by $n$ arbitrary reals\n$t_1,\\ldots,t_n$, where $ t_1<\\cdots<t_n$, according to\n\\begin{equation}\n\\label{cycdef}\n% affine independence is automatic\n%C_d(n)=\\conv\\{ \\mu_d(t_i)\\ \\mid\\\\text{ affinely independent } \\}.\nC_d(n)=\\conv\\{\\,\\mu_d(t_i)\\,\\mid\\,1\\le i\\le n \\}\\,.\n\\end{equation}\n\n\\begin{example}\n\\label{cyc36-ex}\nFigure \\ref{cyc36-fig} shows the cyclic polytope in dimension 3 with 6 facets.\n\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-gale-def/cyc36.pdf}\n\\hfill\\strut\n\\caption[The cyclic polytope $C_3(6)$]{The cyclic polytope $C_3(6)$.}\n\\label{cyc36-fig}\n\\end{figure}\n\\end{example}\n\nGiven $k\\in\\naturals$ and a set $S$, we can represent the function\n$f:[k]\\to S$ as the string $s=s(1)s(2)\\cdots s(k)$; we have a {\\em bitstring}\nif $S=\\{0,1\\}$. A maximal substring of consecutive\n1's in a bitstring is called a {\\em run}.\nA run is called even if its length is even, and odd if its\nlength is odd.\nWe will use the notation $\\1^k$ for a run of\nlength~$k$ and $0^k$ for a string of 0's of\nlength $k$. A {\\em Gale string of length $n$ and\ndimension $d$}, where $n>d$, is a bitstring $s$ that satisfies the\nfollowing conditions:\n\\begin{enumerate}\n\\item exactly $d$ bits of $s$ are equal to $\\1$;\n\\item ({\\em Gale Evenness Condition})\n$\n\\qquad 0\\1^k0\\text{ is a substring of }s\\quad\n{\\Rightarrow}\\quad\nk\\text{ is even.}\n$\n\\end{enumerate}\nWe denote by $G(d,n)$ be the set of Gale strings of length $n$ and\ndimension $d$.\n\nIn general, the Gale Evenness Condition allows for Gale strings that start\nor end with an odd-length run; if $d$ is even then $s$ can start with\nan odd run if and only if it ends with an odd run.\nWhen $d$ is even, we can therefore see the Gale strings in $G(d,n)$\nas ``loops''\nobtained by ``gluing together'' the endpoints of the strings; on these\n``loops'' all runs are even.\nFormally, we can see the bit positions in a Gale string $s\\in G(d,n)$ with\n$d$ even as equivalence classes modulo~$n$.\n\n\\begin{example}\\label{gs-example}\nAs an example for even $d$, we have\n\\begin{align*}\nG(4,6) = \\{ & \\1\\1\\1\\100, \\1\\1\\100\\1, \\1\\100\\1\\1, \\100\\1\\1\\1, 00\\1\\1\\1\\1, \\\\\n            & 0\\1\\1\\1\\10, \\1\\10\\1\\10, \\10\\1\\10\\1, 0\\1\\10\\1\\1 \\}\n\\end{align*}\nThe strings $\\1\\1\\1\\100$, $\\1\\1\\100\\1$, $\\1\\100\\1\\1$, $\\100\\1\\1\\1$,\n$00\\1\\1\\1\\1$ and $0\\1\\1\\1\\10$ are\nequivalent under a cyclic shift (if considering the strings as ``loops'', the\n$\\1$'s are all consecutive), as are the strings $\\1\\10\\1\\10$, $\\10\\1\\10\\1$\nand $0\\1\\10\\1\\1$ (two runs of two $\\1$'s separated by a single $0$).\nAs an example for odd $d$, we have\n\\[\nG(3,5) = \\{ \\1\\1\\100, \\10\\1\\10, \\100\\1\\1, \\1\\100\\1,\n0\\1\\10\\1, 00\\1\\1\\1 \\}\\,.\n\\]\nNotice that because $d$ is odd, a cyclic shift is\nnot allowed: $0\\10\\1\\1$ is a shift of $\\10\\1\\10$ but it is not a Gale\nstring.\n\\end{example}\n\nThe relation between cyclic polytopes and Gale strings was given by\nGale~\\cite{gale}.\n\n\\begin{theorem}{\\rm (Gale \\cite{gale})}\n\\label{origgale-thm}\nFor any $d,n\\in\\naturals$, where $n>d$,\na set $F$ is a facet of $C_d(n)$ if and only if\n\\begin{equation}\n\\label{facet-gs}\nF = \\conv\\{ \\mu(t_j)\\,\\mid\\, s(j)=1 \\quad\\text{ for }s\\in G(d,n) \\}.\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nFirst, a hyperplane in $\\reals^d$ of the form\n$\\{x\\in\\reals^d\\mid a\\T x=a_0\\}$ for some nonzero vector\n$a=(a_1,\\ldots,a_d)\\T$ can contain at most $d$ points on the\nmoment curve, because otherwise the polynomial equation\nwith a polynomial of degree~$d$ given by\n$-a_0+a_1t+a_2t^2+\\cdots a_dt^d=0$ would have more than $d$\nroots~$t$.\nFor the same reason, any $d$ points\non the moment curve are affinely independent and define a\nunique hyperplane through them, which the moment curve {\\em\ncrosses} at these points. Notice that if the curve were tangent to the\nhyperplane at an intersection, then a slight perturbation of the hyperplane\ncould contain $d+1$ or $d-1$ points on the moment curve.\n\nLet $\\overline{t_{1}} < \\cdots < \\overline{t_{d}}$ be a\nchoice of $d$ of the $t_j$'s in the definition\n(\\ref{cycdef}) of $C_d(n)$; then the intersection of the moment curve and of\nthe hyperplane $H$ through the points\n$\\mu_d(\\overline{t_1})$, \\ldots, $\\mu_d(\\overline{t_d})$ coincides\nexactly with the points $\\mu_d(\\overline{t_i})$.\nSince the moment curve crosses the hyperplane at all intersections,\nif $t,t'\\notin\\{ \\overline{t_i} \\}$ and\n$t<\\overline{t_i}<t'$ for exactly one of the $\\overline{t_i}$'s then\n$\\mu_d(t)$ and $\\mu_d(t')$ are on opposite sides of~$H$.\n\nA facet $F$ of the cyclic polytope $C_d(n)$ is given by\n$F=H\\cap C_d(n)$. This corresponds to a choice of\n$\\overline{t_i}$'s such that for all the other\n$t_k\\notin \\{ \\overline{t_i}\\,\\mid\\,i\\in [d] \\}$ in\nthe definition of $C_d(n)$,\nthe corresponding $\\mu_d(t_k)$ are on the {\\em same} side of~$H$.\nThis can happen only if for every pair of these $t_k$'s the moment\ncurve has an even number of crossings at $\\mu(\\overline{t_i})$\nof $H$ between them. This is equivalent to ask that there is\nan even number of $\\overline{t_i}$'s between any two $t_k$'s.\n\nLet $s$ be the bitstring in which the \\1's correspond to the\n$\\overline{t_i}$'s and the 0's correspond to the other $t_k$'s.\nThen the condition that the set $F$ in (\\ref{facet-gs}) is a\nfacet is equivalent to the Gale Evenness Condition.\n\\end{proof}\n\nBecause the moment curve has at most $d$ points on any hyperplane,\neach facet of $C_d(n)$ is a $d$-simplex, so $C_d(n)$ is simplicial\nand the choice of the $t_j$'s in (\\ref{cycdef}) is\nirrelevant for the characterization of the facets of\n$C_d(n)$ as Gale strings, as long as $t_1<\\cdots<t_n$.\n\n\\begin{example}\nConsider the facet $F$ of the cyclic polytope $C_3(6)$ marked in blue\nin Figure \\ref{cyc36fac-fig}.\nLet us label the vertices on the moment curve as $t_i$, with $i\\in [n]$, and\nwe set $s(i)=1$ if $t_i$ is a vertex of $F$ and $s(i)=0$\notherwise. Figure \\ref{cyc36fac-hyper-fig} represents\nthe intersection of the moment curve and the hyperplane $H$ in $\\reals^3$\ndefined by the $t_i$ such that $s(i)=1$. This shows\nhow the corresponding Gale string $s\\in G(3,6)$ is $s=\\100\\1\\10$.\n\n\\begin{figure}[h]\n\\strut\\hfill\n\\includegraphics[width=25ex]{chapter-2/fig-gale-def/cyc36fac.pdf}%\n\\hfill\\strut\n\\caption[A facet of the cyclic polytope $C_3(6)$]{%\nThe facet of the cyclic polytope $C_3(6)$ through the points\n$\\mu_3(t_1),\\mu_3(t_4),\\mu_3(t_5)$.\n}\n\\label{cyc36fac-fig}\n\\end{figure}\n\\begin{figure}[h]\n\\strut\\hfill\n\\includegraphics[width=48ex]{chapter-2/fig-gale-def/100110-hyper.pdf}%\n\\hfill\\strut\n\\caption[A facet of $C_3(6)$ as zeroes of the moment curve]{%\nThe facet of the cyclic polytope $C_3(6)$ through the points\n$\\mu_3(t_1),\\mu_3(t_4),\\mu_3(t_5)$, as in Figure \\ref{cyc36fac-fig},\nseen from the side of the hyperplane.\nThis corresponds to the Gale string $s=\\1 00 \\1\\1 0\\in G(3,6)$.\n}\n\\label{cyc36fac-hyper-fig}\n\\end{figure}\n\\end{example}\n\n\\clearpage\n\n\\begin{example}\n\\label{c46-ex}\nFigure \\ref{c46-fig} shows the cyclic polytope $C_4(6)$, with the exterior\nfacet corresponding to the Gale string $s=\\1\\1\\1\\100$.\nFigure \\ref{cyc46fac-hyper-fig} shows the correspondence between the\nstring $s=\\1\\1\\1\\100$ and the intersection of the moment curve and\nthe hyperplane $H$.\n\\begin{figure}[h]\n\\strut\\hfill\n\\includegraphics[width=50ex]{chapter-2/fig-gale-def/c46.pdf}%\n\\hfill\\strut\n\\caption[The cyclic polytope $C_4(6)$]{%\nThe cyclic polytope $C_4(6)$. The thin lines represent the edges inside\nthe exterior facet, in bold lines. Vertex $i$ corresponds to $t_i$.\n}\n\\label{c46-fig}\n\\end{figure}\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=50ex]{chapter-2/fig-gale-def/111100-hyper.pdf}%\n\\hfill\\strut\n\\caption[A facet of $C_4(6)$ via the moment curve]{%\nThe facet of the cyclic polytope $C_4(6)$ given by the intersection of\nthe moment curve and the hyperplane $H$ through the points\n$\\mu_4(t_1),\\mu_4(t_2),\\mu_4(t_3),\\mu_4(t_4)$. This\ncorresponds to the Gale string $s=\\1\\1\\1\\1 00\\in G(4,6)$.}\n\\label{cyc46fac-hyper-fig}\n\\end{figure}\n\\end{example}\n\n\\clearpage\n\n\\begin{example}\nAs a counterexample, consider Figure \\ref{notfacet-even-hyper-fig}.\nThe points $t=t_3$ and $t'=t_5$ lie on the moment curve, but\n$\\mu_4(t_3)$ and $\\mu_4(t_5)$ are on opposite\nsides of the hyperplane~$H$ defined by the other four points.\nThe corresponding bitstring is $s=\\1\\10\\10\\1$, which is\nnot a Gale string. The violation of the Gale Evenness Condition corresponds\nto the change of side with respect to the hyperplane between $t$ and $t'$.\n\n\\begin{figure}[hp]\n\\strut\\hfill\n\\includegraphics[width=55ex]{chapter-2/fig-gale-def/notfacet-hyper.pdf}%\n\\hfill\\strut\n\\caption[Not a facet of $C_4(6)$]{%\nThere is a change of side between two $\\mu_4(t_j)$'s (for\nthe 0 bits). The bitstring $s=\\1\\10\\1 0\\1\\1$\ndoes not satisfy the Gale Evenness Condition, and the\nset of $\\mu_4(\\overline{t_i})$'s (for the \\1 bits)\ndoes not define a facet of $C_4(6)$.\n}\n\\label{notfacet-even-hyper-fig}\n\\end{figure}\n\\end{example}\n", "meta": {"hexsha": "fe08cd12244de6252baaef2c296aff5c70020cd8", "size": 9632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-2/gale-def.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-def.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-def.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.6827309237, "max_line_length": 78, "alphanum_fraction": 0.7075373754, "num_tokens": 3426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143060406073, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.6736239205468258}}
{"text": "\\subsubsection{Supremum Augmented Dickey Fuller}\n\\label{sec:methods_features_sadf}\n\nSection \\ref{sec:intro_domain} briefly introduced the concept of structural\nbreaks and the index to be implemented and used in this research project, SADF.\nIn words of Lopez de Prado:\n\n\\say{In developing an ML-based investment strategy, we typically wish to bet\nwhen there is a confluence of factors whose predicted outcome offers a favorable\nrisk-adjusted return. Structural breaks, like transition from one market regime\nto another, is one example of particular interest.}\n\nThe problem appears when trying to quantitatively detect how a regime change\noccurs. In \\cite{sadf_paper} Phillips, Wu and Yu studied Nasdaq index in 1990\nprior to the famous DotCom bubble and proposed a new index based on recursive \naugmented Dickey-Fuller tests for unit root against the alternative of an\nexplosive root (the right-tailed). The objective of this test is to identify\nthe presence of exponential growth or collapse, while assuming an autoregressive\nspecification.\n\nIn price series, like the one used in this research project, not only\none, but many bubbles are prune to happen. Not all indexes are useful under this\nassumption as many fail to detect recurrent bubbles. Nevertheless, we will start\nanalyzing the case of just one bubble in the series and then generalize it to\nmany as the it is described in chapter 17 of \\cite{lopez_de_prado}. Suppose a\nprice series that follows a first order autoregressive process:\n\n\\[ y_{t} = \\rho y_{t-1} + \\epsilon_{t} \\]\n\nwhere $\\epsilon_{t} \\sim N(0, \\sigma_{y}^{2})$, i.e. white noise. We can create a\ntest to evaluate the value of $\\rho$ whose null hypothesis states that the price\nseries follows a random walk. In other words, $H_{0}: \\rho = 1$ and the\nalternative hypothesis is that $y_t$ starts as a random walk but at some point\nin time $t^{*}T$ the process becomes explosive, such:\n\n\\begin{equation}\n  H_{1} :\n    \\begin{cases}\n      \\rho = 1 & \\text{if t = 1, ..., $\\tau^{*}T$}\\\\\n      \\rho > 1 & \\text{if t = $\\tau^{*}T$, ..., T}\\\\\n    \\end{cases}       \n\\end{equation}\n\nwhere $\\tau^{*} \\in (0,1)$. At the end of the series, i.e. at $T$, one\ncould try to find the value $\\tau^{*}$ where there was a change of regime from\nrandom walk to an explosive process. To test this hypothesis, we should\nconsider:\n\n\\[ \\Delta y_{t} = \\delta y_{t-1} D_t[\\tau^{*}] + \\epsilon_{t}\\]\n\nwhere $D_t[\\tau^{*}]$ is a dummy variable that takes the value of 0 when\n$t < \\tau^{*}T$ and 1 otherwise. $H_{0}: \\delta = 0$ which is tested against the\none-sided alternative $H_{1}: \\delta > 1$ leading to an statistic:\n\n\\[ DFC_{\\tau^{*}} = \\frac{\\hat{\\delta}}{\\hat{\\sigma}_{\\delta}} \\]\n\nOne needs to determine the value of $\\tau^{*}$ because it is unknown. The\napproach to determine it is to compute the supremum statistic for each possible\nvalue of $\\tau^{*}$ in the series. That would determine the start of the explosive\nprocess yielding to a bubble. Note that only the beginning of the regime change\nis determined with this method, i.e. there is no return to a random walk after\nthe bubble starts. This is where the novelty of Phillips, Wu and Yu appears by\na few key differences to the autoregressive model and test:\n\n\\begin{itemize}\n  \\item The regression specification becomes: $ \\Delta y_t = \\alpha + \\beta y_{t-1} + \\sum_{l=1}^{L} \\gamma_{l} \\Delta y_{t-l} + \\epsilon_t$\n  \\item $H_{0}: \\beta \\le 0$, and $H_{1}: \\beta > 0$\n  \\item $SADF_t = \\sup_{t_{0} \\in [1, t-\\tau]} \\{ADF_{t_{0},t}\\} = \\sup_{t_{0} \\in [1, t-\\tau]} \\frac{\\hat{\\beta}_{t_{0},t}}{\\hat{\\sigma}_{\\beta_{0},t}}$\n\\end{itemize}\n\nA few differences with respect to the original, one-bubble model can be noted:\n\n\\begin{itemize}\n  \\item The regression is changed, there is no more a dummy $D_t[\\tau^{*}]$\n        variable. Instead, the regression starts at $t_{0} \\in [1, t-\\tau]$ and\n        ends in $t \\in [\\tau, T]$.\n  \\item $SADF_t$ computes the supremum in a double nested loop for every\n        possible value of $t_0$ and $t$ which are the indexes to segment the\n        series.\n\\end{itemize}\n\nThe aforementioned characteristics allows SADF to vary provided that it is not\ncomputed just for one time ($T$), but instead for many (every value of\n$t \\in [\\tau, T]$).\n\nGetting into the details of the augmented Dickey-Fuller statistic, the\nconfidence value should be set from the sample to yield the best results. In\n\\cite{sadf_paper} the authors refer to a value close to 4\\% to deliver the best\nperformance but values between 1\\% and 5\\% are recommended. 5\\% was used in this\ncase.\n\n\\paragraph{Implementation notes:} Lopez de Prado offers in his book almost\nthe entire algorithm (see chapter 17 of \\cite{lopez_de_prado}), but leaves\nbehind the outer loop which allows to move forward the $SADF_{t}$ for each\n$t \\in [\\tau, T]$. A modification was introduced in code to avoid excessive and\ninefficient computation in the inner loop: an upper bound for the window was\nintroduced to so that the range of $t$ becomes $[max(\\tau, t - \\Delta t_{max}), T]$.\nAlthough the asymptotic computational complexity of this series generation is\nhigh ($O(n^5)$ at least, see \\cite{lopez_de_prado} for a detailed analysis), one\nway to saturate one order is to use $\\Delta t_{max}$ which should be cautiously\nselected to account for long lasting bubbles.\n\nOn a separate note, the algorithm allows researchers to introduce a constant, a\nlinear and a quadratic polynomial regression depending on the type of series to\nanalyze. All of them were computed in favor of feeding the model with more data\nand experiment what yields the best results.\n\nFinally, a recommendation in the article \\cite{sadf_paper} and discussed in\n\\cite{lopez_de_prado} has been implemented. Instead of using raw prices, the\nalgorithm takes as input log-prices. Conceptually, by applying the logarithmic\ntransformation, the variance of the process gets stabilized and the\nheteroscedastic assumption about the data can be fulfilled. Long time series\nare expected to change their price levels but that does not directly cause a\nregime change and the transformation facilitates to distinguish them. A regime\nchange implies a transition to an explosive behavior, e.g. exponential behavior\nis identified.\n\nThree pictures are shown to illustrate this index: \\ref{fig:sadf_prices},\n\\ref{fig:sadf_prices_ffd}, and \\ref{fig:sadf_prices_log}. They contrast the\nindex with raw bitcoin close price, fractionally differentiated bitcoin price\nand log prices respectively. Note the progression in the pictures and how the \nvolatility of the log-prices series correlates with SADF spikes\n\\ref{fig:sadf_prices_log}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{methods/images/sadf_prices.png}\n    \\caption{Raw close prices and SADF over time.}\n    \\label{fig:sadf_prices}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{methods/images/sadf_prices_ffd.png}\n    \\caption{Fractionally differentiated prices and SADF over time.}\n    \\label{fig:sadf_prices_ffd}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{methods/images/sadf_prices_log.png}\n    \\caption{Close log-prices and SADF over time.}\n    \\label{fig:sadf_prices_log}\n\\end{figure}\n\n", "meta": {"hexsha": "09ed6c84a5509edb4c564603d1ef98d61908bd34", "size": 7246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/methods/features/sadf.tex", "max_stars_repo_name": "agalbachicar/swing_for_the_fences", "max_stars_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/methods/features/sadf.tex", "max_issues_repo_name": "agalbachicar/swing_for_the_fences", "max_issues_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/methods/features/sadf.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": 49.6301369863, "max_line_length": 153, "alphanum_fraction": 0.7430306376, "num_tokens": 1942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757313, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.673623912694349}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\nPage 142\n\\section{If $x \\in X$ and $\\delta_x(f) = f(x)$ for all $f$ in $C_b(X)$, show that $||\\delta_x|| = 1$}\n\n\\begin{align}\n|| \\delta_x ||  &= \\sup\\{ || \\delta_x(f) || : f \\in C_b(X), || f || \\le 1 \\}  \\\\\n&= \\sup\\{ || f(x) || : f \\in C_b(X), || f || \\le 1 \\} \\\\\n&= 1\n\\end{align}\n\nSince $|| f || \\le 1$ are exactly those functions where $f(x) \\le 1 $ for all $x$.\n\n\\end{document}", "meta": {"hexsha": "2ce26777d7a2043b28cb9fb6f24969031334cfc2", "size": 462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/5_Weak_Topologies/7_Milner.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "analysis/5_Weak_Topologies/7_Milner.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis/5_Weak_Topologies/7_Milner.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": 25.6666666667, "max_line_length": 101, "alphanum_fraction": 0.5454545455, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6736239120720829}}
{"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\\section{Slip on a Fault}\\label{Slip CHAP}\n\\begin{figure}[ht]\n\\centerline{\\includegraphics{Slip1}}\n\\caption{Domain $\\Omega=[0,1]^2$ with a vertical fault of length $0.5$.}\n\\label{fig:slip.1}\n\\end{figure}\n%\nIn this example we illustrate how to calculate the stress distribution around\na fault\\index{fault} in the Earth's crust caused by a slip\\index{slip} through\nan earthquake.\n\nTo simplify the presentation we assume a simple domain $\\Omega=[0,1]^2$ with\na vertical fault in its center as illustrated in \\fig{fig:slip.1}.\nWe assume that the slip distribution $s_{i}$ on the fault is known.\nWe want to calculate the distribution of the displacements $u_{i}$\\index{displacement}\nand stress $\\sigma_{ij}$\\index{stress} in the domain.\nFurther, we assume an isotropic, linear elastic material model of the form\n\\begin{eqnarray} \\label{Slip  stress}\n\\sigma_{ij} & = & \\lambda u_{k,k} \\delta_{ij} + \\mu ( u_{i,j} + u_{j,i})\n\\end{eqnarray}\nwhere $\\lambda$ and $\\mu$ are the Lam\\'e coefficients\\index{Lam\\'e coefficients}\nand $\\delta_{ij}$ denotes the Kronecker symbol\\index{Kronecker symbol}.\nOn the boundary the normal stress is given by\n\\begin{eqnarray} \\label{Slip natural fault}\n\\sigma_{ij}n_{j}=0\n\\end{eqnarray}\nand normal displacements are set to zero:\n\\begin{eqnarray} \\label{Slip constraint}\nu_{i}n_{i} =0\n\\end{eqnarray}\nThe stress needs to fulfill the momentum equation\\index{momentum equation}\n\\begin{eqnarray}\\label{Slip general problem}\n- \\sigma_{ij,j}=0\n\\end{eqnarray}\nThis problem is very similar to the elastic deformation problem presented in \\Sec{ELASTIC CHAP}.\nHowever, we need to address an additional challenge: the displacement\n$u_{i}$ is in fact discontinuous across the fault, but we are in the\nlucky situation that we know the jump of the displacements across the fault.\nThis is in fact the given slip $s_{i}$.\nSo we can split the total distribution $u_{i}$ into a component\n$v_{i}$ which is continuous across the fault and the known slip $s_{i}$\n\\begin{eqnarray}\\label{Slip Split}\nu_{i} = v_{i} + \\frac{1}{2} s^{\\pm}_{i}\n\\end{eqnarray}\nwhere $s^{\\pm}=s$ when right of the fault and $s^{\\pm}=-s$ when left of the fault.\nWe assume that $s^{\\pm}=0$ when sufficiently away from the fault.\n\nWe insert this into the stress definition in \\eqn{Slip stress}\n\\begin{eqnarray} \\label{Slip stress split}\n\\sigma_{ij} & = &\n\\sigma^c_{ij} +\n\\frac{1}{2} \\sigma^s_{ij}\n\\end{eqnarray}\n with\n\\begin{eqnarray} \\label{Slip stress split 1}\n\\sigma^c_{ij} = \\lambda v_{k,k} \\delta_{ij} + \\mu ( v_{i,j} + v_{j,i})\n\\end{eqnarray}\nand\n\\begin{eqnarray} \\label{Slip stress split 2}\n\\sigma^s_{ij} = \\lambda s^{\\pm}_{k,k} \\delta_{ij} + \\mu ( s^{\\pm}_{i,j} + s^{\\pm}_{j,i}).\n\\end{eqnarray}\nIn fact, $\\sigma^s_{ij}$ defines a stress jump across the fault.\nAn easy way to construct this function is to use a function $\\chi$ which is\n$1$ on the right and $-1$ on the left side from the fault.\nOne can then set\n\\begin{eqnarray} \\label{Slip  stress split 23 }\n\\sigma^s_{ij} = \\chi \\cdot  ( \\lambda s_{k,k} \\delta_{ij} + \\mu ( s_{i,j} + s_{j,i}) )\n\\end{eqnarray}\nassuming that $s$ is extended by zero away from the fault.\nAfter inserting \\eqn{Slip stress split} into (\\ref{Slip general problem}) we\nget the differential equation\\index{momentum equation}\n\\begin{eqnarray}\\label{Slip general problem 2 }\n- \\sigma^c_{ij,j}=\\frac{1}{2} \\sigma^s_{ij,j}\n\\end{eqnarray}\nTogether with the definition (\\ref{Slip stress split 1}) we have a\ndifferential equation for the continuous function $v_i$.\nNotice that the boundary condition (\\ref{Slip constraint}) and (\\ref{Slip natural fault})\ntransfer to $v_i$ and $\\sigma^c_{ij}$ as $s$ is zero away from the fault.\nIn \\Sec{ELASTIC CHAP} we have discussed how this problem is solved using\nthe \\LinearPDE class. We refer to this section for further details.\n\nTo define the fault we use the \\class{FaultSystem} class introduced in \\Sec{Fault System}.\nThe following statements define a fault system \\var{fs} and add the fault \\var{1} to the system:\n\\begin{python}\n  fs=FaultSystem(dim=2)\n  fs.addFault(fs.addFault(V0=[0.5,0.25], strikes=90*DEG, ls=0.5, tag=1)\n\\end{python}\nThe fault added starts at point $(0.5,0.25)$ has length $0.5$ and points north.\nThe main purpose of the \\class{FaultSystem} class is to define a\nparameterization of the fault using a local coordinate system.\nOne can inquire the class to get the range used to parameterize a fault.\n\\begin{python}\n  p0,p1 = fs.getW0Range(tag=1)\n\\end{python}\nTypically \\var{p0} is equal to zero while \\var{p1} is equal to the length of the fault.\nThe parameterization is given as a mapping from a set of local coordinates\nonto a parameter range (in our case the range \\var{p0} to \\var{p1}).\nFor instance, to map the entire domain \\var{mydomain} onto the fault one can\nuse\n\\begin{python}\n  x = mydomain.getX()\n  p,m = fs.getParametrization(x, tag=1)\n\\end{python}\nOf course there is the problem that not all locations are on the fault.\nFor those locations which are on the fault \\var{m} is set to 1, otherwise 0 is used.\nSo on return the values of \\var{p} define the value of the fault parameterization\n(typically the distance from the starting point of the fault along the fault)\nwhere \\var{m} is positive.\nOn all other locations the value of \\var{p} is undefined.\nNow \\var{p} can be used to define a slip distribution on the fault via\n\\begin{python}\n  s = m*(p-p0)*(p1-p)/((p1-p0)/2)**2*slip_max*[0.,1.]\n\\end{python}\nNotice the factor \\var{m} which ensures that \\var{s} is zero away from the fault.\nIt is important that the slip is zero at the ends of the faults.\n\nWe can now put all components together to get the script:\n\\begin{python}\n  from esys.escript import *\n  from esys.escript.linearPDEs import LinearPDE\n  from esys.escript.models import FaultSystem\n  from esys.finley import Rectangle\n  from esys.weipa import saveVTK\n  from esys.escript.unitsSI import DEG\n\n  #... set some parameters ...\n  lam=1.\n  mu=1\n  slip_max=1.\n  mydomain = Rectangle(l0=1.,l1=1.,n0=16, n1=16)  # n1 needs to be a multiple of 4!\n  # .. create the fault system\n  fs=FaultSystem(dim=2)\n  fs.addFault(V0=[0.5,0.25], strikes=90*DEG, ls=0.5, tag=1)\n  # ... create a slip distribution on the fault\n  p, m=fs.getParametrization(mydomain.getX(), tag=1)\n  p0,p1= fs.getW0Range(tag=1)\n  s=m*(p-p0)*(p1-p)/((p1-p0)/2)**2*slip_max*[0.,1.]\n  # ... calculate stress according to slip:\n  D=symmetric(grad(s))\n  chi, d=fs.getSideAndDistance(D.getFunctionSpace().getX(), tag=1)\n  sigma_s=(mu*D+lam*trace(D)*kronecker(mydomain))*chi\n  #... open symmetric PDE ...\n  mypde=LinearPDE(mydomain)\n  mypde.setSymmetryOn()\n  #... set coefficients ...\n  C=Tensor4(0., Function(mydomain))\n  for i in range(mydomain.getDim()):\n    for j in range(mydomain.getDim()):\n       C[i,i,j,j]+=lam\n       C[j,i,j,i]+=mu\n       C[j,i,i,j]+=mu\n  # ... fix displacement in normal direction\n  x=mydomain.getX()\n  msk=whereZero(x[0])*[1.,0.] + whereZero(x[0]-1.)*[1.,0.] \\\n     +whereZero(x[1])*[0.,1.] + whereZero(x[1]-1.)*[0.,1.]\n  mypde.setValue(A=C, X=-0.5*sigma_s, q=msk)\n  #... solve pde ...\n  mypde.getSolverOptions().setVerbosityOn()\n  v=mypde.getSolution()\n  # .. write the displacement to file:\n  D=symmetric(grad(v))\n  sigma=(mu*D+lam*trace(D)*kronecker(mydomain))+0.5*sigma_s\n  saveVTK(\"slip.vtu\", disp=v+0.5*chi*s, stress=sigma)\n\\end{python}\nThe script creates the file \\file{slip.vtu} which contains the total\ndisplacements and stress.\nThese values are stored as cell-centered data.\n%\n\\begin{figure} [ht]\n\\centerline{\\includegraphics[width=\\figwidth]{Slip2}}\n\\caption{Total Displacement after the slip event}\n\\label{fig:slip.2}\n\\end{figure}\n%\nSee \\fig{fig:slip.2} for a visualization of the result.\n\n", "meta": {"hexsha": "5ec60d2025f7b7b44845ad65b1794f953b15dc47", "size": 8206, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user/slip.tex", "max_stars_repo_name": "markendr/esys-escript.github.io", "max_stars_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/user/slip.tex", "max_issues_repo_name": "markendr/esys-escript.github.io", "max_issues_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-14T03:07:43.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-14T03:07:43.000Z", "max_forks_repo_path": "doc/user/slip.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": 42.7395833333, "max_line_length": 96, "alphanum_fraction": 0.705581282, "num_tokens": 2543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430520409024, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.67362390996229}}
{"text": "\\chapter{Multiscale Methods for polarized maps on the Sphere}\n\\label{ch_mms_pola}\n\n% chapter multiscale transform for pola data\n\n\\section{Module-phase non linear multiscale transform}\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\label{sec:modphase}\n\n\\subsection{Introduction}\nGiven a polarized map in the standard Q-U representation, consider a different point of view and define the modulus $M$ and phase $P$ maps as follows~:\n%\n%From a different point of view, the combined $Q$ and $U$ maps can be considered as a vector field. Let define such combined map $\\mathcal{V}$ as follows~:\n%\\begin{equation}\n%{\\mathcal{V}} = \\left[ Q \\, U\\right]\n%\\end{equation}\n%Each pixel of $\\mathcal{V}$ is then vector valued. A classical approach amounts to decomposing each vector into its modulus and phase part. $\\mathcal{V}$ can then be decomposed into a modulus map $M$ and a phase map $P$~:\n\\begin{eqnarray}\n\\forall k,\\,\\,\\, M_k & = & \\sqrt{Q_k^2 +  U_k^2} \\\\\n\\forall k,\\,\\,\\, P_k & = & \\exp(i \\theta_k) \\mbox{ where } tan(\\theta_k) = U_k/Q_k \n\\end{eqnarray}\nBecause the smoothness of the $Q$ and $U$ maps should result in some smoothness of the modulus map $M$ and the phase map $P$, \none may consider devising a multiscale modulus/phase decomposition of the spin 2 field ${\\mathcal{V}} = \\left[ Q \\, U\\right]$.\\\\\n\nThe specificity of the modulus/phase decomposition of $\\mathcal{V}$ is twofold~: i) the modulus field is non-negative and ii) the phase \nfield takes its values on the unit circle $S^1$. Recently, \\cite{rahman05} introduced a multiscale analysis technique for manifold valued \ndata that will be described in the following paragraph. We then define the modulus/phase (MP) multiscale transform as follows~:\n\\vspace{.1cm}\n\\begin{center}\n\\begin{minipage}[b]{0.85\\linewidth}\n\\footnotesize{\n\\begin{enumerate}\n\\item Apply a classical multiscale transform (\\textit{i.e.} wavelets) to the modulus map $M$.\n\\item Apply the multiscale analysis technique for manifold valued data described in \\cite{rahman05} to the phase map $P$. \n\\end{enumerate}}\n\\end{minipage}\n\\end{center}\n\\vspace{.1cm}\n\n\\subsection{Decimated MP-multiscale transform}\n\n\\begin{figure*}[htb]\n\\centerline{\n \\vbox{\n \\includegraphics[width=\\textwidth]{fig_modphase_back.pdf}\n }\n }\n\\caption{Examples of MP-multiscale coefficients backprojection.}\n\\label{fig_modphase_back}\n\\end{figure*}\nLet us provide some essential notation~: we assume that the entries of the phase map $P$ lie in a manifold $\\mathcal{M}$ \n(\\textit{e.g.} $\\mathcal{M}\\equiv S^1$). According to \\cite{rahman05}, take $p_0,p_1 \\in \\mathcal{M}$ and define $Log_{p_0}(p_1)$ \nas the log-map of $p_1$ onto the tangent space $\\mathcal{T}_{p_0}$ of $\\mathcal{M}$ at $p_0$. The back-projection is obtained \nusing the inverse of the log-map $Exp_{p_0}$. \\footnote{In differential geometry, the Exp map and Log map are generalizations of \nthe usual exponential and logarithm function. Here the manifold $\\mathcal{M}$ is a Riemannian manifold. In that case, the Exp map \nat point $p_0$, $Exp_{p_0}(s)$ is the map which takes a vector $s$ of the tangent space of $\\mathcal{M}$ at $p_0$ and provides the \npoint $p_1$ by travelling along the geodesic starting at $p_0$ in the direction s.}\\\\\nFor instance, if we choose $\\mathcal{M} \\equiv S^1$ then $p_0 = \\exp(i \\theta_0)$ and $p_1 = \\exp(i \\theta_1)$. The $Exp_{p_0}$ and \n$Log_{p_0}$ maps are then defined as follows~:\n\\begin{eqnarray}\n\\forall p_1 \\in S^, \\,\\,\\,  Log_{p_0} (p_1) & = & \\theta_1 - \\theta_0 \\\\\n\\forall s \\in \\mathbb{R} \\,\\,\\, Exp_{p_0} (s) & = & exp(i(\\theta_0 + s))\n\\end{eqnarray}\nThe multiscale transform for manifold valued data introduced in \\cite{rahman05} is equivalent to a two-step interpolation-refinement \nscheme similar to the lifting scheme described in~\\cite{wave:sweldens98}. The wavelet coefficients and low pass approximation pixels \nare then computed as follows at each scale $j$ and pixel $k$~:\n\\begin{eqnarray}\\label{eq:mani}\nw_{j+1,k}^P & = & Log_{c_{j,2k+1}^P}\\left(\\mathcal{P}(c_{j,2k}^P)\\right)   \\\\\nc_{j+1,k}^P & = & Exp_{c_{j,2k}^P} ( -\\mathcal{U}(w_{j+1,k}^P))\n\\label{eq:mani2}\n\\end{eqnarray}\nThe wavelet coefficient $w_{j+1,k}^P$ at pixel $k$ and scale $j$ is the projection of its prediction/interpolation $\\mathcal{P}(c_{j,2k}^P)$ \nonto the tangent space $\\mathcal{T}_{c_{j,2k+1}^P}$ of $\\mathcal{M}$ at $c_{j,2k+1}^P$. The low pass approximation $c_{j+1,k}^P$ at scale $j+1$ \nis computed by updating $c_{j,2k}^P$ from the wavelet coefficient $w_{j+1,k}^P$.\\\\\nThe main advantage of this scheme is its ability to capture local regularities while guaranteeing the low pass approximation to belong to \nthe manifold $\\mathcal{M}$. Indeed, the wavelet coefficient $w_{j+1,k}^P$ at pixel $k$ and scale $j+1$ is computed as the $Exp$ map at \n$c_{j,2k+1}^P$ of an approximation $\\mathcal{P}(c_{j,2k}^P)$ of $c_{j,2k}^P$.\\\\\nNote also that even if the definitions of the $Exp_{p_0}$ and $Log_{p_0}$ maps involve the absolute phase $\\theta(k)$ (\\textit{i.e.} $tan(\\theta(k)) = U_k/Q_k$), \nat least they only require the computation of differences of phases values thus avoiding the explicit manipulation of an absolute phase.\\\\\nHowever the non-linearity of the proposed transform is a major drawback when considering denoising and restoration applications.\\\\ \n\n\\paragraph{Illustration~:\\\\}\nIn the case of polarized data, the entries of the phase map $P$ lie in $\\mathcal{M} \\equiv S^1$. In the following experiments, $\\mathcal{P}$ and $\\mathcal{U}$ are chosen such that~:\n\\begin{eqnarray}\nw_{j+1}^P & = & Log_{c_{j,2k+1}^P}(c_{j,2k}^P)  \\\\\nc_{j+1,k}^P & = & Exp_{c_{j,2k}^P} \\left( - \\frac{w_{j+1}^P}{2}\\right)\n\\end{eqnarray}\nThis multiscale transform is invertible and its inverse is computed as follows~:\n\\begin{eqnarray}\nc_{j,2k}^P & = & Exp_{c_{j+1,k}^P} \\left(\\frac{w_{j+1}^P}{2}\\right)\\\\\nc_{j,2k+1}^P & = & Exp_{c_{j,2k}^P}\\left( w_{j+1}^P \\right)   \n\\end{eqnarray}\nThe picture in Figure~\\ref{fig_modphase_back} features some examples of backprojections of MP-multiscale coefficients.\n\n\\subsection{Undecimated MP-multiscale transform}\nFor image restoration purposes, the use of undecimated multiscale transforms has been shown to provide better results than decimated transforms~\\cite{starck:book98,starck:book06}. \nThe aforementioned modulus/phase multiscale analysis can be extended to an undecimated scheme consisting in~: i) applying an undecimated wavelet transform to the modulus map, \nii) analyzing the phase map P using an extension to the undecimated case of the multiscale transform described in \\cite{rahman05}. In that case, Equations~\\eqref{eq:mani} \nand \\eqref{eq:mani2} are replaced with the following equations~:\n\\begin{eqnarray}\\label{eq:maniu}\nc_{j+1,k}^P & = & Exp_{c_{j,k}^P} ( \\mathcal{F}(c_{j,.}^P))\\\\\nw_{j+1}^P & = & Log_{c_{j+1,k}^P}\\left(c_{j,k}^P\\right)  \n\\end{eqnarray}\nwhere $\\mathcal{F}(c_{j,.}^P) = \\sum_l h_{l} Log_{c_{j,k}}\\left(c_{j,k-2^jl}\\right)$ with $\\sum_l h_l = 1$ and $h_l > 0$. The low pass \napproximation $c_{j+1,k}^P$ is then computed from a linear combination (linear filter) of a neighborhood $\\{c_{j,k-2^jl}\\}_l$ of $c_{j,k}$ \nweighted by the positive scalars $\\{h_l\\}_l$. Note that from scale $j$ to scale $j+1$, the spatial size of the neighborhood increases \nby a factor $2$ which would be equivalent to downsize by a factor $2$ the band pass filter of the classical wavelet decomposition scheme.\\\\\n\n\\subsection{Example}\nIn the case of polarized data, the entries of the phase map $P$ lie in $\\mathcal{M} \\equiv S^1$. In the following experiments, $\\mathcal{F}$ is chosen such that~:\n\\begin{eqnarray}\nc_{j+1,k}^P & = & Exp_{c_{j,k}^P}\\left(\\sum_l h_{l}Log_{c_{j,k}}\\left(c_{j,k-2^jl}^P\\right)\\right)  \\\\\nw_{j+1,k}^P & = & Exp_{c_{j,k}^P} \\left(c_{j+1,k}^P\\right)\n\\end{eqnarray}\nwhere~:\n\\begin{equation}\nh_l = \\left\\{\n\\begin{array}{ccc}\n0 & \\mbox{ if } & l < -2 \\mbox{ or } l > 2 \\\\\n1/16 &\\mbox{ if }& l=-2 \\mbox{ or } l=2 \\\\\n1/4 &\\mbox{ if }& l=-1 \\mbox{ or } l=1\\\\\n3/8 &\\mbox{ if }& l= 0\n\\end{array}\n\\right.\n\\end{equation}\nThis multiscale transform is invertible and its inverse is computed as follows~:\n\\begin{equation}\n c_{j,k}^P  =  Exp_{c_{j+1,k}^P } \\left(- w_{j+1,k}^P\\right)  \n\\end{equation}\n\n\\begin{figure*}[htb]\n \\vbox{\n \\centerline{\n \\hbox{\n \\includegraphics[width=7cm]{fig_mol_synchrotron.pdf}\n \\includegraphics[width=7cm]{fig_mol_synchrotron_noise.pdf}\n }\n }\n \\centerline{\n \\hbox{\n \\includegraphics[width=7cm]{fig_mol_synchrotron_noise_no_scale1-3.pdf}\n \\includegraphics[width=7cm]{fig_mol_synchrotron_noise_no_scale1-5.pdf}\n }\n }\n }\n\\caption{ Polarized field smoothing - \\textit{top left~:} simulated synchroton emission.  \\textit{top right~:} same field corrupted by additive noise.\n \\textit{bottom left~:} MP-multiscale reconstruction after setting to zero all coefficients from the three first scales.\n\\textit{bottom right~:} MP-multiscale reconstruction after setting to zero all coefficients from  the five first scales.}\n\\label{fig_modphase_smoothfield}\n\\end{figure*}\nFig.~\\ref{fig_modphase_smoothfield} top  shows a simulated polarized field of the synchrotron emission and its noisy version.\nWe have applied the MP-multiscale transform and we remove the first three scales (i.e. we put all coefficients to zero) before \nreconstructing. The resulting image is shown on the bottom left of Fig.~\\ref{fig_modphase_smoothfield}. The bottom right of \nFig.~\\ref{fig_modphase_smoothfield} corresponds to the same experiment, but by removing the five first scales. We can see that \nthe field is smoother and smoother, but respecting the large scale structure of the field. This transform will be very well suited \nto CMB studies where the phase is analyzed independently of the modulus, such as in~\\cite{coles05,naselsky05}.\n\n%---------------------------------------------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------------------------------------------\n\n\n\\section{Polarized Wavelet Transform using Spherical Harmonics}\n\\label{sec:pol_iwt}\n\n\\subsection{Isotropic Undecimated Wavelet Transform on the Sphere (UWTS) }\n\\label{sec:UWTS}\n\n\\begin{figure*}[htb]\n\\centerline{\n \\hbox{\n \\includegraphics[width=7cm]{fig_q_iwt_back.pdf}\n \\includegraphics[width=7cm]{fig_u_iwt_back.pdf}\n }\n }\n\\caption{Q-isotropic wavelet transform backprojection (left) and U-isotropic wavelet backprojection (right).}\n\\label{fig_qu_iwt_back}\n\\end{figure*}\n\n\n%---------------------------------------------------------------------------------------------------------------------------------------\nThe undecimated isotropic transform on the sphere described in~\\cite{starck:sta05_2} is similar in many respects to the usual \n\\emph{ \\`a trous} isotropic wavelet transform. It is obtained using a zonal scaling function $\\phi_{l_c}(\\vartheta, \\varphi)$ \nwhich depends only on colatitude $\\vartheta$ and is invariant with respect to a change in longitude $\\varphi$. It follows that \nthe spherical harmonic coefficients $\\hat \\phi_{l_c} (l,m)$ of $\\phi_{l_c}$ vanish when $m \\ne 0$ which makes it simple to compute \nthose spherical harmonic coefficients $\\hat c_{0}(l,m)$ of $c_0 = \\phi_{l_c} * f$ where $*$ stands for convolution :\n\\begin{eqnarray}\n \\hat c_{0}(l,m) = \\widehat{\\phi_{l_c} * f} (l,m) = \\sqrt{\\frac{4\\pi}{2l+1} } \\hat \\phi_{l_c} (l,0) \\hat f(l,m) \n\\end{eqnarray}\nA possible scaling function~\\cite{starck:book98}, defined in the spherical harmonics representation, is $\\phi_{l_c}(l, m) = {2 \\over 3} B_{3} ( { {2 l} \\over {l_{c} } } )$ \nwhere $B_{3}$ is the cubic B-spline compactly supported over $[-2, 2]$. Denoting $\\phi_{2^{-j} l_{c} }$ a rescaled version of \n$\\phi_{l_{c}}$ with cut-off frequency $2^{-j} l_{c}$, a multi-resolution decomposition of $f$ on a dyadic scale is obtained recursively : \n\\begin{eqnarray}\nc_0   & = &  \\phi_{ l_{c} }  * f    \\nonumber    \\\\\nc_j    &=&   \\phi_{2^{-j}  l_{c}  }  * f  =   c_{j-1} * h_{j-1} \\nonumber    \\\\\n\\end{eqnarray}\nwhere the zonal low pass filters $h_{j}$ are defined by \n\\begin{eqnarray}\n \\hat{H}_{j}(l,m)  & =  &  \\sqrt{\\frac{4\\pi}{2l+1} }  \\hat h_{j}(l,m)  \\nonumber \\\\\n &  =  & \\left\\{\n  \\begin{array}{ll}\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\\\\\n0 & \\mbox{otherwise } \\ \n  \\end{array}\n  \\right.\n\\end{eqnarray}\nThe cut-off frequency is reduced by a factor of $2$ at each step so that in applications where this is useful such as compression, \nthe number of samples could be reduced adequately. Using a pixelization scheme such as Healpix \\cite{pixel:healpix}, this can easily \nbe done by dividing by 2 the Healpix {\\it nside} parameter when computing the inverse spherical harmonics transform. \n% Of course, this is only an approximate \\emph{Sampling Theorem} but it proved sufficient for numerical purposes.  However, in the present isotropic undecimated transform, no downsampling is performed  and the maps have the same number of pixels on each scale. Hence the orthogonality requirement is relaxed, which provides us with a higher degree of freedom in the choice and design  of the wavelet function $\\psi_{l_c}$ to be used with the scaling function $\\phi_{l_c}$. \nAs in the \\emph{\\`a trous} algorithm, the wavelet coefficients can be defined as the difference between two consecutive resolutions, \n$w_{j+1}(\\vartheta, \\varphi) = c_{j}(\\vartheta, \\varphi) - c_{j+1}(\\vartheta, \\varphi)$. 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}\n\n\\begin{figure*}[htb]\n\\centerline{\n\\hbox{\n \\includegraphics[width=7cm]{fig_dust_input.pdf}\n}}\n\\caption{Simulated observations on the sphere of the polarized galactic dust emission.}\n\\label{fig_simu_pol_dust}\n\\end{figure*}\n\nWith this particular choice of wavelet function, the decomposition is readily inverted by summing the coefficient maps on all wavelet scales\n \\begin{eqnarray}\\label{IWT}\n   %c_{0}(\\vartheta, \\varphi) = c_{J}(\\vartheta, \\varphi) + \\sum_{j=1}^{J} w_j(\\vartheta, \\varphi)\n   f(\\vartheta, \\varphi) = c_{J}(\\vartheta, \\varphi) + \\sum_{j=1}^{J} w_j(\\vartheta, \\varphi)\n\\end{eqnarray}\nwhere we have made the simplifying assumption that $f$ is equal to $c_0$. Obviously, other wavelet functions $\\psi$ could be used just as well, such as the needlet function~\\cite{marinucci08}.\n\n% Also,  because of the redundancy of the described decomposition, the inverse transform  is not unique and in fact this can profitably be used to impose additional constraints on the synthesis functions (\\emph{e.g.} smoothness, positivity) used in the reconstruction \\cite{starck:sta06}. \n\n\\begin{figure*}[htb]\n\\centerline{\n\\vbox{\n \\hbox{\n \\includegraphics[width=7cm]{fig_ebiwt_scale1.pdf}\n \\includegraphics[width=7cm]{fig_ebiwt_scale2.pdf}\n }\n \\hbox{\n \\includegraphics[width=7cm]{fig_ebiwt_scale3.pdf}\n \\includegraphics[width=7cm]{fig_ebiwt_scale4.pdf}\n }\n  \\hbox{\n \\includegraphics[width=7cm]{fig_ebiwt_scale5.pdf}\n \\includegraphics[width=7cm]{fig_ebiwt_scale6.pdf}\n }\n  }\n }\n\\caption{QU-Undecimated Wavelet Transform of the simulated polarized map of galactic dust emission shown in figure~(\\ref{fig_simu_pol_dust}).}\n\\label{fig_quwt_trans_dust}\n\\end{figure*}\n\n\\subsection{Extension to Polarized Data}\nBy applying the above scalar isotropic wavelet transform to each component $T$, $Q$, $U$ of a polarized map on the sphere, we have~:\n\\begin{eqnarray}\n\\label{tqu_iwt}\nT(\\vartheta, \\varphi) & = c_{J}^T (\\vartheta, \\varphi)+ \\sum_{j=1}^{J} w_j^T  (\\vartheta, \\varphi)\\\\ \\nonumber\nQ(\\vartheta, \\varphi) & = c_{J}^Q (\\vartheta, \\varphi)+ \\sum_{j=1}^{J} w_j^Q (\\vartheta, \\varphi)\\\\ \\nonumber\nU(\\vartheta, \\varphi) & = c_{J}^U (\\vartheta, \\varphi)+ \\sum_{j=1}^{J} w_j^U (\\vartheta, \\varphi)\n\\end{eqnarray}\nwhere $c_{J}^X$ stands for the low resolution approximation to component $X$ and $w_j^X$ is the map of wavelet coefficients of that component on scale $j$. This leads to the following decomposition~:\n\\begin{eqnarray}\n(Q \\pm iU)[k] =    (c^Q_{J} \\pm c^U_{J,p})[k]   +   \\sum_{j=1}^J   ( w_{j}^Q \\pm w_{j}^U )[k]\n\\label{eq_qu_rec_uwt}\n\\end{eqnarray}\nFig.\\ref{fig_qu_iwt_back} shows the backprojection of a Q-wavelet coefficient (left) and a $U$-wavelet coefficient (right).\nFig.~\\ref{fig_quwt_trans_dust} shows the undecimated isotropic polarized wavelet transform of the dust image shown on \nFig.~\\ref{fig_simu_pol_dust} using six scales, \\textit{i.e.} five wavelet scales and the coarse approximation.\n%---------------------------------------------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\section{Polarized Curvelet Transform}\n\\label{sec:pol_cur}\n% \\begin{figure*}\n% \\centerline{\n% \\hbox{\n% \\psfig{figure=fig_back_cur_sphere.ps,bbllx=1cm,bblly=7cm,bburx=20cm,bbury=20cm,height=8.5cm,width=12cm,clip=}\n% }}\n% \\caption{Backprojection of  various curvelet coefficients at different scales and orientations on the sphere.  Each map is obtained by setting all but one of the curvelet coefficients to zero, and applying an inverse curvelet transform. Depending on the scale and the position of the non zero curvelet coefficient, the reconstructed image presents a feature with a given width, length and orientation.}\n %\\label{Figure:back_cur}\n% \\end{figure*}\n \\begin{figure*}[htb]\n\\centerline{\n\\vbox{\n \\hbox{\n \\includegraphics[width=7cm]{fig_mol_backproj_qucur_qj3.pdf}\n \\includegraphics[width=4cm]{fig_backproj_qucur_qj3.pdf}\n }\n \\hbox{\n \\includegraphics[width=7cm]{fig_mol_backproj_qucur_uj3.pdf}\n \\includegraphics[width=4cm]{fig_backproj_qucur_uj3.pdf}\n }\n  }\n }\n\\caption{Top, Q-curvelet backprojection (left)  and zoom (right). Bottom, U-curvelet backprojection (left)  and zoom. }\n\\label{fig_qucur_back}\n\\end{figure*}\nThe 2D ridgelet transform \\cite{cur:candes99_1} was developed in an attempt to overcome some limitations inherent in former multiscale methods \n\\emph{e.g.} the 2D wavelet, when handling smooth images with edges \\textit{i.e.} singularities along smooth curves. Ridgelets are translation \ninvariant \\emph{ridge} functions with a wavelet profile in the normal direction. Although ridgelets provide sparse representations of smooth \nimages with straight edges, they fail to efficiently handle edges along curved lines. This is the framework for curvelets which were given a \nfirst mathematical description in \\cite{Curvelets-StMalo}. Basically, the curvelet dictionary is a multiscale pyramid of localized directional \nfunctions with anisotropic support obeying a specific parabolic scaling such that at scale $2^{-j}$, its length is $2^{-j/2}$ and its width is $2^{-j}$. \nThis is motivated by the parabolic scaling property of smooth curves. Other properties of the curvelet transform as well as decisive optimality results \nin approximation theory are reported in \\cite{Curvelets-StMalo,CandesDonohoCurvelets}. Notably, curvelets provide optimally sparse representations \nof manifolds which are smooth away from edge singularities along smooth curves. Several digital curvelet transforms \\cite{cur:donoho99,starck:sta01_3,cur:demanet06} \nhave been proposed which attempt to preserve the essential properties of the continuous curvelet transform and many papers \\cite{starck:sta04,felix2008,starck:sta04} \nreport on their successful application in image processing experiments. The so-called first generation discrete curvelet described in \\cite{cur:donoho99,starck:sta01_3} \nconsists in applying the ridgelet transform to sub-images of a wavelet decomposition of the original image. By construction, the sub-images are \nwell localized in space and frequency and the subsequent ridgelet transform provides the necessary directional sensitivity. This latter implementation \nin combination with the good geometric properties of the Healpix pixelization scheme, inspired the digital curvelet transform on the sphere~\\cite{starck:sta05_2}. \nThe digital curvelet transform on the sphere is clearly invertible in the sense that each step of the overall transform is itself invertible. \nThe curvelet transform on the sphere has a redundancy factor of $16J + 1$ when $J$ scales are used, which may be a problem for handling huge data sets \nsuch as from the future Planck-Surveyor experiment. This can be reduced by substituting the pyramidal wavelet transform to the undecimated wavelet \ntransform in the above algorithm. More details on the wavelet, ridgelet, curvelet algorithms on the sphere can be found in \\cite{starck:sta05_2}. \nAs for the isotropic wavelet on the sphere, a straightforward extension to polarized data will consist in applying successively the curvelet transform \non the sphere to the three components $T$, $Q$ and $U$. Figure~\\ref{fig_qucur_back} shows the backprojection of a Q-curvelet coefficient and \nU-curvelet coefficient. Clearly, the shapes of these polarized curvelet functions are very different from the polarized wavelet functions.%---------------------------------------------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\section{Polarized E/B Wavelet and E/B Curvelet}\n\\label{sec:pol_eb}\n\n\\subsection{Introduction}\nWe have seen that the generalization of the Fourier representation for polarized data on the sphere is the spin-2 spherical harmonics basis denoted $_{\\pm 2}Y_{\\ell m}$: \n\\begin{equation} \nQ \\pm i U  = \\sum_{\\ell, m}  { _{\\pm 2}a_{\\ell m}}   {_{\\pm 2}Y_{\\ell m} }\n\\end{equation} \n  \nAt this point, it is convenient~\\cite{zalda} to introduce the two quantities denoted $E$ and $B$ which are defined on the sphere by \n\\begin{eqnarray}\\label{EB}\nE = &  \\sum_{\\ell, m}   a_{\\ell m} ^E Y_{\\ell m} =  \\sum_{\\ell, m}  - \\frac{ 1}{2}   ({_{ 2}a_{\\ell m}}  +  {_{- 2}a_{\\ell m}} )    Y_{\\ell m} \\\\ \\nonumber\nB = & \\sum_{\\ell, m}   a_{\\ell m} ^B Y_{\\ell m} =  \\sum_{\\ell, m}  i \\frac{ 1}{2}    ({_{ 2}a_{\\ell m}}  -  {_{- 2}a_{\\ell m}} )   Y_{\\ell m} \n\\end{eqnarray} \n%\\begin{equation}\\label{EB}\n%E =  \\sum_{\\ell, m}   a_{\\ell m} ^E Y_{\\ell m} =  \\sum_{\\ell, m}  - \\frac{   {_{ 2}a_{\\ell m}}  +  {_{- 2}a_{\\ell m}}  }  {2}  Y_{\\ell m}  \\quad \\quad \n%B =  \\sum_{\\ell, m}   a_{\\ell m} ^B Y_{\\ell m} =  \\sum_{\\ell, m}  i \\frac{   {_{ 2}a_{\\ell m}}  -  {_{- 2}a_{\\ell m}}  }  {2}   Y_{\\ell m} \n%\\end{equation} \nwhere $Y_{\\ell m}$ stands for the usual spin 0 spherical harmonics basis functions. The quantities $E$ and $B$ are derived by applying \nthe spin lowering operator twice to $Q + i U$  and the spin raising operator twice to $Q - i U$ so that $E$ and $B$ are real scalar \nfields on the sphere, invariant through rotations of the local reference frame. The normalization of $a_{\\ell m} ^E$ and $a_{\\ell m} ^B$ \nchosen in the latter definition is purely conventional but it appears to be rather popular~\\cite{1997PhRvD..55.1830Z,2003PhRvD..67b3501B}. \nStill, we could multiply $a_{\\ell m} ^E$ and $a_{\\ell m} ^B$ by some $A_{\\ell}$ and we would have just as good a representation of the initial \npolarization maps. Through a change of parity $E$ will remain invariant whereas the sign of pseudo-scalar $B$ will change. The $E$ and $B$ \nmodes defined here are not so different from the \\emph{gradient} (\\emph{i.e. curl} free) and \\emph{curl} (\\emph{i.e. divergence} free) components \nencountered in the analysis of vector fields. Finally, the spatial anisotropies of the Gaussian CMB temperature and polarization fields are \ncompletely characterized in this new linear representation by the power spectra and cross spectra of $T$, $E$ and $B$. Thanks to the different \nparities of $T$ and $E$ on one side and $B$ on the other, the sufficient statistics reduce to only four spectra namely $C_\\ell^{EE}, C_\\ell^{TE}, \nC_\\ell^{TT}, C_\\ell^{BB}$. For a given cosmological model, it is possible to give a theoretical prediction of these spectra. Aiming at inverting \nthe model and inferring the cosmological parameters, an important goal of CMB temperature and polarization data analysis is then to estimate the \nlatter power spectra, based on sampled, noisy sometimes incomplete $T$, $Q$ and $U$ spherical maps.  \n\n\\subsection{E/B Isotropic Wavelet}\nFollowing the above idea of representing CMB polarization maps by means of $E$ and $B$ modes, we propose a formal extension of the previous \nundecimated isotropic wavelet transform that will allow us to handle linear polarization data maps $T$, $Q$ and $U$ on the sphere. Practically, \nthe maps we consider are pixelized using for instance the Healpix pixelization scheme. In fact, we are not concerned at this point with the \nrecovery of E and B modes from pixelized or incomplete data maps which itself is not a trivial task. The extension of the wavelet transform \non the sphere we describe here makes use of the $E$ and $B$ representation of polarized maps described above in a formal way. Given polarization \ndata maps $T$, $Q$ and $U$, the proposed wavelet transform algorithm consists of the following steps : \n\\vspace{.1cm}\n\\begin{center}\n\\begin{minipage}[b]{0.85\\linewidth}\n\\footnotesize{\n\\begin{enumerate}\n\\item Apply the spin $\\pm 2$ spherical harmonics transform to $Q+iU$ and $Q-iU$. Practically, the Healpix software package provides an implementation \nof this transform for maps that use this pixelization scheme. Otherwise, a fast implementation was recently proposed by \\cite{wiauxspin2}.\n\\item Combine the decomposition coefficients ${ _{2}a_{\\ell m}}$ and ${ _{-2}a_{\\ell m}}$ from the first step into $a_{\\ell m}^E$ and $a_{\\ell m}^B$ \nand build \\emph{formal} $E$ and $B$ maps associated with $Q$ and $U$ by applying the usual inverse spherical harmonics transform, as in equation~\\ref{EB}. \nFor numerical and algorithmic purposes, it may be efficient to stay with the spherical harmonics representation of $E$ and $B$.\n\\item Apply the undecimated isotropic transform on the sphere described above to map $T$ and to the $E$, $B$ representation of the polarization maps. \n\\end{enumerate}}\n\\end{minipage}\n\\end{center}\n\\vspace{.1cm}\nThe wavelet coefficient maps  $w_j^T$, $w_j^E$, $w_j^B$ and the low resolution approximation maps $c_J^T$, $c_J^E$, $c_J^B$ are obtained by applying \nthe isotropic undecimated wavelet transform described in section~\\ref{sec:UWTS} to the $T$, $E$, $B$ representation of the polarized data. Figure~\\ref{fig:UWTSpol} \nshows the result of applying the proposed transform to the polarized CMB data map \\emph{ka} \\footnote{available at http://lambda.gsfc.nasa.gov/product/map/current/ } \nfrom the WMAP experiment. The top two images show the initial $Q$ and $U$ maps while the subsequent maps are the low pass and wavelet coefficients'maps \nin a four scale decomposition. The scaling function we used is a cubic box spline as proposed in section~\\ref{sec:UWTS}. The wavelet coefficients were \nobtained as the difference between two successive low pass approximations of the multiresolution decomposition of the $E$ and $B$ maps. The proper choice \nfor the scaling and wavelet functions will depend on the application and the existence of constraints to be enforced.\n\\begin{figure*}\n\\vbox{\n\\centerline{\n\\hbox{\n\\psfig{figure=ka_q_nb_hi.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n\\psfig{figure=ka_u_nb_hi.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n}\n}\n\\centerline{\n\\hbox{\n\\psfig{figure=ka__hi3_1_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n\\psfig{figure=ka__hi3_2_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n}\n}\n\\centerline{\n\\hbox{\n\\psfig{figure=ka__hi2_1_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n\\psfig{figure=ka__hi2_2_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n}\n}\n\\centerline{\n\\hbox{\n\\psfig{figure=ka__hi1_1_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n\\psfig{figure=ka__hi1_2_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n}\n}\n\\centerline{\n\\hbox{\n\\psfig{figure=ka__hi0_1_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n\\psfig{figure=ka__hi0_2_nb.pdf,bbllx=5cm,bblly=2cm,bburx= 19cm,bbury=28cm,height=7cm,width=4cm,angle = 90,clip=}\n}\n}\n}\n\\caption{\\textbf{top~:} $Q$ and $U$ CMB polarization data maps from channel \\emph{ka} of the WMAP experiment. \\textbf{left~:} low pass and wavelet coefficients in three scales of the formal E mode. \\textbf{right~:} low pass and wavelet coefficients in three scales of the formal B mode.}\n\\label{fig:UWTSpol}\n\\end{figure*}\n\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\subsection*{Reconstruction}\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\begin{figure*}[htb]\n\\centerline{\n\\vbox{\n \\hbox{\n \\includegraphics[width=7cm]{fig_e_iwt_back_scale2.pdf}\n \\includegraphics[width=7cm]{fig_b_iwt_back_scale2.pdf}\n }\n  \\hbox{\n \\includegraphics[width=7cm]{fig_e_iwt_back_scale3.pdf}\n \\includegraphics[width=7cm]{fig_b_iwt_back_scale3.pdf}\n }\n \\hbox{\n \\includegraphics[width=7cm]{fig_e_iwt_back_scale4.pdf}\n \\includegraphics[width=7cm]{fig_b_iwt_back_scale4.pdf}\n }\n }\n }\n\\caption{E-isotropic wavelet transform backprojection (left) and B-isotropic wavelet backprojection (right).}\n\\label{fig_eb_iwt_back}\n\\end{figure*}\nObviously, the transform described above is invertible and the inverse transform is readily obtained by applying the inverse \nof each of the three steps in reverse order. If, as in the example decomposition above, we take the wavelet function to be \nthe difference between two successive low pass approximations, the third step is inverted by simply summing the last low pass \napproximation with the maps of wavelet coefficients from all scales as in equation~\\ref{IWT} : \n\\begin{eqnarray}\nT  & = & c_{J}^T + \\sum_{j=1}^{J} w_j^T \\quad \\quad \\nonumber \\\\\nE & = & c_{J}^E + \\sum_{j=1}^{J} w_j^E \\quad \\quad \\nonumber \\\\\nB & = &  c_{J}^B + \\sum_{j=1}^{J} w_j^B\n\\end{eqnarray}\nwhere $c_{J}^X$ stands for the low resolution approximation to component $X$ and $w_j^X$ is the map of wavelet coefficients of that component on scale $j$. Finally, noting that : \n\\begin{eqnarray}\nQ  & =  & -\\frac{1}{2} \\sum_{\\ell, m}   a_{\\ell m} ^E   ( {_{ 2} Y}_{\\ell m} +  {_{ -2} Y}_{\\ell m} ) +  i a_{\\ell m} ^B ( {_{ 2} Y}_{\\ell m} -  {_{ -2} Y}_{\\ell m} )  \\nonumber \\\\\n     & =  & \\sum_{\\ell, m}   a_{\\ell m} ^E   Z_{\\ell m}^+ +  i a_{\\ell m} ^B Z_{\\ell m}^-   \\\\ \\nonumber\nU  & =   & -\\frac{1}{2} \\sum_{\\ell, m}   a_{\\ell m} ^B   ( {_{ 2} Y}_{\\ell m} +  {_{ -2} Y}_{\\ell m} ) -  i a_{\\ell m} ^E ( {_{ 2} Y}_{\\ell m} -  {_{ -2} Y}_{\\ell m} )  \\nonumber \\\\\n      & =  & \\sum_{\\ell, m}   a_{\\ell m} ^B Z_{\\ell m}^+ -  i a_{\\ell m} ^E Z_{\\ell m}^-   \n\\end{eqnarray}\nthe initial representation of the polarized data in terms of $T$, $Q$ and $U$ maps is reconstructed from its wavelet coefficients using the following equations : \n% \\begin{eqnarray}\n%T= c_{J}^T + \\sum_{j=1}^{J} w_j^T \\\\ \\nonumber\n%Q = \\Big \\{ \\sum_{\\ell, m}   <  c_{J}^E , Y_{\\ell m}>  {_{ +} Z}_{\\ell m} +  i <  c_{J}^B , Y_{\\ell m}>  {_{ -} Z}_{\\ell m} \\Big \\}        +   \\sum_{j=1}^{J}  \\Big \\{ \\sum_{\\ell, m}  <  w_j^E , Y_{\\ell m}>  {_{ +} Z}_{\\ell m} +  i <  w_j^B , Y_{\\ell m}>  {_{ -} Z}_{\\ell m} \\Big \\}    \\\\ \\nonumber \n%U = \\Big \\{ \\sum_{\\ell, m}   <  c_{J}^B , Y_{\\ell m}>  {_{ +} Z}_{\\ell m}  -  i <  c_{J}^E , Y_{\\ell m}>  {_{ -} Z}_{\\ell m} \\Big \\}        +   \\sum_{j=1}^{J}  \\Big \\{ \\sum_{\\ell, m}  <  w_j^B , Y_{\\ell m}>  {_{ +} Z}_{\\ell m} -  i <  w_j^E , Y_{\\ell m}>  {_{ -} Z}_{\\ell m} \\Big \\}    \n%\\end{eqnarray}\n%\\begin{eqnarray}\n%T =& c_{J}^T + \\sum_{j=1}^{J} w_j^T \\\\ \\nonumber\n%Q =& c_{J}^E  \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger} Z_{\\ell m}^+ + i c_{J}^B  \\sum_{\\ell, m} Y_{\\ell m} ^{\\dagger} Z_{\\ell m}^-  +   \\sum_{j=1}^{J}  \\Big \\{  w_j^E  \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger} Z_{\\ell m}^+ +{i} w_j^B  \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger}  Z_{\\ell m}^- \\Big \\}    \\\\ \\nonumber \n%U =& c_{J}^B  \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger} Z_{\\ell m}^+ -  i c_{J}^E  \\sum_{\\ell, m} Y_{\\ell m} ^{\\dagger} Z_{\\ell m}^-  +   \\sum_{j=1}^{J}  \\Big \\{  w_j^B  \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger} Z_{\\ell m}^+ - {i} w_j^E  \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger}  Z_{\\ell m}^- \\Big \\}   \n%\\end{eqnarray}\n\\begin{eqnarray}\\label{eq:recons}\nT =& c_{J}^T + \\sum_{j=1}^{J} w_j^T \\\\ \\nonumber\nQ =& c_{J}^{E,+} + i c_{J}^{B,-} + \\sum_{j=1}^{J} \\Big \\{ w_j^{E,+} + i w_j^{B,-} \\Big \\} \\\\ \\nonumber \nU =& c_{J}^{B,+} - i c_{J}^{E,-} + \\sum_{j=1}^{J} \\Big \\{ w_j^{B,+} - i w_j^{E,-} \\Big \\}\n\\end{eqnarray}\nwhere\n\\begin{eqnarray}\\label{eq:change}\nc_{J}^{X,+} = c_{J}^X \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger} Z_{\\ell m}^+ \\quad \\textrm{and} \\quad c_{J}^{X,-} = c_{J}^X \\sum_{\\ell, m} Y_{\\ell m}^{\\dagger} Z_{\\ell m}^- \n\\end{eqnarray}\nwith $W^\\dagger$ denoting the transpose conjugate of $W$ so that $\\tilde{W} W^\\dagger$ is the scalar dot product of $\\tilde{W}$ and $W$ \nwhile $W^\\dagger \\tilde{W}$ is an operator (or matrix) acting on its left hand side as a projection along $W$ and \\emph{reconstruction} \nalong $\\tilde{W}$. In practice, the Healpix software package provides us with an implementation of the forward and inverse spin $0$ and \nspin $2$ spherical harmonics transforms which we need to implement the proposed inverse transform given by equations~\\ref{eq:recons} \nand~\\ref{eq:change}. Clearly, as mentioned earlier in section~\\ref{sec:UWTS}, we could have chosen some other wavelet function than merely \nthe difference between two consecutive scaling functions, and the transformation would still be nearly as simple to invert. Fig.\\ref{fig_eb_iwt_back} \nshows, on the left, backprojections of E-wavelet coefficients, and, on the right, backprojections of B-wavelet coefficients on the right hand side at different scales.\n\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\subsection*{E-B  Curvelet}\n%---------------------------------------------------------------------------------------------------------------------------------------\n\\begin{figure*}[htb]\n\\centerline{\n\\vbox{\n \\hbox{\n \\includegraphics[width=12cm]{fig_ecur_back.pdf}\n }\n  }\n }\n\\caption{E-curvelet coefficient backprojection.}\n\\label{fig_ecur_back}\n\\end{figure*}\n\n\\begin{figure*}[htb]\n\\centerline{\n\\vbox{\n \\hbox{\n \\includegraphics[width=12cm]{fig_bcur_back.pdf}\n }\n }\n }\n\\caption{B-curvelet coefficient backprojection.}\n\\label{fig_bcur_back}\n\\end{figure*}\nSimilarly to the EB-wavelet constructions, we can easily construct an EB-curvelet transform by first computing the E and B components using \nthe spin $\\pm 2$ spherical harmonics transform, and then applying a curvelet transform on the sphere separately on each of these two components.\nFig.~\\ref{fig_ecur_back} shows the backprojection of an E-curvelet coefficient and Fig.~\\ref{fig_bcur_back} shows the backprojectionof a B-curvelet coefficient.\n\n%---------------------------------------------------------------------------------------------------------------------------------------\n", "meta": {"hexsha": "841d1ce663b728e7dc8e1065a258c2142868030d", "size": 35672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/archive_tex/multiscale_pola.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/multiscale_pola.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/multiscale_pola.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": 68.998065764, "max_line_length": 473, "alphanum_fraction": 0.6821596771, "num_tokens": 11229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6736126646819064}}
{"text": "﻿\\chapter{Machine Learning techniques} \\label{chap3}\r\n\\section{Introduction}\r\nIn this chapter, we will focus on the more traditional methods used in natural language processing such as Na\\\"{i}ve-Bayes, decision trees, linear SVM and others. These will serve as a baseline for comparing the performances of the more two advanced models that will be analysed later on: LSTM and Attention Mechanism. The first thing to do when working with text is the do words and texts embedding, indeed, in order to use machine learning algorithms on texts, a mathematical representation of these texts is required. \r\n\\section{Text to vectors}\r\nAs explained before, text needs to be represented in a way that gives more meaningful information than a simple sequence of bits, which have additional drawbacks such that for a given word, the sequence of bits representing it depends on the coding.\r\n The first and simplest coding that comes to mind is a one-hot encoding: a matrix $M$ of size number of texts $\\times$ number of words where $M_{ij} = 1$ if the word $j$ is present in the text  $i$ and $0$ in the other case. But this is still not enough as each word is given the same weight, no matter how often it appears in the text. \\\\ \r\n\r\n In order to overcome this problem, term-frequency might be used, that is, rather than setting $M_{ij}$ to 0 or 1 we set it to the amount of time it appears in the text. \\\\ \r\n\r\n It is possible to use even better text embedding. It is called term-frequency, inverse document frequency. The main idea is that a word that appears often in all the documents is not helpful in order to classify the documents. For example, if the task is to classify books of biology and physics, words atoms, cells or light are more useful than today or tomorrow. \\\\\r\n\r\nIn order to compute tf-idf, it is separated in two parts, the first one being term frequency and the second one inverse document frequency. We have that \\begin{equation}\r\n tf_{ij} = \\#(W_j | W_j \\in D_i)\\\\ \r\n\\end{equation}\r\nThat it $tf_{ij}$ is the number of times the word j appears in the document i. \r\nSecondly, we have that \\begin{equation*}\r\n idf_{j} = \\log(\\frac{\\#D}{\\#(D_i | W_j \\in D_i)}) \\\\\r\n\\end{equation*}\r\nthis is the log of the total number of documents, over the number of documents that contains the word j.\r\nFinally, the value tfidf value is computed by \\begin{equation}\r\n tf-idf_{ij} = tf_{ij} * idf_{j} \\\\\r\n\\end{equation}\r\nThis the text embedding methods that will be used in this section. \r\n\\section{Methodology}\r\n\\paragraph{} All the methods presented will be tested in two different ways: \r\n\\begin{itemize}\r\n \\item On the liar-liar dataset\r\n \\item On the fake corpus dataset, excluding the news from \\textit{beforeitsnews.com} and \\textit{nytimes.com}\r\n\\end{itemize}\r\nTo be more precise, in the first case, the models will be trained on a training set, tuned using validation set and finally tested using test set. In the second case, the same methodology will be used, the dataset has been split be choosing $60\\%$ of the text from each domain for training, and $20\\%$ for validation and testing. This way of splitting has been chosen because of the uneven representation of each domain in the dataset in order to ensure representation of all the domains in the tree subsets. \r\n\\subsection{Evaluation Metrics}\r\nIn order to evaluate each model, multiple evaluation metrics have been used. There are recall, precision and f1-score. It is needed to use multiple metrics because they don't all account for the same values. For instance, it is possible to have a model with a recall of 1 that behave extremely bad because it simply classifies all the inputs in the same single class. \r\nRemember That Precision Is Defined As \\begin{equation}\r\n Precision = \\frac{TP}{TP + FP}\r\n\\end{equation}\r\nWhich means that we can have two different precision, depending on which classes is considered as being positive. This is the proportion of correctly classified positive elements over the number of elements classified as positive. It is equals to 1 when there is no false positive, but it does not mean that all the positive elements are correctly classified as it might be some false negative. The recall helps to solve this problem.\r\nIt Is Defined As \\begin{equation}\r\n recall = \\frac{TP}{TP + FN}\r\n\\end{equation}\r\nThe f1-score combines the recall and the precision. It is defined by \r\n\\begin{equation}\r\n f1-score = \\frac{2 * precision * recall}{precision + recall}\\\\\r\n\\end{equation}\r\nIt is also possible to look at the weighted average of all these values. For instance, it is possible to compute the global recall by averaging the recall for both classes by the respective class ratio. \\\\\r\n\r\nFinally, raw output can be used by looking at the confusion matrix.\\\\\r\n\r\nThe first parameter to tune is the max number of features used by tf-idf. This is the maximum number of words that will be kept to create the text encoding. The words that are kept are the most frequent words. \r\n\\section{Models}\r\nFour models have been used in order to classify texts represented as a TF-IDF matrix. These are Multinomial Na\\\"{i}ve-Bayes, Linear SVM, Ridge Classifier and Decision Tree. I will start by a very brief recap of each model and how they work. \r\n\\subsection{Na\\\"{i}ve-Bayes\\cite{zhang_optimality_nodate}}\r\nThe basic idea of Na\\\"{i}ve-Bayes model is that all features are independent of each other. This is a particularly strong hypothesis in the case of text classification because it supposes that words are not related to each other. But it knows to work well given this hypothesis. \r\nGiven an element of class y and vector of features $\\mathbf{X} = (x_1,...,x_n)$. The probability of the class given that vector is defined as \r\n\\begin{equation}\r\n P(y | \\mathbf{X}) = \\frac{P(y)*P(\\mathbf{X} | y)}{P(\\mathbf{X})}\r\n\\end{equation}\r\nThanks to the assumption of conditional independence, we have that \r\n\\begin{equation}\r\n P(x_i |y,x_1, ...,x_{i-1},x_{i+1},...,x_n) = P(x_i | y)\r\n\\end{equation}\r\nUsing Bayes rules we have that\r\n\\begin{equation}\r\n P(y|x_1,...,x_n) = \\frac{P(y)\\prod_{i=1}^n P(x_i | y)}{P(x_1,...,x_n)}\r\n\\end{equation}\r\nBecause $P(x_1,...,x_n)$ is constant, we have the classification rule \r\n\\begin{equation}\r\n \\hat{y} = \\underset{y}{argmax} P(y)\\prod_{i=1}^n P(x_i | y)\r\n\\end{equation}\r\n\\subsection{Linear SVM}\r\nLinear SVM is a method for large linear classification. Given pairs of features-label $(\\mathbf{x_i}, y_i), y_i \\in \\{-1, 1\\}$, it solves the following unconstrained optimization problem. \r\n\\begin{equation}\r\n \\underset{w}{min} \\frac{1}{2} \\mathbf{w^Tw} + \\mathbf{C} \\sum_{i=1}^l \\xi(\\mathbf{w;x_i},y_u)\r\n\\end{equation}\r\nWhere $\\xi$ is a loss function, in this case L2 loss function has been used, and $\\mathbf{C} > 0$ a penalty parameter. \r\nClass of new examples are assigned by looking at the value of $\\mathbf{w^Tw}$. The class 1 is assigned if $\\mathbf{w^Tw} \\geq 0$ and the class $-1$ if $\\mathbf{w^Tw} < 0$.\r\n\\subsection{Decision Tree\\cite{Rokach:2014:DMD:2755359}}\r\nDecision tree works by recursively selecting features and splitting the dataset on those features. These features can either be nominal or continuous. \\\\\r\n\r\nIn order to find the best split, it uses gini impurity. \r\n\\begin{equation}\r\n G = \\sum_{i=1}^C p(i) * (1-p(i))\\\\\r\n\\end{equation}\r\nWhere $p(i)$ is the probability of class i in the current branch. The best split is chosen as the one that decreases the most the impurity. For instance, beginning from the root, the gini impurity is computed on the complete dataset, then the impurity of each branch is computed over all features, weighting it by the number of elements in each branch. The chosen feature is the one that has the highest impurity. \r\n\\subsection{Ridge Classifier}\r\nRidge classifier works the same way as ridge regression. It states the problem as a minimization of the sum of square errors with penalization. It can be expressed as in \\textbf{Equation \\ref{eq:ridge}}.\r\n\\begin{equation}\r\n \\underset{w}{min} ||Xw-y||^2_2 + \\alpha ||w||^2_2 \\label{eq:ridge}\r\n\\end{equation}\r\nThe predicted class if positive if Xw is positive and negative otherwise. \r\n\\section{Models on liar-liar dataset}\r\n\\subsection{Linear SVC}\r\nIn the case of linear SVC there is one parameter to tune up, which is the penalty parameters for the error term. \\textbf{Figure \\ref{fig:chap3:linearSVC}} shows the three main metrics with respect to the penalty parameter. This show that a parameter of around $0.1$ is the best one. \r\n\\begin{figure*}[]\r\n \\centering\r\n \\makebox[\\textwidth][c]{\\includegraphics[width=1\\textwidth]{images/chapitre3/svc_liar.pdf}}\r\n \\caption{Tuning linearSVC parameters }\r\n \\label{fig:chap3:linearSVC}\r\n\\end{figure*}\r\n\\subsection{Decision Tree}\r\nWith decision trees, it is possible to reduce overfitting by pruning the tree. It is possible to do pre-pruning or post pruning. Pre-pruning means that a stopping criterion is used to stop tree growth earlier and post pruning cut the tree once it has been fully grown. It this case pre-pruning is done by limiting the maximum depth of the tree. \r\n\\begin{figure*}[]\r\n \\centering\r\n \\makebox[\\textwidth][c]{\\includegraphics[width=1\\textwidth]{images/chapitre3/liar-dt.pdf}}\r\n \\caption{Tuning Decision Tree Parameters }\r\n \\label{fig:chap3:dt}\r\n\\end{figure*}\r\n\\textbf{Figure \\ref{fig:chap3:dt}} shows metrics values for different depths. It seems that tree of depth 1000 are the best ones.\r\n\\subsection{Ridge Classifier}\r\nWith the ridge classifier model, it is also possible to tweak the penalty value of the optimization problem. At \\textbf{Figure \\ref{fig:chap3:ridge1}} we can see that the optimal parameter is around 10 or 20, depending of the metrics that we want to maximize. Later on, the value of 10 will be chosen as a compromise between precision and recall. It is the value that maximizes the f1-score. \r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=1\\textwidth]{images/chapitre3/liar-ridge}\r\n \\caption{Average metrics for ridge classifiers with respect to the penalty parameter.}\r\n \\label{fig:chap3:ridge1}\r\n\\end{figure*} \r\n\\subsection{Max Feature Number}\r\nStarting with the maximum number of features, the precision of each model can be analysed when limiting the maximum number of words. The results for each model can be seen at \\textbf{Figure \\ref{fig:chap3:max_feature3}, \\ref{fig:chap3:max_feature1}} and \\textbf{\\ref{fig:chap3:max_feature2}}. Shows that depending on the metrics we want to optimize it is better to choose different parameters. For instance, in order to maximize F1-score, it is better to use a maximum number of features of 1000.\\\\\r\n\r\nThe results are slightly different if the goal is to optimize the precision because if the best value stays the same for Linear SVM and Ridge Classifier, the Na\\\"{i}ve-Bayes work better when using the maximum number of features and it goes the same way for recall. \r\nBased on \\textbf{Figure \\ref{fig:chap3:max_feature3}} we can say that when it comes to precision and recall, Na\\\"{i}ve-Bayes is the one that performs the best.\\\\\r\n\r\nRow results for max features selection are available at \\textbf{Appendix \\ref{Appendix1}}.\r\n\\begin{figure*}[]\r\n \\centering\r\n \\makebox[\\textwidth][c]{\\includegraphics[width=1.2\\textwidth]{images/chapitre3/liar-liar_f1_ML}}\r\n \\caption{Weighted average of f1-score, precision and recall of each class. }\r\n \\label{fig:chap3:max_feature3}\r\n\\end{figure*}\r\nIt goes differently when we focus on a single class. For example, the precision for fake detection is at its maximum for Linear SVM and Ridge Classifier when only 10 features are used. But at the same time, it is at its minium for reliable class. It shows that when trying to optimize the overall model and not only for a single class, it is better to look at the weighted average than at the value for a single class. But it is still important to look at the metrics for a single class because it indicates how it behaves for this class. For instance, in the case of automatic fake news detection, it is important to minimize the number of reliable news misclassified in order to avoid what could be called censorship. \r\n\\begin{figure*}[]\r\n \\centering\r\n \\makebox[\\textwidth][c]{\\includegraphics[width=1.2\\textwidth]{images/chapitre3/liar-liar_precision_ML}}\r\n \\caption{Precision of the model for each class, the x axes is log scale of the number of features}\r\n \\label{fig:chap3:max_feature1}\r\n\\end{figure*}\r\n\\begin{figure*}[]\r\n \\centering\r\n \\makebox[\\textwidth][c]{\\includegraphics[width=1.2\\textwidth]{images/chapitre3/liar-liar_recall_ML}}\r\n \\caption{Precision of the model for each class, the x axes is log scale of the number of features}\r\n \\label{fig:chap3:max_feature2}\r\n\\end{figure*}\r\n\\section{Models on fake corpus dataset}\r\n\\subsection{SMOTE: Synthetic Minority Over-sampling Technique\\cite{Chawla2011}}\r\nAs it has been shown in \\textbf{Chapter \\ref{chap2}}, the fake news corpus is unbalanced. Synthetic minority oversampling is a technique that allows generating fake samples from the minor class. It works by randomly choosing one or many nearest neighbours in the minority class. For instance, if the algorithm is set to use 5 nearest neighbours, for each sample it will choose one of its nearest neighbours, and generate a new sample on the segment joining the sample and its neighbour. \r\n\\begin{algorithm}\r\n  \\KwData{k = Number of nearest neighbours}\r\n  \\KwData{T = number of minority class samples}\r\n  \\For{$i \\leftarrow 1...T$}{Compute k-nearest neighbours of sample i\\;\r\n   Populate(knn, i)\\;}\r\n  \\caption{SMOTE}\r\n  \\label{algo:SMOTE}\r\n\\end{algorithm}\r\n\\begin{algorithm}\r\n \\KwData{knn = the k-nearest neighbour of sample i}\r\n \\KwData{s = ith sample}\r\n nn = random\\_choice(knn)\\;\r\n newSample = s + rand(0, 1) * (nn - s)\\;\r\n \\caption{Populate}\r\n \\label{algo:populate}\r\n\\end{algorithm}\r\n\\textbf{Algorithm \\ref{algo:SMOTE}} and \\textbf{\\ref{algo:populate}} shows how it works. The first one computes the k-nearest neighbours and the second one computes a new element by randomly choosing one of these neighbours. \r\n\\subsection{Model selection without using SMOTE}\r\n\\subsubsection{Hyperparameters tuning}\r\nAs for the models trained on the \\textbf{liar-liar corpus}, hyper-parameters can be optimized the same way. The average metric for each model with respect to their parameters are shown at \\textbf{Figure \\ref{fig:chap3:ridge2}, \\ref{fig:chap3:dt2}} and \\textbf{\\ref{fig:chap3:lsvm2}}. \\\\\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ridge}\r\n \\caption{Metrics value with respect to the penalty parameter for ridge classifier}\r\n \\label{fig:chap3:ridge2}\r\n\\end{figure*}\r\nThe optimal parameter for the ridge classifier is clearly 1. As well as for the decision tree trained on \\textbf{liar-liar} dataset, the optimal maximum depth is of 1000. \r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/fake-dt}\r\n \\caption{Optimal depth of decision tree.}\r\n \\label{fig:chap3:dt2}\r\n\\end{figure*}\r\nAnd finally, the optimal value for the penalty parameter of the svm is also 1.\\\\\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/svc_fake}\r\n \\caption{Optimal penalty parameters for linear svm}\r\n \\label{fig:chap3:lsvm2}\r\n\\end{figure*}\r\nBy looking at \\textbf{Figure \\ref{fig:chap3:max_feature1}, \\ref{fig:chap3:max_feature2}} and \\textbf{\\ref{fig:chap3:max_feature3}} we can find optimal parameters for the number of features used in TF-IDF. It shows that linear svm and ridge classifiers are the ones that perform the best, having an average precision of sligtly more than $94\\%$ for the linear svm and $94\\%$ for the ridge classifier. They achieve these performances from $50,000$ features and does not decrease. On the other hand, Na\\\"{i}ve-Bayes reaches a pike at $100,000$ features and greatly decrease afterward. \\\\\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ML_fake_average}\r\n \\caption{Average recall, precision and f1-score wti respect to the maximum number of features.}\r\n \\label{fig:chap3:max_feat1}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ML_fake_precision}\r\n \\caption{Precision for fake and reliable class for each model with respect to the maximum number of features}\r\n \\label{fig:chap3:max_feat2}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ML_fake_recall}\r\n \\caption{Recall for fake and reliable class for each model with respect to the maximum number of features}\r\n \\label{fig:chap3:max_feat3}\r\n\\end{figure*}\r\n\r\n\\textbf{Figure \\ref{fig:chap3:max_feature3}} shows why it is important to look at all the metrics, because Na\\\"{i}ve-Bayes reaches a recall of 1 for the reliable class and close to 0 for the fake class, which means that almost all texts are classified as reliable. This can be verified by looking at \\textbf{Figure \\ref{fig:chap3:confMat1}}, only a small proportion of true fake is actually classified as it.\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.5\\textwidth]{images/chapitre3/confMat_fake_364070}\r\n \\caption{Confusion matrix for each model using $364,070$ features}\r\n \\label{fig:chap3:confMat1}\r\n\\end{figure*}\r\n\\subsection{Model selection with SMOTE}\r\nThe first thing that can be noticed at \\textbf{Figure \\ref{fig:chap3:ridge3}, \\ref{fig:chap3:dt3}, \\ref{fig:chap3:lsvm3}, \\ref{fig:chap3:smote_max_feat1}, \\ref{fig:chap3:smote_max_feat2}} and \\textbf{\\ref{fig:chap3:smote_max_feat3}} is that the two models that worked the best without applying SMOTE method, linear SVM and ridge classifiers are still the ones that perform the best. By comparing \\textbf{Figure \\ref{fig:chap3:lsvm2}} and \\textbf{Figure \\ref{fig:chap3:lsvm3}} we can see that it works better when applying a smaller regularization parameter. It goes from $0.66\\%$ of accuracy to  $0.86\\%$ of accuracy thus acting as a regularization. The same does not apply to ridge classifiers. \\\\\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ridge+smote}\r\n \\caption{Metrics value with respect to the penalty parameter for ridge classifiers when using SMOTE.}\r\n \\label{fig:chap3:ridge3}\r\n\\end{figure*}\r\nIt also has a huge impact on how Na\\\"{i}ve-Bayes behaves as it removes overfitting when using a larger number of features in TF-IDF, leading to a few percent of accuracy increase. \\\\\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/fake-dt-SMOTE}\r\n \\caption{Optimal depth of decision tree when using SMOTE.}\r\n \\label{fig:chap3:dt3}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/svc_fake_smote}\r\n \\caption{Optimal penalty parameters for linear svm when using SMOTE}\r\n \\label{fig:chap3:lsvm3}\r\n\\end{figure*}\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ML_SMOTE_fake_average}\r\n \\caption{Average recall, precision and f1-score wti respect to the maximum number of features.}\r\n \\label{fig:chap3:smote_max_feat1}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ML_SMOTE_fake_precision}\r\n \\caption{Precision for fake and reliable class for each model with respect to the maximum number of features}\r\n \\label{fig:chap3:smote_max_feat2}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/ML_SMOTE_fake_recall}\r\n \\caption{Recall for fake and reliable class for each model with respect to the maximum number of features}\r\n \\label{fig:chap3:smote_max_feat3}\r\n\\end{figure*}\r\nIt conclusion for SMOTE method we can say that it does help models that do not have a regularization parameter or when the regularization parameter is low. Thus it does help prevent overfitting.\r\n\\section{Results on testing set}\r\n\\subsection{Methodology}\r\nNow that all the models have been tuned, they need to be tested independently on testing set. Each dataset contains a testing set. \\\\\r\nFor the \\textbf{liar-liar} dataset the following parameters will be used:\r\n\\begin{itemize}\r\n \\item Linear SVM with regularization parameters of $0.1$ of a max TF-IDF features of 500,\r\n \\item Ridge Classifier with $\\alpha = 10$ and also max TF-IDF features of 500,\r\n \\item Decision Tree with maximum depth of 1000 and the maximum number of features for TF-IDF,\r\n \\item Na\\\"{i}ve-Bayes will also use the maximum number of features for TF-IDF.\r\n\\end{itemize}\r\nFor the \\textbf{Fake News Corpus}, the following setting will be used:\r\n\\begin{itemize}\r\n \\item Linear SVM with regularization parameters of $1$,\r\n \\item Ridge Classifier with $\\alpha = 1$,\r\n \\item Decision Tree with maximum depth of 100.\r\n\\end{itemize}\r\nThey will all be trained using $100,000$ features for TF-IDF.\r\nFor the \\textbf{Fake News Corpus} with SMOTE, the same parameters will be used, but the maximum number of features for TF-IDF will be used.\\\\\r\nAll the models will be trained on train and validation set and tested on test set. \r\n\\subsection{Results}\r\n\\subsubsection{Liar-Liar Corpus}\r\nBy looking at the row results, based on average accuracy Na\\\"{i}ve-Bayes, Linear SVM and ridge classifiers perform very close, but when looking at the recall per class it shows that Na\\\"{i}ve-Bayes is bad at detecting fake news and classifies most of the text as reliable, when Linear SVM and Ridge classifiers are more balanced. \r\n\\begin{table}\r\n\\begin{subtable}{\\textwidth}\r\n\\begin{tabular}{lrrrrr}\r\n\\toprule\r\n{} &         fake &     reliable &  accuracy &    macro avg &  weighted avg \\\\\r\n\\midrule\r\nf1-score  &     0.514399 &     0.679764 &  0.614049 &     0.597082 &      0.607588 \\\\\r\nprecision &     0.570485 &     0.638376 &  0.614049 &     0.604430 &      0.608744 \\\\\r\nrecall    &     0.468354 &     0.726891 &  0.614049 &     0.597623 &      0.614049 \\\\\r\nsupport   &  1106.000000 &  1428.000000 &  0.614049 &  2534.000000 &   2534.000000 \\\\\r\n\\bottomrule\r\n\\end{tabular}\r\n\\caption{Raw results for Linear SVM}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n\\begin{tabular}{lrrrrr}\r\n\\toprule\r\n{} &         fake &     reliable &  accuracy &    macro avg &  weighted avg \\\\\r\n\\midrule\r\nf1-score  &     0.412107 &     0.698507 &  0.601421 &     0.555307 &      0.573504 \\\\\r\nprecision &     0.578431 &     0.608741 &  0.601421 &     0.593586 &      0.595512 \\\\\r\nrecall    &     0.320072 &     0.819328 &  0.601421 &     0.569700 &      0.601421 \\\\\r\nsupport   &  1106.000000 &  1428.000000 &  0.601421 &  2534.000000 &   2534.000000 \\\\\r\n\\bottomrule\r\n\\end{tabular}\r\n\\caption{Raw results for Na\\\"{i}ve-Bayes}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n\\begin{tabular}{lrrrrr}\r\n\\toprule\r\n{} &         fake &     reliable &  accuracy &    macro avg &  weighted avg \\\\\r\n\\midrule\r\nf1-score  &     0.496366 &     0.691279 &  0.617206 &     0.593822 &      0.606207 \\\\\r\nprecision &     0.582927 &     0.633606 &  0.617206 &     0.608266 &      0.611486 \\\\\r\nrecall    &     0.432188 &     0.760504 &  0.617206 &     0.596346 &      0.617206 \\\\\r\nsupport   &  1106.000000 &  1428.000000 &  0.617206 &  2534.000000 &   2534.000000 \\\\\r\n\\bottomrule\r\n\\end{tabular}\r\n\\caption{Raw results for Ridge Classifer.}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n\\begin{tabular}{lrrrrr}\r\n\\toprule\r\n{} &         fake &     reliable &  accuracy &    macro avg &  weighted avg \\\\\r\n\\midrule\r\nf1-score  &     0.479354 &     0.591549 &  0.542226 &     0.535451 &      0.542580 \\\\\r\nprecision &     0.475936 &     0.594901 &  0.542226 &     0.535418 &      0.542977 \\\\\r\nrecall    &     0.482821 &     0.588235 &  0.542226 &     0.535528 &      0.542226 \\\\\r\nsupport   &  1106.000000 &  1428.000000 &  0.542226 &  2534.000000 &   2534.000000 \\\\\r\n\\bottomrule\r\n\\end{tabular}\r\n\\caption{Raw results for Decision Tree}\r\n\\end{subtable}\r\n\\caption{Raw results on \\textbf{Liar-Liar Corpus}.}\r\n\\end{table}\r\nFinally, it is possible to look at the ROC curve at \\textbf{Figure \\ref{fig:chap3:roc1}}. One more time, it shows that Na\\\"{i}ve-Bayes, linear svm and ridge classifier have similar performance, but in this case it shows that NB has a little advantage, with a slightly larger AUC. There is only one point for the decision tree as it does not output probabilities for each class. \\\\\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/roc1}\r\n \\caption{ROC curve for each model}\r\n \\label{fig:chap3:roc1}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/test_liar_confMat}\r\n \\caption{Confusion Matrix for each models}\r\n \\label{fig:chap3:confMat1}\r\n\\end{figure*}\r\nWhen it comes to the \\textbf{Fake news corpus}, linear models are still the ones that perform the best, with linear svm reaching an accuracy of $94.7\\%$ and ridge classifiers $93.98\\%$. Surprisingly, decision tree outperform Na\\\"{i}ve-Bayes in this case, with an accuracy of $89.4\\%$ when Na\\\"{i}ve-Bayes only gets $85.3\\%$.\\\\\r\n\r\n\\begin{table}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.894700 &      0.965364 &  0.947874 &      0.930032 &      0.947620 \\\\\r\n precision &      0.907861 &      0.960783 &  0.947874 &      0.934322 &      0.947494 \\\\\r\n recall    &      0.881916 &      0.969989 &  0.947874 &      0.925952 &      0.947874 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.947874 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results for Linear SVM on \\textbf{Fake News Corpus}}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.674458 &      0.905634 &  0.853682 &      0.790046 &      0.847585 \\\\\r\n precision &      0.764127 &      0.875841 &  0.853682 &      0.819984 &      0.847790 \\\\\r\n recall    &      0.603624 &      0.937525 &  0.853682 &      0.770574 &      0.853682 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.853682 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results for Na\\\"{i}ve-Bayes on \\textbf{Fake News Corpus}}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.874220 &      0.960438 &  0.939808 &      0.917329 &      0.938788 \\\\\r\n precision &      0.919674 &      0.945736 &  0.939808 &      0.932705 &      0.939192 \\\\\r\n recall    &      0.833048 &      0.975604 &  0.939808 &      0.904326 &      0.939808 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.939808 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results for Ridge Classifier on \\textbf{Fake News Corpus}}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.791687 &      0.929799 &  0.894987 &      0.860743 &      0.895119 \\\\\r\n precision &      0.788700 &      0.930987 &  0.894987 &      0.859844 &      0.895258 \\\\\r\n recall    &      0.794696 &      0.928614 &  0.894987 &      0.861655 &      0.894987 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.894987 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results for Decision Tree on \\textbf{Fake News Corpus}}\r\n\\end{subtable}\r\n\\caption{Results on \\textbf{Fake News Corpus} without using SMOTE.}\r\n\\end{table}\r\nIn this case, the ROC curve (\\textbf{Figure \\ref{fig:chap3:roc2}}) shows almost the same ranking of models, except for Decision Tree that is the last one, and Na\\\"{i}ve-Bayes being juste above it. \r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/roc2}\r\n \\caption{ROC curve for each model}\r\n \\label{fig:chap3:roc2}\r\n\\end{figure*}\r\nConfusion matrix (\\textbf{Figure \\ref{fig:chap3:confMat2}}) shows that Na\\\"{i}ve-Bayes has a tendency of classifying fake news as being reliable. And the other hand, ridge classifier is the one that makes the least misclassification for reliable news, which is a good point. \\\\\r\n\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/test_fake_confMat}\r\n \\caption{Confusion Matrix for Each models}\r\n \\label{fig:chap3:confMat2}\r\n\\end{figure*}\r\nFinally, there is the results of the models trained with SMOTE data augmentation. Using it shows little to no improvements. The only benefit is to balance a little bit the recall for Na\\\"{i}ve-Bayes on fake and reliable news. \r\n\\begin{table}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.891373 &      0.962340 &   0.94407 &      0.926857 &      0.944520 \\\\\r\n precision &      0.869960 &      0.970623 &   0.94407 &      0.920291 &      0.945346 \\\\\r\n recall    &      0.913866 &      0.954198 &   0.94407 &      0.934032 &      0.944070 \\\\\r\n support   &  17496.000000 &  52181.000000 &   0.94407 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results of linear svm on \\textbf{Fake News Corpus} when training using SMOTE}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.714816 &      0.873538 &  0.824777 &      0.794177 &      0.833683 \\\\\r\n precision &      0.604424 &      0.950521 &  0.824777 &      0.777472 &      0.863615 \\\\\r\n recall    &      0.874543 &      0.808091 &  0.824777 &      0.841317 &      0.824777 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.824777 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results of Na\\\"{i}ve-Bayes on \\textbf{Fake News Corpus} when training using SMOTE}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.877755 &      0.956129 &  0.935431 &      0.916942 &      0.936449 \\\\\r\n precision &      0.836588 &      0.973317 &  0.935431 &      0.904953 &      0.938984 \\\\\r\n recall    &      0.923182 &      0.939537 &  0.935431 &      0.931360 &      0.935431 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.935431 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results of Ridge Classifier on \\textbf{Fake News Corpus} when training using SMOTE}\r\n\\end{subtable}\r\n\\begin{subtable}{\\textwidth}\r\n \\begin{tabular}{lrrrrr}\r\n \\toprule\r\n {} &          fake &      reliable &  accuracy &     macro avg &  weighted avg \\\\\r\n \\midrule\r\n f1-score  &      0.787226 &      0.921178 &  0.884969 &      0.854202 &      0.887542 \\\\\r\n precision &      0.734992 &      0.946085 &  0.884969 &      0.840539 &      0.893079 \\\\\r\n recall    &      0.847451 &      0.897549 &  0.884969 &      0.872500 &      0.884969 \\\\\r\n support   &  17496.000000 &  52181.000000 &  0.884969 &  69677.000000 &  69677.000000 \\\\\r\n \\bottomrule\r\n \\end{tabular}\r\n \\caption{Raw results of Decision tree on \\textbf{Fake News Corpus} when training using SMOTE}\r\n\\end{subtable}\r\n\\caption{Results on \\textbf{Fake News Corpus} when training with SMOTE.}\r\n\\end{table}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/roc3}\r\n \\caption{ROC curve for each model}\r\n \\label{fig:chap3:roc3}\r\n\\end{figure*}\r\n\\begin{figure*}\r\n \\centering\r\n \\includegraphics[width=0.8\\textwidth]{images/chapitre3/test_SMOTE_fake_confMat}\r\n \\caption{Confusion Matrix for each models}\r\n \\label{fig:chap3:confMat3}\r\n\\end{figure*}\r\n\\section{Conclusion}\r\nIn this chapter we have analysed how traditional machine learning algorithms words on two different datasets, the second being imbalanced a data augmentation technique, called SMOTE, has been used in order to see if it improves the results. \\\\\r\n\r\nWe can conclude that in all the cases linear models are the ones that work the best, with a top accuracy of $61.7\\%$ on the \\textbf{liar-liar corpus} using Ridge Classifier, and a top accuracy of $94.7\\%$ on the \\textbf{Fake News Corpus} using linear svm. At the end, the result obtains on the second data set are really good, when those obtain on the first when are mitigated. \\\\\r\n\r\nAs explained earlier, it might be important to choose to model that makes the smaller misclassification rate on reliable news in order to avoid possible censorship and confusion matrix shows that in both case Ridge Classifiers is the ones that make the fewer errors in that case. \\\\\r\n\r\nIn addition, we have shown that Synthectic Minority Over Sampling Techniques acts as a regularizers, as it does improve performance when the penalization term in small on linear models. \\\\\r\n\r\nIn the next section, the focus will be put on trying to improve results on the \\textbf{Liar-Liar corpus} as there is room for improvement and that the second dataset already as very good results. But models will still be trying on it for comparison. ", "meta": {"hexsha": "254a7c3f45af3ef8213e5a604c97dd4e2006696b", "size": 33147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reviews/final/chapter3.tex", "max_stars_repo_name": "SimonKenoby/Master-Thesis-Fake-News-Dectection", "max_stars_repo_head_hexsha": "2c3a5e82d4c7d6294ca87c265a1b638d61f2cb08", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-04T22:39:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T08:15:14.000Z", "max_issues_repo_path": "reviews/final/chapter3.tex", "max_issues_repo_name": "SimonKenoby/Master-Thesis-Fake-News-Dectection", "max_issues_repo_head_hexsha": "2c3a5e82d4c7d6294ca87c265a1b638d61f2cb08", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-22T12:00:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-24T19:09:04.000Z", "max_forks_repo_path": "reviews/final/chapter3.tex", "max_forks_repo_name": "SimonKenoby/Master-Thesis-Fake-News-Dectection", "max_forks_repo_head_hexsha": "2c3a5e82d4c7d6294ca87c265a1b638d61f2cb08", "max_forks_repo_licenses": ["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.6941649899, "max_line_length": 721, "alphanum_fraction": 0.716625939, "num_tokens": 9692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.673612663281211}}
{"text": "\\appendix\n\\section{Proof}\n\n\\begin{proof}[Proof of Proposition~\\ref{thm:1}]\nFrom the cross-validation criterion, for linear models we have the well-known result that\n    \\begin{equation*}\n    \\frac{1}{T} \\sum_{i=1}^T \\tilde{e_t}^2 = \\frac{1}{T} \\sum_{i=1}^T \\frac{\\tilde{e_t}^2}{(1-h_t)^2}\n    \\end{equation*}\nwhere $h_t = x_t'(X'X)^{-1}x_t$ is the leverage associated with observation $t$. Applying Taylor expansion, we can expand the above equation as\n    \\begin{eqnarray*}\n    \\frac{1}{T} \\sum_{i=1}^T \\tilde{e_t}^2 & = & \\frac{1}{T} \\sum_{i=1}^T \\frac{\\tilde{e_t}^2}{(1-h_t)^2} \\\\\n                                           & \\approx & \\frac{1}{T} \\sum_{i=1}^T \\hat{e_t}^2 + \\frac{2}{T} \\sum_{i=1}^T \\hat{e_t}^2 h_t \\\\\n                                           & = & \\hat{\\sigma}^2 + \\frac{2}{T} \\sum_{i=1}^T \\hat{e_t}^2 x_t' (X'X)^{-1} x_t\n    \\end{eqnarray*}\nUnder regularity conditions listed in Assumption~\\ref{asump:1}, we have $\\hat{\\sigma}^2 \\stackrel{p}{\\rightarrow} \\sigma^{2}$, and for the penalty term,  $\\frac{1}{T} \\sum_{i=1}^T \\hat{e_t}^2 x_t' (X'X)^{-1} x_t \\stackrel{p}{\\rightarrow} E(\\boldmath{e'Pe})$, putting these two parts together, we can see that CV is asymptotically equivalent to Mallows' Cp under our assumptions except for conditionally homoscedastic errors.\n\\end{proof}\n<<<<<<< HEAD\n\n\\begin{proof}[Proof of Corollary~\\ref{corollary:1}]\nSince CV is asymptotically equivalent to Mallows' Cp, following Hansen's \\cite{hansen2009averaging} proof, write the sample CV criterion for the weighted model as a function of the break model weight $w$,\n    \\begin{equation*}\n      \\mathrm{CV}(w) = (w\\hat{e} + (1-w)\\tilde{e})'(w\\hat{e} + (1-w)\\tilde{e}) + 2(T - 2k)^{-1}(k + w\\bar{p})\\hat{e}'\\hat{e}\n    \\end{equation*}\nwhere $\\bar{p}$ proposed by Hansen is used to approximate the infeasible expected value of the population penalty term. The CV weight is the value in $[0, 1]$ that minimizes $\\mathrm{CV}(w)$, so\n    \\begin{equation*}\n      \\hat{w} = \\frac{(T - 2k)(\\sum_{t=1}^{T}\\tilde{e}_{t}^{2} - \\sum_{t=1}^{T}\\hat{e}_{t}^{2}) - \\bar{p}\\sum_{t=1}^{T}\\hat{e}_{t}^{2}}{(T - 2k)(\\sum_{t=1}^{T}\\tilde{e}_{t}^{2} - \\sum_{t=1}^{T}\\hat{e}_{t}^{2})}\n    \\end{equation*}\nif $(T - 2k)(\\sum_{t=1}^{T}\\tilde{e}_{t}^{2} - \\sum_{t=1}^{T}\\hat{e}_{t}^{2})(\\sum_{t=1}^{T}\\hat{e}_{t}^{2})^{-1} \\geq \\bar{p}$ while $\\hat{w} = 0$ otherwise.\n\\end{proof}\n=======\n\\begin{proof}[Proof of Lemma~\\ref{thm:2}]\nWe relax the conditional homoscedasticity assumption in Hansen's Mallow's model averaging method when there is a possible structural break in the underlying DGP. The proof is adapted from Hansen \\cite{hansen2009averaging} and Andrews \\cite{andrews93} without assuming conditional homoscedasticity. The CV penalty term can be expanded as:\n\\begin{eqnarray*}\ne'P(k)e & = & e'Pe + e'P^{*}(k)e \\\\\n        & = & e'Pe + e'X^{*}(k)(X^{*}(k)'X^{*}(k))^{-1}X^{*}(k)'e\n\\end{eqnarray*}\nwhere the notations for $P$,$P^{*}(k)$ and $X^{*}(k)$ are the same as in Hansen \\cite{hansen2009averaging}.\n\nFor the second term, $e'X^{*}(k)(X^{*}(k)'X^{*}(k))^{-1}X^{*}(k)'e$, we can see\n\\begin{eqnarray*}\nX^{*}(k)'X^{*}(k) & = & (X(k)-X(X'X)^{-1}X(k)'X(k))'(X(k)-X(X'X)^{-1}X(k)'X(k)) \\\\\n                  & = & X(k)'X(k) - X(k)'X(X'X)^{-1}X(k)'X(k) \\\\\n\t\t\t\t  &   & - X(k)'X(k)(X'X)^{-1}X'X(k) + X(k)'X(k)(X'X)^{-1}X(k)'X(k) \\\\\n\t\t\t\t  & \\stackrel{P}{\\rightarrow} & \\pi Q - \\pi QQ^{-1} \\pi Q - \\pi QQ^{-1} \\pi Q + \\pi QQ^{-1} \\pi Q \\\\\n\t\t\t\t  & = & \\pi (1-\\pi)Q\n\\end{eqnarray*}\n\nBy continuous mapping theorem we have $(X^{*}(k)'X^{*}(k))^{-1}\\stackrel{P}{\\rightarrow}(\\pi (1-\\pi))^{-1}Q^{-1}$.\n>>>>>>> 2966618e04912eba46807909c13546d2481a77e9\n\n\\begin{proof}[Proof of Proposition~\\ref{thm:2}]\nThe proof of this proposition is adapted from Hansen \\cite{hansen2009averaging}. By projection arguments, $P(m) = P + P^{*}(m)$, where $P = X(X'X)^{-1}X'$, $P^{*}(m) = X^{*}(m)(X^{*}(m)'X^{*}(m))^{-1}X^{*}(m)'$, $X^{*}(m) = X(m) - PX(m) = X(m) - X(X'X)^{-1}X'X(m) = X(m) - X(X'X)^{-1}X(m)'X(m)$, and $X(m)$ is the matrix of stacked regressors $x_{t}(t < m)$, the cross-validation penalty term can be expanded as:\n    \\begin{eqnarray*}\n    e'P(m)e & = & e'Pe + e'P^{*}(m)e \\\\\n            & = & e'Pe + e'X^{*}(m)(X^{*}(m)'X^{*}(m))^{-1}X^{*}(m)'e\n    \\end{eqnarray*}\n\n\\noindent We start by showing the asymptotic distribution of the second term on the right-hand-side of the above equation, $e'P^{*}(m)e = e'X^{*}(m)(X^{*}(m)'X^{*}(m))^{-1}X^{*}(m)'e$. For the meat part, $X^{*}(m)'X^{*}(m)$, we have\n    \\begin{eqnarray*}\n    X^{*}(m)'X^{*}(m) & = & (X(m)-X(X'X)^{-1}X(m)'X(m))'(X(m)-X(X'X)^{-1}X(m)'X(m)) \\\\\n                      & = & X(m)'X(m) - X(m)'X(X'X)^{-1}X(m)'X(m) \\\\\n    \t\t\t\t  &   & \\quad - X(m)'X(m)(X'X)^{-1}X'X(m) \\\\\n                      &   & \\quad + X(m)'X(m)(X'X)^{-1}X(m)'X(m) \\\\\n    \t\t\t\t  & = & X(m)'X(m) - X(m)'X(X'X)^{-1}X(m)'X(m)\n    \\end{eqnarray*}\n\\noindent From our assumptions and $\\frac{m}{T} \\rightarrow \\pi$, by laws of large numbers, we have\n    \\begin{equation*}\n        \\frac{1}{T} X(m)'X(m) \\stackrel{P}{\\rightarrow} \\pi Q\n    \\end{equation*}\nand\n    \\begin{equation*}\n        \\frac{1}{T} X(m)'X(X'X)^{-1}X(m)'X(m) \\stackrel{P}{\\rightarrow} \\pi QQ^{-1} \\pi Q\n    \\end{equation*}\nso \n    \\begin{equation*}\n        \\frac{1}{T} X^{*}(m)'X^{*}(m) \\stackrel{P}{\\rightarrow} \\pi (1-\\pi)Q\n    \\end{equation*}\n\n\\noindent By continuous mapping theorem we have \n    \\begin{equation*}\n        (\\frac{1}{T} X^{*}(m)'X^{*}(m))^{-1}\\stackrel{P}{\\rightarrow}(\\pi (1-\\pi))^{-1}Q^{-1}\n    \\end{equation*}\n\\noindent For the bread part, $X^{*}(m)'e = X(m) - X(X'X)^{-1}X(m)'X(m))'e$, we can show \n    \\begin{eqnarray*}\n         X(m) - X(X'X)^{-1}X(m)'X(m))'e & = & X(m)'e - X(m)'X(m)(X'X)^{-1}X'e \\\\\n                                        & = & \\jia x_t e_t - \\jia x_t x_t' \\left( \\jian x_t x_t' \\right) ^{-1} \\left( \\jian x_t e_t \\right)\n    \\end{eqnarray*}\n\n\\noindent Next, applying laws of large numbers and the mixing functional central limit theorem, we have\n    \\begin{equation*}\n        \\frac{1}{\\sqrt{T}} \\jia x_t e_t \\Rightarrow W(\\pi)\n    \\end{equation*}\n        \n    \\begin{equation*}\n        \\frac{1}{T} \\jia x_t x_t' \\stackrel{P}{\\rightarrow} \\pi Q\n    \\end{equation*}\n    \n    \\begin{equation*}\n        \\left( \\frac{1}{T} \\jian x_t x_t' \\right) ^{-1} \\stackrel{P}{\\rightarrow} Q\n    \\end{equation*}\n    \n    \\begin{equation*}\n        \\frac{1}{\\sqrt{T}} \\jian x_t e_t \\Rightarrow W(1)\n    \\end{equation*}\nwhere $W(1)$ is the Brownian motion vector with covariance matrix $\\Sigma \\equiv \\lim\\limits_{n\\to\\infty}$VAR$(\\rn\\jian X_i e_i)$, and $W(\\pi)$ is the Brownian vector at time $\\pi$.\n\n<<<<<<< HEAD\n\\noindent Putting together results obtained above, we have\n    \\begin{equation*}\n        \\frac{1}{\\sqrt{T}} X^{*}(m)'e \\Rightarrow W(\\pi) - \\pi W(1)\n    \\end{equation*}\n=======\n\\begin{eqnarray*}\ne'P^{*}(k)e & = & e'X^{*}(k)(X^{*}(k)'X^{*}(k))^{-1}X^{*}(k)'e \\\\\n            & \\stackrel{P}{\\rightarrow} & \\frac{1}{\\pi(1-\\pi)} (W(\\pi) - \\pi W(1))'Q^{-1}(W(\\pi) - \\pi W(1)) =  \\frac{\\mathbf{B}(\\pi)'\\mathbf{B}(\\pi)}{\\pi(1-\\pi)}\\equiv J_0(\\xi_{\\delta})\n\\end{eqnarray*}\nwhere $\\mathbf{B}(\\pi)$ is a Brownian bridge. Combined with Hansen's \\cite{hansen2009averaging} theorem 1 without assuming conditional homoscedasticity or Andrews' \\cite{andrews93} theorem 4, our results follow.\n>>>>>>> 2966618e04912eba46807909c13546d2481a77e9\n\n\\noindent Then we have\n    \\begin{equation*}\n        \\frac{1}{T} e'P^{*}(m)e \\Rightarrow \\frac{1}{\\pi(1-\\pi)} (W(\\pi) - \\pi W(1))'Q^{-1}(W(\\pi) - \\pi W(1)) =  \\frac{\\mathbf{B}(\\pi)'\\mathbf{B}(\\pi)}{\\pi(1-\\pi)}\n    \\end{equation*}\nwhere $\\mathbf{B}(\\pi)$ is a Brownian bridge. Combined with Hansen's \\cite{hansen2009averaging} theorem 1 without assuming conditional homoscedasticity or Andrews' \\cite{andrews93} theorem 4, we have $\\frac{1}{T} e'P^{*}(m)e \\Rightarrow J_0(\\xi_{\\delta})$.\n\n\\noindent For the first component in the penalty term, $e'Pe$, we have\n    \\begin{equation*}\n      e'Pe = (\\frac{1}{\\sqrt{T}} \\jian x_t e_t)'(\\frac{1}{T} \\jian x_t x_t')^{-1}(\\frac{1}{\\sqrt{T}} \\jian x_t e_t)\n    \\end{equation*}\n\\noindent Again, applying relevant laws of large numbers and central limit theorem, \n    \\begin{equation*}\n      \\frac{1}{\\sqrt{T}} \\jian x_t e_t \\Rightarrow W(1)\n    \\end{equation*}\n\n<<<<<<< HEAD\n    \\begin{equation*}\n      \\frac{1}{T} \\jian x_t x_t' \\stackrel{p}{\\rightarrow} Q\n    \\end{equation*}\nso\n    \\begin{equation*}\n      e'Pe \\stackrel{p}{\\rightarrow} \\Xi' Q^{-1} \\Xi\n    \\end{equation*}\nwhere $\\Xi \\sim N(0, \\Sigma)$ .\n=======\nUnder the assumption of conditional homoscedasticity, the above distribution is a $\\chi^2$ distribution times the variance of the population error. If we relax the assumption of conditional homoscedasticity, $e'Pe$ does not converge to a $\\chi^2$ distribution, instead, it converges to a weighted sum of $\\chi^2$ distribution of one degree of freedom.\n>>>>>>> 2966618e04912eba46807909c13546d2481a77e9\n\n\\noindent $\\Sigma$ is symmetric and positive definite, $Q^{-1}$ is of the same rank of $\\Sigma$, applying results of the distribution of quadratic forms (see section 5.4 of Ravishanker and Dipak \\cite{linear_model_textbook}), we have\n    \\begin{equation*}\n      e'Pe \\stackrel{d}{\\rightarrow} \\sum_{j=1}^{k} \\lambda_j \\chi^2(1)\n    \\end{equation*}\nwhere $\\lambda_j$s are the eigenvalues of the matrix $Q^{-1}\\Sigma$, $\\chi^2(1)$ is a random variable having the $\\chi^2$ distribution with degree of freedom one. \n\n<<<<<<< HEAD\n\\noindent Collecting all results shown above, we have\n    \\begin{equation*}\n      e'P(\\hat{m})e \\stackrel{d}{\\rightarrow} \\sum_{j=1}^{k} \\lambda_j \\chi^2(1) + J_0(\\xi_{\\delta})\n    \\end{equation*}\n\\end{proof}\n\n\\begin{proof}[Proof of Corollary~\\ref{corollary:2}]\nFrom proposition~\\ref{thm:2}, take expectation of the CV penalty term,\n    \\begin{equation*}\n      E(e'P(\\hat{m})e) = E(\\sum_{j=1}^{k} \\lambda_j \\chi^2(1)) + E(J_0(\\xi_{\\delta}))\n    \\end{equation*}\nwe have $E(\\sum_{j=1}^{k} \\lambda_j \\chi^2(1)) = \\sum_{j=1}^{k} \\lambda_j$, applying Hansen's technique, approximate the value of $E(J_0(\\xi_{\\delta}))$ by averaging two extreme cases, so $E(J_0(\\xi_{\\delta})) \\approx \\frac{1}{2}(\\mathrm{tr}(\\hat{Q}^{-1}\\hat{\\Sigma}) + 2\\bar{p} - k) \\equiv \\bar{p}^{*}$. Then by the same procedure in the proof of corollary~\\ref{corollary:2},\n    \\begin{equation*}\n      \\mathrm{CV}(w) = (w\\hat{e} + (1-w)\\tilde{e})'(w\\hat{e} + (1-w)\\tilde{e}) + 2(\\mathrm{tr}(\\hat{Q}^{-1}\\hat{\\Sigma}) + w \\bar{p}^{*})\n    \\end{equation*}\n\\noindent The CV weight is the value in $[0, 1]$ that minimizes $\\mathrm{CV}(w)$, so\n    \\begin{equation*}\n      \\hat{w} = 1 - \\frac{\\mathrm{tr}\\left(\\hat{Q}^{-1}\\hat{\\Sigma}\\right) + 2\\bar{p} - k}{2\\left(\\sum_{t=1}^{T}\\tilde{e}_t^2 - \\sum_{t=1}^{T}\\hat{e}_t^2\\right)}\n    \\end{equation*}\nif $(\\sum_{t=1}^{T}\\tilde{e}_{t}^{2} - \\sum_{t=1}^{T}\\hat{e}_{t}^{2}) \\geq \\bar{p}^{*}$ while $\\hat{w} = 0$ otherwise.\n=======\n\\begin{eqnarray*}\ne'Pe & \\stackrel{d}{\\rightarrow} & \\sum_{j=1}^{k} \\lambda_j \\chi^2(1)\n\\end{eqnarray*}\nwhere $\\lambda_j$s are the eigenvalues of the matrix $L'Q^{-1}L$, $\\Sigma = LL'$. Although the asymptotic distribution is not pivotal, since we are only interested in the first moment of this distribution, we can easily obtain its value by $\\mathrm{E}(e'Pe) = \\sum_{j=1}^{k} \\lambda_j = \\tr{(L'Q^{-1}L)} = \\tr{(Q^{-1} \\Sigma)}$, where $Q$ and $\\Sigma$ can be estimated by their sample analogues. This can be done without relying on potentially time-consuming Monte Carlo simulation.\n\\end{proof}\n\\begin{proof}[Proof of Theorem~\\ref{lem:2}]\nThe proof of this theorem follows Hansen\\cite{hansen2009averaging}, just replace all relevant terms according to Theorem~\\ref{thm:2}.\n>>>>>>> 2966618e04912eba46807909c13546d2481a77e9\n\\end{proof}\n", "meta": {"hexsha": "42edf76b77b6c92a831f6be4c196bd769de23d7b", "size": 11682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/allproof.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/allproof.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/allproof.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": 63.1459459459, "max_line_length": 482, "alphanum_fraction": 0.593990755, "num_tokens": 4558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681086260461, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6736126518059188}}
{"text": "\\chapter*{Symbols}\n\\label{symbols}\n\\addToTOC{symbols}\n\n\n\n\\section*{Notation}\n\n\\begin{deflist}\n\\notation{y}{Scalars are denoted in lowercase italic.}\n\\notation{\\z}{Vectors are denoted in lowercase boldface.}\n\\notation{\\A}{Matrices are denoted in uppercase boldface.}\n\\notation{\\ev{\\cdot}}{Time-average of a signal.}\n\\notation{\\abs{\\cdot}}{Number of elements in a set; Magnitude.}\n\\notation{\\had}{Elementwise multiplication. (``Hadamard product'').}\n\\notation{\\sigmoid(\\cdot)}{Sigmoid `squashing' function, $\\reals \\rightarrow (0, 1)$. $ \\ \\sigmoid(x) = \\frac{1}{1 + \\exp(-x)}$.}\n\\notation{\\tanh(\\cdot)}{Hyperbolic tangent, $\\reals \\rightarrow (-1, 1)$. $ \\ \\tanh(x) = 2\\, \\sigmoid(x) - 1$.}\n\\end{deflist}\n\n\n\n\\section*{Signals}\n\\label{sec:signals}\n\n\\begin{deflist}\n\\notation{\\z_t}{Digitized LFP sample at discrete time step $t$. $\\z_t \\in \\reals^C$, with $C$ the number of channels (i.e. the number of electrodes simultaneously recorded from). Input to an SWR detection algorithm.}\n\\notation{o_t}{Output signal of an SWR detection algorithm, $\\in \\reals$.}\n\\notation{n_t}{`Envelope'. Transformation of $o_t$, so that it is constrained to $\\reals^+$. Should be high when the corresponding input sample $\\z_t$ is part of an SWR segment, and low when it is not. $\\ n_t = \\abs{o_t}$ for online linear filters; $n_t = \\sigmoid(o_t)$ for the RNN's of \\cref{ch:RNN}.}\n\\notation{y_t}{Binary target signal, used when training data-driven SWR detection algorithms. We define $y_t = 1$ when the corresponding input sample $\\z_t$ is part of an SWR segment, and $y_t = 0$ when it is not.}\n\\end{deflist}\n\n\n\n\\section*{Measures \\& parameters}\n\n\\begin{deflist}\n\\notation{T}{Detection threshold applied to the envelope $n_t\\,$. $T \\in [\\min{n_t},\\ \\max{n_t}]$. Each threshold $T$ yields a different $P$-value, $R$-value, $F_1$-value, etc.}\n\\notation{P}{Precision. Also known as positive predictive value. The fraction of correct detections, out of all detections.}\n\\notation{R}{Recall. Also known as sensitivity, hit rate, or true positive rate. The fraction of detected reference SWR segments, out of all reference SWR segments.}\n\\notation{F_\\beta}{F-score: weighted harmonic mean of recall and precision. $F_\\beta = \\frac{(1+\\beta^2) P R}{\\beta^2 P + R}$. Measures detection performance ``for a user who attaches $\\beta$ times as much importance to recall as to precision.'' \\cite{Rijsbergen1979}}\n\\notation{F_1}{F-score where recall and precision are weighted equally.}\n\\notation{f_s}{Sampling frequency of a signal.}\n\\end{deflist}\n", "meta": {"hexsha": "e79d9766227c39202bb60cdccf25ffcfbe275314", "size": 2515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Frontmatter/Symbols.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/Frontmatter/Symbols.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/Frontmatter/Symbols.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": 57.1590909091, "max_line_length": 303, "alphanum_fraction": 0.7220675944, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.6735859157919735}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{graphicx}\n\\graphicspath{ {/} }\n \n\n\\makeatletter\n\\def\\l@section{\\@dottedtocline{1}{0em}{3em}}\n\\makeatother\n\n\\begin{document}\n\n\\title{An Introduction to Cost Estimation of Relational Query Plans}\n\\author{Yannis Velegrakis}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Page}\n\nEvery time a hard drive is instructed to read or write something on the disk it does so by reading or writing units of specific size. This size is called a PAGE and has always a fixed size for every system. For example, if the page size is 1024 bytes and the database wants to read 3 bytes from the disk, the disk will read and return to the database 1024 bytes of which the database will throw away the 1021 and keep only the needed 3.\nThe size of a page on the disk will be denoted as $P$.\n\n\\section{Size of a Record}\n\nWe assume that the records of a relation have more or less the same size. The size of a record indicating how much space (in bytes) a record occupies when stored on the disk. The size of a record will be typically given, or if not, it would be possible to compute from the size of the individual attributes. For example, if a relation has five attributes, three of them being integers and two being VARCHAR(25), then the size of a record for this relation is 3*4+2*25=62 bytes. The size of a record of a relation R will be denoted as $t_R$.\n\n\\section{Pages of Relations}\n\nThe data of every relation are stored on the disk. When a page contains some data of a relation, no records from other relations are allowed in that page. What the databases try to do is to try to fill a page with as many records of the same relation as they can, and if no more records can fit, then they start with another page. This means that we can safely assume that all the pages that a relation occupies on the disk are full.\nThe number of pages that a relation R occupies on the disk will be denoted as $P_R$.\n\n\\section{Cardinality of a Relation}\n\nA relation is a set of records. The number of records a relation has is the cardinality of the relation. The cardinality of a relation R will be denoted as $|R|$.\n\n\\section{Cardinality of an Attribute}\n\nThe cardinality of an attribute in a relation is the number of different distinct values that the attribute has. If the attribute is a key, clearly the cardinality of the attribute is the same as the cardinality of the relation, i.e., the number of records of the relation (since a value cannot be repeated). \\\\\nThe cardinality of two or more attributes is similarly the number of different distinct combinations of values of these attributes across the records.\nThe cardinality of an attribute A of a relation R, will be denoted as $|R.A|$, and the cardinality of two or more attributes as $|R.A_1, R.A_2, ..., R.A_n|$. So, if the attribute A is a key, then $|R| = |R.A|$, otherwise $|R.A| \\le |R|$.\n\n\\section{Records per Page}\nThe database does not store in the same page records from different relations. Furthermore, the database does not store a record across different pages. For instance, if a page size is 100 bytes and a record has a size of 30 bytes, then only 3 records will fit in a page (taking space 3*30=90 bytes), and the remaining 10 bytes from the 100 will be left empty. This means that\n\n$$\n\\text{\\#Records of R per Page} = \\Big\\lfloor\\frac{\\text{Page Size}}{\\text{Tuple Size of R}}\\Big\\rfloor = \\Big\\lfloor\\frac{P}{t_R}\\Big\\rfloor\n$$\n\nThe symbol $\\lfloor \\rfloor$ means that we round down to the closest integer. So if the division gives 4.3, then the number of records per page will be 4.\n\n\\section{Relation Size}\n\nThe size of a relation is the space it occupies on the disk. Since there are spaces left in pages, that size is often more than the actual size of its records. So, the size of R in bytes is:\n\n$$\n\\text{Size of R} = \\text{\\#Pages of R} * \\text{PageSize} = \\Big\\lfloor\\frac{\\text{\\#Tuples of R}}{\\text{\\#Tuples of R per page}}\\Big\\rfloor P \\\\\n= \\Big\\lfloor\\frac{ |R| }{\\lfloor\\frac{P}{t_R}\\rfloor}\\Big\\rfloor P\n$$\n\nThe symbol $\\lceil \\rceil$\tmeans that we round up to the closest integer. So, if the internal part is 4.3, then the $\\lceil \\rceil$ will be 5.\nFrom the above mathematical equation, it becomes clear that:\n\n$$\n|R| = P_R * \\#\\text{of records of R in a page} = P_R * \\Big\\lfloor\\frac{P}{t_R}\\Big\\rfloor\n$$\n\n\\section{Cost}\n\nOperations that involve reading from the disk or writing to the disk are called I/O. Operations that are done only in memory are called in-memory. The cost of an in-memory operations is so much smaller than that of an I/O that it is the number of needed I/O operators that are actually determining the cost (time) that a query will take to be executed. For this reason, we will consider the cost of any inmemory operation to be 0 (zero) and we will measure the cost of the execution of a query in terms of number of I/O operations. By definition we will assume that the cost of reading or writing a page on the disk is equal to 1.\n\n\\section{Scan}\n\nA scan operation is a sequential read of a relation. The cost is the cost of reading all the pages that the relation occupies. Thus,\n\n$$\n\\text{Cost of Scan} = \\#\\text{Pages of the relation}\n$$\n\nFor the database to find and read a record in a relation normally it needs to do a scan since the record can be in any of the pages that the relation occupies, and in the absence of any auxiliary structure (for instance the indexes we will see later) or any special organization of the data (for instance if the data is sorted), then the scan is the only option.\n\n\\section{Sorting}\nIf we need to sort a relation based on the value of a specific attribute, there are two main algorithms that this can be done. One of these algorithms assumes that the database has only 3 buffers in its memory. If N is the number of pages occupied by the relation that needs to be sorted, the cost of the sorting (in terms of required I/O operations) is:\n\n$$\n2N(\\lceil \\log_2(N)\\rceil + 1)\n$$\n\n\nTypically, a database has more than 3 memory buffers available for sorting, so an optimized algorithm can be used. If there are B available buffers (with B>3), then the cost of sorting a relation that occupies N pages (in terms of required I/O operations) is:\n\n$$\n2N(\\lceil \\log_{B - 1}(\\lceil\\frac{N}{B}\\rceil)\\rceil + 1)\n$$\n\nThe details of the algorithms can be found in the course textbook, but for us it is enough to simply know these two algorithms and the cost that each one has.\n\n\\section{Indexes}\n\nAn index is an auxiliary structure that is built based on the values of a specific attribute of the database. It helps in identifying the location of the records (meaning the pages in which they reside) that have a value in that attribute that satisfies some specific condition. There are two kinds of Indexes that are of interest to us: The Hash and the B+-trees.\nA Hash index is an index that helps in finding fast records that satisfy conditions of the form A=value, where the A is the attribute on which the hash index has been constructed. For example, if we construct a hash index on the attribute “Age” of a table “Person”, then the index can help identify fast all these records that have Age=10.\nA B+-tree index is an index that helps finding fast records that satisfy either equality conditions like those that also the Hash index can answer, but also can help with range conditions. Range conditions are conditions that require the value of an attribute to be between two values, or greater than a value, or less that a value. Some examples of range conditions are: $A > 5, A \\ge 10$, or even $A \\le 67 AND A \\ge 150$.\nThe advantage of a Hash index is that it is much faster than the B+-tree but cannot answer range queries. The advantage of B+-tree is that it can answer range queries but for the equality conditions it is slower than the Hash.\n\n\\section{Composite Index}\n\nIt is possible to create an index that depends on more than one attribute. These are called composite indexes. In the case of B+trees, the order in which the attributes have been defined plays a role. The idea of the composite index in B+-trees is that the data is indexed first based on the first field, then on the second, then in the third, etc. This means that a B+-tree can be used when we are searching not only for all the attributes of the composite index, but also when searching only for those at the beginning. However, if we are searching for those at the end, the B+-tree cannot be used. For example, a composite index on (firstName, LastName) means that the records are indexed first on he first name, and then among all those with the same first name, they are indexed on the last name. This means that the B+-tree can be used when searching for someone with a specific first and last name. The same index can also be used for searching for someone with a specific first name. However, it cannot be used to search for someone with a specific last name (without knowing the first name).\n\n\\section{Updating Index}\n\nEvery time the data of a relation are updated (the records are modified, new records are inserted or existing records get deleted), the index needs to be updated as well. This of course affects the time of the query execution, which is why it is not a good idea to put too many indexes, but only on those that are really needed. Nevertheless, for our goal here we will ignore the time needed to update the index.\n\n\\section{Index Lookup}\n\nThe operation of using the index to identify where the records that satisfy some condition are located is called the index lookup. The output of an index lookup operation is a set of pointers that indicate the pages that contain these records.\nIndexes are also taking space and since the database tables may be really big, unavoidably the indexes may become also big, to a point that it is not possible to keep them in memory so they are stored on the disk. This means that in order to perform an index lookup, we may need to do a number of disk accesses. Fortunately, the indexes are much smaller than the actual tables, so the index lookups are not very expensive.\n\nIn particular, we can safely consider the generic case in which a Hash index lookup costs 1.2 I/O (meaning that in average 1.2 page reads are needed) and a B+-tree lookup costs  $\\log_s | R.A |$ I/O (meaning $\\log_s | R.A |$ page reads needed) where the A is the attribute on which the index has been defined. If the |R.A| is not known, then the value 3 can be considered for a B+tree lookup that is a typical value. The base s of the log depends on how the B+-tree has been implemented. It is the (maximum) number of children that a node of the B+-tree can have. If every node of the B+-tree can have at most 2 children, then the $s=2$.\n\nThe look-up cost will be denoted as $L$ ($L_h$ if a hash, $L_t$ if a B+tree).\n\n\\section{The Selectivity Factor}\n\nOne question that is usually important to know is how many records are expected to be retrieved given a condition. (They are called the qualifying records). Given a condition c and a relation R, we will denote by Rc the records of R that satisfy the condition c. For instance, Rname=”John” is the set of records of R that have the value “John” in the attribute “name”. The database knows these numbers by keeping some statistics, in structures like histograms. If the histograms are not available, then some probability theory can help. We can assume that the values have an equal distribution. So, if we have a relation R with an attribute A, then the expected number of qualifying records, i.e., records that satisfy the condition A=x where x is some constant value, is\n$$\n|R_{A = c}| = \\frac { |R| }{ |R.A| }\n$$\nSometimes we have something that is called the “selectivity factor”. The selectivity factor is the percentage of the total number of records expected to be retrieved for a specific condition. For instance, with a selectivity factor f for the attribute A, the expected number of records that satisfy the condition A=x, is $f|R|$.\nNote that for multiple conditions the selectivity factors are multiplied. For example, if the attribute A has selectivity factor f, and the attribute B has selectivity factor g, the expected number of records that satisfy the condition $A=x AND B=y$ is $fg|R|$.\n\n\\section{Clustered/Unclustered}\n\nAn index can be clustered or unclustered. Clustered means that all the records that are satisfying a specific condition are stored one next to the other. In the case of an unclustered index, the lookup returns one page-pointer for every qualifying record located on the disk. Instead in the case of a clustered index, a pointer is returned for those pages that contain the qualifying records, which is clearly much smaller than the number of qualifying records. Given the above, for a condition c on a relation R, the number of page pointers returned by the lookup in an clustered index is\n\n$$\n\\text{\\# pages occupied by these tuples} = \\frac{\\text{\\# tuples of R that satisfy}}{\\text{\\# tuples of R that fit in a page}} = \\frac{ |R_c| }{\\lfloor\\frac{P}{t_R}\\rfloor}\n$$\n\n\\section{Cost of Retrieving Qualifying Records}\nTo retrieve the qualifying records after an index lookup has the cost of reading each of the pages for which the lookup returned a pointer. For example, assume that we need to retrieve the records of a table R for which Age=5. If there is no index, the cost will be the cost of reading the whole relation that will be equal to the number of pages that the relation occupies. If there is an index on an attribute different than Age, it cannot be used so the cost would be the same (the number of pages of the whole relation). If there is an index on attribute A and is unclustered, the cost is the cost of the lookup, plus the cost of reading the records. Since the index is unclustered, the lookup will return one pointer for every qualifying record, and there is a need for one read for each such pointer. Thus, the total cost will be:\n\n$$\nL + |R_{age}=5|\n$$\n\nIf the index is instead clustered, then the cost will be:\n\n$$\nL + \\frac{ |R_{age}=5| }{\\lfloor\\frac{P}{t_R}\\rfloor}\n$$\n\n\\section{Cost of an update operator}\n\nThe cost of an update operator is the cost of the index lookup + the cost of reading the page + the cost of writing the page, meanings that the cost would be:\n\n$$\n\\text{Lookup} + \\text{\\#pages that contain the records to be changed} * (1 + 1)\n$$\n\n\\section{Joins}\n\nThe join is the most fundamental operator in queries and special attention has been paid to it. There are many different algorithms for efficiently and effectively implement the joins. Here we mention the most prevalent. Given two relations, one that is called R (occupying M pages and having K records) and the other called S (occupying N pages and having L records). Then\n\nSimple Nested Loops Join: It is the method that can always be done since it does not need any auxiliary structure. It simply reads the first relation and for each page of the first reads the whole second relation. Thus, if we do the $R\\bowtie S$ will have a cost $M + NM$, while $S \\bowtie R$ will have a cost $N + MN$ (which means that it is better if we start from the smaller relation.\nSort Merge Join: We first sort each relation and then we can simply perform the join through an one pass over each relation (having one pointer in each one that we advance). Thus, the cost is: $\\text{Cost to Sort R} + \\text{Cost to Sort S} + M + N$. The cost to sort a relation may be ignored if the relation is already sorted. If not, ref to the cost of sorting described previously.\nHash Join: Assuming that we have enough memory to store a hash structure, we can construct such a hash structure and then use it to perform the join. The algorithm has a cost $3(M+N)$\nIndex Nested Loops Join: This is used when there is an index that can be exploited. We read one relation and then for each record in that relation we use the index on the other to select the matching records (and only the matching records). Of course the index of the other relation has to exist and has to be on the join attribute. Otherwise the idea cannot be used. If the index exists, then the cost will be:\n\n\\begin{align*}\n\\text{Cost To Read R} + \\text{\\#RecordsInR} * \\text{Cost to Retrieve the Matching records in S} = \\\\\n = M + K * (\\text{Index Lookup Cost} + \\text{Cost of Retrieving Qualifying Records})\n\\end{align*}\n\nThe index Lookup and the Qualifying records retrieval cost have already been discussed above.\n\n\\section{Storing the results of a query}\nThe results of a query can be displayed on the screen of the user. This has no cost since every record that the query generates is simply shown on the screen and then thrown away. However, often there is a need to store the results back into the database, which means that we have to write the results on the disk. The cost of this operation is the number of pages that we need to write, which is the same at the number of pages that the records will occupy. So assume that we have created a relation (meaning a set of records). The cost of saving it on the disk is:\n\n$$\n\\text{\\# of Pages Needed for these Tuples} = \\Big\\lceil\\frac{\\text{\\# of Tuples}}{\\text{\\# of Tuples that fit in a page}}\\Big\\rceil = \\frac{\\text{\\#Tuples of R}}{\\lfloor\\frac{P}{t}\\rfloor}\n$$\n\nNote that some time during the execution of a query, a query may need to store some intermediate results on the disk because they may be big and cannot be kept into memory. The cost for doing so is 2 times the cost of the above formula: one for writing the results, and one for reading them afterwards.\nIt is important to note that when intermediate results are stored on the disk, clearly they have no index on them, which means that the only way to read them is to use a scan, which explains why the cost of reading is equal to the cost of writing them.\n\n\\section{Query Execution and Query Plans}\n\nWhen a query is given to the database for execution the database converts it into what is called a query plan. A query plan is a tree of relational algebra operations that implement the query. Clearly there may be many different query plans (meaning trees) for the same SQL query. Given a query plan we need to be able to compute the total cost, i.e., the cost of every operator (node) of the tree. For each node we need to be able to compute apart from the cost, the number of records that the operator generates (remember that every operator is generating always a relation, meaning a set of records).\nThe database has a special component called optimization, the role of which is to evaluate the queries that it received and identify the most effective execution plan to perform.\n\n\\section{On-the-fly Operations}\n\nCertain operators in the query plan can be done as the records arrive (meaning there is no need to wait for all the results to arrive first). So once a record is produced from the operators below, the operator above is executed. This means that the cost is 0 since it is done in memory. These are called on-the-fly operators. For example, imagine the projection on attributes A and B. We do not need to wait for all the records but as a record is given, the A and B are kept and the rest is eliminated. The A and B values of the record can be provided to the operator above the projection.\nNote that if there is a need to do duplicate elimination, then unavoidably the operator has to wait for the whole set of records to be first received.\n\n\\section{Index-only Operations}\n\nAn operation, e.g., a select, a join, etc., that does not require access the actual records but only from the index can find what is needed, is called an index-only operation. For example, the query: \n\n$$\\text{select S.A from S, T where S.B=T.C}$$\n\nwith an index on T.C, is index-only because it only needs a lookup on the Index and not to actually read the records of T.\n\n\\begin{figure}[h]\n\\includegraphics[scale=0.5]{img1.jpg}\n\\centering\n\\caption{An Example of a Query Plan}\n\\end{figure}\n\n\\begin{figure}[h]\n\\includegraphics[scale=0.47]{img2.jpg}\n\\centering\n\\caption{Cost of operations that do not involve Joins}\n\\end{figure}\n\n\\end{document}\n", "meta": {"hexsha": "20dcd111ddbcfd5919e983295c6b74fa43771b0e", "size": 20120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "query-cost/query-cost.tex", "max_stars_repo_name": "mfranzil/unitn-db", "max_stars_repo_head_hexsha": "2aa68f2892947926205ba3c7cd671c6540ccdd55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "query-cost/query-cost.tex", "max_issues_repo_name": "mfranzil/unitn-db", "max_issues_repo_head_hexsha": "2aa68f2892947926205ba3c7cd671c6540ccdd55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "query-cost/query-cost.tex", "max_forks_repo_name": "mfranzil/unitn-db", "max_forks_repo_head_hexsha": "2aa68f2892947926205ba3c7cd671c6540ccdd55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T17:06:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T17:06:22.000Z", "avg_line_length": 91.4545454545, "max_line_length": 1100, "alphanum_fraction": 0.7654075547, "num_tokens": 4813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6735859128487627}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Classical probability}\\label{sec:classical}\n\nWe now return to the question of how we might reasonably assign probabilities to random events. Classical probability deals with finite sample spaces in which all outcomes are equally likely. This means that the probability of an event $A$ is proportional to the number of outcomes it contains, which is called the \\emph{cardinality} of the set and denoted by $|A|$. The classical definition of probability can therefore be written as\n\\[\nP(A) = |A|/|\\Omega|.\n\\]\nProblems can be solved by counting the number of ways different events can occur. For example, if a game has $n$ possible outcomes of which $m$ correspond to winning, then the probability of winning is $m/n$.\n\n\\begin{example}\nAn urn contains $3$ white balls and $5$ black balls. If two balls are drawn at random from the urn, what is the probability that they are both white?\n\\begin{solution}\n\\bit\n\\it The sample space $\\Omega$ is the set of all possible pairs:\n$|\\Omega|\t= \\binom{8}{2} = \\frac{8!}{6!2!} = 28$. \n\\it Let $A$ be the event that both balls are white: \n$|A|  = \\binom{3}{2} = \\frac{3!}{1!2!} = 3$.\n\\eit\nThe probability that both balls are white is $P(A) = |A|/|\\Omega| = 3/28$.\n\\end{solution}\n\\end{example}\n\n\\begin{exercise}[The Division Paradox]\nA \\emph{fair game} is one in which the probability of winning is equal to the probability of losing. Two players $A$ and $B$ decide to play a sequence of fair games until one of the players wins 6 games, but they stop when the score is 5:3 in favour of player $A$. How should the prize money be fairly divided?\n\\begin{answer}\nAssume that the players carried on playing the sequence of games. The maximum number of additional games is 3, and the sample space can be expressed as\n\\[\n\\{AAA,AAB,ABA,BAA,ABB,BAB,BBA,BBB\\}.\n\\]\nThe games are fair, so all outcomes are equally likely.\n\\bit\n\\it Only one outcome is in favour of player $B$, the other seven are in favour of $A$.\n\\it The prize money should therefore be divided in the ratio $7:1$ in favour of $A$.\n\\eit\n\\end{answer}\n\\end{exercise}\n\n%The classical method can only be applied to problems which can be broken down into outcomes that are equally likely, which is not always possible. \n\n%-------------------------------------------------\n\\section{Relative frequency}\\label{sec:frequentist}\n\nClassical probability exploits the symmetry that exists in many random experiments, for example those involving dice, coins and cards, to choose sensible values for the probabilities of different events. How might we define probability in more general situations? If a random experiment can be repeated many times under the same conditions it is natural to think of probability as the number of times an event occurs as a proportion of the total number times that the experiment is repeated.\n\n\\begin{definition}\\label{def:relative_frequency}\nLet $N$ be the number of times an experiment is repeated and let $N(A)$ be the number of times event $A$ occurs during these $N$ repetitions. The ratio $N(A)/N$ is called the \\emph{relative frequency} of $A$. \n\\end{definition}\n\n\\begin{definition}\\label{def:frequentist_probability}\nUnder the \\emph{frequentist model}, the probability of $A$ is the limit of its relative frequency as the number of trials increases to infinity:\n\\[\n\\prob(A) = \\lim_{N\\to\\infty} \\frac{N(A)}{N}.\n\\]\n\\end{definition}\n\n\\begin{exercise}\nLet $\\Omega$ be a finite sample space. Show that probability as defined by the frequentist model has the following properties:\n\\ben\n\\it $P(\\emptyset)=0$ and $P(\\Omega)=1$.\n\\it Complementarity: if $A\\subseteq B$ then $P(A^c) = 1 - P(A)$.\n\\it Monotonicity: $P(A)\\leq P(B)$.\n\\it Additivity: If $A$ and $B$ are disjoint, $P(A\\cup B) = P(A) + P(B)$.\n\\een\nShow also that the conditional probability of $A$ given $B$ is $P(A\\cap B)/P(B)$ whenever $P(B)>0$.\n\n\\begin{answer}\n\\ben\n\\it \n$N(\\emptyset)=0$ and $N(\\Omega)=N$ for any number of repetitions $N$, so $P(\\emptyset)=0$ and $P(\\Omega)=1$.\n\\it \n$A^c$ occurs if and only if $A$ does not, so $N(A^c) = N - N(A)$ and thus\n\\[\nP(A^c) \n\t= \\lim_{N\\to\\infty}\\frac{N(A^c)}{N}\n\t= \\lim_{N\\to\\infty}\\frac{N - N(A)}{N}\n\t= 1 - \\lim_{N\\to\\infty}\\frac{N(A)}{N}\n\t= 1 - P(A^c).\n\\]\n\\it\nIf $A\\subseteq B$ then $A$ occurs whenever $B$ occurs, so $N(A)\\leq N(B)$ and hence\n\\[\nP(A)\n\t= \\lim_{N\\to\\infty}\\frac{N(A)}{N}\n\t\\leq \\lim_{N\\to\\infty}\\frac{N(B)}{N}\n\t= P(B).\n\\]\n\\it\nIf $A$ and $B$ are disjoint, they cannot both occur together, so $N(A\\cup B)=N(A)+N(B)$ and thus\n\\[\nP(A\\cup B)\n\t= \\lim_{N\\to\\infty}\\frac{N(A\\cup B)}{N}\n\t= \\lim_{N\\to\\infty}\\frac{N(A)+N(B)}{N}\n\t= \\lim_{N\\to\\infty}\\frac{N(B)}{N} + \\lim_{N\\to\\infty}\\frac{N(B)}{N}\n\t= P(A) + P(B).\n\\]\n\\een\nLet $P(A|B)$ denote the conditional probability of $A$ given $B$. This is the number of trials in which $A$ and $B$ both occur expressed as a proportion of the number of trials in which $B$ occurs. If $N(A,B)$ is the number of times $A$ and $B$ both occur then\n\\[\n\\prob(A|B)\t= \\lim_{N\\to\\infty}\\frac{N(A,B)}{N(B)} \n\t\t= \\lim_{N\\to\\infty}\\frac{N(A,B)/N}{N(B)/N} \n\t\t= \\frac{\\prob(A\\cap B)}{\\prob(B)}.\n\\]\nas required.\n\\end{answer}\n\\end{exercise}\n\nThe frequentist model is the basis of how probability theory is applied to real-world problems, and dominates in many areas of science (e.g.\\ medical trials). It does however have some serious practical and philosophical drawbacks.\n\n\\bit\n\\it \nNot all experiments can be repeated many times under the same conditions. For example, it is reasonable to consider the probability that Wales will win the World Cup in 2018. The frequentist model does not provide an adequate definition of such probabilities.\n\\it \nIn practical applications, an experiment is repeated finitely many times and the relative frequency of an event is taken as an approximation of its ``true'' probability. If we accept that we can only measure probability with some error of measurement, we find that an error of measurement can itself only be expressed as a probability, which is the very concept we are trying to define. \n\\it\nThe frequentist model is also limited when dealing with infinite sample spaces. For example, consider a random experiment where a coin is tossed repeatedly until the first head occurs, and whose the outcome is the total number of times the coin is tossed. The sample space is the countably infinite set $\\{1,2,3,\\ldots\\}$ but no matter how many times we repeat the experiment, there are outcomes which cannot be observed (e.g\\ if we repeat the experiment $N$ times, we cannot observe runs of length $N+1, N+2,\\ldots$).\n\\eit\n\nFrequentist probability is best regarded an informal theory which is useful in many practical applications, but which lacks the mathematical clarity offered by Kolmogorov's axiomatic theory.\n\n\n", "meta": {"hexsha": "974ee47276ef10ebe9ded726d686b7958f87e72f", "size": 6787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/01C_classical_and_frequentist.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/01C_classical_and_frequentist.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/01C_classical_and_frequentist.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": 55.1788617886, "max_line_length": 518, "alphanum_fraction": 0.7150434654, "num_tokens": 1941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.6735859092562626}}
{"text": "\\refstepcounter{dummy}\n\\pdfbookmark[1]{Notation}{notation}\n\\chapter*{Mathematical Notation}\n\\label{front:notation}\n\nThroughout this document, the following conventions regarding mathematical notation are being assumed, unless stated otherwise:\n\n\\paragraph{General}\n\\begin{items}\n\t\\item Vectorial quantities are marked with an arrow (\\(\\vec{u}\\)). \n\t\\item A dot \\(\\cdot\\) between vectors denotes a scalar product, and a cross \\(\\times\\) the vector product.\n\t\\item Unit vectors carry a caret (\\(\\hat{x}\\)).\n\\end{items}\n\n\\paragraph{Coordinate Systems}\n\\begin{items}\n\t\\item In%\n\t\t\\sidefigure*{}{\\resizebox{.9\\marginparwidth}{!}{\\input{figures/frontmatter/spherical.tex}}}[2]%\n\tCartesian coordinates, the directions are denoted as\n\t\\begin{equation} \n\t\\hat{x} = \\left( \\begin{matrix} 1 \\\\ 0 \\\\ 0 \\end{matrix} \\right), \\quad\n\t\\hat{y} = \\left( \\begin{matrix} 0 \\\\ 1 \\\\ 0 \\end{matrix} \\right), \\quad\n\t\\hat{z} = \\left( \\begin{matrix} 0 \\\\ 0 \\\\ 1 \\end{matrix} \\right).\n\t\\end{equation}\n\tFollowing the convention in Geophysics, \\(x\\) points in zonal direction, \\(y\\) in meridional direction, and \\(z\\) into the vertical direction (skyward). Components of the velocity \\(\\vec{u}\\) in \\(x\\), \\(y\\), and \\(z\\)-direction are denoted as \\(u\\), \\(v\\), and \\(w\\), respectively.\n\t\\item In spherical surface coordinates, the zonal coordinate is denoted as \\(\\phi\\) (longitude), and the meridional coordinate as \\(\\theta\\) (latitude).\n\\end{items}\n\n\\paragraph{Differentiation}\n\\begin{items}\n\t\\item The partial derivative of a quantity \\(h\\) is written as\n\t\\begin{equation} \\frac{\\partial h}{\\partial \\phi} \\equiv h_\\phi. \\end{equation}\n\t\\item It is often necessary to calculate the derivative of a quantity \\emph{along a streamline}. This \\emph{material derivative} is denoted as\n\t%\n\t\\begin{equation} \\Ddx q = \\shortunderbrace{q_t}_{\\mathclap{\\text{partial derivative}}} + \\overbrace{\\vec{u} \\cdot \\nabla q}^{\\mathclap{\\text{advection}}}. \\end{equation}\n\t%\n\t\\item The Nabla operator \\(\\nabla\\), as usual in vector calculus, is defined as\n\t\\begin{equation} \\nabla = \\begin{pmatrix} \\partial/(\\partial x) \\\\ \\partial/(\\partial y) \\\\ \\partial/(\\partial z) \\end{pmatrix}. \\end{equation}\n\t%\n\tHence, \\(\\nabla f\\) denotes the gradient of the scalar field \\(f\\), and \\(\\nabla \\cdot \\vec{u}\\) and \\(\\nabla \\times \\vec{u}\\) the divergence and curl of a vector field \\(\\vec{u}\\), respectively.\n\t\\item The horizontal equivalent of \\(\\nabla\\) is denoted as \\(\\nabla_H\\) and only operates on the \\(x\\) and \\(y\\)-directions of a vector field. The horizontal divergence and curl thus read\n\t\\begin{alignat}{3}\n\t\\divergence_H (\\vec{u}) &= \\nabla_H \\cdot \\vec{u} &&= u_x + v_y \\\\\n\t\\curl_H (\\vec{u}) &= \\nabla_H \\times \\vec{u} &&= v_x - u_y.\n\t\\end{alignat}\n\t\\item The Jacobian determinant\\sidenote{For the sake of brevity just refered to as \\enquote{Jacobian}.} \\(J(a,b)\\) of two scalar fields \\(a\\), \\(b\\) is defined as\n\t\\begin{equation} J(a,b) := a_x b_y - a_y b_x. \\end{equation}\n\\end{items}\n\n\\paragraph{Scale Analysis}\n\\begin{items}\n\t\\item The operator \\(\\orderof{x}\\) is used several times during scale analyses, and simply means \\enquote{order of} --- it maps a physical quantity \\(x\\) to a corresponding typical scale\\sidenote[-2]{These scales are chosen in a heuristic manner, providing motivations rather than formal derivations. While their exact value can be argued, their order of magnitude usually cannot, allowing the comparison of terms that vary by several orders of magnitude.}.\n\\end{items}\n\n\\paragraph{Other}\n\\begin{items}\n\t\\item The temporal mean value of a quantity \\(u\\) is denoted as \\(\\mean{u}\\).\n\\end{items}\n", "meta": {"hexsha": "7e6fae2fb6e7836eb5fd0f646d902217b2405714", "size": 3588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "msc-thesis/src/frontmatter/notation.tex", "max_stars_repo_name": "dionhaefner/dionsthesis", "max_stars_repo_head_hexsha": "cc06f14d54f21692ae87a1a4858979841cf531c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-01-31T00:26:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-25T09:32:03.000Z", "max_issues_repo_path": "msc-thesis/src/frontmatter/notation.tex", "max_issues_repo_name": "dionhaefner/dionsthesis", "max_issues_repo_head_hexsha": "cc06f14d54f21692ae87a1a4858979841cf531c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "msc-thesis/src/frontmatter/notation.tex", "max_forks_repo_name": "dionhaefner/dionsthesis", "max_forks_repo_head_hexsha": "cc06f14d54f21692ae87a1a4858979841cf531c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-09-29T18:31:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-29T16:00:45.000Z", "avg_line_length": 60.813559322, "max_line_length": 458, "alphanum_fraction": 0.7056856187, "num_tokens": 1101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764119, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.673585899205825}}
{"text": "\\section{Modified Mini Batch $k$-Means Algorithm}\n\\label{sec:TheoryKMeans}\nThe $k$-Means algorithm takes $k$ random points in space representing the center of $k$ classes. These class centers are then refined in two steps: First, each data point in a set of training data is classified to belong to one of the classes by selecting the closest class center. Second, the class centers are moved towards the geometric center of all the data points classified as belonging to the class. These steps are repeated until the class centers stop moving.\\\\\nHowever, this approach is impractical for large data sets, since every iteration needs to calculate distances from every data point to every class center. A modification of this algorithm called Mini-batch $k$-Means \\cite{bib:Elkan2003} uses only a random subset of all data points for each iteration. This results in slightly less accurate class centers, but much greater performance.\\\\\nIn our case though, there is no Euclidean feature space in which we could position class centers. The only measure available is the DTW-distance between the different samples. Thus, we modified the second step of the Mini-batch $k$-Means algorithm to choose the center-most sample instead of the arithmetic center. The center-most sample is defined as the one sample in the class that has the least distance from all other samples in the class.\\\\\nRunning this algorithm on our data set results in $k$ class centers. New samples can then be classified to belong to one of these centers by selecting the closest one.\\\\\nCalculating class centers requires the calculation of many distances between many samples. In order to speed up this process, we pre-calculated all the sample distances as described in chapter~\\ref{sec:Distance}.\n", "meta": {"hexsha": "52cceaad007d7be79c242014f0b36a8acfc16a0b", "size": 1765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TheoryKMeans.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/TheoryKMeans.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/TheoryKMeans.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": 220.625, "max_line_length": 471, "alphanum_fraction": 0.8033994334, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6735241142452778}}
{"text": "\\subsection{Woody Fibers Decomposition Model}\nFungi with the ability to decompose lignin or cellulose~\\cite{lignin}\\cite{cellulose} are distributed on an ideal cylindrical dead wood. Under certain environmental temperature and moisture conditions, the hyphae begin to expand and grow, and fungi secrete biologically active enzymes that can decompose the woody fibers. As time goes by, the outer layer of woody fibers decompose and fall off, and the fungi gradually approach the axis of the dead wood. Ignoring the surface area of cylinder bottoms, use the \\textit{cylinder side surface area formula}, and mark it as \\textit{Eq.~(\\ref{cylindersurfacearea})}\n\\begin{equation}\n  \\label{cylindersurfacearea}\n  S_{cylinder} = 2\\pi r\\cdot h\n\\end{equation}\nwhere $r$ represents the radius of dead wood, and $h$ represents the total length of dead wood. As the radius decreases, it comes to a conclusion that the surface area of cylinder also decreases.\n\\par\nBased on the conclusion, it is obvious that the number of fungi per unit area would increase. Meanwhile, fungal hyphae can generally grow to several times their initial size~\\cite{initialsize}. Therefore, even considering the loss of fungi because of wind and rain, the number of fungi would still increase significantly as their distribution gradually approaches the central axis.\n\\par\nCombining with the relevant knowledge of electromagnetic in physics~\\cite{physics}, we find that the distribution of fungi has many similarities with the \\textit{Gaussian surface} in the electric field. On the one hand, the distribution of fungi is cylindrical and could be represented by a cylindrical Gaussian surface. On the other hand, as the radius decreases, both the electric field strength and the number of fungi per unit area (also known as fungi decomposition rate) would increase. From \\textit{Gauss theorem}, the decomposition cylinder is shown in \\textit{Figure~1}, and  we can get \\textit{Eq.~(\\ref{secondeq})}, \\textit{Eq.~(\\ref{thirdeq})} and \\textit{Eq.~(\\ref{fourtheq})} as follows.\n\\begin{figure}[H]\n  \\centering\n  \\label{figure1}\n  \\subfigure[Electric field intensity $\\bm{E}$ and area differential $d\\bm{S}$.]{\n    \\includegraphics[width=0.45\\textwidth]{figures/plain.png}\n  }\n  \\subfigure[Ideal cylindrical wood.]{\n    \\includegraphics[width=0.45\\textwidth]{figures/cylinder.jpg}\n  }\n  \\caption{Decomposition cylinder.}\n\\end{figure}\n\\begin{equation}\n  \\label{secondeq}\n  \\oint_S \\bm{E} \\cdot d\\bm{S}=\\frac{1}{\\varepsilon}\\int_V \\rho d V\n\\end{equation}\n\\begin{equation}\n  \\label{thirdeq}\n  \\bm{E}=\\frac{\\lambda}{2\\pi \\varepsilon R}\n\\end{equation}\n\\begin{equation}\n  \\label{fourtheq}\n  \\Phi = \\oint_S \\bm{E}\\cdot d\\bm{S} = \\oint_S \\frac{\\lambda}{2\\pi\\varepsilon R}d S = \\frac{\\lambda}{2\\pi\\varepsilon R} 2\\pi R l = \\frac{\\lambda l}{\\varepsilon}\n\\end{equation}\nwhere $\\bm{E}$ represents electric field intensity on the surface of a uniformly charged cylinder, whose direction is radial, and $\\Phi$ represents electric flux. Convert the above electromagnetic equations and parameters into formulas for estimating the decomposition rate ($\\bm{DR}$) of fungi in \\textit{Eq.~(\\ref{fiftheq})}, \\textit{Eq.~(\\ref{sixtheq})} and \\textit{Eq.~(\\ref{seventheq})}\n\\begin{equation}\n  \\label{fiftheq}\n  \\oint_S DR\\cdot dS = \\frac{1}{\\varepsilon_{DR}}\\sum N_{inside} = \\frac{1}{\\varepsilon_{DR}} \\int_V \\rho dV\n\\end{equation}\n\\begin{equation}\n  \\label{sixtheq}\n  DR = \\frac{\\alpha}{2\\pi \\varepsilon_{DR} R}\n\\end{equation}\n\\begin{equation}\n  \\label{seventheq}\n  ACT=\\oint_S DR\\cdot dS = \\oint_S \\frac{\\alpha}{2\\pi \\varepsilon_{DR} R} dS = \\frac{\\alpha}{2\\pi \\varepsilon_{DR} R} 2\\pi R h = \\frac{\\alpha h}{\\varepsilon_{DR}}\n\\end{equation}\nwhere $\\alpha$ represents fungi linear density, $DR$ represents the decomposition rate, $\\varepsilon_{DR}$ represents environmental decomposition constant determined by surrounding meteorological indicators, and $ACT$ represents the \\textbf{fungal activity factor}, which is determined by the suitable living concentration of specific fungal types, moisture tolerance and the influence between different fungal species. According to \\textit{Eq.~(\\ref{sixtheq})}, as fungi gradually approach the central axis, the decomposition rate of fungi increases, which is consistent with the previous analysis.", "meta": {"hexsha": "77f2fb741e6c9c73217f1acd31fb6d0b86eb952f", "size": 4280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/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/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/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": 89.1666666667, "max_line_length": 701, "alphanum_fraction": 0.7623831776, "num_tokens": 1199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6735203358372229}}
{"text": "\\lab{Algorithms}{Conditioning and Stability}{Conditioning and Stability}\n\\objective{Explore the condition of problems and the stability of algorithms.}\n\\label{lab:conditioning_stability}\n\n\n\\begin{equation*}\n\\mathlarger{ \\mathlarger{ \\mathlarger{f:X \\rightarrow Y}}}\n\\end{equation*}\n\\begin{center} vs. \\end{center}\n\\begin{equation*}\n\\mathlarger{ \\mathlarger{ \\mathlarger{\\hat{f}:\\hat{X} \\rightarrow \\hat{Y}}}}\n\\end{equation*}\n\n%\\begin{eqnarray}\n%\\mathlarger{\\mathlarger{\\mathlarger{f:X \\rightarrow Y}}}\\\\ \\mathlarger{\\mathlarger{\\mathlarger{ f:\\hat{X} \\rightarrow \\hat{Y} }}}\\\\\n%\\mathlarger{\\mathlarger{\\mathlarger{ \\hat{f}:X \\rightarrow Y }}}%\\\\\n%%\\mathlarger{\\mathlarger{\\mathlarger{ \\hat{f}:\\hat{X} \\rightarrow \\hat{Y} }}}\n% \\end{eqnarray}\n% \n\n\\section*{Conditioning of a Problem}\n\n%\\begin{equation*}\n%\\mathlarger{ \\mathlarger{ \\mathlarger{f:\\hat{X} \\rightarrow \\hat{Y}}}}\n%\\end{equation*}\n\nA \\emph{problem} is a function $f:X \\rightarrow Y$, where $X$ is a vector space of data and $Y$ is a vector space of solutions. In a perfect world, this function takes an exact input $x$ and correctly returns the exact answer $y$. However we are working in the finite world of computers.\n\nSince $X$ and $Y$ are vector spaces of infinite cardinality, we cannot represent these spaces on a computer perfectly. We can only represent finite subsets $\\tilde{X} \\subset X$ and $\\tilde{Y} \\subset Y$. This means that the best we can do is approximate $x \\in X$ with some $\\tilde{x} \\in \\tilde{X}$ and return an approximate correct answer $\\tilde{y} \\in \\tilde{Y}$. But if we change the input from $x$ to $\\tilde{x}$, how much will our output change?\n\nWe define the \\emph{condition number} of $f$ at $x$. Let $\\delta x$ denote a small perturbation of $x$, and let $\\delta f = f(x+\\delta x) - f(x)$. Then the \\emph{absolute condition number} of $f$ at $x$ is \n \\[\n\\hat{\\mathcal{K}} = \\lim_{\\delta \\rightarrow 0} \\sup_{\\norm{\\delta x} \\leq \\delta} { \\frac{\\norm{\\delta f}}{\\norm{\\delta x}} } \n\\]\n\nThis is the ratio of output error to input error. These are \\emph{absolute} errors; however, the error introduced by floating point arithmetic on a computer is \\emph{relative} error. Therefore we define also \\emph{relative condition number}:\n\n\\begin{equation}\n\\mathcal{K} = \\lim_{\\delta \\rightarrow 0} \\sup_{\\norm{\\delta x} \\leq \\delta} \\left({ \\frac{\\norm{\\delta f}}{\\norm{f(x)}} } \\middle/ { \\frac{\\norm{\\delta x}}{\\norm{x}} }\\right)\n\\label{def:relativeconditionnumber}\n\\end{equation}\n\nRelative condition number is usually a more useful concept that absolute condition number.\n\nWe say that a problem $f$ is \\emph{well-conditioned} at $x$ if $\\mathcal{K}$ is small. In this case, small changes to $x$ result in small changes to $f(x)$. We say $f$ is \\emph{ill-conditioned} at $x$ if $\\mathcal{K}$ is large. In this case, small changes to $x$ may result in large changes to $f(x)$. \n\n\\begin{example}[The Wilkinson Polynomial]\nPolynomial root finding is a notoriously ill-conditioned problem. Root-finding for a degree $n$ polynomial can be described by a function $f$, which takes a vector $x$ of $n+1$ coefficients and returns a vector $y$ of $n$ roots. If two of the roots in $y$ are close to each other, the condition number of $f$ at $x$ will be large. In fact if $y$ contains repeated roots, the condition number is $\\infty$.\n \nJames Wilkinson illustrated that root-finding can be extremely ill-conditioned even if the roots are far apart. His classic example is called the \\emph{Wilkinson polynomial}:\n \n\\[\nw(x) = (x-1)(x-2)(x-3)\\hdots(x-20)\n\\]\n \nExpanding this polynomial to obtain coefficients gives\n \n\\[\\begin{array}{cl}\n w(x)=& x^{20}-210x^{19} +20615x^{18} -1256850 x^{17} +53327946 x^{16}\\\\ \n &-1672280820x^{15} + 40171771630x^{14} -756111184500x^{13}\\\\\n&+11310276995381 x^{12} -135585182899530 x^{11}\\\\ \n&+1307535010540395 x^{10} -10142299865511450 x^9\\\\\n&+63030812099294896 x^8 -311333643161390640 x^7\\\\ \n&+1206647803780373360 x^6 -3599979517947607200 x^5\\\\ \n&+8037811822645051776 x^4 -12870931245150988800 x^3\\\\\n& +13803759753640704000 x^2 -8752948036761600000 x\\\\\n& +2432902008176640000\n      \\end{array} \\]\nFigure \\ref{fig:wilkinsonpolynomial} shows what happens to the roots of $w(x)$ when we make tiny perturbations to the coefficients. The condition number of this polynomial is $\\mathcal{K} \\approx 5.1 \\times 10^{13}$.\n\n\\begin{figure}\n\\centering\n\\includegraphics[height=2in]{wilkinsonpolynomial.pdf}\n\\caption{The blue dots are the roots of w(x). The red dots in the complex plane are roots of a randomly perturbed polynomial with coefficients $\\hat{a}_k = a_k(1+r_k)$, where the $r_k$ are normally distributed with mean $0$ and standard deviation $10^{-5}$.}\n\\label{fig:wilkinsonpolynomial}\n\\end{figure}\n\\end{example}\n\n\\begin{problem}\nWrite a function to reproduce Figure \\ref{fig:wilkinsonpolynomial}.\nPerturb $w(x)$ as described in the caption for this Figure.\nInstead of plotting the roots for just one random pertubation of $w(x)$, plot the roots for several random perturbations.\n\nWrite another function that, given an array of roots for a polynomial, computes the polynomial object representing the polynomial with the desired roots, then finds the roots of the resulting polynomial and plots them with the original roots.\nYou may find the \\li{numpy.poly()} function useful for this.\nBe sure you use different colors for the different sets of points.\nUsing equispaced points at integer values, what does the degree of the polynomial have to be for this computation to return incorrect answers?\n\\end{problem}\n\n\\begin{example}[Calculating Eigenvalues]\nConsider the problem of finding the eigenvectors of a given $n \\times n$ matrix $A$. If $A$ is symmetric, then fortunately the eigenvalue problem is well-conditioned. However the problem can be extremely ill-conditioned for non-symmetric matrices, even if $n$ is small. For example, the two matrices \n\\[ \\left( \\begin{array}{cc}\n1 & 1000 \\\\\n0 & 1\n\\end{array} \\right)\n%\n\\left( \\begin{array}{cc}\n1 & 1000 \\\\\n0.001 & 1\n\\end{array} \\right)\n\\]\nhave eigenvalues $\\{ 1,1\\}$ and $\\{0,2 \\}$ respectively.\n\\end{example}\n\n\\begin{problem}\nLet $f:X\\rightarrow Y$ be a function that accepts an $n\\times n$ matrix $A$ and returns an $n \\times 1$ vector of eigenvalues $y$. Write your own function that accepts a matrix $A$ and estimates the condition number $\\mathcal{K}$ of $f$ at $A$. Recall that the definition of $\\mathcal{K}$ in Equation \\ref{def:relativeconditionnumber} includes the limit as $\\delta \\rightarrow 0$ and the supremum over all possible $\\delta x \\leq \\delta$. To mimic this on a computer, simply take $\\delta$ to be very small. Then calculate $\\mathcal{k} =  { \\frac{\\norm{\\delta f}}{\\norm{f(x)}} } / { \\frac{\\norm{\\delta x}}{\\norm{x}} }$ a large number of times, taking a random $\\delta x$ each time such that $\\norm{\\delta x} \\leq \\delta$. Let $\\mathcal{K}$ be the largest of the values $\\mathcal{k}$ calculated. (Hint: Let each $\\delta x$ be a random normal matrix with mean $0$ and standard deviation $\\approx 10^{-4}$.)\n\nExperiment with inputting random symmetric and non-symmetric matrices. Remember that if $A$ is any matrix, then $A'A$ is symmetric. What kinds of condition numbers do you get for symmetric vs. non-symmetric matrices? What kinds of matrices give the biggest condition numbers for the eigenvalue problem?\n\\end{problem}\n\n\\begin{example}[Condition of a System of Equations]\nConsider the system of equations\n\\[ Ax = b \\] \nfor an $n \\times n$ matrix $A$ and $n \\times 1$ vectors $x$ and $b$. If we hold $A$ fixed, consider the problem of computing $b$ with respect to small changes in $x$. Alternatively, hold $A$ fixed and consider the problem of computing $x = A^{-1} b$ with respect to small changes in $b$. Finally, we may hold $b$ fixed and consider the problem of computing $x = A^{-1}b$ with respect to small changes in $A$.\n\nIt turns out that each of these problems has the \\emph{same} relative condition number. This number is \n\\[\n\\mathcal{K} (A) = \\norm{A}_2 \\norm{A^{-1}}_2\n\\]\n\nThis is called the \\emph{condition number of $A$}.\nThe condition number of a matrix can be computed using \\li{numpy.linalg.cond()}.\n\nNotice that the condition number of a matrix cannot be less that $1$.\nIt is almost always best to work with orthonormal matrices (or operations that can be mathematically represented by orthonormal matrices).\nSince orthonormal matrices have a norm of $1$, as do their inverses, these transformations have the best possible condition number.\nThe low condition number of orthonormal matrices is one of the primary reasons that Householder reflections and Givens rotations are used in so many algorithms.\n\\end{example}\n\n\\section*{Stability of an Algorithm}\nThe analysis of problem-solving given above assumed that for a given input $\\hat{x}$, we could determine the correct output $f(\\hat{x})$ exactly. In other words, even if $\\hat{x} \\neq x$, we assumed that we could calculate $f(\\hat{x})$ exactly although it may be different from $f(x)$. \n\nIn practice, our calculation of $f(\\hat{x})$ is not always accurate, \\emph{even if} the problem $f$ is well-conditioned. Our method of solving the problem may introduce new error. Sometimes the new error we introduce may be very large. \n\nWe define an \\emph{algorithm} to be a method of solving a given problem. (The algorithm for solving a problem is different than the problem itself.) If an algorithm introduces large errors while solving a problem, the algorithm is called \\emph{unstable}. A \\emph{stable} algorithm does not introduce large error while solving a problem.\n\nWhat could go wrong in an algorithm that would introduce new errors? Usually this happens when the algorithm breaks the problem into sub-problems, and one of these sub-problems is ill-conditioned. For example, the problem of computing the matrix $e^A$ may be well-conditioned for a given $A$, while the problem of computing the eigenvalues and eigenvectors of the same $A$ may be ill-conditioned. If an algorithm for computing $e^A$ relies on the intermediate step of computing the eigenvalues and eigenvectors, new error will be introduced. \n\nAs another example, take the problem of computing the eigenvalues of a matrix $A$. If $A$ is symmetric, the eigenvalue problem is well-conditioned. However, suppose we use an algorithm that first computes the coefficients of the characteristic polynomial, and then finds the roots of that polynomial. Unavoidably, tiny errors will creep in when we compute the coefficients of the characteristic polynomial. Since root-finding is an ill-conditioned problem, these tiny errors will be magnified. This algorithm is unstable.\n\n\\begin{warn}\nBe careful to not confuse the stability of an algorithm with the conditioning of a problem.\nThese are two very different things.\nA stable algorithm is, roughly speaking, an algorithm that will return a correct result if the problem is well conditioned.\nIf a problem is poorly conditioned, special algorithmic changes may be necessary to ensure a reasonable degree of accuracy.\n\\end{warn}\n\n\\begin{example}[A Simple but Unstable Algorithm]\nConsider\n\\[\\int_0^1 x^n e^{x - 1} dx\\]\nIt is easily seen that this integral is always positive and always less than $1$.\nIt can be shown that, when $n > 1$, the value for this integral is always equal to\n\\[\\left(-1\\right)^{n} !n + \\left(-1\\right)^{n + 1} \\frac{n!}{e}\\]\nwhere $!n$ is a combinatorial function called a derangement (it is equal to the number of permutations of a set that change the position of each element).\n$!n$ is given by the recurrence relation $\\left(n - 1\\right)\\left(!\\left(n - 1\\right) + !\\left(n - 2\\right)\\right)$ and is defined to have the initial values $!0 = 1$ and $!1 = 0$.\nThere is a similar recurrence relation for the factorial function.\nGiven these recurrence relations, we can compute the value for this integral as using the following blocks of code:\n\\begin{lstlisting}\nimport numpy as np\ndef derangement(n):\n    d0, d1 = 1, 0\n    for i in xrange(1, n):\n        d0, d1 = d1, i * (d0 + d1)\n    return d1\ndef factorial(n):\n    d0, d1 = 1, 1\n    for i in xrange(1, n):\n        d0, d1 = d1, i * (d0 + d1)\n    return d1\ndef integral(n):\n    return (-1)**n * derangement(n) + (-1)**(n-1) * factorial(n) / np.e\n\\end{lstlisting}\nUnfortunately, since we are taking the difference of large floating point numbers that are very close to one another, this algorithm only gives correct values for the first few integrals.\nThe output is shown in Table \\ref{table:unstable_computation}.\n\n\\begin{table}\n\\centering\n\\begin{tabular}{|l|l|l|}\n\\hline\nIntegrand & Computed Value & Actual Value \\\\\n\\hline\n$x^{1}e^{x}$: & $0.367879441171$ & $0.367879441171$ \\\\\n$x^{5}e^{x}$: & $0.145532940573$ & $0.145532940573$ \\\\\n$x^{10}e^{x}$: & $0.0838770701084$ & $0.0838770701034$ \\\\\n$x^{15}e^{x}$: & $0.0590209960938$ & $0.0590175408793$ \\\\\n$x^{20}e^{x}$: & $0.0$ & $0.0455448840758$ \\\\\n$x^{25}e^{x}$: & $1073741824.0$ & $0.0370862144237$ \\\\\n$x^{30}e^{x}$: & $-1.80143985095 \\cdot 10^{16}$ & $0.0312796739322$ \\\\\n$x^{35}e^{x}$: & $6.04462909807 \\cdot 10^{23}$ & $0.0270462894091$ \\\\\n$x^{40}e^{x}$: & $0.0$ & $0.023822728669$ \\\\\n$x^{45}e^{x}$: & $0.0$ & $0.0212860390856$ \\\\\n$x^{50}e^{x}$: & $1.46150163733 \\cdot 10^{48}$ & $0.0192377544343$ \\\\\n\\hline\n\\end{tabular}\n\\caption{Inaccuracy of values computed using an unstable algorithm.}\n\\label{table:unstable_computation}\n\\end{table}\n\nThe algorithms that we have studied to solve linear systems have different levels of stability.\nLU decomposition (with pivoting) is usually good enough, but there are some pathological examples of matrices that cause it to break down.\nQR decomposition (with pivoting) is generally considered to be a better option than the LU decomposition.\nSolving a linear system using the SVD is even more stable than the QR decomposition.\n(Pivoting is a modification that is commonly made to the LU decomposition and QR decomposition algorithms we have discussed in earlier labs to make them more stable.)\nUnfortunately, in this case, the algorithms that are more stable are also slower.\nThe LU decomposition is used by \\li{scipy.linalg.solve()}.\nThe SVD is used by \\li{scipy.linalg.lstsq()}.\nHere is some code that uses the QR decomposition of a matrix $A$ to solve the linear system $A x = b$ for $x$.\nIt uses a lower-level function included in SciPy to perform the back substitution required to solve this system.\n\\begin{lstlisting}\nfrom scipy import linalg as la\nfrom scipy.linalg.flapack import dtrtrs\ndef qr_solve(A, b):\n    Q, R = la.qr(A)\n    return dtrtrs(R.T, Q.T.dot(b), lower=1, trans=1)[0]\n\\end{lstlisting}\nA solution using a pivoted QR decomposition would be better, but this will be good enough for demonstration purposes.\n\nThe following are routines that generate matrices designed to show the relative benefits of each of these algorithms.\n\\begin{lstlisting}\nfrom numpy.random import rand\n\ndef bad_arr_1(n):\n    \"\"\" Construct a specific pathological example\n    that breaks LU decomposition. These examples\n    are very rare, but they do exist.\n    Strictly speaking, the condition number\n    for this matrix isn't terribly bad. \"\"\"\n    A = - np.ones((n, n))\n    A[:,:-1] = np.tril(A[:,:-1])\n    np.fill_diagonal(A, 1)\n    A[:,-1] = 1\n    return A\n\ndef bad_arr_2(n, peturbation = 1E-8):\n    \"\"\" Construct another matrix that is nearly singular\n    by computing A.dot(A.T) for a matrix A that is\n    not square and then adding some small changes\n    so it is not exactly singular. \"\"\"\n    A = rand(n, n // 2)\n    return A.dot(A.T) + peturbation * rand(n, n)\n\\end{lstlisting}\n\\end{example}\n\n\\begin{problem}\nFor each of the array creation routines above, plot the error $\\norm{\\text{solve}\\left(A, A b\\right) - b}$ of each of the methods mentioned above for solving a linear system.\nUse a log-scaled $y$-axis.\nWhat do you observe?\n\\end{problem}\n\n%\\subsection*{Stable vs. Backward Stable Algorithms}\n\n%\\subsection*{Table}\n%\n%\\begin{table}[h]\n%\\begin{tabular}{|l|l|l|}\n%\\hline \\textbf{Well-Conditioned} & \\textbf{Ill-Conditioned} & \\textbf{Systems of Equations} \\\\\n%{\\parbox{0.3\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item finding eigenvalues of a symmetric (or normal) matrix \n%                \\item calculating $e^x$ for relatively small values of $x$ \n%                \\item calculating $\\ln(x)$ for $x$ not close to $1$\n%            \\end{itemize} }}           &  \n%             \n%{\\parbox{0.3\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item calculating $x_1 - x_2$ when $x_1 \\approx x_2$ \n%                \\item computing roots of a polynomial, given the coefficients\n%                \\item computing eigenvalues of a non-symmetric matrix\n%            \\end{itemize} }}              &   \n%            \n%{\\parbox{0.3\\textwidth}{\n%            \\begin{itemize}[leftmargin=*]\n%                 \\item relative condition number is \\[ \\mathcal{K} = ||A|| ||A^{-1}|| \\]\n%            \\end{itemize} }}   \\\\ \\hline                      \n%\\end{tabular}\n%\\end{table}\n%\n%\n%\\begin{table}[h]\n%\\begin{tabular}{|l|l|}\n%\\hline \\textbf{Stable} & \\textbf{Unstable} \\\\\n%{\\parbox{0.45\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item finding eigenvalues of a symmetric (or normal) matrix \n%                \\item calculating $e^x$ for relatively small values of $x$ \n%                \\item calculating $\\ln(x)$ for $x$ not close to $1$\n%            \\end{itemize} }}           &  \n%             \n%{\\parbox{0.45\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item calculating $x_1 - x_2$ when $x_1 \\approx x_2$ \n%                \\item computing roots of a polynomial, given the coefficients\n%                \\item computing eigenvalues of a non-symmetric matrix\n%            \\end{itemize} }}    \\\\ \\hline                      \n%\\end{tabular}\n%\\end{table}\n%\n", "meta": {"hexsha": "03317578016fb7a9754c1e39fe1b9b75ab1f77be", "size": 17824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Conditioning_Stability/Conditioning_Stability.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Conditioning_Stability/Conditioning_Stability.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Conditioning_Stability/Conditioning_Stability.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": 59.8120805369, "max_line_length": 903, "alphanum_fraction": 0.7081463196, "num_tokens": 5065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.673494505679587}}
{"text": "\n\\subsection{Engel curves and income elasticity of demand}\n\nThe Engel curve shows demand for a good as a function of income.\n\nDerivative\n\\(x_{di}=x_{di}(I, \\mathbf p)\\)\n\n\\(\\dfrac{\\delta }{\\delta I}x_{di}(I, \\mathbf p)\\)\n\nIncome elasticity of demand\n\\(\\xi_i =\\dfrac{\\delta x_{di}}{\\delta I}\\dfrac{I}{x_{di}}\\)\n\n", "meta": {"hexsha": "a69ca9fa8ee2c988dee2e6c3775c9400f64a734e", "size": 310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/04-01-elasticityIncome.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/04-01-elasticityIncome.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/04-01-elasticityIncome.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.1428571429, "max_line_length": 64, "alphanum_fraction": 0.6806451613, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6734898483490708}}
{"text": "\\chapter{Electrodynamics}\nIn this chapter, we would like to present an important example of field theory. We want to focus on the Hamiltonian description of electrodynamics and see that it yields the classical results. The Lagrangian of the free electromagnetic field without charges is\n\\begin{align}\nL[A^{\\mu}(\\bar{x}), \\dot{A}^{\\mu}(\\bar{x})]  = - \\frac{1}{4} \\displaystyle\\int d^3 x \\ F_{\\mu \\nu}(\\bar{x}) F^{\\mu \\nu}(\\bar{x}),\n\\end{align}\nwhere we use natural units and\n\\begin{align}\nF_{\\mu \\nu}(\\bar{x}) = \\partial_{\\mu} A_{\\nu}(\\bar{x}) - \\partial_{\\nu} A_{\\mu}(\\bar{x})\n\\end{align}\nis the antisymmetric field tensor. Since it is expressed through the vector potential $A^{\\mu}(\\bar{x})$, the vector potential takes the role of our field $\\varphi(\\bar{x})$. Note that we have four different fields, since $\\mu = 0,1,2,3$.\nThat's why we define the generalized momenta to be\n\\begin{align}\n\\pi_{\\rho}(\\bar{y}) = \\frac{\\delta L}{\\delta \\dot{A}^{\\rho}(\\bar{y})}.\n\\end{align}\nInserting the Lagrangian, one gets\n\\begin{align}\n\\pi_{\\rho}(\\bar{y}) &= \\frac{\\delta L}{\\delta \\dot{A}^{\\rho}(\\bar{y})} = - \\frac{1}{4} \\int d^3 x \\ \\frac{\\delta \\left( F_{\\mu \\nu}(\\vec{x}) F^{\\mu \\nu}(\\bar{x}) \\right)}{\\delta \\dot{A}^{\\rho}(\\bar{y})} \\notag \\\\\n&= - \\frac{1}{2} \\int d^3 x \\ F_{\\mu \\nu}(\\bar{x}) \\ \\frac{\\delta \\left(\\partial^{\\mu} A^{\\nu}(\\bar{x}) - \\partial^{\\nu} A^{\\mu}(\\bar{x}) \\right)}{\\delta \\dot{A}^{\\rho}(\\bar{y})} \\notag \\\\\n&= - \\frac{1}{2} \\int d^3 x \\ F_{\\mu \\nu}(\\bar{x}) \\left( \\delta_0^{\\mu} \\ \\frac{\\delta \\dot{A}^{\\nu}(\\bar{x})}{\\delta \\dot{A}^{\\rho}(\\bar{y})} - \\delta_0^{\\nu} \\ \\frac{\\delta \\dot{A}^{\\mu}(\\bar{x})}{\\delta \\dot{A}^{\\rho}(\\bar{y})} \\right) \\notag \\\\\n&= - \\frac{1}{2} \\int d^3 x \\ F_{\\mu \\nu}(\\bar{x}) \\left( \\delta_0^{\\mu} \\delta_{\\rho}^{\\nu} \\ \\delta^3(\\bar{x} - \\bar{y}) - \\delta_0^{\\nu} \\delta_{\\rho}^{\\mu} \\ \\delta^3(\\bar{x} - \\bar{y}) \\right) \\notag \\\\\n&= - \\frac{1}{2} \\int d^3 x \\ \\left( F_{0 \\rho}(\\bar{x}) \\ \\delta^3(\\bar{x} - \\bar{y}) - F_{\\rho 0}(\\bar{x}) \\ \\delta^3(\\bar{x} - \\bar{y}) \\right) \\notag \\\\\n&= - \\frac{1}{2} \\left( F_{0 \\rho}(\\bar{y}) - F_{\\rho 0}(\\bar{y}) \\right) = F_{\\rho 0}(\\bar{y}) .\n\\end{align}\nUsing the explicit formula for $F_{\\mu \\nu}$, the generalized momenta can be written as\n\\begin{align}\n\\pi_{\\rho}(\\bar{y}) = \\partial_{\\rho} A_0(\\bar{y}) - \\dot{A}_{\\rho}(\\bar{y}).\n\\end{align}\n\\label{sec:electrodynamics_primary_constraints}\nTo find the Hamiltonian, one has to invert this equation and express $\\dot{A}_{\\rho}(\\vec{y})$ through $\\pi_{\\rho}(\\vec{y})$ and the field components. We see that this won't be possible for $\\rho = 0$, we have a primary constraint:\n\\begin{align}\n\\pi_0(\\bar{y}) = \\partial_0 A_0(\\bar{y}) - \\dot{A}_0(\\bar{y}) = 0 \\ \\ \\ \\Longrightarrow \\ \\ \\ \\phi_1 = \\pi_0(\\bar{y}) = 0 \\ \\ \\forall \\bar{y} \\in \\mathbb{R}^3.\n\\end{align}\nMore exactly, we have infinitly many constraints because the momentum $\\pi_0(\\bar{y})$ vanishes in every point in space. This corresponds to the gauge freedom of $A^0(\\bar{x})$ as we will see later. No matter how we choose it, the conjugated momentum vanishes identically. For the other components, everything is fine and no more constraints arise. \\\\\n\\label{sec:electrodynamics_hamiltonian}\nThe Hamiltonian is therefore\n\\begin{align}\nH[A^{\\mu}(\\bar{x}), \\pi_{\\mu}(\\bar{x})] &= \\int d^3 x \\ \\dot{A}^{\\mu}(\\bar{x}) \\pi_{\\mu}(\\bar{x}) \\ - \\ L[A^{\\mu}(\\bar{x}), \\dot{A}^{\\mu}(\\bar{x})] \\notag \\\\\n&= \\int d^3 x \\ \\dot{A}^{\\mu}(\\bar{x}) \\pi_{\\mu}(\\bar{x}) \\ + \\  \\frac{1}{4} \\displaystyle\\int d^3 x \\ F_{\\mu \\nu}(\\bar{x}) F^{\\mu \\nu}(\\bar{x}) \\notag \\\\\n&= \\int d^3 x \\left( \\dot{A}^{i}(\\bar{x}) \\pi_{i}(\\bar{x}) + \\frac{1}{2} F_{i 0}(\\bar{x}) F^{i 0}(\\bar{x}) + \\frac{1}{4} F_{i k}(\\bar{x}) F^{i k}(\\bar{x}) \\right) \\notag \\\\\n&= \\int d^3 x \\left( \\left( \\pi_i(\\bar{x}) - \\partial_i A_0(\\bar{x}) \\right) \\pi_i(\\bar{x}) + \\frac{1}{2} \\pi_i(\\bar{x}) (- \\pi_i(\\bar{x})) + \\frac{1}{4} F_{i k}(\\bar{x}) F^{i k}(\\bar{x}) \\right) \\notag \\\\\n&= \\int d^3 x \\left( \\frac{1}{2} \\pi_i(\\bar{x})\\pi_i(\\bar{x}) - \\partial_i A_0(\\bar{x}) \\pi_i(\\bar{x}) + \\frac{1}{4} F_{i k}(\\bar{x}) F^{i k}(\\bar{x}) \\right) \\notag \\\\\n&= \\int d^3 x \\left( \\frac{1}{2} \\pi_i(\\bar{x})\\pi_i(\\bar{x}) + A_0(\\bar{x}) \\partial_i \\pi_i(\\bar{x}) + \\frac{1}{4} F_{i k}(\\bar{x}) F^{i k}(\\bar{x}) \\right),\n\\end{align}\nwhere in the last step we integrated by parts and assumed that the fields vanish at infinity. Terms like $\\pi_i(\\bar{x})\\pi_i(\\bar{x})$, where both indices are down or up, denote usual summation. \\\\ \nThe first term contains the momenta and is equivalent to the kinetic energy. The last term contains spatial derivatives of the fied components and is therefore equivalent to a potential energy. The second term is a mix of kinetic and potential energy and should not appear in a regular Hamiltonian. We have to check whether the consistency condition for our primary constraint is fulfilled or we have secondary constraints. \\\\\nThe total Hamiltonian is \n\\begin{align}\nH_T = H + \\int d^3 x \\ u(\\bar{x}) \\pi_0(\\bar{x}).\n\\end{align}\nAnd the equation of motion is given by \n\\begin{align}\n\\dot{g} = \\left \\{ g,H_T \\right \\} = \\left \\{ g,H \\right \\} + \\int d^3 x \\ u(\\bar{x}) \\left \\{ g,\\pi_0(\\bar{x}) \\right \\},\n\\end{align}\nwhere the Poisson bracket is given by\n\\begin{align}\n\\left \\{ f,g \\right \\} = \\int d^3 z \\left( \\frac{\\delta f}{\\delta A^{\\mu}(\\bar{z})} \\frac{\\delta g}{\\delta \\pi_{\\mu}(\\bar{z})} - \\frac{\\delta g}{\\delta A^{\\mu}(\\bar{z})} \\frac{\\delta f}{\\delta \\pi_{\\mu}(\\bar{z})}  \\right),\n\\end{align}\nanalog to the definition in field theory. It follows that\n\\begin{align}\n0 \\overset{!}{=} \\dot{\\pi}_0(\\bar{y}) &= \\left \\{ \\pi_0(\\bar{y}),H(\\bar{y}) \\right \\} + \\int d^3 x \\ u(\\bar{x}) \\left \\{ \\pi_0(\\bar{y}),\\pi_0(\\bar{x}) \\right \\} \\notag \\\\\n&= - \\int d^3 z \\ \\frac{\\delta \\pi_0(\\bar{y})}{\\delta \\pi_{\\mu}(\\bar{z})} \\frac{\\delta H(\\bar{y})}{\\delta A^{\\mu}(\\bar{z})} = - \\frac{\\delta H(\\bar{y})}{\\delta A^0(\\bar{y})} \\notag \\\\\n&= - \\int d^3 x \\ \\partial_i \\pi_i(\\bar{x}) \\frac{\\delta A^0(\\bar{x})}{\\delta A^0(\\bar{y})} = - \\partial_i \\pi_i(\\bar{y}).\n\\end{align}\n\\label{sec:electrodynamics_secondary_constraints}\nSo we really get a secondary constraint which is\n\\begin{align}\n\\phi_2 = \\partial_i \\pi_i = \\text{div} \\ \\bar{\\pi} = 0.\n\\end{align}\nAgain we have to proof that this constraint is fulfilled at every moment (if not, then the primary constraint wouldn't be fulfilled at every moment). \\\\\nIt follows that\n\\begin{align}\n0 \\overset{!}{=} \\frac{d}{dt} \\Big( \\partial_i \\pi_i(\\bar{y}) \\Big) &= \\left \\{ \\partial_i \\pi_i(\\bar{y}),H(\\bar{y}) \\right \\} + \\int d^3 x \\ u(\\bar{x}) \\left \\{ \\partial_i \\pi_i(\\bar{y}),\\pi_0(\\bar{x}) \\right \\} \\notag \\\\\n&= - \\int d^3 z \\ \\frac{\\delta (\\partial_i B_i(\\bar{y}))}{\\delta B_{\\mu}(\\bar{z})} \\frac{\\delta H(\\bar{y})}{\\delta A^{\\mu}(\\bar{z})} = - \\int d^3 z \\  \\partial_i \\left(\\delta^3(\\bar{y} - \\bar{z})\\right) \\frac{\\delta H(\\bar{y})}{\\delta A^i(\\bar{z})} \\notag \\\\\n&= - \\partial^i \\left( \\frac{\\delta H(\\bar{y})}{\\delta A^i(\\bar{y})} \\right),\n\\end{align}\nwhere the variation is given by \n\\begin{align}\n\\frac{\\delta H(\\bar{y})}{\\delta A^i(\\bar{y})} &= \\frac{\\delta}{\\delta A^i(\\bar{y})} \\left( \\frac{1}{4} \\int d^3 x \\ F_{lk}(\\bar{x})F^{lk}(\\bar{x}) \\right) \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\ F_{lk}(\\bar{x}) \\frac{\\delta F^{lk}(\\bar{x})}{\\delta A^i(\\bar{y})} \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\ F_{lk}(\\bar{x}) \\frac{\\delta (\\partial^l A^k(\\bar{x}) - \\partial^k A^l(\\bar{x}))}{\\delta A^i(\\bar{y})} \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\ F_{lk}(\\bar{x}) \\left( \\delta_i^k  \\partial^l \\left(\\delta^3(\\bar{x} - \\bar{y})\\right) - \\delta_i^l  \\partial^k \\left(\\delta^3(\\bar{x} - \\bar{y})\\right) \\right) \\notag \\\\\n&= \\frac{1}{2} \\int d^3 x \\ \\left( - \\partial^l F_{li}(\\bar{x}) + \\partial^k F_{ik}(\\bar{x}) \\right) \\delta^3(\\bar{x} - \\bar{y}) \\notag \\\\\n&= - \\partial^k F_{ki}(\\bar{y}).\n\\end{align}\nIn the end, we get\n\\begin{align}\n\\frac{d}{dt} \\Big( \\partial_i \\pi_i(\\bar{y}) \\Big) = \\partial^i \\partial^k F_{ki}(\\bar{y}),\n\\end{align}\nwhich is clearly zero since we have a contraction of a symmetric with an antisymmetric tensor. So the secondary constraint is automatically conserved and we get no more constraints. \\\\\n\nNow, that our procedure is finished, we can classify the constraints and say which is first-class and which is second-class.\nSince both constraints depends only on the momentum, they are first-class. So one can write the generalized Hamiltonian as\n\\begin{align}\nH_E = H + \\int d^3 x \\ v(\\bar{x}) \\pi_0(\\bar{x}) + \\int d^3 x \\ V(\\bar{x}) \\partial_i \\pi_i(\\bar{x}),\n\\end{align}\nwhere $v(\\bar{x})$ and $V(\\bar{x})$ are arbitrary functions. \\\\\n\n\\label{sec:electrodynamics_transformations}\nSince we have two undetermined functions in our Hamiltonian, this corresponds to two degrees of gauge freedom.\nLet's see what transformations $g \\longrightarrow g' = g + \\delta g$ these first-class constraints do generate. \\\\\nWe calculate the small shift $\\delta g$ analog to the classical discrete case:\n\\begin{align}\n\\delta g = \\varepsilon_m \\left\\{ g,\\phi_m \\right\\} \\ \\ \\ \\Longrightarrow \\ \\ \\ \\delta g = \\int d^3 y \\ \\varepsilon(\\bar{y}) \\left\\{ g,\\phi(\\bar{y}) \\right\\}.\n\\end{align}\nWe also have a kind of canonical commutation relation\n\\begin{align}\n\\left\\{ A^{\\mu}(\\bar{x}), \\pi_{\\nu}(\\bar{y}) \\right\\} = \\delta_{\\nu}^{\\mu} \\ \\delta^3(\\bar{x} - \\bar{y}),\n\\end{align}\nanalog to $\\left\\{ q_i, p_k \\right\\} = \\delta_{ik}$. Now, we are able to determine the gauge transformations generated by the two constraints. \n\n\\begin{itemize}\n\\item Choosing $g = A^{\\mu}(\\bar{x})$, we get for the first constraint:\n\\begin{align}\n\\delta A^{\\mu}(\\bar{x}) &= \\int d^3 y \\ \\varepsilon(\\bar{y}) \\left\\{ A^{\\mu}(\\bar{x}), \\pi_0(\\bar{y}) \\right\\} \\notag \\\\\n&= \\int d^3 y \\ \\varepsilon(\\bar{y}) \\ \\delta_0^{\\mu} \\ \\delta^3(\\bar{x} - \\bar{y}) \\notag \\\\\n&= \\delta_0^{\\mu} \\ \\varepsilon(\\bar{x}).\n\\end{align}\nSo the first constraint only generates transformations \n\\begin{align}\nA_0(\\bar{x}) \\ \\longrightarrow \\ A'_0(\\bar{x}) = A_0(\\bar{x}) + \\varepsilon(\\bar{x})\n\\end{align}\nand leaves the momentum unchanged since $\\left\\{ \\pi_{\\mu}(\\bar{x}), \\pi_0(\\bar{y}) \\right\\} = 0$.\n\\item The second constraint leaves the momentum unchanged too because of the same reason. Furthermore it leaves $A_0$ unchanged because the constraint contains only spatial terms and the Poisson bracket vanishes. So we have\n\\begin{align}\n\\delta A^k(\\bar{x}) &= \\int d^3 y \\ \\tilde{\\varepsilon}(\\bar{y}) \\left\\{ A^k(\\bar{x}), \\partial_i \\pi_i(\\bar{y}) \\right\\} \\notag \\\\\n&= - \\int d^3 y \\ \\tilde{\\varepsilon}(\\bar{y}) \\ \\delta_i^k \\ \\partial^i \\left( \\delta^3(\\bar{x} - \\bar{y}) \\right) \\notag \\\\\n&= \\partial^k \\tilde{\\varepsilon}(\\bar{x}).\n\\end{align}\nSo the second constraint generates transformations \n\\begin{align}\nA^k(\\bar{x}) \\ \\longrightarrow \\ A'^k(\\bar{x}) = A^k(\\bar{x}) + \\partial^k \\tilde{\\varepsilon}(\\bar{x}),\n\\end{align}\nor in vector notation\n\\begin{align}\n\\bar{A}(\\bar{x}) \\ \\longrightarrow \\ \\bar{A}'(\\bar{x}) = \\bar{A}(\\bar{x}) + \\nabla \\tilde{\\varepsilon}(\\bar{x}).\n\\end{align}\n\\end{itemize}\n\nSo one can write the generalized Hamiltonian as\n\\begin{align}\nH_E &= \\int d^3 x \\left( \\frac{1}{2} \\pi_i(\\bar{x})\\pi_i(\\bar{x}) + (A_0(\\bar{x}) + V(\\bar{x})) \\partial_i \\pi_i(\\bar{x}) + \\frac{1}{4} F_{i k}(\\bar{x}) F^{i k}(\\bar{x}) + v(\\bar{x}) \\pi_0(\\bar{x}) \\right) \\notag \\\\\n&= \\int d^3 x \\left( \\frac{1}{2} \\pi_i(\\bar{x})\\pi_i(\\bar{x}) + V(\\bar{x}) \\partial_i \\pi_i(\\bar{x}) + \\frac{1}{4} F_{i k}(\\bar{x}) F^{i k}(\\bar{x}) + v(\\bar{x}) \\pi_0(\\bar{x}) \\right),\n\\end{align}\nbecause of the gauge freedom of $A_0$, and we see that no mixed terms with momenta and coordinates appear. The Hamiltonian is regular and can be devided in a kinetic and potential energy part. \\\\\n\nLet's analyse the spatial part of the Hamiltonian and see what it means in terms of the electric field $\\bar{E}$ and the magnetic field $\\bar{B}$. \\\\\nRemembering that the electromagnetic field tensor in natural units is\n\\begin{align}\nF^{\\mu \\nu} = \n\\left( \n\\arraycolsep=1.4pt\\def\\arraystretch{1.2}\n\\begin{array}{cccc}\n0 & - E^1 & - E^2 & - E^3 \\\\\nE^1 & 0 & - B^3 & B^2 \\\\\nE^2 & B^3 & 0 & - B^1 \\\\\nE^3 & - B^2 & B^1 & 0  \n\\end{array} \\right) \\ \\ \\\n\\text{and} \\ \\ \\\n\\bar{B} = \\nabla \\times \\bar{A},\n\\end{align}\nthe momentum is nothing more than the electric field:\n\\begin{align}\n\\pi^i = F^{i 0} = E^i.\n\\end{align}\nMoreover, if one notices that \n\\begin{align}\n\\bar{B}^2 &= \\left( \\varepsilon_{ijk} \\partial^j A^k \\right) \\left( \\varepsilon_{ilm} \\partial^l A^m \\right) \\notag \\\\\n&= \\left( \\delta_{jl} \\delta_{km} - \\delta_{jm} \\delta_{kl} \\right)  \\partial^j A^k \\partial^l A^m \\notag \\\\\n&= \\partial_l A_m(\\bar{x}) \\partial^l A^m(\\bar{x}) - \\partial_m A_l(\\bar{x}) \\partial^l A^m(\\bar{x}), \n\\end{align}\nwe can rewrite\n\\begin{align}\nF_{i k}(\\bar{x}) F^{i k}(\\bar{x}) &= \\big( \\partial_i A_k(\\bar{x}) - \\partial_k A_i(\\bar{x}) \\big) \\left( \\partial^i A^k(\\bar{x}) - \\partial^k A^i(\\bar{x}) \\right) \\notag \\\\\n&= 2 \\left( \\partial_i A_k(\\bar{x}) \\partial^i A^k(\\bar{x}) - \\partial_i A_k(\\bar{x}) \\partial^k A^i(\\bar{x}) \\right) \\notag \\\\\n&= 2 \\bar{B}^2.\n\\end{align}\nSo the spatial part of the Hamiltonian can be written as\n\\begin{align}\nH_E = \\int d^3 x \\left( \\frac{\\bar{E}^2(\\bar{x})}{2} + \\frac{\\bar{B}^2(\\bar{x})}{2} \\right) + \\int d^3 x \\ V(\\bar{x}) \\ \\nabla \\cdot \\bar{E}(\\bar{x}),\n\\end{align}\nwhich is the classical result for the energy of the electromagnetic field. The first term is the kinetic term, the second term is the potential and the third term generates the gauge transformation $\\bar{A}' = \\bar{A} + \\nabla \\varepsilon$ that leaves the magnetic field $B$ unchanged.", "meta": {"hexsha": "3c828611ee0e234815cc9fb64033e458d0d2a4ec", "size": 13549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05_electrodynamics.tex", "max_stars_repo_name": "Spektralzerleger/Hamilton-Systems", "max_stars_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-11T22:55:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-11T22:55:50.000Z", "max_issues_repo_path": "05_electrodynamics.tex", "max_issues_repo_name": "Spektralzerleger/Hamilton-Systems", "max_issues_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05_electrodynamics.tex", "max_forks_repo_name": "Spektralzerleger/Hamilton-Systems", "max_forks_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.8563535912, "max_line_length": 426, "alphanum_fraction": 0.6241051, "num_tokens": 5184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6734744162314298}}
{"text": "\\subsection{Binary operators}\n\nA binary operator takes an additional input.\n\n\\begin{itemize}\n\\item If then - \\(\\theta \\rightarrow \\gamma \\)\n\\item Then if - \\(\\theta \\leftarrow \\gamma \\)\n\\item Iff - \\(\\theta \\leftrightarrow \\gamma \\)\n\\item And / Conjunction - \\(\\theta \\land \\gamma \\)\n\\item Or / Disjunction - \\(\\theta \\lor \\gamma \\)\n\\end{itemize}\n\n\n", "meta": {"hexsha": "780a024adacfb018cabbf16f35e490a46fdf6f41", "size": 349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/02-02-binary.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-02-binary.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-02-binary.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.9285714286, "max_line_length": 50, "alphanum_fraction": 0.676217765, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6734393314019878}}
{"text": "\\chapter{ELEC 220 CheatSheet}\n\\begin{multicols}{3}\n\n\\section{Ch.1 DC Conduction}\n$\\sigma$ = conductivity (S/m) and $ \\rho$ = resistivity ($ \\Omega $m). $\\sigma = 1 /\\ \\rho $. \n\\begin{table}\n\\begin{tabular}{c|c}\n\tHall coefficient    & $R_H= \\frac{v_D}{J}=\\frac{-1}{eN_e}=(-eN_e)^{-1}$ \\\\\n\tOhm's Law  & $J = \\sigma \\cdot E \\quad A /\\ m^{2}$\\\\ \n\tResistance & $R= \\frac{\\rho \\cdot  L}{A}= \\frac{L}{\\sigma \\cdot A}$ \\\\\n\tDrude Model  & $J = -eN_ev_D$ \\\\\n\tViscosity Model  & $v_D=\\frac{-e\\tau}{m_e}E$\n\\end{tabular}\n\\caption{Some Equations for DC Conduction}\n\\end{table}\n$$\\textbf{Scattering time Formula:} \\quad \\sigma= \\frac{e^2N_e\\tau}{m_e} $$\n\n\\section{Ch. 2 AC Conduction}\n\\begin{align} \n\\textbf{Skin Depth:} \\quad \\delta= \n\\left(\\frac{2}{\\omega \\mu \\sigma}\\right)^{1/2} \\\\\nE= E_0e^{-i(wt-z/\\ \\delta)}e^{-z/\\ \\delta} \\\\\nI \\sim e^{-2z /\\ \\delta} \\\\\nI \\propto |E|^{2} \\\\\n\\omega = \\frac{2\\pi c}{\\lambda_o}\n\\end{align} \n\\begin{align} \n\\textbf{Plasma Frequency:} \\quad \\omega_p= \n\\left(\\frac{N_ee^2}{m \\epsilon}\\right)^{1/2} \\\\\nk^2= \\omega^2 \\mu \\epsilon - \\frac{N_ee^2\\mu}{m}= \\omega^2\\mu\\epsilon\\left(1-\\frac{\\omega_p^2}{\\omega^2}\\right)\n\\end{align} \n%\\def\\bsq#1{%both single quotes\n%\t\\lq{#1}\\rq}\n\\section{Ch. 3 DC/AC Dielectrics}\n\\begin{align} \n\\textbf{Relative Permittivity:} \\quad = \\frac{C^\\prime}{C}=\\frac{Q^\\prime}{Q}\n= \\epsilon_r \\\\\nPA=Q^\\prime - Q = C^\\prime V - CV= CV(\\epsilon_r-1) \\\\\nP= \\epsilon_0E(\\epsilon_r-1) \\ and \\ \\epsilon_r=1+\\frac{P}{\\epsilon_0E}= 1+\\chi \\\\\nD = \\epsilon E = \\epsilon_0 \\epsilon_r E = \\epsilon_0 E+ P \\\\\nP = Np = Nqd \\\\\n\\epsilon_= 1 + \\frac{N \\alpha_e}{\\epsilon_0}=1+\\chi\n\\end{align}\n\\begin{align}\n\\textbf{Debye Model:} \\quad \n\\epsilon_d(\\omega)= \\frac{\\epsilon_d(0)}{1-i\\omega \\tau_r}=\\epsilon_d^\\prime+i\\epsilon_d^{\\prime \\prime}\\\\\n\\epsilon_d^\\prime= \\frac{\\epsilon_d(0)}{1+\\omega^2 \\tau_r^2} \\quad and \\quad \\epsilon_d^{\\prime \\prime}(\\omega)= \\frac{\\epsilon_d(0)}{1+\\omega^2 \\tau_r^2}\\omega \\tau_r\n\\end{align}\nDifferent Polarization Mechanisms(Decreasing Speed)\nElectronic\t\\\\\nIonic\t\\\\\nDipolar (Orientational)\t\\\\\nSpace Charge (Interfacial)\t\\\\\nFerroelectric\n\\section{Ch. 4 AC Dielectrics Cont'd}\n\\begin{align}\n\\nu =\\frac{c}{n}= \\frac{1}{\\sqrt{\\epsilon_r \\epsilon_o \\mu_o}} \\\\\nn = \\sqrt{\\epsilon_r} \\quad \\text{reflactive index} \\\\\n\\sin(\\theta_c)=\\frac{n_1}{n2} \\\\\nk_{imag}=\\frac{\\omega \\epsilon_r^{\\prime \\prime}}{2c\\sqrt{\\epsilon_r^\\prime}}= \\frac{\\omega}{2c}\\sqrt{\\epsilon_r^\\prime}\\tan{\\delta} \\\\\ndB = 8.69 \\times k_{imag}\n\\end{align}\n\\section{Ch. 8 Schrodinger's Equation}\n\\begin{align}\n\\textbf{Planck's constant} \\quad \\hbar = \\frac{h}{2 \\pi} \\\\\n1.6 \\times 10^{-19}J= 1 eV\t\\\\\np = \\frac{h}{\\lambda} \\\\\nE = \\frac{\\hbar^2 k^2}{2m}= \\frac{n^2h^2}{8mL^2} \\\\\nk=(2mE)^{1/2}h^{-1}\t\\\\\n\\int_{0}^{L} \\psi^2 dz = 1 = A_n^2 \\int_{0}^{L} sin^2(n \\pi z /L) dz = \\frac{A_n^2}{2}L \\\\\n<S> = \\frac{\\int \\psi^*S\\psi dV}{\\int \\psi^*\\psi dV}=\\int \\psi^*S\\psi dV\n\\end{align}\nThe wavefunction y is complex valued\n• We interpret the absolute value of y squared\n(i.e., $\\psi \\times \\psi^*$) as the probability that the\nparticle is in a given position\n• This requires appropriate normalization over\nspace so that the total probability that the\nparticle is anywhere is 1 (i.e., the particle\nexists)\n\\section{Ch. 12 Free Electron Theory of Metals}\n\\begin{align}\n\\textbf{1D Box:} \\quad k_F = \\frac{N \\pi}{2 L} \\\\\nE_F=\\frac{\\hbar^2k_F^2}{2m}=\n\\frac{h^2}{32m}\\left(\\frac\n{N}{L}\\right)^2 \\\\\nZ(E)=\\frac{dN(E)}{dE}= CE^{-1/2} \\\\\n\\textbf{2D Box:} \\quad k_F^2 = 2 \\pi \\frac{N}{L^2} \\\\\nE_F=\\frac{\\hbar^2k_F^2}{2m}=\n\\frac{h^2}{4 \\pi m}\\frac\n{N}{L^2}\t\\\\\nZ(E)=\\frac{dN(E)}{dE}= C \\\\\n\\textbf{3D Box:} \\quad k_F^3 = 3 \\pi^2 \\frac{N}{L^3} \\\\\nE_F=\\frac{\\hbar^2k_F^2}{2m}=\n\\frac{h^2}{2m}\\left(\\frac\n{3N}{8 \\pi L^3}\\right)^{2/3} \\\\\n\\quad Z(E)=\\frac{dN(E)}{dE}= \\frac{4\\pi L^3 (2m)^{3/2}}{h^3}\nE^{1/2}=CE^{1/2}\n\\end{align}\n\\subsection{Fermi Distribution}\n\\begin{align}\nF(E)= 1 \\ if \\ E < E_F \\\\\nF(E)= 0 \\ if \\ E > E_F \\\\\nF(E)= \\frac{1}{1+e^{\\frac{E-E_F}{k_BT}}} \\\\\nE_{tot}= \\int EZ(E)F(E)dE\n\\end{align}\n\\section{Ch. 13 Band Theory}\n\\begin{align}\nV= V_0 \\cos\\left( \\frac{2 \\pi x}{a}\\right) \\\\\nv_g = \\frac{ \\partial \\omega}{ \\partial k} =\\frac{1}{\\hbar} \\frac{ \\partial E}{\\partial k} \\\\\na = \\frac{d v_g}{ d t}= \\frac{1}{\\hbar} \\frac{ \\partial^2 E}{ \\partial k^2}\n\\frac {d k}{d t}\t\\\\\nF = \\frac {dp}{dt}= \\hbar \\frac{k}{t} \\\\\nm^*=\\frac{F}{a}=\\frac{\\hbar^2}\n{\\frac{\\partial^2 E}{\\partial k^2}}\n\\end{align}\n\\section{Ch. 14 Metals and Insulators}\n\\begin{align}\n\\sigma = \\frac{v_F^2Z(E_F)}{3}e^2\\tau_F \\\\\n\\nu = \\frac{E_g}{h}\n\\end{align}\n\\section{Ch. 15 Semiconductors}\n\\begin{align*}\n\\textbf{Total \\# of Electrons in\n\tConduction Band:} N_e = N_c \\cdot e^{\\left(\\frac{E_c-E_F}{k_BT}\\right)} \\\\\nN_c = 2 \\left[\\frac{2\\pi m_e^*kT}{h^2}^{3/2}\\right] \\\\\n\\textbf{Total \\# of Hole in\n\tValence Band:} \\quad N_h = N_v \\cdot e^{\\left(\\frac{E_F-E_v}{k_BT}\\right)} \\\\\nN_v = 2 \\left[\\frac{2\\pi m_h^*kT}{h^2}^{3/2}\\right] \\\\\nE_f=E_v+\\frac{E_g}{2}-\\frac{1}{2}kTln\\left(\\frac{N_c}{N-V}\\right)=\nE_v+\\frac{E_g}{2}-\\frac{3}{4}kTln\\left(\\frac{m_e^*}{m_h^*}\\right) \\\\\n\\textbf{Total Conductivity:} \\quad \\sigma =e(N_e\\mu_e+\nN_h\\mu_h)=eN_e(\\mu_e+\\mu_h) \\\\\n\\text{Einstein's Relation(Ch.16.3 Diffusion Current)} \\quad \\frac{D_h}{\\mu_h} = \\frac{k_bT}{e} \n\\end{align*}  $N_i$ = Intrinsic Carrier Density. For an Intrinsic semiconductor holes = electrons\n$N_i^2=N_vN_c\\exp(-E_g/(kT))$. \\\\ n-type: $N_e \\approx N_D \\quad and \\quad N_h \\approx \\frac{N_i^2}{N_D}$ Minority carrier in %n-type is\nholes \\\\\np-type: $N_h \\approx N_A \\ \\ and \\ \\ N_e \\approx \\frac{N_i^2}{N_A}$\nMinority\ncarrier %in p-type\nis\nelectrons\n\\end{multicols}", "meta": {"hexsha": "67a51aab085457c8aa091bf3f35f5b4d27045492", "size": 5578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/CheatSheets/ELEC220Cheat.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/ELEC220Cheat.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/ELEC220Cheat.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": 39.006993007, "max_line_length": 167, "alphanum_fraction": 0.6258515597, "num_tokens": 2399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6734393265244067}}
{"text": "\\section{Floquet-Drude Conductivity in Quantum Hall Systems}\n\nThe general expression for the conductivity [*Ref: Martin Wackerl Thesis 1.250] with the disorder averaging can be represent as follows\n\\begin{equation} \\label{7.1}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] &=\n    \\frac{-1}{4\\pi\\hbar A}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\\\\n    & \\times\n    \\tr\n    \\qty[\n    {j}^x_0\n    \\qty(\n    \\mb{G}^{r} (\\varepsilon) - \\mb{G}^{a} (\\varepsilon)\n    )\n    {j}^x_0\n    \\qty(\n    \\mb{G}^{r}_0 (\\varepsilon) - \\mb{G}^{a}_0 (\\varepsilon)\n    )\n    ].\n  \\end{aligned}\n\\end{equation}\nwhere ${j}^x_0$ and $\\mb{G}^{r,a} (\\varepsilon)$ are $x$ directional current operator matrix and white noise disorder averaged Green function matrix respectvely defined against to the \\textit{Floquet modes} of the system. Here we have assumed that only $s=0$ Fourier component of the current operator is contributing to the conductivity.\n\n\\noindent\nNow this can be expand in off resonant regime ($\\omega\\tau_0 \\gg 1$)using only central entry Fourier components ($l=l'=0$) of \\textit{Floquet modes} mentioned in Eq. \\eqref{6.1} as\n\\begin{equation} \\label{7.2}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{-1}{4\\pi\\hbar A}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\\\\n    & \\times\n    \\frac{1}{V_{k_x}} \\sum_{k_x}\n    \\sum_{n}\n    \\mel{n,k_x}{\n    {j}^x_0\n    \\qty(\n    \\mb{G}^{r} (\\varepsilon) - \\mb{G}^{a} (\\varepsilon)\n    )\n    {j}^x_0\n    \\qty(\n    \\mb{G}^{r}_0 (\\varepsilon) - \\mb{G}^{a}_0 (\\varepsilon)\n    )\n    }\n    {n,k_x}\n  \\end{aligned}\n\\end{equation}\nand one can evaluate these matrix elements as follows\n\\begin{equation} \\label{7.3}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{-1}{4\\pi\\hbar A}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\frac{1}{V_{k_x}} \\sum_{k_x} \\sum_{n}\n    \\frac{1}{{L_x}^3} \\sum_{{k_x}_1,{k_x}_2,{k_x}_3}\n    \\sum_{n_1,n_2,n_3}\n    \\\\\n    & \\times\n    \\mel{n,k_x}{\n    {j}^x_0}\n    {n_1,{k_x}_1}\n    \\mel{{n_1,{k_x}_1}}{\n    \\qty(\n    \\mb{G}^{r} (\\varepsilon) - \\mb{G}^{a} (\\varepsilon)\n    )}\n    {n_2,{k_x}_2} \\\\\n    & \\times\n    \\mel{n_2,{k_x}_2}{\n    {j}^x_0}\n    {n_3,{k_x}_3}\n    \\mel{n_3,{k_x}_3}{\n    \\qty(\n    \\mb{G}^{r} (\\varepsilon) - \\mb{G}^{a} (\\varepsilon)\n    )\n    }\n    {n,k_x}\n  \\end{aligned}\n\\end{equation}\nSince we can diagonalize the impurity averaged Green's function using unitary trasnformation ($\\mb{T} = \\ket{n,k_x}$) [*Ref: Martin Wackerl - Paper] and we can evaluate the matrix element of differece between retarded and advanced Green's function as follows\n[*Ref: My report 2.535]\n\\begin{equation} \\label{7.4}\n  \\mel{{n_1,{k_x}_1}}{\n  \\mb{T}^{\\dagger}\n  \\qty(\n  \\mb{G}^{r} (\\varepsilon) - \\mb{G}^{a} (\\varepsilon)\n  )\\mb{T}}\n  {n_2,{k_x}_2} =\n  \\qty[\n  \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})\n  \\delta_{n_1,n_2}\\delta_{{k_x}_1,{k_x}_2}}\n  {\n  \\qty(\n  \\frac{1}{\\hbar}\\varepsilon -\n  \\frac{1}{\\hbar}\\varepsilon_{n_1}\n  )^2\n  + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})]^2\n  }]\n\\end{equation}\nand\n\\begin{equation} \\label{7.5}\n  \\mel{{n_3,{k_x}_3}}{\n  \\mb{T}^{\\dagger}\n  \\qty(\n  \\mb{G}^{r} (\\varepsilon) - \\mb{G}^{a} (\\varepsilon)\n  )\\mb{T}}\n  {n,{k_x}} =\n  \\qty[\n  \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})\n  \\delta_{n_3,n}\\delta_{{k_x}_3,{k_x}}}\n  {\n  \\qty(\n  \\frac{1}{\\hbar}\\varepsilon -\n  \\frac{1}{\\hbar}\\varepsilon_{n}\n  )^2\n  + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})]^2\n  }]\n\\end{equation}\n\n\\noindent\nThen appying the results we derived in previous section \\eqref{6.17} we can calculate the conductivity\n\\begin{equation} \\label{7.6}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{-1}{4\\pi\\hbar A}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\frac{1}{V_{k_x}} \\sum_{k_x} \\sum_{n}\n    \\frac{1}{{V_{k_x}}^3} \\sum_{{k_x}_1,{k_x}_2,{k_x}_3}\n    \\sum_{n_1,n_2,n_3}\n    \\\\\n    & \\times\n    \\frac{e^2B}{{m_e}}\n    \\delta_{k_x,{k_x}_1}\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n_1,n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n_1,n-1})\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})\n    \\delta_{n_1,n_2}\\delta_{{k_x}_1,{k_x}_2}}\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n_1}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})]^2\n    }] \\\\\n    & \\times\n    \\frac{e^2B}{{m_e}}\n    \\delta_{{k_x}_2,{k_x}_3}\n    \\qty(\\sqrt{\\frac{n_2+1}{2}} \\delta_{n_3,n_2+1} + \\sqrt{\\frac{n_2}{2}}\n    \\delta_{n_3,n_2-1})\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})\n    \\delta_{n_3,n}\\delta_{{k_x}_3,{k_x}}}\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})]^2\n    }]\n  \\end{aligned}\n\\end{equation}\nand this will be modified to\n\\begin{equation} \\label{7.7}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{-1}{4\\pi\\hbar A}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\frac{1}{V_{k_x}} \\sum_{k_x} \\sum_{n}\n    \\sum_{n_1,n_2}\n    \\\\\n    & \\times\n    \\frac{e^2B}{{m_e}}\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n_1,n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n_1,n-1})\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})\n    \\delta_{n_1,n_2}}\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n_1}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})]^2\n    }] \\\\\n    & \\times\n    \\frac{e^2B}{{m_e}}\n    \\qty(\\sqrt{\\frac{n_2+1}{2}} \\delta_{n,n_2+1} + \\sqrt{\\frac{n_2}{2}}\n    \\delta_{n,n_2-1})\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})]^2\n    }]\n  \\end{aligned}\n\\end{equation}\nand the only non-zero term would be\n\\begin{equation} \\label{7.8}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{-1}{4\\pi\\hbar A}\n    \\frac{e^4B^2}{{{m_e}^2}}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\frac{1}{V_{k_x}} \\sum_{k_x} \\sum_{n}\n    \\qty(n+1)\n    \\\\\n    & \\times\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n+1}}\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n+1}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n+1}}]^2\n    }]\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n}}\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n}}]^2\n    }]\n  \\end{aligned}\n\\end{equation}\n\\hfill$\\blacksquare$\n\n\\noindent\nThen using the following identity derived in [*Ref: My report 2.509]\n\\begin{equation} \\label{7.9}\n  \\qty(\\frac{1}{\\tau(\\varepsilon,k_x)})_{ll} =\n  -2\\text{Im}\\qty[\\qty(\\mb{T}^{\\dagger} {\\sum}^r \\mb{T})_{\\varepsilon}]_{ll}\n\\end{equation}\nusing central element of the inverse scattering time matrix we can modify our result as\n\\begin{equation} \\label{7.10}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{1}{4\\pi\\hbar A}\n    \\frac{e^4B^2}{{{m_e}^2}}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\frac{1}{V_{k_x}} \\sum_{k_x} \\sum_{n}\n    \\qty(n+1)\n    \\\\\n    & \\times\n    \\qty[\n    \\frac{\\qty(\\frac{1}{\\tau(\\varepsilon_{n+1},k_x)})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n+1}\n    )^2\n    + \\qty(\\frac{1}{2\\tau(\\varepsilon_{n+1},k_x)})^2\n    }]\n    \\qty[\n    \\frac{\\qty(\\frac{1}{\\tau(\\varepsilon_{n},k_x)})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty(\\frac{1}{2\\tau(\\varepsilon_{n},k_x)})^2\n    }]\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nWe have identited that the inverse scattering time matrix's central element is not $k_x$ dependent we can get the sum over all available momentum space in $x$ direction. However by considering the condition that the center of the force of the oscillator $y_0$ must physically liw within the system $-L_y/2 < y_0 < L_y/2$, one can derive that\n\\begin{equation} \\label{7.11}\n -\\frac{m_e\\omega_0 Ly}{2\\hbar} \\leq k_x \\leq \\frac{m_e\\omega_0 Ly}{2\\hbar}\n\\end{equation}\nand we can derive that\n\\begin{equation} \\label{7.12}\n    \\frac{1}{V_{k_x}}\\sum_{k_x} = \\frac{m_e\\omega_0 Ly}{\\hbar V_{k_x}} = 1\n\\end{equation}\nThefore Eq. \\eqref{7.10} modified to\n\\begin{equation} \\label{7.13}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{e^2 \\omega_0^2}{4\\pi\\hbar A}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\sum_{n}\n    \\qty(n+1)\n    \\\\\n    & \\times\n    \\qty[\n    \\frac{\\qty(\\frac{1}{\\tau(\\varepsilon_{n+1})})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n+1}\n    )^2\n    + \\qty(\\frac{1}{2\\tau(\\varepsilon_{n+1})})^2\n    }]\n    \\qty[\n    \\frac{\\qty(\\frac{1}{\\tau(\\varepsilon_{n})})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty(\\frac{1}{2\\tau(\\varepsilon_{n})})^2\n    }]\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nThen using Fermi-Dirac distribution as our partical distribution function ($f$) for this system\n\\begin{equation} \\label{7.14}\n  f(\\varepsilon) = \\frac{1}{\\qty[\\exp(\\varepsilon - \\varepsilon_F)/k_B T]+1}\n\\end{equation}\nwhere $k_B$ is Botlzmann constant, $T$ is absolute tempurature and $\\varepsilon_F$ is Fermi energy of the system. Using above distribution, for extreamly low tempuratures we can appromixate that\n\\begin{equation} \\label{7.15}\n  - \\pdv{f(\\varepsilon)}{\\varepsilon} \\approx \\delta(\\varepsilon - \\varepsilon_F)\n\\end{equation}\nand this will mpre simplify our derivation of conductivity as\n\\begin{equation} \\label{7.16}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{e^2 \\omega_0^2}{4\\pi\\hbar A}\n    \\sum_{n}\n    \\qty(n+1)\n    \\qty[\n    \\frac{\\qty(\\frac{1}{\\tau(\\varepsilon_{n+1})})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon_F -\n    \\frac{1}{\\hbar}\\varepsilon_{n+1}\n    )^2\n    + \\qty(\\frac{1}{2\\tau(\\varepsilon_{n+1})})^2\n    }]\n    \\qty[\n    \\frac{\\qty(\\frac{1}{\\tau(\\varepsilon_{n})})\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon_F -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty(\\frac{1}{2\\tau(\\varepsilon_{n})})^2\n    }]\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nNow introduce a new paramter with a physical meaning od scattering-induced broading of the Landau level as follows\n\\begin{equation} \\label{6.17}\n  \\Gamma_n \\equiv\\Gamma(\\varepsilon_n) \\equiv \\qty(\\frac{\\hbar }{2\\tau(\\varepsilon_n)})\n\\end{equation}\nand then we can re-write Eq. \\eqref{7.16} as follows\n\\begin{equation} \\label{7.18}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{e^2 (\\hbar\\omega_0)^2}{\\pi\\hbar A}\n    \\sum_{n}\n    \\qty(n+1)\n    \\qty[\n    \\frac{\\Gamma(\\varepsilon_{n+1})\n    }\n    {\n    \\qty(\n    \\varepsilon_F - \\varepsilon_{n+1}\n    )^2\n    + \\Gamma^2(\\varepsilon_{n+1})\n    }]\n    \\qty[\n    \\frac{\\Gamma(\\varepsilon_{n})\n    }\n    {\n    \\qty(\n    \\varepsilon_F - \\varepsilon_{n}\n    )^2\n    + \\Gamma^2(\\varepsilon_{n})\n    }]\n  \\end{aligned}\n\\end{equation}\n\\begin{equation} \\label{7.19}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{e^2 (\\hbar\\omega_0)^2}{\\pi\\hbar A}\n    \\sum_{n}\n    \\qty(n+1)\n    \\qty[\n    \\frac{\\Gamma_{n+1}\n    }\n    {\n    \\qty(\n    \\varepsilon_F - \\varepsilon_{n+1}\n    )^2\n    + \\Gamma^2_{n+1}\n    }]\n    \\qty[\n    \\frac{\\Gamma_{n}\n    }\n    {\n    \\qty(\n    \\varepsilon_F - \\varepsilon_{n}\n    )^2\n    + \\Gamma^2_{n}\n    }]\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nNow use new dimentionless paramters\n\\begin{equation} \\label{7.20}\n  X_F \\equiv \\frac{\\varepsilon_F}{\\hbar \\omega_0} -\\frac{1}{2}\n\\end{equation}\nand\n\\begin{equation} \\label{7.21}\n  \\gamma_n \\equiv \\frac{\\Gamma_n}{\\hbar \\omega_0}.\n\\end{equation}\nTherefore the Eq. \\eqref{7.19} leads to\n\\begin{equation} \\label{7.22}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{e^2}{\\hbar}\n    \\frac{1}{\\pi A}\n    \\sum_{n}\n    \\qty(n+1)\n    \\qty[\n    \\frac{\\gamma_{n+1}\n    }\n    {\n    \\qty(\n    X_F - n - 1\n    )^2\n    + \\gamma^2_{n+1}\n    }]\n    \\qty[\n    \\frac{\\gamma_{n}\n    }\n    {\n    \\qty(\n    X_F - n\n    )^2\n    + \\gamma^2_{n}\n    }]\n  \\end{aligned}\n\\end{equation}\nand\n\\begin{equation} \\label{7.23}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{xx}(0,\\omega)] & =\n    \\frac{e^2}{\\hbar}\n    \\frac{1}{\\pi A}\n    \\sum_{n}\n    \\frac{\\qty(n+1)}{\\gamma_{n}\\gamma_{n+1}}\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n -1}{\\gamma_{n+1}})^2\n      }\n    ]\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n}{\\gamma_{n}})^2\n      }\n    ]\n  \\end{aligned}\n\\end{equation}\n\\hfill$\\blacksquare$\n\n\\noindent\nSame as above derivation we can derive the transverse conductivity in $y$ direction by using the current operator derived in Eq. \\eqref{6.27} as follows\n\\begin{equation} \\label{7.24}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{yy}(0,\\omega)] & =\n    \\frac{1}{4\\pi\\hbar A}\n    \\frac{e^2\\hbar^2}{{m^2}}\n    \\int_{\\lambda-\\hbar\\Omega/2}^{\\lambda+ \\hbar\\Omega/2} d\\varepsilon\n    \\qty(\n    -\\frac{\\partial f}{\\partial \\varepsilon})\n    \\frac{1}{V_{k_x}} \\sum_{k_x} \\sum_{n}\n    -\\qty(n+1)\n    \\\\\n    & \\times\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n+1}}\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n+1}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n+1}}]^2\n    }]\n    \\qty[\n    \\frac{2i \\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n}}\n    }\n    {\n    \\qty(\n    \\frac{1}{\\hbar}\\varepsilon -\n    \\frac{1}{\\hbar}\\varepsilon_{n}\n    )^2\n    + \\qty[\\text{Im}\\qty(\\mb{T}^{\\dagger} \\sum^r \\mb{T})_{\\varepsilon_{n}}]^2\n    }]\n  \\end{aligned}\n\\end{equation}\nand same as above derivation this can be simplified into\n\\begin{equation} \\label{7.25}\n  \\begin{aligned}\n    \\lim_{\\omega \\to 0}\n    \\text{Re}[{\\sigma}^{yy}(0,\\omega)] & =\n    \\frac{e^2}{\\hbar}\n    \\frac{1}{\\pi A}\n    \\frac{1}{e^2B^2}\n    \\sum_{n}\n    \\frac{\\qty(n+1)}{\\gamma_{n}\\gamma_{n+1}}\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n -1}{\\gamma_{n+1}})^2\n      }\n    ]\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n}{\\gamma_{n}})^2\n      }\n    ]\n  \\end{aligned}\n\\end{equation}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\hfill$\\blacksquare$\n", "meta": {"hexsha": "ae42c5272e1b4b71894d332e2da2b2a23e8e91e9", "size": 15375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_07.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_07.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_07.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": 26.372212693, "max_line_length": 341, "alphanum_fraction": 0.561495935, "num_tokens": 6447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679977, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6734097994583509}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{mathtools}\n\\usepackage{soul}\n\\usepackage{float}\n\\usepackage{listings}\n\n\\title{Types and Programming Languages (Pierce)}\n\\author{Bruno Flores}\n\\date{September 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Untyped Arithmetic Expressions}\n\n\\subsection{Syntax}\n\n\\begin{figure}[h!]\n    \\begin{verbatim}\n        t ::=\n            true\n            false\n            if t then t else t\n            0\n            succ t\n            pred t\n            iszero t\n    \\end{verbatim}\n    \\caption{BNF}\n\\end{figure}\n\n\\begin{figure}[h!]\n    \\begin{enumerate}\n        \\item \\{\\texttt{true, false, 0}\\} \\(\\subseteq\\) \\(\\mathcal{T}\\);\n        \\item \n            if \\texttt{t\\(_1\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\), \n            then \\{\\texttt{succ t\\(_1\\), pred t\\(_1\\), iszero t\\(_1\\)}\\} \\(\\subseteq\\) \\(\\mathcal{T}\\);\n        \\item \n            if \\texttt{t\\(_1\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\), \\texttt{t\\(_2\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\),\n            and \\texttt{t\\(_3\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\), \n            then \\texttt{if t\\(_1\\) then t\\(_2\\) else t\\(_3\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\).\n    \\end{enumerate}\n    \\caption{Terms, inductively}\n\\end{figure}\n\n\\begin{table}[h!]\n    \\centering\n    \\begin{tabular}{c c c}\n         \\texttt{true} \\(\\subseteq\\) \\(\\mathcal{T}\\) & \\texttt{false} \\(\\subseteq\\) \\(\\mathcal{T}\\) & \\texttt{0} \\(\\subseteq\\) \\(\\mathcal{T}\\) \\\\\n         \\\\\n         \\begin{tabular}{c}\n              t\\(_1\\) \\(\\subseteq\\) \\(\\mathcal{T}\\) \\\\\n              \\hline\n              \\texttt{succ t\\(_1\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\)\n         \\end{tabular} & \\begin{tabular}{c}\n              t\\(_1\\) \\(\\subseteq\\) \\(\\mathcal{T}\\) \\\\\n              \\hline\n              \\texttt{pred t\\(_1\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\)\n         \\end{tabular} & \\begin{tabular}{c}\n              t\\(_1\\) \\(\\subseteq\\) \\(\\mathcal{T}\\) \\\\\n              \\hline\n              \\texttt{iszero t\\(_1\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\)\n         \\end{tabular} \\\\\n         \\\\\n         \\multicolumn{3}{c}{\n             \\begin{tabular}{c}\n                  t\\(_1\\) \\(\\subseteq\\) \\(\\mathcal{T}\\) t\\(_2\\) \\(\\subseteq\\) \\(\\mathcal{T}\\) t\\(_3\\) \\(\\subseteq\\) \\(\\mathcal{T}\\) \\\\\n                  \\hline\n                  \\texttt{if t\\(_1\\) then t\\(_2\\) else t\\(_3\\)} \\(\\subseteq\\) \\(\\mathcal{T}\\)\n             \\end{tabular}\n         }\n    \\end{tabular}\n    \\caption{Terms, by inference rules}\n    \\label{tab:my_label}\n\\end{table}\n\n\\begin{table}[h!]\n    \\centering\n    \\begin{tabular}{l l l l}\n        S\\(_0\\) & = & \\(\\emptyset\\) & \\\\\n        S\\(_{\\textit{i}+1}\\) & = & & \\{\\texttt{true, false, 0}\\} \\\\\n        & & \\(\\cup\\) & \\{\\texttt{succ t\\(_1\\), pred t\\(_1\\), iszero t\\(_1\\)} \\(|\\) \\texttt{t\\(_1\\)} \\(\\in\\) S\\(_i\\)\\} \\\\\n        & & \\(\\cup\\) & \\{\\texttt{if t\\(_1\\) then t\\(_2\\) else t\\(_3\\)} \\(|\\) \\texttt{t\\(_1\\), t\\(_2\\), t\\(_3\\)} \\(\\in\\) S\\(_i\\)\\}\n    \\end{tabular}\n    \\caption{Terms, concretely}\n\\end{table}\n\nLet\n\n\\begin{center}\n    S = \\(\\underset{i}{\\text{\\Large\\(\\cup\\)}}\\) S\\(_i\\).\n\\end{center}\n\nS\\(_0\\) is empty; S\\(_1\\) contains just the constants; S\\(_2\\) contains the constants plus the phrases that can be built with constants and just one \\texttt{succ, pred, iszero}, or \\texttt{if}; S\\(_3\\) contains these and all phrases that can be built using \\texttt{succ, pred, iszero}, and \\texttt{if} on phrases in S\\(_2\\); and so on. \\hl{S collects together all the phrases that can be built this way.}\n\n\\subsection{Semantics}\n\n\\textit{Operational semantics} specifies the behaviour of a programming language by defining a simple \\textit{abstract machine} for it. This machine is \"abstract\" in the sense that it uses the terms of the language as its machine code, rather than some low-level microprocessor instruction set. For simple languages, a \\textit{state} of the machine is just a term, and the machine's behaviour is defined by a \\textit{transition function} that, for each state, either gives the next state by performing a step of simplification on the term or declares that the machine has halted. The \\textit{meaning} of a term \\texttt{t} can be taken to be the final state that the machine reaches when started with \\texttt{t} as its initial state.\n\n\\hl{Strictly speaking, the above describes the \\textit{small-step} style of operational semantics.}\n\n\\subsubsection{Run-time error}\n\nFrom the concept of \"stuckness\". Intuitively, it characterises situations where the operational semantics does not know what to do because the program has reached a \"meaningless state\".\n\n\\paragraph{Definition} A closed term is \\textit{stuck} if it is in normal form but not a value.\n\n\\end{document}", "meta": {"hexsha": "56383b0f10b1450ea4a32dcd7b8c3e5c3aad824a", "size": 4635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text.tex", "max_stars_repo_name": "brunoflores/arith", "max_stars_repo_head_hexsha": "279a32f8615e8b4cbf2d61ab76bb1970775670e1", "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": "text.tex", "max_issues_repo_name": "brunoflores/arith", "max_issues_repo_head_hexsha": "279a32f8615e8b4cbf2d61ab76bb1970775670e1", "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": "text.tex", "max_forks_repo_name": "brunoflores/arith", "max_forks_repo_head_hexsha": "279a32f8615e8b4cbf2d61ab76bb1970775670e1", "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": 42.1363636364, "max_line_length": 732, "alphanum_fraction": 0.5823085221, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.6733822864049694}}
{"text": "\\input{../../style/preamble}\n\\input{../../latex-math/basic-math}\n\\input{../../latex-math/basic-ml}\n\n\\newcommand{\\titlefigure}{figure_man/entropy.png}\n\\newcommand{\\learninggoals}{\n  \\item Know the joint entropy\n  \\item Know conditional entropy as remaining uncertainty \n  \\item Know mutual information as the amount of information of an RV obtained by another\n}\n\n\\title{Introduction to Machine Learning}\n\\date{}\n\n\\begin{document}\n\n\\lecturechapter{Joint Entropy and Mutual Information}\n\\lecture{Introduction to Machine Learning}\n\n\n\\begin{vbframe}{Joint entropy}\n\\begin{itemize}\n  \\item The \\textbf{joint entropy} of two discrete random variables $X$ and $Y$ with a joint distribution $p(x, y)$ is:\n  $$ H(X,Y) = -\\sum_{x \\in \\Xspace} \\sum_{y \\in \\Yspace}  p(x,y) \\log(p(x,y)),$$ \n  which can also be expressed as $$ H(X,Y) = -\\E \\left[ \\log(p(X,Y)) \\right].$$\n  % where $I(x,y)$ is the self-information of $(x,y)$.\n  % \\item Intuitively, the joint entropy is a measure of the total uncertainty in the two variables $X$ and $Y$. In other words, it is simply the entropy of the joint distribution p(x,y).\n  % \\item $H(X,Y)$ is always non-negative.\n  %\\item $H(X,Y) \\leq H(X) + H(Y)$, with equality if $X$ and $Y$ are independent.\n  % \\framebreak\n  % \\item More generally,\n  % \\begin{footnotesize}\n  % $$ H(X_1, X_2, \\ldots, X_n) = - \\sum_{x_1 \\in \\Xspace_1} \\ldots \\sum_{x_n \\in \\Xspace_n} p(x_1,x_2, \\ldots, x_n) \\log_2(p(x_1,x_2, \\ldots, x_n)) $$ \n  % \\end{footnotesize}\n  \\item For continuous random variables $X$ and $Y$ with joint density $p(x,y)$, the differential joint entropy is:\\\\\n  $$ h(X,Y) = - \\int_{\\Xspace,\\Yspace} p(x,y) \\ln p(x,y) dx dy$$\n\\end{itemize}\n\n\\begin{footnotesize}\nFor the rest of the section we will stick to the discrete case. Pretty much everything we show and discuss works in a completely analogous manner for the continuous case - if you change sums to integrals.\n\\end{footnotesize}\n\n\\end{vbframe}\n\n\\begin{vbframe}{Conditional entropy}\n\\begin{itemize}\n\n\\item The \\textbf{conditional entropy} $H(Y|X)$ quantifies the uncertainty of $Y$ that remains if the outcome of $X$ is given.\n\n\\item $H(Y|X)$ is defined as the expected value of the entropies of the conditional distributions, averaged over the conditioning RV.\n\\item If $(X, Y) \\sim p(x, y)$, the conditional entropy $H (Y|X)$ is defined as\n\n% $$\n% H(Y|X) = \\sum_{x \\in \\Xspace} p_x(x) H(Y|X=x) \\overset{(*)}{=} H(Y, X) - H(X).\n% $$\n\n\\vspace{-0.2cm}\n\\footnotesize\n\\begin{equation*}\\begin{aligned}\nH(Y | X) &= \\E_X[H(Y|X=x)] = \\sum_{x \\in \\Xspace} p(x) H(Y | X=x) \\\\\n&=-\\sum_{x \\in \\Xspace} p(x) \\sum_{y \\in \\Yspace} p(y | x) \\log p(y | x) \\\\\n&=-\\sum_{x \\in \\Xspace} \\sum_{y \\in \\Yspace} p(x, y) \\log p(y | x) \\\\\n&=-\\E \\left[\\log p(Y | X) \\right]. \n\\end{aligned}\\end{equation*}\n\\normalsize\n\n\\item For the continuous case with density $f$ we have $$h(Y|X) = - \\int f(x,y) \\log f(x|y) dx dy.$$\n\\end{itemize}\n\n\\end{vbframe}\n\n\n\n\\begin{vbframe} {Chain rule for entropy}\nThe \\textbf{chain rule for entropy} is analogous to the chain rule for probability and, in fact, derives directly from it.\n$$H(X, Y)=H(X)+H(Y | X)$$\n\\footnotesize\n\\textbf{Proof:}\n%\\begin{equation*}\n$\\begin{aligned}[t]\nH(X, Y) &=-\\sum_{x \\in \\mathcal{X}} \\sum_{y \\in \\mathcal{Y}} p(x, y) \\log p(x, y) \\\\\n&=-\\sum_{x \\in \\mathcal{X}} \\sum_{y \\in \\mathcal{Y}} p(x, y) \\log p(x) p(y | x) \\\\\n&=-\\sum_{x \\in \\mathcal{X}} \\sum_{y \\in \\mathcal{Y}} p(x, y) \\log p(x)-\\sum_{x \\in \\mathcal{X}} \\sum_{y \\in \\mathcal{Y}} p(x, y) \\log p(y | x) \\\\\n&=-\\sum_{x \\in \\mathcal{X}} p(x) \\log p(x)-\\sum_{x \\in \\mathcal{X}} \\sum_{y \\in \\mathcal{Y}} p(x, y) \\log p(y | x) \\\\\n&=H(X)+H(Y | X)\n\\end{aligned}\n$\n\\normalsize\n%\\end{equation*}\n\n\\lz\n\nn-Variable version:\n$$H\\left(X_{1}, X_{2}, \\ldots, X_{n}\\right)=\\sumin H\\left(X_{i} | X_{i-1}, \\ldots, X_{1}\\right).$$\n\n\n%\\log p(X, Y)=\\log p(X)+\\log p(Y | X)\n\n% \\textbf{Remarks:}\n% \\begin{itemize}\n% \\item From the proof follows that: $H(X, Y | Z)=H(X | Z)+H(Y | X, Z)$\n% \\item Note that $H(Y | X) \\neq H(X | Y) ,$ although $H(X)-H(X | Y)=$\n% $H(Y)-H(Y | X).$\n% \\end{itemize}\n% \\normalsize\n\n  % \\begin{itemize}\n  %   \\item The \\textbf{chain rule for entropy} is analogous to the chain rule for probability and, in fact, derives directly from it.\n  %   \\item Using $p(x,y) = p(x|y)p(y) = p(y|x)p(x)$, the \\enquote{self-information chain rule} is:\n  % \\end{itemize}\n  %   \\begin{equation*}\n  %     \\begin{array}{c}{-\\log _{2} p(x, y)=-\\log _{2} p(x | y)-\\log _{2} p(y)=-\\log _{2} p(y | x)-\\log _{2} p(x)} \\\\ {I(x, y)=I(x | y)+I(y)=I(y | x)+I(x)}\n  %     \\end{array}\n  % \\end{equation*}\n  % \\begin{itemize}\n  %   \\item Taking the expectation, we arrive at the chain rule:\n  % \n  %  \\begin{equation*}\n  %    \\begin{aligned} \n  %      \\mathbb{E}_{X, Y}[I(X, Y)] &=\\mathbb{E}_{X, Y}[I(X | Y)]+\\mathbb{E}_{X, Y}[I(Y)] \\\\ &=\\mathbb{E}_{X, Y}[I(Y | X)]+\\mathbb{E}_{X, Y}[I(X)] \\Longleftrightarrow \\\\ H(X, Y) &=H(X | Y)+H(Y) \\\\ &=H(Y | X)+H(X)\n  %    \\end{aligned}\n  %  \\end{equation*}\n  %  where $H(X | Y)$ and $H(Y | X)$ are the \\textbf{conditional entropies.}\n  % \\end{itemize}\n\\end{vbframe}\n\n% \\begin{vbframe} {Chain rule for entropy (n variables)}\n\n\n% For the case of n variables, let $X_{1}, X_{2}, \\ldots, X_{n}$ be drawn according to $p\\left(x_{1}, x_{2}, \\ldots, x_{n}\\right).$ Then\n\n% $$H\\left(X_{1}, X_{2}, \\ldots, X_{n}\\right)=\\sumin H\\left(X_{i} | X_{i-1}, \\ldots, X_{1}\\right).$$\n\n% \\textbf{Proof:$\\quad$} By repeated application of the two-variable expansion rule for entropies, we have\n\n% \\footnotesize\n% \\begin{equation*}\n% \\begin{aligned}\n% H\\left(X_{1}, X_{2}\\right) &=H\\left(X_{1}\\right)+H\\left(X_{2} | X_{1}\\right) \\\\\n% H\\left(X_{1}, X_{2}, X_{3}\\right) &=H\\left(X_{1}\\right)+H\\left(X_{2}, X_{3} | X_{1}\\right)\n% \\\\\n% \\vdots \\\\\n% &=H\\left(X_{1}\\right)+H\\left(X_{2} | X_{1}\\right)+H\\left(X_{3} | X_{2}, X_{1}\\right)\\\\\n% H\\left(X_{1}, X_{2}, \\ldots, X_{n}\\right) &=H\\left(X_{1}\\right)+H\\left(X_{2} | X_{1}\\right)+\\cdots+H\\left(X_{n} | X_{n-1}, \\ldots, X_{1}\\right) \\\\\n% &=\\sumin H\\left(X_{i} | X_{i-1}, \\ldots, X_{1}\\right).\n% \\end{aligned}\n% \\end{equation*}\n% \\normalsize\n% \\end{vbframe}\n\n\\begin{vbframe} {Joint and Conditional entropy}\n\nThe following relations hold:\n\n\\begin{equation*}\n\\begin{aligned}\nH(X, X)       &= H(X)  \\\\\nH(X | X)      &= 0  \\\\\nH(X, Y | Z)   &=H(X | Z)+H(Y | X, Z)\\\\\n\\end{aligned}\n\\end{equation*}\n\nWhich can all be trivially derived from the previous considerations.\n\n\\lz\n\nFurthermore, if $H(X|Y) = 0$, then $X$ is a function of $Y$, so for all $x$ with $p(x)>0$, there is only one $y$ with $p(x,y)>0$. \nProof is not hard, but also not completely trivial.\n\\end{vbframe}\n\n\\begin{vbframe} {Mutual information}\n\n%The \\textbf{relative entropy} $D(p||q)$ (or Kullback-Leibler distance) is a measure of the inefficiency of assuming that the distribution is $q$ when the true distribution is $p$: \n% \n% \\footnotesize\n% \\begin{equation*}\\begin{aligned}\n% D(p \\| q) &=\\sum_{x \\in \\Xspace} p(x) \\log \\frac{p(x)}{q(x)} \n% =\\E_{p} \\log \\frac{p(X)}{q(X)}\n% \\end{aligned}\\end{equation*}\n% \\normalsize\n\n\\begin{itemize}\n\\item The MI describes the amount of information about one random variable obtained through the other one or how different the joint distribution is from pure independence.\n\\item Consider two random variables $X$ and $Y$ with a joint probability mass function $p(x, y)$ and marginal probability mass functions $p(x)$ and $p(y)$. The MI $I (X;Y)$ is the Kullback-Leibler distance between the joint distribution and the product distribution $p(x)p(y)$:\n\\footnotesize\n\\begin{equation*}\\begin{aligned}\nI(X ; Y) &=\\sum_{x \\in \\Xspace} \\sum_{y \\in \\Yspace} p(x, y) \\log \\frac{p(x, y)}{p(x) p(y)} \\\\\n&=D_{KL}(p(x, y) \\| p(x) p(y)) \\\\\n&=\\E_{p(x, y)} \\left[ \\log \\frac{p(X, Y)}{p(X) p(Y)} \\right].\n\\end{aligned}\\end{equation*}\n\\normalsize\n\n\\item For two continuous random variables with joint density $f(x,y)$:\n\n\\footnotesize\n\\begin{equation*}\\begin{aligned}\nI(X ; Y) &= \\int f(x,y) \\log \\frac{f(x,y)}{f(x)f(y)} dx dy.\n\\end{aligned}\n\\end{equation*}\n\\normalsize\n\n\\end{itemize}\n\n\\end{vbframe}\n\n\\begin{vbframe} {Mutual information}\n\nWe can rewrite the definition of mutual information $I(X;Y)$ as\n\n\\begin{equation*}\\begin{aligned}\nI(X ; Y) &=\\sum_{x, y} p(x, y) \\log \\frac{p(x, y)}{p(x) p(y)} \\\\\n&=\\sum_{x, y} p(x, y) \\log \\frac{p(x | y)}{p(x)} \\\\\n&=-\\sum_{x, y} p(x, y) \\log p(x)+\\sum_{x, y} p(x, y) \\log p(x | y) \\\\\n&=-\\sum_{x} p(x) \\log p(x)-\\left(-\\sum_{x, y} p(x, y) \\log p(x | y)\\right) \\\\\n&=H(X)-H(X | Y).\n\\end{aligned}\\end{equation*}\n\nThus, mutual information $I(X;Y)$ is the reduction in the uncertainty\nof $X$ due to the knowledge of $Y$.\n\n\\end{vbframe}\n\n\\begin{vbframe} {Mutual information}\n\nThe following relations hold:\n\n\\begin{equation*}\n\\begin{aligned}\nI(X ; Y) &= H(X) - H(X | Y) \\\\\nI(X ; Y) &= H(Y) - H(Y | X) \\\\\nI(X ; Y) &= H(X) + H(Y) - H(X, Y) \\\\\nI(X ; Y) &= I(Y ; X) \\\\\nI(X ; X) &= H(X)\\\\\n\\end{aligned}\n\\end{equation*}\n\nAll of the above are trivial to prove.\n\n% The mutual information of $X$ and $Y$, $I(X;Y)$, corresponds to the intersection of the\n% information in $X$ with the information in $Y$.\n\n\\end{vbframe}\n\n\\begin{vbframe} {Mutual information - example}\n\nLet $X, Y$ have the following joint distribution:\n\n\\begin{table}[]\n  \\begin{tabular}{c|c|c|c|c|}\n    & $X_1$ & $X_2$ & $X_3$ & $X_4$ \\\\ \n    \\hline\n    $Y_1$ & $\\frac{1}{8}$ & $\\frac{1}{16}$ & $\\frac{1}{32}$ & $\\frac{1}{32}$ \\\\\n    \\hline\n    $Y_2$ & $\\frac{1}{16}$ & $\\frac{1}{8}$ & $\\frac{1}{32}$ & $\\frac{1}{32}$ \\\\\n    \\hline\n    $Y_3$ & $\\frac{1}{16}$ & $\\frac{1}{16}$ & $\\frac{1}{16}$ & $\\frac{1}{16}$ \\\\\n    \\hline\n    $Y_4$ & $\\frac{1}{4}$ & 0 & 0 & 0 \\\\\n    \\hline\n  \\end{tabular}\n\\end{table}\n\n\\lz\n\nThe marginal distribution of $X$ is $(\\frac{1}{2}, \\frac{1}{4}, \\frac{1}{8}, \\frac{1}{8})$ and the marginal distribution of $Y$ is $(\\frac{1}{4}, \\frac{1}{4}, \\frac{1}{4}, \\frac{1}{4})$, and hence $H(X) = \\frac{7}{4}$ bits and $H(Y) = 2$ bits.\n\n\\framebreak\n\nThe conditional entropy $H(X|Y)$ is given by:\n\n\\begin{equation*}\n  \\begin{aligned}\n    H(X|Y) &= \\sum_{i = 1}^4 p(Y = i) H(X | Y = i) \\\\\n    &= \\frac{1}{4} H \\left( \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{8}, \\frac{1}{8} \\right) +     \\frac{1}{4} H \\left( \\frac{1}{4}, \\frac{1}{2}, \\frac{1}{8}, \\frac{1}{8} \\right) \\\\\n    &+ \\frac{1}{4} H \\left( \\frac{1}{4}, \\frac{1}{4}, \\frac{1}{4}, \\frac{1}{4} \\right) +     \\frac{1}{4} H \\left(1,0,0,0 \\right) \\\\\n    &=  \\frac{1}{4} \\cdot \\frac{7}{4} + \\frac{1}{4} \\cdot \\frac{7}{4} + \\frac{1}{4} \\cdot     2 + \\frac{1}{4} \\cdot 0 \\\\\n    &= \\frac{11}{8} \\text{ bits}.\n  \\end{aligned}\n\\end{equation*}\n\nSimilarly, $H(Y|X) = \\frac{13}{8}$ bits and $H(X,Y) = \\frac{27}{8}$ bits.\n\n\\end{vbframe}\n\n\\begin{vbframe}{Mutual Information - Corollaries}\n\n\\small\n\n\\textbf{Non-negativity of mutual information:} For any two random variables, $X$, $Y$, $ I(X;Y) \\geq 0$, with equality if and only if $X$ and $Y$ are independent. \n\n\\lz\n\n\\textbf{Proof:}$\\quad I(X ; Y)=D_{KL}(p(x, y) \\| p(x) p(y)) \\geq 0,$ with equality if and only if $p(x, y)=p(x) p(y)$ (i.e., $X$ and $Y$ are independent).\n\n\\lz\n  \n\\textbf{Conditioning reduces entropy (information can't hurt):}\n\n$$H(X | Y) \\leq H(X),$$\nwith equality if and only if $X$ and $Y$ are independent.\n\n\\lz\n\n\\textbf{Proof:}$\\quad 0 \\leq I(X ; Y)=H(X)-H(X | Y)$\n\nIntuitively, the theorem says that knowing another random variable $Y$ can only reduce the uncertainty in $X$. Note that this is true only on the average. \n\n\\framebreak\n\n% \\textbf{Corollary:}\n\n% \\footnotesize\n% \\begin{equation*}\n% \\begin{aligned}\n% D_{KL}(p(y | x) \\| q(y | x)) &= \\sum_x p(x) \\sum_y p(y|x) \\log\\frac{p(y|x)}{q(y|x)} \\\\\n% &= \\E_{p(x,y)} \\left[ \\log\\frac{p(Y|X)}{q(Y|X)}\\right] \\\\\n% &\\geq 0\n% \\end{aligned}\n% \\end{equation*}\n% \\normalsize\n\n% with equality if and only if $p(y | x)=q(y | x)$ for all $y$ and $x$ such that $p(x)>0$.\n\n% In the continuous case with density functions $f$, $g$ and support set $S$ we have:\n\n% \\begin{equation*}\n% \\begin{aligned}\n% D_{KL}(f \\| g) \\geq 0,\n% \\end{aligned}\n% \\end{equation*}\n\n% with equality if and only if $f$ and $g$ are equal almost everywhere.\n\n% \\framebreak\n\n% \\textbf{Proof:}\n\n% \\footnotesize\n% \\begin{equation*}\n% \\begin{aligned}\n% -D_{KL}(f \\| g) &= \\int_{S} f \\log \\frac{g}{f} \\\\\n% &\\leq \\log \\int_{S} f \\frac{g}{f} \\\\\n% &= \\log \\int_{S} g \\\\\n% &\\leq \\log 1 = 0\n% \\end{aligned}\n% \\end{equation*}\n% \\normalsize\n\n% \\lz\n\n% \\textbf{Corollary:}$\\quad I(X ; Y | Z) \\geq 0$, with equality if and only if $X$ and $Y$ are conditionally independent given $Z$, where \\textbf{conditional mutual information} is defined as\n\n% \\footnotesize\n% \\begin{equation*}\n% \\begin{aligned}\n% I(X; Y | Z) &= H(X | Z) - H(X | Y, Z) \\\\\n% &= \\E_{p(x,y,z)} \\left[ \\log\\frac{p(X,Y|Z)}{p(X|Z)p(Y|Z)}\\right].\n% \\end{aligned}\n% \\end{equation*}\n% \\normalsize\n\n% \\lz\n\n%left out Theorem 2.6.4\n\n\n\\framebreak\n\n\\textbf{Independence bound on entropy:} Let $X_{1}, X_{2}, \\ldots, X_{n}$ be drawn according to $p\\left(x_{1}, x_{2}, \\ldots, x_{n}\\right) .$ Then\n\n\\footnotesize\n$$H\\left(X_{1}, X_{2}, \\ldots, X_{n}\\right) \\leq \\sum_{i=1}^{n} H\\left(X_{i}\\right),$$\n\\normalsize\n\nwith equality if and only if the $X_{i}$ are independent.\\\\\n\n\\lz\n\n\\textbf{Proof:} With the chain rule for entropies,\n\n\\footnotesize\n\\begin{equation*}\n\\begin{aligned}\nH\\left(X_{1}, X_{2}, \\ldots, X_{n}\\right) &=\\sum_{i=1}^{n} H\\left(X_{i} | X_{i-1}, \\ldots, X_{1}\\right) \n&\\leq \\sum_{i=1}^{n} H\\left(X_{i}\\right),\n\\end{aligned}\n\\end{equation*}\n\\normalsize\n\nwhere the inequality follows directly from above. We have equality if and only if $X_{i}$ is independent of $X_{i-1}, \\ldots, X_{1}$ for all $i$ (i.e., if and only if the $X_{i}$ 's are independent).\n\n\n\\end{vbframe}\n\n\\begin{vbframe} {Mutual information Properties}\n\n%%The reduction of uncertainty in $Y$ after \\textit{learning} $X$ is called \\textbf{mutual information}\n\n%By symmetry and since $H(X,Y) = H(X) + H(Y|X)$, it also follows that\n\n%$$\n%I(Y;X) := H(Y) - H(Y|X) = H(Y) + H(X) - H(X, Y).\n%$$\n\n%\\textbf{Remarks:}\n%\\begin{itemize}\n%\\item The mutual information is symmetric, i. e. $I(Y;X) = I(X;Y)$.\n%\\item It describes the amount of information about one random variable obtained through the other one (\\textbf{information gain}).\n%\\end{itemize}\n\n%\\begin{figure}\n% \\includegraphics{figures/mutualinformation.pdf}\n%\\end{figure}\n\n% \\framebreak\n\n% Mutual information can be used to perform \\textbf{feature selection}. Quite simply, each variable $X_i$ is rated according to $I(X_i;Y)$: The more information we gain on $Y$ by observing $X_i$, the more \"useful\" $X_i$.\n\n% \\lz\n\n% Let $\\D = \\Dset$ and $\\D \\{\\cdot\\}$ a subset of $\\D$ for which condition $\\cdot$ is fulfilled. Then, \\textbf{information gain} is defined as:\n\n% \\footnotesize\n% \\begin{equation*}\n% \\begin{aligned}\n% IG(\\D, s) &= I(X_s;Y) \\\\\n% &= H(Y) - H(Y|X_s) \\\\\n% &= - \\sum_{y \\in Y} p(y) \\log_2 p(y) + \\sum_{x \\in X_s} \\sum_{y \\in Y} p(x,y) \\log_2 p(y|x) \\\\\n% &= - \\sum_{y \\in Y} \\frac{|\\D\\{Y = y\\}|}{|\\D|} \\log_2 \\sum_{y \\in Y} \\frac{|\\D\\{Y = y\\}|}{|\\D|} \\\\ &+\n% \\sum_{x \\in X_s} \\sum_{y \\in Y} \\frac{|\\D\\{Y = y, X_s = x\\}|}{|\\D|} \\log_2 \\frac{|\\D\\{Y = y, X_s = x\\}|}{|\\D\\{X_s = x\\}|}.\n% \\end{aligned}\n% \\end{equation*}\n% \\normalsize\n\n% \\framebreak\n\n\\begin{itemize}\n  % \\item Intuitively, mutual information quantifies the amount of shared information between variables.\n  \\item MI is a measure of the amount of \"dependence\" between variables. It is zero if and only if the variables are independent.\n  \\item On the other hand, if one of the variables is a deterministic function of the other, the mutual information is maximal, i.e. entropy of the first.\n \\item Unlike (Pearson) correlation, mutual information is not limited to real-valued random variables.\n    \\item Mutual information can be used to perform \\textbf{feature selection}. Quite simply, each variable $X_i$ is rated according to $I(X_i;Y)$, this is sometime called information gain.\n  \\item The same principle can also used in decision trees to select a feature to split on. Splitting on MI/IG is then equivalent to risk reduction with log-loss. \n\\end{itemize}\n\\end{vbframe}\n \n\n\\begin{vbframe} {Mutual information vs. correlation}\n  \n  \\begin{itemize}\n    \\item If two variables are independent, their correlation is 0.\n    \\item However, the reverse is not necessarily true. It is possible for two dependent variables to have 0 correlation because correlation only measures linear dependence.\n    \n\\begin{center}\n\\includegraphics[width = 10cm ]{figure_man/correlation.png} \\\\\n\\end{center}\n\n    \\item The figure above shows various scatterplots where, in each case, the correlation is 0 even though the two variables are strongly dependent, and MI is large. \n    \\item Mutual information can therefore be seen as a more general measure of dependence between variables than correlation.\n  \\end{itemize}\n\n\\end{vbframe}\n\n\\begin{vbframe} {Mutual information - example}\n\nLet $X, Y$ be two correlated Gaussian random variables. $(X, Y) \\sim \\mathcal{N}(0, K)$ with correlation $\\rho$ and covariance matrix $K$:\n\n$$\nK =\n\\begin{pmatrix}\n  \\sigma^2 & \\rho \\sigma^2 \\\\\n  \\rho \\sigma^2 & \\sigma^2\n\\end{pmatrix}\n$$\n\nThen $h(X) = h(Y) = \\frac{1}{2} \\log(2 \\pi e) \\sigma^2$, and $h(X,Y) = \\log(2 \\pi e)^2 |K| = \\log(2 \\pi e)^2 \\sigma^4 (1 - \\rho^2)$, and thus\n\n\\begin{equation*}\n\\begin{aligned}\nI(X;Y) = h(X) + h(Y) - h(X,Y) = -  \\frac{1}{2} \\log(1 - \\rho^2).\n\\end{aligned}\n\\end{equation*}\n\nFor $\\rho = 0$, $X$ and $Y$ are independent and $I(X;Y) = 0$. \\\\\nFor $\\rho = \\pm 1$, $X$ and $Y$ are perfectly correlated and $I(X;Y) \\rightarrow \\infty$. \n\\end{vbframe}\n\n% \\begin{vbframe} {Chain rule for information}\n\n\n% $$I\\left(X_{1}, X_{2}, \\ldots, X_{n} ; Y\\right)=\\sumin I\\left(X_{i} ; Y | X_{i-1}, X_{i-2}, \\ldots, X_{1}\\right)$$\n\n% \\textbf{Proof:$\\quad$}\n% \\footnotesize\n% \\begin{equation*}\n% \\begin{aligned}\n% I\\left(X_{1}, X_{2}, \\ldots, X_{n} ; Y\\right) &= H\\left(X_{1}, X_{2}, \\ldots, X_{n}\\right)-H\\left(X_{1}, X_{2}, \\ldots, X_{n} | Y\\right) \\\\\n% &=\\sumin H\\left(X_{i} | X_{i-1}, \\ldots, X_{1}\\right)-\\sum_{i=1}^{n} H\\left(X_{i} | X_{i-1}, \\ldots, X_{1}, Y\\right) \\\\\n% &=\\sumin I\\left(X_{i} ; Y | X_{1}, X_{2}, \\ldots, X_{i-1}\\right).  \n% \\end{aligned}\n% \\end{equation*}\n\n% \\normalsize\n\n% \\end{vbframe}\n\n\n% \\begin{vbframe} {Chain rule for KL distance}\n\n% \\begin{equation*}\n% \\begin{aligned}\n% D_{KL}(p(x, y) \\| q(x,y)) &= D_{KL}(p(x) \\| q(x)) + D_{KL}(p(y|x) \\| q(y|x))\n% \\end{aligned}\n% \\end{equation*}\n\n% \\textbf{Proof:}\n\n% \\footnotesize\n\n% \\begin{equation*}\n% \\begin{aligned}\n% D_{KL}(p(x, y) \\| q(x,y)) &= \\sum_x \\sum_y p(x,y) \\log \\frac{p(x,y)}{q(x,y)} \\\\\n% &= \\sum_x \\sum_y p(x,y) \\log \\frac{p(x)p(y|x)}{q(x)q(y|x)} \\\\\n% &= \\sum_x \\sum_y p(x,y) \\log \\frac{p(x)}{q(x)} + \\sum_x \\sum_y p(x,y) \\log \\frac{p(y|x)}{q(y|x)} \\\\\n% &= D_{KL}(p(x) \\| q(x)) + D_{KL}(p(y|x) \\| q(y|x))\n% \\end{aligned}\n% \\end{equation*}\n\n% \\normalsize\n\n\n% \\end{vbframe}\n\n\n%old slide about KLD \n% %\\normalsize\n% The mutual information between two variables $X$ and $Y$ is also the KL divergence of the product of the marginal distributions $p_x(x) p_y(y)$ from the joint distribution $p(x,y)$ :\n% % $I(x;y)$ is the \\emph{information gain} achieved if the the joint distribution $p_{xy}(x,y)$ is used instead of the product of marginal distributions :\n% \n% \\begin{eqnarray*}\n% I(X;Y) &\\overset{(*)}{=}& D_{KL}(p_{xy}||p_x p_y) = \\sum_{x \\in \\Xspace} \\sum_{y \\in \\Yspace} p_{xy}(x, y) \\cdot \\log \\biggl(\\frac{p_{xy}(x, y)}{p_x(x)p_y(y)}\\biggr)\n% \\end{eqnarray*}\n% \n% For continuous random variables $X$ and $Y$ with joint density $p(x,y)$ and marginal densities $p_x(x) p_y(y)$, the mutual information is:\n% \n% \\begin{eqnarray*}\n% I(X;Y) &=& D_{KL}(p_{xy}||p_x p_y) = \\int_{x \\in \\Xspace} \\int_{y \\in \\Yspace} p_{xy}(x, y) \\cdot \\log \\biggl(\\frac{p_{xy}(x, y)}{p_x(x)p_y(y)}\\biggr)\n% \\end{eqnarray*}\n% \n% \n% (Note: If $X$ and $Y$ are independent, $p(x,y)=p_x(x) p_y(y)$ and $I(X;Y)$ is zero.)\n% \\framebreak\n% \n% (*) Derivation:\n% \n% \\footnotesize\n% \n% \n% \\begin{eqnarray*}\n% I(X;Y) &=& H(Y) + H(X) - H(X, Y)\\\\\n% &=& -\\sum_{y \\in \\Yspace} p_y(y) \\log_2(p_y(y)) -\\sum_{x \\in \\Xspace} p_x(x) \\log_2(p_x(x)) \\\\\n% && -\\sum_{x \\in \\Xspace, y \\in \\Yspace} p_{xy}(x, y) \\log_2(p_{xy}(x, y))\\\\\n% &=& -\\sum_{x \\in \\Xspace, y \\in \\Yspace}p_{xy}(x, y) \\log_2(p_y(y)) -\\sum_{x \\in \\Xspace, y \\in \\Yspace} p_{xy}(x, y) \\log_2(p_x(x)) \\\\\n% && \\quad+ \\sum_{x \\in \\Xspace, y \\in \\Yspace} p_{xy}(x, y) \\log_2(p_{xy}(x, y)) \\\\\n% &=& \\sum_{x \\in \\Xspace} \\sum_{y \\in \\Yspace} p_{xy}(x, y) \\cdot \\log_2 \\biggl(\\frac{p_{xy}(x, y)}{p_x(x)p_y(y)}\\biggr) = D_{KL}(p_{xy}||p_x p_y)\n% \\end{eqnarray*}\n% \n% \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n% \\begin{vbframe} {Summary}\n\n% \\begin{figure}\n%     \\centering\n%       \\scalebox{0.75}{\\includegraphics{figures/quants.png}}\n% \\end{figure}\n  \n\n%     \\begin{align*}\n%       H(X,Y) &= H(X) + H(Y|X) \\\\\n%              &= H(Y) + H(X|Y)\n%     \\end{align*}\n    \n%     \\begin{align*}\n%       I(X;Y) &= H(X) - H(X|Y) \\\\\n%              &= H(Y) - H(Y|X)\n%     \\end{align*}\n\n% \\end{vbframe}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%          REFERENCES          %%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{vbframe}\n% \\frametitle{References}\n% \\footnotesize{\n% \\begin{thebibliography}{99}\n% \n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\bibitem[Chris Olah, 2015]{1} Chris Olah (2015)\n% \\newblock Visual Information Theory\n% \\newblock \\emph{\\url{http://colah.github.io/posts/2015-09-Visual-Information/}}\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\bibitem[Massimiliano Tomassoli, 2016]{2} Massimiliano Tomassoli (2016)\n% \\newblock Information Theory for Machine Learning\n% \\newblock \\emph{\\url{https://github.com/mtomassoli/papers/blob/master/inftheory.pdf}}\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\bibitem[Will Kurt, 2017]{3} Will Kurt, (2017)\n% \\newblock Kullback-Leibler Divergence Explained\n% \\newblock \\emph{\\url{https://www.countbayesie.com/blog/2017/5/9/kullback-leibler-divergence-explained}}\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\bibitem[Eric Jang, 2016]{4} Eric Jang, (2016)\n% \\newblock A Beginner's Guide to Variational Methods: Mean-Field Approximation\n% \\newblock \\emph{\\url{https://blog.evjang.com/2016/08/variational-bayes.html}}\n% \n% \\end{thebibliography}\n% }\n% \\end{vbframe}\n\n% \\section{Information Theory and Machine Learning}\n\n% \\begin{vbframe} {KL to CE to LL}\n% \n% \\begin{equation*}\n%   \\begin{split}\n%     \\theta^* & = \\argmin_{\\theta} \\sum_1^n KL (d_i \\parallel f_{\\theta}(x_i)) \\\\\n%              & = \\argmin_{\\theta} \\sum_1^n [H(d_i, f_{\\theta}(x_i)) - H(d_i)] \\\\\n%              & = \\sum_1^n  H(d_i, f_{\\theta}(x_i))\n%   \\end{split}\n% \\end{equation*}\n% \n% \\framebreak\n% \n% \\begin{equation*}\n%   \\begin{split}\n%     \\theta^* &= \\argmin_{\\theta} \\sum_1^n \\left( - \\sum_y d_i(y) \\log_2f_{\\theta}(y|x_i) \\right) \\\\\n%              &= \\argmin_{\\theta} \\sum_1^n (-\\log_2f_{\\theta}(y|x_i)) \\\\\n%              &= \\argmax_{\\theta} \\sum_1^n \\log_2f_{\\theta}(y|x_i) \\\\\n%              &= \\argmax_{\\theta} \\log \\prod_1^n P(y_i|x_i;\\theta) \\\\\n%              &= \\argmax_{\\theta} \\log P(y_1, \\ldots , y_n | x_1, \\ldots x_n ; \\theta) \\\\\n%              &= \\argmax_{\\theta} \\log L(\\theta)\n%   \\end{split}\n% \\end{equation*}\n% \n% \\end{vbframe}\n\n% \\begin{vbframe} {Density Estimation}\n% \n% Minimizing the \n%   \\begin{equation*}\n%     \\begin{split}\n%       \\theta^* &= \\argmin_{\\theta} KL(\\hat{p} \\parallel p_{\\theta}) = \\argmin_{\\theta} [H(\\hat{p},p_{\\theta}) - H(\\hat{p})] \\\\ &= \\argmin_{\\theta} H(\\hat{p},p_{\\theta}) = \\argmin_{\\theta} \\E_{X \\sim \\hat{p}} [I_{p_{\\theta}}(X)] \\\\\n%                &= \\argmin_{\\theta} \\sum_x \\hat{p}(x) (- \\log p_{\\theta} (x)) \\\\\n%                &= \\argmax_{\\theta} \\sum_1^n \\frac{1}{n} \\log p_{\\theta} (x_i) = \\argmax_{\\theta} \\sum_1^n  \\log p_{\\theta} (x_i) \\\\\n%                &= \\argmax_{\\theta} \\log \\prod_1^n p_{\\theta} (x_i) = \\argmax_{\\theta} \\log P(x_1, \\ldots x_n | \\theta) \\\\\n%                &= \\argmax_{\\theta} \\log L(\\theta)\n%     \\end{split}\n%   \\end{equation*}\n%   \n% \\end{vbframe}\n% \n% \\begin{vbframe} {Information Gain}\n%   \\begin{itemize}\n%     \\item Feature selection using information gain\n%     \\item Joint Mutual Information\n%   \\end{itemize}\n% \\end{vbframe}\n% \n% \\begin{vbframe} {Variational Inference}\n% \n%   \\begin{equation*}\n%     \\begin{split}\n%       KL(q(z) \\parallel p(z|x)) &= \\E_q \\left[ \\log \\frac {q(Z)} {p(Z|x)}  \\right] \\\\\n%                                 &= \\E_q [\\log q(Z)] - \\E_q [\\log p(Z|x)] \\\\\n%                                 &= \\E_q [\\log q(Z)] - \\E_q [\\log p(Z,x)] + \\log p(x) \\\\\n%                                 &= -(\\E_q [\\log p(Z,x) - \\E_q [\\log q(Z)]) + \\log p(x) \\\\\n%                                 &= -L + \\log p(x) \n%     \\end{split}\n%   \\end{equation*}\n%   where L is the ELBO (Evidence Lower Bound)\n% \\end{vbframe}\n\n%\\begin{vbframe} {Chain rule for entropy}\n%\\begin{columns}[T,onlytextwidth]\n%\\column{0.3\\textwidth}\n%\\textbf{Example: Consider a node in a decision tree with 7 samples that belong to either the $+$ or the $-$ class.} \\\\\n%\\lz\n%\\begin{center}\n%<<entropy-ex1, echo=FALSE, size = \"footnotesize\">>=\n%library(knitr)\n%ex1 <- cbind(class=c(\"+\",\"+\",\"-\",\"+\",\"-\",\"-\", \"-\"), attr_1 = c(T,T,T,F,F,F,F), attr_2 = c(T,T,F,F,T,T,T))\n%kable(ex1)\n%@\n%\\end{center}\n%\\column{0.65\\textwidth}\n%\\begin{itemize}\n%\\item How big is the uncertainty/entropy in \\textit{class} (in bits)?\n%%\\small\n%\\begin{eqnarray*}\n%H(\\text{class}) &=& - \\sum_{k=+,\\, -} p(k) \\log_2(p(k)) \\\\\n%&=& - \\frac{3}{7} \\log_2\\left(\\frac{3}{7}\\right)  - \\frac{4}{7} \\log_2\\left(\\frac{4}{7}\\right) \\\\\n%&=& 0.985\n%\\end{eqnarray*}\n%%\\normalsize\n%\\item How much can it be reduced by knowing the other attributes?\n%\\end{itemize}\n%\\end{columns}\n\n\n%\\framebreak\n%\\begin{columns}[T,onlytextwidth]\n%\\column{0.3\\textwidth}\n%\\textbf{Example:} \\\\\n%\\lz\n%\\begin{center}\n%<<entropy-ex2, echo=FALSE, size = \"footnotesize\">>=\n%library(knitr)\n%kable(ex1)\n%@\n%\\end{center}\n%\\column{0.65\\textwidth}\n%\\scriptsize\n\n%\\vspace*{1.5cm}\n\n%$H(\\text{class}|\\text{attr}_1 = T) = - \\frac{2}{3} \\log_2(\\frac{2}{3}) - \\frac{1}{3} \\log_2(\\frac{1}{3}) = 0.92$ \\\\\n%$H(\\text{class}|\\text{attr}_1 = F) = - \\frac{1}{4} \\log_2(\\frac{1}{4}) - \\frac{3}{4} \\log_2(\\frac{3}{4}) = 0.81$ \\\\\n%$H(\\text{class}|\\text{attr}_2 = T) = - \\frac{2}{5} \\log_2(\\frac{2}{5}) - \\frac{3}{5} \\log_2(\\frac{3}{5}) = 0.97$ \\\\\n%$H(\\text{class}|\\text{attr}_2 = F) = - \\frac{1}{2} \\log_2(\\frac{1}{2}) - \\frac{1}{2} \\log_2(\\frac{1}{2}) = 1$ \\\\\n%\\lz\n%$H(\\text{class}|\\text{attr}_1) = \\frac{3}{7} 0.92 + \\frac{4}{7} 0.81 = 0.86$ \\\\\n%$H(\\text{class}|\\text{attr}_2) = \\frac{5}{7} 0.97 + \\frac{2}{7} 1 = 0.98$\n\n%\\normalsize\n\n%\\end{columns}\n\n%\\lz\n\n%By further splitting the node using either of the attributes, the uncertainty in class is reduced.\n\n%\\framebreak\n\n%\\begin{columns}[T,onlytextwidth]\n%\\column{0.3\\textwidth}\n%\\textbf{Example:} \\\\\n%\\lz\n%\\begin{center}\n%<<entropy-ex3, echo=FALSE, size = \"footnotesize\">>=\n%library(knitr)\n%kable(ex1)\n%@\n%\\end{center}\n%\\column{0.65\\textwidth}\n%\\begin{itemize}\n%\\item The reduction in uncertainty, or equivalently, gain in information is:\n%\\footnotesize\n%\\begin{eqnarray*}\n%H(\\text{class}) - H(\\text{class}|\\text{attr}_1) &=& 0.985 - 0.86 \\\\\n% &=& 0.125\n%\\end{eqnarray*}\n\n%\\begin{eqnarray*}\n%H(\\text{class}) - H(\\text{class}|\\text{attr}_2) &=&  0.985 - 0.98 \\\\\n%&=& 0.005\n%\\end{eqnarray*}\n%% \\normalsize\n%% \\lz\n%\\item $\\text{attr}_1$ tells us more about $\\text{class}$. Therefore, to improve the predictive performance of the decision tree in the CART algorithm, it is better to further split the node using $\\text{attr}_1$, rather than $\\text{attr}_2$.\n%\\end{itemize}\n\n%\\end{columns}\n\n%\\end{vbframe}\n\n\\endlecture\n\\end{document}\n\n\n\n", "meta": {"hexsha": "d4136925fcc57b03c54a52955229fec9f10ee167", "size": 27518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/information-theory/slides-info-mutual-info.tex", "max_stars_repo_name": "jukaje/lecture_i2ml", "max_stars_repo_head_hexsha": "cd4900f5190e9d319867b4c0eb9d8e19f659fb62", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 93, "max_stars_repo_stars_event_min_datetime": "2019-02-27T17:20:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T12:05:52.000Z", "max_issues_repo_path": "slides/information-theory/slides-info-mutual-info.tex", "max_issues_repo_name": "jukaje/lecture_i2ml", "max_issues_repo_head_hexsha": "cd4900f5190e9d319867b4c0eb9d8e19f659fb62", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 323, "max_issues_repo_issues_event_min_datetime": "2019-02-27T08:02:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T08:11:41.000Z", "max_forks_repo_path": "slides/information-theory/slides-info-mutual-info.tex", "max_forks_repo_name": "jukaje/lecture_i2ml", "max_forks_repo_head_hexsha": "cd4900f5190e9d319867b4c0eb9d8e19f659fb62", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2019-02-27T16:25:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T05:53:20.000Z", "avg_line_length": 34.354556804, "max_line_length": 277, "alphanum_fraction": 0.5960825641, "num_tokens": 10443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6733156612652099}}
{"text": "%!TEX root=report.tex\n\\subsection{K-means clustering}\n\nClustering is the process of grouping or dividing a set of objects into disjunct subsets, such that objects in each cluster are similar.\nAll clustering methods are unsupervised learning methods, thus there is no ``correct'' answer.\nIt have been shown that given a set of objects, humans also differ in their choice of clusters.\n\nSince similarity is an imprecise term, one uses a distance function to use as a Dissimilarity Measure $d$.\n\nThere are 4 conditions a distance function $d$ must satisfy, they are all derived from the norm definition \\cite[p.~30]{math-4}:\n\\begin{align}\n\\text{(i) }   & d(p_1,p_2) \\ge 0 && \\forall \\ p_1, p_2 \\in V \\\\\n\\text{(ii) }  & d(p_1,p_2) \\le d(p_1, p_3) + d(p_3, p_2) && \\forall \\ p_1, p_2, p_3 \\in V \\\\\n\\text{(iii) } & d(p_1, p_2) = d(p_2, p_1) && \\forall \\ p_1, p_2 \\in V \\\\\n\\text{(iv) } & d(p_1, p_2) = 0 \\Leftrightarrow p_1 = p_2 && \\forall \\ p_1, p_2 \\in V\n\\end{align}\n\nGiven a distance measure the total cluster variance $C^{*}$ can be calculated as\n\\begin{equation}\nC^{*}=\\sum^K_{k=1} N_k \\sum_{i \\in C_k} D(x_i, \\mu_k).\n\\end{equation}\nHere $\\mu_k$ denotes the k\\textsuperscript{th} cluster center (also called a centroid), $N_k$ the number of observations in cluster $k$ and $C_k$ denotes the subset with all the points in the cluster $k$.\n\nIn this analysis the Euclidean distance $D(x_i, x_j) = ||x_i - x_j||_2$ has been chosen as the dissimilarity measure.\nK-means is then the chosen algorithm for minimizing $C^{*}$ given $K$ clusters.\nThe k-means method as the dataset size is $(lat \\cdot lon, days) = (64800,341)$ and k-means is fairly quick to converge and calculate.\n\nK-means makes a single big assumption about the clusters being hyper dimensional sphere. But beyond this K-means is a simple iterative algorithm:\n\\begin{enumerate}\n\t\\item Initialize cluster centroids\n\t\\item Iterate until centroid convergence:\n\t\\begin{enumerate}\n\t\t\\item Given the current set of centroids, reassign each observation to the closest centroid using the distance function.\n\t\t\\item Using the current cluster assignment $C_k\\ \\forall k$, minimize $C^{*}$ by recomputing the centroids for each cluster as the mean of points in each cluster.\n\t\\end{enumerate}\n\\end{enumerate}\n\n\\subsubsection{Gap-statistics}\n\nThe big issue with clustering is that there is no obvious way of selecting the amount of clusters $K$. In this analysis the Gap-statistics \\cite[p.~519]{statistical-learning} as proposes by Hastie, Tibshirani and Firedman is used.\n\nFirst calculate the cluster dissimilarity using $K$ clusters \\cite{gap-statistic}\n\\begin{equation}\nW_K = \\sum_{k=1}^K \\frac{1}{2 N_k} \\sum_{x_i\\in C_k} \\sum_{x_j\\in C_k} ||p_i - p_j||_2^2 = \\sum_{k=1}^K \\sum_{x_i\\in C_k} ||p_i - \\mu_k||_2^2.\n\\end{equation}\n\nGiven the quantity $W_k$ one can then calculate a gap $G$ by simulating $b$ datasets from a random uniform distribution and calculating the gap as\n\\begin{equation}\nG(k) = \\mathrm{E}[\\log(W_k)] - \\log(W_k),\n\\end{equation}\nwhere the expectation $\\mathrm{E}[\\log(W_k)]$ can be estimated by the mean over the $b$ simulated datasets. That is the gap statistics tries to avoid overfitting by comparing the cluster gain on a dataset where there are no clusters (uniformly distributed).\n\nThe amount of clusters $K$ is then minimized under the condition\n\\begin{equation}\nK^{*} = \\argmin_K \\left\\{ K \\ | \\ G(K) \\ge G(K + 1) - s'_{K+1} \\right\\}.\n\\end{equation}\n\nHere $s'_{K+1}$ is the standard error on the $b$ samples calculated as \n\\begin{equation}\ns'_{K} = \\mathrm{SD}[\\log(W_k)] \\sqrt{1+\\frac{1}{b}}.\n\\end{equation}\n", "meta": {"hexsha": "f7d1518fb0f244e4e55240bc3eb1414daa1f042e", "size": 3586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-kmeans.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-kmeans.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-kmeans.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.8387096774, "max_line_length": 257, "alphanum_fraction": 0.7244841049, "num_tokens": 1101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6733156393010403}}
{"text": "\\lab{Introduction to Wavelets}{Introduction to Wavelets}\n\\objective{Wavelets are used to sparsely represent some types of information.\nThis makes them useful in a variety of applications.\nWe explore both the one- and two-dimensional discrete wavelet transforms using various types of wavelets.\n% HERE (above line): added hyphen after \"one\"\nWe then use a Python package called PyWavelets for further wavelet analysis including image cleaning and image compression.\n}\n\n\\section*{Wavelet Functions}\n\n\\emph{Wavelets families} are sets of orthogonal functions (wavelets) designed to decompose nonperiodic, piecewise continuous functions.\nThese families have four types of wavelets: mother, daughter, father, and son functions.\nFather and son wavelets contain information related to the general movement of the function, while mother and daughter wavelets contain information related to the details of the function.\nThe father and mother wavelets are the basis of a family of wavelets.\nSon and daughter wavelets are just scaled translates of the father and mother wavelets, respectively.\n\n\\subsection*{Haar Wavelets}\n\nThe \\emph{Haar Wavelet} family is one of the most widely used wavelet families in wavelet analysis.\nThis set includes the father, mother, son, and daughter wavelets defined below.\nThe Haar father (scaling) function is given by\n\\[\n\\varphi(x) =\n \\begin{cases}\n 1 & \\text{if } 0 \\leq x < 1 \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\]\nThe Haar son wavelets are scaled and translated versions of the father wavelet:\n\\[\n\\varphi_{jk}(x)=\\varphi(2^jx-k) =\n \\begin{cases}\n 1 & \\text{if }\\frac{k}{2^j} \\leq x < \\frac{k+1}{2^j} \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\]\nThe Haar mother wavelet function is defined as\n\\[\n\\psi(x) =\n \\begin{cases}\n  1 & \\text{if } 0 \\leq x < \\frac{1}{2} \\\\\n  -1 & \\text{if } \\frac{1}{2} \\leq x < 1 \\\\\n  0 & \\text{otherwise.}\n \\end{cases}\n\\]\nThe Haar daughter wavelets are scaled and translated versions of the mother wavelet\n\\[\n\\psi_{jk}=\\psi(2^jx-k)\n\\]\n% It might be nice to plot this function and include the image in the lab.\n\n\nInformation (such as a mathematical function or image) can be stored and analyzed by considering its \\emph{wavelet decomposition}.\nA \\emph{wavelet decomposition} is a linear combination of wavelets.\nFor example, a mathematical function $f$ can be approximated as a combination of Haar son and daughter wavelets as follows:\n\\begin{align*}\nf(x) = \\sum_{k=-\\infty}^{\\infty} a_k\\varphi_{m,k}(x) + \\sum_{k=-\\infty}^{\\infty} b_{m,k}\\psi_{m,k}(x) + \\dots + \\sum_{k=-\\infty}^{\\infty} b_{n,k}\\psi_{n,k}(x)\n\\end{align*}\nwhere $m<n$, and all but a finite number of the $a_k$ and $b_{j,k}$ terms are nonzero.\nThe $a_k$ terms are often referred to as \\emph{approximation coefficients} while the $b_{j,k}$ terms are known as \\emph{detail coefficients}.\nThe approximation coefficients typically capture the broader, more general features of a signal while the detail coefficients capture smaller details and noise.\n\nA wavelet decomposition can be done with any family of wavelet functions.\nDepending on the properties of the wavelet and the function (or signal) $f$, $f$ can be approximated to an arbitrary level of accuracy.\nEach arbitrary wavelet family has a mother wavelet $\\psi$ and a father wavelet $\\varphi$ which are the basis of the family.\nA countably infinite set of wavelet functions (daughter and son wavelets) can be generated using dilations and shifts of the first two functions where $m,k \\in \\mathbb{Z}$:\n\\begin{align*}\n\\psi_{m,k}(x) &= \\psi(2^mx - k)\\\\\n\\varphi_{m,k}(x) &= \\varphi(2^mx - k).\n\\end{align*}\n\n\\subsection*{The Discrete Wavelet Transform} % ===================================\n\n% HERE: remove these comments.\n%In wavelet analysis, information (such as a mathematical function or an image) can be stored and analyzed by considering its \\emph{wavelet decomposition}.\n%The wavelet decomposition is a way of expressing information as a linear combination of a particular set of wavelet functions.\n%Every wavelet has associated functions that differentiate it from other wavelets\n%Once a wavelet is chosen, information can then be represented by a sequence of coefficients (called \\emph{wavelet coefficients}) that define the linear combination.\n%The mapping from a function to a sequence of wavelet coefficients is called the \\emph{discrete wavelet transform}.\n\nThe mapping from a function to a sequence of wavelet coefficients is called the \\emph{discrete wavelet transform}.\nThe discrete wavelet transform is analogous to the discrete Fourier transform.\nNow, instead of using trigonometric functions, different families of basis functions are used.\n\n\n\\begin{comment}\nIn the case of finitely-sampled signals and images, only finitely many wavelet coefficients are nonzero.\nDepending on the application, we are often only interested in the coefficients corresponding to a subset of the basis functions.\nSince a given family of wavelets forms an orthogonal set, we can compute the wavelet coefficients\nby taking inner products (i.e. by integrating). This direct approach is not particularly efficient,\nhowever. Just as there are fast algorithms for computing the Fourier transform (e.g. the FFT),\nwe can efficiently calculate wavelet coefficients using techniques from signal processing.\nIn particular, we will use an \\emph{iterative filter bank} to compute the transform.\n% mathematical derivation?\n\\end{comment}\n\nIn the case of finitely-sampled signals and images, there exists an efficient algorithm for computing the wavelet coefficients.\nMost commonly used wavelets have associated high-pass and low-pass filters which are derived from the wavelet and scaling functions, respectively.\nWhen the low-pass filter is convolved with the sampled signal, low frequency (also known as approximation) information is extracted.\nThis is similar to turning up the bass on a speaker, which extracts the low frequencies of a sound wave.\nThis filter highlights the overall (slower-moving) pattern without paying too much attention to the high frequency details and extracts the approximation coefficients.%, which to the eye (or ear) may be unhelpful noise.\n\nWhen the high-pass filter is convolved with the sampled signal, high frequency information (also known as detail) is extracted.\nThis is similar to turning up the treble on a speaker, which extracts the high frequencies of a sound wave.\nThis filter highlights the small changes found in the signal and extracts the detail coefficients.\n\nThe two primary operations of the algorithm are the discrete convolution and downsampling, denoted $*$ and $DS$, respectively.\nFirst, a signal is convolved with both filters.\nThe resulting arrays will be twice the size of the original signal because the frequency of the sample will have changed by a factor of 2.\nTo remove this redundant information, the resulting arrays are \\emph{downsampled}.\nDownsampling is the process of removing unimportant entries from an array.\nIn the context of this lab, a \\emph{filter bank} is the combined process of convolving with a filter, and then downsampling.\nThe result will be an array of approximation coefficients $A$ and an array of detail coefficients $D$.\nThis process can be repeated on the new approximation to obtain another layer of approximation and detail coefficients.\nSee Figure \\ref{fig:filter bank}.\n\nA common lowpass filter is the averaging filter.\nGiven an array \\textbf{x}, the averaging filter produces an array \\textbf{y} where $y_n$ is the average of $x_n$ and $x_{n-1}$.\nIn other words, the averaging filter convolves an array with the array $L=\\begin{bmatrix}\\frac{1}{2} & \\frac{1}{2}\\end{bmatrix}$.\nThis filter preserves the main idea of the data.\nThe corresponding highpass filter is the distance filter.\nGiven an array \\textbf{x}, the distance filter produces an array \\textbf{y} where $y_n$ is the distance between $x_n$ and $x_{n-1}$.\nIn other words, the difference filter convolves an array with the array $H=\\begin{bmatrix}-\\frac{1}{2}&\\frac{1}{2}\\end{bmatrix}$.\nThis filter preserves the details of the data.\n\nFor the Haar Wavelet, we will use these lowpass and highpass filters.\nIn order for this filters to have inverses, the filters must be normalized (for more on why this is, see Additional Materials).\nThe resulting lowpass and highpass filters for the Haar Wavelets are the following:\n\\begin{comment}\n\\begin{align*}\nH &= \\sqrt{2}\\begin{bmatrix}\\frac{1}{2} & \\frac{1}{2}\\\\-\\frac{1}{2} & \\frac{1}{2}\\end{bmatrix}\\\\\n\\end{align*}\n\nFor the Haar Wavelet, the matrix $H$ represents the Haar transform.\nEach row of the transform represents an array which, when convolved with a vector, produces certain approximation and detail coefficients.\nThe first row of the Haar transform corresponds to the low-pass filter for the Haar wavelet, and the second row corresponds to the high-pass filter.\nTo fulfill all necessary properties when dealing with wavelets, the columns are orthonormal.\nFor more on the Haar Wavelet Transform, see Additional Materials.\n\\end{comment}\n\\begin{align*}\nL &= \\begin{bmatrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{bmatrix}\\\\H &=\\begin{bmatrix}-\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{bmatrix}\\\\\n\\end{align*}\n\n\\begin{comment}\nThe key operations in the algorithm are the discrete convolution ($*$) and downsampling ($DS$).\nThe inputs to the algorithm are a one-dimensional array $X$ (the signal that we want to transform), a one-dimensional\narray $L$ (called the \\emph{low-pass filter}), a one-dimensional array $H$ (the \\emph{high-pass filter}), and a positive\ninteger $n$ (controlling to what degree we wish to transform the signal, i.e. how many wavelet coefficients we wish to compute).\nThe low-pass and high-pass filters can be derived from the wavelet and scaling function.\nThe low-pass filter extracts low frequency information, which gives us an approximation of the signal.\nThis approximation highlights the overall (slower-moving) pattern\nwithout paying too much attention to the high frequency details, which to the eye (or ear) may be unhelpful noise.\nHowever, we also need to extract the high-frequency details with the high-pass filter. While they may sometimes be\nnothing more than unhelpful noise, there are applications where they are the most important part of the signal; for example,\ndetails are very important if we are sharpening a blurry image or increasing contrast.\n\\end{comment}\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[auto, node distance=1.5cm, thick, main node/.style={circle, draw}, LoHi/.style={rectangle, draw}, minimum size=.75cm]\n    \\node[draw=none](Aj){A$_j$};\n    \\node[draw=none](j1)[right of=Aj]{};\n    \\node[LoHi](Lo)[above right of=j1]{Lo};\n    \\node[LoHi](Hi)[below right of=j1]{Hi};\n    \\node[main node](1)[right of=Lo]{};\n    \\node[main node](2)[right of=Hi]{};\n    \\node[draw=none](Aj+1)[right of=1]{A$_{j+1}$};\n    \\node[draw=none](Dj+1)[right of=2]{D$_{j+1}$};\n\n\\foreach \\s/\\t in {Aj/j1.center, 1/Aj+1, 2/Dj+1}{\n    \\draw[->] (\\s) -- (\\t);}\n\\foreach \\s/\\t in {j1.center/Lo, j1.center/Hi}{\n    \\draw[](\\s) |- (\\t);}\n\\foreach \\s/\\t in {Lo/1, Hi/2}{\n    \\draw[](\\s) -- (\\t);}\n\\foreach \\s in {1, 2}{\n    \\draw[->, shorten >=.2cm, shorten <=.2cm] (\\s.north) -- (\\s.south);}\n\\end{tikzpicture}\n\n\\vspace{1cm}\n\n\\begin{center}\n\\begin{tikzpicture}\n% Key\n    \\node[draw=none, node distance=2.5cm](K)[below of=Aj]{Key:};\n    \\node[rectangle, draw, minimum size=.5cm, node distance=1cm](rect)[right of=K]{};\n    \\node[draw=none, node distance=1.3cm](conv)[right of=rect]{= convolve};\n    \\node[circle, draw, minimum size=.5cm, node distance=3cm](circ)[right of=rect]{};\n    \\node[draw=none, node distance=1.5cm](conv)[right of=circ]{= downsample};\n    \\draw[->, shorten >=.1cm, shorten <=.1cm] (circ.north) -- (circ.south);\n\\end{tikzpicture}\n\\end{center}\n\\caption{The one-dimensional discrete wavelet transform implemented as a filter bank.}\n\\label{fig:filter bank}\n\\end{figure}\n\n\\begin{comment}\nAt each stage of the algorithm, we filter the signal into an approximation and its details.\nNote that the algorithm returns a sequence of one dimensional arrays\n\\[A_n, D_n, D_{n-1}, \\ldots, D_1.\\]\nIf the input signal $X$ has length $2^m$ for\nsome $m \\geq n$ and we are using the Haar wavelet, then $A_n$ has length $2^{m-n}$, and $D_i$ has length $2^{m-i}$\nfor $i=1,\\ldots,n$. The arrays $D_i$ are outputs of the high-pass filter, and thus represent high-frequency\ndetails.\nHence, these arrays are known as \\emph{details}.\nThe array $A_n$ is computed by recursively passing the signal through the low-pass filter, and hence it\nrepresents the low-frequency structure in the signal.\nIn fact, $A_n$ can be seen as a smoothed approximation of the original signal, and is called the \\emph{approximation}.\n\\end{comment}\n\nAs noted earlier, the key mathematical operations of the discrete wavelet transform are convolution and downsampling.\nGiven a filter and a signal, the convolution can be obtained using \\li{scipy.signal.fftconvolve()}.\n\\begin{lstlisting}\n>>> from scipy.signal import fftconvolve\n>>> # Initialize a filter.\n>>> L = np.ones(2)/np.sqrt(2)\n>>> # Initialize a signal X.\n>>> X = np.sin(np.linspace(0,2*np.pi,16))\n>>> # Convolve X with L.\n>>> fftconvolve(X, L)\n[ -1.84945741e-16   2.87606238e-01   8.13088984e-01   1.19798126e+00\n   1.37573169e+00   1.31560561e+00   1.02799937e+00   5.62642704e-01\n   7.87132986e-16  -5.62642704e-01  -1.02799937e+00  -1.31560561e+00\n  -1.37573169e+00  -1.19798126e+00  -8.13088984e-01  -2.87606238e-01\n  -1.84945741e-16]\n\\end{lstlisting}\n\nThe convolution operation alone gives redundant information, so it is downsampled to keep only what is needed.\nThe array will be downsampled by a factor of 2, which means keeping only every other entry:\n\n\\begin{lstlisting}\n>>> # Downsample an array X.\n>>> sampled = X[1::2] # Keeps odd entries\n\\end{lstlisting}\n\nBoth the approximation and detail coefficients are computed in this manner.  The approximation uses the low-pass filter while the detail uses the high-pass filter.\nImplementation of a filter bank is found in Algorithm \\ref{alg:1d_wavelet}.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{dwt}{$X, L, H, n$}\n    \\State $A_0 \\gets X$            \\Comment{Initialization.}\n   \\For{$i=0 \\ldots n-1$}\n        \\State $D_{i+1} \\gets \\,\\,DS(A_i * H)$ \\Comment{High-pass filter and downsample.}\n        \\State $A_{i+1} \\gets \\,\\,DS(A_i * L)$ \\Comment{Low-pass filter and downsample.}\n    \\EndFor\n    \\State \\pseudoli{return} $A_n,D_n, D_{n-1},\\ldots, D_1$.\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The one-dimensional discrete wavelet transform. $X$ is the signal to be transformed, $L$ is the low-pass filter, $H$ is the high-pass filter and $n$ is the number of\nfilter bank iterations.}\n\\label{alg:1d_wavelet}\n\\end{algorithm}\n\n\\begin{problem}\nWrite a function that calculates the discrete wavelet transform using Algorithm \\ref{alg:1d_wavelet}.\nThe function should return a list of one-dimensional NumPy arrays in the following form: $[A_n, D_n, \\ldots, D_1]$.\n\n%The main body of your function should be a loop in which you calculate two arrays: the $i$-th approximation\n%and detail coefficients. Append the detail coefficients array to your list, and feed the approximation array\n%back into the loop. When the loop is finished, append the approximation array. Finally, reverse the order of your list\n%to adhere to the required return format.\n\nTest your function by calculating the Haar wavelet coefficients of a noisy sine signal with $n=4$:\n\n\\begin{lstlisting}\ndomain = np.linspace(0, 4*np.pi, 1024)\nnoise =  np.random.randn(1024)*.1\nnoisysin = np.sin(domain) + noise\ncoeffs = dwt(noisysin, L, H, 4)\n\\end{lstlisting}\n\nPlot the original signal with the approximation and detail coefficients and verify that they match the plots in Figure \\ref{fig:dwt1D}.\n\\\\ (Hint: Use array broadcasting)\n\\label{prob:dwt1D}\n\\end{problem}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{figures/dwt1D}\n\\caption{A level four wavelet decomposition of a signal.\nThe top panel is the original signal, the next panel down is the approximation, and the remaining panels are the detail coefficients.\nNotice how the approximation resembles a smoothed version of the original signal, while the details capture the high-frequency oscillations and noise.}\n\\label{fig:dwt1D}\n\\end{figure}\n\n\\subsection*{Inverse Discrete Wavelet Transform}\n\nThe process of the discrete wavelet transform is reversible.\nUsing modified filters, a set of detail coefficients and a set of approximation coefficients can be manipulated and added together to recreate a signal.\nThe Haar wavelet filters for the inverse transformation are found by reversing the operations for each filter.\nThe original lowpass filter found the average of elements, so the inverse filter will find the distance.\nThe original highpass filter found the distance of elements, so the inverse filter will find the average.\nThe Haar inverse filters are given below:\n\\begin{align*}\nL^{-1} &= \\begin{bmatrix}\\frac{\\sqrt{2}}{2} & -\\frac{\\sqrt{2}}{2}\\end{bmatrix}\\\\H^{-1}&=\\begin{bmatrix}\\frac{\\sqrt{2}}{2}&\\frac{\\sqrt{2}}{2}\\end{bmatrix}\n\\end{align*}\nThe first row refers to the inverse high-pass filter and the second row refers to the inverse low-pass filter.\n\nSuppose the wavelet coefficients $A_n$ and $D_n$ have been computed.\n$A_{n-1}$ can be recreated by tracing the schematic in Figure \\ref{fig:filter bank} backwards: $A_n$ and $D_n$ are first upsampled, and then are convolved with the inverse low-pass and high-pass filters, respectively.\nIn the case of the Haar wavelet, \\emph{upsampling} involves doubling the length of an array by inserting a 0 at every other position.\nTo complete the operation, the new arrays are convolved and added together to obtain $A_{n-1}$.\n\n\\begin{lstlisting}\n>>> # Upsample the coefficient arrays A and D.\n>>> up_A = np.zeros(2*A.size)\n>>> up_A[::2] = A\n>>> up_D = np.zeros(2*D.size)\n>>> up_D[::2] = D\n>>> # Convolve and add, discarding the last entry.\n>>> A = fftconvolve(up_A, L)[:-1] + fftconvolve(up_D, H)[:-1]\n\\end{lstlisting}\n\nThis process is continued with the newly obtained approximation coefficients and with the next detail coefficients until the original signal is recovered.\n%Now that we have $A_{n-1}$, we repeat the process with $A_{n-1}$ and $D_{n-1}$ to obtain\n%$A_{n-2}$. Proceed for a total of $n$ steps (one for each $D_n, D_{n-1},\\ldots ,D_1$) until we have obtained $A_0$.\n%Since $A_0$ is defined to be the original\n%signal, we have finished the inverse transformation.\n% TODO: proof that this works, perhaps in an appendix...\n\n\\begin{problem} % Inverse wavelet transform\nWrite a function that performs the inverse wavelet transform.\nThe function should accept a list of arrays (of the same form as the output of Problem \\ref{prob:dwt1D}), a reverse low-pass filter, and a reverse high-pass filter.\nThe function should return a single array, which represents the recovered signal.\n\nNote that the input list of arrays has length $n+1$ (consisting of $A_n$ together with $D_n, D_{n-1}, \\ldots, D_1$), so your code should perform the process given above $n$ times.\n\nTo test your function, first perform the inverse transform on the noisy sine wave that you created in the first problem.\nThen, compare the original signal with the signal recovered by your inverse wavelet transform function using \\li{np.allclose()}.\n\\end{problem}\n\n\\begin{warn}\nAlthough Algorithm \\ref{alg:1d_wavelet} and the preceding discussion apply in the general case, the code implementations apply only to the Haar wavelet.\nBecause of the nature of the discrete convolution, when convolving with longer filters, the signal to be transformed needs to undergo a different type of lengthening in order to avoid\ninformation loss during the convolution.\nAs such, the functions written in Problems 1 and 2 will only work correctly with the Haar filters and would require modifications to be compatible with more wavelets.\n\\end{warn}\n\n\n\n\\section*{The Two-dimensional Wavelet Transform} % ==============================\n\nThe generalization of the wavelet transform to two dimensions is similar to one dimensional transforms.\nAgain, the two primary operations used are convolution and downsampling.\nThe main difference in the two-dimensional case is the number of convolutions and downsamples per iteration.\nFirst, the convolution and downsampling are performed along the rows of an array.\nThis results in two new arrays, as in the one dimensional case.\nThen, convolution and downsampling are performed along the columns of the two new arrays.\nThis results in four final arrays that make up the new approximation and detail coefficients.\nSee Figure \\ref{fig:filter bank2d}.\n\n\\begin{figure}[H]\n\\begin{center}\n\\begin{tikzpicture}[node distance=1.5cm,thick,main/.style={circle,draw}, LoHi/.style={rectangle,draw},minimum size=.75cm]\n\n%Nodes\n\\node (LLj) {$LL_j$};\n\\node[draw=none,right of=LLj] (Aux1) {};\n%First split - two layers\n\\node[LoHi,above right of=Aux1] (Lo1) {Lo};\n\\node[LoHi,below right of=Aux1] (Hi1) {Hi};\n\\node[main,right of=Lo1] (A1) {};\n\\node[main,right of=Hi1] (A2) {};\n%Second split - four layers\n\\node[draw=none,right of=A1] (Aux2) {};\n\\node[draw=none,right of=A2] (Aux3) {};\n\\node[LoHi,right of=Aux2] (Hi2) {Hi};\n\\node[LoHi,right of=Aux3] (Lo3) {Lo};\n\\node[LoHi,below of=Lo3] (Hi3) {Hi};\n\\node[LoHi,above of=Hi2] (Lo2) {Lo};\n\\node[main,right of=Lo2] (A3) {};\n\\node[main,right of=Hi2] (A4) {};\n\\node[main,right of=Lo3] (A5) {};\n\\node[main,right of=Hi3] (A6) {};\n\\node[right of=A3] (LLj1) {$LL_{j+1}$};\n\\node[right of=A4] (LHj1) {$LH_{j+1}$};\n\\node[right of=A5] (HLj1) {$HL_{j+1}$};\n\\node[right of=A6] (HHj1) {$HH_{j+1}$};\n\n\\node[above right=1.6cm and -.25cm of Lo1] {$rows$};\n\\node[above right=.1cm and -.25cm of Lo2] {$columns$};\n\n%Arrows between nodes\n\\foreach \\s/\\t in {LLj/Aux1.center,A3/LLj1,A4/LHj1,A5/HLj1,A6/HHj1} \\draw[->,>=stealth'] (\\s) -- (\\t);\n% |- links\n\\foreach \\s/\\t in {Aux1.center/Lo1,Aux1.center/Hi1,Aux2.center/Lo2,Aux3.center/Hi3} \\draw (\\s) |- (\\t);\n%Lines between nodes\n\\foreach \\s/\\t in {Lo1/A1,Hi1/A2,A1/Hi2,A2/Lo3,Lo2/A3,Hi2/A4,Lo3/A5,Hi3/A6} \\draw (\\s) -- (\\t);\n%Arrows in nodes\n\\foreach \\a in {A1,A2,A3,A4,A5,A6} \\draw[->,>=stealth',shorten >=.2cm,shorten <=.2cm] (\\a.north) -- (\\a.south);\n\n\\end{tikzpicture}\n\n\\vspace{1cm}\n\n\\begin{tikzpicture}[thick]\n% Key\n\\node[draw=none,node distance=2.5cm] (K) [below of=LLj] {Key:};\n\\node[rectangle,draw,minimum size=.5cm,node distance=1cm] (rect) [right of=K] {};\n\\node[draw=none,node distance=1.3cm] (conv) [right of=rect] {= convolve};\n\\node[circle,draw,minimum size=.5cm,node distance=3cm] (circ) [right of=rect]{};\n\\node[draw=none,node distance=1.5cm] (conv) [right of=circ] {= downsample};\n\\draw[->,shorten >=.1cm,shorten <=.1cm] (circ.north) -- (circ.south);\n\\end{tikzpicture}\n\n\\caption{The two-dimensional discrete wavelet transform implemented as a filter bank.}\n\\label{fig:filter bank2d}\n\\end{center}\n\\end{figure}\n\nWhen implemented as an iterative filter bank, each pass through the filter bank yields one set of approximation coefficients plus three sets of detail coefficients, rather than just one.\nMore specifically, if the two-dimensional array $X$ is the input to the filter bank, the arrays $LL$, $LH$, $HL$, and $HH$ are obtained.\n$LL$ is a smoothed approximation of $X$ (similar to $A_n$ in the one-dimensional case), and the other three arrays contain detail coefficients that capture high-frequency oscillations in\nvertical, horizontal, and diagonal directions.\nThe arrays $LL$, $LH$, $HL$, and $HH$ are known as \\emph{subbands}.\nAny or all of the subbands can be fed into a filter bank to further decompose the signal into different subbands.\nThis decomposition can be represented by a partition of a rectangle, called a \\emph{subband pattern}.\nThe subband pattern for one pass of the filter bank is shown in Figure \\ref{fig:2dsubbands}, with an example of an image decomposition given in Figure \\ref{fig:dwt2D}.\n\n\\begin{figure}[H]\n\\begin{tikzpicture}\n%\\node[draw, thick, minimum size=4cm](-2,-2) square (2,2) []{$A_k$};\n\\draw[thick] (-2,-2) rectangle (2,2);\n\\draw[step=2cm,thick,draw](4,-2) grid (8,2);\n\\draw[thick] (4,-2) -- (8,-2);\n\n\\node[draw=none]()at(0,0){$X$};\n\\node[draw=none]()at(5,1){$LL$};\n\\node[draw=none]()at(7,1){$LH$};\n\\node[draw=none]()at(5,-1){$HL$};\n\\node[draw=none]()at(7,-1){$HH$};\n\\draw[->, >=stealth', thick, shorten <=.2cm, shorten >=.2cm]\n\t(2,0)--(4,0);\n\\end{tikzpicture}\n\\caption{The subband pattern for one step in the 2-dimensional wavelet transform.}\n\\label{fig:2dsubbands}\n\\end{figure}\n\n\\begin{figure}[H]\n% the Mandrill image used to compute these images is found at http://homepages.cae.wisc.edu/~ece533/images/ (baboon.png)\n\\centering\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{figures/mandrill1.png}\n       \\end{subfigure}%\n%    \\hfill\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{figures/mandrill2.png}\n       \\end{subfigure}%\n    \\hfill\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{figures/mandrill3.png}\n       \\end{subfigure}%\n %   \\hfill\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{figures/mandrill4.png}\n       \\end{subfigure}\n    \\caption{Subbands for the mandrill image after one pass through the filter bank.\n    Note how the upper left subband ($LL$) is an approximation of the original Mandrill image, while the other\n    three subbands highlight the stark vertical, horizontal, and diagonal changes in the image.\\\\\n    Original image source: \\url{http://sipi.usc.edu/database/}.}\n    \\label{fig:dwt2D}\n\\end{figure}\n\nThe wavelet coefficients obtained from a two-dimensional wavelet transform are used to analyze and manipulate images at differing levels of resolution.\nImages are often sparsely represented by wavelets; that is, most of the image information is captured by a small subset of the wavelet coefficients.\nThis is the key fact for wavelet-based image compression and will be discussed in further detail later in the lab.\n\n\\section*{The PyWavelets Module} % ============================================\n\nPyWavelets is a Python package designed for wavelet analysis.\nAlthough it has many other uses, in this lab it will primarily be used for image manipulation.\nPyWavelets can be installed using the following command:\n\\begin{lstlisting}\n$ pip install PyWavelets\n\\end{lstlisting}\n\n\\begin{comment}\nThe most recent version of PyWavelets can be installed using the Anaconda distribution with the following code:\n\n\\begin{lstlisting}\n$ conda install -c ioos pywavelets=0.4.0\n\\end{lstlisting}\n\\end{comment}\n\nPyWavelets provides a simple way to calculate the subbands resulting from one pass through the filter bank.\nThe following code demonstrates how to find the approximation and detail subbands of an image.\n\n\\begin{lstlisting}\n>>> from imageio import imread\n>>> import pywt                             # The PyWavelets package.\n# The True parameter produces a grayscale image.\n>>> mandrill = imread('mandrill1.png', True)\n# Use the Daubechies 4 wavelet with periodic extension.\n>>> lw = pywt.dwt2(mandrill, 'db4', mode='per')\n\\end{lstlisting}\n\nThe function \\li{pywt.dwt2()} calculates the subbands resulting from one pass through the filter bank.\nThe \\li{mode} keyword argument sets the extension mode, which determines the type of padding used in the convolution operation.\nFor the problems in this lab, always use \\li{mode='per'}, which is the periodic extension.\nThe second positional argument specifies the type of wavelet to be used in the transform.\nThe function \\li{dwt2()} returns a list.\nThe first entry of the list is the $LL$, or approximation, subband.\nThe second entry of the list is a tuple containing the remaining subbands, $LH$, $HL$, and $HH$ (in that order).\n\\begin{comment}\nThese subbands can be plotted as follows:\n\n\\begin{lstlisting}\n>>> plt.subplot(221)\n>>> plt.imshow(lw[0], cmap='gray')\n>>> plt.axis('off')\n>>> plt.subplot(222)\n# The absolute value of the detail subbands is plotted to highlight contrast.\n>>> plt.imshow(np.abs(lw[1][0]), cmap='gray')\n>>> plt.axis('off')\n>>> plt.subplot(223)\n>>> plt.imshow(np.abs(lw[1][1]), cmap='gray')\n>>> plt.axis('off')\n>>> plt.subplot(224)\n>>> plt.imshow(np.abs(lw[1][2]), cmap='gray')\n>>> plt.axis('off')\n>>> plt.subplots_adjust(wspace=0, hspace=0)      # Remove space between plots.\n\\end{lstlisting}\n\\end{comment}\nAs noted, the second positional argument is a string that gives the name of the wavelet to be used.\nPyWavelets supports a number of different wavelets which are divided into different classes known as families.\nThe supported families and their wavelet instances can be listed by executing the following code:\n\n\\begin{lstlisting}\n>>> # List the available wavelet families.\n>>> print(pywt.families())\n<<['haar', 'db', 'sym', 'coif', 'bior', 'rbio', 'dmey', 'gaus', 'mexh', 'morl', 'cgau', 'shan', 'fbsp', 'cmor']>>\n>>> # List the available wavelets in a given family.\n>>> print(pywt.wavelist('coif'))\n<<['coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'coif6', 'coif7', 'coif8', 'coif9', 'coif10', 'coif11', 'coif12', 'coif13', 'coif14', 'coif15', 'coif16', 'coif17']>>\n\\end{lstlisting}\n\nDifferent wavelets have different properties; the most suitable wavelet is dependent on the specific application.\nFor example, the morlet wavelet is closely related to human hearing and vision.\nNote that not all of these families work with the function \\li{pywt.dwt2()}, because they are continuous wavelets.\n%The best wavelet to use in a particular application is rarely known beforehand.\nChoosing which wavelet is used is partially based on the properties of a wavelet, but since many wavelets share desirable properties, the best wavelet for a particular application is often not known until\nsome type of testing is done.\n%See Figure \\ref{fig:more_wavelets} for the plots of some of additional wavelets.\n\n\\begin{comment}\n\\begin{figure}\n\\begin{subfigure}[b]{0.45\\textwidth}\n    \\includegraphics[width=\\textwidth]{figures/mexicanHat}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.45\\textwidth}\n    \\includegraphics[width=\\textwidth]{figures/db5_3}\n\\end{subfigure}\n\\caption{Mexican Hat and Daubechies 4 mother wavelets.}\n\\label{fig:more_wavelets}\n\\end{figure}\n\\end{comment}\n\n\\begin{problem}\nExplore the two-dimensional wavelet transform by completing the following:\n\\begin{enumerate}\n    \\item Save a picture of a raccoon with the following code\n\\begin{lstlisting}\n>>> from scipy.misc import face\n>>> racoon = face(True)\n\\end{lstlisting}\n    \\item Plot the subbands of raccoon as described above (using the Daubechies 4 wavelet with periodic extension).\n        Compare this with the subbands of the mandrill image shown in Figure \\ref{fig:dwt2D}.\n    \\item Compare the subband patterns of the haar, symlet, and coiflet wavelets by plotting the $LH$ subband pattern using the picture of the raccoon.\n    The haar subband should have more detail than the symlet subband, and the symlet subband should have more detail than the coiflet wavelet.\n\\end{enumerate}\n\\end{problem}\n\nThe function \\li{pywt.wavedec2()} is similar to \\li{pywt.dwt2()}, but it also includes a keyword argument, \\li{level}, which specifies the number of times to pass an image through the filter bank.\nIt will return a list of subbands, the first of which is the final approximation subband, while the remaining elements are tuples which contain sets of detail subbands ($LH$, $HL$, and $HH$).\nIf \\li{level} is not specified, the number of passes through the filter bank will be determined at runtime.\nThe function \\li{pywt.waverec2()} accepts a list of subband patterns (like the output of \\li{pywt.wavedec2()} or \\li{pywt.dwt2()}), a name string denoting the wavelet, and a keyword argument\n\\li{mode} for the extension mode.\nIt returns a reconstructed image using the reverse filter bank.\nWhen using this function, be sure that the wavelet and mode match the deconstruction parameters.\nPyWavelets has many other useful functions including \\li{dwt()}, \\li{idwt()} and \\li{idwt2()} which can be explored further in the documentation for PyWavelets, \\url{http://pywavelets.readthedocs.io/en/latest/contents.html}.\n\n\n\n\\begin{comment} %A more simplified image processing technique, it works but it is very easy to implement and it is not very interesting.\nIf this is included in the future, consider setting the coefficients of the final detail level to 0 instead of removing them from the reconstruction.\nThis gives similar results without reducing the size of the image.\n\\section*{Image Processing}\nWe are now ready to use the two-dimensional wavelet transform for image processing.\nWavelets are especially good at filtering out high-frequency noise from an image.\nJust as we were able to pinpoint the noise added to the sine wave in Figure \\ref{fig:dwt1D}, the majority of the noise added to an image will be contained in the final $LH$, $HL$, and $HH$ detail subbands of our wavelet decomposition.\nIf we decompose our image and reconstruct it with all subbands except these final subbands, we will eliminate most of the troublesome noise while preserving the primary aspects of the image.\n\nWe perform this cleaning as follows:\n\\begin{lstlisting}\nimage = imread(filename,True)\nwavelet = pywt.Wavelet('haar')\nWaveletCoeffs = pywt.wavedec2(image,wavelet)\nnew_image = pywt.waverec2(WaveletCoeffs[:-1], wavelet)\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function called \\li{clean_image()} which accepts the name of a grayscale image file and cleans high-frequency noise out of the image.\nLoad the image as an ndarray, and perform a wavelet decomposition using PyWavelets.\nReconstruct the image using all subbands except the last set of detail coefficients, and return this cleaned image as an ndarray.\n\\end{problem}\n\\end{comment}\n\n\n\\section*{Applications}\n\n\\subsection*{Noise Reduction}\nNoise in an image is defined as unwanted visual artifacts that obscure the true image.\nImages acquire noise from a variety of sources, including cameras, data transfer, and image processing algorithms.\n%Noise can be completely random and incoherent (as in Figure \\ref{fig:incoherent}), or it can be coherent and display visual patterns (Figure \\ref{fig:coherent}).\nThis section will focus on reducing a particular type of noise in images called \\emph{Gaussian white noise}.\n\n%\\begin{figure}[t]\n%\\minipage{0.49\\textwidth}\n%    \\includegraphics[width=\\linewidth]{figures/phantom_random.pdf}\n%    \\caption{The Phantom image with incoherent noise}\n%    \\label{fig:incoherent}\n%\\endminipage\\hfill\n%\\minipage{0.49\\textwidth}\n%    \\includegraphics[width=\\linewidth]{figures/phantom_coherent.pdf}\n%    \\caption{The Phantom image with coherent noise}\n%    \\label{fig:coherent}\n%\\endminipage\n%\\end{figure}\n\nGaussian white noise causes every pixel in an image to be perturbed by a small amount. % such that the perturbations are normally distributed.\nMany types of noise, including Gaussian white noise, are very high-frequency.\nSince many images are relatively sparse in high-frequency domains, noise in an image can be safely removed from the high frequency subbands while minimally distorting the true image.\nA basic, but effective, approach to reducing Gaussian white noise in an image is thresholding.\nThresholding can be done in two ways, referred to as hard and soft thresholding.\n\nGiven a positive threshold value $\\tau$, hard thresholding sets every wavelet coefficient whose magnitude is less than $\\tau$ to zero, while leaving the remaining coefficients untouched.\nSoft thresholding also zeros out all coefficients of magnitude less than $\\tau$, but in addition maps the remaining positive coefficients $\\beta$ to $\\beta - \\tau$ and the remaining negative coefficients\n$\\alpha$ to $\\alpha + \\tau$.\n\n\\begin{comment}\nImplementing these simple thresholding algorithms in Python is straight-forward, but PyWavelets already provides this functionality.\nThe following code gives an example.\n\n\\begin{lstlisting}\n>>> A = np.arange(-4,5).reshape(3,3)\n>>> A\narray([[-4, -3, -2],\n       [-1,  0,  1],\n       [ 2,  3,  4]])\n>>> pywt.thresholding.hard(A,1.5)\narray([[-4, -3, -2],\n       [ 0,  0,  0],\n       [ 2,  3,  4]])\n>>> pywt.thresholding.soft(A,1.5)\narray([[-2.5, -1.5, -0.5],\n       [ 0. ,  0. ,  0. ],\n       [ 0.5,  1.5,  2.5]])\n\\end{lstlisting}\n\\end{comment}\n\nOnce the coefficients have been thresholded, the inverse wavelet transform is used to recover the denoised image.\n%This can be done by calling the \\li{waverec2} function, providing the list of Wavelet coefficients as well as the name of the desired Wavelet as arguments.\nThe threshold value is generally a function of the variance of the noise, and in real situations, is not known.\nIn fact, noise variance estimation in images is a research area in its own right, but that goes beyond the scope of this lab.\n\n%\\begin{figure}[t]\n%    \\includegraphics[width=\\linewidth]{figures/denoise.pdf}\n%    \\caption{Noisy Lena (left), denoised using hard thresholding (center), and denoised using soft thresholding (right).}\n%    \\label{fig:denoise}\n%\\end{figure}\n\n\\begin{problem}\nWrite two functions that accept a list of wavelet coefficients in the usual form, as well as a threshold value. Each function returns the thresholded wavelet coefficients (also in the usual form). The first function should implement hard thresholding and the second should implement soft thresholding.\nWhile writing these two functions, remember that only the detail coefficients are thresholded, so the first entry of the input coefficient list should remain unchanged.\n\nTo test your functions, perform hard and soft thresholding on \\texttt{noisy\\_darkhair.png} and plot the resulting images together.\nWhen testing your function, use the Daubechies 4 wavelet and four sets of detail coefficients (\\li{level=4} when using \\li{wavedec2()}).\nFor soft thresholding use $\\tau=20$, and for hard thresholding use $\\tau=40$.\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nCreate a noisy version of the Lena image by adding Gaussian\nwhite noise of mean 0 and standard deviation $\\sigma = 20$ (i.e. \\li{scale=20}).\nCompute four levels of the wavelet coefficients using the Daubechies 4 Wavelet,\nand input these into your\nthresholding functions (with $\\tau = 3\\sigma$ for the hard threshold,\nand $\\tau = 3\\sigma/2$ for the soft threshold). Reconstruct the\ntwo denoised images, and then plot these together alongside the\nnoisy image. Your output should match Figure \\ref{fig:denoise}.\n\nWhat do you notice? How does lowering or raising the\nthreshold affect the reconstructed images? What happens if you use\na different Wavelet?\n\\end{problem}\n\\end{comment}\n\n\n\\subsection*{Image Compression} % ---------------------------------------------\n\nTransform methods based on Fourier and wavelet analysis play an important role in image compression; for example, the popular JPEG image compression standard is based on the discrete cosine transform.\nThe JPEG2000 compression standard and the FBI Fingerprint Image database, along with other systems, take the wavelet approach.\n\nThe general framework for compression is as follows.\nFirst, the image to be compressed undergoes some form of preprocessing, depending on the particular application.\nNext, the discrete wavelet transform is used to calculate the wavelet coefficients, and these are then \\emph{quantized}, i.e. mapped to a set of discrete values (for example, rounded to the nearest integer).\nThe quantized coefficients are then passed through an entropy encoder (such as Huffman Encoding), which reduces the number of bits required to store the coefficients.\nWhat remains is a compact stream of bits that can be saved or transmitted much more efficiently than the original image.\nThe steps above are nearly all invertible (the only exception being quantization), allowing the original image to be almost perfectly reconstructed from the compressed bitstream.\nSee Figure \\ref{tikz:wsqscheme}.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[rect/.style= {draw=none, node distance = 3cm},\n\trect2/.style = {draw, thick, minimum width=3cm, minimum\n\theight=1cm}, >=stealth', shorten >=2pt]\n\n\\node[rect] (IM) [] {Image};\n\\node[rect2, node distance=3cm] (PR) [right of = IM]\n\t{Pre-Processing};\n\\node[rect2, node distance=4.5cm] (WD)[right of= PR]\n\t{Wavelet Decomposition};\n\\node[rect2, node distance=1.75cm](Q) [below=of PR.west, anchor=west]\n\t{Quantization};\n\\node[rect2, node distance = 1.75cm](EC)[below=of WD.west, anchor=west]\n\t{Entropy Coding};\n\\node[rect, node distance= 3.5cm](BS)[right of=EC]\n\t{Bit Stream};\n\n\\foreach \\s/\\t in {IM/PR, PR/WD, Q/EC, EC/BS}\n\t{\\path[->, thick](\\s) edge (\\t);}\n\\draw[|-,-|,->, thick](WD.south) |-+(0,-1em)-| (Q.north);\n\n\n\\end{tikzpicture}\n\\caption{Wavelet Image Compression Schematic}\n\\label{tikz:wsqscheme}\n\\end{figure}\n\n%\\begin{comment}\n\n\\subsection*{WSQ: The FBI Fingerprint Image Compression Algorithm} % ----------\n\nThe Wavelet Scalar Quantization (WSQ) algorithm is among the first successful wavelet-based image compression algorithms.\nIt solves the problem of storing millions of fingerprint scans efficiently while meeting the law enforcement requirements for high image quality.\nThis algorithm is capable of achieving compression ratios in excess of 10-to-1 while retaining excellent image quality; see Figure \\ref{fig:finger_compression}.\nThis section of the lab steps through a simplified version of this algorithm by writing a Python class that performs both the compression and decompression.\nDifferences between this simplified algorithm and the complete algorithm are found in the Additional Material section at the end of this lab.\nAlso included in Additional Materials is a more thorough explanation of all the methods in the WSQ class.\n%Most of the methods of the class have already been implemented, the following problems will detail the methods you will need to implement yourself.\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.32\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{figures/uncompressed_finger.png}\n  \\caption{Uncompressed}\n\\end{subfigure}%\n\\begin{subfigure}{.32\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{figures/compressed_finger(30comp).png}\n  \\caption{12:1 compressed}\n\\end{subfigure}%\n\\begin{subfigure}{.32\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{figures/compressed_finger(60comp).png}\n  \\caption{26:1 compressed}\n\\end{subfigure}\n\\caption{Fingerprint scan at different levels of compression.\\\\\nOriginal image source: \\url{http://www.nist.gov/itl/iad/ig/wsq.cfm}.\n}\n\\label{fig:finger_compression}\n\\end{figure}\n\n\\subsubsection*{WSQ: Preprocessing}\nPreprocessing in this algorithm ensures that roughly half of the new pixel values are negative, while the other half are positive, and all fall in the range $[-128,\\,128]$.\nThe input to the algorithm is a matrix of nonnegative 8-bit integer values giving the grayscale pixel values for the fingerprint image.\nThe image is processed by the following formula:\n\\[\nM' = \\frac{M-m}{s},\n\\]\nwhere $M$ is the original image matrix, $M'$ is the processed image, $m$ is the mean pixel value, and $s = \\max\\{\\max(M) - m, m - \\min(M)\\}/128$\n(here $\\max(M)$ and $\\min(M)$ refer to the maximum and minimum pixel values in the matrix).\n\n\n\\begin{comment}\nTo get the mean, min, and max of an array, and the max of two elements,\nwe use the following commands:\n\\begin{lstlisting}\n>>> # assume we have an array M, numerical values a and b\n>>> M.mean()\n>>> M.max()\n>>> M.min()\n>>> max(a,b)\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{problem}\nImplement the preprocessing step as well as its inverse by implementing the class methods \\li{pre_process()} and \\li{post_process()}.\nEach method accepts a NumPy array (the image) and returns the processed image as a NumPy array.\nIn the \\li{pre_process()} method, calculate the values of $m$ and $s$ given above and store them in the class attributes \\li{_m} and \\li{_s}.\n\\end{problem}\n\n\\subsubsection*{WSQ: Calculating the Wavelet Coefficients}\nThe next step in the compression algorithm is decomposing the image into subbands of wavelet coefficients.\nIn this implementation of the WSQ algorithm, the image is decomposed into five sets of detail coefficients (\\li{level=5}) and one approximation subband, as shown in Figure \\ref{fig:wavelets-subbands}.\nEach of these subbands should be placed into a list in the same ordering as in Figure \\ref{fig:wavelets-subbands} (another way to consider this ordering is the approximation subband followed by\neach level of detail coefficients $[LL_5, LH_5, HL_5, HH_5, LH_4, HL_4,\\dots ,HH_1]$).\n\n\\begin{problem}\nImplement the class method \\li{decompose()}.\nThis function should accept an image to decompose and should return a list of ordered subbands.\nUse the function \\li{pywt.wavedec2()} with the \\li{'coif1'} wavelet to obtain the subbands.\nThese subbands should then be ordered in a single list as described above.\n\nImplement the inverse of the decomposition by writing the class method \\li{recreate()}.\nThis function should accept a list of 16 subbands (ordered like the output of \\li{decompose()}) and should return a reconstructed image.\nUse \\li{pywt.waverec2()} to reconstruct an image from the subbands.\nNote that you will need to adjust the accepted list in order to adhere to the required input for \\li{waverec2()}.\n\\end{problem}\n\n\\begin{figure}[H]\n\\begin{center}\n\\begin{tikzpicture}[scale=.60,thick]\n\n%Draw the grids - largest to smallest\n\\draw[step=8cm,draw] (0,0) grid (16,16);\n\\draw[step=4cm,draw] (0,8) grid (8,16);\n\\draw[draw,step=2cm] (0,12) grid (4,16);\n\\draw[draw,step=1cm] (0,14) grid (2,16);\n\\draw[draw,step=.5] (0,15) grid(1,16);\n%Nodes for the numbers\n\\foreach \\x/\\y/\\t in {.25/15.75/0,.75/15.75/1,.25/15.25/2,.75/15.25/3,1.5/15.5/4,.5/14.5/5,1.5/14.5/6,3/15/7,1/13/8,3/13/9,6/14/10,2/10/11,6/10/12,12/12/13,4/4/14,12/4/15} \\node at (\\x,\\y) {$\\t$};\n\n\\end{tikzpicture}\n\n\\caption{Subband Pattern for simplified WSQ algorithm.}\n\\label{fig:wavelets-subbands}\n\\end{center}\n\\end{figure}\n\n\\subsubsection*{WSQ: Quantization}\nQuantization is the process of mapping each wavelet coefficient to an integer value and is the main source of compression in the algorithm.\nBy mapping the wavelet coefficients to a relatively small set of integer values, the complexity of the data is reduced, which allows for efficient encoding of the information in a bit string.\nFurther, a large portion of the wavelet coefficients will be mapped to 0 and discarded completely.\nThe fact that fingerprint images tend to be very nearly sparse in the wavelet domain means that little information is lost during quantization.\nCare must be taken, however, to perform this quantization in a manner that achieves good compression without discarding so much information that the image cannot be accurately reconstructed.\n\nGiven a wavelet coefficient $a$ in subband $k$, the corresponding quantized coefficient $p$ is given by\n\\[\np =\n\\begin{cases}\n   \\left\\lfloor\\frac{a-Z_k/2}{Q_k}\\right\\rfloor + 1, & a> Z_k/2 \\\\\n   0,       & -Z_k/2 \\leq a \\leq Z_k/2\\\\\n   \\left\\lceil\\frac{a + Z_k/2}{Q_k}\\right\\rceil - 1, & a < -Z_k/2.\n  \\end{cases}\n\\]\nThe values $Z_k$ and $Q_k$ are dependent on the subband, and determine how much compression is achieved.\nIf $Q_k=0$, all coefficients are mapped to 0.\n\nSelecting appropriate values for these parameters is a tricky problem in itself, and relies on heuristics based on the statistical properties of the wavelet coefficients.\nTherefore, the methods that calculate these values have already been initialized.\n\nQuantization is not a perfectly invertible process.\nOnce the wavelet coefficients have been quantized, some information is permanently lost.\nHowever, wavelet coefficients $\\hat{a}_k$ in subband $k$ can be roughly reconstructed from the quantized coefficients $p$ using the following formula.\nThis process is called \\emph{dequantization}.\n\\[\n\\hat{a}_k =\n\\begin{cases}\n(p-C)Q_k + Z_k/2, & p> 0\\\\\n0, & p = 0\\\\\n(p + C)Q_k - Z_k/2, & p < 0\n\\end{cases}\n\\]\nNote the inclusion of a new dequantization parameter $C$.\nAgain, if $Q_k = 0$, $\\hat{a}_k = 0$ should be returned.\n\n\\begin{problem}\nImplement the quantization step by writing the \\li{quantize()} method of your class.\nThis method should accept a NumPy array of coefficients and the quantization parameters $Q_k$ and $Z_k$.\nThe function should return a NumPy array of the quantized coefficients.\n\nAlso implement the \\li{dequantize()} method of your class using the formula given above.\nThis function should accept the same parameters as \\li{quantize()} as well as a parameter $C$ which defaults to $.44$.\nThe function should return a NumPy array of dequantized coefficients.\n\nMasking and array slicing will help keep your code short and fast when implementing both of these methods.\nRemember the case for $Q_k=0$.\nTest your functions by comparing the output of your functions to a hand calculation on a small matrix.\n%You may wish to make use of the array slicing techniques demonstrated below:\n%\\begin{lstlisting}\n%>>> # assume X, Y are numpy arrays of same shape\n%>>> m = X < -2 # create mask for entries less than -2\n%>>> Y[m] = np.ceil(X[m]) + 2 # set corresponding entries of Y\n%\\end{lstlisting}\n\\end{problem}\n\n\\subsubsection*{WSQ: The Rest}\nThe remainder of the compression and decompression methods have already been implemented in the WSQ class.\nThe following discussion explains the basics of what happens in those methods.\nOnce all of the subbands have been quantized, they are divided into three groups.\nThe first group contains the smallest ten subbands (positions zero through nine), while the next two groups contain the three subbands of next largest size (positions ten through twelve and\nthirteen through fifteen, respectively).\nAll of the subbands of each group are then flattened and concatenated with the other subbands in the group.\nThese three arrays of values are then mapped to Huffman indices.\nSince the wavelet coefficients for fingerprint images are typically very sparse, special indices are assigned to lists of sequential zeros of varying lengths.\nThis allows large chunks of information to be stored as a single index, greatly aiding in compression.\nThe Huffman indices are then assigned a bit string representation through a Huffman map.\nPython does not natively include all of the tools necessary to work with bit strings, but the Python package bitstring does have these capabilities.\nDownload bitstring using the following command:\n\\begin{lstlisting}\n$ pip install bitstring\n\\end{lstlisting}\nImport the package with the following line of code:\n\\begin{lstlisting}\n>>> import bitstring as bs\n\\end{lstlisting}\n\n\n\\begin{comment}\n\\subsubsection*{WSQ: Grouping}\nAt this point in the algorithm, we have a list of 64 arrays, where the $k$-th\nentry is a matrix containing the quantized wavelet coefficients for the $k$-th subband.\nThe remaining steps in the algorithm focus on entropy coding these quantized\ncoefficients to further increase compression.\nAs such, we have finished with the wavelet analysis portion.\n\nWe will segment the list of quantized subbands into three groups.\nThis gives three lists of quantized coefficients, each having a high degree of homogeneity.\nThis is important for the entropy coding, since we can achieve better compression by separately encoding groups of similar coefficients.\n\nGroup quantized subbands $0$ through $18$ together, $19$ through $51$ together, and finally $52$ through $63$ together.\nYou may understand the logic of these groupings when glancing back at Figure \\ref{fig:wavelets-subbands2}.\nWhen grouping subbands together, flatten each subband and concatenate their entries together, so that you obtain a simple list of integer values.\nSince we are flattening and then concatenating the subbands, we need to save the shape of the original subbands, so that we can later\nreconstruct the subbands from the groups of coefficients.\nFinally, we will not include subbands that consist entirely of zeros, as these contain no information and thus don't need to be stored.\nTherefore, while looping through the subbands and creating the lists of coefficients, include a check for nonzero entries in the subband,\nand also create a list of boolean values for each group whose $i$-th entry indicates whether the $i$-th subband in the group was included.\n\nBelow is sample code for producing the first group.\nUse a similar approach for the other two groups.\n\\begin{lstlisting}\n>>> # assume subbands is my list of the 64 quantized subbands\n>>> g1 = []     # this will hold the group 1 coefficients\n>>> s1 = []     # keep track of the subband dimensions in group 1\n>>> t1 = []     # keep track of which subbands were included\n>>> for i in xrange(19):\n>>>     s1.append(subbands[i].shape)\n>>>     if subbands[i].any(): # True if any nonzero entry\n>>>         g1.extend(subbands[i].ravel())\n>>>         t1.append(True)\n>>>     else: # the subband was not transmitted\n>>>         t1.append(False)\n\\end{lstlisting}\n\nTo reconstruct the subbands from \\li{g1}, \\li{s1}, and \\li{t1}, we have the following code:\n\\begin{lstlisting}\n>>> # reconstruct the subbands in group 1\n>>> subbands1 = []     # the reconstructed subbands in group 1\n>>> i = 0\n>>> for j, shape in enumerate(s1):\n>>>     if t1[j]: # if the j-th subband was included\n>>>         l = shape[0]*shape[1] # number of entries in the subband\n>>>         subbands1.append(np.array(g1[i:i+l]).reshape(shape))\n>>>         i += l\n>>>     else: # the j-th subband wasn't included, so all zeros\n>>>         subbands1.append(np.zeros(shape))\n\\end{lstlisting}\n\\begin{problem}\nCarry out the grouping procedure and its inverse as described above by implementing the li\\{_group} and \\li{ungroup} class methods:\n\nNote that we need the shapes and the boolean lists indicating which subbands were included\nfor the un-grouping step.\nThus, in the \\li{compress} method, once we computed these tuples of lists, we store them in the class attributes \\li{_shapes}\nand \\li{_tvals}, respectively.\n\\begin{lstlisting}\n>>> groups, self._shapes, self._tvals = self._group(q_subbands)\n\\end{lstlisting}\n\\end{problem}\n\n\\subsubsection*{WSQ: From Quantized Coefficients to Huffman Indices}\nWe now have three groups of integer-valued quantized coefficients.\nIt remains to encode each of these three groups using Huffman coding.\n\nNote that each group is likely to contain many consecutive zeros, since we have rounded all of the smallest wavelet coefficients to zero.\nThere will also be a few quantized coefficients of high magnitude.\nThe remaining nonzero coefficients will have values between $-73$ and $74$.\nWith this in mind, we can represent these groups of coefficients even more tersely by mapping them to a set of discrete values (integers from $0$ to $253$), which we call \\emph{Huffman Indices}.\nThe mapping between Huffman indices and quantized coefficients is given in Table \\ref{table:huffIndex}.\n\\begin{table}\n\\begin{tabular}{|c|c|}\n\\hline\n\\textbf{Huffman Index} & \\textbf{Quantized Coefficient}\\\\\\hline\n0 & zero run length 1\\\\\\hline\n1 & zero run length 2\\\\\\hline\n\\vdots & \\vdots\\\\\\hline\n99 & zero run length 100\\\\\\hline\n100 & $75\\leq q \\leq 255$\\\\\\hline\n101 & $-255 \\leq q \\leq -74$\\\\\\hline\n102 & $256 \\leq q \\leq 65535$\\\\\\hline\n103 & $-65535 \\leq q \\leq -256$\\\\\\hline\n104 & zero run of length $101\\leq n \\leq 255$\\\\\\hline\n105 & zero run of length $255\\leq n \\leq 65535$\\\\\\hline\n106 & -73\\\\\\hline\n107 & -72\\\\\\hline\n108 & -71\\\\\\hline\n\\vdots & \\vdots\\\\\\hline\n179 & 0 \\emph{(use index 0)}\\\\\\hline\n\\vdots & \\vdots \\\\\\hline\n252 & 73\\\\\\hline\n253 & 74\\\\\\hline\n\\end{tabular}\n\\caption{The mapping between Huffman indices and quantized coefficients.}\n\\label{table:huffIndex}\n\\end{table}\n\nTo see how this mapping works, suppose that we have the following list of quantized coefficients:\n\\[\n[0, 0, 0, 0, -45, 13, 103, -269, 0]\n\\]\nThe list starts off with a zero run of length $4$, so the first Huffman index is $3$ (each zero run of length $n$ where $n\\leq 100$ get a Huffman index of $n-1$).\nThe next coefficient is $-45$, so we infer from the Table that its Huffman index is $-45 + (106+73) = 134$.\nThe next coefficient is $13$, so as before, its Huffman index is $13 + 179 = 192$.\nThe final three indices are $100$, $103$, and $0$.\n\nNote that this mapping is not one-to-one when dealing with zero runs of lengths greater than $100$, or with coefficients of sufficiently large magnitudes (the Huffman indices for these cases are 100 through 105).\nWe refer to these cases as \\emph{exceptional cases}.\nWhen we encounter exceptional cases, we need to store the length of the zero run or the magnitude of the coefficient, so that we can perfectly reconstruct the quantized coefficients at the decompression stage.\nHence, while generating a list of the Huffman indices for each group, we also generate a list of extra values for the exceptional cases.\n\nFinally, as we generate the list of Huffman indices from the quantized coefficients, we also tabulate the frequency of each index, as this is necessary when building a Huffman Encoder.\n\n\\begin{problem}\nExamine the code for \\li{_huffmanIndices} to make sure you understand it, and add it to your class.\n\\end{problem}\n\nIn the decompression stage, we need to recover the quantized coefficients from the Huffman Indices.\nAs noted before, the mapping is not one-to-one for the exceptional cases, so we need both the list of indices and the extra values.\nGiven these two lists, it is not difficult to recover the coefficients.\n\n\\begin{problem}\nExamine the code for \\li{_indicesToCoeffs} for understanding, and then add the method to your class.\n\\end{problem}\n\n\\subsubsection*{Reading and Writing Bits with bitstring}\nIn the final stage of the algorithm, we take our lists of Huffman indices and map them to bit patterns.\nPure Python is not equipped to manipulate data at the bit level, so we will use the Python package \\li{bitstring} to facilitate the process.\nIn this section we present the functions required for the WSQ algorithm.\n\nOnce you have installed the package, type the import command:\n\\begin{lstlisting}\n>>> import bitstring as bs\n\\end{lstlisting}\nIn order to build a string of bits, we initialize a \\li{BitArray} object, and then add the desired bit patterns.\n\\begin{lstlisting}\n>>> bits = bs.BitArray()\n>>> # add bit patterns 1101 and 01\n>>> bits.append('0b1101')\n>>> bits.append('0b01')\n\\end{lstlisting}\nNote that the string containing the bit pattern must begin with \\li{'0b'}.\n\nWe can add an 8- or 16-bit representations of an integer as follows:\n\\begin{lstlisting}\n>>> # add the 8-bit integer 212, and then the 16-bit integer 1047\n>>> bits.append('uint:8=212')\n>>> bits.append('uint:16=1047')\n\\end{lstlisting}\nTo view the bits contained in the \\li{BitArray}, we can print the \\li{bin} attribute.\n\\begin{lstlisting}\n>>> # view the entire bit string\n>>> print bits.bin\n110101110101000000010000010111\n\\end{lstlisting}\n\nWhen reading the data from a bit stream, we use a \\li{bs.ConstBitStream} object, and call its \\li{read} method, giving it an input string that specifies the way to interpret the bits, and the number of bits to read.\nTo read the next 3 bits as binary, the input string would be \\li{'bin:3'}, whereas to read the next 16 bits as an unsigned integer you would provide the input string \\li{'uint:16'}.\nLet's read the first 6 bits of \\li{bits}, one at a time:\n\\begin{lstlisting}\n>>> bitreader = bs.ConstBitStream(bits)\n>>> for i in xrange(6):\n>>>     print bitreader.read('bin:1')\n1\n1\n0\n1\n0\n1\n\\end{lstlisting}\nWe know that the next 8 bits should be interpreted as an unsigned integer, and likewise for the\nfollowing 16 bits. Thus, we read these bits as follows:\n\\begin{lstlisting}\n>>> print bitreader.read('uint:8')\n212\n>>> print bitreader.read('uint:16')\n1047\n\\end{lstlisting}\n\nYou now have all the tools necessary to read and write the compressed image bit stream.\n\n\\subsubsection*{WSQ: Huffman Coding}\nHuffman coding is a technique for assigning binary codes to a collection of symbols in such a way that minimizes the total number of bits needed to encode the symbols.\nMore frequent symbols will be assigned shorter binary codes, while rare symbols will have longer codes.\nOne simple way to implement Huffman Coding is to build a binary tree, whose leaves correspond to the different symbols to be encoded.\nWe then traverse the tree from the root down to each leaf node to generate the binary codes (left corresponds to 0, right corresponds to 1).\nThe provided classes and functions \\li{huffmanLeaf()}, \\li{huffmanNode()} and \\li{huffman()} implement this.\n\n\nWhen we pass a list of Huffman indices to the function \\li{huffman()}, we obtain obtain a dictionary (called the Huffman map) whose keys are the integers 0 through 253 (the Huffman indices)\nand whose values are the bit pattern assigned to each Huffman index.\nThis Huffman map, together with the list of Huffman indices and extra values, allows us to encode the quantized coefficients as a bit string.\n\n\\begin{problem}\nAdd the \\li{_encode()} method to your class.\nImplement the Huffman coding step in the \\li{compress} method by calculating the Huffman indices, Huffman map, and bit string for each group of quantized coefficients separately.\nStore the resulting three bit strings and Huffman maps in the class attributes \\li{_bitstrings} and \\li{_huff_maps}.\nUse the following code block as a guide.\n\\begin{lstlisting}\n>>> # assume groups is a list of the three groups of coefficients\n>>> # for each group, get huffman indices, create huffman tree, and encode\n>>> huff_maps = []\n>>> bitstrings = []\n>>> for i in xrange(3):\n>>>     inds, freqs, extra = self._huffmanIndices(groups[i])\n>>>     huff_map = huffman(freqs)\n>>>     huff_maps.append(huff_map)\n>>>     bitstrings.append(self._encode(inds, extra, huff_map))\n>>>\n>>> # store the bitstrings and the huffman maps\n>>> self._bitstrings = bitstrings\n>>> self._huff_maps = huff_maps\n\\end{lstlisting}\nYou have now fully implemented the compression algorithm!\n\\end{problem}\n\nFor decompression, we need to decode the bit strings back to Huffman indices.\nThis is straight-forward enough using the Huffman maps.\nEssentially, we read the bit string one bit at a time, check to see if we have a bit pattern found in the Huffman map, and if so, store the corresponding Huffman index in the list of Huffman indices.\nIf the Huffman index is an exceptional case, we read the next 8 or 16 bits from the bit string (depending on the exact value of the index), and store the resulting value in the list of extra values.\nExamine the implementation below for understanding:\n\n\\begin{problem}\nAdd the \\li{_decode()} method to your class.\n\\end{problem}\n\n\\subsubsection*{WSQ: Decompression}\nDecompression refers to recovering the original image from the bit encodings of the quantized wavelet coefficients.\nYou already have all of the methods required for decompression; what remains is to put them together.\n\\begin{problem}\nAdd the \\li{decompress()} method to your class.\n\\end{problem}\n\\end{comment}\n\n\\subsubsection*{WSQ: Calculating the Compression Ratio}\nThe methods of compression and decompression are now fully implemented. The final task is to verify how much compression has taken place.\nThe compression ratio is the ratio of the number of bits in the original image to the number of bits in the encoding.\nAssuming that each pixel of the input image is an 8-bit integer, the number of bits in the image is just eight times the number of pixels\n(the number of pixels in the original source image is stored in the class attribute \\li{_pixels}).\nThe number of bits in the encoding can be calculated by adding up the lengths of each of the three bit strings stored in the class attribute \\li{_bitstrings}.\n\\begin{problem}\nImplement the method \\li{get_ratio()} by calculating the ratio of compression.\nThe function should not accept any parameters and should return the compression ratio.\n\nYour compression algorithm is now complete!\nYou can test your class with the following code:\n\\begin{lstlisting}\n# Try out different values of r between .1 to .9.\nr = .5\nfinger = imread('uncompressed_finger.png', True)\nwsq = WSQ()\nwsq.compress(finger, r)\nprint(wsq.get_ratio())\nnew_finger = wsq.decompress()\nplt.subplot(211)\nplt.imshow(finger, cmap=plt.cm.Greys_r)\nplt.subplot(212)\nplt.imshow(np.abs(new_finger), cmap=plt.cm.Greys_r)\nplt.show()\n\\end{lstlisting}\n\\end{problem}\n\\newpage\n\n\\section*{Additional Material} %-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\\subsection*{Haar Wavelet Transform}\nThe Haar Wavelet is a general matrix transform used to convolve Haar Wavelets.\nIt is found by combining the convolution matrices for a lowpass and highpass filter such that one is directly on top of the other.\nThe lowpass filter is taking the average of every two elements in an array and the highpass filter is taking the difference of every two elements in an array.\nRedundant information given in the new matrix is then removed via downsampling.\nHowever, in order for the transform matrix to have the property $A^T=A^{-1}$, the columns of the matrix must be normalized.\nThus, each column is normalized (and subsequently the filters) and the resulting matrix is the Haar Wavelet Transform.\n\nFor more on the Haar Wavelet Transform, see \\emph{Discrete Wavelet Transformations: An Elementary Approach with Applications} by Patrick J. Van Fleet.\n\n\\subsection*{WSQ Algorithm}\nThe official standard for the WSQ algorithm is slightly different from the version implemented in this lab.\nOne of the largest differences is the subband pattern that is used in the official algorithm; this pattern is demonstrated in Figure \\ref{fig:wavelets-subbands2}.\nThe pattern used may seem complicated and somewhat arbitrary, but it is used because of the relatively good empirical results when used in compression.\nThis pattern can be obtained by performing a single pass of the 2-dimensional filter bank on the image then passing each of the resulting subbands through the filter bank resulting in 16 total subbands.\nThis same process is then repeated with the $LL$, $LH$ and $HL$ subbands of the original approximation subband creating 46 additional subbands.\nFinally, the subband corresponding to the top left of Figure \\ref{fig:wavelets-subbands2} should be passed through the 2-dimensional filter bank a single time.\n\n\\begin{comment}\nWe need to calculate the subband pattern found in Figure \\ref{fig:wavelets-subbands2}.\nThis subband pattern is somewhat arbitrary, but is used because of its empirically good results in compression.\nWhile the pattern may appear complicated at first, we can obtain the required subband coefficients rather easily.\nTo start, decompose the image into 16 subbands, first by using the \\li{dwt2} function to split the image into four subbands, and then applying the function again to each of the four subbands.\n\nUsing the function \\li{_decompose16} on the fingerprint image, you should now have a grid of 16 subbands.\nNext, split each of the three subbands found in the top left corner of the subband grid into 16 additional subbands, in the same way as before.\nYou now have a grid of $13 + 3(16) = 61$ subbands.\n\nFinally, take the very top left subband, and split this into four additional subbands.\nYou should have 64 subbands. Place them into a list in the order indicated by the numbers in Figure \\ref{fig:wavelets-subbands2}.\n\\end{comment}\n\nAs in the implementation given above, the subbands of the official algorithm are divided into three groups.\nThe subbands 0 through 18 are grouped together, as are 19 through 51 and 52 through 63.\nThe official algorithm also uses a wavelet specialized for image compression that is not included in the PyWavelets distribution.\nThere are also some slight modifications made to the implementation of the discrete wavelet transform that do not drastically affect performace.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[scale=.65]\n\\draw [draw, step=1cm, thick] (0,8) grid (4,12);\n\\draw[draw, thick, step=1cm] (0,12) grid (8,16);\n\\draw[step=4cm, thick, draw](0,0) grid (16,16);\n\\draw[draw, step=.5,thick](0,15)grid(1,16);\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y))] in {0, 1}{\n\n\\node[draw=none]()at(.25+.5*\\x,15.75-.5*\\y){\\r};\n\t};\n\t};\n\n\\node[draw=none]()at(1.5, 15.5){4};\n\\node[draw=none]()at(.5,14.5){5};\n\\node[draw=none]()at(1.5,14.5){6};\n\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 7)] in {0, 1}{\n\n\\node[draw=none]()at(2.5+1*\\x,15.5-1*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 7)] in {0, 1}{\n\n\\node[draw=none]()at(2.5+1*\\x,15.5-1*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 11)] in {0, 1}{\n\n\\node[draw=none]()at(.5+1*\\x,13.5-1*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 15)] in {0, 1}{\n\n\\node[draw=none]()at(2.5+1*\\x,13.5-1*\\y){\\r};\n\t};\n\t};\n\n\n\n\\foreach \\j in {0, 1} {\n\\foreach \\k in {0, 1} {\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 4*(\\j) + 8*(\\k)+ 19)] in {0, 1}{\n\n\\node[draw=none]()at(4.5+2*\\j+1*\\x,15.5-2*\\k-1*\\y){\\r};\n\t};\n\t};\n    };\n    };\n\n\\foreach \\j in {0, 1} {\n\\foreach \\k in {0, 1} {\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 4*(\\j) + 8*(\\k)+ 35)] in {0, 1}{\n\n\\node[draw=none]()at(.5+2*\\j+1*\\x,11.5-2*\\k-1*\\y){\\r};\n\t};\n\t};\n    };\n    };\n\n\\node[draw=none]()at(6,10){51};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 60)] in {0, 1}{\n\n\\node[draw=none]()at(10+4*\\x,6-4*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 56)] in {0, 1}{\n\n\\node[draw=none]()at(2+4*\\x,6-4*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 52)] in {0, 1}{\n\n\\node[draw=none]()at(10+4*\\x,14-4*\\y){\\r};\n\t};\n\t};\n\n\\end{tikzpicture}\n\\caption{True subband pattern for WSQ algorithm.}\n\\label{fig:wavelets-subbands2}\n\\end{figure}\n\n\\begin{comment}\nThe following code box contains the partially implemented WSQ class that is needed to complete the problems in this lab.\n\\begin{lstlisting}\nclass WSQ:\n    \"\"\"Perform image compression using the Wavelet Scalar Quantization\n    algorithm. This class is a structure for performing the algorithm, to\n    actually perform the compression and decompression, use the _compress\n    and _decompress methods respectively. Note that all class attributes\n    are set to None in __init__, but their values are initialized in the\n    compress method.\n\n    Attributes:\n        _pixels (int): Number of pixels in source image.\n        _s (float): Scale parameter for image preprocessing.\n        _m (float): Shift parameter for image preprocessing.\n        _Q ((16, ), ndarray): Quantization parameters q for each subband.\n        _Z ((16, ), ndarray): Quantization parameters z for each subband.\n        _bitstrings (list): List of 3 BitArrays, giving bit encodings for\n            each group.\n        _tvals (tuple): Tuple of 3 lists of bools, indicating which\n            subbands in each groups were encoded.\n        _shapes (tuple): Tuple of 3 lists of tuples, giving shapes of each\n            subband in each group.\n        _huff_maps (list): List of 3 dictionaries, mapping huffman index to\n            bit pattern.\n    \"\"\"\n\n    def __init__(self):\n        self._pixels = None\n        self._s = None\n        self._m = None\n        self._Q = None\n        self._Z = None\n        self._bitstrings = None\n        self._tvals = None\n        self._shapes= None\n        self._huff_maps = None\n        self._infoloss = None\n\n    def compress(self, img, r, gamma=2.5):\n        \"\"\"The main compression routine. It computes and stores a bitstring\n        representation of a compressed image, along with other values\n        needed for decompression.\n\n        Parameters:\n            img ((m,n), ndarray): Numpy array containing 8-bit integer\n                pixel values.\n            r (float): Defines compression ratio. Between 0 and 1, smaller\n                numbers mean greater levels of compression.\n            gamma (float): A parameter used in quantization.\n        \"\"\"\n        self._pixels = img.size   # Store image size.\n        # Process then decompose image into subbands.\n        mprime = self.pre_process(img)\n        subbands = self.decompose(img)\n        # Calculate quantization parameters, quantize the image then group.\n        self._Q, self._Z = self.get_bins(subbands, r, gamma)\n        q_subbands = [self.quantize(subbands[i],self._Q[i],self._Z[i])\n                      for i in range(16)]\n        groups, self._shapes, self._tvals = self.group(q_subbands)\n\n        # Complete the Huffman encoding and transfer to bitstring.\n        huff_maps = []\n        bitstrings = []\n        for i in range(3):\n            inds, freqs, extra = self.huffman_indices(groups[i])\n            huff_map = huffman(freqs)\n            huff_maps.append(huff_map)\n            bitstrings.append(self.encode(inds, extra, huff_map))\n\n        # Store the bitstrings and the huffman maps.\n        self._bitstrings = bitstrings\n        self._huff_maps = huff_maps\n\n    def pre_process(self, img):\n        \"\"\"Preprocessing routine that takes an image and shifts it so that\n        roughly half of the values are on either side of zero and fall\n        between -128 and 128.\n\n        Parameters:\n            img ((m,n), ndarray): Numpy array containing 8-bit integer\n                pixel values.\n\n        Returns:\n            ((m,n), ndarray): Processed numpy array containing 8-bit\n                integer pixel values.\n        \"\"\"\n        pass\n\n    def post_process(self, img):\n        \"\"\"Postprocess routine that reverses pre_process().\n\n        Parameters:\n            img ((m,n), ndarray): Numpy array containing 8-bit integer\n                pixel values.\n\n        Returns:\n            ((m,n), ndarray): Unprocessed numpy array containing 8-bit\n                integer pixel values.\n        \"\"\"\n        pass\n\n    def decompose(self, img):\n        \"\"\"Decompose an image into the WSQ subband pattern using the\n        Coiflet1 wavelet.\n\n        Parameters:\n            img ((m,n) ndarray): Numpy array holding the image to be\n                decomposed.\n\n        Returns:\n            subbands (list): List of 16 numpy arrays containing the WSQ\n                subbands in order.\n        \"\"\"\n        pass\n\n    def recreate(self, subbands):\n        \"\"\"Recreate an image from the 16 WSQ subbands.\n\n        Parameters:\n            subbands (list): List of 16 numpy arrays containing the WSQ\n                subbands in order.\n\n        Returns:\n            img ((m,n) ndarray): Numpy array, the image recreated from the\n                WSQ subbands.\n        \"\"\"\n        pass\n\n    def get_bins(self, subbands, r, gamma):\n        \"\"\"Calculate quantization bin widths for each subband. These will\n        be used to quantize the wavelet coefficients.\n\n        Parameters:\n            subbands (list): List of 16 WSQ subbands.\n            r (float): Compression parameter, determines the degree of\n                compression.\n            gamma(float): Parameter used in compression algorithm.\n\n        Returns:\n            Q ((16, ) ndarray): Array of quantization step sizes.\n            Z ((16, ) ndarray): Array of quantization coefficients.\n        \"\"\"\n        subband_vars = np.zeros(16)\n        fracs = np.zeros(16)\n\n        for i in range(len(subbands)): # Compute subband variances.\n            X,Y = subbands[i].shape\n            fracs[i]=(X*Y)/(np.float(finger.shape[0]*finger.shape[1]))\n            x = np.floor(X/8.).astype(int)\n            y = np.floor(9*Y/32.).astype(int)\n            Xp = np.floor(3*X/4.).astype(int)\n            Yp = np.floor(7*Y/16.).astype(int)\n            mu = subbands[i].mean()\n            sigsq = (Xp*Yp-1.)**(-1)*((subbands[i][x:x+Xp, y:y+Yp]-mu)**2).sum()\n            subband_vars[i] = sigsq\n\n        A = np.ones(16)\n        A[13], A[14] = [1.32]*2\n\n        Qprime = np.zeros(16)\n        mask = subband_vars >= 1.01\n        Qprime[mask] = 10./(A[mask]*np.log(subband_vars[mask]))\n        Qprime[:4] = 1\n        Qprime[15] = 0\n\n        K = []\n        for i in range(15):\n            if subband_vars[i] >= 1.01:\n                K.append(i)\n\n        while True:\n            S = fracs[K].sum()\n            P = ((np.sqrt(subband_vars[K])/Qprime[K])**fracs[K]).prod()\n            q = (gamma**(-1))*(2**(r/S-1))*(P**(-1./S))\n            E = []\n            for i in K:\n                if Qprime[i]/q >= 2*gamma*np.sqrt(subband_vars[i]):\n                    E.append(i)\n            if len(E) > 0:\n                for i in E:\n                    K.remove(i)\n                continue\n            break\n\n        Q = np.zeros(16) # Final bin widths.\n        for i in K:\n            Q[i] = Qprime[i]/q\n        Z = 1.2*Q\n\n        return Q, Z\n\n    def quantize(self, coeffs, Q, Z):\n        \"\"\"Implementation of a uniform quantizer which maps wavelet\n        coefficients to integer values using the quantization parameters\n        Q and Z.\n\n        Parameters:\n            coeffs ((m,n) ndarray): Contains the floating-point values to\n                be quantized.\n            Q (float): The step size of the quantization.\n            Z (float): The null-zone width (of the center quantization bin).\n\n        Returns\n            out ((m,n) ndarray): Numpy array of the quantized values.\n        \"\"\"\n        pass\n\n    def dequantize(self, coeffs, Q, Z, C=0.44):\n        \"\"\"Given quantization parameters, approximately reverses the\n        quantization effect carried out in quantize().\n\n        Parameters:\n            coeffs ((m,n) ndarray): Array of quantized coefficients.\n            Q (float): The step size of the quantization.\n            Z (float): The null-zone width (of the center quantization bin).\n            C (float): Centering parameter, defaults to .44.\n\n        Returns:\n            out ((m,n) ndarray): Array of dequantized coefficients.\n        \"\"\"\n        pass\n\n    def group(self, subbands):\n        \"\"\"Split the quantized subbands into 3 groups.\n\n        Parameters:\n            subbands (list): Contains 16 numpy arrays which hold the\n                quantized coefficients.\n\n        Returns:\n            gs (tuple): (g1,g2,g3) Each gi is a list of quantized coeffs\n                for group i.\n            ss (tuple): (s1,s2,s3) Each si is a list of tuples which\n                contain the shapes for group i.\n            ts (tuple): (s1,s2,s3) Each ti is a list of bools indicating\n                which subbands were included.\n        \"\"\"\n        g1 = [] # This will hold the group 1 coefficients.\n        s1 = [] # Keep track of the subband dimensions in group 1.\n        t1 = [] # Keep track of which subbands were included.\n        for i in range(10):\n            s1.append(subbands[i].shape)\n            if subbands[i].any(): # True if there is any nonzero entry.\n                g1.extend(subbands[i].ravel())\n                t1.append(True)\n            else: # The subband was not transmitted.\n                t1.append(False)\n\n        g2 = [] # This will hold the group 2 coefficients.\n        s2 = [] # Keep track of the subband dimensions in group 2.\n        t2 = [] # Keep track of which subbands were included.\n        for i in range(10, 13):\n            s2.append(subbands[i].shape)\n            if subbands[i].any(): # True if there is any nonzero entry.\n                g2.extend(subbands[i].ravel())\n                t2.append(True)\n            else: # The subband was not transmitted.\n                t2.append(False)\n\n        g3 = [] # This will hold the group 3 coefficients.\n        s3 = [] # Keep track of the subband dimensions in group 3.\n        t3 = [] # Keep track of which subbands were included.\n        for i in range(13,16):\n            s3.append(subbands[i].shape)\n            if subbands[i].any(): # True if there is any nonzero entry.\n                g3.extend(subbands[i].ravel())\n                t3.append(True)\n            else: # The subband was not transmitted.\n                t3.append(False)\n\n        return (g1,g2,g3), (s1,s2,s3), (t1,t2,t3)\n\n    def ungroup(self, gs, ss, ts):\n        \"\"\"Re-create the subband list structure from the information stored\n        in gs, ss and ts.\n\n        Parameters:\n            gs (tuple): (g1,g2,g3) Each gi is a list of quantized coeffs\n                for group i.\n            ss (tuple): (s1,s2,s3) Each si is a list of tuples which\n                contain the shapes for group i.\n            ts (tuple): (s1,s2,s3) Each ti is a list of bools indicating\n                which subbands were included.\n\n        Returns:\n            subbands (list): Contains 16 numpy arrays holding quantized\n                coefficients.\n        \"\"\"\n        subbands1 = [] # The reconstructed subbands in group 1.\n        i = 0\n        for j, shape in enumerate(ss[0]):\n            if ts[0][j]: # True if the j-th subband was included.\n                l = shape[0]*shape[1] # Number of entries in the subband.\n                subbands1.append(np.array(gs[0][i:i+l]).reshape(shape))\n                i += l\n            else: # The j-th subband wasn't included, so all zeros.\n                subbands1.append(np.zeros(shape))\n\n        subbands2 = [] # The reconstructed subbands in group 2.\n        i = 0\n        for j, shape in enumerate(ss[1]):\n            if ts[1][j]: # True if the j-th subband was included.\n                l = shape[0]*shape[1] # Number of entries in the subband.\n                subbands2.append(np.array(gs[1][i:i+l]).reshape(shape))\n                i += l\n            else: # The j-th subband wasn't included, so all zeros.\n                subbands2.append(np.zeros(shape))\n\n        subbands3 = [] # the reconstructed subbands in group 3\n        i = 0\n        for j, shape in enumerate(ss[2]):\n            if ts[2][j]: # True if the j-th subband was included.\n                l = shape[0]*shape[1] # Number of entries in the subband.\n                subbands3.append(np.array(gs[2][i:i+l]).reshape(shape))\n                i += l\n            else: # The j-th subband wasn't included, so all zeros.\n                subbands3.append(np.zeros(shape))\n\n        subbands1.extend(subbands2)\n        subbands1.extend(subbands3)\n        return subbands1\n\n    def huffman_indices(self, coeffs):\n        \"\"\"Calculate the Huffman indices from the quantized coefficients.\n\n        Parameters:\n            coeffs (list): Integer values that represent quantized\n                coefficients.\n\n        Returns:\n            inds (list): The Huffman indices.\n            freqs (ndarray): Array whose i-th entry gives the frequency of\n                index i.\n            extra (list): Contains zero run lengths and coefficient\n                magnitudes for exceptional cases.\n        \"\"\"\n        N = len(coeffs)\n        i = 0\n        inds = []\n        extra = []\n        freqs = np.zeros(254)\n\n        # Sweep through the quantized coefficients.\n        while i < N:\n\n            # First handle zero runs.\n            zero_count = 0\n            while coeffs[i] == 0:\n                zero_count += 1\n                i += 1\n                if i >= N:\n                    break\n\n            if zero_count > 0 and zero_count < 101:\n                inds.append(zero_count - 1)\n                freqs[zero_count - 1] += 1\n            elif zero_count >= 101 and zero_count < 256: # 8 bit zero run.\n                inds.append(104)\n                freqs[104] += 1\n                extra.append(zero_count)\n            elif zero_count >= 256: # 16 bit zero run.\n                inds.append(105)\n                freqs[105] += 1\n                extra.append(zero_count)\n            if i >= N:\n                break\n\n            # now handle nonzero coefficients\n            if coeffs[i] > 74 and coeffs[i] < 256: # 8 bit pos coeff.\n                inds.append(100)\n                freqs[100] += 1\n                extra.append(coeffs[i])\n            elif coeffs[i] >= 256: # 16 bit pos coeff.\n                inds.append(102)\n                freqs[102] += 1\n                extra.append(coeffs[i])\n            elif coeffs[i] < -73 and coeffs[i] > -256: # 8 bit neg coeff.\n                inds.append(101)\n                freqs[101] += 1\n                extra.append(abs(coeffs[i]))\n            elif coeffs[i] <= -256: # 16 bit neg coeff.\n                inds.append(103)\n                freqs[103] += 1\n                extra.append(abs(coeffs[i]))\n            else: # Current value is a nonzero coefficient in the range [-73, 74].\n                inds.append(179 + coeffs[i])\n                freqs[179 + coeffs[i].astype(int)] += 1\n            i += 1\n\n        return list(map(int,inds)), list(map(int,freqs)), list(map(int,extra))\n\n    def indices_to_coeffs(self, indices, extra):\n        \"\"\"Calculate the coefficients from the Huffman indices plus extra\n        values.\n\n        Parameters:\n            indices (list): List of Huffman indices.\n            extra (list): Indices corresponding to exceptional values.\n\n        Returns:\n            coeffs (list): Quantized coefficients recovered from the indices.\n        \"\"\"\n        coeffs = []\n        j = 0 # Index for extra array.\n\n        for s in indices:\n            if s < 100: # Zero count of 100 or less.\n                coeffs.extend(np.zeros(s+1))\n            elif s == 104 or s == 105: # Zero count of 8 or 16 bits.\n                coeffs.extend(np.zeros(extra[j]))\n                j += 1\n            elif s in [100, 102]: # 8 or 16 bit pos coefficient.\n                coeffs.append(extra[j]) # Get the coefficient from the extra list.\n                j += 1\n            elif s in [101, 103]: # 8 or 16 bit neg coefficient.\n                coeffs.append(-extra[j]) # Get the coefficient from the extra list.\n                j += 1\n            else: # Coefficient from -73 to +74.\n                coeffs.append(s-179)\n        return coeffs\n\n    def encode(self, indices, extra, huff_map):\n        \"\"\"Encodes the indices using the Huffman map, then returns\n        the resulting bitstring.\n\n        Parameters:\n            indices (list): Huffman Indices.\n            extra (list): Indices corresponding to exceptional values.\n            huff_map (dict): Dictionary that maps Huffman index to bit\n                pattern.\n\n        Returns:\n            bits (BitArray object): Contains bit representation of the\n                Huffman indices.\n        \"\"\"\n        bits = bs.BitArray()\n        j = 0 # Index for extra array.\n        for s in indices: # Encode each huffman index.\n            bits.append('0b' + huff_map[s])\n\n            # Encode extra values for exceptional cases.\n            if s in [104, 100, 101]: # Encode as 8-bit ints.\n                bits.append('uint:8={}'.format(int(extra[j])))\n                j += 1\n            elif s in [102, 103, 105]: # Encode as 16-bit ints.\n                bits.append('uint:16={}'.format(int(extra[j])))\n                j += 1\n        return bits\n\n    def decode(self, bits, huff_map):\n        \"\"\"Decodes the bits using the given huffman map, and returns\n        the resulting indices.\n\n        Parameters:\n            bits (BitArray object): Contains bit-encoded Huffman indices.\n            huff_map (dict): Maps huffman indices to bit pattern.\n\n        Returns:\n            indices (list): Decoded huffman indices.\n            extra (list): Decoded values corresponding to exceptional indices.\n        \"\"\"\n        indices = []\n        extra = []\n\n        # Reverse the huffman map to get the decoding map.\n        dec_map = {v:k for k, v in huff_map.items()}\n\n        # Wrap the bits in an object better suited to reading.\n        bits = bs.ConstBitStream(bits)\n\n        # Read each bit at a time, decoding as we go.\n        i = 0 # The index of the current bit.\n        pattern = '' # The current bit pattern.\n        while i < bits.length:\n            pattern += bits.read('bin:1') # Read in another bit.\n            i += 1\n\n            # Check if current pattern is in the decoding map.\n            if pattern in dec_map:\n                indices.append(dec_map[pattern]) # Insert huffman index.\n\n                # If an exceptional index, read next bits for extra value.\n                if dec_map[pattern] in (100, 101, 104): # 8-bit int or 8-bit zero run length.\n                    extra.append(bits.read('uint:8'))\n                    i += 8\n                elif dec_map[pattern] in (102, 103, 105): # 16-bit int or 16-bit zero run length.\n                    extra.append(bits.read('uint:16'))\n                    i += 16\n                pattern = '' # Reset the bit pattern.\n        return indices, extra\n\n    def decompress(self):\n        \"\"\"Return the uncompressed image recovered from the compressed\n            bistring representation.\n\n        Returns:\n            img ((m,n) ndaray): The recovered, uncompressed image.\n        \"\"\"\n        # For each group, decode the bits, map from indices to coefficients.\n        groups = []\n        for i in range(3):\n            indices, extras = self.decode(self._bitstrings[i],\n                                           self._huff_maps[i])\n            groups.append(self.indices_to_coeffs(indices, extras))\n\n        # Recover the subbands from the groups of coefficients.\n        q_subbands = self.ungroup(groups, self._shapes, self._tvals)\n\n        # Dequantize the subbands.\n        subbands = [self.dequantize(q_subbands[i], self._Q[i], self._Z[i])\n                    for i in range(16)]\n\n        # Recreate the image.\n        img = self.recreate(subbands)\n\n        # Post-process, return the image.\n        return self.post_process(img)\n\n    def get_ratio(self):\n        \"\"\"Calculate the compression ratio achieved.\n\n        Returns:\n            ratio (float): Ratio of number of bytes in the original image\n                to the number of bytes contained in the bitstrings.\n        \"\"\"\n        pass\n\\end{lstlisting}\n\nThe following code includes the methodes used in the WSQ class to perform the Huffman encoding.\n\\begin{lstlisting}\n# Helper functions and classes for the Huffman encoding portions of WSQ algorithm.\n\nimport queue\nclass huffmanLeaf():\n    \"\"\"Leaf node for Huffman tree.\"\"\"\n    def __init__(self, symbol):\n        self.symbol = symbol\n\n    def makeMap(self, huff_map, path):\n        huff_map[self.symbol] = path\n\n    def __str__(self):\n        return str(self.symbol)\n\n    def __lt__(self,other):\n        return False\n\nclass huffmanNode():\n    \"\"\"Internal node for Huffman tree.\"\"\"\n    def __init__(self, left, right):\n        self.left = left\n        self.right = right\n\n    def makeMap(self, huff_map, path):\n        \"\"\"Traverse the huffman tree to build the encoding map.\"\"\"\n        self.left.makeMap(huff_map, path + '0')\n        self.right.makeMap(huff_map, path + '1')\n\n    def __lt__(self,other):\n        return False\n\ndef huffman(freqs):\n    \"\"\"\n    Generate the huffman tree for the given symbol frequencies.\n    Return the map from symbol to bit pattern.\n    \"\"\"\n    q = queue.PriorityQueue()\n    for i in range(len(freqs)):\n        leaf = huffmanLeaf(i)\n        q.put((freqs[i], leaf))\n    while q.qsize() > 1:\n        l1 = q.get()\n        l2 = q.get()\n        weight = l1[0] + l2[0]\n        node = huffmanNode(l1[1], l2[1])\n        q.put((weight,node))\n    root = q.get()[1]\n    huff_map = dict()\n    root.makeMap(huff_map, '')\n    return huff_map\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{comment}\nWe don't need a lot of this expository content in the lab.\n\\subsection*{The Haar Wavelet}\n\nAs noted earlier, the Fourier transform is based on the complex exponential\nfunction. Let us alter the situation and consider instead the following\nfunction, known as the \\emph{Haar wavelet}:\n\\begin{equation*}\n\\psi(x) =\n \\begin{cases}\n  1 & \\text{if } 0 \\leq x < \\frac{1}{2} \\\\\n  -1 & \\text{if } \\frac{1}{2} \\leq x < 1 \\\\\n  0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\n% It might be nice to plot this function and include the image in the lab.\n\nAlong with this wavelet, we introduce the associated \\emph{scaling function}:\n\\begin{equation*}\n\\phi(x) =\n \\begin{cases}\n 1 & \\text{if } 0 \\leq x < 1 \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\nFrom the wavelet and scaling function, we can generate two countable families\nof dyadic dilates and translates given by\n\\begin{equation*}\n\\psi_{m,k}(x) = \\psi(2^mx - k)\n\\end{equation*}\n\\begin{equation*}\n\\phi_{m,k}(x) = \\phi(2^mx - k),\n\\end{equation*}\nwhere $m,k \\in \\mathbb{Z}$.\n\nLet us focus for the moment on that second family of functions, $\\{\\phi_{m,k}\\}$.\nIf we fix $m$ and let $k$ vary over the integers, we have a countable collection of\nsimple functions. The support of a typical function $\\phi_{m,k}$ is the interval\n$[k2^{-m}, (k+1)2^{-m}]$, and for any $m \\in \\mathbb{Z}$ we have\n\\begin{equation*}\n\\mathbb{R} = \\displaystyle\\biguplus_k\\,[k2^{-m}, (k+1)2^{-m}],\n\\end{equation*}\nwhere $\\uplus$ denotes a union over disjoint sets. Thus, the supports can be viewed as\na discretization of the real line, and we can use this collection of simple functions\nto approximate any $f \\in L^2(\\mathbb{R})$ in the following sense:\n\\begin{equation*}\nf(x) \\approx f_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\alpha_{m,k}\\phi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\alpha_{m,k} := 2^m \\displaystyle \\int_{k2^{-m}}^{(k+1)2^{-m}}f(x) dx\n\\end{equation*}\n($\\alpha_{m,k}$ is simply the average value of $f$ on $[k2^{-m},(k+1)2^{-m}]$). As you\nwould probably expect, the point-wise error between $f$ and its approximation $f_m$\n(called a \\emph{frame}) goes to zero as $m \\to \\infty$.\n\nThese frames are not quite good enough, however. Each coefficient $\\alpha_{m,k}$\ncertainly captures local information about $f$ -- namely its average value on\na certain interval -- but it fails to tell us anything about how $f$ changes\non that interval. We need more information than is provided by $f_m$ in order\nto know about discontinuities or high-frequency oscillations of $f$. To this end,\nwe now consider the wavelet function $\\psi$.\nNotice that the Haar wavelet is oscillatory in nature, and is thus better suited\nto capture local information on how a function changes at a given point. For\nany given $m$, we define a function $d_m$, called a \\emph{detail}, as follows:\n\\begin{equation*}\nd_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\beta_{m,k}\\psi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\beta_{m,k} := 2^m \\displaystyle \\int_{-\\infty}^{\\infty}f(x) \\psi_{m,k}(x) dx.\n\\end{equation*}\nEach coefficient $\\beta_{m,k}$ gives information about how $f$ changes on the\nthe interval $[k2^{-m}, (k+1)2^{-m}]$, and larger coefficients correspond\nto larger spikes of width $2^{-m}$. Thus, as $m$ increases, the\ndetail function $d_m$ gives information about the higher-frequency oscillations\nof the function. The details and approximation frames interact in the following way:\n\\begin{equation*}\nf_{m+1} = f_m + d_m.\n\\end{equation*}\nAs a result of this fortuitous relationship, one can prove the decomposition\n\\begin{equation*}\nL^2(R) = V_0 \\oplus W_0 \\oplus W_1 \\oplus \\cdots,\n\\end{equation*}\nwhere $V_j := \\text{span}\\{\\phi_{j,k}\\}_{k \\in \\mathbb{Z}}$ and\n$W_j := \\text{span}\\{\\psi_{j,k}\\}_{k \\in \\mathbb{Z}}$. This fact justifies\nour hope to approximate and analyze functions using wavelets.\n\\begin{figure}[t]\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/sinecurve}\n    \\caption{$f(x) = \\sin (x)$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/discreteSineCurve.pdf}\n    \\caption{$f_4$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/sineCurveDetail}\n    \\caption{$d_4$}\n\\endminipage\n\\end{figure}\n\\begin{problem}\nCalculate and plot the approximation frames for $f(x) = \\sin(x)$ on the interval $[0,2\\pi]$\nfor $m = 4, 6, 8$. Note that because we are working on a finite interval,\nwe only need to calculate certain coefficients $\\alpha_{m,k}$. In\nparticular, we only need the coefficients for $k = 0$ up to the first integer\n$n$ such that $(n+1)2^{-m} > 2 \\pi$ (why?). Furthermore, to plot the frame,\nall we need is an array containing the relevant coefficients. Then simply plot\nthe coefficients against \\li{linspace} with appropriate arguments\nand set \\li{drawstyle='steps'} in the \\li{plt.plot} function.\n\\end{problem}\n\n\\begin{problem}\nNow calculate the details for $f(x) = \\sin(x)$ on the same interval and for the\nsame $m$ values given above. Use previous results to compute the coefficients\nfor $f_5$, $f_7$, and $f_9$ and plot them.\n\\end{problem}\n\nWhat purpose do these details and approximation frames serve? According to the\nproperties discussed above, we can approximate $L^2$ functions as follows:\n\\begin{align*}\nf \\approx f_{J+1} &= f_J + d_J \\\\\n&= f_{J-1} + d_{J-1} + d_J \\\\\n& \\ldots\\\\\n&= f_{I} + d_{I} + d_{I+1} + \\cdots + d_J,\n\\end{align*}\nwhere $1 \\leq I \\leq J$. If $f$ has compact support (as in the case of a finite-time signal,\nfor example), only finitely many of the coefficients in the frame and the details are\nnonzero, thus enabling us to represent $f$ to a reasonable degree of accuracy in a very\nefficient manner. The calculation of these detail coefficients is called the \\emph{discrete\nwavelet transform}. In the context of signals processing, one can imagine calculating these\ncoefficients, transmitting them, and then reproducing the approximated signal on the\nreceiving end. Furthermore, the coefficients of the details reflect the local properties\nof the original function $f$ at the particular level of detail and resolution! This means\nthat we can discard many of the coefficients if we are only interested in reproducing a certain\npart of the signal, or in recovering the entire signal to only a limited resolution. We can\nalso study just those frequencies of the signal that fall within a certain range (called a\nsub-band) by examining the detail coefficients at a particular level. These\nproperties make the discrete wavelet transform an attractive alternative to the Fourier\ntransform in many applications. See Figure \\ref{fig:dwt1D} for an example of the discrete Wavelet transform.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{figures/dwt1D}\n\\caption{A level 4 wavelet decomposition of a signal. The top panel is the original signal,\nthe next panel down is the approximation, and the remaining panels are the detail coefficients.\nNotice how the approximation resembles a smoothed version of the original signal, while the\ndetails capture the high-frequency oscillations and noise.}\n\\label{fig:dwt1D}\n\\end{figure}\n\nIn practice, we are often interested in analyzing discrete signals with compact support (that is,\nfinite-time signals that we have sampled at a finite number of points). If wavelet analysis is\nto be of any use, we first need an efficient way to calculate the discrete wavelet transform.\nThe process described in the first section, while intuitive and illustrative of the mathematical\nprinciples\nbehind wavelet analysis, is not the best approach to calculating the wavelet coefficients. It\nturns out that the discrete wavelet transform can be implemented as an iterated low-pass/high-pass\nfilter bank, one iteration of which is shown graphically in the figure. We present the\nalgorithm without getting into the details of why it works.\n\n\nThe algorithm goes as follows.\nGiven an input matrix of size $2^n \\times 2^n$, first operate on the rows as you would\nin the one-dimensional Wavelet transform (i.e. convolve each row with the filters, then\ndownsample).\nWe then have two matrices of size $2^n \\times 2^{n-1}$,\nsince each row has been downsampled by a factor of 2. Then for each of these two\nintermediate matrices, operate on each column, yielding a total of four matrices of\nsize $2^{n-1} \\times 2^{n-1}$. Figure \\ref{fig:2dwt}\ngives a graphical depiction of one iteration of the algorithm.\n\nWe initialize $LL_0$ to be the\noriginal image matrix, and we terminate once the length of the rows or columns\nis less than the length of the filters. We end up with a list of wavelet\ncoefficients, starting with the final approximation frame $LL_n$ followed by\ncollections of detail coefficients $(LH_n,HL_n,HH_n)$, $(LH_{n-1},HL_{n-1},HH_{n-1})$,\n$\\ldots$, $(LH_1,HL_1,HH_1)$. Note that at each iteration we operate first on the\nrows (convolve with the filter, then downsample), and the we operate on the columns\nof the resulting matrices (\\emph{not} the original matrix). The size of the output\nmatrices have been reduced by a factor of two in both dimensions. As with the\none-dimensional algorithm, to reconstruct the image from the coefficients, we simply\nreverse the process by upsampling, convolving, and adding (first the columns, then\nthe rows). We provide sample code for one iteration of the transform and the inverse.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.signal import fftconvolve\n\n# given the current approximation frame image, and the filters lo_d and hi_d\n# initialize empty arrays\ntemp = np.zeros([image.shape[0], image.shape[1]/2])\nLL = np.zeros([image.shape[0]/2, image.shape[1]/2])\nLH = np.zeros([image.shape[0]/2, image.shape[1]/2])\nHL = np.zeros([image.shape[0]/2, image.shape[1]/2])\nHH = np.zeros([image.shape[0]/2, image.shape[1]/2])\n\n# low-pass filtering along the rows\nfor i in xrange(image.shape[0]):\n\ttemp[i] = fftconvolve(image[i], lo_d, mode='full')[1::2]\n\n# low and hi-pass filtering along the columns\nfor i in xrange(image.shape[1]/2):\n\tLL[:,i] = fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n    LH[:,i] = fftconvolve(temp[:,i],hi_d,mode='full')[1::2]\n\n# hi-pass filtering along the rows\nfor i in xrange(image.shape[0]):\n\ttemp[i] = fftconvolve(image[i], hi_d, mode='full')[1::2]\n\n# low and hi-pass filtering along the columns\nfor i in xrange(image.shape[1]/2):\n\tHL[:,i] = fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n    HH[:,i] = fftconvolve(temp[:,i],hi_d,mode='full')[1::2]\n\\end{lstlisting}\nAt this point, the variables \\li{LL, LH, HL, HH} contain the current level of wavelet coefficients.\nYou would then store \\li{(LH, HL, HH)} in a list, and feed \\li{LL} back into the same\nblock of code (with \\li{LL} replacing \\li{image}) to obtain the next level of coefficients.\n\nNow, given a current level of wavelet coefficients, here is the code to recover the previous\napproximation frame, which is the crucial step in the inverse transform.\n\\begin{lstlisting}\n# given current coefficients LL, LH, HL, HH\n# initialize temporary arrays\nn = LL.shape[0]\ntemp1 = np.zeros([2*n,n])\ntemp2 = np.zeros([2*n,n])\nup1 = np.zeros(2*n)\nup2 = np.zeros(2*n)\n\n# upsample and filter the columns of the coefficient arrays\nfor i in xrange(n):\n\tup1[1::2] = HH[:,i]\n\tup2[1::2] = HL[:,i]\n\ttemp1[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\tup1[1::2] = LH[:,i]\n\tup2[1::2] = LL[:,i]\n\ttemp2[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\n# upsample and filter the rows, then add results together\nresult = sp.zeros([2*n,2*n])\nfor i in xrange(2*n):\n\tup1[1::2] = temp1[i]\n\tup2[1::2] = temp2[i]\n\tresult[i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\\end{lstlisting}\n\n\\begin{problem}\nBuild off of the sample code to fully implement the two-dimensional discrete\nwavelet transform as described above.\nAs before, the input to your function should consist of\nthree arrays: the input image, the low-pass filter, and the high-pass filter.\nYou should return a list of the following form: $$[LL_n,(LH_n,HL_n,HH_n), \\ldots\n,(LH_1,HL_1,HH_1)].$$\n\nThe inverse wavelet transform function should take as input a list\nof that same form, as well as the reconstruction low-pass and high-pass filters,\nand should return the reconstructed image.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\nThis section could be cool, but it's not hashed out very well yet.\n\\section*{Edge Detection}\nIt is often useful to identify the edges of objects and figures\nrepresented in images. The edge information can be used to classify images\nand group them with other similar images (this is part of a field called\n\\textit{computer vision}), to segment the image into component parts, to\nsharpen blurry images, to filter out unnecessary details of the image,\nand so forth. Of course, our human eyes are very adept at recognizing edges,\nbut enabling a computer to do the same is much more difficult. An edge can\nbe thought of as a discontinuity in the image or a region of high contrast\nin either color or brightness. We can therefore leverage the high-frequency\ndetail coefficients of the wavelet transform to detect the edges. Execute the\nfollowing code:\n\\begin{lstlisting}\n>>> # calculate one level of wavelet coefficients\n>>> coeffs = pywt.wavedec2(lena,'haar', level=1)\n\\end{lstlisting}\n\nNote that the approximation coefficients are very close to the original\nimage, while the detail coefficients are much more sparse, and roughly\ncapture the edges in the image. In particular, the upper right coefficients\nemphasize the vertical edges, the lower left coefficients emphasize the\nhorizontal edges, and the lower right coefficients emphasize the diagonal\nedges.\n\n\\begin{problem}\nNow zero out the approximation coefficients and use your inverse DWT\nfunction to recreate the image. Plot its absolute value. This image is\na fairly good representation of the edges. If we add this to the original\nimage, we can increase the contrast at the edges (that is, make the dark\nside darker, and the light side lighter). Do this, and plot the original\nimage side-by-side with the sharpened image. What do you notice? There\nare many image-sharpening techniques, and those based on wavelets\nare more sophisticated than what we have done here, but this gives the\nbasic idea.\n\\end{problem}\nthe above section needs work, or maybe should be taken out completely.\n\\end{comment}\n", "meta": {"hexsha": "58cdde4ec91e18343b5ed93be6720b6ab26a2c27", "size": 105981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume2/Wavelets/Wavelets.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/Volume2/Wavelets/Wavelets.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/Volume2/Wavelets/Wavelets.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": 47.9335142469, "max_line_length": 301, "alphanum_fraction": 0.703588379, "num_tokens": 27900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.8918110396870287, "lm_q1q2_score": 0.6732415193137392}}
{"text": "\\section{Methods}\n\n\\subsection{Notation}\n\nIn the following, we will use definitions and notations introduced by \\citep{rougier:2011} where a neural map is defined as the projection from a manifold $\\Omega \\subset \\mathbb{R}^d$ onto a set $\\mathcal{N}$ of $n$ {\\em  neuron}s which is formally written as $\\Phi : \\Omega \\rightarrow \\mathcal{N}$. Each neuron $i$ is associated with a code word $\\mathbf{w}_i \\in \\mathbb{R}^d$, all of which establish the set  $\\{\\mathbf{w}_i\\}_{i \\in   \\mathcal{N}}$ that is referred as the code book. The mapping from $\\Omega$ to $\\mathcal{N}$ is a closest-neighbor winner-take-all rule such that any vector $\\mathbf{v} \\in \\Omega$ is mapped to a neuron $i$ with the code $\\mathbf{w}_\\mathbf{v}$ being closest to the actual presented stimulus vector $\\mathbf{v}$,\n\\begin{equation}\n\\Phi : \\mathbf{v} \\mapsto argmin_{i \\in \\mathcal{N}} (\\lVert \\mathbf{v} -\n\\mathbf{w}_i \\rVert).\n\\label{eq:psi}\n\\end{equation}\nThe neuron $\\mathbf{w}_\\mathbf{v}$ is named the best matching unit (BMU) and the set $C_i = \\{x \\in \\Omega | \\Phi(x) = \\mathbf{w}_i \\}$ defines the {\\em receptive field} of the neuron $i$.\n\n\n%Before we present our new SOM learning algorithm, we introduce the notation  and terminology we are using throughout the present work. We borrow the notation from a previous work \\citep{rougier:2011}.  A neural map is defined to be the projection from a manifold $\\Omega \\subset \\mathbb{R}^d$ onto a set $\\mathcal{N}$ of $n$ {\\em neuron}s $\\Phi : \\Omega \\rightarrow \\mathcal{N}$. Each neuron $i$ is associated with a code word $\\mathbf{w}_i \\in \\mathbb{R}^d$, all of which establish the set  $\\mathcal{W} = \\{\\mathbf{w}_i, i \\in \\mathcal{N}\\}$ that is referred as the code book. The mapping from $\\Omega$ to $\\mathcal{N}$ is a closest-neighbor winner-take-all rule such that any vector $\\mathbf{v} \\in \\Omega$ is mapped to a neuron $i$ with the code $\\mathbf{w}_\\mathbf{v}$ being closest to the current input vector $\\mathbf{v}$,\n%\\begin{equation}\n%\\Phi : \\mathbf{v} \\mapsto argmin_{i \\in \\mathcal{N}} (\\lVert \\mathbf{v} -\n%\\mathbf{w}_i \\rVert).\n%\\label{eq:psi}\n%\\end{equation}\n%The neuron $\\mathbf{w}_\\mathbf{v}$ is named the best matching unit (BMU) and the set $C_i = \\{x \\in \\Omega | \\Phi(x) = \\mathbf{w}_i \\}$ defines the {\\em receptive field} of neuron $i$.\n\n\n\\subsection{Spatial distribution} % \\& Centroidal Voronoi Tesselation}\n\\label{sec:spatial_dist}\n\nThe SOM space is usually defined as a two-dimensional region where nodes are arranged in a regular lattice (rectangular or hexagonal). Here, we consider instead the random placement of neurons with a specific spectral distribution (blue noise). As explained in \\citep{Zhou:2012}, the spectral distribution property of noise patterns is often described in terms of the Fourier spectrum color. White noise corresponds to a flat spectrum with equal energy distributed in all frequency bands while blue noise has weak low-frequency energy, but strong high-frequency energy. In other words, blue noise has intuitively good properties with points evenly spread without visible structure (see figure~\\ref{fig:sampling} for a comparison of spatial distributions).\n%%\n\\begin{figure}[htbp]\n  \\includegraphics[width=\\textwidth]{figure-blue-noise.pdf}\n  \\caption{\\textbf{Spatial distributions.}\n    \\textbf{\\textsf{A.}} Uniform sampling (n=1000) corresponding to white noise.\n    \\textbf{\\textsf{B.}} Regular grid (n=32$\\times$32) + jitter (2.5\\%).\n    \\textbf{\\textsf{C.}} Poisson disc sampling (n=988) corresponding to blue noise.}\n  \\label{fig:sampling}\n\\end{figure}\n%%\nThere exists several methods \\citep{Lagae:2008} to obtain blue noise sampling that have been originally designed for computer graphics (e.g. Poisson disk sampling, dart throwing, relaxation, tiling, etc.). Among these methods, the fast Poisson disk sampling in arbitrary dimensions \\citep{Bridson:2007} is among the fastest ($\\mathcal{O}(n)$) and easiest to use. This is the one we retained for the placement of neurons over the normalized region $[0,1]\\times[0,1]$. Such Poisson disk sampling guarantees that samples are no closer to each other than a specified minimum radius. This initial placement is further refined by applying a LLoyd relaxation \\citep{Lloyd:1982} scheme for 10 iterations, achieving a quasi centroidal Voronoi tesselation.\n\n\n%The SOM space is usually defined as a two-dimensional manifold where nodes are arranged in a regular lattice (rectangular or hexagonal). Here, we follow a  different approach and, instead of the regular lattice, we place the neurons randomly by sampling a specific spectral distribution. More specifically, we assign neurons positions by drawing samples from a blue noise distribution. \\citep{Zhou:2012}. have shown that the spectral distribution property of noise patterns is often described in terms of the Fourier spectrum color. For instance, white noise corresponds to a flat spectrum with signal's energy equally distributed to all frequency bands while blue  noise has weak low-frequency energy and strong high-frequency energy. An interesting property of the blue noise distribution is that  the resulting positions of neurons drawn are evenly spread without any apparent structure (see figure~\\ref{fig:sampling} for a comparison of spatial distributions).\n%%\n%\\begin{figure}[htbp]\n%  \\includegraphics[width=\\textwidth]{figures/blue-noise.pdf}\n%  \\caption{\\textbf{Spatial distributions.}\n%    \\textbf{\\textsf{A.}} Uniform sampling (n=1000) corresponding to white noise.\n%    \\textbf{\\textsf{B.}} Regular grid (n=32$\\times$32) + jitter (2.5\\%).\n%    \\textbf{\\textsf{C.}} Poisson disc sampling (n=988) corresponding to blue noise.}\n%  \\label{fig:sampling}\n%\\end{figure}\n%%\n\n%Blue noise distributions have been used in the field of computer graphics for many years and there are manych different techniques for computing them: Poisson disk sampling, dart throwing, relaxation, tiling, and other applications (see \\citep{Lagae:2008} for a review). One of the fastest and easiest to implement method for generating blue noise samples is the  fast Poisson disk sampling. This method, introduced by \\citep{Bridson:2007}, can be used on arbitrary dimensions in linear time ($\\mathcal{O}(n)$). In this work, we propose to use this method for placing neurons over a normalized  region of $[0,1]\\times[0,1]$. Such Poisson disk sampling guarantees that samples are no closer to each other than a specified minimum radius. This initial placement is further refined by applying a Lloyd relaxation~\\cite{Lloyd:1982} scheme for $10$ iterations to achieve a quasi centroidal Voronoi tesselation.\n\n\\subsection{Topology}\n\\label{sec:topo}\n\nConsidering a set of $n$ points $P = \\{P_i\\}_{i \\in [1,n]}$ on a finite region,\nwe first compute the Euclidean distance matrix $E$, where $e_{ij} = \\lVert P_i - P_j \\rVert$ \nand we subsequently define a connectivity matrix $G^{p}$\n%= \\{G^{p}_{ij}\\}_{i,j \\in [1,n]}$ \\gid{$G^{p} = g^{p}_{ij},\\, \\text{where } i,j \\in [1,n]$}\nsuch that only the $p$ closest points\nare connected. More precisely, if $P_j$ is among the $p$ closest neighbours of\n$P_i$ then $g^p_{ij} = 1$ else we have $g^p_{ij} = 0$.\nFrom this connectivity\nmatrix representing a graph, we compute the length of the shortest path between\neach pair of nodes and stored them into a distance matrix $D^p$. Note that\nlengths are measured in the number of nodes between two nodes such that two\nnearby points (relatively to the Euclidean distance) may have a corresponding\nlong graph distance as illustrated in figure \\ref{fig:topology}. This matrix\ndistance is then normalized by dividing it by the maximum distance between two\nnodes such that the maximum distance in the matrix is 1. In the singular case\nwhen two nodes cannot be connected through the graph, we recompute a spatial\ndistribution until all nodes can be connected.\n%%\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{figure-distances.pdf}\n  \\caption{\\textbf{Influence of the number of neighbours on the graph\n    distance.} The same initial set of 1003 neurons has been equiped with\n    2-nearest neighbors, 3 nearest neighbors and 4-nearest neighbors induced\n    topology (panels \\textbf{A}, \\textbf{B} and \\textbf{C} respectively). A\n    sample path from the the lower-left neuron to the upper-right neuron has\n    been highlighted with a thick line (with respective lengths of 59, 50 and\n    46 nodes).}\n  \\label{fig:topology}\n\\end{figure}\n\n%Consider a set $P$ of $n$ points on a finite region of $[0, 1] \\times [0, 1]$. The steps we follow to determine the topology of the SOM are: First, we compute the Euclidean distance matrix ${\\bf E} \\in \\mathbb{R}^{n\\times n}$, where $e_{ij} = \\lVert p_i - p_j \\rVert$ and $i, j=1, \\ldots, n$. Subsequently  we define a connectivity matrix ${\\bf G}_m$ with elements $g_{ij} = 1$ if $p_j$ belongs to the $m$ closest points to $p_i$ and $g_{ij} = 0$ otherwise. This definition implies that the matrix ${\\bf G}_m$ carries information about connected neurons within a predetermined vicinity. Once we compute matrix ${\\bf G_m}$, which essentially represents a graph, we compute the shortest path between each pair of nodes on the graph and we store them into a new matrix called ${\\bf D}_m$. Note that lengths are measured in number of nodes (hops) required to reach two nodes such that the two corresponding Euclidean points (represented by the nodes) may have a graph distance as illustrated in figure \\ref{fig:topology}.  \\gid{This matrix distance is then normalized by dividing it by the maximum distance between two nodes. NOT VERY CLEAR}. In the degenerative case where two nodes are not connected on the graph, we resample from a spatial distribution until all nodes have degree greater than one (are connected at least with one other node \\gid{IS THIS CORRECT?}).\n%%\n%\\begin{figure}\n%  \\includegraphics[width=\\columnwidth]{figures/distances.pdf}\n%\\caption{\\textbf{Influence of the number of neighbours on the graph distance.} The same initial set of 1003 neurons has been equipped with 2-nearest neighbors, 3 nearest neighbors and 4-nearest neighbors induced topology (panels \\textbf{A}, \\textbf{B} and \\textbf{C} respectively). A sample path from the the lower-left neuron to the upper-right neuron has been highlighted with a thick line (with respective lengths of 59, 50 and 46 nodes).}\n%  \\label{fig:topology}\n%\\end{figure}\n\n\n\\subsection{Learning}\n\nThe learning process is an iterative process between time $t=0$ and time $t=t_f \\in \\mathbb{N}^+$ where vectors $\\mathbf{v} \\in \\Omega$ are sequentially presented to the map. For each presented vector $\\mathbf{v}$ at time $t$, a winner $s \\in \\mathcal{N}$ is determined according to equation (\\ref{eq:psi}). All codes $\\mathbf{w}_{i}$ from the code book are shifted towards $\\mathbf{v}$ according to\n\\begin{equation}\n  \\Delta\\mathbf{w}_{i} = \\varepsilon(t)~h_\\sigma(t,i,s)~(\\mathbf{v} -\n  \\mathbf{w}_i)\n  \\label{eq:som-learning}\n\\end{equation}\nwith $h_\\sigma(t,i,j)$ being a neighborhood function of the form\n\\begin{equation}\n  h_\\sigma(t,i,j) = e^{- \\frac{{d^p_{ij}}^2}{\\sigma(t)^2}}\n  \\label{eq:som-neighborhood}\n\\end{equation}\nwhere $\\varepsilon(t) \\in \\mathbb{R}$ is the learning rate and $\\sigma(t) \\in \\mathbb{R}$\nis the width of the neighborhood defined as\n\\begin{equation}\n  \\sigma(t) =\n  \\sigma_i\\left(\\frac{\\sigma_f}{\\sigma_i}\\right)^{t/t_f}, \\text{ with } \\varepsilon(t) =\n  \\varepsilon_i\\left(\\frac{\\varepsilon_f}{\\varepsilon_i}\\right)^{t/t_f},\n\\end{equation}\nwhile $\\sigma_i$ and $\\sigma_f$ are respectively the initial and final neighborhood width and $\\varepsilon_i$ and $\\varepsilon_f$ are respectively the initial and final learning rate. We usually have $\\sigma_f \\ll \\sigma_i$ and $\\varepsilon_f \\ll \\varepsilon_i$.\n\n%The learning algorithm we propose in this work relies on the standard SOM algorithm~\\cite{Kohonen:1982}. Once we have define the topology of the map following the steps we described in paragraph~\\ref{sec:topo}, we can start the learning process. Learning is iterative and starts at a time $t_0=0$ and runs until some predetermined final time step, $t_f \\in \\mathbb{N}^+$, has been reached. At every iteration input vectors $\\mathbf{v} \\in \\Omega$ are sequentially given to the map with respect to the probability density function $f$ \\gid{Where is defined?}. For each vector $\\mathbf{v}$ at time $t$, a winner neuron with index  $s \\in \\mathcal{N}$ is determined according to equation (\\ref{eq:psi}). This means that at time $t$ neuron $s$ is closer to the input vector ${\\bf v}$, in the sense of Euclidean distance, than any other neuron. Once the winner neuron has been identified all codes $\\mathbf{w}_{i}$ from the current code book are shifted towards $\\mathbf{v}$ according to\n%\\begin{align}\n%\\label{eq:som-learning}\n%    \\Delta\\mathbf{w}_{i} &= \\varepsilon(t)~h(t,i,s;\\sigma)~(\\mathbf{v} - \\mathbf{w}_i), \n%\\end{align}\n%where $s$ is the index of the winner neuron, $i$ is the index of code words in the code book and $t$ is the current time step. $h_\\sigma(t,i,j;\\sigma)$ is a neighborhood function of the form\n%\\begin{equation}\n%  h(t,i,j; \\sigma) = \\exp\\Big(-\\frac{{d_{ij}}^2}{\\sigma(t)^2}\\Big)\n%  \\label{eq:som-neighborhood}\n%\\end{equation}\n%where $\\varepsilon: \\mathbb{R} \\rightarrow \\mathbb{R}$ is the learning rate time-dependent function given by $\\varepsilon(t) = \\varepsilon_i\\left(\\frac{\\varepsilon_f}{\\varepsilon_i}\\right)^{t/t_f}$, where $\\varepsilon_i$ and $\\varepsilon_f$ are the initial and final learning rates, respectively. $\\sigma: \\mathbb{R} \\rightarrow \\mathbb{R}$ is determines the width of the  neighborhood function~\\eqref{eq:som-neighborhood} and it is reads $\\sigma(t) = \\sigma_i\\left(\\frac{\\sigma_f}{\\sigma_i}\\right)^{t/t_f}$, where $\\sigma_i$ and $\\sigma_f$ are the initial and final neighborhood widths, respectively. We usually assume $\\sigma_f \\ll \\sigma_i$ and  $\\varepsilon_f \\ll \\varepsilon_i$. The entire learning procedure is summarized by Algorithm~\\ref{algo:vsom}. \n\n%% \\input{algorithm}\n\n\\subsection{Analysis Tools}\nIn order to analyze and compare the results of RSOM and SOM, we used a spectral method and persistence diagram analysis on the respective codebooks. These analysis tools are detailed below but roughly, the spectral method allows to estimate the distributions of eigenvalues in the activity of the maps while the persistence diagram allows to check for discrepancies between the topology of the input space and the topology of the map.\n\n% To analyze the results of both the Kohonen SOM and VSOM algorithms and to make any comparison between the two algorithms we use a spectral method and persistence diagram on codebooks. The spectral method estimates the distributions of eigenvalues of the activity of neurons. The persistence diagram is a topological-geometrical  approach, more precisely is a tool coming from the field of topological data analysis (TDA). TDA provides the tools to investigate the topology of the maps and the input space and spot differences between the topology of the input space and the neural space of the SOM algorithms (Kohonen and VSOM). \n\n%\\subsubsection{Topological Data Analysis}\n\\label{sec:tda}\n\nTopological Data Analysis (TDA) \\citep{Carlsson:2009} provides methods and tools to study topological structures of data sets such as point cloud and is useful when geometrical or topological information is not apparent within a data set. Furthermore, TDA tools are insensitive to dimension reduction and noise which make them well suited to analyze high-dimensional self-organized maps and their corresponding input data sets. In this work, we use the notion of persistent barcodes and diagrams \\citep{Edelsbrunner:2008} to spot any differences between the topology of the input and neural spaces. Furthermore, we can apply some metrics from TDA such as the Bottleneck distance and measure how close two persistent diagrams are.\n% qualify the quality of the representations of a map.\nSince the exact manifold (or distribution) of the input space is not known in general and the SOM algorithms only approximate it, we simplify these manifolds by retaining their original topological structure.\nHere we approach the manifolds of input and neural spaces using the Alpha complex. Before diving into more details regarding TDA, we provide here a few definitions and some notation. A $k$-simplex $\\sigma$ is the convex hull of $k+1$ affinely independent points (for instance a $0$-simplex is a point, a $1$-simplex is an edge, a $2$-simplex is a triangle, etc). A simplicial complex with vertex set $\\mathcal{V}$ is a set $\\mathcal{S}$ of finite subsets of $\\mathcal{V}$ such that the elements of $\\mathcal{V}$ belong to $\\mathcal{S}$ and for any $\\sigma \\in \\mathcal{S}$ any subset $\\sigma$ belongs to $\\mathcal{S}$. Said differently, a simplicial complex is a space that has been  constructed out of intervals, triangles, and other higher dimensional simplices.\n\nIn our analysis we let $\\mathcal{S}(\\mathcal{M}, \\alpha)$ be a Alpha simplicial complex with $\\mathcal{M}$ being a point cloud, either the input space or the neural one, and $\\alpha$ is the ``persistence'' parameter. More specifically, $\\alpha$ is a threshold (or radius as we will see later) that determines if the set $X$ spans a $k$-simplex if and only if $d(x_i, x_j) \\leq \\alpha$ for all $0 \\leq i, j \\leq k$. From a practical point of view, we first define a family of thresholds $\\alpha$ (or radius) and for each $\\alpha$, we center a ball of radius $\\alpha$ on each data point and look for possible intersections with other balls. This process is called filtration of simplicial complexes. We start from a small $\\alpha$ where there are no intersecting balls (disjoint set of balls) and steadily we increase the size of $\\alpha$ up to a point where a single connected blob emerges. As $\\alpha$ varies from a low to a large value, holes open and close as different balls start intersecting. Every time an intersection emerges we assign a {\\em birth} point $b_i$ and as the $\\alpha$ increases and some new intersections of larger simplicies emerge some of the old simplicies die (since they merge with  other smaller simplicies to form larger ones). Then we assign a {\\em death} point $d_i$. A pair of a birth and death points $(b_i, d_i)$ is plotted on a Cartesian two-dimensional plane and indicates when a simplicial complex was created and when it died. This two-dimensional diagram is called persistent diagram and the pairs (birth, death) that last longer reflect significant topological properties. The longevity of birth-death pairs is more clear in the persistent barcodes where the lifespan of such a pair is depicted as a straight line.\n\nIn other words, for each value of $\\alpha$ we obtain new simplicial complexes and thus new topological properties such as  homology are revealed. Homology encodes the number of  points, holes, or voids in a space. For more thorough reading we refer the reader to \\citep{Chazal:2017,Ghrist:2008,Zomorodian:2005}. In this work, we used the Gudhi library~\\citep{Maria:2014} to compute the Alpha simplicial complexes, the filtrations and the persistent diagrams and barcodes. Therefore, we compute the persistent diagram and persistent barcode of the input space and of the maps and we calculate the Bottleneck distance between the input and SOM and RSOM maps diagrams. The bottleneck distance provides a tool to compare two persistent diagrams in a quantitative way. The Bottleneck distance between two persistent diagrams $\\text{dgm}_1$ and $\\text{dgm}_2$ as it is described in~\\cite{Chazal:2017}\n%%\n\\begin{align}\n    \\label{eq:bottle}\n    d_b(\\text{dgm}_1, \\text{dgm}_2) &= \\inf_{\\text{matching }m}\\{ \\max_{(p, q) \\in m} \\{||p - q||_{\\infty} \\} \\},\n\\end{align}\n%%\nwhere $p \\in \\text{dgm}_1 \\backslash \\Delta$, $q \\in \\text{dgm}_2 \\backslash \\Delta$, $\\Delta$ is the diagonal of the persistent diagram (the diagonal $\\Delta$ represents all the points that they die the very moment they get born, $b = d$). A matching between two  diagrams $\\text{dgm}_1$ and $\\text{dgm}_2$ is a subset $m \\subset \\text{dgm}_1 \\times \\text{dgm}_2$ such that every point in $\\text{dgm}_1 \\backslash \\Delta$ and $\\text{dgm}_2 \\backslash \\Delta$ appears exactly once in $m$. \n\n% In a similar way the Wasserstein distance is  defined by\n% %%\n% \\begin{align}\n%     \\label{eq:wasser}\n%     W_p(\\text{dgm}_1, \\text{dgm}_2)^p &= \\inf_{\\text{matching } m} \\{ \\sum_{(p, q) \\in m}^{} ||p - q||^p_{\\infty} \\}.\n% \\end{align}\n% %%\n\n\n\n\\subsection{Simulation Details}\n\nUnless specified otherwise, all the models were parameterized using values given in table \\ref{table:parameters}. These values were chosen to be simple and do not really impact the performance of the model. All simulations and figures were produced using the Python scientific stack, namely, SciPy \\citep{Jones:2001}, Matplotlib \\citep{Hunter:2007}, NumPy \\citep{Walt:2011}, Scikit-Learn \\citep{Pedregosa:2011}. Analysis were performed using Gudhi \\citep{Maria:2014}). \nSources are available at \\href{https://github.com/rougier/VSOM}{github.com/rougier/VSOM}.\n%%\n\\begin{table}[!ht]\n  \\begin{center}\n    \\begin{tabular}{ll}\n        \\textbf{Parameter} & \\textbf{Value} \\\\\n        \\hline\n        Number of epochs      ($t_f$)           & 25000\\\\\n        Learning rate initial ($\\varepsilon_i$) & 0.50\\\\\n        Learning rate final   ($\\varepsilon_f$) & 0.01\\\\\n        Sigma initial         ($\\sigma_i$)      & 0.50\\\\\n        Sigma final           ($\\sigma_f$)      & 0.01\\\\\n    \\end{tabular}\n      \\caption{\\textbf{Default parameters} Unless specified otherwise, these are\n        the parameters used in all the simulations.}\n      \\label{table:parameters}\n  \\end{center}\n\\end{table}\n\n%We conduct all the experiments using the parameters provided by Table~\\ref{table:parameters}. In all the experiments the input space is the Cartesian product $[0, 1] \\times [0, 1]$ and neurons positions drawn from a blue noise distribution using the fast Poisson disk sampling algorithm~\\cite{Bridson:2007} (see paragraph~\\ref{sec:spatial_dist} for more details).  The source code of the proposed algorithm is written in the Python programming language (SciPy~\\cite{Jones:2001}, Matplotlib~\\cite{Hunter:2007} and NumPy~\\cite{Walt:2011}, Scikit-Learn~\\cite{Pedregosa:2011}, Gudhi~\\cite{Maria:2014}). Sources are available at \\href{https://github.com/rougier/VSOM}{github.com/rougier/VSOM}.\n\n\n%% Considering a set of $n$ points $P = \\{P_i\\}_{i \\in [1,n]}$ on a finite domain\n%% $D \\in \\mathbb{R}^2$, the Voronoi tesselation $V(P) = \\{V_i\\}_{i \\in [1,n]}$ of\n%% $P$ is defined as:\n%% %\n%% \\begin{equation}\n%%   \\forall i \\in [1,n], V_i = \\{x \\in D \\mid\n%%   \\lVert x - P_i \\rVert \\leq \\lVert x - P_j \\rVert, \\forall j \\neq i\\}\n%% \\end{equation}\n%% %\n%% Reciprocally, the (unique) Delaunay triangulation $T(P) = \\{T_i\\}_{i \\in\n%%   [1,n]}$ of $P$ is the dual graph of the Voronoi diagram and defined such that\n%% no point in $P$ is inside the circumcircle of any triangles in $T(P)$. The\n%% centers of the circumcircles are equivalent to the Voronoi diagram, i.e. a\n%% partition of $D$ into Voronoi cells. For each of the cell $V_i$, we can compute\n%% its centroid $C_i$ which is the center of mass of the cell. A Voronoi\n%% tesselation is said to be centroidal when we have $\\forall i \\in [1,n], C_i =\n%% P_i$ (see figure~\\ref{fig:CVT}).\\\\\n\n%% For an arbitrary set of points, there is no guarantee that the corresponding\n%% Voronoi tesselation is centroidal but different methods can be used to\n%% generate a centroidal tesselation from an arbitrary set of points. One of the\n%% most straightforward and iterative methods is the Lloyd relaxation scheme\n%% \\cite{Lloyd:1982}:\n%% \\begin{enumerate}\n%%   \\item The Voronoi diagram of the $n$ points is computed\n%%   \\item The centroid of each of the $n$ Voronoi cell is computed.\n%%   \\item Each point is moved to the corresponding centroid of its Voronoi cell\n%%   \\item The method terminates if criterion is met (see below), else go to 1\n%% \\end{enumerate}\n%% The algorithm finishes when the maximum distance between points and centroids\n%% is less than a given threshold as illustrated in figure~\\ref{fig:CVT}. It is\n%% to be noted that because of numerical imprecisions, there is no guarantee that\n%% an arbitrary small threshold can be reached.\n\n\n%% \\begin{figure}[htbp]\n%%   \\includegraphics[width=\\textwidth]{figures/CVT.pdf}\n%%   \\caption{\\textbf{Centroidal Voronoi Tesselation.}  \\textbf{\\textsf{A.}}\n%%     Voronoi diagram of a uniform distribution (n=100) where red dots represent\n%%     the uniform distribution and white circles represent the centroids of each\n%%     Voronoi cell. \\textbf{\\textsf{B.}} Centroidal Voronoi diagram where the\n%%     point distribution matches the centroid distribution which constitutes a\n%%     blue noise distribution (i.e. {\\em a distribution that is roughly uniformly\n%%       random with no preferred inter-point directions or distances} according\n%%     to the definition of \\cite{Ebeida:2014}). This figure has been obtained\n%%     from the initial distribution on the left after 50 iterations of the Lloyd\n%%     relaxation algorithm. }\n%%   \\label{fig:CVT}\n%% \\end{figure}\n%\n", "meta": {"hexsha": "4e3b7721d7788c0ab3efe9cba43aacc4cd5da04f", "size": 25088, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article-overleaf/02-methods.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/02-methods.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/02-methods.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": 104.0995850622, "max_line_length": 1753, "alphanum_fraction": 0.7445790816, "num_tokens": 6808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6730924349064594}}
{"text": "%!TEX root = ../main.tex\n\\section{Pure preferential attachment}\\label{section:pure-preferential-attachment}\n\n\\subsection{Degree distribution: Theory}\\label{subsection:ppa-degree-distribution}\nThe master equation that describes the evolution of the BA model is given by\n\n\\begin{equation}\n\tn(k, t+1) = n(k, t) + m \\Pi(k-1, t)n(k-1, t) - m \\Pi(k, t)n(k, t) + \\delta_{k,m}\n\t\\label{eq:master}\n\\end{equation}\nwhere $k$ is the total degree of a vertex, $n(k, t)$ is the number of nodes at time $t$ with total degree $k$, and the probability $\\Pi$ for choosing the existing vertex depends on the model. \n\nIn the pure preferential attachment model, we choose an existing edge with probability $\\Pi_{pa} = k/ 2E(t)$ where $E(t)$ is the number of edges and $2E(t)$ is the normalization constant corresponding to the total degree of the network. Assuming $E(0) = mN(0)$, the number of edges at a given time $t$ is given by $E(t) = mN(t)$, so we get $\\Pi = k / 2mnN(t)$. Since we are concerned with the degree distribution of the model at large $t$, we consider the long-time ansatz $n(k, t) \\rightarrow N(t) p_{\\infty}(k)$. \n\nSubstituting these terms into the master equation, we obtain \n\\begin{equation}\n\tp_{\\infty}(k) = \\frac{1}{2}[(k-1)p_{\\infty}(k-1) - kp_{infty}(k)] + \\delta_{k,m}\n\t\\label{eq:degree-distribution-p-infinity}\n\\end{equation}\n\nIt is clear that $p_{\\infty}(k < m) = 0$, since $m$ edges are added at every stage. So there are 2 cases to consider when solving for the above equation: $k = m$ and $k > m$. \n\nIn the first case of $k > m$, $\\delta_{k,m} = 0$ and we can rearrange \\autoref{eq:degree-distribution-p-infinity} to get\n\n\\begin{equation}\n\t\\frac{p_{\\infty}(k)}{p_{\\infty}(k+1)} = \\frac{k-1}{k+2}\n\t\\label{eq:p-infinity-k-greater-m}\t\n\\end{equation}\n\nWe can substitute in a trial solution of the form\n\n\\begin{equation}\n\tf(z) = A \\frac{\\Gamma(z+1+a)}{\\Gamma(z+1+b)}\n\t\\label{eq:trial-solution}\n\\end{equation}\nwhere $\\Gamma(z)$ is the Gamma function. Its central property is that\n\\begin{equation}\n\t\\Gamma(z+1) = z \\Gamma(z),\\,\\, \\Gamma(1) = 1.\n\t\\label{eq:gamma-function-property}\n\\end{equation}\n\nSubstituting the trial solution in \\autoref{eq:trial-solution} gives\n\\begin{equation}\n\t\\frac{A \\Gamma(z+1+a)}{\\Gamma(z+1+b)} \\times \\frac{\\Gamma(z+b)}{A \\Gamma(z+a)}\n\\end{equation}\nwhich simplifies to give $(z+a) / (z+b)$, using the the property in \\autoref{eq:gamma-function-property}.\n\nSubstituting $a = -1$ and $b=2$, we get the solution for \\autoref{eq:p-infinity-k-greater-m} in terms of $A$ and the Gamma function:\n\n\\begin{equation}\n\tp_{\\infty}(k) = A \\frac{\\Gamma(k)}{\\Gamma(k+3)}\n\\end{equation}\nwhich simplifies to \n\\begin{equation}\n\tp_{\\infty}(k) = \\frac{A}{k(k+1)(k+2)}.\n\t\\label{eq:p-infinity-solution-unknown-A}\n\\end{equation}\n\nFor the second case of $k = m$, \\autoref{eq:degree-distribution-p-infinity} becomes \n\\begin{equation}\n\tp_{\\infty}(m) = \\frac{1}{2}[(m+1)p_{\\infty}(m-1) - mp_{\\infty}(m)] + 1. \n\t\\label{eq:p-infinity-k-equals-m}\n\\end{equation}\nHowever, we already know that $p_{\\infty}(k < m) = 0$, that is, $p_{\\infty}(m-1) = 0$. Using this, and rearranging \\autoref{eq:p-infinity-k-equals-m}, we get \n\n\\begin{equation}\n\tp_{\\infty}(m) = \\frac{2}{m+2}.\n\t\\label{p-infinity-normalization}\n\\end{equation}\n\nSubstituting $k = m$ and \\autoref{p-infinity-normalization} into \\autoref{eq:p-infinity-solution-unknown-A}, we get \n\n\\begin{equation}\n\t\\frac{A}{m(m+1)(m+2)} = \\frac{2}{m+2}, \n\\end{equation}\ngiving us the constant $A$ as\n\\begin{equation}\n\tA = 2m(m+1).\n\t\\label{eq:normalization-constant}\n\\end{equation}\n\nFor this constant to be physically reasonable, we need to check that the probability satisfies normalization, that is, we need to prove\n\\begin{equation}\n\t\\sum_{k=m}^\\infty p_{\\infty}(k) = 2m(m+1)\\sum_{k=m}^\\infty \\frac{1}{k(k+1)(k+2)} = 1. \n\t\\label{eq:normalization-criteria}\n\\end{equation}\n\nThe term in the summation of \\autoref{eq:normalization-criteria} can be expanded as a partial fraction:\n\\begin{equation}\n\t\\sum_{k=m}^\\infty \\frac{1}{k(k+1)(k+2)} = \\sum_{k=m}^\\infty \\frac{1}{2k} - \\sum_{k=m}^\\infty \\frac{1}{k+1} + \\sum_{k=m}^\\infty \\frac{1}{2(k+2)}\n\t\\label{eq:partial-fractions}\n\\end{equation}\n\nBy writing out the first few terms of each summation, we can see that most terms cancel:\n\n\\begin{equation}\n\\setlength{\\arraycolsep}{0pt}% no padding\n\\newcolumntype{B}{>{{}}c<{{}}}\n\\begin{array}{ B l B l B l B l B l B}\n\t\\frac{1}{2m} & {}-{} &\\frac{1}{m+1} & {}+{} & \\cancel{\\frac{1}{2(m+2)}} & \\\\\n\t& {}+{} & \\frac{1}{2(m+1)} & {}-{} &\\cancel{\\frac{1}{m+2}} & {}+{} &\\cancel{\\frac{1}{m+3}} \\\\\n\t& & & {}+{} & \\cancel{\\frac{1}{2(m+2)}} & {}-{} & \\cancel{\\frac{1}{m+3}} & {}+{} &\\frac{1}{2(m+4)} \\\\\n\t& & & & & {}+{}& \\cancel{\\frac{1}{2(m+3)}} & {}-{} & \\frac{1}{m+4} & {}+{} & \\frac{1}{2(m+5)} \\\\\n\t& & & & & & & {}+{}& ...\\\\\n\\end{array}\n\\label{eq:summation-cancel}\n\\end{equation}\nand from the remaining terms we get the relation in \\autoref{eq:normalization-criteria}\n\\begin{equation}\n\t \\sum_{k=m}^\\infty p_{\\infty}(k) = 2m(m+1)\\left ( \\frac{1}{2m} - \\frac{1}{m} + \\frac{1}{2(m+1)} \\right ) = 2m(m+1) \\frac{1}{2m(m+1)} = 1\n\t \\label{eq:normalization-satisfied}\n\\end{equation}\n\nHence, we can confirm that the complete exact solution for the probability distribution in the long time limit is \n\\begin{equation}\n\tp_{\\infty}(k) = \\frac{2m(m+1)}{k(k+1)(k+2)}.\n\t\\label{eq:p-infinity-solution}\n\\end{equation}\n\n\\subsection{Degree distribution: Numerical analysis}\\label{subsection:ppa-numerical-analysis}\n\nTo leverage its speed, \\texttt{c++} code was used to generate graph data, while \\texttt{python} was used for data analysis due to its wide range of data analysis tools, such as \\texttt{numpy}, \\texttt{scipy}, and \\texttt{pandas}. \n\nThere were two main concerns when doing the numerical simulation:\n\n\\begin{enumerate}\n\t\\item What should the initial graph $G_0$ be? \n\t\\item Should self loops and multiple edges be allowed?\n\t\\item Of what order should $m$ and $N$ be respectively?\n\\end{enumerate}\n\nThe initial graph should be negligible if $N \\rightarrow \\infty$. In our simulations, we assumed that the $N$ chosen was large enough for this limit to apply, so we for convenience we chose our initial graph to be an empty graph. \n\nComputational efficiency of our algorithm is important considering that bigger datasets give better and more reliable statistical results. To yield statistically significant results and optimize efficiency, the following algorithm was used. In this algorithm, the array $M$ holds the list of edges represented by pairs of vertices, for example, the vertices at $M[0]$ and $M[1]$ are connected, $M[2]$ and $M[3]$ are connected, and so on. In this list, the number of occurences of a vertex is equal to its degree, so it can be used as a sample pool to achieve preferential attachment. To choose $m$ neighbours for each new vertex, we then sample from $M$. This is also equivalent to choosing an edge at random and then choosing a vertex at random from the edge. \n\n\\begin{algorithm}\n\\caption{Algorithm for preferential attachment}\\label{alg:pa}\n\\begin{algorithmic}[1]\n\\Require{number of vertices $N$, minimum degree $m$}\\Comment{$N > m$}\n\\State Initialize our graph $g$\n\\State Initialize $M$ as an empty array of length $2Nm$\n\\For{$v$ in [0, ..., n-1]}\n\t\\State add new vertex to $g$\n\t\\For{$i$ in [0, ..., m-1]}\n\t\t\\State $M[2(vm + i)] \\gets v$\n\t\t\\State draw $r$ uniformly at random \n\t\t\\State from $[0, ..., 2(vm + i)]$\\Comment{Choose random vertex from $M$}\n\t\t\\State $M[2(vm + i)+1] \\gets M[r]$ \\Comment{Add edge between vertex $M[r]$ and $v$}\n\t\\EndFor\n\\EndFor\n\\State\n\\For{$i$ in [0, ..., nm-1]}\\Comment{Add all edges stored in M into the graph}\n\t\\State Add edge $(M[2i], M[2i+1])$ to graph $g$\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\nClearly this approach produces self loops and multiple edges. However, since we are concerned with the limit of $N \\rightarrow \\infty$, these effects are insignificant. Also, while unsatisfactory, multiple edges and self-loops do not affect our theoretical result. In the large $N$ limit, the probability of getting multiple edges or self loops is small, and so for simplicity this algorithm was used without modification. \n\nTo check that the model was implemented correctly, the degree distribution generated by the model compared checked against the \\texttt{networkx} implementation of the BA model, since it is an established software package. It was verified that the degree distribution for $N = 10^5$ and different values of $m$ generated through our algorithm is highly similar to the \\texttt{networkx} degree distributions. This gives confidence that the algorithm is working as expected. At $N = 10^5$, it is already big enough to achieve a stationary degree distribution. \n\nTo investigate the degree distribution, the model was run for fixed $N$ but varying $m$. $N$ was mostly limited by efficiency and storage space to be $10^7$, and $m$ was chosen to vary logarithmically between $1$ and $32$. As $N$ is finite, there is bound to be a noisy tail at large $k$, where these degrees appeared once. To reduce the noise, 100 simulations were run for a single $m$ and the degree distribution was averaged over all runs. This can be seen in \\autoref{fig:pa-fixed-n-degree-dist}. The log-binning technique \\citep{Christensen:2005} was adopted to to collapse the noisy data. \n\n\\begin{figure}\n    \\centering\n    \\includegraphics[height=0.5\\linewidth]{img/pa-fixed-n-degree-dist}\n    \\caption{Raw degree distribution averaged over 100 runs for $m = 1, 2, 4, 8, 16, 32$. A noisy tail can still be seen at large $k$ due to finite sized effects. }\n    \\label{fig:pa-fixed-n-degree-dist}\n\\end{figure}\n\nVisually, as can be seen from \\autoref{fig:pa-fixed-n-logbin}, the numerical results seem to agree with the theoretical model after log-binning, until finite sized effects begin to kick in at large $k$. Alternatively, we can look at the complementary cumulative distribution function (ccdf) to observe the behaviour of the fat tail more clearly. This is shown in \\autoref{fig:ccdf}. We can see that near the fat tail, the numerical ccdf goes slightly higher than the theoretical, before falling off. This is consistent across different $m$ values.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[height=0.5\\linewidth]{img/pa-fixed-n-logbin}\n    \\caption{The solid lines show log-binned degree distributions for $m = 1, 2, 4, 8, 16, 32$. The dashed lines show the values predicted by the theoretical model. There is good agreement for small $k$ finite sized effects kick in. }\n    \\label{fig:pa-fixed-n-logbin}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[height=0.7\\linewidth]{img/ccdf}\n    \\caption{CCDF of $m=2, 4, 8, 16$, where the solid line is the numerical CCDF and the dotted line is the CCDF predicted by theory.}\n    \\label{fig:ccdf}\n\\end{figure}\n\nA Kolmogorov-Smirnov (KS) test was used to quantify the goodness-of-fit between theoretical and numerical results. It is a non-parametric test that measures how far apart two distributions are, and returns a KS-statistic that can be converted into a $p$-value. A smaller KS-statistic implies that differences between data and model are more likely to be attributed to statistical differences, while a large KS-statistic implies that the model is unlikely to have been the generating function for the data. \n\nThe table below shows the results of the KS test on $m = 1$ to $m=32$:\n\n\\begin{center}\n\\begin{tabular}{ c | c }\n m &  KS-statistic \\\\ \n \\hline\n 1 & 0.000414 \\\\  \n 2 & 0.000978 \\\\\n 4 & 0.000744 \\\\\n 8 & 0.000662 \\\\\n 16 & 0.001002 \\\\\n 32 & 0.001132 \\\\  \n\\end{tabular}\n\\label{table:ks-test}\n\\end{center}\n\nHowever, these values are meaningless unless we know what kind of deviation from theoretical is considered acceptable, and at what value we should reject the null hypothesis. To answer that, we generate synthetic datasets governed by the theoretical distribution in \\autoref{eq:p-infinity-solution} to measure how far they fluctuate from the reference theoretical distribution in a similar way as described by \\citet{Clauset2009}, and compare the results with the simulated data. \n\nThe synthetic datasets were generated with a lower bound of $m$ and an upper bound given by the maximum degree in the simulated dataset. If the simulated data is much further from the theoretical distribution than the typical synthetic data, then we would have grounds to reject the null hypothesis. \n\nFor each of the synthetic datasets, we compare it to the theoretical distribution and calculate its KS-statistic. Then we define our $p$-value as the fraction of the time the resulting statistic is larger than the value for the numerical data. We can then reject the null hypothesis if $p \\leq 0.1$ \\citep{Clauset2009}, that is, if there is a 1 in 10 probability that we would, by chance, get data that agree as poorly with the model as the current data. \n\nAnother issue to consider is the number of synthetic datasets to generate. Again, \\citet{Clauset2009} suggests a useful rule: to have p-values accurate to within about $\\epsilon$, we need at least $\\frac{1}{4}\\epsilon^{-2}$ datasets. In this project, 100 datasets were generated for each $m$, to get an accuracy of about $0.05$. \n\nThe resulting p-values are given in the table below:\n\\begin{center}\n\\begin{tabular}{ c | c }\n m &  p-value\\\\ \n \\hline\n 1 & 0.71 \\\\  \n 2 & 0.45 \\\\\n 4 & 0.50 \\\\\n 8 & 0.58 \\\\\n 16 & 0.71 \\\\\n 32 & 0.46 \\\\  \n\\end{tabular}\n\\captionof{table}{The list of $p$-values for each $m$ for preferential attachment when compared with synthetic datasets.}\n\\label{table:ks-test-all}\n\\end{center}\n\nSince the $p$-values are all larger than $0.1$, we can say it is plausible that the numerical data was drawn from the theoretical distribution. \n\nA point to note is that the KS test is used for continuous distributions, while our degree distribution is discrete. However, it was assumed that for large $N$, there will be values spanning a large range of $k$, hence the change in $k$ can be considered small, and the distribution can be approximated as a continuous distribution. \n\nA chi-squared test was also considered. The chi-squared test is a categorical test, suitable for discrete distributions, however, the test becomes invalid when the observed or expected frequencies for each category is too small, with a typical rule being that the frequencies should be at least 5 \\citep{Lawrence1997}. In our numerical data, there many large values of $k$ that only appeared once, and hence this test was determined to be not suitable. \n\n\\subsection{Largest expected degree: Theory}\nThe finite size of the system imposes a structural cutoff on the largest expected degree. For scale free networks, \\citet{Aiello2001a} defined the maximum degree to be approximately the value above which there is less than one vertex of that degree in the graph on average, that is, $N \\sum_{k = k_1}^\\infty p_\\infty(k) = 1$. \n\nGenerally, it is shown \\citep{Boguna2004} that for a scale free network with $p_{\\infty}(k) \\propto k^{\\gamma}$, the largest expected degree will be\n\n\\begin{equation}\n\tk_1(N) \\sim N^{1 / (\\gamma -1)}.\n\t\\label{eq:largest-expected-degree-research}\n\\end{equation}\n\nStarting with the equation \n\n\\begin{equation}\n\tN \\sum_{k=k_1}^\\infty p_{\\infty}(k) = 1, \n\t\\label{eq:largest-expected-degree-criteria}\n\\end{equation}\nwe can see that this is almost identical to \\autoref{eq:normalization-criteria}, just with a different factor and lower limit. Hence we have \n\n\\begin{equation}\n\t2m(m+1) \\frac{1}{2k_1(k_1+1)} = \\frac{1}{N}.\n\t\\label{eq:largest-expected-degree-derivation}\n\\end{equation}\nWe can then rearrange this to give us an expression for $k_1$:\n\\begin{equation}\n\tk_1 = \\frac{-1 + \\sqrt{1 + 4Nm(m+1)}}{2}\n\t\\label{eq:pa-k1-expression}\n\\end{equation}\nwhere the other negative solution is rejected as it is unphysical, and verifying that $k \\propto N^{0.5}$. \n\n\\subsubsection{Numerical analysis: Largest expected degree}\\label{subsection:pa-numerical-largest-degree}\n\nAs can be seen from the \\autoref{fig:pa-numerical-theoretical-k1}, the numerical value seems to be consistently lower than the theoretical $k_1$ values. This is reasonable since numerical simulations are for finite $N$, and hence there will be an upper limit to the possible degrees that a vertex can take, while in the theoretical derivation, there is no upper limit to the possible values of $k$ that a vertex can have. By looking at the ratios of $ k_1 \\text{(numerical)} / k_1 \\text{(theoretical)} $ as shown in \\autoref{table:pa-numerical-theoretical-ratio}, we can see that deviations are generally constant. \n\nWe can estimate the error on $k_1$ by calculating the standard deviation for the sample and using the following formula to estimate population standard deviation:\n\n\\begin{equation}\n\t\\sigma = \\sqrt{\\frac{1}{n} \\sum_{i=1}^n (k_{1, i} - \\bar{k}_1)^2}\n\t\\label{eq:population-std}\n\\end{equation}\nwhere $n$ is the number of repeats. In this case, $n = 100$. The values can be seen in Table 2. \n\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[height=0.5\\linewidth]{img/pa-numerical-theoretical-k1}\n    \\caption{This shows the difference in $k_1$ for different values of $N$ ranging from $100$ to $10^7$ for preferential attachment. There is a constant offset of the numerical values from the theoretical, indicating a systematic bias instead of statistical fluctuations. }\n    \\label{fig:pa-numerical-theoretical-k1}\n\\end{figure}\n\n\\begin{center}\n\\begin{tabular}{ ||c | c | c | c ||}\n\\hline\nN & $k_1^{\\text{theory}}$ & $k_1^{\\text{numerical}}$ & $k_1^{\\text{numerical}} / k_1^{\\text{theory}} $\\\\ \n\\hline\n$10^2$ & 45    & 39.3  $\\pm$ 0.1 & 0.889 \\\\  \n$10^3$ & 141   & 124.9 $\\pm$ 0.3 & 0.886 \\\\\n$10^4$ & 447   & 396   $\\pm$  1  & 0.887 \\\\\n$10^5$ & 1414  & 1248  $\\pm$  3  & 0.883 \\\\\n$10^6$ & 4472  & 3924  $\\pm$  9  & 0.878 \\\\\n$10^7$ & 14142 & 12558 $\\pm$ 30  & 0.888 \\\\  \n\\hline\n\\end{tabular}\n\\label{table:pa-numerical-theoretical-ratio}\n\\captionof{table}{This table shows the theoretical and numerical values for the largest expected degree as defined in \\autoref{eq:pa-k1-expression} for preferential attachment. The errors on $k_1$ are rounded off to 1 significant figure. }\n\\end{center}\n\n\nTo produce a data collapse, we need to find the function $f$ such that \n\n\\begin{equation}\n\tp_N(k) = f(k) \\mathcal{G}\\left ( k / k_1 \\right )\n\t\\label{eq:data-collapse}\n\\end{equation}\n\nTo find $f(k)$, we know that in the limit of $N \\rightarrow \\infty$, $p$ must have no dependence on $L$, and in the large $N$ limit, $p_N(k) = f(k)$ which is just $p_{\\infty}(k)$. This implies \n\\begin{equation}\n\t\\frac{p_N(k)}{p_{\\infty}(k)} = G \\left ( k / k_1 \\right )\n\\end{equation}\nwhich means that plotting $p_N(k) / p_{\\infty}(k)$ against $k / k_1$ will produce a data collapse, as shown in \\autoref{fig:pa-data-collapse}. \n\n\\begin{figure}\n    \\centering\n    \\includegraphics[height=0.5\\linewidth]{img/pa-data-collapse}\n    \\caption{Data collapse of the degree distribution for networks of size $N=10^2, 10^3, 10^4, 10^5, 10^6, 10^7$}\n    \\label{fig:pa-data-collapse}\n\\end{figure}", "meta": {"hexsha": "b10290293e4161ef0cb991342fa69050edd1e463", "size": 18969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/ppa.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/ppa.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/ppa.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": 59.278125, "max_line_length": 761, "alphanum_fraction": 0.7162739206, "num_tokens": 5763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.673092429656824}}
{"text": "\\section{Dress spectral sequence, Leray-Hirsch}\\label{section-leray-hirsch}\nI think I have to be doing something tomorrow, so no office hours then.\nThe new pset is up, and there'll be one more problem up.\nThere are two more things about spectral sequences, and specifically the multiplicative structure, that I have to tell you about.\nThe construction of the Serre sseq isn't the one that we gave.\nHe did stuff with simplicial homology, but as you painfully figured out, $\\Delta^s\\times\\Delta^t$ isn't another simplex.\nSerre's solution was to not use simplices, but to use cubes.\nHe defined a new kind of homology using the $n$-cube.\nIt's more complicated and unpleasant, but he worked it out.\n\\subsection{Dress' sseq}\nDress made the following variation on this idea, which I think is rather beautiful.\nWe have a trivial fiber bundle $\\Delta^t \\to \\Delta^s\\times\\Delta^t\\to \\Delta^s$.\nLet's do with this what we did with homology in the first place.\nDress started with some map $\\pi:E\\to B$ (not necessarily a fibration), and he thought about the set of maps from $\\Delta^s\\times\\Delta^t\\to \\Delta^s$ to $\\pi:E\\to B$.\nThis set is denoted $\\Sin_{s,t}(\\pi)$.\nThis forgets down to $S_s(B)$.\nAltogether, this $\\Sin_{\\ast,\\ast}(\\pi)$ is a functor $\\Deltab^{op}\\times\\Deltab^{op}\\to \\set$, forming a ``bisimplicial set''.\n\nThe next thing we did was to take the free $R$-module, to get a bisimplicial $R$-module $R\\Sin_{\\ast,\\ast}(\\pi)$.\nWe then passed to chain complexes by forming the alternating sum.\nWe can do this in two directions here!\n(The $s$ is horizontal and $t$ is vertical.)\nThis gives us a double complex.\nWe now get a spectral sequence!\nI hope it doesn't come as a surprise that you can compute the horizontal -- you can compute the vertical differential first, and then taking the horizontal differential gives the homology of $B$ with coefficients in something.\nOh actually, the totalization $tR\\Sin_{\\ast,\\ast}(\\pi) \\simeq R\\Sin_\\ast(E) = S_\\ast(E)$.\nWe'll have\n$$\nE^2_{s,t} = H_s(B;\\text{crazy generalized coefficients}) \\Rightarrow H_{s+t}(E)\n$$\nThese coefficients may not even be local since I didn't put any assumptions on $\\pi$!\nThis is like the ``Leray'' sseq, set up without sheaf theory.\nIf $\\pi$ is a fibration, then those crazy generalized coefficients is the local system given by the homology of the fibers.\nThis gives the Serre sseq.\n\nThis has the virtue of being completely natural.\nAnother virtue is that I can form $\\Hom(-,R)$, and this gives rise to a multiplicative double complex.\nRemember that the cochains on a space form a DGA, and that's where the cup product comes from.\nThe same story puts a bigraded multiplication on this double complex, and that's true \\emph{on the nose}.\nThat gives rise a multiplicative cohomology sseq.\n\nThis is very nice, but the only drawback is that the paper is in German.\nThat was item one in my agenda.\n\\subsection{Leray-Hirsch}\nThis tells you condition under which you can compute the cohomology of a total space.\nAnyway.\nWe'll see.\n\nLet's suppose I have a fibration $\\pi:E\\to B$.\nFor simplicity suppose that $B$ is path connected, so that gives meaning to the fiber $F$ which we'll also assume to be path-connected.\nAll cohomology is with coefficients in a ring $R$.\nI have a sseq\n$$\nE_2^{s,t} = H^s(B;\\underline{H^t F}) \\Rightarrow H^{s+t}(E)\n$$\nIf you want assume that $\\pi_1(B)$ acts trivially so that that cohomology in local coefficients is just cohomology with coefficients in $H^\\ast F$.\nI have an algebra map $\\pi^\\ast:H^\\ast(B)\\to H^\\ast(E)$, making $H^\\ast(E)$ into a module over $H^\\ast(B)$.\nWe have $E^{\\ast,t}_2 = H^\\ast(B;H^t(F))$, and this is a $H^\\ast(B)$-module.\nThat's part of the multiplicative structure, since $E_2^{\\ast,0} = H^\\ast B$.\nThis row acts on every other row by that module structure.\n\nEverything in the bottom row is a permanent cycle, i.e., survives to the $E_\\infty$-page.\nIn other words\n$$\nH^\\ast(B) = E^{\\ast,0}_2 \\fib E^{\\ast,0}_3 \\fib \\cdots \\fib E^{\\ast,0}_\\infty\n$$\nEach one of these surjections is an algebra map.\n\nWhat the multiplicative structure is telling us is that $E^{\\ast,0}_r$ is a graded algebra acting on $E^{\\ast,t}_r$.\nThus, $E^{\\ast,t}_\\infty$ is a module for $H^\\ast(B)$.\n\nReally I should be saying that it's a module for $H^\\ast(B;\\underline{H^0(F)})$.\nCan I guarantee that the $\\pi_1(B)$-action on $F$ is trivial.\nWe know that $F\\to \\ast$ induces an iso on $H^0$ (that's part of being path-connected).\nSo if you have a fibration whose fiber is a point, there's no possibility for an action.\nThis fibration looks the same as far as $H^0$ of the fiber is concerned.\nThus the $\\pi_1(B)$-action is trivial on $H^0(F)$, so saying that it's a $H^\\ast(B)$-module is fine.\n\nWhere were we?\nWe have module structures all over the place.\nIn particular, we know that $H^\\ast(E)$ is a module over $H^\\ast(B)$ as we saw, and also $E^{\\ast,t}_\\infty$ is a $H^\\ast(B)$-module.\nThese better be compatible!\n\nDefine an increasing filtration on $H^\\ast(E)$ via $F_t H^n(E) = F^{n-t} H^n(E)$.\nFor instance, $F_0 H^n(E) = F^n H^n(E)$.\nWhat is that?\nIn our picture, we have the associated quotients along the diagonal on $E^{s,t}_\\infty$ given by $s+t = n$.\nIn the end, since we know that $F^{n+1} H^n(E) = 0$, it follows that\n$$F_0 H^n(E) = F^n H^n(E) = E^{n,0}_\\infty = \\img(\\pi^\\ast:H^n(B)\\to H^n(E))$$\nWith respect to this filtration, we have\n$$\n\\gr_t H^\\ast(E) = E^{\\ast,t}_\\infty\n$$\nI learnt this idea from Dan Quillen.\nIt's a great idea.\nThis increasing filtration $F_\\ast H^\\ast(E)$ is a filtration by $H^\\ast(B)$-modules, and $\\gr_t H^\\ast(E) = E^{\\ast,t}_\\infty$ is true as $H^\\ast B$-modules.\nIt's exhaustive and bounded below.\n\nThis is a great perspective.\nLet's use it for something.\nLet me give you the Leray-Hirsch theorem.\n\\begin{theorem}[Leray-Hirsch]\\label{leray-hirsch}\n    Let $\\pi:E\\to B$.\n    \\begin{enumerate}\n\t\\item Suppose $B$ and $F$ are path-connected.\n\t\\item Suppose that $H^t(F)$ is free\\footnote{Everything is coefficients in $R$} of finite rank as a $R$-module.\n\t\\item Also suppose that $H^\\ast(E)\\fib H^\\ast(F)$.\n    That's a big assumption; it's dual is saying that the homology of the fiber injects into the homology of $E$.\n    This is called ``totally non-homologous to zero'' -- this is a great phrase, I don't know who invented it.\n    \\end{enumerate}\n    Pick an $R$-linear surjection $\\sigma:H^\\ast(F)\\to H^\\ast(E)$; this defines a map $\\overline{\\sigma}:H^\\ast(B)\\otimes_R H^\\ast(F)\\to H^\\ast(E)$ via $\\overline{\\sigma}(x\\otimes y) = \\pi^\\ast(x)\\cup \\sigma(y)$.\n    This is the $H^\\ast(B)$-linear extension.\n    Then $\\overline{\\sigma}$ is an isomorphism.\n\\end{theorem}\n\\begin{remark}\n    It's not natural since it depends on the choice of $\\sigma$.\n    It tells you that $H^\\ast(E)$ is free as a $H^\\ast(B)$-module.\n    That's a good thing.\n\\end{remark}\n\\begin{proof}\n    I'm going to use our Serre sseq\n    $$\n    E^{s,t}_2 = H^s(B;\\underline{H^t F}) \\Rightarrow H^{s+t}(E)\n    $$\n    Our map $H^\\ast(E)\\to H^\\ast(F)$ is an edge homomorphism in the sseq, which means that it factors as $H^\\ast(E)\\to E^{0,\\ast}_2 = H^0(B;\\underline{H^\\ast(F)}) \\subseteq H^\\ast(F)$.\n    Since $H^\\ast(E)\\to H^\\ast(F)$, we have $H^0(B;\\underline{H^\\ast(F)}) \\simeq H^\\ast(F)$.\n    Thus the $\\pi_1(B)$-action on $F$ is trivial.\n    \\begin{question}\n\tWhat's this arrow $H^\\ast(E)\\to E^{0,\\ast}_2$?\n\tWe have a map $H^\\ast(E)\\to H^\\ast(E)/F^1 = E^{0,\\ast}_\\infty$.\n\tThis includes into $E^{0,\\ast}_2$.\n    \\end{question}\n    Now you know that the $E_2$-term is $H^s(B;H^t(F))$.\n    By our assumption on $H^\\ast(F)$, this is $H^s(B)\\otimes_R H^t(F)$, as algebras.\n    What do the differentials look like?\n    I can't have differentials coming off of the fiber, because if I did then the restriction map to the fiber wouldn't be surjective, i.e., that $d_r|_{E^{0,\\infty}_r} = 0$.\n    The differentials on the base are of course zero.\n    This proves that $d_r$ is zero on every page by the algebra structure!\n    This means that $E_\\infty = E_2$, i.e., $E_\\infty^{\\ast,t} = H^\\ast(B)\\otimes H^t(F)$.\n\n    Now I can appeal to the filtration stuff that I was talking about, so that $E^{\\ast,t}_\\infty = \\gr_t H^\\ast(E)$.\n    Let's filter $H^\\ast(B)\\otimes H^\\ast(F)$ by the degree in $H^\\ast(F)$, i.e., $F_q = \\bigoplus_{t\\leq q} H^\\ast(B)\\otimes H^t(F)$.\n    The map $\\overline{\\sigma}:H^\\ast(B)\\otimes H^\\ast(F)\\to H^\\ast(E)$ is filtration preserving, and it's an isomorphism on the associated graded.\n    This is the identification $H^\\ast(B)\\otimes H^t(F) = E^{\\ast,t}_\\infty = \\gr_t H^\\ast(E)$.\n    Since the filtrations are exhaustive and bounded below, we conclude that $\\overline{\\sigma}$ itself is an isomorphism.\n\\end{proof}\n", "meta": {"hexsha": "363a1a2c105bc5099110a984af971d795ce7c28b", "size": 8655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-68-leray-hirsch.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-68-leray-hirsch.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-68-leray-hirsch.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": 58.8775510204, "max_line_length": 226, "alphanum_fraction": 0.6947429232, "num_tokens": 2711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143777, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.673092426802427}}
{"text": "\\documentclass[12pt,pdftex]{article}\n\n\n\\usepackage[usenames,dvipsnames]{color}\n\\newcommand{\\jake}[1]{{\\color{blue}\\it[JTV: #1]}}\n\\newcommand{\\zeljko}[1]{{\\color{ForestGreen}\\it[ZI: #1]}}\n\\newcommand{\\problem}[1]{{\\color{red}\\it[problem: #1]}}\n\n\\title{Creating Robust Periodograms}\n\\author{Jake Vanderplas, \\v{Z}eljko Ivezi\\'{c}}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nThe Lomb-Scargle periodogram is a well-known method of analyzing periodicity in unevenly-sampled time-series data. The problem with the LS approach is that it is not robust to outliers in data. In this paper we propose and compare three approaches to computing robust periodograms: a procedural iterative drop-out approach, a frequentist approach based on robust loss functions, and a Bayesian approach based on marginalization over nuisance parameters.\n\\end{abstract}\n\n\\section{The Plan}\n\\begin{enumerate}\n  \\item Derive classic (generalized) Lomb-Scargle\n  \\item Demonstrate the non-robustness of the classic result\n  \\item Show the Bayesian formulation \\& the robust mixture-model version\n  \\item Show the M-Estimator robust version (Huber's loss function)\n  \\item Show the iterative dropout engineering solution\n  \\item Compare results for robustness, computational complexity, etc.\n\\end{enumerate}\n\n\\section{The Lomb-Scargle Periodogram}\nThe Lomb-Scargle Periodogram is fundamentally a measure of a normalized chi-squared for fitting a sinusoidal model to data. Given data $\\{t_j, y_j\\}$ with homoscedastic Gaussian errors $\\sigma$, and assuming that the mean was subtracted from ``raw'' data\nvalues $\\{y_j\\}$, we can choose a single-term linear sinusoidal model defined by the frequency $\\omega$ and amplitudes $a$ and $b$:\n\n\\begin{equation}\n  f(t|\\omega, a, b) \\equiv a\\sin(\\omega t) + b\\cos(\\omega t)\n\\end{equation}\n\nGiven this model, we can write the likelihood\n\n\\begin{equation}\n\\label{eq:dataL} \n L \\equiv p(\\{y_j\\} |~\\omega, a, b, \\{t_j\\}, \\sigma) =\n  \\prod_{j=1}^{N} \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\exp\\left(\n  \\frac{-[y_j - f(t_j|a, b, \\omega)]^2}{2\\sigma^2} \\right)\n\\end{equation}\n\nFor any choice of $\\omega$, we can find values $[a_0(\\omega), b_0(\\omega)]$ which maximize this likelihood. The goodness-of-fit can be determined by evaluating $\\chi^2$ at this maximum:\n\n\\begin{equation}\n  \\chi^2(\\omega) = \\frac{1}{\\sigma^2}\\sum_{j=1}^N[y_j - f(t|\\omega, a_0(\\omega), b_0(\\omega))]^2\n\\end{equation}\n\nIf we define $\\chi_0^2 = \\sigma^{-2}\\sum y_j^2$, then we can write the {\\it Lomb-Scargle Periodogram} as\n\n\\begin{equation}\n\\label{eq:PLS} \n  P_{LS}(\\omega) \\equiv 1 - \\frac{\\chi^2(\\omega)}{\\chi_0^2}\n\\end{equation}\n\nThis periodogram is a normalized measure of the goodness-of-fit of a sinusoidal model with frequency $\\omega$, as compared to the null hypothesis of a pure-noise constant model, and lies in the range $0 \\le P_{LS} \\le 1$.\n\n\\subsection{Computing $P_{LS}$}\nWe can compute $P_{LS}$ quite easily via the above formalism.\nFor later convenience, let's re-express our model in the form of a matrix-vector product:\n\\begin{equation}\n  f(t|\\omega, \\theta) = X_\\omega \\theta,\n\\end{equation}\nwhere in the simple case above, $\\theta = [a, b]^T$ and\n\\begin{equation}\n  X_\\omega = \\left[\\begin{array}{lll}\n    \\sin\\omega t_1 && \\cos\\omega t_1\\\\\n    \\sin\\omega t_2 && \\cos\\omega t_2\\\\\n     & \\vdots &\\\\\n    \\sin\\omega t_N && \\cos\\omega t_N\n  \\end{array}\\right]\n\\end{equation}\nLetting $y = [y_1, y_2\\cdots y_N]^T$ be the vector of amplitudes, the $\\chi^2$ expression can be concisely written\n\\begin{equation}\n\\chi^2(\\omega, \\theta) = \\frac{1}{\\sigma^2}||y - X_\\omega \\theta||^2\n\\end{equation}\nAssuming a fixed $\\omega$, this $\\chi^2$ can be minimized by standard means to find the best-fit parameters:\n\\begin{equation}\n\\label{eq:thetaML}\n  \\theta_0(\\omega) = (X_\\omega^TX_\\omega)^{-1}X_\\omega^Ty.\n\\end{equation}\nPlugging this result back in to the expression for $\\chi^2$ gives\n\\begin{equation}\n\\label{eq:chi2}\n  \\chi^2(\\omega) = \\frac{1}{\\sigma^2}\\left[\n    y^Ty - y^TX_\\omega(X_\\omega^TX_\\omega)^{-1}X_\\omega^Ty\n    \\right]\n\\end{equation}\nThe reference model (with $X=0$) gives $\\chi_0^2 = \\sigma^{-2}y^Ty$, so we see that\n\\begin{equation}\n  P_{LS}(\\omega) = \\frac{y^TX_\\omega(X_\\omega^TX_\\omega)^{-1}X_\\omega^Ty}{y^Ty}\n\\end{equation}\nIn the standard treatment, $P_{LS}$ is defined as some recipe of products of sines and cosines (e.g. Scargle 1982; Zechmeister \\& Kurster 2009, ICVG2014): all of that is contained in the above expression, and we won't repeat it here. Further, it is possible to use some tricks involving fast Fourier transforms to quickly compute the above expression for many frequencies $\\omega$, but we'll not get into those algorithmic considerations here.\n\nThe important point here is that fundamentally, the Lomb-Scargle periodogram is simply a normalized measure of the $\\chi^2$ for a {\\bf maximum-likelihood model fit} of a particular single-frequency periodic model. Further, it's clear that by changing the definition of $X_\\omega$ and adding more columns, we can quite easily account for an arbitrary offset $\\mu$ (as in the {\\it floating-mean Lomb-Scargle method} proposed by Zechmeister \\& Kurster 2009), include non-uniform errors $\\sigma_j$, compute the periodogram for arbitrary multi-harmonic and multi-frequency models, etc. For detailed discussion, see Section 10.3 in ICVG2014.\n\n\\jake{Show an example periodogram \\& folded light curve here}\n\n\\jake{Mention generalizations to multiple Fourier terms: Bretthorst 2003; Zechmeister \\& Kurstur 2009. These are included in our formalism here!}\n\n\\jake{This all needs to be slightly modified for heteroscedastic errors. Should we do this from the beginning, or mention it separately?}\n\n\\subsection{Bayesian View of the Lomb-Scargle Periodogram}\n\\jake{Mention Bretthorst's work in this area}\n\nThe Bayesian view of this also starts with the likelihood.\nWe'll specify this in terms of $\\omega$, which is our model for a given frequency $\\omega$. In this case, the likelihood is:\n\n\\begin{equation}\n  p(D|\\omega,\\theta) =\n  (2\\pi\\sigma^2)^{-N/2} \\exp\\left(\n  \\frac{-||y - X_\\omega\\theta||^2}{2\\sigma^2}\n  \\right)\n\\end{equation}\napplying Bayes' rule and marginalizing over $\\theta$ gives:\n\\begin{equation}\n  p(\\omega|D) = \\frac{1}{p(D)}\\int p(D|\\omega,\\theta)p(\\omega, \\theta){\\rm d}^N\\theta\n\\end{equation}\nIf we assume uniform priors (i.e. $p(\\omega, \\theta) \\propto 1$) then it can be shown (see Appendix) that the Bayesian odds ratio between the model $\\omega$ and the null model $M_0$ is given by:\n\n\\begin{equation}\n  O_\\omega \\equiv \\frac{p(\\omega|D)}{p(M_0|D)} \\propto \\exp\\left(\\frac{\\chi^2(\\omega)}{2\\sigma^2}\\right) \\propto \\exp\\left(\\frac{\\chi_0^2}{2\\sigma^2}P_{LS}(\\omega)\\right)\n\\end{equation}\n\n\nThis is our Bayesian alternative to the frequentist Lomb-Scargle periodogram.\nMaximizing $O_\\omega$ across multiple values of $\\omega$ gives us the best period in the Bayesian sense.\nThe beauty here is that, unlike the Lomb-Scargle result which is predicated on $\\chi^2$ as a goodness-of-fit, our Bayesian model allows the insertion of any likelihood, including ones which may be robust to outliers. We'll consider this below.\n\n\\jake{should we consider floating-mean LS from the beginning? in this case, the null model is not just $||y||^2$, but is $||y - \\mu||^2$ where we solve for $\\mu$: that is, $X_0 = [1, 1, \\cdots 1]^T$. Nothing else needs to be modified, which is the nice part of this linear algebra approach!}\n\n\\section{Non-Robustness of the Classic Lomb-Scargle}\n\n\\jake{Show a figure here, perhaps using LINEAR sample 1004849}\n\n\\section{Robust Periodogram: Huber Loss}\n{\\it Follow Huber 1981 and use a general $M$-estimator corresponding to the Huber Loss (Huber 1963).}\n\nHuber (1981) proposed the $M$-estimator, which minimizes the generalized loss function\n\\begin{equation}\n  \\sum_i \\rho(y_i|y).\n\\end{equation}\nIn the special case of the standard maximum-likelihood this loss function is proportional to the log of the likelihood:\n\\begin{equation}\n  \\rho(y_i|y) = \\frac{(y_i - y)^2}{2\\sigma_i^2}.\n\\end{equation}\nThis makes it clear that any outliers contribute quadratically to the loss, which is why they will have such a large effect on the fit.\nOne way to address this is to soften these tails for distant points. Huber (1963) proposed a softer loss function, usually known as the {\\it Huber Loss}:\n\\begin{equation}\n  \\rho_H(y_i|y,c) = \\left\\{\n  \\begin{array}{ll}\n    \\frac{1}{2}t^2; & |t| \\le c \\\\\n    c|t| - \\frac{1}{2}c^2; & |t| > c\n  \\end{array}\n  \\right.\n\\end{equation}\nwhere we've defined $t_i \\equiv (y_i - y) / \\sigma_i$. Here $c$ is a free parameter which gives the cutoff (in units of $\\sigma$) beyond which the loss function turns over.\n\nIf we replace the standard $\\chi^2$ goodness-of-fit with an adjusted goodness-of-fit based on this Huber loss, the result is a more robust estimate of the periodogram. Unlike the standard solution above, there is no closed-form version of this. Instead we must do this in a two-step process:\n\n\\begin{equation}\n  \\theta_0(\\omega, c) = \\arg\\min_\\theta \\sum_i\\rho_H(y_i|X_\\omega\\theta, c)\n\\end{equation}\n\nOnce this is computed, the loss is simply $\\sum\\rho_H(y_i|X_\\omega\\theta_0,c)$, and the robust periodogram is\n\n\\begin{equation}\n  P_{LS,H}(\\omega|c) = 1 - \\frac{\\sum_i\\rho_H(y_i|X_\\omega\\theta_0,c)}{\\sum_i\\rho_H(y_i|0,c)}\n\\end{equation}\n\n\\section{Robust Periodogram: Iterative Drop-outs}\nad-hoc procedural solution. Fit a model, drop outliers, repeat until it converges.\n\n\\jake{I just realized an issue: the drop-outs will be different for each $\\omega$! That is, for the wrong $\\omega$ the $\\chi^2$ should be very large. Should there be a limit on the number of dropped points?}\n\n\n\\section{Robust Periodogram based on Bayesian Approach}\n\nA well-known problem with the Lomb-Scargle periodogram is its lack of robustness to outliers: the Gaussian form of the likelihood expression means that if the errors $\\sigma_j$ are mis-specified, the outlying point(s) might have a large effect on the final fit. \nWhat is required is to replace the above $\\chi^2$ computation with a robust model that can account for these errors.\n\nIf we knew which points were outliers, then we would simply exclude them and\napply standard Gaussian results to the remaining points (assuming that outliers\nrepresent a small fraction of the data set). We will assume that we do not have this\ninformation. Bayesian analysis enables a formal treatment of this problem, as well \nas the ability to estimate which points are likely outliers using an objective framework.\n\nFirst, given $\\{t_j, y_j, \\sigma_j\\}$, how do we assess whether non-Gaussianity is important? \nIn case of no outliers, we expect that\n\\begin{equation}\n           \\chi^2_{\\rm dof} = {1 \\over N-1} \\chi^2(\\omega_0) \\approx 1,\n\\end{equation}\nwhere $\\chi^2(\\omega_0)$ is given by eq.~\\ref{eq:chi2}, and evaluated at $\\omega=\\omega_0$ which\nminimizes its value. If $\\chi^2_{\\rm dof}-1$ is a few times larger than $\\sqrt{2/(N-1)}$, then it is unlikely\n(as given by the cumulative pdf for $\\chi^2_{\\rm dof}$ distribution) that our data set $\\{t_j, y_j\\}$ was \ndrawn from a distribution specified by the chosen model and Gaussian error distribution with \nthe claimed $\\{\\sigma_j\\}$.\n\n\n\\subsection{Bayesian Periodogram} \n\nWe start by reformulating the data likelihood from eq.~\\ref{eq:dataL}  as\n\\begin{eqnarray}\n\\label{eq:dataL2} \n    p(\\{y_j, g_j\\} |~\\omega, \\theta, \\{t_j, \\sigma_j\\}) = \\nonumber \\\\ \n  \\prod_{j=1}^{N} \\left[ \\frac{g_j}{\\sqrt{2\\pi\\sigma_j^2}} \\exp\\left(\n  \\frac{-[y_j - f(t_j|\\omega, \\theta)]^2}{2\\sigma_j^2}\\right) + \n       (1-g_j) p_{\\rm bad}(y_j|I) \\right].\n\\end{eqnarray}  \nHere $g_j$ is 1 if the data point is ``good'' and 0 if it came from the distribution\nof outliers, $p_{\\rm bad}(y_j|I)$. In this model $p_{\\rm bad}(y_j|I)$ applies to all\noutliers. Again, if we knew $g_j$ this would be an easy problem to solve.\n\nSince $\\{g_j\\}$ represent hidden variables, we shall treat them as model parameters and then\nmarginalize over them to get $p(\\theta|\\{y_j, t_j, \\sigma_j\\} ,I)$. With a separable prior,\nwhich implies that the reliability of the measurements is decoupled from the true value\nof the quantity we are measuring,\n\\begin{equation}\n        p(\\theta,\\{g_j\\}|I) = p(\\theta|I)  \\, p(\\{g_j\\}|I),\n\\end{equation}\nwe get\n\\begin{equation}\n   p(\\theta,\\{g_j\\}|~\\{y_j, t_j, \\sigma_j\\}, I) \\propto \\prod_{j=1}^{N} \\left[ g_j p_{\\rm good}(y_j)   + (1-g_j) p_{\\rm bad}(y_j|I) \\right] p(\\{g_j\\}|I),\n\\end{equation}\nwhere we assumed uniform priors for parameters $\\theta$ and introduced for notational simplicity\n\\begin{equation}\n       p_{\\rm good}(y_j) = \\frac{1}{\\sqrt{2\\pi\\sigma_j^2}} \\exp\\left(\n                  \\frac{-[y_j - f(t_j|\\omega, \\theta)]^2}{2\\sigma_j^2}\\right). \n\\end{equation}\nFinally, marginalizing over $g_j$ gives\n\\begin{equation}\n  p(\\theta|~\\{y_j, t_j, \\sigma_j\\}, I) \\propto \\int  p(\\theta,\\{g_j\\}|~\\{y_j, t_j, \\sigma_j\\}, I) \\, d^N g_j.\n\\end{equation}\n\n\nFollowing Section 5.6.7 in ICVG2014, in case of uniform priors for all $g_j$, marginalization over\n$g_j$ effectively replaces every $g_j$ by 1/2 and leads to \n\\begin{equation}\n\\label{eq:Btheta}\n   p(\\theta|~\\{y_j, t_j, \\sigma_j\\}, I) \\propto \\prod_{j=1}^{N} \\left[ p_{\\rm good}(y_j)  + p_{\\rm bad}(y_j|I) \\right]. \n\\end{equation}\n\n\\jake{Show the expression for $p(\\omega|~\\{y_j, t_j, \\sigma_j\\}, I)$; this is what we compute via MCMC}\n\n\\section{Discussion}\n\\begin{enumerate}\n  \\item compare the three approaches\n  \\item compare results on several LINEAR curves\n  \\item discuss computational issues  \n\\end{enumerate}\n \n\n\\subsection{QA and Visualization} \n\nAn obvious plot is to compare Lomb-Scargle and Bomb-Scargle periodograms in the same figure. \n\nOne could make a 2D plot where the x axis is $\\omega$ and the y axis is the $j$, the data point index.\nEach ($\\omega, j$) pixel gets colored by its MAP value of $g_j$.\n\n\n\\section{Conclusion}\nThis is what we did\n\n\\section*{References}\n\n\n\\appendix\n\\section{Deriving the Bayesian Expression}\nHere is the calculation of the Bayes factor for our model.\n\nFor separable priors $p(\\omega,\\theta) = p(\\omega)p(\\theta)$ the posterior for our linear model is:\n\n\\begin{equation}\n  p(\\omega|D) = \\frac{p(\\omega)}{p(D)}\\int{\\rm d}^N\\theta(2\\pi\\sigma^2)^{-N/2}\\exp\\left(\\frac{-||y - X_\\omega\\theta||^2}{2\\sigma^2}\\right)\n\\end{equation}\n\nWe can compute this integral by completing the square in $\\theta$. Let's look at the argument of the exponent:\n\n\\begin{equation}\n  ||y - X_\\omega\\theta||^2 = \\theta^TX_\\omega^TX_\\omega\\theta - 2\\theta^TX_\\omega^Ty + y^Ty\n\\end{equation}\n\nIf we now define the hermitian matrix $C = X_\\omega^TX_\\omega$ and find its Cholesky decomposition $U^TU = C$, then we can rewrite this as\n\n\\begin{equation}\n  ||y - X_\\omega\\theta||^2 = ||v - U\\theta||^2 + y^Ty - v^Tv\n\\end{equation}\n\nwhere the length-N array $v$ satisfies $U^Tv = X_\\omega^Ty$. Given this, we can rewrite the expression\n\n\\begin{equation}\n  ||y - X_\\omega\\theta||^2 = ||v - U\\theta||^2 + y^Ty - y^TX_\\omega C^{-1}X_\\omega^Ty\n\\end{equation}\n\nThe expression $\\phi = v - U\\theta$ is now an $\\mathbf{R}^N\\to\\mathbf{R}^N$ mapping with a Jacobian given by $U$, so we can change variables to $\\phi$ in the above integral to simplify its evaluation:\n\n\\begin{equation}\n  p(\\omega|D) = \\frac{p(\\omega)}{p(D)}(2\\pi\\sigma^2)^{-N/2}\n\\int\\frac{{\\rm d}^N\\phi}{\\det|U|}\\exp\\left(\\frac{-||\\phi||^2 - y^Ty + y^TX_\\omega(X_\\omega^TX_\\omega)^{-1}X_\\omega^Ty}{2\\sigma^2}\\right)\n\\end{equation}\n\nObserving that $\\det|U|^2 = \\det|C| = \\det|X_\\omega^TX_\\omega|$ and evaluating the (now straightforward) integral gives\n\n\\begin{equation}\n  p(\\omega|D) = \\frac{p(\\omega)}{p(D)}\\frac{1}{\\sqrt{\\det|X_\\omega^TX_\\omega|}}\n  \\exp\\left(\\frac{y^TX_\\omega(X_\\omega^TX_\\omega)^{-1}X_\\omega^Ty - y^Ty}{2\\sigma^2}\\right)\n\\end{equation}\n\nRecalling that\n\n\\begin{equation}\n  P_{LS}(\\omega) = \\frac{y^TX_\\omega(X_\\omega^TX_\\omega)^{-1}X_\\omega^Ty}{y^Ty}\n\\end{equation}\n\nwe see that we can express this\n\n\\begin{equation}\n  p(\\omega|D) = \\frac{p(\\omega)}{p(D)}\\frac{1}{\\sqrt{\\det|X_\\omega^TX_\\omega|}}\n  \\exp\\left(\\frac{y^Ty(P_{LS}(\\omega) - 1)}{2\\sigma^2}\\right)\n\\end{equation}\n\nWe can compare two models using the odds ratio:\n\\begin{equation}\n  O_{\\omega_1\\omega_2} \\equiv \\frac{p(M_{\\omega_2}|D)}{p(M_{\\omega_1}|D)}\n  =\\frac{p(M_{\\omega_2})}{p(M_{\\omega_1})}\\sqrt{\\frac{\\det|X_{\\omega_1}^TX_{\\omega_1}|}{\\det|X_{\\omega_2}^TX_{\\omega_2}|}}\\exp\\left(\\frac{y^Ty}{2\\sigma^2}\\left[P_{LS}(\\omega_2) - P_{LS}(\\omega_1)\\right]\\right)\n\\end{equation}\n\nFor the special case of $M_0$, where $X = 0$, we can show\n\\begin{equation}\n\\frac{p(M_{\\omega}|D)}{p(M_0|D)} =\n\\frac{p(M_{\\omega})}{p(M_0)}\\sqrt{\\frac{2\\pi\\sigma^2}{\\det|X_\\omega^TX_\\omega|}}\\exp\\left(\\frac{y^Ty}{2\\sigma^2}\\left[P_{LS}(\\omega) - 1\\right]\\right)\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "7c58fd0e6addb5c9f1c68031e787c089fd6400ca", "size": 16683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/BombScargle.tex", "max_stars_repo_name": "jakevdp/BombScargle", "max_stars_repo_head_hexsha": "b32c3739cb6626803a0b5b7e6065ca58aa75ed18", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-01-25T16:58:47.000Z", "max_stars_repo_stars_event_max_datetime": "2016-01-25T16:58:47.000Z", "max_issues_repo_path": "writeup/BombScargle.tex", "max_issues_repo_name": "jakevdp/BombScargle", "max_issues_repo_head_hexsha": "b32c3739cb6626803a0b5b7e6065ca58aa75ed18", "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": "writeup/BombScargle.tex", "max_forks_repo_name": "jakevdp/BombScargle", "max_forks_repo_head_hexsha": "b32c3739cb6626803a0b5b7e6065ca58aa75ed18", "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.2123893805, "max_line_length": 635, "alphanum_fraction": 0.7110831385, "num_tokens": 5437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.6730924197563629}}
{"text": "\\documentclass[12pt, titlepage, oneside]{article}\n\n\\input{settings}\n\n\\begin{document}\n\t\n\t\\textbf{ELECENG 3TQ3}\\\\\n\t\\textbf{Elston A.}\n\t\n\\section{Lecture 5}\n\n\\subsection{Bernoulli Trials}\n\nFrom the last example in Lecture 4, we talked about repeated trails with a coin toss. \n\nConsider tossing a coin 5 times, recording the outcomes, and repeating the whole process 10 times. We can say that one outcome would lead to heads and the other outcome would lead to tails. This is in a way a \"success\" and \"failure\" type experiment. We would like to know how to deal with such an event.\n\nLets continue to a probably more cooler scenario. Consider Intel's manufacturing process in which 100 CPUs are selected for testing.\nAssume that the probability of a CPU manufactured at that location failing the test is 0.02. What is the probability that of the 100 CPUs tested that k will pass the test.\n\nThe answer is simply\n\\begin{align}\n{100\\choose n} (0.98)^n (0.02)^{100-n}\n\\end{align}\nSince we do not care about which order the CPUs failed or passed, we need to only consider the combination rather than the permutation. We know that $(0.98)^n(0.02)^{100-n}$ is the probability that if you picked a single CPU if it would pass, but since we are picking 100 CPUs we need to multiply by the total combination to see the actual pass rate. \n\n\\subsection{Sub Experiment}\n\nInstead of two outcomes, we may have multiple outcomes for every trial shown as $s_1,s_2,\\dots,s_m$. We denote the probability of outcome $s_i$ as $p_i$. If we have $n$ trials, then the sum of all the $m$ outcomes during an experiment $n_1 + n_2 + \\dots + n_m = n$. The probability of the outcome is given as\n\\begin{align}\n{n \\choose n_1,n_2,\\dots,n_m} p_1^{n_1} p_2^{n_2} \\dots p_m^{n_m}\n\\end{align}\nThe coefficient in the bracket is called the multinomial coefficient and represent permutation with repetition. This is because we can have multiple outcomes being the same.\n\n\\b{note}: The multinomial coefficient is calculated as follows\n\\begin{align}\n{n \\choose n_1, n_2, \\dots, n_m} = \\frac{n!}{n_1! n_2! \\dots n_m!}\n\\end{align}\n\n\\ex Let us consider the set $\\{a,a,b,b\\}$. To final all the distinct permutations of this set, we can see it is as follows:\n${aabb,abab,abba,baab,baba,bbaa}$ so the answer is $6$ NOT $4!=24$. To find the distinct permutations, we need to divide the number of permutations that are considered as repetitions\n\\begin{align}\n{4! \\choose 2,2} = \\frac{4!}{2!2!} = 6\n\\end{align}\n\\ex How many 7 digit numbers can you create using $0,0,0,0,1,2,3$ if we ignore numbers that begin with zero\n\\begin{align}\n{7 \\choose 4} = 7!/4! = 210 \n\\end{align}\n\n\\subsection{Reliability}\nDeals with the problem in which we want to find the probability that a particular system consisting of multiple components is all working properly.\n\nThe two main types to consider are series and parallel systems. Series systems needs every component to work whereas parallel needs at least one component to work.\n\nWe \\b{ALWAYS} consider the probabilities to be independent unless specified otherwise\n\n\\ex\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{../Lecture4/images/series}\n\t\\caption{Series systems}\n\t\\label{fig:series}\n\\end{figure}\n\nGiven the probability of each component $W_i$ working is $P(W_i)$. \n\nIn this case we see the probability of the system working would be \n\\begin{align}\nP[W_1W_2W_3] = P[W_1]P[W_2]P[W_3]\n\\end{align}\nThe probability of failure would be\n\\begin{align}\nP[W_1 \\u W_2 \\u W_3] = 1-P[W_1]P[W_2]P[W_3]\n\\end{align}\nWe can see this is a direct result from our talks about independent in the previous lecture.\n\n\\ex\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.4\\linewidth]{../Lecture4/images/parallel}\n\t\\caption{Parallel systems}\n\t\\label{fig:parallel}\n\\end{figure}\n\nWith the same notation as the previous example, we can see the probability of this system working is given as follows:\n\\begin{align}\n&P[W_1 \\u W2 \\u W3] = P[W_1] + P[W_2 \\u W_3] - P[W_1 \\n (W_2 \\u W_3)]\\\\\n&= P[W_1] + P[W_2] + P[W_3] - P[W_1\\u W_2] - P[W_1 \\u W_3] - P[W_2 \\u W_3] + P[W_1 \\u W_2 \\u W_3]\n\\end{align}\nThis way is also too tedious and wastes too much time. Since we know the events are independent, we can use the following to get the same result\n\\begin{align}\nP[W_1 \\u W_2 \\u W_3] = 1- P[W_1 W_2 W_3] = 1-P[W_1]P[W_2]P[W_3]\n\\end{align}\n\\end{document}\n", "meta": {"hexsha": "0a7bc5d219a9505bfa48ad54efaa1979d8d96eb1", "size": 4337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture5/lec5.tex", "max_stars_repo_name": "elston-jja/EE3TQ3", "max_stars_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_stars_repo_licenses": ["MIT"], "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/lec5.tex", "max_issues_repo_name": "elston-jja/EE3TQ3", "max_issues_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_issues_repo_licenses": ["MIT"], "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/lec5.tex", "max_forks_repo_name": "elston-jja/EE3TQ3", "max_forks_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_forks_repo_licenses": ["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.6526315789, "max_line_length": 351, "alphanum_fraction": 0.740142956, "num_tokens": 1326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.673080954449031}}
{"text": "%!TEX root = ../TTK18-Summary.tex\n\\section{Sum of squares programming}\nSoS decomposition can prove non-negativity of polynomials. This can be used for control analysis and design for polynomial nonlinear systems.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%% SUBSECTION %%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Polynomials and monomials}\nA (multivariate) polynomial is\n%\n\\begin{equation}\n  f(x) = \\sum_k c_k\n  \\underbrace{x_1^{a_{k1}} \\dots x_n^{a_{kn}}}_{\\text{a monomial}},\\quad a_{ki} \\in \\mathbb{Z},\n\\end{equation}\n%\nand a monomial is one term in a polynomial, without the coefficient:\n%\n\\begin{equation}\n  m_k(x) = x_1^{a_{k1}} \\dots x_n^{a_{kn}}.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%% SUBSECTION %%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Sum of squares decomposition}\nA \\emph{polynomial} $f(x)$ is a SoS if it can be written as a sum of squares (lol):\n%\n\\begin{equation}\\label{eq:sos-decomp}\n  f(x) =\n  \\sum_{i=1}^N h_i^2(x) =\n  \\sum_{i=1}^N \\left(q_i\\tp v(x)\\right)^2 =\n  v\\tp(x) Q v(x)\n\\end{equation}\n%\nwhere $v(x)$ is a vector of monomials, and $Q \\geq 0$.\n\nA symmetric \\emph{polynomial matrix} $M(x)$ is an SoS matrix if it can be written\n%\n\\begin{equation}\n  M(x) = H\\tp(x) H(x)\n\\end{equation}\n%\nfor some polynomial matrix $H(x)$.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Existence of SoS decomposition}\nAn SoS decomposition is a sufficient condition for non-negativity of a polynomial. Thus, some non-negative polynomials don't have an SoS decomposition.\n\nThe existence of an SoS decomposition is only guaranteed for these nonnegative polynomials:\n%\n\\begin{itemize}\n  \\item in two variables,\n  \\item in quadratic forms, or\n  \\item in three variables and of fourth order.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Uniqueness of SoS decompositions}\nThe matrix $Q$ in \\eqref{eq:sos-decomp} and thus the SoS decomposition is not unique, because the elements of $v(x)$ are not independent:\n%\n\\begin{equation}\n  \\underbrace{2x_1^4 + 2x_1^3x_2 - x_1^2x_2^2 + 5x_2^4}_{f(x)}\n  =\n  \\underbrace{\\bmat{x_1^2 \\\\ x_2^2 \\\\ x_1x_2}\\tp}_{v(x)\\tp}\n  \\underbrace{\\bmat{2 & 0 & 1 \\\\ 0 & 5 & 0 \\\\ 1 & 0 & -1}}_{Q_1}\n  \\underbrace{\\bmat{x_1^2 \\\\ x_2^2 \\\\ x_1x_2}}_{v(x)}\n\\end{equation}\n%\nand\n%\n\\begin{equation}\n  \\underbrace{2x_1^4 + 2x_1^3x_2 - x_1^2x_2^2 + 5x_2^4}_{f(x)}\n  =\n  \\underbrace{\\bmat{x_1^2 \\\\ x_2^2 \\\\ x_1x_2}\\tp}_{v(x)\\tp}\n  \\underbrace{\\bmat{2 & -\\lambda & 1 \\\\ -\\lambda & 5 & 0 \\\\ 1 & 0 & 2\\lambda -1}}_{Q_2}\n  \\underbrace{\\bmat{x_1^2 \\\\ x_2^2 \\\\ x_1x_2}}_{v(x)}\n\\end{equation}\n\nWe have $\\det(Q_1) = -15$, and therefore $Q_1 \\ngeq 0$. Therefore, $Q_1$ does not imply that $f(x)$ is a SoS polynomial. However, we can find a $\\lambda$ in $Q_2$ that gives $Q_2 \\geq 0$, such as $\\lambda = 1 \\Rightarrow \\det(Q_2) = 4 \\Rightarrow Q_2 \\geq 0$. Thus $f(x)$ is a SoS polynomial after all.\n\nIt turns out that in general the set of parameters that make a symmetric matrix $Q \\geq 0$ is convex when it depends linearly on its parameters, and thus SoS constraints are convex.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Solving}\nSoS constraints are usually convex, and can be formulated as a convex semi-definite program. Can be solved with e.g. YALMIP or SOSTOOLS.\n\nSometimes $Q$ is very ill-conditioned, with tiny eigenvalues. Can be improved by\n\\begin{itemize}\n  \\item removing unused monomials from $v(x)$\n  \\item making $Q$ block-diagonal,\n  \\item altering $Q$ based on an initial solution,\n  \\item using software that pre- and post-processes automatically.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Validity of solution}\nPrimal SoS optimization always yields a P.D. $Q$, but the solution may be so inaccurate that the polynomial is still not SoS. With\n%\n\\begin{gather}\n  \\begin{split}\n    \\lambda_{\\min}(Q) &= \\min \\eig(Q) \\\\\n    v(x) &\\in \\mathbb{R}^M \\\\\n    r &= f(x) - v\\tp(x) Q v(x)\n  \\end{split}\n\\end{gather}\n%\nwe can guarantee positivity of $f(x)$ given\n%\n\\begin{equation}\n  \\begin{split}\n    \\lambda_{\\min}(Q) &\\geq 0 \\\\\n    \\lambda_{\\min}(Q) &\\geq M \\cdot \\abs(r)\n  \\end{split}\n\\end{equation}\n\nSometimes, a dual solver will find a valid solution that the primal does not find.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%% SUBSECTION %%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{LMIs and SoS}\nSoS problems are a special case of LMIs, but only some LMI ``tricks'' can be applied to SoSs:\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Linearizing change of variables}\nIf a problem depends linearly on $P>0$ and $PK$ (no standalone $K$s), then we can use $L = PK$ to make the problem linear in $L$ and $P$.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Congruence transform}\nFor a matrix SoS with $M(x) \\geq 0$ and a full rank $W(x)$:\n\\begin{equation}\n  M(x) \\geq 0 \\quad \\Leftrightarrow \\quad W\\tp(x) M(x) W(x) \\geq 0\n\\end{equation}\nNote: Cannot be used with scalarized Schur complement.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Scalarization}\nFor an LMI, positive definiteness has the relation\n%\n\\begin{equation}\n  L > 0 \\Leftrightarrow x\\tp L x > 0 \\quad \\forall x\n\\end{equation}\n%\nwhile for an SoS it is instead\n%\n\\begin{equation}\n  M(x) > 0 \\Leftrightarrow z\\tp M(x) z > 0 \\quad \\forall x, \\forall z.\n\\end{equation}\n%\nAs it turns out, it's better to formulate scalar-valued SoS problems.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Scalarized Schur complement}\nWith\n%\n\\begin{equation}\n  M(x) = \\bmat{E(x) & F\\tp(x) \\\\ F(x) & P(x)},\\quad P(x) \\mbox{ symmetric and invertible}\n\\end{equation}\n%\nthen\n%\n\\begin{equation}\n  \\bmat{x \\\\ z}\\tp M(x) \\bmat{x \\\\ z} > 0 \\quad \\forall\\{x,z\\} \\neq \\{0,0\\}\n\\end{equation}\n%\nis equivalent to (all matrices are functions of $x$)\n%\n\\begin{equation}\n  \\begin{split}\n    x\\tp \\left( E - F\\tp P\\inv F \\right) x &> 0 \\quad \\forall x \\neq 0 \\\\\n    z\\tp P z &> 0 \\quad \\forall z \\neq 0, \\forall x\n  \\end{split}\n\\end{equation}\n%\nbecause of\n%\n\\begin{equation}\n  M(x) =\n  \\bmat{I & F\\tp P\\inv \\\\ 0 & I}\n  \\bmat{E - F\\tp P\\inv F & 0 \\\\ 0 & P}\n  \\bmat{I & 0 \\\\ P\\inv F & I}.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Scalarized Schur product}\nIf we have\n%\n\\begin{equation}\n  \\bmat{x \\\\ w} =\n  \\bmat{I & 0 \\\\ P\\inv(x) F(x) & I}\n  \\bmat{x \\\\ z}\n\\end{equation}\n%\nthen $w$ can take any value regardless of $x$, by choosing $z$. The same applies in reverse: $z$ can take any value regardless of $x$, by choosing $w$.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{S-procedure}\nWe want to prove $f(x) > 0$ when $g(x) < 0$. Can be written\n%\n\\begin{equation}\n  f(x) + s(x) g(x) > 0\n\\end{equation}\n%\nfor an arbitrary SoS polynomial $s(x)$. With this formulation, optimizing over parameters in $s(x)$ and $g(x)$ gives a bilinear (nonconvex) problem.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%% SUBSECTION %%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Bilinear discrete systems}\nThe bilinear\\footnote{Bilinear because the next state is a function with a term that is a product of the state and the input. In a linear system, the $B_x$ term would not be present.} system\n%\n\\begin{equation}\n  x_{k+1} = A x_k + \\sum_{i=1}^m (B_i x_k + b_i) u_{i,k} = A x_k + (B_x + B) u_k\n\\end{equation}\n%\nis stable under state feedback if\n%\n\\begin{gather}\n  x_k\\tp P x_k - x_{k+1}\\tp P x_{k+1} > 0 \\\\\n  x_k\\tp P x_k\n  -\n  \\big(\n    A x_k + (B_x + B) u_k(x_k)\n  \\big)\\tp\n  P\n  \\big(\n    A x_k + (B_x + B) u_k(x_k)\n  \\big)\n  > 0\n\\end{gather}\n\nIf the system is open-loop unstable, $u_k(x_k)$ must be a ratio of same-order polynomials to achieve global quadratic stability, such as:\n%\n\\begin{equation}\n  u_k(x_k) = \\frac{C(x_k) x_k}{c_0(x_k) + 1}\n\\end{equation}\n%\nwhere $C(x_k)$ is a polynomial matrix and $c_0(x_k)$ is an SoS polynomial.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Region of convergence}\nWith a quadratic LF $V(x_k) = x_k\\tp P x_k$, a polynomial matrix $C(x_k)$, and SoS polynomials $c_0(x_k)$, $s_1(x_k,z)$, then the closed loop system is stable for all $x_k | x_k\\tp P x_k < \\gamma$ given\n%\n\\begin{equation}\n  \\bmat{x_k \\\\ z}\\tp\n  M(x)\n  \\bmat{x_k \\\\ z}\n  -\n  s_1(x_k,z) (\\gamma - x_k\\tp P x_k) > 0\n\\end{equation}\n%\nwhere (omitting arguments for brevity)\n%\n\\begin{equation}\\label{eq:polynomial-matrix-convergence}\n  M(x_k) =\n  \\begin{bmatrix}\n    (c_0 + 1) P & \\big( (c_0 + 1)A + (B_x + B)C \\big)\\tp P \\\\\n    P \\big( (c_0 + 1)A + (B_x + B)C \\big) & (c_0 + 1)P\n  \\end{bmatrix}\n\\end{equation}\n%\nwhich comes from $(c_0 + 1)$ being strictly positive, and using the scalarized Schur complement and the S-procedure.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Input saturation}\nThe input constraints\n%\n\\begin{equation}\n  -u_{i,\\max} \\leq u_i \\leq u_{i,\\max}\n\\end{equation}\n%\nare satisfied for all $x_k | x_k\\tp P x_k < \\gamma$ given\n\\begin{equation}\n  \\begin{bmatrix}\n    \\big( c_0(x_k) + 1 \\big)u_{i,\\max}^2 - q_i(x_k)(\\gamma - x_k\\tp P x_k) & c_i(x_k) \\\\\n    c_i(x_k) & c_0(x_k) + 1\n  \\end{bmatrix}\n  > 0\n\\end{equation}\n%\nwhere\n%\n$c_i(x_k)$ are rows of $C(x_k)$, and $c_0(x_k)$ and $q_i(x_k)$ are SoS polynomials.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Rate of convergence}\nWe can change $M(x)$ from \\eqref{eq:polynomial-matrix-convergence} to\n\\begin{equation}\n  M(x_k) =\n  \\begin{bmatrix}\n    (1 - \\alpha)(c_0 + 1) P & \\big( (c_0 + 1)A + (B_x + B)C \\big)\\tp P \\\\\n    P \\big( (c_0 + 1)A + (B_x + B)C \\big) & (c_0 + 1)P\n  \\end{bmatrix}\n\\end{equation}\nto guarantee an exponential convergence rate defined by $\\alpha$. There will be a tradeoff between maximizing the region of convergence and rate of convergence. Using this $M(x)$ allows us to determine the tradeoff.\n\n%%%%%%%%%%%%%%%%%%%%%% SUBSUBSECTION %%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Optimization formulation}\n\\begin{enumerate}\n  \\item If $\\alpha$, $\\gamma$, and $P$ are known, then $C$, $c_0$, $q_i$, $s_1$ enter linearly into inequalities above, and they can be solved as is.\n  \\item If $\\gamma$ and $P$ are known, we can find $C$, $c_0$, $q_i$, $s_1$ by formulating a feasibility problem (optimization without objective).\n  \\item If $C$, $c_0$, $q_i$, and $s_1$ are known, we can maximize $\\gamma$ with $P$ as a free variable. Must normalize $P$, i.e. by a constraint $\\trace(P) = k$, for some constant $k$.\n  \\item Can iterate between the two points directly above to create a controller with gradually larger region of convergence.\n\\end{enumerate}\n", "meta": {"hexsha": "977e58dffded561a3436190568f4a2a536108a7c", "size": 11018, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-sos.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-sos.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-sos.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": 36.1245901639, "max_line_length": 302, "alphanum_fraction": 0.5960246869, "num_tokens": 3622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580952177051, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.6730809483327157}}
{"text": "\n\\section{First compute cost tests}\n\nFor now plots are with SSE and the San Miguel scene (16,852,353 Vertices and 5,600,315 Triangles) \n\nThe function that is optimised: \n\n\\[totalTime = memoryTime * m + computeTime * n \\]\n\nwhile $m$ is the amount of memory batches we load (one batch is 4 in SSE or 8 in AVX) and $n$ the amount of batches we compute.\n\nAn example with SSE and a N8 with the data we collected from San Miguel:\n\\[0.665495 = memoryTime * 8  + computeTime * 8 \\]\n\\[0.749434 = memoryTime * 12 + computeTime * 8 \\]\n\\[0.825299 = memoryTime * 16 + computeTime * 8 \\]\n\\[0.943323 = memoryTime * 20 + computeTime * 8 \\]\n\nAfter a linear least squares approximation it results in $memoryTime = 0.0226$  and $computationTime = 0.0612$. For the graphs below the values are normalized.\n\nIm not sure if it is correct to multiply with the computeTime with 8 and the MemoryTime with 8. The reason i choose it like this is to have a reasonable way to do the calculation with configurations like N2, N3, N5 ...\n\n\\newpage\n\n\\pgfplotsset{\n\tevery axis/.append style={colorbar = false},\n}\n\\begin{minipage}[t]{0.8\\textwidth}\n\\begin{tikzpicture}\n\\pgfplotsset{ymin=0, ymax=1}\n\\begin{axis}[\nybar stacked,\nlegend style={at={(0.99,0.2)}, anchor = north east},\nxlabel = \\leafs,\nylabel = factor,\n]\n\n\\addplot+[ybar]table[y = leafComputeCostNorm, x = leafSize, col sep=comma]{Data/sanMiguelSSESeqMemoryLeafComputeCostTable.txt};\n\\addplot+[ybar]table[y = memoryCostNorm, x = leafSize, col sep=comma]{Data/sanMiguelSSESeqMemoryLeafComputeCostTable.txt};\n\\legend{\\strut triangle compute time, \\strut triangle memory load time}\n\\end{axis}\n\\end{tikzpicture}\n\\end{minipage}\n\n\\begin{minipage}[t]{0.8\\textwidth}\n\\begin{tikzpicture}\n\\pgfplotsset{ymin=0, ymax=1}\n\\begin{axis}[\nybar stacked,\nlegend style={at={(0.99,0.2)}, anchor = north east},\nxlabel = \\nodes,\nylabel = factor,\n]\n\n\n\\addplot+[ybar]table[y = nodeComputeCostNorm, x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n\\addplot+[ybar]table[y = memoryCostNorm, x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n\\legend{\\strut node compute time, \\strut node memory load time}\n\\end{axis}\n\\end{tikzpicture}\n\\end{minipage}\n\\newpage\nThis plot shows the computed time spent on computation or loading memory. The results of the approximation are multiplied with the m and n of the function. (for an example of N3 this would lead to n3 and m=4 since we always pad the memory to multiples of 4 for SSE)\n\n\\begin{minipage}[t]{0.8\\textwidth}\n\\begin{tikzpicture}\n\\begin{axis}\n[\n%view={90}{0} for x, view={0}{0} for y restriction\n%view={90}{0},\nxlabel = \\leafs,\nylabel = time in seconds,\ncycle list name=exotic,\nlegend style={at={(0.25,0.95)}, anchor = north west},\nxtick = {2, 3, ..., 16},\n%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},\n]\n\\addplot+[thick, mark=none]table[y expr = \\thisrowno{4} *\\thisrowno{2} , x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n\\addplot+[thick, mark=none]table[y expr = \\thisrowno{3} *\\thisrowno{0} , x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n%\\addplot+[thick, mark=none]table[y = nodeComputeCost, x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n%\\addplot+[thick, mark=none]table[y = memoryCost, x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n\\legend{node memory loading time, node computation time}\n\\end{axis}\n\\end{tikzpicture}\n\\end{minipage}\n\n\\newpage\nRelative memory cost:\n\n\\begin{minipage}[t]{0.8\\textwidth}\n\t\\begin{tikzpicture}\n\t\\begin{axis}\n\t[\n\t%view={90}{0} for x, view={0}{0} for y restriction\n\t%view={90}{0},\n\txlabel = \\leafs,\n\tylabel = ,\n\tcycle list name=exotic,\n\tlegend style={at={(0.05,1.05)}, anchor = north west},\n\txtick = {2, 3, ..., 16},\n\t%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},\n\t]\n\t\\addplot+[thick, mark=none]table[y = memoryRelative, x = branchFactor, col sep=comma]{Data/sanMiguelSSESeqMemoryNodeComputeCostTable.txt};\n\n\t\\legend{ memory factor in relation to compute cost}\n\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{minipage}", "meta": {"hexsha": "029e5c2ae892f000055896b6f4f1129acfe6b415", "size": 4225, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LatexPlots/FirstComputeCostAnalysis.tex", "max_stars_repo_name": "Hengoo/BVHRaytracer", "max_stars_repo_head_hexsha": "d911f06e1af88859a9c94926669f334a64c516eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LatexPlots/FirstComputeCostAnalysis.tex", "max_issues_repo_name": "Hengoo/BVHRaytracer", "max_issues_repo_head_hexsha": "d911f06e1af88859a9c94926669f334a64c516eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LatexPlots/FirstComputeCostAnalysis.tex", "max_forks_repo_name": "Hengoo/BVHRaytracer", "max_forks_repo_head_hexsha": "d911f06e1af88859a9c94926669f334a64c516eb", "max_forks_repo_licenses": ["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.4859813084, "max_line_length": 265, "alphanum_fraction": 0.7223668639, "num_tokens": 1414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6729787676570521}}
{"text": "\n\\section{Buckley Leverett Equations with/without Gravity} \n\n\\subsection{Nomenclature}\n\\begin{tabular}{c l}\n%\\hline\n%\n$f_{j}$: & fractional flow of phase $j$ \\\\\n%\n$f_{ij}$: & $\\partial f_{i}/\\partial S_{j}$ \\\\\n%\n$g$: & gravitational acceleration constant \\\\\n%\n$j$: & phase \\\\\n%\n$k$: & absolute permeability of the porous medium in 1D \\\\\n%\n$k_{rj}$:& relative permeability of phase $j$ \\\\\n%\n$k^{o}_{rj}$: & endpoint relative permeability of phase $j$ \\\\\n%\n$n_{j}$: & Corey exponent of phase $j$\\\\\n%\n$n_{p}$: & number of phases present\\\\\n%\n$S_{j}$: & saturation of phase $j$\\\\\n%\n$S_{j}^{\\star}$: & normalized saturation of phase $j$\\\\\n%\n$S_{rj}$: & residual saturation of phase $j$\\\\\n%\n$v$: & flow velocity in 1D\\\\\n%\n$\\mu_{j}$: & viscosity of phase $j$\\\\\n%\n$\\rho_{mj}$: & mass density of phase $j$\\\\\n%\n$\\lambda$: & eigenvalue (characteristic velocity)\\\\\n%\n$\\Lambda$: & shock velocity\\\\\n%\n$\\theta$: & dip angle of porous medium from horizontal\\\\\n%\n%\\hline\n\\end{tabular}\n\n\n\n\\subsection{Equations}\n\nUsing the notation and derivation of \\cite{Orr_2007}, the conservation equations for purely convective one-dimensional flow of two immiscible phases is\n\n\\begin{eqnarray}\n&&\\frac{{\\partial S_j }}{{\\partial \\tau }} +  \\frac{{\\partial f_j }}{{\\partial \\xi }}  = 0 \\label{eqn:BL}\\\\\n&&j = g,w,o \\nonumber\n\\end{eqnarray}\n\n\\noindent where dimensionless time $\\tau = \\frac{v t}{\\phi L}$ and dimensionless distance $\\xi = \\frac{x}{L}$ .  For the two-phase water/gas system only one of these equations is independent as $S_g + S_w = 1$.  All variables are defined in the Nomenclature section.\n\nThe fractional flow of a component is defined as\n\n\\begin{eqnarray}\n&&f_j = \\frac{\\frac{k_{rj}}{\\mu_j}}{\\sum_{n=1}^{n_p}{\\frac{k_{rn}}{\\mu_n}}} \\left( 1-\\frac{kg \\sin \\theta}{v} \\sum_{n=1}^{n_p}{\\frac{k_{rn}}{\\mu_n}\\left( \\rho_{mj}-\\rho_{mn} \\right)} \\right) \\label{eqn:ff}\n\\end{eqnarray}\n\n\\noindent where\n\n\\begin{eqnarray}\n&&k_{rj} = k_{rj}^o {\\left(S_j^*\\right)^{n_j}}\\\\\n&&S_j^* = \\frac{S_j - S_{rj}}{1-\\sum_{n=1}^{n_p}{S_{rn}}} \\nonumber\n\\end{eqnarray}\n\n\\noindent which can be written entirely in terms of $S_g$ for the Buckley-Leverett problem using $S_w = 1-S_g$.  Equation \\ref{eqn:BL} can be solved as an eigenvalue problem by ...\n\nThe exact analytical form for the derivative of the fractional flow is\n\n\\begin{eqnarray}\n\\frac{df_g}{dS_g}&=& \\frac{\\left(\\frac{\\frac{d k_{rg}}{d S_g}}{\\mu_g}\\right) \\frac{k_{rw}}{\\mu_w}-\\left(\\frac{\\frac{d k_{rw}}{d S_g}}{\\mu_w}\\right)\\frac{k_{rg}}{\\mu_g}}{\\left(\\frac{k_{rg}}{\\mu_g}+\\frac{k_{rw}}{\\mu_w}\\right)^2}\\left( 1-\\frac{kg \\sin \\theta}{v} \\frac{k_{rw}}{\\mu_w}\\left( \\rho_{mg}-\\rho_{mw} \\right) \\right)\\nonumber \\\\\n&&-f_g\\frac{kg \\sin \\theta}{v} \\frac{\\frac{d k_{rw}}{d S_g}}{\\mu_w}\\left(\\rho_{mg}-\\rho_{mw} \\right)\n\\end{eqnarray}\n\n\\noindent where\n\n\\begin{eqnarray}\n\\frac{d k_{rg}}{d S_g} &=& k_{rg}^o n_g \\frac{\\left(S_g - S_{rg}\\right)^{n_g-1}}{\\left(1-S_{rg}-S_{rw}\\right)^{n_g}}\\nonumber \\\\\n\\frac{d k_{rw}}{d S_g}&=& -k_{rw}^o n_w \\frac{\\left(1-S_g - S_{rw}\\right)^{n_w-1}}{\\left(1-S_{rg}-S_{rw}\\right)^{n_w}}\\nonumber \n\\end{eqnarray}\n\n\n\n\\subsection{Parameters in example problems}\nAll parameters in Equation \\ref{eqn:BL} are assumed to be constant in the Buckley-Leverett problem.  The fractional flow parameters are given in Table \\ref{table:paras}.\n\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{lrrrr}\n\\hline\nPhase&$S_{rj}$&$k_{rj}^o$&$n_j$& $\\mu_j$($cp$)\\\\\n%%\\lcline{1-1}\\rlcline{2-5}\nGaseous&0.1&1.0&2.0&0.1\\\\\n%Oleic&-&-&-&-\\\\\nAqueous&0.3&1.0&2.0&1.0\\\\\n\\hline\n\\end{tabular}\n\\caption{Fractional flow parameters for the benchmark Cases I-III.}\n\\label{table:paras}\n\\end{center}\n\\end{table}\n\n\n\\subsection{Solutions}\n\n\\subsubsection{Case I: Solution without gravity}\nThe first benchmark solution is for the case of no gravity, i.e. a horizontal displacement.  The initial (right state) and injection (left state) conditions are given in Table \\ref{table:BCs}.\n\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{lrr}\n\\hline\nBC & $S_g$ & $S_w$\\\\\n%%\\lcline{1-1}\\rlcline{2-3}\nInitial& 0.0 & 1.0\\\\\n(right state)&  & \\\\\nInjection&1.0 & 0.0\\\\\n(left state)&  & \\\\\n\\hline\n\\end{tabular}\n\\caption{Boundary conditions for benchmark Cases I-III. }\n\\label{table:BCs}\n\\end{center}\n\\end{table}\n\n\n\n\\begin{figure}[h]\n\\centering\n%\\includegraphics[width=0.75\\textwidth,viewport=10 10 420 420,clip]{./figures/BL_no_gravity}\n\\includegraphics[width=10.0cm,height=15.cm]{./figures/BL_no_gravity}\n\\vspace{-4.cm}\n\\caption{Top: Comparison the analytical solutions to Case I without gravity with the upstream weighted DG simulated solution with for 3 (green), 10 (blue) and 50 (red) grid blocks.  Bottom: Comparison the analytical solutions to Case I without gravity with the mixed weighted DG simulated solution for 3 (green), 10 (blue) and 50 (red) grid blocks.} \n\\label{fig:BL_no_grav}\n\\end{figure}\n\n\nThe displacement consists of a fast moving shock wave from the initial condition, with no gas, to a gas saturation of $S_g = 0.3255$, followed by a rarefaction wave to the residual water saturation. As there is no transfer of components between phases, it is impossible to move the residual water from the system.\n\nThe DG simulator was run in 2 modes, upstream weighting and 80\\% upstream weighting.  A comparison of the analytical solution for various levels of refinement is shown for upstream weighting on the top of Figure \\ref{fig:BL_no_grav} and for mixed weighting on the bottom. \n\n\\paragraph{Displacements with gravity}\n\nIn this case the flux in the conservation law is slightly different.  The fractional flow curve as computed from Eq. \\ref{eqn:ff} may be larger than one or less than zero, which is physically meaningless in one dimension as $f_g$ is defined as the fraction of the total flow that is taken up by the gas phase.  The impossible fluxes are caused by the inability of a 1D model to capture counter-current gravity-driven flow.  A 2D benchmark case to study this effect will be dealt with later.  Anytime Eq. \\ref{eqn:ff} gives $f_g > 1.0$ it must be that in 1D $f_g = 1.0$, similarly if $f_g < 0.0$ in Eq. \\ref{eqn:ff}, $f_g = 0.0$.  The additional parameters necessary for the cases including gravity are in Table \\ref{table:grav_const}.  The phase densities are calculated using the method from \\cite{spycher_2003}.\n\n\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{lr}\n\\hline\n$\\rho_g$ ($\\frac{kg}{m^3}$)& 710 \\\\\n%$\\rho_o$ ($\\frac{kg}{m^3}$)&-\\\\\n$\\rho_w$ ($\\frac{kg}{m^3}$)& 1050\\\\\ng ($\\frac{m^2}{s}$)& 9.8 \\\\\nk ($ m^2$)& $9.87E-13$\\\\\nv ($ \\frac{m}{s}$)& $5.00E-06$\\\\\n\\hline\nCase II &\\\\\n$\\theta$ (degrees) & -90 \\\\\n\\hline\nCase III &\\\\\n$\\theta$  (degrees)& 90  \\\\\n\\hline\n\\end{tabular}\n\\caption{Additional parameters needed for benchmark Cases II and III with gravity. Phase densities for water and super-critical CO$_2$ are at 80$^oC$ and 27$MPa$. }\n\\label{table:grav_const}\n\\end{center}\n\\end{table}\n\n\n\n\\paragraph{Case II: Displacements with gravity slowing displacement}\n\nThe first benchmark solution including gravity is the injection of oil into the bottom of a vertical core or sand pack. In this case analytical solution in the presence of gravity is physically meaningful, though there is a small region at low $S_g$ where $f_g < 0.0$.  The solution structure is the same as in the displacement without gravity.  Because the more dense oil is being pushed into the core against the force of gravity the leading shock front and rarefaction wave have both slowed down substantially.\n\n\n\\begin{figure}[h]\n\\vspace{-1cm}\n\\centering\n\\includegraphics[width=15.0cm,height=20.cm]{./figures/BL_gravity_up}\n%\\includegraphics[width=0.75\\textwidth,viewport=10 0 390 300,clip]{./figures/BL_gravity_up}\n\\vspace{-5.5cm}\n\\caption{Analytical solution to Case II, the stable benchmark case with gravity (black) slowing the displacement.  A fine-grid FD solution (red) and the analytical solution for the case without gravity (blue) are shown for comparison purposes.} \n\\label{fig:BL_grav_up}\n\\end{figure}\n\n\\paragraph{Case III: Displacements with gravity accelerating displacement}\n\nThe second benchmark solution including gravity is the injection of oil into the top of a vertical core or sand pack. In reality this displacement is gravity unstable and needs to be modelled in two-dimensions, but for the purposes of benchmarking the code it is still useful. \n\nThe solution with gravity is a shock wave from the right state to the saturation $S_g = 0.2960$ followed by a rarefaction wave to $S_g = 0.3340$.  Then there is a constant state to the injection composition.  This constant state is caused by the fact that $f_g > 1.0$ for large gas saturations and no longer tapers off uniformly as the residual water saturation is approached.\n\nThe analytical solution with gravity is shown in Figure \\ref{fig:BL_grav_down} with a fine-grid FD solution and the analytical solution without gravity for comparison.  \n\n\\begin{figure}[h]\n\\vspace{-1cm}\n\\centering\n\\includegraphics[width=15.0cm,height=20.cm]{./figures/BL_gravity_down}\n\\vspace{-5.5cm}\n%\\includegraphics[width=0.75\\textwidth,viewport=10 0 390 300,clip]{./figures/BL_gravity_down}\n\\caption{Analytical solution to Case III, the unstable benchmark case with gravity (black) accelerating the displacement.  A fine-grid FD solution (red) and the analytical solution for the case without gravity (blue) are shown for comparison purposes.} \n\\label{fig:BL_grav_down}\n\\end{figure}\n\n", "meta": {"hexsha": "9595b3dadd96b361b7acfe9ac45a3c97ae7c109b", "size": 9345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "software/multifluids_icferst/legacy_reservoir_prototype/doc/appendix_BL_eqn_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/appendix_BL_eqn_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/appendix_BL_eqn_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": 44.0801886792, "max_line_length": 813, "alphanum_fraction": 0.7174959872, "num_tokens": 2938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.6728265620400711}}
{"text": "\\documentclass[letterpaper,12pt,leqno]{article}\n\\usepackage{paper,math,notes}\n\n\\begin{document}\n\n\\title{Mathematical Methods for Macroeconomics: Exercises}\n\\author{Pascal Michaillat}\n\\date{}\n\n\\begin{titlepage}\n\\maketitle\n\\end{titlepage}\n\n\\section*{Dynamic Programming}\n\n\\subsection*{Exercise 1.}\n\nConsider the following optimal growth problem: Given initial capital $k_{0}>0$, choose consumption $\\bc{c_{t}} _{t =0}^{+\\infty}$ to maximize utility\n\\begin{equation*}\n\\sum_{t=0}^{\\infty}\\b ^{t}\\cdot \\ln{c_{t}}\n\\end{equation*}\nsubject to the resource constraint\n\\begin{equation*}\nk_{t+1}=A\\cdot k_{t}^{\\a}-c_{t}.\n\\end{equation*}\nThe parameters satisfy $0<\\b<1,\\;A>0,\\;0<\\a <1.$\n\n\\begin{enumerate}\n\\item Derive the optimal law of motion of consumption $c_{t}$ using a Lagrangian.\n\\item Identify the state variable and the control variable. \n\\item Write down the Bellman equation.\n\\item Derive the following Euler equation: \n\\begin{equation*}\nc_{t+1}=\\b\\cdot  \\a\\cdot  A\\cdot k_{t+1}^{\\a -1}\\cdot c_{t}.\n\\end{equation*}\n\n\\item Derive the first two value functions, $V_{1}(k)$ and  $V_{2}(k)$, obtained by iteration on the Bellman equation starting with the value function $V_{0}\\bp{k} \\equiv 0$. \n\\item The process of determining the value function by iterations using the Bellman equation is commonly used to solve dynamic programs numerically. The algorithm is called \\textit{value function iteration}. For this optimal growth problem, one can show show using value function iteration that the value function is\n\\[V\\bp{k} =\\kappa +\\frac{\\ln{k^{\\a}}}{1-\\a\\cdot \\b},\\]\nwhere $\\k$ is a constant. Using the Bellman equation, determine the policy function $k'(k)$ associated with this value function.\n\\item In light of these results, for which reasons would you prefer to use the dynamic-programming approach instead of the Lagrangian approach to solve the optimal growth problem? And for which reasons would you prefer to use the Lagrangian approach instead of the dynamic-programming approach?\n\\end{enumerate}\n\n\\subsection*{Exercise 2.}\n\nConsider the problem of choosing consumption $\\bc{c_{t}}_{t=0}^{+\\infty}$ to maximize expected utility\n\\begin{equation*}\n\\E_{0}\\sum_{t=0}^{+\\infty}\\b^{t}\\cdot u\\bp{c_{t}}\n\\end{equation*}\nsubject to the budget constraint\n\\begin{equation*}\nc_{t}+p_{t}\\cdot s_{t+1}=\\bp{d_{t}+p_{t}}\\cdot s_{t}.\n\\end{equation*}\n$d_{t}$ is the dividend paid out for one share of the asset, $p_{t}$ is the price of one share of the asset, and $s_{t}$ is the number of shares of the asset held at the beginning of period $t$. In equilibrium, the price $p_{t}$ of one share is solely a function of dividends $d_{t}$. Dividends can only take two values $d_{l}$ and $d_{h}$, with $0<d_{l}<d_{h}$. Dividends follow a Markov process with transition probabilities \n\\begin{equation*}\n\\P\\bp{d_{t+1}=d_{l}\\mid d_{t}=d_{l}} =\\P \\bp{d_{t+1}=d_{h}\\mid d_{t}=d_{h}} =\\rho\n\\end{equation*}\nwith $1>\\rho >0.5.$\n\n\\begin{enumerate}\n\\item Identify state and control variables. \n\\item Write down the Bellman equation.\n\\item Derive the following Euler equation: \n\\begin{equation*}\np_{t}\\cdot u'\\bp{c_{t}} =\\b\\cdot  \\E{\\bp{d_{t+1}+p_{t+1}} \\cdot u'\\bp{c_{t+1}} \\mid d_{t}} .\n\\end{equation*}\n\n\\item Suppose that $u\\bp{c} =c$. Show that the asset price is higher when the current dividend is high.\n\\end{enumerate}\n\n\\subsection*{Exercise 3.}\n\nConsider the following optimal growth problem: Given initial capital $k_{0}>0$, choose consumption and labor $\\bc{c_{t},l_{t}}_{t=0}^{+\\infty}$ to maximize utility\n\\begin{equation*}\n\\sum_{t=0}^{+\\infty}\\b^{t}\\cdot u\\bp{c_{t},l_{t}}\n\\end{equation*}\nsubject to the law of motion of capital\n\\begin{align*}\nk_{t+1}&=A_{t}\\cdot f\\bp{k_{t},l_{t}} -c_{t}.\n\\end{align*}\nIn addition, we impose $0\\leq l_{t}\\leq 1$. The discount factor $\\b \\in \\bp{0,1} $. The function $f$ is increasing and concave in both arguments. The function $u$ is increasing and concave in $c$, decreasing and convex in $l$. \n\n\\paragraph{Deterministic case} First, suppose $A_{t}=1$ for all $t$.\n\n\\begin{enumerate}\n\\item What are the state and control variables?\n\\item  Write down the Bellman equation.\n\\item Derive the following optimality conditions: \n\\begin{align*}\n\\pd{u\\bp{c_{t},l_{t}}}{ c_{t}} &=\\b \\cdot \\pd{u\\bp{c_{t+1},l_{t+1}}}{c_{t+1}} \\cdot \\pd{f\\bp{k_{t+1},l_{t+1}}}{ k_{t+1}}\\\\\n\\pd{u\\bp{c_{t},l_{t}}}{ c_{t}}\\cdot \\pd{f\\bp{k_{t},l_{t}}}{l_{t}} &=-\\pd{u\\bp{c_{t},l_{t}}}{l_{t}}.\n\\end{align*}\n\\item Suppose that the production function $f\\bp{k,l} =k^{\\a}\\cdot l^{1-\\a}$. Determine the ratios $c/k$ and $l/k$ in steady state.\n\\end{enumerate}\n\n\\paragraph{Stochastic case} Now, suppose $A_{t}$ is a stochastic process that takes values $A_{1}$ and $A_{2}$ with the following probability: \n\\begin{equation*}\n\\P{A_{t+1}=A_{1}\\mid A_{t}=A_{1}} =\\P{A_{t+1}=A_{2}\\mid A_{t}=A_{2}} =\\rho .\n\\end{equation*}\n\n\\begin{enumerate}\\setcounter{enumi}{4}\n\\item Write down the Bellman equation.\n\\item Derive the optimality conditions.\n\\end{enumerate}\n\n\\section*{Optimal Control}\n\n\\subsection*{Exercise 4.}\n\nConsider the following optimal growth problem: Given initial capital $k_{0}>0$, choose a consumption path $\\bc{c_{t}}_{t\\geq 0}$ to maximize utility\n\\begin{align*}\n\\int_{0}^{\\infty}e^{-\\rho\\cdot  t} \\cdot \\ln{c_{t}} dt \n\\end{align*}\nsubject to the law of motion of capital\n\\begin{align*}\n\\dot{k}_{t} &=f\\bp{k_{t}} -c_{t}-\\d \\cdot k_{t}.\n\\end{align*}\nThe discount factor $\\rho>0$, and the production function $f$ satisfies\n \\[f\\bp{k} =A\\cdot k^{\\a},\\]\n where  $\\a \\in \\bp{0,1}$ and $A>0$.\n\n\\begin{enumerate}\n\\item Write down the present-value Hamiltonian.\n\\item Show that the Euler equation is\n\\begin{align*}\n\\frac{\\dot{c}_{t}}{c_{t}} &=\\a \\cdot  A \\cdot k_{t}^{\\a -1}-\\bp{\\d +\\rho}.\n\\end{align*}\n\n\\item Solve for the steady state of the system.\n\\end{enumerate}\n\n\\subsection*{Exercise 5.}\n\nConsider the following investment problem: Given initial capital $k_{0}$, choose the investment path $\\bc{i_{t}} _{t \\geq 0}$ to maximize profits\n\\begin{align*}\n\\int_{0}^{\\infty} e^{-r\\cdot t}\\bs{f\\bp{k_{t}} -i_{t}-\\frac{\\chi}{2}\\cdot \\bp{\\frac{i_{t}^{2}}{k_{t}}}} dt \n\\end{align*}\nsubject to the law of motion of capital (we assume no capital depreciation)\n\\[\\dot{k}_{t} =i_{t}.\\]\nThe interest rate $r>0$, the capital adjustment cost $\\chi>0$, and the production function $f$ satisfies $f'>0$ and $f''<0$.\n\n\\begin{enumerate}\n\\item Write down the current-value Hamiltonian. \n\\item Use the optimality conditions for the current-value Hamiltonian to derive the following differential equations:\n\\begin{align*}\n\\dot{k}_{t} &=\\bp{\\frac{q_{t}-1}{\\chi}}\\cdot  k_{t} \\\\\n\\dot{q}_{t} &=r\\cdot q_{t}-f'\\bp{k_{t}} -\\frac{1}{2\\cdot \\chi}\\bp{q_{t}-1}^{2}\n\\end{align*}\n\n\\item Solve for the steady state.\n\\end{enumerate}\n\n\\section*{Differential Equations}\n\n\\subsection*{Exercise 6.}\n\nFind the solution of the initial value problem \n\\begin{align*}\n\\dot{a}(t) &=r\\cdot a(t) +s \\\\\na\\bp{0} &=a_{0}\n\\end{align*}\nwhere both $r$ and $s$ are known constant.\n\n\\subsection*{Exercise 7.}\n\nFind the solution of the initial value problem \n\\begin{align*}\n\\dot{a}(t) &=r(t)\\cdot a(t) +s(t) \\\\\na\\bp{0} &=a_{0}\n\\end{align*}\nwhere both  $r(t)$ and $s(t)$ are known functions of $t.$\n\n\\subsection*{Exercise 8.}\n\nConsider the linear system of FODEs given by\n\\begin{equation*}\n\\bm{\\dot{x}}(t)=\\bs{\n\\begin{array}{ll}\n1 & 1 \\\\ \n4 & 1\n\\end{array}} \\bm{x}(t).\n\\end{equation*}\n\\begin{enumerate}\n\\item Find the general solution of the system.\n\\item What would you need to find a specific solution of the system?\n\\item Draw the trajectories of the system.\n\\end{enumerate}\n\n\\subsection*{Exercise 9.}\n\nConsider the initial value problem \n\\begin{align*}\n\\dot{k}(t) &=s\\cdot f\\bp{k(t)} -\\d\\cdot  k(t) \\\\\nk\\bp{0} &=k_{0}\n\\end{align*}\nwhere the saving rate $s\\in \\bp{0,1} $, the capital depreciation rate $\\d \\in \\bp{0,1}$, and the production function $f$ satisfies the \\textit{Inada conditions}. That is, $f$ is continuously differentiable and \n\\begin{align*}\nf(0)&=0\\\\\nf'(x)&>0\\\\\nf''(x)&<0\\\\\n\\lim_{x\\to 0} f'(x)&=+\\infty\\\\\n\\lim_{x\\to +\\infty} f'(x)&=0.\n\\end{align*}\n\n\\begin{enumerate}\n\\item Give a production function $f$ that satisfies the Inada conditions.\n\\item Find the steady state of the system.\n\\item Draw the dynamic path of $k(t) $ and show that it converges to the steady state.\n\\end{enumerate}\n\n\\subsection*{Exercise 10.}\n\nThe solution of the problem studied in Exercise 4 is characterized by a system of two nonlinear first-order differential equations:\n\\begin{align*}\n\\dot{k}_{t} &=f\\bp{k_{t}} -c_{t}-\\d \\cdot k_{t}\\\\\n\\frac{\\dot{c}_{t}}{c_{t}} &=\\a \\cdot  A \\cdot k_{t}^{\\a -1}-\\bp{\\d +\\rho}.\n\\end{align*}\nThe first FODE is the law of motion of capital. The second FODE is the Euler equation, which describes the optimal path of consumption over time.\n\n\n\\begin{enumerate}\n\\item Draw the phase diagram of the system.\n\\item Linearize the system around its steady state.\n\\item Show that the steady state is a saddle point  locally.\n\\item Suppose the economy is in steady state at time $t_{0}$ and there is an unanticipated decrease in the discount factor $\\rho$. Show on your phase diagram the transition dynamics of the model.\n\\end{enumerate}\n\n\\subsection*{Exercise 11.}\n\nThe solution of the investment problem studied in Exercise 5 is characterized by a system of two nonlinear first-order differential equations:\n\\begin{align*}\n\\dot{k}_{t} &=\\bp{\\frac{q_{t}-1}{\\chi}}\\cdot  k_{t} \\\\\n\\dot{q}_{t} &=r\\cdot q_{t}-f'\\bp{k_{t}} -\\frac{1}{2\\cdot \\chi}\\bp{q_{t}-1}^{2}.\n\\end{align*}\nThe first FODE is the law of motion of capital $k_{t}$. The second FODE is the law of motion of the co-state variable $q_{t}$.\n\n\\begin{enumerate}\n\\item Draw the phase diagram.\n\\item Show that the steady state is a saddle point locally.\n\\end{enumerate}\n\n\\subsection*{Exercise 12.}\n\nConsider a discrete time version of the typical growth model:\n\\begin{align*}\nk(t+1) &=f\\bp{k(t)} -c(t) +\\bp{1-\\d}\\cdot  k(t) \\\\\nc(t+1) &=\\b\\cdot  \\bs{ 1+f'\\bp{k(t)} -\\d }\\cdot  c(t) .\n\\end{align*} \nThe discount factor $\\b \\in \\bp{0,1}$, the rate of depreciation of capital $\\d \\in \\bp{0,1}$, initial capital $k_{0}$ is given, and the production function $f$ satisfies the Inada conditions. These two equations are a system of first-order difference equations. Whereas a system of first-order differential equations relates $\\bm{\\dot{x}}(t) $ to $\\bm{x}(t)$, a system of first-order difference equations relate $\\bm{x}(t+1) $ to $\\bm{x}(t)$.\n\nIn this exercise, we will see that we can study a system of first-order difference equations with the tools that we used to study  systems of first-order differential equations. In particular, we can use phase diagrams to understand the dynamics of the system.\n\n\\begin{enumerate}\n\\item Construct a phase diagram for the system. First, define \n\\begin{align*}\n\\D k & \\equiv k(t+1) -k(t) , \\\\\n\\D c & \\equiv c(t+1) -c(t) .\n\\end{align*}\nSecond, draw the $\\D k=0$ locus and the $\\D c=0$ locus on the $(k,c)$ plane. Finally, find the steady state as the intersection of the $\\D k=0$ locus and the $ \\D c=0$ locus.\n\\item Show that the steady state is a saddle point in the phase diagram.\n\\end{enumerate}\n\n\\subsection*{Exercise 13.}\n\nWe consider the following optimal growth problem. Given initial human capital $h_{0}$ and initial physical capital $k_{0}$, choose consumption $c(t) $ and labor $l(t) $ to maximize utility\n\\begin{equation*}\n\\int_{0}^{\\infty}e^{-\\rho\\cdot  t}\\cdot \\ln{c} dt\n\\end{equation*}\nsubject to\n\\begin{align*}\n\\dot{k}_{t} &=y_{t}-c_{t}-\\d\\cdot  k_{t} \\\\\n\\dot{h}_{t} &=B\\cdot \\bp{1-l_{t}}\\cdot  h_{t}.\n\\end{align*}\nOutput $y_{t}$ is defined by\n\\[y_{t}\\equiv A\\cdot k_{t}^{\\a}\\cdot \\bp{l_{t}\\cdot h_{t}} ^{\\b}.\\]\nWe also impose that $0 \\leq l_{t}\\leq 1$. The discount factor $\\rho>0$, the rate of depreciation of physical capital $\\d>0$, the constants $A>0$ and $B>0$, and the production function parameters $\\a\\in \\bp{0,1}$ and $\\b \\in\\bp{0,1}$.\n\n\\begin{enumerate}\n\\item Give state and control variables.\n\\item Write down the present-value Hamiltonian for this problem.\n\\item Derive the optimality conditions. \n\\item Show that the growth rate of consumption $c(t)$ is\n\\begin{equation*}\n\\frac{\\dot{c}}{c}=\\frac{\\a\\cdot  y}{k}-\\bp{\\d +\\rho} .\n\\end{equation*}\n\\item From now on, we assume that $B=0$. Show that $l=1$.\n\\item Draw the phase diagram in the $(k,c)$ plane.\n\\item Show on the diagram that the steady state of the system is a saddle point.\n\\item Derive the Jacobian of the system.\n\\item Show that the steady state of the system is a saddle point.\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "52a021dd2d76cb314de43cb88708694adfea6ed3", "size": 12444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework/exercises.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": "homework/exercises.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": "homework/exercises.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": 42.3265306122, "max_line_length": 442, "alphanum_fraction": 0.6949533912, "num_tokens": 4111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.6728265578190806}}
{"text": "\\subsection*{Binary boolean operators}\n\n\\subsubsection*{\\href{https://source-academy.github.io/sicp/chapters/1.1.6.html\\#p4}{Conjunction}}\n\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{\\&\\&}} \\ \\textit{expression}_2\n\\]\nstands for\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{?}} \\ \\textit{expression}_2 \\ \\textbf{\\texttt{:}}\\ \\textbf{\\texttt{false}}\n\\]\n\n\\subsubsection*{\\href{https://source-academy.github.io/sicp/chapters/1.1.6.html\\#p4}{Disjunction}}\n\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{||}} \\ \\textit{expression}_2\n\\]\nstands for\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{?}}\\ \\textbf{\\texttt{true}}\\  \\textbf{\\texttt{:}}\\ \\textit{expression}_2\n\\]\n\n\n\n", "meta": {"hexsha": "aae768779c76279842ea25420c88bb0f611e3fe8", "size": 658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/specs/source_boolean_operators.tex", "max_stars_repo_name": "jaesimin/js-slang", "max_stars_repo_head_hexsha": "153596c436998e4aa182a61be455febf77eb5510", "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_boolean_operators.tex", "max_issues_repo_name": "jaesimin/js-slang", "max_issues_repo_head_hexsha": "153596c436998e4aa182a61be455febf77eb5510", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2021-05-25T07:15:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T07:12:41.000Z", "max_forks_repo_path": "docs/specs/source_boolean_operators.tex", "max_forks_repo_name": "jaesimin/js-slang", "max_forks_repo_head_hexsha": "153596c436998e4aa182a61be455febf77eb5510", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-22T14:44:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T08:44:06.000Z", "avg_line_length": 26.32, "max_line_length": 114, "alphanum_fraction": 0.6823708207, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637361282707, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6728265464260892}}
{"text": "\\subsection{Surfaces division}\n\\label{oct_sc:surface_division}\n\\paragraph{}\nMapping points back to NURBS surfaces in 3D can be extremely time consuming as there is no known close form mathematical solution.\nEvery point takes about ten to hundreds iterations before the nearest projection point on the NURBS surface is found, depending on the size of the projection surface.\nHowever, in the problem that the proposed method is targeting, reasonably complex geometry is expected.\nAs a result, points projection back to such kind of NURBS surfaces may takes much more computational time than any others do and it may be necessary to find a more complicated but computational efficient algorithm other than the naive implementation.\n\n\\paragraph{}\nOne concept that can be utilized to improve the efficiency here is the ``divided and conquer''.\nAs the time complexity of the naive algorithm is $O(n^3)$ where $n$ is directly correlated to the order of the basis function and the number of control points used to describe the NURBS surfaces, dividing a surface into two generally will make the projection algorithm four times faster.\nConsequently, breaking the origin NURBS surfaces into multiple smaller ones could be one of the practical practices.\n\n\\paragraph{}\nSurfaces division can be performed by the help of knot insertion (Sec.~\\ref{lr_sec:nurbs_knot_ins}).\nAssuming a NURBS surface defined by two knot vectors\\\\\n$\n\\Xi_1 = [-1, -1, -1, a_1, a_2, \\dots, a_n , 1, 1, 1]\n$\\\\\nand\n$\n\\Xi_2 = [-1, -1, -1, b_1, b_2, \\dots, b_m, 1, 1, 1]\n$.\\\\\nSeveral knots will be inserted into these two vector so that all interior knots will repeated $p+1$ times and $p$ stands for the order of the NURBS basis function in that direction.\nAfter knot insertion, the same NURBS surface will now be described by two new vectors\\\\\n$\n\\Xi_1^\\prime = [-1, -1, -1, a_1, a_1, a_1, a_2, a_2, a_2, \\dots, a_n , 1, 1, 1]\n$\\\\\nand\n$\n\\Xi_2^\\prime = [-1, -1, -1, b_1, b_1, b_1, b_2, b_2, b_2, \\dots, b_m, 1, 1, 1]\n$.\\\\\nExtraction then can be conducted by taking the sub-matrix from the generated control points matrix $P^\\prime$ and weight matrix $w^\\prime$.\n\n\\paragraph{}\nFig.~\\ref{oct_fig:nurbs_division} shows a sub-division of breaking a cylinder surface into four smaller ones.\n\n\\begin{figure}[h!]\n    \\centering\n    \\begin{subfigure}[b]{0.4\\linewidth}\n        \\centering\n        \\scalebox{0.27}{\n            \\includegraphics{octree/images/NURBSParent.png}\n        }\n        \\caption{Original NURBS surface}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.4\\linewidth}\n        \\centering\n        \\scalebox{0.25}{\n            \\includegraphics{octree/images/NURBSChildren.png}\n        }\n        \\caption{Subdivided child NURBS surfaces}\n    \\end{subfigure}\n    \\caption{NURBS surface subdivision}\n    \\label{oct_fig:nurbs_division}\n\\end{figure}\n", "meta": {"hexsha": "d2bb6202cdb51127d587240493b1327540e8df42", "size": 2810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "octree/surface_division.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/surface_division.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/surface_division.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.298245614, "max_line_length": 287, "alphanum_fraction": 0.7295373665, "num_tokens": 788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6728245006602991}}
{"text": "\\section{Higher Order Derivatives}\\label{sec:MultivariateHigherOrderDerivatives}\n\nIn single variable calculus we saw that the second derivative is often\nuseful: in appropriate circumstances it measures acceleration; it can\nbe used to identify maximum and minimum points; it tells us something\nabout how sharply curved a graph is. Not surprisingly, second\nderivatives are also useful in the multi-variable case, but again not\nsurprisingly, things are a bit more complicated.\n\nIt's easy to see where some complication is going to come from: with\ntwo variables there are four possible second derivatives. To take a\n``derivative,'' we must take a partial derivative with respect to $x$\nor $y$, and there are four ways to do it: $x$ then $x$, $x$ then $y$, \n$y$ then $x$, $y$ then $y$.\n\n\\begin{example}{Second Derivatives}{SecondDerivatives}\nCompute all four second derivatives of $f(x,y)=x^2y^2$.\n\\end{example}\n\\begin{solution}\nUsing an obvious notation, we get:\n$$f_{xx}=2y^2\\qquad f_{xy}=4xy\\qquad f_{yx}=4xy\\qquad f_{yy}=2x^2.$$\n\\end{solution}\n\nYou will have noticed that two of these are the same, the ``mixed\npartials'' computed by taking partial derivatives with respect to both\nvariables in the two possible orders. This is not an accident---as\nlong as the function is reasonably nice, this will always be true.\\index{mixed partials}\n\n\\begin{theorem}{Clairaut's Theorem}{clairaut}\nIf the mixed partial derivatives are\ncontinuous, they are equal.\\index{Clairaut's theorem}\n\\end{theorem}\n\n\\begin{example}{Mixed Partials}{MixedPartials}\nCompute the mixed partials of $\\ds f=xy/(x^2+y^2)$.\n\\end{example}\n\\begin{solution}\nThe mixed partial $f_{xy}$ is found by first taking the partial derivative with respect to $x$:\n$$\nf_x={y^3-x^2y\\over(x^2+y^2)^2},\n$$\nthen with respect to $y$:\n$$\nf_{xy}=-{x^4-6x^2y^2+y^4\\over (x^2+y^2)^3}.\n$$\nWe leave $f_{yx}$ as an exercise.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:MultivariateHigherOrderDerivatives}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nLet $\\ds f=xy/(x^2+y^2)$; compute $f_{xx}$, $f_{yx}$, and $f_{yy}$.\n\\begin{sol}\n$f_{xx}=(2x^3y-6xy^3)/(x^2+y^2)^3$,\n$f_{yy}=(2xy^3-6x^3y)/(x^2+y^2)^3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$x^3y^2+y^5$.\n\\begin{sol}\n$f_x=3x^2y^2$, $f_y=2x^3y+5y^4$, \n$f_{xx}=6xy^2$, $f_{yy}=2x^3+20y^3$, $f_{xy}=6x^2y$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$4x^3+xy^2+10$.\n\\begin{sol}\n$f_x=12x^2+y^2$, $f_y=2xy$, \\hfill\\break \n$f_{xx}=24x$, $f_{yy}=2x$, $f_{xy}=2y$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$x\\sin y$.\n\\begin{sol}\n$f_x=\\sin y$, $f_y=x\\cos y$, $f_{xx}=0$, $f_{yy}=-x\\sin y$,\n$f_{xy}=\\cos y$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$\\sin(3x)\\cos(2y)$.\n\\begin{sol}\n$\\ds f_x=3\\cos(3x)\\cos(2y)$,\\hfill\\break \n$\\ds f_y=-2\\sin(3x)\\sin(2y)$,\\hfill\\break \n$\\ds f_{xy}=-6\\cos(3x)\\sin(2y)$,\\hfill\\break \n$\\ds f_{yy}=-4\\sin(3x)\\cos(2y)$,\\hfill\\break \n$\\ds f_{xx}=-9\\sin(3x)\\cos(2y)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$e^{x+y^2}$.\n\\begin{sol}\n$\\ds f_x=e^{x+y^2}$, $\\ds f_y=2ye^{x+y^2}$,\\hfill\\break \n$\\ds f_{xx}=e^{x+y^2}$,\\hfill\\break \n$\\ds f_{yy}=4y^2e^{x+y^2}+2e^{x+y^2}$,\\hfill\\break \n$\\ds f_{xy}=2ye^{x+y^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$\\ln\\sqrt{x^3+y^4}$.\n\\begin{sol}\n$\\ds f_x={3x^2\\over2(x^3+y^4)}$, \n$\\ds f_y={2y^3\\over x^3+y^4}$,\n$\\ds f_{xx}={3x\\over x^3+y^4}-{9x^4\\over 2(x^3+y^4)^2}$, \n$\\ds f_{yy}={6y^2\\over x^3+y^4}-{8y^6\\over (x^3+y^4)^2}$,\\hfill\\break \n$\\ds f_{xy}={-6x^2y^3\\over (x^3+y^4)^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$z$ with respect to $x$ and $y$ if \n$x^2+4y^2+16z^2-64=0$.\n\\begin{sol}\n$\\ds z_x={-x\\over16z}$, \n$\\ds z_y={-y\\over4z}$,\\hfill\\break \n$\\ds z_{xx}=-{16z^2+x^2\\over16^2z^3}$,\\hfill\\break \n$\\ds z_{yy}=-{4z^2+y^2\\over16z^3}$,\\hfill\\break \n$\\ds z_{xy}={-xy\\over64z^3}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all first and second partial derivatives of\n$z$ with respect to $x$ and $y$ if \n$xy+yz+xz=1$.\n\\begin{sol}\n$\\ds z_x=-{y+z\\over x+y}$, \n$\\ds z_y=-{x+z\\over x+y}$,\\hfill\\break \n$\\ds z_{xx}=2{y+z\\over(x+y)^2}$, \n$\\ds z_{yy}=2{x+z\\over(x+y)^2}$,\\hfill\\break \n$\\ds z_{xy}={2z\\over(x+y)^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\alpha$ and $k$ be constants.  Prove that the function \n$u(x,t)=e^{-\\alpha^2k^2t}\\sin(kx)$\nis a solution to the heat equation $u_t=\\alpha^2u_{xx}$\n\\end{ex}\n\n\\begin{ex}\nLet $a$ be a constant.  Prove that $u=\\sin(x-at)+\\ln(x+at)$ is\n  a solution to the wave equation $u_{tt}=a^2u_{xx}$.\n\n%% \\exercise Let $f(x,y)$ be a continuous differentiable function.  Analyze\n%%   the level curves near a critical value if that critical value is a\n%%   max or a min.  What if the level curve is a saddle point?\n\\end{ex}\n\n\\begin{ex}\nHow many third-order derivatives does a function of 2 variables\n  have?  How many of these are distinct?\n\\end{ex}\n\n\\begin{ex}\nHow many $n$th order derivatives does a function of 2 variables\n  have?  How many of these are distinct?\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "70127c687d9d7e9095330f166da5d8ab4cf5781d", "size": 5211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-6-multivariate-higher-order-derivatives.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-6-multivariate-higher-order-derivatives.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-6-multivariate-higher-order-derivatives.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2752808989, "max_line_length": 95, "alphanum_fraction": 0.6674342737, "num_tokens": 2011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.6728244820446533}}
{"text": "%% Chapter 7 : Generation Forecasting using ARIMA\n\n\\section{Introduction to Time Series Analysis}\n\\\n\\\n\\\n\\\nTime series of data is a time ordered sequence of data-points of a particular variable. The data-points in a time series are measured/recorded/logged at successive equally spaced points in time. The time series analysis consists of methods to extract meaningful statistical and other characteristic of the data. Forecasting and Regression are two different methods employed in time series analyses;  where forecasting is concerned with developing a model which can predict future values of time series based on its previous values, and regression is concerned with developing models which give relationships between  current values of one or time series.\\\\\n\nThe application of time series has a large spectrum of areas, some of the are listed below:\n\n\\begin{itemize}\n\n\\item Statistics\n\n\\item Signal Processing and Communication Engineering\n\n\\item Econometrics and Mathematical Finance\n\n\\item Weather Forecasting and Earthquake Prediction\n\n\\end{itemize} \n\n\\section{Time Series Models}\n\\\n\\\n\\\n\\\nThere are primarily four time series forecasting models based on the conditional mean and stationarity assumption : AR, MA, ARMA and ARIMA which are discusse in the following sections.\n\n\\subsection{AR Model}\n\\\n\\\n\\\n\\\nThe AR model is Auto-Regressive Model. It models a certain time-varying univariate data series such that its outputs depend linearly on its own previous values and on a stochastic term. It is a special case of the ARMA and ARIMA models. Also, it can have a unit root (that is the series becomes stationary after taking one difference) i.e. it is not always stationary. The eq (\\ref{AR1},\\ref{AR2},\\ref{AR3},\\ref{AR4}) describe the AR Model.\n\n\\begin{equation}\n\\label{AR1}\ny_{t} = c + \\Phi_{1}y_{t-1} + ... + \\Phi_{p}y_{t-p} + \\varepsilon_{t^{'}}\n\\end{equation}\\\\\nwhere,\\\\\n$ y_{t} $ = Univariate Data Series \\\\\n$ c $ = Model Constant  \\\\ \n$ \\varepsilon_{t^{'}} $ = Unpredictable Part of the Series  \\\\ \n\n\\begin{equation}\n\\label{AR2}\nL^{i}y_{t} = y_{t-i}\n\\end{equation}\\\\\n$ L^{i} $ = Lagged Operator of Degree $ i $\n\n\n\\begin{equation}\n\\label{AR3}\n\\Phi(L) = ( 1 - \\Phi_{1}L - ... - \\Phi_{p}L^{p} )\n\\end{equation}\\\\\nwhere,\\\\\n$ \\Phi(L) $ = Lag Operator Polynomial of the AR Process\\\\\n\n\\begin{equation}\n\\label{AR4}\n\\Phi(L)y_{t} = c + \\varepsilon_{t^{'}}\n\\end{equation}\n\nThe Fig (\\ref{figc7h1}) illustrates a time series of a data variable which can be modeled as an AR process.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.1]{ARIMAImg1}\n\\caption{An Data Series with AR Process}\n\\label{figc7h1} %% to refer use, \\ref{}\n\\end{figure}\n\n\\subsection{MA Model}\n\\\n\\\n\\\n\\\nThe MA model is Moving Average Model.It models a certain time-varying univariate data series such that its outputs depend linearly on the current and previous values of the stochastic term. It is a special case of the ARMA and ARIMA models.\nThe eq (\\ref{MA1},\\ref{MA2},\\ref{MA3}) describe the MA Model.\n\n\\begin{equation}\n\\label{MA1}\ny_{t}= c + \\varepsilon_{t} + \\theta_{1}\\varepsilon_{t-1} + ... + \\theta_{q}\\varepsilon_{t-q^{'}}\n\\end{equation}\\\\\nwhere,\\\\\n$ \\varepsilon_{t}, varepsilon_{t-q} $ = Current and past errors of the series \\\\\n \n\n\\begin{equation}\n\\label{MA2}\n\\theta(L) = ( 1 + \\theta_{1}L + ... + \\theta_{p}L^{p} )\n\\end{equation}\\\\\nwhere,\\\\\n$ \\theta(L) $ = Lag Operator Polynomial of the MA Process\\\\\n\n\\begin{equation}\n\\label{MA3}\ny_{t} = \\mu + \\theta\\varepsilon_{t^{'}}\n\\end{equation}\\\\\n$ \\mu $ = It is the unconditional mean of the MA process\n\nThe Fig (\\ref{figc7h2}) illustrates a time series of a data variable which can be modeled as an MA process.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ARIMAImg2}\n\\caption{An Data Series with MA Process}\n\\label{figc7h2} %% to refer use, \\ref{}\n\\end{figure}\n\n\\subsection{ARMA Model}\n\\\n\\\n\\\n\\\nThe ARMA model is the Auto-Regressive Moving Average Model. It consists of both the AR and the MA part. It is used to model more complex univariate data series. Hence, the output of the ARMA model depends on both the previous data values, and the current and previous stochastic term. AR and MA models are its special case.\nThe eq (\\ref{ARMA1},\\ref{ARMA2}) describe the ARMA Model.\n\n\\begin{equation}\n\\label{ARMA1}\ny_{t}= c + \\Phi_{1}y_{t-1} + ... + \\Phi_{p}y_{t-p} + \\varepsilon_{t} +  \\theta_{1}\\varepsilon_{t-1} + ... + \\theta_{q}\\varepsilon_{t-q^{'}}\n\\end{equation}\\\\\n\n\n\\begin{equation}\n\\label{ARMA2}\n\\Phi(L)y_{t} = c + \\theta\\varepsilon_{t^{'}}\n\\end{equation}\\\\\n\nThe Fig (\\ref{figc7h3}) illustrates a time series of a data variable which can be modeled as an ARMA process.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ARIMAImg3}\n\\caption{An Data Series with ARMA Process}\n\\label{figc7h3} %% to refer use, \\ref{}\n\\end{figure}\n\n\\subsection{ARIMA Model}\n\\\n\\\n\\\n\\\nThe ARIMA model is the Auto-Regressive Moving Average Model. it is a generalization of the ARMA model, and it can model even non-stationary univariate data series by means of using differencing to convert non-stationary series to stationary series. It consists of both the AR and the MA part similar to the ARMA model. Hence, the output of the ARIMA model depends on both the previous data values, and the current and previous stochastic term. ARMA, AR and MA models are its special case.\nThe eq (\\ref{ARIMA1},\\ref{ARIMA2}) describe the ARMA Model.\n\n\\begin{equation}\n\\label{ARIMA1}\n\\bigtriangleup^{D}y_{t}= c + \\Phi_{1}\\bigtriangleup^{D}y_{t-1} + ... + \\Phi_{p}\\bigtriangleup^{D}y_{t-p} + \\varepsilon_{t} +  \\theta_{1}\\bigtriangleup^{D}\\varepsilon_{t-1} + ... + \\theta_{q}\\bigtriangleup^{D}\\varepsilon_{t-q^{'}}\n\\end{equation}\\\\\nwhere,\\\\\n$ \\bigtriangleup^{D} $ = It is the difference operator of degree D\n\n\\begin{equation}\n\\label{ARIMA2}\n\\Phi(L)(1-L^{D})y_{t} = c + \\theta\\varepsilon_{t^{'}}\n\\end{equation}\\\\\n\nThe Fig (\\ref{figc7h4}) illustrates a time series of a data variable which can be modeled as an ARIMA process.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{ARIMAImg4}\n\\caption{An Data Series with ARIMA Process}\n\\label{figc7h4} %% to refer use, \\ref{}\n\\end{figure}\n\n\\section{Model Identification}\n\\\n\\\n\\\n\\\nThe first step in time series forecasting is to identify which time series forecasting model described above would best describe the given data series. The concept of Stationarity, the ACF (Auto-Correlation Function), and the PACF (Partial Auto-Correlation Function) helps us in making an intelligent guess for the best model to be used to forecast the given time series data.\n\n\\subsection{Concept of Stationarity}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{figc7h5}) shows a stationary data time series, it can be seen that visually a stationary process seems to be like white noise with no certain pattern whatsoever. If a data time series is stationary the we can rule out ARIMA and focus on ARMA, AR and MA models which could best describe the series.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ARIMAImg5}\n\\caption{A Stationary Time Series}\n\\label{figc7h5} %% to refer use, \\ref{}\n\\end{figure}\n\nHowever, if the data time series is non-stationary i.e. it shows some kind of a pattern as illustrated in the Fig (\\ref{figc7h6}), then the series has to be modeled as an ARIMA process.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{ARIMAImg6}\n\\caption{Types of Non-Stationary Time Series}\n\\label{figc7h6} %% to refer use, \\ref{}\n\\end{figure}\n\nThe different components of a non-stationary time series are described as follows:\n\n\\begin{itemize}\n\n\\item \\textbf{Trend Component:} A trend exists when there is a long-term increase or decrease in the data. It does not have to be linear. Sometimes we will refer to a trend “changing direction” when it might go from an increasing trend to a decreasing trend. It is illustrated in the Fig (\\ref{figc7h6})\n\n\\item \\textbf{Seasonal Component:} A seasonal pattern exists when a series is influenced by seasonal factors (e.g., the quarter of the year, the month, or day of the week). Seasonality is always of a fixed and known period. It is illustrated in the Fig (\\ref{figc7h6})\n\n\\item \\textbf{Cyclic Component:} A cyclic pattern exists when data exhibit rises and falls that are not of fixed period. The duration of these fluctuations is usually of at least 2 years. It is illustrated in the Fig (\\ref{figc7h6})\n\n\\end{itemize}\n\nHowever, real data series may contain one or all of these  components as illustrated in the Fig (\\ref{figc7h6}) with a data series having both trend and seasonal pattern.\\\\\n\nThe Dickey-Fuller Test and the Augmented Dickey-Fuller Test are a good measure of stationarity of a time series data.\n\n\\subsection{ACF and PACF}\n\\\n\\\n\\\n\\\n\nAutocorrelation Function (ACF), also known as serial correlation, is the correlation of a signal with itself at different points in time. Informally, it is the similarity between observations as a function of the time lag between them. It is a mathematical tool for finding repeating patterns, such as the presence of a periodic signal obscured by noise, or identifying the missing fundamental frequency in a signal implied by its harmonic frequencies. .\\\\\n\nThe partial autocorrelation function (PACF) gives the partial correlation of a time series with its own lagged values, controlling for the values of the time series at all shorter lags. It contrasts with the autocorrelation function, which does not control for other lags.\\\\\n\nThe Fig (\\ref{figc7h7}) shows the ACF and PACF plots for a first order AR and a first order MA process.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{ARIMAImg7}\n\\caption{ACF and PACF Graphs for AR and MA Processes}\n\\label{figc7h7} %% to refer use, \\ref{}\n\\end{figure}\n\nBoth ACF and PACF are indispensable tools in selection of the best time series model for time series data forecasting. Some basic thumb rules for interpreting the ACF and PACF plots are given in the Table (\\ref{ARIMATab1})\n\n\\begin{table}[H]\n  \\centering\n  \\caption{Nature of ACF and PACF for Different Time Series Models}\n    \\begin{tabular}{|l|l|l|}\n    \\hline\n    \\multicolumn{1}{|c|}{\\textbf{Model}} & \\multicolumn{1}{c|}{\\textbf{ACF}} & \\multicolumn{1}{c|}{\\textbf{PACF}} \\bigstrut\\\\\n    \\hline\n    AR(p) & Tails off gradually & Cuts off after p lags \\bigstrut\\\\\n    \\hline\n    MA(q) & Cuts off after q lags & Tails off gradually \\bigstrut\\\\\n    \\hline\n    ARMA(p,q) & Tails off gradually & Tails off gradually \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{ARIMATab1}%\n\\end{table}%\n\nThe Ljung-Box Q Test is an excellent statistical tool to measure the amount of correlation present between different lags of the ACF and PACF plots. It helps us in identifying the time series models more effectively.\n\n\n\\section{Model Estimation and Fitness}\n\\\n\\\n\\\n\\\nAfter completing the model identification, usually two to three variations of the model identified are created for being more certain of our choice. In estimation of the models the co-efficients of the AR, MA, ARMA and ARIMA model (depending on the forecasters choice) equations are calculated.\\\\\n\nUsing these complete equations, model statistics are computed for each of the estimated model. The standardized residuals are of great importance in determining the best model to be selected for forecasting. For a good estimated model its standardized residuals should represent white noise i.e. there is no correlation whatsoever in the residuals. Further more the AIC (Akalike Information Criterion) and the BIC (Bayesian Information Criterion) are quantitative measure for better model estimation, the model with least AIC and BIC values is the best esitmated model.\\\\\n\nOnce the decision is made using above criteria, the best model is then used for forecasting the time series data.\\\\\n\n\n\n\n\\section{Process Flow for Forecasting using ARIMA Model}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{figc7ARIMAFlow}) shows the schematic of the process flow for the development of the ARIMA model for forecasting.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ARIMA_Flow}\n\\caption{Schematic of ARIMA Model Development for Forecasting}\n\\label{figc7ARIMAFlow} %% to refer use, \\ref{}\n\\end{figure}\n\n\\section{Results}\n\\\n\\\n\\\n\\\nThe results for generation forecasting using ARIMA have been produced for the GSEC 1MW SPVP. The data utisiled for estimating the ARIMA coefficients is the WRF weather variables generated for the same plant for the month of June 2016 (The WRF results will be discussed in Chapter 9). The forecasted weather variables form the ARIMA models have been fed as inputs to the solar energy estimation app to generate the intra-hour generation forecast.\\\\\n\n\\subsection{GSEC 1MW SPVP - Plant Information}\n\\\n\\\n\\\n\\\nThe Table (\\ref{AnnAppTab1}) gives the site and PV module information of the GSEC 1MW SPVP.\n\n\\begin{table}[H]\n  \\centering\n  \\caption{GSEC 1MW SPVP Plant Information Table}\n    \\begin{tabular}{|l|c|c|c|c|c|}\n    \\hline\n    \\multicolumn{6}{|c|}{\\textbf{GSEC 1MW SVPP}} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{6}{|c|}{\\textbf{SITE INFORMATION}} \\bigstrut\\\\\n    \\hline\n    \\textbf{LATITUDE} & \\multicolumn{5}{c|}{23.275} \\bigstrut\\\\\n    \\hline\n    \\textbf{LONGITUDE} & \\multicolumn{5}{c|}{72.682} \\bigstrut\\\\\n    \\hline\n    \\textbf{PLANT CAPACITY (MW)} & \\multicolumn{5}{c|}{1} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{6}{|c|}{\\textbf{PV MODULE INFORMATION}} \\bigstrut\\\\\n    \\hline\n    \\textbf{DESCRIPTION} & A-si & Cdte & Cigs & Multi & Mono \\bigstrut\\\\\n    \\hline\n    \\textbf{MAKE} & Du-Pont & First Solar & Q Cells & Lanco & Lanco \\bigstrut\\\\\n    \\hline\n    \\textbf{CRYSTALLINE/THIN-FILM} & Thin-Film & Thin-Film & Thin-Film & Crystalline & Crystalline \\bigstrut\\\\\n    \\hline\n    \\textbf{RATING (W)} & 107 & 85 & 95 & 235 & 250 \\bigstrut\\\\\n    \\hline\n    \\textbf{Vmpp (V)} & 74 & 46.4 & 62.1 & 29.56 & 31.15 \\bigstrut\\\\\n    \\hline\n    \\textbf{Impp (A)} & 1.44 & 1.83 & 1.53 & 7.95 & 8.034 \\bigstrut\\\\\n    \\hline\n    \\textbf{Voc (V)} & 99 & 60.5 & 78 & 37.17 & 38.04 \\bigstrut\\\\\n    \\hline\n    \\textbf{Isc (A)} & 1.81 & 1.94 & 1.68 & 8.4 & 8.712 \\bigstrut\\\\\n    \\hline\n    \\textbf{TEMP COEFF OF Voc} & -0.3 & -0.27 & -0.29 & -0.31 & -0.33 \\bigstrut\\\\\n    \\hline\n    \\textbf{TEMP COEFF OF Isc} & 0.09 & 0.04 & 0.04 & 0.06 & 0.036 \\bigstrut\\\\\n    \\hline\n    \\textbf{TEMP COEFF OF Pmp} & -0.25 & -0.25 & -0.38 & -0.43 & -0.47 \\bigstrut\\\\\n    \\hline\n    \\textbf{TOTAL MODULES} & 924 & 1170 & 1056 & 432 & 405 \\bigstrut\\\\\n    \\hline\n    \\textbf{LENGTH (mm)} & 1436 & 1200 & 1196 & 1360 & 1360 \\bigstrut\\\\\n    \\hline\n    \\textbf{BREADTH (mm)} & 1117 & 600 & 636 & 941 & 951 \\bigstrut\\\\\n    \\hline\n    \\textbf{AREA (m2)} & 1.604012 & 0.72 & 0.760656 & 1.27976 & 1.29336 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{AnnAppTab1}%\n\\end{table}%\n\n\\subsection{ARIMA Results}\n\\\n\\\n\\\n\\\nThe ARIMA weather variable forecasted outputs using ARIMA models in comparison with the original data series used are given in the Fig (\\ref{figc7ARIMAWs},\\ref{figc7ARIMAT},\\ref{figc7ARIMAIr}).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ARIMA_Ws}\n\\caption{Comparison of Wind Speed Prediction using ARIMA with Original Data Series obtained from WRF }\n\\label{figc7ARIMAWs} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ARIMA_T}\n\\caption{Comparison of Temperature Prediction using ARIMA with Original Data Series obtained from WRF }\n\\label{figc7ARIMAT} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ARIMA_Ir}\n\\caption{Comparison of Irradiance Prediction using ARIMA with Original Data Series obtained from WRF }\n\\label{figc7ARIMAIr} %% to refer use, \\ref{}\n\\end{figure}\n\nThe energy generation forecast for the GSEC plant is computed using the ARIMA forecasted weather variables using the solar energy estimation application. The forecast is generated from 10.25 (Decimal Time), $4^{th}$ June, 2016 to 10.00 (Decimal Time), $5^{th}$ June, 2016. The weather data series of WRF used are from 0.00 (Decimal Time), $1^{st}$ June, 2016 to 10.00 (Decimal Time), $4^{th}$ June, 2016.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ARIMA_En}\n\\caption{Comparison of Energy Prediction using ARIMA with Original Data Series obtained from WRF }\n\\label{figc7ARIMAEn} %% to refer use, \\ref{}\n\\end{figure}\n\n\\newpage\n\n\\subsection{Conclusion from Graphs}\n\nAll the ARIMA models used are of seasonal type with seasonality of 96 as the data series has a resolution of 15 minutes. Moreover, it has been observed that the ARIMA models with both AR and MA components forecast better. All the original data series have been differenced twice. From the Fig (\\ref{figc7ARIMAWs},\\ref{figc7ARIMAT},\\ref{figc7ARIMAIr},\\ref{figc7ARIMAEn}), we see that the ARIMA models have been able to predict the weather variables and the energy output with a good degree of accuracy.\n", "meta": {"hexsha": "d1e42b85e40582df49662a35ed11b85de5ec7b5d", "size": 16753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8_ProjectReport/2_ProjectProposal/Latex Support Files/Chapters/Ch7.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/Ch7.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/Ch7.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": 42.737244898, "max_line_length": 656, "alphanum_fraction": 0.730376649, "num_tokens": 5014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.6727544170029788}}
{"text": "\\section{Kernel k-means, Spectral Clustering and Normalized Cut}\n\\label{ch:dhillon04}\n\n\\textit{Kernel k-means, Spectral Clustering and Normalized Cut} by Inderjit S. Dhillon.\nCited by 552. \\textit{ACM SIGKDD international conference on Knowledge discovery and data mining}\n\\newline\n\n\\textbf{Main point} is that the paper \\begin{inparaenum}[\\itshape a\\upshape)]\n\\item shows weighted kernel k-means formulation is very general so spectral clustering is a special case of k-means objective-function, \n\\item found k-means algorithm that decreases the normalized cut given weight and a kernel matrix.\n\\end{inparaenum}\n\n\\subsection{Weighted Kernel k-means}\nLet us denote a weight for each point $a$ by $w(a)$, clusters by $\\pi_j$, and a partitioning of points as $\\{\\pi_j\\}_{j=1}^k$. Using using non-linear function $\\phi$, the objective function of weighted kernel k-means is defined as :\n\n\\begin{figure}[ht]\n\\begin{mdframed}\n$ D(\\{ \\pi_j \\}_{j=1}^k) = \\sum\\limits_{j=1}^k \\sum\\limits_{a \\in \\pi_j} w(a)\\| \\phi(a) - m_j \\|^2 $ (1) \\\\\nwhere $m_j = \\frac{\\sum_{b \\in \\pi_j} w(b) \\phi(b)}{ \\sum_{b \\in \\pi_j } w(b) } $\n\\end{mdframed}\n\\caption{Objective function of weight kernel k-means}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\begin{mdframed}\n$ (\\phi(a) - \\frac{\\sum_{b \\in \\pi_j} w(b)\\phi(b)}{\\sum_{b \\in \\pi_j} w(b) })^2$  (2)\n\\end{mdframed}\n\\caption{Distrance function from $\\phi(a)$ to center $m_j$}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\begin{mdframed}\nWeightedKernelKMeans( $ K, k, w, C_1, \\cdots, C_k $ ) \\\\\nInput : K: kernel matrix, k: number of clusters, w: weights for each point \\\\\nOutput : $C_1, \\cdots, C_k$ : partitioning of the points \\\\\n1. Initialize the k clusters: $C_1^{(0)}, \\cdots, C_k^{(0)}$. \\\\\n2. set = $t=0$. \\\\\n3. For each point $a$, find its new cluster index as \\\\\n$j^{*}(a) = \\operatorname*{arg\\,min}_j \\| \\phi(a) - m_j \\|^2 $ using (2) \\\\\n4. Compute the updated clusters as \\\\\n$C_j^{t+1} = \\{ a : j^{*}(a) = j \\}$ \\\\\n5. If not converged, set $t = t + 1$ and go to Step 3, otherwise stop.\n\\end{mdframed}\n\\caption{weighted kernel k-means}\n\\end{figure}\n\n\\subsection{Spectral connection}\nMinimization of the objective function in (1) is equivalent to the maximization of trace($Y^T W^{1/2} K W^{1/2} Y)$. We can obtain an optimal $Y$ by taking the top $k$ eigenvectors of $W^{1/2}K W^{1/2}$. It shows Kernel k-means and spectral clustering have a theoretical connection. \n", "meta": {"hexsha": "1892805de9def37f82a12b10edced0da3c5c3e6e", "size": 2381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/references/reference_research/dhillon04.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/dhillon04.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/dhillon04.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": 48.5918367347, "max_line_length": 283, "alphanum_fraction": 0.6858462831, "num_tokens": 801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.6727544044734594}}
{"text": "\\documentclass[11pt]{scrartcl}\n\\usepackage{atonu}\n\\usepackage{fullpage}\n\\usepackage{amsmath,amsthm, amsfonts}\n\n\n\\begin{document}\n\\title{Order, Primitive Roots and Quadratic Residue}\n\\subtitle{BdMO National Camp 2021}\n\\author{\\scshape{Atonu Roy Chowdhury} \\\\\n\\mailto{atonuroychowdhury@gmail.com}}\n\\date{\\today}\n\\maketitle\n\n\\section{Order!}\nLet's recall two of the theorems that we've seen before.\n\\begin{theorem}[Fermat's Little Theorem and Euler's Theoem]\nLet \\(p\\) be a prime number and \\(a\\) be an integer coprime with \\(p\\). Then\n\\[a^{p-1}\\equiv 1 \\amod{p}\\]\nMore generally, if \\(m\\) and \\(a\\) are positive integers with \\(\\gcd(a,m) =1\\), then\n\\[a^{\\varphi(m)} \\equiv 1 \\amod{m}\\]\n\\end{theorem}\nThat is, if you take the sequence \\(a^1, a^2, a^3, \\ldots\\) in \\(\\text{mod }m\\), then the sequence eventually reaches \\(1\\) at \\(a^{\\varphi(m)}\\), and thus it becomes periodic. But, does the sequence reach \\(1\\) before \\(\\varphi(m)\\)?\\\\\nThe answer is yes. You can easily find examples. One simple example is: taking \\(a=2\\) and \\(m=7\\). Then \\(\\varphi(m)=\\varphi(7)=6\\), but \\(2^3 \\equiv 1 \\amod{7}\\). So \\(6\\) is not the smallest \\(n\\) such that \\(2^n \\equiv 1 \\amod{7}\\). We shall call this smallest such \\(n\\) ``order''. \n\\begin{defn}[Order modulo \\(m\\)]\nLet \\(a\\) and \\(m\\) be coprime positive integers. Then the order of \\(a\\) modulo \\(m\\), denoted by \\(\\ord_m(a)\\) is defined as follows:\n\\[\\ord_m(a) := \\min \\left\\{n\\in\\NN : a^n \\equiv 1 \\amod{m}\\right\\}\\]\nThat means, if \\(\\ord_m(a) = d\\), then \\(a^d \\equiv 1 \\amod{m}\\) and for every positive integer \\(k\\) smaller than \\(d\\), we have \\(a^k \\not\\equiv 1 \\amod{m}\\).\n\\end{defn}\nNow a natural question arises: is there some formula using which we can calculate order? Sadly, the answer is no. But hey, don't get frustrated. You don't really have to check every integer from \\(1\\) to \\(\\varphi(m)\\). To reduce your hardwork, there comes our next theorem. Evan Chen named it ``Fundamental Theorem of Orders'', so I'm keeping the name.\n\\begin{theorem}[Fundamental Theorem of Orders]\n\\(a^N \\equiv 1 \\amod{m}\\) if and only if \\(\\ord_m(a) \\mid N\\). \n\\end{theorem}\n\\begin{proof}\nLet \\(\\ord_m(a)=d\\). The if direction is trivial. If \n\\[d \\mid N \\implies N = dq \\implies a^N \\equiv a^{dq} \\equiv \\left(a^d\\right)^q \\equiv 1^q \\equiv 1 \\amod{m} \\]\nFor the other direction, we just need to use the division algorithm to arrive at contradiction. Assume for the sake of contradiction that \\(d \\nmid N\\). That means, \\(N\\) leaves some non-zero remainder upon division by \\(d\\). So \\(N = dq+r\\), where \\(0<r<d\\). Now, \n\\[1 \\equiv a^N \\equiv a^{dq+r} \\equiv \\left(a^d\\right)^q a^r \\equiv 1^q a^r\\equiv a^r \\amod{m} \\implies \\boxed{a^r \\equiv 1 \\amod{m}} \\]\nBy definition of order, for every positive integer \\(k\\) smaller than \\(d\\), we have \\(a^k \\not\\equiv 1 \\amod{m}\\). Here, \\(r\\) is a positive integer smaller than \\(d\\), but \\(a^r \\equiv 1 \\amod{m}\\). Thus we arrive at a contradiction. Hence \\(d\\) must divide \\(N\\).\n\\end{proof}\nThis theorem immediately gives us a corollary.\n\\begin{corollary}\nIf \\(\\gcd(a,m) = 1\\), then \\(\\ord_m(a) \\mid \\varphi(m)\\)\n\\end{corollary}\nNow we shall see an application of the \\textit{Fundamental Theorem of Orders}.\n\\begin{lemma}\nLet \\(d= \\ord_m(a)\\). Then \\(a^x \\equiv a^y \\amod{m}\\) if and only if \\(x \\equiv y \\amod{d}\\).\n\\end{lemma}\n\\begin{proof}\nWLOG, we can assume that \\(x \\geq y\\). Order is defined only when \\(\\gcd(a,m)=1\\). Therefore, we can actually divide both sides of the modular equation by \\(a^y\\).\n\\[a^x \\equiv a^y \\amod{m} \\iff a^{x-y} \\equiv 1 \\amod{m} \\iff d \\mid x-y \\iff x \\equiv y \\amod{d}\\]\nThus, we are done.\n\\end{proof}\nAlright, time for a fun exercise.\n\\begin{exercise}\nLet \\(a\\) and \\(n\\) be coprime integers. Show that \\(n \\mid \\varphi(a^n - 1)\\)\n\\end{exercise}\n\\begin{soln}\nLet \\(N = a^n - 1\\). Obviously \\(\\gcd(a,N) = \\gcd(a, a^n - 1) = 1\\). Then by \\textit{Corollary 1.3}, \n\\[\\ord_N(a) \\mid \\varphi(N)\\]\nIf we can show that \\(\\ord_N(a) = n\\), then we are basically done. It's actually not hard at all to show. Obviously, \\(a^n \\equiv 1 \\amod N\\). Now,\n\\[0<k<n \\implies a^k - 1 < a^n - 1 \\implies N \\nmid a^k -1 \\implies a^k \\not\\equiv 1 \\amod N\\]\nTherefore, \\(\\ord_N(a) = n\\) and we are done.\n\\end{soln}\n\\pagebreak\n\n\\section{Primitive Roots}\nWe've seen a few example in the Orders section that \\(\\phi(m)\\) may not be the smallest positive integer to raise power such that it becomes \\(1\\) modulo \\(m\\). But occasionally it is the smallest such positive integer. That's when things start getting interesting.\n\\begin{defn}[Primitive Root]\nAn integer \\(g\\) is said to be a primitive root modulo \\(n\\) if \\(\\gcd(g,n) = 1\\) and \\[\\ord_n(g) = \\varphi(n)\\]\n\\end{defn}\nNotice that primitive roots might not always exist. Also, even if they do, they need not be unique. So, what's interesting about primitive roots? Well, they exist when we need them the most.\n\\begin{theorem}\nLet \\(p\\) be a prime number. Then there exists a primitive root modulo \\(p\\).\n\\end{theorem}\nThis theorem has a stronger generalization. We don't need it now.\n\\begin{proof}\nBefore jumping into the proof, we need a lemma. I'll leave the proof of the lemma as an exercise for the reader.\n\\begin{lemma}\nFor every positive integer \\(n\\),\n\\[\\sum_{d \\mid n} \\varphi(d) = n\\]\nThat is, a number is exactly equal to the sum of its divisor's \\(\\varphi\\).\n\\end{lemma}\nWe know that \\(a^{p-1} \\equiv 1 \\amod p\\), and hence \\(\\ord_p(a)\\) is a divisor of \\(p-1\\) for every \\(a\\) with \\(1\\leq a \\leq p-1\\). Let \\(d \\mid p-1\\). For every such \\(d\\), we shall consider this set\n\\[S_d = \\left\\{ a \\ : \\ 1\\leq a \\leq p-1 \\text{ and } \\ord_p(a) = d\\right\\}\\]\nNotice that, if we take union of \\(S_d\\) over all the divisors of \\(p-1\\), we shall get the whole reduced residue system of \\(p\\). Furthermore, all these \\(S_d\\)'s are disjoint. Therefore,\n\\[ \\bigcup_{d \\mid p-1} S_d = RRS(p) \\implies \\boxed{\\sum_{d \\mid p-1} |S_d| = p-1} \\]\nWe shall prove in the next class that, the number of solutions (modulo \\(p\\)) to \\(x^d \\equiv 1 \\amod{p}\\) is at most \\(d\\). The elements of the set \\(X = \\left\\{ a, a^2, a^3, \\ldots, a^d \\right\\} \\) satisfies this modular equation and there are \\(d\\) different elements in \\(X\\). Therefore, \\(S_d\\) must be a subset of this \\(X\\).\\\\\nNow we claim that, if \\(a\\in S_d\\), then \\(a^{i} \\in S_d\\) if and only if \\(\\gcd(i,d)=1\\). To prove our claim, let \\(\\gcd(i,d) = g >1\\) and \\(d = gx, i=gy\\) where \\(x\\) and \\(y\\) are coprime. \n\\[ b = a^{i} = a^{gy} \\implies b^{x} = a^{gxy} = \\left(a^d\\right)^y \\equiv 1 \\amod{p}\\]\nObviously \\(x\\) is smaller than \\(d\\) because \\(g>1\\). Thus \\(b=a^{i}\\) does not have order \\(d\\). It can be shown easily that, if \\(\\gcd(i,d) = 1\\), then \\(a^{i}\\) has order \\(d\\), in other words \\(a^{i} \\in S_d\\). \\\\\nFrom this, we can conclude that, \\(S_d = \\left\\{ a^{i} \\ : \\ \\gcd(i,d)=1 \\right\\} \\), and there are at most \\(\\varphi(d)\\) such elements. Therefore, \\(|S_d| \\leq \\varphi(d)\\). Putting all the pieces of the puzzle together,\n\\[ p-1 = \\sum_{d \\mid p-1} \\varphi(d) \\geq \\sum_{d \\mid p-1} |S_d| = p-1\\]\nTherefore, we must have \\(|S_d| = \\varphi(d)\\) for every \\(d\\). Hence, \\(S_{p-1} = \\varphi(p-1) >0\\). So such element with order \\(p-1\\) exists.\n\\end{proof}\nNot only have we showed that element with order \\(p-1\\) exists, we've also showed that there are \\(\\varphi(p-1)\\) such elements with order \\(p-1\\).\n\\begin{lemma}\nIf \\(g\\) is a primitive root modulo \\(m\\) and \\(\\varphi(m)\\) is even, then\n\\[g^{\\frac{\\varphi(m)}{2}} \\equiv -1 \\pmod{m}\\]\n\\end{lemma}\n\\begin{proof}\nWe shall prove the case of \\(m\\) being prime here. The composite case can be shown using the stronger generalization of Theorem 2.1. \\\\\nWhen \\(m\\) is prime, \\(\\varphi(m)=m-1=2n\\). \\(g\\) is a primitive root modulo \\(m\\), so definitely \\(\\gcd(g,m)=1\\). So\n\\[g^{2n} \\equiv 1 \\amod{m} \\implies m \\mid g^{2n}-1 = (g^n+1)(g^n-1) \\implies g^n \\equiv \\pm 1 \\amod{m}\\]\nIf \\(g^n \\equiv 1 \\amod{m}\\), then we get \\(\\ord_m(g) < \\varphi(m)\\). Thus we arrive at a contradiction. Therefore, \\(g^n \\equiv 1 \\amod{m}\\)\n\\end{proof}\n\\begin{lemma}\nIf \\(g\\) is a primitive root modulo \\(m\\), then the set \\(S = \\left\\{ g, g^2, g^3, \\ldots, g^{\\varphi(m)} \\right\\} \\) is a reduced residue system modulo \\(m\\).\n\\end{lemma}\n\\begin{proof}\n\\(\\gcd(g,m) = 1 \\implies \\gcd(g^{i},m) = 1\\). Therefore, every element of \\(S\\) is coprime to \\(m\\). So all we need to show is every element of \\(S\\) is distinct modulo \\(m\\). \\\\\nAssume for the sake of contradiction that there exists some \\(a,b\\) with \\(g^{a} \\equiv g^b \\amod{m}\\). WLOG, \\(a>b\\). Since \\(g\\) is coprime with \\(m\\), we can actually divide both sides by \\(g^b\\). Then we get,\n\\[g^{a-b} \\equiv 1 \\amod{m}\\]\n\\(a\\) and \\(b\\) lie between \\(1\\) and \\(\\varphi(m)\\). So their difference should be strictly smaller than \\(\\varphi(m)\\). Thus we get \\(g\\) has order smaller than \\(\\varphi(m)\\), which contradicts with the fact that \\(g\\) is a primitive root modulo \\(m\\).\n\\end{proof}\nNow we shall prove Wilson's theorem, but not the proof you usually see in textbooks. We shall prove it using primitive roots.\n\\begin{theorem}[Wilson's Theorem]\nIf \\(p\\) is a prime number, then\n\\[(p-1)! \\equiv -1 \\amod{p}\\]\n\\end{theorem}\n\\begin{proof}\n\\(p=2\\) is trivial, so we shall consider the case of \\(p\\) being odd prime.\\\\\n\\(p\\) is a prime, so it has a primitive root, namely \\(g\\). By Lemma 2.4,\n\\[\\left\\{ g, g^2, g^3, \\ldots, g^{p-1} \\right\\} \\equiv \\left\\{ 1,2,3,\\ldots, p-1 \\right\\} \\amod{p}\\]\nIf we multiply all these, we shall get,\n\\begin{equation*}\n\\begin{split}\n(p-1)! &\\equiv 1 \\cdot 2 \\cdot 3 \\cdots (p-1) \\\\\n&\\equiv g \\cdot g^2 \\cdot g^3 \\cdots g^{p-1} \\\\\n&\\equiv g^{1+2+3+\\cdots+(p-1)} \\\\\n&\\equiv g^{\\frac{(p-1)p}{2}} \\\\\n&\\equiv \\left(g^{\\frac{p-1}{2}}\\right)^p \\\\\n&\\equiv (-1)^p \\equiv -1 \\amod{p}\n\\end{split}\n\\end{equation*}\nThus, we are done.\n\\end{proof}\n\\begin{theorem}[Generalization of Theorem 2.1]\nLet \\(n\\) be a positive integer. A primitive root modulo \\(n\\) exists if and only if\n\\[n \\in \\left\\{ 2, 4, p^k, 2p^k \\right\\} \\]\nwhere \\(p\\) is an odd prime number.\n\\end{theorem}\nI'm not stating the proof here. I'm gonna added it as an exercise problem.\n\n\n\\pagebreak\n\\section{Quadratic Residue}\nThe word ``Quadratic'' suggests that it has something to do with squares, and from the word ``Residue'' you're probably guessing that we will probably work with remainders. Yes, it is what it sounds like. Basically ``Quadratic residue'' deals with the remainders of square numbers. Let's jump into definition. \n\\begin{defn}[Quadratic Residue]\nLet \\(m\\) be a positive integer. An integer \\(n\\) is called a \\textbf{quadratic residue modulo \\(m\\)} if there exists some \\(x\\) such that \\(x^2 \\equiv n \\amod m\\). \n\\end{defn}\nFor example, \\(4\\) is a quadratic residue modulo \\(5\\), because \\(7^2 \\equiv 4 \\amod 5\\). But \\(3\\) is not a quadratic residue modulo \\(5\\), because there does not exist any integer \\(x\\) such that \\(x^2 \\equiv 3 \\amod{5}\\). \n\\begin{defn}[Quadratic Residue Class]\nLet \\(m\\) be a positive integer. The Quadratic Residue Class of \\(m\\), denoted by \\(\\qr(m)\\), is defined as follows:\n\\[\\qr(m) = \\left\\{ n : n \\text{ is a quadratic reisude modulo }m \\right\\} \\]\nThere is an equivalent definition:\n\\[\\qr(m) = \\left\\{ x^2 \\text{ mod } m \\ : \\ 0 \\leq x \\leq m-1 \\right\\} \\]\n\\end{defn}\nIt's not that hard to see that \\(x^2 \\equiv (m-x)^2 \\amod m\\). As a result, the set \\(\\qr(m)\\) will have at most \\(\\frac{m}{2}+1\\) elements. Because two elements contribute to the same quadratic residue. \\\\\nNow, let's talk about a fundamental result about quadratic residue and primes.\n\\begin{proposition}\nLet \\(p\\) be an odd prime. If \\(-1\\) is a quadratic residue modulo \\(p\\), then \\(p \\equiv 1 \\amod 4\\)\n\\end{proposition}\n\\begin{proof}\nAssume for the sake of contradiction that \\(p \\equiv 3 \\amod 4\\), and \\(-1\\) is a quadratic residue modulo \\(p\\). That is, there exists some positive integer \\(x\\) such that \\(x^2 \\equiv -1 \\amod p\\). \\\\\nAs \\(p \\equiv 3 \\amod 4\\), we can express \\(p\\) as \\(4k+3\\) form. Also, \\(p \\mid x^2 + 1\\) gives us \\(\\gcd(x,p)=1\\). Therefore, by \\textit{Fermat's Little Theorem},\n\\[x^{p-1} \\equiv 1 \\amod{p} \\implies 1 \\equiv x^{4k+2} \\equiv \\left(x^2\\right)^{2k+1} \\equiv \\left(-1\\right)^{2k+1} \\equiv -1 \\amod{p} \\]\nwhich leads to a contradiction. Therefore, \\(p \\equiv 1 \\amod 4\\).\n\\end{proof}\nHowever, this proposition does not necessarily imply that \\(-1\\) is a quadratic residue for every prime of the form \\(4k+1\\). But it can be shown easily that for every prime of such form, you can find a positive integer \\(x\\) with \\(x^2 \\equiv -1 \\amod p\\).\n\\begin{lemma}\nIf \\(p\\equiv 1 \\amod 4\\) is a prime, then there exists a positive integer \\(x\\) with \\(x^2 \\equiv -1 \\amod p\\).\n\\end{lemma}\n\\begin{proof}\nWe shall prove it by constructing such \\(x\\). The construction is motivated by \\textit{Wilson's Theorem}. Wilson's theorem says that, if \\(p\\) is a prime, then \\((p-1)! \\equiv -1 \\amod{p}\\). We are given that \\(p\\) is a prime of the form \\(4k+1\\). Substituting this into Wilson's theorem, we get that\n\\[1 \\cdot 2 \\cdot 3  \\cdots (2k) \\cdot (2k+1) \\cdots (4k-1) \\cdot 4k \\equiv -1 \\amod p\\]\nOur main idea is to express the LHS as a square. How can we do it? Notice that,\n\\begin{equation*}\n\\begin{split}\n4k &\\equiv -1 \\amod{p} \\\\\n4k-1 &\\equiv -2 \\amod{p} \\\\\n4k-2 &\\equiv -3 \\amod{p} \\\\\n&\\cdots \\\\\n2k+2 &\\equiv -(2k-1) \\amod{p} \\\\\n2k+1 &\\equiv -2k \\amod{p}\n\\end{split}\n\\end{equation*}\nIf we multiply all these, we would get, \n\\[(2k+1)(2k+2)\\cdots (4k-2)(4k-1)4k \\equiv 1 \\cdot 2 \\cdot 3 \\cdots (2k-1)\\cdot 2k \\amod{p}\\]\nThe negative signs got canceled out because an even number of negative numbers are multiplied. Now, if we substitute this into Wilson's theorem, we get\n\\[\\left(1 \\cdot 2 \\cdot 3 \\cdots (2k-1)\\cdot 2k\\right)\\left(1 \\cdot 2 \\cdot 3 \\cdots (2k-1)\\cdot 2k\\right) \\equiv -1 \\amod{p} \\implies \\left((2k)!\\right)^2 \\equiv -1 \\amod{p}\\]\nThus we have successfully constructed such \\(x\\). So we are done.\n\\end{proof}\n\nI intend to discuss about quadratic residues more in the diophantine equations note. In this note, I wanna introduce about Legendre Symbol.\n\\begin{defn}[Legendre Symbol]\nThe Legendre symbol for a positive integer \\(n\\) and a prime \\(p\\) is denoted by \\(\\left(\\dfrac{n}{p}\\right) \\) and defined as:\n\\[\n\\left(\\dfrac{n}{p}\\right) = \\left\\{ \\begin{array}{ll}\n0 & \\quad \\text{if } p \\mid n \\\\\n1 & \\quad \\text{if } n \\in \\qr(p) \\\\\n-1 & \\quad \\text{if } n \\not\\in \\qr(p)\n\\end{array}\\right.\n\\]\n\\end{defn}\nThe definition is basically saying that, if \\(p \\mid n\\), then \\(\\left(\\dfrac{n}{p}\\right)\\) is \\(0\\). When \\(p\\nmid a\\), we have two cases. If \\(n\\) is a quadratic residue modulo \\(p\\), then \\(\\left(\\dfrac{n}{p}\\right)\\) is \\(1\\), otherwise it's \\(-1\\). \\\\\nNow you may ask, ``\\(0\\) is always a quadratic residue modulo \\(p\\). \\(p \\mid n\\) means \\(n \\equiv 0 \\amod{p}\\), so \\(n\\) is a quadratic residue modulo \\(p\\). Why didn't we put \\(1\\) as the value of \\(\\left(\\dfrac{n}{p}\\right)\\)? Doesn't it make more sense to have \\(1\\) for \\textbf{all} quadratic residues?'' Well, the definition is of Legendre Symbol has a greater purpose to serve other than denoting quadratic residue. That greater purpose is our next theorem.\n\\begin{theorem}[Euler's Criterion]\n\\[ \\left(\\dfrac{n}{p}\\right) = n^{\\frac{p-1}{2}} \\ \\text{ mod } p\\]\n\\end{theorem}\n\\begin{proof}\nIf \\(p\\mid n\\), then the result is trivial. So let's assume \\(p\\nmid n\\). \\\\\nIf \\(n\\) is a quadratic residue, then \\(n \\equiv x^2 \\amod p\\). By Fermat's Little Theorem,\n\\[x^{p-1} \\equiv 1 \\amod{p} \\implies \\left(\\dfrac{n}{p}\\right) = 1 \\equiv \\left(x^2\\right)^{\\frac{p-1}{2}} \\equiv n^{\\frac{p-1}{2}} \\amod{p}\\]\nNow, all we are left with is, whenever \\(n\\) is not a quadratic residue, \\(n^{\\frac{p-1}{2}} \\equiv -1 \\amod{p}\\). We shall need Wilson's theorem for this. \\\\\nTake any integer \\(x\\) with \\(1 \\leq x \\leq p-1\\). Take \\(y = nx^{-1}\\), where \\(x^{-1}\\) denotes the multiplicative inverse of \\(x\\) modulo \\(p\\)\\footnote{This basically means that \\(xx^{-1} \\equiv 1 \\amod{p}\\)}. Therefore, we have\n\\[ xy \\equiv x \\amod p\\]\nNotice that, \\(x\\) and \\(y\\) can't be equal. Because if \\(x\\) and \\(y\\) are equal, then \\(n\\) becomes a quadratic residue modulo \\(p\\). \\\\\nIf we choose a different \\(x\\), we shall get a different \\(y\\). Thus, we can divide all the integers from \\(1\\) to \\(p-1\\) in \\(\\frac{p-1}{2}\\) pairs of \\((x,y)\\). Let the pairs are \\((x_1, y_1), (x_2, y_2), \\ldots, (x_{\\frac{p-1}{2}}, y_{\\frac{p-1}{2}})\\). Using Wilson's theorem,\n\\begin{equation*}\n\\begin{split}\n-1 &\\equiv (p-1)! \\equiv 1 \\cdot 2 \\cdot 3 \\cdots (p-1) \\\\\n&\\equiv (x_1y_1)\\cdot (x_2y_2) \\cdots (x_{\\frac{p-1}{2}} y_{\\frac{p-1}{2}}) \\\\\n&\\equiv n \\cdot n \\cdots n \\\\\n&\\equiv n^{\\frac{p-1}{2}} \\amod{p}\n\\end{split}\n\\end{equation*}\nThus, we are done.\n\\end{proof}\nLegendre Symbol has some very nice properties. I'm not proving these, you should try to prove them yourself.\n\\begin{lemma}\nThe Legendre Symbol \\(\\left(\\dfrac{n}{p}\\right) \\) has the following properties:\n\\begin{enumerate}[i.]\n\\item If \\(p\\nmid ab\\), then \\(\\left(\\dfrac{ab}{p}\\right) = \\left(\\dfrac{a}{p}\\right) \\left(\\dfrac{b}{p}\\right)\\)\n\\item \\(\\left(\\dfrac{2}{p}\\right) = (-1)^{\\frac{p^2-1}{8}}\\)\\\\\n\\item If \\(p\\) and \\(q\\) are distinct odd primes, then \n\\(\\left(\\dfrac{q}{p}\\right)\\left(\\dfrac{p}{q}\\right) = (-1)^{\\frac{p-1}{2} \\frac{q-1}{2}}\\)\n\\end{enumerate}\n\\end{lemma}\nThe last one is known as ``The Law of Quadratic Reciprocity''.\n\\pagebreak\n\n\n\\section{Exercise Problems}\n\\begin{problem}\nFind all positive integers \\(n\\) such that \\(n \\mid 2^n -1\\).\n\\end{problem}\n\\begin{problem}\nFind all pairs of prime numbers \\(p,q\\) such that \\(pq \\mid (5^p-2^p)(5^q-2^q)\\).\n\\end{problem}\n\\begin{problem}\nFind all triplets of prime numbers \\(p,q,r\\) such that\n\\[p \\mid q^r+1 , \\quad q\\mid r^p +1 , \\quad r \\mid p^q+1\\]\n\\end{problem}\n\\begin{problem}\nLet \\(p\\ge2\\) be a prime number. Find all positive integer \\(k\\) such that \\(p\\) divides\n\\[1^k + 2^k + 3^k +\\cdots +(p-1)^k\\]\n\\end{problem}\n\\begin{problem}\nLet \\(g\\) be a primitive root modulo \\(n\\). Then \\(g^m\\) is also a primitive root modulo \\(n\\) if and only if \\(m\\) is relatively prime to \\(\\varphi(n)\\).\n\\end{problem}\n\\begin{problem}\nLet \\(n\\) be an odd positive integer. Show that there exists a primitive root modulo \\(n\\) if and only if there exists a primitive root modulo \\(2n\\)\n\\end{problem}\n\\begin{problem}\nLet \\(p\\) be an odd prime and \\(g\\) be a primitive root modulo \\(p\\). Then either \\(g\\) or \\(g+p\\) is a primitive root modulo \\(p^k\\) for every \\(k\\ge 1\\).\n\\end{problem}\n\\begin{problem}\nIf any exists, there are exactly \\(\\varphi(\\varphi(n))\\) primitive roots modulo \\(n\\).\n\\end{problem}\n\\begin{problem}\nFor each non-negative integer \\(m\\), let \\(n_{m}=101 m-100 \\cdot 2^{m} \\). Let \\(a, b, c, d\\) be integers with \\(0 \\leq a, b, c, d \\leq 99\\) such that \\[n_{a}+n_{b} \\equiv n_{c}+n_{d} \\amod{10100}\\]\n\\end{problem}\n\\begin{problem}\nFind all pairs of positive integers \\((a, b)\\) such that \\(a b(a+b)\\) is not divisible by 7 , but \\((a+b)^{7}-a^{7}-b^{7}\\) is divisible by \\(7^{7}\\).\n\\end{problem}\n\\begin{problem}\nFind all pairs of positive integers \\(x,y\\) such that \\(4xy-x-y\\) is a perfect square.\n\\end{problem}\n\\begin{problem}\n\\(a,b\\) are coprime positive integers and \\(p\\) is an odd prime number. If \\(p \\mid a^2 + b^2\\), show that \\(p\\equiv 1 \\amod{4}\\)\n\\end{problem}\n\\begin{problem}\nFind all triplets of positive integers \\(a,b,c\\) such that \\(a^2+1=b(2^c-1)\\)\n\\end{problem}\n\\begin{problem}\nProve Lemma 3.4\n\\end{problem}\n\\begin{problem}\nProve Theorem 2.6\n\\end{problem}\n\n\\end{document}\n", "meta": {"hexsha": "676b39737f46bb44e55d4188d59143cb6bcfb217", "size": 19424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2021/ord_primroot.tex", "max_stars_repo_name": "atonurc/matholy_resources", "max_stars_repo_head_hexsha": "cc2e027c400988451c032fd6b79d5388cc1cf927", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-30T15:03:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T15:03:42.000Z", "max_issues_repo_path": "2021/ord_primroot.tex", "max_issues_repo_name": "atonurc/matholy_resources", "max_issues_repo_head_hexsha": "cc2e027c400988451c032fd6b79d5388cc1cf927", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2021/ord_primroot.tex", "max_forks_repo_name": "atonurc/matholy_resources", "max_forks_repo_head_hexsha": "cc2e027c400988451c032fd6b79d5388cc1cf927", "max_forks_repo_licenses": ["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.0680272109, "max_line_length": 464, "alphanum_fraction": 0.6487335255, "num_tokens": 6862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.6727544042268955}}
{"text": "\\section{\\module{math} ---\n         Mathematical functions}\n\n\\declaremodule{builtin}{math}\n\\modulesynopsis{Mathematical functions (\\function{sin()} etc.).}\n\nThis module is always available.  It provides access to the\nmathematical functions defined by the C standard.\n\nThese functions cannot be used with complex numbers; use the functions\nof the same name from the \\refmodule{cmath} module if you require\nsupport for complex numbers.  The distinction between functions which\nsupport complex numbers and those which don't is made since most users\ndo not want to learn quite as much mathematics as required to\nunderstand complex numbers.  Receiving an exception instead of a\ncomplex result allows earlier detection of the unexpected complex\nnumber used as a parameter, so that the programmer can determine how\nand why it was generated in the first place.\n\nThe following functions provided by this module:\n\n\\begin{funcdesc}{acos}{x}\nReturn the 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}{atan}{x}\nReturn the arc tangent of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{atan2}{y, x}\nReturn \\code{atan(\\var{y} / \\var{x})}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{ceil}{x}\nReturn the ceiling of \\var{x} as a real.\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 \\code{e**\\var{x}}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{fabs}{x}\nReturn the absolute value of the real \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{floor}{x}\nReturn the floor of \\var{x} as a real.\n\\end{funcdesc}\n\n\\begin{funcdesc}{fmod}{x, y}\nReturn \\code{fmod(\\var{x}, \\var{y})}, as defined by the platform C library.\nNote that the Python expression \\code{\\var{x} \\%\\ \\var{y}} may not return\nthe same result.\n\\end{funcdesc}\n\n\\begin{funcdesc}{frexp}{x}\n% Blessed by Tim.\nReturn the mantissa and exponent of \\var{x} as the pair\n\\code{(\\var{m}, \\var{e})}.  \\var{m} is a float and \\var{e} is an\ninteger such that \\code{\\var{x} == \\var{m} * 2**\\var{e}}.\nIf \\var{x} is zero, returns \\code{(0.0, 0)}, otherwise\n\\code{0.5 <= abs(\\var{m}) < 1}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{hypot}{x, y}\nReturn the Euclidean distance, \\code{sqrt(\\var{x}*\\var{x} + \\var{y}*\\var{y})}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{ldexp}{x, i}\nReturn \\code{\\var{x} * (2**\\var{i})}.\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}{modf}{x}\nReturn the fractional and integer parts of \\var{x}.  Both results\ncarry the sign of \\var{x}.  The integer part is returned as a real.\n\\end{funcdesc}\n\n\\begin{funcdesc}{pow}{x, y}\nReturn \\code{\\var{x}**\\var{y}}.\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\nNote that \\function{frexp()} and \\function{modf()} have a different\ncall/return pattern than their C equivalents: they take a single\nargument and return a pair of values, rather than returning their\nsecond return value through an `output parameter' (there is no such\nthing in Python).\n\nThe module also defines two mathematical constants:\n\n\\begin{datadesc}{pi}\nThe mathematical constant \\emph{pi}.\n\\end{datadesc}\n\n\\begin{datadesc}{e}\nThe mathematical constant \\emph{e}.\n\\end{datadesc}\n\n\\begin{seealso}\n  \\seemodule{cmath}{Complex number versions of many of these functions.}\n\\end{seealso}\n", "meta": {"hexsha": "6edf502629153ac6b6969d8f601fa46cdd0efbc4", "size": 3828, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Doc/lib/libmath.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/libmath.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/libmath.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": 27.1489361702, "max_line_length": 78, "alphanum_fraction": 0.7215256008, "num_tokens": 1158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.6727544038815788}}
{"text": "\\chapter{Trigonometry}\n\nIn the first half of this chapter the three trigonometric functions (sine, cosine and tangent) will be viewed as functions of angles. The second half of the chapter will approach trigonometry as functions of real numbers.\n\n%---------------------------------------------------\n% the unit circle and radians\n%---------------------------------------------------\n\\section{The Unit Circle}\nThe convention for measuring angles can be seen in the diagram below, beginning from the positive $x$-axis and rotating a point from $(1,0)$ counter-clockwise through $(x,y)$. This traces out an angle, $\\theta$. The relationship between the angle and the arc length defines a radian. When the arc length equals the radius, the angle $\\theta=1$ radian. The convention is that the positive direction for measuring angles is anticlockwise and the negative direction for measuring angles is clockwise. This setup also defines a right-angled triangle with hypotenuse $r$. As the radius rotates, all the different right-triangles are drawn. See the \\href{https://www.desmos.com/calculator/4t6zc5eucd}{link} for the animated version.\n\n\\begin{figure}[h]\n\t\\begin{center}\n\t\t\\includegraphics[width=12cm]{unitCircle}\n\t\t\\caption{The unit circle has a radius of 1. When the arc length from $(1,0)$ to $(x,y)$ is equal to the radius, the angle $\\theta$ is 1 radian. There are $2\\pi$ radians in one complete rotation. Click \\href{https://www.desmos.com/calculator/4t6zc5eucd}{here} for an animated version in Desmos.}\n\t\t\\label{fig:unitCircle}\n\t\\end{center}\n\\end{figure}\n\n\\subsection*{Relationship between Degrees and Radians}\nThe abbreviation for radians is \\textit{rad}. One complete revolution is \\ang{360} which is equivalent to $2 \\pi $ radians. It will help to remember one of these conversion factors:\n\\begin{tcolorbox}\\[1\\text{ rev }=2\\pi \\text{ radians} =  \\ang{360} \\qquad\\text{ or }\\qquad\\pi \\text{ radians} =  \\ang{180}\\]\n\\end{tcolorbox}\n\n\\example\\medskip\\\\\n(a) Convert \\ang{36} to radians\\hspace{0.7cm} \n(b) Convert $\\displaystyle\\frac{\\pi }{3}$ $\\mbox{rad}$ to degrees \\hspace{0.7cm} \n(c) Convert $1$ $\\mbox{rad}$ to degrees \\medskip\\\\\n\n\\solution Begin with the conversion factor and then modify as necessary.\n\\begin{tasks}[before-skip = {0ex} , after-skip={-5ex}](3)\n\\task \\begin{align*}\\ang{180}  &  =  \\pi \\text{ rad} \\\\\n\\ang{1}  &  =  \\frac{\\pi }{180}\\text{ rad} \\\\\n\\ang{1} \\times 36 &  =  \\frac{\\pi }{180} \\times 36 =\\frac{\\pi }{5}\\text{ rad}\\end{align*}\n\\task\n\\begin{align*}\\pi  \\text{ rad} &  =  \\ang{180}  \\\\\n\\frac{\\pi }{3} \\text{ rad} &  = \\frac{\\ang{180} }{3} =\\ang{60} \\end{align*}\n\\task\n\\begin{align*}\\pi  \\text{ rad} &  =  \\ang{180} \\\\\n1 \\text{ rad} &  =  \\frac{\\ang{180} }{\\pi } \\\\\n &  \\approx   \\ang{57.3} \\end{align*}\n\\end{tasks}\nNote the similarity between the answers to (b) and (c). This is because $\\frac{\\pi }{3} =1.0472$ so you would expect the values in degrees to be similar. Always include units with your angle whether they be degrees, radians, or even \\textit{gradians}. There are 400 gradians in a circle. This unit is not often used, however, your calculator supports all three.\\\\\n\\begin{figure}[h]\n\\begin{center}\\includegraphics[width=6cm]{calculator1}\\hspace{1cm}\\includegraphics[width=6.8cm]{calculator2}\\end{center}\n\\caption{Your calculator can switch between degrees, radians, and gradians. On the right is a `D' indicating degree mode.}\n\\end{figure}\n\n\\subsection*{Arc Length}\nLet $\\theta $ be the angle subtended at the centre for the ends of an arc of any circle then the fraction of the circumference of the circle is $\\frac{\\theta }{2 \\pi }$ if $\\theta $ is measured in radians and $\\frac{\\theta }{\\ang{360}}$ if $\\theta $ is measured in degrees. The length of the circumference of any circle whose radius is $r$ is $2 \\pi  r$. If $\\theta $ is measured in radians\n\\begin{equation*}\\text{length of arc} =\\frac{\\theta }{2 \\pi } \\times 2 \\pi  r =\\theta  r\n\\end{equation*}\nAnd if $\\theta $ is measured in degrees\n\\begin{equation*}\\text{length of arc} =\\frac{\\theta }{\\ang{360}} \\times 2 \\pi  r\n\\end{equation*}\n\\example Find the length of an arc that subtends an angle of \\ang{45} at the centre of a circle whose radius is 9 cm. \n\n\\solution \\begin{tasks}(2)\n\t\\task Method 1:\\begin{eqnarray*}\\text{Length of arc} &  = & \\frac{\\theta }{360 \\mbox{{\\ensuremath{{}^\\circ}}}} \\times 2 \\pi  r \\\\\n\t&  = & \\frac{45}{360} \\times 2 \\pi  \\times 9 \\\\\n\t&  = & 2.25 \\pi \\text{}\\mbox{cm} \\\\\n\t&  \\approx  & 7.07\\text{}\\mbox{cm}\\end{eqnarray*}\nIf an exact answer is required you should\\\\ leave the answer as $2.25 \\pi $ $\\mbox{cm}$. (Or $\\frac{9 \\pi }{4}$ $\\mbox{cm}\\text{.}$) \n\n\\task Method 2: Change degrees to radians first\n\\begin{eqnarray*}180 \\mbox{{\\ensuremath{{}^\\circ}}} &  = & \\pi \\text{}\\mbox{rad} \\\\\n\t1 \\mbox{{\\ensuremath{{}^\\circ}}} &  = & \\frac{\\pi }{180} \\\\\n\t45 \\mbox{{\\ensuremath{{}^\\circ}}} &  = & \\frac{\\pi }{180} \\times 45 \\\\\n\t&  = & \\frac{\\pi }{4}\\end{eqnarray*}\nNow, the length of arc $= r \\theta = 9 \\times \\frac{\\pi }{4} =\\frac{9 \\pi }{4}\\text{}\\mbox{cm}$.\n\\end{tasks}\n%---------------------------------------------------\n% Right-Angled Triangles: trig ratios\n%---------------------------------------------------\n\\section{Right-Angled Triangles}\nA right angled triangle is a three-sided figure (`tri-gon') with one of the interior angles being \\ang{90}. The unit circle in Figure~\\ref{fig:unitCircle} defines all the possible right angled triangles by rotating the point $(x,y)$ about the origin. Measuring the side-length of triangle (`metry') is where the name trigonometry comes from. If the ratio of two of the three side lengths is known then the angle must be fixed. Similarly, if the angle is known, the ratio of the side-lengths is fixed.\n\n%---------------------------------------------------\n% Pythagorean theorem\n%---------------------------------------------------\n\\section*{Pythagoras}\\label{sec:pythagoras}\nPythagoras is one of the most well known historical figures in mathematics and philosophy, primarily for his eponymous theorem. Given a right-angled triangle, the square of the hypotenuse equals the sum of the squares of the other sides.\n\\begin{tcolorbox}[colback=white]\n\t\\begin{multicols}{2}\n\t\t\\begin{center}\n\t\t\tThe Pythagorean Theorem:\\\\\n\t\t\t\\vspace{1cm}$a^2+b^2=c^2$\n\t\t\\end{center}\n\t\t\\columnbreak\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=6cm]{trigPythagoras}\n\t\t\\end{center}\n\t\\end{multicols}\n\\end{tcolorbox}\n\nThis theorem has many proofs, and one graphical one is shown below. The squares are all the same size. Interestingly this proof does not require any math (symbols) at all!\n\nThis is a 3-4-5 triangle which is useful in building to determine if something is square: measure sides to 3 and 4 (any units), then check that the hypotenuse is 5.\n\n\\begin{figure}\n\\begin{center}\n\t\\includegraphics[width=7cm]{PythagorasProof}\n\\hspace{1cm}\n\t\\includegraphics[width=7cm]{rightTriangle}\n\\end{center}\n\\end{figure}\n\\section*{Sine, Cosine, \\& Tangent}\n\nThe longest side in a right-triangle is always the hypotenuse, with the other two sides being named with respect to the angle of interest, $\\theta$. Notice that if $\\theta$ moves to the other corner then the sides opposite and adjacent are \\textit{reversed}. These names are helpful in defining the trigonometric ratios of sine, cosine and tan.\n\nThe phrase \\textbf{SOH-CAH-TOA} is useful to remember the ratios.\n\\begin{tcolorbox}\n\\begin{equation*}\\text{S-ine }  \\theta  =\\frac{\\text{O-pposite}}{\\text{H-ypotenuse}}\\text{;}\\qquad\\text{C-osine }  \\theta  =\\frac{\\text{A-djacent}}{\\text{H-ypotenuse}}\\text{;}\\qquad\\text{T-angent }  \\theta  =\\frac{\\text{O-pposite}}{\\text{A-djacent}}\n\\end{equation*}\\medskip\n\\hspace{1.7cm}S = O/H\\hspace{3.5cm}C = A/H\\hspace{3.8cm}T = O/A\n\\end{tcolorbox}\n\n%----------------------------------------------------\n\\begin{multicols}{2}\n\t\\example Find the unknown side $x$\\\\\n\t\\begin{center}\n\t\t\\includegraphics[width=8cm]{trigSide1}\n\t\\end{center}\n\n\t\\columnbreak\n\\solution Write the sine ratio and solve the equation for $x$.\\\\\n\\begin{align*}\n\\sin\\theta &=\\frac{\\text{opposite}}{\\text{hypotenuse}}\\\\\n\\sin (14) &= \\frac{x}{17}\\\\\nx&=17\\sin(14)\\\\\nx&\\approx4.11\\end{align*}\n\\end{multicols}\n\\rule{6.8cm}{0.5pt}\\\\\n\\begin{multicols}{2}\n\\example Find the unknown side $x$\\\\\n\\begin{center}\n\t\\includegraphics[width=6cm]{trigSide2}\n\\end{center}\n\t\\columnbreak\n\\solution Write the tangent ratio and solve the equation for $x$.\n\\begin{align*}\n\\tan\\theta &=\\frac{\\text{opposite}}{\\text{adjacent}}\\\\\n\\tan(48) &= \\frac{x}{15}\\\\\nx&=15\\tan(48)\\\\\nx&\\approx 16.7\\end{align*}\n\\end{multicols}\nThe calculator gives approximate values of the trigonometric ratios. You must look at your question to check whether angles are in degrees or radians and ensure the calculator is first set in the right mode. Questions where degrees are to be used will give angles marked with a $^\\circ$ symbol. \n\nWhen solving for an angle on your calculator you select the appropriate trigonometry ratio and use the \\emph{shift} button with sin, cos or tan to find $\\sin ^{ -1}$, $\\cos ^{ -1}$ or $\\tan ^{ -1}$. \n%----------------------------------------------------\n\\begin{multicols}{2}\n\t\\example Find the unknown angle $\\theta$\\\\\n\t\\begin{center}\n\t\t\\includegraphics[width=6cm]{trigAngle1}\n\t\\end{center}\n\t\n\t\\columnbreak\n\t\\solution Write the sine ratio and solve the equation for $\\theta$ by using the inverse-trig function on your calculator: $\\sin^{-1}$.\\\\\n\t\\begin{align*}\n\t\\sin\\theta &=\\frac{\\text{opposite}}{\\text{hypotenuse}}\\\\\n\t\\sin \\theta &= \\frac{8}{10}\\\\\n\t\\sin\\theta&=0.8\\\\\n\t\\theta&=\\sin^{-1}(0.8)\\\\\n\t\\theta&=\\ang{53.1}\n\t\\end{align*}\n\\end{multicols}\\vspace{-0.5cm}\n\\rule{6.8cm}{0.5pt}\\\\\n\\begin{multicols}{2}\n\t\\example Find the unknown angle $\\theta$\\\\\n\t\\begin{center}\n\t\t\\includegraphics[width=4cm]{trigAngle2}\n\t\\end{center}\n\t\\columnbreak\n\t\\solution Write the cosine ratio and solve the equation for $\\theta$ by using the inverse-trig function on your calculator: $\\cos^{-1}$.\n\t\\begin{align*}\n\t\\cos\\theta &=\\frac{\\text{adjacent}}{\\text{hypotenuse}}\\\\\n\t\\cos \\theta &= \\frac{7}{11}\\\\\n\t\\theta&=\\cos^{-1} \\left(\\frac{7}{11}\\right)\\\\\n\t\\theta&=\\ang{50.5}\n\t\\end{align*}\n\\end{multicols}\\vspace{-0.5cm}\n%\\rule{6.8cm}{0.5pt}\\\\\n%----------------------------------------------------\n\\example The height of a steep cliff is to be measured from a point on the opposite side of the river. The following diagram shows the measurements taken. Estimate the height of the cliff.\n\\begin {multicols}{2}\\includegraphics[width=8cm]{L4SZ281H}\n%\\columnbreak\\\\\n\\solution \n\\begin{align*}\\frac{d}{58.2} &  =  \\tan  \\ang{50.0}  \\\\\nd &  =  58.2 \\times \\tan  \\ang{50.0}  \\\\\n\\frac{h}{d} &  =  \\tan  \\ang{76.3}  \\\\\nh &  =  d \\times \\tan  \\ang{76.3}  \\\\\n &  =  58.2 \\times \\tan  \\ang{50.0}  \\times \\tan  \\ang{76.3}  \\\\\n &  \\approx   284.5 \\mbox{m}\\end{align*}\n\\end{multicols}\n\n%----------------------------------------------------\n\\example To estimate the height of a mountain above a level plane the angle of elevation of the top of the mountain is measured to be $\\ang{30} $. $600 \\mbox{m}$ closer to the mountain across the plane it is found that the angle of elevation is $\\ang{36} $. Estimate the height of the mountain. \\\\\n\\begin{center}\\includegraphics[width=11cm]{L4SZ281I}\\end{center}\n\\solution\n\\begin{equation*}\\frac{h}{x} =\\tan  \\ang{36} \\text{and}\\frac{h}{x +600} =\\tan  \\ang{30} \n\\end{equation*}\nWe want $h$ so we eliminate $x$ between these two equations\n\\begin{align*}x &  =  \\frac{h}{\\tan  \\ang{36} }\\text{and}x +600 =\\frac{h}{\\tan  \\ang{30} } \\\\\n\\frac{h}{\\tan  \\ang{30} } &  =  \\frac{h}{\\tan  \\ang{36} } +600 \\\\\n\\frac{h}{\\tan  \\ang{30} } -\\frac{h}{\\tan  \\ang{36} } &  =  600 \\\\\nh \\left (\\frac{1}{\\tan  \\ang{30} } -\\frac{1}{\\tan  \\ang{36} }\\right ) &  =  600 \\\\\nh \\genfrac{(}{)}{}{}{\\tan  \\ang{36}  -\\tan  \\ang{30} }{\\tan  \\ang{30}  \\tan  \\ang{36} } &  =  600 \\\\\nh &  =  600 \\times \\frac{\\tan  \\ang{30}  \\tan  \\ang{36} }{\\tan  \\ang{36}  -\\tan  \\ang{30} } \\\\\n &  \\approx   600 \\times 2.811603815 \\\\\n &  \\approx   1687 \\mbox{ m}\\end{align*}\n\n%---------------------------------------------------\n% identities\n%---------------------------------------------------\n\\subsection*{Identities}\\label{sec:identities}\nThe unit circle has equation $x^{2} +y^{2} =1$ and we define $x =\\cos  \\theta$ and $y =\\sin  \\theta$ so\n\\begin{equation*}x^{2} +y^{2} =1 \\leadsto \\left (\\cos  \\theta\\right )^{2} +\\left (\\sin  \\theta\\right )^{2} =1\n\\end{equation*}\nThis is always written\n\\begin{tcolorbox}\\[\\sin ^{2} \\theta +\\cos ^{2} \\theta =1\\]\n\\end{tcolorbox}\nThis is an \\emph{identity} which means it is true for all values of $\\theta$. There are many identities in trigonometry, we will only use the Pythagorean identity (above) and one more.\nGiven $\\sin =\\frac{\\text{opp}}{\\text{adj}}$ we can solve for $\\text{opp}=(\\sin)(\\text{hyp})$. Similarly from cosine:  $\\text{adj}=(\\cos)(\\text{hyp})$. Substituting these into the tangent relationship:\n\\begin{tcolorbox}\\[\\tan=\\frac{\\text{opp}}{\\text{adj}}=\\frac{(\\sin)(\\cancel{\\text{hyp}})}{(\\cos)(\\cancel{\\text{hyp}})}=\\frac{\\sin}{\\cos}\\]\n\\end{tcolorbox}\nThe sine and cosine law are two more unique relationships that we will cover in section~\\ref{sec:applications}.\n\n%---------------------------------------------------\n% trig functions\n%---------------------------------------------------\n\\subsection*{All Students Take Calculus}\nIn the previous section the angles were between $\\ang{0} $ and $\\ang{90} $. In this section the angles can take any value. Initially we consider angles between $\\ang{0} $ and $\\ang{360} $ and relate these to the radian measure between $0$ and $2 \\pi $. We remind you that angles are measured anticlockwise from the positive $x$-axis. \n\nIf the point $P (x ,y)$ is in the first quadrant, $\\theta $ is the angle between $OP$ and the positive $x$-axis and we complete the right triangle then we have created the following situation.  \n\n\\begin {multicols}{2}\n\\includegraphics[ width=3.774in, height=2.3454in,]{L4SZ281S}\n\nLet the hypotenuse be $r$ then\n\\begin{equation*}r =\\sqrt{x^{2} +y^{2}}\n\\end{equation*}\nTherefore\n\\begin{equation*}\\sin  \\theta  =\\frac{y}{r}\\text{, }\\cos  \\theta  =\\frac{x}{r}\\text{and }\\tan  \\theta  =\\frac{y}{x}\n\\end{equation*}\n\\end {multicols}\n\\begin {multicols}{2}\nWe now let $\\theta $ be any angle and define sine, cosine and tangent in the same way. For instance if $P (x ,y)$ is in the second quadrant: $\\sin  \\theta  =\\frac{y}{r}$ because $y$ is positive $\\sin  \\theta $ will be positive. ($r$ is always positive.) \n\n$\\cos  \\theta  =\\frac{x}{r}$ and since $x$ is negative $\\cos  \\theta $ will be negative. Tangent: $\\tan  \\theta  =\\frac{y}{x}$ and negative for the same reason.\\\\\n\\includegraphics[ width=3.9868in, height=1.8161in,]{L4SZ281T}\n\\end{multicols}\n\nThis pattern can be extended to quadrants 3 and 4. The mnemonic (\\textbf{A}ll \\textbf{S}tudents \\textbf{T}ake \\textbf{C}alculus) might help you remember which one is positive although you can always work it out if you need to. This means all are positive in the first quadrant, only sine is positive in the second quadrant, only tangent is positive in the third quadrant and only cosine is positive in the fourth quadrant.\n\nThe value of a trigonometric function consists of two parts the numerical part and the sign. you must get both parts correct. In the previous section you related the values of a terminal point to another point in the first quadrant. A point on the unit circle could be in any one of the four quadrants. \n\n\\qquad \\qquad \\qquad \\qquad\n\\begin{tabular}{cccccc}\\toprule\n\tQuadrant  & $x$-coordinate  & $y$-coordinate  & $\\cos $  & $\\sin $  & $\\tan $  \\\\\\midrule\n\tI  & $ +$  & $ +$  & $ +$  & $ +$  & $ +$  \\\\\\midrule\n\tII  & $ -$  & $ +$  & $ -$  & $ +$  & $ -$  \\\\\\midrule\n\tIII  & $ -$  & $ -$  & $ -$  & $ -$  & $ +$  \\\\\\midrule\n\tIV  & $ +$  & $ -$  & $ +$  & $ -$  & $ -$  \\\\\\bottomrule\n\\end{tabular}\n\n \n\n\\subsection*{The Area of a Triangle}\nThe fundamental formula for the area of a triangle is $\\text{Area} =\\frac{1}{2} \\times \\text{base} \\times \\text{height}$ Using the trigonometric functions the height can be replaced and the formula becomes:\n\\begin{equation*}\\text{Area} =\\frac{1}{2} \\times \\text{product of two sides} \\times \\text{sine of the included angle}\n\\end{equation*}\nThe formula is particularly easy to remember in symbolic form. Let the triangle have vertices $A$, $B$ and $C$, so the the sides opposite these angles are $a$, $b$ and $c$ respectively. Then the area can be expressed symbolically as\n\\begin{equation*}\\text{Area} =\\frac{1}{2} a b \\sin  C =\\frac{1}{2} b c \\sin  A =\\frac{1}{2} a c \\sin  B\n\\end{equation*}\n\n\\columnsep =30pt\n\\begin {multicols}{2} \n\\includegraphics[width=8cm]{L4SZ281U}\\label{fig:triangleArea}\n\n\\begin{align*}\\sin  A &  = \\frac{h}{c}\\text{ and }h =c \\sin  A \\\\\n\\text{Area} &  =  \\frac{1}{2} \\times \\text{base} \\times \\text{height} \\\\\n &  =  \\frac{1}{2} \\times b \\times c \\sin  A =\\frac{1}{2} b c \\sin  A\n \\end{align*}\n\\end {multicols}\nIt depends where you draw $h$ and which angle you choose to use as to which formula you finish up with. The key point to remember is $b$ and $c$ are two sides and $A$ is the angle between them. The triangle above shows $A$ as an acute angle (between $\\ang{0}$ and $\\ang{90} $). If the angle is obtuse (between $\\ang{90} $ and $\\ang{180} $) the formula still holds. \n\\begin{multicols}{2}\n\\includegraphics[ width=8cm]{L4SZ281V}\nThe angle is in the second quadrant and $\\sin  (180 -\\theta ) =\\sin  \\theta $, so $\\sin  (180 -\\theta ) =\\frac{h}{c}$ can be written as $\\sin  \\theta  =\\frac{h}{c}$ or $h =c \\sin  \\theta $ or $h =c \\sin  A$ where $A$ is obtuse. So the area is $\\frac{1}{2} b c \\sin  A$ \n\\end{multicols}\n\n\\example A triangle has two sides of 5 cm and 8 cm and the angle between them is $\\ang{150} $. Find its area.\\medskip\\\\\n\\solution\n\\begin{equation*}\\text{Area} =\\frac{1}{2} \\times 5 \\times 8 \\times \\sin  \\ang{150} \n\\end{equation*}\n\nIt helps to remember that $\\sin  150 =\\sin  30 =\\frac{1}{2}$\n\\begin{equation*}\\text{Area} =\\frac{1}{2} \\times 5 \\times 8 \\times \\frac{1}{2} =10 \\text{ cm}^{2}\n\\end{equation*}\n\n%---------------------------------------------------\n% TRIG FUNCTIONS & GRAPHS\n%---------------------------------------------------\n\\section{Trig Functions of Real Numbers}\nIn this next part of the chapter the three main trigonometric functions (sine, cosine and tangent) will be studied. They will be viewed as functions of real numbers rather than angles. The trigonometric functions defined in these two ways are identical and there is a simple rule connecting the domains. Why do we show you the two approaches? Trigonometry will be used to solve a variety of problems and these can be divided into two groups, dynamic problems and static problems. When dynamic problems (such as problems involving motion) are being solved real numbers will be used. When static problems (such as finding distances and angles for triangles) are being solved angles will be used. \n\n%---------------------------------------------------\n% trig graphs\n%---------------------------------------------------\n%\\section{Trigonometric Functions}\nYou should be familiar with the fundamental graphs of $y =\\sin  x$ and $y =\\cos  x$. These graphs are the basis of this section. \\Desmos can easily show you the shape of $y =\\sin  x$ and $y =\\cos  x$ so if you are asked to draw a rough sketch of these curves you should plot a few key points and draw a smooth curve between them. You will usually be given the required domain however if you are not you would choose to draw these for one complete cycle ($0 -2 \\pi $). To sketch $y =\\sin  x$ it is enough to select as key points $x =0$, $\\frac{\\pi }{2}$, $\\pi $, $\\frac{3 \\pi }{2}$, $2 \\pi $. \n\n\\begin{center}\n\\begin{tabular}{llllll}\\toprule\n\t$x$  & $0$  & $\\dfrac{\\pi }{2}$  & $\\pi $  & $\\dfrac{3 \\pi }{2}$  & $2 \\pi $ \\\\\\midrule\n\t$y =\\sin  x$  & $0$  & $1$  & $0$  & $ -1$  & $0$  \\\\\\bottomrule\n\\end{tabular}\n\\hspace{1cm}\n\\begin{tabular}[c]{llllll}\\toprule\n\t$x$  & $0$  & $\\dfrac{\\pi }{2}$  & $\\pi $  & $\\dfrac{3 \\pi }{2}$  & $2 \\pi $ \\\\\\midrule\n\t$y =\\cos  x$  & $1$  & $0$  & $ -1$  & $0$  & $1$ \\\\\\bottomrule\n\\end{tabular}\n\\end{center}\n\nYou will be aware that these curves repeat this pattern every $2 \\pi $ where $x$ extends in both the positive and negative directions. $0$ to $2\\pi $ represents one complete cycle. Mathematically we say\n\\begin{align*}\\sin  \\left (x +2 n \\pi \\right ) &  = \\sin  x\\text{\\  for any integer }n \\\\\n\t\\cos  \\left (x +2 n \\pi \\right ) &  = \\cos  x\\text{\\  for any integer }n\\end{align*}\n\nAside: instead of ``for any integer $n$\" we can write $ \\forall n \\in \\mathbb{Z}$. A function that displays this characteristic is described as \\emph{periodic} and for $y =\\sin x$ and $y =\\cos x$ the \\emph{period} is $2 \\pi $. \n\n\\subsection*{Transformations}\nThe following six transformations can be applied to any function including sine, cosine, and tangent.\n% can't get bullets to show up here...future work\n\\begin{tasks}[style=itemize](3)\n\\task Vertical shift \n\\task Horizontal shift \n\\task Vertical stretch \n\\task Horizontal stretch \n\\task Reflection in the $x$-axis \n\\task Reflection in the $y$-axis \n\\end{tasks}\n\n\\example Sketch $y =\\sin  \\left (x -\\frac{\\pi }{2}\\right ) +3$. This may be considered as a sine curve shifted $\\frac{\\pi }{2}$ units to the right. Note for periodic functions like a sine wave a horizontal shift is called a \\textit{phase shift}. and $3$ units upwards.\\\\ \n\\solution 1. Beginning with the special points for $\\sin x$, a table shows the evolution of the points. \\\\\n\\begin{tabular}{llllllc}\\cmidrule{1-6}\n\t$x$  & $0$  & $\\frac{\\pi }{2}$  & $\\pi $  & $\\frac{3 \\pi }{2}$  & $2 \\pi $ & $\\leftarrow x$-values, plot these \\\\\n\t\\cmidrule{1-6}\n\t$\\sin  x$  & $0$  & $1$  & $0$  & $ -1$  & $0$ & \\\\\n\t\\cmidrule{1-6}\n\t$\\sin  \\left (x -\\frac{\\pi }{2}\\right )$  & $ -1$  & $0$  & $1$  & $0$  & $ -1$&  \\\\\n\t\\cmidrule{1-6}\n\t$\\sin  \\left (x -\\frac{\\pi }{2}\\right ) +3\\qquad$  & $2$  & $3$  & $4$  & $3$  & $2$&$\\leftarrow y$-values, plot these  \\\\\n\t\\cmidrule{1-6}\n\\end{tabular}\n\n2. Plot the transformed values with the original special points and connect with a smooth, continuous line. \\Desmos confirms our transformation. The dashed plot shows $y=\\sin x$ as reference.\\\\\n\\begin{center}\n\\includegraphics[width=8cm]{trigShift1}\n\\end{center}\n\n\n\\example Sketch $y =\\cos  (x -\\frac{\\pi }{6})$.\\medskip\\\\\n\\solution You could use a table of values however this is $y =\\cos  x$ with a horizontal shift of $\\frac{\\pi }{6}$ to the right. Sketch the transformation on top of the graph of $y =\\cos  x $.\n\\begin{center}\n\\includegraphics[width=10cm]{L4SZ270H}\n\\end{center}\n\nIn general $y =a \\sin  x$ represents a vertical stretch of $y =\\sin  x$ by $a$. If $a$ is negative the transformation can either be described as a negative stretch or (preferably) as a \\emph{stretch}\nof $\\left \\vert a\\right \\vert $ followed by a \\emph{reflection} in the $x$-axis. Recall the reflection of $y =f \\left (x\\right )$ in the $x$-axis is $y = -f \\left (x\\right )$. The number $\\left \\vert a\\right \\vert $ is called the \\emph{amplitude} for both $y =\\sin  x$ and $y =\\cos  x$ shown below. \n\nIf $0 <a <1$ the fractional stretch causes the curve to shrink vertically. For instance the curve\n$y =\\sin  x$ has a maximum value of $1$ and a minimum value of $ -1$. the curve $y =\\frac{1}{2} \\sin  x$ has a maximum value of $\\frac{1}{2}$ and a minimum value of $ -\\frac{1}{2}$. \n\n\\begin{tasks}(2)\n\\task\\example Sketch $y =\\cos  ( -t)$ \\medskip\\\\\nNotice this reflection is on top of the original. Cosine is symmetric about the $y$-axis.\\\\\n\\includegraphics[width=7.5 cm]{trigTrans1}\\\\\n\n\\task\\example Sketch $y =\\sin(x+\\frac{\\pi}{4})$\\medskip\\\\\nThe angle is shifted to the left by 45 degrees ($\\frac{\\pi}{4}$ radians).\\\\\n\\includegraphics[width=7.5 cm]{trigTrans2}\n\n\\task\\example Sketch $y =\\cos(2x)$ \\medskip\\\\\nHere there are 2 complete cycles between 0 and $2\\pi$.\\\\\n\\includegraphics[width=7.5 cm]{trigTrans3}\n\n\\task\\example Sketch $y =2\\sin(0.5x)$ \\medskip\\\\\nTwo transformations applied together. The 2 refers to the amplitude.\\\\\n\\includegraphics[width=7.5 cm]{trigTrans4}\n\\end{tasks}\n\n\\subsection*{Tangent}\n There are other trig functions that we will not be covering here, for example the reciprocal functions are cosecant$=\\frac{1}{\\sin\\theta}$, secant$=\\frac{1}{\\cos\\theta}$, and the inverse tangent function, cotangent$=\\frac{1}{\\tan\\theta}$. By focussing on sine, cosine and tangent the majority of problems we encounter can be solved. Tangent is the odd function out of the trio of common ones.\n\nPreviously we learnt that the period for the sine and cosine functions was $2 \\pi $. Tangent is also a periodic function and it has a period of $\\pi $ (not $2 \\pi $). This means that it goes through one complete cycle every $\\pi$. Recall $\\tan  x =\\frac{\\sin  x}{\\cos  x}$. To analyse the behaviour of the tangent function it helps if you know what you are looking for. Some key values of tangent will show the pattern. \n\\begin{center}\n\\begin{tabular}{lrrrl}\\toprule\n\t$x$  & $\\qquad\\sin  x$  & $\\qquad\\cos  x$  &\\qquad\\quad& $\\tan  x$  \\\\\n\t\\midrule\n\t$ -\\frac{\\pi }{2}$  & $ -1$  & $0$  && $\\frac{ -1}{0} = -\\infty $  \\\\\n\t\\midrule\n\t$ -\\frac{\\pi }{4}$  & $ -\\frac{\\sqrt{2}}{2}$  & $\\frac{\\sqrt{2}}{2}$  && $ -\\frac{\\sqrt{2}}{2} \\div \\frac{\\sqrt{2}}{2} = -1$  \\\\\n\t\\midrule\n\t$0$  & $0$  & $1$  && $\\frac{0}{1} =0$  \\\\\n\t\\midrule\n\t$\\frac{\\pi }{4}$  & $\\frac{\\sqrt{2}}{2}$  & $\\frac{\\sqrt{2}}{2}$  && $\\frac{\\sqrt{2}}{2} \\div \\frac{\\sqrt{2}}{2} =1$  \\\\\n\t\\midrule\n\t$\\frac{\\pi }{2}$  & $1$  & $0$  && $\\frac{1}{0} =\\infty $  \\\\\n\t\\bottomrule\n\\end{tabular}\n\\end{center}\nAs $x$ takes values from $ -\\frac{\\pi }{2}$ to $\\frac{\\pi }{2}$, $\\tan(x)$ takes values from $ -\\infty $ to $\\infty $. This pattern is repeated every $\\pi $. \nA \\desmos graph can show this relationship. The dashed lines are the asymptotes.\n\n\\begin{figure}\\begin{center}\n\\includegraphics[width=12cm]{trigTan}\n\\caption{The graph of $y=\\tan x$. The asymptotes are shown with dashed lines, repeating every $\\pi$ radians.}\n\\end{center}\\end{figure}\n\nThe graph can be seen to have point symmetry. If you rotate the tangent curve through a half turn using the origin as axis the curve will lie on top of itself. This is a pictorial representation of an odd function.\n\nNote: Do not confuse $y =\\tan  x$ with $y =x^{3}$. While they may appear to be similar in shape the only similarities are that they both pass through the origin and continue towards $\\infty $ in the first quadrant and $ -\\infty $ in the third quadrant. \n\n%---------------------------------------------------\n% sine rule and cosing rule\n%---------------------------------------------------\n\\section{Applications}\\label{sec:applications}\n\\subsection*{The Sine Rule}\nThe Sine Rule is a relationship that allows you to find the sides and angles in triangles \\textit{without} a right angle. In the next section we use the Cosine Rule to find sides and angles in triangles also, so as you study these two sections you need to learn which problems require the Sine Rule and which require the Cosine Rule. Previously, we met the formula for the area of a triangle given two sides and the included angle $\\left ( \\text{area}=\\frac{1}{2} a b \\sin  C\\right )$. The Sine Rule and Cosine Rule also require specific combinations of sides and angles. Using standard side and angle labelling for a triangle $\\rightarrow$ $\\Delta A B C$ and let the sides be lowercase $a$, $b$ and $c$ where $a$ is opposite $\\angle A$ etc. \n\\begin{center}\n\\includegraphics[width=7cm]{SineRuleTriangle1}\n\\end{center}\n\n\\begin{tcolorbox}\n\tThe Sine Rule states that in any triangle\n\t\\begin{equation*}\\frac{\\sin  A}{a} =\\frac{\\sin  B}{b} =\\frac{\\sin  C}{c}\\qquad%\n\t\\text{ or, inversely as: }%\n\t\\qquad\\frac{a}{\\sin  A} =\\frac{b}{\\sin  B} =\\frac{c}{\\sin  C}\n\t\\end{equation*}\\end{tcolorbox}\nTextbooks may use the term ``The Law of Sines'' meaning the same relationship. \n\n\\subsection*{Proof of the Sine Rule}\nThe Sine Rule is easy to prove beginning with the formula for the area of a triangle, and using the diagram above as reference with the base as $c$. (Refer to the diagram on page~\\pageref{fig:triangleArea}.)\n\\begin{equation*}\\text{Area} =\\frac{1}{2}(\\text{base})(\\text{height})=\\frac{1}{2} (c)(b\\sin A)=\\dots=\\frac{1}{2}ab\\sin C=\\frac{1}{2}ac\\sin B\n\\end{equation*}\nFocussing only on the three terms on the right, multiply by 2:\n\\begin{equation*}b c \\sin  A=ab\\sin C=ac\\sin B\n\\end{equation*}\n\nAnd dividing by $a b c$\n\\begin{equation*}\\frac{\\sin A}{a}=\\frac{\\sin B}{b}=\\frac{\\sin C}{c}\n\\end{equation*}\n\\clearpage\n%\\rule{\\textwidth}{0.5pt}\\\\\n\\begin{multicols}{2}\n\\example Find side lengths $a$ and $c$ in the following triangle.\\\\\n\\includegraphics[width=8cm]{SineRuleTriangle2}\\\\\n$\\phantom{1}$\\\\\n$\\phantom{1}$\\\\\n\\solution \\medskip\\\\(1) To find $c$\n\\begin{align*}\\frac{c}{\\sin  C} &  = \\frac{b}{\\sin  B} \\\\\n\\frac{c}{\\sin  43 } &  = \\frac{5}{\\sin  35 } \\\\\nc &  = \\frac{5 \\sin  43 }{\\sin  35 } \\\\\n&  \\approx   5.95 \\mbox{cm}\\text{(2 dp)}\\end{align*} \\\\\n%\\clearpage\n(2) To find $a$ (i) $A =\\ang{180}  -(\\ang{35}  +\\ang{43} ) =\\ang{180}  -\\ang{78}  =\\ang{102}$ (ii) It is usually wise to go back to the original data (i.e. use $b$ and $B$ rather than $c$ and $C$).\n\\begin{align*}\\frac{a}{\\sin  A} &  = \\frac{b}{\\sin  B} \\\\\n\\frac{a}{\\sin  102 } &  = \\frac{5}{\\sin  35 } \\\\\na &  = \\frac{5 \\sin  102 }{\\sin  35 } \\\\\n&  \\approx   8.53 \\mbox{cm}\\text{(2 dp)}\\end{align*}\n\\end{multicols}\n\nThese two calculations illustrate the first two cases in which the Sine Rule is used. You will notice that the triangle has been completely solved in the course of this example. We started with one side and two angles and we found the other two sides and the other angle. \\\\\n\\rule{6.8cm}{0.5pt}\\\\\n\\example Given $a =\\ang{30} $, $a =8$ and $b =7$ solve the triangle (i.e. find $B$, $C$ and $c$). \\\\\n\\begin{center}\n\t\\includegraphics[width=11cm]{SineRuleTriangle3}\\\\\n\\end{center}\n\\solution\n\\begin{tasks}(3)\n\\task Find $B$\n\\begin{align*}\\frac{\\sin  B}{b} &  = \\frac{\\sin  A}{a} \\\\\n\\sin  B &  = \\frac{b \\sin  A}{a} \\\\\n&  = \\frac{7 \\sin  30 }{8} =0.4375 \\\\\nB &  = \\sin ^{ -1} 0.4375 \\approx \\ang{25.94} \\end{align*}\n\n\\task Find $C$\n\\begin{align*}C &  = \\ang{180}  -(\\ang{30}  +\\ang{25.94} ) \\\\\n&  = \\ang{124.06} \\end{align*}\n\n\\task Find $c$\n\\begin{align*}\\frac{c}{\\sin  C} &  = \\frac{a}{\\sin  A} \\\\\nc &  = \\frac{a \\sin  C}{\\sin a} \\\\\n&  = \\frac{8 \\sin  124.06 }{\\sin  30 } \\\\\n&  \\approx   13.3\\end{align*}\n\\end{tasks}\n%--------ambiguous case example---------------------------\nThe third case is not as straight forward and referred to as the ambiguous case. Given two sides and an angle there could be no triangle formed, one triangle formed or two triangles formed depending on the length of the side opposite the given angle.\n\n\\example {The Ambiguous Case:} Given $A =\\ang{30} $, $a =6$ and $b =7$ solve the triangle. \\\\\n\n\\solution In this case $b \\sin  A =3.5$ and $b =7$ so as $a$ lies between $3.5$ and $7$. This is the ambiguous case, therefore there are two solutions as the side lengths and angle can produce two different triangles.\n%\\columnsep =30pt\n\\begin {multicols}{2}\n\\includegraphics[width=8cm]{SineRuleAmb1}\\columnbreak\n\\includegraphics[width=8cm]{SineRuleAmb2}\n\\end {multicols}\n\\textbf{First solution} (Proceed as before) \n\\begin{tasks}(3)\n\t\\task Find $B$\n\\begin{align*}\\frac{\\sin  B}{b} &  = \\frac{\\sin  A}{a} \\\\\n\\sin  B &  = \\frac{b \\sin  A}{a} \\\\\n&  = \\frac{7 \\sin  30 }{6} =0.58 \\dot{3} \\\\\nB &  = \\sin ^{ -1} 0.58 \\dot{3} \\approx \\ang{35.7} \\end{align*}\n\n\\task Find $C$\\\\\nFirst recognize this angle is obtuse $>\\ang{90}$\n\\begin{align*}C &  = \\ang{180}  -(\\ang{30}  +\\ang{35.69} ) \\\\\n&  = \\ang{114.31} \\end{align*} \n\n\\task Find $c$\n\\begin{align*}\\frac{c}{\\sin  C} &  = \\frac{a}{\\sin  A} \\\\\nc &  = \\frac{a \\sin  C}{\\sin  A} \\\\\n&  = \\frac{6 \\sin  114.31 }{\\sin  30 } \\\\\n&  \\approx   10.9\\end{align*}\n\\end{tasks}\n\\textbf{Second solution} \n\\begin{tasks}(2)\n\t\\task Find the second value of $B$ \\\\\n$B =\\ang{180}  -\\ang{35.69}  =\\ang{144.31} $\n\\task Find $C$\\\\\n$C =\\ang{180} -(\\ang{30}  +\\ang{144.31} ) =\\ang{180}  -\\ang{174.31}  =\\ang{5.69} $\n\\task*[](Or if you remember the rule that the exterior angle of a triangle is the sum of the two interior opposite angles $C +\\ang{30}  =\\ang{35.69} $ so $C =\\ang{35.69}  -\\ang{30}  =\\ang{5.69} $) \n\\task[(3)] Find $c$\n\\begin{align*}\\frac{c}{\\sin  C} &  = \\frac{a}{\\sin  A} \\\\\nc &  = \\frac{a \\sin  C}{\\sin  A} \\\\\n&  = \\frac{6 \\sin  5.69 }{\\sin  30 } \\\\\n&  \\approx   1.2\\end{align*}\n\\task[]Both answers here are correct mathematically, however, depending on the situation one answer refers to a specific triangle which should be checked with a diagram.\n\\end{tasks}\n\n\\subsection*{The Cosine Rule}\nThe Cosine Rule, sometimes called `The Law of Cosines', is useful for a non-right triangle when we know all three side lengths without an angle, or two sides and the angle between them.\n\n\\begin{tcolorbox}\n\tFor any triangle side sides $a$, $b$, and $c$ and angle $A$ opposite side $a$:\\\\\n\t\\begin{center}\n\t\t$a^{2} =b^{2} +c^{2} -2 b c \\cos  A$\n\t\\end{center}\t\n\\end{tcolorbox}\nNote the similarity to the Pythagorean theorem (see page~\\pageref{sec:pythagoras}).\n\n\\subsection*{Proof of The Cosine Rule}\n\\textbf{To prove:} For any triangle $ \\Delta A B C\\text{,}$ $a^{2} =b^{2} +c^{2} -2 b c \\cos  A$ \\\\ \n\\columnsep =30pt\n\\begin {multicols}{2}\n\\setlength\\fboxrule{0in}\\setlength\\fboxsep{0.2in}\\fcolorbox[HTML]{000000}{FFFFFF}{\\includegraphics[ width=3.1021in, height=2.3549in,]{L4SZ282A}}\nBy Pythagoras' Theorem\n\\begin{align*}B C^{2} &  = C D^{2} +D B^{2} \\\\\na^{2} &  = \\left (c -b \\cos  A\\right )^{2} +\\left (b \\sin  A\\right )^{2} \\\\\n&  = c^{2} -2 b c \\cos  A +b^{2} \\cos ^{2} A +b^{2} \\sin ^{2} A \\\\\n&  = c^{2} -2 b c \\cos  A +b^{2} \\left (\\cos ^{2} A +\\sin ^{2} A\\right ) \\\\\n&  = c^{2} -2 b c \\cos  A +b^{2}\\text{as}\\cos ^{2} A +\\sin ^{2} A =1\\text{\\ }\\end{align*} \n\\end {multicols}\nThis is usually written\n\\begin{equation*}a^{2} =b^{2} +c^{2} -2 b c \\cos  A\n\\end{equation*}\n\nThe diagram has been drawn to simplify the way the proof unfolds. You will see that by placing the vertex $A$ at the origin the side $a$ is found in terms of $b$, $c$, and $A$. The proof would have been the same had $A$ and $B$ been as shown and $C$ placed in the second quadrant. (Thus producing a triangle with an obtuse angle at $A$.) This rule is symmetrical. You need to be given two sides and the included angle ($b$, $c$ and $A$) and the formula allows you to calculate $a$. Most textbooks will therefore show you three equivalent formulae:\n\\begin{align*}a^{2} &  = b^{2} +c^{2} -2 b c \\cos  A \\\\\nb^{2} &  = c^{2} +a^{2} -2 c a \\cos  B \\\\\nc^{2} &  = a^{2} +b^{2} -2 a b \\cos  C\\end{align*}\n\\rule{6.8cm}{0.5pt}\\\\\n\\example Given $a =5$, $b =6$ and $C =\\ang{130} $, find $c$.\\medskip\\\\\n\\solution\n\\begin{align*}c^{2} &  = a^{2} +b^{2} -2 a b \\cos  C \\\\\n&  = 5^{2} +6^{2} -2 \\times 5 \\times 6 \\times \\cos  130  \\\\\nc^2&  \\approx   99.567 \\\\\nc &  \\approx   \\sqrt{99.567}  \\approx   9.978\\end{align*}\n\n\\example Find the angle given three side lengths; given $a =5$, $b =6$ and $c =9$, find $A$. \\medskip\\\\\n\\solution Because $a$ is the smallest side $A$ will most certainly be an acute angle.\n\\begin{align*}\\cos  A &  = \\frac{b^{2} +c^{2} -a^{2}}{2 b c} \\\\\n&  = \\frac{6^{2} +9^{2} -5^{2}}{2 \\times 6 \\times 9} \\\\\n&  \\approx 0.852 \\\\\nA &  \\approx \\cos ^{ -1} \\left (0.852\\right ) \\\\\n&  \\approx \\ang{31.6} \n\\end{align*}\n\n%---------------------------------------------------\n% Chapter Exercises in a separate file\n%---------------------------------------------------\n\\section{Chapter Exercises}\n\\subimport{}{2TrigExercises}\n\n", "meta": {"hexsha": "c581beda6d343c785c12c8d7798594c66109d64e", "size": 35352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2Trig.tex", "max_stars_repo_name": "millecodex/ENGE401", "max_stars_repo_head_hexsha": "ecb6fddf196353bac375c2c2f585d2e02d87605f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2Trig.tex", "max_issues_repo_name": "millecodex/ENGE401", "max_issues_repo_head_hexsha": "ecb6fddf196353bac375c2c2f585d2e02d87605f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2Trig.tex", "max_forks_repo_name": "millecodex/ENGE401", "max_forks_repo_head_hexsha": "ecb6fddf196353bac375c2c2f585d2e02d87605f", "max_forks_repo_licenses": ["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.5151515152, "max_line_length": 742, "alphanum_fraction": 0.6455363204, "num_tokens": 11935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.6727544025990645}}
{"text": "\\section{Arc Length}{}{}\\label{sec:Arc Length}\n\n\nIn previous sections we used integration to answer the following questions:\n\t\\begin{enumerate}\n\t\\item\t\tGiven a region, what is its area?\n\t\\item\t\tGiven a solid, what is its volume?\n\t\\end{enumerate}\n\t\nIn this section, we address a related question: Given a curve, what is its length? This is often referred to as \\textbf{arc length}. \n\nConsider the graph of $y=\\sin x$ on $[0,\\pi]$ given in Figure \\ref{fig:arcintro} (a). How long is this curve? That is, if we were to use a piece of string to exactly match the shape of this curve, how long would the string be?\n\nAs we have done in the past, we start by approximating; later, we will refine our answer using limits to get an exact solution.\n\nThe length of straight--line segments is easy to compute using the Distance Formula. We can approximate the length of the given curve by approximating the curve with straight lines and measuring their lengths. \n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[t]{0.5\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\\begin{axis}[ %width=\\linewidth,%\n\t\ttick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\n\t\t\t\t\t%x=.37\\marginparwidth,\n\t\t\t\t\t%y=.37\\marginparwidth,\n\t\t\t\t\txtick=\\empty,% \n\t\t\t\t\textra x ticks={.79,1.57,2.36,3.14},\n\t\t\t\t\textra x tick labels={$\\frac{\\pi}4$,$\\frac{\\pi}2$,$\\frac{3\\pi}{4}$,$\\pi$},\n\t\t%\t\t\tytick={1},\n\t\t%\t\t\tyticklabels={$-0.002$,$0.002$,$0.004$},\n\t\t\t\t\t%minor y tick num=1,\n\t\t%\t\t\textra y ticks={1.8},%\n\t\t%\t\t\textra y tick labels={$y$},\n\t\t%\t\t\tminor x tick num=4,\n\t\t\t\t\tymin=-.2,ymax=1.25,%\n\t\t\t\t\txmin=-.1,xmax=3.5,%\n\t\t]\n\t\t\n\t\t\\addplot [{\\colorone},smooth,thick,domain=0:3.14] {sin(deg(x))};\n\t\t\n\t\t\\end{axis}\n\t\t\n\t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\n\t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\n\t\t\\end{tikzpicture}\n        \\label{ }\n        \\caption{} \n    \\end{subfigure}% \n    \\begin{subfigure}[t]{0.5\\textwidth}\n    \\begin{tikzpicture}\n    \\begin{axis}[ %width=\\linewidth,%\n    tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\n    \t\t\t%x=.37\\marginparwidth,\n    \t\t\t%y=.37\\marginparwidth,\n    \t\t\txtick=\\empty,% \n    \t\t\textra x ticks={.79,1.57,2.36,3.14},\n    \t\t\textra x tick labels={$\\frac{\\pi}4$,$\\frac{\\pi}2$,$\\frac{3\\pi}{4}$,$\\pi$},\n    %\t\t\tytick={1},\n    %\t\t\tyticklabels={$-0.002$,$0.002$,$0.004$},\n    \t\t\t%minor y tick num=1,\n    \t\t\textra y ticks={.71},%\n    \t\t\textra y tick labels={$\\frac{\\sqrt{2}}2$},\n    %\t\t\tminor x tick num=4,\n    \t\t\tymin=-.2,ymax=1.25,%\n    \t\t\txmin=-.1,xmax=3.5,%\n    ]\n    \n    \\addplot [{\\colorone},smooth,thick,domain=0:3.14] {sin(deg(x))};\n    \n    \\draw [{\\colortwo},thick] (axis cs:0,0) -- (axis cs:.79,.71) -- (axis cs: 1.57,1) -- (axis cs:2.36,.71) -- (axis cs: 3.14,0);\n    \n    \\filldraw (axis cs:0,0) circle (1pt) (axis cs:.79,.71) circle (1pt) (axis cs: 1.57,1) circle (1pt) (axis cs:2.36,.71) circle (1pt) (axis cs: 3.14,0)circle (1pt);\n    \n    \\end{axis}\n    \n    \\node [right] at (myplot.right of origin) {\\scriptsize $x$};\n    \\node [above] at (myplot.above origin) {\\scriptsize $y$};\n    \\end{tikzpicture}\n        \\label{ }\n        \\caption{}    \n    \\end{subfigure} \n    \\caption{Graphing $y=\\sin x$ on $[0,\\pi]$ and approximating the curve with line segments. \\label{fig:arcintro}\n\\end{figure}\n\nIn Figure \\ref{fig:arcintro} (b), the curve $y=\\sin x$ has been approximated with 4 line segments (the interval $[0,\\pi]$ has been divided into 4 equally--lengthed subintervals). It is clear that these four line segments approximate $y=\\sin x$ very well on the first and last subinterval, though not so well in the middle. Regardless, the sum of the lengths of the line segments is $3.79$, so we approximate the arc length of $y=\\sin x$ on $[0,\\pi]$ to be $3.79$. \n\n%Using 6 evenly spaced subintervals is not too much more work and gives a better approximation. The six lines are shown in Figure \\ref{fig:arcintro} (c) and provide an arc length approximation of $3.81$. \n\nIn general,  we can approximate the arc length of $y=f(x)$ on $[a,b]$ in the following manner. Let $a=x_1 < x_2 < \\ldots < x_n< x_{n+1}=b$ be a partition of $[a,b]$ into $n$ subintervals. Let $\\dx_i$ represent the length of the $i\\,^\\text{th}$ subinterval $[x_i,x_{i+1}]$.\n\n%\\mfigure{.35}{Zooming in on the $i\\,^\\text{th}$ subinterval $[x_i,x_{i+1}$] of a partition of $[a,b]$.}{fig:arcintro2}{figures/figarcintrod}\n%%\n%Figure \\ref{fig:arcintro2} zooms in on the $i\\,^\\text{th}$ subinterval where $y=f(x)$ is approximated by a straight line segment. The dashed lines show that we can view this line segment as they hypotenuse of a right triangle whose sides have length $\\dx_i$ and $\\dy_i$. Using the Pythagorean Theorem, the length of this line segment is\n%$\\ds \\sqrt{\\dx_i^2 + \\Delta y_i^2}.$ Summing over all subintervals gives an arc length approximation\n%$$L \\approx \\sum_{i=1}^n \\sqrt{\\dx_i^2 + \\Delta y_i^2}.$$\n%\n%As shown here, this is \\textit{not} a Riemann Sum. While we could conclude that taking a limit as the subinterval length goes to zero gives the exact arc length, we would not be able to compute the answer with a definite integral. We need first to do a little algebra.\n%\n%In the above expression factor out a $\\dx_i^2$ term:\n%\\begin{align*}\n%\\sum_{i=1}^n \\sqrt{\\dx_i^2 + \\Delta y_i^2} &= \\sum_{i=1}^n \\sqrt{\\dx_i^2\\left(1 + \\frac{\\Delta y_i^2}{\\dx_i^2}\\right)}.\\\\\n%\\intertext{Now pull the $\\dx_i^2$ term out of the square root:}%\\\\\n%\t\t\t&= \\sum_{i=1}^n\\sqrt{1 + \\frac{\\Delta y_i^2}{\\dx_i^2}}\\ \\dx_i.\\\\\n%\\intertext{This is nearly a Riemann Sum. Consider the $\\Delta y_i^2/\\dx_i^2$ term. The expression $\\Delta y_i/\\dx_i$ measures the ``change in $y$/change in $x$,'' that is, the ``rise over run'' of $f$ on the $i\\,^\\text{th}$ subinterval. The Mean Value Theorem of Differentiation (Theorem \\ref{thm:mvt}) states that there is a $c_i$ in the $i\\,^\\text{th}$ subinterval where $\\fp(c_i) = \\Delta y_i/\\dx_i$. Thus we can rewrite our above expression as:} \n%\t\t\t&= \\sum_{i=1}^n\\sqrt{1+\\fp(c_i)^2}\\ \\dx_i.\\\\\n%\\intertext{This \\textit{is} a Riemann Sum. As long as \\fp\\ is continuous, we can invoke Theorem \\ref{thm:riemann_sum} and conclude }%\\\\\n%\t\t\t&= \\int_a^b\\sqrt{1+\\fp(x)^2}\\ dx.\n%\\end{align*}\n%\n%\\keyidea{idea:arclength}{Arc Length}\n%{Let $f$ be differentiable on an open interval containing $[a,b]$, where $\\fp$ is also continuous on $[a,b]$. Then the arc length of $f$ from $x=a$ to $x=b$ is\n%\\index{integration!arc length}\\index{arc length}\n%$$L = \\int_a^b \\sqrt{1+\\fp(x)^2}\\ dx.$$\n%}\n%\n%As the integrand contains a square root, it is often difficult to use the formula in Key Idea \\ref{idea:arclength} to find the length exactly. When exact answers are difficult to come by, we resort to using numerical methods of approximating definite integrals. The following examples will demonstrate this.\\\\\n%\n%\\example{ex_arc1}{Finding arc length}{\n%Find the arc length of $f(x) = x^{3/2}$ from $x=0$ to $x=4$. }\n%{We begin by finding $\\fp(x)= \\frac32x^{1/2}$. Using the formula, we find the arc length $L$ as\n%\\begin{align*}\n%\tL &=\t\\int_0^4 \\sqrt{1+\\left(\\frac32x^{1/2}\\right)^2}\\ dx \\\\\n%\t\t&=\t\\int_0^4 \\sqrt{1+\\frac94x} \\ dx \\\\\n%\t\t&= \t\\int_0^4 \\left(1+\\frac94x\\right)^{1/2}\\ dx \\\\\n%\t\t&=  \\frac23\\frac49\\left(1+\\frac94x\\right)^{3/2}\\Big|_0^4 \\\\\n%\t\t&=\\frac{8}{27}\\left(10^{3/2}-1\\right) \\approx 9.07 \\text{units}.\n%\\end{align*}\n%\\mfigure{.8}{A graph of $f(x) = x^{3/2}$ from Example \\ref{ex_arc1}.}{fig:arc1}{figures/figarc1}\t\n%\tA graph of $f$ is given in Figure \\ref{fig:arc1}. \n%}\\\\\n%\n%\\example{ex_arc2}{Finding arc length}{\n%Find the arc length of $\\ds f(x) =\\frac18x^2-\\ln x$ from $x=1$ to $x=2$.}\n%{This function was chosen specifically because the resulting integral can be evaluated exactly. We begin by finding $\\fp(x) = x/4-1/x$. The arc length is \n%\\begin{align*}\n%L\t\t&=  \\int_1^2 \\sqrt{1+ \\left(\\frac x4-\\frac1x\\right)^2}\\ dx \\\\\n%\t\t&= \t\\int_1^2 \\sqrt{1 + \\frac{x^2}{16} -\\frac12 + \\frac1{x^2} } \\ dx \\\\\n%\t\t&=\t\\int_1^2 \\sqrt{\\frac{x^2}{16} +\\frac12 + \\frac1{x^2} } \\ dx \\\\\n%\t\t&=\t\\int_1^2\t\\sqrt{ \\left(\\frac x4 + \\frac1x\\right)^2}\\ dx \n%\\end{align*}\n%\\begin{align*}\n%\\phantom{L}\n%\t\t\t\t&= \\int_1^2 \\left(\\frac x4 + \\frac1x\\right) \\ dx \\\\\n%\t\t&=  \\left(\\frac{x^2}8 + \\ln x\\right)\\Bigg|_1^2\\\\\n%\t\t&=\t\\frac38+\\ln 2 \\approx 1.07 \\ \\text{units}.\n%\\end{align*}\n%\\mfigure{.8}{A graph of $f(x) =\\frac18x^2-\\ln x$ from Example \\ref{ex_arc2}.}{fig:arc2}{figures/figarc2}\t\n%A graph of $f$ is given in Figure \\ref{fig:arc2}; the portion of the curve measured in this problem is in bold.\n%}\\\\\n%\n%The previous examples found the arc length exactly through careful choice of the functions. In general, exact answers are much more difficult to come by and numerical approximations are necessary. \\\\\n%\n%\\example{ex_arc3}{Approximating arc length numerically}{\n%Find the length of the sine curve from $x=0$ to $x=\\pi$.}\n%{This is somewhat of a mathematical curiosity; in Example \\ref{ex_ftc4} we found the area under one ``hump'' of the sine curve is 2 square units; now we are measuring its arc length.\n%\n%The setup is straightforward: $f(x) = \\sin x$ and $\\fp(x) = \\cos x$. Thus \n%$$L = \\int_0^\\pi \\sqrt{1+\\cos^2x}\\ dx.$$\n%This integral \\textit{cannot} be evaluated in terms of elementary functions so we will approximate it with Simpson's Method with $n=4$. \n%\\mtable{.5}{A table of values of $y=\\sqrt{1+\\cos^2x}$ to evaluate a definite integral in Example \\ref{ex_arc3}.}{fig:arc3}{%\n%$$\\begin{array}{cc}\n%x & \\sqrt{1+\\cos^2x} \\\\ \\hline\n% 0 & \\sqrt{2} \\rule{0pt}{10pt}\\\\\n% \\pi/4 & \\sqrt{3/2} \\\\\n% \\pi/2 & 1 \\\\\n% 3 \\pi/4 & \\sqrt{3/2} \\\\\n% \\pi  & \\sqrt{2} \\\\\n%\\end{array}$$\n%}\n%Figure \\ref{fig:arc3} gives $\\sqrt{1+\\cos^2x}$ evaluated at 5 evenly spaced points in $[0,\\pi]$. Simpson's Rule then states that \n%\\begin{align*}\n%\\int_0^\\pi \\sqrt{1+\\cos^2x}\\ dx &\\approx\t\\frac{\\pi-0}{4\\cdot 3}\\left(\\sqrt{2}+4\\sqrt{3/2}+2(1)+4\\sqrt{3/2}+\\sqrt{2}\\right) \\\\\n%\t\t\t&=3.82918.\n%\\end{align*}\n%Using a computer with $n=100$ the approximation is $L\\approx 3.8202$; our approximation with $n=4$ is quite good.\n%}\\\\\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\n\n\nHere is another geometric application of the integral: Find the length\nof a portion of a curve. As usual, we need to think about how we might\napproximate the length, and turn the approximation into an integral.\n\nWe already know how to compute one simple arc length, that of a line\nsegment. If the endpoints are $\\ds P_0(x_0,y_0)$ and $\\ds P_1(x_1,y_1)$\nthen the length of the segment is the distance between the points,\n$\\ds \\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$, from the Pythagorean theorem, as\nillustrated in Figure~\\ref{fig:length of a line segment}.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 5, y from 0 to 3\n\\axis bottom /\n\\axis left /\n\\putrule from 2 1 to 4.5 1\n\\putrule from 4.5 1 to 4.5 2.5\n\\plot 2 1 4.5 2.5 /\n\\put {$(x_1,y_1)$} [bl] <3pt,3pt> at 4.5 2.5\n\\put {$(x_0,y_0)$} [tr] <-3pt,-3pt> at 2 1\n\\put {$x_1-x_0$} [t] <0pt,-3pt> at 3.25 1\n\\put {$y_1-y_0$} [l] <3pt,0pt> at 4.5 1.75\n\\put {$\\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$} [br] <-3pt,3pt> at 3.25 1.75\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:length of a line segment}\n%\\htmlfigure{Integration_applications-arc_length.html}\n\\caption{\\label{fig:length of a line segment}\nThe length of a line segment.}\n%\\endcaption\n\\endfigure\n\nNow if the graph of $f$ is ``nice'' (say, differentiable) it appears\nthat we can approximate the length of a portion of the curve with line\nsegments, and that as the number of segments increases, and their\nlengths decrease, the sum of the lengths of the line segments will\napproach the true arc length; see \nFigure~\\ref{fig:approximating arc length}.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <1.5truecm,0.8truecm>\n\\setplotarea x from 0 to 8, y from 0 to 5\n\\axis bottom /\n\\axis left /\n\\setquadratic\\plot \n1.000 1.000 1.150 1.953 1.300 2.694 1.450 3.246 1.600 3.636 \n1.750 3.884 1.900 4.012 2.050 4.041 2.200 3.990 2.350 3.874 \n2.500 3.711 2.650 3.515 2.800 3.299 2.950 3.075 3.100 2.853 \n3.250 2.644 3.400 2.454 3.550 2.290 3.700 2.157 3.850 2.060 \n4.000 2.000 4.150 1.979 4.300 1.996 4.450 2.050 4.600 2.138 \n4.750 2.255 4.900 2.396 5.050 2.554 5.200 2.721 5.350 2.886 \n5.500 3.039 5.650 3.168 5.800 3.258 5.950 3.294 6.100 3.261 \n6.250 3.140 6.400 2.912 6.550 2.556 6.700 2.051 6.850 1.374 \n7.000 0.500 /\n\\multiput {$\\bullet$} at 1 1 2.050 4.041 3.250 2.644\n4.300 1.996 5.500 3.039 6.250 3.140 7 0.5 /\n\\setlinear\\plot\n1 1 2.050 4.041 3.250 2.644\n4.300 1.996 5.500 3.039 6.250 3.140 7 0.5 /\n\\endpicture}}\n%\\endtexonly\n%\\figrdef{fig:approximating arc length}\n%\\htmlfigure{Integration_applications-arc_length_line_segments.html}\n\\caption{\\label{fig:approximating arc length}\nApproximating arc length with line segments.}\n%\\endcaption\n\\endfigure\n\nNow we need to write a formula for the sum of the lengths of the line\nsegments, in a form that we know becomes an integral in the limit.  So\nwe suppose we have divided the interval $[a,b]$ into $n$ subintervals\nas usual, each with length $\\Delta x =(b-a)/n$, and endpoints $\\ds\na=x_0$, $\\ds x_1$, $\\ds x_2$, \\dots, $\\ds x_n=b$.  The length of a\ntypical line segment, joining $\\ds (x_i,f(x_i))$ to $\\ds\n(x_{i+1},f(x_{i+1}))$, is $\\ds\\sqrt{(\\Delta x )^2\n  +(f(x_{i+1})-f(x_i))^2}$.  By the Mean Value Theorem, %(\\xrefn{thm:mvt}), \nthere is a number $\\ds t_i$ in $\\ds (x_i,x_{i+1})$\nsuch that $\\ds f'(t_i)\\Delta x=f(x_{i+1})-f(x_i)$, so the length of\nthe line segment can be written as\n$$\n  \\sqrt{(\\Delta x)^2 + (f'(t_i))^2\\Delta x^2}=\n  \\sqrt{1+(f'(t_i))^2}\\,\\Delta x.\n$$\nThen arc length is:\n$$\n  \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} \\sqrt{1+(f'(t_i))^2}\\,\\Delta x=\n  \\int_a^b \\sqrt{1+(f'(x))^2}\\,dx.\n$$\nNote that the sum looks a bit different than others we have\nencountered, because the approximation contains a $\\ds t_i$ instead of an\n$\\ds x_i$. In the past we have always used left endpoints (namely, $\\ds x_i$)\nto get a representative value of $f$ on $\\ds [x_i,x_{i+1}]$; now we are\nusing a different point, but the principle is the same.\n\nTo summarize, to compute the length of a curve on the interval\n$[a,b]$, we compute the integral\n$$\\int_a^b \\sqrt{1+(f'(x))^2}\\,dx.$$ \nUnfortunately, integrals of this form are typically difficult or\nimpossible to compute exactly, because usually none of our methods for\nfinding antiderivatives will work. In practice this means that the\nintegral will usually have to be approximated.\n\n\\begin{example}{Circumference of a Circle}{Circumference of a Circle}\\label{Circumference of a Circle} \nLet $\\ds f(x) = \\sqrt{r^2-x^2}$, the upper half circle of radius\n$r$. The length of this curve is half the circumference, namely $\\pi\nr$. Compute this with the arc length formula.\n\\end{example}\n\n\\begin{solution}\nThe derivative $f'$ is $\\ds \\ds -x/\\sqrt{r^2-x^2}$ so the integral is\n$$\n  \\int_{-r}^r \\sqrt{1+{x^2\\over r^2-x^2}}\\,dx\n  =\\int_{-r}^r \\sqrt{r^2\\over r^2-x^2}\\,dx\n  =r\\int_{-r}^r \\sqrt{1\\over r^2-x^2}\\,dx.\n$$\nUsing a trigonometric substitution, we find the antiderivative, namely\n$\\ds \\arcsin(x/r)$. Notice that the integral is improper at both\nendpoints, as the function $\\ds \\sqrt{1/(r^2-x^2)}$ is undefined when\n$x=\\pm r$. So we need to compute\n$$\n  \\lim_{D\\to-r^+}\\int_D^0  \\sqrt{1\\over r^2-x^2}\\,dx +\n  \\lim_{D\\to r^-}\\int_0^D  \\sqrt{1\\over r^2-x^2}\\,dx.\n$$\nThis is not difficult, and has value $\\pi$, so the original integral,\nwith the extra $r$ in front, has value $\\pi r$ as expected.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Arc Length}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $\\ds f(x)=x^{3/2}$ on $[0,2]$.\n\\begin{sol}\n $\\ds (22\\sqrt{22}-8)/27$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $\\ds f(x) = x^2/8-\\ln x$\non $[1,2]$.\n\\begin{sol}\n $\\ln(2)+3/8$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n\nFind the arc length of $\\ds f(x) = (1/3)(x^2 +2)^{3/2}$\non the interval $[0,a]$.\n\\begin{sol}\n $\\ds a+a^3/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $f(x)=\\ln(\\sin x)$ on the\ninterval $[\\pi/4,\\pi/3]$.\n\\begin{sol}\n $\\ds \\ln((\\sqrt2+1)/\\sqrt3)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Let $a>0$. Show that the length of $y=\\cosh x$ on\n$[0,a]$ is equal to $\\ds \\int _0 ^a \\cosh x\\,dx$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $f(x)=\\cosh x$ on $[0, \\ln 2]$.\n\\begin{sol}\n $3/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Set up the integral to find the arc length of $\\sin x$ \non the interval $[0,\\pi]$; do not evaluate the integral. If you have\naccess to appropriate software, approximate the value of the integral.\n\\begin{sol}\n $\\approx 3.82$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Set up the integral to find the arc length of $\\ds y=xe^{-x}$\non the interval $[2,3]$; do not evaluate the integral. If you have\naccess to appropriate software, approximate the value of the integral.\n\\begin{sol}\n $\\approx 1.01$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the arc length of $\\ds y=e^x$ on the interval $[0,1]$.\n(This can be done exactly; it is a bit tricky and a bit long.)\n\\begin{sol}\n $\\ds \\sqrt{1+e^2}-\\sqrt2+\n{1\\over2}\\ln\\left({\\sqrt{1+e^2}-1\\over\\sqrt{1+e^2}+1}\\right)+\n{1\\over2}\\ln(3+2\\sqrt2)$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "286dfa46f28211970f17db30956f23d0146dd9be", "size": 17395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-7-arclength.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-7-arclength.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-7-arclength.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": 41.4166666667, "max_line_length": 464, "alphanum_fraction": 0.6544984191, "num_tokens": 6443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.9241418184118163, "lm_q1q2_score": 0.6727525551111283}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n\\chapter{Higher-Ranked Polymorphism Subtyping Algorithm}\n\\label{chap:ITP}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n\nIn this chapter, we present a new algorithm for polymorphic subtyping\nwith mechanical formalizations in the Abella theorem prover.\nThere is little work on formalizing type inference algorithms before,\nespecially for higher-ranked systems,\ndue to the fact that environments and variable bindings are\ntricky to mechanize in theorem provers.\nIn order to overcome the difficulty in formalization,\nwe propose the novel algorithm by means of \\emph{worklist judgments}.\nWorklist judgments turn complicated\nglobal propagation of unification constraints into simple local substitutions.\nMoreover, we exploit several ideas in the recent inductive\nformulation of a type-inference algorithm by\n\\citet{dunfield2013complete}, which turn out to be useful\nfor mechanization in a theorem prover.\n\nBuilding on these ideas we develop a complete formalization of\npolymorphic subtyping in the Abella theorem prover. Moreover, we\n show that the algorithm is \\emph{sound}, \\emph{complete}, and \\emph{decidable} with\nrespect to the well-known declarative formulation of polymorphic subtyping by\n\\citet{odersky1996putting}.\nWhile these meta-theoretical results are not new, as far\nas we know our work is the first to mechanically formalize them.\n\n\n\\section{Overview: Polymorphic Subtyping}\n\n% We hope that\n% this work encourages other researchers to use theorem provers for formalizing\n% type-inference algorithms.\n\n\\input{Sources/ITP/sec2.tex}\n\\input{Sources/ITP/sec3.tex}\n\\input{Sources/ITP/sec4.tex}\n\n\\input{Sources/ITP/abella.tex}\n\n%Dunfield and Krishnaswami calculus tracks the (partial) solutions of existential variables\n%in the algorithmic context; they denote a delayed substitution that is\n%incrementally applied to outstanding work as it is encoutered.  \n%Instead of reifying the substitution, our algorithm keeps track of an explicit list of\n%outstanding work.\n\n\n", "meta": {"hexsha": "33cc21db8883ebdbf51aae2d5c06a2545d74ecc4", "size": 2073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Sources/ITP.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.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.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": 42.306122449, "max_line_length": 91, "alphanum_fraction": 0.7588036662, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6725385673761615}}
{"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 13: Lagrange Multipliers}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Motivation of Lagrange Multipliers}\n\nThe usage of Lagrange multipliers is to maximize/minimize the value of a \nfunction $f(x, y, z)$ where $x$, $y$, and $z$ are not independent, in other \nwords there is a constraint $g(x, y, z) = c$.\n\nReal world example: In thermodynamics, we often deal with a system with \nparameters such as temperature T, pressure P, and volume V. These parameters are \nnot independent, and they satisfy a relation $PV = nRT$.\n\nThose kinds of problems cannot be solved by only checking the critical points of \nthe function $f(x, y, z)$, because they probably don't satisfy the existing \nconstraint $g(x, y, z) = c$.\n\n\\begin{example}\n  Find the point closest to the origin on the hyperbola $xy = 3$.\n\n  We need to minimize the function $f(x, y) = \\sqrt{x^2 + y^2}$, or more \n  conveniently, the function $f(x, y) = x^2 + y^2$, with the constraint \n  $g(x, y) = xy = 3$.\n\n  From geometric perspective, we can plot the function graph of \n  $g(x, y) = xy = 3$, and the contour plot of the function \n  $f(x, y) = x^2 + y^2$. We can see that with a large constant $c_1$, the graphs \n  of $g(x, y) = 3$ and $f(x, y) = c_1$ have four intersection points; with a \n  small constant $c_2$, the two graphs have no intersection point. With the \n  correct solution $c_0$, the two graphs have exactly two intersection points.\n\\end{example}\n\n\\section{Solution with Lanrange Multipliers}\n\nOne key observation to the above example: At the minimum, the level curve of the \nfunction $f(x, y)$ is tangent to the hyperbola $xy = 3$, which is another level \ncurve of the function $g(x, y)$.\n\nThen how to find the point $(x, y)$ where the level curves of $f(x, y)$ and \n$g(x, y)$ are tangent to each other?\n\nNotice: The level curves of $f(x, y)$ and $g(x, y)$ are tangent to each other \\\\\n$\\iff$ The level curves of $f(x, y)$ and $g(x, y)$ have the same tangent line \\\\\n$\\iff$ The gradients of $f(x, y)$ and $g(x, y)$ are parallel to each other \\\\\n$\\iff$ $\\nabla f = \\lambda \\nabla g$, where $\\lambda \\neq 0$.\n\nTherefore, we can derive a system of equations from the above statement:\n\nFrom $\\nabla f = \\lambda \\nabla g$, we can derive that\n\\begin{equation*}\n  \\begin{cases}\n    f_x = \\lambda g_x \\\\\n    f_y = \\lambda g_y \\\\\n  \\end{cases}\n\\end{equation*}\nAlso we have the constraint $g(x, y) = c$.\n\nTherefore, for a optimization problem of a function with two variables, the \nderived system of equations is\n\\begin{equation*}\n  \\begin{cases}\n    f_x = \\lambda g_x \\\\\n    f_y = \\lambda g_y \\\\\n    g(x, y) = c \\\\\n  \\end{cases}\n\\end{equation*}\nIt is sufficient to solve the point $(x, y)$ as well as the factor $\\lambda$. \nThis factor $\\lambda$ is called the Lagrange multiplier.\n\n\\begin{example}\n  Find the point closest to the origin on the hyperbola $xy = 3$ (Continue'd).\n\n  \\begin{gather*}\n    f(x, y) = x^2 + y^2 \\\\\n    f_x = 2x \\\\\n    f_y = 2y \\\\\n    g(x, y) = xy \\\\\n    g_x = y \\\\\n    g_y = x \\\\\n  \\end{gather*}\n  Therefore, we can derive the following system of equations to solve the \n  minimum point of $f(x, y)$ under the constraint $g(x, y) = xy = 3$.\n  \\begin{equation*}\n    \\begin{cases}\n      2x = \\lambda y \\\\\n      2y = \\lambda x \\\\\n      xy = 3 \\\\\n    \\end{cases}\n  \\end{equation*}\n  If we focus on the first two equations, we can rewrite them as\n  \\begin{gather*}\n    \\begin{cases}\n      2x - \\lambda y = 0 \\\\\n      \\lambda x - 2y = 0 \\\\\n    \\end{cases} \\\\\n    \\begin{bmatrix}\n      2 & -\\lambda \\\\\n      \\lambda & -2 \\\\\n    \\end{bmatrix} \\cdot\n    \\begin{bmatrix}\n      x \\\\\n      y \\\\\n    \\end{bmatrix} = \n    \\begin{bmatrix}\n      0 \\\\\n      0 \\\\\n    \\end{bmatrix} \\\\\n  \\end{gather*}\n  For this linear system, we have a trivial solution $x = y = 0$, but it doesn't \n  satisfy the constraint. Based on our exploration from geometric perspective, \n  we know that there are two solutions other than $x = y = 0$ for this system of \n  equations. Hence the linear system has more than one solution, which is \n  equivalent to\n  \\begin{gather*}\n    det(A) = 0 \\\\\n    \\begin{vmatrix}\n      2 & -\\lambda \\\\\n      \\lambda & -2 \\\\\n    \\end{vmatrix} = 0 \\\\\n    \\lambda^2 - 4 = 0 \\\\\n    \\lambda = \\pm 2 \\\\\n  \\end{gather*}\n  When $\\lambda = 2$,\n  \\begin{gather*}\n    \\begin{cases}\n      2x - 2y = 0 \\\\\n      2x - 2y = 0 \\\\\n      xy = 3 \\\\\n    \\end{cases}\\\\\n    x = \\sqrt{3}, y = \\sqrt{3} \\\\\n    or\\, x = -\\sqrt{3}, y = -\\sqrt{3} \\\\\n  \\end{gather*}\n  When $\\lambda = -2$,\n  \\begin{gather*}\n    \\begin{cases}\n      2x + 2y = 0 \\\\\n      2x + 2y = 0 \\\\\n      xy = 3 \\\\\n    \\end{cases} \\\\\n    \\textnormal{There is no solution.}\n  \\end{gather*}\n  Therefore, there are two points closest to the origin on the hyperbola \n  $xy = 3$, which are $(\\sqrt{3}, \\sqrt{3})$ and $(-\\sqrt{3}, -\\sqrt{3})$.\n\\end{example}\n\n\\section{Justification of Lagrange Multipliers}\n\nAt the constrained maximum/minimum points of a function $f$, in any direction \nalong the level sets of $g = c$, the rate of change of $f$ must be 0. If not, \nthen an adjacent point along the direction must be greater than or less than the \nmaximum/minimum point, which is a contradiction to the fact of maximum/minimum \npoint.\n\nFor any direction $\\hat{u}$ tangent to the level set $g = c$, it holds that\n\\begin{gather*}\n  \\frac{df}{ds}|_{\\hat{u}} = 0 \\\\\n  \\nabla f \\cdot \\hat{u} = 0 \\\\\n\\end{gather*}\nTherefore, $\\nabla f$ is perpendicular to any direction $\\hat{u}$ tangent to the \nlevel set of $g$. Therefore, $\\nabla f$ is perpendicular to the level set of \n$g$. Also according to the property of gradient, $\\nabla g$ is also \nperpendicular to the level set of $g$. Therefore \n\\[ \\nabla f \\parallel \\nabla g \\]\n\n\\section{Restriction of Lagrange Multipliers}\n\nWARNING: the method of Lagrange multipliers doesn't tell whether a solution is a \nmaximum or minimum points. We need to check other solutions as well as boundary \nvalues to determine whether it is a maximum point or minimum point.\n\nAlso, we cannot use the second derivative test to determine the type of a \nsolution by the method of Lagrange multipliers.\n\n\\begin{example}\n  Suppose that we want to build a pyramid with the given triangular base and the \n  given volume, find the shape with the minimum total surface area.\n\n  Recall that the formula of the volume of a tetraheron is\n  \\[ V = \\frac{1}{3}(\\textnormal{base area})(\\textnormal{height}) \\]\n\n  Since we are given the triangular base and the given volume, the height of the \n  tetraheron is actually fixed. Let $h$ denote the fixed height.\n\n  One method is to suppose that the coordinate of the top vertex is $(x, y, h)$. \n  The coordinates of all other vertices are known: $(x_1, y_1, 0)$, \n  $(x_2, y_2, 0)$, and $(x_3, y_3, 0)$. So we can get the function of the total \n  surface area, which is a function of $x$ and $y$, and then try to minimize the \n  function. The problem with this method is that the function can be too \n  complex to minimize.\n\n  \\begin{tikzpicture}\n    [help line/.style={dashed}]\n    \\draw (-3, -1.732) node[below left] {$P_1$};\n    \\draw (3, -1.732) node[below right] {$P_2$};\n    \\draw (0, 3.464) node[above] {$P_3$};\n    \\draw (-3, -1.732) -- (0, -1.732) node[below] {$a_1$} -- (3, -1.732);\n    \\draw (-3, -1.732) -- (-1.5, 0.866) node[above left] {$a_2$} -- (0, 3.464);\n    \\draw (3, -1.732) -- (1.5, 0.866) node[above right] {$a_3$} -- (0, 3.464);\n    \\draw (0, 0) node[right] {Q};\n    \\draw[help line] (0, 0) -- (0, -0.866) node[right] {$u_1$} -- (0, -1.732);\n    \\draw[help line] (0, 0) -- (-0.75, 0.433) node[right] {$u_2$} -- (-1.5, 0.866);\n    \\draw[help line] (0, 0) -- (0.75, 0.433) node[right] {$u_3$} -- (1.5, 0.866);\n  \\end{tikzpicture}\n\n  Another method is to use different variables to calculate the total surface \n  area. As shown in the above diagram, suppose that the cast point of the top \n  vertex in the base is the point $Q$, and the lengths of the three edges are \n  $a_1$, $a_2$, and $a_3$. From $Q$ we construct perpendicular lines to the \n  three edges of the base, and let $u_1$, $u_2$, and $u_3$ denote their lengths.\n\n  The heights of the three faces can be calculated as\n  \\begin{gather*}\n    h_1 = \\sqrt{u_1^2 + h^2} \\\\\n    h_2 = \\sqrt{u_2^2 + h^2} \\\\\n    h_3 = \\sqrt{u_3^2 + h^2} \\\\\n  \\end{gather*}\n  The area of the three faces can be calculated as\n  \\begin{gather*}\n    s_1 = \\frac{1}{2}a_1\\sqrt{u_1^2 + h^2} \\\\\n    s_2 = \\frac{1}{2}a_2\\sqrt{u_2^2 + h^2} \\\\\n    s_3 = \\frac{1}{2}a_3\\sqrt{u_3^2 + h^2} \\\\\n  \\end{gather*}\n  Therefore, the total area of the three faces can be calculated as\n  \\begin{equation*}\n    s = f(u_1, u_2, u_3) = \\frac{1}{2}a_1\\sqrt{u_1^2 + h^2} + \\frac{1}{2}a_2\\sqrt{u_2^2 + h^2} + \\frac{1}{2}a_3\\sqrt{u_3^2 + h^2}\n  \\end{equation*}\n  Also we have the constraint about the base area:\n  \\begin{equation*}\n    s_b = g(u_1, u_2, u_3) = \\frac{1}{2}a_1u_1 + \\frac{1}{2}a_2u_2 + \\frac{1}{2}a_3u_3\n  \\end{equation*}\n  We need to find the minimum point of the total area of the three faces \n  $s = f(u_1, u_2, u_3)$. According to the method of Lagrange multipliers, we \n  can derive the following system of equations:\n  \\begin{gather*}\n    \\begin{cases}\n      f_{u_1} = \\lambda g_{u_1} \\\\\n      f_{u_2} = \\lambda g_{u_2} \\\\\n      f_{u_3} = \\lambda g_{u_3} \\\\\n      g(u_1, u_2, u_3) = c \\\\\n    \\end{cases} \\\\\n    \\begin{cases}\n      \\frac{a_1}{2}\\frac{u_1}{\\sqrt{u_1^2 + h^2}} = \\lambda \\frac{a_1}{2} \\\\\n      \\frac{a_2}{2}\\frac{u_2}{\\sqrt{u_2^2 + h^2}} = \\lambda \\frac{a_2}{2} \\\\\n      \\frac{a_3}{2}\\frac{u_3}{\\sqrt{u_3^2 + h^2}} = \\lambda \\frac{a_3}{2} \\\\\n      g(u_1, u_2, u_3) = c \\\\\n    \\end{cases} \\\\\n    \\begin{cases}\n      \\frac{u_1}{\\sqrt{u_1^2 + h^2}} = \\lambda \\\\\n      \\frac{u_2}{\\sqrt{u_2^2 + h^2}} = \\lambda \\\\\n      \\frac{u_3}{\\sqrt{u_3^2 + h^2}} = \\lambda \\\\\n      g(u_1, u_2, u_3) = c \\\\\n    \\end{cases} \\\\\n  \\end{gather*}\n  Therefore, when the total surface area is minimum, $u_1 = u_2 = u_3$.\n\\end{example}\n\n\\end{document}", "meta": {"hexsha": "74297019f1ffc41c6de5900f84c33e875355a65b", "size": 10274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture13.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": "lecture13.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": "lecture13.tex", "max_forks_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_forks_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.9568345324, "max_line_length": 129, "alphanum_fraction": 0.6333463111, "num_tokens": 3581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.6725385673761614}}
{"text": "\\chapter{Rod Cutting Algorithm}\nThe objective of this challenge is to determine how to cut an imaginary rod to\nreceive the maximum revenue. Revenue per rod length and initial rod lengths are\ngiven. Note that, if the price for the initial rod length is high enough, the\noptimal solution may require no cutting at all.\n\n\\section{Brute Force}\n\\imb[4][10]{\\alg/rodcutting.cpp}\n\\imb[35][39]{\\alg/rodcutting.cpp}\n\\imb[47][47]{\\alg/rodcutting.cpp}\n\\imb[48][49]{\\alg/rodcutting.cpp}\n\nSince there are $n-1$ places to either cut or leave, there are $2^{n-1}$ ways in\ntotal to cut a rod of $n$ inches. Therefore a brute force algorithm such as the\none presented solves all possible outcomes and finds the maximum value. Time\nComplexity Analysis shows an exponential time function.\n\\newpage\n\n\\section{Dynamic Programming: Top-Down Approach}\n\\imb[12][22]{\\alg/rodcutting.cpp}\n\\imb[35][39]{\\alg/rodcutting.cpp}\n\\imb[41][45]{\\alg/rodcutting.cpp}\n\\imb[48][49]{\\alg/rodcutting.cpp}\n\nThe most critical reason for the brute force algorithm's exponentailly long time\nconplexity is that brute force repeats sonving what is essentially the same set\nof divisions. For example, when processing the cutting of a $9$ inch rod, brute\nforce algorithm processes the same 2, 3, and 4-inch dsivision as 6 different\nmethods $(2,~3,~4),~(3,~2,~4),\\cdots$. This can be solved by recording results\nof previous iterations of the recursion, or the \\textbf{memoisation} of previous\ndata. With the top-down method presented above, the new array \\imc{int* arr} is\na storage array for the previously processed results.\n\n\\section{Dynamic Programming: Bottom-Up Approach}\n\\imb[24][33]{\\alg/rodcutting.cpp}\n\\imb[35][39]{\\alg/rodcutting.cpp}\n\\imb[40][40]{\\alg/rodcutting.cpp}\n\\imb[48][49]{\\alg/rodcutting.cpp}\n\nUnusual circumstances can lead to failures in top-down algorithms where not all\npossible outcomes are tested. The bottom-up approach above often shows strength\nin constant factors and overall stability, and can be mathematically proven in\nits ability to always process all subproblems, although such proof will not be\nprovided in this manual.\n\nBoth Top-Down and Bottom-Up approaches show a time complexity of $T(n)=\\Theta\n\\left(n^2\\right)$.\n", "meta": {"hexsha": "549be8997db94138bf0db981e3fc5e5fb2f4d86d", "size": 2207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/07_rodcutting.tex", "max_stars_repo_name": "thekpaul/Programming-Methodology", "max_stars_repo_head_hexsha": "949e798206f79d26f5f69bda8ab5a546369a8d2b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-06-10T19:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-11T04:09:31.000Z", "max_issues_repo_path": "Algorithms/07_rodcutting.tex", "max_issues_repo_name": "thekpaul/Programming-Methodology", "max_issues_repo_head_hexsha": "949e798206f79d26f5f69bda8ab5a546369a8d2b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-11T04:10:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-11T08:43:32.000Z", "max_forks_repo_path": "Algorithms/07_rodcutting.tex", "max_forks_repo_name": "thekpaul/Programming-Methodology", "max_forks_repo_head_hexsha": "949e798206f79d26f5f69bda8ab5a546369a8d2b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-10T19:00:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-10T19:00:51.000Z", "avg_line_length": 45.9791666667, "max_line_length": 80, "alphanum_fraction": 0.7698232895, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.6725385668487157}}
{"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{December 1, 2014}\n\\maketitle\n\\section*{5.2 \\#13}\nif $\\varphi:\\mathbb{Z}+\\mathbb{Z}\\to\\mathbb{Z}$ is a ring homomorphism then for every $m,n\\in\\mathbb{Z}$ we have $\\varphi(m,n)=\\varphi((m,0)+(0,n))=\\varphi(m,0)+\\varphi(0,n)=\\varphi(\\underbrace{1+1+\\dots+1}_m,0)+\\varphi(0,\\underbrace{1+1+\\dots+1}_n)=\\underbrace{\\varphi(1,0)+\\dots\\varphi(1,0)}_m+\\underbrace{\\varphi(0,1)+\\dots\\varphi(0,1)}_n=m\\varphi(1,0)+n\\varphi(0,1)$\n\nnow $\\alpha=\\varphi(1,0)$ and $\\beta=\\varphi(0,1)$ and $\\alpha+\\beta=\\varphi(1,1)=1$ and so $\\alpha+\\beta=1$\n\nalso $\\alpha\\beta=\\varphi(0,0)=0$.\n\n\\begin{enumerate}\n\\item\n$\\alpha=0$ then $\\beta=1$ and so $\\varphi(m,n)=m\\cdot0+n\\cdot 1=n$ which is a ring homomorphism\n\\item\n$\\beta=0$ then $\\alpha=1$ and so $\\varphi(m,n)=m$ which is a ring homomorphism.\n\\end{enumerate}\n\nwe start with a homomorphism, check all possible outputs and check that all outputs are homomorphisms.\n\\section*{last time}\n$\\varphi:R\\to S$ is a ring hom\n\n$\\ker\\varphi=x\\in R:\\varphi(x)=0$\n\n$R/\\ker\\varphi=\\{[x]:x\\in R\\}$\n\n$x\\sim y\\Leftrightarrow x-y\\in \\ker\\varphi$\n\n$\\Leftrightarrow\\varphi(x)=\\varphi(y)$\n\n\\section*{5.3}\n\\subsection*{definition}\ngiven a comm ring $R$ and a non-empty subset $I\\subseteq R$ we say that $I$ is an {\\bfseries ideal} of(in) $R$ if\n\\begin{enumerate}\n\\item\nfor every two elements $x,y\\in I$ we have $x+y,x-y\\in I$ in particular $0\\in I$.\n\\item\nfor every $r\\in R$ and every $x\\in I$ we have $rx\\in I$\n\n\\end{enumerate}\n\n\\subsection*{examples}\nevery commutative ring has at least two ideals (unless $0=1$)\n\n$\\{0\\}$ is an ideal of $R$\n\n$R$ is an ideal of $R$.\n\nif these are the only possible ideals then $R$ is a field\n\n\\subsection*{thrm}\nlet $R$ be a commutative ring. then $R$ is a field if and only if $\\{0\\}$ and $R$ are the only ideals of $R$.\n\n\\subsubsection*{proof}\n$\\Rightarrow$ assume that $R$ is a field, and let $I$ be an ideal of $R$. if $I=\\{0\\}$ we are done so assome $I\\ne \\{0\\}$. we want to prove that $I=R$. let $x\\ne0\\in I$. because $R$ is a field then $x^{-1}\\in R$ and $x^{-1}x\\in I$ because $x\\in I$ and so $1\\in I$ and $r=r\\cdot 1\\in I$ and so $I=R$\n\n$\\Leftarrow$\nTake $a\\ne 0\\in R$. we want to prove that $a$ is invertible.\n$I=\\{ra:r\\in R\\}\\subseteq R$\n\nclaim: $I$ is an ideal of $R$. Now we have an ideal different from zero because $a\\in I$ therefor $I=R$ and so $1\\in I$. $\\exists r\\in R$ such that $ra=1$ and so $r=a^{-1}$.\n\n\\subsubsection*{observation}\n\\begin{enumerate}\n\\item\ngiven $a\\in R$ then $\\{ra:r\\in R\\}$ is an ideal of $R$ denoted $Ra$ or $(a)$ or $aR$. In fact this is the smallest ideal of $R$ that contains $a$.\n\nwe call this the ideal generated by $a$.\n\\item\n$1\\in I$ iff $I=R$.\n\\end{enumerate}\n\\subsection*{definition}\nfor $R$ commutative ring, we say the $R$ is a {\\bfseries principle ideal} if every ideal of $R$ is principal. that is every  ideal of $R$ is of the form $(a)$\n\n\\subsection*{definition}\nwe say that $R$ is a {\\bfseries principal ideal domain} (PID) if $R$ is an integral domain and a principal ideal ring.\n\n\\subsection*{example}\nfields are always principal ideal rings generated by $1$ (and PID).\n\n$\\mathbb{Z}$ is a PID.\n\\subsection*{example 5.3.1}\nlet $I\\in \\mathbb{Z}$ be an ideal different from 0. Let $a\\in I$ be the smallest positive integer in $I$. (note that there is an element not zero in $I$ and so if there is a negative in $I$ then it's additive inverse is in $I$.\n\n$\\supseteq$\n\n$a\\in I\\to ra\\in I$\n\n$\\subseteq$\n\npick some $x\\in I$ $x=qa+r$ where $0\\le  r<0$ then $r=x+-q(a)$ and because $a\\in I$ then $-qa\\in I$ and $r\\in I$ and so $r=0$ and so $x\\in (a)$\n\n\\section*{examples}\nlet $K$ be a field then $K[x]$ is a PID.\n\nlet $I\\subseteq K[x]$ be a nonzero ideal. let $q(x)\\in I$ be a non-zero polynomial of minimal degree\n\nclaim:$I=(q(x))$\n\\subsubsection*{proof}\n$q(x)K[x]\\subseteq I$ is clear\n\nlet $f(x)\\in I$. $f(x)=b(x)q(x)+r(x)$ where $r(x)=0$ or $\\deg r(x)<\\deg q(x)$\n\nbut $r(x)=f(x)+(-b(x)q(x))\\in I$ of course $q(x)$ has minimal degree and so by this choice we must have $r(x)=0$ and so $f(x)$ is a multiple of $q(x)$ and we are done.\n\\end{document}\n\n\n\n", "meta": {"hexsha": "663084f48f575643bbbcaf825225346b9a1c1eae", "size": 4278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-12-01.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-12-01.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-12-01.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.9495798319, "max_line_length": 370, "alphanum_fraction": 0.6631603553, "num_tokens": 1595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.6725282642410215}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{natbib}\n\n\\usepackage[a4paper, margin=1in]{geometry}\n\n%opening\n\\title{Magnetic Field Model Equations and a Load of Legendre Polynomials}\n\\author{Matt James}\n\n\\begin{document}\n\n\\maketitle\n\n\n\\section{Legendre Polynomials}\n\n\tThis is the form of a Legendre polynomial (Rodrigues' formula):\n\t\n\t\\begin{equation}\n\t\tP_n(x) = \\frac{1}{2^n n!}\\frac{\\text{d}^n}{\\text{d}x^n}(x^2 - 1)^n \\label{EqLegendre}\n\t\\end{equation}\n\twhere $n$ is the degree of the polynomial. The first 5 degrees (0-4) are shown below:\n\t\n\t\\begin{align}\n\t\tP_0(x) &= \\frac{\\text{d}^0}{\\text{d}x^0} (x^2 - 1)^0 &= 1, \\label{EqP0} \\\\\n\t\tP_1(x) &= \\frac{1}{2} \\frac{\\text{d}}{\\text{d}x} (x^2 - 1) &= x, \\label{EqP1} \\\\\n\t\tP_2(x) &= \\frac{1}{8} \\frac{\\text{d}^2}{\\text{d}x^2} (x^2 - 1)^2 &= \\frac{1}{2}(3x^2 - 1), \\label{EqP2} \\\\\n\t\tP_3(x) &= \\frac{1}{48} \\frac{\\text{d}^3}{\\text{d}x^3} (x^2 - 1)^3 &= \\frac{1}{2}(5x^3 - 3x), \\label{EqP3} \\\\\n\t\tP_4(x) &= \\frac{1}{384} \\frac{\\text{d}^4}{\\text{d}x^4} (x^2 - 1)^4 &= \\frac{1}{8}(35x^4 - 30x^2 + 3), \\label{EqP4}\n\t\\end{align}\n \tand $x$ can be substituted for $\\cos{\\theta}$:\n\t\n\t\\begin{align}\n\t\tP_0(\\cos{\\theta}) &= 1 \\label{EqP0t}, \\\\\n\t\tP_1(\\cos{\\theta}) &= \\cos{\\theta}, \\label{EqP1t} \\\\\n\t\tP_2(\\cos{\\theta}) &= \\frac{1}{2}(3\\cos^2{\\theta} - 1 \\label{EqP2t}), \\\\\n\t\tP_3(\\cos{\\theta}) &= \\frac{1}{2}(5\\cos^3{\\theta} - 3\\cos{\\theta}), \\label{EqP3t} \\\\\n\t\tP_4(\\cos{\\theta}) &= \\frac{1}{8}(35\\cos^4{\\theta} - 30x^2 + 3). \\label{EqP4t}\t\t\n\t\\end{align}\n\t\n\t\\subsection{Derivatives}\n\t\t\n\t\tThese derivatives of the above equations \\ref{EqP0}--\\ref{EqP4} with respect to $x$ will come in handy later on...\n\t\t\n\t\tFor equation \\ref{EqP0}:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d} x}P_0 (x) &= 0. \\label{Eqd1P0}\n\t\t\\end{align}\n\n\t\tFor equation \\ref{EqP1}:\n\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d} x} P_1 (x) &= 1. \\label{Eqd1P1}\n\t\t\\end{align}\n\t\t\n\t\tFor equation \\ref{EqP2}:\n\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d} x} P_2 (x) &= 3x, \\label{Eqd1P2} \\\\\n\t\t\t\\frac{\\text{d}^2}{\\text{d} x^2} P_2 (x) &= 3. \\label{Eqd2P2}\n\t\t\\end{align}\n\t\t\n\t\tFor equation \\ref{EqP3}:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d} x} P_3 (x) &= \\frac{1}{2}(15x^2 - 3), \\label{Eqd1P3} \\\\\n\t\t\t\\frac{\\text{d}^2}{\\text{d} x^2} P_3 (x) &= 15x, \\label{Eqd2P3} \\\\\n\t\t\t\\frac{\\text{d}^3}{\\text{d} x^3} P_3 (x) &= 15. \\label{Eqd3P3}\n\t\t\\end{align}\n\t\t\n\t\tFor equation \\ref{EqP4}:\n\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d} x} P_4 (x) &= \\frac{5}{2}(7x^3 - 3x), \\label{Eqd1P4} \\\\\n\t\t\t\\frac{\\text{d}^2}{\\text{d} x^2} P_4 (x) &= \\frac{15}{2}(7x^2 - 1), \\label{Eqd2P4} \\\\\n\t\t\t\\frac{\\text{d}^3}{\\text{d} x^3} P_4 (x) &= 105x, \\label{Eqd3P4} \\\\\n\t\t\t\\frac{\\text{d}^4}{\\text{d} x^4} P_4 (x) &= 105. \\label{Eqd4P4}\n\t\t\\end{align}\n\t\t\t\n\\section{Ferrers Normalized Legendre Polynomials}\n\n\tThe associated Legendre polynomials are defined by \\cite{Ferrers1877} as:\n\t\n\t\\begin{equation}\n\t\tP_{n,m}(x) = (1 - x^2)^\\frac{m}{2} \\frac{\\text{d}^m}{\\text{d}x^m} P_n(x) \\label{EqFerrers},\n\t\\end{equation}\n\twhere $m$ is the order.\n\n\n\tSome equations and their derivatives...\n\t\n\t\\begin{align}\n\t\tP_{0,0} (x) &= 1, \\\\\n\t\tP_{0,0} (\\cos{\\theta}) &= 1, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{0,0} &= 0.\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{1,0} (x) &= x, \\\\\n\t\tP_{1,0} (\\cos{\\theta}) &= \\cos{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{1,0} &= -\\sin{\\theta}.\n\t\\end{align}\n\t\n\t\\begin{align}\n\t\tP_{1,1} (x) &= (1 - x^2)^\\frac{1}{2}, \\\\\n\t\tP_{1,1} (\\cos{\\theta}) &= \\sin{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{1,1} &= \\cos{\\theta}.\n\t\\end{align}\n\n\t\n\t\\begin{align}\n\t\tP_{2,0} (x) &= \\frac{1}{2} (3 x^2 - 1), \\\\\n\t\tP_{2,0} (\\cos{\\theta}) &= \\frac{1}{2}(3\\cos^2{\\theta} - 1), \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{2,0} &= -3\\cos{\\theta}\\sin{\\theta}.\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{2,1} (x) &= 3x(1-x^2)^\\frac{1}{2}, \\\\\n\t\tP_{2,1} (\\cos{\\theta}) &= 3\\cos{\\theta}\\sin{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{2,1} &= 3(2\\cos^2{\\theta}-1).\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{2,2} (x) &= 3(1-x^2), \\\\\n\t\tP_{2,2} (\\cos{\\theta}) &= 3\\sin^2{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{2,2} &= 6\\sin{\\theta}\\cos{\\theta}.\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{3,0} (x) &= \\frac{1}{2} (5x^3 - 3x), \\\\\n\t\tP_{3,0} (\\cos{\\theta}) &= \\frac{1}{2} (5 \\cos^3{\\theta} - 3\\cos{\\theta}), \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{3,0} &= \\frac{3}{2} \\sin{\\theta} (1 - 5 \\cos^2{\\theta}).\n\t\\end{align}\n\n\n\t\\begin{align}\n\t\tP_{3,1} (x) &= \\frac{1}{2} \\sqrt{(1-x^2)}(15x^2 - 3), \\\\\n\t\tP_{3,1} (\\cos{\\theta}) &= \\frac{3}{2} \\sin{\\theta}(5\\cos^2{\\theta} -1), \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{3,1} &= \\frac{3}{2} \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}(5\\cos^2{\\theta}-1) + (5\\cos^2{\\theta} - 1)\\frac{\\text{d}}{\\text{d}\\theta}\\sin{\\theta}\\right], \\\\\n\t\t&= \\frac{3}{2} (15\\cos^3{\\theta} - 11\\cos{\\theta}).\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{3,2} (x) &= 15x (1-x^2), \\\\\n\t\tP_{3,2} (\\cos{\\theta}) &= 15 \\cos{\\theta} \\sin^2{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{3,2} &= 15 \\sin{\\theta} (3\\cos^2{\\theta} - 1).\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{3,3} (x) &= 15(1-x^2)^\\frac{3}{2}, \\\\\n\t\tP_{3,3} (\\cos{\\theta}) &= 15 \\sin^3{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{3,3} &= 45 \\sin^2{\\theta}\\cos{\\theta}.\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{4,0} (x) &= \\frac{1}{8}(35x^4 - 30x^2 + 3), \\\\\n\t\tP_{4,0} (\\cos{\\theta}) &= \\frac{1}{8}(35 \\cos^4{\\theta} - 30\\cos^2{\\theta} + 3), \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{4,0} &= \\frac{5}{2}(7\\cos^3{\\theta} - 3\\cos{\\theta}).\n\t\\end{align}\n\n\n\t\\begin{align}\n\t\tP_{4,1} (x) &= \\frac{5}{2}(7x^3 - 3x) (1-x^2)^\\frac{1}{2}, \\\\\n\t\tP_{4,1} (\\cos{\\theta}) &= \\frac{5}{2} \\sin{\\theta}(7\\cos^3{\\theta} - 3\\cos{\\theta}), \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{4,1} &= \\frac{5}{2}\\left[(7\\cos^3{\\theta} - 3\\cos{\\theta})\\frac{\\text{d}}{\\text{d}\\theta}\\sin{\\theta} + \\sin{\\theta} \\frac{\\text{d}}{\\text{d}\\theta}(7\\cos^3{\\theta} - 3\\cos{\\theta})\\right], \\\\\n\t\t&= \\frac{5}{2}(28 \\cos^4{\\theta} - 27 \\cos^3{\\theta} + 3).\n\t\\end{align}\n\t\n\n\n\t\\begin{align}\n\t\tP_{4,2} (x) &= \\frac{15}{2}(7x^2 - 1) (1-x^2), \\\\\n\t\tP_{4,2} (\\cos{\\theta}) &= \\frac{15}{2} \\sin^2{\\theta}(7\\cos^2{\\theta} - 1), \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{4,2} &= \\frac{15}{2}\\left[(7\\cos^2{\\theta} - 1)\\frac{\\text{d}}{\\text{d}\\theta}\\sin^2{\\theta} + \\sin^2{\\theta} \\frac{\\text{d}}{\\text{d}\\theta}(7\\cos^2{\\theta} - 1)\\right], \\\\\n\t\t&= 30\\cos{\\theta}\\sin{\\theta}(7\\cos^2{\\theta} - 4).\n\t\\end{align}\n\n\t\\begin{align}\n\t\tP_{4,3} (x) &= 105x(1-x^2)^\\frac{3}{2}, \\\\\n\t\tP_{4,3} (\\cos{\\theta}) &= 105 \\cos{\\theta}\\sin^3{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{4,3} &= 105\\left[\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}\\sin^3{\\theta} + \\sin^3{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}\\cos{\\theta}\\right], \\\\\n\t\t&= 105 \\sin^2{\\theta}(4\\cos^2{\\theta} - 1).\n\t\\end{align}\t\n\n\t\\begin{align}\n\t\tP_{4,4} (x) &= 105(1-x^2)^2, \\\\\n\t\tP_{4,4} (\\cos{\\theta}) &= 105 \\sin^4{\\theta}, \\\\\n\t\t\\frac{\\text{d}}{\\text{d} \\theta} P_{4,4} &= 420 \\sin^3{\\theta} \\cos{\\theta}.\n\t\\end{align}\t\n\t\n\t\\subsection{Recurrence Relations}\n\t\t\\label{SectRecurrence}\n\t\tThere are three recurrence relations which are used to calculate the associate polynomials from lower order/degree polynomials. \n\t\t\n\t\t\\begin{align}\n\t\t\t&\\text{A: }  m < n-1  \\nonumber \\\\ \n\t\t\t&P_{n,m} (\\cos{\\theta}) = \\frac{1}{n-m} \\left[(2n-1)\\cos{\\theta} P_{n-1,m} - (n + m -1)P_{n-2,m}\\right] \\\\\n\t\t\t&\\text{B: }  m = n-1  \\nonumber \\\\ \n\t\t\t&P_{n,m} (\\cos{\\theta}) = (2n-1)\\sin{\\theta} P_{n-1,m-1}, \\\\\n\t\t\t&\\text{C: }  m = n  \\nonumber \\\\ \n\t\t\t&P_{n,m} (\\cos{\\theta}) = (2n-1)\\sin{\\theta} P_{n-1,m-1}.\n\t\t\\end{align}\n\t\t\n\t\tThey are based on code used elsewhere, but the difference being that a factor of $(-1)^m$ was removed from rule C (and also from their calculation of $S_{n,m}$ as the seem to cancel each other). Also rule B uses $\\sin$ here as opposed to $\\cos$ (I think the original code had a mistake in it). These changes effectively make rules B and C identical. The examples below should all match with those derived directly from equations \\ref{EqLegendre} and \\ref{EqFerrers} in the previous subsection.\n\t\t\n\t\tExamples for case A:\n\t\t\n\t\t\\begin{align}\n\t\t\tP_{2,0} &= \\frac{1}{2}\\left[ 3\\cos{\\theta} P_{1,0} - P_{0,0} \\right] \\\\\n\t\t\t\t\t&= \\frac{1}{2}(3\\cos^2{\\theta} - 1) \\\\\n\t\t\tP_{3,0} &= \\frac{1}{3}\\left[5\\cos{\\theta}P_{2,0} - 2P_{1,0}\\right] \\\\\n\t\t\t\t\t&= \\frac{1}{2}(5 \\cos^3{\\theta} - 3\\cos{\\theta}) \\\\\n\t\t\tP_{3,1} &= \\frac{1}{2}\\left[5 \\cos{\\theta} P_{2,1} - 3P_{1,1}\\right] \\\\\n\t\t\t\t\t&= \\frac{3}{2}\\sin{\\theta}\\left[5 \\cos^2{\\theta} - 1\\right] \\\\\n\t\t\tP_{4,0} &= \\frac{1}{4}\\left[7\\cos{\\theta}P_{3,0} - 3P_{2,0}\\right] \\\\\n\t\t\t\t\t&= \\frac{1}{8}(35 \\cos^4{\\theta} - 30\\cos^2{\\theta} + 3) \\\\\n\t\t\tP_{4,1} &= \\frac{1}{3}\\left[7\\cos{\\theta} P_{3,1} - 4P_{2,1}\\right] \\\\\n\t\t\t\t\t&= \\frac{5}{2}\\sin{\\theta}\\cos{\\theta}(7\\cos^2{\\theta} - 3) \\\\\n\t\t\tP_{4,2} &= \\frac{1}{2}\\left[7\\cos{\\theta}P_{3,2} - 5P_{2,2}\\right] \\\\\n\t\t\t\t\t&= \\frac{15}{2}\\sin^2{\\theta}(7\\cos^2{\\theta} -1)\n\t\t\\end{align}\n\t\t\n\t\tExamples for case B:\n\t\t\n\t\t\\begin{align}\n\t\t\tP_{2,1} &= 3\\sin{\\theta}P_{1,0} \\\\\n\t\t\t\t\t&= 3\\sin{\\theta}\\cos{\\theta} \\\\\n\t\t\tP_{3,2} &= 5\\sin{\\theta}P_{2,1} \\\\\n\t\t\t\t\t&= 15\\sin^2{\\theta}\\cos{\\theta} \\\\\n\t\t\tP_{4,3} &= 7\\sin{\\theta}P_{3,2} \\\\\n\t\t\t\t\t&= 105\\sin^3{\\theta}\\cos{\\theta} \n\t\t\\end{align}\n\t\t\n\t\tExamples for case C (I think this rule is basically the same as B):\n\t\t\n\t\t\\begin{align}\n\t\t\tP_{1,1} &= \\sin{\\theta}P_{0,0} \\\\\n\t\t\t\t\t&= \\sin{\\theta} \\\\\n\t\t\tP_{2,2} &= 3\\sin{\\theta}P_{1,1} \\\\\n\t\t\t\t\t&= 3\\sin^2{\\theta} \\\\\n\t\t\tP_{3,3} &= 5\\sin{\\theta}P_{2,2} \\\\\n\t\t\t\t\t&= 15\\sin^3{\\theta} \\\\\n\t\t\tP_{4,4} &= 7\\sin{\\theta}P_{3,3} \\\\\n\t\t\t\t\t&= 105\\sin^4{\\theta}\n\t\t\\end{align}\n\t\t\n\t\tThe derivatives can be calculated using similar rules:\n\t\t\n\t\t\\begin{align}\n\t\t\t&\\text{A: }  m < n-1  \\nonumber \\\\ \n\t\t\t&\\frac{\\text{d}}{\\text{d}\\theta} P_{n,m} = \\frac{1}{n-m} \\left[(2n-1)\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{n-1,m} - \\sin{\\theta}P_{n-1,m}\\right) - (n+m-1)\\frac{\\text{d}}{\\text{d}\\theta}P_{n-2,m}\\right] \\\\\n\t\t\t&\\text{B: }  m = n-1  \\nonumber \\\\ \n\t\t\t&\\frac{\\text{d}}{\\text{d}\\theta} P_{n,m} = (2n-1) \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{n-1,m-1} + \\cos{\\theta}P_{n-1,m-1}\\right] \\\\\n\t\t\t&\\text{C: }  m = n  \\nonumber \\\\ \n\t\t\t&\\frac{\\text{d}}{\\text{d}\\theta} P_{n,m} = (2n-1) \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{n-1,m-1} + \\cos{\\theta}P_{n-1,m-1}\\right]\n\t\t\\end{align}\n\t\t\n\t\tExamples for case A:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{2,0} &= \\frac{1}{2}\\left[3\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{1,0} - \\sin{\\theta}P_{1,0}\\right) - \\frac{\\text{d}}{\\text{d} \\theta} P_{0,0}\\right] \\\\\n\t\t\t\t&= \\frac{1}{2} (3 \\cos^2{\\theta} -1)\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{3,0} &= \\frac{1}{3}\\left[5\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{2,0} - \\sin{\\theta}P_{2,0}\\right) - 2\\frac{\\text{d}}{\\text{d} \\theta} P_{1,0}\\right] \\\\\n\t\t\t\t&= \\frac{1}{2}(5\\cos^3{\\theta} - 3\\cos{\\theta})\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{3,1} &= \\frac{1}{2}\\left[5\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{2,1} - \\sin{\\theta}P_{2,1}\\right) - 3\\frac{\\text{d}}{\\text{d} \\theta} P_{1,1}\\right] \\\\\n\t\t\t\t&= \\frac{3}{2}\\sin{\\theta}(5\\cos^2{\\theta} - 1)\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{4,0} &= \\frac{1}{4}\\left[7\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{3,0} - \\sin{\\theta}P_{3,0}\\right) - 3\\frac{\\text{d}}{\\text{d} \\theta} P_{2,0}\\right] \\\\\n\t\t\t\t&= \\frac{1}{8}(35\\cos^4{\\theta} - 30\\cos^2{\\theta} + 3)\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{4,1} &= \\frac{1}{3}\\left[7\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{3,1} - \\sin{\\theta}P_{3,1}\\right) - 4\\frac{\\text{d}}{\\text{d} \\theta} P_{2,1}\\right] \\\\\n\t\t\t\t&= \\frac{5}{2} \\sin{\\theta}\\cos{\\theta}(7\\cos^2{\\theta} - 3) \\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{4,2} &= \\frac{1}{2}\\left[7\\left(\\cos{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{3,2} - \\sin{\\theta}P_{3,2}\\right) - 5\\frac{\\text{d}}{\\text{d} \\theta} P_{2,2}\\right] \\\\\n\t\t\t\t&= \\frac{15}{2}\\sin^2{\\theta}(7\\cos^2{\\theta} - 1)\n\t\t\\end{align}\n\t\t\n\t\tExamples for case B:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{2,1} &= 3 \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{1,0} + \\cos{\\theta}P_{1,0}\\right] \\\\\n\t\t\t&= 6 \\cos^2{\\theta} - 3\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{3,2} &= 5 \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{2,1} + \\cos{\\theta}P_{2,1}\\right] \\\\\n\t\t\t&= 15\\sin{\\theta}(3\\cos^2{\\theta} -1)\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{4,3} &= 7 \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{3,2} + \\cos{\\theta}P_{3,2}\\right] \\\\\n\t\t\t&= 105\\sin^2{\\theta}(4\\cos^2{\\theta} - 1)\n\t\t\\end{align}\n\n\t\tExamples for case C:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{2,2} &= 3 \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{1,1} + \\cos{\\theta}P_{1,1}\\right] \\\\\n\t\t\t&= 6 \\cos{\\theta}\\sin{\\theta} \\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{3,3} &= 5 \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{2,2} + \\cos{\\theta}P_{2,2}\\right] \\\\\n\t\t\t&= 45\\cos{\\theta}\\sin^2{\\theta}\\\\\n\t\t\t\\frac{\\text{d}}{\\text{d}\\theta}P_{4,4} &= 7 \\left[\\sin{\\theta}\\frac{\\text{d}}{\\text{d}\\theta}P_{3,3} + \\cos{\\theta}P_{3,3}\\right] \\\\\n\t\t\t&= 420\\cos{\\theta}\\sin^3{\\theta}\n\t\t\\end{align}\n\t\t\n\t\n\t\tThe recurrence relations listed above can be used to calculate any of the associated Legendre polynomials provided that $P_{0,0}$, $P_{1,0}$ and $P_{1,1}$ are defined initially. Here are some examples below, where the left polynomial is formed using the polynomial(s) to the right of the arrow and the letter in brackets corresponds to the three rules listed above:\n\t\t\n\t\t\\begin{align}\n\t\t\tP_{2,0} &\\leftarrow P_{1,0},P_{0,0} &(C) \\\\\n\t\t\tP_{2,1} &\\leftarrow P_{1,0}\t\t\t&(B) \\\\\n\t\t\tP_{2,2} &\\leftarrow P_{1,1}\t\t\t&(A) \\\\\n\t\t\t\\nonumber \\\\\n\t\t\tP_{3,0} &\\leftarrow P_{2,0},P_{1,0} &(C) \\\\\n\t\t\tP_{3,1} &\\leftarrow P_{2,1},P_{1,1} &(C) \\\\\n\t\t\tP_{3,2} &\\leftarrow P_{2,1}\t\t\t&(B) \\\\\n\t\t\tP_{3,3} &\\leftarrow P_{2,2}\t\t\t&(A) \\\\\n\t\t\t\\nonumber \\\\\n\t\t\tP_{4,0} &\\leftarrow P_{3,0},P_{2,0} &(C) \\\\\n\t\t\tP_{4,1} &\\leftarrow P_{3,1},P_{2,1} &(C) \\\\\n\t\t\tP_{4,2} &\\leftarrow P_{3,2},P_{2,2} &(C) \\\\\n\t\t\tP_{4,3} &\\leftarrow P_{3,2}\t\t\t&(B) \\\\\n\t\t\tP_{4,4} &\\leftarrow P_{3,3}\t\t\t&(A) \n\t\t\\end{align}\n\t\n\t\tNote that the same rules apply for the derivatives too.\n\t\t\n\\section{Schmidt Normalized Legendre Polynomials}\n\t\n\tThe Schmidt normalized Legendre polynomials, $P_n^m$, are defined by\n\t\n\t\\begin{equation}\n\t\tP_n^m = S_n^m P_{n,m},\n\t\\end{equation}\n\t\n\twhere \n\t\n\t\\begin{equation}\n\t\tS_{n,m} = \\sqrt{(2-\\delta_m^0)\\frac{(n-m)!}{(n+m)!}},\n\t\\end{equation}\n\t\n\tand $\\delta_m^0 = 1$ when $m = 0$, and is $\\delta_m^0 = 0$ otherwise.\n\t\n\\section{Calculating the Magnetic Field Model}\n\n\tThe magnetic field, $\\mathbf{B}$, is calculated from a scalar potential,\n\t\n\t\\begin{equation}\n\t\t\\mathbf{B} = -\\mathbf{\\nabla} V, \\label{EqScPot}\n\t\\end{equation}\n\t\n\twhere $\\mathbf{\\nabla} = \\left(\\frac{\\partial}{\\partial r},\\frac{1}{r}\\frac{\\partial}{\\partial \\theta},\\frac{1}{r \\sin{\\theta}} \\frac{\\partial}{\\partial \\phi} \\right) $ in spherical polar coordinates, $V$ is defined as \\cite[e.g.][]{Connerney1998,Winch2005},\n\t\n\t\\begin{equation}\n\t\tV = a\\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{n+1} \\sum_{m=0}^{n} \\left\\{P_n^m(\\cos{\\theta}) \\left[g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right]\\right\\}, \\label{EqSphHarm}\n\t\\end{equation}\n\t\n\tand $a$ is the radius of Jupiter (71,398~km).\n\t\n\tUsing equation \\ref{EqScPot} on \\ref{EqSphHarm}, each component of the magnetic field is defined by,\n\t\n\t\\begin{align}\n\t\tB_r &= -\\frac{\\partial V}{\\partial r} &= \\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{n+2} (n+1) \\sum_{m=0}^{n} \\left\\{P_n^m(\\cos{\\theta}) \\left[g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right]\\right\\}, \\\\\n\t\tB_\\theta &= -\\frac{1}{r}\\frac{\\partial V}{\\partial \\theta} &= -\\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{n+2} \\sum_{m=0}^{n} \\left\\{\\frac{\\text{d}}{\\text{d}\\theta} P_n^m(\\cos{\\theta}) \\left[g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right]\\right\\}, \\\\\n\t\tB_\\phi &= -\\frac{1}{r\\sin{\\theta}}\\frac{\\partial V}{\\partial \\phi} &= -\\frac{1}{\\sin{\\theta}}\\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{n+2} \\sum_{m=0}^{n} \\left\\{mP_n^m(\\cos{\\theta}) \\left[h_n^m \\cos{(m\\phi)} - g_n^m\\sin{(m\\phi)}\\right]\\right\\}.\n\t\\end{align}\n\t\n\tIn the code, the above equations use $a =1$ and $r$ in units of $R_J$.\n\t\n\t\\subsection{Cartesian Solution}\n\t\t\n\t\tPossibly dodgy derivation of the Cartesian solution to equation \\ref{EqScPot}, i.e.\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\mathbf{B} = -\\left(\\frac{\\partial}{\\partial x},\\frac{\\partial}{\\partial y},\\frac{\\partial}{\\partial z}\\right) V. \\label{EqSphHarmCart}\n\t\t\\end{equation}\n\t\n\t\tThis will be done by splitting equation \\ref{EqSphHarm} into several parts and combining them at the end...\n\t\t\n\t\t\\subsubsection{Part 1}\n\t\t\t\n\t\t\tThe derivatives of \n\t\t\t\\begin{equation} \n\t\t\t\ta \\left(\\frac{a}{r}\\right)^{n+1},\n\t\t\t\\end{equation}\n\t\t\twhere $r = \\sqrt{x^2 + y^2 + z^2}$ and we will define $u = a/r$.\n\t\t\t\\begin{align}\n\t\t\t\t\\frac{\\partial}{\\partial x} \\left[ a \\left( \\frac{a}{r}\\right)^{n+1} \\right] &= a \\frac{\\text{d} u}{\\text{d} u} u^{n+1} \\cdot \\frac{\\text{d} u}{\\text{d} r} \\cdot \\frac{\\text{d} r}{\\text{d} x},\\\\\n\t\t\t\t&= a\\left((n+1)u^n\\right)\\cdot \\left(-\\frac{u^2}{a}\\right) \\cdot \\left( \\frac{a}{r}\\right), \\\\\n\t\t\t\t&= -(n+1)\\left(\\frac{x}{r}\\right)\\left(\\frac{a}{r}\\right)^{n+2}.\n\t\t\t\\end{align}\n\t\t\t\n\t\t\tAll three components have similar solutions:\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\frac{\\partial}{\\partial x} \\left[ a \\left( \\frac{a}{r}\\right)^{n+1} \\right] &= -(n+1)\\left(\\frac{x}{r}\\right)\\left(\\frac{a}{r}\\right)^{n+2}, \\\\\n\t\t\t\t\\frac{\\partial}{\\partial y} \\left[ a \\left( \\frac{a}{r}\\right)^{n+1} \\right] &= -(n+1)\\left(\\frac{y}{r}\\right)\\left(\\frac{a}{r}\\right)^{n+2}, \\\\\n\t\t\t\t\\frac{\\partial}{\\partial z} \\left[ a \\left( \\frac{a}{r}\\right)^{n+1} \\right] &= -(n+1)\\left(\\frac{z}{r}\\right)\\left(\\frac{a}{r}\\right)^{n+2}.\n\t\t\t\\end{align}\n\t\t\n\t\t\\subsubsection{Part 2}\n\t\t\t\n\t\t\tThe derivatives of $P_n^m(\\cos\\theta)$ for each component can be done using the chain rule, e.g.:\n\t\t\t\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{\\partial}{\\partial x} P_n^m(\\cos\\theta) = \\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos\\theta) \\frac{\\partial \\theta}{\\partial x}.\n\t\t\t\\end{equation}\n\t\t\t\n\t\t\tUsing\n\t\t\t\\begin{equation}\n\t\t\t\\theta = \\arccos\\frac{z}{r} = \\arccos{\\frac{z}{\\sqrt{x^2 + y^2 + z^2}}},\n\t\t\t\\end{equation}\n\t\t\tand \n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{\\text{d}}{\\text{d} u} \\arccos{u} = \\frac{-1}{\\sqrt{1 - u^2}}, \n\t\t\t\\end{equation}\n\t\t\tthe derivatives of $\\theta$ are:\n\t\t\t\\begin{align}\n\t\t\t\t\\frac{\\partial \\theta}{\\partial x} &= \\frac{xz}{\\rho r^2}, \\\\\n\t\t\t\t\\frac{\\partial \\theta}{\\partial y} &= \\frac{yz}{\\rho r^2}, \\\\\n\t\t\t\t\\frac{\\partial \\theta}{\\partial z} &= -\\frac{\\rho}{r^2}, \n\t\t\t\\end{align}\n\t\t\twhere $\\rho = \\sqrt{x^2 + y^2}$.\n\t\t\t\n\t\t\tLegendre polynomials are therefore,\n\t\t\t\\begin{align}\n\t\t\t\t\\frac{\\partial}{\\partial x} P_n^m(\\cos\\theta) &= \\left(\\frac{xz}{\\rho r^2}\\right)\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos\\theta), \\\\\n\t\t\t\t\\frac{\\partial}{\\partial y} P_n^m(\\cos\\theta) &= \\left(\\frac{yz}{\\rho r^2}\\right)\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos\\theta), \\\\\n\t\t\t\t\\frac{\\partial}{\\partial z} P_n^m(\\cos\\theta) &= \\left(-\\frac{\\rho}{r^2}\\right)\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos\\theta), \n\t\t\t\\end{align}\t\n\t\t\twhere $\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos\\theta)$ is already calculated using the spherical polar version of the code (see section \\ref{SectRecurrence}).\n\t\t\n\t\t\\subsubsection{Part 3}\t\t\n\t\t\n\t\t\tThis section deals with the derivative of\n\t\t\t\\begin{equation}\n\t\t\t\tg_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)},\n\t\t\t\\end{equation}\t\n\t\t\twhich will be treated as a chain rule, e.g.\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{\\partial}{\\partial x}\\left(g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right) = \\frac{\\text{d}}{\\text{d}\\phi}\\left(g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right)\\cdot\\frac{\\partial\\phi}{\\partial x}.\n\t\t\t\\end{equation}\n\t\t\t\n\t\t\tThe first step in that chain rule is as follows (and used in the spherical polar version),\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{\\text{d}}{\\text{d}\\phi}\\left(g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right) = m\\left( h_n^m \\cos{(m\\phi)} - g_n^m \\sin{(m\\phi)}\\right). \\label{Eqdghdphi}\n\t\t\t\\end{equation}\n\t\t\t\n\t\t\tUsing $\\phi = \\arctan{(y/x)}$ and the fact that\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{\\text{d}}{\\text{d} u} \\arctan{u} = \\frac{1}{1 + u^2},\n\t\t\t\\end{equation}\n\t\t\tthe three derivatives of $\\phi$ are,\n\t\t\t\\begin{align}\n\t\t\t\t\\frac{\\partial \\phi}{\\partial x} = \\frac{1}{1 + \\left(\\frac{y}{x}\\right)^2}\\cdot\\frac{-y}{x^2} &= \\frac{-y}{\\rho^2}, \\label{Eqdphidx} \\\\\n\t\t\t\t\\frac{\\partial \\phi}{\\partial y} = \\frac{1}{1 + \\left(\\frac{y}{x}\\right)^2}\\cdot\\frac{1}{x} &= \\frac{x}{\\rho^2},\\label{Eqdphidy} \\\\ \n\t\t\t\t\\frac{\\partial \\phi}{\\partial z} = \\frac{1}{1 + \\left(\\frac{y}{x}\\right)^2}\\cdot 0 &= 0. \\label{Eqdphidz}\n\t\t\t\\end{align}\n\t\t\t\n\t\t\tCombining equation \\ref{Eqdghdphi} with equations \\ref{Eqdphidx}-\\ref{Eqdphidz} gives,\n\t\t\t\\begin{align}\n\t\t\t\t\\frac{\\partial}{\\partial x}\\left(g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right) &= -m\\frac{y}{\\rho^2}\\left( h_n^m \\cos{(m\\phi)} - g_n^m \\sin{(m\\phi)}\\right), \\\\\n\t\t\t\t\\frac{\\partial}{\\partial y}\\left(g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right) &= m\\frac{x}{\\rho^2}\\left( h_n^m \\cos{(m\\phi)} - g_n^m \\sin{(m\\phi)}\\right), \\\\\n\t\t\t\t\\frac{\\partial}{\\partial z}\\left(g_n^m \\cos{(m\\phi)} + h_n^m\\sin{(m\\phi)}\\right) &= 0\n\t\t\t\\end{align}\n\t\t\n\t\t\\subsubsection{Combined solution}\t\n\t\t\t\n\t\t\tUsing the three parts above to solve equation \\ref{EqSphHarmCart}:\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\tB_x = -\\frac{\\partial V}{\\partial x} &= \\sum_{n=1}^{n_{max}} (n + 1)\\left(\\frac{x}{r}\\right)\\left(\\frac{a}{r}\\right)^{(n+2)} \\sum_{m=0}^{n} \\left\\{ P_n^m(\\cos{\\theta}) \\left[ g_n^m \\cos{(m\\phi)} + h_n^m \\sin{(m\\phi)}\\right] \\right\\}    \\nonumber \\\\\n\t\t\t\t&- a \\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{(n+1)} \\sum_{m=0}^{n} \\biggl\\{ \\left(\\frac{xz}{\\rho r^2}\\right)\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos{\\theta}) \\left[g_n^m \\cos{(m\\phi)} + h_n^m \\sin{(m\\phi)} \\right] \\nonumber \\\\\n\t\t\t\t&+ m\\frac{y}{\\rho^2} P_n^m(\\cos{\\theta}) \\left[ g_n^m\\sin{(m\\phi)} - h_n^m \\cos{(m\\phi)}\\right]  \\biggr\\} \\\\\n\t\t\t\tB_y = -\\frac{\\partial V}{\\partial y} &= \\sum_{n=1}^{n_{max}} (n + 1)\\left(\\frac{y}{r}\\right)\\left(\\frac{a}{r}\\right)^{(n+2)} \\sum_{m=0}^{n} \\left\\{ P_n^m(\\cos{\\theta}) \\left[ g_n^m \\cos{(m\\phi)} + h_n^m \\sin{(m\\phi)}\\right] \\right\\}    \\nonumber \\\\\n\t\t\t\t&- a \\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{(n+1)} \\sum_{m=0}^{n} \\biggl\\{ \\left(\\frac{yz}{\\rho r^2}\\right)\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos{\\theta}) \\left[g_n^m \\cos{(m\\phi)} + h_n^m \\sin{(m\\phi)} \\right] \\nonumber \\\\\n\t\t\t\t&+ m\\frac{x}{\\rho^2} P_n^m(\\cos{\\theta}) \\left[ h_n^m \\cos{(m\\phi)} - g_n^m\\sin{(m\\phi)}\\right]  \\biggr\\} \\\\\n\t\t\t\tB_z = -\\frac{\\partial V}{\\partial z} &= \\sum_{n=1}^{n_{max}} (n + 1)\\left(\\frac{z}{r}\\right)\\left(\\frac{a}{r}\\right)^{(n+2)} \\sum_{m=0}^{n} \\left\\{ P_n^m(\\cos{\\theta}) \\left[ g_n^m \\cos{(m\\phi)} + h_n^m \\sin{(m\\phi)}\\right] \\right\\}    \\nonumber \\\\\n\t\t\t\t&- a \\sum_{n=1}^{n_{max}} \\left(\\frac{a}{r}\\right)^{(n+1)} \\sum_{m=0}^{n} \\biggl\\{ \\left(\\frac{\\rho}{ r^2}\\right)\\frac{\\text{d}}{\\text{d} \\theta} P_n^m(\\cos{\\theta}) \\left[g_n^m \\cos{(m\\phi)} + h_n^m \\sin{(m\\phi)} \\right]  \\biggr\\}.\t\t\t\t\n\t\t\t\\end{align}\n\t\t\t\n\\bibliographystyle{agufull08}\n\\bibliography{ref}\n\\end{document}\n", "meta": {"hexsha": "c653ded628e716edc0448c458db420e25ebc32ad", "size": 23015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/equations/equations.tex", "max_stars_repo_name": "mattkjames7/vip4model", "max_stars_repo_head_hexsha": "63f1fd0a566f2adcf93cdd424f5155fc62336ec3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-07T11:44:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T11:44:20.000Z", "max_issues_repo_path": "doc/equations/equations.tex", "max_issues_repo_name": "mattkjames7/vip4model", "max_issues_repo_head_hexsha": "63f1fd0a566f2adcf93cdd424f5155fc62336ec3", "max_issues_repo_licenses": ["MIT"], "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/equations/equations.tex", "max_forks_repo_name": "mattkjames7/vip4model", "max_forks_repo_head_hexsha": "63f1fd0a566f2adcf93cdd424f5155fc62336ec3", "max_forks_repo_licenses": ["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.9479166667, "max_line_length": 495, "alphanum_fraction": 0.5642841625, "num_tokens": 10455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6724742632820857}}
{"text": "\\documentclass{article}\n\\begin{document}\n\n\\section{From V\\&V by Oberkampf and Roy}\n\nvalidation metrics - mathematical operators that compute the difference between the experimentally measured results and the simulation results.  V\\&V in SC, pg 469 (See also page 473)\n\ntype 1 error: model builder's risk.  The error of rejecting the model when the model is actually correct (such as because of comparison with incorrect data) V\\&V in SC, pg 481\n\ntype 2 error: model user's risk.  The error of accepting validity of the model when the model is actually invalid.  V\\&V in SC, pg 482\n\n\nComparison of mean values.  V\\&V in SC, pg 485.  $L_1$ or $L_2$ vector norms usually used:\n\n\\begin{equation}\n  \\| S - E \\|_p = \\left(\\frac{1}{N}\\sum^N_{i=1} | S(x_i) - E(x_i)|^p \\right)^\\frac{1}{p}\n\\end{equation}\n\nComparison of mean with experimental mean and variance. V\\&V in SC, pg\n493-497.  The goal is to determine the true error based on $\\tilde{E}\n= y_m - \\bar{y}_e$ where $y_m$ is the computed value, $\\bar{y}_e$ is\nthe experimental mean and $\\tilde{E}$ is the estimated error.  The\nexperimental mean is:\n\n\\begin{equation}\n  \\bar{y}_e = \\frac{1}{n} \\sum^n_{i=1} y^i_e\n\\end{equation}\n\nThe sample standard deviations is:\n\n\\begin{equation}\n  s = \\left[ \\frac{1}{n-1} \\sum^n_{i=1} (y^i_e - \\bar{y}_e)^2 \\right ]^\\frac{1}{2}\n\\end{equation}\n\nThe interval containing the true error $E = y_m - \\mu$ where the level of confidence is $100(1-\\alpha)$\\% is:\n\n\\begin{equation}\n  \\left ( \\tilde{E}-t_{\\alpha/2,v}\\cdot\\frac{s}{\\sqrt{n}},\\tilde{E}+t_{\\alpha/2,v}\\cdot\\frac{s}{\\sqrt{n}}  \\right )\n\\end{equation}\n\nComparison of means using interpolation of experimental data. V\\&V in\nSC, pg 500-501.  If there are multiple sets of experimental data that\nrelate input variables to results, then the interpolation of the sets\ncan be used for statistics.  The standard deviation can be calculated\nas (where the sets of interpolated experimental data are $y^i_e(x)$):\n\n\\begin{equation}\n  s(x) \\sim \\left [ \\frac{1}{n-1} \\sum^n_{i=1}\\left ( y^i_e(x) - \\bar{y}_e(x) \\right ) ^2 \\right ] ^\\frac{1}{2}\n\\end{equation}\n\nThe true error is in the interval:\n\n\\begin{equation}\n  \\left ( \\tilde{E}(x)-t_{\\alpha/2,v}\\cdot\\frac{s(x)}{\\sqrt{n}},\\tilde{E}(x)+t_{\\alpha/2,v}\\cdot\\frac{s(x)}{\\sqrt{n}}  \\right )\n\\end{equation}\n\nI think this may not be very useful because of the number of\nassumptions required and the shear amount of data that is required to\nget enough $y^i_e$ values.\n\nComparison of means requiring linear regression of the experimental\ndata. V\\&V in SC, pg 508-510. This is where there are a set of $n$\nexperimental measurements $(y^i_e,x_i)$.\n\nThe linear regression function is:\n\n\\begin{equation}\n  \\bar{y}_e(x) = \\theta_1 + x\\theta_2+\\epsilon\n\\end{equation}\n\nThe estimate interval for the true mean is:\n\n\\begin{equation}\n  \\mu(x) \\sim (\\bar{y}(x) - SCI(x),\\bar{y}(x)+SCI(x))\n\\end{equation}\n\nWhere $SCI(x)$ is the width of the Scheff\\'e confidence interval as a function of $x$ and is:\n\n\\begin{equation}\n  SCI(x) = s\\sqrt{[2F(2,n-2,1-\\alpha)]\\left [ \\frac{1}{n}+\\frac{(x-\\bar{x})^2}{(n-1)s^2_x} \\right ] }\n\\end{equation}\n\n\\begin{equation}\n  s = \\sqrt{\\frac{1}{n-1}\\sum^n_{i=1}\\left [ y^i_e-\\bar{y}_e(x_i) \\right ]^2}\n\\end{equation}\n\\begin{equation}\n  \\bar{x} = \\frac{1}{n}\\sum^n_{i=1}x_i\n\\end{equation}\n\\begin{equation}\n  s^2_x=\\frac{1}{n-1}\\sum^n_{i=1}(x_i-\\bar{x})^2\n\\end{equation}\n\n\\section{From Talking with Cristian}\n\n%2015 March 31\n\nThe goal is to be able to tell if the sign of the correlation is\ncorrect.  So say that we have the output variables, and they match in\nprobability distribution.  It is still a problem if for example the\nmain cause of the probability change is input i, but in the\nexperiment, low i causes high output, but in the simulation low i\ncauses low output, that is, the sign of the correlation is wrong.\n\nThis should be similar to the formula used before, but now we have\n$P(ex | S)$ instead of just $P(ex)$.  This is the probability of ex\nconditional on S.  The probability of the simulation (s) is the\nresults of the input chosen, the input chosen is related to the\nexperimental reading via the correlation of the sensors in the\nexperiments.\n\n\\begin{equation}\n  \\int_{-\\infty}^{\\infty}dSP(S) \\int_{-\\infty}^{\\infty} dex(S-ex) P(ex | S)\n\\end{equation}\n\n\\section{Goals for 2015}\n\n\\begin{itemize}\n\\item Determine if the correlation between an input and output are the same in the experiment and in the calculated version. If the probability distributions are the same, is the same thing being calculated?\n\\item Look at the correlation between input and output.\n\\item Look at examining multiple figures of merit (distance measure?).  Especially if some of the output is correlated.\n\\item Look at the correlation between inputs.\n\\item (Optional)Look at time dependent analysis (fourier transforms and such.)\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "83ad07906a235e4225aa147991fcb18aceb02ebf", "size": 4837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/misc/comparison_stats/notes/notes.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/misc/comparison_stats/notes/notes.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/misc/comparison_stats/notes/notes.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": 38.3888888889, "max_line_length": 207, "alphanum_fraction": 0.713045276, "num_tokens": 1531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6724742608552342}}
{"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\\newcommand{\\pp}[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\\addtolength{\\textheight}{2em}\n\n\\begin{document}\n\t\n\\begin{center}\n  \\bf \n  Project: Wave goodbye\n\\end{center}\n\t\nWater waves have occupied mathematicians for centuries. Almost all of the interesting models are nonlinear. One of these is the \\emph{KdV equation},\n\\begin{equation}\n\\label{eq:KdV}\nu_t + 6uu_x + u_{xxx} = 0.\n\\end{equation}\nUnlike the linear advection equation, most solutions of~\\eqref{eq:KdV} do not propagate unchanged. However, there are so-called \\emph{soliton} solutions that do hold their shape as they move. The soliton solutions are\n\\begin{equation}\n\\label{eq:soliton}\n   s(x,t;c) = \\frac{c}{2} \\operatorname{sech}^2 \\left(  \\frac{\\sqrt{c}}{2}(x-ct) \\right),\n\\end{equation}\nwhere $c>0$ is the constant velocity. Solitons can be experimentally observed under the right conditions. They have an odd property: if a faster soliton overtakes a smaller one, they pass through each other with unchanged shapes, but the path of each soliton undergoes a shift; i.e., the solution $s(x,t;c)$ becomes $s(x-\\xi,t;c)$ after the interaction. \n\nIf equation~\\eqref{eq:KdV} is linearized about the soliton solution $s$, the perturbation $w$ is governed by\n\\begin{equation}\n\\label{eq:KdVlin}\n  w_t = -6 ( s w_x + s_x w) - w_{xxx},\n\\end{equation}\nwhich discretizes in $m$ points to \n\\newcommand{\\bfs}{\\mathbf{s}}\n\\begin{equation}\n\\label{eq:KdVlin-disc}\n  \\bfw'(t) = \\bigl[ -6 \\diag(\\bfs)\\mD_x -6 \\diag(\\mD_x\\bfs) -\\mD_{xxx} \\bigr]\\, \\bfw = \\mA\\bfw,\n\\end{equation}\nwhere $\\bfs$ is the spatial discretization of $s(x,t;c)$ at a fixed time $t_*$. As usual, the eigenvalues of the Jacobian matrix in this equation govern time step restrictions due to absolute stability. The presence of the third derivative makes this problem quite stiff in general.\n\nAnother, more easily generalized model of waves is provided by the \\emph{shallow water equations}, \n\\begin{equation}\n\\label{eq:shallow}\n  \\begin{split}\n    h_t + \\pp{}{x} \\bigl( (h-\\delta) u  \\bigr) + \\pp{}{y} \\bigl( (h-\\delta) v  \\bigr) &= 0 \\\\\n    u_t + u u_x + vu_y &= -h_x - \\epsilon u \\\\\n    v_t + uv_x + vv_y &= -h_y - \\epsilon v,\n  \\end{split}\n\\end{equation}\nwhere $h(x,y,t)$ is the height of water above a neutral $z=0$ plane, $u(x,y,t)$ and $v(x,y,t)$ are the $x$-velocity and $y$-velocity of a particle on the surface of the water, and $\\delta(x,y)<0$ describes the depth of the solid bed underneath the surface. The terms with $\\epsilon$ represent frictional loss; and are often set to zero in theoretical work. As far as I know, the shallow water equations don't have pretty solutions like those of KdV.\n\n\n\n\\subsection*{Project assignment}\n\\label{sec:project-assignment}\n\nYou should submit only M-files. Five of them are required to produce output as described in detail below. \\textbf{Each of these scripts should start with the line}\n\\begin{verbatim}\n    close all, clear all\n\\end{verbatim}\nWhile you may use book functions and other codes written for the class as guides, none of them will completely address any of the problems. You may also include as many other M-files as are needed to make the scripts run. In your submission, \\textbf{include all other files needed, including those from the book.} You can locate all dependencies by entering, for example,\n\\begin{verbatim}\n    matlab.codetools.requiredFilesAndProducts('p1')\n\\end{verbatim}\n\n\\textbf{If a script does not run  successfully, you may receive no credit on that part of the assignment. If any code is found to be plagiarized from the internet or another student, you may receive a zero on the entire assignment.}\n\n\\begin{enumerate}\n\\item Let equation~\\eqref{eq:KdV} by posed over $-20<x<20$ with periodic end conditions. Using $m=300$ points and the initial condition $s(x,0;1)$ from~\\eqref{eq:soliton}, compute the solution for $0\\le t \\le 10$. (Remember that the MATLAB IVP solvers allow you to request output at particular times; see the documentation.)\n\\begin{description}\n    \\item[p1.m] This script produces two separate figures. One shows the numerical solution as a function of $x$ at $t=0,2,4,6,8,10$. The other shows the difference between the numerical solution and the exact solution, as a function of $x$, for $t=0,2,4,6,8,10$.\n\\end{description}\n\\item Continuing with the setup in step 1, find the matrix $\\mA$ of the linearization equation~\\eqref{eq:KdVlin-disc} about the solution $s(x,0;1)$. \n\\begin{description}\n    \\item[p2.m] This script makes a plot of the eigenvalues of $\\mA$ in the complex plane. Don't forget to use \\texttt{axis}~\\texttt{equal}!\n\\end{description} \n\\item Look up the stability region of the 4th order R-K method in Figure~12.5. The intersections of the region with the coordinate axes are at the origin, $-2\\sqrt{2}+0i$, and $\\pm2\\sqrt{2}i$. Use this information, compute an upper bound for the time step in RK4. Then apply \\texttt{ode45} to solve the problem (same conditions as in step~1), and find the maximum step size taken by the solver. (If it is larger than your upper bound, you did something wrong.) \n\\begin{description}\n    \\item[p3.m] This script prints out the upper bound and the observed maximum step size.\n\\end{description}\n\\item Still with $-20<x<20$, periodic end conditions, $m=300$, and $0\\le t \\le 10$, compute the numerical solution with initial condition $s(x,0;1) + s(x+8,0;2)$ at 81 equally spaced times in $[0,10]$ (including $t=0$ and $t=10$). You should be able to see clearly that the faster soliton overtakes the slower one, leaving them both shifted sideways from their original paths. \n\\begin{description}\n    \\item[p4.m] This script makes a \\texttt{pcolor} plot showing the numerical solution as a function of $x$ and $t$. \n\\end{description}\n\\item Let the shallow water equations~\\eqref{eq:shallow} be posed over $(x,y) \\in [-8,8]\\times[-4,4]$ and subject to periodicity in both coordinates. Let the depth function be\n  \\begin{equation*}\n    \\delta(x,y) = -2 + 1.75 \\exp[-2(x-4)^2-2y^2],\n  \\end{equation*}\ncorresponding to a flat surface with a tall bump at $(4,0)$, and let $\\epsilon=0.05$. Use $m=n=100$ points in space and let the initial conditions be $h(x,y,0)=\\exp(-x^2/2)$, $u(x,y,0)=0$, and $v(x,y,0)=0$. Simulate for 100 equally spaced times between $t=0$ and $t=10$ (I recommend a nonstiff IVP solver). You should see the original bump split into two waves. The waves aren't perfect, though---they shed little waves behind them as they go. Each of the two main waves will interact with the bump as they flow past the line $x=4$.\n\\begin{description}\n\\item[p5.m] This script should generate an animated GIF of a \\texttt{surf} or \\texttt{pcolor} plot of $h(x,y,t)$ for the 100 times in your numerical solution. You will want a separate function file to define the ODE to be solved, so include that file too. \n\\end{description}\n\n\\end{enumerate}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "6207b9e668ed2a3fe82929d1db6fc54fbdc18c23", "size": 7075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/waterwaves/waterwaves.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/waterwaves/waterwaves.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/waterwaves/waterwaves.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": 66.1214953271, "max_line_length": 532, "alphanum_fraction": 0.7331448763, "num_tokens": 2092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.897695292107347, "lm_q1q2_score": 0.672452074647806}}
{"text": "\\chapter{Neural Networks overview}\n\\label{appendix:neuralNetworks}\nWe provide an overview of the main concepts and techniques relating to Neural Networks as are \nimportant for this work. Section~\\ref{appendix:neuralNetworks/fundamentals} and~\\ref{appendix:neuralNetworks/rnn} \nare based on Graves~\\cite{seqlab:Graves2012-385} work description for Supervised Sequence \nLabeling with Recurrent Networks and Section~\\ref{appendix:neuralNetworks/cnn} is based \non~\\cite{appendix:OSheaN15}.\n\n\\section{Neural Networks Fundamentals}\n\\label{appendix:neuralNetworks/fundamentals}\nArtificial Neural Networks (ANNs), or simply Neural Networks (NNs), are mathematical models \ninspired by how biological brains process information. Their basic structure is a network of \nsmall processing units, also seen as nodes, joined to each other by weighted connections. \nSimilar to how synapses work in biological neurons, the network is activated by providing an \ninput to some or all nodes, which spreads this activation throughout the rest of the network \nalong the weighted connections.\n\n\\subsection{Multilayer Perceptrons}\n\\label{appendix:neuralNetworks/fundamentals/mlp}\nAmong the different varieties of neural networks, \\textbf{Feedforward Neural Networks} are \nstructured in an acyclic way, meaning their connections do not form a cycle. One example are \nthe multilayer perceptrons (MLP), which are arranged in layers with connections feeding \nforward from one layer to the next. An illustration can be seen in Figure~\\ref{fig:multilayerPerceptron}, \nwhere input data are passed to an \\textbf{input layer} and then propagated through one or more \n\\textbf{hidden layers} to the final \\textbf{output layer}. This kind of architecture is more \nsuitable for classification or function approximation tasks~\\cite{seqlab:Graves2012-385}.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics[scale=.45]{imagenes/appendices/appendix_a/mlpModel.PNG}\n    \\caption{Multilayer perceptron~\\cite{seqlab:Graves2012-385}.}\n    \\label{fig:multilayerPerceptron}\n\\end{figure}\n\nThe process to pass data through layers is known as the \\textbf{forward pass} of the network. \nGiven an input vector of length $I$, an input layer of the same length would receive this \ninput vector where each unit in the input layer calculates a weighted sum. For a hidden unit \n$h$, we refer to this sum as the network input to unit $h$, denoted as $a_h$. Denoting $w_{ij}$ \nas the weight from unit $i$ to unit $j$, the formula of $a_h$ for a layer $H_{l}$ is calculated \nusing the formula in Equation~\\ref{eq:hiddenState}.\n\n\\begin{equation} \\label{eq:hiddenState}\n    a_h = \\sum_{h' \\in H_{l-1}}^I w_{h'h} \\; b_{h'}\n\\end{equation}\n\nwhere $b_{h'}$ corresponds to the final activation function of the previous layer. The $b_h$ \nvalue is calculated by applying an activation function $\\theta_h$ over $a_h$, as seen in \nEquation~\\ref{eq:finalActivation}. Note that for the first hidden layer, the previous layer \nis the input layer.\n\n\\begin{equation} \\label{eq:finalActivation}\n    b_h = \\theta_h(a_h)\n\\end{equation}\n\nThis activation function $h$ can vary, though some of the most common functions used are the \nhyperbolic tangent~\\ref{eq:tanh} or sigmoid~\\ref{eq:sigmoid} functions. Two important features \nabout activation functions: they are non-linear and differentiable. Non-linearity allows the \nnetwork to build more complex internal features (e.g. build more flexible boundaries in a \nclassification task), and differentiability is required to perform the backward pass that \nwill be mentioned below.\n\n\\begin{equation} \\label{eq:tanh}\n    tanh(x) = \\frac{e^{2x}-1}{e^{2x}+1}\n\\end{equation}\n\\begin{equation} \\label{eq:sigmoid}\n    sigmoid(x) = \\frac{1}{1+e^{-x}}\n\\end{equation}\n\nThis process of summation and activation is repeated for $L$ hidden layers until reaching the \noutput layer, where the output vector $y$ is determined by using the activation of the last \nhidden layer $H_L$. Then, the network input $a_k$ to each output unit $k$ is calculated by \nsumming over the units of the connected to it, the same way as is expressed in Equation~\\ref{eq:hiddenState}. \nThe output activation function to be used depends on the task the network aims to fulfill. \nFor simple binary classification, the sigmoid function~\\ref{eq:sigmoid} is applied since its \nvalues between 0 or 1 can be seen as a binary probability $p(z|x)$, with $z$ being the target \nvector. Furthermore, if the classification task includes more than 2 classes, there is a \nconvention to have $K$ output units, and normalize the output activations with the softmax \nfunction~\\ref{eq:softmax}. Therefore, the class probability for $C_k$ given the output $x$ is \nrepresented by Equation 5\n\n\\begin{align} \\label{eq:softmax}\n    p(C_k|x) & = y_k \\nonumber \\\\\n        & = softmax(a_k) \\nonumber \\\\ \n        & = \\frac{e^{a_k}}{\\sum_{k'=1}^K e^{a_{k'}}}\n\\end{align}\n\nLastly, a 1-to-K scheme is used to represent the target class $z$ where $z$ is represented as \na one-hot vector (e.g. if $K=4$, the class $C2$ is represented as $[0, \\; 1, \\; 0, \\; 0]$). \nMore formally, the way to express the target probabilities are as follows:\n\n\\[\n    p(z|x) = \\prod_{k=1}^K y_k^{z_k}\n\\]\n\nIn the context of pattern classification, the class label that should be chosen corresponds to \nthe most active output unit, i.e. the higher value from all target probabilities.\n\n\\subsection{Network Training}\n\\label{appendix:neuralNetworks/fundamentals/training}\nIn order to have an idea whether a neural network is working as expected, a loss function is \nused. As per activation functions, the loss function to be used depends on the task the Neural \nNetwork is performing.  For example, for multiple classification the maximum-likelihood function \nis commonly used as a loss function~\\cite{appendix:bishop1995neural}:\n\n\\[\n    L(y_k, z) = \\sum_{k=1}^K z_k ln \\; y_k\n\\]\n\nNeural networks are able to learn, i.e. they can generalize to unseen data, so they can be \ntrained by minimizing the loss function $L$. One of the simplest algorithms to perform such \ntraining process is the \\textit{gradient descent} algorithm. \\text{Gradient descent} consists \nof repeatedly taking a small, fixed-size step in the direction of the negative error gradient \nof the loss function, which can also be seen as going in the opposite direction of the \nnegative slope of the loss function. Note that we perform gradient descent over a training \ndataset, while we save a test dataset that is not used to train but to evaluate the overall \nperformance after training.\n\nThus, a weight update $\\Delta w^n$, also known as gradient , is used to update the weight \nvector $w^n$ from the $n^{th}$ network layer. The gradient $\\Delta w^n$ consists of the \npartial derivative of the loss function when the weight vector $w^n$ varies. This derivative \nis adjusted by a \\textbf{learning rate} $\\alpha \\in [0, 1]$ which limits how quick the training process \nis converging. Then, on each gradient descent iteration $i$ the weight vector $w^n$ is updated as \nfollows:\n\n\\[\n    w_{i}^n = w_{i-1}^n - \\Delta w_{i-1}^n = w_{i-1}^n - \\alpha \\frac{\\partial L}{\\partial w_{i-1}^n}\n\\]\n\nThe backpropagation technique is commonly used to calculate these \ngradients~\\cite{appendix:rumelhart1985learning, appendix:williams1995gradient, appendix:werbos1988generalization}, \noften referred to as the \\textbf{backward pass} of the network. Backpropagation consists of \nthe repeated application of chain rule for partial derivatives. For example, for a multiclass \nnetwork, the application of the chain rule over the loss function defined as \n$\\frac{\\partial L(x, z)}{\\partial w_{ij}} = \\frac{\\partial L(x, z)}{\\partial a_j} \\frac{\\partial a_j}{w_{ij}}$, \nwhich then can be deduced by applying the chain rule again over the unknown gradients. \nNote that this process has to be performed over every weight of each layer on the network.\n\nThe training algorithm is repeated until a \\textbf{stopping criteria} is met (e.g. stop after \na fixed amount of steps, when reaching a certain loss threshold, or when failing to reduce the \nloss on a given number of consecutive steps). Usually, this process involves using the entire \ntraining data more than one time, where an entire pass over the data is known as one \\textbf{epoch}. \nBy the end of the training process, we expect to have the neural network’s weights such that \nthe loss function has reached a value as close as possible to the global minimum when \nevaluating over test examples (i.e. it can predict as best as possible over the training data).\n\nThe training process involves many issues that can lead to bad performance, a long time to \ntrain models, or divergence problems (i.e. training process never ends). One common issue is \nwhen the gradient descent process gets stuck in local minimums, which can be addressed by \nadding a momentum term to reduce learning inertia~\\cite{appendix:plaut1986experiments}. To \nboost training time, many variants of gradient descent have been proposed such as stochastic \ngradient descent or mini-batch gradient descent~\\cite{appendix:lecun1998efficient}.\n\nAnother issue related with bad performance is \\textbf{overfitting}, which causes the network \nnot to be able to generalise properly since it \\dquotesit{memorizes} the data from the training \ndataset. One way to see if a model is overfitted is to check the loss function values \nevolution over the training process for the training and the test set: if the loss for the \ntest is not decreasing but instead increasing while the loss for the training set is \nconstantly decreasing, the model is getting overfitted.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics[scale=.45]{imagenes/appendices/appA_overfitting.PNG}\n    \\caption{Example of early stopping analysis using validation data~\\cite{seqlab:Graves2012-385}.}\n    \\label{fig:earlyStopppingExample}\n\\end{figure}\n\nOne solution that helps to address the overfitting issue is to use a small portion of the \ntraining set as a validation set to include an \\textbf{early stopping criteria}. This \nvalidation set is not used to train the network but to perform validation steps every certain \namount of training steps. Then, the loss values for the validation steps are used to decide \nwhen to stop training. For example, Figure~\\ref{fig:earlyStopppingExample} shows the losses \nover all three data sets (train, validation, test) through the training process. Then, we can \ndetect that the best weight values are found just before the validation loss stops its \ndecreasing tendency and starts increasing again (where the \\dquotes{best} stripped vertical line is \nplaced). There are other techniques to reduce overfitting known as regularizers based on \ninput noise~\\cite{appendix:an1996effects, appendix:koistinen1991kernel, appendix:bishop1995neural} \nor weight noise~\\cite{appendix:murray1994enhanced,appendix:jim1996analysis}.\n\nThough most of the performance of ANNs relies on learnable parameters (such as layers’ weights), \nthere are other parameters that can be set manually to improve the model’s performance, also \nknown as \\textbf{hyperparameters}. Some hyperparameters could be the number of hidden layers, \nthe number of hidden units per layer, the learning rate, among others.\n\nLastly, it is also important to understand how the network input is represented. When we \nmention the \\textbf{input representation}, we refer to the representation of the information \nrequired to predict the outputs, such as the input vector or the network weights. One \nprocedure is input standardisation, which consists of normalizing the components of the input \nvectors to have mean 0 and standard deviation 1 over the training set. This standardization \ndoes not alter the information but helps to improve performance by limiting the values of the \ninput vector to a more suitable range for a standard activation function~\\cite{appendix:lecun1998efficient}. \nNote that the validation set and test set have to be standardised using the same distribution \nused for the training set. \n\nAnother procedure is \\textbf{weight initialisation}, which helps gradient descent to \n\\dquotes{break symmetry} between units~\\cite{appendix:lecun1998efficient} and avoid training \ndivergence. Weight initialisation then is to initialise weights with either a random \ndistribution in the range of small values or a Gaussian distribution with mean 0 and \nstandard deviation 0.1.\n\nAfter reviewing the fundamental concepts needed to understand how neural networks are \nstructured and trained, we will review two neural networks architectures used in this work: \nRecurrent Neural Networks and Convolutional Neural Networks.\n\n\\section{Recurrent Neural Networks}\n\\label{appendix:neuralNetworks/rnn}\nA Recurrent Neural Network (RNN) is a generalization of traditional feedforward Neural \nNetworks that allows cyclical connections~\\cite{seqlab:Graves2012-385}. While MLPs can only \nmap from input to output vectors, RNNs can map the entire history of previous inputs to an \noutput. Hence, RNN connections allow the network to have \\dquotes{memory} of previous inputs, thus \ninfluencing the network output. Furthermore, RNNs are more fit for tasks involving sequence \ndata, such as text or audio. An example of a RNN architecture can be seen in Figure~\\ref{fig:recurrentNN}.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics[scale=.45]{imagenes/appendices/appendix_a/rnnModel.PNG}\n    \\caption{Recurrent Neural Network architecture example~\\cite{seqlab:Graves2012-385} .}\n    \\label{fig:recurrentNN}\n\\end{figure}\n\nA standard RNN computes the \\textbf{forward pass} the same way as an MLP with a single hidden \nlayer, with the difference that the activations arrive at the hidden layer from both the \ncurrent external input and the hidden layer activations from the previous time step. Given a \nsequence of inputs $(x_1,\\ldots,x_T)$, with $T$ the input length, the forward pass for an RNN \nwith $I$ input units and $H$ hidden units is computed using the following formula:\n\n\\begin{equation} \\label{eq:hiddenStateRNN}\n    a_h^t = \\sum_{i=1}^I w_{ih} \\; x_i^t + \\sum_{h'=1}^H w_{h'h} \\; b_{h'}^{t-1}\t\n\\end{equation}\n\nwhere $x_i^t$ denotes the value of input $i$, $a_j^t$ is the network input to unit $j$, and \n$b_j^t$ is the activation unit of unit $j$, all three at time t. Then, the non-linearity $h$ \nis applied the same way as for an MLP, where functions such as the sigmoid function or \nsoftmax function are again a common choice:\n\n\\begin{equation} \\label{eq:activationRNN}\n    b_h^t = \\theta_h(a_h^t)\n\\end{equation}\n\nThe entire learning process for RNNs is then summarized as a recursive application of the \nEquations~\\ref{eq:hiddenStateRNN} and~\\ref{eq:activationRNN}, starting at $t=1$. Since \ninitial values $b_i^0$ are needed, they can be initialized using the same weight \ninitialization methods mentioned above. The output units $a_k$ can be calculated at the same way \nas the hidden activations:\n\n\\begin{equation} \\label{eq:outputStateRNN}\n    a_k^t = \\sum_{h=1}^H w_{hk} \\; b_{h}^{t}\t\n\\end{equation}\n\nThen, the final activation function also depends on the task involved. For connection \ntemporal classification (CTC) tasks, such as sequence labeling or translation, it is common \nto use the softmax function~\\cite{appendix:graves2006connectionist}. The CTC loss function is \nused, that is defined as the negative log probability of correctly labelling all examples in \nthe training set.\n\nThe \\textbf{backward pass} can be performed using a backpropagation through time (BPTT) \nalgorithm~\\cite{appendix:williams1995gradient, semPar:werbos1990}, which is an algorithm \nbased on the standard backpropagation process but adapted to RNNs. The BPTT algorithm also \nconsists of a repeated application of the chain rule, with the difference that, aside from \nthe output layer, the loss function also depends on the activation of the hidden layer \nthrough its influence on the hidden layer at the next timestep. The derivatives can be \ncalculated using the same procedure described in the \\textit{Network Training} subsection\\ref{appendix:neuralNetworks/fundamentals/training}, \nbut taking into consideration that the same weights are being reused at every timestep.\n\nSince the classical RNN architecture only looks to past information, the \\textbf{Bidirectional \nRecurrent Neural Network} (BRNN) was proposed to also include future \ncontext~\\cite{appendix:SchusterP97}. The BRNN’s structure consists of two separate recurrent \nhidden layers, both connected to the same output layer. This idea allows a forwards and \nbackwards training sequence, where the layer that performs the backward training receives the \ninput sequence in the opposite direction. The output layer is not updated until both hidden \nlayers have processed the entire input sequence.\n\n\\subsection{Long Short-Term Memory}\n\\label{appendix:neuralNetworks/rnn/lstm}\nThough RNNs work well with short sentences, their performance decreases with long sentences \nthat involve long term dependencies due to the \\textbf{vanishing gradient} \nproblem~\\cite{seqlab:HochreiterS97, appendix:hochreiter2001gradient}, which occurs when the \ninfluence of the given input on the hidden layer (and therefore on the network output), \neither decays or explodes exponentially through the recurrent connections. In order to \naddress this issue, the \\textbf{Long Short-Term Memory} (LSTM) model~\\cite{seqlab:HochreiterS97} \nwas proposed. The LSTM model allows models to perform well on tasks which require long range \ntemporal dependencies, such as Sequence Labeling~\\cite{seqlab:HuangXY15, seqlab:MaH16}, \nMachine Translation~\\cite{nlToSparql:WuSCLNMKCGMKSJL16} or Summarization~\\cite{appendix:MahasseniLT17}. \nAs per RNNs, the LSTM also has a bidirectional variant, also known as \nBiLSTM~\\cite{appendix:graves2005framewise,appendix:ChenC04a,appendix:ThireouR07}. \n\nAn LSTM network is similar to a standard RNN, except that the summations units in the hidden \nlayer are replaced by \\textbf{memory blocks}, as shown in Figure~\\ref{fig:oneCellLSTM}. This \nstructure allows the memory cells to store and access information over long periods of time, \nthereby reducing the effects of the vanishing gradient problem.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics[scale=.45]{imagenes/appendices/appendix_a/lstmModel.PNG}\n    \\caption{LSTM memory block with one cell~\\cite{seqlab:Graves2012-385}.}\n    \\label{fig:oneCellLSTM}\n\\end{figure}\n\nThe following equations presented below are the formulas used to perform the forward pass \nevaluation over an LSTM with a single memory block for a timestep $t$. For multiple blocks \nthe computations are repeated for each block. The values of $w_{ij}$, $a_j^t$ and $b_j^t$ \nhave the same definition used before. \n\nFirst, the \\textbf{Input Gates}, denoted as $a_\\iota^t$~\\ref{eq:inputHidden} and \n$b_\\iota^t$~\\ref{eq:inputActivation}. The number of inputs \nis denoted by $I$, the number of cells in the hidden layer is $H$ and the number of memory \ncells is $C$. The gate activation function $f$ most commonly used is the sigmoid function, so \nthe gate activations are between 0 (gate closed) and 1 (gate open). The weight $w_{c\\iota}$ \nrepresents the peephole weight from cell $c$ to the input gate. The state of the cell $c$ at \ntime $t$ is denoted as $s_c^t$, which is calculated using Equation~\\ref{eq:cellActivation}.\n\n\\begin{equation} \\label{eq:inputHidden}\n    a_\\iota^t = \\sum_{i=1}^I w_{i\\iota} \\; x_i^t + \\sum_{h=1}^H w_{h\\iota} \\; b_h^{t-1} + \\sum_{c=1}^C w_{c\\iota} \\; s_c^{t-1}\n\\end{equation}\n\\begin{equation} \\label{eq:inputActivation}\n    b_\\iota^t = f(a_\\iota^t)\n\\end{equation}\n\nThen, the \\textbf{Forget Gates}, denoted as $a_\\phi^t$~\\ref{eq:forgetHidden} and \n$b_\\phi^t$~\\ref{eq:forgetActivation}. The weight $w_{c\\phi}$ represents the peephole weight \nfrom cell $c$ to the forget gate. Besides that, other symbols are equivalent to those \nmentioned for the input gate.\n\n\\begin{equation} \\label{eq:forgetHidden}\n    a_\\phi^t = \\sum_{i=1}^I w_{i\\phi} \\; x_i^t + \\sum_{h=1}^H w_{h\\phi} \\; b_h^{t-1} + \\sum_{c=1}^C w_{c\\phi} \\; s_c^{t-1}\n\\end{equation}\n\\begin{equation} \\label{eq:forgetActivation}\n    b_\\phi^t = f(a_\\phi^t)\n\\end{equation}\n\nThe \\textbf{Cells}, denoted as $a_c^t$~\\ref{eq:cellHidden} and $s_c^t$~\\ref{eq:cellActivation}. The \ncell input activation function $g$ is usually hyperbolic tangent or sigmoid.\n\n\\begin{equation} \\label{eq:cellHidden}\n    a_c^t = \\sum_{i=1}^I w_{ic} \\; x_i^t + \\sum_{h=1}^H w_{hc} \\; b_h^{t-1}\n\\end{equation}\n\\begin{equation} \\label{eq:cellActivation}\n    s_c^t = b_\\phi^t \\; s_c^{t-1} + b_\\iota^t \\; g(a_c^t)\n\\end{equation}\n\nNext, the \\textbf{Outputs Gates}, denoted as $a_\\omega^t$~\\ref{eq:outputHidden} and \n$b_\\omega^t$~\\ref{eq:outputActivation}. The weight $w_{c\\omega}$ represent the peephole w\neight from cell $c$ to the output gate.\n\n\\begin{equation} \\label{eq:outputHidden}\n    a_\\omega^t = \\sum_{i=1}^I w_{i\\omega} \\; x_i^t + \\sum_{h=1}^H w_{h\\omega} \\; b_h^{t-1} + \\sum_{c=1}^C w_{c\\omega} \\; s_c^{t-1}\n\\end{equation}\n\\begin{equation} \\label{eq:outputActivation}\n    b_\\omega^t = f(a_\\omega^t)\n\\end{equation}\n\nFinally, the \\textbf{Cell Outputs}, denoted as $b_c^t$~\\ref{eq:cellOutput}. The cells outputs $b_c^t$ \nare the only ones connected to the other blocks in the layer. The index h is used to refer \nto cell outputs from other blocks in the hidden layer, if they exist. As per $g$, the output \nactivation function $h$ is usually hyperbolic tangent or sigmoid, though sometimes the \nidentity function can be used. \n\n\\begin{equation} \\label{eq:cellOutput}\n    b_c^t = b_\\omega^t \\; f(s_c^t)\n\\end{equation}\n\n\n\\section{Convolutional Neural Networks}\n\\label{appendix:neuralNetworks/cnn}\nThe creation of \\textbf{Convolutional Neural Networks} (CNNs) responds to the need to process \ncertain types of data: images~\\cite{appendix:OSheaN15}. Traditional ANNs do not perform well \nwhen processing images since its architecture does not properly support the computational \ncomplexity that involves processing large images as input. Whereas a 32$\\times$32 image will \nbe no problem to a traditional ANN, since it will require only 1024 parameters for a single \nneuron, images tend to have more resolution. On a higher scale, an image of 1024$\\times$1024 \nwill instead require 1,048,576 parameters, which is a substantial increase. Moreover, if we \nconsider colored images (RGB), a 1024$\\times$1024 RGB image would require 3,145,728 \nparameters. There is then a noticeable drawback of using standard feed-forward models where \nnodes are often connected to each node from the previous layer.\n\nConvolutional Neural Networks share many similarities with standard ANNs in the way that both \nare composed of a set of neurons that are capable of learning, where each neuron receives an \ninput and performs many operations, which commonly is a scalar product followed by an \nactivation function. The difference resides in that CNNs are based on the idea that the input \nis shaped as an image. This idea allows the CNN architecture to adapt to this specific type \nof data. Then, a CNN architecture is built using three different types of layers: \nconvolutional layers, pooling layers and fully-connected layers (same layers used in \ntraditional ANNs). Additionally, each layer is organised into three dimensions: the spatial \ndimension (width and height) and the number of channels (also known as depth, which is not \nthe same as the number of layers). An example of a CNN architecture for pattern image \nclassification is shown in Figure~\\ref{fig:convNet}.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics[scale=.45]{imagenes/appendices/appendix_a/cnnModel.PNG}\n    \\caption{Convolutional Neural Network for pattern image classification~\\cite{appendix:OSheaN15}.}\n    \\label{fig:convNet}\n\\end{figure}\n\n\\subsection{Convolutional layer}\n\\label{appendix:neuralNetworks/cnn/convLayer}\nA \\textbf{convolution layer} is the central component of CNNs, which determines the output of \nneurons using calculations based on local regions of the input. This type of layer is based on \nlearnable kernels, which define local convolution operations over the input vector. A \nconvolution consists of the scalar product for each value in a kernel of dimension M$\\times$N \nover a local region with the same size as the kernel used:\n\n\\begin{equation} \\label{eq:convolution}\n    (X \\ast w)_{i, j} = \\sum_{m=1}^M \\sum_{n=1}^{N} X_{m, n} \\cdot w_{i-m, j-n}\n\\end{equation}\n\nFor example, in Figure~\\ref{fig:convolutionPoolingExample} the convolution is being applied \nover a 3$\\times$3 pooled vector, which is the size of the kernel $w$, that is, the local \nregion of the entire input vector $X$. Though these kernels usually have a small spatial \ndimensionality, they are spread along the whole input vector. Besides kernel dimension, an \napplication of padding over the input vector is also possible, which is the process of \npadding the border of the input with zeros. \\textbf{Padding} controls both the dimensionality \nof the output volumes and gives more relevance to the input borders. Lastly, the \n\\textbf{stride} is the amount of spaces the kernel is moved between each convolution. By \nsetting a stride greater than 1, it is possible to reduce the amount of overlap and thus \nreduce the dimension of the activation output.\n\n\\begin{figure}[!h]\n    \\centering\n    \\includegraphics[scale=.45]{imagenes/appendices/appendix_a/convolution.PNG}\n    \\caption{Convolution operation example~\\cite{appendix:OSheaN15}.}\n    \\label{fig:convolutionPoolingExample}\n\\end{figure}\n\nLet $N$ be the size of a input vector of size N$\\times$N, $F$ the kernel F$\\times$F dimension, \n$P$ the padding size, and $S$ the stride value; the final dimension of the output volume will \nbe $\\left\\lfloor \\frac{N - F + 2P}{S} + 1 \\right\\rfloor$. Note that, in the same way an image can be \nrepresented in 3 dimensions, the kernel can be extended to a third dimension by increasing \nthe \\textbf{number of channels}, thus giving control over the output depth of the \nconvolutional layer. The number of channels, stride and padding are hyperparameters that can \nbe optimized. \n\nKernel values are the trainable parameters which a CNN can tune through the same type \nof learning process ANNs perform. The composition of convolutional layers allows to reduce the \ndimensionality of a Neural Network in terms of learnable parameters, based on the assumption \nof parameter sharing. This assumption says that \\dquotesit{if one region is useful to compute at \na set spatial region, then it is likely to be useful in another region}. The constraints of \neach activation within the output volume to the same weights and bias means a significant \ndecrease in the number of parameters used in a convolution layer. Then, the backward pass for \neach neuron in the output represents the overall gradient across channels, where only a \nsingle set of weights is updated.\n\nAfter the application of the convolution, an activation function is applied over the output \nvolume. The most common choice is the rectified linear unit (ReLu) which is an elementwise \nfunction that given a certain threshold $\\alpha$ will set all values less than $\\alpha$ to 0 .\n\n\\subsection{Pooling layer}\n\\label{appendix:neuralNetworks/cnn/poolLayer}\nA pooling layer aims to reduce the volume of an input representation with the purposes of \nreducing the computational complexity of the model. After each activation from a convolutional \nlayer, a pooling layer can be applied to scale its dimensionality through a reducing function. \nThe most common type of pooling is the max-pooling layer, which is a kernel that applies a \nMAX reduction on a local region as per a convolutional kernel. Other examples are average \npooling, or general pooling that applies average reduction and $L_1$/$L_2$ normalization \nrespectively.\n\nThough pooling layers also include settings such as kernel size, stride or number of channels, \nthey do not add learnable parameters. However, they do influence the backward pass to \ncalculate the gradients. Lastly, it is recommended to keep a low stride and kernel size since \nits application could negatively affect performance if large values are used.\n\n\\subsection{Common architectures}\n\\label{appendix:neuralNetworks/cnn/architectures}\nAs mentioned before, a CNN architecture is commonly built with an input layer, which receives \nthe values of the image, followed by various stacked convolutional layers, each one followed \nby pooling layers, and a final stack of fully-connected layers. However, defining exactly the \namount of layers to use is not a simple task. In fact, most of the literature is based on \nstandard architectures that have shown good results on certain image processing tasks.\n\nAmong the most popular architectures, ImageNet~\\cite{appendix:KrizhevskySH12} is a Deep \nConvolutional Network with five convolutional layers, some followed by max-pooling layers, \nfollowed by two fully-connected layers. Another example is ResNet~\\cite{appendix:HeZRS16}, \nwhich includes \\textbf{residual connections} that aim to reduce the vanishing gradient \nproblem that a very dense convolutional network can suffer. The main principle of residual \nconnections is to create connections between non-adjacent layers that skip a certain \namount of layers.", "meta": {"hexsha": "91c104a9d59bb6deafd724246c4244a5c5791c61", "size": 29253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/appendix_A.tex", "max_stars_repo_name": "ddiomedi2906/tesis-latex", "max_stars_repo_head_hexsha": "95597b1601b1277e3275b2581f50687ae999fab5", "max_stars_repo_licenses": ["MIT"], "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/appendix_A.tex", "max_issues_repo_name": "ddiomedi2906/tesis-latex", "max_issues_repo_head_hexsha": "95597b1601b1277e3275b2581f50687ae999fab5", "max_issues_repo_licenses": ["MIT"], "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/appendix_A.tex", "max_forks_repo_name": "ddiomedi2906/tesis-latex", "max_forks_repo_head_hexsha": "95597b1601b1277e3275b2581f50687ae999fab5", "max_forks_repo_licenses": ["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.5852631579, "max_line_length": 142, "alphanum_fraction": 0.7760571565, "num_tokens": 7559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.672452068691406}}
{"text": "%!TEX root = RBM.tex\n\n\\subsubsection{Rao-Blackwellized Tempered Sampling\\protect\\footnote{Available at \\protect\\url{https://github.com/lzhbrian/MCMC/blob/master/src/partition/RTS.m} in Matlab}}\n\n\\para{Algorithm}\nSimilar to AIS, Rao-Blackwellized Tempered (RTS)\\cite{carlson2016partition} Sampling also has a set of inverse temperatures $\\{0= \\beta_{1} < \\beta_{2} < ... < \\beta_{K} =1\\}$, which can define a sequence of\n\\begin{equation}\nf_{k}(\\mathbf x) \\propto f(\\mathbf x)^{\\beta_{k}} p_{1}(\\mathbf x)^{1-\\beta_{k}}\n\\end{equation}\n\nDifferent from AIS, we do not traverse $\\mathbf \\beta$. Instead we sample a $\\beta^{*}$ every loop, from the $\\mathbf \\beta$ set with the distribution $(\\beta|x)$.\n\nSubsequently, we sample from $x_{k}$ to $x_{k+1}$ by the probability of $q(x|\\beta^{*})$ just like what we did in AIS, shown in Figure~\\ref{fig:xkxk1}. However, what also different from AIS is that, we have to iterate from $x_{k}$ to $x_{k+1}$ many times(i.e. 50 times in\\cite{carlson2016partition} ) for the sake of getting a better $x_{k+1}$.\n\nAt the last of every loop, we update the lower variance estimator $\\hat{\\mathbf c}$ by\n\\begin{equation}\n\\hat{c}_{k} = \\hat{c}_{k} + \\frac{1}{N}q(\\beta_{k}|x)\n\\end{equation}\n\nFinally, we get $Z_{k}$ by\n\\begin{equation}\n\\hat{Z}_{k}^{RTS} = \\hat{Z}_{k}\\frac{r_{1}\\hat{c}_{k}}{r_{k}\\hat{c}_{1}},~~k=2,...,K\n\\end{equation}\nin which what we do care is $Z_{B} \\approx \\hat{Z}_{K}^{RTS}$.\n\nThe posterier distribution $q(\\beta_{k}|x)$ in the above equations is defined by:\n\\begin{equation}\nq(\\beta_{k}|x) = \\frac{f_{k}(x)r_{k}/\\hat{Z}_{k}}{\\sum_{k'=1}^{K} f_{k'}(x)r_{k'}/\\hat{Z}_{k'}}\n\\end{equation}\n\n\\para{Practice}\nIn the paper\\cite{carlson2016partition}, Carlson et al. note an initializing method to initialize $Z_{k}$, whose procedure is just like the above process. The only difference is that they sampled $\\beta_{k}$ by uniform distribution in every loop, not by the distribution $(\\beta|x)$. They claim that after doing such initializing work, then we conduct the algorithms above would acquire a better result.\n\nIn our real practice, we directly use the initializing method mentioned above by selecting $\\beta_{k}$ with a uniform distribution in every loop. We also initialize the value of $Z_{A}$ by the method we have mentioned in the AIS section using the dataset. And we have found that the result is already satisfying, there is no need to conduct more loops with $\\beta_{k}$ sampled by $(\\beta|x)$.\n\nAlso, we found that we have to conduct the procedure above for several times s.t. we can acquire our desired partition function value.(i.e. We did it for 100 times, that is to say we update $\\mathbf Z$ for 100 times).\n\n\t\\begin{algorithm}\n        \\caption{Rao-Blackwellized Tempered Sampling}\n        \\begin{algorithmic}\n        \t\\Require $\\{\\beta_{k},r_{k}\\}_{k=1,...,K}$\n            \\State Initialize $b_{A}$ by dataset\n        \t\\State Initialize $log \\hat{Z}_{k}, k=2,...,K$ \n            \\For{$n = 1 \\to Runtime$}\n            \t\\State Initialize $\\beta \\in \\{\\beta_{1}...\\beta_{K}\\}$\n            \t\\State Initialize $\\hat{c}_{k}=0, k=1,...,K$\n                \\For{$t = 1 \\to N$}\n                    \\For{$t = 1 \\to Transition time$}\n                        \\State Sample $\\mathbf x_{k+1}$ given $\\mathbf x_{k}$ using $q(x|\\beta^{*})$\n                    \\EndFor\n                    \\State $\\mathbf x^{*} \\gets \\mathbf x_{k+1}$\n    \t            \\State Sample $\\beta^{*} \\sim (\\beta|\\mathbf x^{*})$ or $\\beta^{*} \\in \\{\\beta_{1}...\\beta_{K}\\}$\n    \t            \\State Update $\\hat{c}_{k} \\gets \\hat{c}_{k}+\\frac{1}{N} q(\\beta_{k}|\\mathbf x^{*})$\n    \t\t\t\\EndFor\n                \\State Update $\\hat{Z}^{RTS}_{k} \\gets \\hat{Z}_{k}\\frac{r_{1}\\hat{c}_{k}}{r_{k}\\hat{c}_{1}}, k=2,...,K$\n            \\EndFor\n        \\end{algorithmic}\n    \\end{algorithm}\n", "meta": {"hexsha": "e7311e31b34a498ab25fdcb5ac8c617031cf585a", "size": 3798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/RTS.tex", "max_stars_repo_name": "lzhbrian/MCMC", "max_stars_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-09-10T04:42:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-21T16:07:29.000Z", "max_issues_repo_path": "tex/RTS.tex", "max_issues_repo_name": "lzhbrian/MCMC", "max_issues_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/RTS.tex", "max_forks_repo_name": "lzhbrian/MCMC", "max_forks_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-03T17:34:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-24T10:54:53.000Z", "avg_line_length": 64.3728813559, "max_line_length": 403, "alphanum_fraction": 0.6366508689, "num_tokens": 1216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6724520554619503}}
{"text": "\\section{Probability}\n\n    \\subsection{What is probability?}\n    Probability is the measurement of the chance of an event occurring.\n    If you've ever checked the weather and seen that it's a \"20\\% chance of rain\", you've seen probability in action.\n    To start, we'll need to define some terms.\n    \\begin{definition}\n        Outcomes: A possible result, typically referencing all of the possible results from the situation.\n    \\end{definition}\n    \\begin{definition}\n        Events: These typically refer to desired outcomes\n    \\end{definition}\n    Typically when finding probability, we'll divide all possible outcomes from our desired outcomes.\n    Thinking in terms of set notation, we'll refer to all of our desired outcomes as n(A), where A is our desired outcome.\n    n(S) will refer to all of the possible outcomes, and P(A) referring to the likelihood of A occurring.\n    To generalize, we'll use the equation below.\n    \\begin{equation*}\n        P(A) = \\frac{n(A)}{n(S)}\n    \\end{equation*}\n    Since the number of desired outcomes will never be greater than the number of total outcomes, we'll always have a decimal between 0 (0\\%) and 1 (100\\%), which we can convert to a percentage (ex. $\\frac{1}{4}=0.25=25\\%$), though typically we'll simply leave it as a reduced version of the fraction.\n    \n    \\subsection{Mutually Exclusive Events and Non-Mutually Exclusive Events}\n    Mutually Exclusive events are events that have zero overlap with other events.\n    Recall the Venn Diagram of Sets in the Combinations section, and assume A and B are both events.\n    To find the probability of either of them happening, we'll have to remember the equation:\n    \\begin{equation*}\n        n(A\\cup B) = n(A) + n(B)\n    \\end{equation*}\n    This equation finds all the ways A or B can happen, with zero overlap.\n    The problem with this equation is that it only finds the number of wanted outcomes.\n    Remember, to find the probability of something, we find the wanted outcomes, and divide it by all of the possible outcomes.\n    After this, our equation will look like this:\n    \\begin{equation*}\n        \\frac{n(A \\cup B)}{n(S)} = \\frac{n(A) + n(B)}{n(S)}\n    \\end{equation*}\n    Which reduces to:\n    \\begin{equation*}\n        P(A\\cup B) = P(A) + P(B)\n    \\end{equation*}\n    For non-mutually exclusive events, we must instead use a different equation, more accurate to the one we've discussed in the Sets Unit.\n    Following the same logic we used earlier, our equation works out to:\n    \\begin{equation*}\n        P(A\\cup B) = P(A) + P(B) - P(A\\cap B)\n    \\end{equation*}\n    Where $P(A\\cap B)$ equals the probability of both of those events occurring.\n\n    \\subsection{Independent Probability}\n    When two events occur at the same time, or one after another with no effect on each other, they are called Independent Events.\n    If you roll a die, then select a card, this would be independent, as the outcomes don't affect each other.\n    So solve an Independent Probability question we'll have to think in terms of sets, so the probability of A and B, can be solved with the equation below.\n    \\begin{equation*}\n        P(A\\cap B) = P(A) \\cap(B)\n    \\end{equation*}\n        But what happens if we need to find the probability of $(A \\mbox{ or } B)$?\n        To find that we'll need to use another equation.\n    \\begin{equation*}\n        P(A\\cup B) = P(A) + P(B) - P(A\\cap B)\n    \\end{equation*}\n    \n    \\subsection{Markov Chains}\n    Markov Chains are ways of predicting probability after successive iterations.\n    Suppose that Product A has a 70\\% chance of repurchasing, and Product B has a 70\\% chance of repurchasing, how would we model this? We'd use a Markov Chain. Shown below is our probability matrix.\n    \\begin{equation*}\n        P = \n        \\begin{bmatrix}\n            0.7 & 0.3\\\\\n            0.3 & 0.7\n        \\end{bmatrix}\n    \\end{equation*}\n    Now, we have to find the initial probability of something, which we call a \\textbf{transition matrix}. We'll represent this in the form of how many people started buying A or B, (shown below). Since this is the initial time, we'll refer to it as $S_{0}$, though you may also hear it called a \\textbf{probability vector}.\n    \\begin{equation*}\n    S_{0} = \n        \\begin{bmatrix}\n            0.6 & 0.4\n        \\end{bmatrix}\n    \\end{equation*}\n    To find the next probability vector, or $S_{1}$, we'll have to multiply the transition matrix by the probability vector.\n    \\begin{equation*}\n        \\begin{bmatrix}\n            0.6 & 0.4\n        \\end{bmatrix}\n        \\cdot\n        \\begin{bmatrix}\n            0.7 & 0.3\\\\\n            0.3 & 0.7\n        \\end{bmatrix}\n        =\n        \\begin{bmatrix}\n            0.54 & 0.46\n        \\end{bmatrix}\n        = S_{1}\n    \\end{equation*}\n    Much like rolling a die, the more times you repeat this process, the closer you are to the actual results. Though what if there was an easier way to do this?\n    \n    \\subsection{Steady State Vectors}\n    In Markov Chains, the probability vectors will eventually stop changing.\n    A probability vector that remains unchanged upon multiplication is called the \\textbf{steady state vector}.\n    This vector will represent the long term trend of the event.\n    To find this without repeating the Markov Chain multiplication, we must think of the problem in terms of a system of equations.\n    \\begin{equation*}\n        \\begin{bmatrix}\n            a & b\n        \\end{bmatrix}\n        \\cdot\n        \\begin{bmatrix}\n            0.7 & 0.3\\\\\n            0.3 & 0.7\n        \\end{bmatrix}\n        =\n        \\begin{bmatrix}\n            a & b\n        \\end{bmatrix}\n    \\end{equation*}\n    To have a systems of equations from this, we must first assert that $a + b = 1$, and find the other by multiplying for one of the values.\n    In this case, we can see that $0.7a + 0.3b = a$.\n    Now solve this systems of equations like you have done in Grade 9.\n    \n    \\subsection{Odds}\n    Have you ever heard the (seemingly wrong) Roll Up The Rim odds?\n    They claim that 1 in 5 people are winners!\n    But what does this mean?\n    Odds are the degree of confidence that someone has that an event will occur.\n    To find the odds of something occurring, we must use the formula below.\n    \\begin{equation*}\n        P(A) : P(A)' \n    \\end{equation*}\n    This equation represents a ratio of the probability of A happening, against the probability of A \\textbf{not} happening. Likewise with the odds of something \\textbf{not occurring}, we can use the reverse of this formula.\n    \\begin{equation*}\n        P(A)' : P(A)\n    \\end{equation*}\n    What happens if we want to win a bet though? You've probably heard of betting odds before. To do that, we'll use the equation below, where X will equal the amount won.\n    \\begin{equation*}\n        \\frac{P(A)}{P(A)'} = \\frac{\\emph{Amount Bet}}{x}\n    \\end{equation*}\n    After this, isolate X, which will give you the following equation.\n    \\begin{equation*}\n        X = \\emph{Amount Bet}\\cdot\\frac{P(A)'}{P(A)}\n    \\end{equation*}", "meta": {"hexsha": "08f8a8740b02ba2b9ec31b29ee35d5d26e398990", "size": 7020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "highschool-projects/MDM4UI/Probability.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/Probability.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/Probability.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": 50.8695652174, "max_line_length": 324, "alphanum_fraction": 0.663960114, "num_tokens": 1870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6724450425602105}}
{"text": "\\chapter{Neural Networks}\\label{sec:neural_network}\nNeural networks (NN) are machine learning algorithms inspired by the biological neural network that constitute the brain. A neural network is a collection of nodes called neurons that transmits and processes signals to and from other neurons connected to it, much like the biological neural network. The goal of a neural network is to approximate some function by learning parameters that results in the best approximation. They are popular as they can usually be constructed to do this fairly well, several people (\\cite{Cybenko1989}, \\cite{Funahashi1989}) have shown that a neural network with one hidden layer can approximate any function on a compact domain arbitrarily closed, if provided with a sufficient number of neurons.\n\\\\\n\\\\\nIn section \\ref{sec:feedforward_nn}, we introduce the most common neural network, the feedforward neural network, which is the type of network we refer to throughout the dissertation, when we use the term neural network. In section \\ref{sec:backprop} we examine a common method for training a neural network called backpropagation and in section \\ref{sec:early_stopping} we introduce a popular method of regularizing neural networks to avoid overfitting. \n\n\\section{Feedforward Neural Networks} \\label{sec:feedforward_nn}\nThe most simple neural networks are called feedforward neural networks or multilayer perceptrons (MLPs). They are called feedforward as information flows in one direction through the neurons. The neurons are typically arranged in layers to indicate which neurons receive and sends data to which neurons. These layers are typically vector-valued with each element of the vector playing the role as a neuron. As such one can describe a neural network as a chain of functions. Say we have three layers, then the neural network is $f(\\mathbf{x}) = f^{(3)}\\lr{f^{(2)}\\lr{f^{(1)}\\lr{\\mathbf{x}}}}$, with $f^{(1)}$ being the first layer to pass the data, $f^{(2)}$ the second layer and so on. The final layer is called the output layer, while the intermediate layers, that do not directly show their output to the user, are called hidden layers. \\\\\n\\\\\nA feedfoward neural network is shown in figure \\ref{fig:mlp} where the data flows from the input layer through two hidden layers and finally to the output layer. While the number of neurons in the input- and output layer depends on the example and the label dimensions, the number of neurons in the hidden layers as well as the number of hidden layers are design decisions chosen by the architect. \\\\\n\\\\\nThe data is sent through these layers by multiplying the inputs with weights $\\boldsymbol{w}$, adding a bias $\\boldsymbol{b}$ and finally applying an activation function $g$ to the result. An activation function is a non-linear function that ensures that we do not just pass linear transformations of the examples through the network, which is necessary to learn non-linear functions. Activation functions come in many different forms, some of the most popular can be seen in figure \\ref{fig:act_funcs}. For a network with two hidden layers the result of the first hidden layer is $f^{(1)}\\lr{\\boldsymbol{X}} = g_1 \\lr{\\boldsymbol{X} \\boldsymbol{w}_1 + \\boldsymbol{b}_1}$ and the result of the second hidden layer is $f^{(2)} \\lr{f^{(1)}\\lr{\\boldsymbol{X}}} = g_2 \\lr{f^{(1)}\\lr{\\boldsymbol{X}} \\boldsymbol{w}_2 + \\boldsymbol{b}_2}$. The subscripts indicate that the activation functions, weights and biases are unique for each layer. At last the result of the output layer is $f^{\\text{out}} \\lr{f^{(2)} \\lr{f^{(1)}\\lr{\\boldsymbol{X}}}} = g_3 \\lr{f^{(2)} \\lr{f^{(1)}\\lr{\\boldsymbol{X}}} \\boldsymbol{w}_3 + \\boldsymbol{b}_3}$. Sometimes the biases are omitted, as they can be represented in the weight vector for an example-matrix that are padded with a column of ones. \\\\\n\\\\\nWhile the choice of activation function are chosen as a design decision by the architect for the hidden layers, the activation function for the output layer are defined by the learning task. If the neural network is performing regression then we typically do not have an activation function for the output layer, as the label space for regression is the real numbers and need not be mapped to a specific set of values. However for binary classification a sigmoid-function is used, while a softmax-function is used for multiclass classification, as these map real values to the interval $[0,1]$ and thus provides valid probabilities for belonging to a specific class. Some popular choices of activation functions are shown in figure \\ref{fig:act_funcs}. Taking an activation value $a$ as input, these are defined as follows:\\\\\n\\\\\nLogistic sigmoid:\n\\begin{equation} \\label{eq:sigmoid}\n    g(a) = \\sigma(a) \\equiv \\frac{1}{1 + e^{-a}}\n\\end{equation}\nSoftmax for $K$ classes:\n\\begin{equation*}\n    g(a)_i = \\frac{e^{a_i}}{\\sum_{j=1}^K e^{a_j}} \\quad \\text{for} \\quad i=1 ,\\dots, K\n\\end{equation*}\nHyperbolic tangens:\n\\begin{equation} \\label{eq:tanh}\n    g(a) = \\tanh \\lr{a} \\equiv \\frac{e^a - e^{-a}}{e^a + e^{-a}}\n\\end{equation}\nRectified linear unit (ReLU):\n\\begin{equation} \\label{eq:relu}\n    g(a) = \\max \\lr{0, a}\n\\end{equation}\nExponential linear unit (ELU):\n\\begin{equation*}\n    g(a) = \\begin{cases}\n    a & a \\geq 0 \\\\\n    \\alpha \\lr{e^a - 1} & a < 0\n    \\end{cases} \\quad \\text{for } \\alpha > 0\n\\end{equation*}\nStep:\n\\begin{equation*}\n    g(a) = \\mathbf{1}_{[a > 0]}\n\\end{equation*}\n\n\n\\begin{figure}\n    \\centering\n    \\begin{neuralnetwork}[height = 4]\n        \\newcommand{\\x}[2]{$x_#2$}\n        \\newcommand{\\y}[2]{$\\hat{y}_#2$}\n        \\newcommand{\\hfirst}[2]{\\small $h^{(1)}_#2$}\n        \\newcommand{\\hsecond}[2]{\\small $h^{(2)}_#2$}\n        \\inputlayer[count=3, bias=false, title=Input\\\\layer, text=\\x]\n        \\hiddenlayer[count=4, bias=false, title=Hidden\\\\layer 1, text=\\hfirst] \\linklayers\n        \\hiddenlayer[count=3, bias=false, title=Hidden\\\\layer 2, text=\\hsecond] \\linklayers\n        \\outputlayer[count=2, title=Output\\\\layer, text=\\y] \\linklayers\n    \\end{neuralnetwork}\n    \\caption{Feedforward neural network with 2 hidden layers and arrows indicating where neurons feed their data.}\n    \\label{fig:mlp}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{pics/act_func_fig.pdf}\n    \\caption{Plot of some of the most used activation functions. The Python code for producing this figure can be seen in appendix \\ref{app:act_funcs}}\n    \\label{fig:act_funcs}\n\\end{figure}\n\n\n\\section{Backpropagation} \\label{sec:backprop}\nAs mentioned in section \\ref{sec:train_val} we seek to find the hypothesis $\\hat{h}^*_S$ that minimizes our empirical loss. For notational convenience we will collect the bias and weights in a parameter vector $\\boldsymbol{\\theta}$, which can be interpreted as using examples padded with a column of ones, so that $\\boldsymbol{x}\\boldsymbol{w}+\\boldsymbol{b} = \\boldsymbol{x}_{\\text{padded}} \\boldsymbol{\\theta}$. In the case of neural networks $\\hat{h}^*_S$ determine the weights used in each neuron as described in section \\ref{sec:feedforward_nn}. To obtain these optimal weights we train the neural network by minimizing the gradient of the (perhaps regularized) loss function $J$ with respect to the weights. To learn these weights we use a minimization algorithm like stochastic gradient descent described in section \\ref{sec:sgd}. However the gradient of the loss function is not readily available in neural networks as we have to trace the information back through the network that produced $\\hat{y}$ for which we calculate the loss. The solution is an algorithm proposed by \\cite{Rumelhart:1986a} called back-propagation or backprop for short.\\\\\n\\\\\nBack-propagation uses the chain rule of calculus, which states that\n\\begin{equation*}\n    \\frac{d \\, f\\lr{g\\lr{x}}}{d \\, x} = \\frac{d \\, f\\lr{g\\lr{x}}}{d \\, g \\lr{x}} \\frac{d \\, g\\lr{x}}{d \\, x}\n\\end{equation*}\nfor a real number $x$ and functions $g$ and $f$. This rule can be generalized for a vector $\\boldsymbol{x} \\in \\mathbb{R}^m$\n\\begin{equation*}\n    \\frac{\\partial f\\lr{g\\lr{\\boldsymbol{x}}}}{\\partial x_i} = \\sum_j \\frac{\\partial f\\lr{g\\lr{\\boldsymbol{x}}}}{\\partial g(x_j)} \\frac{\\partial g(x_j)}{\\partial x_i}\n\\end{equation*}\nwhere $g: \\mathbb{R}^m \\rightarrow \\mathbb{R}^n$ and $f: \\mathbb{R}^n \\rightarrow \\mathbb{R}$. In a neural network with one hidden layer we find the gradient of the loss function $J(\\boldsymbol{\\theta})$ (with $\\boldsymbol{X}$ and $\\boldsymbol{y}$ as implicit inputs to keep notation uncluttered) by\n\\begin{equation} \\label{eq:loss_grad}\n    \\nabla J\\lr{\\boldsymbol{\\theta}} = \\begin{pmatrix}\n    \\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{\\partial \\theta_1} \\\\\n    \\vdots\\\\\n    \\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{\\partial \\theta_m}\n    \\end{pmatrix}\n\\end{equation}\nwhere each element is found by\n\\begin{equation} \\label{eq:loss_grad_element}\n    \\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{\\partial \\theta_i} = \\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{\\partial f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}} \n    \\frac{\\partial f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}{\\partial f^{(1)}\\lr{\\boldsymbol{\\theta}}} \n    \\frac{\\partial f^{(1)}\\lr{\\boldsymbol{\\theta}}}{\\partial \\theta_i}\n\\end{equation}\nwhich can easily be generalized to networks with more than one hidden layer, by using the chain rule in a similar fashion. A computational graph for calculating this in a neural network is shown in figure \\ref{fig:backprop_compgraph}. This provides the fundamentals to understand how the gradient is computed in practice. A vector of weights (perhaps chosen by an update of stochastic gradient descent) is sent through the network as shown by algorithm \\ref{alg:forward_prop} to provide a loss value. This is called forward-propagation. Then the gradient in equation \\ref{eq:loss_grad} is computed using the relation in equation \\ref{eq:loss_grad_element} by back-propagation as shown in algorithm \\ref{alg:back_prop}. The result of the backpropagation algorithm is gradients on the weights that can be directly used for learning the weights that minimizes the gradient on the loss in a stochastic gradient descent algorithm as the one shown in algorithm \\ref{alg:sgd}.\\\\\n\\\\\nSome activation functions like the ReLU-function $g(a) = \\max \\lr{0, a}$ are not differential, which might sound problematic for backpropagation and gradient based learning. However, as mentioned by \\cite{Goodfellow-et-al-2016}, gradient descent still performs well enough for these models, partly because training algorithms usually do not arrive at a local minimum of the loss function. This means that we do not expect to get a gradient of exactly $\\boldsymbol{0}$, and therefore it is not a problem that the minimum of the loss function corresponds to points with an undefined gradient. Furthermore \\cite{Goodfellow-et-al-2016} mentions that most software return one of the one-sided derivatives, which can be heuristically justified since a computer is subject to numerical error anyway. \n\n\\begin{figure}\n    \\centering\n    \\begin{tikzpicture}[minimum size=1.5cm, node distance={45mm}, thick, main/.style = {draw, circle}] \n        \\node[main] (0) {$\\boldsymbol{\\theta}$}; \n        \\node[main] (1) [above of=0]{$f^{(1)} \\lr{\\boldsymbol{\\theta}}$}; \n        \\node[main] (2) [right of=1] {$\\frac{\\partial f^{(1)}\\lr{\\boldsymbol{\\theta}}}{\\partial \\theta_i}$};\n        \\node[main] (3) [right of=2] {$\\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{d \\theta_i}$};\n        \\node[main] (4) [above of=1] {$f^{\\text{out}} \\lr{ f^{(1)}\\lr{\\boldsymbol{\\theta}}}$};\n        \\node[main] (5) [right of=4] {$\\frac{\\partial f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}{\\partial f^{(1)}\\lr{\\boldsymbol{\\theta}}} $};\n        \\node[main] (6) [right of=5] {$\\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{\\partial f^{(1)}\\lr{\\boldsymbol{\\theta}}}$};\n        \\node[main] (7) [above of=4] {$J \\lr{f^{\\text{out}} \\lr{ f^{(1)}\\lr{\\boldsymbol{\\theta}}}}$};\n        \\node[main] (8) [right of=7] {$\\frac{\\partial J\\lr{f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}}}{\\partial f^{\\text{out}} \\lr{f^{(1)}\\lr{\\boldsymbol{\\theta}}}} $};\n        \n        \\draw[->] (0) -- node[midway, left] {$f^{(1)}$} (1);\n        \\draw[->] (1) -- node[midway, above] {$f'$} (2);\n        \\draw[->] (2) -- node[midway, above, pos=0.9] {$\\times$} (3);\n        \\draw[->] (1) -- node[midway, left] {$f^{\\text{out}}$} (4);\n        \\draw[->] (4) -- node[midway, above] {$f'$} (5);\n        \\draw[->] (5) -- node[midway, above, pos=0.8] {$\\times$} (6);\n        \\draw[->] (6) -- (3);\n        \\draw[->] (4) -- node[midway, left] {$J$} (7);\n        \\draw[->] (7) -- node[midway, above] {$f'$} (8);\n        \\draw[->] (8) -- (6);\n    \\end{tikzpicture} \n    \\caption{Computational graph of calculating the elements of the gradient in equation \\ref{eq:loss_grad_element} for the network with one hidden layer. $f'$ indicates that the function of the node is derived with regard to its input and $\\times$ indicates that the node is a product of the nodes pointing to it. }\n    \\label{fig:backprop_compgraph}\n\\end{figure}\n\n\n\n\\begin{algorithm}\\label{alg:forward_prop}\n\\SetAlgoLined\n\\KwInput{Number of layers, $l$}\n\\KwInput{The weight vectors of each layer $\\boldsymbol{w}^{(i)}, i \\in \\lrc{1, \\dots, l}$}\n\\KwInput{The activation functions of each layer, $g^{(i)}, i \\in \\lrc{1, \\dots, l}$}\n\\KwInput{The example to process, $\\boldsymbol{x}$}\n\\KwInput{The target label for the example, $\\boldsymbol{y}$}\n\\KwInput{The (regularized) loss function $J$}\n\\KwOutput{The (regularized) loss on the example, $J\\lr{\\boldsymbol{\\hat{y}}, \\boldsymbol{y}, \\boldsymbol{\\theta}}$}\n initialize $\\boldsymbol{h}^{(0)} \\leftarrow \\boldsymbol{x}$ \\\\\n\\For{$k = 1, \\dots, l$}{\n    $\\boldsymbol{a}^{(k)} \\leftarrow \\boldsymbol{w}^{(k)} \\boldsymbol{h}^{(k-1)}$ \\\\\n    $\\boldsymbol{h}^{(k)} \\leftarrow g^{(k)} \\lr{\\boldsymbol{a}^{(k)}}$ \\\\\n}\n$\\hat{\\boldsymbol{y}} \\leftarrow \\boldsymbol{h}^{(l)}$ \\\\\n$J\\lr{\\boldsymbol{\\hat{y}}, \\boldsymbol{y}, \\boldsymbol{\\theta}} \\leftarrow L\\lr{\\boldsymbol{\\hat{y}}, \\boldsymbol{y}} + \\alpha \\Omega \\lr{\\boldsymbol{\\theta}}$ \\\\\n \\caption{Forwardpropagation through a neural network and the computation of the cost function. For simplicity this demonstration uses only a single input example $\\boldsymbol{x}$, in practice one typically uses a minibatch of examples. We have also omitted the bias terms for simplicity, as these can be part of the weights $\\boldsymbol{w}^{(i)}$ with an example $\\boldsymbol{x}$ padded with a column of 1's. The collection of weights are denoted by $\\boldsymbol{\\theta}$.}\n\\end{algorithm}\n\n\\begin{algorithm}\\label{alg:back_prop}\n\\SetAlgoLined\n\\KwInput{Same variables as forwardpropagation in algorithm \\ref{alg:forward_prop}}\n\\KwOutput{The gradient of the regularized loss function on the weights, $ \\boldsymbol{d} = \\nabla_{\\boldsymbol{w}}J$}\nPerform forward propagation as per algorithm \\ref{alg:forward_prop}\\\\\nComputation of the loss-gradient on the output layer:\\\\\n$\\boldsymbol{d} \\leftarrow \\nabla_{\\hat{\\boldsymbol{y}}} J =  \\nabla_{\\hat{\\boldsymbol{y}}} L\\lr{\\hat{\\boldsymbol{y}}, \\boldsymbol{y}}$ \\\\\n\\For{$k = l, l-1, \\dots, 1$}{\n    $\\boldsymbol{d} \\leftarrow \\nabla_{\\boldsymbol{a}^{(k)}}J = \\boldsymbol{d} \\odot g^{(k)'} \\lr{\\boldsymbol{a}^{(k)}}$\\\\\n    $\\nabla_{\\boldsymbol{\\theta}^{(k)}} J \\leftarrow \\boldsymbol{d} \\boldsymbol{h}^{(k-1)^\\top} + \\lambda \\nabla_{\\boldsymbol{\\theta}^{(k)}} \\Omega \\lr{\\boldsymbol{\\theta}}$\\\\\n    $\\boldsymbol{d} \\leftarrow \\nabla_{\\boldsymbol{h}^{(k-1)}} J = \\boldsymbol{\\theta}^{(k)^\\top} \\boldsymbol{d}$\\\\\n}\n\\caption{Back-propagation}\n\\end{algorithm}\n\n\\clearpage\n\\section{Early Stopping} \\label{sec:early_stopping}\nFor this regularization methods we introduce a validation set, which is a third split of the data that is separate from the training set, that trains our neural networks, and separate from the test set, that evaluates our neural network. This validation set is used for selecting a non-overfitting set of parameters proposed by the training of the algorithm. This means that the validation set contributes to the selection of the optimal hypothesis, which is why we must keep it separate from the test set, which we use to evaluate our algorithm.\n\\\\\n\\\\\n\\cite{Goodfellow-et-al-2016} argues that when we have large models with sufficient capacity to overfit, we often observe that the training error decreases steadily over time, while the validation error begins to rise again at some point before ending the training. This means that we obtain a better model if we stop training and return the parameters at the point with the lowest validation error. This is the concept of regularizing using early stopping. The algorithm terminates training when no parameters have improved the validation error over some pre-specified number of iterations called the patience, $\\phi$. The measure of improvement can be controlled by a hyperparameter $\\delta_{\\text{min}}$, making sure we only constitute an improvement if the decrease in validation error is more than $\\delta_{\\text{min}}$. The parameters $\\boldsymbol{\\theta}$ used for calculating the loss are provided by a training algorithm like ADAM from section \\ref{alg:adam} using back-propagation from section \\ref{sec:backprop}, while the loss is provided by the network output for these parameters and the chosen loss function. This procedure is specified more formally in algorithm \\ref{alg:es}.\\\\\n\\\\\nOne can think of early stopping as a hyperparameter selection algorithm that chooses the number of training steps for the training algorithm. The only significant cost of choosing this parameter automatically with early stopping is running the evaluation of the validation error periodically during training. However this can be done in parallel to the training process, as in Tensorflow where one can run parallel on the GPU. An additional cost is the need to maintain a copy of the optimal parameters, but this is negligible according to \\cite{Goodfellow-et-al-2016} since they are written to infrequently and never during the training-algorithm, and since they can preferably be stored in a slower and larger form of memory like in host memory or disk drive. \n\\\\\n\\\\\n\\cite{bishop1995} and \\cite{sjoberg_ljung1995} argues that early stopping has the effect of restricting the optimization procedure to a small volume of parameter space in the neighborhood of the initial parameter value. \\cite{Goodfellow-et-al-2016} shows with a simple linear model with a quadratic error function and gradient descent how early stopping is equivalent to L2 regularization in equation \\ref{eq:L2_reg}, but that early stopping has the advantage of automatically determining the correct amount of regularization while L2 regularization requires many training experiments with different values of its hyperparameter $\\alpha$. \n\n\n\n\\begin{algorithm}\\label{alg:es}\n\\SetAlgoLined\n\\KwInput{The number of steps between evaluations, $n$}\n\\KwInput{The patience parameter i.e. the number of times of observing worsening validation error before terminating, $\\phi$}\n\\KwInput{The measure of improvement, $\\delta_{\\text{min}}$}\n\\KwOutput{Parameters when terminating $\\boldsymbol{\\theta}^{*}$, training step when terminating $i^{*}$}\n    initialize $i, j \\leftarrow 0$ \\\\\n    initialize $v \\leftarrow \\infty$\\\\\n    Let $\\boldsymbol{\\theta}_0$ be the initial parameters\\\\\n    $\\boldsymbol{\\theta}^* \\leftarrow \\boldsymbol{\\theta}_0$\\\\\n    $i^* \\leftarrow i$\\\\\n    \\While{$j < \\phi$}{\n        Update $\\boldsymbol{\\theta}$ by running the training algorithm for $n$ steps\\\\\n        $i \\leftarrow i + n$\\\\\n        $v' \\leftarrow \\hat{L}\\lr{S_{\\text{val}}, \\boldsymbol{\\theta}}$\\\\\n        \\If{$v' < v - \\delta_{\\text{min}}$}{\n            $j \\leftarrow 0$\\\\\n             $\\boldsymbol{\\theta}^* \\leftarrow \\boldsymbol{\\theta}$\\\\\n            $i^* \\leftarrow i$\\\\\n            $v \\leftarrow v'$\\\\\n            \\Else{\n                $j \\leftarrow j +1$\n            }\n        }\n    }\n \\caption{Early stopping}\n\\end{algorithm}\n\n", "meta": {"hexsha": "462c074bb76230bb180e48094ca8c2ac8ef8c95d", "size": 20205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "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": "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": "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": 99.0441176471, "max_line_length": 1272, "alphanum_fraction": 0.7152684979, "num_tokens": 5732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6724048839755778}}
{"text": "\\chapter{Dual space and trace}\nYou may have learned in high school that given a matrix\n\\[\n\t\\begin{bmatrix}\n\t\ta & c \\\\\n\t\tb & d\n\t\\end{bmatrix}\n\\]\nthe trace is the sum along the diagonals $a+d$\nand the determinant is $ad-bc$.\nBut we know that a matrix is somehow\njust encoding a linear map using a choice of basis.\nWhy would these random formulas somehow not\ndepend on the choice of a basis?\n\nIn this chapter, we are going to\ngive an intrinsic definition of $\\Tr T$,\nwhere $T \\colon V \\to V$ and $\\dim V < \\infty$.\nThis will give a coordinate-free definition\nwhich will in particular imply the trace $a+d$\ndoesn't change if we take a different basis.\n\nIn doing so, we will introduce two new constructions:\nthe \\emph{tensor product} $V \\otimes W$\n(which is a sort of product of two spaces,\nwith dimension $\\dim V \\cdot \\dim W$)\nand the \\emph{dual space} $V^\\vee$,\nwhich is the set of linear maps $V \\to k$ (a $k$-vector space).\nLater on, when we upgrade from a vector space $V$\nto an inner product space $V^\\vee$,\nwe will see that the dual space gives a nice\ninterpretation of the ``transpose'' of a matrix.\nYou'll already see some of that come through here.\n\nThe trace is only defined for finite-dimensional\nvector spaces, so if you want you can restrict\nyour attention to finite-dimensional vector spaces for this chapter.\n(On the other hand we do not need the\nground field to be algebraically closed.)\n\nThe next chapter will then do the same for the determinant.\n\n\\section{Tensor product}\n\\prototype{$\\RR[x] \\otimes \\RR[y] = \\RR[x,y]$.}\nWe know that $\\dim (V \\oplus W) = \\dim V + \\dim W$,\neven though as sets $V \\oplus W$ looks like $V \\times W$.\nWhat if we wanted a real ``product'' of spaces,\nwith multiplication of dimensions?\n\nFor example, let's pull out\nmy favorite example of a real vector space, namely\n\\[ V = \\left\\{ ax^2 + bx + c \\mid a,b,c \\in \\RR \\right\\}. \\]\nHere's another space, a little smaller:\n\\[ W = \\left\\{ dy + e \\mid d,e \\in \\RR \\right\\}. \\]\nIf we take the direct sum, then we would get some rather unnatural\nvector space of dimension five\n(whose elements can be thought of as pairs $(ax^2+bx+c,dy+e)$).\nBut suppose we want a vector space\nwhose elements are \\emph{products} of polynomials in $V$ and $W$;\nit would contain elements like $4x^2y + 5xy + y + 3$.\nIn particular, the basis would be\n\\[ \\left\\{ x^2y, x^2, xy, x, y, 1 \\right\\} \\]\nand thus have dimension six.\n\nFor this we resort to the \\emph{tensor product}.\nIt does exactly this, except that the ``multiplication''\nis done by a scary\\footnote{%\n\tSeriously, $\\otimes$ looks \\emph{terrifying} to non-mathematicians,\n\tand even to many math undergraduates.}\nsymbol $\\otimes$:\nthink of it as a ``wall'' that separates the elements\nbetween the two vector spaces.\nFor example, the above example might be written as\n\\[ 4x^2 \\otimes y + 5x \\otimes y + 1 \\otimes y + 3 \\otimes 1. \\]\n(This should be read as $(4x^2 \\otimes y) + (5x \\otimes y) + \\dots$;\naddition comes after $\\otimes$.)\nOf course there should be no distinction\nbetween writing $4x^2 \\otimes y$ and $x^2 \\otimes 4y$\nor even $2x^2 \\otimes 2y$.\nWhile we want to keep the $x$ and $y$ separate,\nthe scalars should be free to float around.\n\nOf course, there's no need to do everything\nin terms of just the monomials.\nWe are free to write\n\\[ (x + 1) \\otimes (y + 1). \\]\nIf you like, you can expand this as\n\\[ x \\otimes y + 1 \\otimes y + x \\otimes 1 + 1 \\otimes 1. \\]\nSame thing.\nThe point is that we can take any two of our polynomials\nand artificially ``tensor'' them together.\n\nThe definition of the tensor product does exactly this,\nand nothing else.\\footnote{I'll only define this\n\tfor vector spaces for simplicity.\n\tThe definition for modules over a commutative ring $R$ is exactly the same.}\n\\begin{definition}\n\tLet $V$ and $W$ be vector spaces over the same field $k$.\n\tThe \\vocab{tensor product} $V \\otimes_k W$ is the abelian group\n\tgenerated by elements of the form $v \\otimes w$, subject to relations\n\t\\begin{align*}\n\t\t(v_1 + v_2) \\otimes w &= v_1 \\otimes w + v_2 \\otimes w \\\\\n\t\tv \\otimes (w_1 + w_2) &= v \\otimes w_1 + v \\otimes w_2 \\\\\n\t\t(c \\cdot v) \\otimes w &= v \\otimes (c \\cdot w).\n\t\\end{align*}\n\tAs a vector space,\n\tits action is given by\n\t$c \\cdot (v \\otimes w) = (c \\cdot v) \\otimes w = v \\otimes (c \\cdot w)$.\n\\end{definition}\nHere's another way to phrase the same idea.\nWe define a \\vocab{pure tensor} as an\nelement of the form $v \\otimes w$ for $v \\in V$ and $w \\in W$.\nBut we let the $\\otimes$ wall be ``permeable'' in the sense that\n\\[ (c \\cdot v) \\otimes w = v \\otimes (c \\cdot w) = c \\cdot (v \\otimes w) \\]\nand we let multiplication and addition distribute as we expect.\nThen $V \\otimes W$ consists of sums of pure tensors.\n\n\\begin{example}\n\t[Infinite-dimensional example of tensor product: two-variable polynomials]\n\tAlthough it's not relevant to this chapter,\n\tthis definition works equally well with infinite-dimensional\n\tvector spaces.\n\tThe best example might be\n\t\\[ \\RR[x] \\otimes_\\RR \\RR[y] = \\RR[x,y]. \\]\n\tThat is, the tensor product of polynomials in $x$\n\twith real polynomials in $y$\n\tturns out to just be two-variable polynomials $\\RR[x,y]$.\n\\end{example}\n\n\\begin{remark}\n\t[Warning on sums of pure tensors]\n\tRemember the elements of $V \\otimes_k W$\n\treally are \\emph{sums} of these pure tensors!\n\tIf you liked the previous example,\n\tthis fact has a nice interpretation ---\n\tnot every polynomial in $\\RR[x,y] = \\RR[x] \\otimes_\\RR \\RR[y]$ factors\n\tas a polynomial in $x$ times a polynomial in $y$\n\t(i.e.\\ as pure tensors $f(x) \\otimes g(y)$).\n\tBut they all can be written as sums of pure tensors $x^a \\otimes y^b$.\n\\end{remark}\n\n\nAs the example we gave suggested,\nthe basis of $V \\otimes_k W$ is literally the ``product''\nof the bases of $V$ and $W$.\nIn particular, this fulfills our desire that\n$\\dim (V \\otimes_k W) = \\dim V \\cdot \\dim W$.\n\\begin{proposition}[Basis of $V \\otimes W$]\n\tLet $V$ and $W$ be finite-dimensional $k$-vector spaces.\n\tIf $e_1, \\dots, e_m$ is a basis of $V$ and $f_1, \\dots, f_n$ is a basis of $W$,\n\tthen the basis of $V \\otimes_k W$\n\tis precisely $e_i \\otimes f_j$, where $i=1,\\dots,m$ and $j=1,\\dots,n$.\n\\end{proposition}\n\\begin{proof}\n\tOmitted; it's easy at least to see that this basis is spanning.\n\\end{proof}\n\n\\begin{example}[Explicit computation]\n\tLet $V$ have basis $e_1$, $e_2$ and $W$ have basis $f_1, f_2$.\n\tLet $v = 3e_1 + 4e_2 \\in V$ and $w = 5f_1 + 6f_2 \\in W$.\n\tLet's write $v \\otimes w$ in this basis for $V \\otimes_k W$:\n\t\\begin{align*}\n\t\tv \\otimes w &= (3e_1+4e_2) \\otimes (5f_1+6f_2) \\\\\n\t\t&= (3e_1) \\otimes (5f_1) +  (4e_2) \\otimes (5f_1)\n\t\t+ (3e_1) \\otimes (6f_2) + (4e_2) \\otimes (6f_2) \\\\\n\t\t&= 15 (e_1 \\otimes f_1) + 20(e_2 \\otimes f_1)\n\t\t+ 18 (e_1 \\otimes f_2) + 24(e_2 \\otimes f_2).\n\t\\end{align*}\n\tSo you can see why tensor products are a nice ``product'' to\n\tconsider if we're really interested in $V \\times W$\n\tin a way that's more intimate than just a direct sum.\n\\end{example}\n\n\\begin{abuse}\n\tMoving forward, we'll almost always abbreviate $\\otimes_k$ to just $\\otimes$,\n\tsince $k$ is usually clear.\n\\end{abuse}\n\\begin{remark}\n\tObserve that to define a linear map $V \\otimes W \\to X$,\n\tI only have to say what happens to each pure tensor $v \\otimes w$,\n\tsince the pure tensors \\emph{generate} $V \\otimes W$.\n\tBut again, keep in mind that\n\t$V \\otimes W$ consists of \\emph{sums} of these pure tensors!\n\tIn other words, $V \\otimes W$ is generated by pure tensors.\n\\end{remark}\n\n\\begin{remark}\n\tMuch like the Cartesian product $A \\times B$ of sets,\n\tyou can tensor together any two vector spaces $V$ and $W$ over the same field $k$;\n\tthe relationship between $V$ and $W$ is completely irrelevant.\n\tOne can think of the $\\otimes$ as a ``wall'' through which one can pass\n\tscalars in $k$, but otherwise keeps the elements of $V$ and $W$ separated.\n\tThus, $\\otimes$ is \\textbf{content-agnostic}.\n\n\tThis also means that even if $V$ and $W$ have some relation to each other,\n\tthe tensor product doesn't remember this.\n\tSo for example $v \\otimes 1 \\neq 1 \\otimes v$,\n\tjust like $(g,1_G) \\neq (1_G,g)$ in the group $G \\times G$.\n\\end{remark}\n\n\n\\section{Dual space}\n\\prototype{Rotate a column matrix by $90$ degrees.}\n\nConsider the following vector space:\n\\begin{example}\n\t[Functions from $\\RR^3 \\to \\RR$]\n\tThe set of real functions $f(x,y,z)$ is an\n\tinfinite-dimensional real vector space.\n\tIndeed, we can add two functions to get $f+g$,\n\tand we can think of functions like $2f$.\n\\end{example}\nThis is a terrifyingly large vector space,\nbut you can do some reasonable reductions.\nFor example, you can restrict your attention to just\nthe \\emph{linear maps} from $\\RR^3$ to $\\RR$.\n\nThat's exactly what we're about to do.\nThis definition might seem strange at first, but bear with me.\n\n\\begin{definition}\n\tLet $V$ be a $k$-vector space.\n\tThen $V^\\vee$, the \\vocab{dual space} of $V$, is defined\n\tas the vector space whose elements are \\emph{linear maps from $V$ to $k$}.\n\\end{definition}\nThe addition and multiplication are pointwise:\nit's the same notation we use when we write $cf+g$ to mean $c \\cdot f(x) + g(x)$.\nThe dual space itself is less easy to think about.\n\nLet's try to find a basis for $V^\\vee$.\nFirst, here is a very concrete interpretation of the vector space.\nSuppose for example $V = \\RR^3$.\nWe can think of elements of $V$ as column matrices, like\n\\[ v = \\begin{bmatrix}\n\t\t2 \\\\ 5 \\\\ 9\n\t\\end{bmatrix}\n\t\\in V. \\]\nThen a linear map $f \\colon V \\to k$ can be interpreted as a \\emph{row matrix}:\n\\[\n\tf = \\begin{bmatrix}\n\t\t3 & 4 & 5\n\t\\end{bmatrix}\n\t\\in V^\\vee. \\]\nThen\n\\[\n\tf(v) = \\begin{bmatrix}\n\t\t3 & 4 & 5\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\t2 \\\\ 5 \\\\ 9\n\t\\end{bmatrix}\n\t= 71. \\]\n\nMore precisely: \\textbf{to specify a linear map $V \\to k$,\nI only have to tell you where each basis element of $V$ goes}.\nIn the above example, $f$ sends $e_1$ to $3$, $e_2$ to $4$, and $e_3$ to $5$.\nSo $f$ sends \\[ 2e_1 + 5e_2 + 9e_3 \\mapsto 2 \\cdot 3 + 5 \\cdot 4 + 9 \\cdot 5 = 71. \\]\n\nLet's make all this precise.\n\\begin{proposition}[The dual basis for $V^\\vee$]\n\tLet $V$ be a finite-dimensional vector space with basis $e_1, \\dots, e_n$.\n\tFor each $i$ consider the function $e_i^\\vee \\colon V \\to k$\n\tdefined by\n\t\\[\n\t\te_i^\\vee(e_j)\n\t\t= \\begin{cases}\n\t\t\t1 & i=j \\\\\n\t\t\t0 & i \\neq j.\n\t\t\\end{cases}\n\t\\]\n\tIn more humane terms, $e_i^\\vee(v)$\n\tgives the coefficient of $e_i$ in $v$.\n\n\tThen $e_1^\\vee$, $e_2^\\vee$, \\dots, $e_n^\\vee$ is a basis of $V^\\vee$.\n\\end{proposition}\n\n\\begin{example}[Explicit example of element in $V^\\vee$]\n\tIn this notation, $f = 3e_1^\\vee + 4e_2^\\vee + 5e_3^\\vee$.\n\tDo you see why the ``sum'' notation works as expected here?\n\tIndeed\n\t\\begin{align*}\n\t\tf(e_1) &= (3e_1^\\vee + 4e_2^\\vee + 5e_3^\\vee)(e_1) \\\\\n\t\t&= 3e_1^\\vee(e_1) + 4e_2^\\vee(e_1) + 5e_3^\\vee(e_1) \\\\\n\t\t&= 3 \\cdot 1 + 4 \\cdot 0 + 5 \\cdot 0 = 3.\n\t\\end{align*}\n\tThat's exactly what we wanted.\n\\end{example}\n\nYou might be inclined to point out that $V \\cong V^\\vee$ at this point,\nsince there's an obvious isomorphism $e_i \\mapsto e_i^\\vee$.\nYou might call it ``rotating the column matrix by $90\\dg$''.\nThe issue is that this isomorphism\ndepends very much on which basis you choose:\nif I pick a different basis, then the isomorphism\nwill be intrinsically different.\n\nIt \\emph{is} true that $V$ and $V^\\vee$ are isomorphic\nfor finite-dimensional $V$,\nbut you should already know that \\emph{any} two $k$-vector spaces\nof the same dimension are isomorphic.\nIn light of this, the fact that $V \\cong V^\\vee$ is not especially impressive.\n\n\\section{$V^\\vee \\otimes W$ gives matrices from $V$ to $W$}\nGoal of this section:\n\\begin{moral}\n\tIf $V$ and $W$ are finite-dimensional $k$-vector spaces\n\tthen $V^\\vee \\otimes W$ represents linear maps $V \\to W$.\n\\end{moral}\n\nHere's the intuition.\nIf $V$ is three-dimensional and $W$ is five-dimensional, then we can think\nof the maps $V \\to W$ as a $5 \\times 3$ array of numbers.\nWe want to think of these maps as a vector space:\n(since one can add or scale matrices).\nSo it had better be a vector space with dimension $15$,\nbut just saying ``$k^{\\oplus 15}$'' is not really that satisfying\n(what is the basis?).\n\nTo do better, we consider the tensor product\n\\[ V^\\vee \\otimes W \\]\nwhich somehow is a product of maps out of $V$ and the target space $W$.\nWe claim that this is in fact the space we want:\ni.e.\\ \\textbf{there is a natural bijection between elements of $V^\\vee \\otimes W$\nand linear maps from $V$ to $W$}.\n\nFirst, how do we interpret an element of $V^\\vee \\otimes W$ as a map $V \\to W$?\nFor concreteness, suppose $V$ has a basis $e_1$, $e_2$, $e_3$,\nand $W$ has a basis $f_1$, $f_2$, $f_3$, $f_4$, $f_5$.\nConsider an element of $V^\\vee \\otimes W$, say\n\\[ e_1^\\vee \\otimes (f_2 + 2f_4) + 4e_2^\\vee \\otimes f_5. \\]\nWe want to interpret this element as a function $V \\to W$:\nso given a $v \\in V$,\nwe want to output an element of $W$.\nThere's really only one way to do this:\nfeed in $v \\in V$ into the $V^\\vee$ guys on the left.\nThat is, take the map\n\\[ v \\mapsto e_1^\\vee(v) \\cdot (f_2 + 2f_4) + 4e_2^\\vee(v) \\cdot f_5 \\in W. \\]\nSo, there's a natural way to interpret any element\n$\\xi_1 \\otimes w_1 + \\dots + \\xi_m \\otimes w_m \\in V^\\vee \\otimes W$\nas a linear map $V \\to W$.\nThe claim is that in fact, every linear map $V \\to W$ has\nsuch an interpretation.\n\nFirst, for notational convenience,\n\\begin{definition}\n\tLet $\\Hom(V,W)$ denote the set of linear maps from $V$ to $W$\n\t(which one can interpret as matrices which send $V$ to $W$),\n\tviewed as a vector space over $k$.\n\t(The ``$\\Hom$'' stands for homomorphism.)\n\\end{definition}\n\\begin{ques}\n\tIdentify $\\Hom(V,k)$ by name.\n\\end{ques}\n\nWe can now write down something that's more true generally.\n\\begin{theorem}[$V^\\vee \\otimes W$ $\\iff$ linear maps $V \\to W$]\n\t\\label{thm:vect_hom_dualization}\n\tLet $V$ and $W$ be finite-dimensional vector spaces.\n\tWe described a map\n\t\\[ \\Psi \\colon V^\\vee \\otimes W \\to \\Hom(V,W) \\]\n\tby sending $\\xi_1 \\otimes w_1 + \\dots + \\xi_m \\otimes w_m$ to the linear map\n\t\\[ v \\mapsto \\xi_1(v) w_1 + \\dots + \\xi_m(v) w_m. \\]\n\tThen $\\Psi$ is an isomorphism of vector spaces, i.e.\\ every linear map $V \\to W$\n\tcan be uniquely represented as an element of $V^\\vee \\otimes W$ in this way.\n\\end{theorem}\n\nThe above is perhaps a bit dense, so here is a concrete example.\n\\begin{example}[Explicit example]\n\tLet $V = \\RR^2$ and take a basis $e_1$, $e_2$ of $V$.\n\tThen define $T : V \\to V$ by\n\t\\[ T = \\begin{bmatrix}\n\t\t\t1 & 2 \\\\ 3 & 4\n\t\t\\end{bmatrix}. \\]\n\tThen we have\n\t\\[ \\Psi(e_1^\\vee \\otimes e_1 + 2e_2^\\vee \\otimes e_1\n\t\t+ 3e_1^\\vee \\otimes e_2 + 4e_2^\\vee \\otimes e_2) = T. \\]\n\tThe beauty is that the $\\Psi$ definition is basis-free;\n\tthus even if we change the basis,\n\talthough the above expression will look completely different,\n\tthe \\emph{actual element} in $V^\\vee \\otimes V$ doesn't change.\n\\end{example}\n\nDespite this, we'll indulge ourselves in using coordinates for the proof.\n\\begin{proof}\n\t[Proof of \\Cref{thm:vect_hom_dualization}]\n\tThis looks intimidating, but it's actually not difficult.\n\tWe proceed in two steps:\n\t\\begin{enumerate}\n\t\t\\ii First, we check that $\\Psi$ is \\emph{surjective};\n\t\tevery linear map has at least one representation in $V^\\vee \\otimes W$.\n\t\tTo see this, take any $T : V \\to W$.\n\t\tSuppose $V$ has basis $e_1$, $e_2$, $e_3$ and that\n\t\t$T(e_1) = w_1$, $T(e_2) = w_2$ and $T(e_3) = w_3$.\n\t\tThen the element\n\t\t\\[ e_1^\\vee \\otimes w_1 + e_2^\\vee \\otimes w_2 + e_3^\\vee \\otimes w_3 \\]\n\t\tworks, as it is contrived to agree with $T$ on the basis elements $e_i$.\n\t\t\\ii So it suffices to check now that $\\dim V^\\vee \\otimes W = \\dim \\Hom(V,W)$.\n\t\tCertainly, $V^\\vee \\otimes W$ has dimension $\\dim V \\cdot \\dim W$.\n\t\tBut by viewing $\\Hom(V,W)$ as $\\dim V \\cdot \\dim W$ matrices, we see that\n\t\tit too has dimension $\\dim V \\cdot \\dim W$. \\qedhere\n\t\\end{enumerate}\n\\end{proof}\nSo there is a \\textbf{natural isomorphism} $V^\\vee \\otimes W \\cong \\Hom(V,W)$.\nWhile we did use a basis liberally in the\n\\emph{proof that it works}, this doesn't change the\nfact that the isomorphism is ``God-given'',\ndepending only on the spirit of $V$ and $W$ itself\nand not which basis we choose to express the vector spaces in.\n\n\n\\section{The trace}\nWe are now ready to give the definition of a trace.\nRecall that a square matrix $T$ can be thought of as a map $T \\colon V \\to V$.\nAccording to the above theorem,\n\\[ \\Hom(V, V) \\cong V^\\vee \\otimes V \\]\nso every map $V \\to V$ can be thought of as an element of $V^\\vee \\otimes V$.\nBut we can also define an\n\\emph{evaluation map} $\\opname{ev} : V^\\vee \\otimes V \\to k$\nby ``collapsing'' each pure tensor: $f \\otimes v \\mapsto f(v)$.\nSo this gives us a composed map\n\\begin{diagram}\n\t\\Hom(V, V) & \\rTo^\\cong & V^\\vee \\otimes V & \\rTo^{\\opname{ev}} & k.\n\\end{diagram}\nThis result is called the \\vocab{trace} of a matrix $T$.\n\n\\begin{example}[Example of a trace]\n\tContinuing the previous example,\n\t\\[ \\Tr T = e_1^\\vee(e_1) + 2e_2^\\vee(e_1) \n\t\t+ 3e_1^\\vee(e_2) + 4e_2^\\vee(e_2)\n\t\t= 1 + 0 + 0 + 4 = 5. \\]\n\tAnd that is why the trace is the sum of the diagonal entries.\n\\end{example}\n\n\\section{\\problemhead}\n\n\\begin{problem}\n\t[Trace is sum of eigenvalues]\n\tLet $V$ be an $n$-dimensional vector space\n\tover an algebraically closed field $k$.\n\tLet $T \\colon V \\to V$ be a linear map with\n\teigenvalues $\\lambda_1$, $\\lambda_2$, \\dots, $\\lambda_n$\n\t(counted with algebraic multiplicity).\n\tShow that $\\Tr T = \\lambda_1 + \\dots + \\lambda_n$.\n\t\\begin{hint}\n\t\tFollows by writing $T$ in an eigenbasis:\n\t\tthen the diagonal entries are the eigenvalues.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{dproblem}\n\t[Product of traces]\n\tLet $T \\colon V \\to V$ and $S \\colon W \\to W$ be linear maps\n\tof finite-dimensional vector spaces $V$ and $W$.\n\tDefine $T \\otimes S \\colon V \\otimes W \\to V \\otimes W$\n\tby $v \\otimes w \\mapsto T(v) \\otimes S(w)$.\n\tProve that \\[ \\Tr(T \\otimes S) = \\Tr(T) \\Tr(S). \\]\n\t\\begin{hint}\n\t\tAgain one can just take a basis.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{dproblem}\n\t[Traces kind of commute]\n\t\\gim\n\tLet $T \\colon V \\to W$ and $S \\colon W \\to V$ be linear maps\n\tbetween finite-dimensional vector spaces $V$ and $W$.\n\tShow that \\[ \\Tr(T \\circ S) = \\Tr(S \\circ T). \\]\n\t\\begin{hint}\n\t\tOne solution is to just take a basis.\n\t\tOtherwise, interpret $T \\otimes S \\mapsto \\Tr(T \\circ S)$ as a\n\t\tlinear map $(V^\\vee \\otimes W) \\otimes (W^\\vee \\otimes V) \\to k$,\n\t\tand verify that it is commutative.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tAlthough we could give a coordinate calculation,\n\t\twe instead opt to give a cleaner proof.\n\t\tThis amounts to drawing the diagram\n\t\t\\begin{diagram}\n\t\t\t&& (W^\\vee \\otimes V) \\otimes (V^\\vee \\otimes W)\n\t\t\t&\\rIsom& (V^\\vee \\otimes W) \\otimes (W^\\vee \\otimes V) && \\\\\n\t\t\t& \\ldTo^{\\text{compose}} & \\dTo && \\dTo & \\rdTo^{\\text{compose}} & \\\\\n\t\t\t\\Hom(W, W) & \\lIsom & W^\\vee \\otimes W & & V^\\vee \\otimes V & \\rIsom & \\Hom(V, V) \\\\\n\t\t\t& \\rdTo_{\\Tr} & \\dTo_{\\opname{ev}} && \\dTo_{\\opname{ev}} & \\ldTo_{\\Tr} & \\\\\n\t\t\t&& k & \\rIsom{\\id} & k &&\n\t\t\\end{diagram}\n\t\tIt is easy to check that the center rectangle commutes,\n\t\tby checking it on pure tensors $\\xi_W \\otimes v \\otimes \\xi_V \\otimes w$.\n\t\tSo the outer hexagon commutes and we're done.\n\t\tThis is really the same as the proof with bases;\n\t\twhat it amounts to is checking the assertion is true for\n\t\tmatrices that have a $1$ somewhere and $0$ elsewhere,\n\t\tthen extending by linearity.\n\t\\end{sol}\n\\end{dproblem}\n\n\\begin{problem}\n\t[Putnam 1988]\n\t\\gim\n\tLet $V$ be an $n$-dimensional vector space.\n\tLet $T : V \\to V$ be a linear map and suppose there exists $n+1$ eigenvectors,\n\tany $n$ of which are linearly independent.\n\tDoes it follow that $T$ is a scalar multiple of the identity?\n\t\\begin{hint}\n\t\tLook at the trace of $T$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tSee \\url{https://mks.mff.cuni.cz/kalva/putnam/psoln/psol886.html}.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "efa64d72163b5992cf499d7613fe138838c19267", "size": 19643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/linalg/dual-trace.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/linalg/dual-trace.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/linalg/dual-trace.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.5156862745, "max_line_length": 87, "alphanum_fraction": 0.6829913964, "num_tokens": 6768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.6723682653805995}}
{"text": "\n\\section{Branching Bisimulation relation between LTSs}\n\\label{app:A}\n\\begin{definition}\n \\label{branching_bisimulation}\nFor two LTSs $L_1 = (S_1, \\Lambda\\cup\\{\\tau\\}, \\rightarrow_1, i_1)$, $L_2 = (S_2, \\Lambda, \\rightarrow_2, i_2)$ a  relation $R \\subseteq S_1 \\times S_2$ is called a branching   bisimulation relation if for all $s \\in S_1$ and $t \\in S_2$ such that $R(s,t)$, the following conditions are met, for $a\\in \\Lambda\\cup\\{\\tau\\}$:\n  \\begin{itemize}\n  \\item[1.] if $s \\arrow{}{a} s'$ in~$L_1$, then either\n    \\begin{itemize}\n    \\item [--] $a = \\tau$ and $R(s',t)$, or\n    \\item [--] for some $n \\geq 0$, there exist $t_1, \\ldots, t_n$ and~$t'$ in~$S_2$ such that \\\\\n     $t \\arrow{}{\\tau} t_1 \\arrow{}{\\tau}\\ldots \\arrow{}{\\tau} t_{n}\n      \\arrow{}{a} t'$ in~$L_2$, $R(s,t_n)$ and~$R(s',t')$;\n    \\end{itemize}\n  \\item[2.] if $t \\arrow{}{a} t'$ in~$L_2$, then either\n    \\begin{itemize}\n    \\item [--] $a = \\tau$ and $R(s,t')$, or\n    \\item [--] for some $n \\geq 0$, there exist $s_1, \\ldots, s_n$\n      and~$s'$ in~$S_2$ such that \\\\\n      $s \\arrow{}{\\tau} s_1\n      \\arrow{}{\\tau} \\ldots \\arrow{}{\\tau} s_{n}\n      \\arrow{}{a} s'$ in~$L_1$, $R(s_n,t)$ and~$R(s',t')$;\n    \\end{itemize}\n%  \\item[3.] if $s\\downarrow$ in~$Z$, then, for some $n\\geq 0$, %there\n%    exist $t_1, \\ldots, t_n$ in~$\\ST'$ such that $t %\\xrightarrow{\\tau}\n%    t_1 \\xrightarrow{\\tau} \\ldots \\xrightarrow{\\tau} t_{n}$ %in~$Z'$,\n%    $R(s,t_n)$ and $t_n \\downarrow$;\n%  \\item[4.] if $t\\downarrow$ in~$Z'$, then, for some $n\\geq 0$, %there\n%    exist $s_1, \\ldots, s_n$ in~$\\ST$ such that $s %\\xrightarrow{\\tau}\n%    s_1 \\xrightarrow{\\tau} \\ldots \\xrightarrow{\\tau} s_{n}$ %in~$Z$,\n%    $R(s_n,t)$ and $s_n \\downarrow$.\n  \\end{itemize}\n$L_1$ and~$L_2$\n%two states $s$ and~$t$\nare branching bisimilar,\n%notation $L_1 \\bisim_{\\!b\\ } L_2$,\nif there exists a   branching bisimulation relation~$R$ for $L_1$ and~$L_2$ such that~$R(i_1,i_2)$.\n\\end{definition}\n\n", "meta": {"hexsha": "fc1ddfeff8e46c14651a449fc45d4b9f22d06167", "size": 1945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reusable-correct-transformations/def-bisim.tex", "max_stars_repo_name": "ljpengelen/latex-phd-thesis", "max_stars_repo_head_hexsha": "8cabcf160a6f06e12b5ced92bb5cec06983e5bb7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-18T21:53:57.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-18T21:53:57.000Z", "max_issues_repo_path": "reusable-correct-transformations/def-bisim.tex", "max_issues_repo_name": "ljpengelen/latex-phd-thesis", "max_issues_repo_head_hexsha": "8cabcf160a6f06e12b5ced92bb5cec06983e5bb7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reusable-correct-transformations/def-bisim.tex", "max_forks_repo_name": "ljpengelen/latex-phd-thesis", "max_forks_repo_head_hexsha": "8cabcf160a6f06e12b5ced92bb5cec06983e5bb7", "max_forks_repo_licenses": ["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.625, "max_line_length": 323, "alphanum_fraction": 0.5861182519, "num_tokens": 832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.672318635654708}}
{"text": "\\documentclass[./Thesis.tex]{subfiles}\n\\begin{document}\n\n\\chapter{Agda Briefly}\n\\label{chap:agda-briefly}\n\n\\epigraph{\n  The world of mathematics is becoming very large, the complexity of\n  mathematics is becoming very high, and there is a danger of an\n  accumulation of mistakes.\n}{Vladimir Voevodsky \\cite{voevodsky-quote}}\n\nThe goal of this chapter is two-fold. The main goal is to introduce the reader\nto Agda and its style of dependently typed proofs. The secondary goal is to\nintroduce the reader to the syntax and proof styles used in this thesis. Luckily,\nthese goals are complementary so we will tackle them simultaneously.\n\n\\section{Functions and Datatypes}\n\\label{sec:functions-and-datatypes}\n\nThe code snippet below defines the standard boolean datatype ($\\mathbb{Z}/[2]$).\nThe keyword \\AgdaKeyword{data} allows users to define their own types.\nYou can think about the type $\\AgdaPrimitiveType{Set}$ as the type of all types\\footnotemark.\nThe following lines introduce the common names for boolean values while\nexpressing that they are of type boolean.\nThis example also highlights that names in Agda need not be ASCII identifiers.\nThey can be arbitrary unicode strings namely $\\AgdaDatatype{𝔹}$.\n\\footnotetext{\n  This allows for a type theoretic analog of Russell's\n  Paradox. In actuality\n  $\\AgdaPrimitiveType{Set}_{n} : \\AgdaPrimitiveType{Set}_{n + 1}$\n  but as everything in this thesis lives in\n  $\\AgdaPrimitiveType{Set}_0 = \\AgdaPrimitiveType{Set}$\n  we can ignore this complexity.\n}\n\\begin{code}\n  data 𝔹 : Set where\n    false : 𝔹\n    true  : 𝔹\n\n  not : 𝔹 → 𝔹\n  not false = true\n  not true  = false\n\n  not-example : 𝔹\n  not-example = not false\n\\end{code}\nThe function $\\AgdaFunction{not}$ is defined by case analysis and follows\nthe standard mathematical definition closely. Functions in \\Agda{} must be\ntotal. In other words, they must cover every possible value in their domain.\nThe function defined above clearly satisfies this condition. Note that function\napplication, as seen in $\\AgdaFunction{not-example}$ is simply an empty space\nseparating the function and its argument. This convention first appeared in\nAlonzo Church's \\textit{lambda calculus} and as \\Agda{} is an\nextension of the lambda calculus the convention carries over. Investigating the\nlambda calculus is a thesis worthy exercise and in the past many Reed theses\nhave attempted this challenge. In our case, we refer the interested reader to the\nfollowing sources \\cite{harper} \\cite{hott-book}. This being said we consider the\nlambda calculus to be a formalism of the abstract mapping notation common when\ndescribing functions in mathematics. Note the following similarities between the\nmathematical notation and the lambda notation described in \\ref{eqn:mapping}.\n\\begin{align}\n  \\label{eqn:mapping}\n  x \\mapsto x^2 \\text{ is the same as } λ x \\, → \\, x^2\n\\end{align}\n\\Agda{} supports arbitrary lambda expressions and we can use this fact to define\nthe identity function for booleans in lambda notation.\n\\begin{code}[hide]\n  module Identity₁ where\n\\end{code}\n\\begin{code}\n    id : 𝔹 → 𝔹\n    id = λ x → x\n\\end{code}\nThe following identity function is definitionally equal to the lambda function\ndescribed above as every function in \\Agda{} is desugared to the lambda calculus.\n\\begin{code}[hide]\n  module Identity₂ where\n\\end{code}\n\\begin{code}\n    id : 𝔹 → 𝔹\n    id x = x\n\\end{code}\nThe astute reader may find the definitions above suspicious. Why is the identity\nfunction defined with a domain and codomain of the booleans? Does \\Agda{}\nrequire a programmer to create a new identity function for every type?\nThankfully, \\Agda{} adopts a solution pervasive to mathematics, universal\nquantification.\n\\begin{code}[hide]\n  module Identity₃ where\n\\end{code}\n\\begin{code}\n    id : ∀ (A : Set) → A → A\n    id A x = x\n\n    id-𝔹 : 𝔹 → 𝔹\n    id-𝔹 = id 𝔹\n\\end{code}\nThe general identity function depicted above introduces two new concepts.\nIt introduces universal quantification, or type theoretically, dependent types.\nA dependent type comes in two parts. The type of the second half $A \\, → \\, A$ depends\non the input of the first $∀ (A : \\AgdaPrimitiveType{Set}) →$. This is powerful\ninnovation and we will come to see that it drastically increases language expressivity.\nIt also introduces function currying. This concept allows multi-argument\nfunctions to be encoded as functions that return functions.\n\\begin{align}\n  \\label{eqn:currying}\n  (x, y) \\mapsto x^2 + y^2 \\equiv λ x \\, → λ y \\, → \\, x^2 + y^2\n\\end{align}\nEvery function in \\Agda{} is automatically curried so the identity function\ndescribed above is definitionally equal to the following function.\n\\begin{code}[hide]\n  module Identity₄ where\n\\end{code}\n\\begin{code}\n    id : ∀ (A : Set) → A → A\n    id = λ A → λ x → x\n\\end{code}\nNotice how the dependent type behaves similarly to normal function types.\nThis is because all function types in \\Agda{} are actually dependently typed.\nThe syntax $A \\, → \\, B$ is just \\textit{syntactic sugar} for a dependent type that ignores\nthe type of the input $(\\_ : A) \\, → \\, B$. Lastly we make specifying the type\nof the input optional as \\Agda{} can almost always infer that type. Note that we\ncan still specify the type as seen in $\\AgdaFunction{id-example₂}$ and\n$\\AgdaFunction{id-example₃}$\n\\begin{code}[hide]\n  module Identity₅ where\n\\end{code}\n\\begin{code}\n    id : ∀ {A : Set} → A → A\n    id {A} x = x\n\n    id-example₁ : 𝔹\n    id-example₁ = id true\n\n    id-example₂ : 𝔹\n    id-example₂ = id {𝔹} true\n\n    id-example₃ : 𝔹\n    id-example₃ = id {A = 𝔹} true\n\\end{code}\n\\section{Baby's First Proofs}\n\\label{sec:first-proofs}\nIn order to prove interesting mathematical statements we first need a notion of\nequality. The following code defines a datatype that represents equality. The\nfirst line informs \\Agda{} that equality is a binary relation over an arbitrary\ntype. The datatype only has a single constructor which requires that the left\nhand side is the ``same'' as the right hand side. Thus the constructor is named\n$\\AgdaInductiveConstructor{≡-refl}$ as these constraints make the constructor\nsimilar to the reflexivity axiom of equivalence classes.\n\\begin{code}[hide]\n  module Equality where\n\\end{code}\n\\begin{code}\n    data _≡_ {A : Set} : A → A → Set where\n      ≡-refl : ∀ {x : A} → x ≡ x\n\\end{code}\nIn practice the left hand side and right hand side need not be the exact same\ncode. They do need to simplify to the same value. In the following code\n$\\AgdaFunction{not} \\, \\AgdaInductiveConstructor{true}$ simplifies to\n$\\AgdaInductiveConstructor{false}$ so the reflexivity constructor is allowed.\n\\begin{code}\n    simple : not true ≡ false\n    simple = ≡-refl\n\\end{code}\nThese concepts guide the following proof where we prove that $\\AgdaFunction{not}$ is an\ninvolution. The proof proceeds by cases, when the input is\n$\\AgdaInductiveConstructor{false}$ the expression\n$\\AgdaFunction{not} \\,\n(\\AgdaFunction{not} \\, \\AgdaInductiveConstructor{false})$\nsimplifies to $\\AgdaInductiveConstructor{false}$ via repeated applications of\nthe definition of $\\AgdaFunction{not}$. The process proceeds symmetrically when the input is\n$\\AgdaInductiveConstructor{true}$. Note that the case split is required as\n$\\AgdaFunction{not}$ does not simplify for arbitrary booleans. This is unlike\nthe identity function which would simplify for any input.\n\\begin{code}\n    not-involution : ∀ (b : 𝔹) → not (not b) ≡ b\n    not-involution false = ≡-refl\n    not-involution true = ≡-refl\n\\end{code}\n\\section{Natural Numbers}\n\\label{sec:natural-numbers}\nThe set of mathematical statements provable with only finite constructions is\nsignificantly smaller than the set of all provable mathematical statements.\nThankfully \\Agda{} can express many infinite constructions\\footnotemark{}.\nInfinite constructions are defined by an \\textit{inductively defined datatype}\n\\cite{agda}.\nIn the following code we define the simplest inductively defined datatype, the Peano\nnatural numbers. This definition is similar to our definition of the booleans\nbut the $\\AgdaInductiveConstructor{suc}$ constructor recursively\ncontains another natural.\n\\footnotetext{It can easily construct any ordinal less than\n  $\\varepsilon_0$ and with effort can express larger ordinals.\n  \\cite{ordinals}\n}\n\\begin{code}[hide]\n  module Naturals where\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 ≡-Reasoning\n\\end{code}\n\\begin{code}\n    data ℕ : Set where\n      zero : ℕ\n      suc  : ℕ → ℕ\n\n    three : ℕ\n    three = suc (suc (suc zero))\n\\end{code}\nWe can consume these naturals by \\textit{pattern matching} \\cite{agda}. In the\nfollowing example the variable $m$ is bound by pattern matching and is equal to\nthe input $n$ minus one. This is because we are ``pealing'' off one successor\nconstructor.\n\\begin{code}\n    isZero : ℕ → 𝔹\n    isZero zero = true\n    isZero (suc m) = false\n\\end{code}\n\\begin{code}[hide]\n    infixl 7 _+_\n\\end{code}\nThe example above is not a compelling use of natural numbers as it does not\nrequire any properties unique to the natural numbers. The code sample\nbelow defines addition on Peano naturals a more compelling use. As our definition was inductively\ndefined any non trivial operation on naturals must be inductively defined as\nwell.\n\\begin{code}\n    _+_ : ℕ → ℕ → ℕ\n    zero + n = n\n    suc n + m = suc (n + m)\n\\end{code}\nThe previous function name was defined with mixfix syntax. This is a syntax unique\nto \\Agda{} that allows for the construction of complex mathematical operators. A\nvalid name may be interspersed with underscores. At every underscore \\Agda{}\nexpects a user to supply one argument. Addition is a binary operator so we\nsupply one underscore on either side of the addition symbol. \\\\\n\nThis is a proof assistant so lets prove a simple property of the naturals,\nnamely that addition is associative. In order to do this we need a definition of\nassociativity. The following definition is a function that takes\nan arbitrary binary operation and returns a specification of associativity for\nthat binary operation. Note that even arguments can be defined with mixfix.\n\\begin{code}\n    Associative : ∀ {A : Set} → (A → A → A) → Set\n    Associative {A} _∙_ = ∀ (x y z : A) → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z)\n\\end{code}\nThe actual proof begins by cases. When the\nfirst argument is zero, $\\AgdaInductiveConstructor{zero} + (y + z)$ and\n$(\\AgdaInductiveConstructor{zero} + y) + z$ both simplify to $y + z$\ndefinitionally. Thus we can invoke reflexivity. The second case is more\ncomplicated and is proved using equational reasoning combinators. The first\ncombinator $\\AgdaFunction{\\_≡⟨⟩\\_}$ can only be used when the two lines are\ndefinitionally equal to each other. This is the reflexivity axiom in disguise.\nThe next combinator we use is $\\AgdaFunction{\\_≡⟨\\_⟩\\_}$ and it allows us to\nsupply a proof that the first line equals the second.\nWe invoke the inductive hypothesis and wrap a\n$\\AgdaInductiveConstructor{suc}$ around the result. This is allowable as our\nequality type is congruent over any function.\nLastly we push the $\\AgdaInductiveConstructor{suc}$\ninside the term. This is the second line in the definition of addition applied\nin reverse.\n\\begin{code}\n    +-assoc : Associative _+_\n    +-assoc zero y z = ≡-refl\n    +-assoc (suc x) y z = begin\n      suc x + (y + z)   ≡⟨⟩\n      suc (x + (y + z)) ≡⟨ ≡-cong suc (+-assoc x y z) ⟩\n      suc ((x + y) + z) ≡⟨⟩\n      (suc (x + y) + z) ≡⟨⟩\n      (suc x + y) + z   ∎\n\\end{code}\n\\section{Record Types}\n\\label{sec:record-types}\nWe introduce one last critical construct, the record construction. A record is\nvery similar to a datatype but there are some differences. Most importantly\nrecords have only one constructor so they can not be used to define any of the\ndatatype given above. Unlike datatypes, records contain a list of named fields.\nWe define a record type that bundles together all the proofs required for a\nbinary operator to be a semigroup. In this case there is only one constraint\nnamely associativity. \\\\\n\\begin{code}\n    record IsSemigroup {A : Set} (_∙_ : A → A → A) : Set where\n      constructor IsSemigroup✓\n      field\n        ∙-assoc : Associative _∙_\n\\end{code}\nWe prove that $\\AgdaFunction{\\_+\\_}$ is a semigroup but supplying every\nfield of the $\\AgdaDatatype{IsSemigroup}$ record.\n\\begin{code}\n    +-isSemigroup : IsSemigroup _+_\n    +-isSemigroup = IsSemigroup✓ +-assoc\n\\end{code}\nImportantly the type of fields can depend on the value of fields previously in\nthe list. This allows us to define the less than or equal to relation $n \\leq m$\nas $\\exists k. \\, n + k = m$. The reason fields act similarly to exists\nthat when we construct a record we ``forget'' everything specific to the value\nexcept the requirements specified by the fields.\n\\begin{code}\n    record _≤_ (n : ℕ) (m : ℕ) : Set where\n      constructor lte\n      field\n        k : ℕ\n        pf : n + k ≡ m\n\\end{code}\n\n% \\begin{code}\n%   Reflexive : ∀ {A : Set} → (A → A → Set) → Set\n%   Reflexive _R_ = ∀ {x} → x R x\n\n%   ≡-reflexive : ∀ {A : Set} → Reflexive {A = A} _≡_\n%   ≡-reflexive = ≡-refl\n% \\end{code}\n% \\begin{code}\n%   Symmetric : ∀ {A : Set} → (A → A → Set) → Set\n%   Symmetric _R_ = ∀ {x y} → x R y → y R x\n\n%   ≡-sym : ∀ {A : Set} → Symmetric {A = A} _≡_\n%   ≡-sym {A} {x} {.x} ≡-refl = ≡-refl\n% \\end{code}\n% Agda supports mixfix syntax for defining names (datatypes, functions, and arguments).\n% As shown below anywhere an underscore is given an argument should be supplied.\n% \\begin{code}\n%   Transitive : ∀ {A : Set} → (A → A → Set) → Set\n%   Transitive _R_ = ∀ {x y z} → x R y → y R z → x R z\n\n%   ≡-trans : ∀ {A : Set} → Transitive {A = A} _≡_\n%   ≡-trans {A} {x} {.x} {.x} ≡-refl ≡-refl = ≡-refl\n% \\end{code}\n% \\begin{code}\n%   ≡-cong : ∀ {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y\n%   ≡-cong {A} {B} f {x} {.x} ≡-refl = ≡-refl\n% \\end{code}\n% \\begin{code}\n%   infix  1 begin_\n%   begin_ : ∀ {A : Set} {x y : A} → x ≡ y → x ≡ y\n%   begin x≡y = x≡y\n\n%   infix  3 _∎\n%   _∎ : ∀ {A : Set} (x : A) → x ≡ x\n%   x ∎ = ≡-refl\n\n%   infixr 2 _≡⟨_⟩_\n%   _≡⟨_⟩_ : ∀ {A : Set} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z\n%   x ≡⟨ x≡y ⟩ y≡z = ≡-trans x≡y y≡z\n\n%   infixr 2 _≡⟨⟩_\n%   _≡⟨⟩_ : ∀ {A : Set} {y : A} (x : A) → x ≡ y → x ≡ y\n%   x ≡⟨⟩ ≡-refl = ≡-refl\n% \\end{code}\n\n\n\\end{document}\n", "meta": {"hexsha": "b4e421d65637595fbfdfb54532da28d31c397890", "size": 14359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/AgdaBriefly.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/AgdaBriefly.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/AgdaBriefly.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": 40.5621468927, "max_line_length": 97, "alphanum_fraction": 0.7114005154, "num_tokens": 4264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6723186356547078}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Map?}\nThe operation $map?$ will return a boolean which indicates if the passed in argument is a $KV$\n\\begin{schema}{Map?[V]}\n  m? : V \\\\\n  bol! : Boolean \\\\\n  map?~\\_ : V \\fun Boolean\n  \\where\n  bol! = map?(m?) @ bol! = true \\iff m? : KV \\implies V \\hide (Scalar, Collection)\n\\end{schema}\nwhere $V \\hide (Scalar, Collection)$ is used to indicate that $m?$ is of type $V$\n\\begin{zed}\n  V ::= Scalar ~| ~Collection ~| ~KV\n\\end{zed}\nbut in order for $bol! = true$, $m?$ must not be of type $Scalar ~\\lor Collection$ such that\n\\begin{argue}\n  X = \\ldata x_{0}, x_{1}, x_{2}, x_{3}, x_{4} \\rdata \\\\\n  \\t1 x_{0} = 0 \\\\\n  \\t1 x_{1} = foo \\\\\n  \\t1 x_{2} = \\langle baz, \\ qux \\rangle \\\\\n  \\t1 x_{3} = \\ldata abc \\mapsto 123, \\ def \\mapsto 456 \\rdata \\\\\n  \\t1 x_{4} = \\langle \\ldata ghi \\mapsto 789, \\ jkl \\mapsto 101112 \\rdata, \\ \\ldata ghi \\mapsto 131415, \\ jkl \\mapsto 161718 \\rdata \\rangle \\\\\n  map?(X) = true & KV by definition\\\\\n  map?(x_{3}) = true & KV \\\\\n  map?(x_{2}) = false & Collection \\\\\n  map?(x_{4}) = false & Collection of maps\\\\\n  map?(x_{0}) = false & Scalar \\\\\n  map?(x_{1}) = false & String\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "18596d3962e0ecb42659095f578aa09bc5238d43", "size": 1202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/kv/map?.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/map?.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/map?.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.5625, "max_line_length": 142, "alphanum_fraction": 0.6048252912, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6723073257838189}}
{"text": "\\paragraph{Opt.:}\n$\\argmin_x \\operatorname{score}(x) - \\sum \\lambda_i \\operatorname{Regularizer}_i(x)$, $\\operatorname{score}(x) := \\operatorname{mean}(\\operatorname{layer}_l[x])$ (using GD)\n\n\\paragraph{Gradient Feature Attribution}\n$\\nabla_x \\operatorname{logit}_t(x)$\n\n\\paragraph{Shapley Values}\n$\\displaystyle C_i := \\sum_{S \\subseteq P \\setminus \\{i\\}} \\frac{\\lvert S \\rvert! (\\lvert P\\rvert - \\lvert S \\rvert - 1) !}{\\lvert P \\rvert !} \\left(f(S \\cup \\{i\\}) - f(S) \\right)$\n\nNeed to define $f(S)$ (e.g., set pixels not in $S$ to 0)\n\n\\paragraph{Prop.} $\\sum_i C_i = f(P)$\n\n\\paragraph{Robustness} Robust NN rely on more robust features, more aligned with human perception", "meta": {"hexsha": "5567d03c3197ed06bad2b5d914aa205b44fa790e", "size": 674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "visualization.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": "visualization.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": "visualization.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": 48.1428571429, "max_line_length": 180, "alphanum_fraction": 0.6854599407, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6722767265482896}}
{"text": "\n\\section{Theories and Signatures}\n\\label{sec:theories-signatures}\n\n\\begin{figure*}[t]\n\\[\n\\footnotesize\n\\renewcommand{\\arraystretch}{1.0}\n\\begin{array}[t]{l}\n\\mbox{\\textbf{Theory Elements}}\\\\\n\\SET\\ s\\ [\\EQUALS\\ \\mathit{set}\\ ]\\\\\n\\CONST\\ c\\ [\\COLON \\mathit{set}\\ ]\\ [\\EQUALS\\ \\mathit{term}\\ ]\\\\\n{}[\\STABLE{}]\\ \\RELATION\\ r\\ [\\COLON \\mathit{set}\\ ]\\ [\\EQUALS \\mathit{prop}\\ ]\\\\\n\\EQUIVALENCE \\COLON \\mathit{set}\\\\\n\\MODEL\\ M\\COLON\\mathit{theory}\\\\\n\\AXIOM\\ a\\ [\\ M\\COLON\\mathit{theory}\\ ]^{*}\\ [x\\COLON\\mathit{set}\\ ]^*\\EQUALS\\mathit{prop}\\\\\n\\\\\n\\mbox{\\textbf{Propositions}}\\\\\n\\TRUE\\\\\n\\FALSE\\\\\n\\NOT\\ \\Prop\\\\\n\\Prop \\AAND \\Prop\\\\\n\\Prop \\OOR \\Prop\\\\\n\\Prop \\IIMPLY \\Prop\\\\\n\\Prop \\IIFF \\Prop\\\\\nr [\\ \\Term\\ ]^*\\\\\n\\Term\\EQUALS\\Term\\\\ %[\\IN\\ \\Set]\\\\\n\\ALL\\ [x\\COLON \\Set] \\PERIOD \\Prop\\\\\n\\SOME\\ [x\\COLON \\Set] \\PERIOD \\Prop\\\\\n\\UNIQUE\\ [x\\COLON \\Set] \\PERIOD \\Prop\\\\\n\\end{array}\n\\qquad\n\\begin{array}[t]{l}\n\\mbox{\\textbf{Sets}}\\\\\n\\ZERO\\\\\n\\ONE\\\\\n\\BOOL\\\\\ns\\\\\n\\mathit{Model}\\PERIOD \\mathit{name}\\\\\n\\Set \\TIMES \\cdots \\TIMES \\Set\\\\\n\\Setexp \\ARROW \\Setexp\\\\\n\\Label\\ [\\COLON \\Setexp\\ ]\\ \\PLUS \\cdots \\PLUS \\Label\\ [\\COLON \\Setexp\\ ]\\\\\n\\LBRACE \\Ident [\\ \\COLON \\Setexp\\ ]\\ \\BAR \\Proposition \\RBRACE\\\\\n\\Setexp \\PERCENT \\metav{relation}\\\\\n%\\RZ\\ \\Setexp\\\\\n\\\\\n\\mbox{\\textbf{Terms}}\\\\\nx\\\\\n\\LPAREN \\Term\\COMMA \\cdots \\COMMA \\Term \\RPAREN\\\\\n\\Term\\PERIOD \\metav{n}\\\\\n\\Label\\ [\\ \\Term\\ ]\\\\\n\\MATCH\\ \\Term\\ \\WITH\\ \\mbox{\\textit{pattern-matches}}\\\\\n\\LAMBDA\\ x\\COLON\\Set\\ \\PERIOD\\ \\Term\\\\\n\\Term\\ \\Term\\\\\n\\Term \\PERCENT \\metav{relation}\\\\\n\\LET\\ x \\PERCENT \\metav{relation}\\ \\IN\\ \\Term\\EQUALS\\Term\\\\\n\\Term \\SUBIN \\Set\\\\\n\\Term \\SUBOUT \\Set\\\\\n\\THE\\ x\\ [\\COLON\\Set\\ ] \\PERIOD \\Prop\\\\\n\\LET\\ x\\ [\\COLON\\Set\\ ] \\EQUALS\\Term\\ \\IN\\ \\Term\n\\end{array}\n\\]  \n\\vspace{-0.6truecm}\n\\caption{Input Language Summary}\n\\label{fig:input}  \n\\end{figure*}\n\nIn this section we describe first-order theories and signatures.\nOur system translates the former into the later.\n\n\\subsection{Theories}\n\\label{sec:theories}\n\nA \\emph{theory} is a description of a mathematical structure, such as\na group, a vector space, a directed graph, etc. A theory consists of\n%\n\\begin{itemize}\n\\item a list of \\emph{basic sets},\n\\item a list of \\emph{basic constants} belonging to specified sets,\n\\item a list of \\emph{basic relations} on specified sets,\n\\item a list of axioms.\n\\end{itemize}\n%\nTo take a simple example, consider the theory of a semigroup in which\nevery element has a (possibly non-unique) square root; recall that a\nsemigroup is a set with an associative binary operation and a neutral\nelement.\\footnote{An example of a semigroup with square roots is the\n  complex numbers with multiplication as the binary operation.} In our\nsystem it could be written as follows:\n\\vspace{-0.2truecm}\n{\n\\small\n\\VerbatimInput{semigroup.thy}\n}\n\\goodbreak\\goodbreak\n\\noindent The theory is enclosed by \\Verb|thy|\\ldots\\Verb|end|. This theory\ndefines one basic set \\Verb|s|, and two basic constants: an element\n\\Verb|e| of \\Verb|s| and a (curried) binary infix operator \\Verb|*| on\nthe set \\Verb|s|. The \\Verb|implicit| operator is not part of the\ntheory proper, but signals to the type checker that bound\nvariables named \\Verb|x| or \\Verb|y| or \\Verb|z| should be assumed to\nrange over \\Verb|s| unless otherwise specified. Finally,\nwe have three axioms. Axiom arguments, e.g., \\Verb|x|, \\Verb|y|, and\n\\Verb|z| in the associativity axiom, name the free variables occuring\nin the axiom. It is not too big a mistake to think of them as being\nuniversally quantified.\n\nIt is important to note that theories do not include proofs, but\nrather just the statements of the axioms (and theorems) specified to\nhold. Thus although axioms can be defined, one cannot actually refer\nto them within the theory.\n\nThere are several features of theories that our system supports other\nthan those shown in this example above; the input language is\nsummarized in Figure~\\ref{fig:input}, where brackets imply optional\nelements.\n\n\nTheories may declare or define relations. They may be \\Verb|stable|,\ni.e., their computational interpretation is trivial (see\nSection~\\ref{sec:implementation} for further discussion of this\npoint). Axioms can universally quantify over all models of a theory.\nThis is useful for describing universality properties, such as\ninitiality of an algebra or finality of a coalgebra.\n  \nThe propositions are the familiar ones from first-order logic;\n$\\UNIQUE$ is unique existence ($\\exists!$). In addition to the basic\nempty ($\\ZERO$) and unit ($\\ONE$) sets, one can form cartesian\nproducts, function spaces, tagged disjoint unions, subsets, and\nquotients by stable equivalence relations. The corresponding\nintroduction and elimination forms appear in the language of terms.\nFor example, $\\Term \\PERCENT \\metav{relation}$ is the equivalence\nclass under $\\metav{relation}$ containing $\\Term$, while $\\LET\\ x\n\\PERCENT \\metav{relation} \\mbox{\\Verb| = |} \\Term_1\\ \\IN\\ \\Term_2$\nbinds $x$ to a representative of the equivalence class $\\Term_1$ to be\nused in $\\Term_2$. The expression $\\Term \\SUBIN \\Set$ injects $\\Term$\ninto a given subset (recording a proof obligation of the term actually\nbeing a member of the subset), while $\\Term \\SUBOUT \\Set$ projects\n$\\Term$ from a subset out into its superset $\\Set$. The value of the\ndescription operator $\\THE\\ x \\,.\\, \\Prop$ is the unique $x$\nsatisfying $\\Prop$; using it incurs the obligation of proving that\nthere is exactly one such~$x$.\n\n\n\\subsection{Signatures}\n\\label{sec:signatures}\n\nOn the logical side, we have models described by theories.  Thus on\nthe programming side we should have implementations being described by\nspecifications.  Our tool thus translates theories into\n\\emph{signatures}, which are ML's module interfaces.\n\nSignatures allow us to require the existence of certain types, as well\nas values of given type.  This allows decidable typechecking, but we\nneed more expressiveness in order to faithfully translate the content\nof a theory.  We therefore generate signatures augmented by assertion\ncomments, which specify constraints on the values and functions an\nimplementation beyond their type.  It is the responsibility of the\nprogrammer to check that the implementation satisfies these\nassertions, as \\RZ does not attempt to do any theorem proving.\n\nAssertions are written in ordinary classical first-order logic. Since\nprogrammers typically are not trained in constructive logic, this may\nmake it easier to verify the assertions.\n\\goodbreak\nThe output for the theory \\Verb|SQGROUP| above is then:\n{\\small \\VerbatimInput{semigroup.mli}}\n\nAt the ML level we have required a type \\Verb|s|, and three values\n\\Verb|e|, \\Verb|*|, and \\Verb|sqrt|, of types \\Verb|s|,\n\\Verb|s->s->s|, and \\Verb|s->s|, respectively. The third value was\ngenerated from the square root axiom, which has a non-trivial\ncomputational content, cf.\\ Subsection~\\ref{subsec:real-transl}.\n\nComments contain other requirements, not expressible in ML, that\nfurther contstrain the allowed implementations. The assertion\n\\Verb|PER(=s=)| abbreviates the requirement that \\Verb|=s=| be a\npartial equivalence relation on~\\Verb|s|; its domain \\Verb+||s||+ is\nthe subset of terms of type \\Verb|s| that realize semigroup\nelements, and the relation \\Verb|=s=| identifies (possibly different)\nterms realizing the same abstract semigroup element. These data\ntogether determine a modest set. The assertion following the\ndeclarations of \\Verb|e| asserts that \\Verb|e| realizes a valid\nsemigroup element, and the one following \\Verb|*| asserts that\n\\Verb|*| must not be affected by the choice of realizers. Both\n\\Verb|e| and \\Verb|*| must of course still satisfy the \\Verb|unit| and\n\\Verb|assoc| axioms. Finally, the new function \\Verb|sqrt| derived\nfrom the logic must compute square roots. Since the theory requires\nexistence but not uniqueness of square roots, there is no requirement\nthat \\Verb|sqrt| be invariant with respect to the partial equivalence\nrelation on \\Verb|s|; different realizers of the same semigroup\nelement are allowed to produce (realizers of) different square roots.\n\n\n\\subsection{Parameterized Theories}\n\\label{sec:param-theor-funct}\n\nA theory may be parameterized by one or more models of other theories.\nFor example, a theory \\Verb|Real| of the reals may be parameterized in\nterms of a model \\Verb|N| of the naturals.  A theory of free groups may be\nparameterized in terms of the generating set.\n\nParameterized theories serve two purposes.  A model of a\nparameterized theory is a generic implementation that, given any\nimplementation of the parameters, returns an implementation of the\nresulting theory.  At the level of ML, this would be a function from\nmodules to modules, a so-called \\emph{functor}, and so a\nparameterized theory can be translated into the signature of a\nfunctor.\n\nAlternatively, once we have described a parameterized theory\n\\Verb|Real|, we may wish to use it to describe a single specific\nimplementation of real numbers based on a specific model \\Verb|N1|\n(implementation) of the natural numbers; this can be described as\nan implementation satisfying the theory \\Verb|Real(N1)|.\n\nThe dual nature of parameterized theories as being both a description\nof a parameterized model (a $\\Pi$ type) and something which can be\napplied to a model to produce a specialized theory (a $\\lambda$) is\nvery reminiscent the type inclusion of Automath~\\cite{automath}.  ML\ndoes not permit applications of functor signatures, however, so we\nbeta-reduce all theory applications before generating signatures;\n\\Verb|Real(N1)| would produce a signature for a real-number\nimplementation that refers directly to \\Verb|N1| rather than to a\ngeneric parameter \\Verb|N|.\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"case\"\n%%% End: \n", "meta": {"hexsha": "050a8e0e5cf5229b3527e16129f647782864b739", "size": 9697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "private/clase/theories_signatures.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/clase/theories_signatures.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/clase/theories_signatures.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": 41.7974137931, "max_line_length": 92, "alphanum_fraction": 0.7498195318, "num_tokens": 2742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6722355327034718}}
{"text": "\\section{Basic elements of  Lie groups and Lie algebras theory.}\nLet us recall the definitions of the  Lie group Theory taken from \\cite{Iserles.ea_AN2000} and \\cite{Varadarajan_book1984}.\n\n\n\n\n\\subsection{Differential equation (evolving) on a manifold $\\mathcal M$}\n\\begin{definition}\n A $d$-dimensional manifold $\\mathcal M$ is a $d$-dimensional smooth surface $ M\\subset \\RR^n$ for some $n\\geq d$.\n\\end{definition}\n\\begin{definition}\n  Let $\\mathcal M$ be a $d$-dimensional manifold and suppose that $\\rho(t) \\in\\mathcal M$  is a smooth curve such that $\\rho(0) = p$. A tangent vector at $p$ is defined as\n  \\begin{equation}\n    \\label{eq:12}\n    a = \\left. \\frac{d}{dt} (\\rho(t)) \\right|_{t=0}.\n  \\end{equation}\nThe set of all tangents at $p$ is called the tangent space at $p$ and denoted by $T\\mathcal M|_p$. It has the structure of a linear space. \n\\end{definition}\n\\begin{definition}\n   A (tangent) vector field on $\\mathcal M$ is a smooth function $F : \\mathcal M \\rightarrow T\\mathcal M$ such that $F (p) \\in T\\mathcal M|_p$ for all $p \\in \\mathcal M$. The collection of all vector fields on $\\mathcal M$ is denoted by $\\mathcal X(\\mathcal M)$.\n \\end{definition}\n\n\n \\begin{definition}[Differential equation (evolving) on $\\mathcal M$]\n   Let $F$ be a tangent vector field on $\\mathcal M$. By a differential equation (evolving) on $\\mathcal M$ we mean a differential equation of the form\n   \\begin{equation}\n     \\dot y =F(y), t\\geq  0, y(0)\\in \\mathcal M\\label{eq:13}\n   \\end{equation}\n   where $F \\in \\mathcal X(\\mathcal M)$. Whenever convenient, we allow $F$ in~\\eqref{eq:13} to be a function of time, $F = F(t,y)$. The flow of $F$ is the solution operator $\\Psi_{t,F} : \\mathcal M \\rightarrow  \\mathcal M$ such that\n   \\begin{equation}\n     y(t) = \\Psi_{t,F} (y0).\\label{eq:14}\n   \\end{equation}\n \\end{definition}\n\n \\subsection{Lie algebra and Lie group}\n \\begin{definition}[commutator]\n   Given two vector fields $F, G$ on $\\RR^n$ , the commutator $H = [F, G]$ can\n   be computed componentwise at a given point $y ∈ \\RR^n$ as\n   \\begin{equation}\n     H_i(y)= \\sum_{j=1}^n  G_j(y)\\frac{\\partial F_i(y)}{\\partial y_j}   −F_j(y) \\frac{\\partial G_i(y)}{\\partial y_j} .\\label{eq:15}\n   \\end{equation}\n \\end{definition}\n\n \\begin{lemma}\\label{lemma:LieBracket}\nThe commutator of vector fields satisfies the identities\n\\begin{equation}\n  \\label{eq:16}\n  \\begin{array}[lclr]{lclr}\n    \\protect{[}F, G]&=& −\\protect{[}G, F ] & (skew symmetry), \\\\\n    \\protect{[} \\alpha F,G] &=& \\alpha \\protect{[}F,G], \\alpha \\in \\RR &  \\\\\n    \\protect{[}F + G, H]&=& \\protect{[}F, H] + \\protect{[}G, H] & (bilinearity),\\\\\n    0 &=&  \\protect{[}F,\\protect{[}G,H]]+\\protect{[}G,\\protect{[}H,F]]+\\protect{[}H,\\protect{[}F,G]] &(Jacobi’s identity).\n  \\end{array}\n\\end{equation}\n\\end{lemma}\n\\begin{definition}\n  A Lie algebra of vector fields is a collection of vector fields which is closed under linear combination and commutation. In other words, letting $\\mathfrak g$ denote the Lie algebra,\n  \n  \\begin{equation}\n    \\begin{array}[lclr]{l}\n    B \\in \\mathfrak g \\implies \\alpha B \\in \\mathfrak  g \\text{ for all } \\alpha ∈ R .\\\\\n    B_1,B_2 \\in\\mathfrak g \\implies B_1 +B_2, [B_1,B_2]\\in\\mathfrak g\\label{eq:17}\n    \\end{array}\n\\end{equation}\n\nGiven a collection of vector fields $B = {B_1 , B_2 , \\ldots}$, the least Lie algebra of vector fields containing $B$ is called the Lie algebra generated by $B$\n\\end{definition}\n\n\n\\begin{definition}\n  A Lie algebra is a linear space $V$ equipped with a Lie bracket, a bilinear, skew-symmetric mapping\n  \\begin{equation}\n    \\label{eq:18}\n    [ \\cdot , \\cdot ] : V \\times V \\rightarrow V \n  \\end{equation}\nthat obeys identities \\eqref{eq:16} from Lemma~\\ref{lemma:LieBracket}\n\\end{definition}\n\n\\begin{definition}[(General) Lie algebra]\n  A Lie algebra homomorphism is a linear map between two Lie algebras, $\\varphi : \\mathfrak g \\rightarrow \\mathfrak h$, satisfying the identity\n  \\begin{equation}\n\\varphi ([v, w]_{\\mathfrak g}) = [\\varphi(v), \\varphi(w)]_{\\mathfrak h}, v, w in \\mathfrak g\\label{eq:19}.\n\\end{equation}\nAn invertible homomorphism is called an isomorphism.\n\\end{definition}\n\n\\begin{definition}\n  A Lie group is a differential manifold $\\mathcal G$ equipped with a product $\\glaw : \\mathcal G\\times \\mathcal G →\\rightarrow \\mathcal  G$ satisfying\n  \\begin{equation}\n    \\label{eq:20}\n    \\begin{array}[lclr]{lr}\n      p \\glaw(q \\glaw r) = (p\\glaw q)\\glaw r, \\forall  p, q, r ∈ \\mathcal G &\\text{(associativity)}\\\\\n      \\exists I \\in \\mathcal G \\text{ such that } I\\glaw p = p \\glaw I = p,  \\forall p \\in \\mathcal G&\\text{(identity element)}\\ \\\\\n      \\forall p \\in \\mathcal G, \\exists  p^{-1}  \\in \\mathcal G \\text{ such that }  p^{-1}\\glaw p = I&\\text{(inverse) }\\ \\\\\n      \\text{ The maps}  (p, r)  \\rightarrow p\\glaw r \\text{ and }  p  \\rightarrow p^{-1} \\text{are smooth functions }&\\text{(smoothness)}\\                                                                                                \n    \\end{array}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Lie algebra $\\mathfrak g $ of a Lie group $\\mathcal G$]\n  The Lie algebra $\\mathfrak g$ of a Lie group $\\mathcal G$ is defined as the linear space of all tangents to $G$ at the identity $I$. The Lie bracket in $\\mathfrak g$ is defined as\n  \\begin{equation}\n    [a,b]= \\left.\\frac{\\partial^2 }{\\partial s\\partial t} \\rho(s)\\sigma(t)\\rho(-s)\\right|_{s=t=0}\\label{eq:21}\n\\end{equation}\nwhere $\\rho(s)$ and $\\sigma(t)$ are two smooth curves on $\\mathcal G$ such that $\\rho(0) = \\sigma(0) = I$, and \n$\\dot \\rho(0) = a$ and $\\dot \\sigma(0) = b$.\n\\end{definition}\n\n\\subsection{Actions of a group $\\mathcal G$ on  manifold $\\mathcal M$}\n\\begin{definition}\n   A left  action of Lie Group $\\mathcal G$ on a manifold $\\mathcal M$ is a smooth map $\\Lambda^l: \\mathcal G \\times  \\mathcal M \\rightarrow \\mathcal M$ satisfying\n\\begin{equation}\n  \\label{eq:22}\n  \\begin{array}[lcl]{rcl}\n    \\Lambda^l(I,y) &=& y, \\quad \\forall y \\in \\mathcal M \\\\\n    \\Lambda^l(p,\\Lambda(r,y)) &=& \\Lambda^l(p\\glaw r, y) , \\quad \\forall p,r \\in \\mathcal G,\\quad  \\forall y \\in \\mathcal M .\n  \\end{array}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\n   A  right  action of Lie Group $\\mathcal G$ on a manifold $\\mathcal M$ is a smooth map $\\Lambda^r: \\mathcal M \\times \\mathcal G   \\rightarrow \\mathcal M$ satisfying\n\\begin{equation}\n  \\label{eq:23}\n  \\begin{array}[lcl]{rcl}\n    \\Lambda^r(y,I) &=& y, \\quad \\forall y \\in \\mathcal M \\\\\n    \\Lambda^r(\\Lambda(y,r), p) &=& \\Lambda^r(y,  r\\glaw p) , \\quad \\forall p,r \\in \\mathcal G,\\quad  \\forall y \\in \\mathcal M .\n  \\end{array}\n\\end{equation}\n\\end{definition}\n\nA given smooth curve  $S(\\cdot) : t\\in \\RR \\mapsto S(t)\\in \\mathcal G$ in $\\mathcal G$ such that $S(0)= I$ produces a flow $\\Lambda^l(S(t),\\cdot)$ (resp. $\\Lambda^r(\\cdot, S(t))$) on $\\mathcal M$ and by differentiation we find a tangent vector field\n\\begin{equation}\n  \\label{eq:24}\n  F(y) = \\left. \\frac{d}{dt} (\\Lambda^l(S(t),y) \\right|_{t=0}\\quad( \\text{resp.  }  F(y) = \\left. \\frac{d}{dt} (\\Lambda^r(y,S(t)) \\right|_{t=0} ) \n\\end{equation}\nthat defines a ordinary differential equation on a Lie Group\n\\begin{equation}\n  \\label{eq:25}\n  \\dot y(t) = F(y(t)) = \\left. \\frac{d}{dt} (\\Lambda^l(S(t),y) \\right|_{t=0}  \\quad( \\text{resp.  }\\dot y(t) = F(y(t)) = \\left. \\frac{d}{dt} (\\Lambda^r(y,S(t)) \\right|_{t=0})\n\\end{equation}\n  \n\\begin{lemma}\n  Let $\\lambda^l_{*} : \\mathfrak g \\rightarrow \\mathcal X(\\mathcal M) $ (resp. $\\lambda^r_{*} : \\mathfrak g \\rightarrow \\mathcal X(\\mathcal M) $ be defined as\n  \\begin{equation}\n  \\lambda^l_{*}(a)(y) = \\left.\\frac{d}{ds}{ \\Lambda^l (\\rho(s), y)}\\right|_{s=0} \\quad (\\text{ resp. }  \\lambda^r_{*}(a)(y) = \\left.\\frac{d}{ds}{ \\Lambda^r (y, \\rho(s))}\\right|_{s=0})\\label{eq:26}  \n\\end{equation}\n where $\\rho(s)$ is a curve in $\\mathcal G$ such that $\\rho(0)=I$ and $\\dot\\rho (0)=a$. Then $\\lambda^l_{8}$ is a linear\nmap between Lie algebras such that\n\\begin{equation}\n  [a, b]_{\\mathfrak g} = [\\lambda^l_{*}(a), \\lambda^l_{*}(b)]_{\\mathcal X(\\mathcal M)}.\\label{eq:27}\n\\end{equation}\n\\end{lemma}\n\n\nThe following product between an element of an algebra $a \\in \\mathfrak g$ with an element of a group $\\sigma  \\in \\mathcal G$ \n can be defined. This will served as a basis for defining the exponential map.\n\\begin{definition}\n  We define the left product $(\\cdot, \\cdot)^l : \\mathfrak g \\times \\mathcal G \\rightarrow  \\mathcal G$ of an element of an algebra $a \\in \\mathfrak g$ with an element of a group $\\sigma  \\in \\mathcal G$ as\n  \\begin{equation}\n (a, \\sigma)^l = a \\cdot \\sigma = \\left.\\frac{d}{ds} \\rho(s) \\glaw \\sigma \\right|_{s=0}\\label{eq:28}\n\\end{equation}\nwhere $\\rho(s)$ is a smooth curve such that $\\dot\\rho(0)=a$ and $\\rho(0)=I$. In the same way, we can define the right product $(\\cdot, \\cdot)^r : \\mathcal G \\times \\mathfrak g  \\rightarrow   \\mathcal G$ \n\\begin{equation}\n  \\label{eq:29}\n  (\\sigma,a)^r = \\sigma \\cdot a  = \\left.\\frac{d}{ds} \\sigma \\glaw \\rho(s)   \\right|_{s=0}\n\\end{equation}\n\\end{definition}\n\n\\subsection{Exponential map}\n\\begin{definition}\n  Let $\\mathcal G$ be a Lie group and $\\mathfrak g$ its Lie algebra. The exponential mapping $exp : \\mathfrak g \\rightarrow \\mathcal G$ is defined as $\\exp(a) = \\sigma(1)$ where $\\sigma (t)$ satisfies the  differential equation\n\\begin{equation}\n\\dot \\sigma(t) = a \\cdot \\sigma(t), \\quad \\sigma (0) = I.\\label{eq:30}\n\\end{equation}\n\\end{definition}\n\nLet us define $a^k$ as\n\\begin{equation}\n  \\label{eq:31}\n  \\left\\{\\begin{array}[l]{l}\n    a^k = \\underbrace{a\\glaw a \\glaw \\ldots a\\glaw a}_{k \\text{ times}} \\text{ for } k \\geq 1 \\\\\n    a^0  = I\n  \\end{array}\\right.\n\\end{equation}\nThe exponential map can be expressed as\n\\begin{equation}\n  \\label{eq:32}\n  \\exp(at) = \\sum_{k=0}^\\infty \\frac{(ta)^k}{k!}\n\\end{equation}\nsince it is  a solution of \\eqref{eq:30}. A simple computation allows to check this claim:\n\\begin{equation}\n  \\label{eq:33}\n   \\frac{d}{dt}\\exp(at) = \\sum_{k=1}^\\infty  k t^{k-1} \\frac{a^k}{k!} = a \\glaw \\sum_{k=0}^\\infty  t^{k} \\frac{a^k}{k!} = a \\glaw \\exp(at).\n\\end{equation}\nA similar computation gives\n\\begin{equation}\n  \\label{eq:34}\n  \\frac{d}{dt}\\exp(at)  = \\sum_{k=0}^\\infty  t^{k} \\frac{a^k}{k!} \\glaw a = \\exp(at) \\glaw a.\n\\end{equation}\nThe exponential mapping $exp : \\mathfrak g \\rightarrow \\mathcal G$ can also be defined as $\\exp(a) = \\sigma(1)$ where $\\sigma (t)$ satisfies the  differential equation\n\\begin{equation}\n  \\label{eq:35}\n  \\dot \\sigma(t) = \\sigma(t) \\cdot a, \\quad \\sigma (0) = I.\n\\end{equation}\n\n\\begin{theorem}\n  \\label{Theorem:solutionofLieODE}\n  Let $\\Lambda^l:\\mathcal G\\times\\mathcal M \\rightarrow \\mathcal M$ be a left  group action and $\\lambda^l_{∗} : \\mathfrak g\\rightarrow \\mathcal X(\\mathcal M)$ the corresponding Lie algebra homomorphism. For any $a \\in \\mathfrak g$ the flow of the vector field $F = \\lambda^l_{a}(a)$, i.e. the solution of the equation\n  \\begin{equation}\n    \\dot y(t) = F(y(t)) = \\lambda^l_{*}(a)(y(t)),\\quad  t \\geq 0, y(0) = y_0 \\in \\mathcal M,\\label{eq:36}\n\\end{equation}\n  is given as\n  \\begin{equation}\ny(t) = \\Lambda^l(\\exp(ta), y_0).\\label{eq:37}\n\\end{equation}\nLet $\\Lambda^r:\\mathcal M\\times\\mathcal G \\rightarrow \\mathcal M$ be a right group action and $\\lambda^r_{∗} : \\mathfrak g\\rightarrow \\mathcal X(\\mathcal M)$ the corresponding Lie algebra homomorphism. For any $a \\in \\mathfrak g$ the flow of the vector field $F = \\lambda^r_{*}(a)$, i.e. the solution of the equation\n  \\begin{equation}\n    \\dot y(t) = F(y(t)) = \\lambda^r_{*}(a)(y(t)),\\quad  t \\geq 0, y(0) = y_0 \\in \\mathcal M,\\label{eq:38}\n\\end{equation}\n  is given as\n  \\begin{equation}\ny(t) = \\Lambda^r(y_0,\\exp(ta)).\\label{eq:39}\n\\end{equation}\n\n\\end{theorem}\n\n\n\\subsection{Translation (Trivialization) maps}\nThe left and right translation maps defined by \n\\begin{equation}\n  \\label{eq:148}\n  \\begin{array}{rcl}\n    L_z  : \\mathcal G \\times \\mathcal G &\\rightarrow& \\mathcal G \\quad \\text{ (left translation map )} \\\\\n    y &\\mapsto&  z \\glaw y\n  \\end{array}\n\\end{equation}\nand \n\\begin{equation}\n  \\label{eq:149}\n  \\begin{array}{rcl}\n    R_z(y)  :  \\mathcal G \\times  \\mathcal G  & \\rightarrow& \\mathcal G \\quad \\text{ (right translation map )} \\\\\n    y  &\\mapsto&  y \\glaw z \n  \\end{array}\n\\end{equation}\n\nIf we identify the manifold $\\mathcal M$ with the group $\\mathcal G$, The left and right translations can be interpreted as the simplest example of group action on the manifold. Note that the left translation map can be viewed as a left or right action on the group.\n\nIf we consider $L_z(y)$ as a right group action $ L_z(y) = \\Lambda^r( z, y) =z \\glaw y $, by differentiation we get a $L'_z : T \\mathfrak g \\cong  \\mathfrak g \\rightarrow T_z\\mathcal G$ with $\\dot\\rho (0)=a$ such that\n\\begin{equation}\n  \\label{eq:150}\n  \\lambda^r_{*}(a)(z) = L'_z(a) = \\left.\\frac{d}{ds}{ \\Lambda^r (z, \\rho(s))}\\right|_{s=0} = z \\glaw a\n\\end{equation}\nThe map\n\\begin{equation}\n  \\label{eq:152}\n  \\begin{array}{rcl}\n  L'_z  : \\mathfrak g &\\rightarrow& T_z\\mathcal G  \\\\\n         a &\\mapsto&  z \\glaw a\n  \\end{array}\n\\end{equation}\ndetermines an isomorphism of $\\mathfrak g$ with the tangent space  $T_z\\mathcal G$. In other words, the  tangent space can be identified to $\\mathfrak g$ as\n\\begin{equation}\n  \\label{eq:153}\n  T_z\\mathcal G =\\{L'_z(a) = z \\glaw a \\mid a \\in \\mathfrak g  \\}\n\\end{equation}\n\nRespectively, if we consider $R_z(y)$ as a left group action $ R_z(y) = \\Lambda^l( y, z) =y \\glaw z $, by differentiation we get a $R'_z : T \\mathfrak g \\cong  \\mathfrak g \\rightarrow T_z\\mathcal G$ with $\\dot\\rho (0)=a$ such that\n\\begin{equation}\n  \\label{eq:150}\n  \\lambda^l_{*}(a)(z) = R'_z(a) = \\left.\\frac{d}{ds}{ \\Lambda^l (\\rho(s),z)}\\right|_{s=0} = a \\glaw z\n\\end{equation}\nThe map\n\\begin{equation}\n  \\label{eq:152}\n  \\begin{array}{rcl}\n  R'_z  : \\mathfrak g &\\rightarrow& T_z\\mathcal G  \\\\\n         a &\\mapsto&  a \\glaw z\n  \\end{array}\n\\end{equation}\ndetermines an isomorphism of $\\mathfrak g$ with the tangent space  $T_z\\mathcal G$. In other words, the  tangent space can be identified to $\\mathfrak g$ as\n\\begin{equation}\n  \\label{eq:153}\n  T_z\\mathcal G =\\{R'_z(a) = a \\glaw z \\mid a \\in \\mathfrak g  \\}\n\\end{equation}\nAny tangent vector $F : \\mathcal G \\rightarrow T_z\\mathcal G$ can be written in either of the forms\n\\begin{equation}\n  \\label{eq:155}\n  F(z) = L'_z(f(a)) = R'_z(g(z))\n\\end{equation}\nwhere $f,g \\mathcal G \\rightarrow \\mathfrak g$. \n\\subsection{Adjoint representation}\n\\begin{definition}\nLet $p \\in \\mathcal G$ and let $\\sigma (t)$ be a smooth curve on $\\mathcal G$ such that $\\sigma (0)$ = I and $\\dot \\sigma(0) = b \\in \\mathfrak g$. The adjoint representation is defined as\n\\begin{equation}\n\\Ad_p(b) =\\left. \\frac{d}{dt} p\\sigma(t)p^{-1}\\right|_{t=0}\\label{eq:40}\n\\end{equation}\nThe derivative of $\\Ad$ with respect to the first argument is denoted $\\ad$. Let $\\rho(s)$ be a smooth curve on $\\mathcal G$ such that $\\rho(0) = I$  and $\\dot \\rho(0) = a$, it  yields:\n\\begin{equation}\n  \\label{eq:41}\n    \\ad_a(b) = \\left.\\frac{d}{ds} \\Ad_{\\rho(s)}(b)\\right|_{s=0}  = [a, b]\n\\end{equation}\n\\end{definition}\nThe adjoint representation can also be expressed with the map\n\\begin{equation}\n  \\label{eq:154}\n  \\Ad_p(b)  = (L_p \\glaw R_{p^{-1}})' (b) = (L'_p \\glaw R'_{p^{-1}}) (b) = p \\glaw b \\glaw p^{-1}  \n\\end{equation}\n\nFor a tangent vector given in~\\eqref{eq:155}, we have\n\\begin{equation}\n  \\label{eq:151}\n  g(z) = Ad_z(f(z))\n\\end{equation}\nAnother important relation relating $\\Ad$, $\\ad$ and $\\exp$ is\n\\begin{equation}\n  \\label{eq:164}\n  \\Ad_{\\exp(a)} =\\exp{\\ad_a}\n\\end{equation}\n\n\n\\subsection{Differential of the exponential map} There are multiple ways to represent the differential of $\\exp(\\cdot)$ at a point $a\\in \\mathfrak g$. Let us start by the following definition of the differential map at $a\\in\\mathfrak g$\n\\begin{equation}\n  \\label{eq:147}\n  \\begin{array}{lcl}\n    \\exp_a' & : & \\mathfrak g \\rightarrow  T_{exp(a)}\\mathcal G\\\\\n            & &  v \\mapsto \\exp'_a(v)  = \\left.\\frac{d}{dt} \\exp(a+tv)\\right|_{t=0}\n  \\end{array}\n\\end{equation}\nThe definition is very similar to the definition of the directional derivative of $\\exp$ in the direction $v \\in \\mathfrak g$ at a point $a\\in\\mathfrak g$. Using the expression \\eqref{eq:153} of the tangent space at $\\exp(a)$, we can defined another expression of the differential map denoted as $\\dlexp_a : \\mathfrak g  \\rightarrow \\mathfrak g$ such that\n\\begin{equation}\n  \\label{eq:156}\n  \\dlexp_a = L'_{\\exp^{-1}(a)} \\glaw \\exp_a' = L'_{\\exp(-a)} \\glaw \\exp_a' \n\\end{equation}\nThis expression appears as a trivialization of the differential map $\\exp'_a$. Using the expression of $L'_z$ in \\eqref{eq:152}.\nIn~\\cite[Theorem 2.14.13]{Varadarajan_book1984}, an explicit formula relates $\\dlexp_{a}$ to the iteration of the adjoint operator:\n\\begin{equation}\n  \\label{eq:43}\n  \\dlexp_a(b) = \\sum_{k=0}^\\infty \\frac{(-1)^k}{(k+1)!} (\\ad_a(b))^k \\coloneqq \\frac{e - \\exp\\glaw\\ad_a}{\\ad_a}(b)\n\\end{equation}\nwhere $(\\ad_a)^k$ is the kth iteration of the adjoint operator:\n\\begin{equation}\n  \\label{eq:44}\n  \\left\\{\\begin{array}[l]{l}\n    (\\ad_a)^k(b) = \\underbrace{[a, [ a, [ \\ldots, a, [ a, b]]]}_{k \\text{ times}} \\text{ for } k \\geq 1 \\\\\n    (\\ad_a)^0(b)  = b\n  \\end{array}\\right.\n\\end{equation}\nIt is also possible to define the right trivialized differential of the exponential map\n\\begin{equation}\n  \\label{eq:162}\n  \\drexp_a = R'_{\\exp^{-1}(a)} \\glaw \\exp_a' = R'_{\\exp(-a)} \\glaw \\exp_a' \n\\end{equation}\nthat is\n\\begin{equation}\n  \\label{eq:163}\n  \\drexp_a(b) = \\exp'_a(b) \\glaw \\exp(-a)\n\\end{equation}\nWith these expression, we have equivalently for \n\\begin{equation}\n  \\label{eq:157}\n   \\exp_a'(b)  = \\exp_a \\glaw \\dlexp_a(b)\\quad \\text{ and } \\exp_a'(b)  = \\drexp_a(b) \\glaw   \\exp(a)\n\\end{equation}\n\n\nTo avoid to burden to much the notation, we introduced the unified definition of the differential map  that corresponds to $\\dexp=\\drexp$ \n\\begin{definition}\nThe differential of the exponential mapping, denoted by $\\dexp_a : \\mathfrak g \\times \\mathfrak g \\rightarrow \\mathfrak g$ is defined as the ``right trivialized'' tangent of the exponential map\n\\begin{equation}\n  \\label{eq:42}\n  \\frac{d}{dt} (\\exp(a(t))) = \\dexp_{a(t)}(a'(t)) \\exp(a(t))\n\\end{equation}\n\\end{definition}\nAn explicit formula relates $\\dexp_{a}$ to the iteration of the adjoint operator:\n\\begin{equation}\n  \\label{eq:43}\n  \\dexp_a(b) = \\sum_{k=0}^\\infty \\frac{1}{(k+1)!} (\\ad_a(b))^k \\coloneqq \\frac{\\exp\\glaw\\ad_a-e}{\\ad_a}(b)\n\\end{equation}\n\n\n\\begin{ndrva}\n  Say what is not the Jacobian in $\\RR^4$\n\\end{ndrva}\n\nAs for $\\Ad_a$ and $\\ad_a$, the mapping $\\dexp_{a}(b)$ is a linear mapping in its second argument for a fixed $a$. Using the relation~\\eqref{eq:164}, we can also relate the right and the lest trivialization tangent\n\\begin{equation}\n  \\label{eq:165}\n\\dlexp_a (b) =   (\\Ad_{\\exp(a)} \\glaw \\dexp(a))(b) = (\\exp(\\ad_{-a}) \\glaw \\frac{e - \\exp\\glaw\\ad_a}{\\ad_a})(b) = \\frac{e - \\exp\\glaw\\ad_{-a}}{\\ad_a}(b) = \\dexp_{-a}(b)\n\\end{equation}\nIt is also possible to define the  the ``left trivialized'' tangent of the exponential map\n\\begin{equation}\n  \\label{eq:46}\n   \\frac{d}{dt} (\\exp(a(t))) =  \\exp(a(t)) \\dlexp_{a(t)}(a'(t)) = \\exp(a(t)) \\dexp_{-a(t)}(a'(t)) \n\\end{equation}\n\n\\begin{ndrva}\n  other notation and Lie derivative\n  \\begin{equation}\n    \\label{eq:178}\n      Df \\cdot \\widehat \\Omega (p) = (\\widehat \\Omega^r f )(p) \n  \\end{equation}\n\\end{ndrva}\n\n\n\n\\paragraph{Inverse of the exponential map}\n\n\nThe function $\\dexp_{a}$ is an analytical function so it possible to invert it to get\n\\begin{equation}\n  \\label{eq:45}\n  \\dexp^{-1}_{a} = \\sum_{k=0}^\\infty \\frac{B_k}{(k)!} (\\ad_a)^k(b) \n\\end{equation}\nwhere $B_k$ are the Bernouilli number.\n\n\\subsection{Differential of a map $f : \\mathcal G \\rightarrow \\mathfrak g$}\n\nWe follow the notation developed in~\\cite{Owren.Welfert_BIT2000}. Let us first define the differential of the map $f : \\mathcal G \\rightarrow \\mathfrak g$ as\n\\begin{equation}\n  \\label{eq:166}\n  \\begin{array}[rcl]{rcl}\n    f'_z : T_z\\mathcal G &\\rightarrow&T_{f(z)}\\mathfrak g \\cong  \\mathfrak g\\\\\n    b &\\mapsto& \\left.\\frac{d}{dt} f(z\\glaw \\exp(t L'_{z^{-1}}(b))) \\right|_{t=0}\n  \\end{array}\n\\end{equation}\nThe image of $b$ by $f'_z$   is obtained by first identifying $b$ with an element of $v \\in \\mathfrak g$ thanks to the left representation of $T_{f(z)}\\mathfrak g$ view the left translation map $v= t L'_z(b)$. The exponential mapping transforms $v$ an element $y$ of the Lie Group $\\mathcal G$. Then $f'_z$ is obtained by\n\\begin{equation}\n  \\label{eq:167}\n  f'_z(b) = \\lim_{t\\rightarrow 0} \\frac{f(z\\glaw y) - f(z)}{t}\n\\end{equation}\nAs we have done for the exponential mapping, it is possible to get a left trivialization of  \n\\begin{equation}\n  \\label{eq:169}\n  \\dd f_z = (f\\glaw L_z)' = f'_z \\glaw L'_z\n\\end{equation}\nthus\n\\begin{equation}\n  \\label{eq:170}\n  \\dd f_z (a) =  f'_z \\glaw L'_z(a) = f'_z(L'_z(a)) =  \\left.\\frac{d}{dt} f(z\\glaw \\exp(t a )) \\right|_{t=0}\n\\end{equation}\n\n\\paragraph{Newton Method}\nLet us imagine that we want to solve $f(y) = 0 $ for $y \\in \\mathcal G$. A newton method can be written as \n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"DevNotes\"\n%%% End:\n\n", "meta": {"hexsha": "5b0f59fe51aa18b616aa1b173259e48c841e0b63", "size": 21072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sphinx/devel_guide/notes/LieGroupTheory.tex", "max_stars_repo_name": "ljktest/siconos", "max_stars_repo_head_hexsha": "85b60e62beca46e6bf06bfbd65670089e86607c7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 137, "max_stars_repo_stars_event_min_datetime": "2015-06-16T15:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T06:01:59.000Z", "max_issues_repo_path": "docs/sphinx/devel_guide/notes/LieGroupTheory.tex", "max_issues_repo_name": "ljktest/siconos", "max_issues_repo_head_hexsha": "85b60e62beca46e6bf06bfbd65670089e86607c7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 381, "max_issues_repo_issues_event_min_datetime": "2015-09-22T15:31:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T09:05:23.000Z", "max_forks_repo_path": "docs/sphinx/devel_guide/notes/LieGroupTheory.tex", "max_forks_repo_name": "ljktest/siconos", "max_forks_repo_head_hexsha": "85b60e62beca46e6bf06bfbd65670089e86607c7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2015-08-06T22:57:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T20:30:20.000Z", "avg_line_length": 46.9309576837, "max_line_length": 355, "alphanum_fraction": 0.6549449506, "num_tokens": 7665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.6722251021207089}}
{"text": "\\newpage\n\\section{Asymptotic convergence estimates for $H^m$ norm}\nIn this section, we will extend the previous asymptotic approximation analysis \nto $H^k$ Sobolev norm. \n\n\\subsection{Asymptotic error estimates}\n\\begin{theorem}\\label{approximation_rate_theorem}\n Let $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain. If the activation function $\\sigma\\in W^{m,\\infty}(\\mathbb{R})$ is non-zero and satisfies the polynomial decay condition \n \\begin{equation}\\label{growth_condition}\n  |\\sigma^{(k)}(t)| \\leq C_p(1 + |t|)^{-p}\n \\end{equation}\n for $0\\leq k\\leq m$ and some $p > 1$, we have\n \\begin{equation}\n  \\inf_{f_n\\in \\dnn(\\sigma,n)}\\|f - f_n\\|_{H^m(\\Omega)} \\leq |\\Omega|^{\\frac{1}{2}}C(p,m,\\text{\\normalfont diam}(\\Omega),\\sigma)n^{-\\frac{1}{2}}\\|f\\|_{\\mathcal{B}^{m+1}},\n \\end{equation}\n for any $f\\in \\mathcal{B}^{m+1}$.\n\\end{theorem}\nBefore we proceed to the proof, we discuss how this bound depends on\nthe dimension $d$. We first note that $|\\Omega|$ may in a sense depend\non the dimension, as the measure may be exponentially large in high\ndimensions. However, bounding the $H^m$ error over a larger set is\nalso proportionally stronger. This can be seen by noting that dividing\nby the $|\\Omega|^\\frac{1}{2}$ factor transforms the left hand side\nfrom the total squared error to the average squared error.\n\nThe dimension dependence of this result is a consequence of how the\nBarron norm behaves in high dimensions. This issue is discussed in\n\\cite{barron1993universal}, where the norm $\\|\\cdot\\|_{\\mathcal{B}^1}$\nis analyzed for a number of different function classes. A particularly\nrepresentative result found there is that $H^{\\frac{d}{2}+2}\\subset\n\\mathcal{B}^1$. This shows that sufficiently smooth functions have\nbounded Barron norm, where the required number of derivatives depends\nupon the dimension. It is known that approximating functions with such\na dimension dependent level of smoothness can be done efficiently\n\\cite{petrushev1998approximation, kainen2007sobolev}. However, the\nBarron space $\\mathcal{B}^1$ is significantly larger that\n$H^{\\frac{d}{2}+2}$, in fact we only have $\\mathcal{B}^1 \\subset H^1$\nby lemma \\ref{smoothness-lemma}. The precise properties of the Barron\nnorm in high dimensions are an interesting research direction which\nwould help explain exactly how shallow neural networks help alleviate\nthe curse of dimensionality.\n\n\n\\begin{proof}\nGiven the integral representation given by Lemma~\\ref{lem:sampleHk}, we follow\na similar line of reasoning as in \\cite{barron1993universal}. Our\nargument differs from previous arguments in how we write $f$ as convex\ncombination of shifts and dilations of $\\sigma$. This is what allows\nus to relax our assumptions on $\\sigma$. In order to do this, we must\nfirst find a way to normalize the above integral.\n \n The above integral is on an unbounded domain, but the decay\n assumption on the Fourier transform of $f$ allows us to normalize the\n integral in the $\\omega$ direction.  To normalize the integral in the\n $b$ direction, we must use the assumption that $x$ is bounded and\n that $\\sigma$ decays polynomially. Consider the $\\sigma$ part of the\n above integral representation,\n \\begin{equation}\n  D_x^\\alpha\\sigma\\left(\\frac{\\omega}{a}\\cdot x+b\\right).\n \\end{equation}\n Note that by the triangle inequality and the boundedness of $x\\in\n \\Omega$, we can obtain a lower bound on the above argument uniformly\n in $x$. Specifically, we have\n \\begin{equation}\n  \\left|\\frac{\\omega}{a}\\cdot x+b\\right| \\geq \\max\\left(0,|b| - \\frac{R\\|\\omega\\|}{|a|}\\right),\n \\end{equation}\n where $R$ is the maximum norm of an element of $\\Omega$. Note that\n without loss of generality, we can translate $\\Omega$ so that it\n contains the origin and so $R \\leq \\text{\\normalfont diam}(\\Omega)$.\n \nCombining this with the polynomial decay of $\\omega$ \\eqref{growth_condition} implies that\n\\begin{equation}\\label{eq_779}\n  \\left|\\sigma^{(k)}\\left(\\frac{\\omega}{a}\\cdot x+b\\right)\\right| \\leq C_p\\left(1 + \\left|\\frac{\\omega}{a}\\cdot x+b\\right|\\right)^{-p} \\leq C_p\\left(1 + \\max\\left(0,|b| - \\frac{R\\|\\omega\\|}{|a|}\\right)\\right)^{-p}.\n\\end{equation}\nThus the function $h$ defined by \n \\begin{equation}\\label{h_definition}\n  h(b,\\omega) = \\left(1 + \\max\\left(0,|b| - \\frac{R\\|\\omega\\|}{|a|}\\right)\\right)^{-p}\n \\end{equation}\n provides (up to a constant) an upper bound on\n $\\sigma^{(k)}\\left(\\frac{\\omega}{a}\\cdot x+b\\right)$ uniformly in\n $x$.  The decay rate of $h$ is fast enough to make it integrable in\n $b$. Moreover, its integral in $b$ grows at most linearly with\n $\\omega$. Namely, we calculate\n \\begin{equation}\\label{eq_775}\n \\begin{split}\n  \\int_\\mathbb{R} h(\\omega,b)db& = \\int_{|b|\\leq \\frac{R\\|\\omega\\|}{|a|}} db + 2\\int_{b > \\frac{R\\|\\omega\\|}{|a|}} \\left(1 + b - \\frac{R\\|\\omega\\|}{|a|}\\right)^{-p}db \\\\\n  & =~2R|a|^{-1}\\|\\omega\\| + 2\\left[(1-p)^{-1}\\left(1 + b - \\frac{R\\|\\omega\\|}{|a|}\\right)^{1-p}\\right]_{\\frac{R\\|\\omega\\|}{|a|}}^\\infty \\\\\n  &=~2R|a|^{-1}\\|\\omega\\| + \\frac{2}{p-1}\\leq C_1(p,\\text{\\normalfont diam}(\\Omega),\\sigma) (1 + \\|\\omega\\|).\n  \\end{split}\n \\end{equation}\n\\end{proof}\n\n Finally, we note that the approximation rate in this theorem holds as long as the growth condition \\eqref{growth_condition}\n hold for some $f\\in \\dnn(\\sigma)$, i.e. the condition \\eqref{growth_condition} need not hold for $\\sigma$ itself.\n We state this as a corollary below.\n \\begin{corollary}\\label{GeneralApproximation}\n  Let $\\sigma\\in W^{m,\\infty}_{loc}(\\mathbb{R})$ be an activation function and suppose that there exists a $\\nu\\in \\Sigma_1^{n_0}(\\sigma)$ which satisfies the polynomial decay condition \\eqref{growth_condition} in Theorem \\ref{approximation_rate_theorem}. Then for any $f$ satisfying the assumptions of Theorem \\ref{approximation_rate_theorem}, we have\n  \\begin{equation}\n     \\inf_{f_n\\in \\dnn(\\sigma,n)}\\|f - f_n\\|_{H^m(\\Omega)} \\leq |\\Omega|^{\\frac{1}{2}}C(p,m,\\text{\\normalfont diam}(\\Omega),\\sigma)\\sqrt{n_0}\\|f\\|_{\\mathcal{B}^{m+1}}n^{-\\frac{1}{2}}.\n  \\end{equation}\n\n \\end{corollary}\n \\begin{proof}\n The result follows immediately from Theorem \\ref{approximation_rate_theorem} and the observation that $v\\in \\dnn(\\sigma,n_0)(\\sigma)$ implies that\n \\begin{equation}\n  \\dnn(\\nu,n) \\subset \\dnn(\\sigma,nn_0)(\\sigma).\n \\end{equation}\n\n \\end{proof}\n\nNext, we consider the case of periodic activation functions. We show that neural networks with periodic activation functions achieve the same rate of approximation in Theorem \\ref{approximation_rate_theorem}. The argument makes use of a modified integral representation and allows us to relax the smoothness condition on $f$, which now only has to be in $\\mathcal{B}^m$.\n\\begin{theorem}\\label{periodic-activation}\n Let $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain. If the activation function $\\sigma\\in W^{m,\\infty}(\\mathbb{R})$ is a non-constant periodic function, we have\n \\begin{equation}\n  \\inf_{f_n\\in \\dnn(\\sigma,n)}\\|f - f_n\\|_{H^m(\\Omega)} \\leq |\\Omega|^{\\frac{1}{2}}C(\\sigma)n^{-\\frac{1}{2}}\\|f\\|_{\\mathcal{B}^m},\n \\end{equation}\n for any $f\\in \\mathcal{B}^{m}$.\n\\end{theorem}\n\\begin{proof}\n Using the integrability condition on $\\hat{f}$, we define the probability distribution on $\\mathbb{R}^d \\times [0,2\\pi]$ as\n \\begin{equation}\n  d\\lambda = \\frac{1}{2\\pi\\|f\\|_{\\mathcal{B}^m}}(1 + |\\omega|)^m|\\hat{f}(x)|dxdb.\n \\end{equation}\n Then $f(x)$ can be written\n \\begin{equation}\\label{periodic_representation}\n f(x) = \\mathbb{E}_{d\\lambda}\\left(\\|f\\|_{\\mathcal{B}^m}|a_i|^{-1}(1 + |\\omega|)^{-m}\\chi(\\omega,b)\\sigma\\left(\\omega\\cdot x + b\\right)\\right).\n \\end{equation}\n We have now written $f\\in \\mathcal{B}^m\\subset H^m(\\Omega)$ as a convex combination of functions $f_{\\omega,b}\\in H^m(\\Omega)$. As in the proof of \\ref{approximation_rate_theorem}, we now utilize Lemma 1 in \\cite{barron1993universal} and proceed to bound $\\|f_{\\omega,b}\\|_{H^m(\\Omega)}$ using much the same argument.\n\\end{proof}\n", "meta": {"hexsha": "77797e50adf8478b13d8c9f2dc6a8276ee5d0aba", "size": 7861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Barron-Hk.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/Barron-Hk.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/Barron-Hk.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.4692307692, "max_line_length": 370, "alphanum_fraction": 0.7112326676, "num_tokens": 2522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.6722250660383764}}
{"text": "\\section{Compactification}\n\\begin{figure}\n  \\centering\n  \\input{images/RamifiedCoverings1.tex}\n  \\caption{Not sure how to adjust width in this case.}\n\\end{figure}\nWe saw that the Riemann surface $\\Gamma_{p(z)}$ is homeomorphic to $\\bbc$.\n\nWe can generalize the previous constructions to studying graphs of\n\\begin{align*}\n  p(z) &= w^p \\\\\n  p(z,w) &= 0\n\\end{align*}\nBut before we do this, we need to make one more leap which is again inspired from topology.\n\nThe surface $\\Gamma_{p(z)}$ costructed above is not compact.\nNon-compact objects are harder\\footnote{In most case, but of course not always.} to study than compact ones because the behaviour of limits is harder to control for non-compact surfaces and functions on non-compact .\n\\begin{qbox}(Optional exercise)\n  Let $X$ be a subset of $\\bbc$.\n  \\begin{enumerate}\n    \\item Show that if $X$ is compact then every function $f:X \\rightarrow \\bbr$ is bounded.\n    \\item If $X$ is open, find an unbounded continuous function $f:X \\rightarrow \\bbc$.\n  \\end{enumerate}\n\\end{qbox}\nFurthermore, non-compact subsets come in all shapes and sizes (for example, every open subset of $\\bbc$ is non-compact) but as we'll see in the next section there are various classification theorems for compact ones.\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Behaviour at $\\infty$}\n", "meta": {"hexsha": "16fbf7f1d17d2bc3c941f25d57707b7945545c10", "size": 1294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02.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": "02.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": "02.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": 34.0526315789, "max_line_length": 216, "alphanum_fraction": 0.7357032457, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6722008548428131}}
{"text": "\\section{Polymorphism}\n\n\\begin{frame}[fragile,fragile]\n  \\frametitle{Introduction}\n  Take a language such as $\\lggeEF$ with base types $\\enum{}$ and\n  $\\estr{}$ and product types.\n  \n  Can we define \\emph{one} function which takes a triple (e.g.,\n  $\\cpair{a}{\\cpair{b}{c}}$) and returns the middle element (i.e., $b$)?\n\n  % \\bigskip\n\n  \\[\n  \\elam{\\typrod{\\enum{}}{\\typrod{\\enum{}}{\\enum{}}}}{x}{ \\eprl{\\eprr{\\var x}}}\n  \\]\n  \n  \\begin{lstlisting}[language=Haskell]\n-- Haskell\nmiddle :: (t1,(t2,t3)) -> t2\nmiddle (x,(y,z)) = y\n\\end{lstlisting}\n  \n\\begin{lstlisting}[language=Java]\n// Java\n// (assume class Pair<T, V> exists)\npublic <S> S getMiddle(Pair<T,Pair<S,V>> triple){\n  return triple.getRight().getLeft();\n}\n\\end{lstlisting}\n\n\\bigskip\n  \n  More examples?\n  \n\\end{frame}\n\n\n\n\\begin{frame}\n  \\frametitle{Polymorphicity}\n  \\begin{itemize}\n  \\item The term \\emph{polymorphism} refers to a range of language mechanisms\n    that allow a single part of a program to be used with different\n    types in different contexts.\n    % \n  \\item The languages we have considered so far are all\n    \\emph{monomorphic} in that every expression has at most \\emph{one}\n    type (given the types of its free variables).\n    % \n  \\item \\emph{Overloading} is a form of ``ad-hoc polymorphism''. It\n    associates a single function symbol with many implementations.\n    The compiler chooses an appropriate implementation for each\n    application of the function, based on the types of the arguments.\n  \\end{itemize}\n\\end{frame}\n\n\\subsection{Syntax}\n\n\\begin{frame}\n  \\frametitle{Language $\\lggeF$}\n  \\[\n  \\begin{array}{llclll}\n    \\TYPES & \\tau & \\Coloneqq & \\tvar{t} & \\tvar{t} & \\text{type variable}\n    \\\\ \n           &&& \\tyarr{\\tau_1}{\\tau_2}  & \\tau_1 \\rightarrow \\tau_2 & \\text{function}\n    \\\\\n           &&& \\tyall{t}{\\tau} & \\ctyall{t}{\\tau} & \\text{polymorphic}\n    \\\\\n    \\\\\n    \\EXPS & e & \\Coloneqq & \\var{x} & \\var{x} & \\text{variable}\n    \\\\\n           &&& \\elam{\\tau}{x}{e} & \\clam{\\tau}{x}{e} & \\text{abstraction}\n    \\\\\n           &&& \\eapp{e_1}{e_2} & \\capp{e_1}{e_2} & \\text{application}\n    \\\\\n           &&& \\eLAM{t}{e} & \\cLAM{t}{e} & \\text{type abstraction}\n    \\\\\n           &&& \\eAPP{\\tau}{e} & \\cAPP{\\tau}{e} & \\text{type application}\n  \\end{array}\n  \\]\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Exercises}\n  \\begin{itemize}\n  \\item Define the identify function ($\\texttt{id}(x) = x$)\n  \\item Define a polymorphic function to compose function together ($f \\circ g = f(g(x))$)\n  \\item Any more ``standard'' polymorphic functions?\n  \\end{itemize}\n\\end{frame}\n\n% L(T) . \\x:t . x\n% L(T1) . L(T2) . L(T2) \\f:T2->T3 \\g:T1->T2 = f(g(x))\n\n\n\\subsection{Statics}\n\n\\begin{frame}\n  \\frametitle{Judgements}\n\n  Two judgement forms and two kinds of environments, the hypotheses in\n  $\\Delta$ have the form $\\tvar{t} \\ \\typeok$, where $\\tvar{t}$ is a\n  variable of sort $\\TYPES$ and the hypotheses in $\\Gamma$ have the\n  form $\\var{x} : \\tau$, where $\\var{x}$ is a variable of sort $\\EXPS$.\n\n  \\bigskip\n\n  \\begin{itemize}\n  \\item   {\\Huge\n      $    \n      {\\typejudge{\\Delta}{\\tau}}\n      $   \n    }\n\n    says that the type $\\tau$ is well-formed, under the hypotheses in $\\Delta$\n\n    \\bigskip\n\n  \\item   {\\Huge\n      $    \n      {\\tyFjudge{\\Delta}{\\Gamma}{e}{\\tau}}\n      $   \n    }\n    \n    says that the expression $e$ has type $\\tau$, under  the hypotheses in $\\Delta$ and $\\Gamma$\n  \\end{itemize}\n\\end{frame}\n\n\n\n\\note{As usual, we write $\\varnothing$ for the empty context $\\Delta$ or $\\Gamma$}\n\n\n\\begin{frame}\n  \\frametitle{Well-formed types}\n \\[\n  \\tyrule\n  {}\n  {\\,}\n  {\\typejudge{\\Delta, \\tvar{t} \\ \\typeok , \\Delta_2}{\\tvar{t}} }\n  \\]\n\n  \n  \\[\n  \\tyrule\n  {}\n  {\n    \\typejudge{\\Delta}{\\tau_1}\n    \\and\n    \\typejudge{\\Delta}{\\tau_2}\n  }\n  {\\typejudge{\\Delta}{\\tyarr{\\tau_1}{\\tau_2}} }\n  \\]\n\n  \n  \\[\n  \\tyrule\n  {}\n  {\n    \\typejudge{\\Delta, \\tvar{t} \\ \\typeok }{\\tau}\n  }\n  {\\typejudge{\\Delta}{\\tyall{t}{\\tau}} }\n  \\]\n  \n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Examples}\n  Are these types well-formed?\n  \\begin{itemize}\n  \\item $\\tyall{t}{\\tyarr{\\tvar t}{\\tvar t}}$\n  \\item $\\tyall{t_1}{\\tyall{t_2}{\\tvar{t_1}}}$\n  \\item $\\tyall{t_1}{\\tyall{t_2}{\\tyarr{\\tvar{t_2}}{\\tvar{t_1}}}}$\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Typing judgements (1)}\n  \\[\n  \\tyrule\n  {\\ftyrulename{var}}\n  {\\,}\n  {\\tyFjudge{\\Delta}{\\Gamma_1, \\var{x}: \\tau, \\Gamma_2 }{\\var{x}}{\\tau} }\n  \\]\n\n\n  \\[\n  \\tyrule\n  {\\ftyrulename{lam}}\n  {\\tyFjudge{\\Delta}{\\Gamma, \\var{x} : \\tau_1}{e}{\\tau_2}}\n  {\\tyFjudge{\\Delta}{\\Gamma}{\\elam{\\tau_1}{x}{e}}{\\tyarr{\\tau_1}{\\tau_2}}}\n  \\]\n\n  \\[\n  \\tyrule\n  {\\ftyrulename{ap}}\n  {\n    \\tyFjudge{\\Delta}{\\Gamma}{e_1}{\\tyarr{\\tau_1}{\\tau_2}}\n    \\and\n    \\tyFjudge{\\Delta}{\\Gamma}{e_2}{\\tau_2}\n  }\n  {\n    \\tyFjudge{\\Delta}{\\Gamma}{\\eapp{e_1}{e_2}}{\\tau_2}\n  }\n  \\]\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Typing judgements (2)}\n  \n\n  \\[\n  \\tyrule\n  {\\ftyrulename{tlam}}\n  {\\tyFjudge{\\Delta, \\tvar{t} \\ \\typeok}{\\Gamma}{e}{\\tau}}\n  {\n    \\tyFjudge{\\Delta}{\\Gamma}{\\eLAM{t}{e}}{\\tyall{t}{\\tau}}\n  }\n  \\]\n\n\n  \\[\n  \\tyrule\n  {\\ftyrulename{tap}}\n  {\n    \\typejudge{\\Delta}{\\tau}\n    \\and\n    \\tyFjudge{\\Delta}{\\Gamma}{e}{\\tyall{t}{\\tau'}}\n  }\n  {\n    \\tyFjudge{\\Delta}{\\Gamma}{\\eAPP{\\tau}{e}}{\\tsubs{\\tau'}{\\tau}{t}}\n  }\n  \\]\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Examples}\n  Assuming we have product types, do these expression have a type?\n  \\begin{itemize}\n  \\item $\\eLAM{t}{\\elam{\\tvar{t}}{x}{\\var x}}$\n  \\item $\\eLAM{t}{\\elam{\\typrod{\\tvar{t}}{\\typrod{\\tvar{t}}{\\tvar{t}}}}{x}{ \\eprl{\\eprr{\\var x}}}}$\n  \\item Check for the solution of $f \\circ g$\n  \\end{itemize}\n\\end{frame}\n\n% let as lambda => (\\id . <id \"hello\", id 123>) (\\x . x)\n\n\n\\subsection{Semantics}\n\n\\begin{frame}\n  \\frametitle{Dynamics}\n  \\textbf{Call-by-name} semantics\n  \\[\n  \\semrule\n  {\\fsemrulename{lam}}\n  {\\,}\n  {\\valjudge{\\elam{\\tau}{x}{e}}}\n  \\]\n\n  \\[\n  \\semrule\n  {\\fsemrulename{tlam}}\n  {\\,}\n  {\\valjudge{\\eLAM{t}{e}}}\n  \\]\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Dynamics}\n  \\[\n  \\semrule\n  {\\fsemrulename{ap}}\n  {\\jtrans{e_1}{e'_1}}\n  {\n    \\jtrans{\\eapp{e_1}{e_2}}{\\eapp{e'_1}{e_2}}\n  }\n  \\]\n\n  \\[\n  \\semrule\n  {\\fsemrulename{lav}}\n  {\\,}\n  {\\jtrans{\\eapp{\\elam{\\tau}{x}{e_1}}{e_2}}{\\subs{e_1}{e_2}{x}}}\n  \\]\n\\end{frame}\n\n\n\n\n\\begin{frame}\n  \\frametitle{Dynamics}\n  \\[\n  \\semrule\n  {\\fsemrulename{ap}}\n  {\\,}\n  {\n    \\jtrans\n    {\\eAPP{\\tau}{\\eLAM{t}{e}}}\n    {\\tsubs{e}{\\tau}{t}}\n  }\n  \\]\n\n  \\[\n  \\semrule\n  {\\fsemrulename{lav}}\n  {\\jtrans{e}{e'}}\n  {\n    \\jtrans\n    {\\eAPP{\\tau}{e}}\n    {\\eAPP{\\tau}{e'}}\n  }\n  \\]\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Expressivity of $\\lggeF$}\n  Product and sum type can be expressed with the construct\n  of $\\lggeF$!\n  %\n  See Chapter 16.2 of PFPL.\n\\end{frame}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "281c3a0ea1ae996c354a7990ab9e1cf5aede02a5", "size": 6781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/language-f.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/language-f.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/language-f.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": 20.2417910448, "max_line_length": 99, "alphanum_fraction": 0.5805928329, "num_tokens": 2598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6722008494072004}}
{"text": "\\section{Introduction}\n\nOur aim is to provide a tool with which one can easily identify \nthe optimal quantum query complexity as well as corresponding \nquery optimal quantum algorithm for a given Boolean function. This\ngives researchers an easy \nway to identify problems for which a quantum computer \nis better suited than a classical computer. It has been shown that\nthere are many functions for which this is the case, such as\nsearch and factoring.\n\nWe say that a function is better suited to a quantum computer than a classical computer if a quantum computer could evaluate the function more efficiently. Generally, we would measure this efficiency by runtime, but the runtime of a quantum computer for a given function is difficult to calculate. Instead, we can approximate the runtime with the algorithm's query complexity. To evaluate a function the algorithm must query the inputs to gain information about the given problem and the number of queries required is the query complexity.\n\nFor example, if we take a look at the search function, which is a generalization of the single bit OR function, where there is a bit string input and we return a $1$ to indicate that there is a one somewhere in the input bitstring, and a $0$ if there is not. In a classical computer, in the worst case, we would need to examine all input bits to evaluate this function, which would take $n$ queries for a bitstring of length $n$. However, there exists a quantum implementation of the search function that only requires $\\sqrt{n}$ queries of the input bitstring \\cite{grover1996fast}--- this is the query optimal quantum algorithm. In this case, there is a large advantage in using a quantum computer as opposed to a classical computer. \n\nWhile the optimal quantum query complexity of the search function has been shown to be $\\sqrt{n}$, and the query optimal quantum algorithm is known, it is clearly of great interest to identify other functions like search where it would be substantially more efficient to use a quantum computer instead of a classical one. To aid in this search, we have implemented an algorithm that takes a Boolean function and returns the optimal quantum query complexity as well as the query optimal quantum algorithm in the form of a span program. We hope that these results can help build more efficient quantum algorithms and help us better understand the advantages of quantum computers.\n\n\\begin{comment}\nGiven\n\nWhy quantum computers\nWhy we care about query complexity\n\nQuantum computers have many advantages over classical computers as\nalgorithms for a given function can be substantially less time\ncomplex on quantum computers. More specifically, in many of these\nexamples, such as search and factoring, quantum computers require\nsignificantly fewer queries of the function input. For an\nexample, a classic search algorithm for a bit string of length\n$n$ could take up to $n$ queries to see if a $1$ is present.\nHowever, quantum computers only require $\\sqrt{n}$ queries of the\ninput.\n\nIt is then of great interest to identify these functions to\nunderstand the advantages of quantum computers over classical\ncomputers. We implement such a tool for Boolean functions. We\ncalculate the asymptotic quantum query complexity of a given\nfunction which provides a lower bound of run time for a quantum\ncomputer. Furthermore, for each Boolean function, we can also\nprovide a query optimal quantum algorithm such that this optimal\nalgorithm could be implemented to achieve the potential\nimprovement over classical computers.\n\n\\end{comment}", "meta": {"hexsha": "f63720369cd91739f4e14ff5bf0b9962b6f7c2f0", "size": 3553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "conference/sec/intro.tex", "max_stars_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_stars_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "conference/sec/intro.tex", "max_issues_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_issues_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "conference/sec/intro.tex", "max_forks_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_forks_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.75, "max_line_length": 736, "alphanum_fraction": 0.8088938925, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385543, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.6722008460299813}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 1}\nThe radioactive isotope $^{233}$Pa can be produced following neutron capture by $^{232}$Th when the resulting $^{233}$Th decays to $^{233}$Pa. In the neutron flux of a typical reactor, neutron capture in 1 g of $^{232}$Th produces $^{233}$Th at of a rate of $2.0 \\times 10^{11}\\text{ s}^{-1}$.\n\\begin{enumerate}[a)]\n\\item What are the activities (in Ci) of $^{233}$Th and $^{233}$Pa after this sample is irradiated for 1.5 hours?\n\\item The sample is then placed in storage with no further irradiation so that the $^{233}$Th can decay away. What are\nthe activities (in Ci) of $^{233}$Th and $^{233}$Pa after 48 hours of storage?\n\\item The decay of $^{233}$Pa results in $^{233}$U, which is also radioactive. After the above sample has been stored for 1 year what is the $^{233}$U activity in Ci? (Hint: it should not be necessary to set up an additional differential equation to find the $^{233}$U activity.)\n\\end{enumerate}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\tNucleus\t\t&\tHalf-life \\\\\n\t\t\t\\hline\n\t\t\t$^{233}$Th\t&  $22.3$ min\\\\\n\t\t\t$^{233}$Pa\t&  $27.0$ days\\\\\n\t\t\t$^{233}$U\t&  $1.592 \\times 10^5$ yr\\\\\n\t\t\t\\hline\n\t\\end{tabular}\n\t\\label{tab:design-specs}\n\\end{table}\n\\begin{center}$1\\text{ Ci} = 3.7 \\times 10^{10}\\text{ s}^{-1}$\\end{center}\n", "meta": {"hexsha": "88c12feb7f1b8bafe3944fc0626f23627f73fa2f", "size": 1369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc01/disc01_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/disc01/disc01_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/disc01/disc01_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": 54.76, "max_line_length": 293, "alphanum_fraction": 0.6355003652, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744584140003, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6722008295382502}}
{"text": "\\section{Transpose}\n\\label{transpose}\n\nMatrix transpose seems an unlikely candidate for\nSIMD optimization, but there are at least two cases\nwhere it has been applied in APL.\n\nOur implementation of transpose for SHARP APL performed\nan optimization, similar to the one we used in rotate, on \nall array types. A dyadic transpose that leaves one or\ntrailing axes in place moves those elements as a unit,\nusing rbemove or its equivalent, {\\em e.g.}:\n\n\\medskip\n\n{\\apl T\\qlarrow\\02~2~3~3\\qrho\\qiota\\036\\\\\n~~0~~1~~2\\\\\n~~3~~4~~5\\\\\n~~6~~7~~8\\\\\n\\\\\n~~9~10~11\\\\\n12~13~14\\\\\n~15~16~17\\\\\\\n\\\\\n~18~19~20\\\\\n~21~22~23\\\\\n~24~25~26\\\\\n\\\\\n~27~28~29\\\\\n~30~31~32\\\\\n~33~34~35\\\\}\n\n\n{\\apl 1~0~2~3\\qtran\\0T\\\\\n~~0~~1~~2\\\\\n~~3~~4~~5\\\\\n~~6~~7~~8\\\\\n~\\\\\n~18~19~20\\\\\n~21~22~23\\\\\n~24~25~26\\\\\n~\\\\\n~\\\\\n~~9~10~11\\\\\n12~13~14\\\\\n15~16~17\\\\\\\n\\\\\n27~28~29\\\\\n30~31~32\\\\\n33~34~35\\\\}\n\n\\noindent\nA more interesting transpose algorithm applies to \nBoolean arrays whose shape is a multiple of eight\non its last two axes. Monadic transpose \n({\\em e.g.}, {\\apl \\qtran\\010000 75000\\qrho\\00 1}), or a \ndyadic transpose that interchanges only the last two argument axes\n({\\em e.g.}, {\\apl 0 2 1\\qtran\\03 10000 75000\\qrho\\00 1}), can exploit\nan algorithmic kernel for transposing Boolean arrays of shape {\\apl 8~8} \nthat appears, at very least, in \n{\\em Hacker's Delight}.\\cite{Warren:2012:HD:2462741}\nThe algorithm performs 16 logical and shift operations on\na 64-bit value that contains the ravel of the array, and\nproduces the transposed value as its result. The 8x8 results of\napplying this transpose kernel are copied into the final result of the\nlarger array transpose. Jay Foad's implementation of this\napproach for Dyalog APL produced a speedup of about ten times,\nfor 10000x75000 Boolean arrays.\\cite{JFoad:pc2016}.\nSection~\\ref{compressexpand} describes two vector instructions,\n{\\tt PDEP} and {\\tt PEXT},\nthat appear in some recent machine architectures; {\\tt PDEP} can\nbe used to implement the above transpose kernel.\nA {\\em perfect shuffle}, as its name suggests, splits an array into\ntwo halves, then selects elements from alternate halves.\nFoad noted that two {\\tt PDEP} instructions and an {\\tt OR} produce a\nhighly efficient perfect shuffle verb, modeled in APL as {\\apl S},\nand that composing {\\apl S} three times produces the \ntranspose kernel described above:\n\n{\\apl S\\qlarrow\\qlbrace\\qomega\\qlbr\\qugrade\\qlpar\\qrho\\qomega\\qrpar\\qrho\\00~1\\qrbr\\qrbrace}\\\\\n\n{\\apl T\\qlarrow\\08~8\\qrho\\qiota\\064\\\\\n\n{\\apl 8~8\\qrho\\0S~S~S~\\qcomma\\0T}\\\\\n0~~8~16~24~32~40~48~56\\\\\n1~~9~17~25~33~41~49~57\\\\\n2~10~18~26~34~42~50~58\\\\\n3~11~19~27~35~43~51~59\\\\\n4~12~20~28~36~44~52~60\\\\\n5~13~21~29~37~45~53~61\\\\\n6~14~22~30~38~46~54~62\\\\\n7~15~23~31~39~47~55~63\\\\\n}\n\n\\noindent In general, any square array, {\\apl T}, \nwhose shape vector is all powers of two, can be transposed with this verb,\nwhere {\\apl POW} is the APL {\\em power} conjunction.\n\n{\\apl TR\\qlarrow\\qlbrace\\0S POW\\qlpar\\02\\qlog\\01\\qrho\\qrho\\qomega\\qrpar\\qomega\\qrbrace}\n\n\\noindent We plan to investigate SIMD algorithms\nfor efficient transposition of Boolean arrays of shapes other than\npowers of two.\n\nFoad pointed out that the IBM POWER architecture\nincludes the {\\tt vgbbd} instruction, which can perform\ntwo 8x8 Boolean transposes at once. \nHe notes that its performance is less than that of straightforward \nC code, because execution time is dominated by\nargument setup and result storing for the {\\tt vgbbd} instruction.\n\n", "meta": {"hexsha": "27dc7722728c4985365b3a98eb00fe75a0b6eba3", "size": 3422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/LatexTemplate/BooleanSIMD/transpose.tex", "max_stars_repo_name": "bernecky/apex", "max_stars_repo_head_hexsha": "cee572d7a1a52f46d35ba47c64e6363acdd69ee8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:17:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T04:17:56.000Z", "max_issues_repo_path": "Docs/LatexTemplate/BooleanSIMD/transpose.tex", "max_issues_repo_name": "bernecky/apex", "max_issues_repo_head_hexsha": "cee572d7a1a52f46d35ba47c64e6363acdd69ee8", "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/LatexTemplate/BooleanSIMD/transpose.tex", "max_forks_repo_name": "bernecky/apex", "max_forks_repo_head_hexsha": "cee572d7a1a52f46d35ba47c64e6363acdd69ee8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5535714286, "max_line_length": 93, "alphanum_fraction": 0.7267679719, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.6721281560180654}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 11, 2022}\n\\subsection{Elgamal \\emph{continued}}\n\n\\recall we perform Elgamal by starting with a prime $p$ and $g\\in (\\ZZ/p\\ZZ)^\\times$ which is \\emph{public knowledge}.\n\nAlice computes $a$ which is her \\emph{private key}, and $A = g^{a}$ which is her \\emph{public key}.\n\n\\textbf{Encryption:} Bob generates a random $k$ and sends Alice\n\\[c_0\\equiv g^k\\mod{p}\\qquad c_1\\equiv mA^k\\mod{p}\\]\n\n\\textbf{Decryption:} Alice computes\n\\[c_1\\cdot (c_0^a)^{-1}\\equiv m(g^a)^k \\left((g^k)^a\\right)^{-1}\\]\n\nWe continue as we did from last time:\n\\begin{lstlisting}[language=Python]\nimport ext_gcd, pow_mod\nfrom random import randrange\ndef e(A, m): \n    k = randrange(p)\n    return (pow_mod(g, k, p), m * pow_mod(A, k, p))\n\ndef d(a, c):\n    return c[1] * ext_gcd(pow_mod(c[0], a, p), p)[0]\n\\end{lstlisting}\nWhich works as intended (try it out!).\n\nWe note a property of Elgamal that there is an expansion factor of 2. It takes \\emph{twice} as much space to store $c$ as $m$. We note that the expansion factor is always at least $1$ (otherwise, we wouldn't be able to invert it).\n\n\\subsection{Midterm Details}\n\\emph{Feb 16 @ 2pm in class}. If remote, send email.\n\nTopics will include: \\emph{everything up to now} (literally right now).\n\nFocus: More theoretical, less computational. (Both are fair game!)\n\nResources: Pen/pencil, paper. No notes and no book. Nothing else.\n\nWeighting: 20\\% Midterm 1 and 30\\% on Final. 30\\% Midterm 2, 20\\% Homework. Half on written and half on in-class exams.\n\nProblem set \\#3 which is shorter than \\#2. (Good practice!)\n\nMidterm results/curve will be announced hopefully by Friday after the midterm.\n\n\\subsection{Introduction to Group Theory}\nGroups are an algebraic structure... they're sets endowed with an operation.\n\\begin{example}\n    We have that $(\\ZZ/p\\ZZ, +)$ and $((\\ZZ/p\\ZZ)^\\times, \\cdot)$ are both groups.\n    \\[\\begin{array}{rcc}\n            \\toprule\n                                & (\\ZZ/p\\ZZ, +)           & ((\\ZZ/p\\ZZ)^\\times, \\cdot )           \\\\ \\midrule\n            \\text{Identity:}    & 0+a=a                   & 1\\cdot a = a                          \\\\\n            \\text{Inverse:}     & a + (-a) = (-a) + a = 0 & a\\cdot a^{-1} = a^{-1}\\cdot a = 1     \\\\\n            \\text{Associative:} & a + (b + c) = (a+b)+c   & a\\cdot (b\\cdot c) = (a\\cdot b)\\cdot c \\\\\n            \\text{Commutative:} & a + b = b + a           & a\\cdot b = b\\cdot a                   \\\\ \\bottomrule\n        \\end{array}\\]\n\\end{example}\n\\begin{definition}[Group]\n    A group $G$ is a set plus an operation\n    \\[\\circ : G\\times G \\to G\\]\n    satisfying\n    \\begin{enumerate}\n        \\item \\emph{Identity:} There is $e\\in G$ with $e\\circ a = a\\circ e = a$.\n        \\item \\emph{Inverse:} For any $a\\in G$, there is $a^{-1}\\in G$ with\n              \\[a\\circ a^{-1} = a^{-1}\\circ a = e\\]\n        \\item \\emph{Associativity:} $a\\circ (b\\circ c)=(a\\circ b)\\circ c$\n    \\end{enumerate}\n    We additionally say $G$ is \\ul{Abelian} if we have\n    \\[a\\circ b = b\\circ a\\]\n\\end{definition}\n\n\\begin{definition}[Group Order]\n    The \\ul{order} of $G$ written $\\#G$ is the number of elements in group $G$. If the order is finite, we say $G$ is \\ul{finite}.\n\\end{definition}\n\\begin{example}\n    $(\\ZZ/p\\ZZ, +)$ and $((\\ZZ/p\\ZZ)^\\times, \\cdot)$ are both Abelian and finite.\n\\end{example}", "meta": {"hexsha": "239e69377ceabc28a828e03635ce3c023164b313", "size": 3318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-11.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-02-11.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-02-11.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": 43.0909090909, "max_line_length": 230, "alphanum_fraction": 0.6066907776, "num_tokens": 1090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.6721281521321165}}
{"text": "\\section{Weierstrass' Elliptic Functions}\r\nWe shall explore the definition and properties of the Weierstrass $\\wp$-functions, also known as Weierstrass' elliptic functions.\r\n\\subsection{The Definition}\r\nWe know that a non-constant elliptic function has degree at least $2$.\r\nThe Weierstrass $\\wp$-function on a lattice is a elliptic function that behaves like $z\\mapsto z^{-2}$ near any lattice point.\r\n\\begin{definition}\r\n    Let $\\Lambda$ be a lattice in $\\mathbb C^2$.\r\n    The associated Weierstrass $\\wp$-function is defined by\r\n    $$\\wp(z)=\\wp_\\Lambda(z)=\\frac{1}{z^2}+\\sum_{\\omega\\in\\Lambda\\setminus\\{0\\}}\\left(\\frac{1}{(z-\\omega)^2}-\\frac{1}{\\omega^2}\\right)$$\r\n\\end{definition}\r\nWe have A LOT to check.\r\n\\begin{lemma}\r\n    Let $\\Lambda=\\langle\\omega_1,\\omega_2\\rangle$ be a lattice in $\\mathbb C$ and $t\\in\\mathbb R$.\r\n    Then the sum\r\n    $$\\sum_{\\omega\\in\\Lambda\\setminus\\{0\\}}\\frac{1}{|\\omega|^t}$$\r\n    converges iff $t>2$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Consider the tilted square (or unit circle in $\\ell^1$ metric) $Q=\\{(t_1,t_2)\\in\\mathbb R^2:|t_1|+|t_2|=1\\}$.\r\n    By compactness, the continuous function $Q\\to\\mathbb R$ via $(t_1,t_2)\\to|t_1\\omega_1+t_2\\omega_2|$ attains its maximum $M$ and minimum $m$ on $Q$.\r\n    $m\\neq 0$ since $\\omega_1,\\omega_2$ needs to be linearly independent over $\\mathbb R$.\r\n    So $0<m\\le t_1\\omega_1+t_2\\omega_2\\le M<\\infty$ for any $t_1,t_2\\in Q$.\r\n    Consider $(k,l)\\in\\mathbb Z^2\\setminus\\{0\\}$ and take\r\n    $$t_1=\\frac{k}{|k|+|l|},t_2=\\frac{l}{|k|+|l|}$$\r\n    Therefore $m(|k|+|l|)\\le |k\\omega_1+l\\omega_2|\\le M(|k|+|l|)$, hence the sum we wanted is bounded by positive multiples of\r\n    $$\\sum_{(k,l)\\in\\mathbb Z^2\\setminus\\{0\\}}\\frac{1}{(|k|+|l|)^t}$$\r\n    So we only need to understand the convergence of this sum.\r\n    Now for each $n\\in\\mathbb Z_{>0}$, the equation $n=|k|+|l|$ has exactly $4n$ solutions of $(k,l)\\in\\mathbb Z^2\\setminus\\{0\\}$, therefore this sum converges iff\r\n    $$\\sum_{n=1}^\\infty\\frac{4n}{n^t}=4\\sum_{n=1}^\\infty\\frac{1}{n^{t-1}}$$\r\n    which converges iff $t>2$.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    $\\wp_\\Lambda$ is a well-defined elliptic function with $\\Lambda$ its set of periods.\r\n    Moreover, $\\wp_\\Lambda$ is even and has degree $2$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For convergence, we shall estimate the summands.\r\n    \\begin{align*}\r\n        \\left|\\frac{1}{(z-\\omega)^2}-\\frac{1}{\\omega^2} \\right|&=\\left|\\frac{z(2\\omega-z)}{\\omega^2(z-\\omega)^2} \\right|\\\\\r\n        &=\\left|\\frac{z}{\\omega^2}\\right|\\left|\\frac{2\\omega-z}{(z-\\omega)^2}\\right|\\\\\r\n        &\\le \\left|\\frac{z}{\\omega^2}\\right|\\left( \\frac{2}{|z-\\omega|}+\\frac{|z|}{|z-\\omega|^2} \\right)\r\n    \\end{align*}\r\n    Fix $R\\ge|z|$.\r\n    For all but finitely many $\\omega$, we have $|\\omega|\\ge 2R$, so $|\\omega-z|\\ge |\\omega|/2\\ge R$.\r\n    So after throwing away finitely many terms,\r\n    $$\\left|\\frac{z}{\\omega^2}\\right|\\left( \\frac{2}{|z-\\omega|}+\\frac{|z|}{|z-\\omega|^2} \\right)\\le\\frac{R}{|\\omega|^2}\\left( \\frac{2}{|\\omega|/2}+\\frac{R}{|\\omega|R/2} \\right)=\\frac{6R}{|\\omega|^3}$$\r\n    So the sum converges by the preceding lemma since $3>2$, which means $\\wp_\\Lambda(z)$ is indeed well-defined and automatically meromorphic.\r\n    It is clear that it is even.\r\n    To see it is elliptic, choose $\\omega_0\\in\\Lambda$, we need to show that $\\omega_0$ is a period of $\\wp_\\Lambda$.\r\n    Now it is clear that $\\omega_0$ is a period of\r\n    $$\\wp_\\Lambda^\\prime(z)=\\sum_{\\omega\\in\\Lambda}\\frac{-2}{(z-\\omega)^3}$$\r\n    So $f(z)=\\wp_\\Lambda(z+\\omega_0)-\\wp_\\Lambda(z)$ has zero derivative, hence $f$ is constant.\r\n    This means that $\\wp_\\Lambda(z+\\omega_0)=\\wp_\\Lambda(z)+C$ for some constant $C$.\r\n    But $\\wp_\\Lambda$ is even, so setting $z=-\\omega_0/2$ gives $C=0$ and hence $\\omega_0$ is a period, so anything in $\\Lambda$ is a period of $\\wp_\\Lambda$.\r\n    Also the poles of $\\wp_\\Lambda$ is exactly $\\Lambda$, so the set of periods of $\\wp_\\lambda$ has to be exactly $\\Lambda$.\r\n    In particular, $\\wp_\\Lambda$ has a unique pole of order $2$ on $\\mathbb C/\\Lambda$, so $\\deg\\wp_\\Lambda=2$\r\n    This completes the proof.\r\n\\end{proof}\r\n\\begin{remark}\r\n    We now know that:\\\\\r\n    (i) $\\wp_\\Lambda$ is meromorphic with set of periods $\\Lambda$.\\\\\r\n    (ii) $\\wp_\\Lambda$ has poles only at $\\Lambda$.\\\\\r\n    (iii) $\\wp_\\Lambda(z)-z^{-2}\\to 0$ as $z\\to 0$.\\\\\r\n    Furthermore, these properties uniquely characterised $\\wp_\\Lambda$ up to a constant.\r\n\\end{remark}", "meta": {"hexsha": "f42a23cf098f55d1c6040919ec56d409dba0404c", "size": 4426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14/def.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14/def.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14/def.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": 68.0923076923, "max_line_length": 202, "alphanum_fraction": 0.6384997741, "num_tokens": 1593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6721281464880676}}
{"text": "\\subsection{Scheduling: Non-Preemptive, Size-Based}\n\\label{sec:Scheduling-Non-Preemptive-Size-Based}\n\nThe most common non-preemptive size-based scheduling policies are\n\n\\begin{description}\n\t\n\t\\item [Shortest-Job-First (SJF)] the server chooses the job with the smallest size.\n\t\n\\end{description}\n\nIt is convenient to evaluate size-based policies as \\textit{non-preemptive priority queueing}, where priority classes are job sizes and a job has higher priority if it has lower job size.\n\n\n\n\n\\subsection{Non-Preemptive Priority Queueing}\n\\label{sec:NP-Priority}\n\nFor non-preemptive priority queueing (NP-Priority), we have that\n\n\\begin{equation}\n\\label{eqn:NP-Priority-Queue-Time-Size}\n\\expected{T_{Q}(x)}^{\\mathit{NP-Priority}}=\n\\frac{\\varrho\\expected{S^{2}}}{2\\expected{S}}\n\\frac{1}{\\Big(1-\\sum_{i=1}^{x}\\varrho_{i}\\Big)\\cdot\\Big(1-\\sum_{i=1}^{x-1}\\varrho_{i}\\Big)}\n\\end{equation}\n\nThe first factor of the denominator can be seen as the contribution due to waiting for jobs in queue with higher or equal priority.\nThe second factor of the denominator can be seen as the contribution due to those jobs arriving later with strictly higher priority.\n\nRecall that $\\expected{T_{Q}}^{\\mathit{FCFS}}=\\frac{\\varrho\\frac{\\expected{S^{2}}}{\\expected{S}}}{1-\\varrho}$.\n\nIf $k$ is low, $\\expected{T_{Q}(x)}^{\\mathit{NP-Priority}}<\\expected{T_{Q}^{\\mathit{FCFS}}}$.\nIf $k$ is high and job size distribution is heavy-tailed, $\\expected{T_{Q}(x)}^{\\mathit{NP-Priority}}<\\expected{T_{Q}}^{\\mathit{FCFS}}$.\n\nThe above results hold because $\\sum_{i=1}^{k}\\varrho_{i}<<\\varrho$.\n\nWe determine the mean queue time as follow\n\n\\begin{equation}\n\\label{eqn:NP-Priority-Queue-Time}\n\\expected{T_{Q}}^{\\mathit{NP-Priority}}=\\sum_{i=1}^{n}\\expected{T_{Q}(i)}\\cdot p_{i}=\\sum_{i=1}^{n}\\expected{T_{Q}(i)}\\cdot\\frac{\\lambda_{i}}{\\lambda}\n\\end{equation}\n\nwhere $p_{i}$ is the fraction of jobs belonging to class $i$.\n\nWe will use these results to analyze SJF.\n\n\n\n\n\\subsection{Scheduling: SJF}\n\\label{sec:Scheduling-SJF}\n\nWe model SJF as NP-Priority with infinite priority classes, where the smaller the job, the higher the priority.\n\nBy applying \\Cref{eqn:NP-Priority-Queue-Time-Size,eqn:NP-Priority-Queue-Time}, we obtain:\n\n\\begin{equation}\n\\label{eqn:SJF-Queue-Time-Size}\n\\expected{T_{Q}(x)}^{\\mathit{SJF}}=\n\\frac{\\varrho\\expected{S^{2}}}{2\\expected{S}}\\cdot\\frac{1}{\\Big(1-\\varrho_{x}\\Big)^{2}}\n\\end{equation}\n\nwhere $\\varrho_{x}=\\lambda F(x)\\cdot\\int_{t=0}^{x}t\\frac{f(t)}{F(t)}\\partial t$ is the arrival rate of jobs of size no more than $x$, namely $\\lambda F(x)$, multiplied by the expected size of jobs of size no more than $x$, namely $\\int_{t=0}^{x}t\\frac{f(t)}{F(t)}\\partial t$.\n\nWe also obtain:\n\n\\begin{equation}\n\\label{eqn:SJF-Queue-Time}\n\\expected{T_{Q}}^{\\mathit{SJF}}=\n\\frac{\\varrho\\expected{S^{2}}}{2\\expected{S}}\\cdot\\int_{x=0}^{x_{n}}\\frac{f(x)\\partial x}{\\Big(1-\\lambda\\int_{t=0}^{x}tf(t)\\partial t\\Big)^{2}}\n\\end{equation}\n\nBy comparing $\\expected{T_{Q}}^{\\mathit{SJF}}$ with $\\expected{T_{Q}}^{\\mathit{FCFS}}$, we have that SJF is a poor choice for (i) very large jobs (see term $\\varrho_{x}$) and (ii) high-variable job sizes \\footnote{Since real workload are heavy-tailed, most jobs are small, hence we may think not to worry about very large jobs. This is a wrong idea. Heavy-tailed distribution have also high variability.} (see term $\\expected{S^{2}}$).\n\nWhen using SJF under high-variable job size, it is more efficient to kill long-running jobs, given that there are some other jobs in queue. In fact, if there are many jobs in queue, they are likely to include many short jobs, thus mean response time would improve. This is the idea behind TAGS policy in \\cite{harchol2000task}. \n\nThe only way to get good performance out of SJF under real workload is to provide preemption.\n", "meta": {"hexsha": "8eabbf3f04c974773217055a099b9aa5839e2a15", "size": 3775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/scheduling-non-preemptive-size-based.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/scheduling-non-preemptive-size-based.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/scheduling-non-preemptive-size-based.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": 46.6049382716, "max_line_length": 435, "alphanum_fraction": 0.7226490066, "num_tokens": 1201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6721281430643056}}
{"text": "\\section{Divergence and Curl}\\label{sec:DivergenceCurl}\n\nDivergence and curl are two measurements of vector fields that are\nvery useful in a variety of applications. Both are most easily\nunderstood by thinking of the vector field as representing a flow of a\nliquid or gas;\nthat is, each vector in the vector field should be interpreted as a\nvelocity vector. \nRoughly speaking, divergence\nmeasures the tendency of \nthe fluid to collect or disperse at a point, and curl measures the\ntendency of the fluid to swirl around the point. Divergence is a\nscalar, that is, a single number, while curl is itself a vector. The\nmagnitude of the curl measures how much the fluid is swirling, the\ndirection indicates the axis around which it tends to swirl. These\nideas are somewhat subtle in practice, and are beyond the scope of\nthis course.\n%You can find additional information on the web, for\n%example at \n%\\texonly\n%\\url{http://mathinsight.org/curl_idea}%\n%\\vb|http://mathinsight.org/curl_idea|\\endurl\\ \n%and \n%\\url{http://mathinsight.org/divergence_idea}%\n%\\vb|http://mathinsight.org/divergence_idea|\\endurl\\ \n%\\endtexonly\n%\\htmlonly\n%<center>\n%<a href=\"http://mathinsight.org/curl_idea\">http://mathinsight.org/curl_idea</a>\n%</center>\n%and\n%<center>\n%<a href=\"http://mathinsight.org/divergence_idea\">http://mathinsight.org/divergence_idea</a>\n%</center>\n%\\endhtmlonly\n%and in\n%many books including {\\em\n%Div, Grad, Curl, and All That: An Informal Text on Vector Calculus},\n%by H. M. Schey.\n\nRecall that if $f$ is a function, the gradient of $f$\nis given by \n$$\\nabla f=\\left\\langle {\\partial f\\over\\partial x},{\\partial\n  f\\over\\partial y},{\\partial f\\over\\partial z}\\right\\rangle.$$\nA useful mnemonic for this (and for the divergence and curl, as it\nturns out) is to let\n$$\\nabla = \\left\\langle{\\partial \\over\\partial x},{\\partial\n  \\over\\partial y},{\\partial \\over\\partial z}\\right\\rangle,$$\nthat is, we pretend that $\\nabla$ is a vector with rather odd looking\nentries. Recalling that $\\langle u,v,w\\rangle a=\\langle ua,va,wa\\rangle$,\nwe can then think of the gradient as\n$$\\nabla f=\\left\\langle{\\partial \\over\\partial x},{\\partial\n  \\over\\partial y},{\\partial \\over\\partial z}\\right\\rangle f = \n\\left\\langle {\\partial f\\over\\partial x},{\\partial\n  f\\over\\partial y},{\\partial f\\over\\partial z}\\right\\rangle,$$\nthat is, we simply multiply the $f$ into the vector.\n\nThe divergence and curl can now be defined in terms of this same\nvector $\\nabla$ by using the cross product and dot product.\n\n\\begin{formulabox}[Divergence]\nThe divergence of a vector field $\\vect{f}=\\langle f_1, f_2, f_3 \\rangle$ is\n$$\\nabla \\cdot \\vect{f} =\n\\left\\langle{\\partial \\over\\partial x},{\\partial\n  \\over\\partial y},{\\partial \\over\\partial z}\\right\\rangle\\cdot\n\\langle f_1,f_2,f_3\\rangle\n= {\\partial f_1 \\over\\partial x}+{\\partial\n  f_2 \\over\\partial y}+{\\partial f_3\\over\\partial z}.$$\\index{divergence}\\index{vector field!divergence}\n\\end{formulabox}\n\n\\begin{formulabox}[Curl]\nThe curl of $\\vect{f}$ is\n$$\\nabla\\times\\vect{f} = \\left|\n\\begin{matrix}\n\\vect{i}\t&\t\\vect{j}\t&\t\\vect{k}\t\\\\\n{\\partial \\over\\partial x}\t&\t{\\partial \\over\\partial y}\t&\t{\\partial \\over\\partial z}\t\\\\\nf_1\t&\tf_2\t&\tf_3\n\\end{matrix}\n\\right| = \n\\left\\langle {\\partial f_3\\over\\partial y}-{\\partial f_2\\over\\partial z},\n{\\partial f_1\\over\\partial z}-{\\partial f_3\\over\\partial x},\n{\\partial f_2\\over\\partial x}-{\\partial f_1\\over\\partial y}\\right\\rangle.$$\\index{curl}\\index{vector field!curl}\n\\end{formulabox}\n\nHere are two simple but useful facts about divergence and curl.\n\n\\begin{theorem}{Divergence of Curl is Zero}{div of curl is zero}\n$\\nabla\\cdot(\\nabla\\times\\vect{f})=0$.\n\\end{theorem}\n\nIn words, this says that the divergence of the curl is zero.\n\n\\begin{theorem}{Curl of Gradient is Zero}{curl of gradient is zero}\n$\\nabla\\times(\\nabla f) = \\vect{0}$.\n\\end{theorem}\n\nThat is, the curl of a gradient is the zero vector. Recalling that\ngradients are conservative vector fields, this says that the curl of a\nconservative vector field is the zero vector. Under suitable\nconditions, it is also true that if the curl of $\\vect{f}$ is $\\vect{0}$\nthen $\\vect{f}$ is conservative. (Note that this is exactly the same test\nthat we discussed at the end of Section ~\\ref{page:test for conservative vector field}.)\n\n\\begin{example}{}{conservative}\nLet $\\vect{f} = \\langle 2e^x - y, -x ,e^z\\rangle$. Show that $\\vect{f}$ is conservative and find the function $f$ such that $\\vect{f} = \\langle f_x, f_y, f_z \\rangle$. \n\\end{example}\n\n\\begin{solution}\nIf $\\vect{f} = \\langle 2e^x - y, -x ,e^z \\rangle$ then $\\nabla\\times\\vect{f} = \\langle 0, 0, (-1)-(-1) \\rangle = \\vect{0}$.\nThus, $\\vect{f}$ is conservative, and we can exhibit this directly by\nfinding the corresponding $f$.\n\nSince $f_x=2e^x-y$, $f=2e^x-xy+g(y,z)$. Since $f_y=-x$, it must be that\n$g_y=0$, so $g(y,z)= C + h(z)$. Thus $f=2e^x-xy+ C + h(z)$ and \n$$f_z = h'(z) = e^z,$$\nso $h(z)=e^z$. This leaves $f=2e^x -xy + e^z + C$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:DivergenceCurl}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle xy,-xy\\rangle$ and \nlet $D$ be given by $0\\le x\\le 1$, $0\\le y\\le 1$.\nCompute $\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$ and\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds$.\n\\begin{sol}\n\t$-1$, $0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle ax^2,by^2\\rangle$ and \nlet $D$ be given by $0\\le x\\le 1$, $0\\le y\\le 1$.\nCompute $\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$ and\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds$.\n\\begin{sol}\n\t$0$, $a+b$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle ay^2,bx^2\\rangle$ and \nlet $D$ be given by $0\\le x\\le 1$, $0\\le y\\le x$.\nCompute $\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$ and\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds$.\n\\begin{sol}\n\t$(2b-a)/3$, $0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle \\sin x\\cos y,\\cos x\\sin y\\rangle$ and \nlet $D$ be given by $0\\le x\\le \\pi/2$, $0\\le y\\le x$.\nCompute $\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$ and\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds$.\n\\begin{sol}\n\t$0$, $1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle y,-x\\rangle$ and \nlet $D$ be given by $x^2+y^2\\le 1$.\nCompute $\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$ and\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds$.\n\\begin{sol}\n\t$-2\\pi$, $0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle x,y\\rangle$ and \nlet $D$ be given by $x^2+y^2\\le 1$.\nCompute $\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$ and\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot\\vect{N}\\,ds$.\n\\begin{sol}\n\t$0$, $2\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nProve Theorem~\\ref{thm:div of curl is zero}.\n\\end{ex}\n\n\\begin{ex}\nProve Theorem~\\ref{thm:curl of gradient is zero}.\n\\end{ex}\n\n\\begin{ex}\nIf $\\nabla \\cdot \\vect{f}=0$, $\\vect{f}$ is said to be \\dfont{incompressible}.  Show that any vector field\nof the form $\\vect{f}(x,y,z) = \\langle f(y,z),g(x,z),h(x,y)\\rangle$ is\nincompressible.  Give a non-trivial example.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "1585bfc4a19bd30fc97ef6cc6208f46a3fa64140", "size": 7044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-5-divergence-curl.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-5-divergence-curl.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-5-divergence-curl.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": 35.0447761194, "max_line_length": 168, "alphanum_fraction": 0.6856899489, "num_tokens": 2526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.6721072496760185}}
{"text": "\\documentclass[\n\tsuperscriptaddress,\n\ttwocolumn,\n\taps, pre\n]{revtex4-1}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\n\\input{../common.tex}\n\\newcommand{\\dx}{\\Delta x}\n\\newcommand{\\dr}{\\Delta r}\n\\renewcommand{\\L}{_\\mathrm{L}}\n\\newcommand{\\R}{_\\mathrm{R}}\n\\newcommand{\\dom}{\\Omega}\n\\newcommand{\\bndry}{\\partial\\Omega}\n\n\\begin{document}\n\n\\title{Differential operators and boundary conditions in `py-pde`}\n\\author{David Zwicker}\n\\date{\\today}\n\n\\begin{abstract}\nWe here document the differential operators and the associated boundary conditions that are used in the finite difference approximation.\nWe also derive special versions of the Laplace operator that conserves the total mass.\n\\end{abstract}\n\n\n\\maketitle\n\\tableofcontents\n\n\n\\section{General considerations}\nThe main objects in `py-pde` are fields that are expressed on discretized grids.\nThe package provides many functions to manipulate these fields.\nSome functions (e.g., addition, multiplication, integrals) do only use the actual field values, while others (e.g., differential operators and interpolation) might require information on the behavior of the field at the boundary.\nThis documents specifies details for how boundary conditions are handled.\n\nThe simplest fields in `py-pde` are scalar fields, which associate a single value to each grid point.\nIn the continuum, a scalar field $c(\\vect r)$ often has the following boundary conditions:\n\\begin{salign}\n\t\\text{value:} &&\tc &= A\n\\\\\n\t\\text{normal derivative:} && n_\\alpha \\partial_\\alpha c &= B\n\\end{salign}\nwhere $n_\\alpha$ is again the outward normal of the boundary.\nThese two conditions are also often known as Dirichlet and Neumann boundary conditions, respectively.\nThese options are implemented as \\texttt{value} and \\texttt{derivative} in `py-pde`.\n\nFor a vector field $v_\\alpha(\\vect r)$, which associate a vector with each grid point, possible boundary conditions are\n\\begin{salign}\n\t\\text{value:} && v_\\alpha  &= A_\\alpha\n\\\\\n\t\\text{normal component:} && n_\\alpha v_\\alpha  &= A\n\\\\\n\t\\text{normal derivative:} && n_\\beta \\partial_\\beta v_\\alpha &= B_\\alpha\n\\\\\n\t\\text{normal comp. of normal deriv.:} && n_\\alpha n_\\beta \\partial_\\beta v_\\alpha &= B\n\\end{salign}\nThere are now many more options, where the first two specify values (Dirichlet conditions) and the last two specify derivatives (Neumann conditions).\nAdditionally, the conditions differ in that they either specify the full vector (conditions 1 and 3) or just the normal component (conditions 2 and 4).\nThe latter choice obviously contains less information, but is sufficient for differential operators; see below.\nConversely, specifying the full vector using the first or third condition is necessary for interpolating vector fields correctly.\nNote also that the Dirichlet conditionimposes the dot product between the normal vector and the vector field, which in a simple 1d system implies $v_1(x=x\\L)=-A$ and $v_1(x=x\\R)=A$ for the lower and upper boundary, respectively.\nSimilarly, the Neumann condition evaluates the directional derivative of the vector field in the normal direction~$n_\\beta$ of the boundary.\n\n\n\\section{Boundary conditions for differential operators}\nWe start with general considerations that are independent of the grid type.\nHere, we consider differential operators that act on fields defined in a domain~$\\dom$.\nIn particular, we discuss the boundary conditions that can be enforced with each type of operator.\nWe here use a component notation with implicit Einstein summation to denote contractions explicitly.\nFor instance, $\\partial_\\alpha v_\\alpha$ denotes the divergence of a vector field $v_\\alpha(\\vect r)$ and $t_{\\alpha\\alpha}(\\vect r)$ is the trace of a tensor field $t_{\\alpha\\beta}(\\vect r)$.\n\n\\subsection{Laplace operator}\nThe ordinary Laplace operator $\\partial_\\alpha^2 c$ is defined to act on scalar fields~$c(\\vect r)$.\nPossible boundary conditions are\n\\begin{salign}[eqn:bc_laplace]\n\t\\text{value:} &&\tc &= A\n\\\\\n\t\\text{normal derivative:} && n_\\alpha \\partial_\\alpha c &= B\n\\end{salign}\napplied at positions $\\vect r \\in \\bndry$.\nConsequently, either the value~$A$ of the field (Dirichlet condition $c(\\vect r) = A$ at $\\vect r \\in \\bndry$) or the normal derivative (Neumann condition $n_\\alpha \\partial_\\alpha c = B$) is specified, where $n_\\alpha$ is the outwards oriented normal vector at the boundary.\n\n\n\\subsection{Gradient operator}\nThe gradient operator $\\partial_\\alpha c$ acts on a scalar field $c(\\vect r)$ yielding a vector field.\nPossible boundary conditions are\n\\begin{salign}[eqn:bc_gradient]\n\t\\text{value:} &&\tc &= A\n\\\\\n\t\\text{derivative:} && n_\\alpha \\partial_\\alpha c &= B\n\\end{salign}\nwhere $n_\\alpha$ is again the outward normal of the boundary.\n\n\\subsection{Divergence operator}\nThe divergence operator $\\partial_\\alpha v_\\alpha$ acts on a vector field $v_\\alpha(\\vect r)$ with possible boundary conditions\n\\begin{salign}[eqn:bc_divergence]\n\t\\text{normal component:} && n_\\alpha v_\\alpha  &= A\n\\\\\n\t\\text{derivative:} && n_\\alpha n_\\beta \\partial_\\beta v_\\alpha &= B\n\\end{salign}\nNote that the Dirichlet condition in this case imposes the dot product between the normal vector and the vector field, which in a simple 1d system implies $v_1(x=x\\L)=-A$ and $v_1(x=x\\R)=A$ for the lower and upper boundary, respectively.\nSimilarly, the Neumann condition evaluates the directional derivative of the vector field in the normal direction~$n_\\beta$ of the boundary.\nThis implies that the tangential components of the vector field do not affect the boundary condition.\n\n\n\\subsection{Vector Laplacian}\nThe Vector Laplacian is a simple generalization of the ordinary Laplace operator to a vector field $v_\\alpha(\\vect r)$.\nPossible boundary conditions are\n\\begin{salign}[eqn:bc_vector_laplace]\n\t\\text{value:} &&\tv_\\alpha &= A_\\alpha\n\\\\\n\t\\text{normal derivative:} && n_\\beta \\partial_\\beta v_\\alpha &= B_\\alpha\n\\end{salign}\nwhich are applied at positions $\\vect r \\in \\bndry$.\n\n\n\\subsection{Vector gradient operator}\nThe vector gradient  operator $\\partial_\\beta v_\\alpha$ acts on a vector field $v_\\alpha(\\vect r)$ and yields a tensorial field.\nThis operator can be though of as a gradient applied to each component of $v_\\alpha$ and the boundary conditions thus are also applied to each component,\n\\begin{salign}\n\t\\text{value:} &&\tv_\\alpha &= A_\\alpha\n\\\\\n\t\\text{derivative:} && n_\\beta \\partial_\\beta v_\\alpha &= B_\\alpha\n\\end{salign}\n\n\\subsection{Tensor divergence operator}\nThe vector gradient  operator $\\partial_\\beta t_{\\alpha\\beta}$ acts on a tensor field $t_{\\alpha\\beta}(\\vect r)$ and yields a vector field.\nThis operator can be though of as a divergence applied along the $\\beta$-direction to each $\\alpha$-component.\nThe boundary conditions thus are applied to each component,\n\\begin{subequations}\n\\begin{align}\n\t\\text{value:} &&\tn_\\beta t_{\\alpha\\beta} &= A_\\alpha\n\\\\\n\t\\text{derivative:} &&\\partial_\\beta t_{\\alpha\\beta}&= B_\\alpha\n\\end{align}\n\\end{subequations}\n\n\\subsection{Operators not implemented}\nCurrently not implemented are the following operators\n\\begin{subequations}\n\\begin{align}\n\t\\text{Curl:} &&\n\t\t\\epsilon_{\\alpha\\beta\\gamma} \\partial_\\beta v_\\gamma\n\\\\\n\t\\text{Material derivative (Advection):}&&\n\t\tw_\\alpha \\partial_\\alpha v_\\beta\n\\end{align} \n\\end{subequations}\n\n\n%\\subsection{Boundary conditions of compound operators}\n%The Laplace operator can be written as a gradient operator followed by a divergence operator, $\\partial_\\alpha^2 c = \\partial_\\alpha(\\partial_\\alpha c)$.\n%When implementing the involved operators in finite difference, one necessarily needs to determine boundary conditions for all three differential operators.\n%Clearly, boundary conditions given in \\Eqref{eqn:bc_laplace} for the Laplace operator can also be applied to the gradient operator, which employs the same conditions; see \\Eqref{eqn:bc_gradient}.\n%Conversely, the boundary conditions on the divergence operator specify \n\n\n\n\\section{Differential operators on Cartesian grids}\nWe consider a linear domain of length $L$ discretized by $N$ support points.\nWe place these points equidistantly at $x_n = (n+\\frac12)\\dx$ for $n=0,1,\\ldots, N-1$ using the discretization $\\dx=L/N$.\nAny function $y=f(x)$ is then represented by discretized values $y_n = f(x_n)$.\n\nIn the finite difference schemes we discuss, we require differential operators of first and second order.\nTargeting second order accuracy, we obtain these as \n\\begin{subequations}\n\\begin{align}\n\tf'(x_n) &\\sim \\frac{y_{n+1} - y_{n-1}}{2\\dx}\n\\\\\t\n\tf''(x_n) &\\sim \\frac{y_{n+1} - 2 y_n + y_{n-1}}{\\dx^2}\n\\end{align}\n\\end{subequations}\nwhere $\\sim$ denotes the finite difference approximation.\n\nThese derivatives can only be evaluated directly for $n=1,2,\\ldots, n-2$, while the boundary points $n=0$ and $n=N-1$ require knowledge of the value at the respective virtual points $x_{-1}$ and $x_N$ outside the domain.\nWe can derive expressions for the associated function values $y_{-1}$ and $y_N$  taking the boundary conditions in to account, which typically specify the value at the boundary or the (outward) derivative.\nA particular simple case are periodic boundary conditions, where we have $y_{-1} = y_{N-1}$ and $y_N = y_0$, allowing the above formula to be used everywhere.\nFor more complicated boundary conditions, we need to treat both sides separately.\n\n\\subsection{Lower boundary}\nLet us first consider conditions at the lower boundary, which we place at $x=0$.\nWe thus need to evaluate the virtual support point $y_{-1}$ from the boundary condition.\nUsing estimates for the value and the derivative at the boundary,\n\\begin{align}\n\tf(0) &\\sim \\frac{y_0 + y_{-1}}{2}\n&\n\tf'(0) &\\sim \\frac{y_0 - y_{-1}}{\\dx}\n\\end{align}\nwe can now handle several boundary conditions.\n\n\\paragraph{Dirichlet (Constant value):}\nAssuming the boundary condition $f(0) = a$, we obtain $y_{-1} = 2a - y_0$.\n\n\\paragraph{Neumann (Constant derivative):}\nHere, we consider the boundary condition $-f'(0) = b$, which specifies the outward derivative to equal the value $b$.\nWe obtain $y_{-1} = y_0 + b \\dx$.\n\n\\paragraph{Robin (Mixed):}\nAssuming the boundary condition $-f'(0) + c f(0) = b $, we obtain $y_{-1} = A - B y_0$\nwhere \n\\begin{align}\n\tA &= \\frac{2\\dx}{c \\dx + 2} b\n&\n\tB &= \\frac{c\\dx - 2}{c \\dx + 2}\n\\end{align}\n%Hence,\n%\\begin{align}\n%\t\\takenat{\\pfrac{^2 f}{x^2}}{x_0} \\sim \\frac{A - (2 + B) y_0 + y_{1}}{\\dx^2}\n%\\end{align}\nAs a sanity check, we obtain Dirichlet conditions in the limit $b \\rightarrow \\infty$ with $b/c = a$, where $A=2a, B=1$.\nLikewise, we recover Neumann condition for $c=0$.\n\n\\paragraph{Summary:}\nTaken together, we can express the value of the support point as\n\\begin{align}\n\ty_{-1} &= \\alpha\\L + \\beta\\L y_{k\\L}\n\t\\;,\n\\end{align}\nwhere the coefficients $\\alpha\\L$, $\\beta\\L$, and $k\\L$ are taken from \\tabref{tab:cartesian_lower}.\n\n\n\\begin{table}[t]\n\\caption{\\label{tab:cartesian_lower}%\nCoefficients for lower cartesian boundary\n}\n\\begin{ruledtabular}\n\t\\begin{tabular}{cccc}\n\t\tBoundary condition & Offset $\\alpha\\L$ & Pre-factor $\\beta\\L$  & Index $k\\L$\\\\\n\t\t\\colrule\n\t\tPeriodic & $0$ & $1$ & $N-1$ \\\\\n\t\tDirichlet & $2a$ & $-1$ & $0$ \\\\\n\t\tNeumann & $b\\dx$ & $1$  & $0$ \\\\\n\t\tRobin & $\\frac{2b\\dx}{2 + c \\dx}$ &\n\t\t\t\t$\\frac{2 - c\\dx}{2 + c \\dx}$ & $0$ \\\\\n\t\\end{tabular}\n\\end{ruledtabular}\n\\end{table}\n\n\n\\subsection{Upper boundary}\nThe upper boundary at $x=L$ can be treated analogously to the lower one by introducing a virtual point at $x=x_N$.\nConsequently, we find the following conditions for the virtual support point $y_N$:\n\\paragraph{Dirichlet (Constant value):}\nAssuming the boundary condition $f(L) = a$, we obtain $y_N = 2a - y_{N-1}$.\n\n\\paragraph{Neumann (Constant derivative):}\nHere, we consider the boundary condition $f'(L) = b$, which specifies the outward derivative to equal the value $b$.\nWe obtain $y_N = y_{N-1} + b \\dx$.\n\n\nTaken together, we express the value at the virtual support point as\n\\begin{align}\n\ty_N &= \\alpha\\R + \\beta\\R y_{k\\R}\n\t\\;,\n\\end{align}\nwhere the coefficients $\\alpha\\R$, $\\beta\\R$, and $k\\R$ are taken from \\tabref{tab:cartesian_upper}.\n\n\n\\begin{table}[t]\n\\caption{\\label{tab:cartesian_upper}%\nCoefficients for upper cartesian boundary\n}\n\\begin{ruledtabular}\n\t\\begin{tabular}{cccc}\n\t\tBoundary condition & Offset $\\alpha\\R$ & Pre-factor $\\beta\\R$  & Index $k\\R$\\\\\n\t\t\\colrule\n\t\tPeriodic & $0$ & $1$ & $0$ \\\\\n\t\tDirichlet & $2a$ & $-1$ & $N-1$ \\\\\n\t\tNeumann & $b\\dx$ & $1$  & $N-1$ \\\\\n\t\tRobin & $\\frac{2b\\dx}{2 + c \\dx}$ &\n\t\t\t\t$\\frac{2 - c\\dx}{2 + c \\dx}$ & $N-1$ \\\\\n\t\\end{tabular}\n\\end{ruledtabular}\n\\end{table}\n\n\n\\section{Differential operators on cylindrical grids}\nWe here consider fields in $3$ dimensions that possess angular symmetry and thus only depend on the radial coordinate~$r$ and the axial coordinate~$z$.\nClearly, the axial coordinate behaves exactly as the Cartesian ones described above, so we here only have to deal with the polar symmetry.\nSimilar to Cartesian grids, we discretize the associated radial coordinate as $r_n = r_0 + (n + \\frac12) \\dr$, where $r_0$ is the inner radius, which often will be zero.\n\nThe radial part of the gradient operator in cylindrical coordinates is simply given by $\\partial_r f(r)$ and thus obeys the same discretization as in a Cartesian grid.\nThe divergence of a vector field $v_\\alpha(r) = \\rho(r) \\vect e_r$ reads\n$\\partial_\\alpha v_\\alpha(r) =  \\rho'(r) + \\frac{\\rho(r)}{r}$, implying the discretized version\n\\begin{align}\n\t\\partial_\\alpha v_\\alpha \\sim\n\t\t\\frac{y_{n+1} - y_{n-1}}{2\\dr}\n\t\t+ \\frac{y_n}{r_n}\n\\end{align}\nMoreover, the Laplace operator in spherical coordinates reads $\\nabla^2 f(r) = f''(r) + \\frac{f'(r)}{r}$, which in the discretized version becomes\n\\begin{align}\n\t\\partial_\\alpha^2 f \\sim\n\t\t\\frac{y_{n+1} - 2 y_n + y_{n-1}}{\\dr^2}\n\t\t+ \\frac{y_{n+1} - y_{n-1}}{2 r_n \\dr}\n\\end{align}\n\n\\subsection{Boundary condition at the origin}\nDue to the symmetry, only vanishing derivatives are allowed at the inner boundary at the origin, implying the virtual support point $y_{-1} = y_0$.\nHence, the differential operators become\n\\begin{subequations}\n\\begin{align}\n\t\\takenat{\\partial_\\alpha v_\\alpha(r)}{r=0} &\\sim\n\t\t\\frac{y_1 - y_0}{2\\dr}\n\t\t+ \\frac{2y_0}{\\dr}\n\\\\\n\t\\takenat{\\partial_\\alpha^2 f(r)}{r=0} &\\sim\n\t\t2\\frac{y_1 - y_0}{\\dr^2}\n%\t\t\\frac{y_1 - 2 y_0 + y_0}{\\dr^2}\n%\t\t+ \\frac{2(y_1 - y_0)}{\\dr^2}\n%\t\t\\frac{3y_1 -  3y_0}{\\dr^2}\n\\end{align}\n\\end{subequations}\n\n\n\\subsection{Boundary condition at the outer side}\nAt the outer boundary, we can impose boundary conditions similar to the Cartesian grid.\n\n\\paragraph{Dirichlet (Constant value):}\nAssuming the boundary condition $f(R) = a$, we obtain $y_N = 2a - y_{N-1}$.\n\n\\paragraph{Neumann (Constant derivative):}\nHere, we consider the boundary condition $f'(L) = b$, which specifies the outward derivative to equal the value $b$.\nWe obtain $y_n = y_{n-1} + b \\dx$.\n\n\n\n\\section{Differential operators on spherical grid}\nWe here consider fields that a spherically symmetric in $3$ dimensions and thus only depend on the radial coordinate~$r$.\nSimilar to Cartesian grids, we discretize the radial coordinate as $r_n = (n + \\frac12) \\dr$.\n\nThe radial part fo the gradient operator in spherical coordinates is simply given by $\\partial_r f(r)$ and thus obeys the same discretization as in a Cartesian grid.\nThe divergence of a vector field $v_\\alpha(r) = \\rho(r) \\vect e_r$ reads\n$\\partial_\\alpha v_\\alpha(r) =  \\rho'(r) + \\frac{2\\rho(r)}{r}$, implying the discretized version\n\\begin{align}\n\t\\partial_\\alpha v_\\alpha \\sim\n\t\t\\frac{y_{n+1} - y_{n-1}}{2\\dr}\n\t\t+ \\frac{2y_n}{r_n}\n\\end{align}\nMoreover, the naive implementation of Laplace operator in spherical coordinates reads $\\nabla^2 f(r) = f''(r) + \\frac{2f'(r)}{r}$, which in the discretized version becomes\n\\begin{align}\n\t\\partial_\\alpha^2 f \\sim\n\t\t\\frac{y_{n+1} - 2 y_n + y_{n-1}}{\\dr^2}\n\t\t+ \\frac{y_{n+1} - y_{n-1}}{r_n \\dr}\n\\end{align}\nNote that this form of the Laplace operator is not conservative, \\ie, the discretized version of the integral $\\int \\partial_\\alpha^2 f \\diff r$  does not vanish.\n\n\n\\subsection{Boundary condition at the origin}\nDue to the symmetry, only vanishing derivatives are allowed at the inner boundary at the origin, implying the virtual support point $y_{-1} = y_0$.\nHence, the differential operators become\n\\begin{subequations}\n\\begin{align}\n\t\\takenat{\\partial_\\alpha v_\\alpha(r)}{r=0} &\\sim\n\t\t\\frac{y_1 - y_0}{2\\dr}\n\t\t+ \\frac{4y_0}{\\dr}\n\\\\\n\t\\takenat{\\partial_\\alpha^2 f(r)}{r=0} &\\sim\n%\t\t\\frac{y_1 - 2 y_0 + y_0}{\\dr^2}\n%\t\t+ \\frac{2(y_1 - y_0)}{\\dr^2}\n\t\t3\\frac{y_1 -  y_0}{\\dr^2}\n\\end{align}\n\\end{subequations}\nNote that the latter expression applies to both the non-conservative and the conservative form of the Laplacian.\n\n\\subsection{Boundary condition at the outer side}\nAt the outer boundary, we can impose boundary conditions similar to the Cartesian grid.\n\n\\paragraph{Dirichlet (Constant value):}\nAssuming the boundary condition $f(R) = a$, we obtain $y_N = 2a - y_{N-1}$.\n\n\\paragraph{Neumann (Constant derivative):}\nHere, we consider the boundary condition $f'(L) = b$, which specifies the outward derivative to equal the value $b$.\nWe obtain $y_n = y_{n-1} + b \\dx$.\n\n\\subsection{Conservative operator}\n\nWe call a discrete Laplace operator conservative when it preserves the desirable conservation equation\n\\begin{align}\n\t\\int_\\Omega \\partial_\\alpha^2 f \\diff V\n\t\t= \\oint_{\\partial\\Omega} \\partial_\\alpha f n_\\alpha \\diff S= 0\n\\end{align}\nwhen Neumann boundary conditions are imposed on the function $f$.\nA conservative operator can be derived by integrating the definition of the Laplace operator in spherical coordinates over one spherical shell from $r=r_n - \\dr/2$ to $r=r_n  + \\dr/2$,\n\\begin{align}\n%\tr^2 \\partial_\\alpha^2 f &= \\partial_r\\bigl(r^2 \\partial_r f(r)\\bigr)\n%\\\\\n\t\\int_{r_{n - \\frac12}}^{r_{n + \\frac12}} r^2 \\partial_\\alpha^2 f \\diff r\n\t\t&= \\int_{r_{n - \\frac12}}^{r_{n + \\frac12}} \\partial_r\\bigl(r^2 \\partial_r f(r)\\bigr) \\diff r\n\t\\;,\n\\end{align}\nwhere we skipped the factor $4\\pi$ stemming from the angle integration.\nAssuming that the quantity $\\partial_\\alpha^2 f$ is constant across the discretization cell, we thus find\n\\begin{align}\n\tV_n \\partial_\\alpha^2 f %\\left[ \\frac{r^3}{3} \\right]_{r_n - \\dr/2}^{r_n + \\dr/2}\n\t\t&\\sim \\Bigl[r^2 \\partial_r f(r)\\Bigr]_{r_n - \\dr/2}^{r_n + \\dr/2}\n\\end{align}\nwhere we introduced the (scaled) shell volumes\n\\begin{align}\n%\tV_n &= \\frac{\\dr^3}{3}\\bigl[(n + 1)^3 - n^3\\bigr]\n\tV_n &= \\frac{r_{n + \\frac12}^3 - r_{n - \\frac12}^3}{3}\n\t= \\dr \\left(\tr_n^2 + \\frac{\\dr^2}{12} \\right)\n\\;.\n\\end{align}\nConsequently,\n\\begin{align}\n\t\\partial_\\alpha^2 f\n%\t\t&\\sim \\dr^2 \\frac{(n + 1)^2 f'\\left(r_n + \\frac{\\dr}{2}\\right) - n^2 f'\\left(r_n - \\frac{\\dr}{2}\\right)}{V_n}\n\t\t&\\sim \\frac{r_{n+\\frac12}^2 f'\\left(r_{n+\\frac12}\\right) - r_{n-\\frac12}^2 f'\\left(r_{n-\\frac12}\\right)}{V_n}\n\\end{align}\nwhere the derivatives $f'(r)$ are evaluated at the midpoints and can thus be represented as\n\\begin{subequations}\n\\begin{align}\n\tf'\\left(r_{n + \\frac12}\\right) \\sim \\frac{y_{n+1} - y_n}{\\dr}\n\\\\\n\tf'\\left(r_{n - \\frac12}\\right) \\sim \\frac{y_n - y_{n-1}}{\\dr}\n\\end{align}\n\\end{subequations}\nIn the special case where the spherical grid does not have a hole ($r_0=0$), we then arrive at\n\\begin{align}\n\t\\partial_\\alpha^2 f\n\t\t&\\sim \\frac{3}{\\dr^2} \\, \\frac{(n + 1)^2 (y_{n+1} - y_n) - n^2 (y_n - y_{n-1})}{(n + 1)^3 - n^3}\n\t\\;,\n\\end{align}\nwhich is a conservative discretization of the spherical Laplacian by construction.\n\nSimilarly, we can consider a spherical grid where fields depend on the polar angle~$\\theta$ while still keeping azimuthal symmetry, i.e., assuming no dependence on $\\phi$.\nThe condition for a conservative Laplace operator then reads\n\\begin{widetext}\n\\begin{multline}\n\t\\iint_{\\text{cell}(n, m)} r^2 \\sin\\theta \\, \\partial_\\alpha^2 f  \\diff r \\diff \\theta\n=\n\t\\iint_{\\text{cell}(n, m)} \\biggl(\n\t\t\\sin\\theta  \\partial_r\\bigl[r^2 \\partial_r f(r, \\theta)\\bigr]\n\t\t+ \\partial_\\theta \\bigl[ \\sin\\theta \\partial_\\theta  f(r, \\theta)\\bigr]\n\t\\biggr)\\diff r \\diff \\theta\n\\\\=\n\t\\Bigl(\\cos\\theta_{m-\\frac12} - \\cos\\theta_{m + \\frac12}\\Bigr)\n\t\t\\int_{r_{n - \\frac12}}^{r_{n + \\frac12}}\\left(\n\t\t\t \\partial_r\\bigl[r^2 \\partial_r f(r, \\theta)\\bigr]\n\t\t\\right)  \\diff r\n%\\notag\\\\&\\quad\n\t+ \\Delta r\n\t\t\\int_{\\theta_{m - \\frac12}}^{\\theta_{m + \\frac12}}\n\t\t\t \\partial_\\theta \\bigl[ \\sin\\theta \\partial_\\theta  f(r, \\theta)\\bigr]\t \\diff\\theta\n\\\\=\n\t\\Bigl(\\cos\\theta_{m-\\frac12} - \\cos\\theta_{m + \\frac12}\\Bigr)\n\t\t\t\\bigl[r^2 \\partial_r f(r, \\theta)\\bigr]_{r_{n - \\frac12}}^{r_{n + \\frac12}}\n\t+  \\Delta r\n\t\t\\bigl[ \\sin\\theta \\partial_\\theta  f(r, \\theta)\\bigr]_{\\theta_{m - \\frac12}}^{\\theta_{m + \\frac12}}\n%\\\\\n%\t\\partial_\\alpha^2 f \\left[ \\frac{r^3}{3} \\right]_{r_n - \\dr/2}^{r_n + \\dr/2}\n%\t\t&\\sim \\Bigl[r^2 \\partial_r f(r)\\Bigr]_{r_n - \\dr/2}^{r_n + \\dr/2}\n\\end{multline}\n\\end{widetext}\nHere we assumed that we can neglect angular dependencies in the radial integral and vice versa.\nUsing the (scaled) volume of a grid cell,\n\\begin{align}\n\tV_{n,m} =\n\t\t\\left(\\cos\\theta_{m-\\frac12} - \\cos\\theta_{m + \\frac12}\\right)\n\t\t\\frac{r_{n + \\frac12}^3 - r_{n - \\frac12}^3}{3}\n%\\notag\\\\=\n%\t\\left(\\cos\\theta_{m-\\frac12} - \\cos\\theta_{m + \\frac12}\\right)\n\t\\;,\n\\end{align}\nwe can write this as\n\\begin{multline}\n\tV_{n,m} \\partial_\\alpha^2 f\n=\\Bigl(\\cos\\theta_{m-\\frac12} - \\cos\\theta_{m + \\frac12}\\Bigr)\n\t\t\t\\bigl[r^2 \\partial_r f(r, \\theta)\\bigr]_{r_{n - \\frac12}}^{r_{n + \\frac12}}\n\\\\\n\t+  \\Delta r\n\t\t\\bigl[ \\sin\\theta \\partial_\\theta  f(r, \\theta)\\bigr]_{\\theta_{m - \\frac12}}^{\\theta_{m + \\frac12}}\n\\end{multline}\n\n\n%\\bibliographystyle{apsrev4-1}\n%\\bibliography{bibdesk.bib}\n\n\\end{document}  ", "meta": {"hexsha": "c05f00263bbbbc595814071009b8a5a89ed3442c", "size": 21496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/methods/boundary_discretization/boundary_discretization.tex", "max_stars_repo_name": "lmenou/py-pde", "max_stars_repo_head_hexsha": "3899cba0481657ea7b3d5c05e318d0b851bbe8cd", "max_stars_repo_licenses": ["MIT"], "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/methods/boundary_discretization/boundary_discretization.tex", "max_issues_repo_name": "lmenou/py-pde", "max_issues_repo_head_hexsha": "3899cba0481657ea7b3d5c05e318d0b851bbe8cd", "max_issues_repo_licenses": ["MIT"], "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/methods/boundary_discretization/boundary_discretization.tex", "max_forks_repo_name": "lmenou/py-pde", "max_forks_repo_head_hexsha": "3899cba0481657ea7b3d5c05e318d0b851bbe8cd", "max_forks_repo_licenses": ["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.3216494845, "max_line_length": 275, "alphanum_fraction": 0.7133420171, "num_tokens": 6811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6721072453143049}}
{"text": "\\section{Barratt-Puppe sequence}\\label{secbarrattpuppe}\n%Hood's office hours are from 12 to 1:30 on Mondays in 2-390. Mine are from 4-5 on Tuesday in 2-478. Hood's graded the homework already.\n\\subsection{Fiber sequences}\nRecall, from the previous section, that we have a pullback diagram:\n\\begin{equation*}\n    \\xymatrix{\n\t& F(f,\\ast)\\ar[r]\\ar[d]^p \\pb & PY\\ar[d]^p\\ar[dr]^{\\simeq} & \\\\\n\tf^{-1}(\\ast)\\ar[ur]\\ar[r] & X\\ar[r]_f & Y & \\ast\\ar[l]\n    }\n\\end{equation*}\nConsider a pointed map\\footnote{Some people call such a map ``based'', but this makes it sound like we're doing chemistry, so we won't use it.}\n$f:X\\to Y$ (so that $f(\\ast) = \\ast$). Then, we will write $Ff$ for the homotopy fiber $F(f,\\ast)$.\n\nSince we're exploring the homotopy fiber $Ff$, we can ask the following, seemingly silly, question:\nwhat is the fiber of the canonical map $p:Ff\\to X$ (over the basepoint of $X$)?\nThis is precisely the space of loops in $Y$!\nSince $p$ is a fibration (recall that fibrations are closed under pullbacks), the homotopy fiber of $p$ is also the ``strict''\nfiber!\nOur expanded diagram is now:\n\\begin{equation*}\n\\xymatrix{\\\\\n    & \\Omega Y=p^{-1}(\\ast)\\ar[d] & & &\\\\\n    & F(f,\\ast)\\ar[r]\\ar[d]^p & PY\\ar[d]^p\\ar[dr]^{\\simeq} & \\\\\n    f^{-1}(\\ast)\\ar[ur]\\ar[r] & X\\ar[r]_f & Y & \\ast.\\ar[l]\n}\n\\end{equation*}\nIt's easy to see that the composite $Ff\\xar{p} X\\xar{f} Y$ sends $(x,\\omega)\\mapsto f(x)$;\nthis is a pointed nonconstant map.\n(Note that the basepoint we're choosing for $Ff$ is the image of the basepoint in $f^{-1}(\\ast)$ under\nthe canonical map $f^{-1}(\\ast)\\hookrightarrow Ff$.)\n\nWhile the composite $fp:Ff \\to Y$ is not zero ``on the nose'', it is nullhomotopic, for instance\nvia the homotopy $h:Ff\\times I\\to Y$, defined by\n$$h(t,(x,\\omega)) = \\omega(t).$$\n\\begin{exercise}\\label{fiberkernel}\n    Let $f:X\\to Y$ and $g:W\\to X$ be pointed maps.\n    Establish a homeomorphism between the space of pointed maps $W \\xar{p} Ff$ such that $fp = g$ and the space of pointed\n    nullhomotopies of the composite $fg$.\n\\end{exercise}\nThis exercise proves that the homotopy fiber is the ``kernel'' in the homotopy category of pointed spaces and pointed\nmaps between them.\n\nDefine $[W,X]_\\ast = \\pi_0(X^W_\\ast)$; this consists of the pointed homotopy classes of maps $W\\to X$.\nWe may view this as a pointed set, whose basepoint is the constant map.\nFixing $W$, this is a contravariant functor in $X$, so there are maps $[W,Ff]_\\ast\\to [W,X]_\\ast\\to [W,Y]_\\ast$.\nThis composite is not just nullhomotopic: it is ``exact''!\nSince we are working with pointed sets, we need to describe what exactness means in this context:\nthe preimage of the basepoint in $[W,Y]_\\ast$ is exactly the image of $[W,Ff]_\\ast\\to [W,X]_\\ast$.\n(This is exactly a reformulation of Exercise \\ref{fiberkernel}.)\nWe say that $Ff\\to X\\xrightarrow{f}Y$ is a \\emph{fiber sequence}.\n\n\\begin{remark}\n    Let $f:X\\to Y$ be a map of spaces, and suppose we have a homotopy commutative diagram:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\Omega Y\\ar[d]_{\\Omega g}\\ar[r] & Ff\\ar@{-->}[d]\\ar[r] & X\\ar[d]_{h}\\ar[r]^f & Y\\ar[d]^g\\\\\n\t    \\Omega Y^\\prime\\ar[r] & Ff^\\prime\\ar[r] & X^\\prime\\ar[r]_{f^\\prime} & Y.\n\t    }\n    \\end{equation*}\n    Then the dotted map exists, but it {depends on the homotopy} $f^\\prime h\\simeq gf$. \n\\end{remark}\n\n\\subsection{Iterating fiber sequences}\nLet $f:X\\to Y$ be a pointed map, as before.\nAs observed above, we have a composite map $Ff\\xrightarrow{p} X\\xrightarrow{f} Y$, and\nthe strict fiber (homotopy equivalent to the homotopy fiber) of $p$ is $\\Omega Y$.\nThis begets a map $i(f):\\Omega Y\\to Ff$; iterating the procedure of taking fibers gives:\n\\begin{equation*}\n    \\xymatrix{\n\t\\cdots\\ar[r] & Fp_3 \\ar[r]^{p_4} & Fp_2\\ar[r]^{p_3} & Fp_1\\ar[r]^{p_2} & Ff\\ar[r]^{p_1} & X\\ar[r]^{f} & Y\\\\\n\t& \\Omega Fp_0\\ar[u]|{\\simeq}\\ar[ur]|{i(p_2)}\\ar@{-->}[r] & \\Omega X\\ar@{-->}[r]\\ar[u]|{\\simeq}\\ar[ur]|{i(p_1)} & \\Omega Y\\ar[u]|\\simeq \\ar[ur]|{i(f)} & &\n    }\n\\end{equation*}\nAll the $p_i$ in the above diagram are fibrations.\nEach of the dotted maps in the above diagram can be filled in up to homotopy.\nThe most obvious guess for what these dotted maps are is simply $\\Omega X\\xrightarrow{\\Omega f}\\Omega Y$.\nBut \\emph{that is the wrong map}!\n\nThe right map turns out to be $\\Omega X\\xrightarrow{\\overline{\\Omega f}}\\Omega Y$:\n\\begin{lemma}\n    The following diagram commutes to homotopy:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    & Fp\\\\\n\t    \\Omega X\\ar[r]_{\\overline{\\Omega f}}\\ar[ur]^{i(p)} & \\Omega Y;\\ar[u]\n\t    }\n    \\end{equation*}\n    here, $\\overline{\\Omega f}$ is the diagonal in the following diagram:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\Omega X\\ar[r]^{-}\\ar[dr]|{\\Omega f} \\ar[d]_{\\Omega f} & \\Omega X\\ar[d]^{\\Omega f}\\\\\n\t    \\Omega Y\\ar[r]_{-} & \\Omega Y,\n\t    }\n    \\end{equation*}\n    where the map $-:\\Omega X\\to \\Omega X$ sends $\\omega\\mapsto\\overline{\\omega}$.\n\\end{lemma}\n\\begin{proof}\n    \\todo{typeset the following image for the proof... it's going to be impossible to write this up in symbols.}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{assets/barratt-puppe}\n\\caption{A proof of this lemma.}\n\\end{figure}\n\\end{proof}\n%\\begin{lemma}\n%    The following diagram commutes:\n%    \\begin{equation*}\n%\t\\xymatrix{\n%\t    & F(\\overline{\\Omega p_0})\\ar@{=}[dd]\\ar[dr] & \\\\\n%\t    \\Omega^2 Y\\ar[ur]^{i(\\Omega p_0)}\\ar[dr]_{\\overline{\\Omega i(p_0)}} & & \\Omega X\\\\\n%\t    & \\Omega Fp_0\\ar[ur]_{\\overline{\\Omega p_1}} & \n%\t    }\n%    \\end{equation*}\n%\\end{lemma}\n%What is the map $F\\overline{\\Omega p_0}\\to \\Omega X$?? We spent some time figuring this out.\n%But you can now apply $[W,-]_\\ast$ to the following diagram to get a long exact sequence:\nBy the above lemma, we can extend our diagram to:\n\\begin{equation*}\n    \\xymatrix{\n\t\\cdots\\ar[r] & Fp_4\\ar[r] & Fp_3 \\ar[r] & Fp_2\\ar[r] & Fp_1\\ar[r]^{p_2} & Ff\\ar[r]^{p_1} & X\\ar[r]^{f} & Y\\\\\n    \\cdots\\ar[r] & \\Omega Fp_1\\ar[r]|{\\overline{\\Omega p_2}}\\ar[u]_{\\simeq} & \\Omega Ff\\ar[u]_{\\simeq}\\ar[ur]|{i(p_2)}\\ar[r]|{\\overline{\\Omega p}} & \\Omega X\\ar[r]|{\\overline{\\Omega f}}\\ar[u]_{\\simeq}\\ar[ur]|{i(p_1)} & \\Omega Y\\ar[u]_\\simeq \\ar[ur]|{i(f)} & &\\\\\n\t\\Omega^2 X\\ar[u]_{\\simeq}\\ar[r]_{\\Omega^2 f} & \\Omega^2 Y\\ar[u]_{\\simeq}\\ar[ur]_{\\overline{\\Omega i(p_0)}} & & &\n    }\n\\end{equation*}\nWe have a special name for the sequence of spaces sneaking along the bottom of this diagram:\n$$\\cdots\\to \\Omega^2 X \\to \\Omega^2 Y \\to \\Omega Ff \\to \\Omega X \\to \\Omega Y \\to Ff \\to X \\xar{f} Y;$$\nthis is called the \\emph{Barratt-Puppe sequence}.\nApplying $[W,-]_\\ast$ to the Barratt-Puppe sequence of a map $f:X\\to Y$ gives a long exact sequence.\n\nThe most important case of this long exact sequence comes from setting $W = S^0=\\{\\pm 1\\}$;\nin this case, we get terms like $\\pi_0(\\Omega^n X)$.\nWe can identify $\\pi_0(\\Omega^n X)$ with $[S^n,X]_\\ast$: to see this for $n=2$,\nrecall that $\\Omega^2 X = (\\Omega X)^{S^1}$; because $(S^1)^{\\wedge n} = S^n$ (see below for a proof of this fact), \nwe find that\n\\begin{equation}\\label{bpsequence}\n(\\Omega X)^{S^1} \\simeq (X^{S^1}_\\ast)^{S^1}_\\ast = X_\\ast^{S^1\\wedge S^1} = X_\\ast^{S^2},\n\\end{equation}\nas desired.\n\nThe space $\\Omega X$ is a group in the homotopy category; this implies that\n$\\pi_0 \\Omega X = \\pi_1 X$ is a group!\nFor $n>1$, we know that\n$$\\pi_n(X) = [(D^n,S^{n-1}),(X,\\ast)] = [(I^n,\\partial I^n),(X,\\ast)].$$\n\\begin{exercise}\n    Prove that $\\pi_n(X)$ is an abelian group for $n>2$.\n\\end{exercise}\n%Suppose $n=2$, for simplicity.\n%How do I take the product of $\\alpha,\\beta\\in \\pi_2(X)$?\n%Thinking of $\\pi_2(X)$ as $[(I^2,\\partial I^2),(X,\\ast)]$ tells us that . You can play this game; up to homotopy, you can shrink $\\alpha$ and $\\beta$ to make them as small I want, and then reverse their position and expand them again\\footnote{This probably makes no sense without a picture}\\todo{Add a picture}. Thus $\\pi_2(X)$ is an abelian group.\nApplying $\\pi_0$ to the Barratt-Puppe sequence (see Equation \\ref{bpsequence}) therefore gives a long exact sequence\n(of groups when the homotopy groups are in degrees greater than $0$, and of pointed sets in degree $0$):\n$$\\cdots\\to \\pi_2 X\\to \\pi_2 Y\\to \\pi_1 Ff\\to \\pi_1 X\\to\\pi_1 Y\\to\\pi_0 Ff\\to\\pi_0 X\\to \\pi_0 X.$$\n", "meta": {"hexsha": "3d3b9711d794aae82cb0e958ade0b43ab805654a", "size": 8176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-45-barratt-puppe.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-45-barratt-puppe.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-45-barratt-puppe.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.4379084967, "max_line_length": 349, "alphanum_fraction": 0.6581457926, "num_tokens": 2973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.6721072367442975}}
{"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 FourPSF.\n\\end{par} \\vspace{1em}\n\\begin{par}\nFourPSF is an algorithm for estimating the frequency, 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;\nDI.t.v = [0:1/1e4:1-1/1e4];\nDI.y.v = Anom*sin(2*pi*fnom*DI.t.v + phnom) + Onom;\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{FourPSF} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nCS.verbose = 1;\nDO = qwtb('FourPSF', DI, CS);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: FourPSF wrapper: sampling time was calculated from time series\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Display results}\n\n\\begin{par}\nResults is the amplitude, frequency, phase and offset of sampled waveform.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nA = DO.A.v\nf = DO.f.v\nph = DO.ph.v\nO = DO.O.v\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nA =\n\n    2.0000\n\n\nf =\n\n   100\n\n\nph =\n\n    1.0000\n\n\nO =\n\n    0.2000\n\n\\end{lstlisting} \\color{black}\n    \\begin{par}\nErrors of estimation in parts per milion:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nAerrppm = (DO.A.v - Anom)/Anom .* 1e6\nferrppm = (DO.f.v - fnom)/fnom .* 1e6\npherrppm = (DO.ph.v - phnom)/phnom .* 1e6\nOerrppm = (DO.O.v - Onom)/Onom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nAerrppm =\n\n   2.2204e-09\n\n\nferrppm =\n\n     0\n\n\npherrppm =\n\n   8.8818e-09\n\n\nOerrppm =\n\n   1.3878e-09\n\n\\end{lstlisting} \\color{black}\n    \n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "9e36d610ff528edcd64ef4db5594b18f0f708efb", "size": 2548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_FourPSF.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_FourPSF.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_FourPSF.tex", "max_forks_repo_name": "qwtb/qwtb", "max_forks_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-11T02:12:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-17T12:59:18.000Z", "avg_line_length": 18.7352941176, "max_line_length": 225, "alphanum_fraction": 0.6868131868, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6720070093597056}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath} \n\\usepackage{pgfplots}\n\\usepackage{adjustbox}\n\\usepackage{subcaption}\n\n\\title{Linear Regression}\n\\begin{document}\n  \\pagenumbering{gobble}\n  \\maketitle\n  \\newpage\n  \\pagenumbering{arabic}\n\n\\section*{Linear Regression}\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 $\\hat{y}(x)$, that accurately represents given data.\\\\\n\n\\section*{Assumptions}\n\n\\begin{itemize}\n\\item Linear relationship\n\\item Little or no multi-collinearity\n\\item Little or no auto-correlation\n\\item Homoscedasticity\n\\end{itemize}\n\n\\section*{Least Squares Regression}\n\nTotal squared error is defined as: \n$$E = \\sum_{i=1}^m (\\hat{y} - y_i)^2$$. \n\nThe individual errors or residuals are defined as: \n$$e_i = (\\hat{y} - y_i)$$.\n\nWe try to minimize total squared error and $E = \\|{e}\\|_{2}^{2}$.\n\n\\section*{Derivation}\n\nEstimation $\\hat{y}(x_i)$ for each point $x_i$:\n\n$$\\hat{y}(x_1) = {\\alpha}_1 f_1(x_1) + {\\alpha}_2 f_2(x_1) + \\cdots + {\\alpha}_n f_n(x_1),$$\n$$\\hat{y}(x_2) = {\\alpha}_1 f_1(x_2) + {\\alpha}_2 f_2(x_2) + \\cdots + {\\alpha}_n f_n(x_2),$$\n\\begin{center}$ \\cdots $ \\end{center}\n$$\\hat{y}(x_m) = {\\alpha}_1 f_1(x_m) + {\\alpha}_2 f_2(x_m) + \\cdots + {\\alpha}_n f_n(x_m)$$\n\nWe can write this system of equations in terms of column vectors $\\hat{Y}$ and $\\beta$:\\\\\n\n$\\hat{Y}_i = \\hat{y}(x_i)$\\\\\n$\\beta_i = {\\alpha}_i$\\\\\n\nand $m x n$ matrix $A$ such that it's i-th column equals $F_i(x)$.\\\\\n\nThe system of equations becomes then: $\\hat{Y} = A{\\beta}$\\\\\n\nThe total squared error is given by E:\n\n$$E = \\|{\\hat{Y} - Y}\\|_{2}^2$$\n\n$\\hat{Y}$, that is closest to $Y$ is the one that can point perpendicularly to $Y$ .\n\n$${\\text{dot}}(\\hat{Y}, Y - \\hat{Y}) = 0$$\n\n$$\\hat{Y}^T (Y - \\hat{Y}) = 0$$\n\n$$(A{\\beta})^T(Y - A{\\beta}) = 0$$\n\n$${\\beta}^T A^T Y - {\\beta}^T A^T A {\\beta} = {\\beta}^T(A^T Y - A^T A {\\beta}) = 0$$\n\n$$A^T Y - A^T A {\\beta} = 0$$\\\\\n\nWe arrive at the least squares regression formula:\n\n$${\\beta} = (A^T A)^{-1} A^T Y$$\n\n\n\\end{document}", "meta": {"hexsha": "330db8b2a7d12d055512722ad30efd8788dcf246", "size": 2099, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/linear_regression.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/linear_regression.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/linear_regression.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": 26.9102564103, "max_line_length": 141, "alphanum_fraction": 0.6341114817, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6720070056119303}}
{"text": "\\chapter{Kolmogorov–Arnold representation theorem}\n\\begin{verbatim}\nhttps://en.wikipedia.org/wiki/Kolmogorov–Arnold_representation_theorem\n\\end{verbatim}\nFrom Wikipedia, the free encyclopedia\nIn real analysis and approximation theory, the Kolmogorov–Arnold representation theorem (or superposition theorem) states that every multivariate continuous function can be represented as a superposition of continuous functions of two variables. It solved a more general form of Hilbert's thirteenth problem.[1][2]\nThe works of Andrey Kolmogorov and Vladimir Arnold established that if f is a multivariate continuous function, then f can be written as a finite composition of continuous functions of a single variable and the binary operation of addition.[3]\nMore specifically\n$$\nf(x)=\\sum_{q=0}^{2n}\\Phi_q\\left(\\sum_{p=1}^n\\phi_{q,p}(x_p)\\right)\n$$\nConstructive proofs, and even more specific constructions can be found in <ref>Jürgen Braun and Michael Griebel. \"On a constructive proof of Kolmogorov’s superposition theorem\", http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.91.5436&rep=rep1&type=pdf</ref>\n\nIn a sense, they showed that the only true multivariate function is the sum, since every other function can be written using [[univariate]] functions and summing.<ref name=\"dia\">[[Persi Diaconis]] and Mehrdad Shahshahani, ''On Linear Functions of Linear Combinations'' (1984) p. 180 ([http://www-stat.stanford.edu/~cgates/PERSI/papers/nonlin_func.pdf link])</ref>\n\n==History==\nThe Kolmogorov–Arnold representation theorem is closely related to [[Hilbert's 13th problem]]. In his [[Paris]] lecture at the [[International Congress of Mathematicians]] in 1900, [[David Hilbert]] formulated [[Hilbert's problems|23 problems]] which in his opinion were important for the further development of mathematics.<ref>[[David Hilbert]], Mathematical problems, [[Bulletin of the American Mathematical Society]], '''8''' (1902), pp. 461–462.</ref> The 13th of these problems dealt with the solution of general equations of higher degrees. It is known that for algebraic equations of degree 4 the solution can be computed by formulae that only contain radicals and arithmetic operations. For higher orders, [[Galois theory]] shows us that the solutions of algebraic equations cannot be expressed in terms of basic algebraic operations. It follows from the so called [[Tschirnhaus transformation]] that the general algebraic equation <math> x^{n}+a_{n-1}x^{n-1}+\\cdot \\cdot \\cdot +a_{0}=0</math>  can be translated to the form <math> y^{n}+b_{n-4}y^{n-4}+\\cdot \\cdot \\cdot +b_{1}y+1=0</math>. The Tschirnhaus transformation is given by a formula containing only radicals and arithmetic operations and transforms. Therefore, the solution of an algebraic equation of degree <math>n</math>  can be represented as a superposition of functions of two variables if <math>n<7</math> and as a superposition of functions of <math>n-4</math> variables if <math>n\\geq 7</math>. For <math>n=7</math>  the solution is a superposition of arithmetic operations, radicals, and the solution of the equation  <math>y^{7}+b_{3}y^{3}+b_{2}y^{2}+b_{1}y+1=0</math>. \n\nA further simplification with algebraic transformations seems to be impossible which led to Hilbert's conjecture that \"A solution of the general equation of degree 7 cannot be represented as a superposition of continuous functions of two variables\". This explains the relation of [[Hilbert's thirteenth problem]] to the representation of a higher-dimensional function as superposition of lower-dimensional functions. In this context, it has stimulated many studies in the theory of functions and other related problems by different authors.<ref>Jürgen Braun, On Kolmogorov's Superposition Theorem and Its Applications, SVH Verlag, 2010, 192 pp.</ref>\n\n==Variants of the Kolmogorov–Arnold representation theorem==\nA variant of Kolmogorov's theorem that reduces the number of\nouter functions <math>\\Phi _{q}</math> is due to George Lorentz.<ref>George Lorentz, ''Metric entropy, widths, and superpositions of functions'', The American Mathematical Monthly, 69 (1962), pp. 469–485.</ref> He showed in 1962  that the outer functions <math>\\Phi_{q}</math> can be replaced by a single function <math>\\Phi</math>. More precisely, Lorentz proved the existence of functions <math>\\phi _{q,p}</math>, <math>q=0,1,\\ldots,2n,</math> <math>p=1,\\ldots,n,</math> such that \n\n:<math> f(\\bold x) = \\sum_{q=0}^{2n} \\Phi\\left(\\sum_{p=1}^{n} \\phi_{q,p}(x_{p})\\right)</math>.\n\nSprecher <ref>David A. Sprecher, ''On the structure of continuous functions of several variables'', [[Transactions of the American Mathematical Society]], '''115''' (1965), pp. 340–355.</ref> replaced the inner functions <math>\\phi_{q,p}</math> by one single inner function with an appropriate shift in its argument. He proved that there exist real values <math>\\eta, \\lambda_1,\\ldots,\\lambda_n</math>, a continuous function <math>\\Phi\\colon \\mathbb{R} \\rightarrow \\mathbb{R}</math>, and a real increasing continuous function <math>\\phi\\colon [0,1] \\rightarrow [0,1]</math> with <math>\\phi \\in \\operatorname{Lip}(\\ln 2/\\ln (2N+2))</math>, for <math>N \\geq n \\geq 2</math>, such that\n\n:<math> f(\\bold x) = \\sum_{q=0}^{2n} \\Phi\\left(\\sum_{p=1}^{n} \\lambda_p \\phi(x_{p}+\\eta q)+q \\right)</math>.\n\nPhillip A. Ostrand <ref>Phillip A. Ostrand, ''Dimension of metric spaces and Hilbert's problem 13'', [[Bulletin of the American Mathematical Society]], 71 (1965), pp. 619–622.</ref> generalized the Kolmogorov superposition theorem to compact metric spaces. For <math>p=1,...,m</math> let <math>X_p</math> be compact metric spaces of finite dimension <math>n_p</math> and let <math>n = \\sum_{p=1}^{m} n_p</math>. Then there exists continuous functions <math>\\phi_{q,p}\\colon X_p \\rightarrow [0,1], q=0,\\ldots,2n, p=1,\\ldots,m</math> and continuous functions <math>G_q\\colon [0,1] \\rightarrow \\mathbb{R}, q=0,\\ldots,2n</math> such that any continuous function <math>f\\colon X_1 \\times \\dots \\times X_m \\rightarrow \\mathbb{R}</math> is representable in the form \n\n:<math> f(x_1,\\ldots,x_m) = \\sum_{q=0}^{2n} G_{q}\\left(\\sum_{p=1}^{m} \\phi_{q,p}(x_{p})\\right) </math>.\n\n==Original references==\n*[[Andrey Kolmogorov|A. N. Kolmogorov]], \"On the representation of continuous functions of several variables by superpositions of continuous functions of a smaller number of variables\", ''[[Proceedings of the USSR Academy of Sciences]]'', 108 (1956), pp.&nbsp;179–182; English translation: ''Amer. Math. Soc. Transl.'', 17 (1961), pp.&nbsp;369–373.\n*[[Vladimir Arnold|V. I. Arnold]], \"On functions of three variables\", ''Proceedings of the USSR Academy of Sciences'', 114 (1957), pp.&nbsp;679–681; English translation: ''Amer. Math. Soc. Transl.'', 28 (1963), pp.&nbsp;51–54.\n\n==Further reading==\n*S. Ya. Khavinson, ''Best Approximation by Linear Superpositions (Approximate Nomography)'', AMS Translations of Mathematical Monographs (1997)\n\n==References==\n{{reflist}}\n\n \n", "meta": {"hexsha": "ddea71c094c7fc47368d3071ab0430b00a59c457", "size": 6952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/KART.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/KART.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/KART.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": 151.1304347826, "max_line_length": 1651, "alphanum_fraction": 0.750863061, "num_tokens": 1959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6720069946458725}}
{"text": "\n\\section{Finite element method and convolution}\\label{sec:mg}\nLet us first briefly describe finite\nelement methods for the numerical solution of the following boundary\nvalue problem\n\\begin{equation}\n\\label{laplace}\n-\\Delta u = f,  \\mbox{ in } \\Omega,\\quad\nu=0  \\mbox{ on } \\partial\\Omega,\\quad\n\\Omega=(0,1)^2.\n\\end{equation}\nFor the $x$ direction and the $y$ direction, we consider the partition:\n\\begin{equation}\\label{partitionyx}\n 0=x_0<x_1<\\cdots<x_{n+1}=1, \\quad x_i=\\frac{i}{m+1},\\quad (i=0,\\cdots,m+1);\n \\end{equation}\n \\begin{equation}\\label{partitiony}\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{equation}\nFor $\\Omega=(0,1)^2$, we just choose $m=n$. Such a uniform partition in the $x$ and $y$ directions leads us to a special example in two dimensions, a uniform square mesh $\\R_h^2 = \\big\\{(ih,jh); i, j \\in \\Z\\big\\}$ (Figure \\ref{fig:2dpartition}). \n\n\n\\begin{figure}\n\\begin{center}\n\\setlength{\\unitlength}{0.5mm}\n\\begin{picture}(45,45)(50,0)\n\\linethickness{0.25mm}\n\\multiput(0,0)(10,0){6}{\\line(0,1){50}}\n\\multiput(0,0)(0,10){6}{\\line(1,0){50}}\n\\put(0,0){\\line(1,1){50}}\n\\put(10,0){\\line(1,1){40}}\n\\put(20,0){\\line(1,1){30}}\n\\put(30,0){\\line(1,1){20}}\n\\put(40,0){\\line(1,1){10}}\n\\put(0,10){\\line(1,1){40}}\n\\put(0,20){\\line(1,1){30}}\n\\put(0,30){\\line(1,1){20}}\n\\put(0,40){\\line(1,1){10}}\n\\put(47,34){$\\displaystyle \\left. \\begin{array}{l}~ \\\\ ~\\end{array}\n\\right\\} h={1\\over n+1}$}\n\\put(54,14){$\\displaystyle N = n^2$}\n\\multiput(100,0)(10,0){6}{\\line(0,1){50}}\n\\multiput(100,0)(0,10){6}{\\line(1,0){50}}\n\\put(147,34){$\\displaystyle \\left. \\begin{array}{l}~ \\\\ ~\\end{array}\n\\right\\} h={1\\over n+1}$}\n\\put(154,14){$\\displaystyle N = n^2$}\n\\end{picture}\n\\setlength{\\unitlength}{0.5mm}\n\\end{center}\n\\label{fig:2dpartition}\n\\caption{Two-dimensional uniform grids for finite element}\n\\end{figure}\n\nWe consider two finite elements: continuous linear element and\nbilinear element. These two finite element methods find $u_h\\in V_h$\nsuch that\n\\begin{equation}\\label{Discrete:2d}\n(\\nabla u_h, \\nabla v_h)=(f, v_h),\\ \\forall v_h\\in V_h.\n\\end{equation}\n\n\nBasis functions $\\phi_{ij}$ satisfy \n\\begin{equation}\n  \\label{NodalBasis}\n\\phi_{ij}(x_k,y_l)=\\delta_{(i,j),(k,l)}.  \n\\end{equation}\n\nConsider continuous linear finite element discretization of \\eqref{laplace} on\nthe left triangulation in Fig \\ref{fig:2dpartition}. The discrete\nspace for linear finite element is\n$$\n\\mathcal V_h=\\{v_h: v_h|_K\\in P_1(K) \\text{ and } v_h \\text{ is globally continuous}\\}.\n$$ \n\nBy simple computation, we have\n\\begin{equation}\n(\\nabla \\phi_{i,j} , \\nabla \\phi_{k,l})=\n\\left\\{\n\t\t\\begin{array}{ll}\n\t\t-1 & \\mbox{ if } |k-i|+|j-l|= 1,\\\\     \n\t\t4 & \\mbox{ if } (k,l)=(i,j),\\\\\n\t\t0& \\mbox{ elsewhere}.\n\t\t\\end{array}\n\t\t\\right.\n\\end{equation}\nIt is easy to verify that the formulation for the linear element method is \n\\begin{equation}\n  \\label{2d-fe0}\nA\\ast u=4u_{i,j}-(u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1})=f_{i,j},~~u_{i,j}=0~~\\hbox{if}~~i ~~\\hbox{or}~~ j\\in \\{0, n+1\\},\n\\end{equation}\nwhere \n\\begin{equation}\\label{fij_fe}\nf_{i,j} = \\int_{\\Omega} f(x,y)\\phi_{i,j}(x,y) {\\rm d}x {\\rm d}y \\approx h^2 f(x_i, y_j).\n\\end{equation} \n\n\\begin{definition}\\label{def:convolution}\nA convolution defined on $\\mathbb{R}^{m\\times n}$ is a linear mapping \n$K\\ast: \\mathbb{R}^{m\\times n}\\mapsto \\mathbb{R}^{m\\times n}$ defined with padding,  \nfor any $g \\in \\mathbb{R}^{m\\times n}$ by:\n%We first consider $\\theta$ a convolution operator (with stride $1$) \n%and padding:\n\\begin{equation}\\label{con010}\n[K \\ast g]_{i,j} = \\sum_{p,q=-k}^k K_{p, q} g_{i + p, j + q}, \\quad i=1:m, j = 1:n.\n\\end{equation}\n\\end{definition}\nThe coefficients in \\eqref{con010} constitute  a kernel matrix\n\\begin{equation}\nK \\in \\mathbb{R}^{(2k+1) \\times (2k+1)},\n\\end{equation}\nwhere $k$ is often taken as a small integer. \nHere we note that the indices for the entries in $K$ are given in a special way. \nFor example, if $k=1, K\\in \\mathbb R^{3\\times 3}$, and \n$$\nK=\\begin{pmatrix}\n\tK_{-1,-1} &K_{-1,0} &K_{-1,1} \\\\\n\tK_{0,-1} &K_{0,0} &K_{0,1} \\\\\n\tK_{1,-1} &K_{1,0} &K_{1,1} \\\\\n\t\\end{pmatrix},\n$$\nfor we may have the following 2D Laplacian kernel\n\\begin{equation}\\label{key}\nK=\\begin{pmatrix}\n0 &-1 &0\\\\\n-1 &4&-1 \\\\\n0 &-1 &0 \\\\\n\\end{pmatrix}.\n\\end{equation}  \nHere padding means how $ g_{i+ p, j + q}$ is defined\nwhen $(i+ p, j + q)$ is out of $1:m$ or $1:n$. \nThe following three choices are often used\n\\begin{equation}\\label{eq:padding}\ng_{i + p, j + q} = \\begin{cases}\n0,  \\quad &\\text{zero padding}, \\\\\nf_{(i + p)\\pmod{m}, (s + q)\\pmod{n}},  \\quad &\\text{periodic padding}, \\\\\nf_{|i-1 +p|, |j -1  +q|},  \\quad &\\text{reflected padding}, \\\\\n\\end{cases}\n\\end{equation}\nif \n\\begin{equation}\ni + p \\notin \\{1, 2, \\dots, m\\} ~\\text{or} ~  j+ q \\notin \\{1, 2, \\dots, n\\}.\n\\end{equation}\nHere $ d \\pmod{m} \\in \\{1, \\cdots, m\\} $  means the remainder when $d$ is divided by $m$.\n\n\\begin{definition}\\label{def:convolution2}\nFor $g \\in \\mathbb{R}^{m\\times n}$, convolution with stride $2$ is defined as \n\\begin{equation}\\label{stride_2}\n[K \\ast_2 g]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} g_{2i + p-1, 2j + q-1},  \n\\quad i = 1: \\lfloor \\frac{m+1}{2}\\rfloor , j = 1: \\lfloor \\frac{n+1}{2} \\rfloor.\n\\end{equation}\n\\end{definition}\n\nUsing the convolutional notation \\eqref{con010}, \\eqref{2d-fe0} can be written as \n\\begin{equation}\n  \\label{eq:Ac}\nA\\ast u=f\n\\end{equation}\nwith \n\\begin{equation}\n  \\label{Ac}\nA=\n\\begin{pmatrix}\n0&-1&0\\\\\n-1&4&-1\\\\\n0&-1&0\n\\end{pmatrix}\n.\n\\end{equation}\n\n\\begin{proposition}\\label{prop:A}\nThe mapping $A\\ast$ has following properties\n\\begin{enumerate}\n\\item $A$ is symmetric, namely \n$$\n(A\\ast u, v)_{l^2}=(u,A\\ast v)_{l^2}.\n$$\n\\item  $(A\\ast v, v)_F>0, ~~~\\hbox{if}~~~v\\neq 0.$\n\\item $A\\ast u=f$ if and only if \n\\begin{equation}\\label{minProblem}\nu\\in \\argmin_{v\\in \\mathcal V_h} J(v)={1\\over 2}(A\\ast v,v)-(f,v).\n\\end{equation}\n\\item The eigenvalues $\\lambda_{kl}$ and eigenvectors $u^{kl}$ of $A$ are given by\n$$\n\\lambda_{kl}=4(\\sin^2\\frac{k\\pi}{2(n+1)}+ \\sin^2\\frac{l\\pi}{2(n+1)}),\n$$\n$$\nu_{ij}^{kl}=\\sin \\frac{ki\\pi}{n+1}\\sin \\frac{lj\\pi}{n+1},\\ 1\\leq i\\leq n,\\ 1\\leq j\\leq n,\n$$\nand  $\\rho(A)<8$. Furthermore,\n\\begin{equation*}\n\\lambda_{n,n}=8\\cos^2\\frac{\\pi}{2(n+1)}\\approx 8(1- ({\\pi\\over 2(n+1)})^2) \\approx 8-{2\\pi^2\\over (n+1)^2}\n\\end{equation*}\n\\end{enumerate}\n\\end{proposition}\n\n\n  \n\n\n\n\n", "meta": {"hexsha": "4fb9496f7f8ca3bf10852cdec8735ca564ec96c3", "size": 6299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.6-multigrid.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.6-multigrid.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.6-multigrid.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": 31.495, "max_line_length": 246, "alphanum_fraction": 0.6378790284, "num_tokens": 2651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6719936877937082}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n{\\title{\\textbf{Playing Around with Topology}}}\n\\author{Mehdi Drissi}\n\\date{}\n\\allowdisplaybreaks\n\n\\begin{document}\n\\maketitle\n\\newpage\n\n\\tableofcontents\n\\newpage\n\n\\begin{center}\n\\section{Definitions}\n\\end{center}\n\n\\subsection{Weakly Disconnected}\nLet $(X,\\tau)$ be a topological space. Then, $(X,\\tau)$ will be called $\\textbf{weakly disconnected}$ if there exists an an open, non-empty, totally disconnected set.\\\\\n\n\\subsection{Open-Lacking, Partially Connected}\nLet $(X, \\tau)$ be a topological space. Then, $(X, \\tau)$ will be called $\\textbf{open-lacking, partially connected}$ if there exists a set with empty interior, but is not totally disconnected.\\\\\n\n\n\\subsection{Interval in the Reals}\nAn interval in the reals can in 9 possible forms. They are,\\\\\n\n\\begin{itemize}\n\\item $(a,b)$\n\\item $[a,b]$\n\\item $[a,b)$\n\\item $(a,b]$\n\\item $(-\\infty,a)$\n\\item $(-\\infty,a]$\n\\item $(a,\\infty)$\n\\item $[a,\\infty)$\n\\item $\\mathbb{R}$\n\\end{itemize}\n\n\n\\newpage\n\n\\section{Conjectures}\n\\subsection{Strengthening Lemma 1}\nCan the first lemma be re-written to be,\\\\\n\nLet $(X,\\tau)$ be a locally connected space that is not the topology on a one point set. Then $(X,\\tau)$ is not weakly disconnected.\\\\\n\nComments: I know T1-ness is not really necessary (Lemma 3.2). As $U$ was totally disconnected, I knew that A was closed in $U$. The issue was knowing that $A$ was closed in $X$. While a closed set relative to an open subspace, does not have to be closed in the original space, my intuition is that the extra knowledge that $U$ is totally disconnected could be helpful. And honestly, locally connected feels at the heart of the issue of weakly disconnected based on examining why $\\mathbb{R}$ with the usual topology is not weakly disconnected. I'm not confident connected is not needed, though.\n\n\\subsection{General Conjecture 1}\nLet $f: (X,\\tau) \\to (\\mathbb{R},\\rho)$ be a continuous function from the topological space $(X,\\tau)$ to the reals with the standard topology. Fully characterize the types of sets that can be the preimage of an interval.\\\\\n\nComments: My current thoughts are that the characterization is any set that is the intersection of a dense set with empty interior and an open set. For some domain spaces, the empty interior condition should be replaceable with totally disconnected (although what those spaces are is its own problem).\n\n\\subsection{General Conjecture 2}\nFully characterize weakly disconnected spaces.\\\\\n\nComments: While I currently have a sufficient condition for a space to not be weakly disconnected, I know that it is not a necessary condition. Lemma 3.2 reveals that being T1 is not necessary to not be weakly disconnected.\n\n\\subsection{General Conjecture 3}\nFully characterize open-lacking, partially connected spaces.\\\\\n\nComments: This one I'm the least sure of. The issue here is that the you can find an example of an open-lacking, partially connected space if you consider $\\mathbb{R}^2$ with the Euclidean metric (the x-axis is a connected set with empty interior). That a space can be open-lacking, partially connected even with a pretty nice space, it means you'll likely need some very strong conditions. Kind of shows how extremely nice the reals with the standard topology are.\n\n\\subsection{Closed in Open, Totally Disconnected Subspace}\nLet $(X,\\tau)$ be a locally connected topological space. Let $(U,\\tau_U)$ be an open, totally disconnected subspace of $(X,\\tau)$. Are closed sets in $U$ closed in $X$? \\\\\n\nComment: I'm pretty undecided on the correct answer to this. I'm curious about it as it would be a step forward in a more important conjecture. And if it is false, it'd be nice to see a counterexample. I'm not sure the locally connectedness is even helpful and I'll likely start by thinking about how it could fail if we ignore the totally disconnected and locally connected aspects in the problem.\n\n\\newpage\n\n\\section{Lemmas}\n\n\\subsection{Relationship between Connectivity and Weakly Disconnected}\nLet $(X,\\tau)$ be a locally connected, connected, T1 space that is not the topology on a one point set. Then, $(X, \\tau)$ is not weakly disconnected.\\\\\n\nProof:\\\\\n\nThe proof strategy will be to use proof by contrapositive. Let $(X, \\tau)$ be a weakly disconnected space. Let $U$ be an open, non-empty totally disconnected set. Let $(U, \\tau_U)$ be the subspace topology of $U$. As $U$ is totally disconnected and non-empty, its connected components are singletons.\nHere, we'll split the proof into two cases. Either all of its connected components are open or they there exists a connected component that is not open.\\\\\n\nIf there exists a connected component that is not open then its connected components are not all open which means it is not locally connected. As locally connected is hereditary for open subspaces, $(X,\\tau)$, can not be locally connected. \\\\\n\nIf there exists a connected component that is open, call that component $A$. As $U$ is totally disconnected, $A$ must be a singleton. Since $U$ is open, any open set in $U$ is also open in $X$. This means $A$ is an open singleton in $X$. Now we break into another two cases.\\\\\n\nIf $X$ is a T1 space, singletons are closed making $A$ a clopen set. Since $X$ is not a one point set, $A$ is a non-trivial clopen set. This means $(X,\\tau)$ is not connected. \\\\\n\nThe other possible situation is that $X$ is not a T1 space.\\\\\n\nIn any case, $(X, \\tau)$ can not simultaneously have the three properties of being locally connected, connected, and T1. This completes the proof.\n\n\\subsection{T1 is not Necessary to not be Weakly Disconnected}\nThere exist topological spaces $(X,\\tau)$ such that they are not a T1 space, but are not weakly disconnected.\\\\\n\nProof:\\\\\n\nThe proof will be by a simple example. Let $X = \\{1,2\\}$ and let it have the trivial topology. Then, $(X,\\tau)$ is not weakly disconnected while at the same time not being a T1 space.\\\\\n\nComment: This theorem shows that the previous lemma's sufficient condition for a space not being weakly disconnected can not be a necessary condition. The example not only fails to be a T1 space, but isn't even a T0 space. Any space with the trivial topology (ignoring the one point space) can serve as an example of a space that is not weakly disconnected, but isn't T0. Interestingly, this example is still locally connected and connected.\n\n\\subsection{Kernel of Continuous Functions to $ \\mathbb{R}^n $}\nLet $f: (X,\\tau) \\to (\\mathbb{R}^n,\\rho)$ be a continuous function from the topological space $(X,\\tau)$ to $\\mathbb{R}^n$ with the usual Euclidean metric. Then, the kernel of $f$ is a closed set in $X$.\\\\\n\nProof:\\\\\n\nThe kernel of $f$ is $f^{-1}(\\{\\mathbf{0}\\})$. As the set, $\\{\\mathbf{0}\\}$, is closed in $(\\mathbb{R}^n,\\rho)$, the preimage must be closed because $f$ is a continuous function. This shows that the kernel is closed.\n\n\\subsection{Lemma: Weakly Disconnected Property}\nA topological space is weakly disconnected if and only if the interior of a totally disconnected set need not be empty.\\\\\n\nProof:\\\\\n\nWe'll start by assuming the topological space is weakly disconnected. Then, there exists an open, non-empty, totally disconnected set $U$. The $Int(U) = U$ because $U$ is open. As $U$ is totally disconnected and non-empty, it serves as an example of a totally disconnected set whose interior is not empty.\\\\\n\nNow for the other direction, assume there exists a set $U$ that is totally disconnected and whose interior is not empty. Let $V = Int(U)$. Then, $V$ is an open set because the interior of any set is not open. $V$ is also totally disconnected because it is a subset of $U$ and any subset of a totally disconnected set is totally disconnected (since totally disconnected is a hereditary property). As the $Int(U)$ is not empty, $V$ is not empty. So, $V$ is an open, totally disconnected, non-empty set which shows that the space is weakly disconnected.\\\\\n\nComment: This property was actually my original characterization of a weakly disconnected space. The open, totally disconnected, non-empty set version was discovered as an equivalent form of this property that is easier to actually play with.\n\n\\newpage\n\\section{Theorems}\n\n\\newpage\n\\section{Interesting Examples}\n\n\n\\newpage\n\\section{Temporary Lemmas/Theorems}\nThe title refers to how these statements all currently lack a proof, but I do know of a proof somewhere. I'll add all their proofs and put them in the proper section later.\n\n\\subsection{Any Closed Set can be Kernel of Continuous Function to $\\mathbb{R}^n$}\nLet $(X,\\tau)$ be a topological space and $C$ be a closed set of $X$. Then, there exists a continuous function $f: (X,\\tau) \\to (\\mathbb{R}^n,\\rho)$ whose kernel is $C$ and $(\\mathbb{R}^n,\\rho)$ refers to $\\mathbb{R}^n$ with the usual Euclidean metric.\\\\\n\n\n\\subsection{Lemma: Irrationals are not the Preimage of an\\\\ Interval}\nLet $f: (X,\\tau) \\to (\\mathbb{R},\\rho)$ be a continuous function from the topological space $(X,\\tau)$ to the reals with the standard topology. Then, the irrationals can not be the preimage of any interval.\\\\\n\n\n\\subsection{Lemma: Preimage of an Interval Failure}\nLet $f: (X,\\tau) \\to (\\mathbb{R},\\rho)$ be a continuous function from the topological space $(X,\\tau)$ to the reals with the standard topology. Then, a dense set with empty interior intersected with an open set (all in $\\mathbb{R}$ with the standard topology) can not be the preimage of any interval.\\\\\n\nComment: There is one major thing I want to generalize in this. I want to use something more general than an interval in $\\mathbb{R}$. My guess is to first look at an open ball in any metric space and see if the proof works (or where it fails). I'm curious whether I can extend the result in some way to a space that is not a metric space for the range or to see if I can use something a bit more general than an open ball in a metric space. The condition of empty interior is also a weird one that I'd like modified. That will probably occur as a corollary depending on how the other main conjectures go.\n\n\\end{document}", "meta": {"hexsha": "22ebc63e5136dbf60a81eacfb8f042bf27899a31", "size": 10070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Topology Fun.tex", "max_stars_repo_name": "hmc-cs-mdrissi/MathExploration", "max_stars_repo_head_hexsha": "061d25cd73e3f9a538473d1e6410c3540d2bd053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Topology Fun.tex", "max_issues_repo_name": "hmc-cs-mdrissi/MathExploration", "max_issues_repo_head_hexsha": "061d25cd73e3f9a538473d1e6410c3540d2bd053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Topology Fun.tex", "max_forks_repo_name": "hmc-cs-mdrissi/MathExploration", "max_forks_repo_head_hexsha": "061d25cd73e3f9a538473d1e6410c3540d2bd053", "max_forks_repo_licenses": ["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.0405405405, "max_line_length": 605, "alphanum_fraction": 0.7517378352, "num_tokens": 2578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382023207901, "lm_q2_score": 0.7799928951399099, "lm_q1q2_score": 0.6719936767018265}}
{"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            Since $\\vect{F}=\\<P,Q,R\\>$ is conservative,\n            we know from a theorem in section 16.3 from the previous packet\n            that $Q_x=P_y$, $P_z=R_x$, and $R_y=Q_z$. Therefore:\n            \\[\n              \\text{curl }\\vect{F}\n                =\n              \\<R_y-Q_z,P_z-R_x,Q_x-P_y\\>\n                =\n              \\<0,0,0\\>=\\vect{0}\n            \\]\n          \\end{solution}\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            Let $\\vect{F}=\\<P,Q,R\\>=\\<x+y,z^2-3,yz\\>$. Then\n            \\[\n              \\text{curl }\\vect{F}\n                =\n              \\<R_y-Q_z,P_z-R_x,Q_x-P_y\\>\n            \\]\n            \\[\n                =\n              \\<(z)-(2z),(0)-(0),(0)-(1)\\>\n                =\n              \\<-z,0,-1\\>\n            \\]\n\n            By plugging in the point $(2,0,-1)$ we get\n            \\[\n              \\<-(-1),0,-1\\>=\\<1,0,-1\\>\n            \\]\n          \\end{solution}\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            Green's Theorem was given in section 4.1 to be\n            \\[\n              \\int_C \\vect{F}\\cdot\\dvar{\\vect{r}}\n                =\n              \\iint_R Q_x-P_y \\dvar{A}\n            \\]\n\n            Since  \\[\n              \\text{curl }\\vect{F}\n                =\n              \\<R_y-Q_z,P_z-R_x,Q_x-P_y\\>\n            \\]\n            we have that  \\[\n              \\text{curl }\\vect{F} \\cdot \\veck\n                =\n              \\<R_y-Q_z,P_z-R_x,Q_x-P_y\\> \\cdot \\<0,0,1\\>\n                =\n              Q_x-P_y\n            \\]\n\n            Therefore\n            \\[\n              \\int_C \\vect{F}\\cdot\\dvar{\\vect{r}}\n                =\n              \\iint_R Q_x-P_y \\dvar{A}\n                =\n              \\iint_R \\text{curl }\\vect{F} \\cdot \\veck \\dvar{A}\n            \\]\n          \\end{solution}\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            We want to compute\n            \\[\n              \\text{div }(\\text{curl }\\vect{F})\n                =\n              \\text{div }(\\<R_y-Q_z,P_z-R_x,Q_x-P_y\\>)\n            \\]\n\n            Since divergence is the sum of the partial derivatives:\n            \\[\n              \\text{div }(\\<R_y-Q_z,P_z-R_x,Q_x-P_y\\>)\n                =\n              (R_{yx}-Q_{zx}) + (P_{zy}-R_{xy}) + (Q_{xz}-P_{yz})\n            \\]\n\n            By regrouping, we find that\n            \\[\n              (R_{yx}-Q_{zx}) + (P_{zy}-R_{xy}) + (Q_{xz}-P_{yz})\n                =\n              (R_{yx}-R_{xy}) + (P_{zy}-P_{yz}) + (Q_{xz}-Q_{zx})\n                =\n              0\n            \\]\n          \\end{solution}\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            Let $\\vect{F}=\\<P,Q,R\\>=\\<x+y,z^2-3,yz\\>$.\n            We compute divergence as follows:\n            \\[\n              \\text{div }\\vect{F}\n                =\n              P_x+Q_y+R_z\n                =\n              (1)+(0)+(y)\n                =\n              1+y\n            \\]\n\n            Plugging in the point $(2,0,-1)$ gives\n            \\[\n              1+(0) = 1\n            \\]\n          \\end{solution}\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            Let $\\vect{F}=\\<x+y,x^2+y^2\\>$, so then its divergence is\n            $\\text{div }\\vect{F}=(1)+(2y)=1+2y$.\n            By the previous theorem, the flux may be computed by\n            \\[\n              \\int_C \\vect{F}\\cdot\\vect{n}\\dvar{s}\n                =\n              \\iint_R \\text{div }\\vect{F} \\dvar{A}\n                =\n              \\iint_R 1+2y \\dvar{A}\n            \\]\n\n            Since $R$ is the unit square,\n            \\[\n              \\iint_R 1+2y \\dvar{A}\n                =\n              \\int_0^1\\int_0^1 1+2y \\dvar{y}\\dvar{x}\n                =\n              \\int_0^1 2\\dvar{x}\n                =\n              2\n            \\]\n          \\end{solution}\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            The surface $z=f(x,y)$ may be parametrized by\n              \\[\n                \\vect{r}(x,y) = \\<x,y,f(x,y)\\>\n              \\]\n            So we can rewrite the surface as $z=7-2x+y=f(x,y)$, and use the\n            parameterization\n              \\[\n                \\vect{r}(x,y) = \\<x,y,7-2x+y\\>\n              \\]\n          \\end{solution}\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            The surface $z=\\sqrt{x^2+y^2}$ has cylindrical coordinate\n            equation $z=\\sqrt{r^2}=r$.\n            Substituting that into the cylindrical coordinate transformation\n            \\[\n              \\vect{r}(r,\\theta,z)\n                =\n              \\<r\\cos\\theta,r\\sin\\theta,z\\>\n            \\]\n            we get\n            \\[\n              \\vect{r}(\\theta,z)\n                =\n              \\<z\\cos\\theta,z\\sin\\theta,z\\>\n            \\]\n\n            Since the cone revolves fully around the $z$-axis,\n            $0\\leq\\theta\\leq2\\pi$, and we already know $0\\leq z\\leq 3$.\n          \\end{solution}\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            The surface $x^2+y^2+z^2=9$ has spherical coordinate\n            equation $\\rho=3$.\n            Substituting that into the spherical coordinate transformation\n            \\[\n              \\vect{r}(\\rho,\\phi,\\theta)\n                =\n              \\<\\rho\\sin\\phi\\cos\\theta, \\rho\\sin\\phi\\sin\\theta, \\rho\\cos\\phi\\>\n            \\]\n            we get\n            \\[\n              \\vect{r}(\\phi,\\theta)\n                =\n              \\<3\\sin\\phi\\cos\\theta, 3\\sin\\phi\\sin\\theta, 3\\cos\\phi\\>\n            \\]\n\n            Since the sphere revolves fully around the $z$-axis,\n            $0\\leq\\theta\\leq2\\pi$, and since it includes points on the positive\n            and negative $z$-axis, $0\\leq\\phi\\leq\\pi$.\n          \\end{solution}\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            The surface area of $S$ is given by\n            \\[\n              \\iint_S \\dvar{\\sigma}\n                =\n              \\iint_R |\\vect{r}_\\phi\\times\\vect{r}_\\theta|\\dvar{A}\n            \\]\n\n            We may compute the cross product:\n            \\[\n              \\vect{r}_\\phi\\times\\vect{r}_\\theta\n                =\n              \\<\\cos\\phi\\cos\\theta,\\cos\\phi\\sin\\theta,-\\sin\\phi\\>\n                \\times\n              \\<-\\sin\\phi\\sin\\theta,\\sin\\phi\\cos\\theta,0\\>\n            \\]\n            \\[\n                =\n              \\<\\sin^2\\phi\\cos\\theta,-\\sin^2\\phi\\sin\\theta,\\sin\\phi\\cos\\phi\\>\n            \\]\n\n            And its magnitude is then\n            \\[\n              |\\vect{r}_\\phi\\times\\vect{r}_\\theta|\n                =\n              |\\sin\\phi|\n            \\]\n            but we can drop the absolute values since $0\\leq\\phi\\leq\\pi$.\n\n            Using the bounds and plugging in, we get\n            \\[\n              \\iint_R |\\vect{r}_\\phi\\times\\vect{r}_\\theta|\\dvar{A}\n                =\n              \\int_0^{2\\pi}\\int_0^\\pi \\sin\\phi \\dvar{\\phi}\\dvar{\\theta}\n                =\n              \\int_0^{2\\pi} 2\\dvar{\\theta}\n                =\n              4\\pi\n            \\]\n          \\end{solution}\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            Note that for the parameterization $\\vect{r}(u,v)=\\<2u,u+2v,2u-v\\>$,\n            $\\vect{r}(0,0)=\\<0,0,0\\>$, $\\vect{r}(1,0)=\\<2,1,2\\>$,\n            $\\vect{r}(0,1)=\\<0,2,-1\\>$, and $\\vect{r}(1,1)=\\<2,3,1\\>$. So\n            it maps the unit square onto the given parallelogram.\n\n            So we want to compute\n            \\[\n              \\iint_S \\dvar{\\sigma}\n                =\n              \\iint_R |\\vect{r}_u\\times\\vect{r}_v|\\dvar{A}\n                =\n              \\int_0^1\\int_0^1 |\\vect{r}_u\\times\\vect{r}_v|\\dvar{v}\\dvar{u}\n            \\]\n\n            We compute the cross product as follows:\n            \\[\n              \\vect{r}_u\\times\\vect{r}_v\n                =\n              \\<2,1,2\\>\\times\\<0,2,-1\\>\n                =\n              \\<-5,2,4\\>\n            \\]\n            \\[\n              |\\vect{r}_u\\times\\vect{r}_v|\n                =\n              \\sqrt{25+4+16}\n                =\n              \\sqrt{45}\n                =\n              3\\sqrt{5}\n            \\]\n\n            It follows that\n            \\[\n              \\int_0^1\\int_0^1 3\\sqrt{5}\\dvar{v}\\dvar{u}\n                =\n              \\int_0^1 3\\sqrt{5}\\dvar{u}\n                =\n              3\\sqrt{5}\n            \\]\n          \\end{solution}\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            We want to compute\n            \\[\n              \\iint_S \\vect{F}\\cdot\\dvar{\\vect\\sigma}\n                =\n              \\iint_R \\vect{F}\\cdot(\\vect{r}_\\phi\\times\\vect{r}_\\theta)\\dvar{A}\n                =\n              \\int_0^{2\\pi}\\int_0^\\pi\n              \\vect{F}\\cdot(\\vect{r}_\\phi\\times\\vect{r}_\\theta)\n              \\dvar{\\phi}\\dvar{\\theta}\n            \\]\n\n            Using the given parametrization,\n            \\[\n              \\vect{F}=\\<x,y,z\\>=\n              \\<\n                3\\sin\\phi\\cos\\theta,\n                3\\sin\\phi\\sin\\theta,\n                3\\cos\\phi\n              \\>\n            \\]\n            and the cross product is\n            \\[\n              \\vect{r}_\\phi\\times\\vect{r}_\\theta\n                =\n              \\<\n                3\\cos\\phi\\cos\\theta,\n                3\\cos\\phi\\sin\\theta,\n                -3\\sin\\phi\n              \\>\n                \\times\n              \\<\n                -3\\sin\\phi\\sin\\theta,\n                3\\sin\\phi\\cos\\theta,\n                0\n              \\>\n            \\]\n            \\[\n                =\n              \\<\n                9\\sin^2\\phi\\cos\\theta,\n                9\\sin^2\\phi\\sin\\theta,\n                9\\sin\\phi\\cos\\phi\n              \\>\n            \\]\n\n            So their dot product gives:\n            \\[\n              \\int_0^{2\\pi}\\int_0^\\pi\n              \\vect{F}\\cdot(\\vect{r}_\\phi\\times\\vect{r}_\\theta)\n              \\dvar{\\phi}\\dvar{\\theta}\n                =\n              \\int_0^{2\\pi}\\int_0^\\pi\n              27\\sin^3\\phi\\cos^2\\theta +\n              27\\sin^3\\phi\\sin^2\\theta +\n              27\\sin\\phi\\cos^2\\phi\n              \\dvar{\\phi}\\dvar{\\theta}\n            \\]\n            \\[\n                =\n              \\int_0^{2\\pi}\\int_0^\\pi\n              27\\sin^3\\phi +\n              27\\sin\\phi\\cos^2\\phi\n              \\dvar{\\phi}\\dvar{\\theta}\n                =\n              \\int_0^{2\\pi}\\int_0^\\pi\n              27\\sin\\phi\n              \\dvar{\\phi}\\dvar{\\theta}\n            \\]\n          \\end{solution}\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            Following the hint, the curl of $\\<z^2,x^2,y^2\\>$ may be computed\n            to be:\n            \\[\n              \\text{curl }\\<z^2,x^2,y^2\\>\n                =\n              \\<2y-0,2z-0,2x-0\\>\n            \\]\n\n            So it follows from Stokes' Theorem that\n            \\[\n              \\iint_S \\<2y,2z,2x\\>\\cdot\\dvar{\\vect\\sigma}\n                =\n              \\iint_S \\text{curl }\\<z^2,x^2,y^2\\>\\cdot\\dvar{\\vect\\sigma}\n                =\n              \\int_C \\<z^2,x^2,y^2\\>\\cdot\\dvar{\\vect r}\n            \\]\n\n            $C$ is the boundary of $S$, the circle $x^2+y^2=1$ in the\n            plane $z=0$. It has a parametrization\n            \\[\n              \\vect{r}(t) = \\<\\cos t,\\sin t, 0\\>\n            \\]\n            for $0\\leq t\\leq 2\\pi$ and derivative\n            \\[\n              \\frac{d\\vect r}{dt} = \\<-\\sin t,\\cos t, 0\\>\n            \\]\n\n            So the line integral may be rewritten as\n            \\[\n              \\int_C \\<z^2,x^2,y^2\\>\\cdot\\dvar{\\vect r}\n                =\n              \\int_C \\<z^2,x^2,y^2\\>\\cdot\\frac{d\\vect r}{dt}\\dvar{t}\n                =\n              \\int_0^{2\\pi}\n              \\<0^2,(\\cos t)^2,(\\sin t)^2\\>\n              \\cdot\n              \\<-\\sin t,\\cos t, 0\\>\n              \\dvar{t}\n            \\]\n            \\[\n                =\n              \\int_0^{2\\pi} 0 + \\cos^3(t) + 0 \\dvar{t}\n                =\n              \\int_0^{2\\pi} \\cos^3(t) \\dvar{t}\n            \\]\n          \\end{solution}\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            By the Divergence Theorem:\n            \\[\n              \\iint_S \\<x+y,y^2+z^2,z^3+x^3\\>\\cdot\\dvar{\\vect\\sigma}\n                =\n              \\iiint_D \\text{div }\\<x+y,y^2+z^2,z^3+x^3\\>\\dvar{V}\n            \\]\n            \\[\n                =\n              \\int_0^1\\int_0^1\\int_0^1 (1)+(2y)+(3z^2)\\dvar{z}\\dvar{y}\\dvar{x}\n            \\]\n          \\end{solution}\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            Figure it out yourself. :-)\n          \\end{solution}\n\n\n\\end{document}", "meta": {"hexsha": "75b8b983d389e6d8e30ded80ec9a9d0c7fa0acca", "size": 22684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packet4_2_solutions.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_solutions.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_solutions.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": 28.7503168568, "max_line_length": 80, "alphanum_fraction": 0.4639393405, "num_tokens": 6988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303285397348, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.6719279927418874}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\nPage 136\n\\section{If $B=\\text{ball} l^{\\infty}$, show that $d(\\phi, \\psi) = \\sum_{j=1}^{\\infty}{2^{-j} | \\phi(j) - \\psi(j)|}$ defines a metric on $B$ and that this metrics defines the weak-star topology on $B$}\n\n$d$ is a metric:\n\n$d(\\phi, \\phi) = \\sum_{j=1}^{\\infty}{2^{-j} | \\phi(j) - \\phi(j)|} = 0$\n\n$d(\\phi, \\psi) = \\sum_{j=1}^{\\infty}{2^{-j} | \\phi(j) - \\psi(j)|} = \\sum_{j=1}^{\\infty}{2^{-j} | \\psi(j) - \\phi(j)|} = d(\\psi, \\phi)$\n\n\nGiven an arbitrary non-negative number $j$, by the triangle inequality:\n\\begin{align}\n| ( \\phi(j) - \\psi(j) ) + (\\psi(j) - \\rho(j) )| &\\le | \\phi(j) - \\psi(j)| +  | \\psi(j) - \\rho(j)| \\\\\n| \\phi(j) - \\rho(j)| &\\le | \\phi(j) - \\psi(j)| +  | \\psi(j) - \\rho(j)| \\\\\n\\end{align}\n\nTherefore, since $j$ was chosen arbitrarily:\n\\begin{align}\n\\sum_{j=1}^{\\infty}{2^{-j} | \\phi(j) - \\rho(j)|} &\\le \\sum_{j=1}^{\\infty}{2^{-j} | \\phi(j) - \\psi(j)|} + \\sum_{j=1}^{\\infty}{2^{-j} | \\psi(j) - \\rho(j)|} \\\\\nd(\\phi, \\rho) &\\le d(\\phi, \\psi) + \\d(\\psi, \\rho)\n\\end{align}\n\nWe now have to show that given $\\phi$ in $B$ and $\\varepsilon>0$,  $\\{\\psi \\in $B$ : d(\\phi, \\psi) < \\varepsilon\\}$ is open in the weak* topology.\n\nA set $U$ of $B$ is weakly open if and only if for every $x^*_0$ in $U$ there is an $\\varepsilon$ and there are $x_1, ... , x_n$ in $l^1$ such that\n\n$$\\bigcap^n_{i=1}\\{x^*\\in B : |\\langle x_k, x^* - x^*_0 \\rangle| < \\varepsilon_j\\} \\subseteq U$$\n\n\n\\end{document}", "meta": {"hexsha": "59e6b64a4b829a3c7c12beaf44a665bbc254f177", "size": 1483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/5_Weak_Topologies/5_separability.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "analysis/5_Weak_Topologies/5_separability.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis/5_Weak_Topologies/5_separability.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": 41.1944444444, "max_line_length": 201, "alphanum_fraction": 0.5495616993, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6719279873569501}}
{"text": "\n\\chapter{Doubly indexed recurrences}\n\n%\\section{Splitting $\\mathcal{C}$, the Catalan triangle}\n\nA Riordan array $\\mathcal{R}$ is usually denoted by a pair\nof functions $(d(t), h(t))$, with the main request $h(0)=0$; \nmoreover, an array $\\mathcal{R}$ is \\emph{proper} if $d(0)\\neq 0$\nand $\\left.\\frac{\\partial h(t)}{\\partial t}\\right|_{t=0}\\neq0$.\nIt is possible to characterize coefficients lying on column $k$ \n-- indexing is $0$-based, conventionally -- with the following\ngf:\n\\begin{displaymath}\n    d(t)h(t)^{k}\n\\end{displaymath}\n\nAssume to start with a purely generic matrix:\n\\begin{equation}\n\\left[\\begin{matrix}\nc_{0,0} &  &  &  &  &  &  &  &  &  \\\\\nc_{1,0} & c_{1,1} &  &  &  &  &  &  &  &  \\\\\nc_{2,0} & c_{2,1} & c_{2,2} &  &  &  &  &  &  &  \\\\\nc_{3,0} & c_{3,1} & c_{3,2} & c_{3,3} &  &  &  &  &  &  \\\\\nc_{4,0} & c_{4,1} & c_{4,2} & c_{4,3} & c_{4,4} &  &  &  &  &  \\\\\nc_{5,0} & c_{5,1} & c_{5,2} & c_{5,3} & c_{5,4} & c_{5,5} &  &  &  &  \\\\\nc_{6,0} & c_{6,1} & c_{6,2} & c_{6,3} & c_{6,4} & c_{6,5} & c_{6,6} &  &  &  \\\\\nc_{7,0} & c_{7,1} & c_{7,2} & c_{7,3} & c_{7,4} & c_{7,5} & c_{7,6} & c_{7,7} &  &  \\\\\nc_{8,0} & c_{8,1} & c_{8,2} & c_{8,3} & c_{8,4} & c_{8,5} & c_{8,6} & c_{8,7} & c_{8,8} &  \\\\\nc_{9,0} & c_{9,1} & c_{9,2} & c_{9,3} & c_{9,4} & c_{9,5} & c_{9,6} & c_{9,7} & c_{9,8} & c_{9,9} \\\\\n\\end{matrix}\\right]\n\\label{eq:purely:generic:catalan}\n\\end{equation}\nand unfold each term starting from row $1$ according to the Catalan recurrence:\n\\begin{equation}\nc_{n + 1,k + 1} = c_{n,k} + c_{n,k + 1} + c_{n,k + 2} + c_{n,k + 3} + c_{n,k + 4} + c_{n,k + 5} + c_{n,k + 6} + c_{n,k + 7} + c_{n,k + 8} + c_{n,k + 9}\n\\label{eq:catalan:rec}\n\\end{equation}\nthe result is the following matrix, depending only on $c_{0,0}$, \\textcolor{blue}{blue} colored:\n\\begin{equation}\n\\left[\\begin{matrix}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\nc_{0,0} & c_{0,0} &  &  &  &  &  &  &  &  \\\\\n2 c_{0,0} & 2 c_{0,0} & c_{0,0} &  &  &  &  &  &  &  \\\\\n5 c_{0,0} & 5 c_{0,0} & 3 c_{0,0} & c_{0,0} &  &  &  &  &  &  \\\\\n14 c_{0,0} & 14 c_{0,0} & 9 c_{0,0} & 4 c_{0,0} & c_{0,0} &  &  &  &  &  \\\\\n42 c_{0,0} & 42 c_{0,0} & 28 c_{0,0} & 14 c_{0,0} & 5 c_{0,0} & c_{0,0} &  &  &  &  \\\\\n132 c_{0,0} & 132 c_{0,0} & 90 c_{0,0} & 48 c_{0,0} & 20 c_{0,0} & 6 c_{0,0} & c_{0,0} &  &  &  \\\\\n429 c_{0,0} & 429 c_{0,0} & 297 c_{0,0} & 165 c_{0,0} & 75 c_{0,0} & 27 c_{0,0} & 7 c_{0,0} & c_{0,0} &  &  \\\\\n1430 c_{0,0} & 1430 c_{0,0} & 1001 c_{0,0} & 572 c_{0,0} & 275 c_{0,0} & 110 c_{0,0} & 35 c_{0,0} & 8 c_{0,0} & c_{0,0} &  \\\\\n4862 c_{0,0} & 4862 c_{0,0} & 3432 c_{0,0} & 2002 c_{0,0} & 1001 c_{0,0} & 429 c_{0,0} & 154 c_{0,0} & 44 c_{0,0} & 9 c_{0,0} & c_{0,0} \\\\\n\\end{matrix}\\right]\n\\label{eq:unfolded:catalan}\n\\end{equation}\nto obtain a standard triangle of numbers, known as Catalan triangle, just plug $c_{0,0}=1$\nin the above matrix:\n\\begin{equation}\n\\left[\\begin{matrix}\n1 &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 &  &  &  &  &  &  &  &  \\\\\n2 & 2 & 1 &  &  &  &  &  &  &  \\\\\n5 & 5 & 3 & 1 &  &  &  &  &  &  \\\\\n14 & 14 & 9 & 4 & 1 &  &  &  &  &  \\\\\n42 & 42 & 28 & 14 & 5 & 1 &  &  &  &  \\\\\n132 & 132 & 90 & 48 & 20 & 6 & 1 &  &  &  \\\\\n429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 &  &  \\\\\n1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1 &  \\\\\n4862 & 4862 & 3432 & 2002 & 1001 & 429 & 154 & 44 & 9 & 1 \\\\\n\\end{matrix}\\right]\n\\label{eq:standard:catalan}\n\\end{equation}\nSuch triangle is the matrix expansion of the Riordan array $\\mathcal{C}$ defined as:\n\\begin{displaymath}\n    \\mathcal{C}=\\left(\\frac{1-\\sqrt{1-4\\,t}}{2\\,t},\n        \\frac{1-\\sqrt{1-4\\,t}}{2}\\right)\n\\end{displaymath}\n\n\\subsection{Two-way splitting}\n\nNow let us unfold starting from row $2$, leaving the first \\emph{two} rows purely generic, \nproducing matrix in \\autoref{eq:two:splitted:catalan}. We see that the lower part of the\nmatrix -- coefficients lying under row $2$, such row included -- dependends on $\\textcolor{blue}{c_{1,0}}$\nand $\\textcolor{red}{c_{1,1}}$: but it should be possible to rewrite $\\textcolor{red}{c_{1,1}}$\naccording \\autoref{eq:catalan:rec}, yielding matrix in \\autoref{eq:clean:two:splitted:catalan},\nwhich depends only on $\\textcolor{blue}{c_{0,0}}$ and $\\textcolor{blue}{c_{1,0}}$.\n\\begin{sidewaystable}\n%\\vskip-4cm\n\\scriptsize\n%\\rotatebox{90}{$\n\\begin{align}\n\\left[\\begin{matrix}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{1,0}} & \\textcolor{red}{c_{1,1}} &  &  &  &  &  &  &  &  \\\\\nc_{1,0} + c_{1,1} & c_{1,0} + c_{1,1} & c_{1,1} &  &  &  &  &  &  &  \\\\\n2 c_{1,0} + 3 c_{1,1} & 2 c_{1,0} + 3 c_{1,1} & c_{1,0} + 2 c_{1,1} & c_{1,1} &  &  &  &  &  &  \\\\\n5 c_{1,0} + 9 c_{1,1} & 5 c_{1,0} + 9 c_{1,1} & 3 c_{1,0} + 6 c_{1,1} & c_{1,0} + 3 c_{1,1} & c_{1,1} &  &  &  &  &  \\\\\n14 c_{1,0} + 28 c_{1,1} & 14 c_{1,0} + 28 c_{1,1} & 9 c_{1,0} + 19 c_{1,1} & 4 c_{1,0} + 10 c_{1,1} & c_{1,0} + 4 c_{1,1} & c_{1,1} &  &  &  &  \\\\\n42 c_{1,0} + 90 c_{1,1} & 42 c_{1,0} + 90 c_{1,1} & 28 c_{1,0} + 62 c_{1,1} & 14 c_{1,0} + 34 c_{1,1} & 5 c_{1,0} + 15 c_{1,1} & c_{1,0} + 5 c_{1,1} & c_{1,1} &  &  &  \\\\\n132 c_{1,0} + 297 c_{1,1} & 132 c_{1,0} + 297 c_{1,1} & 90 c_{1,0} + 207 c_{1,1} & 48 c_{1,0} + 117 c_{1,1} & 20 c_{1,0} + 55 c_{1,1} & 6 c_{1,0} + 21 c_{1,1} & c_{1,0} + 6 c_{1,1} & c_{1,1} &  &  \\\\\n429 c_{1,0} + 1001 c_{1,1} & 429 c_{1,0} + 1001 c_{1,1} & 297 c_{1,0} + 704 c_{1,1} & 165 c_{1,0} + 407 c_{1,1} & 75 c_{1,0} + 200 c_{1,1} & 27 c_{1,0} + 83 c_{1,1} & 7 c_{1,0} + 28 c_{1,1} & c_{1,0} + 7 c_{1,1} & c_{1,1} &  \\\\\n1430 c_{1,0} + 3432 c_{1,1} & 1430 c_{1,0} + 3432 c_{1,1} & 1001 c_{1,0} + 2431 c_{1,1} & 572 c_{1,0} + 1430 c_{1,1} & 275 c_{1,0} + 726 c_{1,1} & 110 c_{1,0} + 319 c_{1,1} & 35 c_{1,0} + 119 c_{1,1} & 8 c_{1,0} + 36 c_{1,1} & c_{1,0} + 8 c_{1,1} & c_{1,1} \\\\\n\\end{matrix}\\right]\n\\label{eq:two:splitted:catalan} \\\\\n\\left[\\begin{matrix}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{1,0}} & c_{0,0} &  &  &  &  &  &  &  &  \\\\\nc_{0,0} + c_{1,0} & c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  &  &  \\\\\n3 c_{0,0} + 2 c_{1,0} & 3 c_{0,0} + 2 c_{1,0} & 2 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  &  \\\\\n9 c_{0,0} + 5 c_{1,0} & 9 c_{0,0} + 5 c_{1,0} & 6 c_{0,0} + 3 c_{1,0} & 3 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  \\\\\n28 c_{0,0} + 14 c_{1,0} & 28 c_{0,0} + 14 c_{1,0} & 19 c_{0,0} + 9 c_{1,0} & 10 c_{0,0} + 4 c_{1,0} & 4 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  \\\\\n90 c_{0,0} + 42 c_{1,0} & 90 c_{0,0} + 42 c_{1,0} & 62 c_{0,0} + 28 c_{1,0} & 34 c_{0,0} + 14 c_{1,0} & 15 c_{0,0} + 5 c_{1,0} & 5 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  \\\\\n297 c_{0,0} + 132 c_{1,0} & 297 c_{0,0} + 132 c_{1,0} & 207 c_{0,0} + 90 c_{1,0} & 117 c_{0,0} + 48 c_{1,0} & 55 c_{0,0} + 20 c_{1,0} & 21 c_{0,0} + 6 c_{1,0} & 6 c_{0,0} + c_{1,0} & c_{0,0} &  &  \\\\\n1001 c_{0,0} + 429 c_{1,0} & 1001 c_{0,0} + 429 c_{1,0} & 704 c_{0,0} + 297 c_{1,0} & 407 c_{0,0} + 165 c_{1,0} & 200 c_{0,0} + 75 c_{1,0} & 83 c_{0,0} + 27 c_{1,0} & 28 c_{0,0} + 7 c_{1,0} & 7 c_{0,0} + c_{1,0} & c_{0,0} &  \\\\\n3432 c_{0,0} + 1430 c_{1,0} & 3432 c_{0,0} + 1430 c_{1,0} & 2431 c_{0,0} + 1001 c_{1,0} & 1430 c_{0,0} + 572 c_{1,0} & 726 c_{0,0} + 275 c_{1,0} & 319 c_{0,0} + 110 c_{1,0} & 119 c_{0,0} + 35 c_{1,0} & 36 c_{0,0} + 8 c_{1,0} & 8 c_{0,0} + c_{1,0} & c_{0,0} \\\\\n\\end{matrix}\\right]\n\\label{eq:clean:two:splitted:catalan}\n%$}\n\\end{align}\n\\begin{equation}\n\\left[\\begin{matrix}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{1,0}} & \\textcolor{red}{c_{1,1}} &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{2,0}} & \\textcolor{red}{c_{2,1}} & \\textcolor{red}{c_{2,2}} &  &  &  &  &  &  &  \\\\\nc_{2,0} + c_{2,1} + c_{2,2} & c_{2,0} + c_{2,1} + c_{2,2} & c_{2,1} + c_{2,2} & c_{2,2} &  &  &  &  &  &  \\\\\n2 c_{2,0} + 3 c_{2,1} + 4 c_{2,2} & 2 c_{2,0} + 3 c_{2,1} + 4 c_{2,2} & c_{2,0} + 2 c_{2,1} + 3 c_{2,2} & c_{2,1} + 2 c_{2,2} & c_{2,2} &  &  &  &  &  \\\\\n5 c_{2,0} + 9 c_{2,1} + 14 c_{2,2} & 5 c_{2,0} + 9 c_{2,1} + 14 c_{2,2} & 3 c_{2,0} + 6 c_{2,1} + 10 c_{2,2} & c_{2,0} + 3 c_{2,1} + 6 c_{2,2} & c_{2,1} + 3 c_{2,2} & c_{2,2} &  &  &  &  \\\\\n14 c_{2,0} + 28 c_{2,1} + 48 c_{2,2} & 14 c_{2,0} + 28 c_{2,1} + 48 c_{2,2} & 9 c_{2,0} + 19 c_{2,1} + 34 c_{2,2} & 4 c_{2,0} + 10 c_{2,1} + 20 c_{2,2} & c_{2,0} + 4 c_{2,1} + 10 c_{2,2} & c_{2,1} + 4 c_{2,2} & c_{2,2} &  &  &  \\\\\n42 c_{2,0} + 90 c_{2,1} + 165 c_{2,2} & 42 c_{2,0} + 90 c_{2,1} + 165 c_{2,2} & 28 c_{2,0} + 62 c_{2,1} + 117 c_{2,2} & 14 c_{2,0} + 34 c_{2,1} + 69 c_{2,2} & 5 c_{2,0} + 15 c_{2,1} + 35 c_{2,2} & c_{2,0} + 5 c_{2,1} + 15 c_{2,2} & c_{2,1} + 5 c_{2,2} & c_{2,2} &  &  \\\\\n132 c_{2,0} + 297 c_{2,1} + 572 c_{2,2} & 132 c_{2,0} + 297 c_{2,1} + 572 c_{2,2} & 90 c_{2,0} + 207 c_{2,1} + 407 c_{2,2} & 48 c_{2,0} + 117 c_{2,1} + 242 c_{2,2} & 20 c_{2,0} + 55 c_{2,1} + 125 c_{2,2} & 6 c_{2,0} + 21 c_{2,1} + 56 c_{2,2} & c_{2,0} + 6 c_{2,1} + 21 c_{2,2} & c_{2,1} + 6 c_{2,2} & c_{2,2} &  \\\\\n429 c_{2,0} + 1001 c_{2,1} + 2002 c_{2,2} & 429 c_{2,0} + 1001 c_{2,1} + 2002 c_{2,2} & 297 c_{2,0} + 704 c_{2,1} + 1430 c_{2,2} & 165 c_{2,0} + 407 c_{2,1} + 858 c_{2,2} & 75 c_{2,0} + 200 c_{2,1} + 451 c_{2,2} & 27 c_{2,0} + 83 c_{2,1} + 209 c_{2,2} & 7 c_{2,0} + 28 c_{2,1} + 84 c_{2,2} & c_{2,0} + 7 c_{2,1} + 28 c_{2,2} & c_{2,1} + 7 c_{2,2} & c_{2,2} \\\\\n\\end{matrix}\\right]\n\\label{eq:three:splitted:catalan}\n\\end{equation}\n\\begin{equation}\n\\left[\\begin{matrix}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{1,0}} & c_{0,0} &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{2,0}} & c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  &  &  \\\\\n2 c_{0,0} + c_{1,0} + c_{2,0} & 2 c_{0,0} + c_{1,0} + c_{2,0} & 2 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  &  \\\\\n7 c_{0,0} + 3 c_{1,0} + 2 c_{2,0} & 7 c_{0,0} + 3 c_{1,0} + 2 c_{2,0} & 5 c_{0,0} + 2 c_{1,0} + c_{2,0} & 3 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  \\\\\n23 c_{0,0} + 9 c_{1,0} + 5 c_{2,0} & 23 c_{0,0} + 9 c_{1,0} + 5 c_{2,0} & 16 c_{0,0} + 6 c_{1,0} + 3 c_{2,0} & 9 c_{0,0} + 3 c_{1,0} + c_{2,0} & 4 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  \\\\\n76 c_{0,0} + 28 c_{1,0} + 14 c_{2,0} & 76 c_{0,0} + 28 c_{1,0} + 14 c_{2,0} & 53 c_{0,0} + 19 c_{1,0} + 9 c_{2,0} & 30 c_{0,0} + 10 c_{1,0} + 4 c_{2,0} & 14 c_{0,0} + 4 c_{1,0} + c_{2,0} & 5 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  \\\\\n255 c_{0,0} + 90 c_{1,0} + 42 c_{2,0} & 255 c_{0,0} + 90 c_{1,0} + 42 c_{2,0} & 179 c_{0,0} + 62 c_{1,0} + 28 c_{2,0} & 103 c_{0,0} + 34 c_{1,0} + 14 c_{2,0} & 50 c_{0,0} + 15 c_{1,0} + 5 c_{2,0} & 20 c_{0,0} + 5 c_{1,0} + c_{2,0} & 6 c_{0,0} + c_{1,0} & c_{0,0} &  &  \\\\\n869 c_{0,0} + 297 c_{1,0} + 132 c_{2,0} & 869 c_{0,0} + 297 c_{1,0} + 132 c_{2,0} & 614 c_{0,0} + 207 c_{1,0} + 90 c_{2,0} & 359 c_{0,0} + 117 c_{1,0} + 48 c_{2,0} & 180 c_{0,0} + 55 c_{1,0} + 20 c_{2,0} & 77 c_{0,0} + 21 c_{1,0} + 6 c_{2,0} & 27 c_{0,0} + 6 c_{1,0} + c_{2,0} & 7 c_{0,0} + c_{1,0} & c_{0,0} &  \\\\\n3003 c_{0,0} + 1001 c_{1,0} + 429 c_{2,0} & 3003 c_{0,0} + 1001 c_{1,0} + 429 c_{2,0} & 2134 c_{0,0} + 704 c_{1,0} + 297 c_{2,0} & 1265 c_{0,0} + 407 c_{1,0} + 165 c_{2,0} & 651 c_{0,0} + 200 c_{1,0} + 75 c_{2,0} & 292 c_{0,0} + 83 c_{1,0} + 27 c_{2,0} & 112 c_{0,0} + 28 c_{1,0} + 7 c_{2,0} & 35 c_{0,0} + 7 c_{1,0} + c_{2,0} & 8 c_{0,0} + c_{1,0} & c_{0,0} \\\\\n\\end{matrix}\\right]\n\\label{eq:clean:three:splitted:catalan}\n\\end{equation}\n\\end{sidewaystable}\nTwo-way unfolding suggests that we can characterize coefficients lying on a column $k$ as a \ncombination of \\emph{two} generating functions $a_{k}(t)$ and $b_{k}(t)$, multiplied by $c_{0,0}$\nand $c_{1,0}$ respectively. Because coefficients lying on a column $k$ of a Riordan array\ncan also be characterized by the convolution $d(t)h(t)^{k}$, we can state the following relation:\n\\begin{equation} \n    d(t)h(t)^{k} = c_{0,0}a_{k}(t) + c_{1,0}b_{k}(t)\n    \\label{eq:two:splitted:catalan:generic:column:relation}\n\\end{equation} \nwhich can be used toward to assert a relation about two adjacent columns $k$ and $k+1$. \nTo see this, starts by taking the ratio of those columns:\n\\begin{displaymath} \n    \\frac{d(t)h(t)^{k+1}}{d(t)h(t)^{k}} = \\frac{c_{0,0}a_{k+1}(t) + c_{1,0}b_{k+1}(t)}\n        {c_{0,0}a_{k}(t) + c_{1,0}b_{k}(t)}\n\\end{displaymath} \nwhich can be simplified to:\n\\begin{displaymath} \n    h(t)\\left(c_{0,0}a_{k}(t) + c_{1,0}b_{k}(t)\\right) = \n        c_{0,0}a_{k+1}(t) + c_{1,0}b_{k+1}(t)\n\\end{displaymath} \nwhich holds if and only if:\n\\begin{displaymath} \n    h(t) a_{k}(t) = a_{k+1}(t) \\quad \\wedge \\quad h(t) b_{k}(t) = b_{k+1}(t)\n\\end{displaymath} \nunfolding such relations we get, for a generic column $j$ and an integer $s\\in\\lbrace 0,\\ldots,j\\rbrace$:\n\\begin{displaymath} \n    a_{j}(t) = h(t)^{j-s} a_{s}(t) \\quad \\quad \n    b_{j}(t) = h(t)^{j-s} b_{s}(t)\n\\end{displaymath} \nfixing $s=0$ we go down to the very first column:\n\\begin{displaymath} \n    a_{j}(t) = h(t)^{j} a_{0}(t) \\quad \\quad \n    b_{j}(t) = h(t)^{j} b_{0}(t)\n\\end{displaymath} \ntherefore there exists two Riordan arrays $\\mathcal{C}_{a}$ and $\\mathcal{C}_{b}$\ndefined as follows:\n\\begin{displaymath} \n    \\mathcal{C}_{a} = \\left(a_{0}(t), h(t)\\right) \\quad \\quad \n    \\mathcal{C}_{b} = \\left(b_{0}(t), h(t)\\right) \\quad \\quad \n\\end{displaymath} \nsuch that:\n\\begin{equation} \n    \\mathcal{C} = c_{0,0}\\mathcal{C}_{a} + c_{1,0}\\mathcal{C}_{b}\n    \\label{eq:two:splitted:catalan:riordan:expansion}\n\\end{equation} \nFrom now on, we attach a super-script $^{(i)}$, for $i\\in\\lbrace 2,3\\ldots\\rbrace$, \nto functions used in a sum expansion in order to be clear that such functions \nrefers to a matrix unfolding where $i$ variables, namely $c_{0,0},\\ldots,c_{i-1,0}$, \nare present. In the case above, $a_{0}^{(2)}(t)$ and $b_{0}^{(2)}(t)$ \ndenote the same functions as $a_{0}(t)$ and $b_{0}(t)$.\n\n\nStudying \\autoref{eq:two:splitted:catalan:generic:column:relation}\nwith $k=0$ we get:\n\\begin{equation} \n    d(t) = c_{0,0}a_{0}^{(2)}(t) + c_{1,0}b_{0}^{(2)}(t)\n\\end{equation} \na look at \\autoref{eq:standard:catalan} allows us to set both $c_{0,0}$ and $c_{1,0}$ to $1$,\nand looking at \\autoref{eq:clean:two:splitted:catalan} it seems to be permitted to set \nfunction $b_{0}^{(2)}(t)$ to $t\\,d(t)$; therefore, \n\\begin{equation} \n    d(t) = a_{0}^{(2)}(t) + t\\,d(t) \\rightarrow d(t)(1-t) = a_{0}^{(2)}(t)\n\\end{equation} \nholds. So \\autoref{eq:two:splitted:catalan:riordan:expansion} can be rewritten as follows:\n\\begin{displaymath} \n    \\mathcal{C}(d(t), h(t)) = \\mathcal{C}_{a}(d(t)(1-t), h(t)) + \\mathcal{C}_{b}(t\\,d(t), h(t))\n\\end{displaymath} \nin expanded matrix notation:\n\\begin{equation}\n\\hspace{-3cm}\n\\mathcal{C} = \n\\left[\\begin{matrix}\n1 &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 1 &  &  &  &  &  &  &  \\\\\n3 & 3 & 2 & 1 &  &  &  &  &  &  \\\\\n9 & 9 & 6 & 3 & 1 &  &  &  &  &  \\\\\n28 & 28 & 19 & 10 & 4 & 1 &  &  &  &  \\\\\n90 & 90 & 62 & 34 & 15 & 5 & 1 &  &  &  \\\\\n297 & 297 & 207 & 117 & 55 & 21 & 6 & 1 &  &  \\\\\n1001 & 1001 & 704 & 407 & 200 & 83 & 28 & 7 & 1 &  \\\\\n3432 & 3432 & 2431 & 1430 & 726 & 319 & 119 & 36 & 8 & 1 \\\\\n\\end{matrix}\\right] +\n\\left[\\begin{matrix}\n0 &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 0 &  &  &  &  &  &  &  \\\\\n2 & 2 & 1 & 0 &  &  &  &  &  &  \\\\\n5 & 5 & 3 & 1 & 0 &  &  &  &  &  \\\\\n14 & 14 & 9 & 4 & 1 & 0 &  &  &  &  \\\\\n42 & 42 & 28 & 14 & 5 & 1 & 0 &  &  &  \\\\\n132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 &  &  \\\\\n429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0 &  \\\\\n1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1 & 0 \\\\\n\\end{matrix}\\right]\\\\ \n\\label{eq:matrix:expansion:two:splitted:catalan}\n\\end{equation}\n\n\n\\subsection{Three-way splitting}\n\nNow we're going to unfold matrix in \\autoref{eq:purely:generic:catalan} starting from row $3$,\naiming to rewrite that matrix such that it depends only on $c_{0,0}, c_{1,0}, c_{2,0}$.\nWe can characterize the convolution for the generic column $k$ using three\nfunctions $a_{k}^{(3)}(t), b_{k}^{(3)}(t), c_{k}^{(3)}(t)$ as follows:\n\\begin{equation} \n    d(t)h(t)^{k} = c_{0,0}a_{k}^{(3)}(t) + c_{1,0}b_{k}^{(3)}(t) + c_{2,0}c_{k}^{(3)}(t)\n    \\label{eq:three:splitted:catalan:generic:column:relation}\n\\end{equation} \nIn the style of the argument shown in the previous section, we seek for:\n\\begin{equation} \n    \\mathcal{C} = c_{0,0}\\mathcal{C}_{a} + c_{1,0}\\mathcal{C}_{b} + c_{2,0}\\mathcal{C}_{c}\n    \\label{eq:three:splitted:catalan:riordan:expansion}\n\\end{equation} \nwhere:\n\\begin{displaymath} \n    \\mathcal{C}_{a} = \\left(a_{0}^{(3)}(t), h(t)\\right) \\quad \\quad \n    \\mathcal{C}_{b} = \\left(b_{0}^{(3)}(t), h(t)\\right) \\quad \\quad \n    \\mathcal{C}_{c} = \\left(c_{0}^{(3)}(t), h(t)\\right) \\quad \\quad \n\\end{displaymath} \nLooking at \\autoref{eq:clean:three:splitted:catalan} it seems that the following relations hold:\n\\begin{displaymath} \n    b_{0}^{(3)}(t) = t\\,a_{0}^{(2)}(t) = t(1-t)d(t)\\quad \\quad \n    c_{0}^{(3)}(t) = t\\,b_{0}^{(2)}(t) = t^{2}d(t) \n\\end{displaymath} \nand \\autoref{eq:standard:catalan} allows us to set $c_{2,0}$ to $2$. Sustituting in\n\\autoref{eq:three:splitted:catalan:generic:column:relation}, with $k=0$, yields\nfunction $a_{0}^{(3)}(t)$:\n\\begin{displaymath} \n    d(t)\\left(1 -t(1-t) -2t^{2}\\right) = a_{0}^{(3)}(t)\n\\end{displaymath} \nso:\n\\begin{displaymath} \n    d(t)\\left(1 -t -t^{2}\\right) = a_{0}^{(3)}(t)\n\\end{displaymath} \ntherefore $\\mathcal{C}$ factorization, using $3$ variables, can be written as:\n\\begin{displaymath} \n    \\mathcal{C} = \n        \\left(\\left(1 -t -t^{2}\\right)d(t), h(t)\\right) +\n        \\left(\\left(t-t^{2}\\right)d(t), h(t)\\right) +\n        2\\,\\left(t^{2}d(t), h(t)\\right) \n\\end{displaymath} \nin matrix notation:\n\\begin{displaymath}\n\\hspace{-3cm}\n\\scriptsize\n\\mathcal{C} = \n\\left[\\begin{matrix}\n1 &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 1 &  &  &  &  &  &  &  \\\\\n2 & 2 & 2 & 1 &  &  &  &  &  &  \\\\\n7 & 7 & 5 & 3 & 1 &  &  &  &  &  \\\\\n23 & 23 & 16 & 9 & 4 & 1 &  &  &  &  \\\\\n76 & 76 & 53 & 30 & 14 & 5 & 1 &  &  &  \\\\\n255 & 255 & 179 & 103 & 50 & 20 & 6 & 1 &  &  \\\\\n869 & 869 & 614 & 359 & 180 & 77 & 27 & 7 & 1 &  \\\\\n3003 & 3003 & 2134 & 1265 & 651 & 292 & 112 & 35 & 8 & 1 \\\\\n\\end{matrix}\\right] + \n\\left[\\begin{matrix}\n0 &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 0 &  &  &  &  &  &  &  \\\\\n1 & 1 & 1 & 0 &  &  &  &  &  &  \\\\\n3 & 3 & 2 & 1 & 0 &  &  &  &  &  \\\\\n9 & 9 & 6 & 3 & 1 & 0 &  &  &  &  \\\\\n28 & 28 & 19 & 10 & 4 & 1 & 0 &  &  &  \\\\\n90 & 90 & 62 & 34 & 15 & 5 & 1 & 0 &  &  \\\\\n297 & 297 & 207 & 117 & 55 & 21 & 6 & 1 & 0 &  \\\\\n1001 & 1001 & 704 & 407 & 200 & 83 & 28 & 7 & 1 & 0 \\\\\n\\end{matrix}\\right] \n\\end{displaymath}\n\\begin{displaymath}\n\\scriptsize\n+ 2\\,\\left[\\begin{matrix}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n1 & 0 & 0 &  &  &  &  &  &  &  \\\\\n1 & 1 & 0 & 0 &  &  &  &  &  &  \\\\\n2 & 2 & 1 & 0 & 0 &  &  &  &  &  \\\\\n5 & 5 & 3 & 1 & 0 & 0 &  &  &  &  \\\\\n14 & 14 & 9 & 4 & 1 & 0 & 0 &  &  &  \\\\\n42 & 42 & 28 & 14 & 5 & 1 & 0 & 0 &  &  \\\\\n132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 & 0 &  \\\\\n429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0 & 0 \\\\ \n\\end{matrix}\\right]\n\\end{displaymath}\n\n\\subsection{The Fibonacci triangle, which isn't a renewal array}\n\nIn this section we study the Fibonacci triangle, denoted by the following\nRiordan array:\n\\begin{displaymath}\n    \\mathcal{F}=\\left(\\frac{1}{1-t-t^{2}}, \\frac{1-\\sqrt{1-4\\,t}}{2}\\right)\n\\end{displaymath}\nand with the following matrix expansion:\n\\begin{equation}\nf_{0,0}\\left[\\begin{array}{cccccccccc}\n1 &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 &  &  &  &  &  &  &  &  \\\\\n2 & 2 & 1 &  &  &  &  &  &  &  \\\\\n3 & 5 & 3 & 1 &  &  &  &  &  &  \\\\\n5 & 12 & 9 & 4 & 1 &  &  &  &  &  \\\\\n8 & 31 & 26 & 14 & 5 & 1 &  &  &  &  \\\\\n13 & 85 & 77 & 46 & 20 & 6 & 1 &  &  &  \\\\\n21 & 248 & 235 & 150 & 73 & 27 & 7 & 1 &  &  \\\\\n34 & 762 & 741 & 493 & 258 & 108 & 35 & 8 & 1 &  \\\\\n55 & 2440 & 2406 & 1644 & 903 & 410 & 152 & 44 & 9 & 1 \\\\\n\\end{array}\\right]\n\\end{equation}\nproduced by a purely symbolic matrix as the one in \\autoref{eq:purely:generic:catalan},\nchanging the generic symbol from $c$ to $f$, according $A$-sequence:\n\\begin{displaymath}\n    A(t)=\\frac{1}{1-t}\n\\end{displaymath}\nand $Z$-sequence:\n\\begin{displaymath}\n    Z(t)=1+t-t^{2}\n\\end{displaymath}\n\nIn \\autoref{eq:fibonacci:four:splitted} we report a splitting using $4$ free variables \nand in \\autoref{eq:fibonacci:four:splitted:matrix:expansion} the corresponding matrix expansion.\n\\begin{sidewaystable}\n\\scriptsize\n\\begin{equation}\n\\left[\\begin{array}{cccccccccc}\n\\textcolor{blue}{f_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{f_{1,0}} & f_{0,0} &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{f_{2,0}} & f_{0,0} + f_{1,0} & f_{0,0} &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{f_{3,0}} & 2 f_{0,0} + f_{1,0} + f_{2,0} & 2 f_{0,0} + f_{1,0} & f_{0,0} &  &  &  &  &  &  \\\\\nf_{2,0} + f_{3,0} & 5 f_{0,0} + 2 f_{1,0} + f_{2,0} + f_{3,0} & 5 f_{0,0} + 2 f_{1,0} + f_{2,0} & 3 f_{0,0} + f_{1,0} & f_{0,0} &  &  &  &  &  \\\\\nf_{2,0} + 2 f_{3,0} & 14 f_{0,0} + 5 f_{1,0} + 3 f_{2,0} + 2 f_{3,0} & 14 f_{0,0} + 5 f_{1,0} + 2 f_{2,0} + f_{3,0} & 9 f_{0,0} + 3 f_{1,0} + f_{2,0} & 4 f_{0,0} + f_{1,0} & f_{0,0} &  &  &  &  \\\\\n2 f_{2,0} + 3 f_{3,0} & 42 f_{0,0} + 14 f_{1,0} + 7 f_{2,0} + 5 f_{3,0} & 42 f_{0,0} + 14 f_{1,0} + 6 f_{2,0} + 3 f_{3,0} & 28 f_{0,0} + 9 f_{1,0} + 3 f_{2,0} + f_{3,0} & 14 f_{0,0} + 4 f_{1,0} + f_{2,0} & 5 f_{0,0} + f_{1,0} & f_{0,0} &  &  &  \\\\\n3 f_{2,0} + 5 f_{3,0} & 132 f_{0,0} + 42 f_{1,0} + 19 f_{2,0} + 12 f_{3,0} & 132 f_{0,0} + 42 f_{1,0} + 17 f_{2,0} + 9 f_{3,0} & 90 f_{0,0} + 28 f_{1,0} + 10 f_{2,0} + 4 f_{3,0} & 48 f_{0,0} + 14 f_{1,0} + 4 f_{2,0} + f_{3,0} & 20 f_{0,0} + 5 f_{1,0} + f_{2,0} & 6 f_{0,0} + f_{1,0} & f_{0,0} &  &  \\\\\n5 f_{2,0} + 8 f_{3,0} & 429 f_{0,0} + 132 f_{1,0} + 54 f_{2,0} + 31 f_{3,0} & 429 f_{0,0} + 132 f_{1,0} + 51 f_{2,0} + 26 f_{3,0} & 297 f_{0,0} + 90 f_{1,0} + 32 f_{2,0} + 14 f_{3,0} & 165 f_{0,0} + 48 f_{1,0} + 15 f_{2,0} + 5 f_{3,0} & 75 f_{0,0} + 20 f_{1,0} + 5 f_{2,0} + f_{3,0} & 27 f_{0,0} + 6 f_{1,0} + f_{2,0} & 7 f_{0,0} + f_{1,0} & f_{0,0} &  \\\\\n8 f_{2,0} + 13 f_{3,0} & 1430 f_{0,0} + 429 f_{1,0} + 163 f_{2,0} + 85 f_{3,0} & 1430 f_{0,0} + 429 f_{1,0} + 158 f_{2,0} + 77 f_{3,0} & 1001 f_{0,0} + 297 f_{1,0} + 104 f_{2,0} + 46 f_{3,0} & 572 f_{0,0} + 165 f_{1,0} + 53 f_{2,0} + 20 f_{3,0} & 275 f_{0,0} + 75 f_{1,0} + 21 f_{2,0} + 6 f_{3,0} & 110 f_{0,0} + 27 f_{1,0} + 6 f_{2,0} + f_{3,0} & 35 f_{0,0} + 7 f_{1,0} + f_{2,0} & 8 f_{0,0} + f_{1,0} & f_{0,0} \\\\\n\\end{array}\\right]\n\\label{eq:fibonacci:four:splitted}\n\\end{equation}\n\\begin{equation}\n\\begin{split}\n& f_{0,0}\\left[\\begin{array}{cccccccccc}\n1 &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 1 &  &  &  &  &  &  &  \\\\\n0 & 2 & 2 & 1 &  &  &  &  &  &  \\\\\n0 & 5 & 5 & 3 & 1 &  &  &  &  &  \\\\\n0 & 14 & 14 & 9 & 4 & 1 &  &  &  &  \\\\\n0 & 42 & 42 & 28 & 14 & 5 & 1 &  &  &  \\\\\n0 & 132 & 132 & 90 & 48 & 20 & 6 & 1 &  &  \\\\\n0 & 429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 &  \\\\\n0 & 1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1 \\\\\n\\end{array}\\right] + f_{1,0}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 0 &  &  &  &  &  &  &  \\\\\n0 & 1 & 1 & 0 &  &  &  &  &  &  \\\\\n0 & 2 & 2 & 1 & 0 &  &  &  &  &  \\\\\n0 & 5 & 5 & 3 & 1 & 0 &  &  &  &  \\\\\n0 & 14 & 14 & 9 & 4 & 1 & 0 &  &  &  \\\\\n0 & 42 & 42 & 28 & 14 & 5 & 1 & 0 &  &  \\\\\n0 & 132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 &  \\\\\n0 & 429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0 \\\\\n\\end{array}\\right] \\\\\n& + f_{2,0}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n1 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 1 & 0 & 0 &  &  &  &  &  &  \\\\\n1 & 1 & 1 & 0 & 0 &  &  &  &  &  \\\\\n1 & 3 & 2 & 1 & 0 & 0 &  &  &  &  \\\\\n2 & 7 & 6 & 3 & 1 & 0 & 0 &  &  &  \\\\\n3 & 19 & 17 & 10 & 4 & 1 & 0 & 0 &  &  \\\\\n5 & 54 & 51 & 32 & 15 & 5 & 1 & 0 & 0 &  \\\\\n8 & 163 & 158 & 104 & 53 & 21 & 6 & 1 & 0 & 0 \\\\\n\\end{array}\\right] + f_{3,0}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n1 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n1 & 1 & 0 & 0 & 0 &  &  &  &  &  \\\\\n2 & 2 & 1 & 0 & 0 & 0 &  &  &  &  \\\\\n3 & 5 & 3 & 1 & 0 & 0 & 0 &  &  &  \\\\\n5 & 12 & 9 & 4 & 1 & 0 & 0 & 0 &  &  \\\\\n8 & 31 & 26 & 14 & 5 & 1 & 0 & 0 & 0 &  \\\\\n13 & 85 & 77 & 46 & 20 & 6 & 1 & 0 & 0 & 0 \\\\\n\\end{array}\\right]\n\\end{split}\n\\label{eq:fibonacci:four:splitted:matrix:expansion}\n\\end{equation}\n\\end{sidewaystable}\n\n\n\\subsection{A possible generalization}\n\nArguments in previous sections, were unfolding leaving $2$ and $3$ variables are\ndescribed, allow us to conjecture a general factorization for a Riordan array $\\mathcal{C}$.\nLet $\\left\\lbrace \\alpha_{k,i}^{(s)}(t)\\right\\rbrace_{k,i\\in\\mathbb{N}}$ be a family of generating functions\nin the indeterminate $t$, related to matrix unfolding depending on $s$ free variables.\nThen we can state the following relation about the convolution characterizing a \ngeneric column $k$ of $\\mathcal{C}$ as follows:\n\\begin{equation}\n    d(t)h(t)^{k} = c_{0,0}\\alpha_{k,0}^{(s)}(t) + c_{1,0}\\alpha_{k,1}^{(s)}(t) + \\ldots\n        c_{s-1,0}\\alpha_{k,s-1}^{(s)}(t)\n\\end{equation}\nsetting $k=0$ we can get rid of function $h$, looking for a factorization of function $d$:\n\\begin{equation}\n    d(t) = c_{0,0}\\alpha_{0,0}^{(s)}(t) + c_{1,0}\\alpha_{0,1}^{(s)}(t) + \\ldots +\n        c_{s-1,0}\\alpha_{0,s-1}^{(s)}(t)\n\\end{equation}\nwhere $\\alpha_{0, j}^{(s)}(t) = t\\,\\alpha_{0, j-1}^{(s-1)}(t)$, for $j\\in\\lbrace 1,\\ldots,s-1\\rbrace$;\nthe base case for the recursion is $\\alpha_{0, 1}^{(2)}(t) = t\\,d(t)$.\n\nIn \\autoref{eq:table:a:zero:zero:pascal}, \\autoref{eq:table:a:zero:zero:shapiro}, \n\\autoref{eq:table:a:zero:zero:catalan} and \\autoref{eq:table:a:zero:zero:fibonacci}, \nwe report three tables with schemata to compute\n$\\alpha_{0,0}^{(s)}(t)$, for $s\\in\\lbrace 2, 3, 4, 5\\rbrace$, relative to \nPascal triangle $\\mathcal{P}$, Shapiro triangle $\\mathcal{S}$,\nCatalan triangle $\\mathcal{C}$ and, finally, Fibonacci triangle $\\mathcal{F}$, respectively. \nRecall the \\emph{fundamental}\nbase case for the recursion $\\alpha_{0,1}^{(2)}(t) = t\\,d(t)$, then the following \ndefinitions for $d(t)$ functions and initial coefficients are used for each array: \n\\begin{itemize}\n\\item $\\mathcal{P}$:\n\\begin{displaymath}\n     d(t) = \\frac{1}{1-t} \\quad \\quad p_{i,0}=1, i\\in\\lbrace 0,\\ldots,4\\rbrace\n\\end{displaymath}\n\n\\item $\\mathcal{S}$:\n\\begin{displaymath}\n        d(t) = \\frac{1-2t-\\sqrt{1-4t}}{2t^{2}} \\quad \\quad \n            s_{0,0}=1\\quad s_{1,0}=2\\quad s_{2,0}=5\\quad s_{3,0}=14\\quad s_{4,0}=42\n\\end{displaymath}\n\n\\item $\\mathcal{C}$:\n\\begin{displaymath}\n        d(t) = \\frac{1-\\sqrt{1-4t}}{2t} \\quad \\quad \n            c_{0,0}=1\\quad c_{1,0}=1\\quad c_{2,0}=2\\quad c_{3,0}=5\\quad c_{4,0}=14\n\\end{displaymath}\n\n\\item $\\mathcal{F}$:\n\\begin{displaymath}\n        d(t) = \\frac{1}{1-t-t^{2}} \\quad \\quad \n            f_{0,0}=1\\quad f_{1,0}=1\\quad f_{2,0}=2\\quad f_{3,0}=3\\quad f_{4,0}=5\n\\end{displaymath}\n\n\\end{itemize}\n\n\\begin{sidewaystable}\n\\scriptsize\n\n% Pascal triangle\n\\begin{equation}\n    %\\hspace{-3cm}\n    \\begin{array}{ccc}\n        s & d(t) & \\alpha_{0,0}^{(s)}(t) \\\\\n        \\hline\n        2 & p_{0,0}\\alpha_{0,0}^{(2)}(t) + p_{1,0}\\alpha_{0,1}^{(2)}(t) = \\alpha_{0,0}^{(2)}(t) + t\\,d(t) & 1 \\\\\n        3 & p_{0,0}\\alpha_{0,0}^{(3)}(t) + t\\left(p_{1,0}\\alpha_{0,0}^{(2)}(t) + p_{2,0}\\alpha_{0,1}^{(2)}(t)\\right) =\n            \\alpha_{0,0}^{(3)}(t) + t + t^{2}\\,d(t) & 1 \\\\\n        4 & p_{0,0}\\alpha_{0,0}^{(4)}(t) + t\\left(p_{1,0}\\alpha_{0,0}^{(3)}(t) + p_{2,0}\\alpha_{0,1}^{(3)}(t) + p_{3,0}\\alpha_{0,2}^{(3)}(t)\\right)  =\n            \\alpha_{0,0}^{(4)}(t) + t + t^{2} + t^{3}\\,d(t) & 1 \\\\\n        5 & p_{0,0}\\alpha_{0,0}^{(5)}(t) + t\\left(p_{1,0}\\alpha_{0,0}^{(4)}(t) + p_{2,0}\\alpha_{0,1}^{(4)}(t) + p_{3,0}\\alpha_{0,2}^{(4)}(t) + p_{4,0}\\alpha_{0,3}^{(4)}(t)\\right)  =\n            \\alpha_{0,0}^{(5)}(t) + t + t^{2} + t^{3} + t^{4}\\,d(t) & 1 \\\\\n    \\end{array}\n    \\label{eq:table:a:zero:zero:pascal}\n\\end{equation}\n\n% Shapiro triangle\n\\begin{equation}\n    %\\hspace{-5cm}\n    \\begin{array}{ccc}\n        s & d(t) & \\alpha_{0,0}^{(s)}(t) \\\\\n        \\hline\n        2 & s_{0,0}\\alpha_{0,0}^{(2)}(t) + s_{1,0}\\alpha_{0,1}^{(2)}(t) = \\alpha_{0,0}^{(2)}(t) + 2t\\,d(t) & d(t)(1-2t) \\\\\n        3 & s_{0,0}\\alpha_{0,0}^{(3)}(t) + t\\left(s_{1,0}\\alpha_{0,0}^{(2)}(t) + s_{2,0}\\alpha_{0,1}^{(2)}(t)\\right) =\n            \\alpha_{0,0}^{(3)}(t) + 2t(1-2t)d(t) + 5t^{2}\\,d(t) & d(t)\\left(1-2t-t^{2}\\right) \\\\\n        4 & s_{0,0}\\alpha_{0,0}^{(4)}(t) + t\\left(s_{1,0}\\alpha_{0,0}^{(3)}(t) + s_{2,0}\\alpha_{0,1}^{(3)}(t) + s_{3,0}\\alpha_{0,2}^{(3)}(t)\\right)  =\n            \\alpha_{0,0}^{(4)}(t) + 2t\\,d(t)\\left(1-2t-t^{2}\\right) + 5t^{2}\\,d(t)(1-2t) + 14t^{3}\\,d(t) & d(t)\\left(1-2t-t^{2}-2t^{3}\\right) \\\\\n        5 & s_{0,0}\\alpha_{0,0}^{(5)}(t) + t\\left(s_{1,0}\\alpha_{0,0}^{(4)}(t) + s_{2,0}\\alpha_{0,1}^{(4)}(t) + s_{3,0}\\alpha_{0,2}^{(4)}(t) + s_{4,0}\\alpha_{0,3}^{(4)}(t)\\right)  =\n            \\alpha_{0,0}^{(5)}(t) + 2t\\,d(t)\\left(1-2t-t^{2}-2t^{3}\\right) + 5t^{2}\\,d(t)\\left(1-2t-t^{2}\\right) + 14t^{3}\\,d(t)(1-2t) + 42t^{4}\\,d(t) & d(t)\\left(1-2t-t^{2}-2t^{3}-5t^{4}\\right) \\\\\n    \\end{array}\n    \\label{eq:table:a:zero:zero:shapiro}\n\\end{equation}\n\n% Catalan triangle\n\\begin{equation}\n    %\\hspace{-5cm}\n    \\begin{array}{ccc}\n        s & d(t) & \\alpha_{0,0}^{(s)}(t) \\\\\n        \\hline\n        2 & c_{0,0}\\alpha_{0,0}^{(2)}(t) + c_{1,0}\\alpha_{0,1}^{(2)}(t) = \\alpha_{0,0}^{(2)}(t) + t\\,d(t) & d(t)(1-t) \\\\\n        3 & c_{0,0}\\alpha_{0,0}^{(3)}(t) + t\\left(c_{1,0}\\alpha_{0,0}^{(2)}(t) + c_{2,0}\\alpha_{0,1}^{(2)}(t)\\right) =\n            \\alpha_{0,0}^{(3)}(t) + t(1-t)d(t) + 2t^{2}\\,d(t) & d(t)\\left(1-t-t^{2}\\right) \\\\\n        4 & c_{0,0}\\alpha_{0,0}^{(4)}(t) + t\\left(c_{1,0}\\alpha_{0,0}^{(3)}(t) + c_{2,0}\\alpha_{0,1}^{(3)}(t) + c_{3,0}\\alpha_{0,2}^{(3)}(t)\\right)  =\n            \\alpha_{0,0}^{(4)}(t) + t\\,d(t)\\left(1-t-t^{2}\\right) + 2t^{2}\\,d(t)(1-t) + 5t^{3}\\,d(t) & d(t)\\left(1-t-t^{2}-2t^{3}\\right) \\\\\n        5 & c_{0,0}\\alpha_{0,0}^{(5)}(t) + t\\left(c_{1,0}\\alpha_{0,0}^{(4)}(t) + c_{2,0}\\alpha_{0,1}^{(4)}(t) + c_{3,0}\\alpha_{0,2}^{(4)}(t) + c_{4,0}\\alpha_{0,3}^{(4)}(t)\\right)  =\n            \\alpha_{0,0}^{(5)}(t) + t\\,d(t)\\left(1-t-t^{2}-2t^{3}\\right) + 2t^{2}\\,d(t)\\left(1-t-t^{2}\\right) + 5t^{3}\\,d(t)(1-t) + 14t^{4}\\,d(t) & d(t)\\left(1-t-t^{2}-2t^{3}-5t^{4}\\right) \\\\\n    \\end{array}\n    \\label{eq:table:a:zero:zero:catalan}\n\\end{equation}\n\n% Fibonacci triangle\n\\begin{equation}\n    %\\hspace{-5cm}\n    \\begin{array}{ccc}\n        s & d(t) & \\alpha_{0,0}^{(s)}(t) \\\\\n        \\hline\n        2 & f_{0,0}\\alpha_{0,0}^{(2)}(t) + f_{1,0}\\alpha_{0,1}^{(2)}(t) = \\alpha_{0,0}^{(2)}(t) + t\\,d(t) & d(t)(1-t) \\\\\n        3 & f_{0,0}\\alpha_{0,0}^{(3)}(t) + t\\left(f_{1,0}\\alpha_{0,0}^{(2)}(t) + f_{2,0}\\alpha_{0,1}^{(2)}(t)\\right) =\n            \\alpha_{0,0}^{(3)}(t) + t(1-t)d(t) + 2t^{2}\\,d(t) & 1 \\\\\n        4 & f_{0,0}\\alpha_{0,0}^{(4)}(t) + t\\left(f_{1,0}\\alpha_{0,0}^{(3)}(t) + f_{2,0}\\alpha_{0,1}^{(3)}(t) + f_{3,0}\\alpha_{0,2}^{(3)}(t)\\right)  =\n            \\alpha_{0,0}^{(4)}(t) + t + 2t^{2}\\,d(t)(1-t) + 3t^{3}\\,d(t) & 1 \\\\\n        5 & f_{0,0}\\alpha_{0,0}^{(5)}(t) + t\\left(f_{1,0}\\alpha_{0,0}^{(4)}(t) + f_{2,0}\\alpha_{0,1}^{(4)}(t) + f_{3,0}\\alpha_{0,2}^{(4)}(t) + f_{4,0}\\alpha_{0,3}^{(4)}(t)\\right)  =\n            \\alpha_{0,0}^{(5)}(t) + t + 2t^{2} + 3t^{3}\\,d(t)(1-t) + 5t^{4}\\,d(t) & 1 \\\\\n    \\end{array}\n    \\label{eq:table:a:zero:zero:fibonacci}\n\\end{equation}\n\n\\end{sidewaystable}\n\n\\section{An horizontally stretched Pascal-like array}\n\nIn this section we study a stretched version of Pascal-like arrays, \nsplitting a matrix in $2$ and $3$ variables respectively. The \nfollowing is the used recurrence to do unfoldings:\n\\begin{displaymath}\n    m_{n + 1,k + 1} =  m_{n,k - 1} + m_{n,k}\n\\end{displaymath}\nstarting with the following purely symbolic matrix:\n\\begin{equation}\n\\hspace{-4cm}\n\\scriptsize\n\\left[\\begin{array}{ccccccccccccccccccc}\nm_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,1} & m_{1,2} &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{2,0} & m_{2,1} & m_{2,2} & m_{2,3} & m_{2,4} &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{3,0} & m_{3,1} & m_{3,2} & m_{3,3} & m_{3,4} & m_{3,5} & m_{3,6} &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{4,0} & m_{4,1} & m_{4,2} & m_{4,3} & m_{4,4} & m_{4,5} & m_{4,6} & m_{4,7} & m_{4,8} &  &  &  &  &  &  &  &  &  &  \\\\\nm_{5,0} & m_{5,1} & m_{5,2} & m_{5,3} & m_{5,4} & m_{5,5} & m_{5,6} & m_{5,7} & m_{5,8} & m_{5,9} & m_{5,10} &  &  &  &  &  &  &  &  \\\\\nm_{6,0} & m_{6,1} & m_{6,2} & m_{6,3} & m_{6,4} & m_{6,5} & m_{6,6} & m_{6,7} & m_{6,8} & m_{6,9} & m_{6,10} & m_{6,11} & m_{6,12} &  &  &  &  &  &  \\\\\nm_{7,0} & m_{7,1} & m_{7,2} & m_{7,3} & m_{7,4} & m_{7,5} & m_{7,6} & m_{7,7} & m_{7,8} & m_{7,9} & m_{7,10} & m_{7,11} & m_{7,12} & m_{7,13} & m_{7,14} &  &  &  &  \\\\\nm_{8,0} & m_{8,1} & m_{8,2} & m_{8,3} & m_{8,4} & m_{8,5} & m_{8,6} & m_{8,7} & m_{8,8} & m_{8,9} & m_{8,10} & m_{8,11} & m_{8,12} & m_{8,13} & m_{8,14} & m_{8,15} & m_{8,16} &  &  \\\\\nm_{9,0} & m_{9,1} & m_{9,2} & m_{9,3} & m_{9,4} & m_{9,5} & m_{9,6} & m_{9,7} & m_{9,8} & m_{9,9} & m_{9,10} & m_{9,11} & m_{9,12} & m_{9,13} & m_{9,14} & m_{9,15} & m_{9,16} & m_{9,17} & m_{9,18} \\\\\n\\end{array}\\right]\n\\label{eq:purely:symbolic:stretched:pascal:like}\n\\end{equation}\nIt should be pointed out that the given recurrence alone cannot characterize the entire\ntriangle, the \\emph{very first column} in particular. Therefore, we need to use another\nrecurrence for such column, what in the jargon of Riordan arrays is called $Z$-sequence:\n\\begin{displaymath}\n    m_{n + 1,0} =  m_{n,0}\n\\end{displaymath}\n\nIn \\autoref{eq:stretched:pascal:like} we report the unfolding starting at row $1$;\nmoreover, in \\autoref{eq:stretched:pascal:like:two:splitted} and \n\\autoref{eq:stretched:pascal:like:two:splitted:matrix:expansion} we report the same array splitted \nusing two variables and the corresponding matrix expansion as summation, respectively.\nIn parallel, \\autoref{eq:stretched:pascal:like:three:splitted} and \n\\autoref{eq:stretched:pascal:like:three:splitted:matrix:expansion} show the\nsame triangle splitted respect to $3$ variables.\n\\begin{equation}\nm_{0,0}\\left[\\begin{array}{ccccccccccccccccccc}\n1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 2 & 1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 4 & 3 & 1 &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 7 & 7 & 4 & 1 &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 12 & 14 & 11 & 5 & 1 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 20 & 26 & 25 & 16 & 6 & 1 &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 33 & 46 & 51 & 41 & 22 & 7 & 1 &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 34 & 54 & 79 & 97 & 92 & 63 & 29 & 8 & 1 &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 34 & 55 & 88 & 133 & 176 & 189 & 155 & 92 & 37 & 9 & 1 \\\\\n\\end{array}\\right]\n\\label{eq:stretched:pascal:like}\n\\end{equation}\n\n\n\\begin{sidewaystable}\n\\scriptsize\n\\begin{equation}\n\\left[\\begin{array}{ccccccccccccccccccc}\n\\textcolor{blue}{m_{0,0}} &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{m_{1,0}} & m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & m_{0,0} + m_{1,0} & 2 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & m_{0,0} + 2 m_{1,0} & 3 m_{0,0} + m_{1,0} & 3 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & 3 m_{1,0} & m_{0,0} + 4 m_{1,0} & 4 m_{0,0} + 3 m_{1,0} & 6 m_{0,0} + m_{1,0} & 4 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & 3 m_{1,0} & 5 m_{1,0} & m_{0,0} + 7 m_{1,0} & 5 m_{0,0} + 7 m_{1,0} & 10 m_{0,0} + 4 m_{1,0} & 10 m_{0,0} + m_{1,0} & 5 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & 3 m_{1,0} & 5 m_{1,0} & 8 m_{1,0} & m_{0,0} + 12 m_{1,0} & 6 m_{0,0} + 14 m_{1,0} & 15 m_{0,0} + 11 m_{1,0} & 20 m_{0,0} + 5 m_{1,0} & 15 m_{0,0} + m_{1,0} & 6 m_{0,0} & m_{0,0} &  &  &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & 3 m_{1,0} & 5 m_{1,0} & 8 m_{1,0} & 13 m_{1,0} & m_{0,0} + 20 m_{1,0} & 7 m_{0,0} + 26 m_{1,0} & 21 m_{0,0} + 25 m_{1,0} & 35 m_{0,0} + 16 m_{1,0} & 35 m_{0,0} + 6 m_{1,0} & 21 m_{0,0} + m_{1,0} & 7 m_{0,0} & m_{0,0} &  &  &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & 3 m_{1,0} & 5 m_{1,0} & 8 m_{1,0} & 13 m_{1,0} & 21 m_{1,0} & m_{0,0} + 33 m_{1,0} & 8 m_{0,0} + 46 m_{1,0} & 28 m_{0,0} + 51 m_{1,0} & 56 m_{0,0} + 41 m_{1,0} & 70 m_{0,0} + 22 m_{1,0} & 56 m_{0,0} + 7 m_{1,0} & 28 m_{0,0} + m_{1,0} & 8 m_{0,0} & m_{0,0} &  &  \\\\\nm_{1,0} & m_{1,0} & 2 m_{1,0} & 3 m_{1,0} & 5 m_{1,0} & 8 m_{1,0} & 13 m_{1,0} & 21 m_{1,0} & 34 m_{1,0} & m_{0,0} + 54 m_{1,0} & 9 m_{0,0} + 79 m_{1,0} & 36 m_{0,0} + 97 m_{1,0} & 84 m_{0,0} + 92 m_{1,0} & 126 m_{0,0} + 63 m_{1,0} & 126 m_{0,0} + 29 m_{1,0} & 84 m_{0,0} + 8 m_{1,0} & 36 m_{0,0} + m_{1,0} & 9 m_{0,0} & m_{0,0} \\\\\n\\end{array}\\right]\n\\label{eq:stretched:pascal:like:two:splitted}\n\\end{equation}\n\\begin{equation}\nm_{0,0}\\left[\\begin{array}{ccccccccccccccccccc}\n1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 1 & 2 & 1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 1 & 3 & 3 & 1 &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 1 & 4 & 6 & 4 & 1 &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 5 & 10 & 10 & 5 & 1 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 6 & 15 & 20 & 15 & 6 & 1 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1 &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 9 & 36 & 84 & 126 & 126 & 84 & 36 & 9 & 1 \\\\\n\\end{array}\\right] + m_{1,0}\\left[\\begin{array}{ccccccccccccccccccc}\n0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 2 & 1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 4 & 3 & 1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 7 & 7 & 4 & 1 & 0 & 0 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 12 & 14 & 11 & 5 & 1 & 0 & 0 &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 20 & 26 & 25 & 16 & 6 & 1 & 0 & 0 &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 33 & 46 & 51 & 41 & 22 & 7 & 1 & 0 & 0 &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 34 & 54 & 79 & 97 & 92 & 63 & 29 & 8 & 1 & 0 & 0 \\\\\n\\end{array}\\right]\n\\label{eq:stretched:pascal:like:two:splitted:matrix:expansion}\n\\end{equation}\n%\\end{sidewaystable}\n%\\begin{sidewaystable}\n%\\scriptsize\n\\begin{equation}\n\\left[\\begin{array}{ccccccccccccccccccc}\n\\textcolor{blue}{m_{0,0}} &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{m_{1,0}} & m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{m_{2,0}} & m_{1,0} & m_{0,0} + m_{1,0} & 2 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{2,0} & m_{2,0} & m_{1,0} + m_{2,0} & m_{0,0} + 2 m_{1,0} & 3 m_{0,0} + m_{1,0} & 3 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  &  &  \\\\\nm_{2,0} & m_{2,0} & 2 m_{2,0} & m_{1,0} + 2 m_{2,0} & m_{0,0} + 3 m_{1,0} + m_{2,0} & 4 m_{0,0} + 3 m_{1,0} & 6 m_{0,0} + m_{1,0} & 4 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  &  &  \\\\\nm_{2,0} & m_{2,0} & 2 m_{2,0} & 3 m_{2,0} & m_{1,0} + 4 m_{2,0} & m_{0,0} + 4 m_{1,0} + 3 m_{2,0} & 5 m_{0,0} + 6 m_{1,0} + m_{2,0} & 10 m_{0,0} + 4 m_{1,0} & 10 m_{0,0} + m_{1,0} & 5 m_{0,0} & m_{0,0} &  &  &  &  &  &  &  &  \\\\\nm_{2,0} & m_{2,0} & 2 m_{2,0} & 3 m_{2,0} & 5 m_{2,0} & m_{1,0} + 7 m_{2,0} & m_{0,0} + 5 m_{1,0} + 7 m_{2,0} & 6 m_{0,0} + 10 m_{1,0} + 4 m_{2,0} & 15 m_{0,0} + 10 m_{1,0} + m_{2,0} & 20 m_{0,0} + 5 m_{1,0} & 15 m_{0,0} + m_{1,0} & 6 m_{0,0} & m_{0,0} &  &  &  &  &  &  \\\\\nm_{2,0} & m_{2,0} & 2 m_{2,0} & 3 m_{2,0} & 5 m_{2,0} & 8 m_{2,0} & m_{1,0} + 12 m_{2,0} & m_{0,0} + 6 m_{1,0} + 14 m_{2,0} & 7 m_{0,0} + 15 m_{1,0} + 11 m_{2,0} & 21 m_{0,0} + 20 m_{1,0} + 5 m_{2,0} & 35 m_{0,0} + 15 m_{1,0} + m_{2,0} & 35 m_{0,0} + 6 m_{1,0} & 21 m_{0,0} + m_{1,0} & 7 m_{0,0} & m_{0,0} &  &  &  &  \\\\\nm_{2,0} & m_{2,0} & 2 m_{2,0} & 3 m_{2,0} & 5 m_{2,0} & 8 m_{2,0} & 13 m_{2,0} & m_{1,0} + 20 m_{2,0} & m_{0,0} + 7 m_{1,0} + 26 m_{2,0} & 8 m_{0,0} + 21 m_{1,0} + 25 m_{2,0} & 28 m_{0,0} + 35 m_{1,0} + 16 m_{2,0} & 56 m_{0,0} + 35 m_{1,0} + 6 m_{2,0} & 70 m_{0,0} + 21 m_{1,0} + m_{2,0} & 56 m_{0,0} + 7 m_{1,0} & 28 m_{0,0} + m_{1,0} & 8 m_{0,0} & m_{0,0} &  &  \\\\\nm_{2,0} & m_{2,0} & 2 m_{2,0} & 3 m_{2,0} & 5 m_{2,0} & 8 m_{2,0} & 13 m_{2,0} & 21 m_{2,0} & m_{1,0} + 33 m_{2,0} & m_{0,0} + 8 m_{1,0} + 46 m_{2,0} & 9 m_{0,0} + 28 m_{1,0} + 51 m_{2,0} & 36 m_{0,0} + 56 m_{1,0} + 41 m_{2,0} & 84 m_{0,0} + 70 m_{1,0} + 22 m_{2,0} & 126 m_{0,0} + 56 m_{1,0} + 7 m_{2,0} & 126 m_{0,0} + 28 m_{1,0} + m_{2,0} & 84 m_{0,0} + 8 m_{1,0} & 36 m_{0,0} + m_{1,0} & 9 m_{0,0} & m_{0,0} \\\\\n\\end{array}\\right]\n\\label{eq:stretched:pascal:like:three:splitted}\n\\end{equation}\n\\begin{equation}\n\\begin{split}\n& m_{0,0}\\left[\\begin{array}{ccccccccccccccccccc}\n1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 1 & 2 & 1 &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 1 & 3 & 3 & 1 &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 1 & 4 & 6 & 4 & 1 &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 5 & 10 & 10 & 5 & 1 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 6 & 15 & 20 & 15 & 6 & 1 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1 &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 9 & 36 & 84 & 126 & 126 & 84 & 36 & 9 & 1 \\\\\n\\end{array}\\right] + m_{1,0}\\left[\\begin{array}{ccccccccccccccccccc}\n0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 & 1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 1 & 2 & 1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 1 & 3 & 3 & 1 & 0 & 0 &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 1 & 4 & 6 & 4 & 1 & 0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 5 & 10 & 10 & 5 & 1 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 6 & 15 & 20 & 15 & 6 & 1 & 0 & 0 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 & 0 & 0 &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1 & 0 & 0 \\\\\n\\end{array}\\right] +\\\\\n& m_{2,0}\\left[\\begin{array}{ccccccccccccccccccc}\n0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 & 0 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 1 & 0 & 0 & 0 & 0 &  &  &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 2 & 1 & 0 & 0 & 0 & 0 &  &  &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 4 & 3 & 1 & 0 & 0 & 0 & 0 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 7 & 7 & 4 & 1 & 0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 12 & 14 & 11 & 5 & 1 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 20 & 26 & 25 & 16 & 6 & 1 & 0 & 0 & 0 & 0 &  &  \\\\\n1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 33 & 46 & 51 & 41 & 22 & 7 & 1 & 0 & 0 & 0 & 0 \\\\\n\\end{array}\\right] \n\\label{eq:stretched:pascal:like:three:splitted:matrix:expansion}\n\\end{split}\n\\end{equation}\n\\end{sidewaystable}\n\n\\subsection{Splitting renewal arrays with generalized $A$-sequence}\n\nIn this section we study the splitting of renewal arrays with a generalized\n$A$-sequence:\n\\begin{displaymath}\n    A(t) = \\alpha + \\beta\\,t + \\gamma\\,t^{2}\n\\end{displaymath}\nrespect $2$ variables. In \\autoref{eq:abstract:A:sequence:renewal:arrays:unfolded}\nwe report the unfold starting from row $1$; in \\autoref{eq:abstract:A:sequence:renewal:arrays:splitted}\nwe report the splitting respect variables $m_{0,0}$ and $m_{1,0}$; finally, \nin \\autoref{eq:abstract:A:sequence:renewal:arrays:splitted:matrix:expansion} we\nreport the corresponding matrix expansion.\n\n\\begin{sidewaystable}\n\\scriptsize\n\\begin{equation}\nm_{0,0}\\left[\\begin{array}{cccccccccc}\n1 &  &  &  &  &  &  &  &  &  \\\\\n\\beta & \\alpha &  &  &  &  &  &  &  &  \\\\\n\\alpha \\gamma + \\beta^{2} & 2 \\alpha \\beta & \\alpha^{2} &  &  &  &  &  &  &  \\\\\n3 \\alpha \\beta \\gamma + \\beta^{3} & 2 \\alpha^{2} \\gamma + 3 \\alpha \\beta^{2} & 3 \\alpha^{2} \\beta & \\alpha^{3} &  &  &  &  &  &  \\\\\n2 \\alpha^{2} \\gamma^{2} + 6 \\alpha \\beta^{2} \\gamma + \\beta^{4} & 8 \\alpha^{2} \\beta \\gamma + 4 \\alpha \\beta^{3} & 3 \\alpha^{3} \\gamma + 6 \\alpha^{2} \\beta^{2} & 4 \\alpha^{3} \\beta & \\alpha^{4} &  &  &  &  &  \\\\\n10 \\alpha^{2} \\beta \\gamma^{2} + 10 \\alpha \\beta^{3} \\gamma + \\beta^{5} & 5 \\alpha^{3} \\gamma^{2} + 20 \\alpha^{2} \\beta^{2} \\gamma + 5 \\alpha \\beta^{4} & 15 \\alpha^{3} \\beta \\gamma + 10 \\alpha^{2} \\beta^{3} & 4 \\alpha^{4} \\gamma + 10 \\alpha^{3} \\beta^{2} & 5 \\alpha^{4} \\beta & \\alpha^{5} &  &  &  &  \\\\\n5 \\alpha^{3} \\gamma^{3} + 30 \\alpha^{2} \\beta^{2} \\gamma^{2} + 15 \\alpha \\beta^{4} \\gamma + \\beta^{6} & 30 \\alpha^{3} \\beta \\gamma^{2} + 40 \\alpha^{2} \\beta^{3} \\gamma + 6 \\alpha \\beta^{5} & 9 \\alpha^{4} \\gamma^{2} + 45 \\alpha^{3} \\beta^{2} \\gamma + 15 \\alpha^{2} \\beta^{4} & 24 \\alpha^{4} \\beta \\gamma + 20 \\alpha^{3} \\beta^{3} & 5 \\alpha^{5} \\gamma + 15 \\alpha^{4} \\beta^{2} & 6 \\alpha^{5} \\beta & \\alpha^{6} &  &  &  \\\\\n35 \\alpha^{3} \\beta \\gamma^{3} + 70 \\alpha^{2} \\beta^{3} \\gamma^{2} + 21 \\alpha \\beta^{5} \\gamma + \\beta^{7} & 14 \\alpha^{4} \\gamma^{3} + 105 \\alpha^{3} \\beta^{2} \\gamma^{2} + 70 \\alpha^{2} \\beta^{4} \\gamma + 7 \\alpha \\beta^{6} & 63 \\alpha^{4} \\beta \\gamma^{2} + 105 \\alpha^{3} \\beta^{3} \\gamma + 21 \\alpha^{2} \\beta^{5} & 14 \\alpha^{5} \\gamma^{2} + 84 \\alpha^{4} \\beta^{2} \\gamma + 35 \\alpha^{3} \\beta^{4} & 35 \\alpha^{5} \\beta \\gamma + 35 \\alpha^{4} \\beta^{3} & 6 \\alpha^{6} \\gamma + 21 \\alpha^{5} \\beta^{2} & 7 \\alpha^{6} \\beta & \\alpha^{7} &  &  \\\\\n14 \\alpha^{4} \\gamma^{4} + 140 \\alpha^{3} \\beta^{2} \\gamma^{3} + 140 \\alpha^{2} \\beta^{4} \\gamma^{2} + 28 \\alpha \\beta^{6} \\gamma + \\beta^{8} & 112 \\alpha^{4} \\beta \\gamma^{3} + 280 \\alpha^{3} \\beta^{3} \\gamma^{2} + 112 \\alpha^{2} \\beta^{5} \\gamma + 8 \\alpha \\beta^{7} & 28 \\alpha^{5} \\gamma^{3} + 252 \\alpha^{4} \\beta^{2} \\gamma^{2} + 210 \\alpha^{3} \\beta^{4} \\gamma + 28 \\alpha^{2} \\beta^{6} & 112 \\alpha^{5} \\beta \\gamma^{2} + 224 \\alpha^{4} \\beta^{3} \\gamma + 56 \\alpha^{3} \\beta^{5} & 20 \\alpha^{6} \\gamma^{2} + 140 \\alpha^{5} \\beta^{2} \\gamma + 70 \\alpha^{4} \\beta^{4} & 48 \\alpha^{6} \\beta \\gamma + 56 \\alpha^{5} \\beta^{3} & 7 \\alpha^{7} \\gamma + 28 \\alpha^{6} \\beta^{2} & 8 \\alpha^{7} \\beta & \\alpha^{8} &  \\\\\n126 \\alpha^{4} \\beta \\gamma^{4} + 420 \\alpha^{3} \\beta^{3} \\gamma^{3} + 252 \\alpha^{2} \\beta^{5} \\gamma^{2} + 36 \\alpha \\beta^{7} \\gamma + \\beta^{9} & 42 \\alpha^{5} \\gamma^{4} + 504 \\alpha^{4} \\beta^{2} \\gamma^{3} + 630 \\alpha^{3} \\beta^{4} \\gamma^{2} + 168 \\alpha^{2} \\beta^{6} \\gamma + 9 \\alpha \\beta^{8} & 252 \\alpha^{5} \\beta \\gamma^{3} + 756 \\alpha^{4} \\beta^{3} \\gamma^{2} + 378 \\alpha^{3} \\beta^{5} \\gamma + 36 \\alpha^{2} \\beta^{7} & 48 \\alpha^{6} \\gamma^{3} + 504 \\alpha^{5} \\beta^{2} \\gamma^{2} + 504 \\alpha^{4} \\beta^{4} \\gamma + 84 \\alpha^{3} \\beta^{6} & 180 \\alpha^{6} \\beta \\gamma^{2} + 420 \\alpha^{5} \\beta^{3} \\gamma + 126 \\alpha^{4} \\beta^{5} & 27 \\alpha^{7} \\gamma^{2} + 216 \\alpha^{6} \\beta^{2} \\gamma + 126 \\alpha^{5} \\beta^{4} & 63 \\alpha^{7} \\beta \\gamma + 84 \\alpha^{6} \\beta^{3} & 8 \\alpha^{8} \\gamma + 36 \\alpha^{7} \\beta^{2} & 9 \\alpha^{8} \\beta & \\alpha^{9} \\\\\n\\end{array}\\right]\n\\label{eq:abstract:A:sequence:renewal:arrays:unfolded}\n\\end{equation}\n\\begin{equation}\n\\left[\\begin{array}{cccccccccc}\n\\textcolor{blue}{m_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{m_{1,0}} & \\alpha m_{0,0} &  &  &  &  &  &  &  &  \\\\\n\\alpha \\gamma m_{0,0} + \\beta m_{1,0} & \\alpha \\beta m_{0,0} + \\alpha m_{1,0} & \\alpha^{2} m_{0,0} &  &  &  &  &  &  &  \\\\\n2 \\alpha \\beta \\gamma m_{0,0} + \\left(\\alpha \\gamma + \\beta^{2}\\right) m_{1,0} & 2 \\alpha \\beta m_{1,0} + \\left(2 \\alpha^{2} \\gamma + \\alpha \\beta^{2}\\right) m_{0,0} & 2 \\alpha^{2} \\beta m_{0,0} + \\alpha^{2} m_{1,0} & \\alpha^{3} m_{0,0} &  &  &  &  &  &  \\\\\n\\left(2 \\alpha^{2} \\gamma^{2} + 3 \\alpha \\beta^{2} \\gamma\\right) m_{0,0} + \\left(3 \\alpha \\beta \\gamma + \\beta^{3}\\right) m_{1,0} & \\left(2 \\alpha^{2} \\gamma + 3 \\alpha \\beta^{2}\\right) m_{1,0} + \\left(6 \\alpha^{2} \\beta \\gamma + \\alpha \\beta^{3}\\right) m_{0,0} & 3 \\alpha^{2} \\beta m_{1,0} + \\left(3 \\alpha^{3} \\gamma + 3 \\alpha^{2} \\beta^{2}\\right) m_{0,0} & 3 \\alpha^{3} \\beta m_{0,0} + \\alpha^{3} m_{1,0} & \\alpha^{4} m_{0,0} &  &  &  &  &  \\\\\n\\left(8 \\alpha^{2} \\beta \\gamma^{2} + 4 \\alpha \\beta^{3} \\gamma\\right) m_{0,0} + \\left(2 \\alpha^{2} \\gamma^{2} + 6 \\alpha \\beta^{2} \\gamma + \\beta^{4}\\right) m_{1,0} & \\left(8 \\alpha^{2} \\beta \\gamma + 4 \\alpha \\beta^{3}\\right) m_{1,0} + \\left(5 \\alpha^{3} \\gamma^{2} + 12 \\alpha^{2} \\beta^{2} \\gamma + \\alpha \\beta^{4}\\right) m_{0,0} & \\left(3 \\alpha^{3} \\gamma + 6 \\alpha^{2} \\beta^{2}\\right) m_{1,0} + \\left(12 \\alpha^{3} \\beta \\gamma + 4 \\alpha^{2} \\beta^{3}\\right) m_{0,0} & 4 \\alpha^{3} \\beta m_{1,0} + \\left(4 \\alpha^{4} \\gamma + 6 \\alpha^{3} \\beta^{2}\\right) m_{0,0} & 4 \\alpha^{4} \\beta m_{0,0} + \\alpha^{4} m_{1,0} & \\alpha^{5} m_{0,0} &  &  &  &  \\\\\n\\left(5 \\alpha^{3} \\gamma^{3} + 20 \\alpha^{2} \\beta^{2} \\gamma^{2} + 5 \\alpha \\beta^{4} \\gamma\\right) m_{0,0} + \\left(10 \\alpha^{2} \\beta \\gamma^{2} + 10 \\alpha \\beta^{3} \\gamma + \\beta^{5}\\right) m_{1,0} & \\left(5 \\alpha^{3} \\gamma^{2} + 20 \\alpha^{2} \\beta^{2} \\gamma + 5 \\alpha \\beta^{4}\\right) m_{1,0} + \\left(25 \\alpha^{3} \\beta \\gamma^{2} + 20 \\alpha^{2} \\beta^{3} \\gamma + \\alpha \\beta^{5}\\right) m_{0,0} & \\left(15 \\alpha^{3} \\beta \\gamma + 10 \\alpha^{2} \\beta^{3}\\right) m_{1,0} + \\left(9 \\alpha^{4} \\gamma^{2} + 30 \\alpha^{3} \\beta^{2} \\gamma + 5 \\alpha^{2} \\beta^{4}\\right) m_{0,0} & \\left(4 \\alpha^{4} \\gamma + 10 \\alpha^{3} \\beta^{2}\\right) m_{1,0} + \\left(20 \\alpha^{4} \\beta \\gamma + 10 \\alpha^{3} \\beta^{3}\\right) m_{0,0} & 5 \\alpha^{4} \\beta m_{1,0} + \\left(5 \\alpha^{5} \\gamma + 10 \\alpha^{4} \\beta^{2}\\right) m_{0,0} & 5 \\alpha^{5} \\beta m_{0,0} + \\alpha^{5} m_{1,0} & \\alpha^{6} m_{0,0} &  &  &  \\\\\n\\left(30 \\alpha^{3} \\beta \\gamma^{3} + 40 \\alpha^{2} \\beta^{3} \\gamma^{2} + 6 \\alpha \\beta^{5} \\gamma\\right) m_{0,0} + \\left(5 \\alpha^{3} \\gamma^{3} + 30 \\alpha^{2} \\beta^{2} \\gamma^{2} + 15 \\alpha \\beta^{4} \\gamma + \\beta^{6}\\right) m_{1,0} & \\left(30 \\alpha^{3} \\beta \\gamma^{2} + 40 \\alpha^{2} \\beta^{3} \\gamma + 6 \\alpha \\beta^{5}\\right) m_{1,0} + \\left(14 \\alpha^{4} \\gamma^{3} + 75 \\alpha^{3} \\beta^{2} \\gamma^{2} + 30 \\alpha^{2} \\beta^{4} \\gamma + \\alpha \\beta^{6}\\right) m_{0,0} & \\left(9 \\alpha^{4} \\gamma^{2} + 45 \\alpha^{3} \\beta^{2} \\gamma + 15 \\alpha^{2} \\beta^{4}\\right) m_{1,0} + \\left(54 \\alpha^{4} \\beta \\gamma^{2} + 60 \\alpha^{3} \\beta^{3} \\gamma + 6 \\alpha^{2} \\beta^{5}\\right) m_{0,0} & \\left(24 \\alpha^{4} \\beta \\gamma + 20 \\alpha^{3} \\beta^{3}\\right) m_{1,0} + \\left(14 \\alpha^{5} \\gamma^{2} + 60 \\alpha^{4} \\beta^{2} \\gamma + 15 \\alpha^{3} \\beta^{4}\\right) m_{0,0} & \\left(5 \\alpha^{5} \\gamma + 15 \\alpha^{4} \\beta^{2}\\right) m_{1,0} + \\left(30 \\alpha^{5} \\beta \\gamma + 20 \\alpha^{4} \\beta^{3}\\right) m_{0,0} & 6 \\alpha^{5} \\beta m_{1,0} + \\left(6 \\alpha^{6} \\gamma + 15 \\alpha^{5} \\beta^{2}\\right) m_{0,0} & 6 \\alpha^{6} \\beta m_{0,0} + \\alpha^{6} m_{1,0} & \\alpha^{7} m_{0,0} &  &  \\\\\n\\left(14 \\alpha^{4} \\gamma^{4} + 105 \\alpha^{3} \\beta^{2} \\gamma^{3} + 70 \\alpha^{2} \\beta^{4} \\gamma^{2} + 7 \\alpha \\beta^{6} \\gamma\\right) m_{0,0} + \\left(35 \\alpha^{3} \\beta \\gamma^{3} + 70 \\alpha^{2} \\beta^{3} \\gamma^{2} + 21 \\alpha \\beta^{5} \\gamma + \\beta^{7}\\right) m_{1,0} & \\left(14 \\alpha^{4} \\gamma^{3} + 105 \\alpha^{3} \\beta^{2} \\gamma^{2} + 70 \\alpha^{2} \\beta^{4} \\gamma + 7 \\alpha \\beta^{6}\\right) m_{1,0} + \\left(98 \\alpha^{4} \\beta \\gamma^{3} + 175 \\alpha^{3} \\beta^{3} \\gamma^{2} + 42 \\alpha^{2} \\beta^{5} \\gamma + \\alpha \\beta^{7}\\right) m_{0,0} & \\left(63 \\alpha^{4} \\beta \\gamma^{2} + 105 \\alpha^{3} \\beta^{3} \\gamma + 21 \\alpha^{2} \\beta^{5}\\right) m_{1,0} + \\left(28 \\alpha^{5} \\gamma^{3} + 189 \\alpha^{4} \\beta^{2} \\gamma^{2} + 105 \\alpha^{3} \\beta^{4} \\gamma + 7 \\alpha^{2} \\beta^{6}\\right) m_{0,0} & \\left(14 \\alpha^{5} \\gamma^{2} + 84 \\alpha^{4} \\beta^{2} \\gamma + 35 \\alpha^{3} \\beta^{4}\\right) m_{1,0} + \\left(98 \\alpha^{5} \\beta \\gamma^{2} + 140 \\alpha^{4} \\beta^{3} \\gamma + 21 \\alpha^{3} \\beta^{5}\\right) m_{0,0} & \\left(35 \\alpha^{5} \\beta \\gamma + 35 \\alpha^{4} \\beta^{3}\\right) m_{1,0} + \\left(20 \\alpha^{6} \\gamma^{2} + 105 \\alpha^{5} \\beta^{2} \\gamma + 35 \\alpha^{4} \\beta^{4}\\right) m_{0,0} & \\left(6 \\alpha^{6} \\gamma + 21 \\alpha^{5} \\beta^{2}\\right) m_{1,0} + \\left(42 \\alpha^{6} \\beta \\gamma + 35 \\alpha^{5} \\beta^{3}\\right) m_{0,0} & 7 \\alpha^{6} \\beta m_{1,0} + \\left(7 \\alpha^{7} \\gamma + 21 \\alpha^{6} \\beta^{2}\\right) m_{0,0} & 7 \\alpha^{7} \\beta m_{0,0} + \\alpha^{7} m_{1,0} & \\alpha^{8} m_{0,0} &  \\\\\n\\left(112 \\alpha^{4} \\beta \\gamma^{4} + 280 \\alpha^{3} \\beta^{3} \\gamma^{3} + 112 \\alpha^{2} \\beta^{5} \\gamma^{2} + 8 \\alpha \\beta^{7} \\gamma\\right) m_{0,0} + \\left(14 \\alpha^{4} \\gamma^{4} + 140 \\alpha^{3} \\beta^{2} \\gamma^{3} + 140 \\alpha^{2} \\beta^{4} \\gamma^{2} + 28 \\alpha \\beta^{6} \\gamma + \\beta^{8}\\right) m_{1,0} & \\left(112 \\alpha^{4} \\beta \\gamma^{3} + 280 \\alpha^{3} \\beta^{3} \\gamma^{2} + 112 \\alpha^{2} \\beta^{5} \\gamma + 8 \\alpha \\beta^{7}\\right) m_{1,0} + \\left(42 \\alpha^{5} \\gamma^{4} + 392 \\alpha^{4} \\beta^{2} \\gamma^{3} + 350 \\alpha^{3} \\beta^{4} \\gamma^{2} + 56 \\alpha^{2} \\beta^{6} \\gamma + \\alpha \\beta^{8}\\right) m_{0,0} & \\left(28 \\alpha^{5} \\gamma^{3} + 252 \\alpha^{4} \\beta^{2} \\gamma^{2} + 210 \\alpha^{3} \\beta^{4} \\gamma + 28 \\alpha^{2} \\beta^{6}\\right) m_{1,0} + \\left(224 \\alpha^{5} \\beta \\gamma^{3} + 504 \\alpha^{4} \\beta^{3} \\gamma^{2} + 168 \\alpha^{3} \\beta^{5} \\gamma + 8 \\alpha^{2} \\beta^{7}\\right) m_{0,0} & \\left(112 \\alpha^{5} \\beta \\gamma^{2} + 224 \\alpha^{4} \\beta^{3} \\gamma + 56 \\alpha^{3} \\beta^{5}\\right) m_{1,0} + \\left(48 \\alpha^{6} \\gamma^{3} + 392 \\alpha^{5} \\beta^{2} \\gamma^{2} + 280 \\alpha^{4} \\beta^{4} \\gamma + 28 \\alpha^{3} \\beta^{6}\\right) m_{0,0} & \\left(20 \\alpha^{6} \\gamma^{2} + 140 \\alpha^{5} \\beta^{2} \\gamma + 70 \\alpha^{4} \\beta^{4}\\right) m_{1,0} + \\left(160 \\alpha^{6} \\beta \\gamma^{2} + 280 \\alpha^{5} \\beta^{3} \\gamma + 56 \\alpha^{4} \\beta^{5}\\right) m_{0,0} & \\left(48 \\alpha^{6} \\beta \\gamma + 56 \\alpha^{5} \\beta^{3}\\right) m_{1,0} + \\left(27 \\alpha^{7} \\gamma^{2} + 168 \\alpha^{6} \\beta^{2} \\gamma + 70 \\alpha^{5} \\beta^{4}\\right) m_{0,0} & \\left(7 \\alpha^{7} \\gamma + 28 \\alpha^{6} \\beta^{2}\\right) m_{1,0} + \\left(56 \\alpha^{7} \\beta \\gamma + 56 \\alpha^{6} \\beta^{3}\\right) m_{0,0} & 8 \\alpha^{7} \\beta m_{1,0} + \\left(8 \\alpha^{8} \\gamma + 28 \\alpha^{7} \\beta^{2}\\right) m_{0,0} & 8 \\alpha^{8} \\beta m_{0,0} + \\alpha^{8} m_{1,0} & \\alpha^{9} m_{0,0} \\\\\n\\end{array}\\right]\n\\label{eq:abstract:A:sequence:renewal:arrays:splitted}\n%\\label{eq:generic:motzkin:Arec}\n\\end{equation}\n\\begin{equation}\n\\begin{split}\n& m_{0,0}\\left[\\begin{array}{cccccccccc}\n1 &  &  &  &  &  &  &  &  &  \\\\\n0 & \\alpha &  &  &  &  &  &  &  &  \\\\\n\\alpha \\gamma & \\alpha \\beta & \\alpha^{2} &  &  &  &  &  &  &  \\\\\n2 \\alpha \\beta \\gamma & 2 \\alpha^{2} \\gamma + \\alpha \\beta^{2} & 2 \\alpha^{2} \\beta & \\alpha^{3} &  &  &  &  &  &  \\\\\n2 \\alpha^{2} \\gamma^{2} + 3 \\alpha \\beta^{2} \\gamma & 6 \\alpha^{2} \\beta \\gamma + \\alpha \\beta^{3} & 3 \\alpha^{3} \\gamma + 3 \\alpha^{2} \\beta^{2} & 3 \\alpha^{3} \\beta & \\alpha^{4} &  &  &  &  &  \\\\\n8 \\alpha^{2} \\beta \\gamma^{2} + 4 \\alpha \\beta^{3} \\gamma & 5 \\alpha^{3} \\gamma^{2} + 12 \\alpha^{2} \\beta^{2} \\gamma + \\alpha \\beta^{4} & 12 \\alpha^{3} \\beta \\gamma + 4 \\alpha^{2} \\beta^{3} & 4 \\alpha^{4} \\gamma + 6 \\alpha^{3} \\beta^{2} & 4 \\alpha^{4} \\beta & \\alpha^{5} &  &  &  &  \\\\\n5 \\alpha^{3} \\gamma^{3} + 20 \\alpha^{2} \\beta^{2} \\gamma^{2} + 5 \\alpha \\beta^{4} \\gamma & 25 \\alpha^{3} \\beta \\gamma^{2} + 20 \\alpha^{2} \\beta^{3} \\gamma + \\alpha \\beta^{5} & 9 \\alpha^{4} \\gamma^{2} + 30 \\alpha^{3} \\beta^{2} \\gamma + 5 \\alpha^{2} \\beta^{4} & 20 \\alpha^{4} \\beta \\gamma + 10 \\alpha^{3} \\beta^{3} & 5 \\alpha^{5} \\gamma + 10 \\alpha^{4} \\beta^{2} & 5 \\alpha^{5} \\beta & \\alpha^{6} &  &  &  \\\\\n30 \\alpha^{3} \\beta \\gamma^{3} + 40 \\alpha^{2} \\beta^{3} \\gamma^{2} + 6 \\alpha \\beta^{5} \\gamma & 14 \\alpha^{4} \\gamma^{3} + 75 \\alpha^{3} \\beta^{2} \\gamma^{2} + 30 \\alpha^{2} \\beta^{4} \\gamma + \\alpha \\beta^{6} & 54 \\alpha^{4} \\beta \\gamma^{2} + 60 \\alpha^{3} \\beta^{3} \\gamma + 6 \\alpha^{2} \\beta^{5} & 14 \\alpha^{5} \\gamma^{2} + 60 \\alpha^{4} \\beta^{2} \\gamma + 15 \\alpha^{3} \\beta^{4} & 30 \\alpha^{5} \\beta \\gamma + 20 \\alpha^{4} \\beta^{3} & 6 \\alpha^{6} \\gamma + 15 \\alpha^{5} \\beta^{2} & 6 \\alpha^{6} \\beta & \\alpha^{7} &  &  \\\\\n14 \\alpha^{4} \\gamma^{4} + 105 \\alpha^{3} \\beta^{2} \\gamma^{3} + 70 \\alpha^{2} \\beta^{4} \\gamma^{2} + 7 \\alpha \\beta^{6} \\gamma & 98 \\alpha^{4} \\beta \\gamma^{3} + 175 \\alpha^{3} \\beta^{3} \\gamma^{2} + 42 \\alpha^{2} \\beta^{5} \\gamma + \\alpha \\beta^{7} & 28 \\alpha^{5} \\gamma^{3} + 189 \\alpha^{4} \\beta^{2} \\gamma^{2} + 105 \\alpha^{3} \\beta^{4} \\gamma + 7 \\alpha^{2} \\beta^{6} & 98 \\alpha^{5} \\beta \\gamma^{2} + 140 \\alpha^{4} \\beta^{3} \\gamma + 21 \\alpha^{3} \\beta^{5} & 20 \\alpha^{6} \\gamma^{2} + 105 \\alpha^{5} \\beta^{2} \\gamma + 35 \\alpha^{4} \\beta^{4} & 42 \\alpha^{6} \\beta \\gamma + 35 \\alpha^{5} \\beta^{3} & 7 \\alpha^{7} \\gamma + 21 \\alpha^{6} \\beta^{2} & 7 \\alpha^{7} \\beta & \\alpha^{8} &  \\\\\n112 \\alpha^{4} \\beta \\gamma^{4} + 280 \\alpha^{3} \\beta^{3} \\gamma^{3} + 112 \\alpha^{2} \\beta^{5} \\gamma^{2} + 8 \\alpha \\beta^{7} \\gamma & 42 \\alpha^{5} \\gamma^{4} + 392 \\alpha^{4} \\beta^{2} \\gamma^{3} + 350 \\alpha^{3} \\beta^{4} \\gamma^{2} + 56 \\alpha^{2} \\beta^{6} \\gamma + \\alpha \\beta^{8} & 224 \\alpha^{5} \\beta \\gamma^{3} + 504 \\alpha^{4} \\beta^{3} \\gamma^{2} + 168 \\alpha^{3} \\beta^{5} \\gamma + 8 \\alpha^{2} \\beta^{7} & 48 \\alpha^{6} \\gamma^{3} + 392 \\alpha^{5} \\beta^{2} \\gamma^{2} + 280 \\alpha^{4} \\beta^{4} \\gamma + 28 \\alpha^{3} \\beta^{6} & 160 \\alpha^{6} \\beta \\gamma^{2} + 280 \\alpha^{5} \\beta^{3} \\gamma + 56 \\alpha^{4} \\beta^{5} & 27 \\alpha^{7} \\gamma^{2} + 168 \\alpha^{6} \\beta^{2} \\gamma + 70 \\alpha^{5} \\beta^{4} & 56 \\alpha^{7} \\beta \\gamma + 56 \\alpha^{6} \\beta^{3} & 8 \\alpha^{8} \\gamma + 28 \\alpha^{7} \\beta^{2} & 8 \\alpha^{8} \\beta & \\alpha^{9} \\\\\n\\end{array}\\right] \\\\\n& + m_{1,0}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 &  &  &  &  &  &  &  &  \\\\\n\\beta & \\alpha & 0 &  &  &  &  &  &  &  \\\\\n\\alpha \\gamma + \\beta^{2} & 2 \\alpha \\beta & \\alpha^{2} & 0 &  &  &  &  &  &  \\\\\n3 \\alpha \\beta \\gamma + \\beta^{3} & 2 \\alpha^{2} \\gamma + 3 \\alpha \\beta^{2} & 3 \\alpha^{2} \\beta & \\alpha^{3} & 0 &  &  &  &  &  \\\\\n2 \\alpha^{2} \\gamma^{2} + 6 \\alpha \\beta^{2} \\gamma + \\beta^{4} & 8 \\alpha^{2} \\beta \\gamma + 4 \\alpha \\beta^{3} & 3 \\alpha^{3} \\gamma + 6 \\alpha^{2} \\beta^{2} & 4 \\alpha^{3} \\beta & \\alpha^{4} & 0 &  &  &  &  \\\\\n10 \\alpha^{2} \\beta \\gamma^{2} + 10 \\alpha \\beta^{3} \\gamma + \\beta^{5} & 5 \\alpha^{3} \\gamma^{2} + 20 \\alpha^{2} \\beta^{2} \\gamma + 5 \\alpha \\beta^{4} & 15 \\alpha^{3} \\beta \\gamma + 10 \\alpha^{2} \\beta^{3} & 4 \\alpha^{4} \\gamma + 10 \\alpha^{3} \\beta^{2} & 5 \\alpha^{4} \\beta & \\alpha^{5} & 0 &  &  &  \\\\\n5 \\alpha^{3} \\gamma^{3} + 30 \\alpha^{2} \\beta^{2} \\gamma^{2} + 15 \\alpha \\beta^{4} \\gamma + \\beta^{6} & 30 \\alpha^{3} \\beta \\gamma^{2} + 40 \\alpha^{2} \\beta^{3} \\gamma + 6 \\alpha \\beta^{5} & 9 \\alpha^{4} \\gamma^{2} + 45 \\alpha^{3} \\beta^{2} \\gamma + 15 \\alpha^{2} \\beta^{4} & 24 \\alpha^{4} \\beta \\gamma + 20 \\alpha^{3} \\beta^{3} & 5 \\alpha^{5} \\gamma + 15 \\alpha^{4} \\beta^{2} & 6 \\alpha^{5} \\beta & \\alpha^{6} & 0 &  &  \\\\\n35 \\alpha^{3} \\beta \\gamma^{3} + 70 \\alpha^{2} \\beta^{3} \\gamma^{2} + 21 \\alpha \\beta^{5} \\gamma + \\beta^{7} & 14 \\alpha^{4} \\gamma^{3} + 105 \\alpha^{3} \\beta^{2} \\gamma^{2} + 70 \\alpha^{2} \\beta^{4} \\gamma + 7 \\alpha \\beta^{6} & 63 \\alpha^{4} \\beta \\gamma^{2} + 105 \\alpha^{3} \\beta^{3} \\gamma + 21 \\alpha^{2} \\beta^{5} & 14 \\alpha^{5} \\gamma^{2} + 84 \\alpha^{4} \\beta^{2} \\gamma + 35 \\alpha^{3} \\beta^{4} & 35 \\alpha^{5} \\beta \\gamma + 35 \\alpha^{4} \\beta^{3} & 6 \\alpha^{6} \\gamma + 21 \\alpha^{5} \\beta^{2} & 7 \\alpha^{6} \\beta & \\alpha^{7} & 0 &  \\\\\n14 \\alpha^{4} \\gamma^{4} + 140 \\alpha^{3} \\beta^{2} \\gamma^{3} + 140 \\alpha^{2} \\beta^{4} \\gamma^{2} + 28 \\alpha \\beta^{6} \\gamma + \\beta^{8} & 112 \\alpha^{4} \\beta \\gamma^{3} + 280 \\alpha^{3} \\beta^{3} \\gamma^{2} + 112 \\alpha^{2} \\beta^{5} \\gamma + 8 \\alpha \\beta^{7} & 28 \\alpha^{5} \\gamma^{3} + 252 \\alpha^{4} \\beta^{2} \\gamma^{2} + 210 \\alpha^{3} \\beta^{4} \\gamma + 28 \\alpha^{2} \\beta^{6} & 112 \\alpha^{5} \\beta \\gamma^{2} + 224 \\alpha^{4} \\beta^{3} \\gamma + 56 \\alpha^{3} \\beta^{5} & 20 \\alpha^{6} \\gamma^{2} + 140 \\alpha^{5} \\beta^{2} \\gamma + 70 \\alpha^{4} \\beta^{4} & 48 \\alpha^{6} \\beta \\gamma + 56 \\alpha^{5} \\beta^{3} & 7 \\alpha^{7} \\gamma + 28 \\alpha^{6} \\beta^{2} & 8 \\alpha^{7} \\beta & \\alpha^{8} & 0 \\\\\n\\end{array}\\right]\n\\end{split}\n\\label{eq:abstract:A:sequence:renewal:arrays:splitted:matrix:expansion}\n\\end{equation}\n\\end{sidewaystable}\n\n\\subsection{Complete matrix expansions of $\\mathcal{C}$}\n\nAll the content above let us to observe that after the first unfolding\nmacro-step, where elements in a purely symbolic matrix are unfolded\naccording $A$-sequences and $Z$-sequences, starting from a given row $r$,\nthen in the first $r$ rows there are actually ${{r}\\choose{2}}$ free variables.\nWhat we've done so far is to fix $r$ variables lying on the top segment of \ncolumn $0$, namely variables $c_{0,0}\\ldots c_{r-1,0}$, using $c$ as \ngeneric symbol for the matrix.\n\nTherefore we've:\n\\begin{displaymath}\n    {{{{r}\\choose{2}}}\\choose{r}} \n\\end{displaymath}\npossible choices of $r$ variables in order to build a matrix expansion using $r$ matrices.\nIn the following three sections we report \\emph{complete} matrix expansions of $\\mathcal{C}$\nwhere variables rest on the top segment of column $0$, on the main diagonal and, finally,\non the last but one row of the unfolding, respectively.\n\n\\subsubsection{Free variables lying on column $0$}\n\nIn \\autoref{eq:complete:splitting:catalan:variables:on:column:zero},\n\\autoref{eq:complete:expansion:catalan:variables:on:column:zero} and \n\\autoref{eq:complete:dependencies:catalan:variables:on:column:zero}\nwe report splitting, matrix expansion and dependencies of $\\mathcal{C}$\nusing variables $c_{0,0},c_{1,0},\\ldots, c_{9,0}$, respectively.\n\n\\begin{sidewaystable}\n\\scriptsize\n\\begin{equation}\n\\left[\\begin{array}{cccccccccc}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{1,0}} & c_{0,0} &  &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{2,0}} & c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{3,0}} & 2 c_{0,0} + c_{1,0} + c_{2,0} & 2 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{4,0}} & 5 c_{0,0} + 2 c_{1,0} + c_{2,0} + c_{3,0} & 5 c_{0,0} + 2 c_{1,0} + c_{2,0} & 3 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  &  \\\\\n\\textcolor{blue}{c_{5,0}} & 14 c_{0,0} + 5 c_{1,0} + 2 c_{2,0} + c_{3,0} + c_{4,0} & 14 c_{0,0} + 5 c_{1,0} + 2 c_{2,0} + c_{3,0} & 9 c_{0,0} + 3 c_{1,0} + c_{2,0} & 4 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  &  \\\\\n\\textcolor{blue}{c_{6,0}} & 42 c_{0,0} + 14 c_{1,0} + 5 c_{2,0} + 2 c_{3,0} + c_{4,0} + c_{5,0} & 42 c_{0,0} + 14 c_{1,0} + 5 c_{2,0} + 2 c_{3,0} + c_{4,0} & 28 c_{0,0} + 9 c_{1,0} + 3 c_{2,0} + c_{3,0} & 14 c_{0,0} + 4 c_{1,0} + c_{2,0} & 5 c_{0,0} + c_{1,0} & c_{0,0} &  &  &  \\\\\n\\textcolor{blue}{c_{7,0}} & 132 c_{0,0} + 42 c_{1,0} + 14 c_{2,0} + 5 c_{3,0} + 2 c_{4,0} + c_{5,0} + c_{6,0} & 132 c_{0,0} + 42 c_{1,0} + 14 c_{2,0} + 5 c_{3,0} + 2 c_{4,0} + c_{5,0} & 90 c_{0,0} + 28 c_{1,0} + 9 c_{2,0} + 3 c_{3,0} + c_{4,0} & 48 c_{0,0} + 14 c_{1,0} + 4 c_{2,0} + c_{3,0} & 20 c_{0,0} + 5 c_{1,0} + c_{2,0} & 6 c_{0,0} + c_{1,0} & c_{0,0} &  &  \\\\\n\\textcolor{blue}{c_{8,0}} & 429 c_{0,0} + 132 c_{1,0} + 42 c_{2,0} + 14 c_{3,0} + 5 c_{4,0} + 2 c_{5,0} + c_{6,0} + c_{7,0} & 429 c_{0,0} + 132 c_{1,0} + 42 c_{2,0} + 14 c_{3,0} + 5 c_{4,0} + 2 c_{5,0} + c_{6,0} & 297 c_{0,0} + 90 c_{1,0} + 28 c_{2,0} + 9 c_{3,0} + 3 c_{4,0} + c_{5,0} & 165 c_{0,0} + 48 c_{1,0} + 14 c_{2,0} + 4 c_{3,0} + c_{4,0} & 75 c_{0,0} + 20 c_{1,0} + 5 c_{2,0} + c_{3,0} & 27 c_{0,0} + 6 c_{1,0} + c_{2,0} & 7 c_{0,0} + c_{1,0} & c_{0,0} &  \\\\\n\\textcolor{blue}{c_{9,0}} & 1430 c_{0,0} + 429 c_{1,0} + 132 c_{2,0} + 42 c_{3,0} + 14 c_{4,0} + 5 c_{5,0} + 2 c_{6,0} + c_{7,0} + c_{8,0} & 1430 c_{0,0} + 429 c_{1,0} + 132 c_{2,0} + 42 c_{3,0} + 14 c_{4,0} + 5 c_{5,0} + 2 c_{6,0} + c_{7,0} & 1001 c_{0,0} + 297 c_{1,0} + 90 c_{2,0} + 28 c_{3,0} + 9 c_{4,0} + 3 c_{5,0} + c_{6,0} & 572 c_{0,0} + 165 c_{1,0} + 48 c_{2,0} + 14 c_{3,0} + 4 c_{4,0} + c_{5,0} & 275 c_{0,0} + 75 c_{1,0} + 20 c_{2,0} + 5 c_{3,0} + c_{4,0} & 110 c_{0,0} + 27 c_{1,0} + 6 c_{2,0} + c_{3,0} & 35 c_{0,0} + 7 c_{1,0} + c_{2,0} & 8 c_{0,0} + c_{1,0} & c_{0,0} \\\\\n\\end{array}\\right]\n\\label{eq:complete:splitting:catalan:variables:on:column:zero}\n\\end{equation}\n\\begin{equation}\n    \\begin{split}\n    & c_{0,0}\\left[\\begin{array}{cccccccccc}\n    1 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 1 &  &  &  &  &  &  &  &  \\\\\n    0 & 1 & 1 &  &  &  &  &  &  &  \\\\\n    0 & 2 & 2 & 1 &  &  &  &  &  &  \\\\\n    0 & 5 & 5 & 3 & 1 &  &  &  &  &  \\\\\n    0 & 14 & 14 & 9 & 4 & 1 &  &  &  &  \\\\\n    0 & 42 & 42 & 28 & 14 & 5 & 1 &  &  &  \\\\\n    0 & 132 & 132 & 90 & 48 & 20 & 6 & 1 &  &  \\\\\n    0 & 429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 &  \\\\\n    0 & 1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1 \\\\\n    \\end{array}\\right] + c_{1,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    1 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 1 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 1 & 1 & 0 &  &  &  &  &  &  \\\\\n    0 & 2 & 2 & 1 & 0 &  &  &  &  &  \\\\\n    0 & 5 & 5 & 3 & 1 & 0 &  &  &  &  \\\\\n    0 & 14 & 14 & 9 & 4 & 1 & 0 &  &  &  \\\\\n    0 & 42 & 42 & 28 & 14 & 5 & 1 & 0 &  &  \\\\\n    0 & 132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 &  \\\\\n    0 & 429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0 \\\\\n    \\end{array}\\right] + c_{2,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    1 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 1 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 1 & 1 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 2 & 2 & 1 & 0 & 0 &  &  &  &  \\\\\n    0 & 5 & 5 & 3 & 1 & 0 & 0 &  &  &  \\\\\n    0 & 14 & 14 & 9 & 4 & 1 & 0 & 0 &  &  \\\\\n    0 & 42 & 42 & 28 & 14 & 5 & 1 & 0 & 0 &  \\\\\n    0 & 132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 & 0 \\\\\n    \\end{array}\\right]\\\\\n    & + c_{3,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    1 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 1 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 1 & 1 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 2 & 2 & 1 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 5 & 5 & 3 & 1 & 0 & 0 & 0 &  &  \\\\\n    0 & 14 & 14 & 9 & 4 & 1 & 0 & 0 & 0 &  \\\\\n    0 & 42 & 42 & 28 & 14 & 5 & 1 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{4,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 1 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 1 & 1 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 2 & 2 & 1 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 5 & 5 & 3 & 1 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 14 & 14 & 9 & 4 & 1 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{5,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 2 & 2 & 1 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 5 & 5 & 3 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{6,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 2 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right]\\\\\n    & + c_{7,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{8,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] \n    \\end{split}\n\\label{eq:complete:expansion:catalan:variables:on:column:zero}\n\\end{equation}\n\\begin{equation}\n\\text{Buondary conditions on free variables:}\\quad\\left \\{ c_{1,0} : c_{0,0}, \\quad c_{2,0} : 2 c_{0,0}, \\quad c_{3,0} : 5 c_{0,0}, \\quad c_{4,0} : 14 c_{0,0}, \\quad c_{5,0} : 42 c_{0,0}, \\quad c_{6,0} : 132 c_{0,0}, \\quad c_{7,0} : 429 c_{0,0}, \\quad c_{8,0} : 1430 c_{0,0}, \\quad c_{9,0} : 4862 c_{0,0}\\right \\}\n\\label{eq:complete:dependencies:catalan:variables:on:column:zero}\n\\end{equation}\n\\end{sidewaystable}\n\n\n\\subsubsection{Free variables lying on main diagonal}\n\nIn \\autoref{eq:complete:splitting:catalan:variables:on:main:diagonal},\n\\autoref{eq:complete:expansion:catalan:variables:on:main:diagonal} and \n\\autoref{eq:complete:dependencies:catalan:variables:on:main:diagonal}\nwe report splitting, matrix expansion and dependencies of $\\mathcal{C}$\nusing variables $c_{0,0},c_{1,1},\\ldots, c_{9,9}$, respectively.\n\n\\begin{sidewaystable}\n\\scriptsize\n\\begin{equation}\n\\left[\\begin{array}{cccccccccc}\n\\textcolor{blue}{c_{0,0}} &  &  &  &  &  &  &  &  &  \\\\\nc_{0,0} & \\textcolor{blue}{c_{1,1}} &  &  &  &  &  &  &  &  \\\\\nc_{0,0} + c_{1,1} & c_{0,0} + c_{1,1} & \\textcolor{blue}{c_{2,2}} &  &  &  &  &  &  &  \\\\\n2 c_{0,0} + 2 c_{1,1} + c_{2,2} & 2 c_{0,0} + 2 c_{1,1} + c_{2,2} & c_{0,0} + c_{1,1} + c_{2,2} & \\textcolor{blue}{c_{3,3}} &  &  &  &  &  &  \\\\\n5 c_{0,0} + 5 c_{1,1} + 3 c_{2,2} + c_{3,3} & 5 c_{0,0} + 5 c_{1,1} + 3 c_{2,2} + c_{3,3} & 3 c_{0,0} + 3 c_{1,1} + 2 c_{2,2} + c_{3,3} & c_{0,0} + c_{1,1} + c_{2,2} + c_{3,3} & \\textcolor{blue}{c_{4,4}} &  &  &  &  &  \\\\\n14 c_{0,0} + 14 c_{1,1} + 9 c_{2,2} + 4 c_{3,3} + c_{4,4} & 14 c_{0,0} + 14 c_{1,1} + 9 c_{2,2} + 4 c_{3,3} + c_{4,4} & 9 c_{0,0} + 9 c_{1,1} + 6 c_{2,2} + 3 c_{3,3} + c_{4,4} & 4 c_{0,0} + 4 c_{1,1} + 3 c_{2,2} + 2 c_{3,3} + c_{4,4} & c_{0,0} + c_{1,1} + c_{2,2} + c_{3,3} + c_{4,4} & \\textcolor{blue}{c_{5,5}} &  &  &  &  \\\\\n42 c_{0,0} + 42 c_{1,1} + 28 c_{2,2} + 14 c_{3,3} + 5 c_{4,4} + c_{5,5} & 42 c_{0,0} + 42 c_{1,1} + 28 c_{2,2} + 14 c_{3,3} + 5 c_{4,4} + c_{5,5} & 28 c_{0,0} + 28 c_{1,1} + 19 c_{2,2} + 10 c_{3,3} + 4 c_{4,4} + c_{5,5} & 14 c_{0,0} + 14 c_{1,1} + 10 c_{2,2} + 6 c_{3,3} + 3 c_{4,4} + c_{5,5} & 5 c_{0,0} + 5 c_{1,1} + 4 c_{2,2} + 3 c_{3,3} + 2 c_{4,4} + c_{5,5} & c_{0,0} + c_{1,1} + c_{2,2} + c_{3,3} + c_{4,4} + c_{5,5} & \\textcolor{blue}{c_{6,6}} &  &  &  \\\\\n132 c_{0,0} + 132 c_{1,1} + 90 c_{2,2} + 48 c_{3,3} + 20 c_{4,4} + 6 c_{5,5} + c_{6,6} & 132 c_{0,0} + 132 c_{1,1} + 90 c_{2,2} + 48 c_{3,3} + 20 c_{4,4} + 6 c_{5,5} + c_{6,6} & 90 c_{0,0} + 90 c_{1,1} + 62 c_{2,2} + 34 c_{3,3} + 15 c_{4,4} + 5 c_{5,5} + c_{6,6} & 48 c_{0,0} + 48 c_{1,1} + 34 c_{2,2} + 20 c_{3,3} + 10 c_{4,4} + 4 c_{5,5} + c_{6,6} & 20 c_{0,0} + 20 c_{1,1} + 15 c_{2,2} + 10 c_{3,3} + 6 c_{4,4} + 3 c_{5,5} + c_{6,6} & 6 c_{0,0} + 6 c_{1,1} + 5 c_{2,2} + 4 c_{3,3} + 3 c_{4,4} + 2 c_{5,5} + c_{6,6} & c_{0,0} + c_{1,1} + c_{2,2} + c_{3,3} + c_{4,4} + c_{5,5} + c_{6,6} & \\textcolor{blue}{c_{7,7}} &  &  \\\\\n429 c_{0,0} + 429 c_{1,1} + 297 c_{2,2} + 165 c_{3,3} + 75 c_{4,4} + 27 c_{5,5} + 7 c_{6,6} + c_{7,7} & 429 c_{0,0} + 429 c_{1,1} + 297 c_{2,2} + 165 c_{3,3} + 75 c_{4,4} + 27 c_{5,5} + 7 c_{6,6} + c_{7,7} & 297 c_{0,0} + 297 c_{1,1} + 207 c_{2,2} + 117 c_{3,3} + 55 c_{4,4} + 21 c_{5,5} + 6 c_{6,6} + c_{7,7} & 165 c_{0,0} + 165 c_{1,1} + 117 c_{2,2} + 69 c_{3,3} + 35 c_{4,4} + 15 c_{5,5} + 5 c_{6,6} + c_{7,7} & 75 c_{0,0} + 75 c_{1,1} + 55 c_{2,2} + 35 c_{3,3} + 20 c_{4,4} + 10 c_{5,5} + 4 c_{6,6} + c_{7,7} & 27 c_{0,0} + 27 c_{1,1} + 21 c_{2,2} + 15 c_{3,3} + 10 c_{4,4} + 6 c_{5,5} + 3 c_{6,6} + c_{7,7} & 7 c_{0,0} + 7 c_{1,1} + 6 c_{2,2} + 5 c_{3,3} + 4 c_{4,4} + 3 c_{5,5} + 2 c_{6,6} + c_{7,7} & c_{0,0} + c_{1,1} + c_{2,2} + c_{3,3} + c_{4,4} + c_{5,5} + c_{6,6} + c_{7,7} & \\textcolor{blue}{c_{8,8}} &  \\\\\n1430 c_{0,0} + 1430 c_{1,1} + 1001 c_{2,2} + 572 c_{3,3} + 275 c_{4,4} + 110 c_{5,5} + 35 c_{6,6} + 8 c_{7,7} + c_{8,8} & 1430 c_{0,0} + 1430 c_{1,1} + 1001 c_{2,2} + 572 c_{3,3} + 275 c_{4,4} + 110 c_{5,5} + 35 c_{6,6} + 8 c_{7,7} + c_{8,8} & 1001 c_{0,0} + 1001 c_{1,1} + 704 c_{2,2} + 407 c_{3,3} + 200 c_{4,4} + 83 c_{5,5} + 28 c_{6,6} + 7 c_{7,7} + c_{8,8} & 572 c_{0,0} + 572 c_{1,1} + 407 c_{2,2} + 242 c_{3,3} + 125 c_{4,4} + 56 c_{5,5} + 21 c_{6,6} + 6 c_{7,7} + c_{8,8} & 275 c_{0,0} + 275 c_{1,1} + 200 c_{2,2} + 125 c_{3,3} + 70 c_{4,4} + 35 c_{5,5} + 15 c_{6,6} + 5 c_{7,7} + c_{8,8} & 110 c_{0,0} + 110 c_{1,1} + 83 c_{2,2} + 56 c_{3,3} + 35 c_{4,4} + 20 c_{5,5} + 10 c_{6,6} + 4 c_{7,7} + c_{8,8} & 35 c_{0,0} + 35 c_{1,1} + 28 c_{2,2} + 21 c_{3,3} + 15 c_{4,4} + 10 c_{5,5} + 6 c_{6,6} + 3 c_{7,7} + c_{8,8} & 8 c_{0,0} + 8 c_{1,1} + 7 c_{2,2} + 6 c_{3,3} + 5 c_{4,4} + 4 c_{5,5} + 3 c_{6,6} + 2 c_{7,7} + c_{8,8} & c_{0,0} + c_{1,1} + c_{2,2} + c_{3,3} + c_{4,4} + c_{5,5} + c_{6,6} + c_{7,7} + c_{8,8} & \\textcolor{blue}{c_{9,9}} \\\\\n\\end{array}\\right]\n\\label{eq:complete:splitting:catalan:variables:on:main:diagonal}\n\\end{equation}\n\\begin{equation}\n    \\begin{split}\n& c_{0,0}\\left[\\begin{array}{cccccccccc}\n1 &  &  &  &  &  &  &  &  &  \\\\\n1 & 0 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 0 &  &  &  &  &  &  &  \\\\\n2 & 2 & 1 & 0 &  &  &  &  &  &  \\\\\n5 & 5 & 3 & 1 & 0 &  &  &  &  &  \\\\\n14 & 14 & 9 & 4 & 1 & 0 &  &  &  &  \\\\\n42 & 42 & 28 & 14 & 5 & 1 & 0 &  &  &  \\\\\n132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 &  &  \\\\\n429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0 &  \\\\\n1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1 & 0 \\\\\n\\end{array}\\right] + c_{1,1}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 1 &  &  &  &  &  &  &  &  \\\\\n1 & 1 & 0 &  &  &  &  &  &  &  \\\\\n2 & 2 & 1 & 0 &  &  &  &  &  &  \\\\\n5 & 5 & 3 & 1 & 0 &  &  &  &  &  \\\\\n14 & 14 & 9 & 4 & 1 & 0 &  &  &  &  \\\\\n42 & 42 & 28 & 14 & 5 & 1 & 0 &  &  &  \\\\\n132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 &  &  \\\\\n429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0 &  \\\\\n1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1 & 0 \\\\\n\\end{array}\\right] + c_{2,2}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 1 &  &  &  &  &  &  &  \\\\\n1 & 1 & 1 & 0 &  &  &  &  &  &  \\\\\n3 & 3 & 2 & 1 & 0 &  &  &  &  &  \\\\\n9 & 9 & 6 & 3 & 1 & 0 &  &  &  &  \\\\\n28 & 28 & 19 & 10 & 4 & 1 & 0 &  &  &  \\\\\n90 & 90 & 62 & 34 & 15 & 5 & 1 & 0 &  &  \\\\\n297 & 297 & 207 & 117 & 55 & 21 & 6 & 1 & 0 &  \\\\\n1001 & 1001 & 704 & 407 & 200 & 83 & 28 & 7 & 1 & 0 \\\\\n\\end{array}\\right]\\\\\n& + c_{3,3}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 1 &  &  &  &  &  &  \\\\\n1 & 1 & 1 & 1 & 0 &  &  &  &  &  \\\\\n4 & 4 & 3 & 2 & 1 & 0 &  &  &  &  \\\\\n14 & 14 & 10 & 6 & 3 & 1 & 0 &  &  &  \\\\\n48 & 48 & 34 & 20 & 10 & 4 & 1 & 0 &  &  \\\\\n165 & 165 & 117 & 69 & 35 & 15 & 5 & 1 & 0 &  \\\\\n572 & 572 & 407 & 242 & 125 & 56 & 21 & 6 & 1 & 0 \\\\\n\\end{array}\\right] + c_{4,4}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 1 &  &  &  &  &  \\\\\n1 & 1 & 1 & 1 & 1 & 0 &  &  &  &  \\\\\n5 & 5 & 4 & 3 & 2 & 1 & 0 &  &  &  \\\\\n20 & 20 & 15 & 10 & 6 & 3 & 1 & 0 &  &  \\\\\n75 & 75 & 55 & 35 & 20 & 10 & 4 & 1 & 0 &  \\\\\n275 & 275 & 200 & 125 & 70 & 35 & 15 & 5 & 1 & 0 \\\\\n\\end{array}\\right] + c_{5,5}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 1 &  &  &  &  \\\\\n1 & 1 & 1 & 1 & 1 & 1 & 0 &  &  &  \\\\\n6 & 6 & 5 & 4 & 3 & 2 & 1 & 0 &  &  \\\\\n27 & 27 & 21 & 15 & 10 & 6 & 3 & 1 & 0 &  \\\\\n110 & 110 & 83 & 56 & 35 & 20 & 10 & 4 & 1 & 0 \\\\\n\\end{array}\\right]\\\\\n& + c_{6,6}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1 &  &  &  \\\\\n1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 &  &  \\\\\n7 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 &  \\\\\n35 & 35 & 28 & 21 & 15 & 10 & 6 & 3 & 1 & 0 \\\\\n\\end{array}\\right] + c_{7,7}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 &  &  \\\\\n1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 &  \\\\\n8 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\\\\n\\end{array}\\right] + c_{8,8}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 &  \\\\\n1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 \\\\\n\\end{array}\\right] + c_{9,9}\\left[\\begin{array}{cccccccccc}\n0 &  &  &  &  &  &  &  &  &  \\\\\n0 & 0 &  &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n\\end{array}\\right]   \n\\end{split}\n\\label{eq:complete:expansion:catalan:variables:on:main:diagonal}\n\\end{equation}\n\\begin{equation}\n\\text{Buondary conditions on free variables:}\\quad\n\\left \\{ c_{1,1} : c_{0,0}, \\quad c_{2,2} : c_{0,0}, \\quad c_{3,3} : c_{0,0}, \\quad c_{4,4} : c_{0,0}, \\quad c_{5,5} : c_{0,0}, \\quad c_{6,6} : c_{0,0}, \\quad c_{7,7} : c_{0,0}, \\quad c_{8,8} : c_{0,0}, \\quad c_{9,9} : c_{0,0}\\right \\}\n\\label{eq:complete:dependencies:catalan:variables:on:main:diagonal}\n\\end{equation}\n\\end{sidewaystable}\n\n\\subsubsection{Free variables lying on last but one row}\n\nIn \\autoref{eq:complete:splitting:catalan:variables:on:last:but:one},\n\\autoref{eq:complete:expansion:catalan:variables:on:last:but:one} and \n\\autoref{eq:complete:dependencies:catalan:variables:on:last:but:one}\nwe report splitting, matrix expansion and dependencies of $\\mathcal{C}$\nusing variables $c_{9,0},c_{9,1},\\ldots, c_{9,9}$, respectively.\n\n\\begin{sidewaystable}\n\\scriptsize\n\\begin{equation}\n\\left[\\begin{array}{cccccccccc}\nc_{9,9} &  &  &  &  &  &  &  &  &  \\\\\nc_{9,8} - 8 c_{9,9} & c_{9,9} &  &  &  &  &  &  &  &  \\\\\nc_{9,7} - 7 c_{9,8} + 21 c_{9,9} & c_{9,8} - 7 c_{9,9} & c_{9,9} &  &  &  &  &  &  &  \\\\\nc_{9,6} - 6 c_{9,7} + 15 c_{9,8} - 20 c_{9,9} & c_{9,7} - 6 c_{9,8} + 15 c_{9,9} & c_{9,8} - 6 c_{9,9} & c_{9,9} &  &  &  &  &  &  \\\\\nc_{9,5} - 5 c_{9,6} + 10 c_{9,7} - 10 c_{9,8} + 5 c_{9,9} & c_{9,6} - 5 c_{9,7} + 10 c_{9,8} - 10 c_{9,9} & c_{9,7} - 5 c_{9,8} + 10 c_{9,9} & c_{9,8} - 5 c_{9,9} & c_{9,9} &  &  &  &  &  \\\\\nc_{9,4} - 4 c_{9,5} + 6 c_{9,6} - 4 c_{9,7} + c_{9,8} & c_{9,5} - 4 c_{9,6} + 6 c_{9,7} - 4 c_{9,8} + c_{9,9} & c_{9,6} - 4 c_{9,7} + 6 c_{9,8} - 4 c_{9,9} & c_{9,7} - 4 c_{9,8} + 6 c_{9,9} & c_{9,8} - 4 c_{9,9} & c_{9,9} &  &  &  &  \\\\\nc_{9,3} - 3 c_{9,4} + 3 c_{9,5} - c_{9,6} & c_{9,4} - 3 c_{9,5} + 3 c_{9,6} - c_{9,7} & c_{9,5} - 3 c_{9,6} + 3 c_{9,7} - c_{9,8} & c_{9,6} - 3 c_{9,7} + 3 c_{9,8} - c_{9,9} & c_{9,7} - 3 c_{9,8} + 3 c_{9,9} & c_{9,8} - 3 c_{9,9} & c_{9,9} &  &  &  \\\\\nc_{9,2} - 2 c_{9,3} + c_{9,4} & c_{9,3} - 2 c_{9,4} + c_{9,5} & c_{9,4} - 2 c_{9,5} + c_{9,6} & c_{9,5} - 2 c_{9,6} + c_{9,7} & c_{9,6} - 2 c_{9,7} + c_{9,8} & c_{9,7} - 2 c_{9,8} + c_{9,9} & c_{9,8} - 2 c_{9,9} & c_{9,9} &  &  \\\\\nc_{9,1} - c_{9,2} & c_{9,2} - c_{9,3} & c_{9,3} - c_{9,4} & c_{9,4} - c_{9,5} & c_{9,5} - c_{9,6} & c_{9,6} - c_{9,7} & c_{9,7} - c_{9,8} & c_{9,8} - c_{9,9} & c_{9,9} &  \\\\\n\\textcolor{blue}{c_{9,0}} & \\textcolor{blue}{c_{9,1}} & \\textcolor{blue}{c_{9,2}} & \\textcolor{blue}{c_{9,3}} & \\textcolor{blue}{c_{9,4}} & \\textcolor{blue}{c_{9,5}} & \\textcolor{blue}{c_{9,6}} & c_{9,7} & \\textcolor{blue}{c_{9,8}} & \\textcolor{blue}{c_{9,9}} \\\\\n\\end{array}\\right]\n\\label{eq:complete:splitting:catalan:variables:on:last:but:one}\n\\end{equation}\n\\begin{equation}\n    \\begin{split}\n    & c_{9,0}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,1}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,2}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,3}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    -2 & 1 & 0 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] \\\\\n    & c_{9,4}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    -3 & 1 & 0 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    1 & -2 & 1 & 0 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,5}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    1 & 0 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    -4 & 1 & 0 & 0 & 0 & 0 &  &  &  &  \\\\\n    3 & -3 & 1 & 0 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 1 & -2 & 1 & 0 & 0 & 0 & 0 &  &  \\\\\n    0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 &  \\\\\n    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,6}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    0 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    1 & 0 & 0 & 0 &  &  &  &  &  &  \\\\\n    -5 & 1 & 0 & 0 & 0 &  &  &  &  &  \\\\\n    6 & -4 & 1 & 0 & 0 & 0 &  &  &  &  \\\\\n    -1 & 3 & -3 & 1 & 0 & 0 & 0 &  &  &  \\\\\n    0 & 0 & 1 & -2 & 1 & 0 & 0 & 0 &  &  \\\\\n    0 & 0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n    \\end{array}\\right]\\\\\n    & + c_{9,7}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    0 & 0 &  &  &  &  &  &  &  &  \\\\\n    1 & 0 & 0 &  &  &  &  &  &  &  \\\\\n    -6 & 1 & 0 & 0 &  &  &  &  &  &  \\\\\n    10 & -5 & 1 & 0 & 0 &  &  &  &  &  \\\\\n    -4 & 6 & -4 & 1 & 0 & 0 &  &  &  &  \\\\\n    0 & -1 & 3 & -3 & 1 & 0 & 0 &  &  &  \\\\\n    0 & 0 & 0 & 1 & -2 & 1 & 0 & 0 &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & -1 & 1 & 0 & 0 &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n    \\end{array}\\right] + c_{9,8}\\left[\\begin{array}{cccccccccc}\n    0 &  &  &  &  &  &  &  &  &  \\\\\n    1 & 0 &  &  &  &  &  &  &  &  \\\\\n    -7 & 1 & 0 &  &  &  &  &  &  &  \\\\\n    15 & -6 & 1 & 0 &  &  &  &  &  &  \\\\\n    -10 & 10 & -5 & 1 & 0 &  &  &  &  &  \\\\\n    1 & -4 & 6 & -4 & 1 & 0 &  &  &  &  \\\\\n    0 & 0 & -1 & 3 & -3 & 1 & 0 &  &  &  \\\\\n    0 & 0 & 0 & 0 & 1 & -2 & 1 & 0 &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & 0 &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n    \\end{array}\\right] + c_{9,9}\\left[\\begin{array}{cccccccccc}\n    1 &  &  &  &  &  &  &  &  &  \\\\\n    -8 & 1 &  &  &  &  &  &  &  &  \\\\\n    21 & -7 & 1 &  &  &  &  &  &  &  \\\\\n    -20 & 15 & -6 & 1 &  &  &  &  &  &  \\\\\n    5 & -10 & 10 & -5 & 1 &  &  &  &  &  \\\\\n    0 & 1 & -4 & 6 & -4 & 1 &  &  &  &  \\\\\n    0 & 0 & 0 & -1 & 3 & -3 & 1 &  &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 1 & -2 & 1 &  &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 &  \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n    \\end{array}\\right]\n    \\end{split}\n\\label{eq:complete:expansion:catalan:variables:on:last:but:one}\n\\end{equation}\n\\begin{equation}\n\\text{Buondary conditions on free variables:}\\quad\n\\left \\{ c_{9,0} : 4862 c_{0,0}, \\quad c_{9,1} : 4862 c_{0,0}, \\quad c_{9,2} : 3432 c_{0,0}, \\quad c_{9,3} : 2002 c_{0,0}, \\quad c_{9,4} : 1001 c_{0,0}, \\quad c_{9,5} : 429 c_{0,0}, \\quad c_{9,6} : 154 c_{0,0}, \\quad c_{9,7} : 44 c_{0,0}, \\quad c_{9,8} : 9 c_{0,0}, \\quad c_{9,9} : c_{0,0}\\right \\}\n\\label{eq:complete:dependencies:catalan:variables:on:last:but:one}\n\\end{equation}\n\\end{sidewaystable}\n", "meta": {"hexsha": "d3d47aaaaf26ad17f34e7501cf8d9035ed3e2047", "size": 87321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/chapters/doubly-indexed-recurrences.tex", "max_stars_repo_name": "massimo-nocentini/Ph.D", "max_stars_repo_head_hexsha": "7b5174c669d2c1acfe4538e69338064d8acfbe92", "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/doubly-indexed-recurrences.tex", "max_issues_repo_name": "massimo-nocentini/Ph.D", "max_issues_repo_head_hexsha": "7b5174c669d2c1acfe4538e69338064d8acfbe92", "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/doubly-indexed-recurrences.tex", "max_forks_repo_name": "massimo-nocentini/Ph.D", "max_forks_repo_head_hexsha": "7b5174c669d2c1acfe4538e69338064d8acfbe92", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.5408163265, "max_line_length": 1928, "alphanum_fraction": 0.4469257109, "num_tokens": 47627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6719203776411765}}
{"text": "%&LaTeX\n\n\\section{Feedforward Filters}\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 J-DSP}\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\n\\begin{figure}\n  \\begin{center}\n    \\includegraphics[width=5in]{lab4/polezerodiagrams}\n  \\end{center}\n  \\caption{J-DSP setup for specifying filter coefficients and monitoring\n  frequency response and zero location. (Left) Using the \\block{coeff} block. (Right) Using the \\block{PZ-Placement} block\n  \\label{fg:PZfigs}}\n\\end{figure}\n\nJ-DSP has a set of blocks that directly correspond to the concepts we\nhave learned. These include the \\block{Filter} block, which takes an\ninput signal on the left and parameters (zero locations or\ncoefficients) at the bottom, and produces an output signal on the\nright and can have its characteristics (frequency response or zero\nlocations) monitored via a connection from the top. We will use\n\\block{Filter} in two different ways:\n\\begin{enumerate}\n\\item We will specify the coefficients of the transfer function or\n  generating equation using the \\block{Coeff.} block and monitor the\n  filter's output (using \\block{Plot}), frequency response (using\n  \\block{Freq-Resp}), and zero placement (using \\block{PZ-Plot}), as\n  in Figure~\\ref{fg:PZfigs} (left).\n\\item Instead of defining the filter using the \\block{Coeff} block, we will\n  place zeros directly in the complex plane using the \\block{PZ\n    Placement} block (which has an option to show the corresponding\n  filter coefficients), as shown in Figure~\\ref{fg:PZfigs} (right).\n\\end{enumerate}\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.\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\\[\ny[n] = \\frac{1}{2}x[n] + \\frac{1}{2}x[n-1]\n\\]\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 frequency response from this by remembering that \n$H(e^{j\\hat{\\omega}})  = \\mathcal{H}({\\hat{\\omega}})$ or that $z=e^{j\\hat{\\omega}}$. From the zero\nlocation, $z=-1$, we can immediately tell that the frequency response is zero at $e^{j\\hat{\\omega}}=-1$ or \n$\\hat{\\omega}=\\pi$. With a zero at an angle of\n$\\hat{\\omega}=\\pi$, this is a low-pass filter. As a warm-up, use the\nJ-DSP setup of Figure~\\ref{fg:PZfigs} (left) 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 J-DSP to verify this.\n\n\\item Sketch the magnitude of the frequency response as a function of\n\t$\\hat{\\omega}$ from the plot of pole locations and verify this using\n\tJ-DSP. How does the minimum of the magnitude of the frequency\n\tresponse relate to the polar representation of the zero locations?\n\tWhat kind of filter would you say this is?\n\n\\end{enumerate}\n\n\\begin{figure}\n  \\begin{center}\n    \\includegraphics[width=6in]{lab4/filteredsignal}\n  \\end{center}\n\\caption{J-DSP setup for Step 1.2 (e, f, and g). \\label{fg:filtsig}}\n\\end{figure}\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 J-DSP.\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 J-DSP to\n\t  check your results. What kind of filter would you say this is?\n\t  \n\n\\item Use J-DSP to simulate this filter's response to the following\n\t  input. Set the \\block{Sig Gen} to produce a sinusoid with\n\t  \\option{frequency} $0.125\\pi$, \\option{gain} 1, \\option{pulsewidth}\n\t  40. The diagram is shown in Figure \\ref{fg:filtsig}.\n\n\\item Examine the plots of $X$ and $Y$ in J-DSP. 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.\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 expression for\n\t  the filter's frequency response to calculate the amplitude and phase\n\t  at a frequency of $\\hat{\\omega} = \\pi/8$. How do these compare to\n\t  what you determined from the J-DSP 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 J-DSP.\n\t  \n\t  \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 J-DSP to\n\t  check your results. What kind of filter would you 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 J-DSP 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 this filter by doubling the input amplitude in J-DSP ($X' = 2X = X\n+ X$). How does the new output amplitude compare to the old one?\n\n\n\\paragraph{Step 2.2} In one of the self-test exercises in the class notes,\n\ttwo filters with transfer functions $H_1(z) = b_0 + b_1z^{-1}$ and\n\t$H_2(z) = b'_0 + b'_1z^{-1}$ were connected in series, and it was\n\tshown that they could be connected in either order to produce the same\n\tcomposite effect (the same overall transfer function). Redo this\n\texercise using the \\emph{defining equations} for the two filters, i.e.,\n\t$y_1[n] = F_1(x[n])$ for the filter with transfer function $H_1(z)$\n\tand $y_2[n] = F_2(x[n])$ for the filter with transfer function\n\t$H_2(z)$. In other words, show that $F_2(F_1(x[n])) =\n\tF_1(F_2(x[n]))$.\n\n\n\\paragraph{Step 2.3} Use J-DSP to implement a system in which the output of\n\tthe \\block{Sig Gen} is connected to the three-point averager of step\n\t1.1, the output of which is in turn connected to the first-difference\n\tfilter of step 1.2. Set the \\block{Sig Gen} to output a periodic,\n\trectangular waveform with amplitude of 1, pulse width of 10, and\n\tperiod of 20. This is a 50\\% duty cycle square wave. Plot the final\n\toutput waveform. What does it look like?\n\n\n\\paragraph{Step 2.4} Change your J-DSP simulation so that the first\n\tdifference filter is first and the three-point averager is\n\tsecond. Plot the output. How does the output of this configuration\n\tcompare to that of step 3.3?\n\n\n% LocalWords:  WebQ MATLAB\n", "meta": {"hexsha": "c41e4f49c4b638e2bb52c8ac88df4d56d0600431", "size": 12381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "J-DSP 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": "J-DSP 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": "J-DSP 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": 41.9694915254, "max_line_length": 122, "alphanum_fraction": 0.7232049108, "num_tokens": 3606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6718374135031262}}
{"text": "\n\\subsection{Continuity}\n\n\\subsubsection{Transitivity}\n\nAxioms of continuity and transitivity\n\nContinuous\n\nIndependence of irrelevant alternatives\n\n\n\\subsubsection{Axiom 3: Continuity}\n\nIn order to find optimal points for a utility function we want these functions to be differentiable. This requires complete sets of choices. That is, if \\(a\\) if preferred to \\(b\\), points very close to \\(a\\) will also be preferred to \\(b\\).\n\nAgents often make choices discretely. How much of good \\(x\\) to consume, whether to go on a holiday. We treat these as continuous. This is generally not problematic as agents choices become less discrete over longer time spans, and most economic areas of interest do not rest on discrete consumption.\n\n\\subsubsection{Marginal utility}\n\nWe can differentiate our utility function with respect to a good. For example, for:\n\n\\(f=2(x-1)^2-10\\)\n\n\\(\\dfrac{\\delta f}{\\delta x}=4x-1\\)\n\nThis last term is the marginal utility of \\(x\\), often shown as \\(MU_x\\).\n\n\n\\subsubsection{Solving}\n\n", "meta": {"hexsha": "3a281f1dcb8691b2aab2f621ba489f696a360e9f", "size": 1007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/singleAgent/03-01-continuousContinuity.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/03-01-continuousContinuity.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/03-01-continuousContinuity.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.46875, "max_line_length": 300, "alphanum_fraction": 0.7606752731, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6717799077467765}}
{"text": "\\section{Statistics}\n\n\\begin{definition}[Bernoulli distribution]\\label{bernoulli}\n    A distribution of parameters, where $\\forall x, 0 \\leq x \\leq 1$,\n    Typically dual, e.g.\\ in coin toss there is heads and tails.\n    If $\\Pr_{heads} = k$, then $\\Pr_{tails} = 1 - \\Pr_{heads}$\n\\end{definition}\n\n\\begin{definition}[Bigvee]\n    $\\bigvee\\limits_{a \\in I} P_{a}$ says that at least one $P_{a}$ is true.\n    It can also be used for the maximum value in a set.\n\\end{definition}\n\n\\begin{definition}[Central moment]\n    The distribution of variable $[$values$]$ around the mean. \n    This way, you can now if the distribution is spread out or not.\n\n\\end{definition}\n\n\\begin{definition}[Cauchy distribution] \n    A family of distributions with no expected value.\n    They usually look like:\n\n    \\includegraphics[scale=.5]{cau.png}\n\n\\end{definition}\n\n\\begin{definition}[Chernoff bound]\\label{chernoff}\n    In a nutshell, it determines a bound on how many times we must perform\n    a trial to know that our random variables represent a majority.\n    E.g.\\ if we trying to determine that a coin is biased (heads/tails),\n    a chernoff bound will say how many times we must flip the coin to know\n    that we have unraveled a bias. In this case, for example, simply flipping it\n    twice will not suffice.\n\\end{definition}\n\n\\begin{definition}[Conditional expectations]\n    $$\n        E(X | Y=y) = \\sum\\limits_{x \\in X} x \\\n        P(X=x | Y=y) = \\sum_{x \\in X} x \n        \\frac{P(X=x,Y=y)}{P(Y = y)}\n    $$\n\\end{definition}\n\n\\begin{definition}[Conditional probability]\n    \\includegraphics[scale=0.3]{prob_form.png}\n\\end{definition}\n\n\\begin{definition}[Covariance]\n    A measure of how much two random variables change together.\n\n\\end{definition}\n\n\\begin{definition}[Expected value]\\label{expectedvalue}\n    $E[X] = \\sum\\limits_{s \\in S}^{\\dots} X(s) \\cdot \\Pr(\\{s\\}) $ \\newline\n    $E[X] = \\sum\\limits_{s \\in S}^{\\dots} X(s) \\cdot \\Pr(X = x) $\n\\end{definition}\n\n\\begin{definition}[hyperplane]\n    A plane (surface) that has one less dimension than it's ambient space,\n    i.e.\\ the space around it. E.g.\\ a hyperplane for 3-d dims is only defined\n    2D.\n\n    A hyperplane will therefore act as a separator. Imagine a holding a \n    square in the middle of a ball.\n\\end{definition}\n\n\\begin{definition}[Gold standard]\nIn medicine and statistics, gold standard test refers to a diagnostic test or\nbenchmark that is the best available under reasonable conditions. It does\nnot have to be necessarily the best possible test for the condition in absolute\nterms. For example, in medicine, dealing with conditions that require an\nautopsy to have a perfect diagnosis, the gold standard test is less accurate\nthan the autopsy.\n\n\\end{definition}\n\n\\begin{definition}[Ground truth]\n    to the accuracy of the training set's classification for supervised\n    learning techniques. This is used in statistical models to prove or\n    disprove research hypotheses. The term \"ground truthing\" refers to the\n    process of gathering the proper objective data for this test.\n\n\\end{definition}\n\n\\begin{definition}[Normal (Gaussian) distribution]\n    A distribution that is centered around a value.\n    E.g.\\ when you collect people's height, there will be many around the\n    average, and fewer and fewer to the sides.\n\n\\end{definition}\n\n\\begin{definition}[Indicator variable]\n    Indicator variable: 0 or 1 for whether an element is selected or not.\n\\end{definition}\n\n\n\\begin{definition}[Linearity of expectation]\\label{lin_expect}\n    $ E[X] + E[Y] = E[X + Y] \\newline\n    [\\sum\\limits_{x \\in S}^{\\dots} X(s) \\cdot \\Pr(X = x) +\n    \\sum\\limits_{y \\in S}^{\\dots} X(s) \\cdot \\Pr(Y = y) ] \\newline\n    = [\\sum\\limits_{s \\in S}^{\\dots} a \\cdot \\Pr(Y = a) + a \\cdot \\Pr(X = a) ]\n    $\n\\end{definition}\n\n\\begin{theorem}[Likelyhood that both X and Y occur in S]\n    $ \\newline E[X] \\cdot E[Y] = E[X \\cdot Y]$\n\\end{theorem}\n\\begin{proof}\n    From~\\nameref{expectedvalue}: \\newline\n    $\n    E[X \\cdot Y] = \\newline \\sum\\limits_{z \\in S}^{\\dots} z \\cdot \n        \\Pr(X = z \\text{ and } Y = z) = \\newline\n    \\sum\\limits_{x \\in S}^{\\dots}\\sum\\limits_{y \\in S}^{\\dots} x \\cdot y\n    \\cdot \\Pr(X = x \\text{ and } Y=y) = \\newline\n    [\\sum\\limits_{x \\in S}^{\\dots} x \\cdot \\Pr(X = x)] \\cdot  \n    [\\sum\\limits_{y \\in S}^{\\dots} y \\cdot \\Pr(Y = y)]  = \\newline\n    E[X] \\cdot E[Y]\n    $\n\\end{proof}\n\n\n\\begin{definition}[Markov Property]\n    Memoryless stochastic process - what happened at point of time X\n    does not matter for times $Y \\geq X$.\n\\end{definition}\n\n\\begin{definition}[Poisson distribution]\n    expresses the probability of a given number of events occurring in a fixed\n    interval of time and/or space if these events occur with a known average\n    rate and independently of the time since the last even.\n\n\\end{definition}\n\n\\begin{definition}[Probability Mass function]\n    A function that gives a probability that a variable is exactly equal to\n    some value.\n\\end{definition}\n\n\\begin{definition}[Supervised learning]\n    the machine learning task of inferring a function from labeled training\n    data. The training data consist of a set of training examples. In\n    supervised learning, each example is a pair consisting of an input object\n    (typically a vector) and a desired output value (also called the\n    supervisory signal).\n\n\\end{definition}\n", "meta": {"hexsha": "9222f098669dd2ab77b226554d3069b70abdd299", "size": 5331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/statistics.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/statistics.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/statistics.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": 36.0202702703, "max_line_length": 80, "alphanum_fraction": 0.6946163947, "num_tokens": 1479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6717798999530713}}
{"text": "\n\\subsection{Determinants}\n\n\nFrom invertible matrix section in endo\n\n\nA matrix can only be inverted if it can be created from a combination of elementary row operations.\n\nHow can we identify if a matrix is invertible? We want to create a scalar from the matrix which tells us if this possible. We can this scalar the determinant.\n\nFor a matrix \\(A\\) we label the determinant \\(|A|\\), or \\(\\det A\\)\n\nWe propose \\(|A|=0\\) when the matrix is not invertible.\n\nSo how can we identify the function we need to undertake on the matrix?\n\n\\subsubsection{New 1}\n\nWe know that linear dependence results in determinants of \\(0\\).\n\nWe can model this as a function on the columns of the matrix.\n\n\\(\\det M = \\det ([M_1, ...,M_n)\\)\n\nIf there is linear depednence, for example if two columns are the same then:\n\n\\(\\det ([M_1,...,M_i,...,M_i,...,M_n])=0\\)\n\nSimilarly, if there is a column of \\(0\\) then the determinant is \\(0\\).\n\n\\(\\det ([M_1,...,0,...,M_n])=0\\)\n\\subsubsection{New 2}\n\nShow linear in addition\n\nHow can we identify the determinant of less simple matrices? We can use the multilinear form.\n\n\\(\\sum c_i\\mathbf M_i=\\mathbf 0\\)\n\nWhere \\(\\mathbf c \\ne \\mathbf 0\\)\n\nOr:\n\n\\(M\\mathbf c=\\mathbf 0\\)\n\\subsubsection{Rule 1: Columns of matrices can be the input to a multilinear form}\n\nA matrix can be shown in terms of its columns.\n\\(A=[v_1,...,v_n]\\)\n\n\\(\\det A=\\det [v_1,...,v_n]\\)\n\n\n\\(\\det A=\\sum_{k_1=1}^m...\\sum_{k_n=1}\\prod_{i=1}^ma_{ik_i}\\det ([e_{k_1},...,e_{k_n}])\\)\n\n\\subsubsection{Multiplying a matrix by a constant multiplies the determinant by the same amount}\n\nIf a whole row or columns is \\(0\\) then:\n\n\\(\\det A=\\det [v_1,...,v_i,...,v_n]\\)\n\n\\(\\det A'=\\det [v_1,...,cv_i,...,v_n]\\)\n\n\n\\(\\det A=\\det [v_1,...,v_i,...,v_n]\\)\n\n\\(\\det A'=\\det [v_1,...,cv_i,...,v_n]\\)\n\n\\(\\det A'=c\\det [v_1,...,v_i,...,v_n]\\)\n\n\\(\\det A'=c\\det A\\)\n\nAs a result, multiplying a column by \\(0\\) makes the determinant \\(0\\).\n\nA matrix with a column of \\(0\\) therefore has determinant \\(0\\)\n\n\\subsubsection{Rule 2: A matrix with equal columns has a determinant of \\(0\\).}\n\n\\(A=[a_1,...,a_i,...,a_i,...,a_n]\\)\n\n\\(D(A)=D([a_1,...,a_i,...,a_i,...,a_n])\\)\n\nWe know from Result 3 that swapping columns reverses the sign. Reversing columns results in the same matrix, so the determinant must be unchanged.\n\n\\(D(A)=-D(A)\\)\n\n\\(D(A)=0\\)\n\n\\subsubsection{Linear dependence}\n\nIf a column is a linear combination of other columns, then the matrix cannot be inverted.\n\n\\(A=[a_1,...,\\sum_{j\\ne i}^{n}c_ja_j,...,a_n]\\)\n\n\\(\\det A=\\det ([v_1,...,\\sum_{j\\ne i}^{n}c_jv_j,...,v_n])\\)\n\n\\(\\det A=\\sum_{j\\ne i}^{n}c_j\\det ([v_1,...,v_j,...,v_n])\\)\n\n\\(\\det A=\\sum_{j\\ne i}^{n}c_j\\det ([v_1,...,v_j,,...,v_j,...,v_n])\\)\n\nAs there is a repeating vector:\n\n\\(\\det A=0\\)\n\n\\subsubsection{Swapping columns multiplies the determinant by \\(-1\\)}\n\n\\(A=[v_1,...,v_i+v_j,...,v_i+v_j,...,v_n]\\)\n\nWe know.\n\n\\(\\det A=0\\)\n\n\\(\\det A=\\det ([a_1,...,a_i,...,a_i,...,a_n])+\\det([a_1,...,a_i,...,a_j,...,a_n])+\\det([a_1,...,a_j,...,a_i,...,a_n])+\\det([a_1,...,a_j,...,a_j,...,a_n])\\)\n\nSo:\n\n\\(\\det ([a_1,...,a_i,...,a_i,...,a_n])+\\det ([a_1,...,a_i,...,a_j,...,a_n])+\\det([a_1,...,a_j,...,a_i,...,a_n])+\\det([a_1,...,a_j,...,a_j,...,a_n])=0\\)\n\nAs \\(2\\) of these have equal columns these are equal to \\(0\\).\n\n\\(\\det ([a_1,...,a_i,...,a_j,...,a_n])+\\det ([a_1,...,a_j,...,a_i,...,a_n])=0\\)\n\n\\(\\det ([a_1,...,a_i,...,a_j,...,a_n])=-\\det ([a_1,...,a_j,...,a_i,...,a_n])\\)\n\n\\subsubsection{Calculating the determinant}\n\nWe have\n\n\\(\\det A=\\sum_{k_1=1}^m...\\sum_{k_n=1}\\prod_{i=1}^ma_{ik_i}\\det ([e_{k_1},...,e_{k_n}])\\)\n\nSo what is the value of the determinant here?\n\nWe know that the determinant of the identity matrix is \\(1\\).\n\nWe know that the determinant of a matrix with identical columns is \\(0\\).\n\nWe know that swapping columns multiplies the determinant by \\(-1\\).\n\nTherefore the determinants where the values of \\(k\\) are not all unique are \\(0\\).\n\nThe determinants of the others are either \\(-1\\) or \\(1\\) depending on how many swaps are required to restore to the identity matrix.\n\nThis is also shown as the Leibni formula.\n\n\\(\\det A = \\sum_{\\sigma \\in S_n}sgn (\\sigma )\\prod_{i=1}^na_{i,\\sigma_i}\\)\n\n", "meta": {"hexsha": "0afc35142b47ae4b75a1d168da53e12508c747ee", "size": 4131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/05-02-linearDeterminants.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/linearSystemsOperations/05-02-linearDeterminants.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/linearSystemsOperations/05-02-linearDeterminants.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.1020408163, "max_line_length": 158, "alphanum_fraction": 0.626724764, "num_tokens": 1449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.8080672043084051, "lm_q1q2_score": 0.6716194525824772}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 5}\n\nDetermine the cost and structure of an optimal binary search tree for a set of $n = 7$ keys with the following probabilities.\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{c|c c c c c c c c}\n$i$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7\\\\\n\\hline\n$p_i$ &      & 0.04 & 0.06 & 0.08 & 0.02 & 0.10 & 0.12 & 0.14\\\\\n$q_i$ & 0.06 & 0.06 & 0.06 & 0.06 & 0.05 & 0.05 & 0.05 & 0.05\\\\\n\\end{tabular}\n\\caption{Probabilities for searching for different nodes}\\label{tab51}\n\\end{table}\n\n\\subsection*{Solution}\n\nTo obtain the expected cost and the form of the optimal binary search tree based on the probabilities given in Table \\ref{tab51}, $w(i,j)$ is calculated based on Equation \\ref{eq51}.\n\n\\begin{equation}\\label{eq51}\n\\begin{aligned}\nw(i,j) &= \\sum_{l = i}^{j} p_l + \\sum_{l = i-1}^{j} q_l\\\\\n&= w(i, j-1) + p_j + q_j\n\\end{aligned}\n\\end{equation}\n\nTable \\ref{tab52} provides $w(i,j)$ for all $0 \\leq j \\leq 7$ and $1 \\leq i \\leq 8$.\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{c c c c c c c c c}\n  & 0    & 1    & 2    & 3    & 4    & 5    & 6    & 7\\\\\\hline\n1 & 0.06 & 0.16 & 0.28 & 0.42 & 0.49 & 0.64 & 0.81 & 1.00\\\\\n2 &      & 0.06 & 0.18 & 0.32 & 0.39 & 0.54 & 0.71 & 0.90\\\\\n3 &      &      & 0.06 & 0.20 & 0.27 & 0.42 & 0.59 & 0.78\\\\\n4 &      &      &      & 0.06 & 0.13 & 0.28 & 0.45 & 0.64\\\\\n5 &      &      &      &      & 0.05 & 0.20 & 0.37 & 0.56\\\\\n6 &      &      &      &      &      & 0.05 & 0.22 & 0.41\\\\\n7 &      &      &      &      &      &      & 0.05 & 0.24\\\\\n8 &      &      &      &      &      &      &      & 0.05\\\\\\hline\n\\end{tabular}\n\\caption{$w(i,j)$ for $0 \\leq j \\leq 7$ and $1 \\leq i \\leq 8$}\\label{tab52}\n\\end{table}\n\nWe now calculate expected search cost $e[i,j]$ for $0 \\leq j \\leq 7$ and $1 \\leq i \\leq 8$.\nWe know that $e[i,j] = q_{i-1}$ when $j = i - 1$.\nFor the general case however where $i \\leq j$, Equation \\ref{eq52} can be used.\n\n\\begin{equation}\\label{eq52}\n\\begin{aligned}\ne[i,j] = \\min_{i \\leq r \\leq j} \\{e[i, r-1] + e[r+1, j] + w(i,j)\\}\n\\end{aligned}\n\\end{equation}\n\nwhere $r$ is the root in the optimal subtree $n_i$ to $n_j$.\nUsing this equation and following the \\textsc{Optimal-BST} algorithm described in the textbook, $e[i, j]$ and $root[i,j]$ are obtained as shown in Table \\ref{tab53} and Table \\ref{tab54}, respectively.\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{c c c c c c c c c}\n  & 0    & 1    & 2    & 3    & 4    & 5    & 6    & 7\\\\\\hline\n1 & 0.06 & 0.28 & 0.50 & 0.76 & 0.90 & 1.18 & 1.50 & 1.86\\\\\n2 &      & 0.06 & 0.30 & 0.56 & 0.70 & 0.98 & 1.30 & 1.66\\\\\n3 &      &      & 0.06 & 0.32 & 0.46 & 0.74 & 1.06 & 1.42\\\\\n4 &      &      &      & 0.06 & 0.30 & 0.46 & 0.78 & 1.14\\\\\n5 &      &      &      &      & 0.05 & 0.24 & 0.62 & 0.98\\\\\n6 &      &      &      &      &      & 0.05 & 0.32 & 0.68\\\\\n7 &      &      &      &      &      &      & 0.05 & 0.34\\\\\n8 &      &      &      &      &      &      &      & 0.05\\\\\\hline\n\\end{tabular}\n\\caption{$e[i,j]$ for $0 \\leq j \\leq 7$ and $1 \\leq i \\leq 8$}\\label{tab53}\n\\end{table}\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{c c c c c c c c c}\n  & 1    & 2    & 3 & 4 & 5 & 6 & 7\\\\\\hline\n1 & 1 & 2 & 3 & 3 & 5 & 6 & 7\\\\\n2 &   & 2 & 3 & 3 & 5 & 6 & 7\\\\\n3 &   &   & 3 & 3 & 5 & 6 & 7\\\\\n4 &   &   &   & 4 & 5 & 6 & 7\\\\\n5 &   &   &   &   & 5 & 6 & 7\\\\\n6 &   &   &   &   &   & 6 & 7\\\\\n7 &   &   &   &   &   &   & 7\\\\\\hline\n\\end{tabular}\n\\caption{$root[i,j]$ for $1 \\leq i,j \\leq 7$}\\label{tab54}\n\\end{table}\n\nAnd the binary tree can now be constructed based on Table \\ref{tab54}, as shown in Figure \\ref{fig51}.\n\n\\begin{figure}[H]\\centering\n\\begin{tikzpicture}[level distance=1.5cm,\n  level 4/.style={sibling distance=3cm},\n  level 5/.style={sibling distance=1.5cm},scale=0.8]\n\\node[circle,draw]{$k_7$}\nchild{\n  node[circle,draw]{$k_6$}\n  child{\n    node[circle,draw]{$k_5$}\n    child {\n      node[circle,draw]{$k_3$}\n      child {\n        node[circle,draw]{$k_2$}\n        child {\n          node[circle,draw]{$k_1$}\n          child {\n            node[circle,draw,fill=black!20]{$d_0$}\n          }\n          child {\n            node[circle,draw,fill=black!20]{$d_1$}\n          }\n        }\n        child {\n          node[circle,draw,fill=black!20]{$d_2$}\n        }\n      }\n      child {\n        node[circle,draw]{$k_4$}\n        child {\n          node[circle,draw,fill=black!20]{$d_3$}\n        }\n        child {\n          node[circle,draw,fill=black!20]{$d_4$}\n        }\n      }\n    }\n    child {\n      node[circle,draw,fill=black!20]{$d_5$}\n    }\n  }\n  child{\n    node[circle,draw,fill=black!20]{$d_6$}\n  }\n}\nchild{\n  node[circle,draw,fill=black!20]{$d_7$}\n};\n\\end{tikzpicture}\n\\caption{Optimal binary search tree based on given probabilities}\\label{fig51}\n\\end{figure}\n\nThe total cost of the tree can also be easily computed using Table \\ref{tab55} given below.\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{c c c c | c c c c}\nnode & depth & probability & contribution & node & depth & probability & contribution\\\\\\hline\n$k_1$ & 5 & 0.04 & 0.24 & $d_0$ & 6 & 0.06 & 0.42\\\\\n$k_2$ & 4 & 0.06 & 0.30 & $d_1$ & 6 & 0.06 & 0.42\\\\\n$k_3$ & 3 & 0.08 & 0.32 & $d_2$ & 5 & 0.06 & 0.36\\\\\n$k_4$ & 4 & 0.02 & 0.10 & $d_3$ & 5 & 0.06 & 0.36\\\\\n$k_5$ & 2 & 0.10 & 0.30 & $d_4$ & 5 & 0.05 & 0.30\\\\\n$k_6$ & 1 & 0.12 & 0.24 & $d_5$ & 3 & 0.05 & 0.20\\\\\n$k_7$ & 0 & 0.14 & 0.14 & $d_6$ & 2 & 0.05 & 0.15\\\\\n      &   &      &      & $d_7$ & 1 & 0.05 & 0.10\\\\\\hline\n\\end{tabular}\n\\caption{$root[i,j]$ for $1 \\leq i,j \\leq 7$}\\label{tab55}\n\\end{table}\n\nBy summing over the contribution of each node, the entire cost of this binary search tree is found to be 3.95.\n", "meta": {"hexsha": "a6be7b32147c7d5027459105866df0cb2ed15768", "size": 5897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q05.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q05.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q05.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": 36.1779141104, "max_line_length": 201, "alphanum_fraction": 0.5058504324, "num_tokens": 2527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.6716194467466209}}
{"text": "\\section{Multiple View Geometry}\n\n\\includegraphics[width=\\columnwidth]{pictures/epipolarplane}\n\nAll points on $\\pi$ project on l and l’\n\n\\includegraphics[width=\\columnwidth]{pictures/epipolarplane2}\n\nepipoles e,e’\n\\begin{itemize}\n\t\\item intersection of baseline with image plane\n\t\\item projection of projection center in other image\n\t\\item vanishing point of camera motion direction\\\\\n\t\\end{itemize}\n\nan epipolar plane ($\\pi$)\n\\begin{itemize}\n\t\\item plane containing baseline (1-D family)\\\\\n\\end{itemize}\n\nan epipolar line ($l$) \n\\begin{itemize}\n\t\\item intersection of epipolar plane with image (always come in corresponding pairs)\\\\\n\\end{itemize}\n\nepipolar lines from motion\n\n\\includegraphics[width=0.8\\columnwidth]{pictures/motion}\n\nparallel motion\n\n\\includegraphics[width=0.8\\columnwidth]{pictures/parallelmotion}\n\nforward motion\n\n\\includegraphics[width=0.4\\columnwidth]{pictures/forwardmotion}\n\n\\subsection{Fundamental matrix}\n\n$$l' = e' \\times x' = e' \\times Hx = Fx$$\n\nThe fundamental matrix F is independent of the point.\n\n\\includegraphics[width=\\columnwidth]{pictures/epipolarplane3}\n\ncorrespondence condition: \n$$x'^TFx=x'^T l'=0$$\n\n\\begin{itemize}\n\t\\item transpose: if F is fundamental matrix for (P,P'), then transp(F) is fundamental matrix for (P',P)\n\t\\item Epipolar lines: l'=Fx and l=transp(F)x'\n\t\\item Epipoles: on all epipolar lines, thus transp(e')Fx=0 for all x therefore transp(e')F = 0, similarly Fe=0\n\t\\item F has 7 DOF i.e. 3x3-1(homogeneous)-1(rank2)\n\t\\item F is a correlation, projective mapping from a point x to a line l'=Fx (not a proper correlation, i.e. not invertible)\n\\end{itemize}\n\nfor pure translation F only has 2 degrees of freedom\n\n\\subsubsection{Eight-Point Algorithm}\nSince the fundamental matrix F is a 3x3 matrix determined up to an arbitrary scale factor, 8 linear equations are required to obtain a unique solution. It is possible with 7.\n\n\\subsection{Essential Matrix}\nfor the calibrated case\n\n5 linear equations are needed.\n\nSame as Fundamental matrix\n\\begin{itemize}\n\t\\item Ep' is the epipolar line associated with p'\n\t\\item transp(E)p is the epipolar line associated with p\n\t\\item Ee'=0 and transp(E)e=0\n\t\\item E is singular\n\\end{itemize}\n\nNew\n\n\\begin{itemize}\n\t\\item E has two equal non-zero singular values\n\\end{itemize}\n\n\n\\subsection{Multi-view geometry}\n\n\n\\subsection{Dealing with Wide FOV Camera}\n\\begin{itemize}\n\t\\item Two-step linear approach to compute radial distortion\n\t\\item estimates distortion polynomial of arbitrary degree\n\\end{itemize}", "meta": {"hexsha": "2be5b98772b539d7e073da6ea7524d2e53d52eb4", "size": 2497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/5_Multiple_View_Geometry.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/5_Multiple_View_Geometry.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/5_Multiple_View_Geometry.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": 28.0561797753, "max_line_length": 174, "alphanum_fraction": 0.7633159792, "num_tokens": 710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430311279742, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6716194274648416}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%   Thesis template by Youssif Al-Nashif\n%\n%   May 2020\n%\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Clustering with Graph Kernels}\n\n\\hspace*{0.3cm} The resulting graph kernel matrix, with dimensions $n \\times n$, is high dimensional data. We can take this kernel and perform a principal component analysis (PCA) to reduce the high dimensionality of this data. Each row, can be considered as an observation, and each column as its similarity value or in the $j$-th graph's dimension. PCA then allows us to express the data in a lower dimensionality, hopefully in 2 or 3 dimensions which can be visualized much better. \\\\\n\nThen, this transformed kernel data is then used in place of a distance matrix for hierarchical clustering. Since the kernel is a similarity kernel, i.e. larger values mean values are closer or more similar, and not a distance kernel, we need to adjust the kernel. The kernel's elements are passed through the function $f(x) = \\frac{1}{x}$ to get the reciprocal value for each similarity value\\textemdash thus converting the value to a value representative of distance. The hierarchical clustering is performed with the manhattan distance: \\\\\n\n\\begin{equation}\nd(\\vec{p},\\vec{q}) = \\sum_{i=1}^n |p_i - q_i|\n\\end{equation}\n\nSince the edge label histograms have entries of either 1 or 0, the manhattan distance was a better match for the space. The hierarchical clustering also uses a linkage method of Ward's method, for minimizing variance. Ward's method is defined as:\\\\\n\n\\begin{equation}\nd(\\vec{p},\\vec{q}) = || \\vec{p} - \\vec{q} ||^2\n\\end{equation}\n\nThe resulting dendrograms are then able to be visualized, analyzed, and cut to form clusters of the documents. In the dendrograms, each document is a ``leaf\", or end of the tree, and each dendrogram represents the corpus as a whole. Clusters are then formed when the tree is ``cut\" at some height; the clusters are then what are of interest to the researcher, as they are the result of this unsupervised learning method. ", "meta": {"hexsha": "3077767498f0f424135e5af279145def279816e9", "size": 2014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis_Tex/Content/02_Chapters/Chapter 03/Sections/03_HClust.tex", "max_stars_repo_name": "Levi-Nicklas/GraphDocNLP", "max_stars_repo_head_hexsha": "dec1acb24a2ab42b46d161c92b69ad3a55fcc5ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-27T02:08:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-27T02:08:34.000Z", "max_issues_repo_path": "Thesis_Tex/Content/02_Chapters/Chapter 03/Sections/03_HClust.tex", "max_issues_repo_name": "Levi-Nicklas/GraphDocNLP", "max_issues_repo_head_hexsha": "dec1acb24a2ab42b46d161c92b69ad3a55fcc5ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-02-18T16:07:14.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-25T14:18:51.000Z", "max_forks_repo_path": "Thesis_Tex/Content/02_Chapters/Chapter 03/Sections/03_HClust.tex", "max_forks_repo_name": "Levi-Nicklas/GraphDocNLP", "max_forks_repo_head_hexsha": "dec1acb24a2ab42b46d161c92b69ad3a55fcc5ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.56, "max_line_length": 541, "alphanum_fraction": 0.7472691162, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6715914975312814}}
{"text": "\\section{Stochastic Gradient Descent (SGD)}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{SGD: Intro}\n\nWHAT:\\\\\nStochastic Gradient Descent (SGD);\n\\vspace{5mm}\n\nWHY:\\\\\ndo not know $D$, so do not know the gradient of $L_D(w)$.\n\\vspace{5mm}\n\nHOW:\\\\\ntake a step along a \\textbf{random} direction (vector), as long as \\\\\nits \\textbf{expected value} at each iteration will \\textbf{equal the gradient direction} \\\\\n(more generally, a subgradient of the function at the current vector)\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{SGD: Intro}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{fig_14_3}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{SGD: Intro}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.325]{sgd}\n\\end{figure}\n\n\\end{frame}\n\n\n\n\\begin{frame}\n\\frametitle{SGD: Analysis for Convex-Lipschitz-Bounded Fn}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.2]{theorem_14_8}\n\\end{figure}\n\n\\end{frame}\n", "meta": {"hexsha": "7482dd69c826a9f64c7978c84d1a98ce11125fa3", "size": 986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/cvx-sgd-20180316/stoc_gradient_descent.tex", "max_stars_repo_name": "tttor/robot-foundation", "max_stars_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk/tor/cvx-sgd-20180316/stoc_gradient_descent.tex", "max_issues_repo_name": "tttor/robot-foundation", "max_issues_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk/tor/cvx-sgd-20180316/stoc_gradient_descent.tex", "max_forks_repo_name": "tttor/robot-foundation", "max_forks_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.9615384615, "max_line_length": 91, "alphanum_fraction": 0.7231237323, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6715914813348725}}
{"text": "\\chapter{}\n\n\\rmk{1} In general, for any sampling distribution, there is a natural family of prior distributions, called the conjugate family. For a class of distributions \\(\\mathcal{P}=\\{f(\\mathbf{x} \\mid \\theta)\\}_{\\theta \\in \\Theta}\\), a class \\(\\Pi\\) of priors is called a conjugate family for \\(\\mathcal{P}\\) if the posterior is in the class \\(\\Pi\\) for any \\(\\theta \\in \\Theta\\), all priors in \\(\\Pi\\) and all \\(x \\in \\mathcal{X}\\).\n\n\\begin{ex}\n    An experiment consists in flipping a coin independently \\(n\\) times, i.e., the total number of successes \\(X\\) follows a \\(B(n, \\theta)\\) distribution. Suppose \\(\\theta \\sim U[0,1]\\) is our prior distribution (which is quite uninformative/conservative). Show that\n    \\[\n        \\theta \\mid x \\sim \\operatorname{Beta}(x+1, n-x+1). \n    \\]\n\\end{ex}\n\n\\begin{solution}\n    From Bayes' theorem, \n    \\begin{align*}\n        p(\\theta|x) &= \\frac{p(x|\\theta)p(\\theta)}{\\int p(x|\\theta) \\der x} \\\\\n        &\\propto p(x|\\theta)p(\\theta) \\\\\n        &\\propto \\binom{n}{x} \\theta^x(1-\\theta)^{n-x}\\\\\n        &\\propto \\theta^x(1-\\theta)^{n-x}. \n    \\end{align*}\n    So, $\\theta|x\\sim Beta(x+1, n-x+1)$. \n\\end{solution}\n\n\\begin{ex}\n    Suppose we collect a sample \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\operatorname{Poi}(\\lambda), \\lambda>0\\). Develop the posterior distribution \\(\\lambda \\mid \\mathbf{x}\\) when the prior is given by \\(\\lambda \\sim \\Gamma(\\alpha, \\nu)\\), i.e.,\n    \\[\n        \\pi(\\lambda)=\\frac{\\nu^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\alpha-1} e^{-\\nu \\lambda}. \n    \\]\n\\end{ex}\n\n\\begin{solution}\n    Because $x_i\\sim Poi(\\lambda)$, \n    \\[\n        f(\\mathbf{x}|\\lambda) = \\frac{e^{-n\\lambda}\\lambda^{\\sum x_i}}{\\prod x_i!}. \n    \\]\n    \\begin{align*}\n        p(\\theta|x) &= \\frac{p(x|\\theta)p(\\theta)}{\\int p(x|\\theta) \\der x} \\\\\n        &\\propto p(x|\\theta)p(\\theta) \\\\\n        &\\propto \\frac{e^{-n\\lambda}\\lambda^{\\sum x_i}}{\\prod x_i!} \\frac{\\lambda^{\\alpha-1}v^\\alpha e^{-v\\lambda}}{\\Gamma(\\alpha)} \\\\\n        &\\propto \\lambda^{\\sum x_i+\\alpha-1} e^{-\\lambda (n+v)}.\n    \\end{align*}\n    So, $\\lambda|\\mathbf{x}\\sim \\Gamma(\\sum x_i +\\alpha, n+v)$. \n\\end{solution}\n\n\\begin{ex}\n    We saw in class the following example. Suppose \\(\\Theta=\\mathcal{A}=\\mathbb{R}, L(\\theta, a)=(\\theta-a)^{2}\\) and \\(X \\mid \\theta=t \\sim \\mathcal{N}(t, 1)(n=1\\) observation \\() .\\) Then, it is clear that the decision rule \\(d_{\\mathrm{ML}}(X)=X\\) is the ML estimator of \\(\\theta\\). In this problem, we show that \\(d_{\\mathrm{ML}}(X)\\) is not a Bayes rule, irrespective of the prior. By contradiction, suppose it is. \n    \\begin{enumerate}[(a)]\n        \\item Show that\n        \\[\n            r\\left(\\pi, d_{\\mathrm{ML}}(X)\\right)<\\infty\n        \\]\n        \\item Conclude that \\(d_{\\mathrm{ML}}(X)=\\mathbb{E}(\\theta \\mid X)\\). \n        \\item On one hand, show that\n        \\[\n        \\mathbb{E}\\left[\\theta d_{\\mathrm{ML}}(X)\\right]=\\mathbb{E} d_{\\mathrm{ML}}^{2}(X)\n        \\]\n        (hint: condition on \\(X\\) ). \n        \\item  On the other hand, show that\n        \\[\n        \\mathbb{E}\\left[\\theta d_{\\mathrm{ML}}(X)\\right]=\\mathbb{E} \\theta^{2}\n        \\]\n        (hint: condition on \\(\\theta\\) ).\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item From the definition, for some prior distribution $\\pi$, $r(\\pi, d_{\\mathbf{ML}})$ is bayes risk. So, \n        \\[\n            r(\\pi, d_{\\mathrm{ML}}(X)) = \\inf_{d\\in D^\\star} r(\\pi, d)<\\infty. \n        \\]\n        \\item \n    \\end{enumerate}\n\\end{solution}\n\n\n\\begin{ex}\n    Let \\(\\mathbf{X} \\sim f_{X}(\\mathbf{x} \\mid \\theta), \\pi(d \\theta)=\\pi(\\theta) d \\theta\\) be a.c. distributions, and let \\(T\\) be a sufficient statistic for \\(\\theta\\) with a.c. density function \\(g(t \\mid \\theta) d t\\) and a.c. marginal density \\(f_{T}(t)\\). Suppose the factorization theorem holds. Show that\n\\[\n\\pi(\\theta \\mid \\mathbf{x})=\\pi(\\theta \\mid t)=\\frac{\\pi(\\theta) g(t \\mid \\theta)}{f_{T}(t)}\n\\]\n(n.b.: the reason for determining \\(\\pi(\\theta \\mid \\mathbf{x})\\) from a sufficient statistic is that \\(g(t \\mid \\theta)\\) and \\(f_{T}(t)\\) are usually easier to handle than \\(f_{X}(\\mathbf{x} \\mid \\theta)\\) and the marginal \\(f_{\\mathbf{X}}(\\mathbf{x})\\) - see next problem).\n\\end{ex}\n\n\n5. Assume \\(\\mathbf{X}=\\left(X_{1}, \\ldots, X_{n}\\right) \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\theta, \\sigma^{2}\\right)\\), where \\(\\theta\\) is unknown but \\(\\sigma^{2}\\) is known. Let the prior distribution \\(\\pi(\\theta)\\) be a \\(\\mathcal{N}\\left(\\mu, \\tau^{2}\\right)\\) density, where \\(\\mu\\) and \\(\\tau^{2}\\) are known. Show that\n\\[\n\\theta \\mid \\mathbf{x} \\sim \\mathcal{N}\\left(\\mu(\\mathbf{x}), \\rho^{-1}\\right)\n\\]\nwhere\n\\[\n\\rho=\\frac{n \\tau^{2}+\\sigma^{2}}{\\tau^{2} \\sigma^{2}}, \\quad \\mu(\\mathbf{x})=\\frac{\\sigma^{2} / n}{\\tau^{2}+\\sigma^{2} / n} \\mu+\\frac{\\tau^{2}}{\\tau^{2}+\\sigma^{2} / n} \\bar{x}\n\\]\n(hint: use the previous problem and show that\n\\[\n\\frac{(\\theta-\\mu)^{2}}{\\tau^{2}}+\\frac{(t-\\theta)^{2}}{\\sigma^{2} / n}=\\rho\\left[\\theta-\\frac{1}{\\rho}\\left(\\frac{\\mu}{\\tau^{2}}+\\frac{t}{\\sigma^{2} / n}\\right)\\right]^{2}+\\frac{(\\mu-t)^{2}}{\\left(\\sigma^{2} / n+\\tau^{2}\\right)}\n\\]\nNote that \\(f_{T}(t)\\) plays no role in determining the nature of \\(\\left.\\pi(\\theta \\mid \\mathbf{x})\\right)\\).\n6. If \\(S^{2}\\) is the sample variance based on sample of size \\(n\\) from a Normal population, we know that \\(\\frac{(n-1) S^{2}}{\\sigma^{2}} \\sim \\chi_{n-1}^{2}\\). The conjugate prior for \\(\\sigma^{2}\\) is the inverse Gamma distribution \\(I G(\\alpha, \\lambda)\\), which is given by\n\\[\n\\pi\\left(\\sigma^{2} \\mid \\alpha, \\lambda\\right)=\\frac{\\lambda^{\\alpha}}{\\Gamma(\\alpha)}\\left(\\sigma^{2}\\right)^{-\\alpha-1} e^{-\\lambda / \\sigma^{2}} 1_{\\left\\{0<\\sigma^{2}<\\infty\\right\\}}, \\quad \\alpha, \\lambda>0\n\\]\n(a) Show that the posterior distribution of \\(\\sigma^{2}\\) is \\(I G\\left(\\alpha+\\frac{n-1}{2}, \\frac{(n-1) S^{2}}{2}+\\lambda\\right)\\).\n(b) Find the Bayes estimator of \\(\\sigma^{2}\\) assuming quadratic error loss.\n7. Please answer the following questions.\n(a) Show that \\(\\operatorname{Beta}(\\alpha, \\beta)\\) is a conjugate family for \\(B(n, p)\\). In other words, if \\(X \\sim B(n, p)\\) and we assume a prior distribution \\(p \\sim \\operatorname{Beta}(\\alpha, \\beta)\\), then \\(p \\mid X\\) also follows a Beta distribution.\n(b) In the situation described in (a), compute the Bayes rule (estimator of \\(p\\) ) assuming a quadratic loss function.", "meta": {"hexsha": "02e46d807b9ef910b36bf33fb9fa6f86e6587a45", "size": 6371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/Set9.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/Set9.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/Set9.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": 60.1037735849, "max_line_length": 425, "alphanum_fraction": 0.5923716842, "num_tokens": 2241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6714519764783045}}
{"text": "\n\\subsection{Structural supply and demand functions}\n\nSupply:\n\n\\(Q_s=\\alpha_1 + \\beta_1P+\\gamma_1I + \\epsilon_1\\)\n\nDemand:\n\n\\(Q_d=\\alpha_2 + \\beta_2P+\\gamma_2I + \\epsilon_2\\)\n\nCan't estimate because the equations are simulataneous.\n\n", "meta": {"hexsha": "1868a5add7761870eea87f6a7c57bf66053efb56", "size": 233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/02-01-structural.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/02-01-structural.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/02-01-structural.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.6428571429, "max_line_length": 55, "alphanum_fraction": 0.7339055794, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6714511268728574}}
{"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 19, 2014}\n\\maketitle\n\\section*{assignment}\nnumber of cycles of length  $n$ in $S_n$ is $(n-1)!$ because you fix the first entry to eliminate duplicates.\n\nnumber of cycles of length $m$ of $S_n$. pick $\\binom{n}{m}$ for the first element. $\\binom{n}{m}m!/m=\\frac{n!}{(n-m)!}\\frac{1}{m}$\n\n\\#12\n\n(ab) is odd, length three cycles are even, two evens multiplied together is even.\n\n\\section*{3.1 groups}\n$S$ is a set.\n\\subsubsection*{definiton}a binary operation on $S$ is a function $S\\times S\\to S$, or $(x,y)\\to x*y$\n\ninteresting binary operations satisfy: associativity, identity($\\exists e\\in S$ such that $x*e=e*x=x$), inverse ($a*b=b*a=e$). if an element has an inverse, we say that it is invertible.\n\n\\section*{example}\n$\\mathbb{Z}$ with binary operation is usual addition, $(\\mathbb{Z},+)$, then it is associative, $0$ is identity, and all elements are invertible.\n\n$(2\\mathbb{Z},+)$, nothing is different\n\n$(2\\mathbb{Z},\\cdot)$. No identity element.o\n\n$(2\\mathbb{Z}+1,+)$, this operation is not closed, it's not a binary operation.\n\n\\section*{propostion}\nlet $*$ be an associative opertion on $S$, let $a,b,c\\in S$ be invertible elements. then\n\\begin{enumerate}\n\\item\nthe $*$ operation has at most one identity element\n\\item\nif it has an identity elemen, then an element a in S has at most one inverse.\n\\end{enumerate}\n\\subsubsection*{proof}\nassume that $e,e'$ identity elements, $x\\star e=e\\star x=x$ and $x\\star e'=e'\\star x=x$for all $x\\in S$.\n\ntake $x=e'$ then $e'=e'\\star e=e$\n\nnow if $a$ has two inverses $b,b'$ then $b=b\\star e=b\\star (a\\star b')=(b\\star a)\\star b'=e\\star b'=b'$\n\n\\section*{propostion}\nlet $*$ be an associative opertion on $S$, let $a,b,c\\in S$ be invertible elements. then\n\\begin{enumerate}\n\\item\n$a^{-1}$ is invertible\n\n$a\\star a^{-1}=a^{-1}\\star a=e$\n\\item\n$a\\star b$ is invertible and $(a\\star b)^{-1}=a^{-1}\\star b^{-1}$.\n\n$(a*b)*(b^{-1}*a^{-1})=a*e*a^{-1}=e$ and similarly $(b^{-1}*a^{-1})*(a*b)=e$\n\\end{enumerate}\n\n\\section*{definition of group}\nlet $G$ be a set and $\\star$ be a binary operation on $G$. we say that $(G,\\star)$ is a group if\n\\begin{enumerate}\n\\item\n$\\star$ is associative\n\\item\n$\\star$ as an identity element\n\\item\nevery element of $G$ is invertible.\n\\end{enumerate}\n\\subsubsection*{examples}\n$(\\mathbb{Z},+)$ is a group, $(\\mathbb{Z},\\cdot)$ is not, $(\\mathbb{Q},\\cdot)$ is not because zero is not invertible, $(\\mathbb{Q}*,\\cdot)$ is because the $*$ means throw out zero. $(S_n,\\circ)$ where $\\circ$ is a permutation, is a group, $(\\mathbb{Z}_n,+)$ is a group. $\\mathbb{Z}_n^*$ is all the elements of $\\mathbb{Z}_n^*$ is all elements of $\\mathbb{Z}_n$ that are invertible\n\n\\section*{proposition}\n$(G,*)$ is a group, and $a,b,c\\in G$ thenn if $ab=ac$ then $b=c$ and if $ba=ca$ then $b=c$\n\n$a^{-1}ab=a^{-1}ac=b=c$\n\n\\section*{abelian groups (commutative groups)}\na group $(G,*)$ is called abelian if $*$ is commutative.\n\nfor example $(S_n,\\circ)$ is not abelian.\n\nanother example is $GL_n(\\mathbb{R})$ the invertible $n\\times n$ matrices with entries in $\\mathbb{R}$. $(GL_n(\\mathbb{R}),\\cdot)$ is not commutative.\n\n\n\\end{document}\n\n", "meta": {"hexsha": "be21f1cd45a27fd5dc92c97baf8c7623f3b073c7", "size": 3329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-09-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": "abstract algebra/abstract-notes-2014-09-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": "abstract algebra/abstract-notes-2014-09-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": 35.0421052632, "max_line_length": 380, "alphanum_fraction": 0.6731751277, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6713531228553767}}
{"text": "\\section{Dynamical System Scaling}\n\\label{sec:dssdoc}\n\nThe DSS approach to system scaling is based on transforming the typical view of processes to a special coordinate system in terms of the parameter of interest and its agents of change \\cite{DSS2015}.\nBy parameterizing using a time term that will be introduced later in this section, data reproduced can be converted to the special three coordinate system (also called the phase space)\nand form a geometry with curves along the surface containing invariant and intrinsic properties. The remainder of this section is a review of DSS theory introduced in publications\nby Reyes \\cite{DSS2015,Reyes2015,Martin2019} and is used in this analysis for FR scaling. The parameter of interest is defined to be a conserved quantity within a control volume:\n\\begin{equation}\n  \\label{eq_1}\n  \\beta(t)=\\frac{1}{\\Psi_{0}}\\iiint_{V}{\\psi\\left(\\vec{x},t\\right)}dV\n\\end{equation}\n$\\beta$ is defined as the volume integral of the time and space dependent conserved quantity $\\psi$ normalized by a time-independent value, $\\Psi_{0}$, that characterizes the process. The agents of change are defined as the first derivative of the normalized parameter of interest:\n\\begin{equation}\n  \\label{eq_2}\n  \\omega=\\frac{1}{\\Psi_{0}}\\frac{d}{dt}\\iiint_{V}{\\psi\\left(\\vec{x},t\\right)}dV=\\iiint_{V}{\\left(\\phi_{v}+\\phi_{f}\\right)}dV+\\iint_{A}{\\left(\\vec{j}\\cdot\\vec{n}\\right)}dA-\\iint_{A}{\\psi\\left(\\vec{v}-\\vec{v}_{s}\\cdot\\vec{n}dA\\right)}dA\n\\end{equation}\nThe change is categorized into three components; volumetric, surface, and quantity transport. The agents of change is also the sum of the individual agent of change:\n\\begin{equation}\n  \\omega=\\frac{1}{\\Psi_{0}}\\frac{d}{dt}\\iiint_{V}{\\psi\\left(\\vec{x},t\\right)}dV=\\sum^{n}_{i=1}{\\omega_{i}}\n\\end{equation}\nThe relation of $\\omega$ and $\\beta$ is the following:\n\\begin{equation}\n  \\label{eq_3}\n  \\omega(t)=\\left.\\frac{d\\beta}{dt}\\right|_{t}=\\sum^{n}_{i=1}{\\omega_{i}}\n\\end{equation}\nWhere $\\omega$ is the first derivative of reference time. As defined in Einstein and Infeld, time is a value stepping in constant increments \\cite{Einstein1966}. The process dependent term in DSS is called process time:\n\\begin{equation}\n  \\label{eq_4}\n  \\tau(t)=\\frac{\\beta(t)}{\\omega(t)}\n\\end{equation}\nTo measure the progression difference between reference time and process time in respect to reference time, the idea of temporal displacement rate (D) is adopted:\n\\begin{equation}\n  \\label{eq_5}\n  D=\\frac{d\\tau-dt}{dt}=-\\frac{\\beta}{\\omega^{2}}\\frac{d\\omega}{dt}\n\\end{equation}\nThe interval of process time is:\n\\begin{equation}\n  \\label{eq_8}\n  d\\tau=\\tau_{s}=\\left(1+D\\right)dt\n\\end{equation}\nApplying the process action to normalize the phase space coordinates gives the following normalized terms:\n\\begin{equation}\n  \\label{eq_10}\n  \\tilde{\\Omega}=\\omega\\tau_{s},\\qquad \\tilde{\\beta}=\\beta,\\qquad \\tilde{t}=\\frac{t}{\\tau_{s}},\\qquad \\tilde{\\tau}=\\frac{\\tau}{\\tau_{s}},\\qquad\n  \\tilde{D}=D\n\\end{equation}\nThe scaling relation between the prototype and model can be defined both for $\\beta$ and $\\omega$ and represents the scaling of the parameter of interest and the corresponding agents of change (or frequency given from the units of per time):\n\\begin{equation}\n  \\label{eq_11}\n  \\lambda_{A}=\\frac{\\beta_{M}}{\\beta_{P}},\\qquad \\lambda_{B}=\\frac{\\omega_{M}}{\\omega_{P}}\n\\end{equation}\nThe subscripts $M$ and $P$ stand for the model and prototype. Applying these scaling ratios to equations (\\ref{eq_4}), (\\ref{eq_5}), and (\\ref{eq_10}) provides the scaling ratios for other parameters as well:\n\\begin{equation}\n  \\label{eq_12}\n  \\frac{t_{M}}{t_{P}}=\\frac{\\lambda_{A}}{\\lambda_{B}},\\qquad \\frac{\\tau_{M}}{\\tau_{P}}=\\frac{\\lambda_{A}}{\\lambda_{B}},\\qquad \\frac{\\tilde{\\beta}_{M}}{\\tilde{\\beta}_{P}}=\\lambda_{A},\\qquad \\frac{\\tilde{\\Omega}_{M}}{\\tilde{\\Omega}_{P}}=\\lambda_{A},\\qquad \\frac{\\tilde{\\tau}_{M}}{\\tilde{\\tau}_{P}}=1,\\qquad \\frac{D_{M}}{D_{P}}=1\n\\end{equation}\nNormalized agents of change is the sum in the same respect:\n\\begin{equation}\n  \\label{eq_18}\n  \\Omega=\\sum^{k}_{i=1}{\\Omega_{i}}\n\\end{equation}\nThe ratio of $\\Omega$ is expressed in the following alternate form:\n\\begin{equation}\n  \\label{eq_19}\n  \\Omega_{R}=\\frac{\\Omega_{M}}{\\Omega_{P}}=\\frac{\\sum^{k}_{i=1}{\\Omega_{M,i}}}{\\sum^{k}_{i=1}{\\Omega_{P,i}}}=\\frac{\\Omega_{M,1}+\\Omega_{M,2}+...+\\Omega_{M,k}}{\\Omega_{P,1}+\\Omega_{P,2}+...+\\Omega_{P,k}}\n\\end{equation}\nBy the law of scaling ratios, The following must be true:\n\\begin{equation}\n  \\label{eq_13}\n  \\lambda_{A}=\\frac{\\Omega_{M,1}}{\\Omega_{P,1}},\\lambda_{A}=\\frac{\\Omega_{M,2}}{\\Omega_{P,2}},...,\\lambda_{A}=\\frac{\\Omega_{M,k}}{\\Omega_{P,k}}\n\\end{equation}\nDepending on the scaling ratio values, From Reyes, the scaling methods and similarity criteria is subdivided into five categories; 2-2 affine, dilation, $\\beta$-strain, $\\omega$-strain, and identity \\cite{DSS2015}.\nTable \\ref{DSS:table_1} summarizes the similarity criteria. Despite the five categories, in essence, all are 2-2 affine with exceptions of partial scaling ratios values being 1.\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|c|c|c|c}\n\\hline\n%\\rowcolor{lightgray}\n\\multicolumn{5}{c}{Basis for Process Space-time Coordinate Scaling}\\\\\n\\hline\nMetric & \\multirow{2}{*}{$d\\tilde{\\tau}_{P}=d\\tilde{\\tau}_{P}$} & \\multirow{2}{*}{And} & Covariance & \\multirow{2}{*}{$\\frac{1}{\\omega_{P}}\\frac{d\\beta_{P}}{dt_{P}}=\\frac{1}{\\omega_{M}}\\frac{d\\beta_{M}}{dt_{M}}$} \\\\\nInvariance   & & & Principle & \\\\\n\\hline\n\\multicolumn{5}{c}{$\\beta-\\omega$ Coordinate Transformations}\\\\\n\\hline\n2-2 Affine  & Dilation  & $\\beta$-Strain & $\\omega$-Strain & Identity \\\\\n$\\beta_{R}=\\lambda_{A}$ & $\\beta_{R}=\\lambda$ & $\\beta_{R}=\\lambda_{A}$ & $\\beta_{R}=1=\\lambda_{B}$ & $\\beta_{R}=1$ \\\\\n$\\omega_{R}=\\lambda_{B}$ & $\\omega_{R}=\\lambda$ & $\\omega_{R}=1$ & $\\omega_{R}=\\lambda_{B}$ & $\\omega_{R}=1$ \\\\\n\\hline\n\\multicolumn{5}{c}{Similarity Criteria}\\\\\n\\hline\n$\\tilde{\\Omega}_{R}=\\lambda_{A}$ & $\\tilde{\\Omega}_{R}=\\lambda$ & $\\tilde{\\Omega}_{R}=\\lambda_{A}$ & $\\tilde{\\Omega}_{R}=1$ & $\\tilde{\\Omega}_{R}=1$ \\\\\n$\\tau_{R}=t_{R}=\\frac{\\lambda_{A}}{\\lambda_{B}}$ & $\\tau_{R}=t_{R}=1$ & $\\tau_{R}=t_{R}=\\lambda_{A}$ & $\\tau_{R}=t_{R}=\\frac{1}{\\lambda_{B}}$ & $\\tau_{R}=t_{R}=1$ \\\\\n\\hline\n\\end{tabular}\n\\caption{Scaling Methods and Similarity Criteria Resulting from Two-Parameter Transformations \\cite{DSS2015}}\\label{DSS:table_1}\n\\end{table}\nThe separation between both process curves along the constant normalized process time is the local distortion \\cite{Martin2019}:\n\\begin{equation}\n  \\label{eq_15}\n  \\tilde{\\eta}_{k}=\\beta_{P_{k}}\\sqrt{\\varepsilon D_{P_{k}}}\\left[\\frac{1}{\\Omega_{P_{k}}}-\\frac{\\lambda_{A}}{\\Omega_{M_{k}}}\\right]\n\\end{equation}\nWhere $\\epsilon$ is a sign adjuster ensuring positive values within the square root. The total distortion is:\n\\begin{equation}\n  \\label{eq_16}\n  \\tilde{\\eta}_{T}=\\sum^{N}_{k=1}{\\left|\\tilde{\\eta}_{k}\\right|}\n\\end{equation}\nAnd, the equivalent standard deviation is:\n\\begin{equation}\n  \\label{eq_17}\n  \\sigma_{est}=\\sqrt{\\frac{1}{N}\\sum^{N}_{k=1}{\\tilde{\\eta}^{2}_{k}}}\n\\end{equation}\n\n", "meta": {"hexsha": "c55994f19281c589e1e43df77ae87f1bd8834ac8", "size": 7067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory_manual/dssPostProcessor.tex", "max_stars_repo_name": "FlanFlanagan/raven", "max_stars_repo_head_hexsha": "bd7fca18af94376a28e2144ba1da72c01c8d343c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 159, "max_stars_repo_stars_event_min_datetime": "2017-03-24T21:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:44:40.000Z", "max_issues_repo_path": "doc/theory_manual/dssPostProcessor.tex", "max_issues_repo_name": "FlanFlanagan/raven", "max_issues_repo_head_hexsha": "bd7fca18af94376a28e2144ba1da72c01c8d343c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1667, "max_issues_repo_issues_event_min_datetime": "2017-03-27T14:41:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T19:50:06.000Z", "max_forks_repo_path": "doc/theory_manual/dssPostProcessor.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": 61.9912280702, "max_line_length": 326, "alphanum_fraction": 0.7004386586, "num_tokens": 2387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.6713531170168324}}
{"text": "\\subsection{Trigonometric functions}\\label{subsec:trigonometric_functions}\n\n\\begin{definition}\\label{def:trigonometric_functions}\n  We define the two basic \\term{trigonometric functions}. They are also called \\term{circular trigonometric functions} to distinguish them from the hyperbolic trigonometric functions defined and motivated in \\fullref{def:hyperbolic_trigonometric_functions}.\n\n  \\begin{thmenum}\n    \\thmitem{def:trigonometric_functions/sine} The \\term{sine} function, also called the \\term{sinus} function, is\n    \\begin{equation*}\n      \\sin(z)\n      \\coloneqq\n      -i \\sum_{m \\text{ is odd}}^\\infty \\frac {i^m z^m} {m!}\n      =\n      -i \\sum_{k=0}^\\infty \\frac {i^{2k+1} z^{2k+1}} {(2k + 1)!}\n      =\n      \\sum_{k=0}^\\infty \\frac {i^{2k} z^{2k+1}} {(2k + 1)!}\n    \\end{equation*}\n\n    \\thmitem{def:trigonometric_functions/cosine} The \\term{cosine} function, also called the \\term{cosinus} function, is\n    \\begin{equation*}\n      \\cos(z)\n      \\coloneqq\n      \\sum_{m \\text{ is even}}^\\infty \\frac {i^m z^m} {m!}\n      =\n      \\sum_{k=0}^\\infty \\frac {i^{2k} z^{2k}} {(2k)!}.\n    \\end{equation*}\n  \\end{thmenum}\n\n  \\Fullref{def:geometric_trigonometric_functions} justifies the term \\enquote{angle} for the \\hyperref[def:multi_valued_function/arguments]{parameter} of the trigonometric functions.\n\\end{definition}\n\\begin{proposition}\\label{thm:def:trigonometric_function}\n  The \\hyperref[def:trigonometric_functions]{main trigonometric functions} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:trigonometric_function/convergence} Both \\( \\sin(z) \\) and \\( \\cos(z) \\) converge in the entire complex plane.\n    \\thmitem{thm:def:trigonometric_function/parity} \\( \\sin(z) \\) is an odd function and \\( \\cos(z) \\) is an even function.\n    \\thmitem{thm:def:trigonometric_function/derivative} \\( \\sin'(z) = \\cos(z) \\) and \\( \\cos'(z) = -\\sin(z) \\) for all \\( z \\in \\BbbC \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:trigonometric_function/convergence} Note that the zero coefficients in the expansion of either \\( \\sin \\) or \\( \\cos \\) do not alter convergence. Therefore, by \\fullref{thm:power_series_radius_of_convergence}, the radius of convergence is\n  \\begin{equation*}\n    \\limsup_{k \\to \\infty} \\frac {\\abs{i^{k-1} k!}} {\\abs{i^k (k-1)!}}\n    =\n    \\limsup_{k \\to \\infty} k\n    =\n    +\\infty.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:trigonometric_function/parity} Follows from \\fullref{thm:power_series_parity}.\n\n  \\SubProofOf{thm:def:trigonometric_function/derivative} Follows from \\fullref{thm:power_series_are_locally_uniform_convergent} and \\fullref{thm:derivative_limit_exchange}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:trigonometric_identities}\n  We have the following basic trigonometric identities:\n  \\begin{thmenum}\n    \\thmitem{thm:trigonometric_identities/pythagorean_identity} (Pythagorean identity) For any \\( z \\in \\BbbC \\),\n    \\begin{equation}\\label{eq:thm:trigonometric_identities/pythagorean_identity}\n      \\sin(z)^2 + \\cos(z)^2 = 1.\n    \\end{equation}\n\n    \\thmitem{thm:trigonometric_identities/products} (Products) For \\( x, y \\in \\BbbC \\),\n    \\begin{balign}\n      2 \\sin(x) \\sin(y) & = \\cos(x - y) - \\cos(x + y) \\label{eq:thm:trigonometric_identities/products/ss}  \\\\\n      2 \\cos(x) \\cos(y) & = \\cos(x - y) + \\cos(x + y) \\label{eq:thm:trigonometric_identities/products/cc}  \\\\\n      2 \\sin(x) \\cos(y) & = \\sin(x - y) + \\sin(x + y) \\label{eq:thm:trigonometric_identities/products/sc}  \\\\\n      2 \\cos(x) \\sin(y) & = -\\sin(x - y) + \\sin(x + y) \\label{eq:thm:trigonometric_identities/products/cs}\n    \\end{balign}\n\n    \\thmitem{thm:trigonometric_identities/sums} (Sums) For \\( x, y \\in \\BbbC \\),\n    \\begin{balign}\n      \\sin(x) + \\sin(y) & = 2 \\cos\\left(\\frac{x - y} 2 \\right) \\sin\\left(\\frac{x + y} 2 \\right) \\label{eq:thm:trigonometric_identities/sums/sin_sum}   \\\\\n      \\sin(x) - \\sin(y) & = 2 \\sin\\left(\\frac{x - y} 2 \\right) \\cos\\left(\\frac{x + y} 2 \\right) \\label{eq:thm:trigonometric_identities/sums/sin_diff}  \\\\\n      \\cos(x) + \\cos(y) & = 2 \\cos\\left(\\frac{x - y} 2 \\right) \\cos\\left(\\frac{x + y} 2 \\right) \\label{eq:thm:trigonometric_identities/sums/cos_sum}   \\\\\n      \\cos(x) - \\cos(y) & = -2 \\sin\\left(\\frac{x - y} 2 \\right) \\sin\\left(\\frac{x + y} 2 \\right) \\label{eq:thm:trigonometric_identities/sums/cos_diff}\n    \\end{balign}\n\n    \\thmitem{thm:trigonometric_identities/sum_of_angles} (Sum of angles) For \\( x, y \\in \\BbbC \\),\n    \\begin{balign}\n      \\sin(x + y) & = \\cos(x) \\sin(y) + \\cos(x) \\sin(y) \\label{eq:thm:trigonometric_identities/sum_of_angles/sin} \\\\\n      \\cos(x + y) & = \\cos(x) \\cos(y) - \\sin(x) \\sin(y) \\label{eq:thm:trigonometric_identities/sum_of_angles/cos}\n    \\end{balign}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  We first use \\hyperref[def:algebra_of_polynomials/polynomial_multiplication]{Cauchy multiplication} for the power series \\( \\cos(v) \\) and \\( \\cos(w) \\):\n  \\begin{balign}\n    \\cos(v) \\cos(w)\n    &=\n    \\left( \\sum_{k=0}^\\infty \\frac {i^{2k} v^{2k}} {(2k)!} \\right) \\Ast \\left( \\sum_{k=0}^\\infty \\frac {i^{2k} w^{2k}} {(2k)!} \\right)\n    = \\nonumber \\\\ &=\n    \\sum_{k=0}^\\infty \\sum_{m=0}^k \\frac {i^{2m} v^{2m}} {(2m)!} \\frac {i^{2(k-m)} w^{2(k-m)}} {(2(k-m))!}\n    = \\nonumber \\\\ &=\n    \\sum_{k=0}^\\infty \\frac {i^{2k}} {(2k)!} \\sum_{m=0}^k \\binom {2k} {2m} v^{2m} w^{2(k-m)}. \\label{eq:thm:trigonometric_identities/cos_product}\n  \\end{balign}\n\n  Analogously,\n  \\begin{balign}\n    \\sin(v) \\sin(w)\n    &=\n    (-i) (-i) \\left( \\sum_{k=0}^\\infty \\frac {i^{2k+1} v^{2k+1}} {(2k+1)!} \\right) \\Ast \\left( \\sum_{k=0}^\\infty \\frac {i^{2k+1} w^{2k+1}} {(2k+1)!} \\right)\n    = \\nonumber \\\\ &=\n    -\\sum_{k=0}^\\infty \\sum_{m=0}^k \\frac {i^{2m+1} v^{2m+1}} {(2m+1)!} \\frac {i^{2(k-m)+1} w^{2(k-m)+1}} {(2(k-m)+1)!}\n    = \\nonumber \\\\ &=\n    -\\sum_{k=0}^\\infty \\frac {i^{2(k+1)}} {(2(k+1))!} \\sum_{m=0}^k \\binom {2(k+1)} {2m+1} v^{2m+1} w^{2(k-m)+1}\n    = \\nonumber \\\\ &=\n    -\\sum_{k=1}^\\infty \\frac {i^{2k}} {(2k)!} \\sum_{m=0}^{k-1} \\binom {2k} {2m+1} v^{2m+1} w^{2k-(2m+1)}. \\label{eq:thm:trigonometric_identities/sin_product}\n  \\end{balign}\n\n  \\SubProofOf{thm:trigonometric_identities/pythagorean_identity} From \\eqref{eq:thm:trigonometric_identities/cos_product} and \\eqref{eq:thm:trigonometric_identities/sin_product} we have\n  \\begin{equation*}\n    \\sin(z)^2 + \\cos(z)^2\n    =\n    1 + \\sum_{k=1}^\\infty \\frac {i^{2k} z^{2k}} {(2k)!} \\underbrace{\\left[-\\sum_{m=0}^{k-1} \\binom {2k} {2m+1} + \\sum_{m=0}^k \\binom {2k} {2m} \\right]}_{\\eqqcolon a_k}.\n  \\end{equation*}\n\n  It remains to show that the expression \\( a_k \\) equals zero for all \\( k = 1, 2, \\ldots \\). We have\n  \\begin{equation*}\n    a_k\n    =\n    \\sum_{m=0}^k \\binom {2k} {2m} - \\sum_{m=0}^{k-1} \\binom {2k} {2m+1}\n    =\n    \\sum_{m=0}^k (-1)^m \\binom {2k} m\n    \\reloset {\\ref{thm:binomial_theorem}} =\n    1 - 1 = 0.\n  \\end{equation*}\n\n  \\Fullref{eq:thm:trigonometric_identities/pythagorean_identity} follows.\n\n  \\SubProofOf{thm:trigonometric_identities/products} We will only prove \\eqref{eq:thm:trigonometric_identities/products/cc} because the other identities are proved analogously. We have\n  \\begin{balign*}\n    \\cos(v - w) + \\cos(v + w)\n    &=\n    \\sum_{k=0}^\\infty \\frac {i^{2k}} {(2k)!} \\left[(v - w)^{2k} + (v + w)^{2k} \\right]\n    \\reloset {\\ref{thm:binomial_theorem}} = \\\\ &=\n    \\sum_{k=0}^\\infty \\frac {i^{2k}} {(2k)!} \\sum_{m=0}^{2k} \\binom {2k} m v^{2k-m} w^m \\left[ (-1)^m + 1 \\right]\n    = \\\\ &=\n    2 \\sum_{k=0}^\\infty \\frac {i^{2k}} {(2k)!} \\sum_{m=0}^{2k} \\binom {2k} {2m} v^{2(k-m)} w^{2m}\n    \\reloset {\\eqref{eq:thm:trigonometric_identities/cos_product}} = \\\\ &=\n    2 \\cos(v) \\cos(w).\n  \\end{balign*}\n\n  \\SubProofOf{thm:trigonometric_identities/sums} Fix some \\( v, w \\in \\BbbC \\) and define\n  \\begin{balign*}\n    x \\coloneqq \\frac {v + w} 2\n    &&\n    y \\coloneqq \\frac {v - w} 2\n  \\end{balign*}\n  so that \\( v = x + y \\) and \\( w = x - y \\).\n\n  The identity \\eqref{eq:thm:trigonometric_identities/sums/sin_sum} the follows from \\eqref{eq:thm:trigonometric_identities/products/sc} applied to \\( x \\) and \\( y \\). The other identities are proved analogously.\n\n  \\SubProofOf{thm:trigonometric_identities/sum_of_angles} We will only prove \\eqref{eq:thm:trigonometric_identities/sum_of_angles/sin} because \\eqref{eq:thm:trigonometric_identities/sum_of_angles/cos} is proved analogously. From \\eqref{eq:thm:trigonometric_identities/products/cs},\n  \\begin{balign*}\n    \\sin(x + y)\n     & =\n    2 \\cos(x) \\sin(y) + \\sin(x - y)\n    \\reloset {\\eqref{eq:thm:trigonometric_identities/products/sc}} = \\\\ &=\n    2 \\cos(x) \\sin(y) + 2 \\cos(x) \\sin(y) - \\sin(x + y).\n  \\end{balign*}\n\n  After dividing by \\( 2 \\), we obtain \\eqref{eq:thm:trigonometric_identities/sum_of_angles/sin}.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:trigonometric_function_basic_roots}\n  We have the following important special values:\n  \\begin{balign}\n    \\sin(0) = 0,   &  & \\cos(0) = 1,    \\label{eq:thm:trigonometric_function_basic_roots/zero} \\\\\n    \\sin(\\pi) = 0, &  & \\cos(\\pi) = -1. \\label{eq:thm:trigonometric_function_basic_roots/pi}\n  \\end{balign}\n\\end{lemma}\n\\begin{proof}\n\\eqref{eq:thm:trigonometric_function_basic_roots/zero} follows directly from \\fullref{def:trigonometric_functions}.\n  Now consider the \\hyperref[def:multi_valued_function/restriction]{restriction} of \\( \\cos \\) to the real line. Since \\( \\cos(0) \\neq 0 \\) and \\( \\cos \\) is continuously differentiable as a power series, in some neighborhood \\( U \\) of \\( 0 \\) we have \\( 0 \\not\\in \\cos(U) \\). Therefore, the inverse function theorem holds and there exists a neighborhood \\( V \\subseteq U \\) of \\( 1 \\) such that the continuously differentiable function \\( f: V \\to \\BbbR \\) is the inverse of \\( \\cos \\) in \\( V \\) (we have not yet defined \\hyperref[def:inverse_trigonometric_functions/arccos]{\\( \\arccos \\)}). If \\( y = \\cos(x) \\), then\n  \\begin{equation*}\n    Df(y)\n    =\n    \\frac 1 {D\\cos(x)}\n    =\n    \\frac 1 {-\\sin(x)}\n    \\reloset {\\ref{thm:trigonometric_identities/pythagorean_identity}} =\n    -\\frac 1 {\\sqrt{1 - y^2}},\n    \\quad y \\in \\cos(V).\n  \\end{equation*}\n\n  The derivative is actually well-defined and continuous anywhere except for \\( y \\in \\{ -1, 1 \\} \\). Therefore, for any \\( \\alpha \\in (-1, 1) \\),\n  \\begin{equation*}\n    f(y) = f(\\alpha) - \\int_{\\alpha}^y \\frac 1 {\\sqrt{1 - t^2}} dt, \\quad y \\in [\\alpha, 1).\n  \\end{equation*}\n\n  We already know that \\( \\cos(0) = 1 \\), hence \\( f(1) = 0 \\) and, since \\( f(y) \\) is given by a convergent integral in \\( [\\alpha, 1) \\), we can extend this interval to \\( [\\alpha, 1] \\).\n\n  By taking \\( y = \\alpha \\), we obtain\n  \\begin{equation*}\n    f(y) - f(-y) = -\\int_{-y}^y \\frac 1 {\\sqrt{1 - t^2}} dt, \\quad y \\in [-1, 1].\n  \\end{equation*}\n\n  Note that by \\hyperref[def:pi]{our definition} of \\( \\pi \\),\n  \\begin{equation*}\n    \\pi\n    =\n    \\int_{-1}^1 \\frac 1 {\\sqrt{1 - t^2}} dt\n    =\n    -[\\underbrace{f(1)}_{=0} - f(-1)]\n    =\n    f(-1).\n  \\end{equation*}\n\n  Hence, \\( \\cos(\\pi) = -1 \\). From \\fullref{thm:trigonometric_identities/pythagorean_identity},\n  \\begin{equation*}\n    \\abs{\\sin(\\pi)} = \\sqrt{1 - \\cos(\\pi)^2} = 0,\n  \\end{equation*}\n  proving that \\( \\sin(\\pi) = 0 \\).\n\n  This concludes the proof of \\eqref{eq:thm:trigonometric_function_basic_roots/pi}.\n\\end{proof}\n\n\\begin{definition}\\label{def:periodic_function}\n  A function \\( f: G \\to H \\) between \\hyperref[def:abelian_group] abelian groups is called \\term{periodic} with \\term{period} \\( p \\in G \\) if, for all \\( x \\in G \\), we have \\( f(x) = f(x + r) \\).\n\n  The \\term{base period} of a function is the \\hyperref[def:partially_ordered_set_extremal_points/maximum_and_minimum]{least} of all periods, if a minimum exists. When referring to \\enquote{the period}, we mean the base period.\n\n  We can define periods for arbitrary magmas rather than abelian groups, but the definition would make it difficult to talk about the base period.\n\\end{definition}\n\n\\begin{theorem}\\label{thm:trigonometric_function_period}\n  Both \\( \\sin(z) \\) and \\( \\cos(z) \\) are \\( 2\\pi \\)-periodic.\n\\end{theorem}\n\\begin{proof}\n  We will temporarily restrict ourselves to the real line. Since \\( \\cos(x) \\) is continuous, \\( \\cos^{-1}(\\{ 0 \\}) \\) is a closed set by \\fullref{thm:weierstrass_extreme_value_theorem} there exists a minimum \\( \\gamma \\) of \\( [0, \\pi] \\cap \\cos^{-1}(\\{ 0 \\}) \\).\n\n  Since, by \\fullref{thm:trigonometric_function_basic_roots}, \\( \\cos(0) = 1 \\), it follows that \\( \\cos(x) > 0, x \\in (-\\gamma, \\gamma) \\). Therefore, its primitive function \\( \\sin(x) \\) increases on the same interval. It is also continuous, hence by \\fullref{thm:trigonometric_identities/pythagorean_identity}, \\( \\sin(\\gamma) = 1 \\) because \\( \\cos(\\gamma) = 0 \\).\n\n  Because \\( \\sin \\) is an odd function, \\( \\sin(-\\gamma) = \\sin(\\gamma) = -1 \\).\n\n  From \\hyperref[def:pi]{our definition} of \\( \\pi \\) it follows that\n  \\begin{equation*}\n    \\pi\n    =\n    \\int_{-1}^1 \\frac 1 {1 - t^2} dt\n    =\n    \\int_{-\\gamma}^\\gamma \\frac {\\cos(\\varphi)} {1 - \\sin(\\varphi)^2} d\\varphi\n    \\reloset {\\ref{thm:trigonometric_identities/pythagorean_identity}} =\n    \\int_{-\\gamma}^\\gamma d\\varphi\n    =\n    2\\gamma.\n  \\end{equation*}\n\n  In order for a number \\( p \\) to be a period of \\( \\sin \\), we need to have \\( \\sin(p) = \\sin(0) = 0 \\). But we showed that \\( \\sin(x) \\) is increasing from \\( 0 \\) to \\( \\tfrac \\pi 2 \\) and cannot possibly contain zeros in that interval. Hence, \\( p > \\tfrac \\pi 2 \\).\n\n  We also have \\( \\cos(\\tfrac \\pi 2) = 0 \\). By \\fullref{thm:trigonometric_identities/sums},\n  \\begin{equation*}\n    \\sin(\\tfrac \\pi 2 + x)\n    =\n    \\sin(\\tfrac \\pi 2) \\cos(x) + \\cos(\\tfrac \\pi 2) \\sin(x)\n    =\n    \\cos(x).\n  \\end{equation*}\n\n  Since \\( \\cos \\) is positive on \\( [0, \\tfrac \\pi 2) \\), \\( \\sin \\) is positive on \\( [\\tfrac \\pi 2, \\pi) \\).\n\n  We already showed in \\fullref{thm:trigonometric_function_basic_roots} that \\( \\sin(\\pi) = 0 \\).\n\n  It follows that the minimal period of \\( \\sin \\) is either \\( \\pi \\) or a multiple of \\( \\pi \\). It cannot be \\( \\pi \\) since \\( \\cos(\\pi) \\neq \\cos(0) \\), therefore it must be \\( 2\\pi \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:hyperbolic_trigonometric_functions}\n  In analogy with \\fullref{thm:exponential_trigonometric_identities/inverse_eulers_formula}, we define \\term{hyperbolic trigonometric functions}.\n\n  \\begin{thmenum}\n    \\thmitem{def:hyperbolic_trigonometric_functions/sine} The \\term{hyperbolic sine} function:\n    \\begin{equation*}\n      \\sinh(x) \\coloneqq - \\frac {e^x - e^{-x}} 2 \\\\\n    \\end{equation*}\n\n    \\thmitem{def:hyperbolic_trigonometric_functions/cosine} The \\term{hyperbolic cosine} function:\n    \\begin{equation*}\n      \\cosh(x) \\coloneqq \\frac {e^x + e^{-x}} 2\n    \\end{equation*}\n  \\end{thmenum}\n\n  Compare \\fullref{def:quadratic_plane_curve/ellipse/parametric_equations} and \\fullref{def:quadratic_plane_curve/hyperbola/parametric_equations} for a justification of the naming.\n\\end{definition}\n\n\\begin{definition}\\label{def:derived_trigonometric_functions}\n  In addition to \\( \\sin(z) \\) and \\( \\cos(z) \\), we define two additional functions, also called \\enquote{trigonometric}.\n\n  \\begin{thmenum}\n    \\thmitem{def:derived_trigonometric_functions/tan} The \\hyperref[def:partial_function]{partial} \\term{tangent} function, also called \\term{tangens}, is\n    \\begin{equation*}\n      \\tan(z) \\coloneqq \\frac {\\sin(z)} {\\cos(z)}.\n    \\end{equation*}\n\n    It is defined in \\( \\BbbC \\setminus (\\tfrac \\pi 2 + \\pi\\BbbZ) \\).\n\n    \\thmitem{def:derived_trigonometric_functions/cot} The \\hyperref[def:partial_function]{partial} \\term{cotangent function}, also called \\term{cotangens}, is\n    \\begin{equation*}\n      \\cot(z) \\coloneqq \\frac {\\cos(z)} {\\sin(z)}.\n    \\end{equation*}\n\n    It is defined in \\( \\BbbC \\setminus \\pi\\BbbZ \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:inverse_trigonometric_functions}\n  We can define \\term{inverse trigonometric functions}. We will thus restrict ourselves only to real numbers. Fix an integer \\( k \\). Unless noted otherwise, we assume \\( k = 0 \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:inverse_trigonometric_functions/arcsin} The \\term{arcus sinus} function \\( \\arcsin(x) \\) is defined as the \\hyperref[def:multi_valued_function/inverse]{inverse function} of \\( \\sin(x) \\) (see \\fullref{def:trigonometric_functions/sine}) from \\( [-1, 1] \\) to \\( \\left[(k - \\tfrac 1 2) \\pi, (k + \\tfrac 1 2) \\pi \\right) \\).\n\n    \\thmitem{def:inverse_trigonometric_functions/arccos} The \\term{arcus cosinus} function \\( \\arccos(x) \\) is defined as the inverse of \\( \\cos(x) \\) (see \\fullref{def:trigonometric_functions/cosine}) from \\( [-1, 1] \\) to \\( (k\\pi, (k + 1)\\pi) \\).\n\n    \\thmitem{def:inverse_trigonometric_functions/arctan} The \\term{arcus tangens} function \\( \\arctan(x) \\) is defined as the inverse of \\( \\tan(x) \\) (see \\fullref{def:derived_trigonometric_functions/tan}) from \\( \\BbbR \\) to \\( \\left((k - \\tfrac 1 2) \\pi, (k + \\tfrac 1 2) \\pi \\right) \\).\n\n    \\thmitem{def:inverse_trigonometric_functions/arccot} The \\term{arcus cotangens} function \\( \\arccot(x) \\) is defined as the inverse of \\( \\cot(x) \\) (see \\fullref{def:derived_trigonometric_functions/cot}) from \\( \\BbbR \\) to \\( (k\\pi, (k + 1)\\pi) \\).\n\n    \\thmitem{def:inverse_trigonometric_functions/arctantwo} The \\term{two-argument arcus tangens} function \\( \\arctantwo(y, x) \\) is a bit special, however it is very useful in practice - see \\fullref{thm:arctantwo}. It is defined as\n    \\begin{align*}\n       &\\arctantwo: \\BbbR^2 \\setminus \\{ 0 \\} \\to [2k\\pi, 2k\\pi + 2)  \\\\\n       &\\arctantwo(y, x) \\coloneqq \\begin{dcases}\n        \\arctan \\parens*{ \\tfrac y x },       &x > 0                  \\\\\n        \\arctan \\parens*{ \\tfrac y x } + \\pi, &x < 0 \\T{and} y \\geq 0 \\\\\n        \\arctan \\parens*{ \\tfrac y x } - \\pi, &x < 0 \\T{and} y < 0    \\\\\n        \\pi,                                 &x = 0 \\T{and} y \\geq 0 \\\\\n        -\\pi,                                &x = 0 \\T{and} y < 0.\n      \\end{dcases}\n    \\end{align*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:arctantwo}\n  Fix an integer \\( k \\). Given \\( (x_0, y_0) \\in S_{\\BbbR^2} \\), \\( t_0 \\coloneqq \\arctantwo(y_0, x_0) \\) is the unique, solution to the equation\n  \\begin{equation}\\label{thm:arctantwo/equation}\n    \\begin{cases}\n      x_0 = \\cos(t) \\\\\n      y_0 = \\sin(t)\n    \\end{cases}\n  \\end{equation}\n  in \\( t \\in [2k\\pi, 2k\\pi + 2) \\).\n\\end{proposition}\n", "meta": {"hexsha": "e38b44e94fc7c693294d0c478875919d89a7738a", "size": 18322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/trigonometric_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/trigonometric_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/trigonometric_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": 53.8882352941, "max_line_length": 621, "alphanum_fraction": 0.6375941491, "num_tokens": 6814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6713429214581468}}
{"text": "% \n% firstly set up on Jan 2012\n%\n% fully derived the ERI in OS framework\n% derived the overlap, kinetic and nuclear integral in OS framework\n%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{OS Method}\n%\n%\n%\n%\nOS method is based on two cognitions for the integral of Gaussian primitive\nfunctions. The first cognition is that all of integral could be reduced into the\nform of three body overlap integrals. The second cognition is based on\nderivatives of Gaussian primitive function:\n\\begin{equation}\n \\label{OS_general_int_eq:1}\n\\frac{\\partial \\chi}{\\partial R_{x}} = \\frac{\\partial\n(x^{l}y^{m}z^{n}e^{-\\alpha r^{2}})}\n{\\partial R_{x}} =  -lx^{l-1}y^{m}z^{n}e^{-\\alpha r^{2}} + 2\\alpha\nx^{l+1}y^{m}z^{n}e^{-\\alpha r^{2}}\n\\end{equation}\nHere the $x$ is expressed as:\n\\begin{equation}\n x = x_{e} - R_{x} \n\\end{equation}\nIn such relation, it's clear that the $\\chi(l,m,n)$, its derivatives and the\nhigher angular momentum one $\\chi(l+1,m,n)$ are connected with each other so\nthat it provides an potential opportunity to link the $\\chi(l+1,m,n)$\nand $\\chi(l,m,n)$ together through $\\chi$'s derivatives.\n\nNow following the definition in the OS method, we can express such \nrelation as:\n\\begin{equation}\n \\label{OS_general_int_eq:2}\n \\frac{\\partial \\chi(r,\\alpha,l,R)}{\\partial R_{i}} = \n2\\alpha\\chi(r,\\alpha,l+\\iota_{i},R) - N_{i}(l)\\chi(r,\\alpha,l-\\iota_{i},R)\n\\end{equation}\nas $i = x, y, z$. Original $\\chi$ is $\\chi(r,\\alpha,l,R)$, so $r$ is the\nelectron coordinate, $R$ is the nuclear coordinate, $\\alpha$ is the exponent\nand $l$ is the angular momentum (actually it's a three dimensional vector).\n$\\iota$ characterizes the arising or descending of the angular momentum,\nit's actually Kronecker symbol:\n\\begin{equation}\n \\iota_{i} = (\\delta_{ix}, \\delta_{iy}, \\delta_{iz})\n\\label{OS_general_int_eq:3}\n\\end{equation}\nSimilarly, $N_{i}(l)$ is:\n\\begin{equation}\nN_{i}(l) = \n\\begin{cases}\n l_{x} & i = x \\\\\n l_{y} & i = y \\\\\n l_{z} & i = z \n\\end{cases}\n \\label{OS_general_int_eq:4}\n\\end{equation}\n\nBy moving the exponent to the left side, the \\ref{OS_general_int_eq:2}\ncould be further expressed into:\n\\begin{equation}\n \\label{OS_general_int_eq:5}\n\\chi(r,\\alpha,l+\\iota_{i},R) =  \n\\frac{1}{2\\alpha}\\frac{\\partial \\chi(r,\\alpha,l,R)}{\\partial R_{i}}\n+ \\frac{N_{i}(l)}{2\\alpha}\\chi(r,\\alpha,l-\\iota_{i},R)\n\\end{equation} \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Three Center Overlap Integral}\n%\n%\n%\nThe purpose for this section, is to employ the relation in the \\ref{OS_general_int_eq:5}\nto derive a recursive relation for evaluating the three center overlap integral\nin terms of the corresponding lower angular momentum integrals. \n\nNow let's suggest a three body overlap integral between $\\chi_{a}, \\chi_{b}$\nand $\\chi_{c}$:\n\\begin{equation}\n \\begin{split}\n(a|b|c) &= \\int \\chi_{a}(r)\\chi_{b}(r)\\chi_{c}(r) dr \\\\\n&= \\int x^{l_{A}}_{A}y^{m_{A}}_{A}z^{n_{A}}_{A}e^{-\\alpha r_{A}^{2}}\n        x^{l_{B}}_{B}y^{m_{B}}_{B}z^{n_{B}}_{B}e^{-\\beta  r_{B}^{2}} \n        x^{l_{C}}_{C}y^{m_{C}}_{C}z^{n_{C}}_{C}e^{-\\gamma r_{C}^{2}}dr\n \\end{split}\n\\label{OS_three_overlap_int_eq:1}\n\\end{equation}\nA,B and C could be the same center, or different centers. From the previous\nchapter to evaluate the overlap integral, we know that we could combine\n$\\chi_{a}$ and $\\chi_{b}$ together and then combine the new Gaussian primitive\nwhich centers at $p$ with the $\\chi_{c}$. The integral could be generally expressed as:\n\\begin{equation}\n\\label{general_expression_for_3_overlap_os}\n\\begin{split}\n \\int \\chi_{a}(r)\\chi_{b}(r)\\chi_{c}(r) dr &= \n\\kappa_{abc}I_{abc}^{x}I_{abc}^{y}I_{abc}^{z} \\\\\n&= e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}|AB|^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|PC|^{2}} \\\\\n& \\int x^{l_{A}}_{A}y^{m_{A}}_{A}z^{n_{A}}_{A}\n       x^{l_{B}}_{B}y^{m_{B}}_{B}z^{n_{B}}_{B}\n       x^{l_{C}}_{C}y^{m_{C}}_{C}z^{n_{C}}_{C} \ne^{-(\\alpha+\\beta+\\gamma)|r_{G}|^{2}} dr        \n\\end{split}\n\\end{equation}\nIn the combination of Gaussian primitives, new centers generated are given as:\n\\begin{equation}\n \\begin{split}\n  \\overrightarrow{P} &= \\frac{\\alpha \\overrightarrow{A} + \n\\beta \\overrightarrow{B}}{\\alpha+\\beta}\n\\Rightarrow \\\\\n  \\overrightarrow{G} &= \\frac{(\\alpha+\\beta)\\overrightarrow{P} + \\gamma\n\\overrightarrow{C}}{ \\alpha+\\beta +\\gamma } \\\\\n    &= \\frac{\\alpha \\overrightarrow{A} + \\beta \\overrightarrow{B} + \n\\gamma \\overrightarrow{C}}{ \\alpha+\\beta +\\gamma }\n \\end{split}\n\\label{OS_three_overlap_int_eq:2}\n\\end{equation}\nHere we intentionally do not expand the multiplication of \n$x^{l_{A}}_{A}y^{m_{A}}_{A}z^{n_{A}}_{A}$ etc. since we want to keep it\ninto some symmetrical form. The essence for deriving the three center of \noverlap integral, is not to really calculate it; but gain some recursive relationship\namong the integrals. Here the symmetry of the integral \\ref{general_expression_for_3_overlap_os}\nis some key feature.\n\nFirstly, for the pre-factor we could express it into:\n\\begin{equation}\n\\kappa_{abc} = e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}|AB|^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|PC|^{2}}\n\\label{OS_three_overlap_int_eq:3}\n\\end{equation}\nNow we expand the \\ref{OS_three_overlap_int_eq:3} into (We use $A_{i}$, $B_{i}$\nand $C_{i}$ to represent it's component on X, Y or Z direction, i could be\nx, y, or z):\n\\begin{equation}\n \\begin{split}\n &e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}(A_{i}-B_{i})^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}(P_{i}-C_{i})^{2}} \\\\\n&=e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}(A_{i}-B_{i})^{2}} \ne^{-\\frac{\\gamma}{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)}\n((\\alpha+\\beta)C_{i}-\\alpha A_{i} - \\beta B_{i})^{2}} \\\\\n \\end{split}\n\\label{OS_three_overlap_int_eq:4}\n\\end{equation}\nFor the exponents we have:\n\\begin{equation}\n \\begin{split}\n & \\frac{\\alpha\\beta}{\\alpha+\\beta}(A_{i}-B_{i})^{2}\n+ \\frac{\\gamma}{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)}\n((\\alpha+\\beta)C_{i} -\\alpha A_{i} - \\beta B_{i})^{2} \\\\\n&=  \\frac{\\alpha\\beta(\\alpha+\\beta+\\gamma)(A_{i}-B_{i})^{2}\n+ \\gamma((\\alpha+\\beta)C_{i} -\\alpha A_{i} - \\beta B_{i})^{2}}\n{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n&= \\frac{\\alpha^{2}\\beta(A_{i}-B_{i})^{2} \n+ \\alpha\\beta^{2}(A_{i}-B_{i})^{2}+\\alpha\\beta\\gamma(A_{i}-B_{i})^{2}}\n{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n&+ \\frac{\\gamma(\\alpha+\\beta)^{2}C_{i}^{2}+\\alpha^{2}\\gamma A_{i}^{2} +\n\\beta^{2}\\gamma B_{i}^{2} }{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n&+ \\frac{-2\\alpha\\gamma(\\alpha+\\beta)A_{i}C_{i}\n- 2\\beta\\gamma(\\alpha+\\beta)B_{i}C_{i} + 2\\alpha\\beta\\gamma A_{i}B_{i}}\n{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)}  \\\\\n \\end{split}\n\\label{OS_three_overlap_int_eq:5}\n\\end{equation}\nNow let's re-arrange the terms in terms of the order of $\\alpha, \\beta$\nand $\\gamma$:\n\\begin{equation}\n \\begin{split}\n  & \\frac{\\alpha\\beta}{\\alpha+\\beta}(A_{i}-B_{i})^{2}\n+ \\frac{\\gamma}{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)}\n((\\alpha+\\beta)C_{i}-\\alpha A_{i} - \\beta B_{i})^{2} \\\\\n&= \\frac{\\alpha^{2}\\beta(A_{i}-B_{i})^{2} \n+ \\alpha\\beta^{2}(A_{i}-B_{i})^{2}+\n\\alpha^{2}\\gamma(A_{i}-C_{i})^{2} \n+ \\beta^{2}\\gamma(B_{i}-C_{i})^{2}}{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n& +\\frac{\n  \\alpha\\beta\\gamma(A_{i}^{2}+B_{i}^{2}+2C_{i}^{2}-2A_{i}C_{i}-2B_{i}C_{i})}\n{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)}  \\\\\n&= \\frac{\\alpha^{2}\\beta(A_{i}-B_{i})^{2} \n+ \\alpha\\beta^{2}(A_{i}-B_{i})^{2}+\n\\alpha^{2}\\gamma(A_{i}-C_{i})^{2} \n+ \\beta^{2}\\gamma(B_{i}-C_{i})^{2}}{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n&+\\frac{\n  \\alpha\\beta\\gamma\\left( (C_{i}-A_{i})^{2} + (C_{i}-B_{i})^{2}\\right)}\n{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n&= \\frac{\\alpha\\beta(A_{i}-B_{i})^{2}(\\alpha+\\beta) +\n\\alpha\\gamma(A_{i}-C_{i})^{2}(\\alpha+\\beta) \n+ \\beta\\gamma(B_{i}-C_{i})^{2}(\\alpha+\\beta)}\n{(\\alpha+\\beta)(\\alpha+\\beta+\\gamma)} \\\\\n&= \\frac{\\alpha\\beta(A_{i}-B_{i})^{2} +\n\\alpha\\gamma(A_{i}-C_{i})^{2} \n+ \\beta\\gamma(B_{i}-C_{i})^{2}}\n{(\\alpha+\\beta+\\gamma)}\n \\end{split}\n\\label{OS_three_overlap_int_eq:6}\n\\end{equation}\nThe expression in \\ref{OS_three_overlap_int_eq:6} is symmetric. Furthermore, we \ncould re-form it by using the \\ref{OS_three_overlap_int_eq:2} since $G$ will also\nappears in the integral part:\n\\begin{equation}\n \\begin{split}\n &\\frac{\\alpha\\beta(A_{i}-B_{i})^{2} + \\alpha\\gamma(A_{i}-C_{i})^{2}  +\n\\beta\\gamma(B_{i}-C_{i})^{2}}\n {(\\alpha+\\beta+\\gamma)} \\\\\n&= -(\\alpha+\\beta+\\gamma)\\left( G_{i}^{2} - \\frac{\\alpha A_{i}^{2} + \\beta\nB_{i}^{2} + \\gamma C_{i}^{2}}\n{\\alpha+\\beta+\\gamma}\\right)  \n \\end{split}\n\\label{OS_three_overlap_int_eq:7}\n\\end{equation}\nTherefore, for the pre-factor we have:\n\\begin{align}\n\\kappa_{abc} &= e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}|A-B|^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|P-C|^{2}} \\nonumber \\\\\n&= e^{(\\alpha+\\beta+\\gamma)\\left( |G|^{2} - \\frac{\\alpha |A|^{2} + \\beta |B|^{2} + \\gamma |C|^{2}}\n{\\alpha+\\beta+\\gamma}\\right)}\n\\label{OS_three_overlap_int_eq:8}\n\\end{align}\nIts derivatives for the $R_{i}$ is:\n\\begin{equation}\n \\label{OS_three_overlap_int_eq:9}\n\\frac{\\partial \\kappa_{abc}}{R_{i}} = (2\\alpha G_{Ai} - 2\\alpha\nA_{i})\\kappa_{abc}\n\\end{equation}\n\nNow let's expand the integral of $I^{x}_{abc}$:\n\\begin{equation}\n \\begin{split}\n  I^{x}_{abc}(l_{A},l_{B},l_{C}) &= \\sum_{l_{1}=0}^{l_{A}}\\sum_{l_{2}=0}^{l_{B}}\n\\sum_{l_{3}=0}^{l_{C}}  \n\\binom{l_{A}}{l_{1}}\\binom{l_{B}}{l_{2}}\\binom{l_{C}}{l_{3}} \\\\\n&(G_{x}-A_{x})^{(l_{A}-l_{1})} \n (G_{x}-B_{x})^{(l_{B}-l_{2})}\n (G_{x}-C_{x})^{(l_{C}-l_{3})} \\\\\n&\\int (x-G_{x})^{l_{1}+l_{2}+l_{3}}\ne^{-(\\alpha+\\beta+\\gamma)(x-G_{x})^{2}} dx \\\\\n&= \\sqrt{\\frac{\\pi}{\\alpha+\\beta+\\gamma}}\\sum_{l_{1}=0}^{l_{A}}\\sum_{l_{2}=0}^{l_{B}}\n\\sum_{l_{3}=0}^{l_{C}}  \n\\binom{l_{A}}{l_{1}}\\binom{l_{B}}{l_{2}}\\binom{l_{C}}{l_{3}} \\\\\n&(G_{x}-A_{x})^{(l_{A}-l_{1})} \n (G_{x}-B_{x})^{(l_{B}-l_{2})}\n (G_{x}-C_{x})^{(l_{C}-l_{3})} \\\\\n&\\frac{(l_{1}+l_{2}+l_{3}-1)!!}\n{\\left\\lbrace 2(\\alpha+\\beta+\\gamma)\\right\\rbrace^{l_{1}+l_{2}+l_{3}} }\n \\end{split}\n\\label{OS_three_overlap_int_eq:10}\n\\end{equation}\nWe note that $l_{1}+l_{2}+l_{3}$ should be even number else the integral is zero. For\nthe integral on the y, z direction, we have the similar result, too.\nIt's derivative could be expressed as:\n\\begin{equation}\n\\begin{split}\n \\frac{\\partial I^{x}_{abc}}{\\partial R_{x}} &= \nl_{A}\\left( \\frac{\\alpha}{\\alpha+\\beta+\\gamma} -1\\right)I^{x}_{abc}(l_{A}-1,l_{B},l_{C}) \\\\\n&+ l_{B}\\left( \\frac{\\alpha}{\\alpha+\\beta+\\gamma}\\right)I^{x}_{abc}(l_{A},l_{B}-1,l_{C}) \\\\\n&+ l_{C}\\left( \\frac{\\alpha}{\\alpha+\\beta+\\gamma}\\right)I^{x}_{abc}(l_{A},l_{B},l_{C}-1) \n\\end{split}\n \\label{OS_three_overlap_int_eq:11}\n\\end{equation}\nWe note that for the derivatives of $I^{i}_{abc}$ in terms of $R_{j}$ ($j \\neq i$), the result\nis obviously zero. \n\nNow let's combine the result in \\ref{OS_three_overlap_int_eq:9} and \\ref{OS_three_overlap_int_eq:11},\nand also employing the relation in \\ref{OS_general_int_eq:5}; we can arrive at some symmetrical\nrecursive relation for the $(a|b|c)$:\n\\begin{equation}\n \\begin{split}\n (a+\\iota_{x}|b|c) &= \\frac{1}{2\\alpha}\\frac{\\partial }{\\partial R_{Ax}}(a|b|c) \n+ \\frac{l_{A}}{2\\alpha}(a-\\iota_{x}|b|c) \\\\\n&= (G_{Ax} - A_{x})(a|b|c) + \nl_{A}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)} -\\frac{1}{2\\alpha}\\right)(a-\\iota_{x}|b|c) \\\\\n&+ l_{B}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a|b-\\iota_{x}|c)  \\\\\n&+ l_{C}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a|b|c-\\iota_{x}) +  \n\\frac{l_{A}}{2\\alpha}(a-\\iota_{x}|b|c) \\\\\n&= (G_{Ax} - A_{x})(a|b|c) + \nl_{A}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a-\\iota_{x}|b|c) \\\\\n&+ \nl_{B}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a|b-\\iota_{x}|c) \\\\\n&+\nl_{C}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a|b|c-\\iota_{x}) \n \\end{split}\n\\label{OS_three_overlap_int_eq:12}\n\\end{equation}\nSuch relation could be generalized into the derivative for $R_{Xi}$ for all of \ncenter of X and all of components of $i=x,y,z$. The relation is the starting point for \nall of following derivations.\n\nAt last, let's consider that if one of primitive function is ``S'' type of \nfunction, how to reduce the recursive relation in\n\\ref{OS_three_overlap_int_eq:12}. For the S type of function it does not have\nthe angular momentum part, the pre-factor part part still exists; but for the\nintegral in \\ref{OS_three_overlap_int_eq:10}, the derivatives for the S type \nfunction will be zero. For example, suggest that $a$ is the S type of function,\nthen it's obvious that:\n\\begin{equation}\n\\begin{split}\n \\frac{\\partial I^{x}_{abc}}{\\partial R_{x}} &= \nl_{B}\\left(\n\\frac{\\alpha}{\\alpha+\\beta+\\gamma}\\right)I^{x}_{abc}(l_{A},l_{B}-1,l_{C}) \\\\\n&+ l_{C}\\left(\n\\frac{\\alpha}{\\alpha+\\beta+\\gamma}\\right)I^{x}_{abc}(l_{A},l_{B},l_{C}-1) \n\\end{split}\n \\label{OS_three_overlap_int_eq:13}\n\\end{equation}\nThen combined with \\ref{OS_three_overlap_int_eq:12}, it gives:\n\\begin{equation}\n \\begin{split}\n (0+\\iota_{x}|b|c) &= \\frac{1}{2\\alpha}\\frac{\\partial }{\\partial R_{Ax}}(0|b|c) \n\\\\\n&= (G_{Ax} - A_{x})(0|b|c) \n+ l_{B}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(0|b-\\iota_{x}|c) \\\\ \n&+ l_{C}\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(0|b|c-\\iota_{x}) \n \\end{split}\n\\label{OS_three_overlap_int_eq:14}\n\\end{equation}\nFor the other S type centers we have the similar relation, too.\n\nFrom the above derivation, the bottom integral of three center \noverlap could be expressed as:\n\\begin{equation}\n \\begin{split}\n  (0_{A}|0_{B}|0_{C}) &= \\int e^{-\\alpha r_{A}^{2}}e^{-\\beta  r_{B}^{2}} \n             e^{-\\gamma r_{C}^{2}}dr \\\\\n          &= e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}|AB|^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|PC|^{2}} \n\\int e^{-(\\alpha+\\beta+\\gamma)|r_{G}|^{2}} dr \\\\\n          &= e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}|AB|^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|PC|^{2}} \n\\left( \\frac{\\pi}{\\alpha+\\beta+\\gamma}\\right)^{\\frac{3}{2}} \n \\end{split}\n \\label{OS_bottom_three_overlap_int_1}\n\\end{equation}\n\nWe can also write the above integral in another form:\n\\begin{equation}\n \\begin{split}\n  (0_{A}|0_{B}|0_{C}) &= e^{-\\frac{\\alpha\\beta}{\\alpha+\\beta}|AB|^{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|PC|^{2}} \n\\left( \\frac{\\pi}{\\alpha+\\beta+\\gamma}\\right)^{\\frac{3}{2}} \\\\\n&= (0_{A}|0_{B})\\left( \\frac{\\alpha+\\beta}{\\alpha+\\beta+\\gamma}\\right)^{\\frac{3}{2}}\ne^{-\\frac{(\\alpha+\\beta)\\gamma}{\\alpha+\\beta+\\gamma}|PC|^{2}} \n \\end{split}\n \\label{OS_bottom_three_overlap_int_2}\n\\end{equation}\nwhere $(0_{A}|0_{B})$ is the overlap integral in \\ref{overlap_direct_int_eq:1}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Electron Repulsion Integrals}\n\\label{os_eri}\n%\n%\n%\n%\nNow we begin to use the conclusion got in the previous section to solve the\nreal problems. This section we are going to tackle down the most difficult one,\nthe double electrons integral.\n\nLet's consider some electronic repulsion integral over the\nGaussian primitive functions:\n\\begin{equation}\n \\label{OS_ERI_eq:1}\n(ab|cd) = \\int dr \\int dr^{'} \\chi_{a}(r)\\chi_{b}(r)\\frac{1}{|r-r^{'}|}\n\\chi_{c}(r^{'})\\chi_{d}(r^{'})\n\\end{equation}\na,b,c,d are just some general Gaussian primitive functions.\n\nFirstly we do transformation to the $\\frac{1}{|r-r^{'}|}$:\n\\begin{equation}\n \\frac{1}{|r-r^{'}|} = \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0}\ne^{-(r-r^{'})^{2}u^{2}}du\n\\end{equation}\nHere $(r-r^{'})^{2}$ is \n\\begin{equation}\n(r-r^{'})^{2} = (x_{r}-x_{r^{'}})^{2} +  (y_{r}-y_{r^{'}})^{2} +\n(z_{r}-z_{r^{'}})^{2}\n\\end{equation}\nWe note the $r$ and $r^{'}$ are more like the A, B defined in the \n\\ref{OS_three_overlap_int_eq:4}. Based on this transformation,\nthe integral could be reformed as:\n\\begin{equation}\n \\begin{split}\n (ab|cd) &= \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0} du \n\\int dr \\int dr^{'} \\chi_{a}(r)\\chi_{b}(r) e^{(r-r^{'})^{2}u^{2}}\n\\chi_{c}(r^{'})\\chi_{d}(r^{'}) \\\\\n&= \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{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^{2}}\\right) \\\\ \n&= \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0} du\n\\int dr^{'}\\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}|b) \\\\\n&= \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0} du (ab|u|cd)\n \\end{split}\n\\label{OS_ERI_eq:2}\n\\end{equation}\nTherefore, the two electron integral now is converted into the three\ncenter overlap integral.\n\nBefore we move on, it's useful to remind us the key idea of the derivation\nwe are going to. We are going to use the recursive relation for the three\ncenter overlap integral, to derive the potential recursive relation for the\nERI. Furthermore, before we really move into the ERI section, actually there are\nsome very fancy formulas needed to be introduced first. Suggest that there are\nthree variables, $u$, $\\epsilon$ and $\\eta$, they are all independent with each\nother; we can prove that:\n\\begin{equation}\n \\frac{1}{\\epsilon+u^{2}} = \\frac{1}{\\epsilon}\\left( 1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right) - \\frac{1}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}} \n\\label{OS_ERI_eq:3}\n\\end{equation}\nWhere the $\\rho$ is:\n\\begin{equation}\n \\rho = \\frac{\\epsilon\\eta}{\\epsilon+\\eta}\n\\end{equation}\nThis intelligent identity is not so obvious by judging from its appearance.\nHowever, this identity possesses a key path to the final form of expression.\nNow let's go to see how to prove it.\n\\begin{equation}\n \\begin{split}\n &\\frac{u^{2}}{\\rho+u^{2}}\\left( \\frac{\\rho}{\\epsilon^{2}} + \n\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}{\\epsilon+u^{2}}\\right) \\\\\n&= \\frac{u^{2}}{\\rho+u^{2}}\\left(\n\\frac{\\epsilon\\eta}{\\epsilon^{2}(\\epsilon+\\eta)} + \n\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}{\\epsilon+u^{2}}\\right) \\\\\n&= \\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon+\\eta}\\left(\n\\frac{\\epsilon\\eta}{\\epsilon^{2}} + \n\\frac{u^{2}}{\\epsilon+u^{2}}\\right) \\\\\n&= \\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon+\\eta}\\left(\n\\frac{\\eta}{\\epsilon} + \n\\frac{u^{2}}{\\epsilon+u^{2}}\\right) \\\\\n&= \\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon+\\eta}\n\\frac{\\epsilon\\eta + \\eta u^{2} + \\epsilon u^{2}}{\\epsilon(\\epsilon+u^{2})} \\\\\n&= \\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon+\\eta}\n\\frac{\\epsilon\\eta + (\\eta+ \\epsilon)u^{2}}{\\epsilon(\\epsilon+u^{2})} \\\\\n&= \\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon+\\eta}\n\\frac{(\\rho + u^{2})(\\eta+ \\epsilon)}{\\epsilon(\\epsilon+u^{2})} \\\\\n&= \\frac{u^{2}}{\\epsilon(\\epsilon+u^{2})}\n \\end{split} \n\\label{OS_ERI_eq:4}\n\\end{equation}\nNow let's combine the result in (\\ref{OS_ERI_eq:4}) with the last term in\n\\ref{OS_ERI_eq:3}, then it gives:\n\\begin{equation}\n \\begin{split}\n  \\frac{1}{\\epsilon}-\\frac{u^{2}}{\\epsilon(\\epsilon+u^{2})}  \n= \\frac{1}{\\epsilon}\\left( \\frac{\\epsilon}{\\epsilon+u^{2}}\\right) \n= \\frac{1}{\\epsilon+u^{2}}\n \\end{split}\n\\label{OS_ERI_eq:5}\n\\end{equation}\nWhich is the final result in \\ref{OS_ERI_eq:3}. Here we note, that the result\nin the \\ref{OS_ERI_eq:3} will provide us a chance to link the primitives on \n$r$ and primitives on $r^{'}$ in \\ref{OS_ERI_eq:1}.\n\nNow let's firstly solve this integral of $(a|0_{r^{'}}|b)$. We would apply\nthe recursive relation we got in the \\ref{OS_three_overlap_int_eq:12}:\n\\begin{equation}\n \\begin{split}\n (a+\\iota_{i}|b|c) \n&= (G_{Ai} - A_{i})(a|b|c) + \nN_{i}(A)\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a-\\iota_{i}|b|c) \\\\\n&+ \nN_{i}(B)\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a|b-\\iota_{i}|c) \\\\\n&+\nN_{i}(C)\\left(\\frac{1}{2(\\alpha+\\beta+\\gamma)}\\right)(a|b|c-\\iota_{i}) \n \\end{split}\n\\label{OS_ERI_eq:6}\n\\end{equation}\nHere we extended it to the general form, and the $\\iota_{i}$ and $N_{i}$ are just\nthe same as \\ref{OS_general_int_eq:4} etc. $i$ could be $x,y, z$.\n\nLet's consider to fit it to $(a|0_{r^{'}}|b)$. Here the $\\gamma$ is $u^{2}$, and\nfor the center B (it's the $r^{'}$) we only have a S type of orbital so the\nexpression could be further expressed as:\n\\begin{equation}\n \\begin{split}\n  (a+\\iota_{i}|0_{r^{'}}|b)\n&=(G_{Ai} - A_{i})(a|0_{r^{'}}|b) +\nN_{i}(A)\\left(\\frac{1}{2(\\alpha+\\beta+u^{2})}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+\nN_{i}(B)\\left(\\frac{1}{2(\\alpha+\\beta+u^{2})}\\right)(a|0_{r^{'}}|b-\\iota_{i}) \\\\\n&=(G_{Ai} - A_{i})(a|0_{r^{'}}|b) +\nN_{i}(A)\\left(\\frac{1}{2(\\epsilon+u^{2})}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+\nN_{i}(B)\\left(\\frac{1}{2(\\epsilon+u^{2})}\\right)(a|0_{r^{'}}|b-\\iota_{i})\n \\end{split}\n\\label{OS_ERI_eq:7}\n\\end{equation}\n\nAccording to the \\ref{OS_ERI_eq:3}, $\\dfrac{1}{\\epsilon+u^{2}}$ could be\ndirectly expanded; so the result could be reformed into:\n\\begin{equation}\n \\begin{split}\n  (a+\\iota_{i}|0_{r^{'}}|b)\n&=(G_{Ai} - A_{i})(a|0_{r^{'}}|b) \\\\\n&+\n\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&-\\frac{N_{i}(A)}{2}\\left(\\frac{1}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+ \\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)(a|0_{r^{'}}|b-\\iota_{i}) \\\\\n&-\\frac{N_{i}(B)}{2}\\left(\\frac{1}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}}\\right)(a|0_{r^{'}}|b-\\iota_{i})\n \\end{split}\n\\label{OS_ERI_eq:8}\n\\end{equation}\nThe $\\eta$ and corresponding $\\rho$ could be referred later. Now they are only\narbitrary numbers ($\\rho$ depends on $\\eta$ and $\\epsilon$). \n\nNow we are trying to wrap up some terms in the \\ref{OS_ERI_eq:8} into a new\nform:\n\\begin{equation}\n \\begin{split}\n  &(a|0_{r^{'}}+\\iota_{i}|b) \\\\\n  & =(0_{r^{'}}+\\iota_{i}|a|b)  \\\\\n  &= \\left( \\frac{\\alpha A_{i} + \\beta B_{i} + u^{2}r^{'}_{i}}\n{\\alpha +\\beta + u^{2}} - r^{'}_{i}\\right)(a|0_{r^{'}}|b)\\\\\n&+\nN_{i}(A)\\left(\\frac{1}{2(\\epsilon+u^{2})}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+\nN_{i}(B)\\left(\\frac{1}{2(\\epsilon+u^{2})}\\right)(a|0_{r^{'}}|b-\\iota_{i})\n \\end{split}\n\\label{OS_ERI_eq:9}\n\\end{equation}\nSince\n\\begin{equation}\n \\begin{split}\n  \\frac{\\alpha A_{i} + \\beta B_{i} + u^{2}r^{'}_{i}}\n{\\alpha +\\beta + u^{2}} - r^{'}_{i} = \n \\frac{\\alpha A_{i} + \\beta B_{i} -r^{'}_{i}(\\alpha+\\beta)}\n{\\epsilon + u^{2}} = \\frac{P_{i}\\epsilon -r^{'}_{i}\\epsilon}\n{\\epsilon + u^{2}}\n \\end{split}\n\\end{equation}\nwhere \n\\begin{equation}\n P_{i} = \\frac{\\alpha A_{i} + \\beta B_{i}}{\\alpha+\\beta}\n\\end{equation}\nand $\\epsilon = \\alpha+\\beta$, therefore the \\ref{OS_ERI_eq:9} could be\nexpressed as:\n\\begin{equation}\n \\begin{split}\n&(a|0_{r^{'}}+\\iota_{i}|b) \\\\\n&=-\\frac{\\epsilon}{\\epsilon + u^{2}}(r^{'}_{i} - P_{i})(a|0_{r^{'}}|b) \\\\\n&+\nN_{i}(A)\\left(\\frac{1}{2(\\epsilon+u^{2})}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+\nN_{i}(B)\\left(\\frac{1}{2(\\epsilon+u^{2})}\\right)(a|0_{r^{'}}|b-\\iota_{i})  \n \\end{split}\n\\label{OS_ERI_eq:10}\n\\end{equation}\nHere we note that our purpose here is try to build some expression, which\ncould reduce the integral into some potential recursive forms.\n\nNow we can use the $(a|0_{r^{'}}+\\iota_{i}|b)$ to transform the\n\\ref{OS_ERI_eq:8}:\n\\begin{equation}\n \\begin{split}\n    (a+\\iota_{i}|0_{r^{'}}|b)\n&=(G_{Ai} - A_{i})(a|0_{r^{'}}|b) \\\\\n&+\n\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+ \\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)(a|0_{r^{'}}|b-\\iota_{i}) \\\\\n&-\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}{\\rho+u^{2}}(a|0_{r^{'}}+\\iota_{i}|b) \\\\\n&-\\frac{\\epsilon}{\\epsilon+u^{2}}\n\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}{\\rho+u^{2}}(r^{'}_{i} - P_{i})((a|0_{r^{'}}|b)) \n \\end{split}\n\\label{OS_ERI_eq:11}\n\\end{equation}\n\nNow let's use the relation defined in the \\ref{OS_ERI_eq:3}\nto expand the $(G_{Ai} - A_{i})$. We note that the $G_{Ai}$ is:\n\\begin{equation}\n G_{Ai} = \\frac{\\alpha A_{i} + \\beta B_{i} + u^{2} r^{'}_{i}}{\\alpha + \\beta +\nu^{2}}\n = \\frac{\\alpha A_{i} + \\beta B_{i} + u^{2} r^{'}_{i}}{\\epsilon + u^{2}}\n\\end{equation}\nHence, for $(G_{Ai} - A_{i})$ according to \\ref{OS_ERI_eq:3} it's:\n\\begin{equation}\n \\begin{split}\n G_{Ai} - A_{i} &= \\left( \\frac{\\alpha A_{i} + \\beta B_{i}}{\\epsilon} -\nA_{i}\\right) +\n\\frac{u^{2} r^{'}_{i}}{\\epsilon} \\\\\n&-(\\alpha A_{i} + \\beta B_{i} + u^{2} r^{'}_{i})\\left(\\frac{\\rho}{\\epsilon^{2}}\n\\frac{u^{2}}{\\rho+u^{2}} + \\frac{1}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}} \n\\right)  \\\\\n&= \\left( P_{i} - A_{i}\\right) + \\frac{u^{2} r^{'}_{i}}{\\epsilon} \\\\\n&-\\left( \\frac{u^{2}r^{'}_{i}}{\\epsilon} + P_{i}\\right)\n\\left(\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}} + \\frac{\\epsilon}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}} \n\\right) \n \\end{split}\n\\label{OS_ERI_eq:12}\n\\end{equation}\n\nNow let's combine the terms for the $(a|0_{r^{'}}|b)$ in the \\ref{OS_ERI_eq:11}\nand \\ref{OS_ERI_eq:12}. For the $P_{i}$ term, we can see that:\n\\begin{equation}\n \\left( P_{i} - A_{i}\\right)(a|0_{r^{'}}|b) \n-P_{i}\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}(a|0_{r^{'}}|b)\n\\label{OS_ERI_eq:13}\n\\end{equation}\nthe terms for the $\\dfrac{\\epsilon}{\\epsilon+\\eta}\n\\dfrac{u^{2}}{\\epsilon+u^{2}}\\dfrac{u^{2}}{\\rho+u^{2}} $ canceled. \n\nFor the $r_{i}^{'}$, the remaining terms are:\n\\begin{equation}\n \\begin{split}\n&\\frac{u^{2} r^{'}_{i}}{\\epsilon}\n-\\frac{u^{2}r^{'}_{i}}{\\epsilon}\n\\left(\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}} + \\frac{\\epsilon}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}} \n\\right) \\\\\n&-\\frac{\\epsilon}{\\epsilon+u^{2}}\n\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}{\\rho+u^{2}}r^{'}_{i} \n \\end{split}\n\\end{equation}\nWe do not include the integral of $(a|0_{r^{'}}|b)$ here since they are similar\nterms in terms of $(a|0_{r^{'}}|b)$.\n\nHere we have:\n\\begin{equation}\n\\frac{\\epsilon}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\epsilon+u^{2}}\\frac{u^{2}}{\\rho+u^{2}}\\left(\n1+\\frac{u^{2}}{\\epsilon} \\right)r^{'}_{i} = \n\\frac{u^{2}}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\rho+u^{2}}r^{'}_{i} \n\\end{equation}\nThen\n\\begin{equation}\n\\begin{split}\n&\\frac{u^{2}}{\\epsilon+\\eta}\n\\frac{u^{2}}{\\rho+u^{2}}r^{'}_{i} + \n\\frac{u^{2}r^{'}_{i}}{\\epsilon}\n\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}} = \\\\\n&{u^{2}}r^{'}_{i}\n\\frac{u^{2}}{\\rho+u^{2}}\\left(\\frac{1}{\\epsilon+\\eta} + \n\\frac{\\rho}{\\epsilon^{2}} \\right) \\\\\n&= {u^{2}}r^{'}_{i}\n\\frac{u^{2}}{\\rho+u^{2}}\\left(\\frac{1}{\\epsilon+\\eta} + \n\\frac{1}{\\epsilon+\\eta}\\frac{\\eta}{\\epsilon} \\right) \\\\\n&= {u^{2}}r^{'}_{i}\n\\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon}\n\\end{split}\n\\end{equation}\nFinally\n\\begin{equation}\n\\frac{u^{2} r^{'}_{i}}{\\epsilon}\n-{u^{2}}r^{'}_{i}\n\\frac{u^{2}}{\\rho+u^{2}}\\frac{1}{\\epsilon} = r^{'}_{i}\n\\frac{u^{2}}{\\rho+u^{2}}\\frac{\\rho}{\\epsilon}\n\\end{equation}\nSurprisingly, this term is directly corresponding to the terms for $P_{i}$\nin the \\ref{OS_ERI_eq:13}, so totally we have the result that:\n\\begin{equation}\n\\begin{split}\n&(G_{Ai} - A_{i})(a|0_{r^{'}}|b)\n-\\frac{\\epsilon}{\\epsilon+u^{2}}\n\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}{\\rho+u^{2}}(r^{'}_{i} -\nP_{i})(a|0_{r^{'}}|b)  \\\\\n&= \\left( P_{i} - A_{i}\\right)(a|0_{r^{'}}|b) + \n(r^{'}_{i}-P_{i})\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}(a|0_{r^{'}}|b)\n\\end{split}\n\\label{OS_ERI_eq:14}\n\\end{equation}\n \nBy using the \\ref{OS_ERI_eq:14}, the \\ref{OS_ERI_eq:8} could be finally\nexpressed as:\n\\begin{equation}\n \\begin{split}\n  (a+\\iota_{i}|0_{r^{'}}|b)\n&=(P_{i} - A_{i})(a|0_{r^{'}}|b) \\\\\n&+\n\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+ \\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)(a|0_{r^{'}}|b-\\iota_{i}) \\\\\n&+(r^{'}_{i}-P_{i})\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}(a|0_{r^{'}}|b) \n-\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}{\\rho+u^{2}}(a|0_{r^{'}}+\\iota_{i}|b)\n \\end{split}\n\\label{OS_ERI_eq:15}\n\\end{equation}\n\nNow let's set the value of $\\eta$ and $\\rho$, so that to make the $(a+\\iota_{i}|0_{r^{'}}|b)$\nrelated to the outer integral on $\\chi_{c}$ and $\\chi_{d}$:\n\\begin{equation}\n \\label{OS_ERI_eq:16}\n\\eta = \\alpha^{'} + \\beta^{'} \n\\end{equation}\nwhere $\\alpha^{'}$ is the exponent factor for $\\chi_{c}$, and $\\beta^{'}$ is the exponent\nfactor for $\\chi_{d}$. Therefore, the $\\rho$ could be expressed as:\n\\begin{equation}\n \\label{OS_ERI_eq:17}\n\\rho = \\frac{(\\alpha+\\beta)(\\alpha^{'} + \\beta^{'})}{(\\alpha+\\beta)+(\\alpha^{'} + \\beta^{'})} \n\\end{equation}\n\nLet's consider the outer integral over $r^{'}$, it's easy to see that:\n\\begin{equation}\n\\label{OS_ERI_eq:18}\n -\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}} +\\iota_{i} |b)\n= \\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r} + \\iota_{i}|d)\n\\end{equation}\nThis is because that for the term of $0_{r} + \\iota_{i}$, which is converted from\n$r^{'}_{i} - r_{i}$ into $r_{i}-r^{'}_{i}$.Therefore, for the term of \n$\\dfrac{u^{2}}{\\epsilon+\\eta}\\dfrac{u^{2}}\n{\\rho+u^{2}}(a|0_{r^{'}}+\\iota_{i}|b)$ in the integral it could be converted into:\n\\begin{equation}\n \\label{OS_ERI_eq:19}\n\\begin{split}\n&-\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}+\\iota_{i}|b) \\\\\n&=\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)u^{2}(c|0_{r}+\\iota_{i}|d)\n\\end{split}\n\\end{equation}\nWhile according to the \\ref{OS_ERI_eq:10}, the term of $u^{2}(c|0_{r}+\\iota_{i}|d)$\nis:\n\\begin{equation}\n \\begin{split}\n  u^{2}(c|0_{r}+\\iota_{i}|d) &= \n-\\eta(r_{i} - Q_{i})(c|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(C)}{2}\\right)(c-\\iota_{i}|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(D)}{2}\\right)(c|0_{r}|d-\\iota_{i}) \\\\\n&-\\eta(c|0_{r}+\\iota_{i}|d)\n \\end{split}\n\\label{OS_ERI_eq:20}\n\\end{equation}\nand \n\\begin{equation}\n Q_{i} = \\frac{\\alpha^{'}C + \\beta^{'}D}{\\alpha^{'} + \\beta^{'}}\n\\end{equation}\n\nNow let's take the result of \\ref{OS_ERI_eq:20} into \\ref{OS_ERI_eq:19}, it's:\n\\begin{equation}\n \\begin{split}\n  &-\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}+\\iota_{i}|b) \\\\\n&=Q_{i}\\frac{\\eta}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c-\\iota_{i}|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d-\\iota_{i}) \\\\\n&-\\eta \\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r) r_{i} (c|0_{r}|d) \\\\\n&-\\eta\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}+\\iota_{i}|d)\n \\end{split}\n\\label{OS_ERI_eq:21}\n\\end{equation}\n\nNow let's look into the details of \\ref{OS_ERI_eq:21}. In terms of its last\ntwo terms, actually we have:\n\\begin{equation}\n \\begin{split}\n r_{i}(c|0_{r}|d) +(c|0_{r}+\\iota_{i}|d) \n&=\n\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\nr_{i}e^{u^{2}(r^{'}-r)^{2}} \\\\\n&+ \n\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\n(r^{'}_{i}-r_{i})e^{u^{2}(r^{'}-r)^{2}}\n \\end{split}\n\\label{OS_ERI_eq:22}\n\\end{equation}\nHere according to our traditional notation (see \\ref{OS_three_overlap_int_eq:4}),\n$r$ and $r^{'}$ represent the points in the space, and $i$ denotes its components\non the X, Y or Z axis. Therefore, it's clear that:\n\\begin{equation}\n  r_{i}(c|0_{r}|d) +(c|0_{r}+\\iota_{i}|d) =\n\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\nr^{'}_{i}e^{u^{2}(r^{'}-r)^{2}}\n\\label{OS_ERI_eq:23}\n\\end{equation}  \nIf we go over integral by $r$, it yields:\n\\begin{equation}\n\\begin{split}\n&\\int dr \\chi_{a}(r)\\chi_{b}(r) \\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\nr^{'}_{i}e^{(r^{'}-r)^{2}} \\\\\n&= \\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'}) r^{'}_{i}\n\\int dr \\chi_{a}(r)\\chi_{b}(r) e^{u^{2}(r^{'}-r)^{2}} \\\\\n&= \\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'}) r^{'}_{i}(a|0_{r^{'}}|b)\n\\end{split}\n\\label{OS_ERI_eq:24}\n\\end{equation}\nTherefore the \\ref{OS_ERI_eq:21} could be converted into:\n\\begin{equation}\n \\begin{split}\n  &-\\frac{u^{2}}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}+\\iota_{i}|b) \\\\\n&=Q_{i}\\frac{\\eta}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c-\\iota_{i}|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d-\\iota_{i}) \\\\\n&-\\eta \\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'}) r^{'}_{i}(a|0_{r^{'}}|b)\n \\end{split}\n\\label{OS_ERI_eq:25}\n\\end{equation}\n\nNow let's combine the result in \\ref{OS_ERI_eq:25} with the result in \\ref{OS_ERI_eq:15}.\nBy multiplying $\\chi_{c}$ and $\\chi_{d}$ and integrate over $r^{'}$ in \n\\ref{OS_ERI_eq:15}, we can get:\n\\begin{equation}\n \\begin{split}\n&\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a+\\iota_{i}|0_{r^{'}}|b) \\\\\n&=(P_{i} - A_{i})\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}|b) \\\\\n&+\n\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\n(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+ \\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\n(a|0_{r^{'}}|b-\\iota_{i}) \\\\\n&-P_{i}\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}|b) \\\\\n&+\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})r^{'}_{i}(a|0_{r^{'}}|b) \\\\\n&+Q_{i}\\frac{\\eta}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c-\\iota_{i}|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d-\\iota_{i}) \\\\\n&-\\eta \\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'}) r^{'}_{i}(a|0_{r^{'}}|b) \\\\\n&= (P_{i} - A_{i})\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}|b) \\\\\n&+\n\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\n(a-\\iota_{i}|0_{r^{'}}|b) \\\\\n&+ \\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})\n(a|0_{r^{'}}|b-\\iota_{i}) \\\\\n&+\\left(W_{i} -P_{i}\\right)\n\\frac{u^{2}}{\\rho+u^{2}}\\int dr^{'} \\chi_{c}(r^{'})\\chi_{d}(r^{'})(a|0_{r^{'}}|b) \\\\\n&+\n\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c-\\iota_{i}|0_{r}|d) \\\\\n&+\n\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}\\int dr \\chi_{a}(r)\\chi_{b}(r)(c|0_{r}|d-\\iota_{i}) \n \\end{split}\n\\label{OS_ERI_eq:26}\n\\end{equation}\nWhere in this long expression, it's clear that the integral term containing\n$r^{'}_{i}$ vanished, and we combine the terms of $P_{i}$ and $Q_{i}$ together\nso to give $W_{i}$:\n\\begin{equation}\n W_{i} = \\frac{\\epsilon P_{i} + \\eta Q_{i}}{\\epsilon + \\eta}\n\\end{equation}\nWe note, that this surprising result has very beautiful symmetry among the \nresulting integrals.\n\nBy using the expression of $(ab|u|cd)$ in \\ref{OS_ERI_eq:2}, the expression for\nthe \\ref{OS_ERI_eq:26} could be further simplified as:\n\\begin{equation}\n \\begin{split}\n((a+\\iota_{i})b|u|cd) &= (P_{i} - A_{i})(ab|u|cd) +\n\\left(W_{i} -P_{i}\\right)\n\\frac{u^{2}}{\\rho+u^{2}}(ab|u|cd) \\\\\n&+\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)\n((a-\\iota_{i})b|u|cd) \\\\\n&+\\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{u^{2}}{\\rho+u^{2}}\\right)\n(a(b-\\iota_{i})|u|cd) \\\\\n&+\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}(ab|u|(c-\\iota_{i})d) \\\\\n&+\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{u^{2}}\n{\\rho+u^{2}}(ab|u|c(d-\\iota_{i}))\n\\end{split}\n\\label{OS_ERI_eq:27}\n\\end{equation}\n\nNow let's define some auxiliary integral function:\n\\begin{equation}\n\\label{OS_ERI_eq:28}\n (ab|cd)^{(m)} = \\frac{2}{\\sqrt{\\pi}}\\int^{\\infty}_{0} du \\left( \\frac{u^{2}}\n{\\rho+u^{2}}\\right)^{m}(ab|u|cd) \n\\end{equation}\nThen by multiplying with $\\left( \\dfrac{u^{2}}\n{\\rho+u^{2}}\\right)^{m}$ and integrating over $u$\nthe above result could be written as:\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{OS_ERI_result}\n\\end{equation}\nWe note that the true ERI is $(ab|cd)^{(0)}$. This is the final result \nfor deriving the ERI in the OS framework.\n\nFinally, let's make some complementary work. In the \\ref{OS_ERI_result},\nit's clear all of integrals could be derived from the basic integral of\n$(00|00)^{(m)}$, which is in form of:\n\\begin{equation}\n \\begin{split}\n (00|00)^{(m)} &= \\frac{2}{\\sqrt{\\pi}} \\int_{0}^{\\infty} du \\left( \\frac{u^{2}}\n{\\rho+u^{2}}\\right)^{m} (00|u|00) \\\\\n&=\\frac{2}{\\sqrt{\\pi}} \\int_{0}^{\\infty} du \\left( \\frac{u^{2}}\n{\\rho+u^{2}}\\right)^{m} \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^{-(r-r^{'})^{2}u^{2}} \n\\end{split}\n\\end{equation}\nAs for the integral over $r$, by using the three body integral result in\n\\ref{OS_bottom_three_overlap_int_2}, we can rewrite it as:\n\\begin{equation}\n \\begin{split}\n  \\int dr  e^{-\\alpha r_{A}^{2}} e^{-\\beta r_{B}^{2}} e^{-(r-r^{'})^{2}u^{2}} &=\n  (0_{A}|0_{B})\\left( \\frac{\\alpha+\\beta}{\\alpha+\\beta+u^{2}}\\right)^{\\frac{3}{2}}\ne^{-\\frac{(\\alpha+\\beta)u^{2}}{\\alpha+\\beta+u^{2}}|r^{'}-P|^{2}} \n \\end{split}\n \\label{OS_ERI_eq:30}\n\\end{equation}\nThis is equivalent to treat $e^{(r-r^{'})^{2}u^{2}}$ as a S type of Gaussian, where\nthe electron in $r$ centers on ``nuclei'' of $r^{'}$.\n\nThe RHS of \\ref{OS_ERI_eq:30} is still like a Gaussian of $r^{'}$ centering\non $P$, so once again by using the \\ref{OS_bottom_three_overlap_int_2};\nit's able to integrate over $r^{'}$. Before we move on, let's do some prepare\nwork. Firstly, considering the combination of Gaussian on $P$ and Gaussian\non $C$ and $D$, for the exponent coefficient it gives:\n\\begin{equation}\n \\begin{split}\n  \\frac{\\frac{(\\alpha+\\beta)u^{2}}{\\alpha+\\beta+u^{2}}\\times\n  (\\alpha^{'}+\\beta^{'})}{\\frac{(\\alpha+\\beta)u^{2}}{\\alpha+\\beta+u^{2}} \n  +\\alpha^{'}+\\beta^{'}} \n  &= \\frac{(\\alpha^{'}+\\beta^{'})(\\alpha+\\beta)u^{2}}\n  {(\\alpha+\\beta+u^{2})(\\alpha^{'}+\\beta^{'})+(\\alpha+\\beta)u^{2}} \\\\\n  &= \\frac{u^{2}}{1+\\frac{u^{2}}{\\alpha+\\beta}+\\frac{u^{2}}{\\alpha^{'}+\\beta^{'}}} \\\\\n  &= \\frac{u^{2}}{1+u^{2}\\left( \\frac{1}{\\alpha+\\beta}+\\frac{1}{\\alpha^{'}+\\beta^{'}}\n  \\right) } \\\\\n  &= \\frac{u^{2}}{1+\\frac{u^{2}}{\\rho}} \\\\\n  &= \\frac{\\rho u^{2}}{\\rho+ u^{2}}\n \\end{split}\n \\label{OS_ERI_eq:31}\n \\end{equation}\n Here we use the definition for variable of $\\rho$ in \\ref{OS_ERI_eq:17}.\n \n So the integral over $r^{'}$ becomes:\n\\begin{equation}\n \\begin{split}\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^{-(r-r^{'})^{2}u^{2}} \\\\\n&= (0_{A}|0_{B})\\left( \\frac{\\alpha+\\beta}{\\alpha+\\beta+u^{2}}\\right)^{\\frac{3}{2}}   \n  \\int dr^{'}  e^{-\\alpha^{'} (r^{'}_{C})^{2}}e^{-\\beta^{'} (r^{'}_{D})^{2}} \n   e^{-\\frac{(\\alpha+\\beta)u^{2}}{\\alpha+\\beta+u^{2}}|r^{'}-P|^{2}} \\\\\n&= (0_{A}|0_{B})(0_{C}|0_{D})\n\\left( \\frac{\\alpha+\\beta}{\\alpha+\\beta+u^{2}}\\right)^{\\frac{3}{2}} \n\\left( \\frac{\\alpha^{'}+\\beta^{'}}{\\alpha^{'}+\\beta^{'}+ \n\\frac{(\\alpha+\\beta)u^{2}}{\\alpha+\\beta+u^{2}}}\\right)^{\\frac{3}{2}}\ne^{-\\frac{\\rho u^{2}}{\\rho+ u^{2}}|PQ|^{2}}\n\\end{split} \n\\label{OS_ERI_eq:32}\n\\end{equation}\nThis is using the result of \\ref{OS_ERI_eq:31}. Combing the term in \\ref{OS_ERI_eq:32},\nit gives:\n\\begin{equation}\n\\begin{split}\n &\\left( \\frac{\\alpha+\\beta}{\\alpha+\\beta+u^{2}}\\right)^{\\frac{3}{2}} \n\\left( \\frac{\\alpha^{'}+\\beta^{'}}{\\alpha^{'}+\\beta^{'}+ \n\\frac{(\\alpha+\\beta)u^{2}}{\\alpha+\\beta+u^{2}}}\\right)^{\\frac{3}{2}} \\\\\n&= \\left( \\frac{(\\alpha+\\beta)(\\alpha^{'}+\\beta^{'})}\n{(\\alpha+\\beta+u^{2})(\\alpha^{'}+\\beta^{'})+(\\alpha+\\beta)u^{2}}\\right)^{\\frac{3}{2}}\\\\\n&= \\left(\\frac{1}{1+\\frac{u^{2}}{\\rho}}\\right)^{\\frac{3}{2}} \\\\\n&= \\left(\\frac{\\rho}{\\rho+u^{2}}\\right)^{\\frac{3}{2}}\n\\end{split}\n \\label{OS_ERI_eq:33}\n\\end{equation}\nSo after integrate over $r$ and $r^{'}$ the bottom integral becomes:\n\\begin{equation}\n \\begin{split}\n (00|00)^{(m)} &=\\frac{2}{\\sqrt{\\pi}}(0_{A}|0_{B})(0_{C}|0_{D})\n \\int_{0}^{\\infty} du \\left( \\frac{u^{2}}{\\rho+u^{2}}\\right)^{m}\n \\left(\\frac{\\rho}{\\rho+u^{2}}\\right)^{\\frac{3}{2}}\n e^{-\\frac{\\rho u^{2}}{\\rho+ u^{2}}|PQ|^{2}} \n \\end{split}\n\\label{OS_ERI_eq:34}\n\\end{equation}\nIf we set $t^{2} = \\frac{u^{2}}{\\rho+ u^{2}}$, and it's easy to know\nthat \n\\begin{equation}\n du = (1-t^{2})^{-\\frac{3}{2}}\\rho^{1/2} dt\n \\label{OS_ERI_eq:35}\n\\end{equation}\nso \\ref{OS_ERI_eq:34} becomes:\n\\begin{equation}\n \\begin{split}\n (00|00)^{(m)} &= 2\\left( \\frac{\\rho}{\\pi}\\right)^{\\frac{1}{2}}(0_{A}|0_{B})\n(0_{C}|0_{D})\\int^{1}_{0} t^{2m} e^{-(\\rho|PQ|^{2})t^{2}} dt \n \\end{split}\n\\label{OS_ERI_complementary_result}\n\\end{equation}\n\nWhere we have the arguments as:\n\\begin{align}\n \\overrightarrow{P} &= \\frac{\\alpha \\overrightarrow{A} + \\beta\n\\overrightarrow{B}}{\\alpha + \\beta} \\nonumber \\\\\n\\overrightarrow{Q} &= \\frac{\\alpha^{'} \\overrightarrow{C} + \\beta^{'}\n\\overrightarrow{D}}{\\alpha^{'} + \\beta^{'}} \\nonumber \\\\\n\\rho &= \\frac{(\\alpha+\\beta)(\\alpha^{'}+\\beta^{'})}\n{(\\alpha+\\beta)+(\\alpha^{'}+\\beta^{'})}\n\\end{align}\n    \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Overlap Integral}\n%\n%\n%\nthe basic overlap integral is:\n\\begin{equation}\n \\label{OS_overlap_eq:1}\nI = \\int dr \\chi_{a}(r) \\chi_{b}(r)\n\\end{equation}\n\nBy using the recursive relation derived in the three center overlap\nintegral (see \\ref{OS_three_overlap_int_eq:12}), set the middle Gaussian\nprimitive to be zero; we can get the recursive relation for overlap:\n\\begin{equation}\n\\begin{split}\n(a+\\iota_{i}|b) &= \n(P_{i} - A_{i})(a|b) + \nN_{i}(A)\\left(\\frac{1}{2(\\alpha+\\beta)}\\right)(a-\\iota_{i}|b) \\\\\n&+ \nN_{i}(B)\\left(\\frac{1}{2(\\alpha+\\beta)}\\right)(a|b-\\iota_{i})  \n\\end{split}\n\\label{OS_overlap_result}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Derivatives of Basis Sets in Overlap}\n%\n%\n%\nBefore we derive the recursive relation for kinetic energy, let's firstly \ngo to see another type of integral of \n$\\left( \\dfrac{\\partial a}{\\partial x}|b\\right)$.\n\nFirstly, we note that the derivatives can not directly be applied to the \nrecursive relation like \\ref{OS_overlap_result}:\n\\begin{equation}\n\\begin{split}\n(\\frac{\\partial (a+\\iota_{i})}{\\partial x}|b) & \\neq \n(P_{i} - A_{i})(\\frac{\\partial a}{\\partial x}|b) + \nN_{i}(A)\\left(\\frac{1}{2(\\alpha+\\beta)}\\right)(\\frac{\\partial(a-\\iota_{i})}{\\partial x}|b) \\\\\n&+ \nN_{i}(B)\\left(\\frac{1}{2(\\alpha+\\beta)}\\right)(\\frac{\\partial a}{\\partial x}|b-\\iota_{i})  \n\\end{split}\n\\end{equation}\n\nLet's prove this with some simple example. Suggest we have two Gaussian \nprimitives:\n\\begin{align}\n \\chi_{i} &= x^{l_{i}}y^{m_{i}}z^{n_{i}} e^{-\\alpha_{i} r^{2}} \\nonumber \\\\\n \\chi_{j} &= x^{l_{j}}y^{m_{j}}z^{n_{j}} e^{-\\alpha_{j} r^{2}} \\nonumber \\\\\n \\gamma   &= \\alpha_{i} + \\alpha_{j}\n \\end{align}\n\nAccording to the \\ref{derivative_overlap_direct_int_eq:2} and recursive relation\nfor the overlap integral, we can have:\n\\begin{equation}\n \\begin{split}\n \\left(\\frac{\\partial \\chi_{i}}{\\partial x}|\\chi_{j}\\right)  &= \n l_{i}(\\chi_{i}^{l-1mn}|\\chi_{j}) - 2\\alpha_{i} (\\chi_{i}^{l+1mn}|\\chi_{j}) \\\\\n &= l_{i}\\left[ PA_{k}(\\chi_{i}^{l-1mn}-\\iota_{k}|\\chi_{j}) + \n \\frac{N_{k}(A)}{2 \\gamma}(\\chi_{i}^{l-1mn}-2\\iota_{k}|\\chi_{j})  \\right. \\\\ \n &+ \\left. \\frac{N_{k}(B)}{2 \\gamma}(\\chi_{i}^{l-1mn}-\\iota_{k}|\\chi_{j}-\\iota_{k})\n \\right] \\\\\n &-2\\alpha_{i} \\left[ PA_{k}(\\chi_{i}^{l+1mn}-\\iota_{k}|\\chi_{j}) + \n \\frac{N_{k}(A)}{2 \\gamma}(\\chi_{i}^{l+1mn}-2\\iota_{k}|\\chi_{j}) \\right. \\\\ \n &+ \\left. \\frac{N_{k}(B)}{2 \\gamma}(\\chi_{i}^{l+1mn}-\\iota_{k}|\\chi_{j}-\\iota_{k})\n \\right] \n \\end{split}\n \\label{deriv_os_overlap:1}\n\\end{equation}\nHere the index of $i$ and $j$ are omitted for l, m and n. If the l, m and n do not \nchange, they are not listed neither.\n\nIt's easy to see that if $k = y$ or $k = z$ then the above equation could be \nwritten as:\n\\begin{equation}\n \\begin{split}\n  \\left(\\frac{\\partial \\chi_{i}}{\\partial x}|\\chi_{j}\\right)  &= \n l_{i}(\\chi_{i}^{l-1mn}|\\chi_{j}) - 2\\alpha_{i} (\\chi_{i}^{l+1mn}|\\chi_{j}) \\\\ \n &=  PA_{k}(\\frac{\\partial(\\chi_{i}^{lmn}-\\iota_{k})}{\\partial x}|\\chi_{j}) + \n \\frac{N_{k}(A)}{2 \\gamma}(\\frac{\\partial(\\chi_{i}^{lmn}-2\\iota_{k})}{\\partial x}|\\chi_{j}) \n \\\\ \n &+ \\frac{N_{k}(B)}{2 \\gamma}\n (\\frac{\\partial (\\chi_{i}^{lmn}-\\iota_{k}) }{\\partial x}|\\chi_{j}-\\iota_{k}) \n \\end{split}\n\\end{equation}\nHowever, if $k = x$, the above equation does not hold.\n\nFor $k = x$, the \\ref{deriv_os_overlap:1} could be expressed as:\n\\begin{equation}\n \\begin{split}\n \\left(\\frac{\\partial \\chi_{i}}{\\partial x}|\\chi_{j}\\right)  &= \n l_{i}(\\chi_{i}^{l-1mn}|\\chi_{j}) - 2\\alpha_{i} (\\chi_{i}^{l+1mn}|\\chi_{j}) \\\\\n &= l_{i}\\left[ PA_{x}(\\chi_{i}^{l-2mn}|\\chi_{j}) + \n \\frac{N_{x}(A)}{2 \\gamma}(\\chi_{i}^{l-3mn}|\\chi_{j})  \\right. \\\\ \n &+ \\left. \\frac{N_{x}(B)}{2 \\gamma}(\\chi_{i}^{l-2mn}|\\chi_{j}^{l-1mn})\n \\right] \\\\\n &-2\\alpha_{i} \\left[ PA_{x}(\\chi_{i}|\\chi_{j}) + \n \\frac{N_{x}(A)}{2 \\gamma}(\\chi_{i}^{l-1mn}|\\chi_{j}) \\right. \\\\ \n &+ \\left. \\frac{N_{x}(B)}{2 \\gamma}(\\chi_{i}|\\chi_{j}^{l-1mn})\n \\right] \\\\\n &= PA_{x} \\left( l_{i}(\\chi_{i}^{l-2mn}|\\chi_{j}) -2\\alpha_{i} (\\chi_{i}|\\chi_{j}) \n \\right) \\\\\n &+ \\frac{N_{x}(A)}{2 \\gamma}\\left(\n l_{i}(\\chi_{i}^{l-3mn}|\\chi_{j}) -2\\alpha_{i} (\\chi_{i}^{l-1mn}|\\chi_{j})\n \\right) \\\\\n &+ \\frac{N_{x}(B)}{2 \\gamma}\\left(\n l_{i}(\\chi_{i}^{l-2mn}|\\chi_{j}^{l-1mn}) -2\\alpha_{i} (\\chi_{i}|\\chi_{j}^{l-1mn})\n \\right) \\\\\n &= PA_{x} (\\frac{\\partial \\chi_{i}^{l-1mn}}{\\partial x}|\\chi_{j}) + \n PA_{x} (\\chi_{i}^{l-1mn}|\\chi_{j}) \\\\\n &+ \\frac{N_{x}(A)}{2 \\gamma}(\\frac{\\partial \\chi_{i}^{l-2mn}}{\\partial x}|\\chi_{j})\n + 2\\frac{N_{x}(A)}{2 \\gamma}(\\chi_{i}^{l-2mn}|\\chi_{j}) \\\\\n &+ \\frac{N_{x}(B)}{2 \\gamma}(\\frac{\\partial \\chi_{i}^{l-1mn}}{\\partial x}|\\chi_{j}^{l-1mn})\n + \\frac{N_{x}(B)}{2 \\gamma}(\\chi_{i}^{l-1mn}|\\chi_{j}^{l-1mn}) \\\\\n &= PA_{x} (\\frac{\\partial \\chi_{i}^{l-1mn}}{\\partial x}|\\chi_{j}) + \n \\frac{N_{x}(A)}{2 \\gamma}(\\frac{\\partial \\chi_{i}^{l-2mn}}{\\partial x}|\\chi_{j}) \\\\\n &+ \\frac{N_{x}(B)}{2 \\gamma}(\\frac{\\partial \\chi_{i}^{l-1mn}}{\\partial x}|\\chi_{j}^{l-1mn}) \\\\\n &+ PA_{x} (\\chi_{i}^{l-1mn}|\\chi_{j}) + \\frac{N_{x}(A)}{2 \\gamma}(\\chi_{i}^{l-2mn}|\\chi_{j}) \\\\\n &+ \\frac{N_{x}(B)}{2 \\gamma}(\\chi_{i}^{l-1mn}|\\chi_{j}^{l-1mn}) \\\\\n &+ \\frac{N_{x}(A)}{2 \\gamma}(\\chi_{i}^{l-2mn}|\\chi_{j})\n \\end{split}\n \\label{deriv_os_overlap:2}\n\\end{equation}\nTherefore, we have additional terms in \\ref{deriv_os_overlap:2}.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Kinetic Energy Integral}\n%\n%\n%\nAccording to the \\ref{kinetic_direct_int_eq:2}, the kinetic energy integral is:\n\\begin{align}\n \\label{OS_kinetic_eq:1}\nI &= \\frac{1}{2}\\int dr (\\nabla\\chi_{i}(r)) \\cdotp (\\nabla\\chi_{j}(r)) \\nonumber \\\\\n  &= \\frac{1}{2}\\int d x \\frac{\\partial \\chi_{i}(r)}{\\partial x}\n  \\frac{\\partial \\chi_{j}(r)}{\\partial x} \n  +  \\frac{1}{2}\\int d y \\frac{\\partial \\chi_{i}(r)}{\\partial y}\n  \\frac{\\partial \\chi_{j}(r)}{\\partial y} \n  +  \\frac{1}{2}\\int d z \\frac{\\partial \\chi_{i}(r)}{\\partial z}\n  \\frac{\\partial \\chi_{j}(r)}{\\partial z} \n\\end{align}\nSo the kinetic integral is actually a linear combination of overlap integrals,\nand the kinetic integral itself could be decomposed into three integrals sum:\n\\begin{equation}\n I = I_{x} + I_{y} + I_{z}\n\\end{equation}\nIn the following derivation, we will concentrate on one component, which is \nin general named as $I_{i}$.\n\nFor a general Gaussian primitive function of $\\chi = x^{l}y^{m}z^{n}e^{-\\alpha r^{2}}$, who \ncenters on $A$; we can express its derivatives as:\n\\begin{align}\n \\frac{\\partial \\chi^{lmn}_{A}}{\\partial v} &= \n N_{i}(A)(\\chi_{A}^{lmn}-\\iota_{i}) - 2\\alpha(\\chi_{A}^{lmn}+\\iota_{i}) \\nonumber \\\\\n &= N_{i}(A)(-1)_{i} - 2\\alpha(+1)_{i}\n \\label{OS_kinetic_eq:0}\n\\end{align}\n$v$ denotes the possible derivatives, could be x, y or z. \n\nTherefore, suggest that in \\ref{OS_kinetic_eq:1} the $\\chi_{i}$ resides \non $A$ with $\\alpha$ exponential factor, and $\\chi_{j}$ is on $B$ with\n$\\beta$ exponential factor; we can have:\n\\begin{equation}\n\\begin{split}\n\\left(  \\frac{\\partial \\chi_{A}}{\\partial v}|\\frac{\\partial \\chi_{B}}{\\partial v}\n\\right)  &= N_{i}(A)N_{i}(B)(-1|-1)_{i} -2\\alpha N_{i}(B)(+1|-1)_{i} \\\\\n&-2\\beta N_{i}(A)(-1|+1)_{i} + 4\\alpha\\beta(+1|+1)_{i}\n\\end{split}\n\\label{OS_kinetic_eq:2}\n\\end{equation}\nthe $i$ is determined from the v. If v is x, then $N_{i}(A) = l_{A}$ and \n$N_{i}(B) = l_{B}$; if v is y, then $N_{i}(A) = m_{A}$ and \n$N_{i}(B) = m_{B}$ and if v is z, then $N_{i}(A) = n_{A}$ and \n$N_{i}(B) = n_{B}$. \n\nBy expanding all of overlap integrals into its RR form, we can have:\n\\begin{equation}\n \\begin{split}\n \\left(  \\frac{\\partial \\chi_{A}}{\\partial v}|\\frac{\\partial \\chi_{B}}{\\partial v}\n\\right)  &=  N_{i}(A)N_{i}(B)\n\\left[ PA_{k}(-1-\\iota_{k}|-1)_{i} + \\frac{N_{k}(A)}{2 \\gamma}(-1-2\\iota_{k}|-1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{k}(B)}{2 \\gamma}(-1-\\iota_{k}|-1-\\iota_{k})_{i} \\right] \\\\\n&- 2\\alpha N_{i}(B)\n\\left[ PA_{k}(+1-\\iota_{k}|-1)_{i} + \\frac{N_{k}(A)}{2 \\gamma}(+1-2\\iota_{k}|-1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{k}(B)}{2 \\gamma}(+1-\\iota_{k}|-1-\\iota_{k})_{i} \\right] \\\\ \n&- 2\\beta  N_{i}(A)\n\\left[ PA_{k}(-1-\\iota_{k}|+1)_{i} + \\frac{N_{k}(A)}{2 \\gamma}(-1-2\\iota_{k}|+1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{k}(B)}{2 \\gamma}(-1-\\iota_{k}|+1-\\iota_{k})_{i} \\right] \\\\  \n&+ 4\\alpha\\beta\n\\left[ PA_{k}(+1-\\iota_{k}|+1)_{i} + \\frac{N_{k}(A)}{2 \\gamma}(+1-2\\iota_{k}|+1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{k}(B)}{2 \\gamma}(+1-\\iota_{k}|+1-\\iota_{k})_{i} \\right] \n \\end{split}\n \\label{OS_kinetic_eq:3}\n\\end{equation}\nwhere $\\gamma = \\alpha + \\beta$. $k$ denotes possible RR direction, which is \nalso x, y or z. $k$ is different from the $v$ here.\n\nFirstly, let's go to see a simple case that the derivatives direction $i$ is not\nsame with RR direction $k$. It's easy to see, in this case the above result\nturns into:\n\\begin{equation}\n \\begin{split}\n \\left(  \\frac{\\partial \\chi_{A}}{\\partial v}|\\frac{\\partial \\chi_{B}}{\\partial v}\n\\right)  &= PA_{k}\n \\left(\\frac{\\partial (\\chi_{A}-\\iota_{k})}{\\partial v}|\n \\frac{\\partial \\chi_{B}}{\\partial v} \\right) + \n\\frac{N_{k}(A)}{2 \\gamma}\n \\left(\\frac{\\partial (\\chi_{A}-2\\iota_{k})}{\\partial v}|\n \\frac{\\partial \\chi_{B}}{\\partial v} \\right) \\\\\n&+\\frac{N_{k}(B)}{2 \\gamma}\n \\left(\\frac{\\partial (\\chi_{A}-\\iota_{k})}{\\partial v}|\n \\frac{\\partial(\\chi_{B}-\\iota_{k})}{\\partial v} \\right) \n \\end{split}\n \\label{OS_kinetic_eq:4} \n\\end{equation}\n\nFor the case that RR direction $k$ is same with derivatives direction of $i$, according\nto the equation of \\ref{OS_kinetic_eq:3}, we have:\n\\begin{equation}\n \\begin{split}\n \\left(  \\frac{\\partial \\chi_{A}}{\\partial v_{i=k}}|\n \\frac{\\partial \\chi_{B}}{\\partial v_{i=k}} \\right)  &=  N_{i}(A)N_{i}(B)\n\\left[ PA_{i}(-2|-1)_{i} + \\frac{N_{i}(A)-2}{2 \\gamma}(-3|-1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)-1}{2 \\gamma}(-2|-2)_{i} \\right] \\\\\n&- 2\\alpha N_{i}(B)\n\\left[ PA_{i}(0|-1)_{i} + \\frac{N_{i}(A)}{2 \\gamma}(-1|-1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)-1}{2 \\gamma}(0|-2)_{i} \\right] \\\\ \n&- 2\\beta  N_{i}(A)\n\\left[ PA_{i}(-2|+1)_{i} + \\frac{N_{i}(A)-2}{2 \\gamma}(-3|+1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)+1}{2 \\gamma}(-2|0)_{i} \\right] \\\\  \n&+ 4\\alpha\\beta\n\\left[ PA_{i}(0|+1)_{i} + \\frac{N_{i}(A)}{2 \\gamma}(-1|+1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)+1}{2 \\gamma}(0|0)_{i} \\right] \\\\\n&= PA_{i} \\Bigg\\{   \n(N_{i}(A)-1)N_{i}(B)(-2|-1)_{i} - 2\\alpha N_{i}(B)(0|-1)_{i}  \\\\\n&- 2\\beta(N_{i}(A)-1)(-2|+1)_{i} +4\\alpha\\beta (0|+1)_{i} \\Bigg\\}  \\\\\n&+ PA_{i}\\Bigg\\{ N_{i}(B)(-2|-1)_{i} -2\\beta(-2|+1)_{i} \\Bigg\\} \\\\\n&+\\frac{N_{i}(A)}{2 \\gamma} \\Bigg\\{ \n(N_{i}(A)-2)N_{i}(B)(-3|-1)_{i} - 2\\alpha N_{i}(B)(-1|-1)_{i}  \\\\\n&-2\\beta(N_{i}(A)-2)(-3|+1)_{i} + 4\\alpha\\beta(-1|+1)_{i} \\Bigg \\} \\\\\n&+\\frac{N_{i}(B)}{2 \\gamma} \\Bigg\\{ \n(N_{i}(A)-1)(N_{i}(B)-1)(-2|-2)_{i} - 2\\alpha (N_{i}(B)-1)(0|-2)_{i} \\\\ \n&- 2\\beta(N_{i}(A)-1)(-2|0)_{i} + 4\\alpha\\beta(0|0)_{i} \\Bigg\\} \\\\\n&+\\frac{N_{i}(B)(N_{i}(B)-1)}{2 \\gamma}(-2|-2)_{i} - \n\\frac{2\\beta N_{i}(A)}{2 \\gamma} (-2|0)_{i} \\\\\n&-\\frac{2\\beta N_{i}(B)}{2 \\gamma} (-2|0)_{i}\n\\end{split}\n \\label{OS_kinetic_eq:5}\n\\end{equation}\n\nThe above expression could be re-fomulated into more clearly way:\n\\begin{equation}\n \\begin{split}\n \\left(  \\frac{\\partial \\chi_{A}}{\\partial v_{i=k}}|\n \\frac{\\partial \\chi_{B}}{\\partial v_{i=k}} \\right)  &=\n PA_{i}\n \\left(\\frac{\\partial (\\chi_{A}-\\iota_{i})}{\\partial v}|\n \\frac{\\partial \\chi_{B}}{\\partial v} \\right) + \n\\frac{N_{i}(A)}{2 \\gamma}\n \\left(\\frac{\\partial (\\chi_{A}-2\\iota_{i})}{\\partial v}|\n \\frac{\\partial \\chi_{B}}{\\partial v} \\right) \\\\\n&+\\frac{N_{i}(B)}{2 \\gamma}\n \\left(\\frac{\\partial (\\chi_{A}-\\iota_{i})}{\\partial v}|\n \\frac{\\partial(\\chi_{B}-\\iota_{i})}{\\partial v} \\right) \\\\\n&+ PA_{i}\\left[ N_{i}(B)(-2|-1)_{i} -2\\beta(-2|+1)_{i} \\right] \\\\\n&+\\frac{N_{i}(B)(N_{i}(B)-1)}{2 \\gamma}(-2|-2)_{i} - \n\\frac{2\\beta N_{i}(A)}{2 \\gamma} (-2|0)_{i} \\\\\n&-\\frac{2\\beta N_{i}(B)}{2 \\gamma} (-2|0)_{i}\n\\end{split}\n \\label{OS_kinetic_eq:6}\n\\end{equation}\n\n\n\\begin{comment}\n\n\n%\n\n\\begin{equation}\n \\begin{split}\n \\left(  \\frac{\\partial \\chi_{A}}{\\partial v_{i=k}}|\n \\frac{\\partial \\chi_{B}}{\\partial v_{i=k}} \\right)  &=  N_{i}(A)N_{i}(B)\n\\left[ PA_{i}(-2|-1)_{i} + \\frac{N_{i}(A)-2}{2 \\gamma}(-3|-1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)-1}{2 \\gamma}(-2|-2)_{i} \\right] \\\\\n&- 2\\alpha N_{i}(B)\n\\left[ PA_{i}(0|-1)_{i} + \\frac{N_{i}(A)}{2 \\gamma}(-1|-1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)-1}{2 \\gamma}(0|-2)_{i} \\right] \\\\ \n&- 2\\beta  N_{i}(A)\n\\left[ PA_{i}(-2|+1)_{i} + \\frac{N_{i}(A)-2}{2 \\gamma}(-3|+1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)+1}{2 \\gamma}(-2|0)_{i} \\right] \\\\  \n&+ 4\\alpha\\beta\n\\left[ PA_{i}(0|+1)_{i} + \\frac{N_{i}(A)}{2 \\gamma}(-1|+1)_{i} \\right. \\\\ \n &+ \\left. \\frac{N_{i}(B)+1}{2 \\gamma}(0|0)_{i} \\right] \\\\\n&= PA_{i}\n \\left(\\frac{\\partial (\\chi_{A}-\\iota_{i})}{\\partial v_{i}}|\n \\frac{\\partial \\chi_{B}}{\\partial v_{i}} \\right) + \n\\frac{N_{i}(A)}{2 \\gamma}\n \\left(\\frac{\\partial (\\chi_{A}-2\\iota_{i})}{\\partial v_{i}}|\n \\frac{\\partial \\chi_{B}}{\\partial v_{i}} \\right) \\\\\n&+\\frac{N_{i}(B)}{2 \\gamma}\n \\left(\\frac{\\partial (\\chi_{A}-\\iota_{i})}{\\partial v_{i}}|\n \\frac{\\partial(\\chi_{B}-\\iota_{i})}{\\partial v_{i}} \\right) \\\\\n&+\\Biggl( \n-\\frac{2 N_{i}(A)N_{i}(B)}{2\\gamma}(-3|-1)_{i} - \n\\frac{N_{i}(A)N_{i}(B)}{2\\gamma}(-2|-2)_{i} \\\\\n&-\n\\frac{2 \\alpha N_{i}(B)}{2\\gamma}(0|-2)_{i} +\n\\frac{4 \\beta N_{i}(A)}{2\\gamma}(-3|+1)_{i} \\\\\n&-\n\\frac{2 \\beta N_{i}(A)}{2\\gamma}(-2|0)_{i}  +\n\\frac{4 \\alpha\\beta}{2\\gamma}(0|0)_{i}\n\\Biggr)\n \\end{split}\n \\label{OS_kinetic_eq:5}\n\\end{equation}\n\n\\end{comment}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Three Body Kinetic Integral}\n%\n%\n%\nAccording to the \\ref{kinetic_direct_int_eq:2}, the three body kinetic enegy\ncould also be expressed as:\n\\begin{equation}\n\\frac{1}{2}\\sum_{v = x, y, z}\\int \\chi_{A}(r)\\chi_{B}(r)\n\\frac{\\partial^{2}}{\\partial v^{2}} \\chi_{C}(r) dr\n= \\frac{1}{2}\\int \\nabla(\\chi_{A}(r)\\chi_{B}(r)) \\cdot \\nabla\\chi_{C}(r) dr\n \\label{three_body_kinetic_integral_eq:1}\n\\end{equation}\n\nAccording to the \\ref{OS_kinetic_eq:0}, we have:\n\\begin{align}\n \\frac{\\partial \\chi^{lmn}_{A}}{\\partial v} &= \n N_{i}(A)(\\chi_{A}^{lmn}-\\iota_{i}) - 2\\alpha(\\chi_{A}^{lmn}+\\iota_{i}) \\nonumber \\\\\n &= N_{i}(A)(-1)_{i} - 2\\alpha(+1)_{i}\n \\label{three_body_kinetic_integral_eq:2}\n\\end{align}\nWe can further generate derivtives for \\ref{three_body_kinetic_integral_eq:1}\nas:\n\\begin{equation}\n \\begin{split}\n&\\int \\nabla(\\chi_{A}(r)\\chi_{B}(r)) \\cdot \\nabla\\chi_{C}(r) dr \\\\\n&= \\int \\left[ (\\nabla\\chi_{A}(r)\\chi_{B}(r) + \\chi_{A}(r)\\nabla\\chi_{B}(r)\\right] \n\\cdot \\nabla\\chi_{C}(r) dr \\\\\n&= \\sum_{i = x, y, z} \\int\n[ N_{i}(A)(\\chi_{A}-\\iota_{i}) - 2\\alpha(\\chi_{A}+\\iota_{i})] \\chi_{B} \\\\\n&[ N_{i}(C)(\\chi_{C}-\\iota_{i}) - 2\\gamma(\\chi_{C}+\\iota_{i})] dr \\\\\n&+ \\sum_{i = x, y, z} \\int \n\\chi_{A}(r) \\left[ \nN_{i}(B)(\\chi_{B}-\\iota_{i}) - 2\\beta(\\chi_{B}+\\iota_{i})\\right] \\\\\n&\\left[ N_{i}(C)(\\chi_{C}-\\iota_{i}) - 2\\gamma(\\chi_{C}+\\iota_{i})\\right]  dr\n \\end{split}\n\\label{three_body_kinetic_integral_eq:3}\n\\end{equation}\n$\\alpha$ is the expotential factor for $\\chi_{A}$, $\\beta$ is for $\\chi_{B}$\nand $\\gamma$ is for $\\chi_{C}$.\n\nNow let's expand all the terms:\n\\begin{equation}\n \\begin{split}\n&\\int \\nabla(\\chi_{A}(r)\\chi_{B}(r)) \\cdot \\nabla\\chi_{C}(r) dr \\\\\n&= \\sum_{i = x, y, z} \\int\n[ N_{i}(A)(\\chi_{A}-\\iota_{i}) - 2\\alpha(\\chi_{A}+\\iota_{i})] \\chi_{B} \\\\\n&[ N_{i}(C)(\\chi_{C}-\\iota_{i}) - 2\\gamma(\\chi_{C}+\\iota_{i})] dr \\\\\n&+ \\sum_{i = x, y, z} \\int \n\\chi_{A}(r) \\left[ \nN_{i}(B)(\\chi_{B}-\\iota_{i}) - 2\\beta(\\chi_{B}+\\iota_{i})\\right] \\\\\n&\\left[ N_{i}(C)(\\chi_{C}-\\iota_{i}) - 2\\gamma(\\chi_{C}+\\iota_{i})\\right]  dr \\\\\n&= \\sum_{i = x, y, z} \\int \n N_{i}(A)N_{i}(C)(\\chi_{A}-\\iota_{i})\\chi_{B}(\\chi_{C}-\\iota_{i}) dr \\\\\n&- \\sum_{i = x, y, z} \\int \n 2\\alpha N_{i}(C)(\\chi_{A}+\\iota_{i})\\chi_{B}(\\chi_{C}-\\iota_{i}) dr \\\\\n&- \\sum_{i = x, y, z} \\int \n 2\\gamma N_{i}(A)(\\chi_{A}-\\iota_{i})\\chi_{B}(\\chi_{C}+\\iota_{i}) dr \\\\\n&+ \\sum_{i = x, y, z} \\int \n 4\\alpha\\gamma   (\\chi_{A}+\\iota_{i})\\chi_{B}(\\chi_{C}+\\iota_{i}) dr \\\\ \n&+ \\sum_{i = x, y, z} \\int \n N_{i}(B)N_{i}(C)\\chi_{A}(\\chi_{B}-\\iota_{i})(\\chi_{C}-\\iota_{i}) dr \\\\\n&- \\sum_{i = x, y, z} \\int \n 2\\beta  N_{i}(C)\\chi_{A}(\\chi_{B}+\\iota_{i})(\\chi_{C}-\\iota_{i}) dr \\\\\n&- \\sum_{i = x, y, z} \\int \n 2\\gamma N_{i}(B)\\chi_{A}(\\chi_{B}-\\iota_{i})(\\chi_{C}+\\iota_{i}) dr \\\\\n&+ \\sum_{i = x, y, z} \\int \n 4\\beta\\gamma    \\chi_{A}(\\chi_{B}+\\iota_{i})(\\chi_{C}+\\iota_{i}) dr  \n \\end{split}\n\\label{three_body_kinetic_integral_eq:4}\n\\end{equation}\n\nParticularly, for the bottom $SSS$ type integrals, it has the expression as:\n\\begin{equation}\n\\begin{split}\n &\\int \\nabla(0_{A}0_{B}) \\cdot \\nabla 0_{C} dr \\\\\n &= \\sum_{i = x, y, z} \\int \n 4\\alpha\\gamma   (0_{A}+\\iota_{i})0_{B}(0_{C}+\\iota_{i}) dr \\\\ \n &+ \\sum_{i = x, y, z} \\int \n 4\\beta\\gamma    0_{A}(0_{B}+\\iota_{i})(0_{C}+\\iota_{i}) dr \\\\\n\\end{split}\n\\label{three_body_kinetic_integral_eq:5}\n\\end{equation}\nBy using the RR expression for three body overlap integral, it becomes:\n\\begin{equation}\n \\begin{split}\n &\\int \\nabla(0_{A}0_{B}) \\cdot \\nabla 0_{C} dr \\\\\n &= \\sum_{i = x, y, z} \\int \n 4\\alpha\\gamma   (0_{A}+\\iota_{i})0_{B}(0_{C}+\\iota_{i}) dr \\\\ \n &+ \\sum_{i = x, y, z} \\int \n 4\\beta\\gamma    0_{A}(0_{B}+\\iota_{i})(0_{C}+\\iota_{i}) dr \\\\\n &= \\sum_{i = x, y, z} \\int \n 4\\alpha\\gamma\\left\\lbrace (G_{i}-C_{i})(0_{A}+\\iota_{i})0_{B}0_{C}\n +\\frac{1}{2(\\alpha+\\beta+\\gamma)}0_{A}0_{B}0_{C} \\right\\rbrace dr \\\\\n &+ \\sum_{i = x, y, z} \\int \n 4\\beta\\gamma \\left\\lbrace (G_{i}-C_{i})0_{A}(0_{B}+\\iota_{i})0_{C}\n +\\frac{1}{2(\\alpha+\\beta+\\gamma)}0_{A}0_{B}0_{C} \\right\\rbrace dr \\\\\n &= \\sum_{i = x, y, z} \\int \n 4\\alpha\\gamma\\left\\lbrace (G_{i}-C_{i})(G_{i}-A_{i})0_{A}0_{B}0_{C}\n +\\frac{1}{2(\\alpha+\\beta+\\gamma)}0_{A}0_{B}0_{C} \\right\\rbrace dr \\\\\n &+ \\sum_{i = x, y, z} \\int \n 4\\beta\\gamma \\left\\lbrace (G_{i}-C_{i})(G_{i}-B_{i})0_{A}0_{B}0_{C}\n +\\frac{1}{2(\\alpha+\\beta+\\gamma)}0_{A}0_{B}0_{C} \\right\\rbrace dr \\\\ \n &= \\sum_{i = x, y, z} \\left\\lbrace \n 4\\gamma(G_{i}-C_{i}) \\left[ \\alpha(G_{i}-A_{i}) + \\beta(G_{i}-B_{i})\\right] \n + \\frac{2\\gamma(\\alpha+\\beta)}{\\alpha+\\beta+\\gamma}\n \\right\\rbrace \\int 0_{A}0_{B}0_{C} dr\n\\end{split}\n\\label{three_body_kinetic_integral_eq:6}\n\\end{equation}\n\n\n\\begin{comment}\n &+ \\sum_{i = x, y, z} \\int \\Bigl{ \n\\chi_{A}(r) \\left[ \nN_{i}(B)(\\chi_{B}-\\iota_{i}) - 2\\beta(\\chi_{B}+\\iota_{i})\\right]\n\\left[ N_{i}(C)(\\chi_{C}-\\iota_{i}) - 2\\gamma(\\chi_{C}+\\iota_{i})\\right] \\Bigr} dr\n\\end{comment}\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Nuclear Attraction Integral}\n%\n%\n%\nIn the section of \\ref{direct_NAI_derivation}, we have derived the nuclear\nattraction integral explicitly. Here in this section, we will use the recursive\nrelation to derive a simple algorithm to calculate the NAI.\n\nAs we know, a general NAI is expressed as:\n\\begin{equation}\n \\begin{split}\n  (a|\\Lambda_{c}|b) &= \\int \\chi_{i}(r)\\frac{1}{r_{C}}\\chi_{j}(r) dr \\\\\n&= \\int x^{l_{A}}_{A}y^{m_{A}}_{A}z^{n_{A}}_{A}e^{-\\alpha r_{A}^{2}}\n        \\frac{1}{r_{C}}\n        x^{l_{B}}_{B}y^{m_{B}}_{B}z^{n_{B}}_{B}e^{-\\beta  r_{B}^{2}} dr\n \\end{split}\n\\end{equation}\n$r_{A}, r_{B}$ and $r_{c}$ denotes the distance between electron position and\nthe given nuclear (A, B or C).\n\nThrough transformation, the $\\frac{1}{r_{C}}$ becomes:\n\\begin{equation}\n\\label{OS_nuclear_eq:1}\n\\frac{1}{r_{C}} = \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0}e^{-u^{2}(r-C)^{2}} du\n\\end{equation}\nThen it's fully converted into a S type of primitive function.\n\nTherefore, for the $(a|0_{c}|b)$ it could be expressed as:\n\\begin{equation}\n \\label{OS_nuclear_eq:2}\n\\begin{split}\n(a|\\Lambda_{c}|b) &= \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0} du\n \\int dr x^{l_{A}}_{A}y^{m_{A}}_{A}z^{n_{A}}_{A}e^{-\\alpha r_{A}^{2}}\n        e^{-u^{2}(r-C)^{2}}\n        x^{l_{B}}_{B}y^{m_{B}}_{B}z^{n_{B}}_{B}e^{-\\beta  r_{B}^{2}} \\\\\n&= \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0} du  (a|0_{c}|b)\n\\end{split}\n\\end{equation}\nThen the NAI is converted back to the three center overlap integral.\n\nAccording to the recursive relation in \\ref{OS_three_overlap_int_eq:12},\nthe $(a|0_{c}|b)$ could be expressed as:\n\\begin{equation}\n \\begin{split}\n  (a+\\iota_{i}|0_{c}|b) \n&= \\left( \\frac{\\alpha A_{i} + \\beta B_{i} + u^{2}C_{i}}{\\alpha+\\beta+u^{2}} -\nA_{i}\\right) (a|0_{c}|b)  \\\\\n&+ \nN_{i}(A)\\left(\\frac{1}{2(\\alpha+\\beta+u^{2})}\\right)(a-\\iota_{i}|0_{c}|b) \\\\\n&+\nN_{i}(C)\\left(\\frac{1}{2(\\alpha+\\beta+u^{2})}\\right)(a|0_{c}|b-\\iota_{i}) \\\\\n&= \\left( P_{i}  - A_{i}\\right) (a|0_{c}|b) - (P_{i} - C_{i})\n\\frac{u^{2}}{\\alpha+\\beta+u^{2}}(a|0_{c}|b)  \\\\\n&+ \n\\frac{N_{i}(A)}{2(\\alpha+\\beta)}\\left(1-\\frac{u^{2}}{(\\alpha+\\beta+u^{2})}\n\\right)(a-\\iota_{i}|0_{ c }|b) \\\\\n&+\n\\frac{N_{i}(C)}{2(\\alpha+\\beta)}\\left(1-\\frac{u^{2}}{(\\alpha+\\beta+u^{2})}\n\\right)(a|0_{c}|b-\\iota_{i}) \\\\\n \\end{split}\n\\label{OS_nuclear_eq:3}\n\\end{equation}\nWhere $P_{i}$ is:\n\\begin{equation}\n P_{i} = \\frac{\\alpha A_{i} + \\beta B_{i}}{\\alpha+\\beta}\n\\end{equation}\nHere, we are carefully modifying the expression so that to make the result\nsimilar to the one we derived in ERI(see \\ref{OS_ERI_eq:27}). Therefore,\nhere for \\ref{OS_nuclear_eq:3} a similar auxiliary function (see\n\\ref{OS_ERI_eq:28}) could be defined($\\epsilon = \\alpha+\\beta$):\n\\begin{equation}\n\\label{OS_nuclear_eq:4}\n  (a|0_{c}|b)^{(m)} = \\frac{2}{\\sqrt{\\pi}}\\int du \\left( \\frac{u^{2}}\n{\\epsilon+u^{2}}\\right)^{m}(ab|u|cd) \n\\end{equation}\nand we have:\n\\begin{equation}\n \\begin{split}\n  (a+\\iota_{i}|0_{c}|b)^{(m)} &=  \n\\left( P_{i}  - A_{i}\\right) (a|0_{c}|b)^{(m)} - (P_{i} - C_{i})\n(a|0_{c}|b)^{(m+1)}  \\\\\n&+ \n\\frac{N_{i}(A)}{2\\epsilon}\\left(\n(a-\\iota_{i}|0_{ c }|b)^{(m)}-\n(a-\\iota_{i}|0_{ c }|b)^{(m+1)}\n\\right) \\\\\n&+\n\\frac{N_{i}(C)}{2\\epsilon}\\left(\n(a|0_{c}|b-\\iota_{i})^{(m)}-\n(a|0_{c}|b-\\iota_{i})^{(m+1)}\n\\right) \\\\\n \\end{split}\n\\label{OS_nuclear_eq:5}\n\\end{equation}\nThe corresponding integral of $(0_{a}|0_{c}|0_{b})^{(m)}$ is:\n\\begin{equation}\n\\label{OS_nuclear_eq:6}\n (0_{a}|0_{c}|0_{b})^{(m)} = 2\\left(\n\\frac{\\epsilon}{\\pi}\\right)^{1/2}(0_{a}|0_{b})\n\\int^{1}_{0} t^{2m} e^{-(\\epsilon|PC|^{2})t^{2}} dt \n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{comment}\n%%%\n%%%  the description here is not quite what we want. So just screen the\n%    contents.\n%%%\n\n\\subsection{Implementation Considerations}\n%\n%\n%\nNow let's give some deep discussion on how to realize the algorithm. For the\nOS and its derived algorithm, the first thing we can note is that the recursive\nrelationship is actually expressed based on ``shell'' rather than the basis set\norders (for example, shell P has three basis set orders; Px, Py and Pz).\n\nThis is easy to understand. Suggest for an arbitrary overlap integral,\n$(a|b)$, there will be $n_{a}n_{b}$ basis set pairs ($n$ is the number of\nCartesian basis set). For the $(a+\\iota_{i}|b)$, depending on the literal \nmeaning the basis set pairs would be $3n_{a}n_{b}$ since $\\iota_{i}$ loop\nover x, y and z. However, if shell a is incremented to the shell a+1 (like\nfrom shell P to shell D), the basis set pairs would be:\n\\begin{equation}\n N_{1} = n_{b}\\left(\\frac{(L+2)(L+3)(L+4)-(L+1)(L+2)(L+3)}{6} \\right) \n\\end{equation}\n$L$ is the angular momentum number for the shell a. If we expand the\n$3n_{a}n_{b}$ in terms of $L$, it's:\n\\begin{equation}\nN_{2} = 3n_{b}\\left(\\frac{(L+1)(L+2)(L+3)-(L+1)(L+2)L}{6} \\right) \n\\end{equation}\nTherefore $N_{1} - N_{2}$ gives:\n\\begin{equation}\n \\begin{split}\n N_{1} - N_{2} &= n_{b}\\left( \\frac{(L+2)(L+3)(L+4)-(L+1)(L+2)(L+3)}{6}\\right.\n\\\\\n&-\\left. \\frac{3(L+1)(L+2)(L+3)-3(L+1)(L+2)L}{6}\\right) \\\\\n&=  n_{b}(L+2)\\left( \\frac{(L+3)(L+4)-(L+1)(L+3)}{6}\\right. \\\\\n&-\\left.  \\frac{3(L+1)(L+3)-3(L+1)L}{6}\\right) \\\\\n&= n_{b}(L+2)\\left( \\frac{(L+3)(L+4)+3(L+1)L-4(L+1)(L+3)}{6}\\right) \\\\\n&= n_{b}(L+2)\\left( \\frac{(L+3)(-3L)+3(L+1)L}{6}\\right) \\\\\n&= n_{b}(L+2)L\\left( \\frac{-3(L+3)+3(L+1)}{6}\\right) \\\\\n&= n_{b}(L+2)L\\left( \\frac{-6}{6}\\right) \\\\\n&< 0\n \\end{split}\n\\end{equation}\nTherefore, The incremental on the integral could be fully expressed by shell\nrather than basis set orders. What's more, it also indicates that for all of \nrecursive relations in the OS framework, the integral is meaningful to the\n``shells'', we need not to consider it in the basis set order level.\n\n\\end{comment}\n\n\n", "meta": {"hexsha": "5a72540498331db8bbef3b51d09619ca8ef781b8", "size": 65565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm/technic/integral/os.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/os.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/os.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": 40.076405868, "max_line_length": 101, "alphanum_fraction": 0.5839243499, "num_tokens": 27901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6713429114183181}}
{"text": "% Created 2021-07-26 Mon 11:04\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{Output feedback (observer)}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Output feedback (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{Apollo moon lander}\n\\label{sec:orgf367148}\n\\begin{frame}[label={sec:orga00b35e}]{Example - The Apollo lunar module}\n\\begin{center}\n\\includegraphics[width=\\linewidth]{fig-apollo}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:org4e808de}]{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} = k_1 u\\\\ \\dot{x}_2 = \\dot{\\theta} = x_1\\\\ \\dot{x}_3 = \\ddot{z} = k_2\\theta = k_2x_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}{k_2} &\\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}{k_1} \\\\ \\textcolor{red!60!black}{0} \\\\\\textcolor{red!60!black}{0}  \\end{bmatrix}}_{B} u \\]\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org03fd31b}]{Example - The Apollo lunar module}\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^2k_2}{2} & hk_2 & 1\\end{bmatrix} x(kh) + k_1 \\begin{bmatrix} h\\\\ \\frac{h^2}{2} \\\\ \\frac{k_2 h^3}{6} \\end{bmatrix} u(kh)\n\\end{align*}\n\\end{frame}\n\n\n\\section{State feedback with observer}\n\\label{sec:org1049069}\n\\begin{frame}[label={sec:orge0b900b}]{State feedback with reconstructed states}\n\\end{frame}\n\n\\begin{frame}[label={sec:org7f98d83}]{State feedback with reconstructed states}\n\\begin{center}\n\\includegraphics[width=0.9\\linewidth]{fig-apollo}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:org5b63c86}]{State feedback}\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 estimates) 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) = -l_1x_1(k) - l_2x_2(k) - \\cdots - l_n x_n(k) + l_0u_c(k)\\\\\n      &= -Lx(k) + l_0u_c(k), \n\\end{split}\n\\end{equation*}\nwhere \\[ L = \\bbm l_1 & l_2 & \\cdots & l_n \\ebm. \\]\nSubstituting the control law in the state space model \\eqref{eq:ssmodel} gives\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma L \\right) x(k) + 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\n\n\\begin{frame}[label={sec:org71af002}]{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 obserser 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{K\\big(y(k) - C\\hat{x}(k)\\big)}_{\\text{correction}} = \\left(\\Phi - KC\\right)\\hat{x}(k) +  \\Gamma u(k) + Ky(k)\n\\end{split}\n\\end{equation*}\nwith poles given by the eigenvalues of the matrix \\(\\Phi_o = \\Phi - KC\\)\n\n\\alert{Rule-of-thumb} Choose the poles of the observer (eigenvalues of \\(\\Phi-KC\\)) at least twice as fast as the poles (eigenvalues) of \\(\\Phi-\\Gamma L\\).\n\\end{frame}\n\n\\begin{frame}[label={sec:org8c2ca3d}]{Observer design}\n\\alert{Rule-of-thumb} Choose the poles of the observer (eigenvalues of \\(\\Phi-KC\\)) at least twice as fast as the poles (eigenvalues) of \\(\\Phi-\\Gamma L\\).\n\nIn continuous time (the s-plane), choosing a pole to be twice as fast, means moving the pole to twice the disance from the origin. Given a discrete pole \\(p_1\\), the discrete pole in \n\\[ p_2 = \\text{exp}\\left( 2 \\frac{\\ln p_1}{h} h\\right) = \\text{exp} \\big( 2 \\ln p_1 \\big) = p_1^2\\]\ncorresponds to a response that is twice as fast.\n\\end{frame}\n\n\\begin{frame}[label={sec:org71f4946}]{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{red}{K}\\) of the observer\n\\begin{equation*}\n\\begin{split}\n\\hat{x}(k+1) &= \\Phi \\hat{x}(k) + \\Gamma u(k) + \\textcolor{red}{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:orgff3fa4d}]{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- KC\\] is equivalent to determining the gain \\(K\\) in \n\\[(\\Phi-KC)\\transp = \\Phi\\transp - C\\transp 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:org9d34dd5},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\\end{document}", "meta": {"hexsha": "5514d8ce2badc379a3cebe493ac5bd3b329d33cc", "size": 6619, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "state-space/slides/lecture-observer.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": "state-space/slides/lecture-observer.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": "state-space/slides/lecture-observer.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": 38.7076023392, "max_line_length": 577, "alphanum_fraction": 0.6862063756, "num_tokens": 2414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6713429114183181}}
{"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{Notes on General Relativity}}\n\\author{Aditya Vijaykumar}\n\\affiliation{International Centre for Theoretical Sciences, Bengaluru, India.}\n\\emailAdd{aditya.vijaykumar@icts.res.in}\n\n\\begin{document}\n\\maketitle\n\\section{Tensors}\nThe Newtonian equations of motion are often phrased in the language of vectors. For example, take Newton's law of gravitation which gives the gravitational force between two bodies of mass $ m_1 $ and $ m_2 $ with a separation vector $ \\va{r} $ pointing from $ m_1 $ to $ m_2 $\n\\begin{equation}\\label{key}\n\\va{F}_{12} = - G \\dfrac{m_1 m_2}{\\abs{\\va{r}}^3} \\va{r}  \\qq{.}\n\\end{equation}\nHere, $ \\va{F}_{12} $ is the force on $ m_2 $ due to $ m_1 $. There are two ways of looking at this equation:\n\\begin{itemize}\n\t\\item A \\textit{coordinate-free way}, where we look at these objects as just vectors. The equations written in this form have the advantage that they don't demand any coordinate system to be chosen.\n\t\\item A \\textit{coordinate-dependent way}, where we look at these component-wise.\n\\end{itemize}\n\nBefore diving straight in to general relativity and the Einstein equations, one should be comfortable with the basic mathematical language that the theory is written in -- tensors. One can think of tensors to be a generalization of vectors; in fact, in the formalism we develop, it would be easy to see that vectos are tensors of a specific kind. Tensor equations can also be looked at in a coordinate-free and coordinate-dependent way; but it is the latter that we will choose to work with here.\n\\subsection{Tensor Algebra}\n\\subsubsection{Manifolds}\nA tensor is a geometrical object defined on a \\textit{manifold}. One can define a manifold in a detailed geometric way, but we (hopefully) won't need that for the purposes of these notes. Instead, we will just say that a manifold in $ n $-dimensions is something that \\textit{locally} looks like $ n $-dimensional Euclidean (flat) space $\\mathbb{R}^n $. As a simple illustration, let's consider a 2-sphere $ S^2 $. $ S^2 $ and $ \\mathbb{R}^2 $ are definitely not the same globally. But a small bit of $ S^2 $ does look like $ \\mathbb{R}^2 $. For example, even though the earth is (approximately) spherical, we as \\textit{local} humans perceieve it as being flat.\n\nA manifold is then simply a set of points such that each point possesses a set of $ n $-coordinates $ (x^1, x^2, \\ldots, x^n) $ which are all real numbers. These could be thought of as the counterpart of distances and angles in the Euclidean plane. Too add to this, it might even be impossible to cover a manifold in full by a non-degenerate coordinate system. Take a Euclidean example: plane polar coordinates have a degeneracy at the origin where $ \\phi $ becomes indeterminate, though we could make do with Cartesian coordinates in this case. But in other cases, this freedom might not be available. For example, it can be shown that there is no coordinate system that covers the whole of $ S^2 $ without degeneracy. For example, the ``flat'' map of the world (the so called Mercator projection) misses the poles.\n\nAs an illustrative example of the above, let's consider the stereographic projection which maps a sphere onto a plane. Let $ A = (x^1, x^2, x^3) $ be the coordinates of a point on the sphere. Consider also the plane $ \\mathcal{P} $ defined by $ x^3 = -1 $. The stereographic projection involves drawing a line passing through the north pole and $ A $ and finding the intercept of this line on $ \\mathcal{P} $; let's denote the intercept by $ A' = (y^1, y^2) $. We can show that,\n\\begin{equation}\\label{key}\n(y^1, y^2) = \\qty(\\dfrac{2x^1}{1 - x^3}, \\dfrac{2x^2}{1 - x^3})\n\\end{equation}\n\nAs can be seen from the above equation, this mapping fails to capture the north pole itself (it maps a finite point onto $ \\infty $). For us to include the north pole, we have to redefine the steoreographic mapping by considering a line passing through south pole and $ A $. \\textcolor{red}{Think about this a bit more}.\n\nOften, it is convenient to work with only one of these coordinate systems and keep track of the points that aren't included. This coordinate system is called  a coordinate patch, and a set of coordinate patches that covers the entire manifold is called an atlas.\n\n\\subsubsection{Curves and Surfaces}\nGiven a manifold, we would be interested in the subset of points that form curves and surfaces. We shall often define them parametrically. For example, since a curve has one degree of freedom, it will depend only on one \\textit{parameter}; we can define it by:\n\\begin{equation}\\label{key}\nx^a = x^a(u) \\qq{,}\n\\end{equation}\nwhere $ u $ is the parameter and $ x^1(u), x^2(u), \\ldots, x^n(u) $ are all functions of $ u $. Similarly, since a surface of $ m $ dimensions will have m degrees of freedom, we can define it by a set of $ m $ parameters:\n\\begin{equation}\\label{key}\nx^a = x^a(u^1, u^2, \\ldots, u^m) \\qq{.}\n\\end{equation}\nIn particular, if $ m=n-1 $, the surface is called a \\textit{hypersurface}. Here, one can eliminate $ n-1 $ parameters from $ n $ equations to give one equation connecting the coordinates \\textit{ie.},\n\\begin{equation}\\label{hyp}\nf(x^1, x^2, \\ldots, x^n) = 0 \\qq{.}\n\\end{equation}\nEquivalently, if a point on an $ n $-dimensional manifold is constrained to lie on a hypersurface, it should follow eq. \\ref{hyp}. Similarly, points on an $ m $-dimensional surface should follow $ n-m $ such constraints.\n\n\\subsubsection{Transformation of Coordinates}\nWhile writing down tensor equations, we would like to have it hold in all coordinate systems. Hence, we would like to see how one can realize coordinate transformations.\n\nLet's consider a transformation of coordinates $ x^a $ to $ x'^a =  f^a (x_1, x_2,\\ldots, x_n)$, where $ f^a $'s are single-valued, continuous, differentiable functions. We can view this as passively assigning a point with coordinates $ (x^1, x^2,\\ldots, x^n) $ the new coordinates $ (x'^1,x'^2, \\ldots, x'^n) $. More succintly, we will just use the notation $ x'^a = x'^a(x) $\n\nWe now want to see what the transformation will look like. Hence, we differentiate $ x' $ with respect to $ x $ -- this will give us a matrix of coefficients:\n\n\\begin{equation}\\label{jaco}\n\\mqty[\\pdv{x'^a}{x^b}] = \\mqty[\\pdv{x'^1}{x^1} & \\pdv{x'^1}{x^2} & \\ldots & \\pdv{x'^1}{x^n} \\\\\n\\pdv{x'^2}{x^1} & \\pdv{x'^2}{x^2} & \\ldots & \\pdv{x'^2}{x^n} \\\\\n\\vdots & & & \\\\\n\\pdv{x'^n}{x^1} & \\pdv{x'^n}{x^2} & \\ldots & \\pdv{x'^n}{x^n} \n]\n\\end{equation}\n\nThe determinant of the above transformation matrix is called the Jacobian $ J' $ of the transformation. If we assume that $ J' $ is non-zero, we can solve eq \\ref{jaco} and find the inverse transformation $ x^a = x^a(x') $. Using the product rule of determinants, the Jacobian of the inverse transformation $ J = 1/J'$ \n\nHow would the total differential of $ x'^a $ relate to the transformation matrix? We write,\n\\begin{equation}\\label{difftransform}\n\\dd{x'^a} = \\sum_{b = 1}^{n} \\pdv{x'^a}{x^b} \\dd{x^b} = \\pdv{x'^a}{x^b} \\dd{x^b}  \\qq{,}\n\\end{equation}\n\nwhere we invoke the \\textit{Einstein summation convention} to simplify our equations -- we drop the summation altogether and understand that whenever an index is repeated, it should be summed over. This repeated index is also often called the \\textit{bound index} or the \\textit{dummy index}.\n\nAs an aside, we will also define the \\textit{Kronecker delta} to be a quantity which is either $ 0 $ or $ 1 $ according to\n\n\\begin{equation}\\label{key}\n\\delta^a_b = \\begin{cases}\n1 \\qq{if} a = b\\\\\n0 \\qq{if} a \\ne b\n\\end{cases} \\implies \\pdv{x^a}{x^b} = \\pdv{x'^a}{x'^b} = \\delta^a_b \\qq{.}\n\\end{equation}\n\n\\subsubsection{Contravariant Tensors}\nWe now want to define geometrical quantities with reference to their transformation properties under transformations described in the previous section. Before defining contravariant tensors in general, let's first define a contravariant vector.\n\nConsider two neighbouring points on a manifold $ P $ and $ Q $ with coordinates $ x^a $ and $ x^a + \\dd{x^a} $. This forms an infinitesimal vector $ \\va{PQ} $ attached at $ P $ and directed to $ Q $, whose components in this coordinate system are $ \\dd{x^a} $. This vector will get transformed to $ \\dd{x'^a} $ in the new coordinate system, where $ \\dd{x'^a} $ is given by eq. \\ref{difftransform}. Note that the transformation matrix in this case will be evaluated at point $ P $.\n\nWe then define a \\textit{contravariant vector} $ X^a $ as a set of of quantities associated with point $ P $ which transform under a change of coordinates according to\n\n\\begin{equation}\\label{key}\nX'^a = \\pdv{x'^a}{x^b} X^b \\qq{,}\n\\end{equation}\nwith the transformation matrix evaluated at $ P $. This definition of the contravariant vector can then be generalized to \\textit{contravariant tensors}. A contravariant tensor of rank $ m $ in $ n $-dimensions is a set of $ n^m $ quantities associated with a point $ P $ that follow a certain transformation law. For illustrative purposes, in case of $ m=2 $, $ X^{ab} $ is a contravariant tensor if,\n\\begin{equation}\\label{key}\nX'^{ab} =  \\pdv{x'^a}{x^c}  \\pdv{x'^b}{x^d} X^{cd} \\qq{.}\n \\end{equation}\nThe transformation properties of higher rank tensors can be obtained in an analogous manner. A special case is a tensor of rank zero -- which is basically a scalar! This transforms according to $ \\phi' = \\phi $.\n\n\\subsubsection{Covariant and Mixed Tensors}\nConsider a real, continuous, differentiable scalar $ \\phi = \\phi(x) $. We have seen that $ x^a $ can be written as a function of $ x'^a $. Then, we can imagine differentiating $ \\phi $ with respect to $ x'^a $,\n\\begin{equation}\\label{key}\n\\pdv{\\phi}{x'^a} = \\pdv{\\phi}{x^b} \\pdv{x^b}{x'^a} \\qq{.}\n\\end{equation}\nNote that this involves the inverse tranformation from a coordinate system $ x' $ to $ x $. This motivates us to define a covariant vector $ X_a $ as a set of quantities that follows\n\\begin{equation}\\label{key}\nX'_a = \\pdv{x^b}{x'^a} X_b \\qq{,}\n\\end{equation}\nand analogously we can define a rank $ 2 $ covariant tensor by the law\n\\begin{equation}\\label{key}\nX'_{ab} = \\pdv{x^c}{x'^b} \\pdv{x^d}{x'^c} X_{cd} \\qq{,}\n\\end{equation}\nand so on for higher rank tensors. In the same spirit, we can define mixed tensors of rank $ 3 $ by the law\n\n\\begin{equation}\\label{key}\nX'^{a}_{bc} =  \\pdv{x'^a}{x^d} \\pdv{x^e}{x'^b} \\pdv{x^f}{x'^c} X^d_{ef} \\qq{.} \n\\end{equation}\n\nIf a mixed tensor has contravariant rank $ p $ and covariant rank $ q $, it is said to have \\textit{type}  or \\textit{valence} $ (p,q) $.\n\nLet's say we find two tensors $ X_{ab} $ and $ Y_{ab} $ which are equal component-by-component in a certain coordinate system \\textit{ie.} $ X_{ab} = Y_{ab} $. Will the tensors still be equal in a transformed coordinate system? Yes! We can see this by multiplying on both sides by the transformation matrix. In other words, the equality of two tensors would hold true in any and all coordinate systems! We might be interested in introducing coordinate systems for the purposes of a specific problem, but tensorial equations are essentially coordinate-independent.\n\n\\subsubsection{Tensor Fields}\nIn vector analysis, a \\textit{vector field} defined in a region is the association of a vector to every point in that region. Analogously, a tensor field defined in a region is the association of a tensor with the same valence to every point in the region; \\textit{ie},\n\\begin{equation}\\label{key}\nP \\rightarrow T^{a \\ldots}_{b\\ldots} (P) \\qq{,}\n\\end{equation}\nwhere $  T^{a \\ldots}_{b\\ldots} (P) $ is the value of the tensor at $ P $. As one might expect, the tensor field is called continuous and differentiable if its coordinates are continuous and differentiable functions. The tensor field is called smooth is its components are differentiable to all orders, denoted mathematically by saying that the components are $ C^\\infty $.\n\n\\subsubsection{Elementary Operations}\n\n\\begin{itemize}\n\t\\item $X^a_{bc} = Y^a_{bc} + Z^a_{bc}$\n\t\\item $ X^a_{bc} = \\alpha W^a_{bc} $, where $ \\alpha $ is a scalar.\n\t\\item A covariant tensor of rank $ 2 $,  $ X_{ab} $, is said to be symmetric if $ X_{ab} = X_{ba} $. In this case, it has $ \\frac{n(n+1)}{2} $ independent components.\n\t\\item A covariant tensor of rank $ 2 $,  $ X_{ab} $, is said to be anti-symmetric if $ X_{ab} = -X_{ba} $. In this case, it has $ \\frac{n(n-1)}{2} $ independent components.\n\t\\item Given a covariant tensor of rank $ 2 $, one can write it as a sum of a symmetric tensor and an anti-symmetric tensor,\n\t\\begin{align*}\n\tX_{ab} = &X_{(ab)} + X_{[ab]} \\qq{,} \\\\\n\t\\qq{where} X_{(ab)} = \\dfrac{X_{ab} + X_{ba}}{2} &\\qq{and} X_{[ab]} = \\dfrac{X_{ab} - X_{ba}}{2} \\qq{.}\n\t\\end{align*}\n\t\\item In general,\n\t\\begin{align*}\n\t\tX_{(a_1 a_2 \\ldots a_r)} &= \\dfrac{1}{r!} \\text{(sum over all permutations of indices)} \\\\\n\t\tX_{[a_1 a_2 \\ldots a_r]} &= \\dfrac{1}{r!} \\text{(alternating sum over all permutations of indices)} \t\\qq{.}\t\n\t\\end{align*}\n\tFor example, \n\t\\begin{equation}\\label{key}\n\tX_{[abc] }  = \\dfrac{1}{6!} \\qty(X_{abc} -X_{acb} + X_{cab} - X_{cba} + X_{bca} - X_{bac}) \\qq{.}\n\t\\end{equation}\n\t\\item We can multiply a type $ (p_1, q_1) $ tensor and a type $ (p_2, q_2) $ tensor to get a type $ (p_1+p_2, q_1+q_2) $ tensor, \\textit{eg.} $ X^a_{bcd}  = Y^a_b Z_{cd}$\n\t\n\t\\item Given a tensor of type $ (p,q) $, we can construct a type $ (p-1, q-1) $ tensor by the process of contraction \\textit{ie} said a raised index equal to the lower index, \\textit{eg} $ X^{a}_{bcd} \\rightarrow_{contraction}  X^{a}_{acd}  = \\delta_a^b X^{a}_{acd} = Y_{cd}$.\n\n\\end{itemize}\n\n\\subsubsection{Index-free interpretation of covariant tensor fields}\n\nIn the $ x^a $-coordinate system, let's introduce the following notation,\n\\begin{equation}\\label{key}\n\\partial_a = \\pdv{x^a} \\qq{.}\n\\end{equation}\nWe then define an operator $ X $ as,\n\\begin{equation}\\label{key}\nX = X^a \\partial_a \\implies Xf = X^a \\partial_a f = X^a (\\partial_a f) \\qq{,}\n\\end{equation}\nwhere $ f $ is an arbitrary real-valued function. It can be proved that the operator $ X $ is does not depend on the choice of the coordinate system and hence $ X = X^a \\pdv{x^a} =X'^a \\pdv{x'^a}  $. Hence, operating $ X $ on $ f $ will lead to the same result irrespective of the coordinate system used.\n\nSince any vector at $ P $ is given by the above equation, we can think of the quantities $ [\\partial_a]_P $ as forming the basis for all the vectors at $ P $, and $ [X^a]_P $ being the components. The vector space of all the contravariant vectors at $ P $ is called the \\textit{tangent space} at $ P $ and it denoted by $T_P(M)$.\n\nGiven two vector fields $ X $ and $ Y $, we can define a new vector field called the \\textit{commutator} or the \\textit{Lie bracket} of $ X $ and $ Y $ by\n\\begin{equation}\\label{key}\n\\qty[X, Y] = XY - YX \\qq{.}\n\\end{equation}\nHow are we sure the commutator is indeed a vector field? Consider the action of the commutator on a scalar function $ f $,\n\\begin{align*}\n\t\\qty[X, Y] f &= XYf - YXf \\\\\n\t&= X^a \\partial_a ( Y^b \\partial_b f  ) - Y^b \\partial_b (X^a \\partial_a ) f \\\\\n\t&=\\qty(X^a \\partial_a Y^b \\partial_b    - Y^b \\partial_b X^a \\partial_a ) f  + \\qty(X^a Y^b \\partial_a  \\partial_b f - Y^b X^a \\partial_b \\partial_a f) \\\\\n\t& = \\qty(X^b \\partial_b Y^a     - Y^b \\partial_b X^a ) \\partial_a f \\qq{,} \n\\end{align*}\nwhich proves that $ \\qty[X,Y] $ is a vector field.\n\nThe properties of the Lie bracket are:\n\\begin{itemize}\n\t\\item  $ \\qty[X,X] = 0 $\n\t\\item $ \\comm{X}{Y} = - \\comm{Y}{X} $\n\t\\item \\textit{Jacobi Identity}: $ \\comm{X}{\\comm{Y}{Z}} + \\comm{Y}{\\comm{Z}{X}} + \\comm{Z}{\\comm{X}{Y}} = 0 $\n\\end{itemize}\n\n\\subsection{Tensor Calculus}\n\\subsubsection{Partial Differentiation of Tensors does not yield a Tensor}\n\nConsider,\n\\begin{align}\n\\partial'_c X'^a &= \\pdv{x'^c} \\qty(\\pdv{x'^a}{x^b} X^b) \\\\\n&= \\pdv{x^d}{x'^c} \\pdv{x^d} \\qty(\\pdv{x'^a}{x^b} X^b) \\\\\n&= \\pdv[2]{x'^a}{x^b}{ x^d} \\pdv{x^d}{x'^c} X^b + \\pdv{x^d}{x'^c} \\pdv{x'^a}{x^b} \\pdv{X^b}{x^d} \n\\end{align}\nThis exercise clearly shows that the partial derivative \\textit{does not} transform as a tensor.\n\nWhy is this so? Taking a partial derivative really means taking the difference between two points $ P $ and $ Q $, dividing it by the separation, and taking the limit as separation goes to zero. The transformation law of tensors depends on each point, hence the difference of two vectors can have different magnitudes in different coordinate systems. So, the difference of two vectors \\textit{is not a vector}, and hence the derivative of a tensor does not transform as a vector in general.\n\n\\subsubsection{The Lie Derivative}\nA \\textit{congruence of curves} is defined as a set of curves such that exactly one curve passes through a given point on the manifold. This is denoted by $ x^a = x^a(u) $. Given this, we can define the tangent vector field $ \\dv{x^a}{u} $ along the curve. Doing this for every curve in the congruence, we end up with a vector field $ X^a $ given by $ \\dv{x^a}{u} $ at each point and defined over the whole manifold.\n\nConversely, we can think of a vector field $ X^a(u) $ defined on the manifold and can then define a congruence of curves on the manifold, called \\textit{orbits} or \\textit{trajectories} of $ X^a $. These curves can be obtained by solving the equation\n\\begin{equation}\\label{key}\n\\dv{x^a}{u} = X^a(x(u)) \\qq{.}\n\\end{equation}\n\nSay we have an arbitrary tensor $ T^{a \\ldots}_{b \\ldots} $ and quantities $ T_P $ and $ T_Q $ defined at two points $ P $ and $ Q $.\n\n\\end{document}", "meta": {"hexsha": "bd616ca6679f2902a7ae5795b20e3625910ab3ed", "size": 17989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/gr_notes.tex", "max_stars_repo_name": "adivijaykumar/gr", "max_stars_repo_head_hexsha": "feb8430ce7164eadfa3f92d76f2e248460a840ef", "max_stars_repo_licenses": ["MIT"], "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/gr_notes.tex", "max_issues_repo_name": "adivijaykumar/gr", "max_issues_repo_head_hexsha": "feb8430ce7164eadfa3f92d76f2e248460a840ef", "max_issues_repo_licenses": ["MIT"], "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/gr_notes.tex", "max_forks_repo_name": "adivijaykumar/gr", "max_forks_repo_head_hexsha": "feb8430ce7164eadfa3f92d76f2e248460a840ef", "max_forks_repo_licenses": ["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.2677824268, "max_line_length": 816, "alphanum_fraction": 0.7067096559, "num_tokens": 5575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6713429042242051}}
{"text": "\n\\chapter{Funcoids}\n\nIn this chapter (and several following chapters) the word \\emph{filter}\nwill refer to a filter (or equivalently any filter object) on a set\n(rather than a filter on an arbitrary poset).\n\n\n\\section{\\index{funcoid}Informal introduction into funcoids}\n\nFuncoids are a generalization of proximity spaces and a generalization\nof pretopological spaces. Also funcoids are a generalization of binary\nrelations.\n\nThat funcoids are a common generalization of ``spaces'' (proximity\nspaces, (pre)topological spaces) and binary relations (including monovalued\nfunctions) makes them smart for describing properties of functions\nin regard of spaces. For example the statement ``$f$ is a continuous\nfunction from a space $\\mu$ to a space $\\nu$'' can be described\nin terms of funcoids as the formula $f\\circ\\mu\\sqsubseteq\\nu\\circ f$\n(see below for details).\n\nMost naturally funcoids appear as a generalization of proximity spaces.\\footnote{In fact I discovered funcoids pondering on topological spaces, not on proximity spaces, but this is only of a historic interest.}\n\nLet $\\delta$ be a proximity. We will extend the relation~$\\delta$\nfrom sets to filters by the formula:\n\\[\n\\mathcal{A}\\mathrel\\delta'\\mathcal{B}\\Leftrightarrow\\forall\nA\\in\\up\\mathcal{A},B\\in\\up\\mathcal{B}:A\\mathrel\\delta B.\n\\]\n\n\nThen (as it will be proved below) there exist two functions\n$\\alpha,\\beta\\in\\mathscr{F}^{\\mathscr{F}}$\nsuch that\n\\[\n\\mathcal{A}\\mathrel\\delta'\\mathcal{B}\\Leftrightarrow\\mathcal{B}\n\\sqcap\\alpha\\mathcal{A}\\ne\\bot^{\\mathscr{F}}\\Leftrightarrow\\mathcal{A}\n\\sqcap\\beta\\mathcal{B}\\ne\\bot^{\\mathscr{F}}.\n\\]\n\n\nThe pair $(\\alpha,\\beta)$ is called \\emph{funcoid} when\n$\\mathcal{B}\\sqcap\\alpha\\mathcal{A}\\ne\\bot^{\\mathscr{F}}\\Leftrightarrow\\mathcal{\nA}\\sqcap\\beta\\mathcal{B}\\ne\\bot^{\\mathscr{F}}$.\nSo funcoids are a generalization of proximity spaces.\n\nFuncoids consist of two components the first $\\alpha$ and the second\n$\\beta$. The first component of a funcoid $f$ is denoted as $\\supfun f$\nand the second component is denoted as $\\supfun{f^{-1}}$. (The similarity\nof this notation with the notation for the image of a set under a\nfunction is not a coincidence, we will see that in the case of principal\nfuncoids (see below) these coincide.)\n\nOne of the most important properties of a funcoid is that it is uniquely\ndetermined by just one of its components. That is a funcoid $f$ is\nuniquely determined by the function $\\supfun f$. Moreover a funcoid\n$f$ is uniquely determined by values of $\\supfun f$ on principal\nfilters.\n\nNext we will consider some examples of funcoids determined by specified\nvalues of the first component on sets.\n\nFuncoids as a generalization of pretopological spaces: Let $\\alpha$\nbe a pretopological space that is a map \\emph{$\\alpha\\in\\mathscr{F}^{\\mho}$}\nfor some set $\\mho$. Then we define $\\alpha'X=\\bigsqcup_{x\\in X}\\alpha x$\nfor every set $X\\in\\subsets\\mho$. We will prove that there exists\na unique funcoid $f$ such that $\\alpha'=\\supfun f|_{\\mathfrak{P}}\\circ\\uparrow$\nwhere $\\mathfrak{P}$ is the set of principal filters on $\\mho$.\nSo funcoids are a generalization of pretopological spaces. Funcoids\nare also a generalization of preclosure operators: For every preclosure\noperator $p$ on a set $\\mho$ it exists a unique funcoid $f$ such\nthat $\\supfun f|_{\\mathfrak{P}}\\circ\\uparrow=\\uparrow\\circ p$.\n\nFor every binary relation $p$ on a set $\\mho$ there exists unique\nfuncoid $f$ such that\n\\[\n\\forall X\\in\\subsets\\mho:\\supfun f\\uparrow X=\\uparrow\\rsupfun pX\n\\]\n(where $\\rsupfun p$ is defined in the introduction), recall that\na funcoid is uniquely determined by the values of its first component\non sets. I will call such funcoids \\emph{principal}. So funcoids are\na generalization of binary relations.\n\nComposition of binary relations (i.e. of principal funcoids) complies\nwith the formulas:\n\\[\n\\rsupfun{g\\circ f}=\\rsupfun g\\circ\\rsupfun f\\quad\\text{and}\\quad\\rsupfun{(g\\circ\nf)^{-1}}=\\rsupfun{f^{-1}}\\circ\\rsupfun{g^{-1}}.\n\\]\nBy similar formulas we can define composition of every two funcoids.\nFuncoids with this composition form a category (\\emph{the category\nof funcoids}).\n\nAlso funcoids can be reversed (like reversal of $X$ and $Y$ in a\nbinary relation) by the formula $(\\alpha,\\beta)^{-1}=(\\beta,\\alpha)$.\nIn the particular case if $\\mu$ is a proximity we have $\\mu^{-1}=\\mu$\nbecause proximities are symmetric.\n\nFuncoids behave similarly to (multivalued) functions but acting on\nfilters instead of acting on sets. Below there will be defined domain\nand image of a funcoid (the domain and the image of a funcoid are\nfilters).\n\n\n\\section{Basic definitions}\n\\begin{defn}\n\\index{funcoid}Let us call a \\emph{funcoid} from a set $A$ to a\nset $B$ a quadruple $(A,B,\\alpha,\\beta)$ where\n$\\alpha\\in\\mathscr{F}(B)^{\\mathscr{F}(A)}$,\n$\\alpha\\in\\mathscr{F}(A)^{\\mathscr{F}(B)}$ such that\n\\[\n\\forall\\mathcal{X}\\in\\mathscr{F}(A),\\mathcal{Y}\\in\\mathscr{F}(B):(\\mathcal{Y}\n\\nasymp\\alpha\\mathcal{X}\\Leftrightarrow\\mathcal{X}\\nasymp\\beta\\mathcal{Y}).\n\\]\n\n\\end{defn}\n\n\\begin{defn}\n\\index{funcoid!source}\\index{funcoid!destination}\\emph{Source} and\n\\emph{destination} of every funcoid $(A,B,\\alpha,\\beta)$ are defined\nas:\n\\[\n\\Src(A,B,\\alpha,\\beta)=A\\quad\\text{and}\\quad\\Dst(A,B,\\alpha,\\beta)=B.\n\\]\n\n\\end{defn}\nI will denote $\\mathsf{FCD}(A,B)$ the set of funcoids from $A$ to\n$B$.\n\nI will denote $\\mathsf{FCD}$ the set of all funcoids (for small sets).\n\\begin{defn}\n\\index{endo-funcoid}I will call an \\emph{endofuncoid} a funcoid whose source is the same as it's destination.\n\\end{defn}\n\n\\begin{defn}\n$\\supfun{(A,B,\\alpha,\\beta)}\\eqdef\\alpha$ for a funcoid $(A,B,\\alpha,\\beta)$.\n\\end{defn}\n\n\\begin{defn}\n\\index{funcoid!reverse}The \\emph{reverse} funcoid\n$(A,B,\\alpha,\\beta)^{-1}=(B,A,\\beta,\\alpha)$\nfor a funcoid $(A,B,\\alpha,\\beta)$.\\end{defn}\n\\begin{note}\nThe reverse funcoid is \\emph{not} an inverse in the sense of group\ntheory or category theory.\\end{note}\n\\begin{prop}\nIf $f$ is a funcoid then $f^{-1}$ is also a funcoid.\\end{prop}\n\\begin{proof}\nIt follows from symmetry in the definition of funcoid.\\end{proof}\n\\begin{obvious}\n$(f^{-1})^{-1}=f$ for a funcoid $f$.\\end{obvious}\n\\begin{defn}\nThe relation $\\mathord{\\suprel f}\\in\\subsets(\\mathscr{F}(\\Src\nf)\\times\\mathscr{F}(\\Dst f))$\nis defined (for every funcoid $f$ and $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$,\n$\\mathcal{Y}\\in\\mathscr{F}(\\Dst f)$ by the formula $\\mathcal{X}\\suprel\nf\\mathcal{Y}\\Leftrightarrow\\mathcal{Y}\\nasymp\\supfun f\\mathcal{X}$.\\end{defn}\n\\begin{obvious}\n$\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\mathcal{Y}\\nasymp\\supfun\nf\\mathcal{X}\\Leftrightarrow\\mathcal{X}\\nasymp\\supfun{f^{-1}}\\mathcal{Y}$\nfor every funcoid $f$ and $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$,\n$\\mathcal{Y}\\in\\mathscr{F}(\\Dst f)$.\n\\end{obvious}\n\n\\begin{obvious}\n$\\suprel{f^{-1}}=\\suprel f^{-1}$ for a funcoid $f$.\\end{obvious}\n\\begin{thm}\nLet $A$, $B$ be sets.\n\\begin{enumerate}\n\\item For given value of $\\supfun f\\in\\mathscr{F}(B)^{\\mathscr{F}(A)}$\nthere exists no more than one funcoid $f\\in\\mathsf{FCD}(A,B)$.\n\\item For given value of $\\mathord{\\suprel\nf}\\in\\subsets(\\mathscr{F}(A)\\times\\mathscr{F}(B))$\nthere exists no more than one funcoid $f\\in\\mathsf{FCD}(A,B)$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nLet $f,g\\in\\mathsf{FCD}(A,B)$.\n\nObviously, $\\supfun f=\\supfun g\\Rightarrow\\suprel f=\\suprel g$ and\n$\\supfun{f^{-1}}=\\supfun{g^{-1}}\\Rightarrow\\suprel f=\\suprel g$.\nSo it's enough to prove that $\\suprel f=\\suprel g\\Rightarrow\\supfun f=\\supfun\ng$.\n\nProvided that $\\suprel f=\\suprel g$ we have \\[\\mathcal{Y}\\nasymp\\supfun\nf\\mathcal{X}\\Leftrightarrow\\mathcal{X}\\suprel\nf\\mathcal{Y}\\Leftrightarrow\\mathcal{X}\\suprel\ng\\mathcal{Y}\\Leftrightarrow\\mathcal{Y}\\nasymp\\supfun g\\mathcal{X}\\]\nand consequently $\\supfun f\\mathcal{X}=\\supfun g\\mathcal{X}$ for\nevery $\\mathcal{X}\\in\\mathscr{F}(A)$, $\\mathcal{Y}\\in\\mathscr{F}(B)$\nbecause a set of filters is separable, thus $\\supfun f=\\supfun g$.\\end{proof}\n\\begin{prop}\n$\\supfun f\\bot=\\bot$\nfor every funcoid $f$.\\end{prop}\n\\begin{proof}\n$\\mathcal{Y}\\nasymp\\supfun f\\bot\\Leftrightarrow\\bot\\nasymp\\supfun{f^{-1}}\\mathcal{Y}\\Leftrightarrow0\\Leftrightarrow\\mathcal{Y}\n\\nasymp\\bot$.\nThus $\\supfun f\\bot=\\bot$\nby separability of filters.\\end{proof}\n\\begin{prop}\n$\\supfun f(\\mathcal{I}\\sqcup\\mathcal{J})=\\supfun f\\mathcal{I}\\sqcup\\supfun\nf\\mathcal{J}$\nfor every funcoid $f$ and $\\mathcal{I},\\mathcal{J}\\in\\mathscr{F}(\\Src\nf)$.\\end{prop}\n\\begin{proof}\n~\n\\begin{align*}\n\\fullstar\\supfun f(\\mathcal{I}\\sqcup\\mathcal{J}) & =\\\\\n\\setcond{\\mathcal{Y}\\in\\mathscr{F}}{\\mathcal{Y}\\nasymp\\supfun\nf(\\mathcal{I}\\sqcup\\mathcal{J})} & =\\\\\n\\setcond{\\mathcal{Y}\\in\\mathscr{F}}{\\mathcal{I}\\sqcup\\mathcal{J}\\nasymp\\supfun{\nf^{-1}}\\mathcal{Y}} & =\\\\\n\\setcond{\\mathcal{Y}\\in\\mathscr{F}}{\\mathcal{I}\\nasymp\\supfun{f^{-1}}\\mathcal{Y}\n\\lor\\mathcal{J}\\nasymp\\supfun{f^{-1}}\\mathcal{Y}} & =\\\\\n\\setcond{\\mathcal{Y}\\in\\mathscr{F}}{\\mathcal{Y}\\nasymp\\supfun\nf\\mathcal{I}\\lor\\mathcal{Y}\\nasymp\\supfun f\\mathcal{J}} & =\\\\\n\\setcond{\\mathcal{Y}\\in\\mathscr{F}}{\\mathcal{Y}\\nasymp\\supfun\nf\\mathcal{I}\\sqcup\\supfun f\\mathcal{J}} & =\\\\\n\\fullstar(\\supfun f\\mathcal{I}\\sqcup\\supfun f\\mathcal{J}).\n\\end{align*}\n\n\nThus $\\supfun f(\\mathcal{I}\\sqcup\\mathcal{J})=\\supfun f\\mathcal{I}\\sqcup\\supfun\nf\\mathcal{J}$\nbecause $\\mathscr{F}(\\Dst f)$ is separable.\\end{proof}\n\\begin{prop}\nFor every $f\\in\\mathsf{FCD}(A,B)$ for every sets $A$ and $B$ we\nhave:\n\\begin{enumerate}\n\\item \\label{fcd-f-d1}$\\mathcal{K}\\suprel\nf\\mathcal{I}\\sqcup\\mathcal{J}\\Leftrightarrow\\mathcal{K}\\suprel\nf\\mathcal{I}\\lor\\mathcal{K}\\suprel f\\mathcal{J}$\nfor every $\\mathcal{I},\\mathcal{J}\\in\\mathscr{F}(B)$,\n$\\mathcal{K}\\in\\mathscr{F}(A)$.\n\\item \\label{fcd-f-d2}$\\mathcal{I}\\sqcup\\mathcal{J}\\suprel\nf\\mathcal{K}\\Leftrightarrow\\mathcal{I}\\suprel f\\mathcal{K}\\lor\\mathcal{J}\\suprel\nf\\mathcal{K}$\nfor every $\\mathcal{I},\\mathcal{J}\\in\\mathscr{F}(A)$,\n$\\mathcal{K}\\in\\mathscr{F}(B)$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{disorder}\n\\item [{\\ref{fcd-f-d1}}] ~\n\\begin{align*}\n\\mathcal{K}\\suprel f\\mathcal{I}\\sqcup\\mathcal{J} & \\Leftrightarrow\\\\\n(\\mathcal{I}\\sqcup\\mathcal{J})\\sqcap\\supfun f\\mathcal{K}\\ne\\bot^{\\mathscr{F}(B)}\n& \\Leftrightarrow\\\\\n\\mathcal{I}\\sqcap\\supfun\nf\\mathcal{K}\\ne\\bot^{\\mathscr{F}(B)}\\lor\\mathcal{J}\\sqcap\\supfun\nf\\mathcal{K}\\ne\\bot^{\\mathscr{F}(B)} & \\Leftrightarrow\\\\\n\\mathcal{K}\\suprel f\\mathcal{I}\\lor\\mathcal{K}\\suprel f\\mathcal{J}.\n\\end{align*}\n\n\\item [{\\ref{fcd-f-d2}}] Similar.\n\\end{disorder}\n\\end{proof}\n\n\\subsection{Composition of funcoids}\n\\begin{defn}\n\\index{composable!funcoids}\\index{funcoids!composable}Funcoids $f$\nand $g$ are \\emph{composable} when $\\Dst f=\\Src g$.\n\\end{defn}\n\n\\begin{defn}\n\\index{composition!funcoids}\\index{funcoids!composition}\\emph{Composition}\nof composable funcoids is defined by the formula\n\\[\n(B,C,\\alpha_{2},\\beta_{2})\\circ(A,B,\\alpha_{1},\\beta_{1})=(A,C,\\alpha_{2}\n\\circ\\alpha_{1},\\beta_{1}\\circ\\beta_{2}).\n\\]\n\\end{defn}\n\\begin{prop}\nIf $f$, $g$ are composable funcoids then $g\\circ f$ is a funcoid.\\end{prop}\n\\begin{proof}\nLet $f=(A,B,\\alpha_{1},\\beta_{1})$, $g=(B,C,\\alpha_{2},\\beta_{2})$.\nFor every $\\mathcal{X}\\in\\mathscr{F}(A)$, $\\mathcal{Y}\\in\\mathscr{F}(C)$\nwe have\n\\[\n\\mathcal{Y}\\nasymp(\\alpha_{2}\\circ\\alpha_{1})\\mathcal{X}\\Leftrightarrow\\mathcal{\nY}\\nasymp\\alpha_{2}\\alpha_{1}\\mathcal{X}\\Leftrightarrow\\alpha_{1}\\mathcal{X}\n\\nasymp\\beta_{2}\\mathcal{Y}\\Leftrightarrow\\mathcal{X}\\nasymp\\beta_{1}\\beta_{2}\n\\mathcal{Y}\\Leftrightarrow\\mathcal{X}\\nasymp(\\beta_{1}\\circ\\beta_{2})\\mathcal{Y}\n.\n\\]\n\n\nSo $(A,C,\\alpha_{2}\\circ\\alpha_{1},\\beta_{1}\\circ\\beta_{2})$ is a\nfuncoid.\\end{proof}\n\\begin{obvious}\n$\\supfun{g\\circ f}=\\supfun g\\circ\\supfun f$ for every composable\nfuncoids $f$ and $g$.\\end{obvious}\n\\begin{prop}\n$(h\\circ g)\\circ f=h\\circ(g\\circ f)$ for every composable funcoids\n$f$, $g$, $h$.\\end{prop}\n\\begin{proof}\n~\n\\begin{align*}\n\\supfun{(h\\circ g)\\circ f} & =\\\\\n\\supfun{h\\circ g}\\circ\\supfun f & =\\\\\n(\\supfun h\\circ\\supfun g)\\circ\\supfun f & =\\\\\n\\supfun h\\circ(\\supfun g\\circ\\supfun f) & =\\\\\n\\supfun h\\circ\\supfun{g\\circ f} & =\\\\\n\\supfun{h\\circ(g\\circ f)}.\n\\end{align*}\n\\end{proof}\n\\begin{thm}\n$(g\\circ f)^{-1}=f^{-1}\\circ g^{-1}$ for every composable funcoids\n$f$ and $g$.\\end{thm}\n\\begin{proof}\n$\\supfun{(g\\circ\nf)^{-1}}=\\supfun{f^{-1}}\\circ\\supfun{g^{-1}}=\\supfun{f^{-1}\\circ g^{-1}}$.\n\\end{proof}\n\n\\section{Funcoid as continuation}\n\nLet $f$ be a funcoid.\n\\begin{defn}\n$\\rsupfun f$ is the function $\\mathscr{T}(\\Src f)\\rightarrow\\mathscr{F}(\\Dst f)$\ndefined by the formula\n\\[\n\\rsupfun fX=\\supfun f\\uparrow X.\n\\]\n\n\\end{defn}\n\n\\begin{defn}\n$\\rsuprel f$ is the relation between $\\mathscr{T}(\\Src f)$ and $\\mathscr{T}(\\Dst\nf)$\ndefined by the formula\n\\[\nX\\rsuprel fY\\Leftrightarrow\\uparrow X\\suprel f\\uparrow Y.\n\\]\n\\end{defn}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item $\\rsupfun f=\\supfun f\\circ\\uparrow$;\n\\item $\\mathord{\\rsuprel f}=\\uparrow^{-1}\\circ\\mathord{\\suprel f}\\circ\\uparrow$.\n\\end{enumerate}\n\\end{obvious}\n\n\\begin{obvious}\n$\\supfun g\\rsupfun fX=\\rsupfun{g\\circ f}X$ for every $X\\in\\mathscr{T}(\\Src\nf)$.\\end{obvious}\n\\begin{thm}\nFor every funcoid $f$ and $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$,\n$\\mathcal{Y}\\in\\mathscr{F}(\\Dst f)$\n\\begin{enumerate}\n\\item \\label{f-filt-x}$\\supfun f\\mathcal{X}=\\bigsqcap\\rsupfun{\\rsupfun\nf}\\up\\mathcal{X}$;\n\\item \\label{frel-filt}$\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\rsuprel fY$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{frel-filt}}] ~\n\\begin{align*}\n\\mathcal{X}\\suprel f\\mathcal{Y} & \\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun f\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\forall Y\\in\\up\\mathcal{Y}:\\uparrow Y\\sqcap\\supfun\nf\\mathcal{X}\\ne\\bot & \\Leftrightarrow\\\\\n\\forall Y\\in\\up\\mathcal{Y}:\\mathcal{X}\\suprel f\\uparrow Y.\n\\end{align*}\n\n\n\nAnalogously $\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X}:\\uparrow X\\suprel f\\mathcal{Y}$.\nCombining these two equivalences we get\n\\[\n\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:\\uparrow X\\suprel f\\uparrow\nY\\Leftrightarrow\\forall X\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\rsuprel fY.\n\\]\n\n\n\\item [{\\ref{f-filt-x}}] ~\n\\begin{align*}\n\\mathcal{Y}\\sqcap\\supfun f\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{X}\\suprel f\\mathcal{Y} & \\Leftrightarrow\\\\\n\\forall X\\in\\up\\mathcal{X}:\\uparrow X\\suprel f\\mathcal{Y} & \\Leftrightarrow\\\\\n\\forall X\\in\\up\\mathcal{X}:\\mathcal{Y}\\sqcap\\rsupfun fX\\ne\\bot.\n\\end{align*}\n\n\n\nLet's denote $W=\\setcond{\\mathcal{Y}\\sqcap\\rsupfun fX}{X\\in\\up\\mathcal{X}}$.\nWe will prove that $W$ is a generalized filter base. To prove this\nit is enough to show that $V=\\setcond{\\rsupfun fX}{X\\in\\up\\mathcal{X}}$\nis a generalized filter base.\n\n\nLet $\\mathcal{P},\\mathcal{Q}\\in V$. Then $\\mathcal{P}=\\rsupfun fA$,\n$\\mathcal{Q}=\\rsupfun fB$ where $A,B\\in\\up\\mathcal{X}$; $A\\sqcap\nB\\in\\up\\mathcal{X}$\nand $\\mathcal{R}\\sqsubseteq\\mathcal{P}\\sqcap\\mathcal{Q}$ for\n$\\mathcal{R}=\\rsupfun f(A\\sqcap B)\\in V$.\nSo $V$ is a generalized filter base and thus $W$ is a generalized\nfilter base.\n\n\n$\\bot\\notin W\\Leftrightarrow\\bigsqcap\nW\\ne\\bot$\nby properties of generalized filter bases. That is\n\\[\n\\forall X\\in\\up\\mathcal{X}:\\mathcal{Y}\\sqcap\\rsupfun\nfX\\neq\\bot^{\\mathscr{F}(\\Dst\nf)}\\Leftrightarrow\\mathcal{Y}\\sqcap\\bigsqcap\\rsupfun{\\rsupfun\nf}\\up\\mathcal{X}\\ne\\bot.\n\\]\n\n\n\nComparing with the above, $\\mathcal{Y}\\sqcap\\supfun\nf\\mathcal{X}\\ne\\bot^{\\mathscr{F}(\\Dst\nf)}\\Leftrightarrow\\mathcal{Y}\\sqcap\\bigsqcap\\rsupfun{\\rsupfun\nf}\\up\\mathcal{X}\\ne\\bot$.\nSo $\\supfun f\\mathcal{X}=\\bigsqcap\\rsupfun{\\rsupfun f}\\up\\mathcal{X}$\nbecause the lattice of filters is separable.\n\n\\end{widedisorder}\n\\end{proof}\n\\begin{cor}\nLet $f$ be a funcoid.\n\\begin{enumerate}\n\\item The value of $f$ can be restored from the value of $\\rsupfun f$.\n\\item The value of $f$ can be restored from the value of $\\rsuprel f$.\n\\end{enumerate}\n\\end{cor}\n\\begin{prop}\nFor every $f\\in\\mathsf{FCD}(A,B)$ we have (for every $I,J\\in\\mathscr{T}A$)\n\\[\n\\rsupfun f\\bot=\\bot,\\quad\\rsupfun f(I\\sqcup\nJ)=\\rsupfun fI\\sqcup\\rsupfun fJ\n\\]\nand\n\\begin{multline*}\n\\lnot(I \\rsuprel f\\bot), I\\sqcup J\\rsuprel fK\n\\Leftrightarrow I\\rsuprel fK\\lor J\\rsuprel fK \\\\\n\\text{(for every \\ensuremath{I,J\\in\\mathscr{T}A}, \\ensuremath{K\\in\\mathscr{T}B})},\n\\end{multline*}\n\\begin{multline*}\n\\lnot(\\bot \\rsuprel fI), K\\rsuprel fI\\sqcup J\n\\Leftrightarrow K\\rsuprel fI\\lor K\\rsuprel fJ \\\\\n\\text{(for every \\ensuremath{I,J\\in\\mathscr{T}B}, \\ensuremath{K\\in\\mathscr{T}A})}.\n\\end{multline*}\n\\end{prop}\n\\begin{proof}\n$\\rsupfun f\\bot=\\supfun f\\bot=\\supfun\nf\\bot=\\bot$;\n\\[\n\\rsupfun f(I\\sqcup J)=\\supfun f\\uparrow(I\\sqcup J)=\\supfun f\\uparrow\nI\\sqcup\\supfun f\\uparrow J=\\rsupfun fI\\sqcup\\rsupfun fJ.\n\\]\n\n\n$I\\rsuprel\nf\\bot\\Leftrightarrow\\bot\\nasymp\\supfun\nf\\uparrow I\\Leftrightarrow0$;\n\\begin{align*}\nI\\sqcup J\\rsuprel fK & \\Leftrightarrow\\\\\n\\uparrow(I\\sqcup J)\\suprel f\\uparrow K & \\Leftrightarrow\\\\\n\\uparrow K\\nasymp\\supfun f\\uparrow(I\\sqcup J) & \\Leftrightarrow\\\\\n\\uparrow K\\nasymp\\rsupfun f(I\\sqcup J) & \\Leftrightarrow\\\\\n\\uparrow K\\nasymp\\rsupfun fI\\sqcup\\rsupfun fJ & \\Leftrightarrow\\\\\n\\uparrow K\\nasymp\\rsupfun fI\\lor\\uparrow K\\nasymp\\rsupfun fJ & \\Leftrightarrow\\\\\nI\\rsuprel fK\\lor J\\rsuprel fK.\n\\end{align*}\n\n\nThe rest follows from symmetry.\\end{proof}\n\\begin{thm}\n\\label{fcd-as-cont}(fundamental theorem of theory of funcoids) Fix sets $A$ and $B$. Let $L_{F}=\\mylambda\nf{\\mathsf{FCD}(A,B)}{\\rsupfun f}$\nand $L_{R}=\\mylambda f{\\mathsf{FCD}(A,B)}{\\mathord{\\rsuprel f}}$.\n\\begin{enumerate}\n\\item \\label{main-f}$L_{F}$ is a bijection from the set $\\mathsf{FCD}(A,B)$\nto the set of functions $\\alpha\\in\\mathscr{F}(B)^{\\mathscr{T}A}$\nthat obey the conditions (for every $I,J\\in\\mathscr{T}A$)\n\\begin{equation}\n\\alpha\\bot=\\bot,\\quad\\alpha(I\\sqcup J)=\\alpha\nI\\sqcup\\alpha J.\\label{fchar-alph}\n\\end{equation}\n\n\n\nFor such $\\alpha$ it holds (for every $\\mathcal{X}\\in\\mathscr{F}(A)$)\n\\begin{equation}\n\\supfun{L_{F}^{-1}\\alpha}\\mathcal{X}=\\bigsqcap\\rsupfun{\\alpha}\\up\\mathcal{X}\n.\\label{fchar-alph-c}\n\\end{equation}\n\n\n\\item \\label{main-r}$L_{R}$ is a bijection from the set $\\mathsf{FCD}(A,B)$\nto the set of binary relations\n$\\delta\\in\\subsets(\\mathscr{T}A\\times\\mathscr{T}B)$\nthat obey the conditions\n\\begin{equation}\n\\begin{aligned}\\lnot(I & \\mathrel\\delta\\bot), & I\\sqcup\nJ\\mathrel\\delta K & \\Leftrightarrow I\\mathrel\\delta K\\lor J\\mathrel\\delta K &\n\\text{(for every \\ensuremath{I,J\\in\\mathscr{T}A},\n\\ensuremath{K\\in\\mathscr{T}B})},\\\\\n\\lnot(\\bot & \\mathrel\\delta I), & K\\mathrel\\delta I\\sqcup J &\n\\Leftrightarrow K\\mathrel\\delta I\\lor K\\mathrel\\delta J & \\text{(for every\n\\ensuremath{I,J\\in\\mathscr{T}B}, \\ensuremath{K\\in\\mathscr{T}A})}.\n\\end{aligned}\n\\label{f-char-delt}\n\\end{equation}\n\n\n\nFor such $\\delta$ it holds (for every $\\mathcal{X}\\in\\mathscr{F}(A)$,\n$\\mathcal{Y}\\in\\mathscr{F}(B)$)\n\\begin{equation}\n\\mathcal{X}\\suprel{L_{R}^{-1}\\delta}\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\mathrel\\delta Y.\\label{f-char-delt-c}\n\\end{equation}\n\n\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nInjectivity of $L_{F}$ and $L_{R}$, formulas (\\ref{fchar-alph-c})\n(for $\\alpha\\in\\im L_{F}$) and (\\ref{f-char-delt-c}) (for $\\delta\\in\\im L_{R}$),\nformulas (\\ref{fchar-alph}) and (\\ref{f-char-delt}) follow from\ntwo previous theorems. The only thing remaining to prove is that for\nevery $\\alpha$ and $\\delta$ that obey the above conditions a corresponding\nfuncoid $f$ exists.\n\\begin{widedisorder}\n\\item [{\\ref{main-r}}] Let define $\\alpha\\in\\mathscr{F}(B)^{\\mathscr{T}A}$\nby the formula $\\corestar(\\alpha X)=\\setcond{Y\\in\\mathscr{T}B}{X\\mathrel\\delta\nY}$\nfor every $X\\in\\mathscr{T}A$. (It is obvious that\n$\\setcond{Y\\in\\mathscr{T}B}{X\\mathrel\\delta Y}$\nis a free star.) Analogously it can be defined\n$\\beta\\in\\mathscr{F}(A)^{\\mathscr{T}B}$\nby the formula $\\corestar(\\beta Y)=\\setcond{X\\in\\mathscr{T}A}{X\\mathrel\\delta\nY}$.\nLet's continue $\\alpha$ and $\\beta$ to\n$\\alpha'\\in\\mathscr{F}(B)^{\\mathscr{F}(A)}$\nand $\\beta'\\in\\mathscr{F}(A)^{\\mathscr{F}(B)}$ by the formulas\n\\[\n\\alpha'\\mathcal{X}=\\bigsqcap\\rsupfun{\\alpha}\\up\\mathcal{X}\\quad\\text{and}\n\\quad\\beta'\\mathcal{Y}=\\bigsqcap\\rsupfun{\\beta}\\up\\mathcal{Y}\n\\]\nand $\\delta$ to $\\delta'$ by the formula\n\\[\n\\mathcal{X}\\mathrel{\\delta'}\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\mathrel\\delta Y.\n\\]\n\n\n\n$\\mathcal{Y}\\sqcap\\alpha'\\mathcal{X}\\ne\\bot\n\\Leftrightarrow\\mathcal{Y}\\sqcap\\bigsqcap\\rsupfun{\\alpha}\\up\\mathcal{X}\\ne\\bot\n\\Leftrightarrow\\bigsqcap\\rsupfun{\\mathcal{Y}\\sqcap}\\rsupfun{\n\\alpha}\\up\\mathcal{X}\\ne\\bot$.\nLet's prove that\n\\[\nW=\\rsupfun{\\mathcal{Y}\\sqcap}\\rsupfun{\\alpha}\\up\\mathcal{X}\n\\]\nis a generalized filter base: To prove it is enough to show that\n$\\rsupfun{\\alpha}\\up\\mathcal{X}$\nis a generalized filter base. If\n$\\mathcal{A},\\mathcal{B}\\in\\rsupfun{\\alpha}\\up\\mathcal{X}$\nthen exist $X_{1},X_{2}\\in\\up\\mathcal{X}$ such that $\\mathcal{A}=\\alpha X_{1}$,\n$\\mathcal{B}=\\alpha X_{2}$.\n\n\nThen $\\alpha(X_{1}\\sqcap X_{2})\\in\\rsupfun{\\alpha}\\up\\mathcal{X}$.\nSo $\\rsupfun{\\alpha}\\up\\mathcal{X}$ is a generalized filter base\nand thus $W$ is a generalized filter base.\n\n\nBy properties of generalized filter bases,\n$\\bigsqcap\\rsupfun{\\mathcal{Y}\\sqcap}\\rsupfun{\\alpha}\\mathcal{X}\\ne\\bot$\nis equivalent to\n\\[\n\\forall X\\in\\up\\mathcal{X}:\\mathcal{Y}\\sqcap\\alpha X\\ne\\bot,\n\\]\nwhat is equivalent to\n\\begin{align*}\n\\forall X\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:\\uparrow Y\\sqcap\\alpha\nX\\ne\\bot & \\Leftrightarrow\\\\\n\\forall X\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:Y\\in\\corestar(\\alpha X) &\n\\Leftrightarrow\\\\\n\\forall X\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\mathrel\\delta Y.\n\\end{align*}\n\n\n\nCombining the equivalencies we get\n$\\mathcal{Y}\\sqcap\\alpha'\\mathcal{X}\\ne\\bot\n\\Leftrightarrow\\mathcal{X}\\mathrel{\\delta'}\\mathcal{Y}$.\nAnalogously\n$\\mathcal{X}\\sqcap\\beta'\\mathcal{Y}\\ne\\bot\n\\Leftrightarrow\\mathcal{X}\\mathrel{\\delta'}\\mathcal{Y}$.\nSo\n$\\mathcal{Y}\\sqcap\\alpha'\\mathcal{X}\\ne\\bot\n\\Leftrightarrow\\mathcal{X}\\sqcap\\beta'\\mathcal{Y}\\ne\\bot$,\nthat is $(A,B,\\alpha',\\beta')$ is a funcoid. From the formula\n$\\mathcal{Y}\\sqcap\\alpha'\\mathcal{X}\\ne\\bot^{\\mathscr{F}(B)}\n\\Leftrightarrow\\mathcal{X}\\mathrel{\\delta'}\\mathcal{Y}$\nit follows that\n\\[\nX\\rsuprel{(A,B,\\alpha',\\beta')}Y\\Leftrightarrow\\uparrow Y\\sqcap\\alpha'\\uparrow\nX\\ne\\bot\\Leftrightarrow\\uparrow X\\mathrel{\\delta'}\\uparrow\nY\\Leftrightarrow X\\mathrel\\delta Y.\n\\]\n\n\n\\item [{\\ref{main-f}}] Let define the relation\n$\\delta\\in\\subsets(\\mathscr{T}A\\times\\mathscr{T}B)$\nby the formula $X\\mathrel\\delta Y\\Leftrightarrow\\uparrow Y\\sqcap\\alpha\nX\\ne\\bot$.\n\n\nThat $\\lnot(I\\mathrel\\delta\\bot)$ and\n$\\lnot(\\bot\\mathrel\\delta I)$\nis obvious. We have\n\\begin{align*}\nI\\sqcup J\\mathrel\\delta K & \\Leftrightarrow\\\\\n\\uparrow K\\sqcap\\alpha(I\\sqcup J)\\ne\\bot & \\Leftrightarrow\\\\\n\\uparrow K\\sqcap(\\alpha I\\sqcup\\alpha J)\\ne\\bot &\n\\Leftrightarrow\\\\\n\\uparrow K\\sqcap\\alpha I\\ne\\bot\\lor\\uparrow K\\sqcap\\alpha\nJ\\ne\\bot & \\Leftrightarrow\\\\\nI\\mathrel\\delta K\\lor J\\mathrel\\delta K\n\\end{align*}\nand\n\\begin{align*}\nK\\mathrel\\delta I\\sqcup J & \\Leftrightarrow\\\\\n\\uparrow(I\\sqcup J)\\sqcap\\alpha K\\ne\\bot & \\Leftrightarrow\\\\\n(\\uparrow I\\sqcup\\uparrow J)\\sqcap\\alpha K\\ne\\bot &\n\\Leftrightarrow\\\\\n\\uparrow I\\sqcap\\alpha K\\ne\\bot\\lor\\uparrow J\\sqcap\\alpha\nK\\ne\\bot & \\Leftrightarrow\\\\\nK\\mathrel\\delta I\\lor K\\mathrel\\delta J.\n\\end{align*}\n\n\n\nThat is the formulas (\\ref{f-char-delt}) are true.\n\n\nAccordingly to the above there exists a funcoid $f$ such that\n\\[\n\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\mathrel\\delta Y.\n\\]\n\n\n\nFor every $X\\in\\mathscr{T}A$, $Y\\in\\mathscr{T}B$ we have:\n\\[\n\\uparrow Y\\sqcap\\supfun f\\uparrow\nX\\ne\\bot\\Leftrightarrow\\uparrow X\\suprel f\\uparrow\nY\\Leftrightarrow X\\mathrel\\delta Y\\Leftrightarrow\\uparrow Y\\sqcap\\alpha\nX\\ne\\bot,\n\\]\nconsequently $\\forall X\\in\\mathscr{T}A:\\alpha X=\\supfun f\\uparrow X=\\rsupfun\nfX$.\n\n\\end{widedisorder}\n\\end{proof}\nNote that by the last theorem to every (quasi-)proximity $\\delta$ corresponds\na unique funcoid. So funcoids are a generalization of (quasi-)proximity\nstructures. Reverse funcoids can be considered as a generalization\nof conjugate quasi-proximity.\n\\begin{cor}\nIf $\\alpha\\in\\mathscr{F}(B)^{\\mathscr{T}A}$,\n$\\beta\\in\\mathscr{F}(A)^{\\mathscr{T}B}$\nare functions such that $Y\\nasymp\\alpha X\\Leftrightarrow X\\nasymp\\beta Y$\nfor every $X\\in\\mathscr{T}A$, $Y\\in\\mathscr{T}B$, then there exists\nexactly one funcoid $f$ such that $\\langle f\\rangle^{\\ast}=\\alpha$,\n$\\langle f^{-1}\\rangle^{\\ast}=\\beta$.\\end{cor}\n\\begin{proof}\nProve $\\alpha(I\\sqcup J)=\\alpha I\\sqcup\\alpha J$. Really,\n\\begin{multline*}\nY\\nasymp\\alpha(I\\sqcup J)\\Leftrightarrow I\\sqcup J\\nasymp\\beta Y\\Leftrightarrow\nI\\nasymp\\beta Y\\vee J\\nasymp\\beta Y\\Leftrightarrow\\\\ Y\\nasymp\\alpha I\\vee\nY\\nasymp\\alpha J\\Leftrightarrow Y\\nasymp\\alpha I\\sqcup\\alpha J.\n\\end{multline*}\nSo $\\alpha(I\\sqcup J)=\\alpha I\\sqcup\\alpha J$ by star-separability.\nSimilarly $\\beta(I\\sqcup J)=\\beta I\\sqcup\\beta J$.\n\nThus by the theorem there exists a funcoid $f$ such that $\\langle\nf\\rangle^{\\ast}=\\alpha$,\n$\\langle f^{-1}\\rangle^{\\ast}=\\beta$.\n\nThat this funcoid is unique, follows from the above.\\end{proof}\n\\begin{defn}\nAny $\\mathbf{Rel}$-morphism $F:A\\rightarrow B$ corresponds to a\nfuncoid $\\uparrow^{\\mathsf{FCD}}F\\in\\mathsf{FCD}(A,B)$, where by\ndefinition\n$\\supfun{\\uparrow^{\\mathsf{FCD}}F}\\mathcal{X}=\\bigsqcap^{\\mathscr{F}}\\rsupfun{\n\\rsupfun F}\\up\\mathcal{X}$\nfor every $\\mathcal{X}\\in\\mathscr{F}(A)$.\n\\end{defn}\nUsing the last theorem it is easy to show that this definition is\nmonovalued and does not contradict to former stuff. (Take\n$\\alpha=\\uparrow\\circ\\rsupfun F$.)\n\\begin{prop}\n$\\rsupfun{\\uparrow^{\\mathsf{FCD}}f}X=\\rsupfun fX$ for a\n$\\mathbf{Rel}$-morphism~$f$\nand $X\\in\\mathscr{T}\\Src f$.\\end{prop}\n\\begin{proof}\n$\\rsupfun{\\uparrow^{\\mathsf{FCD}}f}X=\\min\\rsupfun{\\uparrow}\\rsupfun{\\rsupfun\nf}\\up X=\\uparrow\\rsupfun fX=\\rsupfun fX$.\\end{proof}\n\\begin{cor}\n$\\mathord{\\rsuprel{\\uparrow^{\\mathsf{FCD}}f}}=\\mathord{\\rsuprel f}$\nfor every $\\mathbf{Rel}$-morphism~$f$.\\end{cor}\n\\begin{proof}\n$X\\rsuprel{\\uparrow^{\\mathsf{FCD}}f}Y\\Leftrightarrow\nY\\nasymp\\rsupfun{\\uparrow^{\\mathsf{FCD}}f}X\\Leftrightarrow Y\\nasymp\\rsupfun\nfX\\Leftrightarrow X\\rsuprel fY$\nfor $X\\in\\mathscr{T}\\Src f$, $Y\\in\\mathscr{T}\\Dst f$.\\end{proof}\n\\begin{defn}\n$\\uparrow^{\\mathsf{FCD}(A,B)}f=\\uparrow^{\\mathsf{FCD}}(A,B,f)$ for\nevery binary relation~$f$ between sets~$A$ and~$B$.\n\\end{defn}\n\n\\begin{defn}\n\\index{funcoid!principal}\\index{principal!funcoid}Funcoids corresponding\nto a binary relation (= multivalued function) are called \\emph{principal\nfuncoids}.\\end{defn}\n\\begin{prop}\n$\\uparrow^{\\mathsf{FCD}}g\\circ\\uparrow^{\\mathsf{FCD}}f=\\uparrow^{\\mathsf{FCD}}\n(g\\circ f)$\nfor composable morphisms~$f$,~$g$ of category~$\\mathbf{Rel}$.\\end{prop}\n\\begin{proof}\nFor every $X\\in\\mathscr{T}\\Src f$\n\\begin{multline*}\n\\rsupfun{\\uparrow^{\\mathsf{FCD}}g\\circ\\uparrow^{\\mathsf{FCD}}f}X=\\rsupfun{\n\\uparrow^{\\mathsf{FCD}}g}\\rsupfun{\\uparrow^{\\mathsf{FCD}}f}X=\\\\\n\\rsupfun g\\rsupfun fX=\\rsupfun{g\\circ\nf}X=\\rsupfun{\\uparrow^{\\mathsf{FCD}}(g\\circ f)}X.\n\\end{multline*}\n\n\\end{proof}\nWe may equate principal funcoids with corresponding binary relations\nby the method of appendix~\\ref{app:prim-exists}. This is useful\nfor describing relationships of funcoids and binary relations, such\nas for the formulas of continuous functions and continuous funcoids\n(see below).\n\nThus $(\\mathsf{FCD}(A,B),\\mathbf{Rel}(A,B))$ is a filtrator. I call\nit \\emph{filtrator of funcoids}.\n\\begin{thm}\n\\label{supfun-genbase}If $S$ is a generalized filter base on $\\Src f$\nthen $\\supfun f\\bigsqcap S=\\bigsqcap\\rsupfun{\\supfun f}S$ for every\nfuncoid $f$.\\end{thm}\n\\begin{proof}\n$\\supfun f\\bigsqcap S\\sqsubseteq\\supfun fX$ for every $X\\in S$ and\nthus $\\supfun f\\bigsqcap S\\sqsubseteq\\bigsqcap\\rsupfun{\\supfun f}S$.\n\nBy properties of generalized filter bases:\n\n\\begin{align*}\n\\supfun f\\bigsqcap S & =\\\\\n\\bigsqcap\\rsupfun{\\rsupfun f}\\up\\bigsqcap S & =\\\\\n\\bigsqcap\\rsupfun{\\rsupfun f}\\setcond X{\\exists\\mathcal{P}\\in\nS:X\\in\\up\\mathcal{P}} & =\\\\\n\\bigsqcap\\setcond{\\rsupfun fX}{\\exists\\mathcal{P}\\in S:X\\in\\up\\mathcal{P}} &\n\\sqsupseteq\\\\\n\\bigsqcap_{\\mathcal{P}\\in S}\\supfun f\\mathcal{P} & =\\\\\n\\bigsqcap\\rsupfun{\\supfun f}S.\n\\end{align*}\n\\end{proof}\n\\begin{prop}\n$\\mathcal{X}\\suprel f\\bigsqcap S\\Leftrightarrow\\exists\\mathcal{Y}\\in\nS:\\mathcal{X}\\suprel f\\mathcal{Y}$\nif $f$ is a funcoid and $S$ is a generalized filter base on $\\Dst f$.\\end{prop}\n\\begin{proof}\n~\n\\begin{multline*}\n\\mathcal{X}\\suprel f\\bigsqcap S\\Leftrightarrow\\bigsqcap S\\sqcap\\supfun\nf\\mathcal{X}\\neq\\bot\\Leftrightarrow\\bigsqcap\\langle\\langle\nf\\rangle\\mathcal{X}\\sqcap\\rangle^{\\ast}S\\neq\\bot\\Leftrightarrow\\\\\n\\text{(by properties of generalized filter bases)}\\Leftrightarrow\\\\\n\\exists\\mathcal{Y}\\in\\langle\\supfun\nf\\mathcal{X}\\sqcap\\rangle^{\\ast}S:\\mathcal{Y}\n\\neq\\bot\\Leftrightarrow\\exists\\mathcal{Y}\\in S:\\langle\nf\\rangle\\mathcal{X}\\sqcap\\mathcal{Y}\\neq\\bot\\Leftrightarrow\\exists\\mathcal{Y}\\in\nS:\\mathcal{X}\\suprel f\\mathcal{Y}.\n\\end{multline*}\n\\end{proof}\n\\begin{defn}\n\\index{preserve filtered meets}\nA function $f$ between two posets is said to \\emph{preserve filtered meets}, when $f\\bigsqcap S=\\bigsqcap\\rsupfun{f}S$\nwhenever $\\bigsqcap S$ is defined for a filter base~$S$ on the first of the two posets.\n\\end{defn}\n\\begin{thm}\n\\label{fcd-as-func}(discovered by \\noun{Todd Trimble}) A function\n$\\varphi:\\mathscr{F}(A)\\rightarrow\\mathscr{F}(B)$ preserves finite\njoins (including nullary joins) and filtered meets iff there exists\na funcoid $f$ such that $\\supfun f=\\varphi$.\\end{thm}\n\\begin{proof}\nBackward implication follows from above.\n\nLet $\\psi=\\varphi|_{\\mathscr{T}A}$. Then $\\psi$ preserves bottom\nelement and binary joins. Thus there exists a funcoid $f$ such that\n$\\rsupfun f=\\psi$.\n\nIt remains to prove that $\\supfun f=\\varphi$.\n\nReally, $\\supfun f\\mathcal{X}=\\bigsqcap\\rsupfun{\\rsupfun\nf}\\up\\mathcal{X}=\\bigsqcap\\rsupfun{\\psi}\\up\\mathcal{X}=\\bigsqcap\\rsupfun{\\varphi\n}\\up\\mathcal{X}=\\varphi\\bigsqcap\\up\\mathcal{X}=\\varphi\\mathcal{X}$\nfor every $\\mathcal{X}\\in\\mathscr{F}(A)$.\\end{proof}\n\\begin{cor}\nFuncoids $f$ from $A$ to $B$ bijectively correspond by the formula\n$\\langle f\\rangle=\\varphi$ to functions\n$\\varphi:\\mathscr{F}(A)\\rightarrow\\mathscr{F}(B)$\npreserving finite joins and filtered meets.\n\\end{cor}\n\n\\section{\\label{fcd-rel-another}Another way to represent funcoids as binary\nrelations}\n\nThis is based on a\\noun{ Todd Trimble}'s idea.\n\\begin{defn}\nThe binary relation\n$\\xi^{\\circledast}\\in\\subsets(\\mathscr{F}(\\Src\\xi)\\times\\mathscr{F}(\\Dst\\xi))$\nfor a funcoid $\\xi$ is defined by the formula\n$\\mathcal{A}\\mathrel{\\xi^{\\circledast}}\\mathcal{B}\\Leftrightarrow\\mathcal{B}\n\\sqsupseteq\\langle\\xi\\rangle\\mathcal{A}$.\n\\end{defn}\n\n\\begin{defn}\nThe binary relation\n$\\xi^{\\ast}\\in\\subsets(\\mathscr{T}\\Src\\xi\\times\\mathscr{T}\\Dst\\xi)$\nfor a funcoid $\\xi$ is defined by the formula\n\\[\nA\\mathrel{\\xi^{\\ast}}B\\Leftrightarrow B\\sqsupseteq\\langle\\xi\\rangle\nA\\Leftrightarrow B\\in\\up\\langle\\xi\\rangle A.\n\\]\n\\end{defn}\n\\begin{prop}\nFuncoid $\\xi$ can be restored from\n\\begin{enumerate}\n\\item the value of $\\xi^{\\circledast}$;\n\\item the value of $\\xi^{\\ast}$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{enumerate}\n\\item The value of $\\supfun{\\xi}$ can be restored from $\\xi^{\\circledast}$.\n\\item The value of $\\rsupfun{\\xi}$ can be restored from $\\xi^{\\ast}$.\n\\end{enumerate}\n\\end{proof}\n\\begin{thm}\nLet $\\nu$ and $\\xi$ be composable funcoids. Then:\n\\begin{enumerate}\n\\item\n\\label{fcomp-1}$\\xi^{\\circledast}\\circ\\nu^{\\circledast}=(\\xi\\circ\\nu)^{\n\\circledast}$;\n\\item \\label{fcomp-2}$\\xi^{\\ast}\\circ\\nu^{\\ast}=(\\xi\\circ\\nu)^{\\ast}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{fcomp-1}}]\n\\begin{multline*}\n\\mathcal{A}\\mathrel{(\\xi^{\\circledast}\\circ\\nu^{\\circledast})}\\mathcal{C}\n\\Leftrightarrow\\exists\\mathcal{B}:\\left(\\mathcal{A}\\mathrel{\\nu^{\\circledast}}\n\\mathcal{B}\\wedge\\mathcal{B}\\mathrel{\\xi^{\\circledast}}\\mathcal{C}\n\\right)\\Leftrightarrow\\\\\n\\exists\\mathcal{B}\\in\\mathscr{F}(\\Dst\\nu):(\\mathcal{B}\\sqsupseteq\\supfun{\\nu}\n\\mathcal{A}\\wedge\\mathcal{C}\\sqsupseteq\\supfun{\\xi}\\mathcal{B})\\Leftrightarrow\\\\\n\\mathcal{C}\\sqsupseteq\\supfun{\\xi}\\supfun{\\nu}\\mathcal{A}\\Leftrightarrow\\mathcal\n{C}\\sqsupseteq\\supfun{\\xi\\circ\\nu}\\mathcal{A}\\Leftrightarrow\\mathcal{A}\\mathrel{\n(\\xi\\circ\\nu)^{\\circledast}}\\mathcal{C}.\n\\end{multline*}\n\n\\item [{\\ref{fcomp-2}}] ~\n\\begin{multline*}\nA\\mathrel{(\\xi^{\\ast}\\circ\\nu^{\\ast})}C\\Leftrightarrow\\exists\nB:\\left(A\\mathrel{\\nu^{\\ast}}B\\wedge\nB\\mathrel{\\xi^{\\ast}}C\\right)\\Leftrightarrow\\\\\n\\exists B:(B\\in\\up\\supfun{\\nu}A\\wedge\nC\\in\\up\\supfun{\\xi}B)\\Leftrightarrow\\exists\nB\\in\\up\\supfun{\\nu}A:C\\in\\up\\supfun{\\xi}B.\n\\end{multline*}\n\n\\end{widedisorder}\n$A\\mathrel{(\\xi\\circ\\nu)^{\\ast}}C\\Leftrightarrow C\\in\\up\\langle\\xi\\circ\\nu\\rangle\nB\\Leftrightarrow C\\in\\up\\langle\\xi\\rangle\\supfun{\\nu}B$.\n\nIt remains to prove\n\\[\n\\exists B\\in\\up\\supfun{\\nu}A:C\\in\\up\\langle\\xi\\rangle B\\Leftrightarrow\nC\\in\\up\\supfun{\\xi}\\langle\\nu\\rangle A.\n\\]\n$\\exists B\\in\\up\\supfun{\\nu}A:C\\in\\up\\langle\\xi\\rangle B\\Rightarrow\nC\\in\\up\\supfun{\\xi}\\supfun{\\nu}A$\nis obvious.\n\nLet $C\\in\\up\\supfun{\\xi}\\supfun{\\nu}A$. Then\n$C\\in\\up\\bigsqcap\\rsupfun{\\supfun{\\xi}}\\up\\supfun{\\nu}A$;\nso by properties of generalized filter bases, $\\exists\nP\\in\\rsupfun{\\supfun{\\xi}}\\up\\supfun{\\nu}A:C\\in\\up P$;\n$\\exists B\\in\\up\\supfun{\\nu}A:C\\in\\up\\supfun{\\xi}B$.\n\\end{proof}\n\\begin{rem}\nThe above theorem is interesting by the fact that composition of funcoids\nis represented as relational composition of binary relations.\n\\end{rem}\n\n\\section{Lattices of funcoids}\n\\begin{defn}\n$f\\sqsubseteq g\\eqdef\\mathord{\\suprel f}\\subseteq\\mathord{\\suprel g}$ for $f,g\\in\\mathsf{FCD}(A,B)$\nfor every sets $A$, $B$.\n\\end{defn}\nThus every $\\mathsf{FCD}(A,B)$ is a poset. (It's taken into account\nthat $\\mathord{\\suprel f}\\ne\\mathord{\\suprel g}$ when $f\\ne g$.)\n\n\\index{filtrator!of funcoids}We will consider filtrators (\\emph{filtrators\nof funcoids}) whose base is $\\mathsf{FCD}(A,B)$ and whose core are\nprincipal funcoids from $A$ to $B$.\n\\begin{lem}\\label{fcd-up-x-lem}\n$\\rsupfun fX=\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\rsupfun FX$ for\nevery funcoid $f$ and typed set $X\\in\\mathscr{T}(\\Src f)$.\\end{lem}\n\\begin{proof}\nObviously $\\rsupfun fX\\sqsubseteq\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\rsupfun\nFX$.\n\nLet $B\\in\\up\\rsupfun fX$. Let $F_{B}=X\\times B\\sqcup\\overline{X}\\times\\top$.\n\n$\\rsupfun{F_{B}}X=B$.\n\nLet $P\\in\\mathscr{T}(\\Src f)$. We have\n\\[\n\\bot\\ne P\\sqsubseteq\nX\\Rightarrow\\rsupfun{F_{B}}P=B\\sqsupseteq\\rsupfun fP\n\\]\nand\n\\[\nP\\nsqsubseteq\nX\\Rightarrow\\rsupfun{F_{B}}P=\\top\\sqsupseteq\\rsupfun fP.\n\\]\n\n\nThus $\\rsupfun{F_{B}}P\\sqsupseteq\\rsupfun fP$ for every $P$ and\nso $F_{B}\\sqsupseteq f$ that\nis $F_{B}\\in\\up f$.\n\nThus $\\forall B\\in\\up\\rsupfun fX:B\\in\\up\\bigsqcap_{F\\in\\up\nf}^{\\mathscr{F}}\\rsupfun FX$\nbecause $B\\in\\up\\rsupfun{F_{B}}X$.\n\nSo $\\bigsqcap_{F\\in\\up f}\\rsupfun FX\\sqsubseteq\\rsupfun fX$.\\end{proof}\n\\begin{thm}\n\\label{fcd-up-x}$\\supfun f\\mathcal{X}=\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\supfun\nF\\mathcal{X}$\nfor every funcoid $f$ and $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$.\\end{thm}\n\\begin{proof}\n~\n\\begin{align*}\n\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\supfun F\\mathcal{X} & =\\\\\n\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\bigsqcap^{\\mathscr{F}}\\rsupfun{\\rsupfun F}\\up\\mathcal{X} & =\\\\\n\\bigsqcap_{F\\in\\up\nf}^{\\mathscr{F}}\\bigsqcap_{X\\in\\up\\mathcal{X}}^{\\mathscr{F}}\\rsupfun FX & =\\\\\n\\bigsqcap_{X\\in\\up\\mathcal{X}}^{\\mathscr{F}}\\bigsqcap_{F\\in\\up\nf}^{\\mathscr{F}}\\rsupfun FX & =\\\\\n\\bigsqcap_{X\\in\\up\\mathcal{X}}^{\\mathscr{F}}\\rsupfun fX & =\\\\\n\\supfun f\\mathcal{X}\n\\end{align*}\n(the lemma used).\n\\end{proof}\nBelow it is shown that $\\mathsf{FCD}(A,B)$ are complete lattices\nfor every sets $A$ and $B$. We will apply lattice operations to\nsubsets of such sets without explicitly mentioning $\\mathsf{FCD}(A,B)$.\n\\begin{thm}\n\\label{fcd-join-sets}$\\mathsf{FCD}(A,B)$ is a complete lattice (for\nevery sets $A$ and $B$). For every $R\\in\\subsets\\mathsf{FCD}(A,B)$\nand $X\\in\\mathscr{T}A$, $Y\\in\\mathscr{T}B$\n\\begin{enumerate}\n\\item \\label{sr-join}$X\\rsuprel{\\bigsqcup R}Y\\Leftrightarrow\\exists f\\in\nR:X\\rsuprel fY$;\n\\item \\label{sf-join}$\\rsupfun{\\bigsqcup R}X=\\bigsqcup_{f\\in R}\\rsupfun fX$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nAccordingly \\cite{pm:complete-lattice-criteria} to prove that it\nis a complete lattice it's enough to prove existence of all joins.\n\\begin{widedisorder}\n\\item [{\\ref{sf-join}}] $\\alpha X\\eqdef\\bigsqcup_{f\\in R}\\rsupfun fX$.\nWe have $\\alpha\\bot=\\bot$;\n\\begin{align*}\n\\alpha(I\\sqcup J) & =\\\\\n\\bigsqcup_{f\\in R}\\rsupfun f(I\\sqcup J) & =\\\\\n\\bigsqcup_{f\\in R}(\\rsupfun fI\\sqcup\\rsupfun fJ) & =\\\\\n\\bigsqcup_{f\\in R}\\rsupfun fI\\sqcup\\bigsqcup\\rsupfun fJ & =\\\\\n\\alpha I\\sqcup\\alpha J.\n\\end{align*}\n\n\n\nSo $\\rsupfun h=\\alpha$ for some funcoid $h$. Obviously\n\\begin{equation}\n\\forall f\\in R:h\\sqsupseteq f.\\label{min-fcd-join}\n\\end{equation}\n\n\n\nAnd $h$ is the least funcoid for which holds the condition (\\ref{min-fcd-join}).\nSo $h=\\bigsqcup R$.\n\n\\item [{\\ref{sr-join}}] ~\n\\begin{align*}\nX\\rsuprel{\\bigsqcup R}Y & \\Leftrightarrow\\\\\n\\uparrow Y\\sqcap\\rsupfun{\\bigsqcup R}X\\ne\\bot &\n\\Leftrightarrow\\\\\n\\uparrow Y\\sqcap\\bigsqcup_{f\\in R}\\rsupfun fX\\ne\\bot &\n\\Leftrightarrow\\\\\n\\exists f\\in R:\\uparrow Y\\sqcap\\rsupfun fX\\ne\\bot &\n\\Leftrightarrow\\\\\n\\exists f\\in R:X\\rsuprel fY\n\\end{align*}\n(used proposition~\\ref{b-f-back-distr}).\n\\end{widedisorder}\n\\end{proof}\nIn the next theorem, compared to the previous one, the class of infinite\njoins is replaced with lesser class of binary joins and simultaneously\nclass of sets is changed to more wide class of filters.\n\\begin{thm}\n\\label{fcd-fin-join}For every $f,g\\in\\mathsf{FCD}(A,B)$ and\n$\\mathcal{X}\\in\\mathscr{F}(A)$\n(for every sets $A$,~$B$)\n\\begin{enumerate}\n\\item \\label{fjoin-x}$\\supfun{f\\sqcup g}\\mathcal{X}=\\supfun\nf\\mathcal{X}\\sqcup\\supfun g\\mathcal{X}$;\n\\item \\label{fjoin-r}$\\mathord{\\suprel{f\\sqcup g}}=\\mathord{\\suprel\nf}\\cup\\mathord{\\suprel g}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{fjoin-x}}] Let $\\alpha\\mathcal{X}\\eqdef\\supfun\nf\\mathcal{X}\\sqcup\\supfun g\\mathcal{X}$;\n$\\beta\\mathcal{Y}\\eqdef\\supfun{f^{-1}}\\mathcal{Y}\\sqcup\\supfun{g^{-1}}\\mathcal{Y\n}$\nfor every $\\mathcal{X}\\in\\mathscr{F}(A)$, $\\mathcal{Y}\\in\\mathscr{F}(B)$.\nThen\n\\begin{align*}\n\\mathcal{Y}\\sqcap\\alpha\\mathcal{X}\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun\nf\\mathcal{X}\\ne\\bot\\lor\\mathcal{Y}\\sqcap\\supfun\ng\\mathcal{X}\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\supfun{f^{-1}}\\mathcal{Y}\\ne\\bot\\lor\\mathcal{\nX}\\sqcap\\supfun{g^{-1}}\\mathcal{Y}\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\beta\\mathcal{Y}\\ne\\bot.\n\\end{align*}\nSo $h=(A,B,\\alpha,\\beta)$ is a funcoid. Obviously $h\\sqsupseteq f$\nand $h\\sqsupseteq g$. If $p\\sqsupseteq f$ and $p\\sqsupseteq g$\nfor some funcoid $p$ then $\\supfun p\\mathcal{X}\\sqsupseteq\\supfun\nf\\mathcal{X}\\sqcup\\supfun g\\mathcal{X}=\\supfun h\\mathcal{X}$\nthat is $p\\sqsupseteq h$. So $f\\sqcup g=h$.\n\\item [{\\ref{fjoin-r}}] For every $\\mathcal{X}\\in\\mathscr{F}(A)$,\n$\\mathcal{Y}\\in\\mathscr{F}(B)$\nwe have\n\\begin{align*}\n\\mathcal{X}\\suprel{f\\sqcup g}\\mathcal{Y} & \\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun{f\\sqcup g}\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap(\\supfun f\\mathcal{X}\\sqcup\\supfun\ng\\mathcal{X})\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun\nf\\mathcal{X}\\ne\\bot\\lor\\mathcal{Y}\\sqcap\\supfun\ng\\mathcal{X}\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{X}\\suprel f\\mathcal{Y}\\lor\\mathcal{X}\\suprel g\\mathcal{Y}.\n\\end{align*}\n\n\\end{widedisorder}\n\\end{proof}\n\n\\section{More on composition of funcoids}\n\\begin{prop}\n\\label{comp-fcd-r}$\\mathord{\\suprel{g\\circ f}}=\\mathord{\\suprel g}\\circ\\supfun\nf=\\supfun{g^{-1}}^{-1}\\circ\\mathord{\\suprel f}$\nfor every composable funcoids $f$ and $g$.\\end{prop}\n\\begin{proof}\nFor every $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$, $\\mathcal{Y}\\in\\mathscr{F}(\\Dst\ng)$\nwe have\n\\begin{align*}\n\\mathcal{X}\\suprel{g\\circ f}\\mathcal{Y} & \\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun{g\\circ f}\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun g\\supfun f\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\supfun f\\mathcal{X}\\suprel g\\mathcal{Y} & \\Leftrightarrow\\\\\n\\mathcal{X}\\mathrel{(\\mathord{\\suprel g}\\circ\\supfun f)}\\mathcal{Y}\n\\end{align*}\nand\n\\begin{align*}\n\\mathord{\\suprel{g\\circ f}} & =\\\\\n\\mathord{\\suprel{(f^{-1}\\circ g^{-1})^{-1}}} & =\\\\\n\\mathord{\\suprel{f^{-1}\\circ g^{-1}}}^{-1} & =\\\\\n(\\mathord{\\suprel{f^{-1}}}\\circ\\supfun{g^{-1}})^{-1} & =\\\\\n\\supfun{g^{-1}}^{-1}\\circ\\mathord{\\suprel f}.\n\\end{align*}\n\n\\end{proof}\nThe following theorem is a variant for funcoids of the statement (which\ndefines compositions of relations) that $x\\mathrel{(g\\circ\nf)}z\\Leftrightarrow\\exists y:(x\\mathrel fy\\land y\\mathrel gz)$\nfor every $x$ and $z$ and every binary relations $f$ and $g$.\n\\begin{thm}\n\\label{fcd-atom-middle}For every sets $A$, $B$, $C$ and $f\\in\\mathsf{FCD}(A,B)$,\n$g\\in\\mathsf{FCD}(B,C)$ and $\\mathcal{X}\\in\\mathscr{F}(A)$,\n$\\mathcal{Z}\\in\\mathscr{F}(C)$\n\\[\n\\mathcal{X}\\suprel{g\\circ f}\\mathcal{Z}\\Leftrightarrow\\exists\ny\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{X}\\suprel fy\\land y\\suprel g\\mathcal{Z}).\n\\]\n\\end{thm}\n\\begin{proof}\n~\n\\begin{align*}\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{X}\\suprel fy\\land y\\suprel\ng\\mathcal{Z}) & \\Leftrightarrow\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{Z}\\sqcap\\supfun\ngy\\ne\\bot\\land y\\sqcap\\supfun\nf\\mathcal{X}\\ne\\bot) & \\Leftrightarrow\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{Z}\\sqcap\\supfun\ngy\\ne\\bot\\land y\\sqsubseteq\\supfun f\\mathcal{X}) &\n\\Rightarrow\\\\\n\\mathcal{Z}\\sqcap\\supfun g\\supfun f\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{X}\\suprel{g\\circ f}\\mathcal{Z}.\n\\end{align*}\n\n\nReversely, if $\\mathcal{X}\\suprel{g\\circ f}\\mathcal{Z}$ then $\\supfun\nf\\mathcal{X}\\suprel g\\mathcal{Z}$,\nconsequently there exists $y\\in\\atoms\\supfun f\\mathcal{X}$ such that\n$y\\suprel g\\mathcal{Z}$; we have $\\mathcal{X}\\suprel fy$.\\end{proof}\n\\begin{thm}\nFor every sets $A$, $B$, $C$\n\\begin{enumerate}\n\\item $f\\circ(g\\sqcup h)=f\\circ g\\sqcup f\\circ h$ for $g,h\\in\\mathsf{FCD}(A,B)$,\n$f\\in\\mathsf{FCD}(B,C)$;\n\\item $(g\\sqcup h)\\circ f=g\\circ f\\sqcup h\\circ f$ for\n$g,h\\in\\mathsf{FCD}(B,C)$,\n$f\\in\\mathsf{FCD}(A,B)$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nI will prove only the first equality because the other is analogous.\n\nFor every $\\mathcal{X}\\in\\mathscr{F}(A)$, $\\mathcal{Z}\\in\\mathscr{F}(C)$\n\\begin{align*}\n\\mathcal{X}\\suprel{f\\circ(g\\sqcup h)}\\mathcal{Z} & \\Leftrightarrow\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{X}\\suprel{g\\sqcup h}y\\land\ny\\suprel f\\mathcal{Z}) & \\Leftrightarrow\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:((\\mathcal{X}\\suprel\ngy\\lor\\mathcal{X}\\suprel hy)\\land y\\suprel f\\mathcal{Z}) & \\Leftrightarrow\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:((\\mathcal{X}\\suprel gy\\land y\\suprel\nf\\mathcal{Z})\\lor(\\mathcal{X}\\suprel hy\\land y\\suprel f\\mathcal{Z})) &\n\\Leftrightarrow\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{X}\\suprel gy\\land y\\suprel\nf\\mathcal{Z})\\lor\\exists y\\in\\atoms^{\\mathscr{F}(B)}:(\\mathcal{X}\\suprel hy\\land\ny\\suprel f\\mathcal{Z}) & \\Leftrightarrow\\\\\n\\mathcal{X}\\suprel{f\\circ g}\\mathcal{Z}\\lor\\mathcal{X}\\suprel{f\\circ\nh}\\mathcal{Z} & \\Leftrightarrow\\\\\n\\mathcal{X}\\suprel{f\\circ g\\sqcup f\\circ h}\\mathcal{Z}.\n\\end{align*}\n\n\\end{proof}\nAnother proof of the above theorem (without atomic filters):\n\\begin{proof}\n~\n\\begin{align*}\n\\supfun{f\\circ(g\\sqcup h)}\\mathcal{X} & =\\\\\n\\supfun f\\supfun{g\\sqcup h}\\mathcal{X} & =\\\\\n\\supfun f(\\supfun g\\mathcal{X}\\sqcup\\supfun h\\mathcal{X}) & =\\\\\n\\supfun f\\supfun g\\mathcal{X}\\sqcup\\supfun f\\supfun h\\mathcal{X} & =\\\\\n\\supfun{f\\circ g}\\mathcal{X}\\sqcup\\supfun{f\\circ h}\\mathcal{X} & =\\\\\n\\supfun{f\\circ g\\sqcup f\\circ h}\\mathcal{X}.\n\\end{align*}\n\n\\end{proof}\n\n\\section{Domain and range of a funcoid}\n\\begin{defn}\n\\index{funcoid!identity}Let $A$ be a set. The \\emph{identity funcoid}\n$1_{A}^{\\mathsf{FCD}}=(A,A,\\id_{\\mathscr{F}(A)},\\id_{\\mathscr{F}(A)})$.\n\\end{defn}\n\\begin{obvious}\nThe identity funcoid is a funcoid.\\end{obvious}\n\\begin{prop}\n$\\mathord{\\suprel f}=\\mathord{\\suprel{1_{\\Dst f}}}\\circ\\supfun f$\nfor every funcoid $f$.\\end{prop}\n\\begin{proof}\nFrom proposition~\\ref{comp-fcd-r}.\\end{proof}\n\\begin{defn}\n\\index{funcoid!restricted identity}Let $A$ be a set,\n$\\mathcal{A}\\in\\mathscr{F}(A)$.\nThe \\emph{restricted identity funcoid\n\\[\n\\id_{\\mathcal{A}}^{\\mathsf{FCD}}=(A,A,\\mathcal{A}\\sqcap,\\mathcal{A}\\sqcap).\n\\]\n}\\end{defn}\n\\begin{prop}\nThe restricted identity funcoid is a funcoid.\\end{prop}\n\\begin{proof}\nWe need to prove that\n$(\\mathcal{A}\\sqcap\\mathcal{X})\\sqcap\\mathcal{Y}\\ne\\bot\n\\Leftrightarrow(\\mathcal{A}\\sqcap\\mathcal{Y})\\sqcap\\mathcal{X}\\ne\\bot$\nwhat is obvious.\\end{proof}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item $(1_{A}^{\\mathsf{FCD}})^{-1}=1_{A}^{\\mathsf{FCD}}$;\n\\item\n$(\\id_{\\mathcal{A}}^{\\mathsf{FCD}})^{-1}=\\id_{\\mathcal{A}}^{\\mathsf{FCD}}$.\n\\end{enumerate}\n\\end{obvious}\n\n\\begin{obvious}\nFor every $\\mathcal{X},\\mathcal{Y}\\in\\mathscr{F}(A)$\n\\begin{enumerate}\n\\item\n$\\mathcal{X}\\suprel{1_{A}^{\\mathsf{FCD}}}\\mathcal{Y}\\Leftrightarrow\\mathcal{X}\n\\sqcap\\mathcal{Y}\\ne\\bot$;\n\\item\n$\\mathcal{X}\\suprel{\\id_{\\mathcal{A}}^{\\mathsf{FCD}}}\\mathcal{Y}\n\\Leftrightarrow\\mathcal{A}\\sqcap\\mathcal{X}\\sqcap\\mathcal{Y}\\ne\\bot$.\n\\end{enumerate}\n\\end{obvious}\n\\begin{defn}\n\\index{restricting!funcoid}I will define \\emph{restricting} of a\nfuncoid $f$ to a filter $\\mathcal{A}\\in\\mathscr{F}(\\Src f)$ by the\nformula\n\\[\nf|_{\\mathcal{A}}=f\\circ\\id_{\\mathcal{A}}^{\\mathsf{FCD}}.\n\\]\n\n\\end{defn}\n\n\\begin{defn}\n\\index{image!of funcoid}\\emph{Image} of a funcoid $f$ will be defined\nby the formula $\\im f=\\supfun f\\top^{\\mathscr{F}(\\Src f)}$.\n\n\\index{domain!of funcoid}\\emph{Domain} of a funcoid $f$ is defined\nby the formula $\\dom f=\\im f^{-1}$.\\end{defn}\n\\begin{obvious}\nFor every morphism $f\\in\\mathbf{Rel}(A,B)$ for sets~$A$ and~$B$\n\\begin{enumerate}\n\\item $\\im\\uparrow^{\\mathsf{FCD}}f=\\uparrow\\im f$;\n\\item $\\dom\\uparrow^{\\mathsf{FCD}}f=\\uparrow\\dom f$.\n\\end{enumerate}\n\\end{obvious}\n\\begin{prop}\n$\\supfun f\\mathcal{X}=\\supfun f(\\mathcal{X}\\sqcap\\dom f)$ for every\nfuncoid $f$, $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$.\\end{prop}\n\\begin{proof}\nFor every $\\mathcal{Y}\\in\\mathscr{F}(\\Dst f)$ we have\n\\begin{align*}\n\\mathcal{Y}\\sqcap\\supfun f(\\mathcal{X}\\sqcap\\dom f)\\ne\\bot\n& \\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\dom f\\sqcap\\supfun{f^{-1}}\\mathcal{Y}\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\im\nf^{-1}\\sqcap\\supfun{f^{-1}}\\mathcal{Y}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\supfun{f^{-1}}\\mathcal{Y}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{Y}\\sqcap\\supfun f\\mathcal{X}\\ne\\bot.\n\\end{align*}\n\n\nThus $\\supfun f(\\mathcal{X}\\sqcap\\dom f)=\\supfun f\\mathcal{X}$ because\nthe lattice of filters is separable.\\end{proof}\n\\begin{prop}\n$\\supfun f\\mathcal{X}=\\im(f|_{\\mathcal{X}})$ for every funcoid $f$,\n$\\mathcal{X}\\in\\mathscr{F}(\\Src f)$.\\end{prop}\n\\begin{proof}\n~\n\\begin{align*}\n\\im(f|_{\\mathcal{X}}) & =\\\\\n\\supfun{f\\circ\\id_{\\mathcal{X}}^{\\mathsf{FCD}}}\\top & =\\\\\n\\supfun f\\supfun{\\id_{\\mathcal{X}}^{\\mathsf{FCD}}}\\top &\n=\\\\\n\\supfun f(\\mathcal{X}\\sqcap\\top) & =\\\\\n\\supfun f\\mathcal{X}.\n\\end{align*}\n\\end{proof}\n\\begin{prop}\\label{x-dom-fcd}\n$\\mathcal{X}\\sqcap\\dom f\\ne\\bot\\Leftrightarrow\\supfun\nf\\mathcal{X}\\ne\\bot$\nfor every funcoid $f$ and $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$.\\end{prop}\n\\begin{proof}\n~\n\\begin{align*}\n\\mathcal{X}\\sqcap\\dom f\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\supfun{f^{-1}}\\top^{\\mathscr{F}(\\Dst\nf)}\\ne\\bot & \\Leftrightarrow\\\\\n\\top\\sqcap\\supfun f\\mathcal{X}\\ne\\bot & \\Leftrightarrow\\\\\n\\supfun f\\mathcal{X}\\ne\\bot.\n\\end{align*}\n\\end{proof}\n\\begin{cor}\\label{dom-fcd-at}\n$\\dom f=\\bigsqcup\\setcond{a\\in\\atoms^{\\mathscr{F}(\\Src f)}}{\\supfun\nfa\\ne\\bot}$.\\end{cor}\n\\begin{proof}\nThis follows from the fact that $\\mathscr{F}(\\Src f)$ is an atomistic\nlattice.\\end{proof}\n\\begin{prop}\n$\\dom(f|_{\\mathcal{A}})=\\mathcal{A}\\sqcap\\dom f$ for every funcoid\n$f$ and $\\mathcal{A}\\in\\mathscr{F}(\\Src f)$.\\end{prop}\n\\begin{proof}\n~\n\n\\begin{align*}\n\\dom(f|_{\\mathcal{A}}) & =\\\\\n\\im(\\id_{\\mathcal{A}}^{\\mathsf{FCD}}\\circ f^{-1}) & =\\\\\n\\supfun{\\id_{\\mathcal{A}}^{\\mathsf{FCD}}}\\supfun{f^{-1}}\\top & =\\\\\n\\mathcal{A}\\sqcap\\supfun{f^{-1}}\\top & =\\\\\n\\mathcal{A}\\sqcap\\dom f.\n\\end{align*}\n\\end{proof}\n\\begin{thm}\n$\\im f=\\bigsqcap^{\\mathscr{F}}\\rsupfun{\\im}\\up f$ and $\\dom\nf=\\bigsqcap^{\\mathscr{F}}\\rsupfun{\\dom}\\up f$\nfor every funcoid $f$.\\end{thm}\n\\begin{proof}\n~\n\\begin{align*}\n\\im f & =\\\\\n\\supfun f\\top & =\\\\\n\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\supfun F\\top & =\\\\\n\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\im F & =\\\\\n\\bigsqcap^{\\mathscr{F}}\\rsupfun{\\im}\\up f.\n\\end{align*}\n\n\nThe second formula follows from symmetry.\\end{proof}\n\\begin{prop}\nFor every composable funcoids $f$, $g$:\n\\begin{enumerate}\n\\item \\label{im-gf}If $\\im f\\sqsupseteq\\dom g$ then $\\im(g\\circ f)=\\im g$.\n\\item \\label{dom-gf}If $\\im f\\sqsubseteq\\dom g$ then $\\dom(g\\circ f)=\\dom f$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{im-gf}}] ~\n\\begin{align*}\n\\im(g\\circ f) & =\\\\\n\\supfun{g\\circ f}\\top & =\\\\\n\\supfun g\\supfun f\\top & =\\\\\n\\supfun g\\im f & =\\\\\n\\supfun g(\\im f\\sqcap\\dom g) & =\\\\\n\\supfun g\\dom g & =\\\\\n\\supfun g\\top & =\\\\\n\\im g.\n\\end{align*}\n\n\\item [{\\ref{dom-gf}}] $\\dom(g\\circ f)=\\im(f^{-1}\\circ g^{-1})$ what\nby proved above is equal to $\\im f^{-1}$ that is $\\dom f$.\n\\end{widedisorder}\n\\end{proof}\n\\section{Categories of funcoids}\n\nI will define two categories, the \\emph{category of funcoids} and\nthe \\emph{category of funcoid triples}.\n\n\\index{category!of funcoids}The \\emph{category of funcoids} is defined\nas follows:\n\\begin{itemize}\n\\item Objects are small sets.\n\\item The set of morphisms from a set $A$ to a set $B$ is $\\mathsf{FCD}(A,B)$.\n\\item The composition is the composition of funcoids.\n\\item Identity morphism for a set is the identity funcoid for that set.\n\\end{itemize}\nTo show it is really a category is trivial.\n\n\\index{category!of funcoid triples}The \\emph{category of funcoid\ntriples} is defined as follows:\n\\begin{itemize}\n\\item Objects are filters on small sets.\n\\item The morphisms from a filter $\\mathcal{A}$ to a filter $\\mathcal{B}$\nare triples $(\\mathcal{A},\\mathcal{B},f)$ where\n$f\\in\\mathsf{FCD}(\\Base(\\mathcal{A}),\\Base(\\mathcal{B}))$\nand $\\dom f\\sqsubseteq\\mathcal{A}\\land\\im f\\sqsubseteq\\mathcal{B}$.\n\\item The composition is defined by the formula\n$(\\mathcal{B},\\mathcal{C},g)\\circ(\\mathcal{A},\\mathcal{B},f)=(\\mathcal{A}\n,\\mathcal{C},g\\circ f)$.\n\\item Identity morphism for a filter $\\mathcal{A}$ is\n$\\id_{\\mathcal{A}}^{\\mathsf{FCD}}$.\n\\end{itemize}\nTo prove that it is really a category is trivial.\n\\begin{prop}\n$\\uparrow^{\\mathsf{FCD}}$ is a functor from $\\mathbf{Rel}$ to\n$\\mathsf{FCD}$.\\end{prop}\n\\begin{proof}\n$\\uparrow^{\\mathsf{FCD}}(g\\circ\nf)=\\uparrow^{\\mathsf{FCD}}g\\circ\\uparrow^{\\mathsf{FCD}}f$\nwas proved above.\n$\\uparrow^{\\mathsf{FCD}}1_{A}^{\\mathbf{Rel}}=1_{A}^{\\mathsf{FCD}}$\nis obvious.\n\\end{proof}\n\n\\section{Specifying funcoids by functions or relations on atomic filters}\n\\begin{thm}\\label{fcd-atoms}\nFor every funcoid $f$ and\n$\\mathcal{X}\\in\\mathscr{F}(\\Src f)$,\n$\\mathcal{Y}\\in\\mathscr{F}(\\Dst f)$\n\\begin{enumerate}\n\\item \\label{f-at-f}$\\supfun f\\mathcal{X}=\\bigsqcup\\rsupfun{\\supfun\nf}\\atoms\\mathcal{X}$;\n\\item \\label{f-at-r}$\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\exists\nx\\in\\atoms\\mathcal{X},y\\in\\atoms\\mathcal{Y}:x\\suprel fy$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{f-at-f}}] ~\n\\begin{align*}\n\\mathcal{Y}\\sqcap\\supfun f\\mathcal{X}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{X}\\sqcap\\supfun{f^{-1}}\\mathcal{Y}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\exists\nx\\in\\atoms\\mathcal{X}:x\\sqcap\\supfun{f^{-1}}\\mathcal{Y}\\ne\\bot & \\Leftrightarrow\\\\\n\\exists x\\in\\atoms\\mathcal{X}:\\mathcal{Y}\\sqcap\\supfun\nfx\\ne\\bot.\n\\end{align*}\n\n\n\n$\\corestar\\supfun f\\mathcal{X}=\\bigsqcup\\rsupfun{\\corestar}\\rsupfun{\\supfun\nf}\\atoms\\mathcal{X}=\\corestar\\bigsqcup\\rsupfun{\\supfun f}\\atoms\\mathcal{X}$.\nSo $\\supfun f\\mathcal{X}=\\bigsqcup\\rsupfun{\\supfun f}\\atoms\\mathcal{X}$\nby corollary~\\ref{d-inj}.\n\n\\item [{\\ref{f-at-r}}] If $\\mathcal{X}\\suprel f\\mathcal{Y}$, then\n$\\mathcal{Y}\\sqcap\\supfun f\\mathcal{X}\\ne\\bot$,\nconsequently there exists $y\\in\\atoms\\mathcal{Y}$ such that $y\\sqcap\\supfun\nf\\mathcal{X}\\ne\\bot$,\n$\\mathcal{X}\\suprel fy$. Repeating this second time we get that there\nexists $x\\in\\atoms\\mathcal{X}$ such that $x\\suprel fy$. From this\nit follows\n\\[\n\\exists x\\in\\atoms\\mathcal{X},y\\in\\atoms\\mathcal{Y}:x\\suprel fy.\n\\]\n\n\n\nThe reverse is obvious.\n\n\\end{widedisorder}\n\\end{proof}\n\\begin{cor}\n~Let $f$ be a funcoid.\n\\begin{itemize}\n\\item The value of $f$ can be restored from the value of $\\supfun\nf|_{\\atoms^{\\mathscr{F}(\\Src f)}}$.\n\\item The value of $f$ can be restored from the value of $\\mathord{\\suprel\nf}|_{\\atoms^{\\mathscr{F}(\\Src f)}\\times\\atoms^{\\mathscr{F}(\\Dst f)}}$.\n\\end{itemize}\n\\end{cor}\n\\begin{thm}\n\\label{cont-fcd-on-atoms}Let $A$ and $B$ be sets.\n\\begin{enumerate}\n\\item \\label{at-restr-f}A function\n$\\alpha\\in\\mathscr{F}(B)^{\\atoms^{\\mathscr{F}(A)}}$\nsuch that (for every $a\\in\\atoms^{\\mathscr{F}(A)}$)\n\\begin{equation}\n\\alpha\na\\sqsubseteq\\bigsqcap\\rsupfun{\\bigsqcup\\circ\\rsupfun{\\alpha}\n\\circ\\atoms\\circ\\uparrow}\\up a\\label{at-func-cond}\n\\end{equation}\ncan be continued to the function $\\supfun f$ for a unique\n$f\\in\\mathsf{FCD}(A,B)$;\n\\begin{equation}\n\\supfun\nf\\mathcal{X}=\\bigsqcup\\rsupfun{\\alpha}\\atoms\\mathcal{X}\\label{at-func-eq}\n\\end{equation}\nfor every $\\mathcal{X}\\in\\mathscr{F}(A)$.\n\n\\item \\label{at-restr-r}A relation\n$\\delta\\in\\subsets(\\atoms^{\\mathscr{F}(A)}\\times\\atoms^{\\mathscr{F}(B)})$\nsuch that (for every $a\\in\\atoms^{\\mathscr{F}(A)}$,\n$b\\in\\atoms^{\\mathscr{F}(B)}$)\n\\begin{equation}\n\\forall X\\in\\up a,Y\\in\\up b\\exists x\\in\\atoms\\uparrow X,y\\in\\atoms\\uparrow\nY:x\\mathrel\\delta y\\Rightarrow a\\mathrel\\delta b\\label{at-rel-cond}\n\\end{equation}\ncan be continued to the relation $\\suprel f$ for a unique\n$f\\in\\mathsf{FCD}(A,B)$;\n\\begin{equation}\n\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\exists\nx\\in\\atoms\\mathcal{X},y\\in\\atoms\\mathcal{Y}:x\\mathrel\\delta y\\label{at-rel-eq}\n\\end{equation}\nfor every $\\mathcal{X}\\in\\mathscr{F}(A)$, $\\mathcal{Y}\\in\\mathscr{F}(B)$.\n\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nExistence of no more than one such funcoids and formulas (\\ref{at-func-eq})\nand (\\ref{at-rel-eq}) follow from the previous theorem.\n\\begin{widedisorder}\n\\item [{\\ref{at-restr-f}}] Consider the function\n$\\alpha'\\in\\mathscr{F}(B)^{\\mathscr{T}A}$\ndefined by the formula (for every $X\\in\\mathscr{T}A$)\n\\[\n\\alpha'X=\\bigsqcup\\rsupfun{\\alpha}\\atoms\\uparrow X.\n\\]\n\n\n\nObviously $\\alpha'\\bot^{\\mathscr{T}A}=\\bot^{\\mathscr{F}(B)}$. For\nevery $I,J\\in\\mathscr{T}A$\n\\begin{align*}\n\\alpha'(I\\sqcup J) & =\\\\\n\\bigsqcup\\rsupfun{\\alpha}\\atoms\\uparrow(I\\sqcup J) & =\\\\\n\\bigsqcup\\rsupfun{\\alpha}(\\atoms\\uparrow\\cup\\atoms\\uparrow J) & =\\\\\n\\bigsqcup(\\rsupfun{\\alpha}\\atoms\\uparrow I\\cup\\rsupfun{\\alpha}\\atoms\\uparrow J)\n& =\\\\\n\\bigsqcup\\rsupfun{\\alpha}\\atoms\\uparrow\nI\\sqcup\\bigsqcup\\rsupfun{\\alpha}\\atoms\\uparrow J & =\\\\\n\\alpha'I\\sqcup\\alpha'J.\n\\end{align*}\n\n\n\nLet continue $\\alpha'$ till a funcoid $f$ (by the theorem \\ref{fcd-as-cont}):\n$\\supfun f\\mathcal{X}=\\bigsqcap\\rsupfun{\\alpha'}\\up\\mathcal{X}$.\n\n\nLet's prove the reverse of (\\ref{at-func-cond}):\n\\begin{align*}\n\\bigsqcap\\rsupfun{\\bigsqcup\\circ\\rsupfun{\\alpha}\\circ\\atoms\\circ\\uparrow}\\up a &\n=\\\\\n\\bigsqcap\\rsupfun{\\bigsqcup\\circ\\rsupfun{\\alpha}}\\rsupfun{\\atoms}\\rsupfun{\n\\uparrow}\\up a & \\sqsubseteq\\\\\n\\bigsqcap\\rsupfun{\\bigsqcup\\circ\\rsupfun{\\alpha}}\\{\\{a\\}\\} & =\\\\\n\\bigsqcap\\left\\{ \\left(\\bigsqcup\\circ\\rsupfun{\\alpha}\\right)\\{a\\}\\right\\}  & =\\\\\n\\bigsqcap\\left\\{ \\bigsqcup\\rsupfun{\\alpha}\\{a\\}\\right\\}  & =\\\\\n\\bigsqcap\\left\\{ \\bigsqcup\\{\\alpha a\\}\\right\\}  & =\\\\\n\\bigsqcap\\{\\alpha a\\}  & =\\\\\n\\alpha a.\n\\end{align*}\n\n\n\nFinally,\n\\[\n\\alpha\na=\\bigsqcap\\rsupfun{\\bigsqcup\\circ\\rsupfun{\\alpha}\\circ\\atoms\\circ\\uparrow}\\up\na=\\bigsqcap\\rsupfun{\\alpha'}\\up a=\\supfun fa,\n\\]\n\n\n\nso $\\supfun f$ is a continuation of $\\alpha$.\n\n\\item [{\\ref{at-restr-r}}] Consider the relation\n$\\delta'\\in\\subsets(\\mathscr{T}A\\times\\mathscr{T}B)$\ndefined by the formula (for every $X\\in\\mathscr{T}A$, $Y\\in\\mathscr{T}B$)\n\\[\nX\\mathrel{\\delta'}Y\\Leftrightarrow\\exists x\\in\\atoms\\uparrow\nX,y\\in\\atoms\\uparrow Y:x\\mathrel\\delta y.\n\\]\n\n\n\nObviously $\\lnot(X\\mathrel{\\delta'}\\bot^{\\mathscr{F}(B)})$ and\n$\\lnot(\\bot^{\\mathscr{F}(A)}\\mathrel{\\delta'}Y)$.\n\n\nFor suitable $I$ and $J$ we have:\n\\begin{align*}\nI\\sqcup J\\mathrel{\\delta'}Y & \\Leftrightarrow\\\\\n\\exists x\\in\\atoms\\uparrow(I\\sqcup J),y\\in\\atoms\\uparrow Y:x\\mathrel\\delta y &\n\\Leftrightarrow\\\\\n\\exists x\\in\\atoms\\uparrow I\\cup\\atoms\\uparrow J,y\\in\\atoms\\uparrow\nY:x\\mathrel\\delta y & \\Leftrightarrow\\\\\n\\exists x\\in\\atoms\\uparrow I,y\\in\\atoms\\uparrow Y:x\\mathrel\\delta y\\lor\\exists\nx\\in\\atoms\\uparrow J,y\\in\\atoms\\uparrow Y:x\\mathrel\\delta y & \\Leftrightarrow\\\\\nI\\mathrel{\\delta'}Y\\lor J\\mathrel{\\delta'}Y;\n\\end{align*}\nsimilarly $X\\mathrel{\\delta'}I\\sqcup J\\Leftrightarrow X\\mathrel{\\delta'}I\\lor\nX\\mathrel{\\delta'}J$\nfor suitable $I$ and $J$. Let's continue $\\delta'$ till a funcoid\n$f$ (by the theorem \\ref{fcd-as-cont}):\n\\[\n\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\forall\nX\\in\\up\\mathcal{X},Y\\in\\up\\mathcal{Y}:X\\mathrel{\\delta'}Y.\n\\]\n\n\n\nThe reverse of (\\ref{at-rel-cond}) implication is trivial, so\n\\[\n\\forall X\\in\\up a,Y\\in\\up b\\exists x\\in\\atoms\\uparrow X,y\\in\\atoms\\uparrow\nY:x\\mathrel\\delta y\\Leftrightarrow a\\mathrel\\delta b.\n\\]\n\n\n\nAlso\n\\begin{align*}\n\\forall X\\in\\up a,Y\\in\\up b\\exists x\\in\\atoms\\uparrow X,y\\in\\atoms\\uparrow\nY:x\\mathrel\\delta y & \\Leftrightarrow\\\\\n\\forall X\\in\\up a,Y\\in\\up b:X\\mathrel{\\delta'}Y & \\Leftrightarrow\\\\\na\\suprel fb.\n\\end{align*}\n\n\n\nSo $a\\mathrel\\delta b\\Leftrightarrow a\\suprel fb$, that is $\\suprel f$\nis a continuation of $\\delta$.\n\n\\end{widedisorder}\n\\end{proof}\nOne of uses of the previous theorem is the proof of the following\ntheorem:\n\\begin{thm}\n\\label{fcd-intrs-atom}If $A$ and $B$ are sets, $R\\in\\subsets\\mathsf{FCD}(A,B)$,\n$x\\in\\atoms^{\\mathscr{F}(A)}$, $y\\in\\atoms^{\\mathscr{F}(B)}$, then\n\\begin{enumerate}\n\\item \\label{meet-f-at}$\\supfun{\\bigsqcap R}x=\\bigsqcap_{f\\in R}\\supfun fx$;\n\\item \\label{meet-r-at}$x\\suprel{\\bigsqcap R}y\\Leftrightarrow\\forall f\\in\nR:x\\suprel fy$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{meet-r-at}}] Let denote $x\\mathrel\\delta y\\Leftrightarrow\\forall\nf\\in R:x\\suprel fy$.\nFor every $a\\in\\atoms^{\\mathscr{F}(A)}$, $b\\in\\atoms^{\\mathscr{F}(B)}$\n\\begin{align*}\n\\forall X\\in\\up a,Y\\in\\up b\\exists x\\in\\atoms\\uparrow X,y\\in\\atoms\\uparrow\nY:x\\mathrel\\delta y & \\Rightarrow\\\\\n\\forall f\\in R,X\\in\\up a,Y\\in\\up b\\exists x\\in\\atoms\\uparrow X,y\\in\\atoms\\uparrow\nY:x\\suprel fy & \\Rightarrow\\\\\n\\forall f\\in R,X\\in\\up a,Y\\in\\up b:X\\rsuprel fY & \\Rightarrow\\\\\n\\forall f\\in R:a\\suprel fb & \\Leftrightarrow\\\\\na\\mathrel\\delta b.\n\\end{align*}\n\n\n\nSo by theorem~\\ref{cont-fcd-on-atoms}, $\\delta$ can be continued\ntill $\\suprel p$ for some funcoid $p\\in\\mathsf{FCD}(A,B)$.\n\n\nFor every funcoid $q\\in\\mathsf{FCD}(A,B)$ such that $\\forall f\\in R:q\\sqsubseteq\nf$\nwe have\n\\[\nx\\suprel qy\\Rightarrow\\forall f\\in R:x\\suprel fy\\Leftrightarrow x\\mathrel\\delta\ny\\Leftrightarrow x\\suprel py,\n\\]\n\n\n\nso $q\\sqsubseteq p$. Consequently $p=\\bigsqcap R$.\n\n\nFrom this $x\\suprel{\\bigsqcap R}y\\Leftrightarrow\\forall f\\in R:x\\suprel fy$.\n\n\\item [{\\ref{meet-f-at}}] From the former\n\\begin{align*}\ny\\in\\atoms\\supfun{\\bigsqcap R}x & \\Leftrightarrow\\\\\ny\\sqcap\\supfun{\\bigsqcap R}x\\ne\\bot & \\Leftrightarrow\\\\\n\\forall f\\in R:y\\sqcap\\supfun fx\\ne\\bot & \\Leftrightarrow\\\\\ny\\in\\bigsqcap\\rsupfun{\\atoms}\\setcond{\\supfun fx}{f\\in R} & \\Leftrightarrow\\\\\ny\\in\\atoms\\bigsqcap_{f\\in R}\\supfun fx\n\\end{align*}\nfor every $y\\in\\atoms^{\\mathscr{F}(A)}$. From this it follows $\\supfun{\\bigsqcap\nR}x=\\bigsqcap_{f\\in R}\\supfun fx$.\n\\end{widedisorder}\n\\end{proof}\n\\begin{thm}\n$g\\circ f=\\bigsqcap^{\\mathsf{FCD}}\\setcond{G\\circ F}{F\\in\\up f.G\\in\\up g}$ for every\ncomposable funcoids~$f$ and~$g$.\\end{thm}\n\\begin{proof}\nLet $x\\in\\atoms^{\\mathscr{F}(\\Src f)}$. Then\n\\begin{align*}\n\\supfun{g\\circ f}x & =\\\\\n\\supfun g\\supfun fx & =\\text{ (theorem \\ref{fcd-up-x})}\\\\\n\\bigsqcap_{G\\in\\up g}^{\\mathscr{F}}\\supfun G\\supfun fx & =\\text{ (theorem\n\\ref{fcd-up-x})}\\\\\n\\bigsqcap_{G\\in\\up g}^{\\mathscr{F}}\\supfun G\\bigsqcap_{F\\in\\up\nf}^{\\mathscr{F}}\\supfun Fx & =\\text{ (theorem \\ref{supfun-genbase})}\\\\\n\\bigsqcap_{G\\in\\up g}^{\\mathscr{F}}\\bigsqcap_{F\\in\\up f}^{\\mathscr{F}}\\supfun\nG\\supfun Fx & =\\\\\n\\bigsqcap^{\\mathscr{F}}\\setcond{\\supfun G\\supfun Fx}{F\\in\\up f,G\\in\\up g} & =\\\\\n\\bigsqcap^{\\mathscr{F}}\\setcond{\\supfun{G\\circ F}x}{F\\in\\up f,G\\in\\up g} & =\\text{ (theorem\n\\ref{fcd-intrs-atom})}\\\\\n\\supfun{\\bigsqcap^{\\mathsf{FCD}}\\setcond{G\\circ F}{F\\in\\up f,G\\in\\up g}}x.\n\\end{align*}\n\n\nThus $g\\circ f=\\bigsqcap^{\\mathsf{FCD}}\\setcond{G\\circ F}{F\\in\\up f.G\\in\\up g}$.\\end{proof}\n\n\\begin{prop}\n  For $f \\in \\mathsf{FCD} (A, B)$, a finite set $X \\in \\subsets A$\n  and a function $t \\in \\mathscr{F} (B)^X$ there exists (obviously unique) $g\n  \\in \\mathsf{FCD} (A, B)$ such that $\\supfun{g} p = \\langle f\n  \\rangle p$ for $p \\in \\atoms^{\\mathscr{F} (A)} \\setminus \\atoms\n  X$ and $\\supfun{g} @\\{ x \\} = t (x)$ for $x \\in X$.\n\n  This funcoid $g$ is determined by the formula\n  \\[ g = (f \\setminus (@X \\times^{\\mathsf{FCD}} \\top)) \\sqcup\n     \\bigsqcup_{x \\in X} (@\\{ x \\} \\times^{\\mathsf{FCD}} t (x)) . \\]\n\\end{prop}\n\n\\begin{proof}\n  Take $g = (f \\setminus (@X \\times^{\\mathsf{FCD}} \\top)) \\sqcup\n  \\bigsqcup_{q \\in X} (@\\{ q \\} \\times^{\\mathsf{FCD}} t (x))$ that is\n\\begin{multline*}\ng = \\left( f \\sqcap \\overline{X \\times \\top} \\right) \\sqcup \\bigsqcup_{q \\in\n  X} (@\\{ q \\} \\times^{\\mathsf{FCD}} t (x)) = \\\\\\left( f \\sqcap \\left(\n  \\overline{X} \\times \\top \\right) \\right) \\sqcup \\bigsqcup_{q \\in X} (@\\{ q \\}\n  \\times^{\\mathsf{FCD}} t (x)).\n\\end{multline*}\n\n\\begin{multline*}\n  \\supfun{g} p = \\text{(theorem~\\ref{fcd-fin-join})} =\\\\ \\left\\langle f\n  \\sqcap \\left( \\overline{X} \\times \\top \\right) \\right\\rangle p \\sqcup\n  \\bigsqcup_{q \\in X} \\langle @\\{ q \\} \\times^{\\mathsf{FCD}} t (x)\n  \\rangle p = \\\\ \\text{(theorem~\\ref{fcd-intrs-atom})} = \\left( \\supfun{f} p \\sqcap\n  \\left\\langle \\overline{X} \\times \\top \\right\\rangle p \\right) \\sqcup\n  \\bigsqcup_{q \\in X} \\langle @\\{ q \\} \\times^{\\mathsf{FCD}} t (x)\n  \\rangle p.\n\\end{multline*}\n\n  So $\\supfun{g} @\\{ x \\} = (\\supfun{f}^{\\ast} @\\{ x \\} \\sqcap\n  \\bot) \\sqcup t (x) = t (x)$ for $x \\in X$.\n\n  If $p \\in \\atoms^{\\mathscr{F} (A)} \\setminus \\atoms X$ then we\n  have $\\supfun{g} p = (\\supfun{f} p \\sqcap \\top) \\sqcup \\bot =\n  \\supfun{f} p$.\n\\end{proof}\n\n\\begin{cor}\n  If $f \\in \\mathsf{FCD} (A, B)$, $x \\in A$, and $\\mathcal{Y} \\in\n  \\mathscr{F} (B)$, then there exists an (obviously unique) $g \\in\n  \\mathsf{FCD} (A, B)$ such that $\\supfun{g} p = \\langle f\n  \\rangle p$ for all ultrafilters $p$ except of $p = @\\{ x \\}$ and $\\langle g\n  \\rangle @\\{ x \\} = \\mathcal{Y}$.\n\n  This funcoid $g$ is determined by the formula\n  \\[ g = (f \\setminus (@\\{ x \\} \\times^{\\mathsf{FCD}} \\top)) \\sqcup (\\{\n     x \\} \\times^{\\mathsf{FCD}} \\mathcal{Y}) . \\]\n\\end{cor}\n\n\\begin{thm}\n\\label{fcd-cross}Let $A$, $B$, $C$ be sets, $f\\in\\mathsf{FCD}(A,B)$,\n$g\\in\\mathsf{FCD}(B,C)$, $h\\in\\mathsf{FCD}(A,C)$. Then\n\\[\ng\\circ f\\nasymp h\\Leftrightarrow g\\nasymp h\\circ f^{-1}.\n\\]\n\\end{thm}\n\\begin{proof}\n~\n\\begin{align*}\ng\\circ f\\nasymp h & \\Leftrightarrow\\\\\n\\exists a\\in\\atoms^{\\mathscr{F}(A)},c\\in\\atoms^{\\mathscr{F}(C)}:a\\suprel{(g\\circ\nf)\\sqcap h}c & \\Leftrightarrow\\\\\n\\exists a\\in\\atoms^{\\mathscr{F}(A)},c\\in\\atoms^{\\mathscr{F}(C)}:(a\\suprel{g\\circ\nf}c\\land a\\suprel hc) & \\Leftrightarrow\\\\\n\\exists\na\\in\\atoms^{\\mathscr{F}(A)},b\\in\\atoms^{\\mathscr{F}(B)},c\\in\\atoms^{\\mathscr{F}\n(C)}:(a\\suprel fb\\land b\\suprel gc\\land a\\suprel hc) & \\Leftrightarrow\\\\\n\\exists b\\in\\atoms^{\\mathscr{F}(B)},c\\in\\atoms^{\\mathscr{F}(C)}:(b\\suprel\ngc\\land b\\suprel{h\\circ f^{-1}}c) & \\Leftrightarrow\\\\\n\\exists\nb\\in\\atoms^{\\mathscr{F}(B)},c\\in\\atoms^{\\mathscr{F}(C)}:b\\suprel{g\\sqcap(h\\circ\nf^{-1})}c & \\Leftrightarrow\\\\\ng\\nasymp h\\circ f^{-1}.\n\\end{align*}\n\n\\end{proof}\n\n\\section{Funcoidal product of filters}\n\nA generalization of Cartesian product of two sets is funcoidal product\nof two filters:\n\\begin{defn}\n\\index{product!funcoidal}\\emph{Funcoidal product} of filters $\\mathcal{A}$\nand $\\mathcal{B}$ is such a funcoid\n$\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}\\in\\mathsf{FCD}(\\Base(\\mathcal{A}\n),\\Base(\\mathcal{B}))$\nthat for every $\\mathcal{X}\\in\\Base(\\mathcal{A})$,\n$\\mathcal{Y}\\in\\Base(\\mathcal{B})$\n\\[\n\\mathcal{X}\\suprel{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}\\mathcal{Y}\n\\Leftrightarrow\\mathcal{X}\\nasymp\\mathcal{A}\\land\\mathcal{Y}\\nasymp\\mathcal{B}.\n\\]\n\\end{defn}\n\\begin{prop}\n$\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}$ is really a funcoid\nand\n\\[\n\\supfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}\\mathcal{X}=\\begin{cases}\n\\mathcal{B} & \\text{if }\\mathcal{X}\\nasymp\\mathcal{A}\\\\\n\\bot^{\\mathscr{F}(\\Base(\\mathcal{B}))} & \\text{if }\\mathcal{X}\\asymp\\mathcal{A}.\n\\end{cases}\n\\]\n\\end{prop}\n\\begin{proof}\nObvious.\\end{proof}\n\\begin{obvious}\n~\n\\begin{itemize}\n\\item $\\uparrow^{\\mathsf{FCD}(U,V)}(A\\times B)=\\uparrow^{U}A\\times\\uparrow^{V}B$\nfor sets $A\\subseteq U$ and $B\\subseteq V$.\n\\item $\\uparrow^{\\mathsf{FCD}}(A\\times B)=\\uparrow A\\times\\uparrow B$ for\ntyped sets~$A$ and~$B$.\n\\end{itemize}\n\\end{obvious}\n\\begin{prop}\n$f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}\\Leftrightarrow\\dom\nf\\sqsubseteq\\mathcal{A}\\land\\im f\\sqsubseteq\\mathcal{B}$\nfor every $f\\in\\mathsf{FCD}(A,B)$ and $\\mathcal{A}\\in\\mathscr{F}(A)$,\n$\\mathcal{B}\\in\\mathscr{F}(B)$.\\end{prop}\n\\begin{proof}\nIf $f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}$ then\n$\\dom\nf\\sqsubseteq\\dom(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})\\sqsubseteq\\mathcal\n{A}$,\n$\\im\nf\\sqsubseteq\\im(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})\\sqsubseteq\\mathcal{\nB}$.\nIf $\\dom f\\sqsubseteq\\mathcal{A}\\land\\im f\\sqsubseteq\\mathcal{B}$\nthen\n\\[\n\\forall\\mathcal{X}\\in\\mathscr{F}(A),\\mathcal{Y}\\in\\mathscr{F}(B):(\\mathcal{X}\n\\suprel\nf\\mathcal{Y}\\Rightarrow\\mathcal{X}\\sqcap\\mathcal{A}\\ne\\bot\n\\land\\mathcal{Y}\\sqcap\\mathcal{B}\\ne\\bot);\n\\]\nconsequently $f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}$.\n\\end{proof}\nThe following theorem gives a formula for calculating an important\nparticular case of a meet on the lattice of funcoids:\n\\begin{thm}\n$f\\sqcap(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})=\\id_{\\mathcal{B}}^{\\mathsf\n{FCD}}\\circ f\\circ\\id_{\\mathcal{A}}^{\\mathsf{FCD}}$\nfor every funcoid $f$ and $\\mathcal{A}\\in\\mathscr{F}(\\Src f)$,\n$\\mathcal{B}\\in\\mathscr{F}(\\Dst f)$.\\end{thm}\n\\begin{proof}\n$h\\eqdef\\id_{\\mathcal{B}}^{\\mathsf{FCD}}\\circ\nf\\circ\\id_{\\mathcal{A}}^{\\mathsf{FCD}}$.\nFor every $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$\n\\[\n\\supfun h\\mathcal{X}=\\supfun{\\id_{\\mathcal{B}}^{\\mathsf{FCD}}}\\supfun\nf\\supfun{\\id_{\\mathcal{A}}^{\\mathsf{FCD}}}\\mathcal{X}=\\mathcal{B}\\sqcap\\supfun\nf(\\mathcal{A}\\sqcap\\mathcal{X}).\n\\]\n\n\nFrom this, as easy to show, $h\\sqsubseteq f$ and\n$h\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}$.\nIf $g\\sqsubseteq f\\land g\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}$\nfor a $g\\in\\mathsf{FCD}(\\Src f,\\Dst f)$ then $\\dom g\\sqsubseteq\\mathcal{A}$,\n$\\im g\\sqsubseteq\\mathcal{B}$,\n\\[\n\\supfun g\\mathcal{X}=\\mathcal{B}\\sqcap\\supfun\ng(\\mathcal{A}\\sqcap\\mathcal{X})\\sqsubseteq\\mathcal{B}\\sqcap\\supfun\nf(\\mathcal{A}\\sqcap\\mathcal{X})=\\supfun{\\id_{\\mathcal{B}}^{\\mathsf{FCD}}}\\supfun\nf\\supfun{\\id_{\\mathcal{A}}^{\\mathsf{FCD}}}\\mathcal{X}=\\supfun h\\mathcal{X},\n\\]\n$g\\sqsubseteq h$. So\n$h=f\\sqcap(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})$.\\end{proof}\n\\begin{cor}\n$f|_{\\mathcal{A}}=f\\sqcap(\\mathcal{A}\\times^{\\mathsf{FCD}}\\top^{\\mathscr{F}(\\Dst\nf)})$\nfor every funcoid $f$ and $\\mathcal{A}\\in\\mathscr{F}(\\Src f)$.\\end{cor}\n\\begin{proof}\n$f\\sqcap(\\mathcal{A}\\times^{\\mathsf{FCD}}\\top^{\\mathscr{F}(\\Dst\nf)})=\\id_{\\top^{\\mathscr{F}(\\Dst f)}}^{\\mathsf{FCD}}\\circ\nf\\circ\\id_{\\mathcal{A}}^{\\mathsf{FCD}}=f\\circ\\id_{\\mathcal{A}}^{\\mathsf{FCD}}\n=f|_{\\mathcal{A}}$.\\end{proof}\n\\begin{cor}\n$f\\nasymp\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}\\Leftrightarrow\\mathcal{A}\n\\suprel f\\mathcal{B}$\nfor every funcoid $f$ and $\\mathcal{A}\\in\\mathscr{F}(\\Src f)$,\n$\\mathcal{B}\\in\\mathscr{F}(\\Dst f)$.\\end{cor}\n\\begin{proof}\n~\n\\begin{align*}\nf\\nasymp\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B} & \\Leftrightarrow\\\\\n\\rsupfun{f\\sqcap(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})}\\top\\ne\\bot & \\Leftrightarrow\\\\\n\\rsupfun{\\id_{\\mathcal{B}}^{\\mathsf{FCD}}\\circ\nf\\circ\\id_{\\mathcal{A}}^{\\mathsf{FCD}}}\\top\\ne\\bot & \\Leftrightarrow\\\\\n\\supfun{\\id_{\\mathcal{B}}^{\\mathsf{FCD}}}\\supfun\nf\\rsupfun{\\id_{\\mathcal{A}}^{\\mathsf{FCD}}}\\top\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{B}\\sqcap\\supfun f(\\mathcal{A}\\sqcap\\top)\\ne\\bot & \\Leftrightarrow\\\\\n\\mathcal{B}\\sqcap\\supfun f\\mathcal{A}\\ne\\bot &\n\\Leftrightarrow\\\\\n\\mathcal{A}\\suprel f\\mathcal{B}.\n\\end{align*}\n\\end{proof}\n\\begin{cor}\nEvery filtrator of funcoids is star-separable.\\end{cor}\n\\begin{proof}\nThe set of funcoidal products of principal filters is a separation\nsubset of the lattice of funcoids.\\end{proof}\n\\begin{thm}\n\\label{meet-prod-fcd}Let $A$, $B$ be sets. If\n$S\\in\\subsets(\\mathscr{F}(A)\\times\\mathscr{F}(B))$\nthen\n\\[\n\\bigsqcap_{(\\mathcal{A},\\mathcal{B})\\in\nS}(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})=\\bigsqcap\\dom\nS\\times^{\\mathsf{FCD}}\\bigsqcap\\im S.\n\\]\n\\end{thm}\n\\begin{proof}\nIf $x\\in\\atoms^{\\mathscr{F}(A)}$ then by theorem \\ref{fcd-intrs-atom}\n\\[\n\\supfun{\\bigsqcap_{(\\mathcal{A},\\mathcal{B})\\in\nS}(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})}x=\\bigsqcap_{(\\mathcal{A}\n,\\mathcal{B})\\in S}\\supfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}x.\n\\]\n\n\nIf $x\\nasymp\\bigsqcap\\dom S$ then\n\\begin{gather*}\n\\forall(\\mathcal{A},\\mathcal{B})\\in\nS:(x\\sqcap\\mathcal{A}\\ne\\bot\\land\\supfun{\\mathcal{A}\\times^{\n\\mathsf{FCD}}\\mathcal{B}}x=\\mathcal{B});\\\\\n\\setcond{\\supfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}x}{(\\mathcal{A}\n,\\mathcal{B})\\in S}=\\im S;\n\\end{gather*}\n\n\nif $x\\asymp\\bigsqcap\\dom S$ then\n\\begin{gather*}\n\\exists(\\mathcal{A},\\mathcal{B})\\in\nS:(x\\sqcap\\mathcal{A}=\\bot\\land\\supfun{\\mathcal{A}\\times^{\n\\mathsf{FCD}}\\mathcal{B}}x=\\bot);\\\\\n\\setcond{\\supfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}x}{(\\mathcal{A}\n,\\mathcal{B})\\in S}\\ni\\bot.\n\\end{gather*}\n\n\nSo\n\\[\n\\supfun{\\bigsqcap_{(\\mathcal{A},\\mathcal{B})\\in\nS}(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})}x=\\begin{cases}\n\\bigsqcap\\im S & \\text{if }x\\nasymp\\bigsqcap\\dom S\\\\\n\\bot^{\\mathscr{F}(B)} & \\text{if }x\\asymp\\bigsqcap\\dom S.\n\\end{cases}\n\\]\n\n\nFrom this the statement of the theorem follows.\\end{proof}\n\\begin{cor}\nFor every $\\mathcal{A}_{0},\\mathcal{A}_{1}\\in\\mathscr{F}(A)$,\n$\\mathcal{B}_{0},\\mathcal{B}_{1}\\in\\mathscr{F}(B)$\n(for every sets $A$,~$B$)\n\\[\n(\\mathcal{A}_{0}\\times^{\\mathsf{FCD}}\\mathcal{B}_{0})\\sqcap(\\mathcal{A}_{1}\n\\times^{\\mathsf{FCD}}\\mathcal{B}_{1})=(\\mathcal{A}_{0}\\sqcap\\mathcal{A}_{1}\n)\\times^{\\mathsf{FCD}}(\\mathcal{B}_{0}\\sqcap\\mathcal{B}_{1}).\n\\]\n\\end{cor}\n\\begin{proof}\n$(\\mathcal{A}_{0}\\times^{\\mathsf{FCD}}\\mathcal{B}_{0})\\sqcap(\\mathcal{A}_{1}\n\\times^{\\mathsf{FCD}}\\mathcal{B}_{1})=\\bigsqcap\\{\\mathcal{A}\\times^{\\mathsf{FCD\n}}\\mathcal{B}_{0},\\mathcal{A}_{1}\\times^{\\mathsf{FCD}}\\mathcal{B}_{1}\\}$\nwhat is by the last theorem equal to\n$(\\mathcal{A}_{0}\\sqcap\\mathcal{A}_{1})\\times^{\\mathsf{FCD}}(\\mathcal{B}_{0}\n\\sqcap\\mathcal{B}_{1})$.\\end{proof}\n\\begin{thm}\nIf $A$, $B$ are sets and $\\mathcal{A}\\in\\mathscr{F}(A)$ then\n$\\mathcal{A}\\times^{\\mathsf{FCD}}$\nis a complete homomorphism from the lattice $\\mathscr{F}(B)$ to the\nlattice $\\mathsf{FCD}(A,B)$, if also $\\mathcal{A}\\ne\\bot^{\\mathscr{F}(A)}$\nthen it is an order embedding.\\end{thm}\n\\begin{proof}\nLet $S\\in\\subsets\\mathscr{F}(B)$, $X\\in\\mathscr{T}A$,\n$x\\in\\atoms^{\\mathscr{F}(A)}$.\n\\begin{align*}\n\\rsupfun{\\bigsqcup\\rsupfun{\\mathcal{A}\\times^{\\mathsf{FCD}}}S}X & =\\\\\n\\bigsqcup_{\\mathcal{B}\\in\nS}\\rsupfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}X & =\\\\\n\\begin{cases}\n\\bigsqcup S & \\text{if }X\\in\\corestar\\mathcal{A}\\\\\n\\bot^{\\mathscr{F}(B)} & \\text{if }X\\notin\\corestar\\mathcal{A}\n\\end{cases} & =\\\\\n\\rsupfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\bigsqcup S}X;\\\\\n\\supfun{\\bigsqcap\\rsupfun{\\mathcal{A}\\times^{\\mathsf{FCD}}}S}x & =\\\\\n\\bigsqcap_{\\mathcal{B}\\in\nS}\\supfun{\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}}x & =\\\\\n\\begin{cases}\n\\bigsqcap S & \\text{if }x\\nasymp\\mathcal{A}\\\\\n\\bot^{\\mathscr{F}(B)} & \\text{if }x\\asymp\\mathcal{A}.\n\\end{cases}\n\\end{align*}\n\n\nThus\n$\\bigsqcup\\rsupfun{\\mathcal{A}\\times^{\\mathsf{FCD}}}S=\\mathcal{A}\\times^{\\mathsf\n{FCD}}\\bigsqcup S$\nand\n$\\bigsqcap\\rsupfun{\\mathcal{A}\\times^{\\mathsf{FCD}}}S=\\mathcal{A}\\times^{\\mathsf\n{FCD}}\\bigsqcap S$.\n\nIf $\\mathcal{A}\\ne\\bot$ then obviously\n$\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{X}\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{Y} \\Leftrightarrow\n\\mathcal{X}\\sqsubseteq\\mathcal{Y}$.\n\\end{proof}\nThe following proposition states that cutting a rectangle of atomic\nwidth from a funcoid always produces a rectangular (representable\nas a funcoidal product of filters) funcoid (of atomic width).\n\\begin{prop}\nIf $f$ is a funcoid and $a$ is an atomic filter on $\\Src f$ then\n\\[\nf|_{a}=a\\times^{\\mathsf{FCD}}\\supfun fa.\n\\]\n\\end{prop}\n\\begin{proof}\nLet $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$.\n\\[\n\\mathcal{X}\\nasymp a\\Rightarrow\\supfun{f|_{a}}\\mathcal{X}=\\supfun\nfa,\\quad\\mathcal{X}\\asymp\na\\Rightarrow\\supfun{f|_{a}}\\mathcal{X}=\\bot^{\\mathscr{F}(\\Dst f)}.\n\\]\n\n\\end{proof}\n\n\\begin{lem}\n$\\mylambda{\\mathcal{B}}{\\mathscr{F}(B)}{\\top^{\\mathscr{F}}\\times^{\\mathsf{FCD}}\n\\mathcal{B}}$\nis an upper adjoint of $\\mylambda f{\\mathsf{FCD}(A,B)}{\\im f}$ (for\nevery sets $A$, $B$).\\end{lem}\n\\begin{proof}\nWe need to prove $\\im f\\sqsubseteq\\mathcal{B}\\Leftrightarrow\nf\\sqsubseteq\\top\\times^{\\mathsf{FCD}}\\mathcal{B}$\nwhat is obvious.\\end{proof}\n\\begin{cor}\n\\label{fcd-dom-join}Image and domain of funcoids preserve joins.\\end{cor}\n\\begin{proof}\nBy properties of Galois connections and duality.\\end{proof}\n\\begin{prop}\n$f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}\\Leftrightarrow\\dom\nf\\sqsubseteq\\mathcal{A}\\wedge\\im f\\sqsubseteq\\mathcal{B}$\nfor every funcoid $f$ and filters $\\mathcal{A}\\in\\mathfrak{F}(\\Src f)$,\n$\\mathcal{B}\\in\\mathfrak{F}(\\Dst f)$.\\end{prop}\n\\begin{proof}\n$f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}\\Rightarrow\\dom\nf\\sqsubseteq\\mathcal{A}$\nbecause\n$\\dom(\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B})\\sqsubseteq\\mathcal{A}$.\n\nLet now $\\dom f\\sqsubseteq\\mathcal{A}\\wedge\\im f\\sqsubseteq\\mathcal{B}$.\nThen $\\supfun f\\mathcal{X}\\neq\\bot\\Rightarrow\\mathcal{X}\\nasymp\\mathcal{A}$\nthat is $f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\top$. Similarly\n$f\\sqsubseteq\\top\\times^{\\mathsf{FCD}}\\mathcal{B}$. Thus\n$f\\sqsubseteq\\mathcal{A}\\times^{\\mathsf{FCD}}\\mathcal{B}$.\n\\end{proof}\n\n\\section{Atomic funcoids}\n\\begin{thm}\nAn $f\\in\\mathsf{FCD}(A,B)$ is an atom of the lattice $\\mathsf{FCD}(A,B)$\n(for some sets $A$, $B$) iff it is a funcoidal product of two atomic\nfilter objects.\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] Let $f\\in\\mathsf{FCD}(A,B)$ be an atom of the\nlattice $\\mathsf{FCD}(A,B)$. Let's get elements $a\\in\\atoms\\dom f$\nand $b\\in\\atoms\\supfun fa$. Then for every $\\mathcal{X}\\in\\mathscr{F}(A)$\n\\[\n\\mathcal{X}\\asymp\na\\Rightarrow\\supfun{a\\times^{\\mathsf{FCD}}b}\\mathcal{X}=\\bot\n\\sqsubseteq\\supfun f\\mathcal{X},\\quad\\mathcal{X}\\nasymp\na\\Rightarrow\\supfun{a\\times^{\\mathsf{FCD}}b}\\mathcal{X}=b\\sqsubseteq\\supfun\nf\\mathcal{X}.\n\\]\n\n\n\nSo $a\\times^{\\mathsf{FCD}}b\\sqsubseteq f$; because $f$ is atomic we\nhave $f=a\\times^{\\mathsf{FCD}}b$.\n\n\\item [{$\\Leftarrow$}] Let $a\\in\\atoms^{\\mathscr{F}(A)}$,\n$b\\in\\atoms^{\\mathscr{F}(B)}$,\n$f\\in\\mathsf{FCD}(A,B)$. If $b\\asymp\\supfun fa$ then $\\lnot(a\\suprel fb)$,\n$f\\asymp a\\times^{\\mathsf{FCD}}b$; if $b\\sqsubseteq\\supfun fa$ then\n$\\forall\\mathcal{X}\\in\\mathscr{F}(A):(\\mathcal{X}\\nasymp a\\Rightarrow\\supfun\nf\\mathcal{X}\\sqsupseteq b)$,\n$f\\sqsupseteq a\\times^{\\mathsf{FCD}}b$. Consequently $f\\asymp\na\\times^{\\mathsf{FCD}}b\\lor f\\sqsupseteq a\\times^{\\mathsf{FCD}}b$;\nthat is $a\\times^{\\mathsf{FCD}}b$ is an atom.\n\\end{description}\n\\end{proof}\n\\begin{thm}\nThe lattice $\\mathsf{FCD}(A,B)$ is atomic (for every fixed sets $A$, $B$).\\end{thm}\n\\begin{proof}\nLet $f$ be a non-empty funcoid from $A$ to $B$. Then $\\dom\nf\\ne\\bot$,\nthus by theorem~\\ref{filt-atomic} there exists $a\\in\\atoms\\dom f$.\nSo $\\supfun fa\\ne\\bot$ thus it exists $b\\in\\atoms\\supfun fa$.\nFinally the atomic funcoid $a\\times^{\\mathsf{FCD}}b\\sqsubseteq f$.\\end{proof}\n\\begin{thm}\nThe lattice $\\mathsf{FCD}(A,B)$ is separable (for every fixed sets $A$,\n$B$).\\end{thm}\n\\begin{proof}\nLet $f,g\\in\\mathsf{FCD}(A,B)$, $f\\sqsubset g$. Then there exists\n$a\\in\\atoms^{\\mathscr{F}(A)}$ such that $\\supfun fa\\sqsubset\\supfun ga$.\nSo because the lattice $\\mathscr{F}(B)$ is atomically separable,\nthere exists $b\\in\\atoms$ such that $\\supfun fa\\sqcap\nb=\\bot$\nand $b\\sqsubseteq\\supfun ga$. For every $x\\in\\atoms^{\\mathscr{F}(A)}$\n\\begin{gather*}\n\\supfun fa\\sqcap\\supfun{a\\times^{\\mathsf{FCD}}b}a=\\supfun fa\\sqcap\nb=\\bot,\\\\\nx\\ne a\\Rightarrow\\supfun fx\\sqcap\\supfun{a\\times^{\\mathsf{FCD}}b}x=\\supfun\nfx\\sqcap\\bot=\\bot.\n\\end{gather*}\n\n\nThus $\\supfun fx\\sqcap\\supfun{a\\times^{\\mathsf{FCD}}b}x=\\bot$\nand consequently $f\\asymp a\\times^{\\mathsf{FCD}}b$.\n\\begin{gather*}\n\\supfun{a\\times^{\\mathsf{FCD}}b}a=b\\sqsubseteq\\supfun ga,\\\\\nx\\ne\na\\Rightarrow\\supfun{a\\times^{\\mathsf{FCD}}b}x=\\bot\n\\sqsubseteq\\supfun gx.\n\\end{gather*}\n\n\nThus $\\supfun{a\\times^{\\mathsf{FCD}}b}x\\sqsubseteq\\supfun gx$ and\nconsequently $a\\times^{\\mathsf{FCD}}b\\sqsubseteq g$.\n\nSo the lattice $\\mathsf{FCD}(A,B)$ is separable by theorem\n\\ref{msl-sep-conds}.\\end{proof}\n\\begin{cor}\n\\label{fcd-is-sep}The lattice $\\mathsf{FCD}(A,B)$ is:\n\\begin{enumerate}\n\\item separable;\n\\item strongly separable;\n\\item atomically separable;\n\\item conforming to Wallman's disjunction property.\n\\end{enumerate}\n\\end{cor}\n\\begin{proof}\nBy theorem \\ref{sep-conds}.\\end{proof}\n\\begin{rem}\nFor more ways to characterize (atomic) separability of the lattice\nof funcoids see subsections ``Separation subsets and full stars''\nand ``Atomically separable lattices''.\\end{rem}\n\\begin{cor}\nThe lattice $\\mathsf{FCD}(A,B)$ is an atomistic lattice.\\end{cor}\n\\begin{proof}\nBy theorem~\\ref{amstc-sep}.\\end{proof}\n\\begin{prop}\n$\\atoms(f\\sqcup g)=\\atoms f\\cup\\atoms g$ for every funcoids\n$f,g\\in\\mathsf{FCD}(A,B)$\n(for every sets $A$, $B$).\\end{prop}\n\\begin{proof}\n$a\\times^{\\mathsf{FCD}}b\\nasymp f\\sqcup g\\Leftrightarrow a\\suprel{f\\sqcup\ng}b\\Leftrightarrow a\\suprel fb\\lor a\\suprel gb\\Leftrightarrow\na\\times^{\\mathsf{FCD}}b\\nasymp f\\lor a\\times^{\\mathsf{FCD}}b\\nasymp g$\nfor every atomic filters $a$ and $b$.\\end{proof}\n\\begin{thm}\nThe set of funcoids between sets~$A$ and~$B$ is a co-frame.\\end{thm}\n\\begin{proof}\nTheorems \\ref{fcd-as-cont} and \\ref{frame-main}.\\end{proof}\n\\begin{rem}\nThe above proof does not use axiom of choice (unlike the below proof).\n\\end{rem}\nSee also an older proof of the set of funcoids being co-brouwerian:\n\\begin{thm}\nFor every $f,g,h\\in\\mathsf{FCD}(A,B)$, $R\\in\\subsets\\mathsf{FCD}(A,B)$\n(for every sets $A$ and $B$)\n\\begin{enumerate}\n\\item \\label{fcd-dist-j}$f\\sqcap(g\\sqcup h)=(f\\sqcap g)\\sqcup(f\\sqcap h)$;\n\\item \\label{fcd-dist-m}$f\\sqcup\\bigsqcap R=\\bigsqcap\\rsupfun{f\\sqcup}R$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will take into account that the lattice of funcoids is an atomistic\nlattice.\n\\begin{widedisorder}\n\\item [{\\ref{fcd-dist-j}}] ~\n\\begin{align*}\n\\atoms(f\\sqcap(g\\sqcup h)) & =\\\\\n\\atoms f\\cap\\atoms(g\\sqcup h) & =\\\\\n\\atoms f\\cap(\\atoms g\\cup\\atoms h) & =\\\\\n(\\atoms f\\cap\\atoms g)\\cup(\\atoms f\\cap\\atoms h) & =\\\\\n\\atoms(f\\sqcap g)\\cup\\atoms(f\\sqcap h) & =\\\\\n\\atoms((f\\sqcap g)\\sqcup(f\\sqcap h)).\n\\end{align*}\n\n\\item [{\\ref{fcd-dist-m}}] ~\n\\begin{align*}\n\\atoms\\left(f\\sqcup\\bigsqcap R\\right) & =\\\\\n\\atoms f\\cup\\atoms\\bigsqcap R & =\\\\\n\\atoms f\\cup\\bigcap\\rsupfun{\\atoms}R & =\\\\\n\\bigcap\\rsupfun{(\\atoms f)\\cup}\\rsupfun{\\atoms}R & =\\text{ (use the following\nequality)}\\\\\n\\bigcap\\rsupfun{\\atoms}\\rsupfun{f\\sqcup}R & =\\\\\n\\atoms\\bigsqcap\\rsupfun{f\\sqcup}R.\\\\\n\\rsupfun{(\\atoms f)\\cup}\\rsupfun{\\atoms}R & =\\\\\n\\setcond{(\\atoms f)\\cup A}{A\\in\\rsupfun{\\atoms}R} & =\\\\\n\\setcond{(\\atoms f)\\cup A}{\\exists C\\in R:A=\\atoms C} & =\\\\\n\\setcond{(\\atoms f)\\cup(\\atoms C)}{C\\in R} & =\\\\\n\\setcond{\\atoms(f\\sqcup C)}{C\\in R} & =\\\\\n\\setcond{\\atoms B}{\\exists C\\in R:B=f\\sqcup C} & =\\\\\n\\setcond{\\atoms B}{B\\in\\rsupfun{f\\sqcup}C} & =\\\\\n\\rsupfun{\\atoms}\\rsupfun{f\\sqcup}R.\n\\end{align*}\n\n\\end{widedisorder}\n\\end{proof}\n\n\\begin{conjecture}\n$f \\sqcap \\bigsqcup S = \\bigsqcup \\langle f \\sqcap \\rangle^{\\ast} S$ for principal funcoid~$f$ and a set~$S$ of\nfuncoids of appropriate sources and destinations.\n\\end{conjecture}\n\n\\begin{rem}\nSee also example~\\ref{fcd-not-infdist} below.\n\\end{rem}\n\nThe next proposition is one more (among the theorem \\ref{fcd-atom-middle})\ngeneralization for funcoids of composition of relations.\n\\begin{prop}\\label{fcd-at-comp}\nFor every composable funcoids $f$, $g$\n\\begin{multline*}\n\\atoms(g\\circ f)=\\\\\n\\setcond{x\\times^{\\mathsf{FCD}}z}{\\begin{array}{l}\nx\\in\\atoms^{\\mathscr{F}(\\Src f)},z\\in\\atoms^{\\mathscr{F}(\\Dst g)},\\\\\n\\exists y\\in\\atoms^{\\mathscr{F}(\\Dst f)}:(x\\times^{\\mathsf{FCD}}y\\in\\atoms\nf\\land y\\times^{\\mathsf{FCD}}z\\in\\atoms g)\n\\end{array}}.\n\\end{multline*}\n\\end{prop}\n\\begin{proof}\nUsing the theorem \\ref{fcd-atom-middle},\n\\[\nx\\times^{\\mathsf{FCD}}z\\nasymp g\\circ f\\Leftrightarrow x\\suprel{g\\circ\nf}z\\Leftrightarrow\\exists y\\in\\atoms^{\\mathscr{F}(\\Dst\nf)}:(x\\times^{\\mathsf{FCD}}y\\nasymp f\\land y\\times^{\\mathsf{FCD}}z\\nasymp g).\n\\]\n\\end{proof}\n\\begin{cor}\n$g\\circ f=\\bigsqcup\\setcond{G\\circ F}{F\\in\\atoms f,G\\in\\atoms g}$\nfor every composable funcoids $f$, $g$.\\end{cor}\n\\begin{thm}\nLet $f$ be a funcoid.\n\\begin{enumerate}\n\\item \\label{ffilt-r}$\\mathcal{X}\\suprel f\\mathcal{Y}\\Leftrightarrow\\exists\nF\\in\\atoms f:\\mathcal{X}\\suprel F\\mathcal{Y}$\nfor every $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$, $\\mathcal{Y}\\in\\mathscr{F}(\\Dst\nf)$;\n\\item \\label{ffilt-f}$\\supfun f\\mathcal{X}=\\bigsqcup_{F\\in\\atoms f}\\supfun\nF\\mathcal{X}$\nfor every $\\mathcal{X}\\in\\mathscr{F}(\\Src f)$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{ffilt-r}}] ~\n\\begin{align*}\n\\exists F\\in\\atoms f:\\mathcal{X}\\suprel F\\mathcal{Y} & \\Leftrightarrow\\\\\n\\exists a\\in\\atoms^{\\mathscr{F}(\\Src f)},b\\in\\atoms^{\\mathscr{F}(\\Dst\nf)}:(a\\times^{\\mathsf{FCD}}b\\nasymp\nf\\land\\mathcal{X}\\suprel{a\\times^{\\mathsf{FCD}}b}\\mathcal{Y}) &\n\\Leftrightarrow\\\\\n\\exists a\\in\\atoms^{\\mathscr{F}(\\Src f)},b\\in\\atoms^{\\mathscr{F}(\\Dst\nf)}:(a\\times^{\\mathsf{FCD}}b\\nasymp f\\land\na\\times^{\\mathsf{FCD}}b\\nasymp\\mathcal{X}\\times^{\\mathsf{FCD}}\\mathcal{Y}) &\n\\Leftrightarrow\\\\\n\\exists F\\in\\atoms f:(F\\nasymp f\\land\nF\\nasymp\\mathcal{X}\\times^{\\mathsf{FCD}}\\mathcal{Y}) & \\Leftrightarrow\\\\\nf\\nasymp\\mathcal{X}\\times^{\\mathsf{FCD}}\\mathcal{Y} & \\Leftrightarrow\\\\\n\\mathcal{X}\\suprel f\\mathcal{Y}.\n\\end{align*}\n\n\\item [{\\ref{ffilt-f}}] Let $\\mathcal{Y}\\in\\mathscr{F}(\\Dst f)$. Suppose\n$\\mathcal{Y}\\nasymp\\supfun f\\mathcal{X}$. Then $\\mathcal{X}\\suprel\nf\\mathcal{Y}$;\n$\\exists F\\in\\atoms f:\\mathcal{X}\\suprel F\\mathcal{Y}$; $\\exists F\\in\\atoms\nf:\\mathcal{Y}\\nasymp\\supfun F\\mathcal{X}$;\n$\\mathcal{Y}\\nasymp\\bigsqcup_{F\\in\\atoms f}\\supfun F\\mathcal{X}$.\nSo $\\supfun f\\mathcal{X}\\sqsubseteq\\bigsqcup_{F\\in\\atoms f}\\supfun\nF\\mathcal{X}$.\nThe contrary $\\supfun f\\mathcal{X}\\sqsupseteq\\bigsqcup_{F\\in\\atoms f}\\supfun\nF\\mathcal{X}$\nis obvious.\n\\end{widedisorder}\n\\end{proof}\n\n\\section{Complete funcoids}\n\\begin{defn}\n\\index{funcoid!co-complete}I will call \\emph{co-complete} such a\nfuncoid $f$ that $\\rsupfun fX$ is a principal filter for every\n$X\\in\\mathscr{T}(\\Src f)$.\\end{defn}\n\\begin{obvious}\nFuncoid $f$ is co-complete iff $\\supfun f\\mathcal{X}\\in\\mathfrak{P}(\\Dst f)$\nfor every $\\mathcal{X}\\in\\mathfrak{P}(\\Src f)$.\\end{obvious}\n\\begin{defn}\n\\index{generalized closure}I will call \\emph{generalized closure}\nsuch a function $\\alpha\\in(\\mathscr{T}B)^{\\mathscr{T}A}$ (for some\nsets $A$, $B$) that\n\\begin{enumerate}\n\\item $\\alpha\\bot=\\bot$;\n\\item $\\forall I,J\\in\\mathscr{T}A:\\alpha(I\\sqcup J)=\\alpha I\\sqcup\\alpha J$.\n\\end{enumerate}\n\\end{defn}\n\\begin{obvious}\nA funcoid $f$ is co-complete iff $\\rsupfun f=\\mathord{\\uparrow}\\circ\\alpha$\nfor a generalized closure $\\alpha$.\\end{obvious}\n\\begin{rem}\nThus funcoids can be considered as a generalization of generalized\nclosures. A topological space in Kuratowski sense is the same as reflexive\nand transitive generalized closure. So topological spaces can be considered\nas a special case of funcoids.\\end{rem}\n\\begin{defn}\n\\index{funcoid!complete}I will call a \\emph{complete funcoid} a funcoid\nwhose reverse is co-complete.\\end{defn}\n\\begin{thm}\nThe following conditions are equivalent for every funcoid $f$:\n\\begin{enumerate}\n\\item \\label{cfcd:main}funcoid $f$ is complete;\n\\item \\label{cfcd:r-filt}$\\forall S\\in\\subsets\\mathscr{F}(\\Src\nf),J\\in\\mathscr{T}(\\Dst f):\\left(\\bigsqcup S\\suprel\nfJ\\Leftrightarrow\\exists\\mathcal{I}\\in S:\\mathcal{I}\\suprel fJ\\right)$;\n\\item \\label{cfcd:r-set}$\\forall S\\in\\subsets\\mathscr{T}(\\Src f),J\\in\\mathscr{T}(\\Dst\nf):\\left(\\bigsqcup S\\rsuprel fJ\\Leftrightarrow\\exists I\\in S:I\\rsuprel\nfJ\\right)$;\n\\item \\label{cfcd:f-filt}$\\forall S\\in\\subsets\\mathscr{F}(\\Src f):\\supfun\nf\\bigsqcup S=\\bigsqcup\\rsupfun{\\supfun f}S$;\n\\item \\label{cfcd:f-set}$\\forall S\\in\\subsets\\mathscr{T}(\\Src f):\\rsupfun\nf\\bigsqcup S=\\bigsqcup\\rsupfun{\\rsupfun f}S$;\n\\item \\label{cfcd:sing}$\\forall A\\in\\mathscr{T}(\\Src f):\\rsupfun\nfA=\\bigsqcup_{a\\in\\atoms A}\\rsupfun fa$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{cfcd:r-set}$\\Rightarrow$\\ref{cfcd:main}}] For every\n$S\\in\\subsets\\mathscr{T}(\\Src f)$,\n$J\\in\\mathscr{T}(\\Dst f)$\n\\[\n\\bigsqcup S\\sqcap\\rsupfun{f^{-1}}J\\ne\\bot\\Leftrightarrow\\exists I\\in\nS:I\\sqcap\\rsupfun{f^{-1}}J\\ne\\bot,\n\\]\nconsequently by theorem~\\ref{crit1} we have that $\\rsupfun{f^{-1}}J$\nis a principal filter.\n\\item [{\\ref{cfcd:main}$\\Rightarrow$\\ref{cfcd:r-filt}}] For every\n$S\\in\\subsets\\mathscr{F}(\\Src f)$,\n$J\\in\\mathscr{T}(\\Dst f)$ we have that $\\rsupfun{f^{-1}}J$ is a\nprincipal filter, consequently\n\\[\n\\bigsqcup S\\sqcap\\rsupfun{f^{-1}}J\\ne\\bot \\Leftrightarrow\\exists\\mathcal{I}\\in\nS:\\mathcal{I}\\sqcap\\rsupfun{f^{-1}}J\\ne\\bot.\n\\]\nFrom this follows \\ref{cfcd:r-filt}.\n\\item [{\\ref{cfcd:sing}$\\Rightarrow$\\ref{cfcd:f-set}}] ~\n\\begin{align*}\n\\rsupfun f\\bigsqcup S & =\\\\\n\\bigsqcup_{a\\in\\atoms\\bigsqcup S}\\rsupfun fa & =\\\\\n\\bigsqcup\\bigcup_{A\\in S}\\setcond{\\rsupfun fa}{a\\in\\atoms A} & =\\\\\n\\bigsqcup_{A\\in S}\\bigsqcup_{a\\in\\atoms A}\\rsupfun fa & =\\\\\n\\bigsqcup_{A\\in S}\\rsupfun fA & =\\\\\n\\bigsqcup\\rsupfun{\\rsupfun f}S.\n\\end{align*}\n\n\\item [{\\ref{cfcd:r-filt}$\\Rightarrow$\\ref{cfcd:f-filt}}] Using\ntheorem~\\ref{crit1},\n\\begin{align*}\nJ\\nasymp\\supfun f\\bigsqcup S & \\Leftrightarrow\\\\\n\\bigsqcup S\\suprel fJ & \\Leftrightarrow\\\\\n\\exists\\mathcal{I}\\in S:\\mathcal{I}\\suprel fJ & \\Leftrightarrow\\\\\n\\exists\\mathcal{I}\\in S:J\\nasymp\\supfun f\\mathcal{I} & \\Leftrightarrow\\\\\nJ\\nasymp\\bigsqcup\\rsupfun{\\supfun f}S.\n\\end{align*}\n\n\\item\n[{\\ref{cfcd:r-filt}$\\Rightarrow$\\ref{cfcd:r-set},~\\ref{cfcd:f-filt}\n$\\Rightarrow$\\ref{cfcd:f-set},~\\ref{cfcd:f-set}$\\Rightarrow$\\ref{cfcd:r-set},\n~\\ref{cfcd:f-set}$\\Rightarrow$\\ref{cfcd:sing}}] Obvious.\n\\end{description}\n\\end{proof}\nThe following proposition shows that complete funcoids are a direct\ngeneralization of pretopological spaces.\n\\begin{prop}\nTo specify a complete funcoid $f$ it is enough to specify $\\rsupfun f$\non one-element sets, values of $\\rsupfun f$ on one element sets can\nbe specified arbitrarily.\\end{prop}\n\\begin{proof}\nFrom the above theorem is clear that knowing $\\rsupfun f$ on one-element\nsets $\\rsupfun f$ can be found on every set and then the value of\n$\\supfun f$ can be inferred for every filter.\n\nChoosing arbitrarily the values of $\\rsupfun f$ on one-element sets\nwe can define a complete funcoid the following way: $\\rsupfun\nfX=\\bigsqcup_{\\alpha\\in\\atoms X}\\rsupfun f\\alpha$\nfor every $X\\in\\mathscr{T}(\\Src f)$. Obviously it is really a complete\nfuncoid.\\end{proof}\n\\begin{thm}\nA funcoid is principal iff it is both complete and co-complete.\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}] Obvious.\n\\item [{$\\Leftarrow$}] Let $f$ be both a complete and co-complete funcoid.\nConsider the relation $g$ defined by that $\\uparrow\\rsupfun g\\alpha=\\rsupfun\nf\\alpha$\nfor one-element sets~$\\alpha$ ($g$ is correctly defined because\n$f$ corresponds to a generalized closure). Because $f$ is a complete\nfuncoid $f$ is the funcoid corresponding to $g$.\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{fcd-join-compl}If $R\\in\\subsets\\mathsf{FCD}(A,B)$ is a set\nof (co-)complete funcoids then $\\bigsqcup R$ is a (co-)complete funcoid\n(for every sets $A$ and $B$).\\end{thm}\n\\begin{proof}\nIt is enough to prove for co-complete funcoids. Let\n$R\\in\\subsets\\mathsf{FCD}(A,B)$\nbe a set of co-complete funcoids. Then for every $X\\in\\mathscr{T}(\\Src f)$\n\\[\n\\rsupfun{\\bigsqcup R}X=\\bigsqcup_{f\\in R}\\rsupfun fX\n\\]\nis a principal filter (used theorem \\ref{fcd-join-sets}).\\end{proof}\n\\begin{cor}\n\\label{fcd-compl-join}If $R$ is a set of binary relations between\nsets $A$ and $B$ then\n$\\bigsqcup\\rsupfun{\\uparrow^{\\mathsf{FCD}(A,B)}}R=\\uparrow^{\\mathsf{FCD}(A,B)}\n\\bigcup R$.\\end{cor}\n\\begin{proof}\nFrom two last theorems.\\end{proof}\n\\begin{lem}\n\\label{fcd-rep}Every funcoid is representable as meet (on the lattice\nof funcoids) of binary relations of the form\n$X\\times Y\\sqcup\\overline{X}\\times\\top^{\\mathscr{T}(B)}$ (where $X$, $Y$ are typed sets).\\end{lem}\n\\begin{proof}\nLet $f\\in\\mathsf{FCD}(A,B)$, $X\\in\\mathscr{T}A$, $Y\\in\\up\\supfun fX$,\n$g(X,Y)\\eqdef X\\times Y\\sqcup\\overline{X}\\times\\top^{\\mathscr{T}(B)}$.\nThen $g(X,Y)=X\\times^{\\mathsf{FCD}}Y\\sqcup\\overline{X}\\times^{\\mathsf{FCD}}\\top^{\\mathscr{F}(B)}$.\nFor every $K\\in\\mathscr{T}A$\n\\begin{multline*}\n\\rsupfun{g(X,Y)}K=\\rsupfun{X\\times^{\\mathsf{FCD}}Y}K\\sqcup\\rsupfun{\\overline{X}\n\\times^{\\mathsf{FCD}}\\top^{\\mathscr{F}(B)}}K=\\\\\n\\left(\\begin{cases}\n\\bot^{\\mathscr{F}(B)} & \\text{if }K=\\bot^{\\mathscr{T}A}\\\\\nY & \\text{if }\\bot^{\\mathscr{T}A}\\ne K\\sqsubseteq X\\\\\n\\top^{\\mathscr{F}(B)} & \\text{if }K\\nsqsubseteq X\n\\end{cases}\\right)\\sqsupseteq\\rsupfun fK;\n\\end{multline*}\nso $g(X,Y)\\sqsupseteq f$. For every $X\\in\\mathscr{T}A$\n\\[\n\\bigsqcap_{Y\\in\\up\\rsupfun fX}\\rsupfun{g(X,Y)}X=\\bigsqcap^{\\mathscr{F}}_{Y\\in\\up\\rsupfun\nfX}Y=\\rsupfun fX;\n\\]\nconsequently\n\\[\n\\rsupfun{\\bigsqcap\\setcond{g(X,Y)}{X\\in\\mathscr{T}A,Y\\in\\up\\rsupfun\nfX}}X\\sqsubseteq\\rsupfun fX\n\\]\nthat is\n\\[\n\\bigsqcap\\setcond{g(X,Y)}{X\\in\\mathscr{T}A,Y\\in\\up\\rsupfun fX}\\sqsubseteq f\n\\]\n and finally\n\\[\nf=\\bigsqcap\\setcond{g(X,Y)}{X\\in\\mathscr{T}A,Y\\in\\up\\rsupfun fX}.\n\\]\n\\end{proof}\n\\begin{cor}\n\\label{fcd-filtered}Filtrators of funcoids are filtered.\n\\end{cor}\n\n\\begin{thm}\\label{metcomp-thm}\n~\n\\begin{enumerate}\n\\item \\label{metcomp}$g$ is metacomplete if $g$ is a complete funcoid.\n\\item \\label{cometcomp}$g$ is co-metacomplete if $g$ is a co-complete\nfuncoid.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{metcomp}}] Let $R$ be a set of funcoids from a set $A$ to a set\n$B$ and $g$ be a funcoid from $B$ to some $C$. Then\n\\begin{align*}\n\\rsupfun{g\\circ\\bigsqcup R}X & =\\\\\n\\supfun g\\rsupfun{\\bigsqcup R}X & =\\\\\n\\supfun g\\bigsqcup_{f\\in R}\\rsupfun fX & =\\\\\n\\bigsqcup_{f\\in R}\\supfun g\\rsupfun fX & =\\\\\n\\bigsqcup_{f\\in R}\\rsupfun{g\\circ f}X & =\\\\\n\\rsupfun{\\bigsqcup_{f\\in R}(g\\circ f)}X & =\\\\\n\\rsupfun{\\bigsqcup\\rsupfun{g\\circ}R}X\n\\end{align*}\nfor every typed set $X\\in\\mathscr{T}A$. So $g\\circ\\bigsqcup\nR=\\bigsqcup\\rsupfun{g\\circ}R$.\n\\item [{\\ref{cometcomp}}] By duality.\n\\end{widedisorder}\n\\end{proof}\n\\begin{conjecture}\n$g$ is complete if $g$ is a metacomplete funcoid.\n\\end{conjecture}\nI will denote $\\mathsf{ComplFCD}$ and $\\mathsf{CoComplFCD}$ the\nsets of small complete and co-complete funcoids correspondingly.\n$\\mathsf{ComplFCD}(A,B)$\nare complete funcoids from $A$ to $B$ and likewise with\n$\\mathsf{CoComplFCD}(A,B)$.\n\\begin{obvious}\n$\\mathsf{ComplFCD}$ and $\\mathsf{CoComplFCD}$ are closed regarding\ncomposition of funcoids.\\end{obvious}\n\\begin{prop}\n$\\mathsf{ComplFCD}$ and $\\mathsf{CoComplFCD}$ (with induced order)\nare complete lattices.\\end{prop}\n\\begin{proof}\nIt follows from theorem \\ref{fcd-join-compl}.\\end{proof}\n\\begin{thm}\nAtoms of the lattice $\\mathsf{ComplFCD}(A,B)$ are exactly funcoidal\nproducts of the form $\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b$\nwhere $\\alpha\\in A$ and $b$ is an ultrafilter on $B$.\\end{thm}\n\\begin{proof}\nFirst, it's easy to see that $\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b$\nare elements of $\\mathsf{ComplFCD}(A,B)$. Also $\\bot^{\\mathsf{FCD}(A,B)}$\nis an element of $\\mathsf{ComplFCD}(A,B)$.\n\n$\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b$ are atoms of\n$\\mathsf{ComplFCD}(A,B)$\nbecause they are atoms of $\\mathsf{FCD}(A,B)$.\n\nIt remains to prove that if $f$ is an atom of $\\mathsf{ComplFCD}(A,B)$\nthen $f=\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b$ for some $\\alpha\\in A$\nand an ultrafilter $b$ on $B$.\n\nSuppose $f\\in\\mathsf{FCD}(A,B)$ is a non-empty complete funcoid.\nThen there exists $\\alpha\\in A$ such that $\\rsupfun\nf@\\{\\alpha\\}\\ne\\bot^{\\mathscr{F}(B)}$.\nThus $\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b\\sqsubseteq f$\nfor some ultrafilter $b$ on $B$. If $f$ is an atom then\n$f=\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b$.\\end{proof}\n\\begin{thm}\n\\label{complfcd-rep}$G\\mapsto\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))$\nis an order isomorphism from the set of functions $G\\in\\mathscr{F}(B)^{A}$\nto the set $\\mathsf{ComplFCD}(A,B)$.\n\nThe inverse isomorphism is described by the formula $G(\\alpha)=\\rsupfun\nf@\\{\\alpha\\}$\nwhere $f$ is a complete funcoid.\\end{thm}\n\\begin{proof}\n$\\bigsqcup_{\\alpha\\in A}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))$\nis complete because $G(\\alpha)=\\bigsqcup\\atoms G(\\alpha)$ and thus\n\\[\n\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))=\\bigsqcup\\setcond{\n\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b}{\\alpha\\in A,b\\in\\atoms G(\\alpha)}\n\\]\nis complete. So $G\\mapsto\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))$\nis a function from $G\\in\\mathscr{F}(B)^{A}$ to $\\mathsf{ComplFCD}(A,B)$.\n\nLet $f$ be complete. Then take\n\\[\nG(\\alpha)=\\bigsqcup\\setcond{b\\in\\atoms^{\\mathscr{F}(\\Dst\nf)}}{\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}b\\sqsubseteq f}\n\\]\nand we have $f=\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))$\nobviously. So $G\\mapsto\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))$\nis surjection onto $\\mathsf{ComplFCD}(A,B)$.\n\nLet now prove that it is an injection:\n\nLet\n\\[\nf=\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}F(\\alpha))=\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))\n\\]\nfor some $F,G\\in\\mathscr{F}(\\Dst f)^{\\Src f}$. We need to prove $F=G$.\nLet $\\beta\\in\\Src f$.\n\\[\n\\rsupfun f@\\{\\beta\\}=\\bigsqcup_{\\alpha\\in\nA}\\rsupfun{\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}F(\\alpha)}@\\{\n\\beta\\}=F(\\beta).\n\\]\nSimilarly $\\rsupfun f@\\{\\beta\\}=G(\\beta)$. So $F(\\beta)=G(\\beta)$.\n\nWe have proved that it is a bijection. To show that it is monotone\nis trivial.\n\nDenote $f=\\bigsqcup_{\\alpha\\in\nA}(\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha))$.\nThen\n\\begin{multline*}\n\\rsupfun f@\\{\\alpha'\\}=\\text{(because\n\\ensuremath{\\uparrow^{A}\\{\\alpha'\\}} is principal)}=\\\\\n\\bigsqcup_{\\alpha\\in\nA}\\supfun{\\uparrow^{A}\\{\\alpha\\}\\times^{\\mathsf{FCD}}G(\\alpha)}@\\{\n\\alpha'\\}=\\supfun{\\uparrow^{A}\\{\\alpha'\\}\\times^{\\mathsf{FCD}}G(\\alpha')}\n@\\{\\alpha'\\}=G(\\alpha').\n\\end{multline*}\n\\end{proof}\n\\begin{cor}\n$G\\mapsto\\bigsqcup_{\\alpha\\in\nA}(G(\\alpha)\\times^{\\mathsf{FCD}}\\uparrow^{A}\\{\\alpha\\})$\nis an order isomorphism from the set of functions $G\\in\\mathscr{F}(B)^{A}$\nto the set $\\mathsf{CoComplFCD}(A,B)$.\n\nThe inverse isomorphism is described by the formula\n$G(\\alpha)=\\rsupfun{f^{-1}}@\\{\\alpha\\}$\nwhere $f$ is a co-complete funcoid.\n\\end{cor}\n\n\\begin{cor}\n$\\mathsf{ComplFCD}(A,B)$ and $\\mathsf{CoComplFCD}(A,B)$ are co-frames.\n\\end{cor}\n\n\\section{Funcoids corresponding to pretopologies}\n\nLet $\\Delta$ be a pretopology on a set $U$ and $\\cl$ the preclosure\ncorresponding to it (see theorem \\ref{pretop-bij}).\n\nBoth induce a funcoid, I will show that these two funcoids are reverse\nof each other:\n\\begin{thm}\nLet $f$ be a complete funcoid defined by the formula $\\rsupfun\nf@\\{x\\}=\\Delta(x)$\nfor every $x\\in U$, let $g$ be a co-complete funcoid defined by\nthe formula $\\rsupfun gX=\\uparrow^{U}\\cl(\\GR X)$ for every $X\\in\\mathscr{T}U$.\nThen $g=f^{-1}$.\\end{thm}\n\\begin{rem}\nIt is obvious that funcoids $f$ and $g$ exist.\\end{rem}\n\\begin{proof}\nFor $X,Y\\in\\mathscr{T}U$ we have\n\\begin{align*}\nX\\rsuprel gY & \\Leftrightarrow\\\\\n\\uparrow Y\\nasymp\\supfun g\\uparrow X & \\Leftrightarrow\\\\\nY\\nasymp\\cl(\\GR X) & \\Leftrightarrow\\\\\n\\exists y\\in Y:\\Delta(y)\\nasymp\\uparrow X & \\Leftrightarrow\\\\\n\\exists y\\in Y:\\rsupfun f\\uparrow^{U}\\{y\\}\\nasymp\\uparrow X & \\Leftrightarrow\\\\\n\\text{(proposition \\ref{b-f-back-distr} and properties of complete funcoids)}\\\\\n\\rsupfun fY\\nasymp\\uparrow X & \\Leftrightarrow\\\\\nY\\rsuprel fX.\n\\end{align*}\n\n\nSo $g=f^{-1}$.\n\\end{proof}\n\n\\section{Completion of funcoids}\n\\begin{thm}\n$\\Cor f=\\Cor'f$ for an element $f$ of a filtrator of funcoids.\\end{thm}\n\\begin{proof}\nBy theorem~\\ref{cor-eq} and corollary~\\ref{fcd-filtered}.\\end{proof}\n\\begin{defn}\n\\index{completion!of funcoid}\\emph{Completion} of a funcoid\n$f\\in\\mathsf{FCD}(A,B)$\nis the complete funcoid $\\Compl f\\in\\mathsf{FCD}(A,B)$ defined by\nthe formula $\\rsupfun{\\Compl f}@\\{\\alpha\\}=\\rsupfun\nf@\\{\\alpha\\}$\nfor $\\alpha\\in\\Src f$.\n\\end{defn}\n\n\\begin{defn}\n\\index{co-completion!of funcoid}\\emph{Co-completion} of a funcoid\n$f$ is defined by the formula\n\\[\n\\CoCompl f=(\\Compl f^{-1})^{-1}.\n\\]\n\\end{defn}\n\\begin{obvious}\n$\\Compl f\\sqsubseteq f$ and $\\CoCompl f\\sqsubseteq f$.\\end{obvious}\n\\begin{prop}\nThe filtrator $(\\mathsf{FCD}(A,B),\\mathsf{ComplFCD}(A,B))$ is\nfiltered.\\end{prop}\n\\begin{proof}\nBecause the filtrator of funcoids is filtered.\\end{proof}\n\\begin{thm}\n$\\Compl f=\\Cor^{\\mathsf{ComplFCD}(A,B)}f=\\Cor'^{\\mathsf{ComplFCD}(A,B)}f$\nfor every funcoid $f\\in\\mathsf{FCD}(A,B)$.\\end{thm}\n\\begin{proof}\n$\\Cor^{\\mathsf{ComplFCD}(A,B)}f=\\Cor'^{\\mathsf{ComplFCD}(A,B)}f$\nusing theorem \\ref{cor-eq} since the filtrator\n$(\\mathsf{FCD}(A,B),\\mathsf{ComplFCD}(A,B))$\nis filtered.\n\nLet $g\\in\\up^{\\mathsf{ComplFCD}(A,B)}f$. Then\n$g\\in\\mathsf{ComplFCD}(A,B)$ and $g\\sqsupseteq f$. Thus $g=\\Compl\ng\\sqsupseteq\\Compl f$.\n\nThus $\\forall g\\in\\up^{\\mathsf{ComplFCD}(A,B)}f:g\\sqsupseteq\\Compl f$.\n\nLet $\\forall g\\in\\up^{\\mathsf{ComplFCD}(A,B)}f:h\\sqsubseteq g$\nfor some $h\\in\\mathsf{ComplFCD}(A,B)$.\n\nThen $h\\sqsubseteq\\bigsqcap\\up^{\\mathsf{ComplFCD}(A,B)}f=f$\nand consequently $h=\\Compl h\\sqsubseteq\\Compl f$.\n\nThus\n\\[\n\\Compl\nf=\\bigsqcap^{\\mathsf{ComplFCD}(A,B)}\\up^{\\mathsf{ComplFCD}(A,B)}f=\\Cor^{\\mathsf{\nComplFCD}(A,B)}f.\n\\]\n\\end{proof}\n\\begin{thm}\n$\\rsupfun{\\CoCompl f}X=\\Cor\\rsupfun fX$ for every funcoid $f$ and\ntyped set $X\\in\\mathscr{T}(\\Src f)$.\\end{thm}\n\\begin{proof}\n$\\CoCompl f\\sqsubseteq f$ thus $\\rsupfun{\\CoCompl f}X\\sqsubseteq\\rsupfun fX$\nbut $\\rsupfun{\\CoCompl f}X$ is a principal filter thus $\\rsupfun{\\CoCompl\nf}X\\sqsubseteq\\Cor\\rsupfun fX$.\n\nLet $\\alpha X=\\Cor\\rsupfun fX$. Then $\\alpha\\bot^{\\mathscr{T}(\\Src\nf)}=\\bot^{\\mathscr{F}(\\Dst f)}$\nand\n\\begin{multline*}\n\\alpha(X\\sqcup Y)=\\Cor\\rsupfun f(X\\sqcup Y)=\\Cor(\\rsupfun fX\\sqcup\\rsupfun\nfY)=\\\\\n\\Cor\\rsupfun fX\\sqcup\\Cor\\rsupfun fY=\\alpha X\\sqcup\\alpha Y\n\\end{multline*}\n(used theorem~\\ref{dual-core-join}). Thus $\\alpha$ can be continued\ntill $\\supfun g$ for some funcoid $g$. This funcoid is co-complete.\n\nEvidently $g$ is the greatest co-complete element of $\\mathsf{FCD}(\\Src f,\\Dst\nf)$\nwhich is lower than $f$.\n\nThus $g=\\CoCompl f$ and $\\Cor\\rsupfun fX=\\alpha X=\\rsupfun gX=\\rsupfun{\\CoCompl\nf}X$.\\end{proof}\n\\begin{thm}\n$\\mathsf{ComplFCD}(A,B)$ is an atomistic lattice.\\end{thm}\n\\begin{proof}\nLet $f\\in\\mathsf{ComplFCD}(A,B)$, $X\\in\\mathscr{T}(\\Src f)$.\n\\[\n\\rsupfun fX=\\bigsqcup_{x\\in\\atoms X}\\rsupfun fx=\\bigsqcup_{x\\in\\atoms\nX}\\rsupfun{f|_{x}}x=\\bigsqcup_{x\\in\\atoms X}\\rsupfun{f|_{x}}X,\n\\]\nthus $f=\\bigsqcup_{x\\in\\atoms X}(f|_{x})$. It is trivial that every\n$f|_{x}$ is a join of atoms of $\\mathsf{ComplFCD}(A,B)$.\\end{proof}\n\\begin{thm}\nA funcoid is complete iff it is a join (on the lattice $\\mathsf{FCD}(A,B)$)\nof atomic complete funcoids.\\end{thm}\n\\begin{proof}\nIt follows from the theorem \\ref{fcd-join-compl} and the previous\ntheorem.\\end{proof}\n\\begin{cor}\n$\\mathsf{ComplFCD}(A,B)$ is join-closed.\\end{cor}\n\\begin{thm}\n$\\Compl\\bigsqcup R=\\bigsqcup\\rsupfun{\\Compl}R$ for every\n$R\\in\\subsets\\mathsf{FCD}(A,B)$\n(for every sets $A$, $B$).\\end{thm}\n\\begin{proof}\nFor every typed set $X$\n\\begin{align*}\n\\rsupfun{\\Compl\\bigsqcup R}X & =\\\\\n\\bigsqcup_{x\\in\\atoms X}\\rsupfun{\\bigsqcup R}x & =\\\\\n\\bigsqcup_{x\\in\\atoms X}\\bigsqcup_{f\\in R}\\rsupfun fx & =\\\\\n\\bigsqcup_{f\\in R}\\bigsqcup_{x\\in\\atoms X}\\rsupfun fx & =\\\\\n\\bigsqcup_{f\\in R}\\rsupfun{\\Compl f}X & =\\\\\n\\rsupfun{\\bigsqcup\\rsupfun{\\Compl}R}X.\n\\end{align*}\n\\end{proof}\n\\begin{cor}\n$\\Compl$ is a lower adjoint.\\end{cor}\n\\begin{conjecture}\n$\\Compl$ is not an upper adjoint (in general).\\end{conjecture}\n\\begin{prop}\n$\\Compl f=\\bigsqcup_{\\alpha\\in\\Src f}(f|_{\\uparrow\\{\\alpha\\}})$\nfor every funcoid $f$.\\end{prop}\n\\begin{proof}\nLet denote $R$ the right part of the equality to prove.\n\n$\\rsupfun R@\\{\\beta\\}=\\bigsqcup_{\\alpha\\in\\Src\nf}\\rsupfun{f|_{\\uparrow\\{\\alpha\\}}}@\\{\\beta\\}=\\rsupfun\nf@\\{\\beta\\}$\nfor every $\\beta\\in\\Src f$ and $R$ is complete as a join of complete\nfuncoids.\n\nThus $R$ is the completion of $f$.\\end{proof}\n\\begin{conjecture}\n$\\Compl f=f\\psetminus(\\Omega\\times^{\\mathsf{FCD}}\\mho)$.\n\\end{conjecture}\nThis conjecture may be proved by considerations similar to these in\nthe section ``Fr\\'echet filter''.\n\\begin{lem}\nCo-completion of a complete funcoid is complete.\\end{lem}\n\\begin{proof}\nLet $f$ be a complete funcoid.\n\\begin{multline*}\n\\rsupfun{\\CoCompl f}X=\\Cor\\rsupfun fX=\\Cor\\bigsqcup_{x\\in\\atoms X}\\rsupfun fx=\\\\\n\\bigsqcup_{x\\in\\atoms X}\\Cor\\rsupfun fx=\\bigsqcup_{x\\in\\atoms\nX}\\rsupfun{\\CoCompl f}x\n\\end{multline*}\nfor every set typed $X\\in\\mathscr{T}(\\Src f)$. Thus $\\CoCompl f$\nis complete.\\end{proof}\n\\begin{thm}\n$\\Compl\\CoCompl f=\\CoCompl\\Compl f=\\Cor f$ for every funcoid $f$.\\end{thm}\n\\begin{proof}\n$\\Compl\\CoCompl f$ is co-complete since (used the lemma) $\\CoCompl f$\nis co-complete. Thus $\\Compl\\CoCompl f$ is a principal funcoid. $\\CoCompl f$\nis the greatest co-complete funcoid under $f$ and $\\Compl\\CoCompl f$\nis the greatest complete funcoid under $\\CoCompl f$. So $\\Compl\\CoCompl f$\nis greater than any principal funcoid under $\\CoCompl f$ which is\ngreater than any principal funcoid under $f$. Thus $\\Compl\\CoCompl f$\nis the greatest principal funcoid under $f$. Thus $\\Compl\\CoCompl f=\\Cor f$.\nSimilarly $\\CoCompl\\Compl f=\\Cor f$.\n\\end{proof}\n\n\\subsection{More on completion of funcoids}\n\\begin{prop}\nFor every composable funcoids $f$ and $g$\n\\begin{enumerate}\n\\item \\label{compl-ge}$\\Compl(g\\circ f)\\sqsupseteq\\Compl g\\circ\\Compl f$;\n\\item \\label{cocompl-ge}$\\CoCompl(g\\circ f)\\sqsupseteq\\CoCompl g\\circ\\CoCompl\nf$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{disorder}\n\\item [{\\ref{compl-ge}}] $\\Compl g\\circ\\Compl f=\\Compl(\\Compl g\\circ\\Compl\nf)\\sqsubseteq\\Compl(g\\circ f)$.\n\\item [{\\ref{cocompl-ge}}] $\\CoCompl g\\circ\\CoCompl f=\\CoCompl(\\CoCompl\ng\\circ\\CoCompl f)\\sqsubseteq\\CoCompl(g\\circ f)$.\n\\end{disorder}\n\\end{proof}\n\\begin{prop}\\label{comp-compl}\nFor every composable funcoids $f$ and $g$\n\\begin{enumerate}\n\\item \\label{cocompl-eq}$\\CoCompl(g\\circ f)=(\\CoCompl g)\\circ f$ if $f$\nis a co-complete funcoid.\n\\item \\label{compl-eq}$\\Compl(f\\circ g)=f\\circ\\Compl g$ if $f$ is a complete\nfuncoid.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{cocompl-eq}}] For every $X\\in\\mathscr{T}(\\Src f)$\n\\begin{align*}\n\\rsupfun{\\CoCompl(g\\circ f)}X & =\\\\\n\\Cor\\rsupfun{g\\circ f}X & =\\\\\n\\Cor\\supfun g\\rsupfun fX & =\\\\\n\\supfun{\\CoCompl g}\\rsupfun fX & =\\\\\n\\rsupfun{(\\CoCompl g)\\circ f}X.\n\\end{align*}\n\n\\item [{\\ref{compl-eq}}] $(\\CoCompl(g\\circ f))^{-1}=f^{-1}\\circ(\\CoCompl\ng)^{-1}$;\n$\\Compl(g\\circ f)^{-1}=f^{-1}\\circ\\Compl g^{-1}$; $\\Compl(f^{-1}\\circ\ng^{-1})=f^{-1}\\circ\\Compl g^{-1}$.\nAfter variable replacement we get $\\Compl(f\\circ g)=f\\circ\\Compl g$\n(after the replacement $f$ is a complete funcoid).\n\\end{widedisorder}\n\\end{proof}\n\\begin{cor}\n~\nFor every composable funcoids $f$ and $g$\n\\begin{enumerate}\n\\item $\\Compl f\\circ\\Compl g=\\Compl(\\Compl f\\circ g)$.\n\\item $\\CoCompl g\\circ\\CoCompl f=\\CoCompl(g\\circ\\CoCompl f)$.\n\\end{enumerate}\n\\end{cor}\n\\begin{prop}\nFor every composable funcoids $f$ and $g$\n\\begin{enumerate}\n\\item \\label{compl2-eq}$\\Compl(g\\circ f)=\\Compl(g\\circ(\\Compl f))$;\n\\item \\label{cocompl2-eq}$\\CoCompl(g\\circ f)=\\CoCompl((\\CoCompl g)\\circ f)$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{compl2-eq}}] ~\n\\begin{multline*}\n\\rsupfun{g\\circ(\\Compl f)}@\\{x\\}=\\supfun g\\rsupfun{\\Compl\nf}@\\{x\\}=\\\\\n\\supfun g\\rsupfun f@\\{x\\}=\\rsupfun{g\\circ f}@\\{x\\}.\n\\end{multline*}\n\n\n\nThus $\\Compl(g\\circ(\\Compl f))=\\Compl(g\\circ f)$.\n\n\\item [{\\ref{cocompl2-eq}}] $(\\Compl(g\\circ(\\Compl f))^{-1}=(\\Compl(g\\circ\nf))^{-1}$;\n$\\CoCompl(g\\circ(\\Compl f))^{-1}=\\CoCompl(g\\circ f)^{-1}$; $\\CoCompl((\\Compl\nf)^{-1}\\circ g^{-1})=\\CoCompl(f^{-1}\\circ g^{-1})$;\n$\\CoCompl((\\CoCompl f^{-1})\\circ g^{-1})=\\CoCompl(f^{-1}\\circ g^{-1})$.\nAfter variable replacement $\\CoCompl((\\CoCompl g)\\circ f)=\\CoCompl(g\\circ f)$.\n\\end{widedisorder}\n\\end{proof}\n\\begin{thm}\nThe filtrator of funcoids (from a given set~$A$ to a given set~$B$)\nis with co-separable core.\\end{thm}\n\\begin{proof}\nLet $f,g\\in\\mathsf{FCD}(A,B)$ and $f\\sqcup g=\\top$. Then for every\n$X\\in\\mathscr{T}A$ we have\n\\begin{multline*}\n\\supfun f^{\\ast}X\\sqcup\\supfun g^{\\ast}X=\\top\\Leftrightarrow\\Cor\\supfun\nf^{\\ast}X\\sqcup\\Cor\\supfun g^{\\ast}X=\\top\\Leftrightarrow\\\\\n\\rsupfun{\\CoCompl f}X\\sqcup\\rsupfun{\\CoCompl g}X=\\top.\n\\end{multline*}\nThus $\\rsupfun{\\CoCompl f\\sqcup\\CoCompl g}X=\\top$;\n\\begin{equation}\nf\\sqcup g=\\top\\Rightarrow\\CoCompl f\\sqcup\\CoCompl g=\\top.\\label{fcd-sep-d}\n\\end{equation}\nApplying the dual of the formulas (\\ref{fcd-sep-d}) to the formula\n(\\ref{fcd-sep-d}) we get:\n\\[\nf\\sqcup g=\\top\\Rightarrow\\Compl\\CoCompl f\\sqcup\\Compl\\CoCompl g=\\top\n\\]\nthat is $f\\sqcup g=\\top\\Rightarrow\\Cor f\\sqcup\\Cor g=\\top$. So\n$\\mathsf{FCD}(A,B)$\nis with co-separable core.\\end{proof}\n\\begin{cor}\nThe filtrator of complete funcoids is also with co-separable core.\n\\end{cor}\n\n\\section{Monovalued and injective funcoids}\n\n\\index{funcoid!monovalued}\\index{monovalued!funcoid}Following the\nidea of definition of monovalued morphism let's call \\emph{monovalued}\nsuch a funcoid $f$ that $f\\circ f^{-1}\\sqsubseteq\\id_{\\im f}^{\\mathsf{FCD}}$.\n\n\\index{funcoid!injective}\\index{injective!funcoid}Similarly, I will\ncall a funcoid injective when $f^{-1}\\circ f\\sqsubseteq\\id_{\\dom\nf}^{\\mathsf{FCD}}$.\n\\begin{obvious}\nA funcoid $f$ is:\n\\begin{enumerate}\n\\item monovalued iff $f\\circ f^{-1}\\sqsubseteq1_{\\Dst f}^{\\mathsf{FCD}}$;\n\\item injective iff $f^{-1}\\circ f\\sqsubseteq1_{\\Src f}^{\\mathsf{FCD}}$.\n\\end{enumerate}\n\\end{obvious}\nIn other words, a funcoid is monovalued (injective) when it is a monovalued\n(injective) morphism of the category of funcoids. Monovaluedness is\ndual of injectivity.\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item A morphism $(\\mathcal{A},\\mathcal{B},f)$ of the category of funcoid\ntriples is monovalued iff the funcoid $f$ is monovalued.\n\\item A morphism $(\\mathcal{A},\\mathcal{B},f)$ of the category of funcoid\ntriples is injective iff the funcoid $f$ is injective.\n\\end{enumerate}\n\\end{obvious}\n\\begin{thm}\nThe following statements are equivalent for a funcoid $f$:\n\\begin{enumerate}\n\\item \\label{fcd-mv}$f$ is monovalued.\n\\item \\label{fcd-mmv}It is metamonovalued.\n\\item \\label{fcd-wmmv}It is weakly metamonovalued.\n\\item \\label{mnv-atom}$\\forall a\\in\\atoms^{\\mathscr{F}(\\Src f)}:\\supfun\nfa\\in\\atoms^{\\mathscr{F}(\\Dst f)}\\cup\\{\\bot^{\\mathscr{F}(\\Dst f)}\\}$.\n\\item \\label{mnv-flt}$\\forall\\mathcal{I},\\mathcal{J}\\in\\mathscr{F}(\\Dst\nf):\\supfun{f^{-1}}(\\mathcal{I}\\sqcap\\mathcal{J})=\\supfun{f^{-1}}\\mathcal{I}\n\\sqcap\\supfun{f^{-1}}\\mathcal{J}$.\n\\item \\label{mnv-set}$\\forall I,J\\in\\mathscr{T}(\\Dst f):\\rsupfun{f^{-1}}(I\\sqcap\nJ)=\\rsupfun{f^{-1}}I\\sqcap\\rsupfun{f^{-1}}J$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{\\ref{mnv-atom}$\\Rightarrow$\\ref{mnv-flt}}] Let\n$a\\in\\atoms^{\\mathscr{F}(\\Src f)}$,\n$\\supfun fa=b$. Then because $b\\in\\atoms^{\\mathscr{F}(\\Dst\nf)}\\cup\\{\\bot^{\\mathscr{F}(\\Dst f)}\\}$\n\\begin{gather*}\n(\\mathcal{I}\\sqcap\\mathcal{J})\\sqcap b\\ne\\bot \\Leftrightarrow\n\\mathcal{I}\\sqcap b\\ne\\bot\\land\\mathcal{J}\\sqcap b\\ne\\bot;\\\\\na\\suprel f\\mathcal{I}\\sqcap\\mathcal{J}\\Leftrightarrow a\\suprel f\\mathcal{I}\\land\na\\suprel f\\mathcal{J};\\\\\n\\mathcal{I}\\sqcap\\mathcal{J}\\suprel{f^{-1}}a\\Leftrightarrow\\mathcal{I}\\suprel{f^\n{-1}}a\\land\\mathcal{J}\\suprel{f^{-1}}a;\\\\\na\\sqcap\\supfun{f^{-1}}(\\mathcal{I}\\sqcap\\mathcal{J})\\ne\\bot\n\\Leftrightarrow a\\sqcap\\supfun{f^{-1}}\\mathcal{I}\\ne\\bot\n\\land a\\sqcap\\supfun{f^{-1}}\\mathcal{J}\\ne\\bot;\\\\\n\\supfun{f^{-1}}(\\mathcal{I}\\sqcap\\mathcal{J})=\\supfun{f^{-1}}\\mathcal{I}\n\\sqcap\\supfun{f^{-1}}\\mathcal{J}.\n\\end{gather*}\n\n\\item [{\\ref{mnv-flt}$\\Rightarrow$\\ref{fcd-mv}}]\n$\\supfun{f^{-1}}a\\sqcap\\supfun{f^{-1}}b=\\supfun{f^{-1}}(a\\sqcap\nb)=\\supfun{f^{-1}}\\bot=\\bot$\nfor every two distinct atomic filter objects $a$ and $b$ on $\\Dst f$.\nThis is equivalent to $\\lnot(\\supfun{f^{-1}}a\\suprel fb)$; $b\\asymp\\supfun\nf\\supfun{f^{-1}}a$;\n$b\\asymp\\supfun{f\\circ f^{-1}}a$; $\\lnot(a\\suprel{f\\circ f^{-1}}b)$.\nSo $a\\suprel{f\\circ f^{-1}}b\\Rightarrow a=b$ for every ultrafilters\n$a$ and $b$. This is possible only when $f\\circ f^{-1}\\sqsubseteq1_{\\Dst\nf}^{\\mathsf{FCD}}$.\n\\item [{\\ref{mnv-set}$\\Rightarrow$\\ref{mnv-flt}}] ~\n\\begin{align*}\n\\supfun{f^{-1}}(\\mathcal{I}\\sqcap\\mathcal{J}) & =\\\\\n\\bigsqcap\\rsupfun{\\rsupfun{f^{-1}}}\\up(\\mathcal{I}\\sqcap\\mathcal{J}) & =\\\\\n\\bigsqcap\\rsupfun{\\rsupfun{f^{-1}}}\\setcond{I\\sqcap\nJ}{I\\in\\up\\mathcal{I},J\\in\\up\\mathcal{J}} & =\\\\\n\\bigsqcap\\setcond{\\rsupfun{f^{-1}}(I\\sqcap J)}{I\\in\\up\\mathcal{I},J\\in\\up\\mathcal{J}}\n& =\\\\\n\\bigsqcap\\setcond{\\rsupfun{f^{-1}}I\\sqcap\\rsupfun\nfJ}{I\\in\\up\\mathcal{I},J\\in\\up\\mathcal{J}} & =\\\\\n\\bigsqcap\\setcond{\\rsupfun\nfI}{I\\in\\up\\mathcal{I}}\\sqcap\\bigsqcap\\setcond{\\rsupfun{f^{-1}}J}{J\\in\\up\\mathcal{J}}\n& =\\\\\n\\supfun{f^{-1}}\\mathcal{I}\\sqcap\\supfun{f^{-1}}\\mathcal{J}.\n\\end{align*}\n\n\\item [{\\ref{mnv-flt}$\\Rightarrow$\\ref{mnv-set}}] Obvious.\n\\item [{$\\lnot$\\ref{mnv-atom}$\\Rightarrow$$\\lnot$\\ref{fcd-mv}}] Suppose\n$\\supfun fa\\notin\\atoms^{\\mathscr{F}(\\Dst f)}\\cup\\{\\bot^{\\mathscr{F}(\\Dst f)}\\}$\nfor some $a\\in\\atoms^{\\mathscr{F}(\\Src f)}$. Then there exist two\natomic filters $p$ and $q$ on $\\Dst f$ such that $p\\ne q$ and\n$\\supfun fa\\sqsupseteq p\\land\\supfun fa\\sqsupseteq q$. Consequently\n$p\\nasymp\\supfun fa$; $a\\nasymp\\supfun{f^{-1}}p$;\n$a\\sqsubseteq\\supfun{f^{-1}}p$;\n$\\supfun{f\\circ f^{-1}}p=\\supfun f\\supfun{f^{-1}}p\\sqsupseteq\\supfun\nfa\\sqsupseteq q$;\n$\\supfun{f\\circ f^{-1}}p\\nsqsubseteq p$ and $\\supfun{f\\circ\nf^{-1}}p\\ne\\bot^{\\mathscr{F}(\\Dst f)}$.\nSo it cannot be $f\\circ f^{-1}\\sqsubseteq1_{\\Dst f}^{\\mathsf{FCD}}$.\n\\item [{\\ref{fcd-mmv}$\\Rightarrow$\\ref{fcd-wmmv}}] Obvious.\n\\item [{\\ref{fcd-mv}$\\Rightarrow$\\ref{fcd-mmv}}] ~\n\\begin{multline*}\n\\supfun{\\left(\\bigsqcap G\\right)\\circ f}x=\\supfun{\\bigsqcap\nG}\\supfun fx=\\bigsqcap_{g\\in G}\\supfun g\\supfun fx=\\\\\\bigsqcap_{g\\in\nG}\\supfun{g\\circ f}x=\\supfun{\\bigsqcap_{g\\in G}(g\\circ f)}x\n\\end{multline*}\nfor every atomic filter object $x\\in\\atoms^{\\mathscr{F}(\\Src f)}$.\nThus $\\left(\\bigsqcap G\\right)\\circ f=\\bigsqcap_{g\\in G}(g\\circ f)$.\n\\item [{\\ref{fcd-wmmv}$\\Rightarrow$\\ref{fcd-mv}}] Take\n$g=a\\times^{\\mathsf{FCD}}y$\nand $h=b\\times^{\\mathsf{FCD}}y$ for arbitrary atomic filter objects\n$a\\ne b$ and~$y$. We have $g\\sqcap h=\\bot$; thus $(g\\circ f)\\sqcap(h\\circ\nf)=(g\\sqcap h)\\circ f=\\bot$\nand thus impossible $x\\suprel fa\\land x\\suprel fb$ as otherwise $x\\suprel{g\\circ\nf}y$\nand $x\\suprel{h\\circ f}y$ so $x\\suprel{(g\\circ f)\\sqcap(h\\circ f)}y$.\nThus $f$ is monovalued.\n\\end{description}\n\\end{proof}\n\\begin{cor}\nA binary relation corresponds to a monovalued funcoid iff it is a\nfunction.\\end{cor}\n\\begin{proof}\nBecause $\\forall I,J\\in\\subsets(\\im f):\\rsupfun{f^{-1}}(I\\sqcap\nJ)=\\rsupfun{f^{-1}}I\\sqcap\\rsupfun{f^{-1}}J$\nis true for a funcoid $f$ corresponding to a binary relation if and\nonly if it is a function (see proposition~\\ref{rel-mono}).\\end{proof}\n\\begin{rem}\nThis corollary can be reformulated as follows: For binary relations\n(principal funcoids) the classic concept of monovaluedness and monovaluedness\nin the above defined sense of monovaluedness of a funcoid are the\nsame.\\end{rem}\n\\begin{thm}\nIf $f$, $g$ are funcoids, $f\\sqsubseteq g$ and $g$ is monovalued\nthen $g|_{\\dom f}=f$.\\end{thm}\n\\begin{proof}\nObviously $g|_{\\dom f}\\sqsupseteq f$. Suppose for contrary that $g|_{\\dom\nf}\\sqsubset f$.\nThen there exists an atom $a\\in\\atoms\\dom f$ such that $\\langle g|_{\\dom\nf}\\rangle a\\neq\\langle f\\rangle a$\nthat is $\\supfun ga\\sqsubset\\supfun fa$ what is impossible.\n\\end{proof}\n\n\\section{\\texorpdfstring{$T_{0}$-, $T_{1}$-, $T_{2}$-, $T_{3}$-, and $T_{4}$-separable\nfuncoids}%\n{T0-, T1-, T2-, and T3-separable funcoids}}\n\n\\index{funcoids!separable}For funcoids it can be generalized $T_{0}$-,\n$T_{1}$-, $T_{2}$-, and $T_{3}$- separability. Worthwhile note\nthat $T_{0}$ and $T_{2}$ separability is defined through $T_{1}$\nseparability.\n\\begin{defn}\nLet call \\emph{$T_{1}$-separable} such endofuncoid $f$ that for\nevery $\\alpha,\\beta\\in\\Ob f$ is true\n\\[\n\\alpha\\ne\\beta\\Rightarrow\\lnot(@\\{\\alpha\\}\\rsuprel f@\\{\\beta\\}).\n\\]\n\\end{defn}\n\\begin{prop}\nAn endofuncoid $f$ is $T_{1}$-separable iff $\\Cor f\\sqsubseteq1_{\\Ob\nf}^{\\mathsf{FCD}}$.\\end{prop}\n\\begin{proof}\n~\n\\begin{multline*}\n\\forall x,y\\in\\Ob f:(@\\{x\\}\\rsuprel{f}@\\{y\\}\\Rightarrow x=y)\\Leftrightarrow\\\\\n\\forall x,y\\in\\Ob f:(@\\{x\\}\\rsuprel{\\Cor f}@\\{y\\}\\Rightarrow x=y)\\Leftrightarrow\\Cor f\\sqsubseteq1_{\\Ob f}^{\\mathsf{FCD}}.\n\\end{multline*}\n\\end{proof}\n\n\\begin{prop}\nAn endofuncoid~$f$ is $T_{1}$-separable iff $\\Cor\\rsupfun{f}\\{x\\}\\sqsubseteq\\{x\\}$ for every $x\\in\\Ob f$.\n\\end{prop}\n\n\\begin{proof}\n\\begin{multline*}\n\\Cor \\rsupfun{f} \\{ x \\} \\sqsubseteq \\{ x \\}\n\\Leftrightarrow \\rsupfun{\\CoCompl f} \\{ x \\} \\sqsubseteq \\{\nx \\} \\Leftrightarrow \\\\ \\Compl \\CoCompl f \\sqsubseteq\n1^{\\mathsf{FCD}}_{\\Ob f} \\Leftrightarrow \\Cor f \\sqsubseteq\n1^{\\mathsf{FCD}}_{\\Ob f}.\n\\end{multline*}\n\\end{proof}\n\n\\begin{defn}\nLet call \\emph{$T_{0}$-separable} such funcoid $f\\in\\mathsf{FCD}(A,A)$\nthat $f\\sqcap f^{-1}$ is $T_{1}$-separable.\n\\end{defn}\n\n\\begin{defn}\nLet call \\emph{$T_{2}$-separable} such funcoid $f$ that $f^{-1}\\circ f$\nis $T_{1}$-separable.\n\\end{defn}\nFor symmetric transitive funcoids $T_{0}$-, $T_{1}$- and $T_{2}$-separability\nare the same (see theorem \\ref{sym-trans}).\n\\begin{obvious}\nA funcoid $f$ is $T_{2}$-separable iff $\\alpha\\ne\\beta\\Rightarrow\\rsupfun\nf@\\{\\alpha\\}\\nasymp\\rsupfun f@\\{\\beta\\}$\nfor every $\\alpha,\\beta\\in\\Src f$.\\end{obvious}\n\\begin{defn}\nFuncoid $f$ is \\emph{regular} iff for every $C\\in\\mathscr{T}\\Dst f$ and\n$p\\in\\Src f$\n\\[\\supfun{f} \\langle f^{- 1} \\rangle C \\asymp \\supfun{f}\n@\\{ p \\} \\Leftarrow \\uparrow^{\\Src f} \\{ p \\}\n\\asymp \\langle f^{- 1} \\rangle C.\\]\n\\end{defn}\n\n\\begin{prop}\nThe following are pairwise equivalent:\n\\begin{enumerate}\n  \\item A funcoid $f$ is regular.\n  \\item $\\Compl (f \\circ f^{- 1} \\circ f) \\sqsubseteq \\Compl f$.\n  \\item $\\Compl (f \\circ f^{- 1} \\circ f) \\sqsubseteq f$.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\nEquivalently transform the defining formula for regular funcoids:\n\n$\\supfun{f} \\langle f^{- 1} \\rangle C \\asymp \\supfun{f}\n@\\{ p \\} \\Leftarrow \\uparrow^{\\Src f} \\{ p \\}\n\\asymp \\langle f^{- 1} \\rangle C$;\n\n$\\supfun{f} \\langle f^{- 1} \\rangle C \\nasymp \\supfun{f}\n@\\{ p \\} \\Rightarrow \\uparrow^{\\Src f} \\{ p \\} \\nasymp \\supfun{f^{-1}}C$;\n\n(by definition of funcoids)\n\n$C \\nasymp \\supfun{f} \\langle f^{- 1} \\rangle \\supfun{f}\n@\\{ p \\} \\Rightarrow C \\nasymp \\supfun{f}\n@\\{ p \\}$;\n\n$\\supfun{f} \\langle f^{- 1} \\rangle \\supfun{f}\n@\\{ p \\} \\sqsubseteq \\supfun{f}@\\{ p \\}$;\n\n$\\supfun{f \\circ f^{- 1} \\circ f} @\\{ p \\}\n\\sqsubseteq \\supfun{f} @\\{ p \\}$;\n\n$\\Compl (f \\circ f^{- 1} \\circ f) \\sqsubseteq \\Compl f$;\n\n$\\Compl (f \\circ f^{- 1} \\circ f) \\sqsubseteq f$.\n\\end{proof}\n\n\\begin{prop}\nIf $f$ is complete, regularity of funcoid $f$ is equivalent to $f \\circ\n\\Compl (f^{- 1} \\circ f) \\sqsubseteq f$.\n\\end{prop}\n\n\\begin{proof}\n  By proposition~\\ref{comp-compl}.\n\\end{proof}\n\n\\begin{rem}\nAfter seeing how it collapses into algebraic formulas about funcoids, the\ndefinition for a funcoid being regular seems quite arbitrary and sucked out of\nthe finger (not an example of algebraic elegance). So I present these formulas\nonly because they coincide with the traditional definition of regular\ntopological spaces. However this is only my personal opinion and it may be\nwrong.\n\\end{rem}\n\n\n\\begin{defn}\nAn endofuncoid is $T_{3}$- iff it is both $T_{2}$- and regular.\n\\end{defn}\n\nA topological space~$S$ is called $T_4$-separable when for any two disjoint closed sets $A,B\\subseteq S$\nthere exist disjoint open sets~$U$,~$V$ containing $A$ and $B$ respectively.\n\nLet $f$ be the complete funcoid corresponding to the topological space.\n\nSince the closed sets are exactly sets of the form $\\rsupfun{f^{- 1}} X$ and sets $X$ and $Y$ having non-intersecting open\nneighborhood is equivalent to $\\rsupfun{f} X \\asymp \\langle f\n\\rangle^{\\ast} Y$, the above is equivalent to:\n\n$\\rsupfun{f^{-1}} A \\asymp \\rsupfun{f^{-1}} B\n\\Rightarrow \\rsupfun{f} \\rsupfun{f^{-1}} A \\asymp\n\\rsupfun{f} \\rsupfun{f^{-1}} B$;\n\n$\\rsupfun{f} \\rsupfun{f^{-1}} A \\nasymp \\langle f\n\\rangle^{\\ast} \\rsupfun{f^{-1}} B \\Rightarrow \\langle f^{- 1}\n\\rangle^{\\ast} A \\nasymp \\rsupfun{f^{-1}} B$;\n\n$\\rsupfun{f} \\rsupfun{f^{-1}} \\langle f\n\\rangle^{\\ast} \\rsupfun{f^{-1}} A \\nasymp B \\Rightarrow \\langle\nf \\rangle^{\\ast} \\rsupfun{f^{-1}} A \\nasymp B$;\n\n$\\rsupfun{f} \\rsupfun{f^{-1}} \\langle f\n\\rangle^{\\ast} \\rsupfun{f^{-1}} A \\sqsubseteq \\langle f\n\\rangle^{\\ast} \\rsupfun{f^{-1}} A$;\n\n$f \\circ f^{- 1} \\circ f \\circ f^{- 1} \\sqsubseteq f \\circ f^{- 1}$.\n\nTake the last formula as the definition of $T_4$-funcoid~$f$.\n\n\\section{Filters closed regarding a funcoid}\n\\begin{defn}\n\\index{filter!closed}Let's call \\emph{closed} regarding a funcoid\n$f\\in\\mathsf{FCD}(A,A)$ such filter $\\mathcal{A}\\in\\mathscr{F}(\\Src f)$\nthat $\\supfun f\\mathcal{A}\\sqsubseteq\\mathcal{A}$.\n\\end{defn}\nThis is a generalization of closedness of a set regarding an unary\noperation.\n\\begin{prop}\nIf $I$ and $J$ are closed (regarding some funcoid $f$), $S$ is\na set of closed filters on $\\Src f$, then\n\\begin{enumerate}\n\\item $\\mathcal{I}\\sqcup\\mathcal{J}$ is a closed filter;\n\\item $\\bigsqcap S$ is a closed filter.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nLet denote the given funcoid as $f$. $\\supfun\nf(\\mathcal{I}\\sqcup\\mathcal{J})=\\supfun f\\mathcal{I}\\sqcup\\supfun\nf\\mathcal{J}\\sqsubseteq\\mathcal{I}\\sqcup\\mathcal{J}$,\n$\\supfun f\\bigsqcap S\\sqsubseteq\\bigsqcap\\rsupfun{\\supfun\nf}S\\sqsubseteq\\bigsqcap S$.\nConsequently the filters $\\mathcal{I}\\sqcup\\mathcal{J}$ and $\\bigsqcap S$\nare closed.\\end{proof}\n\\begin{prop}\nIf $S$ is a set of filters closed regarding a complete funcoid, then\nthe filter $\\bigsqcup S$ is also closed regarding our funcoid.\\end{prop}\n\\begin{proof}\n$\\supfun f\\bigsqcup S=\\bigsqcup\\rsupfun{\\supfun f}S\\sqsubseteq\\bigsqcup S$\nwhere $f$ is the given funcoid.\n\\end{proof}\n\n\\section{Proximity spaces}\n\nFix a set $U$. Let equate typed subsets of $U$ with subsets of~$U$.\n\nWe will prove that proximity spaces are essentially the same as reflexive,\nsymmetric, transitive funcoids.\n\nOur primary interest here is the last axiom (\\ref{prox-last}) in\nthe definition~\\ref{prox} of proximity spaces.\n\\begin{prop}\nIf $f$ is a transitive, symmetric funcoid, then the last axiom of\nproximity holds.\\end{prop}\n\\begin{proof}\n~\n\\begin{multline*}\n\\neg\\left(A\\rsuprel fB\\right)\\Leftrightarrow\\neg\\left(A\\rsuprel{f^{-1}\\circ\nf}B\\right)\\Leftrightarrow\\rsupfun fB\\asymp\\rsupfun fA\\Leftrightarrow\\\\\n\\exists M\\in U:M\\asymp\\rsupfun fA\\wedge\\overline{M}\\asymp\\rsupfun fB.\n\\end{multline*}\n\\end{proof}\n\\begin{prop}\nFor a reflexive funcoid, the last axiom of proximity implies that\nit is transitive and symmetric.\\end{prop}\n\\begin{proof}\nLet $\\neg\\left(A\\rsuprel fB\\right)$ implies $\\exists M:M\\asymp\\rsupfun\nfA\\wedge\\overline{M}\\asymp\\rsupfun fB$.\nThen $\\neg\\left(A\\rsuprel fB\\right)$ implies $M\\asymp\\rsupfun{f}A\\land\\rsupfun{f}B\\sqsubseteq M$,\nthus $\\rsupfun{f}A\\asymp\\rsupfun{f}B$; $\\neg\\left(A\\rsuprel{f^{-1}\\circ\nf}B\\right)$\nthat is $f\\sqsupseteq f^{-1}\\circ f$ and thus $f=f^{-1}\\circ f$.\nBy theorem \\ref{sym-trans} $f$ is transitive and symmetric.\\end{proof}\n\\begin{thm}\nReflexive, symmetric, transitive funcoids endofuncoids on a set~$U$\nare essentially the same as proximity spaces on~$U$.\\end{thm}\n\\begin{proof}\nAbove and theorem~\\ref{fcd-as-cont}.\\end{proof}\n\n", "meta": {"hexsha": "6fee9bb620e21237cddde32c15e0d554c80ad190", "size": 120182, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-funcoids.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-funcoids.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-funcoids.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": 36.3197340586, "max_line_length": 210, "alphanum_fraction": 0.6909603768, "num_tokens": 49050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6712993619255649}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Integrals}\n\\subsection{Integrals as Areas}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{integral.png}\n\t\\caption*{Signed area under the curve is given by $\\int_a^b f(t)\\:dt$}\n\\end{figure}\nThe integral of a function captures the concept of an area.\n\\begin{align*}\n\t\\int \\limits_{a}^b f(t) dt = \\mbox{ signed area between the curve $y=f(x)$ and the x-axis \\strut}\n\\end{align*}\nwhere by signed area we mean that the integral is negative if $f(x) < 0$ and hence equals negative of the area in this case (as area is always positive). This is a good {\\it interpretation} but not a good {\\it definition} as we have not rigorously defined what area is.\nInstead we'll define the integral in terms of a limit and then define the (signed) area as the integral.\n\n\\begin{exercise}\n\tExpress the following areas as (sums of) integrals. For each problem, draw pictures to justify your answer.\n\t\\begin{enumerate}\n\t\t\\item Area between the line $x + y = 1$, the x-axis and the y-axis.\n\t\t\\item Area enclosed between the graph $y = \\sin x$ and the x-axis for $x \\in [0,2\\pi]$.\n\t\t\\item Area enclosed between the parabola $y=x^2$ and the line $y=1$.\n\t\t\\item Area of a circle of radius 1.\n\t\\end{enumerate}\n\\end{exercise}\nSeveral physical quantities can be expressed as integrals, for example,\nif $t$ denotes time and $f(t)$ is the speed of a particle then the integral measures the distance traveled, if $t$ denotes length and $f(t)$ is the linear density of a one dimensional object then the integral measures the total mass, etc.\n\n\\subsection{Definition of Integral}\nWe need several preliminary definitions to define the integral.\n\\begin{definition}$ $\n\t\\begin{enumerate}\n\t\t\\item For an interval $[a,b]$ a {\\bf partition} $P$ is a sequence of real numbers\n\t\t      \\begin{align*}\n\t\t\t      a = x_0 < x_1 < \\dots < x_n = b\n\t\t      \\end{align*}\n\t\t\\item A {\\bf uniform partition} $P_n$ of $[a,b]$ is the {\\it uniform length} partition\n\t\t      \\begin{align*}\n\t\t\t      x_0 & = a                          \\\\\n\t\t\t      x_1 & = a + \\dfrac{b-a}{n}         \\\\\n\t\t\t          & \\:\\:\\: \\vdots                \\\\\n\t\t\t      x_i & = a + i \\cdot \\dfrac{b-a}{n} \\\\\n\t\t\t          & \\:\\:\\: \\vdots                \\\\\n\t\t\t      x_n & = b\n\t\t      \\end{align*}\n\t\t\\item For a partition $P$ define\n\t\t      \\begin{align*}\n\t\t\t      M_i & = \\sup \\{ f(x) : x_i \\le x \\le x_{i+1}\\} \\\\\n\t\t\t      m_i & = \\inf \\{ f(x) : x_i \\le x \\le x_{i+1}\\}\n\t\t      \\end{align*}\n\t\t      Define the {\\bf upper Riemann sum} $U(f,P)$ and the {\\bf lower Riemann sum} $L(f,P)$ as\n\t\t      \\begin{align*}\n\t\t\t      U(f,P) & = \\sum \\limits_{i=0}^{n-1} M_i \\cdot (x_{i+1} - x_i) \\\\\n\t\t\t      L(f,P) & = \\sum \\limits_{i=0}^{n-1} m_i \\cdot (x_{i+1} - x_i)\n\t\t      \\end{align*}\n\t\\end{enumerate}\n\\end{definition}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{RiemannSums2.png}\n\t\\includegraphics[width=0.8\\textwidth]{RiemannSums1.png}\n\t\\caption*{For finer partitions, the Riemann sums provide better approximations of the integral, hence in the limiting case as $n\\rightarrow \\infty$ we obtain the exact integral.}\n\\end{figure}\n\\begin{definition}\n\t\\label{def:definition_Integral}\n\tWe say that a function $f(x)$ is (Riemann) {\\bf integrable} on an interval $[a,b]$ if there exists a real number $I$ such that\n\t\\begin{align*}\n\t\t\\lim \\limits_{ n \\rightarrow \\infty} U(f,P_n) = I = \\lim \\limits_{ n \\rightarrow \\infty} L(f,P_n)\n\t\\end{align*}\n\tIn this case, we define the integral of $f$ on $[a,b]$ as\n\t\\begin{align*}\n\t\t\\int \\limits_{a}^{b} f(t) \\: dt & = I\n\t\\end{align*}\n\\end{definition}\n\\noindent Thus when a function $f(x)$ is integrable it suffices to compute either $\\lim \\limits_{ n \\rightarrow \\infty} U(f,P_n)$ or $\\lim \\limits_{ n \\rightarrow \\infty} L(f,P_n)$ to compute the integral. \\\\\n\nWe'll assume the following theorem without proof. The proof requires the notion of {\\bf uniform continuity} which is beyond the scope of this class.\n\n\\begin{theorem}\n\t\\label{theorem:continuous_are_integrable}\n\tIf $f$ is a continuous function on the interval $[a,b]$ then $f$ is integrable on $[a,b]$.\n\\end{theorem}\n\nWe'll do a few examples to better understand the definition of integral.\n\\begin{exercise}\n\tLet $f(x) = -x$, let $a=0$ and $b = 1$.\n\t\\begin{enumerate}\n\t\t\\item Use basic geometry to find $\\int_{0}^1 f(t) \\: dt$.\n\t\t\\item Using pictures describe and compute $L(f,P_1)$, $L(f,P_2)$, and $L(f,P_3)$.\n\t\t\\item Compute $L(f,P_n)$ where $n$ is a positive integer. You'll need to use\n\t\t      \\begin{align*}\n\t\t\t      1 + 2 + 3 + \\dots + n = \\dfrac{n(n+1)}{2}\n\t\t      \\end{align*}\n\t\t\\item Find $\\lim \\limits_{n \\rightarrow \\infty} L(f,P_n)$, which equals $\\int_{0}^1 f(t) \\: dt$ by Theorem \\ref{theorem:continuous_are_integrable}, and verify that it agrees with part 1.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tLet $f(x) = x^2$, let $a=0$ and $b = 1$.\n\t\\begin{enumerate}\n\t\t\\item Compute $U(f,P_n)$ where $n$ is a positive integer. You'll need to use the identity\n\t\t      \\begin{align*}\n\t\t\t      1^2 + 2^2 + 3^2 + \\dots + n^2 = \\dfrac{n(n+1)(2n+1)}{6}\n\t\t      \\end{align*}\n\t\t\\item Find $\\lim \\limits_{n \\rightarrow \\infty} U(f,P_n)$, which equals $\\int_{0}^1 f(t) \\: dt$ by Theorem \\ref{theorem:continuous_are_integrable}.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tLet $a = 0$, $b = 1$, and let\n\t\\begin{align*}\n\t\tf(x) = \\begin{cases}\n\t\t\t1 & \\mbox{ if $x$ is rational}    \\\\\n\t\t\t0 & \\mbox{ if $x$ is irrational.}\n\t\t\\end{cases}\n\t\\end{align*}\n\t\\begin{enumerate}\n\t\t\\item For $n$ a positive integer, compute $U(f,P_n)$ and $L(f,P_n)$.\n\t\t\\item Find $\\lim \\limits_{n \\rightarrow \\infty} U(f,P_n)$ and $\\lim \\limits_{n \\rightarrow \\infty} L(f,P_n)$ and show that the $f(x)$ is not integrable.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\n\\subsubsection{Indefinite Integrals}\nWe'll assume the following theorem without proof.\n\\begin{theorem}\n\t\\label{theorem:integral_sum}\n\tFor real numbers $a < b < c$, if $f$ is integrable on $[a,c]$ then\n\t\\begin{align*}\n\t\t\\int \\limits_a ^c f(t) \\: dt = \\int \\limits_a ^b f(t) \\: dt  + \\int \\limits_b ^c f(t) \\: dt\n\t\\end{align*}\n\\end{theorem}\n\\begin{exercise}\n\tDraw a picture to explain the statement of the above theorem.\n\\end{exercise}\n\nSo far, we've only defined $\\int_a^b f(t) \\: dt$ for $a < b$. We now extend this to all real numbers $a$, $b$ by defining\n\\begin{align*}\n\t\\int \\limits_a^a f(t) \\:dt\n\t= 0\n\t &  & \\mbox{ and } &  &\n\t\\int \\limits_a^b f(t) \\:dt\n\t= -\\int \\limits_b^a f(t) \\:dt\n\t\\mbox{ \\quad if } a > b\n\\end{align*}\nWith this extended notation one can check that Theorem \\ref{theorem:integral_sum} is true for all real numbers $a$, $b$, $c$. For example, for $ a < b < c$\n\\begin{align*}\n\t         &  &\n\t\\int \\limits_a ^c f(t) \\: dt = \\int \\limits_a ^b f(t) \\: dt  + \\int \\limits_b ^c f(t) \\: dt \\\\\n\t\\implies &  &\n\t\\int \\limits_a ^c f(t) \\: dt = \\int \\limits_a ^b f(t) \\: dt  - \\int \\limits_c ^b f(t) \\: dt \\\\\n\t\\implies &  &\n\t\\int \\limits_a ^c f(t) \\: dt + \\int \\limits_c ^b f(t) \\: dt = \\int \\limits_a ^b f(t) \\: dt\n\\end{align*}\n\n\n\\begin{definition}\n\tFor an integrable function $f$ and a real number $a$, an {\\bf antiderivative} is a function on the real numbers defined as\n\t\\begin{align*}\n\t\tF_a(x) = \\int \\limits_a^x f(t) \\: dt\n\t\\end{align*}\n\\end{definition}\n\n\\begin{exercise}\n\t\\label{q:difference_antiderivatives}\n\tFor real numbers $a$, $b$ show that\n\t\\begin{align*}\n\t\tF_a(x) - F_b(x)\n\t\\end{align*}\n\tis a constant that does not depend on $x$.\n\\end{exercise}\n\nThus for any integrable function $f$ any two antiderivatives differ by a constant. This allows us to {\\it define} the {\\bf indefinite integral} denoted\n\\begin{align*}\n\t\\int f(x) \\: dx\n\\end{align*}\nas $\\int_a^x f(t) \\: dt$ for some real number $a$. Changing the constant $a$ changes $F_a(x)$ by a constant, hence the indefinite integral is only defined up to a constant.\n", "meta": {"hexsha": "c443afa54e5a24c39ebf416ad55179c86ff98ae1", "size": 7764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/06Integrals.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/06Integrals.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/06Integrals.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": 43.1333333333, "max_line_length": 269, "alphanum_fraction": 0.642194745, "num_tokens": 2630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.671280202814062}}
{"text": "\\section{Selection}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The $3$rd largest element (Problem 3.1)}\n  \\[\n\tV_k(n): \\text{$\\min$ \\#comparisons to find the $k$-th largest element of $n$ elements.}\n  \\]\n\n  \\pause\n  \\begin{align*}\n\tV_1(n) &= n - 1 \\\\\n\tV_2(n) &= (n - 1) + (\\lceil \\log n \\rceil - 1) \\\\\n  \\end{align*}\n\n  \\pause\n  \\[\n\tV_3(n) = \\;?\n  \\]\n\n  \\pause\n  \\[\n\tV_3(n) \\le (n - 1) + (\\lceil \\log n \\rceil - 1) + \\textcolor{red}{(n - 3)}\n  \\]\n\n  \\pause\n  \\[\n\tV_3(n) \\le (n - 1) + (\\lceil \\log n \\rceil - 1) + \\textcolor{red}{(\\lceil \\log n \\rceil - 1)} \n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The $3$rd largest element (Problem 3.1)}\n  \\centerline{``$Q_1$: What is the exact value of $V_3(n)$?''}\n\n  \\begin{theorem}[$V_3(n)$]\n\t$n \\ge 6, n = 2^k + r (0 \\le r < 2^k)$:\n\t\\begin{equation*}\n\t  V_3(n) = \\begin{cases}\n\t\t(n - 3) + 2 k \t  & r = 0, 1 \\\\\n\t\t(n - 3) + 2 k + 1 & 2 \\le r \\le 2^{k -2} + 1 \\\\\n\t\t(n - 3) + 2 k + 2 & \\text{o.w.} \\\\\n\t  \\end{cases}\n\t\\end{equation*}\n  \\end{theorem}\n\n  \\begin{alertblock}{References}\n\t``Selecting the Top Three Elements'' by Aigner, 1982.\n  \\end{alertblock}\n\n  \\pause\n  \\begin{alertblock}{Reference}\n\t``The Art of Computer Programming, Vol 3: Sorting and Searching (Section 5.3.3)'' by Donald E. Knuth.\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The $3$rd largest element (Problem 3.1)}\n  \\begin{center}\n\t``$Q_2$: Does your algorithm need to find the $1$st and the $2$nd elements?'' \\\\[0.30cm] \\pause\n\n\t``YES!''\n  \\end{center}\n\n  \\pause\n  \\begin{center}\n\t``$Q_3$: Do all algorithms have to find the $1$st and the $2$nd elements?'' \\\\[0.30cm] \\pause\n\n\t``NO!''\n  \\end{center}\n\n  \\pause\n  \\begin{alertblock}{References}\n\t``Selecting the Top Three Elements'' by Aigner, 1982.\n  \\end{alertblock}\n\n  % \\pause\n  % \\begin{description}\n  %   \\item[$V_t(n)$:] \n  %   \\item[$W_t(n)$:] \n  %   \\item[$U_t(n)$:] \n  % \\end{description}\n\n  % \\pause\n  % \\begin{align*}\n  %   U_1(n) &= V_1(n) = W_1(n) = n - 1 \\\\\n  %   W_2(n) &= V_2(n) = n + \\lceil \\log n \\rceil - 2\n  % \\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Selection with minimum \\#comparisons (Problem 3.2)}\n  Selecting the median of $5$ elements using $6$ comparisons.\n\n  \\fignocaption{width = 0.60\\textwidth}{figs/median5.jpg}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Sorting with minimum \\#comparisons (Problem 2.4)}\n  Sorting $5$ elements using $7$ comparisons.\n\n  \\[\n    S(5) = 7\n  \\]\n\n  \\pause\n  \\begin{alertblock}{Reference}\n\t``The Art of Computer Programming, Vol 3: Sorting and Searching (Section 5.3.1)'' by Donald E. Knuth.\n  \\end{alertblock}\n\n  \\[\n\tS(21) = 66\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Sorting with minimum \\#comparisons (Problem 2.4)}\n  Sorting $5$ elements using $7$ comparisons.\n  \\fignocaption{width = 0.60\\textwidth}{figs/median5.jpg}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Medians of sorted arrays (Problem 3.7)}\n  \\centerline{\\url{http://cs.stackexchange.com/a/33129/4911}}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{The largest $k$ elements (Problem 3.5)}\n% \\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Close to median (Problem 3.6)}\n% \\end{frame}\n% %%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Dynamic median (Problem 3.8)}\n% \\end{frame}\n% %%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Weighted median (Problem 3.9)}\n% \\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\n", "meta": {"hexsha": "40de85dd4e64a01a587c40a2fc72274eb8de9f40", "size": 3326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-search-selection-20170410/sections/selection.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/selection.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/selection.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.007518797, "max_line_length": 102, "alphanum_fraction": 0.556825015, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272544, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6712801886054075}}
{"text": "\\SecDef{lindiff}{Resistance against Linear and Differential Cryptanalysis}\n\nLinear and differential cryptanalysis are powerful methods of attacking symmetric cryptographic primitives. \n\nIn most block ciphers, S-Boxes are usually the only source of nonlinearity. The resistance of a cipher depends largely on the cryptographic strength of the S-Boxes it uses. Due to typically small sizes of S-Boxes, the linear and differential propagations through them may be analyzed in an exhaustive manner. For this purpose, the \\emph{Linear Approximation Table (LAT)} and the \\emph{Difference Distribution Table (DDT)} are used. Even though these objects are motivated by the analysis of S-Boxes, they are also useful theoretical tools in the analysis of larger cryptographic functions.\n\n\\begin{definition}[Walsh Transform]\nThe \\emph{Walsh transform} $\\walsh{f}$ of a Boolean function $f\\colon \\field{n} \\to \\field{}$ is defined as:\n\\begin{align*}\n    & \\walsh{f}\\colon \\field{n} \\to \\ZZ,\\\\\n    & \\walsh{f}(a) \\eqdef \\sum_{x \\in \\field{n}} (-1)^{f(x)\\oplus \\inprod{a,x}} = -2^n \\cor(f \\oplus \\varphi_a),\n\\end{align*}\nwhere $\\varphi_a(x) \\eqdef \\inprod{a,x}$. It can be seen as a multidimensional Fourier transform of the function $x \\mapsto (-1)^{f(x)}$. The multiset of all values of the Walsh transform of $f$ is called the \\emph{Walsh spectrum} of $f$.\n\\end{definition}\n\n\\begin{definition}[Linear Approximation Table (LAT)]\nLet $S: \\field{n} \\to \\field{m}$. The linear approximation table (LAT) of $S$ is the mapping\n\\begin{align*}\n& \\LAT{S}: \\field{n}\\times\\field{n} \\to \\ZZ,\\\\    \n& \\LAT{S}(a,b) \\eqdef \\walsh{S_b}(a) = 2\\psize{\\pset{x \\in \\field{n} \\mid \\inprod{a,x} = \\inprod{b,S(x)} }} - 2^{n}\n= \\sum_{x \\in \\field{n}} (-1)^{\\inprod{a,x} \\oplus \\inprod{b,S(x)}}\n.\n\\end{align*}\n$\\LAT{S}$ naturally defines a $2^n \\times 2^n$ matrix over $\\ZZ$ (where the inputs $a,b$ are ordered in the lexicographic order). The columns of $\\LAT{S}$ correspond to \\emph{Walsh transforms} of the components of $S$.\n\\end{definition}\n\nI remark that in several papers the LAT is defined with a coefficient $1/2$ or $-1/2$, e.g. in~\\cite{OurFeistel}. \n\n\\begin{definition}[Difference Distribution Table (DDT)]\nLet $S: \\field{n} \\to \\field{m}$. The difference distribution table (DDT) of $S$ is the mapping\n\\begin{align*}\n& \\DDT{S}: \\field{n}\\times\\field{n} \\to \\ZZzeroplus, \\\\\n& \\DDT{S}(a,b) =\n\\psize{\\pset{x \\in \\field{n} \\mid S(x\\oplus a) \\oplus S(x) = b }}\n.    \n\\end{align*}\n$\\DDT{S}$ naturally defines a $2^n \\times 2^n$ matrix over $\\ZZzeroplus$ (where the inputs $a,b$ are ordered in the lexicographic order).\n\\end{definition}\n\nThe maximum absolute values of the LAT and the DDT of an S-Box are used to measure the cryptographic strength of the S-Box. For this purpose, the \\emph{linearity} and the \\emph{differential uniformity} of an function are defined.\n\n\\begin{definition}[Linearity]\nLet $f\\colon \\field{n} \\to \\field{}$ be a Boolean function. The \\emph{linearity} of $f$ is denoted by $\\LIN(f)$ and is defined to be the maximum absolute value in the Walsh spectrum of $f$:\n$$\n\\LIN(f) \\eqdef \\max_{a \\in \\field{n}} \\pabs{\\walsh{f}(a)}\n= \\max_{a \\in \\field{n}} \\abs{\\sum_{x \\in \\field{n}}(-1)^{f(x) \\oplus \\inprod{a,x}}}\n.$$\n\nLet $S: \\field{n} \\to \\field{m}$ be a Vectorial Boolean function. The \\emph{linearity} of $S$ is denoted by $\\LIN(S)$ and is equal to the maximum linearity among the components of $S$:\n$$\n\\LIN(S) \\eqdef \\max_{b \\in \\field{n}, b \\ne 0} \\LIN(S_b)\n= \\max_{a \\in \\field{n},b\\in \\field{n},b\\ne 0} \\abs{\\sum_{x \\in \\field{n}} (-1)^{\\inprod{b,f(x)} \\oplus \\inprod{a,x}}}\n.\n$$\n\\end{definition}\n\n\n\n\\begin{definition}[Differential Uniformity]\nLet $f: \\field{n} \\to \\field{m}$. The differential uniformity of $f$ is denoted by $\\DU(f)$ and is given by:\n$$\n\\DU(f) = \\max_{a\\in \\field{n}, b\\in \\field{m}, a\\ne 0} \\DDT{f}(a,b).\n$$\n\\end{definition}\n\nThe entries of the DDT of any S-Box are always even. It follows that the differential uniformity can never be smaller than 2. The functions achieving this lower bound are called \\emph{Almost Perfect Nonlinear (APN)}. For example, the cube function over the finite field is always APN~\\cite{Nyb94}: $x \\mapsto x^3, x \\in \\fielde{n}$. When $n$ is odd, the cube function is a \\emph{permutation} of $\\fielde{n}$ and thus is an \\emph{APN permutation}. However, it is not bijective when $n$ is even. The question of existence of APN permutations in even dimensions is a long-standing problem. For $n=4$ the answer is known to be negative, and for $n=6$ the positive answer was given by Dillon~\\etal{}~\\cite{DillonAPN} who explicitly provided a 6-bit APN permutation as a look-up table. In \\ChapRef{apn} I describe an interesting decomposition of this function which we found together with my colleagues using S-Box reverse-engineering methods~\\cite{OurAPN}. For even $n\\ge 8$ the question is still a big open problem.\n\n\n\\subsubsection{Effect of Affine Encodings on the LAT}\n\nCompositions of a function with affine mappings have a simple effect on the function's LAT. The following propositions describe the effect separately for addition of constants and composition with linear maps. The constant addition only affects the signs of the LAT coefficients, and the linear encodings shuffle the LAT coefficients in a linear way.\n\n\\begin{proposition}\nLet $S\\colon \\field{n} \\to \\field{m}$ and let $S'\\colon \\field{n} \\to \\field{m}, S'(x) = S(x \\oplus c_x) \\oplus c_y$ for some $c_x \\in \\field{n}, c_y \\in \\field{m}$. Then for any $a \\in \\field{n}, b \\in \\field{m}$\n$$\n\\LAT{S'}(a,b) = \\LAT{S}(a,b) (-1)^{\\inprod{a,c_x}\\oplus {\\inprod{b, c_y}}}.\n$$\n\\end{proposition}\n% \\begin{proof}\n% \\begin{multline*}\n% \\LAT{S'}(a,b) =\n% \\sum_{x \\in \\field{n}} (-1)^{\\inprod{a,x} \\oplus \\inprod{b,S(x \\oplus c_x)\\oplus  c_y}} =\n% \\sum_{z \\in \\field{n}} (-1)^{\\inprod{a,z \\oplus c_x} \\oplus \\inprod{b,S(z)\\oplus  c_y}} = \\\\\n% = \\sum_{z \\in \\field{n}} (-1)^{\\inprod{a,z} \\oplus \\inprod{b,S(z)}} (-1)^{\\inprod{a, c_x} \\oplus \\inprod{b, c_y}} = \\LAT{S}(a,b) (-1)^{\\inprod{a, c_x} \\oplus \\inprod{b, c_y}}.\n% \\end{multline*}\n% \\end{proof}\n\n\\begin{proposition}\n\\Label{prop:linear-lat}\nLet $S\\colon \\field{n} \\to \\field{m}$ and let $S' \\eqdef B \\circ S \\circ A$ for some $A \\in \\linbij{n}, B \\in \\linbij{m}$. Then for any $a \\in \\field{n}, b \\in \\field{m}$\n$$\n\\LAT{S'}(a,b) = \\LAT{S}(\\invtop{A} \\times a, B \\times b).\n$$\n\\end{proposition}\n% \\begin{proof}\n% \\begin{multline*}\n% \\LAT{S'}(a,b) =\n% \\sum_{x \\in \\field{n}} (-1)^{\\inprod{a,x} \\oplus \\inprod{b,B(S(A(x)))}} =\n% \\sum_{z \\in \\field{n}} (-1)^{\\inprod{a,A^{-1}(z)} \\oplus \\inprod{b,B(S(z))}} = \\\\\n% \\sum_{z \\in \\field{n}} (-1)^{\\inprod{\\invtop{A} (a),(z)} \\oplus \\inprod{B^{\\top} (b), S(z)}} = \\LAT{S}(\\invtop{A} \\times a, B^{\\top} \\times b).\n% \\end{multline*}\n% \\end{proof}\n", "meta": {"hexsha": "ee868ec7760df0992c5bd304b22b57b050a9a289", "size": 6741, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/2_Prelim/2lindiff.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/2_Prelim/2lindiff.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/2_Prelim/2lindiff.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.4466019417, "max_line_length": 1011, "alphanum_fraction": 0.6798694556, "num_tokens": 2297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093668, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6712801848031228}}
{"text": "\n\\section{The \\adjacentdifference algorithm}\n\\Label{sec:adjacentdifference}\n\nThe \\adjacentdifference algorithm in the \\cxx Standard Library \\cite[\\S 29.8.11]{cxx-17-draft}\ncomputes the differences of adjacent elements in a range.\n%\nOur version of the original signature reads:\n\n\\begin{lstlisting}[style=acsl-block]\n\nsize_type\nadjacent_difference(const value_type* a, size_type n, value_type* b);\n\\end{lstlisting} \n\nAfter executing the function \\adjacentdifference the array \\inl{b[0..n-1]} holds the following values\n\\begin{align}\n   \\mathtt{b}[0] &= \\mathtt{a}[0] \\nonumber \\\\\n   \\mathtt{b}[1] &= \\mathtt{a}[1] - \\mathtt{a}[0] \\nonumber \\\\\n                 &\\vdotswithin{=} \\nonumber \\\\\n   \\mathtt{b}[n-1] &= \\mathtt{a}[n-1] - \\mathtt{a}[n-2] \\nonumber \\\\\n\\end{align}\n\n\\subsection{The predicate \\AdjacentDifference}\n\nWe start with the definition of the logic function \\Difference whose definition\nis shown in the following listing.\n\n\\input{Listings/Difference.acsl.tex}\n\n\\clearpage \n\nBuilding on top of \\Difference we now introduce the predicate \\AdjacentDifference.\nWe also provide the predicate \\AdjacentDifferenceBounds\nthat captures conditions that prevent numeric overflows\nwhile computing differences of the form \\inl{a[i] - a[i-1]}.\n\n\\input{Listings/AdjacentDifference.acsl.tex}\n\nLemmas \\logicref{AdjacentDifferenceStep} and \\logicref{AdjacentDifferenceSection}\nwill help us later in the verification of \\implref{adjacentdifferenceinv}.\n\n\\clearpage\n\n\\subsection{Formal specification of \\adjacentdifference}\n\nUsing the predicates \\logicref{AdjacentDifference} and \\logicref{AdjacentDifferenceBounds}\nwe can provide in the following listing a concise formal specification of \\adjacentdifference.\nAs in the case of the specification of \\specref{partialsum}\nwe require that the arrays \\inl{a[0..n-1]} and \\inl{b[0..n-1]} \nare separated.\n\n\\input{Listings/adjacent_difference.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\adjacentdifference}\n\nThe following listing shows an implementation of \\adjacentdifference\nwith corresponding loop annotations.\nIn order to achieve the verification of the loop invariant \\inl{difference} we \nrely on\n\\begin{itemize}\n\\item the assertions \\inl{bound} and \\inl{difference}\n\\item the lemmas \\logicref{AdjacentDifferenceStep} and \\logicref{AdjacentDifferenceSection}\n\\item a statement contract with the two postconditions labeled as \\inl{step}\n\\end{itemize}\n\n\\input{Listings/adjacent_difference.c.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "0ed5087f4fd98466b800931a94adb791361c615e", "size": 2454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/adjacent_difference.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/numeric/adjacent_difference.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/numeric/adjacent_difference.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 33.6164383562, "max_line_length": 101, "alphanum_fraction": 0.7775061125, "num_tokens": 650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311906630568, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6712801826818292}}
{"text": "\\subsection{Optimization problem}\n\\label{subsec:learningprocess:optimizationproblem}\n\n\n% ----------------------- paths to graphics ------------------------\n\n\n\n% ----------------------- contents from here ------------------------\n% \n\nWe can define the learning process as follows: given a sample from a dataset, its schema and a set of pattern detectors as input, output a compression tree that, when applied to the dataset, produces a compressed representation of it of minimum disk size.\n\nThe schema is a list of columns and their data types. The pattern detectors are implementations of the \\nameref{subsec:genericpd}---receives the columns as input, evaluates the sample and returns a list of \\textit{(expression node, evaluation result)} tuples. Adding an \\textit{expression node} to the compression tree means: 1) altering the schema by deleting existing columns and creating new ones; 2) altering the sample by applying the \\textit{compression operator} to the input columns and generating new data. The learning process can go on by recursively feeding the new schema and sample data to the pattern detectors, resulting in new \\textit{(expression node, evaluation result)} tuples. This recursive process stops when no pattern detector outputs any result anymore---no pattern matches on the current schema and data.\n\nEach decision of adding or not adding an \\textit{expression node} to the compression tree generates a new solution. This leads to a total number of \\(2^n\\) possible solutions (different compression trees), where \\(n\\) is the total number of \\textit{expression nodes} generated by the recursive process (\\(n\\) binary decisions: \\(1\\) means adding a node and \\(0\\) not adding it). The total number of \\textit{expression nodes} (\\(n\\)) depends on how well pattern detectors match on the initial columns and the newly generated ones. This is entirely dependent on the characteristics of the data and the patterns that were evaluated on it. In the worst case, all pattern detectors will match on any column, leading to the following expression for \\(n\\):\n\\begin{equation}\n\\label{eq:optimizationproblem:n}\n    n = c_{in} \\times (p \\times \\mathit{avg}(n_{p}) \\times b) ^ h\n\\end{equation}\n\\begin{equation}\n\\label{eq:optimizationproblem:b}\n    b = \\mathit{avg}(c_{out})\n\\end{equation}\nwhere:\n\\begin{itemize}\n    \\item[] \\(n\\) = total number of expression nodes\n    \\item[] \\(c_{in}\\) = number of input columns\n    \\item[] \\(p\\) = number of pattern detectors\n    \\item[] \\(n_{p}\\) = number of expression nodes returned by a pattern detector\n    \\item[] \\(b\\) = branching factor of the compression tree\n    \\item[] \\(h\\) = height of the compression tree\n    \\item[] \\(c_{out}\\) = number of output columns of an expression node\n\\end{itemize}\n\nThe score of each solution is given by the size of the compressed data that resulted after applying the compression tree to the dataset. The goal of the learning process is to choose the one that gives the smallest size.\n\nThe computational effort needed for each individual \\textit{expression node} consists of: 1) applying the compression operator on its input columns to generate the new data (feeding each tuple in the sample data to the operator); 2) evaluating the pattern detectors on all the new columns (feeding each tuple in the sample data to each pattern detector). Moreover, some pattern detectors may need to evaluate combinations of columns instead of individual columns, which requires all the existing columns to be reevaluated for every newly generated column (e.g. \\nameref{subsec:pd:columncorrelation} evaluates all pairs of 2 columns to determine the correlation coefficient between them).\n\n\\iffalse\nTODO:\nbetter formalize problem\nhttps://en.wikipedia.org/wiki/Optimization\\_problem\n\\fi\n\n% ---------------------------------------------------------------------------\n% ----------------------- end of thesis sub-document ------------------------\n% ---------------------------------------------------------------------------", "meta": {"hexsha": "3944075e0f6631250691ed784d0a558331128ed2", "size": 3995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/5_automatic_learning/learning_process/optimization_problem.tex", "max_stars_repo_name": "bogdanghita/master-thesis", "max_stars_repo_head_hexsha": "f271ceb09960a5cf332fde3603244616069724fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-16T08:58:07.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-16T08:58:07.000Z", "max_issues_repo_path": "src/5_automatic_learning/learning_process/optimization_problem.tex", "max_issues_repo_name": "bogdanghita/master-thesis", "max_issues_repo_head_hexsha": "f271ceb09960a5cf332fde3603244616069724fe", "max_issues_repo_licenses": ["MIT"], "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/5_automatic_learning/learning_process/optimization_problem.tex", "max_forks_repo_name": "bogdanghita/master-thesis", "max_forks_repo_head_hexsha": "f271ceb09960a5cf332fde3603244616069724fe", "max_forks_repo_licenses": ["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.2291666667, "max_line_length": 831, "alphanum_fraction": 0.7131414268, "num_tokens": 853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6712193371789185}}
{"text": "% !TEX root = index.tex\n\n\\section{Dimension}\n\n\\begin{qbox}\n  Consider the line $L = \\{ c \\vec{v}: c \\in \\bbr \\} $ where $\\vec{v}$ is a non-zero vector in $\\bbr^n$. One basis for $L$ is $\\calb = \\{ \\vec{v}\\}$.\n  \\begin{enumerate}\n    \\item Argue that every basis of $L$ has exactly one element.\n  \\end{enumerate}\n\\end{qbox}\n\n\\begin{qbox}\n  Consider the plane $P = \\{ c_1 \\vec{v}_1 + c_2 \\vec{v}_2: c_1, c_2 \\in \\bbr \\} $ where $\\vec{v}_1, \\vec{v}_2$ are non-zero vectors in $\\bbr^n$ which are not linear multiples of each other.\n  One basis for $P$ is $\\{ \\vec{v}_1, \\vec{v}_2 \\}$.\n  \\begin{enumerate}\n    \\item Argue that every basis of $P$ has exactly two elements.\n  \\end{enumerate}\n\\end{qbox}\n\nThis generalizes to arbitrary vector spaces.\n\n\\begin{theorem}\n  \\label{theorem:dimensionVectorSpace}\n  If a subspace $V$ of $\\bbr^n$ has a basis $\\calb$ of size $k$ then every basis $\\calb'$ of $V$ has size $k$.\n\\end{theorem}\n\nThis number is then defined to be the dimension of the subspace $V$.\n\n\\begin{mdframed}\n  The proof of Theorem \\ref{theorem:dimensionVectorSpace} is a bit long and complicated.\n  If you are seeing this for the first time, you can assume this theorem without proof, so the the sections below are optional.\n  You should at least skim through them to get an idea of how the proof goes.\n\\end{mdframed}\n\nWe start by analysing arbitrary linearly independent sets inside a vector space.\n\n\\begin{proposition}\n  \\label{proposition:sizeOfLinIndependentSets}\n  Let $V$ be a subspace of $\\bbr^n$ with a finite basis $\\calb$.\n  Let $\\cals$ be an arbitrary linearly independent subset of $V$.\n  Then $\\abs{\\cals} \\le \\abs{\\calb}$.\n\\end{proposition}\n\\begin{proof}\n  Let $\\calb = \\set{\\vec{v}_1, \\dots, \\vec{v}_k}$ be a basis of $V$ and let $\\cals$ be a linearly independent subset of $V$. We want to show that $\\ell \\le k$.\n  We will instead prove the contrapositive:\n  {\\it If  $\\ell > k$ then there exist scalars $c_1$, \\dots, $c_{\\ell}$, not all 0, such that \\begin{align}\n  \\label{equation:linearDependence}\n    c_1\\vec{w}_1 + \\dots + c_\\ell \\vec{w}_\\ell= 0.\n  \\end{align}}\n  In the basis $\\calb$, we can express the vectors $\\vec{w_i}$'s as coordinate vectors.\n  \\begin{align*}\n    [w_i]_{\\calb}\n    &=\n    \\begin{bmatrix}\n      A_{1i} \\\\\n      A_{2i} \\\\\n      \\vdots \\\\\n      A_{ki}\n    \\end{bmatrix}\n  \\end{align*}\n  Equation \\eqref{equation:linearDependence} then simplifies as\n  \\begin{align*}\n    %&&\n    c_1\\vec{w}_1 + \\dots + c_\\ell \\vec{w}_\\ell&= 0 \\\\\n    \\implies %&&\n    c_1[\\vec{w}_1]_\\calb + \\dots + c_\\ell [\\vec{w}_\\ell]_\\calb&= 0 \\\\\n    \\implies %&&\n    c_1 \\begin{bmatrix}\n      A_{11} \\\\\n      A_{21} \\\\\n      \\vdots \\\\\n      A_{k1}\n    \\end{bmatrix}\n    +\n    \\dots\n    +\n    c_\\ell \\begin{bmatrix}\n      A_{1\\ell} \\\\\n      A_{2\\ell} \\\\\n      \\vdots \\\\\n      A_{k\\ell}\n    \\end{bmatrix}\n    &= 0 \\\\\n    \\implies\n    %&&\n    \\begin{bmatrix}\n      A_{11}c_1 \\\\\n      A_{21}c_1 \\\\\n      \\vdots \\\\\n      A_{k1}c_1\n    \\end{bmatrix}\n    +\n    \\dots\n    +\n    \\begin{bmatrix}\n       A_{1\\ell} c_\\ell\\\\\n       A_{2\\ell} c_\\ell\\\\\n      \\vdots \\\\\n       A_{k\\ell}c_\\ell\n    \\end{bmatrix}\n    &= 0 \\\\\n    \\implies\n    %&&\n    \\begin{bmatrix}\n      A_{11} c_1 + \\dots + A_{1\\ell} c_\\ell\\\\\n      A_{21} c_1 + \\dots + A_{2\\ell} c_\\ell\\\\\n      \\vdots \\\\\n      A_{k1} c_1 + \\dots + A_{k\\ell}c_\\ell\n    \\end{bmatrix}\n    &= 0 \\\\\\\\\n    \\implies\n    %&&\n      A_{11} c_1 + \\dots + A_{1\\ell} c_\\ell &= 0 \\\\\n      %&&\n      A_{21} c_1 + \\dots + A_{2\\ell} c_\\ell &= 0 \\\\\n      %&&\n      \\vdots \\\\\n      %&&\n      A_{k1} c_1 + \\dots +  A_{k\\ell}c_\\ell &= 0\n  \\end{align*}\n  These are $k$ equations in $\\ell$ variables and $\\ell > k$, so we have more variables than equations. Such a system is called an \\emph{under-determined} linear system. Because the right-hand is zero, such a system always has a solution (Lemma \\ref{theorem:underDeterminedLinearSystem}) with not all $c_i$ equal to 0.\n\\end{proof}\n\nBecause every basis is also a linearly independent set, we can use Proposition \\ref{proposition:sizeOfLinIndependentSets} to say several things about bases.\n\n\\begin{corollary}\n  Let $V$ be a subspace of $\\bbr^n$.\n  \\begin{enumerate}\n    \\item If $\\calb$ is a basis of $V$ then $|\\calb| \\le n$.\n    \\item If $\\calb$ and $\\calb'$ are two bases of $V$, then $|\\calb| = |\\calb'|$.\n    \\item Every basis of $\\bbr^n$ has $n$ elements.\n  \\end{enumerate}\n\\end{corollary}\n\n\\begin{qbox}\n  Prove the above corollaries using Proposition \\ref{proposition:sizeOfLinIndependentSets}.\n\\end{qbox}\n\nNotice that the above theorems compare the sizes of linearly independent sets to the size of a basis. But we have not shown that a basis exists in the first place.\n\n\\begin{theorem}\n  \\label{theorem:existenceOfBasis}\n  Let $V$ be a subspace of $\\bbr^n$. Then $V$ has a basis.\n\\end{theorem}\n\\begin{proof}\n  We provide an algorithm for constructing a basis $\\calb$.\\\\\\\\\n  Set $i=0$ and let $S_0 = \\varnothing$.\n  \\begin{enumerate}\n    \\item If $\\spn(S_i) = V$ we are done.\n    \\item If $\\spn(S_i) \\neq V$ then there exists a vector $\\vec{v}_i$ such that $\\vec{v}_i \\in V \\setminus \\spn(S_i)$.\n    \\item Let $S_{i+1} = S_i \\cup \\set{\\vec{v}_i}$ and increment $i$ by 1. Go back to Step 1.\n  \\end{enumerate}\n  Once this process terminates the final set $S_i$ that we obtain is a basis for $V$.\n  \\begin{qbox}\n    \\begin{enumerate}\n      \\item Show that the sets $S_i$ constructed above are all linearly independent.\n      \\item Using Proposition \\ref{proposition:sizeOfLinIndependentSets} argue that the above algorithm always terminates?\n      \\item Prove that the final $S_i$ is a basis for $V$?\n    \\end{enumerate}\n  \\end{qbox}\n\\end{proof}\n\nThis allows to make the following definition.\n\\begin{definition}\n  For a subspace $V$ of $\\bbr^n$, the \\emph{dimension} of $V$ is defined to be the size of any basis $\\calb$.\n  \\begin{align*}\n    \\dim V := \\abs{\\calb} \\mbox{ where } \\calb \\mbox{ is any basis of } V\n  \\end{align*}\n\\end{definition}\n\n\\begin{qbox}(Optional)\n  Using a similar algorithm it is possible to prove a slightly stronger statement than Theorem \\ref{theorem:existenceOfBasis}.\n  Let $V \\subsetneq V'$ be subspaces of $\\bbr^n$. Let $\\calb$ be a basis of $V$. Show that $\\calb$ can be extended to a basis $\\calb'$ of $V'$.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\\begin{definition}\n  If a vector space $V$ has a finite basis $\\calb$ then we define\n  \\begin{align*}\n    \\dim V = \\abs{\\calb}\n  \\end{align*}\n  Otherwise we say that $V$ is infinite dimensional.\n\\end{definition}\n\n\\begin{remark}\n  Our proofs about subspaces of $\\bbr^n$ carry over to arbitrary vector spaces verbatim, except the one about existence of basis. For arbitrary vector spaces, what do you think might go wrong with the proof of Theorem \\ref{theorem:existenceOfBasis}?\\footnote{The proof of existence of basis of an arbitrary vector space relies on the Axiom of Choice.}\n\\end{remark}\n\n\n\n\n\n\n\n\n\n\n\n\\begin{lemma}[Under-determined linear system]\n  \\label{theorem:underDeterminedLinearSystem}\n  Consider the following system with $k$ equations and $\\ell$ variables. ($A_{ij}$ are scalar constants and we are solving for the $c_i$'s.)\n  \\begin{align*}\n    A_{11} c_1 + \\dots + A_{1\\ell}c_\\ell  &= 0 \\\\\n    A_{21} c_1 + \\dots + A_{2\\ell}c_\\ell  &= 0 \\\\\n    \\vdots \\\\\n    A_{k1} c_1 + \\dots +  A_{k\\ell}c_\\ell &= 0\n  \\end{align*}\n  If $k < \\ell$, then this system of equations always has a solution such that at least one of the $c_i$'s is non-zero.\n\\end{lemma}\n\\begin{proof}\n  Proof is induction on $k$.\n  \\begin{qbox}\n    \\emph{Base case: }Prove Lemma \\ref{theorem:underDeterminedLinearSystem} for $k = 1$.\n  \\end{qbox}\n  \\emph{Induction hypothesis: }\n  Assume that we know Lemma \\ref{theorem:underDeterminedLinearSystem} to be true when $k = m$.\n\n  \\emph{Induction step: }\n  Consider now $k = m+1$.\n  \\begin{qbox}\n    Argue that if $A_{11} = \\dots = A_{1\\ell} = 0$ then we are done by the induction hypothesis.\n  \\end{qbox}\n  Without any loss of generality, assume that $A_{11} \\neq 0$. Then the first equation gives us\n  \\begin{align*}\n    c_1 = -\\dfrac{c_2 A_{12} + \\dots + c_l A_{1l}}{A_{11}}\n  \\end{align*}\n  \\begin{qbox}\n    Plug this in the other equations and conclude the proof using the induction hypothesis.\n  \\end{qbox}\n\\end{proof}\n\n\\iffalse\n\n\n\n\n\n\n\\subsection{Optional section: Direct sums and direct products}\nGiven a collection of vector spaces $\\set{V_i}_{i \\in I}$, it is possible to construct two vector\\todo{Put this in the linear transformations section.}\n\\begin{definition}\n  The \\emph{direct sum} $\\bigoplus_{i \\in I} V_i$ of the vector spaces $\\set{V_i}_{i \\in I}$ is defined as the collection of finite sums $\\vec{v}_1 + \\dots + \\vec{v}_k$ for $\\vec{v}_j$ in some $V_i$.\n\\end{definition}\n\n\\begin{definition}\n  The \\emph{direct product} $\\prod_{i \\in I} V_i$ of the vector spaces $\\set{V_i}_{i \\in I}$ is defined as the collection of tuples $(\\vec{v}_i)_{i \\in I}$ where $\\vec{v}_i \\in V_i$.\n\\end{definition}\n\n\\begin{qbox}\n  Show that there is a natural linear transformation\n  \\begin{equation*}\n    \\varphi: \\bigoplus_{i \\in I} V_i \\longrightarrow \\prod_{i \\in I} V_i\n  \\end{equation*}\n  which is injective.\n  Further, show that $\\varphi$ is an isomorphism if and only if $I$ is finite.\n\\end{qbox}\n\n\n\n\n\n\n\n\\subsection{Optional section: Infinite dimensional vector spaces}\nThe following theorem requires the axiom of choice to prove.\n\\begin{theorem}\n  Every vector space $V$ has a basis.\n\\end{theorem}\n\\begin{qbox}\n  Try to mimic the proof of Theorem \\ref{theorem:existenceOfBasis}. What goes wrong? Can you think of a way to fix it?\n\\end{qbox}\n\nThis innocent theorem has surprising conquences.\n\\begin{corollary}\n  The space of continuous functions $f: \\bbr \\rightarrow \\bbr$ has a basis.\n\\end{corollary}\n\\begin{corollary}\n  The set of real numbers thought of as a vector space over the rational numbers has a basis. This is called the Hamel basis.\n\\end{corollary}\n% For most of this class you can assume that $V$ is as subspace of $\\bbr^n$.\n%\n% \\begin{qbox}\n%   direct sums\n%   quotients\n% \\end{qbox}\n\\fi\n", "meta": {"hexsha": "2d572ec0e052ac4b26dee38f4e370abc1146f15d", "size": 9976, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02.tex", "max_stars_repo_name": "apurvnakade/mc2019-linear-algebra", "max_stars_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "02.tex", "max_issues_repo_name": "apurvnakade/mc2019-linear-algebra", "max_issues_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "02.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5892255892, "max_line_length": 351, "alphanum_fraction": 0.6587810746, "num_tokens": 3321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.8791467770088163, "lm_q1q2_score": 0.6712142900273173}}
{"text": "\\chapter{Source detection: denoising and background modeling}\n\\label{ch_background}\n\n% \\markright{Source detection: denoising and background modeling}\n\n\\section{Method}\nIn some cases such as for Fermi data, the diffuse emission from the Milky Way  makes a relatively intense background. We have to extract this background in order to detect point sources. This diffuse interstellar emission may be modeled, and we want to use such a background model and incorporate a background removal in our denoising algorithm.\n\nWe note $\\mathbf{Y}$ the data, $\\mathbf{B}$ the background we want to remove, and $d^{(b)}_{j}[k]$ the MS-VSTS coefficients of $\\mathbf{B}$ at scale $j$ and position $k$. We determine the multi-resolution support by comparing $|d_j[k]-d^{(b)}_{j}[k]|$ with $\\kappa \\sigma_j$.\n\nWe formulate the reconstruction problem as a convex constrained minimization problem:\n\n\\begin{equation}\n\\label{bgr_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}\\mathbf{X})_j[k]=(\\mathbf{ \\Phi}^{T}(\\mathbf{Y} - \\mathbf{B}))_j[k] , \\end{array}\\right.\n\\end{split}\n\\end{equation}\n\nThen, the reconstruction algorithm scheme becomes:\n\\begin{eqnarray}\n\\tilde{\\mathbf{X}} = P_{+}[\\mathbf{ X}^{(n)} + \\mathbf{ \\Phi} P_{\\mathcal{M}} \\mathbf{ \\Phi}^{T} (\\mathbf{ Y} - \\mathbf{B} - \\mathbf{ X}^{(n)})] , \\\\\n\\mathbf{X}^{(n+1)} = \\mathbf{ \\Phi}\\text{ST}_{\\lambda_n}[\\mathbf{ \\Phi}^{T}\\tilde{\\mathbf{X}}].\n\\end{eqnarray}\n\n\\begin{figure}[htb]\n\\begin{center}\n\\includegraphics[width=2.9in]{13822fg24.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg25.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg26.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg27.pdf}\n\\caption{Theoretical testing for MS-VSTS + IUWT denoising + background removal algorithm (Algorithm~\\ref{alg3}). View on a single HEALPix face.\n\\emph{Top Left}: Simulated background : sum of two Gaussians of standard deviation equal to 0.1 and 0.01 respectively.\n\\emph{Top Right}: Simulated source: Gaussian of standard deviation equal to 0.01.\n\\emph{Bottom Left}: Simulated poisson data.\n\\emph{Bottom Right}: Image denoised with MS-VSTS + IUWT and background removal.\n}\n\\label{background}\n\\end{center}\n\\end{figure}\nThe algorithm is illustrated by the theoretical study in Figure~\\ref{background}. We denoise Poisson data while separating a single source, which is a Gaussian of standard deviation equal to 0.01, from a background, which is a sum of two Gaussians of standard deviation equal to 0.1 and 0.01 respectively. \n\n\\begin{algorithm}\n\\caption{MS-VSTS + IUWT Denoising + Background extraction}\n\\label{alg3}\n\n\\begin{algorithmic}[1]\n\\REQUIRE $\\quad$ data $a_0:=\\mathbf{Y}$, background $B$, 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] - d^{(b)}_{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 = 1$.\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} (\\mathbf{ Y} - \\mathbf{B} - \\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} = \\frac{N_{\\max} - (n+1)}{N_{\\max} - 1}$.\n\\ENDFOR\n\\STATE Get the estimate $\\hat{\\mathbf{\\Lambda}} = \\mathbf{X}^{(N_{\\max})}$.\n\\end{algorithmic}\n\\end{algorithm}\n\nLike Algorithm~\\ref{alg1}, Algorithm~\\ref{alg3} can be adapted to make multiresolution support adaptation.\n\n\n\\section{Experiment}\n\nWe applied Algorithms~\\ref{alg3} on simulated Fermi data. To test the efficiency of our method, we detect the sources with the SExtractor routine~\\citep{astro:bertin96}, and compare the detected sources with the theoretical sources catalog to get the number of true and false detections. Results are shown on Figures~\\ref{sources} and~\\ref{sourcesreest}. The SExtractor method was applied on the first wavelet scale of the reconstructed map, with a detection threshold equal to 1. It has been chosen to optimise the number of true detections. SExtractor makes $593$ true detections and $71$ false detections on the Fermi simulated map restored with Algorithm~\\ref{alg4} among the $1000$ sources of the simulation. On noisy data, many fluctuations due to Poisson noise are detected as sources by SExtractor, which leads to a big number of false detections (more than 2000 in the case of Fermi data). \n\n\\begin{figure}[htb]\n\\begin{center}\n\\includegraphics[width=2.9in]{13822fg28.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg29.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg30.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg31.pdf} \\hfill\n\\includegraphics[width=2.9in]{13822fg32.pdf}\n\\caption{\\emph{Top Left}: Simulated background model.\n\\emph{Top Right}: Simulated Gamma Ray sources.\n\\emph{Middle Left}: Simulated Fermi data with Poisson noise.\n\\emph{Middle Right}: Reconstructed Gamma Ray Sources with MS-VSTS + IUWT + background removal (Algorithm~\\ref{alg3}) with threshold $5\\sigma_j$.\n\\emph{Bottom}: Reconstructed Gamma Ray Sources with MS-VSTS + IUWT + background removal (Algorithm~\\ref{alg3}) with threshold $3\\sigma_j$.\nPictures are in logarithmic scale.}\n\\label{sources}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\begin{center}\n\\includegraphics[width=2.5in]{13822fg33.pdf} \\hfill\n\\includegraphics[width=2.5in]{13822fg34.pdf} \\hfill\n\\includegraphics[width=2.5in]{13822fg35.pdf} \\hfill\n\\includegraphics[width=2.5in]{13822fg36.pdf} \\hfill\n\\includegraphics[width=2.5in]{13822fg37.pdf}\n\\caption{View of a single HEALPix face from the results of Figure~\\ref{sources}.\\emph{Top Left}: Simulated background model.\n\\emph{Top Right}: Simulated Gamma Ray sources.\n\\emph{Middle Left}: Simulated Fermi data with Poisson noise.\n\\emph{Middle Right}: Reconstructed Gamma Ray Sources with MS-VSTS + IUWT + background removal (Algorithm~\\ref{alg3}) with threshold $5\\sigma_j$.\n\\emph{Bottom}: Reconstructed Gamma Ray Sources with MS-VSTS + IUWT + background removal (Algorithm~\\ref{alg3}) with threshold $3\\sigma_j$.\nPictures are in logarithmic scale.\n}\n\\label{sourcesreest}\n\\end{center}\n\\end{figure}\n\n\n\n\\subsection{Sensitivity to model errors}\n\\begin{table}\n  \\centering\n  \\caption{Percent of true and false detection and signal-noise ratio versus the standard deviation of the Gaussian noise on the background model. \n  }\n  \\begin{tabular}{|c|c|c|c|}\n\\hline\nModel error std dev & $\\%$ of true detect & $\\%$ of false detect & SNR (dB) \\\\\n\\hline\n  0 & $59.3\\%$ & $7.1\\%$ & 23.8 \\\\\n  10 & $57.0\\%$ & $11.0\\%$ & 23.2 \\\\\n  20 & $53.2\\%$ & $18.9\\%$ & 22.6 \\\\\n  30 & $49.1\\%$ & $43.5\\%$ & 21.7 \\\\\n  40 & $42.3\\%$ & $44.3\\%$ & 21.0 \\\\\n  50 & $34.9\\%$ & $39.0\\%$ & 20.3 \\\\\n  60 & $30.3\\%$ & $37.5\\%$ & 19.5 \\\\\n  70 & $25.0\\%$ & $34.6\\%$ & 18.9 \\\\\n  80 & $23.0\\%$ & $28.5\\%$ & 18.7 \\\\\n  90 & $23.6\\%$ & $27.1\\%$ & 18.3 \\\\  \n\\hline\n\\end{tabular}\n  \n  \\label{table1}\n\\end{table}\n\nAs it is difficult to model the background precisely, it is important to study the sensitivity of the method to model errors. We add a stationary Gaussian noise to the background model, we compute the MS-VSTS + IUWT with threshold $3\\sigma_j$ on the simulated Fermi Poisson data with extraction of the noisy background, and we study the percent of true and false detections with respect to the total number of sources of the simulation and the signal-noise ratio ($\\text{SNR} (dB) = 20 \\log (\\sigma_{signal} / \\sigma_{noise})$) versus the standard deviation of the Gaussian perturbation. Table~\\ref{table1} shows that, when the standard deviation of the noise on the background model becomes of the same range as the mean of the Poisson intensity distribution ($\\lambda_{\\text{mean}} = 68.764$), the number of false detections increases, the number of true detections decreases and the signal noise ratio decreases. While the perturbation is not too strong (standard deviation $< 10$), the effect of the model error remains low.\n\n", "meta": {"hexsha": "3c3d362a3afba44197a427c04029c8802c443095", "size": 8183, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/msvst_background.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_background.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_background.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": 59.7299270073, "max_line_length": 1028, "alphanum_fraction": 0.7174630331, "num_tokens": 2639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6712142781473793}}
{"text": "%!TEX root = forallxyyc.tex\n\\chapter[Quick reference]{Quick reference}\n%\\pagestyle{plain}\n\\section{Characteristic Truth Tables}\n\\label{app.CharacteristicTTs}\n\n\\begin{tabular}{c|c}\n\\meta{A} & \\enot\\meta{A}\\\\\n\\hline\nT & F\\\\\nF & T \\\\\n\\phantom{.}\\\\\n\\phantom{.}\n\\end{tabular}\n\\hfill\n\\begin{tabular}{c c|c|c|c|c}\n\\meta{A} & \\meta{B} & $\\meta{A}\\eand\\meta{B}$ & $\\meta{A}\\eor\\meta{B}$ & $\\meta{A}\\eif\\meta{B}$ & $\\meta{A}\\eiff\\meta{B}$\\\\\n\\hline\nT & T & T & T & T & T\\\\\nT & F & F & T & F & F\\\\\nF & T & F & T & T & F\\\\\nF & F & F & F & T & T\n\\end{tabular}\n\n\n\\vfill\n\n\\section{Symbolization}\n\\begin{center}\n\\label{app.symbolization}\n\\begin{tabular*}{\\textwidth}{rl}\n\\multicolumn{2}{c}{\\textsc{Sentential Connectives}}\\\\ \\\\\nIt is not the case that P & $\\enot P$\\\\\nEither P, or Q & $(P \\eor Q)$\\\\\nNeither P, nor Q & $\\enot(P \\eor Q)$\\ or \\ $(\\enot P \\eand \\enot Q)$\\\\\nBoth P, and Q & $(P \\eand Q)$\\\\\nIf P, then Q & $(P \\eif Q)$\\\\\nP only if Q & $(P \\eif Q)$\\\\\nP if and only if Q & $(P \\eiff Q)$\\\\\nP unless Q & $(P \\eor Q)$\\\\\n\\\\\n\\multicolumn{2}{c}{\\label{SymbolizingPredicates}\\textsc{Predicates}}\\\\ \\\\\nAll Fs are Gs & $\\forall x(Fx \\eif Gx)$\\\\\nSome Fs are Gs & $\\exists x(Fx \\eand Gx)$\\\\\nNot all Fs are Gs & $\\enot\\forall x(Fx \\eif Gx)$\\ or\\ $\\exists x(Fx \\eand \\enot Gx)$\\\\\nNo Fs are Gs & $\\forall x(Fx \\eif\\enot Gx)$\\ or\\ $\\enot\\exists x(Fx \\eand Gx)$\\\\\n\\\\\n\\multicolumn{2}{c}{\\textsc{Identity}}\\\\ \\\\\nOnly c is G & $\\forall x(Gx \\eiff x=c)$\\\\\nEverything besides c is G & $\\forall x(\\enot x = c \\eif Gx)$\\\\\n%$j$ is more $R$ than anyone else. & $\\forall x(x\\neq j \\eif Rjx)$\\\\\nThe F is G & $\\exists x(Fx \\eand \\forall y(Fy \\eif x=y) \\eand Gx)$\\\\\nIt is not the case that the F is G & $\\enot\\exists x(Fx \\eand \\forall y(Fy \\eif x=y) \\eand Gx)$\\\\\nThe F is non-G & $\\exists x(Fx \\eand \\forall y(Fy \\eif x=y) \\eand \\enot Gx)$\n\\end{tabular*}\n\\end{center}\n\n\n\n\n\n\n% BEGIN: symbolizing cardinality\n\n\\newpage\n\\section{Using identity to symbolize quantities}\n\n\\subsection*{There are at least \\blank\\ Fs.}\n\\label{summary.atleast}\n\n\\begin{ekey}\n\\item[\\text{one}] $\\exists xFx$\n\\item[\\text{two}] $\\exists x_1\\exists x_2(Fx_1 \\eand Fx_2 \\eand \\enot x_1  = x_2)$\n\\item[\\text{three}] $\\exists x_1\\exists x_2\\exists x_3(Fx_1 \\eand Fx_2 \\eand Fx_3 \\eand \\enot x_1 = x_2 \\eand\\enot x_1 = x_3 \\eand \\enot x_2 = x_3)$\n\\item[\\text{four}] $\\exists x_1\\exists x_2\\exists x_3\\exists x_4 (Fx_1 \\eand Fx_2 \\eand Fx_3 \\eand Fx_4 \\eand \\phantom{x}$\\\\\n\\phantom{$\\exists x_1\\exists x_2$}$\\enot x_1 = x_2 \\eand \\enot x_1 = x_3 \\eand \\enot x_1 = x_4 \\eand \\enot x_2 = x_3 \\eand \\enot x_2 = x_4 \\eand \\enot x_3 = x_4)$\n\\item[n] $\\exists x_1\\ldots\\exists x_n(Fx_1 \\eand\\ldots\\eand Fx_n \\eand \\enot x_1 = x_2 \\eand\\ldots\\eand \\enot x_{n-1} = x_n)$ \n\\end{ekey}\n\n\\subsection*{There are at most \\blank\\ Fs.}\n\\label{summary.atmost}\n\nOne way to say `there are at most $n$ Fs' is to put a negation sign in front of the symbolization for `there are at least $n+1$ Fs'. Equivalently, we can offer:\n\\begin{ekey}\n\\item[\\text{one}] $\\forall x_1\\forall x_2\\bigl[(Fx_1 \\eand Fx_2) \\eif x_1=x_2\\bigr]$\n\\item[\\text{two}] $\\forall x_1\\forall x_2\\forall x_3\\bigl[(Fx_1 \\eand Fx_2 \\eand Fx_3) \\eif (x_1=x_2 \\eor x_1=x_3 \\eor x_2=x_3)\\bigr]$\n\\item[\\text{three}] $\\forall x_1\\forall x_2\\forall x_3\\forall x_4\\bigl[(Fx_1 \\eand Fx_2 \\eand Fx_3 \\eand Fx_4) \\eif \\phantom{.}$\\\\\n\\phantom{$\\exists x_1 \\exists x_2$}$(x_1=x_2 \\eor x_1=x_3 \\eor x_1=x_4 \\eor x_2=x_3 \\eor x_2=x_4 \\eor x_3=x_4)\\bigr]$\n\\item[n]$\\forall x_1\\ldots\\forall x_{n+1}\n\\bigl[(Fx_1\\eand \\ldots \\eand Fx_{n+1}) \\eif (x_1=x_2 \\eor \\ldots \\eor x_n=x_{n+1})\\bigr]$ \n\\end{ekey}\n\n\\subsection*{There are exactly \\blank\\ Fs.}\n\\label{summary.exactly}\n\nOne way to say `there are exactly $n$ Fs' is to conjoin two of the symbolizations above and say `there are at least $n$ Fs and there are at most $n$ Fs.' The following equivalent formulae are shorter:\n\\begin{ekey}\n\\item[\\text{zero}] $\\forall x\\enot Fx$\n\\item[\\text{one}] $\\exists x\\bigl[Fx \\eand \\forall y(Fy \\eif x= y)\\bigr]$\n\\item[\\text{two}] $\\exists x_1\\exists x_2\\bigl[Fx_1 \\eand Fx_2 \\eand \\enot x_1 = x_2 \\eand \\forall y\\bigl(Fy \\eif (y= x_1 \\eor y = x_2)\\bigr) \\bigr]$\n\\item[\\text{three}] $\\exists x_1\\exists x_2\\exists x_3\\bigl[Fx_1 \\eand Fx_2 \\eand Fx_3 \\eand \\enot x_1 =  x_2 \\eand \\enot  x_1 = x_3 \\eand \\enot x_2 = x_3 \\eand \\phantom{.}$\\\\\n\\phantom{$\\exists x_1 \\exists x_2$}$\\forall y\\bigl(Fy \\eif (y = x_1 \\eor y = x_2 \\eor y =  x_3)\\bigr) \\bigr]$\n\\item[n] $\\exists x_1\\ldots\\exists x_n\\bigl[Fx_1 \\eand\\ldots\\eand Fx_n  \\eand \\enot x_1 = x_2 \\eand\\ldots\\eand \\enot x_{n-1}= x_n \\eand \\phantom{.}$\\\\\n\\phantom{$\\exists x_1\\exists x_2$}$\\forall y\\bigl(Fy \\eif (y= x_1 \\eor \\ldots \\eor y= x_n)\\bigr)\\bigr]$ \n%\\item[one] $\\exists x\\forall y\\bigl[Fx \\eand (Fy \\eif y = x)\\bigr]$\n%\\item[two] $\\exists x\\exists y\\forall z\\Bigl(Fx \\eand Fy \\eand \\bigl[Fz \\eif (z=x \\eor z=y)\\bigr] \\eand x \\neq y\\Bigr)$\n%\\item[three] $\\exists x_1\\exists x_2\\exists x_3\\forall y\\Bigl(Fx_1 \\eand Fx_2 \\eand Fx_3 \\eand [Fy \\eif (y=x_1 \\eor y=x_2 \\eor y=x_3)] \\eand x_1 \\neq x_2 \\eand x_1 \\neq x_3 \\eand x_2 \\neq x_3\\Bigr)$\n%\\item[n] $\\exists x_1\\cdots\\exists x_n\\forall y\\Bigl(Fx_1 \\eand\\cdots\\eand Fx_n \\eand \\bigl[Fy \\eif (y=x_1 \\eor \\cdots \\eor y=x_n)\\bigr] \\eand x_1 \\neq x_2 \\eand\\cdots\\eand x_{n-1}\\neq x_n\\Bigr)$ \n\\end{ekey}\n\n\n\\label{ProofRules}\n\\newpage\\section{Basic deduction rules for TFL}\n\\renewenvironment{proof}\n\t{\\noindent\\par\\noindent\\small$\\begin{nd}}\n\t{\\end{nd}$\\noindent\\normalsize\\ignorespacesafterend}\n\n%{\\LARGE \\textbf{Basic Rules of Proof}}\n\\begin{multicols}{2}\n\n\\subsection*{Conjunction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}}\n\t\\have[n]{b}{\\meta{B}}\n\t\\have[\\ ]{c}{\\meta{A}\\eand\\meta{B}} \\ai{a, b}\n\n\t\\have[m]{ab}{\\meta{A}\\eand\\meta{B}}\n\\\\\t\\have[\\ ]{a}{\\meta{A}} \\ae{ab}\n\n\t\\have[m]{ab}{\\meta{A}\\eand\\meta{B}}\n\\\\\t\\have[\\ ]{b}{\\meta{B}} \\ae{ab}\n\\end{proof}\n\n\\subsection*{Conditional}\n\n\\begin{proof}\n\t\\open\n\t\t\\hypo[i]{a}{\\meta{A}}\n\t\t\\have[j]{b}{\\meta{B}}\n\t\\close\n\t\\have[\\ ]{ab}{\\meta{A}\\eif\\meta{B}}\\ci{a-b}\n\n\t\\have[m]{ab}{\\meta{A}\\eif\\meta{B}}\n\\\\\t\\have[n]{a}{\\meta{A}}\n\t\\have[\\ ]{b}{\\meta{B}} \\ce{ab,a}\n\\end{proof}\n\n\\subsection*{Negation}\n\n\\begin{proof}\n\\open\n\t\\hypo[i]{a}{\\meta{A}}\n\t\\have[j]{nb}{\\ered}\n\\close\n\\have[\\ ]{na}{\\enot\\meta{A}}\\ni{a-nb}\n\n\\have[m]{na}{\\enot\\meta{A}}\n\\\\ \\have[n]{a}{\\meta{A}}\n\\have[ ]{bot}{\\ered}\\ri{na, a}\n\\end{proof}\n\n\\subsection*{Indirect proof}\n\n\\begin{proof}\n\\open\n\t\\hypo[i]{a}{\\enot\\meta{A}}\n\t\\have[j]{nb}{\\ered}\n\\close\n\\have[\\ ]{na}{\\meta{A}}\\ip{a-nb}\n\\end{proof}\n\n\n\\subsection*{Explosion}\n\n\\begin{proof}\n\\have[m]{bot}{\\ered}\n\\\\\\have[ ]{}{\\meta{A}}\\re{bot}\n\\end{proof}\n\n\\subsection*{Disjunction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}}\n\t\\have[\\ ]{ab}{\\meta{A}\\eor\\meta{B}}\\oi{a}\n\n\t\\have[m]{a}{\\meta{A}}\n\\\\\t\\have[\\ ]{ba}{\\meta{B}\\eor\\meta{A}}\\oi{a}\n\n\t\\have[m]{ab}{\\meta{A}\\eor\\meta{B}}\n\\\\\t\\open\n\t\t\\hypo[i]{a}{\\meta{A}}\n\t\t\\have[j]{c1}{\\meta{C}}\n\t\\close\n\t\\open\n\t\t\\hypo[k]{b}{\\meta{B}}\n\t\t\\have[l]{c2}{\\meta{C}}\n\t\\close\n\t\\have[\\ ]{c}{\\meta{C}} \\oe{ab,a-c1, b-c2}\n\\end{proof}\n\n\\subsection*{Biconditional}\n\n\\begin{proof}\n\t\\open\n\t\t\\hypo[i]{a1}{\\meta{A}} \n\t\t\\have[j]{b1}{\\meta{B}}\n\t\\close\n\t\\open\n\t\t\\hypo[k]{b2}{\\meta{B}}\n\t\t\\have[l]{a2}{\\meta{A}}\n\t\\close\n\t\\have[\\ ]{ab}{\\meta{A}\\eiff\\meta{B}}\\bi{a1-b1,b2-a2}\n\n\t\\have[m]{ab}{\\meta{A}\\eiff\\meta{B}}\n\\\\\t\\have[n]{a}{\\meta{A}}\n\t\\have[\\ ]{b}{\\meta{B}} \\be{ab,a}\n\n\t\\have[m]{ab}{\\meta{A}\\eiff\\meta{B}}\n\\\\\t\\have[n]{a}{\\meta{B}}\n\t\\have[\\ ]{b}{\\meta{A}} \\be{ab,a}\n\\end{proof}\n\n\\end{multicols}\n\n\\newpage\n\\section{Derived rules for TFL}\n\\begin{multicols}{2}\n\\subsection*{Disjunctive syllogism}\n\\begin{proof}\n\t\\have[m]{ab}{\\meta{A} \\eor \\meta{B}}\n\t\\have[n]{nb}{\\enot \\meta{A}}\n\t\\have[\\ ]{con}{\\meta{B}}\\by{DS}{ab, nb}\n\n\t\\have[m]{ab}{\\meta{A} \\eor \\meta{B}}\n\\\\\t\\have[n]{nb}{\\enot \\meta{B}}\n\t\\have[\\ ]{con}{\\meta{A}}\\by{DS}{ab, nb}\n\\end{proof}\n\n\\subsection*{Reiteration}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}}\n\t\\have[\\ ]{c}{\\meta{A}} \\by{R}{a}\n\\end{proof}\n\n\\subsection*{Modus Tollens}\n\n\\begin{proof}\n\t\\have[m]{ab}{\\meta{A}\\eif\\meta{B}}\n\t\\have[n]{a}{\\enot\\meta{B}}\n\t\\have[\\ ]{b}{\\enot\\meta{A}} \\by{MT}{ab,a}\n\\end{proof}\n\n\\subsection*{Double-negation elimination}\n\t\\begin{proof}\n\t\t\\have[m]{dna}{\\enot \\enot \\meta{A}}\n\t\t\\have[ ]{a}{\\meta{A}}\\dne{dna}\n\t\\end{proof}\n\n\n\\subsection*{Excluded middle}\n\t\\begin{proof}\n\t\t\\open\n\t\t\t\\hypo[i]{a}{\\meta{A}}\n\t\t\t\\have[j]{c1}{\\meta{B}}\n\t\t\\close\n\t\t\\open\n\t\t\t\\hypo[k]{b}{\\enot\\meta{A}}\n\t\t\t\\have[l]{c2}{\\meta{B}}\n\t\t\\close\n\t\t\\have[\\ ]{ab}{\\meta{B}}\\tnd{a-c1,b-c2}\n\t\\end{proof}\n\n%\n%\\subsection*{Hypothetical Syllogism}\n%\n%\\begin{proof}\n%\t\\have[m]{ab}{\\meta{A}\\eif\\meta{B}}\n%\t\\have[n]{bc}{\\meta{B}\\eif\\meta{C}}\n%\t\\have[\\ ]{ac}{\\meta{A}\\eif\\meta{C}}\\by{HS}{ab,bc}\n%\\end{proof}\n\n\\subsection*{De Morgan Rules}\n\\begin{proof}\n\t\\have[m]{ab}{\\enot (\\meta{A} \\eor \\meta{B})}\n\t\\have[\\ ]{dm}{\\enot \\meta{A} \\eand \\enot \\meta{B}}\\dem{ab}\n\n\t\\have[m]{ab}{\\enot \\meta{A} \\eand \\enot \\meta{B}}\n\\\\\t\\have[\\ ]{dm}{\\enot (\\meta{A} \\eor \\meta{B})}\\dem{ab}\n\n\t\\have[m]{ab}{\\enot (\\meta{A} \\eand \\meta{B})}\n\\\\\t\\have[\\ ]{dm}{\\enot \\meta{A} \\eor \\enot \\meta{B}}\\dem{ab}\n\n\t\\have[m]{ab}{\\enot \\meta{A} \\eor \\enot \\meta{B}}\n\\\\\t\\have[\\ ]{dm}{\\enot (\\meta{A} \\eand \\meta{B})}\\dem{ab}\n\\end{proof}\n\\end{multicols}\n\n\\newpage\n\n\\section{Basic deduction rules for FOL}\n\n\\begin{multicols}{2}\n\\subsection*{Universal elimination}\n\n\\begin{proof}\n\t\\have[m]{a}{\\forall \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)}\n\t\\have[\\ ]{c}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)} \\Ae{a}\n\\end{proof}\n\n\\subsection*{Universal introduction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)}\n\t\\have[\\ ]{c}{\\forall \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)} \\Ai{a}\n\\end{proof}\n\n\\medskip\\begin{raggedright}\n\\meta{c} must not occur in any undischarged assumption\n\n\\meta{x} must not occur in\\\\ $\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)$\n\\end{raggedright}\n\n\\subsection*{Existential introduction}\n\n\\begin{proof}\n\t\\have[m]{a}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)}\n\t\\have[\\ ]{c}{\\exists \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{c}\\ldots)}\\Ei{a}\n\\end{proof}\n\n\\medskip\\begin{raggedright}\n\\noindent \\meta{x} must not occur in\\\\ $\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)$\n\\end{raggedright}\n%\\noindent You can replace one or more instance of \\meta{c} with \\meta{x}.\n\n\\subsection*{Existential elimination}\n\n\\begin{proof}\n\t\\have[m]{a}{\\exists \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)}\n\t\\open\t\n\t\t\\hypo[i]{b}{\\meta{A}(\\ldots \\meta{c} \\ldots \\meta{c}\\ldots)}\n\t\t\\have[j]{c}{\\meta{B}}\n\t\\close\n\t\\have[\\ ]{d}{\\meta{B}}\\Ee{a,b-c}\n\\end{proof}\n\n\\medskip\\begin{raggedright}\n\\noindent \\meta{c} must not occur in any undischarged assumption, in $\\exists \\meta{x}\\meta{A}(\\ldots \\meta{x} \\ldots \\meta{x}\\ldots)$, or in \\meta{B}\\end{raggedright}\\vfill\\columnbreak\n\n\\end{multicols}\n\n\\subsection*{Identity introduction}\n\n\\begin{proof}\n\t\\have[\\ \\,\\,\\,]{x}{\\meta{c}=\\meta{c}} \\by{=I}{}\n\\end{proof}\n\n\n\\subsection*{Identity elimination}\n\n\\begin{multicols}{2}\n\\begin{proof}\n\t\\have[m]{e}{\\meta{a}=\\meta{b}}\n\t\\have[n]{a}{\\meta{A}(\\ldots \\meta{a} \\ldots \\meta{a}\\ldots)}\n\t\\have[\\ ]{ea1}{\\meta{A}(\\ldots \\meta{b} \\ldots \\meta{a}\\ldots)} \\by{=E}{e,a}\n\\end{proof}\n\\begin{proof}\n\t\\have[m]{e}{\\meta{a}=\\meta{b}}\n\t\\have[n]{a}{\\meta{A}(\\ldots \\meta{b} \\ldots \\meta{b}\\ldots)}\n\t\\have[\\ ]{ea2}{\\meta{A}(\\ldots \\meta{a} \\ldots \\meta{b}\\ldots)} \\by{=E}{e,a}\n\\end{proof}\n\\end{multicols}\n\n\\begin{minipage}{\\textwidth} % hack to keep section header with table\n\\section{Derived rules for FOL}\n\n\\begin{multicols}{2}\n\\begin{proof}\n\t\\have[m]{ab}{\\forall \\meta{x}\\enot \\meta{A}}\n\t\\have[\\ ]{ac}{\\enot \\exists \\meta{x} \\meta{A}}\\cq{m}\n\n\t\\have[m]{ab}{\\enot \\exists \\meta{x}  \\meta{A}}\n\\\\\t\\have[\\ ]{ac}{\\forall \\meta{x}\\enot\\meta{A}}\\cq{m}\n\\end{proof}\n\\begin{proof}\n\t\\have[m]{ab}{\\exists \\meta{x}\\enot\\meta{A}}\n\t\\have[\\ ]{ac}{\\enot \\forall \\meta{x} \\meta{A}}\\cq{m}\n\n\t\\have[m]{ab}{\\enot \\forall \\meta{x}  \\meta{A}}\n\\\\\t\\have[\\ ]{ac}{\\exists \\meta{x}\\enot \\meta{A}}\\cq{m}\n\\end{proof}\n\\end{multicols}\n\\end{minipage}\n", "meta": {"hexsha": "97f45932f7d19163c5dcc2d1f7d107441f39a821", "size": 11914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "forallx-yyc-quickreference.tex", "max_stars_repo_name": "peasantcore/forallx-yyc", "max_stars_repo_head_hexsha": "7023818f0871d1d4712fd84032b920c73292cc53", "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": "forallx-yyc-quickreference.tex", "max_issues_repo_name": "peasantcore/forallx-yyc", "max_issues_repo_head_hexsha": "7023818f0871d1d4712fd84032b920c73292cc53", "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": "forallx-yyc-quickreference.tex", "max_forks_repo_name": "peasantcore/forallx-yyc", "max_forks_repo_head_hexsha": "7023818f0871d1d4712fd84032b920c73292cc53", "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.1620253165, "max_line_length": 200, "alphanum_fraction": 0.6217055565, "num_tokens": 5409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911056, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.6712142757298621}}
{"text": "\\section{M-estimation}\n\nGeneralization of maximum likelihood estimation. No statistical model needs to be assumed to perform M-estimation.\\\\\n\n\nMedian\n\n\n\\section{Hubert loss}\n\n$h_\\delta (x) = \\begin{cases}  \\frac{x^2}{2} \\quad \\text {if} \\,  \\,  \\left| x \\right| < \\delta \\\\ \\delta ( \\left| x \\right| - \\delta /2 ) \\quad \\text {if} \\,  \\,  \\left| x \\right| > \\delta \\end{cases}.$\n\nthe derivative of Huber's loss is the clip function :\n\n$\\text {clip}_\\delta (x) := \\frac{d}{dx} h_\\delta (x) = \\begin{cases}  \\delta \\quad \\text {if} \\,  \\,  x > \\delta \\\\ x \\quad \\text {if} \\,  \\,  -\\delta \\leq x \\leq \\delta \\\\ -\\delta \\quad \\text {if} \\,  \\,  x < -\\delta \\\\ \\end{cases}$", "meta": {"hexsha": "578145bafb80a0370d8e7710833b90dd19b6fb86", "size": 669, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/M_estimation.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/M_estimation.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/M_estimation.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 44.6, "max_line_length": 234, "alphanum_fraction": 0.600896861, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6711564328131843}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{makeidx}\n\\usepackage{graphicx}\n\\newtheorem{defi}{Definition}\n\\author{moi}\n\\begin{document}\n\\section{Introduction}\nLet $R$ be a unital commutative ring, $(A,\\mu,\\eta)$ an $R$ algebra and $\\alpha \\in \\mathrm{Aut}_{R-\\mathrm{alg}}(A)$. We are interested in certain Ore extension over polynomial rings in multiple variables.\n\\subsection{$\\alpha$ derivations and Ore extensions}\n\\begin{defi}\nWe call a map $\\delta \\in \\mathrm{End}_R(A)$ an $\\alpha$ derivation if\n$$\\delta(a b) = \\alpha(a) \\delta(b) + \\delta(a) b$$\nfor all $a, b \\in A$. Let $\\alpha$ and $\\delta$ be as above, an Ore extension $A[X,\\alpha,\\delta]$ over $A$ is an $A$ algebra with\n$$X a = \\alpha(a) X + \\delta(a)$$\ndefining the $A$ right module structure.\n\\end{defi}\nOur question can be reformulated as given $A = R[x]$, we are interested in all $\\alpha$ derivations on $R[x]$.\n\\subsection{Generator action}\nAs $A$ is spanned by all finite sums of powers over $R$, we get:\n$$\\delta_\\alpha(x^i) = \\alpha(x) \\delta_\\alpha(x^{i-1}) + \\delta_\\alpha(x) x^{i-1}.$$\nTherefore:\n$$\\delta_\\alpha(x^2) = \\alpha(x) \\delta_\\alpha(x) + \\delta_\\alpha(x) x$$\nand in case $A$ is commutative nicely:\n$$(\\alpha + id_A)(x) \\delta_\\alpha(x) = \\delta_\\alpha(x^2)$$\nand generally in a tensorial manner:\n$$(\\alpha \\otimes \\delta_\\alpha + \\delta_\\alpha \\otimes id_A) (x \\otimes x) = \\delta_\\alpha(\\mu_A(x \\otimes x)).$$\nThis shows that $\\delta_\\alpha$ is a $(\\alpha,id_A)$ skew-primitive element in the coalgebra generated by group-likes (algebra automorphisms) and skew-primitive elements (generalized derivations).\n\\paragraph{Example} Let us consider\n$$\\alpha = [x \\longmapsto x - 1] \\in \\mathrm{Aut}_{R-\\mathrm{alg}}(A)$$\nas automorphism. We get\n$$\\begin{array}{rclcl}\n\\delta_\\alpha(x^2) &=& (x - 1) \\delta_\\alpha(x) + x \\delta_\\alpha(x) &=& (2 x - 1) \\delta_\\alpha(x)\\\\\n&&&&\\\\\n\\delta(x^3) &=& (x - 1) \\delta_\\alpha(x^2) + \\delta_\\alpha(x) x^2 &=& (x - 1)(2 x - 1) \\delta_\\alpha(x) + x^2 \\delta_\\alpha(x)\\\\\n&&&&\\\\\n&=& (2 x^2 - 3 x + 1 + x^2) \\delta_\\alpha(x) &=& (3 x^2 - 3 x + 1) \\delta_\\alpha(x)\\\\\n&\\vdots&&\\vdots&\\\\\n\\delta_\\alpha(x^i) &=& (x - 1) \\delta_\\alpha(x^{i-1}) + \\delta_\\alpha(x) x^{i-1} &=& (x^i - (x - 1)^i) \\delta_\\alpha(x^i)\\\\ \n\\end{array}$$\nWe want to show that any $R$ derivation (in sense of Ore extensions, an $id_A$ derivation) can be/can not be extended to $R[x]$ as an $\\alpha$ derivation\n\\end{document}", "meta": {"hexsha": "29ce80ddfdb85f756839dbba604fa39d7badc639", "size": 2506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ore_extend/ore_extend.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": "ore_extend/ore_extend.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": "ore_extend/ore_extend.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": 55.6888888889, "max_line_length": 206, "alphanum_fraction": 0.6612130886, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6711141820158135}}
{"text": "\\section{Additional Background} \\label{preliminaries}\nWe denote the security parameter by $\\lambda$ and use ``$||$'' as concatenation operator \n(i.e., if $a$ and $b$ are two strings then by $a||b$ we denote the concatenation of $a$ and $b$). \nFor a finite set $Q$, $x\\from Q$ denotes a sampling of $x$ from $Q$ \nwith uniform distribution. \nWe use the abbreviation \\ppt\\ that stands for probabilistic polynomial time. We use $\\poly(\\cdot)$\n to indicate a generic polynomial function. \nWhen it is necessary to refer to the randomness $r$ used by and algorithm $A$ we use the following notation: $A(\\cdot;r)$.\nWe say a function $\\negligible$ is {\\em negligible} if for every positive integer $c$ there is an integer $N_c$ such that for all $x > N_c$, $|\\negligible(x)|< 1/x^c$.\nWe say $a \\stackrel{\\text{negl}}{\\leq} b$ for real values $a, b$ to mean that $a \\leq b + \\negligible(\\lambda)$ for negligible function $\\negligible$.\nWe denote with $[n]$ the set  $\\{1,\\dots,n\\}$, with $\\mathbb{F}$ an arbitrary (but fixed) finite field and with $\\mathbb{N}$ the set of non-negative integer.\n\n\n\n\n\n\n\n", "meta": {"hexsha": "bca592835aff4685e534c0b5d4be1b327e4765e4", "size": 1091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/FC20/paper/sections/definitions.tex", "max_stars_repo_name": "MitchellTesla/decentralized-software-updates", "max_stars_repo_head_hexsha": "89f5873f82c0ff438e2cd3fff83cc030a46e29da", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-01-25T19:38:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T02:08:38.000Z", "max_issues_repo_path": "papers/FC20/paper/sections/definitions.tex", "max_issues_repo_name": "MitchellTesla/decentralized-software-updates", "max_issues_repo_head_hexsha": "89f5873f82c0ff438e2cd3fff83cc030a46e29da", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 120, "max_issues_repo_issues_event_min_datetime": "2019-03-06T18:29:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T10:20:09.000Z", "max_forks_repo_path": "papers/FC20/paper/sections/definitions.tex", "max_forks_repo_name": "MitchellTesla/decentralized-software-updates", "max_forks_repo_head_hexsha": "89f5873f82c0ff438e2cd3fff83cc030a46e29da", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-07-18T13:38:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-16T10:39:00.000Z", "avg_line_length": 57.4210526316, "max_line_length": 167, "alphanum_fraction": 0.7002749771, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6711141731074691}}
{"text": "\\input{../header.tex}\n\\title{\\vspace{-2cm}INF3490/INF4490 Exercise Solutions - Representations}\n\\author{Ole Herman S. Elgesem\\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{Representations}\nRecall all the representations that have been presented.\nWhich mutation and recombination operators are compatible with which representations?\\\\\n\n\\textit{Answer:}\n\n\\begin{itemize}\n    \\item Binary representation\n    \\begin{itemize}\n        \\item Bit-flip mutation\n        \\item N-point and uniform crossover\n    \\end{itemize}\n    \\item Integer representation\n    \\begin{itemize}\n        \\item Random reset and creep mutation\n        \\item N-point and uniform crossover\n    \\end{itemize}\n    \\item Cardinal/enumerated/symbolic representations\n    \\begin{itemize}\n        \\item Random reset mutation\n        \\item N-point and uniform crossover\n    \\end{itemize}\n    \\item Real-valued/Continuous representation\n    \\begin{itemize}\n        \\item Uniform and Gaussian mutation\n        \\item N-point, discrete uniform and arithmetic crossover\n    \\end{itemize}\n    \\item Permutation representation\n    \\begin{itemize}\n        \\item Swap, insert, scramble and invert mutation\n        \\item Partially mapped, order, cycle and edge crossover\n    \\end{itemize}\n    \\item Tree representation\n    \\begin{itemize}\n        \\item Mutation by random replacement\n        \\item Subtree swap mutation\n    \\end{itemize}\n\\end{itemize}\n\n\\section{Bit flip mutation}\nGiven the binary chromosome with length 4, calculate the probability that no bits,\none bit and more than one bit will be flipped in a bit-flip mutation with \\(p_m = \\frac{1}{4}\\).\\\\\n\n\\textit{Answer:}\n\nProbability of no mutation:\n\\begin{equation*}\n    P(0) = \\frac{3}{4} \\frac{3}{4} \\frac{3}{4} \\frac{3}{4} = \\frac{3^4}{4^4} \\approx 32\\%\n\\end{equation*}\n\\href{https://en.wikipedia.org/wiki/Binomial_distribution}{Binomial probability}:\n\\begin{equation}\n    P = {n \\choose k} p^k (1-p)^{n-k}\n\\end{equation}\n\\href{https://en.wikipedia.org/wiki/Binomial_coefficient}{Binomial coefficient}:\n\\begin{equation}\n    {n \\choose k} = \\frac{n!}{k!(n-k)!}\n\\end{equation}\nWhere \\(n\\) is number of events,\n\\(k\\) is number of occurences wanted and \\(p\\) is the probability of a single event.\\\\\n\nIn this case we want exactly 1 mutation in 4 events, and the probability is 0.25:\n\\begin{align*}\n    n &= 4\\\\\n    k &= 1\\\\\n    p &= p_m = 0.25\\\\\n    P(1) &= {4 \\choose 1} 0.25^1 (1-0.25)^{4-1}\\\\\n    P(1) &= \\frac{4!}{1!(4-1)!} 0.25^1 (1-0.25)^{4-1}\\\\\n    P(1) &= \\frac{4*3*2}{3*2} 0.25^1 (0.75)^{3}\\\\\n    P(1) &= 4 * 0.25^1 (0.75)^{3}\\\\\n    P(1) &= 0.75^3 \\approx 42\\%\n\\end{align*}\nThis makes intuitive sense and we could also arrive at this result without using the general formula.\nFor example, the probability of mutation (yes,no,no,no) is:\n\\begin{align*}\n    P(1) &= \\frac{1}{4} \\frac{3}{4} \\frac{3}{4} \\frac{3}{4}\\\\\n    P(1) &= 0.25 * 0.75^3\n\\end{align*}\nAnd there are 4 variants, 4 places where the mutation can happen, so:\n\\begin{align*}\n    P(1) &= 4 * (0.25 * 0.75^3)\\\\\n    P(1) &= 0.75^3 \\approx 42\\%\\\\\n\\end{align*}\nFinally, the probability of more than one mutation:\n\\begin{align*}\n    P(2+) &= 1 - P(0) - P(1)\\\\\n    P(2+) &\\approx 1 - 32\\% - 42\\%\\\\\n    P(2+) &\\approx 26\\%\n\\end{align*}\n\n\\section{Crossover \\marginsymbol}\nGiven the sequences (2,4,7,1,3,6,8,9,5) and (5,9,8,6,2,4,1,3,7).\nImplement these algorithms to create a new pair of solutions:\n\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\begin{enumerate}\n  \\item Partially mapped crossover (PMX).\n  \\item Order crossover.\n  \\item Cycle crossover.\n\\end{enumerate}\n\n\\textit{Answer:}\n\n\\subsection{Partially mapped crossover}\n\\subsubsection{Output}\n\\begin{verbatim}\nParents:\n[2, 4, 7, 1, 3, 6, 8, 9, 5]\n[5, 9, 8, 6, 2, 4, 1, 3, 7]\nChildren:\n[5, 9, 7, 1, 3, 6, 4, 2, 8]\n[3, 1, 8, 6, 2, 4, 7, 9, 5]\n\\end{verbatim}\n\\subsubsection{Source code}\n\\inputminted{Python}{pmx.py}\n\\subsection{Order Crossover}\n\\subsubsection{Output}\n\\begin{verbatim}\nParents:\n[2, 4, 7, 1, 3, 6, 8, 9, 5]\n[5, 9, 8, 6, 2, 4, 1, 3, 7]\nChildren:\n[9, 2, 4, 1, 3, 6, 8, 7, 5]\n[7, 3, 8, 6, 2, 4, 1, 9, 5]\n\\end{verbatim}\n\\subsubsection{Source code}\n\\inputminted{Python}{order.py}\n\\subsection{Cycle Crossover}\n\\subsubsection{Output}\n\\begin{verbatim}\nParents:\n[2, 4, 7, 1, 3, 6, 8, 9, 5]\n[5, 9, 8, 6, 2, 4, 1, 3, 7]\nChildren:\n[2, 4, 7, 1, 3, 6, 8, 9, 5]\n[5, 9, 8, 6, 2, 4, 1, 3, 7]\n\\end{verbatim}\n(These 2 parents have just one cycle, so the child will be the same as parent 1).\n\\subsubsection{Source code}\n\\inputminted{Python}{cycle.py}\n\n\\input{../contact.tex}\n\\end{document}\n% ==============================================================================\n", "meta": {"hexsha": "2a0aff26b01c49d368949ab56f9df814bc91be59", "size": 4989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "material/week2/inf3490-sol2.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/week2/inf3490-sol2.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/week2/inf3490-sol2.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": 31.18125, "max_line_length": 101, "alphanum_fraction": 0.6223692123, "num_tokens": 1773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.671110013092385}}
{"text": "\\chapter{Combinatorial}\n\n\\section{The Twelvefold Way}\n\t\\import{twelvefoldway.tex}\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 the number of $n$-permutations whose cycle lengths all belong to the set $S$ be denoted by $g_S(n)$. 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\\[ 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\t\\kactlimport{derangements.h}\n\n\t\\subsection{Involutions}\n\t\tAn involution is a permutation with maximum cycle length 2, and it is its own inverse.\n\t\t$$a(n) = a(n-1) + (n-1)a(n-2)$$\n\t\t$$a(0) = a(1) = 1$$\n\t\t1, 1, 2, 4, 10, 26, 76, 232, 764, 2620, 9496, 35696, 140152\n\n\t\\subsection{Stirling numbers of the first kind}\n\t\t$$s(n,k) = (-1)^{n-k}c(n,k)$$\n\t\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\t$$s(n,k) = s(n-1,k-1) - (n-1) s(n-1,k)$$\n\t\t$$s(0,0) = 1, s(n,0) = s(0,n) = 0$$\n\t\t$$c(n,k) = c(n-1,k-1) + (n-1) c(n-1,k)$$\n\t\t$$c(0,0) = 1, c(n,0)=c(0,n)=0$$\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{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\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\t$$p(n,k) = p(n-1,k-1)+p(n-k,k)$$\n\t\t$$p(0,0)=p(1,n)=p(n,n)=p(n,n-1)=1$$\n\n\t\tFor partitions with any number of parts, $p(n)$ obeys\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\n\t\\subsection{Binomials}\n\t\t\\kactlimport{binomial.h}\n\t\t\\kactlimport{binomialModPrime.h}\n\t\t\\kactlimport{RollingBinomial.h}\n\t\t\\kactlimport{multinomial.h}\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.\n\t\t$$B(n) = \\sum_{k=1}^n \\binom{n-1}{k-1}B(n-k) = \\sum_{k=1}^n S(n,k)$$\n\t\t$$B(0) = B(1) = 1$$\n\t\tThe first are 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597.\n\t\tFor a prime $p$\n\t\t$$B(p^m+n)\\equiv mB(n)+B(n+1) \\pmod{p}$$\n\n\t\\subsection{Triangles}\n\t\tGiven rods of length $1,\\ldots,n$,\n\t\t$$T(n) = \\frac{1}{24} \\left\\{\\begin{array}{ll}n(n-2)(2n-5) & n \\text{ even}\\\\(n-1)(n-3)(2n-1) & n \\text{ odd}\\end{array}\\right.$$\n\t\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\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_{n+1} = \\frac{2(2n+1)}{n+2}C_n$$\n\t\t$$C_0=1, C_{n+1}=\\sum C_iC_{n-i}$$\n\t\tFirst few are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900.\n\t\t\\begin{itemize}\n\t\t\t\\setlength\\itemsep{0pt}\n\t\t\t\\item \\# of monotonic lattice paths of a $n\\times n$-grid which do not pass above the diagonal.\n\t\t\t\\item \\# of expressions containing $n$ pairs of parenthesis which are correctly matched.\n\t\t\t\\item \\# of full binary trees with with $n+1$ leaves (0 or 2 children).\n\t\t\t\\item \\# of non-isomorphic ordered trees with $n+1$ vertices.\n\t\t\t\\item \\# of ways a convex polygon with $n+2$ sides can be cut into triangles by connecting vertices with straight lines.\n\t\t\t\\item \\# of permutations of $[n]$ with no three-term increasing subsequence.\n\t\t\\end{itemize}\n\n\t\\subsection{Super Catalan numbers}\n\t\tThe number of monotonic lattice paths of a $n\\times n$-grid that do not touch the diagonal.\n\t\t$$S(n) = \\frac{3(2n-3)S(n-1)-(n-3)S(n-2)}{n}$$\n\t\t$$S(1)=S(2)=1$$\n\t\t1, 1, 3, 11, 45, 197, 903, 4279, 20793, 103049, 518859\n\n\t\\subsection{Motzkin numbers}\n\t\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\t$$M(n) = \\frac{3(n-1)M(n-2)+(2n+1)M(n-1)}{n+2}$$\n\t\t$$M(0) = M(1) = 1$$\n\t\t1, 1, 2, 4, 9, 21, 51, 127, 323, 835, 2188, 5798, 15511, 41835, 113634\n\n\t\\subsection{Narayana numbers}\n\t\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\t$$N(n,k) = \\frac{1}{n}\\binom{n}{k}\\binom{n}{k-1}$$\n\t\t$$N(n,1) = N(n,n) = 1$$\n\t\t$$\\sum_{k=1}^n N(n,k) = C_n$$\n\t\t1, 1, 1, 1, 3, 1, 1, 6, 6, 1, 1, 10, 20, 10, 1, 1, 15, 50\n\n\t\\subsection{Schröder numbers}\n\t\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\t\t1, 2, 6, 22, 90, 394, 1806, 8558, 41586, 206098\n\n", "meta": {"hexsha": "6c07b9e6054975456f26fad4dfdb214ae99cefa0", "size": 6264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/kactl/combinatorial/chapter.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": "src/kactl/combinatorial/chapter.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": "src/kactl/combinatorial/chapter.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": 47.8167938931, "max_line_length": 290, "alphanum_fraction": 0.5996168582, "num_tokens": 2773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6711100093658763}}
{"text": "\\section{Component segment coordinate transform}\n%\n\\begin{figure}[htb]\n  \\centering\n  % trim left, bottom, right , top\n  \\includegraphics[trim=1cm 1cm 1cm 0.5cm, clip=true,width = 8cm]{gfx/compSegTheo}\n\t\\caption{Illustration for the calculation of the component segment coordinate transformation}\n\t\\label{fig:cs_surf}\n\\end{figure}\n%\nThe coordinate transform of component segment coordinates is somewhat more complicated than the segment coordinate transform. To simplify the procedure, the component segment should consist of only one segment for now. The segment is again defined by its corner points $\\vec p_1 \\dots \\vec p_4$. Figure \\ref{fig:cs_surf} should help understanding the forthcoming calculations. \\par\nFirst we need some definitions:\n\\begin{itemize}\n\t\\item Leading edge:  $ \\vec s_v = \\vec p_2 - \\vec p_1 $\n\t\\item Trailing edge: $ \\vec s_h = \\vec p_4 - \\vec p_3 $\n\t\\item Projected leading edge:   $\\vec n = -\\vec s_v$, with $n_x = 0$  \n\\end{itemize}\n\n\n\\subsection{Extending leading and trailing edges}\nPlane through $\\vec p_4$ with normal vector $\\vec n$. Calculate inersection with leading edge. Plane equation is:\n\\begin{equation}\n(\\vec p - \\vec p_4) \\cdot \\vec n = 0\n\\label{eq:plane}\n\\end{equation}\n Linear equation for the leading edge:\n \n\\begin{equation}\n\\vec p = \\vec p_1 + \\alpha (\\vec p_2 - \\vec p_1)\n\\label{eq:lin_eq1}\n\\end{equation}\n\nInserting (\\ref{eq:lin_eq1}) into (\\ref{eq:plane}) yields:\n\\begin{equation}\n\\alpha_v = \\frac {(\\vec p_4 - \\vec p_1) \\cdot \\vec n }{(\\vec p_2 - \\vec p_1) \\cdot \\vec n}\n\\label{eq:nothing}\n\\end{equation}\n%\nIf $\\alpha_v > 1$, the leading edge has to be extended, else the trailing edge must be extended. In the first case, we calculate the extended leading edge point $\\vec p_2^\\prime$:\n\\begin{equation}\n\\vec p_2^\\prime = \\vec p_1 + \\alpha_v (\\vec p_2 - \\vec p_1)\n\\label{eq:}\n\\end{equation}\n%\nIn the other case ($\\alpha_v < 1$), the intersection point with the trailing edge can be calculated in the same fashion.  \\par\nNow, we apply the same method also to the inner section, getting the extended points $\\vec p_1^\\prime$ and $\\vec p_2^\\prime$.\n\n\\subsection{Calculating $\\eta$ values of the corners}\nFor the following calculations, we need to know the eta coordinates of the corner points $\\vec p_1 \\dots \\vec p_4$. Lets image a plane with the previously defined normal vector $\\vec n$ that goes through one of these points. Without loss of generality, let this point be $\\vec p_3$. This plane is then defined by the equation\n%\n\\begin{equation}\n(\\vec p - \\vec p_3) \\cdot \\vec n = 0\n\\label{eq:plane_p3}\n\\end{equation}\n%\nNow we should find out, at which eta coordinate the plane intersects the leading edge, which is now parametrized as follows:\n\\begin{equation}\np = \\vec p_1^ \\prime + \\eta ({\\vec p_2}^\\prime - {\\vec p_1}^\\prime).\n\\end{equation}\nCombining both equations leads to $\\eta_3 = \\frac {(\\vec p_3 - {\\vec p_1}^\\prime) \\cdot \\vec n }{({\\vec p_2}^\\prime - {\\vec p_1}^\\prime) \\cdot \\vec n}$, or in general:\n\\begin{equation}\n\\eta_i = \\frac {(\\vec p_i - {\\vec p_1}^\\prime) \\cdot \\vec n }{({\\vec p_2}^\\prime - {\\vec p_1}^\\prime)\\cdot \\vec n}.\n\\end{equation}\n\nAfter doing these calculations (which have to be done only once), we can finally proceed to the coordinate transform.\n\n\\subsection{Calculating 3D coordinates of the $(\\eta, \\xi)$ pair}\nThe easiest way to do the transformation is to move first in $\\xi$ direction. As the component segment is straight between the points $(\\vec p_1, \\vec p_3)$ and $(\\vec p_2, \\vec p_4)$ by definition, we move first along these lines:\n\\begin{align}\n\\vec p_{beg}(\\xi) &= (1-\\xi)\\vec p_1 + \\xi \\vec p_3 \\\\\n\\vec p_{end}(\\xi) &= (1-\\xi)\\vec p_2 + \\xi \\vec p_4\n\\end{align}\n\nThe corresponding eta coordinates of the points are \n\\begin{align}\n\\eta_{beg}(\\xi) &= (1-\\xi)\\eta_1 + \\xi \\eta_3 \\\\\n\\eta_{end}(\\xi) &= (1-\\xi)\\eta_2 + \\xi \\eta_4\n\\end{align}\n\nFinally, we walk along the line defined by the new point $\\vec p_{beg}$ and $\\vec p_{end}$ (depicted green in figure \\ref{fig:cs_surf}). We have to keep in mind their eta coordinates (which are not 0 and 1)! We get our final result\n\n\\begin{equation}\n\\vec p(\\eta, \\xi) = \\vec p_{beg} (\\xi) + \\frac {\\eta - \\eta_{beg}(\\xi)}{\\eta_{end}(\\xi) - \\eta_{beg}(\\xi)} \\cdot \\left( \\vec p_{end}(\\xi) - \\vec p_{beg}(\\xi) \\right).\n\\end{equation}", "meta": {"hexsha": "3ed0a0e9bab4e26d891608d6e826bc13558c1b24", "size": 4273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tiglGuide/componentSegmentMath.tex", "max_stars_repo_name": "cfsengineering/tigl", "max_stars_repo_head_hexsha": "abfbb57b82dc6beac7cde212a4cd5e0aed866db8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 171, "max_stars_repo_stars_event_min_datetime": "2015-04-13T11:24:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T00:56:38.000Z", "max_issues_repo_path": "doc/tiglGuide/componentSegmentMath.tex", "max_issues_repo_name": "cfsengineering/tigl", "max_issues_repo_head_hexsha": "abfbb57b82dc6beac7cde212a4cd5e0aed866db8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 620, "max_issues_repo_issues_event_min_datetime": "2015-01-20T08:34:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:05:33.000Z", "max_forks_repo_path": "doc/tiglGuide/componentSegmentMath.tex", "max_forks_repo_name": "cfsengineering/tigl", "max_forks_repo_head_hexsha": "abfbb57b82dc6beac7cde212a4cd5e0aed866db8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2015-02-09T13:33:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T04:52:51.000Z", "avg_line_length": 50.869047619, "max_line_length": 381, "alphanum_fraction": 0.7041890943, "num_tokens": 1368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6711100022072614}}
{"text": "\\section{Class Structure}\r\n\\begin{definition}\r\n    For $i,j\\in I$, we say $i$ leads to $j$ (or sometimes $i\\rightarrow j$) if $\\mathbb P_i[\\exists n,X_n=j]>0$ for some $n$.\\\\\r\n    We say $i$ communicates with $j$ (or sometimes $i\\leftrightarrow j$) if $i\\rightarrow j$ and $j\\rightarrow i$.\r\n\\end{definition}\r\nThis definition, as were most definitions in maths, is motivated by a theorem.\r\n\\begin{theorem}\r\n    For $i\\neq j$ the followings are equivalent:\\\\\r\n    (a) $i\\rightarrow j$.\\\\\r\n    (b) $p_{i_1i_2}\\cdots p_{i_{n-1}i_n}>0$ for some $i_1,\\ldots,i_n$ with $i_1=i$ and $i_n=j$.\\\\\r\n    (c) $p_{ij}^{(n)}>0$ for some $n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Quite obvious.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    The relation $\\leftrightarrow$ is an equivalence relation.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Reflexivity and symmetry are straight from definition.\r\n    Transitivity follows from the preceding theorem.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The equivalence classes of $\\leftrightarrow$ is called the communicating classes of the Markov chain.\\\\\r\n    A Markov chain is irreducible if there is only one communicating class in it.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A subset $C\\subset I$ of the state space is closed if $i\\in C$ and $i\\rightarrow j$ implies $j\\in C$.\\\\\r\n    A state $i\\in I$ is absorbing if $\\{i\\}$ is closed.\r\n\\end{definition}\r\n\\begin{example}\r\n    Take the Markov chain with transition matrix\r\n    $$\\begin{pmatrix}\r\n        1/2&1/2&&&\\\\\r\n        &&1&&&\\\\\r\n        1/3&&&1/3&1/3&\\\\\r\n        &&&1/2&1/2&\\\\\r\n        &&&&&1\\\\\r\n        &&&&1&\r\n    \\end{pmatrix}$$\r\n    By observation, the communicating classes are $\\{1,2,3\\},\\{4\\},\\{5,6\\}$ and only $\\{5,6\\}$ is closed.\r\n\\end{example}", "meta": {"hexsha": "f196a96fcdeb182359bd8e6d4ba5e86244e5e2a6", "size": 1724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/class.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": "2/class.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": "2/class.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": 41.0476190476, "max_line_length": 128, "alphanum_fraction": 0.6316705336, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6710384901934042}}
{"text": "\\chapter{Refining Heuristics}\n\\label{chapter:refining}\nIn this chapter are discussed the heuristic that starting from an initial solution of the TSP, return a better solution in term of cost. This kind of heuristic will be called Refining Heuristics because of the solution cost improvement. \n\n\\section{2-opt} \\label{sec:best_2_opt}\n\nThis heuristic is a simple and effective local search algorithm for TSP problem.\\\\\nA pseudo-code is proposed in alg. \\ref{alg:2opt} to describe how it works. The input parameter $ T $ is an ordered list of edges that define a tour and each edge is represented with an ordered pair of nodes. The \\texttt{swap\\_edges} method remove the two input edges from the tour $ T $ and add the new edges as show in fig. \\ref{fig:2_opt_graph}.\n\n\\begin{algorithm}\n\t\\caption{}\\label{alg:2opt}\n\t\\begin{algorithmic}[1]\n\t\\Procedure{Procedure 2\\_opt}{T}\n\t\t\\State{\\textit{// Variable initialization}}\n\t\t\\State{$ (n_1, n_2), (m_1, m_2) = T[1], T[3] $}\n\t\t\\State{$ (n_1^*, n_2^*), (m_1^*, m_2^*) = (n_1, n_2), (m_1, m_2) $}\n\t\t\\State{$ \\delta_{cost}^* = c_{n_1m_1} + c_{n_2m_2} - c_{n_1n_2} - c_{m_1m_2}  $}\n\t\t\\For{$ (n_1,n_2) \\in T $}\n\t\t\t\\For{$ (m_1,m_2) \\in T $ } \\textit{ // For each pair of edge in the tour}\n\t\t\t\t\\If{$ n_1 == m_1 \\lor n_1 == m_2 \\lor n_2 == m_1 \\lor n_2 == m_2 $}\n\t\t\t\t\t\\State{\\textbf{continue}}\n\t\t\t\t\\EndIf\n\t\t\t\t\\State{$ \\delta_{cost} = c_{n_1m_1} + c_{n_2m_2} - c_{n_1n_2} - c_{m_1m_2} $}\n\t\t\t\t\\If{$ \\delta_{cost} < \\delta_{cost}^* $} \\textit{ // Find 2-opt candidates}\n\t\t\t\t\t\\State{$ \\delta_{cost}^* = \\delta_{cost} $}\n\t\t\t\t\t\\State{$ (n_1^*, n_2^*), (m_1^*, m_2^*) = (n_1, n_2), (m_1, m_2) $}\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\\EndFor\n\t\t\\State{\\texttt{swap\\_edges($ T, (n_1^*, n_2^*), (m_1^*, m_2^*) $)}}\n\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=.3\\columnwidth]{img/2_opt_graph.png}\n\t\\caption{Example graph to explain \\texttt{2\\_opt} method. The input graph is that with continuous edges. \\texttt{2\\_opt} would remove $ (1,4) $ and $ (2,5) $ from the tour and replace them with $ (1,5) $ and $  (2,4) $.}\n\t\\label{fig:2_opt_graph}\n\\end{figure}\nAs can be seen in fig. \\ref{fig:lb_time_grasp_best_two_opt_d2103} multiple execution of \\texttt{2\\_opt} can improve more than 50\\% the cost of the solution before to find a local minimum. This multiple execution of \\texttt{2\\_opt} in the report is called \\texttt{best\\_two\\_opt}.\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=.6\\columnwidth]{../res/lb_time_grasp_best_two_opt_d2103.png}\n\\caption{Solution cost profile of \\texttt{best\\_two\\_opt}. \\texttt{GRASP} solution is used as warm start.}\n\\label{fig:lb_time_grasp_best_two_opt_d2103}\n\\end{figure}\n\nIt is interesting to see the solution cost profile of \\texttt{best\\_two\\_opt} (fig. \\ref{fig:a280_25}) applied to the best of the Greedy solutions (called \\texttt{greedy\\_best\\_two\\_opt}). The improve of the cost solution is considerable even if it stop on a local minimum.  Note that, the best tour is calculated in about $ 8 $s with \\texttt{subtour\\_callback\\_general}, \\texttt{n\\_greedy} take about $ 0.0045 $s to find the best tour and \\texttt{best\\_two\\_opt} find a local minimum in $0.07$s. Moreover is important to consider that greedy method can be easily modify to execute each greedy tour in parallel and than apply \\texttt{best\\_two\\_opt}.\n\nIn fig.s \\ref{fig:a280_10} and \\ref{fig:a280_25} can be compared the \\texttt{Greedy}, \\texttt{greedy\\_best\\_two\\_opt} and \\texttt{subtour\\_callback\\_gen \\\\ eral} tours, solutions cost and execution time.\n\n\\begin{figure}[!h]\n\t\\begin{subfigure}{.5\\columnwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/a280_28.png}\n\t\t\\caption{\\texttt{n\\_greedy\\_10}: cost=3078, time=0.0045s}\n\t\t\\label{fig:a280_10}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.5\\columnwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/a280_25.png}\n\t\t\\caption{\\texttt{n\\_greedy\\_best\\_two\\_opt}: cost=2683, time=0.06s}\n\t\t\\label{fig:a280_25}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.5\\columnwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/lb_greedy_best_two_opt_a280.png}\n\t\t\\caption{\\centering{The profile of the solution cost over time of the \\texttt{best\\_two\\_opt} optimization phase.}}\n\t\t\\label{fig:lb_greedy_best_two_opt_a280}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.5\\columnwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/a280_0.png}\n\t\t\\caption{\\texttt{subtour\\_callback\\_general}: cost=2579, time=8s}\n\t\t\\label{fig:a280_0}\n\t\\end{subfigure}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\centering\n\t\\begin{subfigure}{.95\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lconstructives_refining_LA_time_new.png}\n\t\t\\caption{Solution time domain.}\n\t\t\\label{fig:Lconstructives_refining_time}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.95\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lconstructives_refining_LA_lb_new.png}\n\t\t\\caption{Solution cost domain.}\n\t\t\\label{fig:Lconstructives_refining_lb}\n\t\\end{subfigure}\n\\caption{Performance profiles of refining heuristics.}\n\\label{fig:pp_Lconstructives_refining}\n\\end{figure}\n\nThe performance profile in fig. \\ref{fig:pp_Lgreedy_refining} compare greedy algorithms with their \\texttt{best\\_two\\_opt} optimization. It is clear that most of the execution time is required for the constructive heuristic, however the difference in term of cost optimization is done by the \\texttt{best\\_two\\_opt}. In fig. \\ref{fig:Lgreedy_refining_LA_lb} \\texttt{n\\_greedy\\_best\\_two\\_opt} gain the solution of \\texttt{greedy\\_best\\_two\\_opt}, proving that it is not necessary to find the best tour created from the greedy, but is enough to compute 10 random tour and than apply \\texttt{best\\_two\\_opt} to find similar solutions.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{0.8\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lgreedy_refining_LA_time.png}\n\t\t\\caption{Performance profile in solution cost domain.}\n\t\t\\label{fig:Lgreedy_refining_LA_time}\n\t\\end{subfigure}\n\t\\begin{subfigure}{0.8\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lgreedy_refining_LA_lb.png}\n\t\t\\caption{Performance profile in solution cost domain.}\n\t\t\\label{fig:Lgreedy_refining_LA_lb}\n\t\\end{subfigure}\n\t\\caption{Comparison of constructive (\\texttt{Greedy n\\_greedy}) heuristics and their refining versions of greedy methods.}\n\t\\label{fig:pp_Lgreedy_refining}\n\\end{figure}\n\n\nThe effectiveness of the refining heuristic depend from the warm start solution. In fig. \\ref{fig:Lgrasp_insertion_refining_LA_lb} it is show that, even if \\texttt{heuristic\\_insertion} generate shorter tour than \\texttt{n\\_grasp}, \\texttt{n\\_grasp\\_best\\_two\\_opt} is better than \\texttt{insertion\\_best\\_two\\_opt}, even over time (fig. \\ref{fig:Lgrasp_insertion_refining_LA_time}).\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}{0.9\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/Lgrasp_insertion_refining_LA_time_new.png}\n\t\\caption{Performance profile in solution cost domain.}\n\t\\label{fig:Lgrasp_insertion_refining_LA_time}\n\\end{subfigure}\n\\begin{subfigure}{0.9\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/Lgrasp_insertion_refining_LA_lb_new.png}\n\t\\caption{Performance profile in solution cost domain.}\n\t\\label{fig:Lgrasp_insertion_refining_LA_lb}\n\\end{subfigure}\n\\caption{Comparison of \\texttt{n\\_grasp} and \\texttt{heuristic\\_insertion} with and without \\texttt{best\\_two\\_opt}.}\n\\label{fig:pp_Lgrasp_insertion_refining}\n\\end{figure}\n\nIn conclusion, \\texttt{best\\_two\\_opt} is a really useful refining heuristic for its time efficiency and cost effectiveness, however the second one depends from how many cross edges has the warm start solution.", "meta": {"hexsha": "49c7e6a058061d51a11aa4152ff1770756e27f9b", "size": 7698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/refining-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/refining-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/refining-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": 55.7826086957, "max_line_length": 650, "alphanum_fraction": 0.7474668745, "num_tokens": 2540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.6710384895769324}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage{amsmath,amsthm}\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\\usepackage{color}\n\\usepackage{graphicx}\n\n\\pagestyle{myheadings}\n\\markboth{Eye See You}{Eye See You}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Eye See You\n\\end{center}\n\nWe have used least-squares fitting to create functions of a single variable, $y=f(t)$, which can be plotted as a curve to represent data. Some curves, however, cannot be represented as a single function. A more flexible representation is a parametric curve: \n\\begin{equation}\n  \\label{eq:1}\n  x = f(t), \\qquad y = g(t).\n\\end{equation}\nGiven points in the plane as $(x_i,y_i)$, we can separately fit them as functions of a third parametric variable $t$ and use the curve $(f(t),g(t))$ to pass near the points. \n\n\\subsection*{Preparation}\n\nRead section 3.1. \n\n\\subsection*{Goals}\n\nYou will capture an image of an eye and find points along the top and bottom eyelids, then do two least-squares fits to represent the eyelids as curves. Because both $x$ and $y$ are periodic as you go around the eye once, you will use periodic functions for the least-squares fitting implied in equation~(1):\n\\begin{align}\n  f(t) &= b_1 + b_2 \\cos(2\\pi t) + b_3 \\cos(4\\pi t) + b_4 \\cos(6\\pi t)  + b_5 \\sin(2\\pi t) + b_6 \\sin(4\\pi t) + b_7 \\sin(6\\pi t),\\label{eq:2x} \\\\\n  g(t) &= c_1 + c_2 \\cos(2\\pi t) + c_3 \\cos(4\\pi t) + c_4 \\cos(6\\pi t)  + c_5 \\sin(2\\pi t) + c_6 \\sin(4\\pi t) + c_7 \\sin(6\\pi t). \\label{eq:2y}\n\\end{align}\n\n\n\\subsection*{Procedure}\n\nDownload the template script and edit it to perform the following steps.\n\n\\begin{enumerate}\n\\item Using a phone, take a picture of an open eye (your own or someone else's). Load the image into MATLAB using \\texttt{imread} and display it using \\texttt{image}. \n\\item Enter the command \n\\begin{verbatim}\n[xup,yup] = ginput(10);\n\\end{verbatim}\nThis will create a crosshair in the image window. Click at ten roughly\nevenly spaced points along the upper eyelid \\textbf{from right to left}. Get close to the corners of the eye, but don't put points on the corners. Afterward both \\texttt{xup} and \\texttt{yup} will be $10\\times 1$ vectors representing the selected points. \n\\item Repeat step 2 using \\verb+[xlo,ylo] = ginput(10)+ and clicking\n  along the lower eyelid \\textbf{from left to right}.\n\\item Stack \\texttt{xup} and \\texttt{xlo} into a vector \\texttt{x},\n  and stack \\texttt{yup} and \\texttt{ylo} into a vector \\texttt{y}. Both of these should be $20\\times 1$. On top of your eye image, plot the points $(x_i,y_i)$ using \\texttt{'o'} markers. (If the points don't lie close to the eyelids, you have done something wrong.)  \n\\item Now let \\texttt{t} be a $20\\times 1$ vector where $t_i=(i-1)/20$ for $i=1,\\ldots,20$. Referring back to equations~\\eqref{eq:2x} and~\\eqref{eq:2y}, create a $20\\times 7$ matrix \\texttt{A} whose columns are the values of the functions $1$, $\\cos(2\\pi t)$, and so on, through $\\sin(6\\pi t)$. \n\\item Apply linear least squares (using backslash) to solve for the coefficients $b_j$ in~(2) using the \\texttt{x} data, and to solve for the coefficients $c_j$ in~(3) using the \\texttt{y} data. \n\\item Evaluate the functions in~\\eqref{eq:2x} and~\\eqref{eq:2y} at 500 equally spaced values of $t$ between 0 and 1. On top of the axes showing the eye image and the selected points, and using the coefficients from the previous step, plot the curve defined by equation~\\eqref{eq:1}. \n\\end{enumerate}\n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "eaaeb4915c9af50a7ade383326bf53c7b75b6ee2", "size": 3557, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter03/EyeSeeYou/EyeSeeYou.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/chapter03/EyeSeeYou/EyeSeeYou.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/chapter03/EyeSeeYou/EyeSeeYou.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": 52.3088235294, "max_line_length": 308, "alphanum_fraction": 0.7163339893, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6710384892241844}}
{"text": "% Created 2016-04-06 ons 13:25\n% Intended LaTeX compiler: pdflatex\n\\documentclass{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\\author{Kjartan Halvorsen}\n\\date{Due 2016-03-21}\n\\title{Computerized control - homework 3}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Computerized control - homework 3},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 24.5.1 (Org mode 8.3.4)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section*{The system}\n\\label{sec:orgheadline1}\nA feedback system for level control of a tank is shown in the figure below.\n\\begin{center}\n\\includegraphics[width=\\linewidth]{tank-system-crop}\n\\caption{Feedback system for level control. Alla variables are variations from a working point. Water is pumped from the water tank as needed by some industrial process downstream.}\n\\end{center}\nThe flow of water, \\(x(t)\\) does not change immediately with a change of input \\(u(t)\\) to the valve, but reacts as a first order system\n\\[ \\frac{dx}{dt} = -2x + 4u. \\]\nThe flows \\(x(t)\\) and \\(v(t)\\) has the dimension \\unit{}{\\meter\\cubed\\per\\second}.\n\nThe PID controller has transfer function \n\\[ F(s) = K_P + sK_D + \\frac{K_I}{s}. \\]\n\n\\section*{Exercises}\n\\label{sec:orgheadline7}\n\\subsection*{Problem 1}\n\\label{sec:orgheadline2}\nDraw a block diagram of the system, and derive the transfer function for the closed-loop system\n\\[ Y(s) = G_c(s)Y_{ref}(s) - S(s)V(s) = \\frac{G_1(s)G_2(s)F(s)}{1 + G_1(s)G_2(s)F(s)} Y_{ref}(s) - \\frac{G_1(s)}{1 + G_1(s)G_2(s)F(s)}V(s), \\]\nwhere\n\\begin{align}\nG_1(s) &= \\frac{2}{s}\\\\\nG_2(s) &= \\frac{4}{s+2}.\n\\end{align}\n\n\\subsection*{Problem 2}\n\\label{sec:orgheadline3}\nShow that the transfer function from the outlet \\(-v(t)\\) to the variation in the water level \\(y(t)\\) is given by \n\\[ S(s) = \\frac{2s(s+2)}{s^3 + (2+8K_D)s^2  + 8K_Ps + 8K_I}. \\]\n\n\\subsection*{Problem 3}\n\\label{sec:orgheadline4}\nConsider the three different settings of the PID-controller in the table below. Pair each of the settings with the correct pole-zero plot of \\(S(s)\\) and the correct response of the water level to a step in \\(v(t)\\). \n\n\\begin{center}\n\\begin{tabular}{lrrr}\n & \\(K_P\\) & \\(K_I\\) & \\(K_D\\)\\\\\n\\hline\nI & 2 & 0 & 0\\\\\n\\hline\nII & 4 & 1 & 0\\\\\n\\hline\nIII & 2 & 2 & 1\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\includegraphics[width=\\linewidth]{tank-system-step-response}\n\n\\subsection*{Problem 4}\n\\label{sec:orgheadline5}\nAssume that there is a small delay of \\(T_d=\\unit{0.1}{\\second}\\) in the feedback path of the controller. Tune the PID controller using the Ziegler-Nicholls ultimate sensitivity method (Table 8.3 in Å\\&W). To do this, you need to implement the feedback system in matlab using a P-controller. Do step-responses, and crank up the gain of the P-controller until you get sustained oscillations. The corresponding gain is the so-called \\emph{ultimate gain} \\(K_u\\). Find the period of the oscillations, \\(T_u\\), at this gain. From these two values you can determine the PID controller parameters from Table 8.3.\n\nHere is some matlab code to get you started\n\\begin{verbatim}\n% The plant model\nTd = 0.1;\ns = tf('s');\nG1 = 2/s;\nG2 = 4/(s+2);\nG = G1*G2\n\n% Set D and I gain to zero and try different values of the proportional \n% gain of the controller\nKi = 0;\nKd = 0;\nKp = 2\nF = Kp + s*Kd + Ki/s;\n\n% The loop gain and closed loop system\nGo = G*F;\nGc = feedback(Go,exp(-Td*s)); % Note the delay in the feedback path\n\n% Step response\nfigure(1)\nclf\nstep(Gc, 10)\n\\end{verbatim}\n\n\\textbf{Include a step response with the PID parameters you found!}\n\n\\subsection*{Problem 5}\n\\label{sec:orgheadline6}\n\\begin{enumerate}\n\\item Discretize your PID controller for general sampling period \\(h\\) using Tustin's formula.\n\\item Simulate the discretized model in matlab using a sampling period that is equal to the time delay \\(T_d\\). Here is some code to help:\n\\begin{verbatim}\nGd = c2d(G, Td, 'zoh'); % Discretize plant model to be able to simulate\nFd = c2d(F, Td, 'tustin')\nGod = Gd*Fd;\nGcd = feedback(God,tf([1],[1 0], Td)); % Note the delay in the feedback path\n\n% Step response\nfigure(1)\nclf\nstep(Gc, Gcd, 10)\n\\end{verbatim}\n\\textbf{Include the step response in your report.}\n\\item Discuss in 2-4 sentences the difference between the response using the continuous PID controller and the discretized PID controller.\n\\end{enumerate}\n\\section*{Solutions}\n\\label{sec:orgheadline16}\n\\subsection*{Problem 1}\n\\label{sec:orgheadline8}\n\\begin{tikzpicture}[node distance=2.6cm, block/.style={rectangle, draw, minimum height=15mm, minimum width=20mm}, sumnode/.style={circle, draw, inner sep=1pt}]\n\n  \\node[coordinate] (input) {};\n  \\node[sumnode, right of=input] (sum) {$\\sum$};\n  \\node[block, right of=sum] (control) {PID};\n  \\node[block, right of=control, node distance=3.1cm] (valve) {$G_2$};\n  \\node[sumnode, right of=valve] (sumdist) {$\\sum$};\n  \\node[block, right of=sumdist] (tank) {$G_1$};\n  \\node[coordinate, right of=tank] (output) {};\n  \\draw[->] (tank) -- node[coordinate] (measure) {} node[above, pos=0.9] {$y$} (output);\n\n  \\node[coordinate, above of=sumdist, node distance=2cm] (dist) {};\n\n  \\draw[->] (input) -- node[above, pos=0.2] {$y_{ref}$} (sum);\n  \\draw[->] (sum) -- node[above] {$e$} (control);\n  \\draw[->] (control) -- node[above] {$u$} (valve);\n  \\draw[->] (valve) -- node[above] {$x$} (sumdist);\n  \\draw[->] (dist) -- node[left]{$v$} node[right, pos=0.9] {$-$} (sumdist);\n  \\draw[->] (sumdist)  to (tank);\n  \\draw[->] (measure) |- ++(-2cm, -2cm) -| node[pos=0.97, right] {$-$} (sum);\n\\end{tikzpicture}\n\nTransform the signals to the Laplace-domain and write the PID controller as the transfer function \\(F(s)\\). \n\\begin{equation*}\n \\begin{split}\n  Y &= G_1(X-V) = G_1(G_2FE-V) = G_1\\big(G_2F(Y_{ref}-Y)-V\\big)\\\\\n  (I + G_1G_2F) Y &= G_1G_2FY_{ref} - G_1V\\\\\n   Y &= \\underbrace{\\frac{G_1G_2F}{1 + G_1G_2F}}_{G_c(s)} Y_{ref} - \\underbrace{\\frac{G_1}{1 + G_1G_2F}}_{S(s)}V\n \\end{split}\n\\end{equation*}\n\\subsection*{Problem 2}\n\\label{sec:orgheadline9}\nSubstituting \\(F(s) = K_P + sK_D + K_I/s\\), \\(G_1(s)= 2/s\\) and \\(G_2(s) = 4/(s+2)\\) into the expression for \\(S(s)\\) gives\n\\begin{equation*}\n \\begin{split}\n S(s) &= \\frac{2/s}{1 + \\frac{2}{s}\\frac{4}{s+2}(K_P + sK_D + K_I/s)}\\\\\n      &= \\frac{2(s+2)}{s(s+2) + 8(K_P + sK_D + K_I/s)}\\\\\n      &= \\frac{2s(s+2)}{s^2(s+2) + 8K_Ds^2 + 8K_Ps + 8K_I}\\\\\n      &= \\frac{2s(s+2)}{s^3 + (2 + 8K_D)s^2 + 8K_Ps + 8K_I}\n \\end{split}\n\\end{equation*}\n\n\\subsection*{Problem 3}\n\\label{sec:orgheadline13}\n\\subsubsection*{Setting I - P control}\n\\label{sec:orgheadline10}\nSetting I is pure proportional control, so \\(K_D=K_I=0\\). This gives\n\\[ S(s) = \\frac{2s(s+2)}{s^3 + 2s^2 + 8K_Ps} = \\frac{2(s+2)}{s^2 + 2s + 16} \\]\nwith one zero at \\(s=-2\\) and two complex-conjugated poles in \\(s = -1 \\pm 3.873i\\). This must correspond to the zero-pole plot \\textbf{B}. The step response will have a stationary error, since there is no zero in the origin. This corresponds to the \\textbf{dotted line}.\n\\subsubsection*{Setting II - PI control}\n\\label{sec:orgheadline11}\nSetting II gives the transfer function\n\\[ S(s) = \\frac{2s(s+2)}{s^3 + 2s^2 + 8K_Ps + 8K_I} = \\frac{2s(s+2)}{s^3 + 2s^2 + 32s + 8}\\]\nwith zeros at -2 and in the origin and poles in \\(s=-0.2535\\) and \\(s = -0.8732 \\pm 5.549i\\). This must correspond to the zero-pole plot \\textbf{A}. The PI controller has higher gain compared to the P controller with setting I, and an integrating term, which gives the two fast poles with small damping. We also have a dominating pole close to the origin, which gives a slow response. Hence, the corresponding step-response must be the \\textbf{dashed line}.\n\\subsubsection*{Setting III - PID control}\n\\label{sec:orgheadline12}\nBy elimination, we now have that this corresponds to zero-pole plot \\textbf{C} and the \\textbf{solid line} in the step-response. This can also be seen by calculating the poles of the transfer function\n\\[ S(s) = \\frac{2s(s+2)}{s^3 + 10s^2 + 16s + 16}.\\]\nThe poles are \\(s=-8.3055\\) and \\(s = -0.8472 \\pm 1.0994i\\). The response has reasonable damping.\n\\subsection*{Problem 4}\n\\label{sec:orgheadline14}\nTrying a few different values for \\(K_P\\) leads to \\(K_u = 2.58\\). A step-response of the closed-loop system with this ultimate gain is shown below\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{ultimate_period_hw3_spring16}\n\\end{center}\n\nUsing table 8.3 in Å\\&W, we get the PID controller\n\\[F(s) = K(1 + \\frac{1}{T_is} + T_ds) = 0.6K_u(1 + \\frac{1}{0.5T_us} + 0.125T_us) = 1.548\\big(1 + \\frac{1}{0.725s} +  0.1812 s\\big). \\]\n\nThe step response of the closed-loop system (also with discretized controller) is shown below.\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{tuned_response_hw3_spring16}\n\\end{center}\n\n\\subsection*{Problem 5}\n\\label{sec:orgheadline15}\n\\begin{enumerate}\n\\item Discretizing the controller using Tustin's approximation gives\n\\begin{equation*}\n\\begin{split}\n F_d(z) &= F(s)|_{s=\\frac{2}{h}\\frac{z-1}{z+1}}\\\\\n       &= 1.548 \\frac{0.1812s^2 + s +1/0.725}{s}|_{s=\\frac{2}{h}\\frac{z-1}{z+1}}\\\\\n       &= 1.548 \\frac{0.1812 \\left( \\frac{2}{h}\\frac{z-1}{z+1} \\right)^2 + \\frac{2}{h}\\frac{z-1}{z+1} + 1.3793}{\\frac{2}{h}\\frac{z-1}{z+1}}\\\\  \n       &= 1.548 \\frac{0.1812 \\frac{4(z-1)^2}{h(z+1)} + 2(z-1) + 1.3793 h(z+1)}{2(z-1)}\\\\\n       &= 1.548 \\frac{0.7248 (z-1)^2 + 2h(z-1)(z+1) + 1.3793 h^2(z+1)^2}{2h(z-1)(z+1)}\\\\\n       \\end{split}\n\\end{equation*}\n\\item Discretizing the controller and doing a step-response test gives the figure already shown above under Problem 4.\n\\item The discretized controller gives a system with less damping. The discretization involves a sample-and-hold, which gives a time-delay of approximately \\(h/2\\). This explains the smaller damping. The discretization of the controller is an approximation, so we cannot expect better performance with the discrete controller, but as the sampling period dicreases, the performance will be closer to that of the contninuous controller. This is illustrated in the figure below. \n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{tuned_response_half_h_hw3_spring16}\n\\end{center}\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "3974bed6cdc875adc3db7d08eddb6e2c2e202029", "size": 10306, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework/historical/hw3-spring16.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/hw3-spring16.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/hw3-spring16.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": 44.6147186147, "max_line_length": 606, "alphanum_fraction": 0.688433922, "num_tokens": 3627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6710384796770076}}
{"text": "\n\n\n\\chapter{Electromagnetism}\n\nThe scope of Electricity and Magnetism is almost undoubtably the most broadly reaching field within Physics, describing everything from   why the sky is blue, to how we can send radio signals across the world, to why you can see yourself in a mirror. Somehow this huge array of phenomena stem entirely from just \\emph{four} basic laws, called Maxwell's equations.\n\n\n\n\n\\section{Maxwell's Equations}\n\n\n\\subsection{Gauss's Law}\\label{gauss}\nThe electric field is an abstraction that tells us how a charge would move if it is in it's presence, with\n\\begin{align}\n    \\textbf{F} = q\\textbf{E}\n\\end{align}\nGauss' law tells us that the divergence of the electric field at any point, is equal to the charge density at that point, divided by some constant\n\\begin{align}\n    \\nabla\\cdot\\textbf{E} = \\frac{\\rho}{\\epsilon_0}\n\\end{align}\nThis equation is easier to interpret in integral form. With\n\\begin{align}\n    \\int dV~ \\nabla\\cdot\\textbf{E} &= \\int dV~\\frac{\\rho}{\\epsilon_0}\\\\\n    \\int d\\textbf{A}\\cdot\\textbf{E} &= \\frac{Q_{enc}}{\\epsilon_0}\n\\end{align}\n\nThis equation says that if you add up the electric field going straight through every bit of area on some given surface, you will always find exactly the amount of charge that is in the volume enclosed by that surface. This quantity is also sometimes called the electric flux\n\\begin{align}\n    \\int d\\textbf{A}\\cdot\\textbf{E} = \\Phi_E\n\\end{align}\n\n\\subsection{No Monopoles}\nThis law doesn't really have a name, but is just simply a fact that there happen to experimentally be no magnetic charges\n\\begin{align}\n    \\nabla\\cdot\\textbf{B} = 0\n\\end{align}\nOr in integral form\n\\begin{align}\n    \\int d\\textbf{A}\\cdot\\textbf{B} &= 0\n\\end{align}\n\n\n\\subsection{Ampere's Law}\nTypically thought of as current generates a magnetic field. In differential form\n\\begin{align}\n    \\nabla\\times\\textbf{B} = \\mu_0\\textbf{J} +\\mu_0\\epsilon_0\\frac{d\\textbf{E}}{dt}\n\\end{align}\nWhere $\\textbf{J}$ is the current density, or current per unit area, and points in the direction that the positive current goes. The extra factor with $\\textbf{E}$ is called the \\emph{displacement current}, and accounts for times when we have current entering a surface, but the current has no place to go (such as current going onto a capacitor), but we still need to satisfy Gauss' law. In integral form we have\n\\begin{align}\n    \\int \\textbf{B}\\cdot d\\textbf{l} = \\mu_0 I + \\mu_0\\epsilon_0\\frac{d\\Phi_E}{dt}\n\\end{align}\n\n\n\n\\subsection{Faraday's Law}\nFaraday's law says that if we have a changing magnetic field, we will get an electric field that is created by it. In differential form\n\\begin{align}\n    \\nabla\\times\\textbf{E} = -\\frac{d\\textbf{B}}{dt}\n\\end{align}\nIn integral form, we can see how the voltage is generated, with\n\\begin{align}\n    \\int \\textbf{E}\\cdot d\\textbf{l} = V =  -\\frac{d\\Phi_B}{dt}\n\\end{align}\nWhere $\\Phi_B$ is the magnetic flux, and has the same form as the electric flux.\n\n\n\\section{Electrostatics}\nUsing the definition of the electric field in electrostatics\n\\begin{align}\n\\textbf{E}(\\textbf{r}) = -\\nabla \\varphi(\\textbf{r})\n\\end{align}\nTo arrive at Poisson's equation\n\\begin{align}\n\\nabla^2\\varphi(\\textbf{r}) = -\\rho(\\textbf{r})/\\epsilon_0\n\\end{align}\nWe can use Green's functions (Section \\ref{green}) to solve the the differential equation, looking first for \n\\begin{align}\n\\nabla^2 G(\\textbf{r},\\textbf{r}') = \\delta(\\textbf{r}-\\textbf{r}')\n\\end{align}\nBut we found something that solves that equation before with Equation \\ref{dirac} (after adjusting constants) so we can write the \\emph{free space} Green's function as\n\\begin{align}\nG(\\textbf{r},\\textbf{r}') = \\frac{-1}{4\\pi|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nIn the formulation of Green's functions, we have\n\\begin{align}\\label{potential}\n\\varphi(\\textbf{r}) = \\frac{-1}{\\epsilon_0}\\int dr'^3  G(\\textbf{r},\\textbf{r}') \\rho(\\textbf{r}') = \\frac{1}{4\\pi\\epsilon_0}\\int d^3\\textbf{r}' \\frac{\\rho(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nThis is the quintessential equation used in Electrostatics, and from here we do things like expand it with Legendre Polynomials and Spherical Harmonics, etc. to get rid of the bottom term which makes things difficult to integrate.\n\n\\subsection{Green's Reciprocity Theorem}\nNormal electrostatic energy is defined by adding up all of the charges of one subset ($1$) multiplied by their potential at their given location created by another subset of charges ($2$). In integral form, the potential energy $V$ needed to put the set of charges in the given potential is\n\\begin{align}\nV = \\int dr^3 \\varphi_1(\\textbf{r})\\rho_2(\\textbf{r}) \n\\end{align}\nA nice consequence of the Green's function solution to the potential is that we can rewrite this equation with\n\\begin{equation}\n\\int dr^3 \\varphi_1(\\textbf{r})\\rho_2(\\textbf{r}) = \\int dr^3 \\int dr'^3 \\frac{\\rho_2(\\textbf{r}')\\rho_1(\\textbf{r})} {|\\textbf{r}-\\textbf{r}'|} = \\int dr^3 \\varphi_2(\\textbf{r})\\rho_1(\\textbf{r}) \n\\end{equation}\nWhich is nice if the charge distribution from one set is easy to find, but not so easy the other way, we can swap which one we want to integrate over and the energy will be the same. This lets us find an unknown potential or charge distribution using tricks if we have somewhere that one of the potentials is zero, making the integrand zero. The \\emph{total} electrostatic energy required to assemble the entire thing from nothing is given by\n\\begin{align}\nU_T = \\frac{1}{2} \\int dr^3 \\varphi (\\textbf{r})\\rho(\\textbf{r}) = \\frac{1}{2}\\epsilon_0\\int dr^3 |\\textbf{E}(\\textbf{r})|^2\n\\end{align}\nUsing now the entire distribution and ensuring we don't double count with the extra factor of 1/2. Integration by parts gives us the expression in terms of $\\textbf{E}$.\n\n\n\n\\subsection{Multipole Expansion}\nIf we have that the point of observation $\\textbf{r}$ is much farther than the location of the source $\\textbf{r}'$, we can Taylor expand the denominator in equation \\ref{potential} and get\n\\begin{align}\n\\frac{1}{|\\textbf{r}-\\textbf{r}'|} = \\frac{1}{r} - \\textbf{r}'\\cdot\\nabla\\frac{1}{r} + \\frac{(\\textbf{r}'\\cdot\\nabla)^2}{2!}\\frac{1}{r} - ...\n\\end{align}\nRewriting the potential, we get something kind of nasty\n\\begin{align}\n\\varphi(\\textbf{r}) &= \\frac{1}{4\\pi\\epsilon_0}\\int d^3\\textbf{r}' \\frac{\\rho(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|} = \\frac{1}{4\\pi\\epsilon_0}\n\\Big(\\frac{Q}{r} + \\frac{\\textbf{p}\\cdot\\textbf{r}}{r^3} + Q_{ij}\\frac{3r_ir_j-r^2\\delta_{ij}}{r^5} + ...\\Big)\n\\end{align}\nWhere the first term in the last expansion is the monopole moment, followed by the dipole moment, defined as \n\\begin{align}\n\\textbf{p} \\equiv \\int dr^3 \\rho(\\textbf{r}) \\textbf{r} = \\sum q_i\\textbf{r}_i\n\\end{align}\nWhich is just the vector sum of all of the charges multiplied by their coordinate, analogous to a calculation for center of mass. We can find the form of the electric field of a dipole using tensor notation with\n\\begin{align}\n\\textbf{E}_{dip} = -\\nabla V_{dip} &= -\\frac{1}{4\\pi\\epsilon_0}\\partial_j \\frac{p_ir_i}{r^3}\\\\\n&= - \\frac{1}{4\\pi\\epsilon_0}\\Big[\\frac{p_i}{r^3}\\partial_jr_i + p_ir_i\\partial_j\\frac{1}{r^3}\\Big]\\\\\n&= -\\frac{1}{4\\pi\\epsilon_0} \\Big[\\frac{p_i}{r^3}\\delta_{ij} -\\frac{3p_ir_ir_j}{r^5}\\Big]\\\\\n&= \\frac{1}{4\\pi\\epsilon_0} \\frac{3(\\textbf{p}\\cdot\\hat{\\textbf{r}})\\hat{\\textbf{r}} - \\textbf{p}}{r^3}\n\\end{align}\nWe can also find the expression for energy $E$ and torque $\\boldsymbol{\\tau}$ with\n\\begin{align}\nE_{dip} = - \\textbf{p}\\cdot\\textbf{E}\\\\\n\\mathbf{\\tau}_{dip} = \\textbf{p}\\times\\textbf{E}\n\\end{align}\nOne can remember the minus sign because a dipole always points in the direction of it's positive charge, so one pointing parallel with an electric field will have lower energy. The torque rule can be recovered drawing out the dipole and imagining how it will spin in combiniation with the right hand rule.\n\nThe quadrupole moment $Q_{ij}$ is a tensor defined as \n\\begin{align}\nQ_{ij} = \\frac{1}{2}\\int dr^3 \\rho(\\textbf{r})r_ir_j = \\frac{1}{2} \\sum q r_i r_j\n\\end{align}\nWhere $r_i = x,y,z$, this is not summation notation! One quadrant would look like\n\\begin{align}\nQ_{xy} = \\frac{1}{2}\\int dr^3 \\rho(\\textbf{r})xy\n\\end{align}\n\n\n%The field and electrostatic enery are given as\n\n%\\begin{align}\n%%\\textbf{E}(\\textbf{r}) &= \\frac{1}{4\\pi\\epsilon_0}\\int d^3\\textbf{r}' \\frac{\\rho(\\textbf{r}')%%(\\textbf{r} - \\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|^3}\\\\\n%U_E &= \\frac{1}{2}\\epsilon_0\\int d^3r|\\textbf{E}|^2\n%\\end{align}\n\n\n\\subsection{Uniqueness}\nIn order for use to have unique solutions to each electrostatics question, which lets us get the solution be literally any means, it happens that\\cite{zangwill}, using something called Dirichlet boundary conditions, we need the potential specified at some boundary, such that any two solutions evaluated at that boundary will be equal or $\\varphi_1(\\textbf{r}_s) -\\varphi_2(\\textbf{r}_s) = 0$ where $\\textbf{r}_s$ is the location of the boundary. There are other choices such Neumann Boundary conditions, but we probably won't need to know them.\n\n\\subsection{Symmetries}\nAnother key to solving these equations is looking for places where you can leverage symmetries to make evaluation of many of these things near trivial. For instances if we are looking at the potential of a conducting sphere relative to infinity, we can just use Gauss' law to solve for the electric field\n\\begin{align}\n\\int d\\textbf{S}\\cdot\\textbf{E} =\\frac{Q}{\\epsilon_0} = 4\\pi r^2 E\n\\end{align}\nThen integrate from infinity to field the potential\n\\begin{align}\nV = - \\int_\\infty^r d\\textbf{l}\\cdot\\textbf{E}  = -\\frac{Q}{4\\pi \\epsilon_0}\\int_\\infty^r \\frac{dr'}{r'^2} = \\frac{Q}{4\\pi\\epsilon_0 r}\n\\end{align}\n\n\n\n\\subsection{Image Charges}\nTo solve these, need to have some kind of boundary, you can place a fake \"image charge\" within the boundary, and, through uniqueness, solve for the potential outside by just vector summing the  fictitious charge, and the real ones. It is typically done with grounded surfaces, but works equally well if the surface is just maintained at a constant potential, because we can just add more image charges in other locations to make it so (for instance the center of a sphere). For a sphere the image charge to make an equipotential surface is given as\n\n\\begin{align}\nq' = -\\frac{R}{d}q\\\\\nd' = \\frac{R^2}{d}\n\\end{align}\n\nWhere $q$ is the magnitude of the charge outside the sphere, a distance $d$ from it's center, requiring that a charge of opposite sign $q'$ be put a distance along the same axis given by $d'$ to create the surface. You actually hardly have to remember these, since as long as you know that the charge should be negative and less in magnitude when it is inside the sphere, you can just make whatever ratio you like with the radius to make it so.\n\nFor a dielectric surface, we can also use image charges. For an infinite sheet, we actually need \\emph{two} image charges to keep the parallel component of the electric field equal to zero on the interface.\n\n\n\n\n\\section{Laplace's Equation}\nLaplace's equation, obtained by plugging in the expression for electric potential into Gauss' law, is written as \n\\begin{align}\n\\nabla^2\\varphi = 0\n\\end{align}\nAnd is used to solve the electric potential within a region with no charge. All the problems here involve solutions to the aptly named Laplacian operator $\\nabla^2$ in various geometries using separation of variables.\\cite{zangwill} is a great resource here. To solve these questions follow this algorithm\n\\begin{enumerate}\n\\item Recognize geometry of the problem (Cartesian, Spherical with Azimuthal Symmetry, etc.)\n\\item Shrink Laplace's equation by getting rid of any terms that the potential doesn't depend on out of the Laplacian, e.g. if it doesn't depend on $z, \\frac{d^2 Z(z)}{dz^2} = 0$.\n\n\\item Use boundary conditions to collapse form further and get some constants\n\n\\item If necessary, use orthogonality of whatever functions you have to select out terms to find equations for coefficients for the potential\n\n\\item Do the same thing for continuity of the electric field\n\n\\item Plug in constants and you're done\n\n\n\\end{enumerate}\n\n\n\n\\subsection{Cartesian}\nHere we guess that the potential has the form of a product of $X(x)Y(y)Z(z)$ which lets us manipulate Laplace's equation into the form\n\\begin{align}\n\\frac{X''}{X} + \\frac{Y''}{Y} + \\frac{Z''}{Z} = 0\n\\end{align}\nThese all have to be constants, since they are all independent variables, which in total must sum to zero, so \n\\begin{align}\n\\alpha^2 + \\beta^2 + \\gamma^2 = 0\n\\end{align}\nWhich gives us solutions\n\\begin{align}\nX(x) &= \\begin{cases}\nA_0 +B_0x &\\alpha = 0\\\\\nA_\\alpha e^{\\alpha x} + B_\\alpha e^{-\\alpha x} &\\alpha \\neq 0\n\\end{cases}\\\\\nY(y) &= \\begin{cases}\nC_0 +D_0y &\\beta = 0\\\\\nC_\\beta e^{\\beta y} + B_\\beta e^{-\\beta y} &\\beta \\neq 0\n\\end{cases}\\\\\nZ(z) &= \\begin{cases}\nE_0 +F_0z &\\gamma = 0\\\\\nE_\\gamma e^{\\gamma z} + F_\\gamma e^{-\\gamma z} &\\gamma \\neq 0\n\\end{cases}\n\\end{align}\nThe solution is a general linear combination of all solutions that satisfy $\\alpha^2+\\beta^2+\\gamma^2=0$, so the potential is\n\\begin{align}\n\\varphi(x,y,z) = \\sum_\\alpha \\sum_\\beta \\sum_\\gamma X_\\alpha(x)Y_\\beta(y)Z_\\gamma(z) \\delta(\\alpha^2+\\beta^2+\\gamma^2)\n\\end{align}\n\n\\subsection{Spherical}\nFor an \\textbf{azimuthally symmetric} system, the form is\n\\begin{align}\\label{laplace}\n\\varphi(r,\\theta)=\\sum_{l=0}^\\infty [A_l r^l+B_lr^{-(l+1)}]P_l(\\cos\\theta)\n\\end{align}\nCan remove either the positive or negative exponents depending on if your solution must include 0 or infinity. Can also figure it out from Taylor expansion that give you the Legendre Polynomials in section \\ref{legendrepoly}. \n\nFor \\textbf{non-azimuthally symmetric} systems, we have to expand the Legendre Polynomials in terms of Spherical Harmonics, so\n\\begin{align}\n\\varphi(r,\\theta)=\\sum_{l=0}^\\infty\\sum_{m=-l}^l [A_{lm} r^l+B_{lm}r^{-(l+1)}]Y^l_m(\\theta,\\phi)\n\\end{align}\n\n\n\n\n\\subsection{Cylindrical}\\label{cylinderlaplace}\nHere we guess the form that the potential looks like a product of $R(\\rho)G(\\phi)Z(z)$, which comes out (Section \\ref{cylinderlaplacian}) with solutions to Laplace's equation in Cylindrical that look like\n\\begin{align}\nG_\\alpha(\\phi) &= \\begin{cases}\nx_0 + y_0\\phi &\\alpha = 0\\\\\nx_\\alpha e^{i\\alpha \\phi} + y_\\alpha e^{-i\\alpha \\phi} &\\alpha \\neq 0\n\\end{cases}\n\\end{align}\nWhere $\\alpha$ comes from the equation\n\\begin{align}\n\\frac{d^2G}{d\\phi^2} =  -\\alpha^2 G\n\\end{align}\nSo it makes sense we get sines and cosines, or just linear terms if $\\alpha = 0$. Since we need that $\\varphi(\\phi) = \\varphi(\\phi+2\\pi)$, So as long as we are using the full angular range we need\n\\begin{align}\n\\alpha = 0,\\pm 1,\\pm 2, \\pm 3, ... \n\\end{align}\nThe $z$ portion is similar to the angular portion, but it happens that the constant can be either sign, so\n\\begin{align}\nZ_k(z) &= \\begin{cases}\ns_0 + t_0 z &k = 0\\\\\ns_k e^{kz} + t_k e^{-k z} &k \\neq 0\n\\end{cases}\n\\end{align}\nThe radial portion is quite nasty, we get the constants from the other two equations, with things like condary conditions, then can use them to help decide what radial function we need below.\n\\begin{align}\nR^k_\\alpha(r) &= \\begin{cases}\nA_0 + B_0\\ln\\rho &k=0, \\alpha = 0\\\\\nA_\\alpha \\rho^\\alpha  + B_\\alpha \\rho^{-\\alpha} &k = 0, \\alpha \\neq 0\\\\\nA_\\alpha^kJ_\\alpha(k\\rho) + B_\\alpha^kN_\\alpha(k\\rho) & k^2 > 0\\\\\nA_\\alpha^kI_\\alpha(-ik\\rho) + B_\\alpha^kK_\\alpha(-ik\\rho) & k^2 < 0\n\\end{cases}\n\\end{align}\nWhere $J(x)$ and $N(x)$ are Bessel Functions (Section \\ref{bessel}) and $I(x)$ and $K(x)$ are modified Bessel functions. The general solution is given by a linear super position of all the elementary solutions with\n\\begin{align}\n\\varphi(\\rho,\\phi,z) = \\sum_\\alpha\\sum_k R_\\alpha^k(\\rho)G_\\alpha(\\phi)Z_k(z)\n\\end{align}\n\n\n\\section{Magnetostatics}\n\\subsection{Magnetic Potential}\nWe first need a vector identity that is true for any vector, given by\n\\begin{align}\n    \\textbf{C}(\\textbf{r}) = \\nabla\\times\\frac{1}{4\\pi}\\int d^3r'\\frac{\\nabla'\\times\\textbf{C}(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|} - \\nabla\\frac{1}{4\\pi}\\int d^3r'\\frac{\\nabla'\\cdot\\textbf{C}(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nSince $\\nabla\\cdot\\textbf{B} = 0$, we have that\n\\begin{align}\n    \\textbf{B}(\\textbf{r}) = \\nabla\\times\\frac{1}{4\\pi}\\int d^3r'\\frac{\\nabla'\\times\\textbf{B}(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nIn Magnetostatics\n\\begin{align}\n    \\nabla\\times\\textbf{B} = \\mu_0\\textbf{j}\n\\end{align}\nWe identify the term before the curl as the magnetic potential with\n\\begin{align}\n    \\textbf{A}(\\textbf{r}) = \\frac{\\mu_0}{4\\pi}\\int d^3r'\\frac{\\textbf{j}(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nWe can also derive the Biot-Savart law for the magnetic field using index notation with\n\\begin{align}\n        \\textbf{B}(\\textbf{r}) &= \\nabla\\times\\frac{\\mu_0}{4\\pi}\\int d^3r'\\frac{\\textbf{j}(\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|}\\\\\n        B_i &=\\frac{\\mu_0}{4\\pi} \\varepsilon_{ijk}\\partial_j\\int d^3r'\\frac{j_k'}{|\\textbf{r}-\\textbf{r}'|}\\\\\n        &= \\frac{\\mu_0}{4\\pi} \\int d^3r' \\epsilon_{ijk}j_k \\partial_j \\frac{1}{|\\textbf{r}-\\textbf{r}'|}\\\\\n        &=-\\frac{\\mu_0}{4\\pi} \\int d^3r' \\epsilon_{ijk}j_k \\frac{r_j}{|\\textbf{r}-\\textbf{r}'|^2}\\\\\n\\end{align}\nFix this. Thus we see that\n\\begin{align}\n    \\textbf{B}(\\textbf{r}) &= \\frac{\\mu_0}{4\\pi} \\int d^3r'\\frac{\\textbf{j}(\\textbf{r}')\\times(\\textbf{r}-\\textbf{r}')}{|\\textbf{r}-\\textbf{r}'|^3}\n\\end{align}\n\n\n\\subsection{Ohm's Law}\nWhen I first studied E\\&M, it was always weird to me that people would say \"There is no electric field in a conductor\" while simultaneously saying \"The current in a conductor is proportional to the voltage difference between two regions (and therefore the electric field)\". The real thing goes like this; we take the perspective of a single electron in a conductor, and look at a simplified version of all the forces that act on it\n\\begin{align}\nm\\dot{\\textbf{v}} = -e\\textbf{E} -  \\frac{m\\textbf{v}}{\\tau}\n\\end{align}\nThe electric field term is straightforward, and the other one is a drag term meant to account for collisions, since the electron will be slowed down when it runs into things. Since the electron is feeling a force propotional to however fast it is going, it will eventually reach an equilibrium speed, which we can find by setting the acceleration to zero.\n\\begin{align}\n\\textbf{v}_d = -\\frac{e\\tau}{m}\\textbf{E}\n\\end{align}\nThis is called the \\emph{drift speed} and is actually quite small in most metals ($\\sim 10^{-3}$ m/s). We define the current from the continuity equation for conservation of charge, since\n\\begin{align}\n\\frac{\\partial \\rho}{\\partial t} +\\nabla\\cdot(\\rho\\textbf{v}) = 0\n\\end{align}\nThe \\emph{current density} we call the right part, defined as\n\\begin{align}\n\\textbf{j} \\equiv \\rho\\textbf{v}\n\\end{align}\nIf we have just one type of charge, the current density is identical to multiplying just one charge by its velocity then by however many there are in that region $n$, or if we have a whole bunch of kinds of charges $N$\n\\begin{align}\n\\textbf{j} = \\sum_{i=1}^N q_in_i\\textbf{v}_i\n\\end{align}\nIf we have only electrons, we have just one term, and since each electron will feel the same electric field, will have the same drift velocity, so we can say\n\\begin{align}\n\\textbf{j} = \\frac{ne^2\\tau}{m}\\textbf{E} = \\sigma\\textbf{E}\n\\end{align}\nWhere $\\sigma$ is called the conductivity. This is Ohm's law $V=IR$ since we see the current is linear in the electric field.\nThe surface charge density is given by\n\\begin{align}\n\\textbf{K} &= \\sigma \\textbf{v}\n\\end{align}\nBut this time $\\sigma$ is the surface charge density, which can be needlessly confusing if you are unfamiliar with how to use these equations.\n\\section{Dipoles}\n\n\\subsection{Electric Dipoles}\n\\begin{align}\n    V(\\textbf{r}) = \\frac{1}{4\\pi\\epsilon_0} \\frac{\\textbf{p}\\cdot\\textbf{r}}{r^3}\n\\end{align}\n\n\\subsection{Magnetic Dipoles}\n\n\n\n\\begin{align}\n\\textbf{A}(\\textbf{r},t) = \\frac{\\mu_0}{4\\pi}\\frac{\\textbf{m}\\times\\textbf{r}}{r^3} \n\\end{align}\nUsing index notation we can find the field with\n\\begin{align}\n    \\textbf{B}(\\textbf{r},t) = \\frac{\\mu_0}{4\\pi}\\Big(\\frac{3\\hat{r}(\\textbf{m}\\cdot\\hat{r}) - \\textbf{m}}{r^3}\\Big)\n\\end{align}\n\nThe magnetic moment is defined as \n\\begin{align}\n    \\textbf{m} = \\frac{1}{2} \\int dr^3 [\\textbf{r}\\times\\textbf{j}_m\\Big] + \\frac{1}{2} \\int dS [\\textbf{r}\\times\\textbf{K}_m]\n\\end{align}\n\n\n\\section{Fields in Matter}\n% TODO When we consider electric and magnetic fields inside of materials, not just vacuum ...\n\\subsection{Dielectrics}\nA perfect conductor is capable of reorienting any and all of its electrons such that it always exactly cancels out any static electric field that is applied to it. In reality of course, most objects can't reorient themselves this well, but still can to a degree. These materials are called \\emph{dielectrics} and physically appear from the stretching of electrons from their nuclei inside a material, which makes it so the field inside the material is no longer just the externally applied field, but also a field created by the stretched molecules created by the external field itself. So we break up the field into components\n\\begin{align}\n\\textbf{D} = \\epsilon_0\\textbf{E} + \\textbf{P}\n\\end{align}\nWhere $\\textbf{D}$ is called the \\emph{auxillary} field, the field leftover inside the material after the molecules reorient themselves according to the applied field $\\textbf{E}$ which gives the object it's \\emph{polarization} $\\textbf{P}$. In the lab we can control how much free charge  $\\rho_f$ we can put on something, but not necessarily how much bound charge $\\rho_B$ shows up, so most people use $\\textbf{D}$ in real life circumstances.\n\n\nSomething something free vs bound charge.\n\n\n As a memorization rule, it seems best to obtain the expressions for bound charge from combining expressions for $\\textbf{D}$ and $\\textbf{E}$. We first say\n\\begin{align}\n\\nabla\\cdot\\textbf{D} = \\rho_f(\\textbf{r})\n\\end{align}\nAnd taking the divergence\n\\begin{align}\n\\epsilon_0\\nabla\\cdot\\textbf{E} - \\nabla\\cdot\\textbf{D} &=  -\\nabla\\cdot \\textbf{P}\\\\\n\\rho(\\textbf{r})  - \\rho_f(\\textbf{r}) &= -\\nabla\\cdot \\textbf{P}\n\\end{align}\nSo we have to have that\n\\begin{align}\n\\nabla\\cdot \\textbf{P} = -\\rho_B(\\textbf{r})\n\\end{align}\n\n\nWhich just says if we add up the free and bound charge, we get the total charge density. We also want to have boundary conditions for the auxilary field, with\n\\begin{align}\n\\hat{n}\\cdot[\\textbf{D}_{out}-\\textbf{D}_{in}] &= \\sigma_f\\\\\n\\hat{n}\\cdot[\\textbf{E}_{out}-\\textbf{E}_{in}] &= \\sigma/\\epsilon_0\n\\end{align}\nIf we are looking at the interface of vacuum and a medium with polarization $\\textbf{P}$, we have\n\\begin{align}\n\\hat{n}\\cdot[\\epsilon_0\\textbf{E}_{out} + 0 -\\epsilon_0\\textbf{E}_{in} -\\textbf{P}] &= \\sigma_f\\\\\n\\sigma -\\textbf{P}\\cdot\\hat{n} &= \\sigma_f\n\\end{align}\nThus\n\\begin{align}\n\\textbf{P}\\cdot\\hat{n} = \\sigma_B\n\\end{align}\nTypically we consider only linear (first order), isotropic (same from any direction), homogeneous (the same all over) materials, which means that the polarization is linearly proportional to the applied field\n\\begin{align}\n\\textbf{P} = \\epsilon_0\\chi\\textbf{E}\n\\end{align}\nThere are  alot of constants here, with\n\\begin{align}\n\\epsilon = \\epsilon_0(1+\\chi) &&\\kappa = \\frac{\\epsilon}{\\epsilon_0}\n\\end{align}\nThese let you express a whole bunch of things in a huge number of ways, for instance\n\\begin{align}\n\\rho_b = -\\frac{\\chi}{1+\\chi}\\rho_f\n\\end{align}\nAnother useful thing to know is the relationship between an electric dipole moment $\\textbf{p}$ and the field\n\\begin{align}\n    \\textbf{p} = \\alpha \\textbf{E}\n\\end{align}\nWhere $\\alpha$ is the polarizability. With this knowledge, we can express the polarization in terms of the electric dipoles with\n\\begin{align}\n    \\textbf{P} = \\frac{d\\textbf{p}}{dV}\n\\end{align}\n\n\n\n\\subsection{Magnetization}\nMagnetization happens when we get a rearrangement of internal currents in a material when an external magnetic field is applied to it. Electron spin is responsible for most of magnetism in paramagnets and ferromagnets.\n\n\nSimilar to electrostatics in materials, we want a magnetic field that comes just from the the free current $\\textbf{j}_f$ (with $\\partial\\textbf{E}/\\partial t = 0$) . We also call this field the auxiliary field $\\textbf{H}$ with\n\\begin{align}\n\\nabla\\times\\textbf{H} = \\textbf{j}_f\n\\end{align}\nWhen these things were being define, they thought that $\\textbf{H}$ was the real full field, and $\\textbf{B}$ was the field that just came from the free currents, so the definition is similar to that for dielectrics, but with the two swapped and the constant only on $\\textbf{B}$\n\\begin{align}\n\\frac{1}{\\mu_0}\\textbf{B} = \\textbf{H} + \\textbf{M}\n\\end{align}\nDoing the same tricks to find out things about the Magnetization, $\\textbf{M}$ we have\n\\begin{align}\n\\frac{1}{\\mu_0}\\nabla\\times\\textbf{B} &= \\nabla\\times\\textbf{H} + \\nabla\\times\\textbf{M}\\\\\n\\textbf{j} &= \\textbf{j}_f + \\nabla\\times\\textbf{M}\n\\end{align}\nSo the magnetization current density is\n\\begin{align}\n\\textbf{j}_m = \\nabla\\times\\textbf{M}\n\\end{align}\nThere is also another interesting property that the auxiliary field can have, a divergence, since\n\\begin{align}\n\\frac{1}{\\mu_0}\\nabla\\cdot\\textbf{B} = \\nabla\\cdot\\textbf{H} + \\nabla\\cdot\\textbf{M}\\\\\n\\rightarrow \\nabla\\cdot\\textbf{H} = -\\nabla\\cdot\\textbf{M}\n\\end{align}\nWe can also use the boundary conditions to find out things about free and bound surface currents\n\\begin{align}\n\\hat{n}\\times[\\textbf{H}_{out} - \\textbf{H}_{in}] = \\textbf{K}_f\\\\\n\\hat{n}\\times[\\textbf{B}_{out} - \\textbf{B}_{in}] =\\mu_0\\textbf{K}\n\\end{align}\nSo looking for the equivalent bound current, with no magnetization on the outside\n\\begin{align}\n\\hat{n}\\times[\\textbf{B}_{out}  - \\textbf{B}_{in} + \\textbf{M}] &= \\textbf{K}_f\\\\\n\\textbf{K} +\\hat{n}\\times\\textbf{M} &= \\textbf{K}_f\n\\end{align}\nThus\n\\begin{align}\n\\textbf{M}\\times\\hat{n} = \\textbf{K}_m\n\\end{align}\nAfter swapping the order of the cross product.\n\n\\subsection{Waves}\nMaxwell's equation's in matter can be rewritten, quite easily by simply changing all instances of $\\epsilon_0 \\rightarrow \\epsilon$ and $\\mu_0 \\rightarrow \\mu$, so\n\\begin{align}\n\\nabla\\cdot\\textbf{E} &= \\frac{\\rho}{\\epsilon} & \\nabla\\cdot\\textbf{B} &= 0\\\\\n\\nabla\\times\\textbf{E} &= -\\frac{\\partial\\textbf{B}}{\\partial t} &\\nabla\\times\\textbf{B} &= \\mu\\textbf{j} + \\mu\\epsilon\\frac{\\partial\\textbf{E}}{\\partial t} \n\\end{align}\n\n\n\n\\subsection{Polarization}\nScarab beetles reflect almost only circularly polarized light.\n\n\n\n\\section{Boundary Conditions}\n\\begin{align}\n\\hat{n}\\cdot[\\textbf{D}_{out} - \\textbf{D}_{in}] &= \\sigma_{free} &\\hat{n}\\cdot[\\textbf{B}_{out} - \\textbf{B}_{in}] &= 0\\\\\n\\hat{n}\\times[\\textbf{E}_{out} - \\textbf{E}_{in}] &= 0 &\\hat{n}\\times[\\textbf{H}_{out}-\\textbf{H}_{in}] &= \\textbf{K}_{free}\n\\end{align}\nWhere we assume $\\textbf{D} = \\epsilon\\textbf{E}$ and $\\textbf{H} = \\textbf{B}/\\mu$. These can easily be rederived thinking about an infinite sheet with charge density $\\sigma$ for $\\textbf{D}$ and just drawing vectors and using the right hand rule to put things in the right place for $\\textbf{H}$\n\n\\section{Waves}\n\\subsection{Waves in Vacuum}\nMaxwell's equations in vacuum $\\rho = \\textbf{j} = 0$ are\n\\begin{align}\n\\nabla\\cdot\\textbf{E} &= 0 &\\nabla\\cdot\\textbf{B} &= 0\\\\\n\\nabla\\times\\textbf{E} &= -\\frac{\\partial \\textbf{B}}{\\partial t} & \\nabla\\times\\textbf{B} &= \\epsilon_0\\mu_0\\frac{\\partial \\textbf{E}}{\\partial t}\n\\end{align}\nJust to see what happens, let's take the curl of Faraday's law\n\\begin{align}\n\\nabla\\times(\\nabla\\times\\textbf{E}) &= -\\nabla\\times\\frac{\\partial \\textbf{B}}{\\partial t}\\\\\n\\nabla(\\nabla\\cdot\\textbf{E}) - \\nabla^2\\textbf{E} &= -\\frac{\\partial}{\\partial t}\\Big(\\nabla\\times\\textbf{B}\\Big)\\\\\n\\nabla^2\\textbf{E} &= \\epsilon_0\\mu_0\\frac{\\partial^2\\textbf{E}}{\\partial t^2}\n\\end{align}\nThis is the wave equation in three dimensions. We can match the term in front of the time derivative with the normal form of the wave equation to recover the speed at which the electric field propagates as\n\\begin{align}\nc = \\frac{1}{\\sqrt{\\epsilon_0\\mu_0}} = 3\\times 10^8~\\rm{m/s}\n\\end{align}\nWhich is in fact the speed of light in vacuum. We can also rewrite the magnetic field doing the same thing with\n\\begin{align}\n\\nabla^2\\textbf{B} &= \\frac{1}{c^2}\\frac{\\partial^2\\textbf{B}}{\\partial t^2}\n\\end{align}\nSo the changing in space and time of the electric field is able to generate a magnetic field, which then twists and turns back into an electric field, over and over and over again as it propagates through vacuum. The well known solutions to this equation let write a general solution to \n\\begin{align}\n\\nabla^2\\textbf{w} &= \\frac{1}{c^2}\\frac{\\partial^2\\textbf{w}}{\\partial t^2}\n\\end{align}\nAs a function of new arguments\n\\begin{align}\n\\textbf{w}(z, t) = \\textbf{g}(z-ct) + \\textbf{f}(z+ct)\n\\end{align}\nAs long as the velocity $c^2$ is independent of frequency. We can then adjust constants and write the general electric field wave as\n\\begin{align}\n\\textbf{E}(\\textbf{r},t) &= \\textbf{E}_0 f(\\textbf{k}\\cdot\\textbf{r} -\\omega t)\\\\\n\\end{align}\nThis is an electric field that propagates in the \\emph{positive} $\\hat{k}$ direction, which can be seen by looking at its phase. We take  $\\textbf{B}$ to be an identical function of $\\textbf{r}$ and $t$\n%\\footnote{Why?}\n, with\n\\begin{align}\n\\textbf{B}(\\textbf{r},t) &= \\textbf{B}_0 f(\\textbf{k}\\cdot\\textbf{r} -\\omega t)\n\\end{align}\nWith $c|\\textbf{k}| = \\omega$. Using tensor notation and Faraday's law, we see\n\\begin{align}\n\\varepsilon_{ijk}\\partial_j\\Big[E_k f(k_lr_l-\\omega t)\\Big] &= -\\partial_tB_if(k_lr_l-\\omega t)\\\\\n\\varepsilon_{ijk}E_kf'(k_lr_l-\\omega t)\\delta_{jl}k_l &= \\omega B_if'(k_lr_l-\\omega t)\\\\\n\\textbf{k}\\times\\textbf{E}_0f'(k_lr_l-\\omega t) &= \\omega \\textbf{B}_0f'(k_lr_l-\\omega t)\\\\\n\\textbf{k}\\times\\textbf{E}_0 &= \\omega \\textbf{B}_0\n\\end{align}\nThis tells us that\n\\begin{align}\n|\\textbf{E}| = c|\\textbf{B}|\n\\end{align}\nSo we can write general \\textbf{plane wave} solutions as\n\\begin{align}\n\\tilde{\\textbf{E}}(\\textbf{r},t) &= \\textbf{E}_0\\exp\\Big[i(\\textbf{k}\\cdot\\textbf{r}-\\omega t)\\Big]\\\\\n\\tilde{\\textbf{B}}(\\textbf{r},t) &= \\frac{1}{\\omega}\\textbf{k}\\times\\textbf{E}_0\\exp\\Big[i(\\textbf{k}\\cdot\\textbf{r}-\\omega t)\\Big]\n\\end{align}\nWe are able to write in general the fields in terms of a single exponential function, with the phase hidden in the constant. These are much nicer to use than trigonometric functions, although the \\emph{real} part of these fields are the things that create the \\emph{real} field, which can be found just taking the real part of these equations with\n\\begin{align}\n    \\textbf{E}(\\textbf{r},t) = \\rm{Re}\\Big(\\tilde{\\textbf{E}}\\Big)\\\\\n    \\textbf{B}(\\textbf{r},t) = \\rm{Re}\\Big(\\tilde{\\textbf{B}}\\Big)\n\\end{align}\n\n\n\n\\subsection{Waves in Matter}\nFor these questions, we can find the $\\omega$ dependent permitivity by\n\\begin{enumerate}\n\\item Write out the forces on each of the individual electrons\n\\item Find the current density using the equation\n\\begin{align}\n\\textbf{j} = \\sum_\\alpha q_\\alpha  n_\\alpha \\dot{\\textbf{x}} = \\sigma\\textbf{E}\n\\end{align}\n\\item Find an expression for the effective permitivity in maxwells equations in matter\n\\item Solve for the effective permitivity\n \n\\end{enumerate}\n\n\n\n\n\n\\subsection{Waves in Conductors}\n\nThe whole idea here is that in Maxwell's equations, because of Ohm's law $\\textbf{j} = \\sigma\\textbf{E}$, which make the electrons resistance to movement, we get funny residual effects that wouldn't happen if they could move instantly. Using Maxwell's equations in matter, we first assume that we have waited long enough for the charge density $\\rho$ to go away, but a time that we still have a current. I'm still not super clear on this. Anyways, we have\n\\begin{align}\n\\nabla\\cdot\\textbf{E} &= 0& \\nabla\\cdot\\textbf{B} &= 0\\\\\n\\nabla\\times\\textbf{E} &= -\\frac{\\partial\\textbf{B}}{\\partial t} &\\nabla\\times\\textbf{B} &= \\mu\\textbf{j} + \\mu\\epsilon\\frac{\\partial\\textbf{E}}{\\partial t} \n\\end{align}\nLet's take the curl of Ampere's law and replace $\\textbf{j} = \\sigma\\textbf{E}$\n\\begin{align}\n\\nabla\\times(\\nabla\\times\\textbf{E}) &= -\\nabla\\times\\frac{\\partial\\textbf{B}}{\\partial t}\\\\\n\\nabla(\\nabla\\cdot\\textbf{E}) - \\nabla^2\\textbf{E} &= -\\frac{\\partial}{\\partial t}\\nabla\\times\\textbf{B}\\\\\n-\\nabla^2\\textbf{E} &= -\\frac{\\partial}{\\partial t}\\Big[\\mu\\sigma\\textbf{E}+ \\mu\\epsilon\\frac{\\partial\\textbf{E}}{\\partial t}\\Big]\\\\\n\\nabla^2\\textbf{E} &= \\mu\\sigma\\frac{\\partial\\textbf{E}}{\\partial t} + \\mu\\epsilon\\frac{\\partial^2\\textbf{E}}{\\partial t^2}\\label{maxwellmatter}\n\\end{align}\nThis equation can again be solved with an plane wave, with\n\\begin{align}\n\\textbf{E}(\\textbf{r},t) &= \\textbf{E}_0\\exp\\Big[i(\\tilde{\\textbf{k}}\\cdot\\textbf{r}-\\omega t)\\Big]\\\\\n\\textbf{B}(\\textbf{r},t) &= \\textbf{B}_0\\exp\\Big[i(\\tilde{\\textbf{k}}\\cdot\\textbf{r}-\\omega t)\\Big]\n\\end{align}\nPlugging it into the new wave equation, we find that\n\\begin{align}\n\\tilde{\\textbf{k}}^2 = i\\mu\\sigma\\omega + \\mu\\epsilon\\omega^2\n\\end{align}\nObviously $\\tilde{\\textbf{k}}$ must have an imaginary part to it, so we can now write it as a complex number\n\\begin{align}\n\\tilde{\\textbf{k}} = (k+i\\kappa)\\hat{k} = \\textbf{k} + i\\boldsymbol{\\kappa}\n\\end{align}\nThus\n\\begin{align}\n 2ik\\kappa + (k^2 -\\kappa^2) = i\\mu\\sigma\\omega + \\mu\\epsilon\\omega^2\n\\end{align}\nWe can now match the real and imaginary parts, leading to a quadratic equation, which can be solved. The important part is that the fields now go like\n\\begin{align}\n\\textbf{E}(\\textbf{r},t) &= \\textbf{E}_0e^{-\\boldsymbol{\\kappa}\\cdot\\textbf{r}}\\kappa\\exp\\Big[i\\textbf{k}\\cdot\\textbf{r}-\\omega t)\\Big]\\\\\n\\textbf{B}(\\textbf{r},t) &= \\textbf{B}_0e^{-\\boldsymbol{\\kappa}\\cdot\\textbf{r}}\\exp\\Big[i(\\textbf{k}\\cdot\\textbf{r}-\\omega t)\\Big]\n\\end{align}\nSo we see the fields die off exponential as we go into the conductor. We define the skin depth as\n\\begin{align}\nd = \\frac{1}{\\kappa}\n\\end{align}\n\n\n\n\n\\subsection{Waves in Plasma}\n\n\n\"The frequency dispersion of the index of refraction ... occurs because matter cannot respond instantaneously to an external perturbation\".\\cite{zangwill} Now we again look at the motion of a charge particle in a magnetic and electric field. We first look at the forces on a charge, pretending it has a binding force $-m\\omega_0^2\\textbf{x}$\n\\begin{align}\nm\\ddot{\\textbf{x}} = q\\textbf{E} -m\\gamma\\dot{\\textbf{x}} - m\\omega_0^2\\textbf{x}\n\\end{align}\nWe assume that it matches the field\n\\begin{align}\n\\textbf{x}(t) = \\textbf{x}_0e^{i\\omega t} &&\\textbf{E}(t) = \\textbf{E}_0e^{i\\omega t}\n\\end{align}\nThis gives us\n\\begin{align}\n\\textbf{x} = \\frac{q/m}{i\\omega\\gamma - \\omega^2-\\omega_0^2}\\textbf{E}\n\\end{align}\nWe can plug this into the formula for current density, if we have just one species and get\n\\begin{align}\n\\textbf{j} = \\frac{i\\omega q^2n/m}{i\\omega\\gamma + \\omega^2-\\omega_0^2}\\textbf{E}\n\\end{align}\nWe can find the effective permittivity from maxwells equations in matter with Equation \\ref{maxwellmatter}. \n\\begin{align}\n\\frac{\\tilde\\epsilon(\\omega)}{\\epsilon_0} = 1 + \\frac{i\\sigma}{\\epsilon_0 \\omega}\n\\end{align}\nWe use Ohm's law to find the conductivity and find\n\\begin{align}\nn = \\sqrt{\\frac{\\tilde\\epsilon(\\omega)}{\\epsilon_0}} = \\sqrt{1- \\frac{\\omega_p^2}{i\\omega\\gamma + \\omega^2-\\omega_0^2}}\n\\end{align}\nWhere the plasma frequency is given by\n\\begin{align}\n\\boxed{\\omega_p^2 = \\frac{q^2n}{\\epsilon_0 m}}\n\\end{align}\n\n\n\n\n\\subsection{Waveguides}\nTake Maxwell's equation's in free space, and assume of the electric field as\n\\begin{align}\n    \\textbf{E} = \\textbf{E}(x,y)e^{i(kz-\\omega t)}\n\\end{align}\nPlay around with their components to come up with a differential equation for $x$ and $y$ in terms of $z$.\n\\begin{align}\n    \\Big[\\frac{\\partial^2}{\\partial x^2} + \\frac{\\partial^2}{\\partial y^2} + (\\omega/c)^2 - k^2\\Big]E_z &= 0\\\\\n    \\Big[\\frac{\\partial^2}{\\partial x^2} + \\frac{\\partial^2}{\\partial y^2} + (\\omega/c)^2 - k^2\\Big]B_z &= 0\n\\end{align}\nThere are two typical cases considered \\textbf{Transverse electric} which happens when the electric field is \\emph{never} in the $z$ direction, or $E_z = 0$. \\textbf{Transverse magnetic} is when the magnetic field is never in the $z$ direction so $B_z = 0$. There is also a case where both are transverse aptly named \\textbf{TEM} waves where $B_z = E_z = 0$. After solving for $E_z$ or $B_z$, we will get coefficients in place of the derivative operators. The sum of these must add to zero to keep the equation true. Typically it looks something like\n\\begin{align}\n    \\Big(\\frac{n\\pi}{d_x}\\Big)^2 + \\Big(\\frac{m\\pi}{d_y}\\Big)^2 + (\\omega/c)^2 - k^2 = 0\n\\end{align}\n\nOur job here is to find the \\emph{smallest possible} $\\omega$, which is done just rearranging\n\\begin{align}\n    \\omega = c\\sqrt{k^2 -\\Big(\\frac{n\\pi}{d_x}\\Big)^2 - \\Big(\\frac{m\\pi}{d_y}\\Big)^2}\n\\end{align}\nNow in most cases $n,m= 0,1,2,3, ...$ etc. So we just pick the one that makes it so, giving us our \"cutoff frequency\" $\\omega_c$ which is the smallest frequency that can possibly travel down the waveguide. To solve for the other components of the electric field as it is traveling, just plug $E_z$ into Maxwell's equations to get differential equations for $E_x$ and $E_y$. For instance\n\\begin{align}\n    \\nabla\\cdot\\textbf{E} = 0 = \\partial_x E_x + \\partial_y E_y + \\partial_z E_z\n\\end{align}\nWhere we can usually assume one of these is zero to start with, since we usually just look at TE or TM waves.\n\n\n\n\n\n\\section{Potentials and Energy Transport}\n\n\n\\subsection{Gauges}\nBecause $\\nabla\\cdot\\textbf{B} = 0$  always (there are no magnetic monopoles), and the divergence of the curl of any vector is always zero, we can say\n\\begin{align}\n    \\nabla\\cdot\\textbf{B} = 0 = \\nabla\\cdot\\Big(\\nabla\\times\\textbf{A}\\Big) \n\\end{align}\nSo we define the magnetic potential $\\textbf{A}$ as\n\\begin{align}\n    \\textbf{B} = \\nabla\\times\\textbf{A}\n\\end{align}\nWe want to also maintain the same definition we used for the scalar potential before that arose because the curl of a gradient is zero with\n\\begin{align}\n    \\nabla\\times\\textbf{E} = 0 = \\nabla\\times \\Big(-\\nabla\\varphi\\Big)\n\\end{align}\nIn electrodynamics of course, Faraday's law reads\n\\begin{align}\n    \\nabla\\times \\textbf{E} = -\\frac{\\partial\\textbf{B}}{\\partial t} = -\\frac{\\partial}{\\partial t}\\Big(\\nabla\\times\\textbf{A}\\Big)\n\\end{align}\nWhich inspires us to write\n\\begin{align}\n    \\textbf{E} = -\\nabla\\varphi -\\frac{\\partial \\textbf{A}}{\\partial t}\n\\end{align}\n\nThe only restriction on these potentials is that when you do the operations described, you must get back the same fields. Playing around and you can see that this lets us change \n\\begin{align}\n    \\textbf{A}' &= \\textbf{A} +\\nabla\\psi\\\\\n    \\varphi' &=\\varphi -\\frac{\\partial \\psi}{\\partial t}\n\\end{align}\nWhere $\\psi(\\textbf{r},t)$ is any scalar function. The \\textbf{Coulomb Gauge} is one where $\\nabla\\cdot\\textbf{A} = 0$, so we get equations familiar to us in electrostatics, with \n\\begin{align}\n    \\nabla\\cdot\\textbf{E} = -\\nabla^2\\varphi = \\rho/\\epsilon_0\n\\end{align}\nThe \\textbf{Lorenz Gauge} is one where\n\\begin{align}\n    \\boxed{\\nabla\\cdot\\textbf{A} = -\\frac{1}{c^2}\\frac{\\partial\\varphi}{\\partial t}}\n\\end{align}\nThis equation is particularly useful in electrodynamics. Partially because then the potentials satisfy an inhomogeneous wave equation with\n\\begin{align} \\label{potwaves}\n     \\frac{1}{c^2}\\frac{\\partial^2\\varphi}{\\partial t^2}- \\nabla^2\\varphi &= \\frac{\\rho}{\\epsilon_0}\\\\ \\label{magpotwaves}\n     \\frac{1}{c^2}\\frac{\\partial^2\\textbf{A}}{\\partial t^2}- \\nabla^2\\textbf{A} &= \\mu_0\\textbf{j}\n\\end{align}\nIn relativistic electrodynamics, these wave equations are consolidated into a super small formula after we define\n\\begin{align}\nA^\\mu &\\equiv (\\varphi/c, A_x,A_y,A_z)\\\\\nj^{\\mu} &\\equiv (\\rho c, j_x, j_y, j_z)\n\\end{align}\nSo\n\\begin{align}\n    \\partial_\\mu \\partial^\\mu A^\\nu = \\mu_0j^\\nu\n\\end{align}\nOne can use Green's functions to solve equations \\ref{potwaves} and \\ref{magpotwaves}. Giving us the solutions as\n\\begin{align}\n    \\varphi(\\textbf{r},t) &= \\frac{1}{4\\pi\\epsilon_0}\\int dr'^3 ~\\frac{\\rho(\\textbf{r}', t - |\\textbf{r}-\\textbf{r}'|/c)}{|\\textbf{r}-\\textbf{r}'|}\\\\ \\label{magpotretard}\n    \\textbf{A}(\\textbf{r},t) &= \\frac{\\mu_0}{4\\pi}\\int dr'^3 ~\\frac{\\textbf{j}(\\textbf{r}',t-|\\textbf{r} - \\textbf{r}'|/c)}{|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nThe intuition behind these equations is that at the point $\\textbf{r}$, it will take time for the information from the charge and current density to propagate to wherever the observer is. So what we have to do is add up all the charge and current density that existed at an earlier time, where that time is determined by how long it takes light to reach the location of the observer, from the location of the source. \n\n\n\\subsection{Poynting's Theorem}\nThe rate of change of mechanical energy of a system due to work done by charges is given by\n\\begin{align}\n    \\frac{dW_{mech}}{dt} = \\int dr^3 \\rho(\\textbf{E} + \\textbf{v}\\times\\textbf{B})\\cdot\\textbf{v} = \\int dr^3 \\textbf{j}\\cdot\\textbf{E}\n\\end{align}\nSince the magnetic force does no work. Solving for the current density in Ampere's law we have that\n\\begin{align}\n    \\textbf{j} = \\frac{\\nabla\\times\\textbf{B}}{\\mu_0} - \\epsilon_0\\frac{\\partial\\textbf{E}}{\\partial t}\n\\end{align}\nSo\n\\begin{align}\n    \\int dr^3 \\textbf{j}\\cdot\\textbf{E} = \\int dr^3 \\Big(\\frac{\\nabla\\times\\textbf{B}}{\\mu_0} - \\epsilon_0\\frac{\\partial\\textbf{E}}{\\partial t}\\Big)\\cdot\\textbf{E}\n\\end{align}\nThe curl must act before the divergence, so let us look at the term\n\\begin{align}\n    \\textbf{E}\\cdot\\Big(\\nabla\\times\\textbf{B}\\Big) &= \\epsilon_{ijk}E_i\\partial_jB_k = \\epsilon_{ijk} \\Big[\\partial_j (E_iB_k) - B_k\\partial_jE_i\\Big] \\\\\n    &= -\\nabla\\cdot\\Big(\\textbf{E}\\times\\textbf{B}\\Big) + \\textbf{B}\\cdot\\Big(\\nabla\\times\\textbf{E}\\Big)\\\\\n    &= - \\nabla \\cdot\\Big(\\textbf{E}\\times\\textbf{B}\\Big) -\\textbf{B}\\cdot\\frac{\\partial\\textbf{B}}{\\partial t}\n\\end{align}\nPlugging in we get\n\\begin{align}\n    \\int dr^3 \\textbf{j}\\cdot\\textbf{E} = -\\int dr^3 \\Big[\\frac{1}{\\mu_0}\\nabla\\cdot\\Big(\\textbf{E}\\times\\textbf{B}\\Big) + \\frac{\\partial}{\\partial t}\\Big(\\frac{1}{2\\mu_0} \\textbf{B}\\cdot\\textbf{B} + \\frac{\\epsilon_0}{2}\\textbf{E}\\cdot\\textbf{E}\\Big)\\Big]\n\\end{align}\nMatching the integrands we see that\n\\begin{align}\n     \\frac{\\partial}{\\partial t}\\Big(\\frac{1}{2\\mu_0} \\textbf{B}\\cdot\\textbf{B} + \\frac{\\epsilon_0}{2}\\textbf{E}\\cdot\\textbf{E}\\Big) + \\frac{1}{\\mu_0}\\nabla\\cdot\\Big(\\textbf{E}\\times\\textbf{B}\\Big)  = -\\textbf{j}\\cdot\\textbf{E}\n\\end{align}\nThe term on the left is called the electromagnetic energy density $u_E$. Written in a more illuminating way, we have\n\\begin{align}\n    -\\frac{\\partial u_E}{\\partial t} = \\nabla\\cdot\\textbf{S} + \\textbf{j}\\cdot\\textbf{E}\n\\end{align}\nThis is effectively an energy conservation equation. It says the decrease in energy per unit volume ($-\\partial u_E / \\partial t$) is equal to the energy that leaves the volume ($\\nabla\\cdot\\textbf{S}$) plus the work done on the charges ($\\textbf{j}\\cdot\\textbf{E}$).\n\n\n\n\n\\section{Radiation}\nElectromagnetic radiation is caused by the acceleration of charged particles. The primary equation that simplifies almost all of radiation and makes the math bearable takes a long time to derive \\cite{zangwill} gives us the power radiated per solid angle as %\\todo{Not really true, i guess it is for general radiation}\n\\begin{align}\\label{powerdistribution}\n    \\frac{dP}{d\\Omega} = \\frac{1}{c\\mu_0}\\Big| \\textbf{r}\\times\\frac{\\partial \\textbf{A}_{ret}}{\\partial t}\\Big|^2\n\\end{align}\nWe know that the Poynting vector tells us the flux of energy through each unit surface area per unit time, so if we added up all the flux through an entire surface, we would get the total power radiated. We can thinking about doing things as follows (this is just an area integral in Spherical coordinates). We first add up all the flux going through a ring created by the distance from the $z$ axis ($r\\sin\\theta$) at some given $\\theta$ value\n\\begin{align}\n    dP_{ring} (\\textbf{r}) = \\int_0^{2\\pi} d\\phi r\\sin\\theta ~\\textbf{S}\\cdot\\hat{r}\n\\end{align}\nThen we just add up all these contributions for each $\\theta$ value\n\\begin{align}\n    P (\\textbf{r}) = \\int_0^\\pi r d\\theta~ dP_{ring} (\\textbf{r})\n\\end{align}\nSo we see the total flux through a given surface is just \n\\begin{align}\n    P = \\int d\\Omega  ~r^2 \\textbf{S}\\cdot{\\hat{r}}\n\\end{align}\nThis gives us our expression for the differential power radiated per solid angle as just the integrand of this expression \n\\begin{align}\n    \\frac{dP}{d\\Omega} = r^2\\textbf{S}\\cdot\\hat{r} = \\frac{r^2}{\\mu_0} \\hat{r}\\cdot\\Big(\\textbf{E}\\times\\textbf{B}\\Big)\n\\end{align}\n\n\nTypically when looking at radiation, we care about what the field looks like very far away. Skipping ahead and looking at the form of the radiation fields in equation \\ref{radiationfields}, most of the terms have $1/r^2$ or more dependence, which means that very far away from the source, these contributions will be next to nothing. There are a few that this is not the case for, called the radiation fields, which, when multiplied by the $r^2$ that comes from the surface integral, give a factor with \\emph{no dependence} on $r$, which means there will always be the same amount of power that travels through a sphere of any size. This is what we call radiation. For a wave traveling in free space the electric and magnetic field are always perpendicular to each other, and to the direction of travel, so we know that \n\\begin{align}\n    \\hat{r} = \\hat{E}\\times\\hat{B}\n\\end{align}\nSo plugging into our expression for power radiated, we see\n\\begin{align}\n    \\frac{dP}{d\\Omega} = \\frac{r^2}{\\mu_0} \\hat{r}\\cdot\\Big(\\textbf{E}\\times\\textbf{B}\\Big) = \\frac{r^2}{\\mu_0}\\hat{r}\\cdot\\Big(\\hat{E}\\times\\hat{B}\\Big)|\\textbf{E}||\\textbf{B}|\n\\end{align}\nWe also know from Maxwell's equations in free space that\n\\begin{align}\n    |\\textbf{E}| = c|\\textbf{B}|\n\\end{align}\nSo we see that\n\\begin{align}\n    \\frac{dP}{d\\Omega} = \\frac{r^2}{\\mu_0c} |\\textbf{E}|^2\n\\end{align}\nThere seems to be endless variations on how you expression the radiated power, I suppose the best idea for attacking radiation problems is find the formulation that sits the best in your head. A useful equation that comes up often is the Larmor formula which says\n \\begin{align}\n P &=\\frac{1}{4\\pi\\epsilon_0}\\frac{2q^2|\\textbf{a}_{ret}|^2}{3c^3}\n \\end{align}\n \n \n\\subsection{Electric Dipole Radiation}\\label{electricdipole}\nThe current density of a dipole at the origin is given by\n\\begin{align}\n    \\textbf{j}(\\textbf{r},t) = \\dot{\\textbf{p}}(t) \\delta(\\textbf{r})\n\\end{align}\nWhich is equivalent to thinking about the charge in the dipole oscillating back and forth between its two poles, but the poles not moving at all. This is likely the easiest and most sensible place to start the derivation of the rest of dipole radiation. We can plug this into equation \\ref{magpotretard} and have\n\\begin{align}\n    \\textbf{A}(\\textbf{r},t) &= \\frac{\\mu_0}{4\\pi}\\int dr'^3 ~\\frac{\\dot{\\textbf{p}}(t-|\\textbf{r} - \\textbf{r}'|/c)}{|\\textbf{r}-\\textbf{r}'|}\\delta(\\textbf{r}') = \\frac{\\mu_0}{4\\pi}\\frac{\\dot{\\textbf{p}}(t-r/c)}{r}\n\\end{align}\nUsing the Lorenz gauge condition we can find the potential with\n\\begin{align}\n\\varphi &= -c^2 \\int dt \\nabla\\cdot\\textbf{A} \\\\\n&= -\\frac{1}{4\\pi\\epsilon_0}\\int dt \\Big[\\frac{1}{r}\\partial_i \\dot{p}_i + \\dot{p}_i\\partial_i\\frac{1}{r}\\Big]\\\\\n&= -\\frac{1}{4\\pi\\epsilon_0}\\int dt \\Big[\\frac{1}{r}\\ddot{p}_i\\partial_i(t-r/c) - \\dot{p}_i\\frac{1}{r^2}\\partial_i r \\Big]\\\\\n&= \\frac{1}{4\\pi\\epsilon_0}\\int du \\frac{\\ddot{p}_i(u)r_i}{r^2c} + \\frac{\\dot{p}_i(u)r_i}{r^3}\\\\\n\\varphi(\\textbf{r},t) &= \\frac{1}{4\\pi\\epsilon_0}\\Big[\\frac{\\dot{\\textbf{p}}(t-r/c)\\cdot\\textbf{r}}{r^2c} + \\frac{\\textbf{p}(t-r/c)\\cdot\\textbf{r}}{r^3}\\Big]\n\\end{align}\nTo find the field's we have to plug them into the definitions we used to create the potentials first of all with\n\\begin{align}\n    \\textbf{B} = \\nabla\\times\\textbf{A} &&\\textbf{E} = -\\nabla\\varphi -\\frac{\\partial\\textbf{A}}{\\partial t}\n\\end{align}\nThis gives us the fields as\n\\begin{align}\\label{radiationfields}\n    \\textbf{B}(\\textbf{r},t) &= -\\frac{\\mu_0}{4\\pi}\\hat{r}\\times\\Big[\\frac{\\dot{\\textbf{p}}_{ret}}{r^2} + \\frac{\\ddot{\\textbf{p}}_{ret}}{cr}\\Big]\\\\\n    \\textbf{E}(\\textbf{r},t) =\\frac{1}{4\\pi\\epsilon_0}\\Big[\\frac{3\\hat{r}(\\hat{r}\\cdot\\textbf{p}_{ret})-\\textbf{p}_{ret}}{r^3}& + \\frac{3\\hat{r}(\\hat{r}\\cdot\\dot{\\textbf{p}}_{ret})-\\dot{\\textbf{p}}_{ret}}{cr^2} + \\frac{\\hat{r}(\\hat{r}\\cdot\\ddot{\\textbf{p}}_{ret})-\\ddot{\\textbf{p}}_{ret}}{c^2r}\\Big]\n\\end{align}\nThey're pretty gross looking, but can be calculated with tensor notation. the magnetic field is relatively straightforward, the electric field however takes quite a while. The key is to just look at the denominators, so if you are very far away, $r\\gg 0$, then most of the other terms will be near zero. The $1/r$ terms are the fields that are characteristic to radiation, as energy they give off per solid angle is constant. The radiation fields are given by\n\\begin{align}\n    \\textbf{B}(\\textbf{r},t) &= -\\frac{\\mu_0}{4\\pi}\\hat{r}\\times\\Big(\\frac{\\ddot{\\textbf{p}}_{ret}}{cr}\\Big)\\\\\n    \\textbf{E}(\\textbf{r},t) &= \\frac{1}{4\\pi\\epsilon_0}\\Big( \\frac{\\hat{r}(\\hat{r}\\cdot\\ddot{\\textbf{p}}_{ret})-\\ddot{\\textbf{p}}_{ret}}{c^2r}\\Big)\n\\end{align}\n\n\n \n\n\n%\\subsection{Magnetic Dipole Radiation}\n\n %TODO\n\n\\section{Scattering}\nStarting with equation \\ref{powerdistribution}, we can time average it, looking at only the real part of the field, which if we have a sinusoidal field oscillation, gives us\n\\begin{align}\n    \\Big\\langle \\frac{dP}{d\\Omega}\\Big\\rangle = \\frac{1}{2}\\frac{dP}{d\\Omega}\n\\end{align}\nWe can then plug this into the equation for differential scattering cross section\n\\begin{align}\n \\frac{d\\sigma}{d\\Omega} = \\frac{\\langle dP/d\\Omega\\rangle}{\\frac{1}{2}\\epsilon_0c E_0^2}\n \\end{align}\nIntegrating this over the entire solid angle gives us the full cross section, which is essentially how large of an object the incident wave sees when it is first scattered. The algorithm goes as\n\\begin{enumerate}\n    \\item Find the current density, using Newton's laws, etc\n    \\item Plug this into the equation for magnetic potential\n    \\item Plug the time derivative of this into the equation for power radiated per solid angle\n    \\item Plug this into the equation for differential cross section\n    \\item Integrate to find total cross section\n\\end{enumerate}\n\n\n\\subsection{Thomson Scattering}\nThomson scattering is when a plane wave scatters off a single free electron. It is the low energy ($\\omega \\ll mc^2/\\hbar$) limit of Compton Scattering. We first find the current density with Newton's laws for a unbounded particle\n\\begin{align}\n    m\\ddot{\\textbf{x}} = qE_0e^{i\\omega t}\\hat{e_0}\n\\end{align}\nWe plug this into the equation for current density (one electron)\n\\begin{align}\n    \\textbf{j}(t,\\textbf{r}) = q\\dot{\\textbf{x}}\\delta(\\textbf{r}) = \\frac{-iq^2E_0}{m\\omega}e^{i\\omega t}\\hat{e}_0\n\\end{align}\nPlug into equation for magnetic potential, take a derivative, then plug in for average power per solid angle\n\\begin{align}\n\\Big\\langle \\frac{dP}{d\\Omega}\\Big\\rangle = \\frac{1}{2}\\frac{\\mu_0}{c}\\Big(\\frac{q^2E_0^2}{4\\pi m}\\Big)^2 |\\hat{r}\\times\\hat{e}_0|^2\n\\end{align}\nPlug in for cross section\n\\begin{align}\n    \\frac{d\\sigma}{d\\Omega} = \\frac{\\langle dP/d\\Omega\\rangle}{\\frac{1}{2}\\epsilon_0c E_0^2} = \\Big(\\frac{q^2}{4\\pi m \\epsilon_0 c^2} \\Big)^2 | \\hat{r}\\times\\hat{e}_0|^2\n\\end{align}\nIt turns out if we set the rest energy of an electron equation to it's potential energy, we get\n\\begin{align}\n    mc^2 = \\frac{q^2}{4\\pi\\epsilon_0 r_e} & \\rightarrow r_e = \\frac{q^2}{4\\pi\\epsilon_0mc^2}\n\\end{align}\nSo $r_e$ is in some sense the 'radius of the electron' and is technically called the \\emph{classical electron radius}. Plugging this in, our equation becomes\n\\begin{align}\n    \\frac{d\\sigma}{d\\Omega}  = r_e^2|\\hat{r}\\times\\hat{e}_0|^2\n\\end{align}\nWhere $\\hat{r}$ points in the direction of wherever you are observing from, and $\\hat{e}_0$ points in the direction of the electric field polarization of the initial plane wave. An important result is the differential cross section from unpolarized light. If we have the incident wave comes from the $z$ direction and is polarized making an angle $\\gamma$ with the $x$ axis, we can explicitly do the cross product getting.\n\\begin{align}\n    |\\hat{r}\\times\\hat{e}_0|^2 = \\cos^2\\theta + \\sin^2\\theta\\sin^2(\\gamma-\\phi)\n\\end{align}\nWe can average this over the angle $\\gamma$, since it polarized equally in each direction, i.e. not polarized, and get\n\\begin{align}\n    \\frac{d\\sigma}{d\\Omega} = r_e^2|\\hat{r}\\times\\hat{e}_0|^2 &= r_e^2\\Big(\\cos^2\\theta + \\frac{1}{2}\\sin^2\\theta\\Big)\\\\\n    &=\\frac{1}{2}r_e^2\\Big(1 + \\cos^2\\theta\\Big)\n\\end{align}\nWe can integrate this over the entire solid angle and find\n\\begin{align}\n    \\sigma = \\frac{8\\pi}{3}r_e^2\n\\end{align}\nNormally we would think the surface area that a plane wave would see when looking at the electron would just be the area of a circle created by it's projection $\\sigma = \\pi r_e^2$, but it's not for some reason (more in Carter's notes).\n\n\\subsection{Rayleigh Scattering}\nRayleigh scattering is why the sky is blue. This type of scattering happens when the object being scattered off of is much smaller than the wavelength of the light hitting it. In the sky, Nitrogen (the majority of the stuff that makes it up) has a radius of $\\sim 0.155 $ nm whereas blue light has a wavelength of $\\sim 450$ nm. In this regime, over the entire particle, the phase of the light hitting it is all roughly the same, since it is so small.\n\n%TODO - Question 13 Practice Comp Day 2 v 1. \"Electron is bound to a spring with spring constant k\"\n\nRayleigh scattering is also the cause of why some eyes are blue colored. It turns out in blue eyes, there is a low concentration of melanin, which evidently acts like a dipole radiator with power radiated like $\\omega^4$.\\cite{wiki_eye}\n\\subsection{Mie Scattering}\nMie scattering happens when the wavelength incident on the object is comparable with the size of the object itself. This type of scattering is possibly the cause of grey eyes, which have larger deposits of collagen in the stroma, which are larger in size than the melanin. This is analogous to scattering off of clouds vs scattering off the sky itself.\n\nEssentially what happens here is within the entirety of the particle, each 'dipole' is at a different phase, which causes constructive and destructive interference.\n\n\\subsection{Relativistic Electromagnetism}\nKey equations to learn are\n\\begin{align}\n    \\textbf{E}_{||}' &= \\textbf{E}_{||} & \\textbf{E}_\\perp ' &= \\gamma( \\textbf{E}_\\perp + \\textbf{v}\\times\\textbf{B}_\\perp)\\\\\n    \\textbf{B}_{||}' &=\\textbf{B}_{||} & \\textbf{B}_\\perp' &= \\gamma\\Big(\\textbf{B}_\\perp -\\frac{\\textbf{v}\\times\\textbf{E}_\\perp}{c^2}\\Big)\n\\end{align}\nThis says that if we have another frame moving next to us with velocity $\\textbf{v}$, the fields \\emph{parallel} to the direction of travel are exactly the same as the ones they see, but the ones perpendicular the the direction of travel are changed. We can also write the potential and current as a four vector.\n\\begin{align}\nA^\\mu &\\equiv (\\Phi/c, A_x,A_y,A_z)\\\\\nj^{\\mu} &\\equiv (\\rho c, j_x, j_y, j_z)\n\\end{align}\n$\\rho$ is the charge density, $j$ is the current density. Remember the latter equation with the charge conservation formula, which can be written as $\\partial_\\mu j^\\mu = 0$. Gauge invariance can be rewritten as \n$$A'_\\mu = A_\\mu + \\partial_\\mu \\theta$$\nIf you take the derivative of $A'_\\mu$, you get\n\n\\begin{align}\n\\partial_\\nu A'_\\mu &= \\partial_\\nu A_\\mu + \\partial_\\nu \\partial_\\mu \\theta\\\\\n\\implies \\partial_\\nu \\partial_\\mu \\theta &= \\partial_\\mu \\partial_\\nu \\theta\\\\\n\\partial_\\nu A'_\\mu - \\partial_\\nu A_\\mu &= \\partial_\\mu A'_\\nu - \\partial_\\mu A_\\nu \\\\\nF_{\\mu\\nu} \\equiv\\partial_\\mu A'_\\nu - \\partial_\\nu A'_\\mu &= \\partial_\\mu A_\\nu - \\partial_\\nu A_\\mu \\\\\n\\end{align}\nThis invariant tensor is called the \\textit{field strength}. Lets calculate $F_{01}$.\n\n\\begin{align}\nF_{01} &= \\partial_0 A_1 - \\partial_1 A_0\\\\\n &= \\frac{1}{c}\\partial_t A_x + \\partial_x \\Phi/c\\\\\n &= -E_x/c\n\\end{align}\n\nThe rest of the differentiation yields this invariant traceless, antisymmetric matrix to be\n\n$$F_{\\mu\\nu} = \\left({\\begin{array}{cccc}\n0&-E_1/c & -E_2/c & -E_3/c\\\\\nE_1/c& 0 & B_3 & -B_2 \\\\\nE_2/c& -B_3 & 0 & B_1 \\\\\nE_3/c& B_2 & -B_1 & 0\n\\end{array}}\\right)$$\n\nYou can find $F^{\\mu\\nu}$ by simply multiplying the first column and first row by $-1$\n$$\\partial_\\mu F^{\\mu\\nu} = j^\\nu$$\n\n\n\n\n \n \\subsection{Lienard-Wiechert Potentials}\n The Lienard Wiechert potentials come directly from Maxwell's equations, but happen to be relativistically correct. They describe the potentials of a moving point charge. Due to Lorentz contraction (Equation \\ref{lorentzcontract}) of the dimension in which the particle is traveling, The distance between \n \n \\begin{align}\n    \\varphi(\\textbf{r},t) &= \\frac{1}{4\\pi\\epsilon_0}\\Big(\\frac{q}{(1-\\hat{n}\\cdot\\frac{\\textbf{v}}{c})|\\textbf{r}-\\textbf{r}'|} \\Big)_{t_{r}}\\\\\n    \\textbf{A}(\\textbf{r},t) &= \\frac{\\textbf{v}(t_r)}{c^2}\\varphi(\\textbf{r},t)\n \\end{align}\n Where $\\hat{n} = \\frac{\\textbf{r}-\\textbf{r}'}{|\\textbf{r}-\\textbf{r}'|}$\n\n", "meta": {"hexsha": "7a1fbd50e7cd7338e010761dba235909472a494d", "size": 57064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics/electromagnetism.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/electromagnetism.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/electromagnetism.tex", "max_forks_repo_name": "williamnash/notes", "max_forks_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.1783567134, "max_line_length": 820, "alphanum_fraction": 0.7145135287, "num_tokens": 18935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6709373329178472}}
{"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{noisecg}\n\\section*{\\hspace*{-1.6cm} noisecg}\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}\nAnalytic complex gaussian noise (white or colored).\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}\nnoise = noisecg(N)\nnoise = noisecg(N,a1)\nnoise = noisecg(N,a1,a2)\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 noisecg} computes an analytic complex gaussian\n        noise of length {\\ty N} with mean 0 and variance 1.0. \\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c} Name &\nDescription & Default value\\\\ \\hline {\\ty N} & length of the output\nvector\\\\ {\\ty a1} & first coefficient of the auto-regressive filter used to\ncolor the noise & {\\ty 0} \\\\ {\\ty a2} & second coefficient of the\nauto-regressive filter used to color the noise & {\\ty 0} \\\\ \\hline {\\ty\nnoise} & output vector containing the noise samples\\\\ \\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\n{\\ty noise=noisecg(N)} yields a complex white gaussian noise.\\\\\n \n{\\ty noise=noisecg(N,a1)} yields a complex colored gaussian noise obtained\nby filtering a white gaussian noise through a first order filter whose\nimpulse response is \n\\[H(z)\\ =\\ \\frac{\\sqrt{1-a_1^2}}{1-a_1\\ z^{-1}}.\\]\n \n{\\ty noise=noisecg(N,a1,a2)} yields a complex colored gaussian noise\nobtained by filtering a white gaussian noise through a second order filter whose\nimpulse response is \n\\[H(z)\\ =\\ \\frac{\\sqrt{1-a_1^2-a_2^2}}{1-a_1\\ z^{-1}-a_2\\ z^{-2}}.\\]\n \n\\end{minipage}\n\n\\newpage\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         N=500; noise=noisecg(N);\n         [abs(mean(noise)),std(noise).^2]\n         ans = \n               0.0152    0.9680\n\n         subplot(211); plot(real(noise)); axis([1 N -3 3]);\n         subplot(212); f=linspace(-0.5,0.5,N); \n         plot(f,abs(fftshift(fft(noise))).^2);\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}\nrand, randn, noisecu.\n\\end{verbatim}\n\\end{minipage}\n\n", "meta": {"hexsha": "1f28124026257f5131b084134a4dd341d7581613", "size": 2341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/noisecg.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/noisecg.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/noisecg.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.6022727273, "max_line_length": 80, "alphanum_fraction": 0.6578385305, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6709219875938554}}
{"text": "\\documentclass{mrl}\n\n\\title{Sets of spent outputs}\n\\authors{Sarang Noether\\footnote{\\texttt{sarang.noether@protonmail.com}}}\n\\affiliations{Monero Research Lab}\n\\date{\\today}\n\n\\type{TECHNICAL NOTE}\n\\ident{MRL-0007}\n\n\\newtheorem{definition}{Definition}\n\\newtheorem{example}{Example}\n\n\\begin{document}\n\n\\begin{abstract}\nThis technical note generalizes the concept of spent outputs using basic set theory. The definition captures a variety of earlier work on identifying such outputs. We quantify the effects of this analysis on the Monero blockchain and give a brief overview of mitigations.\n\\end{abstract}\n\n\\section{Introduction}\nTransactions in Monero generate \\textit{outputs} (sometimes called \\textit{notes} in other literature) destined for a set of recipients by consuming one or more existing outputs under the sender's control. For each spent output in the transaction, the sender chooses a collection of arbitrary outputs from the blockchain into a \\textit{ring}. The transaction includes a proof that for each ring, any of the ring's outputs is equiprobable as the spent output. A \\textit{key image} (also called a \\textit{tag} in other literature) is included to ensure that no spent output has been spent in any previous transaction.\n\nIt is important for sender anonymity that no output in a ring is otherwise known to have been spent from external information. If an output is known to be spent, an observer can reduce the effective size of the ring as an anonymity set. If this process continues with enough outputs, the true spent output may be identified. We stress that Monero outputs cannot be linked to the wallet address of the sender, providing an additional layer of protection.\n\nAt Monero's launch, senders could choose any ring size, including a ring containing only a single output; this output is obviously the true spend. With this information, it is possible to deduce other spent outputs in small rings. Later protocol upgrades added consensus-enforced minimum ring sizes that have increased over time. These increases, as well as a transition to outputs with confidential amounts, have all but eliminated the effects of these early trivial rings. However, it is possible to generate more complex sets of rings that together reveal spent outputs, even though it may not be possible to identify which transaction spent such an output.\n\nIn this technical note, we define the idea of a spent output in a general way using basic set theory. We show that this definition captures several known methods for spent output identification. Using a tool available to all Monero users, we quantify the occurrence of many spent outputs on the Monero blockchain, showing that modern transactions are essentially unaffected by them.\n\nIndependent concurrent work in \\cite{unpub1,unpub2} (to appear) makes a similar definition and provides a somewhat more general algorithm for identifying certain spent outputs, as well as performing formal analysis.\n\n\\section{Definition}\nLet $\\mathcal{N}$ be the (finite) set of all outputs on a blockchain. We define a \\textit{ring} as a subset of $\\mathcal{N}$. A ring containing exactly $n$ elements is an $n$\\textit{-ring}. We often use lowercase letters as generic outputs.\n\n\\begin{definition}\nLet $\\{R_i\\}_{i=1}^n$ be a set of rings. We say each $R_i$ is \\textit{spent} if $$\\left| \\bigcup_{i=1}^n R_i \\right| = n.$$ An output is \\textit{spent} if it is an element of a spent ring.\n\\end{definition}\n\n\\begin{example}\nLet $R = \\{a\\}$ be a 1-ring. Then the output $a$ (and $R$ itself) is spent.\n\\end{example}\n\n\\begin{example}\nLet $R = \\{a,b\\}$ and $S = \\{b,c\\}$ and $T = \\{a,c\\}$ be rings. Then each output (and ring) is spent.\n\\end{example}\n\n\\section{Specific cases}\nEarlier work like in \\cite{mrl0001,mrl0004,kumar,moser,wijaya} has suggested several classes of spent outputs. We review some of them briefly and show how they fit into our definition.\n\n\\subsection{Chain reaction}\nThe so-called \\textit{chain reaction} method uses trivial rings to iteratively identify spent outputs. This method first marks all 1-rings as spent, and removes the corresponding outputs from all other rings. It repeats this process until no 1-rings remain. The initial presentations of this method were also identified in the context of an active attack, where the adversary spends many outputs in 1-rings in an attempt to identify honest users' spent outputs.\n\nAt the end of the iteration process, each spent ring contributes a single unique spent output that was the last such identified output in the ring. This means the collection of all such spent rings matches our definition.\n\n\\subsection{Ring repetition}\nThe so-called \\textit{ring repetition} method uses multiple appearances of the same ring to identify spent outputs. This method simply identifies a collection of $n$ separate $n$-rings containing the same outputs, where we can conclude that the ring is spent. This analysis was initially presented as semi-cooperative attack, where an adversary generates ring repetitions of controlled outputs to signal to other adversarial users that the ring is spent.\n\nThis method trivially matches our definition.\n\n\\subsection{Subset analysis}\nThe standard Monero toolset includes an optional blackball tool that scans the blockchain and flags certain classes of spent outputs. In addition to the chain reaction and ring repetition methods, the tool can also perform a \\textit{subset analysis}. In this method, the tool iterates over each ring. For each of the $2^n-1$ (nonempty) subsets of an $n$-ring $R$, it counts the number of occurrences of the subset as a standalone ring elsewhere. If the sum of all such counts for subsets of $R$ is exactly $n$, it flags $R$ as spent.\n\nThis method trivially matches our definition.\n\n\\subsection{Other analysis}\nAbsent other information, our definition completely captures on-chain spent outputs. However, other sources exist in practice that may be used to flag outputs as spent, either by attackers or by users who wish to avoid selecting such outputs in new rings.\n\n\\begin{itemize}\n\\item \\textbf{Chain forks}: In the event of a chain fork, a user may choose to spend the same output on multiple forks. The construction of Monero key images means that each spend of the same output will yield the same key image. An observer who sees distinct rings on multiple forks with the same key image can conclude that the spent output must appear in the intersection of all such rings, which statistically is likely to reveal the spent output. Observe that this analysis is beyond the scope of our definition.\n\\item \\textbf{Output age distribution}: A variety of heuristics exist that may give an adversary a statistical advantage in guessing the spent output in a ring. For example, spend analysis on transparent blockchains suggests that recently-generated outputs are more likely to be spent than older outputs. We note that in practice, selection of non-spent ring elements according to a distribution matching expected spend patterns easily mitigates the effectiveness of this particular heuristic. There exist other heuristics that we do not consider here. Such heuristics do not inherently provide proof that a given output is spent, and are beyond the scope of our definition. \n\\end{itemize}\n\n\\section{Mitigations}\nIt is possible in theory for each user to scan her copy of the blockchain, identify all spent outputs using whatever information sources are available, and ensure that she does not choose spent outputs as ring members in future transactions. However, a complete set-theoretic characterization using our definition is impractical. Even the use of an integrated blackball tool that performs only a partial analysis may take several hours for a recent snapshot of the Monero blockchain, and would need to be regularly updated for maximal privacy.\n\nFortunately, the risk to users of spent output identification is negligible. Early chain reaction effects among small rings dissipated quickly early in the Monero blockchain's history. As mandatory minimum ring sizes have increased, the likelihood of an accidental ring union producing a set of spent outputs is vanishingly small. While an attacker could generate collections of rings maliciously designed to produce spent outputs, a non-cooperating attacker may need to perform intensive computations to detect them; further, the generating attacker can always identify her own controlled outputs regardless of their association with other rings, making such an attack unlikely to be of additional value since it costs the attacker fees.\n\nThe number of spent outputs produced from a chain fork depends highly on the number of existing outputs spent on multiple chains, and requires a large fraction of the existing network to participate. Further, modern selection algorithms for ring members strongly favor newer outputs, meaning the effects of a fork dissipate quickly over time. In practice, the combination of these effects renders them generally impractical.\n\nTo quantify these effects, we analyzed the Monero blockchain in October 2018 using the integrated blackball tool. This tool examined several classes of spent outputs:\n\\begin{itemize}\n\\item outputs included in 1-rings\n\\item outputs in repeated rings (discussed above)\n\\item outputs identified by subset analysis (discussed above)\n\\item outputs identified by chain reaction analysis (discussed above)\n\\end{itemize}\nWe further classify these outputs by whether they use confidential amounts. Modern transactions choose only decoys that use confidential amounts. Table \\ref{table:spent} shows the results of this analysis.\n\n\\begin{table}[ht]\n\\begin{center}\n\\begin{tabular}{rrr}\n& Legacy outputs & Confidential outputs \\\\\n\\hline\n1-ring & 12147067 & 0 \\\\\nRepeated & 40 & 5 \\\\\nSubset & 5916927 & 0 \\\\\nChain reaction & 749688 & 0 \\\\\n\\hline\nTotal spent outputs & 18813722 & 5 \\\\\nTotal outputs on chain & 21850122 & 7445622 \\\\\n\\end{tabular}\n\\caption{Spent output analysis for Monero blockchain as of October 2018 using integrated blackball tool}\n\\label{table:spent}\n\\end{center}\n\\end{table}\n\nWhile the analysis shows that 86\\% of all non-confidential outputs are identified as spent, 0\\% of confidential outputs are. Since modern transactions only use the latter type as decoys, the effects of spent output analysis on anonymity is completely negligible.\n\n\\section{Conclusion}\nWe have presented a simple set-theoretic definition that completely characterizes spent outputs on the Monero blockchain given only set information about the ring elements themselves. This definition captures and generalizes other analysis presented elsewhere. While this definition does not address external information from sources like forked chains or temporal analysis, it offers insight into the selection of outputs toward optimal spend anonymity. While a complete analysis of all spent outputs on the Monero blockchain is computationally infeasible, we quantified several known classes of spent outputs and determined that modern transactions are unaffected by them.\n\n\\bibliographystyle{plain}\n\\nocite{*}\n\\bibliography{refs}\n\n\\end{document}\n", "meta": {"hexsha": "830a0bb7b354573d4d887abfb861ae1e9c9d9cac", "size": 11119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/bulletins/MRL-0007-spent/main.tex", "max_stars_repo_name": "SarangNoether/research-lab", "max_stars_repo_head_hexsha": "f6ce10547aa721c6dcd0f65f2ef89a6a5e9b34b0", "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-0007-spent/main.tex", "max_issues_repo_name": "SarangNoether/research-lab", "max_issues_repo_head_hexsha": "f6ce10547aa721c6dcd0f65f2ef89a6a5e9b34b0", "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-0007-spent/main.tex", "max_forks_repo_name": "SarangNoether/research-lab", "max_forks_repo_head_hexsha": "f6ce10547aa721c6dcd0f65f2ef89a6a5e9b34b0", "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": 95.8534482759, "max_line_length": 738, "alphanum_fraction": 0.8014209911, "num_tokens": 2380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6709051185560577}}
{"text": "% !TEX options=--shell-escape\n\\documentclass [12pt]{article} \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\\usepackage{csquotes}\n\\usepackage[cache=false]{minted}\n\\usepackage{mdframed}\n\\usepackage{tikz}\n\\usetikzlibrary{shapes.symbols}\n\\newtheorem{theorem}{Theorem}\n\n\\DeclareTColorBox {Solution}{}{breakable, title={Solution}}\n\\DeclareTColorBox {Solution*}{}{breakable, title={Solution (provided)}}\n\\DeclareTColorBox {Instruction}{}{boxrule=0pt, boxsep=0pt, left=0.5em, right=0.5em, top=0.5em, bottom=0.5em, arc=0pt, toprule=1pt, bottomrule=1pt}\n\\DeclareDocumentCommand {\\Expecting }{+m}{\\textbf {[We are expecting:} #1\\textbf {]}}\n\\DeclareDocumentCommand {\\Points }{m}{\\textbf {(#1 pt.)}} \n\\newcommand {\\hint }[1]{\\noindent {[\\textbf {HINT:} \\em #1 \\em ]}} \\newcommand {\\pts }[1]{\\textbf {(#1 pt.)}} \n\n\\begin{document} \n\n{\\LARGE \\textbf {COMP 285 (NC A\\&T, Spr `22)}\\hfill \\textbf {Weekly Quiz 2} } \n\n\\begin{Instruction}\n\n\\paragraph{Reporting Issues} If you find any issues with the solutions, reach out to Chi Wang (author) or Luis Perez (reviewer).\n\n\\end{Instruction}\n\n\n\\section{} Which of the following is the correct recurrence relations for MergeSort?\n\n\\begin{Solution}\n$T(n) = 2 \\cdot T\\left(\\frac{n}{2}\\right) + O(n)$\n\\paragraph{} \n For each step, MergeSort divides the original problem by two, recursively calling itself to solve these two smaller problems. This is where $2 \\cdot T(n)$ comes from. Once it has the answers, it merges the results which takes an additional $O(n)$ time, giving the recurrence above.\n\\end{Solution}\n\n\n\\section{} What's the closed-form solution for the running time of the following recurrence relation $T(n) = 5 \\cdot T\\left(\\frac{n}{3}\\right) + O(n)$ (Hint: You might want to use the Master Theorem) (Aside: This is the actual recurrence relation of Strassen's Multiplication Algorithm, an improvement to Karatsuba's)\n\n\\begin{Solution}\n$$\nO(n^{\\log_3 5})\n$$\n\nWe can see that $a=5, b=3, d=1, a=5 > b^d=3$, so the result would be  $O(n^{\\log_b a})$ = $O(n^{\\log_3 5})$ according to the Master Theorem.\n\\end{Solution}\n\n\n\\section{} What's the closed-form solution for the running time of the following recurrence relation $T(n) = T\\left(\\frac{999n}{1000}\\right) + O(n)$ (Hint: You might want to use the Master Theorem).\n\n\\begin{Solution}\n$$O(n)$$\n\n$a=1, b=\\frac{1000}{999}, d=1, a=1 < b^d=\\frac{1000}{999}$, so the result would be $O(n)$ according to the Master Theorem.\n\\end{Solution}\n\n\n\\section{} Select the recurrence relations below for which you CANNOT directly apply the Master Theorem.\n\n\\begin{Solution}\n\\begin{itemize}\n  \\item $T(n) = 2T(n-1) + O(n^2)$ because were are creating smaller problems of size $n - 1$. The Master Theore only works when the problems become a fraction of their original size.\n  \\item $T(n) = 4T\\left(\\frac{9n}{10}\\right) + O(n \\log n)$ because the additional work we do to combine the problems is not polynomial (eg, $n^d$) but $n \\log n$.\n  \\item $T(n) = T\\left(\\frac{n}{5}\\right) + T\\left(\\frac{7n}{10}\\right) + O(n)$ because we don't split the original problem into subproblems of equal size.\n\\end{itemize}\n\\end{Solution}\n\n\n\\section{} There is an $O(n)$ time algorithm for the k-Select Problem.\n\n\\begin{Solution}\nYes. Use divide-and-conquer recursive-based solution as we covered in class.\n\\end{Solution}\n\n\n\\section{} What is the running time of a mergesort-based solution to the k-Select problem?\n\n\\begin{Solution}\n$$\\Theta(nlogn)$$\n\nMergeSort will take $\\Theta(n \\log n)$ time.\n\\end{Solution}\n\n\n\\section{} In our divide-and-conquer recursive-based solution to the k-Select problem, what is the running time if we always pick the minimum as the pivot.\n\n\\begin{Solution}\n$$\\Theta(n^2)$$\nIf we always pick the minimum(worst-case pivot), we are unable to divide the problem into half each time. The recurrence relation will be $T(n) = T(n-1) + O(n)$ which will end-up with a running time of $O(n^2)$.\n\\end{Solution}\n\n\n\\section{} In our divide-and-conquer recursive-based solution to the k-Select problem, what is the running time if we always pick the median as the pivot.\n\n\\begin{Solution}\n$$\\Theta(n)$$\n\\paragraph{} \nIf we always pick the median(best-case pivot), we can divide the problem into half each time. The recurrence relation will be $T(n) = T\\left(\\frac{n}{2}\\right) + O(n)$ which is $O(n)$ by the Master Theorem.\n\\end{Solution}\n\n\n\\section{} The running time of our trivial implementation of k-Select using MergeSort is always slower than the running time of a divide-and-conquer solution that randomly selects the pivot element.\n\n\\begin{Solution}\nFalse\n\\paragraph{} \nThe running time of k-Select using MergeSort is $\\Theta(n \\log n)$, and in worst-case the divide-and-conquer solution would take $\\Theta(n^2)$ time, which is slower than $\\Theta(n \\log n)$.\n\\end{Solution}\n\n\n\\section{} In practice, it's often best to simply pick the pivot randomly rather than implement a more sophisticated, deterministic pivot selection method.\n\n\\begin{Solution}\nTrue\n\\paragraph{} \nIf there is a bad guy who gets to see our pivot choices, that’s just as bad as the worst-case pivot.\n\n\\end{Solution}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\end{document} ", "meta": {"hexsha": "d977ebfffdadf05da46bffa50dbabcd588347b5b", "size": 5788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/quizzes/quiz2.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/quizzes/quiz2.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/quizzes/quiz2.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": 35.7283950617, "max_line_length": 317, "alphanum_fraction": 0.7180373186, "num_tokens": 1694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8991213840277783, "lm_q1q2_score": 0.6708695342420264}}
{"text": "\\section{Model counting}\n\\label{sect:background-model-counting}\n\n\\subsection{Exact/Approximate model counting}\nThe \\textit{model counting}~\\cite{SATHandbook-ModelCounting} problem asks to find the number of the satisfying assignments of a Boolean formula $\\pf$.\nThe exact algorithms compute the precise count $\\#\\pf$ of the satisfying assignments.\nThe approximate algorithms compute bounds of the precise count $\\#\\pf$ with a confidence level.\nOne common formulation is the $(\\epsilon,\\delta)$ approximate model counting,\nwhich asks to find an answer that is sufficiently close to the precise count with high enough probability.\nThis formulation can be characterized by the inequality\n$\\spb{(1+\\epsilon)^{-1}\\#\\pf\\leq A\\leq (1+\\epsilon)\\#\\pf}\\geq 1-\\delta$,\nwhere the parameters $\\epsilon$ and $\\delta$ can be configured to trade precision against scalability.\n\n\\subsection{Weighted model counting}\nThe weighted version asks to compute the weight of a formula $\\pf$ given a weighting function $\\wt:\\vf{\\pf}\\mapsto[0,1]$.\nThe weight of a positive literal $x$ (resp. a negative literal $\\lnot x$) is defined to be $\\wt(x)$ (resp. $1-\\wt(x)$).\nThe weight of an assignment $\\as$, denoted as $\\wt(\\as)$, equals the product of the weights of its individual literals.\nThe weight of the formula $\\pf$, denoted as $\\wt(\\pf)$, is the summation of the weights of its satisfying assignments.", "meta": {"hexsha": "492e2aaca2c911d8da25129e55b55cc2922a86bb", "size": 1379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background/model-counting.tex", "max_stars_repo_name": "nianzelee/PhD-Dissertation", "max_stars_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-11T19:38:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T19:38:13.000Z", "max_issues_repo_path": "paper/background/model-counting.tex", "max_issues_repo_name": "nianzelee/PhD-Dissertation", "max_issues_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/background/model-counting.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": 76.6111111111, "max_line_length": 150, "alphanum_fraction": 0.7606961566, "num_tokens": 332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6707477699296592}}
{"text": "\\chapter[Finite differences in 1D]{Finite differences for \\\\ \nstationary problems in 1D}\n\\label{chap: finite diff 1d}\nWe begin our study of numerical methods for partial differential equations \n(PDEs) by treating the one-dimensional (1D) case, which means we deal only with \nan \\emph{ordinary} differential equation (ODE).  Moreover, in this chapter we \nlimit our attention to \\emph{two-point boundary-value problems} for \n\\emph{second-order} ODEs.  In fact, we will focus mostly on the very simple \nmodel problem on the interval~$[0,L]$,\n\\begin{equation}\\label{eq: model 1d}\n-u''=f(x)\\quad\\text{for $0<x<L$,}\n\t\\quad\\text{with $u(0)=\\gamma_0$ and $u(L)=\\gamma_L$,}\n\\end{equation}\nin which the \\emph{source term}~$f(x)$ and \\emph{boundary data} $\\gamma_0$, \n$\\gamma_L$ are given, and we seek the \\emph{unknown solution}~$u(x)$.  The \nsimplest physical interpretation of~\\eqref{eq: model 1d} is as a steady-state \nheat equation, so that $u(x)$ is the temperature at~$x$ and $f(x)$ gives the \ndensity of heat sources.\n\nFor a constant source term~$f(x)=c$, the solution is given by\n\\begin{equation}\\label{eq: u const f}\nu(x)=\\frac{1}{L}\\bigl((L-x)\\gamma_0+x\\gamma_L\\bigr)+\\frac{c}{2}\\,x(L-x)\n\t\\quad\\text{for $0\\le x\\le L$;}\n\\end{equation}\nsee Exercise~\\ref{ex: u const f} and Figure~\\ref{fig: bvp 1d f const}. For a \ngeneral~$f$, Exercise~\\ref{ex: variation of params} shows that\n\\begin{equation}\\label{eq: model 1d exact soln}\nu(x)=\\frac{L-x}{L}\\biggl(\\gamma_0+\\int_0^x yf(y)\\,dy\\biggr)\n\t+\\frac{x}{L}\\biggl(\\gamma_L+\\int_x^L(L-y)f(y)\\,dy\\biggr)\n\t\\quad\\text{for $0\\le x\\le L$.}\n\\end{equation}\nOur aim in this chapter is to study finite difference methods for computing \na numerical approximation to the values of~$u$ at a set of grid points in the \ninterval~$[0,L]$.\n\n\\begin{figure}\n\\caption{Solutions of the simple two-point boundary-value \nproblem~\\eqref{eq: model 1d} with $L=1$ and right-hand side~$f(x)=c$, for \nvarious choices of the constant~$c$.}\\label{fig: bvp 1d f const}\n\\begin{center}\n\\includegraphics[scale=0.75]{../src/chap1/bvp1d_const_rhs.pdf}\n\\end{center}\n\\end{figure}\n\n\\section{Second-order central difference}\nTo derive a finite difference approximation to the second derivative~$u''(x)$, \nwe will use Taylor's theorem in the following form.\n\n\\begin{theorem}\\label{thm: Taylor remainder}\nLet $h>0$. If $f$ is $C^{k+1}$ on the closed interval~$[x,x+h]$ then\n\\begin{equation}\\label{eq: Taylor 1}\nf(x+h)=\\sum_{j=0}^k\\frac{1}{j!}\\,f^{(j)}(x)\\,h^j+(R_kf)(x,h),\n\\end{equation}\nwhere the remainder term is given by\n\\begin{equation}\\label{eq: Taylor 2}\n(R_kf)(x,h)=\\frac{1}{k!}\\int_x^{x+h}(x+h-y)^kf^{(k+1)}(y)\\,dy\n\\end{equation}\nand satisfies\n\\begin{equation}\\label{eq: Taylor 3}\n|(R_kf)(x,h)|\\le\\frac{h^{k+1}}{(k+1)!}\\,\\max_{x\\le y\\le x+h}|f^{(k+1)}(y)|.\n\\end{equation}\nSimilarly, if $f$ is $C^{k+1}$ on~$[x-h,x]$, then\n\\[\nf(x-h)=\\sum_{j=0}^k\\frac{(-1)^j}{j!}\\,f^{(j)}(x)\\,h^j+(R_kf)(x,-h)\n\\]\nwhere \n\\[\n(R_kf)(x,-h)=\\frac{(-1)^{k+1}}{k!}\\int_{x-h}^x(y+h-x)^kf^{(k+1)}(y)\\,dy\n\\]\nand\n\\[\n|(R_kf)(x,-h)|\\le\\frac{h^{k+1}}{(k+1)!}\\,\\max_{x-h\\le y\\le x}|f^{(k+1)}(y)|.\n\\]\n\\end{theorem}\n\\begin{proof}\nWe use induction on~$k$.  If $k=0$, then the formulae \n\\eqref{eq: Taylor 1}~and \\eqref{eq: Taylor 2} reduce to\n\\[\nf(x+h)=f(x)+(R_0f)(x,h)\\quad\\text{where}\\quad\n(R_0f)(x,h)=\\int_x^{x+h}f'(y)\\,dy,\n\\]\nwhich follows from the fundamental theorem of calculus.  Let $k\\ge0$ and make \nthe induction hypothesis that \\eqref{eq: Taylor 1} holds with $R_kf$ given \nby~\\eqref{eq: Taylor 2}.  Integrating by parts, we have\n\\begin{align*}\n(R_kf)(x,h)&=\\biggl[\n\t-\\frac{(x+h-y)^{k+1}}{(k+1)!}\\,f^{(k+1)}(y)\\biggr]_{y=x}^{x+h}\n\t+\\int_x^{x+h}\\frac{(x+h-y)^{k+1}}{(k+1)!}\\,f^{(k+2)}(y)\\,dy\\\\\n\t&=\\frac{h^{k+1}}{(k+1)!}\\,f^{(k+1)}(x)+(R_{k+1}f)(x,y),\n\\end{align*}\nimplying that \\eqref{eq: Taylor 1}~and \\eqref{eq: Taylor 2} hold with~$k$\nreplaced by~$k+1$, as required.  The estimate~\\eqref{eq: Taylor 3} is an \nimmediate consequence of the inequality\n\\begin{align*}\n|(R_kf)(x,y)|&\\le\\int_x^{x+h}\\frac{(x+h-y)^k}{k!}\\,|f^{(k+1)}(y)|\\,dy\\\\\n\t&\\le\\biggl(\\max_{x\\le y\\le x+h}|f^{(k+1)}(y)|\\biggr)\n\t\\int_x^{x+h}\\frac{(x+h-y)^k}{k!}\\,dy.\n\\end{align*}\nThe expansion for~$f(x-y)$ and the bound for~$(R_kf)(x,-h)|$ follow in a \nsimilar fashion.\n\\end{proof}\n\n\nA straight forward manipulation of such Taylor expansions shows that\n\\[\nf''(x)=\\frac{f(x+h)-2f(x)+f(x-h)}{h^2}+O(h^2)\\quad\\text{as $h\\to0$;}\n\\]\nmore precisely, the following result holds.\n\n\\begin{theorem}\\label{thm: 2nd central diff}\nIf $f$ is $C^4$ on the closed interval~$[x-h,x+h]$, then\n\\[\n\\biggl|f''(x)-\\frac{f(x+h)-2f(x)+f(x-h)}{h^2}\\biggr|\\le\\frac{h^2}{12}\n\t\\max_{x-h\\le y\\le x+h}|f^{(4)}(y)|.\n\\]\n\\end{theorem}\n\\begin{proof}\nSince\n\\[\nf(x+h)=f(x)+f'(x)h+\\tfrac12f''(x)h^2+\\tfrac{1}{3!}f'''(x)h^3+(R_3f)(x,h)\n\\]\nand\n\\[\nf(x-h)=f(x)-f'(x)h+\\tfrac12f''(x)h^2-\\tfrac{1}{3!}f'''(x)h^3+(R_3f)(x,-h)\n\\]\nwe see that\n\\[\nf(x+h)+f(x-h)=2f(x)+f''(x)h^2+(R_3f)(x,h)+(R_3f)(x,-h).\n\\]\nThus,\n\\begin{equation}\\label{eq: second diff remainder}\n\\frac{f(x+h)-2f(x)+f(x-h)}{h^2}-f''(x)=\\frac{(R_3f)(x,h)+(R_3f)(x,-h)}{h^2}\n\\end{equation}\nand since\n\\begin{align*}\n|(R_3f)(x,h)+(R_3f)(x,-h)|&\\le\n\\frac{h^4}{4!}\\max_{x\\le y\\le x+h}|f^{(4)}(y)|\n+\\frac{h^4}{4!}\\max_{x-h\\le y\\le x}|f^{(4)}(y)|\\\\\n\t&\\le\\frac{2h^4}{4!}\\,\\max_{x-h\\le y\\le x+h}|f^{(4)}(y)|\n\\end{align*}\nthe result follows.\n\\end{proof}\n\nTo set up a finite difference scheme for~\\eqref{eq: model 1d}, we choose a \npositive integer~$P$ and define a uniform grid on~$[0,L]$,\n\\[\nx_p=p\\,\\Delta x\\quad\\text{for $0\\le p\\le P$,}\n\t\\quad\\text{where $\\Delta x=\\frac{L}{P}$.}\n\\]\nIn this way, we divide $[0,L]$ into $P$~subintervals, namely $[x_{p-1},x_p]$\nfor~$1\\le p\\le P$, each of length~$\\Delta x$.  The finite difference solution \nconsists of $P+1$ numbers $U_0$, $U_1$, \\dots, $U_P$ that approximate $u(x)$ at \nthe $P+1$ grid points, that is,\n\\[\nU_p\\approx u(x_p)\\quad\\text{for $0\\le p\\le P$.}\n\\]\nNoting that $x_{p\\pm1}=x_p\\pm\\Delta x$, we have\n\\begin{equation}\\label{eq: u'' approx}\n\\frac{u(x_{p+1})-2u(x_p)+u(x_{p-1})}{\\Delta x^2}\n\t=\\frac{u(x_p+\\Delta x)-2u(x_p)+u(x_p-\\Delta x)}{\\Delta x^2}\n\t\\approx u''(x_p)\n\\end{equation}\nwhich suggests the following discrete approximation to the ODE $-u''=f(x)$,\n\\begin{equation}\\label{eq: model 1d discrete}\n-\\frac{U_{p+1}-2U_p+U_{p-1}}{\\Delta x^2}=f(x_p)\\quad\\text{for $1\\le p\\le P-1$.}\n\\end{equation}\nWe can satisfy the boundary conditions $u(x_0)=u(0)=\\gamma_0$ and \n$u(x_P)=u(L)=\\gamma_L$ exactly, by putting\n\\[\nU_0=\\gamma_0\\quad\\text{and}\\quad U_P=\\gamma_L.\n\\]\nWhen~$p=1$ in~\\eqref{eq: model 1d discrete} we move $U_0=\\gamma_0$ to the \nright-hand side, \n\\[\n\\frac{2U_1-U_2}{\\Delta x^2}=f(x_1)+\\frac{\\gamma_0}{\\Delta x^2},\n\\]\nand similarly when $p=P-1$ we move $U_P=\\gamma_L$ to the right-hand side,\n\\[\n\\frac{-U_{P-2}+2U_{P-1}}{\\Delta x^2}=f(x_{P-1})+\\frac{\\gamma_L}{\\Delta x^2}.\n\\]\n\n\\begin{figure}\n\\caption{Comparison of exact solution and its finite difference approximation\nfrom Example~\\ref{example: bvp1d example}.}\\label{fig: bvp1d example}\n\\begin{center}\n\\includegraphics[scale=0.75]{../src/chap1/bvp1d_example.pdf}\n\\end{center}\n\\end{figure}\n\n\\begin{example}\\label{example: bvp1d example}\nIf $P=6$ then the finite difference scheme results in a $5\\times5$ \nlinear system\n\\begin{equation}\\label{eq: model 1d linear system}\n\\frac{1}{\\Delta x^2}\\begin{bmatrix}\n 2&-1&  & &\\\\\n-1& 2&-1& &\\\\\n  &-1& 2&-1&\\\\\n  &  &-1& 2&-1\\\\\n  &  &  &-1& 2\n\\end{bmatrix}\n\\begin{bmatrix}U_1\\\\ U_2\\\\ U_3\\\\ U_4\\\\ U_5\\end{bmatrix}\n=\\begin{bmatrix}f_1\\\\ f_2\\\\ f_3\\\\ f_4\\\\ f_5 \\end{bmatrix}\n+\\frac{1}{\\Delta x^2}\n\\begin{bmatrix}\\gamma_0\\\\ 0\\\\ 0 \\\\ 0\\\\ \\gamma_L \\end{bmatrix},\n\\end{equation}\nwhere, for brevity, we have written $f_p=f(x_p)$.  Also, the zero entries in \nthe coefficient matrix are left blank.  The problem\n\\[\n-u''=5e^{-x}\\quad\\text{for $0\\le x\\le2$,}\n    \\quad\\text{with $u(0)=-1$ and $u(2)=5/2$,}\n\\]\nhas the solution\n\\[\nu(x)=A+Bx+5e^{-x}\\quad\n\\text{where $A=\\gamma_0+5$ and $B=(\\gamma_L-A-5e^{-L})$.}\n\\]\nFigure~\\ref{fig: bvp1d example} shows that $U_p$ does in fact provide a \nreasonable approximation to~$u(x_p)$ in this case using only $P=6$~subintervals.\n\\end{example}\n\nSeveral questions arise naturally with regard to the above numerical method.\n\\begin{enumerate}\n\\item Does the linear system arising from the finite difference approximation \nalways have a unique solution?\n\\item If so, what is an efficient way to compute the $U_p$?\n\\item How accurate is the approximation~$U_p\\approx u(x_p)$?\n\\item Does the error $U_p-u(x_p)$ tend to zero if~$\\Delta x\\to0$, and if so how \nrapidly?\n\\end{enumerate}\nThe following sections will address these concerns.\n\n\\section{Symmetric tridiagonal linear systems}\n\\label{sec: sym tridiagonal}\nHow can we solve a symmetric, tridiagonal linear system such as the one\n\\eqref{eq: model 1d linear system} arising from the finite difference \nscheme~\\eqref{eq: model 1d discrete}?  To discuss this problem, consider a \n$5\\times5$ matrix of the form\n\\begin{equation}\\label{eq: A symm tridiagonal}\n\\boldsymbol{A}=\\begin{bmatrix}\n\\alpha_1& \\beta_1&        &        &\\\\\n \\beta_1&\\alpha_1& \\beta_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\beta_3 &\\\\\n        &        & \\beta_3&\\alpha_4&\\beta_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}.\n\\end{equation}\nA standard algorithm involves computing $5\\times5$~matrices \n$\\boldsymbol{L}$~and $\\boldsymbol{D}$ of the form\n\\[\n\\boldsymbol{L}=\\begin{bmatrix}\n     1&      &      &      &\\\\\n\\ell_1&     1&      &      &\\\\\n      &\\ell_2&     1&      &\\\\\n      &      &\\ell_3&     1&\\\\\n      &      &      &\\ell_4&1\n  \\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{D}=\\begin{bmatrix}\nd_1&   &   &   &\\\\\n   &d_2&   &   &\\\\\n   &   &d_3&   &\\\\\n   &   &   &d_4&\\\\\n   &   &   &   &d_5\n  \\end{bmatrix}\n\\]\nhaving the property that\n\\begin{equation}\\label{eq: L D LT}\n\\boldsymbol{A}=\\boldsymbol{L}\\boldsymbol{D}\\boldsymbol{L}^\\top.\n\\end{equation}\nGiven a right-hand side vector~$\\boldsymbol{b}$, we can solve the linear system\n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ by solving in sequence the three\nlinear systems\n\\begin{equation}\\label{eq: LDLT systems}\n\\boldsymbol{L}\\boldsymbol{z}=\\boldsymbol{b},\\qquad\n\\boldsymbol{D}\\boldsymbol{y}=\\boldsymbol{z},\\qquad\n\\boldsymbol{L}^\\top\\boldsymbol{x}=\\boldsymbol{y},\n\\end{equation}\nbecause it will then follow that\n\\[\n\\boldsymbol{A}\\boldsymbol{x}\n    =\\boldsymbol{L}\\boldsymbol{D}\\boldsymbol{L}^T\\boldsymbol{x}\n    =\\boldsymbol{L}\\boldsymbol{D}\\boldsymbol{y}\n    =\\boldsymbol{L}\\boldsymbol{z}=\\boldsymbol{b}.\n\\]\nSince $\\boldsymbol{L}$ is \\emph{lower triangular} and $\\boldsymbol{D}$ is \n\\emph{diagonal}, we can easily compute first $\\boldsymbol{z}$, then \n$\\boldsymbol{y}$ and finally $\\boldsymbol{x}$.  To see how, we write out the \nequations in the $5\\times5$~case:\n\\begin{align*}\n      z_1    &=b_1,& d_1y_1&=z_1,& x_1+\\ell_1 x_2&=y_1,\\\\\n\\ell_1z_1+z_2&=b_2,& d_2y_2&=z_2,& x_2+\\ell_2 x_3&=y_2,\\\\\n\\ell_2z_2+z_3&=b_3,& d_3y_3&=z_3,& x_3+\\ell_3 x_4&=y_3,\\\\\n\\ell_3z_3+z_4&=b_4,& d_4y_4&=z_4,& x_4+\\ell_4 x_5&=y_4,\\\\\n\\ell_4z_4+z_5&=b_5,& d_5y_5&=z_5,& x_5           &=y_5.\n\\end{align*}\nHence, the steps of the computation are as follows:\n\\begin{align*}\nz_1&=b_1,           & y_1&=z_1/d_1,& x_5&=y_5,\\\\\nz_2&=b_2-\\ell_1 z_1,& y_2&=z_2/d_2,& x_4&=y_4-\\ell_4x_5,\\\\\nz_3&=b_3-\\ell_2 z_2,& y_3&=z_3/d_3,& x_3&=y_3-\\ell_3x_4,\\\\\nz_4&=b_4-\\ell_3 z_3,& y_4&=z_4/d_4,& x_2&=y_2-\\ell_2x_3,\\\\\nz_5&=b_5-\\ell_4 z_4,& y_5&=z_5/d_5,& x_1&=y_1-\\ell_1x_2.\\\\\n\\end{align*}\nMatrix multiplication gives\n\\[\n\\boldsymbol{L}\\boldsymbol{D}\\boldsymbol{L}^\\top=\\begin{bmatrix}\n      d_1&      \\ell_1d_1&               &               &         \\\\\n\\ell_1d_1&d_2+\\ell_1^2d_1&      \\ell_2d_2&               &         \\\\\n         &      \\ell_2d_2&d_3+\\ell_2^2d_2&      \\ell_3d_3&         \\\\\n         &               &      \\ell_3d_3&d_4+\\ell_3^2d_3&\\ell_4d_4\\\\\n         &               &               &      \\ell_4d_4&d_5+\\ell_4^2d_4\n\\end{bmatrix},\n\\]\nso the factorization~\\eqref{eq: L D LT} requires that\n\\begin{align*}\n     \\alpha_1&=d_1,      &        &                 &&&&&&\\\\\n      \\beta_1&=\\ell_1d_1,&\\alpha_2&=d_2+\\ell_1^2d_1,&&&&&&\\\\\n    &&\\beta_2&=\\ell_2d_2,&\\alpha_3&=d_3+\\ell_2^2d_2,&&&&\\\\\n  &&&&\\beta_3&=\\ell_3d_3,&\\alpha_4&=d_4+\\ell_3^2d_3,&&\\\\\n&&&&&&\\beta_4&=\\ell_4d_4,&\\alpha_5&=d_5+\\ell_4^2d_4.\n\\end{align*}\nThus, the steps in computing the entries of $\\boldsymbol{L}$~and \n$\\boldsymbol{D}$ are as follows:\n\\begin{align*}\n         d_1&=\\alpha_1,   &   &                      &&&&&&\\\\\n      \\ell_1&=\\beta_1/d_1,&d_2&=\\alpha_2-\\ell_1^2d_1,&&&&&&\\\\\n    &&\\ell_2&=\\beta_2/d_2,&d_3&=\\alpha_3-\\ell_2^2d_2,&&&&\\\\\n  &&&&\\ell_3&=\\beta_3/d_3,&d_4&=\\alpha_4-\\ell_3^2d_3,&&\\\\\n&&&&&&\\ell_4&=\\beta_4/d_4,&d_5&=\\alpha_5-\\ell_4^2d_4.\n\\end{align*}\nIn the general $n\\times n$~case,\nAlgorithm~\\ref{alg: LDLT} computes the factorization~\\eqref{eq: L D LT}\nand Algorithm~\\ref{alg: solve symmetric tridiagonal} \nuses this factorization to solve the linear \nsystem~$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$. \n\nThe derivations above show that if the factorization \\eqref{alg: LDLT} exists,\nthen it is unique, that is, $\\boldsymbol{L}$ and $\\boldsymbol{D}$ are uniquely \ndetermined by~$\\boldsymbol{A}$.  Unfortunately,\nAlgorithm~\\ref{alg: LDLT} can break down because one of the $d_j$ is zero, as \nthe following example shows.\n\n\\begin{example}\nThe $3\\times3$ matrix\n\\[\n\\boldsymbol{A}=\\begin{bmatrix}1&1&0\\\\1&1&2\\\\ 0&2&0 \\end{bmatrix}\n\\]\nis non-singular with inverse\n\\[\n\\boldsymbol{A}^{-1}=\\begin{bmatrix}1&0&-1/2\\\\ 0&0&1/2\\\\ -1/2&1/2&0\\end{bmatrix},\n\\]\nbut Algorithm~\\ref{alg: LDLT} produces\n\\[\nd_1=1,\\quad \\ell_1=1,\\quad d_2=0,\n\\]\nand then breaks down because $\\ell_2=2/0$.\n\\end{example}\n\nHowever, the following result can be shown.\n\n\\begin{theorem}\nIf the $n\\times n$, symmetric, tridiagonal matrix $\\boldsymbol{A}$ is \npositive-definite, then the factorization~\\eqref{eq: L D LT} exists and $d_j>0$ \nfor $1\\le j\\le n$.\n\\end{theorem}\n\n\\begin{algorithm}\n\\caption{Compute the factorization \\eqref{eq: L D LT} for a symmetric, \ntridiagonal matrix $\\boldsymbol{A}$.}\n\\label{alg: LDLT}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{\\alpha}=[\\alpha_1,\\alpha_2,\\ldots,\\alpha_n]$ is the main \ndiagonal of $\\boldsymbol{A}$.}\n\\Require{$\\boldsymbol{\\beta}=[\\beta_1,\\beta_2,\\ldots,\\beta_{n-1}]$ is the \noff-diagonal of $\\boldsymbol{A}$.}\n\\Statex\n\\Function{Factorize}{$\\boldsymbol{\\alpha}, \\boldsymbol{\\beta}$}\n\\State Allocate storage for $\\boldsymbol{d}=[d_1,d_2,\\ldots, d_n]$ and\n$\\boldsymbol{\\ell}=[\\ell_1,\\ell_2,\\ldots,\\ell_{n-1}]$\n\\State $d_1=\\alpha_1$\n\\For{$j=1:n-1$}\n\\State $\\ell_j=\\beta_j/d_j$\n\\State $d_{j+1}=\\alpha_{j+1}-\\ell_j^2d_j$\n\\EndFor\n\\State\\Return{$\\boldsymbol{d}$, $\\boldsymbol{\\ell}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}\n\\caption{Solve a symmetric, tridiagonal linear system \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ given the \nfactorization~\\eqref{eq: L D LT}.}\n\\label{alg: solve symmetric tridiagonal}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{b}=[b_1,b_2,\\ldots,b_n]$ the right-hand side vector.}\n\\Require{$\\boldsymbol{d}=[d_1, d_2, \\ldots, d_n]$ the main diagonal of \n$\\boldsymbol{D}$.}\n\\Require{$\\boldsymbol{\\ell}=[\\ell_1,\\ell_2,\\ldots,\\ell_{n-1}]$ the first \nsub-diagonal of~$\\boldsymbol{L}$.}\n\\Statex\n\\Function{Solve}{$\\boldsymbol{b},\\boldsymbol{d},\\boldsymbol{\\ell}$}\n\\State Allocate storage for $\\boldsymbol{x}=[x_1,x_2,\\ldots,x_n]$,\n$\\boldsymbol{y}=[y_1,y_2,\\ldots,y_n]$ and $\\boldsymbol{z}=[z_1,z_2,\\ldots,z_n]$.\n\\State $z_1=b_1$\n\\For{$j=1:n-1$}\n\\State $z_{j+1}=b_{j+1}-\\ell_jz_j$\n\\EndFor\n\\For{$j=1:n$}\n\\State $y_j=z_j/d_j$\n\\EndFor\n\\State $x_n=y_n$\n\\For{$j=n-1:-1:1$}\n\\State $x_j=y_j-\\ell_jx_{j+1}$\n\\EndFor\n\\State\\Return{$\\boldsymbol{x}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\nOnce $d_j$ has been computed, the value of $\\alpha_j$ is never used in \nsubsequent steps of Algorithm~\\ref{alg: LDLT}. Similarly, once $\\ell_j$ has been \ncomputed, the value of~$\\beta_j$ is never used subsequently.  It is therefore \npossible to economize on storage by computing the factorization \n\\emph{in place}, that is, overwriting $\\alpha_j$ with~$d_j$,\nand likewise overwriting $\\beta_j$ with~$\\ell_j$, as shown in \nAlgorithm~\\ref{alg: LDLT in place}.  The solution of the triangular and \ndiagonal linear systems can also be performed in place, as shown in \nAlgorithm~\\ref{alg: solve symmetric tridiagonal in place}.  Here, we have \nfollowed the convention from Julia that an exclamation mark~! is appended to \nthe name of any function that modifies at least one of its arguments.  Also, \nthe symbol~$\\gets$ in this context means ``is overwritten with''.\n\n\\begin{algorithm}\n\\caption{Compute the factorization \\eqref{eq: L D LT} in place.}\n\\label{alg: LDLT in place}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{d}=[\\alpha_1,\\alpha_2,\\ldots,\\alpha_n]$ holds the main\ndiagonal of $\\boldsymbol{A}$.}\n\\Require{$\\boldsymbol{\\ell}=[\\beta_1,\\beta_2,\\ldots,\\beta_{n-1}]$ holds the \noff-diagonal of $\\boldsymbol{A}$.}\n\\Statex\n\\Function{Factorize!}{$\\boldsymbol{d}$, $\\boldsymbol{\\ell}$}\n\\For{$j=1:n-1$}\n\\State $\\ell_j\\gets\\ell_j/d_j$\n\\State $d_{j+1}\\gets d_{j+1}-\\ell_j^2d_j$\n\\EndFor\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}\n\\caption{Solve a symmetric, tridiagonal linear system \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ in place.}\n\\label{alg: solve symmetric tridiagonal in place}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{x}=[b_1,b_2,\\ldots,b_n]$ holds the right-hand side \nvector.}\n\\Require{$\\boldsymbol{d}=[d_1, d_2, \\ldots, d_n]$ holds the main diagonal of \n$\\boldsymbol{D}$.}\n\\Require{$\\boldsymbol{\\ell}=[\\ell_1,\\ell_2,\\ldots,\\ell_{n-1}]$ holds the first \nsub-diagonal of~$\\boldsymbol{L}$.}\n\\Statex\n\\Function{Solve!}{$\\boldsymbol{x},\\boldsymbol{d},\\boldsymbol{\\ell}$}\n\\For{$j=1:n-1$}\n    \\State $x_{j+1}\\gets x_{j+1}-\\ell_jx_j$\n\\EndFor\n\\For{$j=1:n$}\n    \\State $x_j\\gets x_j/d_j$\n\\EndFor\n\\For{$j=n-1:-1:1$}\n    \\State $x_j\\gets x_j-\\ell_jx_{j+1}$\n\\EndFor\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\nCounting the numbers of arithmetic operations in Algorithms\n\\ref{alg: LDLT}~ and \\ref{alg: solve symmetric tridiagonal} yields\n\\cref{tab: LDLT flops}.  If we use the in-place versions, \nAlgorithms \\ref{alg: LDLT in place}~and \n\\ref{alg: solve symmetric tridiagonal in place}, then we have to store only\n$3n-1$ floating-point numbers.  Thus, the overall computational cost is \n$O(n)$~operations and $O(n)$~storage, implying that the computational cost of\nsolving the finite difference equations~\\eqref{eq: model 1d discrete} is \n$O(P)$~operations and $O(P)$~storage.  We therefore expect that the runtime and \nmemory requirements of a program to compute~$\\boldsymbol{U}$ will scale \nlinearly with~$P$ for our 1D boundary-value problem.  \n\n\\begin{table}\n\\caption{Operation counts for solving a symmetric positive-definite, \ntridiagonal linear system.}\\label{tab: LDLT flops}\n\\begin{center}\n\\begin{tabular}{c|c|c}\n&Algorithm~\\ref{alg: LDLT}\n&Algorithm~\\ref{alg: solve symmetric \ntridiagonal}\\\\\n\\hline\nadditions/subtractions&   $n-1$&$2(n-1)$\\\\\n       multiplications&$2(n-1)$&$2(n-1)$\\\\\n             divisions&   $n-1$&$n$\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\n\\section{General two-point boundary-value problem}\n\\label{sec: gen two-point bvp}\n\nNow consider a general second-order linear differential operator,\n\\[\n\\mathcal{L}u=-a(x)u''+b(x)u'+c(x)u,\n\\]\nwhere, for simplicity, we will assume that the coefficients $a$, $b$ and \n$c$ are continuous on~$[0,L]$, and that the \\emph{leading coefficient}~$a$ is \n\\emph{strictly positive} on~$[0,L]$, so there is a constant~$a_{\\min}$ such that\n\\begin{equation}\\label{eq: ellipticity 1d}\na(x)\\ge a_{\\min}>0\\quad\\text{for $0\\le x\\le L$.}\n\\end{equation}\nThe general \\emph{two-point boundary-value problem} is to find $u=u(x)$ \nsatisfying\n\\begin{equation}\\label{eq: two-point bvp}\n\\begin{aligned}\n\\mathcal{L}u&=f(x)&&\\text{for $0<x<L$,}\\\\\n\\alpha_0u'+\\beta_0u&=\\gamma_0&&\\text{at $x=0$,}\\\\\n\\alpha_Lu'+\\beta_Lu&=\\gamma_L&&\\text{at $x=L$,}\n\\end{aligned}\n\\end{equation}\nwhere, for the boundary conditions to make sense, we assume that at least one \nof $\\alpha_0$~and $\\beta_0$ is not zero, and likewise at least one of  \n$\\alpha_L$~and $\\beta_L$ is not zero.  For simplicity, we will also assume that \nthe function~$f$ is continuous on~$[0,L]$.  The simple \nproblem~\\eqref{eq: model 1d} is just the special case\n\\[\na(x)=1,\\quad b(x)=0,\\quad \nc(x)=0,\\quad\\alpha_0=0,\\quad\\beta_0=1,\\quad\\alpha_L=0,\\quad\\beta_L=1.\n\\]\n\nTo construct a finite difference scheme for~\\eqref{eq: two-point bvp}, we need \nto approximate the first derivative~$u'$.  Once again, we apply Taylor \nexpansions, this time showing that\n\\[\n\\frac{f(x+h)-f(x-h)}{2h}=f'(x)+O(h^2)\\quad\\text{as $h\\to0$.}\n\\]\nMore precisely, the following holds.\n\n\\begin{theorem}\\label{thm: first central diff}\nIf $f$ is $C^3$ on the closed interval~$[x-h,x+h]$, then\n\\[\n\\biggl|f'(x)-\\frac{f(x+h)-f(x-h)}{2h}\\biggr|\n\t\\le\\frac{h^2}{6}\\,\\max_{x-h\\le y\\le x+h}|f'''(y)|.\n\\]\n\\end{theorem}\n\\begin{proof}\nSince\n\\[\nf(x+h)=f(x)+f'(x)h+\\tfrac12f''(x)h^2+(R_2f)(x,h)\n\\]\nand\n\\[\nf(x-h)=f(x)-f'(x)h+\\tfrac12f''(x)h^2+(R_2f)(x,-h),\n\\]\nwe have\n\\[\nf(x+h)-f(x-h)=2f'(x)h+(R_2f)(x,h)-(R_2f)(x,-h).\n\\]\nThus,\n\\[\n\\frac{f(x+h)-f(x-h)}{2h}-f'(x)=\\frac{(R_2f)(x,h)-(R_2f)(x,-h)}{2h},\n\\]\nand since\n\\begin{align*}\n\\bigl|(R_2f)(x,h)-(R_2f)(x,-h)\\bigr|\n\t&\\le\\frac{h^3}{3!}\\max_{x\\le y\\le x+h}|f'''(y)|\n \t   +\\frac{h^3}{3!}\\max_{x-h\\le y\\le x}|f'''(y)|\\\\\n\t&\\le\\frac{2h^3}{3!}\\max_{x-h\\le y\\le x+h}|f'''(y)|,\n\\end{align*}\nthe result follows at once.\n\\end{proof}\n\nThe approximations \\eqref{eq: u'' approx}~and\n\\begin{equation}\\label{eq: u' approx}\n\\frac{u(x_{p+1})-u(x_{p-1})}{2\\,\\Delta x}\n\t=\\frac{u(x_p+\\Delta x)-u(x_p-\\Delta x)}{2\\,\\Delta x}\n\t\\approx u'(x_p)\n\\end{equation}\nsuggest the following discrete approximation to~$(\\mathcal{L}u)(x_p)$, \n\\begin{equation}\\label{eq: Lu Delta x}\n(\\mathcal{L}_{\\Delta x}U)_p=\n-a_p\\,\\frac{U_{p+1}-2U_p+U_{p-1}}{\\Delta x^2}\n\t+b_p\\,\\frac{U_{p+1}-U_{p-1}}{2\\,\\Delta x}+c_pU_p,\n\\end{equation}\nwhere we have used the abbreviations $a_p=a(x_p)$, $b_p=b(x_p)$~and \n$c_p=c(x_p)$.  The central difference approximation to~$u'$ can also be used \nin the boundary conditions by allowing ``ghost'' grid points $x_{-1}=-\\Delta \nx$~and $x_{P+1}=L+\\Delta x$ lying just outside the interval~$[0,L]$, so that\n\\begin{equation}\\label{eq: bc ghost points}\nu'(0)\\approx\\frac{U_1-U_{-1}}{2\\,\\Delta x}\n\\quad\\text{and}\\quad\nu'(L)\\approx\\frac{U_{P+1}-U_{P-1}}{2\\,\\Delta x}.\n\\end{equation}\nFour cases can occur.\n\\begin{enumerate}\n\\item If $\\alpha_0=0$ and $\\alpha_L=0$, then we require\n\\[\n(\\mathcal{L}_{\\Delta x}U)_p=f_p\\quad\\text{for $1\\le p\\le P-1$,}\\quad\n\\text{with $\\beta_0U_0=\\gamma_0$ and $\\beta_LU_P=\\gamma_L$.}\n\\]\nEliminating $U_0=\\gamma_0/\\beta_0$~and $U_P=\\gamma_L/\\beta_L$ leads to a \n$(P-1)\\times(P-1)$ linear system for $U_1$, $U_2$, \\dots, $U_{P-1}$.\n\\item If $\\alpha_0\\ne0$ and $\\alpha_L=0$, then we require\n\\[\n(\\mathcal{L}_{\\Delta x}U)_p=f_p\\quad\\text{for $0\\le p\\le P-1$,}\\quad\n\\text{with $\\alpha_0\\,\\frac{U_1-U_{-1}}{2\\,\\Delta x}+\\beta_0U_0=\\gamma_0$\nand $\\beta_LU_P=\\gamma_L$.}\n\\]\nEliminating $U_{-1}=U_1+2\\,\\Delta x\\,(\\beta_0U_0-\\gamma_0)/\\alpha_0$ and \n$U_P=\\gamma_L/\\beta_L$ leads to a $P\\times P$ linear system for $U_0$, \n$U_1$, \\dots, $U_{P-1}$.\n\\item If $\\alpha_0=0$ and $\\alpha_L\\ne0$, then we require\n\\[\n(\\mathcal{L}_{\\Delta x}U)_p=f_p\\quad\\text{for $1\\le p\\le P$,}\\quad\n\\text{with $\\beta_0U_0=\\gamma_0$ and\n$\\alpha_L\\,\\frac{U_{P+1}-U_{P-1}}{2\\,\\Delta x}+\\beta_LU_P=\\gamma_L$.}\n\\]\nEliminating $U_0=\\gamma_0/\\beta_0$ and\n$U_{P+1}=U_{P-1}+2\\,\\Delta x(\\gamma_L-\\beta_LU_P)/\\alpha_L$ leads to a \n$P\\times P$ linear system for $U_1$, $U_2$, \\dots, $U_P$.\n\\item If $\\alpha_0\\ne0$ and $\\alpha_L\\ne0$, then we require\n\\[\n(\\mathcal{L}_{\\Delta x}U)_p=f_p\\quad\\text{for $0\\le p\\le P$,}\n\\]\nwith\n\\[\n\\alpha_0\\,\\frac{U_1-U_{-1}}{2\\,\\Delta x}+\\beta_0U_0=\\gamma_0\n\\quad\\text{and}\\quad\n\\alpha_L\\,\\frac{U_{P+1}-U_{P-1}}{2\\,\\Delta x}+\\beta_LU_P=\\gamma_L.\n\\]\nEliminating $U_{-1}$~and $U_{P+1}$ leads to a $(P+1)\\times(P+1)$ linear system \nfor $U_0$, $U_1$, \\dots, $U_P$.\n\\end{enumerate}\n\nIn case~1, the first equation is\n\\[\n-a_1\\,\\frac{U_2-2U_1+U_0}{\\Delta x^2}+b_1\\,\\frac{U_2-U_0}{2\\,\\Delta x}\n\t+c_1U_1=f_1\n\\]\nso $U_0=\\gamma_0/\\beta_0$ gives\n\\[\na_1\\,\\frac{2U_1-U_2}{\\Delta x^2}+b_1\\,\\frac{U_2}{2\\,\\Delta x}+c_1U_1\n\t=f_1+\\biggl(\\frac{a_1}{\\Delta x^2}+\\frac{b_1}{2\\,\\Delta x}\\biggr)\n\t\\frac{\\gamma_0}{\\beta_0}.\n\\]\nSimilarly, the last equation is\n\\[\n-a_{P-1}\\,\\frac{U_P-2U_{P-1}+U_{P-2}}{\\Delta x^2}\n\t+b_{P-1}\\,\\frac{U_P-U_{P-2}}{2\\,\\Delta x}+c_{P-1}U_{P-1}=f_{P-1},\n\\]\nso $U_P=\\gamma_L/\\beta_L$ gives\n\\[\na_{P-1}\\,\\frac{-U_{P-2}+2U_{P-1}}{\\Delta x^2}\n\t-b_{P-1}\\,\\frac{U_{P-2}}{2\\,\\Delta x}+c_{P-1}U_{P-1}\n\t=f_{P-1}+\\biggl(\\frac{a_{P-1}}{\\Delta x^2}-\\frac{b_{P-1}}{2\\,\\Delta x}\n\t\\biggr)\\,\\frac{\\gamma_L}{\\beta_L}.\n\\]\nFor example, if $P=6$ we obtain a $5\\times5$ linear system\n\\begin{equation}\\label{eq: finite diff matrix 1d}\n\\boldsymbol{A}\\boldsymbol{U}+\\boldsymbol{B}\\boldsymbol{U}\n\t+\\boldsymbol{C}\\boldsymbol{U}=\\boldsymbol{f}+\\boldsymbol{g},\n\\end{equation}\nwhere\n\\begin{gather*}\n\\boldsymbol{A}=\\frac{1}{\\Delta x^2}\\begin{bmatrix}\n2a_1&-a_1&    &    &    \\\\\n-a_2&2a_2&-a_2&    &    \\\\\n    &-a_3&2a_3&-a_3&    \\\\\n    &    &-a_4&2a_4&-a_4\\\\\n    &    &    &-a_5&2a_5\\\\\n               \\end{bmatrix},\\qquad\n\\boldsymbol{B}=\\frac{1}{2\\,\\Delta x}\\begin{bmatrix}\n   0& b_1&    &    &    \\\\\n-b_2&   0& b_2&    &    \\\\\n    &-b_3&   0& b_3&    \\\\\n    &    &-b_4&   0& b_4\\\\\n    &    &    &-b_5&   0\\end{bmatrix},\\\\\n\\boldsymbol{C}=\\begin{bmatrix}\nc_1&   &   &   &   \\\\\n   &c_2&   &   &   \\\\\n   &   &c_3&   &   \\\\\n   &   &   &c_4&   \\\\\n   &   &   &   &c_5\n\\end{bmatrix},\\quad\n\\boldsymbol{U}=\\begin{bmatrix} U_1\\\\ U_2\\\\ U_3\\\\ U_4\\\\ U_5\\end{bmatrix},\\quad\n\\boldsymbol{f}=\\begin{bmatrix} f_1\\\\ f_2\\\\ f_3\\\\ f_4\\\\ f_5\\end{bmatrix},\\quad\n\\boldsymbol{g}=\\begin{bmatrix} g_1\\\\ 0\\\\ 0\\\\ 0\\\\ g_5 \\end{bmatrix},\n\\end{gather*}\nwhere\n\\[\ng_1=\\biggl(\\frac{a_1}{\\Delta x^2}+\\frac{b_1}{2\\,\\Delta x}\\biggr)\n\t\\frac{\\gamma_0}{\\beta_0}\n\\quad\\text{and}\\quad\ng_5=\\biggl(\\frac{a_{P-1}}{\\Delta x^2}-\\frac{b_{P-1}}{2\\,\\Delta x}\n\t\\biggr)\\,\\frac{\\gamma_L}{\\beta_L}.\n\\]\n\nIn case~4, the first equation is \n\\[\n-a_0\\,\\frac{U_1-2U_0+U_{-1}}{\\Delta x^2}+b_0\\,\\frac{U_1-U_{-1}}{2\\,\\Delta x}\n    +c_0U_0=f_0\n\\]\nso $U_{-1}=U_1+2\\,\\Delta x(\\beta_0U_0-\\gamma_0)/\\alpha_0$ gives\n\\[\n-2a_0\\,\\frac{U_1-U_0}{\\Delta x^2}+c_0U_0\n    -\\frac{\\beta_0(2a_0+b_0\\,\\Delta x)}{\\alpha_0\\,\\Delta x}\\,U_0\n    =f_0\n    -\\frac{2a_0+b_0\\,\\Delta x}{\\alpha_0\\,\\Delta x}\\,\\gamma_0.\n\\]\nSimilarly, the last equation is\n\\[\n-a_P\\,\\frac{U_{P+1}-2U_P+U_{P-1}}{\\Delta x^2}\n    +b_P\\,\\frac{U_{P+1}-U_{P-1}}{2\\,\\Delta x}+c_PU_P=f_P,\n\\]\nso $U_{P+1}=U_{P-1}+2\\,\\Delta x(\\gamma_L-\\beta_LU_P)/\\alpha_L$ gives\n\\[\n-2a_P\\,\\frac{-U_P+U_{P-1}}{\\Delta x^2}+c_PU_P\n    +\\frac{\\beta_L(2a_P-b_P\\,\\Delta x)}{\\alpha_L\\,\\Delta x}\\,U_P\n    =f_P+\\frac{2a_P-b_P\\,\\Delta x}{\\alpha_L\\,\\Delta x}\\,\\gamma_L.\n\\]\nFor example, if $P=4$ then we obtain a $5\\times5$ linear \nsystem of the form~\\eqref{eq: finite diff matrix 1d} but now\n\\begin{gather*}\n\\boldsymbol{A}=\\frac{1}{\\Delta x^2}\\begin{bmatrix}\n2a_0(1-\\beta_0\\,\\Delta x/\\alpha_0)&-2a_0&    &    &    \\\\\n-a_1&2a_1&-a_1&    &    \\\\\n    &-a_2&2a_2&-a_2&    \\\\\n    &    &-a_3&2a_3&-a_3\\\\\n    &    &    &-2a_4&2a_4(1+\\beta_L\\,\\Delta x/\\alpha_L)\\\\\n               \\end{bmatrix},\\\\\n\\boldsymbol{B}=\\frac{1}{2\\,\\Delta x}\\begin{bmatrix}\n-2b_0\\beta_0\\,\\Delta x/\\alpha_0&    &    &    &    \\\\\n-b_1&   0& b_1&    &    \\\\\n    &-b_2&   0& b_2&    \\\\\n    &    &-b_3&   0& b_3\\\\\n    &    &    &    &-2b_P\\beta_L\\,\\Delta x/\\alpha_L\\end{bmatrix},\\\\\n\\boldsymbol{C}=\\begin{bmatrix}\nc_0&   &   &   &   \\\\\n   &c_1&   &   &   \\\\\n   &   &c_2&   &   \\\\\n   &   &   &c_3&   \\\\\n   &   &   &   &c_4\n\\end{bmatrix},\\quad\n\\boldsymbol{U}=\\begin{bmatrix} U_0\\\\ U_1\\\\ U_2\\\\ U_3\\\\ U_4\\end{bmatrix},\\quad\n\\boldsymbol{f}=\\begin{bmatrix} f_0\\\\ f_1\\\\ f_2\\\\ f_3\\\\ f_4\\end{bmatrix},\\quad\n\\boldsymbol{g}=\\begin{bmatrix} g_0\\\\ 0\\\\ 0\\\\ 0\\\\ g_4 \\end{bmatrix},\n\\end{gather*}\nwhere\n\\[\ng_0=-\\frac{2a_0+b_0\\,\\Delta x}{\\alpha_0\\,\\Delta x}\\,\\gamma_0\n\\quad\\text{and}\\quad\ng_4=\\frac{2a_4-b_4\\,\\Delta x}{\\alpha_L\\,\\Delta x}\\,\\gamma_L.\n\\]\n\nThe procedure in cases 2~and 3 should now be clear.\n\n\\section{Maximum principle}\nIt will be convenient to use the standard notation\n\\[\n\\|f\\|_\\infty=\\max_{0\\le x\\le L}|f(x)|\n\\]\nfor the \\emph{maximum norm} of any (continuous) function~$f$ over \nthe interval~$[0,L]$, and to let\n\\[\nu^+(x)=\\max\\{u(x),0\\}\n\\quad\\text{and}\\quad\nu^-(x)=\\min\\{u(x),0\\}.  \n\\]\nWe begin by proving a \\emph{maximum principle} that \nfollows from our \\emph{ellipticity} assumption~\\eqref{eq: ellipticity 1d} and \nsimple calculus.\n\n\\begin{lemma}\\label{lem: Lu<0}\nAssume that $u$ is $C^2$ on the open interval~$(0,L)$.\nIf $c\\ge0$ and $\\mathcal{L}u<0$ on~$(0,L)$, then $u$ cannot attain a \nnon-negative local maximum in~$(0,L)$.\n\\end{lemma}\n\\begin{proof}\nSuppose for a contradiction that there exist $x_0\\in(0,L)$~and $\\delta>0$ such\nthat\n\\[\nu(x_0)\\ge0\\quad\\text{and}\\quad\n\\text{$u(x)\\le u(x_0)$ for~$x\\in(x_0-\\delta,x_0+\\delta)\\subseteq(0,L)$.}\n\\]\nSince $u$ has an interior local maximum at~$x_0$, it follows that \n$u'(x_0)=0$~and $u''(x_0)\\le0$ so \n\\[\n(\\mathcal{L}u)(x_0)=-a(x_0)u''(x_0)+c(x_0)u(x_0)\\ge 0,\n\\]\ncontradicting our assumption that $\\mathcal{L}u<0$ on~$(0,L)$.\n\\end{proof}\n\n\\begin{theorem}\\label{thm: max principle 1d}\nAssume that $u$ is continuous on the closed interval~$[0,L]$ and is $C^2$ on \nthe open interval~$(0,L)$. If $c\\ge0$ and $\\mathcal{L}u\\le0$ on~$(0,L)$, then\n\\[\nu(x)\\le\\max\\{u^+(0),u^+(L)\\}\\quad\\text{for $0<x<L$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $\\epsilon>0$~and $\\mu>0$, and put $w(x)=u(x)+\\epsilon e^{\\mu x}$.  Since\n\\[\n(\\mathcal{L}w)(x)\n\t=(\\mathcal{L}u)(x)+\\epsilon\\bigl[-a(x)\\mu^2+b(x)\\mu+c(x)\\bigr]e^{\\mu x}\n\\le-\\epsilon\\bigl[a_{\\min}\\mu^2-\\mu\\|b\\|_\\infty-\\|c\\|_\\infty\\bigr]e^{\\mu x}\n\\]\nby choosing $\\mu$ sufficiently large we can ensure that $\\mathcal{L}w<0$\non~$(0,L)$.  By Lemma~\\ref{lem: Lu<0}, the function~$w$ cannot attain a \nnon-negative local maximum in~$(0,L)$, implying that \n\\[\nu(x)\\le w(x)\\le w^+(x)\\le\\max\\{w^+(0),w^+(L)\\}\n\t\\le\\max\\{u^+(0)+\\epsilon,u^+(L)+\\epsilon e^{\\mu L}\\}\n\\]\nfor~$0<x<L$.  Since this inequality holds for any~$\\epsilon>0$, the result \nfollows.\n\\end{proof}\n\n\\begin{theorem}\\label{thm: max min 1d}\nAssume that $u$ is continuous on the closed interval~$[0,L]$ and is $C^2$ on \nthe open interval~$(0,L)$. If $c\\ge0$ and $\\mathcal{L}u=f$ on~$(0,L)$, then\n\\[\n\\max_{[0,L]}u\\le\\max\\{u^+(0),u^+(L)\\}+\\cosh(\\mu L/2)\\max_{[0,L]}f^+\n\\]\nand\n\\[\n\\min_{[0,L]}u\\ge\\min\\{u^-(0),u^-(L)\\}+\\cosh(\\mu L/2)\\min_{[0,L]}f^-,\n\\]\nwhere $\\mu=\\max\\bigl\\{1,(1+\\|b\\|_\\infty)/a_{\\min}\\bigr\\}$.\n\\end{theorem}\n\\begin{proof}\nLet\n\\[\nw(x)=\\max\\{u^+(0),u^+(L)\\}+v(x)\\,\\max_{[0,L]}f^+\n\\quad\\text{where}\\quad\nv(x)=\\cosh(\\mu L/2)-\\cosh\\mu(x-L/2),\n\\]\nand observe that $v\\ge0$ on~$[0,L]$ with\n\\begin{align*}\n(\\mathcal{L}v)(x)&=a(x)\\mu^2\\cosh\\mu(x-L/2)\n\t-b(x)\\mu\\sinh\\mu(x-L/2)+c(x)v(x)\\\\\n\t&\\ge\\bigl(a_{\\min}\\mu^2-\\|b\\|_\\infty\\mu\\bigr)\\cosh\\mu(x-L/2)\n\t\\ge(a_{\\min}\\mu-\\|b\\|_\\infty)\\mu\\ge1\n\\end{align*}\nfor $0<x<L$, so\n\\[\n\\mathcal{L}(u-w)=f-c(x)\\max\\{u^+(0),u^+(L)\\}-(\\mathcal{L}v)\\max_{[0,L]}f^+\n    \\le f-\\max_{[0,L]}f^+\\le0\\quad\\text{on $(0,L)$.}\n\\]\nBy Theorem~\\ref{thm: max principle 1d},\n\\[\nu(x)-w(x)\\le\\max\\{(u-w)^+(0),(u-w)^+(L)\\}\\quad\\text{for $0<x<L$,}\n\\]\nand since $v(0)=0=v(L)$ we see that \n\\[\n(u-w)(0)=u(0)-\\max\\{u^+(0),u^+(L)\\}\\le0\n\\]\nand\n\\[\n(u-w)(L)=u(L)-\\max\\{u^+(0),u^+(L)\\}\\le0.\n\\]\nThus, $u-w\\le0$ on~$(0,L)$, and therefore \n\\[\n\\max_{[0,L]}u\\le\\max_{[0,L]}w(x)=w(L/2)=\\max\\{u^+(0),u^+(L)\\}\n\t+v(L/2)\\max_{[0,L]}f^+, \n\\]\nproving the first inequality.  \nThe second follows because $\\mathcal{L}(-u)=-f$, $(-u)^+=-u^-$~and\n$(-f)^+=-f^-$.\n\\end{proof}\n\nNow consider the two-point boundary-value problem~\\eqref{eq: two-point bvp} in \nthe case when $\\alpha_0=0=\\alpha_L$ and $\\beta_0=1=\\beta_L$:\n\\begin{equation}\\label{eq: Lu=f Dirichlet}\n\\mathcal{L}u=f\\quad\\text{on $(0,L)$,}\n\t\\quad\\text{with $u(0)=\\gamma_0$ and $u(L)=\\gamma_L$.}\n\\end{equation}\nAs an immediate consequence of Theorem~\\ref{thm: max min 1d} we have the \nfollowing \\emph{a priori} estimate, which serves to bound the solution~$u$ in \nterms of the data $f$, $\\gamma_0$~and $\\gamma_L$.\n\n\\begin{theorem}\\label{thm: Lu=f apriori infty}\nIf $c\\ge0$ on~$(0,L)$, then any solution~$u$ of~\\eqref{eq: Lu=f Dirichlet} \nsatisfies\n\\[\n\\|u\\|_\\infty\\le\\max\\{|\\gamma_0|,|\\gamma_L|\\}+\\cosh(\\mu L/2)\\|f\\|_\\infty.\n\\]\n\\end{theorem}\n\nUsing Theorem~\\ref{thm: Lu=f apriori infty} it can be shown that\nthe two-point boundary-value problem~\\eqref{eq: Lu=f Dirichlet} is \n\\emph{well-posed}, that is, \n\\begin{enumerate}\n\\item a unique solution exists for each choice of the data $f$, $\\gamma_0$~and \n$\\gamma_L$, and \n\\item small changes in the data lead to only small changes in the solution.\n\\end{enumerate}\nTo explain the second part, suppose that we perturb the data to $\\tilde f$, \n$\\tilde\\gamma_0$ and $\\tilde\\gamma_L$, and let $\\tilde u$ denote the solution \nof the resulting perturbed problem,\n\\[\n\\mathcal{L}\\tilde u=\\tilde f\\quad\\text{on $(0,L)$,}\n    \\quad\\text{with $\\tilde u(0)=\\tilde\\gamma_0$ \nand $\\tilde u(L)=\\tilde\\gamma_L$.}\n\\]\nIf we denote the changes in the solution and the data by\n\\[\n\\delta u=\\tilde u-u,\\quad\\delta f=\\tilde f-f,\\quad\n\\delta\\gamma_0=\\tilde\\gamma_0-\\gamma_0,\\quad\n\\delta\\gamma_L=\\tilde\\gamma_L-\\gamma_L,\n\\]\nthen we need to show that $\\delta u$ is small whenever $\\delta f$, \n$\\delta\\gamma_0$~and $\\delta\\gamma_L$ are all small.\n\n\\begin{theorem}\nIf $c\\ge0$ on~$(0,L)$, then \\eqref{eq: Lu=f Dirichlet} has a unique \nsolution~$u$.  This solution is continuous on~$[0,L]$ and is $C^2$ on~$(0,L)$.\nMoreover, when the problem is perturbed as described above, \n\\[\n\\|\\delta u\\|_\\infty\\le\\max\\{|\\delta\\gamma_0|,|\\delta\\gamma_L|\\}\n    +\\cosh(\\mu L/2)\\|\\delta f\\|_\\infty.\n\\]\n\\end{theorem}\n\\begin{proof}\nWe will not prove the hard part, namely existence.  Since the $\\mathcal{L}$ is \nlinear, the proof of uniqueness follows easily from \nTheorem~\\ref{thm: Lu=f apriori infty}.  In fact, suppose that $u_1$~and $u_2$ \nare solutions, that is,\n\\[\n\\mathcal{L}u_1=f=\\mathcal{L}u_2\\quad\\text{on $(0,L)$,}\n    \\quad\\text{with $u_1(0)=\\gamma_0=u_2(0)$ and $u_1(L)=\\gamma_L=u_2(L)$.}\n\\]\nThe difference $v=u_1-u_2$ satisfies\n\\[\n\\mathcal{L}v=\\mathcal{L}(u_1-u_2)=\\mathcal{L}u_1-\\mathcal{L}u_2=f-f=0\n    \\quad\\text{on $(0,L)$},\n\\]\nwith $v(0)=u_1(0)-u_2(0)=\\gamma_0-\\gamma_0=0$ and\n$v(L)=u_1(L)-u_2(L)=\\gamma_L-\\gamma_L=0$, so $\\|v\\|_\\infty\\le0$ by \nTheorem~\\ref{thm: Lu=f apriori infty}, which means that $u_1=u_2$ on~$[0,L]$.\n\nSimilarly, since $\\mathcal{L}$ is linear, we find that\n\\[\n\\mathcal{L}\\delta u=\\delta f\\quad\\text{on $(0,L)$,}\n    \\quad\\text{with $\\delta u(0)=\\delta\\gamma_0$ \nand $\\delta u(L)=\\delta\\gamma_L$,}\n\\]\nand Theorem~\\ref{thm: Lu=f apriori infty} implies the desired estimate \nfor~$\\|\\delta u\\|_\\infty$.\n\\end{proof}\n\n\\section{Discrete maximum principle}\n\nWe will now establish a maximum principle for our finite difference \napproximation to the two-point boundary-value problem~\\eqref{eq: two-point bvp} \nin the case\n\\begin{equation}\\label{eq: discrete max assumptions}\nb(x)=0,\\qquad\\alpha_0=0,\\quad\\beta_0=1,\\quad\\alpha_L=0,\\quad\\beta_L=1.\n\\end{equation}\nThus, \n\\begin{equation}\\label{eq: simple Lu=f}\n(\\mathcal{L}u)(x)=-a(x)u''(x)+c(x)u(x)=f(x)\\quad\\text{for~$0<x<L$,}\\quad\n\\text{with $u(0)=\\gamma_0$~and $u(L)=\\gamma_L$.}\n\\end{equation}\nLikewise,\n\\[\n(\\mathcal{L}_{\\Delta x}U)_p=-a_p\\,\\frac{U_{p+1}-2U_p+U_{p-1}}{\\Delta x^2}\n\t+c_pU_p\\quad\\text{for $1\\le p\\le P-1$,}\n\\]\nand our finite difference method is (case~1 in \nsection~\\ref{sec: gen two-point bvp})\n\\begin{equation}\\label{eq: finite diff Dirichlet 1d}\n(\\mathcal{L}_{\\Delta x}U)_p=f_p\\quad\\text{for $1\\le p\\le P-1$,}\\quad\n\t\\text{with $U_0=\\gamma_0$ and $U_P=\\gamma_L$.}\n\\end{equation}\nThe following discrete analogue of Theorem~\\ref{lem: Lu<0} holds.\n\n\\begin{lemma}\\label{lem: discrete LU<0}\nAssume \\eqref{eq: discrete max assumptions}.\nIf $c_p\\ge0$ and $(\\mathcal{L}_{\\Delta x}U)_p<0$ for~$1\\le p\\le P-1$, then\nthere is no $p^*$ in the range $1\\le p^*\\le P-1$ for which\n\\[\nU_{p^*}\\ge 0,\\qquad U_{p^*-1}\\le U_{p^*}\\qquad\\text{and}\\qquad\nU_{p^*+1}\\le U_{p^*}.\n\\]\n\\end{lemma}\n\\begin{proof}\nIf such a $p^*$ exists, then $U_{p^*+1}+U_{p^*-1}\\le 2U_{p^*}$ so\n\\[\n(\\mathcal{L}_{\\Delta x}U)_{p^*}\n\t=a_{p^*}\\,\\frac{-U_{p^*+1}+2U_{p^*}-U_{p^*-1}}{\\Delta x^2}\n\t+c_{p^*}U_{p^*}\\ge 0,\n\\]\ncontradicting the second hypothesis of the lemma.\n\\end{proof}\n\nA discrete analogue of Theorem~\\ref{thm: max principle 1d} then follows.\n\n\\begin{theorem}\\label{thm: discrete max principle}\nAssume \\eqref{eq: discrete max assumptions}.\nIf $c_p\\ge0$ and $(\\mathcal{L}_{\\Delta x}U)_p\\le0$ for $1\\le p\\le P-1$, then \n\\[\nU_p\\le\\max\\{U_0^+,U_P^+\\}\\quad\\text{for $1\\le p\\le P-1$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $\\epsilon>0$~and $\\mu>0$, and put $W_p=U_p+\\epsilon e^{\\mu x_p}$.  \nWe see from~\\eqref{eq: second diff remainder} that the \nfunction~$g(x)=e^{\\mu x}$ satisfies\n\\[\n\\frac{g(x_{p+1})-2g(x_p)+g(x_{p-1})}{\\Delta x^2}-g''(x_p)\n\t=\\frac{1}{\\Delta x^2}\\bigl[(R_3g)(x_p,\\Delta x)+(R_3g)(x_p,-\\Delta x)\\bigr],\n\\]\nwhere\n\\begin{align*}\n(R_3g)(x_p,\\Delta x)\n\t&=\\frac{1}{4!}\\int_{x_p}^{x_{p+1}}(x_{p+1}-y)^3g^{(4)}(y)\\,dy,\\\\\n(R_3g)(x_p,-\\Delta x)\n\t&=\\frac{(-1)^4}{4!}\\int_{x_{p-1}}^{x_p}(y-x_{p-1})^3g^{(4)}(y)\\,dy.\n\\end{align*}\nSince $g^{(4)}(y)=\\mu^4e^{\\mu y}\\ge0$ for all~$y$, it follows that\n$(R_3g)(x_p,\\pm\\Delta x)\\ge0$ and thus\n\\[\n\\frac{g(x_{p+1})-2g(x_p)+g(x_{p-1})}{\\Delta x^2}\\ge g''(x_p)=\\mu^2e^{\\mu x_p}.\n\\]\nHence, \n\\begin{align*}\n(\\mathcal{L}_{\\Delta x}W)_p&=(\\mathcal{L}_{\\Delta x}U)_p\n\t+\\epsilon\\biggl(-a_p\\,\\frac{g(x_{p+1})-2g(x_p)+g(x_{p-1})}{\\Delta x^2}\n\t+c_pg(x_p)\\biggr)\\\\\n\t&\\le (\\mathcal{L}_{\\Delta x}U)_p\n\t\t+\\epsilon\\bigl(-a_p\\mu^2e^{\\mu x_p}+c_pe^{\\mu x_p}\\bigr)\n\t\\le0-\\epsilon(a_{\\min}\\mu^2-\\|c\\|_\\infty)e^{\\mu x_p}, \n\\end{align*}\nand by choosing $\\mu^2>\\|c\\|_\\infty/a_{\\min}$ we can ensure that \n$(\\mathcal{L}_{\\Delta x}U)_p<0$ for~$1\\le p\\le P-1$.  By \nLemma~\\ref{lem: discrete LU<0}, we conclude that\n\\[\nU_p\\le W_p\\le W_p^+\\le\\max\\{W_0^+,W_P^+\\}\n\t=\\max\\{U_0^++\\epsilon,U_P^++\\epsilon e^{\\mu L}\\}\n\\]\nfor $1\\le p\\le P-1$.  Since this inequality holds for any $\\epsilon>0$, the \nresult follows.\n\\end{proof}\n\nNext is a discrete version of Theorem~\\ref{thm: max min 1d}.\n\n\\begin{theorem}\nAssume \\eqref{eq: discrete max assumptions}.\nIf $c_p\\ge0$ and $(\\mathcal{L}_{\\Delta x}U)_p=f_p$ for $1\\le p\\le L$, then\n\\[\n\\max_{0\\le p\\le P}U_p\\le\\max\\{U^+_0,U^+_P\\}+\\frac{L^2}{8a_{\\min}}\n\t\\max_{1\\le q\\le P-1}f_q^+\n\\]\nand\n\\[\n\\min_{0\\le p\\le P}U_p\\ge\\min\\{U^+_0,U^+_P\\}+\\frac{L^2}{8a_{\\min}}\n\t\\max_{1\\le q\\le P-1}f_q^-\n\\]\n\\end{theorem}\n\\begin{proof}\nLet \n\\[\nW_p=\\max\\{U^+_0,U^+_P\\}+V_p\\max_{1\\le q\\le P-1}f_q^+\n\\quad\\text{where}\\quad\nV_p=\\frac{x_p(L-x_p)}{2a_{\\min}}.\n\\]\nSince the second-order central difference formula is exact for a quadratic \npolynomial,\n\\[\n\\frac{V_{p+1}-2V_p+V_{p-1}}{\\Delta x^2}=\\frac{-1}{a_{\\min}}\n\\]\nand thus, noting that $V_p\\ge0$, we conclude that\n\\[\n(\\mathcal{L}_{\\Delta x}V)_p=\\frac{a_p}{a_{\\min}}+c_pV_p\\ge1\n\t\\quad\\text{for $1\\le p\\le P-1$.}\n\\]\nIt follows that\n\\[\n(\\mathcal{L}_{\\Delta x}W)_p=\\max\\{U^+_0,U^+_P\\}(\\mathcal{L}_{\\Delta x}1)_p\n\t+\\Bigl(\\max_{1\\le q\\le P-1}f_q^+\\Bigr)(\\mathcal{L}_{\\Delta x}V)_p\n\t\\ge\\max_{1\\le q\\le P-1}f_q^+\n\\]\nand so\n\\[\n\\bigl(\\mathcal{L}_{\\Delta x}(U-W)\\bigr)_p=f_p-(\\mathcal{L}_{\\Delta x}W)_p\n\t\\le f_p-\\max_{1\\le q\\le P-1}f_q^+\\le0\\quad\\text{for $1\\le p\\le P-1$,}\n\\]\nwith\n\\[\n(U-W)_0=U_0-\\max{U_0^+,U_P^+}\\le0\n\\quad\\text{and}\\quad\n(U-W)_P=U_P-\\max{U_0^+,U_P^+}\\le0.\n\\]\nBy Theorem~\\ref{thm: discrete max principle},\n\\[\nU_p-W_p\\le\\max\\{(U-W)_0^+,(U-W)_P^+\\}\\le0\\quad\\text{for $1\\le p\\le P-1$,}\n\\]\nand the first inequality follows because\n\\[\nU_p\\le W_p\\le\\max\\{U^+_0,U^+_P\\}\n\t+\\biggl(\\max_{0\\le x\\le L}\\frac{x(L-x)}{2a_{\\min}}\\biggr)\n\t\\biggl(\\max_{1\\le q\\le P-1}f_q^+\\biggr). \n\\]\nThe second follows because $\\bigl(\\mathcal{L}_{\\Delta x}(-U)\\bigr)_p=-f_p$,\n$(-U)_p^+=-U_p^-$~and $(-f)_p^+=-f_p^-$.\n\\end{proof}\n\nOur final result for this section is a discrete version of \nTheorem~\\ref{thm: Lu=f apriori infty}.\n\n\\begin{theorem}\\label{thm: discrete apriori 1D}\nAssume \\eqref{eq: discrete max assumptions}. If $c\\ge0$ on~$(0,L)$, then the\nfinite difference equations~\\eqref{eq: finite diff Dirichlet 1d} have a unique\nsolution~$U_p$, and\n\\[\n\\max_{0\\le p\\le P}|U_p|\\le\\max\\{|\\gamma_0|,|\\gamma_L|\\}\n    +\\frac{L^2}{8a_{\\min}}\\max_{1\\le q\\le P-1}|f_q|.\n\\]\n\\end{theorem}\n\\begin{proof}\nThe \\emph{a priori} estimate for~$U_p$ follows at once from \nTheorem~\\ref{thm: max min 1d}.  To prove existence and uniqueness, we write the \nfinite difference equations in matrix form, as \nin~\\eqref{eq: finite diff matrix 1d} except that \nnow $\\boldsymbol{B}=\\boldsymbol{0}$ so\n\\[\n(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}=\\boldsymbol{f}+\\boldsymbol{g}.\n\\]\nThe \\emph{a priori} estimate shows that if $f_p=0$ for~$1\\le p\\le P-1$ and \n$\\gamma_0=0=\\gamma_L$, then $U_p=0$ for~$0\\le p\\le P$.  In other words if \n$\\boldsymbol{f}=\\boldsymbol{0}=\\boldsymbol{g}$, then \n$\\boldsymbol{U}=\\boldsymbol{0}$.  Thus, the homogeneous linear system admits \nonly the trivial solution, which implies that the \nmatrix~$\\boldsymbol{A}+\\boldsymbol{C}$ is non-singular and so the linear system \nis uniquely solvable for any $f_p$, $\\gamma_0$~and $\\gamma_L$.\n\\end{proof}\n\n\\section{An error bound}\n\nThe finite difference method defined in section~\\ref{sec: gen two-point bvp}\nis said to be \\emph{stable} if a unique solution~$U_p$ exists for any choice of \nthe data $f_p$, $\\gamma_0$~and $\\gamma_L$, and if there is a constant~$C$ --- \nindependent of $f_p$, $\\gamma_0$, $\\gamma_L$~and $\\Delta x$ --- such that\n\\[\n\\max_{0\\le p\\le P}|U_p|\\le C\\Bigl(|\\gamma_0|+|\\gamma_L|\n    +\\max_{1\\le p\\le P-1} |f_p|\\Bigr).\n\\]\nFor example, by Theorem~\\ref{thm: discrete apriori 1D}, the \nconditions~\\eqref{eq: discrete max assumptions} are sufficient to ensure \nstability.\n\nSuppose $\\alpha_0=0=\\alpha_L$ (that is, case~1). We define the \n\\emph{local truncation error}~$\\tau_p$ by\n\\[\n\\tau_p=f_p-(\\mathcal{L}_{\\Delta x}u)_p\n    =(\\mathcal{L}u)_p-(\\mathcal{L}_{\\Delta x}u)_p,\n\\]\nand note that\n\\begin{multline*}\n\\tau_p=-a_p\\biggl(\n    u''(x_p)-\\frac{u(x_p+\\Delta x)-2u(x_p)+u(x_p-\\Delta x)}{\\Delta x^2}\\biggr)\\\\\n+b_p\\biggl(u'(x_p)-\\frac{u(x_p+\\Delta x)-u(x_p-\\Delta x)}{2\\,\\Delta x}\\biggr)\n\\end{multline*}\nso, by Theorems \\ref{thm: 2nd central diff}~and \\ref{thm: first central diff},\n\\begin{equation}\\label{eq: tau_p bound}\n|\\tau_p|\\le\\biggl(\\frac{|a_p|}{12}\\,\\|u^{(4)}\\|_\\infty\n    +\\frac{|b_p|}{6}\\,\\|u^{(3)}\\|_\\infty\\biggr)\\,\\Delta x^2.\n\\end{equation}\nSince $(\\mathcal{L}_{\\Delta x}U)_p=f_p=(\\mathcal{L}u)_p$ and since the \nfinite difference operator~$\\mathcal{L}_{\\Delta x}$ is linear, it follows that\nthe \\emph{solution error},\n\\[\nE_p=U_p-u(x_p)\n\\]\nsatisfies\n\\[\n(\\mathcal{L}_{\\Delta x}E)_p=(\\mathcal{L}_{\\Delta x}U)_p\n    -(\\mathcal{L}_{\\Delta x}u)_p=\\tau_p\\quad\\text{for $1\\le p\\le P-1$.}\n\\]\nMoreover, since $U_0=\\gamma_0=u(x_0)$~and $U_P=\\gamma_L=u(x_P)$ we have \n$E_0=0=E_P$.  Therefore, the stability property applies with $U_p$, $f_p$, \n$\\gamma_0$~and $\\gamma_L$ replaced by $E_p$, $\\tau_p$, $0$~and $0$, \nrespectively, and so\n\\[\n\\max_{0\\le p\\le P}|E_p|\\le C\\max_{1\\le p\\le P-1}|\\tau_p|.\n\\]\nCombining this estimate with~\\eqref{eq: tau_p bound} we obtain the error bound\n\\[\n|U_p-u(x_p)|\\le C \\biggl(\\frac{\\|a\\|_\\infty}{12}\\,\\|u^{(4)}\\|_\\infty\n    +\\frac{\\|b\\|_\\infty}{6}\\,\\|u^{(3)}\\|_\\infty\\biggr)\\,\\Delta x^2\n    \\quad\\text{for $0\\le p\\le P$.}\n\\]\nIn other words,\n\\[\nU_p=u(x_p)+O(\\Delta x^2)\\quad\\text{as $\\Delta x\\to0$, for $0\\le p\\le P$,}\n\\]\nshowing that the finite difference method is \\emph{second-order accurate}.\n\nIt turns out that for many numerical methods, there is an exponent~$r>0$ and a \ncontinuous function~$v(x)$ such that\n\\begin{equation}\\label{eq: Ep asymp}\nE_p=U_p-u(x_p)=v(x_p)\\,\\Delta x^r+O(\\Delta x^{r+\\epsilon})\n\\end{equation}\nfor some~$\\epsilon>0$.  Therefore, if we let\n\\[\n\\mathcal{E}(\\Delta x)=\\max_{0\\le p\\le P}|E_p|\n\\]\nthen\n\\[\n\\mathcal{E}(\\Delta x)\\approx\\Bigl(\\max_{0\\le x\\le L}|v(x)|\\Bigr)\\,\\Delta x^2.\n\\]\nIt follows that we can estimate the value of~$r$ by computing the ratio\n\\[\n\\frac{\\mathcal{E}(2\\,\\Delta x)}{\\mathcal{E}(\\Delta x)}\\approx 2^r\n\\]\nand taking logarithms (to base~2):\n\\[\nr\\approx\\log_2\\frac{\\mathcal{E}(2\\,\\Delta x)}{\\mathcal{E}(\\Delta x)}.\n\\]\nMore precisely, the logarithm on the right will converge to~$r$ \nas~$\\Delta x\\to0$.\n\n\\begin{table}\n\\caption{Convergence behaviour of the finite difference solution from\n\\cref{example: bvp1d conv}}\\label{table: bvp1d conv}\n\\begin{center}\n\\renewcommand{\\arraystretch}{1.2}\n\\begin{tabular}{r|cc}\n\\multicolumn{1}{c|}{$P$}&max error&rate\\\\\n\\hline\n   8&   5.28e-03&\\\\\n  16&   1.33e-03&   1.986\\\\\n  32&   3.34e-04&   1.998\\\\\n  64&   8.35e-05&   1.999\\\\\n 128&   2.09e-05&   2.000\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\begin{example}\\label{example: bvp1d conv}\nLet $e_P=\\max_{0\\le p\\le P}|U_p-u(x_p)|$ denote the maximum error in the finite \ndifference solution for a grid with $P$~subintervals.  The argument above shows \nthat if the error behaves as in~\\eqref{eq: Ep asymp} then\n\\begin{equation}\\label{eq: eP asymp}\nr\\approx\\log_2\\frac{E_{P/2}}{E_P}.\n\\end{equation}\n\\Cref{table: bvp1d conv} shows the values of the maximum error~$e_P$ and \nthe estimated convergence rates according to~\\eqref{eq: eP asymp} as we \nrepeatedly double~$P$, using the problem from \\cref{example: bvp1d example}.\nThese results confirm that the finite difference scheme is second-order \naccurate, that is, $r=2$.\n\\end{example}\n\n\\begin{Exercises}\n\n\\exercise\\label{ex: u const f}\nVerify that \\eqref{eq: u const f} satisfies \\eqref{eq: model 1d} if $f(x)=c$.\n\n\\exercise\\label{ex: variation of params}\nBy following the steps below, use variation of parameters to  verify that \n\\eqref{eq: model 1d exact soln} solves \\eqref{eq: model 1d} for a \ngeneral~$f(x)$.  Let\n\\[\nu_1(x)=L-x\\quad\\text{and}\\quad u_2(x)=x\n\\]\nand write\n\\[\nu(x)=v_1(x)u_1(x)+v_2(x)u_2(x).\n\\]\n\\begin{description}\n\\item{(i)} Verify that $u_1$~and $u_2$ are solutions of the homogeneous \nequation~$u''=0$, and find their Wronskian\n\\[\nW=\\begin{vmatrix}u_1&u_2\\\\ u_1'&u_2' \\end{vmatrix}.\n\\]\n\\item{(ii)} Hence, noting that $u''=-f(x)$, determine\n\\[\nv_1'(x)=-\\frac{u_2(x)[-f(x)]}{W(x)}=\\frac{u_2(x)f(x)}{W(x)}\n\\quad\\text{and}\\quad\nv_2'(x)=\\frac{u_1(x)[-f(x)]}{W(x)}=-\\frac{u_1(x)f(x)}{W(x)}.\n\\]\n\\item{(iii)}\nFind $v_1$~and $v_2$, using the boundary conditions $u(0)=\\gamma_0$~and \n$u(L)=\\gamma_L$ to determine the constants of integration.\n\\item{(iv)} Deduce from \\eqref{eq: model 1d exact soln} that if $f(x)\\ge0$ \nfor~$0\\le x\\le L$, then the graph of~$u(x)$ is always above the straight line \njoining $(0,\\gamma_0)$~and $(L,\\gamma_L)$.  What if $f(x)\\le0$ \nfor~$0\\le x\\le L$?\n\\end{description}\n\\begin{ans}\n(i) $W(x)=L$\\quad (ii) $v_1'=\\dfrac{xf(x)}{L}$, \n$v_2'=\\dfrac{(L-x)f(x)}{L}$\\quad (iii) We have\n\\[\nv_1(x)=A+\\int_0^x\\frac{yf(y)}{L}\\,dy\n\\quad\\text{and}\\quad\nv_2(x)=B+\\int_x^L\\frac{(L-y)f(y)}{L}\\,dy,\n\\]\nand the boundary conditions imply that $A=\\gamma_0$ and $B=\\gamma_L$.\n\\end{ans}\n\n\\exercise\nUse Taylor expansion to find the coefficient~$c$ such that, as~$x\\to0$,\n\\begin{description}\n\\item{(i)}\n$\\dfrac{x}{1-x^2}-\\sin x=cx^3+O(x^5)$.\n\\item{(ii)}\n$\\log\\cos x=cx^2+O(x^4)$.\n\\item{(iii)}\n$\\dfrac{x-\\sinh x}{x^3}=c+O(x^2)$.\n\\end{description}\n\\begin{ans}\n(i) $7/6$\\quad (ii) $-1/2$\\quad (iii) $-1/6$\n\\end{ans}\n\n\\exercise\nUse Taylor expansion to find the coefficient~$c$ such that\n\\begin{description}\n\\item{(i)} $\\dfrac{3u(x)-4u(x-h)+u(x-2h)}{2h}\n=u'(x)+cu'''(x)\\,h^2+O(h^3)$.\n\\item{(ii)} $\\dfrac{-u(x+2h)+4u(x+h)-3u(x)}{2h}\n=u'(x)+cu'''(x)\\,h^2+O(h^3)$.\n\\end{description}\n\\begin{ans}\n(i) $c=-1/3$ \\quad(ii) $c=-1/3$\n\\end{ans}\n\n\\begin{table}\n\\caption{Errors in the approximations of $f'(a)$ from \nExercise~\\ref{ex: complex deriv}.}\n\\label{tab: complex deriv}\n\\begin{center}\n\\renewcommand{\\arraystretch}{1.2}\n\\ttfamily\n\\begin{tabular}{lrr}\n\\multicolumn{1}{c}{$h$}&\n\\multicolumn{1}{c}{$\\epsilon_1(h)$}&\n\\multicolumn{1}{c}{$\\epsilon_2(h)$}\\\\\n\\hline\n$10^{-2}$ &-9.00e-06&9.01e-06\\\\\n$10^{-4}$ &-9.02e-10&9.01e-10\\\\\n$10^{-6}$ & 8.52e-11&9.02e-14\\\\\n$10^{-8}$ &-4.02e-09&0.00e+00\\\\\n$10^{-10}$& 1.22e-06&0.00e+00\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\exercise\\label{ex: complex deriv} \nLet $f$ be complex analytic in a neighbourhood of a point~$a$ on the real axis, \nand assume that $f(x)$ is real when $x$ is real.\n\\begin{description}\n\\item{(i)} Show that $\\Im f(a+ih)/h=f'(a)+O(h^2)$ if $h\\to0$ and $h$ is real.\n\\item{(ii)} \\cref{tab: complex deriv} shows the values of\n\\[\n\\epsilon_1(h)=\\frac{f(a+h)-f(a-h)}{2h}-f'(a)\n\\quad\\text{and}\\quad\n\\epsilon_2(h)=\\frac{\\Im f(a+ih)}{h}-f'(a),\n\\]\nwhen $f(x)=x^2+\\sin x$ and $a=1$, for different choices of~$h$, with all \ncomputations performed in standard 64~bit floating-point arithmetic.  Explain \nthe different behavior of $\\epsilon_1(h)$ and $\\epsilon_2(h)$.\n\\end{description}\n\n\\exercise\nConsider the boundary value problem\n\\[\n\\begin{aligned}\n-u''+2u'-u&=1&&\\text{for $0<x<2$,}\\\\\nu&=1&&\\text{at $x=0$,}\\\\\nu&=-1&&\\text{at $x=2$.}\n\\end{aligned}\n\\]\n\\begin{description}\n\\item{(i)}\nSet up a finite difference approximation as explained in lectures\nwith $P=4$ (so $\\Delta x=1/2$).\n\\item{(ii)}\nEliminate the variables $U_0$ and $U_4$ to obtain a $3\\times3$ linear\nsystem.\n\\item{(iii)}\nSolve the linear system to find $U_1$, $U_2$~and $U_3$.  (You can use\nfor favourite software.)\n\\item{(iv)}\nFind the exact solution~$u(x)$, and hence compute the errors~$E_p=U_p-u(x_p)$ \nin your numerical solution.\n\\end{description}\n\\begin{ans}\n(i) $-6U_{p-1}+7U_p-2U_{p-1}=1$ for $1\\le p\\le3$\\quad\n(ii) Since $U_0=1$ and $U_4=-1$,\n\\[\n\\begin{bmatrix}7&-2& 0\\\\ -6& 7&-2\\\\  0&-6& 7\\end{bmatrix}\n\\begin{bmatrix}U_1\\\\ U_2\\\\ U_3\\end{bmatrix}\n=\\begin{bmatrix}7\\\\ 1\\\\ -1\\end{bmatrix}\n\\]\n(iii) $U_1=269/175=1.5371$, $U_2=47/25=1.88$,\n$U_3=257/175=1.4686$\\\\\n(iv) $u=(2-x)e^x-1$ so the errors $E_p=U_p-u(x_p)$ are\n$E_1=0.06406$, $E_2=-0.16172$, $E_3=0.22773$.\n\\end{ans}\n\n\\exercise\nConsider the two-point boundary-value problem\n\\[\n-u''=f(x)\\quad\\text{for $0<x<L$,}\n\t\\quad\\text{with $-u'(0)=\\gamma_0$ and $u'(L)=\\gamma_L$.}\n\\]\n\\begin{description}\n\\item{(i)} Show that if $u(x)$ is a solution then so is $u(x)+C$ for any \nconstant~$C$.\n\\item{(ii)} Show that if $u(x)$ exists, then \n$\\gamma_0+\\gamma_L+\\int_0^Lf(x)\\,dx=0$.\n\\item{(iii)} Use central difference approximations of the form \n\\eqref{eq: u'' approx}~and \\eqref{eq: u' approx} to derive a $(P+1)\\times(P+1)$ \nlinear system \n$\\boldsymbol{A}\\boldsymbol{U}=\\boldsymbol{f}+\\boldsymbol{g}$ that yields\n$U_p\\approx u(x_p)$ for~$0\\le p\\le P$.  When $P=5$ you should obtain\n\\[\n\\frac{1}{\\Delta x^2}\\begin{bmatrix}\n 1&-1&  &  &  &\\\\                     \n-1& 2&-1&  &  &\\\\\n  &-1& 2&-1&  &\\\\\n  &  &-1& 2&-1&\\\\\n  &  &  &-1& 2&-1\\\\\n  &  &  &  &-1& 1\n\\end{bmatrix}\n\\begin{bmatrix}U_0\\\\ U_1\\\\ U_2\\\\ U_3\\\\ U_4\\\\ U_5\\end{bmatrix}\n=\\begin{bmatrix}\\tfrac12f_0\\\\ f_1\\\\ f_2\\\\ f_3\\\\ f_4\\\\ \\tfrac12 f_5\n\\end{bmatrix}\n+\\frac{1}{\\Delta x}\n\\begin{bmatrix}\\gamma_0\\\\ 0\\\\ 0\\\\ 0\\\\ 0\\\\ \\gamma_L\\end{bmatrix}.\n\\]\nHint: applying central differences at $x_0$~and $x_P$ requires the use of \n``ghost'' grid points $x_{-1}$~and $x_{P+1}$ lying outside the interval~$[0,L]$.\nHowever, the boundary conditions allow you to eliminate $U_{-1}$~and $U_{P+1}$.\n\\item{(iv)} Show that if $\\boldsymbol{U}=[U_p]$ is a solution, then so is \n$[U_p+C]$.\n\\item{(v)} Show that if a solution~$\\boldsymbol{U}$ exists, then\n\\[\n\\gamma_0+\\gamma_L+\\bigl(\\tfrac12f_0+f_1+f_2+\\cdots+f_{P-1}+\\tfrac12f_P\\bigr)\n\\Delta x=0.\n\\]\n\\item{(vi)} If we interpret the ODE as a steady-state heat equation, what is \nthe physical meaning of the condition in~(ii), and of its discrete analogue \nin~(v)?\n\\end{description}\n\n\\exercise\nHow can we use the $LDL^\\top$ factorization of an $n\\times n$, symmetric \ntridiagonal matrix~$\\boldsymbol{A}$ to compute its determinant?\n\\begin{ans} \n$\\det\\boldsymbol{A}=d_1d_2\\cdots d_n$\n\\end{ans}\n\n\\exercise\nFind the $LDL^\\top$ factorization of the matrix\n\\[\n\\boldsymbol{A}=\\begin{bmatrix}1&-1&0&0\\\\ -1&4&6&0\\\\ 0&6&14&6\\\\ 0&0&6&22\n\\end{bmatrix}.\n\\]\n\\begin{ans}\n$\\boldsymbol{L}=\\begin{bmatrix}1&0&0&0\\\\ -1&1&0&0\\\\ 0&2&1&0\\\\ 0&0&3&1 \n\\end{bmatrix}$,\n$\\boldsymbol{D}=\\begin{bmatrix}1&&&\\\\ &3&&\\\\ &&2&&\\\\ &&&4\\end{bmatrix}$\n\\end{ans}\n\n\\exercise\nIf $\\boldsymbol{A}$ is symmetric tridiagonal matrix, then instead of the \nfactorization~\\eqref{eq: L D LT} we can seek a tridiagonal, upper triangular\nmatrix~$\\boldsymbol{R}$ such that \n$\\boldsymbol{A}=\\boldsymbol{R}^\\top\\boldsymbol{R}$.  We call $\\boldsymbol{R}$ \nthe \\emph{Cholesky factor} of~$\\boldsymbol{A}$.\n\\begin{description}\n\\item{(i)} Show that if a matrix~$\\boldsymbol{A}$ has a Cholesky factorization, \nthen $\\boldsymbol{A}$ is necessarily symmetric and positive semidefinite.\n\\item{(ii)} Show that if the Cholesky factor is non-singular, then \n$\\boldsymbol{A}$ must be \\emph{strictly} positive-definite.\n\\item{(iii)} Consider the $5\\times5$ case and denote the entries \nof~$\\boldsymbol{A}$ as in~\\eqref{eq: A symm tridiagonal}.  Determine a sequence \nof formulae to compute the entries of\n\\[\n\\boldsymbol{R}=\\begin{bmatrix}\nd_1&u_1&   &   &\\\\\n   &d_2&u_2&   &\\\\\n   &   &d_3&u_3&\\\\\n   &   &   &d_4&u_4\\\\\n   &   &   &   &u_5\\end{bmatrix}.\n\\]\n\\item{(iv)} Hence formulate an algorithm to compute~$\\boldsymbol{R}$ in the \ngeneral, $n\\times n$~case.\n\\item{(v)} Formulate an in-place version of the algorithm in part~(iv).\n\\item{(vi)} How is the Cholesky factorization used to solve a linear \nsystem~$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$?\n\\item{(vii)} Show that the algorithm is stable (provided $\\boldsymbol{A}$ is \npositive-definite) in the sense that all entries of~$\\boldsymbol{R}$ can be \nbounded by entries of~$\\boldsymbol{A}$.\n\\end{description}\n\\begin{ans}\n(i)\n\\[\n\\begin{aligned}\nd_1&=\\sqrt{\\alpha_1},&u_1&=\\beta_1/d_1,\\\\\nd_2&=\\sqrt{\\alpha_2-u_1^2},&u_2&=\\beta_2/d_2\\\\\nd_3&=\\sqrt{\\alpha_3-u_2^2},&u_3&=\\beta_3/d_3\\\\\nd_4&=\\sqrt{\\alpha_4-u_3^2},&u_4&=\\beta_3/d_3\\\\\nd_5&=\\sqrt{\\alpha_5-u_4^2}.\n\\end{aligned}\n\\]\n\\end{ans}\n\n\n\\exercise\nConsider the ODE in \\emph{divergence form}:\n\\begin{equation}\\label{eq: ODE divergence form}\n-\\frac{d}{dx}\\biggl(a(x)\\,\\frac{du}{dx}\\biggr)=f(x)\\quad\\text{for $0<x<L$.}\n\\end{equation}\n\\begin{description}\n\\item{(i)}\nFind $w(x)$ such that\n\\begin{multline*}\n\\frac{1}{\\Delta x}\\biggl(\n a(x+\\tfrac12\\Delta x)\\,\\frac{u(x+\\Delta x)-u(x)}{\\Delta x}\n-a(x-\\tfrac12\\Delta x)\\,\\frac{u(x)-u(x-\\Delta x)}{\\Delta x}\\biggr)\\\\\n    =\\frac{d}{dx}\\biggl(a(x)\\,\\frac{du}{dx}\\biggr)+w(x)\\Delta x^2+O(\\Delta x^4)\n    \\quad\\text{as $\\Delta x\\to0$.}\n\\end{multline*}\nHint: for $h=\\tfrac12\\Delta x$, let \n\\[\nv(x)=a(x)\\,\\frac{u(x+h)-u(x-h)}{2h}\n\\]\nand use the result\n\\[\n\\frac{v(x+h)-v(x-h)}{2h}=v'(x)+\\frac{1}{6}\\,v'''(x)h^2+O(h^4)\n    \\quad\\text{as $h\\to0$.}\n\\]\n\\item{(ii)} Hence devise a finite difference scheme with $\\Delta x=L/P$ to \nsolve \\eqref{eq: ODE divergence form} subject to the Dirichlet boundary \nconditions $u(0)=\\gamma_0$~and $u(L)=\\gamma_L$.\n\\item{(iii)} Write out the linear system in matrix form when~$P=5$.\n\\end{description}\n\\begin{ans}\n(i) $w(x)=\\bigl[(au')'''(x)+(au''')'(x)\\bigr]/24$\\quad (ii) Putting\n$a_{p\\pm1/2}=a(x_p\\pm\\tfrac12\\Delta x)$ we have\n\\[\n-\\frac{1}{\\Delta x}\\biggl(a_{p+1/2}\\,\\frac{U_{p+1}-U_p}{\\Delta x}\n    -a_{p-1/2}\\,\\frac{U_p-U_{p-1}}{\\Delta x}\\biggr)=f_p\n    \\quad\\text{for $1\\le p\\le P-1$,}\n\\]\nwith $U_0=\\gamma_0$~and $U_P=\\gamma_L$.\\quad (iii)\n\\begin{multline*}\n\\frac{1}{\\Delta x^2}\\begin{bmatrix}\n            (a_{1/2}+a_{3/2})&-a_{3/2}&&\\\\\n   -a_{3/2}&(a_{3/2}+a_{5/2})&-a_{5/2}&\\\\\n  &-a_{5/2}&(a_{5/2}+a_{7/2})&-a_{7/2}\\\\\n &&-a_{7/2}&(a_{7/2}+a_{9/2})\n\\end{bmatrix}\n\\begin{bmatrix}U_1\\\\ U_2\\\\ U_3\\\\ U_4\\end{bmatrix}\\\\\n=\\begin{bmatrix}f_1\\\\ f_2\\\\ f_3\\\\ f_4 \\end{bmatrix}+\\frac{1}{\\Delta x^2}\n\\begin{bmatrix}a_{1/2}\\gamma_0\\\\ \\\\ \\\\ a_{9/2}\\gamma_L \\end{bmatrix}.\n\\end{multline*}\n\\end{ans}\n\n\\end{Exercises}\n", "meta": {"hexsha": "9a7ec74ff23b2fa06be66a0ab8a9b645059005b2", "size": 55501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/chap1.tex", "max_stars_repo_name": "billmclean/ComputationalMathsNotes", "max_stars_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-30T21:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T21:30:20.000Z", "max_issues_repo_path": "texsrc/chap1.tex", "max_issues_repo_name": "billmclean/ComputationalMathsNotes", "max_issues_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "texsrc/chap1.tex", "max_forks_repo_name": "billmclean/ComputationalMathsNotes", "max_forks_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3284532145, "max_line_length": 81, "alphanum_fraction": 0.6404569287, "num_tokens": 23693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079208, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.6706756150270852}}
{"text": "\n\\section{Verifying a random number generator}\n\\Label{sec:randomnumber}\n\nWe describe in this section \\specref{randomnumber} which implements\na simple random-number generator.\nAs in the case of \\specref{shuffle} itself, we do not formulate precise\nproperties of randomness and only require its result to\nbe in the specified range \\inl{[0..n-1]}.\nAgain, the \\inl{assigns} clause to the array \\inl{state} models the\ndependency on an additional state.\n\nNote that in the following listing, we also provide the rather simple\nspecification of the function \\randominit that is called to initialize the \nstate of the random generator.\n\n\\input{Listings/random_number.h.tex}\n\nThe implementations of \\randomnumber and \\randominit are shown in the following listing.\nInternally, we rely on a custom implementation of the POSIX.1\nrandom number generator \\inl{lrand48()}\\footnote{\n  See \\url{http://pubs.opengroup.org/onlinepubs/9699919799/functions/lrand48.html}\n}\nThis random number generator is a linear congruence\ngenerator with a 48~bit state and the iteration procedure\n\\begin{equation}\n\\label{eq:random}\nx_{n+1}=ax_n+c\\bmod 2^{48}\n\\end{equation}\n%\nwhere $a=25214903917$ and $c=11$ are relatively prime integers.\n\nAs a part of the iteration procedure in Equation~\\eqref{eq:random}\nan unsigned overflow may occur.\nThis does not affect the result as we are only interested in its lowest 48 bits.\nHowever, as one of the options we use, \\inl{-warn-unsigned-overflow},\ncauses \\wpframac  assert the absence of unsigned overflow this algorithm does not verify under\nthe same options used for the other algorithms.\n%\nAs an exception, we have therefore decided to disable \\inl{-warn-unsigned-overflow}\nfor this function as the unsigned overflow is both benign and\nwell-defined (cf.\\ \\cite[\\S 6.2.5, 9]{isoc}).\n\n\\input{Listings/random_number.c.tex}\n\nNote that we use the custom acsl lemma \\logicref{RandomNumberModulo}\nfrom the following listing to support the verification of some assertions.\n\n\\input{Listings/C_Bit.acsl.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "be7c3a2a7aaa294e75cb05aa029c06ade6d0a924", "size": 2021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/mutating/random_number.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/random_number.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/random_number.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 38.1320754717, "max_line_length": 94, "alphanum_fraction": 0.7877288471, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.6706756069130801}}
{"text": "\\chapter{Kutzelnigg-Mukherjee tensor notation}\n\n\\minitoc\n\n\\begin{ntt}\\label{ntt:kutzelnigg-mukherjee-notation}\n\\thmtitle{Kutzelnigg-Mukherjee tensor notation}\nIn \\textit{Kutzelnigg-Mukherjee (KM) tensor notation}, creation operators are denoted using superscripts, $a^p\\equiv a_p\\dg$.\nConsequently, the one-particle and one-hole density matrices are written as\n$\n  \\g^p_q\n\\equiv\n  \\ip{\\F|a^pa_q|\\F}\n$\nand\n$\n  \\h_p^q\n\\equiv\n  \\ip{\\F|a_p a^q|\\F}\n$,\nrespectively.\nThe one- and two-electron integrals are also written with upper and lower indices: lower indices denote spin-orbitals in the bra and upper ones refer to spin-orbitals in the ket.\n\\begin{align}\n  h_p^q\n\\equiv\n  \\ip{\\y_p|\\op{h}|\\y_q}\n&&\n  g_{pq}^{rs}\n\\equiv\n  \\ip{pq|rs}\n&&\n  \\ol{g}_{pq}^{rs}\n\\equiv\n  \\ip{pq||rs}\n\\end{align}\nVacuum-normal-ordered excitations are given the compact notation\n$\n  a^{p_1\\cd p_m}_{q_1\\cd q_m}\n\\equiv\n  a^{p_1}\\cd a^{p_m}a_{q_m}\\cd a_{q_1}\n$\nand $\\F$-normal-ordered excitations are written as\n$\n  \\tl{a}^{p_1\\cd p_m}_{q_1\\cd q_m}\n\\equiv\n  \\gno{a^{p_1}\\cd a^{p_m}a_{q_m}\\cd a_{q_1}}\n$.\nUsing upper and lower indices enables one to employ the \\textit{Einstein summation convention}, in which any index that appears twice in a product, once as a lower index and once as an upper one, is implicitly summed over.\nAs an example, consider the electronic Hamiltonian as expressed in KM notation.\n\\begin{align}\n  H\n=\n  h_p^q\n  a^p_q\n+\n  \\tfr{1}{4}\n  \\ol{g}_{pq}^{rs}\n  a^{pq}_{rs}\n=\n  E_{\\text{ref}}\n+\n  H_{\\text{c}}\n&&\n  H_{\\text{c}}\n=\n  f_p^q\n  \\tl{a}^p_q\n+\n  \\tfr{1}{4}\n  \\ol{g}_{pq}^{rs}\n  \\tl{a}^{pq}_{rs}\n&&\n  E_{\\text{ref}}\n\\equiv\n  h_p^q\n  \\g^p_q\n+\n  \\tfr{1}{2}\n  \\ol{g}_{pr}^{qs}\n  \\g^p_q\n  \\g^r_s\n&&\n  f_p^q\n\\equiv\n  h_p^q\n+\n  \\ol{g}_{pr}^{qs}\n  \\g_s^r\n\\end{align}\nHere, $E_{\\text{ref}}$ is the Hartree-Fock reference energy, $f_p^q$ denotes a matrix element of the Fock operator, and $H_{\\text{c}}$ denotes the correlation component of the Hamiltonian.\nMore generally, if $\\op{v}$ is an \\textit{$m$-electron operator}, i.e.\\ an operator that acts on $m$ electronic coordinates, its second quantized form is expressed in KM notation as\n\\begin{align}\\label{eq:interaction-tensor}\n  \\left.\n  \\op{v}\\,\n  \\right|_{\\mc{F}(\\mc{H})}\n=&\\\n  \\tfr{1}{m!}\n  v_{p_1\\cd p_m}^{q_1\\cd q_m}\n  a^{p_1\\cd p_m}_{q_1\\cd q_m}\n&\n  v_{p_1\\cd p_m}^{q_1\\cd q_m}\n\\equiv\n  \\int\n  d(1\\cd m)\\,\n  \\y_{p_1}^*(1)\\cd \\y_{p_m}^*(m)\n  \\op{v}(1,\\ld,m)\n  \\y_{q_1}(1)\\cd \\y_{q_m}(m)\n&\n\\\\\n\\intertext{\nwhere $v_{p_1\\cd p_m}^{q_1\\cd q_m}$ is the \\textit{interaction tensor} of $\\op{v}$.\nEquivalently, $\\op{v}$ can also be expressed as\n}\n\\label{eq:antisymmetrized-interaction-tensor}\n  \\left.\n  \\op{v}\n  \\right|_{\\mc{F}(\\mc{H})}\n=&\\\n  (\\tfr{1}{m!})^2\\,\n  \\ol{v}_{p_1\\cd p_m}^{q_1\\cd q_m}\n  a^{p_1\\cd p_m}_{q_1\\cd q_m}\n&\n  \\ol{v}_{p_1\\cd p_m}^{q_1\\cd q_m}\n\\equiv\n  \\sum_\\pi^{\\mr{S}_m}\n  \\e_\\pi\n  v_{p_1\\hphantom{_{\\pi()}}\\cd p_m}^{q_{\\pi(1)}\\cd q_{\\pi(m)}}\n\\hspace{3cm}&\n\\end{align}\nwhere $\\ol{v}_{p_1\\cd p_m}^{q_1\\cd q_m}$ is an \\textit{antisymmetrized interaction tensor}.\nOrdinary interaction tensors are symmetric under simultaneous permutation of upper and lower indices, which is equivalent to changing integration variables in equation~\\ref{eq:interaction-tensor}.\nAntisymmetrized interaction tensors allow for independent permutations of upper and lower indices, with a sign factor corresponding to the parity of the permutation.\nThe same permutational symmetries are shared by the excitation operators\n\\begin{align}\\label{eq:excitation-permutational-symmetries-1}\n  \\tl{a}^{p_1\\cd p_m}_{q_1\\cd q_m}\n=\n  \\e_{\\pi}\n  \\tl{a}^{p_{\\pi(1)}\\cd p_{\\pi(m)}}_{q_1\\hphantom{_{\\pi()}}\\cd q_m}\n=\n  \\e_{\\pi}\n  \\tl{a}^{p_1\\hphantom{_{\\pi()}}\\cd p_m}_{q_{\\pi(1)}\\cd q_{\\pi(m)}}\n=\n  \\tl{a}^{p_{\\pi(1)}\\cd p_{\\pi(m)}}_{q_{\\pi(1)}\\cd q_{\\pi(m)}}\n&&\n  \\text{for all $\\pi\\in\\mr{S}_m$}\n\\end{align}\nsince creation operators anticommute with each other, as do annihilation operators.\nNote also the following rearrangements\n\\begin{align}\\label{eq:excitation-permutational-symmetries-2}\n  \\tl{a}^{p_1\\cd p_m}_{q_1\\cd q_m}\n=\n  \\gno{a^{p_1}_{q_1}\\cd a^{p_m}_{q_m}}\n&&\n  \\gno{a^{p_1\\cd p_m}_{q_1\\cd q_m}a^{r_1\\cd r_n}_{s_1\\cd s_n}}\n=\n  \\gno{a^{p_1}_{q_1}\\cd a^{p_m}_{q_m}a^{r_1}_{s_1}\\cd a^{r_n}_{s_n}}\n=\n  \\tl{a}^{p_1\\cd p_mr_1\\cd r_n}_{q_1\\cd q_ms_1\\cd s_n}\n\\end{align}\nwhich follow from the fact that the normal-ordering mapping is antisymmetric with respect to its operator string.\n\\end{ntt}\n\n\n\\begin{ntt}\\label{ntt:dot-notation}\n\\thmtitle{Dot notation for contractions}\nTo make the notation more flexible, we here augment the traditional KM notation with the following definitions of \\emph{particle $\\ptcl$ contractions} and \\emph{hole $\\hole$ contractions}.%\\footnote{The dot notation is borrowed from physics: \\url{https://en.wikipedia.org/wiki/Wick's_theorem#Definition_of_contraction}}\n\\begin{align}\n&&\n  a_{p^\\ptcl}a^{q^\\ptcl}\n\\equiv\n  \\ctr{}{a}{_p}{a} a_pa^q\n&&\n  a^{q^\\ptcl}a_{p^\\ptcl}\n\\equiv\n-\n  \\ctr{}{a}{_p}{a} a_pa^q\n&&\n  a^{q^\\hole}a_{p^\\hole}\n\\equiv\n  \\ctr{}{a}{^q}{a} a^qa_p\n&&\n  a_{p^\\hole}a^{q^\\hole}\n\\equiv\n-\n  \\ctr{}{a}{^q}{a} a^qa_p\n\\end{align}\nNote that $a^{p^\\ptcl}_{q^\\ptcl}=-\\h^p_q$ and $a^{p^\\hole}_{q^\\hole}=\\g_q^p$.\nIn $\\vac$-normal ordering, the hole contractions vanish and the particle contractions become Kronecker deltas.\nFor multiply contracted strings, different contractions will be distinguished with repeated dots, $a_{p^{\\ptcl\\ptcl}}a^{p^{\\ptcl\\ptcl}}$, or dots with numbers, $a_{p^{\\ptcl2}}a^{p^{\\ptcl2}}$.\nThis notation allows for normal ordered strings with contractions to keep all of the permutational symmetries shown in equations~\\ref{eq:excitation-permutational-symmetries-1} and~\\ref{eq:excitation-permutational-symmetries-2}.\n\\end{ntt}\n\n\\begin{ex}\\label{ex:km-notation-wick-expansions}\nUsing notations~\\ref{ntt:kutzelnigg-mukherjee-notation} and~\\ref{ntt:dot-notation}, the Wick expansions for vacuum-normal single and double excitations in terms of $\\F$-normal ones look as follows.\nThe signs are determined by pairing up contracted indices using \\cref{eq:excitation-permutational-symmetries-1,eq:excitation-permutational-symmetries-2}.\n\\begin{align*}\n  a^p_q\n=&\\\n  \\tl{a}^p_q\n+\n  \\tl{a}^{p^\\hole}_{q^\\hole}\n=\n  \\tl{a}^p_q\n+\n  \\g^p_q\n\\\\\n  a^{pq}_{rs}\n=&\\\n  \\tl{a}^{pq}_{rs}\n+\n  \\tl{a}^{p^\\hole q}_{r^\\hole s}\n+\n  \\tl{a}^{p^\\hole q}_{r\\ s^\\hole}\n+\n  \\tl{a}^{p\\ q^\\hole}_{r^\\hole s}\n+\n  \\tl{a}^{p q^\\hole}_{r s^\\hole}\n+\n  \\tl{a}^{p^\\hole q^{\\hole\\hole}}_{r^\\hole s^{\\hole\\hole}}\n+\n  \\tl{a}^{p^{\\hole\\hphantom{\\hole}} q^{\\hole\\hole}}_{r^{\\hole\\hole} s^\\hole}\n\\\\=&\\\n  \\tl{a}^{pq}_{rs}\n+\n  \\g^p_r\n  \\tl{a}^{q}_{s}\n-\n  \\g^p_s\n  \\tl{a}^{q}_{r}\n-\n  \\g^q_r\n  \\tl{a}^{p}_{s}\n+\n  \\g^q_s\n  \\tl{a}^{p}_{r}\n+\n  \\g^p_r\n  \\g^q_s\n-\n  \\g^p_s\n  \\g^q_r\n\\end{align*}\n\\end{ex}\n\n\\newpage\n\\begin{dfn}\\label{dfn:riffle-shuffles}\n\\thmtitle{Riffle shuffle permutations}\nLet $\\mr{S}_R$ be the \\textit{symmetric group on $R\\equiv(r_1,\\ld,r_k)$}, comprising all $k!$ permutations of this tuple.\nFor each integer composition\\footnote{See \\url{https://en.wikipedia.org/wiki/Composition_(combinatorics)}} $(k_1,\\ld,k_m)$ of $k$, the \\textit{$(k_1,\\ld,k_m)$-shuffles~of~$R$} partition the tuple into blocks $R_1\\cup\\cd\\cup R_m$ of the form $R_i\\equiv(r_{h_i+1},\\ld,r_{h_i+k_i})$ with $h_i\\equiv\\sum_{j=1}^{i-1}k_j$ and interleave them in all possible ways.\nThe cardinality of this subset $\\mr{S}_R^{(k_1,\\ld,k_m)}\\subseteq \\mr{S}_R$ is given by the following multinomial coefficient\n\\begin{align}\n  |\\mr{S}_R^{(k_1,\\ld,k_m)}|\n\\equiv\n  \\fr{k!}{k_1!\\cd k_m!}\n\\end{align}\nsince for each shuffle there are $k_1!\\cd k_m!$ permutations in $\\mr{S}_R$ derived by permuting the elements within each block.\nThese are termed \\textit{riffle shuffle permutations},\\footnote{See \\url{https://en.wikipedia.org/wiki/Riffle_shuffle_permutation}} by analogy with the process of cutting and interleaving a deck of cards.\n\\end{dfn}\n\n\\begin{dfn}\n\\thmtitle{Index antisymmetrizers}\nLet $\\op{P}_{(r_1/\\cd/r_k)}$ be the \\textit{full antisymmetrizer} for the indices in $R$.\\footnote{Note that we are borrowing some definitions from \\cref{dfn:riffle-shuffles}, such as $R$ and $R_i$.}\\,\\footnote{For example, we can express the position-space Slater determinant $\\F_{(p_1\\cd p_n)}(1,\\ld,n)$ as $\\fr{1}{\\sqrt{n!}}\\op{P}_{(p_1/\\cd/p_n)}\\y_{p_1}(1)\\cd \\y_{p_n}(n)$.}\nMore generally, let $\\op{P}_{(R_1/\\cd/R_m)}$ be a \\textit{reduced antisymmetrizer}, which antisymmetrizes a term in $R$ that it is already antisymmetric in each block, $R_i$.\nReduced antisymmetrization is achieved by summing over riffle shuffles.\n\\begin{align}\n  \\op{P}_{(R_1/\\cd/R_m)}\n\\equiv\n  \\sum_\\pi^{\\mr{S}_R^{(k_1,\\ld,k_m)}}\n  \\e_\\pi\n  \\op{\\pi}\n&&\n  \\op{\\pi}\\,\n  t_{r_1\\cd r_k}\n\\equiv\n  t_{\\pi(r_1)\\cd \\pi(r_k)}\n\\end{align}\nTo antisymmetrize multiple disjoint sets of indices, we use the compact notation\n$\n  \\op{P}^{(X_1|\\cd|X_l)}_{(Y_1|\\cd|Y_m)}\n\\equiv\n  \\op{P}^{(X_1)}\\cd \\op{P}^{(X_l)}\n  \\op{P}_{(Y_1)}\\cd \\op{P}_{(Y_m)}\n$,\nwhere each $X_i$ or $Y_i$ stands for a reduced antisymmetrizer argument $R_1/\\cd/R_m$ for a different set of indices.\n\\end{dfn}\n\n\\begin{ex}\nPermutation operators $\\op{\\pi}$ can be written as products of transpositions $(pq)t_{pq}\\equiv t_{qp}$.\nIn this notation,\n\\begin{align*}\n  \\op{P}_{(p/q)}\n=\n  1\n-\n  (pq)\n&&\n  \\op{P}_{(p/q/r)}\n=\n  1\n-\n  (pq)\n-\n  (pr)\n-\n  (qr)\n+\n  (pq)(qr)\n+\n  (pr)(qr)\n&&\n  \\op{P}_{(p/qr)}\n=\n  1\n-\n  (pq)\n+\n  (pr)(qr)\n\\end{align*}\nare the unique antisymmetrizers for two and three indices.\nNote that $\\op{P}_{(p/qr)}\\op{P}_{(q/r)}=\\op{P}_{(p/q/r)}$, which is an immediate consequence of the definition of the reduced antisymmetrizer.\n\\end{ex}\n\n\\begin{ex}\nUsing index antisymmetrizers, the second Wick expansion in \\cref{ex:km-notation-wick-expansions} can be expressed even more compactly.\n\\begin{align*}\n  a^{pq}_{rs}\n=&\\\n  \\tl{a}^{pq}_{rs}\n+\n  \\op{P}^{(p/q)}_{(r/s)}\n  \\tl{a}^{p^\\hole q}_{r^\\hole s}\n+\n  \\op{P}_{(r/s)}\n  \\tl{a}^{p^\\hole q^{\\hole\\hole}}_{r^\\hole s^{\\hole\\hole}}\n=\n  \\tl{a}^{pq}_{rs}\n+\n  \\op{P}^{(p/q)}_{(r/s)}\n  \\g^p_r\n  \\tl{a}^{q}_{s}\n+\n  \\op{P}_{(r/s)}\n  \\g^p_r\n  \\g^q_s\n\\end{align*}\nNote that permuting $p$ and $q$ in the second term, for example, is equivalent to ``moving the contraction dot'' from one to the other, since the excitation operators are antisymmetric in their upper and lower indices:\n$\n  (pq)\n  \\tl{a}^{p^\\hole q}_{r^\\hole s}\n=\n-\n  \\tl{a}^{q^\\hole p}_{r^\\hole s}\n=\n  \\tl{a}^{p\\,\\, q^\\hole}_{r^\\hole s}\n$.\nIn general, this allows us to reduce Wick expansions to a sum over unique contraction ``patterns'', with the remaining contractions generated from these by index antisymmetrizers.\nThe next two examples show how this works in practice.\n\\end{ex}\n\n\\begin{ex}\nReduced antisymmetrizers come into play in the Wick expansion of a triple excitation operator.\n\\begin{align}\n  a^{pqr}_{stu}\n=\n  \\tl{a}^{pqr}_{stu}\n+\n  \\op{P}^{(p/qr)}_{(s/tu)}\n  \\tl{a}^{p^\\hole qr}_{s^\\hole tu}\n+\n  \\op{P}^{(p/q/r)}_{(st/u)}\n  \\tl{a}^{p^\\hole q^{\\hole\\hole} r}_{s^\\hole t^{\\hole\\hole} u}\n+\n  \\op{P}^{(p/q/r)}\n  \\tl{a}^{p^\\hole q^{\\hole\\hole} r^{\\hole\\hole\\hole}}\n        _{s^\\hole t^{\\hole\\hole} u^{\\hole\\hole\\hole}}\n\\end{align}\nThe permutation factors are chosen as follows.\nIn the second term, permutations of $qr$ an $tu$ are omitted because they do not produce unique contractions.\nIn the third term, we can include permutations of either $pq$ or $st$ but not both.\nOtherwise, we would double-count terms like\n$\n  \\tl{a}^{p^\\hole q^{\\hole\\hole} r}_{s^\\hole t^{\\hole\\hole} u}\n$\nby also including\n$\n  \\tl{a}^{p^{\\hole\\hole} q^\\hole r}_{s^{\\hole\\hole} t^\\hole u}\n$,\nwhich represents the same contraction.\nThe same reasoning applies to the last term, where we can either antisymmetrize $pqr$ or $stu$.\n\\end{ex}\n\n\n\n\\begin{ex}\n\\thmtitle{Derivation of CIS equations in KM notation}\nA programmable expression for the CI singles Hamiltonian matrix elements, $\\ip{\\F_i^a|H_c|\\F_j^b}$,  can be derived in KM notation as follows.\n\\begin{align*}\n&\n  \\ip{\\F|\\tl{a}_a^i\\tl{a}_q^p\\tl{a}_j^b|\\F}\n=\n  \\gno{\n    a_{a^\\ptcl}^{i^\\hole}\n    a_{q^{\\ptcl\\ptcl}}^{p^\\ptcl}\n    a_{j^\\hole}^{b^{\\ptcl\\ptcl}}\n  }\n+\n  \\gno{\n    a_{a^\\ptcl}^{i^{\\hole}}\n    a_{q^{\\hole}}^{p^{\\hole\\hole}}\n    a_{j^{\\hole\\hole}}^{b^{\\ptcl}}\n  }\n=\n  \\g^i_j\\h_a^p\\h_q^b\n-\n  \\g_q^i\\g_j^p\\h_a^b\n\\\\\n&\n  \\ip{\\F|\\tl{a}_a^i\\tl{a}^{pq}_{rs}\\tl{a}_j^b|\\F}\n=\n  \\op{P}^{(p/q)}_{(r/s)}\n  \\gno{\n    a^{i^\\hole}_{a^\\ptcl}\n    a^{p^\\ptcl q^{\\hole\\hole}}_{r^\\hole s^{\\ptcl\\ptcl}}\n    a^{b^{\\ptcl\\ptcl}}_{j^{\\hole\\hole}}\n  }\n=\n  \\op{P}^{(p/q)}_{(r/s)}\n  \\g^i_r\\h^p_a\\g^q_j\\h^b_s\n\\\\\n&\n\\implies\n  \\ip{\\F_i^a|H_{\\text{c}}|\\F_j^b}\n=\n  f_p^q\\pr{\n    \\g^i_j\\h_a^p\\h_q^b\n  -\n    \\g_q^i\\g_j^p\\h_a^b\n  }\n+\n  \\tfr{1}{4}\n  \\ol{g}_{pq}^{rs}\\pr{\n    \\op{P}^{(p/q)}_{(r/s)}\n    \\g^i_r\\h^p_a\\g^q_j\\h^b_s\n  }\n=\n  f_a^b\\g_j^i\n-\n  f_j^i\\h_a^b\n+\n  \\ol{g}^{ib}_{aj}\n\\end{align*}\nwhich simplifies to\n$\\ip{\\F_i^a|H_{\\text{c}}|\\F_j^b}=f_a^b\\delta_j^i-f_j^i\\delta_a^b+\\ol{g}^{ib}_{aj}$.\nHere, we have used the fact that $\\tl{a}_i^a=a_i^a$ and $\\tl{a}_a^i=a_a^i$.\n\\end{ex}\n\n\\begin{ex}\n\\begin{samepage}\n\\thmtitle{Derivation of CID equations in KM notation}\nProjecting the CI doubles Schr\\\"odinger equation, $H_{\\text{c}}\\Y=E_{\\text{c}}\\Y$ where $\\Y=(1+\\tfr{1}{4}c_{cd}^{kl}\\tl{a}_{kl}^{cd})\\F$, by $\\F$ and $\\F_{ij}^{ab}$\ngives a system of linear equations\n\\begin{align*}\n  E_{\\text{c}}\n=&\\\n  \\ip{\\F|H_{\\text{c}}(1+\\tfr{1}{4}c_{cd}^{kl}\\tl{a}_{kl}^{cd})|\\F}\n&&\n  \\implies\n&\n  E_{\\text{c}}\n=&\\\n  \\tfrac{1}{4}\n  \\ip{\\F|H_c|\\F_{kl}^{cd}}c_{cd}^{kl}\n\\\\\n  E_{\\text{c}}c_{ab}^{ij}\n=&\\\n  \\ip{\\F_{ij}^{ab}|H_{\\text{c}}(1+\\tfr{1}{4}c_{cd}^{kl}\\tl{a}_{kl}^{cd})|\\F}\n&&\n  \\implies\n&\n  E_{\\text{c}}c_{ab}^{ij}\n=&\\\n  \\ip{\\F_{ij}^{ab}|H_{\\text{c}}|\\F}\n+\n  \\tfrac{1}{4}\n  \\ip{\\F_{ij}^{ab}|H_{\\text{c}}|\\F_{kl}^{cd}}c_{cd}^{kl}\n\\end{align*}\nwhich can be simplified into programmable expressions as follows.\\\\[5pt]\n$\n\\begin{array}{rl}\n  \\ip{\\F|\\tl{a}^{pq}_{rs}\\tl{a}_{kl}^{cd}|\\F}\n=&\n  \\op{P}^{(p/q)}_{(r/s)}\n  \\g_k^p\\g_l^q\\h_r^c\\h_s^d\n\\\\\n  \\ip{\\F|\\tl{a}_{ab}^{ij}\\tl{a}_q^p\\tl{a}_{kl}^{cd}|\\F}\n=&\n  \\op{P}^{(c/d)}\n        _{(a/b|k/l)}\n  \\gno{\n    a_{a^{\\ptcl1}b^{\\ptcl3}}\n     ^{i^{\\hole1}j^{\\hole2}}\n    a_{q^{\\ptcl2}}\n     ^{p^{\\ptcl1}}\n    a_{k^{\\hole1}l^{\\hole2}}\n     ^{c^{\\ptcl2}d^{\\ptcl3}}\n  }\n+\n  \\op{P}^{(i/j|c/d)}\n        _{(k/l)}\n  \\gno{\n    a_{a^{\\ptcl1}b^{\\ptcl2}}\n     ^{i^{\\hole1}j^{\\hole3}}\n    a_{q^{\\hole1}}\n     ^{p^{\\hole2}}\n    a_{k^{\\hole2}l^{\\hole3}}\n     ^{c^{\\ptcl1}d^{\\ptcl2}}\n  }\n\\\\=&\n  \\op{P}^{(c/d)}\n        _{(a/b|k/l)}\n  \\h_a^p\\h_q^c\\h_b^d\\g_k^i\\g_l^j\n-\n  \\op{P}^{(i/j|c/d)}\n        _{(k/l)}\n  \\g_q^i\\g_k^p\\g_l^j\\h_a^c\\h_b^d\n\\\\\n  \\ip{\\F|\\tl{a}_{ab}^{ij}\\tl{a}_{rs}^{pq}\\tl{a}_{kl}^{cd}|\\F}\n=&\n  \\op{P}^{(c/d)}\n        _{(a/b|k/l)}\n  \\gno{\n    a_{a^{\\ptcl1}b^{\\ptcl2}}\n     ^{i^{\\hole1}j^{\\hole2}}\n    a_{r^{\\ptcl3}s^{\\ptcl4}}\n     ^{p^{\\ptcl1}q^{\\ptcl2}}\n    a_{k^{\\hole1}l^{\\hole2}}\n     ^{c^{\\ptcl3}d^{\\ptcl4}}\n  }\n+\n  \\op{P}^{(i/j|c/d)}\n        _{(k/l)}\n  \\gno{\n    a_{a^{\\ptcl1}b^{\\ptcl2}}\n     ^{i^{\\hole1}j^{\\hole2}}\n    a_{r^{\\hole1}s^{\\hole2}}\n     ^{p^{\\hole3}q^{\\hole4}}\n    a_{k^{\\hole3}l^{\\hole4}}\n     ^{c^{\\ptcl1}d^{\\ptcl2}}\n  }\n+\n  \\op{P}^{(p/q|i/j|c/d)}\n        _{(r/s|k/l|a/b)}\n  \\gno{\n    a_{a^{\\ptcl1}b^{\\ptcl3}}\n     ^{i^{\\hole1}j^{\\hole3}}\n    a_{r^{\\hole1}s^{\\ptcl2}}\n     ^{p^{\\hole2}q^{\\ptcl1}}\n    a_{k^{\\hole2}l^{\\hole3}}\n     ^{c^{\\ptcl2}d^{\\ptcl3}}\n  }\n\\\\=&\n  \\op{P}^{(c/d)}\n        _{(a/b|k/l)}\n  \\h_a^p\\h_b^q\\h_r^c\\h_s^d\n  \\g_k^i\\g_l^j\n+\n  \\op{P}^{(i/j|c/d)}\n        _{(k/l)}\n  \\g_r^i\\g_s^j\\g_k^p\\g_l^q\n  \\h_a^c\\h_b^d\n-\n  \\op{P}^{(p/q|i/j|c/d)}\n        _{(r/s|k/l|a/b)}\n  \\g_r^i\\g_k^p\\g_l^j\n  \\h_a^q\\h_s^c\\h_b^d\n\\end{array}$\n\\begin{align*}\n&\n  \\implies\n&&\n  E_{\\text{c}}\n=\n  \\tfr{1}{4}\n  \\ol{g}_{kl}^{cd}c_{cd}^{kl}\n&&\n  E_{\\text{c}}c_{ab}^{ij}\n=\n  \\ol{g}_{ab}^{ij}\n+\n  \\op{P}_{(a/b)}\n  f_a^c\n  c_{cb}^{ij}\n-\n  \\op{P}^{(i/j)}\n  f_k^i\n  c_{ab}^{kj}\n+\n  \\tfrac{1}{2}\n  \\ol{g}_{ab}^{cd}\n  c_{cd}^{ij}\n+\n  \\tfrac{1}{2}\n  \\ol{g}_{kl}^{ij}\n  c_{ab}^{kl}\n+\n  \\op{P}^{(i/j)}\n        _{(a/b)}\n  \\ol{g}_{ak}^{ic}\n  c_{bc}^{jk}\n\\end{align*}\n\\end{samepage}\n\\end{ex}\n\n", "meta": {"hexsha": "fbf20ff185d9682fbefe3f9dff6506e56d48464d", "size": 15966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/kutzelnigg-mukherjee.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/kutzelnigg-mukherjee.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/kutzelnigg-mukherjee.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": 26.0456769984, "max_line_length": 378, "alphanum_fraction": 0.614305399, "num_tokens": 6940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6706531152624431}}
{"text": "\\chapter{Electricity \\& Magnetism}\n\n\\section{Maxwell's Equations}\n\\begin{align}\n\t\\nabla\\cdot\\mathbf{E}&=4\\pi\\rho \\label{eq:gauss}\\\\[0.5em]\n\t\\nabla\\cdot\\mathbf{B}&=0 \\label{eq:divB0}\\\\[0.5em]\n\t\\nabla\\times\\mathbf{E}&=-\\frac{1}{c}\\frac{\\partial\\mathbf{B}}{\\partial t} \\label{eq:faraday}\\\\[0.5em]\n\t\\nabla\\times\\mathbf{B}&=\\frac{4\\pi}{c}\\mathbf{j} + \\frac{1}{c}\\frac{\\partial\\mathbf{E}}{\\partial t} \\label{eq:ampere_maxwell}\n\\end{align}\n\n\\section{Basic Properties of Maxwell's Equations}\n\\begin{itemize}\n\t\\item Eq. \\ref{eq:gauss} relates the flux of the electric field through any ``Gaussian surface'' to the total enclosed charge. By counting the field lines through the surface, we may have an idea of the total enclosed charge, or the charge distribution.\n\t\\item Eq. \\ref{eq:divB0} says that there are no magnetic monopoles. Unlike electric fields, there are no ``magnetic point charges'' to generate magnetic fields. Rather, a magnetic field must be generated by the \\textit{flow} of charge, i.e. a current. This fields are of course also generated by magnetic dipoles which may be viewed as miniature current loops. More specifically, this statement says that any magnetic field line that leaves a given volume must return to that given volume such that the net flux is zero. \n\t\\item Eq. \\ref{eq:faraday} says that a time varying magnetic field can produce an electric field. This is a statement of electromagnetic induction.\n\t\\item Eq. \\ref{eq:ampere_maxwell} says that a magnetic field can be generated both by a current and by a time-varying electric field.\n\t\\item Because $\\nabla\\cdot\\mathbf{B}=0$, we may express $\\mathbf{B}$ as the curl of some vector field $\\mathbf{A}$ such that $\\nabla\\times\\mathbf{A}=\\mathbf{B}$, where $\\mathbf{A}$ is referred to as the magnetic vector potential. Using Eq. \\ref{eq:faraday}, we find that $\\nabla\\times\\left(\\mathbf{E} + \\frac{1}{c}\\frac{\\partial}{\\partial t}\\mathbf{A}\\right) = 0$. Thus, we may express the term in the parentheses as $-\\nabla\\phi$, the gradient of a vector potential. This leads to the familiar formulation.\n\t\\begin{equation}\n\t\t\\mathbf{E} = -\\nabla\\phi - \\frac{1}{c}\\frac{\\partial }{\\partial t}\\mathbf{A}.\n\t\\end{equation}\n\\end{itemize}\n%\n\\section{Electrostatics}\n\\section{Magnetostatics}\n\\section{Boundary Value Problems}\n\\section{Waves}\n", "meta": {"hexsha": "40621787c59cdac925ce28b2f5fd22d4901cf271", "size": 2301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch_em.tex", "max_stars_repo_name": "wtbarnes/space_plasma_notes", "max_stars_repo_head_hexsha": "ad608d603b4a523ce49ff0c2af5605c3af46bac6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-28T15:37:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-28T15:37:23.000Z", "max_issues_repo_path": "chapters/ch_em.tex", "max_issues_repo_name": "wtbarnes/space_plasma_notes", "max_issues_repo_head_hexsha": "ad608d603b4a523ce49ff0c2af5605c3af46bac6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-16T07:34:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-16T07:34:46.000Z", "max_forks_repo_path": "chapters/ch_em.tex", "max_forks_repo_name": "wtbarnes/space_plasma_notes", "max_forks_repo_head_hexsha": "ad608d603b4a523ce49ff0c2af5605c3af46bac6", "max_forks_repo_licenses": ["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.2222222222, "max_line_length": 522, "alphanum_fraction": 0.7414167753, "num_tokens": 710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6705983130339132}}
{"text": "\\subsection{2016 Free-Response Questions}\r\nQuestions 1 and 2 part of the same section area are allotted 30 minutes from completion with the aid of a graphing calculator.\r\nQuestions 3 through 6 are part of the same section and area allotted 1 hour from completion without the aid of a graphing calculator.\r\n\r\n\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{|c||c|c|c|c|c|}\r\n\t\t\t\\hline\r\n\t\t\t$t$ (hours) & 0 & 1 & 3 & 6 & 8 \\\\\r\n\t\t\t\\hline\r\n\t\t\t$R(t)$ (liters / hour) & 1340 & 1190 & 950 & 740 & 700 \\\\\r\n\t\t\t\\hline\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\\end{table}\r\n\r\n\\begin{enumerate}\r\n\t\\item Water is pumped into a tank at a rate modeled by $W(t)=2000e^{-t^2/20}$ liters per hour for $0 \\leq t \\leq 8$, where $t$ is measured in hours.\r\n\tWater is removed from the tank at a rate modeled by $R(t)$ liters per hour, where $R$ is differentiable and decreasing on $0 \\leq t \\leq 8$.\r\n\tSelected values of $R(t)$ are shown in the table above.\r\n\tAt time $t=0$, there are 50000 liters of water in the tank.\r\n\t\\begin{enumerate}\r\n\t\t\\item Estimate $R^\\prime(2)$.\r\n\t\tShow the work that leads to your answer.\r\n\t\tIndicate units of measure.\r\n\t\t\\item Use a left Riemann sum with the four subintervals indicated by the table to estimate the total amount of water removed from the tank during the 8 hours.\r\n\t\tIs this an over estimate or underestimate of the total amount of water removed?\r\n\t\tGive a reason for your answer.\r\n\t\t\\item Use your answer from part (b) to find an estimate for the total amount of water in the tank, to the nearest liters, at the end of the 8 hours.\r\n\t\t\\item For $0 \\leq t \\leq 8$, is there a time $t$ when the rate at which the water is pumped into the tank is the same rate as the rate at which water is removed from the tank?\r\n\t\tExplain why or why not.\r\n\t\\end{enumerate}\r\n\r\n\t\\begin{figure}[H]\r\n\t\t\\label{2016_2}\r\n\t\t\\centering\r\n\t\t\\includegraphics{./additional_materials/2016_2.png}\r\n\t\t\\caption{\\hyperref{https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap16\\_frq\\_calculus\\_bc.pdf}{}{}{AP Calculus BC 2016 Exam Free-Response Question 2}}\r\n\t\\end{figure}\r\n\t\r\n\t\\item At time $t$, the position of a particle moving in the $xy$-plane is given by the parametric functions $(x(t),y(t))$, where $\\dd{x}{t} = t^2 + \\sin{(3t^2)}$.\r\n\t\tThe graph of $y$ consisting of three line segments, is shown in the figure above.\r\n\t\tAt $t=0$, the particle is at position $(5,1)$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find the position of the particle at $t=3$.\r\n\t\t\t\\item Find the slope of the line tangent to the part of the particle at $t=3$.\r\n\t\t\t\\item Find the speed of the particle at $t=3$.\r\n\t\t\t\\item Find the total distance traveled by the particle from $t=0$ to $t=2$.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{2016_3}\r\n\t\t\\centering\r\n\t\t\\includegraphics{./additional_materials/2016_3.png}\r\n\t\t\\caption{\\hyperref{https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap16\\_frq\\_calculus\\_bc.pdf}{}{}{AP Calculus BC 2016 Exam Free-Response Question 3, Graph of $f$}}\r\n\t\\end{figure}\r\n\t\r\n\t\\item The figure above shows the graph of the piecewise-linear function $f$.\r\n\t\tFor $-4 \\leq x \\leq 12$, the function $g$ is defined by $g(x)=\\int_{2}^{x}{f(t)\\d{t}}$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Does $g$ have a relative minimum, a relative maximum, or neither at $x=10$?\r\n\t\t\t\tJustify your answer.\r\n\t\t\t\\item Does the graph of $g$ have a point of inflection at $x=4$?\r\n\t\t\t\tJustify your answer.\r\n\t\t\t\\item Find the absolute minimum value and the absolute maximum value of $g$ on the interval $-4 \\leq x \\leq 12$.\r\n\t\t\t\tJustify your answers.\r\n\t\t\t\\item For $-4 \\leq x \\leq 12$, find all intervals for which $g(x) \\leq 0$.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\item Consider the differential equation $\\dd{y}{x} = x^2 - \\frac{1}{2}y$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find $\\dd{^2y}{x^2}$ in terms of $x$ and $y$.\r\n\t\t\t\\item Let $y=f(x)$ be the particular solution to the given differential equation whose graph passes through the point $(-2,8)$.\r\n\t\t\t\tDoes the graph of $f$ have a relative minimum, a relative maximum, or neither at the point $(-2,8)$?\r\n\t\t\t\tJustify your answer.\r\n\t\t\t\\item Let $y=g(x)$ be the particular solution to the given differential equation with $g(-1)=2$.\r\n\t\t\t\tFind $\\lim_{x\\to -1}{\\left(\\frac{g(x)-2}{3(x+1)^2}\\right)}$.\r\n\t\t\t\tShow the work that leads to your answer.\r\n\t\t\t\\item Let $y=h(x)$ be the particular solution to the given differential equation with $h(0)=2$.\r\n\t\t\t\tUse Euler's method, starting at $x=0$ with two steps of equal size, to approximate $h(1)$.\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{2016_5}\r\n\t\t\\centering\r\n\t\t\\includegraphics{./additional_materials/2016_5.png}\r\n\t\t\\caption{\\hyperref{https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap16\\_frq\\_calculus\\_bc.pdf}{}{}{AP Calculus BC 2016 Exam Free-Response Question 5}}\r\n\t\\end{figure}\r\n\t\r\n\t\\item The inside of a funnel of height 10 inches has circular cross sections, as shown in the figure above.\r\n\t\tAt height $h$, the radius of the funnel is given by $r = \\frac{1}{20}\\left(3+h^2\\right)$, where $0 \\leq h \\leq 10$.\r\n\t\tThe units of $r$ and $h$ are inches.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Find the average value of the radius of the funnel.\r\n\t\t\t\\item Find the volume of the funnel.\r\n\t\t\t\\item The funnel contains liquid that is draining from the bottom.\r\n\t\t\t\tAt the instant when the height of the liquid is $h=3$ inches, the radius of the surface of the liquid is decreasing at a rate of $\\frac{1}{5}$ inch per second.\r\n\t\t\t\tAt this instant, what is the rate of change of the height of the liquid with respect to time?\r\n\t\t\\end{enumerate}\r\n\t\r\n\t\\item The function $f$ has a Taylor series about $x=1$ that converges to $f(x)$ for all $x$ in the interval of convergence.\r\n\t\tIt is known that $f(1)=1$, $f^\\prime(1)=-\\frac{1}{2}$, and the $n$th derivative of $f$ at $x=1$ is given by $f^{(n)}(1) = (-1)^{n}\\frac{(n-1)!}{2^n}$ for $n \\geq 2$.\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item Write the first four nonzero terms and the general term of the Taylor series for $f$ about $x=1$.\r\n\t\t\t\\item The Taylor series for $f$ about $x=1$ has a radius of convergence of 2.\r\n\t\t\t\tFind the interval of convergence.\r\n\t\t\t\tShow the work that leads to your answer.\r\n\t\t\t\\item The Taylor series for $f$ about $x=1$ can be used to represent $f(1.2)$ as an alternating series.\r\n\t\t\t\tUse the first three non-zero terms of the alternating series to approximate $f(1.2)$.\r\n\t\t\t\\item Show that the approximation found in part (c) is within 0.001 of the exact value of $f(1.2)$.\r\n\t\t\\end{enumerate}\r\n\\end{enumerate}", "meta": {"hexsha": "93cc9da46c6525a868402537096cfb011085e2ac", "size": 6450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/additional_materials/2016_questions.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/2016_questions.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/2016_questions.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.5892857143, "max_line_length": 181, "alphanum_fraction": 0.6852713178, "num_tokens": 2041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.6705982940556059}}
{"text": "% !TeX root = ./main.tex\n% chktex-file 46\n% !TeX spellcheck = en-GB\n% !TeX encoding = utf8\n\n% - re-model current strategies: doing nothing, social distancing, isolation.\n\nIn the following we will present two extensions to the above methods.\nFirst we demonstrate a baysian approach to estimate the populations' health state.\nSecond we show how the above methods could be utilized to derive disease containment policies.\n\n\\subsection{Baysian way of estimating the Probabilities}\n\nA major drawback of our analysis is that we only take fixed disease states of individuals into account, i.e either susceptible, infected or recovered. However, in real live, due to the lack of data, these states are mostly unknown and have to be estimated by probability distributions. If we model these probabilities based on detailed assumptions, we can use Bayes' posterior probability to update these distributions based on the individual interaction of people. Thus, we define $X$ as the random variable that represents the state of a single individual. It can be assumed, that $X$ is well approximated by the multinomial distribution ($n\\gg1$):\n\\begin{equation}\n    X = \\left(X_{S}, X_{I}, X_{R}\\right) \\sim \\text{Mn}(n;p_S^{(t)},p_I^{(t)},p_R^{(t)})\n\\end{equation}\nwhere $n$ is the population size, and $p_S^{(t)}$, $p_I^{(t)}$, and $p_R^{(t)}$ are the probability for an individual to be either in susceptible, an infected or recovered state. These probabilities change over time as the disease progresses, while\n\n\\begin{equation}\n    p_S^{(t)}+p_I^{(t)}+p_R^{(t)}=1.\n\\end{equation}\n\nAs we can only estimate the probabilities $p_S^{(t)}$, $p_I^{(t)}$, and $p_R^{(t)}$ from samples of our population with a certain error, we assume that the probabilities are realisations of a prior distribution, in this case the Dirichlet distribution:\n\n\\begin{equation}\n    \\left(p_{S,i}^{(t)}, p_{I,i}^{(t)}, p_{R,i}^{(t)}\\right) \\sim \\operatorname{Dir}\\left(\\alpha_{S,i}^{(t)}, \\alpha_{I,i}^{(t)}, \\alpha_{R,i}^{(t)}\\right).\n\\end{equation}\n\nThe pseudo-counts $\\alpha_{1,i}^{(0)}$, $\\alpha_{2,i}^{(0)}$, and $\\alpha_{3,i}^{(0)}$ can be estimated from $p_S^{(0)}$, $p_I^{(0)}$, and $p_R^{(0)}$ and are equal for each individual $i$ at $t=0$. Because we have no additional prior information, we also choose $\\sum_{i\\in\\{S,I,R\\}}\\alpha_i = 1$.\n\nIf we now assume that two individuals with unknown state meet at the same location, an interaction occurs and we cannot neglect, that at least one of the individuals may carry the disease and may potentially infect the other. Therefore, we assume, that each individual is present in an infectious superstate $\\braket{x}$ where\n\\begin{equation}\n    \\braket{x} = \\left(\\braket{x_{S,i}}, \\braket{x_{I,i}}, \\braket{x_{R,i}}\\right) = \\left(p_S^{(t)},p_I^{(t)},p_R^{(t)}\\right)\n\\end{equation}\nIf the state of an individual in this group known, due to a previous test for example, the state collapses into the right state (e.g $(0,1,0)$ for an infected individual).\n\nBased on this either known or super positional state, we can define the graph based Bayesian update rule of the pseudo-counts, where the infection rate $\\beta$ is also taken into account, as followed~\\cite{rice2006mathematical}:\n\n\\begin{align}\n    \\alpha_{S,i}^{(t+1)\\prime} &= \\alpha_{1,i}^{(t)\\prime}\\\\\n    \\alpha_{I,i}^{(t+1)\\prime} &= \\alpha_{2,i}^{(t)\\prime} + \\beta \\cdot\n    \\sum_{j\\in A^{(t)}_{v_i}} A^{(t)}_{i,j} x_{I,j}\\\\\n    \\alpha_{R,i}^{(t+1)\\prime} &= \\alpha_{3,i}^{(t)\\prime}\\\\\n    \\alpha_{0,i}^{(t+1)\\prime} &= \\alpha_{S,i}^{(t+1)\\prime}+\\alpha_{I,i}^{(t+1)\\prime}+\\alpha_{R,i}^{(t+1)\\prime}\n\\end{align}\n\nImportant to notice is that the adjacent $A$ has to be normalized to $\\operatorname{max}(A)=1$, where $A_{v_i,v_j}=1$ means a direct contact between individual $v_i$ and individual $v_j$.\nIn this step, the update is only done for the $\\alpha_I$, as only the possible infection of an individual can change the infection state of another individual.\n\nHowever, so far this model still does not take the potential recovery into account. We can add this by looking at the estimated Values of $p_{S,i}^{(t+1)}$, $p_{I,i}^{(t+1)}$, and $p_{R,i}^{(t+1)}$ \n\\begin{alignat}{2}\n    \\operatorname{E}[p_{S,i}^{(t+1)}] &= \\frac{\\alpha_{S,i}^{(t+1)\\prime}}{\\alpha_{0,i}^{(t+1)\\prime}} & &= \\frac{\\alpha_{S,i}^{(t+1)}}{\\alpha_{0,i}^{(t+1)\\prime}} \\\\\n    \\operatorname{E}[p_{I,i}^{(t+1)}]&= \\frac{\\alpha_{I,i}^{(t+1)\\prime}}{\\alpha_{0,i}^{(t+1)\\prime}}-\\gamma & &=\\frac{\\alpha_{I,i}^{(t+1)}}{\\alpha_{0,i}^{(t+1)}} \\\\\n    \\operatorname{E}[p_{R,i}^{(t+1)}]&= \\frac{\\alpha_{R,i}^{(t+1)\\prime}}{\\alpha_{0,i}^{(t+1)\\prime}}+\\gamma & &= \\frac{\\alpha_{R,i}^{(t+1)}}{\\alpha_{0,i}^{(t+1)}}\n\\end{alignat}\n\nBased on this equation system, we can calculate $\\alpha_{k,i}^{(t+1)}$ for $k\\in{S,I,R}$. Needless to say, that if the expectation value of $p_{I,i}^{(t+1)}$ or $p_{R,i}^{(t+1)}$ return a value smaller than 0 or larger than 1, we set $\\gamma=0$ and therefore $\\alpha_{k,i}^{(t+1)\\prime}=\\alpha_{k,i}^{(t+1)}$. Something similar may be found in~\\cite{stojanovic2019bayesian}.\n\nWe see here, that the probability for an individual to be in the susceptible state shrinks over time, the more contacts with people have been observed. Thus, if we set this individual into quarantine, the probabilities shift towards either the susceptible state or the recovered state. This is an early indicator, why it is necessary to put the whole population under quarantine in the case of a pandemic.\n\nWe can now find an optimal test setup by applying tests to those individuals, who's unknown infection state introduce the most uncertainty to our estimation. Furthermore, we could even set individuals with a high probability to have the disease under quarantine, without testing them (which should be an urgent object of an ethical discussion).\n\n\n\n\\subsection{Policy Design}\nIn the previous sections we have shown how predict the health state of all individuals in a location tracked population.\nThe next step is to use this information to compute optimal policies.\nThese policies guide a governments' and societies' response to the spread of COVID-19 and modify how the disease is able to spread in a population.\n\nAn optimal policy always keeps the infection counts below the medical systems' capacity and the total number of infections as small as possible.\n% not much real data on this.\nMathematically speaking we want to minimize the sum of all future infections\n\\begin{equation}\\label{eq:number-of-infected}\n\t\\min \\sum_{\\forall t} N^{(t)}_i\n\\end{equation}\nwhilst\n\\begin{equation}\\label{eq:cap-constraint}\n\tN^{(l)}_i \\leq N_{limit}, \\forall t\n\\end{equation}\n\nA policy may consist out of two different kinds of actions, non pharmaceutical interventions (NPI) and test prioritization (TP).\n\n\n\\subsubsection{Non Pharmaceutical Interventions (NPI)}\nAll non pharmaceutical interventions can be understood as some kind of edge removal in our graph-based approach:\n\\begin{itemize}\n\t\\item Isolation of an infected individual removes all of its edges with very high probability.\n\t\\item Quarantine of a contact person removes all of its edges with high probability.\n\t\\item Social distancing removes some edges of many individuals.\n\t\\item Cancellation of large events remove many edges of many individuals.\n\\end{itemize}\n\nFormally speaking, the square matrix $C \\in \\mathbb{B}$ with dimensions $N \\times N$ models desirable edge cancellations.\nThis is the policy, which will be optimized.\nTo avoid the trivial solution of $C=0$, the cancellation of all edges, we also want to minimize the the number of cancellations\n\\begin{equation}\\label{eq:cancellations}\n\t\\min_{C} -\\sum_i \\sum_j C_{ij}\n\\end{equation}\n\nNote, that this matrix does not have to know the edges of a future time step, it only expresses which edges must not exist.\nIt is multiplied element-wise onto the adjacency matrix $A$ to obtain the adjacency matrix with applied cancellations $\\bar{A} = A \\odot C$.\n\n% Future Work: This would be more powerful, if there would be some different kinds of edges (social, work, education, large events, etc.)\\\\\n% Future Work: This only takes the current time step into account but it would be desirable to look even further into the future.\n\nTo obtain an optimal cancellation policy one thus must jointly minimize \\cref{eq:number-of-infected,eq:cancellations} whilst fulfilling \\cref{eq:cap-constraint}.\n\n\\subsubsection{Test Prioritization (TP)}\nWhen tests are limited, we argue that they should be used to discover as much as possible about the health state of the overall population.\nThis in turn allows non pharmaceutical interventions such as school cancellations to become more efficient.\nCurrently there are only rough medical-based guidelines who should be tested and who should not.\n\nLets assume there are $t_{\\text{max}}$ tests per time step.\nA test reveals the true health state of an individual (ignoring false negatives and false positives)\n\\begin{equation}\nh_{{v}_i}^{(t)} \\xrightarrow{\\text{test}} h_{{v}_i}^{(t+1)} \\in \\{\\vec{e}_0, \\vec{e}_1, \\vec{e}_2 \\}\n\\end{equation}\n\nThe test assignment $T$ with dimension $N$ is a binary variable describing which individuals should be tested.", "meta": {"hexsha": "f5ba137856b83619dd0b400c9956c90822ba9f30", "size": 9148, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sections/outlook.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/sections/outlook.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/sections/outlook.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": 76.2333333333, "max_line_length": 650, "alphanum_fraction": 0.7286838653, "num_tokens": 2565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.67059828362524}}
{"text": "\\chapter{Speech Recognition Features}\n\n\\section{Mel Spectral Features}\n\\label{sec:mel-spectral-features}\n\nMel spectral features are generally formed using a filterbank\nwhose center frequencies increase exponential and whose \nbandwidths are increasing along the frequency axis.  They are\ncentered such that they are linear with the mel scale given\nby the equation\n\\begin{equation}\nmel(f) = 2595 \\log_{10}\\left(1 + \\frac{f}{700}\\right)\n\\end{equation}\nwhich is given in \\cite{wiki:mel_scale}.\n", "meta": {"hexsha": "e06b4e15eafff2563ae642de01e75005038d7119", "size": 490, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch3_speech_features.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/ch3_speech_features.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/ch3_speech_features.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": 32.6666666667, "max_line_length": 61, "alphanum_fraction": 0.7897959184, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6705904283658759}}
{"text": "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%                          Thesis Appendix B                          %\n%                       Manifolds Descriptions                        %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Manifolds Descriptions}\n\\label{appendix:manifolds}\n\n\\graphicspath{{Appendix2-Manifolds/Figs/}}\n\nThis appendix chapter comes as a complement for Chapter~\\ref{chapter:optimization_on_noneuclidean_manifolds} in which we explicit the elements necessary for the description of several elementary manifolds.\n\n%{{{ THE REAL SPACE MANIFOLD $\\MATHBB{R^N$}\n\\section{The Real Space manifold}\n\\label{sec:the_real_space}\nThe Realspace manifold of dimension $n$ is denoted $\\mathbb{R}^n$.\nSince $\\mathbb{R}^n$ is a Euclidean manifold, the operations that we use on it are straightforward.\n\n\\begin{table} [H]\n\\caption{Description of the $\\mathbb{R}^n$ manifold}\n\\centering\n\\begin{tabular}{cc}\n  \\toprule\n  $\\mathcal{M}$ & $\\mathbb{R}^n$ \\\\\n  \\midrule\n  $\\mathbb{E}$ & $\\mathbb{R}^n$ \\\\\n  \\midrule\n  $T_x\\mathcal{M}$ & $\\mathbb{R}^n$ \\\\\n  \\midrule\n  $T_x\\mathbb{E}$ & $\\mathbb{R}^n$ \\\\\n  \\midrule\n  $\\phi_x(\\mathbf{z})$ & $\\mathbf{x} + \\mathbf{z}$ \\\\\n  \\midrule\n  $\\partial \\phi_x(0)$ & $\\mathbf{1}_n$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\quad\n\\begin{tabular}{cc}\n  \\toprule\n  $\\zeta(x,y)$ & $\\mathbf{y} - \\mathbf{x}$ \\\\\n  \\midrule\n  $\\frac{\\partial \\zeta_x}{\\partial y}(x)$ & $\\mathbf{1}_n$ \\\\\n  \\midrule\n  $\\mathcal{T}(x,\\mathbf{z}, \\mathbf{v})$ & $\\mathbf{v}$ \\\\\n  \\midrule\n  $\\pi_\\mathcal{M}(\\mathbf{x})$ & $\\mathbf{x}$ \\\\\n  \\midrule\n  $\\pi_{T_x\\mathcal{M}}(\\mathbf{z})$ & $\\mathbf{z}$ \\\\\n  \\midrule\n  $\\lim$ & $\\|\\mathbf{v}\\| \\leq \\infty$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{table}\n%}}}\n%{{{ THE 3D ROTATION MANIFOLD SO(3): MATRIX REPRESENTATION\n\\section{The 3D Rotation manifold: Matrix representation}\n\\label{sec:the_3d_rotation_manifold_matrix_representation}\n\nThe 3D rotation manifold is denoted $SO(3)$.\n\nAn element $x$ of $SO(3)$ is represented by $\\mathbf{x}=\\psi(x)$ in $\\mathbb{R}^{3\\times 3}$ by:\n\\begin{equation}\n  x\\in SO(3),\\ \\mathbf{x} =\\begin{bmatrix}\n    x_{00} & x_{01} & x_{02} \\\\\n    x_{10} & x_{11} & x_{12} \\\\\n    x_{20} & x_{21} & x_{22} \\\\\n  \\end{bmatrix}\n\\end{equation}\n\nWe recall the operators\n\\begin{equation}\n\\widehat{.}: \\begin{bmatrix}\n  \\omega_0\\\\\\omega_1\\\\\\omega_2\\\\\n\\end{bmatrix}\n\\rightarrow\n\\begin{bmatrix}\n  0 & -\\omega_2 & \\omega_1 \\\\\n  \\omega_2 & 0 & -\\omega_0 \\\\\n  -\\omega_1 & \\omega_0 & 0\\\\\n\\end{bmatrix}\n\\end{equation}\nAnd its inverse:\n\\begin{equation}\n\\widecheck{.}: \\begin{bmatrix}\n    x_{00} & x_{01} & x_{02} \\\\\n    x_{10} & x_{11} & x_{12} \\\\\n    x_{20} & x_{21} & x_{22} \\\\\n\\end{bmatrix}\n\\rightarrow\n\\begin{bmatrix}\n  x_{21}\\\\x_{02}\\\\x_{10}\\\\\n\\end{bmatrix}\n\\end{equation}\n\n\nThe exponential map is known as the Rodrigues formula:\n\\begin{equation}\n  \\forall \\mathbf{v}\\in\\mathbb{R}^3,\\ \\exp(\\mathbf{v}) = \\mathbf{1}_3 +\n  \\frac{\\sin \\|\\mathbf{v}\\|}{\\|\\mathbf{v}\\|} \\hat{\\mathbf{v}} +\n  \\frac{1-\\cos \\|\\mathbf{v}\\|}{\\|\\mathbf{v}\\|^2} \\hat{\\mathbf{v}}^2\n\\end{equation}\n\nNote that when $\\|\\mathbf{v}\\|$ is small, we make the following replacements to avoid numerical instability.\nIt is important to ensure the precision of the retractation near zero because, in an optimization process, many small steps are taken, especially when close to the solution.\n\n\\begin{align}\n \\frac{\\sin \\|\\mathbf{v}\\|}{\\|\\mathbf{v}\\|} & = 1-\\frac{\\|\\mathbf{v}\\|}{6}\\\\\n \\frac{1-\\cos \\|\\mathbf{v}\\|}{\\|\\mathbf{v}\\|^2} & = 0.5 - \\frac{\\|\\mathbf{v}\\|}{24}\n\\end{align}\n\nAnd the logarithm is computed as follows (see~\\cite{merlhiot:thesis:2009}):\n\\begin{align}\n\\begin{split}\n  \\forall R\\in\\psi(SO(3)),\\ f(R) &=\n  \\left\\{ \\begin{matrix}\n  0 & \\text{if }Tr(R) = 3 \\\\\n  \\frac{\\arccos\\left(\\frac{Tr(R)-1}{2}\\right)}{2\\sin\\left(\\arccos\\left(\\frac{Tr(R)-1}{2}\\right)\\right)}\\left(R-R^T\\right) & \\text{otherwise} \\\\\n  \\end{matrix} \\right.\\\\\n  \\log(R) &= \\widecheck{f\\left(R\\right)}\n\\end{split}\n\\end{align}\n\nWe consider a point $x\\in\\mathcal{M}$ and its representation matrix with the following storing order:\n\\begin{equation}\n\\mathbf{x}=\\psi(x)\n= \\begin{pmatrix}\n  x_0 & x_3 & x_6 \\\\\n  x_1 & x_4 & x_7 \\\\\n  x_2 & x_5 & x_8 \\\\\n\\end{pmatrix}\n= \\begin{pmatrix}\n  x_{00} & x_{01} & x_{02} \\\\\n  x_{10} & x_{11} & x_{12} \\\\\n  x_{20} & x_{21} & x_{22} \\\\\n\\end{pmatrix}\n\\end{equation}\n\nThe derivative of retractation operation writes as:\n\n\\begin{align}\n\\label{eq:diffRetrSO3Matrix}\n  \\frac{\\partial \\varphi_x}{\\partial \\mathbf{z}}(0) =\n  \\begin{bmatrix}\n    0 & -x_6 & x_3 \\\\\n    0 & -x_7 & x_4 \\\\\n    0 & -x_8 & x_5 \\\\\n    x_6 & 0 & -x_0 \\\\\n    x_7 & 0 & -x_1 \\\\\n    x_8 & 0 & -x_2 \\\\\n    -x_3 & x_0 & 0 \\\\\n    -x_4 & x_1 & 0 \\\\\n    -x_5 & x_2 & 0 \\\\\n  \\end{bmatrix}\n\\end{align}\n\nAnd the derivation of the logarithm operation writes as:\n\n\\begin{align}\n\\label{eq:diffLogSO3Matrix}\n  \\mathbf{v} &= \\begin{pmatrix}\n    \\frac{x_{21} - x_{12}}{2}\\\\\n    \\frac{x_{02} - x_{20}}{2}\\\\\n    \\frac{x_{10} - x_{01}}{2}\\\\\n  \\end{pmatrix} \\\\\n  f &= \\frac{\\arccos \\left( \\frac{Tr(\\mathbf{x})-1}{2} \\right)}{2 \\sin \\left( \\arccos \\left( \\frac{Tr(\\mathbf{x})-1}{2} \\right) \\right) } \\\\\n  df &= \\frac{\\left(Tr(\\mathbf{x})-1\\right)f-1}{2 \\left( 1- {\\left( \\frac{Tr(\\mathbf{x})-1}{2} \\right)}^2 \\right)} \\\\\n  \\frac{\\partial \\zeta_x}{\\partial y}(x) &= \\begin{bmatrix}\n      & 0 & 0 & 0 &  & f & 0 & -f &  \\\\\n    df.\\mathbf{v} & 0 & -f & 0 & df.\\mathbf{v} & 0 & f & 0 & df.\\mathbf{v}  \\\\\n      & f & 0 & -f &  & 0 & 0 & 0 &  \\\\\n  \\end{bmatrix}\n\\end{align}\n\n\\begin{table} [H]\n\\caption{Description of the $SO(3)$ manifold with matrix representation}\n\\centering\n\\begin{tabular}{cc}\n  \\toprule\n  $\\mathcal{M}$ & $SO(3)$ \\\\\n  \\midrule\n  $\\mathbb{E}$ & $\\mathbb{R}^{3\\times 3}$ \\\\\n  \\midrule\n  $T_x\\mathcal{M}$ & $\\mathbb{R}^3$ \\\\\n  \\midrule\n  $T_x\\mathbb{E}$ & $\\mathbb{R}^3$ \\\\\n  \\midrule\n  $\\psi(x) = \\mathbf{x}$ & $ \\begin{bmatrix}\n    x_{00} & x_{01} & x_{02} \\\\\n    x_{10} & x_{11} & x_{12} \\\\\n    x_{20} & x_{21} & x_{22} \\\\\n  \\end{bmatrix} $ \\\\\n  \\midrule\n  $\\phi_x(\\mathbf{z})$ & $\\mathbf{x}\\exp(\\mathbf{z})$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\quad\n\\begin{tabular}{cc}\n  \\toprule\n  $\\partial \\phi_x(0)$ & see Equation~\\ref{eq:diffRetrSO3Matrix} \\\\\n  \\midrule\n  $\\zeta(x,y)$ & $\\log(\\mathbf{x}^T\\mathbf{y})$ \\\\\n  \\midrule\n  $\\frac{\\partial \\zeta_x}{\\partial y}(x)$ & see Equation~\\ref{eq:diffLogSO3Matrix} \\\\\n  \\midrule\n  $\\mathcal{T}(x,\\mathbf{z}, \\mathbf{v})$ & $\\mathbf{v}$ \\\\\n  \\midrule\n  $\\pi_\\mathcal{M}(\\mathbf{x})$ & Q from QR decomposition of $\\mathbf{x}$ \\\\\n  \\midrule\n  $\\pi_{T_x\\mathcal{M}}(\\mathbf{z})$ & $\\mathbf{z}$ \\\\\n  \\midrule\n  $\\lim$ & $\\|\\mathbf{v}\\| \\leq \\pi$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{table}\n\n%}}}\n\n%{{{ THE 3D ROTATION MANIFOLD SO3 QUATERNION REPRESENTATION\n\\section{The 3D Rotation manifold with quaternion representation}\n\\label{sec:the_3d_rotation_manifold_quaternion_representation}\n\nThe 3D rotation manifold is denoted $SO(3)$.\n\nAn element $x$ of $SO(3)$ is represented by $\\mathbf{q}=\\psi(x)$ in $\\mathbb{R}^{4}$ by:\n\\begin{equation}\n  x\\in SO(3),\\ \\mathbf{q} =\\begin{bmatrix}\n    q_{w}\\\\\n    q_{x}\\\\\n    q_{y}\\\\\n    q_{z}\\\\\n  \\end{bmatrix}\n  =\\begin{bmatrix}\n    q_{w}\\\\\n    \\mathbf{q_{vec}}\\\\\n  \\end{bmatrix}\n\\end{equation}\n\nThe exponential map is:\n\\begin{equation}\n  \\exp\\ :\\left|\n  \\begin{array}{ccc}\n    \\mathbb{R}^3 & \\rightarrow & \\mathbb{R}^4 \\\\\n    \\mathbf{z} & \\mapsto & \\begin{bmatrix}\n      \\cos \\left( \\frac{\\|\\mathbf{z}\\|}{2} \\right)\\\\\n      \\sin \\left( \\frac{\\|\\mathbf{z}\\|}{2} \\right) \\frac{\\mathbf{z}}{\\|\\mathbf{z}\\|}\\\\\n    \\end{bmatrix} \\\\\n  \\end{array} \\nonumber%\n  \\right.\n\\end{equation}\n\nNote that when $\\|\\mathbf{v}\\|$ is small, we make the following replacements to avoid numerical instability.\n\n\\begin{equation}\n  \\exp(\\mathbf{z}) = \\begin{bmatrix}\n    1 -\\frac{\\|\\mathbf{z}\\|}{8} + \\frac{{\\|\\mathbf{z}\\|}^2}{384}\\\\\n    \\left(0.5 - \\frac{\\|\\mathbf{z}\\|}{48} + \\frac{{\\|\\mathbf{z}\\|}^2}{3840}\\right)\\mathbf{z}\n  \\end{bmatrix}\n\\end{equation}\n\nAnd the logarithm is:\n\\begin{equation}\n  \\log\\ :\\left|\n  \\begin{array}{ccc}\n    \\mathbb{R}^4 & \\rightarrow & \\mathbb{R}^3 \\\\\n    q & \\mapsto & \\arctan \\left( \\frac{2 \\|\\mathbf{q_{vec}}\\| q_w}{q_w^2 - {\\|\\mathbf{q_{vec}\\|}^2}} \\right) \\frac{\\mathbf{q_{vec} } }{\\|\\mathbf{q_{vec}}\\|} \\\\\n  \\end{array}\n  \\right.\n\\end{equation}\n\nWe consider a point $q\\in\\mathcal{M}$ and its representation quaternion with the following storing order:\n\\begin{equation}\n\\mathbf{q}=\\psi(q)\n= \\begin{pmatrix}\n  q_w \\\\\n  q_x \\\\\n  q_y \\\\\n  q_z \\\\\n\\end{pmatrix}\n\\end{equation}\n\nThe derivative of retractation operation writes as:\n\n\\begin{align}\n\\label{eq:diffRetrSO3Quat}\n  \\frac{\\partial \\varphi_q}{\\partial \\mathbf{z}}(0) = \\frac{1}{2}\n  \\begin{bmatrix}\n    -q_x & -q_y & -q_z \\\\\n     q_w & -q_z &  q_y \\\\\n     q_z &  q_w & -q_x \\\\\n    -q_y &  q_x &  q_w \\\\\n  \\end{bmatrix}\n\\end{align}\n\nAnd the derivation of the logarithm operation writes as:\n\n\\begin{align}\n\\label{eq:diffLogSO3Quat}\n  f &= \\frac{\\arctan \\left( \\frac{2 \\|\\mathbf{q_{vec}}\\| q_w}{q_w^2 - {\\|\\mathbf{q_{vec}}\\|}^2} \\right)}{n}\\\\\n  g &= \\frac{2 q_w - f}{{\\|\\mathbf{q_{vec}}\\|}^2} \\\\\n  \\frac{\\partial \\zeta_x}{\\partial y}(\\mathbf{x}) &= \\begin{bmatrix}\n  \\begin{pmatrix}\n    \\\\\n    -2\\mathbf{q_{vec}}\\\\\n    \\\\\n  \\end{pmatrix} &\n  \\begin{pmatrix}\n    \\\\\n    f\\mathbf{1}_3 + g\\mathbf{q_{vec}}\\mathbf{q_{vec}}^T\\\\\n    \\\\\n  \\end{pmatrix}\n  \\end{bmatrix}\n\\end{align}\n\n\n\\begin{table} [H]\n\\caption{Description of the $\\mathbf{SO(3)}$ manifold with quaternion representation}\n\\centering\n\\begin{tabular}{cc}\n  \\toprule\n  $\\mathcal{M}$ & $SO(3)$ \\\\\n  \\midrule\n  $\\mathbb{E}$ & $\\mathbb{R}^{4}$ \\\\\n  \\midrule\n  $T_x\\mathcal{M}$ & $\\mathbb{R}^3$ \\\\\n  \\midrule\n  $T_x\\mathbb{E}$ & $\\mathbb{R}^3$ \\\\\n  \\midrule\n  $\\phi_x(\\mathbf{z})$ & $\\mathbf{x}\\exp(\\mathbf{z})$ \\\\\n  \\midrule\n  $\\partial \\phi_x(0)$ & see Appendix~\\ref{eq:diffRetrSO3Quat} \\\\\n  \\bottomrule\n\\end{tabular}\n\\quad\n\\begin{tabular}{cc}\n  \\toprule\n  $\\zeta(x,y)$ & $\\log(\\mathbf{x}^{-1}\\mathbf{y})$ \\\\\n  \\midrule\n  $\\frac{\\partial \\zeta_x}{\\partial y}(x)$ & see Appendix~\\ref{eq:diffLogSO3Quat} \\\\\n  \\midrule\n  $\\mathcal{T}(x,\\mathbf{z}, \\mathbf{v})$ & $\\mathbf{v}$ \\\\\n  \\midrule\n  $\\pi_\\mathcal{M}(\\mathbf{x})$ & $\\frac{\\mathbf{x}}{\\|\\mathbf{x}\\|}$ \\\\\n  \\midrule\n  $\\pi_{T_x\\mathcal{M}}(\\mathbf{z})$ & $\\mathbf{z}$ \\\\\n  \\midrule\n  $\\lim$ & $\\|\\mathbf{v}\\| \\leq \\pi$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{table}\n\n%}}}\n\n\n%{{{ THE UNIT SPHERE MANIFOLD $S^2$\n\\section{The Unit Sphere manifold}\n\\label{sec:the_unit_sphere_manifold_s2}\n\nAn element $x$ of $S^2$ is represented by $\\mathbf{x}=\\psi(x)$ in $\\mathbb{R}^{3}$ by:\n\\begin{equation}\n  x\\in S^2,\\ \\mathbf{x} =\\begin{bmatrix}\n    x_0\\\\\n    x_1\\\\\n    x_2\\\\\n  \\end{bmatrix}\n\\end{equation}\n\nWith this manifold, the tangent space at $x$ is the tangent plane to the unit-sphere at $x$.\nThus, $T_x\\mathcal{M}$ it is a 2-dimensional space, and its representation space is $\\mathbb{R}^3$.\n%A tangent vector to $x$, $\\mathbf{z}$, is such that $\\mathbf{x}\\cdot \\mathbf{z} = \\mathbf{x}^T\\mathbf{z}=0$.\n\nFor the retractation we simply use a normalized sum:\n\\begin{equation}\n  \\phi_x(\\mathbf{z}) = \\frac{\\mathbf{x}+\\mathbf{z}}{\\|\\mathbf{x}+\\mathbf{z}\\|}\n\\end{equation}\n\nWe define a distance operation on $S^2$ as:\n\\begin{equation}\n  \\dist(x, y) = 1-\\mathbf{x}\\cdot \\mathbf{y}\n\\end{equation}\n\nAnd the projection on the tangent space:\n\\begin{equation}\n  \\pi_{T_x\\mathcal{M}}(\\mathbf{z}) = \\mathbf{z} - (\\mathbf{x} \\cdot \\mathbf{z}) \\mathbf{x}\n\\end{equation}\n\nThe pseudo-logarithm operation is the following:\n\\begin{equation}\n  \\zeta_x(y) = \\dist(x,y)\\frac{\\pi_{T_x\\mathcal{M}}(\\mathbf{z})}{\\|\\pi_{T_x\\mathcal{M}}(\\mathbf{z})\\|}\n\\end{equation}\n\nThe vector transport operation of vector $\\mathbf{v}$ from $T_x\\mathcal{M}$ to $T_y\\mathcal{M}$ with $y = \\phi_x(\\mathbf{v})$, corresponds to rotating $\\mathbf{v}$ by the rotation that transforms $x$ into $y$:\n\\begin{align}\n  &\\mathbf{y} = \\phi_x(\\mathbf{z}) \\\\\n  &R = \\mathbf{1}_3 + \\widehat{\\mathbf{x} \\wedge \\mathbf{y}} + \\frac{{\\widehat{\\mathbf{x} \\wedge \\mathbf{y} } }^2}{1+\\mathbf{x}\\cdot\\mathbf{y}} \\\\\n  &\\mathcal{T}(x,\\mathbf{z}, \\mathbf{v}) = R\\mathbf{v}\n\\end{align}\n\n\\begin{table} [H]\n\\caption{Description of the $S^2$ manifold}\n\\centering\n\\begin{tabular}{cc}\n  \\toprule\n  $\\mathcal{M}$ & $S^2$ \\\\\n  \\midrule\n  $\\mathbb{E}$ & $\\mathbb{R}^{3}$ \\\\\n  \\midrule\n  $T_x\\mathcal{M}$ & $\\mathbb{R}^2$ \\\\\n  \\midrule\n  $T_x\\mathbb{E}$ & $\\mathbb{R}^3$ \\\\\n  \\midrule\n  $\\phi_x(\\mathbf{z})$ & $\\frac{\\mathbf{x}+\\mathbf{z}}{\\|\\mathbf{x}+\\mathbf{z}\\|}$ \\\\\n  \\midrule\n  $\\partial \\phi_x(0)$ & $\\mathbf{1}_3 - \\mathbf{x}\\cdot\\mathbf{x}^T$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\quad\n\\begin{tabular}{cc}\n  \\toprule\n  $\\zeta(x,y)$ & $\\mathbf{y} - (\\mathbf{x} \\cdot \\mathbf{y}) \\mathbf{x}$ \\\\\n  \\midrule\n  $\\frac{\\partial \\zeta_x(x)}{\\partial y}$ & $\\mathbf{1}_3 -\\mathbf{x}\\cdot\\mathbf{x}^T$ \\\\\n  \\midrule\n  $\\mathcal{T}(x,\\mathbf{z}, \\mathbf{v})$ & $\\mathbf{1}_3 + \\widehat{\\mathbf{x} \\wedge \\phi_x(\\mathbf{z})} + \\frac{{\\widehat{\\mathbf{x} \\wedge \\phi_x(\\mathbf{z})}}^2}{1+\\mathbf{x}\\cdot\\phi_x(\\mathbf{z})}$ \\\\\n  \\midrule\n  $\\pi_\\mathcal{M}(\\mathbf{x})$ & $\\frac{\\mathbf{x}}{\\|\\mathbf{x}\\|}$ \\\\\n  \\midrule\n  $\\pi_{T_x\\mathcal{M}}(\\mathbf{z})$ & $\\mathbf{z} - (\\mathbf{x} \\cdot \\mathbf{z}) \\mathbf{x}$ \\\\\n  \\midrule\n  $\\lim$ & $\\|\\mathbf{v}\\| \\leq \\infty$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{table}\n\n%}}}\n", "meta": {"hexsha": "4a606032021a6a453391806fdaa823e6952cdf3a", "size": 13319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix2-Manifolds/appendix2.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": "Appendix2-Manifolds/appendix2.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": "Appendix2-Manifolds/appendix2.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": 30.5481651376, "max_line_length": 209, "alphanum_fraction": 0.5929874615, "num_tokens": 5378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162774, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.670585006383357}}
{"text": "\\documentclass[t,usenames,dvipsnames]{beamer}\n\\usetheme{Copenhagen}\n\\setbeamertemplate{headline}{} % remove toc from headers\n\\beamertemplatenavigationsymbolsempty\n\n\\usepackage{amsmath, tikz, xcolor, array, graphicx}\n\\usetikzlibrary{arrows.meta}\n\\everymath{\\displaystyle}\n\n\\title{Rotation of Axes}\n\\author{}\n\\date{}\n\n\\AtBeginSection[]\n{\n  \\begin{frame}\n    \\frametitle{Table of Contents}\n    \\tableofcontents[currentsection]\n  \\end{frame}\n}\n\n\\begin{document}\n\n\\begin{frame}\n    \\titlepage\n\\end{frame}\n\n\\section{Rotate a point in the coordinate plane and convert an equation to rotated form.}\n\n\\begin{frame}{Intro}\nNormally, in the coordinate plane, each point has both an $x$- and $y$-coordinate; polar representation: $(r, \\alpha)$.\n\\begin{center}\n    \\begin{tikzpicture}[scale=0.5]\n    \\draw [<->, >=stealth] (-4.5,0) -- (4.5,0) node [right] {$x$};\n    \\draw [<->, >=stealth] (0,-4.5) -- (0,4.5) node [right] {$y$};\n    \\draw [fill=black] (2,3) circle (2pt);\n    \\draw [dashed] (0,0) -- (2,3) node [pos=0.6, left] {$r$};\n    \\draw [->, >=stealth] (0:0.75) arc (0:56.3:0.75) node [midway, right, yshift=0.20cm] {$\\alpha$};\n    \\end{tikzpicture}\n    \nThe point makes an angle $\\alpha$ with the $x$-axis.\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Intro}\nNow, suppose we rotate the axes through the origin at an angle of $\\theta$:\n\\begin{center}\n    \\begin{tikzpicture}[scale=0.5]\n    \\draw [<->, >=stealth] (-4.5,0) -- (4.5,0) node [right] {$x$};\n    \\draw [<->, >=stealth] (0,-4.5) -- (0,4.5) node [right] {$y$};\n    \\draw [<->, >=stealth, dashed, red] (-4,-4) -- (4,4) node [right] {$x'$};\n    \\draw [<->, >=stealth, dashed, red] (4,-4) -- (-4,4) node [above] {$y'$};\n    \\draw [->, >=stealth, red] (0:1) arc (0:45:1) node [midway, right, red] {$\\theta$};\n    \\coordinate (A) at (101.3:3.65);\n    \\draw [fill=black] (A) circle (2pt);\n    \\draw [dashed] (0,0) -- (A) node [pos=0.6, left] {$r$};\n    \\draw [->, >=stealth] (45:1.25) arc (45:101.3:1.25) node [midway, above right] {$\\alpha$};\n    \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}{Rotate the Axes}\nFrom the $x'$- and $y'$ axes perspective, the point $(x', y')$ has polar coordinates $(r\\cos \\alpha, r\\sin \\alpha)$. \\newline\\\\ \\pause\n\nFrom the $x$- and $y$-axes perspective, the point has polar coordinates:\n\\[\nx = r\\cos(\\theta + \\alpha) \\quad \\text{and} \\quad y = r\\sin(\\theta + \\alpha)\n\\]\n\\end{frame}\n\n\\begin{frame}{Derivation}\nExpanding each of these using the angle sum identities for cosine and sine gives us\n\\begin{align*}\n    x &= r \\cos(\\theta + \\alpha)    \\\\\n      \\onslide<2->{&= {\\color{red}r}(\\cos \\theta){(\\color{red}\\cos\\alpha)} - {\\color{blue}r}(\\sin\\theta){\\color{blue}(\\sin\\alpha)}    }\\\\\n      \\onslide<3->{&= {\\color{red}x'}\\cos\\theta - {\\color{blue}y'}\\sin\\theta \\quad (\\text{since } {\\color{red}x'=r\\cos\\alpha} \\text{ and } {\\color{blue}y'=r\\sin\\alpha})  }  \n\\end{align*}\n\\onslide<4->{and}\n\\begin{align*}\n    \\onslide<5->{y &= r \\sin(\\theta + \\alpha)    }\\\\\n    \\onslide<6->{  &= {\\color{red}r}(\\sin \\theta){\\color{red}(\\cos\\alpha)} + {\\color{blue}r(\\sin\\alpha)}(\\cos\\theta)    }\\\\\n    \\onslide<7->{  &= x'\\sin\\theta + y'\\cos\\theta    \\quad (\\text{since } {\\color{red}x' = r\\cos \\alpha} \\text{ and } {\\color{blue}y' = r\\sin \\alpha})  }\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}{Derivation}\nSo      \\newline\\\\  \n$\n\\begin{cases}\nx &= x'\\cos\\theta - y'\\sin\\theta    \\\\\ny &= x'\\sin\\theta + y'\\cos\\theta    \\\\\n\\end{cases}\n$   \\qquad  \\onslide<2->{and \\qquad\n$\\begin{cases}\nx' &= x\\cos \\theta + y\\sin \\theta   \\\\\ny' &= -x\\sin \\theta + y\\cos \\theta  \\\\\n\\end{cases}$}\n\n\\vspace{15pt}\n\\onslide<3->{\n\\emph{Note:} The $x'$ and $y'$ cases can be found by replacing $\\theta$ with $-\\theta$: \n\n\\[x' = r\\cos(\\alpha-\\theta) \\text{ and } y' = r\\sin(\\alpha-\\theta)\\]}\n\\end{frame}\n\n\\begin{frame}{Derivation}\n\\emph{Also Note:} The matrix representations of $(x,y)$ and $(x',y')$ are below:\n\n\\[\n\\begin{bmatrix}\nx \\\\\ny \n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\\cos\\theta & -\\sin\\theta \\\\\n\\sin\\theta & \\cos\\theta\n\\end{bmatrix}\n\\begin{bmatrix}\nx'  \\\\\ny'\n\\end{bmatrix}\n\\hspace{0.5in}\n\\begin{bmatrix}\nx'  \\\\\ny'  \n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\\cos \\theta &   \\sin \\theta     \\\\\n-\\sin \\theta    &   \\cos \\theta\n\\end{bmatrix}\n\\begin{bmatrix}\nx   \\\\  \ny\n\\end{bmatrix}\n\\]\n\\end{frame}\n\n\\begin{frame}{Example 1}\nSuppose the $x$- and $y$-axes are both rotated counter-clockwise through the angle $\\theta = \\frac{\\pi}{3}$ to produce the $x'$- and $y'$-axes, respectively.    \\newline\\\\\n(a) \\quad   Let $P(x,y) = (2,-4)$ and find $P(x',y')$.\n\\begin{align*}\n    \\onslide<2->{x' &= x\\cos\\theta + y\\sin\\theta   & \\onslide<5->{y' &= -x\\sin\\theta + y\\cos\\theta}}    & \\\\[8pt]\n    \\onslide<3->{x' &= 2\\cos\\left(\\frac{\\pi}{3}\\right)+(-4)\\sin\\left(\\frac{\\pi}{3}\\right) & \\onslide<6->{y' &= -2\\sin\\left(\\frac{\\pi}{3}\\right) + (-4)\\cos\\left(\\frac{\\pi}{3}\\right)}}  &   \\\\[8pt]\n    \\onslide<4->{x' &= 1-2\\sqrt{3} & \\onslide<7->{y' &= -\\sqrt{3}-2}} & \\\\\n\\end{align*}\n\\[\n\\onslide<8->{P(x',y') = \\left(1-2\\sqrt{3}, -2-\\sqrt{3}\\right)}\n\\]\n\\end{frame}\n\n\\begin{frame}{Example 1}\n(b) \\quad   Convert the equation $21x^2 + 10xy\\sqrt{3} + 31y^2 = 144$ to an equation in $x'$ and $y'$.\n\\begin{align*}\n    x &= x'\\cos\\left(\\frac{\\pi}{3}\\right) - y'\\sin\\left(\\frac{\\pi}{3}\\right) \\\\[10pt]\n    \\onslide<2->{{\\color{red}x} &{\\color{red}= \\frac{1}{2}x' - \\frac{\\sqrt{3}}{2}y'} }\\\\[10pt]\n    \\onslide<3->{x^2 &= \\frac{(x')^2}{4} - \\frac{(x')(y')\\sqrt{3}}{2} + \\frac{3(y')^2}{4} }\\\\[10pt]\n    \\onslide<4->{21x^2 &= \\frac{21(x')^2}{4} - \\frac{21(x')(y')\\sqrt{3}}{2} + \\frac{63(y')^2}{4}}\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}{Example 1 \\quad $21x^2 + 10xy\\sqrt{3} + 31y^2 = 144$}\n\\begin{align*}\n    y &= x'\\sin\\left(\\frac{\\pi}{3}\\right) + y'\\cos\\left(\\frac{\\pi}{3}\\right) \\\\[10pt]\n    \\onslide<2->{{\\color{blue}y} &{\\color{blue}= \\frac{\\sqrt{3}}{2}x' + \\frac{1}{2}y'} }\\\\[10pt]\n    \\onslide<3->{y^2 &= \\frac{3(x')^2}{4} + \\frac{(x')(y')\\sqrt{3}}{2} + \\frac{(y')^2}{4}    }\\\\[10pt]\n    \\onslide<4->{31y^2 &= \\frac{93(x')^2}{4} + \\frac{31(x')(y')\\sqrt{3}}{2} + \\frac{31(y')^2}{4}}\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}{Example 1 \\quad $21x^2 + 10xy\\sqrt{3} + 31y^2 = 144$}\n\\begin{align*}\n    xy &= {\\color{red}\\left(\\frac{1}{2}x' - \\frac{\\sqrt{3}}{2}y'\\right)}{\\color{blue}\\left(\\frac{\\sqrt{3}}{2}x' + \\frac{1}{2}y'\\right)} \\\\[10pt]\n    \\onslide<2->{{\\color{violet}xy} &= {\\color{violet}\\frac{(x')^2\\sqrt{3}}{4} - \\frac{(x')(y')}{2}-\\frac{(y')^2\\sqrt{3}}{4}}} \\\\[10pt]\n    \\onslide<3->{10xy\\sqrt{3} &= \\frac{30(x')^2}{4} - \\frac{10(x')(y')\\sqrt{3}}{2}-\\frac{30(y')^2}{4}}\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}{Example 1 \\quad $21x^2 + 10xy\\sqrt{3} + 31y^2 = 144$}\n$21x^2 + 10xy\\sqrt{3} + 31y^2 = 144$    \\newline\\\\\n\\setlength{\\extrarowheight}{6pt}\n\\begin{tabular}{ccccc}\n    \\onslide<2->{& $\\frac{21(x')^2}{4}$ &  $- \\frac{21(x')(y')\\sqrt{3}}{2}$ & $+ \\frac{63(y')^2}{4}$ &  }\\\\[12pt]\n    \\onslide<3->{& $\\frac{30(x')^2}{4}$ &  $- \\frac{10(x')(y')\\sqrt{3}}{2}$ & $-\\frac{30(y')^2}{4}$ & }\\\\[12pt]\n    \\onslide<4->{+& $\\frac{93(x')^2}{4}$ & $+ \\frac{31(x')(y')\\sqrt{3}}{2}$ & $ + \\frac{31(y')^2}{4}$ \\\\[12pt]    \\hline}\n    \\onslide<5->{& $36(x')^2$ & & + $16(y')^2$ & = 144 }\\\\\n\\end{tabular}\n\\[  \\onslide<6->{\\frac{(x')^2}{4} + \\frac{(y')^2}{9} = 1}\n\\]\n\\end{frame}\n\n\\section{Eliminate the xy-term in a rotated conic.}\n\n\\begin{frame}{Eliminating the $xy$-Term}\nGiven an equation in the form $Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0$ where $B \\neq 0$, there exists an angle $\\theta$ such that if we rotate the equation counter-clockwise by $\\theta$, the $Bxy$ term will be eliminated.  \\newline\\\\   \\pause\n\nSubstituting $x'\\cos \\theta - y'\\sin \\theta$ and $x'\\sin\\theta + y'\\cos\\theta$ for $x$ and $y$, respectively, into $Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0$, we get \\pause\n\n\\begin{equation*}\n\\begin{split}\nA(x'\\cos\\theta - y'\\sin\\theta)^2 + B(x'\\cos\\theta-y'\\sin\\theta)(x'\\sin\\theta + y'\\cos\\theta)   &\\\\ + C(x'\\sin\\theta + y'\\cos\\theta)^2 + D(x'\\cos\\theta - y'\\sin\\theta)  &\\\\  + E(x'\\sin\\theta + y'\\cos\\theta) + F = 0\n\\end{split}\n\\end{equation*}\n\\end{frame}\n\n\n\\begin{frame}{Eliminating the $xy$-Term}\nDoing algebra, we get the following coefficient for $x'y'$:\n\\begin{align*}\n &= 2(C-A)\\sin\\theta\\cos\\theta + B(\\cos^2\\theta - \\sin^2\\theta)  \\\\[10pt]\n \\onslide<2->{&= (C-A)\\sin(2\\theta) + B\\cos(2\\theta)} \n\\end{align*}\n\\onslide<3->{If we set this equal to 0, we get $(A-C)\\sin(2\\theta) = B\\cos(2\\theta)$}\n\\onslide<4->{\nfrom which\n\\[\n\\cot(2\\theta) = \\frac{A-C}{B}\n\\]}\n\\end{frame}\n\n\n\\begin{frame}{Example 2}\nFind the smallest angle of rotation in order to rewrite each of the following without the $xy$-term.  \\newline\\\\\n(a) \\quad   $5x^2 + 26xy + 5y^2 - 16x\\sqrt{2} + 16y\\sqrt{2} - 104 = 0$\n\\begin{align*}\n    \\onslide<2->{\\cot(2\\theta) &= \\frac{5-5}{26}} \\\\[6pt]\n    \\onslide<3->{\\cot(2\\theta) &= 0} \\\\[6pt]\n    \\onslide<4->{2\\theta &= \\cot^{-1}(0)} \\\\[6pt]\n    \\onslide<5->{2\\theta &= 90^\\circ} \\\\[6pt]\n    \\onslide<6->{\\theta &= 45^\\circ = \\frac{\\pi}{4}} \\\\\n\\end{align*}\n\\end{frame}\n\n\n\\begin{frame}{Example 2}\n(b) \\quad $16x^2 + 24xy + 9y^2 + 15x - 20y = 0$\n\\begin{align*}\n    \\onslide<2->{\\cot(2\\theta) &= \\frac{16-9}{24}} \\\\[6pt]\n    \\onslide<3->{\\cot(2\\theta) &= \\frac{7}{24}} \\\\[6pt]\n    \\onslide<4->{2\\theta &= \\cot^{-1}\\left(\\frac{7}{24}\\right)} \\\\[6pt]\n    \\onslide<5->{2\\theta &\\approx 73.8^\\circ} \\\\[6pt]\n    \\onslide<6->{\\theta &\\approx 36.9^\\circ} \\\\\n\\end{align*}\n\\end{frame}\n\n\\section{Determine the graph of a non-degenerate conic section.}\n\n\\begin{frame}{Conic Section Based on Equation}\nThe presence of an $xy$-term eliminates the ease in which we were previously able to classify a conic section based on its equation. \\newline\\\\  \\pause\n\nGiven that $Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0$ is a non-degenerate conic section:    \\newline\\\\  \\pause\n\\begin{itemize}\n    \\item If $B^2 - 4AC > 0$, then the graph is a hyperbola.    \\newline\\\\  \\pause\n    \\item If $B^2 - 4AC = 0$, then the graph is a parabola.    \\newline\\\\  \\pause\n    \\item If $B^2 - 4AC < 0$, then the graph is an ellipse or circle.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Example 3}\nClassify each of the following. \\newline\\\\\n(a) \\quad   $21x^2 + 10xy\\sqrt{3} + 31y^2 = 144$    \\newline\\\\  \\pause\n$A = 21 \\quad B = 10\\sqrt{3} \\quad C = 31$  \\newline\\\\  \\pause\n$B^2 - 4AC = (10\\sqrt{3})^2 - 4(21)(31) = -2304$    \\newline\\\\  \\pause\nEquation is an ellipse.\n\\end{frame}\n\n\\begin{frame}{Example 3}\nClassify each of the following. \\newline\\\\\n(b) \\quad   $5x^2 + 26xy + 5y^2 - 16x\\sqrt{2} + 16y\\sqrt{2} - 104 = 0$  \\newline\\\\  \\pause\n$A = 5 \\quad B = 26 \\quad C = 5$        \\newline\\\\  \\pause\n$B^2-4AC = 26^2 - 4(5)(5) = 576$        \\newline\\\\  \\pause\nEquation is a hyperbola.\n\\end{frame}\n\n\\begin{frame}{Example 3}\nClassify each of the following. \\newline\\\\\n(c) \\quad   $16x^2 + 24xy + 9y^2 + 15x - 20y = 0$    \\newline\\\\  \\pause\n$A = 16 \\quad B = 24 \\quad C = 9$    \\newline\\\\  \\pause\n$B^2 - 4AC = 24^2 - 4(16)(9) = 0$    \\newline\\\\  \\pause\nEquation is a parabola.\n\\end{frame}\n\n\\end{document}\n\n", "meta": {"hexsha": "bf74b7b79384e13253997ff78b32e6e345519016", "size": 10887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rotation_of_Axes(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": "Rotation_of_Axes(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": "Rotation_of_Axes(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": 37.9337979094, "max_line_length": 239, "alphanum_fraction": 0.5772021677, "num_tokens": 4544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683037, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.6705316306066356}}
{"text": "\\subsection{Vertical Asymptotes}\\label{subsec:VerticalAsymptotes}\nThe line $x=a$ is called a \\dfont{vertical asymptote} of $f(x)$ if \\ifont{at least one} of the following is true:\n$$\\lim_{x\\to a}f(x)=\\infty\\qquad\\lim_{x\\to a^-}f(x)=\\infty\\qquad\\lim_{x\\to a^+}f(x)=\\infty$$\n$$\\lim_{x\\to a}f(x)=-\\infty\\qquad\\lim_{x\\to a^-}f(x)=-\\infty\\qquad\\lim_{x\\to a^+}f(x)=-\\infty$$ \n\n\\begin{example}{Vertical Asymptotes}{VerticalAsymptotes}\nFind the vertical asymptotes of\n$\\ds f(x)=\\frac{2x}{x-4}$.\n%\\vspace{-0.5cm}\n\\end{example}\n\n\\begin{solution} \nIn the definition of vertical asymptotes we need a certain limit to be $\\pm\\infty$.\nCandidates would be to consider values not in the domain of $f(x)$, such as $a=4$.\nAs $x$ approaches $4$ but is larger than $4$ then $x-4$ is a small positive number and $2x$ is close to $8$, so the quotient $2x/(x-4)$ is a large positive number.\nThus we see that\n$$\\lim_{x\\to 4^+}\\frac{2x}{x-4}=\\infty.$$\nThus, at least one of the conditions in the definition above is satisfied. Therefore $x=4$ is a vertical asymptote.\n\\end{solution}", "meta": {"hexsha": "27b0fbedea0f1da7e43161a19310bf04d82fa97a", "size": 1057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-5-1-vertical-asymptotes.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-5-1-vertical-asymptotes.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-5-1-vertical-asymptotes.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.6315789474, "max_line_length": 163, "alphanum_fraction": 0.7000946074, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6705316304167387}}
{"text": "%\\Lecture{Jayalal Sharma}{Sept 19, 2020}{07}{Catalan Bijections}{Anshu Yadav}{$\\alpha$}{JS}\n\n\\subsection{Diagonal avoiding paths and Catlan numbers}\n%Path coordinate Notation: \nIn this section we explore the connection  between the above paths that we discussed and the Catalan number. \nLet us ask this question:\nHow many paths are there in the grid from $(0,0)$ to $(n,n)$ that avoids crossing the diagonal? \n\nWe first define what \\textit{crossing the diagonal} means. The diagonal consists of the points of the form $(i,i)$, $i\\in\\{0,\\ldots, n\\}$. A path $((u_0,v_0), \\ldots, (u_{2n},v_{2n}))$ is said to be crossing the diagonal if it \\textit{intersects} through the diagonal and goes to some point below the diagonal. Mathematically, a path is a diagonal crossing path if $\\exists~i$ such that $u_i>v_i$. In particular, $\\exists i: u_i = v_i+1$ (refer fig. \\ref{fig:diagonal-crossing-path} for example. Any diagonal crossing path must necessarily pass through one of the red dots). Equivalently, in a diagonal avoiding path $\\forall i\\in\\{0,\\ldots, 2n\\}, v_i\\ge u_i$. A sample \\emph{diagonal-avoiding path} is shown in the fig. \\ref{fig:diagonal-avoiding-path} %\\anote{explain $u_i = v_i+1$}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/diagonal-crossing.jpeg}\n    \\caption{Diagonal crossing paths. Note that path in (a) is crossing the diagonal at $(0,0)$}\n    \\label{fig:diagonal-crossing-path}\n\\end{figure}\n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/diagonal-avoiding-path.png}\n    \\caption{A diagonal avoiding path. Observe that it can still touch the diagonal}\n    \\label{fig:diagonal-avoiding-path}\n\\end{figure}\n\nBefore computing this number, an obvious question is what is the connection between such restricted paths and Catalan number. It turns out that the set of diagonal avoiding paths from $(0,0)$ to $(n,n)$ is in bijection with the set of balanced paranthesized strings of length $2n$. Hence, to count the number of balanced paranthesized strings of length $2n$, which is also the Catalan number, we only need to count the diagonal avoiding paths from $(0,0)$ to $(n,n)$. Let us first establish the bijection between the two.\n\n\\subsection{Bijection from Diagonal avoiding paths to Balanced parenthesisation problem}\nIntuitively, the bijection can be defined as follows: for any given balanced parenthesized string $w = w_1w_2\\ldots w_{2n}$, the corresponding path from $(0,0)$ to $(n,n)$ is obtained by starting from position $(0,0)$, and scanning the string from left to right. Take  right move whenever $`('$ is encountered and a down move for $`)'$. Formally we define the bijection as follows:\n\\medskip{}\n\n\\noindent\\underline{Defining the bijection:} Let $P$ be the set of diagonal avoiding paths from $(0,0)$ to $(n,n)$  and $B$ be the set of balanced paranthesized  strings of length $2n$ over the alphabets $\\{(,)\\}$. Define the bijection $\\phi:B\\rightarrow P$ as follows:\\\\\nFor $w=w_1 w_2 \\ldots w_{2n}\\in B$, $\\phi(w) = (u_0,v_0), (u_1,v_1), \\ldots, (u_i, v_i), \\ldots, (u_{2n}, v_{2n})$, where \n\\begin{enumerate}\n    \\item $(u_0,v_0)=(0,0)$ \n    \\item $\\forall i\\in\\{1,2,\\ldots, 2n\\}$\\\\\n    \\[\n    (u_i, v_i) = \n    \\begin{cases}  \n    (u_{i-1}+1, v_{i-1})& ~~~~\\text{if }w_i=)\\\\\n    (u_{i-1}, v_{i-1}+1)&~~~~\\text{if }w_i=(\n    \\end{cases}\n    \\]\n    % $(u_i, v_i) = (u_{i-1}+1, v_{i-1})~~~~\\text{if }w_i='('$\\\\\n    % $(u_i, v_i) = (u_{i-1}, v_{i-1}+1)~~~~\\text{if }w_i=')'$\n\\end{enumerate}\n\\underline{Proof of bijection}\n\\begin{description}\n\\item \\textit{Well-defined:} From the above description, given any string $w$, $\\phi(w)$ is uniquely defined. Further, for any string $w\\in B$, since the number of $'('$ is same as  the number of $')' = n$, the corresponding path has $n$ right and $n$ down moves and hence it ends at $(n,n)$. Also, since the number of left brackets is greater than or equal to the number of right brackets in any prefix of $w$, for all $i\\in[2n]$, $v_i\\ge u_i$. This shows that $\\forall w\\in B, \\phi(w)\\in P$. Hence,  $\\phi$ is well-defined.\n\\item \\textit{Injective:} Let $w, w'$ be two different strings in set $B$. Then $\\exists~$ an index $i\\in[2n]$ where $w_i\\ne w'_i$. Hence $\\phi(w)$ and $\\phi(w')$ also differ at the $i$th step, where one of the paths takes one step right while the other takes one step down. \n\\item \\textit{Surjective:} \nGiven any path $((0,0), (u_1, v_1), \\ldots, (u_{2n}, v_{2n}))$ the corresponding string $w\\in B$ is defined as follows:\\\\\n$\\forall i\\in[2n]$\n\\[\nw_i = \n\\begin{cases}\n`(`& ~~~~~\\text{if } (u_i, v_i) = (u_{i-1}, v_{i-1}+1)\\\\\n`)`& ~~~~~\\text{if } (u_i,v_i) = (u_{i-1}+1, v_{i-1})\n\\end{cases}\n\\]\nWe can verify that the string $w$ indeed is in set $B$, because firstly, for any path in $P$, $\\forall i, v_i\\ge u_i$ and hence by definition, number of left brackets $`(`$ in $w$ is greater than or equal to number of right brackets, $`(`$ in any prefix of $w$. Secondly, for any path to reach from $(0,0)$ to $(n,n)$ it must have $n$ right moves (increase in 2nd coordinate) and $n$ down moves (increase in 1st coordinate) and hence $w$ must have $n$ left brackets and $n$ right brackets.\n\\end{description}\n\n\n% Properties:\n% %$\\phi(w_1)=u_1$ and $\\phi(w_2)=u_2$ will be same till $(i-1)$th step, i.e. $(u_{1,(i-1)}, v_{1,(i-1)}=(u_{2,(i-1)}, v_{2,(i-1)}$ for $j=0$ to $i-1$.\n\n\\subsection{Counting the number of diagonal avoiding paths} \nHaving established the bijection between Catalan number and diagonal avoiding paths, we get  \n\\begin{equation}\n\\label{eq:catalan-expr-1}\n    C_n = \\# \\text{ of diagonal avoiding paths from } (0,0) to (n,n) \n\\end{equation}\nSo, our next task is to count the number of diagonal avoiding paths from $(0,0)$ to $(n,n)$. \nTo count this, we take following approach. Let us call the diagonal avoiding paths as \\textit{good} paths and diagonal crossing paths as \\textit{bad} paths. Then,\n\\begin{equation}\n\\label{eq:no-of-good-paths}\n\\Large\n    \\substack{\\text{\\# of diagonal avoiding paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)}  = \\substack{\\text{\\# of paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)} - \\substack{\\text{\\# of diagonal crossing paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)}\n\\end{equation}  \n\nSo, now our revised goal is to count the number of diagonal crossing paths from $(0,0)$ to $(n,n)$. How do we do that? Here again bijection plays an important role. The idea is to translate diagonal crossing paths into  different kind of paths which are easy to count. \n\nLet us define the following path translation:  Let $\\pi=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$ be  a diagonal crossing path. Then there must exist $i$ such that $u_i = v_i+1$. There can be many such indices as the path can cross the diagonal multiple times. Choose $i$ to be the least such index. Let $u_i = \\ell$, then the first co-ordinate after crossing the diagonal is $(\\ell, \\ell-1)$. Let us call this point $P$ (refer fig. \\ref{fig:reflecting-path}(a)). Then to find the translated path we reflect the part of the path $\\pi$ after point $P$ w.r.t. the main diagonal. \n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/reflecting-path.jpeg}\n    \\caption{Point P in a diagonal crossing path and the reflected path after P}\n    \\label{fig:reflecting-path}\n\\end{figure}\n\nMore precisely, we can divide the diagonal crossing path into two stretch $S_1, S_2$, where $S_1$ is the part of the path between $(0,0)$ to $P$ and $S_2$ is the part of the path between $P$  to $(n,n)$. \nThen to translate $\\pi$ into a new path, replace $S_2$ with $S_2'$  to get a new path $\\pi' = S_1S_2'$. The replacement $S_2'$ is defined as follows:\n\\begin{itemize}\n    \\item[-] replace downward edges with right edges and \n    \\item[-] replace right edges with downward edges.\n\\end{itemize} Refer fig. \\ref{fig:reflecting-path}(b)\nWe can observe that the new path $\\pi'$ described in this way is always between $(0,0)$ to $(n+1, n-1)$. The argument for this goes as follows:\n\nOriginally (in $S_2$), $(\\ell, \\ell-1)$ goes to $(n,n)$ which means it takes $(n-\\ell)$ downward moves and $(n-\\ell+1)$ right moves. Since, we are swapping the right and downward moves to get $S_2'$ from $S_2$, there are $(n-\\ell+1)$ downward moves and $(n-\\ell)$ right moves from point $P=(\\ell, \\ell-1)$ in $S_2'$. Thus, $S_2'$ goes from $(\\ell, \\ell-1)$ to $(\\ell+n-\\ell+1, \\ell-1+n-\\ell) = (n+1, n-1)$ and hence, $\\pi' = S_1S_2'$ is a path from $(0,0)$ to $(n+1, n-1)$. \n\nThus we have established that any diagonal crossing path from $(0,0)$ to $(n,n)$ maps to a path from $(0,0)$ to $(n+1,n-1)$ after applying the transformation described above. The converse is also true, i.e., given any path from $(0,0)$ to $(n+1, n-1)$, we can translate it back to a diagonal crossing path from $(0,0)$ to $(n,n)$ by using the same reflection technique.  Thus, we get a bijection between the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ to the set of paths from $(0,0)$ to $(n+1,n-1)$. We formally define the translation and prove that it is indeed a bijection.\n\\begin{description}\n\\item \\underline{Bijection:}\nLet $A$ be the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and $B$ be the set of paths from $(0,0)$ to $(n+1,n-1)$. Then the mapping $\\phi:A\\rightarrow B$ is formally defined as follows: \n\\\\\nLet $\\pi=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$ and $(u_i, v_i)$ be the first point when $\\pi$ crosses the diagonal. Then $\\phi(\\pi) = \\pi'=(0,0), (u'_1,v'_1), \\ldots, (u'_{2n}, v'_{2n})$ is given by:\n\\begin{enumerate}\n    \\item $\\forall 1\\le j\\le i, (u'_j, v'_j) = (u_j, v_j)$\n    \\item $\\forall i+1\\le j\\le 2n$, \n    \\[\n    (u'_j, v'_j) = \n    \\begin{cases}\n    (u'_{j-1}+1, v'_{j-1})& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}, v'_{j-1}+1)\\\\\n    (u'_{j-1}, v'_{j-1}+1)& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}+1, v'_{j-1})\n    \\end{cases}\n    \\]\n\\end{enumerate}\n% We can verify that $\\phi:A\\rightarrow B$ satisfies all the properties of a bijection as follows:\n\\item \\textit{Well-defined:} We already observed that any path $\\pi\\in A$ from $(0,0)$ to $(n,n)$ maps to a path $(0,0)$ to $(n+1,n-1)$. Hence $\\phi$ is well defined.\n\\item \\textit{Injection:} Consider two different diagonal crossing paths $\\pi_1$ and $\\pi_2$. Let $\\pi_1 = S_{1,1}S_{1,2}$ and $\\pi_2 = S_{2,1}S_{2,2}$, where the two components $S_{i,1}$ and $S_{i,2}$ for $i\\in\\{1,2\\}$ are as defined before. Then following two cases are possible:\n\\begin{itemize}\n    \\item Case1: $S_{11}\\ne S_{21}$. Then $\\pi_1'\\ne \\pi_2'$, because the first component is copied as it is in the translation, i.e. $\\pi_1' = S_{1,1}S_{1,2}'$ and $\\pi_2' = S_{2,1}S_{2,2}'$.\n    \\item Case2: $S_{11}= S_{21}$, but $S_{12}\\ne S_{22}$. In this case $S_{12}'\\ne S_{22}'$ because of the way it is defined, i.e. for every right move there is a downwards move and vice-versa. Hence, $\\pi_i'\\ne \\pi_2'$.\n\\end{itemize}\n\\item \\textit{Surjective:} Given any path $\\pi'$ from  $(0,0)$ to $(n+1,n-1)$, we can construct the corresponding path $\\pi$ from $(0,0)$ to $(n,n)$, such that $\\phi(\\pi) = \\pi'$, as follows.\\\\\nLet $\\pi'=(0,0), (u'_1,v'_1), \\ldots, (u'_{2n}, v'_{2n})$. Since $\\pi'$ goes to $(n+1, n-1)$ which is below the diagonal there must exist $i$ such that $(u'_i,v'_i)$ is below the diagonal. Again, there can be many such indices. Take $i$ to be the first such index. Same as before, let $\\pi' = S_1'S_2'$, where $S_1'$ is the path from $(0,0)$ to $(u_i', v_i')$ and  $S_1'$ is the path from $(u_i',v_i')$ to $(u_{2n}', v_{2n}')$. Then $\\pi = S_1'S_2$ where $S_2$ is obtained from $S_2'$ by swapping the right and downwards moves. Mathematically, let $\\pi=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$. Then\n\\begin{enumerate}\n    \\item $\\forall j\\le i$, $(u_j, v_j) = (u_j', v_j')$\n    \\item $\\forall~i+1\\le j\\le 2n$\n    \\[\n    (u_j, v_j) =\n    \\begin{cases}\n    (u_{j-1}+1, v_{j-1}) & ~~~~~\\text{if } (u_j', v_j') = (u_{j-1}', v_{j-1}'+1)\\\\\n    (u_{j-1}, v_{j-1}+1) & ~~~~~\\text{if } (u_j', v_j') = (u_{j-1}'+1, v_{j-1}')\n    \\end{cases}\n    \\]\n\\end{enumerate}\nAgain by the same argument as before it can be verified that $\\pi$ is a diagonal crossing path from $(0,0)$ to $(n,n)$. We write it here for completeness. Let $(\\ell, \\ell-1)$ be the first point when $\\pi'$ crosses the diagonal. Then since the path from $(0,0)$ to $(\\ell, \\ell-1)$ remains as it is in $\\pi$, it is a diagonal crossing path. Further since $\\pi'$ is path from $(0,0)$ to $(n+1, n-1)$, it takes $n+1-\\ell$ downward steps and $n-\\ell$ right steps from $(\\ell, \\ell-1)$. Hence, $\\pi$ takes $n+1-\\ell$ right and $n-\\ell$ downward steps from $(\\ell, \\ell-1)$. Thus, $\\pi$ ends at $(\\ell+n-\\ell, \\ell-1+n+1-\\ell) = (n,n)$. \n\\end{description}\n\nThus, we have established a bijection between the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and the set of  paths from $(0,0)$ to $(n+1,n-1)$. Hence, \n\\begin{eqnarray*}\n    \\# \\text{of diagonal crossing paths from } (0,0) \\text{ to } (n,n) &=& \\# \\text{of paths from } (0,0) \\text{ to } (n+1,n-1)\\\\\n    &= &{2n\\choose n+1}\n\\end{eqnarray*}\nHence, from~\\eqref{eq:catalan-expr-1},\\eqref{eq:no-of-good-paths},\n\\begin{align*} %\\label{eq:no-of-good-paths-2}\nC_n &= \\# \\text{of diagonal avoiding paths from} (0,0) \\text{ to } (n,n)\\\\\n%\\Large\n %   \\substack{\\text{\\# of diagonal avoiding paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)} \n     &= \\Large \\substack{\\text{\\# of paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)} - \\Large\\substack{\\text{\\# of diagonal crossing paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)}\\\\\n    &= {2n\\choose n} - {2n\\choose n+1}\\\\\n    & = {2n\\choose n} - \\frac{n}{n+1}{2n\\choose n}\\\\\n    &=\\frac{1}{n+1}{2n\\choose n}\n\\end{align*}  \n\nHere, in the second last line, we have used the identity: $${2n\\choose n+1} = \\frac{n}{n+1}{2n\\choose n}.$$\n\n\n\n\n\n\n\n\n\n% Let us define the following path translation: Let $p=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$ be  a diagonal crossing path which goes below the diagonal at point $(u_i, v_i)$ for for the first time. Then, translate the path $p$ to a new path $p' = (u'_0, v'_0), (u'_1,v'_1), \\ldots, (u'_{2n}, v'_{2n})$ by \\textit{reflexing} $p$ between  $(u_i, v_i)$ and $(u_{2n}, v_{2n})$ in the sense that whenever $p$ goes right, $p'$ goes down, and whenever $p$ goes down, $p'$ moves right. Mathematically,\n% \\begin{enumerate}\n%     \\item $\\forall 1\\le j\\le i, (u'_j, v'_j) = (u_j, v_j)$\n%     \\item $\\forall i+1\\le j\\le 2n$, \n%     \\[\n%     (u'_j, v'_j) = \n%     \\begin{cases}\n%     (u'_{j-1}+1, v'_{j-1})& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}, v'_{j-1}+1)\\\\\n%     (u'_{j-1}, v'_{j-1}+1)& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}+1, v'_{j-1})\n%     \\end{cases}\n%     \\]\n% \\end{enumerate}\n% In the example, we can see that the translated path ends up at $(n+1, n-1)$. In general, we can prove the following: The above defined translation of any diagonal crossing path $p$ from $(0,0)$ to $(n,n)$ always ends at $(n+1, n-1)$.\n% \\begin{proof}\n% Let $p$ croses the diagonal for the first time at $(u_i, v_i)$. Then \n% $$u_i = v_i+1.$$ \n% From $(u_i, v_i)$, $p$ moves $(n-u_i)$ steps down and $(n-v_i)$ steps in the right to reach $(n,n)$. Hence, the translated path $p'$ takes $(n-u_i)$ steps right and $(n-v_i)$ steps down from $(u_i, v_i)$ and ends at $$ (u_i+n-v_i, v_i+n-u_i) = (n+(u_i-v_i), n+(v_i-u_i)) = (n+1, n-1)$$. \n% \\end{proof}\n\n% Conversely, any path $p'$ from $(0,0)$ to $(n+1, n-1)$ can be mapped to a diagonal crossing path from $(0,0)$ to $(n,n)$. Intuitively, this can be done by again reflecting it  from the point $(u_i, v_i)$, where it crosses the diagonal for the first time. Note that such a point always exist because to reach the point $(n+1, n-1)$ $p'$ must cross the diagonal because $(n+1, n-1)$ is below the diagonal. Using the same argument as above, it can be shown that this translates $p'$ into a diagonal crossing path from $(0,0)$ to $(n,n)$.\n\n% Thus, we get a bijection between the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and the set of paths from $(0,0)$ to $(n+1,n-1)$ defined formally as follows:\\\\\n\n% Definition: Let $A$ be the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and $B$ be the set of paths from $(0,0)$ to $(n+1,n-1)$. Then a bijection $\\phi:A\\rightarrow B$ is defined as follows:\n\n% For any path $p = (u_0, v_0), (u_1, v_1), \\ldots, (u_{2n}, v_{2n})\\in A$, let $(u_i, v_i)$ be the point where the path crosses the diagonal for the first time. That is, \n% \\begin{enumerate}\n%     \\item $\\forall j<i, v_j\\ge u_j$, and\n%     \\item $u_i=v_i+1$\n% \\end{enumerate}\n% Then $\\phi(p)=p' = (u'_0, v'_0), (u'_1, v'_1), \\ldots, (u'_{2n}, v'_{2n})$, where\n% \\begin{enumerate}\n%     \\item \n% \\end{enumerate}\n\\begin{ex}\n\\item Try to establish a bijection between the set of different possible polygon triangulation in a polygon of $n+2$ nodes and the set of binary trees with $n$ internal nodes.\n\n\\textit{Hint: associate each internal node with a triangle in a triangulation. Then, each internal node will have degree three, which is the case for full binary tree, except for the leaves. Leaves will correspond to those triangles whose one of the edge is the boundary of the polygon.}\n\\end{ex}\n\n \n\n", "meta": {"hexsha": "0e96a04ed3c356fc45b2ab2e85285374d3c1dcc9", "size": 17087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture07.tex", "max_stars_repo_name": "narasimhasai07/theory-toolkit", "max_stars_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture07.tex", "max_issues_repo_name": "narasimhasai07/theory-toolkit", "max_issues_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture07.tex", "max_forks_repo_name": "narasimhasai07/theory-toolkit", "max_forks_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.7559808612, "max_line_length": 784, "alphanum_fraction": 0.650436004, "num_tokens": 5983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257127, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.6705316146127709}}
{"text": "\\chapter{Quantum circuits}\nNow that we've discussed qubits, we can talk about how to use them in circuits.\nThe key change --- and the reason that quantum circuits can do things that\nclassical circuits cannot --- is the fact that we are allowing\nlinear combinations of $0$ and $1$.\n\n\\section{Classical logic gates}\nIn classical logic, we build circuits which take in some bits for input,\nand output some more bits for input.\nThese circuits are built out of individual logic gates.\nFor example, the \\vocab{AND gate} can be pictured as follows.\n\\[\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{0} &\\qw & \\multigate{1}{\\textsc{and}} & \\rstick{0} \\qw \\\\\n\t\t\\lstick{0} &\\qw & \\ghost{\\textsc{and}} & \n\t}\n\t\\hspace{4.5em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{0} &\\qw & \\multigate{1}{\\textsc{and}} & \\rstick{0} \\qw \\\\\n\t\t\\lstick{1} &\\qw & \\ghost{\\textsc{and}} & \n\t}\n\t\\hspace{4.5em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{1} &\\qw & \\multigate{1}{\\textsc{and}} & \\rstick{0} \\qw \\\\\n\t\t\\lstick{0} &\\qw & \\ghost{\\textsc{and}} & \n\t}\n\t\\hspace{4.5em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{1} &\\qw & \\multigate{1}{\\textsc{and}} & \\rstick{1} \\qw \\\\\n\t\t\\lstick{1} &\\qw & \\ghost{\\textsc{and}} & \n\t}\n\\]\nOne can also represent the AND gate using the ``truth table'':\n\\[\n\t\\begin{array}{|cc|c|}\n\t\t\\hline\n\t\tA & B & A \\text{ and } B \\\\ \\hline\n\t\t0 & 0 & 0 \\\\\n\t\t0 & 1 & 0 \\\\\n\t\t1 & 0 & 0 \\\\\n\t\t1 & 1 & 1 \\\\\n\t\t\\hline\n\t\\end{array}\n\\]\nSimilarly, we have the \\vocab{OR gate} and the \\vocab{NOT gate}:\n\\[\n\t\\begin{array}{|cc|c|}\n\t\t\\hline\n\t\tA & B & A \\text{ or } B \\\\ \\hline\n\t\t0 & 0 & 0 \\\\\n\t\t0 & 1 & 1 \\\\\n\t\t1 & 0 & 1 \\\\\n\t\t1 & 1 & 1 \\\\\n\t\t\\hline\n\t\\end{array}\n\t\\qquad\n\t\\begin{array}{|c|c|}\n\t\t\\hline\n\t\tA & \\text{not } A \\\\ \\hline\n\t\t0 & 1 \\\\\n\t\t1 & 0 \\\\\n\t\t\\hline\n\t\\end{array}\n\\]\nWe also have a so-called \\vocab{COPY gate}, which duplicates a bit.\n\\[\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{0} & \\qw & \\multigate{1}{\\textsc{copy}} & \\rstick{0} \\qw & \\\\\n\t\t&& & \\rstick{0} \\qw & \n\t}\n\t\\qquad\\qquad\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{1} & \\qw & \\multigate{1}{\\textsc{copy}} & \\rstick{1} \\qw & \\\\\n\t\t&& & \\rstick{1} \\qw & \n\t}\n\\]\nOf course, the first theorem you learn about these gates is that:\n\\begin{theorem}\n\t[AND, OR, NOT, COPY are universal]\n\tThe set of four gates AND, OR, NOT, COPY is universal in the sense that\n\tany boolean function $f : \\{0,1\\}^n \\to \\{0,1\\}$ \n\tcan be implemented as a circuit using only these gates.\n\\end{theorem}\n\\begin{proof}\n\tSomewhat silly: we essentially write down a circuit that OR's across\n\tall input strings in $f\\pre(1)$.\n\tFor example, suppose we have $n=3$ and want to simulate the function\n\t$f(abc)$ with $f(011) = f(110) = 1$ and $0$ otherwise.\n\tThen the corresponding Boolean expression for $f$ is simply\n\t\\[\n\t\tf(abc) = \n\t\t\\left[ \\text{(not $a$) and $b$ and $c$} \\right]\n\t\t\\text{ or }\n\t\t\\left[ \\text{$a$ and $b$ and (not $c$)} \\right].\n\t\\]\n\tClearly, one can do the same for any other $f$,\n\tand implement this logic into a circuit.\n\\end{proof}\n\\begin{remark}\n\tSince\n\t$x \\text{ and } y = \\text{not } ( (\\text{not $x$}) \\text{ or } (\\text{not $y$}))$,\n\tit follows that in fact, we can dispense with the AND gate.\n\\end{remark}\n\n\\section{Reversible classical logic}\n\\prototype{CNOT gate, Toffoli gate.}\n\nFor the purposes of quantum mechanics, this is not enough.\nTo carry through the analogy we in fact need gates that are \\vocab{reversible},\nmeaning the gates are bijections from the input space to the output space.\nIn particular, such gates must take the same number of input and output gates.\n\\begin{example}[Reversible gates]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii None of the gates AND, OR, COPY are reversible for dimension reasons.\n\t\t\\ii The NOT gate, however, is reversible:\n\t\tit is a bijection $\\{0,1\\} \\to \\{0,1\\}$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[The CNOT gate]\n\tThe controlled-NOT gate, or the \\vocab{CNOT} gate,\n\tis a reversible $2$-bit gate with the following truth table.\n\t\\[\n\t\t\\begin{array}{|rr|rr|}\n\t\t\t \\hline\n\t\t\t \\multicolumn{2}{|c|}{\\text{In}} & \\multicolumn{2}{|c|}{\\text{Out}} \\\\\n\t\t\t \\hline\n\t\t\t 0 & 0 & 0 & 0 \\\\ \n\t\t\t 1 & 0 & 1 & 1 \\\\ \n\t\t\t 0 & 1 & 0 & 1 \\\\ \n\t\t\t 1 & 1 & 1 & 0 \\\\ \\hline\n\t\t\\end{array}\n\t\\]\n\tIn other words, this gate XOR's the first bit to the second bit,\n\twhile leaving the first bit unchanged.\n\tIt is depicted as follows.\n\t\\[\n\t\t\\Qcircuit @C=1em @R=.7em {\n\t\t\t\\lstick{x} & \\ctrl{1} & \\rstick{x} \\qw \\\\\n\t\t\t\\lstick{y} & \\targ & \\rstick{x+y \\mod 2} \\qw \n\t\t}\n\t\\]\n\tThe first dot is called the ``control'',\n\twhile the $\\oplus$ is the ``negation'' operation:\n\tthe first bit controls whether the second bit gets flipped or not.\n\tThus, a typical application might be as follows.\n\t\\[\n\t\t\\Qcircuit @C=1em @R=.7em {\n\t\t\t\\lstick{1} & \\ctrl{1} & \\rstick{1} \\qw \\\\\n\t\t\t\\lstick{0} & \\targ & \\rstick{1} \\qw\n\t\t}\n\t\\]\n\\end{example}\nSo, NOT and CNOT are the only nontrivial reversible gates on two bits.\n\nWe now need a different definition of universal for our reversible gates.\n\\begin{definition}\n\tA set of reversible gates can \\vocab{simulate} a Boolean function $f(x_1 \\dots x_n)$,\n\tif one can implement a circuit which takes\n\t\\begin{itemize}\n\t\t\\ii As input, $x_1 \\dots x_n$ plus some fixed bits set to $0$ or $1$,\n\t\tcalled \\vocab{ancilla bits}\\footnote{%\n\t\t\tThe English word ``ancilla'' means ``maid''.}.\n\t\t\\ii As output, the input bits $x_1, \\dots, x_n$,\n\t\tthe output bit $f(x_1, \\dots, x_n)$,\n\t\tand possibly some extra bits (called \\vocab{garbage bits}).\n\t\\end{itemize}\n\tThe gate(s) are \\vocab{universal} if they can simulate any Boolean function.\n\\end{definition}\nFor example, the CNOT gate can simulate the NOT gate,\nusing a single ancilla bit $1$,\naccording to the following circuit.\n\\[\n\t\\Qcircuit @C=1em @R=.7em {\n\t\t\\lstick{x} & \\ctrl{1} & \\rstick{x} \\qw \\\\\n\t\t\\lstick{1} & \\targ & \\rstick{\\text{not } x} \\qw\n\t}\n\\]\nUnfortunately, it is not universal.\n\\begin{proposition}\n\t[CNOT $\\not\\Rightarrow$ AND]\n\tThe CNOT gate cannot simulate the boolean function ``$x \\text{ and } y$''.\n\\end{proposition}\n\\begin{proof}[Sketch of Proof]\n\tOne can see that any function simulated using only CNOT gates\n\tmust be of the form\n\t\\[ a_1 x_1 + a_2 x_2 + \\dots + a_n x_n \\pmod 2 \\]\n\tbecause CNOT is the map $(x,y) \\mapsto (x, x+y)$.\n\tThus, even with ancilla bits, we can only create functions\n\tof the form $ax+by+c \\pmod 2$ for fixed $a$, $b$, $c$.\n\tThe AND gate is not of this form.\n\\end{proof}\n\nSo, we need at least a three-qubit gate.\nThe most commonly used one is:\n\\begin{definition}\n\tThe three-bit \\vocab{Toffoli gate}, also called the CCNOT gate, is given by\n\t\\[\n\t\t\\Qcircuit @C=1em @R=.7em {\n\t\t\t\\lstick{x} & \\ctrl{1} & \\rstick{x} \\qw \\\\\n\t\t\t\\lstick{y} & \\ctrl{1} & \\rstick{y} \\qw \\\\\n\t\t\t\\lstick{z} & \\targ & \\rstick{z + xy \\pmod 2} \\qw\n\t\t}\n\t\\]\n\tSo the Toffoli has two controls, and toggles the last bit if and only if \n\tboth of the control bits are $1$.\n\\end{definition}\nThis replacement is sufficient.\n\\begin{theorem}\n\t[Toffoli gate is universal]\n\tThe Toffoli gate is universal.\n\\end{theorem}\n\\begin{proof}\n\tWe will show it can \\emph{reversibly} simulate\n\tAND, NOT, hence OR,\n\twhich we know is enough to show universality.\n\t(We don't need COPY because of reversibility.)\n\n\tFor the AND gate, we draw the circuit\n\t\\[\n\t\t\\Qcircuit @C=1em @R=.7em {\n\t\t\t\\lstick{x} & \\ctrl{1} & \\rstick{x} \\qw \\\\\n\t\t\t\\lstick{y} & \\ctrl{1} & \\rstick{y} \\qw \\\\\n\t\t\t\\lstick{0} & \\targ & \\rstick{x \\text{ and } y} \\qw\n\t\t}\n\t\\]\n\twith one ancilla bit, and no garbage bits.\n\n\tFor the NOT gate, we use two ancilla $1$ bits and one garbage bit:\n\t\\[\n\t\t\\Qcircuit @C=1em @R=.7em {\n\t\t\t\\lstick{1} & \\ctrl{1} & \\rstick{1} \\qw \\\\\n\t\t\t\\lstick{z} & \\ctrl{1} & \\rstick{z} \\qw \\\\\n\t\t\t\\lstick{1} & \\targ & \\rstick{\\text{not } z} \\qw\n\t\t}\n\t\\]\n\tThis completes the proof.\n\\end{proof}\n\nHence, in theory we can create any classical circuit we desire\nusing the Toffoli gate alone.\nOf course, this could require exponentially many gates for even the\nsimplest of functions.\nFortunately, this is NO BIG DEAL because I'm a math major,\nand having $2^n$ gates is a problem best left for the CS majors.\n\n\\section{Quantum logic gates}\nIn quantum mechanics, since we can have \\emph{linear combinations} of basis\nelements, our logic gates will instead consist of \\emph{linear maps}.\nMoreover, in quantum computation, gates are always reversible,\nwhich was why we took the time in the previous section to show\nthat we can still simulate any function when restricted to reversible gates\n(e.g.\\ using the Toffoli gate).\n\nFirst, some linear algebra:\n\\begin{definition}\n\tLet $V$ be a finite dimensional inner product space.\n\tThen for a map $U : V \\to V$, the following are equivalent:\n\t\\begin{itemize}\n\t\t\\ii $\\left< U(x), U(y) \\right> = \\left< x,y \\right>$ for $x,y \\in V$.\n\t\t\\ii $U^\\dagger$ is the inverse of $U$.\n\t\t\\ii $\\norm{x} = \\norm{U(x)}$ for $x \\in V$.\n\t\\end{itemize}\n\tThe map $U$ is called \\vocab{unitary}\n\tif it satisfies these equivalent conditions.\n\\end{definition}\n\nThen\n\\begin{moral}\n\tQuantum logic gates are unitary matrices.\n\\end{moral}\nIn particular, unlike the classical situation,\nquantum gates are always reversible\n(and hence they always take the same number of input and output bits).\n\nFor example, consider the CNOT gate.\nIts quantum analog should be a unitary map $\\UCNOT : H \\to H$,\nwhere $H = \\CC^{\\oplus 2} \\otimes \\CC^{\\oplus 2}$,\ngiven on basis elements by\n\\[\n\t\\UCNOT(\\ket{00}) = \\ket{00}, \\quad\n\t\\UCNOT(\\ket{01}) = \\ket{01}\n\\]\n\\[\n\t\\UCNOT(\\ket{10}) = \\ket{11}, \\quad\n\t\\UCNOT(\\ket{11}) = \\ket{10}.\n\\]\nSo pictorially, the quantum CNOT gate is given by\n\\[\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket0} & \\ctrl{1} & \\rstick{\\ket0} \\qw \\\\\n\t\t\\lstick{\\ket0} & \\targ & \\rstick{\\ket0} \\qw \\\\\n\t}\n\t\\hspace{6em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket0} & \\ctrl{1} & \\rstick{\\ket0} \\qw \\\\\n\t\t\\lstick{\\ket1} & \\targ & \\rstick{\\ket1} \\qw \\\\\n\t}\n\t\\hspace{6em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket1} & \\ctrl{1} & \\rstick{\\ket1} \\qw \\\\\n\t\t\\lstick{\\ket0} & \\targ & \\rstick{\\ket1} \\qw \\\\\n\t}\n\t\\hspace{6em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket1} & \\ctrl{1} & \\rstick{\\ket1} \\qw \\\\\n\t\t\\lstick{\\ket1} & \\targ & \\rstick{\\ket0} \\qw \\\\\n\t}\n\\]\nOK, so what?\nThe whole point of quantum mechanics is that we allow linear\nqubits to be in linear combinations of $\\ket0$ and $\\ket1$,\ntoo, and this will produce interesting results.\nFor example, let's take $\\xdown = \\frac{1}{\\sqrt2} (\\ket0-\\ket1)$\nand plug it into the top, with $\\ket 1$ on the bottom, and see what happens:\n\\[\n\t\\UCNOT \\left( \\xdown \\otimes \\ket1 \\right)\n\t= \\UCNOT \\left( \\frac{1}{\\sqrt2} (\\ket{01}-\\ket{11}) \\right)\n\t= \\frac{1}{\\sqrt2} \\left( \\ket{01}-\\ket{10} \\right)\n\t= \\ket{\\Psi_-}\n\\]\nwhich is the fully entangled \\emph{singlet state}! Picture:\n\\[\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\xdown} & \\ctrl{1} & \\rstick{\\ket{\\Psi_-}} \\qw \\\\\n\t\t\\lstick{\\ket1} & \\targ & \\rstick{} \\qw \\\\\n\t}\n\\]\n\nThus, when we input mixed states into our quantum gates,\nthe outputs are often entangled states,\neven when the original inputs are not entangled.\n\n\\begin{example}\n\t[More examples of quantum gates]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Every reversible classical gate that we encountered before\n\t\thas a quantum analog obtained in the same way as CNOT:\n\t\tby specifying the values on basis elements.\n\t\tFor example, there is a quantum Tofolli gate which\n\t\tfor example sends\n\t\t\\[\n\t\t\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\t\t\\lstick{\\ket1} & \\ctrl{1} & \\rstick{\\ket1} \\qw \\\\\n\t\t\t\t\\lstick{\\ket1} & \\ctrl{1} & \\rstick{\\ket1} \\qw \\\\\n\t\t\t\t\\lstick{\\ket0} & \\targ & \\rstick{\\ket1} \\qw.\n\t\t\t}\n\t\t\\]\n\t\t\\ii The \\vocab{Hadamard gate} on one qubit is a rotation given by\n\t\t\\[\n\t\t\t\\begin{bmatrix}\n\t\t\t\t\\frac{1}{\\sqrt2} & \\frac{1}{\\sqrt2} \\\\\n\t\t\t\t\\frac{1}{\\sqrt2} & -\\frac{1}{\\sqrt2}\n\t\t\t\\end{bmatrix}.\n\t\t\\]\n\t\tThus, it sends $\\ket0$ to $\\xup$ and $\\ket1$ to $\\xdown$.\n\t\tNote that the Hadamard gate is its own inverse.\n\t\tIt is depicted by an ``$H$'' box.\n\t\t\\[\n\t\t\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\t\t\\lstick{\\ket0} & \\gate{H} & \\rstick{\\xup} \\qw\n\t\t\t}\n\t\t\\]\n\t\t\\ii More generally, if $U$ is a $2 \\times 2$ unitary matrix\n\t\t(i.e.\\ a map $\\CC^{\\oplus 2} \\to \\CC^{\\oplus 2}$) then\n\t\tthere is \\vocab{$U$-rotation gate} similar to the previous one,\n\t\twhich applies $U$ to the input.\n\t\t\\[\n\t\t\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\t\t\\lstick{\\ket\\psi} & \\gate{U} & \\rstick{U\\ket\\psi} \\qw\n\t\t\t}\n\t\t\\]\n\t\tFor example, the classical NOT gate is represented by $U = \\sigma_x$.\n\t\t\\ii A \\vocab{controlled $U$-rotation gate} generalizes the CNOT gate.\n\t\tLet $U : \\CC^{\\oplus 2} \\to \\CC^{\\oplus 2}$ be a rotation gate,\n\t\tand let $H = \\CC^{\\oplus 2} \\otimes \\CC^{\\oplus 2}$ be a $2$-qubit space.\n\t\tThen the controlled $U$ gate has the following circuit diagrams.\n\t\t\\[\n\t\t\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\t\t\\lstick{\\ket0} & \\ctrl{1} & \\rstick{\\ket0} \\qw \\\\\n\t\t\t\t\\lstick{\\ket\\psi} & \\gate{U} & \\rstick{\\ket\\psi} \\qw\n\t\t\t}\n\t\t\t\\hspace{8em}\n\t\t\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\t\t\\lstick{\\ket1} & \\ctrl{1} & \\rstick{\\ket1} \\qw \\\\\n\t\t\t\t\\lstick{\\ket\\psi} & \\gate{U} & \\rstick{U\\ket\\psi} \\qw\n\t\t\t}\n\t\t\\]\n\t\tThus, $U$ is applied when the controlling bit is $1$,\n\t\tand CNOT is the special case $U = \\sigma_x$.  As before,\n\t\twe get interesting behavior if the control is mixed.\n\t\\end{enumerate}\n\\end{example}\n\nAnd now, some more counterintuitive quantum behavior.\nSuppose we try to use CNOT as a copy, with truth table.\n\\[\n\t\\begin{array}{|rr|rr|}\n\t\t \\hline\n\t\t \\multicolumn{2}{|c|}{\\text{In}} & \\multicolumn{2}{|c|}{\\text{Out}} \\\\\n\t\t \\hline\n\t\t 0 & 0 & 0 & 0 \\\\ \n\t\t 1 & 0 & 1 & 1 \\\\ \n\t\t 0 & 1 & 0 & 1 \\\\ \n\t\t 1 & 1 & 1 & 0 \\\\ \\hline\n\t\\end{array}\n\\]\nThe point of this gate is to be used with a garbage $0$ at the bottom\nto try and simulate a ``copy'' operation.\nSo indeed, one can check that\n\\[\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket0} & \\multigate{1}{U} & \\rstick{\\ket0} \\qw \\\\\n\t\t\\lstick{\\ket0} & \\ghost{U} & \\rstick{\\ket0} \\qw\n\t}\n\t\\hspace{8em}\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket1} & \\multigate{1}{U} & \\rstick{\\ket1} \\qw \\\\\n\t\t\\lstick{\\ket0} & \\ghost{U} & \\rstick{\\ket1} \\qw\n\t}\n\\]\nThus we can copy $\\ket0$ and $\\ket1$.\nBut as we've already seen if we input $\\xdown \\otimes \\ket0$ into $U$,\nwe end up with the entangled state $\\ket{\\Psi_-}$\nwhich is decisively \\emph{not} the $\\xdown \\otimes \\xdown$ we wanted.\nAnd in fact, the so-called \\vocab{no-cloning theorem} implies\nthat it's impossible to duplicate an arbitrary $\\ket\\psi$;\nthe best we can do is copy specific orthogonal states as in the classical case.\nSee also \\Cref{prob:baby_no_clone}.\n\n\\section{Deutsch-Jozsa algorithm}\nThe Deutsch-Jozsa algorithm is the first example of a nontrivial\nquantum algorithm which cannot be performed classically:\nit is a ``proof of concept'' that would later inspire Grover's search algorithm\nand Shor's factoring algorithm.\n\nThe problem is as follows: we're given a function $f : \\{0,1\\}^n \\to \\{0,1\\}$,\nand promised that the function $f$ is either\n\\begin{itemize}\n\t\\ii A constant function, or\n\t\\ii A balanced function, meaning that exactly half the inputs map to\n\t$0$ and half the inputs map to $1$.\n\\end{itemize}\nThe function $f$ is given in the form of a reversible black box $U_f$ which\nis the control of a NOT gate, so it can be represented as the circuit diagram\n\\[\n\t\\Qcircuit @C=1em @R=0.7em {\n\t\t\\lstick{\\ket{x_1x_2 \\dots x_n}} & /^n \\qw & \\multigate{1}{U_f} &\n\t\t\t\\rstick{\\ket{x_1x_2\\dots x_n}} \\qw \\\\\n\t\t\\lstick{\\ket{y}} & \\qw & \\ghost{U_f} & \\rstick{\\ket{y+f(x) \\mod 2}}\\qw \\\\\n\t}\n\\]\ni.e.\\ if $f(x_1, \\dots, x_n) = 0$ then the gate does nothing,\notherwise the gate flips the $y$ bit at the bottom.\nThe slash with the $n$ indicates that the top of the input really consists\nof $n$ qubits, not just the one qubit drawn,\nand so the black box $U_f$ is a map on $n+1$ qubits.\n\nThe problem is to determine,\nwith as few calls to the black box $U_f$ as possible,\nwhether $f$ is balanced or constant.\n\n\\begin{ques}\n\tClassically, show that in the worst case we may need\n\tup to $2^{n-1}+1$ calls to the function $f$ to answer the question.\n\\end{ques}\n\nSo with only classical tools, it would take $O(2^n)$ queries to determine\nwhether $f$ is balanced or constant.\nHowever,\n\\begin{theorem}\n\t[Deutsch-Jozsa]\n\tThe Deutsch-Jozsa problem can be determined in a quantum circuit\n\twith only a single call to the black box.\n\\end{theorem}\n\\begin{proof}\n\tFor concreteness, we do the case $n=1$ explicitly;\n\tthe general case is contained in \\Cref{prob:deutsch_jozsa}.\n\tWe claim that the necessary circuit is\n\t\\[\n\t\t\\Qcircuit @C=1em @R=0.7em {\n\t\t\t\\lstick{\\ket0} & \\gate{H} & \\multigate{1}{U_f} & \\gate{H} & \\meter \\qw \\\\\n\t\t\t\\lstick{\\ket1} & \\gate{H} & \\ghost{U_f} & \\qw & \\\\\n\t\t}\n\t\\]\n\tHere the $H$'s are Hadamard gates,\n\tand the meter at the end of the rightmost wire\n\tindicates that we make a measurement along the usual $\\ket0$, $\\ket1$ basis.\n\tThis is not a typo! Even though classically the top wire is just\n\ta repeat of the input information,\n\twe are about to see that it's the top we want to measure.\n\n\tNote that after the two Hadamard operations, the state we get is\n\t\\begin{align*}\n\t\t\\ket{01} &\\xmapsto{H^{\\otimes 2}}\n\t\t\\left( \\frac{1}{\\sqrt2}(\\ket0+\\ket1) \\right)\n\t\t\\otimes\n\t\t\\left( \\frac{1}{\\sqrt2}(\\ket0-\\ket1) \\right) \\\\\n\t\t&=\n\t\t\\half \\Big( \\ket0\\otimes\\big(\\ket0-\\ket1\\big) \n\t\t\\; + \\; \\ket1\\otimes\\big(\\ket0-\\ket1\\big) \\Big).\n\t\\end{align*}\n\tSo after applying $U_f$, we obtain\n\t\\[\n\t\t\\half\\Big( \n\t\t\\ket0\\otimes\\big(\\ket{0+f(0)}-\\ket{1+f(0)}\\big)\n\t\t\\; + \\; \\ket1\\otimes\\big(\\ket{0+f(1)}-\\ket{1+f(1)}\\big)\n\t\t\\Big)\n\t\\]\n\twhere the modulo $2$ has been left implicit.\n\tNow, observe that the effect of going from\n\t$\\ket0-\\ket1$ to $\\ket{0+f(x)}-\\ket{1+f(x)}$ is merely\n\tto either keep the state the same (if $f(x)=0$)\n\tor to negate it (if $f(x)=1$).\n\tSo we can simplify and factor to get\n\t\\[\n\t\t\\half\n\t\t\\left( (-1)^{f(0)}\\ket0 + (-1)^{f(1)}\\ket1 \\right)\n\t\t\\otimes\n\t\t\\left( \\ket0-\\ket1 \\right).\n\t\\]\n\tThus, the picture so far is:\n\t\\[\n\t\t\\Qcircuit @C=1em @R=0.7em {\n\t\t\t\\lstick{\\ket0} & \\gate{H} & \\multigate{1}{U_f} &\n\t\t\t\t\\rstick{\\frac{1}{\\sqrt2}%\n\t\t\t\t\\Big((-1)^{f(0)}\\ket0+(-1)^{f(1)}\\ket1\\Big)} \\qw \\\\\n\t\t\t\\lstick{\\ket1} & \\gate{H} & \\ghost{U_f} &\n\t\t\t\t\\rstick{\\frac{1}{\\sqrt2}(\\ket0-\\ket1)} \\qw\n\t\t}\n\t\\]\n\tIn particular, the resulting state is not entangled,\n\tand we can simply discard the last qubit (!).\n\tNow observe:\n\t\\begin{itemize}\n\t\t\\ii If $f$ is constant, then the upper-most state is $\\pm\\xup$.\n\t\t\\ii If $f$ is balanced, then the upper-most state is $\\pm\\xdown$.\n\t\\end{itemize}\n\tSo simply doing a measurement along $\\sigma_x$ will give us the answer.\n\tEquivalently, perform another $H$ gate\n\t(so that $H\\xup = \\ket0$, $H\\xdown = \\ket1$)\n\tand measuring along $\\sigma_z$ in the usual $\\ket0$, $\\ket1$ basis.\n\tThus for $n=1$ we only need a single call to the oracle.\n\\end{proof}\n\n\n\\section\\problemhead\n\\begin{problem}[Fredkin gate]\n\tThe \\vocab{Fredkin gate} (also called the controlled swap, or CSWAP gate)\n\tis the three-bit gate with the following truth table:\n\t\\[\n\t\\begin{array}{|rrr|rrr|}\n\t\t \\hline\n\t\t \\multicolumn{3}{|c|}{\\text{In}} & \\multicolumn{3}{|c|}{\\text{Out}} \\\\\n\t\t \\hline\n\t\t 0 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t 0 & 0 & 1 & 0 & 0 & 1 \\\\\n\t\t 0 & 1 & 0 & 0 & 1 & 0 \\\\\n\t\t 0 & 1 & 1 & 0 & 1 & 1 \\\\\n\t\t 1 & 0 & 0 & 1 & 0 & 0 \\\\\n\t\t 1 & 0 & 1 & 1 & 1 & 0 \\\\\n\t\t 1 & 1 & 0 & 1 & 0 & 1 \\\\\n\t\t 1 & 1 & 1 & 1 & 1 & 1 \\\\\\hline\n\t \\end{array}\n\t\\]\n\tThus the gate swaps the last two input bits whenever the first bit is $1$.\n\tShow that this gate is also reversible and universal.\n\t\\begin{hint}\n\t\tOne way is to create CCNOT using a few Fredkin gates.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tTo show the Fredkin gate is universal\n\t\tit suffices to reversibly create a CCNOT gate with it.\n\t\tWe write the system\n\t\t\\begin{align*}\n\t\t\t(z,\\neg z,-) &= \\opname{Fred}(z,1,0) \\\\\n\t\t\t(x,a,-) &= \\opname{Fred}(x,1,0) \\\\\n\t\t\t(y,b,-) &= \\opname{Fred}(y,a,0) \\\\\n\t\t\t(-,c,-) &= \\opname{Fred}(b,0,1) \\\\\n\t\t\t(-,d,-) &= \\opname{Fred}(c, z, \\neg z).\n\t\t\\end{align*}\n\t\tDirect computation shows that $d = z+xy\\pmod 2$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Baby no-cloning theorem]\n\t\\label{prob:baby_no_clone}\n\tShow that there is no unitary map $U$ on two qubits\n\twhich sends $U(\\ket\\psi \\otimes \\ket0) = \\ket\\psi \\otimes \\ket\\psi$\n\tfor any qubit $\\ket\\psi$, i.e.\\\n\tthe following circuit diagram is impossible.\n\t\\[\n\t\\Qcircuit @C=0.8em @R=.7em {\n\t\t\\lstick{\\ket\\psi} & \\multigate{1}{U} & \\rstick{\\ket\\psi} \\qw \\\\\n\t\t\\lstick{\\ket0} & \\ghost{U} & \\rstick{\\ket\\psi} \\qw\n\t}\n\t\\]\n\t\\begin{hint}\n\t\tPlug in $\\ket\\psi=\\ket0$, $\\ket\\psi=\\ket1$, $\\ket\\psi = \\xup$\n\t\tand derive a contradiction.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}[Deutsch-Jozsa]\n\t\\label{prob:deutsch_jozsa}\n\tGiven the black box $U_f$ described in the Deutsch-Jozsa algorithm,\n\tconsider the following circuit.\n\t\\[\n\t\t\\Qcircuit @C=1em @R=0.7em {\n\t\t\t\\lstick{\\ket{0\\dots0}} & /^n \\qw & \\gate{H^{\\otimes n}} & \\multigate{1}{U_f}\n\t\t\t\t& \\gate{H^{\\otimes n}} & \\meter \\qw \\\\\n\t\t\t\\lstick{\\ket1} & \\qw & \\gate{H} & \\ghost{U_f} & \\qw & \\\\\n\t\t}\n\t\\]\n\tThat is, take $n$ copies of $\\ket 0$, apply the Hadamard rotation to all of them,\n\tapply $U_f$, reverse the Hadamard to all $n$ input bits\n\t(again discarding the last bit), then measure all $n$ bits\n\tin the $\\ket0$/$\\ket1$ basis (as in \\Cref{ex:simult_measurement}).\n\n\tShow that the probability of measuring $\\ket{0\\dots0}$\n\tis $1$ if $f$ is constant and $0$ if $f$ is balanced.\n\t\\begin{hint}\n\t\tFirst show that the box sends\n\t\t$\\ket{x_1} \\otimes \\dots \\otimes \\ket{x_m} \\otimes \\xdown$\n\t\tto $(-1)^{f(x_1, \\dots, x_m)}\n\t\t(\\ket{x_1} \\otimes \\dots \\otimes \\ket{x_m} \\otimes \\xdown)$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tPut $\\xdown = \\frac{1}{\\sqrt2} (\\ket0-\\ket1)$.\n\t\tThen we have that $U_f$ sends\n\t\t\\[\n\t\t\t\\ket{x_1}  \\dots  \\ket{x_m}  \\ket 0 \n\t\t\t- \\ket{x_1}  \\dots  \\ket{x_m}  \\ket 1 \n\t\t\t\\xmapsto{U_f}\n\t\t\t\\pm \\ket{x_1}  \\dots  \\ket{x_m}  \\ket 0 \n\t\t\t\\mp \\ket{x_1}  \\dots  \\ket{x_m}  \\ket 1 \n\t\t\\]\n\t\tthe sign being $+$, $-$ exactly when $f(x_1, \\dots, x_m) = 1$.\n\n\t\tNow, upon inputting $\\ket0 \\dots \\ket0 \\ket1$, we find that $H^{\\otimes m+1}$ maps it to\n\t\t\\[ 2^{-n/2} \\sum_{x_1, \\dots, x_n} \\ket{x_1} \\dots \\ket{x_n} \\xdown.  \\]\n\t\tThen the image under $U_f$ is\n\t\t\\[ 2^{-n/2} \\sum_{x_1, \\dots, x_n} (-1)^{f(x_1, \\dots, x_n)} \\ket{x_1} \\dots \\ket{x_n} \\xdown.  \\]\n\t\tWe now discard the last qubit, leaving us with\n\t\t\\[ 2^{-n/2} \\sum_{x_1, \\dots, x_n} (-1)^{f(x_1, \\dots, x_n)} \\ket{x_1} \\dots \\ket{x_n}.  \\]\n\t\tApplying $H^{\\otimes m}$ to this, we get\n\t\t\\[ 2^{-n/2} \\sum_{x_1, \\dots, x_n} (-1)^{f(x_1, \\dots, x_n)}\n\t\t\t\\cdot\n\t\t\t\\left(\n\t\t\t2^{-n/2}\n\t\t\t\\sum_{y_1, \\dots, y_n}\n\t\t\t(-1)^{x_1 y_1 + \\dots + x_n y_n}\n\t\t\t\\ket{y_1} \\ket{y_2} \\dots \\ket{y_n}\n\t\t\t\\right)\n\t\t\\]\n\t\tsince $H\\ket0 = \\frac{1}{\\sqrt2}(\\ket0+\\ket1)$\n\t\twhile $H\\ket1 = \\frac{1}{\\sqrt2}(\\ket0-\\ket1)$,\n\t\tso minus signs arise exactly if $x_i = 0$ and $y_i = 0$ simultaneously,\n\t\thence the term $(-1)^{x_1 y_1 + \\dots + x_n y_n}$.\n\t\tSwapping the order of summation, we get\n\t\t\\[ \n\t\t\t2^{-n}\n\t\t\t\\sum_{y_1, \\dots, y_n}\n\t\t\tC(y_1, \\dots, y_n)\n\t\t\t\\ket{y_1} \\ket{y_2} \\dots \\ket{y_n}\n\t\t\\]\n\t\twhere $C_{y_1, \\dots, y_n} \n\t\t= \\sum_{x_1, \\dots, x_n} (-1)^{f(x_1, \\dots, x_n)\n\t\t\t+x_1 y_1 + \\dots + x_n y_n}$.\n\t\tNow, we finally consider two cases.\n\t\t\\begin{itemize}\n\t\t\t\\ii If $f$ is the constant function, then we find that\n\t\t\t\\[\n\t\t\t\tC(y_1, \\dots, y_n) = \n\t\t\t\t\\begin{cases}\n\t\t\t\t\t\\pm 1 &  y_1 = \\dots = y_n = 0 \\\\\n\t\t\t\t\t0 & \\text{otherwise}.\n\t\t\t\t\\end{cases}\n\t\t\t\\]\n\t\t\tTo see this, note that the result is clear for $y_1 = \\dots = y_n = 0$;\n\t\t\totherwise, if WLOG $y_1 = 1$, then the terms for $x_1 = 0$ exactly cancel\n\t\t\tthe terms for $x_1 = 0$, pair by pair.\n\t\t\tThus in this state, the measurements all result in $\\ket0 \\dots \\ket0$.\n\n\t\t\t\\ii On the other hand if $f$ is balanced, we derive that\n\t\t\t\\[ C(0, \\dots, 0) = 0. \\]\n\t\t\tThus \\emph{no} measurements result in $\\ket 0 \\dots \\ket 0$.\n\t\t\\end{itemize}\n\t\tIn this way, we can tell whether $f$ is balanced or not.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{dproblem}[Barenco et al, 1995; arXiv:quant-ph/9503016v1]\n\tLet\n\t\\[\n\t\tP = \\begin{bmatrix} 1 & 0 \\\\ 0& i \\end{bmatrix} \n\t\t\\qquad\n\t\tQ = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & -i \\\\ -i & 1 \\end{bmatrix}\n\t\\]\n\tVerify that the quantum Toffoli gate can be implemented\n\tusing just controlled rotations via the circuit\n\t\\[\n\t\t\\Qcircuit @R=1em @C=0.7em {\n\t\t\t\\lstick{\\ket{x_1}} & \\qw & \\ctrl{2} & \\ctrl{1} & \\ctrl{1} & \\qw & \\ctrl{1} & \\qw \\\\\n\t\t\t\\lstick{\\ket{x_2}} & \\ctrl{1} & \\qw & \\gate{P} & \\targ & \\ctrl{1} & \\targ & \\qw \\\\\n\t\t\t\\lstick{\\ket{x_3}} & \\gate{Q} & \\gate{Q} & \\qw & \\qw & \\gate{Q^\\dagger} & \\qw & \\qw\n\t\t}\n\t\\]\n\tThis was a big surprise to researchers when discovered,\n\tbecause classical reversible logic requires three-bit gates (e.g. Toffoli, Fredkind).\n\t\\begin{hint}\n\t\tThis is direct computation.\n\t\\end{hint}\n\\end{dproblem}\n", "meta": {"hexsha": "4f2a2f4eaf2041460c65a09724117c8a62bfde40", "size": 24391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/quantum/circuits.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/circuits.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/circuits.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": 33.9707520891, "max_line_length": 100, "alphanum_fraction": 0.6328973802, "num_tokens": 9424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6703442243444055}}
{"text": "\\subsection{Data Selection and Processing}\n\nThe \\gls{uiuc} Solar Farm 1.0 dashboard provides data for the solar energy\ngenerated  on campus \\cite{alsoenergy_university_2019}. The \\gls{uiuc}\nFacilities and Services Department shared proprietary data for campus\nelectricity demand and wind energy with us \\cite{marquissee_campus_2019}. All\ndata had hourly resolution. Weather data were retrieved from the\n\\gls{noaa}\\cite{national_center_for_environmental_information_find_nodate} for\ntwo locations: Champaign, IL, where \\gls{uiuc} is located, and Lincoln, IL,\nwhere Railsplitter Windfarm is located. \\gls{uiuc} has a power purchase\nagreement with Railsplitter Windfarm \\cite{breitweiser_wind_2016}.\n\nIn the case of \\gls{uiuc} solar data, significant portions were missing due to\ninstrument failure. In order to fill in this missing data, we calculated the\ntheoretical solar energy production based on irradiance data from OpenEI\n\\cite{noauthor_national_nodate, garcia_nuclear_2015} with\n\\begin{align}\n  P &= G_T\\eta_{ref}\\tau_{pv}A\\left(1-\\gamma\\left(T-25\\right)\\right) \\text{ } \\left[W\\right]\\\\\n  \\intertext{where}\n  P &= \\text{ the total power of the solar farm}\\nonumber\\\\\n  G_T &= \\text{ the total incident solar irradiance}\\nonumber\\\\\n  &= P_{DNI}\\cos\\left(\\beta+\\delta-lat\\right)+ P_{DHI}\\left(\\frac{180-\\beta}{180}\\right) \\left[\\frac{W}{m^2}\\right]\\\\\n  \\intertext{and}\n  \\delta &= \\text{ the solar declination angle}\\nonumber\\\\\n  &= 23.44\\sin\\left(\\left(\\frac{\\pi}{180}\\right)\\left(\\frac{360}{365}\\right)(N+284)\n  \\right) \\left[^\\circ \\right]\\\\\n  \\eta_{ref} &= \\text{ conversion efficiency [-]}\\nonumber\\\\\n  \\tau_{pv} &= \\text{ transmittance [-]}\\nonumber\\\\\n  \\gamma &= \\text{ thermal coefficient [-]}\\nonumber\\\\\n  A &= \\text{ solar panel coverage  $[m^2]$}\\nonumber\\\\\n  P_{DNI}&= \\text{direct normal irradiance  $\\left[\\frac{W}{m^2}\\right]$}\\nonumber\\\\\n  P_{DHI}&= \\text{diffuse horizontal irradiance  $\\left[\\frac{W}{m^2}\\right]$}\\nonumber\\\\\n  \\beta &= \\text{tilt angle of the solar panels [$^\\circ$]}\\nonumber\\\\\\nonumber\n\\end{align}\nWe also calculated the solar elevation angle, $\\alpha$, using\ncoordinates for the \\gls{uiuc} Solar Farm 1.0\n\\cite{us_department_of_commerce_esrl_nodate, meeus_astronomical_1998},\n\\begin{align}\n  \\alpha &= \\sin^{-1}\\left[\\sin(\\delta)\\sin(\\phi)+\\cos(\\delta)\\cos(\\phi)\\cos(\\omega)\\right] \\left[^\\circ \\right]\n  \\intertext{where}\\nonumber\n  \\delta &= \\text{declination angle  [$^\\circ$]}\\\\\\nonumber\n  \\phi &= \\text{latitude of interest  [$^\\circ$]}\\\\\\nonumber\n  \\omega &= \\text{hour angle  [$^\\circ$]}\\\\\\nonumber\n\\end{align}\nFinally, we normalized all of the data using the infinity norm\n\\begin{align}\n  \\norm{\\mathbf{x}}_\\infty \\equiv \\text{max}\\left|x_i\\right|.\n\\end{align}\nThe infinity norm is equivalent to normalizing by the system capacity. This\nsimplifies the comparison of our results between\ntasks whose training data have vastly different magnitudes. This normalization\nalso makes it possible to compare results with other work and is consistent\nwith the recommendation from Kobylinski et al. (2020) \\cite{kobylinski_high-resolution_2020}. Table \\ref{tab:capacity} gives the maximum value for each\nsystem.\n\n\\begin{table}[h]\n  \\centering\n  \\caption{Description of the size of the \\gls{uiuc} microgrid}\n  \\label{tab:capacity}\n  \\begin{tabular}{l r}\n    \\hline\n    System & Maximum Value\\\\\n    \\hline\n    Electricity Demand & 81.6 [MW]\\\\\n    Solar Energy & 4.7 [MW]\\\\\n    Wind Energy & 8.8 [MW]\\\\\n    \\hline\n  \\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "2c1a12e78723f812ab6e71f39bbb9163d5524822", "size": 3480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/forecasting-paper/data.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/data.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/data.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": 49.7142857143, "max_line_length": 151, "alphanum_fraction": 0.7255747126, "num_tokens": 1077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6703442243444055}}
{"text": "\\section{Hamiltonian Mechanics}\nRecall hte Lagrangian is\n\\begin{align}\n    L = T - U\n\\end{align}\nwhich is a function $L(q_1,\\ldots,q_n, \\dot{q}_1,\\ldots,\\dot{q}_n)$.\nLet use define\n\\begin{align}\n    p_i &= \\frac{\\partial L}{\\partial q_i}\n\\end{align}\nwhere $p_i$ is called the \\emph{canonical momentum} or momentum conjugate to\n$q_i$.\nThe \\emph{Legendre transform} is\n\\begin{align}\n    H &= \\sum_i p_i \\dot{q}_i - L\n\\end{align}\nwhere $H=H(q_i, p_i)$.\n\nThe $n$ q_i$ and $n$ p_i$ define a point in a $2n$-dimensional space,\ncalled \\emph{phase space}.\nHamilton's equations determine a unique path in phase space,\nstarting from any initial point.\n\nLet's derive Hamilton's euqations for a 1D system.\n\\begin{align}\n    H &=\n    p\\dot{q}(q, p) - L\\left( q, \\dot{q}(q, p) \\right)\n\\end{align}\nThe point is that $\\dot{q}$ is determined implicitly in terms of $q$ and $p$\nby the definition of $p$.\n\\begin{align}\n    \\left(\\frac{\\partial L}{\\partial \\dot{q}}\\right)_{q} = p.\n\\end{align}\nwhere we are holding $q$ fixed in the derivative.\nLet's calculate the derivative\n\\begin{align}\n    \\left( \\frac{\\partial H}{\\partial q} \\right)_p\n    &=\n    p \\left( \\frac{\\partial\\dot{q}}{\\partial q} \\right)_p\n    - \\left[ \n    \\left( \\frac{\\partial L}{\\partial q} \\right)_p\n    \\underbrace{\\left(\\frac{\\partial q}{\\partial q}_\\right)_p}_{1}\n    +\n    \\underbrace{\\left( \\frac{\\partial L}{\\partial q} \\right)_q}_{p}\n    \\left( \\frac{\\partial \\dot{q}}{\\partial q} \\right)_p\n    \\right]\n\\end{align}\nIt's just an exercise of partial derivatives.\nYou see that one of the terms cancel.\nSo using Lagrange's equation,\n\\begin{align}\n    \\left( \\frac{\\partial H}{\\partial q} \\right)_p\n    &=\n    - \\left( \\frac{\\partial L}{\\partial q} \\right)_{\\dot{q}}\\\\\n    &=\n    -\\frac{d}{dt}\\left( \\frac{\\partial L}{\\partial \\dot{q}} \\right)_{q}\\\\\n    &= -\\frac{dp}{dt}\n\\end{align}\nwhere it's true on a classical path\n\nSimilarly,\n\\begin{align}\n    \\left( \\frac{\\partial H}{\\partial p} \\right)_{q}\n    &=\n    \\dot{q}\n    +\n    p \\left( \\frac{\\partial \\dot{q}}{\\partial p} \\right)_{q}\n    -\n    \\left[ \n    \\left( \\frac{\\partial L}{\\partial q} \\right)_{\\dot{q}}\n    \\underbrace{\\left( \\frac{\\partial q}{\\partial p} \\right)_{q}}_{0}\n    +\n    \\underbrace{\\left( \\frac{\\partial L}{\\partial \\dot{q}}\n    \\right)_{q}}_{p}\n    \\left( \\frac{\\partial \\dot{q}}{\\partial p} \\right)_{q}\n    \\right]\\\\\n    &= \\dot{q}\n\\end{align}\nAnd so we have derived Hamilton's equations\n\\begin{align}\n    \\left( \\frac{\\partial H}{\\partial q} \\right)_{p} &= -\\dot{p}\\\\\n    \\left( \\frac{\\partial H}{\\partial p} \\right)_{q} &= -\\dot{q}\n\\end{align}\nThese are first order equations.\nThis tells you how a point $(q,p)$ changes with time in phase space.\n\nIn the Lagrangian approach,\nfora system with one degrees of freedom,\nwe obtain a single second order equation.\nIn the Hamiltonian approach,\nwe obtain two first order equations.\n\n\\subsection{Atwood's Machine}\nOnce again,\nwe consider the Atwood's machine as an example.\n\nWe have a string on a pulley with two masses on its end\n$m_1$ and $m_2$.\nThe length of the string on the $m_1$ is  $x$\nand the length of the string on the $m_2$ side is $y$.\nThe constraint is that\n\\begin{align}\n    x + y = \\textrm{constant}\n\\end{align}\nwhich means the string is inextensible,\nso if one goes up the other goes down.\n\nThe Lagrangian is\n\\begin{align}\n    L &=\n    \\frac{1}{2}m_1\\dot{x}^2\n    +\n    \\frac{1}{2}m_2 \\dot{y}^2\n    - \\left( \n    -m_1 gx\n    - m_2 gy\n    \\right)\\\\\n    &=\n    \\frac{1}{2}m_1\\dot{x}^2 + \\frac{1}{2}m_2\\dot{y}^2\n    + m_1 gx + m_2gy\\\\\n    &=\n    \\frac{1}{2}\\left( m_1 + m_2 \\right) \\dot{x}^2\n    +\n    \\left( m_1 - m_2 \\right) gx\n\\end{align}\nThen we can calculte the momenta\n\\begin{align}\n    p &= \\frac{\\partial L}{\\partial x}\\\\\n    &=\n    \\left( m_1 + m_2 \\right)\\dot{x}\n\\end{align}\nand write the velocity in terms of momentum\n\\begin{align}\n    \\dot{x} &= \\frac{p}{m_1 + m_2}\n\\end{align}\nwhich we can substitute into the Lagrangian\n\\begin{align}\n    L &=\n    \\frac{1}{2} \\frac{p^2}{m_1 + m_2}\n    +\n    \\left( m_1 - m_2 \\right)gx\n\\end{align}\nso the Hamiltonian is\n\\begin{align}\n    H &= p\\dot{x} - L\\\\\n    &=\n    p \\frac{p}{m_1 + m_2} - L\\\\\n    &=\n    \\frac{1}{2}\\frac{p^2}{m_1 + m_2}\n    -\n    \\left( m_1 - m_2 \\right)gx\n\\end{align}\nUsing Hamilton's equations\n\\begin{align}\n    -\\dot{p} &= \\frac{\\partial H}{\\partial q}\\\\\n    \\dot{x} &= \\frac{\\partial H}{\\partial p}\n\\end{align}\nyou can convince yourself it gives\n\\begin{align}\n    \\dot{p} &= \\left( m_1 - m_2 \\right)g\\\\\n    \\dot{x} &= \\frac{p}{m_1 + m_2}\n\\end{align}\nDifferentiate the second equation with respect to time and we gte\n\\begin{align}\n    \\ddot{x} &=\n    \\frac{\\left( m_1 - m_2 \\right)g}{m_1 + m_2}\n\\end{align}\n\nYou could of course get the same differential equation from the Euler-Lagrange\nequations in the Lagrangian approach.\n\\begin{align}\n    \\frac{d}{dt}\\left( \\frac{\\partial L}{\\partial \\dot{x}} \\right)\n    - \\frac{\\partial L}{\\partial x} &= 0\\\\\n    \\frac{d}{dt}\\left[ \n    \\left( m_1 + m_2 \\right)x\n    \\right]\n    -\n    \\left( m_1 - m_2 \\right)g\n    &= 0\\\\\n    \\ddot{x} &=\n    \\frac{\\left( m_1 - m_2 \\right)g}{m_1 + m_2}\n\\end{align}\nWhy bother with Hamilton's equations with a fraction of the work.\n\nAfter Hamilton came up with these equations they made him a professor at Dublin\nwhen he was just an undergrad!\nSo what is the great insight of Hamilton?\n\nThe minus sign changes the symmetry from the obvious one into a more subtle\nsymmetry.\nIf you are a theoretical physicist,\nyou see they have a symplectic geometry.\nThe Hamiltonian formalism leads to a symmetry between the $p$ and $q$'s.\nYou know how much easier it is to solve a system if it has the right coordinate\nsystem?\n\nNow the fact is,\nthere is a symmetry between the coordinates and momentum,\nwhich means you have the option to choose coordaintes which are combinations of\ncoordaintes and momenta.\nYou can make transformations between coordaintes and moemnta together,\nwhich increases the choics of possible coordinates,\nwith so much more freedom to choose coordinates.\n\nThere are problems you can solve using thismethod no one knows how to solve\notherwise.\nIt's because of this greater flexibility.\nUnfortunatley,\nthere's no problem you will lsolve in this course where this is actually true.\nThat's why it's important even in classical mechanics.\nThese transformations are called \\emph{canonical transformations}.\n\n\\section{Phase space orbits}\nThe generalization of Hamilton's equations to many degrees of freedom is\n\\begin{align}\n    \\dot{q}_i &= \\frac{\\partial H}{\\partial p_i}\\\\\n    -\\dot{p}_i &= \\frac{\\partial H}{\\partial q_i}\n\\end{align}\nYou will need to remember these equatinos,\nbut it's pretty easy to remember,\njust need to know where the sign is.\nIf you can't remember,\njust consider the free particle with Hamiltonian\n$H=p^2/2m$ and so $\\partial H/\\partial q = p/m$ and $\\dot{q}=p/m$.\n\n\\begin{align}\n    \\dot{q}_i &= \\frac{\\partial H}{\\partial p_i} = f_i(q_j, p_j)\\\\\n    -\\dot{p}_i &= \\frac{\\partial H}{\\partial q_i} = g_i(q_j, p_j)\n\\end{align}\nIntroduce the $2n$ dimensional vectors\n\\begin{align}\n    \\vec{z} &=\n    \\begin{pmatrix}\n        q_1\\\\\n        \\vdots\\\\\n        q_n\\\\\n        p_1\\\\\n        \\vdots\\\\\n        p_n\n    \\end{pmatrix}\n\\end{align}\nand\n\\begin{align}\n    \\vec{h} &=\n    \\begin{pmatrix}\n        f_1(q_j, p_j)\\\\\n        \\vdots\\\\\n        f_n(q_j, p_j)\\\\\n        g_1(q_j, p_j)\\\\\n        \\vdots\\\\\n        g_n(q_j, p_j)\n    \\end{pmatrix}\n\\end{align}\nso we can write all of Hamilton's equations as\n\\begin{align}\n    \\dot{\\vec{z}} &= \\vec{h}(\\vec{z}).\n\\end{align}\nThe vector $\\vec{z}$ defines the ``position'' of the system in phase space.\n\nThere's a $2n$-dimensional phase space.\nThere's one dimension for every $p$ and one dimension for every $q$.\nIf you know what $z$ is,\nyou know the particle position in phase space at any given time,\nand this equation tells you how the particle moves in phase space as a function\nof time.\n\nLet's say you have some trajectory on phase space.\nBecause the vector $\\dot{\\vec{z}}$ is unique for a given $\\vec{z}$,\nthere should be no crossing of paths in phase space.\n\n\\subsection{Harmonic Oscillator in 1 dimension}\nThe Lagrangian is\n\\begin{align}\n    L &= \\frac{1}{2}m\\dot{x}^2 - \\frac{1}{2}kx^2\n\\end{align}\nso the Hamiltonian is\n\\begin{align}\n    H &= p\\dot{x} - L\\\\\n    &= \\frac{p^2}{m} - \\left[ \n    \\frac{1}{2}m\\left( \\frac{p}{m} \\right)^2\n    - \\frac{1}{2}kx^2\n    \\right]^2\\\\\n    &=\n    \\frac{1}{2}\\frac{p^2}{m}\n    + \\frac{1}{2}kx^2\n\\end{align}\nso Hamilton's equations gives\n\\begin{align}\n    \\frac{\\partial H}{\\partial p} &= \\dot{x}\n    &\\implies\n    \\frac{p}{m} &= \\dot{x}\\\\\n    \\frac{\\partial H}{\\partial q} &= -\\dot{p}\n    &\\implies\n    kx &= -\\dot{p}\n\\end{align}\nEliminating $p$,\nwe get\n\\begin{align}\n    m\\ddot{x} &= -kx\n\\end{align}\nand if we define $\\omega^2 = k/m$,\nwe get the solution\n\\begin{align}\n    x &= A \\cos(\\omega t - \\eta)\\\\\n    p &= m\\dot{x} = - mA\\omega \\sin(\\omega t - \\eta)\n\\end{align}\nThe phase space for the harmonic oscillator is the 2D space with coordinates\n$(x,p)$.\nAs time changes,\nthe particle traces out a path in phase space,\ncalled the \\emph{orbit} in phase space.\nDespite the name, it's generally not a closed path.\n\nFor a Harmonic oscillator in 1 dimensions,\nthe orbit is an ellipse\n\\begin{align}\n    \\frac{x^2}{A^2} + \\frac{p^2}{mA^2\\omega^2} &= 1\n\\end{align}\nand it's going clockwise.\n\n\\section{About the Midterm}\nI've written the exam already.\nIf you did the homework,\nunderstand how to solve those problems,\nit should be quite straightforward to get 50\\% very easily.\nI think it's an exam where to get 100\\% is not easy,\nto get 90\\% is tough.\nSome questions are straightforward,\nbut some are had.\nAll carry equal points.\nIt's not that easy questions are first.\nYou can read the exam,\nrecognise the questions.\nMake sure you do the ones you know how to do.\nIn the end,\nthe most important thing is to pass.\nNail all those you know.\nOnce you're confident they're right,\nspend time on the tough ones.\n\nYou need to memorize the formula for the Method of Steepest descent.\nThere is no cheat sheet.\n\nIt's not like the qualifier,\nwhere you need to know\nall of classical, all of quantum, and you have to pass them all at once,\nor some BS like that.\nTrust me, the midterm is much easier than being tested on all of physics.\n\nThe questions are like this.\n2 from the first homework, 2 from the second homework and 2 from the last.\nAll questions are are of equal weight.\nOn Thursday, try to get here early!\nClass is 9:30 to 11:20 but try to get here early.\nI will hand out the question papers early enough so you begin exactly at 09:30.\nYou can look at the question paper before that,\nbut you can only start writing at 09:30.\n\nI will try to provide paper,\nbut just in case bring your own.\n\nI suggest spending time doing the homework problems,\nmake sure you can absolutely do all the homework problems.\nOnce you've done that,\nlook at all the worked examples I did in class.\nThat's basic preparation.\nIf you have time beyond that,\nthere's all those books,\nsome of them have problems,\nlook through the problems and see if you know how to do those problems.\n\nDo we need a calculator?\nI don't think you should need a calculator.\n\nAre we scanning or handing in physical paper at the end?\nI'm thinking of handing in physical paper,\nbecause it will take you 10 minutes of scanning.\n\nA calculator might be useful for binomial coefficients,\nbut you can calculate the first 2 or 3.\nYou'll get some points for sure.\n\nWill we be given the contours to integrate over?\nChoosing contour shapes, should we learn?\nLook very carefully through all the homework problems.\nI'm not going to tell you which contour to choose,\nyou're going to have to figure it out yourself.\nThat's important.\n\nWill the mapping for mapping problems be provided?\nThe choice of mapping will be provided.\n\nAlso, one last thing, there's a new set of notes online.\n", "meta": {"hexsha": "4c42895286b1d8740507089627f39e8a7280dc5e", "size": 11829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture15.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/lecture15.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/lecture15.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.0228426396, "max_line_length": 79, "alphanum_fraction": 0.6755431566, "num_tokens": 3759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6703442224546078}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Alex Li}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\nLe plus court chemin entre deux v\\'erit\\'es dans le domaine r\\'eel passe par le domaine complexe.\n%The shortest path between two truths in the real domain passes through the complex domain.\n\\byline{Jacques Hadamard}\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  Define $\\C$.  (How many ``different'' definitions do you know?)\n\\end{problem}\\\\\n\\begin{solution}\nThe complex numbers $\\C = \\{S, +, *\\}$ are a ring (in fact a field) defined as follows:\n\\begin{align*}\nS &= \\{(a, b): a\\in \\mathbb{R}, b\\in \\mathbb{R}\\}\\\\\n+ &: (x_1, x_2) \\in S, (y_1, y_2) \\in S \\mapsto (x_1 + y_1, x_2 + y_2)\\\\\n* &: (x_1, x_2) \\in S, (y_1, y_2) \\in S \\mapsto (x_1y_1 - x_2y_2, x_1y_2 + x_2    y_1)\n\\end{align*}\nWe use the shorthand $a, a\\in\\R$ to denote $(a, 0)$ and $ai, a\\in \\R$ to denote $(0, a)$.\n\\\\\nA second definition:\n$$\\C = \\R[x]/x^2 + 1$$\n\\\\\n\\end{solution}\n\\begin{problem}\n  Define $\\conj{z}$ and $\\abs{z}$ for $z \\in \\C$.\n\\end{problem}\n\\begin{solution}\nFor $a+bi=z$, $\\conj{z}=a-bi$ and $\\abs{z}=\\sqrt{z\\conj{z}}$.\n\\end{solution}\n\n\\begin{problem}\nFor complex numbers $z, w \\in \\C$, what do we mean by $z^w$ ?\n\\end{problem}\n\\begin{solution}\n$e^x$ for any complex number $x$ is defined by the power series of the $\\exp$ function evaluated at $x$.\n\n$z^w$ is defined to be $e^{w \\Log z}$, where $\\Log z = a+bi$ is the unique complex number with $b\\in(-\\pi, \\pi]$ such that $a = \\log|z|$ and $b$ is the counterclockwise angle $z$ makes with $(1,0)$ in radians.\n\\end{solution}\n\n\\section{Numericals}\n\\begin{problem}\nApply \\textbf{partial fractions} to write $\\displaystyle\\frac{1}{1-z^4}$ as a sum of terms of the form $\\displaystyle\\frac{A}{Bz + C}$.\n\\end{problem}\n\\begin{solution}\nFirst note that we can factor $(1-z^4)$ as $(1-z)(1+z)(1-iz)(1+iz)$. Now let's find coefficients so that \n$$\\frac{1}{1-z^4} = \\frac{A_1}{1-z} + \\frac{A_2}{1+z} + \\frac{A_3}{1-iz} + \\frac{A_4}{1+iz}$$\n\nMultiplying throughout by $1-z^4$,\n\\begin{align*}\n1 &= A_1(1+z)(1+z^2) + A_2(1-z)(1+z^2) + A_3(1-z^2)(1+iz) + A_4(1-iz)(1-z^2)\\\\\n1 &= A_1(1+z+z^2+z^3) + A_2(1-z+z^2-z^3) \\\\&+A_3(1+iz-z^2-iz^3) + A_4(1-iz-z^2+iz^3)\\\\\n\\end{align*}\nEquating coefficients,\n\\begin{align}\n1 &= A_1+A_2+A_3+A_4\\\\\n0z &= (A_1 - A_2 + iA_3 - iA_4)z\\\\\n0z^2 &= (A_1 + A_2 - A_3 - A_4)z^2\\\\\n0z^3 &= (A_1 - A_2 - iA_3 + iA_4)z^3\n\\end{align}\nGiving us a linear system of equations. We get that\n\\begin{align}\n\\begin{pmatrix}1&1&1&1\\\\1&-1&i&-i\\\\1&1&-1&-1\\\\1&-1&-i&i\\\\\\end{pmatrix}^{-1}\n\\begin{pmatrix}1\\\\0\\\\0\\\\0\\end{pmatrix} = \\begin{pmatrix}\nA_1\\\\A_2\\\\A_3\\\\A_4\\end{pmatrix}\n\\end{align}\nAnd solving, \n$$\\frac{1}{1-z^4} = \\frac{\\frac{1}{4}}{1-z} + \\frac{\\frac{1}{4}}{1+z} + \\frac{\\frac{1}{4}}{1-iz} + \\frac{\\frac{1}{4}}{1+iz}$$\n\\end{solution}\n\\begin{problem}\n  Find $a, b, z \\in \\C$ so that $\\left(z^a\\right)^b \\neq z^{\\left(ab\\right)}$.\n\\end{problem}\n\\begin{solution}\nLet $z=e, a=2\\pi i, b=i$. Then \n\\[\nz^{ab} = e^{-2\\pi},\n\\]\n\\[(z^{a})^b = (e^{2\\pi i})^i = e^{i\\Log{(e^{2\\pi i})}} = e^{i{0}} = 1\\]\nAnd clearly, $1\\neq e^{-2\\pi}$.\n\\end{solution}\n\\begin{problem}\n  We will often see \\textbf{roots of unity}.  To practice computing with such objects, let\n  \\[\n    \\zeta := \\cos \\left( \\frac{2\\pi}{7} \\right) + i \\, \\sin \\left( \\frac{2\\pi}{7} \\right) \\mbox{ and }\n    r := \\zeta + \\zeta^2 - \\zeta^3 + \\zeta^4 - \\zeta^5 - \\zeta^6.\n  \\]\n  Find the integer $r^2$.  (This surprise is a \\textbf{Gauss sum}.)\n\\end{problem}\n\\begin{solution}\n\\begin{align*}\nr^2 &= (\\zeta + \\zeta^2 - \\zeta^3 + \\zeta^4 - \\zeta^5 - \\zeta^6)(\\zeta + \\zeta^2 - \\zeta^3 + \\zeta^4 - \\zeta^5 - \\zeta^6)\\\\\n&= \\zeta^2 + 2\\zeta^3 - \\zeta^4 + \\zeta^6 - 6\\zeta^7 + \\zeta^8 - \\zeta^{10} + 2\\zeta^{11} + \\zeta^{12}\\\\\n&= \\zeta + \\zeta^2 + \\zeta^3 + \\zeta^4 + \\zeta^5 + \\zeta^6 - 6\\\\\n&= -7\n\\end{align*}\n\\end{solution}\n\\begin{problem}\nFor which $z \\in \\mathbb{C}$ is it the case that $\\log \\left( e^z \\right) = z$?  \\\\ (What do we mean when we write $\\log$ here?)\n\\end{problem}\n\\begin{solution}\nIf $\\log z$ has only one value, then it's implied that it's the prinipal log - the value for which $\\log z$ is the inverse of $e^z$ and $\\log z$ has an imaginary part in $(-\\pi, \\pi]$. Then by defintion, any value $z = a+bi, b\\in (-\\pi, \\pi]$ satisfies the equation. Conversely, if $b$ is not in this interval, then $\\log(e^z)$ will have imaginary part in the interval $(-\\pi, \\pi)$, so the equation will not be satisfied.\n\\end{solution}\n\\section{Exploration}\n\n\\begin{problem}\n  Let's review some linear algebra.  Define $J(x,y) = (y,-x)$ so $J$\n  is counter-clockwise rotation by $90^\\circ$, and suppose\n  $T : \\R^2 \\to \\R^2$ is a linear transformation with the property\n  that $T \\circ J = J \\circ T$.  Can you relate $T$ to the complex\n  numbers?\n\\end{problem}\n\\begin{solution}\n$J$ sounds like multiplication by $i$ in that multiplying $(a,b)=a+bi$ by $i$ gives the complex number $J\\begin{pmatrix}a\\\\b\\end{pmatrix}$. All complex numbers commute with $i$, so letting $T'$ be set of the linear transformations obtained from multiplying by any complex number, we must have $T'\\subset T$. Any element in $T'$ is a linear combination of multiplying by the identity matrix (adding 1) and multiplying by $J$ (adding i), so it's a 2 dimensional vector space.\n\nWe might hope that the opposite is also true, $T\\subset T'$. Let's check.\n\n\\begin{align*}\nT\\circ J = J \\circ T& \\implies \\begin{pmatrix}c&d\\\\e&f\\end{pmatrix} \\begin{pmatrix}0&1\\\\-1&0\\end{pmatrix} = \\begin{pmatrix}0&1\\\\-1&0\\end{pmatrix}  \\begin{pmatrix}c&d\\\\e&f\\end{pmatrix}\\\\\n& \\implies \\begin{pmatrix}-d&c\\\\-f&e\\end{pmatrix} = \\begin{pmatrix}e&f\\\\-c&-d\\end{pmatrix}\\\\\n\\end{align*}\nSo we must have $d=-e$ and $c=f$, and thus $T$ is a 2 dimensional subspace of $2\\times 2$ matricies. As both $T$ and $T'$ are 2 dimensional vector spaces, they are the same.\n\\end{solution}\n\n\\begin{problem}\\label{mobius-transformations}Here is another connection to linear algebra.  Suppose we have complex-valued functions\n  \\[\n    f(z) = \\frac{az + b}{cz + d} \\mbox{ and }\n    F(z) = \\frac{Az + B}{Cz + D}.\n  \\]\n  Such functions are \\textbf{M\\\"obius transformations}.  Relate the\n  function $f \\circ F$ to a product of certain matrices.\n\\end{problem}\n\\begin{solution}\n\\begin{align*}\nf \\circ F &= \\frac{a(\\frac{Az + B}{Cz + D}) + b}{c(\\frac{Az + B}{Cz + D}) + d}\\\\\n&= \\frac{aAz + aB + bCz + bD}{cAz+cB+dCz+Dd}\\\\\n&= \\frac{(aA + bC)z + (aB + bD)}{(cA+dC)z+(cB+Dd)}\n\\end{align*}\nAssociate to a symbolic expression of the from $\\frac{wz + x}{yz+z}$ the matrix $\\begin{pmatrix}w&x\\\\y&z\\end{pmatrix}.$\nThen the associated matrix of $f$ times the associated matrix of $F$ is the matrix associated with $f\\circ F$.\n\\end{solution}\n\\begin{problem}\\label{abels-theorem}Let's review some real analysis.  Consider a sequence $(a_n)$ of real number so that $\\sum_{n=0}^\\infty a_n$ converges to $L$.  Does the one-sided limit\n  \\[\n    L' = \\lim_{x \\to 1^{-}} \\sum_{n=0}^\\infty a_n x^n\n  \\]\n  also equal $L$?  See \\textbf{Abel's theorem}.\n\\end{problem}\n\\begin{solution}\n% Got stuck and took this solution from \n% https://sites.math.washington.edu/~morrow/335_16/AbelLaplace.pdf\nFirst let's show the limit exists. When $x > 0$, since $\\sum a_n$ converges to $L$, $\\forall \\epsilon>0 \\exists N s.t. \\forall n > N, |a_n| < \\epsilon.$ Then $|\\sum_{n=N}^\\infty a_nx^n| < \\sum_{n=N}^\\infty \\epsilon|x^n| < \\epsilon\\frac{1}{1-x}$, which converges for $x\\in (0, 1].$\n\nDefine $s_n = \\sum_{n=0}^n a_n$. We consider the sum $\\sum_{n=0}^\\infty s_nx^n$, noting that this converges for fixed $x$ by comparison to a geometric series since $s_n$ approaches the constant $L$.\n\\begin{align*}\nL' &= \\sum_{i=0}^\\infty (s_n-s_{n-1})x^n\\\\\n&=  \\sum_{i=0}^\\infty s_nx^n - x\\sum_{i=0}^\\infty s_{n}x^n\n= (1-x)\\sum_{i=0}^\\infty s_nx^n\\\\\n&= (1-x)\\sum_{i=0}^\\infty s_nx^n + (L - L(1-x)\\sum_{i=0}^\\infty x^n) &\\color{red}\\text{note: } (1-x)\\sum_{i=0}^\\infty x^n=1\\\\\n&= (1-x)\\sum_{i=0}^\\infty (s_n - L)x^n + L\n\\end{align*}\n\nSince $s_n$ converges to $L$,  $\\exists N>n$ such that $|s_n - L| < \\epsilon/2$.\n\\begin{align*}\n|L' - L| &= (1 - x)\\sum_0^\\infty (s_n - L)x^n\\\\\n&= (1 - x)\\sum_0^N (s_n - L)x^n + (1 - x)\\sum_{N+1}^\\infty (s_n - L)x^n \\\\\n&\\leq (1 - x)\\sum_0^N (s_n - L)x^n + (1 - x)\\sum_{N+1}^\\infty x^n \\epsilon/2\\\\\n&\\leq (1 - x)\\sum_0^N (s_n - L)x^n + \\epsilon/2\n\\end{align*}\n\nBy choosing $x$ to be very close to 1, we can make the first $N$ terms less than $\\epsilon/2$, since it's a finite polynomial with a root at 0, and so $|L' - L| \\leq \\epsilon$ for all positive $\\epsilon$, proving the claim.\n\n\n\\end{solution}\n\\begin{problem}\\label{harmonic-function}\n  For an open subset $U \\subset \\R^2$, a \\textbf{harmonic function} $f : U \\to \\R$ is a twice continuously differential function satisfying the Laplace's equation\n  \\[\n    \\frac{\\partial^2 f}{\\partial x^2} + \\frac{\\partial^2 f}{\\partial y^2} = 0.\n  \\]\n  Suppose $f(x,y) = Ax^3 + Bx^2 y + C xy^2 + D y^3$ is harmonic for constants $A, B, C, D \\in \\R$.  Relate $f$ to $z \\cdot (x + iy)^3$.\n\\end{problem}\n\\begin{solution}\nSince $f$ satisfies the Laplace equation, it must be that\n\\begin{align*}\n  [6Ax+2By] + [2Cx + 6Dy] = 0\n\\end{align*}\nThen the following 2 equations must be satisfied:\n\\begin{align*}\n3A = -C\\\\\n3D = -B\n\\end{align*}\n\nNote that the coefficients of\n\\[\n(x+iy)^3 = x^3 + 3ix^2y - 3xy^2 - iy^3\n\\]\nsatisfy these two constraints, and they continue to be satisfied after multiplication by $z$. Furthermore, if we take the real part of the coefficients, the constraints (which involve scaling by real numbers) will still be satisified, and furthermore it's easy to see that every solution can be obtained in this way.\nSo there is a bijection from points $z$ on the complex plane to the set of valid $f$ made by multiplying $z$ by $(x+iy)^3$ and taking the real part of every coefficient.\n\n\\end{solution}\n\\section{Prove or Disprove and Salvage if Possible (PODASIP)}\n\n\\begin{problem}\\label{blaschke-factors}\n  Suppose $w \\in \\C$ and $\\abs{w} < 1$.  Define a function by the rule\n  \\[\n    f(z) = \\frac{w - z}{1 - \\conj{w}z}.\n  \\]\n  If $\\abs{z} < 1$, then $\\abs{f(z)} < 1$.  (These are \\textbf{Blaschke factors}.)\n\\end{problem}\n\\begin{solution}\nThis is true, provided that $z\\in(\\C/\\conj{w}^{-1})$ (so the denominator is nonzero).\nIf $\\abs{f(z)} < 1$, then multiplying by the denominator and squaring gives\n\\begin{align*}\n|1-\\conj{w}z|^2 > |w-z|^2\\\\\n(1-\\conj{w}z)(1-w\\conj{z}) > (w-z)(\\conj{w}-\\conj{z}) \\\\\n(1-\\conj{w}z-w\\conj{z}+|\\conj{w}z|) > |w|^2 + -\\conj{w}z - w\\conj{z}+ |z|^2\\\\\n1 + |\\conj{w}z|^2 > |w|^2 + |z|^2 \\\\\n1 - |w|^2 - |z|^2 + |w||z|^2 > 0\\\\\n(1 - |w|^2)(1 - |z|^2) > 0\n\\end{align*}\nAnd this is evidently true.\n\\end{solution}\n\n\\begin{problem}\\label{C-complete} % you may assume R is complete.\n  The field $\\mathbb{C}$ is complete.\n\\end{problem}\n\\begin{solution}\nLet $a_j + ib_j;j\\in \\mathbb{R}$ be a cauchy sequence of complex numbers. Then $\\forall \\epsilon \\exists N s.t. j, k > N \\implies |(a_j - a_k) + i(b_j - b_k)| < \\epsilon.$ Thus \n$(a_j-a_k)^2 + (b_j - b_k)^2 < \\epsilon$\nand so\n$(a_j-a_k)^2 < \\epsilon \\land (b_j - b_k)^2 < \\epsilon.$\nThus the $a_i$ and $b_i$ are both cauchy sequences of real numbers. Since the real numbers are complete, we can find $N$ so that the $a_i$ approach some real number $L_1$ within $\\epsilon$ and the $b_i$ approach some real number $L_2$ within $\\epsilon$. So the norm of points after the $N$th point is $|(a_i - L_1) + i(b_i-L_2)| \\leq \\epsilon^2 + \\epsilon^2$, which can be made arbitrarily small.\n\\end{solution}\n\\begin{problem}\n For all $z, w \\in \\C$ it is the case that $\\sqrt{z} \\sqrt{w} = \\sqrt{zw}$.\n\\end{problem}\n\\begin{solution}\nFalse. Let $z=w=-i$. Then \n\\[(\\sqrt{-i})^2 = \\left(e^{(\\frac{1}{2}\\Log(-i)}\\right)^2 = \\left(e^{\\frac{-i\\pi}{4}}\\right)^2 = -i\\]\nBut $\\sqrt{-i*-i} = \\sqrt{-1} = i$.\n\nA salvage is to say that $\\sqrt{z} \\sqrt{w} = \\pm\\sqrt{zw}.$ Let $z=e^{a+bi}, w=e^{c+di}$. Then\n\\begin{align*}\n\\sqrt{zw} &= \\exp\\left(\\frac{\\Log e^{a+c+(b+d)i}}{2}\\right)\\\\\n&= \\exp\\left(\\frac{a+c + (b+d)i + 2i\\pi k_1}{2}\\right)\\\\\n&= \\exp\\left(\\frac{a+c + (b+d)i}{2} + i\\pi k_1\\right)\\\\\n\\end{align*}\nfor $k_1\\in\\Z$, and similarly\n\\begin{align*}\n\\sqrt{z}\\sqrt{w} &= (\\exp\\frac{a+bi + 2i\\pi k_2}{2})(\\exp\\frac{c+di + 2i\\pi k_3}{2}) = \\exp\\left(\\frac{a+c + (b+d)i}{2} + i\\pi (k_2 + k_3)\\right)\n\\end{align*}\nfor $k_2, k_3 \\in \\Z$. The only difference in these equations is the choice of $k_1,k_2,k_3$, which changes only the sign.\n\\end{solution}\n\\begin{problem} % missing non-empty, compact\n  Suppose $K_1 \\supset K_2 \\supset \\cdots$ be nested subsets of $\\C$ so that $\\diam K_n < 1/2^n$.  Then\n  \\[\n    \\bigcap_{n=1}^\\infty K_n\n  \\]\n  is non-empty and consists of a single point.\n\\end{problem}\n\\begin{solution}\nFalse, let $K_1 = \\emptyset$. To salvage, we assume that each $K_n$ is nonempty and furthermore compact.\n\nFirst, note that no more than 1 point can be inside of the intersection - if there are two or more points, there is a pair of distance $d$ apart, but we can choose $n$ such that $\\diam K_n < 1/2^n < d$, so it cannot contain both points.\n\nConsider the sequence $c_n$ of complex numbers defined by choosing $c_n$ as an arbitrary point in $K_n$. $c_n$ is a Cauchy sequence since the distance between points gets arbitrarily small (less than $\\frac{1}{2}^N$ after the $N$th point.) Since $\\C$ is complete \\ref{C-complete}, the limit point exists, and we will show it is contained in the intersection.\n\nIt suffices to show that the limit point is contained in $K_i$ for arbitrary $i$. Since every point of $c_n$ after the $i$th is contained in $K_n$, $c_n$ is Cauchy, and $K_n$ is compact, the limit point is contained in $K_n$.\n\\end{solution}\n\n\\begin{problem}\n For all $a, b, z \\in \\C$ it is the case that $z^a \\, z^b = z^{a+b}$.\n\\end{problem}\n\\begin{solution}\nTrue.\n\\[\nz^az^b = e^{a\\Log{z}}e^{b\\Log{z}} = e^{(a+b)\\Log{z}} = z^{a+b}\n\\]\n\\end{solution}\n\n\n\\begin{problem}\\label{cross-ratio}\n  Define the \\textbf{cross-ratio} of distinct complex numbers $z_1,z_2,z_3,z_4 \\in \\C$ by\n\\[\n\\left(z_1,z_2;z_3,z_4\\right):=\\frac {\\left(z_3-z_1\\right)\\,\\left(z_4-z_2\\right)}{\\left(z_3-z_2\\right)\\,\\left(z_4-z_1\\right)}.\n \\]\n If $f$ is a M\\\"obius transformation (cf.~\\ref{mobius-transformations}), then\n \\[\n   \\left(z_1,z_2;z_3,z_4\\right) =\n   \\left(f(z_1),f(z_2);f(z_3),f(z_4)\\right).\n\\]\n\\end{problem}\n\\begin{solution}\nLet's plug it into the mobius tranformation $f(z) = \\frac{az + b}{cz + d}$ and see.\n\\[\n\\left(f(z_1),f(z_2);f(z_3),f(z_4)\\right) = \n\\frac{\n(\\frac{az_3+b}{cz_3+d} - \\frac{az_1+b}{cz_1+d})(\\frac{az_4+b}{cz_4+d} - \\frac{az_2+b}{cz_2+d})\n}{\n(\\frac{az_3+b}{cz_3+d}-\\frac{az_2+b}{cz_2+d})(\\frac{az_4+b}{cz_4+d}-\\frac{az_1+b}{cz_1+d})\n}\n\\]\nNow multiply top and bottom by $\\prod_{i=1}^4 cz_i + d.$\n\\begin{align*}\n&=\\frac{\n[(az_3 + b)(cz_1+d) - (az_1 + b)(cz_3 + d)][(az_4 + b)(cz_2+d) - (az_2 + b)(cz_4 + d)]\n}{\n[(az_3 + b)(cz_2+d) - (az_2 + b)(cz_3 + d)][(az_4 + b)(cz_1+d) - (az_1 + b)(cz_4 + d)]\n}\\\\\n&=\\frac{\n((ad-bc)z_3 + (bc-ad)z_1)((ad-bc)z_4 + (bc-ad)z_2)\n}{\n((ad-bc)z_3 + (bc-ad)z_2)((ad-bc)z_4 + (bc-ad)z_1)\n}\\\\\n&= \\frac{(z_3 - z_1)(z_4-z_2)}{(z_3-z_2)(z_4 - z_1)}\n\\end{align*}\nOk that looks the same to me, must be true.\n\\end{solution}\n\n\\end{document}\n\n", "meta": {"hexsha": "66c5f9ecbcaebd28c1128b4021356628f02f4507", "size": 15110, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol1.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/sol1.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/sol1.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": 46.0670731707, "max_line_length": 473, "alphanum_fraction": 0.6336201191, "num_tokens": 6077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6703238753919283}}
{"text": "\\documentclass{article}\n\n% Packages\n\\usepackage[a4paper]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{progproving}\n\\usepackage{listings}\n\n\\geometry{top=25mm,bottom=25mm,inner=25mm,outer=20mm}\n\\allowdisplaybreaks\n\n\\begin{document}\n\\title{ProgProving package : Example}\n\n\\author{BERG Lucas}\n\n\\maketitle\n\n\\section{Introduction}\n    This document is an example for the ProgProving package. We will prove the following function :\n\n    \\begin{lstlisting}[language=C]\nint sum(int array[], int length) {\n    int total = 0;\n    int i = 0;\n    while (i < length) {\n        total = total + array[i];\n        i = i + 1;\n    }\n    return total;\n}\n    \\end{lstlisting}\n\n\\section{Specifications}\n    First, let's write the specifications of the function.\n    \n    \\subsection{Header}\n        \\begin{lstlisting}[language=C]\nint sum(int array[], int length)\n        \\end{lstlisting}\n    \n    \\subsection{Environment}\n        /\n    \n    \\subsection{Preconditions}\n        \\begin{flalign*}\n            & \\pre = \\state{\n                0 \\leq length = \\text{size of array[]}\n            } &\n        \\end{flalign*}\n    \n    \\subsection{Postconditions}\n        \\begin{flalign*}\n            & \\post = \\state{\n                & length = length_0 \\wedge \\\\\n                & array = array_0 \\wedge \\\\\n                & sum = \\sum^{length-1}_{j=0} array[j]\n            } &\n        \\end{flalign*}\n\n\\section{Proof using the strongest postcondition (sp)}\n    \\subsection{Definitions}\n        \\begin{flalign*}\n            & \\init \\equiv\n                \\begin{aligned}\n                    & total := 0; \\\\\n                    & i := 0;\n                \\end{aligned}\n            & \\\\\n            & \\iter \\equiv \n                \\begin{aligned}\n                    & total := total + array[i]; \\\\\n                    & i := i + 1;\n                \\end{aligned}\n            & \\\\\n            & \\term \\equiv  sum := total; & \\\\\n            & \\text{Loop condition} : \\cond \\equiv i < length & \\\\\n            & \\text{Loop preconditions} : \\lpre = \\state{\n                & 0 \\leq length = \\text{size of array[]} \\wedge \\\\\n                & total = 0 \\wedge \\\\\n                & i = 0\n            } &\n        \\end{flalign*}\n    \n    \\subsection{Find the loop invariant}\n        First, we need to find the loop invariant. In most cases, the invariant will describe the state of the loop using i-1. In our case, the invariant is :\n        \\begin{flalign*}\n            & \\inv = \\state{\n                & 0 \\leq i \\leq length \\wedge \\\\\n                & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                & length = length_0 \\wedge \\\\\n                & array = array_0\n            } &\n        \\end{flalign*}\n    \n    \\subsection{Proof that $\\inv$ is an invariant}\n        Now, we have to prove $\\{ \\inv \\wedge \\cond \\} \\iter \\{ \\inv \\}$. If we can prove that, this means that the invariant is correct.\n        First, let's define $\\inv \\wedge \\cond$\n        \\begin{flalign*}\n            & \\inv \\wedge \\cond = \\state{\n                & 0 \\leq i \\leq length \\wedge \\\\\n                & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                & length = length_0 \\wedge \\\\\n                & array = array_0\n            } \\wedge \\state{\n                i < length\n            } = \\state{\n                & 0 \\leq i < length \\wedge \\\\\n                & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                & length = length_0 \\wedge \\\\\n                & array = array_0\n            } &\n        \\end{flalign*}\n\n        Then, we can do a sp to check if $\\inv$ is an invariant.\n\n        \\begin{flalign*}\n                & \\ppsp{\\iter}{\\inv \\wedge \\cond} & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    \\begin{aligned}\n                        & total := total + array[i]; \\\\\n                        & i := i + 1;\n                    \\end{aligned}\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    i := i + 1;\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }[total/total']\n                    \\wedge\n                    \\state{\n                        total := total + array[i]\n                    }[total/total']\n                } & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    i := i + 1;\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total' = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                    \\wedge\n                    \\state{\n                        total = total' + array[i]\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    i := i + 1;\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total' = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                    \\wedge\n                    \\state{\n                        total - array[i] = total'\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    i := i + 1;\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total - array[i] = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    i := i + 1;\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total = (\\sum^{i-1}_{j = 0} array[j]) + array[i] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    i := i + 1;\n                }{\n                    \\state{\n                        & 0 \\leq i < length \\wedge \\\\\n                        & total = \\sum^{i}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & 0 \\leq i < length \\wedge \\\\\n                    & total = \\sum^{i}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                }[i/i'] \\wedge \\state{\n                    i := i + 1\n                }[i/i'] & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & 0 \\leq i' < length \\wedge \\\\\n                    & total = \\sum^{i'}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } \\wedge \\state{\n                    i = i' + 1\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & 0 \\leq i' < length \\wedge \\\\\n                    & total = \\sum^{i'}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } \\wedge \\state{\n                    i - 1 = i'\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & 0 \\leq i-1 < length \\wedge \\\\\n                    & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & 0 < i \\leq length \\wedge \\\\\n                    & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } & \\\\\n            %\n            %\n            %\n            & \\Rightarrow \\inv &\n        \\end{flalign*}\n\n        All right, the invariant is correct so we can move on to the next step.\n    \n    \\subsection{Proof that $\\inv$ is strong enough}\n        The next step is to prove that the invariant is true before the loop so we need to prove $\\lpre \\Rightarrow \\inv$.\n\n        \\begin{flalign*}\n            \\lpre = & \\state{\n                        & 0 \\leq length = \\text{size of array[]} \\wedge \\\\\n                        & total = 0 \\wedge \\\\\n                        & i = 0\n                    } & \\\\\n            %\n            %\n            %\n                  = & \\state{\n                        & 0 = i \\leq length = \\text{size of array[]} \\wedge \\\\\n                        & total = \\sum^{-1}_{j = 0} array[j] = 0\n                    } & \\\\\n            %\n            %\n            %\n                    & \\Rightarrow \\inv\n        \\end{flalign*}\n\n        All right, the invariant is strong enough so we can move on to the next step.\n\n    \\subsection{Proof that the program will return the postconditions after the loop}\n        The next step is to prove that the program will return the postconditions after the loop so we need to prove $\\{ \\inv \\wedge \\neg \\cond \\} \\term \\{ \\post \\}$.\n        First, let's define $\\inv \\wedge \\neg \\cond$\n        \\begin{flalign*}\n            \\inv \\wedge \\neg \\cond & = \\state{\n                & 0 \\leq i \\leq length \\wedge \\\\\n                & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                & length = length_0 \\wedge \\\\\n                & array = array_0\n            } \\wedge \\state{\n                i \\geq length\n            } = \\state{\n                & i = length \\wedge \\\\\n                & total = \\sum^{i-1}_{j = 0} array[j] \\wedge \\\\\n                & length = length_0 \\wedge \\\\\n                & array = array_0\n            } & \\\\\n            & = \\state{\n                & total = \\sum^{length-1}_{j = 0} array[j] \\wedge \\\\\n                & length = length_0 \\wedge \\\\\n                & array = array_0\n            } &\n        \\end{flalign*}\n\n        Then, we can do a sp.\n\n        \\begin{flalign*}\n                & \\ppsp{\\term}{\\inv \\wedge \\neg \\cond} & \\\\\n            %\n            %\n            %\n            =   & \\ppsp{\n                    sum := total;\n                }{\n                    \\state{\n                        & total = \\sum^{length-1}_{j = 0} array[j] \\wedge \\\\\n                        & length = length_0 \\wedge \\\\\n                        & array = array_0\n                    }\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & total = \\sum^{length-1}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } \\wedge \\state{\n                    sum := total;\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & total = \\sum^{length-1}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } \\wedge \\state{\n                    sum = total;\n                } & \\\\\n            %\n            %\n            %\n            =   & \\state{\n                    & sum = \\sum^{length-1}_{j = 0} array[j] \\wedge \\\\\n                    & length = length_0 \\wedge \\\\\n                    & array = array_0\n                } & \\\\\n            %\n            %\n            %\n            & \\Rightarrow \\post &\n        \\end{flalign*}\n\n        Everything is proved so the program is correct.\n\\end{document}", "meta": {"hexsha": "80c0dbd6ae956ba9b493bfac223621a96e6524b6", "size": 12444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example.tex", "max_stars_repo_name": "BergLucas/ProgProving", "max_stars_repo_head_hexsha": "9ccb43e8d4e485ce62168d0a4b6042d019cd00ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T13:45:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T13:45:25.000Z", "max_issues_repo_path": "example.tex", "max_issues_repo_name": "BergLucas/ProgProving", "max_issues_repo_head_hexsha": "9ccb43e8d4e485ce62168d0a4b6042d019cd00ff", "max_issues_repo_licenses": ["MIT"], "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": "BergLucas/ProgProving", "max_forks_repo_head_hexsha": "9ccb43e8d4e485ce62168d0a4b6042d019cd00ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-21T20:51:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T20:51:32.000Z", "avg_line_length": 32.40625, "max_line_length": 166, "alphanum_fraction": 0.3423336548, "num_tokens": 3040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.6703238719328735}}
{"text": "\\subsubsection{Second Order Variation of Parameters}\r\n\\noindent\r\nWe'll modify our second order equation of have a 1 as the coefficient of the $y''$ term by dividing to get an equation of the form\r\n\\begin{equation*}\r\n\ty'' + py' + qy = g(x)\r\n\\end{equation*}\r\nJust like for undetermined coefficients, we'll find homogeneous and particular solutions $y = y_h + y_p$. Since the equation is second-order, the solution to the homogeneous equation will yield two fundamental solutions $y_1$ and $y_2$ where $y_h = C_1y_1 + C_2y_2$.\\\\\r\n\r\n\\noindent\r\nSo, we can write $y$ as\r\n\\begin{equation*}\r\n\ty(x) = A(x)y_1 + B(x)y_2\r\n\\end{equation*}\r\nwhere\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tA'y_1  + B'y_2  = 0 \\\\\r\n\t\tA'y_1' + B'y_2' = g(x)\r\n\t\\end{cases}\r\n\\end{equation*}\r\nWe will then solve this system to solve for $A'$ and $B'$ and integrate.\r\n\r\n\\ifodd\\includeHigherOrderExamples\\input{./higherOrder/nonHomeg/variationParameters_secondOrder_example.tex}\\fi", "meta": {"hexsha": "44169dd2c8783d90bd802326bd91ac0538fc631d", "size": 939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_secondOrder.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_secondOrder.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_secondOrder.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8260869565, "max_line_length": 269, "alphanum_fraction": 0.7113951012, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6703238700412106}}
{"text": "% !TEX root = Main.tex\n\\appendix\n\\appendixpage\n\\addappheadtotoc\n\\section{The benzene molecule}\\label{benzex}\n\\begin{wrapfigure}[7]{r}{.3\\textwidth}\n\t\\vspace{-2.3em}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\chemfig{1*6(-2-3-4-5-6-)}\n\t\\end{tikzpicture}\n\t\\caption{Indices of a benzene molecule}\\label{benz}\n\\end{wrapfigure}\nAs an example the Hamiltonian of benzene is considered. In \\cref{benz} one can see the indices of a benzene molecule. Remember that \\(\\bra{\\phi_{\\pi}(1)}\\hat{H}\\ket{\\phi_{\\pi}(1)} = 0\\) and \\cref{V}, the Hamiltonian reads:\n\\begin{align}\n\t\\mqty{                            \\\\ \\\\ \\\\ \\vb{H} = V_{pp\\pi}\\\\ \\\\ \\\\} \\ \\mqty{\t\t\t\t\t\t&  \\mqty{1 & 2 & 3 & 4 & 5 & 6} \\\\\n\t\t\\mqty{1                           \\\\ 2 \\\\ 3 \\\\ 4 \\\\ 5 \\\\ 6} &\t\\mqty*(0 & 1 & 0 & 0 & 0 & 1 \\\\\n\t1 & 0 & 1 & 0 & 0 & 0             \\\\\n\t0 & 1 & 0 & 1 & 0 & 0             \\\\\n\t0 & 0 & 1 & 0 & 1 & 0             \\\\\n\t0 & 0 & 0 & 1 & 0 & 1             \\\\\n\t1 & 0 & 0 & 0 & 1 & 0)}\\label{BH}\n\\end{align}\nAs a helping aid, \\cref{BH} shows the atomic indices of the atom on the top and to the left of the matrix. This will give an understanding of how to work with such matrices.\nThe structure of the benzene molecule is rotationally symmetric and rotating the indices one sixth must yield the same Hamiltonian. Consider the energy eigenvector:\n\\begin{align}\n\t\\phi = \\mqty(c_1 & c_2 & c_3 & c_4 & c_5 & c_6)\n\\end{align}\nThere must exist an operator that rotates the indices as such:\n\\begin{align}\n\tC_6\\phi = \\mqty(c_2 & c_3 & c_4 & c_5 & c_6 & c_1)\n\\end{align}\nThe rotated Hamiltonian is the same, and thus \\(C_6\\) and \\(\\vb{H}\\) commute. The rotated vector must be an eigenvector with the same energy and it should be possible to find simultaneous eigenvectors to \\(C_6\\) and \\(\\vb{H}\\).\n\\begin{align}\n\tC_6\\phi = \\mqty(c_2 & c_3 & c_4 & c_5 & c_6 & c_1) = \\lambda\\mqty(c_1 & c_2 & c_3 & c_4 & c_5 & c_6)\n\\end{align}\nThis operator \\(C_6\\) is represented with the matrix:\n\\begin{align}\n\t\\vb{C}_6 = \\mqty*(0 & 1 & 0 & 0 & 0 & 0  \\\\\n\t0                   & 0 & 1 & 0 & 0 & 0  \\\\\n\t0                   & 0 & 0 & 1 & 0 & 0  \\\\\n\t0                   & 0 & 0 & 0 & 1 & 0  \\\\\n\t0                   & 0 & 0 & 0 & 0 & 1  \\\\\n\t1                   & 0 & 0 & 0 & 0 & 0)\n\\end{align}\nIt can quickly be shown that the normalised eigenvectors to \\(C_6\\) are\n\\begin{align}\n\t\\phi_n = \\frac{1}{\\sqrt{6}}\\mqty(\\lambda_n^0 & \\lambda_n^1 & \\lambda_n^2 & \\lambda_n^3 & \\lambda_n^4 & \\lambda_n^5), \\quad \\lambda_n = \\exp{-i2\\pi n / 6}, \\quad n = 0,1,2,3,4,5\n\\end{align}\nThese eigenvectors are also eigenvectors for \\(\\vb{H}\\) with the eigenvalues:\n\\begin{align}\n\t\\varepsilon_n = \\lambda_n + \\lambda_{n-1} = 2 \\cos{n\\pi/3}\n\\end{align}\nThus thanks to the rotational symmetry it was possible to find the eigenvectors and eigenenergies for the Hamiltonian.\n\\section{Additional figures}\\label{appfigs}\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{Figures/BetaimrealTE8.eps}\n\t\t\\caption{Figure showing a plot of the Green's function at the \\nth{8} site}\n\t\t\\label{4th}\n\t\\end{subfigure}\n\t~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc.\n\t%(or a blank line to force the subfigure onto a new line)\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{Figures/BetaimrealTE11.eps}\n\t\t\\caption{Figure showing a plot of the Green's function at the \\nth{11} site}\n\t\t\\label{7th}\n\t\\end{subfigure}\n\t\\caption{Two plots showing how the Green's function changes as the site is changed. The \\nth{8} and \\nth{11} sites are corresponding to atoms of those indices (8, 11) in \\cref{inlinepointplot}. Note how the LDOS changes (imaginary part) for the different sites.}\\label{siteLDOSplot}\n\\end{figure}\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{Figures/FabNPGBS.eps}\n\t\t\\caption{Normal NPG}\n\t\t\\label{Fabbs}\n\t\\end{subfigure}\n\t~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc.\n\t%(or a blank line to force the subfigure onto a new line)\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{Figures/paraNPGBS.eps}\n\t\t\\caption{Para NPG}\n\t\t\\label{parabs}\n\t\\end{subfigure}\n\t~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc.\n\t%(or a blank line to force the subfigure onto a new line)\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{Figures/metaNPGBS.eps}\n\t\t\\caption{Meta NPG}\n\t\t\\label{metabs}\n\t\\end{subfigure}\n\t\\caption{Plot showing band structures in the energy range \\SI{-1.5}{\\electronvolt} to \\SI{1.5}{\\electronvolt} for normal, para and meta NPG. The are plotted between symmetry points \\(X\\) and \\(Y\\) with respect to the origin \\(\\Gamma\\)}\\label{allbands}\n\\end{figure}\n\n% \\section{Project overview}\n% A Gantt chart is provided on the next page. \\textbf{Not Updated.}\n% \\newpage\n% \\begin{turnpage}\n% \\setcounter{myWeekNum}{6}\n% \\ganttset{%\n% \tcalendar week text={\\myWeek{}}%\n% }\n% \\begin{figure}\\vspace{-10mm}\n% \\begin{ganttchart}[\n% \t\thgrid,\n% \t\tvgrid={*{6}{draw=none}, dotted},\n% \t\tx unit=.15cm,\n% \t\t%\ty unit title=.6cm,\n% \t\t%\ty unit chart=.6cm,\n% \t\tinline,\n% \t\tmilestone inline label node/.append style={left=5mm},\n% \t\tmilestone/.append style={xscale=3},\n% \t\ttime slot format=isodate,\n% \t\ttime slot format/start date=2019-02-04\n% \t]{2019-02-04}{2019-05-31}\n% \t\\gantttitlecalendar{year, month=shortname, week}\\\\\n% \t\\ganttgroup{Report writing}{2019-02-25}{2019-05-31}\\\\\n% \t\\ganttgroup[inline = false]{Course 33442}{2019-02-04}{2019-03-31}\\\\\n% \t\\ganttbar{Ch. 1 \\& 2}{2019-02-04}{2019-02-17}\\\\\n% \t\\ganttlinkedbar[link bulge=2]{Ch. 3}{2019-02-18}{2019-02-24}\\\\\n% \t\\ganttlinkedbar[link bulge=2,bar inline label node/.style={right=15pt}]{Ch. 4 \\& 5}{2019-02-25}{2019-03-03}\\\\\n% \t\\ganttgroup[inline = false]{Python code}{2019-03-04}{2019-03-31}\\\\\n% \t\\ganttbar{Py TB scripts}{2019-02-18}{2019-03-17}\\\\\n% \t\\ganttlinkedbar[link bulge=2, bar inline label node/.style={right=45pt}]{Small NPG systems simulations}{2019-03-10}{2019-03-31}\\\\\n% \t\\ganttmilestone{Proof of Concept with Python}{2019-03-31}\\\\\n% \t\\ganttgroup[inline = false]{Large scale TB}{2019-04-01}{2019-04-28}\\\\\n% \t\\ganttbar[bar inline label node/.style={left=10pt}]{SISL \\& TBtrans tutorial}{2019-04-01}{2019-04-05}\\\\\n% \t\\ganttlinkedbar[link bulge=2, bar inline label node/.style={right=50pt}]{Setup NPG variations}{2019-04-06}{2019-04-28}\\\\\n% \t\\ganttgroup[inline = false]{Generate data}{2019-04-28}{2019-05-31}\\\\\n% \t\\ganttmilestone{Hand in report}{2019-05-31}\n% \\end{ganttchart}\n% \\end{figure}\n% \\end{turnpage}\n% \\clearpage\n% \\global\\pdfpageattr\\expandafter{\\the\\pdfpageattr/Rotate 90}\n", "meta": {"hexsha": "4188210b886a29d34911c11f49f420693933843b", "size": 6609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix.tex", "max_stars_repo_name": "rwiuff/QuantumTransport", "max_stars_repo_head_hexsha": "5367ca2130b7cf82fefd4e2e7c1565e25ba68093", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-25T14:05:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-25T14:05:45.000Z", "max_issues_repo_path": "Appendix.tex", "max_issues_repo_name": "rwiuff/QuantumTransport", "max_issues_repo_head_hexsha": "5367ca2130b7cf82fefd4e2e7c1565e25ba68093", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-31T03:17:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-31T03:17:38.000Z", "max_forks_repo_path": "Appendix.tex", "max_forks_repo_name": "rwiuff/QuantumTransport", "max_forks_repo_head_hexsha": "5367ca2130b7cf82fefd4e2e7c1565e25ba68093", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-27T10:27:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-17T10:18:18.000Z", "avg_line_length": 48.2408759124, "max_line_length": 283, "alphanum_fraction": 0.6553185051, "num_tokens": 2493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6703238700180485}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\n\\section{If $p$ is a seminorm on $\\mathscr{X}$, $\\mathscr{M}$ is a linear manifold in $\\mathscr{X}$, and $\\bar{p}: \\mathscr{X} / \\mathscr{M} \\mapsto [0,\\infty]$ is defined by $\\bar{p}(x + \\mathscr{M}) = \\inf\\{p(x+y):y \\in \\mathscr{M}\\}$, then $\\bar{p}$ is a seminorm on $\\mathscr{X} / \\mathscr{M}$}.\n\nTriangle Inequality: Must show that $\\bar{p}(x_1+x_2+M) \\le \\bar{p}(x_1+\\mathscr{M}) + \\bar{p}(x_2+\\mathscr{M})$\n\n$\\inf\\{p(x_1 + x_2 + y) : y \\in \\mathscr{M}\\} \\le \\inf\\{p(x_1 + y) : y \\in \\mathscr{M}\\} + \\inf\\{p(x_2 + y ): y \\in \\mathscr{M}\\}$.\n\nApply the triangle inequality somehow inside the infimums to expand into a larger expression that is still \"less than or equal to\" all the way through???\n\nAbsolute homogeneity: Must show that $\\bar{p}(\\alpha x + \\mathscr{M}) = |\\alpha|\\bar{p}(x + \\mathscr{M})$\n\n$\\inf\\{p( \\alpha x +y) : y \\in \\mathscr{M}\\} = \\inf\\{p( \\alpha x + \\alpha y) : y \\in \\mathscr{M}\\} = \\inf\\{  | \\alpha | p( x +y) : y \\in \\mathscr{M}\\}  =  | \\alpha | \\inf\\{p( x +y) : y \\in \\mathscr{M}\\} $\n\nThe first equality is justified since both $y$ and $\\alpha y$ are in $\\mathscr{M}$, and the second is since $p$ is itself a seminorm.\n\n\\section{Show that if $\\mathscr{M} \\le \\mathscr{X}$ and $\\mathscr{M}$ is topologically complimented in $\\mathscr{X}$, then $\\mathscr{M}^{\\bot}$ is topologically complimented in $\\mathscr{X}^*$ and that its complement is weak-star and linearly homeomorphic to $\\mathscr{X}^* / \\mathscr{M}^{\\bot}$}\n\n\n\\end{document}", "meta": {"hexsha": "981e7e59552405a3b145c1e706afca0b1a64fa76", "size": 1546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/5_Weak_Topologies/2_Dual_of_a_Subspace.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "analysis/5_Weak_Topologies/2_Dual_of_a_Subspace.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis/5_Weak_Topologies/2_Dual_of_a_Subspace.tex", "max_forks_repo_name": "lukemassa/math-exercises", "max_forks_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.4166666667, "max_line_length": 299, "alphanum_fraction": 0.6326002587, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.6703238592471258}}
{"text": "\\paragraph{Activation functions} We consider 21 activation functions, 6 of which are ``novel'' and proposed in \\citet{Ramach:2018}. The functional form of these 6 is given in Table \\ref{table:functions}, together with the \\sigmoid{} function. \n\\begin{table}[!htb]\n  \\centering\n  \\begin{tabular}{ll}\n  \\toprule\n    \\sigmoid & $f(x)=\\sigma(x)=1/(1+\\exp(-x))$\\\\\n    %\\mytanh & \\\\\n    \\swish & $f(x)=x\\cdot \\sigma(x)$\\\\\n    \\maxsig & $f(x)=\\max\\{x,\\sigma(x)\\}$\\\\\n    \\cosid & $f(x)=\\cos(x)-x$\\\\\n    \\minsin & $f(x)=\\min\\{x,\\sin(x)\\}$\\\\\n    \\arctid & $f(x)=\\arctan(x)^2-x$\\\\\n    \\maxtanh & $f(x)=\\max\\{x,\\tanh(x)\\}$\\\\\n    \\midrule\n    \\lrelua & $f(x)=\\max\\{x,0.01x\\}$ \\\\\n    \\lrelub & $f(x)=\\max\\{x,0.3x\\}$ \\\\\n    {\\small \\pentan} & $f(x)=\\begin{cases}\\tanh(x) & x>0,\\\\ 0.25\\tanh(x) & x\\le 0\\end{cases}$\\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Top: \\sigmoid{} activation function as well as 6 top performing activation functions from \\citet{Ramach:2018}. Bottom: the LReLU functions with different parametrizations as well as \\pentan{}.}\n  \\label{table:functions}\n\\end{table}\n\nThe remaining 14 are: \\mytanh, \\mysin, \\relu, \\lrelua, \\lrelub, \\maxouta, \\maxoutb, \\maxoutc, \\prelu, \\linear, \\elu{}, \\cube, \\pentan, \\selu{}. We briefly describe \n%a few of these in greater detail: \nthem: \n\\lrelua{} and \\lrelub{} are the so-called leaky relu (LReLU) functions \\cite{Maas:2013}; the idea behind them is to avoid zero activations/derivatives in the negative region of \\relu{}. Their functional form is given in Table \\ref{table:functions}. \\prelu{} \\cite{He:2015} generalizes the LReLU functions by allowing the slope in the negative region to be a %n arbitrary \nlearnable parameter. The maxout functions \\cite{Goodfellow:2013} are different in that they introduce additional parameters and do not operate on a single scalar input. For example, \\maxouta{} is the operation that takes the maximum of two inputs: $\\max\\{\\mathbf{xW}+\\mathbf{b},\\mathbf{xV}+\\mathbf{c}\\}$, so the number of learnable parameters is doubled. \\maxoutb{} is the analogous function that takes the maximum of three inputs.\n%: $\\max\\{\\mathbf{xW}+\\mathbf{b},\\mathbf{xV}+\\mathbf{c},\\mathbf{xU}+\\mathbf{d}\\}$, etc. \nAs shown in \\citet{Goodfellow:2013}, maxout can approximate any convex function. \\mysin{} is the standard sine function, proposed in neural network learning, e.g., in \\citet{Parascandolo:2016}, where it was shown to enable faster learning on certain tasks than more established functions. \\pentan{} \\cite{Xu:2016} has been defined in analogy to the LReLU functions, which can be thought of as ``penalizing'' the identity function in the negative region. \nThe reported good performance of \\pentan{} on CIFAR-100 \\cite{Krizhevsky:2009}\n%, an image classification dataset with 100 classes, \nlets the authors speculate that the slope %and offset \nof activation functions near the origin may be crucial for learning. \n\\linear{} is the identity function, $f(x)=x$. \\cube{} is the function $f(x)=x^3$, proposed in \\citet{Chen:2014} for an MLP used in dependency parsing. \\elu{} \\cite{Clevert:2015} has been proposed as (yet another) variant of \\relu{} that assumes negative values, making the mean activations more zero-centered. \\selu{} is a scaled variant of \\elu{} used in \\citet{Klambauer:2017} in the context of so-called self-normalizing neural nets.\n\n\\paragraph{Properties of activation functions} \n\\begin{table*}[!htb]\n\\centering\n\\footnotesize\n\\begin{tabular}{llll}\n  \\toprule\n  Property & Description & Problems & Examples \\\\ \\midrule\n  derivative & $f'$ & $>1$ exploding gradient (e) &  \\sigmoid{} (v), \\mytanh{} (v), \\cube{} (e)\\\\\n  & & $<1$ vanishing (v) & \\\\\n  zero-centered & range centered around zero? &   if not, slower learning & \\mytanh{} ($+$), \\relu{} ($-$) \\\\ \n  saturating & finite limits & vanishing gradient in the limit & \\mytanh{}, \\pentan{}, \\sigmoid{}\\\\\n  monotonicity & $x>y\\implies f(x)\\ge f(y)$ & unclear & exceptions: \\mysin{}, \\swish{}, \\minsin{} \n  \\\\ \\bottomrule\n \\end{tabular}\n \\caption{Frequently cited properties of activation functions}.\n \\label{table:properties}\n\\end{table*}\n\nMany properties of activation functions have been speculated to be crucial for successful learning. \nSome of these are listed in Table \\ref{table:properties}, together with brief descriptions and illustrations. \n%%%First, most activation functions are monotonic, probably as a historical \n%One important factor appears to be the \\textbf{derivative} of the activation functions, because small derivatives may lead to vanishing gradients and large derivatives to exploding gradients. Since the relu function \\cite{Glorot:2011} has a derivative of 1 in the positive region, which is  putatively the optimal value, it has been claimed to be much more suitable than its predecessors such as \\mytanh{} and particularly \\sigmoid{}. However, \\relu{} has a derivative of zero in the negative region and additionally is not \\textbf{zero-centered}, %which makes functions such as leaky relu appear more suitable. \n%which is the reason why functions such as LReLU and \\elu{} have been proposed.  \n%Another frequently cited property is whether activation functions are \\textbf{saturating} or not, that is, how they behave in the limits. A non-saturating function like \\relu{} tends towards infinity as the pre-activation goes towards $+\\infty$, while functions like \\sigmoid{} and \\mytanh{} converge toward a finite limit. This means that the derivatives of saturating functions may become very small, implying again a vanishing gradient problem. \n%Most activation functions proposed are also \\textbf{monotonic}, that is, larger $x$ implies larger activation. This is probably a historical relic: originally, neural networks were described by metaphors adapted from neuro-science, where a larger pre-activation of a unit was associated with a larger probability of that unit ``firing''. By contrast, many of the activation functions found by automatic search in \\citet{Ramach:2018} are non-monotonic, including \\swish{}. In particular, automatic search yielded many periodic functions, such as sine and cosine, usually in connection with the raw pre-activation $x$. \n%\\citet{Ramach:2018} also find that ``simpler'' activation functions tend to outperform more complicated ones, and functions using division perform badly, because of numerical problems when the denominator approaches zero. \n\nGraphs of all activation functions can be found in the appendix. ", "meta": {"hexsha": "db5fd5b6ee10a2217e255804d8bc91a8389e62fd", "size": 6433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "arxiv-pdf-summary-helper/test/resources/1901/theory.tex", "max_stars_repo_name": "Xhattam/PDF_summary_helper", "max_stars_repo_head_hexsha": "6935d9f44d276020393ac4384236b08ef218280c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "arxiv-pdf-summary-helper/test/resources/1901/theory.tex", "max_issues_repo_name": "Xhattam/PDF_summary_helper", "max_issues_repo_head_hexsha": "6935d9f44d276020393ac4384236b08ef218280c", "max_issues_repo_licenses": ["MIT"], "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-pdf-summary-helper/test/resources/1901/theory.tex", "max_forks_repo_name": "Xhattam/PDF_summary_helper", "max_forks_repo_head_hexsha": "6935d9f44d276020393ac4384236b08ef218280c", "max_forks_repo_licenses": ["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.515625, "max_line_length": 618, "alphanum_fraction": 0.7348049122, "num_tokens": 1789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.670275298975309}}
{"text": "\\problemname{Greedily Increasing Subsequence}\nGiven a permutation $A = (a_1, a_2, \\dots, a_N)$ of the integers $1, 2, \\dots, N$, we define the \\emph{greedily increasing subsequence} (GIS) in the following way.\n\nLet $g_1 = a_1$. For every $i > 1$, let $g_i$ be the leftmost integer in $A$ that is strictly larger than $g_{i-1}$.\nIf there for a given $i$ is no such integer, we say that the GIS of the sequence is the sequence $(g_1, g_2, ..., g_{i - 1})$.\n\nYour task is to, given a permutation $A$, compute the GIS of $A$.\n\n\\section*{Input}\nThe first line of input contains an integer $1 \\le N \\le 10^6$, the number of elements of the permutation $A$.\nThe next line contains $N$ distinct integers between $1$ and $N$, the elements $a_1, \\dots, a_N$ of the permutation $A$.\n\n\\section*{Output}\nFirst, output a line containing the length $l$ of the GIS of $A$.\nThen, output $l$ integers, containing (in order) the elements of the GIS.\n\n\\section*{Explanation of sample 1}\nIn this case, we have the permutation  $2, 3, 1, 5, 4, 7, 6$.\nFirst, we have $g_1 = 2$.\nThe leftmost integer larger than $2$ is $3$, so $g_2 = 3$.\nThe leftmost integer larger than $3$ is $5$ ($1$ is too small), so $g_3 = 5$.\nThe leftmost integer larger than $5$ is $7$, so $g_4 = 7$.\nFinally, there is no integer larger than $7$.\nThus, the GIS of $2, 3, 1, 5, 4, 7, 6$ is $2, 3, 5, 7$.\n", "meta": {"hexsha": "c887adb07689e4af568e84e95a7a12cdf81c4982", "size": 1353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "greedilyincreasing/problem_statement/problem.en.tex", "max_stars_repo_name": "jsannemo/hiq-challenge-2017", "max_stars_repo_head_hexsha": "8271c716fe249674d585731f472b64616370300a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "greedilyincreasing/problem_statement/problem.en.tex", "max_issues_repo_name": "jsannemo/hiq-challenge-2017", "max_issues_repo_head_hexsha": "8271c716fe249674d585731f472b64616370300a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "greedilyincreasing/problem_statement/problem.en.tex", "max_forks_repo_name": "jsannemo/hiq-challenge-2017", "max_forks_repo_head_hexsha": "8271c716fe249674d585731f472b64616370300a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.12, "max_line_length": 163, "alphanum_fraction": 0.6777531412, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893520001, "lm_q2_score": 0.8221891392358014, "lm_q1q2_score": 0.6702752986973806}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\n\\setlength\\parindent{0pt}\n\n\\title{Retrograde and anterograde linear models of pathological spread along directed structural connectomes}\n\\author{Eli J. Cornblath}\n\n\\begin{document}\n\t\n\\maketitle\n\n\\section*{Introduction}\n\nLinear diffusion models are a highly promising tool for investigating the mechanisms of neurodegenerative disease progression, which is thought to be driven by transsynaptic spread throughout structural connectomes \\cite{Raj2012,Pandya2017,Pandya2019,Henderson2019,Mezias2020}.\n\nThere are two possible directions for transsynaptic spread. In retrograde spread, misfolded proteins travel backwards from distal axons towards the soma. In anterograde spread, the opposite process occurs-- misfolded proteins starting in the soma of a neuron travel down the axon to distal regions.\\\\\n\nIn this brief document, I will describe the simple version of the model used in Ref. \\cite{Henderson2019} to capture anterograde spread between to brain regions (equivalently, neurons or network nodes). Here, we use a matrix $W$ and the equation \n\n\\begin{equation}\n\\dot{x}=Wx\n\\label{eq1}\n\\end{equation}\nto instantiate an anterograde spreading process whereby pathology in node $A$ spreads from neuron soma in $A$ along axons that terminate in node $B$. In our model\n\n\\begin{equation}\nW= \n\\begin{bmatrix}\nW_{A\\rightarrow A} & W_{B\\rightarrow A}\\\\\nW_{A\\rightarrow B} & \tW_{B\\rightarrow B}\n\\end{bmatrix},\n\\label{eq2}\n\\end{equation}\nwhere the element $W_{A\\rightarrow B}$ indicates the strength of the axonal projections initiating from the somas in region $A$ and terminating in region $B$, and $\tW_{A\\rightarrow A} = \tW_{B\\rightarrow B} = 0$. \\\\\n\nSuppose at the beginning of model time, we seed 1 unit of pathology in region $A$ and represent it in the vector $x$:\n\\begin{equation}\nx = \\begin{bmatrix}\n1 \\\\ 0\n\\end{bmatrix}\n\\label{eq3}\n\\end{equation}\n\n\\noindent The general form of equation \\ref{eq1} is solved by the dot product between the $i$th row of $W$ and the columns of $x$ to generate $\\dot{x}_i$, as in\n\\begin{equation}\n\\dot{x} = \n\\begin{bmatrix}\nW_{1,1} & W_{1,2} \\\\\nW_{2,1} & W_{2,2}\n\\end{bmatrix}\n\\begin{bmatrix}\nx_{1,1} \\\\\nx_{2,1}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\nW_{1,1}x_{1,1} + W_{1,2}x_{2,1} \\\\\nW_{2,1}x_{1,1} + W_{2,2}x_{2,1}\n\\end{bmatrix}.\n\\label{eq4}\n\\end{equation}\n\n\\noindent We can substitute in our values into equation \\ref{eq4} and solve for $\\dot{x}$, which yields\n\n\\begin{equation}\n\\dot{x}=\n\\begin{bmatrix}\nW_{A\\rightarrow A} & W_{B\\rightarrow A}\\\\\nW_{A\\rightarrow B} & \tW_{B\\rightarrow B}\n\\end{bmatrix}\n\\begin{bmatrix}\n1 \\\\ 0\n\\end{bmatrix}\n\\label{eq5}\n\\end{equation}\n\\begin{equation}\n=\n\\begin{bmatrix}\n(1\\times W_{A\\rightarrow A}) + (0\\times W_{B\\rightarrow A}) \\\\\n(1\\times W_{A\\rightarrow B}) + (0\\times W_{B\\rightarrow B})\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n0 \\\\\nW_{A\\rightarrow B}\n\\end{bmatrix} .\n\\label{eq6}\n\\end{equation}\n\nIn this equation, we now observe that pathology in node $B$, represented by $x_{2,1}$, will change over time at a rate determined by the strength of axonal projections from neuron somas in $A$ terminating in $B$, which are reflected in $W_{A\\rightarrow B}$. This process reflects anterograde spread as intended through the design of $W$ in equation \\ref{eq2}, and as we implemented in Ref. \\cite{Henderson2019}. \\\\\n\nNote that in equation \\ref{eq1}, we define $\\dot{x}$, which is the rate of change of pathology at each node. However, it is often more intuitive to solve for the amount of pathology at each node, represented by the vector $x$. Integration of equation \\ref{eq1} yields\n\n\\begin{equation}\nx=e^{Wt}x_o\n\\end{equation}\n\nwhere $x_o$ is the initial state of $x$, and $e$ is the natural exponent.\n\\section*{Acknowledgments}\n\nI would like to thank Jason Z. Kim for his input on this document.\n\n\\bibliographystyle{plain}\n\\bibliography{\\string ~/Dropbox/Cornblath_Bassett_Projects/library.bib}\n\\end{document}", "meta": {"hexsha": "a928d1050d2587655dab9a1e6a305918c66fee94", "size": 3972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example/example.tex", "max_stars_repo_name": "thealexrk/Modeling-Tau-Spread", "max_stars_repo_head_hexsha": "322398bb37841da47cd0cbd31095188c4327b59b", "max_stars_repo_licenses": ["MIT"], "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/example.tex", "max_issues_repo_name": "thealexrk/Modeling-Tau-Spread", "max_issues_repo_head_hexsha": "322398bb37841da47cd0cbd31095188c4327b59b", "max_issues_repo_licenses": ["MIT"], "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/example.tex", "max_forks_repo_name": "thealexrk/Modeling-Tau-Spread", "max_forks_repo_head_hexsha": "322398bb37841da47cd0cbd31095188c4327b59b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-29T18:22:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-29T18:22:22.000Z", "avg_line_length": 36.4403669725, "max_line_length": 414, "alphanum_fraction": 0.7449647533, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6702752971298732}}
{"text": "\\section{Sequential Inversion}\\label{sec:sequential}\nThe DCI framework relies on evaluating the ratio function $r(\\param)$ in $\\dimD$--dimensional QoI space, so we turn our attention to addressing the challenges associated with the growth of this space.\nAs $\\dimD$ increases, we must approximate a push-forward distribution with perhaps a fixed number of samples (from model evaluations) $\\nsamps$, which represents a considerable source of error since the convergence rate for kernel density estimation with Gaussian kernels is $\\mathcal{O} (N^{2+\\dimD})$.\n\nFor example, consider a time-dependent problem for which hundreds of spatial sensors are providing streams of data.\nApproximating a $100$-dimensional space with $\\nsamps = 1E3$ or $1E4$ samples (as we have been using for demonstrations), poses a problem for any density approximation method.\nHowever, either of these values for $\\nsamps$ are generally sufficient to estimate a one-dimensional distribution.\nIn some sense, approximating a QoI at each location over time is reasonable, but doing so for all of them simultaneously is not.\nTo this end, we propose an approach to solving the parameter estimation problem by performing inversion through a sequence of scalar-valued QoIs rather than employ a vector-valued approach.\n\nAny choice of dimension below $\\dimD$ would suffice, but this sequential-scalar-valued approach provides a starting place and admits a simplicity in exposition.\nBy choosing a dimension of one, the focus of the examples is restricted to solely the order in which the QoIs are inverted; it avoids the additional complexity of enumerating the combinations of QoI when dimensions can vary.\nWe also choose to use a linear map for convenience so that we can use the analytical solutions presented in Chapter~\\ref{chapter:mud} without concern for approximation error.\nFurthermore, we omit measurement error from polluting the observations so that all the inverse contours intersect at a point.\nIn the event that there is measurement error, each contour will be displaced, so the collection of contours will form a convex hull whose volume is proportional to the approximation error.\nBy omitting measurement error, we simulate scalar-valued QoI which are constructed with sufficient number of measurements so as to ameliorate the impact of misidentifying each contour's location in $\\pspace$.\n\nWith each iteration in the sequence of inverse problems, we explain measurements that constitute a single QoI at the expense of accuracy in others.\nBy contrast, the vector-valued approach seeks accuracy in all of the directions of observations simultaneously.\nThis trade off is all about efficiency, since 1-dimensional problems are computationally ``cheap,'' we can iterate through many more of them for the same computational cost.\nBy the time we finish iterating through all available QoI, the estimate obtained from $Q^{(1)}$ may have drifted significantly away from its solution contour through the sequence of inverting through $Q^{(1)}, Q^{(2)}, \\dots Q^{(100)}$.\nTo address this, we perform multiple passes through the set of QoI.\nBorrowing from other sequential algorithms, these ``epochs'' will allow us to iterate until the solution stops changing by some predefined relative threshold, representing a lack of ``learning'' through continued effort.\n\n\n\\subsection{Motivating Linear Example}\nWe study the following motivating two-dimensional example with QoI defined by $10$ equispaced rotations of the unit vector $[0, 1]$ through the first two Euclidean quadrants.\nWe first plot the result of a single epoch in the left panel of Fig.~\\ref{fig:iterative-linear-demo}.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.475\\linewidth]{examples/iterative/10D-firstepoch.png}\n  \\includegraphics[width=0.475\\linewidth]{examples/iterative/10D-fewepochs.png}\n\n  \\caption{\n  Dotted lines show the solution contours for each row of the operator $A$.\n  (Left): First epoch for iterating through 10 QoI.\n  (Right): Three more epochs allows our estimate to get much closer to the true value.\n  }\n  \\label{fig:iterative-linear-demo}\n\\end{figure}\n\nThe spiral shape is a result of the underlying geometry of this QoI map defined by rotations. The successive rows are so similar to each other that very little is ``learned'' between each iteration; the projection doesn't cover a large distance in $\\pspace$.\nAt the end of these epochs, the estimate in the right panel of \\ref{fig:iterative-linear-demo} is still far off from the true parameter value (the intersection of the contours).\n\nTo further underscore the lack of mutually distinct information in successive rows of the QoI, we choose two pairs of indices from among the ten available in order to define two QoI maps, the contours for which we plot in different colors in Fig.~\\ref{fig:iterative-linear-demo-pair}.\nWe solve a total of ten 1-D inverse problems for each of them (five epochs) to match the budget of the previous example in the left panel of \\ref{fig:iterative-linear-demo} (with ten maps and one epoch).\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.475\\linewidth]{examples/iterative/10D-fewepochs-pair.png}\n  \\includegraphics[width=0.475\\linewidth]{examples/iterative/10D-fewepochs-pair-alt.png}\n  \\caption{\n  Iterating through five epochs of two QoI, each formed by picking two of the ten available rows of $A$ at random.\n  The random directions chosen on the left exhibit more redundancy than those on the right, so the same amount of iteration results in less accuracy.\n  }\n  \\label{fig:iterative-linear-demo-pair}\n\\end{figure}\n\nWe observe that in Fig~\\ref{fig:iterative-linear-demo-pair}, that there is much greater accuracy in estimating the true parameter value than in the case of Fig~\\ref{fig:iterative-linear-demo}.\nThe reason for this difference is that there is more mutually distinct information between successive iterations of a pair of random rows of $A$ than there is between adjacent rows, as measured by the angle between the solution contours.\n\n\\subsection{Connection to Skewness}\nIf we are careful with how we construct maps or choose an iteration strategy, we can achieve considerably more accurate solutions with the same computational cost.\nHad the choice of QoI components corresponded to a pair of rows that were orthogonal, the initial mean would converge to the reference value in a single epoch (two iterations), since there is no redundancy in information whatsoever.\nThis is equivalent to saying that we have an incentive to select rows that induce a QoI map with unit skewness.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.475\\linewidth]{examples/iterative/10D-firstepoch-pair-smart.png}\n  \\includegraphics[width=0.475\\linewidth]{examples/iterative/10D-firstepoch-rand.png}\n  \\caption{\n  (Left): Iterating through a single epoch with a QoI formed by picking rows of $A$ which exhibit mutual orthogonality.\n  (Right): Iterating through the rows of $A$ at a random order for a single epoch results in considerably more accuracy than doing so in the original order of rows of $A$.\n  }\n  \\label{fig:iterative-linear-demo-smart}\n\\end{figure}\n\n\nWe show this in the left half of Figure~\\ref{fig:iterative-linear-demo-smart} for two QoI maps with orthogonal pairs of components.\nIf instead no a priori analysis of the rows of $A$ and iteration through the available QoI at random is the chosen ordering, more accuracy is achieved with only ten iterations.\nWe show this in the right-half of Figure \\ref{fig:iterative-linear-demo-smart}, which exhibits a more accurate estimate compared to \\ref{fig:iterative-linear-demo} at the same computational cost.\n\n\n\\subsection{Comparisons and Convergence Results}\nTo make these results more concrete, we propose the following example:\nWe limit ourselves to solving 100 inverse problems (i.e. up to ten epochs for this map), with the \\emph{only} difference between approaches being the order in which the rows of $A$ are used.\nFirst, we use the QoI as they are presented: in order with respect to increased rotation angle (which defines the rows of $A$).\nNext, we shuffle the rows of $A$ and then perform ten epochs using this permuted map.\nLastly, we create an ordering based on a random shuffling of ten sets of indices representing the rows of $A$.\nThe latter approach is similar to the second in that the same problems are solved the same number of times overall, but it lifts the restriction that a row must only be used once in each successive set of ten iterations (equal computational effort).\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.95\\linewidth]{examples/iterative/10D-convergence-comparison.png}\n  \\caption{\n  Twenty different initial means are chosen and iterated on for three approaches.\n  Individual experiments are transparent and the mean error is shown as solid lines.\n  In the \\emph{Ordered} approach, we iterate through the rows of $A$ as they are given to us for ten epochs.\n  \\emph{Shuffled QoI} refers to establishing a different random ordering of the rows of $A$ for each trial, and then\n  using this ordering for ten epochs.\n  Finally, in the \\emph{Random QoI} approach, we choose a QoI at random for each of 100 iterations, where the ordering still ensures each row gets used ten times, representing the same overall set of inverse problems solved as the other two.\n  }\n  \\label{fig:iterative-convergence-comparison}\n\\end{figure}\n\nIn Figure~\\ref{fig:iterative-convergence-comparison}, it is shown that using the rows of $A$ sequentially performs very poorly (the error struggles to get past a single decimal place of accuracy), which aligns with ``spiraling'' seen in Figure~\\ref{fig:iterative-linear-demo} where the first few epochs are plotted.\nShuffling the rows but requiring that every tenth iteration to use the same row (i.e., ensure same ordering for each epoch), leads to a considerable improvement by which sixteen decimal places of accuracy are achieved in under $100$ iterations.\nIn a few instances, the shuffled approach stumbles on an ordering that accelerates convergence, likely due to orthogonal pairs of rows in the shuffled order.\nThese cases exhibit the kind of behavior seen in the left panel of Fig~\\ref{fig:iterative-linear-demo-smart}; in other words, sometimes random shuffling finds the ``smart'' rows to iterate through.\nSince the ordering has no dependence on iteration number in the approach where we use random rows, we have more opportunities to find these successive orthogonal pairings, and so we see that on average, it takes fewer iterations to achieve the same accuracy.\n\n%\n% \\subsection{Iterated Solutions for a PDE Example}\\label{sec:iterated-nonlinear}\n%\n% Batch-updates is the connection to make here.\n% We are going to set up the heatrod example here but place measurement devices throughout and record the measurements at several intervals in time, the point being here that the dimension of the QoI will be higher than the input space but it's okay because we're iterating.\n%\n% Some systems will be more informative early in time, others late, so the best thing to do is not really something we're going to answer, we're just going to show how this approach \\emph{could} work in a situation like this where the data is streaming in over time.\n", "meta": {"hexsha": "75c85a00ea107739f773c6fb858f2796e318ae89", "size": 11256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "extensions/sequential_inversion.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/sequential_inversion.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/sequential_inversion.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": 93.8, "max_line_length": 315, "alphanum_fraction": 0.7933546553, "num_tokens": 2524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219505, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6702752952844376}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{The likelihood ratio test}\\label{sec:slrt}\n\n\\begin{definition}\nThe \\emph{likelihood ratio} statistic $\\lambda:D\\to\\R$ for testing $H_0:\\theta\\in\\Theta_0$ against $H_1:\\theta\\in\\Theta_1$ is defined by\n\\[\n\\lambda(\\mathbf{x}) = \\frac{\\max\\{L(\\theta;\\mathbf{x}):\\theta\\in\\Theta_0\\}}{\\max\\{L(\\theta;\\mathbf{x}):\\theta\\in\\Theta_1\\}} \n\\]\n\\end{definition}\n\n% simple case\nIf $H_0$ and $H_1$ are both simple hypotheses, say $H_0:\\theta=\\theta_0$ and $H_1:\\theta=\\theta_1$, the likelihood ratio reduces to\n\\[\n\\lambda(\\mathbf{x}) = \\frac{L(\\theta_0;\\mathbf{x})}{L(\\theta_1;\\mathbf{x})}\n\\]\n\nIf $\\lambda(\\mathbf{x})$ is small then $L(\\theta_1;\\mathbf{x})$ is large relative to $L(\\theta_0;\\mathbf{x})$ which indicates that $\\theta_1$ is more likely than $\\theta_0$ of being the true parameter value, and as a result we might be inclined to reject $H_0$. \n\n% definition: likelihood ratio test\n\\begin{definition}\nThe \\emph{likelihood ratio test} (LRT) of $H_0:\\theta\\in\\Theta_0$ against $H_1:\\theta\\in\\Theta_1$ is defined by the critical region\n\\[\nC = \\left\\{\\mathbf{x}:\\lambda(\\mathbf{x}) \\leq k\\right\\}\n\\]\nwhere $k$ is chosen according to the required size of the test.\n\\end{definition}\n\nIf $H_0$ and $H_1$ are both simple hypotheses, this is sometimes called the \\emph{simple likelihood ratio test} (SLRT).\n\n% example\n\\begin{example}\nLet $X_1,\\ldots,X_n$ be a random sample from the $\\text{Exponential}(\\theta)$ distribution, where $\\theta>0$ is an unknown rate parameter. Derive an explicit form for the critical region of the likelihood ratio test for testing the simple hypothesis $H_0:\\theta=\\theta_0$ against the simple alternative $H_1:\\theta=\\theta_1$, where $\\theta_1 > \\theta_0$.\n\\begin{solution}\nThe PDF is $f(x;\\theta) = \\theta e^{-\\theta x}$ so the likelihood function is\n\\[\nL(\\theta;\\mathbf{x}) = \\prod_{i=1}^n \\theta e^{-\\theta x_i} = \\theta^n \\exp\\left(-\\theta\\sum_{i=1}^n x_i\\right).\n\\]\nHence the likelihood ratio is\n\\[\n\\lambda(\\mathbf{x})\n\t= \\frac{L(\\theta_0;\\mathbf{x})}{L(\\theta_1;\\mathbf{x})} \n\t= \\frac{\\theta_0^n \\exp\\left(-\\theta_0\\sum_{i=1}^n x_i\\right)}{\\theta_1^n \\exp\\left(-\\theta_1\\sum_{i=1}^n x_i\\right)}\n\t= \\left(\\frac{\\theta_0}{\\theta_1}\\right)^n \\exp\\left(-(\\theta_0-\\theta_1)\\sum_{i=1}^n x_i\\right).\n\\]\nThe critical region for the SLRT is therefore\n\\begin{align*}\nC = \\{\\mathbf{x}:\\lambda(\\mathbf{x}) \\leq k\\} \n\t& = \\left\\{\\mathbf{x}:\\left(\\frac{\\theta_0}{\\theta_1}\\right)^n\\exp\\left(-(\\theta_0-\\theta_1)\\sum_{i=1}^n x_i\\right) \\leq k\\right\\} \\\\\n\t& = \\left\\{\\mathbf{x}: n\\log\\left(\\frac{\\theta_0}{\\theta_1}\\right) - (\\theta_0-\\theta_1)\\sum_{i=1}^n x_i \\leq \\log k \\right\\} \\\\\n%\t& = \\left\\{\\mathbf{x}: \\sum_{i=1}^n x_i \\leq \\frac{\\log k - n\\log(\\theta_0/\\theta_1)}{\\theta_0-\\theta_1} \\right\\}\\\\\n\t& = \\left\\{\\mathbf{x}: \\sum_{i=1}^n x_i \\leq \\frac{\\log k + n\\log(\\theta_1/\\theta_0)}{\\theta_1-\\theta_0} \\right\\}\\\\\n\t& = \\left\\{\\mathbf{x}: \\sum_{i=1}^n x_i \\leq k' \\right\\} \\quad\\text{or alternatively}\\quad \\left\\{\\mathbf{x}: \\frac{1}{n}\\sum_{i=1}^n x_i \\leq k'' \\right\\}\n\\end{align*}\nwhere we have used the fact that $\\theta_1 > \\theta_0$. The critical value $k'$ (or $k''$) is then chosen according to the required size of the test.\n\\end{solution}\n\\end{example}\n\n\n% example\n\\begin{example}\nLet $X_1,\\ldots,X_n$ be a random sample from the distribution of $X$, whose PDF is given by\n\\[\nf(x;\\theta) = \\begin{cases}\n\t\\theta x^{\\theta-1}\t& 0\\leq x\\leq 1 \\\\\n\t0\t\t\t\t\t& \\text{otherwise,}\n\\end{cases}\n\\]\nwhere $\\theta\\geq 1$ is an unknown scalar parameter. Construct a likelihood ratio test of the null hypothesis $H_0:\\theta=1$ against the alternative $H_1:\\theta>1$.\n\\begin{solution}\nThe PDF is $f(x;\\theta) = \\theta e^{-\\theta x}$ so the likelihood function is\n\\[\nL(\\theta;\\mathbf{x}) \n\t= \\textstyle\\prod_{i=1}^n \\theta x_i^{\\theta-1} \n\t= \\theta^n\\left(\\prod_{i=1}^n x_i\\right)^{\\theta-1}.\n\\]\nThe likelihood ratio is\n\\[\n\\lambda(\\mathbf{x})\n\t= \\frac{L(1;\\mathbf{x})}{L(\\theta;\\mathbf{x})} \n\t= \\frac{1}{\\theta^n\\big(\\prod_{i=1}^n x_i\\big)^{\\theta-1}}\n\t= \\theta^{-n}\\left(\\prod_{i=1}^n x_i\\right)^{1-\\theta}.\n\\]\nThe critical region is \n\\begin{align*}\nC = \\{\\mathbf{x}:\\lambda(\\mathbf{x}) \\leq k\\} \n\t= \\left\\{\\mathbf{x}:\\theta^{-n}\\left(\\prod_{i=1}^n x_i\\right)^{1-\\theta} \\leq k\\right\\}\n\t& = \\left\\{\\mathbf{x}: -n\\log\\theta + (1-\\theta)\\sum_{i=1}^n \\log x_i \\leq \\log k \\right\\} \\\\\n\t& = \\left\\{\\mathbf{x}: (1-\\theta)\\sum_{i=1}^n\\log x_i \\leq \\log k + n\\log\\theta\\right\\}\\\\\n\t& = \\left\\{\\mathbf{x}: -\\sum_{i=1}^n \\log x_i \\leq -\\frac{\\log k + n\\log\\theta}{1-\\theta}\\right\\} \\\\\n\\end{align*}\nThus a likelihood ratio test of $H_0:\\theta=1$ against $H_1:\\theta>1$ is given by the critical region\n\\[\nC = \\{\\mathbf{x}: T(\\mathbf{x}) \\leq k'\\} \\qquad\\text{where}\\quad T(\\mathbf{x}) = -\\sum_{i=1}^n \\log x_i,\n\\]\nand $k'>0$ is chosen according to the required size of the test.\n%\\bigskip\n%\\textbf{Remarks}\n%\\bit\n%\\it The null hypothesis $H_0:\\theta=1$ corresponds to $X\\sim\\text{Uniform}[0,1]$.\n%\\it As $\\theta$ increases away from $1$, the probability mass moves away from $x=0$ and towards $x=1$.\n%\\it Observations that are close to $1$ yield small positive values of $-\\log x_i$.\n%\\it Observations that are close to $0$ yield large positive values of $-\\log x_i$.\n%\\eit\n%Small values of $T(\\mathbf{x}) = -\\sum_{i=1}^n \\log x_i$ therefore indicate that many observations are close to $1$, leading us to reject the claim that $X\\sim\\text{Uniform}[0,1]$. Compare this test to a test based on the sample mean of the $X_i$:\n%\\[\n%C' = \\left\\{\\mathbf{x}: \\frac{1}{n}\\sum_{i=1}^n x_i \\geq k''\\right\\}\n%\\]\n%A preponderance of observations close to $1$ will lead us to reject $H_0$. However the LRT is a more sensitive test: $-\\log(x)$ \\emph{amplifies} the contribution of observations that are close to zero, and \\emph{diminishes} the contribution of observations that are close to $1$.\n\\end{solution}\n\\end{example}\n\n", "meta": {"hexsha": "320c7a5feadf64972dad0e1ba62f7eca40b43cfc", "size": 5892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/09C_slrt.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/09C_slrt.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/09C_slrt.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": 51.6842105263, "max_line_length": 354, "alphanum_fraction": 0.6620841819, "num_tokens": 2188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.6702752771080082}}
{"text": "%!TEX root = ../Tibt.tex\n\n\\exercise{2.7}\n\n\\subsubsection*{Point (a)}\n\nOne has:\n\\begin{eqnarray*}\n    \\textrm{linear regression:} \\quad && \\hat{f}(x_0) = x_0^T \\hat{\\beta} = x_0^T (\\mathbf{X} ^{T} \\mathbf{X}) ^{-1} \\mathbf{X} ^{T} Y \\\\\n    && l_i(x_0, \\mathcal{X}) = \\left( \\mathbf{X} (\\mathbf{X} ^{T}\\mathbf{X}) ^{-1} x_0\\right)_i \\\\\n    \\textrm{k-nn:} \\quad && l_i(x_0, \\mathcal{X}) = \\frac{1}{k}\\, \\mathbf{I} \\left( x_i \\textrm{ is among the } k \\textrm{ closest neighbors of } x_0 \\right)\n\\end{eqnarray*}\n\n\\subsubsection*{Point (b)}\n\nNotice that:\n\\begin{eqnarray*}\n    \\mathbb{E}_{\\mathcal{Y}|\\mathcal{X}} \\left[ \\hat{f}(x_0) \\right] & = & \\bm{l}^{T}(x_0; \\mathcal{X})\\,\\bm{f}(X),\\\\\n    \\textrm{Var}_{\\mathcal{Y}|\\mathcal{X}}\\left( \\hat{f}(x_0) \\right) & = & \\bm{l}^{T}(x_0; \\mathcal{X})\\, \\textrm{Cov}(\\bm{\\epsilon}) \\, \\bm{l}(x_0; \\mathcal{X}) = \\sigma^2 \\, ||\\bm{l}(x_0; \\mathcal{X})||^2\n\\end{eqnarray*}\nwhere we denoted $(\\bm{l}(x_0; \\mathcal{X}))_i \\equiv l_i(x_0; \\mathcal{X})$ and $(\\bm{f}(X))_i \\equiv f(x_i)$. Hence:\n\\begin{eqnarray*}\n    \\mathbb{E}_{\\mathcal{Y}| \\mathcal{X}} \\left[ \\left( f(x_0) - \\hat{f}(x_0) \\right)^2 \\right]  & = & \\textrm{Bias}^2_{\\mathcal{Y}| \\mathcal{X}}(y_0) + \\textrm{Var}_{\\mathcal{Y}| \\mathcal{X}}(y_0)\\\\ \n    \\textrm{Bias}^2_{\\mathcal{Y}| \\mathcal{X}}(y_0) & \\equiv & \\left( f(x_0) - \\bm{l}^{T}(x_0; \\mathcal{X})\\,\\bm{f}(X) \\right)^2\\\\\n    \\textrm{Var}_{\\mathcal{Y}| \\mathcal{X}}(y_0) & \\equiv & \\sigma^2 ||\\bm{l}(x_0; \\mathcal{X})||^2 \n\\end{eqnarray*}\nThe first term represents the bias, while the second represents the variance of the estimator as the training responses vary for fixed $\\mathcal{X}$.\n\n\\subsubsection*{Point (c)}\n\nFor this part can go down a similar road, using now the independence of $X$ and $\\epsilon$:\n\\begin{eqnarray*}\n    \\mathbb{E}_{\\mathcal{Y},\\mathcal{X}} \\left[ \\hat{f}(x_0) \\right] & = & \\mathbb{E}_{\\mathcal{X}} \\left[ \\bm{l}^T(x_0; \\mathcal{X}) \\, \\bm{f}(X) \\right],\\\\\n    \\textrm{Var}_{\\mathcal{Y},\\mathcal{X}}\\left( \\hat{f}(x_0) \\right) & = & \\textrm{Var}_{\\mathcal{X}} \\left( \\bm{l}^T(x_0; \\mathcal{X}) \\, \\bm{f}(X) \\right) + \n    \\sigma ^2 \\mathbb{E}_{\\mathcal{X}} \\left[ ||\\bm{l}(x_0; \\mathcal{X})||^2  \\right],\n\\end{eqnarray*}\nHence:\n\\begin{eqnarray*}\n    \\mathbb{E}_{\\mathcal{Y}, \\mathcal{X}} \\left[ \\left( f(x_0) - \\hat{f}(x_0) \\right)^2 \\right] & = & \\textrm{Bias}^2_{\\mathcal{Y}, \\mathcal{X}}(y_0) + \\textrm{Var}_{\\mathcal{Y}, \\mathcal{X}}(y_0)\\\\\n    \\textrm{Bias}^2_{\\mathcal{Y}, \\mathcal{X}}(y_0) & \\equiv &\\left( f(x_0) - \\mathbb{E}_{\\mathcal{X}} \\left[ \\bm{l}^T(x_0; \\mathcal{X}) \\, \\bm{f}(X) \\right]  \\right)^2\\\\\n    \\textrm{Var}_{\\mathcal{Y}, \\mathcal{X}}(y_0) & \\equiv & \\textrm{Var}_{\\mathcal{X}} \\left( \\bm{l}^T(x_0; \\mathcal{X}) \\, \\bm{f}(X) \\right) + \n    \\sigma ^2 \\mathbb{E}_{\\mathcal{X}} \\left[ ||\\bm{l}(x_0; \\mathcal{X})||^2  \\right]\n\\end{eqnarray*}\n\n\\subsubsection*{Point (d)}\n\nCombining the equations above one can see that:\n\\begin{eqnarray*}\n    \\textrm{Bias}^2_{\\mathcal{Y}, \\mathcal{X}}(y_0) + \\textrm{Var}_{\\mathcal{Y}, \\mathcal{X}}(y_0) = \\mathbb{E}_{\\mathcal{X}} \\left( \\textrm{Bias}^2_{\\mathcal{Y}| \\mathcal{X}}(y_0) + \\textrm{Var}_{\\mathcal{Y}| \\mathcal{X}}(y_0) \\right)\n\\end{eqnarray*}\nwhich is a simple consequence of the conditional expectations identity:\n\\begin{eqnarray*}\n    \\mathbb{E}_{\\mathcal{Y}, \\mathcal{X}} \\left[ \\left( f(x_0) - \\hat{f}(x_0) \\right)^2 \\right] =  \\mathbb{E}_{\\mathcal{X}} \\left[ \\mathbb{E}_{\\mathcal{Y}| \\mathcal{X}} \\left[ \\left( f(x_0) - \\hat{f}(x_0) \\right)^2 \\right]  \\right]\n\\end{eqnarray*}\n{\\color{red} This might be the relationship the authors wanted us to find.}", "meta": {"hexsha": "818afd5c809b31786809ad46ce7c3b58500cad11", "size": 3609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/Chapter2/ex_2_7.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/Chapter2/ex_2_7.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/Chapter2/ex_2_7.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": 65.6181818182, "max_line_length": 235, "alphanum_fraction": 0.5996120809, "num_tokens": 1676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6702645706829655}}
{"text": "\\paragraph{Statistical test}\nfor testing hypothesis $H$ against $K$, defined on sample $\\sample$, is a function:\n\\begin{gather*}\n\\psi: \\mathcal{H} \\rightarrow \\{0, 1\\}\n\\end{gather*}\nwhere $\\psi = 1$ means that we reject $H$ (i.e. we accept $K$) and $\\psi = 0$ means that we do not reject $H$.\n\nUsually, $\\psi$ has the following form:\n\\begin{gather*}\n\\psi(\\sample) = \n\\begin{cases}\n1 \\mbox{ if } T(\\sample) \\in \\mathcal{K}_\\alpha \\\\\n0 \\mbox{ if } T(\\sample) \\not\\in \\mathcal{K}_\\alpha\n\\end{cases}\n\\end{gather*}\nwhere $T$ is a test statistic, and $\\mathcal{K}_\\alpha$ is a critical region.\n\n\\paragraph{Null hypothesis}\nis usually denoted by $H$, and it is a hypothesis that we test. In most of the cases it is some\nphenomenon about which we are not sure whether it really happens, and we perform a test in order to\ndetermine the reality.\n\n\\paragraph{Alternative hypothesis}\nis usually denoted by $K$, and it is a hypothesis opposite to the null hypothesis.\n\n\\paragraph{Critical region}\nis a set of all outcomes of a test, for which we reject the null hypothesis. Denoted by $\\mathcal{K}_\\alpha$.\n\n\\paragraph{Type I error}\nis made when $H$ is rejected when in fact it is true. Probability of this error is denoted by $\\alpha_\\psi$.\n\n\\paragraph{Type II error}\nis made when $H$ is not rejected when in fact it is false. Probability of this error is denoted by $\\beta_\\psi$.\n\n\\paragraph{Significance level}\ndenoted with $\\alpha$ is the upper bound for probability of making type I error. It is fixed in\nadvance.\n\\begin{gather*}\n\\begin{cases}\n\\alpha_\\psi \\leq \\alpha \\\\\n\\beta_\\psi \\rightarrow \\min\n\\end{cases} \\equiv \n\\begin{cases}\nP(\\psi = 1 | H) \\leq \\alpha \\\\\nP(\\psi = 0 | K) \\rightarrow \\min\n\\end{cases}\n\\end{gather*}\n\n``Significance'' in statistics does not have the usual everyday meaning.\n\n\\paragraph{Power of a test}\nis a probability of rejecting false hypothesis.\n\\begin{gather*}\n\\Pi = P(\\psi = 1 | K) = 1 - P(\\psi = 0 | K) = 1 - \\beta_\\psi\n\\end{gather*}\n\n\\paragraph{Uniformly most powerful test}\n(or U.M.P.T.) is such test $\\psi^*$, defined for hypothesis $H: \\theta \\in \\Theta_H$ against $K: \\theta \\in\n\\Theta_K$, on the significance level $\\alpha$, that satisfies the following:\n\\begin{gather*}\n\\forall \\theta \\in \\Theta_K : \\mathbb{E}_\\theta \\psi^*(X) \\geq \\mathbb{E}_\\theta \\psi(X)\n\\end{gather*}\n\n\\paragraph{Neyman-Pearson Lemma}\nstates, that if we consider a testing problem $H: f_0$ against $K: f_1$, defined as follows:\n\nLet $\\alpha \\in (0,1)$ and let $\\psi$ denote a test that:\n\\begin{gather*}\n\\psi(X) = \\begin{cases}\n1 \\mbox{ if } f_1(X) > k f_0(X) \\\\\n0 \\mbox{ if } f_1(X) < k f_0(X)\n\\end{cases}\n\\label{eq:neymanpearson1} \\tag{A}\n\\end{gather*}\n\nwhere $k$ is a constant, $k > 0$, and it satisfies:\n\\begin{gather*}\n\\mathbb{E}_{f_0} \\psi(X) = \\alpha\n\\label{eq:neymanpearson2} \\tag{B}\n\\end{gather*}\n\n\\noindent \\ldots then we may conclude the following:\n\\begin{enumerate}\n\n  \\item Test $\\psi$ satisfying \\eqref{eq:neymanpearson1} and \\eqref{eq:neymanpearson2} is the\n  U.M.P.T. for $H$ against $K$ on the significance level $\\alpha$.\n\n  \\item If $\\alpha$ is the U.M.P.T. for $H$ against $K$ on the significance level $\\alpha$, the test\n  $\\psi$ should satisfy \\eqref{eq:neymanpearson1} and \\eqref{eq:neymanpearson2}.\n\n\\end{enumerate}\n\n\\paragraph{Monotonic likelihood ratio}\nfor a family $P = \\{ f_\\theta : \\theta \\in \\Theta \\}$ exists if there is a statistic $T$\nsuch that $\\frac{ p_{\\theta_1}(X) }{ p_{\\theta_0}(X) }$ for $\\theta_1 > \\theta_0$ is a nondecreasing\nfunction of $T(X)$.\n\n\\paragraph{Karlin-Rubin theorem}\nlet $P = \\left\\{ f_\\theta : \\theta \\in \\Theta \\right\\}$ denote a family with the monotonic\nlikelihood ratio with respect to statistic $T$. Consider the hypothesis $H: \\theta \\leq \\theta_0$\nagainst $K: \\theta > \\theta_0$. Then, for any $\\alpha \\in (0,1)$ there exists the U.M.P.T on the\nsignificance level $\\alpha$ of the form:\n\\begin{gather*}\n\\psi(\\sample) = \\begin{cases}\n1 \\mbox{ if } T(\\sample) > C_\\alpha \\\\\n0 \\mbox{ otherwise}\n\\end{cases}\n\\end{gather*}\n\n\\paragraph{Unbiasedness of a hypothesis test}\nis determined by checking if for a test $\\psi$ the following holds:\n\\begin{gather*}\n\\begin{cases}\n\\forall \\theta \\in \\Theta_H : \\mathbb{E}_\\theta \\psi(X) \\leq \\alpha \\\\\n\\forall \\theta \\in \\Theta_K : \\mathbb{E}_\\theta \\psi(X) \\geq \\alpha\n\\end{cases}\n\\end{gather*}\n\n\\paragraph{Consistent hypothesis test}\nis such test for H against K, for which the following holds:\n\\begin{gather*}\n\\forall \\theta \\in \\Theta_K \\limit{n}{\\infty} \\mathbb{E}_\\theta \\psi(\\sample) = 1\n\\end{gather*}\n\n\\paragraph{Two categories}\nof hypothesis tests are: parametric and non-parametric.\n\n\\paragraph{Parametric test}\nis a test, in which we have parameters that uniquely define the distribution to which the sample\nunder study belongs.\n\n\\paragraph{Non-parametric statistical test}\nis a test that does not assume that sample belongs to any specific distribution. Such test is also\ncalled a distribution-free test.\n\n\\paragraph{p-value}\nis an indicator for rejection or acceptance of null hypothesis. When it is not smaller than\nsignificance level of the test, we accept our hypothesis.\n", "meta": {"hexsha": "1972b3b5a04edb986699945e1447080894fb8cbc", "size": 5085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_7a_tests.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_7a_tests.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_7a_tests.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5827338129, "max_line_length": 112, "alphanum_fraction": 0.7097345133, "num_tokens": 1598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.6702645562767353}}
{"text": "\\label{ch:four}\n\\label{ch:four}\n\n\\section{Mutual information}\\label{mutInfo}\n\tThe mutual information measures the amount of information that $X$ and $Y$ \\textit{share}.\n    It can be used as a measure of correlation (or dependency) between random variables.\n    Intuitively we can use the mutual information --- along with a check of privacy against Eve --- to measure how much shared key two random variables $X$ and $Y$ can hold.\n    \\begin{definition}\n\tLet $X$ and $Y$ be two jointly distributed random variables. Then the mutual information of the random variables is the relative entropy --- a measure of distance between probability distributions --- between the joint distribution $P_{XY}(x,y)$ and the product distribution $P_X(x)\\cdot P_Y(y)$.\n\t\\begin{equation}\n\t\t\\I(X;Y) = \\sum_{y\\in\\mathcal{Y}}\\sum_{x\\in\\mathcal{X}} p(x,y) \\log\\left(\\frac{p(x,y)}{p(x)p(y)}\\right) \n\t\\end{equation}\n\tor equivalently, showing its relation to the entropies of the random variables\n\t\\begin{equation}\n\t\t\\I(X;Y) = \\Ent(X) - \\Ent(X|Y) = \\Ent(X,Y) - \\Ent(X|Y) - \\Ent(Y|X) = \\Ent(Y) - \\Ent(Y|X)\n\t\\end{equation}\n\tThis relation can be seen more directly in Fig. \\ref{fig:mutual_info}.\n    \\end{definition} \n\tMutual information is nonnegative and bounded by the entropy of random variable $X$\n\t\\begin{equation}\n\t\t0 \\leq \\I(X;Y) \\leq \\min \\left(\\Ent(X), \\Ent(Y)\\right)\n\t\\end{equation}\n\tIn this sense the mutual information can also be interpreted as how much information $X$ gives about $Y$, thus being bounded by its own entropy.\n\t\\begin{figure}[ht]\n\t\t\\centering\n\t\t\\input{images/mutual-info}\n\t\t\\caption{Representation of mutual information $\\I(X;Y)$ in relation with entropies $\\Ent(X)$ and $\\Ent(Y)$ and joint entropy $\\Ent(X,Y)$ of the random variables .\n\t\t\\label{fig:mutual_info}}\n\t\\end{figure}\t\n\t\n\\section{An eavesdropper that can choose the best channel to listen to}\nAdditional information on a third random variable $Z$ can increase or decrease the mutual information \\cite{CT12}.\n    The \\emph{conditional mutual information} $\\I(X;Y|Z)$ is the expected value of the mutual information of $X$ and $Y$ given a realization of a third variable $Z$.\n    In a context of key exchange, we can interpret this as the remaining correlation between honest parties after the observations of an attacker Eve.\n    What if Eve tried to minimize this, i.e. tried to find the best viewpoint possible over the communication between Alice and Bob?\n    \\begin{definition}\\cite{MW99, RW03}\n    \tLet $P_{XYZ}$ be a discrete probability distribution. Then the intrinsic information between $X$ and $Y$ given $Z$ is\n    \\begin{equation} \\label{intrininfo}\n    \t\\intrinfo{X}{Y}{Z}:= \\inf_{Z\\rightarrow \\bar{Z}} \\I(X;Y | \\bar{Z})\n    \\end{equation}\n    \\end{definition}\n    The infimum is taken over all possible channels applied to $Z$ (the choice of a channel can be seen as the choice of a point of view for Eve).\n    \n    The intrinsic information is an upper bound to the secret-key rate, although not tight \\cite{RW03}. \n    \\begin{equation} \\label{eq:bkeyinfo}\n    \t\\keyrate{X}{Y}{Y} \\leq \\intrinfo{X}{Y}{Y}\n    \\end{equation}\n    Refer to the next chapter to see an analysis of the gap between the two measures.\n    The amount of secret bits Alice and Bob can extract from the distribution is then bounded by how much the attacker Eve can disrupts their conditional mutual correlation.\n    Intrinsic information is also a lower bound to another measure, \\emph{information of formation}, which is the amount of initial secret bits between Alice and Bob required to create the distribution $P_{XYZ}$ with LOPC.\n    \n   \n\\section{When correlation is unusable}\nSetting the bound in Eq. \\ref{eq:bkeyinfo} we can see that not always factoring out the adversary can be enough to be able to produce a key.\nFor example we could have \n\\begin{align*}\n\t\\keyrate{X}{Y}{Z} & = 0 \\\\\n\t\\intrinfo{X}{Y}{Z} & > 0 \n\\end{align*}\nmeaning that there exists some sort of mutual correlation between Alice and Bob, but they share no key.\nWhether this case is possible is the question of bound information expressed at the beginning of this work.\n\\begin{definition}\\cite{GisWolf00, RW03} \nLet $P_{XYZ}$ be a joint probability distribution for parties Alice, Bob and Eve.\nFor such distribution let \n\\begin{equation}\n\t\\intrinfo{X}{Y}{Z} > 0\n\\end{equation}\nand \n\\begin{equation}\n\\keyrate{X}{Y}{Z} = 0\n\\end{equation}\nhold.\nThen $P_{XYZ}$ is said to have \\emph{bound information}.\n\\end{definition}\n\nRecalling the intuition from quantum mechanics, we now pose the case of the existence of bound entanglement.\nAs stated before (section \\ref{distillation}), quantum distillation extract from an entangled mixed state a set of quasi-pure entangled states.\nPure entangled states can be used as a resource to produce a key for Alice and Bob \\cite{Ekert91}.\nThere are, furthermore, entangled mixed states that are non-distillable, i.e. no pure entanglement can be extracted from them \\cite{3H98}.\nBound entanglement is a kind of correlation between Alice and Bob --- that can become inaccessible to Eve --- but nevertheless of no use for generating a secret (quantum) key.\nSo in the quantum regime this questions has already been answered.\n\t\n\t\n\t\n\t\t\n", "meta": {"hexsha": "b8a838a2f85947ae5c1114bd5432657defbf5e04", "size": 5184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writings/chapters/chapter4.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/chapter4.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/chapter4.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": 60.2790697674, "max_line_length": 297, "alphanum_fraction": 0.7357253086, "num_tokens": 1404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6702645521862728}}
{"text": "\\section{Hausdorff distance}\n\\label{hausdorff_distance_chapter}\n\\nblink{brats/15a\\_hausdorff\\_distance.ipynb}\n\nIn the previous section, we showed differences between the reference neural network output and the output of images where a part of them has been masked by a circle.\nShowing this difference for all the applied masks is impractical. A single visualization which shows all the output segment changes would be helpful.\nA first step is getting a single number for the difference between two segments: The unchanged reference segment vs. output segment from masked image or any generated segment vs. the ground truth.\n\nA way to calculate the similarity or difference between two matrices, e.g. the output segments of the neural network, is a distance function.\n\nWe choose the Hausdorff distance function because it has a specific property that is helpful for our requirements: A slightly moved object is still considered more similar to\nan object with a completely different shape, even when the changed pixel count is exactly the same.\n\n% The formula for the Hausdorff distance is:\n% $ _{\\mathrm {H} }(X,Y)=\\max\\{\\,\\sup _{x\\in X}\\inf _{y\\in Y}d(x,y),\\,\\sup _{y\\in Y}\\inf _{x\\in X}d(x,y)\\} $\n% $X$ and $Y$ are the two sets/matrices which are compared. $d(x,y)$ is the distance between two points. $inf$ and $sup$ are the Infimum and supremum: When comparing two\n% ordered sets A and B, the infinum of A in comparison to B is the biggest item in A that is still smaller than all items of B. The inverse is the supremum,\n% the smallest item in A that is still bigger \n% \\begin{figure}[H]\n% \\centering\n% \\includegraphics[width=8cm]{chapters/06_hdm/images/inf_sup.png}\n% \\caption{Visualization of the Infimum and supremum \\cite{hausdorffdistanceimage2}}\n% \\label{inf_sup}\n% \\end{figure}\n\nIntuitively, the Hausdorff distance searches the two maximal distances between sets (A to B and B to A) and returns the higher one as the distance.\nThe maximal distance from set A to set B is the biggest distance between a pixel from set A to a pixel in set B, but the distance from the pixel from set A to the pixel B has to be the smallest distance from pixel A to any pixel on the set B.\n\nA visual explanation of the Hausdorff distance is given in Figure \\ref{hausdorff_distance}.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=6cm]{chapters/06_hdm/images/hausdorff_distance.png}\n\\caption{Visualization of the Hausdorff distance. The Hausdorff distance from set Y to set X is the maximal distance of a point in set Y to a point in set X, but this distance still has to be the smallest distance from this specific point on set Y to any point on set X \\cite{hausdorffdistanceimage}.}\n\\label{hausdorff_distance}\n\\end{figure}\n\nA naive implementation of the algorithm in Python is given in Listing \\ref{hausdorff_distance_python}.\n\n\\begin{listing}[H]\n\\begin{minted}{python}\ndef inner_hausdorff(X, Y):\n    minimal_distances = []\n    for x in X:\n        distances = []\n        for y in Y:\n            distances.append(distance(x,y))\n        min_distance = min(distances)  # infinum\n        minimal_distances.append(min_distance)\n    return max(minimal_distances) # supremum\n\ndef hausdorff_distance(X, Y):\n    return max(inner_hausdorff(X, Y), inner_hausdorff(Y, X))\n\\end{minted}\n\\caption{Naive implementation of the Hausdorff distance in Python}\n\\label{hausdorff_distance_python}\n\\end{listing}\n\n\\clearpage\n\n\\subsection{Examples}\nThe following visualizations show samples of shapes compared with the Hausdorff distance function.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_original.png}\n        \\caption{Original shape}\n    \\end{subfigure}%\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_moved1.png}\n        \\caption{Shape moved slightly to the right}\n    \\end{subfigure}\n    \\caption{Hausdorff distance between the left and the right figure: 476.}\n    \\label{hdm_moved1}\n\\end{figure}\n\nFigure \\ref{hdm_moved1} shows a slightly moved circle, the Hausdorff distance between the images is quite low with 476.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_original.png}\n        \\caption{Original shape}\n    \\end{subfigure}%\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_moved2.png}\n        \\caption{Shape moved to the right}\n    \\end{subfigure}\n    \\caption{Hausdorff distance between the left and the right figure: 1656. }\n    \\label{hdm_moved2}\n\\end{figure}\n\nFigure \\ref{hdm_moved2} shows a shape that is moved to the right, showing a bigger Hausdorff distance than in Figure \\ref{hdm_moved1} with 1565.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_original.png}\n        \\caption{Original shape}\n    \\end{subfigure}%\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_hole.png}\n        \\caption{Shape moved to the right}\n    \\end{subfigure}\n    \\caption{Hausdorff distance between the left and the right figure: 840. }\n    \\label{hdm_hole}\n\\end{figure}\n\nFigure \\ref{hdm_hole} shows the shape at the same position but with a hole in the middle.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_original.png}\n        \\caption{Original shape}\n    \\end{subfigure}%\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_square.png}\n        \\caption{Shape moved to the right}\n    \\end{subfigure}\n    \\caption{Hausdorff distance between the left and the right figure: 1197. }\n    \\label{hdm_square}\n\\end{figure}\n\nFigure \\ref{hdm_square} shows the shape transformed into a square. The distance between the shapes is much bigger compared the the shape with a hole in it in Figure \\ref{hdm_hole}, even when the\nchanged count of pixels is similar.\n\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_original.png}\n        \\caption{Original shape}\n    \\end{subfigure}%\n    \\begin{subfigure}{.35\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{chapters/06_hdm/images/hdm_smaller_circles.png}\n        \\caption{Shape moved to the right}\n    \\end{subfigure}\n    \\caption{Hausdorff distance between the left and the right figure: 1353.}\n    \\label{hdm_smaller_circles}\n\\end{figure}\n\nFigure \\ref{hdm_smaller_circles} shows the shape completely replaced by three smaller circles. The Hausdorff distance is the highest of all the sample images with 1353.\n", "meta": {"hexsha": "468622c362948c9837f276ead710e3023761f44b", "size": 7020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/06_hdm/03_hausdorff_distance.tex", "max_stars_repo_name": "andef4/thesis-doc", "max_stars_repo_head_hexsha": "a94ecd7cff9f00ecd23ecee319076b78bef79a8e", "max_stars_repo_licenses": ["MIT"], "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/06_hdm/03_hausdorff_distance.tex", "max_issues_repo_name": "andef4/thesis-doc", "max_issues_repo_head_hexsha": "a94ecd7cff9f00ecd23ecee319076b78bef79a8e", "max_issues_repo_licenses": ["MIT"], "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/06_hdm/03_hausdorff_distance.tex", "max_forks_repo_name": "andef4/thesis-doc", "max_forks_repo_head_hexsha": "a94ecd7cff9f00ecd23ecee319076b78bef79a8e", "max_forks_repo_licenses": ["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.2903225806, "max_line_length": 301, "alphanum_fraction": 0.7371794872, "num_tokens": 1902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6702645466134274}}
{"text": "% !TEX encoding = UTF-8 Unicode\n\\section{BLAS - Basic Linear Algebra Subprograms}\n%%%%%%%%%%%%%%%%\n\t\\begin{frame}{BLAS - Basic Linear Algebra Subprograms}{Levels}\n\t\t\\begin{itemize}\n\t\t\t\\item copy\n\t\t\t\\item dot\n\t\t\t\\item saxpy \\\\ \\small $ z = \\alpha x + y $ \\normalsize\n\t\t\t\\item gaxpy \\\\ \\small $ z = Ax + y $ \\normalsize\n\t\t\t\\item matmul \\\\ \\small  $ c = AB $ \\normalsize\n\t\t\\end{itemize}\n\t\tLevel-1, Level-2, Level-3 $ \\Rightarrow O(n), O(n^2), O(n^3)$\n\t\\end{frame}\n\t\\begin{frame}{Levels}\n\t\t\\begin{enumerate}[a)]\n\t\t\t\\item Level 1 BLAS vector-vector operations\n\t\t\t$y \\leftarrow y + \\alpha x$; dot products\n\t\t\t\\begin{figure}\n\t\t\t\t\\includegraphics[height=1cm]{img/13/level1}\n\t\t\t\\end{figure}\n\t\t\t\\item Level 2 BLAS matrix-vector operations\n\t\t\t$y \\leftarrow y + Ax$\n\t\t\t\\begin{figure}\n\t\t\t\t\\includegraphics[height=1cm]{img/13/level2}\n\t\t\t\\end{figure}\n\t\t\t\\item Level 3 BLAS matrix-matrix operations\n\t\t\t$A \\leftarrow A + B \\cdot C$\n\t\t\t\\begin{figure}\n\t\t\t\t\\includegraphics[height=1cm]{img/13/level3}\n\t\t\t\\end{figure}\n\t\t\\end{enumerate}\n\t\\end{frame}\n\t\\begin{frame}{Arithmetic/Memory references}\n\t\tArithmetic is performed at the top of the memory hierarchy!!!\n\t\t\\begin{figure}\n\t\t\t\\includegraphics[height=5cm]{img/13/arithmeticmemref}\n\t\t\\end{figure}\n\t\\end{frame}\n\t\\begin{frame}{Arithmetic/Memory references}\n\t\t\\begin{tabular}{ | l | l | l | l | l |}\n\t\t\\hline\n\t\tBLAS Level & \t\t& flops \t&memref \t& $\\frac{flops}{mem ref}$ \\\\ \\hline\n\t\t1 & $y \\leftarrow y + \\alpha x$ \t& $2n$ \t& $3n$ \t& $\\frac{2}{3} $ \\\\ \\hline\n\t\t2 & $y \\leftarrow y + Ax$ \t\t& $2n^2$ \t& $n^2$ \t& 2 \t\t\t\\\\ \\hline\n\t\t3 & $C \\leftarrow C + AB$ \t& $2n^3$ \t& $4n^2$ \t& $\\frac{n}{2}$ \t\\\\ \\hline\n\t\t\\end{tabular} \\\\ \n\t\t\n\t\tFor level 1: 2 vector loads, 2 vector operations, 1 vector store\\dots \n\t\t\n\t\tHigher level: Increase of granularity $\\Rightarrow$ lower synchronization cost\n\t\\end{frame}\n\t\\begin{frame}{BLAS character}\n\t\t\\begin{itemize}\n\t\t\t\\item \\textit{clarity} - code $\\rightarrow$ shorter, easier to read\n\t\t\t\\item \\textit{modularity} - programmers have larger building blocks\n\t\t\t\\item \\textit{performace} - manufacturers tuned machine-spec. BLAS\n\t\t\t\\item \\textit{program portability} - machine dependencies confined to the BLAS\n\t\t\\end{itemize}\n\t\\end{frame}\n\t\\begin{frame}{BLAS naming conventions}\n\t\\[\n\t\t\\underbrace{1}_{} \\underbrace{2}_{} \\underbrace{3}_{} \\underbrace{4}_{} \\underbrace{5}_{} \\underbrace{6}_{}\n\t\\]\n\t1 $\\rightarrow$ fortran data type of the matrix \\\\\n\t2, 3 $\\rightarrow$ kind of the matrix involved \\\\\n\t4, 5, 6 $\\rightarrow$ type of the operation\n\t\\end{frame}\n\t", "meta": {"hexsha": "80480235b9e2da2221f56094d2c4b7043fb07680", "size": 2511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13_biblioteki/13_1_BLAS.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": "13_biblioteki/13_1_BLAS.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": "13_biblioteki/13_1_BLAS.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": 36.9264705882, "max_line_length": 109, "alphanum_fraction": 0.6507367583, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6702645329779653}}
{"text": "\n\\subsection{MLE of the Gaussian distribution}\n\nThe parameters are the population means and covariance matrix.\n\nThe MLE estimator for the mean is the sample mean.\n\nThe MLE estimator for the covariance matrix is the unadjusted sample covariance.\n\n", "meta": {"hexsha": "96c90debf63edfc005f3dba25db105736b70db99", "size": 246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/MLE/03-01-gaussian.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/MLE/03-01-gaussian.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/MLE/03-01-gaussian.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.6, "max_line_length": 80, "alphanum_fraction": 0.8089430894, "num_tokens": 47, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377272885904, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6702617315431609}}
{"text": "\\documentclass[a4paper,10pt]{article}\r\n\\usepackage{amsfonts}\r\n\\usepackage{amsmath}\r\n\\usepackage{eucal}\r\n\\usepackage{amscd}\r\n\\usepackage{url}\r\n\r\n\\newcommand{\\Z}{\\mathbb{Z}}\r\n\\newcommand{\\N}{\\mathbb{N}}\r\n\\newcommand{\\Q}{\\mathbb{Q}}\r\n\\newcommand{\\I}{\\mathbb{I}}\r\n\\newcommand{\\C}{\\mathbb{C}}\r\n\\newcommand{\\R}{\\mathbb{R}}\r\n\\newcommand{\\Pee}{\\mathbb{P}}\r\n\\newcommand{\\EuO}{\\mathcal{O}}\r\n\\newcommand{\\Qbar}{\\overline{\\mathbb{Q}}}\r\n\\newcommand{\\code}{\\lstinline}\r\n\r\n\\newcommand{\\ljk}[2]{\\left(\\frac{#1}{#2}\\right)}\r\n\\newcommand{\\trans}[2]{(\\,#1\\;\\;#2\\,)}\r\n\\newcommand{\\modulo}[1]{\\;\\left(\\mbox{mod}\\;#1\\right)}\r\n\\newcommand{\\fr}{\\mathfrak}\r\n\\newcommand{\\qed}{\\square}\r\n\r\n\\DeclareMathOperator{\\Log}{Log}\r\n\r\n\\def\\notdivides{\\mathrel{\\kern-3pt\\not\\!\\kern4.5pt\\bigm|}}\r\n\\def\\nmid{\\notdivides}\r\n\\def\\nsubseteq{\\mathrel{\\kern-3pt\\not\\!\\kern2.5pt\\subseteq}}\r\n\r\n\\newtheorem{theorem}{Theorem}[section]\r\n\\newtheorem{lemma}[theorem]{Lemma}\r\n\\newtheorem{proposition}[theorem]{Proposition}\r\n\\newtheorem{corollary}[theorem]{Corollary}\r\n\r\n\\newenvironment{proof}[1][Proof]{\\begin{trivlist}\r\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\r\n\\newenvironment{definition}[1][Definition]{\\begin{trivlist}\r\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\r\n\\newenvironment{example}[1][Example]{\\begin{trivlist}\r\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\r\n\\newenvironment{remark}[1][Remark]{\\begin{trivlist}\r\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\r\n\r\n\\parindent=0pt\r\n\\parskip 4pt plus 2pt minus 2pt \r\n\r\n\\title{Complex Variables}\r\n\\author{William Hart}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\r\n\\section{Limits}\r\n\r\n\\begin{definition}\r\nWe say that the \\textbf{limit} of a complex function $f(z)$ as $z$ approaches $z_0$ is $w$, written\r\n$$\\lim_{z\\to z_0}f(z) = w$$\r\nif for each $\\epsilon > 0$ there is a $\\delta > 0$ such that $|f(z) - w| < \\epsilon$ whenever $0 < |z - z_0| < \\delta$. \r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nLet $f(z) = u(x, y) + iv(x, y)$ and $z_0 = x_0 + iy_0$ for real valued functions $u$ and $v$ and real variables $x_0$ and $y_0$. Then \r\n$$\\lim_{z \\to z_0}f(z) = u_0 + iv_0$$\r\niff\r\n$$\\lim_{(x, y) \\to (x_0, y_0)}u(x, y) = u_0 \\;\\;\\mbox{and}\\;\\; \\lim_{(x, y) \\to (x_0, y_0)}v(x, y) = v_0.$$\r\n\\end{theorem}\r\n\r\nPick $\\delta_1$ and $\\delta_2$ such that $|u - u_0|$ and $|v - v_0|$ are both less than $\\epsilon/2$ whenever $||(x, y) - (x_0, y_0)||$ is less than $\\delta_1$ or $\\delta_2$ respectively.\r\n\r\nBoth hold if we use $\\delta =$ min$(\\delta_1, \\delta_2)$ instead.\r\n\r\nUsing the triangle inequality, we can bound $|(u + iv) - (u_0 + iv_0)|$ by $\\epsilon$ and the result follows from the definition of the limit.\r\n\r\nThe converse also follows by application of the triangle inequality.\r\n\r\n\\begin{theorem}\r\nSuppose that\r\n$$\\lim_{z\\to z_0}f_1(z) = w_1 \\;\\;\\mbox{and}\\;\\; \\lim_{z\\to z_0}f_2(z) = w_2$$\r\nthen\r\n\\begin{itemize}\r\n\\item $\\lim_{z \\to z_0}f_1(z) + f_2(z) = w_1 + w_2$\r\n\\item $\\lim_{z \\to z_0}f_1(z)f_2(z) = w_1w_2$\r\n\\item If $w_2 \\neq 0$ then $\\lim_{z \\to z_0}\\frac{f_1(z)}{f_2(z)} = \\frac{w_1}{w_2}.$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nThese follow from the corresponding results for real functions.\r\n\r\n\\begin{definition}\r\nBy \r\n$$\\lim_{z \\to z_0}f(z) = \\infty$$\r\nwe mean that for each $\\epsilon > 0$ there is a $\\delta > 0$ such that $|f(z)| > \\frac{1}{\\epsilon}$ whenever $0 < |z - z_0| < \\delta$ and by\r\n$$\\lim_{z\\to \\infty}f(z) = w$$\r\nwe mean that for each $\\epsilon > 0$ there exists a $\\delta > 0$ such that $|f(z) - w| < \\epsilon$ whenever $|z| > \\frac{1}{\\delta}$.\r\n\\end{definition}\r\n\r\n\\section{Continuity}\r\n\r\n\\begin{definition}\r\nA function $f(z)$ of a complex variable is \\textbf{continuous} at $z_0$ if \r\n$$\\lim_{z \\to z_0}f(z) = f(z_0).$$\r\nWe say that $f$ is continuous in a region $R$ if it is continuous at every point in $R$.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nWe have that\r\n\\begin{itemize}\r\n\\item the sum and product of continuous functions is continuous. \r\n\\item excluding division by zero, the quotient of continuous functions is continuous. \r\n\\item The composition $f(g(z))$ of continuous functions $f(w)$, $g(z)$ is continuous. \r\n\\item the function $f(z) = u(x, y) + iv(x, y)$ for $z = x + iy$ is continuous iff the components $u, v$ are continuous functions of two real variables.\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nAll of these follow easily from the definition and relevant properties of limits.\r\n\r\n\\begin{corollary}\r\nAny polynomial function $f(z) = a_0 + a_1z + \\cdots + a_nz^n$ for $a_i \\in \\C$ is continuous everywhere in the complex plane.\r\n\\end{corollary}\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ and $g(z)$ are continuous at $z_0$ then\r\n\\begin{itemize}\r\n\\item $f(z) + g(z)$ is continuous at $z_0$\r\n\\item $f(z)g(z)$ is continuous at $z_0$\r\n\\item $f(z)/g(z)$ is continuous at $z_0$ if $g(z_0) \\neq 0$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nThese follow from the corresponding results on limits.\r\n\r\n\\begin{theorem}\r\nIf $f(x)$ is continuous at $x_0$, $z_0 = f(x_0)$ and $g(z)$ is continuous at $z_0$ then $(g\\circ f)(x)$ is continuous at $x_0$.\r\n\\end{theorem}\r\n\r\nWe have an $(\\epsilon, \\delta)$ statement for $g(z)$ at $z_0$. By continuity of $f(x)$ at $x_0$ we know there is a $\\gamma > 0$ such that $|f(x) - f(x_0)| < \\delta$ whenever $|x - x_0| < \\gamma$. Thus we have an $(\\epsilon, \\gamma)$ statement for $(g\\circ f)(x)$.\r\n\r\n\\begin{corollary}\r\nIf $f(z)$ is continuous at $z_0$ and $f(z_0) \\neq 0$, then there is a neighbourhood of $z_0$ for which $f(z) \\neq 0$.\r\n\\end{corollary}\r\n\r\nIf $|f(z_0)| = \\epsilon$, there is a $\\delta$ neighbourhood of $z_0$ for which $|f(z) - f(z_0)| < \\epsilon$, i.e. $f(z)$ can't reach as far as $0$ in this neighbourhood.\r\n\r\n\\begin{theorem}\r\nA function $f(z) = u(x, y) + iv(x, y)$ for real-valued functions $u$ and $v$ is continuous at $z_0$ iff $u$ and $v$ are.\r\n\\end{theorem}\r\n\r\nThis follows from the corresponding theorem for limits.\r\n\r\n\\begin{corollary}\r\nIf $f(z)$ is continuous on a closed, bounded region $R$, then $f$ is bounded on $R$ and $|f(z)|$ achieves a maximum somewhere on $R$.\r\n\\end{corollary}\r\n\r\nWrite $f(z) = u(x, y) + iv(x, y)$ for real-valued $u$ and $v$. By the theorem $u$ and $v$ are continuous on $R$. Thus $u$ and $v$ and hence $f$ are bounded on $R$.\r\n\r\nThe function $\\sqrt{u(x, y)^2 + v(x, y)^2}$ achieves a maximum on $R$, and thus so does $|f(z)|$.\r\n\r\n\\begin{definition}\r\nWe say that a function $f(z)$ is \\textbf{uniformly continuous} on a region $R$ if for any $\\epsilon > 0$ there is a single value of $\\delta > 0$ such that\r\n$$|f(z) - f(z_0)| < \\epsilon \\;\\;\\mbox{whenever}\\;\\; |z - z_0| < \\delta$$\r\nfor all $z_0 \\in R$.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nA function $f(z)$ which is continuous in a closed, bounded region $R$ is uniformly continuous there.\r\n\\end{theorem}\r\n\r\nWrite $f(z) = u(x, y) + iv(x, y)$ for real-valued $u$ and $v$. The result follows from the corresponding theorem for real-valued functions.\r\n\r\n\\section{Derivatives}\r\n\r\n\\begin{definition}\r\nLet $f(z)$ be a function defined in a neighbourhood of a point $z_0$. The \\textbf{derivative} of $f$ at $z_0$ is defined to be\r\n$$f'(z_0) = \\lim_{z\\to z_0} \\frac{f(z) - f(z_0)}{z - z_0}$$\r\nif the limit exists. The function is said to be \\textbf{differentiable} at $z_0$ if it does.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nIf the derivative of $f(z)$ exists at $z_0$ then $f(z)$ is continuous there.\r\n\\end{theorem}\r\n\r\nMultiply the expression for the derivative at $z_0$ above by $\\lim_{z\\to z_0}(z - z_0) = 0$ and we have that $\\lim_{z\\to z_0}(f(z) - f(z_0)) = 0$. This is precisely the statement of the continuity of $f(z)$ at $z_0$.\r\n\r\n\\begin{theorem}\r\nIf $c \\in \\C$ and $f(z)$ is differentiable then\r\n\\begin{itemize}\r\n\\item $\\frac{d}{dz}c = 0$\r\n\\item $\\frac{d}{dz}z = 1$\r\n\\item $\\frac{d}{dz}cf(z) = cf'(z)$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nThese follow directly from the definition.\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$\\frac{d}{dz}z^n = nz^{n-1}$$\r\nfor all $n > 0$, and also for $n < 0$ when $z \\neq 0$.\r\n\\end{theorem}\r\n\r\nTo prove this, we use the definition of the derivative and write $\\delta = z - z_0$. We expand $(z_0 + \\delta)^n$ using the binomial theorem.\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ and $g(z)$ are both differentiable at $z$ then\r\n\\begin{itemize}\r\n\\item $\\frac{d}{dz}\\left(f(z) + g(z)\\right) = f'(z) + g'(z)$\r\n\\item $\\frac{d}{dz}\\left(f(z)g(z)\\right) = f(z)g'(z) + f'(z)g(z)$\r\n\\item $\\frac{d}{dz}\\left(f(z)/g(z)\\right) = \\frac{f'(z)g(z) - f(z)g'(z)}{g(z)^2}$ when $g(z) \\neq 0$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nThe first part follows directly from the definitions.\r\n\r\nFor the second part we use\r\n\\begin{multline*}\r\nf(z + \\delta)g(z + \\delta) - f(z)g(z) = f(z)\\left[g(z + \\delta) - g(z)\\right] \\\\\r\n         + \\left[f(z + \\delta) - f(z)\\right]g(z + \\delta).\r\n\\end{multline*}\r\n\r\nFor the third part, we prove the result first for $f(z) = 1$, which follows from the definition, and then use the second part.\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ has a derivative at $z_0$ and $g(z)$ has a derivative at $f(z_0)$ then $h(z) = g(f(z))$ has a derivative at $z_0$, and\r\n$$h'(z_0) = g'\\left[f(z_0)\\right]f'(z_0).$$\r\n\\end{theorem}\r\n\r\nWriting $w = f(z)$ and $w_0 = f(z_0)$ we must show that\r\n$$\\lim_{z\\to z_0}\\frac{g(w) - g(w_0)}{z - z_0} = g'(w_0)\\lim_{z\\to z_0}\\frac{w - w_0}{z - z_0}.$$\r\n\r\nThis would be true if\r\n$$g(w) - g(w_0) = (g'(w_0) + T(w))(w - w_0),$$\r\nfor $T(w)$ defined in a neighbourhood of $w_0$, so long as $\\lim_{z\\to z_0}T(w) = 0$.\r\n\r\nThe function defined by\r\n$$T(w) = \\frac{g(w) - g(w_0)}{w - w_0} - g'(w_0),$$\r\nwhen $w \\neq w_0$ and $T(w) = 0$ at $w = w_0$, has precisely the required properties.\r\n\r\nIt is easy to see that $T(w)$ is continuous at $w = w_0$ and $w = f(z)$ is continuous at $z = z_0$. Thus $T(w) = T(f(z))$ is continuous at $z_0$. Thus\r\n$$\\lim_{z\\to z_0}T(f(z)) = T(f(z_0)) = T(w_0) = 0,$$\r\nas required.\r\n\r\n\\section{The Cauchy-Riemann identities}\r\n\r\nWe can find some necessary conditions for $f(z) = u(x, y) + iv(x, y)$ to be differentiable at $z_0 = x_0 + iy_0$.\r\n\r\n\\begin{theorem}\r\nIf $f(z) = u(x, y) + iv(x, y)$ is differentiable at $z_0 = x_0 + iy_0$ then\r\n\\begin{equation}\r\n\\begin{split}\r\nf'(z_0) & = u_x(x_0, y_0) + iv_x(x_0, y_0) \\\\\r\n        & = -i\\left[u_y(x_0, y_0) + iv_y(x_0, y_0)\\right]\r\n\\end{split}\r\n\\end{equation}\r\n\\end{theorem}\r\n\r\nThis follows by expanding the expression for $f'(z)$ in terms of $u$ and $v$ and noting that the limits must still hold if we approach $z_0$ along the line $z = x + iy_0$ or along the line $z = x_0 + iy$, respectively.\r\n\r\n\\begin{corollary} (Cauchy-Riemann)\r\nIf $f(z) = u(x, y) + iv(x, y)$ is differentiable at $z_0 = x_0 + iy_0$ then\r\n$$u_x(x_0, y_0) = v_y(x_0, y_0)$$\r\nand\r\n$$u_y(x_0, y_0) = -v_x(x_0, y_0).$$\r\n\\end{corollary}\r\n\r\nWe obtain this by equating the two expressions in the theorem and comparing real and imaginary parts.\r\n\r\nThe Cauchy-Riemann equations are only a necessary condition. But with some additional continuity conditions, we can find sufficient conditions for differentiability.\r\n\r\n\\begin{theorem}\r\nIf $f(z) = u(x, y) = iv(x, y)$ is defined in a neighbourhood of $z_0 = x_0 + iy_0$ then $f'(z_0)$ exists if \r\n\\begin{itemize}\r\n\\item the partial derivatives of $u$ and $v$ exist everywhere in the neighbourhood\r\n\\item the partial derivatives are continuous at $(x_0, y_0)$\r\n\\item the Cauchy-Riemann equations hold at $(x_0, y_0)$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nBecause the partial derivatives are continuous at $(x_0, y_0)$ we can write\r\n$$\\Delta u = u_x(x_0, y_0)\\Delta x + u_y(x_0, y_0)\\Delta y + \\epsilon_1 |\\Delta z|$$\r\nand\r\n$$\\Delta v = v_x(x_0, y_0)\\Delta x + v_y(x_0, y_0)\\Delta y + \\epsilon_2 |\\Delta z|$$\r\nfor some functions $\\epsilon_1$, $\\epsilon_2$ that tend to $0$ as $(\\Delta x, \\Delta y)$ tends to $(0, 0)$.\r\n\r\nMaking use of the Cauchy-Riemann relations, we obtain an expression for $f'(z_0)$ which clearly exists.\r\n\r\nOne can restate the Cauchy-Riemann equations in polar coordinates when $z_0 \\neq 0$.\r\n\r\nTo convert to polar form, we write\r\n$$x = r\\cos\\theta \\;\\;\\mbox{and}\\;\\; y = r\\sin\\theta.$$\r\n\r\n\\begin{theorem} (Cauchy-Riemann)\r\nIf $f(z) = u(r, \\theta) + iv(r, \\theta)$ is differentiable at $z_0 \\neq 0$ then\r\n$$u_r = v_\\theta/r \\;\\;\\mbox{and}\\;\\; u_\\theta = -rv_r.$$\r\nThe derivative is given by\r\n$$f'(z_0) = e^{-i\\theta_0}\\left(u_r(r_0, \\theta_0) + iv_r(r_0, \\theta_0)\\right).$$\r\n\\end{theorem}\r\n\r\nWe have\r\n$$u_r = u_x\\cos\\theta + u_y\\sin\\theta$$\r\n$$u_\\theta = -u_x r\\sin\\theta + u_y r\\cos\\theta$$\r\n$$v_r = v_x\\cos\\theta + v_y\\sin\\theta$$\r\n$$v_\\theta = -v_x r\\sin\\theta + v_y r\\cos\\theta.$$\r\n\r\nApplying the Cauchy-Riemann relations yields the stated result.\r\n\r\nThe necessary conditions for differentiability become the following.\r\n\r\n\\begin{theorem}\r\nIf $f(z) = u(r, \\theta) + iv(r, \\theta)$ is defined in a neighbourhood of $z_0 = r_0\\exp(i\\theta_0) \\neq 0$ then $f'(z_0)$ exists if\r\n\\begin{itemize}\r\n\\item the partial derivatives of $u$ and $v$ with respect to $r$ and $\\theta$ exist\r\n\\item the partial derivatives are continuous at $(r_0, \\theta_0)$\r\n\\item the partial derivatives satisfy the polar form of the Cauchy-Riemann relations\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nThis is a straightforward translation of the result for rectangular coordinates.\r\n\r\n\\begin{definition}\r\nA region of the complex plane is \\textbf{connected} if any two points in the region can be joined by a series of straight lines.\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nA \\textbf{domain} is an open region of the complex plane that is connected.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nIf $f'(z) = 0$ at all points in a domain $D$ then $f(z)$ is constant in $D$.\r\n\\end{theorem}\r\n\r\nWe write $f(z) = u(x, y) + iv(x, y)$ and note that if $f'(z) = 0$ then $u_x + iv_x = 0$. By the Cauchy-Riemann equations we then have\r\n$$u_x = u_y = v_x = v_y = 0.$$\r\n\r\nBut this means that any directional derivative of $u$ at any point in $D$ is zero, and similarly for $v$. In particular, this means that the value of $f$ along any line in $D$ must be constant.\r\n\r\nAs $D$ is connected, the result follows.\r\n\r\n\\section{Analytic functions}\r\n\r\n\\begin{definition}\r\nA function $f(z)$ is \\textbf{analytic} (or holomorphic) in an open set if it is differentiable at each point in that set. The function $f(z)$ is analytic at a point $z_0$ if it is analytic in a neighbourhood of $z_0$.\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nA function $f(z)$ is \\textbf{entire} if it is analytic at every point in the complex plane.\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nIf a function $f(z)$ is analytic at every point in a neighbourhood of $z_0$ except $z_0$ itself, then $z_0$ is called a \\textbf{singular} point of $f$.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ and $g(z)$ are analytic in a domain $D$ then\r\n\\begin{itemize}\r\n\\item $f(z) + g(z)$ is analytic in $D$\r\n\\item $f(z)g(z)$ is analytic in $D$\r\n\\item $f(z)/g(z)$ is analytic in $D$ if $g(z) \\neq 0$ for all $z \\in D$\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ is analytic in a domain $D$ and $g(z)$ is analytic in a domain containing the image of $D$ under $z \\mapsto f(z)$, then $g(f(z))$ is analytic in $D$.\r\n\\end{theorem}\r\n\r\nThese follow from the corresponding facts about differentiability.\r\n\r\n\\section{The exponential function}\r\n\r\nFor real-valued $x$, the exponential function $e^x$ satisfies two important identities.\r\n\r\n\\begin{itemize}\r\n\\item $e^x$ is entire and $\\frac{d}{dx}e^x = e^x$\r\n\\item for all $x, y \\in \\R$ we have $e^{x + y} = e^xe^y$\r\n\\end{itemize}\r\n\r\nWhen defining the exponential function $e^z$ for complex $z = x + iy$ it is natural to define it to be a function that has the above properties and that reduces to the ordinary real-valued function when $y = 0$.\r\n\r\nIn fact, there is a unique complex-valued function with these properties.\r\n\r\n\\begin{theorem}\r\nThe function\r\n$$f(z) = e^x(\\cos y + i\\sin y)$$\r\nis entire and $f'(z) = f(z)$.\r\n\\end{theorem}\r\n\r\nWriting $f(z) = u(x, y) + iv(x, y)$ we have $u_x = v_y$ and $u_y = -v_x$, which are everywhere continuous. Thus $f(z)$ is differentiable everywhere.\r\n\r\nWe have that $f'(z) = u_x + iv_x = f(z)$.\r\n\r\nNote that $f(z)$ as defined in the theorem reduces to $e^x$ when $y = 0$.\r\n\r\n\\begin{theorem}\r\nThe only complex-valued function $f(z)$ which satisfies\r\n\\begin{itemize}\r\n\\item $f(x) = e^x$ for $x \\in \\R$\r\n\\item $f$ is entire and $f'(z) = f(z)$ for all $z \\in \\C$\r\n\\end{itemize}\r\nis the function $f(z) = e^x(\\cos y + i\\sin y)$.\r\n\\end{theorem}\r\n\r\nLet us write $e^z$ as a shorthand for $e^x(\\cos y + i\\sin y)$. Let $f(z)$ be a function with the required properties. Write $g(z) = f(z)e^{-z}$.\r\n\r\nAs $f(z)$ and $e^{-z}$ are entire, so is $g(z)$. By the product rule and chain rule, we have\r\n$g'(z) = f'(z)e^{-z} - f(z)e^{-z} = 0$.\r\n\r\nThus $g'(z) = c$ for some constant $c \\in \\C$, i.e. $f(z) = c/e^{-z} = ce^z$ as can be verified by expanding out $e^{-z}$.\r\n\r\nClearly $c = 1$ in order for the first condition to hold.\r\n\r\nIt makes sense to define the complex exponential as follows.\r\n\r\n\\begin{definition}\r\nWe define\r\n$$e^z = e^x(\\cos y + i\\sin y),$$\r\nfor all $z = x + iy \\in \\C$.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$e^{z_1 + z_2} = e^{z_1}e^{z_2},$$\r\nfor all $z_1, z_2 \\in \\C$.\r\n\\end{theorem}\r\n\r\nWrite $z_1 = x_1 + iy_1$ and $z_2 = x_2 + iy_2$. We check that\r\n$$(\\cos y_1 + i\\sin y_1)(\\cos y_2 + i\\sin y_2) = \\cos (y_1 + y_2) + i\\sin (y_1 + y_2)$$\r\nusing standard trig identities. The rest of the result is straightforward.\r\n\r\n\\begin{corollary}\r\nFor $n \\in \\Z$ we have\r\n$$e^{nz} = (e^z)^n.$$\r\n\\end{corollary}\r\n\r\nFollows from the theorem by induction for positive $n$. As we already saw above, $e^{-z} = 1/e^z$, so the result also follows for negative $n$. For $n = 0$, use $e^0 = e^ze^{-z} = 1$.\r\n\r\n\\section{Trigonometric functions}\r\n\r\nFrom $e^{iy} = \\cos y + i\\sin y$ and $e^{-iy} = \\cos y - i\\sin y$ we obtain\r\n$$\\sin y = \\frac{e^{iy} - e^{-iy}}{2i} \\;\\;\\mbox{and}\\;\\; \\cos y = \\frac{e^{iy} + e^{-iy}}{2}.$$\r\n\r\nThis leads us to the following definition.\r\n\r\n\\begin{definition}\r\nFor $z \\in C$ we define\r\n$$\\sin z = \\frac{e^{iz} - e^{-iz}}{2i} \\;\\;\\mbox{and}\\;\\; \\cos y = \\frac{e^{iz} + e^{-iz}}{2}.$$\r\n\\end{definition}\r\n\r\nThese are entire function by the rules of sums and quotients of entire functions.\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$\\frac{d}{dz}\\sin z = \\cos z \\;\\;\\mbox{and}\\;\\; \\frac{d}{dz}\\cos z = -\\sin z.$$\r\n\\end{theorem}\r\n\r\nThis follows directly from the definition and the derivative of the exponential function.\r\n\r\nWe also have\r\n$$\\sin(-z) = -\\sin z \\;\\;\\mbox{and}\\;\\; \\cos(-z) = \\cos z.$$\r\n\r\n\\begin{theorem}\r\nWe have the following identities\r\n$$\\sin(z_1 + z_2) = \\sin z_1\\cos z_2 + \\cos z_1\\sin z_2$$\r\n$$\\cos(z_1 + z_2) = \\cos z_1\\cos z_2 - \\sin z_1\\sin z_2$$\r\n$$\\sin^2 z + \\cos^2 z = 1$$\r\n$$\\sin(z + \\pi/2) = \\cos z$$\r\n$$\\sin(z - \\pi/2) = -\\cos z$$\r\n$$\\sin(z + \\pi) = -\\sin z$$\r\n$$\\cos(z + \\pi) = -\\cos z$$\r\n$$\\sin(z + 2\\pi) = \\sin z$$\r\n$$\\cos(z + 2\\pi) = \\cos z$$\r\n\\end{theorem}\r\n\r\nThese follow by straightforward algebraic manipulation and standard trig identities for real variables.\r\n\r\nRecall that for $y \\in \\R$ we have\r\n$$\\sinh y = \\frac{e^y - e^{-y}}{2} \\;\\;\\mbox{and}\\;\\; \\cosh y = \\frac{e^y + e^{-y}}{2}.$$\r\n\r\nWe can use these to obtain the real and complex parts of $\\sin$ and $\\cos$.\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$\\sin z = \\sin x\\cosh y + i\\cos x \\sinh y$$\r\n$$\\cos z = \\cos x\\cosh y - i\\sin x \\sinh y$$\r\n\\end{theorem}\r\n\r\nWe note that $\\sin(iy) = i\\sinh y$ and $\\cos(iy) = \\cosh y$.\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$|\\sin z|^2 = \\sin^2 x + \\sinh^2 y$$\r\n$$|\\cos z|^2 = \\cos^2 x + \\sinh^2 y$$\r\n\\end{theorem}\r\n\r\nWe use the previous theorem and the fact that $\\sin^2 y + \\cos^2 y = 1$ and $\\cosh^2 y - \\sinh^2 y = 1$.\r\n\r\n\\begin{theorem}\r\nThe zeroes of $\\sin z$ are $z = n\\pi$ for $n \\in \\Z$, and the zeroes of $\\cos z$ are offset from those by $\\pi/2$.\r\n\\end{theorem}\r\n\r\nWe use the previous theorem and note that we must have $\\sin x = 0$ and $\\sinh y = 0$.\r\n\r\n\\begin{definition}\r\nWe define\r\n$$\\tan z = \\frac{\\sin z}{\\cos z}, \\;\\; \\cot z = \\frac{\\cos z}{\\sin z},$$\r\n$$\\sec z = \\frac{1}{\\cos z}, \\;\\; \\csc z = \\frac{1}{\\sin z}.$$\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$\\frac{d}{dz}\\tan z = \\sec^2 z, \\;\\; \\frac{d}{dz}\\cot z = -\\csc^2 z,$$\r\n$$\\frac{d}{dz}\\sec z = \\sec z\\tan z, \\;\\; \\frac{d}{dz}\\csc z = -\\csc z\\cot z.$$\r\n\\end{theorem}\r\n\r\nWe use the quotient rule in the definitions and standard trig identities.\r\n\r\n\\section{The logarithm}\r\n\r\nRecall that $\\ln x$ is the inverse of the exponential function $e^x$ for $x \\in \\R$. As the latter takes on every positive real value, the domain of $\\ln x$ is $\\R^{+}$.\r\n\r\n\\begin{theorem}\r\nIf $z = re^{i\\theta}$ is a complex number in modulus/argument format, with $-\\pi < \\theta \\leq \\pi$, the multi-valued function\r\n$$\\log z = \\ln r + i(\\theta + 2n\\pi), \\;\\; n \\in \\Z$$\r\nsatisfies\r\n$$e^{\\log z} = z.$$\r\n\\end{theorem}\r\n\r\nAs $e^{2\\pi i} = 1$, the result follows by substitution.\r\n\r\n\\begin{definition}\r\nWe define the complex logarithm by\r\n$$\\log z = \\ln r + i(\\theta + 2n\\pi), \\;\\; n \\in \\Z$$\r\nfor all $z = re^{i\\theta}$ with $-\\pi < \\theta \\leq \\pi$. The function\r\n$$\\Log z = \\ln r + i\\theta$$\r\nis called the \\textbf{principal branch} of $\\log z$.\r\n\\end{definition}\r\n\r\nRecall that $\\ln x$ is continuous and differentiable for $x > 0$ with\r\n$$\\frac{d}{dx}\\ln x = \\frac{1}{x}.$$\r\n\r\n\\begin{theorem}\r\nThe function $\\Log z$ is analytic (and therefore continuous) on the domain $r > 0$, $-\\pi < \\theta < \\pi$.\r\n\\end{theorem}\r\n\r\nWriting $\\Log z$ in polar form we get $u(r, \\theta) = \\ln r$ and $v(r, \\theta) = \\theta$. The first order partial derivatives are continuous on the stated domain.\r\n\r\nWe also have\r\n$$u_r = v_\\theta/r \\;\\;\\mbox{and}\\;\\; u_\\theta = -rv_r,$$\r\nso that the polar form of the Cauchy-Riemann equations is satisfied. Thus $\\Log z$ is analytic on the stated domain.\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$\\frac{d}{dz}\\Log z = \\frac{1}{z}$$\r\non the domain $r > 0$, $-\\pi < \\theta < \\pi$.\r\n\\end{theorem}\r\n\r\nWe have\r\n$$\\frac{d}{dz}\\Log z = e^{-i\\theta}(u_r + iv_r) = \\frac{1}{re^{i\\theta}} = \\frac{1}{z}.$$\r\n\r\n\\begin{definition}\r\nA \\textbf{branch} of a multi-valued function $f(z)$ is a single-valued function $F(z)$ analytic on some domain where it takes one of the values of $f(z)$.\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nA \\textbf{branch cut} is a line or curve that is used to define a branch $F(z)$ of a multi-valued function $f(z)$. Points on a branch cut are singular values for the single valued function $F(z)$. Any point that is on every branch cut of $f$ is called a \\textbf{branch point}.\r\n\\end{definition}\r\n\r\nFor example, the ray $\\theta = \\pi$ is a branch cut for $\\log z$, and the origin is a branch point.\r\n\r\nThe following theorem holds for the multivalued function $\\log$, by which we mean that if two of the values in the identity are specified, there is a value of the third function making the identity hold.\r\n\r\n\\begin{theorem}\r\nWe have\r\n$$\\log(z_1z_2) = \\log z_1 + \\log z_2$$\r\nfor all $z_1, z_2 \\in \\C$.\r\n\\end{theorem}\r\n\r\nThis follows immediately from the definition of $\\log z$.\r\n\r\nNote that this result doesn't hold everywhere for the principal branch.\r\n\r\n\\section{Complex exponents}\r\n\r\n\\begin{definition}\r\nFor $z \\neq 0$ and $c$ any complex number, we define\r\n$$z^c = e^{c\\log z}.$$\r\n\\end{definition}\r\n\r\nNote that this is may be multi-valued function. For example, if $c = 1/n$ for an integer $n$, then there are $n$ distinct values of the function.\r\n\r\n\\begin{definition}\r\nThe \\textbf{principal value} of $z^c$ is given when $\\log z$ is replaced with the principal branch $\\Log z$ in the definition.\r\n\\end{definition}\r\n\r\n\\begin{theorem}\r\nThe derivative of a branch of $z^c$ is given by\r\n$$\\frac{d}{dz}z^c = cz^{c - 1},$$\r\nwhich is single-valued on the same domain as $z^c$.\r\n\\end{theorem}\r\n\r\nFollows by the chain rule.\r\n\r\n\\section{Inverse trigonometric functions}\r\n\r\n\\begin{theorem}\r\nThe inverse sine function is given by the multi-valued function\r\n$$\\sin^{-1} z = -i\\log\\left[iz + (1 - z^2)^{1/2}\\right].$$\r\n\\end{theorem}\r\n\r\nWe want $w$ where\r\n$$z = \\frac{e^{iw} - e^{-iw}}{2i}.$$\r\n\r\nExpressing as a quadratic and solving for $e^{iw}$ we get\r\n$$e^{iw} = iz + (1 - z^2)^{1/2}.$$\r\n\r\nTaking logarithms of both sides yields the stated result.\r\n\r\nThe same technique can be used to show the following.\r\n\r\n\\begin{theorem}\r\n$$\\cos^{-1} z = -i\\log\\left[z + i(1 - z^2)^{1/2}\\right]$$\r\n\\end{theorem}\r\n\r\n\\begin{theorem}\r\n$$\\tan^{-1} z = \\frac{i}{2}\\log\\frac{i+z}{i-z}.$$\r\n\\end{theorem}\r\n\r\nWe easily differentiate these expressions to obtain the following.\r\n\r\n\\begin{theorem}\r\n$$\\frac{d}{dz}\\sin^{-1} z = \\frac{1}{(1 - z^2)^{1/2}},$$\r\n$$\\frac{d}{dz}\\cos^{-1} z = -\\frac{1}{(1 - z^2)^{1/2}},$$\r\n$$\\frac{d}{dz}\\tan^{-1} z = \\frac{1}{1 + z^2}.$$\r\n\\end{theorem}\r\n\r\nThe first two depend on the choice of square root made, whereas the last is single-valued regardless of what branch of $\\log$ is taken.\r\n\r\n\\section{Complex-valued functions of a real variable}\r\n\r\n\\begin{definition}\r\nIf $f(t) = u(t) + iv(t)$ is a complex-valued function of a real parameter $t$, the derivative of $f$ with respect to $t$ is given by\r\n$$f'(t) = u'(t) + iv'(t).$$\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nIf $f(t) = u(t) + iv(t)$ is a complex-valued function of a real parameter $t$, the definite integral of $f$ with respect to $t$ in the interval $a \\leq t \\leq b$ is given by\r\n$$\\int_a^b f(t)dt = \\int_a^b u(t) + i\\int_a^b v(t)dt.$$\r\n\\end{definition}\r\n\r\nThe definite integral exists if both $u$ and $v$ are piecewise continuous on the interval $a \\leq t \\leq b$.\r\n\r\nSimilar definitions exist for improper integrals.\r\n\r\nThe Fundamental Theorem of Calculus holds for functions of this type.\r\n\r\n\\begin{theorem}\r\nIf $f(t) = u(t) + iv(t)$ and $F(t) = U(t) + iV(t)$ are continuous on $a \\leq t \\leq b$ with $F'(t) = f(t)$ then\r\n$$\\int_a^b f(t)dt = F(b) - F(a).$$\r\n\\end{theorem}\r\n\r\nFollows from the definition of the integral.\r\n\r\n\\begin{theorem}\r\nFor $a \\leq b$ we have\r\n$$\\left|\\int_a^b f(t)dt\\right| \\leq \\int_a^b |f(t)|dt.$$\r\n\\end{theorem}\r\n\r\nWe obtain the absolute value of the integral on the left side by multiplying it by the inverse of $e^{i\\theta}$ where $\\theta$ is its argument. The scaled integral then has a real value.\r\n\r\nThis means we only need to consider the real part of this scaled integral. But\r\n$$\\mbox{Re}(e^{-i\\theta}f(t)) \\leq \\left|e^{-i\\theta}f(t)\\right| = \\left|f(t)\\right|.$$\r\n\r\nThis gives the stated inequality by standard inequalities for integrals of real-valued functions.\r\n\r\n\\section{Contours}\r\n\r\nIntegrals of complex-valued functions of a complex variable $z$ are defined for curves in the complex plane. The curve is first parameterised by a real parameter $t$, so that we can use the integrals of the previous section to define such path integrals.\r\n\r\n\\begin{definition}\r\nAn \\textbf{arc} $C$ in the complex plane is a set of points $z = x(t) + iy(t)$ for $a \\leq t \\leq b$ for continuous real-valued functions $x(t)$ and $y(t)$.\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nAn arc $C$ is said to be \\textbf{simple} if it doesn't cross itself. An arc $C$ is said to be a \\textbf{simple closed curve} if it doesn't cross itself except for $z(a) = z(b)$.\r\n\\end{definition}\r\n\r\nExamples include straight line segments and circles, or arcs of circles.\r\n\r\n\\begin{definition}\r\nAn arc $C$ with points $z(t) = x(t) + iy(t)$ for $a \\leq t \\leq b$ is said to be a \\textbf{differentiable arc} if $x'(t)$ and $y'(t)$ exist and are continuous.\r\n\\end{definition}\r\n\r\nWe can compute the length of a differentiable arc.\r\n\r\n\\begin{theorem}\r\nIf $C$ is a differentiable arc with points $z(t) = x(t) + iy(t)$ for $a \\leq t \\leq b$ then the length of the arc is given by\r\n$$L = \\int_a^b \\left|z'(t)\\right| dt.$$\r\n\\end{theorem}\r\n\r\nThinking of the points in the complex plane as points in the $(x, y)$ plane, this is just the standard formula for arc length from calculus.\r\n\r\nThe parameterisation of an arc by a parameter $t$ is not unique. If we have another parameter $\\tau$ such that\r\n$$t = \\phi(\\tau), \\;\\; \\alpha \\leq \\tau \\leq \\beta,$$\r\nwe can convert between the two parameterisations.\r\n\r\nIn order to ensure that $t$ increases whenever $\\tau$ does, we require that $\\phi'(\\tau) > 0$ for all $\\alpha \\leq \\tau \\leq \\beta$.\r\n\r\n\\begin{theorem}\r\nIf $C$ is a differentiable arc with points $z(t) = x(t) + iy(t)$ for $a \\leq t \\leq b$ and $t = \\phi(\\tau)$ for $\\alpha \\leq \\tau \\leq \\beta$ with $\\phi'(\\tau) > 0$ for all $\\alpha \\leq \\tau \\leq \\beta$ then the length of $C$ is given by\r\n$$L = \\int_{\\alpha}^\\beta \\left|z'(\\phi(\\tau))\\right|\\phi'(\\tau)d\\tau.$$\r\n\\end{theorem}\r\n\r\nFollows by splitting $z(t)$ into real and imaginary parts and then making use of the corresponding result for real-valued functions.\r\n\r\nNote that if $z(t) = Z(\\tau) = z(\\phi(\\tau))$ for $\\alpha \\leq \\tau \\leq \\beta$ then\r\n$$Z'(\\tau) = z'(\\phi(\\tau))\\phi'(\\tau)$$\r\nby the chain rule.\r\n\r\n\\begin{definition}\r\nA differentiable arc $C$ given by $z(t) = x(t) + iy(t)$ for $a \\leq t \\leq b$ is said to be \\textbf{smooth} if $z'(t) \\neq 0$ on the open interval $a < t < b$.\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\nThe unit tangent vector to a smooth arc $C$ given by $z(t) = x(t) + iy(t)$ for $a \\leq t \\leq b$ is given by\r\n$$\\underbar{T} = \\frac{z'(t)}{|z'(t)|}.$$\r\n\\end{definition}\r\n\r\nNote that the unit tangent vector doesn't depend on the parameter $t$, since changing the parameter $t$ by $t = \\phi(\\tau)$ for $\\phi'(\\tau) > 0$ only changes $z'$ by a positive real factor, which is subsequently scaled out.\r\n\r\nThe unit tangent vector is in fact the unit tangent vector to the curve $C$ when thought of as a curve in the $(x, y)$ plane.\r\n\r\n\\begin{definition}\r\nA \\textbf{contour} is a piecewise smooth arc.\r\n\\end{definition}\r\n\r\nThe integral of a function $f(z)$ along a contour $C$ is denoted\r\n$$\\int_C f(z)dz$$\r\n\r\n\\begin{definition}\r\nIf the contour $C$ is given by points $z = z(t)$ for $a \\leq t \\leq b$ and $f(z)$ is a piecewise continuous function on $C$, then the \\textbf{contour integral} of $f$ along $C$ is given by\r\n$$\\int_C f(z)dz = \\int_a^b f(z(t))z'(t)dt$$\r\n\\end{definition}\r\n\r\nNote that as $C$ is a contour, $z'(t)$ is piecewise continuous. As $f(z)$ is piecewise continuous, so is $f(z(t))$ and thus the integral exists.\r\n\r\n\\begin{theorem}\r\nThe value of the contour integral is independent is independent of the representation of $C$.\r\n\\end{theorem}\r\n\r\nThe proof is essentially the same as the proof of independence of arc length.\r\n\r\n\\begin{theorem}\r\nFor any constant $z_0$ and piecewise continuous functions $f(z)$ and $g(z)$ we have\r\n$$\\int_C z_0f(z)dz = z_0\\int_C f(z)dz$$\r\nand\r\n$$\\int_C [f(z) + g(z)]dz = \\int_C f(z)dz + \\int_C g(z) dz$$\r\n\\end{theorem}\r\n\r\nThese follow immediately from the definitions of the contour integral and the corresponding definitions of complex-valued functions of a real parameter.\r\n\r\n\\begin{theorem}\r\nIf we write $-C$ for the contour $C$ in reverse, then for a piecewise continuous function $f(z)$ we have\r\n$$\\int_{-C}f(z)dz = -\\int_C f(z)dz$$\r\n\\end{theorem}\r\n\r\nThe contour $-C$ has points $z = z(-t)$ for $-b \\leq t \\leq -a$. Thus\r\n$$\\int_{-C}f(z)dz = \\int_{-b}^{-a} f(z(-t))(-z'(t))dt$$\r\n\r\nThe result follows by making a change of variables $s = -t$.\r\n\r\n\\begin{theorem}\r\nIf $C_1$ is a contour whose endpoint is the starting point of a contour $C_2$, then for any piecewise continuous function $f(z)$ we have\r\n$$\\int_C f(z)dz = \\int_{C_1}f(z)dz + \\int_{C_2}f(z)dz,$$\r\nwhere $C$ is the contour that first follows $C_1$ then $C_2$.\r\n\\end{theorem}\r\n\r\nWe note that shifting the representation of a contour with points $z(t)$ for $a \\leq t \\leq b$ so that it has points $Z(s) = z(s - d)$ for $a + d \\leq s \\leq b + d$ doesn't change the value of the integral, since $s'(t) = 1$.\r\n\r\nThus the points of $C$ can be represented as a function of a single parameter $t$, with the points of $C_2$ shifted so that the starting point of $C_2$ is the end point of $C_1$.\r\n\r\nThe result follows by the corresponding theorem for the sum of two integrals of a real-valued parameter.\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ is a piecewise continuous function on a contour $C$ of length $L$ such that $|f(z)| \\leq M$ for some nonnegative constant $M$ for all points on $C$ then\r\n$$\\left|\\int_C f(z)dz\\right| \\leq LM$$\r\n\\end{theorem}\r\n\r\nIf the points of $C$ are given by $z(t)$ for $a \\leq t \\leq b$ then\r\n$$\\left|\\int_C f(z)dz\\right| \\leq \\int_a^b |f(z(t))z'(t)|dt.$$\r\n\r\nThe result now follows by replacing $|f(z)|$ by $M$ and pulling out the constant $M$, and noticing that what remains is the length of the contour.\r\n\r\n\\section{Antiderivatives}\r\n\r\nSometimes contour integrals are independent of the path that is taken between the endpoints. We examine when this is the case.\r\n\r\n\\begin{definition}\r\nAn \\textbf{antiderivative} of a continuous function $f$ in a domain $D$ is a function $F$ such that $F'(z) = f(z)$ for all $z \\in D$.\r\n\\end{definition}\r\n\r\nNote that an antiderivative is analytic on $D$.\r\n\r\n\\begin{theorem}\r\nThe antiderivate $F(z)$ of a continuous function $f(z)$ is unique up to addition of a constant, if it exists.\r\n\\end{theorem}\r\n\r\nIf $G(z)$ is also an antiderivative then $F(z) - G(z)$ has derivative zero. This implies that $F(z) - G(z) = c$ for some constant $c$.\r\n\r\n\\begin{theorem}\r\nIf $f(z)$ is continuous on a domain $D$ then the following are equivalent\r\n\\begin{itemize}\r\n\\item $f$ has an antiderivative $F$ on $D$\r\n\\item integrals of $f$ along contours lying entirely in $D$ with the same start and end points, have the same value\r\n\\item integrals of $f$ around closed contours lying entirely in $D$ have value zero\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\nTo show the first implies the second, consider first the case of smooth arcs $C$ between fixed endpoints $z_1$ and $z_2$.\r\n\r\nIf $C$ is parameterised by $z = z(t)$ for $a \\leq t \\leq b$ then\r\n$$\\frac{d}{dz}F(z(t)) = F'(z(t))z'(t) = f(z(t))z'(t).$$\r\n\r\nBy the Fundamental Theorem of Calculus extends to complex functions of a real variable, we have\r\n$$\\int_C f(z)dz = \\int_a^b f(z(t))z'(t)dt = F(z(b)) - F(z(a)).$$\r\n\r\nThis clearly only depends on the values of $F$ at the endpoints.\r\n\r\nThe result holds for an arbitrary contour by additivity.\r\n\r\nThe third part obviously follows from the second, by considering any two distinct points on the closed contour and thinking of the closed contour in two parts, between those points.\r\n\r\nClearly the converse of this implication also holds, by reversing the argument. Thus to show that the third part of the theorem implies the first, it is sufficient to show that the second part implies the first.\r\n\r\nTo accomplish this, we define\r\n$$F(z) = \\int_{z_0}^z f(s)ds,$$\r\nwhere the integral notation means to take any contour from $s = z_0$ to $s = z$ lying wholly within $D$.\r\n\r\nWe are done if we show that $F$ is an antiderivative of $f$, i.e. that $F'(z) = f(z)$ on $D$.\r\n\r\nTo do so, let $\\Delta z$ be any point distinct from $z$ in a neighbourhood of $z$ contained in $D$. By additivity\r\n$$F(z + \\Delta z) - F(z) = \\int_z^{z + \\Delta z} f(s)ds.$$\r\n\r\nBy path independence, we can take the path of integration to be a straight line.\r\n\r\nIt is easy to show that\r\n$$f(z) = \\frac{1}{\\Delta z}\\int_z^{z + \\Delta z}f(z) ds,$$\r\nfor any fixed value of $z$ (so that $f(z)$ is a constant in the integral).\r\n\r\nThus\r\n$$\\frac{F(z + \\Delta z) - F(z)}{\\Delta z} - f(z) = \\frac{1}{\\Delta z}\\int_z^{z + \\Delta z}f(s) - f(z)ds.$$\r\n\r\nThe derivative we are after is the limit of the first expression on the left side as $\\Delta z \\to 0$.\r\n\r\nBut $f$ is continuous at $z$. Thus the right hand side can be made as close to zero as one wishes.\r\n\r\nThus $F'(z) = f(z)$ and we are done.\r\n\r\n\\section{The Cauchy-Goursat theorem}\r\n\r\nSuppose that $C$ is a simple, closed contour given by points $z(t)$ for $a \\leq t \\leq b$ and that the contour is counterclockwise. Also suppose that $f(z)$ is analytic in the interior of, and at each point of $C$.\r\n\r\nWe recall that\r\n$$\\int_C f(z)dz = \\int_a^b f(z(t))z'(t)dt.$$\r\n\r\nWriting\r\n$$f(z) = u(x(t), y(t)) + iv(x(t), y(t)),$$\r\nfor $z = x + iy$ and making use of the chain rule, we have\r\n$$\\int_C f(z)dz = \\int_a^b (ax' - vy')dt + i\\int_a^b (vx' + uy')dt.$$\r\n\r\nIn terms of line integrals of real-valued functions of real variables, this yields\r\n$$\\int_C f(z)dz = \\int_C udx - vdy + i\\int vdx + udy.$$\r\n\r\nNow recall the following theorem from multivariable calculus.\r\n\r\n\\begin{theorem} (Green)\r\nIf two real-valued functions $P(x, y)$ and $Q(x, y)$ and their first-order partial derivatives are continuous throughout the closed region $R$ with boundary $C$ then\r\n$$\\int_C Pdx + Qdy = \\int \\int_R (Q_x - P_y)dA.$$\r\n\\end{theorem}\r\n\r\nSince the function $f$ above is analytic on $R$, it is continuous there. Thus $u$ and $v$ are also continuous in $R$.\r\n\r\nSuppose in addition that $f'$ is also continuous in $R$. Then the first order partial derivatives of $u$ and $v$ will be too. Then Green's theorem gives us\r\n$$\\int_C f(z) dz = \\int \\int_R (-v_x - u_y)dA + i\\int \\int_R (u_x - v_y)dA.$$\r\n\r\nBut since $f$ is analytic on $R$ we have by the Cauchy-Riemann equations that\r\n$$u_x = v_y \\;\\;\\mbox{and}\\;\\; u_y = -vx.$$\r\n\r\nThus the previous integral is zero, i.e. we have\r\n$$\\int_C f(z) dz = 0.$$\r\n\r\nAlong the way, we added the assumption that $f$ had continuous derivative. But Goursat was able to remove this assumption. In fact, the following theorem holds.\r\n\r\n\\begin{theorem} (Cauchy-Goursat)\r\nIf a function $f$ is analytic at all points interior to and on a simple, closed countour $C$, then\r\n$$\\int_C f(z)dz = 0.$$\r\n\\end{theorem}\r\n\r\nWe give only a sketch of the proof of this result, since the full proof is quite long.\r\n\r\nThe idea is that we will divide the region $R$ enclosed by $C$ into a collection of squares, and partial squares along the boundary.\r\n\r\nWe claim that it is possible to divide the region in such a way, using squares not necessarily of the same size, such that for each of the squares, indexed by $j = 1, 2, \\ldots, n$ there is a point $z_j$ for which\r\n$$\\left|\\frac{f(z) - f(z_j)}{z - z_j} - f'(z_j)\\right| < \\epsilon$$\r\nfor all $z \\neq z_j$ in that square, where $\\epsilon$ is fixed and as small as one desires.\r\n\r\nThis follows from the definition of the derivative as a limit. If the number of squares were not finite, then it must be possible to subdivide a given square into four equal sized squares, and one of those into four more an so on, so that the inequality never holds. We end up with a sequence of every smaller squares converging on a point, for which the inequality doesn't hold. But this then contradicts the definition of the derivative at that point. Thus there are a finite number of squares.\r\n\r\nNext we define the function\r\n$$\\delta_j = \\begin{cases}\\frac{f(z) - f(z_j)}{z - z_j} - f'(z_j) & \\mbox{when}\\;\\; z \\neq z_j,\\\\ 0 & \\mbox{when}\\;\\; z = z_j\\end{cases}.$$\r\n\r\nOn the $j$-th square, we have $|\\delta_j(z)| < \\epsilon$. The function $\\delta_j(z)$ is also continuous on that region.\r\n\r\nLet $C_j$ be the boundary of the $j$-th square or partial square. Critically, we have\r\n$$f(z) = f(z_j) - z_jf'(z_j) + f'(z_j)z + (z - z_j)\\delta_j(z)$$\r\non such a region.\r\n\r\nBecause each of these terms has an antiderivative except the last, their integrals along $C_j$ are zero, leading to\r\n$$\\int_{C_j} f(z)dz = \\int_{C_j} (z - z_j)\\delta_j(z)dz.$$\r\n\r\nThe integral of $f(z)$ on $C$ is the sum of the integrals along the boundaries of all the squares and partial squares, since each boundary of a square on the interior of $R$ is part of the boundary of two different squares in the opposite sense and so their integrals cancel.\r\n\r\nLetting $s_j$ be the side length of the $j$-th square, we have\r\n$$|z - z_j| \\leq \\sqrt{s}s_j.$$\r\n\r\nThe length of the boundary of the $j$-th square is either $4s_j$ if it is a square, or if not, it is bounded by $4s_j + L_j$ where $L_j$ is the length of the portion of the region $R$ included in the boundary of the partial square.\r\n\r\nUsing these inequalities, it is possible to obtain a bound of the following form\r\n$$\\left|\\int_C f(z)dz\\right| < D\\epsilon,$$\r\nwhere $D$ is some constant in terms of say the area of a square bounding $R$ and the length of the boundary of $R$.\r\n\r\nSince $\\epsilon$ may be taken as small as one desires, the result follows.\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "53d5e5a55cd7a9c8b54d0131c472a0ef058aaf6d", "size": 39793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ComplexVariablesSummary.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": "ComplexVariablesSummary.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": "ComplexVariablesSummary.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": 42.6049250535, "max_line_length": 497, "alphanum_fraction": 0.6531550775, "num_tokens": 13397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8652240947405565, "lm_q1q2_score": 0.6701882073651725}}
{"text": "% !TEX root = main.tex\n%=====================================================================\n\\chapter{Random processes}\\label{chap:randomprocesses}\n\n\\newcommand{\\Znn}{\\mathbb{Z}_{\\geq 0}}\n\n%-------------------------------------------------\n%\\section{Random processes}\\label{sec:rprocs}\nLet $\\Omega$ be the sample space of some random experiment and let $T\\subseteq\\R$ be a set of \\emph{times}. The canonical examples are $T=\\{0,1,2,\\ldots\\}$ which defines a discrete-time process, and $T=[0,\\infty)$ which defines a continuous-time process.\n\n\\begin{definition}\nA \\emph{random process} on $\\Omega$ is a collection of random variables $\\{X_t:t\\in T\\}$, where each $X_t:\\Omega\\to\\R$ is a random variable on $\\Omega$.\n\\ben\n\\it If $T$ is countable, $\\{X_t\\}$ is called a \\emph{discrete-time} random process.\n\\it If $T$ is uncountable, $\\{X_t\\}$ is called a \\emph{continuous-time} random process. \n\\een\n\\end{definition}\n\nWe can think of a random process $\\{X_t\\}$ as a mapping:\n\\[\n\\begin{array}{rccl}\n\\{X_t\\}: \t& T\\times\\Omega\t\t& \\to\t\t& \\R \\\\\n\t\t\t& (t,\\omega)\t\t& \\mapsto\t& X_t(\\omega).\n\\end{array}\n\\]\n\n\\begin{definition}\nFor a fixed outcome $\\omega\\in\\Omega$, the associated realisation $\\{X_t(\\omega):t\\in T\\}$ of the random process $\\{X_t:t\\in T\\}$ is called a \\emph{trajectory} or \\emph{sample path} of the process. \n\\end{definition}\n\nIf $T$ is a finite set then $\\{X_t\\}$ is random vector which is defined by its joint CDF. If $T$ is an infinite set (either countable or uncountable) it is not easy to define a CDF to describe $\\{X_t\\}$. To do it, we have to deal with the joint distributions of $(X_{t_1},X_{t_2},\\ldots,X_{t_n})$ for all $n\\in\\N$ and all choices of $t_1,t_2,\\ldots,t_n\\in T$. These are called the \\emph{finite-dimensional distributions} of the random process.\n\n%-----------------------------\n\\subsection{The canonical probability space}\n\nLet $\\Omega = [0,1]^{\\N}$ be the set of infinite sequences of real numbers from the unit interval $[0,1]$, let $\\mathbf{\\omega}\\in\\Omega$ and write this as\n\\[\n\\mathbf{\\omega} = (\\omega_0,\\omega_1,\\omega_2,\\ldots).\n\\]\nThe $n$th term of the sequence is extracted by the random variable\n\\[\n\\begin{array}{rccl}\n\t\\gamma_n:\t& \\omega\t\t\t& \\to\t\t& [0,1] \\\\\n\t\t\t\t& \\mathbf{\\omega}\t& \\mapsto\t& \\omega_n.\n\\end{array}\n\\]\nWe state the following theorem without proof.\n\\begin{theorem}\nThere exists a probability measure $\\prob$ on $\\Omega)$ such that the random variables $\\gamma_0,\\gamma_1,\\ldots$ are independent and uniformly distributed on $[0,1]$.\n\\end{theorem}\n\nWe think of the single outcome $\\mathbf{\\omega} = (\\omega_0,\\omega_1,\\omega_2,\\ldots)$ as the source of all randomness in our experiment, and all other quantities are deterministic functions of this outcome (random variables).\n\n%-----------------------------\n\\subsection{The Bernoulli process}\\label{sec:bernoulliprocs}\n\\begin{definition}\nA random process $\\{X_n\\}$ consisting of independent and identically distributed $\\text{Bernoulli}(p)$ variables is called the $\\text{Bernoulli}(p)$ process.\n\\end{definition}\n\nIn terms of the canonical probability space,\n\\[\nX_n = \\begin{cases}\n\t1\t& \\gamma_n\\leq p, \\\\\n\t0\t& \\text{otherwise.}\n\\end{cases}\n\\]\nTrajectories of the Bernoulli process are binary sequences (of infinite length).\n\n\\begin{example}\nLet $\\{X_n\\}$ be a $\\text{Bernoulli}(p)$ process. If $p>0$, show that a `success' is eventually observed with probability $1$.\n\\begin{solution}\n\\bit\n\\it $E \t\t= \\{\\omega\\in\\Omega:X_n(\\omega)=1 \\text{ for some } n\\}$\n\\it $E_n \t= \\{\\omega\\in\\Omega:X_m(\\omega)=1 \\text{ for some } m\\leq n\\}$\n\\it $E_1\\subset E_2\\subset E_3\\subset\\ldots$ is an expanding sequence, with $E=\\cup_{n=1}^{\\infty} E_i$.\n\\it By continuity, \n\\[\n\\prob(E) = \\lim_{n\\to\\infty}\\prob(E_n) = \\lim_{n\\to\\infty}\\big(1 - (1-p)^n\\big) = 1.\n\\]\n\\eit\n\\end{solution}\n\\end{example}\n\n% ex: hitting times\n\\begin{example} \nSuppose have observed the first $n$ terms of a $\\text{Bernoulli}(p)$ process. Let $\\tau$ be the time until we next observe a `success'. Show that $\\tau\\sim\\text{Geometric}(p)$.\n\\begin{solution}\n\\[\n\\tau = \\min\\{m>0:X_{n+m}=1\\}. \n\\]\nBecause the $X_i$ are independent,\n\\begin{align*}\n\\prob(\\tau > m | X_1,X_2,\\ldots,X_n)\n\t& = \\prob(X_{n+1}=0,X_{n+2}=0,\\ldots,X_{n+m}=0 | X_1,X_2,\\ldots,X_n) \\\\\n\t& = \\prob(X_{n+1}=0)\\prob(X_{n+2}=0)\\cdots\\prob(X_{n+m}=0) \\\\\n\t& = (1-p)^{m}\n\\end{align*}\nso $\\tau\\sim\\text{Geometric}(p)$ with $\\prob(\\tau=m)=(1-p)^{m-1}p$.\n\\end{solution}\n\\end{example}\n\n% ex: memoryless\n\\begin{exercise}\nShow that the geometric distribution has the so-called memoryless property: if $\\tau\\sim\\text{Geometric}(p)$, then\n\\[\n\\prob(\\tau > m+n|\\tau > n) = \\prob(\\tau > m).\n\\]\n\\begin{answer}\n\\begin{align*}\n\\prob(\\tau > m+n|\\tau > n) \n\t& = \\prob(\\tau>m+n,\\tau>n)/\\prob(\\tau>n) \\\\\n\t& = \\prob(\\tau>m+n)/\\prob(\\tau>n) \\\\\n\t& = (1-p)^{m+n}/(1-p)^n \\\\\n\t& = (1-p)^m \\\\\n\t& = \\prob(\\tau > m).\n\\end{align*}\n\\end{answer}\n\\end{exercise}\n\n%-------------------------------------------------\n%\\subsection{The Poisson process}\\label{sec:poissonprocess}\n\n\n%-------------------------------------------------\n\\section{Random walks}\\label{sec:rwalks}\n\n%intro\nThe \\emph{simple random walk} is the simplest model of a \\emph{diffusion process}. We consider a particle which inhabits the set of integer points $\\Z$ and at each (discrete) time step the particle moves either one step to the right with probability $p$ or one step to the left with probability $q=1-p$. \n\\bit\n\\it For fixed $\\omega$ the random variable $X_n$ describes the trajectory of the particle over time.\n\\it For fixed $n$ the random variable $X_n$ describes the (spatial) distribution of the particle at time $n$.\n\\eit\n\n\\begin{definition}\nA discrete random process $\\{X_n\\}$ is called a  \\emph{simple random walk} with parameter $p\\in(0,1)$ if\n\\ben\n\\it $X_{n+1}-X_n$ is independent of $X_0,X_1,\\ldots,X_n$, \n\\it $\\prob(X_{n+1} = X_n + 1) = p$ and $\\prob(X_{n+1} = X_n - 1) = q$ where $q=1-p$.\n\\een\nIf $p=1/2$ the random walk is called \\emph{symmetric}.\n\\end{definition}\n\n\n% link with canonical probability space\nIn terms of the random variables $\\gamma_n$ defined on the canonical probability space let us define a new sequence of random variables,\n\\[\n\\xi_n = \\begin{cases}\n\t\\phantom{-}1\t& \\gamma_n\\leq p, \\\\\n\t-1\t& \\text{otherwise.}\n\\end{cases}\n\\]\n\\begin{lemma}\nThe random process $\\{X_n\\}$ where $X_n = X_0 + \\sum_{k=1}^n \\xi_k$ is a simple random walk.\n\\begin{proof}\n\\ben\n\\it The $\\xi_n$ are independent (they are transforms of the $\\gamma_n$, which are independent), so the increment $X_{n+1}-X_n$ is independent of $\\xi_1,\\xi_2,\\ldots,\\xi_n$, and because $X_0,X_1,\\ldots,X_n$ are just linear combinations of $\\xi_1,\\xi_2,\\ldots,\\xi_n$, it follows that $X_{n+1}-X_n$ is independent of $X_0,X_1,\\ldots,X_n$.\n\\it Because $\\gamma_{n+1}\\sim\\text{Uniform}[0,1]$,\n\\begin{align*}\n\\prob(X_{n+1} = X_n + 1) \n\t& = \\prob(\\xi_{n+1} = 1) \\prob(\\gamma_{n+1}\\leq p) = p.\n\\prob(X_{n+1} = X_n - 1) \n\t& = \\prob(\\xi_{n+1} = -1) \\prob(\\gamma_{n+1} > p) = 1-p.\n\\end{align*}\n\\een\n\\end{proof}\n\\end{lemma}\n\n%-----------------------------\n\\subsection{Properties}\n\n\\begin{definition}\nA \\emph{stationary} random process is one whose behaviour does not change when shifted in time and space.\n\\end{definition}\n\n\\begin{lemma}\nThe simple random walk satisfies\n\\[\n\\begin{array}{lcll}\n\\prob(X_n=x\\,|\\,X_0=a) \n\t& = & \\prob(X_n=x+b\\,|\\,X_0=a+b) \t&\\qquad\\text{(spatial homogeneity), and} \\\\\n\\prob(X_n=x\\,|\\,X_0=a) \n\t& = & \\prob(X_{m+n}=x\\,|\\,X_m=a) \t&\\qquad\\text{(temporal homgeneity)}\n\\end{array}\n\\]\nand is therefore a stationary process.\n\\begin{proof}\n\\[\n\\begin{array}{lll}\n\\prob(X_n=x|X_0=a) \n\t& = \\prob\\left(a+\\sum_{k=1}^n \\xi_k = x\\right) \\\\\n\t& = \\prob\\left((a+b)\\sum_{k=1}^n \\xi_k = x+b\\right) = \\prob(X_n=x+b|X_0=a+b) \\\\\n\\prob(X_n=x|X_0=a) \n\t& = \\prob\\left(a+\\sum_{k=1}^n \\xi_k = x\\right) \\\\\n\t& = \\prob\\left(a+\\sum_{k=m+1}^{m+n} \\xi_k = x\\right) = \\prob(X_{m+n}=x|X_m=a).\n\\end{array}\n\\]\n\\end{proof}\n\\end{lemma}\n\n%%-----------------------------\n%\\begin{theorem}\n%Let $\\{X_n\\}$ be a simple random walk with parameter $p$, and suppose that $X_0=0$. Then $X_n$ is a discrete random variable, with\n%\\[\n%\\prob(X_n=\\ell) = \\binom{n}{\\frac{n+\\ell}{2}} p^{(n+\\ell)/2}q^{(n-\\ell)/2}\n%\\quad\\text{for } \\ell\\in\\{-n,-n+2,\\ldots,-2,0,2,\\ldots n-2, n\\},\n%\\]\n%where $q=1-p$, and zero otherwise.\n%\\begin{proof}\n%\n%\\end{proof}\n%\\end{theorem}\n\n%--------------------------------------------------------------------------\n\\subsection{Sample paths}\n%--------------------------------------------------------------------------\nThe motion of a particle can be represented by the sequence $\\{(n,X_n)\\,:\\,n=0,1,2,\\ldots\\}$., which is called the \\emph{trajectory} or \\emph{path} of the particle. By convention, sample paths are plotted with time on the horizontal axis, and displacement on the vertical axis.\n\nAny event can be expressed in terms of an appropriate set of paths: the probability of the event is the probability that one of the associated paths is realized. The set of sample paths therefore serves as a \\emph{sample space} for analysing the simple random walk.\n\nLet $C_n$ be the set of all possible paths of length $n$,\n\\[\nC_n = \\big\\{(x_0,x_1,\\ldots,x_n)\\in\\Z^{n+1}: x_{k+1}-x_k = \\pm 1\\text{ for } k=0,1,2,\\ldots,n-1\\big\\}.\n\\]\n\nThe probability that the first $n$ steps of the random walk follows any particular path $\\mathbf{x}=(x_0,x_1,\\ldots,x_n)$ is $p^cq^d$ where\n\\bit\n\\it $c$ is the number of positive steps (right/up), and\n\\it $d$ is the number of negative steps (left/down).\n\\eit\n\n%-------------------------\n\\subsubsection{The distribution of the particle at time $n$}\nWe can compute the PMF of $X_n$ by examining the ensemble of all possible paths over the first $n$ steps. Let $C_n(a,b)$ be the set of paths from $(0,a)$ to $(n,b)$,\n\\[\nC_n(a,b) = \\big\\{\\mathbf{x}\\in C_n: x_0=a, x_n=b\\}.\n\\]\n\n% lemma: PMF of $X_n$\n\\begin{lemma}\nThe number of possible paths from $(0,a)$ to $(n,b)$ is \n\\[\n|C_n(a,b)| = \\binom{n}{\\frac{1}{2}(n+b-a)}\n\\]\nprovided that $(n+b-a)/2$ belongs to the set $\\{0,1,2\\ldots,n\\}$. \n\\end{lemma}\nIf $X_0=0$, the condition says that the particle can occupy only odd-numbered sites after an odd number of steps, and only even-numbered sites after an even number of steps.)\n\n\\begin{proof}\nChoose a path from $(0,a)$ to $(n,b)$. Let $u$ be the number of positive steps, and $d$ the number of negative steps.\n\\bit\n\\it $u+d=n$ is the total number of steps;\n\\it $u-d=b-a$ is the overall displacement to the right.\n\\eit\nSolving for $c$ and $d$, we get $c=\\frac{1}{2}(n+b-a)$ and $d=\\frac{1}{2}(n-b+a)$. The number of paths from $(0,a)$ to $(n,b)$ is the number of ways of choosing exactly $u$ positive steps from the $n$ available steps, so\n\\[\n|C_n(a,b)| = \\binom{n}{u} = \\binom{n}{\\frac{1}{2}(n+b-a)}\n\\]\n\\end{proof}\n\n% corollary: PMF of X_n\n\\begin{corollary}\n%The probability that $X_n=b$ given that $X_0=a$ is \n\\[\n\\prob(X_n=b|X_0=a) = \\binom{n}{\\frac{1}{2}(n+b-a)}p^{\\frac{1}{2}(n+b-a)}q^{\\frac{1}{2}(n-b+a)}\n\\]\n\\end{corollary}\n\\begin{proof}\nEach path in $C_n(a,b)$ occurs with probability $p^{\\frac{1}{2}(n+b-a)}q^{\\frac{1}{2}(n-b+a)}$, so\n\\[\n\\prob(X_n=b|X_0=a) = \\binom{n}{\\frac{1}{2}(n+b-a)}p^{\\frac{1}{2}(n+b-a)}q^{\\frac{1}{2}(n-b+a)}\n\\]\n\\end{proof}\n\n%--------------------------------------------------------------------------\n\\subsection{The Reflection Principle}\n%--------------------------------------------------------------------------\nCounting sample paths is made easier by using the \\emph{reflection principle}.\n\n\\begin{figure}\n\\centering\\resizebox{0.5\\linewidth}{!}{\\includegraphics{reflection_principle}}\n\\caption{The Reflection Principle\\label{reflection_principle}}\n\\end{figure}\n\n%Let $a,b>0$ and define $C^{0}_n(a,b)$ to be the set of paths from $(0,a)$ to $(n,b)$ which contain a point of the form $(k,0)$, i.e.\\ those trajectories which return to the (spatial) origin at some time step $k=0,1,2,\\ldots,n$. We can use the reflection principle to show that the number of such paths is equal to the total number of paths from $(0,-a)$ to $(n,b)$.\n%\n%-------------------------\n% theorem: reflection principle\n\\begin{theorem}\nLet $a,b>0$, and let $C^{0}_n(a,b)$ be the set of paths from $(0,a)$ to $(n,b)$ which visit the (spatial) origin:% at some time step $k\\in\\{1,2,\\ldots,n-1\\}$,\n\\[\nC^{0}_n(a,b) = \\big\\{\\mathbf{x}\\in C_n(a,b): x_k=a \\text{ for some } k=1,2,\\ldots,n-1\\}.\n\\]\nThe number of such paths is equal to the total number of paths from $(0,-a)$ to $(n,b)$,\n\\[\n|C^0_n(a,b)| = |C_n(-a,b)|.\n\\]\n\\end{theorem}\n\\begin{proof}\nEach path from $(0,a)$ to $(n,b)$ intersects the horizontal axis at some earliest point $(k,0)$. If we reflect the segment of the path with $0\\leq t\\leq k$ in the horizontal axis, we obtain a path from $(0,a)$ to $(n,b)$ which intersects the horizontal axis. This operation puts the elements of $C^0_n(a,b)$ and $C_n(-a,b)$ in one-to-one correspondence, which proves the theorem.\n\\end{proof}\n\n%For simplicity, we now focus our attention on simple random walks that start at the origin, i.e.\\ those for which $X_0=0$.\n%\n%For $\\ell > 0$, let $C^{*}_n(\\ell)$ be the set of paths from $(0,0)$ to $(n,\\ell)$ which do \\emph{not} revisit the initial location $X_0=0$. \n%\n%\n\n\n%%--------------------------------------------------------------------------\n%\\subsubsection{The Ballot Theorem}\n%\n%For $b>a\\geq 0$, let $C^{*}_n(a,b)$ to be the set of paths from $(0,a)$ to $(n,b)$ which do \\emph{not} revisit the initial location $X_0=a$. \n%\\[\n%C^{*}_n(a,b) = \\big\\{\\mathbf{x}\\in C_n(a,b): x_k=0 \\text{ for some } k=1,2,\\ldots,n-1\\}.\n%\\]\n\n% ballot theorem\n\\begin{theorem}[The ballot theorem]\nLet $b>a\\geq 0$, and let $C^{*}_n(a,b)$ to be the set of paths from $(0,a)$ to $(n,b)$ which do \\emph{not} revisit the initial location $X_0=a$, \n\\[\nC^{*}_n(a,b) = \\big\\{\\mathbf{x}\\in C_n(a,b): x_k=a \\text{ for some } k=1,2,\\ldots,n-1\\}.\n\\]\nThe number of such paths is given by\n\\[\n|C^{*}_n(a,b)| = \\frac{b-a}{n} |C_n(a,b)|,\n\\]\nwhere $C_n(a,b)$ is the set of all paths from $(0,a)$ to $(n,b)$.\n\\end{theorem}\n\n%-------------------------\n\\begin{proof}\nWithout loss of generality, let $a=0$. The first step of all such paths must be to $(1,1)$, so by the reflection principle the number of such paths is\n\\begin{align*}\n|C^{*}_n(0,b)|\n\t& = |C_{n-1}(1,b)| - |C^0_{n-1}(1,b)| \\\\\n\t& = |C_{n-1}(1,b)| - |C_{n-1}(-1,b)|\n\\end{align*}\nThe result then follows by the fact that the total number of paths $(0,0)$ to $(n,b)$ is equal to\n\\[\n|C_n(0,b)| = \\binom{n}{\\frac{1}{2}(n+b)}\n\\]\nand\n\\[\n\\begin{array}{lll}\n|C_{n-1}(1,b)| \t& = \\binom{n-1}{\\frac{1}{2}(n+b)} \t& = \\frac{n+b}{2n} |C_n(0,b)| \\\\\n|C_{n-1}(-1,b)|\t& = \\binom{n-1}{\\frac{1}{2}n+b-1}\t& = \\frac{n-b}{2n} |C_n(0,b)| \\\\\n\\end{array}\n\\]\n\\end{proof}\n\n%-------------------------\n% example\n\\begin{example}\nIn an election, candidate A scores $\\alpha$ votes and candidate B scores $\\beta$ votes, where $\\alpha > \\beta$. What is the probability that candidate $A$ was always ahead of candidate $B$ during the election? \n\\begin{solution}\nAssume that each possible combination of $\\alpha$ votes for $A$ and $\\beta$ votes for $B$ is equally likely.\n\n\\bigskip\nAfter $n=\\alpha+\\beta$ steps, the required probability is the proportion of paths from $(0,0)$ to $(\\alpha+\\beta,\\alpha-\\beta)$ which do not re-visit the horizontal axis. By the ballot theorem, \n\\[\n\\prob(\\text{$A$ was always ahead of $B$}) = \\frac{\\alpha-\\beta}{\\alpha+\\beta}.\n\\]\n\\end{solution}\n\\end{example}\n\n\n%% thm: maximum\n%\\begin{theorem}\n%Let $\\{X_n\\}$ be a symmetric simple random walk with $X_0=0$, and let $M_n=\\max\\{X_0,X_2,\\ldots,X_n\\}$. Then\n%\\[\n%\\prob(M_n\\geq \\ell)\t= \\prob(X_n=\\ell) + \\prob(X_n=\\ell+1) \n%\\]\n%Note that only one of $\\prob(X_n=\\ell)$ and $\\prob(X_n=\\ell+1)$ is non-zero, the first if $n$ and $\\ell$ are both odd or both even, and the second if one is odd and the other is even.\n%\\end{theorem}\n%\n%\\begin{proof}\n%Let $A_n(\\ell)$ be the set of paths whose maximum is at least equal to $\\ell$:\n%\\begin{align*}\n%A_n(\\ell) \n%\t& = \\{\\mathbf{x}\\in C_n: \\max x_k \\geq \\ell, k=1,2,\\ldots,n\\} \\\\\n%\t& = \\big\\{\\mathbf{x}\\in C_n: x_k \\geq \\ell \\text{ for at least one } k\\in\\{0,1,\\ldots,n\\}\\big\\}\n%\\end{align*}\n%There are $2^n$ possible sample paths, all equally likely, so \n%\\[\n%\\prob(M_n \\geq \\ell) = 2^{-n}|A_n(\\ell)|.\n%\\]\n%Let \n%\\bit\n%\\it $A_n^{(1)}(\\ell) = \\big\\{\\mathbf{x}\\in A_n(\\ell): x_n > \\ell\\big\\}$,\n%\\it $A_n^{(2)}(\\ell) = \\big\\{\\mathbf{x}\\in A_n(\\ell): x_n = \\ell\\big\\}$,\n%\\it $A_n^{(3)}(\\ell) = \\big\\{\\mathbf{x}\\in A_n(\\ell): x_n < \\ell\\big\\}$.\n%\\eit\n%Then\n%\\[\n%|A_n(\\ell)| = |A_n^{(1)}(\\ell)| + |A_n^{(2)}(\\ell)| + |A_n^{(3)}(\\ell)|\n%\\]\n%\n%By the reflection principle, the trajectories in $A_n^{(1)}(\\ell)$ are in one-to-one correspondence with those in $A_n^{(3)}(\\ell)$, so \n%\\[\n%|A_n(\\ell)| = 2|A_n^{(1)}(\\ell)| + |A_n^{(2)}(\\ell)|\n%\\]\n%\n%Now, \n%\\bit\n%\\it $A_n^{(1)}(\\ell) = \\cup_{k=\\ell+1}^{\\infty}\\{\\mathbf{x}: x_n=k\\}$ and \n%\\it $A_n^{(2)}(\\ell) = \\{\\mathbf{x}: x_n=\\ell\\}.\n%\\eit\n%\n%There are $2^n$ sample paths, each equally likely, so\n%\\begin{align*}\n%\\prob(M_n\\geq \\ell)\n%\t& = 2\\sum_{k=\\ell+1}^{\\infty}\\prob(X_n=k) + \\prob(X_n=\\ell) \\\\\n%\t& = \\sum_{k=\\ell+1}^{\\infty}\\prob(X_n=k) + \\sum_{k=\\ell}^{\\infty}\\prob(X_n=\\ell) \\\\\n%\\end{align*}\n%\n%Hence,\n%\\begin{align*}\n%\\prob(M_n = \\ell) \n%\t& = \\prob(M_n\\geq \\ell) - \\prob(M_n\\geq \\ell+1) \\\\\n%\t& = \\prob(M_n\\geq \\ell) - \\prob(M_n\\geq \\ell+1) \\\\\n%\t& = \\left(\\sum_{k=\\ell+1}^{\\infty}\\prob(X_n=k) + \\sum_{k=\\ell}^{\\infty}\\prob(X_n=k)\\right)\n%\t\t\t- \\left(\\sum_{k=\\ell+2}^{\\infty}\\prob(X_n=k) + \\sum_{k=\\ell+1}^{\\infty}\\prob(X_n=k)\\right) \\\\\n%\t& = \\sum_{k=\\ell}^{\\infty}\\prob(X_n=k) - \\left(\\sum_{k=\\ell+2}^{\\infty}\\prob(X_n=k) \\\\\n%\t& = \\prob(X_n=\\ell)\\right) + \\prob(X_n=\\ell+1)\\right) \\\\\n%\\end{align*}\n%\n%\\end{proof}\n\n%-----------------------------\n\\subsection{Hitting times}\nLet $X_n=\\sum_{k=1}^{n}\\xi_k$ be a simple random walk with $X_0=0$. The \\emph{first hitting time} at level $\\ell$ is the time at which the trajectory first reaches level $\\ell\\in\\N$,\n\\[\nT_{\\ell} = \\min\\{n: X_n=\\ell\\}\n\\]\nIf $T_{\\ell}=n$, we must have that (1) $X_n = \\ell$ and (2) $X_k < \\ell$ for all $k=0,1,2,\\ldots,n-1$.\n\n\\begin{example}[Gambler's ruin]\nA gambler starts with $\\pounds x$ and plays a game in which a fair coin is tossed repeatedly. Each time, if the coin shows heads then he wins $\\pounds 1$, but if the coin shows tails he loses $\\pounds 1$. The gambler stops when either he goes bankrupt or otherwise reaches some pre-determined amount $\\pounds a$. Find the probability that the gambler goes bankrupt.\n%Show that the probability that the gambler goes bankrupt is equal to $(a-x)/x$.\n\\end{example}\n\n\\begin{solution}\nLet $X_n$ denote the gambler's \\emph{winnings} after $n$ steps. The sequence $X_0,X_1,X_2,\\ldots$ can be modelled by a symmetric simple random walk starting at $X_0=0$, with\n\\[\nX_n = \\sum_{k=1}^n \\xi_k \\quad\\text{where $\\prob(\\xi_k=1)=1/2$ and $\\prob(\\xi_k=-1)=1/2$.} \n\\]\nLet $T$ be the (random) time at which the game stops:\n\\bit\n\\it $T=\\min\\{T_0,T_a\\}$ where $T_0$ and $T_a$ are the hitting times of levels $0$ and $a$ respectively.\n\\eit\n\nConsider the random variable $X_T = \\sum_{k=1}^{T}\\xi_k$, the gambler's winnings at the random time $T$.\n\\bit\n\\it Clearly $X_T = -x$ or $X_T = a-x$. \n\\it Let $p_0=\\prob(X_T = -x)$ and $p_1=\\prob(X_T = a-x)$. \n\\eit\n\nLet $\\xi$ be a random variable with $\\prob(\\xi_k=1)=1/2$ and $\\prob(\\xi_k=-1)=1/2$, and let $\\xi_1,\\xi_2,\\ldots$ be independent increments from the distribution of $\\xi$. By Corollary~\\ref{cor:GF-NofX} (Wald's identity),\n\\[\n\\expe(X_T) = \\expe(T)\\expe(\\xi) = \\expe(T)\\times 0 = 0,\n\\]\nWe also know that $\\expe(X_T) = (-x)p_0 + (a-x)p_a$, so $xp_0 = (a-x)p_a$. Thus, using the fact that $p_0+p_a=1$, we obtain\n\\[\np_0 = \\frac{a-x}{a} \\quad\\text{and}\\quad p_1 = \\frac{x}{a}.\n\\] \nNote that we have assumed that $\\expe(T)<\\infty$, which requires that $\\prob(T<\\infty)=1$.\n\n\\end{solution}\n\n%-----------------------------\n\n\\begin{theorem}\nLet $\\{X_n\\}$ be a simple random walk with $X_0=0$, and let $T$ be the first hitting time at level $\\ell=1$. The PMF of $T$ is given by the following recursive formula,\n\\[\np_n = q\\sum_{k=1}^{n-2}p_{k}p_{n-k-1}, \\qquad p_0=0, p_1=p, q=1-p..\n\\]\nwhere $p_n = \\prob(T=n)$.\n\\end{theorem}\n\\begin{proof}\n\\bit\n\\it We cannot move from $0$ to $1$ in an even number of steps, so $p_{2n}=0$ for $n\\in\\Znn$.\n\\it For $n=1$, the first step must be upwards, so $p_1=p$.\n\\it For $n>1$, the first step must be downwards (which occurs with probability $q$), and then we need to climb from $-1$ to $0$, and then from $0$ to $1$. \n\\eit\n\\begin{align*}\n\\prob(T=n)\n\t& = q\\sum_{k=1}^{n-2}\\prob(\\text{$k$ steps to first hit $0$ from $-1$, and $n-k-1$ steps to first hit 1 from $0$}) \\\\\n\t& = q\\sum_{k=1}^{n-2}\\prob(\\text{$k$ steps to first hit $0$ from $-1$})\\prob(\\text{$n-k-1$ steps to first hit $1$ from $0$}) \\\\\n\t& = q\\sum_{k=1}^{n-2}\\prob(\\text{$k$ steps to first hit $1$ from $0$})\\prob(\\text{$n-k-1$ steps to first hit $1$ from $0$}) \\\\\n\t& = q\\sum_{k=1}^{n-2}p_{k}p_{n-k-1}\n\\end{align*}\n\\end{proof}\n\n\\begin{theorem}\nThe PGF of $T$ is given by $\\displaystyle G(t) = \\frac{1 - \\sqrt{1-4pqt^2}}{2qt}$.\n\\end{theorem}\n\n\\begin{proof}\nLet $G(t) = \\sum_{k=0}^{\\infty} p_k t^k$ be the PGF of $T$. The square of the PGF can be written as \n\\[\nG(t)^2 = \\sum_{k=0}^{\\infty} \\left(\\sum_{i=0}^{k} p_ip_{k-i}\\right) t^k\n\\]\nBecause $p_0=0$ and $p_{k+1}=q\\sum_{i=1}^{k-1}p_{i}p_{k-i}$, the inner sum can be written as\n\\[ \n\\sum_{i=0}^{k} p_ip_{k-i} \n\t= \\sum_{i=1}^{k-1} p_ip_{k-i} \n\t=  q^{-1}p_{k+1} \\quad\\text{for $k\\geq 2$.}\n\\]\n(and zero for $k=0$ and $k=1$). Hence,\n\\[\nG(t)^2 = q^{-1}\\sum_{k=2}^{\\infty} p_{k+1} t^{k+1} = G(t) - pt\n\\]\nso\n\\[\nqtG(t)^2 = \\sum_{k=2}^{\\infty} p_{k+1} t^{k+1} = \\sum_{k=0}^{\\infty} p_k t^k - pt = G(t) - pt.\n\\]\nThus we obtain a quadratic equation for $G(t)$,\n\\[\nqtG(t)^2 - G(t) + pt = 0\n\\]\nand solving for $G(t)$ we obtain\n\\[\nG(t) = \\frac{1\\pm\\sqrt{1-4pqt^2}}{2qt}\n\\]\nFor any PGF we must have that $G(t)\\leq 1$, so we conclude that\n\\[\nG(t) = \\frac{1 - \\sqrt{1-4pqt^2}}{2qt}\n\\]\n\\end{proof}\n\n\\begin{remark}\nThe probabilities $p_n$ can be computed by taking successive derivatives of $G(t)$ and evaluating these at $t=1$. An explicit expression is given by\n\\[\np_{2n-1} = p^n q^{n-1}\\frac{2}{n}\\binom{2n-3}{n-2}.\n\\]\nThis result can also be obtained by the reflection principle. \n\\end{remark}\n\n% probability that we don't hit level 1 at all\n\\begin{remark}\nSince $G(1)=\\sum_{k=0}^{\\infty}p_k$ we might be inclined to think that $G(1)=1$. In fact,\n\\[\nG(1) = \\frac{1 - \\sqrt{1-4pq}}{2q} = \\frac{1-|p-q|}{2q} \n\t= \\begin{cases} \n\t\t1 \t& \\text{ for $p\\geq 1/2$,} \\\\\n\t\tp/q & \\text{ for $p < 1/2$.}\n\t\\end{cases}\n\\]\nThus if $p<q$ we see that $G(1)<1$, which show that the random walk might never reach level $1$ when the probability of a positive step is smaller than the probability of a negative step. In this case, $G(1)=\\sum_{k=0}^{\\infty}p_k = \\prob(T<\\infty)$, so $\\prob(T=\\infty)>0$. It is a remarkable fact that if $p=1/2$, the random walk will \\emph{always} hit level $1$ sooner or later, but this need not happen if $p<1/2$. This behaviour is known as \\emph{criticality} -  many systems exhibit qualitatively different behaviour when the value of a parameter $p$ lies either side of some critical value $p_c$.\n\\end{remark}\n\n% expected first hitting time\n\\begin{remark}\nWe can compute the \\emph{expected} time before the random walk hits $1$ for the first time. If $p<1/2$ then $\\prob(T=\\infty)>0$ so $\\expe(T)=\\infty$. For the case $p\\geq 1/2$, note that\n\\[\nG'(t) = \\frac{2p}{\\sqrt{1-4pqt^2}} - \\frac{1-\\sqrt{1-4pqt^2}}{2qt^2}.\n\\]\n\\[\n\\begin{array}{lcl}\np=1/2:\t& \\qquad\t& \\expe(T) = \\lim_{t\\nearrow 1}G'(t)\t= \\lim_{t\\nearrow 1}\\left(\\frac{1}{\\sqrt{1-t^2}} - \\frac{1-\\sqrt{1-t^2}}{t^2}\\right) = +\\infty. \\\\\np>1/2:\t&\t\t\t& \\expe(T) = \\lim_{t\\nearrow 1}G'(t) = \\frac{1}{p-q}.\n\\end{array}\n\\]\n\\end{remark}\n\n%==========================================================================\n\\begin{exercise}\nConsider a simple random walk $X_0,X_1,X_2,\\ldots$ with $X_0=0$. Let $q$ be the probability that the random walk eventually returns to the starting position $X_0$. If $q=1$, position $X_0$ is called \\emph{recurrent}; if $q<1$, position $X_0$ is called \\emph{transient}. Show that $X_0$ is transient if and only if $\\sum_{n=1}^{\\infty} \\prob(X_n = 0) < \\infty$. [\\textit{Hint}: find expressions for the expected number of times that $X_0$ is re-visited.]\n\\begin{answer}\nLet \n\\[\nI_n = \\begin{cases}\n1 & \\text{if } X_n = 0 \\\\\n0 & \\text{otherwise.}\n\\end{cases}\n\\]\nand let $N = \\sum_{n=1}^{\\infty} I_n$ be the number of times that state $X_0=0$ is revisited.\n\nThe expected value of $N$ is given by\n\\[\n\\expe(N) \n\t= \\expe\\left(\\sum_{n=1}^{\\infty} I_n\\right) \n\t= \\sum_{n=1}^{\\infty} \\expe(I_n)\n\t= \\sum_{n=1}^{\\infty} \\prob(X_n = 0)\n\\]\n\nThe expected value of $N$ is also given by\n\\begin{align*}\n\\expe(N)\n\t& = \\sum_{k=1}^{\\infty} k\\prob(N=k) \\\\\n\t& = \\sum_{k=1}^{\\infty} \\big[ k\\prob(N\\geq k) - k\\prob(N\\geq k+1)\\big] \\\\\n\t& = \\sum_{k=1}^{\\infty} k\\prob(N\\geq k) - \\sum_{k=2}^{\\infty} (k-1)\\prob(N\\geq k) \\\\\n\t& = \\sum_{k=1}^{\\infty} \\prob(N\\geq k) \\\\\n\t& = \\sum_{k=1}^{\\infty} q^k \n\\end{align*}\nwhere the last equality follows by the fact that every return occurs independently with probability $q$. Combining these results, we get\n\\[\n\\sum_{n=1}^{\\infty}\\prob(X_n=0) = \\sum_{k=1}^{\\infty} q^k\n\\]\nwhich diverges if $q=1$, and converges if $q<1$. Thus the random walk is recurrent precisely when $\\sum_{n=1}^{\\infty} \\prob(X_n = 0)$ is infinite.\n\\end{answer}\n\\end{exercise}\n\n%% reflection principle (first passage time distribution)\n%%==========================================================================\n%\\begin{exercise}\n%Consider a simple random walk $X_0,X_1,X_2,\\ldots$ with $X_0=0$. Let $T_{\\ell}$ be the first hitting time at level $\\ell$, defined by $T_{\\ell} = \\min\\{n\\geq 0\\,:\\, X_n = \\ell\\}$. Use the reflection principle to show that the distribution of $T_{\\ell}$ satisfies \n%\\[\n%\\prob(T_{\\ell}\\leq n) = \\prob(X_n = \\ell) + 2\\prob(X_n > \\ell).\n%\\]\n%\\begin[answer}\n%Consider the sequence $X_n^{*}$ defined by\n%\\[\n%X_n^{*} = \\begin{cases}\n%\tX_n\t\t\t& \\text{if } n\\leq\\tau(m) \\\\\n%\t2m - X_n\t\t& \\text{if } n\\geq\\tau(m)\n%\\end{cases}\t\n%\\]\n%By the reflection principle, $X_n^{*}$ is a simple random walk starting from $X_0^{*}=0$.\n%%\n%Consider the event $\\tau(m)\\leq n$. If this event occurs, $X_n$ and $X_n^{*}$ are on opposite sides of $m$ (unless they are both at $m$), and correspond under reflection. Since both processes are simple random walks starting at zero,\n%\\[\n%\\prob(X_n^{*} = m+k) = \\prob(X_n = m+k) \\qquad\\text{for all } k\\geq 0\n%\\]\n%\n%If $k\\geq 0$, the event $X_n=m+k$ is impossible unless $\\tau(m)\\leq n$, so\n%\\begin{align*}\n%\\prob(X_n = m+k) \n%\t& = \\prob\\big(X_n \t= m+k \\text{ and } \\tau(m)\\leq n\\big) \\\\\n%\t& = \\prob\\big(X_n^{*}= m+k \\text{ and } \\tau(m)\\leq n\\big) \\\\\n%\t& = \\prob\\big(X_n \t= m-k \\text{ and } \\tau(m)\\leq n\\big) \\\\\n%\\end{align*}\n%and therefore\n%\\begin{align*}\n%\\prob\\big(\\tau(m)\\leq n\\big) \n%\t& = \\sum_{k=-\\infty}^{\\infty} \\prob\\big(X_n = m+k\\text{ and }\\tau(m)\\leq n\\big) \\\\\n%\t& = \\prob(X_n = m) + 2\\prob(X_n > m)\n%\\end{align*}\n%as required.\n%\\end{answer}\n%\\end{exercise}\n\n\n%-------------------------------------------------\n\\section{Branching processes}\\label{sec:branching}\nIn Victorian England, several aristocratic families realised that their family names could become extinct. In 1873, Sir Francis Galton posed the following question in the \\textit{Educational Times}:\n\\begin{quote}\nHow many male children (on average) must each generation of a family have for the family name to continue in perpetuity?\n\\end{quote}\nThe first complete answer was put forward by Reverend Henry Watson. Galton and Watson published a paper entitled \\textit{On the probability of extinction of families} in 1874. Their model is as follows.\n\n\\ben\n\\it A population starts with a single individual, $Z_0=1$\n\\it At time $n=1$, this individual gives birth to $Z_1$ offspring, where $Z_1\\in\\{0,1,2,\\ldots\\}$, then dies.\n\\it If $Z_1=0$, the population is extinct and $Z_n=0$ for all $n\\geq 2$.\n\\it If $Z_1>0$, each of the $Z_1$ individuals in the first generation gives birth to a random number of offspring at time $n=2$: the first has $Z_{1,1}$ offspring, the second has $Z_{1,2}$ offspring, ..., and the has last $Z_{1,Z_1}$ offspring. \n\\it Assume that every individual in every generation has the same offspring distribution, and the number of offpring born to any individual is independent of the number born to any other individual.\n\\it The total number of individuals in the second generation is\n\\[\nZ_2 = \\sum_{k=1}^{Z_1} Z_{1,k}.\n\\]\n\\it The third, fourth, fifth etc. generations are produced in the same way.\n\\it If it happens that $Z_m=0$ for some $m$ then $Z_n=0$ for all $m\\geq n$, and the population is \\emph{extinct}.\n\\een\n\n\\begin{definition}\nA random process $Z_0,Z_1,Z_2\\ldots$ with the properties described above is called a \\emph{simple branching process} (or Galton-Watson process).\n\\end{definition}\n\nThe offspring distribution determines the evolution of a branching process. Galton's question is to find conditions on the offspring distribution under which\n\\[\n\\prob\\big(Z_n\\geq 1 \\text{ for all } n=0,1,2,\\ldots\\big) = 1.\n\\]\n\nLet $p_0,p_1,p_2,\\ldots$ denote the offspring distribution, and let $G(t)=\\sum_{k=1}^{\\infty}p_k t^k$ be its PGF.\n\n\\begin{theorem}\nThe PGF of $Z_n$ is the $n$-fold composition of $G(t)$ with itself,\n\\[\nG_{Z_n}(t) = \\underbrace{G(G(\\ldots G(t)\\ldots))}_{\\text{$n$ times}} \\quad\\qquad (n\\geq 1). \n\\]\n\\begin{proof}\nFor $n=1$, $Z_1$ has distribution $p_0,p_1,p_2,\\ldots$ so $G_{Z_1}(t) = G(t)$.\nSuppose the statement holds for some $n\\in\\N$. Then\n\\[\nZ_{n+1} = \\sum_{i=1}^{Z_n} Z_{n,i}.\n\\]\nis a random sum of $Z_n$ independent variables with PMF $p_0,p_1,\\ldots$, and where the number of summands $Z_n$ is independent of the summands $Z_{n,1},Z_{n,2},\\ldots,Z_{n,Z_n}$.\n\n\\bigskip\nHence, by Theorem~\\ref{thm:GF-NofX},\n\\[\nG_{Z_{n+1}}(t) = G_{Z_n}\\big[G(t)\\big]\n\\]\nand by the inductive hypothesis, \n\\[\nG_{Z_{n+1}}(t) = \\underbrace{G(G(\\ldots G(t)\\ldots))}_{\\text{$n+1$ times}}\n\\]\nas required.\n\\end{proof}\n\\end{theorem}\n\n%-------------------------\n% theorem\n\\begin{theorem}\nLet $Z_0,Z_1,Z_2,\\ldots$ be a simple branching process, and let $\\mu$ and $\\sigma^2$ be the mean and variance of its offspring distribution. Then $\\expe(Z_n)=\\mu^n$ and \n\\[\n\\var(Z_n) \n\t= \\sigma^2\\mu^n(1+\\mu+\\mu^2+\\cdots+\\mu^n)\n\t= \\begin{cases}\n\t\t\\sigma^2(n+1)\t\t\t\t\t\t\t& \\text{if } \\mu=1,\\\\\n\t\t\\sigma^2\\mu^n\\left(\\frac{1-\\mu^{n+1}}{1-\\mu}\\right)\t& \\text{if } \\mu\\neq 1.\n\t\\end{cases}\t\t\n\\]\n\\end{theorem}\n%-------------------------\n\\begin{proof}\nFor brevity, let $G_n(t)$ denote the PGF $G_{Z_n}(t)$ of $Z_n$\n\\ben\n\\it % mean\nTo find the mean, differentiate $G_n(t) = G\\big(G_{n-1}(t)\\big)$,\n\\[\nG'_n(t) = G'\\big(G_{n-1}(t)\\big)G'_{n-1}(t).\n\\]\nEvaluating this at $t=1$, and using the fact that $G_{n-1}(1)=1$,\n\\[\n\\expe(Z_n) = G'_n(1) = G'(1)G'_{n-1}(1) = \\mu\\expe(Z_{n-1})\n\\]\nThe result then follows by induction.\n\\it % variance\nTo find the variance, differentiate $G_n(s)=G\\big(G_{n-1}(s)\\big)$ twice to obtain\n\\[\nG''_n(1) = G''(1)G'_{n-1}(1)^2 + G'(1)G''_{n-1}(1)\n\\]\nand substitute in the expression $\\var(Z_n) = G''_n(1) + G'_n(1) - G'_n(1)^2$.\n\\een\n\\end{proof}\n\n%-----------------------------\n\\subsection{Extinction probability}\n\nThe event that the population becomes extinct can be written as\n\\[\nE = \\big\\{\\omega\\in\\Omega:Z_n(\\omega)=0 \\text{ for some } n\\in\\N\\}.\n\\]\nThis can be written as the union of an expanding sequence of events $E_1\\subseteq E_2\\subseteq\\ldots$,\n\\[\nE = \\medcup_{n=1}^{\\infty} E_n \\quad\\text{where}\\quad E_n = \\{\\omega\\in\\Omega:Z_n(\\omega)=0\\}.\n\\]\nBy the continuity of probability measures, the \\emph{extinction probability} is \n\\[\n\\prob(E) = \\lim_{n\\to\\infty}\\prob(E_n).\n\\]\nUsing the fact that $\\prob(E_n) = \\prob(Z_n=0) = G_{Z_n}(0)$,\n\\[\n\\prob(E) = \\lim_{n\\to\\infty}G_{Z_n}(0) = \\lim_{n\\to\\infty} \\underbrace{G(G(\\ldots G(0)\\ldots))}_{\\text{$n$ times}}\n\\]\n\nRemarkably, the extinction probability $\\prob(E)$ can be computed even when $G_{Z_n}$ is not known explicitly.\n\\begin{theorem}\nThe extinction probability is the smallest non-negative solution of the so-called \\emph{extinction equation},\n\\[\nx = G(x)\n\\]\nwhere $G$ is the PGF of the offspring distribution.\n\\end{theorem}\n\n\\begin{proof}\nLet $e=\\prob(E)$ be the extinction probability. First we show that $e$ is a solution of $x=G(x)$. Let\n\\[\nx_n = \\underbrace{G(G(\\ldots G(0)\\ldots))}_{\\text{$n$ times}}\n\\]\nThen (1) $e=\\lim_{n\\to\\infty}x_n$ and (2) $G(x_n) = x_{n+1}$, so\n\\[\ne \t= \\lim_{n\\to\\infty}x_n \n\t= \\lim_{n\\to\\infty}x_{n+1} \n\t= \\lim_{n\\to\\infty}G(x_n) \n\t= G(\\left(\\lim_{n\\to\\infty}x_n\\right)\n\t= G(e),\n\\]\nwhere we have used the fact that $G$ is a continuous function.\n\nTo show that $e=\\prob(E)$ is the smallest solution, let $e'$ be another solution of $x=G(x)$ in $[0,1]$. Since $e'\\geq 0$ and $G(t)$ is a non-decreasing function,\n\\[\nG(0) \\leq G(e') = e'.\n\\]\nApplying $G$ to both sides, since $G(t)$ is increasing,\n\\[\nG(G(0)) \\leq G(G(e')) = G(e') = e'.\n\\]\nRepeating this procedure, we get\n\\[\n\\prob(E_n) = \\underbrace{G(G(\\ldots G(0)\\ldots))}_{\\text{$n$ times}} \\leq e'.\n\\]\nHence,\n\\[\ne =\\prob(E) = \\lim_{n\\to\\infty}\\prob(E_n) \\leq \\lim_{n\\to\\infty} e' = e',\n\\]\nso $e$ is not larger than any other solution $e'$ of $x=G(x)$.\n\\end{proof}\n\n%-------------------------------------------------\n\\section{Martingales}\\label{sec:martingales}\n%-------------------------\n% definition\n\\begin{definition}\nA random process $X_0,X_1,\\ldots$ is called a \\emph{martingale} with respect to the sequence of random variables $\\xi_1,\\xi_2,\\ldots$ if \n\\ben\n\\it $\\expe(|X_n|) < \\infty$ and\n\\it $\\expe(X_{n+1}|\\xi_1,\\ldots,\\xi_n) = X_n$.\n\\een\n\\bit\n\\it A \\emph{sub-martingale} has $\\expe(X_{n+1}|\\xi_1,\\ldots,\\xi_n) \\geq X_n$ (the process tends to increase over time).\n\\it A \\emph{super-martingale} has $\\expe(X_{n+1}|\\xi_1,\\ldots,\\xi_n) \\leq X_n$ (the process tends to decrease over time).\n\\eit\n\\end{definition}\n\n%-------------------------\n% example\n\\begin{example}[Random walk]\nLet $X_n=X_0+\\sum_{k=1}^n \\xi_n$ be a symmetric simple random walk (so $\\prob(\\xi_k=1)=\\prob(\\xi_k=-1) = 1/2$). Show that $\\{X_n\\}$ is a martingale with respect to the increments $\\xi_1,\\xi_2,\\ldots$.\n\\begin{solution}\nFor the first condition, $\\expe(|\\xi_i|)=1$ so\n\\[\n\\expe(|X_n|) = \\expe\\left(\\left|\\sum_{i=1}^{n} \\xi_i\\right|\\right) \\leq \\sum_{i=1}^{n} \\expe(|\\xi_i|) < \\infty.\n\\]\nFor the second condition,\n\\begin{align*}\n\\expe(X_{n+1}|\\xi_1,\\xi_2,\\ldots,\\xi_n)\n\t& = \\expe(\\xi_1+\\xi_2\\ldots+\\xi_{n+1}|\\xi_1,\\ldots,\\xi_n) \\\\\n\t& = \\expe(\\xi_1|\\xi_1,\\ldots,\\xi_n) + \\expe(\\xi_2|\\xi_1,\\ldots,\\xi_n) + \\ldots + \\expe(\\xi_{n+1}|\\xi_1,\\ldots,\\xi_n) \\\\\n\t& = \\expe(\\xi_1|\\xi_1) + \\expe(\\xi_2|\\xi_2) + \\ldots + \\expe(\\xi_n|\\xi_n) + \\expe(\\xi_{n+1}) \\qquad \\text{by independence} \\\\\n\t& = \\xi_1 + \\xi_2 + \\ldots + \\xi_n + 0 \\\\\n\t& = X_n.\n\\end{align*}\n\\end{solution}\n\\end{example}\n\n%-------------------------\n% example\n\\begin{example}[Sub-martingale]\nLet $\\xi_1,\\xi_2,\\ldots$ be independent random variables with zero means, finite variances and partial sums $X_n=\\sum_{i=1}^n \\xi_i$. Show that $X_n^2$ is a sub-martingale with respect to $\\xi_1,X_2,\\ldots$.\n\\begin{solution}\nSince $X^2_{n+1} = (X_n + \\xi_{n+1})^2$, \n\\begin{align*}\n\\expe(X^2_{n+1}|\\xi_1,\\xi_2,\\ldots,\\xi_n)\n\t& = \\expe(X_n^2 + 2X_n\\xi_{n+1} + \\xi_{n+1}^2 | \\xi_1,\\ldots,\\xi_{n}) \\\\\n\t& = X^2_n + 2\\expe(\\xi_{n+1})\\expe(X_n | \\xi_1,\\ldots,\\xi_n) + \\expe(\\xi_{n+1}^2) \\qquad \\text{by independence,} \\\\\n\t& = X^2_n + \\expe(\\xi_{n+1}^2) \\geq T_n \\qquad\\text{because $\\expe(\\xi_{n+1})=0$.}\n\\end{align*}\t\nSince $\\xi_{n+1}^2>0$, $\\expe(X^2_{n+1}|\\xi_1,\\xi_2,\\ldots,\\xi_n)\\geq X^2_n$, so $X^2_n$ is a sub-martingale.\n\\end{solution}\n\\end{example}\n\n%-------------------------\n% thm: MCT\n\\begin{theorem}[Martingale Convergence Theorem]\nLet $X_0,X_1,\\ldots$ be a martingale such that $\\expe(|X_n|)$ is bounded for all $n=0,1,2,\\ldots$. Then there exists a finite random variable $X$ such that $X_n\\to X$ with probability one as $n\\to\\infty$.\n\\end{theorem}\n\nThe MCT can be used to prove the following remarkable theorem.\n%-------------------------\n% example (application of MCT}\n\\begin{theorem}\nA symmetric simple random walk on $\\Z$ will visit every point with probability 1.\n\\end{theorem}\n\\begin{proof}\nLet $X_0=0$ and $b\\in\\Z$, and suppose (without loss of generality) that $b<0$. Let $T$ be the first time $n$ for which $X_n=b$, and consider the corresponding \\emph{stopped process} $\\tilde{X}_0,\\tilde{X}_1,\\tilde{X}_2,\\ldots$ defined by $\\tilde{X}_n = X_{\\min\\{n,T\\}}$.\n\\bit\n\\it The stopped process remains in position $b$ from time $T$ onwards.\n\\eit\n\nIt is easy to show that $\\tilde{X}_n$ is a martingale, and because $\\tilde{X}_n - b$ is non-negative, $\\expe(|\\tilde{X}_n - b|) = \\expe(\\tilde{X}_n - b) < \\infty$.\n\n\\bigskip\nBy the Martingale Convergence Theorem, the limit $\\tilde{X} = \\lim_{n\\to\\infty}\\tilde{X}_n$ exists and is finite with probability one.\n\\bit\n\\it In particular, $|\\tilde{X}_{n+1} - \\tilde{X}_n|$ converges to zero, and must therefore  be less than 1 for large $n$.\n\\it However $|\\tilde{X}_{n+1} - \\tilde{X}_n| = 1$ whenever $n < T$.\n\\it Thus we have $T<\\infty$, and hence $X_n = b$ for some $n$.\n\\eit\n\\end{proof}\n\n% ex: branchingn process\n\\begin{exercise}\nLet $Z_0,Z_1,Z_2,\\ldots$ be a simple branching process with $Z_0=1$. Show that the sequence $W_1,W_2,\\ldots$ with $W_n=Z_n/\\expe(Z_n)$ is a martingale with respect to $Z_1,Z_2,\\ldots$.\n\\begin{answer}\nConditioned on $Z_n=z_n$, the number $Z_{n+1}$ is the sum of $z_n$ independent familiy sizes,\n\\[\n\\expe(Z_{n+1}: Z_n=z_n) = \\mu z_n\n\\]\nwhere $\\mu$ is the expected family size. By the Markov property,\n\\[\n\\expe(Z_{n+1}: Z_1,Z_2,\\ldots,Z_n) = \\mu Z_n\n\\]\nSince $\\expe(Z_n)=\\mu^n$, we conclude that\n\\[\n\\expe(W_{n+1}: Z_1,Z_2,\\ldots,Z_n) = W_n\n\\]\nas required.\n\\end{answer}\n\\end{exercise}\n\n%==========================================================================\n\\begin{exercise}\nAn urn contains one red ball and one green ball. At each time step, we choose one ball uniformly at random from the urn, and replace it along with another ball of the same colour. Let $R_n$ and $G_n$ respectively denote the number of red balls and green balls after $n$ steps, and let $M_n$ denote the fraction of green balls in the urn.\n\\ben\n\\it Show that $M_n$ is a martingale.\n\\it Show that $M_n$ converges to a finite limit with probability 1 as $n\\to\\infty$\n\\een\n\\begin{answer}\n\\ben\n\\it % (a)\n$M_n$ is a martingale because\n\\begin{align*}\n\\expe(M_{n+1} | R_0,G_0,\\ldots,R_n,G_n)\n\t& = \\left(\\frac{R_n}{R_n+G_n}\\right)\\left(\\frac{G_n}{R_n+G_n+1}\\right)\n\t  + \\left(\\frac{G_n}{R_n+G_n}\\right)\\left(\\frac{G_n+1}{R_n+G_n+1}\\right) \\\\\n\t& = \\frac{G_n}{R_n+G_n} \\\\\n\t& = M_n\n\\end{align*}\t\t\n\\it % (b)\nSince $M_n\\geq 0$ is bounded for all $n\\in\\N$, it follows by the martingale that there exists a finite random variable $M$ such that $M_n\\to M$ with probability one as $n\\to\\infty$. In fact, it can be shown that\n\\[\n\\prob(G_n = m+1) = \\binom{m}{n}\\frac{m!(n-m)!}{(n+1)!} = \\frac{1}{n+1}\n\\]\nand hence\n\\[\n\\prob(M_n\\leq x) = \\frac{\\lfloor x(n+2)-1\\rfloor}{n+1} \\to x \\quad\\text{as }n\\to\\infty\n\\]\nThus the distribution of $M_n$ approaches a uniform distribution on $[0,1]$ as $n\\to\\infty$.\n\\een\n\\end{answer}\n\\end{exercise}\n\n\\endinput\n", "meta": {"hexsha": "ac5fb40fc91b6c64b00a9cdcedc0ecbe2832d4c0", "size": 38999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/12_random_processes.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/12_random_processes.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/12_random_processes.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": 41.62113127, "max_line_length": 603, "alphanum_fraction": 0.6255545014, "num_tokens": 14483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.8652240947405565, "lm_q1q2_score": 0.6701882073651724}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{The Cram\\'{e}r-Rao lower bound}\\label{sec:crlb}\n\nWe now show that the variance of any unbiased estimator cannot be smaller than a certain fixed value which depends only on the Fisher information of the associated distribution. First we need the following lemma.\n%\\bit\n%\\it Let $X$ be a random variable having PDF $f(x,\\theta)$, where $\\theta$ is an unknown scalar parameter. \n%\\it Let $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$. \n%\\it Let $I(\\theta)$ be the Fisher information of a single observation,\n%\\[\n%I(\\theta) = \\var\\big[u(\\theta;X)\\big]\n%\\quad\\text{where}\\quad\n%u(\\theta;X) = \\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta).\n%\\]\n%\\eit\n%\n\\begin{lemma}\n%Let $X$ be a random variable, let $f(x,\\theta)$ denote its PDF, l\nLet $T(X)$ be an unbiased estimator of $\\theta$ and let $U(X)$ be the score function of $X$. Then\n\\[\n\\cov(T,U) = 1\n\\]\n\\end{lemma}\n\n\\begin{proof}\nWe prove the lemma for continuous random variables. \n\\par\nBy Lemma~\\ref{lem:expe_score_function}, $\\expe(U)=0$ so\n\\begin{align*}\n\\cov(T,U)\n\t& = \\expe(TU) - \\expe(T)\\expe(U) = \\expe(TU) \\\\\n%\t= \\expe(TU) \\\\\n\t& = \\expe\\left[T(X)\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\\right)\\right] \\\\\n\t& = \\expe\\left[T(X)\\left(\\frac{1}{f(X;\\theta)}\\frac{\\partial}{\\partial\\theta}f(X;\\theta)\\right)\\right] \\\\\n\t& = \\int T(x)\\left(\\frac{1}{f(x;\\theta)}\\frac{\\partial}{\\partial\\theta}f(x;\\theta)\\right)f(x;\\theta)\\,dx \\\\\n\t& = \\int T(x)\\left(\\frac{\\partial}{\\partial\\theta}f(x;\\theta)\\right)\\,dx\\\\\n\t& = \\frac{\\partial}{\\partial\\theta}\\int T(x)f(x;\\theta)\\,dx \\quad\\text{(by the regularity conditions)} \\\\\n\t& = \\frac{\\partial}{\\partial\\theta}\\expe(T)\n\t= \\frac{\\partial}{\\partial\\theta}\\theta\n\t= 1\\qquad\\text{(because $T$ is unbiased).}\n\\end{align*}\n\\end{proof}\n\n% thm: CRLB\n\\begin{theorem}[CRLB]\\label{thm:crlb}\nLet $X$ be a random variable and let $f(x;\\theta)$ denote its PDF where $\\theta$ is an unknown scalar. If $T(X)$ is an unbiased estimator of $\\theta$ then\n\\[\n\\var(T) \\geq \\frac{1}{I(\\theta)}.\n\\]\n\\end{theorem}\n\n% proof\n\\begin{proof}\n%Because $\\expe(U)=0$ and $\\expe(T)=0$, \nBy the Cauchy-Schwarz inequality applied to $T-\\expe(T)$ and $U-\\expe(U)$,\n\\begin{align*}\n1 = \\cov(T,U)^2\n\t& = \\expe\\big([T-\\expe(T)][U-\\expe(U)]\\big)^2 \\\\\n\t& \\leq \\expe\\big([T-\\expe(T)]^2\\big)\\expe\\big([U-\\expe(U)]^2\\big) \\\\\n\t& = \\var(T)\\var(U)\n\\end{align*}\nHence\n\\[\n\\var(T) \\geq \\frac{1}{\\var(U)}.\n\\]\nThus, because $I(\\theta)=\\var(U)$, i.e. the variance of the score function, we conclude that\n\\[\n\\var(T) \\geq \\frac{1}{I(\\theta)}.\n\\]\n\\end{proof}\n\n% thm: CRLB\n\\begin{corollary}\\label{cor:crlb}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample and let $f(x,\\theta)$ denote their common PDF, where $\\theta$ is an unknown scalar. If $T_n$ is an unbiased estimator of $\\theta$ then\n\\[\n\\var(T_n) \\geq \\frac{1}{nI(\\theta)}\n\\]\nwhere $I(\\theta)$ is the Fisher information of a single observation.\n\\end{corollary}\n\n% remark\n\\begin{remark}\n\\bit\n\\it The CRLB provides a \\emph{lower limit} on the variance of an unbiased estimator.\n%\\it The CRLB provides an \\emph{upper limit} on the amount of information we can extract from a random sample.\n\\it Similar results hold for biased estimators, vectors of parameters, non-independent samples, and so on.\n\\it The CRLB has deep connections with the \\emph{Heisenberg Uncertainty Principle}.\n\\eit\n\\end{remark}\n\n%----------------------------------------------------------------------\n\\section{Efficiency}\n%----------------------------------------------------------------------\n\n% definition: efficiency\n\\begin{definition}\nLet $T$ be an unbiased estimator of the parameter $\\theta$.\n\\ben\n\\it \nThe \\emph{efficiency} of $T$ as an estimator of $\\theta$ is defined by \n$e(T) = \\displaystyle\\frac{1/I(\\theta)}{\\var(T)}$.\n\\it \nIf $e(T)=1$ then $T$ is called an \\emph{efficient} estimator of $\\theta$.\n\\een\n\\end{definition}\nAn efficient estimator is thus an unbiased estimator whose variance achieves the Cram\\'{e}r-Rao lower bound (for all $\\theta$) and which therefore has the smallest variance among all possible unbiased estimators.\n\n%----------------------------------------\n% example: mean of a Bernoulli sample\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Bernoulli}(\\theta)$ distribution, where $0<\\theta<1$ is unknown. Show that the sample mean $\\bar{X}$ is an efficient estimator of $\\theta$.\n\\end{example}\n\n\\begin{solution}\nLet $X\\sim\\text{Bernoulli}(\\theta)$. Then $\\var(X)=\\theta(1-\\theta)$, so \n\\[\n\\var(\\bar{X})=\\frac{\\theta(1-\\theta)}{n}.\n\\]\n\\par\n\\par\nThe PMF of $X$ is \n$\nf(x;\\theta)=\\theta^x(1-\\theta)^{1-x}\\quad\\text{for $x\\in\\{0,1\\}$ (and zero otherwise).}\n$\n%for $x\\in\\{0,1\\}$, and zero otherwise.\n\\par\nThe log-likelihood function of a single observation is\n\\[\n%\\log f(x;\\theta) = \\displaystyle\\frac{x-\\theta}{\\theta(1-\\theta)}\n\\log f(x;\\theta) = x\\log\\theta + (1-x)\\log(1-\\theta).\n\\]\nThe score function of a single observation is\n\\[\nu(\\theta;x)\n\t= \\frac{\\partial}{\\partial\\theta}\\log f(x,\\theta)\n%\t= \\frac{\\partial}{\\partial\\theta}\\left(\\frac{1}{\\theta(1-\\theta)}\\right)\n\t= \\frac{x}{\\theta} - \\frac{1-x}{1-\\theta}\n\t= \\frac{x-\\theta}{\\theta(1-\\theta)}.\n\\]\nSince $\\expe(X)=\\theta$ and $\\var(X)=\\theta(1-\\theta)$, the Fisher information of a single observation is\n\\[\nI(\\theta) = \\expe\\left[\\left(\\frac{\\partial\\log f(x,\\theta)}{\\partial\\theta}\\right)^2\\right]\n\t= \\frac{\\expe\\big[(X-\\theta)^2\\big]}{\\theta^2(1-\\theta)^2} \n\t= \\frac{\\var(X)}{\\theta^2(1-\\theta)^2} \n\t= \\frac{1}{\\theta(1-\\theta)}.\n\\]\nHence for a random sample of size $n$, because $\\bar{X}$ is an unbiased estimator of $\\theta$, the Cram\\'{e}r-Rao lower bound yields\n\\[\n\\var(\\bar{X}) \\geq \\frac{\\theta(1-\\theta)}{n}.\n\\]\nBut we know that $\\var(\\bar{X})=\\theta(1-\\theta)/n$, so the variance of $\\bar{X}$ attains the CRLB. Thus it follows that $\\bar{X}$ is an efficient estimator of $\\theta$.\n\\end{solution}\n\n% example: mean of normal sample\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\theta,\\sigma^2)$ distribution, whose mean $\\theta$ is unknown but whose variance $\\sigma^2$ is known. Show that $\\bar{X}$ is an efficient estimator of $\\theta$.\n\\end{example}\n\\begin{solution}\nLet $X\\sim N(\\theta,\\sigma^2)$. By Example~\\ref{example:fisher_information_normal}, the Fisher information of $X$ is \n\\[\nI(\\theta) = \\displaystyle\\frac{1}{\\sigma^2}.\n\\]\n$\\bar{X}$ is an unbiased estimator of $\\theta$, so its variance is bounded below by the CRLB:\n\\[\n\\var(\\bar{X}) \\geq \\frac{1}{nI(\\theta)} \n\\qquad\\text{so}\\qquad\n\\var(\\bar{X}) \\geq \\frac{\\sigma^2}{n}.\n\\]\nSince $\\var(\\bar{X}) = \\displaystyle\\frac{\\sigma^2}{n}$, we see that $\\var(\\bar{X})$ attains the CRLB, so $\\bar{X}$ is an efficient estimator for $\\theta$.\n\\end{solution}\n\n\\begin{example}\nLet $X$ be a continuous random variable with the following PDF:\n\\[\nf(x) = \\begin{cases}\n\t\\displaystyle\\frac{3\\theta^3}{(x+\\theta)^4}\t& \\text{ for $x>0$,} \\\\\n\t0\t\t\t\t\t\t\t\t\t\t\t& \\text{ otherwise.}\n\\end{cases}\n\\]\n\\ben\n\\it Show that $\\expe(X)=\\theta/2$ and $\\var(X) = 3\\theta^2/4$.\n\\it Show that $T = 2\\bar{X}$ is an unbiased esimator of $\\theta$, and find its variance.\n\\it Show that the efficiency of $T$ as an estimator of $\\theta$ is $5/9$.\n\\een\n\\begin{solution}\n\\ben\n\\it % <<< mean and variance of sample points\nIntegration by parts:\n\\begin{align*}\n\\expe(X)\n\t& = 3\\theta^3 \\int_0^{\\infty} \\frac{x}{(x+\\theta)^4}\\,dx \\\\\n\t& = 3\\theta^3\\left(\\left[\\frac{-x}{(x+\\theta)^3}\\right]_0^\\infty - \\int_0^\\infty \\frac{-1}{3(x+\\theta)^2}\\,dx\\right)\n\t= 3\\theta^3\\left[\\frac{-1}{6(x+\\theta)^2}\\right]_0^\\infty = \\frac{\\theta}{2}. \\\\\n\\expe(X^2)\n\t& = 3\\theta^3 \\int_0^{\\infty} \\frac{x^2}{(x+\\theta)^4}\\,dx \\\\\n\t& = 3\\theta^3\\left(\\left[\\frac{-x^2}{(x+\\theta)^3}\\right]_0^\\infty - \\int_0^\\infty 2x\\frac{-1}{3(x+\\theta)^3}\\,dx\\right) \\\\\n\t& = 2\\theta^3\\int_0^\\infty \\frac{x}{(x+\\theta)^3}\\,dx \\\\\n\t& = 2\\theta^3\\left(\\left[\\frac{-x}{2(x+\\theta)^2}\\right]_0^\\infty - \\int_0^\\infty \\frac{-1}{2(x+\\theta)^2}\\,dx\\right)\n\t= \\theta^3\\left[\\frac{-1}{x+\\theta}\\right]_0^\\infty = \\theta^2.\n\t\\end{align*}\nHence $\\var(X) = \\expe(X^2)-\\expe(X)^2 = \\theta^2 - \\theta^2/4 = 3\\theta^2/4$.\t\n\\it % <<< bias & variance of T\nThe mean and variance of $T$ are\n\\begin{align*}\n\\expe(T) \n\t& = 2\\expe(\\bar{X}) = 2\\expe(X) = \\theta \\quad\\text{so $T$ is unbiased}, \\\\\n\\var(T) \n\t& = 4\\var(\\bar{X}) = 4\\var(X)/n = 3\\theta^2/n.\n\\end{align*}\n\\it % <<< efficiency\n\\bit\n\\it $f(x) = 3\\theta^3/(x+\\theta)^4$.\n\\it $\\ell(\\theta) = \\log 3 + 3\\log\\theta - 4\\log(x+\\theta)$.\n\\it $\\ell'(\\theta) = \\displaystyle\\frac{3}{\\theta} - \\frac{4}{x+\\theta}$.\n\\it $\\ell''(\\theta) = -\\displaystyle\\frac{3}{\\theta^2} + \\frac{4}{(x+\\theta)^2}$.\n\\it $I(\\theta) = -\\expe\\big[\\ell''(\\theta;X)\\big] = \\displaystyle\\frac{3}{\\theta^2} - 4\\expe\\left(\\frac{1}{(X+\\theta)^2}\\right)$.\n\\eit\nNow,\n\\begin{align*}\n\\expe\\left(\\frac{1}{(X+\\theta)^2}\\right)\n\t& = \\int_0^\\infty \\left(\\frac{1}{(x+\\theta)^2}\\right)\\left(\\frac{3\\theta^3}{(x+\\theta)^4}\\right)\\,dx \\\\\n\t& = 3\\theta^3 \\int_0^\\infty \\frac{1}{(x+\\theta)^6}\\,dx \\\\\n\t& = 3\\theta^3\\left[\\frac{-1}{5(x+\\theta)^5}\\right]_0^\\infty\n\t= \\frac{3}{5\\theta^2}.\n\\end{align*}\nHence,\n\\[\nI(\\theta) = \\frac{3}{\\theta^2} - \\frac{12}{5\\theta^2} = \\frac{3}{5\\theta^2}\n\\quad\\text{and}\\quad\nI_n(\\theta) = nI(\\theta) = \\frac{3n}{5\\theta^2}\n\\]\nSince $\\var(T)=3\\theta^2/n$, we see that\n\\[\n\\text{Efficiency}(T) = \\frac{1/I_n(\\theta)}{\\var{T}} = \\frac{5\\theta^2/3n}{3\\theta^2/n} = \\frac{5}{9}.\n\\]\n\\een\n\\end{solution}\n\\end{example}\n\n%%-----------------------------\n%% example: variance of normal sample\n%\\begin{example}\n%Let $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\mu,\\theta)$ distribution, whose mean $\\mu$ is known but whose variance $\\theta$ is unknown. Using the fact that, for the normal distribution, $\\expe\\big((X-\\mu)^4\\big)=3\\theta^2$, show that the statistic\n%\\[\n%T(X_1,X_2,\\ldots,X_n) = \\frac{1}{n}\\sum_{i=1}^{n} (X_i-\\mu)^2 \n%\\]\n%is an efficient estimator of the variance $\\theta$.\n%\\end{example}\n%\n%\\begin{solution}\n%Let $X\\sim N(\\mu,\\theta)$. First we note that $T$ is unbiased, because\n%\\[\n%\\expe(T) = \\frac{1}{n}\\sum_{i=1}^{n} \\expe\\big[(X_i-\\mu)^2\\big] = \\var(X) = \\theta.\n%\\]\n%\n%Furthermore, because the $X_i$ are independent, the variance of $T$ is\n%\\begin{align*}\n%\\var(T) \n%\t= \\frac{1}{n}\\var\\big[(X-\\mu)^2\\big]\n%\t& = \\frac{1}{n}\\Big(\\expe\\big[(X-\\mu)^4\\big] - \\expe\\big[(X-\\mu)^2\\big]^2\\Big) \\\\\n%\t& = \\frac{1}{n}\\big(3\\theta^2 - \\theta^2\\big) \\\\\n%\t& = \\frac{2\\theta^2}{n}\n%\\end{align*}\n%\n%Let $f(x;\\theta)$ denote the PDF of the $N(\\mu,\\theta)$ distribution:\n%\\begin{align*}\n%f(x;\\theta) \n%\t& = \\ \\frac{1}{\\sqrt{2\\pi\\theta}}\\exp\\left(-\\frac{(x-\\mu)^2}{2\\theta}\\right), \\\\[2ex]\n%\\log f(x;\\theta)\n%\t& = \\ \\log\\left(\\frac{1}{\\sqrt{2\\pi}}\\right) + \\log\\left(\\frac{1}{\\sqrt{\\theta}}\\right)  - \\frac{(x-\\mu)^2}{2\\theta}, \\\\[2ex]\n%\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\n%\t& = \\ -\\frac{1}{2\\theta} + \\frac{(x-\\mu)^2}{2\\theta^2}, \\\\[2ex]\n%\\frac{\\partial^2}{\\partial\\theta^2}\\log f(x;\\theta)\n%\t& = \\ \\frac{1}{2\\theta^2} - \\frac{(x-\\mu)^2}{\\theta^3}.\n%\\end{align*}\n%\n%The Fisher information of a single observation is thus given by\n%\\begin{align*}\n%I(\\theta) \n%\t= -\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(X;\\theta)\\right)\n%\t& = -\\expe\\left(\\frac{1}{2\\theta^2} - \\frac{(X-\\mu)^2}{\\theta^3}\\right) \\\\\n%\t& = -\\frac{1}{2\\theta^2} + \\frac{\\expe(X-\\mu)^2}{\\theta^3} \\\\\n%\t& = -\\frac{1}{2\\theta^2} + \\frac{\\theta}{\\theta^3} \n%\t= \\frac{1}{2\\theta^2}.\n%\\end{align*}\n%\n%By the Cram\\'{e}r-Rao theorem,\n%\\[\n%\\var(T) \\geq \\frac{1}{nI(\\theta)} = \\frac{2\\theta^2}{n}\n%\\]\n%\n%\\bit\n%\\it The variance of $T$ attains the CRLB for all values of $\\theta>0$.\n%\\it $T$ is therefore an efficient estimator of the variance of the Normal distribution.\n%\\eit\n%\\end{solution}\n\n% !TEX root = main.tex\n%----------------------------------------------------------------------\n\\begin{exercise}\n\\begin{questions}\n%----------------------------------------\n\\question\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Poisson}(\\theta)$ distribution, where $\\theta>0$ is unknown. Show that the sample mean $\\bar{X}$ is an efficient estimator of $\\theta$.\n\n\\begin{answer}\nThe PMF of the $\\text{Poisson}(\\theta)$ distribution is\n\\[\nf(x;\\theta) = \\frac{\\theta^x\\exp(-\\theta)}{x!} \\quad \\text{for $x=0,1,2,3,\\ldots$ (zero otherwise)}\n\\]\nLet $X\\sim\\text{Poisson}(\\theta)$. The score function of $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$ and $\\var(X)=\\theta$, the Fisher information of a single observation is therefore\n\\[\nI(\\theta) \n\t= \\expe\\left[\\left(\\frac{\\partial}{\\partial\\theta}\\log f(x,\\theta)\\right)^2\\right]\n\t= \\frac{\\expe\\big[(X-\\theta)^2\\big]}{\\theta^2} = \\frac{\\var(X)}{\\theta^2} = \\frac{1}{\\theta}.\n\\]\nHence for a random sample of size $n$, the CRLB is equal to \n\\[\n\\frac{1}{nI(\\theta)} = \\frac{\\theta}{n}.\n\\]\nThis is equal to the variance of the sample mean $\\bar{X}$, so $\\bar{X}$ is an efficient estimator of $\\theta$.\n\n\\end{answer}\n\n\n%----------------------------------------\n\\question\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\mu,\\theta)$ distribution, whose mean $\\mu$ is known but whose variance $\\theta$ is unknown. Using the fact that $\\expe\\big((X-\\mu)^4\\big)=3\\theta^2$ for the normal distribution, show that the statistic\n\\[\nT = \\frac{1}{n}\\sum_{i=1}^{n} (X_i-\\mu)^2 \n\\]\nis an efficient estimator of the variance $\\theta$.\n\n\\begin{answer}\nLet $X\\sim N(\\mu,\\theta)$. First we note that $T$ is unbiased, because\n\\[\n\\expe(T) = \\frac{1}{n}\\sum_{i=1}^{n} \\expe\\big[(X_i-\\mu)^2\\big] = \\var(X) = \\theta.\n\\]\n\nFurthermore, because the $X_i$ are independent, the variance of $T$ is\n\\begin{align*}\n\\var(T) \n\t= \\frac{1}{n}\\var\\big[(X-\\mu)^2\\big]\n\t& = \\frac{1}{n}\\Big(\\expe\\big[(X-\\mu)^4\\big] - \\expe\\big[(X-\\mu)^2\\big]^2\\Big) \\\\\n\t& = \\frac{1}{n}\\big(3\\theta^2 - \\theta^2\\big) \\\\\n\t& = \\frac{2\\theta^2}{n}\n\\end{align*}\n\nLet $f(x;\\theta)$ denote the PDF of the $N(\\mu,\\theta)$ distribution:\n\\begin{align*}\nf(x;\\theta) \n\t& = \\ \\frac{1}{\\sqrt{2\\pi\\theta}}\\exp\\left(-\\frac{(x-\\mu)^2}{2\\theta}\\right), \\\\[2ex]\n\\log f(x;\\theta)\n\t& = \\ \\log\\left(\\frac{1}{\\sqrt{2\\pi}}\\right) + \\log\\left(\\frac{1}{\\sqrt{\\theta}}\\right)  - \\frac{(x-\\mu)^2}{2\\theta}, \\\\[2ex]\n\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\n\t& = \\ -\\frac{1}{2\\theta} + \\frac{(x-\\mu)^2}{2\\theta^2}, \\\\[2ex]\n\\frac{\\partial^2}{\\partial\\theta^2}\\log f(x;\\theta)\n\t& = \\ \\frac{1}{2\\theta^2} - \\frac{(x-\\mu)^2}{\\theta^3}.\n\\end{align*}\n\nThe Fisher information of a single observation is thus given by\n\\begin{align*}\nI(\\theta) \n\t= -\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(X;\\theta)\\right)\n\t& = -\\expe\\left(\\frac{1}{2\\theta^2} - \\frac{(X-\\mu)^2}{\\theta^3}\\right) \\\\\n\t& = -\\frac{1}{2\\theta^2} + \\frac{\\expe(X-\\mu)^2}{\\theta^3} \\\\\n\t& = -\\frac{1}{2\\theta^2} + \\frac{\\theta}{\\theta^3} \n\t= \\frac{1}{2\\theta^2}.\n\\end{align*}\n\nBy the Cramer-Rao theorem,\n\\[\n\\var(T) \\geq \\frac{1}{nI(\\theta)} = \\frac{2\\theta^2}{n}\n\\]\n\n\\bit\n\\it The variance of $T$ attains the CRLB for all values of $\\theta>0$.\n\\it $T$ is therefore an efficient estimator of the variance of the Normal distribution.\n\\eit\n\\end{answer}\n\n\\question % rayleigh\nLet $X\\sim\\text{Rayleigh}(\\theta)$ whose CDF is given by\n\\[\nF(x) = 1 - e^{-x^2/2\\theta} \\quad\\text{for $x\\geq 0$ and zero otherwise.}\n\\]\n\\ben\n\\it Show that $X^2\\sim\\text{Exponential}(2\\theta)$ where $2\\theta$ is a scale paremter.\n\\it Show that the MLE of $\\theta$ is $\\displaystyle T=\\frac{1}{2n}\\sum_{i=1}^n X_i^2$.\n\\it Show that the $T$ is an unbiased estimator of $\\theta$.\n\\it Show that the $T$ is an efficient estimator of $\\theta$.\n\\een\n\\begin{answer}\n\\ben\n\\it % <<< transformation\nLet $Y=g(X)$ where $g(x)=x^2$. This is one-to-one and increasing over $\\supp(f_X)=[0,\\infty)$. The inverse transformation is $g^{-1}(y) = \\sqrt{y}$ and $\\supp(f_Y)=[0\\infty)$. Hence\n\\[\nF_Y(y) = F_X\\big[g^{-1}(y)\\big] = 1 - e^{-y/2\\theta} \\quad\\text{for $y\\geq 0$, and zero otherwise.}\n\\]\nThis is the CDF of the $\\text{Exponential}(2\\theta)$ distribution, where $2\\theta$ is a scale parameter.\n\\it % <<< MLE\n\\bit\n\\it $f(x,\\theta) = \\displaystyle\\frac{x}{\\theta}e^{-x^2/2\\theta}$.\n\\it $L(\\theta) = \\prod_{i=1}^n \\displaystyle\\frac{x_i}{\\theta}e^{-x_i^2/2\\theta}$.\n\\it $\\ell(\\theta) = -n\\log\\theta + \\sum_{i=1}^n\\log x_i - \\displaystyle\\frac{1}{2\\theta}\\sum_{i=1}^n x_i^2$.\n\\it $\\ell'(\\theta) = -\\displaystyle\\frac{n}{\\theta} + \\frac{1}{2\\theta^2}\\sum_{i=1}^n x_i^2$.\n\\it $\\ell''(\\theta) = \\displaystyle\\frac{n}{\\theta^2} - \\frac{1}{\\theta^3}\\sum_{i=1}^n x_i^2$.\n\\eit\nSetting $\\ell'(\\theta)=0$, the MLE of $\\theta$ is $\\displaystyle T=\\frac{1}{2n}\\sum_{i=1}^n X_i^2$.\n\\it % <<< bias\nBecause $X^2\\sim\\text{Exponential}(2\\theta)$ we have $\\expe(X^2)=2\\theta$, so\n\\[\n\\expe(T) = \\frac{1}{2n}\\sum_{i=1}^n \\expe(X_i^2) = \\theta.\n\\]\nso $T$ is unbiased.\n\n\\it % <<< efficiency\nAgain using the fact that $\\expe(X^2) = 2\\theta$,\n\\begin{align*}\nI_n(\\theta) = -\\expe\\big[\\ell''(\\theta;\\mathbf{X})\\big] \n\t& = -\\frac{n}{\\theta^2} + \\frac{1}{\\theta^3}\\sum_{i=1}^n \\expe(X_i^2)\n\t= -\\frac{n}{\\theta^2} + \\frac{n}{\\theta^3}2\\theta\t\n\t= \\frac{n}{\\theta^2}.\n\\end{align*}\nBecause $X^2\\sim\\text{Exponential}(2\\theta)$ we have $\\expe(X^2)=2\\theta$ and $\\var(X^2) = 4\\theta^2$. By indepedence,\n\\[\n\\var(T) = \\frac{1}{4n^2}\\sum_{i=1}^n\\var(X_i) = \\frac{n}{4n^2}4\\theta^2 = \\frac{\\theta^2}{n}\n\\]\nThus $\\var(T)$ achieves the CRLB, so $T$ is an efficient estimator for $\\theta$. \n\\een\n\\end{answer}\n\n%----------------------------------------\n\\question \nLet $X\\sim\\text{Exponential}(\\lambda)$ where $\\lambda>0$ is an unknown rate parameter and let $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$. The PDF of $X$ is\n\\[\nf(x) = \\begin{cases}\n\t\\lambda e^{-\\lambda x}\t& \\text{ for $x>0$,} \\\\\n\t0\t\t\t\t\t\t& \\text{ otherwise.}\n\\end{cases}\n\\]\nLet $S_n=\\sum_{i=1}^n X_i$. This is the sum of $n$ independent $\\text{Exponential}(\\lambda)$ random variables, and has the so-called \\emph{Erlang} distribution with parameters $n\\in\\N$ and $\\lambda>0$, whose PDF is given by\n\\[\nf_S(s) = \\frac{\\lambda^n s^{n-1}e^{-\\lambda s}}{\\Gamma(k)} \\quad\\text{for $s>0$ and zero otherwise,} \n\\]\nwhere $\\Gamma(k)$ is the so-called \\emph{gamma function},\n\\[\n\\Gamma(k) = \\int_{0}^{\\infty} t^{k-1}e^{-t}\\,dt.\n\\]\n$\\Gamma(k)$ is an extension of the factorial function and has the property $\\Gamma(k+1) = k\\Gamma(k)$.\n\n\\ben\n\\it Show that \n$\\expe(S_n^{-1}) = \\displaystyle\\frac{\\lambda}{n-1}$ and \n$\\var(S_n^{-1}) = \\displaystyle\\frac{\\lambda^2}{(n-1)^2(n-2)}$.\n%$\\displaystyle\\expe\\left(\\frac{1}{S_n}\\right) = \\frac{\\lambda}{n-1}$ and \n%%$\\displaystyle\\expe\\left(\\frac{1}{S_n^2}\\right) = \\frac{\\lambda^2}{(n-1)(n-2)}$.\n%$\\displaystyle\\var\\left(\\frac{1}{S_n}\\right) = \\frac{\\lambda^2}{(n-1)^2(n-2)}$.\n\\it Show that the MLE of $\\lambda$ is given by $T_n = \\displaystyle\\frac{n}{\\sum_{i=1}^n X_i}$.\n\\it Show that $T_n$ is an asymptotically unbiased estimator for $\\lambda$ as $n\\to\\infty$.\n\\it Show that $T_n$ is an asymptotically efficient estimator of $\\lambda$, in the sense that its variance converges to the CRLB as $n\\to\\infty$.\n\\een\n\n\\begin{answer}\n\\ben\n\\it % <<< inverse moments\n\\begin{align*}\n\\expe(S_n^{-1}) \n\t& = \\frac{\\lambda^n}{\\Gamma(n)}\\int_0^\\infty s^{n-2}e^{-\\lambda s}\\,ds\n\t= \\frac{\\lambda}{\\Gamma(n)}\\int_0^\\infty u^{n-2}e^{-u}\\,du \n\t= \\frac{\\lambda\\Gamma(n-1)}{\\Gamma(n)} = \\frac{\\lambda}{n-1}. \\\\\n\\expe(S_n^{-2}) \n\t& = \\frac{\\lambda^n}{\\Gamma(n)}\\int_0^\\infty s^{n-3}e^{-\\lambda s}\\,ds \n\t= \\frac{\\lambda^2}{\\Gamma(n)}\\int_0^\\infty u^{n-3}e^{-u}\\,du \n\t= \\frac{\\lambda^2\\Gamma(n-2)}{\\Gamma(n)} = \\frac{\\lambda^2}{(n-1)(n-2)}. \\\\\n\\var(S_n^{-1})\n\t& = \\expe(S_n^{-2}) -\\expe(S_n^{-1})^2 =  \\frac{\\lambda^2}{(n-1)^2(n-2)}.\n\\end{align*}\n\\it % <<< mle\n\\bit\n\\it $L(\\lambda) = \\prod_{i=1}^n \\lambda e^{-\\lambda x_i}$.\n\\it $\\ell(\\lambda) = n\\log\\lambda + (\\theta-1)\\sum_{i=1}^n x_i$.\n\\it $\\ell'(\\lambda) = n/\\theta + \\sum_{i=1}^n x_i$.\n\\it $\\ell''(\\lambda) = -n/\\theta^2 < 0$.\n\\eit\nSetting $\\ell'(\\lambda)=0$ we obtain $T=n/\\sum_{i=1}^n X_i$ as the MLE of $\\lambda$.\n\\it % <<< bias\n$T_n$ is an asymptotically unbiased estimator for $\\lambda$ because\n\\[\n\\expe(T_n) \n\t= n\\expe\\left(\\frac{1}{S_n}\\right) \n\t= \\left(\\frac{n}{n-1}\\right)\\lambda.\n\t= \\left(\\frac{1}{1-1/n}\\right)\\lambda\n\t\\to \\lambda \\text{ as $n\\to\\infty$.}\n\\]\n\\it % <<< efficiency\nThe Fisher information of the sample is\n\\[\nI_n(\\lambda) = -\\expe\\big[\\ell''(\\lambda)\\big] = \\frac{n}{\\lambda^2}\n\\]\nso the CRLB is $\\lambda^2/n$. Now,\n\\[\n\\var(T_n) \n\t= n^2\\var\\left(\\frac{1}{S_n}\\right) \n\t= \\frac{\\lambda^2}{n}\\left(\\frac{n^3}{(n-1)^2(n-2)}\\right)\n\t= \\frac{\\lambda^2}{n}\\left(\\frac{1}{(1-1/n)^2(1-2/n)}\\right)\n\t\\to \\frac{\\lambda^2}{n} \\text{ as $n\\to\\infty$.}\n\\]\nThus $\\var(T_n)$ converges to the CRLB as $n\\to\\infty$.\n\\een\n\\end{answer}\n\n%----------------------------------------\n\\end{questions}\n\\end{exercise}\n%----------------------------------------------------------------------\n\n%======================================================================\n\\endinput\n%======================================================================\n", "meta": {"hexsha": "62d6328f3085669c86188589dc9d2e9638db0e9a", "size": 20978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/08D_efficiency.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/08D_efficiency.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/08D_efficiency.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.6559546314, "max_line_length": 261, "alphanum_fraction": 0.6047764325, "num_tokens": 8070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.6701881916308522}}
{"text": "% Chapter II: Groups, first encounter\n\\chapter{Groups, first encounter}\n\n\\section{Definition of group}\n\\begin{xca}\nLet $(G, \\bullet)$ be a group with $e$ denoting the identity element of $G$. We\nconstruct a category $\\mc{C}$ as follows:\n\\begin{itemize}\n    \\item $\\opn{Obj}(\\mc{C}) := \\{ \\ast \\}$.\n    \\item $\\Hom_{\\mc{C}}(\\ast, \\ast) := G$.\n    \\item $1_{\\ast} = e$.\n\\end{itemize}\nThen, it is easy to check $\\mc{C}$ is indeed a category. Also, since every\nelement $g \\in G$ has an inverse, every morphism $\\ast \\to \\ast$ has an inverse.\nThat is, every morphism $\\ast \\to \\ast$ is an isomorphism. Thus, $\\mc{C}$ is a\ngroupoid. Hence, we conclude every group is the group of isomorphisms of a\ngroupoid (with a single object.)\n\nIn particular, we note every group is the group of automorphisms of some object\nin some category.\n\\end{xca}\n\n\\begin{xca}\n$(\\Z, +), (\\Q, +), (\\R, +)$, and $(\\C, +)$ are all groups with (additive)\nidentity $0$.\n\n$(\\Q^*, \\cdot), (\\R^*, \\cdot)$, and $(\\C^*, \\cdot)$ are all groups, with\n(multiplicative) identity $1$.\n\\end{xca}\n\n\\begin{xca}\nFor all elements $g, h$ of a group $G$, we note $(gh)(h^{-1} g^{-1}) =\ng(h h^{-1})g^{-1} = g 1_G g^{-1} = g g^{-1} = 1_G$, and $(h^{-1} g^{-1})(gh) =\nh^{-1}(g^{-1}g)h = h^{-1} 1_G h = h^{-1} h = 1_G$. Therefore, we conclude\n$(gh)^{-1} = h^{-1} g^{-1}$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $g^2 = e$ for all elements $g$ of a group $G$. Then, $g^{-1} = g^{-1} e\n= g^{-1}(g^2) = (g^{-1} g) g = e g = g$. That is, every element $g$ of $G$ is\nits own inverse. Therefore, for all $g, h \\in G$, $gh = g^{-1} h^{-1} =\n(hg)^{-1} = hg$, thereby implying $G$ is commutative.\n\\end{xca}\n\n\\begin{xca}\nSuppose the row corresponding to an element $g$ in the multiplication table of\na group contains the same element in two different columns that correspond to\n(distinct) elements, $h_1$ and $h_2$, say. Then, $g h_1 = g h_2$, which, by\ncancellation on the left, implies $h_1 = h_2$, a contradiction. \\\\\nThe argument is similar for any column of the multiplication table of the group.\n\nHence, we conclude every row and column of the multiplication table of a group\ncontains all elements of the group exactly once. \\\\\n\nThe above statements can also be recast in the following form: \\\\\nLet $g$ be an element of a group $G$. Then, the mappings given by \\[ h \\mapsto\ngh \\] and \\[ h \\mapsto hg, \\] for all elements $h \\in G$, are bijective.\n\\end{xca}\n\n\\begin{xca}\n($G$ has one element) This element must be the identity $1_G$. And, thus,\nthere can be only one multiplication table for $G$: $1_G 1_G = 1_G$.\n\n($G$ has two elements) Let these elements be $1_G$ and $a$. Now, if $a a = a$,\nthen by the cancellation property, $a = 1_G$, a contradiction. Thus, we must\nhave $a a = 1_G$. Therefore, there is only one multiplication table for $G$:\n$1_G 1_G = 1_G, a a = 1_G$.\n\n($G$ has three elements) Let these distinct elements be $1_G, a, b$. Now, $a b\n\\neq a$, for otherwise, by cancellation, $b = 1_G$, a contradiction. Similarly,\n$ab \\neq b$. Thus, we must have $a b = 1_G$. That is, $a$ and $b$ are inverses\nof each other. Also, $a a \\neq 1$, for otherwise, $a = a^{-1}$, which implies\n$a = b$, a contradiction. Again, $a a \\neq a$, for otherwise, by cancellation,\n$a = 1_G$, a contradiction. Thus, $a a = b$. Similarly, $b b = a$. And, this\nexhausts all the possible cases for the multiplication table of $G$. Hence,\nthere is only one multiplication table for $G$: $a b = 1_G, a a = b, b b = a$.\n\nThe above thus shows there is only \\emph{one} possible multiplication table for\n$G$ if $G$ has exactly 1, 2, or 3 elements.\n\n($G$ has four elements) Let these distinct elements be $1_G, a, b, c$. There\nare two possible choices for $ab$: $ab = 1_G$, or $ab = c$. Other choices for\n$ab$, \\emph{viz.} $a$, or $b$, lead to contradictions. The two choices are:\n\\begin{itemize}\n    \\item ($ab = 1_G$) Now, $ac \\neq c$, for otherwise, we get $a = 1_G$, a\n    contradiction. So, we must have $ac = b$, and thus, $aa = c$. Once we fill\n    in the (partially-completed) multiplication table with the above data, we\n    can fill in the rest of the multiplication table as follows. We can't have\n    $ba = b$, so we must have $ba = 1_G$, and hence, $ca = b$. Then, $bb = c$,\n    and $cb = a$, which forces $bc = a$, and $cc = 1_G$.\n\n    The completed multiplication table in this case is as follows:\n    \\[\n    \\begin{array}{c || c | c | c | c |}\n          & 1 & a & b & c \\\\\n        \\hline \\hline\n        1 & 1 & a & b & c \\\\\n        \\hline\n        a & a & c & 1 & b \\\\\n        \\hline\n        b & b & 1 & c & a \\\\\n        \\hline\n        c & c & b & a & 1 \\\\\n        \\hline\n    \\end{array}\n    \\]\n    A little bit of calculation shows $a^2 = c$, $a^3 = a^2 a = ca = b$, and\n    $a^4 = cc = 1_G$. Therefore, the above multiplication table can be entirely\n    rewritten in terms of $1_G$ and $a$ as follows:\n    \\[\n    \\begin{array}{c || c | c | c | c |}\n            & 1   & a   & a^2 & a^3 \\\\\n        \\hline \\hline\n        1   & 1   & a   & a^2 & a^3 \\\\\n        \\hline\n        a   & a   & a^2 & a^3 & 1 \\\\\n        \\hline\n        a^2 & a^2 & a^3 & 1   & a \\\\\n        \\hline\n        a^3 & a^3 & 1   & a   & a^2 \\\\\n        \\hline\n    \\end{array}\n    \\]\n    The above table is precisely the one for the \\emph{cyclic group} $C_4$ of\n    order $4$.\n\n    \\item ($ab = c$) The elements of the group are $1, a, b$, and $ab$. There\n    are two possible choices for $a^2$: $1$, or $b$. If $a^2 = b$, then we\n    have $b = a^2, ab = a^3$, which reduces to the previous case above. So, we\n    are left with the only case to consider: $a^2 = 1$. Then, this forces\n    $a(ab) = b$. Now, if $b^2 = a$, then this again reduces to the previous\n    case above (up to isomorphism.) So, we are left with only one case to\n    consider: $b^2 = 1$. Therefore, $b(ab) = a$. Filling up the rest of the\n    multiplication table, we finally obtain $(ab)a = b, (ab)b = a$, and $(ab)^2\n    = 1$.\n\n    So, the completed multiplication table looks as follows:\n    \\[\n    \\begin{array}{c || c | c | c | c |}\n           & 1  & a  & b  & ab \\\\\n        \\hline \\hline\n        1  & 1  & a  & b  & ab \\\\\n        \\hline\n        a  & a  & 1  & ab & b \\\\\n        \\hline\n        b  & b  & ab & 1  & a \\\\\n        \\hline\n        ab & ab & b  & a  & 1 \\\\\n        \\hline\n    \\end{array}\n    \\]\n\\end{itemize}\nHence, we conclude there are \\emph{two} distinct tables, up to reordering the\nelements of $G$, if $G$ has exactly four elements.\n\nUsing the tables above, it is also easy to verify all groups with $\\le 4$\nelements are commutative.\n\\end{xca}\n\n\\begin{xca}\n(Prove Corollary 1.11) Let $g$ be an element of finite order, and let $N \\in\n\\Z$. We claim\n\\[ g^N = e \\iff N \\text{ is a multiple of } |g|. \\]\n\nNote, if $N = 0$, then the statement\n\\[ g^0 = e \\iff 0 \\text{ is a multiple of } |g| \\]\nholds, since both sides of the double implication are trivially true. Hence,\nthe statement holds for $N = 0$.\n\nWe now need prove our claim only for all $N \\ne 0$.\n\n($\\implies$) Suppose $g^N = e$, where $N \\ne 0$. If $N > 0$, then by Lemma 1.10,\n$N$ is a multiple of $|g|$. And, if $N < 0$, then $g^{-N} = g^{-N} e = g^{-N}\ng^N = g^{-N + N} = g^0 = e$, and since $-N > 0$, again, by Lemma 1.10, $-N$ is\na multiple of $|g|$. Hence, for all $N \\ne 0$, $N$ is a multiple of $|g|$.\n\n($\\impliedby$) Suppose $N$ is a multiple of $|g|$, where $N \\ne 0$. Then, $N =\nn |g|$, for some $0 \\ne n \\in \\Z$. Therefore, $g^N = g^{n|g|} = (g^{|g|})^n =\ne^n = e$.\n\nHence, our original claim is proved.\n\\end{xca}\n\n\\begin{xca}\nSuppose $G$ is a finite abelian group with exactly one element $f$ of order $2$.\nThat is, $f^2 = 1_G$. Then, $f^{-1} = f$, which means $f$ is its own inverse.\nTherefore, every element, other than $f$, of $G$, necessarily has an inverse\nthat is not $f$. And, since the elements of the group commute, every\n(non-identity) term in $\\prod_{g \\in G} g$ can be placed next to its inverse,\nand all these pairs reduce to $1_G$, except $f$. Hence, $\\prod_{g \\in G} g =\nf$.\n\\end{xca}\n\n\\begin{xca}\nLet $G$ be a finite group, of order $n$, and let $m$ be the number of elements\n$g \\in G$ of order exactly $2$. We claim $n-m$ is odd.\n\nFirst, note the identity element is the only element in a group with order $1$.\nAlso, it is easy to check, for all non-identity elements $g \\in G$,\n\\[ |g| = 2 \\iff g = g^{-1}. \\] That is, elements with order $2$ are precisely\nthe elements that are their own inverses (not counting the identity element.)\nThis implies elements $g$ with order $> 2$ have inverses that are distinct from\nthemselves. Thus, these elements come in pairs, which all have distinct\ncomponents. So,\n\\begin{align*}\n    |G| &= \\sum_{|g| \\in \\Z^+} \\text{ \\# of elements with order } |g| \\\\\n        &= \\sum_{|g| = 1} \\bullet + \\sum_{|g| = 2} \\bullet + \\sum_{|g| > 2}\n        \\bullet \\\\\n        &= 1 + m + 2k,\n\\end{align*}\nfor some $k \\in \\N$. Therefore, $n - m = 2k + 1$, showing $n-m$ is indeed odd.\n\nIn addition, if $n$ is even, then using the previous equation, it is easy to\nsee $m = n - 2k + 1$ is odd, and hence $G$ necessarily contains elements of\norder 2.\n\\end{xca}\n\n\\begin{xca}\nSuppose the order of $g$ is odd. Then $|g| = 2n + 1$, for some $n \\in \\N$.\nUsing Proposition 1.13, we have\n\\begin{align*}\n    |g^2| &= \\frac{\\lcm(2, |g|)}{2} \\\\\n          &= \\frac{\\lcm(2, 2n + 1)}{2} \\\\\n          &= \\frac{2(2n + 1)}{2} \\\\\n          &= 2n + 1\n\\end{align*}\nWe thus conclude $|g^2| = |g|$.\n\\end{xca}\n\n\\begin{xca}\nWe claim for all $g, h$ in a group $G$, $|gh| = |hg|$.\n\nTo that end, we first prove the following ancillary claim:\n\\[ |aga^{-1}| = |g| \\text{ for all } a, g \\in G. \\]\n\nIndeed, suppose $a, g$ are elements of a group $G$, and let $|g| = n$, where\n$n \\in \\Z^+$. Then, $(aga^{-1})^n = \\underbrace{(aga^{-1}) \\cdots\n(aga^{-1})}_{n \\text{ times}} = a g^n a^{-1} = a 1_G a^{-1} = aa^{-1} = 1_G$.\n\nSo, $m = |aga^{-1}|$ divides $n$. Now, suppose $m < n$. Then, $(aga^{-1})^m =\n1_G = (aga^{-1})^n$, which implies $a g^m a^{-1} = a g^n a^{-1}$, which by\ncancellation, $g^m = g^n$, which implies $g^{n-m} = 1_G$, which (since\n$n-m < n$) contradicts the assumption $|g| = n$. Therefore, $|aga^{-1}| = n =\n|g|$, which proves our ancillary claim.\n\nNow, using the previous result, we immediately conclude, for all $g, h$ in a\ngroup $G$, $|gh| = |gh1_G| = |gh(gg^{-1})| = |g(hg)g^{-1}| = |hg|$, and we are\ndone.\n\\end{xca}\n\n\\begin{xca}\nIn the group of invertible $2 \\times 2$ matrices, consider\n\\begin{center}\n    $g =\n    \\left( \\begin{array}{cc}\n        0 & -1 \\\\\n        1 & 0 \\end{array} \\right)$,\n    $h =\n    \\left( \\begin{array}{cc}\n        0  & 1 \\\\\n        -1 & -1 \\end{array} \\right)$.\n\\end{center}\nWe verify below $|g| = 4, |h| = 3$, and $|gh| = \\infty$.\n\nIt is easy to verify\n\\begin{center}\n    $g^2 = \\left( \\begin{array}{cc}\n               -1 & 0 \\\\\n                0 & -1 \\end{array} \\right)$,\n    $g^3 = \\left( \\begin{array}{cc}\n        0 & 1 \\\\\n        -1 & 0 \\end{array} \\right)$, and\n    $g^4 = \\left( \\begin{array}{cc}\n        1 & 0 \\\\\n        0 & 1 \\end{array} \\right)$.\n\\end{center}\nTherefore, $|g| = 4$.\n\nAgain, it is easy to verify\n\\begin{center}\n    $h^2 = \\left( \\begin{array}{cc}\n               -1 & -1 \\\\\n                1 & 0 \\end{array} \\right)$, and\n    $h^3 = \\left( \\begin{array}{cc}\n               1 & 0 \\\\\n               0 & 1 \\end{array} \\right)$.\n\\end{center}\nTherefore, $|h| = 3$. \\\\\n\nNow, note\n\\[\ngh = \\left( \\begin{array}{cc}\n          1 & 1 \\\\\n          0 & 1 \\end{array} \\right).\n\\]\nUsing induction on $n$, it is easy to show\n\\[\n(gh)^n = \\left( \\begin{array}{cc}\n             1 & n \\\\\n             0 & 1 \\end{array} \\right),\n\\]\nfor all $n \\in \\Z^+$. Therefore, $(gh)^n \\neq I_n$ for any positive integer\n$n$, where $I_n$ is the $n \\times n$ (identity) diagonal matrix. Hence, $|gh| =\n\\infty$.\n\\end{xca}\n\n\\begin{xca}\nConsider the cyclic group $C_4$ of order $4$, generated by $a$. Choose elements\n$g = a$ and $h = a^3$. Then, it is easy to verify $|g| = 4$ and $|h| = 4$.\nTherefore, $\\lcm(|g|, |h|) = \\lcm(4, 4) = 4$. And, $|gh| = |aa^3| = |a^4| =\n|e| = 1$. Also, $g$ and $h$ commute. Thus, we have an example wherein $g, h$\ncommute but $|gh| = 1 \\ne 4 = \\lcm(|g|, |h|)$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $g$ and $h$ commute \\emph{and} $\\gcd(|g|, |h|) = 1$. We claim $|gh| =\n|g||h|$.\n\nTo that end, let $m = |g|$ and $n = |h|$, so that $\\gcd(m, n) = 1$. By\nProposition 1.14, $|gh|$ divides $\\lcm(|g|, |h|) = \\lcm(m, n) = mn/\\gcd(m, n) =\nmn/1 = mn$. Let $N = |gh|$. So, $N \\mid mn$.\n\nNow, $(gh)^N = 1$\n\\begin{align*}\n    &\\implies g^N = (h^{-1})^N \\\\\n    &\\implies |g^N| = |(h^{-1})^N| \\\\\n    &\\implies |g^N| = |h^N| \\\\\n    &\\implies \\frac{|g|}{\\gcd(N, |g|)} = \\frac{|h|}{\\gcd(N, |h|)} \\\\\n    &\\implies \\frac{m}{\\gcd(N, m)} = \\frac{n}{\\gcd(N, n)} \\\\\n    &\\implies m \\cdot \\gcd(N, n) = n \\cdot \\gcd(N, m)\n\\end{align*}\nSince $\\gcd(m, n) = 1$, it follows $m \\mid \\gcd(N, m)$ and $n \\mid \\gcd(N, n)$.\nAnd, since $\\gcd(N, m) \\mid N$ and $ \\gcd(N, n) \\mid N$, it follows $m \\mid N$\nand $n \\mid N$, whence $mn \\mid N$. But, $N \\mid mn$, and so, $N = mn$. Thus,\n$|gh| = N = mn = |g||h|$, and this proves our claim.\n\\end{xca}\n\n\\begin{xca}\n%TODO: Chapter II - Exercise 1.15\n\\end{xca}\n\n\\section{Examples of groups}\n\\begin{xca}\nOne can associate an $n \\times n$ matrix $M_{\\sigma}$ with a permutation\n$\\sigma \\in S_n$ by letting the entry at $(i, (i)\\sigma)$ be $1$ and letting\nall other entries be 0. For example, the matrix corresponding to the\npermutation\n\\[\n\\sigma =\n    \\begin{pmatrix}\n        1 & 2 & 3 \\\\\n        3 & 1 & 2\n    \\end{pmatrix}\n        \\in S_3\n\\]\nwould be\n\\[\nM_{\\sigma} =\n    \\begin{pmatrix}\n        0 & 0 & 1 \\\\\n        1 & 0 & 0 \\\\\n        0 & 1 & 0\n    \\end{pmatrix}.\n\\]\nWe show that, with this notation, \\[ M_{\\sigma \\tau} = M_{\\sigma} M_{\\tau} \\]\nfor all $\\sigma, \\tau \\in S_n$, where the product on the right is the ordinary\nproduct of matrices.\n\nFirst, note $\\sigma \\tau \\in S_n$, and so, $M_{\\sigma \\tau}$ is an $n \\times n$\nmatrix where the entry at $(i, (i)\\sigma \\tau)$ is $1$ and all other entries is\n$0$. And, $M_{\\sigma} M_{\\tau}$ is an $n \\times n$ matrix whose entry at\n$(i, j)$ equals \\[ \\sum_{r=1}^{n} (M_{\\sigma})_{i,r} (M_{\\tau})_{r,j}, \\] which\nequals $1$ (otherwise, $0$) iff $(M_{\\sigma})_{i,r} = 1 = (M_{\\tau})_{r,j}$ for\nsome $1 \\le r \\le n$ iff $(i)\\sigma = r$ and $(r)\\tau = j$ for some $1 \\le r \\le\nn$ iff $((i)\\sigma) \\tau = j$ iff $(i)(\\sigma \\tau) = j$ iff the entry at\n$(i, (i)\\sigma \\tau)$ of $M_{\\sigma \\tau}$ equals $1$ and all other entries is\n$0$. We thus conclude $M_{\\sigma \\tau} = M_{\\sigma} M_{\\tau}$, and we are done.\n\\end{xca}\n\n\\begin{xca}\nSuppose $d \\le n$. Then, consider the permutation $\\sigma \\in S_n$ given by\n\\[ 1 \\to 2 \\to 3 \\to \\ldots \\to d \\to 1 \\] and all positive integers $> d$\nbeing mapped to themselves. Then, clearly, $|\\sigma| = d$. This shows $S_n$\ncontains elements of order $d$.\n\\end{xca}\n\n\\begin{xca}\nFor every positive integer $n$, an element $\\sigma \\in S_{\\N}$ of order $n$ is\ngiven by the mapping \\[ 1 \\to 2 \\to 3 \\to \\ldots \\to n \\to 1 \\] such that\n$n+i$ is mapped to itself, for all positive integers $i \\ge 1$.\n\\end{xca}\n\n\\begin{xca}\n%TODO - Chapter II: Ex 2.4\n\\end{xca}\n\n\\begin{xca}\n%TODO - Chapter II: Ex 2.5\n\\end{xca}\n\n\\begin{xca}\n%TODO - Chapter II: Ex 2.6\n\\end{xca}\n\n\\begin{xca}\n%TODO - Chapter II: Ex 2.7\n\\end{xca}\n\n\\begin{xca}\n%TODO - Chapter II: Ex 2.8\n\\end{xca}\n\n\\begin{xca}\nWe verify `congruence mod $n$' is an equivalence relation. Indeed, let $n$ be a\npositive integer.\n\n(Reflexivity) For all $a \\in \\Z$, $n \\mid (a - a)$, and so, $a \\equiv a \\mod n$.\n\n(Symmetry) For all $a, b \\in \\Z$, if $a \\equiv b \\mod n$, then $n \\mid (b - a)$,\nwhich implies $n \\mid (a - b)$, and thus, $b \\equiv a \\mod n$.\n\n(Transitivity) For all $a, b, c \\in \\Z$, if $a \\equiv b \\mod n$ and $b \\equiv c\n\\mod n$, then $n \\mid (b - a)$ and $n \\mid (c - b)$, and since $c - a = (c - b)\n+ (b - a)$, $n \\mid (c - a)$, and so, $a \\equiv c \\mod n$.\n\nAnd, we are done.\n\\end{xca}\n\n\\begin{xca}\nWe claim $\\Z/{n\\Z}$ consists precisely of $n$ elements, for all positive\nintegers $n$.\n\nIndeed, suppose $n$ is a positive integer. First, note the $n$ equivalence\nclasses \\[ [0]_n, [1]_n, \\ldots, [n-1]_n \\] are all distinct, for if $[i]_n =\n[j]_n$ for some $0 \\le i < j < n$, then $n \\mid (j-i)$, a contradiction, since\n$0 < j-i < n$.\n\nNext, note for any $a \\in \\Z$, by the Euclidean algorithm, $a = qn + r$, for\nsome $q, r \\in \\Z$, where $0 \\le r < n$. That is, $n \\mid (a-r)$, and so,\n$a \\equiv r \\mod n$, and thus, $[a]_n = [r]_n$. That is to say, the equivalence\nclass of any integer equals one of the $n$ equivalence classes stated above.\n\nHence, we conclude $\\Z/{n\\Z}$ consists precisely of $n$ elements.\n\\end{xca}\n\n\\begin{xca}\nWe show the square of every odd integer is congruent to $1$ modulo $8$.\n\nIndeed, consider $\\Z/{8\\Z}$. Suppose $a \\in \\Z$ is an odd integer. Then, $[a]_8$\nequals $[1]_8, [3]_8, [5]_8$, or $[7]_8$. But, $[1]_8^2 = [3]_8^2 = [5]_8^2 =\n[7]_8^2 = [1]_8$, which implies $[a]_8^2 = [1]_8$, and hence, $a^2 \\equiv 1 \\mod\n8$, and we are done.\n\\end{xca}\n\n\\begin{xca}\nWe show there are no \\emph{nonzero} integers $a, b, c$ such that $a^2 + b^2 =\n3c^2$.\n\nTo that end, we study the solutions to the equation $[a]_4^2 + [b]_4^2 =\n3[c]_4^2$ in $\\Z/{4\\Z}$. First, note $[0]_4^2 = [0]_4, [1]_4^2 = [1]_4, [2]_4^2\n= [0]_4$, and $[3]_4^2 = [1]_4$. This implies $3[c]_4^2$ equals $[0]_4$ or\n$[3]_4$. Thus, any solutions to the equation above exist only when $[a]_4^2 +\n[b]_4^2 = [0]_4 = 3[c]_4^2$, and this is possible precisely when $a, b, c$ are\nall even.\n\nNow, assume, for the sake of contradiction, triples $(a, b, c)$ (where $a, b,\nc$ are all nonzero) exist that are solutions to the original equation $a^2 +\nb^2 = 3c^2$. Then, from the foregoing argument, $a, b, c$ must all be even. Let\nus restrict our attention, for the moment, only to positive integer solutions\n$c$. Using the well-ordering principle, there must exist a smallest $c$, such\nthat with the corresponding $a$ and $b$, the triple $(a, b, c)$ is a solution\nto the original equation. Now, let $a = 2k, b = 2l$, and $c = 2m$, for some\nintegers $k, l, m$. Therefore, $(2k)^2 + (2l)^2 = 3(2m)^2$, which implies\n$k^2 + l^2 = 3m^2$, which is of the same form as the original equation. But,\nthis implies there exists some triple $(k, l, m)$ that is a solution to the\noriginal equation, where $m = c/2 < c$, thus contradicting the assumption that\n$c$ is the smallest positive integer such that $(a, b, c)$ (for some $a, b$) is\na solution to the original equation.\n\nWe obtain a similar result if we assume $c$ is a negative integer. Hence, we\nconclude there do not exist nonzero integers $a, b, c$, such that $a^2 + b^2 =\n3c^2$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $\\gcd(m, n) = 1$. Then, by Corollary 2.5, the class $[m]_n$ generates\n$\\Z/{n\\Z}$. Therefore, there exists some $a \\in \\Z$ such that $a[m]_n = [1]_n$,\nwhich implies $[am]_n = [1]_n$, and thus, $am \\equiv 1 \\mod n$, which implies\n$n \\mid am - 1$. Therefore, there exists some integer $k$ such that $am - 1 =\nkn$, and thus, $am + (-k)n = 1$. We thus conclude there exist integers $a$ and\n$b = -k$ such that $am + bn = 1$.\n\nConversely, suppose $am + bn = 1$ for some integers $a$ and $b$. Then, since\n$\\gcd(m, n)$ divides both $m$ and $n$, $\\gcd(m, n) \\mid am + bn = 1$. This\nforces $\\gcd(m, n) = 1$, and we are done.\n\\end{xca}\n\n\\begin{xca}\n(Analog of Lemma 2.2) If $a \\equiv a' \\mod n$ and $b \\equiv b' \\mod n$, then\n\\[ ab \\equiv a'b' \\mod n. \\]\n\n(Proof) Suppose $a \\equiv a' \\mod n$ and $b \\equiv b' \\mod n$. Then, $n \\mid\na' - a$ and $n \\mid b' - b$, and since $a'b' - ab = a'(b' - b) + b(a' - a)$,\n$n \\mid a'b - ab$, which implies $ab \\equiv a'b' \\mod n$. And, this completes\nour proof.\n\nThe above statement shows if $[a]_n = [a']_n$ and $[b]_n = [b']_n$, then\n$[ab]_n = [a'b']_n$, thus showing the multiplication on $\\Z/{n\\Z}$ is a\nwell-defined operation.\n\\end{xca}\n\n\\begin{xca}\nLet $n > 0$ be an odd integer.\n\\begin{itemize}\n\\item We show if $\\gcd(m, n) = 1$, then $\\gcd(2m + n, 2n) = 1$. We prove the\ncontrapositive of our claim. Indeed, suppose $\\gcd(2m + n, 2n) = d \\ne 1$. Then,\n$d \\mid 2m + n$ and $d \\mid 2n$. Now, since $n$ is an odd integer, $2m + n$ is\nodd and $2n$ is even. Therefore, $d$ must be an odd integer, and since $d$ and\n$2$ are relatively prime, $d \\mid n$. In addition, $d \\mid 2m$, which implies\n$d \\mid m$, and since $\\gcd(m, n) \\ge d$, $\\gcd(m, n) \\ne 1$, and we are done.\n\n\\item Suppose $\\gcd(r, 2n) = 1$. Then, $r$ must be an odd integer, and hence,\n$(r - n)$ is an even integer. Furthermore, there exist integers $a, b$ such that\n$ar + b(2n) = 1$, which implies \\[ 2a\\left(\\frac{r - n}{2}\\right) + (a + 2b)n =\n1. \\] Therefore, $\\gcd(\\frac{r - n}{2}, n) = 1$, and we are done.\n\n\\item We now show the function given by \\[ [m]_n \\mapsto [2m + n]_{2n} \\] is a\nbijection between $(\\Z/{n\\Z})^*$ and $(\\Z/{2n\\Z})^*$.\n\nIndeed, note that since $\\gcd(m, n) = 1$ implies $\\gcd(2m + n, 2n) = 1$, the\nabove mapping does define a function between $(\\Z/{n\\Z})^*$ and $(\\Z/{2n\\Z})^*$.\n\n(Injective) Suppose for any $[m_1]_n, [m_2]_n \\in (\\Z/{n\\Z})^*$, $[2m_1 + n] =\n[2m_2 + n]$. Then, $2m_1 + n \\equiv 2m_2 + n \\mod 2n$, which implies $2n \\mid\n(2m_2 + n) - (2m_1 + n)$, and thus, $2n \\mid 2(m_2 - m_1)$, and so, $n \\mid\n(m_2 - m_1)$, from which we conclude $m_1 \\equiv m_2 \\mod n$, and hence,\n$[m_1]_n = [m_2]_n$, thereby proving the aforesaid mapping is injective.\n\n(Surjective) Let $[2m + n]_{2n} \\in (\\Z/{2n\\Z})^*$, where $m \\in \\Z$. Then,\n$\\gcd(2m + n, 2n) = 1$, which, by one of the previous results, implies\n$\\gcd(\\frac{2m + n - n}{2}, n) = 1$, and thus, $\\gcd(m, n) = 1$. Therefore,\n$[m]_n \\in (\\Z/{n\\Z})^*$. Hence, $[m]_n$ in $(\\Z/{n\\Z})^*$ maps to\n$[2m + n]_{2n}$ in $(\\Z/{2n\\Z})^*$. Thus, the aforesaid function is surjective.\n\nThus, from the foregoing arguments, it follows the defined function between\n$(\\Z/{n\\Z})^*$ and $(\\Z/{2n\\Z})^*$ is a bijection.\n\n~\\\\\nThe number $\\phi(n)$ of elements of $(\\Z/{n\\Z})^*$ is \\emph{Euler's}\n$\\phi$-\\emph{function}. We have just proved if $n$ is odd, then $\\phi(2n) =\n\\phi(n)$.\n\\end{itemize}\n\\end{xca}\n\n\\begin{xca}\nWe show the last digit of $1238237^{18238456}$ is $1$. Working in $\\Z/{10\\Z}$,\nwe first note $[1238237]_{10} = [1238230 + 7]_{10} = [1238230]_{10} + [7]_{10}\n= [0]_{10} + [7]_{10} = [0 + 7]_{10} = [7]_{10}$. Therefore, $[1238237]_{10}^4\n= [7]_{10}^4 = [7^2]_{10}^2 = [49]_{10}^2 = [-1]_{10}^2 = [1]_{10}$. Thus,\n$[1238237]_{10}^{4 \\cdot 4559614} = [1]_{10}^{4559614}$. That is,\n$[1238237]_{10}^{18238456} = [1]_{10}$. Hence, $1238237^{18238456} \\equiv 1\n\\mod 10$, whence the last digit of $1238237^{18238456}$ is $1$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $m \\equiv m' \\mod n$. Then, $[m]_n = [m']_n$\n\\begin{align*}\n&\\implies m \\cdot [1]_n = m' \\cdot [1]_n \\\\\n&\\implies |m \\cdot [1]_n| = |m' \\cdot [1]_n| \\\\\n&\\implies \\frac{|[1]_n|}{\\gcd(m, |[1]_n|)} = \\frac{|[1]_n|}{\\gcd(m', |[1]_n|)}\n\\q (\\text{by Proposition 1.13}) \\\\\n&\\implies \\frac{n}{\\gcd(m, n)} = \\frac{n}{\\gcd(m', n)} \\\\\n&\\implies \\gcd(m, n) = \\gcd(m', n).\n\\end{align*}\nHence, $\\gcd(m, n) = 1$ iff $\\gcd(m', n) = 1$.\n\\end{xca}\n\n\\begin{xca}\n% TODO - Chapter II: Ex 2.18\n\\end{xca}\n\n\\begin{xca}\n$(\\Z/{5\\Z})^* = \\{ [1]_5, [2]_5, [3]_5, [4]_5 \\}$ and its multiplication table\nis given below:\n\\[\n\\begin{array}{c || c  c  c  c |}\n          & [1]_5 & [2]_5 & [3]_5 & [4]_5 \\\\\n    \\hline \\hline\n    [1]_5 & [1]_5 & [2]_5 & [3]_5 & [4]_5 \\\\\n    \\hline\n    [2]_5 & [2]_5 & [4]_5 & [1]_5 & [3]_5 \\\\\n    \\hline\n    [3]_5 & [3]_5 & [1]_5 & [4]_5 & [2]_5 \\\\\n    \\hline\n    [4]_5 & [4]_5 & [3]_5 & [2]_5 & [1]_5 \\\\\n    \\hline\n\\end{array}\n\\]\n~\\\\\n$(\\Z/{12\\Z})^* = \\{ [1]_{12}, [5]_{12}, [7]_{12}, [11]_{12} \\}$, and its \nmultiplication table is given below:\n\\[\n\\begin{array}{c || c  c  c  c |}\n              & [1]_{12}  & [5]_{12}  & [7]_{12}  & [11]_{12} \\\\\n    \\hline \\hline\n    [1]_{12}  & [1]_{12}  & [5]_{12}  & [7]_{12}  & [11]_{12} \\\\\n    \\hline\n    [5]_{12}  & [5]_{12}  & [1]_{12}  & [11]_{12} & [7]_{12} \\\\\n    \\hline\n    [7]_{12}  & [7]_{12}  & [11]_{12} & [1]_{12}  & [5]_{12} \\\\\n    \\hline\n    [11]_{12} & [11]_{12} & [7]_{12}  & [5]_{12}  & [1]_{12} \\\\\n    \\hline\n\\end{array}\n\\]\n\nIt is easy to see all the elements of $(\\Z/{12\\Z})^*$ have order $2$, whereas\nat least one element ($[2]_5, [3]_5$, to be precise) in $(\\Z/{5\\Z})^*$) have\norder greater than $2$. So, no reordering of elements in $(\\Z/{12\\Z})^*$ will\nmake them match the elements in $(\\Z/{5\\Z})^*$.\n\\end{xca}\n", "meta": {"hexsha": "30f1df4189bbbae3871372c4318853ba929a83ac", "size": 24278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/groups-first-encounter.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": "chapters/groups-first-encounter.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": "chapters/groups-first-encounter.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": 39.0321543408, "max_line_length": 80, "alphanum_fraction": 0.5745942829, "num_tokens": 9547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.670178156505921}}
{"text": "\\subsection{Topological continuity}\\label{subsec:topological_continuity}\n\n\\begin{definition}\\label{def:local_continuity}\n  We say that the function \\( f: X \\to Y \\) between topological spaces is \\term{continuous} at the point \\( x_0 \\in X \\) if \\( f(x_0) \\) is a limit \\hyperref[def:local_convergence]{point} of \\( f \\) at \\( x_0 \\).\n\n  If limit point is unique (e.g. in \\hyperref[def:separation_axioms/T2]{Hausdorff spaces}), this condition can be formulated by \\enquote{interchanging} \\( \\lim \\) and \\( f \\) as follows:\n  \\begin{equation*}\n    f(x_0) = f\\left( \\lim_{x \\to x_0} x \\right) = \\lim_{x \\to x_0} f(x).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:global_continuity}\n  We say that the function \\( f: X \\to Y \\) between topological spaces is \\term{everywhere continuous} or simply \\term{continuous} if and of the following conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:global_continuity/limits} \\( f \\) is continuous at every point of \\( X \\) in the sense of \\fullref{def:local_continuity}.\n    \\thmitem{def:global_continuity/open} For every open set \\( V \\in T \\), the \\hyperref[thm:def:function/preimage]{preimage} \\( f^{-1}(V) \\) is open.\n    \\thmitem{def:global_continuity/closed} For every closed set \\( F \\in F_{\\mscrT_Y} \\), the preimage \\( f^{-1}(F) \\) is closed.\n    \\thmitem{def:global_continuity/base} There exists a \\hyperref[def:topological_base]{base} \\( \\mscrB_{\\mscrT_Y} \\subseteq T_Y \\), such that for every \\( V \\in B_{\\mscrT_Y} \\), the preimage \\( f^{-1}(V) \\) is open.\n    \\thmitem{def:global_continuity/subbase} There exists a \\hyperref[def:topological_subbase]{subbase} \\( P_{\\mscrT_Y} \\subseteq T_Y \\), such that for every \\( V \\in P_{\\mscrT_Y} \\), the preimage \\( f^{-1}(V) \\) is open.\n    \\thmitem{def:global_continuity/closure} For every set \\( A \\subseteq X \\), \\( f(\\cl(A)) \\subseteq \\cl(f(A)) \\).\n  \\end{thmenum}\n\n  We denote the set of all continuous functions from \\( X \\) to \\( Y \\) by \\( C(X, Y) \\).\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:global_continuity/limits}{def:global_continuity/open} Follows from \\fullref{def:local_convergence/neighborhoods}.\n  \\ImplicationSubProof{def:global_continuity/open}{def:global_continuity/closed} If \\( F \\in F_{\\mscrT_Y} \\) is a closed set, \\( Y \\setminus F \\) is open, therefore \\( f^{-1}(Y \\setminus F) = X \\setminus f^{-1}(F) \\) is also open. Hence, \\( f^{-1}(F) \\) is closed.\n  \\ImplicationSubProof{def:global_continuity/open}{def:global_continuity/base} \\( \\mscrT \\) is a base of itself.\n  \\ImplicationSubProof{def:global_continuity/base}{def:global_continuity/subbase} Every base is also a subbase.\n  \\ImplicationSubProof{def:global_continuity/subbase}{def:global_continuity/limits} Follows from the equivalences in \\fullref{def:local_convergence}.\n  \\ImplicationSubProof{def:global_continuity/closed}{def:global_continuity/closure} Note that\n  \\begin{equation*}\n    A\n    \\reloset {\\ref{thm:function_image_preimage_composition/preimage_of_image}} \\subseteq\n    f^{-1}(f(A))\n    \\reloset {\\ref{thm:def:function_preimage/monotonicity}} \\subseteq\n    f^{-1}(\\cl(f(A))).\n  \\end{equation*}\n\n  Apply \\( f \\circ \\cl \\) to the above chain of inclusions to obtain\n  \\begin{equation*}\n    f(\\cl(A))\n    \\subseteq\n    f(\\underbrace{\\cl}_{\\ref{def:global_continuity/closed}}(f^{-1}(\\cl(f(A)))))\n    \\reloset {\\ref{thm:function_image_preimage_composition/image_of_preimage}} \\subseteq\n    \\cl(f(A)),\n  \\end{equation*}\n  which proves the implication.\n\n  \\ImplicationSubProof{def:global_continuity/closure}{def:global_continuity/closed} Fix a closed set \\( F \\subseteq Y \\). Then\n  \\begin{equation}\\label{def:global_continuity/closure_implies_closed_right}\n    f(\\cl(f^{-1}(F)))\n    \\reloset {\\ref{def:global_continuity/closure}} \\subseteq\n    \\cl(f(f^{-1}(F)))\n    \\reloset {\\ref{thm:function_image_preimage_composition/image_of_preimage}} \\subseteq\n    \\cl(F)\n    =\n    F.\n  \\end{equation}\n\n  Since \\( \\cl \\) is monotone, we have\n  \\begin{equation}\\label{def:global_continuity/closure_implies_closed_left}\n    f(\\cl(f^{-1}(F)))\n    \\supseteq\n    f(f^{-1}(F))\n    \\reloset {\\ref{thm:function_image_preimage_composition/preimage_of_image}} \\supseteq\n    F.\n  \\end{equation}\n\n  From \\eqref{def:global_continuity/closure_implies_closed_right} and \\eqref{def:global_continuity/closure_implies_closed_left} it follows that\n  \\begin{equation*}\n    F = f(\\cl(f^{-1}(F))).\n  \\end{equation*}\n\n  By taking the preimage, we obtain\n  \\begin{equation*}\n    f^{-1}(F)\n    =\n    f^{-1}(f(\\cl(f^{-1}(F))))\n    \\reloset {\\ref{thm:function_image_preimage_composition/image_of_preimage}} \\supseteq\n    \\cl(f^{-1}(F)).\n  \\end{equation*}\n\n  Therefore, \\( f^{-1}(F) \\) is closed.\n\\end{proof}\n\n\\begin{definition}\\label{def:homeomorphism}\n  We say that the continuous function \\( f: X \\to Y \\) is \\term{open} (resp. \\term{closed}), if the image \\( f(U) \\) of an open (resp. closed) in \\( \\mscrT_X \\) set is open (resp. closed) in \\( \\mscrT_Y \\).\n\n  If \\( f \\) is an open bijection, we say that \\( f \\) is a \\term{homeomorphism}. If \\( f \\) is only an open injection, we say that \\( f \\) is a \\term{homeomorphic embedding}.\n\\end{definition}\n\n\\begin{definition}\\label{def:parametric_curve}\n  Let \\( I \\) be an interval (of any type) in \\( \\BbbR \\) with endpoints \\( a < b \\), not necessarily finite. Depending on the use case, we define a \\term{parametric curve} on \\( I \\) by any of the non-equivalent definitions\n\n  \\begin{thmenum}\n    \\thmitem{def:parametric_curve/function} A continuous function \\( \\gamma: I \\to X \\) is called a parametric curve.\n\n    \\thmitem{def:parametric_curve/image} The image \\( \\img(\\gamma) \\) of a parametric curve \\( \\gamma \\) is also called a parametric curve.\n\n    \\thmitem{def:parametric_curve/equivalence_class} The equivalence class of all continuous functions from \\( I \\) to \\( X \\) with\n    \\begin{equation*}\n      \\gamma \\cong \\beta \\iff \\img(\\gamma) = \\img(\\beta) \\text{ and the endpoints of } \\gamma \\text{ and } \\beta \\text{ coincide}\n    \\end{equation*}\n    is also called a parametric curve.\n  \\end{thmenum}\n\n  The points \\( \\gamma(a) \\) and \\( \\gamma(b) \\) are called the \\term{endpoints} of the curve, \\( \\gamma(a) \\) is the \\term{start} and \\( \\gamma(b) \\) is the \\term{end}. We say that \\( \\gamma \\) \\term{connects} \\( a \\) and \\( b \\).\n\n  Parametric curves on \\( I = [0, 1] \\) are also called \\term{paths}.\n\n  We define some fundamental types of curves:\n  \\begin{thmenum}\n    \\thmitem{def:parametric_curve/closed} The curve \\( \\gamma \\) is called \\term{closed} if its endpoints coincide, i.e. \\( \\gamma(a) = \\gamma(b) \\).\n\n    \\thmitem{def:parametric_curve/simple} The curve \\( \\gamma \\) is called \\term{simple} if the function \\( \\gamma: I \\to Y \\) is injective with the possible exception of the endpoints (in which case we speak of \\term{simple closed curves}.\n  \\end{thmenum}\n\n  If \\( \\gamma: I \\to X \\) is a parametric curve, related curves are:\n  \\begin{thmenum}\n    \\thmitem{def:parametric_curve/function_graph}\\mcite[def. 1.20]{ИвановТужилин2017}The \\hyperref[def:multi_valued_function/graph]{graph} \\( \\gph(\\gamma) \\) of \\( \\gamma \\) is a the image of the curve \\( \\overline{\\gamma}(t, x) \\coloneqq (t, \\gamma(x)) \\) in the topological space \\( I \\times X \\).\n\n    \\thmitem{def:parametric_curve/implicit}\\mcite[def. 1.24]{ИвановТужилин2017}If \\( M \\) is a subset of \\( X \\) and if there exists a curve \\( \\gamma: I \\to X \\) such that \\( \\imag(\\gamma) = M \\), we call \\( M \\) an \\term{implicit parametric curve}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:parametric_hypersurface}\n  In analogy to \\fullref{def:parametric_curve} (and with the caveats of \\fullref{def:parametric_curve}), we define \\term{parametric hypersurfaces} as follows:\n\n  Let \\( \\xi \\) is a potentially infinite cardinal number, let \\( \\card \\mscrK = \\xi \\) and let \\( \\{ I_\\alpha \\}_{\\alpha \\in \\mscrK} \\) be a family of intervals in \\( \\BbbR \\). We define a parametric hypersurface to be a continuous image from the \\hyperref[def:topological_product]{product space} \\( \\prod_{\\alpha \\in \\mscrK} I_\\alpha \\) to \\( Y \\).\n\n  We call \\( \\xi \\) the \\term{dimension} of the hypersurface.\n\\end{definition}\n\n\\begin{definition}\\label{def:fundamental_groupoid}\n  \\todo{Define fundamental groupoids}.\n\\end{definition}\n", "meta": {"hexsha": "af02f311fae10c799baabcd88e28939b3abcb913", "size": 8252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/topological_continuity.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_continuity.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_continuity.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.7971014493, "max_line_length": 350, "alphanum_fraction": 0.688075618, "num_tokens": 2649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6701781514785009}}
{"text": "\\chapter{Drawing the Planets and Orbits}\n\\section{Planets}\nDrawing the planets is generally very simple: at first we create a sphere using the {\\em sphere} function which gives us the coordinates {\\em x}, {\\em y} and {\\em z} of each corner of the sphere while taking the  resolution as the argument. The resolution defines how smooth the surface of the sphere is. For example: a resolution of 50 generates a spheres composed of 50 equally wide rings with 50 equally big surfaces. Following images shows how the spheres react to different resolutions:\n\n\\begin{center}\n\\includegraphics[width=0.45\\textwidth]{imgs/drawing_planets_orbits/spheres_res4.jpg}\n\\includegraphics[width=0.45\\textwidth]{imgs/drawing_planets_orbits/spheres_res5.jpg}\\\\\n\\textit{Left: a sphere with resolution 4 (top and side view); Right: a sphere with resolution 5 (top and side view)}\n\\end{center}\n\nWe then manipulate the position values to scale and move the sphere as needed. We do this by multiplying the position matrices with a factor and then adding a constant to move it to the correct position.\\\\\n\nNext we load the textures from an image using various \\matlab{} functions: first we read the image of a map of the planet using {\\em imread}. Then we convert the data to doubles using {\\em im2double}. Next we use {\\em imresize} to adjust the image the size of the planet. We then only have to flip the data upside down to correctly display the texture. This is done using the {\\em flipud} function. Further details for these function can be found in the help pages of each function.\\\\\n\nLast but no least we create a surface object, or the 'planet', using the {\\em surf} function by passing the position matrices and the textures. We can then use this object to move and rotated the planet.\n\nFollowing {\\em MatLab} code draws a simple sphere with a texture as described above:\n\\begin{framed}\\begin{verbatim}\n[x,y,z] = sphere(resolution);\nx = x*scale(1) + pos(1); y = y*scale(2) + pos(2); z = z*scale(3) + pos(3);\n\ntexture = flipud(imresize(im2double(imread(imgFile)),size(x)));\nplanet = surf(x, y, z, texture,'EdgeColor', 'none');\n\\end{verbatim}\\end{framed}\n{\\em pos} and {\\em scale} are vectors containing the coordinates of the center of the planet and factors for stretching the planet in {\\em x}, {\\em y} and {\\em z} directions. {\\em imgFile} is a string containing the path to the textures of the planet and {\\em resolution} is an integer for the resolution of the sphere as described above.\n\n\\subsection{Rings}\nSome planets, in our case only saturn, have rings of water ice and rocky material circling them. To respect the thickness of such rings and for simplicity we created them using a torus and squished it to make it thiner. A torus is described as follows:\n\n\\begin{align*}\nx(\\theta, \\varphi) = (R + r*\\cos(\\theta) * \\cos(\\varphi)\\\\\ny(\\theta, \\varphi) = (R + r*\\cos(\\theta) * \\sin(\\varphi)\\\\\nx(\\theta, \\varphi) = r*\\sin(\\varphi)\n\\end{align*}\n\n$\\theta$, $\\varphi$ are angles which make a full circle, so that their values start and end at the same point,\\\\\nR is the distance from the center of the tube to the center of the torus,\\\\\nr is the radius of the tube.\n\nIn \\matlab{} this looks some what like this:\n\\begin{framed}\\begin{verbatim}\nphi = linspace(0,2*pi,resolution)';\nalpha = linspace(0,2*pi,resolution*10)';\n\ntmp = [R + r*cos(phi), r*sin(phi)];\nx = cos(alpha)*tmp(:,1)';\ny = sin(alpha)*tmp(:,1)';\nz = tmp(:,2)';\nz = z(ones(1,length(alpha)),:);\n\\end{verbatim}\\end{framed}\nThe rest for drawing the ring is the same as for drawing the planets: we move and scale the ring using vectors containing the position of the center and factors for each direction and then create a surface object with the textures of the ring. Only the textures are slightly different compared to the planets. While the planets use a map, the ring has to be only a portion of the ring mirrored along the inner {\\em 'edge'} of the ring.\n\n\n\\section{Orbits}\nWe decided to use circular orbits for our modle, instead of simulating them and calculating the trajectory. Thus drawing the trajectory of each planet was made a lot easier.  The function {\\em getPlanetOrbit} draws a simple circle in a 3 dimensional room. The function has the following attributes:\n\\begin{itemize}\n  \\item Center: stands for the middle of the circle\n  \\item Normal: stands for direction that the circle is tilted\n  \\item Radius: radius of the circle\n  \\item Color: color of the circle \\ldots\n\\end{itemize}\n\n\n\\begin{framed}\\begin{verbatim}\ntheta = 0:0.01:(2*pi+0.01);\nv = null(normal);\npoints = repmat(center',1,size(theta,2))+radius*(v(:,1)*cos(theta)+v(:,2)*sin(theta));\norbit = plot3(points(1,:),points(2,:),points(3,:),'Color',color);\n\\end{verbatim}\\end{framed}\n\n% ================================\n\\pagebreak\n\\section{Key Values for the Modle}\nAs said before, we tryed to use realistic values and scales for the modle. Listed in the following two chapters are the values we ended up using. We gathered the data from: \\hyperref[space-facts.com]{http://space-facts.com/}\n\n\\subsection{Distances}\n\\begin{center}\n    \\begin{tabular}{| l | l | l | l |}\n    \\hline\n    Planet & Distance [km] & Distance [AU] & Scale Factor \\\\ \\hline\n    Mercury & 57'909'227 & 0.39 & 0.39 \\\\ \\hline\n    Venus & 108'209'475 & 0.73 & 0.73 \\\\ \\hline\n    Earth & 149'598'262 & 1 & 1 \\\\ \\hline\n    Moon & 384'400 & 0.0025 & 0.0025 \\\\ \\hline\n    Mars & 227'943'824 & 1.38 & 1.38 \\\\ \\hline\n    Jupiter & 778'340'821 & 5.20 & 5.20 \\\\ \\hline\n    Saturn & 1'426'666'422 & 9.58 & 9.58 \\\\ \\hline\n    Uranus & 2'870'658'186 & 19.22 & 19.22 \\\\ \\hline\n    Neptune & 4'498'396'441 & 30.10 & 30.10 \\\\\n    \\hline\n    \\end{tabular}\\\\\n    \\textit{The distances are all the average distance from the sun.\\\\\n    Except for the moon, whose distance is the average distance from earth.}\n\\end{center}\n\n\n\\subsection{Sizes}\n\\begin{center}\n    \\begin{tabular}{| l | l | l |}\n    \\hline\n    Planet & Diameter [km] & Scale Factor \\\\ \\hline\n    Sun & 1'392'684 & 109.18 \\\\ \\hline\n    Mercury & 4'879 & 0.38 \\\\ \\hline\n    Venus & 12'104 & 0.95 \\\\ \\hline\n    Earth & 12'756 & 1 \\\\ \\hline\n    Moon & 3'475 & 0.27 \\\\ \\hline\n    Mars & 6'805 & 0.53 \\\\ \\hline\n    Jupiter & 142'984 & 11.21 \\\\ \\hline\n    Saturn & 120'536 & 9.45 \\\\ \\hline\n    Uranus & 51'118 & 4.01 \\\\ \\hline\n    Neptune & 49'528 & 3.88 \\\\\n    \\hline\n    \\end{tabular}\\\\\n    \\textit{The diameters used are the equatorial diameters of the planets.\\\\\n    The scale factor used is log10 of the value in this table.}\n\\end{center}\n\n\n\\subsection{Speed}\n\\begin{center}\n    \\begin{tabular}{| l | l | l |}\n    \\hline\n    Planet & Earth days / year & Scale Factor \\\\ \\hline\n    Mercury & 87.97 & 4.1521 \\\\ \\hline\n    Venus & 224.7 & 1.6255 \\\\ \\hline\n    Earth & 365.26 & 1 \\\\ \\hline\n    Moon & 27.3 & 13.3795 \\\\ \\hline\n    Mars & 686.98 & 0.5317 \\\\ \\hline\n    Jupiter & 4332.82 & 0.0843 \\\\ \\hline\n    Saturn & 10755.7 & 0.034 \\\\ \\hline\n    Uranus & 30687.15 & 0.0119 \\\\ \\hline\n    Neptune & 60190.03 & 0.0061 \\\\\n    \\hline\n    \\end{tabular}\\\\\n    \\textit{The scale factor is used for the orbit speed.\\\\\n    Therefor less days mean faster orbit speed.}\n\\end{center}\n", "meta": {"hexsha": "ffec7fe2124af0a131e5c16639efba8e29a32dc9", "size": 7101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/inputfiles/Drawing_Planets_Orbits.tex", "max_stars_repo_name": "polarcode/SolarSystemSimulation", "max_stars_repo_head_hexsha": "0a4f78a5deadcd8dba0da63ae8370aa19a8857b9", "max_stars_repo_licenses": ["MIT"], "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/inputfiles/Drawing_Planets_Orbits.tex", "max_issues_repo_name": "polarcode/SolarSystemSimulation", "max_issues_repo_head_hexsha": "0a4f78a5deadcd8dba0da63ae8370aa19a8857b9", "max_issues_repo_licenses": ["MIT"], "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/inputfiles/Drawing_Planets_Orbits.tex", "max_forks_repo_name": "polarcode/SolarSystemSimulation", "max_forks_repo_head_hexsha": "0a4f78a5deadcd8dba0da63ae8370aa19a8857b9", "max_forks_repo_licenses": ["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.4565217391, "max_line_length": 491, "alphanum_fraction": 0.6918743839, "num_tokens": 2127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6701781458721372}}
{"text": "\\section{Relaxed and Regularized Transport}\n\nIn the previous section, we introduced the Monge-Kantorovich formulation for the computation of the OT between two distributions, as the minimization of the energy~\\eqref{eqMK}. In this section, we modify this energy in order to obtain a regular OT mapping, which is important for applications such as color transfer. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Relaxed Transport}\n\\label{subsec-relaxed-transport}\n\nSection~\\ref{sec-appli-color} tackles the color transfer problem, where, as in many applications in imaging, strict mass conservation should be avoided.  As a consequence, it is not desirable to impose a one-to-one mapping between the points in $X$ and $Y$. \n\nThe relaxation we propose allows each point of $X$ to be transported to multiple points of $Y$ and vice versa. This corresponds to imposing the constraints \n\\eq{\n\tk_X \\U \\leq \\Sig \\U \\leq K_X \\U\n\t\\qandq \n\tk_Y \\U \\leq \\Sigma^* \\U \\leq K_Y \\U\n} \non the matrix $\\Sig$, where \n$\\kappa=(k_X,K_X,k_Y,K_Y) \\in (\\RR^+)^4$\nare the parameters of the method. \n% Note that these restrictions on $\\Sig$ do not rule out the option of decreasing the overall mass. \nTo impose the total amount of mass $M$ transported between the densities, we further impose the constraint $\\U^* \\Sig\\U=M$, where $M>0$ is a parameter.\nThe initial OT problem~\\eqref{eqMK} now becomes:\n\\eql{\\label{eq-relax-map}\n\t\\umin{\\Sigma \\in \\Matr_\\kappa} \\dotp{C_{X,Y}}{\\Sig}\n}  \n\\eq{\n\t\\qwhereq\n\t\\Matr_\\kappa = \\enscond{\\Sig \\in [0,1]^{N \\times N}}{ \n\t\t\\begin{array}{ll}\n\t\t\tk_X \\U \\leq \\Sigma \\U \\leq K_X \\U, \\\\\n\t\t\tk_Y \\U \\leq \\Sigma^* \\U \\leq K_Y \\U, \n\t\t\\end{array} \\: \n\t\t\\U^* \\Sig\\U=M\n\t\t }.\n}\nTo ensure that $\\Matr_\\kappa$ is non empty, we impose that\n\\eq{ \n \t\\max(k_X,k_Y) \\leq \\frac{M}{N} \\leq \\min(K_X,K_Y)\n}\nFor the application to the color manipulations considered in this paper, we set once and for all this parameter to $M=N$. \n\n%\\todo{Either provide a mathematical statement with a proof, or remove this sentence. }\nNote that if $\\min(K_X,K_Y) \\geq N$, there is no restriction on the number of connections of each element of $X$ or $Y$, then the optimal solution increases (always under the constraints $\\U^*\\Sig\\U=M$) the weight given to the connection between the closest points in $X$ to the closest points in $Y$, that is to say, the minima $(C_{X,Y})_{i,j}$ are assigned the maximum possible weight, see Fig.~\\ref{im:relaxationk} for an example.  \n\n%the solution of \\eqref{eq-relax-map} is the nearest neighbor assignment.\n  \nProblem~\\eqref{eq-relax-map} is  a convex linear program, which can be solved using standard linear programming algorithms. \n\n\\paragraph{Relaxed OT map} Optimal matrices $\\Sig$ minimizing~\\eqref{eq-relax-map} are in general non binary and furthermore their non zero entries do not define one-to-one maps between the points of $X$ and $Y$. It is however possible to define a map $T$ from $X$ to $Y$ by mapping each point $X_i$ to a weighted barycenter of its neighbors in $Y$ as defined by $\\Sig$. This corresponds to defining\n\\eq{\\label{eqT}\nT(X_i) = \\frac{\\sum_{j=1}^N \\Sig_{i,j} Y_j }{\\sum_{j=1}^N \\Sig_{i,j}}\\\\\n} which in vectorial form can be expressed as $T(X_i)= Z_i $, where $Z=(\\diag(\\Sig \\U))^{-1} \\Sig Y$, and where the operator $\\diag(v)$ creates a diagonal matrix in $\\RR^{N \\times N}$ with the vector $v \\in \\RR^N$ on the diagonal.\nTo insure that the map is well defined, we impose that $k_X > 0$.  Note that it is possible to define a map from $Y$ to $X$ by replacing $\\Sig$ by $\\Sig^*$ in the previous formula and exchanging the roles of $X$ and $Y$.\n \nThe following proposition shows that an optimal $\\Sig$ is binary when the parameters $\\kappa$ are integers. Such a binary $\\Sig$ can be interpreted as a set of pairwise assignments between the points in $X$ and $Y$. Note that this is not true in general when the parameters $\\kappa$ are not integers.\n\n\\begin{prop}\\label{prop}\n\tFor $(k_X,K_X,k_Y,K_Y,M) \\in (\\NN^*)^5$, there exists a solution  $\\tilde{\\Sig}$ of~\\eqref{eq-relax-map} which is binary, i.e. $\\tilde \\Sigma \\in \\{0,1\\}^{N \\times N}$.\n\t\\if 0\n\t\twhich is solution of\n\t\\eql{\\label{eq-relaxed-transport}\n\t\t\\umin{\\Sig \\in \\Bb_{\\kappa}} \\dotp{C_{X,Y}}{\\Sig},\n\t}\n\t\\eq{\n\t\t\\qwhereq\n\t\t\\Bb_{\\kappa}= \\enscond{\\Sig \\in \\{0,1\\}^{N \\times N}}{\n\t\t\\begin{array}{ll}\n\t\t\tk_X \\U \\leq \\Sigma \\U \\leq K_X \\U, \\\\\n\t\t\tk_Y \\U \\leq \\Sigma^* \\U \\leq K_Y \\U, \n\t\t\\end{array} \\: \n\t\t\\U^* \\Sig\\U=M\n\t\t}\n\t}\n\tthat is to say, $\\tilde{\\Sig}$ is a binary matrix.\n\t\\fi\n\\end{prop}\n\\begin{proof}\n\tOne can write \n\t$\\Matr_\\kappa = \\enscond{ \\Sig \\in \\RR^{N \\times N} }{ \\Aa(\\Sig) \\leq b_\\kappa }$\n\twhere $\\Aa$ is the linear mapping\n\t$\\Aa(\\Sig)=(-\\Sig,\\Sig \\U,-\\Sig \\U,\\Sig^* \\U,-\\Sig^* \\U,\\U\\Sig\\U,-\\U\\Sig\\U)$, where $\\Sig^* \\U, \\Sig\\U \\in \\RR^{N}$ and $\\U\\Sig\\U \\in \\RR$, \tand $b_\\kappa = (0_{N,N}, K_X\\U, -k_X\\U, K_Y\\U, -k_Y\\U, M, -M)$. A standard result shows that $\\Aa$ is a totally unimodular matrix~\\cite{schrijver-book}. For any $(k_X,K_X,k_Y,K_Y,M) \\in (\\NN^*)^5$, the vector $b_\\kappa$ has integer coefficients, and thus the polytope $\\Matr_\\kappa$ has integer vertices. Since there is always a solution of the linear program~\\eqref{eq-relax-map} which is a vertex of $\\Matr_\\kappa$, it has coefficients in $\\{0,1\\}$.\n\\end{proof}\n \n \n\\begin{figure}\n\\centering\n\\begin{tabular}{@{}|@{}c@{}|@{}c@{}|@{}c@{}|}\n\\hline\n\\includegraphics[width=.33\\linewidth]{cluster_matching_l0kx1KX1ky1KY1_nn4.eps} & \n\\includegraphics[width=.33\\linewidth]{cluster_matching_l0kx1KX1ky0KY2_nn4.eps} &\n\\includegraphics[width=.33\\linewidth]{cluster_matching_l0kx1KX1ky01KY10_nn4.eps} \\\\ \n$\\kappa=(1,1,1,1)$ & $\\kappa=(1,1,0,2)$ & $\\kappa=(1,1,0.1,10)$ \\\\\\hline \n\\includegraphics[width=.33\\linewidth]{cluster_matching_l0kx1KX1ky01KY15_nn4.eps} & \n\\includegraphics[width=.33\\linewidth]{cluster_matching_l0kx0KX2ky1KY1_nn4.eps} &\n\\includegraphics[width=.33\\linewidth]{cluster_matching_l0kx01KX10ky01KY10_nn4.eps}  \\\\\n  $\\kappa=(1,1,0.1,1.5)$ & $\\kappa=(0,2,1,1)$  & $\\kappa=(0.1,10,0.1,10)$ \\\\\\hline \n\\end{tabular}\n\\caption{\\label{im:relaxationk}Relaxed transport computed between $X$ (blue dots) and $Y$ (red dots) for different values of $\\kappa$.\nNote that $\\kappa=(1,1,1,1)$ corresponds to classical OT. The mappings $\\Sigma_{i,j}$ that relate $X_i$ and $Y_j$ are plotted as line segments connecting which are dashed if $\\Sigma_{i,j} \\in ]0.1,1[$  and solid if $\\Sigma_{i,j}=1$.  }\n\\end{figure}\n\n%%%\n\\paragraph{Numerical Illustrations}\n\nIn Fig.~\\ref{im:relaxationk}, we show a simple example to illustrate the properties of the method proposed so far. Given a set of points $X$ (in blue) and $Y$ (in red), we compute the optimal $\\Sig$ solving~\\eqref{eq-relax-map} for different values of $\\kappa$. For each values of $\\kappa$, we draw a line between $X_i$ and $Y_j$ if the value of the associated optimal $\\Sigma_{i,j} > 0.1$, solid if $\\Sigma_{i,j}=1$, and dashed otherwise.\n\nAs we prove in the Proposition~\\ref{prop}, for non integer values of $K_X,K_Y$, the mappings $\\Sigma_{i,j}$ are in $[0,1]$ while for integer values, $\\Sigma_{i,j} \\in \\{0,1\\}$. Note that as we increase the values of $K_X,K_Y$ (Fig.~\\ref{im:relaxationk}, right), the points in $X$ tend to be mapped to the closer points in $Y$.\n\n\n%\\begin{figure}\n%\\begin{tabular}{cccc}\n%\\includegraphics[height=2.5cm]{./images/k1_l0.png} &\n%\\includegraphics[height=2.5cm]{./images/k2_l0.png} &\n%\\includegraphics[height=2.5cm]{./images/k25_l0.png}&\n%\\includegraphics[height=2.5cm]{./images/k10_l0.png} \\\\\n% (a) & (b) & (c) & (d)\n% \\end{tabular}\n%\\caption{Relaxed transport computed between $X$ (blue dots) and $Y$ (red dots) with the parameters \\textbf{(a)} $k=1$ (classical OT) \\textbf{(b)} $k=2$ \\textbf{(c)} $k=2.5$ \\textbf{(d)} $k=10$. The color of the line between $X_i$ and $Y_j$ indicates the value of the mapping $\\Sigma_{i,j}$. }\n%\\label{im:relaxationk}\n%\\end{figure}\n\n\n", "meta": {"hexsha": "ebddaa04ee62b452bfe72b6463ff65349f977565", "size": 7842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/sec-relaxed.tex", "max_stars_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_stars_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-27T03:15:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-19T17:21:04.000Z", "max_issues_repo_path": "paper/sections/sec-relaxed.tex", "max_issues_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_issues_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sections/sec-relaxed.tex", "max_forks_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_forks_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-10-12T17:29:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-04T01:52:32.000Z", "avg_line_length": 63.756097561, "max_line_length": 594, "alphanum_fraction": 0.688854884, "num_tokens": 2661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.8104789040926007, "lm_q1q2_score": 0.6700324827000652}}
{"text": "From Equation~\\ref{eq:theta_ls} we can begin to derive the recursive least\nsquares estimator. It is worth noting at the beginning of this derivation that\nwe have implicitly assumed that our data is already centered; in other words,\nthe relationship between $\\varphi_t$ and $y_t$ has no offset term, and so our\nmodel $\\hat\\Theta_{LS}$ will always predict an output vector of all zeros for\nan input vector of all zeros. This is a fine assumption when all of the data\nhas been collected ahead of time, but breaks down when we want to do recursive\nleast squares because we cannot estimate the means of our inputs and outputs\nahead of time. Since it is easier to derive the recursive least squares\nestimator in the centered case than in the uncentered case, we tackle this\nlimited version first. \n\n\\subsection{Breaking Up the Normal Equation}\nWe begin by writing out the normal equation as two sums multiplied together\n\\begin{align}\n  \\hat\\Theta_{LS}(T) &= (X_T^\\top X_T)^{-1} X_T^\\top Y_T \\\\\n                  &= \\left[\\sum_{t=1}^T \\varphi_t^\\top \\varphi_t\\right]^{-1} \\left[\\sum_{t=1}^T\\varphi_t^\\top y_t \\right] \\label{eq:two_sums}\n\\end{align}\nLet us define the inverse sample covariance matrix $P_T$ to be the left-hand\nterm in Equation~\\ref{eq:two_sums}, so that we then have\n\\begin{align}\n  \\label{eq:sample_covar_split}\n  P_T^{-1} &= \\sum_{t=1}^T \\varphi_t^\\top \\varphi_t \\\\\n           &= P_{T - 1}^{-1} + \\varphi_T^\\top \\varphi_T \\label{eq:p_inv_update}\\\\\n  \\implies P_{T - 1}^{-1} &= P_T^{-1} - \\varphi_T^\\top \\varphi_T \\label{eq:sub_covar}\n\\end{align}\nSimilarly, we can break up the right-hand term in Equation~\\ref{eq:two_sums}:\n\\begin{equation}\n  \\sum_{t=1}^T\\varphi_t^\\top y_t = \\sum_{t=1}^{T-1} \\varphi_t^\\top y_t + \\varphi_T^\\top y_T\n\\end{equation}\n\n\\subsection{Deriving the $\\hat\\Theta$ Update}\nOur normal equation is now\n\\begin{equation}\n  \\hat\\Theta_{LS} = P_T \\cdot \\left[\\sum_{t=1}^{T-1} \\varphi_t^\\top y_t + \\varphi_T^\\top y_T\n\\right]\n\\end{equation}\nUsing the definition of $\\hat\\Theta_{LS}(T - 1)$, we get\n\\begin{equation}\n  \\hat\\Theta_{LS}(T) = P_T \\cdot \\left[P_{T-1}^{-1} \\hat\\Theta_{LS}(T-1) + \\varphi_T^\\top y_T\\right]\n\\end{equation}\nSubstituting in Equation~\\ref{eq:sub_covar}:\n\\begin{align}\n  \\hat\\Theta_{LS}(T) &= P_T \\cdot \\left[(P_{T}^{-1} - \\varphi_T^\\top \\varphi_T) \\hat\\Theta_{LS}(T-1) + \\varphi_T^\\top y_T\\right] \\\\\n                     &= \\hat\\Theta_{LS}(T - 1) - P_T \\varphi_T^\\top \\varphi_T \\hat\\Theta_{LS}(T-1) + P_T \\varphi_T^\\top y_T \\\\\n                     &= \\hat\\Theta_{LS}(T - 1) + P_T \\varphi_T^\\top \\left[y_T - \\varphi_T\\hat\\Theta_{LS}(T-1)\\right] \\label{eq:centered_theta_update}\n\\end{align}\nNote that the last term in Equation~\\ref{eq:centered_theta_update} ($y_T -\n\\varphi_T\\hat\\Theta_{LS}(T-1)$) is the prediction error of our model at\ntimestep $T-1$ on the new datum, so the new estimate of $\\Theta$ that we get is\nthe old estimate plus the prediction error on a new datum filtered by $P_T\n\\varphi_T^\\top$. Intuitively, this represents a reweighting of the prediction\nerror using our existing estimate of the sample covariance, which effectively\nrescales the update to $\\Theta$ to take into account the scales of the\ncoordinates of the features.\n\n\\subsection{Deriving the $P_T$ Update}\nThough Equation~\\ref{eq:p_inv_update} gives us a way to update $P_T^{-1}$\neasily with each new datum, to recover $P_T$ and update\n$\\hat\\theta_{LS}$ we would need to invert an $n\\times n$ matrix at on each time\nstep. This is not only computationally expensive for all but small values of\n$n$, it also introduces the risk of running into floating-point errors if\n$P_T^{-1}$ ever becomes ill-conditioned\\footnote{These sorts of issues can also\nbe dealt with using any number of techniques from numerical linear\nalgebra~\\cite{trefethen1997numerical}}.\n\nWe can get around these issues by doing away with $P_T^{-1}$ all together and\nderiving a direct update for $P_T$. We do this with the Woodbury matrix\nidentity~\\cite{woodbury1950inverting}, also known as the ``matrix inversion\nlemma.'' This result tells us that for matrices $A, U, C, V$ such that $UCV$ has rank $k$, the inverse of the rank-$k$ update is given by:\n\\begin{equation}\n  \\label{eq:woodbury}\n  \\left(A + UCV\\right)^{-1} = A^{-1} - A^{-1}U\\left(C^{-1} + VA^{-1}U\\right)^{-1}VA^{-1}\n\\end{equation}\nIn our case, since we are doing a rank-1 update $\\varphi_T^\\top \\varphi_T$ to\n$P_{T-1}^{-1}$, this lemma gives us that\n\\begin{equation}\n  \\label{eq:centered_p_update}\n  P_T = \\left(P_{T-1}^{-1} + \\varphi_T^\\top \\varphi_T\\right)^{-1} = P_{T - 1} - \\frac{P_{T-1}\\varphi_T^\\top \\varphi_T P_{T-1}}{1 + \\varphi_T P_{T-1} \\varphi_T^\\top}\n\\end{equation}\nAnd just like that, we're done! Equations~\\ref{eq:centered_theta_update}\nand~\\ref{eq:centered_p_update} give us the update equations that define the\nrecursive least squares algorithm. At each timestep $t$, we simply need to:\n\\begin{enumerate}\n\\begin{singlespace}\n  \\item Record $\\varphi_t$ and $y_t$ from our datastream $F(t)$. \n  \\item Calculate $P_t$ from $P_{t-1}$ and $\\varphi_t$ using Equation~\\ref{eq:centered_p_update}. \n  \\item Calculate $\\hat\\Theta_{LS}(t)$ from $\\hat\\Theta_{LS}(t-1)$, $\\varphi_t$, $y_t$, and $P_{t}$ using Equation~\\ref{eq:centered_theta_update}. \n\\end{singlespace}\n\\end{enumerate}\n", "meta": {"hexsha": "64b273fbf5049fdc042d593fee30ef780da1cd6a", "size": 5248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/src/centered.tex", "max_stars_repo_name": "cannontwo/rls", "max_stars_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_stars_repo_licenses": ["MIT"], "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/src/centered.tex", "max_issues_repo_name": "cannontwo/rls", "max_issues_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_issues_repo_licenses": ["MIT"], "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/src/centered.tex", "max_forks_repo_name": "cannontwo/rls", "max_forks_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_forks_repo_licenses": ["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.6703296703, "max_line_length": 164, "alphanum_fraction": 0.7120807927, "num_tokens": 1705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6700324743734385}}
{"text": "%!TEX root = 497Notes-Temple.tex\n\\newpage\n\\section{Initialization for deep neural networks}\nTo build a machine learning algorithm, we need to define an architecture (e.g. Logistic regression, Support Vector Machine, Neural Network) and train it to learn parameters. The training of neural network is actually the iteration of the above architecture. Then, the initial guess of the parameters is important in avoiding gradient vanishing or blowup. \nThe initialization step deals with the initial guess of parameters, and can be critical to the model's ultimate performance. \n\n\n\\subsection{Xavier's Initialization with $\\sigma  = id$}\nThe goal of Xavier initialization~\\cite{glorot2010understanding} is to initialize the deep neural network to avoid gradient vanishing or blowup when the input is white noise. \n\n\nRecall the DNN models in Section \\ref{sec:DNN}\n\\begin{equation}\n\\begin{cases}\nf^1(x) &= W^1 x + b^1 \\\\\nf^{\\ell}(x) &= W^\\ell \\sigma(f^{\\ell-1}(x)) + b^\\ell \\quad \\ell = 2:L \\\\\nf(x) &= f^{L} \\\\\n\\end{cases},\n\\end{equation}\nwith $x \\in \\mathbb{R}^{n_0}$ and $f^{\\ell} \\in \\mathbb{R}^{n_\\ell}$. More precisely, we have\n\\begin{equation}\\label{key}\nW^\\ell \\in \\mathbb{R}^{n_{\\ell} \\times n_{\\ell-1}}.\n\\end{equation}\nWe make the basic assumptions below:\n\\begin{itemize}\n%% \\item The input $x$ is a mean $0$ random variable with identity covariance, i.e. $\\mathbb{E}(x) = 0$, $\\mathbb{E}(x_ix_j) = 0$ if $i\\neq j$, and $\\mathbb{E}(x_i^2) = 1$\n% \\item \\blue{The input $x$ is a mean $0$ random vector with the same variance for each component, i.e. $\\mathbb{E}[[x]_i] = 0$ and $\\mathbb{E}[[x]_i^2] (\\mathbb{V} [[x]_i]) =$ $\\mathbb{E}[[x]_j^2] (\\mathbb{V}[[x]_j])$. }\n% (Here we notice that, after data normalization as discussed before this assumption holds directly.)\n \\item The initial weights $W^\\ell_{ij}$ are i.i.d symmetric random variables with mean $0$, namely the \n probability distribution of $W^\\ell_{ij}$ is even.\n \\item The initial bias $b^\\ell = 0$.\n\\end{itemize}\nThe goal of Xavier's initialization is to ensure that the features $f^\\ell$ and gradients do not blow up or vanish. Note that the mean of $f^\\ell$ is zero, we only need to choose appropriate initial parameters to bound the variance of $f^\\ell$. To this end we have the following lemma.\n\n\\begin{lemma}\\label{lemm:init}\nUnder the previous assumptions $f^\\ell_i$  is a symmetric random variable with $\\mathbb{E}[f^\\ell_i] = 0$.\nMoreover, we have the following identity\n\\begin{equation}\\label{eq:FWini}\n\\mathbb{V}[f^{\\ell}_i] = \\mathbb{E}[(f^{\\ell}_i)^2] = \\sum_{k}\\mathbb{E}[(W^\\ell_{ik})^2]\\mathbb{E}[\\sigma(f^{\\ell-1}_k)^2].\n\\end{equation}\nwhere the subscript $i$ of the notation $f_i^\\ell$ represents the $i$-th component of $f^\\ell$.\n% \\begin{equation}\\label{key}\n%  \\mathbb V [f^{L}_i] =  \\left(\\Pi_{\\ell=1}^{L} n_{\\ell-1} {\\rm Var} [W^\\ell_{st}] \\right)\\mathbb V [x_j].\n% \\end{equation}\n\\end{lemma}\n%Note that here we don't have that $f^\\ell_i$ and $f^\\ell_j$ are actually independent, just that they are `linearly' independent.\n\\begin{proof}\nFor general activation function $\\sigma(x)$, let first prove that\n$f^\\ell_i$  is a symmetric random variable with $\\mathbb{E}[f^\\ell_i] = 0$.\nFor any $\\ell$ and $1\\le i \\le n_\\ell$, we have\n\\begin{equation}\n f^\\ell_i = \\sum_k W^\\ell_{ik}\\sigma(f^{\\ell-1}_k) + b_i^\\ell,\n\\end{equation}\nTaking expectations, noting that $W^\\ell_{ik}$ are independent of $f^{\\ell-1}_k$ and that $b_i^\\ell = 0$, we get\n\\begin{equation}\n \\mathbb{E}[f^\\ell_i] = \\sum_k \\mathbb{E}[W^\\ell_{ik}]\\mathbb{E}[\\sigma(f^{\\ell-1}_k)] = 0.\n\\end{equation}\nsince $\\mathbb{E}[W^\\ell_{ik}] = 0$.\nMoreover, if the $W_{ij}^\\ell$ are symmetric, it is clear that $f^\\ell_i$ will be.\n\n \n% Furthermore, we calculate (note that $b^\\ell = 0$)\n% \\begin{equation}\n% \\begin{split}\n%  \\mathbb{E}(f^\\ell_if^\\ell_j) &= \\mathbb{E}\\left(\\left(\\sum_k W^\\ell_{ik}\\sigma(f^{\\ell-1}_k)\\right)\\left(\\sum_l W^\\ell_{jl}\\sigma(f^{\\ell-1}_l)\\right)\\right) \\\\ &= \\sum_{k,l}\\mathbb{E}(W^\\ell_{ik}W^\\ell_{jl}\\sigma(f^{\\ell-1}_k)\\sigma(f^{\\ell-1}_l))\n%  \\end{split}\n% \\end{equation}\n%\n%Since $W^\\ell_{ik}$ and $W^\\ell_{jl}$ are independent ($i\\neq j$), and are both independent of $f^{\\ell-1}$, each of the terms above is \n%\\begin{equation}\n% \\mathbb{E}(W^\\ell_{ik})\\mathbb{E}(W^\\ell_{jl})\\mathbb{E}(\\sigma(f^{\\ell-1}_k)\\sigma(f^{\\ell-1}_l)) = 0.\n%\\end{equation}\nNext we calculate the variance of $f^{\\ell}_i$, we get\n\\begin{equation}\n\\begin{split}\n \\mathbb{V}[f^{\\ell}_i] = \\mathbb{E}[(f^{\\ell}_i)^2] &= \\mathbb{E}\\left[\\left(\\sum_k W^\\ell_{ik}\\sigma(f^{\\ell-1}_k)\\right)\\left(\\sum_l W^\\ell_{il}\\sigma(f^{\\ell-1}_l)\\right)\\right]\\\\ &= \\sum_{k,l}\\mathbb{E}[W^\\ell_{ik}W^\\ell_{il}\\sigma(f^{\\ell-1}_k)\\sigma(f^{\\ell-1}_l)].\n \\end{split}\n\\end{equation}\nIn the above sum we will have $W^\\ell_{ik}$ and $W^\\ell_{il}$ independent unless $k = l$. In this case the term will be $0$. So the only terms which remain are those for which $k=l$ and we get\n\\begin{equation}\\label{eq:FWini}\n  \\mathbb{E}[(f^{\\ell}_i)^2] = \\sum_{k}\\mathbb{E}[(W^\\ell_{ik})^2]\\mathbb{E}[\\sigma(f^{\\ell-1}_k)^2].\n\\end{equation}\n\n\\end{proof}\n\n\nNow, we assume $\\sigma  = id$. This assumption is pretty reasonably since most activation functions in use at the time (such as the hyperbolic tangent) were close to the identity near $0$. \n\n\\begin{lemma}\\label{th:idnormal}\nIf $\\sigma  = id$, \n \\begin{equation}\\label{key}\n\t\\mathbb V [f^{L}_i] =  \\left(\\Pi_{\\ell=2}^{L} n_{\\ell-1} {\\rm Var} [W^\\ell_{st}] \\right) \\left(\\mathbb{V}[W^1_{st}]\\sum_{j}\\mathbb{E}[( x^j)^2] \\right),\n\t\\end{equation}\nwhere $x^j$ represents the $j$-th component of data $x$.\n\\end{lemma}\n\\begin{proof}\nLet us prove it this by induction. For $\\ell=1$,\n\\begin{equation}\\label{key}\n\\mathbb{V}[f^{1}_i] = \\sum_{j}\\mathbb{E}[(W^1_{ij})^2]\\mathbb{E}[( x^j)^2] = {\\mathbb{E}[(W^1_{ij})^2]  \\left(\\sum_{j}\\mathbb{E}[( x^j)^2] \\right)},\n\\end{equation}\nfor any $i = 1,2,\\cdots, n_1$. Since we already know that\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[f^1_i ] = {\\mathbb{E}[(W^1_{ij})^2]  \\left(\\sum_{j}\\mathbb{E}[( x^j)^2] \\right)} = \\mathbb{V}[f^1_k], \\quad \\forall i,k,\n\t\\end{equation}\n\tfrom derivation in $\\ell=1$. We will see that for $\\ell=2$,\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[f^2_i ] = n_1 \\mathbb{V}[W^2_{ij}]  \\mathbb{V}[ f^1_j] = n_1     \\mathbb{V}[W^2_{st}] \\left(\\mathbb{V}[W^1_{st}]\\sum_{j}\\mathbb{E}[(x^j)^2] \\right).\n\t\\end{equation}\nBy induction, \n\\begin{equation}\\label{key}\n\t\\mathbb V [f^{L}_i] =  \\left(\\Pi_{\\ell=2}^{L} n_{\\ell-1} {\\rm Var} [W^\\ell_{st}] \\right) \\left(\\mathbb{V}[W^1_{st}]\\sum_{j}\\mathbb{E}[( x^j)^2] \\right).\n\t\\end{equation}\n\\end{proof}\n%We will see in the next section that (as first observed by Kaiming He) if $\\sigma$ is the ReLU function, \n%then we don't need to make this assumption since the left hand side in \\eqref{eq:FWini} can be calculated exactly. \n\nAccording to Theorem \\ref{th:idnormal}, one way to make sure the variance $\\mathbb{V}[W^\\ell_{ik}]$ does not blow up is to set \n\\begin{equation}\\label{varianceW}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell-1}}, \\quad \\forall \\ell \\ge 2.\n\\end{equation}\nIn this case,\n\\begin{equation}\n\\mathbb V [f^{L}_i] = \\mathbb V [f^{L-1}_j] = \\cdots =  \\mathbb V [f^{1}_k] = \\mathbb{V}[W^1_{st}]\\sum_{j}\\mathbb{E}[(x^j)^2].\n\\end{equation}\nThus, in pure DNN models, it is enough to just control $\\displaystyle \\sum_{j}\\mathbb{E}[(x^j)^2]$.\nThe choice \\eqref{varianceW} comes from the analysis of $\\mathbb{V}[W^\\ell_{ik}]$. We can also consider the propagation of the gradient $\\frac{\\partial L(\\theta)}{\\partial f^\\ell}$. A similar analysis suggests the choice \n$\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell}}.\n$\nThus, the {\\bf Xavier's initialization} suggests to initialize $W^\\ell_{ik}$ with variance as:\n\\begin{itemize}\n\t\\item To control $\\mathbb V [f^{\\ell}_i] $:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell-1}}.\n\t\\end{equation}\n\t\\item To control $\\mathbb{V}[\\frac{\\partial L(\\theta)}{\\partial f_i^\\ell}]$:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell}}.\n\t\\end{equation}\n\t\\item Trade-off to control $\\mathbb{V} [\\frac{\\partial L(\\theta)}{\\partial W_{ik}^\\ell}]$: \n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell-1} + n_\\ell}.\n\t\\end{equation}\n\\end{itemize}\nHere we note that, this analysis works for all symmetric type distribution around zero. We often just choose uniform distribution $\\mathcal U(-a,a)$ and normal distribution $\\mathcal N(0,s^2)$. Since the expectation of $W^{\\ell}_{ik}$ is zero and the variance is given above, the final version of Xavier's initialization takes the trade-off type as\n\\begin{equation}\nW^{\\ell}_{ik} \\sim \\mathcal{U}(-\\sqrt{\\frac{6}{n_\\ell+n_{\\ell-1}}}, \\sqrt{\\frac{6}{n_\\ell+n_{\\ell-1}}}),\\quad \\text{ or }\\quad\nW^{\\ell}_{ik} \\sim \\mathcal{N}(0,  {\\frac{2}{n_\\ell+n_{\\ell-1}}}).\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\input{6DL/Init_Backward}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%See the separate file in {``6DL/HandWrittenNotes/InitBackward.pdf''}\n%\\includepdf[pages=-,pagecommand={}]{HandWrittenNotes/InitBackward.pdf}\n%\\includepdf[pages=-,pagecommand={}]{497/handwritten_notes/MultidimensionalVariance.pdf}\n\n\n\\subsection{Kaiming's initialization}\nIn~\\cite{he2015delving}, Kaiming He and others extended this analysis to get an \\textit{exact} result when the activation function is the  ReLU.\n\nWe first have the following lemma for symmetric distribution.\n\\begin{lemma}\n\tIf $X_i \\in \\mathbb{R}$ for $i=1:n$ are i.i.d with symmetric probability density function $p(x)$, i.e. $p(x)$ is even.\n\tThen for any nonzero random vector $Y = (Y_1, Y_2, \\cdots, Y_n) \\in \\mathbb{R}^n$ which is independent with $X_i$, \n\tthe following random variable\n\t\\begin{equation}\\label{key}\n\tZ = \\sum_{i=1}^n X_i Y_i,\n\t\\end{equation} \n\tis also symmetric.\n\\end{lemma}\n\n\\begin{proof}\n\tLet us denote the joint distribution function for $Y$ as $q(y_1, \\cdots, y_n)$. Then\n\tthe joint distribution density function for $(X,Y)$ is \n\t\\begin{equation}\\label{key}\n\tf(x_1, \\cdots, x_n,y_1, \\cdots, y_n) = p(x_1)p(x_2)\\cdots p(x_n)q(y_1, y_2, \\cdots, y_n).\n\t\\end{equation}\n\tThen we have the following probability function\n\t\\begin{equation}\\label{key}\n\t\\begin{aligned}\n\t\\mathbb P(Z < z) &= \\int_{\\sum_{i=1}^n {x_i y_i} < z} f(x_1, \\cdots, x_n,y_1, \\cdots, y_n)  dxdy \\\\\n\t&= \\int_{\\sum_{i=1}^n {x_i y_i} < z} p(x_1)p(x_2)\\cdots p(x_n)q(y_1, y_2, \\cdots, y_n)  dxdy \\\\\n\t&= \\int_{\\sum_{i=1}^n {-x_i y_i} > -z} p(x_1)p(x_2)\\cdots p(x_n)q(y_1, y_2, \\cdots, y_n)  dxdy\\\\\n\t&= \\int_{\\sum_{i=1}^n {-x_i y_i} > -z} p(-x_1)p(-x_2)\\cdots p(-x_n)q(y_1, y_2, \\cdots, y_n)  dxdy\\\\\n\t&= \\int_{\\sum_{i=1}^n \\tilde x_i y_i >-z} p(\\tilde x_1)p(\\tilde x_2)\\cdots p(\\tilde x_n)q(y_1, y_2, \\cdots, y_n)  d\\tilde xdy\\\\\n\t&= \\mathbb P(Z >- z).\n\t\\end{aligned}\n\t\\end{equation}\n\\end{proof}\n\nThen state the following result for ReLU function and random variable with \nsymmetric distribution around $0$.\n\\begin{lemma}\nIf $X$ is a random variable on $\\mathbb{R}$ with symmetric probability density $p(x)$ around zero, i.e., \n\\begin{equation}\\label{key}\np(x) = p(-x).\n\\end{equation}\nThen we have $\\mathbb{E} X = 0$ and \n\\begin{equation}\\label{key}\n\\mathbb{E}[[{\\rm ReLU}(X)]^2] = \\frac{1}{2}{\\rm Var}[X].\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tBy definition\n\t\\begin{equation}\\label{key}\n\t\\mathbb{E} X = \\int_{-\\infty}^\\infty xp(x)d(x) = 0. \\quad (\\text{since } p(x) = p(-x)).\n\t\\end{equation}\n\tFurthermore, \n\t\\begin{equation}\\label{key}\n\t\\begin{aligned}\n\t\\mathbb{E}[[{\\rm ReLU}(X)]^2] &= \\int_{-\\infty}^\\infty ({\\rm ReLU}(x))^2 p(x)  dx \\\\\n\t&= \\int_{0}^\\infty x^2 p(x) dx \\\\\n\t&= \\frac{1}{2} \\int_{-\\infty}^\\infty (x - \\mathbb E [x])^{2} p(x) dx \\\\\n\t& = \\frac{1}{2} \\mathbb E[ [X - \\mathbb{E} X]^2] \\\\\n\t& = \\frac{1}{2}\\mathbb{V}[X].\n\t\\end{aligned}\n\t\\end{equation}\n\\end{proof}\n\n\n\nBased on the previous Lemma~\\ref{lemm:init}, we know that $f^{\\ell-1}_k$ is a symmetric distribution around $0$.\nThe most important observation in Kaiming's paper~\\cite{he2015delving} is that:\n\\begin{equation*}\\label{key}\n\\mathbb{V}[ f^\\ell_i ] = n_{\\ell-1}  \\mathbb{V}[W^\\ell_{ij}] {\\mathbb{E}[[\\sigma(f^{\\ell-1}_j)]^2]} = n_{\\ell-1} \\mathbb{V}[W^\\ell_{ik}] {\\frac{1}{2} \\mathbb{V}[f^{\\ell-1}_k]},\n\\end{equation*}\n{if $\\sigma = {\\rm ReLU}$}.\nThus, Kaiming's initialization suggests to take:\n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell-1}}, , \\quad \\forall \\ell \\ge 2.\n\\end{equation}\n\nFor the first layer $\\ell=1$, by definition\n\\begin{equation}\\label{key}\nf^1 = W^1 x + b^1,\n\\end{equation}\nthere is no ReLU, thus it should be $\\mathbb{V}[W^1_{ik}] = \\frac{1}{d}$. \nFor simplicity, they still use $\\mathbb{V}[W^1_{ik}] = \\frac{2}{d}$ in the paper~\\cite{he2015delving}. Similarly, an analysis of the propagation of the gradient suggests that we set \n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell}}.\n\\end{equation}\nHowever, in paper~\\cite{he2015delving} authors did not suggest to take the trade-off version, they just chose \n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell-1}},\n\\end{equation} as default.\nThus, the final version of Kaiming's initialization takes the forward type as\n\\begin{equation}\nW^{\\ell}_{ik} \\sim \\mathcal{U}(-\\sqrt{\\frac{6}{n_{\\ell-1}}}, \\sqrt{\\frac{6}{n_{\\ell-1}}}),\n\\quad\\text{ or }\\quad\nW^{\\ell}_{ik} \\sim \\mathcal{N}(0,  {\\frac{2}{n_{\\ell-1}}}).\n\\end{equation}\n\n%And another difference is that Xavier use the uniform distribution but He use the Gaussian distribution. \n%More precisely, \n%However, in Pytorch implementation, the uniform distribution is also applied.\n\n\n\\section{Data normalization in CNNs}\nFor CNN models, following the analysis above we have the next iterative scheme in CNNs\n\\begin{equation}\\label{key}\nf^{\\ell,\\nu} = K^{\\ell,\\nu} \\ast \\sigma (f^{\\ell,\\nu-1}),\n\\end{equation}\nwhere the previous step $f^{\\ell,\\nu-1} \\in \\mathbb{R}^{c_\\ell\\times n_\\ell \\times m_\\ell }$, the current step $f^{\\ell,\\nu} \\in \\mathbb{R}^{h_\\ell\\times n_\\ell \\times m_\\ell}$ and $K \\in \\mathbb{R}^{(2k+1) \\times (2k+1) \\times h_\\ell \\times c_\\ell}$.\nThus we have\n\\begin{equation}\\label{key}\nf^{\\ell,\\nu}_{h;p,q} = \\sum_{c=1}^{c_\\ell}\\sum_{s,t=-k}^k K^{\\ell,\\nu}_{h,c;s,t} \\ast \\sigma (f^{\\ell,\\nu-1}_{c;p+s,q+t}).\n\\end{equation}\nTake variance on both sides, we will get\n\\begin{equation}\\label{key}\n\\mathbb{V} [f^{\\ell,\\nu}_{h;p,q}] = c_\\ell (2k+1)^2 \\mathbb{V}[K^{\\ell,\\nu}_{h,o;s,t}] \\mathbb{E}[(f^{\\ell,\\nu-1}_{o;p+s,q+t})^2],\n\\end{equation}\nthus we have the following initialization strategies:\n\\begin{description}\n\t\\item[Xavier's initialization] \n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,\\nu}_{h,o;s,t}] = \\frac{2}{ (c_\\ell + h_\\ell) (2k+1)^2}.\n\t\\end{equation}\n\t\\item[Kaiming's initialization]\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,\\nu}_{h,o;s,t}] = \\frac{2}{c_\\ell (2k+1)^2}.\n\t\\end{equation}\n\\end{description}\n\nHere we can take this Kaiming's initialization as:\n\\begin{itemize}\n\t\\item Double the Xavier's choice, and get\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,\\nu}_{h,o;s,t}] = \\frac{4}{(c_\\ell + h_\\ell )(2k+1)^2}.\n\\end{equation}\n\t\\item Then pick $c_\\ell$ or $h_\\ell$ for final result  \n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,\\nu}_{h,o;s,t}] = \\frac{2}{c_\\ell (2k+1)^2}.\n\t\\end{equation}\n\\end{itemize}\n\nAnd they have the both uniform and normal distribution type.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\linewidth]{converge_22layers}\n\t\\end{center}\n\t\\caption{The convergence of a \\textbf{22-layer} large model. The $x$-axis is the number of training epochs. The y-axis is the top-1 error of 3,000 random val samples, evaluated on the center crop. Use ReLU as the activation for both cases. Both Kaiming's initialization (red) and ``\\emph{Xavier's}'' (blue) \\cite{glorot2010understanding} lead to convergence, but Kaiming's initialization starts reducing error earlier.}\n\t\\label{fig:converge_22layers}\n\\end{figure}\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.5\\linewidth]{converge_30layers}\n\t\\end{center}\n\t\\caption{The convergence of a \\textbf{30-layer} small model (see the main text). Use ReLU as the activation for both cases. Kaiming's initialization (red) is able to make it converge. But ``\\emph{Xavier's}'' (blue) \\cite{glorot2010understanding} completely stalls - It is also verified that that its gradients are all diminishing. It does not converge even given more epochs.}\n\t\\label{fig:converge_30layers}\n\\end{figure}\n\nGiven a 22-layer model, in Cifar10 both Kaiming's and Xavier's initialization are able to converge and the validation accuracies with two different initialization \nare about the same(error is 33.82,33.90). But the convergence with Kaiming's initialization is faster than Xavier's.\nWith extremely deep model with up to 30 layers, \nKaiming's initialization is able to make the model convergence. On the contrary, Xavier's method completely stalls the learning.\n\n\n\\endinput\n\n\\iffalse\n\\subsection{Basic assumptions in Xavier's and Kaiming's initialization.}\n\\begin{itemize}\n\t\\item $f^\\ell$ is a random vector and $f^\\ell_i$ for $i = 1:n_\\ell$ are i.i.d.\n\t\\item $W^\\ell$ should be initialized as random vector independently to $f^{\\ell-1}$ and $W^\\ell_{ij}$ \n\tfor all $i = 1:n_{\\ell},j=1:n_{\\ell-1}$ are i.i.d with a zero mean and symmetric distribution around zero.\n\t\\item $b^\\ell = 0$.\n\\end{itemize}\n\n\n\\subsection{Xavier's initialization.} There are two steps in Xavier's initialization:\n\\begin{itemize}\n\t\\item forward variance formula,\n\t\\item backward variance formula.\n\\end{itemize}\nFor forward variance:\n\\begin{equation}\\label{key}\nf^\\ell_i = W^\\ell_i \\cdot \\sigma(f^{\\ell-1}) + b^\\ell_i.\n\\end{equation}\nTake variance on both sides:\n\\begin{equation}\\label{key}\n{\\rm Var}[ f^\\ell_i ] = {\\rm Var}[W^\\ell_i \\cdot \\sigma(f^{\\ell-1})]+ b^\\ell _i].\n\\end{equation}\nThey further \\red{assume that $\\sigma  = id$} and\n\\begin{equation}\\label{key}\n\\mathbb{E}[ f^{\\ell-1}_j] = 0.\n\\end{equation}\nThen, they have\n\\begin{equation}\\label{key}\n{\\rm Var}[ f^\\ell_i ]  = n_{\\ell-1}{\\rm Var}[W^\\ell_{ij}] {\\rm Var}[f^{\\ell-1}_j], \n\\end{equation}\nfor all $i=1:n_\\ell$ and $j = 1:n_{\\ell-1}$.\nThis leads to\n\\begin{equation}\\label{key}\n{\\rm Var}[ f^L_i ]  = {\\rm Var}[f^{0}_j] (\\prod_{\\ell=1}^L n_{\\ell-1}{\\rm Var}[W^\\ell_{st}] ),\n\\end{equation}\nfor any $i,j,s,t$.\nThe ideal situation to control the variance of $f^{\\ell}$ during forward propagation is that\n\\begin{equation}\\label{key}\n{\\rm Var}[ f^L_i ] =  {\\rm Var}[f^{0}_j].\n\\end{equation}\nThus, a sufficient condition from forward analysis is:\n\\begin{equation}\\label{key}\n{\\rm Var}[W^\\ell_{ij}] = \\frac{1}{n_{\\ell-1}}.\n\\end{equation}\n\nThe so-called backward variance analysis is to investigate the variance of $\\frac{\\partial L(\\theta)}{\\partial f^\\ell}$ and $\\frac{\\partial L(\\theta)}{\\partial f^{\\ell-1}}$\nwhere $L(\\theta)$ is the loss function.\nThis is important because that:\n\\begin{equation}\\label{key}\n\\frac{\\partial L(\\theta)}{\\partial f^{\\ell-1}} = \\frac{\\partial L(\\theta)}{\\partial f^\\ell} \\frac{\\partial f^\\ell}{\\partial f^{\\ell-1}}.\n\\end{equation}\nWe have the next backward propagation case:\n\\begin{equation}\\label{key}\n\\frac{\\partial L(\\theta)}{\\partial f^{\\ell-1}} = [W^\\ell]^T \\cdot \\frac{\\partial L(\\theta)}{\\partial f^\\ell}.\n\\end{equation}\nSimilarly, we can derive the condition to keep \n\\begin{equation}\\label{key}\n{\\rm Var}[ \\frac{\\partial L(\\theta)}{\\partial f^\\ell}] = {\\rm Var} [ \\frac{\\partial L(\\theta)}{\\partial f^{\\ell-1}}],\n\\end{equation}\nas\n\\begin{equation}\\label{key}\n{\\rm Var}[W^\\ell_{ij}] = \\frac{1}{n_{\\ell}}.\n\\end{equation}\n\nThus, the {\\bf Xavier's initialization} suggests to initialize $W^\\ell_{ij}$ with variance as:\n\\begin{itemize}\n\t\\item Forward based:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ij}] = \\frac{1}{n_{\\ell-1}}.\n\t\\end{equation}\n\t\\item Backward based:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ij}] = \\frac{1}{n_{\\ell}}.\n\t\\end{equation}\n\t\\item Trade-off: \n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ij}] = \\frac{2}{n_{\\ell-1} + n_\\ell}.\n\t\\end{equation}\n\\end{itemize}\n\\fi\n\n\n\\iffalse\nIn order to find a good initialization for deep networks, Kaiming He (2015) followed Xavier (2010) to study the propagations of signals from input layer to output layer.\nSome preliminary results about variance of random variable.\n\\begin{itemize}\n\t\\item Definition:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[X] = \\mathbb{E}[X - \\mathbb{E}[X]]^2 = \\mathbb{E}[X^2] - (E[X])^2.\n\t\\end{equation}\n\t\\item Summation:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[X + Y] = {\\rm Var}[X] + {\\rm Var}[Y],  \n\t\\end{equation}\n\tif $X$ and $Y$ are independent.\n\t\\item Multiplication:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[XY] = \\mathbb{E}[X^2]\\mathbb{E}[Y^2] - (\\mathbb{E}[X])^2(\\mathbb{E}[Y])^2,\n\t\\end{equation}\n\tif $X$ and $Y$ are independent. Furthermore, if $\\mathbb{E}[X] = 0$, \n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[XY] = {\\rm Var}[X]\\mathbb{E}[Y^2].\n\t\\end{equation}\n\\end{itemize}\n\\fi\n\n", "meta": {"hexsha": "a15680e8060bb86650fe148c2c3285083ba71fef", "size": 20763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/initialization.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/initialization.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/initialization.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.3986013986, "max_line_length": 420, "alphanum_fraction": 0.6697490729, "num_tokens": 7651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.6700324702648353}}
{"text": "\\section{Group cohomology}\nToday we will connect the two topics of 2-cocycles and group extensions and finally define the notion of group cohomology.\n% \\begin{mdframed}\n\\begin{mdframed}\n  \\adjustbox{scale=1,center}{%\n    \\begin{tikzcd}\n      &\\mbox{Adding 2-digit numbers}\n        \\ar[ddddl, leftrightarrow]\n        \\ar[ddddr, leftrightarrow, end anchor={[xshift=0ex]}]\n        &\n      \\\\\\\\\\\\\\\\\n      \\mbox{2-cocycle condition}\\ar[rr, dashed, leftrightarrow]& & \\text{Group extensions}\n    \\end{tikzcd}\n  }\n\\end{mdframed}\n\n\nIn the case of two digit numbers, this correspondence looks as follows.\n\n\\begin{mdframed}\n  \\adjustbox{scale=0.73,center}{%\n    \\begin{tikzcd}\n      &\\bbz/100 \\mbox{ under standard addition}\n        \\ar[ddddl, leftrightarrow]\n        \\ar[ddddr, leftrightarrow, end anchor={[xshift=0ex]}]\n        &\n      \\\\\\\\\\\\\\\\\n      \\mbox{carry: }\\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10\\ar[rr, dashed, leftrightarrow]& & {0 \\rightarrow \\bbz/10 \\rightarrow \\bbz/100 \\rightarrow \\bbz/10 \\rightarrow 0}\n    \\end{tikzcd}\n  }\n\\end{mdframed}\n\nBut there is nothing special about $\\bbz/10$ or $\\bbz/100$ and all our proofs and correspondences can be generalized to arbitrary group extensions.\n\n\\begin{mdframed}\n  \\adjustbox{scale=0.88,center}{%\n    \\begin{tikzcd}\n      & G = \\set{\\tens{a}\\units{b} : a \\in H, b \\in K}\n        \\ar[ddddl, leftrightarrow]\n        \\ar[ddddr, leftrightarrow, end anchor={[xshift=0ex]}]\n        &\n      \\\\\\\\\\\\\\\\\n      c:K \\times K \\rightarrow H \\ar[rr, dashed, leftrightarrow]& & {0 \\rightarrow H \\rightarrow (G,+_c) \\rightarrow K \\rightarrow 0}\n    \\end{tikzcd}\n  }\n\\end{mdframed}\n\n% \\end{mdframed}\n% \\subsection{Warmup: Commutative diagrams}\n% Algebraists love commutative diagrams.\n% Commutative diagrams simplify a lot of complex arguments and allow us to ``visualize'' how elements move around but\n%\n% The following \\emph{commutative diagram} represents the equation $i_2 = \\varphi \\circ i_1$.\n% \\begin{equation*}\n%   \\begin{tikzcd}\n%         & G_1 \\ar[dd, \"\\varphi\"] \\\\\n%     H \\ar [ru, \"i_1\"] \\ar[dr, \"i_2\", swap]& \\\\\n%         & G_2\n%   \\end{tikzcd}\n% \\end{equation*}\n%\n% \\begin{qbox}[Practice problems]\n%   For the following commutative diagram, find the homomorphism (if possible)\n%   \\begin{equation*}\n%     \\begin{tikzcd}\n%           & \\bbz/100 \\ar[dd, \"\\varphi\"] \\\\\n%       \\bbz/10 \\ar [ru, \"i_1\"] \\ar[dr, \"i_2\", swap]& \\\\\n%           & \\bbz/100\n%     \\end{tikzcd}\n%   \\end{equation*}\n%   \\begin{enumerate}\n%     \\item $i_1 : $\n%   \\end{enumerate}\n% \\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Maps between extensions}\nWe will fix two abelian groups $H$ and $K$.\n\n\nLet $G_c$ and $G_d$ be two group extensions of $H$ and $K$, given by the 2-cocycles $c: K \\times K \\rightarrow H$ and $d:K \\times K \\rightarrow H$.\nThis means that in $G_c$ and $G_d$ the additions are given by\n\\begin{align}\n  \\label{eq:groupAdditionGroups}\n  \\begin{split}\n    \\tens{a_1}\\units{b_1} +_c \\tens{a_2}\\units{b_2}\n      &=\n      \\tens{a_1 + a_2 + c(b_1, b_2)}\\units{b_1 + b_2} \\\\\n    \\tens{a_1}\\units{b_1} +_d \\tens{a_2}\\units{b_2}\n      &=\n      \\tens{a_1 + a_2 + d(b_1, b_2)}\\units{b_1 + b_2}\n  \\end{split}\n\\end{align}\nwhere $a_1$, $a_2 \\in H$ and $b_1$, $b_2 \\in K$. And there are short exact sequences\n\\begin{equation*}\n  \\begin{tikzcd}\n    0 \\ar[r] & H \\ar[r,\"i_c\"] &  (G_c,+_c)  \\ar[r, \"p_c\"] & K \\ar[r] & 0, \\\\\n    0 \\ar[r] & H \\ar[r,\"i_d\"] &  (G_d,+_d)  \\ar[r, \"p_d\"] & K \\ar[r] & 0.\n  \\end{tikzcd}\n\\end{equation*}\n\n\n% Set $S_{100}$ be the set of two digit numbers and let $c: \\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$ be normalized symmetric 2-cocycle.\n% Denote by $(S_{100}, +_c)$ the abelian group with addition given by\n% \\begin{equation*}\n%   \\tens{a_1}\\units{b_1} + \\tens{a_2}\\units{b_2}\n%   =\n%   \\tens{a_1 + a_2 + c(b_1, b_2)}\\units{b_1 + b_2}\n% \\end{equation*}\n% Hence $(S_{100}, +_c)$ sits in a short exact sequence\n% \\begin{equation*}\n%   \\begin{tikzcd}\n%     0 \\ar[r] & H \\ar[r,\"i\"] &  (S_{100}, +_c)  \\ar[r, \"p\"] & K \\ar[r] & 0\n%   \\end{tikzcd}\n% \\end{equation*}\n%\n%\n% A group homomorphism between $(S_{100}, +_c)$ and $(S_{100}, +_d)$ is a map $\\varphi: (S_{100}, +_c) \\rightarrow (S_{100}, +_d)$ that satisfies\n% \\begin{align*}\n%   \\varphi([a_1][b_1] +_c [a_2][b_2])\n%   &=\n%   \\varphi([a_1][b_1]) +_d \\varphi([a_2][b_2])\n% \\end{align*}\n% There is nothing more we can do here as we do not know anything about the right hand side. So we need to put more restrictions on what group homomorphisms are allowed.\n\n\\begin{definition}\n  A \\emph{morphism between extensions} is a group homomorphism $\\varphi: G_c \\rightarrow G_d$ which satisfies the following properties:\n  \\begin{enumerate}\n    \\item $\\varphi$ restricted to $H$ is just the identity map,\n    \\item the map induced by $\\varphi$ on $K$ is the identity map.\n  \\end{enumerate}\n  % If further $\\varphi$ is bijective (=one-to-one and onto), we say that $\\varphi$ is an \\emph{isomorphism}.\n\n  In the language of short exact sequences, this is written as\n  \\begin{equation*}\n    \\begin{tikzcd}\n      0 \\ar[r] & H \\ar[r,\"i_c\"] \\ar[d,\"\\id_H\"] &  G_c \\ar[d,\"\\varphi\"] \\ar[r, \"p_c\"] & K \\ar[r] \\ar[d,\"\\id_K\"]& 0 \\\\\n      0 \\ar[r] & H \\ar[r,\"i_d\"] &  G_d  \\ar[r, \"p_d\"] & K \\ar[r] & 0\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{qbox}\n  What are all the group homomorphisms $\\bbz/100 \\rightarrow \\bbz/100$?\n  Of these, which group homomorphisms are also morphisms from the standard extension $0 \\rightarrow \\bbz/10 \\rightarrow \\bbz/100 \\rightarrow \\bbz/10 \\rightarrow 0$ to itself.\n\\end{qbox}\n\n\\begin{qbox}\n  What are all the group homomorphisms $\\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10 \\times \\bbz/10$?\n  Of these, which group homomorphisms are also morphisms from the extension $0 \\rightarrow \\bbz/10 \\rightarrow \\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10 \\rightarrow 0$ to itself.\n\\end{qbox}\n\n\\begin{qbox}\n  For $a \\in H$ and $b \\in K$, show that $\\varphi(\\tens{a}\\units{0}) = \\tens{a}\\units{0}$ and $\\varphi(\\tens{0}\\units{b}) = \\tens{a'}\\units{b}$ for some $a' \\in H$.\n\\end{qbox}\nFor each $b \\in K$, let $\\alpha(b)$ be the element in $H$ such that $p(\\tens{0}\\units{b}) = \\tens{\\alpha(b)}\\units{b}$, so that $\\alpha$ is a function (not a group homomorphism) $K \\rightarrow H$.\n\n\\begin{qbox}\n  For $a \\in H$ and $b \\in K$, show that $\\varphi(\\tens{a}\\units{b}) = \\tens{a + \\alpha(b)}\\units{b}$.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that every morphism between extensions $G_c$ and $G_d$ is bijective.\n\\end{qbox}\n\nAs we did with group axioms, we want to rewrite what a group homomorphism means in terms of the 2-cocycles $c$ and $d$.\nThe group homomorphism $\\varphi: (G_1,+_c) \\rightarrow (G_2,+_d)$ satisfies the identity\n\\begin{align}\n  \\label{eq:groupHom}\n  \\varphi(\\tens{a_1}\\units{b_1} +_c \\tens{a_2}\\units{b_2}) = \\varphi(\\tens{a_1}\\units{b_1}) +_d \\varphi(\\tens{a_2}\\units{b_2})\n\\end{align}\n% And the additions $+_c$ and $+_d$ are given by the identities in Equation \\eqref{eq:groupAdditionGroups}.\n\n\\begin{qbox}\n  \\label{q:2coboundaryIdentity}\n  Expand the identity \\eqref{eq:groupHom} using the equation \\eqref{eq:groupAdditionGroups} and find a new identity involving the functions $c$, $d$, and $h$.\n\\end{qbox}\n\n\\begin{definition}\n  A \\emph{normalized 2-coboundary} is a map $e(b_1,b_2): K \\times K \\rightarrow H$ such that\n  \\begin{equation*}\n    e(b_1, b_2) = \\alpha(b_1 + b_2) - \\alpha(b_1) - \\alpha(b_2)\n  \\end{equation*}\n  for some function $h:K \\rightarrow H$.\n\\end{definition}\n\n\\begin{qbox}\n  Check that the identity in Q.\\ref{q:2coboundaryIdentity} is saying that $c - d$ is a normalized 2-coboundary.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that a normalized 2-coboundary is also a normalized, symmetric, 2-cocycle.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Group cohomology}\n\\begin{qbox}\n  Show that the set of normalized, symmetric, 2-cocycles $c:K \\times K \\rightarrow H$ forms a group under addition.\n  This group is denoted $\\calz^2(K;H)$.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that the set of normalized 2-coboundaries $c: K \\times K \\rightarrow H$ forms a group under addition.\n  This group is denoted $\\calb^2(K; H)$.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that $\\calb^2(K; H)$ is a subgroup of $\\calz^2(K;H)$.\n\\end{qbox}\n\n\\begin{definition}\n  The second cohomology group of $K$ with coefficients $H$ is defined as\n  \\begin{align*}\n    H^2(K;H) := \\calz^2(K;H) / \\calb^2(K; H)\n  \\end{align*}\n\\end{definition}\n\nWe say that two extensions are equivalent if there is a morphism between them.\n\\begin{qbox}\n  Show that this defines an equivalence relation on the set of group extensions.\n\\end{qbox}\n\nDenote by $\\ext^1(K;H)$ the equivalence classes of extensions under this equivalence relation.\n\n\\begin{qbox}\n  Prove that there is a 1-1 correspondence between $H^2(K;H)$ and $\\ext^1(K;H)$.\n\\end{qbox}\n", "meta": {"hexsha": "3f3ca939aa09e1d5d7335ff8910c58c918122a93", "size": 8717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03.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": "03.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": "03.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": 34.7290836653, "max_line_length": 196, "alphanum_fraction": 0.6503384192, "num_tokens": 3242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.670032463830436}}
{"text": "%---------------------------Skew-----------------------------\n\\section{Skew}\n\nFirst define normalized principal axes\n\\[\n\\begin{array}{lcl}\n\\hat X_1 &=& \\frac {\\vec X_1} {\\normvec{X_1}}\\\\\n\\hat X_2 &=& \\frac {\\vec X_2} {\\normvec{X_2}}.\n\\end{array}\n\\]\n\nThe skew is then\n\\[\nq = | \\hat X_1 \\cdot \\hat X_2 |.\n\\]\nA geometric intepretation of the skew is that it measures the angle between the principal axes.\nIn fact, it is the absolute value of the cosine of the angle between the principal axes.\n\nNote that if $\\normvec{X_1}$ or $\\normvec{X_2} < DBL\\_MIN$, we set $q = 0$.\n\n\\quadmetrictable{skew}%\n{$1$}%                                      Dimension\n{$[0.5,1]$}%                                Acceptable range\n{$[0,1]$}%                                  Normal range\n{$[0,1]$}%                                  Full range\n{$1$}%                                      Unit square\n{Adapted from \\cite{rob:87}}%               Citation\n{v\\_quad\\_skew}%                            Verdict function name\n\n", "meta": {"hexsha": "3bc451685c18fd3d7a2df333adc6d9070d852e18", "size": 996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadSkew.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/QuadSkew.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/QuadSkew.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": 33.2, "max_line_length": 95, "alphanum_fraction": 0.4889558233, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6699392705234077}}
{"text": "% !TEX root =../thesis-letomes.tex\n\n\\chapter{Miscellaneous Derivations}\n\n\\section{Nondimensionalization of H-R4B Equations of Motion} \\label{apx:hr4b-nondimensionalization}\n\nLooking at the \\(p_j\\) from \\cref{eq:pr,eq:ptheta,eq:pphi} we can infer their units:\n\n\\begin{align}\n    k_{pr} &= \\frac{k_m}{k_r k_t} \\\\[0.2cm]\n    k_{p\\theta} &= \\frac{k_m k_r^2}{k_t} = k_{pr} k_r \\\\[0.2cm]\n    k_{p\\phi} &= k_{p\\theta}\n\\end{align}\n\nWe now introduce the quantity\n\n\\begin{equation}\n    b_j = \\frac{p_j}{m_s}.\n\\end{equation}\nIt proves useful to introduce into Hamilton's equations because the mass cancels out (as expected from Newton's 2nd Law, and thus removes the need for introducing  selecting characteristic mass \\(k_m\\). We will treat the interpretation later. \\(b_j\\) has units:\n\n\\begin{align}\n    k_{br} = \\frac{k_{pr}}{k_m} = \\frac{k_r}{k_t} \\\\[0.2cm]\n    k_{b\\theta} = \\frac{k_{p\\theta}}{k_m} = \\frac{k_r^2}{k_t} \\\\[0.2cm]\n    k_{b\\phi} = \\frac{k_{p\\phi}}{k_m} = \\frac{k_r^2}{k_t}\n\\end{align}\n\nFor the \\(q_j\\), \\cref{eq:rdot,eq:thetadot,eq:phidot}, we set \\(b_j = \\frac{p_j}{m_s}\\) and nondimensionalize:\n\n\\begin{align}\n    \\od{r}{t} &= \\frac{\\blue{p_r}}{\\blue{p_r}} \\\\[0.2cm]\n    \\Leftrightarrow \\od{r}{t} &= \\blue{b_r} \\\\[0.2cm]\n    \\Leftrightarrow \\frac{k_r}{k_t} \\od{R}{T} &= k_{br} B_R,\n\\end{align}\nso we get\n\\begin{empheq}[box=\\widefbox]{align}\n    \\label{eq:Rdot}\n    \\dot{R} = B_R\n\\end{empheq}\n\n\\begin{align}\n    \\od{\\theta}{t} &= \\frac{\\blue{p_\\theta}}{\\blue{m_s} r^2} \\\\[0.2cm]\n    \\Leftrightarrow \\od{\\theta}{t} &= \\frac{\\blue{b_\\theta}}{r^2} \\\\[0.2cm]\n    \\Leftrightarrow \\od{\\theta}{t} &= \\frac{b_\\theta}{r^2} \\\\[0.2cm]\n    \\Leftrightarrow \\frac{1}{k_t} \\od{\\theta}{T} &= \\frac{k_{b\\theta}}{k_r^2} \\frac{B_\\theta}{R^2},\n\\end{align}\nso we get\n\\begin{empheq}[box=\\widefbox]{align}\n    \\label{eq:thetadot-nondim}\n    \\dot{\\theta} = \\frac{B_\\theta}{R^2}\n\\end{empheq}\n\n\\begin{align}\n    \\od{\\phi}{t} &= \\frac{\\blue{p_\\phi}}{{\\blue{m_s}} r^2 \\sin^2{\\theta}} \\\\[0.3cm]\n    \\Leftrightarrow \\od{\\phi}{t} &= \\frac{\\blue{b_\\phi}}{r^2 \\sin^2{\\theta}}  \\\\[0.3cm]\n    \\Leftrightarrow \\frac{1}{k_t} \\frac{\\Phi}{T} &= \\frac{k_\\phi}{k_r^2} \\frac{B_\\phi}{R^2 \\sin^2{\\theta}},\n\\end{align}\nso we get\n\\begin{empheq}[box=\\widefbox]{align}\n    \\label{eq:phidot-nondim}\n    \\dot{\\phi} = \\frac{B_\\phi}{R^2 \\sin^2{\\theta}}\n\\end{empheq}\n\nFor the \\(p_j\\), \\cref{eq:prdot,eq:pthetadot,eq:pphidot} , we first divide by \\(m_s\\) then set \\(b_j = \\frac{p_j}{m_s}\\) (\\blue{relevant terms marked in blue}) and \\(\\mu_k = G M_k\\):\n\n\\begin{align}\n    \\begin{split}\n        \\od{\\blue{p_r}}{t} = -\\pd{H}{q_r} &= \\frac{\\blue{p_\\theta^2}}{\\blue{m_s} r^3} + \\frac{\\blue{p_\\phi^2}}{\\blue{m_s} r^3 \\sin^2{\\theta} } \\\\\n        &+ G \\blue{m_s} \\\\\n        &\\sum\\limits_{k} M_k \\frac{-r + r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)}\\right)}{\\left[r^2 + r_k^2 - 2 r r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}},\n    \\end{split} \\\\[0.3cm]\n    \\begin{split}\n        \\Leftrightarrow \\od{\\blue{b_r}}{t} &= \\frac{\\blue{b_\\theta^2}}{r^3} + \\frac{\\blue{b_\\phi^2}}{r^3 \\sin^2{\\theta} } \\\\\n        &+ \\sum\\limits_{k} \\mu_k \\frac{-r + r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)}\\right)}{\\left[r^2 + r_k^2 - 2 r r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}}.\n    \\end{split}\n\\end{align}\nAnd finally we nondimensionalize:\n\\begin{align}\n    \\begin{split}\n        \\Leftrightarrow \\teal{\\frac{k_{br}}{k_t}} \\od{B_R}{T} &= \\orange{\\frac{k_{b\\theta}^2}{k_r^3}} \\frac{B_\\theta^2}{R^3} + \\orange{\\frac{k_{b\\phi}^2}{k_r^3}} \\frac{B_\\phi^2}{R^3 \\sin^2{\\theta} } \\\\\n        &+ \\red{\\frac{k_r^3}{k_t^2}\\frac{1}{k_r^2}} \\\\\n        & \\sum\\limits_{k} \\eta_k \\frac{-R + R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)}\\right)}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}},\n    \\end{split}\n\\end{align}\n\nwhere the characteristic units are colored teal, orange and red, \\([\\mu] = [G] [M_k] = \\frac{k_r^3}{k_m k_t^2} k_m = \\frac{k_r^3}{k_t^2} \\), the first part of the red factor, the second part being from the fraction inside the summation, having units \\(\\frac{1}{k_r^2}\\). Dividing \\(\\frac{k_{br}}{k_t}\\) over from the left-hand side the units cancel as they must:\n\n\\begin{align}\n    & \\teal{\\frac{k_t}{k_{br}}} \\orange{\\frac{k_{b\\theta}^2}{k_r^3} } \\\\\n    = &\\frac{k_t^2}{k_r} \\frac{k_r^4}{k_t^2 k_r^3}\\\\\n    = &1,\n\\end{align}\nand equivalently same for the second orange since \\(k_\\theta\\) and \\(k_\\phi\\) have the same units. And the red terms:\n\n\\begin{align}\n    & \\teal{\\frac{k_t}{k_{br}}} \\red{\\frac{k_r^3}{k_t^2}\\frac{1}{k_r^2}} \\\\\n    = &\\frac{k_t^2}{k_r} \\frac{k_r^3}{k_t^2} \\frac{1}{k_r^2} \\\\\n    = &1\n\\end{align}\n\nand we are left with the nondimensionalized equation:\n\\begin{empheq}[box=\\widefbox]{align}\n    \\label{eq:Brdot}\n    \\dot{B}_r = &\\frac{B_\\theta^2}{R^3} + \\frac{B_\\phi^2}{R^3 \\sin^2{\\theta}} \\\\\n    & + \\sum\\limits_{k} \\eta_k \\frac{-R + R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)}\\right)}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}} \\notag\n\\end{empheq}\n\nThe exact same procedure for \\(\\dot{p_\\theta}\\) and \\(\\dot{p}_\\phi\\) gives us:\n\n\\begin{empheq}[box=\\widefbox]{align}\n    \\label{eq:Bthetadot}\n    \\dot{B}_\\theta = &\\frac{B_\\phi^2}{R^2 \\sin^2{\\theta} \\tan{\\theta}} \\\\\n    &+ \\sum\\limits_{k} \\eta_k \\frac{R R_k \\left[-\\sin{\\theta}\\cos{\\theta_k} + \\cos{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right]}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}} \\notag\n\\end{empheq}\n\n\\begin{empheq}[box=\\widefbox]{align}\n    \\label{eq:Bphidot}\n    \\dot{B}_\\phi = &\\sum\\limits_{k} \\eta_k \\frac{- R R_k \\sin{\\theta}\\sin{\\theta_k}\\sin{(\\phi - \\phi_k)}}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}}\n\\end{empheq}\n\nFinally we can get the nondimensionalize \\(H\\) by the same method. Again we first divide by \\(m_s\\) to obtain ``Hamiltonian per spacecraft mass'', \\(H/m_s = H_m\\):\n\n\\begin{equation*}\n    \\begin{aligned}\n        H &= \\frac{p_r^2}{2 m_s} + \\frac{p_\\theta^2}{2 m_s r^2} + \\frac{p_\\phi^2}{2 m_s r^2 \\sin^2{\\theta}} \\\\\n        &- G m_s \\sum\\limits_{k} \\frac{M_k}{\\sqrt{r^2 + r_k^2 - 2 r r_k \\left[\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k})\\right]}},\n    \\end{aligned}\n\\end{equation*}\n\n\\begin{equation}\n    \\begin{aligned}\n        \\Leftrightarrow H_m &= \\frac{b_r^2}{2} + \\frac{b_\\theta^2}{2 r^2} + \\frac{b_\\phi^2}{2 r^2 \\sin^2{\\theta}} \\\\\n        &- \\sum\\limits_{k} \\mu_k \\frac{1}{\\sqrt{r^2 + r_k^2 - 2 r r_k \\left[\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k})\\right]}},\n    \\end{aligned}\n\\end{equation}\n\nand then use our characteristic units to get \\(\\mathcal{H}_m\\):\n\n\\begin{equation}\n    \\begin{aligned}\n        \\Leftrightarrow \\mathcal{H}_m &= \\frac{B_r^2}{2} + \\frac{B_\\theta^2}{2 R^2} + \\frac{B_\\phi^2}{2 R^2 \\sin^2{\\theta}} \\\\\n        &- \\sum\\limits_{k} \\eta_k \\frac{1}{\\sqrt{R^2 + R_k^2 - 2 R R_k \\left[\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k})\\right]}}. \\label{eq:HH_m}\n    \\end{aligned}\n\\end{equation}\n\n\\section{Symplectic Verlet Derivations}\\label{apx:symplectic-verlet-derivations}\n\n\\subsection{Symplectic Verlet Derivations (Handwritten)}\n\\includepdf[scale=1.0,pages={-}]{pdf/r4b-symplectic-verlet-handwritten.pdf}\n\n\\subsection{Symplectic Verlet Derivations (Mathematica Check)}\n\\includepdf[scale=1.0,pages={-}]{pdf/r4b-symplectic-verlet-mathematica.pdf}", "meta": {"hexsha": "ae86d456506b5437f652ce0c8908633c7462e4a5", "size": 7862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/APX2-Miscellaneous-Derivations.tex", "max_stars_repo_name": "GandalfSaxe/letomes", "max_stars_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/APX2-Miscellaneous-Derivations.tex", "max_issues_repo_name": "GandalfSaxe/letomes", "max_issues_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/APX2-Miscellaneous-Derivations.tex", "max_forks_repo_name": "GandalfSaxe/letomes", "max_forks_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.7236842105, "max_line_length": 362, "alphanum_fraction": 0.6128211651, "num_tokens": 3241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6699200057891992}}
{"text": "\\subsection{part d}\n\\begin{itemize}\n    \\item sensitivity function\n    $$\n    S_G^{G_{cl}} = \\dfrac{1}{1+C(s)G(s)}\n    $$\n    \\begin{figure}[H]\n        \\caption{sensitivity function bode magnitude}\n        \\centering\n        \\includegraphics[width=12cm]{../Figure/Q1/Q1_d/sensitivity_func.png}\n    \\end{figure}\n    System sensitivity is very hight at high frequency but low at low frequency.\n    \\item complementary sensitivity function \n    $$\n    S_G^{G_{cl}} = \\dfrac{C(s)G(s)}{1+C(s)G(s)}\n    $$\n    \\begin{figure}[H]\n        \\caption{complementary sensitivity function bode magnitude}\n        \\centering\n        \\includegraphics[width=12cm]{../Figure/Q1/Q1_d/com_sensitivity_func.png}\n    \\end{figure}\n    \\item Nichols chart for sensitivity function and complementary sensitivity function \n    \\begin{figure}[H]\n        \\caption{nyquist chart}\n        \\centering\n        \\includegraphics[width=12cm]{../Figure/Q1/Q1_d/nyquist.png}\n    \\end{figure}\n\\end{itemize}\n", "meta": {"hexsha": "b06fb4ca0b2447dbad04b43b28339b11a44c740d", "size": 968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW IV/Report/Q1/Q1_d/Q1_d.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 IV/Report/Q1/Q1_d/Q1_d.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 IV/Report/Q1/Q1_d/Q1_d.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": 33.3793103448, "max_line_length": 88, "alphanum_fraction": 0.6518595041, "num_tokens": 275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6698829292674084}}
{"text": "\\subsection{Model optimization}\n\\label{sec:optimization}\n\nOur objective is to find the best clustering, or equivalently, the indicator vectors $\\{\\bm{z}_r\\}_{r=1}^k$ that \nminimizes the penalty function $\\mathcal{J}()$.\nNote that $\\mathcal{J}()$ is a function of $\\bml$ and $\\bmo$ (which are the weights of meta-paths and object\nattributes), whose values need to be learned as well.\n\\schain\\ learns these parameters using an iterative mutual update approach. \nEach iteration consists of two steps. First, given $\\bml$ and $\\bmo$, we find the optimal clustering \n$\\{\\bm{z}_r\\}_{r=1}^k$. Second, given $\\{\\bm{z}_r\\}_{r=1}^k$, we\nfind the optimal $\\bml$ and $\\bmo$.\n\\schain\\ iterates until the change in the penalty is smaller than a threshold $\\epsilon$ or \na fixed number of iterations have been executed.\nNext, we show how the two update steps are performed.\n\n\\subsubsection{Finding the optimal $\\{${\\boldmath $z$}$_r\\}_{r=1}^k$ given {\\boldmath $\\lambda$} and \\boldmath $\\omega$}\n\nFor fixed values of $\\bml$ and $\\bmo$, $\\mathcal{J}()$ is a function of $\\bmz$.\nWe define a matrix $\\tilde{Z}$, where its $r$-th column\n$\\tilde{Z}_{\\cdot r}$ \nequals $D^{\\frac{1}{2}}\\bm{z}_r/(\\bm{z}_r^TD\\bm{z}_r)^{\\frac{1}{2}}$. \nNote that since $\\tilde{Z}^T\\tilde{Z} = I_k$, where $I_k$ is the $k \\times k$ identity matrix,\n$\\tilde{Z}$ is an orthonormal matrix.\nFor fixed values of $\\bml$ and $\\bmo$, minimizing $\\mathcal{J}()$ is equivalent to minimizing:\n%\\begin{small}\n\\begin{equation}\n\\label{eq:obj:trans2}\n\\begin{split}\n\\mathcal{J}'(\\tilde{Z}) & = \\mathit{trace}(\\tilde{Z}^TD^{-\\frac{1}{2}}(D-S-W\\circ S)D^{-\\frac{1}{2}}\\tilde{Z}), \\\\\n%& = \\mathit{trace}(\\tilde{Z}^TD^{-\\frac{1}{2}}DD^{-\\frac{1}{2}}\\tilde{Z}-\\tilde{Z}^TD^{-\\frac{1}{2}}(S+ W\\circ S)D^{-\\frac{1}{2}}\\tilde{Z}) \\\\\n& = \\mathit{trace}(I_k-\\tilde{Z}^TD^{-\\frac{1}{2}}(S+W\\circ S)D^{-\\frac{1}{2}}\\tilde{Z}).\n\\end{split}\n\\end{equation}\n%\\end{small}\nSince $trace(I_k)$ is a constant, the above is equivalent to solving the following trace maximization problem:\n\\begin{equation}\n\\begin{split}\n\\label{eq:max}\n& \\max_{\\tilde{Z}^T\\tilde{Z} = I_k}\\mathit{trace}(\\tilde{Z}^TD^{-\\frac{1}{2}}(S+W\\circ S)D^{-\\frac{1}{2}}\\tilde{Z}).  \\\\\n\\end{split}\n\\end{equation}\nSince $\\tilde{Z}$ is a rigorous cluster indicator matrix, the optimization problem is NP-hard~\\cite{DBLP:dblp_conf/icml/LongZWY06}.\nTo address this issue, we allow real relaxation to $\\tilde{Z}$ so that its entries can assume real values. Then,\naccording to the Ky-Fan theorem~\\cite{bhatia1997matrix}, \nthe maximization problem (\\ref{eq:max}) has a closed-form solution that corresponds to the subspace spanned \nby the top $k$ eigenvectors of $K = D^{-\\frac{1}{2}}(S+W\\circ S)D^{-\\frac{1}{2}}$. \nSince $\\tilde{Z}_{\\cdot r} = D^{\\frac{1}{2}}\\bm{z}_r/(\\bm{z}_r^TD\\bm{z}_r)^{\\frac{1}{2}}$,\nwe need to transform each $\\tilde{Z}_{\\cdot r}$ back to a real-relaxed $\\bm z_r$. \nWe first calculate\n$U = D^{-\\frac{1}{2}}\\tilde{Z}$ and then\nnormalize it by column.\nEach column in $U$ is a real-relaxed $\\bm z_r$.\nFinally, with the real relaxation, entries in $U$ take on fractional values, so the clustering is not\ndefinite. To derive a hard clustering, \nwe treat each row in $U$ as a feature vector of an object.\nAfter row normalization on $U$, we adopt $k$-means to cluster objects.\n%a postprocessing step is required and we adopt $k$-means to convert $\\tilde{Z}$ to $\\{\\bm {z}_r\\}_{r=1}^k$.\n%we take the cluster membership values of each object (derivable from $\\bmz$)\n%as features of objects and cluster the objects using $k$-means based on these cluster membership features.\n\n\\subsubsection{Finding the optimal {\\boldmath $\\lambda$} and {\\boldmath $\\omega$} given $\\{${\\boldmath $z$}$_r\\}_{r=1}^k$}\n%After clusters are derived, they can be used to supervise the weight learning of meta paths and attributes, \n%because different meta paths and attributes play different roles in determining the formation of these clusters.\n%Therefore, we can optimize $\\bm \\lambda$ and $\\bm \\omega$ based on the results of $\\{\\bm z_i\\}_{i=1}^k$.\n\nFor fixed $\\{\\bm z_r\\}_{r=1}^k$, $\\mathcal{J}()$ is a function of $\\bml$ and $\\bmo$.\nWe rewrite Eq.~\\ref{eq:obj:trans:reg} as:\n\\begin{small}\n\\begin{equation}\n\\label{eq:obj:trans3}\n\\begin{split}\n\\mathcal{J}(\\bm \\lambda, \\bm \\omega) & = \n%\\sum_{i=1}^k\\frac{\\bm{z}_i^T(D-S- \\mathcal{W} \\circ S)\\bm{z}_i}{\\bm{z}_i^TD\\bm{z}_i} + \\gamma(||\\bm\\lambda||^2+||\\bm \\omega||^2) \\\\\n%& = \n\\sum_{r=1}^k\\frac{\\bm{z}_r^TD\\bm{z}_r-\\bm{z}_r^T(S+ \\mathcal{W} \\circ S)\\bm{z}_r}{\\bm{z}_r^TD\\bm{z}_r} + \\gamma(||\\bm\\lambda||^2+||\\bm \\omega||^2), \\\\\n& = k - \\sum_{r=1}^k\\frac{\\bm{z}_r^T(S+ \\mathcal{W} \\circ S)\\bm{z}_r}{\\bm{z}_r^TD\\bm{z}_r} + \\gamma(||\\bm\\lambda||^2+||\\bm \\omega||^2). \\\\\n%& + \\gamma(\\|\\bm \\lambda\\|^2 + \\sum_{c=1}^k \\|A_c\\|_F^2),\n\\end{split}\n\\end{equation}\n\\end{small}\nSince $k$ is a constant, minimizing $\\mathcal{J}(\\bml, \\bmo)$ is equivalent to maximizing:\n\\begin{equation}\n\\label{eq:obj:trans4}\n%\\mathcal{J}''(\\bml, \\bmo) = \n\\max_{\\bm \\lambda, \\bm \\omega} \\sum_{r=1}^k\\frac{\\bm{z}_r^T(S+ \\mathcal{W} \\circ S)\\bm{z}_r}{\\bm{z}_r^TD\\bm{z}_r}\n- \\gamma(||\\bm \\lambda||^2+||\\bm \\omega||^2).\n\\end{equation}\nNote that the entries of matrices $S$ and $D$ are linear functions of $\\bml$ and $\\bmo$.\nTherefore, the numerator and the denominator of each term in the summation are both linear functions of $\\bml$ and $\\bmo$.\nHence, (\\ref{eq:obj:trans4})\ncan be rewritten as:\n%can be reformulated to a nonlinear polynomial fractional programming (NPFP) problem~\\cite{dinkelbach1967nonlinear}.\n\n%\\textbf{Nonlinear polynomial fractional programming problem (NPFPP)}.\n%$f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) = \\sum_{u=1}^p a_u\\prod_{j = 1}^{|\\mathcal{PS}|}(\\lambda_j)^{b_u}\\prod_{i=1}^k\\prod_{j=1}^{|\\mathcal{A}|}((A_i)_{jj})^{c_{uij}}$, \n%$g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) = \\sum_{u=1}^q r_u \\prod_{j = 1}^{|\\mathcal{PS}|}(\\lambda_j)^{s_u}\\prod_{i=1}^k\\prod_{j=1}^{|\\mathcal{A}|}((A_i)_{jj})^{t_{uij}}$.\n%Then Eq.~\\ref{eq:obj:trans4} can be revised as\n\\begin{equation}\n\\label{eq:obj:trans5}\n\\mathcal{H}(\\bml, \\bmo) = \\max_{\\bm \\lambda, \\bm \\omega} \\frac{f(\\bm \\lambda, \\bm \\omega)}{g(\\bm \\lambda, \\bm \\omega)},\n\\end{equation}\nwhere\n$f(\\bm \\lambda, \\bm \\omega)$ and $g(\\bm \\lambda, \\bm \\omega)$ are two nonlinear multivariate polynomial functions.\n\nIt is shown in~\\cite{dinkelbach1967nonlinear} that the maximization problem with the form shown in Eq.~\\ref{eq:obj:trans5} can be solved by solving the following\nrelated {\\it non-linear parametric programming} problem:\n%It is difficult to directly perform analysis on a NPFP problem to determine the existence of solution, so it is necessary to \n%convert this kind of problem into an easy-to-solve one. \n%\n%\\begin{theorem}\n%\\label{theo:NPFP}~\\cite{DBLP:dblp_journals/jgo/TuyTK04}\n%The above NPFP problem is equivalent to the following polynomial programming (PP) problem\n%\\begin{equation}\n%\\label{eq:obj:trans6}\n%\\max_{\\bm \\lambda, \\bm \\omega, \\eta} \\eta f(\\bm \\lambda, \\bm\\omega)\n%\\end{equation}\n%subject to $\\sum_{i=1}^{|\\mathcal{PS}|}\\lambda_i = 1$,$\\lambda_i \\geq 0$, $i = 1,2,...|\\mathcal{PS}|$,\n%$\\sum_{j=1}^{|A|}\\omega_j = 1$, $\\omega_j \\geq 0$, $j = 1,2,...|A|$\n%and $0 \\leq \\eta \\leq 1/g(\\bm \\lambda, \\bm \\omega)$.\n%\\comment{\n%Proof: Suppose $(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k, \\hat \\eta)$ is an optimal solution for Eq.~\\ref{eq:obj:trans6},\n%obviously, $\\hat \\eta = 1/g(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$ and $\\hat \\eta f(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k) = \n%f(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)/g(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$. Then for any solution $(\\bm \\lambda, \\{A_i\\}_{i=1}^k)$ for NFPP,\n%setting $\\eta = 1/g(\\bm \\lambda, \\{A_i\\}_{i=1}^k)$ satisfies the constraints for PPPPC. Since $(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k, \\hat \\eta)$\n%corresponds to the maximum value of Eq.~\\ref{eq:obj:trans6}, we have $\\eta f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) \\leq \\hat \\eta f(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$\n%, i.e., \n%$f(\\bm \\lambda, \\{A_i\\}_{i=1}^k)/g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) \\leq$ $f(\\hat{\\bm \\lambda},$ $\\{\\hat A_i\\}_{i=1}^k)$$/g(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$.\n%Therefore, $(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$ solves NFPP.\n%\n%Conversely, suppose $(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$ solves NFPP. Then for any solution $(\\bm \\lambda, \\{A_i\\}_{i=1}^k, \\eta)$ for PPPPC, \n%we have $\\eta f(\\bm \\lambda, \\{A_i\\}_{i=1}^k)$ $\\leq f(\\bm \\lambda, \\{A_i\\}_{i=1}^k)/g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) \\leq f(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)/g(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$. By setting $\\hat \\eta = 1/g(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k)$, obviously, $(\\hat{\\bm \\lambda}, \\{\\hat A_i\\}_{i=1}^k, \\hat \\eta)$ solves PPPPC.\n%}\n%\\hfill$\\Box$\n%\\end{theorem}\n%\n%According to Theorem~\\ref{theo:NPFP}, the NPFP problem can be solved by \n%solving an equivalent PP problem at the cost of adding one more parameter.\n%Obviously, the added parameter brings in new burden and is not preferred.\n%Moreover, it is well known that the key to solving a global optimization problem is to transcend an incumbent value of the objective function,\n%so we can reformulate the NPFP problem into a nonlinear parametric programming (NPP) problem and further simplify it.\n%Using the same symbols in Eq.~\\ref{eq:obj:trans5}, we define\n\\begin{definition}\n\\label{def:npp}\n\\textbf{[Non-linear parametric programming (NPP)]}\nLet $f(\\bml,\\bmo)$ and $g(\\bml,\\bmo)$ be two multivariate polynomial functions. For a given $\\mu$, find\n\\begin{equation}\n\\label{eq:obj:trans7}\nF(\\mu) = \\max_{\\bm \\lambda, \\bm \\omega} \\left( f(\\bm \\lambda, \\bm \\omega) - \\mu g(\\bm \\lambda, \\bm \\omega) \\right).\n\\end{equation}\nIn our context, the parameters $\\bml$ and $\\bmo$ are subject to the constraints listed at the end of Section~\\ref{sec:penalty}.\n%subject to $\\sum_{i=1}^{|\\mathcal{PS}|}\\lambda_i = 1$,$\\lambda_i \\geq 0$, $i = 1,2,...|\\mathcal{PS}|$ and\n%$\\sum_{j=1}^{|A|}\\omega_j \\newline= 1$, $\\omega_j \\geq 0$, $j = 1,2,...|A|$.\n\\hfill$\\Box$\n\\end{definition}\nIn~\\cite{dinkelbach1967nonlinear}, the following theorem is proved.\n\\begin{theorem}\n\\label{theorem2}\nGiven a fixed $\\mu$, let $({\\bm \\lambda^*}, {\\bm \\omega^*})$ be the optimal solution to $F(\\mu)$ (Eq.~\\ref{eq:obj:trans7}).\n$(\\bm \\lambda^*, \\bm \\omega^*)$ is also an optimal solution to $\\mathcal{H}(\\bml, \\bmo)$ (Eq.~\\ref{eq:obj:trans5}) if and only if $F(\\mu) = 0$.\n%$f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) = \\sum_{u=1}^p a_u \\prod_{j = 1}^{|\\mathcal{PS}|}(\\lambda_j)^{b_u}\\prod_{i=1}^k$ $\\prod_{j=1}^{|\\mathcal{A}|}((A_i)_{jj})^{c_{uij}}$, \n%$g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) = \\sum_{u=1}^q r_u \\prod_{j = 1}^{|\\mathcal{PS}|}(\\lambda_j)^{s_u}\\prod_{i=1}^k$ $\\prod_{j=1}^{|\\mathcal{A}|}((A_i)_{jj})^{t_{uij}}$.\n\\hfill$\\Box$\n\\end{theorem}\n\nBesides Theorem~\\ref{theorem2}, a few lemmas are also proved in~\\cite{dinkelbach1967nonlinear}:\n%Theorem~\\ref{theorem2} reduces the NPFP problem to a NPP problem \\emph{in the same parameter space},\n%which is much simpler compared with PP problem. Also it is much easier to solve a NPP problem than a NPFP problem.\n%Besides, we have some lemmas to help with the optimization.\n\n\\begin{lemma}\n\\label{lemma1}\n$F(\\mu)$ is convex.\n\\comment{\nProof: Suppose $(\\bm \\lambda, \\{A_i\\}_{i=1}^k)$ is the solution corresponding to $\\mu = t\\mu_1 + (1-t)\\mu_2$,\nwhere $\\mu_1 \\neq \\mu_2, 0 \\leq t \\leq 1$. Then we have $F(\\mu) = f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - \\mu g(\\bm \\lambda, \\{A_i\\}_{i=1}^k)\n= f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - (t\\mu_1 + (1-t)\\mu_2)g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) = t(f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - \\mu_1g(\\bm \\lambda, \\{A_i\\}_{i=1}^k))\n+ (1-t)(f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - \\mu_2g(\\bm \\lambda, \\{A_i\\}_{i=1}^k))$.\nObviously, $f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - \\mu_1g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) \\leq F(\\mu_1)$ and \n$f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - \\mu_2g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) \\leq F(\\mu_2)$,\nwhich induces $F(t\\mu_1 + (1-t)\\mu_2) \\leq tF(\\mu_1)+(1-t)F(\\mu_2)$.\n}\n\\hfill$\\Box$\n\\end{lemma}\n\\begin{lemma}\n\\label{lemma2}\n$F(\\mu)$ is continuous.\n\\hfill$\\Box$\n\\end{lemma}\n\\begin{lemma}\n\\label{lemma3}\n$F(\\mu)$ is strictly monotonically decreasing, i.e., if $\\mu_1 < \\mu_2$, $F(\\mu_1) > F(\\mu_2)$.\n\\comment{\nProof: Suppose $(\\hat{\\bm \\lambda}, \\{\\hat{A}_i\\}_{i=1}^k)$ is the solution corresponding to $\\mu_2$. \nThen we have $F(\\mu_2) = f(\\hat{\\bm \\lambda}, \\{\\hat{A}_i\\}_{i=1}^k) - \\mu_2g(\\hat{\\bm \\lambda}, \\{\\hat{A}_i\\}_{i=1}^k) \n< f(\\hat{\\bm \\lambda}, \\{\\hat{A}_i\\}_{i=1}^k) - \\mu_1g(\\hat{\\bm \\lambda}, \\{\\hat{A}_i\\}_{i=1}^k) \\leq \n\\max_{\\bm \\lambda, \\{A_i\\}_{i=1}^k} f(\\bm \\lambda, \\{A_i\\}_{i=1}^k) - \\mu_1 g(\\bm \\lambda, \\{A_i\\}_{i=1}^k) = F(\\mu_1)$\n}\n\\hfill$\\Box$\n\\end{lemma}\n\\begin{lemma}\n\\label{lemma4}\n$F(\\mu) = 0$ has a unique solution.\n\\hfill$\\Box$\n\\end{lemma}\nDue to space limit, \nreaders are referred to~\\cite{dinkelbach1967nonlinear, stancu2012fractional} for the proofs of the theorem and lemmas.\n\nFrom Theorem~\\ref{theorem2}, we need to find\na $\\mu^*$ and its corresponding $({\\bm \\lambda^*}, {\\bm \\omega^*})$ such that $F(\\mu^*) = 0$.\n\\schain\\ does so by an iterative numerical method.\nIn each iteration, \\schain\\ computes a $\\mu$ and $(\\bml, \\bmo)$.\nLet $\\mu_i$, $(\\bml_i, \\bmo_i)$ be those computed in the $i$-th iteration.\n\\schain\\ first sets $\\mu_1 = 0$ and in each iteration, performs two steps:\n(Step 1:) Solve the NPP problem (Eq.~\\ref{eq:obj:trans7}) for $\\mu = \\mu_i$ and set $(\\bml_i, \\bmo_i)$ to be the solution found. \n(Step 2:) Set $\\mu_{i+1} = f(\\bml_i, \\bmo_i)/g(\\bml_i, \\bmo_i)$.\nNext, we show theoretical properties of this update process.\n\n\\noindent{\\bf Property 1:}\n$\\bm{F(\\mu_1) > 0}$. \nWithout loss of generality, we assume $f(\\bml, \\bmo) > 0$ and $g(\\bml, \\bmo) > 0$.\\footnote{One can show that the quantity (\\ref{eq:obj:trans4})\nis bounded below by $-2\\gamma$. We can add an arbitrary large constant to (\\ref{eq:obj:trans4}) to make it, and thus \n$f(\\bml, \\bmo)$ and $g(\\bml, \\bmo)$, positive.}\nNow, $F(\\mu_1)$ = $F(0)$ = $\\max_{\\bml, \\bmo} f(\\bm \\lambda, \\bm \\omega) > 0$.\n\n\\noindent{\\bf Property 2: if} $\\bm{F(\\mu_i) > 0}$ {\\bf then} \n$\\bm {0 \\leq F(\\mu_{i+1}) < F(\\mu_i)}$.\nSince $(\\bml_i, \\bmo_i)$ is the solution of the NPP problem for $\\mu = \\mu_i$ (Eq. \\ref{eq:obj:trans7}),\nwe have $f(\\bml_i, \\bmo_i) - \\mu_i g(\\bml_i, \\bmo_i) = F(\\mu_i) > 0$.\nHence, $\\mu_{i+1} = f(\\bml_i, \\bmo_i)/g(\\bml_i, \\bmo_i) > \\mu_i$.\nBy Lemma~\\ref{lemma3}, $F(\\mu_{i+1}) < F(\\mu_i)$.\nAlso, we have\n$F(\\mu_{i+1})$ = $\\max_{\\bm \\lambda, \\bm \\omega} ( f(\\bm \\lambda, \\bm \\omega) -\\mu_{i+1}g(\\bm \\lambda, \\bm \\omega))\n\\geq f(\\bm \\lambda_i, \\bm \\omega_i) - \\mu_{i+1} g(\\bm \\lambda_i, \\bm \\omega_i) = 0$.\n\nFrom the properties, we see that \\schain\\ starts with a positive $F(\\mu)$, whose value \nstays positive and decreases across iterations until it reaches 0.\nThe update procedure thus converges to the optimal values.\n%The process is repeated until a certain maximum number of iterations have been executed, or until $F(\\mu_i)$ becomes\n%negative for some iteration $i$. \n%In the latter case, due to Lemma~\\ref{lemma3}, we know that $\\mu^* \\in [\\mu_{i-1}, \\mu_i]$.\n%\\schain\\ then switches to the bisection method:\n%It computes $\\mu_{i+1} = (\\mu_{i-1} + \\mu_i)/2$, and repeats either with the interval $[\\mu_{i-1}, \\mu_{i+1}]$ or $[\\mu_{i+1}, \\mu_i]$,\n%depending on which interval contains $\\mu^*$. \nThe \\schain\\ algorithm is summarized in Algorithm~\\ref{alg}.\n\\begin{algorithm}\n\\begin{small}\n\\caption{SCHAIN}\n\\label{alg}\n\\begin{algorithmic}[1]\n%\\Require $G=(V, E)$, $A$, meta-paths $\\mathcal{P}$'s, $\\mathcal{X}_i$, $\\mathcal{L}$, $D$, $B$, $N_s$.\n\\Require $G$, $\\mathcal{M}$, $\\mathcal{C}$, $T_i$, $k$, $\\mathcal{PS}$.\n\\Ensure $\\mathfrak{C} = \\{C_1, ..., C_k\\}$\n\\State Compute similarity matrices $S_A$, $S_L$, and $S$\n\\State $t=0$, $\\Delta \\mathcal{J} = \\infty$\n%\\State Derive $S$ by Eq.~\\ref{eq:S}\n\\State $\\bm \\lambda = (\\frac{1}{|\\mathcal{PS}|}, ..., \\frac{1}{|\\mathcal{PS}|})$;\n$\\bm \\omega = (\\frac{1}{|A_i|}, ..., \\frac{1}{|A_i|})$\n%\\State Calculate $\\mathit{QS}(D)$\n\\While{$\\Delta \\mathcal{J} > \\epsilon$ or $t$ < max\\_iter}\n%\\State Construct $\\mathcal{M}$ and $\\mathcal{C}$\n\\LeftComment Step 1: Optimize $\\{\\bm z_r\\}_{r=1}^k$ given {$\\bm \\lambda$} and $\\bm \\omega$\n\\State Solve Eq.~\\ref{eq:max} to obtain real-relaxed $\\tilde{Z}$\n\\State Calculate $U=D^{-1/2}\\tilde{Z}$ and normalize it\n\\State Derive $\\{{\\bm z}_r\\}_{r=1}^k$ from $U$ by k-means\n\\LeftComment Step 2: Optimize {$\\bm \\lambda$} and $\\bm \\omega$ given $\\{${$\\bm z$}$_r\\}_{r=1}^k$\n\\State $j=1$; $\\mu_j = 0$\n%\\For{$j = 0$ to $F(\\mu)$ converges to 0}\n\\Repeat\n\\State Solve Eq.~\\ref{eq:obj:trans7} with $\\mu = \\mu_j$ to obtain ${\\bm \\lambda}_{j}$, ${\\bm \\omega}_{j}$\n\\State $\\mu_{j+1} = f({\\bm \\lambda}_{j}, {\\bm \\omega}_{j}) / g({\\bm \\lambda}_{j}, {\\bm \\omega}_{j})$; $j$++\n\\Until  $F(\\mu_{j+1})$ converges to 0%($j$ > max\\_iter2) %or ($F(\\mu_j) < 0$) \n%\\If{($F(\\mu_j) < 0$)}\n%\\State use bisection method to determine $\\bml$, $\\bmo$\n%\\Else \n%\\State $\\bml = \\bml_j$; $\\bmo = \\bmo_j$\n%\\EndIf\n\\State $\\Delta \\mathcal{J}$ = change in $\\mathcal{J}$ with the updated $\\{{\\bm z_r}\\}_{r=1}^k$, $\\bml$, $\\bmo$\n\\State $t$++\n%\\State $\\bm \\lambda^{t+1} = \\hat{\\bm \\lambda}^{j+1}$; $\\bm \\omega^{t+1} = \\hat{\\bm \\omega}^{j+1}$\n\\EndWhile\n\\State Decode $\\{C_r\\}_{r=1}^k$ from $\\{{\\bm z_r}\\}_{r=1}^k$\n\\State \\Return $\\mathfrak{C} = \\{C_1, ..., C_k\\}$\n\\end{algorithmic}\n\\end{small}\n\\end{algorithm}\n\n\n\n\n\n\n\\comment{\n\nIn conclusion, to solve a NPFP problem, we need to first convert it into a NPP problem. \nTo solve the NPP problem, it involves in two steps. The first step is to select a $\\mu$ value and the second one is to solve the maximization problem in\nEq.~\\ref{eq:obj:trans7} to get $(\\bm \\lambda, \\bm \\omega)$ and $F(\\mu)$.\nSince the final aim is to find the $\\mu$ which makes $F(\\mu) = 0$,\nwe adopt an iterative two-step update strategy to perform optimization.\nStep 1: given a $\\mu$, solve the maximization problem in Eq.~\\ref{eq:obj:trans7} to get $(\\bm \\lambda, \\bm \\omega)$ and the $F(\\mu)$ value.\nStep 2: given $(\\bm \\lambda, \\bm \\omega)$, calculate a new $\\mu$ value.\nDue to the monotonically decreasing property of $F(\\mu)$,\nwe can start from a $\\mu$ which makes $F(\\mu) > 0$. \n%and $F(0) = \\max_{\\bm \\lambda, \\bm \\omega} f(\\bm \\lambda, \\bm \\omega) > 0$, \n%we can start from $\\mu = 0$. \nAfter $(\\bm \\lambda, \\bm \\omega)$ is calculated, according to Proposition~\\ref{prop1}, we assign $\\mu = f(\\bm \\lambda, \\bm \\omega)/g(\\bm \\lambda, \\bm \\omega)$.\nThe iteration repeats until $F(\\mu) = 0$.\n\nSince $||\\bm \\lambda||^2 \\leq 1$ and $||\\bm \\omega||^2 \\leq 1$,\nwe usually add a term $2\\gamma$ to the end of Eq.~\\ref{eq:obj:trans4} \nto ensure $-\\gamma(||\\bm \\lambda|| ^ 2 + ||\\bm \\omega||^2) + 2\\gamma \\geq 0$.\nOn the one hand, the added term is irrelevant to $\\bm \\lambda$ and $\\bm \\omega$,\nso it will not influence the optimization result.\nOn the other hand, it can ensure the derived $f(\\bm \\lambda, \\bm \\omega) > 0$ in Eq.~\\ref{eq:obj:trans5}.\nSince $F(0) = \\max f(\\bm \\lambda, \\bm \\omega) > 0$,\nwe can safely start from $\\mu = 0$.\n\n\n\\begin{proposition}\n\\label{prop1}\nSuppose $F(\\hat \\mu) > 0$ and $(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega})$ solves Eq.~\\ref{eq:obj:trans7} corresponding to $\\hat \\mu$, \nthen $f(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega})/g(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega}) > \\hat \\mu$.\n\nProof: $F(\\hat \\mu) = \\max_{\\bm \\lambda, \\bm \\omega} f(\\bm \\lambda, \\bm \\omega) - \\hat \\mu g(\\bm \\lambda, \\bm \\omega) =\nf(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega}) - \\hat \\mu g(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega}) > 0$.\n$g$ derives from Eq.~\\ref{eq:obj:trans4}, as the denominator,\n$g(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega}) > 0$,\nso we have $f(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega})/g(\\hat{\\bm \\lambda}, \\hat{\\bm \\omega}) > \\hat \\mu$.\n\\hfill$\\Box$\n\\end{proposition}\n\nBased on the above iterative optimization method, the model will finally converge.\nProofs are listed as follows.\n\\begin{theorem}\n\\label{theorem3}\nThe proposed model finally converges.\n\nProof: The objective is to minimize Eq.~\\ref{eq:obj:trans:reg}, which includes three parts.\nFirst, $0 \\leq \\bm{z}_i^T(D-S)\\bm{z}_i / \\bm{z}_i^TD\\bm{z}_i \\leq 1$.\nSecond, for $-(\\bm{z}_i^TW\\circ S\\bm{z}_i / \\bm{z}_i^TD\\bm{z}_i)$, we consider two extreme cases:\nif all the object pairs in cluster $i$ are in the must-link set $\\mathcal{M}$, then $0 \\leq \\bm{z}_i^TW\\circ S\\bm{z}_i / \\bm{z}_i^TD\\bm{z}_i \\leq 1$;\nif all the object pairs in cluster $i$ are in the cannot-link set $\\mathcal{C}$, then $-1 \\leq \\bm{z}_i^TW\\circ S\\bm{z}_i / \\bm{z}_i^TD\\bm{z}_i \\leq 0$,\nso $-1 \\leq \\bm{z}_i^TW\\circ S\\bm{z}_i / \\bm{z}_i^TD\\bm{z}_i \\leq 1$, i.e., $-1 \\leq -(\\bm{z}_i^TW\\circ S\\bm{z}_i / \\bm{z}_i^TD\\bm{z}_i) \\leq 1$.\nThird, since $\\gamma \\geq 0$, $\\gamma (||\\bm \\lambda||^2 + ||\\bm \\omega||^2)$ is convex, the constraints on $\\bm \\lambda$ and $\\bm \\omega$ are \nalso convex, so  \n%$\\sum_{i=1}^{|\\mathcal{PS}|}\\lambda_i = 1$, $\\sum_{i=1}^{|\\mathcal{PS}|}\\lambda_i = 1$,$\\lambda_i \\geq 0$ and $\\lambda_j \\geq 0$,\nit must have a minimum value.\nIn conclusion, Eq.~\\ref{eq:obj:trans:reg} has a lower bound.\n\nFurthermore, the iterative optimization method, either optimizing $\\{${\\boldmath $z$}$_i\\}_{i=1}^k$ or \nupdating $\\bm \\lambda$ and $\\bm \\omega$, always decreases the objective function, so the convergence is guaranteed.\n\\hfill$\\Box$\n\\end{theorem}\n\n}\n\n\n\n\n\n\n\n", "meta": {"hexsha": "7dfc9ac7a5b83d805392c87ec6592fa8695099e0", "size": 21177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/HINGCN/tex/optimization.tex", "max_stars_repo_name": "dingdanhao110/HINGCN", "max_stars_repo_head_hexsha": "281b73c03bd3b00e35bce4c5e1c27076233555e4", "max_stars_repo_licenses": ["MIT"], "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/HINGCN/tex/optimization.tex", "max_issues_repo_name": "dingdanhao110/HINGCN", "max_issues_repo_head_hexsha": "281b73c03bd3b00e35bce4c5e1c27076233555e4", "max_issues_repo_licenses": ["MIT"], "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/HINGCN/tex/optimization.tex", "max_forks_repo_name": "dingdanhao110/HINGCN", "max_forks_repo_head_hexsha": "281b73c03bd3b00e35bce4c5e1c27076233555e4", "max_forks_repo_licenses": ["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.5, "max_line_length": 361, "alphanum_fraction": 0.6395617887, "num_tokens": 8339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6698425658675029}}
{"text": "\\section{Numerical Results}\n\\label{sec:numerical_results}\n\n\\begin{frame}[c]{Synthetic Asset}\n\t\\begin{block}{Goal}\n\t\tEvaluate different RL algorithms in a controlled environment, i.e.  on a synthetic asset with profitably tradable features \n\t\\end{block}\n\tThe synthetic asset price is given by\n\t\\begin{equation*}\n\t\tZ_t = \\exp\\left(\\frac{z_t}{\\max_t z_t - \\min_t z_t}\\right)\n\t\\end{equation*}\n\twhere $\\{z_t\\}$ is a random walk with autoregressive trend $\\{\\beta_t\\}$\n\t\t\\begin{equation*}\n\t\t\t\\begin{split}\n\t\t\t\tz_t &= z_{t-1} + \\beta_{t-1} + \\kappa \\epsilon_t\\\\\n\t\t\t\t\\beta_t &= \\alpha \\beta_{t-1} + \\nu_t\\\\\n\t\t\t\\end{split}\n\t\t\\end{equation*}\n\\end{frame}\n\n\\begin{frame}[c]{Convergence of RL algorithms}\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[height=5cm,width=1.0\\textwidth]{Images/6_0_single_synthetic_neutral_convergence}\n\\end{figure}\n\\end{frame}\n\n\n\\begin{frame}[c]{Backtest Performance of the Trading Strategies Learned}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[height=6cm,width=1.0\\textwidth]{Images/6_1_single_synthetic_neutral_performance}\n\\end{figure}\n\\end{frame}\n\n\\begin{frame}[c]{Impact of Transaction Costs}\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[height=3cm,width=1.0\\textwidth]{Images/6_2_impact_transaction_costs}\n\\end{figure}\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[height=3cm,width=1.0\\textwidth]{Images/6_3_impact_short_selling_fees}\n\\end{figure}\n\\end{frame}\n\n\n", "meta": {"hexsha": "6db6ecffc3cbf18442c2c23d372b68109646e889", "size": 1400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pacs/Presentation/Sections/6_numerical_results.tex", "max_stars_repo_name": "AmineAboussalah/Thesis", "max_stars_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 80, "max_stars_repo_stars_event_min_datetime": "2016-06-13T15:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T23:47:13.000Z", "max_issues_repo_path": "Pacs/Presentation/Sections/6_numerical_results.tex", "max_issues_repo_name": "pnecchi/Thesis", "max_issues_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Pacs/Presentation/Sections/6_numerical_results.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": 29.1666666667, "max_line_length": 125, "alphanum_fraction": 0.7392857143, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.669842564450934}}
{"text": "\\section{Construction of icosahedral grid}\nThe icosahedral geodesic grid is constructed as follows:\n\\begin{enumerate}\n  \\item Each side of the icosahedron whose vertices are on a unit sphere are\n    projected onto the sphere. This grid is called 'glevel 0' gri. (Fig. \\ref{fig:scale-gm_grid}(a)).\n  \\item By connecting the mid-points of the geodesic arcs, four\n      sub-trianbles are generated from each of the 'glevel 0' triangles. This\n      grid is called 'glevel 1' grid (Fig. \\ref{fig:scale-gm_grid}(b)).\n  \\item By iterating this process $l$-th times, a grid structure of 'glevel l'\n    is obtained. \n\\end{enumerate}\nThe total number $N_p$ of triangle verrtices with the glevel $l$ grid can be\ndescribed as \n\\begin{equation}\n  N_p(l) = 10 \\times 4^l + 2 \\nonumber\n\\end{equation}\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=10cm]{../../figure/grid_structures}\n%    \\begin{tabular}{cc}\n%    \\includegraphics[width=5cm]{../../figure/grid0} &\n%    \\includegraphics[width=5cm]{../../figure/grid1} \\\\\n%    \\includegraphics[width=5cm]{../../figure/grid2} &\n%    \\includegraphics[width=5cm]{../../figure/grid3}\n%    \\end{tabular}\n    \\caption{Grid structure (grid division levels 0-3).}\n    \\label{fig:scale-gm_grid}\n  \\end{center}\n\\end{figure}\n\n\n\\section{Control volume}\nAll the  variables are defined at the vertices of triangles. This arrangement\nis so-called 'Arakawa-A' type grid. Since the descritization of equations is\nbased on the finite volume method, it is necessary for the control volume to\nbe defined. The schematic figure of control volume is shown in Fig. \\ref{fig:scale-gm_control_volume}. The\nred points of $P_0$ up to $P_6$ are the vertices of triangles, Green points\nremained are defined as gravitational center of the corresponding\ntriangles. The control volume for the point $P_0$ is defined as the polygon\nconstructed by connecting the gravitational centers of the neighbouring\ntriangles. The shape of control volume in the almost region is hexagon, while\nit is pentagon at only 12 points inherited from glevel 0.\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=5cm]{../../figure/control_volume}\n    \\caption{Schematic figure of the control volume}\n    \\label{fig:scale-gm_control_volume}\n  \\end{center}\n\\end{figure}\n\n\n\\section{Modification of icosahedral grid}\nThe construction method of control volume as described in the previous\nsubsection has one problem as regards to accuracy. From the viewpoints of\naccuracy, any variable-defined point should be the gravitational center of\ncontrol volume. However, it is not so in the above construction. So, we\ndevelop a new grid by modifying the default grid as follows.\n\\begin{enumerate}\n  \\item After the construction of first control volume by the previous method,\n    variable-defined points are moved to the gravitaitonal center of control\n    volume. This process is shown in Fig. \\ref{fig:scale-gm_modified_control_volume}. The blue points are new\n    locations of variable-defined points.\n  \\item By using the new location of variable-defined points, next\n    variable-defined points are obtained in the same manner.\n  \\item This iteration is reported until the variable-defined points is\n    converged.\n\\end{enumerate}\nWhether grid is converged or not has not been yet mathematically proved, but\npractically, it can be converged up to glevel 8. Those grids are called glevel\n$l$M.\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=5cm]{../../figure/modified_control_volume}\n    \\caption{Schematic figure of modified grid and control volume}\n    \\label{fig:scale-gm_modified_control_volume}\n  \\end{center}\n\\end{figure}\n\n\nFigure \\ref{fig:scale-gm_control_volume_comparison} gives the default grid and modified one for the grid division level\n3. As shown in this figure, the grid interval around vertices of icosahedron\nslightly decreases by the modification. This lead to the increase of\nmaximum/minimum ratio of grid interval. \n%The maximum/minimum ratio of grid\n%interval against grid division level is shown in Fgi. XX, where grid interval\n%$d$ is defined as the root of control volume area. It can be guessed from this\n%figure that even in the glevel 11M grid the value of $d_max/d_min$ will be\n%about 3, so it is enough acceptable. \n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=5cm]{../../figure/control_volume_comparison}\n    \\caption{Comparison of default and modiified grids. The perspective\n      center of the figures is located at the north pole.}\n    \\label{fig:scale-gm_control_volume_comparison}\n  \\end{center}\n\\end{figure}\n\n\n\n\\section{Parallelization}\n\\subsection{Region division}\nThe concept of region division level is introduced as follows.\n\\begin{enumerate}\n  \\item By connecting two neighboring triangles of spherical icosahedron, ten\n    rectangles are constructed as Fig. \\ref{fig:scale-gm_region_structure}(a). This construction is called 'rlevel\n    0.'\n  \\item For each rectangle, four sub-rectangles are generated by connecting\n    the diagonal mid-grid-points (Fig. \\ref{fig:scale-gm_region_structure}(b)). This construction is called\n    'rlevel 1.'\n  \\item This process is repeated until the desirable regions are obtained.\n\\end{enumerate}\nThis example of grid structure in a region is shown in Fig. \\ref{fig:scale-gm_grid_structure}. Although the\ngrid is not based on rectangles but triangles, it is like a\nstructured-grid. On the other words, all variables can be described by\nFortran's 2 dimensional array. This is an advantage for vector super-computing.\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=10cm]{../../figure/region_structure}\n    \\caption{Region structure (region division levels 0-3)}\n    \\label{fig:scale-gm_region_structure}\n  \\end{center}\n\\end{figure}\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=5cm]{../../figure/grid_structure}\n    \\caption{Grid structure of one region.}\n    \\label{fig:scale-gm_grid_structure}\n  \\end{center}\n\\end{figure}\n\n\n\\subsection{Parallelization}\nIn the parallel computing, the regions made by the above method are managed by\nsome processes. One of the simples solutions of parallilization is that one\nprocess manages one region. However, it is lacking of flexibility. We design\nthe management of region as follows.\n\\begin{enumerate}\n  \\item Any process can manage any nubmer and any location of regions.\n  \\item Number of managed process is not necessary to be constant.\n\\end{enumerate}\nThis design concept makes the load of each CPU be uniform.\n\nWhen two neigouring regions are not managed by the same process, the excahnge\nof boundary conditions is done using MPI communication. When two neighboring\nregions are managed by the same process, it is done by copying the memory of\nboundary.\n\nFigure \\ref{fig:scale-gm_parallel} shows the schematic figure of region management. This figure is an\nexpansion for rlevel 1. Total amount of region is forty and ten processes\nmanage those regions. Each of the processes manages the region marked by same\ncolor. For example, regions A, B, C, and D are managed by the same process. It\nis configured for each fo processes to manage the regions from pole and\nequatorial regions. By this configuration, locad imbalance due to the\natmospheric physical process would be avoided.\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[width=5cm]{../../figure/parallel}\n    \\caption{Schematic figure of parallelization.}\n    \\label{fig:scale-gm_parallel}\n  \\end{center}\n\\end{figure}\n\n\n\n\\subsection{Note}\n \\begin{itemize}\n   \\item g-level (grid level): number of subdivision times of the grid from the original icosahedron.\n         the number starts from 1, we recommend to use the number larger than 4.\n   \\item r-level (region level): number of subdivision times of the region(tile)\n         from the original icosahedron. When r-level = 0, we have ten regions(tiles).\n         At that time, the number of available maximum MPI processes is ten.\n \\end{itemize}\n\n\\textcolor{red}{[さらにHALOを説明する図もある方が良い]}\n\n", "meta": {"hexsha": "4ed9a3bb5f5c0b45d817c1c4b2e4e613f0e695c9", "size": 7988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/users-guide/en/setting_gm_level.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/users-guide/en/setting_gm_level.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/users-guide/en/setting_gm_level.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": 43.650273224, "max_line_length": 119, "alphanum_fraction": 0.7606409614, "num_tokens": 2032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.669842564450934}}
{"text": "\n\n\\input{6DL/DoubleFourier}\n%\\section{Asymptotic convergence estimates for $L^2$ norm}\n%\\subsection\n\n \n\\iffalse\nThen we propose the next assumption on $\\sigma$\n\\begin{assumption}\\label{assump:sigma}[Siegle \\& Xu 2020]\n\tLet $\\sigma \\in L^{\\infty}(\\Omega)$ and there exists $p> 1$  such that\n\t\\begin{equation}\\label{key}\n\t|\\sigma(t)| \\le (1+|t|)^{-p}.\n\t\\end{equation}\n\\end{assumption}\n\n\nThen we have the next important lemma about the estimate of $\\rho(\\theta)$.\n\\fi\n\n\\begin{theorem}\\label{approximation_rate_theoreml2}\n Let $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain. If the activation function $\\sigma $ is non-zero and satisfies the polynomial decay condition \n$$\n\\sigma(t) \\le (1+|t|)^{-p}\n$$\nfor some $p>1$, then for any $n \\ge 1$, there exist \n\t$\\theta_i = (\\omega_i, b_i) \\in \\mathbb{R}^{d+1}$ such that\n\t\\begin{equation}\\label{key}\n\t\\|u-u_n\\|_{L^{2}(\\Omega)} \\lesssim n^{-\\frac{1}{2}}\\|u\\|_{\\mathcal B^1(\\Omega)},\n\t\\end{equation}\n\twhere\n\t\\begin{equation}\\label{key}\n\tu_n(x) = \\frac{\\|\\rho\\|_{L^1}}{n} \\sum_{i=1}^n \\beta_i {\\sigma}(a^{-1}\\omega_i\\cdot x + b_i) %{\\rm Re} \\left( \\hat f(\\omega_i)e^{iab}\\right) \n\t\\in \\dnn(\\sigma, n).\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\\label{approximation_rate_theorem}\n Let $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain. If the activation function $\\sigma\\in W^{m,\\infty}(\\mathbb{R})$ is non-zero and satisfies the polynomial decay condition \n \\begin{equation}\\label{growth_condition}\n  |\\sigma^{(k)}(t)| \\leq C_p(1 + |t|)^{-p}\n \\end{equation}\n for $0\\leq k\\leq m$ and some $p > 1$, we have\n \\begin{equation}\n  \\inf_{u_n\\in \\dnn(\\sigma,n)}\\|u-u_n\\|_{H^m(\\Omega)} \\leq |\\Omega|^{\\frac{1}{2}}C(p,m,\\text{\\normalfont diam}(\\Omega),\\sigma)n^{-\\frac{1}{2}}\\|u\\|_{\\mathcal{B}^{m+1}(\\Omega)},\n \\end{equation}\n for any $u\\in \\mathcal{B}^{m+1}$.\n\\end{theorem}\nBefore we proceed to the proof, we discuss how this bound depends on\nthe dimension $d$. We first note that $|\\Omega|$ may in a sense depend\non the dimension, as the measure may be exponentially large in high\ndimensions. However, bounding the $H^m$ error over a larger set is\nalso proportionally stronger. This can be seen by noting that dividing\nby the $|\\Omega|^\\frac{1}{2}$ factor transforms the left hand side\nfrom the total squared error to the average squared error.\n\nThe dimension dependence of this result is a consequence of how the\nBarron norm behaves in high dimensions. This issue is discussed in\n\\cite{barron1993universal}, where the norm $\\|\\cdot\\|_{\\mathcal{B}^1}$\nis analyzed for a number of different function classes. A particularly\nrepresentative result found there is that $H^{\\frac{d}{2}+2}\\subset\n\\mathcal{B}^1$. This shows that sufficiently smooth functions have\nbounded Barron norm, where the required number of derivatives depends\nupon the dimension. It is known that approximating functions with such\na dimension dependent level of smoothness can be done efficiently\n\\cite{petrushev1998approximation, kainen2007sobolev}. However, the\nBarron space $\\mathcal{B}^1$ is significantly larger that\n$H^{\\frac{d}{2}+2}$, in fact we only have $\\mathcal{B}^1 \\subset H^1$\nby lemma \\ref{smoothness-lemma}. The precise properties of the Barron\nnorm in high dimensions are an interesting research direction which\nwould help explain exactly how shallow neural networks help alleviate\nthe curse of dimensionality.\n\n\nNext we consider the proof for Theorem \\ref{approximation_rate_theoreml2}. Recall\n \\begin{equation} \nu(x) =  \\int_{\\mathbb{R}^d}\\int_\\mathbb{R} k(x,\\theta) dbd\\omega,\\quad \n  k(x,\\theta)= \\frac{1}{ \\hat{\\sigma}(a)}\n  \\sigma\\left(a^{-1}{\\omega}\\cdot\n    x+b\\right)\\hat{u}(\\omega)e^{-2\\pi iab}. \n \\end{equation}\nwhere $\\theta=(\\omega, b)$. \n Define \n\\begin{equation}\\label{key}\nh(\\omega, b) = \\max_{x\\in \\Omega}|\\sigma(a^{-1}\\omega\\cdot x+b)|, \\quad \\mbox{ and }\\quad \\rho(\\theta) = h(\\omega, b)  |\\hat u(\\omega)|.\n\\end{equation}\nIf $ \\rho(\\theta) \\in L^1(\\mathbb{R}^{d+1})$, then $f(x)=\\mathbb{E}(k(x,\\theta))$. By the Monte Carlo method in Theorem \\ref{MC}, it is sufficient to prove $ \\rho(\\theta) \\in L^1(\\mathbb{R}^{d+1})$. \n\\begin{lemma}\nLet $\\sigma \\in L^{\\infty}(\\Omega)$ and there exists $p> 1$  such that\n\t\\begin{equation}\\label{key}\n\t|\\sigma(t)| \\le (1+|t|)^{-p},\n\t\\end{equation}\nthen we have \n$$\n\\rho(\\theta) \\in L^1(\\mathbb{R}^{d+1}).\n$$\n\\end{lemma}\n\\begin{proof}\nNote that\n\\begin{equation}\n\\label{eq:4}\n\\begin{aligned}\n|k(x,\\theta)| &\\le \\frac{1}{ |\\hat \\sigma(a)|} \\max_{x\\in \\Omega} |\\sigma\\left(a^{-1}{\\omega}\\cdot\nx+b\\right) | |\\hat u(\\omega)|  \\\\\n&\\le  \\frac{1}{ |\\hat \\sigma(a)|}  h(\\omega, b)|\\hat u(\\omega)|   =  \\frac{1}{  |\\hat \\sigma(a)|} \\rho(\\theta)\n\\end{aligned},\n\\end{equation}\nand\n\t\\begin{equation}\\label{key}\n\t\\|\\rho\\|_{L^1(\\mathbb{R}^{d+1})} = \\int_{\\mathbb{R}^{d+1}} |\\rho(\\theta)|d\\theta = \\int_{\\mathbb{R}^d} \\left( \\int_{\\mathbb{R}} h(\\omega, b)db\\right) |\\hat u(\\omega)| d\\omega.\n\t\\end{equation}\nNote that\n\\begin{equation}\\label{key}\n|a^{-1}\\omega \\cdot x + b| \\ge |b| - |a^{-1}\\omega \\cdot x | \\ge  |b| - |a^{-1}||\\omega| | x|  \\ge |b| - |a^{-1}| |\\omega | R,\n\\end{equation}\nwhere \n\\begin{equation}\\label{key}\nR = \\max_{x\\in \\bar \\Omega} |x|,\n\\end{equation}\nas $\\Omega$ is bounded.\nThus\n\\begin{equation}\\label{key}\n|a^{-1}\\omega \\cdot x + b| \\ge \\max(0, |b| - \\frac{R}{|a|} |\\omega |).\n\\end{equation}\nThat is to say\n\\begin{equation}\\label{key}\nh(\\omega, b) \\le (1+  \\max(0, |b| - \\frac{R}{|a|}|\\omega|))^{-p},\n\\end{equation}\n\tThen we calculate\n\t\\begin{equation}\\label{eq_775}\n\t\\begin{split}\n\t\\int_\\mathbb{R} h(\\omega,b)db& \\le \\int_{|b|\\leq \\frac{R|\\omega|}{|a|}} db + 2\\int_{b > \\frac{R\\|\\omega\\|}{|a|}} \\left(1 + b - \\frac{R|\\omega|}{|a|}\\right)^{-p}db \\\\\n\t& =~2R|a|^{-1}|\\omega| + 2\\left[(1-p)^{-1}\\left(1 + b - \\frac{R|\\omega|}{|a|}\\right)^{1-p}\\right]_{\\frac{R|\\omega|}{|a|}}^\\infty \\\\\n\t&=~2R|a|^{-1}|\\omega| + \\frac{2}{p-1}\\leq C_1(p,\\text{\\normalfont diam}(\\Omega),\\sigma) (1 + |\\omega|).\n\t\\end{split}\n\t\\end{equation}\n\tThus, we have\n\t\\begin{equation}\\label{key}\n\t\t\\|\\rho\\|_{L^1(\\mathbb{R}^{d+1})} \\le C_1\\int_{\\mathbb{R}^d} (1+|\\omega|)|\\hat u(\\omega)| d\\omega.\n\t\\end{equation}\n\\end{proof}\nHere we denote \n\\begin{equation}\\label{key}\n\\|u\\|_{\\mathcal B^1(\\Omega)} = \\int_{\\mathbb{R}^d} (1+\\|\\omega\\|)|\\hat u(\\omega)| d\\omega,\n\\end{equation}\nnamely\n\\begin{equation}\\label{key}\n\\|\\rho\\|_{L^1(\\mathbb{R}^{d+1})} \\lesssim \\|u\\|_{\\mathcal B^1(\\Omega)}.\n\\end{equation}\n\n \nThese two theorems include many popular activation functions, such as the rectified linear units \\cite{nair2010rectified} and logistic sigmoid activation functions. Below we provide a table listing some well-known activation functions to which this theorem applies.\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c|c| } \n \\hline\n Activation Function & $\\sigma(x)$ & Maximal $m$ & $n_0$ & $\\nu(x)$ \\\\\n \\hline\n Sigmoidal (Logistic) & $(1 + e^{-x})^{-1}$ & $\\infty$ & $2$ & $\\sigma(x+1) - \\sigma(x)$ \\\\\n \\hline\n\n Arctan & $\\arctan(x)$ & $\\infty$ & $2$ & $\\sigma(x+1) - \\sigma(x)$ \\\\ \n \\hline\n Hyperbolic Tangent & $\\tanh(x)$ & $\\infty$ & $2$ & $\\sigma(x+1) - \\sigma(x)$ \\\\\n \\hline\n SoftPlus \\cite{glorot2011deep} & $\\log(1 + e^x)$ & $\\infty$ & $4$ & $\\sigma(x+1) + \\sigma(x - 1) - 2\\sigma(x)$ \\\\\n \\hline\n ReLU\\cite{nair2010rectified} & $\\max(0,x)$ & $1$ & $4$ & $\\sigma(x+1) + \\sigma(x - 1) - 2\\sigma(x)$ \\\\\n \\hline\n  Leaky ReLU\\cite{maas2013rectifier} & $\\epsilon x + (1-\\epsilon)\\max(0,x)$ & $1$ & $4$ & $\\sigma(x+1) + \\sigma(x - 1) - 2\\sigma(x)$ \\\\\n \\hline\n $k$-th power of ReLU & $[\\max(0,x)]^k$ & $k$ & $k+1$ & $\\sum_{i=0}^k(-1)^i\\binom{k}{i} \\sigma(x - \\lfloor k/2 \\rfloor + i)$\\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n \nThe bound depends on\nthe dimension $d$. We first note that $|\\Omega|$ may in a sense depend\non the dimension, as the measure may be exponentially large in high\ndimensions. However, bounding the $H^m$ error over a larger set is\nalso proportionally stronger. This can be seen by noting that dividing\nby the $|\\Omega|^\\frac{1}{2}$ factor transforms the left hand side\nfrom the total squared error to the average squared error.\n\n\n\n\n\n\n\n\\iffalse\n\\newpage\n\n\\subsection{Comparison with linear finite element method}\nWe can briefly have the next two asymptotic approximation results for deep neural networks and adaptive\nlinear finite element methods:\n\\begin{description}\n\t\\item[Neural Network (NN)] \n\t\\begin{equation}\\label{key}\n\t\\inf_{f_n \\in \\dnn(\\sigma,n)} \\|f-f_n\\|_{L^{2}(\\Omega)} \\lesssim  n^{-\\frac{1}{2}}\\|f\\|_{\\mathcal B^1(\\Omega)},\n\t\\end{equation}\n\twhere $nd$ is the number of parameters.\n\t\\item[Finite Element (FE)] \n\t\\begin{equation}\\label{key}\n\t\\inf_{f_n \\in V_n} \\|f-f_n\\|_{L^{2}(\\Omega)} \\lesssim  n^{-\\frac{2}{d}}\\|f\\|_{\\ast},\n\t\\end{equation}\n\twhere\n\t\\begin{equation}\\label{key}\n\tV_n: \\text{linear finite element space of}~ n-\\text{elements},\n\t\\end{equation}\n\tand $\\|f\\|_{\\ast}$ is some Besov norm. \n\\end{description}\nA direct observation for the asymptotic approximation error is that :\n\\begin{equation}\\label{key}\n(\\frac{n}{d})^{-\\frac{1}{2}} << n^{-\\frac{2}{d}},\n\\end{equation}\nif $d >> 1$ with respect to the umber of parameters. However, in the future  we will show that \n\\begin{equation}\\label{key}\n{\\rm DNN}({\\rm ReLU}) = \\text{Linear FE},\n\\end{equation}\nor we can say that DNN with ReLU activation function is a different way to parametrize linear \nfinite element space.\n\\fi\n", "meta": {"hexsha": "c1e917736a49ddd789021b815c8b7fe975c67a45", "size": 9248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Barron-L2.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/Barron-L2.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/Barron-L2.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.2857142857, "max_line_length": 265, "alphanum_fraction": 0.6559256055, "num_tokens": 3422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.6698382636756025}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n%\\usepackage[scientific-notation=true]{siunitx}\n\\usepackage{tabularx}\n\\newcommand{\\D}{\\displaystyle}\n\\begin{document}\n\\section{Method 1}\nSuppose we take time series data points, N (indexed by a) from each of S species. \n$$\nX_i^a\\rightarrow X^1= \n\\begin{bmatrix}\n           x_{1}^1 \\\\\n           x_{2}^1 \\\\\n           \\vdots \\\\\n           x_{S}^1\n \\end{bmatrix}\n ,X^2=\n \\begin{bmatrix}\n           x_{1}^2 \\\\\n           x_{2}^2 \\\\\n           \\vdots \\\\\n           x_{S}^2\n \\end{bmatrix} \n ....\n ,X^N=\n \\begin{bmatrix}\n           x_{1}^N \\\\\n           x_{2}^N \\\\\n           \\vdots \\\\\n           x_{S}^N\n \\end{bmatrix}\n$$\n\nGoal: Maximizing$ P(X|\\mu,\\sigma^2,d) $\n\\hfill\\break\n\\hfill\\break\nAssumptions:\n\\hfill\\break\n\\hfill\\break\n1). A is a symmetric S by S matrix \\hfill\\break\n2). $A_{ij}=\\dfrac{\\mu}{S}+B_{ij}$, where $B_{ij}~N(0,\\dfrac{\\sigma^2}{S}), i.e. A_{ij}~N(\\dfrac{\\mu}{S}, \\dfrac{\\sigma^2}{S})$\n3). $A_{ii}= -d+\\dfrac{\\mu}{S}$\n4). For A sufficiently large, the determinants of A for different random entries are similar so we use the average determinat of A in place of A. $<detA>=D(\\mu,\\sigma^2,d)$\n\\hfill\\break\nSince, $x_i$ are independent, the average probability of observing $x_i$ given $\\mu,\\sigma,d$:\n$$\nP(x|\\mu, \\sigma^2,d)=\\int dA \\prod(P(x^a|A)P(A|\\mu,\\sigma^2,d)\n$$\nwe can pull the product out and distribute it to each term\n$$\n=\\int (\\prod_{i<j}(dA_{ij})\\dfrac{(detA)^{N/2}}{(2\\pi)^{NS/2}} exp(\\dfrac{1}{2}\\sum_{a=1}^{N}\\sum_{ij}^S x_i^a A_{ij} x_j^a) P(A|\\mu,\\sigma^2,d)\n$$\nGiven our assumptions:\n$$\n=\\dfrac{<detA>^{N/2}}{(2\\pi)^{NS/2}} \\int (\\prod_{i<j}dB_{ij}) exp(\\dfrac{1}{2}\\sum_{a=1}^N(-d \\sum(x_i^a)^2 +\\dfrac{\\mu}{S} \\sum_{ij} x_i^a x_j^a + \\sum_{i<j}x_i B_{ij} x_j)  P(B|\\sigma^2))\n$$\npulling out the terms seperate from $B_{ij} $\n$$\n=\\dfrac{<detA>^{N/2}}{(2\\pi)^{NS/2}}exp(\\dfrac{-d}{2}\\sum_{a=1}^N\\sum_{i=1}^S(x_i^a)^2 + \\dfrac{\\mu}{2S}\\sum_{a=1}^N(\\sum_{i=1}^S x_i^a)^2 \\times \\int((\\prod_{ij}dB_{ij})exp(\\sum_{a=1}^N\\sum_{i<j} x_i^a B_{ij}x_j^a)exp(- \\sum_{i<j} \\dfrac{B_{ij}^2}{2\\sigma ^2/S}) \n$$\n$$\n\\times(\\sqrt{\\dfrac{S}{2\\pi}}\\dfrac{1}{\\sigma}))\n$$\nThe firt part of the integral becomes\\hfill\\break\n$$\\prod_{i<j}dB_{ij}\\rightarrow \\prod_{i<j}exp(\\dfrac{\\sigma^2}{2S}(\\sum_{a=1}^N x_i^a x_j^a)^2)=exp(\\dfrac{\\sigma^2}{4S} \\sum_{ij}\\sum_a x_i^a x_j^a \\sum_b x_i^b x_j^b)$$\\hfill\\break\nThen we can condense the summations and obtain:\n$$ exp(\\dfrac{\\sigma^2}{4S}\\sum_{ab}(\\sum_i x_i^a x_i^b )^2)$$\nThe portion in the exponent becomes\\hfill\\break\n\n$$\\prod_{i<j} exp(-\\dfrac{B_{ij}^2}{2\\sigma^2/S}+\\sum_{a=1}^N x_i^a B_{ij} x_j^a)\\sqrt{\\dfrac{S}{2\\pi}}\\dfrac{1}{\\sigma}$$\n\\hfill\\break\nAfter rearranging the terms we get \\hfill\\break\n$$\\prod_{i<j} dB_{ij} \\sqrt{\\dfrac{S}{2\\pi}}\\dfrac{1}{\\sigma}exp(-\\dfrac{B_{ij}^2}{2\\sigma^2/S}+\\sum_{a=1}^N x_i^a B_{ij} x_j^a)$$\nLet $y=B_{ij}, \\tau=\\dfrac{\\sigma}{\\sqrt{S}}, z=\\sum_{a=1} x_i^a x_j^a$\n\\hfill\\break\\hfill\\break\nThen our integral becomes :\n$$\n\\int dy \\sqrt{\\dfrac{1}{2\\pi}}\\dfrac{1}{\\tau}exp(\\dfrac{-y^2}{2\\tau ^2}+yz)\n$$\nWhich when solved, simplifies to:\n$$\nexp(\\dfrac{\\tau ^2 z^2}{2})\n$$\nNow let us denote $P(x|\\mu,\\sigma,d)$ as P:\n$$\nP=D\\times exp(\\dfrac{-d}{2}\\sum_{a=1}^N\\sum_{i=1}^S(x_i^a)^2 + \\dfrac{\\mu}{2S} \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2+\\dfrac{\\sigma^2}{4S}\\sum_{ab}(\\sum_i x_i^a x_i ^b)^2)\n$$\n$$\n\\dfrac{2}{N}logP=logD-\\dfrac{d}{N}\\sum_{a=1}^N\\sum_{i=1}^S(x_i^a)^2 - \\dfrac{\\mu}{SN} \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2+\\dfrac{\\sigma^2}{2SN}\\sum_{ab}(\\sum_i x_i^a x_i ^b)^2\n$$\n\n\\subsection{Optimization}\nTo optimize P we take the partial derivatives wrt $\\mu, \\sigma$, and d and set them all equal to 0\n\n1). $\\dfrac{2}{N}\\dfrac{\\partial logP}{\\partial d}=\\dfrac{1}{D}\\dfrac{\\partial D}{\\partial d}-\\dfrac{1}{N}\\sum_{a=1}^N\\sum_{i=1}^S(x_i^a)^2 =0$\n\\hfill\\break\\hfill\\break\n2). $\\dfrac{2}{N}\\dfrac{\\partial logP}{\\partial \\sigma^2}=\\dfrac{1}{D}\\dfrac{\\partial D}{\\partial \\sigma^2}+\\dfrac{1}{2SN}\\sum_{ab}(\\sum_i x_i^a x_i ^b)^2 =0$\n\\hfill\\break\\hfill\\break\n3). $\\dfrac{2}{N}\\dfrac{\\partial logP}{\\partial \\mu}=\\dfrac{1}{D}\\dfrac{\\partial D}{\\partial \\mu}-\\dfrac{1}{SN} \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2 =0$\n\\hfill\\break\\hfill\\break\n\\subsection{Determinant of A}\nThe average determinant as given to us by the semicircular law in Random Matrix Theory-Robert Wiegner \n$$\n<log D>=\\sum_i log(\\lambda_i)=log(d+\\mu)+(S-1)\\int d\\lambda \\dfrac{\\sqrt{4\\sigma^2-(\\lambda+d)^2}}{2\\pi\\sigma}log(\\lambda)\n$$\nWe evaluate this integral from $-d-2\\sigma : -d+2\\sigma$ as that is the radius in which all of our eigenvalues lie according to the semicircular law. Let $z=\\dfrac{\\lambda -d}{2\\sigma}, b=\\dfrac{2d}{\\sigma}$ so $\\lambda \\rightarrow 2\\sigma z+d, d\\lambda \\rightarrow 2\\sigma dz$. Now we divide everything by $2\\sigma$ and the integral:\n$$\n\\int_{-d/2\\sigma -1}^{-d/2\\sigma +1} d\\lambda \\dfrac{\\sqrt{1-(\\dfrac{\\lambda -d}{2\\sigma})^2}}{2\\pi\\sigma}log(\\dfrac{\\lambda}{2\\sigma})+log(2\\sigma)\n$$\nbecomes:\n$$\nI=\\dfrac{2\\sigma}{\\pi}[log(2\\sigma)\\int_{-b-1}^{-b+1}dz\\sqrt{1-z^2}+\\int_{-b-1}^{-b+1} dz log(z+b)\\sqrt{1-z^2}]\n$$\nBy using mathematica we solve the integral, where $F_{3,1}$ is the Hypergeometric function $HypegeometricPFQ[(1,1,\\dfrac{3}{2}),(2,3),\\dfrac{1}{b^2}]$:\n$$\nI=log(d)-\\dfrac{\\sigma^2}{2d^2}[F_{3,11}(\\dfrac{4\\sigma^2}{d^2})]\n$$\nNow we can rewrite the average log determinant as:\n$$\n\\dfrac{1}{S}<logD>=\\dfrac{1}{S}log(d+\\mu)+(1-\\dfrac{1}{S})I\n$$\n\n\\subsection{Solving the Optimization Equations}\nNow that we have the $<logD>$ we can solve optimization equations 1)., 2). and 3). \n\\hfill\\break\nSo first let $g(x)=\\dfrac{1}{2}xF_{3,1}(4x)$, Then $g'(x)=\\dfrac{1}{1+\\sqrt{1-4x}-2x}$\n\\hfill\\break\n\\hfill\\break\n\\textbf{Optimization equation 3).} becomes\n$$\n\\dfrac{2}{N}\\dfrac{\\partial logP}{\\partial \\mu}=\\dfrac{1}{d+\\mu}-\\dfrac{1}{SN} \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2=0\n$$\nIf we solve optimization equation 3). for $d+\\mu$ we get $d+\\mu=\\dfrac{SN}{ \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2}$. We replace $d+\\mu$ in optimization equation 1). with this.\n\\hfill\\break\\hfill\\break\n\\textbf{Optimization equation 1).} becomes:\n$$\n\\dfrac{2}{N}\\dfrac{\\partial logP}{\\partial d}=\\dfrac{1}{d}+\\dfrac{2\\sigma^2}{d^3}g'(\\dfrac{\\sigma^2}{d^2})-\\dfrac{1}{SN}\\sum_{a=1}^N\\sum_{i=1}^S(x_i^a)^2 +\\dfrac{1}{S^2N} \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2=0\n$$\n$$\n\\rightarrow \\dfrac{1}{d}+\\dfrac{2\\sigma^2}{d^3}g'(\\dfrac{\\sigma^2}{d^2})=\\dfrac{1}{SN}\\sum_{a=1}^N\\sum_{i=1}^S(x_i^a)^2 - \\dfrac{1}{S^2N} \\sum_{a=1}^N (\\sum_{i=1}^S x_i^a)^2\n$$\n\\textbf{Optimization equation 2).} becomes:\n$$\n\\dfrac{2}{N}\\dfrac{\\partial logP}{\\partial \\mu}=-\\dfrac{1}{d^2}g'(\\dfrac{\\sigma^2}{d^2})+\\dfrac{1}{2SN}\\sum_{ab}(\\sum_i x_i^a x_i ^b)^2 =0\n$$\n$$\n\\rightarrow \\dfrac{1}{S}\\dfrac{1}{2SN}\\sum_{ab}(\\sum_i x_i^a x_i ^b)^2=\\dfrac{1}{d^2}g'(\\dfrac{\\sigma^2}{d^2})\n$$\n\n\\hfill\\break\\hfill\\break\nTo solve for $\\mu, \\sigma$ and d we use rootsolvers in R...\n\\end{document}\n", "meta": {"hexsha": "2d02b88f7a5126ebca780953ebfb4a45847bc2cd", "size": 6882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MS/Equations(1).tex", "max_stars_repo_name": "ndorilas2014/RMTProject", "max_stars_repo_head_hexsha": "67edc50786cf525404e94bca34a2cbdb8f77c3c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-08T23:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-08T23:04:46.000Z", "max_issues_repo_path": "MS/Equations(1).tex", "max_issues_repo_name": "ndorilas2014/RMTProject", "max_issues_repo_head_hexsha": "67edc50786cf525404e94bca34a2cbdb8f77c3c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MS/Equations(1).tex", "max_forks_repo_name": "ndorilas2014/RMTProject", "max_forks_repo_head_hexsha": "67edc50786cf525404e94bca34a2cbdb8f77c3c0", "max_forks_repo_licenses": ["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.6883116883, "max_line_length": 334, "alphanum_fraction": 0.6239465272, "num_tokens": 3085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6698372024559517}}
{"text": "\\chapter{Methods}\n\n\\section{System of Equations}\nThe system of study was modelled using coupled Ordinary Differential Equations (ODEs). The model is based on a logistic framework modified with a dynamic carrying capacity that depends on the environmental conditions. The ``environment\" consists of the resources, oxygen and testosterone which have their own equations for production and consumption. We make the simplifying assumption that every other resource required by cells are present in non-limiting concentrations. Additionally, the cell types were assumed to not mutate and hence cannot change their types. No spatial structure is considered and the system is assumed to be well mixed and the resource available in bulk for all the cells.\n\nThe ODEs for population size of a cell type is given in \\autoref{cell_eq}. The equation is such that the population increases by a maximum growth rate $r_{i,max}$ and reduces by a maximum death rate $\\delta_i$. The effective growth rate decreases as the total population approaches a maximum limit while the effective death rate stays the same. This maximum limit for the total population varies between 1 to $K_{i,max}$ and varies depending on the resource availability as a function of the form as given in \\autoref{fres_eq} and visualised in \\autoref{fig_fres}.\\\\\nFor $i \\in \\{T^+,T^p,T^-\\}$\n\\begin{equation}\n  \\frac{dy_i}{dt} = r_{i,max}(dtx) y_i (1 - \\frac{\\sum_j y_j}{1 + K_{i,max} f_i(O_2) f_i(test)} )- \\delta_i y_i\n  \\label{cell_eq}\n\\end{equation}\n\nThe functional dependence on resource $f_i(res) \\in [0,1]$. Below the lower limit, $ll_{res,i}$ the function is 0, representative of no growth, and increases linearly above it upto the upper limit, $ul_{res,i}$ and the function saturates to 1, representative of the maximum growth, for any resource levels above that.\\\\\nFor $res \\in \\{O_2,test\\}$\n\\begin{equation}\n  f_i(res) = \\begin{cases}\n  1 &\\text{if } ul_{res,i} \\leq res \\\\\n  \\frac{res-ll_{res,i}}{ul_{res,i}-ll_{res,i}} &\\text{if } ll_{res,i} < res < ul_{res,i} \\\\\n  0 &\\text{if } res \\leq ll_{res,i} \\\\\n  \\end{cases}\n  \\label{fres_eq}\n\\end{equation}\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{f_res}\n  \\caption{$f_i(res)$}\n  \\label{fig_fres}\n\\end{figure}\n\nThe ODE for oxygen is given in \\autoref{o2_eq}. This involves a term for external production that increase oxygen levels constantly at a rate $p_{O_2}$, a term for uptake by all cells where they decrease oxygen levels at a rate $\\mu_{O_2,i}$ and a term for decay where oxygen level decreases at a rate $\\lambda_{O_2}$.\n\\begin{equation}\n  \\frac{dO_2}{dt} = p_{O_2} - \\sum_i \\mu_{O_2,i} y_i - \\lambda_{O_2} O_2\n  \\label{o2_eq}\n\\end{equation}\n\nThe ODE for testosterone is given in \\autoref{test_eq}. The form is similar to that of oxygen, with the difference being production being done by $T^p$ cells at a rate $p_{test}$ here.\n\\begin{equation}\n  \\frac{dtest}{dt} = p_{test}(abi) y_{T^p} - \\sum_i \\mu_{test,i} y_i - \\lambda_{test} test\n  \\label{test_eq}\n\\end{equation}\n\nNote that these equations are defined only for positive values of cell count and resource level to be biologically relevant. To mitigate the problem of having a continuous variable for  cell count, $y_i < 1$ is defined as extinction of the cell type $i$ and $y_i = \\frac{dy_i}{dt} = 0$ in such a case.\n\n\\section{Therapy}\nFor implementation of therapy, production rate of testosterone and growth rate of the cells are governed by the dose of abiraterone $abi$ and docetaxel $dtx$ respectively as given in \\autoref{p_test_dose_eq} and \\autoref{r_dose_eq}. Therapy is modelled as a boolean value, where $1$ represents dose at MTD and $0$ represents no dose.\n\\begin{equation}\n  p_{test}(abi) = \\begin{cases}\n  p_{test,max} &\\text{if } abi = 0 \\\\\n  p_{test,min} &\\text{if } abi = 1 \\\\\n  \\end{cases}\n  \\label{p_test_dose_eq}\n\\end{equation}\n\\begin{equation}\n  r_i(dtx) = \\begin{cases}\n  r_{i,max} &\\text{if } dtx = 0 \\\\\n  r_{i,min} &\\text{if } dtx = 1 \\\\\n  \\end{cases}\n  \\label{r_dose_eq}\n\\end{equation}\nThe dosing scheme for standard-of-care is given in \\autoref{dose_soc_eq}. Here, the dose is applied at MTD at all times from the start of the simulation regardless of the population size.\\\\\nFor $dose \\in \\{abi,dtx\\}$\n\\begin{equation}\n  dose(x,t) = 1 \\quad \\forall\\ t, x\n  \\label{dose_soc_eq}\n\\end{equation}\n\nThe dosing scheme for adaptive therapy is given in \\autoref{dose_at_eq}. A binary mode of adaptive therapy is considered here, where dose is applied at MTD when the population size exceeds the On threshold and stays on until the population size falls below the Off threshold, after which it is turned off.\n\\begin{equation}\n  dose(x,t) = \\begin{cases}\n  0 &\\text{if } dose(x,t-\\Delta t) = 0 \\text{ and } x < \\text{On} \\\\\n  1 &\\text{if } dose(x,t-\\Delta t) = 0 \\text{ and } x \\geq \\text{On} \\\\\n  1 &\\text{if } dose(x,t-\\Delta t) = 1 \\text{ and } x > \\text{Off} \\\\\n  0 &\\text{if } dose(x,t-\\Delta t) = 1 \\text{ and } x \\leq \\text{Off} \\\\\n  \\end{cases}\n  \\label{dose_at_eq}\n\\end{equation}\n\n\\section{Constraint equations and parameters from literature}\n\\autoref{parmtable} gives a brief description of the parameters from the above equations, the values used, and the sources for these values where applicable. Note that all the resource parameters are normalised to ``Tissue levels of that resource\" as obtained from the literature sources cited. The cell lines of LNCaP, 22Rv1 and PC3 were considered to correspond to the $T^+$, $T^p$ and $T^-$ cells respectively when obtaining literature values.\n\nConstraint equations given below were used to determine the values of some parameters for which direct sources were not available.\\\\\n\\autoref{r_eq} is obtained from solving \\autoref{cell_eq} from $N_0$ to $2N_0$ under the assumption that resources are not limiting and $y_i$ is small. This constraint along with doubling time and death rates obtained from literature can be used to get the growth rate.\n\\begin{equation}\n  r_{i,max} = \\frac{ln(2)}{\\tau_{d,i}} + \\delta_i\n  \\label{r_eq}\n\\end{equation}\n\\autoref{K_eq} is obtained from setting \\autoref{cell_eq} = 0 under the assumption that equilibrium is reached with only one cell type present and resources are not limited. This constraint along with an assumed equilibrium value of 10000 for the cells, growth and death rate obtained from above can be used to get the maximum carrying capacity for that cell type.\n\\begin{equation}\n  K_{i,max}=\\frac{r_{i,max}}{r_{i,max}-\\delta_i} y_i^*\n  \\label{K_eq}\n\\end{equation}\n\\autoref{p_o2_eq} is obtained from setting \\autoref{o2_eq} = 0 under the assumption that equilibrium is reached with only $T^-$ cell type present. This constraint along with an assumed equilibrium value of 1 for oxygen and 10000 for the cells, and uptake and decay rates from literature can be used to get the production rate of oxygen.\n\\begin{equation}\n  p_{O_2} = \\lambda_{O_2} O_2^* + y_i^* \\mu_i\n  \\label{p_o2_eq}\n\\end{equation}\n\\autoref{p_test_eq} is obtained from setting \\autoref{test_eq} = 0 under the assumption that equilibrium is reached with only $T^p$ cell type present. This constraint along with an assumed equilibrium value of 1 for oxygen and 10000 for the cells, decay rates from literature can be used to get the production rate of testosterone.\n\\begin{equation}\n  p_{test,max} - \\mu_{test,T^p} = \\frac{test^* \\lambda_{test}}{y_{T^p}^*} = 4 \\times 10^{-4}\n  \\label{p_test_eq}\n\\end{equation}\n\\autoref{p_test_doseparm_eq} is the same as \\autoref{p_test_eq} with a lower equilibrium value of testosterone with abiraterone therapy.\n\\begin{equation}\n  p_{test,min} = \\frac{test_{abi}^* \\lambda_{test}}{y_{T^p}^*} + \\mu_{test,T^p}\n  \\label{p_test_doseparm_eq}\n\\end{equation}\n\\autoref{r_doseparm_eq} is the rearranged version of \\autoref{K_eq} with a lower equilibrium value for the cells with docetaxel therapy.\n\\begin{equation}\n  r_{i,min}=\\frac{K_{i,max}}{K_{i,max} - y_{i,dtx}^*} \\delta_i\n  \\label{r_doseparm_eq}\n\\end{equation}\n\n\\section{Code Implementation}\nThe code is written in Python 3 and with dependencies of numpy, scipy, pandas, matplotlib and seaborn libraries. The system of equations were solved numerically by the LSODA algorithm provided by the \\texttt{scipy.integrate.ode} function. The code is designed to iterate over the different parameters of a set parallely over multiple threads, however, the actual solver is sequential and single threaded.\n\nThe code, at each time step checks if the values are non-negative and sets them to 0 if it is the case. This is since the equations are not defined in these range of values and numerical errors can give rise to negative values. A similar implementation is done for $y_i < 1$.\n\nThe source code along with the data is available at the following Github repository: \\url{https://www.github.com/harshavardhan-bv/cancer-compe-strat}.\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.15\\textwidth]{github}\n  \\caption{QR code for the Github repository}\n  \\label{github}\n\\end{figure}\n\n\n\\newpage\n\\begin{longtable}[c]{|l|p{4.3cm}|c|p{2.3cm}|}\n\n  \\hline \\multicolumn{1}{|c|}{\\textbf{Parameter}} & \\multicolumn{1}{c|}{\\textbf{Description}} & \\multicolumn{1}{c|}{\\textbf{Value(s)}} & \\multicolumn{1}{c|}{\\textbf{Source(s)}}\\\\ \\hline\n  \\endhead\n\n  \\hline \\multicolumn{4}{|r|}{{Continued on next page}} \\\\ \\hline\n  \\endfoot\n\n  \\endlastfoot\n\n  $y_i$ & No. of cells of cell type $i$ & N/A & N/A  \\\\ \\hline\n  $r_{i,max}$ & Population growth rate of cell type $i$  &\n  \\begin{tabular}{l|l}\n    $T^+$ & $2.84 \\times 10^{-3}$ \\tiny{min$^{-1}$}\\\\\n    $T^p$ & $2.79 \\times 10^{-3}$ \\tiny{min$^{-1}$}\\\\\n    $T^-$ & $6.23 \\times 10^{-4}$ \\tiny{min$^{-1}$}\\\\\n  \\end{tabular}\n  & \\autoref{r_eq} \\\\ \\hline\n  $r_{i,min}$ & Population growth rate of cell type $i$ under $dtx$ therapy &\n  \\begin{tabular}{l|l}\n    $T^+$ & $2.55 \\times 10^{-3}$ \\tiny{min$^{-1}$}\\\\\n    $T^p$ & $2.54 \\times 10^{-3}$ \\tiny{min$^{-1}$}\\\\\n    $T^-$ & $2.06 \\times 10^{-4}$ \\tiny{min$^{-1}$}\\\\\n  \\end{tabular}\n  & \\autoref{r_doseparm_eq} \\\\ \\hline\n  $\\delta_i$  & Population death rate of cell type $i$ &\n  \\begin{tabular}{l|l}\n    $T^+$ & $2.5 \\times 10^{-3}$ \\tiny{min$^{-1}$}\\\\\n    $T^p$ & $2.5 \\times 10^{-3}$ \\tiny{min$^{-1}$}\\\\\n    $T^-$ & $1.6 \\times 10^{-4}$ \\tiny{min$^{-1}$}\\\\\n  \\end{tabular}\n  & \\cite{Jain}  \\\\ \\hline\n  $K_{i,max}$ & Maximum Carrying capacity, coming up through the environment/resources &\n  \\begin{tabular}{l|l}\n    $T^+$ & $8.35 \\times 10^4$ \\\\\n    $T^p$ & $9.62 \\times 10^4$ \\\\\n    $T^-$ & $1.34 \\times 10^4$ \\\\\n  \\end{tabular}\n  & \\autoref{K_eq} \\\\ \\hline\n  $f_{i,res}$ & Functional dependence of cell type $i$ on resource $res$, normalised to 1 & $f_{T^-,test}=1$ & N/A \\\\ \\hline\n  $p_{res}$ & Production rate of resource, either as bulk or by cells &\n  \\begin{tabular}{l|l}\n    $O_2$ & 0.11 \\tiny{min$^{-1}$}\\\\\n    $test,max$ & $5 \\times 10^{-7}$ \\tiny{min$^{-1}$cell$^{-1}$}\\\\\n  \\end{tabular}\n  & \\autoref{p_o2_eq}, \\autoref{p_test_eq}\\\\ \\hline\n  $p_{test,min}$ & Production rate of $test$ under $abi$ therapy & $1 \\times 10^{-7}$ \\tiny{min$^{-1}$cell$^{-1}$} & \\autoref{p_test_doseparm_eq}\\\\ \\hline\n  $\\mu_{res,i}$ & Uptake of resource $res$ by cell type $i$ &\n  \\begin{tabular}{l|l|l}\n    $O_2$ & $T^+$ & $1.63 \\times 10^{-6}$ \\tiny{min$^{-1}$cell$^{-1}$}\\\\\n    & $T^p$ & $1.63 \\times 10^{-6}$ \\tiny{min$^{-1}$cell$^{-1}$}\\\\\n    & $T^-$ & $1.04 \\times 10^{-6}$ \\tiny{min$^{-1}$cell$^{-1}$}\\\\ \\hline\n    $test$ & $T^+$ & $2.34 \\times 10^{-8}$ \\tiny{min$^{-1}$cell$^{-1}$}\\\\\n    & $T^p$ & $6.00 \\times 10^{-8}$ \\tiny{min$^{-1}$cell$^{-1}$}\\\\\n    & $T^-$ & 0 \\tiny{min$^{-1}$cell$^{-1}$}\\\\\n  \\end{tabular}\n  & \\cite{HailJr}, \\autoref{p_test_eq}\\\\ \\hline\n  $\\lambda_{res}$ & Decay rate of resource $res$ &\n  \\begin{tabular}{l|l}\n    $O_2$ & 0.100 \\tiny{min$^{-1}$}\\\\\n    $test$ & 0.004 \\tiny{min$^{-1}$}\\\\\n  \\end{tabular}\n  & \\cite{Jain}\\\\ \\hline\n  $ll_{res,i}$ & Lower limit/threshold level of resource $res$ for carrying capacity of cell type $i$ & $\\in [0,1]$ & N/A \\\\ \\hline\n  $ul_{res,i}$ & Upper limit/saturation level of resource $res$ for carrying capacity of cell type $i$ & $\\in [0,1]$ & N/A \\\\ \\hline\n  \\multicolumn{4}{|c|}{Supplementary Parameters}\\\\ \\hline\n  $\\tau_d$  & Doubling time of cell type $i$ &\n  \\begin{tabular}{l|l}\n    $T^+$ & $34$ \\tiny{hr} \\\\\n    $T^p$ & $40$ \\tiny{hr} \\\\\n    $T^-$ & $25$ \\tiny{hr} \\\\\n  \\end{tabular}\n  & \\cite{atcc} \\\\ \\hline\n  $y_i^*$ & Equilibrium value of cell number in absence of competition & 10000 & assumed \\\\ \\hline\n  $y_{i,dtx}^*$ & Equilibrium value of cell number in absence of competition under $dtx$ therapy &\n  \\begin{tabular}{l|l}\n    $T^+$ & $0.30 \\times y_i^*$ \\\\\n    $T^p$ & $0.30 \\times y_i^*$ \\\\\n    $T^-$ & $0.15 \\times y_i^*$ \\\\\n  \\end{tabular}\n  & \\cite{Morikawa} \\\\ \\hline\n  $res^*$ & Equilibrium/Tissue levels of resource with one cell type present &\n  \\begin{tabular}{l|l}\n    $O_2$    & 2.5 \\tiny{mmHg}          \\\\\n    $test$   & 3.74 \\tiny{pmol/g tissue}\\\\\n  \\end{tabular}\n  & \\cite{Steward},\\cite{Titus} \\\\ \\hline\n  $test_{abi}^*$ & Equilibrium/Tissue levels of testosterone with only $T^p$ cell type present under $abi$ therapy & $0.1 \\times test^*$ & \\cite{Acharya} \\\\ \\hline\n\n  \\caption{Table of all parameters}\n  \\label{parmtable}\\\\\n\\end{longtable}\n", "meta": {"hexsha": "a80747d7df763127b552c1fae6df4e20dde0a913", "size": 13184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writing/MSThesis/chapters/Methods.tex", "max_stars_repo_name": "Harshavardhan-BV/Cancer-compe-strat", "max_stars_repo_head_hexsha": "e4decacd5779e85a68c81d0ce3bedf42dea2964f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-18T15:54:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-18T15:54:26.000Z", "max_issues_repo_path": "writing/MSThesis/chapters/Methods.tex", "max_issues_repo_name": "Harshavardhan-BV/Cancer-compe-strat", "max_issues_repo_head_hexsha": "e4decacd5779e85a68c81d0ce3bedf42dea2964f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writing/MSThesis/chapters/Methods.tex", "max_forks_repo_name": "Harshavardhan-BV/Cancer-compe-strat", "max_forks_repo_head_hexsha": "e4decacd5779e85a68c81d0ce3bedf42dea2964f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.9272727273, "max_line_length": 698, "alphanum_fraction": 0.6822663835, "num_tokens": 4379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6698054622845699}}
{"text": "\\section{Appendix\\label{sec:appendix}}\n\\subsection{Notations}\nWe follow the ZOGY paper symbol notations. Frequency space quantities are\nmarked with \\(\\hat{\\ }\\), complex conjugation is marked by\n\\(\\overline{x}\\). Pixels of images are referred as functions\n(\\Cref{eq:img_func}). Expectation value of random variables are marked by\n\\(\\langle\\ \\rangle\\).\n%\n\\par We use the terms \\emph{image space} and \\emph{Fourier- or frequency\n  space} to refer to the discrete Fourier transform of images. \\emph{Pixels}\nmay refer to either space depending on the context.\n\\begin{align}\nx &= \\{x(0), x(1), ... , x(n) \\},\\ x(n) \\in \\mathbb{R}\\\\\n\\hat{x} &= \\{\\hat{x}(0), \\hat{x}(1), ... , \\hat{x}(k) \\},\\ \\hat{x}(k) \\in\n\\mathbb{C}\\\\\n\\label{eq:img_func}\n\\end{align}\n%\n\\subsection{Parseval theorem\\label{sec:parseval}}\nThe Parseval theorem states that the integral (sum) of absolute\nsquares in image and frequency space are equal. In DFT form:\n\\begin{equation}\n  \\sum_i \\abs{x_i}^2 = \\frac{1}{N} \\sum_k \\abs{\\hat{x}_k}^2\\label{eq:Parseval}\n\\end{equation}\n%\n\\subsection{Floating point values\\label{sec:floating_point}}\nThe machine \\emph{epsilon} is the smallest positive floating point value\nwhere \\(1 + \\varepsilon \\neq 1\\). This is \\(\\approx 1e-16\\) for double\nprecision.\n%\n\\par The machine \\emph{tiny} is the smallest positive floating point value\nwhere the significand does not start with leading zeroes but the exponent is\nthe smallest representable. Going below this value the floating point number\nlooses significant digits and eventually rounds to exact zero. About\n\\(\\mathrm{epsilon}\\cdot\\mathrm{tiny} = 0\\).\n%\n\\par Underflow to zero occurs around the order of the floating-point\n\\emph{tiny} value, we found, however, that this never practically\nhappens. In all our practical PSF transformation cases FFT values\ncannot go a few orders below the floating-point \\emph{epsilon} that is\nseveral orders higher than the \\emph{tiny} limit. This is\nunderstandable if we consider that every pixel is a result of addition\noperations, where the number of terms roughly equals to the number of\npixels in the image. As the PSFs are normalized, the zero frequency\nvalue is always 1, which approximately sets the exponent of these\nfloating point values.\n%\n\\par Furthermore, we usually zero pad a small PSF image to a larger image\nsize that creates a window function effect in the padded image. The\ntransformed image, therefore, have long oscillating tails in frequency space\nand we found that all pixel (absolute) values remain a few orders even above\nthe epsilon threshold.\n%\n\\subsection{Complex random variables}\n%\n\\begin{equation}\n\\langle Z\\rangle = \\langle\\Re(Z)\\rangle + i\\langle\\Im(Z)\\rangle\n\\end{equation}\n%\n\\begin{equation}\n\\langle \\bar{Z}\\rangle = \\overline{\\langle Z\\rangle}\n\\end{equation}\n%\n\\newcommand{\\Var}{\\mathrm{Var}}\n%\nThe variance and covariance of a complex random variable are defined as:\n\\begin{equation}\n\\operatorname{Var}(Z) \\in \\mathbb{R} \\equiv \\langle\\abs{Z-\\langle Z \\rangle}^2 \\rangle =\n\\langle\\abs{Z}^2\\rangle - \\abs{\\langle Z \\rangle}^2\n\\end{equation}\n%\n\\begin{align}\n\\operatorname{Cov}(X, Y) &\\equiv \\left\\langle\\left(X - \\langle X \\rangle\\right)\n\\overline{\\left(Y - \\langle Y \\rangle\\right)} \\right\\rangle\n= \\langle X\\bar{Y} \\rangle - \\langle X \\rangle \\overline{\\langle Y \\rangle} \\\\\n\\operatorname{Cov}(X, X) &= \\operatorname{Var}(X)\n\\end{align}\n%\n\\subsection{Discrete Fourier transformation normalization convention}\n\\par There is a freedom how normalization factors are placed in the\nforward and inverse Fourier transforms.  This scales the individual\nvalues of frequency components compared to corresponding pixel space\nvalues. Usually, we do not need to worry about these scalings as the\nforward and inverse operation factors cancel out. However, certain\nfrequency space relations change in their form if the normalization\nconvention changes, most importantly for us, the expression of the\nconvolution theorem changes.\n%\nThe definition of DFT usually has the following normalization convention:\n\\begin{equation}\n\\hat{X}(k) = \\mathcal{F}[x](k) \\equiv \\sum_n x(n) e^{-i\\frac{2\\pi}{N}k\\cdot n}\n\\end{equation}\n%\n\\begin{equation}\nx(n) = \\mathcal{F}^{-1}[\\hat{x}](n) \\equiv \\frac{1}{N}\\sum_k \\hat{x}(k)\n  e^{i\\frac{2\\pi}{N}n\\cdot k}\n\\end{equation}\nIn this convention, the convolution theorem (and its dual) looks like:\n\\begin{equation}\n\\mathcal{F}[x \\otimes y] =  \\hat{x} \\cdot \\hat{y}\n\\end{equation}\n\\begin{equation}\n\\mathcal{F}[x\\cdot y] = \\frac{1}{N} \\hat{x} \\otimes \\hat{y}\n\\end{equation}\nAlso:\n\\begin{equation}\n\\mathcal{F}[x](0) = \\sum_n x(n)\n\\label{eq:X0sum}\n\\end{equation}\nThese relations change with factors of $\\sqrt{N}$ if the transform\nnormalization changes. We must be sure that the correct convention is used\nby numpy. This is the default as of v1.18.\n%\n\\subsection{Noise variance properties in frequency space\\label{sec:noise_freq_space}}\n%\n\\par Let's take a look at the covariance of the Fourier transform of zero\nexpectation value pixels The complex covariance can be written as:\n\\begin{equation}\n\\begin{split}\n\\left\\langle \\hat{x}(k) \\overline{\\hat{x}(j)} \\right\\rangle =\n\\left\\langle \\sum_{n=0}^{N-1} x(n) e^{-i\\frac{2\\pi}{N}kn}\n \\sum_{l=0}^{N-1} \\overline{x(l)} e^{i\\frac{2\\pi}{N}jl} \\right\\rangle = \\\\\n\\sum_{n,l=0}^{N-1} \\left\\langle x(n)\\overline{x(l)}\\right\\rangle e^{-i\\frac{2\\pi}{N}(kn - jl)} =\n\\sum_{n=0}^{N-1} \\sigma(n)^2 e^{-i\\frac{2\\pi}{N}(k-j)}\n\\label{eq:freq_cov}\n\\end{split}\n\\end{equation}\n%\n\\par If \\(k=j\\), we get the variance at each frequency. From the last\nexpression in \\Cref{eq:freq_cov}, we can see that the variance is the same\nat all frequency and it is the sum of the individual pixel\nvariances. Considering the normalization in the forward and inverse Fourier\ntransformation, we can think of this as the average of the individual pixel\nvariances, too.\n%\n\\par This implies that using the average value of the variance plane as the\nvariance in frequency space is actually not an approximation but the exact\nvalue.\n%\n\\par If \\(k\\neq j\\), but the individual pixel variances are equal, then the\nphase factors in \\Cref{eq:freq_cov} average out and we get that the\ncovariance in frequency space is zero between different frequencies. As a\nsimilar expression and argument can be written for the pseudo-covariance, we\nreceive that any two different frequencies are uncorrelated. This is the\nwell-known relation that the Fourier transform of white noise is white noise. If\n\\(\\sigma_n\\)-s are not equal however, the phase factors won't average to\nzero. Spatial variations of pixel noise introduce correlation in frequency\nspace noise. The correlation in frequency space encodes the spatial\ndistribution of \\(\\sigma_n\\) values in image space.\n%\n\\par We note that this is the case if we add zero padding to the\nimage, because the zero padding can be seen as pixels with zero sigma\nnoise. Also, if we change the correlation between frequencies by\nmultiplying with frequency-dependent factors, this implies a spatial\nchange of noise in image space, following the convolution\ntheorem.\n%\n\\par Finally, let's consider a white noise image that got convolved by a kernel\nimage. From the convolution theorem, we get that in frequency space the\nvariance becomes frequency-dependent, but different frequencies remain still\nuncorrelated.\n%\n\\par We summarize these noise transformation properties in\n\\Cref{tab:freq_noise}, noting the duality of variances values and\ncorrelation between pixels in image and frequency spaces. Our understanding\nis that correlated noise in image space can be decorrelated by scaling in\nfrequency space so that all components have the same variance. This is one\nof the key ideas in the ZOGY difference image construction, that one square\nroot of the likelihood variance weight can be assigned to the proper\ndifference image, so that its noise gets whitened (decorrelated). (The other\nsquare root is part of the difference image PSF.)\n%\n\\par The change of the spatial distribution of pixel sigmas follows the overall\nconvolution (like \\(c_n, c_r\\)) of the original uncorrelated images. If\nfurthermore, per pixel variances are uniform across the image, then the\nwhitening restores uncorrelated white noise across the image.\n%\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{c|c}\n  image space & frequency space \\\\\n  \\hline\n  white noise & white noise \\\\\n  \\parbox{3in}{different variance values in uncorrelated pixels} &\n  \\parbox{3in}{same average variance at all frequencies\n    but correlation in noise between different\n    frequencies}\n  \\\\\n  \\parbox{3in}{same variance but correlated pixel noise due to\n  convolution operation} & \\parbox{3in}{different variances at frequencies but\n                 noise between frequencies are still uncorrelated} \\\\\n\\end{tabular}\n\\end{center}\n\\caption{\\label{tab:freq_noise}Summary of image space and frequency space\n  noise properties.}\n\\end{table}\n%\n\\subsection{The resolution of DFT space\\label{sec:dft}}\n\\par Finite DFT transforms N pixel into N pixel in frequency space. The\ncovered frequency range always goes from -1/2 through zero to \\(\\frac{1}{2}\n\\frac{1}{\\mathrm{px}}\\) frequencies but the resolution depends on the number\nof input pixels (\\Cref{fig:dft_sampling}). As conservation of information,\nthe N resulting frequencies can distinguish exactly N spatial positions. The\nsame concept is described by the interpretation that finite DFT always sees\nthe input as if it were periodic, giving the same result as if the input\nwere repeating in every N pixels. This also means that when we make a\nfrequency space manipulation we must see not only the input image or kernel\nbut the results as well to be periodic back in image\nspace.\\footnote{\\Cref{fig:dft_sampling} source:\n  \\texttt{https://en.wikipedia.org/wiki/File:Fourier\\_transform,\\_Fourier\\_series,\\_DTFT,\\_DFT.svg}}\n\\begin{figure}[h]\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/dft_sampling.pdf}\n\\end{center}\n\\caption{\\label{fig:dft_sampling}Overview of sampling and periodicity\n  effects in frequency space. Given the Fourier transform of a\n  function (top left), sampling it every T time may cause a change in\n  the frequency space values according to the sampling theorem (bottom\n  left). This is called aliasing, in the bottom left panel, the\n  minimum value shown is different from the top left panel. If the\n  function is periodic, the frequency space values reduced to discrete\n  values as well (top right). DFT/FFT combines the two concepts\n  (bottom right). Considering unit pixel size, the FFT space always\n  goes to 1/2 frequency with a resolution of 1/N. Figure source:\n  Wikipedia:Discrete Fourier transform}\n\\end{figure}\n%\n\\subsection{Zero padding in FFT frequency space\\label{sec:zeropadS}}\n%\n\\par While in image space convolution operations can have their own\nway of handling edges, in Fourier space, multiplication always\ncorresponds to the circular boundary conditions in image space.  If we\nwant to implement a convolution without circular boundary\nconditions that we want to calculate in frequency space,\nwe need to pad the images by extra edge pixels to avoid the\nreappearance of values from the opposite side.\nAs we saw in \\Cref{sec:patterns}, numerical artifacts in the matching\nkernels cannot be bounded well in image space, they fill the full area\nindependently of the padding size. Therefore we cannot practically perform\nthe kernel matching convolutions in image space.\n%\n\\par In the previous section, we also saw that a zero-padding violates one\nof the ZOGY assumptions: that frequencies are independent and log\nlikelihoods can be calculated from them by simple addition. Is this a\nsignificant inaccuracy in the score image?\n%\n\\par Let's assume for a moment that the image background is extended in a\nsourceless way with white noise. In this case, all the assumptions of the\ndetection statistics derivation hold thus we get \\Cref{eq:Shat}. This is a\nusual convolution expression in image space and at any pixel its value\ndepends only from the half \\(P_d\\) size neighboring area. If \\(P_d\\)\nsignificant values are located in about the same square size as the original\nPSF size then the affected edge area also remains the same. If the PSF\ncontains edges, however, \\(P_d\\) can be significantly bigger in size. Zero\npadding adds pixels to an image that, from a noise model perspective, all\nhave a noise variance of zero. By padding the input images with zeroes, the\npixel variance of the difference image and, in a smaller edge region, the\nscore image variance will decrease. It is unclear whether scaling the score\nimage \\(S\\) with its variance plane satisfactorily corrects for this\neffect. Nevertheless, this correction term is listed as a suggested\nrescaling of the score image in the ZOGY paper Section 3.3. Beside this\ncorrectional approach, we propose the implementation of padding with the\nmodel white noise instead of constant zeroes in the future.\n%\n\\subsection{Sampling}\n\\par It can be shown that Gaussians with \\(0.95 < \\sigma\\), are well\nsampled in the sense that \\(3\\sigma\\) of their Fourier\ntransform Gaussian fit up to the 1/2 frequency limit. For\n\\(5\\sigma\\) fit, this is \\(1.59 < \\sigma\\).\n\n", "meta": {"hexsha": "901c821c3dd8b508c7da152e8a5128dcdd339edc", "size": 13095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "zogy_appendix.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_appendix.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_appendix.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": 48.3210332103, "max_line_length": 100, "alphanum_fraction": 0.7665521191, "num_tokens": 3422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6698054004699079}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Alex Li}\n\\input{preamble}\n\n\\DeclareMathOperator{\\polylog}{Li}\n\\newcommand{\\dilog}{\\polylog_2}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\n    Music is nothing but ratios and harmonic math, anyways.\n    \\byline{Andrew Sega}\n    \\end{inspiration}\n\n    With this being a ``short'' week because of the instructional break,\n    this problem set is concomitantly shorter.\n\n    \\section{Terminology}\n\n    \\begin{problem}\n      What is a harmonic function?\n      \\end{problem}\n      \\begin{solution}\n      Let $U$ be an open subset of $\\C$. A function $f:U \\to \\R$ is real harmonic if $f\\in C^2$ and $\\Delta f = 0$.\n      \\end{solution}\n      \\begin{problem}\n        Define the term \\textbf{harmonic conjugate}.  (Recall \\ref{harmonic-conjugate}.)\n        \\end{problem}\n        \\begin{solution}\n        A harmonic conjugate of a harmonic funcion $f$ is a function $g$ such that $f+ig$ is holomorphic.\n        \\end{solution}\n\n        \\section{Numericals}\n\n        \\begin{problem}\\label{relate-fourier-and-taylor-series}Let $S^1 := \\{(x,y) \\in \\R^2 : x^2 + y^2 = 1 \\}$ and $D_1(0) := \\{ (x,y) \\in \\R^2 : x^2 + y^2 \\leq 1 \\}$.  Find a continuous function $F : D_1(0) \\to \\R$ that is harmonic on the interior of $D_1(0)$ and that extends\n          $f : S^1 \\to \\R$ given by\n           \\[\n              f(\\cos \\theta,\\sin \\theta) = \\sum_{k=0}^N \\left(c_k \\, \\cos \\left( k\\theta \\right) + s_k \\, \\sin \\left( k \\theta \\right) \\right).\n               \\]\n                (This problem encourages you to relate Fourier series and Taylor series.)\n                \\end{problem}\n                \\begin{solution}\n                Extend $f$ to the disk by the following equation:\n                \\[\n                F(r, \\theta) = f(\\theta)r^{k}\n                \\]\n                On the open disk, $r=1$ and so the additional term we multiply by is $r^1=1$, and thus this function agrees with $f$ on the edges of the disk. As a sum and product of infinitely differentiable functions, it is $C^2$.\n\n                Checking that the laplacian $F_{xx} + F_{yy} = 0$ is equivalent to checking the following in polar coordinates:\n                \\begin{align*}\n                F_{rr} +  \\frac{F_r}{r} + \\frac{F_{\\theta\\theta}}{r^2} &= 0\\\\\n                f(\\theta)k(k-1)r^{k-2} +  \\frac{f(\\theta)kr^{k-1}}{r} + \\frac{(-f(\\theta))r^k}{r^2} &= 0\\\\\n                r^{k-2}(k(k-1) +  k - k^2) &= 0\\\\\n                r^{k-2}\\cdot 0 &= 0\n                \\end{align*}\n                Thus this function is harmonic on the interior of $D$.\n                \\end{solution}\n                \\section{Exploration}\n\n                \\begin{problem}\n                  Recall \\ref{where-converge-one-over-n}.  Consider the power series for the \\textbf{dilogarithm} function,\n                    \\[\n                        \\dilog(z) = \\sum_{n=1}^\\infty \\frac{z^n}{n^2}.\n                          \\]\n                            What is its radius $r$ of convergence?  Where on the boundary of\n                              $B_r(0)$ does this series converge?  (Note that there is no pole on\n                                the boundary; not every singularity is a pole!)\n                                \\end{problem}\n                                \\begin{solution}\n                                The radius of convergence is 1: if $r > 1$, then  \n                                \\[\\abs{Li_2(r)} = \\sum_1^\\infty \\frac{r^n}{n^2}\\]\n                                But as $n\\to\\infty$, \n                                \\[\n                                \\lim_{n\\to \\infty} \\frac{r^n}{n^2} = \\lim_{n\\to \\infty} \\frac{nr^{n-1}}{2n} =  \\lim_{n\\to \\infty} n(n-1)r^{n-2} = \\infty,\n                                \\]\n                                so the terms grow arbitrarily large, and thus the sum diverges.\n\n                                On the other hand, if $r\\leq 1$, then \n                                \\[\\abs{Li_2(z)} \\leq \\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6},\\]\n                                so the sum converges absolutely and thus the sum converges everywhere on the closed unit ball of radius 1, and nowhere outside of it.\n                                %TODO This seems too easy?\n                                \\end{solution}\n                                \\begin{problem}\\label{laplacian-via-wirtinger}Consider an open set\n                                  $U \\subset \\C$ and a holomorphic function $f : U \\to \\C$.  Write\n                                    the \\textbf{Laplacian}\n                                      \\[\n                                          \\Delta := \\frac{\\partial^2}{\\partial x^2} + \\frac{\\partial^2}{\\partial y^2} \n                                            \\]\n                                              in terms of the mixed Wirtinger derivative\n                                                $\\displaystyle\\frac{\\partial^2}{\\partial z \\partial \\conj{z}}$.\n                                                \\end{problem}\n                                                \\begin{solution}\n                                                \\begin{align*}\n                                                \\pfrac{}{z}\\pfrac{}{\\conj{z}} &= \\frac{1}{2}(\\pfrac{}{x} - i\\pfrac{}{y})\\frac{1}{2}(\\pfrac{}{x} + i\\pfrac{}{y})\\\\\n                                                &= \\frac{1}{4}(\\ppfrac{}{x} + \\ppfrac{}{y}) = \\frac{\\Delta}{4}\n                                                \\end{align*}\n                                                \\end{solution}\n\n                                                \\begin{problem}\\label{composition-holomorphic-harmonic}Consider open\n                                                  sets $U, V \\subset \\C$ and a holomorphic function $f : U \\to V$ and\n                                                    a harmonic function $g : V \\to \\R$.  Is the composition $g \\circ f$\n                                                      a harmonic function on $V$?\n                                                      \\end{problem}\n                                                      \\begin{solution}\n                                                      Choose real valued functions $u, v:U \\to \\R$ such that $f(z) = u(z) + iv(z)$. Let $g_x$ be the derivative of $g$ in the first coordinate and $g_y$ the second.\n                                                      \\begin{align*}\n                                                      \\ppfrac{g(u, v)}{x} &= \\pfrac{}{x}\\left( g_x(u, v)(u_x + v_x) \\right)\\\\\n                                                      &=  g_{xx}(u, v)(u_x + v_x)^2 + g_x(u, v)(u_{xx} + v_{xx})\\\\\n                                                      &=  g_{xx}(u, v)(u_x - u_y)^2 \\color{purple} \\qquad \\text{Cauchy Riemann Equations}\n                                                      \\end{align*}\n                                                      Let's do the same for the y derivative\n                                                      \\begin{align*}\n                                                      \\ppfrac{g(u, v)}{y} &= \\pfrac{}{y}\\left( g_y(u, v)(u_y + v_y) \\right)\\\\\n                                                      &=  g_{yy}(u, v)(u_y + v_y)^2 + g_x(u, v)(u_{yy} + v_{yy})\\\\\n                                                      &=  g_{yy}(u, v)(u_y - u_x)^2 \\color{purple} \\qquad \\text{Cauchy Riemann Equations}\n                                                      \\end{align*}\n                                                      Then $g\\circ f$ is harmonic since,\n                                                      \\begin{align*}\n                                                          (\\ppfrac{}{y}+\\ppfrac{}{x})g\\circ f = (g_{xx} + g_{yy})(u, v)(u_x - u_y)**2 = 0\n                                                          \\end{align*}\n                                                          (using the fact that $g$ is harmonic).\n                                                          \\end{solution}\n                                                          \\section{Prove or Disprove and Salvage if Possible}\n                                                          \\begin{problem} % wrong sign\n                                                            If $f : U \\to \\R$ is a harmonic function on an open set $U \\subset \\R^2$, then \n                                                              \\[\n                                                                  F(x+iy) := f_x(x,y) + i f_y(x,y) \n                                                                    \\]\n                                                                      defines a holomorphic function $F : U \\to \\C$, regarding $U$ as an\n                                                                        open subset of $\\C$.\n                                                                        \\end{problem} \n                                                                        \\begin{solution}\n                                                                        % Let $f = \\frac{1}{z}$ on $U=\\C/\\{0\\}$. Since $f$ is holomorphic, it's twice differentiable with $f_{xx}(z) = f''(x+iy) = -f_{yy}(z)$, so $f_{xx} + f_{yy} = 0$ and $f$ is harmonic. \n                                                                        No, take $f=\\Re(z^2) = x^2 - y^2$. This is harmonic as it is the real part of a holomorphic function. Then $F = 2x - 2yi = 2\\conj{z}$, and this is not holomorphic. \n\n                                                                        Instead define \n                                                                          \\[\n                                                                              F_2(x+iy) := f_x(x,y) - i f_y(x,y) \n                                                                                \\]\n                                                                                We can see that $F_2$ satisfies the Cauchy-Riemann equations: Let $u=f_x(x,y)$ and $v=f_y(x,y)$ so that $F=u-iv$. Then\n                                                                                \\begin{gather*}\n                                                                                u_x = f_{xx}(x, y) = -f_{yy}(x, y) = v_y\\\\\n                                                                                u_y = f_{xy}(x, y) = f_{yx}(x, y) = -v_x\n                                                                                \\end{gather*}\n                                                                                Since $f$ is a harmonic function, $F_2$ is twice differentiable and this is more than enough to conclude that it is in fact holomorphic.\n                                                                                \\end{solution}\n                                                                                \\begin{problem}\\label{maximum-principle}For an open set\n                                                                                  $U \\subset \\R^2$ and a harmonic function $f : U \\to \\R$, the\n                                                                                        function $f$ does not achieve a maximum. % nonconstant missing\n                                                                                        \\end{problem}\n                                                                                        \\begin{solution}\n                                                                                        False, take $f=0$. It's true if $f$ is not constant and $U$ is connected.\n\n                                                                                        Let $g$ be a holomorphic function with real part $f$.\n                                                                                        Suppose that $f$ achieves a maximum at the point $z$.\n                                                                                        Then consider a curve $\\gamma(t) = re^{it} + z$ from 0 to $2\\pi$ and apply Cauchy's integral formula:\n                                                                                        \\begin{align*}\n                                                                                        f(z) &= \\Re\\left(\\frac{1}{2\\pi i}\\int_\\gamma \\frac{g(w)}{w-z}dw\\right)\\\\\n                                                                                        &= \\Re\\left(\\frac{1}{2\\pi i}\\int_0^{2\\pi} \\frac{g(z + re^{i\\theta})ire^{i\\theta}}{re^{i\\theta}}d\\theta\\right)\\\\\n                                                                                        &= \\frac{1}{2\\pi }\\int_0^{2\\pi} f(z + re^{i\\theta})d\\theta\n                                                                                        \\end{align*}\n                                                                                        Subtracting $f(z)$, we see that \n                                                                                        \\begin{align*}\n                                                                                        0 = \\frac{1}{2\\pi }\\int_0^{2\\pi} f(w) - f(z) d\\theta\n                                                                                        \\end{align*}\n                                                                                        Since $f(z)$ is the maximum value, the integrand is never positive and by continuity of $f$ it must always be 0. Since this is true for all circles centered at $z$, the set of points which achieve the maximum value of $f$ is open, and the complement of this set is the preimage of the open set $\\R/\\{f(z)\\}$, so it is open. Since $U$ is connected, $f$ is constna\n                                                                                        \\end{solution}\n                                                                                        \\begin{problem}\\label{universal-taylor-series}Suppose\n                                                                                          $\\displaystyle\\sum_{n=0}^\\infty a_n z^n$ is a power series with\n                                                                                            radius of convergence 1.  We say that series is \\textbf{universal}\n                                                                                              if, for every $\\epsilon > 0$ and $\\delta > 0$, for every closed disk\n                                                                                                $D_r(a)$ with $\\abs{a-1} > r$, for every holomorphic function\n                                                                                                  $f : B_{r + \\delta}(a) \\to \\C$, there exists $N$ so that\n                                                                                                    \\[\n                                                                                                        \\sup_{z \\in D_r(a)} \\abs{ f(z) - \\sum_{n=0}^N a_n z^n } < \\epsilon.\n                                                                                                          \\]\n\n                                                                                                            There is a universal power series.\n                                                                                                            \\end{problem}\n                                                                                                            \\begin{solution}\n                                                                                                            This is super false, since the power series isn't neccessarily the power series of $f$. For example, take $a_n=1$ and $f=0$, and consider the disk of radius .2 around the point $0$. Then $\\sum_{n=0}^N a_nz^n = 1 + \\sum_{n=1}^N 0^n = 1$ for any $N$ but $f(0) = 0$.\n\n                                                                                                            Let's choose $f$ first, and let the power series be the taylor series of $f$ at the point $0$. We can write it out using Cauchy's integral formula and a positively oriented curve $\\gamma$ around the circle of radius $r+\\delta$.\n\n                                                                                                            \\begin{align}\\label{Taylor_Series_0_for_f}\n                                                                                                                f(z) = \\sum_{n=0}^N \\int_\\gamma \\frac{f(w) dw}{w^{n+1}}z^n\n                                                                                                                \\end{align}\n\n                                                                                                                Now we just really need to show that this function approaches $f(z)$. We can apply Cauchy's integral formula to $f$ in a small circle $\\gamma_2$ centered at $z$ and contained in the circle $\\gamma$ .\n                                                                                                                \\begin{align}\\label{Cauchys_Integral_Formula_for_f}\n                                                                                                                    f(z) &= \\int_{\\gamma_2} \\frac{f(w) dw}{w - z}\n                                                                                                                    \\end{align}\n                                                                                                                    In fact, we can replace $\\gamma_2$ with $\\gamma$ since the two curves are homotopic on the set $\\C\\setminus z$ where the function $\\frac{f(w)}{w-z}$ is holomorphic. Thus we need to show that difference of the RHS of equations \\ref{Taylor_Series_0_for_f} and \\ref{Cauchys_Integral_Formula_for_f} is 0.\n\n                                                                                                                    \\begin{align*}\n                                                                                                                        \\int_{\\gamma} \\frac{f(w) dw}{w - z} - \\sum_{n=0}^N \\int_\\gamma \\frac{f(w) dw}{w^{n+1}}z^n &= \\int_\\gamma f(w)\\left( \\frac{1}{w-z} - \\sum_{n=0}^n \\frac{z^n}{w^{n+1}}\\right) dw\\\\\n                                                                                                                            &= \\int_\\gamma f(w)\\left( \\frac{1}{w-z} - \\frac{1/w}{1-\\frac{z}{w}}\\right) dw\\\\\n                                                                                                                                &= \\int_\\gamma 0 dw = 0\n                                                                                                                                \\end{align*}\n                                                                                                                                \\end{solution}\n                                                                                                                                \\end{document}\n\n", "meta": {"hexsha": "f2c444f02ea31076ab2d02e407aad59b4a131772", "size": 19014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol7.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/sol7.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/sol7.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": 92.7512195122, "max_line_length": 450, "alphanum_fraction": 0.3254444094, "num_tokens": 3700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.795658095217705, "lm_q1q2_score": 0.6698053878401566}}
{"text": "\\section*{Summary of Section 1}\n\\begin{itemize}\n  \\item Addition in $\\bbz/100$ is defined by the formula\n  \\begin{equation*}\n    \\tens{a_1}\\units{b_1} + \\tens{a_2}\\units{b_2}\n    =\n    \\tens{a_1 + a_2 + c(b_1, b_2)}\\units{b_1 + b_2}\n  \\end{equation*}\n  where $c: \\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$ is the ``carry'' function.\n  Unravelling the axioms of abelian groups we see that $c$ satisfies the following three identities:\n  \\begin{enumerate}\n    \\item $c(b_1, 0) = 0 = c(0,b_1)$,\n    \\item $c(b_1, b_2) = c(b_2, b_1)$,\n    \\item $c(b_1, b_2) + c(b_1 + b_2, b_3) = c(b_1 , b_2 + b_3) + c(b_2, b_3)$.\n  \\end{enumerate}\n  Such a function $c$ is called a \\emph{normalized, symmetric, 2-cocycle}.\n\n  \\item We now flip the tables and ``define'' an addition on the set of 2-digit numbers by the formula $\\tens{a_1}\\units{b_1} + \\tens{a_2}\\units{b_2}\n  =\n  \\tens{a_1 + a_2 + c(b_1, b_2)}\\units{b_1 + b_2}$ where $c$ is any normalized, symmetric, 2-cocycle.\n\n  \\item Examples:\n    \\begin{enumerate}\n      \\item $c(b_1, b_2) = \\left \\lfloor \\dfrac{b_1 + b_2}{10}  \\right \\rfloor $ defines the standard addition on $\\bbz/100$.\n      \\item $c(b_1, b_2) = 0$ defines the addition in which the set of 2-digit numbers becomes $\\bbz/10 \\times \\bbz/10$.\n      \\item $c(b_1, b_2) = k\\left \\lfloor \\dfrac{b_1 + b_2}{10}  \\right \\rfloor$ for any integer $k$ defines an addition on the set of 2-digit numbers, the isomorphism class of the resulting abelian group depends on $k \\mod 10$.\n      \\item $c(b_1, b_2) = b_1 b_2$ defines an addition on the set of 2-digit numbers, and resulting group is $\\bbz/20 \\times \\bbz/5$.\n    \\end{enumerate}\n\\end{itemize}\n\n\nThere are exactly 4 isomorphism classes of abelian groups of order 100:\n  \\begin{equation*}\n    \\bbz/100,\\quad \\bbz/50 \\times \\bbz/2, \\quad \\bbz/20 \\times \\bbz/5, \\quad \\bbz/10 \\times \\bbz/10.\n  \\end{equation*}\n\\begin{q*}\n  How do we know which abelian group is being created by using a particular addition?\n\\end{q*}\n\\begin{proof}[Answer]\n  The four groups $\\bbz/100$, $\\bbz/50 \\times \\bbz/2$, $\\bbz/20 \\times \\bbz/5$, $\\bbz/10$ can be differentiated in the following way:\n  $\\bbz/100$ contains an element of order 100,\n  $\\bbz/50 \\times \\bbz/2$ contains an element of order 50 but not of order 100,\n  $\\bbz/20 \\times \\bbz/5$ contains an element of order 20 but not of order 100,\n  the order of every element of $\\bbz/10 \\times \\bbz/10$ is at most 10.\n\\end{proof}\n", "meta": {"hexsha": "336a4b616ef7ad801653de68b2ba5ecd6637c64d", "size": 2414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01Summary.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": "01Summary.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": "01Summary.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": 52.4782608696, "max_line_length": 228, "alphanum_fraction": 0.6636288318, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148981, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6698053867222303}}
{"text": "\\subsection{Performance Measures} \\label{performance_measures}\n\nSince our proposed sliding window filter is tested on time series streams that contain various different gestures, we need to treat the described online gesture recognition challenge as multi-class problem.\nCommon performance measures for multi-class problems are $Precision_{\\mu}$, $Recall_{\\mu}$ and $F_{\\beta}score_{\\mu}$ \\cite{sokolova2009systematic}:\n\n\\begin{equation*}\n    Precision_{\\mu} = {\\sum \\limits_{i=1}^{l} tp_i}  \\bigg/  {\\sum \\limits_{i=1}^{l} (tp_i + fp_i)}\n\\end{equation*}\n\\begin{equation*}\n    Recall_{\\mu} = {\\sum \\limits_{i=1}^{l} tp_i} \\bigg/{\\sum \\limits_{i=1}^{l} (tp_i + fn_i)}\n\\end{equation*}\n\\begin{equation*}\n    F_{\\beta}score_{\\mu} = {(\\beta^2 + 1)Precision_{\\mu} Recall_{\\mu}} \\bigg/ {\\beta^2 Precision_{\\mu} + Recall_{\\mu}}\n\\end{equation*}\n\nwhere $\\beta$ is usually set to one and $l$ denotes the number of classes that require separate computation of true positives ($tp$), false positives ($fp$), and false negatives ($fn$).\nThese multi-class performance measures allow us to compare and rank the results for different parameter settings.\nFor our evaluation we employ the $F_{1}score_{\\mu}$, which weights $Precision_{\\mu}$ and $Recall_{\\mu}$ equally.\n", "meta": {"hexsha": "4f01094b5eaf6adf114f5da817e89777188a9344", "size": 1250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/evaluation/performance_measures.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/performance_measures.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/performance_measures.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": 65.7894736842, "max_line_length": 206, "alphanum_fraction": 0.7224, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6697998245699255}}
{"text": "\\subsection{Terminology, notation, and the inverse problems}\nWe provide a summary of the notation, definitions, problem-formulation, and assumptions that reoccur throughout this work.\nFor more details on the original sources and derivations,  we refer the interested reader to \\cite{BES12, BE13, BET+14, BJW18a, BWY20}.\nTo make comparisons more clear, we first introduce shared notation between the SIP and Bayesian inverse problems.\n\n\nLet $u$ be the solution to a model, mathematically represented by $\\M(u, \\param) = 0$, where $\\param$ represents a parameter into such a model, e.g. the permeability of the medium in the subsurface through which a contaminant is spreading.\nSuch parameters are often uncertain, and we begin the quantification of uncertainty by identifying the set of all physically plausible parameters denoted by $\\pspace\\subset\\RR^\\dimP$.\nSince different choices of $\\param \\in \\pspace$ often lead to different model solutions, we write $u\\lam$ to make this dependence on the parameter space explicit.\n\nIn general, we cannot observe the entire solution $u(\\param)$ due to practical limitations.\nFor example, one cannot observe air pressure at every point throughout a room, but one can perform experiments and take measurements to infer pressure at specific locations within the room.\nPut more precisely, we are often limited in our ability to observe data related to some QoI that are mathematically defined as functionals of $u\\lam$.\nWe let $\\qoi$ denote the (potentially vector-valued) QoI map from the solution space of the model to the space of observable data.\n\nThen, given $\\param \\in \\pspace$, we obtain $u\\lam$ and compute $\\qoi(u\\lam)$ to get the QoI predicted by the model.\nThe QoI map depends on $\\param$ through the dependency of $u$ on $\\param$, so we write $\\qlam$ to simplify our notation.\nWe generally assume this map is at least piecewise-differentiable.\nThe data space $\\dspace \\subset \\RR^\\dimD$ is defined as the range of the QoI map $\\qoi$, i.e.\n\\[\n\\dspace = \\qoi(\\pspace).\n\\]\nIn other words, we use $\\dspace$ to denote the space of all physically plausible data for the QoI that the model can predict.\n\n\nLet $\\pborel$ and $\\dborel$ denote (the Borel) $\\sigma$-algebras on $\\pspace$ and $\\dspace$, respectively.\nA $\\sigma$-algebra is a collection of subsets representing the set of all measurable events, i.e., events for which it makes sense to assign a probability.\nThe map $\\qoi$ between measurable spaces $(\\pspace, \\pborel)$ and $(\\dspace, \\dborel)$ is immediately measurable by the smoothness assumption.\nThen, equipping $\\pspace$ and $\\dspace$ with (dominating) measures $\\pmeas$ and $\\dmeas$, respectively, is the final necessary component for constructing the Radon--Nikodym derivatives defining probability density functions (pdfs) from probability measures defined on the measure spaces $(\\pspace, \\pborel, \\pmeas)$ and $(\\dspace, \\dborel, \\dmeas)$.\nIn practice, $\\pmeas$ and $\\dmeas$ are often taken to be Lebesgue measures when $\\pspace$ and $\\dspace$ are finite-dimensional~\\cite{BET+14, BJW18a}.\nIn general, these measure allow for the description of commonly known probability measures as familiar pdfs.\n\n\\subsection{Problem Formulation and Solution}\nWe begin with defining the types of forward and inverse problems considered in this thesis.\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}\n  Given 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\n  \\noindent Any probability measure $\\PP_\\pspace$ satisfying \\eqref{eq:inverse-problem} is referred to as a \\emph{consistent solution} to the inverse problem, and \\eqref{eq:inverse-problem} is referred to as the \\emph{consistency condition}.\n  If $\\PP_\\pspace$ or $\\PP_\\dspace$ are absolutely continuous with respect to $\\pmeas$ or $\\dmeas$, respectively, 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 (i.e., pdfs) of $\\PP_\\pspace$ and $\\PP_\\dspace$, respectively.\n  In such a case, we can rewrite \\eqref{eq:forward-problem} and \\eqref{eq:inverse-problem} using these pdfs. For example, here is a variant of \\eqref{eq:inverse-problem} using these pdfs:\n\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), \\; \\forall \\; E \\in \\mathcal{B}_\\dspace.\n  \\end{equation*}\n\\end{defn}\n\n\\subsubsection{The Stochastic Inverse Problem (SIP)}\n\nIn measure-theoretic terms, $\\PP_\\dspace$ in Definition~\\ref{defn:forward-problem} is a push-forward measure of $\\PP_\\pspace$, and in Definition~\\ref{defn:inverse-problem}, $\\PP_\\pspace$ is a pull-back measure of $\\PP_\\dspace$.\nFrom the perspective of a forward problem, we seek $\\PP_\\pspace$ such that its \\emph{push-forward measure is equivalent to} $\\PP_\\dspace$.\nIn other words, \\emph{the solution we seek to the inverse problem is constrained by a forward problem.}\nBelow, we formalize some of the vocabulary involved in the formulation and solution of the SIP.\nWe refine the concept of push-forward measures as solutions to the SFP mentioned in the introduction, formally introducing the requisite vocabulary of \\emph{initial}, \\emph{observed}, and \\emph{predicted} densities.\nThis helps frame the SIP more clearly as the direct inversion of the SFP.\n\n\\begin{defn}[Observed Distribution]\\label{defn:observed}\n  When the measure $\\PP_\\dspace$ in \\eqref{eq:inverse-problem} is defined by the quantitative characterization of uncertainty in the QoI data, it is referred to as the \\emph{observed measure}, $\\observedP$.\n  If a dominating measure $\\mu_\\dspace$ exists on $(\\dspace, \\dborel)$, the \\emph{observed density} $\\observed$ is given by the Radon-Nikodym derivative of $\\observedP$ with respect to the measure $\\dmeas$.\n\\end{defn}\n\n%%%%%%%%%%%%%%%%%%%\n\nThe map $\\qoi$ impacts the structure of any solution to the SIP since the underlying data space $\\dspace$ itself depends on $\\qoi$.\nIn the event that the map $\\qoi$ is a bijection, then the consistency condition \\eqref{eq:inverse-problem} defines a unique measure $\\PP_\\pspace$ given the specification of an observed density.\nHowever, there are many applications of interest where $\\qoi$ fails to be a bijection, either due to differences in the dimensions of the parameter and data spaces, nonlinearities inherent in the model itself, or both.\n\n%%%%%%%%%%%%%%%%%%%\n\nTherefore, we do not generally expect that there is a unique $\\mathbb{P}_\\pspace$ solving the SIP in Definition~\\ref{defn:inverse-problem}, but rather there is a class of pullback measures that solve the SIP.\nIn \\cite{BET+14}, a disintegration theorem \\citep{Chang_Pollard, Dellacherie_Meyer_book} along with an ansatz is used to establish the existence of solutions to the SIP that are unique up to the choice of ansatz.\nAn algorithm is provided in \\cite{BET+14} for explicitly approximating pullback measures by applying a specified ansatz to approximations of contour events, i.e., approximations of $Q^{-1}(E_i)$ where $\\set{E_i}_{i\\in\\mathcal{I}}$ is a partitioning of $\\dspace$ according to some (finite) index set $\\mathcal{I}$.\nIn \\cite{BJW18a}, a density-based approach is presented that is computationally simpler to implement, and scales well with increasing parameter dimension\n% The solution to the SIP presented there is a direct inversion of a SFP; we introduce the following definitions to connect the result to general forms presented in \\ref{defn:forward-problem} and \\ref{defn:inverse-problem}:\nThe density-based approach makes explicit use of a solution to the SFP in constructing a solution to the SIP.\nWe make use of the following definitions in this approach.\n\n\\begin{defn}[Initial Distribution]\\label{defn:initial}\n  When the measure $\\PP_\\pspace$ in \\eqref{eq:forward-problem} is defined by the quantitative characterization of uncertainty in parameter variability before observations on QoI are taken into account, it is referred to as the initial measure $\\initialP$.\n  If a dominating measure $\\mu_\\pspace$ exists on $(\\pspace, \\pborel)$, the \\emph{initial distribution} $\\initial$ is given by the Radon-Nikodym derivative of $\\initialP$ with respect to the measure $\\pmeas$.\n\\end{defn}\n\n\nTo construct a density-based solution to the SIP, we first push-forward the initial density using the QoI map.\nIn other words, we first solve the SFP of \\eqref{eq:forward-problem}.\nWe refer to the push-forward of the initial measure as the \\emph{predicted measure} since it may be constructed before any observed data are known.\nThis also helps to distinguish it from the {\\em observed} measure used in the formulation of the SIP.\nTo make this precise, we use the following:\n\n\\begin{defn}[Predicted Distribution]\\label{defn:predicted}\n  The push-forward density of $\\initial$ under the map $\\qoi$ is denoted as $\\predicted$, and is referred to as the \\emph{predicted distribution} (or density).\n  It is given as the Radon-Nikodym derivative (with respect to $\\dmeas$) of the push-forward probability measure \\eqref{eq:forward-problem} given by\n  \\begin{equation}\\label{eq:predicted}\n    \\predictedP (E) = \\initialP \\left ( \\qoi^{-1}(E) \\right ), \\; \\forall \\; E \\in \\dborel.\n  \\end{equation}\n\\end{defn}\n\n%%%%%%%%%%%%%%%%%%%\nWe now have all of the definitions required to summarize the density-based solution to the SIP, known as the \\emph{updated density} as:\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%%%%%%%%%%%%%%%%%%%\nWe refer the interested reader to \\cite{BJW18a} for the theoretical and algorithmic details of implementing the solution to the SIP, though some are summarized in \\ref{sec:properties}.\nFor now, we note that the solution in \\eqref{eq:updated-pdf} is stable with respect to perturbations in the initial and observed probability measures, and that the solution given by \\eqref{eq:updated-pdf} requires only the forward-problem construction of $\\predicted$, since $\\initial$ and $\\observed$ are specified in the SIP.\nAdditional properties of $\\updated$ are given in \\ref{sec:properties} alongside the conditions for the existence and uniqueness of $\\updated$ of the form given by \\eqref{eq:updated-pdf}.\n%%%%%%%%%%%%%%%%%%%\n\nIn order to ensure that $\\updated$ is in fact a density, a predictability assumption is required \\cite{BJW18a}.\nA practical form of the predictability assumption is that there exists a constant $C>0$ such that $\\observed(q)\\leq C\\predicted(q)$ for $\\text{ a.e. } q\\in\\dspace$.\nConceptually, we interpret the predictability assumption as stating that we are able to predict the observed data.\nThis also helps to frame the special role of $\\initial$ in the SIP compared to the role of the prior density used in the Bayesian inverse problem that is discussed below.\nSpecifically, $\\initial$ allows us to perform (1) robust predictions, and (2) define a particular data-consistent solution.\n\n\n%%%%%%%%%%%%%%%%%%%\n\n\n\\subsubsection{The Deterministic Inverse Problem (DIP)}\nA typical Bayesian approach to an inverse problem focuses on first modeling epistemic uncertainties in data on a QoI obtained from a true, but unknown, parameter value, which we denote by $\\paramref$.\nThis is in contrast to the SIP and its data-consistent solutions that are defined as pullback measures of an observed probability measure on the QoI.\nTo make the distinction between the two approaches more clear, we introduce the following two definitions to frame the problems addressed by the Bayesian framework:\n\n\n\\begin{defn}[Deterministic Forward Problem (DFP)]\n  Given a space $\\pspace$, and QoI map $\\qoi$, the \\emph{deterministic forward problem} is to determine the values, $\\q \\in \\dspace$ that satisfy\n  \\begin{equation}\n    \\q = \\qlam, \\; \\forall \\; \\param \\in \\pspace.\n  \\end{equation}\n\\end{defn}\n\n\\begin{defn}[Deterministic Inverse Problem (DIP) Under Uncertainty]\n  Given a noisy datum (or data-vector) $d = \\q + \\xi$, $\\q \\in \\dspace$, the \\emph{deterministic inverse problem} is to determine the parameter $\\param \\in \\pspace$ which minimizes\n  \\begin{equation}\n    \\norm{\\qoi(\\param) - d}\n  \\end{equation}\n  where $\\xi$ is a random variable (or vector) drawn from a distribution characterizing the uncertainty in observations due to measurement errors.\n\\end{defn}\n\nIn the above definition, $\\xi$ is some unobservable perturbation to the true output, arising from epistemic uncertainty (e.g. the precision of available measurement equipment).\nThe Bayesian inversion framework  is perhaps the most popular approach in the UQ community for incorporating uncertainties in inverse solutions.\nAs mentioned in the introduction, the data-consistent framework developed in \\cite{BJW18a, BJW18b, BWY20} is designed to quantify aleatoric sources of uncertainty while the typical Bayesian framework \\citep{0266-5611-7-5-003,\n Kennedy_O_JRSSSB_2001, MNR07, CDS10, starktenorio,\n AlexanderianPetraStadlerEtAl14, Bui-ThanhGhattas14, Ernst2014,\n 0266-5611-30-11-110301, ROM:CMW_2016, Stuart10,\n cockayneoatessullivangirolami} is designed to quantify epistemic sources of uncertainty.\nThese conceptual differences have significant impacts on the solutions to inverse problems formulated within these distinctive frameworks.\n% To help build intuition about these differences, we summarize key details about the SIP and its solution before presenting an example that highlights differences in solutions.\nWe provide more details in Section~\\ref{sec:compare} to further clarify these impacts for the reader.\n%An example is then used to illustrate the differences, which is also helpful for building intuition.\nMoreover, the details provided below play a vital role in Section~\\ref{sec:estimation} where features of the data-consistent framework are used to motivate its extension to parameter estimation problems.\n\n\\FloatBarrier\n", "meta": {"hexsha": "560b031f4521983438da72562e99f8ecd9568599", "size": 14652, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro/framework.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/framework.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/framework.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.1882352941, "max_line_length": 349, "alphanum_fraction": 0.7609200109, "num_tokens": 3825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6697188106867732}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{fullpage}\n\\usepackage{amsmath}\n\\usepackage{amsmath}\n\n%\\usepackage{amsymbols}\n\n\\begin{document}\n\\section{Review}\nChange of Bases: \n$$\n\\mathcal{B} \\{b_1, b_2, \\dots b_n \\} \\longrightarrow B \\{b_1|b_2\\dots|b_n\\}\n$$\n$$\n\\mathcal{C} \\{c_1, c_2, \\dots c_n \\} \\longrightarrow C \\{c_1|c_2\\dots|c_n\\}\n$$\n\n\nDiagnolization:\n$$\nA \\in C^{n \\times n}\n$$\n\n$A$ is diagnolizable if $\\exists$ $X \\in C^{n\\times n}$ duch that $det (X) \\neq 0$ \n\n$v \\in C^{n \\times n}$ \n\n$ [v] = B[v]_B$ \n\n$[v]_B = B^{-1}[v]$ \n\n$[v]_C = C^{-1}B[v]_B$\n\n\n$A = X\\Lambda X^{-1}$ , $\\Lambda = diag(\\lambda_1, \\lambda_2, \\dots \\lambda_n)$\n$\\Lambda = X^{-1}AX$\n\n\nDiagnolization is like change of basis\n\n$$\nA[v] = X\\Lambda X^{-1}[v]/[v]_X = [\\Lambda v]_X/[\\Lambda v]\n$$\n\n\\textbf{Claim: }If spectrum of $A$, $card(\\sigma(A)) = n i.e.(\\lambda_i \\neq \\lambda_j, i \\neq j)$ then $A$ is diagonizable(non-defective)\n\n\\textbf{Proof:} Do induction on \\# of eigen vector\n\n$\\lambda_1 \\neq \\lambda_2$\n$c_1\\vec{X}_1 + c_2\\vec{X}_2 = 0$; $c_1,c_2 \\neq 0$ \n\n$c_1A\\vec{X}_1 + c_2A\\vec{X}_2 =0$\n\n$c_1\\lambda_1\\vec{X}_1 + c_2\\lambda_2\\vec{X}_2 =0$\n\n$-c_1\\lambda_2\\vec{X}_1 + c_2\\lambda_2\\vec{X}_2 =0$\n\n $c_1(\\lambda_1-\\lambda_2)\\vec{X}_1=0$ $->$ Contradiction\n \n Assume truth for $k=1$\n \n $\\sum_{i=1}^k c_i \\vec{X}_i = 0$ $c_i is not zero$\n \n In particular, at least one of $c_i$ is not zero\n \n \\begin{align*}\n\\sum_{i}c_i\\lambda_i X_i &= 0\\\\\n0 &= \\lambda_k 0 - 0\\\\\n&= \\lambda_k \\sum c_iX_o - \\sum_i c_i \\lambda_i X_i\\\\\n&= \\sum_i c_i(\\lambda_k - \\lambda_i)X_i\\\\ contradiction\n\\end{align*}\n\n$X_i$ are independent, hence follows.\n\n\\section{Interpretation}\nAssume $A \\in C^{n \\times n} \\text{ and } \\vec{b} \\in C^n$ ; $det(A) \\neq 0$\n\n$AX = \\vec{b}$\n\nBest case:\n\\begin{itemize}\n\\item $A$ is diagnolizable\n\\item $A$ is triangular(upper/lower)\n\\end{itemize}\n\nProperties:\n\\begin{itemize}\n\\item Production of 2 upper triangle is upper triangular\n\\item Inverse of non singular upper triangular is upper triangular\n\\end{itemize}\n\nArgument of (2):\n\\begin{align*}\nSX &= I\\\\\n[SX_1, SX_2, \\dots, SX_n] &= [e_1,e_2, \\dots e_n] (Std basis)\\\\\nS\\vec{X}_i &= \\vec{e}_i\n\\end{align*}\n\nElementary row operations\n\n\\begin{itemize}\n\\item R1 Multiply on RHS by a constant\n\\item R2 Exchanging two rows\n\\item R3 add non zero multiple of one to another\n\\end{itemize}\n\n(R2)Permutation matrix: exactly one 1 in row or column -> Not lower or upper traingular. But holds for R1,R3\n\n\n\nLU decomposition $[L_1, L_2,L3]A = U$ $\\hat{L}A = U$\n$A = LU$\n$L=\\hat{L}^{-1}$\n\n$AX =b -> Ly= b -> UX=y$\n\nTwo factorization:\n1. $A = X\\Lambda X^{-1}$ when $X$ is non-defective\n2. $A = LU$, when $A$ is square and not of permutation type.\n\n\n\\section{Norms}\n\nAbsolute value:\n\\begin{align*}\n|a| &\\geq 0 \\\\\n|a| &=0 -> a=0,\\\\\n|ab| & = |a||b|\\\\\n|x+y| \\leq |x|+|y|\n\\end{align*}\n\nNorm:\n\\begin{itemize}\n\\item Norm is  mapping $||. || : V -> R$ $V over C$\n\\item ||0||: V ->R\n\\item $||\\vec{v}|| \\geq 0, ||v|| = 0$ iff $v=0$\n\\item $||c\\vec{v}|| = |c|||\\vec{v}||$\n\\item $||\\vec{v}+\\vec{w}|| \\leq ||\\vec{v}|| + ||\\vec{w}||$\n\\end{itemize}\n\n$p$ norm:\n$p \\leq \\infty$\n\n$||\\vec{v}||_p = \\sum (|v_i|^p)^{1/p}$\n\n$||v||_{\\infty} = max|V_i|$ $1 \\leq i \\leq n$ \n\n\n\\textbf{Clasim:} $||v||_p$ is a norm\n\\end{document}\n", "meta": {"hexsha": "f7950c2f7ce91f8ee5f14c808af1148c4d1c8aeb", "size": 3244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Fall/MATH-574/lecture3.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/MATH-574/lecture3.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/MATH-574/lecture3.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": 21.3421052632, "max_line_length": 138, "alphanum_fraction": 0.6155980271, "num_tokens": 1395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.669718801703418}}
{"text": "\\subsubsection{Adaptive Naive Bayes Classifier} \\label{sec:anbc} ANBC \\cite{14} is a supervised learning algorithm that can be used to classify any type of N-dimensional signal. It is based on simple probabilistic classifier called Naive Bayes classifier. It fundamentally works by fitting an N-dimensional Gaussian distribution to each class during the training phase. New gestures can then be recognized in the prediction phase by finding the gesture that results.\n\nANBC like Naive Bayes classifier makes a number of basic assumptions with input data that all the variables in the data are independent. However, despite these naive assumptions, Naive Bayes Classifiers have proved successful in many real-world classification problems \\cite{15}. It has also been shown in a study that the Naive Bayes Classifier not only performs well with completely independent features, but also with functionally dependent features.\n\nANBC algorithm is based on Bayes theory and gives the likelihood of event $A$ occurring, given the observation of event $B$. In the equation \\ref{eq:grt:bayes}, $P(A)$ represents the prior probability of event $A$ occurring and $P(B)$ is a normalizing factor to ensure that all the posterior probabilities sum to 1.\n\n\\input{chapter/equations/grt-bayes}\n\n\\paragraph*{Training} The weighting coefficient adds an important feature for the ANBC algorithm as it enables one general classifier to be trained with multidimensional inputs, even if a number of inputs are only relevant for one particular gesture. For example, if it is used to recognize hand gestures, the weighting coefficients would enable the classifier to recognize both left and right hand gestures independently, without the position of the left hand affecting the classification of a right-handed gesture. For example, hand gesture recognition using x,y,z position of palms of Left and Right hand will have 6 dimensional sample. In this case left hand gestures will have weights {1,1,1,0,0,0}, right hand gestures will have weights {0,0,0,1,1,1} and both hand gestures will have weights {1,1,1,1,1,1}.\n\nUsing the weighted Gaussian model, the ANBC algorithm requires $G(3N)$ parameters, assuming that each of the $G$ gestures require specific values for the N-dimensional $ \\mu_{k} , \\sigma_{k}^{2} $ and $ \\phi_{k} $ vectors where $ \\mu_{k} , \\sigma_{k}^{2},\\phi_{k}$ are mean, variance and weighting coefficients. Assuming that $ \\phi_{k} $ is set by the user, $ \\mu_{k} $ and $\\sigma_{k}^{2} $ values can easily be calculated in a supervised learning scenario by grouping the input training data $X$ into a matrix containing $M$ training examples each with $N$ dimensions, into their corresponding classes. The values for $ \\mu$ and $\\sigma^{2} $of each dimension $n$ for each class $k$ can then be estimated by computing the mean and variance of the grouped training data for each of the respective classes \\cite{14}.\n\n\\input{chapter/equations/grt-gauss}\n\nAfter the Gaussian models have been trained for each of the $G$ classes, an unknown N-dimensional vector $x$ can be classified as one of the $G$ classes using the maximum a posterior probability estimate (MAP). MAP estimate classifies $x$ as the $k$-th class that results in the maximum a posterior probability given by the equation \\ref{eq:grt:gauss}\n\n\\input{chapter/equations/grt-threshold}\n\n\\paragraph*{Rejection Threshold} Using equation \\ref{eq:grt:threshold}, an unknown N-dimensional vector $x$ can be classified as one of the $G$ classes from a trained ANBC model. If $x$ actually comes from an unknown distribution that has not been modeled by one of the trained classes then, it will be incorrectly classified against the $k$ th gesture that gives the maximum likelihood value. A rejection threshold must therefore be calculated for each of the $G$ gestures to enable the algorithm to classify any of the $G$ gestures from a continuous stream of data that also contains non-gestural data \\cite{14}.\n\n\\paragraph*{Online Training} One key element of ANBC is that it can easily be made adaptive. Adding an adaptive online training phase to the common two-phase (training and prediction) provides some significant advantages for the recognition gestures. During online training phase the algorithm will not only perform real-time predictions on the continuous stream of input data, but it will also continue to train and refine the models for each gesture. This enables the user to initially train the algorithm with a low number of training samples and during the adaptive online training phase, the algorithm can continue to train and refine the initial models, creating a more robust model as the number of training samples increases.\n\n\\paragraph*{Pros / Cons} ANBC works well for the classification of static gestures and non-temporal pattern recognition. However, the main limitation of the ANBC is that, it does not work well when the data you want to classify, is not linearly separable because it uses a Gaussian distribution to represent each class. Also when ANBC is working with online training enabled, a small number of incorrectly labeled training examples can create a loose model that becomes less effective at each update step and ultimately lead to a poor performance and accuracy.\n\n\\subsubsection{Gesture Recognition Toolkit (GRT)} \\label{sec:grt} GRT is a cross-platform open-source C++ library designed and developed mainly by Nicholas Gillian at MIT Media Lab to make real-time machine learning and gesture recognition \\cite{16}. Emphasis is placed on the ease of use with a consistent, minimalist design that promotes accessibility while supporting flexibility and customization for advanced users. The toolkit features a broad range of classification and regression algorithms, and has extensive support for building real-time systems. GRT includes algorithms for signal processing, feature extraction and automatic gesture spotting. \n\nIn this thesis, we attempt to take advantage of GRT as framework to carry out most of the tasks involved in hand gesture recognition. Figure \\ref{fg:grt:pipeline} shows that GRT provides the full fledge pipeline to build a real-time gesture recognition system. \n\n\\input{chapter/figures/grt-pipeline}\n\n\\paragraph*{Pipeline} GRT provides an API to reduce the need for boilerplate code to perform common functionality, such as passing data between algorithms or to per-process data sets. GRT uses an object-oriented modular architecture and it is built around a set of core modules and a gesture-recognition pipeline. The input to both the modules and pipeline consists of an N-dimensional double-precision vector, making the toolkit flexible to any type of input signal. The algorithms can be used as stand-alone classes; alternatively a gesture recognition pipeline can be used to chain modules together to create a more sophisticated gesture recognition system. Modularity of GRT pipeline offers developers opportunities to work on each stages of gesture recognition independently. Additionally, pipeline can be stored and loaded dynamically so that an compiled application can work in many different configurations. \n\n\\paragraph*{ClassificationData} Accurate labeling of dataset is very critical for machine learning problems. The toolkit thus contains an extensive support for recording, labeling and managing supervised and unsupervised datasets for classification, regression and time series analysis. \\textit{ClassificationData} is the data structure used for supervised learning problems and for most of the non temporal classification algorithms.\n\nGRT allows us to store and load the training data in GRT format or Comma Separated Values (CSV). Since the training datasets are stored in human readable format, it enables us to add more samples which are collected separately or remove false data from the training dataset.\n\n\\paragraph*{TrainingDataRecordingTimer} Important part of the training phase is recording positive samples of modeled hand gestures. Hence, GRT provides a feature called \\textit{TrainingDataRecordingTimer} that sets recording and preparation time in milliseconds. Once it is started by calling \\textit{startRecording(prepationTime, recordTime)} method, it waits for given preparation time before it actually starts to store the data. This feature helps the trainer get into the right pose before samples are added to the training data and as well as train all the gestures for the same time duration.\n\n\\paragraph*{Algorithms} GRT features a broad range of machine-learning algorithms such as AdaBoost, Decision Trees, Dynamic Time Warping (DTW), Hidden Markov Models (HMM), K-Nearest Neighbor (KNN), Linear and Logistic Regression, Adaptive Naive Bayes (ANBC), Multilayer Perceptrons (MLP), Random Forests and Support Vector Machines (SVM) \\cite{16}. \n\n\\paragraph*{Null Rejection} Another important feature of GRT is Null Rejections threshold. It means that algorithms can automatically spot the difference between trained gestures and unintended gestures that can happen when the user moves the hand in freely. It can be enabled by the method \\textit{enableNullRejection(true)} and the range of the null rejection region can be set by this method \\textit{setNullRejectionCoeff(double nullRejectionCoeff)} of the classifier. Algorithm such as the ANBC and N-Dimensional DTW, learn rejection thresholds from the training data, which are then used to automatically recognize valid gestures from a continuous stream of real-time data.\n\n\\input{chapter/figures/grt-null}\n\nFigure \\ref{fg:grt:null} shows that the decision boundaries computed by training six of classification algorithms on an example dataset with 3 classes. After training each classifier, each point in the two-dimensional feature space is colored by the likelihood of the predicted class label (red for class 1, green for class 2, blue for class 3). The top row shows the predictions of each classifier with null rejection disabled. The bottom row shows the predictions of each classifier with null rejection enabled with a coefficient of 3.0. Rejected points are colored white. Note that both the decision boundaries and null-rejection regions are different for each of the classifiers. This results from the several learning and prediction algorithms used by each classifier. \n\n\\paragraph*{Scaling Normalization} Real-time classification faces normalization problems when the range of training data differ from prediction input. To solve this problems, there are few solutions such as Z-score Standardization and Feature Scaling. GRT presents a simple solution called as Minimum-Maximum scaling.\n\nMin-Max scaling rescales the range in [0, 1] or [-1, 1]. Selecting the target range depends on the nature of the data. Classifiers \\textit{enableScaling(true)} method scales input vector between the default min-max range that is from 0 to 1. The cost of having this bounded range is that model will end up with smaller standard deviations, which can suppress the effect of outliers. Equation \\ref{eq:grt:scaling} shows how Min-Max scaling is done.\n\n\\input{chapter/equations/grt-scaling}\n\n\\paragraph*{Pre/Post Processing Modules} In many real-world scenarios, the input to a classification algorithm must be preprocessed and have salient features extracted. GRT therefore supports a wide range of pre/post-processing modules such as Moving Average Filter, Class Label Filter and Class Label Change Filter, embedded feature extraction algorithms such as AdaBoost, dimensionality reduction techniques such as Principal Component Analysis (PCA) and unsupervised quantizers such as K-Means Quantizer, Self-Organizing Map Quantizer.\n\nThere will not be any need of preprocessing modules in this project since raw data received from depth sensor is processed by NiTE framework. However, post-processing modules such as Class Label Filter and Class Label Change Filter may be needed for a reasons that depth sensor samples 30 frames per second, therefore 30 input samples per second are supplied to the classifier for prediction and the output must be triggered once for every gesture. \n\n\\input{chapter/figures/grt-label-filter}\n\n\\paragraph*{Class Label Filter} It is a useful post-processing module which can remove erroneous or sporadic prediction spikes that may be made by a classifier on a continuous input stream of data. Figure \\ref{fg:grt:label} that the classifier correctly outputs the predicted class label of 1 for a large majority of the time that a user is performing gesture 1. However, may be due to sensor noise or false samples in the training data, the classifier outputs the class label of 2. In this instance the class label filter can be used to remove these sporadic prediction values with the output of the class label filter in this instance being 1. \n\nClass Label Filter module is controlled through two parameters: the minimum count value and buffer size value. The minimum count sets the minimum number of label values that must be present in the buffer to be output by the Class Label Filter. The size of the class labels buffer is set by the buffer size parameter. If there is more than one type of class label in the buffer then the class label with the maximum number of instances will be output. If the maximum number of instances for any class label in the buffer is less than the minimum count parameter then the Class Label Filter will output the default null rejection class label of 0.\n\n\\input{chapter/figures/grt-label-change-filter}\n\n\\paragraph*{Class Label Change Filter} It is one of the useful post-processing module that triggers when the predicted output of a classifier changes. Figure \\ref{fg:grt:label:change}shows that, if the output stream of a classifier is {1,1,1,1,2,2,2,2,3,3}, then the output of the filter would be {1,0,0,0,2,0,0,0,3,0}. This module is useful to trigger a gesture once, if the user is gesticulating the same gesture for longer time duration. If the user intends to trigger the same gesture again, then hand position must be changed to another such as pointing the hand towards the ground, and gesticulate the gesture again.\n\n\\paragraph*{GUI} Figure \\ref{fg:grt:gui} shows GRT-GUI which is an application that provides an easy-to-use graphical interface developed in C++ to setup and configure a gesture recognition pipeline that can be used for classification, regression, or time-series analysis. Data and control commands are streamed in and out of this application as Open Sound Control (OSC) packets via UDP . Therefore, it acts as a standalone application to record, label, save, load and test the training data and performs a real-time prediction for the incoming data, send output to another application. \n\n\\input{chapter/figures/grt-gui} \n", "meta": {"hexsha": "7931d81c04f91fdba0878e8e48cccf6a5c198813", "size": 14717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/thesis/chapter/content/background/grt.tex", "max_stars_repo_name": "AravinthPanch/gesture-recognition-for-human-robot-interaction", "max_stars_repo_head_hexsha": "42effa14c0f7a03f460fba5cd80dd72d5206e2a8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2016-05-26T16:19:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T12:52:09.000Z", "max_issues_repo_path": "document/thesis/chapter/content/background/grt.tex", "max_issues_repo_name": "AravinthPanch/gesture-recognition-for-human-robot-interaction", "max_issues_repo_head_hexsha": "42effa14c0f7a03f460fba5cd80dd72d5206e2a8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-11-20T13:28:59.000Z", "max_issues_repo_issues_event_max_datetime": "2017-11-22T13:52:50.000Z", "max_forks_repo_path": "document/thesis/chapter/content/background/grt.tex", "max_forks_repo_name": "AravinthPanch/gesture-recognition-for-human-robot-interaction", "max_forks_repo_head_hexsha": "42effa14c0f7a03f460fba5cd80dd72d5206e2a8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 35, "max_forks_repo_forks_event_min_datetime": "2015-06-25T08:51:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T04:47:16.000Z", "avg_line_length": 210.2428571429, "max_line_length": 916, "alphanum_fraction": 0.8070258884, "num_tokens": 3086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6697188004651513}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{The fundamental theorem of identity types}\\label{chap:fundamental}\n\\sectionmark{The fundamental theorem}\n\n\\index{fundamental theorem of identity types|(}\n\\index{characterization of identity type!fundamental theorem of identity types|(}\nFor many types it is useful to have a characterization of their identity types. For example, we have used a characterization of the identity types of the fibers of a map in order to conclude that any equivalence is a contractible map. The fundamental theorem of identity types is our main tool to carry out such characterizations, and with the fundamental theorem it becomes a routine task to characterize an identity type whenever that is of interest.\n\nIn our first application of the fundamental theorem of identity types we show that any equivalence is an embedding. Embeddings are maps that induce equivalences on identity types, i.e., they are the homotopical analogue of injective maps. In our second application we characterize the identity types of coproducts.\n\nThroughout the rest of this book we will encounter many more occasions to characterize identity types. For example, we will show in \\cref{thm:eq_nat} that the identity type of the natural numbers is equivalent to its observational equality, and we will show in \\cref{thm:eq-circle} that the loop space of the circle is equivalent to $\\Z$.\n\nIn order to prove the fundamental theorem of identity types, we first prove the basic fact that a family of maps is a family of equivalences if and only if it induces an equivalence on total spaces. \n\n\\subsection{Families of equivalences}\n\n\\index{family of equivalences|(}\n\\begin{defn}\nConsider a family of maps\n\\begin{equation*}\nf : \\prd{x:A}B(x)\\to C(x).\n\\end{equation*}\nWe define the map\\index{total(f)@{$\\tot{f}$}}\n\\begin{equation*}\n\\tot{f}:\\sm{x:A}B(x)\\to\\sm{x:A}C(x)\n\\end{equation*}\nby $\\lam{(x,y)}(x,f(x,y))$.\n\\end{defn}\n\n\\begin{lem}\\label{lem:fib_total}\n  For any family of maps $f:\\prd{x:A}B(x)\\to C(x)$ and any $t:\\sm{x:A}C(x)$,\n  there is an equivalence\\index{fiber!of total(f)@{of $\\tot{f}$}}\\index{total(f)@{$\\tot{f}$}!fiber}\n  \\begin{equation*}\n    \\eqv{\\fib{\\tot{f}}{t}}{\\fib{f(\\proj 1(t))}{\\proj 2(t)}}.\n  \\end{equation*}\n\\end{lem}\n\n\\begin{proof}\n  For any $p:\\fib{\\tot{f}}{t}$ we define $\\varphi(t,p):\\fib{\\proj 1(t)}{\\proj 2(t)}$ by $\\Sigma$-induction on $p$. Therefore it suffices to define $\\varphi(t,(s,\\alpha)):\\fib{\\proj 1(t)}{\\proj 2 (t)}$ for any $s:\\sm{x:A}B(x)$ and $\\alpha:\\tot{f}(s)=t$. Now we proceed by path induction on $\\alpha$, so it suffices to define $\\varphi(\\tot{f}(s),(s,\\refl{})):\\fib{f(\\proj 1(\\tot{f}(s)))}{\\proj 2(\\tot{f}(s))}$. Finally, we use $\\Sigma$-induction on $s$ once more, so it suffices to define\n  \\begin{equation*}\n    \\varphi((x,f(x,y)),((x,y),\\refl{})):\\fib{f(x)}{f(x,y)}.\n  \\end{equation*}\n  Now we take as our definition\n  \\begin{equation*}\n    \\varphi((x,f(x,y)),((x,y),\\refl{}))\\defeq(y,\\refl{}).\n  \\end{equation*}\n\n  For the proof that this map is an equivalence we construct a map\n  \\begin{equation*}\n    \\psi(t) : \\fib{f(\\proj 1(t))}{\\proj 2(t)}\\to\\fib{\\tot{f}}{t}\n  \\end{equation*}\n  equipped with homotopies $G(t):\\varphi(t)\\circ\\psi(t)\\htpy\\idfunc$ and $H(t):\\psi(t)\\circ\\varphi(t)\\htpy\\idfunc$. In each of these definitions we use $\\Sigma$-induction and path induction all the way through, until an obvious choice of definition becomes apparent. We define $\\psi(t)$, $G(t)$, and $H(t)$ as follows:\n  \\begin{align*}\n    \\psi((x,f(x,y)),(y,\\refl{})) & \\defeq ((x,y),\\refl{}) \\\\\n    G((x,f(x,y)),(y,\\refl{})) & \\defeq \\refl{} \\\\\n    H((x,f(x,y)),((x,y),\\refl{})) & \\defeq \\refl{}.\\qedhere\n  \\end{align*}\n\\end{proof}\n\n\\begin{thm}\\label{thm:fib_equiv}\n  Let $f:\\prd{x:A}B(x)\\to C(x)$ be a family of maps. The following are equivalent:\n  \\index{is an equivalence!total(f) of family of equivalences@{$\\tot{f}$ of family of equivalences}}\n  \\index{total(f)@{$\\tot{f}$}!of family of equivalences is an equivalence}\\index{is family of equivalences!if total(f) is an equivalence@{iff $\\tot{f}$ is an equivalence}}\n\\begin{enumerate}\n\\item For each $x:A$, the map $f(x)$ is an equivalence. In this case we say that $f$ is a \\define{family of equivalences}.\n\\item The map $\\tot{f}:\\sm{x:A}B(x)\\to\\sm{x:A}C(x)$ is an equivalence.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{thm:equiv_contr,thm:contr_equiv} it suffices to show that $f(x)$ is a contractible map for each $x:A$, if and only if $\\tot{f}$ is a contractible map. Thus, we will show that $\\fib{f(x)}{c}$ is contractible if and only if $\\fib{\\tot{f}}{x,c}$ is contractible, for each $x:A$ and $c:C(x)$. However, by \\cref{lem:fib_total} these types are equivalent, so the result follows by \\cref{ex:contr_equiv}.\n\\end{proof}\n\nNow consider the situation where we have a map $f:A\\to B$, and a family $C$ over $B$. Then we have the map\n\\begin{equation*}\n  \\lam{(x,z)}(f(x),z):\\sm{x:A}C(f(x))\\to\\sm{y:B}C(y).\n\\end{equation*}\nWe claim that this map is an equivalence when $f$ is an equivalence. The technique to prove this claim is the same as the technique we used in \\cref{thm:fib_equiv}: first we note that the fibers are equivalent to the fibers of $f$, and then we use the fact that a map is an equivalence if and only if its fibers are contractible to finish the proof.\n\nThe converse of the following lemma does not hold. Why not?\n\n\\begin{lem}\\label{lem:total-equiv-base-equiv}\n  Consider an equivalence $e:A\\simeq B$, and let $C$ be a type family over $B$. Then the map\n  \\begin{equation*}\n    \\sigma_f(C) \\defeq\\lam{(x,z)}(f(x),z):\\sm{x:A}C(f(x))\\to\\sm{y:B}C(y)\n  \\end{equation*}\n  is an equivalence.\n\\end{lem}\n\n\\begin{proof}\n  We claim that for each $t:\\sm{y:B}C(y)$ there is an equivalence\n  \\begin{equation*}\n    \\fib{\\sigma_f(C)}{t}\\simeq \\fib{f}{\\proj 1(t)}.\n  \\end{equation*}\n  We obtain such an equivalence by constructing the following functions and homotopies:\n  \\begin{align*}\n    \\varphi(t) & : \\fib{\\sigma_f(C)}{t}\\to\\fib{f}{\\proj 1 (t)} & \\varphi((f(x),z),((x,z),\\refl{})) & \\defeq (x,\\refl{}) \\\\\n    \\psi(t) & : \\fib{f}{\\proj 1(t)} \\to\\fib{\\sigma_f(C)}{t} & \\psi((f(x),z),(x,\\refl{})) & \\defeq ((x,z),\\refl{}) \\\\\n    G(t) & : \\varphi(t)\\circ\\psi(t)\\htpy\\idfunc & G((f(x),z),(x,\\refl{})) & \\defeq \\refl{} \\\\\n    H(t) & : \\psi(t)\\circ\\varphi(t)\\htpy\\idfunc & H((f(x),z),((x,z),\\refl{})) & \\defeq \\refl{}.\n  \\end{align*}\n  Now the claim follows, since we see that $\\varphi$ is a contractible map if and only if $f$ is a contractible map.\n\\end{proof}\n\nWe now combine \\cref{thm:fib_equiv,lem:total-equiv-base-equiv}.\n\n\\begin{defn}\n  Consider a map $f:A\\to B$ and a family of maps\n  \\begin{equation*}\n    g:\\prd{x:A}C(x)\\to D(f(x)),\n  \\end{equation*}\n  where $C$ is a type family over $A$, and $D$ is a type family over $B$. In this situation we also say that $g$ is a \\define{family of maps over $f$}. Then we define\\index{total f(g)@{$\\tot[f]{g}$}}\n  \\begin{equation*}\n    \\tot[f]{g}:\\sm{x:A}C(x)\\to\\sm{y:B}D(y)\n  \\end{equation*}\n  by $\\tot[f]{g}(x,z)\\defeq (f(x),g(x,z))$.\n\\end{defn}\n\n\\begin{thm}\\label{thm:equiv-toto}\n  Suppose that $g$ is a family of maps over $f$, and suppose that $f$ is an equivalence. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The family of maps $g$ over $f$ is a family of equivalences.\n  \\item The map $\\tot[f]{g}$ is an equivalence.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  Note that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      \\sm{x:A}C(x) \\arrow[rr,\"{\\tot[f]{g}}\"] \\arrow[dr,swap,\"\\tot{g}\"]& & \\sm{y:B}D(y) \\\\\n      & \\sm{x:A}D(f(x)) \\arrow[ur,swap,\"{\\lam{(x,z)}(f(x),z)}\"]\n    \\end{tikzcd}\n  \\end{equation*}\n  By the assumption that $f$ is an equivalence, it follows that the map $\\sm{x:A}D(f(x))\\to \\sm{y:B}D(y)$ is an equivalence. Therefore it follows that $\\tot[f]{g}$ is an equivalence if and only if $\\tot{g}$ is an equivalence. Now the claim follows, since $\\tot{g}$ is an equivalence if and only if $g$ if a family of equivalences.\n\\end{proof}\n\\index{family of equivalences|)}\n\n\\subsection{The fundamental theorem}\n\n\\index{identity system|(}\nMany types come equipped with a reflexive relation that possesses a similar\nstructure as the identity type. The observational equality on the natural\nnumbers is such an example. We have see that it is a reflexive, symmetric, and\ntransitive relation, and moreover it is contained in any other reflexive\nrelation. Thus, it is natural to ask whether observational equality on the natural numbers is equivalent to the identity type.\n\nThe fundamental theorem of identity types (\\cref{thm:id_fundamental}) is a general theorem that can be used to answer such questions. It describes a necessary and sufficient condition on a type family $B$ over a type $A$ equipped with a point $a:A$, for there to be a family of equivalences $\\prd{x:A}(a=x)\\simeq B(x)$. In other words, it tells us when a family $B$ is a characterization of the identity type of $A$.\n\nBefore we state the fundamental theorem of identity types we introduce the notion of \\emph{identity systems}. Those are families $B$ over a $A$ that satisfy an induction principle that is similar to the path induction principle, where the `computation rule' is stated with an identification.\n\n\\begin{defn}\n  Let $A$ be a type equipped with a term $a:A$. A \\define{(unary) identity system} on $A$ at $a$ consists of a type family $B$ over $A$ equipped with $b:B(a)$, such that for any family of types $P(x,y)$ indexed by $x:A$ and $y:B(x)$,\n  the function\n  \\begin{equation*}\n    h\\mapsto h(a,b):\\Big(\\prd{x:A}\\prd{y:B(x)}P(x,y)\\Big)\\to P(a,b)\n  \\end{equation*}\n  has a section.\n\\end{defn}\n\nThe most important implication in the fundamental theorem is that (ii) implies (i). Occasionally we will also use the third equivalent statement. We note that the fundamental theorem also appears as Theorem 5.8.4 in \\cite{hottbook}.\n\n\\begin{thm}\\label{thm:id_fundamental}\nLet $A$ be a type with $a:A$, and let $B$ be be a type family over $A$ with $b:B(a)$.\nThen  the following are logically equivalent for any family of maps\n\\begin{equation*}\n  f:\\prd{x:A}(a=x)\\to B(x).\n\\end{equation*}\n\\begin{enumerate}\n\\item The family of maps $f$ is a family of equivalences.\n\\item The total space\\index{is contractible!total space of an identity system}\n\\begin{equation*}\n\\sm{x:A}B(x)\n\\end{equation*}\nis contractible.\n\\item The family $B$ is an identity system.\n\\end{enumerate}\nIn particular the canonical family of maps\n\\begin{equation*}\n\\pathind_a(b):\\prd{x:A} (a=x)\\to B(x)\n\\end{equation*}\nis a family of equivalences if and only if $\\sm{x:A}B(x)$ is contractible.\n\\end{thm}\n\n\\begin{proof}\n  First we show that (i) and (ii) are equivalent.\n  By \\cref{thm:fib_equiv} it follows that the family of maps $f$ is a family of equivalences if and only if it induces an equivalence\n  \\begin{equation*}\n    \\eqv{\\Big(\\sm{x:A}a=x\\Big)}{\\Big(\\sm{x:A}B(x)\\Big)}\n  \\end{equation*}\n  on total spaces. We have that $\\sm{x:A}a=x$ is contractible. Now it follows by \\cref{ex:contr_equiv}, applied in the case\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=3em]\n      \\sm{x:A}a=x \\arrow[rr,\"\\tot{f}\"] \\arrow[dr,swap,\"\\eqvsym\"] & & \\sm{x:A}B(x) \\arrow[dl] \\\\\n      & \\unit & \\phantom{\\sm{x:A}a=x}\n    \\end{tikzcd}\n  \\end{equation*}\n  that $\\tot{f}$ is an equivalence if and only if $\\sm{x:A}B(x)$ is contractible.\n\n  Now we show that (ii) and (iii) are equivalent. Note that we have the following commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      \\prd{t:\\sm{x:A}B(x)}P(t) \\arrow[rr,\"\\evpair\"] \\arrow[dr,swap,\"{\\evpt(a,b)}\"] & & \\prd{x:A}\\prd{y:B(x)}P(x,y) \\arrow[dl,\"{\\lam{h}h(a,b)}\"] \\\\\n      \\phantom{\\prd{x:A}\\prd{y:B(x)}P(x,y)} & P(a,b)\n    \\end{tikzcd}\n  \\end{equation*}\n  In this diagram the top map has a section. Therefore it follows by \\cref{ex:3_for_2} that the left map has a section if and only if the right map has a section. Notice that the left map has a section for all $P$ if and only if $\\sm{x:A}B(x)$ satisfies singleton induction, which is by \\cref{thm:contractible} equivalent to $\\sm{x:A}B(x)$ being contractible.\n\\end{proof}\n\\index{identity system|)}\n\n\\subsection{Embeddings}\n\\index{embedding|(}\nAs an application of the fundamental theorem we show that equivalences are embeddings. The notion of embedding is the homotopical analogue of the set theoretic notion of injective map.\n\n\\begin{defn}\nAn \\define{embedding} is a map $f:A\\to B$\\index{is an embedding} satisfying the property that\\index{is an equivalence!action on paths of an embedding}\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$. We write $\\isemb(f)$\\index{is-emb(f)@{$\\isemb(f)$}} for the type of witnesses that $f$ is an embedding.\n\\end{defn}\n\nAnother way of phrasing the following statement is that equivalent types have equivalent identity types.\n\n\\begin{thm}\n\\label{cor:emb_equiv} \nAny equivalence is an embedding.\\index{is an embedding!equivalence}\\index{equivalence!is an embedding}\n\\end{thm}\n\n\\begin{proof}\nLet $e:\\eqv{A}{B}$ be an equivalence, and let $x:A$. Our goal is to show that\n\\begin{equation*}\n\\apfunc{e} : (\\id{x}{y})\\to (\\id{e(x)}{e(y)})\n\\end{equation*}\nis an equivalence for every $y:A$. By \\cref{thm:id_fundamental} it suffices to show that \n\\begin{equation*}\n\\sm{y:A}e(x)=e(y)\n\\end{equation*}\nis contractible for every $y:A$. Now observe that there is an equivalence\n\\begin{samepage}\n\\begin{align*}\n\\sm{y:A}e(x)=e(y) & \\eqvsym \\sm{y:A}e(y)=e(x) \\\\\n& \\jdeq \\fib{e}{e(x)}\n\\end{align*}\n\\end{samepage}\nby \\cref{thm:fib_equiv}, since for each $y:A$ the map\n\\begin{equation*}\n\\invfunc : (e(x)=e(y))\\to (e(y)= e(x))\n\\end{equation*}\nis an equivalence by \\cref{ex:equiv_grpd_ops}.\nThe fiber $\\fib{e}{e(x)}$ is contractible by \\cref{thm:contr_equiv}, so it follows by \\cref{ex:contr_equiv} that the type $\\sm{y:A}e(x)=e(y)$ is indeed contractible.\n\\end{proof}\n\\index{embedding|)}\n\n\\subsection{Disjointness of coproducts}\n\n\\index{disjointness of coproducts|(}\n\\index{characterization of identity type!coproduct|(}\n\\index{identity type!coproduct|(}\n\\index{coproduct!identity type|(}\n\\index{coproduct!disjointness|(}\nTo give a second application of the fundamental theorem of identity types, we characterize the identity types of coproducts. Our goal in this section is to prove the following theorem.\n\n\\begin{thm}\\label{thm:id-coprod-compute}\nLet $A$ and $B$ be types. Then there are equivalences\n\\begin{align*}\n(\\inl(x)=\\inl(x')) & \\eqvsym (x = x')\\\\\n(\\inl(x)=\\inr(y')) & \\eqvsym \\emptyt \\\\\n(\\inr(y)=\\inl(x')) & \\eqvsym \\emptyt \\\\\n(\\inr(y)=\\inr(y')) & \\eqvsym (y=y')\n\\end{align*}\nfor any $x,x':A$ and $y,y':B$.\n\\end{thm}\n\nIn order to prove \\cref{thm:id-coprod-compute}, we first define\na binary relation $\\Eqcoprod_{A,B}$ on the coproduct $A+B$.\n\n\\begin{defn}\nLet $A$ and $B$ be types. We define \n\\begin{equation*}\n\\Eqcoprod_{A,B} : (A+B)\\to (A+B)\\to\\UU\n\\end{equation*}\nby double induction on the coproduct, postulating\n\\begin{align*}\n\\Eqcoprod_{A,B}(\\inl(x),\\inl(x')) & \\defeq (x=x') \\\\\n\\Eqcoprod_{A,B}(\\inl(x),\\inr(y')) & \\defeq \\emptyt \\\\\n\\Eqcoprod_{A,B}(\\inr(y),\\inl(x')) & \\defeq \\emptyt \\\\\n\\Eqcoprod_{A,B}(\\inr(y),\\inr(y')) & \\defeq (y=y')\n\\end{align*}\nThe relation $\\Eqcoprod_{A,B}$ is also called the \\define{observational equality of coproducts}\\index{observational equality!of coproducts}.\n\\end{defn}\n\n\\begin{lem}\nThe observational equality relation $\\Eqcoprod_{A,B}$ on $A+B$ is reflexive, and therefore there is a map\n\\begin{equation*}\n\\Eqcoprodeq:\\prd{s,t:A+B} (s=t)\\to \\Eqcoprod_{A,B}(s,t)\n\\end{equation*}\n\\end{lem}\n\n\\begin{constr}\nThe reflexivity term $\\rho$ is constructed by induction on $t:A+B$, using\n\\begin{align*}\n\\rho(\\inl(x))\\defeq \\refl{\\inl(x)}  & : \\Eqcoprod_{A,B}(\\inl(x)) \\\\\n\\rho(\\inr(y))\\defeq \\refl{\\inr(y)} & : \\Eqcoprod_{A,B}(\\inr(y)).\\qedhere\n\\end{align*}\n\\end{constr}\n\nTo show that $\\Eqcoprodeq$ is a family of equivalences, we will use the fundamental theorem, \\cref{thm:id_fundamental}. Moreover, we will use the functoriality of coproducts (established in \\cref{ex:coproduct_functor}), and the fact that any total space over a coproduct is again a coproduct:\n\\begin{align*}\n\\sm{t:A+B}P(t) & \\eqvsym \\Big(\\sm{x:A}P(\\inl(x))\\Big)+\\Big(\\sm{y:B}P(\\inr(y))\\Big)\n\\end{align*}\nAll of these equivalences are straightforward to construct, so we leave them as an exercise to the reader. \n\n\\begin{lem}\\label{lem:is-contr-total-eq-coprod}\nFor any $s:A+B$ the total space\n\\begin{equation*}\n\\sm{t:A+B}\\Eqcoprod_{A,B}(s,t)\n\\end{equation*}\nis contractible.\n\\end{lem}\n\n\\begin{proof}\nWe will do the proof by induction on $s$. The two cases are similar, so we only show that the total space\n\\begin{equation*}\n\\sm{t:A+B}\\Eqcoprod_{A,B}(\\inl(x),t)\n\\end{equation*}\nis contractible. Note that we have equivalences\n\\begin{samepage}\n\\begin{align*}\n& \\sm{t:A+B}\\Eqcoprod_{A,B}(\\inl(x),t) \\\\\n& \\eqvsym \\Big(\\sm{x':A}\\Eqcoprod_{A,B}(\\inl(x),\\inl(x'))\\Big)+\\Big(\\sm{y':B}\\Eqcoprod_{A,B}(\\inl(x),\\inr(y'))\\Big) \\\\\n& \\eqvsym \\Big(\\sm{x':A}x=x'\\Big)+\\Big(\\sm{y':B}\\emptyt\\Big) \\\\\n& \\eqvsym \\Big(\\sm{x':A}x=x'\\Big)+\\emptyt \\\\\n& \\eqvsym \\sm{x':A}x=x'.\n\\end{align*}%\n\\end{samepage}%\nIn the last two equivalences we used \\cref{ex:unit-laws-coprod}. This shows that the total space is contractible, since the latter type is contractible by \\cref{thm:total_path}.\n\\end{proof}\n\n\\begin{proof}[Proof of \\cref{thm:id-coprod-compute}]\nThe proof is now concluded with an application of \\cref{thm:id_fundamental}, using \\cref{lem:is-contr-total-eq-coprod}.\n\\end{proof}\n\\index{disjointness of coproducts|)}\n\\index{characterization of identity type!coproduct|)}\n\\index{identity type!coproduct|)}\n\\index{coproduct!identity type|)}\n\\index{coproduct!disjointness|)}\n\n\\begin{exercises}\n  \\exercise\n  \\begin{subexenum}\n  \\item \\label{ex:is-emb-empty}Show that the map $\\emptyt\\to A$ is an embedding for every type $A$.\\index{is an embedding!0 to A@{$\\emptyt\\to A$}}\n  \\item \\label{ex:is-emb-inl-inr}Show that $\\inl:A\\to A+B$ and $\\inr:B\\to A+B$ are embeddings for any two types $A$ and $B$.\n    \\index{is an embedding!inl (for coproducts)@{$\\inl$ (for coproducts)}}\n    \\index{is an embedding!inr (for coproducts)@{$\\inr$ (for coproducts)}}\n    \\index{inl@{$\\inl$}!is an embedding}\n    \\index{inr@{$\\inr$}!is an embedding}\n  \\end{subexenum}\n  \\exercise Consider an equivalence $e:A\\simeq B$. Construct an equivalence\n  \\begin{equation*}\n    (e(x)=y)\\simeq(x=e^{-1}(y))\n  \\end{equation*}\n  for every $x:A$ and $y:B$.\n  \\exercise Show that\\index{embedding!closed under homotopies}\n  \\begin{equation*}\n    (f\\htpy g)\\to (\\isemb(f)\\leftrightarrow\\isemb(g))\n  \\end{equation*}\n  for any $f,g:A\\to B$.\n  \\exercise \\label{ex:emb_triangle}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$. \n  \\begin{subexenum}\n  \\item Suppose that $g$ is an embedding. Show that $f$ is an embedding if and only if $h$ is an embedding.\\index{is an embedding!composite of embeddings}\\index{is an embedding!right factor of embedding if left factor is an embedding}\n  \\item Suppose that $h$ is an equivalence. Show that $f$ is an embedding if and only if $g$ is an embedding.\\index{is an embedding!left factor of embedding if right factor is an equivalence}\n  \\end{subexenum}\n  \\exercise \\label{ex:is-equiv-is-equiv-functor-coprod}Consider two maps $f:A\\to A'$ and $g:B \\to B'$.\n  \\begin{subexenum}\n  \\item Show that if the map\n    \\begin{equation*}\n      f+g:(A+B)\\to (A'+B')\n    \\end{equation*}\n    is an equivalence, then so are both $f$ and $g$ (this is the converse of \\cref{ex:coproduct_functor_equivalence}).\n  \\item \\label{ex:is-emb-coprod}Show that $f+g$ is an embedding if and only if both $f$ and $g$ are embeddings.\n  \\end{subexenum}\n  \\exercise \\label{ex:htpy_total} \n  \\begin{subexenum}\n  \\item Let $f,g:\\prd{x:A}B(x)\\to C(x)$ be two families of maps. Show that\n    \\begin{equation*}\n      \\Big(\\prd{x:A}f(x)\\htpy g(x)\\Big)\\to \\Big(\\tot{f}\\htpy \\tot{g}\\Big). \n    \\end{equation*}\n  \\item Let $f:\\prd{x:A}B(x)\\to C(x)$ and let $g:\\prd{x:A}C(x)\\to D(x)$. Show that\n    \\begin{equation*}\n      \\tot{\\lam{x}g(x)\\circ f(x)}\\htpy \\tot{g}\\circ\\tot{f}.\n    \\end{equation*}\n  \\item For any family $B$ over $A$, show that\n    \\begin{equation*}\n      \\tot{\\lam{x}\\idfunc[B(x)]}\\htpy\\idfunc.\n    \\end{equation*}\n  \\end{subexenum}\n  \\exercise \\label{ex:id_fundamental_retr}Let $a:A$, and let $B$ be a type family over $A$. \n  \\begin{subexenum}\n  \\item Use \\cref{ex:htpy_total,ex:contr_retr} to show that if each $B(x)$ is a retract of $\\id{a}{x}$, then $B(x)$ is equivalent to $\\id{a}{x}$ for every $x:A$.\n    \\index{fundamental theorem of identity types!formulation with retractions}\n  \\item Conclude that for any family of maps\n    \\index{fundamental theorem of identity types!formulation with sections}\n    \\begin{equation*}\n      f : \\prd{x:A} (a=x) \\to B(x),\n    \\end{equation*}\n    if each $f(x)$ has a section, then $f$ is a family of equivalences.\n  \\end{subexenum}\n  \\exercise Use \\cref{ex:id_fundamental_retr} to show that for any map $f:A\\to B$, if\n  \\begin{equation*}\n    \\apfunc{f} : (x=y) \\to (f(x)=f(y))\n  \\end{equation*}\n  has a section for each $x,y:A$, then $f$ is an embedding.\\index{is an embedding!if the action on paths have sections}\n  \\exercise \\label{ex:path-split}We say that a map $f:A\\to B$ is \\define{path-split}\\index{path-split} if $f$ has a section, and for each $x,y:A$ the map\n  \\begin{equation*}\n    \\apfunc{f}(x,y):(x=y)\\to (f(x)=f(y))\n  \\end{equation*}\n  also has a section. We write $\\pathsplit(f)$\\index{path-split(f)@{$\\pathsplit(f)$}} for the type\n  \\begin{equation*}\n    \\sections(f)\\times\\prd{x,y:A}\\sections(\\apfunc{f}(x,y)).\n  \\end{equation*}\n  Show that for any map $f:A\\to B$ the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is an equivalence.\n  \\item The map $f$ is path-split.\n  \\end{enumerate}\n  \\exercise \\label{ex:fiber_trans}Consider a triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=small]\n      A \\arrow[rr,\"h\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"g\"] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  with a homotopy $H:f\\htpy g\\circ h$ witnessing that the triangle commutes. \n  \\begin{subexenum}\n  \\item Construct a family of maps\n    \\begin{equation*}\n      \\fibtriangle(h,H):\\prd{x:X}\\fib{f}{x}\\to\\fib{g}{x},\n    \\end{equation*}\n    for which the square\n    \\begin{equation*}\n      \\begin{tikzcd}[column sep=8em]\n        \\sm{x:X}\\fib{f}{x} \\arrow[r,\"\\tot{\\fibtriangle(h,H)}\"] \\arrow[d] & \\sm{x:X}\\fib{g}{x} \\arrow[d] \\\\\n        A \\arrow[r,swap,\"h\"] & B\n      \\end{tikzcd}\n    \\end{equation*}\n    commutes, where the vertical maps are as constructed in \\cref{ex:fib_replacement}.\n  \\item Show that $h$ is an equivalence if and only if $\\fibtriangle(h,H)$ is a family of equivalences.\n  \\end{subexenum}\n\\end{exercises}\n\\index{fundamental theorem of identity types|)}\n\\index{characterization of identity type!fundamental theorem of identity types|)}\n\n\\endinput\n\n  \\begin{comment}\n    \\exercise \\label{ex:eqv_sigma_mv}Consider a map\n    \\begin{equation*}\n      f:A \\to \\sm{y:B}C(y).\n    \\end{equation*}\n    \\begin{subexenum}\n    \\item Construct a family of maps\n      \\begin{equation*}\n        f':\\prd{y:B} \\fib{\\proj 1\\circ f}{y}\\to C(y).\n      \\end{equation*}\n    \\item Construct an equivalence\n      \\begin{equation*}\n        \\eqv{\\fib{f'(b)}{c}}{\\fib{f}{(b,c)}}\n      \\end{equation*}\n      for every $(b,c):\\sm{y:B}C(y)$.\n    \\item Conclude that the following are equivalent:\n      \\begin{enumerate}\n      \\item $f$ is an equivalence.\n      \\item $f'$ is a family of equivalences.\n      \\end{enumerate}\n    \\end{subexenum}\n    \\exercise \\label{ex:coh_intro}Consider a type $A$ with base point $a:A$, and let $B$ be a type family on $A$ that implies the identity type, i.e., there is a term\n    \\begin{equation*}\n      \\alpha : \\prd{x:A} B(x)\\to (a=x).\n    \\end{equation*}\n    Show that the \\define{coherence reduction map}\n    \\begin{equation*}\n      \\cohreduction : \\Big(\\sm{y:B(a)}\\alpha(a,y)=\\refl{a}\\Big) \\to \\Big(\\sm{x:A}B(x)\\Big)\n    \\end{equation*}\n    defined by $\\lam{(y,q)}(a,y)$ is an equivalence.\n  \\end{comment}\n", "meta": {"hexsha": "33061d0deaad22e9312a48a551b65b060adb7477", "size": 24119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/fundamental.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/fundamental.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/fundamental.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": 48.7252525253, "max_line_length": 486, "alphanum_fraction": 0.6765620465, "num_tokens": 8203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.6696735292057377}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Sampling from a small population}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Sampling with replacement}\n\nWhen sampling \\hl{with replacement}, you put back what you just drew.\n\n\\pause\n\n\\begin{itemize}\n\n\\item Imagine you have a bag with 5 red, 3 blue and 2 orange chips in it. What is the probability that the first chip you draw is blue?\n\\begin{center}\n5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$}\n\\end{center}\n\n\\pause\n\n\\[ Prob(1^{st} \\text{ chip } B) = \\frac{3}{5 + 3 + 2} = \\frac{3}{10} = 0.3 \\]\n\n\\pause\n\n\\item Suppose you did indeed pull a blue chip in the first draw. If drawing with replacement, what is the probability of drawing a blue chip in the second draw?\n\n\\pause\n\n\\begin{center}\n$1^{st}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$} \\\\\n\n\\pause\n\n$2^{nd}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$}\n\\end{center}\n\n\\pause\n\n\\[ Prob(2^{nd} \\text{ chip } B | 1^{st} \\text{ chip } B) = \\frac{3}{10} = 0.3 \\]\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Sampling with replacement (cont.)}\n\n\\begin{itemize}\n\n\\item Suppose you actually pulled an orange chip in the first draw. If drawing with replacement, what is the probability of drawing a blue chip in the second draw?\n\n\\pause\n\n\\begin{center}\n$1^{st}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$} \\\\\n\\pause\n$2^{nd}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$}\n\\end{center}\n\\pause\n\\[ Prob(2^{nd} \\text{ chip } B | 1^{st} \\text{ chip } O) = \\frac{3}{10} = 0.3 \\]\n\n\\pause\n\\item If drawing with replacement, what is the probability of drawing two blue chips in a row?\n\\begin{center}\n\n\\pause\n$1^{st}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$} \\\\\n$2^{nd}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$}\n\\end{center}\n\\pause\n\\[ Prob(1^{st} \\text{ chip } B) \\cdot Prob(2^{nd} \\text{ chip } B | 1^{st} \\text{ chip } B) = 0.3 \\times 0.3 \\]\n\\[ = 0.3^2 = 0.09 \\]\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Sampling with replacement (cont.)}\n\n\\begin{itemize}\n\n\\item When drawing with replacement, probability of the second chip being blue does not depend on the color of the first chip since whatever we draw in the first draw gets put back in the bag.\n\\[ Prob(B | B) = Prob(B | O) \\]\n\n\\item In addition, this probability is equal to the probability of drawing a blue chip in the first draw, since the composition of the bag never changes when sampling with replacement.\n\\[ Prob(B | B) = Prob(B) \\]\n\n\\item \\hl{When drawing with replacement, draws are independent.}\n\n\\end{itemize}\n\n\\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Sampling without replacement}\n\nWhen drawing \\hl{without replacement} you do not put back what you just drew.\n\n\\begin{itemize}\n\n\\pause\n\n\\item Suppose you pulled a blue chip in the first draw. If drawing without replacement, what is the probability of drawing a blue chip in the second draw?\n\\pause\n\\begin{center}\n$1^{st}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$} \\\\\n\\pause\n$2^{nd}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 2 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$}\n\\end{center}\n\\pause\n\\[ Prob(2^{nd} \\text{ chip } B | 1^{st} \\text{ chip } B) = \\frac{2}{9} = 0.22 \\]\n\n\\pause\n\n\\item If drawing without replacement, what is the probability of drawing two blue chips in a row?\n\\begin{center}\n\n\\pause\n$1^{st}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 3 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$} \\\\\n$2^{nd}$ draw: 5 \\textcolor{red}{$\\CIRCLE$}~, 2 \\textcolor{blue}{$\\CIRCLE$}~, 2 \\textcolor{orange}{$\\CIRCLE$}\n\\end{center}\n\\pause\n\\[ Prob(1^{st} \\text{ chip } B) \\cdot Prob(2^{nd} \\text{ chip } B | 1^{st} \\text{ chip } B)  = 0.3 \\times 0.22 \\]\n\\[ = 0.066 \\]\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Sampling without replacement (cont.)}\n\n\\begin{itemize}\n\n\\item When drawing without replacement, the probability of the second chip being blue given the first was blue is not equal to the probability of drawing a blue chip in the first draw since the composition of the bag changes with the outcome of the first draw.\n\\[ Prob(B | B) \\ne Prob(B) \\]\n\n\\pause\n\n\\item \\hl{When drawing without replacement, draws are not independent.}\n\n\\pause\n\n\\item This is especially important to take note of when the sample sizes are small. If we were dealing with, say, 10,000 chips in a (giant) bag, taking out one chip of any color would not have as big an impact on the probabilities in the second draw.\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Practice}\n\n\\pq{In most card games cards are dealt without replacement. What is the probability of being dealt an ace and then a 3? Choose the closest answer.}\n\n\\twocol{0.3}{0.6}{\n\\begin{enumerate}[(a)]\n\\item 0.0045\n\\item 0.0059\n\\solnMult{0.0060}\n\\item 0.1553\n\\end{enumerate}\n}\n{\n\\soln{\n\\pause\n\\[ P(ace~then~3) = \\frac{4}{52} \\times \\frac{4}{51} \\approx 0.0060 \\]\n}}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", "meta": {"hexsha": "7ddb5256a144e5ec0fcf0262add06ef034684bc4", "size": 5497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/3-3_sample_from_small_population/3-3_sample_from_small_population.tex", "max_stars_repo_name": "sumitrmishra/data504", "max_stars_repo_head_hexsha": "e0cb3259f6dd362c9591375390c9d6e5d59689b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slides/3-3_sample_from_small_population/3-3_sample_from_small_population.tex", "max_issues_repo_name": "sumitrmishra/data504", "max_issues_repo_head_hexsha": "e0cb3259f6dd362c9591375390c9d6e5d59689b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slides/3-3_sample_from_small_population/3-3_sample_from_small_population.tex", "max_forks_repo_name": "sumitrmishra/data504", "max_forks_repo_head_hexsha": "e0cb3259f6dd362c9591375390c9d6e5d59689b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-20T07:26:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-20T07:26:35.000Z", "avg_line_length": 29.7135135135, "max_line_length": 260, "alphanum_fraction": 0.6430780426, "num_tokens": 1762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568417, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.6696735161714217}}
{"text": "\\subsection{Operations}\n\n\\begin{frame}[t]{Prime fields}{Operations}\n\tWhen the field $GF(p)$ is a prime field we encounter that:\n\t\n\t\\begin{itemize}\n\t\t\\item All nonzero elements of $GF(p)$ have an inverse.\n\t\t\\item Arithmetic in $GF(p)$ is done modulo $p$. \n\t\\end{itemize}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{Prime fields}{Operations example}\n\tGiven $GF(5)$ and $a, b \\in GF(5)$\n\t\\medskip\n\t\n\t\\begin{columns}\n\t\t\\begin{column}{0.5\\textwidth}\n\t\t\t\\centering $+(a, b) = a + b \\mod 5$\t\t\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|ccccc}\n\t\t\t\t\t\\textbf{+} & \\textbf{0} & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} \\\\ \\hline\n\t\t\t\t\t\\textbf{0} & 0          & 1          & 2          & 3          & 4          \\\\\n\t\t\t\t\t\\textbf{1} & 1          & 2          & 3          & 4          & 0          \\\\\n\t\t\t\t\t\\textbf{2} & 2          & 3          & 4          & 0          & 1          \\\\\n\t\t\t\t\t\\textbf{3} & 3          & 4          & 0          & 1          & 2          \\\\\n\t\t\t\t\t\\textbf{4} & 4          & 0          & 1          & 2          & 3         \n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\t\\begin{column}{0.5\\textwidth}  %%<--- here\n\t\t\t\\centering $\\times(a, b) = a * b \\mod 5$\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|ccccc}\n\t\t\t\t\t\\textbf{$\\times$} & \\textbf{0} & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} \\\\ \\hline\n\t\t\t\t\t\\textbf{0} & 0          & 0          & 0          & 0          & 0          \\\\ \n\t\t\t\t\t\\textbf{1} & 0          & 1          & 2          & 3          & 4          \\\\\n\t\t\t\t\t\\textbf{2} & 0          & 2          & 4          & 1          & 3          \\\\\n\t\t\t\t\t\\textbf{3} & 0          & 3          & 1          & 4          & 2          \\\\\n\t\t\t\t\t\\textbf{4} & 0          & 4          & 3          & 2          & 1         \n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\\end{columns}\n\\end{frame}\n\n\\begin{frame}[t]{Prime fields}{Additive Inverse}\n\tGiven $GF(5)$ and $a, b \\in GF(5)$\n\t\\medskip\n\t\n\t\\begin{columns}\n\t\t\\begin{column}{0.5\\textwidth}\n\t\t\t\\centering $+(a, b) = a + b \\mod 5$\t\t\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|ccccc}\n\t\t\t\t\t\\textbf{+} & \\textbf{0} & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} \\\\ \\hline\n\t\t\t\t\t\\textbf{0} & 0          & 1          & 2          & 3          & 4          \\\\\n\t\t\t\t\t\\textbf{1} & 1          & 2          & 3          & 4          & 0          \\\\\n\t\t\t\t\t\\textbf{2} & 2          & 3          & 4          & 0          & 1          \\\\\n\t\t\t\t\t\\textbf{3} & 3          & 4          & 0          & 1          & 2          \\\\\n\t\t\t\t\t\\textbf{4} & 4          & 0          & 1          & 2          & 3         \n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\t\\begin{column}{0.5\\textwidth}  %%<--- here\n\t\t\t\\centering $-a$\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|cc}\n\t\t\t\t\t-0  & = & 1 \\\\ \\hline\n\t\t\t\t\t-1 & = & 4 \\\\\n\t\t\t\t\t-2  & = & 3 \\\\\n\t\t\t\t\t-3  & = & 2 \\\\\n\t\t\t\t\t-4  & = & 1\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\\end{columns}\n\\end{frame}\n\n\\begin{frame}[t]{Prime fields}{Multiplicative inverse}\n\tGiven $GF(5)$ and $a, b \\in GF(5)$\n\t\\medskip\n\t\n\t\\begin{columns}\n\t\t\\begin{column}{0.5\\textwidth}\n\t\t\t\\centering $\\times(a, b) = a * b \\mod 5$\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|ccccc}\n\t\t\t\t\t\\textbf{$\\times$} & \\textbf{0} & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} \\\\ \\hline\n\t\t\t\t\t\\textbf{0} & 0          & 0          & 0          & 0          & 0          \\\\\n\t\t\t\t\t\\textbf{1} & 0          & 1          & 2          & 3          & 4          \\\\\n\t\t\t\t\t\\textbf{2} & 0          & 2          & 4          & 1          & 3          \\\\\n\t\t\t\t\t\\textbf{3} & 0          & 3          & 1          & 4          & 2          \\\\\n\t\t\t\t\t\\textbf{4} & 0          & 4          & 3          & 2          & 1         \n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\t\\begin{column}{0.5\\textwidth}  %%<--- here\n\t\t\t\\centering $a^{-1}$\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|cc}\n\t\t\t\t\t$0^{-1}$  & = & Doesn't exist \\\\ \\hline\n\t\t\t\t\t$1^{-1}$  & = & 1 \\\\\n\t\t\t\t\t$2^{-1}$  & = & 3 \\\\\n\t\t\t\t\t$3^{-1}$  & = & 2 \\\\\n\t\t\t\t\t$4^{-1}$  & = & 4\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\\end{columns}\n\\end{frame}\n\n\\begin{frame}[t]{Prime fields}{GF(2)}\n\tGiven $GF(2)$ and $a, b \\in GF(2)$ \n\t\\bigskip\n\t\\medskip\t\n\t\\begin{columns}\n\t\t\\begin{column}{0.5\\textwidth}\n\t\t\t\\centering $\\oplus(a, b) = a + b \\mod 2$\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|cc}\n\t\t\t\t\t\\textbf{$\\oplus$} & \\textbf{0} & \\textbf{1} \\\\ \\hline\n\t\t\t\t\t\\textbf{0} & 0         & 1           \\\\\n\t\t\t\t\t\\textbf{1} &1          & 0           \\\\\n\t\t\t\t\t      \n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\t\\begin{column}{0.5\\textwidth}  %%<--- here\n\t\t\t\\centering $\\wedge(a, b) = a * b \\mod 2$\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|cc}\n\t\t\t\t\t\\textbf{$\\wedge$} & \\textbf{0} & \\textbf{1} \\\\ \\hline\n\t\t\t\t\t\\textbf{0} & 0          & 0                 \\\\\n\t\t\t\t\t\\textbf{1} & 0          & 1                 \\\\\n\t\t\t\t\t        \n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\\end{columns}\n\\end{frame}\n\n\\begin{frame}[t]{Extension Fields}{$GF(2^m)$}\n\tWhen m is different than 1. The operations regarding our fields change. In the case of the AES, and for convenient reasons, m is equal to 8.\n\t\n\tA field $F$ defined as $GF(2^m)$ will be called an extension field.\n\t\n\tBefore writing the definition of the multiplication operation over $G(2^8)$ let's introduce the notion of polynomials with coefficients in $G(2^8)$.\n\t\n\\end{frame}\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Definition}\n\tIn the \\textbf{AES} algorithm will be presented as the concatenation of its individual bit values (0 or 1) between braces in the order $\\{ b_7, b_6, b_5, b_4, b_3, b_2, b_1, b_0 \\}$. As we have 8 bits, we can store it exactly in 1 byte of memory. Let's write these elements using a polynomial representation: \\bigskip\n\t\n\n\t$b_7x^7 + b_6x^6 + b_5x^5 + b_4x^4 + b_3x^3 + b_2x^2 + b_1x^1 + b_0 = \\sum_{i=0}^{7}b_ix^i$. \\\\[10pt]\n\n\n\tFor example, $\\{01100011\\}$ identifies the specific finite field element $x^6 + x^5 + x + 1$.\n\t\t\n\\end{frame}\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Representation}\n\tIt is also convenient to denote byte values using hexadecimal notation with each of two groups of four bits being denoted by a single character as followed: \\\\[5pt]\n\n\t\\begin{columns}\n\t\t\\tiny \n\t\t\\setlength{\\tabcolsep}{3pt} \n\t\t\\begin{column}{0.5\\textwidth}\t\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|c}\n\t\t\t\t\t\\textbf{Bit Pattern} & \\textbf{Character} \\\\ \\hline\n\t\t\t\t\t\\textbf{0000} & 0                  \\\\\n\t\t\t\t\t\\textbf{0001} & 1                  \\\\\n\t\t\t\t\t\\textbf{0010} & 2                  \\\\\n\t\t\t\t\t\\textbf{0011} & 3                  \\\\\n\t\t\t\t\t\\textbf{0100} & 4                  \\\\\n\t\t\t\t\t\\textbf{0101} & 5                  \\\\\n\t\t\t\t\t\\textbf{0110} & 6                  \\\\\n\t\t\t\t\t\\textbf{0111} & 7                  \\\\\t\t\t\t\t\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\n\t\t\n\t\t\\begin{column}{0.5\\textwidth}  %%<--- here\t\n\t\t\t\\begin{table}[]\n\t\t\t\t\\begin{tabular}{c|c}\n\t\t\t\t\t\\textbf{Bit Pattern} & \\textbf{Character} \\\\ \\hline\n\t\t\t\t\t\\textbf{1000} & 8                  \\\\\n\t\t\t\t\t\\textbf{1001} & 9                  \\\\\n\t\t\t\t\t\\textbf{1010} & A                  \\\\\n\t\t\t\t\t\\textbf{1011} & B                  \\\\\t\n\t\t\t\t\t\\textbf{1100} & C                  \\\\\n\t\t\t\t\t\\textbf{1101} & D                  \\\\\n\t\t\t\t\t\\textbf{1110} & E                  \\\\\n\t\t\t\t\t\\textbf{1111} & F                  \\\\\n\t\t\t\t\t\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{table}\n\t\t\\end{column}\n\t\\end{columns}\n\n\t\\centering Figure 1. Hexadecimal representation of bit patterns.\t\n\\end{frame}\n\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Example}\n\t\n\tFor example, the following expressions are equivalent to one another: \n\t\\medskip\n\t\n\t(polynomial notation);\n\t$(x^6 + x^4 + x^2 + x + 1) + (x^7 + x + 1) = x^7 + x^6 + x^4 + x^2$ \n\t\n\t\\bigskip\n\t\n\t(binary notation); \\\\\n\t$\\{01010111\\} \\wedge \\{10000011\\} = \\{11010100\\}$\n\t\n\t\\bigskip\n\t\n\t(hexadecimal notation);\t\\\\\t\n\t$\\{57\\} \\wedge \\{83\\} = \\{D4\\}$ \t\n\n\n\\end{frame}\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Multiplication}\n\tIn the polynomial representation, multiplication in $G(2^8)$ (denoted as $bullet$) corresponds to:\n\t\n\t\\medskip\n\t\n\tLet $a(x), b(x) \\in GF(2^8)$ \n\t\n\t\\begin{enumerate}[i.]\n\t\t\\item Compute $a(x) * b(x)$ as in normal polynomial calculus.\n\t\t\\item Apply the modulo using an \\textbf{irreducible polynomial} $m(x)$ of degree $8$.\n\t\n\t\\end{enumerate}\n\t\\begin{itemize}\n\t\t\\item A polynomial is irreducible if its only divisors are $1$ and itself.\n\t\t\\item Doing this, we ensure that $a(x) \\bullet b(x) \\in GF(2^8)$.\n\t\t\\item In the AES, $m(x) = x^8 + x^4 + x^3 + x + 1$\n\t\\end{itemize}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Multiplication example}\n\t\n\tFor example, $\\{57\\} \\bullet \\{83\\} = \\{C1\\}$, because \n\t\\medskip\n\t\n\n\t\\begin{center}\n\t\t\\small\n\t\t\\begin{tabular}{ccl}\\\n\t\t\t$(x^6 + x^4 + x^2 + x + 1)(x^7 + x + 1)$ & = &  $x^{13} + x^{11} + x^9 + x^8 + x^7 + x^7 + $ \\\\\n\t\t\t& & $ x^5 + x^3 + x^2 + x + x^6 + x^4 + x^2 $ \\\\\n\t\t\t& & $+ x + 1$ \\\\\n\t\t\t& = & $x^{13} + x^{11} + x^9 + x^8 + x^6 + x^5 + $ \\\\\n\t\t\t& & $ x^4 + x^3 + 1$\\\\\n\t\t\t\n\t\\end{tabular}\\end{center}\n\t\n\tand\n\t\n\t\\begin{center}\n\t\t\\small\n\t\t\t$x^{13} + x^{11} + x^9 + x^8 + x^6 + x^5 + x^4 + x^3 + 1 \\text{ modulo} (x^8 + x^4 + x^3 + x + 1) $ \\\\\t\n\t\t\t$ = x^{7} + x^6 +1 $ \\\\\n\t\t\t\n\t\\end{center}\n\\end{frame}\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{The xtime operation}\n\tMultiplying the binary polynomial previously defined with the polynomial $x$ results in \\\\\n\t\\medskip\n\t\n\t\\centering{ $b_7x^8 + b_6x^7 + b_5x^6 + b_4x^5 + b_3x^4 + b_2x^3 + b_1x^2 + b_0x$.}\n\t\n\t\\medskip\n\t\n\t\\begin{itemize}\n\t\t\\item $x \\bullet b(x)$ is obtained by reducing the above result modulo $m(x)$.\n\t\t\\item If $b_7 = 0$, the result is already in reduced form.\n\t\t\\item If $b_7=1$, the reduction is accomplished by subtracting the polynomial $m(x)$.\n\t\t\\item It follows  that multiplication by $x$ ($\\{02\\}$) can be implemented at the byte level as a left shift and a subsequent conditional bit wise XOR with $\\{1B\\}$. \n\t\\end{itemize}\n\t\n\\end{frame}\n\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Other Example}\n\t\n\tFor example, $\\{57\\} \\bullet \\{13\\} = \\{FE\\}$, because \n\t\\medskip\n\t\n\t\n\t\\begin{center}\n\t\t\\small\n\t\t\\begin{tabular}{ccccccl}\n\t\t\t\n\t\t\t$\\{57\\}$ & $\\bullet$ & $\\{02\\}$ & = &  $xtime(\\{57\\})$ & = & $\\{AE\\}$ \\\\\n\t\t\t$\\{57\\}$ & $\\bullet$ & $\\{04\\}$ & = &  $xtime(\\{AE\\})$ & = & $\\{47\\}$ \\\\\n\t\t\t$\\{57\\}$ & $\\bullet$ & $\\{08\\}$ & = &  $xtime(\\{47\\})$ & = & $\\{8E\\}$ \\\\\n\t\t\t$\\{57\\}$ & $\\bullet$ & $\\{10\\}$ & = &  $xtime(\\{8E\\})$ & = & $\\{07\\}$ \\\\\n\t\t\t\n\t\\end{tabular}\\end{center}\n\t\n\tthus,\n\t\n\t\\begin{center}\n\t\t\\small\n\t\t\\begin{tabular}{ccl}\\\n\t\t\t$\\{57\\} \\bullet \\{13\\}$ & = &  $\\{57\\} \\bullet (\\{01\\} \\oplus \\{02\\} \\oplus \\{10\\})$ \\\\\n\t\t\t& = & $\\{57\\} \\oplus \\{AE\\} \\oplus \\{07\\}$ \\\\\n\t\t\t& = &  $FE$ \\\\\n\t\t\t\n\t\\end{tabular}\\end{center}\n\\end{frame}\n\n\n\\begin{frame}[t]{Polynomials with coefficients in $G(2^8)$}{Inversion in $GF(2^8)$}\n\tFor any non-zero binary polynomial $b(x)$ of degree less than 8, the multiplicative inverse of $b(x)$, denoted $b^{-1}(x)$, can be found as follows: the extended Euclidean algorithm is used to compute polynomials $a(x)$ and $c(x)$ such that \\\\\n\t\\medskip\n\t\n\t\\centering{ $b(x)a(x) + m(x)c(x) = 1$}\n\t\n\t\\medskip\n\t\n\t\\begin{flushleft}\n\t\tHence, $a(x) \\bullet b(x) \\mod m(x) = 1$, which means\n\t\\end{flushleft}\n\n\t\n\t\\centering{ $b^{-1}(x) = a(x) \\mod  m(x)$.}\n\t\n\t\\medskip\n\t\\begin{flushleft}\n\t\tMoreover, for any $a(X) \\text{,} b(x) \\text{ and } c(x)$ in the field, it holds that\n\t\\end{flushleft}\n\t\n\t\\centering{ $a(x) \\bullet (b(x)+c(x)) = a(x) \\bullet b(x) + a(x) \\bullet c(x)$}\n\t\n\\end{frame}\n\n\\section{The SubBytes and InvSubBytes Operations}\n\n\\subsection{The SubBytes}\n\n\\begin{frame}[t]{SubBytes}{Definition}\n\t\\begin{itemize}\n\t\t\\item Non-linear byte substitution that operates independently on each byte of the State.\n\t\t\\item Constructed by composing two transformations\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Take the multiplicative inverse in the finite field GF($2^8$); the element $\\{00\\}$ is mapped to itself.\n\t\t\t\t\\item Apply the following affine transformation (over GF(2)): \n\t\t\t\t\\begin{center}\n\t\t\t\t\t$b_i^{'}= b_i \\oplus b_{(i+4)mod8} \\oplus b_{(i+5)mod8} \\oplus b_{(i+6)mod8} \\oplus b_{(i+7)mod8} \\oplus c_i$\n\t\t\t\t\\end{center}\t\t\t\t\t\n\t\t\t\tfor $0 \\leq i < 8$, where $b_i$ is the $i^{th}$ bit of the byte, and $c_i$ is the $i^{th}$ bit of a byte. $c$ with the value $\\{63\\}$ or $\\{01100011\\}$\n\t\t\t\\end{enumerate}\n\t\t\\item Is invertible.\n\t\\end{itemize}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{SubBytes}{The Affine transformation}\n\t\n\tIn matrix form, the affine transformation element of the S-box can be expressed as:\n\t\n\t\\[\n\t\\begin{bmatrix}\n\tb_0^{'} \\\\\n\tb_1^{'} \\\\\n\tb_2^{'} \\\\\n\tb_3^{'} \\\\\n\tb_4^{'} \\\\\n\tb_5^{'} \\\\\n\tb_6^{'} \\\\\n\tb_7^{'} \\\\\t\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t1 & 0 & 0 & 0 & 1 & 1 & 1 & 1\\\\\n\t1 & 1 & 0 & 0 & 0 & 1 & 1 & 1\\\\\n\t1 & 1 & 1 & 0 & 0 & 0 & 1 & 1\\\\\n\t1 & 1 & 1 & 1 & 0 & 0 & 0 & 1\\\\\n\t1 & 1 & 1 & 1 & 1 & 0 & 0 & 0\\\\\n\t0 & 1 & 1 & 1 & 1 & 1 & 0 & 0\\\\\n\t0 & 0 & 1 & 1 & 1 & 1 & 1 & 0\\\\\n\t0 & 0 & 0 & 1 & 1 & 1 & 1 & 1\\\\\n\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\tb_0 \\\\\n\tb_1 \\\\\n\tb_2 \\\\\n\tb_3 \\\\\n\tb_4 \\\\\n\tb_5 \\\\\n\tb_6 \\\\\n\tb_7 \\\\\t\n\t\\end{bmatrix}\n\t+\n\t\\begin{bmatrix}\n\t1 \\\\\n\t1 \\\\\n\t0 \\\\\n\t0 \\\\\n\t0 \\\\\n\t1 \\\\\n\t1 \\\\\n\t0 \\\\\t\n\t\\end{bmatrix}\n\t\\]\n\n\\end{frame}\n\n\\begin{frame}[t]{SubBytes}{S-Box Figure}\n\t\n\tThe following figure illustrates the effect of the \\textbf{SubBytes()} transformation on the State:\n\t\n\t\\medspace\n\t\t\n\t\\begin{center}\n\t\t\\includegraphics[scale=0.8]{images/s_box}\n\t\\end{center}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{Sbox}\n\t\\small\n\tThe S-box used in the \\textbf{SubBytes()} transformation is presented in hexadecimal for as in figure. \\\\\n\tFor example, if $s_{1,1} = {53}$, then the substitution value would be determined by the intersection of the row with index '5' and the column with index '3'. This would result in $s^{'}_{1,1}$ having a value of ${ED}$.\n\t\n\t\\begin{table}[]\n\t\t\\tiny \n\t\t\\setlength{\\tabcolsep}{2pt} \n\t\t\\begin{tabular}{c|cccccccccccccccc}\n\t\t\t& 0    &    1 &    2 &    3 &    4 &    5 &    6 &    7 &    8 &    9 &    A &    B &  C &   D  &  E &  F \\\\ \\hline\n\t\t\t0 & 0x63 & 0x7C & 0x77 & 0x7B & 0xF2 & 0x6B & 0x6F & 0xC5 & 0x30 & 0x01 & 0x67 & 0x2B & 0xFE & 0xD7 & 0xAB & 0x76 \\\\\n\t\t\t1 & 0xCA & 0x82 & 0xC9 & 0x7D & 0xFA & 0x59 & 0x47 & 0xF0 & 0xAD & 0xD4 & 0xA2 & 0xAF & 0x9C & 0xA4 & 0x72 & 0xC0 \\\\\n\t\t\t2 & 0xB7 & 0xFD & 0x93 & 0x26 & 0x36 & 0x3F & 0xF7 & 0xCC & 0x34 & 0xA5 & 0xE5 & 0xF1 & 0x71 & 0xD8 & 0x31 & 0x15 \\\\\n\t\t\t3 & 0x04 & 0xC7 & 0x23 & 0xC3 & 0x18 & 0x96 & 0x05 & 0x9A & 0x07 & 0x12 & 0x80 & 0xE2 & 0xEB & 0x27 & 0xB2 & 0x75 \\\\\n\t\t\t4 & 0x09 & 0x83 & 0x2C & 0x1A & 0x1B & 0x6E & 0x5A & 0xA0 & 0x52 & 0x3B & 0xD6 & 0xB3 & 0x29 & 0xE3 & 0x2F & 0x84 \\\\\n\t\t\t5 & 0x53 & 0xD1 & 0x00 & 0xED & 0x20 & 0xFC & 0xB1 & 0x5B & 0x6A & 0xCB & 0xBE & 0x39 & 0x4A & 0x4C & 0x58 & 0xCF \\\\\n\t\t\t6 & 0xD0 & 0xEF & 0xAA & 0xFB & 0x43 & 0x4D & 0x33 & 0x85 & 0x45 & 0xF9 & 0x02 & 0x7F & 0x50 & 0x3C & 0x9F & 0xA8 \\\\\n\t\t\t7 & 0x51 & 0xA3 & 0x40 & 0x8F & 0x92 & 0x9D & 0x38 & 0xF5 & 0xBC & 0xB6 & 0xDA & 0x21 & 0x10 & 0xFF & 0xF3 & 0xD2 \\\\\n\t\t\t8 & 0xCD & 0x0C & 0x13 & 0xEC & 0x5F & 0x97 & 0x44 & 0x17 & 0xC4 & 0xA7 & 0x7E & 0x3D & 0x64 & 0x5D & 0x19 & 0x73 \\\\\n\t\t\t9 & 0x60 & 0x81 & 0x4F & 0xDC & 0x22 & 0x2A & 0x90 & 0x88 & 0x46 & 0xEE & 0xB8 & 0x14 & 0xDE & 0x5E & 0x0B & 0xDB \\\\\n\t\t\tA & 0xE0 & 0x32 & 0x3A & 0x0A & 0x49 & 0x06 & 0x24 & 0x5C & 0xC2 & 0xD3 & 0xAC & 0x62 & 0x91 & 0x95 & 0xE4 & 0x79 \\\\\n\t\t\tB & 0xE7 & 0xC8 & 0x37 & 0x6D & 0x8D & 0xD5 & 0x4E & 0xA9 & 0x6C & 0x56 & 0xF4 & 0xEA & 0x65 & 0x7A & 0xAE & 0x08 \\\\\n\t\t\tC & 0xBA & 0x78 & 0x25 & 0x2E & 0x1C & 0xA6 & 0xB4 & 0xC6 & 0xE8 & 0xDD & 0x74 & 0x1F & 0x4B & 0xBD & 0x8B & 0x8A \\\\\n\t\t\tD & 0x70 & 0x3E & 0xB5 & 0x66 & 0x48 & 0x03 & 0xF6 & 0x0E & 0x61 & 0x35 & 0x57 & 0xB9 & 0x86 & 0xC1 & 0x1D & 0x9E \\\\\n\t\t\tE & 0xE1 & 0xF8 & 0x98 & 0x11 & 0x69 & 0xD9 & 0x8E & 0x94 & 0x9B & 0x1E & 0x87 & 0xE9 & 0xCE & 0x55 & 0x28 & 0xDF \\\\\n\t\t\tF & 0x8C & 0xA1 & 0x89 & 0x0D & 0xBF & 0xE6 & 0x42 & 0x68 & 0x41 & 0x99 & 0x2D & 0x0F & 0xB0 & 0x54 & 0xBB & 0x16 \n\t\t\\end{tabular}\n\t\\end{table}\n\\end{frame}\n\n\\subsection{The InvSubBytes}\n\n\\begin{frame}[t]{InvSubBytes}{Definition}\n\t\\begin{itemize}\n\t\t\\item The S-Box can be inversed by applying the inverse of each operation in reverse order.\n\t\t\\item In the S-Box computation we first applied the Galois Field inverse and then the affine function.\n\t\t\\item We will apply the inverse of the affine function (which is also affine) and then the inverse of the Galois field which is the function itself.\n\t\t\\item The derivations of the inverse of the affine function are vaguely specified in the bibliography consulted.\n\t\t\\item As in the SubBytes operation, we will try to build a lookup table.\n\t\\end{itemize}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{InvSubBytes}{The inverse Affine transformation}\n\t\n\tIn matrix form, the affine transformation element of the S-box can be expressed as:\n\t\n\t\\[\n\t\\begin{bmatrix}\n\tb_0^{'} \\\\\n\tb_1^{'} \\\\\n\tb_2^{'} \\\\\n\tb_3^{'} \\\\\n\tb_4^{'} \\\\\n\tb_5^{'} \\\\\n\tb_6^{'} \\\\\n\tb_7^{'} \\\\\t\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t0 & 0 & 1 & 0 & 0 & 1 & 0 & 1\\\\\n\t1 & 0 & 0 & 1 & 0 & 0 & 1 & 0\\\\\n\t0 & 1 & 0 & 0 & 1 & 0 & 0 & 1\\\\\n\t1 & 0 & 1 & 0 & 0 & 1 & 0 & 0\\\\\n\t0 & 1 & 0 & 1 & 0 & 0 & 1 & 0\\\\\n\t0 & 0 & 1 & 0 & 1 & 0 & 0 & 1\\\\\n\t1 & 0 & 0 & 1 & 0 & 1 & 0 & 0\\\\\n\t0 & 1 & 0 & 0 & 1 & 0 & 1 & 0\\\\\n\t\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\tb_0 \\\\\n\tb_1 \\\\\n\tb_2 \\\\\n\tb_3 \\\\\n\tb_4 \\\\\n\tb_5 \\\\\n\tb_6 \\\\\n\tb_7 \\\\\t\n\t\\end{bmatrix}\n\t+\n\t\\begin{bmatrix}\n\t1 \\\\\n\t0 \\\\\n\t1 \\\\\n\t0 \\\\\n\t0 \\\\\n\t0 \\\\\n\t0 \\\\\n\t0 \\\\\t\n\t\\end{bmatrix}\n\t\\]\n\t\n\\end{frame}\n\n\\begin{frame}[t]{InvSbox}\n\t\\small\n\tThe Inv-S-box used in the \\textbf{InvSubBytes()} transformation is presented in hexadecimal for as in figure. \\\\\n\tFor example, if $s_{1,1} = {53}$, then the substitution value would be determined by the intersection of the row with index '5' and the column with index '3'. This would result in $s^{'}_{1,1}$ having a value of ${50}$.\n\t\n\t\\begin{table}[]\n\t\t\\tiny \n\t\t\\setlength{\\tabcolsep}{2pt} \n\t\t\\begin{tabular}{c|cccccccccccccccc}\n\t\t\t& 0    &    1 &    2 &    3 &    4 &    5 &    6 &    7 &    8 &    9 &    A &    B &  C &   D  &  E &  F \\\\ \\hline\n\t\t\t0 & 0x52 & 0x09 & 0x6A & 0xD5 & 0x30 & 0x36 & 0xA5 & 0x38 & 0xBF & 0x40 & 0xA3 & 0x9E & 0x81 & 0xF3 & 0xD7 & 0xFB \\\\\n\t\t\t1 & 0x7C & 0xE3 & 0x39 & 0x82 & 0x9B & 0x2F & 0xFF & 0x87 & 0x34 & 0x8E & 0x43 & 0x44 & 0xC4 & 0xDE & 0xE9 & 0xCB \\\\\n\t\t\t2 & 0x54 & 0x7B & 0x94 & 0x32 & 0xA6 & 0xC2 & 0x23 & 0x3D & 0xEE & 0x4C & 0x95 & 0x0B & 0x42 & 0xFA & 0xC3 & 0x4E \\\\\n\t\t\t3 & 0x08 & 0x2E & 0xA1 & 0x66 & 0x28 & 0xD9 & 0x24 & 0xB2 & 0x76 & 0x5B & 0xA2 & 0x49 & 0x6D & 0x8B & 0xD1 & 0x25 \\\\\n\t\t\t4 & 0x72 & 0xF8 & 0xF6 & 0x64 & 0x86 & 0x68 & 0x98 & 0x16 & 0xD4 & 0xA4 & 0x5C & 0xCC & 0x5D & 0x65 & 0xB6 & 0x92 \\\\\n\t\t\t5 & 0x6C & 0x70 & 0x48 & 0x50 & 0xFD & 0xED & 0xB9 & 0xDA & 0x5E & 0x15 & 0x46 & 0x57 & 0xA7 & 0x8D & 0x9D & 0x84 \\\\\n\t\t\t6 & 0x90 & 0xD8 & 0xAB & 0x00 & 0x8C & 0xBC & 0xD3 & 0x0A & 0xF7 & 0xE4 & 0x58 & 0x05 & 0xB8 & 0xB3 & 0x45 & 0x06 \\\\\n\t\t\t7 & 0xD0 & 0x2C & 0x1E & 0x8F & 0xCA & 0x3F & 0x0F & 0x02 & 0xC1 & 0xAF & 0xBD & 0x03 & 0x01 & 0x13 & 0x8A & 0x6B \\\\\n\t\t\t8 & 0x3A & 0x91 & 0x11 & 0x41 & 0x4F & 0x67 & 0xDC & 0xEA & 0x97 & 0xF2 & 0xCF & 0xCE & 0xF0 & 0xB4 & 0xE6 & 0x73 \\\\\n\t\t\t9 & 0x96 & 0xAC & 0x74 & 0x22 & 0xE7 & 0xAD & 0x35 & 0x85 & 0xE2 & 0xF9 & 0x37 & 0xE8 & 0x1C & 0x75 & 0xDF & 0x6E \\\\\n\t\t\tA & 0x47 & 0xF1 & 0x1A & 0x71 & 0x1D & 0x29 & 0xC5 & 0x89 & 0x6F & 0xB7 & 0x62 & 0x0E & 0xAA & 0x18 & 0xBE & 0x1B \\\\\n\t\t\tB & 0xFC & 0x56 & 0x3E & 0x4B & 0xC6 & 0xD2 & 0x79 & 0x20 & 0x9A & 0xDB & 0xC0 & 0xFE & 0x78 & 0xCD & 0x5A & 0xF4 \\\\\n\t\t\tC & 0x1F & 0xDD & 0xA8 & 0x33 & 0x88 & 0x07 & 0xC7 & 0x31 & 0xB1 & 0x12 & 0x10 & 0x59 & 0x27 & 0x80 & 0xEC & 0x5F \\\\\n\t\t\tD & 0x60 & 0x51 & 0x7F & 0xA9 & 0x19 & 0xB5 & 0x4A & 0x0D & 0x2D & 0xE5 & 0x7A & 0x9F & 0x93 & 0xC9 & 0x9C & 0xEF \\\\\n\t\t\tE & 0xA0 & 0xE0 & 0x3B & 0x4D & 0xAE & 0x2A & 0xF5 & 0xB0 & 0xC8 & 0xEB & 0xBB & 0x3C & 0x83 & 0x53 & 0x99 & 0x61 \\\\\n\t\t\tF & 0x17 & 0x2B & 0x04 & 0x7E & 0xBA & 0x77 & 0xD6 & 0x26 & 0xE1 & 0x69 & 0x14 & 0x63 & 0x55 & 0x21 & 0x0C & 0x7D \n\t\t\\end{tabular}\n\t\\end{table}\n\\end{frame}", "meta": {"hexsha": "0fa9d9f78a1bf7c723e38e49974b180c43b64af8", "size": 19885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/2_mathematics/operations.tex", "max_stars_repo_name": "belgrades/aes", "max_stars_repo_head_hexsha": "ebd1fbf36acd8e3a787ebc0cd68f83e3784d2979", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T12:34:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T12:34:37.000Z", "max_issues_repo_path": "presentation/2_mathematics/operations.tex", "max_issues_repo_name": "belgrades/aes", "max_issues_repo_head_hexsha": "ebd1fbf36acd8e3a787ebc0cd68f83e3784d2979", "max_issues_repo_licenses": ["MIT"], "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/2_mathematics/operations.tex", "max_forks_repo_name": "belgrades/aes", "max_forks_repo_head_hexsha": "ebd1fbf36acd8e3a787ebc0cd68f83e3784d2979", "max_forks_repo_licenses": ["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.7643884892, "max_line_length": 318, "alphanum_fraction": 0.5213477496, "num_tokens": 9057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583169, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6695955930026481}}
{"text": "\\documentclass{article}\n\n\\title{ICPC Notebook}\n\\author{pedroteosousa}\n\\date{}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[hidelinks]{hyperref}\n\\usepackage{listings}\n\\usepackage{xcolor}\n\\usepackage{multicol}\n\\usepackage[a4paper, margin=0.5in]{geometry}\n\n\\lstset{\n\ttabsize=4,\n\tbasicstyle={\\small\\ttfamily},\n\tshowstringspaces=false,\n\tcommentstyle=\\color{black},\n\tkeywordstyle=\\color{blue},\n\tstringstyle=\\color{red}\n}\n\n\\begin{document}\n%\\begin{multicols}{2}\n\n\\maketitle\n\\tableofcontents\n\n\\section{Geometry}\n\\subsection{Basic}\n\\begin{lstlisting}[language=C++]\nstruct point {\n    coord x, y;\n    point(): x(0), y(0) {}\n    point(coord a, coord b): x(a), y(b) {}\n\n    inline point operator+ (point o) { return {x + o.x, y + o.y}; }\n    inline point operator- (point o) { return {x - o.x, y - o.y}; }\n    inline point operator* (coord o) { return {x * o, y * o}; }\n    inline point operator/ (coord o) { return {x / o, y / o}; }\n\n    inline coord operator* (point o) { return x * o.x + y * o.y; }\n    inline coord operator^ (point o) { return x * o.y - y * o.x; }\n    \n    inline bool operator< (point o) { return make_pair(x, y) < make_pair(o.x, o.y); }\n\n    inline bool operator== (point o) { return abs(x-o.x) < eps && abs(y-o.y) < eps; }\n\n    // cw angle\n    inline double ang(point o) {\n        point p = *this;\n        return atan2(-(p ^ o), p * o);\n    }\n\n    inline coord sqr() { return x * x + y * y; }\n    inline double len() { return sqrt(sqr()); }\n\n    // rotate cw\n    inline point rot90() { return {y, -x}; }\n    inline point rotate(double a) { return {cos(a)*x + sin(a)*y, -sin(a)*x + cos(a)*y}; }\n\n    inline int ccw(point o) { coord a = (*this) ^ o; return (eps < a) - (a < -eps); }\n    inline int dir(point o) { coord a = (*this) * o; return (eps < a) - (a < -eps); }\n\n    bool in_seg(point a, point b) {\n        point p = *this;\n        return (p-a).ccw(b-a) == 0 && (p-a).dir(p-b) <= 0;\n    }\n    double dist_line(point a, point b) {\n        point p = *this;\n        return (b-a).sqr() <= eps ? (p-a).sqr() : double(abs((a-p) ^ (b-p))) / (b-a).len();\n    }\n    double dist_seg(point a, point b) {\n        point p = *this;\n        return (p-a).dir(p-b) <= 0 ? dist_line(a, b) : min((p-a).len(), (p-b).len());\n    }\n};\n\nstruct line {\n    point p; coord c;\n    line() {}\n    line(point s, point e): p((s-e).rot90()), c(p*s) {}\n    point inter(line o) {\n        if (p.ccw(o.p) == 0) throw 1;\n        coord d = (p ^ o.p);\n        return point((c * o.p.y - p.y * o.c) / d, (o.c * p.x - o.p.x * c) / d);\n    }\n};\n\nbool inter_seg(point a, point b, point c, point d) {\n    if (a.in_seg(c, d) || b.in_seg(c, d) || c.in_seg(a, b) || d.in_seg(a, b)) return true;\n    return ((c-a).ccw(b-a) * (d-a).ccw(b-a) == -1 && (a-c).ccw(d-c) * (b-c).ccw(d-c) == -1);\n}\\end{lstlisting}\n\\subsection{Convex Hull}\n\\begin{lstlisting}[language=C++]\ndouble side(point a, point b, point c) {\n\treturn (a^b) + (b^c) + (c^a);\n}\n\nvector<point> convex_hull(vector<point> p) {\n\tint n = p.size(), k = 0;\n\tif (n == 1) return p;\n\tvector<point> hull(2*n);\n\n\tsort(p.begin(), p.end());\n\n\tfor(int i=0; i<n; i++) {\n\t\t// use <= when including collinear points\n\t\twhile(k>=2 && (side(hull[k-2], hull[k-1], p[i]) < 0))\n\t\t\tk--;\n\t\thull[k++] = p[i];\n\t}\n\n\tfor(int i=n-2,t=k+1; i>=0; i--) {\n\t\twhile(k>=t && (side(hull[k-2], hull[k-1], p[i]) < 0))\n\t\t\tk--;\n\t\thull[k++] = p[i];\n\t}\n\n\thull.resize(k-1);\n\treturn hull;\n}\n\\end{lstlisting}\n\\section{Graph Algorithms}\n\\subsection{Tarjan}\n\\begin{lstlisting}[language=C++]\nconst int inf = 1791791791;\n\nvector<int> adj[N];\n\n// time complexity: O(V+E)\nstack<int> ts;\nint tme = 0, ncomp = 0, low[N], seen[N];\nint comp[N]; // nodes in the same scc have the same color\nint scc_dfs(int n) {\n\tseen[n] = low[n] = ++tme;\n\tts.push(n);\n\tfor (auto a : adj[n]) {\n\t\tif (seen[a] == 0)\n\t\t\tscc_dfs(a);\n\t\tlow[n] = min(low[n], low[a]);\n\t}\n\tif (low[n] == seen[n]) {\n\t\tint node;\n\t\tdo {\n\t\t\tnode = ts.top(); ts.pop();\n\t\t\tcomp[node] = ncomp;\n\t\t\tlow[node] = inf;\n\t\t} while (n != node && ts.size());\n\t\tncomp++;\n\t}\n\treturn low[n];\n}\\end{lstlisting}\n\\subsection{Lowest Common Ancestor}\n\\begin{lstlisting}[language=C++]\nconst int N = 1e6 + 5;\nconst int L = 20;\n\nvector<int> adj[N];\nint prof[N], p[N][L+5];\n\nvoid dfs(int v, int h = 1) {\n\tprof[v] = h;\n\tif (h == 1) p[v][0] = v;\n\tfor (auto u : adj[v])\n\t\tif (prof[u] == 0) {\n\t\t\tp[u][0] = v;\n\t\t\tdfs(u, h+1);\n\t\t}\n}\n\nvoid init(int n) {\n\tfor (int i = 1; i <= L; i++)\n\t\tfor (int j = 1; j < n; j++)\n\t\t\tp[j][i] = p[p[j][i-1]][i-1];\n}\n\nint lca(int u, int v) {\n\tif (prof[u] < prof[v]) swap(u, v);\n\tfor (int i = L; i >= 0; i--)\n\t\tif (prof[p[u][i]] >= prof[v])\n\t\t\tu = p[u][i];\n\tfor (int i = L; i >= 0; i--)\n\t\tif (p[u][i] != p[v][i]) {\n\t\t\tu = p[u][i];\n\t\t\tv = p[v][i];\n\t\t}\n\twhile (u != v) {\n\t\tu = p[u][0];\n\t\tv = p[v][0];\n\t}\n\treturn u;\n}\n\\end{lstlisting}\n\\subsection{Centroid}\n\\begin{lstlisting}[language=C++]\nvector<int> adj[N], centroid[N];\nint sze[N];\n\nint dfs(int v, int p = 0) {\n    sze[v] = 1;\n    for (int u: adj[v])\n        if (u != p && sze[u] != -1) sze[v] += dfs(u, v);\n    return sze[v];\n}\n\n// returns root of centroid tree\nint build(int v) {\n    int n = dfs(v, v);\n    int w = v;\n    do {\n        v = w;\n        for (int u: adj[v])\n            if (sze[u] != -1 && sze[u] < sze[v] && 2 * sze[u] >= n)\n                w = u;\n    } while (v != w);\n    sze[v] = -1;\n    for (int u: adj[v])\n        if (sze[u] != -1)\n            centroid[v].push_back(build(u));\n    return v;\n}\\end{lstlisting}\n\\section{Flow}\n\\subsection{Dinic's Algorithm}\n\\begin{lstlisting}[language=C++]\nstruct dinic {\n\tstruct edge {\n\t\tint from, to;\n\t\tll c, f;\n\t};\n\tvector<edge> edges;\n\tvector<int> adj[N];\n\n\tvoid addEdge(int i, int j, ll c) {\n\t\tedges.push_back({i, j, c, 0}); adj[i].push_back(edges.size() - 1);\n\t\tedges.push_back({j, i, 0, 0}); adj[j].push_back(edges.size() - 1);\n\t}\n\n\tint turn, seen[N], dist[N], st[N];\n\tbool bfs (int s, int t) {\n\t\tseen[t] = ++turn;\n\t\tdist[t] = 0; \n\t\tqueue<int> q({t});\n\t\twhile (q.size()) {\n\t\t\tint u = q.front(); q.pop();\n\t\t\tst[u] = 0;\n\t\t\tfor (auto e : adj[u]) {\n\t\t\t\tint v = edges[e].to;\n\t\t\t\tif (seen[v] != turn && edges[e^1].c != edges[e^1].f) {\n\t\t\t\t\tseen[v] = turn;\n\t\t\t\t\tdist[v] = dist[u] + 1;\n\t\t\t\t\tq.push(v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn seen[s] == turn;\n\t}\n\n\tll dfs(int s, int t, ll f) {\n\t\tif (s == t || f == 0)\n\t\t\treturn f;\n\t\tfor (int &i = st[s]; i < adj[s].size(); i++) {\n\t\t\tint e = adj[s][i], v = edges[e].to;\n\t\t\tif (seen[v] == turn && dist[v] + 1 == dist[s] && edges[e].c > edges[e].f) {\n\t\t\t\tif (ll nf = dfs(v, t, min(f, edges[e].c - edges[e].f))) {\n\t\t\t\t\tedges[e].f += nf;\n\t\t\t\t\tedges[e^1].f -= nf;\n\t\t\t\t\treturn nf;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 0ll;\n\t}\n\n\tll max_flow(int s, int t) {\n\t\tll resp = 0ll;\n\t\twhile (bfs(s, t))\n\t\t\twhile (ll val = dfs(s, t, inf))\n\t\t\t\tresp += val;\n\t\treturn resp;\n\t}\n};\n\\end{lstlisting}\n\\subsection{Min Cost}\n\\begin{lstlisting}[language=C++]\ntypedef long long ll;\nconst ll inf = 1e12;\n\nstruct min_cost {\n\tstruct edge {\n\t\tint from, to;\n\t\tll cp, fl, cs;\n\t};\n\tvector<edge> edges;\n\tvector<int> adj[N];\n\t\n\tvoid addEdge(int i, int j, ll cp, ll cs) {\n\t\tedges.push_back({i, j, cp, 0, cs}); adj[i].push_back(edges.size() - 1);\n\t\tedges.push_back({j, i, 0, 0, -cs}); adj[j].push_back(edges.size() - 1);\n\t}\n\n\tll seen[N], dist[N], pai[N], cost, flow;\n\tint turn;\n\tll spfa(int s, int t) {\n\t\tturn++;\n\t\tqueue<int> q; q.push(s);\n\t\tfor (int i = 0; i < N; i++) dist[i] = inf;\n\t\tdist[s] = 0;\n\t\tseen[s] = turn;\n\t\twhile (q.size()) {\n\t\t\tint u = q.front(); q.pop();\n\t\t\tseen[u] = 0;\n\t\t\tfor (auto e : adj[u]) {\n\t\t\t\tint v = edges[e].to;\n\t\t\t\tif (edges[e].cp > edges[e].fl && dist[u] + edges[e].cs < dist[v]) {\n\t\t\t\t\tdist[v] = dist[u] + edges[e].cs;\n\t\t\t\t\tpai[v] = e ^ 1;\n\t\t\t\t\tif (seen[v] < turn) {\n\t\t\t\t\t\tseen[v] = turn;\n\t\t\t\t\t\tq.push(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (dist[t] == inf) return 0;\n\t\tll nfl = inf;\n\t\tfor (int u = t; u != s; u = edges[pai[u]].to)\n\t\t\tnfl = min(nfl, edges[pai[u] ^ 1].cp - edges[pai[u] ^ 1].fl);\n\t\tcost += dist[t] * nfl;\n\t\tfor (int u = t; u != s; u = edges[pai[u]].to) {\n\t\t\tedges[pai[u]].fl -= nfl;\n\t\t\tedges[pai[u] ^ 1].fl += nfl;\n\t\t}\n\t\treturn nfl;\n\t}\n\n\tvoid mncost(int s, int t) {\n\t\tcost = flow = 0;\n\t\twhile (ll fl = spfa(s, t))\n\t\t\tflow += fl;\n\t}\n};\n\\end{lstlisting}\n\\section{Data Structures}\n\\subsection{Trie}\n\\begin{lstlisting}[language=C++]\nstruct trie {\n\tstruct node {\n\t\tint to[A], freq, end;\n\t};\n\tstruct node t[N];\n\tint sz = 0;\n\tint offset = 'a';\n\t\n\t// init trie\n\tvoid init() {\n\t\tmemset(t, 0, sizeof(struct node));\n\t}\n\t\n\t// insert string\n\tvoid insert(char *s, int p = 0) {\n\t\tt[p].freq++;\n\t\tif (*s == 0) {\n\t\t\tt[p].end++;\n\t\t\treturn;\n\t\t}\n\t\tif (t[p].to[*s - offset] == 0)\n\t\t\tt[p].to[*s - offset] = ++sz;\n\t\tinsert(s+1, t[p].to[*s - offset]);\n\t}\n\n\t// check if string is on trie\n\tint find(char *s, int p = 0) {\n\t\tif (*s == 0)\n\t\t\treturn t[p].end;\n\t\tif (t[p].to[*s - offset] == 0)\n\t\t\treturn false;\n\t\treturn find(s+1, t[p].to[*s - offset]);\n\t}\n\t\n\t// count the number of strings that have this prefix\n\tint count(char *s, int p = 0) {\n\t\tif (*s == 0)\n\t\t\treturn t[p].freq;\n\t\tif (t[p].to[*s - offset] == 0)\n\t\t\treturn 0;\n\t\treturn count(s+1, t[p].to[*s - offset]);\n\t}\n\n\t// erase a string\n\tint erase(char *s, int p = 0) {\n\t\tif (*s == 0 && t[p].end) {\n\t\t\t--t[p].end;\n\t\t\treturn --t[p].freq;\n\t\t}\n\t\tif ((*s == 0 && t[p].end == 0) || t[p].to[*s - offset] == 0)\n\t\t\treturn -1;\n\t\tint count = erase(s+1, t[p].to[*s - offset]);\n\t\tif (count == 0)\n\t\t\tt[p].to[*s - offset] = 0;\n\t\tif (count == -1)\n\t\t\treturn -1;\n\t\treturn --t[p].freq;\n\t}\n};\n\\end{lstlisting}\n\\subsection{Binary Indexed Tree}\n\\begin{lstlisting}[language=C++]\nint b[N];\n\nint update(int p, int val, int n) {\n\tfor(;p < n; p += p & -p) b[p] += val;\n}\n\nint getsum(int p) {\n\tint sum = 0;\n\tfor(; p != 0; p -= p & -p) {\n\t\tsum += b[p];\n\t}\n\treturn sum;\n}\n\\end{lstlisting}\n\\subsection{Lazy Segment Tree}\n\\begin{lstlisting}[language=C++]\ntypedef long long ll;\n\nconst ll N = 1e5 + 5;\nconst ll inf = 1791791791;\n\nstruct seg_tree {\n\tll seg[4*N];\n\tll lazy[4*N];\n\n\tseg_tree() {\n\t\tmemset(seg, 0, sizeof(seg));\n\t\tmemset(lazy, 0, sizeof(lazy));\n\t}\n\n\tvoid do_lazy(ll root, ll left, ll right) {\n\t\tseg[root] += lazy[root];\n\t\tif (left != right) {\n\t\t\tlazy[2*root+1] += lazy[root];\n\t\t\tlazy[2*root+2] += lazy[root];\n\t\t}\n\t\tlazy[root] = 0;\n\t}\n\n\t// sum update\n\tll update(ll l, ll r, ll val, ll left = 0, ll right = N-1, ll root = 0) {\n\t\tdo_lazy(root, left, right);\n\t\tif (r < left || l > right) return seg[root];\n\t\tif (left >= l && right <= r) {\n\t\t\tlazy[root] += val;\n\t\t\tdo_lazy(root, left, right);\n\t\t\treturn seg[root];\n\t\t}\n\t\tll update_left = update(l, r, val, left, (left+right)/2, 2*root+1);\n\t\tll update_right = update(l, r, val, (left+right)/2+1, right, 2*root+2);\n\t\treturn seg[root] = min(update_left, update_right);\n\t}\n\n\tll query(ll l, ll r, ll left = 0, ll right = N-1, int root = 0) {\n\t\tdo_lazy(root, left, right);\n\t\tif (r < left || l > right)\n\t\t\treturn inf;\n\t\tif (left >= l && right <= r) return seg[root];\n\t\tll query_left = query(l, r, left, (left+right)/2, 2*root+1);\n\t\tll query_right = query(l, r, (left+right)/2+1, right, 2*root+2);\n\t\treturn min(query_left, query_right);\n\t}\n};\n\\end{lstlisting}\n\\subsection{Union Find}\n\\begin{lstlisting}[language=C++]\nint p[N], w[N];\n\nvoid init() {\n\tfor (int i = 0; i < N; i++)\n\t\tw[p[i] = i] = 1;\n}\n\nint find(int x) {\n\treturn p[x] = (x == p[x] ? x : find(p[x]));\n}\n\nvoid join(int a, int b) {\n\tif ((a = find(a)) == (b = find(b))) return;\n\tif (w[a] < w[b]) swap(a, b);\n\tw[a] += w[b];\n\tp[b] = a;\n}\\end{lstlisting}\n\\section{Mathematics}\n\\subsection{Matrix}\n\\begin{lstlisting}[language=C++]\ntemplate <int n> struct matrix {\n\tlong long mat[n][n];\n\tmatrix () {\n\t\tmemset (mat, 0, sizeof (mat));\n\t}\n\tmatrix (long long temp[n][n]) {\n\t\tmemcpy (mat, temp, sizeof (mat));\n\t}\n\tvoid identity() {\n\t\tmemset (mat, 0, sizeof (mat));\n\t\tfor (int i=0;i<n;i++)\n\t\t\tmat[i][i] = 1;\n\t}\n\tmatrix<n> mul (const matrix<n> &a, long long m) const {\n\t\tmatrix<n> temp;\n\t\tfor (int i=0; i<n; i++)\n\t\t\tfor (int j=0; j<n; j++)\n\t\t\t\tfor (int k=0; k<n; k++) {\n\t\t\t\t\ttemp.mat[i][j] += (mat[i][k]*a.mat[k][j])%m;\n\t\t\t\t\ttemp.mat[i][j] %= m;\n\t\t\t\t}\n\t\treturn temp;\n\t}\n\tmatrix<n> operator% (long long m) {\n\t\tmatrix<n> temp(mat);\n\t\tfor (int i=0; i<n; i++)\n\t\t\tfor (int j=0; j<n; j++)\n\t\t\t\ttemp.mat[i][j] %= m;\n\t\treturn temp;\n\t}\n\tmatrix<n> pow(long long e, long long m) {\n\t\tmatrix<n> temp;\n\t\tif (e == 0) {\n\t\t\ttemp.identity();\n\t\t\treturn temp%m;\n\t\t}\n\t\tif (e == 1) {\n\t\t\tmemcpy (temp.mat, mat, sizeof (temp.mat));\n\t\t\treturn temp%m;\n\t\t}\n\t\ttemp = pow(e/2, m);\n\t\tif (e % 2 == 0)\n\t\t\treturn (temp.mul(temp, m))%m;\n\t\telse\n\t\t\treturn (((temp.mul(temp, m))%m)*pow(1, m))%m;\n\t}\n};\n\\end{lstlisting}\n\\subsection{Fast Fourier Transform}\n\\begin{lstlisting}[language=C++]\ntypedef complex<double> cpx;\nconst double pi = acos(-1.0);\n// DFT if type = 1, IDFT if type = -1\n// If you are multiplying, remember to let EACH vector with n >= sum of degrees of both polys\n// n is required to be a power of 2\nvoid FFT(vector<cpx> &v, vector<cpx> &ans, int n, int type, int p[]) { // p[n]\n\tassert(!(n & (n - 1))); int i, sz, o; p[0] = 0;\n\tfor(i = 1; i < n; i++) p[i] = (p[i >> 1] >> 1) | ((i & 1)? (n >> 1) : 0);\n\tfor(i = 0; i < n; i++) ans[i] = v[p[i]];\n\tfor(sz = 1; sz < n; sz <<= 1) {\n\t\tconst cpx wn(cos(type * pi / sz), sin(type * pi / sz));\n\t\tfor(o = 0; o < n; o += (sz << 1)) {\n\t\t\tcpx w = 1;\n\t\t\tfor(i = 0; i < sz; i++) {\n\t\t\t\tconst cpx u = ans[o + i], t = w * ans[o + sz + i];\n\t\t\t\tans[o + i] = u + t;\n\t\t\t\tans[o + i + sz] = u - t;\n\t\t\t\tw *= wn;\n\t\t\t}\n\t\t}\n\t}\n\tif(type == -1) for(i = 0; i < n; i++) ans[i] /= n;\n}\\end{lstlisting}\n\\subsection{Extended Euclidean Algorithm}\n\\begin{lstlisting}[language=C++]\n// x * a + y * b = gcd(a, b)\nll ext(ll a, ll b, ll &x, ll &y) {\n\tif (a == 0) {\n\t\tx = 0;\n\t\ty = 1;\n\t\treturn b;\n\t}\n\tll x1, y1;\n\tll gcd = ext(b%a, a, x1, y1);\n\n\tx = y1 - (b/a)*x1;\n\ty = x1;\n\n\treturn gcd;\n}\\end{lstlisting}\n\\subsection{Rabin-Miller Primality Test}\n\\begin{lstlisting}[language=C++]\nlong long llrand(long long mn, long long mx) {\n\tlong long p = rand();\n\tp <<= 32ll;\n\tp += rand();\n\treturn p%(mx-mn+1ll)+mn;\n}\n\nlong long mul_mod(long long a, long long b, long long m) {\n\tlong long x = 0, y = a%m;\n\twhile (b) {\n\t\tif (b % 2)\n\t\t\tx = (x+y)%m;\n\t\ty = (2*y)%m;\n\t\tb >>= 1;\n\t}\n\treturn x%m;\n}\n\nlong long exp_mod(long long e, long long n, long long m) {\n\tif (n == 0)\n\t\treturn 1ll;\n\tlong long temp = exp_mod(e, n/2, m);\n\tif (n & 1)\n\t\treturn mul_mod(mul_mod(temp, temp, m), e, m);\n\telse\n\t\treturn mul_mod(temp, temp, m);\n}\n\n// complexity: O(t*log2^3(p))\nbool isProbablyPrime(long long p, long long t=64) {\n\tif (p <= 1) return false;\n\tif (p <= 3) return true;\n\tsrand(time(NULL));\n\tlong long r = 0, d = p-1;\n\twhile (d % 2 == 0) {\n\t\tr++;\n\t\td >>= 1;\n\t}\n\twhile (t--) {\n\t\tlong long a = llrand(2, p-2);\n\t\ta = exp_mod(a, d, p);\n\t\tif (a == 1 || a == p-1) continue;\n\t\tfor (int i=0; i<r-1; i++) {\n\t\t\ta = mul_mod(a, a, p);\n\t\t\tif (a == 1) return false;\n\t\t\tif (a == p-1) break;\n\t\t}\n\t\tif (a != p-1) return false;\n\t}\n\treturn true;\n}\n\\end{lstlisting}\n\\section{Strings}\n\\subsection{Z function}\n\\begin{lstlisting}[language=C++]\nint z[N];\n\nvoid Z(string s) {\n\tint n = s.size();\n\tint m = -1;\n\tfor (int i = 1; i < n; i++) {\n\t\tz[i] = 0;\n\t\tif (m != -1 && m + z[m] >= i)\n\t\t\tz[i] = min(m + z[m] - i, z[i-m]);\n\t\twhile (i + z[i] < n && s[i+z[i]] == s[z[i]])\n\t\t\tz[i]++;\n\t\tif (m == -1 || i + z[i] > m + z[m])\n\t\t\tm = i;\n\t}\n}\n\\end{lstlisting}\n\\subsection{Knuth–Morris–Pratt Algorithm}\n\\begin{lstlisting}[language=C++]\nint kmp[N];\n\nvoid build(string p) {\n\tint n = p.size(), k = -1;\n\tkmp[0] = k;\n\tfor (int i = 1; i < n+1; i++) {\n\t\twhile (k >= 0 && p[k] != p[i-1]) k = kmp[k];\n\t\tkmp[i] = ++k;\n\t}\n}\n\nvector<int> match(string p, string s) {\n\tint n = s.size(), m = p.size(), j = 0;\n\tvector<int> matches;\n\tfor (int i = 1; i < n+1; i++) {\n\t\twhile (j >= 0 && p[j] != s[i-1]) j = kmp[j];\n\t\tif (++j == m) {\n\t\t\tmatches.push_back(i-j+1);\n\t\t\tj = kmp[j];\n\t\t}\n\t}\n\treturn matches;\n}\n\\end{lstlisting}\n\\section{Miscellaneous}\n\\subsection{vim settings}\n\\begin{lstlisting}[language=]\nset ai si noet ts=4 sw=4 sta sm nu rnu\ninoremap <NL> <ESC>o\nnnoremap <NL> o\ninoremap <C-up> <C-o>:m-2<CR>\ninoremap <C-down> <C-o>:m+1<CR>\nnnoremap <C-up> :m-2<CR>\nnnoremap <C-down> :m+1<CR>\nvnoremap <C-up> :m-2<CR>gv\nvnoremap <C-down> :m'>+1<CR>gv\nsyntax on\ncolors evening\nhighlight Normal ctermbg=none \"No background\nhighlight nonText ctermbg=none\n\\end{lstlisting}\n\n\n%\\end{multicols}\n\\end{document}\n\n", "meta": {"hexsha": "40dac01b6656167a505597059247221ad869d8cd", "size": 16116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook.tex", "max_stars_repo_name": "pedroteosousa/caderno", "max_stars_repo_head_hexsha": "9d13449df8734dc979d1f66cd4c424b8a7d8cc48", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "pedroteosousa/caderno", "max_issues_repo_head_hexsha": "9d13449df8734dc979d1f66cd4c424b8a7d8cc48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-02-06T16:52:39.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-13T05:21:24.000Z", "max_forks_repo_path": "notebook.tex", "max_forks_repo_name": "pedroteosousa/caderno", "max_forks_repo_head_hexsha": "9d13449df8734dc979d1f66cd4c424b8a7d8cc48", "max_forks_repo_licenses": ["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.8271954674, "max_line_length": 93, "alphanum_fraction": 0.5312732688, "num_tokens": 6103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.83114303531056, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6695955906511861}}
{"text": "\\chapter{Affine schemes: the Zariski topology}\n\\label{ch:spec_zariski}\nNow that we understand sheaves well,\nwe can define an affine scheme.\nIt will be a ringed space, so we need to define\n\\begin{itemize}\n\t\\ii The set of points,\n\t\\ii The topology on it, and\n\t\\ii The structure sheaf on it.\n\\end{itemize}\nIn this chapter, we handle the first two parts;\n\\Cref{ch:spec_sheaf} does the last one.\n\nQuick note: \\Cref{ch:spec_examples}\ncontains a long list of examples of affine schemes.\nSo if something written in this chapter is not making sense,\none thing worth trying is skimming through the next chapter\nto see if any of the examples there are more helpful.\n\n\\section{Some more advertising}\nLet me describe what the construction of $\\Spec A$ is going to do.\n\nIn the case of $\\Aff^n$, we used $\\CC^n$ as the set of points\nand $\\CC[x_1, \\dots, x_n]$ as the ring of functions\nbut then remarked that the set of points\nof $\\CC^n$ corresponded to the maximal ideals of $\\CC[x_1, \\dots, x_n]$.\nIn an \\emph{affine scheme}, we will take an \\emph{arbitrary} ring $A$,\nand generate the entire structure from just $A$ itself.\nThe final result is called $\\Spec A$, the \\vocab{spectrum} of $A$.\nThe affine varieties $\\VV(I)$ we met earlier will just be\n$\\CC[x_1, \\dots, x_n] / I$, but now we will be able to take\n\\emph{any} ideal $I$, thus finally completing the table at the end\nof the ``affine variety'' chapter.\n\nThe construction of the affine scheme in this way\nwill have three big generalizations:\n\\begin{enumerate}\n\t\\ii We no longer have to work over an algebraically\n\tclosed field $\\CC$, or even a field at all.\n\tThis will be the most painless generalization:\n\tyou won't have to adjust your current picture much for this to work.\n\n\t\\ii We allow non-radical ideals:\n\t$\\Spec \\CC[x] / (x^2)$ will be the double point\n\twe sought for so long.\n\tThis will let us formalize the notion of a ``fat'' or ``fuzzy'' point.\n\n\t\\ii Our affine schemes will have so-called \\emph{non-closed points}:\n\tpoints which you can visualize as floating around,\n\tsomewhere in the space but nowhere in particular.\n\t(They'll correspond to prime non-maximal ideals.)\n\tThese will take the longest to get used to,\n\tbut as we progress we will begin to see that these non-closed points\n\tactually make life \\emph{easier},\n\tonce you get a sense of what they look like.\n\\end{enumerate}\n\n\\section{The set of points}\n\\prototype{$\\Spec \\CC[x_1, \\dots, x_n] / I$.}\n\nFirst surprise, for a ring $A$:\n\\begin{definition}\n\tThe set $\\Spec A$ is defined as the set of prime ideals of $A$.\n\\end{definition}\n\nThis might be a little surprising, since we might have guessed\nthat $\\Spec A$ should just have the maximal ideals.\nWhat do the remaining ideals correspond to?\nThe answer is that they will be so-called \\emph{non-closed points}\nor \\emph{generic points} which are ``somewhere'' in the space,\nbut nowhere in particular.\n(The name ``non-closed'' is explained next chapter.)\n\n\\begin{remark}\n\tAs usual $A$ itself is not a prime ideal, but $(0)$\n\tis prime if and only if $A$ is an integral domain.\n\\end{remark}\n\n\\begin{example}\n\t[Examples of spectrums]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\Spec \\CC[x]$ consists of a point $(x-a)$ for every $a \\in \\CC$,\n\t\twhich correspond to what we geometrically think of as $\\Aff^1$.\n\t\tIn additionally consists of a point $(0)$,\n\t\twhich we think of as a ``non-closed point'', nowhere in particular.\n\n\t\t\\ii $\\Spec \\CC[x,y]$ consists of points $(x-a,y-b)$\n\t\t(which are the maximal ideals) as well as $(0)$ again,\n\t\ta non-closed point that is thought of as ``somewhere in $\\CC^2$,\n\t\tbut nowhere in particular''.\n\t\tIt also consists of non-closed points corresponding to irreducible\n\t\tpolynomials $f(x,y)$, for example $(y-x^2)$,\n\t\twhich is a ``generic point on the parabola''.\n\n\t\t\\ii If $k$ is a field, $\\Spec k$ is a single point,\n\t\tsince the only maximal ideal of $k$ is $(0)$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Complex affine varieties]\n\tLet $I \\subseteq \\CC[x_1, \\dots, x_n]$ be an ideal.\n\tBy \\Cref{prop:prime_quotient},\n\tthe set \\[ \\Spec \\CC[x_1, \\dots, x_n] /I \\]\n\tconsists of those prime ideals of $\\CC[x_1, \\dots, x_n]$\n\twhich contain $I$: in other words, it has a\n\tpoint for every closed irreducible subvariety of $\\VV(I)$.\n\tSo in addition to the ``geometric points'' \n\t(corresponding to the maximal ideals $(x_1-a_1, \\dots, x_n-a_n)$\n\twe have non-closed points along each of the varieties).\n\\end{example}\n\nThe non-closed points are the ones you are not used to:\nthere is one for each non-maximal prime ideal\n(visualized as ``irreducible subvariety'').\nI like to visualize them in my head like a fly:\nyou can hear it, so you know it is floating \\emph{somewhere} in the room,\nbut as it always moving, you never know exactly where.\nSo the generic point of $\\Spec \\CC[x,y]$ corresponding to the prime\nideal $(0)$ is floating everywhere in the plane,\nthe one for the ideal $(y-x^2)$ floats along the parabola, etc.\n\\begin{center}\n\t\\includegraphics[scale=0.4]{media/calvin-hobbes-fly.png} \\\\\n\t\\footnotesize Image from \\cite{img:calvin_hobbes_fly}.\n\\end{center}\n\n\\begin{example}\n\t[More examples of spectrums]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\Spec \\ZZ$ consists of a point for every prime $p$,\n\t\tplus a generic point that is somewhere, but no where in particular.\n\n\t\t\\ii $\\Spec \\CC[x] / (x^2)$ has only $(x)$ as a prime ideal.\n\t\tThe ideal $(0)$ is not prime since $0 = x \\cdot x$.\n\t\tThus as a \\emph{topological space},\n\t\t$\\Spec \\CC[x] / (x^2)$ is a single point.\n\t\t\n\t\t\\ii $\\Spec \\Zc{60}$ consists of three points.\n\t\tWhat are they?\n\t\\end{enumerate}\n\\end{example}\n\n\\section{The Zariski topology on the spectrum}\n\\prototype{Still $\\Spec \\CC[x_1, \\dots, x_n] / I$.}\n\nNow, we endow a topology on $\\Spec A$.\nSince the points on $\\Spec A$ are the prime ideals, we continue\nthe analogy by thinking of the points $f$ as functions on $\\Spec A$. That is:\n\\begin{definition}\n\tLet $f \\in A$ and $\\kp \\in \\Spec A$.\n\tThen the \\vocab{value} of $f$ at $\\kp$ is defined to be $f \\pmod{\\kp}$,\n\tan element of $A/\\kp$.\n\tWe denote it $f(\\kp)$.\n\\end{definition}\n\\begin{example}\n\t[Vanishing locii in $\\Aff^n$]\n\tSuppose $A = \\CC[x_1, \\dots, x_n]$,\n\tand $\\km = (x_1-a_1, x_2-a_2, \\dots, x_n-a_n)$ is a maximal ideal of $A$.\n\tThen for a polynomial $f \\in \\CC$,\n\t\\[ f \\pmod \\km = f(a_1, \\dots, a_n) \\]\n\twith the identification that $\\CC/\\km \\cong \\CC$.\n\\end{example}\n\\begin{example}\n\t[Functions on $\\Spec \\ZZ$]\n\tConsider $A = \\Spec \\ZZ$.\n\tThen $2019$ is a function on $A$.\n\tIts value at the point $(5)$ is $4 \\pmod 5$;\n\tits value at the point $(7)$ is $3 \\pmod 7$.\n\\end{example}\n\nIndeed if you replace $A$ with $\\CC[x_1, \\dots, x_n]$\nand $\\Spec A$ with $\\Aff^n$ in everything that follows,\nthen everything will become quite familiar.\n\n\\begin{definition}\n\tLet $f \\in A$. We define the \\vocab{vanishing locus} of $f$ to be\n\t\\[ \\VV(f) = \\left\\{ \\kp \\in \\Spec A \\mid f(\\kp) = 0 \\right\\}\n\t\t= \\left\\{ \\kp \\in \\Spec A \\mid f \\in \\kp \\right\\}. \\]\n\tMore generally, just as in the affine case,\n\twe define the vanishing locus for an ideal $I$ as\n\t\\begin{align*}\n\t\t\\VV(I) &= \\left\\{ \\kp \\in \\Spec A \\mid f(\\kp)=0 \\; \\forall f \\in I \\right\\} \\\\\n\t\t&= \\left\\{ \\kp \\in \\Spec A \\mid f \\in \\kp \\; \\forall f \\in I \\right\\} \\\\\n\t\t&= \\left\\{ \\kp \\in \\Spec A \\mid I \\subseteq \\kp \\right\\}.\n\t\\end{align*}\n\tFinally, we define the \\vocab{Zariski topology} on $\\Spec A$\n\tby declaring that the sets of the form $\\VV(I)$ are closed.\n\\end{definition}\n\nWe now define a few useful topological notions:\n\\begin{definition}\n\tLet $X$ be a topological space.\n\tA point $p \\in X$ is a \\vocab{closed point}\n\tif the set $\\{p\\}$ is closed.\n\\end{definition}\n\\begin{ques}\n\t[Mandatory]\n\tShow that a point (i.e.\\ prime ideal)\n\t$\\km \\in \\Spec A$ is a closed point\n\tif and only if $\\km$ is a maximal ideal.\n\\end{ques}\nRecall also in \\Cref{def:closure} we denote by $\\ol S$\nthe closure of a set $S$ (i.e.\\ the smallest closed set containing $S$);\nso you can think of a closed point $p$ also\nas one whose closure is just $\\{p\\}$,\nwhile with a generic point\nTherefore the Zariski topology lets us refer back to the old ``geometric''\nas just the closed points.\n\n\\begin{example}\n\t[Non-closed points, continued]\n\tLet $A = \\CC[x,y]$ and let $\\kp = (y-x^2) \\in \\Spec A$;\n\tthis is the ``generic point'' on a parabola.\n\tIt is not closed, but we can compute its closure:\n\t\\[\n\t\t\\ol{\\{\\kp\\}}\n\t\t= \\VV(\\kp) = \\left\\{ \\kq \\in \\Spec A \\mid \\kq \\supseteq \\kp \\right\\}.\n\t\\]\n\tThis closure contains the point $\\kp$ as well\n\tas several maximal ideals $\\kq$, such as $(x-2,y-4)$ and $(x-3,y-9)$.\n\tIn other words, the closure of the ``generic point'' of the parabola\n\tis literally the set of all points that are actually on the parabola\n\t(including generic points).\n\n\tThat means the way to picture $\\kp$ is a point that\n\tis floating ``somewhere on the parabola'', but nowhere in particular.\n\tIt makes sense then that if we take the closure,\n\twe get the entire parabola,\n\tsince $\\kp$ ``could have been'' any of those points.\n\\end{example}\n\n\\begin{center}\n\\begin{asy}\n\tgraph.xaxis();\n\tgraph.yaxis();\n\treal f(real x) { return x*x; }\n\tgraph.xaxis(\"$x$\");\n\tgraph.yaxis(\"$y$\");\n\tdraw(graph(f,-2,2,operator ..), red+dotted, Arrows(TeXHead));\n\tdot(\"$(y-x^2)$\", (1.4, f(1.4)), dir(-45), red);\n\tdot(\"$(x+1,y-1)$\", (-1,1), dir(225), blue);\n\\end{asy}\n\\end{center}\n\n\\begin{example}\n\t[The generic point of the $y$-axis isn't on the $x$-axis]\n\tLet $A = \\CC[x,y]$ again.\n\tConsider $\\VV(y)$, which is the $x$-axis of $\\Spec A$.\n\tThen consider $\\kp = (x)$, which is the generic point on the $y$-axis.\n\tObserve that\n\t\\[ \\kp \\notin \\VV(y). \\]\n\tThe geometric way of saying this is that a \\emph{generic point}\n\ton the $y$-axis does not lie on the $x$-axis.\n\\end{example}\n\nWe now also introduce one more word:\n\\begin{definition}\n\tA topological space $X$ is \\vocab{irreducible}\n\tif either of the following two conditions hold:\n\t\\begin{itemize}\n\t\t\\ii The space $X$ cannot be written as the\n\t\tunion of two proper closed subsets.\n\t\t\\ii Any two nonempty open sets of $X$ intersect.\n\t\\end{itemize}\n\tA subset $Z$ of $X$ (usually closed) is irreducible\n\tif it is irreducible as a subspace.\n\\end{definition}\n\\begin{exercise}\n\tShow that the two conditions above are indeed equivalent.\n\tAlso, show that the closure of a point is always irreducible.\n\\end{exercise}\n\nThis is the analog of the ``irreducible''\nwe defined for affine varieties,\nbut it is now a topological definition,\nalthough in practice this definition is only\nuseful for spaces with the Zariski topology.\nIndeed, if any two nonempty open sets intersect\n(and there is more than one point),\nthe space is certainly not Hausdorff!\nAs with our old affine varieties,\nthe intuition is that $\\VV(xy)$ (the union of two lines)\nshould not be irreducible.\n\n\\begin{example}\n\t[Reducible and irreducible spaces]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The closed set $\\VV(xy) = \\VV(x) \\cup \\VV(y)$ is reducible.\n\t\t\\ii The entire plane $\\Spec \\CC[x,y]$ is irreducible.\n\t\tThere is actually a simple (but counter-intuitive,\n\t\tsince you are just getting used to generic points)\n\t\treason why this is true:\n\t\tthe generic point $(0)$ is in \\emph{every} open set,\n\t\tergo, any two open sets intersect.\n\t\\end{enumerate}\n\\end{example}\n\nSo actually, the generic points\nkind of let us cheat our way through the following bit:\n\\begin{proposition}\n\t[Spectrums of integral domains are irreducible]\n\tIf $A$ is an integral domain,\n\tthen $\\Spec A$ is irreducible.\n\\end{proposition}\n\\begin{proof}\n\tJust note $(0)$ is a prime ideal,\n\tand in every open set.\n\\end{proof}\nYou should compare this with our old classical result that\n$\\CC[x_1, \\dots, x_n]/I$\nwas irreducible as an affine variety exactly when $I$ was prime.\nThis time, the generic point actually takes care\nof the work for us:\nthe fact that it is \\emph{allowed} to float\nanywhere in the plane lets us capture the idea that\n$\\Aff^2$ should be irreducible\nwithout having to expend any additional effort.\n\\begin{remark}\n\tSurprisingly, the converse of this proposition is false:\n\twe have seen $\\Spec \\CC[x]/(x^2)$ has only one point,\n\tso is certainly irreducible.\n\tBut $A = \\CC[x]/(x^2)$ is not an integral domain.\n\tSo this is one weird-ness introduced by allowing ``non-radical'' behavior.\n\\end{remark}\n\nAt this point you might notice something:\n\\begin{theorem}\n\t[Points are in bijection with irreducible closed sets]\n\tConsider $X = \\Spec A$.\n\tFor every irreducible closed set $Z$,\n\tthere is exactly one point $\\kp$ such that $Z = \\ol{\\{\\kp\\}}$.\n\t(In particular points of $X$ are in bijection\n\twith closed subsets of $X$.)\n\\end{theorem}\n\\begin{proof}\n\t[Idea of proof]\n\tThe point $\\kp$ corresponds to the closed set $\\VV(\\kp)$,\n\twhich one can show is irreducible.\n\t% Maybe I really should prove this here,\n\t% but I don't really want to draw to much attention to radicals yet;\n\t% there's too much going on already.\n\\end{proof}\nThis gives you a better way to draw non-closed points:\nthey are the generic points lying along any irreducible closed set\n(consisting of more than just one point).\n\nAt this point\\footnote{Pun not intended},\nI may as well give you the real definition of generic point.\n\\begin{definition}\n\tGiven a topological space $X$,\n\ta \\vocab{generic point} $\\eta$\n\tis a point whose closure is the entire space $X$.\n\\end{definition}\nSo for us, when $A$ is an integral domain,\n$\\Spec A$ has generic point $(0)$.\n\\begin{abuse}\n\tVery careful readers might note I am being a little careless\n\twith referring to $(y-x^2)$ as\n\t``the generic point along the parabola''\n\tin $\\Spec \\CC[x,y]$.\n\tWhat's happening is that $\\VV(y-x^2)$ is a closed set,\n\tand as a topological subspace, it has generic point $(y-x^2)$.\n\\end{abuse}\n\n\\section{On radicals}\nBack when we studied classical algebraic geometry in $\\CC^n$,\nwe saw Hilbert's Nullstellensatz (\\Cref{thm:hilbert_null}) show up\nto give bijections between radical ideals and affine varieties;\nwe omitted the proof, because it was nontrivial.\n\nHowever, for a \\emph{scheme}, where the points \\emph{are} prime ideals\n(rather than tuples in $\\CC^n$),\nthe corresponding results will actually be \\emph{easy}:\neven in the case where $A = \\CC[x_1, \\dots, x_n]$,\nthe addition of prime ideals (instead of just maximal ideals)\nwill actually \\emph{simplify} the proof,\nbecause radicals play well with prime ideals.\n\nWe still have the following result.\n\\begin{proposition}\n\t[$\\VV(\\sqrt I) = \\VV(I)$]\n\tFor any ideal $I$ of a ring $A$\n\twe have $\\VV(\\sqrt I) = \\VV(I)$.\n\\end{proposition}\n\\begin{proof}\n\tWe have $\\sqrt I \\supseteq I$.\n\tHence automatically $\\VV(\\sqrt I) \\subseteq \\VV(I)$.\n\n\tConversely, if $\\kp \\in \\VV(I)$, then $I \\subseteq \\kp$,\n\tso $\\sqrt I \\subseteq \\sqrt{\\kp} = \\kp$\n\t(by \\Cref{prop:radical}).\n\\end{proof}\n\nWe hinted the key result in an earlier remark,\nand we now prove it.\n\\begin{theorem}\n\t[Radical is intersection of primes]\n\t\\label{thm:radical_intersect_prime}\n\tLet $I$ be an ideal of a ring $A$.\n\tThen \\[ \\sqrt I = \\bigcap_{\\kp \\supseteq I} \\kp. \\]\n\\end{theorem}\n\\begin{proof}\n\tThis is a famous statement from commutative algebra,\n\tand we prove it here only for completeness.\n\tIt is ``doing most of the work''.\n\n\tNote that if $I \\subseteq \\kp$,\n\tthen $\\sqrt I \\subseteq \\sqrt{\\kp} = \\kp$;\n\tthus $\\sqrt I \\subseteq \\bigcap_{\\kp \\supseteq I} \\kp$.\n\n\tConversely, suppose $x \\notin \\sqrt I$,\n\tmeaning $1, x, x^2, x^3, \\dots \\notin I$.\n\tThen, consider the localization $A[1/x]$.\n\tLike any ring, it has some maximal ideal (Krull's theorem).\n\tThis means our usual bijection between prime ideals of $A[1/x]$\n\tgives some prime ideal $\\kp$ of $A$ containing $I$ but not containing $x$.\n\tThus $x \\notin \\bigcap_{\\kp \\supseteq I} \\kp$,\n\tas desired.\n\\end{proof}\n\\begin{remark}\n\t[A variant of Krull's theorem]\n\tThe longer direction of this proof is essentially\n\tsaying that for any $x \\in A$,\n\tthere is a maximal ideal of $A$ not containing $x$.\n\tThe ``short'' proof is to use Krull's theorem on $A[1/x]$ as above,\n\tbut one can also still prove it directly using Zorn's lemma\n\t(by copying the proof of the original Krull's theorem).\n\\end{remark}\n\n\\begin{example}\n\t[$\\sqrt{(2016)} = (42)$ in $\\ZZ$]\n\tIn the ring $\\ZZ$, we see that $\\sqrt{(2016)} = (42)$,\n\tsince the distinct primes containing $(2016)$\n\tare $(2)$, $(3)$, $(7)$.\n\\end{example}\n\nGeometrically, this gives us a good way to describe $\\sqrt I$:\nit is the \\emph{set of all functions vanishing on all of $\\VV(I)$}.\nIndeed, we may write\n\\[ \\sqrt I = \\bigcap_{\\kp \\supset I} \\kp\n\t= \\bigcap_{\\kp \\in \\VV(I)} \\kp\n\t= \\bigcap_{\\kp \\in \\VV(I)} \\left\\{ f \\in A \\mid f(\\kp) = 0 \\right\\}. \\]\n\nWe can now state:\n\\begin{theorem}\n\t[Radical ideals correspond to closed sets]\n\tLet $I$ and $J$ be ideals of $A$,\n\tand considering the space $\\Spec A$.\n\tThen\n\t\\[ \\VV(I) = \\VV(J) \\iff \\sqrt I = \\sqrt J. \\]\n\tIn particular, radical ideals exactly\n\tcorrespond to closed subsets of $\\Spec A$.\n\\end{theorem}\n\\begin{proof}\n\tIf $\\VV(I) = \\VV(J)$,\n\tthen $\\sqrt I = \\bigcap_{\\kp \\in \\VV(I)} \\kp =\n\t\\bigcap_{\\kp \\in \\VV(J)} \\kp = \\sqrt J$ as needed.\n\n\tConversely, suppose $\\sqrt I = \\sqrt J$.\n\tThen $\\VV(I) = \\VV(\\sqrt I) = \\VV(\\sqrt J) = \\VV(J)$.\n\\end{proof}\n\nCompare this to the theorem we had earlier\nthat the \\emph{irreducible} closed subsets correspond to \\emph{prime} ideals!\n\n\\section{\\problemhead}\nAs \\Cref{ch:spec_examples} contains many\nexamples of affine schemes to train your intuition,\nit's possibly worth reading even before attempting these problems,\neven though there will be some parts that won't make sense yet.\n\n\\begin{problem}\n\t[{$\\Spec \\QQ[x]$}]\n\tDescribe the points and topology of $\\Spec \\QQ[x]$.\n\t\\begin{hint}\n\t\tGalois conjugates.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[Product rings]\n\tDescribe the points and topology of $\\Spec A \\times B$\n\tin terms of $\\Spec A$ and $\\Spec B$.\n\\end{problem}\n\n\\begin{problem}\n\tShow that if $A$ is \\emph{not} an integral domain,\n\tthen $\\Spec A$ is not irreducible.\n\\end{problem}\n\n\\endinput\n\n\\begin{problem}\n\t[From Andrew Critch]\n\t\\gim\n\tLet $A$ be a Noetherian ring.\n\tShow that $A$ is an integral domain if and only if it has no idempotents,\n\tand $A_\\kp$ is an integral domain for every prime $\\kp$.\n\t\\begin{hint}\n\t\tShow that if $\\Spec A$ is connected and its stalks are irreducible,\n\t\tthen $\\Spec A$ is itself irreducible.\n\t\tConsider nilradical $N = \\sqrt{(0)}$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThis is the proposition on the second page of\n\t\t\\url{http://www.acritch.com/media/math/Stalk-local_detection_of_irreducibility.pdf}\n\t\\end{sol}\n\\end{problem}\n\n", "meta": {"hexsha": "a7cd9fa71b49edd9f9f499afe17758d0f0bd571b", "size": 18344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-geom/spec-zariski.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-geom/spec-zariski.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-geom/spec-zariski.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.7582846004, "max_line_length": 85, "alphanum_fraction": 0.6979393807, "num_tokens": 5632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.6695955901421043}}
{"text": "\\documentclass{article}\n\\usepackage[T1,T2A]{fontenc}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{amsmath}\n\\usepackage{siunitx}\n\\begin{document}\n\\title{Flight Model}\n\\author{Vasili V}\n\\renewcommand{\\today}{November 22, 2018}\n\\maketitle\n\\section{Lift}\nThe buoyant force on a balloon of diameter $d$ with density of content $\\rho_{in}$ and environmental density $\\rho_{out}$:\n\\begin{equation}\n\\begin{aligned}\nF_b &= (\\rho_{out} - \\rho_{in})g\\frac{\\pi{d}^3}{6},\n\\end{aligned}\n\\end{equation}\nwhere content is Helium with density (at STP):\n\\begin{equation}\n\\begin{aligned}\n\\rho_{in} &= 0.1786 && [\\si{kg.m^{-3}}].\n\\end{aligned}\n\\end{equation}\nThe environment is standard atmosphere taken from \\cite{NASA76} at zero altitude:\n\\begin{equation}\n\\begin{aligned}\n\\rho_{out} &= 1.225 && [\\si{kg.m^{-3}}].\n\\end{aligned}\n\\end{equation}\nunder following conditions:\n\\begin{equation}\n\\begin{aligned}\np &= \\num{1.01325e5} && [\\si{kg.m^{-3}}]. \\\\\nT &= \\num{288.15} && [\\si{\\kelvin}].\n\\end{aligned}\n\\end{equation}\nUnder the conditions Helium density is:\n\\begin{equation}\n\\begin{aligned}\n\\rho_{in} &= 0.1786\\cdot\\frac{\\num{1.01325e5}}{\\num{1e5}}\\cdot\\frac{\\num{273.15}}{\\num{288.15}} = 0.1715 && [\\si{kg.m^{-3}}].\n\\end{aligned}\n\\end{equation}\nLet's simplify equation (1):\n\\begin{equation}\n\\begin{aligned}\nF_b &= k_0d^3,\n\\end{aligned}\n\\end{equation}\nwhere $k_0$ is:\n\\begin{equation}\n\\begin{aligned}\nk_0 &= \\frac{\\pi}{6}\\cdot\\num{9.81}\\cdot(\\num{1.225}-\\num{0.1715}) = 5.411. && [\\si{\\newton.m^{-3}}]\n\\end{aligned}\n\\end{equation}\nFor example balloons with diameters $\\num{0.36}$, $\\num{0.70}$ and $\\num{1.15}$ $\\si{m}$ get following lifts:\n\\begin{equation}\n\\begin{aligned}\nF_s &= \\num{5.411}\\cdot\\num{0.36}^3 = 0.2525 [\\si{\\newton}] = 25.74 [\\si{gf}]; \\\\\nF_m &= \\num{5.411}\\cdot\\num{0.70}^3 = 1.856 [\\si{\\newton}] = 189.3 [\\si{gf}]; \\\\\nF_b &= \\num{5.411}\\cdot\\num{1.15}^3 = 8.230 [\\si{\\newton}] = 839.2 [\\si{gf}].\n\\end{aligned}\n\\end{equation}\nThese balloons have following volumes:\n\\begin{equation}\n\\begin{aligned}\nV_s &= 24.43 && [\\si{L}]; \\\\\nV_m &= 179.6 && [\\si{L}]; \\\\\nV_b &= 796.3 && [\\si{L}],\n\\end{aligned}\n\\end{equation}\nwhich is approximately $\\frac{1}{57}$, $\\frac{1}{7}$ and $\\frac{2}{3}$ of 10 L tank.\n\\begin{thebibliography}{9}\n\\bibitem{NASA76}\n  NOAA, NASA, USAF,\n  US. Standard Atmosphere,\n  1976\n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "20daee05881300180ee5a2a1fdf999f2b9b7451f", "size": 2349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "flight-model/model.tex", "max_stars_repo_name": "capsoid/hab", "max_stars_repo_head_hexsha": "9be7a461603adae357dc031b9d1d63d3ed7c46f4", "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": "flight-model/model.tex", "max_issues_repo_name": "capsoid/hab", "max_issues_repo_head_hexsha": "9be7a461603adae357dc031b9d1d63d3ed7c46f4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-05T08:42:50.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-05T08:42:50.000Z", "max_forks_repo_path": "flight-model/model.tex", "max_forks_repo_name": "capsoid/hab", "max_forks_repo_head_hexsha": "9be7a461603adae357dc031b9d1d63d3ed7c46f4", "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.3625, "max_line_length": 125, "alphanum_fraction": 0.6581524053, "num_tokens": 915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6695955882027506}}
{"text": "\\subsection{Proof of Theorem \\ref{thm:finite}}\nFirst, for any $\\epsilon > 0$,\n$$\\begin{aligned}\n\\Pr[U_S(F) > \\epsilon] =& \\Pr[\\exists f\\in F, A_S(f) - A_D(f) > \\epsilon] \\\\\n\\leq & \\sum_{f\\in F} \\Pr[A_S(f) - A_D(f) > \\epsilon] \\\\\n=& \\sum_{f\\in F} \\Pr[\\frac{1}{k} \\sum_{i=1}^k f(s_i) - A_D(f) > \\epsilon]. \\\\\n\\end{aligned}$$ \nBy Hoeffding's inequality \\cite{BBL04} we have\n$$\\Pr[\\frac{1}{k} \\sum_{i=1}^k f(s_i) - A_D(f) > \\epsilon] \\leq \\exp\\left(-\\frac{2k\\epsilon^2}{m^2}\\right).$$\nHence\n$$\\Pr[U_S(F) > \\epsilon] \\leq |F| \\exp\\left(-\\frac{2k\\epsilon^2}{m^2}\\right).$$\nSimilarly one can show that\n$$\\Pr[\\sup_{f\\in F} [ A_D(f) - A_S(f) ] > \\epsilon] \\leq |F| \\exp\\left(-\\frac{2k\\epsilon^2}{m^2}\\right).$$\nThus putting the two cases together,\n$$\\Pr[\\sup_{f\\in F} | A_S(f) - A_D(f) | > \\epsilon] \\leq 2|F| \\exp\\left(-\\frac{2k\\epsilon^2}{m^2}\\right).$$\nEquivalently for any $\\delta>0$, with probability at least $1-\\delta$,\n$$\\sup_{f\\in F} | A_S(f) - A_D(f) | \\leq m\\sqrt{\\frac{\\log(2|F|) + \\log(1/\\delta)}{2k}}.$$\nWe have obtained the desired upper bound in Theorem \\ref{thm:finite}.\n\n\\subsection{Proof of Theorem \\ref{thm:main}}\nIn this section, we show our main result (Theorem \\ref{thm:main}).\nWe start from the definition of self bounding function \\cite{Oneto13}.\n\\begin{definition}\nLet $s_1$, $s_2$, $\\cdots$, $s_k$ be independent random variables taking values from a set $D$. A function $f: D^k \\to [0, +\\infty]$ is a self bounding function if there exists a constant $c$ and a function $g: D^{k-1}\\to \\mathbb{R}$ such that for any $s_1$, $\\cdots$, $s_{j-1}$, $s_{j+1}$, $\\cdots$, $s_k \\in D$, the following conditions hold:\n$$0 \\leq f(s_1, \\cdots, s_k) - g(s_1,\\cdots, s_{j-1}, s_{j+1}, \\cdots, s_k) \\leq c,$$\n$$\\sum_{j=1}^k [f(s_1, \\cdots, s_k) - g(s_1,\\cdots, s_{j-1}, s_{j+1}, \\cdots, s_k)] \\leq f(s_1, \\cdots, s_k).$$\n\\end{definition}\n\nThe following concentration inequality can be achieved for self bounding functions \\cite{BLM99}.\n\n\\begin{lemma}\n\\cite{BLM99} If a function $Z = f(s_1,\\cdots,s_k)$ is a self bounding function with constant $c$, then for $t \\leq \\E Z$,\n$$\\Pr[\\E Z - Z \\geq t] \\leq \\exp\\left(-\\frac{t^2}{2c\\E Z}\\right).$$\nFor $t > \\E Z$, the left probability is zero trivially.\nHere we take randomness over $s_1$, $s_2$, $\\cdots$, $s_k$.\n\\end{lemma}\n\nBy using the above lemma, we can show a similar inequality for Rademacher average. \n\n\\begin{lemma}\n\\label{lem1}\n$$\\Pr[\\E R_S(F) \\geq R_S(F) + t] \\leq \\exp\\left(-\\frac{kt^2}{4m\\E R_S(F)}\\right),$$\nwhere $\\E$ takes randomness over the samplings $s_1$, $s_2$, $\\cdots$, $s_k$.\n\\end{lemma}\n\\begin{proof}\nIt suffices to show that $R_S(F)$ is a self bounding function with constant $c=2m/k$.\nDefine\n$$Z = R_S(F) = \\E_\\sigma \\sup_{f\\in F} \\left[\\frac{2}{k}\\sum_{i=1}^k \\sigma_i f(s_i) \\right],$$\n$$G_j = \\E_\\sigma \\sup_{f\\in F} \\left[\\frac{2}{k}\\sum_{i\\not= j} \\sigma_i f(s_i) \\right].$$\nIt is clear that $Z$ is non-negative:\n$$Z \\geq \\sup_{f\\in F} \\left[ \\E_\\sigma \\frac{2}{k}\\sum_{i=1}^k \\sigma_i f(s_i) \\right]=0.$$\nAlso it is clear that $Z \\geq G_j$ for each $j$: suppose $\\tilde{f}$ achieves the supreme of $G_j$. Then\n$$\\begin{aligned}\nG_j &= \\E_\\sigma \\left[\\frac{2}{k}\\sum_{i=1}^k \\sigma_i \\tilde{f}(s_i) - \\frac{2}{k} \\sigma_j \\tilde{f}(s_j)\\right] \\\\\n&= \\E_\\sigma \\left[\\frac{2}{k}\\sum_{i=1}^k \\sigma_i \\tilde{f}(s_i)\\right] - \\E_\\sigma \\left[ \\frac{2}{k} \\sigma_j \\tilde{f}(s_j)\\right] \\\\\n&= \\E_\\sigma \\left[\\frac{2}{k}\\sum_{i=1}^k \\sigma_i \\tilde{f}(s_i) \\right]  \\leq Z.\n\\end{aligned}$$\nNext we show $Z- G_j \\leq 2m/k =c$:\n$$\\begin{aligned}\nG_j &= \\E_\\sigma \\sup_{f\\in F} \\left[ \\frac{2}{k} \\sum_{i=1}^k \\sigma_i f(s_i) - \\frac{2}{k} \\sigma_j f(s_j) \\right] \\\\\n&\\geq \\E_\\sigma \\sup_{f\\in F} \\left[ \\frac{2}{k} \\sum_{i=1}^k \\sigma_i f(s_i) \\right] - \\E_\\sigma \\sup_{f\\in F} \\left[ \\frac{2}{k} \\sigma_j f(s_j) \\right] \\\\\n&\\geq \\E_\\sigma \\sup_{f\\in F} \\left[ \\frac{2}{k} \\sum_{i=1}^k \\sigma_i f(s_i) \\right] - \\frac{2m}{k}.\n\\end{aligned}$$\nFinally we need to verify $\\sum_{j=1}^k Z-G_j \\leq Z$:\n$$\\begin{aligned}\n\\sum_{j=1}^k G_j &= \\E_\\sigma \\sum_{j=1}^k \\sup_{f\\in F} \\left[ \\frac{2}{k}\\sum_{i\\not= j} \\sigma_i f(s_i) \\right]\\\\\n&\\geq \\E_\\sigma \\sup_{f\\in F}\\left[ \\frac{2}{k} \\sum_{j=1}^k \\sum_{i\\not= j} \\sigma_i f(s_i) \\right]\\\\\n&=\\frac{2(k-1)}{k} \\E_\\sigma \\sup_{f\\in F}\\left[\\sum_{j=1}^k \\sigma_i f(s_i) \\right] = (k-1)Z.\n\\end{aligned}$$\n\\end{proof}\n\nWe still need the following lemma on the relation between uniform deviation and Rademacher average.\n\n\\begin{lemma}\n\\label{lem2}\n$$\\E \\sup_{f\\in F} [ A_S(f) - A_D(f) ] \\leq \\E R_S(F),$$\n$$\\E \\sup_{f\\in F} [ A_D(f) - A_F(f) ] \\leq \\E R_S(F).$$\nHere we take randomness over the $k$ samplings.\n\\end{lemma}\n\\begin{proof}\nThe proof idea is based on ghost samplings, i.e., independently draw another $k$ samples: $s_1'$, $\\cdots$, $s_k'$, and then we have\n$$A_D(f) = \\frac{1}{m}\\sum_{i=1}^m f(i) = \\E \\frac{1}{k} \\sum_{j=1}^k f(s_j'),$$\nwhere $\\E$ takes randomness over the $k$ ghost samples.\nThus\n$$\\begin{aligned}\n\\E \\sup_{f\\in F} [ A_S(f) - A_D(f) ] &= \\E \\sup_{f\\in F} \\left[\\frac{1}{k} \\sum_{i=1}^k f(s_i) - \\E \\frac{1}{k} \\sum_{j=1}^k f(s_j') \\right]\\\\\n&\\leq \\E \\sup_{f\\in F} \\left[\\frac{1}{k} \\sum_{i=1}^k f(s_i) - \\frac{1}{k} \\sum_{j=1}^k f(s_j') \\right].\\\\\n\\end{aligned}$$\nSince all the samples $s$, $s'$ are independently identically distributed, flipping the sign of $f(s_i) - f(s_i')$ will not change the expected supreme, i.e.,\n$$\\E \\sup_{f\\in F} \\left[\\frac{1}{k} \\sum_{i=1}^k f(s_i) - \\frac{1}{k} \\sum_{j=1}^k f(s_j') \\right] = \\E \\sup_{f\\in F} \\frac{1}{k} \\sum_{i=1}^k \\left[\\sigma_i (f(s_i) - f(s_i')) \\right],$$\nwhere $\\sigma_i$ is uniformly distributed over $\\{-1, 1\\}$.\nSince \n$$\\E \\sup_{f\\in F} \\frac{1}{k} \\sum_{i=1}^k \\left[\\sigma_i (f(s_i) - f(s_i')) \\right] \\leq 2 \\E \\sup_{f\\in F} \\frac{1}{k} \\sum_{i=1}^k \\sigma_i f(s_i)  = \\E R_S(F),$$\nwe have shown the first inequality. The second inequality is analogous.\n\\end{proof}\n\nWe also need McDiarmid's inequality \\cite{M89}.\n\\begin{lemma}\n\\cite{M89} Let $s_1$, $\\cdots$, $s_k$ be independent random variables taking values from a set $D$. Suppose a function $h: D^k \\to \\mathbb{R}$ satisfies\n$$\\sup_{x_1,\\cdots,x_k,x_i'\\in D} |h(x_1,\\cdots,x_k) - h(x_1,\\cdots,x_{i-1},x_i',x_{i+1},\\cdots,x_k)| \\leq c_i$$\nfor some constants $c_i$ and every $1\\leq i \\leq k$. Then for any $t>0$, we have\n$$\\Pr[h(s_1,\\cdots,s_k) - \\E h(s_1,\\cdots,s_k) \\geq t] \\leq \\exp\\left(-\\frac{2t^2}{\\sum_{i=1}^k c_i^2}\\right).$$\n\\end{lemma}\n\nBy the above three lemmas, we can bound the difference between true average and sampled average as follows.\n\\begin{lemma}\n$$\\begin{aligned}\n&\\Pr\\left[\\sup_{f\\in F} |A_D(f) - A_S(f)| \\geq R_S(F) + t\\right] \\\\\n\\leq& 4\\exp\\left(-\\frac{2kt^2}{(m+\\sqrt{8m\\E R_S(F)})^2} \\right).\\end{aligned}$$\n\\end{lemma}\n\\begin{proof}\nFirst by Lemma \\ref{lem2},\n$$\\begin{aligned}\n&\\Pr\\left[\\sup_{f\\in F} [A_D(f) - A_S(f)] \\geq R_S(F) + t\\right] \\\\\n\\leq& \\Pr\\left[\\sup_{f\\in F} [A_D(f) - A_S(f)] \\geq \\E\\sup_{f\\in F} [A_D(f) - A_S(f)] + at\\right] \\\\\n&+ \\Pr\\left[\\E R_S(F) \\geq R_S(F)+(1-a)t\\right] \\\\\n\\end{aligned}$$\nfor any $a\\in [0,1]$. Let\n$$h(s_1,\\cdots,s_k) = A_D(f) - A_S(f) = A_D(f) - \\frac{1}{k}\\sum_{i=1}^k f(s_i).$$\nIt is clear that \n$$\\begin{aligned}\n&\\sup_{x_1,\\cdots,x_k,x_i'\\in D} |h(x_1,\\cdots,x_k) - h(x_1,\\cdots,x_{i-1},x_i',x_{i+1},\\cdots,x_k)| \\\\\n=&\\sup_{x_1,\\cdots,x_k,x_i'\\in D} \\left|\\frac{1}{k}\\sum_{j=1, j\\not=i}^k f(x_j)+\\frac{1}{k}f(x_i') - \\frac{1}{k}\\sum_{i=1}^k f(x_i)\\right| \\\\\n=&\\sup_{x_1,\\cdots,x_k,x_i'\\in D} \\left|\\frac{1}{k}f(x_i') - \\frac{1}{k} f(x_i)\\right| \\leq \\frac{m}{k}.\n\\end{aligned}$$\nBy McDiarmid's inequality,\n$$\\begin{aligned}\n&\\Pr\\left[\\sup_{f\\in F} [A_D(f) - A_S(f)] \\geq \\E\\sup_{f\\in F} [A_D(f) - A_S(f)] + at\\right] \\\\\n\\leq& \\exp\\left(-\\frac{2a^2t^2}{\\sum_{i=1}^k m^2/k^2}\\right)\n=\\exp\\left(-\\frac{2ka^2t^2}{m^2}\\right).\n\\end{aligned}$$\n\nBy Lemma \\ref{lem1},\n$$\\Pr\\left[\\E R_S(F) \\geq R_S(F)+(1-a)t\\right] \\leq \\exp\\left(-\\frac{k(1-a)^2t^2}{4m\\E R_S(F)}\\right).$$\nLet $a = 1/(1+\\sqrt{8\\E R_S(F) / m})$. Then putting everything together, we have \n$$\\begin{aligned}\n&\\Pr\\left[\\sup_{f\\in F} [A_D(f) - A_S(f)] \\geq R_S(F) + t\\right] \\\\\n\\leq& 2\\exp\\left(-\\frac{2kt^2}{(m+\\sqrt{8m\\E R_S(F)})^2} \\right).\\end{aligned}$$\nSimilarly one can show \n$$\\begin{aligned}\n&\\Pr\\left[\\sup_{f\\in F} [A_S(f) - A_D(f)] \\geq R_S(F) + t\\right] \\\\\n\\leq& 2\\exp\\left(-\\frac{2kt^2}{(m+\\sqrt{8m\\E R_S(F)})^2} \\right).\\end{aligned}$$\nThus we have the inequality as desired.\n\\end{proof}\nBy the above lemma we have the following important corollary.\n\\begin{corollary}\nWith probability at least $1-\\delta$, we have\n$$\\sup_{f\\in F}|A_S(f) - A_D(f)| \\leq R_S(F) + (m+\\sqrt{8m \\E R_S(F)})\\sqrt{\\frac{\\log \\frac{4}{\\delta}}{2k}}.$$\n\\end{corollary}\n\nWe still need to upper bound $\\E R_S(F)$. By Lemma \\ref{lem1}, with probability at least $1-\\delta$,\n$$\\E R_S(F) \\leq R_S(F) + \\sqrt{4m\\E R_S(F)\\frac{\\log \\frac{1}{\\delta}}{k}}.$$\nOr equivalently,\n$$\\sqrt{\\E R_S(F)} \\leq \\sqrt{\\frac{m}{k}\\log \\frac{1}{\\delta}} + \\sqrt{\\frac{m}{k}\\log \\frac{1}{\\delta} + R_S(F)}.$$\nHence with probability at least $1-2\\delta$, we have\n$$\\sup_{f\\in F}|A_S(f) - A_D(f)| \\leq R_S(F) + \\left(m+m\\sqrt{\\frac{8}{k}\\log \\frac{1}{\\delta}} + m\\sqrt{\\frac{8}{k}\\log \\frac{1}{\\delta} + \\frac{8R_S(F)}{m}}\\right)\\sqrt{\\frac{\\log \\frac{4}{\\delta}}{2k}}.$$\nWe have shown Theorem \\ref{thm:main}.\n\n\n\\subsection{Proof of Theorem \\ref{thm2}}\nFor any $s>0$, by Jensen's inequality,\n$$\\begin{aligned}\n\\exp(skR_S(F)) & = \\exp\\left(2s\\E_\\sigma \\sup_{f\\in F} \\sum_{i=1}^k \\sigma_i f(s_i)\\right) \\\\\n&\\leq \\E_\\sigma \\exp\\left(2s \\sup_{f\\in F} \\sum_{i=1}^k \\sigma_i f(s_i)\\right) \\\\\n&\\leq \\E_\\sigma \\sum_{f\\in F} \\exp\\left(2s\\sum_{i=1}^k \\sigma_i f(s_i)\\right).\n\\end{aligned}$$\nBy Hoeffding's Lemma \\cite{H63},\n$$\\begin{aligned}\n&\\E_\\sigma \\sum_{f\\in F} \\exp\\left(2s\\sum_{i=1}^k \\sigma_i f(s_i)\\right) \\\\\n\\leq & \\sum_{f\\in F}\\prod_{i=1}^k \\exp\\left(2s^2f(s_i)^2\\right) \\\\\n=& \\sum_{f\\in F} \\exp\\left(2s^2\\sum_{i=1}^k f(s_i)^2\\right).\n\\end{aligned}$$\nLet $\\ell^2 = \\sup_{f\\in F}\\sum_{i=1}^k f(s_i)^2$, and then\n$$\\sum_{f\\in F} \\exp\\left(2s^2\\sum_{i=1}^k f(s_i)^2\\right) \\leq |F| \\exp\\left(2s^2\\ell^2\\right).$$\nThus\n$$R_S(F) \\leq \\frac{1}{sk}(\\log|F| + 2s^2\\ell^2),$$\nfor any $s>0$. It turns out that to minimize the right hand side of the above equation, we have\n$$s = \\sqrt{\\frac{\\log|F|}{2\\ell^2}}.$$\nThen\n$$R_S(F) \\leq \\frac{\\ell}{k}\\sqrt{8\\log |F|}.$$ \n\n\n\\subsection{Discussions of Theorem \\ref{thm:new}}\nTheorem \\ref{thm:new} can be treated as a special case of Theorem \\ref{thm:finite} and Theorem \\ref{thm:main} when $m=c$. All the reasoning will not be affected and thus the desired bound follows.", "meta": {"hexsha": "f6b78e9b7192552cc2d75d187220d352fa29f496", "size": 10563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cos_sim_apprx/appendix.tex", "max_stars_repo_name": "shiyujiucsb/incubator", "max_stars_repo_head_hexsha": "2d14c41a935741cb89a399389cca92d07c415292", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-06-05T09:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-05T09:04:46.000Z", "max_issues_repo_path": "cos_sim_apprx/appendix.tex", "max_issues_repo_name": "shiyujiucsb/incubator", "max_issues_repo_head_hexsha": "2d14c41a935741cb89a399389cca92d07c415292", "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": "cos_sim_apprx/appendix.tex", "max_forks_repo_name": "shiyujiucsb/incubator", "max_forks_repo_head_hexsha": "2d14c41a935741cb89a399389cca92d07c415292", "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.4076086957, "max_line_length": 344, "alphanum_fraction": 0.6182902584, "num_tokens": 4654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6695955862633969}}
{"text": "\\subsection{Loss functions}\nHere we are going to discuss some of the loss functions that have been tested in this field so far, and that are relevant to this article. We will look away from the content loss as this part has stayed the same for virtually all papers on the matter.\n\\newline\\newline\nStyle loss was initially discovered to be separable from content loss in a CNN (namely VGG16) by gatys et al \\cite{Gatys:1}. They calculated what is known as the gram matrix which represents the style of an image as correlation between different features. The style loss is the squared error between the gram matrix of the features of the reference style image and the image for which we are minimizing the loss function. This function has been the basis for several other style transfer algorithms, and was for instance approximated with a neural net by Johnson et al \\cite{Johnson:1} trained on a certain style.\n\\newline\\newline\nAnother key finding was that the distribution of the features was a more complete representation of style. This lead to Huang et al. \\cite{Huang:1} testing out minimizing the wasserstein distance between the features instead. This new representation of style produced results of higher artistic quality. Other techniques based the idea of the distance between two distributions as loss has also been tested out with MMD (Maximum mean discrepancy) as the distance measure in a paper by Li et al. \\cite{Li:2} where they also combined it with the gram matrix. Chuan Li and Michael Wand used markov random fields to calculate an alternative to the gram matrix entirely \\cite{Li:3}. Other style loss functions that noteworthy but not too relevant to delve into here are histogram loss \\cite{Risser:1} and coral loss \\cite{sun:1}\n\\newline\\newline\nTemporal loss has not been the main focus on this article we will just briefly go through the ones used. To go from picture style transfer to video style transfer we must introduce a temporal loss to avoid flickering, meaning that we should punish frames for being to different. The easiest way to do this is to just look at the difference between the current frame and the previous. This is known as short-term temporal loss. Long-term temporal loss is doing the same but for multiple previous frames. this will create more stable results given a greater context of the current frame.\n\\newline\\newline\nAfter applying style transfer on an image with Gatys et al \\cite{Gatys:1}, we can end up with an image with many high frequency artifacts. To get rid of these variations in the output image, we want to penalize local variation. We can define this local variation loss as\n\\begin{equation}\n    \\sum{|y_{i+1}-y_i|^\\beta}\n\\end{equation}\nwhere $\\beta\\in\\{1,2\\}.$ Here $y$ are the pixel-values in one row of the output image \\cite{Zhaoyou:1}. Now we can extend Equation (\\ref{eq:total_loss}) with the total variation loss\n\\begin{equation}\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})+\\lambda\\mathcal{L}_\\text{TV}(\\vec{x})\n\\end{equation}\nwhere $\\lambda$ is the weight for the total variation loss.\n\\newpage", "meta": {"hexsha": "ffabba335401246656e8c09470a420b1711b32ce", "size": 3179, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Background/loss-functions.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/Background/loss-functions.tex", "max_issues_repo_name": "kjerand/video-style-transfer", "max_issues_repo_head_hexsha": "fe44a1b486e976725cddd6db4981b161dea13813", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/Background/loss-functions.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": 167.3157894737, "max_line_length": 823, "alphanum_fraction": 0.7851525637, "num_tokens": 757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6695955804453355}}
{"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-02.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 2 Covariant 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.\n\n   \\nabla{#}::Derivative.\n   \\partial{#}::PartialDerivative.\n\n   # rule for covariant derivative of v^{a}\n\n   deriv := \\nabla_{a}{v^{b}} -> \\partial_{a}{v^{b}} + \\Gamma^{b}_{c a} v^{c}.\n\n   # create an expression\n\n   foo := \\nabla_{a}{v^{b}}.                     # cdb (ex-02.101,foo)\n\n   # apply the rule, then simplify\n\n   substitute   (foo,deriv)                      # cdb (ex-02.102,foo)\n   canonicalise (foo)                            # cdb (ex-02.103,foo)\n\n   checkpoint.append (foo)\n\\end{cadabra}\n\n\\begin{align}\n   \\cdb{ex-02.101} &= \\Cdb{ex-02.102}\\\\\n                   &= \\Cdb{ex-02.103}\n\\end{align}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 2 Covariant derivatives using ``position=independent''}\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   # rule for covariant derivative of v^{a}\n\n   deriv := \\nabla_{a}{v^{b}} -> \\partial_{a}{v^{b}} + \\Gamma^{b}_{c a} v^{c}.\n\n   # create an expression\n\n   foo := \\nabla_{a}{v^{b}}.                     # cdb (ex-02.201,foo)\n\n   # apply the rule, then simplify\n\n   substitute   (foo,deriv)                      # cdb (ex-02.202,foo)\n   canonicalise (foo)                            # cdb (ex-02.203,foo)\n\n   checkpoint.append (foo)\n\\end{cadabra}\n\n\\begin{align}\n   \\cdb{ex-02.201} &= \\Cdb{ex-02.202}\\\\\n                   &= \\Cdb{ex-02.203}\n\\end{align}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 2 Covariant derivatives using generic rule for deriv}\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   deriv := \\nabla_{a}{A?^{b}} -> \\partial_{a}{A?^{b}} + \\Gamma^{b}_{c a} A?^{c}.\n\n   # create an expression\n\n   foo := \\nabla_{a}{u^{b}} + \\nabla_{a}{v^{b}}. # cdb (ex-02.301,foo)\n\n   # apply the rule, then simplify\n\n   substitute   (foo,deriv)                      # cdb (ex-02.302,foo)\n   canonicalise (foo)                            # cdb (ex-02.303,foo)\n\n   checkpoint.append (foo)\n\\end{cadabra}\n\n\\begin{align}\n   \\cdb{ex-02.301} &= \\Cdb{ex-02.302}\\\\\n                   &= \\Cdb{ex-02.303}\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": "a39bc9c2f2227fa2283424fe5070e68127fc5d7c", "size": 3367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-02.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-02.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-02.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.1007751938, "max_line_length": 94, "alphanum_fraction": 0.4995544996, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.6695955785059816}}
{"text": "% !TEX root = BusSim.tex\n\\section*{Appendix A: The BusSim model \\label{appendix:BusSim}}\n\nFigure 2 illustrates the workflow for BusSim-truth. At each current time step $t$, each Bus agent checks whether the next time step would be larger than the vehicle's scheduled dispatch time $\\delta_j$. If $t>\\delta_j$, we then check whether the bus is on the road (Status equals $MOVING$), or at a stop for passenger dwelling (Status equals $DWELLING$), or has finished its service (Status equals $FINISHED$), otherwise the bus remains $IDLE$. \n\nIf the status is $MOVING$, we first check whether the bus is at a bus stop, by comparing the $GeoFence$ area of each bus stop agent with the bus' location. If the bus is not approaching a bus stop, its current speed $v_j$ will be compared with the surrounding traffic speed $V$. If $v_j<V$, we assume that the bus will speed up with an acceleration rate $a_j$, thus we have: \n\\begin{equation}\nv_j^{t} = v_j^{t-dt} + a_j \\cdot dt\n\\end{equation}\n\nTherefore for the next time step, the bus will cover a distance of: \n\\begin{equation}\nS_j^t = S_j^{t-dt} + v_j^t \\cdot dt\n\\end{equation}\n\nIf the speed already matches the traffic speed $V$, the bus will maintain the same speed. Or else if the bus is approaching a bus stop, the system will first check if the stop is the last stop. If it is the last stop, then the bus' status will be changed to $FINISHED$ and bus speed is changed to zero. If it is not the last stop, the system will change the status of agent Bus $j$ to $DWELLING$ and its speed to zero. The number of boarding and alighting passengers from the bus $j$, and the time that it will leave the stop are estimated as follows.  \n\nThe number of boarding passenger is proportional to the time gap between the current time (when Bus $j$ approaches the bus stop $m$) and the last time any bus visits the bus stop $m$:     \n\\begin{equation}\nB_{j,m} = \\nint{Po(Arr_m \\cdot (t^a_{j+1,m}-t^a_{j,m}) } \\quad | \\quad B_{j,m}\\in\\mathbb{N}\n\\label{eq:Boarding_est}\n\\end{equation}\n\nEquation \\ref{eq:Boarding_est} shows that the number of boarding passengers is estimated using a stochastic Poisson process. A Poisson process is widely adopted in literature to estimate the count of passengers waiting at a public transport stop \\citep{toledo2010mesoscopic,cats2010mesoscopic}. Extensions of this stochastic process have been introduced, such as non-homogeneous Poisson process \\citep{kieu2018stochastic}, where the arrival rate is time-dependent, but for simplicity we adopt a homogeneous Poisson process for this paper. Equation \\ref{eq:Boarding_est} makes the BusSim-truth model stochastic, because there is randomness in the way the Poisson process generates a number. For more details on the number generation process using stochastic Poisson process (e.g. thinning algorithm), interested readers may refer to \\citep{lewis1979simulation}. The number of boarding passengers is also limited by the available capacity of the bus:\n\\begin{equation}\nB_{j,m} = \\text{max} \\big( B_{j,m}, C - Occ_m )   \\big)\n\\label{eq:Boarding_limit}\n\\end{equation}\n\nThe number of alighting passengers is proportional to the number of passenger on board (bus occupancy) and the departure rate at the stop $m$.  For simplicity, we assume that $A_{j,m}$ is the product between the departure rate from bus stop $m$ and the current bus occupancy (the number of passenger on board leaving the last stop): \n\\begin{equation}\nA_{j,m} = \\nint{Dep_m \\cdot Occ_{j,m-1}} \\quad | \\quad A_{j,m}\\in\\mathbb{N}\n\\end{equation}\n\nTo estimate the amount of time that bus will have to stay at the bus stop $m$ for passenger boarding and alighting, a.k.a. \\textit{dwell time} $D_{j,m}$, we adopt the approach in \\citep{bertini2004modeling} and the Transit Capacity and Quality of Service Manual (TCQSM) \\citep{kfh2013transit}:\n\\begin{equation}\nD_{j,m} = \\theta_1 + \\theta_2 \\times B_{j,m} + \\theta_3 \\times A_{j,m} \n\\label{eq:dwell_time}\n\\end{equation}\nThe parameter set [$\\theta_1,\\theta_2,\\theta_3$] represents the time spent for passenger boarding, alighting, and a fixed value for vehicle stopping and starting, respectively. Equation \\ref{eq:dwell_time} is the formulation for a single-door bus system, where boarding and alighting occurs sequentially. \n\nThe departure time of bus $j$ from stop $m$ is calculated from the arrival time $t^a_{j,m}$ plus the time spent at stops for passenger boarding and alighting, or in other words the dwell time $D_m$:\n\\begin{equation}\nt^d_{j,m} = t^a_{j,m} + D_{j,m}\n\\end{equation}\nIn BusSim, the bus $j$ is only allowed to leave the bus $m$ at time $t^d_{j,m}$, so this is also called the $Leave\\_stop\\_time$, as can be seen in the Figure 2. \n\nIf the status of bus $j$ is $DWELLING$, it is at a stop for passenger boarding and alighting. We then check if the next time step would be larger or equal to the leave stop time $t^d_{j,m}$. If it would, then the bus would start accelerate to leave the stop, otherwise it would stay for at least another time interval. Finally, if the status of the bus is $FINISHED$, then we would do nothing. The modelling process then moves to the next Bus agent until the last Bus, then the whole model moves to the next time step until the last time step. \n\nBusSim-truth also assumes that parameters dynamically change over time by introducing an additional parameter $\\xi$ to represent the change in passenger demand or surrounding traffic speed. For simplicity, we assume that a single, deterministic parameter $\\xi$ can model these dynamic changes. In practice, it is possible, and more desirable, to use a time-dependent value of $\\xi$ such that dynamic change is better captured, and multiple $\\xi$ to model different changes. $\\xi>0$ represents an increase in passenger demand and traffic speed, and $\\xi<0$ represents otherwise. In this paper, the change in passenger demand or traffic speed is modelled as: \n\\begin{align}\nV = V \\cdot \\big( 1 - \\frac{t}{T} \\cdot \\frac{100}{\\xi} \\big) \\\\\nArr_m = Arr_m \\cdot (1 - \\frac{t}{T} \\cdot \\frac{100}{\\xi}\n\\label{eq:dynamic_bussim}\n\\end{align}\nA positive value of $\\xi$ in Equation \\ref{eq:dynamic_bussim} gradually reduces the surrounding traffic speed $V$ and increases the arrival rate $Arr_m$, which would lead to more bus delays and congestion. \n", "meta": {"hexsha": "952839790797d60ef797c88ba87685b2f8d5334e", "size": 6260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/2019-BusSim-ParticleFilter-MK/AppendixA.tex", "max_stars_repo_name": "RobertClay/DUST-RC", "max_stars_repo_head_hexsha": "09f7ec9d8d093021d068dff8a7a48c15ea318b86", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2018-11-21T14:57:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T15:42:09.000Z", "max_issues_repo_path": "Writing/2019-BusSim-ParticleFilter-MK/AppendixA.tex", "max_issues_repo_name": "RobertClay/DUST-RC", "max_issues_repo_head_hexsha": "09f7ec9d8d093021d068dff8a7a48c15ea318b86", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 125, "max_issues_repo_issues_event_min_datetime": "2019-11-06T13:03:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-07T13:38:33.000Z", "max_forks_repo_path": "Writing/2019-BusSim-ParticleFilter-MK/AppendixA.tex", "max_forks_repo_name": "RobertClay/DUST-RC", "max_forks_repo_head_hexsha": "09f7ec9d8d093021d068dff8a7a48c15ea318b86", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-11-20T15:56:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T10:21:06.000Z", "avg_line_length": 109.8245614035, "max_line_length": 948, "alphanum_fraction": 0.7579872204, "num_tokens": 1671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6695124430634901}}
{"text": "% !TEX root = Main.tex\n\\section{Non-Negative Matrix Factorization}\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)$\n\n\\subsection*{EM for pLSA}\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):\\\\\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}}$\\\\\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$. pLSA fixes both dimensions.\\\\\nDirichlet distribution: $p(u_i|\\alpha) = \\prod_{z=1}^K u_{zi}^{\\alpha_k-1}$\\\\\nLDA model: $p(x|V,u) = \\frac{l!}{\\prod_j x_j!}\\prod_j \\pi_j^{x_j}$\\\\\nwhere $\\pi_j=\\sum_z v_{zj} u_z$, $l=\\sum_j x_j$\n\n\\subsection*{NMF Algorithm for quadratic cost function}\n$\\mathbf{X} \\in \\mathbb{Z}^{N \\times M}_{\\geq 0}$, NMF: $\\mathbf{X} \\approx \\mathbf{U^\\top V}, x_{ij}$\n\n$\\min_{\\mathbf{U}, \\mathbf{V}} J(\\mathbf{U}, \\mathbf{V}) = \\frac{1}{2} \\|\\mathbf{X} - \\mathbf{U}^\\top\\mathbf{V}\\|_F^2$\\\\\ns.t. $\\forall i,j,z:u_{zi},v_{zj} \\geq 0 $\n\n\n1. init: $\\mathbf{U}, \\mathbf{V} = rand()$ 2. repeat 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": "fcba1aa2c7b1e0c17ed01475c6b01f8a2008828d", "size": 1848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NMF.tex", "max_stars_repo_name": "hlynurf/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "41b60db531665c3c33fe2103d942cfe8653bb2d4", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-07-31T11:12:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-02T09:35:54.000Z", "max_issues_repo_path": "NMF.tex", "max_issues_repo_name": "hlynurf/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "41b60db531665c3c33fe2103d942cfe8653bb2d4", "max_issues_repo_licenses": ["CC0-1.0"], "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": "hlynurf/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "41b60db531665c3c33fe2103d942cfe8653bb2d4", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-07-19T14:14:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-05T13:50:06.000Z", "avg_line_length": 54.3529411765, "max_line_length": 122, "alphanum_fraction": 0.5811688312, "num_tokens": 882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6693181639532216}}
{"text": "\\documentclass[11pt]{article}\n\n\\input{preamble}\n\n\\title{Week 2: Gradients}\n\\author{\\url{http://mlvu.github.io}}\n\n\\begin{document}\n\n\\maketitle\n\n\\noindent In this session we will practice searching for a good or optimal model using the \\emph{gradient}. We will define the \\emph{loss function} of a model, with respect to some target data, and we will will minimize the loss function with respect to the parameters.\n\nIn the following explanation, some parts are replaced by green dots. Fill these in.\n\n\\section{Partial derivatives}\n\nWe'll begin by reviewing the idea of \\emph{partial derivatives}: derivatives of functions with multiple inputs. If you haven't worked with derivatives for a while (or ever), start by having a look at the following resources:\n\\begin{itemize}\n\\item \\url{https://www.youtube.com/watch?v=ANyVpMS3HL4}\n\\item \\url{https://www.youtube.com/watch?v=hCLfogkqzEk}\n\\item \\url{http://betterexplained.com/articles/derivatives-product-power-chain/}\n\\end{itemize}\n\n\\noindent A partial derivative is the derivative with respect to one of the parameters, treating all the others as constants. For a simple example, consider the function\n\\[\n f(\\rc{a},\\bc{b})= 3\\rc{a}^2 + \\bc{b}^2 - \\rc{a}\\bc{b} + \\rc{a}.\n\\]\n\\noindent\nWe first take the derivative with respect to \\rc{a}:\n\\[\n\t\\frac{\\kp f(\\rc{a},\\bc{b})}{\\kp \\rc{a}} = \\frac{\\kp(3\\rc{a}^2 + \\bc{b}^2 - \\rc{a}\\bc{b} + \\rc{a})}{\\kp \\rc{a}} = 6\\rc{a} -\\bc{b} + 1 \\p\n\\]\nNote that the second term of the function ($\\bc{b}^2$) does not contain $\\rc{a}$, i.e. it is constant with respect to $\\rc{a}$, so it disappears from the derivative.\n\n\\noindent Then, we take the derivative wrt. to \\bc{b}:\n\\[\n\\frac{\\kp f(\\rc{a},\\bc{b})}{\\kp \\bc{b}} = \\frac{\\kp(3\\rc{a}^2 + \\bc{b}^2 - \\rc{a}\\bc{b} + \\rc{a})}{\\kp \\bc{b}} = 2\\bc{b} - \\rc{a} \\p\n\\]\nThe \\emph{gradient} $\\nabla f(\\rc{a},\\bc{b})$ is simply all the partial derivatives of a function arranged in a (row) vector:\n\\[\n\\nabla f(\\rc{a},\\bc{b}) = \\left ( \\frac{\\kp f(\\rc{a},\\bc{b})}{\\kp \\rc{a}},\\;\\;\\frac{\\kp f(\\rc{a},\\bc{b})}{\\kp \\bc{b}}\\right) = \\left(6\\rc{a} - \\bc{b} + 1, \\;\\;2\\bc{b} - \\rc{a}\\right) \\p\n\\]\n\n\\noindent If we imagine the function f as a ``landscape'' over the plane defined by the $\\rc{a}$ and $\\bc{b}$-axes, the gradient at each point in that plane, is an arrow pointing in the direction in which the ascent is the steepest.\\footnotemark~A marble placed at some point, and released, would roll in the opposite direction to the gradient.\n\n\\footnotetext{We can interpret a vector $\\x \\in R^n$ as a point in $R^n$, but also as a \\emph{direction}. The direction is that of the arrow between the origin and the point $\\x$. The gradient only makes sense as a direction.}\n\nTo find the point at which the function has reached its minimum, we must find out where all partial derivatives are equal to zero.\\footnotemark\n\\footnotetext{To be precise, if all partial derivatives are zero, the function may be at a minimum, a maximum, or a plateau. It may even be a saddle-point, a place where the function is a minimum in one dimension and a maximum in another. For the purposes of this exercise, you may assume that if the gradient is zero, you have found a minimum.}\n\n\\qu To find the \\rc{a} and \\bc{b} for which f(\\rc{a}, \\bc{b}) is minimal, we set the partial derivatives to zero. Fill in the blanks (indicated by ``\\ldots'') in this derivation:\n\\begin{align*}\n6\\rc{a} - \\bc{b} + 1 &= 0 & 2\\bc{b}-\\rc{a} &= 0 \\\\\n\\rc{a} &= (\\bc{b}-1)/6 & \\bc{b} &= \\rc{a}/2 \\\\\n & & \\bc{b} &= \\ans{\\frac{\\bc{b}-1}{6}\\frac{1}{2}}{\\dots}\\\\ \n & & \\ans{\\bc{b} - \\frac{\\bc{b}}{12}}{\\ldots}&= \\ans{- \\frac{1}{12}}{\\ldots}\\\\\n  & & \\bc{b} &= -\\frac{1}{11}\\\\\n  \\rc{a} &= \\ans{\\frac{-\\frac{1}{11} - 1}{6}}{\\ldots}=-\\frac{2}{11} & & \\\\\n\\end{align*}\n\n\\noindent A quick check on \\href{http://wolfr.am/9DrZFKcR}{Wolfram Alpha} shows that this solution is correct.\n\n\\subsection{Rules}\n\nWhile it's important to understand intuitively what differentation means (see the \\emph{better explained} link above), actually finding a specific derivative is usually a very mechanical process of matching existing rules and rewriting a function to a useful form. The following rules are usually sufficient:\nLet $c$ be a constant, independent of $x$, and let $f(x)$ and $g(x)$ be arbitrary functions of $x$. Then:\n\n\\begin{align*}\n\t\\frac{\\kp c}{\\kp x}     &=0        & \\text{ the \\emph{constant} rule} \\\\\n\t\\frac{\\kp x^\\rc{n}}{\\kp x}   &=\\rc{n}x^{\\rc{n}-1} & \\text{the \\emph{exponent} rule} \\\\\n\t\\frac{\\kp x}{\\kp x}     &= 1       & \\text{(follows from the exponent rule)} \\\\\n\t\\frac{\\kp \\rc{c}f(x)}{\\kp x} &= \\rc{c}\\frac{\\kp f(x)}{\\kp x} & \\text{the \\emph{constant factor} rule} \\\\\n\t\\frac{\\kp \\kc{\\left ( \\bc{f(x)} + \\gc{g(x)}\\right )}}{\\kp x} &= \\frac{\\kp \\bc{f(x)}}{\\kp x} + \\frac{\\kp \\gc{g(x)}}{\\kp x} & \\text{the \\emph{sum} rule} \\\\\n\t\\frac{\\kp \\bc{f(\\gc{g(x)})} }{\\kp x} &= \\frac{\\kp \\bc{f(\\gc{g(x)})}}{\\kp \\gc{g(x)}}\\frac{\\kp \\gc{g(x)}}{\\kp x} & \\text{the \\emph{chain} rule} \\\\\n\\end{align*}\n\n\\noindent To find the derivative of $f(x, y, z)$ with respect to $y$, you write down \n\\[\n\\frac{\\kp f(x, y, z)}{\\kp y} \\text{,}\\]\nfill in the definition of $f$, and match the result (whole, or part of it) with the left-hand side of one of these rules. You replace it by the right-hand side and keep going until all the $\\kp$'s are gone.\n\n\\qu To practice, let's take the \tderivative of $(x + y + z)^2$ with respect to $y$. Fill in the blanks.\n\n\\begin{align*}\n\\frac{\\kp \\bc{(\\gc{x + y + z})^2}}{\\kp y} &= \\frac{\\kp \\bc{(\\gc{x + y + z})^2}}{\\kp \\kc{(\\gc{x + y + z})}}\\frac{\\kp \\kc{(\\gc{x + y + z})}}{\\kp y} & \\text{using the \\ans{chain}{\\ldots} rule} \\\\\n &= 2(x + y + z)\\frac{\\kp \\kc{(x + y + z)}}{\\kp \\kc{y}} & \\text{using the \\ans{exponent}{\\ldots} rule} \\\\\n &= \\kc{2(x + y + z)}\\left (\\frac{\\kp x}{\\kp y} + \\frac{\\kp y}{\\kp y} + \\frac{\\kp z}{\\kp y} \\right) & \\text{using the \\ans{sum}{\\ldots} rule} \\\\\n  &= \\kc{2(x + y + z)}(0 + 1 + 0) & \\text{using the \\ans{constant}{\\ldots} and \\ans{exponent}{\\ldots} rules} \\\\\n  &=  2(x + y + z) & \\\\\n\\end{align*}\n\n\\section{Linear regression}\n\nAs discussed in the lecture, the optimal model for standard linear regression can be computed directly. In this assignment we will derive this function. Let’s say we are trying to predict the size to which a particular newborn baby will grow in the coming months. We have measured the child in its first few months and found the following data:\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{l | l}\n\tage($a$, months) & height ($h$, cm) \\\\\n\t\\hline\n\t$a_1 = 0$ & $h_1 = 30$ \\\\\n\t$a_2 = 2$ & $h_2 = 40$ \\\\\n\t$a_3 = 4$ & $h_3 = 50$ \n\\end{tabular}\n\\end{table}\n\n\n\\noindent Let $n$ be the number of examples we have (3 in this case, but we want to derive a solution for arbitrary $n$). Our model, $f$, is a linear function, described by two parameters: the slope $s$ and the intercept $b$:\n\\[\nf_{s, b}(a) = sa + b\n\\]\n\n\\noindent Where $f(a_i)$ should be as close to $h_i$ as possible. We will use the sum of squared errors as our loss function. That is, we will compute the residual $f(a_i) - h_i$ for each data point, square them, and sum these squared values. In other words, our loss function is\n\\[\n\\text{loss}(s, b) = \\frac{1}{2}\\sum_i\\left ( \\rc{f_{s, b}(a_i)} - h_i\\right )^2 = \\frac{1}{2}\\sum_i\\left ( \\rc{sa_i + b} - h_i\\right )^2\n\\]\n\n\\noindent The $\\frac{1}{2}$ multiplier is there to simplify the derivatives later. It doesn't affect the minimum of the loss function, which is what we're after.\\footnotemark\n\n\\footnotetext{In the slides, we used the \\emph{mean} sum of squared errors (i.e. we multiplied by $\\frac{1}{n}$ as well). Since $n$ is a constant, the two functions have the same minimum and we can use either one.}\n\n\\qu For $s=1$ and $b=0$, and the data given above, what is the loss?\n\\ans{\n\\begin{align*}\n\t\\text{loss}(1, 0) &= \\frac{1}{2}\\sum_i\\left ( \\rc{1 \\times a_i + 0} - h_i\\right )^2 \\\\\n\t&= \\frac{1}{2}\\left ((0 - 30)^2 + (2 - 40)^2 + (4 - 50)^2 \\right) \\\\\n\t&= \\frac{1}{2}\\left (900 + 1444 + 2116 \\right) = 2230\\\\\n\\end{align*}\n}{}\n\n\\qu The term $f(a_i) - h_i$ represents the difference between our model's prediction and the observed value (the \\emph{residual}). Per example, this is a good measure of the error. Why do we not just sum these, and check how far it is from 0? Why square it first, and \\emph{then} sum?\n\n\\ans{\nIf we summed them, one big positive error could cancel out against one big negative error, giving the false impression that the model is highly accurate. We need to square the errors before summing them. The choice for square instead of another approach (like taking the absolute value, or raising to some other power) is more subtle. Squaring emphasizes the loss of large errors compared to the absolute value.\n\nIt turns out that if we assume that the data is linear, but with added Gaussian noise, optimizing for the sum-of-squared errors is equivalent to optimizing likelihood (we will discuss this later in the probability lectures.)\n}{}\n\n\\qu Let's find the derivative of the loss function. One with respect to $s$ and one with respect to $b$. Fill in the blanks.\n\n\\begin{align*}\n\\frac{\\kp\\text{loss}(s, b)}{\\kp s} & = \\frac{\\kp \\frac{1}{2} \\sum_i\\left (s a_i + b - h_i \\right) ^2}{\\kp s} \\\\\n&= \\frac{1}{2} \\sum_i \\frac{\\kp \\left (sa_i + b -h\\right )^ 2}{\\kp (sa_i + b -h_i)}\\frac{\\kp (sa_i + b -h_i)}{\\kp s}\\\\\n&= \\ans{\\frac{1}{2}\\sum_i 2(a_is + b - h_i)a_i}{\\ldots} \\\\\t\n&= \\sum_i (a_is + b - h_i)a_i \\\\\t\n&= \\sum_i ({a_i}^2s + a_ib - a_ih_i) \\\\\t\n&= s \\sum_i {a_i}^2 + b \\sum_ia_i - \\sum_i a_i h_i \\\\\t\n\\end{align*}\n\n\\begin{align*}\n\\frac{\\kp\\text{loss}(s, b)}{\\kp b} & = \\ans{\\frac{\\kp \\frac{1}{2} \\sum_i\\left (s a_i + b - h_i \\right) ^2}{\\kp b}}{\\dots} \\\\\n&= \\ans{\\frac{1}{2} \\sum_i \\frac{\\kp \\left (sa_i + b -h_i\\right )^ 2}{\\kp (sa_i + b -h_i)}\\frac{\\kp (sa_i + b -h_i)}{\\kp b}}{\\ldots}\\\\\n&= \\ans{\\frac{1}{2}\\sum_i 2(a_is + b - h_i)}{\\ldots} \\\\\t\n&= \\sum_i (a_is + b - h_i) \\\\\t\n&= s \\sum_i {a_i} + bn - \\sum_i h_i \\\\\t\n\\end{align*}\n\n\\qu For many loss functions, setting the gradients equal to zero results in a system of equations that cannot be solved analytically. In that case we will have to \\emph{search}. We can still use the gradient though, in an algorithm called \\emph{gradient descent}. Starting with the parameter values $s=1$ and $b=0$, describe one step of the gradient descent algorithm (with learning rate 0.01).\n\\ans{\nFor these parameters, the gradient is \n\\begin{align*}\n&\\left (\\rc{s \\sum_i {a_i}^2 + b \\sum_i a_i - \\sum_i a_i h_i }, \\;\\; \\bc{s \\sum_i a_i + bn - \\sum_i h_i} \\right) \\\\\n&\\;= \\left(\\rc{\\sum_i {a_i}^2 - \\sum_i a_i h_i},\\;\\; \\bc{\\sum_i {a_i} - \\sum_i h_i} \\right) \\\\\n&\\;= \\left( \\rc{4 + 16 - (2\\cdot 40 + 4\\cdot 50)},\\;\\; \\bc{6 - 120}\\right) \\\\\n&\\;= \\left( \\rc{-260},\\;\\; \\bc{-114}\\right) \\\\\n\\end{align*}\nFor gradient descent we pick the opposite direction (since the gradient points up), multiply by the learning rate, and add the result to the current parameters. Thus, the new parameters are:\n\\begin{align*}\n\\begin{bmatrix}s^\\text{new} \\\\b^\\text{new}\\end{bmatrix} &= \\begin{bmatrix}s \\\\b\\end{bmatrix} - \\eta \\nabla \\text{loss}(s, b)\\\\\n&= \\begin{bmatrix}1 \\\\0\\end{bmatrix} - 0.01 \\begin{bmatrix}\\rc{-260} \\\\\\bc{-114}\\end{bmatrix} = \\begin{bmatrix}3.6 \\\\ 1.14\\end{bmatrix}\\p\n\\end{align*} \n}{}\n\n\\qu Set the two derivatives found above equal to zero, and solve to obtain expressions for the optimal model. Make sure that your expression for $s$ does not depend on $b$, so that the solution can actually be computed. \nTo simplify notation, it can be helpful to use the following conventions for the data means and other statistics:\n\\begin{align*}\n\\overline{a} &= \\frac{1}{n}\\sum_i a_i\t\\\\\n\\overline{h} &= \\frac{1}{n}\\sum_i h_i\t\\\\\n\\overline{a^2} &= \\frac{1}{n}\\sum_i {a_i}^2\t\\\\\n\\overline{h^2} &= \\frac{1}{n}\\sum_i {h_i}^2\t\\\\\n\\overline{ah} &= \\frac{1}{n}\\sum_i a_ih_i\t\\\\\n\\end{align*}\n\n\\noindent Fill in the blanks:\n\n\\begin{align}\n\ts \\sum_i {a_i}^2 + b \\sum_ia_i - \\sum_i a_i h_i &= 0 \\notag\\\\\n\ts \\sum_i {a_i}^2 &= \\ans{- b \\sum_ia_i + \\sum_i a_i h_i}{\\dots} \\notag\\\\\n\ts &= - b \\frac{\\sum_i a_i}{\\sum_i{a_i}^2} + \\frac{\\sum_i a_i h_i}{\\sum_i{a_i}^2} \\notag \\\\\n\ts &= \\ans{- b \\frac{\\frac{1}{n}\\sum_i a_i}{\\frac{1}{n}\\sum_i{a_i}^2} + \\frac{\\frac{1}{n}\\sum_i a_i h_i}{\\frac{1}{n}\\sum_i{a_i}^2}}{\\ldots} \\notag\\\\\n\ts &= -b\\frac{\\overline{a}}{\\overline{a^2}} + \\frac{\\overline{ah}}{\\overline{a^2}} \\label{line:s}\n\\end{align}\n\n\\begin{align}\n\ts \\sum_i {a_i} + bn - \\sum_i h_i &=0 \\notag \\\\\n\tbn &= \\ans{\\sum_ih_i - s\\sum_i a_i}{\\ldots} \\notag\\\\\n\tb &= \\ans{\\frac{1}{n}\\sum_ih_i - s\\frac{1}{n}\\sum_i a_i}{\\ldots} \\notag\\\\\n\tb &= \\overline{h}-s\\overline{a} \\label{line:b}\n\\end{align}\nFill equation (\\ref{line:b}) into equation (\\ref{line:s}):\n\\begin{align*}\ns &= -\\left(\\ans{\\overline{h}-s\\overline{a}}{\\ldots}\\right)\\frac{\\overline{a}}{\\overline{a^2}} + \\frac{\\overline{ah}}{\\overline{a^2}} \\\\\ns &= - \\frac{\\overline{h}\\overline{a}}{\\overline{a^2}} + s \\frac{\\overline{a}^2}{\\overline{a^2}} + \\ans{\\frac{\\overline{ah}}{\\overline{a^2}}}{\\ldots} \\\\\n s \\left(1-\\frac{\\overline{a}^2}{\\overline{a^2}}\\right)&= \\ans{- \\frac{\\overline{h}\\overline{a}}{\\overline{a^2}} +\\frac{\\overline{ah}}{\\overline{a^2}}}{\\ldots} \\\\\n s &= \\frac{\\overline{ah} - \\overline{a}\\overline{h}}{\\overline{a^2} - \\overline{a}^2} \\\\\n\\end{align*}\n\\noindent Note that we have now expressed $s$ and $b$ purely in terms of statistics that are easily computed from our data, like the mean height $\\overline{h}$ and the mean age $\\overline{a}$.\n\n\\qu Fill in the values from the data set, and compute the optimal parameters for this data. Can you explain what the parameters $s$ and $b$ mean? That is, what can they tell us about the baby we've measured?\n\\ans{Filling in the data gives us $\\overline{ah} = \\frac{280}{3}$, $\\overline{a} = 2$, $\\overline{h} = 40$, $\\overline{a^2} = \\frac{20}{3}$. This gives us\n\\begin{align}\ns = \\frac{\\frac{280}{3} - 2\\cdot 40}{\\frac{20}{3} - 4} = \\frac{\\frac{40}{3}}{\\frac{8}{3}} = 5 \\\\\nb = 40 - 5 \\cdot 2 = 30\n\\end{align}\nThis tells us that this baby grows about 5 cm per month, and its size at birth was 30 cm. (Note these values were made up, and are actually a little small for a newborn baby.)}{}\nSee if \\href{https://goo.gl/dEcRBG}{Wolfram Alpha} agrees with your answer.\n\n\\end{document}", "meta": {"hexsha": "52e0caae52c223e448f45760a448930b18f79841", "size": 14172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week2.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": "week2.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": "week2.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": 64.7123287671, "max_line_length": 411, "alphanum_fraction": 0.6508608524, "num_tokens": 5089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6693044883287759}}
{"text": "\\chapter{Transient and Steady-State Analysis of the LMS Adaptive Filter}\n\\label{app:lms_analysis}\nIn this appendix, we give a more detailed transient and steady-state analysis of the LMS adaptive filter than found in Lecture~\\ref{ch:SD_LMS}. Specifically, we derive the condition for mean-square convergence and the expressions for the learning curve, the excess mean-square error (EMSE), the mean-square deviation (MSD), and the misadjustment. We do this for two reasons. Firstly, it is instructive to see how the analysis is carried out, and, secondly, it highlights how difficult the analysis is - even of the simple LMS adaptive filter. \n\nIn the derivation below, we use the analysis model previously discussed in Sec.~\\ref{ssec:analysis_model}. We also need the following important result.\n\n\\section{A Special Fourth Order Moment of a Gaussian Random Vector}\nLet $\\vect{u}$ be a real-valued $M\\times 1$ dimensional Gaussian random vector with zero-mean and correlation matrix $\\vect{R}_u$. Moreover, let $\\vect{W}$ be an $M\\times M$ symmetric matrix. We then have that \\cite[p.~44]{Sayed2003}\n\\bmath\n  E[\\vect{uu}^T\\vect{Wuu}^T] = \\vect{R}_u\\tr{\\vect{WR}_u}+2\\vect{R}_u\\vect{WR}_u\\ .\n\\emath\nIf $\\vect{R}_u = \\vect{X\\Lambda X}^T$ is the eigenvalue decomposition of the correlation matrix and if we define $\\vect{F}=\\vect{X}^T\\vect{WX}$, we may write\n\\bmath\n  E[\\vect{uu}^T\\vect{Wuu}^T] = \\vect{X}[\\vect{\\Lambda}\\tr{\\vect{F\\Lambda}}+2\\vect{\\Lambda F\\Lambda}]\\vect{X}^T\\ .\n\\emath\nWith this result in mind, we can now evaluate the following expectation\n\\begin{align}\n  E[(\\vect{I}-\\mu\\vect{u}\\vect{u}^T)\\vect{W}(\\vect{I}-\\mu\\vect{u}\\vect{u}^T)]&= \\vect{W}+\\mu^2E[\\vect{uu}^T\\vect{Wuu}^T]-\\mu\\vect{R}_u\\vect{W}-\\mu\\vect{W}\\vect{R}_u\\\\\n  &= \\vect{W} + \\mu^2\\vect{R}_u\\tr{\\vect{WR}_u}+2\\mu^2\\vect{R}_u\\vect{WR}_u -\\mu\\vect{R}_u\\vect{W}-\\mu\\vect{W}\\vect{R}_u\\\\\n  &= \\vect{X}[\\vect{F} - \\mu(\\vect{\\Lambda F}+\\vect{F\\Lambda}) + \\mu^2(\\vect{\\Lambda}\\tr{\\vect{F\\Lambda}} + 2\\vect{\\Lambda F\\Lambda})]\\vect{X}^T\\ .\n\\end{align}\nIf $\\vect{F}$ is diagonal, then $\\vect{F\\Lambda}=\\vect{\\Lambda F}$ and we have that\n\\bmath\n\tE[(\\vect{I}-\\mu\\vect{u}\\vect{u}^T)\\vect{W}(\\vect{I}-\\mu\\vect{u}\\vect{u}^T)] = \\vect{X}[\\vect{F} - 2\\mu\\vect{\\Lambda F} + \\mu^2(\\vect{\\Lambda}\\tr{\\vect{F\\Lambda}} + 2\\vect{\\Lambda}^2 \\vect{F})]\\vect{X}^T\\ .\n\t  \\label{eq:app_lms_4mom}\n\\emath\nThis result is very important for the derivation below.\n\n\\section{The Analysis Model}\nThe LMS algorithm is given by\n\\bmath\n  \\vect{w}(n+1) = \\vect{w}(n) + \\mu\\vect{u}(n)e(n)\n\\emath\nwhere $\\vect{w}(n)$, $\\vect{u}(n)$, and $e(n)$ are the filter vector, the input vector and the error, respectively, at time index $n$. The positive scalar $\\mu$ is the step-size, and the error is given by\n\\bmath\n  e(n) = d(n) - \\vect{u}^T(n)\\vect{w}(n)\n\\emath\nwhere the desired signal $d(n)$ in the analysis model (see also Sec.~\\ref{ssec:analysis_model}) is given by\n\\bmath\n  d(n) = v(n) + \\vect{u}^T(n)\\vect{w}_o\\ .\n\\emath\nWe assume that $v(n)$ is white Gaussian noise with variance $\\sigma_v^2$ and uncorrelated with the input signal $u(n)$. Finally, we assume that $\\vect{u}(n)$ is a white Gaussian process with correlation matrix $\\vect{R}_u$. This implies that $\\vect{u}(n)$ and $\\vect{w}(n)$ are uncorrelated.\n\nThe difference between the optimal filter vector $\\vect{w}_o$ and the filter vector $\\vect{w}(n)$ is called the weight error, and it is given by\n\\begin{align}\n  \\vect{\\Delta}\\vect{w}(n) &= \\vect{w}_o-\\vect{w}(n) = \\vect{w}_o - \\vect{w}(n-1) - \\mu\\vect{u}(n-1)e(n-1)\\\\\n  &= \\vect{\\Delta}\\vect{w}(n-1) - \\mu \\vect{u}(n-1)[v(n)+\\vect{u}^T(n-1)\\vect{w}_o-\\vect{u}^T(n-1)\\vect{w}(n-1)]\\\\\n  &= [\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)]\\vect{\\Delta}\\vect{w}(n-1)-\\mu\\vect{u}(n-1)v(n)\\ .\n \\label{app:lms_weight_error}\n\\end{align}\nIn terms of the weight error, the error is given by\n\\bmath\n  e(n) = d(n) - \\vect{u}^T(n)\\vect{w}(n) = v(n)+\\vect{u}^T(n)\\vect{\\Delta}\\vect{w}(n)\\ ,\n\\emath\nand the minimum mean-squared error (MMSE) is achieved at the optimum where $\\vect{\\Delta}\\vect{w}(n)=\\vect{0}$ and thus given by\n\\bmath\n  J_\\textup{min} = J_1(\\vect{w}_o) = E[v^2(n)] = \\sigma_v^2\\ .\n\\emath\n\n\\section{Transient Analysis}\nIn the transient analysis, we first consider how we should select the step-size $\\mu$ in order to ensure the mean-square stability of the LMS algorithm. Second, we derive an expression for the learning curve.\n\n\\subsection{Mean-Square Convergence}\nAs already discussed in Lecture~\\ref{ch:SD_LMS}, we say that the LMS algorithm converges in the mean-square if\n\\bmath\n  \\lim_{n\\to\\infty} E[\\|\\vect{\\Delta w}(n)\\|^2] = c <\\infty\\ .\n\\emath\nIn this section, we show that the LMS algorithm converges in the mean square if the step-size $\\mu$ is selected such that it satisfies\n\\bmath\n  f(\\mu) = \\frac{\\mu}{2}\\sum_{m=1}^M \\frac{\\lambda_m}{1-\\mu\\lambda_m} < 1\n\\emath\nwhere $\\lambda_m$ is the $m$'th eigenvalue of the correlation matrix $\\vect{R}_u$. \n\nIn order to do this, we investigate $E[\\|\\vect{\\Delta w}(n)\\|^2]$ as $n$ grows. For convenience of notation, it turns out to be easier to work with $E[\\|\\vect{c}(n)\\|^2]$ where $\\vect{c}(n)= \\vect{X}^T\\vect{\\Delta}\\vect{w}(n)$ and $\\vect{X}$ contains the $M$ eigenvectors of $\\vect{R}_u$. Since $\\vect{X}$ is orthogonal, it follows that\n\\bmath\n  E[\\|\\vect{c}(n)\\|^2] = E[\\|\\vect{X}^T\\vect{\\Delta w}(n)\\|^2] = E[\\|\\vect{\\Delta w}(n)\\|^2]\n\\emath\nThus, $E[\\|\\vect{c}(n)\\|^2]$ converges in the same way as $E[\\|\\vect{\\Delta w}(n)\\|^2]$ does. In the derivation below, we express $E[\\|\\vect{c}(n)\\|^2]$ as a function of $\\vect{c}(0)$, $\\mu$, $\\vect{\\Lambda}$, and $J_\\textup{min}$. We do this in a recursive manner starting by expressing $E[\\|\\vect{c}(n)\\|^2]$ as a function of $\\vect{c}(n-1)$, $\\mu$, $\\vect{\\Lambda}$, and $J_\\textup{min}$. Once we have obtained an expression for this recursion, we express $E[\\|\\vect{c}(n)\\|^2]$ as a function of $\\vect{c}(n-2)$, $\\mu$, $\\vect{\\Lambda}$, and $J_\\textup{min}$ in the next recursion and so on.\n\n\\subsubsection{The First Recursion}\nMultiplying \\eq{app:lms_weight_error} from the left with $\\vect{X}^T$ and inserting it into $E[\\|\\vect{c}(n)\\|^2]$ yields\n\\begin{align}\n  E[\\|\\vect{c}(n)\\|^2] ={}& E[\\|\\vect{X}^T[\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)]\\vect{X}\\vect{c}(n-1)-\\mu\\vect{X}^T\\vect{u}(n-1)v(n)\\|^2]\\\\\n   ={}& E[\\vect{c}^T(n-1)\\vect{X}^T[\\vect{I}-\\mu \\vect{u}(n-1)\\vect{u}^T(n-1)]^2\\vect{X}\\vect{c}(n-1)]\\notag\\\\\n   &{}+\\mu^2E[v^2(n)\\vect{u}^T(n-1)\\vect{u}(n-1)]\n   \\label{eq:app_lms_first_recur_start}\n\\end{align}\nwhere the last equality follows from the assumption that $v(n)$ and $\\vect{u}(n)$ are uncorrelated.\nThe expectation of the last term is given by\n\\begin{align}\n E[v^2(n)\\vect{u}^T(n-1)\\vect{u}(n-1)] &= E[v^2(n)]E[\\vect{u}^T(n-1)\\vect{u}(n-1)]\\\\\n &= J_\\textup{min} E[\\tr{\\vect{u}^T(n-1)\\vect{u}(n-1)}]\\\\\n &= J_\\textup{min} E[\\tr{\\vect{u}(n-1)\\vect{u}^T(n-1)}]\\\\\n &= J_\\textup{min} \\tr{E[\\vect{u}(n-1)\\vect{u}^T(n-1)]}\\\\\n &= J_\\textup{min} \\tr{\\vect{R}_u}\\\\\n &= J_\\textup{min} \\tr{\\vect{\\Lambda}}\\ .\n\\end{align}\nThe second equality follows since the trace of a scalar equals the value of the scaler. The third equality follows from a property of the trace operator given by\n\\bmath\n  \\tr{\\vect{AB}} = \\tr{\\vect{BA}}\n\\emath\nfor any pair of matrices $\\vect{A}$ and $\\vect{B}$ with $\\vect{A}$ and $\\vect{B}^T$ being of the same dimension. The fourth equality follows since both the expectation and the trace operators are linear operators whose order can therefore be interchanged. Finally, the last equality follows since\n\\bmath\n  \\tr{\\vect{R}_u} = \\tr{\\vect{X\\Lambda X}^T} = \\tr{\\vect{\\Lambda X}^T\\vect{X}} = \\tr{\\vect{\\Lambda}}\\ .\n\\emath\nThis was previously stated in the beginning of Lecture~\\ref{ch:SD_LMS}.\n\nIn order to evaluate the expectation of the first term in \\eq{eq:app_lms_first_recur_start}, we use the law of iterated expectations given by\\footnote{It follows since\n\\begin{align*}\n  E[E[X|Y]] &= \\int E[X|Y]f_Y(y)dy = \\int \\left[\\int x f_{X|Y}(x|y)dx\\right]f_Y(y)dy = \\int\\int x f_{X,Y}(x,y)dxdy\\\\\n  &= \\int x \\left[\\int f_{X,Y}(x,y)dy\\right]dx = \\int x f_X(x)dx = E[X]\\ .\n\\end{align*}}\n\\bmath\n  E[X] = E[E[X|Y]]\\ ,\n\\emath\nand the assumption that $\\vect{u}(n)$ and $\\vect{w}(n)$ are uncorrelated. From this, we obtain that\n\\begin{align}\n   E[\\vect{c}^T(n-1)\\vect{X}^T[\\vect{I}-\\mu &\\vect{u}(n-1)\\vect{u}^T(n-1)]^2\\vect{X}\\vect{c}(n-1)] = \\notag\\\\\n   &E[\\vect{c}^T(n-1)\\vect{X}^TE[(\\vect{I}-\\mu \\vect{u}(n-1)\\vect{u}^T(n-1))^2]\\vect{X}\\vect{c}(n-1)]\\ .\n\\end{align}\nThe inner expectation is on the same form as \\eq{eq:app_lms_4mom} with $\\vect{W}=\\vect{F}=\\vect{I}$. Thus, we have that\n\\begin{align}\n  \\vect{S}(1) &= \\vect{X}^TE[(\\vect{I}-\\mu \\vect{u}(n-1)\\vect{u}^T(n-1))^2]\\vect{X}\\\\\n  &= \\vect{I}-2\\mu\\vect{\\Lambda}+\\mu^2[\\vect{\\Lambda}\\tr{\\vect{\\Lambda}}+2\\vect{\\Lambda}^2]\\ .\n\\end{align}\nwhich is a diagonal matrix. Thus, we can write \\eq{eq:app_lms_first_recur_start} as\n\\bmath\n  E[\\|\\vect{c}(n)\\|^2] = E[\\vect{c}^T(n-1)\\vect{S}(1)\\vect{c}(n-1)]+\\mu^2J_\\textup{min}\\tr{\\vect{\\Lambda}}\\ .\n  \\label{eq:app_lms_first_recur}\n\\emath\n\n\\subsubsection{The Second Recursion}\nSince the second term of \\eq{eq:app_lms_first_recur} does not depend on $\\vect{c}(n)$, we consider the first term of \\eq{eq:app_lms_first_recur}. Multiplying \\eq{app:lms_weight_error} for time index $n-1$ from the left with $\\vect{X}^T$ and inserting it into the first term yields\n\\begin{align}\n  E[&\\vect{c}^T(n-1)\\vect{S}(1)\\vect{c}(n-1)] = \\notag\\\\\n  &E[\\vect{c}^T(n-2)\\vect{X}^T[\\vect{I}-\\mu\\vect{u}(n-2)\\vect{u}^T(n-2)]\\vect{X}\\vect{S}(1)\\vect{X}^T[\\vect{I}-\\mu\\vect{u}(n-2)\\vect{u}^T(n-2)]\\vect{X}\\vect{c}(n-2)]\\notag\\\\\n  &{}+\\mu^2 E[v^2(n)\\vect{u}^T(n-2)\\vect{X}\\vect{S}(1)\\vect{X}^T\\vect{u}(n-2)]\\ .\n  \\label{eq:app_lms_second_recur_start}\n\\end{align}\nThe expectation of the last term is given by\n\\begin{align}\n E[v^2(n)\\vect{u}^T(n-2)\\vect{X}\\vect{S}(1)\\vect{X}^T\\vect{u}(n-2)] &= E[v^2(n)]E[\\vect{u}^T(n-2)\\vect{X}\\vect{S}(1)\\vect{X}^T\\vect{u}(n-2)]\\notag\\\\\n &= J_\\textup{min} E[\\tr{\\vect{u}^T(n-2)\\vect{X}\\vect{S}(1)\\vect{X}^T\\vect{u}(n-2)}]\\notag\\\\\n &= J_\\textup{min} \\tr{\\vect{X}\\vect{S}(1)\\vect{X}^TE[\\vect{u}(n-2)\\vect{u}^T(n-2)]}\\notag\\\\\n &= J_\\textup{min}\\tr{\\vect{S}(1)\\vect{\\Lambda}}\\ .\n\\end{align}\nThe equalities in the derivation above follows from the same arguments as in the derivation for the equivalent expression in the first recursion. Using the same arguments as in the first recursion, the first term of \\eq{eq:app_lms_second_recur_start} may be written as an outer and an inner expectation. The inner expectation can be evaluated using \\eq{eq:app_lms_4mom} with $\\vect{W}=\\vect{XS}(1)\\vect{X}^T$ or $\\vect{F}=\\vect{S}(1)$. Thus, we have that $\\vect{S}(2)$ is given by\n\\begin{align}\n  \\vect{S}(2) &= \\vect{X}^TE\\left[[\\vect{I}-\\mu\\vect{u}(n-2)\\vect{u}^T(n-2)]\\vect{X}\\vect{S}(1)\\vect{X}^T[\\vect{I}-\\mu\\vect{u}(n-2)\\vect{u}^T(n-2)]\\right]\\vect{X}\\notag\\\\\n  &= \\vect{S}(1) - 2\\mu\\vect{\\Lambda}\\vect{S}(1)+\\mu^2[\\vect{\\Lambda}\\tr{\\vect{S}(1)\\vect{\\Lambda}}+2\\vect{\\Lambda}\\vect{S}(1)\\vect{\\Lambda}]\n\\end{align}\nwhich is diagonal since $\\vect{S}(1)$ is diagonal. Thus, in total we have that\n\\begin{align}\n    E[\\|\\vect{c}(n)\\|^2] &= E[\\vect{c}^T(n-1)\\vect{S}(1)\\vect{c}(n-1)] +\\mu^2J_\\textup{min}\\tr{\\vect{\\Lambda}}\\\\\n    &= E[\\vect{c}^T(n-2)\\vect{S}(2)\\vect{c}(n-2)]+\\mu^2J_\\textup{min}\\tr{\\vect{S}(1)\\vect{\\Lambda}}+\\mu^2J_\\textup{min}\\tr{\\vect{\\Lambda}}\\\\\n    &= E[\\vect{c}^T(n-2)\\vect{S}(2)\\vect{c}(n-2)]+\\mu^2J_\\textup{min}\\tr{[\\vect{S}(1)+\\vect{I}]\\vect{\\Lambda}}\\ .\n    \\label{eq:app_lms_second_recur}\n\\end{align}\n\n\\subsubsection{The Third Recursion}\nSince the second term of \\eq{eq:app_lms_second_recur} does not depend on $\\vect{c}(n)$, we consider the first term of \\eq{eq:app_lms_second_recur}. This has the same form as the first term of \\eq{eq:app_lms_first_recur} so the derivation of the third recursion is the same as for the second recursion, except that all the time indices should be decreased by one. We therefore obtain that\n\\begin{align}\n    E[\\|\\vect{c}(n)\\|^2] &= E[\\vect{c}^T(n-1)\\vect{S}(1)\\vect{c}(n-1)] +\\mu^2J_\\textup{min}\\tr{\\vect{\\Lambda}}\\\\\n    &= E[\\vect{c}^T(n-2)\\vect{S}(2)\\vect{c}(n-2)]+\\mu^2J_\\textup{min}\\tr{[\\vect{S}(1)+\\vect{I}]\\vect{\\Lambda}}\\\\\n    &= E[\\vect{c}^T(n-3)\\vect{S}(3)\\vect{c}(n-3)]+\\mu^2J_\\textup{min}\\tr{[\\vect{S}(2)+\\vect{S}(1)+\\vect{I}]\\vect{\\Lambda}}\\ .\n    \\label{eq:app_lms_third_recur}\n\\end{align}\n\n\\subsubsection{The $n$'th Recursion}\nFrom the first, second, and third recursion, it is not hard to see a pattern for the recursions. Therefore, for the $n$'th recursion, we have that\n\\begin{align}\n    E[\\|\\vect{c}(n)\\|^2] &= \\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)+\\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\n    \\label{eq:app_lms_nth_recur}\n\\end{align}\nwhere\n\\bmath\n  \\vect{S}(n) = \\vect{S}(n-1) - 2\\mu\\vect{\\Lambda}\\vect{S}(n-1)+\\mu^2[\\vect{\\Lambda}\\tr{\\vect{S}(n-1)\\vect{\\Lambda}}+2\\vect{\\Lambda}\\vect{S}(n-1)\\vect{\\Lambda}]\n  \\label{eq:app_lms_Sn_recur}\n\\emath\nwith $\\vect{S}(0) = \\vect{I}$. From the recursion in \\eq{eq:app_lms_nth_recur}, we see that we must require that $\\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)$ remains bounded for $n\\to\\infty$, regardless of the initial conditions $\\vect{c}(0)$. Since $\\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)$ remains bounded if and only if all the eigenvalues of $\\vect{S}(n)$ are in the interval $[-1,1]$, we therefore perform an eigenvalue analysis of $\\vect{S}(n)$.\n\n\\subsubsection{Eigenvalue Analysis of $\\vect{S}(n)$}\nDefine the vector of ones\n\\bmath\n  \\vect{1} = \\bbmtx 1 & 1 & \\cdots & 1\\ebmtx^T\\ .\n\\emath\nUsing this vector, we may write the trace of a diagonal matrix $\\vect{M}$ as\n\\bmath\n  \\tr{\\vect{M}} = \\vect{1}^T\\vect{M1}\\ .\n\\emath\nSince $\\vect{S}(n)$ and $\\vect{\\Lambda}$ are diagonal matrices, the product $\\vect{S}(n)\\vect{\\Lambda}$ is also diagonal, and we have that\n\\begin{align}\n  \\vect{S}(n-1)\\vect{\\Lambda} &= \\vect{\\Lambda}\\vect{S}(n-1)\\\\\n  \\tr{\\vect{S}(n)\\vect{\\Lambda}} &= \\vect{1}^T\\vect{S}(n)\\vect{\\Lambda 1} = \\vect{1}^T\\vect{\\Lambda}\\vect{S}(n)\\vect{1}\\ .\n  \\label{eq:app_lms_tr_diag}\n\\end{align}\nMultiplying both sides of \\eq{eq:app_lms_Sn_recur} from the right with $\\vect{1}$, we obtain\n\\begin{align}\n  \\vect{S}(n)\\vect{1} &= \\vect{S}(n-1)\\vect{1} - 2\\mu\\vect{\\Lambda}\\vect{S}(n-1)\\vect{1}+\\mu^2[\\vect{\\Lambda}\\vect{1}\\vect{1}^T\\vect{\\Lambda}\\vect{S}(n-1)\\vect{1}+2\\vect{\\Lambda}^2\\vect{S}(n-1)\\vect{1}]\\\\\n  &= [\\vect{I}-2\\mu\\vect{\\Lambda}+\\mu^2(\\vect{\\Lambda}\\vect{1}\\vect{1}^T\\vect{\\Lambda}+2\\vect{\\Lambda}^2)]\\vect{S}(n-1)\\vect{1}\\ .\n\\end{align}\nNow, we define\n\\bmath\n  \\vect{D} = \\vect{I}-2\\mu\\vect{\\Lambda}+\\mu^2(\\vect{\\Lambda}\\vect{1}\\vect{1}^T\\vect{\\Lambda}+2\\vect{\\Lambda}^2)\n  \\label{eq:app_lms_D}\n\\emath\nso that we have\n\\begin{align}\n  \\vect{S}(n)\\vect{1} &= \\vect{D}\\vect{S}(n-1)\\vect{1}\\\\\n  &\\underset{\\vdots}{=} \\vect{D}^2\\vect{S}(n-2)\\vect{1}\\\\\n  & = \\vect{D}^n\\vect{S}(0)\\vect{1}\n  \\label{eq:app_lms_S_D_recur}\n\\end{align}\nThis means that the elements of the diagonal matrix $\\vect{S}(n)$ are bounded if and only if all the eigenvalues of $\\vect{D}$ are in the interval $[-1,1]$.\n\n\\subsubsection{Eigenvalue Analysis of $\\vect{D}$}\nWe can write $\\vect{D}$ as \n\\bmath\n  \\vect{D} = 2(\\vect{I}-\\mu\\vect{\\Lambda})^2+2\\mu\\vect{\\Lambda}+\\mu^2\\vect{\\Lambda}\\vect{1}\\vect{1}^T\\vect{\\Lambda}\n\\emath\nwhich is clearly positive semidefinite since $\\mu>0$ and $\\lambda_m > 0$. Thus, all eigenvalues of $\\vect{D}$ are non-negative, and the only requirement to the eigenvalues is therefore that they are smaller than one. This is equivalent to requiring that $\\vect{I}-\\vect{D}$ is positive definite. From Sylvester's criterion, we know that an $M\\times M$ matrix $\\vect{A}$ is positive definite if and only if the determinant of all the upper $m\\times m$ matrices $\\vect{A}_m$ of $\\vect{A}$ are positive for $m = 1,\\ldots,M$. If $\\vect{1}_m$ is a vector consisting of $m$ ones, $\\vect{I}_m$ is the $m\\times m$ identity matrix, and $\\vect{\\Lambda}_m$ and $\\vect{D}_m$ are the upper $m\\times m$ matrices of $\\vect{\\Lambda}$ and $\\vect{D}$, respectively, we have that\n\\bmath\n  \\vect{D}_m = \\vect{I}_m - 2\\mu\\vect{\\Lambda}_m+\\mu^2\\vect{\\Lambda}_m(\\vect{1}_m\\vect{1}_m^T+2\\vect{I}_m)\\vect{\\Lambda}_m\\ ,\\qquad \\text{for }m=1,\\ldots,M\\ ,\n\\emath\nand we require that\n\\bmath\n  |\\vect{I}_m - \\vect{D}_m| > 0\\ ,\\qquad \\text{for }m=1,\\ldots,M\n\\emath\nfor $\\vect{I}-\\vect{D}$ to be positive definite. The determinant of $\\vect{I}_m - \\vect{D}_m$ is \n\\begin{align}\n  |\\vect{I}_m-\\vect{D}_m| &= |2\\mu\\vect{\\Lambda}_m-\\mu^2\\vect{\\Lambda}_m(\\vect{1}_m\\vect{1}_m^T+2\\vect{I}_m)\\vect{\\Lambda}_m|\\\\\n  &= |\\mu^2\\vect{\\Lambda}_m||2\\mu^{-1}\\vect{I}_m-2\\vect{\\Lambda}_m - \\vect{1}_m\\vect{1}_m^T\\vect{\\Lambda}_m|\n\\end{align}\nSince $\\mu>0$ and $\\lambda_m > 0$, the determinant of $\\mu^2\\vect{\\Lambda}_m$ is positive for all $m=1,\\ldots,M$. In order to evaluate the second determinant, we use the matrix determinant lemma which states that\n\\bmath\n  |\\vect{A}+\\vect{U}\\vect{V}^T| = |\\vect{A}||\\vect{I}+\\vect{V}^T\\vect{A}^{-1}\\vect{U}|\n\\emath\nwhere $\\vect{A}$ is an $N\\times N$ matrix, and $\\vect{U}$ and $\\vect{V}$ are $N\\times M$ matrices. From the matrix determinant lemma, we have that\n\\begin{align}\n  |2\\mu^{-1}\\vect{I}_m-2\\vect{\\Lambda}_m - \\vect{1}_m\\vect{1}_m^T\\vect{\\Lambda}_m| &= |2\\mu^{-1}\\vect{I}_m-2\\vect{\\Lambda}_m||1-\\frac{1}{2}\\vect{1}_m^T\\vect{\\Lambda}_m(\\mu^{-1}\\vect{I}_m-\\vect{\\Lambda}_m)^{-1}\\vect{1}_m|\n\\end{align}\nThe argument of the first determinant is a diagonal matrix. Thus, it leads to\n\\begin{alignat}{2}\n  && 0 &< 2\\mu^{-1}-2\\lambda_m\\ ,\\qquad \\text{for }m=1,\\ldots,M\\\\\n  \\ArrowBetweenLines\n  && \\mu &< \\frac{1}{\\lambda_\\textup{max}}\\ .\n  \\label{eq:app_lms_u1}\n\\end{alignat}\nThe argument of the second determinant is a scalar. It leads to\n\\begin{alignat}{2}\n  && 0 &< 1-\\frac{1}{2}\\vect{1}_m^T\\vect{\\Lambda}_m(\\mu^{-1}\\vect{I}_m-\\vect{\\Lambda}_m)^{-1}\\vect{1}_m\\ ,\\qquad \\text{for }m=1,\\ldots,M\\\\\n  \\ArrowBetweenLines\n  && 1 &> \\frac{1}{2}\\vect{1}_m^T\\vect{\\Lambda}_m(\\mu^{-1}\\vect{I}_m-\\vect{\\Lambda}_m)^{-1}\\vect{1}_m\\ ,\\qquad \\text{for }m=1,\\ldots,M\\\\\n  && &= \\frac{1}{2}\\tr{\\vect{\\Lambda}_m(\\mu^{-1}\\vect{I}_m-\\vect{\\Lambda}_m)^{-1}}\\ ,\\qquad \\text{for }m=1,\\ldots,M\\\\\n  && &= \\frac{1}{2}\\sum_{i=1}^m\\frac{\\lambda_i}{\\mu^{-1}-\\lambda_i}\\ ,\\qquad \\text{for }m=1,\\ldots,M\\\\\n  && &= \\frac{\\mu}{2}\\sum_{i=1}^m\\frac{\\lambda_i}{1-\\mu\\lambda_i} = f_m(\\mu)\\ ,\\qquad \\text{for }m=1,\\ldots,M\\ .\n\\end{alignat}\nThe first bound on the step-size in \\eq{eq:app_lms_u1} ensures that $\\lambda_i/(1-\\mu\\lambda_i)$ is always positive. Thus,\n\\bmath\n  f_1(\\mu) < f_2(\\mu) < \\cdots < f_M(\\mu)\\ ,\\qquad\\text{for }\\mu\\in[0,\\lambda_\\textup{max}^{-1}]\\ .\n\\emath\nTherefore, if the step-size satisfies\n\\bmath\n  f(\\mu) = f_M(\\mu) < 1\\ ,\n\\emath\nthen all of the functions $f_m(\\mu)$ are also smaller than one. Moreover, $f(0) = 0$, and $f(\\mu)$ is an increasing function as long as the first bound on the step-size in \\eq{eq:app_lms_u1} is satisfied. The latter follows since the derivative of $f(\\mu)$ satisfies\n\\bmath\n  \\frac{df}{d\\mu} = \\frac{1}{2}\\sum_{m=1}^M\\frac{\\lambda_m}{(1-\\mu\\lambda_m)^2} > 0\\ ,\\qquad\\text{for }\\mu\\in[0,\\lambda_\\textup{max}^{-1}]\\ .\n\\emath\nThese observations lead to the conclusion that $\\vect{I} - \\vect{D}$ is positive definite, provided that the step-size satisfies the bound\n\\bmath\n  \\boxed{f(\\mu) = \\frac{\\mu}{2}\\sum_{m=1}^M\\frac{\\lambda_m}{1-\\mu\\lambda_m} < 1}\\ .\n  \\label{eq:app_lms_u2}\n\\emath\nIn matrix notation, we can write this bound as\n\\bmath\n  \\boxed{f(\\mu) = \\frac{1}{2}\\vect{1}^T\\vect{\\Lambda}(\\mu^{-1}\\vect{I}-\\vect{\\Lambda})^{-1}\\vect{1} =  \\frac{1}{2}\\tr{\\vect{\\Lambda}(\\mu^{-1}\\vect{I}-\\vect{\\Lambda})^{-1}}< 1}\n  \\label{eq:app_lms_u2_matrix}\n\\emath\nwhere the last equality follows since $\\vect{\\Lambda}(\\mu^{-1}\\vect{I}-\\vect{\\Lambda})^{-1}$ is diagonal. Moreover, since\n\\bmath\n  \\lim_{\\mu\\to \\lambda_\\textup{max}^{-1}} f(\\mu) = \\infty > 1\\ ,\n\\emath\nthe first bound in \\eq{eq:app_lms_u1} is always satisfied if the second bound in \\eq{eq:app_lms_u2} is satisfied. Thus, we have shown that the LMS algorithm converges in the mean-square if and only if the step-size satisfies \\eq{eq:app_lms_u2} or, equivalently, \\eq{eq:app_lms_u2_matrix}.\n\n\n\\subsection{Learning Curve}\nThe value of the cost function at time $n$ is given by\n\\begin{align}\n  J_1(\\vect{w}(n)) &= E[e^2(n)] = E[(v(n)+\\vect{u}^T(n)\\vect{\\Delta}\\vect{w}(n))^2]\\\\\n  &= E[\\vect{\\Delta}\\vect{w}^T(n)\\vect{u}(n)\\vect{u}^T(n)\\vect{\\Delta}\\vect{w}(n)]+J_\\textup{min}\n\\end{align}\nwhere the last equality follows from the fact that $v(n)$ and $\\vect{u}(n)$ are uncorrelated. If we also use the law of iterated expectations and that $\\vect{u}(n)$ and $\\vect{w}(n)$ are uncorrelated, we obtain that \n\\begin{align}\n  J_1(\\vect{w}(n)) &= E[\\vect{\\Delta}\\vect{w}^T(n)E[\\vect{u}(n)\\vect{u}^T(n)|\\vect{w}(n)]\\vect{\\Delta}\\vect{w}(n)]+J_\\textup{min}\\\\\n  &= E[\\vect{\\Delta}\\vect{w}^T(n)E[\\vect{u}(n)\\vect{u}^T(n)]\\vect{\\Delta}\\vect{w}(n)]+J_\\textup{min}\\\\\n  &= E[\\vect{\\Delta}\\vect{w}^T(n)\\vect{R}_u\\vect{\\Delta}\\vect{w}(n)]+J_\\textup{min}\\ .\n\\end{align}\nFinally, if we replace the correlation matrix $\\vect{R}_u$ of $\\vect{u}(n)$ with its eigenvalue decomposition $\\vect{R}_u=\\vect{X\\Lambda X}^T$, we have that \n\\bmath\n  J_1(\\vect{w}(n)) = E[\\vect{c}^T(n)\\vect{\\Lambda}\\vect{c}(n)]+J_\\textup{min}\n\\emath\nwhere we again have defined that $\\vect{c}(n)= \\vect{X}^T\\vect{\\Delta}\\vect{w}(n)$. Now, for $\\vect{S}(0)=\\vect{\\Lambda}$, we obtain from \\eq{eq:app_lms_nth_recur} that\n\\bmath\n    \\boxed{J_1(\\vect{w}(n)) = \\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)+\\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}+J_\\textup{min}}\n    \\label{eq:app_lms_learning_curve}\n\\emath\nwhere\n\\begin{align}\n  \\vect{S}(n) &= \\vect{S}(n-1) - 2\\mu\\vect{\\Lambda}\\vect{S}(n-1)+\\mu^2[\\vect{\\Lambda}\\tr{\\vect{S}(n-1)\\vect{\\Lambda}}+2\\vect{\\Lambda}\\vect{S}(n-1)\\vect{\\Lambda}]\\\\\n  &= \\diag{\\vect{S}(n)\\vect{1}} = \\diag{\\vect{D}^n\\vect{\\Lambda}\\vect{1}}\\ .\n\\end{align}\nHere, $\\diag{\\cdot}$ creates a diagonal matrix from a vector.\n\n\\section{Steady-State Analysis}\nIn the steady-state analysis, we derive expressions for the mean-square deviation (MSD), the excess mean-square error (EMSE), and the misadjustment of the LMS algorithm. These expressions can be derived in two different ways. One way is presented in \\cite[pp.~462--465]{Sayed2003}. Here, we give another derivation which we believe is more intuitive.\n\n\\subsection{Mean-Square Deviation}\nThe MSD is given by the limit\n\\bmath\n  \\text{MSD:}\\qquad  \\lim_{n\\to\\infty} E[\\|\\vect{\\Delta w}(n)\\|^2]\\ ,\n\\emath\nand we denote this limit by $E[\\|\\vect{\\Delta w}(\\infty)\\|^2]$. We make direct use of the definition in the derivation of the MSD. Again, we define $\\vect{c}(n)= \\vect{X}^T\\vect{\\Delta}\\vect{w}(n)$. Thus, from \\eq{eq:app_lms_nth_recur}, we have that\n\\begin{align}\n  E[\\|\\vect{\\Delta w}(\\infty)\\|^2] &= \\lim_{n\\to\\infty} E[\\|\\vect{\\Delta w}(n)\\|^2] = \\lim_{n\\to\\infty} E[\\|\\vect{c}(n)\\|^2]\\\\\n  &= \\lim_{n\\to\\infty} \\left\\{\\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)+\\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\\right\\}\\\\\n  &= \\lim_{n\\to\\infty} \\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0) + \\lim_{n\\to\\infty} \\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\\ .\n\\end{align}\nwith $\\vect{S}(0)=\\vect{I}$. If we select the step-size $\\mu$ such that the LMS algorithm converges in the mean-square, the first term equals zero. Thus, we have that\n\\begin{align}\n  E[\\|\\vect{\\Delta w}(\\infty)\\|^2] &= \\lim_{n\\to\\infty} \\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}} = \\mu^2J_\\textup{min}\\sum_{i=0}^{\\infty}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\\ .\n\\end{align}\nThe matrices $\\vect{S}(i)$ and $\\vect{\\Lambda}$ are both diagonal, and we therefore use \\eq{eq:app_lms_tr_diag} to obtain\n\\begin{align}\n  E[\\|\\vect{\\Delta w}(\\infty)\\|^2] &= \\mu^2J_\\textup{min}\\sum_{i=0}^{\\infty}\\vect{1}^T\\vect{\\Lambda}\\vect{S}(i)\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\sum_{i=0}^{\\infty}\\vect{1}^T\\vect{\\Lambda}\\vect{D}^i\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}\\sum_{i=0}^{\\infty}\\left[\\vect{D}^i\\right]\\vect{1}\n\\end{align}\nwhere the second equality follows from \\eq{eq:app_lms_S_D_recur} with  $\\vect{S}(0)=\\vect{I}$ and $\\vect{D}$ defined in \\eq{eq:app_lms_D}. Since all the eigenvalues of $\\vect{D}$ have a magnitude smaller than 1, we have from the geometric series of matrices that \\cite[p.~58]{Petersen2008}\n\\bmath\n  \\sum_{i=0}^{\\infty}\\vect{D}^i = (\\vect{I}-\\vect{D})^{-1}\\ .\n\\emath\nThus, we obtain that\n\\begin{align}\n  E[\\|\\vect{\\Delta w}(\\infty)\\|^2] &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}(\\vect{I}-\\vect{D})^{-1}\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}(2\\mu\\vect{\\Lambda}-\\mu^2(\\vect{\\Lambda}\\vect{1}\\vect{1}^T\\vect{\\Lambda}+2\\vect{\\Lambda}^2))^{-1}\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}[(2\\vect{\\mu}^{-1}\\vect{I}-2\\vect{\\Lambda}-\\vect{\\Lambda}\\vect{1}\\vect{1}^T)\\mu^2\\vect{\\Lambda}]^{-1}\\vect{1}\\\\\n  &= J_\\textup{min}\\vect{1}^T(2\\vect{\\mu}^{-1}\\vect{I}-2\\vect{\\Lambda}-\\vect{\\Lambda}\\vect{1}\\vect{1}^T)^{-1}\\vect{1}\\ .\n\\end{align}\nNow, by defining\n\\bmath\n  \\vect{G} = \\vect{\\mu}^{-1}\\vect{I}-\\vect{\\Lambda}\n\\emath\nand using the matrix inversion lemma from \\eq{eq:woodbury}, we obtain\n\\begin{align}\n  E[\\|\\vect{\\Delta w}(\\infty)\\|^2] &= J_\\textup{min}\\vect{1}^T(2\\vect{G}-\\vect{\\Lambda}\\vect{1}\\vect{1}^T)^{-1}\\vect{1}\\\\\n  &= J_\\textup{min}\\vect{1}^T\\left[\\frac{1}{2}\\vect{G}^{-1}+\\frac{1}{2}\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\left(1-\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right)^{-1}\\vect{1}^T\\vect{G}^{-1}\\frac{1}{2}\\right]\\vect{1}\\\\\n  &= J_\\textup{min}\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{1}\\left[1+\\left(1-\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right)^{-1}\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right]\\\\\n  &= J_\\textup{min}\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{1}\\left(1-\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right)^{-1}\\ .\n\\end{align}\nFinally, from \\eq{eq:app_lms_u2_matrix}, we have that\n\\bmath\n  f(\\mu) = \\frac{1}{2}\\vect{1}^T\\vect{\\Lambda}\\vect{G}^{-1}\\vect{1} = \\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\n\\emath\nwhich leads to\n\\bmath\n  \\boxed{ E[\\|\\vect{\\Delta w}(\\infty)\\|^2] = \\frac{J_\\textup{min}}{1-f(\\mu)}\\frac{\\mu}{2}\\sum_{m=1}^M\\frac{1}{1-\\mu\\lambda_m}}\\ .\n\\emath\n\n\\subsection{Excess Mean-Square Error}\nThe derivation of the EMSE is done in the same way as the MSE was derived. The EMSE is given by the limit\n\\bmath\n  \\text{EMSE:}\\qquad  \\lim_{n\\to\\infty} J_1(\\vect{w}(n))-J_\\textup{min}\\ ,\n\\emath\nand we denote it by $J_\\textup{ex}$. Inserting the expression for the learning curve from \\eq{eq:app_lms_learning_curve} in this limit yields\n\\begin{align}\n  J_\\textup{ex} &= \\lim_{n\\to\\infty} \\left\\{\\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)+\\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\\right\\}\\\\\n  &= \\lim_{n\\to\\infty} \\vect{c}^T(0)\\vect{S}(n)\\vect{c}(0)+\\lim_{n\\to\\infty}\\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\n\\end{align}\nwhere $\\vect{S}(0)=\\vect{\\Lambda}$ and $\\vect{c}(n)= \\vect{X}^T\\vect{\\Delta}\\vect{w}(n)$. If we select the step-size $\\mu$ such that the LMS algorithm converges in the mean-square, the first term equals zero. Thus, we have that\n\\begin{align}\n  J_\\textup{ex} &= \\lim_{n\\to\\infty} \\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}} = \\mu^2J_\\textup{min}\\sum_{i=0}^{\\infty}\\tr{\\vect{S}(i)\\vect{\\Lambda}}\\ .\n\\end{align}\nNote that the expression for the EMSE is the same as for the MSD, except for the value of $\\vect{S}(0)$. The matrices $\\vect{S}(i)$ and $\\vect{\\Lambda}$ are both diagonal, and we therefore use \\eq{eq:app_lms_tr_diag} to obtain\n\\begin{align}\n  J_\\textup{ex} &= \\mu^2J_\\textup{min}\\sum_{i=0}^{\\infty}\\vect{1}^T\\vect{\\Lambda}\\vect{S}(i)\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\sum_{i=0}^{\\infty}\\vect{1}^T\\vect{\\Lambda}\\vect{D}^i\\vect{\\Lambda}\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}\\sum_{i=0}^{\\infty}\\left[\\vect{D}^i\\right]\\vect{\\Lambda}\\vect{1}\n\\end{align}\nwhere the second equality follows from \\eq{eq:app_lms_S_D_recur} with $\\vect{S}(0)=\\vect{\\Lambda}$ and $\\vect{D}$ defined in \\eq{eq:app_lms_D}. Since all the eigenvalues of $\\vect{D}$ have a magnitude smaller than 1, we have from the geometric series of matrices that \\cite[p.~58]{Petersen2008}\n\\bmath\n  \\sum_{i=0}^{\\infty}\\vect{D}^i = (\\vect{I}-\\vect{D})^{-1}\\ .\n\\emath\nThus, we obtain that\n\\begin{align}\n  J_\\textup{ex} &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}(\\vect{I}-\\vect{D})^{-1}\\vect{\\Lambda}\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}(2\\mu\\vect{\\Lambda}-\\mu^2(\\vect{\\Lambda}\\vect{1}\\vect{1}^T\\vect{\\Lambda}+2\\vect{\\Lambda}^2))^{-1}\\vect{\\Lambda}\\vect{1}\\\\\n  &= \\mu^2J_\\textup{min}\\vect{1}^T\\vect{\\Lambda}[(2\\vect{\\mu}^{-1}\\vect{I}-2\\vect{\\Lambda}-\\vect{\\Lambda}\\vect{1}\\vect{1}^T)\\mu^2\\vect{\\Lambda}]^{-1}\\vect{\\Lambda}\\vect{1}\\\\\n  &= J_\\textup{min}\\vect{1}^T(2\\vect{\\mu}^{-1}\\vect{I}-2\\vect{\\Lambda}-\\vect{\\Lambda}\\vect{1}\\vect{1}^T)^{-1}\\vect{\\Lambda}\\vect{1}\\ .\n\\end{align}\nNow, by defining\n\\bmath\n  \\vect{G} = \\vect{\\mu}^{-1}\\vect{I}-\\vect{\\Lambda}\n\\emath\nand using the matrix inversion lemma from \\eq{eq:woodbury}, we obtain\n\\begin{align}\n  J_\\textup{ex} &= J_\\textup{min}\\vect{1}^T(2\\vect{G}-\\vect{\\Lambda}\\vect{1}\\vect{1}^T)^{-1}\\vect{\\Lambda}\\vect{1}\\\\\n  &= J_\\textup{min}\\vect{1}^T\\left[\\frac{1}{2}\\vect{G}^{-1}+\\frac{1}{2}\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\left(1-\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right)^{-1}\\vect{1}^T\\vect{G}^{-1}\\frac{1}{2}\\right]\\vect{\\Lambda}\\vect{1}\\\\\n  &= J_\\textup{min}\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\left[1+\\left(1-\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right)^{-1}\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right]\\\\\n  &= J_\\textup{min}\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\left(1-\\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\\right)^{-1}\\ .\n\\end{align}\nFinally, from \\eq{eq:app_lms_u2_matrix}, we have that\n\\bmath\n  f(\\mu) = \\frac{1}{2}\\vect{1}^T\\vect{\\Lambda}\\vect{G}^{-1}\\vect{1} = \\frac{1}{2}\\vect{1}^T\\vect{G}^{-1}\\vect{\\Lambda}\\vect{1}\n\\emath\nwhich leads to\n\\bmath\n  \\boxed{ J_\\textup{ex} = J_\\textup{min}\\frac{f(\\mu)}{1-f(\\mu)}}\\ .\n\\emath\n\n\\subsection{Misadjustment}\nThe expression for the misadjustment is\n\\bmath\n  \\boxed{\\mathcal{M} = \\frac{J_\\textup{ex}}{J_\\textup{min}} = \\frac{f(\\mu)}{1-f(\\mu)}}\\ .\n\\emath\n", "meta": {"hexsha": "f6cb711469417b7cdd7b9b846f538d4be1f4967e", "size": 30279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/lectures/app_lms_analysis.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/app_lms_analysis.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/app_lms_analysis.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": 71.0774647887, "max_line_length": 760, "alphanum_fraction": 0.6469830576, "num_tokens": 12274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6693044854636275}}
{"text": "\\section{Examples of Conformal Structures; Analytic Functions}\r\n\\subsection{Covering Maps and Analyticity}\r\n\\begin{lemma}\\label{covering_conformal}\r\n    If $\\pi:\\tilde{R}\\to R$ is a covering map where $R$ is a Riemann surface, then there is a unique conformal structure on $\\tilde{R}$ such that $\\pi$ is analytic.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We construct an atlas on $\\tilde{R}$ as follows:\r\n    For $p\\in\\tilde{R}$, as $\\pi$ is a covering map, there is an open neighbourhood $\\tilde{N}_p$ of $p$ such that $\\pi|_{\\tilde{N}_p}:\\tilde{N}_p\\to N_p$ is a homeomorphism for some neighbourhood $N(p)$ of $\\pi(p)$.\r\n    Now there is a conformal structure on $R$, so we can pick a chart $(\\phi_p,U_p)$ on $R$ such that $p\\in U_p$.\r\n    Our desired chart is then $(\\tilde{\\phi}_p,\\tilde{U}_p)$ where $\\tilde{U}_p=(\\pi|_{\\tilde{N}_p})^{-1}(N_p\\cap U_p)$ and $\\tilde{\\phi}_p=\\phi_p|_{N_p\\cap U_p}\\circ\\pi|_{\\tilde{U}_p}$.\r\n    It is easy to see it is a chart.\r\n    The collection of all charts produced in this form is an atlas.\r\n    To see this, just observe that the transition function is\r\n    $$\\tilde{\\phi}_p\\circ\\tilde{\\phi}_q^{-1}=\\phi_p\\circ\\pi\\circ\\pi^{-1}\\circ\\phi_q^{-1}=\\phi_p\\circ\\phi_q^{-1}$$\r\n    (with proper restrictions to local open sets) which is analytic as we got $\\phi_p,\\phi_q$ from another atlas.\r\n    So it extends to a conformal structure $\\tilde{A}$ on $\\tilde{R}$.\\\\\r\n    We shall show that $\\pi$ is analytic in this choice of conformal structure.\r\n    Let $p\\in\\tilde{R}$ and choose chart $(\\phi_p,U_p)$ in $R$ around $\\pi(p)$ and chart $(\\tilde{\\phi}_p,\\tilde{U}_p)$ in $\\tilde{R}$ constructed from $(\\phi_p,U_p)$ in the above way.\r\n    Then with proper restrictions,\r\n    $$\\phi_p\\circ\\pi\\circ\\tilde{\\phi}_p^{-1}=\\phi_p\\circ\\pi\\circ\\pi^{-1}\\circ\\phi_p^{-1}=\\operatorname{id}_{\\mathbb C}$$\r\n    which is analytic.\r\n    We are then done by Lemma \\ref{analytic_local}.\\\\\r\n    To see the uniqueness of this conformal structure, let $\\tilde{B}$ be any conformal structure on $\\tilde{R}$ such that $\\pi$ is analytic.\r\n    Let $p\\in\\tilde{R}$, $(\\psi,V)\\in\\tilde{B}$ a chart around $p$ and $(\\phi_p,U_p)$ a chart around $f(p)$.\r\n    But then locally the transition function $\\tilde\\phi_p\\circ\\psi^{-1}=\\phi_p\\circ\\pi\\circ\\psi^{-1}$ is analytic.\r\n    So by maximality $\\tilde{B}=\\tilde{A}$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the Riemann surface $R$ associated with $\\log$ we considered earlier.\r\n    Let $f,\\pi$ be the functions as usual.\r\n    As $\\pi$ is a covering map, there is a unique way to make $R$ a Riemann surface by the preceding lemma where $\\pi:R\\to C_\\star$ is analytic.\r\n    Furthermore, locally $f|_{U_{I(n)}}=f_{I(n)}\\circ\\pi$, so $f$ is analytic as well.\\\\\r\n    Furthermore, we know that there is a homeomorphism $f_{I(n)}:U_{I(n)}\\to\\tilde{V}_{I(n)}$ (where $\\tilde{V}_I=\\mathbb R+iI$) having $\\exp|_{\\tilde{V}_{I(U)}}$ as inverse.\r\n    Then $f_{I(n)}^{-1}$ agree wherever their domains intersect, so we can piece them together to give a conformal equivalence between $R$ and $\\mathbb C$.\r\n\\end{example}\r\n\\begin{example}\r\n    Similar case happened with $R_k$ and $\\sqrt[k]{\\cdot}$.\r\n    Again $\\pi$ induces a unique conformal structure on $R_k$ that makes it and $g$ analytic.\r\n    By the same argument as above, we get $g$ is a conformal equivalence.\\\\\r\n    Actually, we can even do better with this example.\r\n    Note that the singularities in $0$ and $\\infty$ are removable by identifying $\\hat{p}_k(0)=\\hat{\\pi}(0)=\\hat{g}(0)=0$ and $\\hat{p}_k(\\infty)=\\hat{\\pi}(\\infty)=\\hat{g}(\\infty)=\\infty$ (where $\\hat{g},\\hat{p}_k,\\hat{\\pi}$ are our notation for $g,p_k,\\pi$ with this extended domain and codomain).\r\n    This gives\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\hat{R}_k=R_k\\cup\\{0,\\infty\\}\\arrow{r}{\\hat{g}}\\arrow[swap]{dr}{\\hat{\\pi}}&\\mathbb C_\\infty\\arrow{d}{\\hat{p}_k}\\\\\r\n            &\\mathbb C_\\infty\r\n        \\end{tikzcd}\r\n    \\]\r\n    which is pretty nice except now $\\hat{\\pi}$ is not a covering map anymore.\r\n\\end{example}", "meta": {"hexsha": "413d9bded7379c4bfcff506567c5bc1b30288c4d", "size": 3987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/covana.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": "4/covana.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": "4/covana.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": 79.74, "max_line_length": 298, "alphanum_fraction": 0.6566340607, "num_tokens": 1331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737916455819, "lm_q2_score": 0.8333245994514082, "lm_q1q2_score": 0.6693044782129234}}
{"text": "\\section{Global Sobol Sensitivity: Sudret}\nAssociated external model: \\texttt{sudret\\_sobol\\_poly.py}\n\nThis model provides analytic Sobol sensitivities for a flexible number of input parameters.  It is taken from\n\\cite{sudret2007} and has the following form:\n\\begin{equation}\n  u(Y) = \\frac{1}{2^N} \\prod_{n=1}^N \\left(3y_n^2 + 1\\right).\n\\end{equation}\nThe variables $y_n$ are distributed uniformly on [0,1].  For three input variables ($N=3$), the Sobol sensitivities are\nas follows, to 12 digits of accuracy:\n\\begin{align}\n  S_1 = S_2 = S_3 &= \\frac{25}{91}\\hspace{10pt} (0.2747), \\\\\n  S_{1,2} = S_{1,3} = S_{2,3} &= \\frac{5}{91}\\hspace{10pt} (0.0549), \\\\\n  S_{1,2,3} &= \\frac{1}{91}\\hspace{10pt} (0.0110).\n\\end{align}\nThe mean is 1.0 and the variance is 0.728.\n\n\\subsection{Second-Order ANOVA of Second-Order Cut-HDMR Expansion of Sudret}\nOne particular analytic tests involves calculating Sobol sensitivities for the second-order cut-HDMR expansion\nof the Sudret.  We use three variables and equate $u(Y) = f(x,y,z)$.  The reference cut point is $(\\bar\nx,\\bar y, \\bar z) = (\\frac{1}{2},\\frac{1}{2},\\frac{1}{2})$.\n\nThe first step is to construct the second-order cut-HDMR expansion $T$,\n\\begin{equation}\n  f(x,y,z) \\approx T[f](x,y,z) = t_r + t_x + t_y + t_z + t_{xy} + t_{xz} + t_{yz},\n\\end{equation}\n\\begin{equation}\n  t_r \\equiv f(\\bar x,\\bar y,\\bar z),\n\\end{equation}\n\\begin{equation}\n  t_x \\equiv f(x,\\bar y,\\bar z) -t_r,\n\\end{equation}\n\\begin{equation}\n  t_{xy} \\equiv f(x,y,\\bar z) - t_x - t_y - t_r.\n\\end{equation}\nSymmetry between $x,y,z$ provides similar expressions for the remaining terms.\nThe cut-plane evaluations are\n\\begin{equation}\n  f_0 = t_r \\equiv f(\\bar x,\\bar y,\\bar z) = \\frac{343}{512},\n\\end{equation}\n\\begin{equation}\n  f_x \\equiv f(x,\\bar y, \\bar z) = \\frac{49}{128}(3x^2+1),\n\\end{equation}\n\\begin{equation}\n  f_{xy} \\equiv f(x,y, \\bar z) = \\frac{7}{32}(3x^2+1)(3y^2+1),\n\\end{equation}\nand similar for the remaining terms.  Expanding the cut-HDMR expression,\n\\begin{align}\n  T[f](x,y,z) = t_r &+ (f_x-t_r) + (f_y-t_r) + (f_y-t_r) +\\nonumber\\\\\n  &[f_{xy} - (f_x-t_r) - (f_y-t_r) - t_r]+ \\nonumber\\\\\n  &[f_{xz} - (f_x-t_r) - (f_z-t_r) - t_r]+ \\nonumber\\\\\n  &[f_{yz} - (f_y-t_r) - (f_z-t_r) - t_r],\n\\end{align}\nand collecting terms\n\\begin{equation}\n  T[f](x,y,z) = t_r - f_x - f_y - f_z + f_{xy} + f_{xz} + f_{yz}.\n\\end{equation}\nThe ANOVA terms are recovered by integration of the cut-HDMR expansion.  The ANOVA expansion $H$ is similar in\nappearance to the cut-HDMR but uses different definitions; in fact, cut-HDMR is a coarse approximation of the\nANOVA expansion.  Here we use ANOVA to approximate the cut-HDMR expansion, instead of the original model.\n\n\\begin{equation}\n  H[T](x,y,z) = h_0 + h_x + h_y + h_z + h_{xy} + h_{xz} + h_{yz},\n\\end{equation}\n\\begin{equation}\n  h_0 \\equiv \\int_0^1\\int_0^1\\int_0^1 T[f](x,y,z)\\ dx\\ dy\\ dz,\n\\end{equation}\n\\begin{equation}\n  h_x \\equiv \\int_0^1\\int_0^1 T[f](x,y,z)\\ dy\\ dz - h_0,\n\\end{equation}\n\\begin{equation}\n  h_{xy} \\equiv \\int_0^1 T[f](x,y,z)\\ dz - h_x - h_y - h_0,\n\\end{equation}\nand similarly for the remaining terms.  We evaluate the necessary integrals in the expansion.\n\\begin{align}\n  \\int_0^1\\int_0^1\\int_0^1 T[f](x,y,z)\\ dxdydz &= \\int_0^1\\int_0^1\\int_0^1 t_r - f_x - f_y - f_z + f_{xy} +\n    f_{xz} + f_{yz}\\ dxdydz,\\nonumber \\\\\n    &= \\frac{343}{512} - 3\\left(\\frac{49}{64}\\right) + 3\\left(\\frac{7}{8}\\right), \\nonumber\\\\\n    &= \\frac{511}{512}.\\nonumber\n\\end{align}\n\\begin{equation}\n  h_0 = \\int_0^1\\int_0^1\\int_0^1 T[f](x,y,z)\\ dxdydz = \\frac{511}{512}.\n\\end{equation}\n\\begin{align}\n  \\int_0^1\\int_0^1 T[f](x,y,z)\\ dxdy &= \\int_0^1\\int_0^1 t_r - f_x - f_y - f_z + f_{xy} +\n    f_{xz} + f_{yz}\\ dxdy, \\nonumber\\\\\n    &= \\frac{259}{512} + \\frac{189}{128}z^2. \\nonumber\n\\end{align}\n\\begin{equation}\n  h_z = \\int_0^1\\int_0^1 T[f](x,y,z)\\ dxdy - h_0 = \\frac{259}{512} + \\frac{189}{128}z^2 - \\frac{511}{512} =\n  -\\frac{63}{128} + \\frac{189}{128}z^2.\n\\end{equation}\n\\begin{align}\n  \\int_0^1 T[f](x,y,z)\\ dx &= \\int_0^1 t_r - f_x - f_y - f_z + f_{xy} + f_{xz} + f_{yz}\\ dx, \\nonumber\\\\\n  &= \\frac{119}{512} + \\frac{105}{128}(y^2+z^2)+ \\frac{63}{32}y^2z^2,\\nonumber\n\\end{align}\n\\begin{align}\n  h_{yz} &=\\int_0^1 T[f](x,y,z)\\ dx - h_y - h_z - h_0,\\nonumber\\\\\n  &= \\frac{119}{512} + \\frac{105}{128}(y^2+z^2)+ \\frac{63}{32}y^2z^2 - \\nonumber\\\\\n  &=\\frac{7}{32} - \\frac{21}{32}(y^2+z^2) + \\frac{63}{32}y^2z^2.\n\\end{align}\nThe other terms are obtained similarly, and are symmetric.  In summary,\n\\begin{align}\n  h_0 &= \\frac{511}{512}, \\\\\n  h_x &= -\\frac{63}{128} + \\frac{189}{128}x^2, \\\\\n  h_y &= -\\frac{63}{128} + \\frac{189}{128}y^2, \\\\\n  h_z &= -\\frac{63}{128} + \\frac{189}{128}z^2, \\\\\n  h_{xy} &= \\frac{7}{32} - \\frac{21}{32}(x^2+y^2) + \\frac{63}{32}x^2y^2, \\\\\n  h_{xz} &= \\frac{7}{32} - \\frac{21}{32}(x^2+z^2) + \\frac{63}{32}x^2z^2, \\\\\n  h_{yz} &= \\frac{7}{32} - \\frac{21}{32}(y^2+z^2) + \\frac{63}{32}y^2z^2.\n\\end{align}\nIt can be shown that the expectation value of any ANOVA expansion term is zero, with the exception of the\nfirst term $h_0$.  Additionally, each term is orthogonal to each other term.  The second moment can thus be\ncalculated as\n\\begin{align}\n  \\langle H[T](x,y,z)^2\\rangle &\\equiv \\int_0^1\\int_0^1\\int_0^1 (h_0+h_x+h_y+h_z+h_{xy}+h_{xz}+h_{yz})^2\\\n  dxdydz, \\nonumber\\\\\n  &= h_0^2+\\int_0^1\\int_0^1\\int_0^1 h_x^2+h_y^2+h_z^2+h_{xy}^2+h_{xz}^2+h_{yz}^2\\ dxdydz.\n\\end{align}\nTo obtain the variance $\\sigma_\\text{tot}^2$, we subtract the square of the mean,\n\\begin{equation}\n  \\sigma_\\text{tot}^2 = \\int_0^1\\int_0^1\\int_0^1 h_x^2+h_y^2+h_z^2+h_{xy}^2+h_{xz}^2+h_{yz}^2\\ dxdydz.\n\\end{equation}\nThe partial variance $\\sigma_k^2$ of any subset $k$ is the integral of the square of that ANOVA term.\n\\begin{equation}\n  \\sigma_x^2 = \\sigma_y^2 = \\sigma_z^2 = \\frac{3969}{20480} \\approx0.19379883,\n\\end{equation}\n\\begin{equation}\n  \\sigma_{xy}^2 = \\sigma_{xz}^2 = \\sigma_{yz}^2 = \\frac{49}{1600} =0.030625.\n\\end{equation}\nThe total variance is a sum of the partial variances,\n\\begin{equation}\n  \\sigma_\\text{tot}^2 = 3\\left(\\frac{3969}{20480}\\right) + 3\\left(\\frac{49}{1600}\\right) =\n  \\frac{68943}{102400} \\approx 0.67327.\n\\end{equation}\n\nThe Sobol indices are the ratio of the partial variance to the total,\n\n\\begin{equation}\n  \\mathcal{S}_x =\\mathcal{S}_y = \\mathcal{S}_z = \\frac{135}{469} \\approx 0.287846482,\n\\end{equation}\n\\begin{equation}\n  \\mathcal{S}_{xy} =\\mathcal{S}_{xz} = \\mathcal{S}_{yz} = \\frac{64}{1407} \\approx 0.045486851.\n\\end{equation}\n%\n%\n%\n%\n%\n%\n%\n\\section{Global Sobol Sensitivity: Ishigami}\nAssociated external model: \\texttt{ishigami.py}\n\nThis model has interesting properties for its sensitivity indices, in that $y_3$ has zero impact alone but a\nnonzero impact when coupled with $y_1$.  Additionally, the sinusoidal expression is not trivially represented\nby polynomial expansion.  It is listed in \\cite{saltelli2000} and has the following form:\n\\begin{equation}\n  u(Y) = \\sin(y_1) + a\\sin^2(y_2) + b y_3^4\\sin(y_1),\n\\end{equation}\nwhere in this case $a=7$ and $b=0.1$, and all $y_n$ are uniformly distributed on $[-\\pi,\\pi]$.\n\nThe variance and partial variances are as follows:\n\\begin{align}\n  D_\\text{tot} &= \\frac{a^2}{8} + \\frac{b\\pi^4}{5} + \\frac{b^2\\pi^8}{18} + \\frac{1}{2}, \\\\\n  D_1 &= \\frac{b\\pi^4}{5} + \\frac{b^2\\pi^8}{50} + \\frac{1}{2} ,\\\\\n  D_2 &= \\frac{a^2}{8}, \\\\\n  D_3 &= 0, \\\\\n  D_{1,2} &= 0, \\\\\n  D_{2,3} &= 0, \\\\\n  D_{1,3} &= \\frac{8b^2\\pi^8}{225}, \\\\\n  D_{1,2,3} &= 0.\n\\end{align}\nThe corresponding variance values and Sobol sensitivities are listed in Table \\ref{tab:ishigami sens}.\n\\begin{table}[h]\n  \\centering\n  \\begin{tabular}{c|c|c|c}\n    Variable & Partial Variance & Sobol Index & Sobol Total Index\\\\ \\hline\n    (total) & 13.8446 & 1 & -\\\\\n    $y_1$         & 4.34589 & 0.3138 & 0.5574\\\\\n    $y_2$         & 6.125   & 0.4424 & 0.4424\\\\\n    $y_3$         & 0       & 0      & 0.2436\\\\\n    $y_1,y_2$     & 0       & 0      & -\\\\\n    $y_1,y_3$     & 3.3737  & 0.2436 & -\\\\\n    $y_2,y_3$     & 0       & 0      & -\\\\\n    $y_1,y_2,y_3$ & 0       & 0      & -\\\\\n  \\end{tabular}\n  \\caption{Ishigami sensitivities and variances}\n  \\label{tab:ishigami sens}\n\\end{table}\n\n%\n%\n%\n%\n%\n%\n\\section{Sobol G-Function}\nAssociated external model: \\texttt{gFunction.py}\n\nThis function developed by Sobol has the benefit of tuning factors $a_n$ that allow the importance of any\nparticular term to be increased or decreased.  Because of the absolute value, this function is quite\nchallenging for polynomial expansion.  Documentation can be found in \\cite{sobol2003}.  The function is\nrepresented by\n\\begin{equation}\n  u(Y) = \\prod_{n=1}^N \\frac{|4y_n - 2|+a_n}{1+a_n},\n\\end{equation}\nwhere $y_n$ are distributed uniformly on [0,1] and $a_n$ are non-negative.  $a_n$ are generally integers, and\nsmaller values lead to greater impact of corresponding $y_n$.  As in \\cite{sudret2007} we use $N=8$ with\n$a=[1,2,5,10,20,50,100,500]$.  The partial variances are given by\n\\begin{equation}\n  D_n = \\frac{1}{3(1+a_n)^2},\n\\end{equation}\n\\begin{equation}\n  D_\\text{tot} = \\prod_{n=1}^N (D_n+1)-1.\n\\end{equation}\nAnalytic values for Sobol sensitivities are given in Table \\ref{tab:gfunc sens}.\n\\begin{table}[h]\n  \\centering\n  \\begin{tabular}{c|c|c}\n    Variable & Sobol sensitivity & Sobol total sensitivity\\\\ \\hline\n    $y_1$ & 0.6037 & 0.6342\\\\\n    $y_2$ & 0.2683 & 0.2945\\\\\n    $y_3$ & 0.0671 & 0.0756\\\\\n    $y_4$ & 0.0200 & 0.0227\\\\\n    $y_5$ & 0.0055 & 0.0062\\\\\n    $y_6$ & 0.0009 & 0.0011\\\\\n    $y_7$ & 0.0002 & 0.0003\\\\\n    $y_8$ & 0.0000 & 0.0000\\\\\n  \\end{tabular}\n  \\caption{G-Function sensitivities and variances}\n  \\label{tab:gfunc sens}\n\\end{table}\n", "meta": {"hexsha": "24021e74094a694214b40fc9765bebc1ffc97618", "size": 9569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/sobol_sens.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/tests/sobol_sens.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/tests/sobol_sens.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": 40.8931623932, "max_line_length": 119, "alphanum_fraction": 0.6397742711, "num_tokens": 3950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.6693044702020158}}
{"text": "This work consists in solving the two main problems of ``k-means''-like\nalgorithms described in Section \\ref{related} and \\ref{problem_definition}:\nchoosing the $k$ parameter and placing the $k$ initial centroids.\nThe only assumption is that the dataset is generated from one or more gaussian\ndisitributions.\n\n\n\\subsection{The choice of $k$}\nThe most common scenario does not involve a domain expert. As a matter of fact,\nno prior knowledge can be used to guess a proper and reasonable value for $k$.\\\\\nThe main idea behind the solution proposed in this work is that of exploiting global\nand local density analysis to get an initial estimate of the number of clusters\nin the data.\n\nMore formally, a \\emph{peak detection} procedure is used to retrieve\nall the peaks (i.e. local maxima) in the density function for each feature\\footnote{If\nthe item considered is a point in an n-dimensional euclidean space, this is equivalent to\nfinding all the local maxima in the density functions for each axis.} of the items in\nthe dataset. In this way, a \\emph{peak} is a data sample that is larger than\nits two neighbour samples.\nThis results in a list of peaks for each feature space and finally a n-dimensional grid\nmatching every possible peak among all the features available is created\n(see Algorithm \\ref{alg:grid_creation}).\n\\input{pseudo/grid_creation.tex}\n\nAs Figure~\\ref{grid} shows, the black diamonds on the top and on\nthe left sub-figures are the peaks found on the density distribution function among all\nthe points in the dataset, while the orange points in the central sub-figure represent the\ngrid of all the potential centroids.\nIn this way, the worst-case scenario is taken into account, allowing this approach not\nto miss any potential centroid in the whole dataset\\footnote{This approach produces an\nover-estimation of the real number of centroids, introducing possible false-negatives.}.\n\n\\begin{figure*}\n  \\center{\\includegraphics[width=0.7\\textwidth]{unbalance_rescaled_coolfig.png}}\n  \\caption{The grid with all the potential centroids computed from the peaks.}\n  \\label{grid}\n\\end{figure*}\n\nMoreover, among all the potential peaks created, only those which have at least one data\nitem assigned after a run of the k-means are kept. This allows to discard all the\nfalse-positives that were found creating all the possible combinations in all the feature spaces.\nFurthermore, it represents the refinement step for the algorithm.\n\nFinally, the items in this grid are the initial centroids, representing both the value for the\n$k$ parameter (i.e. the number of items in this grid) and their coordinates.\n\n\n\\subsection{Centroids refinement}\nThe other important phase is to find a good positioning of the $k$ initial centroids.\nThe main idea behind this feature is the following:\n\\begin{enumerate}\n    \\item \\label{step1} use peaks' locations as the ones of the centroids.\n    \\item build an ellipse around every centroid with the $(a,b)$ parameters (namely the x-axis\n        and the y-axis radii) applying the formula in Equation \\ref{ellipse_params} (see\n        Algorithm~\\ref{alg:find_ellipses}).\n    \\item merge all the ellipses that intersect with each other (see\n        Algorithm~\\ref{alg:merge_procedure}).\n    \\item go to \\ref{step1} until convergence or some other exit criterion is met.\n\\end{enumerate}\n\n\\input{pseudo/find_ellipses.tex}\n\\input{pseudo/merge_procedure.tex}\n\nThe formula described in Equation~\\ref{ellipse_params} computing the heigth and the width of\nthe ellipses is the key aspect of the proposed merging strategy.\n\\begin{equation}\n\\label{ellipse_params}\n    f(\\sigma, cdens) = ((\\sigma * 2 * 0.35) + (cdens * 0.7)) * 5\n\\end{equation}\nWhere:\n\\begin{itemize}\n    \\item $\\sigma$ is the standard deviation of the gaussian distribution underlying the cluster.\n    \\item $cdens$ is the value of the gaussian distribution Probability Distribution Function (PDF)\n        in the mean.\n\\end{itemize}\n\nTo better understand the reasoning behind this formuls, a more precise explenation of its components\nis needed.\\\\\nGiven the mean and the standard deviation of a cluster,\n$\\sigma$ is doubled to take both the sides of the gaussian distribution into account.\nThe 0.35 and the 0.7 values allow the density in the mean value of the gaussian distribution ($cdens$)\nto influence more the size of the ellipse rather than its standard deviation ($\\sigma$). Finally, 5 is\nan overall scaling factor useful to allow the comparison of cluster with very different densities.\n\nFrom an higher point of view, Equation \\ref{ellipse_params} represents the \\emph{Estimated Influence Area}\n(EIA) for each cluster. As the name suggests, this depicts (also visually) the area of influence a\ncluster has on all the others.\\\\\nAs it is possible to see from Figure~\\ref{start}, the ellipses represent all the initial\n\\emph{EIAs} starting from all the potential centroids after discarding\nall the centroids that has no item belonging to them (which are clearly false-positives).\nIf two clusters' estimated influence area has a non-empty intersection, it\nmeans that they can be collapsed and become a single bigger cluster.\nThe Figures~\\ref{start}, \\ref{middle} and \\ref{end} depicts the trend and the position of the\n\\emph{EIAs} during an example merging procedure.\n\nMoreover, as it is possible to notice from Figure \\ref{end}, the approach described in this\nsection started with many potential centroids (see Figure~\\ref{start}) and after a\nfew iterations converged finding the 8 clusters in the dataset successfully\n(see Figure~\\ref{end}).\n\n\\begin{figure}[t]\n  \\center{\\includegraphics[width=0.5\\textwidth]{unbalance_rescaled_density_0.png}}\n  \\caption{The first estimated influence areas after filtering some of the false-positives.}\n  \\label{start}\n\\end{figure}\n\n\\begin{figure}[t]\n  \\center{\\includegraphics[width=0.5\\textwidth]{unbalance_rescaled_density_3.png}}\n  \\caption{The situation after 4 iterations.}\n  \\label{middle}\n\\end{figure}\n\n\\begin{figure}[t]\n  \\center{\\includegraphics[width=0.5\\textwidth]{unbalance_rescaled_density_6.png}}\n  \\caption{The final outcome of the algorithm.}\n  \\label{end}\n\\end{figure}\n\nA noteworthy aspect is that all the aforementioned factors used inside Equation \\ref{ellipse_params} have\nbeen set after several tuning stages through empirical tests using many datasets with different\nclusters' properties.\n\nNevertheless, representing the clusters by means of sufficient statistics allows to implement an $O(1)$\nmerging procedure. More in detail, every cluster is internally represented as a touple with the\nfollowing information:\n\\begin{equation*}\n    \\left(\\left[\\sum_{p}^{|C|} feat[0],\\dots,\\sum_{p}^{|C|} feat[n]\\right],|C|\\right)\n\\end{equation*}\nIn a 2-dimensional euclidean space, this metadata result in a list containing the the sum of all the\npoints' coordinates among the 2 axes and the number of points within the cluster taken into consideration.\nThis structure contains the least possible information to compute the centroid's coordinates as the\nbarycenter of that particolar cluster.\n\nFinally, this merging strategy enables all the \\emph{Data Mining Desiderata} mentioned in Section\n\\ref{intro}. It makes use of sufficient statistics to internally represent every cluster, hence\nrequiring an overall amount of memory that is linear in the number of peaks ($O(k)$, \\emph{limited memory}\nproperty). Furthermore, the \\emph{online} behaviour is guaranteed by default, since the centroid\nbootstrap and merging procedure always return a solution at any point in time. Finally, it allows\nto deal with \\emph{straming} data thanks both to its linear memory consumption and to its ability to\nwork with chunks of data by default, propagating all the sufficient statistics needed to update the\ncentroids from one iteration to another. This also guarantees that if the computation is stopped\nit can be restarted without the need to re-process everything from scratch.\n\n\n\\subsection{Applications}\nThe approach presented in this work can have two main applications. On the one hand,\nthis procedure can be used as a bootstrapping phase for a  ``k-means''-like algorithm.\nOn the other, it can be integrated with other partitional clustering algorithms to\nrefine the local solution during the computation phase, allowing the system as a\nwhole to find increasingly better clusters.\n\nMoreover, this work is agnostic with respect\nto the metric used to compute the distance between the items. For the seek of\ncompleteness, all the figures presented in this work are computed using a\nstandard euclidean distance.\n", "meta": {"hexsha": "366f2bdce07de4e28a730ad4531e4cfe152ac925", "size": 8543, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/solution.tex", "max_stars_repo_name": "GianlucaBortoli/enhanced-clustering", "max_stars_repo_head_hexsha": "7ca4654fd72b2b279d77f803d35db9196b4a0a82", "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/sections/solution.tex", "max_issues_repo_name": "GianlucaBortoli/enhanced-clustering", "max_issues_repo_head_hexsha": "7ca4654fd72b2b279d77f803d35db9196b4a0a82", "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/sections/solution.tex", "max_forks_repo_name": "GianlucaBortoli/enhanced-clustering", "max_forks_repo_head_hexsha": "7ca4654fd72b2b279d77f803d35db9196b4a0a82", "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.4140127389, "max_line_length": 106, "alphanum_fraction": 0.7863748098, "num_tokens": 1997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544825, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.6693044576636368}}
{"text": "% file: problems/tree-traversal.tex\n\n\\section{Tree Traversal (UD Problem 4.2)}\n\n\\begin{enumerate}[(a)]\n  \\item Write an algorithm which, given a tree $T$,\n    calculates the sum of the depths of all the nodes of $T$.\n  \\item Write an algorithm which, given a tree $T$ and a positive integer $K$,\n    calculates the number of nodes in $T$ at depth $K$.\n  \\item Write an algorithm which, given a tree $T$,\n    checks whether it has any leaf at an even depth.\n\\end{enumerate}\n\n\\subsection{Solution}\n\n\\input{algs/sum-of-depths}\n\\input{algs/nodes-at-depth-K}\n", "meta": {"hexsha": "b320d951bcb136b3c17b7c15664d97431478fcb7", "size": 554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2017/2017-2nd/2-2-efficiency/problems/tree-traversal.tex", "max_stars_repo_name": "courses-at-nju-by-junma/problem-solving-class-problems", "max_stars_repo_head_hexsha": "79de740506000972b2bec91cc6042fa639cd2e55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2018-03-16T04:33:03.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-11T14:50:38.000Z", "max_issues_repo_path": "2017/2017-2nd/2-2-efficiency/problems/tree-traversal.tex", "max_issues_repo_name": "courses-at-nju-by-junma/problem-solving-class-problems", "max_issues_repo_head_hexsha": "79de740506000972b2bec91cc6042fa639cd2e55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2018-03-19T10:36:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T04:58:39.000Z", "max_forks_repo_path": "2017/2017-2nd/2-2-efficiency/problems/tree-traversal.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": 30.7777777778, "max_line_length": 78, "alphanum_fraction": 0.7075812274, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6692982279738592}}
{"text": "% !TeX root = ../libro.tex\n% !TeX encoding = utf8\n%\n%*******************************************************\n% Summary\n%*******************************************************\n\n\\selectlanguage{english}\n\\chapter{Summary}\n\nPrime numbers are of special importance when it comes to Mathematics in general and, in specific, the branch of Number Theory. Their applications go from purely theoretic results to practical uses like cryptography, which is the base of the security on the Internet.\\\\\n\nPrimality testing has been extensively studied throughout history, and specially during the second half of the $20^{th}$ and $21^{st}$ centuries with the formalitation of complexity theory by \\textit{Alan Turing}.\\\\\n\nThere has been many attempts to come up with efficient techniques to prove the primality of a number. The definition of prime numbers provides by itself a primality test: check if some number below $\\sqrt{n}$ divides $n$. This test has complexity $O(\\sqrt{n})$, which is far from ideal. We want a test that runs in logarithmic time. A great attempt for that is the \\textit{Little Fermat's Theorem}, which states that if $n$ is prime, then $a^n \\equiv a \\mod(n)$ for every $a \\in \\Z$. With that, we can check some values of $a$ and see if the congruence holds. If it doesn't hold for some value, then $n$ is definitely composite. Otherwise it is probably prime. This almost gives us an efficient test which runs in $\\Omega(\\log(n))$.\\\\\n\nUnfortunately, there exists some numbers for which the congruence holds for every value of $a$. They are called \\textit{Charmichael Numbers}. Therefore, this test is not valid, but we can make it work with a generalization of the \\textit{Little Fermat's Theorem}.\\\\\n\nLet $n > 1$ and $a \\in \\Z$. Then $n$ is prime if, and only if,\n\n\\begin{equation}\n(X + a)^n \\equiv X^n + a \\mod(n)\n\\end{equation}\n\nwhere $X$ is an indeterminate variable.\\\\\n\nThis property leads us to a general, deterministic and inconditional primality test: try the congruence for some $a$ and check if it holds. The problem with this approach is that it gives us a test with complexity $\\Omega(n)$ due to the fact that we need to evaluate $n$ coefficients in the left hand side of the congruence.\\\\\n\nWe can speed up the process if we reduce the amount of coefficients to evaluate by restricting the congruence to the ring $\\Z_n[X]/(X^r - 1)$, where $r$ is sufficiently small. This way, the congruence above is transformed into the next one below\n\n\\begin{equation}\n(X + a)^n \\equiv X^n + a \\mod(n, X^r - 1)\n\\end{equation}\n\nThis congruence still holds if $n$ is prime for every $a \\in \\Z$ and every $r$. However, it also holds for some values of $a$ and $r$ when $n$ is composite. This property can be almost completely restored if we appropriately choose $r$ and test it for some values of $a$. We are going to prove that $r$ and $a$ are $O(\\log^c(n))$ for some constant $c$, which leads us to a deterministic polynomial algorithm.\\\\\n\nThe algorithm is of great interest when it comes to the theory, as it is the first polynomial, deterministic, general and unconditional primality test. This opens the door to the development of better algorithms that also run in polynomial time.\\\\\n\nHowever, this algorithm falls behind some other tests that are currently used. For example, the \\textit{Miller-Rabin} test is of probabilistic nature, but its runtime is superior, which makes it more eligible when it comes to test for primality in branches like cryptography, where we need to test really big numbers (normally bigger than $1024$ bits) really fast.\\\\\n\nEven other primality tests that are deterministic and non-polynomial, like the ones based in elliptic curves, perform better than the \\textbf{AKS} in most useful cases.\\\\\n\nAn empirical study and comparison with other probabilistic tests is going to let us jump to that conclusion.\\\\\n\nThe algorithm is easy to implement, but some care must be taken when dealing with polynomial multiplication. A good algorithm for polynomial multiplication is needed so that the test is not completely useless. We will see that a bad algorithm for polynomial multiplication can lead to an efficiency of $O^\\sim(\\log^{31/2}(n))$ instead of $O^\\sim(\\log^{21/2}(n))$. This is going to make the test struggle for inputs bigger than $16$ bits.\\\\\n\nThe implementation uses C++ as the main programming language for its raw speed and control over the memory. For multiprecision, \\textbf{GMP} is the library that we are going to use to implement the algorithm, as it has been extensively tested and is one of the most used libraries. It is written in C, and it has a C++ API, which makes the integration easier.\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": "5a2faa6e6a5d8f770de49508890b95b24d57c3c8", "size": 4781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Memoria/preliminares/summary.tex", "max_stars_repo_name": "fgallegosalido/TFG", "max_stars_repo_head_hexsha": "0432a99442f5fcffd2b1ddfa7ba340f49609f290", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-25T09:58:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T22:57:27.000Z", "max_issues_repo_path": "Memoria/preliminares/summary.tex", "max_issues_repo_name": "fgallegosalido/TFG", "max_issues_repo_head_hexsha": "0432a99442f5fcffd2b1ddfa7ba340f49609f290", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Memoria/preliminares/summary.tex", "max_forks_repo_name": "fgallegosalido/TFG", "max_forks_repo_head_hexsha": "0432a99442f5fcffd2b1ddfa7ba340f49609f290", "max_forks_repo_licenses": ["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.9423076923, "max_line_length": 734, "alphanum_fraction": 0.7433591299, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.6692982233404814}}
{"text": "\n\\subsection{NOT}\n\nWe can perform basic operations on inputs.\n\nA simple operation is the unary NOT operator, which returns the reverse of the values of all bits.\n\nWe also have binary operators, which take two bits and return another bit. Of note are, AND, OR and XOR.\n\nThese operations are a model of Boolean algebra. So there are \\(16\\) possible binary functions and \\(4\\) possible unary operators.\n\nAs in logic, we can combine elementary logical gates to create other logic gates.\n\nThese operations can also be performed on a series of bits, however each individual bit is independent of other bits for these operations.\n\n", "meta": {"hexsha": "3e003b6b4989097f4521be41f538701ada0d30a8", "size": 624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/logic/03-01-bitwise.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/logic/03-01-bitwise.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/logic/03-01-bitwise.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.0, "max_line_length": 138, "alphanum_fraction": 0.7820512821, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.6692449235522184}}
{"text": "\\paragraph{Confidence interval}\nis a random interval, within which a true value of an estimated parameter $\\param$ lies. We cannot say\nwhere exactly inside the interval the above-mentioned value is placed.\n\\[ P(T_L < \\param < T_U) \\geq 1 - \\alpha \\]\n\n\\paragraph{Confidence interval length}\nis defined as $|T_U - T_L|$.\n\n\\vfill\n\n\\paragraph{Confidence level}\nis defined as $ 1 - \\alpha $ or $ (1 - \\alpha)100\\% $, depending on what units we want to use.\n$\\alpha$ is significance level, described later on.\n\n\\paragraph{Confidence interval properties}\nwith sample size $n$, confidence interval length $l = |T_U - T_L|$, confidence level $c = 1 - \\alpha$\n\n\\vspace{10pt} \\noindent are as follows:\n\\begin{itemize}[noitemsep,nolistsep]\n  \\item $c \\nearrow \\; \\Rightarrow \\; l \\nearrow$\n  \n  \\item for fixed $c$: sample size $n \\nearrow \\; \\Rightarrow \\; l \\searrow$\n  \n  %\\item coś jeszcze?\n  \n\\end{itemize}\n", "meta": {"hexsha": "ffed0a615a1f2f74dbddfa041eb5a69c5e6b181a", "size": 900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_5a_estim_interval.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_5a_estim_interval.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_5a_estim_interval.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3333333333, "max_line_length": 102, "alphanum_fraction": 0.7033333333, "num_tokens": 264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6692159226980596}}
{"text": "%mainfile: ../../master.tex\n\\section{Expressions}\n\\label{sec:Expressions}\nThis section describes expressions. In The Language Described in This Report, expressions are defined as the constructs that have a value. These can be used together with specific operators to create larger expressions as one would do in mathematics. Apart from combining expressions, they are often used as the right hand side of an assignment, but can also be used for indexing, the condition in conditional statements, for return values and in general all places where a value is expected.\n\n\\subsection{Operators}\\label{subsec:operators}\nFirst we look at the mathematical operators that can combine expressions.\n\\setlength{\\grammarindent}{100pt}\n\\begin{grammar}\n<Expression> ::= <Expression> <Psevenoperator> <OP6>\n \\alt <OP7>\n\n<OP7> ::= <OP7> <Psixoperator> <OP6>\n \\alt <OP6>\n\n<OP6> ::= <Pfiveoperator> <OP6>\n \\alt <OP5>\n\n<OP5> ::= <OP5> <Pfouroperator> <OP4>\n \\alt <OP4>\n\n<OP4> ::= <OP4> <Pthreeoperator> <OP3>\n \\alt <OP3>\n\n<OP3> ::= <OP3> <Ptwooperator> <OP2>\n \\alt <OP2>\n\n<OP2> ::= <OP2> <Poneoperator> <OP1>\n \\alt <OP1>\n\n<OP1> ::= <Pzerooperator> <OP1>\n \\alt <OP0>\n\n<OP0> ::= <Operand>\n \\alt '(' <Expression> ')'\n\n<PZEROOPERATOR> ::= '(''int' | 'real' | 'char' | 'bool'')'\n\n<PONEOPERATOR> ::= '$\\Twedge$' | '\\#'\n\n<PTWOOPERATOR> ::= '*' | '/' | '\\%'\n\n<PTHREEOPERATOR> ::= '+' | '-'\n\n<PFOUROPERATOR> ::= '=' | '!=' | '$\\textless$' | '$\\textless$=' | '$\\textgreater$' | '$\\textgreater$='\n\n<PFIVEOPERATOR> ::= 'NOT'\n\n<PSIXOPERATOR> ::= 'AND' | 'NAND'\n\n<PSEVENOPERATOR> ::= 'OR' | 'XOR' | 'NOR'\n\\end{grammar}\nThe precedence of the operators are created in the grammar. Here, the parse tree will be created, such that the $\\braket{PSEVENOPERATOR}$ is placed highest in the tree and the $\\braket{PZEROOPERATOR}$ is placed lowest as standard, meaning that the precedence goes from $\\braket{PZEROOPERATOR}$ to $\\braket{PSEVENOPERATOR}$ with zero having highest precedence. This precedence can be overwritten by parentheses, which resets the order so expressions inside parentheses are placed lowest in the tree. All operators have left associativity. An example can be seen in \\cref{precedenceExamples} this shows how the parse tree is created from the expression: \\\\\n\\begin{center}\n$\\Tnot a \\Tand b \\Txor 2 < 3 * (2 + 2) + 4$\n\\end{center}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{Design/Expressions/precidenceExamples.png}\n\\caption{The parse tree for \\textnormal{\\enquote{$\\Tnot a \\Tand b \\Txor 2 < 3 * (2 + 2) + 4$}}} %[XOR [AND [NOT [Bool a]][Bool b]] [< [Integer 2] [+ [* [Integer 3] [+ [Integer 2] [Integer 2]]] [Integer 4]]]]\n\\label{precedenceExamples}\n\\end{figure}\n\nWe can see that the operator placed lowest in the tree is \\enquote{+} even though \\enquote{*} has a higher precedence, and should therefore be lower in the tree. This is done because the parentheses overwrite the order, so that everything inside gets higher precedence, as intended. If we insert parentheses to illustrate the implicit precedence in the expression it would look like this:\n\\begin{center}\n$((\\Tnot a) \\Tand b) \\Txor (2 < ((3 * (2 + 2)) + 4))$\n\\end{center}\nIn \\cref{precedenceExamples} we can see that the \\enquote{XOR} operator is placed highest in the tree meaning that it has the lowest precedence. We can also see from the tree that this operator takes the result from \\enquote{AND} and \\enquote{<} as arguments where \\enquote{<} again takes the result from \\enquote{+} and the integer 2 as arguments and so on. We can see that the arguments change type as we traverse the tree. We now look at the semantics and what impact this has on the formal type rules.\n\n\\subsubsection{Arithmetic Expressions}\n\nFirst we look at arithmetic expressions. Arithmetic expressions are in TLDR defined as expressions that evaluate to a number, either a real or integer. The operators that create the arithmetic expressions are +, -, *, /, \\%, $\\Tpot$ and \\#. The semantics for these operators are as follows:\n\n\\begin{itemize}\n\\item \"+\" is a binary operator that adds two numbers of the same type\n\n\\begin{align*}\n&\\inference[$\\text{ADD}_\\text{L}$]{sEnv \\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv \\vdash  a_1 + a_2 \\Rightarrow_A a_1' + a_2}\n&\n&\\inference[$\\text{ADD}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_2 + a_1 \\Rightarrow_A a_2 + a_1'}\n\\\\\\\\\n&\\inference[$\\text{ADD}_\\text{V}$]{}\n                    {v_1 + v_2 \\Rightarrow_A v}\n                    {, v_1 + v_2 = v}\n\\end{align*}\n\n\\item \"-\" is a binary operator that subtracts two numbers of the same type\n\n\\begin{align*}\n&\\inference[$\\text{SUB}_\\text{L}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_1 - a_2 \\Rightarrow_A a_1' - a_2}\n&\n&\\inference[$\\text{SUB}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_2 - a_1 \\Rightarrow_A a_2 - a_1'}\n\\\\\\\\\n&\\inference[$\\text{SUB}_\\text{V}$]{}\n                    {v_1 - v_2 \\Rightarrow_A v}\n                    {, v_1 - v_2 = v}\n\\end{align*}\n\n\\item \"*\" is a binary operator that multiplies two numbers of the same type\n\n\\begin{align*}\n&\\inference[$\\text{MULT}_\\text{L}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                     {sEnv\\vdash a_1 * a_2 \\Rightarrow_A a_1' * a_2}\n&\n&\\inference[$\\text{MULT}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                     {sEnv\\vdash a_2 * a_1 \\Rightarrow_A a_2 * a_1'}\n\\\\\\\\\n&\\inference[$\\text{MULT}_\\text{V}$]{}\n                     {v_1 * v_2 \\Rightarrow_A v}\n                     {, v_1 * v_2 = v}\n\\end{align*}\n\n\\item \"/\" is a binary operator that divides two numbers of the same type\n\n\\begin{align*}\n&\\inference[$\\text{DIV}_\\text{L}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_1 / a_2 \\Rightarrow_A a_1' / a_2}\n&\n&\\inference[$\\text{DIV}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_2 / a_1 \\Rightarrow_A a_2 / a_1'}\n\\\\\\\\\n&\\inference[$\\text{DIV}_\\text{V}$]{}\n                    {v_1 / v_2 \\Rightarrow_A v}\n                    {, \\frac{v_1}{v_2} = v}\n\\end{align*}\n\n\\item \"\\%\" is a binary operator that returns the remainder of a floored division of two numbers of the same type\n\n\\begin{align*}\n&\\inference[$\\text{MOD}_\\text{L}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_1 \\% a_2 \\Rightarrow_A a_1' \\% a_2}\n&\n&\\inference[$\\text{MOD}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_2 \\% a_1 \\Rightarrow_A a_2 \\% a_1'}\n\\\\\\\\\n&\\inference[$\\text{MOD}_\\text{V}$]{}\n                    {v_1 \\% v_2 \\Rightarrow_A v}\n                    {, v_1 \\;\\; \\textrm{mod} \\;\\; v_2 = v}\n\\end{align*}\n\n\\item \"\\^{}\" is a binary operator that lifts the first number to the power of the second number\n\n\\begin{align*}\n&\\inference[$\\text{POW}_\\text{L}$]{sEnv\\vdash a_1  \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_1 \\Twedge a_2 \\Rightarrow_A a_1' \\Twedge a_2}\n&\n&\\inference[$\\text{POW}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_2 \\Twedge a_1 \\Rightarrow_A a_2 \\Twedge a_1'}\n\\\\\\\\\n&\\inference[$\\text{POW}_\\text{V}$]{}\n                    {v_1 \\Twedge v_2 \\Rightarrow_A v}\n                    {, v_1 ^ {v_2} = v}\n\\end{align*}\n\n\\item \"\\#\" is a binary operator that roots the first operand to the second operand\n\\begin{align*}\n&\\inference[$\\text{ROOT}_\\text{L}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_1 \\# a_2 \\Rightarrow_A a_1' \\# a_2}\n&\n&\\inference[$\\text{ROOT}_\\text{R}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv\\vdash a_2 \\# a_1 \\Rightarrow_A a_2 \\# a_1'}\n\\\\\\\\\n&\\inference[$\\text{ROOT}_\\text{V}$]{}\n                    {v_1 \\# v_2 \\Rightarrow_A v}\n                    {, \\sqrt[v_1]{v_2} = v}\n\\end{align*}\n\n\\item \"( )\" Parentheses gives what they surrounds the highest precedence.\n\n\\begin{align*}\n&\\inference[$\\text{PARENS}_\\text{A}$]{sEnv\\vdash a_1 \\Rightarrow_A a_1'}\n                       {sEnv\\vdash (a_1) \\Rightarrow_A (a_1')}\n&\n&\\inference[$\\text{PARENS}_\\text{V}$]{}\n                       {(v) \\Rightarrow_A v}\n\\end{align*}\n\\end{itemize}\n\nFor simplicity we create the following set since all type rules for these are the same.\n\n\\begin{center}\n$\\Taop = \\left\\{ {+, -, *, /, \\%, \\; \\Tpot \\;} \\right\\}$\n\\end{center}\n\nDue to the semantics of all \\enquote{AOP} operators these cannot evaluate to a real, if the two inputs are both integers. Therefore all operators in this set can take either two integers and evaluate to an integer or two reals and evaluate to a real.\n\nThe \\enquote{\\#} operator is a bit different. When taking the an integer root of another integer it can still evaluate to a real, for instance $\\sqrt[2]{2}$ evaluates to $1.4142\\dots$ Therefore both rules for \\enquote{\\#} evaluate to a real.\n\nNo operator can take a combination of real and integer. This is done since all implicit type casts are avoided in TLDR. The reason for this is that the language is designed to give the programmer all errors as early as possible, preferably on compile-time, see \\cref{typesys}. With no implicit type casts the programmer is always aware when type casts are performed and will therefore not be as prone to make runtime type errors.\n\n\\begin{align*}\n&\\inference[$\\text{EXPR}_{\\Tint,\\Tint}$]{\\Tenv e_1  : \\Tint & \n                       \\Tenv e_2 : \\Tint}\n                    {\\Tenv e_1 \\mathbin{\\text{op}} e_2 : \\Tint},  \\text{op} \\in \\Taop\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\\\\\\\\n&\\inference[$\\text{EXPR}_{\\Treal,\\Treal}$]{\\Tenv e_1 : \\Treal & \n                       \\Tenv e_2 : \\Treal}\n                    {\\Tenv e_1 \\mathbin{\\text{op}} e_2 : \\Treal},  \\text{op} \\in \\Taop\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\\\\\\\\n&\\inference[$\\text{ROOT}_{\\Tint,\\Tint}$]{\\Tenv e_1 : \\Tint &\n                       \\Tenv e_2 : \\Tint}\n                    {\\Tenv e_1 \\mathbin{\\#} e_2 : \\Treal}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\\\\\\\\n&\\inference[$\\text{ROOT}_{\\Treal,\\Treal}$]{\\Tenv e_1 : \\Treal &\n                       \\Tenv e_2 : \\Treal}\n                    {\\Tenv e_1 \\mathbin{\\#} e_2 : \\Treal}\n\\end{align*}\n\n\\subsubsection{Boolean Expressions}\nBoolean expressions are in TLDR defined as expressions that takes boolean types as arguments and returns a boolean type. The boolean expressions can be constructed from the operators AND, NAND, OR, NOR, XOR, NOT.\n\nThe following are the semantics for all boolean operators and their truth table.\n\n\\begin{itemize}\n\\item \"AND\" is a binary operator that returns true if both values are true. False otherwise\n\\begin{figure}[H]\n\\centering\n  \\begin{minipage}[c]{0.45\\linewidth}\n\t  \\centering\n    \\begin{align*}\n    &\\inference[$\\text{AND}_1$]{sEnv \\vdash b_1 \\Rightarrow_B \\bot}\n                               {sEnv \\vdash b_1 \\Tand b_2 \\Rightarrow_B \\bot}\n    \\\\\\\\\n    &\\inference[$\\text{AND}_2$]{sEnv \\vdash b_1 \\Rightarrow_B \\top \\\\ sEnv \\vdash b_2 \\Rightarrow_B \\bot}\n                               {sEnv \\vdash b_1 \\Tand b_2 \\Rightarrow_B \\bot}\n    \\\\\\\\\n    &\\inference[$\\text{AND}_3$]{sEnv \\vdash b_1 \\Rightarrow_B \\top \\\\ sEnv \\vdash b_2 \\Rightarrow_B \\top}\n                               {sEnv \\vdash b_1 \\Tand b_2 \\Rightarrow_B \\top}\n    \\end{align*}\n  \\end{minipage}\n\t\\quad\n\t\\begin{minipage}[c]{0.45\\linewidth}\n\t  \\centering\n    \\begin{tabular}{ | c | c | c | }\n      \\hline\n      $e_1$ & $e_2$ & $e_1 \\Tand e_2$ \\\\\\hline\n      $\\bot$ & $\\bot$ & $\\bot$ \\\\\\hline\n      $\\bot$ & $\\top$ & $\\bot$ \\\\\\hline\n      $\\top$ & $\\bot$ & $\\bot$ \\\\\\hline\n      $\\top$ & $\\top$ & $\\top$ \\\\\\hline\n    \\end{tabular}\n  \\end{minipage}\n\\end{figure}\n\n\\item \"OR\" is a binary operator that returns true if at least one value is true. False otherwise\n\n\\begin{align*}\n&\\inference[OR]{}\n                 {sEnv \\vdash b_1 \\Tor b_2 \\Rightarrow_B \\Tnot(\\Tnot b_1 \\Tand \\Tnot b_2)}\n\\end{align*}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | c | }\n\\hline\n$e_1$ & $e_2$ & $e_1 \\Tor e_2$ \\\\\\hline\n$\\bot$ & $\\bot$ & $\\bot$ \\\\\\hline\n$\\bot$ & $\\top$ & $\\top$ \\\\\\hline\n$\\top$ & $\\bot$ & $\\top$ \\\\\\hline\n$\\top$ & $\\top$ & $\\top$ \\\\\\hline\n\\end{tabular}\n\\end{center}\n\n\\item \"XOR\" is a binary operator that returns true if only one operand is true. False otherwise\n\n\\begin{align*}\n&\\inference[XOR]{}\n                  {sEnv \\vdash b_1 \\Txor b_2 \\Rightarrow_B (\\Tnot(b_1 \\Tand b_2)) \\Tand (b_1 \\Tor b_2)}\n\\end{align*}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | c | }\n\\hline\n$e_1$ & $e_2$ & $e_1 \\Txor e_2$ \\\\\\hline\n$\\bot$ & $\\bot$ & $\\bot$ \\\\\\hline\n$\\bot$ & $\\top$ & $\\top$ \\\\\\hline\n$\\top$ & $\\bot$ & $\\top$ \\\\\\hline\n$\\top$ & $\\top$ & $\\bot$ \\\\\\hline\n\\end{tabular}\n\\end{center}\n\n\\item \"NOR\" is OR negated.\n\n\\begin{align*}\n&\\inference[NOR]{}\n                   {sEnv \\vdash b_1 \\Tnor b_2 \\Rightarrow_B \\Tnot( b_1 \\Tor b_2 )}\n\\end{align*}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | c | }\n\\hline\n$e_1$ & $e_2$ & $e_1 \\Tnor e_2$ \\\\\\hline\n$\\bot$ & $\\bot$ & $\\top$ \\\\\\hline\n$\\bot$ & $\\top$ & $\\bot$ \\\\\\hline\n$\\top$ & $\\bot$ & $\\bot$ \\\\\\hline\n$\\top$ & $\\top$ & $\\bot$ \\\\\\hline\n\\end{tabular}\n\\end{center}\n\n\\item \"NOT\" is a unary operator that returns the opposite value of the operand.\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}[c]{0.45\\linewidth}\n\\centering\n\\begin{align*}\n&\\inference[$\\text{NOT}_\\top$]{sEnv \\vdash b_1 \\Rightarrow_B \\top}\n                       {sEnv \\vdash \\Tnot b_1 \\Rightarrow_B \\bot}\n\\\\\\\\\n&\\inference[$\\text{NOT}_\\bot$]{sEnv \\vdash b_1 \\Rightarrow_B \\bot}\n                       {sEnv \\vdash \\Tnot b_1 \\Rightarrow_B \\top}\n\\end{align*}\n\\end{minipage}\n\\quad\n\\begin{minipage}[c]{0.45\\linewidth}\n\\centering\n\\begin{tabular}{ | c | c | }\n\\hline\n$e_1$ & $ \\Tnot e_1$ \\\\\\hline\n$\\bot$ & $\\top$ \\\\\\hline\n$\\top$ & $\\bot$ \\\\\\hline\n\\end{tabular}\n\\end{minipage}\n\\end{figure}\n\n\\item \"NAND\" is a binary operator that returns true if none or a single operand is true. False otherwise.\n\n\\begin{align*}\n&\\inference[NAND]{}\n                   {sEnv \\vdash b_1 \\Tnand b_2 \\Rightarrow_B \\Tnot( b_1 \\Tand b_2 )}\n\\end{align*}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | c | }\n\\hline\n$e_1$ & $e_2$ & $e_1 \\Tnand e_2$ \\\\\\hline\n$\\bot$ & $\\bot$ & $\\top$ \\\\\\hline\n$\\bot$ & $\\top$ & $\\top$ \\\\\\hline\n$\\top$ & $\\bot$ & $\\top$ \\\\\\hline\n$\\top$ & $\\top$ & $\\bot$ \\\\\\hline\n\\end{tabular}\n\\end{center}\n\n\\item \"()\" Parentheses gives what they surround the highest precedence.\n  \n\\begin{align*}\n&\\inference[$\\text{PARENS}_\\text{B}$]{sEnv \\vdash b_1 \\Rightarrow_B b_1'}\n                       {sEnv \\vdash (b_1) \\Rightarrow_B (b_1')}\n\\end{align*}\n\\end{itemize}\n\nAll boolean operators, except NOT, takes two booleans and returns a boolean. For the simplicity of the type rules we create the Boolean Operator (BOP):\n\n\\begin{center}\n$\\Tbop = \\left\\{ {\\text{AND, NAND, OR, NOR, XOR}} \\right\\}$\n\\end{center}\n\nNote that \\enquote{NOT} is not included in the set since it only takes one boolean as input and return a boolean.\n\n\\begin{align*}\n&\\inference[$\\text{BOOL}_{BOP}$]{\\Tenv e_1 : \\Tbool &\n                       \\Tenv e_2 : \\Tbool}\n                    {\\Tenv e_1 \\mathbin{\\text{op}} e_2 : \\Tbool}, \\text{op} \\in \\Tbop\n\\\\\\\\\n&\\inference[$\\text{BOOL}_{NOT}$]{\\Tenv e : \\Tbool}\n                    {\\Tenv \\mathbin{\\text{NOT}} \\; e : \\Tbool}\n\\end{align*}\n\n\n\\subsubsection{Logical Operations}\n\\label{sec:logicOps}\n\nLogical operators are defined as operators that take numbers, i.e. integers and reals, and evaluate to boolean types.\n\nFor logical comparisons we chose \\enquote{=}. This was done in accordance with the goal of keeping a natural mathematical language. In mathematics \\enquote{=} is read as \\enquote{is equal to} or simply \\enquote{equals}, and is used for stating that two parts are equivalent to each other. Sometimes mathematicians use this statement in a contradicting manner, where they expect to prove the statement to be false. It is from this perspective of being a statement, either true or false, that we chose \\enquote{=} to be a logical comparison. The same arguments exist for other types of logical operations.\n\n\\begin{itemize}\n\\item \"=\" is a binary operator that compares the two operands for equality. Returns true if equal. False otherwise.\n\n\\begin{align*}\n&\\inference[$\\text{EQUALS}_\\text{L}$]{sEnv \\vdash a_1 \\Rightarrow_B a_1'}\n                    {sEnv \\vdash a_1 = a_2 \\Rightarrow_B a_1' = a_2}\n&\n&\\inference[$\\text{EQUALS}_\\text{R}$]{sEnv \\vdash a_1 \\Rightarrow_B a_1'}\n                    {sEnv \\vdash a_2 = a_1 \\Rightarrow_B a_2 = a_1'}\n\\\\\\\\\n&\\inference[$\\text{EQUALS}_\\text{V1}$]{}\n                    {v_1 = v_2 \\Rightarrow_B \\top}\n                    {, v_1 = v_2}\n&\n&\\inference[$\\text{EQUALS}_\\text{V2}$]{}\n                    {v_1 = v_2 \\Rightarrow_B \\bot}\n                    {, v_1 \\neq v_2}\n\\end{align*}\n\n\\item \"!=\" is a binary operator that compares the two operands for equality. Returns true if not equal. False otherwise.\n\n\\begin{align*}\n&\\inference[$NEQUALS$]{}\n                    {sEnv \\vdash a_1 != a_2 \\Rightarrow_B \\Tnot (a_1 = a_2)}\n\\end{align*}\n\n\\item \"<\" is a binary operator that compares the two operands. Returns true if the first operand is strictly less than the second operand. False otherwise.\n\n\\begin{align*}\n&\\inference[$\\text{LT}_\\text{L}$]{sEnv \\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv \\vdash a_1 < a_2 \\Rightarrow_A a_1' < a_2}\n&\n&\\inference[$\\text{LT}_\\text{R}$]{sEnv \\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv \\vdash a_2 < a_1 \\Rightarrow_A a_2 < a_1'}\n\\\\\\\\\n&\\inference[$\\text{LT}_\\text{V1}$]{}\n                    {v_1 < v_2 \\Rightarrow_B \\top}\n                    {, v_1 < v_2}\n&\n&\\inference[$\\text{LT}_\\text{V2}$]{}\n                    {v_1 < v_2 \\Rightarrow_B \\bot}\n                    {, v_1 \\geq v_2}\n\\end{align*}\n\n\\item \"<=\" is a binary operator that compares the two operands. Returns true if the first operand is less than or equal to the second operand. False otherwise.\n\n\\begin{align*}\n&\\inference[$LTEQ$]{}\n                    {sEnv \\vdash a_1 <= a_2 \\Rightarrow_A (a_1 < a_2) \\Tor (a_1 = a_2)}\n\\end{align*}\n\n\\item \">\" is a binary operator that compares the two operands. Returns true if the first operand is strictly greater than the second operand. False otherwise.\n\n\\begin{align*}\n&\\inference[$\\text{GT}_\\text{L}$]{sEnv \\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv \\vdash a_1 > a_2 \\Rightarrow_A a_1' > a_2}\n&\n&\\inference[$\\text{GT}_\\text{R}$]{sEnv \\vdash a_1 \\Rightarrow_A a_1'}\n                    {sEnv \\vdash a_2 > a_1 \\Rightarrow_A a_2 > a_1'}\n\\\\\\\\\n&\\inference[$\\text{GT}_\\text{V1}$]{}\n                    {v_1 > v_2 \\Rightarrow_B \\top}\n                    {, v_1 > v_2}\n&\n&\\inference[$\\text{GT}_\\text{V2}$]{}\n                    {v_1 > v_2 \\Rightarrow_B \\bot}\n                    {, v_1 \\leq v_2}\n\\end{align*}\n\n\\item \">=\" is a binary operator that compares the two operands. Returns true if the first operand is greater than or equal to the second operand. False otherwise.\n\n\\begin{align*}\n&\\inference[$GTEQ$]{}\n                    {sEnv \\vdash a_1 >= a_2 \\Rightarrow_A (a_1 > a_2) \\Tor (a_1 = a_2)}\n\\end{align*}\n\\end{itemize}\n\nSince all logical operators take a number and returns a boolean we create the set Logical Operators (LOP):\n\\begin{center}\n$\\Tlop = \\left\\{ {=, !=, <, <=, >, >=} \\right\\}$\t\n\\end{center}\n\n\\begin{align*}\n&\\inference[$\\text{BOOL}_{\\Tint,\\Tint}$]{\\Tenv e_1 : \\Tint & \n                       \\Tenv e_2 : \\Tint}\n                    {\\Tenv e_1 \\mathbin{\\text{op}} e_2 : \\Tbool}, \\text{op} \\in \\Tlop\n\\\\\\\\\n&\\inference[$\\text{BOOL}_{\\Treal,\\Treal}$]{\\Tenv e_1 : \\Treal &\n                       \\Tenv e_2 : \\Treal}\n                    {\\Tenv e_1 \\mathbin{\\text{op}} e_2 : \\Tbool}, \\text{op} \\in \\Tlop\n\\end{align*}\n\n\\subsection{Operands}\\label{operands}\n\nWhen creating expressions, one also needs operands to use in the operators. The operands are as follows in formal syntax:\n\\begin{grammar}\n<Operand>\t::= <Block>\n \\alt <Integer>\n \\alt <Real>\n \\alt <Boolean>\n \\alt <Literals>\n \\alt <Invocation>\n\\end{grammar}\nSome of these operands can evaluate something that is neither an Integer, Real or Boolean; for instance lists, actors and structures. This means that, due to the type system seen in \\cref{subsec:operators}, the operand cannot be an argument to any operand. This however does not mean that it cannot be an expression, they can because all operands by themselves also have value and are an expression.\n\n\\subsubsection{Integer}\nThe integer is a literal integer that is written directly in the code, for instance in the statement \\enquote{$\\Tlet \\Tx := 2;$}, \\enquote{2} is an integer literal. All integers are interpreted as decimal numbers and can be any combination of the symbols 0-9 in any length. They can be either positive or negative, illustrated with the symbol \\enquote{-}, but may not start with a 0 unless it is only the number \\enquote{0}. This is done since readability is weighted higher than writeability, see \\cref{analsum}, and it was assessed for instance \\enquote{00023} is not very readable compared to \\enquote{23}. \n\n\\paragraph{Syntax}\n\n\\begin{grammar}\n<Integer> ::= '-'?[1-9][0-9]* | '0'\n\\end{grammar}\n\n\\paragraph{Semantics}\n\n\n\\begin{align*}\n\\intertext{The num rule is mapping numerals to numbers.}\n&\\inference[NUM]{}\n                  {sEnv \\vdash n \\Rightarrow_A v}\n                  {, \\mathcal{N}(n) = v}\n\\end{align*}\n\n\\paragraph{Type Rules}\n\n\\begin{align*}\n\\intertext{The type of a integer literal is simply $int$}\n&\\inference[NUM]{\\Tenv n:\\Tint}\n                 {\\Tenv n: \\Tint} \n\\end{align*}\n\n\\subsubsection{Real}\nThe real is a literal real that is written directly in the code, for instance in the statement \\enquote{$\\Tlet \\Tx := 4.3;$}, \\enquote{4.3} is an real literal. All real are interpreted as decimal numbers and is an integer followed by a \\enquote{.} and then any combination of the symbols 0-9. They can like integers be either positive or negative, indicated with the symbol \\enquote{-}. There must be at least one number both before and after the \\enquote{.}. This means that neither \\enquote{.1} and \\enquote{1.} are allowed. This is done since it was assessed that for instance \\enquote{-0.1} is more readable than \\enquote{-.1}.\n\n\\paragraph{Syntax}\n\n\\begin{grammar}\n<Real> ::= ('-'?[1-9][0-9]* | '0')'.'[0-9]+\n\\end{grammar}\n\n\\paragraph{Semantics}\n\n\\begin{align*}\n\\intertext{The real rule is mapping numerals to reals}\n&\\inference[REAL]{}\n                  {sEnv \\vdash n \\Rightarrow_A v}\n                  {, \\mathcal{R}(n) = v}\n\\end{align*}\n\n\\paragraph{Type Rules}\n\n\\begin{align*}\n&\\inference[REAL]{\\Tenv n_1:\\Tint & \\Tenv n_2:\\Tint}\n                 {\\Tenv n_1.n_2: \\Treal}\n\\end{align*}\n\n\\subsubsection{Boolean}\nBooleans are symbols that hold the value of either true or false. For instance we can in mathematics write \\enquote{2 > 3}, this is a contradiction and therefore false.\n\n\\paragraph{Syntax}\n\n\\begin{grammar}\n<Boolean> ::= 'true' | 'false'\n\\end{grammar}\n\n\\paragraph{Semantics}\n\n\\begin{align*}\n\\intertext{The bool rules are mapping boolean literals to boolean values}\n&\\inference[TRUE]{}\n                   {\\Braket{\\Ttrue,sEnv} \\Rightarrow_B \\top}\n&\\inference[FALSE]{}\n                   {\\Braket{\\Tfalse,sEnv} \\Rightarrow_B \\bot}\n\\end{align*}\n\n\\paragraph{Type Rules}\n\n\\begin{align*}\n\\intertext{The type of a bool literal is simply a bool type}\n&\\inference[BOOL]{\\Tenv b:\\Tbool}\n                 {\\Tenv b: \\Tbool}\n\\end{align*}\n\n\\subsubsection{Invocation}\\label{subsubsec:invocation}\nAn invocation in TLDR is defined as a series of characters, from here on referred to as the symbol, which is associated with a value. The value can either depend on arguments, a function, or be independent from any input, a constant or variable. If the value depends on arguments the evaluation is done lazy, meaning that the output value is only associated with the symbol when the symbol is invoked. Otherwise the symbol is associated with the functionality, i.e. its statements and how to evaluate the function. \n\nWe differentiate between direct and indirect arguments. Direct arguments are put inside parentheses after the symbol. These arguments can be any value as long as the types follow the type rules. A symbol can be dependent on a value, that is not given as a direct input, but outside its body, as long as it is in scope. We call these indirect arguments. If a function is dependent on indirect arguments we call it impure. Note that this property will be important in \\cref{subsubsec:BasicActorFunctionality}. \n\nA symbols dependence on arguments, both direct and indirect, is illustrated with parentheses. Inside the parentheses are the direct arguments. Note that these parentheses can be empty, if the symbol is only dependent on indirect or no arguments. For instance if x is declared as a symbol that takes an integer and returns an integer, see \\cref{subsubsec:BasicActorFunctionality} for declarations, writing \\enquote{y := x} would mean that y also has to be a function that takes an integer and returns an integer, but writing \\enquote{z := x(2)} means that z is an integer. Any symbol, both invoked and uninvoked, can be considered expressions, i.e. having a value.\n\nThis syntax was decided since it is very close to mathematics, where functions take arguments in parentheses.\n\\begin{grammar}\n<Invocation> ::= <Identifier> ('(' (<Expression> (',' <Expression>)*)? ')')?;\n\n<Identifier> ::= 'me'\n \\alt <Id>\n \\alt <Id> <Accessor>\n\n<Id> ::= [a-zA-Z][a-zA-Z\\_0-9]*-('let' | 'var' | 'bool' | 'integer' | 'real' | 'char' | 'struct' | 'actor' | 'receive' | 'send' | 'spawn' | 'return' | 'for' | 'in' | 'if' | 'else' | 'while' | 'die' | 'me');\n\n<Accessor> ::= '.' <Identifier>\n \\alt '.' '[' <Expression> ']'\n\n<Primitive> ::= 'int' | 'real' | 'char' | 'bool'\n\\end{grammar}\n\n\\begin{align*}\n\\intertext{A symbol, $x$, is evaluated to a value by finding the symbol in the symbol environment $sEnv$.}\n&\\inference[$\\text{INVOKE}_{A1}$]{\\Braket{S,sEnv} \\Rightarrow_A v}\n                  {\\Braket{x,sEnv} \\Rightarrow_A v}\n                  {,sEnv(x) = \\Braket{S,\\epsilon}}\n\\intertext{A function, $x_1$ is invoked with the parameter $x_2$ and evaluated to a value by finding $x_1$ in the symbol environment $sEnv$. This lookup results in the statement $S_1$ which is the body of the function, and the formal parameter $x_1'$. The actual parameter $x_2$ is then looked up in the symbol environment $sEnv$ for the statement $S_2$ which is the body of the actual parameter, and $x_2'$ which is the parameter for $x_2$. To evaluate the function, the formal parameter $x_1'$ in the symbol environment is assigned to the result of the lookup of the formal parameter $x_2$, $S_2$ and $x_2'$.}\n&\\inference[$\\text{INVOKE}_{A2}$]{\\Braket{S_1,sEnv[x_1' \\mapsto \\Braket{S_2,x_2'}]} \\Rightarrow_A v}\n                  {\\Braket{x_1(x_2),sEnv} \\Rightarrow_A v}\n                  {,sEnv(x_1) = \\Braket{S_1,x_1'}, sEnv(x_2) = \\Braket{S_2,x_2'}}\n\\intertext{A symbol $x$ is evaluated to a boolean value of true, when the body $S$ of the symbol is found in the symbol environment $sEnv$, evaluates to true.}\n&\\inference[$\\text{INVOKE}_{B1\\top}$]{\\Braket{S,sEnv} \\Rightarrow_B \\top}\n                  {\\Braket{x,sEnv} \\Rightarrow_B \\top}\n                  {,sEnv(x) = \\Braket{S,\\epsilon}}\n\\intertext{This rule is the same as the above, but in this case, the body of the symbol $x$ evaluates to false, and therefore so does $x$ too.}\n&\\inference[$\\text{INVOKE}_{B1\\bot}$]{\\Braket{S,sEnv} \\Rightarrow_B \\bot}\n                  {\\Braket{x,sEnv} \\Rightarrow_B \\bot}\n                  {,sEnv(x) = \\Braket{S,\\epsilon}}\n\\intertext{This rule is similar to the rule $INVOKE_{A2}$, but instead of the value being a arithmetic value, it is a boolean value.}\n&\\inference[$\\text{INVOKE}_{B2\\top}$]{\\Braket{S_1,sEnv[x_1' \\mapsto \\Braket{S_2,x_2'}]} \\Rightarrow_B \\top}\n                  {\\Braket{x_1(x_2),sEnv} \\Rightarrow_B \\top}\n                 {,sEnv(x_1) = \\Braket{S_1,x_1'}, sEnv(x_2) = \\Braket{S_2,x_2'}}\n\\intertext{This rule is the same as $INVOKE_{B2\\top}$, but instead of the boolean value being true, it is false.}\n&\\inference[$\\text{INVOKE}_{B2\\bot}$]{\\Braket{S_1,sEnv[x_1' \\mapsto \\Braket{S_2,x_2'}]} \\Rightarrow_B \\bot}\n                  {\\Braket{x_1(x_2),sEnv} \\Rightarrow_B \\bot}\n                 {,sEnv(x_1) = \\Braket{S_1,x_1'}, sEnv(x_2) = \\Braket{S_2,x_2'}}\n\\end{align*}\n\n\\begin{align*}\n\\intertext{The type of an invocation can be looked up in the type environment $E$.}\n&\\inference[INVOKE]{\\Tenv x: \\Tt}\n                 {\\Tenv x: \\Tt}\n\\end{align*}\n\n\\subsubsection{Literals}\nThere are four types of literals other than the numerical types and booleans. These are \\emph{char}, \\emph{list}, \\emph{structLiteral} and \\emph{tuple}.\\\\\nA \\emph{char} is a single alphanumerical character, written in the code with apostrophes on either side. An example of a char is \\emph{'a'}.\\\\\nA \\emph{list} is a collection type which can contain an arbitrary number of elements of a single type. A \\emph{list} is written in the code inside square brackets, with the elements either separated by commas or written as a range from one number to another signified by \\emph{..}. Two examples of a \\emph{list} are \\emph{[1,2,3]} and \\emph{[1 .. 10]}.\\\\\nA \\emph{structliteral} is an initialisation of a struct. If we have a struct \\emph{struct s := \\{x:int; y:real;\\};}, a literal of \\emph{s} could for example be \\emph{\\{x := 3; y:= 2.3;\\}}.\\\\\nA \\emph{tuple} is much like a \\emph{struct} in the way it can contain an arbitrary amount of fields with no restrictions on types. In \\emph{tuples} however, the fields have no name. An example of a \\emph{tuple} is \\emph{(1, 2.5 , \\enquote{hello world} )}.\\\\\n\\begin{grammar}\n<Literals> ::= <String>\n \\alt <Char>\n \\alt <List>\n \\alt <StructLiteral>\n \\alt <Tuple>\n\n<String> ::= '\\textquotedbl' (U+0020 .. U+007E)* '\\textquotedbl'\n\n<Char> ::= '\\textquotesingle' U+0020 .. U+007E '\\textquotesingle'\n\\end{grammar}\n\n\\subsubsection{Block}\nIn TLDR, blocks are a way to encapsulate statements, see \\cref{sec:statements}. This is done via curly brackets, \\enquote{\\{} starting the block, and \\enquote{\\}} ending it.\n\n\\begin{grammar}\n<Block> ::= '\\{' <Body> '\\}'\n\n<Body> ::= <Body> ';' <Statement>\n \\alt <Body> ';'\n \\alt <Statement>\n\\end{grammar}\n\nNote the that the last semicolon in a block is optional.\n\nStatements do not have a value in TLDR, but they update the state of the program or at least have the possibility to do so. When a block is evaluated the statements inside it are run.\n\n\\begin{align*}\n&\\inference[$\\text{BLOCK}_{S1}$]{\\Braket{S,sEnv} \\Rightarrow_S \\Braket{S',sEnv'}}\n                                {\\Braket{\\{S\\},sEnv} \\Rightarrow_S \\Braket{\\{S'\\},sEnv'}}\n\\end{align*}\nA block is bit different than most other constructs in TLDR in that it is a statement, but can at the same time be an expression too. If the last that is run inside the block is a statement the block itself is only a statement:\n\\begin{align*}\n&\\inference[$\\text{BLOCK}_{S2}$]{\\Braket{S,sEnv} \\Rightarrow_S sEnv'}\n                                {\\Braket{\\{S\\},sEnv} \\Rightarrow_S sEnv'}\n\\end{align*}\nAn expression by itself is in principle a statement in TLDR, for instance \\enquote{2 + 2;}. Note that this is not allowed in an expression, for instance \\enquote{2 + 2; + 4}. An expression which takes the form of a statement, will not have value, but can give a block value if it is the last thing that is evaluated in it. If it is, the block takes the value of this expression thereby making the block an expression. So for instance the block:\n\\begin{lstlisting}\n{\n  let a:int := 5;\n  a * 2\n}\n\\end{lstlisting}\nwill have the value 10 when evaluated. This is formally, for aritmetic expressions, described as:\n\\begin{align*}\n&\\inference[$\\text{BLOCK}_{A3}$]{\\Braket{x,sEnv} \\Rightarrow_A \\Braket{x',sEnv}}\n                         {\\Braket{\\{x\\},sEnv} \\Rightarrow_A \\Braket{\\{x'\\},sEnv}}\n&\n&\\inference[$\\text{BLOCK}_{A4}$]{\\Braket{x,sEnv} \\Rightarrow_A v}\n                         {\\Braket{\\{x\\},sEnv} \\Rightarrow_A v}\n\\end{align*}\nAnd for boolean and logical expressions:\n\\begin{align*}\n&\\inference[$\\text{BLOCK}_{B1}$]{\\Braket{x,sEnv} \\Rightarrow_B \\Braket{x',sEnv}}\n                         {\\Braket{\\{x\\},sEnv} \\Rightarrow_B \\Braket{\\{x'\\},sEnv}}\n\\\\\\\\\n&\\inference[$\\text{BLOCK}_{B2}$]{\\Braket{x,sEnv} \\Rightarrow_B \\top}\n                         {\\Braket{\\{x\\},sEnv} \\Rightarrow_B \\top}\n&\n&\\inference[$\\text{BLOCK}_{B3}$]{\\Braket{x,sEnv} \\Rightarrow_B \\bot}\n                         {\\Braket{\\{x\\},sEnv} \\Rightarrow_B \\bot}\n\\end{align*}\nThe keyword \\enquote{return} forces an exit from the block and gives the block the value of whatever that expression that is after the keyword. This is done simply by inserting the expression and removing any further statements.\n\\begin{align*}\n&\\inference[$\\text{RETURN}_{1}$]{}\n                   {\\Braket{\\{\\Treturn \\Tx;S\\},sEnv} \\Rightarrow_S \\Braket{\\{x\\},sEnv}}\n\\\\\\\\\n&\\inference[$\\text{RETURN}_{2}$]{}\n                   {\\Braket{\\{\\Treturn \\Tx\\},sEnv} \\Rightarrow_S \\Braket{\\{x\\},sEnv}}\n\\\\\\\\\n&\\inference[$\\text{RETURN}_{3}$]{}\n                   {\\Braket{\\{\\Treturn;S\\},sEnv} \\Rightarrow_S \\Braket{sEnv}}\n\\\\\\\\\n&\\inference[$\\text{RETURN}_{3}$]{}\n                   {\\Braket{\\{\\Treturn\\},sEnv} \\Rightarrow_S \\Braket{sEnv}}\n\\end{align*}\nIf the block is not an expression we say it has the return type \\enquote{unit}. Any piece of code, that does not evaluate to a value, is said to be of type unit and cannot be used in an assignment. Note that all statements by themselves have the type unit, but that a block only has the type unit when evaluated.\n\n\\begin{align*}\n\\intertext{Blocks have the type of the last statement run in the block.}\n&\\inference[BLOCK]{\\Tenv s_1: \\Tt & \\Tenv s_2: \\Tt'}\n                 {\\Tenv \\{s_1; s_2\\} : \\Tt'}\n\\end{align*}\n", "meta": {"hexsha": "0e088732baa14d1c274632580788eb5746596670", "size": 33638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Design/Expressions/expressions.tex", "max_stars_repo_name": "simonvandel/TLDR", "max_stars_repo_head_hexsha": "1fb4ce407174224efce92aa3ee5e1ac5704a307b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-02-18T13:38:49.000Z", "max_stars_repo_stars_event_max_datetime": "2015-02-18T13:38:49.000Z", "max_issues_repo_path": "Report/Design/Expressions/expressions.tex", "max_issues_repo_name": "simonvandel/P4", "max_issues_repo_head_hexsha": "1fb4ce407174224efce92aa3ee5e1ac5704a307b", "max_issues_repo_licenses": ["MIT"], "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/Design/Expressions/expressions.tex", "max_forks_repo_name": "simonvandel/P4", "max_forks_repo_head_hexsha": "1fb4ce407174224efce92aa3ee5e1ac5704a307b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-04-12T20:49:43.000Z", "max_forks_repo_forks_event_max_datetime": "2016-04-12T20:49:43.000Z", "avg_line_length": 47.1781206171, "max_line_length": 663, "alphanum_fraction": 0.6429038587, "num_tokens": 10597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6690530520743271}}
{"text": "\\section{The dispersion method in three and two dimensions}\\label{sec:3D dispersion}\nIn this section we explicitly derive the dispersion formalism in both three and two dimensions by renormalizing the contact interaction on a lattice.\nThis non-perturbative renormalization allows to extract regularization independent observables (see also \\Refs{Seki:2005ns, Epelbaum:2018zli}).\nWe show that it is possible to tune the contact strength parameter in a finite volume for a given discretization scheme such that one directly obtains continuum infinite volume results when using the dispersion formalism---without any further extrapolation.\n\n\\subsection{Three dimensions}\n\nAccording to \\eqref{T matrix}, \\eqref{I0} and \\eqref{spherical FD}, we find that the phase shifts are related to the contact interaction by\n\\begin{equation}\\label{eq:blah blah}\n\tp \\cot \\delta_3(p)\n\t= \\lim\\limits_{\\Lambda \\to \\infty}\\frac{2 \\pi}{\\mu}\\frac{1}{T(p, \\Lambda)} + i p\n\t= \\lim\\limits_{\\Lambda \\to \\infty}\n\t\t\\frac{2 \\pi}{\\mu} \\left[\n\t\t\t\\frac{1}{C(\\Lambda)} - I_3(p, \\Lambda)\n\t\t\\right]\n\t\\, ,\n\\end{equation}\nwith\n\\begin{equation}\n\tI_3(p, \\Lambda)\n\t=\n\t-\\frac{\\mu}{2 \\pi}\n\t\\left[\n\ti p + \\frac{2 \\Lambda}{\\pi} + \\frac{2  p}{\\pi} \\log \\left( \\frac{\\Lambda - p}{\\Lambda + p}\\right)\n\t\\right]\n\\end{equation}\nThe contact interaction cannot depend on any dynamic momenta; it is only possible to absorb momentum independent regulator terms when renormalizing the contact interaction.\nIt is still possible to renormalize the interaction such that the phase shifts, in the limit of $\\Lambda \\to \\infty$, are independent of the cutoff by choosing the renormalized strength $C_R$ according to\n\\begin{equation}\\label{eq:three-d-counterterm}\n\t\\frac{2 \\pi}{\\mu} \\frac{1}{C_R(\\Lambda)} + \\frac{2 \\Lambda}{\\pi}\n\t\\equiv\n\t- \\frac{1}{a_3}\n\t=\n\tp \\cot \\delta_3(p)\n\t\\, .\n\\end{equation}\n\nIn particular, because the limit of $\\Lambda \\to \\infty$ is well defined for this choice of the contact interaction parameter $C_R(\\Lambda)$, one is able to evaluate both sides for a given momentum, such as $p=0$\n\\begin{equation}\n\t- \\frac{1}{a_3}\n\t=\n\t\\lim\\limits_{p \\to 0}\\lim\\limits_{\\Lambda \\to \\infty}\n\t\t\\left[\n\t\t\t\\frac{2 \\pi}{\\mu}\\frac{1}{T(p, \\Lambda)} \\bigg|_{C=C_R} + i p\n\t\\right]\n\t=\n\t\\lim\\limits_{\\Lambda \\to \\infty}\n\t\\frac{2 \\pi}{\\mu}\n\t\t\\left[\n\t\t\\frac{1}{C_R(\\Lambda)} - I_3(0, \\Lambda)\n\t\t\\right]\n\t\\, .\n\\end{equation}\n\nWe now want to find an equivalent expression to the finite-volume zeta functions in presence of a discretization scheme.\nIn particular, the discretization scheme depends on the implementation of the kinetic operator $K^{(n_s)}$ and thus depends on the $n_s$ parameter.\nThe lattice spacing can be identified with the hard momentum cutoff $\\Lambda = \\pi / \\epsilon$.\nThat is, the expectation value of the dispersion scales as $\\hat K^{(n_s)}(\\epsilon) \\ket{p} = p^2 [1 + \\mathcal O(\\epsilon p)^{2 n_s}]\\ket{p}$.\n\nIf one replaces the continuum momentum dispersion $q^2$ in $I_3$ with the kinetic operator for a given lattice spacing and discretization, one defines a sequence in $n_s$ which converges against $I_3$ in the limit of $n_s \\to \\infty$\n\\begin{equation}\n\t\\lim\\limits_{n_s \\to \\infty} I^{(n_s)}_3(p, \\Lambda) = I_3(p, \\Lambda)\n\t\\, , \\qquad\n\tI^{(n_s)}_3\\left(p, \\Lambda=\\frac{\\pi}{\\epsilon} \\right)\n\t=\n\t    \\int\\limits_{-\\pi/\\epsilon}^{+\\pi/\\epsilon}\n        \\mathrm{d}^3 \\vec{q}\n        \\left[\n            \\PV \\left(\n                \\frac{1}{\n                    E - \\frac{1}{2\\mu} K_{qq}^{(n_s)} }\n                \\right)\n            -i \\pi \\delta\\left(E - \\frac{1}{2\\mu}K_{qq}^{(n_s)}\\right)\n        \\right]\n        \\, .\n\\end{equation}\nWe furthermore define a sequence for the contact strength parameter depending on the cutoff and the employed discretization scheme which equivalently converges against the continuum result.\nThis sequence is determined by matching against the dispersion integral for each value of the cutoff and for each discretization scheme\n\\begin{equation}\\label{eq:dispersion-renormalization}\n\t\\lim\\limits_{n_s \\to \\infty} C^{(n_s)}_R(\\Lambda) = C_R(\\Lambda) \\, ,\n\t\\qquad\n\t- \\frac{1}{a_3}\n\t\\equiv\n\t\\frac{2 \\pi}{\\mu}\n\t\t\\left[\n\t\t\\frac{1}{C_R^{(n_s)}(\\Lambda)} - I_3^{(n_s)}(0, \\Lambda)\n\t\t\\right]\n\t\\, .\n\\end{equation}\nIt is possible to make this choice since both terms do not depend on any external momentum $p$.\nThis is specific for the contact interaction.\nOne can view this choice as the renormalization equation for contact interaction in presence of lattice discretization which, by definition, trivially satisfies\n\\begin{equation}\n\t- \\frac{1}{a_3}\n\t=\n\t\\lim\\limits_{\\Lambda \\to \\infty} \\lim\\limits_{n_s \\to \\infty}\n\t\\frac{2 \\pi}{\\mu}\n\t\t\\left[\n\t\t\\frac{1}{C_R^{(n_s)}(\\Lambda)} - I_3^{(n_s)}(0, \\Lambda)\n\t\t\\right]\n\t\\, .\n\\end{equation}\nIn fact, it satisfies this equation even without the limits.\n\nNext we address how this renormalization choice relates to the dispersion zeta function.\nFor any lattice implementation of a contact interaction with strength $c^\\dispersion$ in finite volume, the Schr\\\"odinger equation can be rewritten as\n\\begin{equation}\\label{eq:schroe}\n\t\\hat G(E) \\hat V \\ket{\\psi} = E\\ket{\\psi}\n\t\\quad \\Rightarrow \\quad\n\t0 = 1 - c^\\dispersion I_{3, \\FV}^{(n_s)}\\left(\\sqrt{2 \\mu E^\\dispersion}, \\Lambda = \\frac{\\pi}{\\epsilon}\\right) \\, ,\n\\end{equation}\nwhere $E^\\dispersion$ are the finite volume energy levels, which depend on the employed discretization scheme and on the contact interaction of strength $c^\\dispersion$.\nThe finite volume sum $I_{3, \\FV}^{(n_s)}(p, \\pi/\\epsilon)$ is obtained by replacing the integral $d^3 \\vec q$ in $I_3^{(n_s)}(p, \\Lambda)$ with a sum  over vectors $\\vec q = 2 \\pi \\vec n / L$.\nBecause the above equation is true for any value of $c^\\dispersion$ and its corresponding spectrum, it is especially true for $c^\\dispersion = C_R^{(n_s)}(\\Lambda)$.\nThis means that\n\\begin{equation}\n\t- \\frac{1}{a_3}\n\t=\n\t\\frac{2 \\pi}{\\mu}\n\t\t\\left[\n\t\tI_{3, \\FV}^{(n_s)}\\left(\\sqrt{2 \\mu E_i}, \\frac{\\pi}{\\epsilon}\\right)\n\t\t- I_3^{(n_s)}\\left(0, \\frac{\\pi}{\\epsilon}\\right)\n\t\t\\right]\n\t\\, ,\n\\end{equation}\nwhich defines the dispersion zeta function\n\\begin{align}\\label{eq:dispersion-zeta-form}\n\t- \\frac{1}{a_3}\n\t=\n\t\\frac{1}{\\pi L}\n\tS^{\\dispersion}_3(x^\\dispersion)\n\t&=\\frac{1}{\\pi L}\\left(\\sum\\limits_{n \\in \\BZ}\\frac{1}{K_{nn}^{(n_s)} - x^\\dispersion} - \\mathcal{L}_3^{\\dispersion} \\frac{N}{2}\\right)\n\t\\, ,\n\t\\\\ \\label{eq:dispersion-zeta-contact}\n\t\\mathcal{L}_3^\\dispersion\n\t&=\n\t\\frac{2 \\pi^2 L}{\\mu}\n\tI_3^{(n_s)}\\left(0, \\Lambda = \\frac{\\pi}{\\epsilon}\\right)\n\t\\overset{n_s\\to\\infty}{\\longrightarrow} 15.348\n\t\\, .\n\\end{align}\nSee \\Secref{dispersion-counterterm} for the computation of this coefficient.\nEquation \\eqref{dispersion-zeta-form} explains why results directly match the continuum infinite volume phase shifts when computed with this modified zeta function.\nNote that this result does not hold for general finite-range interactions if it is not possible to make an equivalent choice as in \\eqref{dispersion-renormalization}.\nWe stress that this derivation uses the analytic  expression for the $T$-matrix and simplifies drastically because the phase shifts for a renormalized contact interaction are momentum independent.\nThis momentum independence had the consequence that the counter term in \\eqref{dispersion-zeta-contact} is momentum independent as well.\n\n\\subsection{Two dimensions}\n\nIn two dimensions the analog of~\\eqref{blah blah} is\n\\begin{equation}\n\\cot \\delta_2(p) - i =\\lim_{\\Lambda\\to\\infty}\\frac{2}{\\mu}\\left(\\frac{1}{C(\\Lambda)}- I_2(p, \\Lambda)\\right)\\ , %\\frac{1}{2\\pi}\\mathcal{P}\\int_0^\\Lambda  \\mathrm { d } q \\ q \\left( \\frac { 1 } { E - \\frac{\\vec{q}^2}{m} } \\right)\\right)\\ ,\n\\end{equation}\nwith\n\\begin{equation}\nI_2(p, \\Lambda)\n=\n-\\frac{\\mu}{\\pi } \\log \\left(\\frac{p}{\\sqrt{\\Lambda ^2-p^2}}\\right)\n+ i\\frac{\\mu }{2}\n\\ .\n\\end{equation}\nOur renormalized coefficient is defined by using the phase shift condition for a contact interaction in 2-D~\\eqref{2d contact phase shift} in the $\\Lambda\\to\\infty$ limit,\n\\begin{equation}\\label{eq:log stuff}\n\t\\frac{2}{\\mu}\\frac{1}{C_R(\\Lambda)} + \\frac{2}{\\pi } \\log \\left(\\frac{p}{\\Lambda}\\right)\n\t=\n\t\\frac { 2 } { \\pi } \\log \\left( p \\tilde a _ { 2 } \\right)\\ ,\n\\end{equation}\nwhich ensures the renormalized contact strength $C_R(\\Lambda)$ is momentum independent.\nWith the kinetic operator for a given lattice spacing and discretization, we again define a sequence in $n_s$ which converges against $I_2$ in the limit of $n_s \\to \\infty$,\n\\begin{equation}\n\t\\lim\\limits_{n_s \\to \\infty} I^{(n_s)}_2(p, \\Lambda) = I_2(p, \\Lambda)\n\t\\, , \\qquad\n\tI^{(n_s)}_2\\left(p, \\Lambda=\\frac{\\pi}{\\epsilon} \\right)\n\t=\n\t    \\int\\limits_{-\\pi/\\epsilon}^{+\\pi/\\epsilon}\n        \\mathrm{d}^2 \\vec{q}\n        \\left[\n            \\PV \\left(\n                \\frac{1}{\n                    E - \\frac{1}{2\\mu} K_{qq}^{(n_s)} }\n                \\right)\n            -i \\pi \\delta\\left(E - \\frac{1}{2\\mu}K_{qq}^{(n_s)}\\right)\n        \\right]\n        \\, .\n\\end{equation}\nAs was done prior to~\\eqref{dispersion-renormalization}, we also define a sequence for the discrete coefficient $C^{(n_s)}_R(\\Lambda)$ that is determined by matching against the dispersion integral for each value of the cutoff and for each discretization scheme.  However, in this case, due to the presence of logarithms in~\\eqref{log stuff}, we first subtract the expression $\\frac{2}{\\pi}\\log(pL/2\\pi)$ prior to setting $p=0$,\n\\begin{equation}\n%\t\\lim\\limits_{n_s \\to \\infty} C^{(n_s)}_R(\\Lambda) = C_R(\\Lambda) \\, ,\n%\t\\quad\n\t\\lim\\limits_{p\\to 0}\n\t\\left[\n\t\t\\frac { 2 } { \\pi } \\log \\left( p \\tilde a _ { 2 } \\right)-\\frac{2}{\\pi } \\log \\left(\\frac{pL}{2\\pi}\\right)\n\t\\right]\n\t=\n\t\\frac { 2 } { \\pi } \\log \\left(2\\pi \\frac{\\tilde a _ { 2 }}{L} \\right)\n\t\\equiv\n\t\\frac{2 \\pi}{\\mu}\n\t\t\\left[\n\t\t\\frac{1}{C_R^{(n_s)}(\\Lambda)} - \\left.\\left(I_2^{(n_s)}(p, \\Lambda) - i\\frac{\\mu}{2}+\\frac{\\mu}{\\pi^2} \\log \\left(\\frac{pL}{2\\pi}\\right)\\right)\\right|_{p=0}\n\t\t\\right]\n\t\\, .\n\\end{equation}\nOur sequence $\\lim_{n_s\\to\\infty}C^{(n_s)}_R(\\Lambda) = C_R(\\Lambda)$ is well defined but implicitly depends on an external length scale $L$ due to the presence of the logarithm.  To arrive at the dispersion equation in two dimensions one repeats the steps from~\\eqref{schroe} leading up to~\\eqref{dispersion-zeta-form}, but now~\\eqref{dispersion-zeta-form} becomes\n\\begin{equation}\n    \\frac{2}{\\pi} \\log \\left(\\frac{2\\pi \\tilde a_{2}}{L}\\right)=\\frac{1}{\\pi^2}S^{\\dispersion}_2\\left(x^\\dispersion\\right)\n    =\n    \\frac{1}{\\pi^2}\n    \\left(\n        \\sum_{n\\in\\operatorname{B.Z.}}\\frac{1}{\\tilde{K}^N_{nn}-x^\\dispersion}\n        -2\\pi \\log \\left(\\mathcal{L}^\\dispersion_2\\frac{N}{2}\\right)\n    \\right)\\ .\n\\end{equation}\nHere\n\\begin{equation}\n    \\mathcal{L}^\\dispersion_{2}\n    =\n    \\exp \\left(\\log (2)-G \\frac{2}{\\pi}\\right)\n    =\n    1.116306393581637659468497 \\ldots\n\\end{equation}\nand $G$ is Catalan's constant.  We derive this counterterm in \\ref{sec:dispersion-counterterm}.  The renormalized coefficient in this case is\n\\begin{equation}\\label{eq:C2-dispersion}\nC^{(n_s)}_R(\\Lambda)=-\\frac{ \\pi}{\\mu \\log \\left(\\tilde a_{2} \\counterterm^\\dispersion_2\\Lambda\\right)}\\ ,\n\\end{equation}\nwhere now the coefficient $\\counterterm_2^\\dispersion$ carries a $n_s$ dependence.\n", "meta": {"hexsha": "c0c6a628971dba7cc1d659c82146d8e48305c03e", "size": 11193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/appendix/three-d.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/appendix/three-d.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/appendix/three-d.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": 49.5265486726, "max_line_length": 428, "alphanum_fraction": 0.6822120968, "num_tokens": 3737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6690530448515228}}
{"text": "%begin-include\n\n\\section{Predicate logic}\n\n\\begin{definition}\nLet $L = (\\Sigma, T, F)$ be a first-order language and $\\xi\\subseteq F$ a collection of formulas.\nThe first order system $\\mathsf{H}$ on the language $L$ defined by the \\emph{non-logical axioms} $\\xi$ is the formal system $\\mathsf{H} = (L,\\Xi,R)$ where $\\Xi$ and $R$ are defined as follows.\n\nThe set of axioms $\\Xi$ consists of $\\xi$ and all the axioms defined by the schemata \\ref{axp1}, \\ref{axp2} and \\ref{axp3} in addition to the following.\n\\begin{axioms}[Q]\n\\item \\label{axq1} If $A$ is a formula, $x_i$ a variable and $t$ a term not containing any variables quantified in $A$, then $((\\forall x_i) A \\limplies A(x_i\\Vert t))$.\nThe formula $A$ may or may not contain occurrences of $x_i$.\nWhen we use $A(x_i\\Vert t)$, we refer to the formula obtained by replacing every occurrence of $x_i$ in $A$, should there be any, by $t$.\n\\item \\label{axq2} If $A$ and $B$ are formulas, $x_i$ is a variable and $A$ does not contain $x_i$ as a free variable, then $((\\forall x_i)(A\\limplies B)\\limplies (A\\limplies (\\forall x_i) B))$.\n\\end{axioms}\n\nThe set $R$ of rules of inference contains modus ponens (which we have already studied) and the rule of \\emph{generalisation}. The rule of generalisation states that, for any formula $A\\in F$ and any variable $x_i\\in T$, $A\\vdash (\\forall x_i) A$.\n\nThe formal system $\\mathsf{Q}$ of first-order logic is the first-order system on the language $L_Q$ defined in \\ref{lfo}\\ref{lq} with an empty set of non-logical axioms.\n\\end{definition}\n\n\\begin{para}\nThere are some important remarks that need to be made about the definition I have just given you. The first of them concerns the purpose of the generalisation rule.\nWhen we work in first-order logic, we are only concerned with closed formulas (sentences), so the generalisation rule fixes the oddity of free variables by saying ``hey, is there a free variable in this formula? Well, that is the same as saying that the formula holds for every possible value this variable can take''.\n\nYou see, when setting out the axioms for a first order-system, we could have done so in such a way that no axioms would contain free variables.\nNevertheless, that would not have stopped anyone from trying to make deductions from non-closed formulas.\nHence, the only way to prevent the appearance of free variables in our variables would have been to define first order languages in such a way that all its formulas were closed.\nDoing so in a proper, inductive way is --- as far as I know --- unnecessarily complicated.\nFurthermore, we would be losing a lot of expressive power.\nYou know, sometimes free variables have their place!\nMaybe not as theorems of a formal system, but would you dare say that, if we were considering a first-order language of set theory, the formula $x = \\emptyset$ is not a formula? That does not seem right.\nSo, instead of doing weird things when defining our language, the most simple thing to do is to introduce the generalisation rule.\n\nLet us now see the generalisation rule in action with a simple example.\nNotice how, when combined with \\ref{axq1} and MP, it allows us to deduce, for any given formula $A$ dependent on a variable $x_i$, that $A\\vdash A(x_i\\Vert x_j)$. This enables us to relabel our variables in our formulas freely, which is a pretty good deal.\n\nWith that sorted, there is a part of the definition that might have created some confusion.\nUnless you paid close attention to \\ref[prel]{notaquan}, you might be having issues understanding how \\ref{axq1} and \\ref{axq2} are parenthesised.\nIn \\ref{axq1}, the scope of the first quantifier is only $A$, whereas, in \\ref{axq2}, the scope of the first quantifier is $(A\\limplies B)$ and the scope of the second is $B$.\n\nIf this has not been enough for you to fully understand what is going on, I invite you to revisit \\ref[prel]{notaquan} and take things a little bit more slowly!\n\\end{para}\n\n\\begin{example}\n\\label{exfofs}\n\\begin{parlist}\n\\item A very interesting kind of first-order system is that of first-order systems with equality. These systems use the first-order language associated to any set of symbols containing $\\{=\\}$ with signature $\\sigma(=) = -2$; in other words, it uses any language incorporating one additional symbol representing a 2-ary predicate. Instead of writing ${=}(x,y)$, it is customary to use infix notation and write $x=y$.\n\nThe set of non-logical axioms of these formal systems contains the following formulas and schemata.\n\\begin{axioms}[E]\n\\item $(\\forall x)\\qsep x = x$. \\label{axe1}\n\\item $(\\forall x)(\\forall y)\\qsep x = y \\limplies y = x$. \\label{axe2}\n\\item If $f$ is an $n$-ary function symbol and $t_1,\\ldots t_n$ are terms, $(\\forall x)(\\forall y)\\qsep x = y \\limplies f(t_1,\\ldots,x,\\ldots,t_n) = f(t_1,\\ldots,y,\\ldots,t_n)$. \\label{axe3}\n\\item If $P$ is an $n$-ary predicate symbol and $t_1,\\ldots,t_n$ are terms, $(\\forall x)(\\forall y)\\qsep x = y \\limplies (P(t_1,\\ldots,x,\\ldots,t_n) \\limplies P(t_1,\\ldots,y,\\ldots,t_n))$. \\label{axe4}\n\\end{axioms}\nOnly \\ref{axe3} and \\ref{axe4} are axiom schemata. The remaining items are axioms.\n\n\\item \\label{fspa} The standard first-order formalisation of arithmetic is known as Peano Arithmetic. The formal system $\\mathsf{PA}$ of Peano Arithmetic uses the first-order language of arithmetic defined in \\ref{lfo}\\ref{lpa}. It is a formal system using first-order logic with equality and --- in addition to \\ref{axe1}, \\ref{axe2}, \\ref{axe3} and \\ref{axe4} --- its non-logical axioms are:\n\\begin{axioms}[PA]\n\\item \\label{axpa1} $(\\forall x)\\qsep\\lnot(s(x) = 1)$.\n\\item \\label{axpa1bis} $(\\forall x,y)\\qsep s(x) = s(y) \\limplies x = y$.\n\\item \\label{axpa2} $(\\forall x)\\qsep x + 1 = s(x)$.\n\\item \\label{axpa3} $(\\forall x,y)\\qsep x + s(y) = s(x+y)$.\n\\item \\label{axpa4} $(\\forall x)\\qsep x \\cdot 1 = x$.\n\\item \\label{axpa5} $(\\forall x,y)\\qsep x \\cdot s(y) = x\\cdot y + x$.\n\\item \\label{axpa6} If $A\\in F$ has a free variable $x$, $(A(x\\Vert0) \\land (\\forall x) (A \\limplies A(x\\Vert s(x)))) \\limplies (\\forall x) A$. \n\\end{axioms}\nAxiom \\ref{axpa1} simply states that, within the theory of arithmetic, $1$ cannot be the successor of any number.\nAxiom \\ref{axpa1bis} establishes that two numbers are equal whenever the numbers succeeding them are equal.\nAxioms \\ref{axpa2} and \\ref{axpa3} define addition, and \\ref{axpa4} and \\ref{axpa5} define multiplication. Finally, the axiom schema \\ref{axpa6} formalises the principle of induction.\n\nWhen I first studied this, the axiom schema of induction made me feel suspicious. It kind of looks like a second-order axiom, doesn't it? It seems like we are quantifying over all the predicates! Isn't that cheating? Well, no. There is a second-order formalisation of Peano Arithmetic that, instead of using this axiom schema, uses a proper quantification over all the possible predicates, and the consequences of that seemingly innocent difference are very significant. \nWe will come back to this later.\n\\end{parlist}\n\\end{example}\n\n\\begin{definition}\nLet $S$ be a collection of symbols together with a signature function $\\sigma$.\nLet $L = (\\Sigma, T, F)$ be the first-order language associated to $(S,\\sigma)$.\nAn interpretation $I$ of $L$ is the assignment of a set $D_I$ as the \\emph{domain} of the interpretation together with an \\emph{interpretation function} $\\iota_I$ mapping every $c\\in S$ with $\\sigma(c) = 0$ to an element $\\iota_I(c) \\in D$, every $f\\in S$ with $\\sigma(c) = n > 0$ to an $n$-ary function $\\iota_I(f):D\\times\\cdots\\times D \\longrightarrow D$, and every $P \\in S $ with $\\sigma(P) = -n < 0$ to an $n$-ary predicate $\\iota_I(P)$ taking values in $D$.\nInstead of writing $\\iota_I(c)$, $\\iota_I(f)$ and $\\iota_I(P)$, we will often use $\\und{c}$, $\\und{f}$ and $\\und{P}$, provided there is no room for ambiguity, in order to make our notation more clear.\n\nTo put it in less formal terms, an interpretation is nothing more than the definition of a domain (in which the variables of the languages are meant to take values) and an assignment of constants in that domain to the constant symbols of the language, of $n$-ary predicates taking arguments in the domain to each $n$-ary predicate symbol of the language, and of $n$-ary functions taking arguments in values in $S$ to every $n$-ary function symbol of the language.\n\nLet us then consider an arbitrary interpretation $I$ on $L$. An \\emph{assignment of values} (\\emph{assignment}, for short)  is any function $\\alpha : \\{x_1,\\ldots, x_n,\\ldots\\} \\longrightarrow D_I$ that can be extended to a function $\\tilde{\\alpha}:T\\longrightarrow D_I$ by defining, for every $n$-ary function letter $f\\in S$,\n\\[\\tilde{\\alpha}(f(x_1,\\ldots,x_n)) = \\und{f}\\left( \\tilde{\\alpha}(x_1),\\ldots,\\tilde{\\alpha}(x_n) \\right). \\]\nEach of these assignments induces a valuation function $v_\\alpha:F\\longrightarrow\\{0,1\\}$ defined by the following inductive rules:\n\\begin{enumerate}\n\\item If $P\\in S$ is an $n$-ary predicate letter and $t_1,\\ldots,t_n \\in T$, then $v_\\alpha(P(t_1,\\ldots,t_n)) = 1$ if and only if the predicate $\\und{P}$ holds for $(\\tilde{\\alpha}(t_1),\\ldots,\\tilde{\\alpha}(t_n))$.\n\\item If $A,B\\in F$, then $v_\\alpha(A\\limplies B) = 0$ if and only if $v_\\alpha(A) = 1$ and $v_\\alpha(B) = 0$.\n\\item If $A \\in F$, then $v_\\alpha(\\lnot A) = 1$ if and only if $v_\\alpha(A) = 0$.\n\\item If $A\\in F$, then $v_\\alpha((\\forall x_i) A) = 1$ if and only if, for every assignment $\\alpha'$ verifying $\\alpha'(x_j) = \\alpha(x_j)$ for every index $j\\neq i$, $v_{\\alpha'}(A) = 1$.\n\\end{enumerate}\nIf, given a formula $A\\in F$, $v_\\alpha(A) = 1$, it is said that the assignment $\\alpha$ \\emph{satisfies} the formula $A$.\nInformally speaking, the only purpose of assignments is, as their name suggests, assigning a value to the variables in the formulas.\nA formula is true in an interpretation $I$ if and only if it is satisfied by every assignment in $I$.\nAnalogously, a formula is false in $I$ if and only if it is not satisfied by any assignment in $I$. \n\nTwo interpretations $I$ and $J$ of a language $L$ are said to be \\emph{isomorphic} if they are equal up to a relabelling of the elements of their domains.\nTo put it in formal terms, they are said to be isomorphic if there exists a bijective function $\\theta: D_I \\longrightarrow D_J$ verifying, for every constant symbol $c\\in S$, $\\iota_J(c) = \\theta(\\iota_I(c))$; for every $n$-ary function symbol $f$,\n\\[\\iota_I(f):(x_1,\\ldots,x_n)\\longmapsto \\theta^{-1}(\\iota_J(f)(\\theta(x),\\ldots,\\theta(x_n)),\\]\nand, for every $n$-ary predicate letter $P$, $\\iota_I(P)(x_1,\\ldots,x_n)$ if and only if $\\iota_J(P)(\\theta(x_1),\\ldots,\\theta(x_n))$. \n\nGiven a first-order system $\\mathsf{H}$ over a first-order language $L$, an interpretation $I$ of $L$ is said to be a \\emph{model} of $\\mathsf{H}$ if all the axioms of $\\mathsf{H}$ are true in $I$.\nSome first-order languages and systems are built with a particular model in mind; these models are known as the \\emph{intended interpretations} or \\emph{standard models}.\nAny model of a formal system that is non-isomorphic to the intended interpretation is said to be a \\emph{non-standard model}.\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{example}\nThe intended interpretation $\\mathcal{N}$ of the first-order language of arithmetic defined in \\ref{lfo}\\ref{lpa} is defined by taking the set of natural numbers $\\mathbb{N}$ as the domain of discourse and by making the following assignments:\n\\begin{itemize}\n\\item The constant $\\und{1}$ is the number $1\\in \\mathbb{N}$.\n\\item The predicate $\\und{=}$ is the binary predicate that is true if and only if its two arguments are the same number.\n\\item The function $\\und{s}$ is the function taking every $x\\in \\mathbb{N}$ to $x+1\\in\\mathbb{N}$.\n\\item The function $\\und{+}$ is the function taking every $x,y\\in \\mathbb{N}$ to $x+y\\in\\mathbb{N}$.\n\\item The function $\\und{\\cdot}$ is the function taking every $x,y\\in \\mathbb{N}$ to $x\\cdot y \\in \\mathbb{N}$.\n\\end{itemize}\nIt should be obvious that $\\mathcal{N}$ is a model of $\\mathsf{PA}$.\n\nThe formula $(x+1) + 1= s(x) + 1$ is true in $\\mathcal{N}$ because, regardless of the value that $x$ is given in any assignment $\\alpha$, the formula is satisfied; given any $n\\in \\mathbb{N}$, it is true that $(n+1) + 1 = (n+1) + 1$. Notice how this last expression is not meant to be a formula of the formal language, but a ``real'' (semantic) statement about $\\mathbb{N}$.\nA formula in a formal language is a meaningless sequence of symbols. But what we have written is just a representation, with the usual notation of arithmetic, of $(n\\und{+}\\und{1})\\und{+}\\und{1} = \\und{s}(n)+\\und{1}$, which in turn represents the statement ``adding one to $n$ plus one is the same as adding one to the number that goes after $n$''.\nAnalogously, it is easy to see how the formula $(x+1) = x$ is false in $\\mathcal{N}$. Now, let us consider the formula $x = 1$. Is it true? Certainly not! It suffices to consider any assignment $\\alpha$ with $\\alpha(x) \\neq 1$.\nNevertheless, it is not false either, for it is satisfied by any assignment $\\alpha$ with $\\alpha(x) = 1$. \n\nLet us now define a model isomorphic to $\\mathcal{N}$. We just need to consider the interpretation $\\mathcal{N}'$ obtained by\n\\begin{itemize}\n\\item using $\\mathbb{N}'=\\{1',2',3',\\ldots\\}$ instead of $\\mathbb{N}$;\n\\item using the constant $1'$ instead of $1$;\n\\item using the functions $x'+' y' = (x+y)'$ instead of $+$, and  $x'\\cdot' y' = (x\\cdot y)'$ instead of $\\cdot$,\n\\item and using the relation $x' =' y'$ defined to be true if and only if $x = y$ instead of using the relation $=$.\n\\end{itemize}\n\nTo conclude this example, there is one question that we need to answer: are there any non-standard models of Peano Arithmetic? Yes, there are.\nNonetheless, getting to those models truly goes beyond the scope of this book.\n\nThe only way to have a formal system of arithmetic without non-standard models is to use second-order logic: and that is because of the axiom schema we discussed before!\nYou see, the axiom schema we used when defining $\\mathsf{PA}$ is much weaker than a quantification over all the possible predicates, for it only takes into consideration the predicates that can be defined within the language of arithmetic, and those predicates need to be formulated with a finite combination of symbols!\nThus, there is an infinite amount of predicates that the formulas of our language cannot capture.\n\nYou may then wonder, why don't we study second-order logic?\nWell, second-order logic has its oddities too, and, as we will later see in our study of set theory, first-order logic will suffice to define a formal system able to ``contain'' all mathematics (and, yes, that \\emph{kind of} includes second-order arithmetic).\n\\end{example}\n\n\n\\begin{theorem}[First-order deduction theorem]\n\\label{dedthmfol}\nLet $\\mathsf{H}$ be a first-order formal system over a first-order language $L = (\\Sigma,T,F)$ with a set of axioms $\\Xi$.\nFor any collection of formulas $\\Gamma\\subseteq F$, any \\emph{closed} formula $A\\in F$ and any formula $B\\in F$, if one can deduce $\\Gamma\\cup\\{A\\}\\vdash_{\\mathsf{H}} B$, then $\\Gamma \\vdash_\\mathsf{H} (A\\limplies B)$. \n\nConversely, even if $A$ is not closed, if $\\Gamma \\vdash_\\mathsf{H} (A\\limplies B)$, then $\\Gamma\\cup\\{A\\}\\vdash_{\\mathsf{H}} B$.\n\\label{}\n\\end{theorem}\n\n\\begin{proof}\nThe reasoning followed in \\ref{dedthmprop} to show that $\\Gamma\\cup\\{A\\} \\vdash B$ implies $\\Gamma\\vdash (A\\limplies B)$ is perfectly valid for first-order systems. We just need to extend it in order to take into consideration the generalisation rule.\n\nProceeding by induction as in \\ref{dedthmprop}, let us then assume that $B$ has been obtained by an application of the generalisation rule on a formula $X$ such that, according to our inductive hypothesis, $\\Gamma \\vdash (A\\limplies X)$. We will assume that, for a certain variable $x_i$, $B$ is of the form $(\\forall x_i) X$.\nIn order to show that $\\Gamma \\vdash  (A \\limplies B)$, we just need to consider the following deduction from $\\Gamma$.\n\\begin{deduction}{dedthmfol1}\n\\dstep[h1]{By hypothesis, can be deduced from $\\Gamma$}{A\\limplies X,}\n\\dstep[s1]{Generalisation on \\dref{h1}}{(\\forall x_i) (A\\limplies X),}\n\\dstep[h2]{\\ref{axq2}}{(\\forall x_i)(A\\limplies X) \\limplies (A\\limplies (\\forall x_i) X),}\n\\dstep{MP on \\dref{h1}, \\dref{h2}}{A \\limplies (\\forall x_i) X.}\n\\end{deduction}\n\nThe proof of the converse is completely analogous to that of \\ref{dedthmprop}.\nFurthermore, as we pointed out in the statement of the theorem, for the converse to be true, $A$ need not be closed.\n\\end{proof}\n\n\\begin{para}\nLet $A\\in F_P$ be any tautology of propositional logic. Given any first-order language $L$, any first-order formula obtained by replacing the propositional symbols in $A$ by formulas of $L$ is also said to be a tautology in $L$.\n\nFor instance, we know $A\\limplies A \\in F_P$ to be a tautology. Thus, the formula $(\\forall x_1) P_1^1(x_1) \\limplies (\\forall x_1)P^1_1(x_1)$ is a tautology in $L_Q$.\n\\end{para}\n\n\\begin{proposition}\n\\label{fotaupro}\nLet $\\mathsf{H}$ be an arbitrary first-order system defined on a first-order language $L = (\\Sigma, T, F)$.\n\\begin{statements}\n\\item \\label{fotauthm} Any tautology in $L$ is a theorem of $\\mathsf{H}$.\n\\item \\label{tauval} Any tautology in $L$ is a valid formula.\n\\end{statements}\n\\label{tautovalid}\n\\end{proposition}\n\n\\begin{proof}\n\\begin{parlist}\n\\item Let ${A}$ be a tautology in propositional logic and let $A'\\in F$ be the first-order tautology obtained by substituting the propositional symbols of $A$ by formulas in $L$.\nAs $\\mathsf{P}$ is semantically complete, $\\vdash_{\\mathsf{P}}{A}$ and, therefore, we there know to exist a proof $({A}_1,\\ldots,{A}_n)$ in $\\mathsf{P}$ with ${A}_n = {A}$.\nWe can then consistently substitute all the propositional symbols in the proof by their corresponding formulas in $L$ in such a way that $A_n' = A'$.\nThus, we are led to a proof of $A'$ in $\\mathsf{H}$ because the MP inference rule and the axiom schemata \\ref{axp1}, \\ref{axp2} and \\ref{axp3} are included in $\\mathsf{H}$ and, consequently, $\\vdash_{\\mathsf{H}}{A'}$. \n\n\\item As before, let $A \\in F_P$ be a tautology of propositional logic and let $A' \\in F$ be a first-order formula obtained by substituting the propositional symbols in $A$ by formulas in $L$.\nLet $B_1,\\ldots,B_n$ be those distinct formulas and, without loss of generality, let $p_1,\\ldots,p_n$ be the respective propositional symbols being substituted by them.\n\nBefore diving into the proof, let us extend our notation. For any formula $P\\in F_P$ using, exclusively, the propositional symbols $p_1,\\ldots,p_n$, we will denote by $P'$ the first-order formula in $L$ obtained by replacing every propositional symbol $p_k$ in $P$ by $B_k$.\n\nLet us consider an arbitrary interpretation $\\mathcal{I}$ of $L$. We need to show that, for any assignment of values $\\alpha$ in $\\mathcal{I}$, $v_\\alpha(A) = 1$. In order to achieve this, we will first prove that --- for any interpretation $i$ of propositional logic verifying, for any $k \\in \\{1,\\ldots,n\\}$, $v_i(p_k) = v_\\alpha(B_k)$ --- we have $v_\\alpha(A') = v_i(A)$, which will be equal to $1$, since $A$ is a tautology.\n\nWe will prove our claim by induction on the number of connectives $m$ in ${A}$. For the base case $m=0$, $A'$ will be $p_1$. Thus, by the definition of $i$, it is clear that $v_i(p_1) = v_\\alpha(B_1)$. \nLet us now assume our claim to hold for an arbitrary $m\\in\\mathbb{N} \\cup \\{0\\}$ and prove it for $m+1$.\nThere are three cases we need to consider: $A$ may be of the form $X\\limplies p_k$,  $p_k \\limplies X$ or $\\lnot X$ for some $k \\in \\{1,\\ldots,n\\}$ and for some $X\\in F_P$ having $m$ connectives.\nIn the first case we mentioned, we have a formula of the form $X\\limplies p_k$ with $v_i(X) = v_\\alpha(X')$ and $v_i(p_k) = v_\\alpha(B_k)$.\nBy the semantics of propositional and predicate logic, we know that both $v_\\alpha(X' \\limplies B_k)$ and $v_i(X\\limplies p_k)$ are $0$ if and only if $v_\\alpha(X') = v_i(X) = 0$ and $v_\\alpha(B_k) = v_i(p_k) = 1$, and they are both $1$ otherwise.\nHence, they always have the same value. The proof for the second case is analogous. Lastly, the third case is trivial: if $v_i(X) = v_\\alpha(X')$, then $v_i(\\lnot X)$ and $v_\\alpha(X')$ will both be $0$ if and only if $v_i(X) = v_\\alpha(X') = 1$ and $1$ otherwise.\n\\end{parlist}\n\n\\end{proof}\n\n\n\\begin{para}\nLet $A\\in F_P$ be any contradiction of propositional logic. Given any first-order language $L$, any first-order formula obtained by replacing the propositional symbols in $A$ by formulas of $L$ is also said to be a contradiction in $L$.\nIt can be easily shown, in full analogy with the proof of \\ref{tautovalid}\\ref{tauval}, that any first-order contradiction is false under any interpretation. I will leave the details for you.\n\\end{para}\n\n\n\\begin{para}\nThe fact that any tautology in a first order system is both a theorem and a valid formula enables us to import effortlessly many results from propositional logic into predicate logic.\nIn the remainder of this section, we will present a bunch of those results referencing their analogues in our treatment of propositional logic.\nIf no proofs are given, it is because --- once \\ref{fotaupro} is taken into consideration --- they are practically identical to those provided in our study of propositional logic.\n\\end{para}\n\n\\begin{lemma}[Analogue of \\ref{cinr}]\nLet $\\mathsf{H}$ be a first-order system on a first-order language $L = (\\Sigma, T, F)$. Let $\\Gamma \\subseteq F$ and let $A$ and $B$ be two arbitrary formulas. One can deduce $\\Gamma\\vdash_{\\mathsf{H}} (A\\land B)$ if and only if one can deduce both $\\Gamma \\vdash_{\\mathsf{H}} A$ and $\\Gamma \\vdash_\\mathsf{H} B$.\n\\label{}\n\\end{lemma}\n\n\\begin{proposition}[Analogue of \\ref{piff}]\n\\label{foiff}\nLet $\\mathsf{H}$ be a first-order system on a first-order language $L$. Given any formulas $A$ and $B$ of $L$, $\\Gamma \\vdash_{\\mathsf{H}} (A \\liff B)$ if and only if $\\Gamma \\vdash_\\mathsf{H} (A\\limplies B)$ and $\\Gamma \\vdash_\\mathsf{H} (B\\limplies A)$.\n\nIn particular, if $\\Gamma = \\emptyset$, $A\\liff B$ is a theorem of $\\mathsf{H}$ if and only if so are $A\\limplies B$ and $B\\limplies A$.\n\\end{proposition}\n\n\\begin{proposition}[Principle of explosion. Analogue of \\ref{pexpprop}]\nIn an arbitrary first-order system $\\mathsf{H}$, anything can be deduced from a false premise: given any two formulas $A,B$ in its language, we have $A,\\lnot A \\vdash_{\\mathsf{H}} B$. \n\\label{fo-pexpl}\n\\end{proposition}\n\n\\begin{lemma}\nLet $\\mathsf{H}$ be a consistent first-order system with a set of non-logical axioms $\\xi$.\nIf $A$ is a closed formula that is not a theorem in $\\mathsf{H}$, the formal system $\\mathsf{H}^*$ obtained from $\\mathsf{H}$ by adding $\\lnot A$ as a non-logical axiom is consistent.\n\\label{notacons}\n\\end{lemma}\n\n\\begin{proof}\nLet us assume that $\\mathsf{H}^*$ is inconsistent and, therefore, that, for a formula $B\\in F$, both $B$ and $\\lnot B$ are theorems of $\\mathsf{H}^*$.\nFrom the principle of explosion \\ref{fo-pexpl}, it follows that $\\vdash_{\\mathsf{H}^*} A$.\nNevertheless, since $\\mathsf{H}^*$ is nothing more than $\\mathsf{H}$ with $\\lnot A$ as an additional axiom, any proof in $\\mathsf{H}^*$ is a deduction from $\\lnot A$ in $\\mathsf{H}$.\nTherefore, $\\lnot A \\vdash_\\mathsf{H} A$.\n\nBy hypothesis, $A$ is closed and so must be $\\lnot A$. Under these conditions, we can apply the deduction theorem to conclude that $\\vdash_{\\mathsf{H}} \\lnot A \\limplies A$. In addition, since the tautology $(\\lnot A \\limplies A)\\limplies A$ is a theorem of $\\mathsf{H}$, so an application of MP yields $\\vdash_{\\mathsf{H}} A$, which cannot be the case according to our hypotheses and proves that $\\mathsf{H}^*$ need be consistent.\n\\end{proof}\n\n\n\\begin{theorem}\n\\label{proph}\nLet $\\mathsf{H}$ be any first-order system on a first-order language $L = (\\Sigma,T,F)$. The following metatheorems are true.\n\\begin{statements}\n\\item \\label{haxtrue} Every instance of the axiom schemata \\ref{axp1}, \\ref{axp2}, \\ref{axp3}, \\ref{axq1} and \\ref{axq2} in $L$ is valid. Consequently, verifying the non-logial axioms of a first-order system is sufficient to show an interpretation to be a model.\n\\item \\label{hsound} Let $\\mathcal{M}$ be a model of $\\mathsf{H}$. If, given any collection of formulas $\\Gamma\\subseteq F$ and any formula $A\\in F$, it can be deduced that $\\Gamma\\vdash A$, then $\\mathcal{M}\\vDash \\Gamma$ implies $\\mathcal{M}\\vDash A$. In other words, if $\\Gamma\\vdash A$, any model in which all the formulas in $\\Gamma$ are true makes $A$ true too. If, in particular, we take $\\Gamma = \\emptyset$, this means that any theorem of $\\mathsf{H}$ is true in any model of $\\mathsf{H}$.\n\\item \\label{hcons} If $\\mathsf{H}$ has a model, it is consistent.\n\\item \\label{consmodel} If $\\mathsf{H}$ is consistent, it has a model.\n\\item \\label{hsemc} Any valid formula $A$ in $L$ is a theorem in $\\mathsf{H}$. In other words, any first-order system is semantically complete.\n\\end{statements}\n\\label{<+label+>}\n\\end{theorem}\n\n\\begin{proof}\n\\begin{parlist}\n\\item All instances of the axiom schemata \\ref{axp1}, \\ref{axp2} and \\ref{axp3} are, undoubtedly, tautologies; therefore, applying \\ref{fotaupro}\\ref{tauval}, we already known them to be valid formulas.\nLet us then focus on the axiom schemata \\ref{axq1} and \\ref{axq2} and show that all of their instances are valid.\nFor this purpose, we will consider an arbitrary interpretation $\\mathcal{I}$ of $L$ and an arbitrary assignment of values $\\alpha$ in $\\mathcal{I}$.\n\nLet us begin with \\ref{axq1}. Let $A\\in F$ be an arbitrary formula, $x_i\\in T$ be any variable and $t\\in T$ be any term containing no variables that are quantified in $A$.\nWe need to show that $v_\\alpha( (\\forall x_i) A \\limplies A(x_i\\Vert t)) = 1$.\nIf we had $v_\\alpha( (\\forall x_i) A \\limplies A(x_i\\Vert t)) = 0$, then, necessarily, $v_\\alpha( (\\forall x_i) A) = 1$ and $v_\\alpha ( A(x_i\\Vert t)) = 0$.\nNevertheless, the fact that $v_\\alpha( (\\forall x_i) A) = 1$ means that, for any valuation $\\alpha'$ with $\\alpha(x_j) = \\alpha'(x_j)$ for any $i\\neq j$, we have $v_{\\alpha'}(A) = 1$.\nWe will consider a particular $\\alpha'$ satisfying $\\alpha'(x_i) = t$ .\nSince none of the variables present in $t$ are quantified in $A$, it follows that $v_\\alpha(A(x_i\\Vert t)) = v_{\\alpha'}(A) = 1$. As it is impossible for $v_\\alpha(A(x_i\\Vert t))$ to be both $0$ and $1$, we can conclude that it is impossible for $v_\\alpha( (\\forall x_i) A \\limplies A(x_i\\Vert t) )$ to be $0$.\n\nLastly, let us analyse \\ref{axq2}. Let $A,B\\in F$ be any formulas and let $x_i$ be any variable not appearing free in $A$. Let us assume that\n\\[v_\\alpha( (\\forall x_i)(A\\limplies B) \\limplies (A\\limplies (\\forall x_i) B)) = 0.\\]\nIn this scenario, we have $v_\\alpha( (\\forall x_i) (A\\limplies B) ) = 1$ and $v_\\alpha(A\\limplies (\\forall x_i) B) = 0$ simultaneously. \nIf $v_\\alpha( (\\forall x_i) (A\\limplies B)) = 1$, then, for any assignment $\\alpha'$ with $\\alpha'(x_j) = \\alpha(x_j)$ for any $i\\neq j$, we have $v_{\\alpha'}( A \\limplies B) = 1$.\nSince $x_i$ does not appear as a free variable in $A$ and all such assignments $\\alpha'$ only differ in $\\alpha'(x_i)$, their valuations of $A$ are either all equal to $1$ or all equal to $0$.\nIf they were all equal to $0$, then, in particular, $v_\\alpha(A) = 0$, which would mean that $v_\\alpha(A\\limplies (\\forall x_i) B) = 1$, and that would contradict our hypothesis.\nThus, all those assignments $\\alpha'$ need to verify $\\alpha'(x_i) = 1$.\nNevertheless, since, $v_{\\alpha'}(A \\limplies B) = 1$, this means that $v_\\alpha'(B) = 1$ for any $\\alpha'$.\nIt is then immediate that $v_\\alpha( (\\forall x_i) B) = 1$ and, therefore, that $v_\\alpha( A\\limplies (\\forall x_i) B) = 1$, which, again, would contradict our initial assumptions.\nIt follows that, necessarily, $v_\\alpha( (\\forall x_i)(A\\limplies B) \\limplies (A\\limplies (\\forall x_i) B )) = 1$.\n\n\\item We proceed by induction on the length $n$ of the deduction $(A_1,\\ldots,A_n)$ with $A_n = A$ of $\\Gamma\\vdash A$.\nThe base case $n=1$ is trivial: if the deduction is $(A)$ then $A$ may be an axiom (which is, by definition, true in any model) or an element of $\\Gamma$ (which is, by hypothesis, true in $\\mathcal{M}$).\n\nLet us assume the result to be true for any natural number smaller than or equal to an arbitrary $n\\in \\mathbb{N}$ and let us prove it for $n+1$.\nIf we have a deduction with $n+1$ elements, $A$ may still be an axiom or an element of $\\Gamma$ (if that were the case, we have nothing to worry about), but it may also have been obtained by applying the MP rule or the generalisation rule on previous elements of the deduction.\nThese elements have deductions of length smaller than $n+1$ and, therefore, the inductive hypothesis applies to them.\n\nIf $A$ has been obtained by an application of MP to two formulas of the form $X$ and $X\\limplies A$ verifying $\\mathcal{M} \\vDash X$ and $\\mathcal{M} \\vDash X\\limplies A$, is $A$ true in $\\mathcal{M}$? We know that any assignment of values $\\alpha$ verifies $v_\\alpha(B) = 1$ and $v_\\alpha(B\\limplies A) = 1$. That can only mean that $v_\\alpha(A) = 1$ for any assignment $\\alpha$ and, therefore, that $\\mathcal{M}\\vDash A$.\n\nIf, on the other hand, $A$ is a formula of the form $(\\forall x_i) X$ and has been obtained by an application of the rule of generalisation to $X$ with $\\mathcal{M}\\vDash X$, is $A$ true in $\\mathcal{M}$?\nAny assignment $\\alpha$ verifies $v_\\alpha(X) = 1$ and, for $(\\forall x_i) X$ to be true, we need to have $v_\\alpha( (\\forall x_i) X) = 1$ for any assignment $\\alpha$.\nLet us consider an arbitrary assignment $\\alpha$ and show it.\nBy definition, $v_\\alpha( (\\forall x_i) X ) = 1$ if and only if, for every assignment $\\alpha'$ with $\\alpha'(x_j) = \\alpha(x_j)$ for $j \\neq i$, we have $v_{\\alpha'}(X) = 1$. Is that the case? Of course it is\\ldots didn't we have $\\mathcal{M}\\vDash X$?\n\nBy the principle of mathematical induction, the proof is complete.\n\n\\item According to \\ref{hsound}, any theorem in $\\mathsf{H}$ needs to be true in $\\mathcal{M}$. Thus, if $A$ is a theorem, every assignment $\\alpha$ verifies $v_\\alpha(A) = 1$ and, consequently, $v_\\alpha(\\lnot A) = 0$, so $\\lnot A$ is false in $\\mathcal{M}$ and cannot be a theorem of $\\mathsf{H}$.\n\n\\item This is an important result, but the proof is pretty lengthy and technical.\nIf you are curious about the proof and want to go through it, check out \\ref[appendix]{foconmodel} in the appendices.\n\n\\item Let $A\\in F$ be a valid formula and let us assume that $\\not\\vdash_{\\mathsf{H}} A$ and that $\\mathsf{H}$ is consistent.\nAccording to \\ref{notacons}, the formal system $\\mathsf{H}^*$ obtained by adding the axiom $\\lnot A$ to $\\mathsf{H}$ is consistent.\nApplying \\ref{consmodel}, we know $\\mathsf{H}^*$ to have a model $\\mathcal{M}$, and, by the very definition of model, $\\mathcal{M} \\vDash \\lnot A$, which means that $A$ will be false in $\\mathcal{M}$.\nNonetheless, that is impossible for, by hypothesis, $A$ is valid and, therefore, true in every interpretation.\nConsequently, every valid formula is, necessarily, a theorem in $\\mathsf{H}$.\n\nIf $\\mathsf{H}$ is not consistent, any formula is a theorem by the explosion principle and the result is trivial.\n\\end{parlist}\n\\end{proof}\n\n\n\n\\begin{theorem}\nThe following metatheorems about the formal system of predicate logic are true:\n\\begin{statements}\n\\item All the theorems of $\\mathsf{Q}$ are valid formulas: $\\mathsf{Q}$ is sound.\n\\item The formal system $\\mathsf{Q}$ is consistent.\n\\end{statements}\n\\label{<+label+>}\n\\end{theorem}\n\n\\begin{proof}\n\\begin{parlist}\n\\item According to \\ref{proph}\\ref{haxtrue}, any interpretation is a model of $\\mathsf{Q}$. Moreover, applying \\ref{proph}\\ref{hsound}, any theorem of $\\mathsf{Q}$ must be true in every model of $\\mathsf{Q}$, i.e. in every interpretation. This means that every theorem of $\\mathsf{Q}$ is a valid formula.\n\\item We know, thanks to \\ref{proph}\\ref{haxtrue}, that $\\mathsf{Q}$ has a model (it can be any interpretation). Thus, the result is a direct consequence of \\ref{proph}\\ref{hcons}.\n\n\\end{parlist}\n\\end{proof}\n\n\n\n\\begin{lemma}[Analogue of \\ref{replacetautology}]\nLet $\\mathsf{H}$ be a first-order system on a language $L$. Let $A$, $X$ and $Y$ be formulas of $L$. If $X\\liff Y$ is a valid formula in $L$ and $A'$ denotes the formula resulting from replacing each appearance of $X$ in $A$ by $Y$, then $A\\liff A'$ is a valid formula and, by \\ref{proph}\\ref{hsemc}, a theorem in $\\mathsf{H}$.\n\\end{lemma}\n\n\\begin{para}\nIn \\ref{lpinformal}, we saw how the informal manipulations of propositional forms --- e.g., removing parentheses or swapping formulas around $\\land$ or $\\lor$ --- can be safely used in $\\mathsf{P}$.\nThat same reasoning should also be enough to convince you by now that those manipulations, together with the conventions set out in \\ref[prel]{hierarchy} and \\ref[prel]{notaquan}, can be used in any first-order system.\n\nIn addition, it should be clear that the informal use of the pseudo-quantifiers that were introduced in \\ref[prel]{pseudoquan} is perfectly safe in any first-order system accepting them.  \n\\end{para}\n\n\n\\begin{proposition}[Analogue of \\ref{impsystemp}]\nLet $\\mathsf{H}$ be a formal system on a language $L$. Let $A$, $B$, $A_1$, $A_2$, $B_1$ and $B_2$ be formulas of $L$ and $\\Gamma$ a set of formulas of $L$.\n\\begin{statements}\n\\item One can deduce $\\Gamma \\vdash_\\mathsf{H} (A \\limplies (B_1\\land B_2))$ if and only if one can deduce both $\\Gamma \\vdash_\\mathsf{H} (A\\limplies B_1)$ and $\\Gamma \\vdash_\\mathsf{H} (A\\limplies B_2)$. In particular, if $\\Gamma = \\emptyset$, $A\\limplies (B_1\\land B_2)$ is a theorem of $\\mathsf{H}$ if and only if so are $A\\limplies B_1$ and $A \\limplies B_2$.\n\n\\item One can deduce $\\Gamma \\vdash_\\mathsf{H} ( (A_1\\land A_2) \\limplies B_1 )$ if and only if one can deduce $\\Gamma \\vdash_\\mathsf{H} (A_1 \\limplies (A_2 \\limplies B))$ or $\\Gamma \\vdash_\\mathsf{H} (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\n\\begin{para}\nThe remarks that we made about the deduction theorem in \\ref{remarkdedp} are as valid for first-order closed formulas as they were for propositional forms. Nevertheless, they are not true for formulas with free variables.\n\nIn a first-order system, given two formulas $A$ and $B$, $A\\vdash B$ and $\\vdash A\\limplies B$ are not necessarily equivalent if $A$ is not closed.\nIf $A$ has free variables, the statement $\\vdash A \\limplies B$ is stronger than $A \\vdash B$; and, from a semantic perspective, it is obvious why this is the case.\n\nGoing back to \\ref{proph}\\ref{hsound}, we know that if $A\\vdash B$, then any model \\emph{making $A$ true} makes $B$ true.\nIf, instead, $\\vdash (A\\limplies B)$, we know that $A\\limplies B$ is true in \\emph{any} model of the system and, therefore, that --- in any model --- any assignment satisfying $A$ also satisfies $B$.\n\nFor example, in $\\mathsf{PA}$, the generalisation rule yields $x = 1 \\vdash (\\forall x)\\qsep x = 1$ while, clearly, $\\not\\vdash (x = 1 \\limplies (\\forall x)\\qsep x = 1)$. On the other hand, $\\vdash (x = 1 \\limplies s(x)  = s(1))$ and, consequently, $x = 1 \\vdash s(x) = s(1)$.\nYou see, saying that $A \\vdash B$ is the same as saying that $B$ is a theorem if we add $A$ as a general assumption (i.e., as an axiom of the formal system), whereas $\\vdash A \\limplies B$ means that, in our formal system, whenever $A$ is true, $B$ is true.\nDo you remember when I told you that removing formulas with free variables would make us lose expressive power? This is what I was talking about. \n\nIn mathematics, when working inside any first order system, it is extremely common to represent --- for any two formulas $A$ and $B$ --- the statement $\\vdash A\\limplies B$ as $A\\implies B$.\nBe aware that $A\\implies B$, unlike $A\\limplies B$, is a statement in the metalanguage.\nUsing $A\\implies B$ instead of $\\vdash A\\limplies B$ is so common that some mathematicians do not know what $\\vdash A \\limplies B$ means, so, unless you want to be frowned upon, always stick to $A\\implies B$ unless, of course, you are working on mathematical logic as we have been doing.\n\nIn full analogy, given any two formulas $A$ and $B$ in a first-order system, $A\\iff B$ is used to mean $\\vdash A\\liff B$. This, as with $\\implies$, is stronger a statement than saying both $A\\vdash B$ and $B\\vdash A$.\n\\end{para}\n\n\\begin{theorem}\nLet us consider an arbitrary first-order system.\n\\begin{statements}\n\\item Let $A$ and $B$ be any formulas. Proving that $A\\implies B$ is equivalent to proving the \\emph{contrapositive}: $\\lnot B \\implies \\lnot A$. \\label{contra}\n\\item Let $X$ be any formula and let $C$ be any contradiction.\nProving that $X$ is a theorem is equivalent to showing that $\\lnot X \\implies C$. In particular, if $X$ is of the form $A \\limplies B$, proving $A \\implies B$ is the same as showing\n\\[A \\land \\lnot B \\implies (A \\land \\lnot A),\\]\nwhere we have used the fact that $A \\land \\lnot B$ is equivalent to $\\lnot(A \\limplies B)$. The use of this technique is known as doing a \\emph{proof by contradiction}.\n\\end{statements}\nNotice how any proof that makes use of the contrapositive can be trivially transformed into a proof by contradiction, but not conversely.\n\\label{pftch}\n\\end{theorem}\n\n\\begin{proof}\n\\begin{parlist}\n\\item Let us assume that $A \\implies B$, this is, that $\\vdash A \\limplies B$.\nAs we know $(A\\limplies B) \\liff (\\lnot B \\limplies \\lnot A)$ to be a tautology and, therefore, a theorem in our formal system, a direct application of MP and \\ref{foiff} yields $\\vdash \\lnot B \\limplies \\lnot A$. The converse is analogous.\n\n\\item The proof of this statement is analogous to that of \\ref{contra} and relies on the fact that the formula\n$ X \\liff \\left( \\lnot X \\limplies C \\right)$\nis a tautology.\n\\end{parlist}\n\\end{proof}\n\n\\begin{para}\nAnd now, as we reach then end of the chapter, it is time for us to address the issue that we considered in \\ref{whybother} and discuss a deep topic: G\\\"odel's incompleteness theorem.\n\nNow that we leave our analysis of mathematical logic behind, we will begin working in the formal system of set theory that unifies all mathematics. What properties would we like that system to have?\nWe would certainly like it to be consistent and syntactically complete.\nIn other words, given any formula $A$, we want either $A$ or $\\lnot A$ to be a theorem because, whenever you have a property of set theory, you know that either it or its negation are true and, of course, you would like your system to be powerful enough to deduce the true one (and only the true one).\n\nIf you were a committed formalist and you believed that mathematics is just a game of symbols with some rules, you would also want the formal system to be able to prove its own consistency in order for everything to fit nicely.\nIn fact, were you not able to do that for basic arithmetic, all the work we have done would render meaningless for you because, in order to prove results about the formal system of propositional logic, we have been using some basic properties of the natural numbers and arithmetic.\nThus, from the point of view of a pure formalist, the only way to see what we have done as valid would be formalising our reasoning in a formal metatheory that would need to capture basic arithmetic and prove its own consistency.\n\nThere are some nice properties that we could also ask our formal system to have (like all their axioms' being independent), but that is insignificant when compared with the importance of what we have just discussed.\n\nNow, the question is: has anyone managed to do such a thing? Has anyone been able to prove the consistency of mathematics within mathematics? The answer is no, and that is for a very good reason\\ldots\n\\end{para}\n\n\\begin{theorem}[Kurt G\\\"odel]\nLet $\\mathsf{H}$ be any consistent formal system capturing elementary arithmetic.\n\\begin{statements}\n\\item The formal system $\\mathsf{H}$ is not syntactically complete.\n\\item The formal system $\\mathsf{H}$ cannot prove its own consistency. \n\\end{statements}\n\\label{<+label+>}\n\\end{theorem}\n\n\\begin{proof}\nThis one does go far beyond the scope of this book. Nonetheless, if you have the time for it --- depending on you level of understanding, it may take you a few days, --- I invite you to read G\\\"odel's original proof at some point. You can find it in \\cite{Godel}. It is a pretty illuminating experience.\n\\end{proof}\n\n\\begin{para}\nI should warn you that what follows is a personal, partially subjective remark. That theorem was\\ldots intense, wasn't it? If you are a formalist, please accept my condolences.\nJust as Russel's paradox sentenced logicism by showing that we cannot reduce mathematics to logic, G\\\"odel's theorem killed pure formalism by proving that no formal system is able to capture all mathematics or even formally prove its consistency. In other words: syntax is not enough; symbols are not enough; there is something else.\n\nNow does this mean that arithmetic may be inconsistent? \nFrom a purely formal point of view, yes.\nFrom a human point of view, of course not.\nWe, as humans, can see further beyond mere formalisations of theories, and, even if we cannot prove it formally, we know that Peano Arithmetic is consistent.\nWhy? Because we see arithmetic: the reality of arithmetic is one that we have already explored through our minds and know to exist and be consistent.\nThis fact cannot be captured formally, but that does not make it any less real.\n\nThis very same reasoning will also be applicable to the formalisation of set theory that we will soon introduce and that --- as we will see --- includes Peano Arithmetic and is thus affected by G\\\"odel's theorem.\n\nI am, of course, not trying to make a case for fully disregarding formalisation.\nOur minds are extremely fallible, and a formalist approach to mathematics is, to some extent, indispensable;\nfurthermore, there is a special beauty in exploring the inner workings of reason, and that can only be done in a formal framework.\nNevertheless, we should not forget that formalisation, in spite of its undoubted importance, is still a tool, not an end.\nThe art of mathematics goes far beyond the mere manipulation of symbols.\n\nI will leave it there. An in-depth treatment of these issues is more suitable for a philosophy book.\nIf you would like to get more insights on the philosophy of mathematics, I encourage you to read \\cite{Brown}.\n\\end{para}\n", "meta": {"hexsha": "4588a1ee95e945f5ad6f076d7f66bf6fa98fa8e3", "size": 42512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch1/sec3.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/sec3.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/sec3.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": 91.423655914, "max_line_length": 498, "alphanum_fraction": 0.7239838163, "num_tokens": 12565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768108626046, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6690530435662994}}
{"text": "\\section{Miscellaneous}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Hamiltonian path in Tournament graph}\n  \\begin{exampleblock}{Hamiltonian path in Tournament graph (Problem 6.22)}\n\t\\begin{align*}\n\t  \\forall u, v:\\; &(u \\to v \\lor v \\to u) \\\\\n\t  \t&\\land \\lnot (u \\to v \\land v \\to u)\n\t\\end{align*}\n  \\end{exampleblock}\n\n  \\vspace{0.60cm}\n  \\centerline{By mathematical induction on $n$.}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "c3cc7fb94a42c57cbc91d30905fc44aca965a17b", "size": 413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/alg-tutorial-paths-20170605/sections/misc.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/misc.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/misc.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.8125, "max_line_length": 75, "alphanum_fraction": 0.6004842615, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6690530291206909}}
{"text": "\\section{Diagonalization}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine when it is possible to diagonalize a matrix.\n  \\item When possible, diagonalize a matrix.\n  \\end{enumerate}\n\\end{outcome}\n", "meta": {"hexsha": "c0c4952d19e210801290ce351ce99d082f1ff1f3", "size": 203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryDiagonalization.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/spectraltheoryDiagonalization.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/spectraltheoryDiagonalization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 22.5555555556, "max_line_length": 62, "alphanum_fraction": 0.7536945813, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6690530162258675}}
{"text": "\\subsection{Univariate polynomials}\\label{subsec:univariate_polynomials}\n\nWe will discuss here the \\hyperref[def:polynomial_algebra]{polynomial ring} \\( R[X] \\) in one indeterminate over the nontrivial \\hyperref[def:ring/commutative]{commutative unital ring} \\( R \\). We call them \\term{univariate polynomials} using the general convention for function arguments from \\fullref{def:multi_valued_function/arguments}. \\Fullref{rem:polynomials_over_infinitely_many_indeterminates} discusses why we often focus only on finitely many indeterminates, and why the theory of univariate polynomials is often sufficient.\n\nPolynomials are not functions in general, and the exact relationship between polynomials and polynomial functions is discussed in \\fullref{thm:polynomial_algebra_universal_property} and \\fullref{thm:functions_over_prime_fields}.\n\n\\begin{definition}\\label{def:polynomial_degree}\n  The \\term{degree} of the nonzero univariate \\hyperref[def:polynomial_algebra]{monomial} \\( X^k \\) is its power \\( k \\). More generally, the degree of a multivariate monomial \\( \\prod_{X \\in \\mscrX} X^{\\gamma_X} \\) in the set of indeterminates \\( \\mscrX \\) is the \\hyperref[def:multi_index]{multi-index norm} \\( \\norm \\gamma = \\sum_{X \\in \\mscrX} \\gamma_X \\).\n\n  The degree \\( \\deg(p) \\) of a polynomial \\( p \\) is the maximal degree of its nonzero monomials. For the zero polynomial, we leave the degree undefined.\n\n  For a univariate polynomial\n  \\begin{equation*}\n    p(X) = \\sum_{k=0}^\\infty a_k X^k = a_0 + a_1 X + a_2 X^2 + a_3 X^3 + \\cdots,\n  \\end{equation*}\n  the degree \\( n \\coloneqq \\deg(p) \\) allows us to write\n  \\begin{equation*}\n    p(X) = \\sum_{k=0}^n a_k X^k = a_0 + a_1 X + a_2 X^2 + \\cdots + a_{n-1} X^{n-1} + a_n X^n.\n  \\end{equation*}\n\n  This notation also subsumes the zero polynomial. We call \\( a_n \\) the \\term{leading coefficient} and \\( a_0 \\) the \\term{constant coefficient} of the polynomial.\n\n  We introduce the following names for univariate polynomials of certain degrees:\n  \\begin{center}\n    \\begin{tabular}{l | l}\n      Constant  & \\( \\deg(p) = 0 \\) or \\( p \\) is the zero polynomial \\\\\n      Linear    & \\( \\deg(p) = 1 \\)                                   \\\\\n      Quadratic & \\( \\deg(p) = 2 \\)                                   \\\\\n      Cubic     & \\( \\deg(p) = 3 \\)                                   \\\\\n      Quartic   & \\( \\deg(p) = 4 \\)                                   \\\\\n      Quintic   & \\( \\deg(p) = 5 \\)\n    \\end{tabular}\n  \\end{center}\n\\end{definition}\n\n\\begin{definition}\\label{def:monic_polynomial}\n  We say that the nonzero univariate polynomial \\( p(X) \\) is \\term{monic} if its leading coefficient is \\( 1 \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:polynomial_degree}\n  The \\hyperref[def:polynomial_degree]{polynomial degree} has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:polynomial_degree/sum} For any two zero polynomials satisfying \\( p(X) \\neq -q(X) \\), we have\n    \\begin{equation}\\label{eq:thm:def:polynomial_degree/sum}\n      \\deg (p + q) \\leq \\max \\set{ \\deg p, \\deg q }.\n    \\end{equation}\n\n    \\thmitem{thm:def:polynomial_degree/product} For any two nonzero polynomials \\( p(X) \\) and \\( q(X) \\) whose leading coefficients do not multiply to zero, we have\n    \\begin{equation}\\label{eq:thm:def:polynomial_degree/product}\n      \\deg (pq) = \\deg p + \\deg q.\n    \\end{equation}\n\n    An easy sufficient condition for \\eqref{eq:thm:def:polynomial_degree/product} is for the ring to be \\hyperref[def:entire_semiring]{entire}, although it is also sufficient for the ring to be nontrivial (so that \\( 0_R \\neq 1_R \\)) and either \\( p(X) \\) or \\( q(X) \\) to be \\hyperref[def:monic_polynomial]{monic}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  Fix nonzero polynomials\n  \\begin{align*}\n    p(X) &\\coloneqq \\sum_{k=0}^n a_k X^k, \\\\\n    q(X) &\\coloneqq \\sum_{k=0}^m b_k X^k.\n  \\end{align*}\n\n  \\SubProofOf{thm:def:polynomial_degree/sum} Additionally assume that \\( p(X) \\neq -q(X) \\) since otherwise \\( p(X) + q(X) = 0 \\) and \\( \\deg(p + q) \\) is undefined. Thus, there exists at least one index \\( k = 1, 2, \\ldots \\), so that \\( a_k \\neq b_k \\). Denote by \\( k_0 \\) the largest such index (only finitely many are nonzero). Then\n  \\begin{equation*}\n    a_k = b_k = 0 \\T{for} k > k_0.\n  \\end{equation*}\n\n  Therefore, \\( \\deg(p + q) = k_0 \\). Note that \\( k_0 \\) cannot exceed both \\( \\deg p \\) and \\( \\deg q \\) because it corresponds to a nonzero coefficient. Thus, \\( k_0 \\leq \\max\\set{ \\deg p, \\deg q } \\).\n\n  \\SubProofOf{thm:def:polynomial_degree/product} The coefficient \\( c_{n + m} \\) of the product \\( p(X) q(X) \\) is \\( a_n b_m \\) by definition. By assumption, it is nonzero. Then, since \\( c_{n+m+1} = 0 \\), we have\n  \\begin{equation*}\n    \\deg (pq) = \\deg p + \\deg q.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{algorithm}[Euclidean division of polynomials]\\label{alg:euclidean_division_of_polynomials}\\mcite[prop. 1.12]{Knapp2016BasicAlgebra}\n  Fix two univariate polynomials \\( f(X) \\) and \\( g(X) \\), and assume that \\( g(X) \\) is \\hyperref[def:monic_polynomial]{monic}.\n\n  We will build polynomials \\( q(X) \\) and \\( r(X) \\), where \\( r(X) \\) is either zero or \\( \\deg r < \\deg g \\), such that\n  \\begin{equation*}\n    f(X) = g(X) q(X) + r(X).\n  \\end{equation*}\n\n  The algorithm only demonstrates existence; we will prove uniqueness right after it.\n\n  \\begin{thmenum}\n    \\thmitem{alg:euclidean_division_of_polynomials/zero_degree} If \\( \\deg f = \\deg g = 0 \\), necessarily \\( g(X) = 1_R \\), and in this case we define\n    \\begin{align*}\n      q(X) &\\coloneqq f(X), \\\\\n      r(X) &\\coloneqq 0_R.\n    \\end{align*}\n\n    \\thmitem{alg:euclidean_division_of_polynomials/no_division} If \\( f(X) \\) is the zero polynomial or \\( \\deg f < \\deg g \\), define\n    \\begin{align*}\n      q(X) &\\coloneqq 0_R, \\\\\n      r(X) &\\coloneqq f(X).\n    \\end{align*}\n\n    In this case, \\( r(X) \\) is either zero or \\( \\deg r = \\deg f < \\deg b \\).\n\n    \\thmitem{alg:euclidean_division_of_polynomials/positive_degree} Suppose that\n    \\begin{align*}\n      f(X) = a_n X^n + \\hat f(X), \\\\\n      g(X) = X^m + \\hat g(X),\n    \\end{align*}\n    where \\( n \\) and \\( m \\) are positive, \\( \\hat f(X) \\) is either zero or \\( \\deg \\hat f < \\deg f \\), and similarly for \\( \\deg \\hat g \\).\n\n    Then\n    \\begin{align*}\n    f(X) - g(X) a_n X^{n-m}\n    &=\n    a_n X^n + \\hat f(X) - (b_m X^m + \\hat g(X)) a_n X^{n-m}\n    = \\\\ &=\n    a_n X^n + \\hat f(X) - a_n X^n - \\hat g(X) a_n X^{n-m}\n    = \\\\ &=\n    \\underbrace{\\hat f(X) - \\hat g(X) a_n X^{n-m}}_{\\hat r(X)}.\n    \\end{align*}\n\n    The polynomial \\( \\hat r(X) \\) is either zero, in which case we define \\( r(X) \\coloneqq \\hat r(X) \\), or \\( \\deg \\hat r \\leq n - 1 \\).\n\n    In the latter case, we use the algorithm recursively to divide \\( \\hat r(X) \\) by \\( g(X) \\), and obtain \\( \\hat q(X) \\) and \\( r(X) \\) such that\n    \\begin{equation*}\n      \\hat r(X) \\coloneqq g(X) \\hat q(X) + r(X),\n    \\end{equation*}\n    where \\( r(X) \\) is either zero or \\( \\deg r < \\deg g \\).\n\n    Then\n    \\begin{align*}\n      \\hat r(X)                                         &= f(X) - g(X) a_n X^{n-m} \\\\\n      g(X) \\hat q(X) + r(X)                             &= f(X) - g(X) a_n X^{n-m} \\\\\n      g(X) \\left(\\hat q(X) - a_n X^{n-m} \\right) + r(X) &= f(X).\n    \\end{align*}\n\n    Define\n    \\begin{equation*}\n      q(X) \\coloneqq \\hat q(X) - a_n X^{n-m}.\n    \\end{equation*}\n\n    We have obtained polynomials \\( r(X) \\) and \\( q(X) \\) where \\( r(X) \\) is either zero or \\( \\deg r < \\deg g \\).\n  \\end{thmenum}\n\\end{algorithm}\n\\begin{defproof}\n  \\SubProof{Proof of uniqueness} Suppose that\n  \\begin{equation*}\n    a(X) = g(X)q(X) + r(X) = g(X) \\widetilde{q}(X) + \\widetilde{r}(X),\n  \\end{equation*}\n  where \\( r(X) \\) and \\( \\widetilde{r}(X) \\) are either zero or have degree less than \\( g(X) \\).\n\n  Assume that \\( r(X) \\neq \\widetilde{r}(X) \\).\n\n  \\begin{itemize}\n    \\item If both \\( r(X) \\) and \\( \\widetilde{r}(X) \\) are nonzero, we have\n    \\begin{equation*}\n      g(X) \\parens[\\Big]{ q(X) - \\widetilde{q}(X) } = -\\parens[\\Big]{ r(X) - \\widetilde{r}(X) }.\n    \\end{equation*}\n\n    Since \\( g(X) \\) is monic and its leading coefficient \\( 1_R \\) is not a zero divisor, \\fullref{thm:def:polynomial_degree/product} holds, and thus\n    \\begin{equation*}\n      \\deg g + \\deg(q - \\widetilde{q})\n      \\reloset {\\eqref{eq:thm:def:polynomial_degree/product}} =\n      \\deg(g (q - \\widetilde{q}))\n      =\n      \\deg(r - \\widetilde{r})\n      \\reloset {\\eqref{eq:thm:def:polynomial_degree/sum}} =\n      \\leq \\max\\set{ \\deg r, \\deg \\widetilde{r} }\n      <\n      \\deg g,\n    \\end{equation*}\n    which is a contradiction.\n\n    \\item If \\( r(X) \\) is zero but \\( \\widetilde{r}(X) \\) is not, then\n    \\begin{equation*}\n      g(X) q(X) = g(X) \\widetilde{q}(X) + \\widetilde{r}(X),\n    \\end{equation*}\n    implying that\n    \\begin{equation*}\n      \\widetilde{r}(X) = g(X) \\parens[\\Big]{ q(X) - \\widetilde{q}(X) }.\n    \\end{equation*}\n\n    By \\eqref{thm:def:polynomial_degree/product}, \\( \\deg g \\leq \\widetilde{r} \\), which contradicts our choice of \\( \\widetilde{r}(X) \\).\n  \\end{itemize}\n\\end{defproof}\n\n\\begin{definition}\\label{def:algebraic_derivative}\n  Generalizing \\fullref{def:differentiability} from analysis, we define the \\term{algebraic derivative} of a univariate polynomial\n  \\begin{equation*}\n    p(X) = \\sum_{k=0}^n a_k X^k = a_n X^n + a_{n-1} X^{n-1} + \\cdots + a_2 X^2 + a_1 X + a_0\n  \\end{equation*}\n  as\n  \\begin{equation*}\n    p'(X) \\coloneqq \\sum_{k=1}^n k a_k X^{k-1} = n a_n X^{n-1} + (n-1) a_{n-1} X^{n-2} + \\cdots + a_2 X + a_1.\n  \\end{equation*}\n\n  Via \\hyperref[rem:natural_number_recursion]{natural number recursion}, we can define algebraic derivatives of order \\( m \\) as\n  \\begin{equation*}\n    p^{(m)}(X) \\coloneqq \\begin{cases}\n      p(X)              &m = 0 \\\\\n      \\parens[\\Big]{ p^{(m - 1)} }'(X) &m > 0\n    \\end{cases}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:algebraic_derivative}\n  \\hyperref[def:algebraic_derivative]{Algebraic derivatives} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:algebraic_derivative/linear} The derivative operator \\( p(X) \\mapsto p'(X) \\) is linear.\n    \\thmitem{thm:def:algebraic_derivative/degree} \\( p^{(n)}(X) \\) is either zero or has degree \\( \\deg p - n \\).\n\n    \\thmitem{thm:def:algebraic_derivative/product} We have the product rule\n    \\begin{equation}\\label{eq:thm:def:algebraic_derivative/product}\n      (pq)' = p'q + pq'.\n    \\end{equation}\n\n    \\thmitem{thm:def:algebraic_derivative/leibniz} Leibniz' rule holds:\n    \\begin{equation}\\label{eq:thm:def:algebraic_derivative/leibniz}\n      (pq)^{(n)} = \\sum_{k=0}^n \\binom n k p^{(k)} q^{(n-k)}\n    \\end{equation}\n\n    \\thmitem{thm:def:algebraic_derivative/affine_power} If \\( m \\leq n \\), the \\( m \\)-th derivative of \\( (X - u)^n \\) is \\( \\tfrac {n!} {(n-m)!} (X - u)^{n-m} \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:algebraic_derivative/linear} Trivial.\n\n  \\SubProofOf{thm:def:algebraic_derivative/degree} Trivial.\n\n  \\SubProofOf{thm:def:algebraic_derivative/product} By \\fullref{thm:def:algebraic_derivative/linear}, it is enough to consider the case where both \\( p(X) \\) and \\( q(X) \\) are monomials.\n\n  \\begin{align*}\n    p'(X) q(X) + p(X) q'(X)\n    &=\n    n a_n X^{n-1} \\cdot b_m X^m + a_n X^n \\cdot m b_m X^{m-1}\n    = \\\\ &=\n    (n + m) a_n b_m X^{n+m-1}\n    = \\\\ &=\n    (a_n b_m X^{n+m})'\n    = \\\\ &=\n    (pq)'(X).\n  \\end{align*}\n\n  \\SubProofOf{thm:def:algebraic_derivative/leibniz} The proof in \\fullref{thm:leibniz_rule} relies only on the product rule, hence it holds here as well.\n\n  \\SubProofOf{thm:def:algebraic_derivative/affine_power} We use outer induction on \\( m \\) and inner induction on \\( n \\).\n\n  The case \\( m = n = 1 \\) is obvious. Assume that the statement holds for \\( m = 1 \\) and \\( n - 1 \\). Then\n  \\begin{equation*}\n    \\parens[\\Big]{ (X - u)^n }'\n    =\n    \\parens[\\Big]{ (X - u)^{n-1} \\cdot (X - u) }'\n    \\reloset {\\eqref{eq:thm:def:algebraic_derivative/product}} =\n    \\parens[\\Big]{ (X - u)^{n-1} }' (X - u) + (X - u)^{n-1}\n    \\reloset {\\T{ind.}} =\n    n (X - u)^{n-1}.\n  \\end{equation*}\n\n  Now suppose that the statement holds for derivatives of order less than \\( m \\) and for every \\( n \\geq m \\). Then,\n  \\begin{equation*}\n    \\parens[\\Big]{ (X - u)^n }^{(m)}\n    =\n    \\parens*{\\parens[\\Big]{ (X - u)^n }^{(m-1)}}'\n    \\reloset {\\T{ind.}} =\n    \\parens*{ \\frac {n!} {(n - m + 1)!} (X - u)^{n - m + 1} }'\n    \\reloset {\\T{ind.}} =\n    \\frac {n!} {(n - m)!} (X - u)^{n - m}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:polynomial_root}\n  Let \\( R \\) be a nontrivial commutative ring.\n\n  We say that the value \\( u \\in R \\) is a \\term{root} of multiplicity \\( m \\) for the univariate polynomial \\( p(X) \\in R[X] \\) of degree \\( n \\geq m \\) if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:polynomial_root/division} The polynomial \\( (X - u)^m \\) divides \\( p(X) \\).\n\n    \\thmitem{def:polynomial_root/derivative_roots} The value \\( u \\) is a \\hyperref[def:zero_locus]{zero} of the \\hyperref[def:algebraic_derivative]{algebraic derivatives} \\( p^{(0)}(X), p^{(1)}(X), \\ldots, p^{(m-1)}(X) \\) of \\( p(X) \\).\n  \\end{thmenum}\n\n  Every polynomial \\( p(X) \\) has a \\hyperref[def:weighted_set/multiset]{multiset} of roots.\n\\end{definition}\n\\begin{defproof}\n  \\ImplicationSubProof{def:polynomial_root/division}{def:polynomial_root/derivative_roots} Suppose that \\( (X - u)^m \\) divides \\( p(X) \\). Then there exists a polynomial \\( q(X) \\) such that\n  \\begin{equation*}\n    p(X) = (X - u)^m q(X).\n  \\end{equation*}\n\n  For the \\( n < m \\)-th derivative of \\( p(X) \\), by \\fullref{thm:def:algebraic_derivative/leibniz}, we have\n  \\begin{equation*}\n    p^{(n)}(X) = \\sum_{k=0}^n \\binom n k \\underbrace{\\parens[\\Big]{ (X - u)^m }^{(k)}}_{\\mathclap{\\frac {m!} {k!} (X - u)^{m-k} \\T*{by} \\ref{thm:def:algebraic_derivative/affine_power}}} q^{(n-k)}(X).\n  \\end{equation*}\n\n  Let \\( \\Phi_u: R[X] \\to R \\) be the \\hyperref[thm:polynomial_algebra_universal_property]{evaluation homomorphism} at \\( u \\). Then\n  \\begin{equation*}\n    \\Phi_u(p^{(n)}) = \\sum_{k=0}^n \\binom n k \\frac {m!} {k!} 0_R^{m-k} \\Phi_u(q^{(n-k)})\n  \\end{equation*}\n\n  For \\( n < m \\), clearly \\( \\Phi_u(p^{(n)}) = 0_R \\).\n\n  \\ImplicationSubProof{def:polynomial_root/derivative_roots}{def:polynomial_root/division} Suppose that \\( u \\) is a root of \\( p^{(0)}(X), \\ldots, p^{(m-1)}(X) \\). We will use induction on \\( m \\) to show that \\( (X - u)^m \\mid p(X) \\).\n\n  The case \\( m = 0 \\) is trivial. Suppose that \\( u \\) being a root of \\( p^{(0)}(X), \\ldots, p^{(m-1)}(X) \\) implies that \\( (X - u)^{m-1} \\mid p(X) \\), and additionally let \\( u \\) be a root of \\( p^{(m)}(X) \\).\n\n  By the inductive hypothesis, there exists a polynomial \\( q(X) \\) such that\n  \\begin{equation*}\n    p(X) = (X - u)^{m-1} q(X).\n  \\end{equation*}\n\n  By \\fullref{thm:def:algebraic_derivative/leibniz},\n  \\begin{equation*}\n    p^{(m-1)}(X) = \\sum_{k=0}^{m-1} \\binom {m-1} k \\underbrace{\\parens[\\Big]{ (X - u)^{m - 1} }^{(k)}}_{\\mathclap{\\frac {(m - 1)!} {k!} (X - u)^{m - k - 1} \\T*{by} \\ref{thm:def:algebraic_derivative/affine_power}}} q^{(m - k - 1)}(X).\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    \\Phi_u(p^{(m-1)}) = \\sum_{k=0}^{m-1} \\binom {m-1} k \\frac {(m - 1)!} {k!} 0_R^{m - k - 1} \\Phi_u(q^{(m - k - 1)}).\n  \\end{equation*}\n\n  All terms on the right are zero except for \\( \\Phi_u(q) \\). But \\( u \\) is a root of \\( p^{(m-1)} \\), implying that it is also a root of \\( q \\).\n\n  We use \\fullref{alg:euclidean_division_of_polynomials} to obtain a polynomial \\( s(X) \\) and a constant polynomial \\( r(X) = r_0 \\) so that\n  \\begin{equation*}\n    q(X) = (X - u) s(X) + r_0.\n  \\end{equation*}\n\n  Since \\( \\Phi_u(q) = 0_R \\), then necessarily \\( r_0 = 0_R \\). Therefore,\n  \\begin{equation*}\n    p(X) = (X - u)^{m-1} q(X) = (X - u)^m s(X).\n  \\end{equation*}\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:representatives_in_univariate_polynomial_quotient_set}\n  Given \\hyperref[def:monic_polynomial]{monic polynomial} \\( g(X) \\) in a nontrivial commutative ring \\( R \\), every coset in \\( R[X] / \\braket{ g(X) } \\) has a unique representative that is either the zero polynomial or a polynomial of degree less than \\( g(X) \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( f(X) \\) be an arbitrary polynomial. \\Fullref{alg:euclidean_division_of_polynomials} gives us polynomials \\( q(X) \\) and \\( r(X) \\) so that\n  \\begin{equation*}\n    f(X) = g(X) q(X) + r(X),\n  \\end{equation*}\n  where \\( r(X) \\) is either zero or has degree less than \\( g(X) \\).\n\n  Multiples of \\( q(X) \\) are congruent to \\( 0_R \\) modulo the ideal \\( \\braket{ q(X) } \\), hence \\( f(X) \\) is congruent to \\( r(X) \\).\n\n  By the uniqueness of \\( r(X) \\), the statement of the corollary follows.\n\\end{proof}\n\n\\begin{remark}\\label{rem:adjoining_roots}\n  Fix arbitrary commutative rings \\( R \\subseteq S \\) and some element \\( u \\) of \\( S \\). By \\fullref{thm:polynomial_algebra_universal_property}, there exists a unique \\hyperref[def:algebra_over_ring/homomorphism]{\\( R \\)-algebra homomorphism} \\( \\Phi_u: R[X] \\to S \\) sending \\( X \\) to \\( u \\). If the kernel of \\( \\Phi_u \\) is a principal ideal, and if \\( p(X) \\) is a generator, then we have the algebra isomorphism\n  \\begin{equation*}\n    R[X] / \\braket{ p(X) } \\cong R[u].\n  \\end{equation*}\n\n  By \\fullref{thm:representatives_in_univariate_polynomial_quotient_set}, there exists a correspondence between polynomials\n  \\begin{equation*}\n    f(X) = \\sum_{k=0}^n a_k X^k\n  \\end{equation*}\n  of degree less than \\( \\deg p \\), and elements of the form\n  \\begin{equation*}\n    \\sum_{k=0}^n a_k u^k\n  \\end{equation*}\n\n  Furthermore, multiplication in \\( R[u] \\) corresponds to polynomial multiplication modulo \\( p(X) \\).\n\\end{remark}\n\n\\begin{example}\\label{ex:gaussian_integers}\n  The \\term{Gaussian integers} are complex numbers \\( z = a + bi \\) with integer real and imaginary components. We can define several isomorphic rings for the Gaussian integers, demonstrating \\fullref{rem:adjoining_roots}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:gaussian_integers/quotient} We can take the \\hyperref[def:ring/quotient]{quotient ring} \\( \\BbbZ[X] / \\braket{X^2 + 1} \\). By \\fullref{thm:representatives_in_univariate_polynomial_quotient_set}, the remainder from \\fullref{alg:euclidean_division_of_polynomials} can be used as a canonical representative within the quotient. The remainder must be either a constant or a linear polynomial. That is, \\( r(X) = aX + Y \\).\n\n    In order to make sense of the imposed ring structure in the quotient, we can see how multiplication modulo \\( X^2 + 1 \\) works. We have\n    \\begin{align*}\n      (bX + a) (dX + c)\n      &\\cong\n      bdX^2 + (ad + bc)X + ac\n      &\\pmod {X^2 + 1} \\cong \\\\ &\\cong\n      bd\\parens[\\Big]{ X^2 + 1 } + \\parens[\\Big]{ (ad + bc)X - bd + ac }\n      &\\pmod {X^2 + 1} \\cong \\\\ &\\cong\n      (ad + bc)X + (ac - bd)\n      &\\pmod {X^2 + 1}. \\phantom{\\cong}\n    \\end{align*}\n\n    This is precisely the definition of multiplication of complex numbers as given in \\fullref{def:set_of_complex_numbers}. Thus,\n    \\begin{equation*}\n      \\BbbZ[X] / \\braket{X^2 + 1}\n    \\end{equation*}\n    is the desired ring of Gaussian integers.\n\n    \\thmitem{ex:gaussian_integers/evaluation} We can also \\hyperref[thm:adjoining_elements_to_semiring]{adjoin} \\( i \\) to \\( \\BbbZ \\) to obtain the ring \\( \\BbbZ[i] \\).\n\n    Given a Gaussian integer \\( z = a + bi \\), it corresponds to the polynomial\n    \\begin{equation*}\n      p_z(X) \\coloneqq a + bX.\n    \\end{equation*}\n\n    Conversely, consider the \\hyperref[thm:polynomial_algebra_universal_property]{evaluation homomorphism} \\( \\Phi_i: \\BbbZ[X] \\to \\BbbC \\) for the imaginary unit. Let \\( p(X) \\in \\BbbZ[X] \\). Then\n    \\begin{equation*}\n      p(i)\n      =\n      \\Phi_i(p)\n      =\n      \\sum_{k=0}^n a_k i^n\n      =\n      \\thickspace \\sum_{\\scriptscriptstyle{\\rem(k, 4) = 0}}^n a_k - \\sum_{\\scriptscriptstyle{\\rem(k, 4) = 2}}^n a_k + i \\parens[\\Bigg]{ \\sum_{\\scriptscriptstyle{\\rem(k, 4) = 1}}^n a_k - \\sum_{\\scriptscriptstyle{\\rem(k, 4) = 3}}^n a_k }.\n    \\end{equation*}\n\n    This is clearly a Gaussian integer.\n\n    It remains to show that multiplication in \\( \\BbbZ[i] \\) is compatible with multiplication in \\( \\BbbC \\). But complex \\hyperref[def:set_of_complex_numbers]{multiplication} is defined to be compatible with the notation \\( a + bi \\), that is,\n    \\begin{equation*}\n    (a + bi) (c + di)\n    =\n    ac + ibc + iad - bd\n    =\n    (ac - bd) + i(bc + ad).\n    \\end{equation*}\n\n    Thus, the Gaussian integers are precisely the homomorphic image of \\( \\BbbZ[X] \\) under \\( \\Phi_i \\).\n  \\end{thmenum}\n\\end{example}\n\n\\begin{corollary}\\label{thm:polynomial_quotient_modules_vs_algebras}\n  For two nonzero monic polynomials \\( p(X) \\) and \\( q(X) \\) of the same degree, the \\hyperref[def:ring/quotient]{quotient rings} \\( R[X] / \\braket{ p(X) } \\) and \\( R[X] / \\braket{ q(X) } \\) are isomorphic as \\( R \\)-modules, but may not be isomorphic as \\( R \\)-algebras.\n\\end{corollary}\n\\begin{proof}\n  By \\fullref{thm:representatives_in_univariate_polynomial_quotient_set}, for every coset in the quotient, \\fullref{alg:euclidean_division_of_polynomials} gives us a unique representative of the corresponding degree. Addition and scalar multiplication must be the same in both.\n\n  As shown in \\fullref{ex:gaussian_integers} and \\fullref{ex:integers_with_sqrt2}, however, the vector multiplication operation may differ.\n\\end{proof}\n\n\\begin{example}\\label{ex:integers_with_sqrt2}\n  Similarly to how the Gaussian integers were defined in multiple ways in \\fullref{ex:gaussian_integers}, \\fullref{rem:adjoining_roots} gives us an isomorphism\n  \\begin{equation*}\n    \\BbbZ[X] / \\braket{X^2 - 2} \\cong \\BbbZ[\\sqrt 2].\n  \\end{equation*}\n\n  The gist of this example is that, even though \\( \\BbbZ[\\sqrt 2] \\) and \\( \\BbbZ[i] \\) are isomorphic as modules, their vector multiplication operation is different. Indeed, multiplication modulo \\( X^2 - 2 \\) works as follows:\n  \\begin{align*}\n    (aX + b) (cX + bd)\n    &\\cong\n    acX^2 + (bc + ad)X + bd\n    &\\pmod {X^2 - 2} \\cong \\\\ &\\cong\n    ac(X^2 - 2) + \\parens[\\Big]{ (bc + ad)X + 2ac + bd }\n    &\\pmod {X^2 - 2} \\cong \\\\ &\\cong\n    (bc + ad)X + (2ac + bd)\n    &\\pmod {X^2 - 2}. \\phantom{\\cong}\n  \\end{align*}\n\\end{example}\n", "meta": {"hexsha": "65524ebb4f7adaea5e6bb65d9d9067a0c2031692", "size": 22275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/univariate_polynomials.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/univariate_polynomials.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/univariate_polynomials.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8322147651, "max_line_length": 535, "alphanum_fraction": 0.6207856341, "num_tokens": 7941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6690458503249793}}
{"text": "\\chapter{Permutations}\n\\label{chap-Permutations}\n\nFrom our perspective, a \\emph{permutation of size $n$} is a sequence of length $n$ taken from the alphabet $\\{1, 2, \\dots, n\\}$ in which each letter occurs precisely once. To define containment, we say that two sequences $u$ and $v$ of the same length are \\emph{order-isomorphic} if for all indices $i$ and $j$ we have\n\\[\n\tu(i) > u(j)\n\t\\iff\n\tv(i) > v(j).\n\\]\nFinally, the permutation $\\pi$ contains another permutation $\\sigma = \\sigma(1) \\sigma(2) \\cdots \\sigma(m)$ \\emph{as a pattern} if there is a subsequence $\\pi(i_1) \\pi(i_2) \\cdots \\pi(i_m)$ of $\\pi$ that is order-isomorphic to $\\sigma$. If $\\pi$ does not contain $\\sigma$, then we say that $\\pi$ \\emph{avoids} $\\sigma$.\n\nIt is helpful to identify a permutation $\\pi = \\pi(1) \\cdots \\pi(n)$ with its plot. A \\emph{plot} of $\\pi$ is a set of points in the plane, no two with the same $x$- or $y$-value, so that the sequence of $y$-values read from left to right are order-isomorphic to $\\pi$, and \\emph{the (canonical)} plot of $\\pi$ is the set of points $\\{(i,\\pi(i))\\}_{i = 1}^{n}$. This graphical representation of $\\pi$ helps to visualize the pattern-containment order: $\\pi$ contains $\\sigma$ if a subset of the plot of $\\pi$ constitutes a plot of $\\sigma$. An example of containment displayed through plots is exhibited in Figure~\\ref{fig-perm-plots}.\n\n\\begin{figure}[ht]\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale={1/3}, baseline=(current bounding box.center)]\n\t\t% The permutation:\n\t\t\\draw (0,0) rectangle (6,6);\n\t\t\\plotpartialperm{1/2,2/5,4/1};\n\t\t% Labels:\n\t\t\\node at (1,0) [below] {$2$};\n\t\t\\node at (2,0) [below] {$3$};\n\t\t\\node at (4,0) [below] {$1$};\n\t\t\n\t\t\\begin{scope}[shift={(8.5,0)}]\n\t\t\t\\node at (0,3) {$\\le$};\n\t\t\t\\node at (0,0) [below] {$\\le$};\n\t%\t\t\t\\node at (0,0) [below] {\\phantom{$1$}};\n\t\t\\end{scope}\n\n\t\t\\begin{scope}[shift={(11,0)}]\n\t\t\t% The permutation:\n\t\t\t\\draw (0,0) rectangle (6,6);\n\t\t\t\\plotperm{2,5,3,1,4};\n\t\t\t% The containment of 231---can't use \\plotpermencircle because of strange font sizes.\n\t\t\t\\begin{scope}[xshift=-0.15pt, yshift=+1.45pt]\n\t\t\t\t\\draw (1,2) circle (16pt);\n\t\t\t\t\\draw (2,5) circle (16pt);\n\t\t\t\t\\draw (4,1) circle (16pt);\n\t\t\t\\end{scope}\n\t\t\t% Labels:\n\t\t\t\\node at (1,0) [below] {$\\underline{2}$};\n\t\t\t\\node at (2,0) [below] {$\\underline{5}$};\n\t\t\t\\node at (3,0) [below] {$3$};\n\t\t\t\\node at (4,0) [below] {$\\underline{1}$};\n\t\t\t\\node at (5,0) [below] {$4$};\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{An example of permutation containment displayed through their plots.}\n\\label{fig-perm-plots}\n\\end{figure}\n\nBefore introducing the universality problem for permutations, we give a few definitions that will be helpful throughout this chapter. Given permutations $\\pi$ and $\\sigma$ of respective sizes $m$ and $n$, their \\emph{direct sum} is the permutation $\\pi\\directsum\\sigma$ of size $m+n$ defined by\n\\[\n\t(\\pi\\directsum\\sigma)(i)\n\t=\n\t\\left\\{\\begin{array}{ll}\n\t\t\\pi(i)         &\\text{if $  1 \\le i \\le m$,}\\\\\n\t\t\\sigma(j-m)+m  &\\text{if $m+1 \\le i \\le m+n$.}\n\t\\end{array}\\right.\n\\]\nPictorially, the plot of $\\pi\\directsum\\sigma$ consists of the plot of $\\sigma$ placed above and to the right of the plot of $\\pi$, as shown on the left of Figure~\\ref{fig-sums}. Similarly, we define the \\emph{skew sum} of $\\pi$ and $\\sigma$ by\n\\[\n\t(\\pi\\skewsum\\sigma)(i)\n\t=\n\t\\left\\{\\begin{array}{ll}\n\t\t\\pi(i) + n  &\\text{if $  1 \\le i \\le m  $,}\\\\\n\t\t\\sigma(j-m) &\\text{if $m+1 \\le i \\le m+n$.}\n\t\\end{array}\\right.\n\\]\nPictorially, the plot of $\\pi\\skewsum\\sigma$ consists of the plot of $\\sigma$ placed below and to the right of the plot of $\\pi$, as shown on the right of Figure~\\ref{fig-sums}. A permutation that cannot be written as a direct sum (resp. skew sum) is said to be \\emph{sum-indecomposable} (resp. \\emph{skew-indecomposable}.)\n\n\\begin{figure}\n\t\\begin{tikzpicture}[scale=0.2, baseline=(current bounding box.center)]\n\t\t\\node at (-4, 4.75) {$\\pi\\directsum\\sigma = $};\n\t\t\\plotpermbox{1}{1}{4}{4};\n\t\t\\plotpermbox{5}{5}{8}{8};\n\t\t\\node at (2.5,2.5) {$\\pi$};\n\t\t\\node at (6.5,6.5) {$\\sigma$};\n\n\t\t\\begin{scope}[shift={(20,0)}]\n\t\t\t\\node at (-4, 4.75) {$\\pi\\skewsum\\sigma = $};\n\t\t\t\\plotpermbox{1}{5}{4}{8};\n\t\t\t\\plotpermbox{5}{1}{8}{4};\n\t\t\t\\node at (2.5,6.5) {$\\pi$};\n\t\t\t\\node at (6.5,2.5) {$\\sigma$};\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{The plot of the direct sum of $\\pi$ and $\\sigma$ on the left and the plot of the skew sum of $\\pi$ and $\\sigma$ on the right.}\n\\label{fig-sums}\n\\end{figure}\n\nAs usual, we say that a permutation is $m$-universal if it contains all permutations of size $m$ as patterns. Such a permutation is sometimes called an \\emph{$m$-superpattern} (for example, by B\\'ona~\\cite[Chapter 5, Exercises 19--22 and Problems Plus 9--12]{bona:combinatorics-o:}.) The first result about universal permutations was obtained by Simion and Schmidt in 1985~\\cite[Section~5]{simion:restricted-perm:}, who computed the number of $3$-universal permutations of size $n \\ge 5$ to be\n\\[\n\tn!\n\t- 6 C_n\n\t+ 5 \\cdot 2^n\n\t+ 4 \\binom{n}{2}\n\t- 2F_n\n\t- 14n\n\t+ 20.\n\\]\n(Here $C_n$ denotes the $n$th Catalan number and $F_n$ denotes the $n$th \\emph{combinatorial} Fibonacci number, so $F_0=F_1=1$ and $F_n=F_{n-1}+F_{n-2}$ for $n\\ge 2$.) Simion and Schmidt did not use the term ``universal'' and received their formula as a corollary to a sequence of results enumerating those permutation classes where membership is defined by avoiding sets of $3$-patterns. The first to study the universal permutation problem for general $m$ was Arratia~\\cite{arratia:on-the-stanley-:} in 1999.\n\nLet $\\u(m)$ denote the size of the smallest $m$-universal permutation. Arratia observed that for any permutation of size $n$ to be $m$-universal, it must have at least $m!$ length-$m$ subsequences, and thus\n\\[\n\t\\binom{n}{m}\n\t\\ge\n\tm!.\n\\]\nThis simple inequality, together with the inequalities $\\left(\\frac{ne}{m}\\right)^m \\ge \\binom{n}{m}$ and $m! \\ge \\left(\\frac{m}{e}\\right)^m$, implies that $n \\ge m^2/e^2$. This also follows from Observation~\\ref{obs-alstrup-rauhe}, again using that $m! \\ge \\left(\\frac{m}{e}\\right)^m$.\n\nArratia also provided a simple construction of an $m$-universal permutation of size $m^2$, proving that $\\u(m) = \\oTheta{m^2}$. Consider the permutation whose plot consists of an $m \\times m$ grid of points, with sides initially parallel to the axes, then rotated slightly clockwise. More precisely, partition the integers $1$ to $m^2$ into congruence classes modulo $m$, write each congruence class in increasing order, and then concatenate these sequences in decreasing order according to their first element. The left panel of Figure~\\ref{fig-tilted-square} displays the plot of the $4$-universal permutation constructed in this manner. Arratia observed that such a permutation is $m$-universal, as the point $(i, \\pi(i))$ of the pattern $\\pi$ of size $m$ can simply embed into the point $i$th column (from the left) and $\\pi(i)$th row (from the bottom). This kind of embedding actually allows for much more freedom in the universal permutations formed: dividing the square $(0, m^2] \\times (0, m^2]$ into $m^2$ many $m \\times m$ squares, this construction demonstrates that any permutation whose canonical plot places precisely $1$ point in each sqaure is $m$-universal. We exhibit another $4$-universal permutation of size $16$ that meets this criteria in the right panel of Figure~\\ref{fig-tilted-square}.\n\n\\begin{figure}[ht]\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale=0.25]\n\t\t\\plotpermborder{4,8,12,16,3,7,11,15,2,6,10,14,1,5,9,13}\n\n\t\t\\draw ( 4.5,0.5) -- ++(0,16);\n\t\t\\draw ( 8.5,0.5) -- ++(0,16);\n\t\t\\draw (12.5,0.5) -- ++(0,16);\n\n\t\t\\draw (0.5, 4.5) -- ++(16,0);\n\t\t\\draw (0.5, 8.5) -- ++(16,0);\n\t\t\\draw (0.5,12.5) -- ++(16,0);\n\n\t\t\\begin{scope}[shift={(20,0)}]\n\t\t\t\\plotpermborder{6, 13, 9, 1, 11, 2, 5, 15, 10, 8, 4, 16, 14, 3, 12, 7}\n\n\t\t\t\\draw ( 4.5,0.5) -- ++(0,16);\n\t\t\t\\draw ( 8.5,0.5) -- ++(0,16);\n\t\t\t\\draw (12.5,0.5) -- ++(0,16);\n\n\t\t\t\\draw (0.5, 4.5) -- ++(16,0);\n\t\t\t\\draw (0.5, 8.5) -- ++(16,0);\n\t\t\t\\draw (0.5,12.5) -- ++(16,0);\n\t\t\\end{scope}\n\t\t\n\t\\end{tikzpicture}\n\\caption{The $4 \\times 4$ tilted-square permutation and another $4$-universal permutation of size $16$.}\n\\label{fig-tilted-square}\n\\end{figure}\n\nThe first to improve upon these trivial bounds provided by Arratia were Eriksson, Eriksson, Linusson, and W\\\"{a}stlund~\\cite{eriksson:dense-packing-o:}, who used probabilistic methods to construct an $m$-universal permutation of size $(2/3 + \\oo{1})m^2$. The next improvement came in~\\cite{miller:asymptotic-boun:}, wherein Miller proves that there is a word over the alphabet $[m+1]$ of length $(m^2 + m)/2$ that contains subsequences order-isomorphic to every permutation of size $m$. Miller noted that by ``breaking ties'' between the letters of such a word, one obtains an $m$-universal permutation of size $(m^2 + m)/2$.\n\n\\begin{theorem}[Miller~\\cite{miller:asymptotic-boun:}]\n\t\\label{thm-miller-perms}\n\tFor all $m \\ge 1$, there is a word over the alphabet $[m+1]$ of length $(m^2+m)/2$ containing subsequences order-isomorphic to every permutation of size $m$.\n\\end{theorem}\n\t\nTo establish this result, define the \\emph{infinite zigzag word} to be the word formed by alternating between ascending \\emph{runs} of the odd positive integers $1357\\cdots$ and descending \\emph{runs} of the even positive integers $\\cdots 8642$,\n\\[\n\t(1357\\cdots)\\ (\\cdots 8642)\\ \n\t(1357\\cdots)\\ (\\cdots 8642)\\ \n\t(1357\\cdots)\\ (\\cdots 8642)\\ \\cdots.\n\\]\nWhile this object does not conform to most definitions of the word \\emph{word} in combinatorics, we hope the reader forgives the slight expansion of the definition adopted here. We are interested in the leftmost embeddings of words over $\\mathbb{P}$ into the infinite zigzag word.\n\nWe also need two definitions. First, given a word $p\\in\\mathbb{P}^\\ast$, we define the word $p^{+1}\\in\\mathbb{P}^\\ast$ to be the word formed by adding $1$ to each letter of $p$, so $p^{+1}(i)=p(i)+1$ for all indices $i$ of $p$. Next we say that the word $p\\in\\mathbb{P}^\\ast$ has an \\emph{immediate repetition} if there is an index $i$ with $p(i)=p(i+1)$, i.e., if $p$ contains a factor equal to $\\ell\\ell$ for some letter $\\ell\\in\\mathbb{P}$.\n\n\\begin{proposition}[Miller~\\cite{miller:asymptotic-boun:}]\n\t\\label{prop-miller-words}\n\tIf the word $p\\in\\mathbb{P}^m$ has no immediate repetitions, then either $p$ or $p^{+1}$ occurs as a subsequence of the first $m$ runs of the infinite zigzag word.\n\\end{proposition}\n\nBefore proving Proposition~\\ref{prop-miller-words}, note that permutations do not have immediate repetitions. Thus if $\\pi$ is a permutation of size $m$, Proposition~\\ref{prop-miller-words} implies that either $\\pi$ or $\\pi^{+1}$ occurs as a subsequence in the first $m$ runs of the infinite zigzag word. Since $\\pi^{+1}$ is order-isomorphic to $\\pi$ and both $\\pi$ and $\\pi^{+1}$ are words over $[m+1]$, this implies that the restriction of the first $m$ runs of the infinite zigzag word to the alphabet $[m+1]$ contains every permutation of size $m$. For example, in the case of $m=5$ we obtain the universal word\n\\[\n\t135\\ 642\\ 135\\ 642\\ 135\n\\]\nof length $15$ over the alphabet $[6]$.\n\nThe restriction of the infinite zigzag word described above consists of $m$ runs of average length $(m+1)/2$: if $m$ is odd, then all runs are of this length, while if $m$ is even, then half are of length $m/2$ and half are of length $(m+2)/2$. Thus Proposition~\\ref{prop-miller-words} implies Theorem~\\ref{thm-miller-perms}. While Proposition~\\ref{prop-miller-words} does not appear explicitly in \\cite{miller:asymptotic-boun:}, its proof, presented below, is adapted from Miller's proof of Theorem~\\ref{thm-miller-perms}.\n\n\\newenvironment{proof-of-prop-miller-words}{%\n\t\\medskip\\noindent {\\it Proof of Proposition~\\ref{prop-miller-words}.\\/}%\n}{%\n\t\\qed\\bigskip%\n}\n%\n\\begin{proof-of-prop-miller-words}\n\tWe define the \\emph{score} of the word $p\\in\\mathbb{P}^\\ast$, denoted by $s(p)$, as the minimum number of runs that an initial segment of the infinite zigzag word must have in order to contain $p$, minus the length of $p$. Thus our goal is to show that for every word $p\\in\\mathbb{P}^\\ast$ without immediate repetitions, either $s(p)\\le 0$ or $s(p^{+1})\\le 0$. In fact, we show that for such words we have $s(p)+s(p^{+1})=1$, which implies this.\n\n\tWe prove this claim by induction on the length of $p$. For the base case, we see that words consisting of a single odd letter are contained in the first run of the infinite zigzag word (thus corresponding to scores of $0$) while words consisting of a single even letter are contained in the second run (corresponding to scores of $1$). Thus for every $\\ell\\in\\mathbb{P}^1$ we have $s(\\ell)+s(\\ell^{+1})=1$, as desired. Now suppose that the claim is true for all words $p\\in\\mathbb{P}^m$ without immediate repetitions and let $\\ell\\in\\mathbb{P}$ denote a letter. We see that, for any $p \\in \\mathbb{P}^m$,\n\t\\[\n\t\ts(p\\ell)-s(p)\n\t\t=\n\t\t\\left\\{\n\t\t\\begin{array}{cl}\n\t\t\t-1&\t\\begin{array}{l}\n\t\t\t\t\\text{if $p(n)<\\ell$ and both entries are odd or}\\\\\n\t\t\t\t\\text{if $p(n)>\\ell$ and both entries are even;}\n\t\t\t\t\\end{array}\n\t\t\t\\\\[12pt]\n\t\t\t0&\t\\begin{array}{l}\n\t\t\t\t\\text{if $p(n)$ and $\\ell$ are of different parity; or}\n\t\t\t\t\\end{array}\n\t\t\t\\\\[8pt]\n\t\t\t+1&\t\\begin{array}{l}\n\t\t\t\t\\text{if $p(n)<\\ell$ and both entries are even,}\\\\\n\t\t\t\t\\text{if $p(n)=\\ell$, or}\\\\\n\t\t\t\t\\text{if $p(n)>\\ell$ and both entries are odd.}\n\t\t\t\t\\end{array}\n\t\t\\end{array}\n\t\t\\right.\n\t\\]\n\tBecause our words do not have immediate repetitions, we can ignore the possibility that $\\ell=p(m)$. In the other cases, it can be seen by inspection that\n\t\\[\n\t\t\\big(  s(p\\ell)-s(p)  \\big)\n\t\t+\n\t\t\\big(  s\\!\\left((p\\ell)^{+1}\\right) - s\\!\\left(p^{+1}\\right)\\!  \\big)\n\t\t=\n\t\t0.\n\t\\]\n\tBy rearranging these terms, we see that\n\t\\[\n\t\ts(p\\ell) + s\\!\\left((p\\ell)^{+1}\\right)\n\t\t=\n\t\ts(p)+s\\!\\left(p^{+1}\\right).\n\t\\]\n\tSince $s(p)+s\\!\\left(p^{+1}\\right)=1$ by induction, this completes the proof of the inductive claim, and thus also of the proposition.\n\\end{proof-of-prop-miller-words}\n\nHere, we give a new improvement to Miller's upper bound. In order to do so, we further restrict the infinite zigzag word, and then break ties between its letters to obtain a specific permutation $\\zeta_m$. To this end, we define the word $z_m$ to be the restriction of the first $m$ runs of the infinite zigzag word to the alphabet $[m]$. When $m$ is even, each run of $z_m$ has length $m/2$. When $m$ is odd, $z_m$ consists of $(m+1)/2$ ascending odd runs, each of length $(m+1)/2$, and $(m-1)/2$ descending even runs, each of length $(m-1)/2$. Thus we have\n\\[\n\t\\size{z_m}\n\t=\n\t\\left\\{\n\t\\begin{array}{cl}\n\t\t\\displaystyle\\frac{m^2}{2}  &\\text{if $m$ is even,}\\\\[12pt]\n\t\t\\displaystyle\\frac{m^2+1}{2}&\\text{if $m$ is odd.}\n\t\\end{array}\n\t\\right.\n\\]\n\nAs one additional definition, we say that a word $u$ is \\emph{order-homomorphic} to another word $v$ of the same length if for all indices $i$ and $j$, we have\n\\[\n\tu(i) > u(j)\n\t\\implies\n\tv(i) > v(j).\n\\]\nNext, we choose a specific permutation, $\\zeta_m$, such that $z_m$ is order-homomorphic to $\\zeta_m$. In constructing $\\zeta_m$, we have the freedom to break ties between equal letters of $z_m$. That is to say, if $z_m(i)=z_m(j)$ for $i\\neq j$, then in constructing $\\zeta_m$ we may choose whether $\\zeta_m(i)<\\zeta_m(j)$ or $\\zeta_m(i)>\\zeta_m(j)$ arbitrarily without affecting any other pair of comparisons and thus without losing any occurrences of permutations. We choose to break these ties by replacing all instances of a given letter $k\\in[m]$ in $z_m$ by a decreasing subsequence in $\\zeta_m$. Thus for indices $i<j$, we have\n\\[\n\tz_m(i)=z_m(j)\n\t\\implies\n\t\\zeta_m(i)>\\zeta_m(j).\n\\]\nThis choice uniquely determines $\\zeta_m$ (up to order-isomorphism), as all comparisons between its letters are determined either in $z_m$, if the corresponding letters of $z_m$ differ, or by the rule above, if the corresponding letters of $z_m$ are the same. Figure~\\ref{fig-z5-zeta5} shows the plots of $z_5$ and $\\zeta_5$, where the \\emph{plot} of a word $w$ over $\\mathbb{P}$ is the set $\\{(i,w(i))\\}$ of points in the plane.\n\n\\begin{figure}[ht]\n\\captionsetup{justification=centering}\n\t\\begin{footnotesize}\n\t\t\\begin{tabular}{ccc}\n\t\t\t\\begin{tikzpicture}[scale=0.35, baseline=(current bounding box.south)]\n\t\t\t\t\\foreach \\y/\\val [count = \\x] in {1/2, 3/7, 5/12, 4/9.5, 2/4.5, 1/2, 3/7, 5/12, 4/9.5, 2/4.5, 1/2, 3/7, 5/12} {\n\t\t\t\t\t\\absdot{(\\x,\\val)}\n\t\t\t\t\t\\node at (\\x, 0) {\\y};\n\t\t\t\t\t}\n\t\t\t\t\\draw[darkgray, thick, line cap=round] (0.5,0.5) rectangle (13.5,13.5);\n\t\t\t\t\\foreach \\y in {3,5,8,10} {\n\t\t\t\t\t\\draw[darkgray, thick, line cap=round] (0.5, \\y+0.5) -- (13.5, \\y+0.5);\n\t\t\t\t\t\\draw[darkgray, thick, line cap=round] (\\y+0.5, 0.5) -- (\\y+0.5, 13.5);\n\t\t\t\t}\n\t\t\t\\end{tikzpicture}\n\t\t\t&\\quad\\quad&\n\t\t\t\\begin{tikzpicture}[scale=0.35, baseline=(current bounding box.south)]\n\t\t\t\t\\plotperm{3,8,13,10,5,2,7,12,9,4,1,6,11}\n\t\t\t\t% The labels\n\t\t\t\t\\node at (1,0) {3};\n\t\t\t\t\\node at (2,0) {8};\n\t\t\t\t\\node at (3,0) {1\\!\\!\\:3};\n\t\t\t\t\\node at (4,0) {1\\!\\!\\:0};\n\t\t\t\t\\node at (5,0) {5};\n\t\t\t\t\\node at (6,0) {2};\n\t\t\t\t\\node at (7,0) {7};\n\t\t\t\t\\node at (8,0) {1\\!\\!\\:2};\n\t\t\t\t\\node at (9,0) {9};\n\t\t\t\t\\node at (10,0) {4};\n\t\t\t\t\\node at (11,0) {1};\n\t\t\t\t\\node at (12,0) {6};\n\t\t\t\t\\node at (13,0) {1\\!\\!\\:1};\n\t\t\t\t\\draw[darkgray, thick, line cap=round] (0.5,0.5) rectangle ++(13,13);\n\t\t\t\t\\foreach \\y in {3,5,8,10} {\n\t\t\t\t\t\\draw[darkgray, thick, line cap=round] (0.5, \\y+0.5) -- ++(13, 0);\n\t\t\t\t\t\\draw[darkgray, thick, line cap=round] (\\y+0.5, 0.5) -- ++(0, 13);\n\t\t\t\t}\n\t\t\t\t\\node at (0,0) {\\phantom{1}};\n\t\t\t\\end{tikzpicture}\n\t\t\\end{tabular}\n\t\\end{footnotesize}\n\\caption{On the left, the further restriction we define of the infinite zigzag word, $z_5$. On the right, the normalized permutation formed by breaking ties, $\\zeta_5$.}\n\\label{fig-z5-zeta5}\n\\end{figure}\n\nIn the following sequence of results, we show that $\\zeta_m$ is \\emph{almost} universal. In fact, we show that $\\zeta_m$ fails to be universal only for even $m$, and in that case, the only missing permutation is the decreasing permutation $m\\cdots 21$. The first of these results, Proposition~\\ref{prop-distant-inv-desc}, covers almost all permutations. (In fact, Proposition~\\ref{prop-distant-inv-desc-layered} shows that Proposition~\\ref{prop-distant-inv-desc} handles all but $2^{m-1}$ permutations of size $m$.)\n\nWe say that two entries $\\pi(j)$ and $\\pi(k)$ form an \\emph{inverse-descent} if $j<k$ and $\\pi(j)=\\pi(k)+1$. (As the name is meant to indicate, if a pair of entries forms an inverse-descent in $\\pi$, then the corresponding entries of $\\pi^{-1}$ form a descent.) If $\\pi(j)$ and $\\pi(k)$ form an inverse-descent and they are not adjacent in $\\pi$ (so $k\\ge j+2$), then we say that they form a \\emph{distant} inverse-descent.\n\n\\begin{proposition}\n\t\\label{prop-distant-inv-desc}\n\tIf the permutation $\\pi$ of size $m$ has a distant inverse-descent, then $\\zeta_m$ contains a subsequence order-isomorphic to $\\pi$.\n\\end{proposition}\n\\begin{proof}\n\tSuppose that the entries $\\pi(a)$ and $\\pi(b)$ form a distant inverse-descent in $\\pi$, meaning that $\\pi(a)=\\pi(b)+1$ and $b\\ge a+2$. We define the word $p\\in [m-1]^m$ by\n\t\\[\n\t\tp(i)\n\t\t=\n\t\t\\left\\{\\begin{array}{ll}\n\t\t\t\\pi(i)   &\\text{if $\\pi(i)\\le\\pi(b)$,}\\\\\n\t\t\t\\pi(i)-1 &\\text{if $\\pi(i)\\ge\\pi(a)=\\pi(b)+1$.}\n\t\t\\end{array}\\right.\n\t\\]\n\n\tThe word $p$ has two occurrences of the letter $\\pi(b)$, but because $\\pi(a)$ and $\\pi(b)$ form a distant inverse-descent, these two occurrences of $\\pi(b)$ in $p$ do not constitute an immediate repetition. Thus Proposition~\\ref{prop-miller-words} shows that either $p$ or $p^{+1}$ occurs as a subsequence in the first $n$ runs of the infinite zigzag word. As $p$ and $p^{+1}$ are both words over $[m]$, whichever of these words occurs in the first $n$ runs of the infinite zigzag word  also occurs as a subsequence of $z_m$. Suppose that this subsequence occurs in the indices $1\\le i_1<i_2<\\cdots<i_m\\le \\size{z_m}$, so $z_m(i_1)z_m(i_2)\\cdots z_m(i_m)$ is equal to either $p$ or $p^{+1}$, and thus for $j,k \\in [m]$ we have\n\t\\[\n\t\tz_m(i_j) > z_m(i_k)\n\t\t\\iff \n\t\tp(j) > p(k).\n\t\\]\n\tBecause $z_m$ is order-homomorphic to $\\zeta_m$, this implies that for all pairs of indices $j,k\\in[m]$ except the pair $\\{a,b\\}$, we have\n\t\\[\n\t\t\\zeta_m(i_j) > \\zeta_m(i_k)\n\t\t\\iff \n\t\tp(j) > p(k)\n\t\t\\iff \n\t\t\\pi(j) > \\pi(k).\n\t\\]\n\tFurthermore, since $p(a)=p(b)$, we have $z_m(a)=z_m(b)$, and so by our construction of $\\zeta_m$ it follows that $\\zeta_m(a)>\\zeta_m(b)$, while we know that $\\pi(a)>\\pi(b)$ because those entries form an inverse-descent. This verifies that $\\zeta_m(i_1)\\zeta_m(i_2)\\cdots \\zeta_m(i_m)$ is order-isomorphic to $\\pi$, completing the proof.\n\\end{proof}\n\n\\begin{figure}[ht]\n\t\\captionsetup{justification=centering}\n\t\t\\begin{tikzpicture}[scale=0.2, baseline=(current bounding box.center)]\n\t\t\t\\draw[thick] (0.5, 0.5)\n\t\t\t\trectangle ++(2,2)\n\t\t\t\trectangle ++(1,1)\n\t\t\t\trectangle ++(3,3)\n\t\t\t\trectangle ++(2,2);\n\t\t\t% The permutation:\n\t\t\t\\begin{scope}[shift={(0,-1pt)}]\n\t\t\t\t\\plotperm{2,1,3,6,5,4,8,7};\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}\n\t\\caption{The plot of the layered permutation $21\\ 3\\ 654\\ 87$ with layer lengths $2$, $1$, $3$, $2$.}\n\t\\label{fig-layered}\n\\end{figure}\n\nTo describe the permutations that Proposition~\\ref{prop-distant-inv-desc} does not apply to, we need the notion of a layered permutation. A permutation is said to be \\emph{layered} if it can be expressed as a sum of decreasing permutations, and in this case, these decreasing permutations are themselves called the \\emph{layers}. An example of a layered permutation is shown in Figure~\\ref{fig-layered}.\n\n\\begin{proposition}\n\t\\label{prop-distant-inv-desc-layered}\n\tThe permutation $\\pi$ is layered if and only if it does not have a distant inverse-descent.\n\\end{proposition}\n\\begin{proof}\n\tOne direction is completely trivial: if $\\pi$ is layered then all of its inverse-descents are between consecutive entries, so it does not have a distant inverse-descent. For the other direction, we use induction on the size of $\\pi$. The empty permutation is layered, so the base case holds. If $\\pi$ is a nonempty permutation without distant inverse-descents, then it must begin with the entries $\\pi(1)$, $\\pi(1)-1$, $\\dots$, $2$, $1$ in that order. This means that $\\pi=\\delta\\directsum\\sigma$ where $\\delta$ is a nonempty decreasing permutation and $\\sigma$ is a permutation smaller than $\\pi$ that also does not have any distant inverse-descents. By induction, $\\sigma$ is layered, and thus $\\pi$ is as well, completing the proof.\n\\end{proof}\n\nHaving characterized the permutations to which Proposition~\\ref{prop-distant-inv-desc} does not apply, we now show that almost all of them are nevertheless contained in $\\zeta_m$.\n\n\\begin{proposition}\n\t\\label{prop-layered-zeta}\n\tIf the permutation $\\pi$ of size $n$ is layered and not a decreasing permutation of even size, then $\\zeta_m$ contains a subsequence order-isomorphic to $\\pi$.\n\\end{proposition}\n\\begin{proof}\n\tLet $\\pi$ denote an arbitrary layered permutation of size $n$. To prove the result, we compute the score of $\\pi$ as in the proof of Proposition~\\ref{prop-miller-words}, show that this score can only take on the values $0$ or $\\pm 1$, and then describe an alternative embedding of $\\pi$ in $\\zeta_m$ in the case where the score of $\\pi$ is $1$, except when $\\pi$ is a decreasing permutation of even size.\n\n\tRecall that the score of any word $\\pi$, $s(\\pi)$, is defined as the number of initial runs of the infinite zigzag word necessary to contain $\\pi$ minus the size of $\\pi$. As observed in the proof of Proposition~\\ref{prop-miller-words}, the score of a word does not change upon reading a letter of opposite parity. This implies that, while reading a layered permutation, the score changes only when transitioning from one layer to the next, and thus we compute the score of $\\pi$ layer-by-layer.\n\n\t\\renewcommand{\\OE}{\\textsf{odd}\\text{--}\\textsf{even}}\n\t\\newcommand{\\OO}{\\textsf{odd}\\text{--}\\textsf{odd}}\n\t\\newcommand{\\EE}{\\textsf{even}\\text{--}\\textsf{even}}\n\t\\newcommand{\\EO}{\\textsf{even}\\text{--}\\textsf{odd}}\n\n\t\\begin{figure}[ht]\n\t\\captionsetup{justification=centering}\n\t\t\\begin{footnotesize}\n\t\t\t\\begin{tikzpicture}[\n\t\t\t\tscale=1, \n\t\t\t\txscale=3, \n\t\t\t\tnode style/.style={thick, draw, ellipse, minimum width=68pt, minimum height = 16.66666pt, align=center}\n\t\t\t]\n\n\t\t\t\t\\draw (-1, 0) node[node style] (oe) {$\\OE$};\n\t\t\t\t\\draw ( 0,-1) node[node style] (ee) {$\\EE$};\n\t\t\t\t\\draw ( 0, 1) node[node style] (oo) {$\\OO$};\n\t\t\t\t\\draw ( 1, 0) node[node style] (eo) {$\\EO$};\n\t\t\t\t\n\t\t\t\t\\draw [->] (0,-{1.6}) to (0,-{1.333333});\n\t\t\t\t\n\t\t\t\t% \\draw [->] (eo) to (oo);\n\t\t\t\t\\draw [-] (+0.9, +0.4) to (+0.9,+0.8);\n\t\t\t\t\\draw [domain=0:90] plot ({+0.833333+0.066667*cos(\\x)}, {+0.8+0.2*sin(\\x)});\n\t\t\t\t\\draw [->] (+0.833333,+1.0) to (+0.425, +1.0);\n\t\t\t\t\\node at (0.8,0.8) {$-1$};\n\t\t\t\t\n\t\t\t\t% \\draw [->] (oo) to (oe);\n\t\t\t\t\\draw [-] (-0.425, 1.0) to (-0.833333,1.0);\n\t\t\t\t\\draw [domain=90:180] plot ({-0.833333+0.066667*cos(\\x)}, {0.8+0.2*sin(\\x)});\n\t\t\t\t\\draw [->] (-0.9,0.8) to (-0.9, 0.4);\n\t\t\t\t\\node at (-0.8,0.8) {$-1$};\n\t\t\t\t\n\t\t\t\t% \\draw [->] (oe) to (ee);\n\t\t\t\t\\draw [-] (-0.9, -0.4) to (-0.9,-0.8);\n\t\t\t\t\\draw [domain=180:270] plot ({-0.833333+0.066667*cos(\\x)}, {-0.8+0.2*sin(\\x)});\n\t\t\t\t\\draw [->] (-0.833333,-1.0) to (-0.5, -1.0);\n\t\t\t\t\\node at (-0.8,-0.8) {$+1$};\n\t\t\t\t\n\t\t\t\t% \\draw [->] (ee) to (eo);\n\t\t\t\t\\draw [-] (+0.5, -1.0) to (+0.833333,-1.0);\n\t\t\t\t\\draw [domain=270:360] plot ({+0.833333+0.066667*cos(\\x)}, {-0.8+0.2*sin(\\x)});\n\t\t\t\t\\draw [->] (+0.9,-0.8) to (+0.9, -0.4);\n\t\t\t\t\\node at (+0.8,-0.8) {$+1$};\n\t\t\t\t\n\t\t\t\t% \\draw [->] (oe) to (oe);\n\t\t\t\t\\newcommand\\hmargin{0.0666667}\n\t\t\t\t\\newcommand\\vmargin{0.2}\n\t\t\t\t\\newcommand\\leftloopleft{-1.45}\n\t\t\t\t\\newcommand\\leftloopright{-1.166667}\n\t\t\t\t\\newcommand\\loopupper{0.45}\n\t\t\t\t\\newcommand\\looplower{-\\loopupper}\n\t\t\t\t\n\t\t\t\t\\draw [-] (\\leftloopright+\\hmargin, 0.4) to (\\leftloopright+\\hmargin,\\loopupper);\n\t\t\t\t\\draw [domain=  0: 90] plot ({\\leftloopright+\\hmargin*cos(\\x)}, {\\loopupper+\\vmargin*sin(\\x)}); % NE corner\n\t\t\t\t\\draw [-] (\\leftloopright, \\loopupper+\\vmargin) to (\\leftloopleft,\\loopupper+\\vmargin);\n\t\t\t\t\\draw [domain= 90:180] plot ({\\leftloopleft+\\hmargin*cos(\\x)}, {\\loopupper+\\vmargin*sin(\\x)}); % NW corner\n\t\t\t\t\\draw [-] (\\leftloopleft-\\hmargin,\\loopupper) to (\\leftloopleft-\\hmargin, \\looplower);\n\t\t\t\t\\draw [domain=180:270] plot ({\\leftloopleft+\\hmargin*cos(\\x)}, {\\looplower+\\vmargin*sin(\\x)}); % SW corner\n\t\t\t\t\\draw [-] (\\leftloopright, \\looplower-\\vmargin) to (\\leftloopleft,\\looplower-\\vmargin);\n\t\t\t\t\\draw [domain=270:360] plot ({\\leftloopright+\\hmargin*cos(\\x)}, {\\looplower+\\vmargin*sin(\\x)}); % SE corner\n\t\t\t\t\\draw [->] (\\leftloopright+\\hmargin,\\looplower) to (\\leftloopright+\\hmargin, -0.4);\n\t\t\t\t\\node at (\\leftloopleft,\\loopupper) {$0$};\n\t\t\t\t\n\t\t\t\t% \\draw [->] (eo) to (eo);\n\t\t\t\t\\newcommand\\rightloopright{-\\leftloopleft}\n\t\t\t\t\\newcommand\\rightloopleft{-\\leftloopright}\n\n\t\t\t\t\\draw [-] (\\rightloopleft-\\hmargin,-0.4) to (\\rightloopleft-\\hmargin, \\looplower);\n\t\t\t\t\\draw [domain=180:270] plot ({\\rightloopleft+\\hmargin*cos(\\x)}, {\\looplower+\\vmargin*sin(\\x)}); % NE corner\n\t\t\t\t\\draw [-] (\\rightloopright, \\looplower-\\vmargin) to (\\rightloopleft,\\looplower-\\vmargin);\n\t\t\t\t\\draw [domain=270:360] plot ({\\rightloopright+\\hmargin*cos(\\x)}, {\\looplower+\\vmargin*sin(\\x)}); % NW corner\n\t\t\t\t\\draw [-] (\\rightloopright+\\hmargin,\\looplower) to (\\rightloopright+\\hmargin, \\loopupper);\n\t\t\t\t\\draw [domain=  0: 90] plot ({\\rightloopright+\\hmargin*cos(\\x)}, {\\loopupper+\\vmargin*sin(\\x)}); % SW corner\n\t\t\t\t\\draw [-] (\\rightloopright, \\loopupper+\\vmargin) to (\\rightloopleft,\\loopupper+\\vmargin);\n\t\t\t\t\\draw [domain= 90:180] plot ({\\rightloopleft+\\hmargin*cos(\\x)}, {\\loopupper+\\vmargin*sin(\\x)}); % SE corner\n\t\t\t\t\\draw [->] (\\rightloopleft-\\hmargin, \\loopupper) to (\\rightloopleft-\\hmargin,0.4);\n\t\t\t\t\\node at (\\rightloopright,\\looplower) {\\footnotesize$0$};\n\n\n\t\t\t\t\\node at (-0.8,-0.8) {$+1$};\n\n\t\t\t\t% \\draw [->] (oo) to (ee);\n\t\t\t\t\\draw [->] (-0.1,0.575) to (-0.1,-0.625);\n\t\t\t\t\\node at (-0.15,0) {$0$};\n\t\t\t\t\n\t\t\t\t% \\draw [->] (ee) to (oo);\n\t\t\t\t\\draw [->] (+0.1,-0.625) to (+0.1,+0.575);\n\t\t\t\t\\node at (+0.15,0) {$0$};\n\t\t\t\t\n\t\t\t\\end{tikzpicture}\n\t\t\\end{footnotesize}\n\t\t\\caption{A directed graph describing the scoring of a layered permutation.}\n\t\t\\label{fig-layered-zeta-automaton}\n\t\\end{figure}\n\n\tThe change in score when moving from one layer of $\\pi$ to the next is determined by the parity of the last entry of the layer we are leaving and the first entry of the layer we are entering. Specifically, the score changes by $-1$ if both of these entries are odd and $+1$ if both are even. This shows that in order to compute the score of the layered permutation $\\pi$, we simply need to know the parities of the first and last entries of each of its layers. This information is represented by the labels of the nodes of the directed graph shown in Figure~\\ref{fig-layered-zeta-automaton}.\n\n\tMoreover, not all transitions between these nodes are possible, because the last entry of a layer is precisely $1$ greater than the first entry of the preceding layer. This is why there are only eight edges shown in Figure~\\ref{fig-layered-zeta-automaton}. In this figure, each of those edges is labeled by the change in the score function. Note that the first layer must end with $1$ (an odd entry), and its first entry must be either odd (for a score of $0$) or even (for a score of $1$); this is equivalent to starting our walk on the graph in Figure~\\ref{fig-layered-zeta-automaton} at the node labeled $(\\EE)$ before any layers are read.\n\n\tFrom this graphical interpretation of the scoring process, it is apparent that the score of a layered permutation can take on only three values: $-1$ if it ends at the node $(\\OE)$; $0$ if it ends at either node $(\\EE)$ or $(\\OO)$; or $1$ if it ends at the node $(\\EO)$. Except in this final case, we are done.\n\n\tNow suppose that we are in the final case, so the ultimate layer of $\\pi$ is of $(\\EO)$ type. The first entry of this layer is the greatest entry of $\\pi$, so we know that $\\pi$ has even size. If $\\pi$ were a decreasing permutation then there would be nothing to prove (as we have not claimed anything in this case), so let us further suppose that $\\pi$ is not a decreasing permutation, and thus that $\\pi$ has at least two layers. We further divide this case into two cases. In both cases, as in the proof of Proposition~\\ref{prop-distant-inv-desc}, we construct a word $p\\in[m-1]^m$ such that if $z_m$ contains $p$, then $\\zeta_m$ contains $\\pi$.\n\n\tFirst, suppose that the penultimate layer of $\\pi$ is of $(\\EO)$ type and that this layer begins with the entry $\\pi(b)$. This implies that the penultimate layer of $\\pi$ has at least two entries (because its first and last entries have different parities). In this case, we define $p$ by\n\t\\[\n\t\tp(i)\n\t\t=\n\t\t\\left\\{\\begin{array}{ll}\n\t\t\t\\pi(i)&\\text{if $\\pi(i)<\\pi(b)$,}\\\\\n\t\t\t\\pi(i)-1&\\text{if $\\pi(i)\\ge\\pi(b)$.}\n\t\t\\end{array}\\right.\n\t\\]\n\tIn other words, to form $p$ from $\\pi$ we decrement the first entry of the penultimate layer and all entries of the ultimate layer. Because the penultimate layer of $\\pi$ has at least two entries, performing this operation creates an immediate repetition (of the entry $\\pi(b)-1$) at the beginning of this layer. For example, if $\\pi=21\\ 6543\\ 87$ then $\\pi(b)=6$ and we decrement the $6$, $8$, and $7$ to obtain the word $p=21\\ 5543\\ 76$.\n\n\tAs with our previous constructions, if $z_m$ contains an occurrence of $p$, then $\\zeta_m$ will contain a copy of $\\pi$. We establish that $z_m$ contains $p$ by showing that $s(p)=0$, which requires a further bifurcation into subcases. In both subcases, the scoring of $p$ is computed by considering its score in the antepenultimate layer (the layer immediately before the penultimate layer), the score change when reading the newly decremented first entry of the penultimate layer, the score penalty of $+1$ because $p$ contains an immediate repetition (namely, $\\pi(b)-1$ occurs twice in a row), and finally the score change between the penultimate and ultimate layers. We label these cases by the final three nodes of the directed graph from Figure~\\ref{fig-layered-zeta-automaton} visited while computing the score of $\\pi$.\n\t\\begin{itemize}\n\t\t\\item The final three layers are of type $(\\EE)(\\EO)(\\EO)$. Note that this case includes the possibility that $\\pi$ has only two layers. If $p$ has an antepenultimate layer, then the score while reading that layer is $0$ and the ascent between its last entry and the newly decremented first entry of the penultimate layer is of different parity (even to odd), contributing $0$ to the score. If $p$ does not have an antepenultimate layer, then $p$ begins with the newly decremented first entry of its penultimate layer, which contributes $0$ to the score. In either case, the score of $p$ is $0$ upon reading the first entry of the penultimate layer. The immediate repetition in the penultimate layer contributes $+1$ to the score, while the ascent between the last entry of the penultimate layer and the newly decremented first entry of the ultimate layer is odd and thus contributes $-1$, so $s(p) = 0$.\n\t\t\\item The final three layers are of type $(\\EO)(\\EO)(\\EO)$. The score while reading the antepenultimate layer is $+1$. The ascent between the last entry of the antepenultimate layer and the newly decremented first entry of the penultimate layer is odd, so it contributes $-1$ to the score, the immediate repetition in the penultimate layer contributes $+1$, and the ascent between the last entry of the penultimate layer and the newly decremented first entry of the ultimate layer is odd and thus contributes $-1$, so $s(p) = 0$.\n\t\\end{itemize}\n\n\tIt remains to treat the case where the penultimate layer is of $(\\EE)$ type. Note that this case includes the possibility that the penultimate layer consists of a single entry. Suppose that the penultimate layer ends with the entry $\\pi(a)$. We define $p$ by\n\t\\[\n\t\tp(i)\n\t\t=\n\t\t\\left\\{\\begin{array}{ll}\n\t\t\t\\pi(i)   &\\text{if $\\pi(i)<\\pi(a)$ or $\\pi(i)=m$,}\\\\\n\t\t\t\\pi(i)+1 &\\text{if $\\pi(i)\\ge\\pi(a)$ and $\\pi(i)\\neq m$.}\n\t\t\\end{array}\\right.\n\t\\]\n\tThus in forming $p$ from $\\pi$ we increment all entries of the penultimate layer and all but the first entry of the ultimate layer. For example, if $\\pi=21\\ 3\\ 654\\ 87$, then we increment the $6$, $5$, $4$, and $7$ to obtain the word $p=21\\ 3\\ 765\\ 88$.\n\n\tAs before, if $z_m$ contains an occurrence of $p$ then $\\zeta_m$ will contain a copy of $\\pi$. Thus we need only show that $s(p)=0$, which we do, as in the previous case, by considering the scoring of the final three layers. As in that case, we identify two subcases.\n\t\\begin{itemize}\n\t\t\\item The final three layers are of type $(\\OE)(\\EE)(\\EO)$. The score while reading the antepenultimate layer is $-1$. The ascent between the last entry of the antepenultimate layer and the newly incremented first entry of the penultimate layer is of different parity (even to odd) and thus contributes $0$ to the score. The ascent between the newly incremented last entry of the penultimate and the first entry of the ultimate layer (which is $m$) is of different parity (odd to even) and thus contributes $0$ to the score. Finally, the immediate repetition at the beginning of the ultimate layer (the two entries equal to $m$) contributes $+1$ to the score, so $s(p)=0$.\n\t\t\\item The final three layers are of type $(\\OO)(\\EE)(\\EO)$. The score while reading the antepenultimate layer is $0$. The ascent between the last entry of the antepenultimate layer and the newly incremented first entry of the penultimate layer contributes $-1$ to the score (as both entries are now odd). The ascent between the newly incremented last entry of the penultimate layer and the first entry of the ultimate layer (which is $n$) is of different parity (odd to even) and thus contributes $0$ to the score. Finally, the immediate repetition at the beginning of the ultimate layer contributes $+1$ to the score, so $s(p)=0$.\n\t\\end{itemize}\n\n\tAs we have considered all of the cases, the proof is complete.\n\\end{proof}\n\nIt remains only to conclude. The size of $\\zeta_m$ is $(m^2+1)/2$ when $m$ is odd and $m^2/2$ when $m$ is even. When $m$ is odd, we have established that $\\zeta_m$ is $m$-universal. However, Proposition~\\ref{prop-layered-zeta} shows that $\\zeta_m$ need not be universal when $m$ is even. (Indeed, it can be checked that $\\zeta_m$ is \\emph{not} $m$-universal when $m$ is even.) However, in this case, we know that $\\zeta_m$ contains the decreasing permutation $(m-1)\\cdots 21$ (for instance because it contains the permutation $(m-1)\\cdots 21\\oplus 1$). Thus we obtain an $m$-universal permutation by prepending a new maximum entry to $\\zeta_m$, giving us the following bound.\n\n\\begin{theorem}[Engen and Vatter~\\cite{engen:containing-all-:}]\n\\label{thm-perm-universal}\nThere is an $m$-universal permutation of size $\\ceil{(m^2+1)/2}$.\n\\end{theorem}\n\nA computer search reveals that the bound in Theorem~\\ref{thm-perm-universal} is best-possible for $m \\le 5$. Alas, for $m=6$ the $6$-universal permutation of Theorem~\\ref{thm-perm-universal}'s construction has size $19$, but Arnar Arnarson [private communication] has found that the permutation\n\\[\n\t6\\ 14\\ 10\\ 2\\ 13\\ 17\\ 5\\ 8\\ 3\\ 12\\ 9\\ 16\\ 1\\ 7\\ 11\\ 4\\ 15\n\\]\nof size $17$ is $6$-universal, and computations have shown that no smaller permutation suffices.\n\nArratia~\\cite[Conjecture 2]{arratia:on-the-stanley-:} conjectured that the size of the smallest $m$-universal permutations is asymptotic to $m^2/e^2$. In~\\cite{chroman:lower-bounds:}, Chroman, Kwan, and Singhal prove that any $m$-universal permutation must have size at least $(1.000076/e^2)m^2$ asymptotically, refuting Arratia's conjecture. In~\\cite{eriksson:dense-packing-o:}, Eriksson, Eriksson, Linusson, and W\\\"{a}stlund conjecture that the smallest $m$-universal permutations have size asymptotic to $m^2/2$, and in~\\cite{arratia:on-the-stanley-:}, Arratia presents Alon's conjecture that, asymptotically, most permutations of size $m^2/4$ are $m$-universal.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Proper Permutation Classes}\n\\label{sec-perm-proper}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nIn this section, we consider the problem of universality for proper permutation classes. For reference, some known or computed values of minimum sizes for universal permutations for various classes are presented in Appendix~\\ref{appendix-permutations}. Every class may be described as the set of permutations that avoid each element of a set of permutations, and the minimal such set is called the \\emph{basis} of the class. If $\\P$ is the set of permutations that avoid the set of permutations $S$, then we write $\\P = \\Av(S)$.\n\nThe pattern containment order is closely related to the induced subgraph order, a connection that frequently proves useful. If $\\pi$ is a permutation of size $n$, define the \\emph{inversion graph} of $\\pi$, denoted $\\g(\\pi)$, to be the graph with vertex set $[n]$ and edges $i \\sim j$ if and only if $i < j$ and $\\pi(i) > \\pi(j)$. Then, if $\\pi$ contains $\\tau$ as a pattern, then $\\g(\\pi)$ contains $\\g(\\tau)$ as an induced subgraph.\n\nFor any collection of permutations $\\P$, let $\\g(\\P) = \\{\\g(\\pi) \\st \\pi \\in \\P\\}$. Suppose that $\\G$ is a class of graphs with $\\G = \\g(\\P)$ for some permutation class $\\P$. If the permutation $\\pi$ is $\\P_m$-universal, then $\\g(\\pi)$ is $\\G(\\P)_m$-universal. Moreover, if $\\pi$ is a proper $\\P_m$-universal permutation, then $\\g(\\pi)$ lies in $\\G$, so $\\g(\\pi)$ is a proper $\\G_m$-universal graph. This shows that $\\u_\\G^p(m) \\le \\u_\\P^p(m)$, giving us the following rhombus of inequalities.\n\n\\begin{center}\n\\begin{tabular}{CCC}\n\t\\u_{\\G}(m) & \\le & \\u_{\\G}^{p}(m) \\\\\n\t  \\rotle   &     &     \\rotle     \\\\\n\t\\u_{\\P}(m) & \\le & \\u_{\\P}^{p}(m)\n\\end{tabular}\n\\end{center}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Layered Permutations}\n\\label{sec-perm-layered}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nRecall that a permutation is layered if it is the direct sum of decreasing permutations. Equivalently, a permutation is layered if it avoid the patterns $231$ and $312$. Let $\\Lay = \\Av(231,312)$ denote the class of layered permutations. Proposition~\\ref{prop-clusterize} shows that any graph may be transformed into a cluster graph of the same size that contains each cluster graph that the original graph contained. Similarly, the following proposition, which appears in~\\cite{albert:universal-layer:}, shows that any permutation may be transformed into a layered permutation of the same size while retaining each of its layered containments.\n\n\\begin{proposition}[Albert, Engen, Pantone, and Vatter~\\cite{albert:universal-layer:}]\n\\label{prop-layerize}\n\tGiven any permutation $\\pi$ of size $n$, there is a layered permutation of size $n$ that contains every layered permutation contained in $\\pi$.\n\\end{proposition}\n\\begin{proof}\n\tWe prove the claim by induction on $n$. Note that the base case is trivial, and let $\\pi$ be a permutation of size $n \\ge 1$. Let $D$ denote a decreasing subsequence of $\\pi$ of maximum possible size. Because $D$ is a maximal decreasing subsequence, every entry of $\\pi$ that is not in $D$ must either lie to the southwest of an entry of $D$ or to the northeast of such an entry, but not both. Let $D^-$ denote the set of entries that lie to the southwest of an entry of $D$ and let $D^+$ denote the set of entries that lie to the northeast of such an entry, so that $D$, $D^-$, and $D^+$ together constitute a partition of the entries of $\\pi$. An example of this decomposition is shown on the leftmost panel of Figure~\\ref{fig-layerization}.\n\n\tDefine $\\pi^-$ (resp., $\\pi^+$) to be the permutation in the same relative order as the entries of $D^-$ (resp., $D^+$). Let $\\delta$ be the decreasing permutation of size $\\size{D}$, and define $\\pi^\\ast = \\pi^-\\directsum\\delta\\directsum\\pi^+$. Thus, in some sense, $\\pi^\\ast$ is a ``straightened-out'' version of $\\pi$, and an example is shown in the central panel of Figure~\\ref{fig-layerization}.\n\n\t\\begin{figure}[h]\n\t\\captionsetup{justification=centering}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[scale=0.25, baseline=(current bounding box.center)]\n\t\t\t\t\\draw [darkgray, very thick, fill=lightgray] (0.5,11.5) rectangle (4,10);\n\t\t\t\t\\draw [darkgray, very thick, fill=lightgray] (4,10) rectangle (6,9);\n\t\t\t\t\\draw [darkgray, very thick, fill=lightgray] (6,9) rectangle (8,8);\n\t\t\t\t\\draw [darkgray, very thick, fill=lightgray] (8,8) rectangle (9,7);\n\t\t\t\t\\draw [darkgray, very thick, fill=lightgray] (9,7) rectangle (11,2);\n\t\t\t\t\\draw [darkgray, very thick, fill=lightgray] (11,2) rectangle (11.5,0.5);\n\t\t\t\t\\plotperm{3, 5, 4, 10, 1, 9, 6, 8, 7, 11, 2};\n\t\t\t\t\\draw [darkgray, very thick] (0.5,0.5) rectangle (11.5,11.5);\n\t\t\t\t\\node at (5.5,4.5) {$D^-$};\n\t\t\t\t\\node at (10.25,9.25) {$D^+$};\n\t\t\t\\end{tikzpicture}\n\t\t\t\\quad\\quad\\quad\n\t\t\t\\begin{tikzpicture}[scale=0.25, baseline=(current bounding box.center)]\n\t\t\t\t\\plotperm{2,4,3,5,1,10,9,8,7,6,11};\n\t\t\t\t\\draw [darkgray, very thick] (0.5,0.5) rectangle (11.5,11.5);\n\t\t\t\t\\draw [darkgray, very thick] (0.5,0.5) rectangle (5.5,5.5);\n\t\t\t\t\\draw [darkgray, very thick] (5.5,5.5) rectangle (10.5,10.5);\n\t\t\t\t\\draw [darkgray, very thick] (10.5,10.5) rectangle (11.5,11.5);\n\t\t\t\\end{tikzpicture}\n\t\t\t\\quad\\quad\\quad\n\t\t\t\\begin{tikzpicture}[scale=0.25, baseline=(current bounding box.center)]\n\t\t\t\t\\plotperm{1,4,3,2,5,10,9,8,7,6,11};\n\t\t\t\t\\draw [darkgray, very thick] (0.5,0.5) rectangle ++(11,11);\n\t\t\t\t\\draw [darkgray, very thick] (0.5,0.5) %\n\t\t\t\t\trectangle ++(5,5) % \n\t\t\t\t\trectangle ++(5,5) %\n\t\t\t\t\trectangle ++(1,1);\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\\caption{The steps in the proof of Proposition~\\ref{prop-layerize}. From left to right, the drawings show an example of $\\pi$, of $\\pi^\\ast$, and of the layered permutation $\\tau^- \\directsum \\delta \\directsum \\tau^+$.}\n\t\\label{fig-layerization}\n\t\\end{figure}\n\n\tWe claim that every layered permutation contained in $\\pi$ is also contained in $\\pi^\\ast$. Suppose $\\lambda=\\lambda_{1}\\directsum\\cdots\\directsum\\lambda_\\ell$ is a layered permutation contained in $\\pi$, where each $\\lambda_{i}$ is a decreasing permutation, and fix an embedding of $\\lambda$ into $\\pi$. Choose $j$ maximally so that in this embedding of $\\lambda$ into $\\pi$, the layers $\\lambda_{1}\\directsum\\cdots\\directsum\\lambda_{j-1}$ are embedded entirely using entries in $D^-$. It follows that the entries of $\\lambda_{j+1}\\directsum\\cdots\\directsum\\lambda_\\ell$ are embedded entirely using entries of $D^+$. Since $\\lambda_j$ certainly embeds into $D$ and consequently into $\\delta$, we have that $\\lambda \\le \\pi^\\ast$.\n\n\tFinally, by induction we see that there are layered permutations $\\mu^-$ and $\\mu^+$ that contain all of the layered permutations contained in $\\pi^-$ and $\\pi^+$, respectively. It follows that $\\mu^- \\directsum \\delta \\directsum \\mu^+$ is layered and contains all of the layered permutations contained in $\\pi^\\ast$, which in turn contains all of the layered permutations contained in $\\pi$, proving the proposition. An example of this final construction is shown in the rightmost panel of Figure~\\ref{fig-layerization}.\n\\end{proof}\n\nIn particular, any $\\Lay_m$-universal permutation may be transformed into a layered permutation of the same size that is still $\\Lay_m$-universal, affirming a conjecture of Gray~\\cite{gray:bounds-on-super:}. Thus, among the smallest $\\Lay_m$-universal permutations there are proper $\\Lay_m$-universal permutations, establishing following corollary, which appears in~\\cite{albert:universal-layer:}.\n\\begin{corollary}[Albert, Engen, Pantone, and Vatter~\\cite{albert:universal-layer:}]\n\tFor all integers $m \\ge 0$, the smallest proper $\\Lay_m$-universal permutations are also smallest $\\Lay_m$-universal permutations.\n\\end{corollary}\n\nWe note that if $\\lambda$ and $\\mu$ are layered permutations with layer lengths $\\lambda_1, \\cdots, \\lambda_m$ and $\\mu_1, \\cdots, \\mu_n$ respectively, then we have $\\lambda \\le \\mu$ if and only if there are indices $i_1 < i_2 < \\cdots < i_m$ so that $\\lambda_{j} \\le \\mu_{i_j}$ for all $j$. Therefore the poset of layered permutations is isomorphic to the poset of compositions under the generalized subword order discussed in Chapter~\\ref{chap-compositions}. As in any question of universality for classes of layered permutations we may assume that the containing permutation is layered, we may reduce each such question to the corresponding question of universality for composition classes. Theorem~\\ref{thm-comp-universal}, adapted from~\\cite{albert:universal-layer:}, gives a precise formula for the size of the smallest $m$-universal compositions, and thus a formula for the size of the smallest $\\Lay_m$-universal permutations.\n\\begin{corollary}[Albert, Engen, Pantone, and Vatter~\\cite{albert:universal-layer:}]\n\\label{cor-perm-layered}\n\tFor all integers $m \\ge 0$, the smallest (proper) $\\Lay_m$-universal permutations have size $\\ell(m) = (m+1)\\ceil{\\log_2 (m+1)} - 2^{\\ceil{\\log_2 (m+1)}} + 1$.\n\\end{corollary}\n\nCorollary~\\ref{cor-perm-layered} improves upon lower and upper bounds of $\\oOmega{m \\log m}$ and $m \\log_2 m + m$ respectively proven by Bannister, Cheng, Devanny, and Eppstein~\\cite{bannister:superpatterns-a:} as well as lower and upper bounds of $m \\log m - m$ and $m \\floor{\\log_2 m} + m$ respectively proven by Gray~\\cite{gray:bounds-on-super:}.\n\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\subsection{A Constructive Upper Bound}\n% \\label{subsec-a-constructive-upper-bound}\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nThe recursive construction used to prove Theorem~\\ref{thm-comp-universal} can be repurposed to construct universal permutations for classes using direct sums. Let $\\P$ be a permutation class and let $\\P^{\\sumind}$ denote the set of those permutations in $\\P$ that are sum-indecomposable. For each permutation $\\pi \\in \\P$, decompose $\\pi$ as $\\pi_{1} \\directsum \\cdots \\directsum \\pi_{m}$, where each $\\pi_i$ is a nonempty sum-indecomposable permutation. Define $\\comp(\\pi)$ to be the composition $\\size{\\pi_{1}} \\size{\\pi_{2}} \\cdots \\size{\\pi_{m}}$ and let $\\comp(\\P) = \\{\\comp(\\pi) \\st \\pi \\in \\P\\}$.\n\n\\begin{proposition}\n\\label{prop-an-upper-bound}\n\tSuppose that for each $m \\le n$ the permutation $\\tau_m$ is $\\P^{\\sumind}_m$-universal. If the composition $c = c(1) \\cdots c(n)$ is $\\comp(\\P)_m$-universal, then the permutation $\\tau_{c(1)} \\directsum \\tau_{c(2)} \\cdots \\directsum \\tau_{c(n)}$ is $\\P_m$-universal.\n\\end{proposition}\n\\begin{proof}\n\tLet $\\pi \\in \\P_n$, and write $\\pi = \\pi_{1} \\directsum \\cdots \\directsum \\pi_{k}$, where each $\\pi_{i}$ is a nonempty sum-indecomposable permutation. Then as $c$ is $\\comp(\\P)_n$-universal, there must be some sequence of indices $1 \\le i_1 < i_2 < \\cdots < i_k \\le n$ such that $\\size{\\pi_{j}} \\le c(i_j)$ for all $j$. As $\\tau_{c(i_j)}$ is $c(i_j)$-universal, $\\pi_{j}$ embeds into $\\tau_{c(i_j)}$, and we have that $\\tau_{c(1)} \\directsum \\tau_{c(2)} \\cdots \\directsum \\tau_{c(n)}$ contains $\\pi$, as desired.\n\\end{proof}\n\nWe now present a two brief applications of Proposition~\\ref{prop-an-upper-bound}. As our first example, let $\\Q = \\Av(132, 231, 321) = \\{\\varepsilon\\} \\cup \\{(1 \\skewsum \\iota_a) \\directsum \\iota_b \\st a, b \\ge 0\\}$. Then, using vocabulary introduced in Chapter~\\ref{chap-compositions}, $\\comp(\\P) = \\Age(\\omega 1^\\omega)$ is the class of compositions in which every part after the first is $1$. The composition $m 1^{m-1}$ is $\\Age(\\omega 1^\\omega)_m$-universal for each $m$, and the permutation $1 \\skewsum \\iota_{m-1}$ is $m$-universal for the set $\\Q^{\\sumind} = \\{1 \\skewsum \\iota_a \\st a \\ge 0\\}$ of sum-indecomposable permutations in $\\Q$. Thus, by Proposition~\\ref{prop-an-upper-bound}, the permutation $(1 \\skewsum \\iota_{m-1}) \\directsum \\iota_{m-1}$ is $\\Q_m$-universal.\n\\begin{proposition}\n\tThe permutation $(1 \\skewsum \\iota_{m-1}) \\directsum \\iota_{m-1}$ is $m$-universal for $\\Av(132, 231, 321)$.\n\\end{proposition}\n\nFor our second example, let $\\P = \\Av(231, 321)$. Then $\\P^{\\sumind} = \\{1 \\skewsum \\iota_k \\st k \\ge 0\\}$ contains permutations of all sizes, and as $\\P$ is closed under direct sums, $\\comp(\\P)$ is the class of all compositions. The composition $w_m$ defined by $w_0 = \\varepsilon$ and, for $m \\ge 1$,\n\\[\n\tw_m\n\t=\n\tw_{\\floor{(m-1)/2}} m w_{\\ceil{(m-1)/2}}\n\\]\nof length $m$ and size $\\ell(m)$ defined in Chapter~\\ref{chap-compositions} is $m$-universal, and the permutation $\\tau_m = 1 \\skewsum \\iota_{m-1}$ is $\\P^{\\sumind}_m$-unviersal. Thus the permutation $\\sigma_m$ defined as $\\sigma_0 = \\varepsilon$ and for $m \\ge 1$\n\\[\n\t\\sigma_m\n\t=\n\t\\sigma_{\\floor{(m-1)/2}}\n\t\\directsum\n\t\\tau_m\n\t\\directsum\n\t\\sigma_{\\ceil{(m-1)/2}}\n\\]\nof size $\\ell(m)$ is $\\P_m$-universal by Proposition~\\ref{prop-an-upper-bound}. As $\\P$ is closed under direct sums and $\\tau_m \\in \\P$ for each $m$, each $\\sigma_m$ lies in $\\P$ and is thus a proper $\\P_m$-universal permutation.\n\\begin{proposition}\n\\label{prop-perm-231-321-univ-proper}\n\tLet $\\sigma_0 = \\varepsilon$ and, for $m \\ge 1$,\n\t\\[\n\t\t\\sigma_m\n\t\t=\n\t\t\\sigma_{\\floor{(m-1)/2}}\n\t\t\\directsum\n\t\t(m 1 2 \\cdots (m-1))\n\t\t\\directsum\n\t\t\\sigma_{\\ceil{(m-1)/2}}.\n\t\\]\n\tThen $\\sigma_m$ of size $\\ell(m)$ is $m$-universal for $\\Av(231, 321)_m$-universal for all $m$.\n\\end{proposition}\n\nThe permutations $\\sigma_m$ are in fact asymptotically optimal, in the sense that their size is asymptotic to the size of the smallest proper $\\P_m$-universal permutations as the next result shows.\n\n\\begin{theorem}\n\\label{thm-perm-231-321-proper}\n\tLet $\\P = \\Av(231, 321)$, and let $S = \\{\\pi \\in \\P \\st \\pi(1) \\neq 1\\}$. Let $s(m)$ denote the minimum size of an $S_m$-universal permutation in $\\P$. Then $s(0) = s(1) = 0$, and for $m \\ge 2$,\n\t\\[\n\t\ts(m)\n\t\t\\ge\n\t\tm + \\min\\{s(k) + s(m-k-1) \\st 1 \\le k \\le m-1\\}.\n\t\\]\n\\end{theorem}\nThe proof of Theorem~\\ref{thm-perm-231-321-proper} is similar to that of the lower bound of Theorem~\\ref{thm-comp-universal}, so it may serve the reader well to ``warm up'' with that proof first.\n\\begin{proof}\n\tWe proceed by induction on $m$. Each of $S_0$ and $S_1$ are empty, so the empty pattern is both $S_0$- and $S_1$-universal, and thus $s(0) = s(1) = 0$. \n\n\tLet $m \\ge 2$. Suppose that $\\pi \\in \\P$ is an $S_m$-universal permutation and write $\\pi = \\pi_{1} \\directsum \\cdots \\directsum \\pi_\\ell$, where each $\\pi_j$ is sum-indecomposable. Then at least one $\\pi_j$ has size at least $m$, as $\\pi$ must contain the pattern $m 1 2 \\cdots (m-1)$ and must do so entirely within one summand $\\pi_j$. Suppose $\\size{\\pi_j} \\ge m$, and choose $k \\ge 1$ so that\n\t\\[\n\t\ts(k)\n\t\t\\le\n\t\t\\size{\\pi_{1} \\directsum \\cdots \\directsum \\pi_{j-1}}\n\t\t<\n\t\ts(k+1).\n\t\\]\n\tAs $\\size{\\pi_{1} \\directsum \\cdots \\directsum \\pi_{j-1}} < s(k+1)$, there must be some $\\sigma \\in S_k$ that does not embed into $\\pi_{1} \\directsum \\cdots \\directsum \\pi_{j-1}$. Therefore the earliest that $\\sigma$ may embed into $\\pi$ is into $\\pi_{1} \\directsum \\cdots \\directsum \\pi_{j}$. In particular, the earliest that the last summand of $\\sigma$ may embed into $\\pi$ is into $\\pi_{j}$. \n\t\n\tFor any pair of sum-indecomposable permutations $\\tau, \\rho \\in \\P$, the permutation $\\tau \\directsum \\rho$ necessarily contains the pattern $132$ as $\\rho$ necessarily contains the pattern $12$. Thus $\\pi_j$ must avoid $\\tau \\directsum \\rho$, as every sum-indecomposable permutation in $\\P$ is of the form $1 \\skewsum \\iota_n$ for some $n$, and thus must avoid the pattern $132$. Thus, if $\\rho^\\ast \\in S_{m-k-1}$, then its first sum-component $\\rho$ has size at least $2$ (as its first sum-component cannot by $1$ by definition,) and so any embedding of $\\sigma \\directsum \\rho^\\ast$ into $\\pi$ embeds $\\rho^\\ast$ entirely within $\\pi_{j+1} \\directsum \\cdots \\directsum \\pi_\\ell$. As $\\rho^\\ast$ is an abitrary permutation in $S_{m-k-1}$, it follows that $\\pi_{j+1} \\directsum \\cdots \\directsum \\pi_\\ell$ is a $S_{m-k-1}$-universal permutation in $\\P$, and thus $\\size{\\pi_{j+1} \\directsum \\cdots \\directsum \\pi_\\ell} \\ge s(m-k-1)$. Together, we have\n\t\\begin{align*}\n\t\t\\size{\\pi}\n\t\t\t&= \\size{\\pi_{1} \\directsum \\cdots \\directsum \\pi_{j-1} \\directsum \\pi_j \\directsum \\pi_{j+1} \\directsum \\cdots \\directsum \\pi_\\ell} \\\\\n\t\t\t&= \\size{\\pi_{1} \\directsum \\cdots \\directsum \\pi_{j-1}} + \\size{\\pi_j} + \\size{\\pi_{j+1} \\directsum \\cdots \\directsum \\pi_\\ell} \\\\\n\t\t\t& \\ge s(k) + m + s(m-k-1) \\\\\n\t\t\t& \\ge m + \\min\\{s(k) + s(m-k-1) \\st 1 \\le k \\le m-1\\},\n\t\\end{align*}\n\tas desired.\n\\end{proof}\n\nLet $t(0) = t(1) = 0$ and $t(m) = m + \\min\\{t(k)+t(m-k-1) \\st 1 \\le k \\le m-1\\}$, then one can show that $t(m) \\ge \\ell(m) - m$ by induction, and Theorem~\\ref{thm-perm-231-321-proper} implies that every proper $\\P_m$-universal permutations has size at least $t(m)$. Together with the upper bound of $\\ell(m)$ provided by Proposition~\\ref{prop-perm-231-321-univ-proper}, we have have that the smallest proper $\\P_m$-universal permutations have size between $\\ell(m) - m$ and $\\ell(m)$, meaning they have size asymptotic to $\\ell(m) \\sim m \\log_2 m$.\n\nSupported by computational evidence, we conjecture that the size of the smallest (proper) $\\P_m$-universal permutations is in fact equal to $\\ell(m)$.\n\\begin{conjecture}\n\tFor all $m \\ge 0$, the smallest (proper) $m$-universal permutations for $\\Av(231, 321)$ have size $\\ell(m)$.\n\\end{conjecture}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Grid Classes}\n\\label{subsec-grid-classes}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nOne well-studied family of permutation classes are the monotone grid classes. Roughly speaking, the grid class of a matrix $M$ is the collection of permutations whose plots may be divided, in a manner prescribed by $M$, into blocks each containing a monotone pattern. More formally, let $M$ be a $0/ \\pm 1$ matrix with $t$ columns and $u$ rows. An \\emph{$M$-gridding} of the permutation $\\pi$ of size $n$ is a choice of column divisions $0 = c_0 \\le c_1 \\le \\dots \\le c_t = n$ and row divisions $0 = r_0 \\le r_1 \\le \\dots \\le r_u = n$ such that for all $i$ and $j$, the subsequence of $\\pi$ with indices in the real interval $(c_{i-1}, c_i]$ and values in the real interval $(r_{j-1}, r_j]$ is increasing if $M_{i,j} = 1$, decreasing if $M_{i,j} = -1$, and empty if $M_{i,j} = 0$. The \\emph{grid class} of $M$, denote $\\Grid{M}$, is the collection of all permutations that admit an $M$-gridding. An example of an $M$-gridding of a permutation for some matrix $M$ is drawn in Figure~\\ref{fig-m-gridding}.\n\n\\begin{figure}\n\\captionsetup{justification=centering, margin=0.5in}\n\t\\begin{tikzpicture}[scale={1/4}]\n\t\t\\plotperm{2, 4, 12, 11, 1, 3, 5, 6, 8, 7, 9, 10}\n\t\t\\draw[draw=gray!75, very thick] (0.5,0.5) rectangle ++(12,12);\n\t\t\\draw[draw=gray!75, very thick] (2.5,0.5) -- ++(0,12);\n\t\t\\draw[draw=gray!75, very thick] (9.5,0.5) -- ++(0,12);\n\t\t\\draw[draw=gray!75, very thick] (0.5,6.5) -- ++(12,0);\n\t\\end{tikzpicture}\n\\caption{A $\\left(\\begin{smallmatrix} 0 & -1 & 1\\\\ 1 & 1 & 0 \\end{smallmatrix}\\right)$-gridding of a permutation $\\pi$. As $\\pi$ admits such a gridding, we write $\\pi \\in \\gridVertThree{1,0}{1,-1}{0,1}$.}\n\\label{fig-m-gridding}\n\\end{figure}\n\nTo aid comprehension, we denote grid classes by their \\emph{cell diagrams} rather than by their matrices. For example, we abbreviate $\\Grid{\\begin{smallmatrix} 0 & -1 & 1\\\\ 1 & 1 & 0 \\end{smallmatrix}}$ as $\\gridVertThree[{1/3}]{1,0}{1,-1}{0,1}$. Occasionally, where it is convenient, we use a cell diagram to stand for the matrix itself.\n\nWe begin the results portion of this subsection with an observation useful for providing lower bounds on the size of proper universal permutations for grid classes.\n\n\\begin{observation}\n\\label{obs-grid-points}\n\tLet $\\P = \\Grid{M}$ be a grid class, and let $\\sigma, \\pi \\in \\P$. If in every $M$-gridding of $\\sigma$ there are $k$ points in cell $M_{i,j}$ and $\\sigma \\le \\pi$, then in every $M$-gridding of $\\pi$ there are at least $k$ points in the cell $M_{i,j}$.\n\\end{observation}\n\nAs one simple example where Observation~\\ref{obs-grid-points} is useful, let $M = \\gridHorizTwo[{1/3}]{1}{1}$ and consider the grid class $\\P = \\Grid{M}$. In the unique $M$-gridding of the permutation $m 12 \\cdots (m-1)$, the lower cell of $M$ contains $m-1$ points, and thus any $M$-gridding of any proper $\\P_m$-universal permutation must place at least $m-1$ points the lower cell of $M$. Likewise, the unique $M$-gridding of the permutation $2 \\cdots m1$ places $m-1$ points in the upper cell of $M$, and thus any $M$-gridding of any proper $\\P_m$-universal permutation must place at least $m-1$ points in the upper cell of $M$. Together, these observations show that any proper $\\P_m$-universal permutation must have at least $2(m-1)$ points, which is nearly optimal as we will see shortly in Theorem~\\ref{thm-perm-riffle}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Wedge Permutations and Riffle Shuffle Permutations}\n\\label{subsec-wedgle-riffle}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nUp to symmetry, the two simplest non-trivial grid classes are $\\gridVertOne[{1/3}]{-1,-1}$ and $\\gridVertOne[{1/3}]{-1,1}$. In this section, we show that both classes have smallest (proper) $m$-universal permutations of size $2m-1$. To begin, let $\\W = \\Av(132, 312) = \\gridVertOne[{1/3}]{1,-1}$ denote the class of non-empty \\emph{wedge} permutations. In~\\cite{bannister:superpatterns-a:}, Bannister, Cheng, Devanny, and Eppstein prove that $\\W$ has smallest (proper) universal permutations of size $2m-1$, and below we provide a proof of this fact. To begin, we show that the poset of nonempty wedge permutations is isomorphic to the poset of words over a two-letter alphabet, discussed in generality in Section~\\ref{sec-words}.\n\n\\begin{proposition}\n\\label{prop-perm-wedge-isomorphism}\nDefine the map $P: \\{p, m\\}^\\ast \\to \\W$ recursively as follows:\n\\begin{enumerate}\n\t\\item $P(\\varepsilon) = 1$ is the permutation of size $1$.\n\t\\item $P(vp) = P(v) \\directsum 1$ is the direct sum of $P(v)$ with the pattern $1$.\n\t\\item $P(vm) = P(v) \\skewsum 1$ is the skew sum of $P(v)$ with the pattern $1$.\n\\end{enumerate}\nThen $P$ is a poset isomorphism.\n\\end{proposition}\n\nThe map $P$ sends words of size $m$ to permutations of size $m+1$, so we omit the $0$-pattern from $\\W$. Before proving Proposition~\\ref{prop-perm-wedge-isomorphism}, we present a useful lemma.\n\\begin{lemma}\n\\label{lemma-perm-sum}\nIf $\\pi$ and $\\sigma$ are permutations, then\n\\begin{enumerate}\n\t\\item $\\pi \\directsum 1 \\le \\sigma \\directsum 1$ if and only if $\\pi              \\le \\sigma$.\n\t\\item $\\pi \\directsum 1 \\le \\sigma \\skewsum   1$ if and only if $\\pi \\directsum 1 \\le \\sigma$.\n\t\\item $\\pi \\skewsum   1 \\le \\sigma \\directsum 1$ if and only if $\\pi \\skewsum   1 \\le \\sigma$.\n\t\\item $\\pi \\skewsum   1 \\le \\sigma \\skewsum   1$ if and only if $\\pi              \\le \\sigma$.\n\\end{enumerate}\n\\end{lemma}\n\nWe now present the proof of Proposition~\\ref{prop-perm-wedge-isomorphism}.\n\n\\newenvironment{proof-of-prop-perm-wedge-isomorphism}{%\n\t\\medskip\\noindent {\\it Proof of Proposition~\\ref{prop-perm-wedge-isomorphism}.\\/}%\n}{%\n\t\\qed\\bigskip%\n}\n\\begin{proof-of-prop-perm-wedge-isomorphism}\n\tWe begin by proving that if $v, w \\in \\{p, m\\}^\\ast$ with $v \\le w$, then $P(v) \\le P(w)$.\n\n\tLeveraging the recursive nature of the map $P$, we proceed by induction on the size of $v$. For our base case, note that if $v$ is the empty word, then $P(v) = 1$, which is contained in every non-empty permutation. Thus, assume that $v$ is a non-empty word, let $\\ell$ be the final letter of $v$, and write $v = v_0 \\ell$. Let $w \\in \\{p, m\\}^\\ast$ be any word with $v \\le w$. As $v$ is a subsequence of $w$, we may write $w = w_0 \\ell v_1$, where $v_0 \\le w_0$. By induction, we have $P(v_0) \\le P(w_0)$. By Lemma~\\ref{lemma-perm-sum}, we have $P(v_0\\ell) \\le P(w_0\\ell)$ no matter the value of $\\ell$. Finally, as $P(w_0\\ell) \\le P(w_0\\ell w_1)$, we have\n\t\\[\n\t\tP(v) \n\t\t=\n\t\tP(v_0\\ell)\n\t\t\\le\n\t\tP(w_0\\ell)\n\t\t\\le\n\t\tP(w_0\\ell w_1)\n\t\t=\n\t\tP(w),\n\t\\]\n\tas desired.\n\n\tFor the converse, we show that if $P(v)$ and $P(w)$ are permutations with $P(v) \\le P(w)$, then $v \\le w$. Again, we proceed by induction on the size of $v$ and begin by noting that the permutation $P(\\varepsilon) = 1$ is contained in every permutation in $\\W$, and the empty word $\\varepsilon$ is contained in every word in $\\{p, m\\}^\\ast$, so the base case is satisfied.\n\n\tLet $P(v)$ and $P(w)$ be permutations with $P(v) \\le P(w)$ and $\\size{P(v)} \\ge 2$, or equivalently, $\\size{v} \\ge 1$. Without loss of generality, assume that $v = v_0 p$ and $w = w_0 p m^k$ for some $k \\ge 0$. Repeated applications of Lemma~\\ref{lemma-perm-sum} mean that $P(v_0 p) \\le P(w_0 p m^k)$ implies that $P(v_0) \\le P(w_0)$. By induction we must have $v_0 \\le w_0$, and thus $v_0 p \\le w_0 p m^k$, completing the proof.\n\\end{proof-of-prop-perm-wedge-isomorphism}\n\nOne consequence of this isomorphism is that the smallest universal words constructed in Section~\\ref{sec-words} translate into smallest proper universal permutations for $\\W$.\n\\begin{corollary}\n\\label{cor-perm-wedge-proper}\n\tThe smallest proper $\\W_m$-universal permutations have size $2m-1$.\n\\end{corollary}\n\nAs $\\W_m$ contains both $12 \\cdots m$ and $m \\cdots 21$, any $\\W_m$-universal permutation must contain a length-$m$ increasing subsequence as well as a length-$m$ decreasing subsequence. As these subsequences may not intersect in more than one entry, any $\\W_m$-universal permutation must have size at least $2m-1$, so no smaller $\\W_m$-universal permutation exists outside $\\W$.\n\n\\begin{corollary}\n\\label{cor-perm-wedge-improper}\n\tThe smallest (proper) $\\W_m$-universal permutations have size $2m-1$.\n\\end{corollary}\n\nThe other $2 \\times 1$ grid class is $\\R = \\Av(123, 3412, 3142) = \\gridVertOne{-1,-1}$, the class of \\emph{riffle shuffle} permutations, so called as they are precisely those patterns that may be formed by a single riffle shuffle of a deck of $n$ cards. In~\\cite{bannister:small-superpatt:}, Bannister, Devanny, and Eppstein prove that the permutation $(m+1)1(m+2)2\\cdots(2m-1)(m-1) \\in \\R$ is $\\R_m$-universal. This construction may be seen to be optimal, as we now show. Consider the layered permutation class $\\P = \\gridVertTwo[{1/3}]{-1,0}{0,-1}$. By Proposition~\\ref{prop-layerize}, the minimum size of a $\\P_m$-universal permutation is the same as the minimum size of an $m$-universal composition for the composition class $\\Age(\\omega^2)$, which is $2m-1$ by Proposition~\\ref{prop-comp-length-2-improper}. As $\\P \\subseteq \\R$, the smallest $\\R_m$-universal permutation must have size at least $2m-1$, and thus the construction by Bannister, Devanny, and Eppstein is optimal.\n\n\\begin{theorem}\n\\label{thm-perm-riffle}\n\tLet $\\R = \\gridVertOne[{1/3}]{-1,-1}$. The smallest (proper) $\\R_m$-universal permutations have size $2m-1$ for $m \\ge 1$.\n\\end{theorem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{\\texorpdfstring{$\\{123, 312\\}$}{(123, 312)}-avoiding Permutations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nOne immediate consequence of Theorem~\\ref{thm-perm-riffle} is that any class of permutations that contains $\\gridVertTwo[{1/3}]{-1,0}{0,-1}$ and is contained in $\\gridVertOne[{1/3}]{-1,-1}$ must have smallest $m$-universal permutations of size $2m-1$. The class $\\gridVertThree[{2/9}]{0,-1,0}{0,0,-1}{-1,0,0}$ meets this criteria, and thus the corollary below follows.\n\\begin{corollary}\n\\label{cor-perm-123-312-improper}\n\tLet $\\P = \\Av(123, 312) = \\gridVertThree[{2/9}]{0,-1,0}{0,0,-1}{-1,0,0}$. For each $m \\ge 1$, the smallest $\\P_m$-universal permutations have size $2m-1$.\n\\end{corollary}\n\nThe size of the smallest proper $\\Av(123, 312)_m$-universal permutations is slightly larger, as the following theorem shows.\n\\begin{theorem}\n\tLet $\\P = \\Av(123, 312) = \\gridVertThree[{2/9}]{0,-1,0}{0,0,-1}{-1,0,0}$. For each $m \\ge 3$, the smallest proper $\\P_m$-universal permutations have size $3m-4$.\n\\end{theorem}\n\\begin{proof}\n\tTo begin, we claim that the permutation $\\pi = (\\delta_{m-1} \\directsum \\delta_{m-1}) \\skewsum \\delta_{m-2}$ is $\\P_m$-universal. Let $\\sigma \\in \\P_m$. If $\\sigma$ avoids $12$, then $\\sigma$ is the decresing permutation of size $m$, and as $\\pi$ contains $\\delta_{m-2} \\skewsum \\delta_{m-1} = \\delta_{2m-3}$ and $2m-3 \\ge m$, we have that $\\pi$ contains $\\sigma$. Otherwise, $\\sigma$ contains $12$, and we may decompose $\\sigma$ as $\\sigma = (\\delta_a \\directsum \\delta_b) \\skewsum \\delta_c$ for nonnegative integers $a, b, c$ with $a, b \\ge 1$ and $a + b + c = m$. In this case, both $a$ and $b$ must be at most $m-1$, and $c$ must be at most $m-2$, which implies that $\\sigma$ is contained in $(\\delta_{m-1} \\directsum \\delta_{m-1}) \\skewsum \\delta_{m-2} = \\pi$.\n\n\tLet $M$ be the matrix $\\gridVertThree[{2/9}]{0,-1,0}{0,0,-1}{-1,0,0}$. To establish a lower bound, we show that in any $M$-gridding of a proper $\\P_m$-universal permutation, the lower-right cell must have at least $m-2$ points and both the leftmost cell and topmost cell must each have at least $m-1$ points.\n\n\tConsider the permutations $\\sigma_1 = 1 \\directsum \\delta_{m-1}$, $\\sigma_2 = \\delta_{m-1} \\directsum 1$, and $\\sigma_3 = 12 \\skewsum \\delta_{m-2}$.\n\t\\begin{enumerate}\n\t\t\\item The permutation $\\sigma_1 = 1 m \\cdots 2$ has a unique $M$-gridding, where the $m-1$ entries $2, 3, \\dots, m$ are placed in topmost cell and the entry $1$ is placed in the leftmost cell. \n\t\t\\item The permutation $\\sigma_2 = (m-1)\\cdots 2m$ has a unique $M$-gridding, where the entry $m$ is placed in the topmost cell and the $m-1$ entries $1, 2, \\dots, (m-1)$ are placed in the leftmost cell. \n\t\t\\item The permutation $\\sigma_3 = (m-1)m(m-2) \\cdots 21$ has a unique gridding in $M$, where the $m-2$ entries $1, 2, \\dots, (m-2)$ are placed in the lower-right cell, the entries $m-1$ and $m$ are placed in the leftmost and topmost cells, respectively.\n\t\\end{enumerate}\n\tBy Observation~\\ref{obs-grid-points}, any $M$-gridding of any proper $\\P_m$-universal permutation must contain at least $m-1$ points in the topmost cell, at least $m-1$ points in the leftmost cell, and at least $m-2$ points in the lower-left cell, and therefore must have size at least $(m-2) + (m-1) + (m-1) = 3m-4$, as desired.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{\\texorpdfstring{$\\{231, 2143\\}$}{231, 2143}-avoiding Permutations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nLet $\\P = \\Av(231, 2143) = \\gridVertTwo[{1/3}]{1,-1}{0,1}$ be the class of $\\{231, 2143\\}$-avoiding permutations. In~\\cite{bannister:superpatterns-a:}, Bannister, Cheng, Devanny, and Eppstein prove that there are $\\P_m$-universal permutations of size $3m-4$ for $m \\ge 3$. We provide a simple proof of this construction.\n\n\\begin{theorem}[Bannister, Cheng, Devanny, and Eppstein~\\cite{bannister:superpatterns-a:}]\n\\label{thm-perm-231-2143-proper}\n\tFor each $m \\ge 3$, there is a proper $\\P_m$-universal permutation of size $3m-4$.\n\\end{theorem}\n\\begin{proof}\n\tLet $\\upsilon_3 = 51324$, and for each $m > 3$, let $\\upsilon_{m+1} = 1 \\skewsum (1 \\directsum \\upsilon_{m} \\directsum 1)$. We claim that, for each $m \\ge 3$, $\\upsilon_m$ is (1) in $\\P$ and (2) $\\P_m$-universal. To begin, note that $\\upsilon_3$ is in $\\P$ and that for any permutation $\\pi \\in \\P$, the permutations $1 \\skewsum \\pi$, $1 \\directsum \\pi$, and $\\pi \\directsum 1$ all lie in $\\P$. As $\\upsilon_{m+1}$ is constructed from $\\upsilon_m$ using only these operations, we have that $\\upsilon_m \\in \\P$ for all $m \\ge 3$ by induction.\n\n\tTo show that $\\upsilon_m$ is $m$-universal for all $m \\ge 3$, we begin by noting that $\\upsilon_3 = 51324$ is $\\P_3$-universal, meaning it contains the pattern $123$, $132$, $213$, $312$ and $321$, which we may check by hand. Given any permutation $\\pi \\in \\P$, we may decompose $\\pi$ as at least one of $\\pi = 1 \\directsum \\pi^\\ast$, $\\pi = 1 \\skewsum \\pi^\\ast$, or $\\pi = \\pi^\\ast \\directsum 1$, where $\\pi^\\ast \\in \\P_{m-1}$. As $\\upsilon_m$ contains each of $1 \\directsum \\upsilon_{m-1}$, $1 \\skewsum \\upsilon_{m-1}$, and $\\upsilon_{m-1} \\directsum 1$, and $\\upsilon_{m-1}$ contains $\\pi^\\ast$ necessarily by induction, we have that $\\upsilon_m$ contains $\\pi$, completing the proof.\n\\end{proof}\n\nMoreover, Bannister, Cheng, Devanny, and Eppstein prove that, with $\\Q = \\Av(231, 312, 2143, 1324) = \\gridHorizTwo[{1/3}]{1,0}{0,-1} \\cup \\gridVertTwo[{1/3}]{-1,0}{0,1}$, any $\\Q_m$-universal permutation has size at least $3m-4$. As $\\Q \\subseteq \\P$, any $\\P_m$-universal permutation must have size at least $3m-4$, which together with the $\\P_m$-universal permutations of size $3m-4$ of Theorem~\\ref{thm-perm-231-2143-proper} are the best-possible even outside the class.\n\\begin{theorem}[Bannister, Cheng, Devanny, and Eppstein~\\cite{bannister:superpatterns-a:}]\n\\label{thm-perm-231-2143-improper}\n\tThe smallest $m$-universal permutations for $\\Av(231, 2143)$ have size $3m-4$.\n\\end{theorem}\n\nAs a corollary, Bannister, Cheng, Devanny, and Eppstein note that any class contained in $\\P$ that contains $\\Q$ has smallest universal permutations of this size as well:\n\\begin{corollary}[Bannister, Cheng, Devanny, and Eppstein~\\cite{bannister:superpatterns-a:}]\n\tIf $\\R$ is a permutation class with $\\Q \\subseteq \\R \\subseteq \\P$, then the smallest $\\R_m$-universal permutations have size $3m-4$.\n\\end{corollary}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{\\texorpdfstring{$231$}{231}-avoiding Permutations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nIn~\\cite{knuth:the-art-of-comp:1}, Knuth shows that the permutations that may be sorted with a stack are precisely those that avoid the permutation $231$. Let $\\P = \\Av(231)$ denote the class of $231$-avoiding permutations. In~\\cite{bannister:superpatterns-a:}, Bannister, Cheng, Devanny, and Eppstein construct $\\P_m$-universal permutations of size $\\floor{m^2/4} + m$ and construct, for every proper subclass of $\\P$, $m$-universal permutations of size $\\oO{m \\log^{\\oO{1}}m}$. The $\\P_{10}$-universal permutation of their construction is presented in the left panel of Figure~\\ref{fig-perm-231-univ}.\n\nTo present a construction of proper $\\P_m$-universal permutations, we say the \\emph{reverse-inverse-reverse} of a permutation $\\pi$, denoted $\\pi^{\\rir}$, is defined as $\\pi^{\\rir} = ((\\pi^{r})^{-1})^{r}$, where $\\pi^r$ is the permutation formed by reversing $\\pi$, and $\\pi^{-1}$ is the function inverse of $\\pi$. Pictorially, a plot of $\\pi^{\\rir}$ may be obtained by reflecting the plot of $\\pi$ across the line $y = -x$. The reverse and inverse symmetries preserve containment, so the reverse-inverse-reverse symmetry does as well, meaning that $\\sigma \\le \\pi$ if and only if $\\sigma^{\\rir} \\le \\pi^{\\rir}$. As $231 = 231^{\\rir}$, the class $\\P$ is closed under the reverse-inverse-reverse symmetry, and thus $\\pi$ is $\\P_m$-universal if and only if $\\pi^{\\rir}$ is.\n\n\\begin{proposition}\n\\label{prop-perm-231-proper}\nLet $\\Pi_0 = \\varepsilon$, and for $m \\ge 1$, define\n\\[\n\t\\Pi_m\n\t=\n\t\\left(1 \\skewsum \\Pi_{m-1}^{\\rir}\\right) \\directsum \\Pi_{\\floor{m/2}}.\n\\]\nThen $\\Pi_{m}$ is a proper $\\P_m$-universal permutation for all $m$.\n\\end{proposition}\n\n\\begin{figure}\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale={6/35}]\n\t\t\\draw (0.25,0.35) rectangle ++(35.5, 35.5);\n\t\t\\plotperm{34,23,14,7,2,1,33,22,13,6,3,32,21,12,5,4,31,20,11,8,30,19,10,9,29,18,15,28,17,16,27,24,26,25,35}\n\n\t\t\\begin{scope}[shift={(40,0)}]\n\t\t\t\\draw (0.25,0.35) rectangle ++(35.5, 35.5);\n\t\t\t\\plotperm{26,1,5,3,2,4,25,19,7,6,8,18,14,9,13,11,10,12,16,15,17,20,24,22,21,23,32,27,31,29,28,30,34,33,35}\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{On the left, the $\\P_{10}$-universal permutation of size $35$ of Bannister, Chung, Devanny, and Eppstein's construction~\\cite{bannister:superpatterns-a:}. On the right, the proper $\\P_8$-universal permutation $\\Pi_{8}$ of size $35$.}\n\\label{fig-perm-231-univ}\n\\end{figure}\n\n\\begin{proof}\n\tBefore showing that $\\Pi_{m}$ is $\\P_m$-universal for each $m$, we show that each $\\P_m$ lies in $\\P$ by a brief inductive arguemnt. The permutation $\\Pi_0 = \\varepsilon$ lies in every class of permutations, so our base case is satisfied. In addition to being closed under the reverse-inverse-reverse symmetry, the class $\\P$ is closed under prepending a new largest element and under direct sums, ie. if $\\pi, \\sigma \\in \\P$, then both $1 \\skewsum \\pi$ and $\\pi \\directsum \\sigma$ lie in $\\P$. Thus, by induction, $\\Pi_{m} = (1 \\skewsum \\Pi_{m-1}^{\\rir}) \\directsum \\Pi_{\\floor{m/2}} \\in \\P$ for all $m$.\n\n\tTo show that $\\Pi_{m}$ is $\\P_m$-universal for all $m$, we again proceed by induction on $m$. The permutation $\\Pi_0 = \\varepsilon$ is clearly $0$-universal for every class, so assume that $\\Pi_{m'}$ is $m'$-universal for $\\P$ for all $m' < m$.\n\n\tLet $\\pi \\in \\P_m$. If $\\pi$ is sum-indecomposable, then $\\pi = 1 \\skewsum \\tau$ for some $\\tau \\in \\P_{m-1}$. As $\\Pi_{m-1}$ is $\\P_{m-1}$-universal, $\\Pi^{\\rir}_{m-1}$ is as well. Thus, as $\\Pi_m$ contains $1 \\skewsum \\Pi^{\\rir}_{m-1}$ and $\\pi = 1 \\skewsum \\sigma$ for $\\sigma \\in \\P_{m-1}$, we have that $\\pi \\le \\Pi_m$. \n\t\n\tOtherwise, we may write $\\pi = \\pi_{1} \\directsum \\pi_{2}$, where $\\pi_{2}$ is a non-empty sum-indecomposable permutation, and we complete our analysis in two cases: when $\\size{\\pi_{2}} \\le \\floor{m/2}$ and when $\\size{\\pi_{2}} \\ge \\floor{m/2} + 1$. In the first case, assume that $\\size{\\pi_{2}} \\le \\floor{m/2}$. As $\\size{\\pi_{1}} \\le m-1$, we have that $\\pi_{1}$ embeds into $\\Pi_{m-1}^{\\rir}$, and as $\\size{\\pi_{2}} \\le \\floor{m/2}$, we have that $\\pi_{2}$ embeds into $\\Pi_{\\floor{m/2}}$. Since $\\Pi_{m}$ contains $\\Pi_{m-1}^{\\rir} \\directsum \\Pi_{\\floor{m/2}}$, we may conclude that $\\pi = \\pi_{1} \\directsum \\pi_{2} \\le \\Pi_{m}$. In the second case, assume that $\\size{\\pi_{2}} \\ge \\floor{m/2}+1$, and thus $\\size{\\pi_{1}} \\le \\ceil{m/2}-1$. We claim that $\\pi$ embeds into $\\Pi_{m-1}^{\\rir} = \\Pi_{k-1}^{\\rir} \\directsum (1 \\skewsum \\Pi_{m-2})$. As $\\pi_{2}$ is sum-indecomposable, we may write $\\pi_{2} = 1 \\skewsum \\tau$ for some $\\tau$ with $\\size{\\tau} \\le m-2$. Thus we have $\\pi = \\pi_{1} \\directsum (1 \\skewsum \\tau)$, where $\\size{\\pi_{1}} \\le k-1$ and $\\size{\\tau} \\le 2k-2$, and so by induction, $\\pi$ embeds into $\\Pi_{k-1}^{\\rir} \\directsum (1 \\skewsum \\Pi_{2k-2}) = \\Pi_{2k-1}^{\\rir}$, completing the proof.\n\\end{proof}\n\n\\begin{corollary}\n\\label{cor-231-ub-formula}\nThe sequence $\\size{\\Pi_{m}} = p(m)$ is given by $p(0) = 0$ and, for $m \\ge 1$,\n\\[\n\tp(m) \n\t= \n\tp(m-1) + p\\left(\\floor{m/2}\\right) + 1,\n\\]\nand thus the smallest proper $\\P_m$-universal permutations have size at most $p(m)$.\n\\end{corollary}\n\nThe proper $\\P_m$-universal permutations constructed in Proposition~\\ref{prop-perm-231-proper} are much larger than the $\\P_m$-universal permutations of size $\\floor{m^2/4} + m$ constructed by Bannister, Cheng, Devanny, and Eppstein in~\\cite{bannister:superpatterns-a:}, as the next result shows.\n\n\\begin{theorem}[Knuth~\\cite{knuth:an-almost-linear:}]\n\\label{thm-almost-linear}\nLet $a(1) = 1$ and $a(n) = a(n-1) + a(\\floor{n/2})$ for $n \\ge 2$. Then $a(n)$ grows faster than any polynomial. That is, for any power $k$, there is some $N_k$ such that for all $n \\ge N_k$ we have $a(n) > n^k$.\n\\end{theorem}\n\nBefore presenting the proof of Theorem~\\ref{thm-almost-linear}, note that $s(n) \\ge a(n)$, and thus $s$ grows faster than any polynomial.\n\n\\newenvironment{proof-of-thm-almost-linear}{%\n\t\\medskip\\noindent {\\it Proof of Proposition~\\ref{thm-almost-linear}.\\/}%\n}{%\n\t\\qed\\bigskip%\n}\n\\begin{proof-of-thm-almost-linear}\n\tFix $k$. We aim to show that for sufficiently large $n$, we have $a(n) > n^k$. Let $N$ be such that \n\t\\[\n\t\t2^{k+1} + 1 \\ge \\left(2 + \\frac{1}{N}\\right)^{k+1}\n\t\\]\n\tand let\n\t\\[\n\t\tc \n\t\t=\n\t\t\\min\\left\\{\\frac{a(n)}{n^{k+1}} \\st N \\le n \\le 2N\\right\\}.\n\t\\]\n\tWe claim that for all $n \\ge N$, we have $a(n) \\ge cn^{k+1}$. For $N \\le n \\le 2N$, this is clear as $c \\le a(n)/n^{k+1}$. If $n > 2N$, induction shows that\n\t\\begin{align*}\n\t\ta(n)\n\t\t\t&= a(n-1) + a(\\floor{n/2}) \\\\\n\t\t\t&\\ge c\\cdot(n-1)^{k+1} + c\\cdot\\floor{n/2}^{k+1} \\\\\n\t\t\t&\\ge c\\left((n-1)^{k+1} + \\left(\\frac{n-1}{2}\\right)^{k+1}\\right) \\\\\n\t\t\t% &=   c\\left( 1 + 1/2^{k+1}             \\right)     (n-1)^{k+1} \\\\\n\t\t\t&=   c\\left( \\frac{2^{k+1}+1}{2^{k+1}} \\right)     (n-1)^{k+1} \\\\\n\t\t\t&\\ge c\\left( \\frac{2+\\frac{1}{N}}{2} \\right)^{k+1} (n-1)^{k+1} \\\\\n\t\t\t&=   c\\left( 1+\\frac{1}{2N}          \\right)^{k+1} (n-1)^{k+1} \\\\\n\t\t\t&\\ge c\\left( 1+\\frac{1}{n-1}         \\right)^{k+1} (n-1)^{k+1} \\\\\n\t\t\t&=   c n^{k+1}.\n\t\\end{align*}\n\t\n\tTo conclude, choose $N_k$ such that $N_k \\ge N$ and $N_k \\ge 1/c$ (so that $cn \\ge c N_k \\ge 1$), and the proof is complete.\n\\end{proof-of-thm-almost-linear}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{\\texorpdfstring{$321$}{321}-avoiding Permutations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nLet $\\S$ be the class of $321$-avoiding permutations. Equivalently, $\\S$ is the class of permutations that may be partitioned into two increasing subsequences. In~\\cite{bannister:small-superpatt:}, Bannister, Devanny, and Eppstein construct $\\S_m$-universal permutations of size $22m^{3/2} + \\oTheta{m}$.\n\nIn~\\cite{Atminas:Universal-graph:}, Atminas, Kitaev, Lozin, and Valyuzhenich construct a proper $\\S_m$-universal permutation of size $m^2$. The corresponding permutation graph is thus a proper $\\g(\\S)_m$-universal graph, where in this case $\\g(\\S)$ is the class of bipartite permutation graphs. This corresponding $\\g(\\S)_m$-universal permutation graph is in fact equal to the size-$m^2$ graph that Lozin and Rudolf construct in \\cite{lozin:minimal-univers:}. The question of whether $\\S$ admits sub-quadratic sized proper universal permutations remains open, but evidence points towards ``no''. In~\\cite{alecu:critical-properties:}, Alecu, Lozin, and Malyshev prove that any proper $m$-universal graph for the class of bipartite permutation graphs must have size $\\oOmega{m^\\alpha}$ for all $\\alpha < 2$, implying that any proper $\\S_m$-universal permutation must have size $\\oOmega{m^\\alpha}$ for all $\\alpha < 2$. They conjecture that the smallest $m$-universal graphs for the class of bipartite permutation graphs have size $\\oOmega{m^2}$, which would imply that the smallest proper $\\S_m$-universal permutations have size $\\oTheta{m^2}$.\n\n%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%\n\\subsection{Subclasses of \\texorpdfstring{$\\Av(321)$}{Av(321)}: Truncated Staircases}\n%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%\n\nThe class $\\Av(321)$ may be represented as the grid class of an infinite matrix. First shown by Albert, Atkinson, Brignall, Ru\\v{s}kuc, Smith, and West~\\cite{albert:growth-rates-fo:}, we have\n\\[\n\t\\Av(321)\n\t=\n\t\\begin{tikzpicture}[grids]\n\n\t\t\\foreach \\x in {0, 1, 2, 3, 4} {\n\t\t\t\\draw [thin, gray] (\\x,0) -- ++(0,3.9);\n\t\t}\n\n\t\t\\foreach \\y in {0, 1, 2, 3} {\n\t\t\t\\draw [thin, gray] (0,\\y) -- ++(4.9,0);\n\t\t}\n\n\t\t\\draw (0,0) rectangle ++(1,1);\n\t\t\\draw[ultra thick, shorten <=4pt, shorten >=4pt] (0,0) -- ++(1,1);\n\t\t\\draw (1,0) rectangle ++(1,1);\n\t\t\\draw[ultra thick, shorten <=4pt, shorten >=4pt] (1,0) -- ++(1,1);\n\t\t\\draw (1,1) rectangle ++(1,1);\n\t\t\\draw[ultra thick, shorten <=4pt, shorten >=4pt] (1,1) -- ++(1,1);\n\t\t\\draw (2,1) rectangle ++(1,1);\n\t\t\\draw[ultra thick, shorten <=4pt, shorten >=4pt] (2,1) -- ++(1,1);\n\t\t\\draw (2,2) rectangle ++(1,1);\n\t\t\\draw[ultra thick, shorten <=4pt, shorten >=4pt] (2,2) -- ++(1,1);\n\t\t\\draw (3,2) rectangle ++(1,1);\n\t\t\\draw[ultra thick, shorten <=4pt, shorten >=4pt] (3,2) -- ++(1,1);\n\t\t\\foreach \\d in {0.25, 0.50, 0.75} {\n\t\t\t\\filldraw[black] ({3+\\d}, {3+\\d}) circle [radius=0.03cm];\n\t\t\t\\filldraw[black] ({4+\\d}, {3+\\d}) circle [radius=0.03cm];\n\t\t}\n\t\\end{tikzpicture}\n\\]\n\nThe figure on the right is known as the infinite \\emph{positive staircase}. One natural family of subclasses of $\\Av(321)$ are the finite positive staircases. Let $\\S^k$ be the positive staircase consisting of the first $k$ nonempty cells of the infinite staircase, e.g, $\\S^1 = \\gridCell[{1/3}]{1}$, $\\S^2 = \\gridHorizOne[{1/3}]{1,1}$, $\\S^3 = \\gridHorizTwo[{1/3}]{1,1}{0,1}$, and so on.\n\nThen, as \n\\[\n\t\\S^1\n\t\\subseteq\n\t\\S^2\n\t\\subseteq\n\t\\S^3\n\t\\subseteq\n\t\\cdots\n\t\\subseteq\n\t\\S,\n\\]\nwe have\n\\[\n\t\\u_{\\S^1}(m)\n\t\\le\n\t\\u_{\\S^2}(m)\n\t\\le\n\t\\u_{\\S^3}(m)\n\t\\le\n\t\\cdots\n\t\\le\n\t\\u_{\\S}(m).\n\\]\n\nFor all $m$, every permutation in $\\S_m$ may be gridded using the first $\\ceil{(m+1)/2}$ cells of the infinite positive, and there is some permutation in $\\S_m$ that cannot be gridded using $\\ceil{(m-1)/2}$ cells. Thus, any proper $\\S_m$-universal permutation may not use fewer than the first $\\ceil{(m+1)/2}$ cells, and computation suggests that among all smallest proper $\\S_m$-universal permutations, there is at least one that may itself be gridded in $\\ceil{(m+1)/2}$ cells. \n\\begin{conjecture}\n\\label{conj-no-more-cells}\nFor all $m \\ge 0$, there is a smallest proper $\\S_m$-universal permutation that lies in $\\S^{\\ceil{(m+1)/2}}$.\n\\end{conjecture}\n\nWe now demonstrate, through Observation~\\ref{obs-grid-points}, a lower bound on the size of proper $\\S^{k}_m$-universal permutations. For $k \\ge 2$, let $M$ be the matrix corresponding to the the finite positive staircase with $k$ nonempty cells. The permutation $\\pi = 21 43 \\cdots (2k-2)(2k-3)$ has a unique $M$-gridding, placing one point in each of the first and last cells and two points in every other cell. Consider some entry $\\pi(i)$ of $\\pi$ that is placed in the cell $C$ in the unique $M$-gridding of $\\pi$. Replacing the entry $\\pi(i)$ of $\\pi$ with a contiguous increasing sequence of entries of size $m-2k+3$ and yields a permutation of size $m$ that has a unique $M$-gridding, placing $m-2k+3$ points in the cell $C$ if $C$ is the first or last cell of $M$ or $m-2k+4$ points in the cell $C$ otherwise. \n\nThus for $m \\ge 2k-2$, any $M$-gridding of a proper $\\S^k_m$-universal permutation must have at least $m-2k+3$ points in its first and last cells, and $m-2k+4$ points in each of its other $k-2$ cells. This shows that any proper $\\S^k_m$-universal permutation must have size at least $2(m-2k+3) + (k-2)(m-2k+4) = km - 2(k-1)^2$.\n\n\\begin{proposition}\n\\label{prop-cells-proper-lower}\n\tFor $m \\ge 2k-2$, any proper $\\S^k_m$-universal permutation has size at least $km - 2(k-1)^2$.\n\\end{proposition}\n\nUsing Conjecture~\\ref{conj-no-more-cells} and Proposition~\\ref{prop-cells-proper-lower}, we have the conjollary\\footnote{A \\emph{conjollary} is a corollary that follows from a conjecture.} below.\n\\begin{conjollary}\n\tFor all $m \\ge 4$, any proper $\\S_m$-universal permutation must have size at least $m^2/8$.\n\\end{conjollary}\n\\begin{proof}\n\tBy Conjecture~\\ref{conj-no-more-cells}, we have that the size of the smallest proper $\\S_m$-universal permutations and the size of the smallest proper $\\S^k_m$-universal permutations are the same for all $k \\le (m+2)/2$. By Proposition~\\ref{prop-cells-proper-lower}, every proper $\\S^k_m$ universal permutation has size at least $km - 2(k-1)^2$, and thus\n\t\\begin{align*}\n\t\t\\u_{\\S}^p(m) \n\t\t\t&\\ge \\max\\{mk - 2(k-1)^2 \\st k \\le (m+2)/2\\} \\\\\n\t\t\t&\\ge m \\floor{\\frac{m}{4}+1} - 2 \\floor{\\frac{m}{4}}^2 \\\\\n\t\t\t&> \\frac{m^2}{8},\n\t\\end{align*}\n\tas desired.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Skew riffle Permutations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nWe say that $\\pi$ is a \\emph{skew riffle} permutation if it is the sum of riffle and antiriffle permutations. Let $\\SR$ be the class of skew riffle permutations:\n\\[\n\t\\P\n\t=\n\t\\bigdirectsum \n\t\\left(\n\t\t\\gridVertTwoDisplay{1}{1}\n\t\t\\cup \n\t\t\\gridVertOneDisplay{1,1}\n\t\\right).\n\\]\n\nIn~\\cite{bannister:small-superpatt:}, Bannister, Devanny, and Eppstein construct $\\P_m$-universal permutations of size $16m \\log m + \\oTheta{m}$. Let $\\R = \\gridVertTwo[{1/3}]{1}{1} \\cup \\gridVertOne[{1/3}]{1,1}$. The permutation \n\\[\n\t\\pi_m \n\t= \n\t1 3 5 \\cdots (2m-1) 2 (2m) 4 (2m+1) 6 \\cdots (3m-3) (2m-2) (3m-2)\n\\]\nof size $3m-2$ is $\\R_m$-universal, as the lowest $2m-1$ values form the permutation $1 3 5 \\cdots (2m-1) 2 4 6 \\cdots (2m-2)$, which is $m$-universal for $\\gridVertTwo[{1/3}]{1}{1}$, and the rightmost $2m-1$ values form the permutation $m 1 (m+1) 2 \\cdots (m-1) (2m-1)$, which is $m$-universal for $\\gridVertOne[{1/3}]{1,1}$. In the language of Proposition~\\ref{prop-an-upper-bound}, $\\comp(\\R)$ is the class of all compositions, and the recursively-defined composition $w_m = w_{\\floor{(m-1)/2}} m w_{\\ceil{(m-1)/2}}$ (with $w_0 = \\varepsilon$) of length $m$ and size $\\ell(m)$ is $m$-universal. Thus the permutation $\\tau_m = \\directsum_{i = 1}^{m} \\pi_{w_m(i)}$ is $\\R_m$-universal and has size at most $3\\ell(m) \\sim 3m \\log_2 m$. For example, Figure~\\ref{fig-perm-construction} shows the plots of $\\pi_4$ and $\\tau_3$.\n\n\\begin{figure}\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale=0.25]\n\t\t\\plotpermborder{1,3,5,7,2,8,4,9,6,10}\n\t\t\\begin{scope}[shift={(12,0.5)}]\n\t\t\t\\draw[thick, gray] (0.5,0.5) rectangle ++(1,1);\n\t\t\t\\draw[thick, gray] (1.5,1.5) rectangle ++(7,7);\n\t\t\t\\draw[thick, gray] (8.5,8.5) rectangle ++(1,1);\n\t\t\t\\plotpermborder{1,2,4,6,3,7,5,8,9}\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{On the left, the permutation $\\pi_4$, which is $4$-universal for $\\gridVertTwo[{1/3}]{1}{1} \\cup \\gridVertOne[{1/3}]{1,1}$. On the right, the $\\P_3$-universal permutation $\\tau_3$ with its summands $\\pi_1$, $\\pi_3$, and $\\pi_1$ outlined.}\n\\label{fig-perm-construction}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Concluding Remarks}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nUnlike in the context of graphs, there is no clear guess about the ``optimal'' size of an $m$-universal permutation for a class based on the number of $m$-patterns in the class. Both the class of wedge permutations and the class of layered permutations contain precisely $2^{m-1}$ patterns of size $m$, but their smallest (proper) universal permutations have sizes $\\ell(m) \\sim m \\log_2 m$ and $2m-1$, respectively. One immediately desirable characterization would be of those maximal permutation classes that admit linear-size universal permutations. \n\\begin{question}\n\tWhat are the maximal permutations classes that admits linear-size universal permutations?\n\\end{question}\n", "meta": {"hexsha": "5e86f08a1f3718e18a7b86d556dcc986445b27a6", "size": 88403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-permutations.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-permutations.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-permutations.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": 77.207860262, "max_line_length": 1311, "alphanum_fraction": 0.6702261235, "num_tokens": 29618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6690458414691869}}
{"text": "% !TEX encoding = UTF-8 Unicode\n% !TEX spellcheck = en_US\n% !TEX root = ../../../ICMA2020.tex\n\\subsection{Signal Processing}\n\\label{subsec:SignalProcessing}\nAll experiments described in Sec.\\,\\ref{subsec:ExperimentScenario} are carried out multiple times with the same set of parameters. Over $N_\\text{r}=50$ repetitions of each experiment the mean of the joint angular positions $\\overline{\\boldsymbol{q}}(t_p)$ and the measured torques $\\overline{\\boldsymbol{\\tau}}(t_p)$ are calculated for every time step $t_p$. \n\nIn the case of the \\textsc{Fourier} series the frequency spectrum of the excitation is known, which allows for additional filtering of the position measurements: \nThe discrete \\textsc{Fourier} transform of the mean position measurements $\\overline{\\boldsymbol{q}}$ is calculated and only the first $n_\\mathrm{h}+1$ \\textsc{Fourier} coefficients are retained. These correspond to the offset, the base frequency and the $n_\\mathrm{h}-1$ harmonics. Utilizing this filter technique yields nearly noise-free estimates of the joint angular positions.\nA possible loss of information is tolerated in favor of reduced noise.\nThe same filter technique is used in \\cite{Olsen.2002} and \\cite{Stueckelmaier.}. \nBecause of the averaging of the measurement data and the additional filtering for the \\textsc{Fourier} series the derivatives for the joint angular velocities and accelerations can be calculated numerically for all experiments.\n\n%Since periodic \\textsc{Fourier} series are used as excitation trajectories, no leakage errors are introduced due to the allowed settling time of the system. \n\nTo take into account the different signal-to-noise ratios in each joint, the WLS method is used for parameter estimation. The measurement points are weighted using the inverse of the covariance matrix of the measured torque. The noise of the torque measurements in all joints $j$ in every time step $t_p$ can be estimated using the equation for the sample variance\n\\begin{equation}\\label{eq:var_tau}\n\t\\sigma^2_{j,p} = \\frac{1}{N_\\text{r}-1} \\sum\\limits_{k=1}^{N_\\text{r}} (\\tau_{k,j} (t_p) - \\overline{\\tau}_j(t_p))^2,\n\\end{equation}\nwhere $k$ refers to the repetitions of the experiment.\nThe matrix $\\boldsymbol{W}$ is then defined as:\n\\begin{equation}\\label{eq:WLS_Gew}\n\t\\boldsymbol{W} = \\mathrm{diag}(\\boldsymbol{W}_1^{-1}, \\boldsymbol{W}_2^{-1}, \\hdots, \\boldsymbol{W}_6^{-1})\n\\end{equation}\n\twith\n\\begin{equation}\n\t\\boldsymbol{W}_j = \\mathrm{diag}(\\sigma^2_{j,1}, \\sigma^2_{j,2}, \\hdots, \\sigma^2_{j,p}).\n\\end{equation}\nSince the measurements are assumed to be independent, $\\boldsymbol{W}$ is a diagonal matrix.\nAll measurements used for this evaluation were taken when the robot was in the controlled state.\n\n", "meta": {"hexsha": "f87fc401492eda6d415ea0bf6108ba50eae55c65", "size": 2722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/Chapters/Experiments/Signal_Processing/Signal_Processing.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/Experiments/Signal_Processing/Signal_Processing.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/Experiments/Signal_Processing/Signal_Processing.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": 85.0625, "max_line_length": 381, "alphanum_fraction": 0.768185158, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6689649860415605}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\\usepackage{mystyle}\n\n\\begin{document}\n\n\\section{Limits}\n\n\\begin{defn}[Limit]\n\t$a$ is the limit of a sequence ${(xn)}_{n \\in \\NN}$ if $\\forall \\eps > 0 \\quad \\exists N \\in \\NN: n > N \\implies | x_n -a | < \\eps$.\n\tWe write\n\t\\[ \\lim_{n \\to \\infty} x_n = a \\]\n\\end{defn}\n\n\\begin{prop}\n\tLet $a$ be the limit of the sequence $x_n$, then $a$ is unique.\n\\end{prop}\n\n\\begin{proof}\n\tAssume we have two limits $a$ and $b$, then $\\forall \\eps > 0\n\t\\quad \\exists N_1, N_2 \\in \\NN$ such that\n\t\\[ n > N_1 \\implies |x_n - a| < \\eps \\]\n\t\\[ n > N_2 \\implies |x_n - b| < \\eps \\]\n\n\tLet $N = \\max\\{N_1, N_2\\}$, then if $n > N$\n\t\\[ |x_n - a| < \\eps, \\quad |x_n - b| < \\eps \\]\n\n\t\\begin{align*}\n\t\t|b-a| &= |(x_n - a) + (b - x_n)| \\leq |x_n - a| + |x_n - b| \\\\\n\t\t      &\\implies |b-a| < 2\\eps \\\\\n\t\t      &\\implies b - a = 0 \\implies a = b\n\t\\end{align*}\n\\end{proof}\n\n\\begin{thm}[Archimedian Property]\n\tLet $x,y \\in \\RR, \\, x>0$ then $\\exists n \\in \\NN$ such that $xn > y$.\n\\end{thm}\n\n\\begin{proof}\n\tAssume $nx \\leq y, \\, \\forall n \\in \\NN$.\n\n\tLet $S_x = \\{ nx \\mid n \\in \\NN \\}$. By assumption, $S_x$ is\n\tbounded, and so by the completeness of the real numbers, we know\n\tthe supremum of this set exists. $y$ is the maximum of the set\n\tso it must be the supremum too.\n\n\t$x > 0 \\implies y-x < y$ so $y-x$ is not an upper bound for $S_x$.\n\t\\begin{align*}\n\t\t&\\implies \\exists s \\in S_x : y-x < s = kx, \\, k \\in \\NN \\\\\n\t\t&\\implies y < (k+1)x = mx \\in S_x\n\t\\end{align*}\n\twhich is a contradiction to our assumption.\n\\end{proof}\n\n\\begin{cor}\n\t\\[ \\forall y \\in \\RR, \\, \\exists N \\in \\NN : n > y \\]\n\\end{cor}\n\n\\begin{prop}\n\tLet $x_n = \\frac{1}{n}, \\, n \\in \\NN$, then $\\lim_{n \\to \\infty}\n\tx_n = 0$.\n\\end{prop}\n\n\\begin{proof}\n\tLet $\\frac{1}{\\eps} \\in \\RR$. By the Archimedian Property,\n\t$\\exists N \\in \\NN : N > \\frac{1}{\\eps}, \\, \\forall \\eps > 0$.\n\n\tLet $n>N$, then\n\t\\[ |x_n - 0| = \\frac{1}{n} < \\frac{1}{N} < \\frac{1}{1/\\eps} < \\eps \\]\n\\end{proof}\n\n\\begin{prop}\n\tAssume $\\lim_{n \\to \\infty} x_n = a$ and $\\lim_{n \\to \\infty}\n\ty_n = b$, then:\n\t\\begin{enumerate}\n\t\t\\item\n\t\t\t$\\lim (x_n + y_n) = a + b$\n\t\t\\item\n\t\t\t$\\lim (x_n \\dot y_n) = a \\dot b$\n\t\t\\item\n\t\t\tAssuming $y_n \\neq 0 \\, \\forall n$ and $b \\neq 0$,\n\t\t\t$\\lim(\\frac{x_n}{y_n}) = \\frac{a}{b}$\n\t\t\\item\n\t\t\tIf a sequence is constant i.e. $x_n = c \\,\n\t\t\t\\forall n$, then $\\lim x_n = c$\n\t\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n\t4:\n\t\\begin{align*}\n\t\t&|x_n - c| = 0, \\, \\forall n \\in \\NN \\\\\n\t\t\\implies &|x_n - c| < \\eps, \\, \\forall \\eps > 0 \\in \\RR, n \\in \\NN \\\\\n\t\t\\implies &c = \\lim x_n\n\t\\end{align*}\n\n\t1:\n\tFor a given $\\eps > 0, \\, \\exists N_1, N_2 \\in \\NN$ such that\n\t\\[ n > N_1 \\implies |x_n - a| < \\frac{\\eps}{2} \\]\n\t\\[ n > N_2 \\implies |y_n - b| < \\frac{\\eps}{2} \\]\n\t\\[\n\t\tn > \\max \\{ N_1, N_2 \\} \\implies | (x_n + y_n) - (a+b)|\n\t\\]\n\t\\[\n\t\t\\leq |x_n - a| + |y_n - b|\n\t\t< \\frac{\\eps}{2} + \\frac{\\eps}{2} = \\eps\n\t\\]\n\n\t3:\n\t\\[ \\exists N_1 : |x_n - a| < |a|/2 \\]\n\t\\[ |a| = |a + x_n - x_n| \\leq |a - x_n| + |x_n| < |a|/2 + |x_n| \\]\n\t\\[ \\implies |a|/2 < |x_n| \\implies 1/|x_n| < 2/|a| \\]\n\t\\[ \\exists N_2 : |x_n -a| < \\frac{|a|^2}{2}\\eps \\]\n\t\\begin{align*}\n\t\tn > \\max{N_1, N_2} \\implies \\\\\n\t\t|\\frac{1}{x_n} - \\frac{1}{a}| &= |\\frac{a-x_n}{ax_n} \\\\\n\t\t&= \\frac{1}{|a|}\\frac{1}{|x_n|}|x_n - a| \\\\\n\t\t&< \\frac{1}{|a|}\\frac{2}{|a|}|x_n - a| \\\\\n\t\t&< \\frac{2}{|a|^2}\\frac{a^2}{2}\\eps = \\eps\n\t\\end{align*}\n\n\\end{proof}\n\n\\begin{ex}\n\t\\[\n\t\t\\lim \\frac{n^2 - 1}{n_2 + 1}\n\t\t= \\lim \\frac{1 - \\frac{1}{n^2}}{1 + \\frac{1}{n^2}}\n\t\\]\n\t\\[ \\lim \\frac{1}{n} = 0 \\implies \\lim \\frac{1}{n^2} = 0 \\]\n\t\\[ \\implies \\lim \\frac{n^2 - 1}{n_2 + 1} = 1 \\]\n\\end{ex}\n\n\\begin{defn}[Divergence]\n\tA sequence $x_n$ diverges to $+\\infty$ if $\\forall A > 0, \\,\n\t\\exists N \\in \\NN : n > N \\implies x_n > A$. We say\n\t\\[ \\lim_{n \\to \\infty} x_n = \\infty \\]\n\n\tSimilarly, if $\\forall A < 0, \\, \\exists N \\in \\NN : n > N\n\t\\implies x_n - A$, then\n\t\\[ \\lim_{n \\to \\infty} x_n = -\\infty \\]\n\\end{defn}\n\n\\begin{defn}[Increasing]\n\tA sequence is called increasing if $\\forall n \\in \\NN, \\, x_n\n\t\\leq x_{n+1}$.\n\\end{defn}\n\n\\begin{defn}[Decreasing]\n\tA sequence is called decreasing if $\\forall n \\in \\NN, \\, x_n\n\t\\geq x_{n+1}$.\n\\end{defn}\n\n\\begin{defn}[Monotonic]\n\tA sequence is monotonic if it is increasing or descreasing.\n\\end{defn}\n\n\\begin{defn}[Bounded]\n\tA sequence is bounded if $\\exists A > 0 : |x_n| \\leq A \\,\n\t\\forall n \\in \\NN$.\n\\end{defn}\n\n\\begin{thm}[MonontonicConvergence]\n\tIf $x_n$ is bounded and increasing, it converges to $\\sup\\{x_1,\n\t\\ldots, x_n\\}$. If it is bounded and decreasing then it\n\tconverges to $\\inf\\{x_1, \\ldots, x_n\\}$.\n\\end{thm}\n\n\\begin{proof}\n\tAssume the sequence is increasing.\\\\\n\n\tThe supremum, $a$, of the sequence exists because $\\RR$ is\n\tcomplete and the sequence is bounded. Take $\\eps > 0$, then $a\n\t- \\eps < a$ so $a - \\eps$ is not a upper bound for $\\{x_1,\n\t\\ldots, x_n\\}$ and there is $N \\in \\NN$ such that $x_N > a - \\eps$.\n\n\tFor every $n > N$ we have $x_n \\geq x_N$, due to the increasing\n\tnature of the sequence. Hence,\n\t\\[\n\t\ta - \\eps < x_n \\leq a < a + \\eps\n\t\t\\implies a - \\eps < x_n < a + \\eps\n\t\t\\implies | x_n - a | < \\eps\n\t\\]\n\tand $\\lim x_n = \\sup\\{x_1, \\ldots, x_n\\}$.\\\\\n\n\tAssume now that the sequence is decreasing.\\\\\n\n\tAgain by completeness and boundedness $a = \\inf \\{x_1, \\ldots,\n\tx_n\\}$ is well defined.\n\tFix $\\eps > 0$ then $a + \\eps > a$ and so $a + \\eps$ is not a\n\tlower bound for $\\{x_1, \\ldots, x_n\\}$ and there is $N \\in \\NN$\n\tsuch that $x_N < a + \\eps$.\n\tSince $x_n$ is decreasing, $n > N \\implies x_n \\leq x_N$, so\n\t\\[\n\t\ta - \\eps < a \\leq x_n < a + \\eps\n\t\t\\implies | x_n - a | < \\eps\n\t\\]\n\tand $\\lim x_n = \\inf \\{x_1, \\ldots, x_n\\}$.\n\\end{proof}\n\n\\begin{ex}\n\tLet $x_1 = 2$ and $x_{n+1} = 2 + \\sqrt{x_n}$, so $x_2 = 2 +\n\t\\sqrt{2}$, $x_3 = 2 + \\sqrt{2 + \\sqrt{2}}$, etc.\n\n\tWe aim to show that $2 \\leq x_n \\leq 4 \\quad \\forall n \\in \\NN$.\n\n\t$n=1$ is clearly true, so we may assume true for $n=k$.\n\n\t\\[\n\t\t2 \\leq x_k \\leq 4 \\implies \\sqrt{2} \\leq \\sqrt{x_k} \\leq \\sqrt{4} = 2\n\t\\]\n\t\\[\n\t\t\\implies 2 + \\sqrt{2} \\leq 2 + \\sqrt{x_k} \\leq 4\n\t\\]\n\t\\[\n\t\t2 + \\sqrt{2} > 2 \\implies x_{k+1} > 2 \\implies 2 \\leq x_{k+1} \\leq 4\n\t\\]\n\n\tSo $x_n$ is bounded and increasing hence $\\lim_{n \\to \\infty} x_n = 4$.\n\\end{ex}\n\n\\begin{defn}[Cauchy Sequence]\n\tA sequence is Cauchy if\n\t\\[\n\t\t\\forall \\eps > 0 \\, \\exists N \\in \\NN :\n\t\t| x_n - x_m | < \\eps \\forall n,m > N\n\t\\]\n\\end{defn}\n\n\\begin{thm}\n\tAny Cauchy sequence is bounded.\n\\end{thm}\n\n\\begin{proof}\n\tLet $x_n$ be a Cauchy sequence. Take $\\eps = 1$, then $\\exists\n\tN \\in \\NN : |x_n - x_m| < 1 \\quad \\forall n,m > N$.\n\n\tIf $m = N+1$ then $|x_n - x_{N+1}| < 1 \\iff x_{N+1} - 1 < x_n < x_{N+1} + 1$.\n\n\t$A = \\max\\{x_1, x_2, \\ldots, x_N, x_{N+1}+1\\}$\n\t$B = \\min\\{x_1, x_2, \\ldots, x_N, x_{N+1}-1\\}$\n\n\tSo $B \\leq x_n \\leq A \\quad \\forall n$, hence $x_n$ is bounded.\n\\end{proof}\n\n\\begin{prop}\n\tIf $S$ and $T$ are bounded subsets of $\\RR$ and $S \\subseteq T$,\n\tthen $\\inf T \\leq \\inf S$.\n\\end{prop}\n\n\\begin{proof}\n\tLet $t = \\inf T$ and $s = \\inf S$.\n\n\tAssume $s<t$. By completeness, $t$ cannot be a lower bound of\n\t$S$, hence\n\t\\begin{align*}\n\t\t\\exists \\alpha \\in S : \\alpha < t \\\\\n\t\t&\\implies \\alpha < \\beta \\forall \\beta \\in T \\\\\n\t\t&\\implies \\alpha \\notin T \\\\\n\t\t&\\implies S \\nsubseteq T\n\t\\end{align*}\n\n\tThe contrapositive statement has been proved, hence the original\n\tstatement is true as well.\n\\end{proof}\n\n\\begin{thm}\n\tA sequence is Cauchy iff it converges.\n\\end{thm}\n\n\\begin{proof}\n\tAssume that a sequence converges such that $\\lim x_n = a$, then\n\t\\[\n\t\t\\forall \\eps > 0 \\exists N \\in \\NN :\n\t\t| x_n - a | < \\frac{\\eps}{2}, \\quad\n\t\t| x_m - a | < \\frac{\\eps}{2}, \\quad\n\t\t\\forall n,m > N\n\t\\]\n\t\\begin{align*}\n\t\t|x_n - x_m| &= |(x_n -a) - (x_m -a)| \\\\\n\t\t\t    &\\leq |x_n -a| + |x_m -a| \\\\\n\t\t\t    &< \\frac{\\eps}{2} + \\frac{\\eps}{2} = \\eps\n\t\\end{align*}\n\n\tAssume now that $x_n$ is Cauchy, then we know it is bounded and\n\tby completeness, $\\inf\\{x_1, \\ldots, x_n, x_{n+1}\\}$ is well\n\tdefined.\n\n\tLet\n\t\\begin{align*}\n\t\tb_1 &= \\inf \\{x_1, \\ldots\\} \\\\\n\t\tb_2 &= \\inf \\{x_2, \\ldots\\} \\\\\n\t\tb_n &= \\inf \\{x_n, \\ldots\\}\n\t\\end{align*}\n\tthen\n\t\\[\n\t\tb_1 \\leq b_2 \\leq \\cdots \\leq b_n \\leq \\cdots\n\t\\]\n\tand\n\t\\[\n\t\tb_n \\leq x_n \\leq B\n\t\\]\n\twhere $B$ is an upper bound $\\forall n \\in \\NN$.\n\n\tBy the Monotonic Covergence Theorem, $a = \\lim b_n$ exists, so\n\t\\[\n\t\t\\forall \\eps > 0 \\exists N_1 \\in \\NN :\n\t\t|b_n - a| < \\frac{\\eps}{3}, \\quad \\forall n > N_1\n\t\\]\n\t\\[\n\t\tb_n + \\frac{\\eps}{3} > b_n = \\inf\\{x_n\\}\n\t\\]\n\t\\[\n\t\t\\implies \\exists m_0 > N_1 :\n\t\tb_n < x_{m_0} < b_n + \\frac{\\eps}{3}\n\t\\]\n\n\t$x_n$ is Cauchy, hence\n\t\\[\n\t\t\\exists N_2 \\in \\NN :\n\t\t|x_n - x_m| < \\frac{\\eps}{3}, \\quad\n\t\t\\forall n,m > N_2\n\t\\]\n\n\tLet $N = \\max\\{N_1, N_2\\}$, then\n\t\\begin{align*}\n\t\t|x_n - a| &\\leq |(x_n - x_m) + (x_m - b_n) + (b_n - a)| \\\\\n\t\t\t  &\\leq |x_n - x_m| + |x_m - b_n| + |b_n - a| \\\\\n\t\t\t  &< \\frac{\\eps}{3} + \\frac{\\eps}{3}\n\t\t\t\t+ \\frac{\\eps}{3} = \\eps\n\t\\end{align*}\n\\end{proof}\n\n\\begin{ex}[Harmonic Series]\n\t\\[\n\t\ty_n = 1 + \\frac{1}{2} + \\cdots + \\frac{1}{n}\n\t\\]\n\tWe claim that $y_n$ diverges.\n\t\\begin{align*}\n\t\ty_{2n} - y{n} &=\n\t\t\\left(1 + \\frac{1}{2} + \\cdots + \\frac{1}{2n} \\right)\n\t\t\\left(1 + \\frac{1}{2} + \\cdots + \\frac{1}{n} \\right) \\\\\n\t\t&= \\frac{1}{n+1} + \\cdots + \\frac{1}{2n}\n\t\t> \\frac{1}{2n} + \\cdots + \\frac{1}{2n} = \\frac{1}{2}\n\t\\end{align*}\n\n\tIf we set $\\eps = \\frac{1}{3}$ then for $m = 2n$\n\t\\[\n\t\t|y_m - y_n| > \\eps\n\t\\]\n\thence the sequence is not Cauchy and so it cannot converge.\n\\end{ex}\n\n\\begin{cor}\n\tAny convergent sequence is bounded.\n\\end{cor}\n\n\\begin{ex}\n\t\\[\n\t\tx_n = {(-1)}^n\n\t\\]\n\t\\[\n\t\tx_n = \\pm 1 \\quad \\forall n \\in \\NN\n\t\\]\n\thence $x_n$ is bounded yet it does not converge.\n\\end{ex}\n\n\\section{Subsequences}\n\n\\begin{prop}\n\tIf $x_n$ is a convergent sequence with $\\lim_{n \\to \\infty} x_n\n\t= a$, then any subsequence $x_{n_k}$ coverges and $\\lim_{k \\to\n\t\\infty} x_{n_k} = a$.\n\\end{prop}\n\n\\begin{proof}\n\t$x_n$ coverges so\n\t\\[\n\t\t\\forall \\eps > 0 \\exists N : |x_n - a| < \\eps \\quad \\forall n > N\n\t\\]\n\n\tSince $x_{n_k}$ is a subsequence of $x_n$, $n_k \\geq k$ hence\n\t\\[\n\t\t| x_{n_k} -a | < \\eps \\quad \\forall k > N\n\t\t\\implies \\lim x_{n_k} = a\n\t\\]\n\\end{proof}\n\n\\begin{thm}[Bolzano-Weierstrass]\n\tAny bounded sequence has a convergent subsequence.\n\\end{thm}\n\n\\begin{proof}\n\tLet $x_n$ be a bounded sequence, then\n\t\\[\n\t\t\\exists I_1 = [a,b] : x_n \\in I_1, \\, \\forall n \\geq 1\n\t\\]\n\n\tIf $c_1$ is the midpoint of $I_1$, then either $[a,c_1]$ or\n\t$[c_1,b]$ contains infinitely many terms of $x_n$. We call this\n\t$I_2$.\n\n\tWe can continue in this manner, forming a sequnce $I_n$.\n\n\tWe can form a subsequence of $x_n$ by taking $x_{n_1} \\in I_1$,\n\t$x_{n_2} \\in I_2$, etc.\\ such that $n_1 < n_2 < \\cdots < n_k$.\n\n\tSince the interval sizes are arbitrarily small, we can take\n\t$\\eps = b_n - a_n$, where $I_n = [a_n,b_n]$. Hence\n\t\\[\n\t\t|x-y| < b_n - a_n = \\eps, \\quad \\forall x,y \\in I_n\n\t\\]\n\tand $x_{n_k}$ is Cauchy so it must converge.\n\\end{proof}\n\n\\section{Functions}\n\n\\begin{defn}[Continuous]\n\tA function $f: (a,b) \\to \\RR$ is continuous at $c \\in (a,b)$\n\tif for any sequence of real numbers $x_n \\in (a,b)$ where $\\lim\n\tx_n = c$, one has $\\lim f(x_n) = f(c)$.\n\n\tEquivalently, we could say $\\lim_{x \\to c} f(x) = f(c)$.\n\n\\end{defn}\n\n\\begin{defn}[Function Limits]\n\tFunctions can have left and right limits.\n\n\tLet $f: (a,c) \\cup (c,b) \\to \\RR$.\n\n\tConsider $x \\in (a,c)$, then $\\lim_{x \\to c^-} f(x) = L$ is the\n\tleft limit of $f$ if:\n\t\\[\n\t\t\\forall \\eps > 0 \\exists \\delta > 0 :\n\t\tc - \\delta < x < c \\implies L - \\eps < f(x) < L\n\t\\]\n\n\tNow consider $x \\in (c,b)$, then $\\lim_{x \\to c^+} f(x) = L$ is\n\tthe right limit of $f$ if:\n\t\\[\n\t\t\\forall \\eps > 0 \\exists \\delta > 0 :\n\t\ta < x < a + \\delta \\implies L < f(x) < L + \\eps\n\t\\]\n\n\tLet $x \\in (a,c) \\cup (c,b)$, then $\\lim_{x \\to c} f(x) = L$ is\n\tthe limit of $f$ if:\n\t\\[\n\t\t\\forall \\eps > 0 \\exists \\delta > 0 :\n\t\t|x-c| < \\delta \\implies |f(x) - L| < \\eps\n\t\\]\n\n\tIf the limit exists, then so do the left and right limits and they are\n\tall equal. Conversely, if the left and right limits exist and are equal,\n\tthe limit exists and share this common value.\n\\end{defn}\n\n\\begin{thm}\n\tLet $f$ be a function defined on $U = (a,c) \\cup (c,b)$, then\n\t$\\lim_{x \\to c}f(x)$ exists iff for all sequences $x_n \\in U$\n\twith $\\lim_{x \\to \\infty} x_n = c$, we have\n\t\\[\n\t\t\\lim_{n \\to \\infty} f(x_n) = \\lim_{x \\to c} f(x)\n\t\\]\n\\end{thm}\n\n\\begin{proof}\n\tAssume that $\\lim_{x \\to c}f(x) = L$.\n\n\t\\[\n\t\t\\forall \\eps > 0 \\, \\exists \\delta :\n\t\t|x-c| < \\delta \\implies |f(x)-L| < \\eps\n\t\\]\n\n\tLet $x_n$ be a sequence such that $\\lim_{n \\to\\infty}x_n = c$, then\n\t\\[\n\t\t\\forall \\eps' > 0 \\, \\exists N \\in \\NN :\n\t\t|x_n - c| < \\eps', \\, \\forall n > N\n\t\\]\n\n\tLet $\\eps' = \\delta$, then\n\t\\begin{align*}\n\t\t|x_n - c| < \\delta \\quad \\forall n > N \\\\\n\t\t&\\implies |f(x_n) - L| < \\eps \\quad \\forall n > N \\\\\n\t\t&\\implies \\lim f(x_n) = L\n\t\\end{align*}\n\n\tAssume now that $\\lim x_n = L$.\n\n\tAssume that $\\lim f(x) \\neq L$, then\n\t\\[\n\t\t\\exists \\eps > 0 \\, \\forall \\delta > 0 : \\exists x :\n\t\t|x-c| < \\delta \\implies |f(x) - L| \\geq \\eps\n\t\\]\n\n\tFix $\\eps$ and let $\\delta = 1$, then there exists $x_1$ such that:\n\t\\[\n\t\t|x_1 - c| < 1 \\implies |f(x_1) - L| \\geq \\eps\n\t\\]\n\n\tLet $\\delta = \\frac{1}{2}$, then there exists $x_2$ such that:\n\t\\[\n\t\t|x_2 - c| < \\frac{1}{2} \\implies |f(x_2) - L| \\geq \\eps\n\t\\]\n\n\tContinuing in this way, we obtain a sequence $x_n$ such that\n\t$\\lim f(x_n) \\neq L$, which is an obvious contradiction.\n\\end{proof}\n\n\\begin{rem}\n\tLet $f:[a,b] \\to \\RR$ be a function. $f$ is continuous as $c \\in\n\t(a,b)$ if $\\lim_{x \\to c} f(x) = f(c)$.\n\t$f$ is continuous as $a \\in (a,b)$ if $\\lim_{x \\to a^-} f(x) =\n\tf(a)$.\n\t$f$ is continuous as $a \\in (a,b)$ if $\\lim_{x \\to b^+} f(x) =\n\tf(b)$.\n\\end{rem}\n\n\\begin{defn}[Continuous]\n\t$f:[a,b] \\to \\RR$ is continuous at $c$ if\n\t\\[\n\t\t\\forall \\eps > 0 \\, \\exists \\delta > 0 :\n\t\t|x-c| < \\delta \\implies |f(x)-f(c)| < \\eps\n\t\\]\n\t$f$ is continuous if it is continuous at every point in its\n\tdomain.\n\\end{defn}\n\n\\subsection{Open and Closed Subsets}\n\n\\begin{defn}[Open Subset]\n\tA subset $U \\subset \\RR$ is called open if\n\t\\[\n\t\t\\forall a \\in U \\, \\exists \\eps > 0 :\n\t\t(a-\\eps, a+\\eps) \\subset U\n\t\\]\n\\end{defn}\n\n\\begin{defn}[Preimage]\n\tLet $f:[a,b] \\to \\RR$ and $U \\subset \\RR$. The preimage of $U$\n\tis defined as follows:\n\t\\[\n\t\tf^{-1}(U) = \\{ x \\in [a,b] \\mid f(x) \\in U \\}\n\t\\]\n\\end{defn}\n\n\\begin{ex}\n\t\\[\n\t\tf(x) = x^2, \\quad f:\\RR \\to \\RR, \\quad U = \\{0,1\\}\n\t\\]\n\t\\[\n\t\tf^{-1}(U) = \\{ x \\in \\RR \\mid x^2 \\in U \\}\n\t\t= \\{ \\pm 1, 0 \\}\n\t\\]\n\\end{ex}\n\n\\begin{defn}[Closed Subset]\n\tA subset $V \\in \\RR$ is closed if its compliment is open.\n\\end{defn}\n\n\\begin{prop}\n\t$V \\subset \\RR$ is closed iff for any convergent sequence of\n\treal numbers $x_n$ in $V$, the limit is also in $V$.\n\\end{prop}\n\n\\begin{proof}\n\tLet $V = [a,b]$ and $x_n$ be a sequence in $V$.\n\n\tIf every $x_n$ has a limit in $V$ then the sequence $a +\n\t\\frac{\\eps}{n}$, which clearly converges to $a$, must be in $V$.\n\tLikewise, the sequence $b - \\frac{\\eps}{n}$, whose limit is\n\tclearly $b$, must have it's limit in $V$.\n\n\tAssuming $V$ is closed, assume also that there is a sequence\n\t$x_n$ whose limit $L \\notin [a,b]$, then $L = a -\n\t\\frac{\\eps}{2}$ or $b + \\frac{\\eps}{2}$ for some $\\eps > 0 \\in\n\tRR$.\n\n\t\\begin{align*}\n\t\tL &= a - \\frac{\\eps}{2} \\\\\n\t\t  &\\implies \\exists N \\in \\NN : |x_n - a + \\frac{\\eps}{2}|\n\t\t< \\frac{\\eps}{2}, \\,\\forall n > N \\\\\n\t\t&\\implies |x_n - a| - |- \\frac{\\eps}{2}| < \\frac{\\eps}{2} \\\\\n\t\t&\\implies |x_n - a| < \\eps \\\\\n\t\t&\\implies a = \\lim x_n\n\t\\end{align*}\n\tThis is a contradiction because $a \\in V$.\n\n\t\\begin{align*}\n\t\tL &= b + \\frac{\\eps}{2} \\\\\n\t\t  &\\implies \\exists N \\in \\NN : |x_n - b - \\frac{\\eps}{2}|\n\t\t< \\frac{\\eps}{2}, \\,\\forall n > N \\\\\n\t\t&\\implies |x_n - b| - |\\frac{\\eps}{2}| < \\frac{\\eps}{2} \\\\\n\t\t&\\implies |x_n - b| < \\eps \\\\\n\t\t&\\implies b = \\lim x_n\n\t\\end{align*}\n\tThis is a contradiction because $b \\in V$.\n\\end{proof}\n\n\\subsection{Properties of Open and Closed Sets}\n\n\\begin{itemize}\n\t\\item A finite union of closed subsets is closed\n\t\\item Any intersetion of closed subsets is closed\n\t\\item Any union of open subsets is open\n\t\\item A finite intersection of open subsets is open\n\\end{itemize}\n\n\\begin{proof}\n\tNumber 2. \\\\\n\n\tLet $[a,b]$ and $[c,d]$ be two closed subsets in $\\RR$, with a\n\tnonempty intersection.  If either is a subset of the other, then\n\twe are done.  If not, then either $c>a$ and $d>b$, or $a>c$ and\n\t$b>d$, resulting in the intersection being either $[c,b]$ or\n\t$[a,d]$, both of which are clearly closed.\n\\end{proof}\n\n\\begin{thm}\n\tFor a function $f:(a,b) \\to \\RR$, $f$ is continuous iff the\n\tpreimage of an open set under $f$ is also open.\n\\end{thm}\n\n\\begin{proof}\n\tAssume that $f$ is continuous. \\\\\n\n\tLet $U \\subset \\RR$ be open and let $W$ be the preimage of $U$\n\tunder $f$.  Let $c \\in W$ such that $f(c) = d \\in U$. Given that\n\t$U$ is open, ther is $\\eps > 0$ such that $(d-\\eps, d+\\eps)\n\t\\subset U$.\n\n\tBy the coninuity of $f$, there must be a $\\delta > 0$ such that\n\t$|f(x) - f(c)| < \\eps$ when $|x-c| < \\delta$. We now need to\n\tshow that $(c-\\delta, c+\\delta) \\subset W$.\n\n\t\\[\n\t\tz \\in (c-\\delta, c+\\delta) \\implies |z-c| < \\delta\n\t\t\\implies |f(z)-f(c)| < \\eps\n\t\\]\n\t\\[\n\t\t\\implies |f(z) - f(d)| < \\eps\n\t\t\\implies f(z) \\in (d-\\eps, d+\\eps) \\subset U\n\t\t\\implies z \\in W\n\t\\]\n\n\tSo, $(c-\\delta, c+\\delta) \\subset W$, hence\n\t\\[\n\t\t\\forall c \\in W \\exists \\delta > 0 :\n\t\t(c-\\delta, c+\\delta) \\subset W\n\t\\]\n\tand $W$ is open. \\\\\n\n\tAssume the openness of sets is preserved under $f$. \\\\\n\n\tFix $\\eps > 0$ and let $x \\in (a,b)$ such that $f(x) = d \\in\n\tRR$.  Let $U = (d-\\eps, d+\\eps) \\subset \\RR$, then $W =\n\tf^{-1}(U)$ is open by assumption.\n\n\t\\[\n\t\t\\implies \\exists \\delta > 0 :\n\t\t(x-\\delta, x+\\delta) \\subset W\n\t\\]\n\n\tLet $y \\in (x-\\delta, x+\\delta)$, then $|x-y| < \\delta$ hence\n\t$f(y) \\in (d-\\eps, d+\\eps)$ and $|f(y) - f(x)| < \\eps$.\n\n\\end{proof}\n\n\n\\subsection{Properties of Continuous Functions}\n\n\\begin{enumerate}\n\t\\item The identity map is continuous\n\t\\item\n\t\tIf $f,g:(a,b) \\to \\RR$ are continuous, then $f+g$, $f-g$,\n\t\t$f\\cdot g$ are all continuous. If $g(x) \\neq 0 \\forall x\n\t\t\\in (a,b)$, $f(x)/g(x)$ is also continuous.\n\t\\item $f \\circ g$ is continuous\n\t\\item $f(\\lim x_n) = \\lim f(x_n)$\n\\end{enumerate}\n\n\\begin{proof}\n\t\\begin{enumerate}\n\t\t\\item\n\t\t\tFix $\\eps$ and take $\\delta = \\eps$, then\n\t\t\t\\[ |x-y| < \\delta \\implies |x-y| < \\eps \\implies |f(x)-f(y)| < \\eps \\]\n\n\t\t\\item Follows from preservation of open sets.\n\n\t\t\\item\n\t\t\tLet $c = \\lim x_n$, then\n\t\t\t\\[ \\exists \\eps > 0, \\, N \\in \\NN : |x_n - c| < \\eps, \\, \\forall n > N \\]\n\t\t\tBy continuity,\n\t\t\t\\[ \\exists \\delta > 0 : |x_n -c| < \\delta \\implies |f(x)-f(c)| < \\delta \\]\n\t\t\t\\[\n\t\t\t\t\\implies |f(x_n) - f(c)| < \\delta, \\, \\forall n > N\n\t\t\t\t\\implies \\lim f(x_n) = f(c) = f(\\lim x_n)\n\t\t\t\\]\n\n\t\t\\item\n\t\t\tFollows from 4 and the properties of limits, since $f$ is continuous at $c$ iff\n\t\t\t$x_n \\to c \\implies f(x_n) \\to f(c)$.\n\t\\end{enumerate}\n\\end{proof}\n\n\\begin{cor}\n\tAny polynomial is a continuous function.\n\\end{cor}\n\n\\subsection{Intermediate Value Theorem}\n\n\\begin{thm}[Sandwich]\n\tLet $a_n$ and $b_n$ be sequences such that $\\lim a_n = \\lim b_n\n\t= C$. Then, if $c_n$ is a sequence such that $a_n \\leq c_n \\leq\n\tb_n \\, \\forall n \\in \\NN$, then $\\lim c_n = C$.\n\\end{thm}\n\n\\begin{proof}\n\t$|c_n -C| \\leq |a_n - C|$ or $|c_n -C| \\leq |b_n - C|$, i.e.\\\n\t$c_n$ is closer to $C$ than either $a_n$ or $b_n$.\n\n\t$\\forall \\eps > 0 \\exists N_1,N_2 \\in \\NN : n > N_1 \\implies\n\t|a_n - C| < \\eps, \\, n > N_2 \\implies |b_n - C| < \\eps$\n\n\tLet $N = \\max(N_1, N_2)$, then for all $n > N$:\n\t\\[ |a_n - C| < \\eps \\quad |b_n - C| < \\eps \\]\n\t\\[ \\implies |c_n -C| < \\eps \\implies \\lim c_n = C \\]\n\\end{proof}\n\n\\begin{thm}[Intermediate Value Theorem]\n\tLet $f:[a,b] \\to \\RR$ be a continuous function. If $f(a) = A\n\t\\leq C \\leq B = f(b)$, then $\\exists c \\in [a,b] : f(c) = C$.\n\\end{thm}\n\n\\begin{proof}\n\tConsider $g(x) = f(x) - C$. We aim to show that $g(c) = 0$ for some $c \\in [a,b]$.\n\n\tAssume $A \\leq C \\leq B$, then\n\t\\[ g(a) = f(a) - C \\leq 0 \\]\n\t\\[ g(b) - f(b) - C \\geq 0 \\]\n\n\tIf $g(a) = 0$ or $g(b) = 0$, the we are done. Assume $g(a) < 0$ and $g(b) > 0$.\n\n\tWe can construct segments $[a_k, b_k] \\subset [a,b]$, inductively as follows:\n\t\\[ [a_1, b_1] = [a,b] \\]\n\tAssume $[a_n, b_n]$ exists, and let $m$ be the midpoint of this interval.\n\t\\[ m = \\frac{b_n + a_n}{2} \\in [a_n, b_n] \\subset [a,b] \\]\n\tEither $g(m) \\leq 0$ or $g(m) > 0$. If $g(m) \\leq 0$, then\n\t\\[ [a_{n+1}, b_{n+1}] = [m, b_n] \\]\n\tbut if $g(m) > 0$, then\n\t\\[ [a_{n+1}, b_{n+1}] = [a_n, m] \\]\n\n\tWe now have two bounded monotonic sequnces, $a_n$ and $b_n$, so\n\tthey have well-defined limits.\n\n\tWe also have\n\t\\[\n\t\tb_{n+1} - a_{n+1} = \\frac{1}{2^n}(b-a)\n\t\t\\implies \\lim a_n = \\lim b_n = c\n\t\\]\n\n\tNote that $g(a_k) \\leq 0$ and $g(b_k) \\geq 0$ for every $k \\NN$.\n\t\\[ \\implies \\lim g(a_n) = g(\\lim a_n) = g(c) \\leq 0 \\]\n\tsimilarly,\n\t\\[ \\implies \\lim g(b_n) = g(\\lim b_n) = g(c) \\geq 0 \\]\n\t\\[ \\implies g(c) = 0 \\implies f(c) = C \\]\n\\end{proof}\n\n\\begin{defn}[Bounded Function]\n\tA function $f:I \\to \\RR$, where $I = [a,b] \\subset \\RR$, is bounded if\n\t\\[ \\exists M \\in \\RR, \\, m > 0 : |f(x)| \\leq M \\, \\forall x \\in I. \\]\n\tEquivalently, we could say\n\t\\[ \\exists A, B \\in \\RR : A \\leq f(x) \\leq B \\, \\forall x \\in I. \\]\n\\end{defn}\n\n\\begin{thm}\n\tIf $f:[a,b] \\to \\RR$ is continuous, then $f$ is bounded.\n\\end{thm}\n\n\\begin{proof}\n\tAssume that $f$ is unbounded on $I = [a,b]$. Let $m = \\frac{b+a}{2}$\n\tand divide $I$ into two subintervals: $[a,m]$ and $[m,b]$; $f$ must be\n\tunbounded on one of these intervals.\n\n\tDenote this subinterval by $[a_1, b_1]$, then construct a\n\tsequence of subintervals inductively.\n\n\tIt is clear that $\\lim a_n = \\lim b_n = c$.\n\n\tBy assumption, $f$ is unbounded in each of these intervals, in other words,\n\t\\[ \\exists c_n \\in [a_n, b_n] : f(c_n) > N \\forall N \\in \\NN. \\]\n\n\tThis implies $\\lim f(c_n)$ does not exist, but this contradicts\n\tthe sandwich theorem.\n\\end{proof}\n\n\\begin{thm}[Weierstrass Extremal Value Theorem]o\n\tLet $f:[a,b] \\to \\RR$ be a continuous function, then\n\t\\[ \\exists c,d \\in [a,b] : f(c) \\leq f(x) \\leq f(d) \\forall x \\in [a,b] \\]\n\\end{thm}\n\n\\begin{proof}\n\t$\\{f(x) \\mid x \\in [a,b] \\}$ is bounded, so $m = \\inf \\{f(x)\\}$ exists.\n\n\t$m+\\eps$ is not a lower bound, hence $\\exists y : f(y) < m+\\eps$.\n\n\tIf $\\eps = 1/n$, then denote with $y_n$ the corresponding $y$.\n\n\t\\[\n\t\tm \\leq f(y_n) < m + \\frac{1}{n}\n\t\t\\implies |f(y_n) -m| < \\frac{1}{n} \\, \\forall n \\in \\NN\n\t\\]\n\t\\[ \\implies \\lim f(y_n) = m \\]\n\n\t$y_n \\in [a,b] \\forall n \\in \\NN$, hence $y_n$ is bounded and\n\thas a convergent subsequence.\n\n\t\\[\n\t\t\\lim y_{n_k} = c \\implies f(\\lim y_{n_k}) = f(c)\n\t\t= \\lim f(y_{n_k}) = m\n\t\\]\n\t\\[ \\implies m = f(c) \\implies f(x) \\geq f(c) \\forall x \\in [a,b] \\]\n\n\tSimilarly, $M = \\sup \\{f(x)\\}$, hence $M-\\eps$ is not an upper bound and\n\t$\\exists y \\in (a,b) : M \\geq f(y) > M-\\eps$.\n\t\\[ \\implies |f(y) - M| < \\eps \\]\n\n\tLet $\\eps = \\frac{1}{n}$ for $y_n$, then $\\lim f(y_n) = M$.\n\tTherefore there is a subsequence $y_{n_k}$ such that $\\lim y_{n_k} = d$.\n\n\t\\[ \\implies f(\\lim y_{n_k}) = f(d) = \\lim f(y_{n_k}) = M \\]\n\t\\[ \\implies f(d) = M \\implies f(x) \\leq f(d) \\forall x \\in [a,b] \\]\n\n\tThe extrema are reached at least once, simply because the limits\n\thave to exist within the bounded subsets in which their\n\tsequences are contained.\n\\end{proof}\n\n\\subsection{Applications of IVT}\n\n\\begin{itemize}\n\t\\item If $f:[a,b] \\to \\RR$ is continuous, with $f(a) < 0$ and\n\t\t$f(b) > 0$, then $\\exists c \\in (a,b) : f(c) = 0$\n\t\\item Let $f:[0,1] \\to (0,1)$ be continuous, then\n\t\t$\\exists c \\in (0,1): f(c) = c$\n\\end{itemize}\n\n\\begin{proof}\n\tLet $g(x) = x - f(x)$, then $g(0) = -f(0) < 0$ and $g(1) = 1 - f(1) > 0$,\n\tsince $f(x) \\in (0,1)$.\n\n\t\\[ \\implies \\exists c \\in (0,1) : g(c) = 0 \\implies f(c) = c \\]\n\\end{proof}\n\n\\subsection{Differentiable Functions}\n\n\\begin{defn}[Differentiable]\n\tA function $f$ is differentiable at $c$ if the following limit exists:\n\t\\[ \\lim_{h \\to 0} \\frac{f(c+h) - f(c)}{h} \\]\n\t$f$ is called differentiable if it is differentiable at any point in it's domain.\n\\end{defn}\n\n\\begin{lemma}\n\t$f$ differentiable at $c$ implies $f$ continuous at $c$.\n\\end{lemma}\n\n\\begin{proof}\n\tLet $f$ be differentialble at $c$.\n\t\\[\n\t\t\\implies f'(c) = \\lim_{h \\to 0} \\frac{f(c+h) - f(c)}{h}\n\t\t= \\lim_{x \\to c} \\frac{f(x) - f(c)}{x-c}\n\t\\]\n\t\\begin{align*}\n\t\t\\lim_{x \\to c} f(x) - f(c)\n\t\t&= \\lim_{x \\to c}(x-c) \\lim_{x \\to c} \\frac{f(x) - f(c)}{x-c} \\\\\n\t\t&= 0\n\t\\end{align*}\n\t\\[\n\t\t\\implies \\lim_{x \\to c} f(x) = f(c)\n\t\\]\n\thence $f$ is continuous at $c$.\n\\end{proof}\n\n\\begin{rem}\n\tNot all continuous functions are differentiable, e.g.\\ $f(x) = |x|$.\n\\end{rem}\n\n\\begin{lemma}[Product Rule]\n\t$(f(x)g(x))' = f(x)g'(x) + f'(x)g(x)$.\n\\end{lemma}\n\n\\begin{proof}\n\t\\begin{align*}\n\t\t&\\lim_{h \\to 0} \\frac{f(x+h)g(x+h) - f(x)g(x)}{h} \\\\\n\t\t&= \\lim_{h \\to 0} \\frac{f(x+h)g(x+h) - f(x+h)g(x) + f(x+h)g(x) - f(x)g(x)}{h} \\\\\n\t\t&= \\lim_{h \\to 0} \\frac{f(x+h)(g(x+h) - g(x))}{h}\n\t\t+ \\lim_{h \\to 0} \\frac{g(x)(f(x+h) - f(x))}{h} \\\\\n\t\t&= \\lim_{h \\to 0} f(x+h) \\lim_{h \\to 0} \\frac{g(x+h) - g(x)}{h}\n\t\t+ g(x) \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h} \\\\\n\t\t&= f(x)g'(x) + g(x)f'(x)\n\t\\end{align*}\n\\end{proof}\n\n\\begin{lemma}[Quotient Rule]\n\t\\[ \\left( \\frac{f}{g} \\right)' = \\frac{f'g - g'f}{g^2} \\]\n\\end{lemma}\n\n\\begin{proof}\n\t\\begin{align*}\n\t\t&\\lim_{h \\to 0} \\left(\\frac{f(x+h)}{g(x+h)} - \\frac{f(x)}{g(x)}\\right)/h \\\\\n\t\t&= \\lim_{h \\to 0} \\frac{f(x+h)g(x) - f(x)g(x+h)}{hg(x)g(x+h)} \\\\\n\t\t&= \\lim_{h \\to 0} \\frac{f(x+h)g(x) - f(x)g(x) - f(x)g(x+h) + f(x)g(x)}{hg(x)g(x+h)} \\\\\n\t\t&= \\lim_{h \\to 0} \\left(\n\t\t\tg(x)\\frac{f(x+h) - f(x)}{h} - f(x)\\frac{g(x+h) - g(x)}{h}\n\t\t\\right)/g(x)g(x+h)\n\t\\end{align*}\n\\end{proof}\n\n\\begin{lemma}\n\t$f$ is differentiable at $c$ iff $\\exists A \\in \\RR$ and a continuous funtion $\\alpha$ such that\n\t\\[ f(x) = f(c) + A(x-c) + \\alpha(x)(x-c) \\]\n\twhere $\\lim_{x \\to c} \\alpha(x) = 0$.\n\tIf this is so, then $A = f'(c)$.\n\\end{lemma}\n\n\\begin{proof}\n\tAssume $A$ and $\\alpha$ exist.\n\t\\[ f(c+h) = f(c) + Ah + \\alpha(c+h)h \\]\n\t\\[\n\t\t\\lim_{h \\to 0} \\frac{f(c+h) - f(c)}{h}\n\t\t= \\lim_{h \\to 0} \\frac{Ah + h\\alpha(c+h)}{h} = A\n\t\\]\n\t\\[ \\implies f'(c) = A\\]\n\t(since $\\alpha(c) = 0$).\n\n\tAssume $f$ differentiable at $c$.\n\n\tLet $f'(c) = A = \\lim_{h \\to 0}\\frac{f(c+h) - f(c)}{h}$.\n\tLet\n\t\\[\n\t\t\\alpha(x) =\n\t\t\\begin{cases}\n\t\t\t\\frac{f(x) - f(c)}{x-c} - A, &x \\neq c \\\\\n\t\t\t0, &x = c\n\t\t\\end{cases}\n\t\\]\n\t\\[ f(x) = f(c) + (x-c)A + (x-c)\\alpha(x) \\]\n\tNeed to show that $\\lim_{x \\to c} \\alpha(x) = 0$.\n\n\t\\begin{align*}\n\t\t\\lim_{x \\to c} \\alpha(x) &= \\lim_{x \\to c}\\frac{f(x)-f(c)}{x-c} - f'(c) \\\\\n\t\tx = c+h &\\implies \\lim_{h \\to 0} \\frac{f(c+h)-f(c)}{h} - f'(c) \\\\\n\t\t\t&= 0\n\t\\end{align*}\n\\end{proof}\n\n\\begin{lemma}[Chain Rule]\n\tLet $f:(a,b) \\to (c,d) \\subset \\RR$ and $g:(c,d) \\to \\RR$, where\n\t$f$ is differentiable at $x_0 \\in (a,b)$ and $g$ is\n\tdifferentiable at $y_0 = f(x_0)$. Then, $\\phi(x) = g(f(x))$ is\n\tdifferentiable at $x_0$, and\n\t\\[ \\phi'(x_0) = g'(f(x_0))f'(x_0). \\]\n\\end{lemma}\n\n\n\\begin{proof}\n\tUsing the previous lemma, we know that:\n\t\\[ f(x) = f(x_0) + A(x-x_0) + \\alpha(x)(x-x_0) \\]\n\twhere\n\t\\[ A = f'(x_0), \\, \\lim_{x \\to x_0} \\alpha(x) = 0 \\]\n\n\tSimilarly,\n\t\\[ g(y) = g(y_0) + B(y-y_0) + \\beta(y)(y-y_0) \\]\n\twhere\n\t\\[ B = g'(y_0), \\, \\lim_{y \\to y_0} \\beta(y) = 0 \\]\n\n\tLet $y = f(x)$ and $y_0 = f(x_0)$, then\n\t\\[ g(f(x)) = g(f(x_0)) + B(f(x)-f(x_0)) + \\beta(f(x))(f(x) - f(x_0)) \\]\n\t\\[\n\t\t\\implies \\phi(x) = \\phi(x_0) + B(A(x-x_0) + (x-x_0)\\alpha(x))\n\t\t+ \\beta(f(x))(A(x-x_0) + (x-x_0)\\alpha(x))\n\t\\]\n\t\\[ \\phi(x_0) + BA(x-x_0) + \\gamma(x)(x-x_0) \\]\n\twhere\n\t\\[ \\gamma(x) = B\\alpha(x) + A\\beta(f(x)) + \\alpha(x)\\beta(f(x)) \\]\n\n\t$\\lim_{x \\to x_0} \\gamma(x) = 0$ since $\\lim_{x \\to x_0} \\alpha(x) = \\lim_{x \\to x_0} \\beta(f(x)) = 0$.\n\n\t\\[ \\implies BA = \\phi'(x_0) \\]\n\t\\[ \\implies \\phi'(x_0) = g'(f(x_0))f'(x_0) \\]\n\\end{proof}\n\n\\begin{defn}[Local Maximum]\n\tLet $f:[a,b] \\to \\RR$. $x_0$ is a local maximum of $f$ if $\\exists \\delta > 0$ such that\n\t\\[ f(x) \\leq f(x_0) \\forall x \\in (x_0 - \\delta, x_0 + \\delta) \\subset [a,b]. \\]\n\\end{defn}\n\n\\begin{thm}[Fermat]\n\tAssume $f:[a,b] \\to \\RR$ is continuous, and differentiable at\n\t$x_0$. If $x_0$ is a local maximum, then $f'(x_0) = 0$.\n\\end{thm}\n\n\\begin{proof}\n\tLet $\\delta > 0$ and $U = (x_0 - \\delta, x_0 + \\delta) \\subset [a,b]$, where $x_0$ is a local max.\n\n\tTake $h > 0$ such that $x_0 + h \\in U$, then\n\t\\[\n\t\t\\lim_{h \\to 0} \\frac{f(x_0 + h) - f(x_0)}{h} \\leq 0\n\t\\]\n\n\tWe may also take $h < 0$ such that $x_0 + h \\in U$, and\n\t\\[\n\t\t\\lim_{h \\to 0} \\frac{f(x_0 + h) - f(x_0)}{h} \\geq 0\n\t\\]\n\n\t\\[ \\implies f'(x_0) = 0 \\]\n\\end{proof}\n\n\\begin{defn}[Critical Point]\n\tA point $x_0 \\in (a,b)$ of $f:[a,b] \\to \\RR$ iff $f'(x_0) = 0$.\n\tNote that any local maxiumum or minimum is a critical point.\n\\end{defn}\n\n\\begin{cor}\n\t$\\max f(x) = \\max \\{ f(A), f(B), f(x_1), \\ldots, f(x_n) \\}$, where\n\t$x_1, \\ldots, x_n$ are critical points of $f$.\n\\end{cor}\n\n\\begin{ex}\n\t\\[ f:[0,2] \\to \\RR, \\quad f(x) = 1 + 5x - x^5 \\]\n\t\\begin{align*}\n\t\tf'(x) = 5 - 5x^4 &= 0 \\\\\n\t\tx^4 &= 1 \\\\\n\t\tx &= \\pm 1\n\t\\end{align*}\n\n\t$-1 \\not \\in [0,2]$ so $1$ is the only critical point we care about.\n\n\tWe now check the values of the bounds and critical points:\n\t\\[ f(1) = 1 \\]\n\t\\[ f(0) = 1 \\]\n\t\\[ f(2) = -21 \\]\n\thence, $\\max f(x) = 1$ (on $[0,2]$).\n\\end{ex}\n\n\\begin{thm}[Rolle's Theorem]\n\tLet $f:[a,b] \\to \\RR$ be a continuous funtion, which is\n\tdifferentiable on $(a,b)$. If $f(a) = f(b)$, then there is $c\n\t\\in (a,b)$ such that $f'(c) = 0$.\n\\end{thm}\n\n\\begin{proof}\n\tWe know there are points $x_0$ and $x_1$ in $[a,b]$ such that\n\t$f(x_0) \\leq f(x) \\leq f(x_1) \\forall x \\in [a,b]$. (By taking\n\tthe max and min of the endpoints and critical points).\n\n\tIf $x_1$ and $x_0$ are the endpoints of the interval $[a,b]$,\n\tthen the function must be constant, so $f'(x) = 0 \\forall x \\in\n\t[a,b]$.\n\n\tAssume that $x_1$ is within $(a,b)$, then $x_1$ is a local\n\tmaximum and, by Fermat's Theorem, is a critical point. Hence\n\t$f'(x_1) = 0$.\n\\end{proof}\n\n\\begin{thm}[Mean Value Theorem (Lagrange)]\n\tLet $f:[a,b] \\to \\RR$ be a continuous function, which is\n\tdifferentiable on $(a,b)$, then:\n\t\\[ \\exists c \\in (a,b) : f(b) - f(a) = f'(c)(b-a) \\]\n\\end{thm}\n\n\\begin{proof}\n\tConsider a function\n\t\\[ g(x) = f(x) - \\frac{f(b) - f(a)}{b-a}x \\]\n\t\\begin{align*}\n\t\tg(b) - g(a) &= f(b) - \\frac{f(b) - f(a)}{b-a}b\n\t\t- f(a) + \\frac{f(b) - f(a)}{b-a}a \\\\\n\t\t&= \\left( f(b) - f(a) \\right)\n\t\t\\left(1 - \\frac{b}{b-a} + \\frac{a}{b-a} \\right) \\\\\n\t\t&= 0\n\t\\end{align*}\n\n\tBy Rolle's theorem, there is $c \\in (a,b)$ such that $g'(c) = 0$.\n\n\t\\[ \\implies f'(c) = \\frac{f(b) - f(a)}{b-a} \\]\n\\end{proof}\n\n\\begin{cor}\n\tLet $f:[a,b] \\to \\RR$ be a continuous function, which is differentiable in $(a,b)$, then:\n\t\\begin{enumerate}\n\t\t\\item If $f'(x) > 0 \\forall x \\in (a,b)$, then f is strictly increasing.\n\t\t\\item If $f'(x) < 0 \\forall x \\in (a,b)$, then f is strictly decreasing.\n\t\t\\item If $f'(x) = 0 \\forall x \\in (a,b)$, then f is constant.\n\t\\end{enumerate}\n\\end{cor}\n\n\\begin{proof}\n\t\\begin{enumerate}\n\t\t\\item Take $[c,d] \\subset [a,b]$ and $x_0 \\in (c,d)$, then by MVT we have\n\t\t\t\\[ f(d) - f(c) = f'(x_0)(d-c) > 0 \\implies f(d) > f(c) \\]\n\t\t\\item Similar to 1.\n\t\t\\item Take $c,d \\in [a,b]$, then $\\exists x_0 \\in (c,d)$ such that\n\t\t\t\\[ f(d) - f(c) = f'(x_0)(d-c) = 0 \\implies f(d) = f(c) \\]\n\t\\end{enumerate}\n\\end{proof}\n\n\\begin{ex}\n\t\\[ f(x) = \\frac{1}{3}x^3 - 3x^2 + 8x - 5 \\]\n\n\t\\[ f'(x) = x^2 - 6x + 8 = (x-4)(x-2) \\]\n\thence $x=4,2$ are critical points.\n\n\t\\[ f'(3) = 9 - 18 + 8 = -1 \\implies f'(x) < 0 \\forall x \\in (2,4) \\]\n\n\t\\[ f'(x) > 0 \\forall x \\in \\RR \\setminus [2,4] \\]\n\n\tSo $f(x)$ is increasing in $(2,4)$ and decreasing in $\\RR \\setminus [2,4]$.\n\\end{ex}\n\n\\begin{thm}[Cauchy MVT Generalisation]\n\tAssume $f,g:[a,b] \\to \\RR$ are continous and differentiable in $(a,b)$, then\n\t\\[ \\exists c \\in (a,b) : (g(b) - g(a))f'(c) = (f(b) - f(a))g'(c) \\]\n\\end{thm}\n\n\\begin{proof}\n\tIf $g(b) = g(a)$ then by Rolle's Theorem, $\\exists c \\in (a,b) : g'(c) = 0$, and we are done.\n\n\tAssume $g(a) \\neq g(b)$.\n\n\tLet $h(x) = (g(b) - g(a))f(x) - (f(b) - f(a))g(x)$.\n\n\t\\begin{align*}\n\t\th(b) - h(a) &= f(b)g(b) - f(b)g(a) - f(b)g(b) + f(a)g(b) \\\\\n\t\t&- f(a)g(b) + f(a)g(a) + f(b)g(a) - f(a)g(a) \\\\\n\t\t&= 0\n\t\\end{align*}\n\n\t\\[ \\implies \\exists c \\in (a,b) : h'(c) = 0 \\]\n\n\t\\[ h'(x) = (g(b) - g(a))f'(x) - (f(b) - f(a))g'(x) \\]\n\t\\[ h'(c) = 0 \\implies (g(b) - g(a))f'(c) = (f(b) - f(a))g'(c) \\]\n\\end{proof}\n\n\\begin{rem}\n\tSetting $g$ to the identity map yields the standard MVT\\@.\n\\end{rem}\n\n\\begin{lemma}[L'hopital Rule]\n\tAssume $f$ and $g$ are differentiable in $(a,b)$ and $c \\in (a,b) : f(c) = g(c) = 0$.\n\tMoreover, let $g(x), g'(x) \\neq 0 \\forall x \\neq c$. Then\n\t\\[ \\lim_{x \\to c} \\frac{f(x)}{g(x)} = \\lim_{x \\to c} \\frac{f'(x)}{g'(x)} \\]\n\\end{lemma}\n\n\\begin{proof}\n\tLet $x_n \\in (c,b) : \\lim_{n \\to \\infty} x_n = c$.\n\n\tBy Cauchy MVT, $\\exists y_n \\in (c, x_n)$ such that\n\t\\[ (g(x_n) - g(c))f'(y_n) = (f(x_n) - f(c))g'(y_n) \\]\n\n\tBy assumption, $f(c) = g(c) = 0$, so\n\t\\[\n\t\tg(x_n)f'(y_n) = f(x_n)g'(y_n)\n\t\t\\implies\n\t\t\\frac{f'(y_n)}{g'(y_n)} = \\frac{f(x_n)}{g(x_n)}\n\t\\]\n\n\t\\[ x_n \\to c \\implies y_n \\to c \\]\n\n\t\\[\n\t\t\\implies\n\t\t\\lim_{n \\to \\infty}\\frac{f(x_n)}{g(x_n)}\n\t\t= \\lim_{n \\to \\infty}\\frac{f'(y_n)}{g'(y_n)}\n\t\t= \\lim_{x \\to c^+}\\frac{f'(x)}{g'(x)}\n\t\\]\n\n\tWe can use a similar method for $x_n \\in (a,c)$, hence\n\t\\[\n\t\t\\lim_{x \\to c^-}\\frac{f(x)}{g(x)}\n\t\t= \\lim_{x \\to c^+}\\frac{f(x)}{g(x)}\n\t\t= \\lim_{x \\to c}\\frac{f'(x)}{g'(x)}\n\t\\]\n\\end{proof}\n\n\\begin{ex}\n\t\\[ \\lim_{x \\to 0} \\frac{x - \\sin x}{x^3} \\]\n\n\t$x \\to 0 \\implies f(x), g(x) \\to 0$, so we can apply l'hopital.\n\n\t\\[\n\t\t\\lim_{x \\to 0} \\frac{x - \\sin x}{x^3}\n\t\t= \\lim_{x \\to 0} \\frac{1 - \\cos x}{3x^2}\n\t\\]\n\n\t$x \\to 0 \\implies f(x), g(x) \\to 0$, so we can apply l'hopital again.\n\n\t\\[\n\t\t\\lim_{x \\to 0} \\frac{1 - \\cos x}{3x^2}\n\t\t= \\lim_{x \\to 0} \\frac{\\sin x}{6x}\n\t\t= \\lim_{x \\to 0} \\frac{\\cos x}{6}\n\t\t= \\frac{1}{6}\n\t\\]\n\n\\end{ex}\n\n\\section{Riemann Integration}\n\nDenote by $B_{[a,b]}$ the set of all bounded functions on $[a,b]$, and\nby $C_{[a,b]}$ the set of all continuous functions on $[a,b]$. Note that\n$C_{[a,b]} \\subset B_{[a,b]}$.\n\n\\begin{defn}[Partition]\n\tA partition of the interval $[a,b]$ is a (strictly increasing)\n\tsequence of numbers, $P := \\{x_0, \\ldots, x_n\\}$, where $x_0 = a$\n\tand $x_n = b$.\n\\end{defn}\n\n\\begin{defn}[Partition width]\n\tThe width of a partition $P$ is given\n\t\\[ ||P|| = \\max\\{x_{i+1} - x_i\\}.\\]\n\\end{defn}\n\n\\begin{defn}[Refinement]\n\tIf $P$ and $P'$ are partitions of $[a,b]$, then if $P \\subset\n\tP'$, we say that $P'$ is a refinement of $P$.\n\\end{defn}\n\n\\begin{rem}\n\tIf $P'$ is a refinement of a partition $P$, then $||P'|| \\leq ||P||$.\n\\end{rem}\n\n\\begin{defn}[Riemann Sums]\n\tLet $f:[a,b] \\to \\RR$ be a bounded function and $P$ a partition of $[a,b]$.\n\n\tThe lower Riemann sum of $f$ with respect to $P$ is\n\t\\[ L(f,P) = \\sum_{i=0}^{n-1} m_i (x_{i+1} - x_i) \\]\n\twhere $m_i = \\inf_{x_i \\leq x \\leq x_{i+1}} \\{f(x)\\}$.\n\n\tThe upper Riemann sum of $f$ with respect to $P$ is\n\t\\[ U(f,P) = \\sum_{i=0}^{n-1} M_i (x_{i+1} - x_i) \\]\n\twhere $M_i = \\sup_{x_i \\leq x \\leq x_{i+1}} \\{f(x)\\}$.\n\n\t$m_i$ and $M_i$ are well defined as a result of the boundedness of $f$.\n\\end{defn}\n\n\\begin{rem}\n\t\\[ L(f,P) \\leq U(f,P) \\]\n\\end{rem}\n\n\\begin{lemma}\n\tAssume $P'$ is a refinement of a partition $P$, then for a bounded function $f$\n\t\\[ L(f,P) \\leq L(f,P'), \\quad U(f,P') \\leq U(f,P). \\]\n\\end{lemma}\n\n\\begin{proof}\n\tConsider $P = \\{x_0, \\ldots, x_n\\}$ and $P' = \\{x_0, x', x_1, \\ldots, x_n\\}$.\n\n\t\\[ L(f,P) = m_0(x_1 - x_0) + \\cdots + m_{n-1}(x_n - x_{n-1}) \\]\n\t\\[ L(f,P') = m_0'(x' - x_0) + m_0''(x_1 - x') + \\cdots + m_{n-1}(x_n - x_{n-1}) \\]\n\n\tIt is clear that $m_0' \\geq m_0$ and $m_0'' \\geq m_0$, since $m_0 \\in f([x_0, x'])$\n\tor $m_0 \\in f([x', x_1])$ or bothe (if $m_0 = f(x')$).\n\n\t\\begin{align*}\n\t\tL(f,P) - L(f,P') &= m_0(x_1 - x_0) - m_0(x' - x_0) - m_0''(x_1 - x') \\\\\n\t\t\t\t &\\leq m_0(x_1 - x_0 - x' + x_0 - x_1 + x') \\\\\n\t\t   \t\t &= 0\n\t\\end{align*}\n\t\\[ \\implies L(f,P) \\leq L(f,P') \\]\n\n\tSimilarly, $M_0'' \\leq M_0$ and $M_0' \\leq M_0$.\n\t\\begin{align*}\n\t\tU(f,P) - U(f,P') &= M_0(x_1 - x_0) - M_0'(x' - x_0) + M_0''(x_1 - x') \\\\\n\t\t\t\t &\\geq 0\n\t\\end{align*}\n\t\\[ \\implies U(f,P) \\geq U(f,P') \\]\n\\end{proof}\n\n\\begin{lemma}\n\tIf $P$ and $Q$ are partitions of $[a,b]$, then\n\t\\[ L(f, P) \\leq U(f, Q) \\]\n\\end{lemma}\n\n\\begin{proof}\n\tLet $R = P \\cup Q$ It is clear that $R$ is a partition of\n\t$[a,b]$ and a refinement of both $P$ and $Q$.\n\n\tWe know that $L(f,R) \\leq U(f,R)$ and from the previous lemma:\n\t\\[ L(f,P) \\leq L(f,R) \\quad U(f,R) \\leq U(f,Q) \\]\n\n\t\\[ \\implies L(f,P) \\leq U(f,Q) \\]\n\\end{proof}\n\n\\begin{defn}[Lower Integral]\n\tThe lower integral of the function $f:[a,b] \\to \\RR$ is\n\t\\[ (L) \\int_a^b f(x) dx = \\sup \\{L(f,P)\\} \\]\n\twhere $P$ is any partition of $[a,b]$.\n\\end{defn}\n\n\\begin{defn}[Upper Integral]\n\tThe upper integral of the function $f:[a,b] \\to \\RR$ is\n\t\\[ (U) \\int_a^b f(x) dx = \\inf \\{U(f,P)\\} \\]\n\twhere $P$ is any partition of $[a,b]$.\n\\end{defn}\n\n\\begin{defn}[Upper Integral]\n\tA function $f:[a,b] \\to \\RR$ is called Riemann Integrable if\n\t\\[ (L) \\int_a^b f(x) dx = (U) \\int_a^b f(x) dx \\]\n\n\tThis common value is called the Riemann Integral of $f$ and is simply denoted\n\t\\[ \\int_a^b f(x) dx \\]\n\\end{defn}\n\n\\begin{rem}\n\t\\begin{itemize}\n\t\t\\item The set of all Riemann Integrable funciton is denoted $R_{[a,b]}$\n\t\t\\item $R_{[a,b]} \\subset B_{[a,b]}$\n\t\\end{itemize}\n\\end{rem}\n\n\\begin{defn}[Uniform Continuity]\n\t$f$ is uniformly continuous if\n\t\\[ \\forall \\eps > 0 \\exists \\delta > 0 : |x-y| < \\delta \\implies |f(x) - f(y)| < \\eps \\]\n\\end{defn}\n\n\\begin{rem}\n\tThe difference between regular and uniform continuity is that\n\tuniform continuity depends only on $\\eps$, whereas regular\n\tcontinuity depends on a point in the domain of $f$.\n\\end{rem}\n\n\\begin{thm}\n\tIf $f:[a,b] \\to \\RR$ is continuous, then $f$ is uniformly continuous.\n\\end{thm}\n\n\\begin{proof}\n\tAssume $f$ is not uniformly continuous, then:\n\t\\[ \\exists \\eps > 0 \\forall \\delta > 0 : \\exists x, y : |x-y| < delta \\implies |f(x)-f(y)| \\geq \\eps \\]\n\n\tFix $\\eps$ and take $\\delta = \\frac{1}{n}$\n\t\\[ \\exists x_n, y_n \\in [a,b] : |x_n - y_n| < \\frac{1}{n} \\implies |f(x_n)-f(y_n)| \\geq \\eps \\]\n\n\tWe have two bounded sequences which, by the Bolzano-Wieirstrass theorem, have convergent subsequences.\n\t\\[ x_n, \\ldots, x_{m_l} \\to c \\in [a,b] \\]\n\t\\[ y_n, \\ldots, y_{m_l} \\to d \\in [a,b] \\]\n\n\t\\[ |x_{m_l} - y_{m_l}| < \\frac{1}{n} \\implies c = d \\]\n\t\\[ f(x_{m_l})- f(y_{m_l}) \\geq \\eps \\]\n\n\t\\[ \\implies \\lim_{l \\to \\infty} |f(x_{m_l}) - f(y_{m_l})| \\geq \\eps \\]\n\t\\[ \\implies | \\lim f(x_{m_l}) - \\lim f(y_{m_l}) | \\geq \\eps \\]\n\t\\[ \\implies | f(\\lim x_{m_l}) - f(\\lim f_{m_l}) | \\geq \\eps \\]\n\t\\[ \\implies |f(c) - f(d)| \\geq \\eps \\]\n\n\tThis is a contradiction because $c=d$ and $\\eps > 0$.\n\\end{proof}\n\n\\begin{thm}\n\tA function $f:[a,b] \\to \\RR$ is integrable iff\n\t\\[ \\forall \\eps > 0 \\exists \\delta : ||P|| < \\delta \\implies U(f,P) - L(f,P) < \\eps \\]\n\\end{thm}\n\n\\begin{proof}\n\t$f$ integrable\n\t\\begin{align*}\n\t\t&\\implies \\inf \\{ U(f,P) \\} = \\sup \\{ L(f,P) \\} \\\\\n\t\t&\\implies \\lim_{||P|| \\to 0} U(f,P) = \\lim_{||P|| \\to 0} L(f,P) \\\\\n\t\t&\\implies (\\forall \\eps > 0 \\exists \\delta : ||P|| < \\delta \\implies U(f,P) - L(f,P) < \\eps)\n\t\\end{align*}\n\tThis follows from the result that $L(f,P) \\leq L(f,P')$ and $U(f,P) \\geq U(f,P')$.\n\\end{proof}\n\n\\begin{thm}\n\tAny continuous function $f:[a,b] \\to \\RR$ is integrable.\n\\end{thm}\n\n\\begin{proof}\n\tContinuity implies uniform continuity, hence\n\t\\[\n\t\t\\forall \\eps > 0 \\exists \\delta : |x-y| < \\delta\n\t\t\\implies |f(x)-f(y)| < \\frac{\\eps}{2(b-a)}\n\t\\]\n\n\tLet $P$ be a partition of $[a,b]$ such that $||P|| < \\delta$.\n\n\t\\begin{align*}\n\t\tU(f,P) - L(f,P)\n\t\t&= \\sum_{i=0}^{n-1} M_i (x_{i+1} - x_i) - \\sum_{i=0}^{n-1} m_i (x_{i+1} - x_i) \\\\\n\t\t&= \\sum_{i=0}^{n-1} (M_i - m_i)(x_{i+1} - x_i) \\\\\n\t\t&\\leq \\sum_{i=0}^{n-1} \\frac{\\eps}{2(b-a)} (x_{i+1} - x_i)\n\t\\end{align*}\n\n\tsince\n\t\\[\n\t\t||P|| < \\delta \\implies x_{i+1} - x_i < \\delta\n\t\t\\implies M_i - m_i < \\frac{\\eps}{2(b-a)}\n\t\\]\n\n\t\\begin{align*}\n\t\t\\sum_{i=0}^{n-1} x_{i+1} - x_i\n\t\t&= (x_1 - x_0 + x_2 - x_1 + \\cdots + x_n - x_{n-1}) \\\\\n\t\t&= x_n - x_0 \\\\\n\t\t&= b - a\n\t\\end{align*}\n\n\t\\[\n\t\t\\implies U(f,P) - L(f,P) \\leq \\frac{\\eps(b-a)}{2(b-a)}\n\t\t= \\frac{\\eps}{2} < \\eps\n\t\\]\n\n\tIt follows from the previous theorem that $f$ must be integrable.\n\n\\end{proof}\n\n\\begin{defn}[Primtive]\n\tA primitive of a function $f:[a,b] \\to \\RR$ is a function $F:[a,b] \\to \\RR$, where\n\t\\[ F'(x) = f(x). \\]\n\\end{defn}\n\n\\begin{rem}\n\tIf $F(x)$ is a primative of $f(x)$, then $F(x) + c$ is also a primitive of $f(x)$.\n\tFurthermore, if $F_1$ and $F_2$ are primitives of $f$, then $F_1 = F_2 + c$.\n\\end{rem}\n\n\\begin{thm}[Fundamental Theorem of Calculus]\n\tIf $F$ is a primitve of $f:[a,b] \\to \\RR$, then\n\t\\[ \\int_a^b f(x) dx = F(b) - F(a) \\]\n\\end{thm}\n\n\\begin{proof}\n\tLet $P$ be a partition of $[a,b]$.\n\n\tUsing MVT, we have:\n\t\\[ F(x_{i+1}) - F(x_i) = F'(y_i)(x_{i+1} - x_i) \\]\n\tfor some $y_i \\in [x_i, x_{i+1}]$.\n\n\t\\[ m_i \\leq f(y_i) = F'(y_i) \\leq M_i \\]\n\t\\begin{align*}\n\t\t&\\implies L(f,P) \\leq \\sum_{i=0}^{n-1} f(y_i)(x_{i+1}-x_i) \\leq U(f,P) \\\\\n\t\t&\\implies L(f,P) \\leq \\sum_{i=0}^{n-1} F(x_{i+1}) - F(x_i) \\leq U(f,P) \\\\\n\t\t&\\implies L(f,P) \\leq F(b) - F(a) \\leq U(f,P) \\\\\n\t\t&\\implies \\int_a^b f(x) dx = F(b) - F(a)\n\t\\end{align*}\n\\end{proof}\n\n\\subsection{Properties of Integrals}\n\nLet $f,g : [a,b] \\to \\RR$ be integrable, then\n\\begin{enumerate}\n\t\\item\n\t\t$\\alpha f + \\beta g$ is integrable and\n\t\t\\[ \\int_a^b \\alpha f + \\beta g = \\alpha \\int_a^b f + \\beta \\int_a^b g \\]\n\t\\item\n\t\t\\[ \\int_a^b f = \\int_a^c f + \\int_c^b f, \\quad \\forall c \\in [a,b] \\]\n\t\\item\n\t\tif $|f(x)| \\leq M$,\n\t\t\\[ \\left| \\int_a^b f \\right| \\leq M |b-a| \\]\n\\end{enumerate}\n\n\\begin{proof}\n\t\\begin{enumerate}\n\t\t\\item\n\t\t\tLet $h = \\alpha f + \\beta g$, and let $F,G$ be primitives of $f,g$.\n\t\t\tLet $H = \\alpha F + \\beta G + c$, then $H' = \\alpha f + \\beta g$.\n\n\t\t\t\\begin{align*}\n\t\t\t\t\\int_a^b h &= H(b) - H(a) \\\\\n\t\t\t\t\t   &= \\alpha F(b) - \\alpha F(a)\n\t\t\t\t\t\t+ \\beta G(b) - \\beta G(a) \\\\\n\t\t\t\t\t   &= \\alpha \\int_a^b f + \\beta \\int_a^b g\n\t\t\t\\end{align*}\n\t\t\\item\n\t\t\t\\begin{align*}\n\t\t\t\t\\int_a^c f + \\int_c^b f &= F(c) - F(a) + F(b) - F(c) \\\\\n\t\t\t\t\t\t\t&= F(b) - F(a) \\\\\n\t\t\t\t   \t\t\t&= \\int_a^b f\n\t\t\t\\end{align*}\n\t\t\\item\n\t\t\tLet $P = \\{a,b\\}$ be a partition of $[a,b]$, then\n\t\t\t\\begin{align*}\n\t\t\t\t|f(x)| \\leq M &\\implies \\sup\\{f(x)\\} = M_i = M \\\\\n\t\t\t\t\t      &\\implies U(f,P) = M(b-a)\n\t\t\t\\end{align*}\n\t\t\tLet  $P' = \\{a,c,b\\}$ be a refinement of $P$, then\n\t\t\t\\[ U(f,P') \\leq U(f,P) \\leq M(b-a) \\]\n\t\t\t\\[ \\int_a^b f \\leq \\inf\\{U(f,P)\\} \\implies \\int_a^b f \\leq M(b-a) \\]\n\t\\end{enumerate}\n\\end{proof}\n\n\\begin{thm}\n\tLet $f:[a,b] \\to \\RR$ be an integrable function. Consider the function\n\t\\[ F(x) = \\int_a^x f(t) dt \\]\n\tthen $F:[a,b] \\to \\RR$ is continuous. Futhermore, if $f$ is\n\tcontinuous at $c \\in (a,b)$, then $F$ is differentiable at $c$\n\tand $F'(c) = f(c)$.\n\\end{thm}\n\n\\begin{proof}\n\tTake $c \\in (a,b)$. We need to show that\n\t\\[ \\lim_{x \\to c} F(x) = F(c) \\]\n\tor\n\t\\[ \\lim_{h \\to o} F(c+h) = F(c). \\]\n\n\t\\begin{align*}\n\t\t|F(c+h) - F(c)| &= \\left| \\int_a^{c+h} f(t) - \\int_a^c f(t) \\right| \\\\\n\t\t\t\t&= \\left| \\int_a^c f(t) + \\int_c^{c+h} f(t) - \\int_a^c f(t) \\right| \\\\\n\t\t\t \t&= \\left| \\int_c^{c+h} f(t) \\right|\n\t\\end{align*}\n\n\t$f$ is bounded, so\n\t\\[ \\exists M : |f(x)| \\leq M \\]\n\t\\[ \\implies | F(c+h) - F(c) | \\leq M(c+h-c) = Mh \\]\n\n\t\\[ \\lim_{h \\to 0} Mh = 0 \\implies \\lim_{h \\to 0} F(c+h) = F(c) \\]\n\thence $F$ is continuous at $c \\in [a,b]$.\n\n\tWe now aim to prove that $F'(c) = f(c)$, or\n\t\\[ \\lim_{h \\to 0} \\frac{F(c+h) - F(c)}{h} = f(c) \\]\n\n\t\\begin{align*}\n\t\t\\left|\\frac{1}{h} \\int_a^{c+h} f(t) - \\frac{1}{h} \\int_a^c f(t) - f(c) \\right| \\\\\n\t\t&= \\left| \\frac{1}{h} \\int_c^{c+h} f(t) - f(c) \\right| \\\\\n\t\t&= \\left| \\frac{1}{h} \\int_c^{c+h} f(t) - \\frac{h}{h} f(c) \\right| \\\\\n\t\t&= \\left| \\frac{1}{h} \\int_c^{c+h} f(t) - \\frac{1}{h} \\int_c^{c+h} f(c) \\right| \\\\\n\t\t&= \\left| \\frac{1}{h} \\int_c^{c+h} (f(t) - f(c)) \\right|\n\t\\end{align*}\n\n\tBy assumption, $f$ is continuous, hence\n\t\\begin{align*}\n\t\t&\\implies \\forall \\eps > 0 \\exists \\delta > 0 : |t-c| \\implies |f(t)-f(c)| < \\eps \\\\\n\t\t&\\implies \\frac{1}{h} \\int_c^{c+h} f(t) - f(c) \\leq \\frac{\\eps(c+h-c)}{h} = \\eps \\\\\n\t\t&\\implies \\lim_{h \\to 0} \\frac{F(c+h) - F(c)}{h} = f(c) \\\\\n\t\t&\\implies F'(c) = f(c)\n\t\\end{align*}\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "6a21395b7510119cc5224a61ac35caf35577f526", "size": 43773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/real_analysis.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/real_analysis.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/real_analysis.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": 28.5166123779, "max_line_length": 133, "alphanum_fraction": 0.5477805953, "num_tokens": 19662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6689649827616434}}
{"text": "\\lab{Algorithms}{Modified Gram-Schmidt (QR)}{QR decomposition}\n\\label{lab:QRdecomp}\n\\objective{Use Gram-Schmidt algorithm and orthonormal transformations to perform QR decomposition.}\n\nThe QR decomposition is used to represent any invertible square matrix as the matrix product of an orthogonal ($A^T A = I$) matrix, $Q$, and an upper triangular matrix, $R$.\nThis decomposition is useful in computing least squares and is part of a common method for finding eigenvalues (the QR algorithm).\nWe can succinctly state the QR decomposition in the following theorem.\n\\begin{theorem}\nLet $A$ be an $m\\times n$ matrix of rank $n$.  Then $A$ can be\nfactored into a product $Q R$, where $Q$ is an $m\\times n$ matrix\nwith orthonormal columns and $R$ is a nonsingular $n \\times n$ upper\ntriangular matrix.\n\\end{theorem}\n\n\\section*{Computing the QR Decomposition}\nThere are many methods for computing the QR factorization.\nThis lab will focus on the method that uses the Gram-Schmidt algorithm for orthogonalizing \na full-rank matrix.\nWe use this algorithm to create $Q$.\nLet $\\{\\x_i\\}_{i=1}^n$ be a basis for the inner product space $V$.\nLet \\[ \\q_1 = \\frac{\\x_1}{\\norm{\\x_1}}\\] and define $\\q_2,\\q_3,\\ldots,\\q_n$ recursively by\n$$ \n\\q_{k} = \\frac{\\x_k - \\p_{k-1}}{\\|\\x_k - \\p_{k-1}\\|}, \\,\\,\\,\\, k=2,\\ldots,n,\n$$\nwhere\n$$\n\\p_{k-1} = \\sum_{i=1}^{k-1} \\langle \\q_i, \\x_k\\rangle \\q_i,\n$$\nand $\\p_0 = 0$. \nThen the set $\\{\\q_i\\}_{i=1}^n$ is an orthonormal basis for $V$.\n\nFor the above algorithm, let $r_{j k} = \\langle \\q_j, \\x_k\\rangle$ when $j < k$ and\n$r_{kk} = \\|\\x_k-\\p_{k-1}\\|$.\nThis can be written as\n\\begin{align*}\n\\x_1 &= r_{1 1} \\q_1\\\\\n\\x_2 &= r_{1 2} \\q_1 + r_{2 2} \\q_2\\\\\n\\vdots \\:\\: &= \\quad \\vdots\\\\\n\\x_n &= r_{1 n} \\q_1 + r_{2 n} \\q_2 + \\ldots + r_{n n} \\q_{n},\n\\end{align*}\nor in matrix form as\n\\[\n[\\x_1 \\hspace{5mm} \\x_2 \\hspace{5mm} \\cdots \\hspace{5mm} \\x_n]\n=\n[\\q_1 \\hspace{5mm} \\q_2 \\hspace{5mm} \\cdots \\hspace{5mm} \\q_n]\n\\begin{bmatrix}\nr_{1 1} & r_{1 2} & \\cdots & r_{1 n}\\\\\n0 & r_{2 2} & \\cdots & r_{2 n}\\\\\n\\vdots & \\vdots & \\ddots & \\vdots\\\\\n0 & 0 & \\cdots & r_{n n}\n\\end{bmatrix}.\n\\]\nHence if our original basis vectors $\\{\\x_i\\}_{i=1}^n$ correspond to column\nvectors of a matrix $A$, we can likewise write the resulting\northonormal basis $\\{\\q_i\\}_{i=1}^n$ as a matrix $Q$ of column\nvectors.  Then we have that $A = Q R$, where $R$ is the above\nnonsingular upper-triangular $n\\times n$ matrix.\nNumerically, the Gram Schmidt process can have problems due to\nfinite precision arithmetic. \n\nIn some cases, rounding errors may cause the resulting basis to fail to be orthonormal. To combat this, we consider the Modified Gram-Schmidt which can be used to carry out a slightly revised algorithm.  To do this, we first compute $\\q_1$ as before.  We then project it out of each of the remaining original vectors\n$\\x_2,\\x_3,\\ldots,\\x_n$ via\n\\[\n\\x_k := \\x_k - \\langle \\q_1,\\x_{k} \\rangle \\q_1,\\quad k=2,\\ldots,n.\n\\]\nThen we compute $\\q_2$ to be the unit vector of $\\x_2$, that is,\n\\[\n\\q_2 = \\frac{\\x_2}{\\|\\x_2\\|}.\n\\]\nWe repeat by projecting out $\\q_2$ from the remaining vectors\n$\\x_3,\\x_4,\\ldots,\\x_n$, and then continuing this process until\nall $\\q_i$ are obtained.\n\n\\begin{algorithm}\n\\caption{Modified Gram-Schmidt}\n\\label{Alg:MGS}\n\\begin{algorithmic}[1]\n\\Procedure{Modified Gram-Schmidt}{$A$}\n\\State $m, n \\gets \\text{shape} \\left( A \\right)$\n\\State $Q \\gets \\text{copy} \\left( A \\right)$\n\\State $Q \\gets \\text{zeros}((n,n))$\n\\For{$0 \\leq i < n$}\n    \\State $R_{i,i} \\gets \\norm{Q_{:,i}}$\n    \\State $Q_{:,i} \\gets Q_{:,i}/R_{i,i}$\n    \\For{$i+1 \\leq j < n$}\n        \\State $R_{i,j} \\gets Q_{:,j}Q_{:,i}$\n        \\State $Q_{:,j} \\gets Q_{:,j}-R_{i,j}Q_{:,i}$\n\t\\EndFor\n\\EndFor\n\\State \\pseudoli{return} $Q, R$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{problem}\n\\label{prob:QR}\nWrite your own implementation of the QR decomposition. Write a function \\li{QR} that accepts as input a square matrix $A$ of full rank, and computes the QR decomposition, returning the matrices $Q$ and $R$ (which should be the same shape as $A$). Be sure to use the numerically stable Modified Gram-Schmidt algorithm. Also assume there are no zeros on the main diagonal.\n\nYou can test that you have the right decomposition by verifying that $QR=A$ and $Q^T Q = I$. While this is true most of the time, it may not always be true due to roundoff.\n\\end{problem}\n\n\\begin{problem}\nThe QR decomposition gives a really nice way to calculate the magnitude of the determinant of a square matrix of full rank. Write a function \\li{QRDet} that accepts a square matrix of full rank as input, and returns the magnitude of the determinant of that matrix. Use your QR decomposition to perform this\ncalculation.\n\nYou may check your work by comparing your results to those produced by \\li{scipy.linalg.det}. \n\\end{problem}\n\n\\section*{QR Decomposition in SciPy}\nThe linear algebra library in SciPy wraps the very efficient algorithms of LAPACK to calculate the QR decomposition.\nIn addition to being much faster, SciPy's QR decomposition is also much more general and can decompose non-square matrices.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n>>> A = np.random.rand(4,3)\n>>> Q, R = la.qr(A)\n>>> Q.dot(R) == A                      # there are False entries\n>>> np.allclose(Q.dot(R), A)           # A = QR\n>>> np.allclose(Q.T.dot(Q), np.eye(4)) # Q is indeed, orthogonal\n\\end{lstlisting}\n\nIn order to interpret the results correctly, we need to understand that the computer has limited precision (especially with floating point numbers).\nThis is why \\li{Q.dot(R)} is not exactly equal to \\li{A}. However, we can see that the matrix product of $QR$ is very close to $A$ using the \\li{allclose} method. This verifies that the product of $Q$ and $R$ is indeed $A$. Also note that $Q^T Q = I$, which implies that the column vectors of $Q$ are orthonormal.\n\n\\section*{Solving Least Squares Problems}\nThe QR decomposition can only be used to solve the linear least squares problem if $A$ is full rank. If $A$ is less than full rank, then we have to calculate the least squares solution more creatively.\n\n%MATLAB's least squares backslash operator is based off the QR decomposition.\n%SciPy uses the SVD to solve least squares problems because, although it is slower, the algorithm is more numerically stable.\n\n\nFor large or ill-conditioned problems, the QR decomposition provides a nice method for computing least squares solutions of over-determined matrices.\nConsider the least squares problem $Ax=b$. We can approximate the solution with $\\widehat x = (A^T A)^{-1}A^T b$.\nAlternatively, we write the linear system as\n\\[ Q R x = b. \\]\nWe then multiply both sides by $Q^T$, yielding\n\\[ R x = Q^T b. \\]\nThen $\\widehat x = R^{-1} Q^T b$.\n\nHowever, we can avoid calculating the inverse of $R$ (inverting a matrix is \\emph{very expensive} computationally).\nSince $R$ is a triangular matrix, we have a triangular system that we can solve much more efficiently.\nSciPy includes a solver for triangular systems, \\li{linalg.solve_triangular()}.\nWe approximate $x$ by solving the triangular system $Rx = Q^T b$.\n\n\\begin{problem}\nWrite a function \\li{LeastSquares} that will accept a linear system (a matrix $A$ and a vector $b$) and solve the least squares problem.\nYour function should rely on the SciPy's QR decomposition and triangular system solver.  Assume that $A$ is full rank.\nYou may test your function against the output of SciPy's least squares function, \\li{linalg.lstsq()}.\n\\end{problem}\n\n\\section*{Orthonormal transformations}\nRecall that a matrix $Q$ is \\emph{unitary} if $Q^\\mathsf{H} Q = I$ or, for real matrices, $Q^T Q = I$.\nFor the real case we say that such a matrix is \\emph{orthonormal}.\n\nUnitary transformations have the very desirable property of being numerically stable. The number $\\kappa(A) = \\norm{A} \\norm{A^{-1}}$ is called the \\emph{condition number} of $A$. We'll discuss condition number more in another lab; for now, all you need to know is that if $\\kappa(A)$ is small, then calculations involving $A$ are less susceptible to numerical errors.\n\n\nFor the induced 2-norm, it holds that $\\norm{Q}=1$ when $Q$ is unitary.\nThe Cauchy-Schwarz inequality \n\n\\centerline{$\\norm{AB} \\leq \\norm{A} \\norm{B}$}\nalso holds for this norm, and so it follows that \n\n\\centerline{$\\kappa(A) = \\norm{A} \\norm{A^{-1}} \\geq \\norm{A A^{-1}} = \\norm{I} = 1$.}\n\n\nNote that if $Q$ is unitary, $Q^{-1} = Q^\\mathsf{H}$ and $Q^\\mathsf{H}$ is also unitary, so $\\kappa(Q) = \\norm{Q} \\norm{Q^\\mathsf{H}} = 1$. This means that orthonormal matrices have the smallest possible condition number.\n\nAny orthogonal matrix $Q$ can be described as a reflection, a rotation, or some combination of the two.\nIf $det(Q) = 1$, then $Q$ is a rotation.\nIf $det(Q) = -1$, then $Q$  is a reflection or a composition of a reflection and a rotation. Let's explore these two types of unitary transformations and some of their applications. We will focus on the real case to simplify matters.\n\n\\section*{Householder reflections}\nA Householder reflection is a linear transformation $P: \\mathbb{R}^n \\rightarrow \\mathbb{R}^n$ that reflects a vector $x$ about a hyperplane.\nSee figure \\ref{fig:Householder_reflector}.\nRecall that a hyperplane can be defined by a unit vector $v$ which is orthogonal to the hyperplane. \nAs shown in figure \\ref{fig:Householder_reflector}, $x - \\langle v,x \\rangle v$ is the projection of $x$ onto the hyperplane orthogonal to $v$.\nHowever, to reflect \\emph{across} the hyperplane, we must move twice as far; that is, $Px = x - 2\\langle v,x \\rangle v$.\nThis can be written $Px = x - 2v(v^\\mathsf{H} x)$, so $P$ has matrix representation $P = I - 2v v^\\mathsf{H}$.\nNote that $P^\\mathsf{H} P = I$; thus $P$ is orthonormal.\n\n\\begin{figure}\n\\includegraphics[width= \\textwidth]{fig1}\n\\caption{Householder reflector}\n\\label{fig:Householder_reflector}\n\\end{figure}\n\n\\subsection*{Householder triangularization}\nConsider the problem of computing the $QR$ decomposition of a matrix $A$.\nYou've already learned the Gram-Schmidt and the Modified Gram-Schmidt algorithms for this problem.\nThe $QR$ decomposition can also be computed by applying a series of Householder reflections.\nGram-Schmidt and Modified Gram-Schmidt make $A$ \\emph{orthonormal} using a series of transformations stored in an \\emph{upper triangular} matrix.\nOn the other hand, we can use Householder reflections to make $A$ \\emph{triangular} by a series of \\emph{orthonormal} transformations.\n\nLet's demonstrate this method on a $4 \\times 3$ matrix $A$.\nFirst we find an orthonormal transformation $Q_1$ that maps the first column of A into the span of $e_1$\n(where $e_1$ is the vector where the first element is one and the remainder of the elements are zeros).\n\n\\def\\mc#1{\\multicolumn{1}{c|}{#1}}\n\\begin{equation*}\n\\begin{pmatrix}\n* & * & * \\\\\n* & * & * \\\\\n* & * & * \\\\\n* & * & *\n\\end{pmatrix}\n\\underrightarrow{Q_1}\n\\begin{pmatrix}\n\n* & * & * & \\\\ \\cline{2-3}\n\\mc{0} & * & \\mc{*}& \\\\\n\\mc{0} & * & \\mc{*} & \\\\\n\\mc{0}& * & \\mc{*} & \\\\ \\cline{2-3}\n\\end{pmatrix}\n\\end{equation*}\nLet $A_2$ be the boxed submatrix of $A$.\nNow find an orthonormal transformation $Q_2$ that maps the first column of $A_2$ into the span of $e_2$.\n\n\\begin{equation*}\n\\begin{pmatrix}\n* & * \\\\\n* & * \\\\\n* & *\n\\end{pmatrix}\n\\underrightarrow{Q_2}\n\\begin{pmatrix}\n* & * \\\\\n0 & * \\\\\n0 & *\n\\end{pmatrix}\n\\end{equation*}\nSimilarly, $ \\begin{pmatrix} * \\\\ * \\end{pmatrix} \\underrightarrow{Q_3} \\begin{pmatrix} * \\\\ 0 \\end{pmatrix} $.\n(Technically $Q_2$ and $Q_3$ act on the whole matrix and not just on the submatrices, so that $Q_i: \\mathbb{R}^n \\rightarrow \\mathbb{R}^n$ for all $i$.\n$Q_2$ leaves the first row and the first column alone, and $Q_3$ leaves the first two rows and the first two columns alone.)\nThen $Q_3 Q_2 Q_1 A =$\n\n\\begin{equation*}\nQ_3 Q_2 Q_1\n\\begin{pmatrix}\n* & * & * \\\\\n* & * & * \\\\\n* & * & * \\\\\n* & * & *\n\\end{pmatrix}\n= Q_3 Q_2\n\\begin{pmatrix}\n* & * & * \\\\\n0 & * & * \\\\\n0 & * & * \\\\\n0 & * & *\n\\end{pmatrix}\n= Q_3\n\\begin{pmatrix}\n* & * & * \\\\\n0 & * & * \\\\\n0 & 0 & * \\\\\n0 & 0 & *\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n* & * & * \\\\\n0 & * & * \\\\\n0 & 0 & * \\\\\n0 & 0 & 0\n\\end{pmatrix}\n\\end{equation*}\n\nWe've accomplished our goal, which was to triangularize $A$ using orthonormal transformations.\nBut how do we find the $Q_i$ that do what we want? The answer lies in using Householder reflections.\n\nTo find $Q_1$, we first identify an appropriate hyperplane to reflect $x$ into the span of $e_1$.\nIt turns out there are two hyperplanes that will work, as shown in figure \\ref{fig:two reflectors}.\n(In the complex case, there are infinitely many such hyperplanes.)\nBetween the two, the one that reflects $x$ further will be more numerically stable.\nThis is the hyperplane perpendicular to $v = sign(x_1)\\norm{x}_2 e_1 + x$.\n\nTo see how this works, let $x$ be the first column of the submatrix that we want to project onto the span of $e_1$.\nIn order for this to be a unitary operation, this will need to preserve the norm of $x$.\nThis means that $\\left( I - 2 v v^\\mathsf{H} \\right) x = \\pm \\norm{x} e_1$, or, in other words,\n\n\\[ 2 v v^\\mathsf{H} x =\n\\begin{pmatrix}\nx_1 \\pm \\norm{x} \\\\\nx_2 \\\\\nx_3 \\\\\n\\vdots \\\\\nx_n\n\\end{pmatrix}\\]\n\nLet $u$ be the vector on the right hand side of this expression.\nIt can be shown that the vector  $\\frac{u}{\\norm{u}}$ is the proper choice for $v$.\n%We will show that the vector $\\frac{u}{\\norm{u}}$ is the proper choice for $v$.\n%Notice that:\n%\n%\\[\\norm{u}^2 = \\norm{x}^2 \\pm 2 \\norm{x} x_1 + x_1^2 + x_2 + \\dots + x_n^2 = 2 \\norm{x}^2 \\pm 2 \\norm{x} x_1 \\]\n%\n%and that\n%\n%\\[\\norm{x}^2 \\pm \\norm{x} x_1 = u^\\mathsf{H} x \\]\n%\n%So we have\n%\n%\\begin{align*}\n%2 v v^\\mathsf{H} x &= 2 u \\frac{\\norm{x}^2 \\pm x_1 \\norm{x}}{\\norm{u}^2} \\\\\n%\t\t&= 2 u \\frac{u^\\mathsf{H} x}{\\norm{u}^2} \\\\\n%\t\t&= 2 \\frac{u}{\\norm{u}} \\left( \\frac{u}{\\norm{u}} \\right)^\\mathsf{H} x\n%\\end{align*}\n%\n%So $\\frac{u}{\\norm{u}}$ is a proper choice of $v$ that will project $x$ into the span of $e_1$.\n\nThis whole process is summarized in Algorithm \\ref{Alg:Householder}.\n\n\\begin{figure}\n\\includegraphics[width= \\textwidth]{fig2}\n\\caption{two reflectors}\n\\label{fig:two reflectors}\n\\end{figure}\n\n\\begin{algorithm}\n\\caption{Householder triangularization}\n\\label{Alg:Householder}\n\\begin{algorithmic}[1]\n\\Procedure{Householder}{$A$}\n\\State $m, n \\gets \\text{shape} \\left( A \\right)$\n\\State $R \\gets \\text{copy} \\left( A \\right)$\n\\State $Q \\gets I_m$\n\\For{$0 \\leq k < n-1$}\n    \\State $v_k \\gets \\text{copy} \\left( R_{k:,k} \\right)$\n    \\State $v_{k_0} \\gets v_{k_0} + \\text{sign} \\left( v_{k_0} \\right) \\norm{v_k}$\n    \\State $v_k \\gets v_k / \\norm{v_k}$\n    \\State $R_{k:,k:} \\gets R_{k:,k:} - 2 v_k \\left( v_k^\\mathsf{H} R_{k:,k:} \\right)$\n    \\State $Q_{k:} \\gets Q_{k:} - 2 v_k \\left( v_k^\\mathsf{H} Q_{k:} \\right)$\n\\EndFor\n\\State \\pseudoli{return} $Q^\\mathsf{H}, R$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\nTo see how we are operating on the matrices $A$ and $Q$, consider the way each orthonormal transformation defined by the $v_k$ operates blockwise on each matrix.\nThe matrix form of each operation on $A$ and $Q$ can be represented in block form like this:\n\n\\[\n\\begin{pmatrix}\nI & 0 \\\\\n0 & I - 2 v_k v_k^\\mathsf{H}\n\\end{pmatrix}\n\\]\n\nNotice that a block matrix of this form operates only on entries that lie in the rows from $k$ onward.\nConsider what happens when we left-multiply a $m \\times n$ matrix by a block matrix of this form.\nWe obtain the following:\n\n\\[\n\\begin{pmatrix}\nI & 0 \\\\\n0 & I - 2 v_k v_k^\\mathsf{H}\n\\end{pmatrix}\n\\cdot\n\\begin{pmatrix}\nA[:k,:k] & A[:k,k:] \\\\\nA[k:,:k] & A[k:,k:]\n\\end{pmatrix}\n\\]\n\\[\n=\n\\begin{pmatrix}\nA[:k,:k] & A[:k,k:] \\\\\nA[k:,:k] - 2 v_k v_k^\\mathsf{H} A[k:,:k] & A[k:,k:] - 2 v_k v_k^\\mathsf{H} A[k:,k:]\n\\end{pmatrix}\n\\]\n\nAnd, when we consider right multiplication by the same block matrix, we see that it fixes the first $k-1$ columns as below.\n\n\\[\n\\begin{pmatrix}\nA[:k,:k] & A[:k,k:] \\\\\nA[k:,:k] & A[k:,k:]\n\\end{pmatrix}\n\\cdot\n\\begin{pmatrix}\nI & 0 \\\\\n0 & I - 2 v_k v_k^\\mathsf{H}\n\\end{pmatrix}\n=\n\\begin{pmatrix}\nA[:k,:k] & A[:k,k:] - 2  A[:k,k:] v_k v_k^\\mathsf{H} \\\\\nA[k:,:k] & A[k:,k:] - 2 A[k:,k:] v_k v_k^\\mathsf{H}\n\\end{pmatrix}\n\\]\n\nWhen we are iterating through the columns of $R$ and zeroing out the entries below the main diagonal we are able to safely ignore all the entries that lie in columns we have already processed because they are already zero.\n\nThis algorithm returns orthonormal $Q$ and upper triangular $R$ satisfying $A = QR$.nNotice that we did not explicitly construct each orthonormal reflector matrix. We applied the changes we needed to each portion of the array that needed to be changed. Doing the operations in this way allows us to avoid unnecessarily increasing the computational complexity of the algorithm.\nA few other clever optimizations can still be applied, but they will not change the overall complexity of the algorithm.\n\n%It should now be clear how it was that we computed $R$ using this algorithm.\n%$Q$ is computed in much the same way.\n%Since each of the orthonormal operations is self-inverse (i.e. idempotent), $Q$ can be computed by applying the these operations to the identity in reverse order.\n%In other words, you could make an identity matrix and then for $k$ such that $n-2 \\geq k > -1$ , do $I[k:,k:] -= 2 v_k v_k^\\mathsf{H}$\n%In our computation, it may be more convenient to simply apply the operations to an identity matrix as we go, just like we are doing to $R$, then take the transpose at the end to invert $Q$.\n%This way we do not have to store the $v_k$ as we go.\n%There is one key difference, when applying these operations to $Q$ we cannot ignore columns we have already processed because they are not necessarily zero.\n%It is interesting to note that we can use the $v_k$ to behave like $Q$ or $Q^{-1}$ depending on the order in which we apply them.\n%Such an approach does not require the computation of $Q$ or $Q^{-1}$ at all.\n\nAnother important thing to notice is that an outer product is needed to compute $v_k \\left( v_k^\\mathsf{H} A[k:,k:] \\right)$, not an inner product.\nMake sure this is accounted for when you write the code to run this algorithm. You can either make the vectors $v_k$ column vectors (two dimensional with a single column) instead of just one-dimensional arrays, or you can use the built in function \\li{np.outer} in the appropriate location.\n\n\\begin{problem}\n\\label{prob:HouseholderQR}\nWrite a function \\li{householder} that accepts an array $A$ as input, and performs\nthe algorithm described above to compute the QR decomposition of $A$. Return the\nmatrices $Q$ and $R$.\n\nIt is simple to check that your code works: multiply the two output matrices\nof your function, and check that the result matches the original input matrix.\n\\end{problem}\n\n\\subsection*{Stability of the Householder QR algorithm}\nWe will now examine the stability of the Householder QR algorithm.\nWe will use SciPy's built in QR factorization which uses Householder reflections internally.\n\nTry the following.\n\n\\begin{lstlisting}\n>>> Q, X = la.qr(np.random.rand(500,500)) # create a random orthonormal matrix:\n>>> R = np.triu(np.random.rand(500,500)) # create a random upper triangular matrix\n>>> A = np.dot(Q,R) # Q and R are the exact QR decomposition of A\n>>> Q1, R1 = la.qr(A) # compute QR decomposition of A\n\\end{lstlisting}\n\nObserve:\n\n\\begin{lstlisting}\n>>> la.norm(Q1-Q)/la.norm(Q) # check error in Q\n0.282842955725\n>>> la.norm(R1-R)/la.norm(R) # check error in R\n0.0428922016647\n\\end{lstlisting}\n\nThis is terrible!\nThis algorithm works in $16$ decimal points of precision, but $Q_1$ and $R_1$ are only accurate to $0$ and $1$ decimal points, respectively.\nWe've lost $16$ decimal points of precision!\n\nDon't lose hope.\nCheck how close the product $Q_1 R_1$ is to $A$.\n\\begin{lstlisting}\n>>> A1 = Q1.dot(R1)\n>>> np.absolute(A1 - A).max()\n3.9968028886505635e-15\n\\end{lstlisting}\nWe've now recovered $15$ digits of accuracy.\nConsidering the error relative to the norm of $A$ (using the 2-norm for matrices), we see that this relative error is even smaller.\n\\begin{lstlisting}\n>>> la.norm(A1 - A, ord=2) / la.norm(A, ord=2)\n8.8655568331889288e-16\n\\end{lstlisting}\nThe errors in $Q_1$ and $R_1$ were somehow ``correlated,\" so that they canceled out in the product.\nThe errors in $Q_1$ and $R_1$ are called \\emph{forward errors}.\nThe error in $A_1$ is the \\emph{backward error}.\n\nIn fact, the large errors in \\li{Q1} and \\li{R1} were not because the algorithm was bad, it was because $A$ was poorly conditioned.\nThe condition number for randomly generated upper triangular matrices is generally very high, and this was the case here.\nThis has, in turn, made the condition number of $A$ extremely large.\n\nTry the following to compute the condition number of $A$.\nIn this case the condition number of $A$ and $R$ are computed to be different, though, in theory, they should be exactly the same.\n\\begin{lstlisting}\n>>> from numpy.linalg import cond\n>>> cond(A)\n4.1426075832870472e+18\n>>> cond(R)\n3.1767577244363792e+19\n\\end{lstlisting}\n\nHouseholder QR factorization is more numerically stable than Gram-Schmidt or even Modified Gram-Schmidt (MGS).\nHowever, MGS is still useful for some types of iterative methods because it finds the orthonormal basis one vector at a time instead of all at once (for an example see Lab \\ref{lab:EigSolve}).\n\n\\subsection*{Upper Hessenberg Form}\nAn upper Hessenberg matrix is a square matrix with zeros below the first subdiagonal.\nEvery  $n \\times n$ matrix $A$ can be written $A = Q^THQ$ where $Q$ is orthonormal and $H$ is an upper Hessenberg matrix, called the Hessenberg form of $A$.\n\nThe Hessenberg decomposition can be computed using Householder reflections in a process very similar to Householder triangularization.\nLet's demonstrate this process on a $5 \\times 5$ matrix $A$.\nNote that $A=Q^THQ$ is equivalent to $QAQ^T = H$. Our strategy is to multiply $A$ on the right and left by a series of orthonormal matrices until it is in Hessenberg form.\nIf we use the same $Q_1$ as in the first step of the Householder algorithm, then with $Q_1 A$ we introduce zeros in the first column of $A$.\nHowever, since we now have to multiply $Q_1 A$ on the left by $Q_1^T$, all those zeros are destroyed, as demonstrated below.\nIn order to zero out the entire first column we must choose $Q_1$ appropriately so it does not fix the first row. When we apply the same operation on the right, this ruins the column that we just zeroed out.\n(Although this process may seem futile now, it actually does tend to decrease the size of the subdiagonal entries.\nIf we repeat over and over again, the subdiagonal entries will often converge to zero. That's the idea behind the $QR$ algorithm in Lab \\ref{lab:EigSolve}.)\n\\[\n\\begin{array}{ccccc}\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & *\n\\end{pmatrix}\n&\\underrightarrow{Q_1 \\cdot }&\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & *\n\\end{pmatrix}\n&\\underrightarrow{\\cdot Q_1^T }&\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & *\n\\end{pmatrix}\n\\\\\nA & & Q_1A & & Q_1 A Q_1^T\n  \\end{array}\n\\]\nInstead, let's try starting with a different $Q_1$ that leaves the \\emph{first} row alone and reflects the \\emph{rest} of the rows into the span of $e_2$. This means that $Q_1^T$ leaves the first column alone.\n\\[\n\\begin{array}{ccccc}\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & *\n\\end{pmatrix}\n&\\underrightarrow{Q_1 \\cdot }&\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & *\n\\end{pmatrix}\n&\\underrightarrow{\\cdot Q_1^T }&\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & *\n\\end{pmatrix}\n\\\\\nA & & Q_1A & & Q_1 A Q_1^T\n  \\end{array}\n\\]\nWe now iterate through the matrix until we obtain\n\\begin{equation*}\nQ_3 Q_2 Q_1 A Q_1^T Q_2 ^T Q_3^T =\n\\begin{pmatrix}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & 0 & * & * & * \\\\\n0 & 0 & 0 & * & *\n\\end{pmatrix}\n\\end{equation*}\n\nThis is even more convenient when we are working with Hermitian matrices.\nIn that case, the matrices applied on the left zero out everything below the first subdiagonal and the matrices applied on the right zero out everything above the first superdiagonal, leaving us with a tridiagonal matrix.\nThere are remarkably efficient ways to solve systems involving tridiagonal matrices, so this is especially convenient.\n\nThe pseudocode for computing the Hessenberg form of a matrix is shown in Algorithm \\ref{Alg:Hessenberg}.\nThe exact inner workings of this algorithm are similar to the inner workings of Algorithm \\ref{Alg:Householder}.\n\n\\begin{algorithm}\n\\caption{Reduction to Hessenberg Form}\n\\label{Alg:Hessenberg}\n\\begin{algorithmic}[1]\n\\Procedure{Hessenberg}{$G,u,l,p$}\n\\State $m, n \\gets \\text{shape}(A)$\n\\State $H \\gets \\text{copy}(A)$\n\\State $Q \\gets I_m$\n\\For{$0 \\leq k < n-2$}\n    \\State $v_k \\gets H_{k+1:, k}$\n    \\State $v_{k_0} \\gets v_{k_0} + \\text{sign}(v_{k_0}) \\norm{v_k}$\n    \\State $v_k \\gets v_k/norm{v_k}$\n    \\State $H_{k+1:,k:} \\gets H_{k+1:,k:} - 2v_k(v_k^\\mathsf{H} H_{k+1:,k:})$\n    \\State $H_{:,k+1:} \\gets H_{:,k+1:} - 2(H_{:,k+1:} v_k) v_k^\\mathsf{H}$\n    \\State $Q_{k+1:} \\gets Q_{k+1:} - 2v_k(v_k^\\mathsf{H} Q_{k+1:})$\n\\EndFor\n\\State \\pseudoli{return} $Q, R$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{problem}\n\\label{prob:hessenberg}\nWrite a function \\li{hessenberg} that computes the Hessenberg form of a real-valued\ninput matrix $A$. The function should return $Q$ and $H$ satisfying $A = Q^THQ$,\nwhere $Q$ is orthonormal and $H$ has zeros below the first subdiagonal.\n\nThe code for this algorithm will be fairly similar to the code for the QR factorization using Householder reflections.\nThis factorization technique will be used later on in Lab \\ref{lab:EigSolve}.\nNotice what happens when you compute the Hessenberg factorization of a Hermitian matrix.\n\\end{problem}\n\n%Sources: http://www.cs.unc.edu/~krishnas/eigen/node5.html\n% http://en.wikipedia.org/wiki/Givens_rotation\n%http://en.wikipedia.org/wiki/QR_decomposition\n%\tNote the Operation count: Householder is 2/3 n^3, MGS is 2 n^3\n%http://en.wikipedia.org/wiki/QR_algorithm\n%Applied Numerical methods using MATLAB by Yang has some code written for this\n%http://www.math.kent.edu/~reichel/courses/intr.num.comp.2/lecture21/evmeth.pdf\n%\tThese are eigenvalue algorithms explained carefully\n%http://en.wikipedia.org/wiki/Householder_transformation\n%Numerical Linear Algebra, by Lloyd N. Trefethen and David Bau III, Chapters 10 and 16 \n\n", "meta": {"hexsha": "a3653af4007bba966511a99d9f58935278d5fcdc", "size": 26750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/QR/QR.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/QR/QR.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/QR/QR.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": 43.6378466558, "max_line_length": 376, "alphanum_fraction": 0.6905046729, "num_tokens": 8538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.6687687910290078}}
{"text": "%% ps1_q2.tex\n\\section{Two small categories}\n\nObjects: 1, 2\n\nMorphisms: \n\n\\begin{align*} \n1 \\rightarrow 1 &: \\{id_1\\}  \\\\\n2 \\rightarrow 2 &: \\{id_2\\}  \\\\\n1 \\rightarrow 2 &: \\{f\\}     \\\\\n2 \\rightarrow 1 &: \\emptyset\n\\end{align*} \n\nComposition:\n\\begin{align*} \n  id_1 \\circ id_1 &= id_1 \\\\\n  id_2 \\circ id_2 &= id_2 \\\\\n     f \\circ id_1 &= f \\\\\n     id_2 \\circ f &= f \n\\end{align*} \n\nRight unit: $f \\circ id_1 = f$\nLeft unit: $id_2 \\circ f = f$\n\nAssociativity: as we only compose with identity, the associativity is trivial,\n\n$$\n   id_2 \\circ f \\circ  id_1 = (id_2 \\circ f) \\circ  id_1 = id_2 \\circ  (f \\circ id_1) = f\n$$\n", "meta": {"hexsha": "1e99c83429b8e837e3062fbcc409ea457db07c69", "size": 620, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps1/ps1_q2.tex", "max_stars_repo_name": "alf239/procats", "max_stars_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps1/ps1_q2.tex", "max_issues_repo_name": "alf239/procats", "max_issues_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps1/ps1_q2.tex", "max_forks_repo_name": "alf239/procats", "max_forks_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0, "max_line_length": 89, "alphanum_fraction": 0.5967741935, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6687281021117085}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{Sheet 2}\n\n\\subsection{Constant acceleration}\n\n\\subsubsection{Coordinate velocity}\n\nWe are given the position as a function of time, \n\\begin{equation} \\label{eq:constant-acceleration} \n  x(t) = \\frac{\\sqrt{1 + \\kappa^2 t^2} -1 }{\\kappa }\\,,\n\\end{equation}\n%\nand we can directly compute its derivative\n%\n\\begin{equation} \\label{eq:constant-acceleration-velocity} \n  v(t) = \\dv{x}{t} =\n  \\frac{\\kappa t}{\\sqrt{\\kappa^2 t^2  + 1} }=\\frac{1}{\\sqrt{\\frac{1}{\\kappa^2 t^2}+1 }}\\,.\n\\end{equation}\n\nIt is clear from the expression that \\(\\abs{v} < 1\\) for all times, while \\(v\\) approaches 1 at positive temporal infinity and \\(-1\\) at negative temporal infinity.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/velocity.pdf}\n    \\caption{Velocity as a function of coordinate time \\(t\\)}\n    \\label{fig:velocity-constant-acceleration}\n\\end{figure}\n\n\\subsubsection{Components of the 4-velocity}\n\nThe Lorentz factor \\(\\gamma \\) is given by\n%\n\\begin{equation} \\label{eq:constant-acceleration-gamma}\n  \\gamma = \\frac{1}{\\sqrt{1-v^2}}\n  = \\frac{1}{\\sqrt{1 - \\frac{\\kappa^{2} t^{2}}{\\kappa^{2} t^{2} + 1} }}\n  = \\sqrt{\\kappa^2 t^2 + 1} \\,,\n\\end{equation}\n%\ntherefore the four-velocity is given by:\n%\n\\begin{equation}\n  u^{\\mu } =\n  \\begin{bmatrix}\n  \\gamma  \\\\\n  \\gamma v \\\\\n  0 \\\\\n  0\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n    \\sqrt{\\kappa^2 t^2 + 1}  \\\\\n    \\kappa t \\\\\n    0 \\\\\n    0\n  \\end{bmatrix}\\,.\n\\end{equation}\n\n\\subsubsection{Proper time}\n\nThe relation between coordinate and proper time is given by the definition of the first component of the four-velocity: \\(u^{0} = \\dv*{t}{\\tau} = \\gamma \\), therefore \\(\\dd{\\tau } = \\dd{t} / \\gamma \\).\nIntegrating this relation we get:\n%\n\\begin{equation}\n    \\tau = \\int_0^{\\tau} \\dd{\\tau'} \n    = \\int_0^{t} \\frac{\\dd[]{t'} }{\\gamma(t')}\n    = \\displaystyle \\frac{\\operatorname{arcsinh}{\\left(\\kappa t \\right)}}{\\kappa}\\,,\n\\end{equation}\n%\nwhere the constant of integration is selected by imposing \\(t = 0 \\iff \\tau = 0\\).\nNotice that, as we would expect, when expanding up to first order near \\(t = \\tau = 0 \\) we have \\(t \\sim \\tau \\), since in that region the velocity is much less than unity.\n\nThe inverse relation is given by \\(t = \\sinh (\\kappa \\tau ) / \\kappa \\). Using this, we can write:\n%\n\\begin{equation}\n  x (t(\\tau ))  =\\frac{\\cosh{\\left(\\kappa \\tau \\right)} - 1}{\\kappa}\\,.\n\\end{equation}\n\n\\subsubsection{Four-acceleration}\n\nNow, we wish to compute the four-acceleration. There are many ways to approach this: an easy one is to simply find the explicit expression \\(u^{\\mu } (\\tau )\\) and to differentiate it. The expression we get is:\n%\n\\begin{equation}\n    a^{\\mu } = \\dv{}{\\tau } u^{\\mu } = \\dv{}{\\tau }   \n  \\begin{bmatrix}\n    \\sqrt{\\sinh^{2}{\\left(\\kappa \\tau \\right)} + 1}\n        \\\\\n    \\frac{\\sqrt{\\kappa^{2} t^{2} + 1} \\sinh{\\left(\\kappa \\tau \\right)}}{\\sqrt{\\sinh^{2}{\\left(\\kappa \\tau \\right)} + 1}} \\\\\n    0 \\\\\n    0\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n    \\frac{\\sqrt{2} \\kappa \\sinh{\\left(2 \\kappa \\tau \\right)}}{2 \\sqrt{\\cosh{\\left(2 \\kappa \\tau \\right)} + 1}}\n    \\\\\n    \\kappa \\cosh \\left(\\kappa \\tau \\right)\\\\\n    0 \\\\\n    0\n  \\end{bmatrix}\n\\,,\n\\end{equation}\n%\nwhich is a bit unwieldy but it can be used to check two important facts: \\(a^{\\mu } a_{\\mu } = \\const \\) and \\(a^{\\mu }u_{\\mu } = 0\\). The first of the two is:\n%\n\\begin{equation}\n    a^{\\mu }a_{\\mu } = -(a_0 )^2 + (a_1 )^2 =\n    \\kappa^{2} \\cosh^{2}{\\left(\\kappa \\tau \\right)} - \\frac{\\kappa^{2} \\sinh^{2}{\\left(2 \\kappa \\tau \\right)}}{2 \\left(\\cosh{\\left(2 \\kappa \\tau \\right)} + 1\\right)}\n    = \\kappa^2 \n\\,,\n\\end{equation}\n%\nwhich tells us that the constant acceleration \\(\\sqrt{a^{\\mu }a_{\\mu }} = \\kappa \\).\n\nAlso, we verify the orthogonality to the four-velocity: \n%\n\\begin{equation}\n  a^{\\mu }u_{\\mu } = \n  - \\frac{\\sqrt{2} \\kappa \\sqrt{\\sinh^{2}{\\left(\\kappa \\tau \\right)} + 1} \\sinh{\\left(2 \\kappa \\tau \\right)}}{2 \\sqrt{\\cosh{\\left(2 \\kappa \\tau \\right)} + 1}} + \\kappa \\sinh{\\left(\\kappa \\tau \\right)} \\cosh{\\left(\\kappa \\tau \\right)}\n  = 0\n\\,.\n\\end{equation}\n\n\\subsubsection{Local velocity \\& acceleration}\n\nWe can apply a Lorentz boost corresponding to this velocity:\nit will be given by the matrix:\n%\n\\begin{equation}\n  \\left[\\begin{array}{cccc}\n  \\gamma  & -v \\gamma  & 0 & 0 \\\\ \n  -v \\gamma  & \\gamma  & 0 & 0 \\\\ \n  0 & 0 & 1 & 0 \\\\ \n  0 & 0 & 0 & 1\n  \\end{array}\\right]\n\\,,\n\\end{equation}\n%\nwhere \\(v\\) and \\(\\gamma \\) are those found before.\nWithout doing any calculations we could already say that the transformed velocity will be equal to the time-like unit vector, while the acceleration will be equal to \\(\\kappa \\) times the unit \\(x\\)-directed vector.\n\nThe velocity becomes:\n%\n\\begin{equation}\n  \\qty(u^{\\mu})' =\n  \\left[\\begin{array}{cccc}\n    \\sqrt{\\kappa^2 t^2 + 1}  & -\\kappa t  & 0 & 0 \\\\ \n    -\\kappa t  & \\sqrt{\\kappa^2 t^2 + 1}  & 0 & 0 \\\\ \n    0 & 0 & 1 & 0 \\\\ \n    0 & 0 & 0 & 1\n    \\end{array}\\right]\n    \\begin{bmatrix}\n      \\sqrt{\\kappa^2 t^2 + 1}  \\\\\n      \\kappa t \\\\\n      0 \\\\\n      0\n    \\end{bmatrix} \n  = \n  \\begin{bmatrix}\n  1 \\\\\n  0 \\\\\n  0 \\\\\n  0\n  \\end{bmatrix}\n\\,,\n\\end{equation}\n%\nas we expected.\n\nThe acceleration instead becomes:\n%\n\\begin{equation}\n  \\qty(a^{\\mu})' =\n  \\left[\\begin{array}{cccc}\n    \\sqrt{\\kappa^2 t^2 + 1}  & -\\kappa t  & 0 & 0 \\\\ \n    -\\kappa t  & \\sqrt{\\kappa^2 t^2 + 1}  & 0 & 0 \\\\ \n    0 & 0 & 1 & 0 \\\\ \n    0 & 0 & 0 & 1\n    \\end{array}\\right]\n    \\begin{bmatrix}\n      \\frac{\\sqrt{2} \\kappa \\sinh{\\left(2 \\kappa \\tau \\right)}}{2 \\sqrt{\\cosh{\\left(2 \\kappa \\tau \\right)} + 1}}\n      \\\\\n      \\kappa \\cosh \\left(\\kappa \\tau \\right)\\\\\n      0 \\\\\n      0\n    \\end{bmatrix}\n  = \n  \\begin{bmatrix}\n  0 \\\\\n  \\kappa  \\\\\n  0 \\\\\n  0\n  \\end{bmatrix}\n\\,,\n\\end{equation}\n%\nAt small speeds the Lorentz boost matrix reduces to the identity matrix: this implies $kt\\simeq k\\tau\\simeq 0$. In this case we obtain the same results of the rest frame of the particle for both acceleration and speed.\n\\subsection{Fixed target collision}\n\n\\subsubsection{Center of mass momenta}\n\nIn the CoM frame, the momenta of the two protons are respectively \\((E_p, \\pm p, 0,0)^\\top = m_p (\\gamma, \\pm v, 0, 0)\\), where \\(E_p^2 = m_p^2 + p^2\\).\nThe total CoM energy is \\(-(p^\\mu _A + p^\\mu _B )^2 = 2 m_p^2\\).\n\n\\subsubsection{Center of mass velocity}\n\nThe momentum of particle \\(B\\) will be given by \\(p^{\\mu } = m_p u^{\\mu } = (m_p \\gamma , m_p \\gamma v, 0, 0)^\\top\\). Therefore, \\(\\gamma v = p / m_p\\). Solving this we get: \n%\n\\begin{equation}\n  v = \\frac{p}{m_p} \\sqrt{\\frac{1}{(p/m_p)^{2} + 1}} = \\frac{p}{E_p}\n\\,,\n\\end{equation}\n%\n\n\\subsubsection{Lab frame momenta}\n\nThe momentum of particle \\(B\\) in its own rest frame will just be \\((m_p, 0, 0, 0)^\\top\\).\nThe momentum of particle \\(A\\) instead will be given by a boost in the \\(x\\) direction with velocity \\(-v\\):\n%\n\\begin{equation}\n  (p_A^\\mu) _{\\text{lab}} = \n  \\left[\\begin{array}{cccc}\n  \\gamma  & v \\gamma  & 0 & 0 \\\\ \n  v \\gamma  & \\gamma  & 0 & 0 \\\\ \n  0 & 0 & 1 & 0 \\\\ \n  0 & 0 & 0 & 1\n  \\end{array}\\right]\n  \\left[\\begin{array}{c}\n  E_p  \\\\ \n  p \\\\ \n  0 \\\\ \n  0\n  \\end{array}\\right]  \n  = \\left[\\begin{array}{c}\n    \\gamma E_p + v \\gamma p  \\\\ \n    v \\gamma E_p + \\gamma p \\\\ \n    0 \\\\ \n    0\n    \\end{array}\\right]  \n  = \\left[\\begin{array}{c}\n    m_p \\gamma^2 (1+v^2)  \\\\ \n    2 \\gamma p\\\\ \n    0 \\\\ \n    0\n    \\end{array}\\right]\n\\,,\n\\end{equation}\n%\n\n\\subsection{Weak field gravitational time dilation}\n\n\\subsubsection{Time dilation expression}\n\nIt is more intuitive geometrically to deal with a pulse sent from \\(A\\) to \\(B\\), for which we expect the time dilation to work in the opposite sense: \n%\n\\begin{equation}\n  \\Delta t_B = \\Delta t_A \\qty(1 + gh)\n\\,,\n\\end{equation}\n%\nup to first order in \\(gh\\) and \\(g\\Delta t_A\\), since \\((1+gh )(1-gh) = 1-(gh)^2 = 1\\) to first order in \\(gh\\).\nAlternatively, one can just map \\(g \\rightarrow -g\\) to recover the time contraction for pulses sent in the other direction.\n\nWe know that the paths of the observers are two curves of constant acceleration: we know their explicit expression from equation \\eqref{eq:constant-acceleration}, and additionally we assume that they are separated by a space interval \\(h\\): \n%\n\\begin{subequations}\n\\begin{align}\n  x_A(t) &= \\frac{\\sqrt{1 + (gt)^2} -1}{g} \\\\ \n  x_B(t) &= \\frac{\\sqrt{1 + (gt)^2} -1}{g} + h\n  \\,.\n\\end{align}\n\\end{subequations}\n\nAt \\(t=0\\) Alice sends a pulse, which then reaches Bob at a time \\(t_1\\). After a time \\(\\Delta t_A\\), she sends another, which then reaches Bob at a time \\(t_2 \\). \nRight now, we are referring to all times as measured in the rest frame of Alice at \\(t=0\\).\nThese times can be found by imposing that the space and time separation between the events of the pulse being sent and received are equal, since it travels at light speed: the equations which represent this are \\(x_B(t_1) = t_1\\) and \\(x_B(t_2 ) -x_A (\\Delta t_A) = t_2 - \\Delta t_A\\). Substituting the expressions for the positions:\n%\n\\begin{subequations}\n\\begin{align}\n  t_1 &= \\frac{\\sqrt{1+(g t_1 )^2} -1}{g} +h \\\\\n  t_2 - \\Delta t_A &= \\frac{\\sqrt{1+(gt_2 )^2} -1}{g} + h - \\qty(\\frac{\\sqrt{1+(g \\Delta t_A )^2} -1}{g})\\,.\n\\end{align}\n\\end{subequations}\n\nNow, it is just a matter of calculation to solve these equations, expand up to first order in the adimensional parameters \\(gh\\) and \\(g \\Delta t_A\\) and one recovers the desidered expression for  \\(\\Delta t_B = t_2 - t_1\\).\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=\\textwidth]{figures/Visualization_of_accelerational_time_dilation.eps}\n  \\caption{Visualization of the beams, in the frame where the rocket is stationary as the first beam is being sent. The two curves intersecting the space axis are the tip and tail of the spaceship; the beams being sent from the tail are events \\(C\\) and \\(D\\), while their reception at the tip are events \\(A\\) and \\(B\\). Event \\(E\\) is just calculated as \\(B-A\\), to make comparisons with \\(D\\) easier. \\(H\\) and \\(G\\) are computed by tracing the dotted line of points which have the same spacetime interval from the origin as points \\(D\\) and \\(E\\) respectively, and selecting its intersection with the temporal axis: this effectively means finding the proper time separation between the two beams being sent/received.}\n  \\label{fig:beam-visualization}\n\\end{figure}\n\nThere is one more consideration to make though: what about the Lorentz time dilation for Bob? This it actually a \\emph{second order effect}.\n\n\\begin{claim}\nThe time interval measured by Bob in his frame at \\(t \\sim t_1\\) is the same as the one measured in the rest frame of Alice at \\(t=0\\) up to first order in \\(gh\\) and \\(g \\Delta t_B\\).\n\\end{claim}\n\n\\begin{proof}\nWe perform a Lorentz boost to the velocity of Bob at \\(t=t_1 \\): this is given by equation \\eqref{eq:constant-acceleration-velocity}, and is equal to:\n%\n\\begin{equation}\n  v = \\frac{gt }{\\sqrt{(gt)^2 + 1}}\n\\,,\n\\end{equation}\n%\nwith a Lorentz factor of \\(\\gamma = \\sqrt{(gt)^2 +1} \\) (see equation \\eqref{eq:constant-acceleration-gamma}).\n\nThe temporal separation between the two events is \\(\\Delta t_B\\), while the spatial separation is \\(\\Delta x_B \\approx  v \\Delta t_B\\) to first order. The boost, in the \\((t, x)\\) plane, looks like: \n%\n\\begin{equation}\n  \\left[\\begin{array}{c}\n  \\Delta t_B \\\\ \n  \\Delta x_B\n  \\end{array}\\right]'\n  =\n  \\left[\\begin{array}{cc}\n  \\gamma  & -v \\gamma  \\\\ \n  -v \\gamma  & \\gamma \n  \\end{array}\\right]  \n  \\left[\\begin{array}{c}\n  \\Delta t_B \\\\ \n  \\Delta x_B\n  \\end{array}\\right] \n  =\n  \\left[\\begin{array}{c}\n  \\Delta t_B \\qty(\\sqrt{(gt)^2+1} - (gt)^2/\\sqrt{(gt)^2+1}) \\\\ \n  -gt \\Delta t_B + \\sqrt{(gt)^2+1} gt \\Delta t / \\sqrt{(gt)^2+1}\n  \\end{array}\\right]\n\\,,\n\\end{equation}\n%\ntherefore as we would expect the spatial separation is eliminated, while expanding the factor multiplying the temporal one near \\(gt = 0\\) we get: \n%\n\\begin{equation}\n  \\sqrt{(gt)^2+1} - (gt)^2/\\sqrt{(gt)^2+1} = 1+O((gt)^2)\n\\,,\n\\end{equation}\n%\nwhich proves our result.\n\\end{proof}\n\n\\subsubsection{Gravitational time dilation}\n\nBy the equivalence principle, the effects measured in a uniformly accelerating frame at \\(g\\) are the same as those measured in a gravitational field with constant acceleration \\(g\\).\nThe gravitational field in such a frame is given by \\(\\Phi  = gh\\), where \\(h\\) is the height (with arbitrary zero point): the result follows.\n\n\\subsubsection{Twins and gravitation}\n\nThe gravitational time dilation difference, in absolute value, is given by: \n%\n\\begin{equation}\n  \\Delta t = t _{\\text{elapsed}} \\frac{g \\Delta h}{c^2}\n  \\approx \\SI{1}{yr} \\frac{\\SI{10}{m/s^2} \\times \\SI{100}{m}}{(\\SI{3e8}{m/s})^2} \\approx \\SI{3.5e-7}{s} \n\\,.\n\\end{equation}\n\nWe are asked what is the age of the twin on the ground as measured by the twin who is higher up: this is analogous to the situation considered in the first section of this problem; the twin higher up will measure the twin lower down to be older, specifically if \\(\\text{age}_{\\text{up}} = \\SI{1}{yr}\\), then the observer up in the palace will measure the age of the twin at ground level as:\n%\n\\begin{equation}\n  \\text{age}_{\\text{down}} = \\SI{1}{yr} + \\SI{3.5e-7}{s} \\approx (1+\\num{1e-14}) \\text{age}_{\\text{up}}\n\\,.\n\\end{equation}\n%\n\n\\end{document}\n", "meta": {"hexsha": "7a13003adca3579aa17f72673ac63ff9f74b640f", "size": 13213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/gr_exercises/sheet2.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/sheet2.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/sheet2.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.9048913043, "max_line_length": 721, "alphanum_fraction": 0.6383107546, "num_tokens": 4590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6687235505564724}}
{"text": "Calculation:\r\n\\begin{equation*}\r\n\tOut = \\begin{cases}0 & Num=0, Den = 0\\\\ maxVal & Num > 0, Den=0\\\\ minVal & Num < 0, Den =0\\\\ \\frac{Num}{Den} & \\text{otherwise} \\end{cases}\r\n\\end{equation*}\r\n\\paragraph{Note:}\\textit{maxVal} and \\textit{minVal} refer to the maximum/minimum representable value of the implementation.\r\n\r\n", "meta": {"hexsha": "b11490177e1021f05cef8eba0a7748096963ad57", "size": 320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Library/Math/Doc/Div_Info.tex", "max_stars_repo_name": "AlexisTM/X2C", "max_stars_repo_head_hexsha": "31f39b598afe271a7fd46ef1ee9e06c410b1120c", "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": "Library/Math/Doc/Div_Info.tex", "max_issues_repo_name": "AlexisTM/X2C", "max_issues_repo_head_hexsha": "31f39b598afe271a7fd46ef1ee9e06c410b1120c", "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": "Library/Math/Doc/Div_Info.tex", "max_forks_repo_name": "AlexisTM/X2C", "max_forks_repo_head_hexsha": "31f39b598afe271a7fd46ef1ee9e06c410b1120c", "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.7142857143, "max_line_length": 141, "alphanum_fraction": 0.678125, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6686988799088285}}
{"text": "\\documentclass{article}\n\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{amsthm}\n\\usepackage{hyperref}\n\n\\newcommand*{\\thead}[1]{\\multicolumn{1}{|c|}{\\bfseries #1}}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{question}{Question}\n\n\\begin{document}\n\n\\title{Euclid's Algorithm and B\\'ezout's Identity}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{Introduction}\n\nWhen working with large numbers, we will often want to calculate their greatest common divisor.\nIn particular, it is often important to know if two numbers are co-prime, that is, if they have a\ngreatest common divisor of 1. A fast algorithm for this, which dates from ancient times, is\nEuclid's Algorithm. \n\nFor math competitions, it will sometimes be useful to be able to find a linear combination of two\nnumbers with integer solutions, especially when working in modular arithmetic. Based on Euclid's\nalgorithm, we will also show how to create such a linear combination using B\\'ezout's identity.\n\n\\section{Euclid's Algorithm}\n\nThe Greatest Common Divisor of two integers $a,b$ is the largest positive integer $k$ which \nevenly divides both $a$ and $b$. That is, we can write $a=km$, $b=kn$ for $m,n \\in \\mathbb{Z}$ and \n$\\gcd(m,n) = 1$. For smaller numbers, we will typically do this by finding the prime decomposition\nof the two numbers, and identifying prime numbers which are common factors of both numbers.\n\nHowever, this is impractical for larger numbers. Thankfully, Euclid's algorithm gives us a simple\nmethod to systematically find the GCD of any two natural numbers.\n\n\\begin{theorem}\nGiven two positive integers $a,b \\in \\mathbb{Z}^+$, we can find unique non-negative integers \n$q,r \\in \\mathbb{Z}^+$ (quotient and remainder) such that:\n\n\\[ a = qb + r \\]\n\nwith $0\\leq r < a$\n\\end{theorem}\n\nThat is, we can always divide $b$ into $a$ to get a quotient and a remainder. We can even weaken the\nrequirement that $a$ and $b$ are positive integers, if we allow negative values of $q$ and we can find a\npositive $r < |b|$. For example, if we use this with $a=89, b=17$, we get $q=5, r=4$, and \n$89 = 5 \\times 17 + 4$. What makes this into an algorithm to calculate the GCD is the following result:\n\n\\begin{theorem}\nGiven positive integers $a,b$ with $a>b$, and non-negative integers $q,r$ such that $a=qb+r$:\nIf $r>0$ then $\\gcd(a,b) = \\gcd(b,r)$.\n\\end{theorem}\n\n\\begin{proof}\nLet $k = \\gcd(a,b)$. Then $a=km, b=kn, \\gcd(n,m) = 1$.\n\nWe are given:\n\\begin{eqnarray*}\n\t a &=& qb+r \\\\\n\t\\implies r &=& a-qb \\\\\n\t\\implies r &=& k(m-qn) \n\\end{eqnarray*}\nSo $r$ is a multiple of $k$.\n\nAlso, if $gcd(b,r)=j > k$ then $qb = jm, r=jn$ for some $m,n$, and then:\n\\[ a = qb+r = j(m+n) \\]\nso $a$ is also a multiple of $j$ and $k$ is not the GCD of $a,b$, which is a contradiction.\n\nTherefore, $\\gcd(a,b) = \\gcd(b,r)$. \n\\end{proof}\n\nThis gives us a way to repeat this operation until $r$ eventually reaches $0$, at which case the $r$\nin the prior step is the GCD.\n\nLet's work through an example to see it in action.\n\n\\begin{question}\nFind the GCD of 1128\\ and 33.\n\\end{question}\n\\begin{proof}[Answer]\n\t\\begin{eqnarray*}\n\t\t1128 &=& 34\\times 33 + 6 \\\\\n\t\t33 &=& 5\\times 6 + 3 \\\\\n\t\t6 &=& 2 \\times 3 + 0   \n\t\\end{eqnarray*}\n\tSo the GCD of 1128 and 33 is 3 (the last non-zero remainder).\n\\end{proof}\n\n\\begin{question} Find the GCD of 6540 and 1206. \\end{question}\n\\vspace*{\\bigskipamount}\n\n\\section{Bézout's identity}\n\nGiven $a,b \\in \\mathbb{Z}, a, b \\neq 0$, we can find $n,m \\in \\mathbb{Z}$ such that:\n\\[ \\gcd(a,b) = ma + nb \\]\nIn fact when both $a$ and $b$ are not equal to 0, we can find infinitely many such pairs $(m,n)$.\n\nIn particular, if $\\gcd(a,b)=1$, then for all integers $k$, we can find $n,m\\in \\mathbb{Z}$ such that:\n\\[ k = am + bn \\]\n\nAnd further, if $\\gcd(a,b)=k$, there are no solutions to the equation $am+bn=j$ if $j$ is not a\nmultiple of $k$.\n\nThe way that we use Euclid's algorithm to generate this identity is that we start at the last step,\nand rearrange everything to be in terms of $\\gcd(a,b)$, and then at each stel we replace the remainder\nterm with $a-qb$.\n\nLet's work through an example to see how it works:\n\n\\begin{question}\n\tFind an integer solution to:\n\t\\[ 267x + 112y = 3 \\]\n\\end{question}\n\\begin{proof}[Answer]\n\tLet's start by calculating the GCD of 267 and 112 using Euclid's algorithm, and also\n\tnoting the form $r = a-qb$ at each step:\n\t\\begin{align*}\n\t\t267 &= 2 \\times 112 + 43 & 43 &= 267 - 2 \\times 112 \\\\\n\t\t112 &= 2 \\times 43 + 26 & 26 &= 112 - 2 \\times 43\\\\\n\t\t43 &= 1 \\times 26 + 17 & 17 &= 43 - 1 \\times 26 \\\\\n\t\t26 &= 1 \\times 17 + 9 & 9 &= 26 - 1 \\times 17 \\\\\n\t\t17 &= 1 \\times 9 + 8 & 8 &= 17 - 1 \\times 9 \\\\\n\t\t9 &= 1 \\times 8 + 1 & 1 &= 9 - 1 \\times 8 \\\\\n\t\t8 &= 8 \\times 1 + 0 &&\n\t\\end{align*}\n\n\tSo the GCD of 267 and 112 is 1.\n\n\tNow we run through the algorithm backwards, isolating the remainder term:\n\t\\begin{eqnarray*}\n\t\t1 &=&  9 - 1 \\times 8  \\\\\n\t\t1 &=&  9 - 1 \\times (17 - 1 \\times 9) = 2 \\times 9 -1 \\times 17  \\\\\n\t\t1 &=&  2 \\times (26 - 1 \\times 17) - 1 \\times 17 = 2 \\times 26 - 3 \\times 17  \\\\\n\t\t1 &=&  2 \\times 26 - 3 \\times (43 - 1 \\times 26) = 5 \\times 26 - 3 \\times 43  \\\\\n\t\t1 &=&  5 \\times (112 - 2 \\times 43) - 3 \\times 43 = 5 \\times 112 -13 \\times 43 \\\\\n\t\t1 &=&  5 \\times 112 - 13 \\times (267 - 2 \\times 112) = 31 \\times 112 - 13 \\times 267\n\t\\end{eqnarray*}\n\n\tNow we have a general solution $1 = 31\\times 112 - 13\\times 267$, and we can generate other\n\tsolutions to the same equation by adding and subtracting multiples of $112 \\times 267$ as follows:\n\t\\[ 1 = (31-267k) \\times 112 + (112k - 13) \\times 267 \\]\n\t\n\tAnd we can get the general solution to the question asked by multiplying every term by 3:\n\t\\[ 3 = (93-801k) \\times 112 + (336k - 39) \\times 267 \\]\n\n\twhich gives solutions for any $k\\in \\mathbb{Z}$.\n\n\\end{proof}\n\nQuestions of this type often arise with different notation or ways of framing the question. Here are\nanother could of examples, and some exercises:\n\n\\begin{question}\n\tDetective John McLain and Zeus, a New York small business owner in the wrong place at the wrong\n\ttime, are directed by the mysterious terrorist Simon to a fountain in Central Park, where they\n\tfind an armed bomb. They are given an enigma to solve to defuse the bomb.\n\n\tGiven a 3 gallon jug and a 5 gallon jug, how can they measure out exactly 4 gallons to put\n\ton the scale and defuse the bomb?\n\\end{question}\n\n\\begin{proof}[Answer]\n\tWe can now recognize this as a simple application of B\\'ezout's Identity. We want to find integers\n\t$a, b$ such that $5a + 3b = 4$. It is straightforward to find values of $a$ and $b$ that work,\n\tbut we will run through the algorithm to find the general solution.\n\n\t\\begin{align*}\n\t\t5 &= 1 \\times 3 + 2 & 2 &= 5 - 3  \\\\\n\t\t3 &= 1 \\times 2 + 1 & 1 &= 3 - 2 \\\\\n\t\t& & 1 &= 3 - (5 - 3) = 2(3) - 5\n\t\\end{align*}\n\n\tOur base solution is:\n\t\\[ 3(2) + 5(-1) = 1\\]\n\tand multiplying across by 4, ww get \n\t\\[ 3(8) + 5(-4) = 4\\]\n\n\tAdding and subtracting $15k$ to obtain the general solution gives us:\n\t\\[ 3(8-5k) + 5(3k-4) = 4\\]\n\n\tNow the smallest solution in terms of steps is at $k=2$, $2\\times 5 - 2\\times 3 = 4$. So we have\n\tto fill up the five gallon drum twice, and empty out the 3 gallon drum twice.\n\n\t\\begin{figure}[ht!]\n\t\\includegraphics{mathologer.png}\n\t\t\\caption{\\href{https://www.youtube.com/watch?v=0Oef3MHYEC0}{Mathologer\n\t\tvisual demonstration of this problem in action}}\n\t\\end{figure}\n\n\t\\vspace{1em}\n\n\t\\begin{tabular}{|l|c|c|r|}\n\t\t\\hline\n\t\t\\thead{Step} & \\thead{5 Gallon Jug} & \\thead{3 Gallon jug}\\\\\n\t\t\\hline\n\t\tFill 5G jug from fountain & 5 & 0 \\\\\n\t\tFill 3G jug from 5G jug & 2 & 3 \\\\\n\t\tEmpty 3G jug & 2 & 0 \\\\\n\t\tEmpty 5G jug into 3G jug & 0 & 2 \\\\\n\t\tFill 5G jug from fountain & 5 & 2 \\\\\n\t\tTop up 3G jug from 5G jug & 4 & 3 \\\\\n\t\t\\hline\n\t\t\\multicolumn{3}{|c|}{\\bfseries Weigh 5G jug} \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\n\t\\vspace{1em}\n\n\tNow - given the relationship to B\\'ezout's identity, can you find\n\tanother solution which involves filling the 3G jug from the fountain?\n\n\n\\end{proof}\n\n\\begin{question}\nWhat is the inverse of 10 modulo 17?\n\\end{question}\n\n\\begin{proof}[Answer]\n\tThe multiplicative inverse of $k \\pmod{n}$ in modular arithmetic is an integer which, when you\n\tmultiply it by $k$, gives a result of $1 \\pmod{n}$\n\n\tIn other words, we need to find a number $m$ such that:\n\t\\[ 10m + 17n = 1 \\]\n\n\tWe will use Euclid's algorithm to get the GCD of 10 and 17 (which is obviously 1):\n\t\\begin{align*}\n\t\t17 &= 10 + 7 & 7 &= 17 - 10 \\\\\n\t\t10 &= 7 + 3  & 3 &= 10 - 7 \\\\\n\t\t7 &= 2 \\times 3 + 1 & 1 &= 7 - 2 \\times 3 \\\\\n\t\t&& 1 &= 7 - 2 \\times (10 - 7) \\\\\n\t\t&& 1 &= 3 \\times 7 - 2 \\times 10 \\\\\n\t\t&& 1 &= 3 \\times (17 - 10) - 2 \\times 10 \\\\\n\t\t&& 1 &= 3 \\times 17 - 5 \\times 10 \\\\\n\t\\end{align*}\n\t\n\tWe have an identity, with a general term: \n\t\\[ 1  = (3 - 10k) \\times 17 + (17k-5) \\times 10 \\]\n\twith the smallest positive multiple of 10 which works being $k=1$, $17-5 = 12$\n\tAnd it's easy to verify that $1 = 12\\times10 - 7\\times17$.\n\\end{proof}\n\n\\begin{question}Find a solution in integers to the Diophantine equation $61x + 23y = 1$\\end{question}\n\\vspace*{\\bigskipamount}\n\n\\begin{question}Find a natural number $k$ such that $(573k+4)/719$ is also a natural\nnumber.\\end{question}\n\\vspace*{\\bigskipamount}\n\n\\begin{question}Find the smallest positive integer that ends in 2010, and is divisible by 2011.\\end{question}\n\\vspace*{\\bigskipamount}\n\n\n\\end{document}\n", "meta": {"hexsha": "7d5c5ebeb6588244e4ba3803e13785e3e533cd87", "size": 9324, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "euclids_algorithm.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": "euclids_algorithm.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": "euclids_algorithm.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": 35.4524714829, "max_line_length": 109, "alphanum_fraction": 0.6646289146, "num_tokens": 3258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.6686988775657594}}
{"text": "\\section{Residual error model}\n\\label{sec:residualErrorModel}\n\\label{maths:error_model}\n\\label{maths:combined-err-model}\n\nIn this section we consider different forms of the residual error, i.e. about $g$ in the term\n\\begin{eqnarray}\ng(x_{ij}, \\psi_{i}, \\xi) \\epsilon_{ij} \\nonumber\n\\end{eqnarray}\nof the eq.\\ref{eq:nlmeModel} with $\\epsilon_{ij} \\sim N(0, 1)$, i.e. a standardised random variable. \nThe residual errors are part of the \\textit{Observations Model}, see section \\ref{sec:eg1-obs-model} for detailed discussion. \nThe following table contains some of the models which can be implemented in \\pharmml:\n\n\\begin{table}[htdp]\n\\begin{center}\n\\begin{tabular}{l c c}\nModel name & $g$ & $\\xi$ \\\\\n\\hline \\hline \nConstant error model & $a$ & $a$ \\\\\nProportional error model & $bf$ & $b$ \\\\\nCombined error model & $a + bf$ & $a,b$ \\\\\nAlternative combined error model 1& $\\sqrt{a^2 + b^2f^2}$ & $a,b$ \\\\\nAlternative combined error model 2 & $a + bf^c$ & $a, b, c$ \n\\end{tabular}\n\\end{center}\n\\caption{Examples of residual error models which can be implemented in \\pharmml.}\n\\label{tab:residualModels}\n\\end{table}%\n\n\n\n\n", "meta": {"hexsha": "f6347346522fd3d7242a80e69383ace1290f7825", "size": 1117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "input/residualErrorModel_specSection.tex", "max_stars_repo_name": "pharmml/pharmml-spec", "max_stars_repo_head_hexsha": "b102aedd082e3114df26a072ba9fad2d1520e25f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-01-26T13:17:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-26T13:17:54.000Z", "max_issues_repo_path": "input/residualErrorModel_specSection.tex", "max_issues_repo_name": "pharmml/pharmml-spec", "max_issues_repo_head_hexsha": "b102aedd082e3114df26a072ba9fad2d1520e25f", "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": "input/residualErrorModel_specSection.tex", "max_forks_repo_name": "pharmml/pharmml-spec", "max_forks_repo_head_hexsha": "b102aedd082e3114df26a072ba9fad2d1520e25f", "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.8484848485, "max_line_length": 126, "alphanum_fraction": 0.7054610564, "num_tokens": 362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6686491605940837}}
{"text": "\n\\subsection{Metric tensors}\n\nA metric tensor assigns a bilinear form to each point on the manifold.\n\nWe can then take two vectors in the tangent space and return a scalar.\n\n", "meta": {"hexsha": "8abfe59f9dbc7cd7f96e85e7ebe7245efb493883", "size": 174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-01-tensor.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-01-tensor.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-01-tensor.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.75, "max_line_length": 70, "alphanum_fraction": 0.7816091954, "num_tokens": 37, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6686220877553533}}
{"text": "\n\n\n\\input{../preamble}\n\n\\renewcommand{\\thefootnote}{\\fnsymbol{footnote}}\n\n\\begin{document}\n\\title{Euler Characteristic of the Sphere}\n\\author{Apurva Nakade}\n\\maketitle\n\nA topological invariant assigns to a topological space, in our case a surface, an algebraic object such as a number, a polynomial or a vector space. If two surfaces have different topological invariants then they must be topologically inequivalent. (However the converse is not always true in that two inequivalent surfaces can have the same topological invariants.) The simplest non-trivial topological invariant is the Euler characteristic. The Euler characteristic assigns to each surface an integer and can be thought of as a way of quantifying shapes.\n\nEuler characteristic for surfaces is computed using graphs. We begin with the simplest surface, the sphere $ S ^ 2 $.\n\n\\begin{example}\n\tFor a polyhedron $P$ let $v,e,f$ denote the number of vertices, edges and faces respectively. When $P$ is a tetrahedron $v = 4, e=6, f=4$ and hence $v-e+f = 2$. When $P$ is a cube $v = 8, e=12, f=6$ and hence $v-e+f = 2$.\n\\end{example}\n\nWhat does the cube and the tetrahedron have in common? They can all be continuously deformed to the 2 dimensional sphere $ S^2 $.\n\n\n\n\\section{Planar graphs}\nWe'll start by computing the Euler characteristic of a planar graph. For us a graph $ G $ is a pair of finite sets $(V,E) $ where the vertices, $ V $, are distinct points in the standard plane $ \\R ^2 $ and the edges, $ E $, are segments connecting two vertices. We say that a graph is \\textbf{connected} if each vertex is connected to every other vertex via a sequence of edges. We say that a graph is \\textbf{planar} if no two edges intersect in a point outside the set of vertices.\n\n\nA planar graph divides the plane $ \\R ^ 2 $ into \\textbf{faces}. Denote the set of faces by $ F $.\\footnote{We won't include the unbounded face in $F$, for us all the faces are (possibly non-convex) polygons.} (It is possible for the set $ F $ to be empty.) The \\textbf{Euler characteristic} of a planar graph $ G $ is defined to be\n\\begin{align*}\n\t\\chi (G):= |V| - |E| + |F|\n\\end{align*}\nwhere $ |S| $ denotes the size of the set $ S $.\n\n\\begin{thm}\\label{thm:euler_characteristic_of_graphs}\n\tThe Euler characteristic of a connected planar graph is 1.\n\\end{thm}\n\nExercise \\ref{proof_of_euler's_thm} describes one proof of this theorem using induction on the number of faces. First we prove the theorem in the case when the graph has no faces.\n\nA \\emph{connected} graph $ G $ without any face, i.e. when $ F $ is an empty set  or equivalently $ |F| = 0 $, is called a \\textbf{tree}. (A graph with no faces but which is not necessarily connected is called a forest!) A vertex in a tree with only one edge attached to it is called a \\textbf{leaf}.\n\n\\begin{exercise}\n\tFor a tree $ G $ what is the relationship between $ |V| $ and $ |E| $? What is $ \\chi (G)$?\n\\end{exercise}\n\n\\begin{exercise}\\label{proof_of_euler's_thm}\n\tThe following is the proof of \\eqref{thm:euler_characteristic_of_graphs}\n\t\\begin{enumerate}\n\t\t\\item For a connected planar graph $ G $ with at least 1 face, show that it is possible to delete an edge and obtain a graph $ G' $ such that $G' $ has exactly one less face than $ G $.\n\t\t\\item What is the relationship between the Euler characteristic of $ G $ and $ G' $?\n\t\t\\item Induct on $ |F| $ to complete the proof of Theorem \\ref{thm:euler_characteristic_of_graphs}. (What is the base case for induction here?)\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tWhat is the Euler characteristic of a planar graph which is not necessarily connected?\n\\end{exercise}\n\n\n\n\n\n\n\\section{Euler characteristic of $ S ^ 2 $}\n\nA \\textbf{surface graph} on a sphere $ S ^ 2 $ is a \\emph{connected planar} graph $ G = (V,E) $ such that $ V $ and $ E $ are now on $ S ^ 2 $ and all the faces are \\textbf{polygons}. The tetrahedron, the cube, and the octahedron, provide examples of such surface graphs. A surface graph is called a \\textbf{triangulation} if all the faces are triangles.\n\n\\begin{thm}\\label{thm:euler_characteristic_of_sphere}\n\tThe Euler characteristic of any surface graph $G$\ton $ S ^ 2 $ is 2. Hence we can define the Euler characteristic of $ S^2 $ as $\\chi(S^2):= \\chi(G)$ and we have, $$ \\chi(S ^ 2) = 2 $$\n\\end{thm}\n\n\n\\begin{exercise}\n\tTheorem \\ref{thm:euler_characteristic_of_sphere} follows directly from Theorem \\ref{thm:euler_characteristic_of_graphs} for planar graphs,\n\t\\begin{enumerate}\n\t\t\\item Explain how a surface graph on $ S ^ 2 $ gives rise to a planar graph on $ \\R ^ 2 $.\n\t\t\\item Draw the planar graphs for the cube, the tetrahedron and the octahedron.\n\t\t\\item Show that the Euler characteristic of a graph on $ S ^ 2 $ is 2.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\section{Brussel Sprouts}\nThe game of \\textbf{Brussel Sprouts} starts with 2 crosses. Each move involves joining two free ends with a curve not crossing any existing line and then putting a short stroke across the line to create two new free ends. The game ends when no such move is possible.\n\\begin{center}\n\t\\begin{tabular}{c}\n\t\t{\\includegraphics[width=5cm, height=5cm] {images/brussel_sprouts}} \\\\\n\t\tA game of Brussel Sprouts                                          \\\\\\\\\n\t\\end{tabular}\n\\end{center}\n\n\\begin{exercise}\n\tPlay a few games of Brussel Sprouts!\n\\end{exercise}\n\nIt turns out that every game of Brussel Sprouts always ends in the same number of steps! The following exercises describe a proof of it,\n\n\\begin{exercise}Let $G$ be the connected planar graph (vertices are the crosses) at the end of the game.\n\t\\begin{enumerate}\n\t\t\\item What happens to the number of free ends after each move? How many free ends are there in the end?\n\t\t\\item Argue that at each stage of the game every face should have at least one open end on it's boundary. Further, argue that there cannot be two or more open ends on the boundary of a face at the end of the game. Hence every face of $G$ should have exactly 1 open end on it's boundary. The same is true for the \\textit{unbounded face}.\n\t\t\\item Conclude that $G$ has 7 faces.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tAssume that the game ends in $ \\mathbf{n} $ steps.\n\t\\begin{enumerate}\n\t\t\\item How many vertices and edges are added after each move? Argue that $ |E| = 2n $ and $ |V| = 2 + n $.\n\t\t\\item Use Theorem \\ref{thm:euler_characteristic_of_graphs} to find $ n $.\n\t\\end{enumerate}\n\\end{exercise}\nCan you generalize the above proof to $k$ crosses in the beginning? How about playing Brussel Sprouts on a Torus?\n\n\\iffalse\\subsection{Platonic Solids}\nA platonic solid is a convex polyhedron all of whose faces are regular polygons which are congruent to each other, i.e. all the edges have the same length and all the faces have the same number of sides. We'll assume that the word convex means that the platonic solid is topologically equivalent to $S^2$. We've seen 3 platonic solids earlier, the cube, the tetrahedron, and the octahedron. There are exactly two more,\n\n\\begin{center}\\begin{tabular}{c c}\n\t%\\includegraphics[width=3cm, height=3cm]{icosahedron} & %\\includegraphics[width=3cm, height=3cm]{dodecahedron} \\\\\n\ticosahedron & dodecahedron \\\\\\\\\n\t\\end{tabular}\n\\end{center}\n\nWe can use the Euler characteristic to prove that these 5 are the only ones possible.\n\nConsider a platonic solid $ S $ and think of it as the graph $(V,E,F)$. Suppose all the faces of $ S $ are polygons with $ \\mathbf{n} $ number of edges. Further suppose that $ \\mathbf{p} $ edges of $S $ intersect at a single vertex.\n\n\\begin{exercise}\n\tArgue that both $ n $ and $ p $ should be at least 3. What are $ n$ and $ p $ for the five platonic solids?\n\\end{exercise}\n\n\\begin{exercise}\\leavevmode\n\t\\begin{enumerate}\n\t\t\\item By counting the total number of edges cleverly, show that $ p |V| = 2 |E| $ and $ n |F| = 2|E| $.\n\t\t\\item Use Theorem \\ref{thm:euler_characteristic_of_sphere} to conclude\n\t\t      \\begin{align}\\label{eq:platonic_solid}\n\t\t      \t\\dfrac{1}{n} - \\dfrac{1}{2} + \\dfrac{1}{p} = \\dfrac{1}{|E|}\n\t\t      \\end{align}\n\t\t      and because $ |E| > 0 $ this implies $ \\frac{1}{n} + \\frac{1}{p} >  \\frac{1}{2}$.\n\t\t\\item Show that the above inequality cannot hold if $ n $ and $ p $ are both bigger than 4. Now we have that both $n$ and $p$ are at least 3 and one of them is at the most 4.\n\t\t\\item Find (by trial and error) the possible values of $ n, p, |E| $ that satisfy (\\ref{eq:platonic_solid}) and relate them to the 5 platonic solids.\n\t\\end{enumerate}\n\\end{exercise}\n\\fi\n\n\n\\end{document}\n", "meta": {"hexsha": "5552e3da4581311d0e3736f13f0ddd5aa997ce22", "size": 8481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02 Euler Characteristic/01 Euler's theorem for a plane.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": "02 Euler Characteristic/01 Euler's theorem for a plane.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": "02 Euler Characteristic/01 Euler's theorem for a plane.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": 57.3040540541, "max_line_length": 556, "alphanum_fraction": 0.7229100342, "num_tokens": 2463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.9304582501911272, "lm_q1q2_score": 0.6686220811086347}}
{"text": "\\documentclass[bnt.tex]{subfile}\n\n\\begin{document}\n\t\\section{Congruence}\n\t\tWe may call congruence (also known as \\textit{modular arithmetic}) the dual of divisibility. It was first introduced and highly\n\t\tused by \\textit{Carl Fredrich Gauss}.\n\t\t\t\\begin{definition}\n\t\t\t\tIf two integers $a$ and $b$ leave the same remainder upon division by $n$, then $a$ and $b$ are said to be \\textit{congruent modulo} $n$. In other words, $a$ leaves remainder $b$ (not necessarily minimum or absolute minimum) upon division by $n$.\n\t\t\t\\end{definition}\n\t\t\t\n\t\t\t\\begin{example}\n\t\t\t\tSince $14$ and $62$ leaves the same remainder $6$ upon division by $8$, we say that $14$ and $62$ are congruent modulo $8$. We denote it by $14\\equiv62\\pmod8$ and say $14$ is congruent to $62$ modulo $8$. Likewise, $11\\equiv4\\pmod7$. Note that these remainders can be negative. So, we can also take\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t11 & \\equiv-1\\pmod6\n\t\t\t\t\t\\end{align*}\n\t\t\t\\end{example}\n\t\tThe set $\\mathbb{Z}_n=\\{0,1,2,\\ldots,n-1\\}$ (the set of integers modulo $n$) is called the \\textit{complete set of residue class modulo} $n$. However, we mostly consider the set $Z_n-\\{0\\}$. This is called a complete set of residue class modulo $n$ because any integer gives a remainder upon division by $n$ which is an element of this set. Also, it is obvious that every integer gives a unique remainder upon division by $n$ which belongs to this set. This actually follows from $\\#10$ of divisibility.\n\t\t\t\\begin{definition}\n\t\t\t\t$P(x)$ is a polynomial a sum of some powers of $x$ (obviously finite). That is,\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\tP(x) & = a_nx^n+\\cdots+a_1x+a_0\n\t\t\t\t\t\\end{align*}\n\t\t\t\tThe highest power of a polynomial is called \\textit{degree} which is $n$ in this case.\n\t\t\t\\end{definition}\n\t\tThe following proposition discusses some of the basics of modular arithmetic.\n\t\t\t\\begin{proposition}\n\t\t\t\tWe let $a,b,k,n$ be positive integers.\n\t\t\t\t\t\\begin{enumerate}[(1)]\n\t\t\t\t\t\t\\item $a\\equiv b\\pmod n\\iff n|a-b$. This is straightforward from the definition.\n\t\t\t\t\t\t\\item $a\\equiv a\\pmod n$ (reflexive property).\n\t\t\t\t\t\t\\item If $a\\equiv b\\pmod n$ then $b\\equiv a\\pmod n$ (symmetric property) and vice versa.\n\t\t\t\t\t\t\\item If $a\\equiv b\\pmod n$ and $b\\equiv c\\pmod n$ then $a\\equiv c\\pmod n$ (transitive property).\n\t\t\t\t\t\t\\item If $a\\equiv b\\pmod n$ then $a+nk\\equiv b\\pmod n$ holds as well.\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\\end{proposition}\n\t\t\t\n\t\t\t\\begin{proposition}[Operations in congruence]\n\t\t\t\tAssume that $a,b,c,d$ are positive integers. Moreover $a\\equiv b\\pmod n$ and $c\\equiv d\\pmod n$. Then\n\t\t\t\t\t\\begin{enumerate}[(1)]\n\t\t\t\t\t\t\\item $a+b\\equiv c+d\\pmod n$.\n\t\t\t\t\t\t\\item $a-b\\equiv c-d\\pmod n$.\n\t\t\t\t\t\t\\item $ac\\equiv bd\\pmod n$.\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\\end{proposition}\n\t\tProving them is easy. From $a\\equiv b\\pmod n$, we can say $a=b+nk$ for some integer $k$. Similarly, $c=d+nl$ for some integer $l$. Now,\n\t\t\t\\begin{align*}\n\t\t\t\ta+b & = c+d+n(k+l)\\\\\n\t\t\t\t\t& \\equiv c+d\\pmod n\n\t\t\t\\end{align*}\n\t\tThe ones described in the previous proposition or the other ones in this proposition can be proved in the same way. We have a corollary.\n\t\t\t\\begin{align*}\n\t\t\t\tac & \\equiv bc\\pmod n\n\t\t\t\\end{align*}\n\t\tYou can see, congruence is keeping up with equations so far. So you may want to conjecture that if $ac\\equiv bc\\pmod n$ then $a\\equiv b\\pmod n$. However, is that correct? Take some examples. See if all of them are consistent with this statement.\n\\end{document}", "meta": {"hexsha": "bc139da0cc3fa6cb30ae3c8fee560b50e1b22420", "size": 3391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mod.tex", "max_stars_repo_name": "fifaboy/bnt", "max_stars_repo_head_hexsha": "9a150151c485936e37fe5852aa8d2703d5c87b29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mod.tex", "max_issues_repo_name": "fifaboy/bnt", "max_issues_repo_head_hexsha": "9a150151c485936e37fe5852aa8d2703d5c87b29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mod.tex", "max_forks_repo_name": "fifaboy/bnt", "max_forks_repo_head_hexsha": "9a150151c485936e37fe5852aa8d2703d5c87b29", "max_forks_repo_licenses": ["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.6545454545, "max_line_length": 505, "alphanum_fraction": 0.6823945739, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6685771847494043}}
{"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. A NHPP is when the rate function for a Poisson process is dependent on time. This process 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 if $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}\nFurthermore the definition of a NHPP is as given below.\n\\begin{defn} % S 277\nA counting 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 means that 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. $N(t)$ is Poisson distributed with parameter\n\\begin{equation}\n\\Lambda(t) = \\int_{0}^{t} \\lambda(u) du. \n\\label{eq:largelambda}\n\\end{equation}\nFrom the NHPP the number of failures are given by,\n\\begin{equation}\nP(N(t) = n) = \\frac{\\Lambda(t)^n}{n!}e^{-\\Lambda(t)} \\quad n=0,1,2,... \\quad 0\\leq t \\leq \\tau.\n\\label{eq:NumNHPP}\n\\end{equation}\nTo generate data the desired number of data points can be picked. This means that the parameters of the NHPP must be chosen to fulfill the desired number of data points. From a NHPP we have that the expected number of events within a time $\\tau$ is $\\Lambda(\\tau)$. Since we have assumed that time runs are between 0 and $\\tau$, the expected number of events is\n\\begin{equation*}\nE[events] = \\Lambda(\\tau).\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. These determine the shape of the function. The parameter $a$ is just for scaling the expected number of events. By testing for different parameters we have chosen six shapes of the rate function to be used. The parameter $a$ is then chosen so that the expected number of events is around 30. This is our desired expected number of events. The resulting 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 a gamma density \\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": "df99cda3acd0d17e4f01892faf5bdea5e6e2f77d", "size": 4335, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "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/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/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": 77.4107142857, "max_line_length": 935, "alphanum_fraction": 0.7296424452, "num_tokens": 1415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.668577184310249}}
{"text": "\\subsection{Classical DNN}\nFirst, we have a more comprehensive notation for classical DNN models.\n\\begin{equation}\\label{eq:DNNdef_J}\n\\begin{aligned}\n{\\rm{DNN}_J} :=\\{& f:f=\n\\theta^J \\circ \\sigma \\circ \\theta^{J-1} \\cdots \\sigma \\circ \\theta^0(x), \\\\\n&\\theta^\\ell \\in \\mathbb{R}^{n^{\\ell+1} \\times (n^\\ell+1)}, \\quad n^0 = d, \\quad n^{J+1} = 1, \\quad n^\\ell \\in \\mathbb{N}^+\\}.\n\\end{aligned}\n\\end{equation}\n\nThus to say, we have the general two definition for DNN with\n\\begin{itemize}\n\\item  $\\sigma \\circ \\theta$ type:\n\\begin{equation}\\label{eq:sigma+theta}\n\\begin{aligned}\nf^0 &= x, \\\\\nf^{i+1} &= \\sigma \\circ \\theta^{i}(f^i), \\\\\n{\\rm DNN}_J &= \\{\\theta^J(f^J)\\}.\n\\end{aligned}\n\\end{equation}\n\n\\item $\\theta \\circ \\sigma $ type:\n\\begin{equation}\\label{eq:theta+sigma}\n\\begin{aligned}\nf^0 &= \\theta^0(x), \\\\\nf^{i+1} &=  \\theta^{i+1} \\circ \\sigma (f^i), \\\\\n{\\rm DNN}_J &= \\{f^J\\}.\n\\end{aligned}\n\\end{equation}\n\\end{itemize}\n\n\\subsection{DNN type ResNet}\nFor simplicity, we choose $\\sigma \\circ \\theta$ type as example.\n\n\\paragraph{ResNet}\nThe ResNet can be written as\n\\begin{equation}\\label{ori-ResNet-dnn}\n\\begin{cases}\nf^0 &= x, \\\\\nf^{i} &= \\sigma \\left( P^i f^{i-1} + \\mathcal{F}^{ i} (f^{i-1}) \\right), \\quad i = 1:J ,\\\\\n{\\rm ResNet}_{J} &= \\{  \\theta^J f^{J} \\}.\n\\end{cases}\n\\end{equation}\nHere\n\\begin{equation}\\label{eq:F-ResNet}\n\\mathcal{F}^{i} (f^{i-1}) = \\xi^{i} \\circ \\sigma \\circ \\eta^{i} (f^{i-1}),\n\\end{equation}\nmeans ResNet with skip connection distant 2. And $P^i$ is use to fit the dimension as\n\\begin{equation}\\label{eq:P^i}\nP^i: \\mathbb{R}^{n_{i-1}} \\mapsto \\mathbb{R}^{n_i}.\n\\end{equation}\n\n\\paragraph{iResNet} \nThe iResNet can be written as:\n\\begin{equation}\\label{ori-iResNet-dnn}\n\\begin{cases}\nf^0 &= x, \\\\\nf^{i} &=  P^i f^{i-1} + \\mathcal{F}^{ i} (f^{i-1}) , \\quad i = 1:J ,\\\\\n{\\rm iResNet}_{J} &= \\{  \\theta^J f^{J} \\}.\n\\end{cases}\n\\end{equation}\nHere\n\\begin{equation}\\label{eq:F-iResNet}\n\\mathcal{F}^{i} (f^{i-1}) = \\xi^{i} \\circ \\sigma \\circ \\eta^{i}  \\circ \\sigma (f^{i-1}),\n\\end{equation}\nmeans iResNet with skip connection distant 2. \nAnd $P^i$ is use to fit the dimension as in ResNet in \\eqref{eq:P^i}.\n\nThe only difference between ResNet and iResNet can be viewed as \nputting a $\\sigma$ in different places. \n\nAnd we also need to notice that ${\\rm ResNet}_J$ or  ${\\rm iResNet}_J$\nare often called DNN with $2J$-th layers if the distance of skip connection\nis $2$ as in \\eqref{eq:F-ResNet} and \\eqref{eq:F-iResNet}.\n\n\\subsection{DNN type MgNet}\nSimilar with ResNet, we can rewrite MgNet.\n\nHere use $\\theta \\circ \\sigma$ type as example.\n\\begin{equation}\\label{ori-MgNetNet-dnn}\n\\begin{cases}\nf^0 &= 0, \\quad f^0 = \\theta^0(x) \\\\\nf^{i} &=  P^i f^{i-1} + \\mathcal{F}^{ i} (f^{i-1}) , \\quad i = 1:J ,\\\\\n{\\rm iResNet}_{J} &= \\{  f^{J} \\}.\n\\end{cases}\n\\end{equation}\nHere\n\\begin{equation}\\label{eq:F-MgNet}\n\\mathcal{F}^{i} (f^{i-1}) = \\xi^{i} \\left( f^{i-1} +  \\sigma \\circ \\eta^{i} \\circ \\sigma(f^{i-1}) \\right).\n\\end{equation}\n\n\\subsection{DNN type DenseNet}\nIn fact, DenseNet might be simple for definition in DNN case. \n\nHere use $\\sigma \\circ \\theta$ type as example.\n\\begin{equation}\\label{ori-DenseNet-dnn}\n\\begin{cases}\nf^0 &= x, \\\\\nf^{i} &=   \\sigma \\circ \\theta^{i}([f^{i-1}, f^{i-2}, \\cdots, f^0]) , \\quad i = 1:J ,\\\\\n{\\rm DenseNet}_{J} &= \\{  \\theta^J f^{J} \\}.\n\\end{cases}\n\\end{equation}\n\nHere $[f^{i-1}, f^{i-2}, \\cdots, f^0]$ means a long vector by collecting all \noutputs from $f^0$ to $f^{i-1}$, thus to say\n$$\n{\\rm dim}([f^{i-1}, f^{i-2}, \\cdots, f^0]) = \\sum_{i=0}^{i-1} n_i.\n$$\n\n\n\\section{A Universal DNN Model}\n\n\\subsection{Kailai's definition}\nA DNN is defined as a tuple $M=(\\mathcal{S}, \\mathcal{O}, s_0, F, \\delta)$\n\\begin{itemize}\n\t\\item $\\mathcal{S}$ is a non-empty set of states.\n\t\\item $\\mathcal{O}$ is a finite, non-empty set of parametrized operators.\n\t\\item $s_0\\in \\mathcal{S}$ is the initial input. \n\t\\item $F\\subset \\mathcal{S}$ is the set of final states~(outputs). \n\t\\item $\\delta: 2^{\\mathcal{S}}\\times \\mathcal{O} \\rightarrow \\mathcal{S}$ is the mapping function. \n\\end{itemize}\nand an acceptable ordered sequence $(\\delta_1, \\delta_2, \\ldots, \\delta_n)$, which maps $s_0$ to $\\delta_n \\circ \\delta_{n-1} \\circ \\delta_1 (s_0) \\in F$.\n\n\\subsection{Juncai's definition}\nThe idea is that, deep neural network comes from the composition of linear and \nelement-wise activation. \nSo, we define the basic component of our model as:\n\\begin{equation}\n\\mathcal L_{\\sigma,1}(x) = Wx + b + \\sigma(\\tilde Wx + \\tilde b),\n\\end{equation}\nwhere \n\\begin{equation}\nx \\in \\mathbb{R}^d, \\quad W, ~ \\tilde W \\in \\mathbb{R}^{n \\times d} \\quad \\text{and} \\quad b,~ \\tilde b \\in \\mathbb{R}^n.\n\\end{equation}\nThen we try to define an important operator in the universal DNN model,\nknown as $\\mathcal L_{\\sigma, \\ell}(x^1, \\cdots, x^k)$, by recursion of $\\mathcal L_{\\sigma,1}$. \nFor $x^i \\in \\mathbb{R}^{n_i}, i = 1:\\ell$,  we have\n\\begin{equation}\n\\mathcal L_{\\sigma, \\ell}(x^1, \\cdots, x^k) = \\mathcal L_{\\sigma,1}\n\\left([\\mathcal L_{\\sigma, \\ell-1}(\\hat x^1), \\mathcal L_{\\sigma, \\ell-1}(\\hat x^2), \\cdots, \\mathcal L_{\\sigma, \\ell-1}(\\hat x^k)]\\right),\n\\end{equation}\nwhere\n\\begin{equation}\n\\mathcal L_{\\sigma, \\ell-1}(\\hat x^k) = \\mathcal L_{\\sigma, \\ell-1} (x^1, \\cdots, x^{k-1}, x^{k+1}, \\cdots, x^\\ell),\n\\end{equation}\nand \n\\begin{equation}\n[\\mathcal L_{\\sigma, \\ell-1}(\\hat x^1), \\mathcal L_{\\sigma, \\ell-1}(\\hat x^2), \\cdots, \\mathcal L_{\\sigma, \\ell-1}(\\hat x^k)],\n\\end{equation}\nmeans to collect all the output of $\\mathcal L_{\\sigma, \\ell-1}(\\hat x^k)$ into one vector such \nthat it can be the input of $\\mathcal L_{\\sigma, 1}$.\n\nThen we define the $J-$layer universal DNN model by recursion as:\n\\begin{equation}\n\\begin{cases}\nf^{0} &= x,  \\\\\nf^{\\ell} &= \\mathcal L_{\\sigma, \\ell}(f^0,\\cdots, f^{\\ell-1}), \\quad \\ell = 1:J, \\\\\nf(x) &= W^J f^J + b^J. \n\\end{cases}\n\\end{equation}\n\n\n", "meta": {"hexsha": "9e7b43551c1965293e80998ab0e5d5a39fa79894", "size": 5835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/juncai_dnn.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/juncai_dnn.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/juncai_dnn.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": 35.7975460123, "max_line_length": 154, "alphanum_fraction": 0.6358183376, "num_tokens": 2350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740728, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6685764841467899}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage{amssymb}\r\n\\usepackage{eqnarray}\r\n\\usepackage[utf8]{inputenc}\r\n\r\n\\setlength{\\parindent}{0pt}\r\n\\setlength{\\parskip}{1em}\r\n\r\n\\newcommand{\\K}{\\mathbb{K}}\r\n\\newcommand{\\N}{\\mathbb{N}}\r\n\\newcommand{\\Z}{\\mathbb{Z}}\r\n\\newcommand{\\R}{\\mathbb{R}}\r\n\\newcommand{\\C}{\\mathbb{C}}\r\n\\newcommand{\\Q}{\\mathbb{Q}}\r\n\\newcommand{\\F}{\\mathcal{F}}\r\n\\newcommand{\\G}{\\mathcal{G}}\r\n\r\n\\begin{document}\r\n\r\n\\section{Polynomials}\r\n\r\n\\textbf{Definition 1.}  Polynomial function $P \\colon \\mathbb{R} \\to \\mathbb{R}$ can be presented in the form of\r\n$$P(x)=a_nx^n+a_{n-1}x^{n-1}+\\dots+a_1x+a_0$$\r\nwhere $a_0,\\dots,a_n$ are real numbers called the polynomial coefficients. Largest $n$ for which $a_n\\ne 0$ is called the degree of polynomial.\r\n\r\n\r\n\\textbf{Theorem 2 (Bezout's theorem).}\r\nA polynomial $P(x)$ is divisible by the binomial $(x-a)$ if and only if $P(a)=0$.\r\n\r\n\\textbf{Theorem 3 (The fundamental theorem of algebra).}\r\nEvery non-constant polynomial has a complex root.\r\n\r\n\\textbf{Theorem 4 (The rational root theorem).} If $x = p/q$ is a rational zero\r\nof a polynomial $P(x) = a_nx^n +\\hdots +a_0$ with integer coefficients and $(p, q)=1$,\r\nthen $p | a_0$ and $q | a_n$.\r\n\r\n\\textbf{Theorem 5 (Vieta's formulae).} If the solutions polynomial of degree $n$ are $x_1,x_2,\\dots,x_n$ and  $a_n=1$, then the following holds:\r\n\\begin{eqnarray*}\r\nx_1+x_2+\\ldots+x_n &=& -a_{n-1},\\\\\r\nx_1x_2+x_1x_3+\\ldots+x_{n-1}x_{n} &=& \\hphantom{-} a_{n-2}, \\\\\r\nx_1x_2x_3+x_1x_2x_4+\\ldots+x_{n-2}x_{n-1}x_n &=& -a_{n-3},\\\\\r\n\\ldots \\\\\r\nx_1x_2\\ldots x_n &=& (-1)^n a_0.\r\n\\end{eqnarray*}\r\n\r\n\\begin{enumerate}\r\n\r\n\\item\r\nFind the roots of polynomial $P(x)=x^5-x^4-13x^3+x^2+12x$.\r\n\r\n\\item % Talvine lahtine võistlus 2010, noorem rühm\r\nFind the value of $x^5+2x^2-4x+2010$ given that $x^3+2x+2=0$.\r\n\r\n\\item\r\nHow many points do we need to uniquely define a polynomial of degree $n$?\r\n\r\n\\item\r\nThe roots for polynomial $P_2(x)=ax^2+bx+c$ are $x_1$ and $x_2$. Find the coefficients for third order polynomial which has roots $x_1^2$, $x_2^2$ and $x_1x_2$.\r\n\r\n\\item % PSS 24\r\nIn $x^3+px^2+qx+r$ one root is the sum of the two others. Find the relationship between $p$, $q$ and $r$. \r\n\r\n\\item % http://eqworld.ipmnet.ru/en/solutions/ae/ae0106.pdf\r\nFind the roots of the polynomial $P(x)=ax^4+bx^3+cx^2+bx+a$\r\n\r\n\r\n\\item %PSS 31\r\nPolynomial with integer coefficients $ax^3+bx^2+cx+d$ has $ad$ odd and $bc$ even. Show that at least one zero of the polynomial is irrational.\r\n\r\n\\item % PRoblem solving strategies 72\r\nPolynomial of degree $n$ with non-negative coefficients and leading coefficient $1$ and constant term $1$ has $n$ real roots. Prove that $P(2)\\geq 3^n$.\r\n\r\n\r\n\\end{enumerate}\r\n\r\n\\end{document}", "meta": {"hexsha": "c93e18b6a861b7bcfb7dad43b7b25c4d4630d6da", "size": 2706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03_polynomials.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": "03_polynomials.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": "03_polynomials.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": 35.1428571429, "max_line_length": 161, "alphanum_fraction": 0.6777531412, "num_tokens": 1018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6685764773103664}}
{"text": "\\lab{Python}{Generators}{Generators}\n\\label{lab:Python_Generators}\n\nLists, tuples, sets, and dictionaries are examples of sequences in Python.\nOften it is useful to visit all the elements of a sequence.  This process of visiting\neach element of a sequence once is called \\emph{iteration}. \nEach of the Python types we have mentioned define their own iterators.\nYou use them every time you execute the statement \\li{for <elem> in <list>}.\nPython has a special type of object called a \\emph{generator}.\nSimilar to an iterator, a generator returns a sequence of values.\nThe important difference is that a generator computes the next value in the sequence and returns it.\nIt never has to store all of the values in the sequence.\nA good way to think of this is to remember: \\emph{Iterators return their values while generators yield their values}.\nIn fact, Python uses the \\li{yield} keyword to define a generator.\nLet's illustrate the difference between iterating and generating by re-implementing Python's \\li{range} function\nas both an iterator and a generator.\n\\begin{lstlisting}\ndef range_iter(start, stop, step=1):\n    i = start\n    r = []\n    while i < stop:\n       r.append(i)\n       i = i + step\n    return r\n\\end{lstlisting}\n\\begin{lstlisting}\ndef range_gen(start, stop, step=1):\n    i = start\n    while i < stop:\n        yield i\n        i = i + step\n\\end{lstlisting}\nThe two functions look very similar.  But, you will soon see that they behave very differently.\nThe first function, when executed will immediately build a list, one element at a time until the done\nat which point it returns the entire list.  On the author's computer, this function takes about 1.43ms\nto build and return a list of 10000 elements.  The second function is only marginally better at\nreturning the 10000 elements in approximately 1.09ms.  \nThis gap between the two functions grows much wider as the inputs are increased.\nWhere the real difference in the two functions lies is in the time the function takes to execute when\nit is first called.  The first function requires 1.43ms to execute the first time.  The second function,\na mere .00000041ms!  The reason for this is the first function calculates its results and returns them all at once.  The second function only creates a \\emph{generator} object.  This object has several methods.\nThe most important and most useful method is the \\li{next()} method.  Every time this method is called, \nthe generator resumes from its previous state and computes the next value in the sequence. Each time \\li{yield} statement is executed, the generator is effectively suspended until \\li{next()} is called again.\nWhen the generator has finished executing, a \\li{StopIteration} exception is raised the generator terminates.\nYou can send values and throw exceptions to the generators via the \\li{send()} and \\li{throw()} methods respectively.\nFor more information on these methods we refer to PEP 342 (Python Enhancement Proposal 342).\n\nWhen you are writing \\li{for} loops, you should be sure to use a generator whenever it is reasonable to do so.\nThe \\li{xrange()} function that is built into Python is a generator based version of \\li{range()} and is generally faster when used in \\li{for} loops.\n\nWhen are generators helpful? If you encounter the situations below, consider trying to solve \nyour problem using generators.  Generators have proven to be very useful in these situations.\n\\begin{itemize}\n\\item \\emph{Iterating through only part of a sequence.}\nIt is inefficient to create an entire sequence if we know that we will not need all of it.\nRepresenting the sequence as a generator could possibly avoid excess memory use and excess computation.\n\\item \\emph{Iterating through a sequence once.} Consider the statement \n\\li{sum([i for i in range(1000) if i\\%2 == 0])}.\nWe are creating two sequences just to iterate through them once and never use them again.\nWe can make this more efficient using generators.\n\\li{sum(i for i in xrange(1000) if i\\%2 == 0)}\nNotice that we have used syntax similar to a list comprehension.\nThe line \\li{(i for i in xrange(1000) if i\\%2 == 0)} will define a generator object similar to the list made by \\li{[i for i in xrange(1000) if i\\%2 == 0]}.\nThe solution using generators will often execute faster, but it will almost always be more memory efficient.  Consider using generators for any function that reduces a sequence to a single value.  Examples of such functions are \\li{min()}, \\li{max()}, and \\li{sum()}.\n\\item \\emph{Calculating large sequences.}  The sequence must be stored somewhere in computer memory.\nIf the sequence is large, we could exhaust all available memory.\n\\item \\emph{Calculations involving infinite sequences.}  Pre-computed sequences are necessarily finite.  We cannot create a list that stores all natural numbers, but we can create a generator that returns the next natural number every time it is called.\n\\end{itemize}\n\n\n\\section*{Combinations}\nCombinations are subsets of a set.  The power set of a set, $S$, is the set of all combinations\nof elements in $S$.  The cardinality of the the power set is $2^{\\abs{S}}$.  Clearly, if our\nset is of any appreciable size, the power set will be much larger.  Let's look at one method for\ngenerating the power set of a set.\n\nWe can generate the power set of a set by representing each element in a set by one bit.\nIf a bit is 0, then we do not include the element in the current combination.  If a\nbit is 1, the element is included in the combination.\nUsing this representation we can count through the power set of any finite set $A$, by counting from 0 to $2^{\\abs{A}}-1$, looking at the binary representation of the number, and then including or excluding elements based on the value of each bit.\n\n\\begin{problem}\nWrite a function that will accept a list and return a list of all the combinations\nof elements of that list.\n\\end{problem}\n\nThis is, however, an inefficient way to generate combinations.  Ideally, we would want\nto generate the next combination by modifying the previous combination.  However, with\nour current method of counting in binary, we are rebuilding the combination from scratch\neach time.  For example it we have a combination represented by \\texttt{01111}, the next\ncombination would be \\texttt{10000}.  We added one element and removed four elements!\nIt can be useful to get our next combination by changing the previous combination as little as possible.\nFortunately, there is a really neat way of doing this--reflected binary codes or Gray codes. \nA Gray code is a sequence of binary numbers where each new number is generated by\nchanging the previous code by exactly one bit.  Geometrically, we can think of it as\ntraversing a unit cube by moving only along the edges of the cube.\nGrey codes are used frequently in error correction schemes.\n\nA Gray code is constructed as follows.\n\\footnote{Brualdi, Richard Brualdi. \\emph{Introductory Combinatorics}. New Jersey: Pearson, 2009}\nThe Gray code of order $n$ can be calculated using recursion in the following way:\n\\begin{enumerate}\n\\item The Gray code of order 1 is 0, 1.\n\\item Compute the Gray code of order $n-1$.  Write the binary numbers in a new list and then write them again in reverse order on the end of the same list (reflect them so that the last Gray code or order $n-1$ is first and the first Gray code of order $n-1$ is last).\n\\item Prepend a 0 to the first half of the list and prepend a 1 to the remaining half of the list.\n\\end{enumerate}\nWhile this is a simple algorithm to describe, it is not very efficient.  \nTo generate a Gray code of order $n$, we have to generate all previous Gray codes.\nIf we were to calculate the Gray codes up to order 6, we would calculate the Gray code of order 6 once, order 5 twice, order 4 three times, order 3 four times, and order 2 five times!\nFortunately, there exists another way to compute Gray codes of order $n$ much more efficiently.\nThe algorithm is given in Brualdi's book.  \nWe first note that a Gray code of order $n$ is of length $2^n$ with each code of length $n$.\nWe also observe that the reflected gray codes always begin with $0\\dots0$ and terminate with $10\\dots0$.\n\\begin{enumerate}\n\\item Start with $0\\dots0$ ($n$ zeros).  This is the current binary number.\n\\item Sum the digits of the current binary number.\n\\begin{enumerate}\n\\item If the sum of the digits is even, add 1 to the last digit mod 2.\nThis becomes our new current Gray and we go back to step 1.\n\\item If the sum of the digits is odd, find the rightmost non-zero digit and add 1 to the digit immediately to the left of it.\nThis becomes our new current number and we go back to step 1.\n\\item If the rightmost non-zero digit of the number is the first one you have reached the end of the Gray code.\n\\end{enumerate}\n\\end{enumerate}\n\n\\begin{problem}\n\\label{prob:brualdi_gray}\nImplement the algorithm above for calculating the Gray code of order $n$.\nYour implementation must function as a generator.\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:changed_elem_gray}\nGray codes are an ordering of the power set such that any consecutive subsets differ by exactly one element.  Write a generator that will only return the change required to arrive at the next subset in the ordering.  Each time the generator is called, \nit should return a single element and a boolean value that determines if that element should be\nadded or removed from the set to obtain the next Gray code.  This function should be able to accept any set with arbitrary elements.\n\\end{problem}\n\n\\section*{Itertools}\nThere is a very powerful library in the Python Standard Library that is built around the concept\nof generators and iterators.  The functions in \\li{itertools} are designed to be used as\nbuilding blocks in larger functions.  These functions are fast and memory efficient.\nWe encourage you to view the documentation for \\li{itertools} on the Python website.  Itertools has a much more general and much faster solution for generating combinations and permutations of a set.\nThe generator that we have written as a solution to \\ref{prob:changed_elem_gray} is especially useful when we are interested in the changed elements between successive subsets, or when we want to continuously update a single data structure using the elements of a Gray code.\nThe benefits of such an approach would be particularly apparent in cases where it is costly to add or remove items from the data sructure.\nThe documentation for \\li{itertools} also includes various recipes for other useful generator functions.\nFeel free to look through the documentation \\url{http://docs.python.org/2/library/itertools.html}.\n\n\\begin{problem}\n\\label{prob:subblocks}\nWrite a generator function that will evenly split a 1-dimensional array into sub-blocks.\nYour function should be capable of returning sub-blocks that could possibly overlap.\nThe function should accept as arguments: a 1-dimensional array, a block width, and an optional offset.\nIf the array cannot be evenly divided into sub-blocks, raise an error.\nFor example, if I want to divide an array\\li{X} with 9 elements into subblocks of 3 elements with a step of 2 between each block, my generator would return the values \\li{X[0:3]}, \\li{X[2:5]}, \\li{X[4:7]}, and \\li{X[6:9]}.\nIt would raise an error if I were to ask for that sort of stepping on an array with 10 entries since the last item could not be included in any subblock.\n\\end{problem}\n\n\\begin{problem}\nExpand your solution to Problem \\ref{prob:subblocks} to work with 2-dimensional\narrays.  You may implement them as separate functions if you wish.\n\\end{problem}\n", "meta": {"hexsha": "87ed789ee8217ba66483f126366a9093270ba109", "size": 11568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/Generators/Generators.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/Generators/Generators.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/Generators/Generators.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": 70.9693251534, "max_line_length": 274, "alphanum_fraction": 0.7749827109, "num_tokens": 2745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936537604181, "lm_q2_score": 0.8723473730188543, "lm_q1q2_score": 0.6684742558189203}}
{"text": "\\label{sec:data-fitting}\n\nWe can fit a triangular mesh, $\\M$, to a set of data points, $\\{\\d_i; i=0 \\ldots n-1\\}$\nby minimizing the sum of the $l_2$ distances from the points to the mesh:\n\\begin{equation}\nf(\\M) = \\sum_{i=0}^{n-1} \\| \\d_i - \\Pr_\\M (\\d_i) \\|^2 ,\n\\end{equation}\nwhere $\\Pr_\\M (\\d_i)$ is the point on $\\M$ closest to $\\d_i$,\nthat is, the {\\em projection} of $\\d_i$ on $\\M$.\nNote that $f:\\Reals^{3n} \\mapsto \\Re$,\nwhere $n$ is the number of vertices in $\\M$.\n\nWe compute $\\Pr_\\M (\\d)$ by minimizing  $\\| \\d - \\Pr_\\s (\\d) \\|^2$\nover all simplices $\\s \\in \\M$.\nWe need only consider the faces of $\\M$,\nthose edges not in any face,\nand the vertices not in any edge,\nbecause the closest point on a face must at least\nas the closest point on any of its edges,\nand similarly for vertices.\nMore generally, spatial binning of the simplices and data can greatly\nreduce the number of simplices that need to be examined.\n\nThe following sections consider the projection of a single\ndata point $\\d$ on a mesh $\\M$,\nand the gradient of the squared distance,\nas a function of the vertex positions $\\p(\\v)$.\n\nUnfortunately, derivatives of the distance function are not continuous.\nSecond derivative discontinuities occur\nwhen a data point is on the boundary\nof a 'watershed' region, the set of points\nprojecting on a vertex or the interior of an edge or face.\nGradient discontinuities are encountered\nwhen a data point is equidistant from 2 distinct closest mesh points.\n\n\\subsection{Distance to vertex}\n\\label{sec:Distance-to-vertex}\n\nLet $\\p = \\p(\\v)$ be the position of a particular vertex $\\v$,\nand $\\d$ the 3d data point.\nIt follows from equation \\ref{eq:l2-gradient} that\n\\begin{equation}\n\\label{eq:vertex-distance-gradient}\n\\Gc{\\p}{\\| \\p - \\d \\|^2}{\\q} = 2 ( \\q - \\d ).\n\\end{equation}\n\nThe distance to the nearest vertex in a set of vertices $\\V$ is:\n$\\min_{\\v \\in \\V} \\| \\p(\\v) - \\d \\|^2$.\nIf $\\v^{\\mathrm min}$ is the minimizing vertex,\nand\n$\\p^{\\mathrm min}$ its position,\nthen the partial gradient with respect\nto the position of any other vertex is zero,\nand the partial gradient with respect to $\\p^{\\mathrm min}$\nis given in equation \\ref{eq:vertex-distance-gradient}.\nNote that the gradient is only defined and continuous\nwhile $\\d$ is within the interior of the\nVoronoi regions surrounding the vertices.\n\n\\subsection{Distance to edge}\n\\label{sec:Distance-to-edge}\n\nLet the edge $\\e$ have end points $\\p = (\\p_0, \\p_1) \\in \\Reals^6$.\nWe can write the projection of a data point $\\d$ on $\\e$ as:\n\\begin{equation}\n\\Pr_\\p (\\d) = b_0(\\p) \\p_0 + b_1(\\p) \\p_1\n\\end{equation}\nwhere\n\\begin{eqnarray}\nb_0(\\p) & = &\n\\min\\left(0,\\max\\left(1,\n{{ (\\d - \\p_1) \\bullet (\\p_0 - \\p_1) }\n\\over\n{ \\| \\p_0 - \\p_1 \\|^2 }\n}\\right) \\right) \\\\\nb_1(\\p) & = & 1 - b_0(\\p)\n\\nonumber\n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\label{eq:edge-distance-gradient-derivation}\n\\De{\\p_0}{ \\| \\Pr_{\\p} (\\d) - \\d \\|^2 }{\\q}\n& = &\n2 \\left( \\Pr_{\\q} (\\d) - \\d \\right)^\\dagger\n\\De{\\p_0}{\\Pr_{\\p} (\\d) }{\\q}\n\\\\\n& = &\n2 \\left( \\Pr_{\\q} (\\d) - \\d \\right)^\\dagger\n\\De{\\p_0}{\\left[ b_0(\\p)\\p_0 + b_1(\\p)\\p_1 \\right]}{\\q}\n\\nonumber \\\\\n& = &\n2 \\left( \\Pr_{\\q} (\\d) - \\d \\right)^\\dagger\n\\De{\\p_0}{\\left[ b_0(\\p)\\p_0 + (1 - b_0(\\p))\\p_1 \\right]}{\\q}\n\\nonumber \\\\\n& = &\n2 \\left( \\Pr_{\\q} (\\d) - \\d \\right)^\\dagger\n\\De{\\p_0}{\\left[ b_0(\\p)(\\p_0 - \\p_1) \\right]}{\\q}\n\\nonumber \\\\\n& = &\n2 \\left( \\Pr_{\\q} (\\d) - \\d \\right)^\\dagger\n\\left[ b_0(\\q) \\I + (\\q_0 - \\q_1) \\otimes \\Gc{\\p_0}{b_0(\\p)}{\\q} \\right]\n\\nonumber\n\\end{eqnarray}\nBecause $\\left( \\Pr_{\\q} (\\d) - \\d \\right)$ is orthogonal to\n$\\left( \\q_0 - \\q_1 \\right)$, we get:\n\\begin{eqnarray}\n\\label{eq:edge-distance-gradient}\n\\Gc{\\p_0}{ \\| \\Pr_{\\p} (\\d) - \\d \\|^2 }{\\q}\n& = & 2 b_0(\\q) \\left[ \\Pr_{\\q} (\\d) - \\d \\right]\n\\\\\n\\Gc{\\p_1}{ \\| \\Pr_{\\p} (\\d) - \\d|^2 }{\\q}\n& = & 2 b_1(\\q) \\left[ \\Pr_\\q (\\d) - \\d \\right]\n\\nonumber\n\\end{eqnarray}\n\nAs in the vertex case,\nthe distance to the nearest edge in a set of edges $\\E$ is:\n\\begin{equation}\n\\| \\Pr_{\\E} (\\d) - \\d|^2 = \\min_{\\e \\in \\E} \\| \\Pr_{\\p(\\e)}(\\d) - \\d \\|^2\n\\end{equation}\nIf $\\e^{\\min}$ is the minimizing edge,\n$\\v_0^{\\min}$ and $\\v_1^{\\min}$ its vertices,\nand $\\p_0^{\\min}$ and $\\p_1^{\\min}$\nthe corresponding endpoints,\nthen the partial gradient with respect to\nthe position of any\nother vertex is zero,\nand the partial gradient with respect to $\\p_0^{\\min}$ and $\\p_1^{\\min}$\nis given in equation \\ref{eq:edge-distance-gradient}.\n\nThe total gradient is defined and continuous\nwhen $\\d$ is within the union of the watershed regions\nof $\\e^{\\min}$ and its vertices.\nIt is also continuous where the watershed of one of the vertices\nmeets the watershed of any of the edges containing that vertex.\nIt is not if $\\d$ lies on the boundary of the\nwatershed of $\\e^{\\min}$ and the watershed of an\nedge with which it does not share a vertex.\n\n\\subsection{Distance to face}\n\\label{sec:Distance-to-face}\n\nLet the face $\\f$ have corner points $\\p = (\\p_0, \\p_1, \\p_2) \\in \\Reals^9$.\nAs in the edge case,\nwe can write the projection of a data point $\\d$ on $\\f$\nin terms of the barycentric coordinates as:\n\\begin{equation}\n\\Pr_\\p (\\d) = b_0(\\p) \\p_0 + b_1(\\p) \\p_1 + b_2(\\p) \\p_2,\n\\end{equation}\nand, by an argument simlar to that used in\nequation \\ref{eq:edge-distance-gradient-derivation},\nwe can show that\n\\begin{eqnarray}\n\\label{eq:face-distance-gradient}\n\\Gc{\\p_0}{ \\| \\Pr_{\\p} (\\d) - \\d \\|^2 }{\\q}\n& = & 2 b_0(\\q) \\left[ \\Pr_{\\q} (\\d) - \\d \\right]\n\\\\\n\\Gc{\\p_1}{ \\| \\Pr_{\\p} (\\d) - \\d|^2 }{\\q}\n& = & 2 b_1(\\q) \\left[ \\Pr_\\q (\\d) - \\d \\right]\n\\nonumber\n\\\\\n\\Gc{\\p_2}{ \\| \\Pr_{\\p} (\\d) - \\d|^2 }{\\q}\n& = & 2 b_2(\\q) \\left[ \\Pr_\\q (\\d) - \\d \\right]\n\\nonumber\n\\end{eqnarray}\n\nComputing the barycentric coordinates for the projection\non a face (triangle) is slightly more complicated than\nfor an edge (line segment).\n\nFirst center the problem by letting\n$\\v = \\p - \\p_0$,\n$\\v_1 = \\p_1 - \\p_0$, and $\\v_2 = \\p_2 - \\p_0$.\nThen compute the raw, unbounded barycentric coordinates\nof the projection of $\\p$ onto the plane\nspanned by the triangle:\n\\begin{eqnarray}\nr_0(\\p) & = & 1 - r_1(\\p) - r_2(\\p)\n\\\\\nr_1(\\p) & = & v \\bullet {{\\v_1 \\perp \\v_2} \\over {\\| \\v_1 \\perp \\v_2 \\|^2} }\n\\nonumber\n\\\\\nr_2(\\p) & = & v \\bullet {{\\v_2 \\perp \\v_1} \\over {\\| \\v_2 \\perp \\v_1 \\|^2} }\n\\nonumber\n\\end{eqnarray}\nTo correctly bound the raw coordinates to numbers between 0 and 1,\nwe need to determine whether the projected point is in\nthe interior of the triangle, on one of the edges,\nor on one of the vertices.\n\n\\begin{description}\n\n\\item[Vertex case:]\nIf any 2 of the $r_i$ are negative,\nthen $\\p$ projects on the remaining vertex.\nSet the 2 $b_i$ corresponding to the negative $r_i$\nto 0 and the remaining $b_i$ to 1.\n\n\\item[Edge case:]\nIf any single 1 of the $r_i$ is negative,\nthen $\\p$ projects on the opposite edge.\nSet the $b_i$ corresponding to the negative $r_i$\nto 0.\nGo to \\autoref{sec:Distance-to-edge} to see\nhow to compute the remaining barycentric coordinates\nby projecting on the edge\n\n\\item[Interior case:]\nIf none of the $r_i$ is negative,\nthen $\\p$ projects on the interior\nand each $b_i = r_i$\n\n\\end{description}\n", "meta": {"hexsha": "23014f8df43d747c1d842f3291b21e65c6267d3f", "size": 7058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/data-fitting.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/data-fitting.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/data-fitting.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": 32.8279069767, "max_line_length": 87, "alphanum_fraction": 0.6531595353, "num_tokens": 2579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6684742503217441}}
{"text": "\\documentclass[main.tex]{subfiles}\n\n\\begin{document}\n\t\n\t\\section{Band structure}\\label{sec:band_structure}\n\t\\subsection{Theory}\n\tIn a crystal, the potential must necessarily be periodic in the unit cell, otherwise the discrete translational symmetry is broken. As such the following equation holds for any lattice vector $ \\V{R} $:\n\t\\begin{equation}\\label{eq:band_period_V}\n\t\tV(\\V{r}+\\V{R}) = V(\\V{r}).\n\t\\end{equation}\n\tDue to this periodicity, the potential can also be expressed as a sum over reciprocal lattice vectors. To see this, we start with the potential operator:\n\t\\begin{equation}\n\t\t\\hat{V} = \\infint V(\\V{r}) \\ket{\\V{r}}\\bra{\\V{r}}\\ud \\V{r}.\n\t\\end{equation}\n\tWe insert two continuous identities for $ \\V{k} $ and $ \\V{k}' $, which is the equivalent of taking the Fourier transform of the potential: \n\t\\begin{align}\n\t\t\\hat{V} &= \\infint V(\\V{r}) \\bb{ \\infint \\ket{\\V{k}} \\bra{\\V{k}} \\ud \\V{k}  } \\ket{\\V{r}}\\bra{\\V{r}} \\bb{\\infint \\ket{\\V{k}'} \\bra{\\V{k}'} \\ud \\V{k}' } \\ud \\V{r} , \\\\\n\t\t&=\\infint \\infint \\infint V(\\V{r}) \\ket{\\V{k}} \\braket{\\V{k} | \\V{r}} \\braket{\\V{r} | \\V{k}'} \\bra{\\V{k}}  \\ud\\V{k}'   \\ud\\V{k}   \\ud\\V{r}.\n\t\\end{align}\n\tThe two middle brakets are $ \\braket{\\V{k}| \\V{r}}= \\sqrt{(2\\pi)^3}\\inverse e^{-i \\V{k} \\D \\V{r}} $ and $ \\braket{\\V{r} | \\V{k}'} = \\sqrt{(2\\pi)^3}\\inverse e^{i \\V{k}' \\D \\V{r}} $, where $ \\sqrt{(2\\pi)^3}\\inverse $ is a normalization factor. This then becomes\n\t\\begin{align}\n\t\t\\hat{V} &= \\frac{1}{(2\\pi)^3}\\infint \\infint  \\infint  V(\\V{r}) e^{-i(\\V{k}-\\V{k}') \\D \\V{r}} \\ket{\\V{k}} \\bra{\\V{k}'} \\ud\\V{k}'   \\ud\\V{k}   \\ud\\V{r}.\n\t\\end{align}\n\tNext we use the now familiar trick of letting $ \\V{r} = \\V{R} + \\V{x} $:\n\t\\begin{equation}\n\t\t\\hat{V} = \\frac{1}{(2\\pi)^3}\\infint \\infint  \\bb{\\sum_{\\V{R}} e^{i(\\V{k}'-\\V{k}) \\D \\V{R}}}  \\int_{\\substack{\\text{unit-} \\\\\\text{cell}}} V(\\V{x})\\  e^{-i (\\V{k}-\\V{k}') \\D \\V{x}} \\ket{\\V{k}} \\bra{\\V{k}'} \\ud \\V{x} \\ud\\V{k}'   \\ud\\V{k}.\n\t\\end{equation}\n\tThis sum, like before, equals 0 for $ \\V{k}'-\\V{k} \\neq \\V{G} $. However, when $ \\V{k}'-\\V{k} = \\V{G} $ this sum becomes infinite (given the infinite amount of lattice points), with a prefactor of $ (2\\pi)^3 / a^{-3} $ \\cite{simon}. This then gives\n\t\\begin{align}\n\t\t\\hat{V} &= \\frac{1}{a^3} \\sum_{G} \\infint \\infint \\delta(\\V{k}'-\\V{k}-\\V{G}) \\int_{\\substack{\\text{unit-} \\\\\\text{cell}}} V(\\V{x})\\  e^{-i \\V{G} \\D \\V{x}} \\ket{\\V{k}} \\bra{\\V{k}'} \\ud \\V{x} \\ud\\V{k}'   \\ud\\V{k}, \\\\\n\t\t&= \\sum_{G} V_{\\V{G}}  \\infint \\ket{\\V{k}} \\bra{\\V{k}-\\V{G}} \\ud \\V{k}, \\quad V_{\\V{G}} = \\frac{1}{a^3} \\int_{\\substack{\\text{unit-} \\\\\\text{cell}}} V(\\V{x}) e^{-i\\V{G} \\D \\V{x}} \\ud \\V{x},\n\t\\end{align}\n\twhere $ V_{\\V{G}} $ is the Fourier transform of the potential, in $ \\V{G} $, over the unit cell, which is the same as the structure factor for scattering, except for a normalisation factor. Now, inserting two additional identities, but this time for $ \\V{r} $ and $ \\V{r}' $:\n\t\\begin{align}\n\t\t\\hat{V} &=\\sum_{G}  V_{\\V{G}} \\infint \\bb{\\infint \\ket{\\V{r}} \\bra{\\V{r}} \\ud \\V{r}} \\ket{\\V{k}} \\bra{\\V{k}+ \\V{G}} \\bb{\\infint \\ket{\\V{r}'} \\bra{\\V{r}'} \\ud \\V{r}'} \\ud \\V{k}, \\\\\n\t\t&=\\sum_{G} V_{\\V{G}} \\infint  \\infint \\infint \\sqrt{(2\\pi)^3}\\inverse e^{i \\V{k} \\D \\V{r}} \\sqrt{(2\\pi)^3}\\inverse e^{-i (\\V{k}+\\V{G}) \\D \\V{r}'} \\ket{\\V{r}} \\bra{\\V{r}'} \\ud \\V{k} \\ud \\V{r} \\ud \\V{r}', \\\\\n\t\t&=\\frac{1}{(2\\pi)^3} \\sum_{G} V_{\\V{G}} \\infint \\infint \\infint  e^{-i \\V{G} \\D \\V{r}'} e^{i \\V{k} \\D (\\V{r}-\\V{r}')} \\ket{\\V{r}} \\bra{\\V{r}'} \\ud \\V{k} \\ud \\V{r} \\ud \\V{r}'.\n\t\\end{align}\n\tWe can get rid of two of these integrals, if we use the fact that \\cite{riley}\n\t\\begin{equation} \\label{eq:delta_funct}\n\t\t\\delta(\\V{r}-\\V{r}') = \\frac{1}{(2\\pi)^3} \\infint  e^{i \\V{k} \\D (\\V{r}-\\V{r}')} \\ud \\V{k},\n\t\\end{equation}\n\tas we then get\n\t\\begin{equation}\n\t\t\\hat{V} = \\sum_{\\V{G}} V_{\\V{G}} \\infint e^{-i \\V{G} \\D \\V{r}} \\ket{\\V{r}} \\bra{\\V{r}} \\ud \\V{r},\n\t\\end{equation}\n\twhich, if the prefactors and the sum is taken inside the integral, is the same form as we started with! Thus we get our desired result of\n\t\\begin{equation}\n\t\tV(\\V{r}) =  \\sum_{\\V{G}} V_{\\V{G}} \\,e^{i \\V{G} \\D \\V{r}}, \\quad V_{\\V{G}} = \\frac{1}{a^3} \\int_{\\substack{\\text{unit-} \\\\\\text{cell}}}  V(\\V{x})\\  e^{-i \\V{G} \\D \\V{x}} \\ud \\V{x},\n\t\\end{equation}\n\twhere we have made the substitution $ \\V{G} \\to -\\V{G} $ in the expression for $ V(\\V{r}) $. This does not change the sum index as all terms are still included, and as we shall see below, we have $ V_{\\V{G}}= V_{-\\V{G}} $, so the above equality holds.\n\t\n\tThis form allows us to write the Schrödinger equation in a form where the dispersion relation is easily calculated numerically. First we Fourier transform the equation:\n\t\\begin{equation}\n\t\t\\infint e^{-i \\V{k} \\D \\V{r}} \\bb{\\frac{\\V{p}^2}{2m} + V(\\V{r})}\\psi(\\V{r}) \\ud \\V{r}= \\infint e^{-i\\V{k} \\D \\V{r}}\\, E\\, \\psi(\\V{r}) \\ud \\V{r} = E \\,\\tilde{\\psi}(\\V{k}).\n\t\\end{equation}\n\tThe kinetic energy term is just\n\t\\begin{equation}\n\t\t\\mathcal{F}\\bb{\\frac{\\V{p}^2}{2m} \\psi(\\V{r})} = -\\frac{\\hbar^2}{2m}\\infint e^{-i \\V{k} \\D \\V{r}}\\, \\nabla^2\\psi(\\V{r}) \\ud \\V{r} = \\frac{\\hbar^2 \\V{k}^2}{2m}\\tilde{\\psi(\\V{k})},\n\t\\end{equation}\n\twhilst the potential energy term is\n\t\\begin{align}\n\t\t\\mathcal{F}[V(\\V{r}) \\psi(\\V{r})] &= \\infint e^{-i \\V{k} \\D \\V{r}}\\, V(\\V{r})\\, \\psi(\\V{r}) \\ud \\V{r} = \\infint e^{-i \\V{k}\\D \\V{r}} \\bb{\\sum_{\\V{G}} e^{i \\V{G} \\D \\V{r}}\\, V_{\\V{G}} }\\psi (\\V{r}) \\ud \\V{r}, \\\\\n\t\t&= \\sum_{\\V{G}} V_{\\V{G}} \\infint e^{-i(\\V{k}-\\V{G})\\D \\V{r}}\\, \\psi(\\V{r}) \\ud \\V{r},\n\t\\end{align}\n\twhere the integral is just the Fourier transform of the wave function, in $ \\V{k}-\\V{G} $:\n\t\\begin{equation}\n\t\t\\mathcal{F}[V(\\V{r}) \\psi(\\V{r})] = \\sum_{\\V{G}} V_{\\V{G}} \\, \\tilde{\\psi}(\\V{k}-\\V{G}).\n\t\\end{equation}\n\tWith this expression, the whole equation becomes\n\t\\begin{equation}\n\t\t\\sum_{\\V{G}} \\bb{\\frac{\\hbar^2 \\V{k}^2}{2m} \\delta_{\\V{G},0} + V_{\\V{G}} } \\tilde{\\psi}(\\V{k}-\\V{G}) = E\\, \\tilde{\\psi}(\\V{k}).\n\t\\end{equation}\n\tThis equation gives the energy for a single value of $ \\V{k} $, by relating the state $ \\tilde{\\psi}(\\V{k}) $ to all other states with the same crystal momentum. If we then consider all the different equations for states with the same crystal momentum $ \\tilde{\\psi} (\\V{k}-\\V{G}) $, we can describe them all as a matrix equation, where the eigenvalues are the energies for the state with wave vector $ \\V{k} $, in all of the different bands. The first (lowest) eigenvalue is thus the energy of $ \\tilde{\\psi} (\\V{k}) $ in the lowest band.\n\t\n\tTo calculate the dispersion relation for a given lattice and potential we then need to find the eigenvalue of the above matrix equation for a range of different $ \\V{k} $. However, due to the unbounded nature of $ \\V{G} $, the matrix and vector will both have an infinite amount of elements. For the purposes of the program we need to only allow some set of $ \\V{G} $, making the matrix and vector finite dimensional.\n\t\n\tThis can be thought of through the lens of perturbation theory. If we have a free particle (corresponding to no allowed value of $ \\V{G} $), we just get a $ 1\\times 1$ ``matrix'', whose eigenvalue trivially is the energy of a free particle. Adding the potential for $ \\V{G} = 0 $ gives the first order perturbation, shifting the state by some constant energy (the matrix equation still only has one allowed state). Allowing the set of next smallest values for $ \\V{G} $ would then constitute a second order perturbation, where the particle is allowed to scatter into these states. Further allowing a larger set of $ \\V{G} $ will give a more accurate calculation of the dispersion relation for the particle, until finally it becomes exact when the full, infinite spectrum of values for $ \\V{G} $ is included.\n\t\n\t\\subsection{Implementation}\n\tIn the above calculations we have assumed a three dimensional system. In the following however, we will restrict ourselves to two dimensions and a square lattice with lattice spacing $ a $. The reciprocal lattice vectors $ \\V{G} $ can then be indexed with the coefficients $ m_1 $ and $ m_2 $, as $ \\V{G} = \\frac{2\\pi}{a} (m_1 \\U{x} + m_2 \\U{y}) $. This also means that the sum over $ \\V{G} $ can be expressed as a double sum over $ m_1 $ and $ m_2 $. \n\t\n\tTo describe the matrix it is helpful to first describe the vector in the equation. Let us call this $ \\ket{\\psi} $. This consists of $ \\tilde{\\psi} (\\V{k}+\\V{G}) $ for all the allowed $ \\V{G} $. Let us also call these $ \\psi[m_1, m_2] $:\n\t\\begin{equation}\n\t\t\\ket{\\psi} = \\begin{pmatrix}\n\t\t\\vdots \\\\ \\tilde{\\psi}(\\V{k}-\\V{G}_1) \\\\ \\tilde{\\psi}(\\V{k}) \\\\ \\tilde{\\psi}(\\V{k}+\\V{G}_1) \\\\ \\vdots\n\t\t\\end{pmatrix} = \\begin{pmatrix}\n\t\t\\vdots \\\\ \\psi\\coef{0, -1}\\\\ \\psi\\coef{0, 0} \\\\ \\psi\\coef{0, 1} \\\\ \\vdots\n\t\t\\end{pmatrix},\n\t\\end{equation}\n\twhere $ \\V{G}_1 = \\frac{2\\pi}{a} \\U{y}$, for example. Correspondingly we write $ V_{\\V{G}} $ as $ V\\coef{m_1, m_2} $.\n\n\tThe matrix in the above equation can be split into two different matrices: One for the kinetic energy $ T $, which is just a diagonal matrix, and one for the potential energy $ V $. The diagonal elements of the kinetic energy matrix are just the energy of the state, if no potential was present:\n\t\n\t\\begin{equation}\n\t\tT = \\frac{\\hbar^2}{2m} \\begin{pmatrix}\n\t\t\t\\ddots\t& \t\t \t\t\t&\t\t\t& \t\t\t\t\t& \\\\\n\t\t\t\t\t& (\\V{k}-\\V{G}_1)^2\t& \t\t\t& \t\t\t\t\t& \\\\\n\t\t\t\t\t& \t \t\t\t\t& \\V{k}^2\t& \t\t\t\t\t& \\\\\n\t\t\t\t\t&\t\t\t\t\t&\t\t\t& (\\V{k}+\\V{G}_1)^2\t& \\\\\n\t\t\t\t\t&\t\t\t\t\t&\t\t\t&\t\t\t\t\t& \\ddots\n\t\t\\end{pmatrix}.\n\t\\end{equation}\n\tThe potential energy matrix is a bit more complicated. It is best described with an example. Say we allow $ m_1, m_2 \\in \\{-1,0,1\\} $. The sum still has an infinite amount of terms, but we only allow 9 of these in our matrix equation. These terms have pairs of coefficients for $ \\psi $ that are in the ordered list\n\t\\begin{equation}\n\t\t[m_1, m_2] \\in \\{ [-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1,-1], [1, 0], [1,1]  \\}.\n\t\\end{equation}\n\t\n\tIf we then calculate (part of) the row equation for $ m_1 = -1, m_2 = 0 $ (which is the second row of the potential matrix) we get\n\t\\begin{align*}\n\t\tE \\psi\\coef{-1,0} = {} & \\sum_{m'_1 =  -\\infty}^{\\infty}\\sum_{m'_2 = -\\infty}^{\\infty} V\\coef{m'_1, m'_2} \\ \\psi\\coef{-1-m'_1, -m'_2}, \\\\\n\t\t= {} & \\dots +  V\\coef{-2, -1}\\psi\\coef{1,1} + V\\coef{-2, 0} \\psi\\coef{1, 0} + V\\coef{-2, 1}\\psi\\coef{1,-1} +  \\dots  \\\\\n\t\t& + V\\coef{-1, -1} \\psi\\coef{-2, 1} + V\\coef{-1, 0} \\psi\\coef{-2, 0} + V\\coef{-1, 1} \\psi\\coef{-2, -1} + \\dots\\\\\n\t\t& + V\\coef{0, -1} \\psi\\coef{-1, 1} + V\\coef{0, 0} \\psi\\coef{-1, 0} + V\\coef{0, 1}\\psi\\coef{-1, -1} + \\dots\\\\\n\t\t&+ V\\coef{1, -1} \\psi \\coef{0,1} + V\\coef{1, 0} \\psi \\coef{0, 0} + V\\coef{1,1} \\psi \\coef{0, -1} + \\dots.\n\t\\end{align*}\n\tNow, the 4th to 6th  shown terms contain ``disallowed'' states, i.e. they have coefficients for $ \\psi $ outside of the allowed range. The other 9 shown terms are ``allowed'' states however.\n\t\n\tAs for the ordering of the rows of the matrix: $ [-1, -1] $ is the first pair of coefficients in the ordered set of coefficients. Because of this $ V\\coef{0, 1} \\psi\\coef{-1,-1}$ is the first term in the matrix equation, and $ V\\coef{0, 1} $ is then the first element in the matrix row. The whole row is then:\n\t\\begin{equation}\n\t\t\\begin{pmatrix}\n\t\t\tV\\coef{0, 1} &  V\\coef{0, 0} & V\\coef{0, -1} & V\\coef{1, 1} & V\\coef{1, 0} & V\\coef{1,-1} & V\\coef{-2, 1} & V\\coef{-2, 0} & V\\coef{-2, -1}\n\t\t\\end{pmatrix}.\n\t\\end{equation}\n\tThe algorithm for constructing the potential matrix is as follows:\n\t\\begin{enumerate}\n\t\t\\item Choose a range of values for $ m_1 $ and $ m_2 $ and arrange them in an ordered set.\n\t\t\\item For each pair of coefficients in this set, ($ [m_1, m_2] $, corresponding to some row), calculate $ [m_1-m_1', m_2-m_2'] $, where $ [m_1', m_2'] $ are all the pairs of coefficients from the same set, corresponding to the columns of the matrix.\n\t\t\\item This new pair of coefficients, $ [m_1-m_1', m_2-m_2'] $, will be coefficients for the potential at the corresponding matrix element: $ V\\coef{m_1-m_1', m_2-m_2'} $. (The corresponding matrix element is the one with row/column corresponding to the position of $ [m_1, m_2]/[m_1', m_2'] $ in the ordered set). \n\t\\end{enumerate}\n\tWith this algorithm in mind, we can see a couple of characteristics of the matrix:\n\t\\begin{itemize}\n\t\t\\item The diagonal elements are all $ V\\coef{0,0} $, corresponding to the state not being scattered into any other state.\n\t\t\\item The matrix is Hermitian, if $ V\\coef{m_1, m_2} = V\\coef{-m_1, -m_2}$, which is the same condition one gets when using perturbation theory to calculate the band structure in the Nearly Free Electron Model, see section \\ref{sec:nearly_free}. This is all very fortunate since the potential matrix must necessarily be hermitian for the whole Hamiltonian to be hermitian, which it has to be, since it corresponds to an observable quantity, namely energy.\n\t\\end{itemize}\n\tOn the last characteristic: Since the potential is real and symmetric (rather, it is even about any lattice point $ \\V{R} $, in both the $ x $ and $ y $-direction), it is guaranteed that $ V\\coef{m_1, m_2} = V\\coef{-m_1, -m_2}$. This is because the Fourier transform of a real and even function is also real and even \\cite{riley}. As such, for any periodic potential (that is even in both $ x $ and $ y $ about lattice points) the potential matrix, and therefore also the whole Hamiltonian is hermitian!\n\t\n\tSpecific potentials implemented in the program include a two dimensional Dirac Comb, and a harmonic potential:\n\t\\begin{equation}\n\t\tV_{\\text{dirac}}(\\V{r}) = V_0 a^2 \\sum_{\\V{R}} \\delta(\\V{r}-\\V{R}), \\quad V_{\\text{harmonic}}(\\V{r}) = V_0 \\bb{\\cos\\pp{\\frac{2\\pi}{a} x} + \\cos\\pp{\\frac{2\\pi}{a} y}},\n\t\\end{equation}\n\twhere the $ a^2 $ in the Dirac comb potential arises from the fact that the Dirac delta function carries units $ \\e{m}^{-2} $ (in general it carries units that are inverse of its argument as can be seen from Eq. \\eqref{eq:delta_funct} by dimensional analysis). Now, $ V\\coef{m_1, m_2} $ for the Dirac Comb potential is easily calculated. We let the unit cell run from $ -a/2 $ to $ a/2 $ in both $ x $ and $ y $, to make sure the delta functions are well within the integration limits. Then it just becomes:\n\t\\begin{equation}\n\t\tV\\coef{m_1, m_2} = V_0 \\frac{a^2}{a^2} \\int_{-a/2}^{a/2} \\int_{-a/2}^{a/2} e^{i 2\\pi (m_1 x + m_2 y)/a} \\delta(\\V{r}) = V_0 \\ud x \\ud y,\n\t\\end{equation}\n\tand the potential matrix is just a matrix full of ones, scaled by $ V_0 $. For the harmonic potential we let the unit cell run from $ 0 $ to $ a $ in both directions and get\n\t\\begin{equation}\n\t\tV\\coef{m_1, m_2} = \\frac{V_0}{a^2} \\int_{0}^{a} \\int_0^a e^{i 2\\pi(m_1x + m_2y)/a} \\bb{\\cos\\pp{\\frac{2\\pi}{a} x} + \\cos\\pp{\\frac{2\\pi}{a} y}} \\ud x \\ud y.\n\t\\end{equation}\n\tThis can be split into two integrals, $ I_1 $ and $ I_2 $. The first is\n\t\\begin{align}\n\t\tI_1 &=  \\frac{V_0}{a^2} \\int_{0}^{a} \\int_0^a e^{i 2\\pi(m_1x + m_2y)/a}\\cos\\pp{\\frac{2\\pi}{a} x} \\ud x \\ud y , \\\\\n\t\t&= \\frac{V_0}{2a^2} \\int_{0}^{a} e^{i 2\\pi m_2 y / a} \\ud y\\ \\int_{0}^{a} \\ e^{i 2\\pi m_1 x/a} \\bb{e^{i 2\\pi x/a} + e^{-i 2\\pi x/a}} \\ud x, \\\\\n\t\t&= \\frac{V_0}{2a^2} \\int_0^a e^{i 2\\pi m_2 y / a} \\ud y\\  \\int_{0}^{a} \\ud x\\ \\bb{e^{i 2\\pi(m_1+1) x/a} + e^{-i 2\\pi (m_1-1)x/a}} \\ud x.\n\t\\end{align}\n\tNow if $ m_2 = 0 $, the integrand in the $ y $-integral is just 1, and the whole integral evaluates to $ a $. If $ m_2 \\neq 0 $ this is not the case. However, the antiderivative evaluated at both ends is the same, and the whole integral is 0:\n\t\\begin{equation}\n\t\t\\int_{0}^{a} e^{i 2\\pi m_2 y/a} \\ud y = \\frac{a}{i 2\\pi m_2} \\bb{e^{i2\\pi m_2 y /a}}_0^a = 0.\n\t\\end{equation}\n\tThe same goes for the integrals in $ x $, but with $ m_1 \\pm 1 $ instead of $ m_2 $. As such\n\t\\begin{equation}\n\t\tI_1 = \\frac{V_0 a^2}{2 a^2} \\bb{\\delta_{m_2,0} (\\delta_{m_1, 1} + \\delta_{m_1, -1})},\n\t\\end{equation}\n\twith a similar result for $ I_2 $. $ V\\coef{m_1, m_2} $ is then\n\t\\begin{equation}\n\t\tV\\coef{m_1, m_2} = \\begin{cases}\n\t\t\t\\frac{V_0}{2} \t& \\text{if } [m_1, m_2] \\in \\{[0,1], [0,-1], [1,0], [-1,0]\\}, \\\\\n\t\t\t0\t\t\t\t\t& \\text{else}.\n\t\t\\end{cases}\n\t\\end{equation}\n\tAnd the potential energy matrix is\n\t\\begin{equation}\n\t\tV_{\\text{harmonic}} = \\frac{V_0}{2} \\begin{pmatrix}\n\t\t0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t1 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n\t\t0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n\t\t1 & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n\t\t0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\\\\n\t\t0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 1 \\\\\n\t\t0 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 \\\\\n\t\t0 & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n\t\t0 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 0\n\t\t\\end{pmatrix}.\n\t\\end{equation}\n\tWith this we have the full Hamiltonian matrix, and we can solve it for a range of $ \\V{k} $ to get the dispersion relation for a particle in a square lattice.\n\t\n\tTo calculate the dispersion relation, the program needs values for $ V_0 $, $ a $ and $ \\hbar^2/2m $ along with the range of coefficients for $ \\V{G} $. To make this more simple for the user, we define $ k_0 \\equiv 2\\pi/a $ (the same factor as in the scattering program) and $ E_0 \\equiv \\hbar^2 k_0^2/m $. These allow us to rewrite the equation in a dimensionless form:\n\t\\begin{equation}\\label{key}\n\t\t\\sum_{\\tilde{\\V{G}}} \\bb{\\frac{\\tilde{\\V{k}}^2}{2} \\delta_{\\tilde{\\V{G}},0} + \\tilde{V}_{\\tilde{\\V{G}}}} \\tilde{\\psi}(\\tilde{\\V{k}} - \\tilde{\\V{G}}) = \\tilde{E} \\tilde{\\psi}(\\tilde{\\V{k}}),\n\t\\end{equation}\n\twith $ \\tilde{\\V{G}} \\equiv \\V{G}/k_0 = m_1 \\U{x}+m_2 \\U{y} $, $ \\tilde{\\V{k}} \\equiv \\V{k}/k_0 $ $ \\tilde{V}_{\\tilde{\\V{G}}} \\equiv V_{\\V{G}} / E_0$ and $ \\tilde{E} \\equiv E/E_0 $. This also redefines the first Brillouin zone to be $ -1/2 \\leq \\tilde{k} \\leq 1/2 $ in each direction.\n\t\n\tWith this the Hamiltonian matrix is created. The program also takes a value for the number of points in the first Brillouin-zone in $ k $-space and creates linearly spaced points from $ -1/2 $ to $ 1/2 $.\n\t\n\tFor each point in the Brillouin zone the program then creates the corresponding kinetic energy matrix, adds the potential energy matrix, and finds the eigenvalues for the resulting matrix. These values are stored in a multidimensional array (represented as a series of matrices, each with size $ n_k \\times n_k $, where $ n_k $ is the number of points in the Brillouin zone, in each direction). When the energies for all coordinates are calculated, the lowest energies for each of the points (corresponding to the first matrix in the multidimensional array) will then be the dispersion of the particle in the first band.\n\t\n\tNext we aim to find the Fermi sea and surface, and not just the dispersion relation. For a crystal with monovalent atoms the electrons fill up half a band, corresponding to half the area of the first Brillouin zone (in two dimensions). To represent this we use the fact that we have discretised the Brillouin zone into $ n_k^2 $ points. The Fermi sea is then covered by the values of $ \\V{k} $ which have an energy lower than the $ n_k^2/2 $'th lowest energy. So to plot only the Fermi sea for a 2D material, we order the energies in the band from lowest to highest, find the middle value, and only plot points that have an energy lower than, or equal to, this energy.\n\t\n\t\\subsection{Examples}\n\tSay we just want to find the dispersion of a free particle. Then we just call the program with $ \\tilde{V}_0 \\equiv V_0/E_0 = 0 $. For good measure we can specify that the potential should be the Dirac potential and that we want the edges of the dispersion relation shown (to increase visibility on a printed page):\n\\begin{lstlisting}\nBand_structure(V0=0,\n\t\t\t   potential='dirac',\n\t\t\t   edges=True)\n\\end{lstlisting}\n\tAnd if we want the high-potential limit of the harmonic potential (which happens to be $ \\tilde{V}_0 = 1 $) we write\n\\begin{lstlisting}\nBand_structure(V0=1,\n\t\t\t   edges=True)\n\\end{lstlisting}\n\tWe do not need to specify that the potential should be harmonic, as this is the default argument. To be explicit we could add the argument \\texttt{potential='harmonic'}.\tThese lines produce figures \\ref{fig:band_structure_none} and \\ref{fig:band_structure_strong} respectively.\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{figures/band_structure_none.pdf}\n\t\t\\caption{The dispersion relation for a free particle in a square lattice of monovalent atoms, along with the Fermi surface.}\n\t\t\\label{fig:band_structure_none}\n\t\\end{figure}\n\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{figures/band_structure_strong.pdf}\n\t\t\\caption{The dispersion relation of a particle in a strong harmonic potential, on a square lattice of monovalent atoms, along with the corresponding Fermi surface.}\n\t\t\\label{fig:band_structure_strong}\n\t\\end{figure}\n\n\\end{document}", "meta": {"hexsha": "1041976c3feba25711b4fc00856e907e61e87afd", "size": 20588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/2D_band_structure.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/2D_band_structure.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/2D_band_structure.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": 91.0973451327, "max_line_length": 808, "alphanum_fraction": 0.6396444531, "num_tokens": 7767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6684742329502935}}
{"text": "\\documentstyle[11pt,reduce]{article}\n\\title{{\\tt FPS}\\\\ \nA Package for the\\\\\nAutomatic Calculation \\\\\nof Formal Power Series}\n\\date{}\n\\author{Wolfram Koepf\\\\\n\tZIB Berlin \\\\\n\tEmail: {\\tt  Koepf@ZIB.de}\n\\\\\n\\\\\n\tPresent \\REDUCE{} form by \\\\\n\tWinfried Neun \\\\\n\tZIB Berlin \\\\\n        Email: {\\tt Neun@ZIB.de}}\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nThis package can expand functions of certain type into\ntheir corresponding Laurent-Puiseux series as a sum of terms of the form\n\\begin{displaymath}\n\\sum_{k=0}^{\\infty} a_{k} (x-x_{0})^{m k/n + s}\n\\end{displaymath}\nwhere $m$ is the `symmetry number', $s$ is the `shift number',\n$n$ is the `Puiseux number',\nand $x_0$ is the `point of development'. The following types are\nsupported:\n\\begin{itemize}\n\\item\n{\\bf functions of `rational type'}, which are either rational or have a\nrational derivative of some order;\n\\item\n{\\bf functions of `hypergeometric type'} where $a(k+m)/a(k)$ is a rational\nfunction for some integer $m$;\n\\item\n{\\bf functions of `explike type'} which satisfy a linear homogeneous\ndifferential equation with constant coefficients.\n\\end{itemize}\n\nThe FPS package is an implementation of the method\npresented in \\cite{Koepf:92}. The implementations of this package\nfor {\\sc Maple} (by D.\\ Gruntz) and {\\sc Mathematica} (by W.\\ Koepf)\nserved as guidelines for this one.\n\nNumerous examples can be found in \\cite{Koepf:93a}--\\cite{Koepf:93b}, \nmost of which are contained in the test file {\\tt fps.tst}. Many \nmore examples can be found in the extensive bibliography of Hansen \\cite{Han}.\n\n\n\\section{\\REDUCE{} operator {\\tt FPS}}\nThe FPS Package must be loaded first by:\n\\begin{verbatim}\nload FPS;\n\\end{verbatim}\n{\\tt FPS(f,x,x0)} tries to find a formal power\nseries expansion for {\\tt f} with respect to the variable {\\tt x} \nat the point of development {\\tt x0}. \nIt also works for formal Laurent (negative exponents) and Puiseux series\n(fractional exponents). If the third \nargument is omitted, then {\\tt x0:=0} is assumed.\n\nExamples: {\\tt FPS(asin(x)\\verb+^+2,x)} results in\n\\begin{verbatim}\n\n         2*k  2*k             2  2\n        x   *2   *factorial(k) *x\ninfsum(----------------------------,k,0,infinity)\n        factorial(2*k + 1)*(k + 1)\n\\end{verbatim}\n{\\tt FPS(sin x,x,pi)} gives\n\\begin{verbatim}\n                   2*k       k\n        ( - pi + x)   *( - 1) *( - pi + x)\ninfsum(------------------------------------,k,0,infinity)\n                factorial(2*k + 1)\n\\end{verbatim}\nand {\\tt FPS(sqrt(2-x\\verb+^+2),x)} yields\n\\begin{verbatim}\n            2*k\n         - x   *sqrt(2)*factorial(2*k)\ninfsum(--------------------------------,k,0,infinity)\n           k             2\n          8 *factorial(k) *(2*k - 1)\n\\end{verbatim}\nNote: The result contains one or more {\\tt infsum} terms such that it does\nnot interfere with the {\\REDUCE} operator {\\tt sum}. In graphical oriented\nREDUCE interfaces this operator results in the usual $\\sum$ notation.\n\nIf possible, the output is given using factorials. In some cases, the\nuse of the Pochhammer symbol {\\tt pochhammer(a,k)}$:=a(a+1)\\cdots(a+k-1)$\nis necessary.\n\nThe operator {\\tt FPS} uses the operator {\\tt SimpleDE} of the next section.\n\nIf an error message of type\n\\begin{verbatim}\nCould not find the limit of:\n\\end{verbatim}\noccurs, you can set the corresponding limit yourself and try a\nrecalculation. In the computation of {\\tt FPS(atan(cot(x)),x,0)},\nREDUCE is not able to find the value for the limit \n{\\tt limit(atan(cot(x)),x,0)} since the {\\tt atan} function is multi-valued.\nOne can choose the branch of {\\tt atan} such that this limit equals\n$\\pi/2$ so that we may set \n\\begin{verbatim}\nlet limit(atan(cot(~x)),x,0)=>pi/2;\n\\end{verbatim}\nand a recalculation of {\\tt FPS(atan(cot(x)),x,0)}\nyields the output {\\tt pi - 2*x} which is\nthe correct local series representation.\n\n\\section{\\REDUCE{} operator {\\tt SimpleDE}}\n\n{\\tt SimpleDE(f,x)} tries to find a homogeneous linear differential\nequation with polynomial coefficients for $f$ with respect to $x$.\nMake sure that $y$ is not a used variable.\nThe setting {\\tt factor df;} is recommended to receive a nicer output form.\n\nExamples: {\\tt SimpleDE(asin(x)\\verb+^+2,x)} then results in\n\\begin{verbatim}\n            2\ndf(y,x,3)*(x  - 1) + 3*df(y,x,2)*x + df(y,x)\n\\end{verbatim}\n{\\tt SimpleDE(exp(x\\verb+^+(1/3)),x)} gives\n\\begin{verbatim}\n              2\n27*df(y,x,3)*x  + 54*df(y,x,2)*x + 6*df(y,x) - y\n\\end{verbatim}\nand {\\tt SimpleDE(sqrt(2-x\\verb+^+2),x)} yields\n\\begin{verbatim}\n          2\ndf(y,x)*(x  - 2) - x*y\n\\end{verbatim}\nThe depth for the search of a differential equation for {\\tt f} is\ncontrolled by the variable {\\tt fps\\verb+_+search\\verb+_+depth};\nhigher values for {\\tt fps\\verb+_+search\\verb+_+depth}\nwill increase the chance to find the solution, but increases the\ncomplexity as well. The default value for {\\tt fps\\verb+_+search\\verb+_+depth} \nis 5. For {\\tt FPS(sin(x\\verb+^+(1/3)),x)}, or \n{\\tt SimpleDE(sin(x\\verb+^+(1/3)),x)} e.\\ g., a setting\n{\\tt fps\\verb+_+search\\verb+_+depth:=6} is necessary.\n\nThe output of the FPS package can be influenced by the\nswitch {\\tt tracefps}. Setting {\\tt on tracefps} causes various\nprints of intermediate results.\n\n\\section{Problems in the current version}\nThe handling of logarithmic singularities is not yet implemented.\n\nThe rational type implementation is not yet complete.\n\nThe support of special functions \\cite{Koepf:94}\nwill be part of the next version.\n\n\\begin{thebibliography}{9}\n\n\\bibitem{Han}\nE.\\ R. Hansen, {\\em A table of series and products.}\nPrentice-Hall, Englewood Cliffs, NJ, 1975.\n\n\\bibitem{Koepf:92} Wolfram Koepf,\n{\\em Power Series in Computer Algebra},\nJ.\\ Symbolic Computation 13 (1992)\n\n\\bibitem{Koepf:93a} Wolfram Koepf,\n{\\em Examples for the Algorithmic Calculation of Formal\nPuiseux, Laurent and Power series},\nSIGSAM Bulletin 27, 1993, 20-32.\n\n\\bibitem{Koepf:93b} Wolfram Koepf,\n{\\em Algorithmic development of power series.} In:\nArtificial intelligence and symbolic mathematical computing,\ned.\\ by J.\\ Calmet and J.\\ A.\\ Campbell,\nInternational Conference AISMC-1, Karlsruhe, Germany, August 1992, Proceedings,\nLecture Notes in Computer Science {\\bf 737}, Springer-Verlag,\nBerlin--Heidelberg, 1993, 195--213.\n\n\\bibitem{Koepf:94} Wolfram Koepf,\n{\\em Algorithmic work with orthogonal polynomials and special functions.}\nKonrad-Zuse-Zentrum Berlin (ZIB), Preprint SC 94-5, 1994.\n\n\\end{thebibliography}\n\n\\end{document}\n\n\n\n", "meta": {"hexsha": "991e0e543a880095fd4f51233491397eec74d47d", "size": 6397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packages/specfn/fps.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/specfn/fps.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/specfn/fps.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": 33.8465608466, "max_line_length": 79, "alphanum_fraction": 0.6896982961, "num_tokens": 1917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6684280259403335}}
{"text": "\\subsection{Loss functions}\n\\label{sec:loss functions}\nHere we are going to discuss some of the loss functions that have been tested in this field so far, and that are relevant to this article. We will look away from the content loss as this part has stayed the same for virtually all papers on the matter.\n\\newline\\newline\nStyle loss was initially discovered to be separable from content loss in a CNN (namely VGG16) by Gatys et al \\cite{Gatys:1}. They calculated what is known as the Gram matrix which represents the style of an image as correlation between different features. The style loss is the squared error between the Gram matrix of the features of the reference style image and the image for which we are minimizing the loss function. This function has been the basis for several other style transfer algorithms, and was for instance approximated with a neural net by Johnson et al \\cite{Johnson:1} trained on a certain style.\n\\newline\\newline\nAnother key finding was that the distribution of the features was a more complete representation of style. This led to Huang et al. \\cite{Huang:1} testing out minimizing the Wasserstein distance between the features instead. This new representation of style produced results of higher artistic quality. Other techniques based the idea of the distance between two distributions as loss has also been tested out with MMD (Maximum mean discrepancy) as the distance measure in a paper by Li et al. \\cite{Li:2} where they also combined it with the gram matrix. Chuan Li and Michael Wand used markov random fields to calculate an alternative to the Gram matrix entirely \\cite{Li:3}. Other style loss functions that noteworthy but not too relevant to delve into here are histogram loss \\cite{Risser:1} and coral loss \\cite{sun:1}\n\\newline\\newline\nAnother possible loss function component for video style transfer is the temporal loss. As temporal loss has only been mentioned in the Ruder et al. \\cite{Ruder:1} paper we will just briefly go some that are described here. To go from picture style transfer to video style transfer we can introduce a temporal loss to avoid flickering, meaning that we should punish adjacent frames for being too different from each other.The easiest way to do this is to just look at the difference between the current frame and the previous one and use the difference of the generated frame and the previous frame as a part of the loss function. This can however create some issues in the resulting video, as there are some parts of each image that should change between frames, and other parts that should not. A better way is to add weights for this loss function, penalizing the model for having difference on only the frames that are supposed to be the same. This is known as short-term temporal loss. Long-term temporal loss is doing the same but looking further back in multiple previous frames for occluded areas that are disoccluded in the current frame. This loss function tries to make areas occluded by moving objects stay the same when disoccluded again. However, this requires a lot of additional computation. \n\\newline\\newline\nAfter applying style transfer on an image with Gatys et al \\cite{Gatys:1}, we can end up with an image with many high frequency artifacts. To get rid of these variations in the output image, we want to penalize local variation. We can define this local variation loss as\n\\begin{equation}\n    \\sum{|y_{i+1}-y_i|^\\beta}\n\\end{equation}\nwhere $\\beta\\in\\{1,2\\}.$ Here $y$ are the pixel-values in one row of the output image \\cite{Zhaoyou:1}. Now we can extend Equation (\\ref{eq:total_loss}) with the total variation loss\n\\begin{equation}\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})+\\lambda\\mathcal{L}_\\text{TV}(\\vec{x})\n\\end{equation}\nwhere $\\lambda$ is the weight for the total variation loss.\n\\newpage", "meta": {"hexsha": "8726eec494871f83f61585d0b127215b754b39a1", "size": 3928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Background/loss-functions.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/loss-functions.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/loss-functions.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": 196.4, "max_line_length": 1308, "alphanum_fraction": 0.7902240326, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038221, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.6684280114041513}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{natbib}\n\\usepackage{amssymb,amsmath}\n\n\\begin{document}\n\n\\title{Simple Epidemiological Models.}\n\n\\maketitle\n\n\\section{SIR model}\n\nThe susceptible-infected-recovered (SIR) model in a closed population was\nproposed by~\\cite{kermack1927contribution} as a special case of a more general\nmodel, and forms the framework of many compartmental models.  Susceptible\nindividuals, $S$, are infected by infected individuals, $I$, at a per-capita\nrate $\\beta I$, and infected individuals recover at a per-capita rate $\\gamma$\nto become recovered individuals, $R$.\n\n\\begin{align}\n\\frac{dS(t)}{dt} &= -\\beta S(t) I(t)\\\\\n\\frac{dI(t)}{dt} &= \\beta S(t) I(t)- \\gamma I(t)\\\\\n\\frac{dR(t)}{dt} &= \\gamma I(t)\n\\end{align}\n\n\\section{SEIR model}\n\nThe susceptible-exposed-infected-recovered (SEIR) model extends the SIR model\nto include an exposed but non-infectious class. The implementation in this\nsection considers proportions of susceptibles, exposed, infectious individuals\nin an open population, with no additional mortality associated with infection\n(such that the population size remains constant and $R$ is not modelled\nexplicitly).\n\n\\begin{align}\n\\frac{dS(t)}{dt} &= \\mu-\\beta S(t) I(t) - \\mu S(t)\\\\\n\\frac{dE(t)}{dt} &= \\beta S(t) I(t)- (\\sigma + \\mu) E(t)\\\\\n\\frac{dI(t)}{dt} &= \\sigma E(t)- (\\gamma + \\mu) I(t)\\\\\n\\frac{dR(t)}{dt} &= \\gamma I(t) = \\mu R\n\\end{align}\n\n\\bibliographystyle{plain}\n\\bibliography{main}\n\n\\end{document}\n", "meta": {"hexsha": "f77db568925807c01e801d4eaeace42a116f53ca", "size": 1479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "development_data/SIR-SEIR_models_latex_and_json/main.tex", "max_stars_repo_name": "mikiec84/automates", "max_stars_repo_head_hexsha": "62b65689ce39f6a3a89310a8d3c8c0e1eb5feb11", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-12T01:49:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-12T01:49:00.000Z", "max_issues_repo_path": "development_data/SIR-SEIR_models_latex_and_json/main.tex", "max_issues_repo_name": "mikiec84/automates", "max_issues_repo_head_hexsha": "62b65689ce39f6a3a89310a8d3c8c0e1eb5feb11", "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": "development_data/SIR-SEIR_models_latex_and_json/main.tex", "max_forks_repo_name": "mikiec84/automates", "max_forks_repo_head_hexsha": "62b65689ce39f6a3a89310a8d3c8c0e1eb5feb11", "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.8125, "max_line_length": 78, "alphanum_fraction": 0.7187288709, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6684036906214897}}
{"text": "\\chapter{Signals \\& Systems}\n\n\\section{What is a system?}\n\nA system is defined as a grouping of elements to be \nanalysed together. They can be categorised as linear or \nnon-linear, depending on the equations used to \ndescribe them.\nLinear systems are considered to be idealised systems, \nwhilst non-linear systems are those representing real-world \nconditions.\n\nSystems may also be categorised based on the\n\\emph{order} of their differential equations. Some examples \nof categorised systems are shown in table \\ref{table: \nexamples of systems}.\n\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c|cc}\n & Linear & Non-Linear\\\\\n \\hline\n1st order & RC circuit & Population growth\\\\\n2nd order & Spring Mass Damper & Pendulum\\\\\n3rd order & - & Chaotic Systems\\\\\n... & ...  & ... \\\\\nNth order & Wave Equation & General Relativity\\\\\n\\hline\n\\end{tabular}\n\\label{table: examples of systems}\n\\caption{Examples of linear and non-linear systems.}\n\\end{table}\n\n\\section{Linear Systems}\nA system is considered linear if they meet the following \ntwo principles: \n\n\\begin{itemize}\n \\item Proportionality. Given an input $t$, the system will \nreturn an output $f(t)$, and if given an input $\\alpha t$ \nthe system will return an output $f(\\alpha t) = \\alpha \nf(t)$.\n \\item Superposition. Given inputs $t_1$ and $t_2$, the \nsystem will return outputs $f(t_1)$ and $f(t_2)$ \nrespectively. If given an input $t_1 + t_2$ the system will \nreturn an output $f(t_1 + t_2) = f(t_1) + f(t_2)$.\n\\end{itemize}\n\n\\subsection{Exercise: Linear systems}\nGiven the following equations, determine if they belong to \nlinear systems or not.\n\n\\textbf{Case 1:} $f(s) = 3s$. Evaluating the function to \ntest proportionality, we obtain the following:\n\n\\begin{equation*}\n \\begin{split}\n  f(2s) & =3(2s)\\\\\n  & = 6 s\\\\\n  2 f(s) &= 2 (3s)\\\\\n  &= 6s\\\\\n  f(2s)&=2f(s)\n \\end{split}\n\\end{equation*}\n\nFor the superposition principle, we have:\n\\begin{equation*}\n \\begin{split}\n  f(s_1) & =3s_1\\\\\n  f(s_2) & =3s_2\\\\\n  f(s_1+s_2) & =3(s_1+s_2)\\\\\n   &= 3s_1 + 3s_2\\\\\n  f(s_1 + s_2) & = f(s_1) + f(s_2)\n \\end{split}\n\\end{equation*}\n\nWe conclude that case 1 is linear.\n\n% \\vspace*{1cm}\n\nAn equation can be tested to meet both principles \nsimultaneously. Let $s=\\alpha(s_1+s_2)$ and $f(s)$ be the \noutput of the system. A system is linear if the following \ncondition is met:\n\n\\begin{equation}\n  f(\\alpha(s_1+s_2))  = \\alpha f(s_1) + \\alpha f(s_2)\n  \\label{eq: proportionality and superposition}\n\\end{equation}\n\nEvaluating \\ref{eq: proportionality and superposition} for \ncase 1 as an example:\n\n\\begin{equation*}\n\\begin{split}\n f(\\alpha (s_1 + s_2)) & = 3 (\\alpha (s_1 + s_2))\\\\\n & = 3 \\alpha s_1 + 3 \\alpha s_2\\\\\n f(\\alpha s) & = 3 \\alpha s \\\\\n f(\\alpha (s_1 + s_2)) & = \\alpha f(s_1) + \\alpha f(s_2)\n\\end{split}\n\\end{equation*}\n\n\\textbf{Case 2:} $f(s) = 3s + 1$.\n\n\\begin{equation*}\n \\begin{split}\n  f(\\alpha s) & = 3 \\alpha  s +1\\\\\n  \\alpha f(s) & = 3 \\alpha s + \\alpha\\\\\n  f(\\alpha s) & \\neq \\alpha f(s)\\\\\n  f(s_1) + f(s_2) & = 3 s_1 + 3 s_2 + 2\\\\\n  f(s_1 + s_2) & = 3 (s_1+s_2) + 1\\\\\n  f(s_1 +s_2) & \\neq f(s_1) + f(s_2)\n \\end{split}\n\\end{equation*}\n\n\nCase 2 is non-linear.\n\n% \\vspace*{1cm}\n\n\\textbf{Case 3:} $f(s) = 0.5 \\cos (0.1 s) $\n\n\\begin{equation*}\n \\begin{split}\n  f(\\alpha s) & = 0.5 \\cos (0.1 \\alpha s)\\\\\n  \\alpha f(s) & = 0.5 \\alpha \\cos (0.1 s)\\\\\n  f(\\alpha s) & \\neq \\alpha f(s)\\\\\n  f(s_1) + f(s_2) & = 0.5 \\cos (0.1 s_1) + 0.5 \\cos (0.1 \ns_2) \\\\\n  f(s_1 + s_2) & = 0.5 \\cos (0.1 s_1 + 0.1 s_2)\\\\\n  f(s_1 + s_2) & \\neq f(s_1) + f(s_2)\n \\end{split}\n\\end{equation*}\n\n\nCase 3 is non-linear.\n\n% \\vspace*{1cm}\n\n\\textbf{Case 4:} $f(s) = 1.2 \\mathrm{e}^{0.1 s}$\n\n\\begin{equation*}\n \\begin{split}\nf(\\alpha (s_1+s_2))  & = 1.2 \\mathrm{e}^{0.1 \\alpha (s_1 + \ns_2)}\\\\\n\\alpha f(s_1) & = 1.2 \\alpha \\mathrm{e}^{0.1 s_1}\\\\\n\\alpha f(s_1) + \\alpha f(s_2) & = 1.2 \\alpha \n(\\mathrm{e}^{0.1 s_1} + \\mathrm{e}^{0.1 s_2})\\\\\nf(\\alpha (s_1+s_2))  & \\neq \\alpha f(s_1) + \\alpha f(s_2)\n \\end{split}\n\\end{equation*}\n\n\nCase 4 is non-linear.\n\n% \\vspace*{1cm}\n\n\\textbf{Case 5:} $f(s) = \\int\\limits_0^t s(t)dt$\n\\begin{equation*}\n \\begin{split}\nf(\\alpha (s_1 + s_2))  & = \\alpha \\int\\limits_0^t \n\\Bigl( s_1(t)+s_2(t) \\Bigr)  dt\\\\\n& = \\alpha \\int\\limits_0^t \ns_1(t)dt + \\alpha \\int\\limits_0^t \ns_2(t)dt\\\\\n\\alpha f(s_1) + \\alpha f(s_2) & = \\alpha \\int\\limits_0^t \ns_1(t)dt + \\alpha \\int\\limits_0^t \ns_2(t)dt\\\\\nf(\\alpha (s_1+s_2))  & = \\alpha f(s_1) + \\alpha f(s_2)\n \\end{split}\n\\end{equation*}\n\nCase 5 is linear.\n\n% \\vspace*{1cm}\n\n\\textbf{Case 6:} $f(s) = \\frac{ds(t)}{dt}$\n\n\\begin{equation*}\n \\begin{split}\nf(\\alpha (s_1 + s_2))  & =  \\alpha \n\\frac{d \\Bigl (s_1(t)+s_2(t) \\Bigr)}{dt}\\\\\n& = \\alpha \\frac{d s_1(t)}{dt} + \\alpha \\frac{d \ns_2(t)}{dt} \\\\\n\\alpha f(s_1) + \\alpha f(s_2) & = \\alpha \\frac{d s_1(t)}{dt} \n+ \\alpha \\frac{d s_2(t)}{dt} \\\\\nf(\\alpha (s_1+s_2))  & = \\alpha f(s_1) + \\alpha f(s_2)\n \\end{split}\n\\end{equation*}\n\nCase 6 is linear.\n\nNote that for all equations $\\alpha \\neq 1$ because using \nthe identity is not valid for proving compliance.\n\n\\subsection{Order of a system}\n\nThe order of a system is dependent on the highest order of \nderivatives in the equations that describe it. A system \nwith no derivative terms is a \\emph{zero order} system, a \nsystem with a differential equation of order 1 is a \n\\emph{first-order} system, and so on.\n\nRevisiting the cases shown in Exercise 1, we can classify \nthe systems depending on their order as well. Table \n\\ref{table: exercise 1 order} contains the classification \nof each case.\n\n\\begin{table}[t]\n\\centering\n\\begin{tabular}{c|cc}\nEquation & Type & Order\\\\\n\\hline\n$3s$ & Linear & 0\\\\\n$3s + 1$ & Non-linear & 0\\\\\n$0.5 \\cos (0.1 s)$ & Non-Linear & 0\\\\\n$1.2 \\mathrm{e}^{0.1s}$ & Non-Linear & 0\\\\\n$\\int\\limits_0^{t} s(t)dt$ & Linear & 0\\\\\n$\\frac{d s(t)}{dt}$ & Linear & 1\\\\\n\\hline\n\\end{tabular}\n\\label{table: exercise 1 order}\n\\caption{Classification of systems.}\n\\end{table}\n\n\\section{Example: Spring-Mass-Damper System}\n\nThe Spring-Mass-Damper System (abbreviated SMD) is the most \ncommonly used abstraction for systems. Depending on the \ninitial conditions of the systems, it may or may not be \nlinear. An example is presented below.\n\nGiven the forces interacting in the Free Body Diagram, the \nsystem's equation is obtained as follows:\n\n\\begin{equation}\n \\begin{split}\n  \\sum F & = 0\\\\\n  F_s(t) + F_d(t) - F(t) & = 0\\\\\n \\end{split}\n \\label{eq: sum of forces - week01}\n\\end{equation}\n\nRecall the equations for springs and dampers, substituting \nthem in \\eqref{eq: sum of forces - week01}.\n\n\\begin{equation*}\n \\begin{split}\n  F_s & = b \\dot{x}\\\\\n  F_d & = k x(t)\\\\\n  b \\dot{x} + k x(t) & = F(t)\n \\end{split}\n\\end{equation*}\n\nRewriting the equation into the form $\\dot x + f(t) x(t) = \ng(t)$.\n\n\\begin{equation}\n \\dot{x} + \\frac{k}{b} x(t) = \\frac{1}{b} F(t)\n \\label{eq: system equation}\n\\end{equation}\n\n\\subsection{Linear System Case}\n\nSolving the system via Laplace Transforms to obtain an \nequation for x(t). Consider $x(0) = 0$ as the initial \ncondition.\n\n\\begin{equation}\n \\begin{split}\n  \\mathfrak{L} \\Bigl \\{ \\dot{x} + \\frac{k}{b} x(t)  = \n\\frac{1}{b} F(t) \\Bigr \\} & \\xrightarrow{} s \\mathcal{X} - \nx(0) + \\frac{k}{b} \\mathcal{X} = \\frac{1}{b} \\mathcal{F}\n \\end{split}\n \\label{eq: general laplace transform}\n\\end{equation}\n\nEvaluating $x(0)=0$ gives us the system equation in the \nfrequency domain.\n\n\\begin{equation}\n s \\mathcal{X} + \\frac{k}{b} \\mathcal{X} = \\frac{1}{b}\n\\mathcal{F}\n\\label{eq: laplace transform}\n\\end{equation}\n\nSolve \\ref{eq: laplace transform} for $\\mathcal{X}$ and \nthen obtain the inverse Laplace transform of the equation.\n\n\\begin{equation*}\n \\begin{split}\n  \\mathcal{X} (s + \\frac{k}{b}) & = \\frac{1}{b} \n\\mathcal{F}\\\\\n\\mathcal{X} & = \\frac{1}{b} \\frac{1}{s + \\frac{k}{b}}\n\\mathcal{F}\\\\\n \\end{split}\n\\end{equation*}\n\n\n\\begin{equation}\n \\begin{split}\n  \\mathfrak{L}^{-1} \\Bigl \\{ \\mathcal{X}  = \\frac{1}{b} \n\\frac{1}{s + \\frac{k}{b}}\n\\mathcal{F}   \\Bigr\\} & \\xrightarrow{} x(F(t)) = \n\\frac{1}{b} \\mathrm{e}^{-\\frac{k}{b}t} F(t)\n \\end{split}\n \\label{eq: linear system equation}\n\\end{equation}\n\nTesting the principles of proportionality and superposition \non \\ref{eq: linear system equation} we have\n\n\\begin{equation*}\n \\begin{split}\n  x(\\alpha (F_1 + F_2)) & = \\frac{\\alpha}{b} \n\\mathrm{e}^{-\\frac{k}{b}t} (F_1 + F_2)\\\\\n\\alpha x(F_1) & = \\frac{\\alpha}{b} \n\\mathrm{e}^{-\\frac{k}{b}t} F_1\\\\\n\\alpha x(F_1) + \\alpha x(F_2) & = \\frac{\\alpha}{b} \n\\mathrm{e}^{-\\frac{k}{b}t} (F_1 + F_2)\\\\\nx(\\alpha (F_1 + F_2)) & = \\alpha x(F_1) + \\alpha x(F_2)\n \\end{split}\n\\end{equation*}\n\nWe confirm that the system is linear for an initial \ncondition of $x(0)=0$.\n", "meta": {"hexsha": "f8bd63571fc0198c9a07e96328ee774d7c625b26", "size": 8555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/week01.tex", "max_stars_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_stars_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/tex/week01.tex", "max_issues_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_issues_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/tex/week01.tex", "max_forks_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_forks_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0823170732, "max_line_length": 61, "alphanum_fraction": 0.6398597312, "num_tokens": 3379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893519999, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6684036852399075}}
{"text": "\\section{Partial Differentiation}\\label{sec:PartialDifferentiation}\n\nThe derivative of a function of a single variable tells us how quickly\nthe value of the function changes as the value of the independent variable\nchanges. Intuitively, it tells us how ``steep'' the graph of the function is.\nWe might wonder if there is a similar idea for graphs of functions\nof two variables, that is, surfaces. It is\nnot clear that this has a simple answer, nor how we might proceed. We\nwill start with what seem to be very small steps toward the goal.\nSurprisingly, it turns out that these simple ideas hold the keys to a\nmore general understanding.\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/parabolic_crosssection.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{The intersection of a plane $x+y=1$ and the surface $f(x,y)=x^2+y^2$}\n\\label{fig:parabolic bowl cross-section}\n\\end{figure}\n\nThe derivative of a single-variable function $f(x)$ tells us how much $f(x)$\nchanges as $x$ increases. The obvious analogue for a function of two\nvariables $g(x,y)$ would be something that tells us how quickly $g(x,y)$\nincreases as $x$ and $y$ increase. However, in most cases this will depend on\nhow quickly $x$ and $y$ are changing relative to each other.\n\n\\begin{example}{}{}\nAnalyze $f(x,y)=y^2$.\n\\end{example}\n\\begin{solution}\nIf we look at a point $(x,y,y^2)$ on this surface, the value of a function\ndoes not change at all if we fix $y$ and let $x$ increase, but increases like $y^2$\nif we fix $x$ and let $y$ increase.\n\\end{solution}\n\nNow let us consider what happens to $f(x,y)$ when both $x$ and $y$ are\nincreasing, perhaps at different rates. We can think of this as being a\nmovement in a certain direction of a point in the $x,y$-plane. A point and a\ndirection defines a line in the $x,y$-plane, and so we are asking how the function\nchanges as we move along this line.\n\nLet us then imagine a plane perpendicular to the $x,y$-plane that intersects\nthe the $x,y$-plane along this line. This plane will intersect the surface of\n$f$ in a curve, so we can just look at the behaviour of this curve in the given plane.\n\nFigure~\\ref{fig:parabolic bowl cross-section} shows the plane $x+y=1$, which\nis the plane perpendicular to the line $x+y=1$ in the $x,y$-plane.\nObserve that its intersection with the surface of $f$ is a curve, in fact, a parabola.\nWe will refer to such a curve as the cross-section of the surface above the line in\nthe $x,y$-plane.\n\nWe can now look at the rate of change (or slope) of $f$ in a particular\ndirection by looking at the slope of a curve in a plane --- something we\nalready have experience with.\n\nLet's start by looking at some particularly\neasy lines: Those parallel to the $x$ or $y$ axis. Suppose we are\ninterested in the cross-section of $f(x,y)$ above the line $y=b$. If\nwe substitute $b$ for $y$ in $f(x,y)$, we get a function in one\nvariable, describing the height of the cross-section as a function of\n$x$. Because $y=b$ is parallel to the $x$-axis, if we view it from a\nvantage point on the negative $y$-axis, we will see what appears to be\nsimply an ordinary curve in the $x$-$z$ plane.\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 4, y from 0 to 1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/parabolic_crosssection2.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/parabolic_crosssection3.eps}}} at 2.5 0\n\\endpicture}}\n%\\endtexonly\n\\caption{$f(x,y)=x^2 + y^2$, cut by the plane $y=2$}\n\\label{fig:parabolic bowl cross-section two}\n\\end{figure}\n\nConsider again the parabolic surface $f(x,y)=x^2+y^2$. The\ncross-section above the line $y=2$ consists of all points\n$(x,2,x^2+4)$. Looking at this cross-section we see what appears to be just the curve\n$f(x)=x^2+4$. At any point on the cross-section, $(a,2,a^2+4)$, the\nslope of the surface \\emph{in the direction of the line} $y=2$ is\n  simply the slope of the curve $f(x)=x^2+4$, namely $2x$.\nFigure~\\ref{fig:parabolic bowl cross-section two} shows the same\nparabolic surface as before, but now cut by the plane $y=2$. The left\ngraph shows the cut-off surface, the right shows just the\ncross-section. \n\nIf, for example, we're interested in the point $(-1,2,5)$ on the surface, then\nthe slope in the direction of the line $y=2$ is $2x=2(-1)=-2$. This\nmeans that starting at $(-1,2,5)$ and moving on the surface, above the\nline $y=2$, in the direction of increasing $x$ values, the surface\ngoes down; of course moving in the opposite direction, toward\ndecreasing $x$ values, the surface will rise.\n\nIf we're interested in some other line $y=k$, there is really no\nchange in the computation. The equation of the cross-section above\n$y=k$ is $x^2+k^2$ with derivative $2x$. We can save ourselves the\neffort, small as it is, of substituting $k$ for $y$: all we are in\neffect doing is temporarily assuming that $y$ is some constant. With\nthis assumption, the derivative ${d\\over dx}(x^2+y^2)=2x$. To\nemphasize that we are only temporarily assuming $y$ is constant, we\nuse a slightly different notation: ${\\partial\\over \\partial\n  x}(x^2+y^2)=2x$; the ``$\\partial$'' reminds us that there are more\nvariables than $x$, but that only $x$ is being treated as a variable.\nWe read the equation as ``the partial derivative of $(x^2+y^2)$ with\nrespect to $x$ is $2x$.'' A convenient alternate notation for the\npartial derivative of $f(x,y)$ with respect to $x$ is\nis $f_x(x,y)$.\n\n\\begin{example}{Partial Derivative with respect to $x$}{PartialDerOne}\nFind the partial derivative with respect to $x$ of $x^3+3xy$.\n\\end{example}\n\\begin{solution}\nThe partial derivative with respect to $x$ of \n$x^3+3xy$ is $3x^2+3y$. Note that the partial derivative includes the\nvariable $y$, unlike the example $x^2+y^2$. It is somewhat unusual for\nthe partial derivative to depend on a single variable; this example is\nmore typical.\n\\end{solution}\n\nOf course, we can do the same sort of calculation for lines parallel\nto the $y$-axis. We temporarily hold $x$ constant, which gives us the\nequation of the cross-section above a line $x=k$. We can then compute\nthe derivative with respect to $y$; this will measure the slope of\nthe curve in the $y$ direction.\n\n\\begin{example}{Partial Derivative with respect to $y$}{PartialDerTwo}\nFind the partial derivative with respect to $y$ of $f(x,y)=\\sin(xy)+3xy$.\n\\end{example}\n\\begin{solution}\nThe partial derivative with respect to $y$ of \n$f(x,y)=\\sin(xy)+3xy$ is \n$$f_y(x,y)={\\partial\\over\\partial y}\\sin(xy)+3xy=\\cos(xy){\\partial\\over\\partial\n  y}(xy)+ 3x=x\\cos(xy)+3x.\n$$\n\\end{solution}\n\nSo far, using no new techniques, we have succeeded in measuring the\nslope of a surface in two quite special directions. For functions of\none variable, the derivative is closely linked to the notion of\ntangent line. For surfaces, the analogous idea is the tangent\nplane---a plane that just touches a surface at a point, and has the\nsame slope as the surface in all directions. Even though we\nhaven't yet figured out how to compute the slope in all directions, we\nhave enough information to find tangent planes. Suppose we want the\nplane tangent to a surface at a particular point $(a,b,c)$. If we compute the\ntwo partial derivatives of the function for that point, we get enough\ninformation to determine two lines tangent to the surface, both \nthrough $(a,b,c)$ and both tangent to the surface in their respective\ndirections. These two lines determine a plane, that is, there is\nexactly one plane containing the two lines: the tangent\nplane. Figure~\\ref{fig:sphere with tangent plane} \nshows (part of) two tangent lines at a point,\nand the tangent plane containing them. \n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 3, y from 0 to 1\n\\put {\\hbox{\\epsfxsize4cm\\epsfbox{images/tangent_vectors.eps}}} at 0 -0.15\n\\put {\\hbox{\\epsfxsize5.8cm\\epsfbox{images/tangent_plane.eps}}} at 2.5 0\n\\endpicture}}\n%\\endtexonly\n\\caption{Tangent vectors and tangent plane.}\n\\label{fig:sphere with tangent plane}\n\\end{figure}\n\nHow can we discover an equation for this tangent plane? We know a\npoint on the plane, $(a,b,c)$; we need a vector normal to the\nplane. If we can find two vectors, one parallel to each of the tangent\nlines we know how to find, then the cross product of these vectors\nwill give the desired normal vector.\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 4.1, y from 0 to 3.1\n\\axis left ticks numbered from 0 to 3 by 1 /\n\\axis bottom ticks numbered from 0 to 4 by 1 /\n\\put {$z$} [b] <0pt,3pt> at 0 3.1\n\\put {$x$} [l] <3pt,0pt> at 4.1 0\n\\put {$f_x(2,b)$} [l] <3pt,0pt> at 3 1.35\n\\putrule from 2 1.17 to 3 1.17\n\\putrule from 3 1.17 to 3 1.5\n\\setlinear\n%\\plot 2 1.17 3 1.5 /\n\\arrow <5pt> [0.17, 0.5] from 2 1.17 to 3 1.5\n\\setquadratic\n\\plot 0.000 1.167 0.100 1.135 0.200 1.107 0.300 1.082 0.400 1.060 \n0.500 1.042 0.600 1.027 0.700 1.015 0.800 1.007 0.900 1.002 \n1.000 1.000 1.100 1.002 1.200 1.007 1.300 1.015 1.400 1.027 \n1.500 1.042 1.600 1.060 1.700 1.082 1.800 1.107 1.900 1.135 \n2.000 1.167 2.100 1.202 2.200 1.240 2.300 1.282 2.400 1.327 \n2.500 1.375 2.600 1.427 2.700 1.482 2.800 1.540 2.900 1.602 \n3.000 1.667 3.100 1.735 3.200 1.807 3.300 1.882 3.400 1.960 \n3.500 2.042 3.600 2.127 3.700 2.215 3.800 2.307 3.900 2.402 \n4.000 2.500 /\n%0.000 1.333 0.100 1.270 0.200 1.213 0.300 1.163 0.400 1.120 \n%0.500 1.083 0.600 1.053 0.700 1.030 0.800 1.013 0.900 1.003 \n%1.000 1.000 1.100 1.003 1.200 1.013 1.300 1.030 1.400 1.053 \n%1.500 1.083 1.600 1.120 1.700 1.163 1.800 1.213 1.900 1.270 \n%2.000 1.333 2.100 1.403 2.200 1.480 2.300 1.563 2.400 1.653 \n%2.500 1.750 2.600 1.853 2.700 1.963 2.800 2.080 2.900 2.203 \n%3.000 2.333 3.100 2.470 3.200 2.613 3.300 2.763 3.400 2.920 \n%3.500 3.083 3.600 3.253 3.700 3.430 3.800 3.613 3.900 3.803 \n%4.000 4.000 / \n\\endpicture}}\n%\\endtexonly\n\\caption{A tangent vector.}\n\\label{fig:tangent vector}\n\\end{figure}\n\nHow can we find vectors parallel to the tangent lines? Consider first\nthe line tangent to the surface above the line $y=b$. A vector\n$\\langle u,v,w\\rangle$ parallel to this tangent line must have $y$\ncomponent $v=0$, and we may as well take the $x$ component to be\n$u=1$. The ratio of the $z$ component to the $x$ component is the\nslope of the tangent line, precisely what we know how to compute. The\nslope of the tangent line is $f_x(a,b)$, so\n$$ f_x(a,b)={w\\over u} ={w\\over1} = w.$$\nIn other words, a vector parallel to this tangent line is\n$\\langle 1,0,f_x(a,b)\\rangle$, as shown in Figure~\\ref{fig:tangent vector}. \nIf we repeat the reasoning for the\ntangent line above $x=a$, we get the vector $\\langle\n0,1,f_y(a,b)\\rangle$.\n\nNow to find the desired normal vector we compute the cross product,\n$\\langle 0,1,f_y\\rangle\\times\\langle 1,0,f_x\\rangle=\n\\langle f_x,f_y,-1\\rangle$. From our earlier discussion of planes, we\ncan write down the equation we seek: $f_x(a,b)x+f_y(a,b)y-z=k$, and\n$k$ as usual can be computed by substituting a known point:\n$f_x(a,b)(a)+f_y(a,b)(b)-c=k$. There are various more-or-less nice\nways to write the result:\n\\begin{align*}\n&f_x(a,b)x+f_y(a,b)y-z=f_x(a,b)a+f_y(a,b)b-c\t\\\\\n&f_x(a,b)x+f_y(a,b)y-f_x(a,b)a-f_y(a,b)b+c=z\t\\\\\n&f_x(a,b)(x-a)+f_y(a,b)(y-b)+c=z\t\\\\\n&f_x(a,b)(x-a)+f_y(a,b)(y-b)+f(a,b)=z\t\\\\\n\\end{align*}\n\n\\begin{example}{Tangent Plane to a Sphere}{TangentPlaneSphere}\nFind the plane tangent to $x^2+y^2+z^2=4$ at\n$(1,1,\\sqrt2)$.\n\\end{example}\n\\begin{solution}\nThe point $(1,1,\\sqrt2)$ is on the upper hemisphere, so \nwe use $\\ds f(x,y)=\\sqrt{4-x^2-y^2}$. Then \n$\\ds f_x(x,y)=-x(4-x^2-y^2)^{-1/2}$ and $\\ds\nf_y(x,y)=-y(4-x^2-y^2)^{-1/2}$, so $f_x(1,1)=f_y(1,1)=-1/\\sqrt2$\nand the equation of the plane is \n$$z=-{1\\over\\sqrt2}(x-1)-{1\\over\\sqrt2}(y-1)+\\sqrt2.$$\nThe hemisphere and this tangent plane are pictured in\nFigure~\\ref{fig:sphere with tangent plane}.\n\\end{solution}\n\nSo it appears that to find a tangent plane, we need only find two\nquite simple ordinary derivatives, namely $f_x$ and $f_y$. This is\ntrue {\\em if the tangent plane exists}. It is, unfortunately, not\nalways the\ncase that if $f_x$ and $f_y$ exist there is a tangent plane. \nConsider the function  $xy^2/(x^2+y^4)$ with $f(0,0)$ defined to be 0, pictured in \nFigure~\\ref{fig:weird limit}. This function has value 0 when $x=0$\nor $y=0$. Now it's clear that $f_x(0,0)=f_y(0,0)=0$, because in the\n$x$ and $y$ directions the surface is simply a horizontal line. But\nit's also clear from the picture that this surface does not have\nanything that deserves to be called a tangent plane at the origin,\ncertainly not the $x$-$y$ plane containing these two tangent lines.\n\nWhen does a surface have a tangent plane at a particular point? What\nwe really want from a tangent plane, as from a tangent line, is that\nthe plane be a ``good'' approximation of the surface near the\npoint. Here is how we can make this precise:\n\n\\begin{definition}{Tangent Plane}{TangentPlaneDefinition}\nLet $\\Delta x=x-x_0$, $\\Delta y=y-y_0$, and $\\Delta z=z-z_0$\nwhere $z_0=f(x_0,y_0)$. The\nfunction $z=f(x,y)$ is differentiable\\index{differentiable} at\n$(x_0,y_0)$ if\n$$\\Delta z=f_x(x_0,y_0)\\Delta x+f_y(x_0,y_0)\\Delta y+\\epsilon_1\\Delta\nx + \\epsilon_2\\Delta y,$$ where both $\\epsilon_1$ and $\\epsilon_2$\napproach 0 as $(x,y)$ approaches $(x_0,y_0)$.\\index{tangent plane}\n\\end{definition}\n\nThis definition takes a bit of absorbing. Let's rewrite the central\nequation a bit:\n\\begin{equation}\\label{eq:f is differentiable}\nz=f_x(x_0,y_0)(x-x_0)+f_y(x_0,y_0)(y-y_0)+f(x_0,y_0)+\n\\epsilon_1\\Delta x + \\epsilon_2\\Delta y.\n\\end{equation}\nThe first three terms on\nthe right are the equation of the tangent plane, that is,\n$$f_x(x_0,y_0)(x-x_0)+f_y(x_0,y_0)(y-y_0)+f(x_0,y_0)$$\n is the $z$-value\nof the point on the plane above $(x,y)$. \nEquation~\\ref{eq:f is differentiable} says that\nthe $z$-value of a point on the surface is equal to the $z$-value of a\npoint on the plane plus a ``little bit,'' namely $\\epsilon_1\\Delta x +\n\\epsilon_2\\Delta y$. As $(x,y)$ approaches $(x_0,y_0)$, both $\\Delta\nx$ and $\\Delta y$ approach 0, so this little bit $\\epsilon_1\\Delta x +\n\\epsilon_2\\Delta y$ also approaches 0, and the $z$-values on the\nsurface and the plane get close to each other. But that by itself is\nnot very interesting: since the surface and the plane both contain the\npoint $(x_0,y_0,z_0)$, the $z$ values will approach $z_0$ and hence\nget close to each other whether the tangent plane is ``tangent'' to\nthe surface or not. The extra condition in the definition says that as\n$(x,y)$ approaches $(x_0,y_0)$, the $\\epsilon$ values approach\n0---this means that $\\epsilon_1\\Delta x + \\epsilon_2\\Delta y$\napproaches 0 much, much faster, because $\\epsilon_1\\Delta x$ is much\nsmaller than either $\\epsilon_1$ or $\\Delta x$. It is this extra\ncondition that makes the plane a tangent plane.\n\nWe can see that the extra condition on $\\epsilon_1$ and $\\epsilon_2$\nis just what is needed if we look at partial derivatives. Suppose we\ntemporarily fix $y=y_0$, so $\\Delta y=0$. Then the equation from the\ndefinition becomes\n$$\\Delta z=f_x(x_0,y_0)\\Delta x+\\epsilon_1\\Delta x$$\nor\n$${\\Delta z\\over\\Delta x}=f_x(x_0,y_0)+\\epsilon_1.$$\nNow taking the limit of the two sides as $\\Delta x$ approaches 0, the\nleft side turns into the partial derivative of $z$ with respect to\n$x$ at $(x_0,y_0)$, or in other words $f_x(x_0,y_0)$, and the right\nside does the same, because as $(x,y)$ approaches $(x_0,y_0)$,\n$\\epsilon_1$ approaches 0. Essentially the same calculation works for \n$f_y$.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:PartialDifferentiation}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)=\\cos(x^2y)+y^3$.\n\\begin{sol}\n$-2xy\\sin(x^2y)$, $-x^2\\sin(x^2y)+3y^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)={xy\\over x^2+y}$.\n\\begin{sol}\n$(y^2-x^2y)/(x^2+y)^2$, $x^3/(x^2+y)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)=e^{x^2+y^2}$.\n\\begin{sol}\n$2xe^{x^2+y^2}$, $2ye^{x^2+y^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)=xy\\ln(xy)$.\n\\begin{sol}\n$y\\ln(xy)+y$, $x\\ln(xy)+x$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)=\\sqrt{1-x^2-y^2}$.\n\\begin{sol}\n$-x/\\sqrt{1-x^2-y^2}$, $-y/\\sqrt{1-x^2-y^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)=x\\tan(y)$.\n\\begin{sol}\n$\\tan y$, $x\\sec^2 y$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $f_x$ and $f_y$ where $\\ds f(x,y)={1\\over xy}$.\n\\begin{sol}\n$-1/(x^2y)$, $-1/(xy^2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane tangent to \n$\\ds 2x^2+3y^2-z^2=4$ at\n$(1,1,-1)$. \n\\begin{sol}\n$z=-2(x-1)-3(y-1)-1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane tangent to \n$\\ds f(x,y)=\\sin(xy)$ at\n$(\\pi,1/2,1)$. \n\\begin{sol}\n$z=1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane tangent to \n$\\ds f(x,y)=x^2+y^3$ at\n$(3,1,10)$. \n\\begin{sol}\n$z=6(x-3)+3(y-1)+10$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:ln tan plane}\nFind an equation for the plane tangent to \n$\\ds f(x,y)=x\\ln(xy)$ at\n$(2,1/2,0)$. \n\\begin{sol}\n$z=(x-2)+4(y-1/2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the line normal to \n$\\ds x^2+4y^2=2z$ at\n$(2,1,4)$. \n\\begin{sol}\n${\\bf r}(t)=\\langle 2,1,4\\rangle+t\\langle 2,4,-1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nExplain in your own words why, when taking a partial derivative\nof a function of multiple variables, we can treat the variables not\nbeing differentiated as constants.\n\\end{ex}\n\n\\begin{ex}\nConsider a differentiable function, $f(x,y)$.  Give physical\n  interpretations of the meanings of $f_x(a,b)$ and $f_y(a,b)$ as they\n  relate to the graph of $f$.\n\\end{ex}\n\n\\begin{ex}\nIn much the same way that we used the tangent line to\n  approximate the value of a function from single variable calculus,\n  we can use the tangent plane to approximate a function from\n  multivariable calculus.  Consider the tangent plane found in\n  Exercise~\\ref{ex:ln tan plane}. Use this plane to approximate\n  $f(1.98, 0.4)$.\n\\end{ex}\n\n\\begin{ex}\n\tThe volume of a cylinder is given by $V=\\pi r^2 h$.\n\tSuppose that the current values of $r$ and $h$ are $r=7$ cm and $h=3$ cm. Is\n\tthe volume more sensitive to a small change in radius or the same amount of\n\tchange in height? Why?\n\t\\begin{sol}\n\t\theight\n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose that one of your colleagues has calculated the partial\n  derivatives of a given function, and reported to you that\n  $f_x(x,y)=2x+3y$ and that $f_y(x,y)=4x+6y$.  Do you believe them?\n  Why or why not?  If not, what answer might you have accepted for\n  $f_y$?\n\\end{ex}\n\n\\begin{ex}\nSuppose $f(t)$ and $g(t)$ are single variable differentiable\n  functions.  Find $\\partial z/\\partial x$ and\n  $\\partial z/\\partial y$ for each of the following two variable functions.\n\\begin{enumerate}\n\t\\item $z=f(x)g(y)$\n\t\\item $z=f(xy)$\n\t\\item $z=f(x/y)$\n\\end{enumerate}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "0cb4c4ef1a37d56f6d1a34f254d804813203f1cb", "size": 19245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-3-partial-differentiation.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-3-partial-differentiation.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-3-partial-differentiation.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.722334004, "max_line_length": 86, "alphanum_fraction": 0.7086515978, "num_tokens": 6644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8887587905460026, "lm_q1q2_score": 0.668357785530144}}
{"text": "%!TEX root=ClassNotes.tex\n\\section{Limits \\& Continuity}\n\nWe'll now use the proof techniques we've learned so far to study functions.\n\nWe'll start with rigorously defining limits. At first this might seem unnecessarily complicated, but having precise definitions will allow us to make more and more sophisticated constructions and later on in the course enable us to prove statements about derivatives and integrals.\n\nTime permitting, towards the end of the semester, we'll construct the Weierstrass function, a function defined on real numbers which is continuous everywhere but differentiable nowhere! But it all starts with the definition of a limit.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\textwidth]{WeierstrassFunction.jpg}\n\t% \\captionsetup{labelformat=empty}\n\t\\caption*{Weierstrass function (Image from Wikipedia)}\n\\end{figure}\n\n\\subsection{Limits}\nAt the heart of all analysis (and hence calculus) lies the notion of a limit. Almost every single concept that we'll define will be a limit of some kind.\n\n\\begin{definition}[Provisional definition of limit]\n\t\\label{def:provisional_definition_limit}\n\tFor a function $f$ and a real number $a$, we say that the function $f$ \\textbf{approaches a limit $L$ at $a$}, for some real number $L$, if we can make $f(x)$ as close to $L$ as we like by requiring that $x$ be sufficiently close to, but unequal to, $a$. This is denoted\n\t\\begin{align*}\n\t\t\\lim \\limits _ {x \\rightarrow a} f(x) = L\n\t\\end{align*}\n\\end{definition}\n\\noindent There are 3 problems with this definition:\n\\begin{enumerate}\n\t\\item The terms {\\it ``as close to $L$ as we like''} and {\\it``sufficiently close''} are not precise. (How close is sufficiently close?)\n\t\\item The order of implication is unclear.\n\t\\item The definition does not give us a way to come up with the limit $L$.\n\\end{enumerate}\n\nFirst, we'll make the terms precise.  We can measure the distance between two real numbers $x$, $y$ by taking their difference $x - y$, however, the difference can be negative so we use the absolute value $|x - y|$ instead.  So that\n\\begin{center}\n\t\\begin{tabular}{l l l}\n\t\t{\\it $x$ sufficiently close to, but unequal to, $a$} & translates to & {\\it $0 < |x - a| < \\delta$}                            \\\\\n\t\t{\\it $f(x)$ as close to $L$ as we like}              & translates to & {\\it for every $\\epsilon > 0$, $|f(x) - L| < \\epsilon$}\\end{tabular}\n\\end{center}\nand the definition of limit becomes\\\\\n\\begin{indentPara}\n\t\\dots $f$ \\textbf{approaches a limit $L$ at $a$}, for some real number $L$, if we can make $|f(x) - L| < \\epsilon$ for every $\\epsilon > 0$ by requiring that $0 < |x - a | < \\delta$ for some $\\delta > 0$.\\\\\n\\end{indentPara}\n\nNext, to clarify the order of implication we rephrase the statement in the more standard {\\it ``If ... then''} form and put all the quantifiers in the front,\\\\\n\\begin{indentPara}\n\t\\dots $f$ \\textbf{approaches a limit $L$ at $a$}, for some real number $L$, if for every $\\epsilon > 0$, there exists a $\\delta > 0$ such that, for all $x$, if $0 < |x - a | < \\delta$ then $|f(x) - L| < \\epsilon$.\\\\\n\\end{indentPara}\n\n\nThe third problem cannot be fixed! There is no systematic way of finding the limit of a general function, the only thing we can do is {\\it guess} the limit and then use the definition to {\\it prove} that it is indeed the limit. For special functions like polynomials, trig functions, exponential, and logarithms, we can find limits explicitly, which is what makes these functions useful for approximating and estimating more complicated functions.\n\n\\begin{definition}[Formal definition of limit]\n\t\\label{def:formal_definition_limit}\n\tWe say that the function $f$ \\textbf{approaches a limit $L$ at $a$}, for some real number $L$, if for every $\\epsilon > 0$, there exists a $\\delta > 0$ such that, for all $x$, if $0 < |x - a | < \\delta$ then $|f(x) - L| < \\epsilon$.\n\\end{definition}\n\n\\begin{exercise}\n\tCome up with formal definitions for the following:\n\t\\begin{enumerate}\n\t\t\\item The function $f$ approaches a limit $L$ at $a$ {\\bf from the right}, for some real number $L$, if we can make $f(x)$ as close to $L$ as we like by requiring that $x$ be sufficiently close to, but strictly greater than $a$. This is denoted\n\t\t      \\begin{align*}\n\t\t\t      \\lim \\limits _ {x \\rightarrow a^+} f(x) = L.\n\t\t      \\end{align*}\n\t\t\\item The function $f$ approaches a limit $L$ at $a$ {\\bf from the left}, for some real number $L$, if we can make $f(x)$ as close to $L$ as we like by requiring that $x$ be sufficiently close to, but strictly smaller than $a$. This is denoted\n\t\t      \\begin{align*}\n\t\t\t      \\lim \\limits _ {x \\rightarrow a^-} f(x) = L.\n\t\t      \\end{align*}\n\t\t\\item The function $f$ \\textbf{approaches the limit $\\infty$ at $a$}, if $f(x)$ can be made as large as we like by requiring that $x$ be sufficiently close to, but unequal to, $a$. This is denoted \\footnote{\n\t\tIn mathematics $\\infty$ means several things, in fact, there are infinitely many infinities. For us, $\\infty$ is a {\\it placeholder} for a limit of a function that grows very large. $\\infty$ is not a real number and hence cannot be used in equations.}\n\t\t      \\begin{align*}\n\t\t\t      \\lim \\limits _ {x \\rightarrow a} f(x) = \\infty.\n\t\t      \\end{align*}\n\n\t\t\\item The function $f$ \\textbf{approaches a limit $L$ at $\\infty$}, for some real number $L$ if we can make $f(x)$ as close to $L$ as we like by requiring that $x$ be sufficiently large. This is denoted\n\t\t      \\begin{align*}\n\t\t\t      \\lim \\limits _ {x \\rightarrow \\infty} f(x) = L.\n\t\t      \\end{align*}\n\t\t% \\item The function $f$ \\textbf{does not approaches a limit $L$ at $a$}. Further generalize this to: the function $f$ does not approaches a limit $L$ at $a$, {\\it for any $L$}. In this case, we say that the {\\bf limit of $f$ at $a$ does not exist}.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tFor each of the following, first guess the limit, then use the formal definition of limit to prove that it is indeed the limit.\n\t\\begin{enumerate}\n\t\t\\item $\\lim \\limits_{x \\rightarrow 1^+} 2x + 1$\n\t\t\\item $\\lim \\limits_{x \\rightarrow 1^+} x^2$\n\t\t\\item $\\lim \\limits_{x \\rightarrow \\infty} x^{10} + x$\n\t\t\\item $\\lim \\limits_{x \\rightarrow 0^+} 1/x$\n\t\t% \\item $\\lim \\limits_{x \\rightarrow 0^+} \\dfrac{\\sin x}{x}\\qquad$  (You can assume that $\\sin x < x - \\dfrac{x^3}{6}$ for all $0 < x < 1$.)\n\t\t\\item $\\lim \\limits_{x \\rightarrow 0} f(x)$ where $f(x) = \\begin{cases}\n\t\t\t\t      x & \\mbox{ if $x$ is rational}   \\\\\n\t\t\t\t      0 & \\mbox{ if $x$ is irrational}\n\t\t\t      \\end{cases}$\n\t\\end{enumerate}\n\\end{exercise}\n\n\\subsubsection*{Optional Problems}\n\n\\begin{exercise} Give examples to show that the following definitions of $\\lim \\limits _ {x \\rightarrow a} f(x) = L$ are not correct.\n\t\\begin{enumerate}\n\t\t\\item For every $ \\delta > 0$, there exists an $ \\epsilon > 0$ such that, for all $x$, if $ 0<|x-a|< \\delta$ then $ |f(x) - L|< \\epsilon$.\n\t\t\\item For every $\\epsilon > 0$, there exists a $\\delta > 0$ such that, for all $x$, if $|f(x) - L| < \\epsilon$ then $0 < |x - a| < \\delta$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tProve that if $\\lim \\limits _ {x \\rightarrow a} f(x) = L$ and $ L \\neq 0$ then $\\lim \\limits _ {x \\rightarrow a} 1/f(x) = 1/L$ .\n\\end{exercise}\n\n\n\n\\subsubsection{Triangle Inequality}\n\nTo prove abstract theorems involving absolute values we will need the following very important inequality called the {\\bf triangle inequality}.\n\\begin{align*}\n\t|x - y| \\le |x| + |y|\n\\end{align*}\nIf you think of the points $0$, $x$, $y$ (on the real axis) as being the three vertices of a (degenerate) triangle, then $|x|$, $|y|$, and $|x - y|$ are the lengths of the three sides and the triangle inequality is saying that: {\\it the sum of the lengths of two sides of a triangle is greater than or equal to the length of the third side.}\\\\\\\\\nThere are other forms in which the triangle inequality is commonly used, e.g.\n\\begin{align*}\n\t|x + y|       & \\le |x| + |y|   \\\\\n\t|x + y| - |y| & \\le |x|         \\\\\n\t|x|           & \\le |x-y| + |y|\n\\end{align*}\nThese inequalities are central to a lot of analysis proofs.\n\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Prove that $|x| + |x - 1| \\ge 1$ for any real number $x$.\n\t\t\\item Prove that for any real number $x$, at least one of $|x|$ and $|x-1|$ is $\\ge 1/2$.\\hint{Proof by Contradiction.}\n\t\\end{enumerate}\n\\end{exercise}\n\nWe'll use these to prove inequalities about the non-existence of limits.\n\n\\begin{definition}\n\tIf $f$ does not approach the limit $L$, for any real number or $\\infty$ or $-\\infty$, then we say that the limit of $f$ at $a$ {\\bf does not exist}.\n\\end{definition}\n\n\\begin{exercise}\n\t\\label{q:formal_definition_non_existence_limit}\n\tNegate the formal definitions of limits and come up with an $\\epsilon, \\delta$ definition for the following.\n\t\\begin{enumerate}\n\t\t\\item $f$ {\\bf does not} approach the limit $L$, where $L$ is a real number, at $a$.\n\t\t\\item $f$ {\\bf does not} approach the limit $\\infty$ at $a$. (Similarly for $-\\infty$.)\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\t\\label{q:rational_irrational_discontinuity}\n\tLet $\n\t\tf(x) = \\begin{cases}\n\t\t\t1 & \\mbox{if $x$ is rational,}   \\\\\n\t\t\t0 & \\mbox{if $x$ is irrational.}\n\t\t\\end{cases}\n\t$\n\t\\begin{enumerate}\n\t\t\\item Prove that for every real number $L$, $\\lim \\limits_{x \\rightarrow 0} f(x) \\neq L$.\n\t\t\\item Prove that $\\lim \\limits_{x \\rightarrow 0} f(x) \\neq \\infty$. (Similarly for $-\\infty$.)\n\t\\end{enumerate}\n\tHence the limit of $f$ at $0$ does not exist.\n\\end{exercise}\n\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Prove that $\\lim \\limits_{x \\rightarrow a} f(x) = L$ if and only if $\\lim \\limits_{x \\rightarrow a^+} f(x) = L$ and $\\lim \\limits_{x \\rightarrow a^-} f(x) = L$.\\hint{This is very easy, don't overthink! Simply write down the formal definitions.}\n\t\t      (Similarly for $\\infty$, $-\\infty$.)\n\n\t\t\\item Prove that $\\lim \\limits_{x \\rightarrow 0} \\dfrac{1}{x}$ does not exist.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\subsection{Non-existence of limits}\n\nLet's move backwards and try and understand what it means {\\it intuitively} for a function to not approach a limit $L$ near $a$. The solution to Exercise \\ref{q:formal_definition_non_existence_limit} is the following:\\\\\n\n\\begin{indentPara}\n\t{\\it (Formal definition)} The function $f$ \\textbf{does not approach thelimit $L$ at $a$} if there exists an $\\epsilon > 0$, such that for all $\\delta > 0$, there exists an $x$ such that, $0 < |x - a | < \\delta$ and $|f(x) - L| \\ge \\epsilon$.\\\\\n\\end{indentPara}\n\nGoing back to how to we came up with the Formal Definition of Limit \t\\ref{def:formal_definition_limit}\nfrom the Provisional Definition of Limit \\ref{def:provisional_definition_limit} and replacing the absolute values by the distance between points, we can work backwards and get the following provisional definition:\\\\\n\n\\begin{indentPara}\n\t{\\it (Provisional definition)}\n\tThe function $f$ \\textbf{does not approach the limit $L$ at $a$} if no matter how close we are to $a$, there is some $x$ for which $f(x)$ is not close to $L$.\n\\end{indentPara}\n\n\n% \\subsubsection*{Optional Problems}\n% \\begin{exercise} $ $\n% \t\\begin{enumerate}\n% \t\t\\item Explain how the provisional definition captures the notion of the failure of the function to approach a limit $L$ at $a$.\n% \t\t\\item Starting from the provisional definition try to systematically come up with the formal definition using arguments similar to the ones we made to go from Definition  \\ref{def:provisional_definition_limit} to Definition \\ref{def:formal_definition_limit}.\n% \t\\end{enumerate}\n% \\end{exercise}\n%\n% \\begin{exercise}\n% \tIt is easy to show that for the function\n% \t\\begin{align*}\n% \t\tf(x) = \\begin{cases}\n% \t\t\t0 & \\mbox{if } x \\le 0 \\\\\n% \t\t\t1 & \\mbox{if } x > 0\n% \t\t\\end{cases}\n% \t\\end{align*}\n% \tthe limit $\\lim \\limits_{x \\rightarrow 0} f(x)$ does not exist by computing the limits from the left and the right.\n%\n% \tTry to prove that, $\\lim \\limits_{x \\rightarrow 0} f(x) \\neq L$ for some real numbers, say $L = 0$, 1, 1/2, and more generally for any real number, using the formal definition and try to explain what the variables $\\epsilon$, $\\delta$, $x$ in your proof mean {\\it geometrically}.\n% \\end{exercise}\n\n\\subsection{Continuity}\n\n\\begin{definition}\n  We say that a function $f$ is {\\bf continuous} at $a$ if\n  \\begin{align*}\n    \\lim \\limits_{x \\rightarrow a} f(x) = f(a)\n  \\end{align*}\n  We say that a function $f$ is {\\bf continuous on an interval} $(a,b)$ it $f$ is continuous at every $x$ in $(a,b)$. \\footnote{If we use closed intervals $[a,b]$ instead, then we have to use $\\lim \\limits_{x \\rightarrow a^+}$ and $\\lim \\limits_{x \\rightarrow b^-}$ in the definition of continuity.}\n\\end{definition}\n\nThus continuous functions have {nice} limits. Further, we have the following theorem which makes continuous functions easy to manipulate.\n\n\\begin{theorem}\n  \\label{theorem:continuous_functions}\n  If the functions $f$, $g$ are continuous at $x=a$ then so are the functions\n  \\begin{enumerate}\n    \\item $ f + g$\n    \\item $f \\cdot g$\n    \\item $f / g$, if $g(a) \\neq 0$\n  \\end{enumerate}\n\\end{theorem}\n\n\\noindent The full proof of this theorem is just a tricky application of the triangle inequalities. We'll only prove the first part which is relatively manageable.\n\n\n\\begin{exercise}\n  \\label{q:for_later_1}\n  Using the formal definition of limits and the triangle inequality $|x+y| \\le |x| + |y|$, prove that\n  \\begin{indentPara}\n    {\\it if the functions $f$, $g$ are continuous at $x=a$ then so is the function $f + g$.}\n  \\end{indentPara}\n  Is the converse true?\n\\end{exercise}\n\n\\begin{exercise}$ $\n  \\label{q:for_later_2}\n  \\begin{enumerate}\n    \\item Prove that the constant function $f(x) = c$ is continuous everywhere, where $c$ is some real number.\n    \\item  Prove that the function $f(x) = x$ is continuous everywhere.\n    \\item Argue that these two facts along with Theorem \\ref{theorem:continuous_functions} imply that polynomials are continuous everywhere.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n  \\label{q:for_later_3}\n  Let $f$ be a continuous function on $[a,b]$, and let $g$ be a continuous function on $[b,c]$, such that \\begin{align*}\n    f(b) = g(b).\n  \\end{align*}\n  Show that the function $h$ defined as\n  \\begin{align*}\n    h(x) :=\n    \\begin{cases}\n      f(x) & \\mbox{if } x \\le b \\\\\n      g(x) & \\mbox{if } x > b\n    \\end{cases}\n  \\end{align*}\n  is continuous at $b$ (i.e. we can {\\it glue} continuous functions).\n\\end{exercise}\n", "meta": {"hexsha": "4006c05909bbcc4acfeb299f4a9f2316b519ecf6", "size": 14398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/03LimitsContinuity.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/03LimitsContinuity.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/03LimitsContinuity.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": 53.1291512915, "max_line_length": 447, "alphanum_fraction": 0.6815529935, "num_tokens": 4362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.6683577834062092}}
{"text": "\\section{Diagonalization}\n\n\nThere are two questions for a linear operator $T$:\n\\begin{enumerate}\n    \\item Is there an ordered basis $\\beta$ that $\\coordinate{T}_\\beta$ is a diagonal matrix?\n    \\item If such basis exists, how can it be found?\n\\end{enumerate}\n\n\n\\subsection{Eigenvalue and Eigenvectors}\n\n\\begin{definition}\n    A linear operator $T$ on $V$ is \\cindex{diagonalizable} if there is an ordered basis $\\beta$ of $V$ that $\\coordinate{T}_\\beta$ is a diagonal matrix. A matrix is \\cindex{diagonalizable} if $L_A$ is diagonalizable.\n\n\nIf an operator $T$ is diagonalizable, for $\\beta = \\{v_i\\}$, we have\n\\begin{equation*}\n    T(v_j) = \\sum_{i=1}^n D_{ij} v_j = D_{jj} v_j = \\lambda_j v_j\n\\end{equation*}\nSo to prove a  linear operator $T$ is diagnolizable is to find a basis $\\beta = \\{ v_i \\}$ and $\\{ \\lambda_j \\}$ that $T(v_i) = \\lambda_i v_i$.\n\\qed\n\\end{definition}\n\n\\begin{definition}\n    A \\emph{non-zero} vector $v \\in V$ is called an \\cindex{eigenvector} of linear operator $T$ if $\\exists \\lambda : T(v) = \\lambda v$. $\\lambda$ is called \\cindex{eigenvalue} corresponding to eigenvector $v$. Eigenvector is also called \\cindex{characteristic vector}. Eigenvalue is also called \\cindex{characteristic value}.\n\n    \n    \n    A eigenvalue could be $0$, but eigenvector could not be $\\vec{0}$. An eigenvector is an invariant subspace of dimension $1$.\n\\end{definition}\n\n\n\\begin{theorem}\n    A linear operator $T$ is diagonalizable if there exists an ordered basis consisting of eigenvectors of $T$.\n\\end{theorem}\n\n\\begin{theorem}\n    $\\lambda$ is an eigenvalue of $A$ $\\iff$ $\\determinate{A - \\lambda I_n} = 0$.\n\\end{theorem}\n\n\\begin{proof}\n    If $\\lambda$ is an eigenvalue of $A$, $\\exists v \\in F^n, v \\neq 0$ that $A v = \\lambda v$, which is $(A - \\lambda I_n)(v)= 0$, which means $A - \\lambda I_n$ is not invertible because $v \\neq 0$, so $\\determinate{A - \\lambda I_n} = 0$.\n\\end{proof}\n\n\\begin{theorem}\n    Every eigenvalue has at least one eigenvector.    \n\\end{theorem}\n\\begin{proof}\n    Since $\\determinate{A - \\lambda I_n} = 0$, $(A - \\lambda I_n) x = 0$ is a homogeneous equation with $\\dimension{A - \\lambda I_n} < n$.\n\\end{proof}\n\n\n\n\\begin{definition}\n    For $A = \\coordinate{T}_\\beta$ the polynomial $f_A(t) = \\determinate{A - t I_n}$ is called the \\cindex{characteristic polynomial} of $A$ and $T$. \n\\end{definition}\n\n\\begin{theorem}\n    For all eigenvalues $\\lambda_i$ of $A$, define \n    \\begin{equation}\n        S_k(A) = \\sum_{1\\leq j_1 \\leq j_2 \\leq \\dots \\leq j_k} \\prod_{j=1}^k \\lambda_{i_j}\n    \\end{equation}\n    that is $S_k(A)$ is the sum of the product of all $k$ eigenvalues, which is the coefficient of characteristic polynomial of $f_A(t)$:\n    \\begin{equation}\n        f_A(t) = (-1)^n t^n + (-1)^{n-1} S_{1}(\\lambda)t^{n-1} + \\dots + (-1)^{n-k} S_{k} t^{n-1} + \\dots + S_{n}\n    \\end{equation}\n    Define the sum of all\\footnote{There are $\\binom{n}{k}$ of them.} principal minor of size $k$ of $A$ as $E_k(A)$. We have\n    \\begin{equation}\n        E_k(A) = S_k(A)\n    \\end{equation}\n    So \n    \\begin{equation}\n        \\text{tr} A = \\sum \\lambda_i\n    \\end{equation}\n    and \n    \\begin{equation}\n        \\determinate{A} = \\prod \\lambda_i\n    \\end{equation}\n\\end{theorem}\n\\begin{proof}\n    calculate the coefficient by $\\dfrac{1}{k!} \\eval{\\dod[k]{f_A(t)}{t}}_{t = 0}$\n\\end{proof}\n\n\n\n\\begin{theorem}\n    The choice of basis $\\beta$ did not change the eigenvalue of $T$. \n\\end{theorem}\n\\begin{proof}\n    \\begin{equation*}\n        \\absolutevalue{\\coordinate{T}_\\beta - \\lambda I} = \\absolutevalue{Q^{-1} \\left( \\coordinate{T}_\\alpha - \\lambda I \\right) Q} = \\absolutevalue{Q^{-1}} \\times \\absolutevalue{\\coordinate{T}_\\alpha - \\lambda I } \\times \\absolutevalue{Q} = \\absolutevalue{\\coordinate{T}_\\alpha - \\lambda I } \n    \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}\nSimilar matrices have the same characteristic function.    \n\\end{theorem}\n\\begin{proof}\n    Assume $A$ is similar to $B$: $A = P^{-1} B P$. We have\n    \\begin{equation*}\n    f_A(\\lambda) = \\determinate{Ax - \\lambda I} = \\determinate{P^{-1} B P - \\lambda P^{-1} P} = \\determinate{P^{-1}} \\times \\determinate{B - \\lambda I } \\times \\determinate{P} = \\determinate{B - \\lambda I } = f_B(\\lambda)\n    \\end{equation*}\n\\end{proof}\n\n\n\n\n\\begin{theorem}\n    if $Q$ is a matrix with columns of eigenvectors of $\\beta$, then according to \\thmref{specialchangeofcoordinates} , $Q^{-1} A Q$ is a diagonal matrix with eigenvalue.\n\\end{theorem}\n\n\n\n\\subsection{Diagonalizability}\n\n\n\\begin{theorem}\n    Let ${\\lambda_i}$ be distinct eigenvalue of $T$. If $\\set{v_i}$ are eigenvector that corresponding to $\\lambda_i$, then $\\set{v_i}$ is \\emph{linearly independent}.\n\\end{theorem}\n\\begin{proof}\n    suppose it works for $k - 1 \\geq 1$ and we have $k$ eigenvector $\\{ v_i\\}$. Suppose\n    \\begin{equation*}\n        a_1 v_1 + a_2 v_2 + \\dots + a_k v_k = 0\n    \\end{equation*}\n    \n    multiply $T - \\lambda_k I$ to both sides, we have\n    \\begin{equation*}\n        a_1(\\lambda_1 - \\lambda_k) v_1 + a_1(\\lambda_2 - \\lambda_k) v_2 +  \\dots + a_1(\\lambda_{k-1} - \\lambda_k) v_{k-1} +  = 0\n    \\end{equation*}\n    \n    because $\\set{v_1, v_2, \\dots, v_{k-1} }$ are linearly independent, we have \n    \\begin{equation*}\n        a_1(\\lambda_1 - \\lambda_k) = a_1(\\lambda_2 - \\lambda_k) =  a_1(\\lambda_{k-1} - \\lambda_k) = 0\n    \\end{equation*}\n    \n    because $\\lambda_i$ are different, we have $a_i = 0$.\n\\end{proof}\n\n\\begin{theorem}\n    if $T$ has $n$ distinct eigenvalues, then $T$ is diagonalizable. If $T$ is diagonalizable, it may not have $n$ distinct eigenvalues, for example the identity matrix $I_V$.\n\\end{theorem}\n\n\\begin{definition}\n    A polynomial $f(t)$ in $P(F)$ \\cindex{split over} $F$ if there are scalars $c, a_1, \\dots, a_n$ (not necessarily distinct) in $F$ that\n    \\begin{equation*}\n        f(t) = c(t - a_1)(t - a_2) \\dots (t-a_n)\n    \\end{equation*}\n    \n    the \\cindex{multiplicity} of $\\lambda$ is the largest positive integer $k$ for which $(t - \\lambda)^k$ is a factor of $f(t)$.\n\\end{definition}\n\n\\begin{theorem}\n    the characteristic polynomial of any diagonalizable linear operator splits.\n\\end{theorem}\n\n\\begin{proof}\n    choose a basis $\\beta$ of eigenvectors. $[\\mathrm{T}]_\\beta$ is a diagonal matrix $D$. The characteristic polynomial of $T$ is $|D - tI|$ splits.\n\\end{proof}\n\nBe careful that the characteristic polynomial splits does not mean the matrix is diagonalizable. The eigenvectors need to form a basis.\n\n\n\\begin{definition}\n    let $\\lambda$ be an eigenvalue of $T$. Let $E_\\lambda = \\nullspace{T - \\lambda I_V}$. the set $E_\\lambda$ is called the \\cindex{eigenspace} of $T$ corresponding to eigenvalue $\\lambda$. So is it for matrix.\n\\end{definition}\n\n\\begin{theorem}\n    let $\\lambda$ be an eigenvalue of $T$ having multiplicity $m$. then $1 \\leq \\dimension{E_\\lambda} \\leq m$.\n\\end{theorem}\n\\begin{proof}\n    choose ordered basis $\\set{v_1, v_2, \\dots, v_p}$ for $E_\\lambda$, and extend it to ordered basis $\\beta =\\set{v_1, v_2, \\dots, v_p, v_{p+1}, \\dots, v_n}$ for $V$, and let $A = \\coordinate{T}_\\beta$. let $v_i (1 \\leq i \\leq q)$ be an eigenvector of $T$ corresponding to $\\lambda$, we have\n    \\begin{equation*}\n        A = \\begin{pmatrix}\n            \\lambda I_p & B \\\\\n            0 & C\n        \\end{pmatrix}\n    \\end{equation*}\n    so \\begin{equation*}\n        \\begin{aligned}\n            f(t) &= \\absolutevalue{A - t I_n} \\\\\n            &= \\absolutevalue{\\begin{bmatrix}\n                (\\lambda - t) I_p & B \\\\\n                0 & C - t I_{n-p}\n            \\end{bmatrix}} \\\\\n            &= \\absolutevalue{(\\lambda - t)I_p} \\times \\absolutevalue{C - t I_{n-p}} \\\\\n            &= (\\lambda - t)^p g(t)\n        \\end{aligned}\n        \\end{equation*}\n    So $(\\lambda - t)^p$ is a factor of $f(t)$, and the multiplicity of $\\lambda$ is at least $p = \\text{dim}(E_\\lambda)$, so $\\text{dim}(E_\\lambda) \\leq m$ \n\\end{proof}\n\n\\begin{theorem}\n    let $\\set{\\lambda_1, \\lambda_2, \\dots, \\lambda_k}$ be distinct eigenvalue of $T$. let $S_i$ be a finite linearly independent subset of eigenspace $E_{\\lambda_i}$. then $S_1 \\cup S_2 \\cup \\dots \\cup S_k$ is a linearly independent subset of $V$.\n\\end{theorem}\n\n\\begin{theorem}\n    let $\\lambda_1, \\lambda_2, \\dots, \\lambda_k$ be distinct eigenvalue of $T$, then\n    \\begin{enumerate}\n        \\item $T$ is diagonalizable $\\iff$ the multiplicity of $\\lambda_i$ is equal to $\\dimension{E_{\\lambda_i}}$ for all $i$.\n        \\item If $T$ is diagonalizable and $\\beta_i$ is an ordered basis for $E_{\\lambda_i}$ for each $i$, then $\\beta = \\beta_1 \\cup \\beta_2 \\cup \\dots \\cup \\beta_k$ is an ordered basis for $V$ consisting of eigenvectors of $T$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}\n    $T$ is diagonalizable $\\iff$ both of the following holds:\n    \\begin{enumerate}\n        \\item the characteristic polynomial of $T$ splits.\n        \\item for each eigenvalue $\\lambda$ of $T$, the multiplicity of $\\lambda$ equals $n - \\rank{T - \\lambda I}$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{definition}\n    Let $W_i$ be subspaces of a vector space $V$. The \\cindex{sum} of these subspaces is defined as:\n    \\begin{equation}\n        \\sum_{i=1}^k W_i = \\set{v_1 + v_2 + \\dots + v_k : v_i \\in W_i \\text{ for } 1 \\leq i \\leq k }\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n    let $W_i$ be subspace of $V$. $V$ is the \\cindex{direct sum} of subspace $\\set{W_1, W_2, \\dots, W_k}$, or $V = W_1 \\oplus W_2 \\oplus \\dots \\oplus W_k$ if\n    \\begin{equation*}\n        V = \\sum_{i=1}^k W_i\n    \\end{equation*}\n    and \n    \\begin{equation*}\n        W_j \\cap \\sum_{i \\neq j} W_i = \\emptyset, (1 \\leq j \\leq k)\n    \\end{equation*}\n\\end{definition}\n\n\\begin{theorem}\n    $T$ is diagonalizable $\\iff$ $V$ is the direct sum of eigenspaces of $T$.\n\\end{theorem}\n\n\n\\subsection{Invariant Subspaces}\n\n\\begin{definition}\n    A subspace $W$ of $V$ is $T$-\\cindex{invariant subspace} of $V$ if $T(W) \\subseteq W$.\n    Common $T$-invariant subspaces are: $\\emptyset$, $V$, $R(T)$, $N(T)$.\n    \\qed\n\\end{definition}\n\n\\begin{theorem}\n    A subspace $W$ with basis $\\alpha = \\set{v_1, v_2, \\dots, v_k}$ is $T$-invariant. Let $\\beta = \\alpha \\cup \\gamma$ as the expanded basis of $V$. Then\n    \\begin{equation}\n        \\coordinate{T}_\\beta = \\begin{bmatrix}\n            A_{k \\times k} & B \\\\\n            0 & C\n        \\end{bmatrix}\n    \\end{equation}\n    The reverse is true. If $\\coordinate{T}_\\beta$  has such representation, the first $k$ basis of $\\beta$ is $T$-invariant. \n\\end{theorem}\n\n\n\n\\begin{definition}\n    A $T$-\\cindex{cyclic subspace} of $V$ generated by $x$ is defined as $W=\\text{span} \\left(  \\set{x, T(x), T^2(x), \\dots} \\right)$.\n\\end{definition}\n\n\\begin{theorem}\n    Let $T$ be a linear operator on finite-dimensional vector space $V$, and let $W$ be a $T$-invariant subspace of $V$. Then the characteristic polynomial of $T_W$ divides the characteristic polynomial of $T$.\n\\end{theorem}\n\n\\begin{proof}\n    Choose ordered basis $\\gamma$ for $W$ and expand it to $\\beta$ for $V$. Calculate $\\coordinate{T}_\\beta$ and $\\coordinate{T}_\\gamma$.\n\\end{proof}\n\n\n\\begin{theorem}\n    Let $T$ be a linear operator on finiate-dimensional vector space $V$, and let $W$ be a $T$-cyclic subspace of $V$ generated by nonzero vector $v \\in V$. Let $k = \\dimension{W}$. Then:\n    \\begin{enumerate}\n        \\item $\\set{v, T(v), T^2(v), \\dots, T^{k-1}(v)}$ is a basis for $W$.\n        \\item If $a_0 v + a_1 T(v) + a_2 T^2(v) + \\dots + a_{k-1} T^{k-1}(v) + T^k(v) = 0$, then the characteristic polynomial of $T_W$ is $f(t) = (-1)^k \\left( a_0 + a_1 t + \\dots + a_{k-1} t^{k-1} + t^k \\right)$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n    Let $\\beta = \\set{v, T(v), T^2(v), \\dots, T^{k-1}(v)}$, and let $a_i$ be the scalars that \n    \\begin{equation*}\n            a_0 v + a_1 T(v) + a_2 T^2(v) + \\dots + a_{k-1} T^{k-1}(v) + T^k(v) = 0\n    \\end{equation*}\n    \n    Fors basis $\\set{v, T(v), T^2(v), \\dots, T^{k-1}(v)}$, $\\coordinate{T(v)}_\\beta = \\coordinate{0,1,\\dots, 0}$, $T\\left( T(v)\\right)_\\beta = \\coordinate{0,0,1,\\dots, 0}$, etc, we have:\n    \\begin{equation*}\n        [T_W]_\\beta = \\begin{bmatrix}\n            0 & 0 & \\dots & 0 & - a_0 \\\\\n            1 & 0 & \\dots & 0 & -a_1\\\\\n            \\vdots & \\vdots  & & \\vdots & \\vdots \\\\\n            0 & 0 & \\dots & 1 & - a_{k-1}\n        \\end{bmatrix}\n    \\end{equation*}\n    which has characteristic polynomial\n    \\begin{equation*}\n        f(t) = (-1)^k (a_0 + a_1 t + \\dots + a_{k-1} t^{k-1} + t^k)\n    \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[\\cindex{Cayley-Hamilton}]\n    Let $T$ be linear operator on a finite-dimensional vector space $V$, and let $f(t)$ be the characteristic polynomial of $T$. Then $f(T) = 0$.\n\\end{theorem}\n\n\\begin{proof}\n    Suppose $v \\neq 0$. Let $W$ be the $T$-cyclic subspace generated by $v$, and suppose the $\\dimension{W} =k$. So there exists scalars $\\set{a_i}$ that \n    \\begin{equation*}\n        a_0 v + a_1 T(v) + a_2 T^2(v) + \\dots + a_{k-1} T^{k-1}(v) + T^k(v) = 0\n    \\end{equation*}\n    which implies the characteristic polynomial of $T_W$ is\n    \\begin{equation*}\n        g(t) = (-1)^k \\left(a_0 + a_1 t + \\dots + a_{k-1} t^{k-1} + t^k \\right)\n    \\end{equation*}\n    We have\n    \\begin{equation*}\n        g(T)(v) = (-1)^k \\left(a_0 I + a_1 T + \\dots + a_{k-1} T^{k-1} + T^k \\right)(v) = 0\n    \\end{equation*}\n    Because $g(t)$ divides $f(t)$, $\\exists q(t)$ that $f(t) = g(t) q(t)$. So\n    \\begin{equation*}\n        f(T)(v) = q(T)g(T)(v) = q(T) \\left(g(T)(v)\\right) = q(T)(0) = 0\n    \\end{equation*}\n\\end{proof}\n\n\n\n\\begin{definition}\n    Let $B_1 \\in M_{m \\times m}(F)$, and $B_2 \\in M_{n \\times n} (F)$. The \\cindex{direct sum} of $B_1$ and $B_2$, denoted as $B_1 \\oplus B_2$, as the $(m+n) \\times (m+n)$ matrix $A$ that\n    \\begin{equation*}\n        A = \\begin{bmatrix}\n            B_1 & 0 \\\\\n            0 & B_2\n        \\end{bmatrix}\n    \\end{equation*}\n\\end{definition}\n\n\n\\begin{theorem}\n    Suppose $V=W_1 \\oplus W_2 \\oplus \\dots \\oplus W_k$, where $W_i$ is a $T$-invariant subspace of $V$. Suppose $f_i(t)$ is the characteristic polynomial of $T_{W_i}$, Then $\\displaystyle \\prod_{i=1}^k f_i$ is the characteristic polynomial of $T$. Let $\\beta_i$ be an ordered basis for $W_i$, and let $\\displaystyle \\beta = \\bigcup_{i=1}^k \\beta_i$. Let $A=\\coordinate{T}_\\beta$, and $B_i=[T_{W_i}]_\\beta$. Then $A = B_1 \\oplus B_2 \\oplus \\dots \\oplus B_k$.\n\\end{theorem}\n\n\n\n\\subsection{Limit of Markov Chain Matrix}\n\n\\begin{definition}\n    A sequence $\\set{A_1, A_2, \\dots}$ \\cindex{converge} to \\cindex{limit} $L$ if $\\displaystyle \\lim_{m \\rightarrow \\infty} (A_m)_{ij} = L_{ij}$.\n\\end{definition}\n\n\\begin{theorem}\n    If $A_i \\rightarrow L$, them for any $P$ and $Q$, $\\displaystyle \\lim_{m \\rightarrow \\infty} P A_m = PL$ and $\\displaystyle \\lim_{m \\rightarrow \\infty} A_m Q = LQ$.\n\\end{theorem}\n\n\\begin{theorem}\n    Let $Q$ be invertible and $A_i \\rightarrow L$. Then $\\displaystyle \\lim_{m \\rightarrow \\infty} (Q A Q^{-1})^m = Q A Q^{-1}$.\n\\end{theorem}\n\n\\begin{definition}\n    Define a set $S$ which consists of the interior of unit disk and $1$:\n    \\begin{equation}\n        S = \\set{\\lambda \\in C :  \\absolutevalue{\\lambda} < 1   \\vee \\lambda = 1}\n    \\end{equation}\n\\end{definition}\n\n\n\\begin{theorem}\n    Let $A$ be square matrix in $C$. $\\displaystyle \\lim_{m \\rightarrow \\infty} A^m$ exists if and only if:\n    \\begin{enumerate}\n        \\item Every eigenvalue of $A$ is in $S$.\n        \\item If $1$ is an eigenvalue of $A$, then the dimension of its eigenspace equals its multiplicity.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n    use Jordan canonical form.\n\\end{proof}\n\n\n\\begin{theorem}\n    For square matrix $A$ in $C$, if\n    \\begin{enumerate}\n        \\item Every eigenvalue of $A$ is in $S$.\n        \\item $A$ is diagonalizable.\n    \\end{enumerate}    \n    Then $\\displaystyle \\lim_{m \\rightarrow \\infty} A^m$ exists.\n\\end{theorem}\n\\begin{proof}\n    Since $A$ is diagonalizable, $\\exists Q: A = Q D Q^{-1}$. So $A^m = Q D^m Q^{-1}$. This is used to calculate $A^m$.\n\\end{proof}\n\n\\begin{definition}\n    \\cindex{transition matrix} or \\cindex{stochastic matrix} is a square matrix $A$ that $A_{ij} \\geq 0 \\wedge \\forall j \\left(\\sum_{i} A_{ij} = 1 \\right)$.\n\\end{definition}\n\n\\begin{definition}\n    $P$ is a \\cindex{probability vector} if its entries are all non-negative and sum to $1$.\n\\end{definition}\n\n\\begin{definition}\n    \\cindex{$\\vec{1_n}$} is a column vector that each coordinate is $1$.\n\\end{definition}\n\n\\begin{theorem}\n    Let $M$ be a square matrix with non-negative real entries, and $v$ a column vector with real non-negative coordinates. Then\n    \\begin{enumerate}\n        \\item $M$ is a transition matrix if and only if $M^\\top \\vec{1_n} = \\vec{1_n}$.\n        \\item $v$ is a probability vector if and only if $\\vec{1_n}^\\top v = 1$.\n        \\item The product of two transition matrix is transition matrix.\n        \\item The product of a transition matrix and probability vector is a probability vector.\n    \\end{enumerate}    \n\\end{theorem}\n\n\\begin{definition}\n    A transition matrix is \\cindex{regular} if some power of the matrix contains only positive entries. It may contain zero entries.\n\\end{definition}\n\n\\begin{definition}\n    For square matrix $A$, define $\\displaystyle \\rho_i (A) = \\sum_j \\absolutevalue{A_{ij}}$ and $\\displaystyle v_j(A) = \\sum_i \\absolutevalue{A_{ij}}$. The \\cindex{row sum} $\\rho (A) = \\max \\rho_i$ and \\cindex{column sum} $v(A) = \\max v_j$.\n\\end{definition}\n\n\\begin{definition}\n    For square matrix $A_{n \\times n}$, the \\cindex{Gerschgorin disk} $C_i$ is defined as:\n    \\begin{equation}\n        C_i = \\set{z \\in C: \\absolutevalue{z - A_{ii}} < \\rho_i (A) - \\absolutevalue{A_{ii}}}\n    \\end{equation}\n    So the disk center is the diagonal entry, and the radius is the sum of the absolute values of all rest row entries.\n\\end{definition}\n\n\\begin{theorem}\n    Every eigenvalue of $A$ is contained in a Gerschgorin disk.    \n\\end{theorem}\n\\begin{proof}\n    Let $\\lambda$ be a eigenvalue with eigenvector $v$. So $\\displaystyle \\sum_{j=1}^n A_{ij} v_j = \\lambda v_i$. Assume $v_k$ is the coordinate of $v$ that has the largest absolute value. Then $v_k \\neq 0$ because $v \\neq 0$. We have\n    \\begin{equation*}\n        \\begin{aligned}\n            \\absolutevalue{\\lambda v_k - A_{kk} v_k} = \\absolutevalue{\\sum_{j=1}^n A_kj v_j - A_{kk} v_k} = \\absolutevalue{\\sum_{j \\neq k} A_{kj} v_j} \\leq \\sum_{j \\neq k} \\absolutevalue{A_{kj}} \\absolutevalue{v_j} \\leq \\sum_{j \\neq k} \\absolutevalue{A_{kj}} \\absolutevalue{v_k} = \\absolutevalue{v_k} \\left(\\rho_i (A) - \\absolutevalue{A_{kk}} \\right)\n        \\end{aligned}\n    \\end{equation*}\n    So $\\absolutevalue{v_k} \\times \\absolutevalue{\\lambda - A_{kk} } \\leq \\absolutevalue{v_k} \\left(\\rho_i (A) - \\absolutevalue{A_{kk}} \\right)$ and $\\absolutevalue{\\lambda - A_{kk} } \\leq \\left(\\rho_i (A) - \\absolutevalue{A_{kk}} \\right)$.\n\\end{proof}\n\n\\begin{theorem}\n    Let $\\lambda$ be any eigenvalue of $A$. Then $\\absolutevalue{\\lambda} \\leq \\rho(A)$.\n\\end{theorem}\n\\begin{proof}\n    $\\displaystyle \\absolutevalue{\\lambda} = \\absolutevalue{(\\lambda - A_{kk}) + A_{kk}} \\leq \\absolutevalue{\\lambda - A_{kk}} + \\absolutevalue{A_{kk}} \\leq \\rho_i (A) - \\absolutevalue{A_{kk}}  + \\absolutevalue{A_{kk}}  = \\rho_i (A)$\n\\end{proof}\n\n\\begin{theorem}\n    Let $\\lambda$ be any eigenvalue of $A$. Then $\\absolutevalue{\\lambda} \\leq \\min \\set{\\rho(A), v(A)}$.\n\\end{theorem}\n\\begin{proof}\n    $\\lambda$ is an eigenvalue of $A^\\top$.\n\\end{proof}\n\n\\begin{theorem}\n    If $\\lambda$ is an eigenvalue of transition matrix, then $\\absolutevalue{\\lambda} \\leq 1$.\n\\end{theorem}\n\n\\begin{theorem}\n    Every transition matrix has $1$ as eigenvalue.    \n\\end{theorem}\n\\begin{proof}\n    $A^\\top \\times  \\vec{1_n} = \\vec{1_n}$.\n\\end{proof}\n\n\\begin{theorem}\n    Let $A$ be a matrix with positive entries, and let $\\lambda$ be an eigenvalue of $A$ that $\\absolutevalue{\\lambda} = \\rho(A)$. Then $\\lambda = \\rho(A)$ and $\\vec{1_n}$ is a basis for $E_\\lambda$.\n\\end{theorem}\n\\begin{proof}\n    Let $v$ be an eigenvector for $\\lambda$, and $v_k$ is the coordinate that has the largest absolute value $b = \\absolutevalue{v_k}$. Then\n    \\begin{equation*}\n        \\absolutevalue{\\lambda} b = \\absolutevalue{\\lambda v_k} = \\absolutevalue{\\sum_{j=1}^n A_{kj} v_j} \\leq \\sum_{j=1}^n \\absolutevalue{A_{kj} v_j} = \\sum_{j=1}^n \\absolutevalue{A_{kj}} \\absolutevalue{v_j} \\leq \\sum_{j=1}^n \\absolutevalue{A_{kj}} b = \\rho_k(A) b \\leq \\rho(A) b\n    \\end{equation*}\n    Since $\\absolutevalue{\\lambda} = \\rho(A)$, all inequalities are equalities, so\n    \\begin{enumerate}\n        \\item \\label{transitionmatrixproperty1}$\\displaystyle \\absolutevalue{\\sum_{j=1}^n A_{kj} v_j} = \\sum_{j=1}^n \\absolutevalue{A_{kj} v_j}$\n        \\item \\label{transitionmatrixproperty2}$\\displaystyle \\absolutevalue{A_{kj}} \\absolutevalue{v_j} = \\sum_{j=1}^n \\absolutevalue{A_{kj}} b$\n        \\item \\label{transitionmatrixproperty3}$\\rho_k(A) \\leq \\rho(A)$\n    \\end{enumerate}\n    \n    For Item \\ref{transitionmatrixproperty1} to hold, $A_{kj} v_j$ are non-negative multiplies of a common complex number $z$. Assume $\\absolutevalue{z}=1$. Then $\\left(\\exists \\set{c_j} \\subset R^+ \\right) (A_{kj} v_j = c_j z)$.\n    \n    For item \\ref{transitionmatrixproperty2}, since $b = \\max \\absolutevalue{v_j}$, $\\absolutevalue{v_j} = b$. So $\\displaystyle b = \\absolutevalue{v_j} = \\absolutevalue{\\frac{c_j}{A_{kj}} z} = \\frac{c_j}{A_{kj}}$, and $\\displaystyle v_j = \\frac{c_j}{A_{kj}} z = bz$, and $v = bz \\vec{1_n}$.\n    \n    Since $A$ and $\\vec{1_n}$ are all positive, $A \\vec{1_n} = \\lambda \\vec{1_n}$, so $\\lambda > 0$.\n\\end{proof}\n\n\\begin{theorem}\n    Let $A$ be a transition matrix that each entry is positive, and let $\\lambda$ be any eigenvalue of $A$ other than $1$. Then $\\absolutevalue{\\lambda} < 1$. Moreover, the eigenspace of eigenvalue $1$ has dimension $1$.\n\\end{theorem}\n\n\\begin{theorem}\n    Let $A$ be a regular transition matrix, and $\\lambda$ be one of its eigenvalue, then\n    \\begin{enumerate}\n        \\item $\\absolutevalue{\\lambda} \\leq 1$.\n        \\item If $\\absolutevalue{\\lambda} = 1$, then $\\lambda = 1$ and $\\dimension{E_\\lambda} = 1$.\n    \\end{enumerate}    \n\\end{theorem}\n\n\\begin{theorem}\n    Let $A$ be a disagonalizable regular transition matrix, then $\\displaystyle \\lim_{m \\rightarrow \\infty} A^m$ exists.\n\\end{theorem}\n\n\\begin{theorem}\n    Let $A$ be a regular transition matrix, then\n    \\begin{enumerate}\n        \\item the multiplicity of eigenvalue $1$ is $1$.\n        \\item $\\displaystyle \\lim_{m \\rightarrow \\infty} A^m$ exists.\n        \\item $L = \\displaystyle \\lim_{m \\rightarrow \\infty} A^m$ is a transition matrix.\n        \\item $AL = LA = L$.\n        \\item The column of $L$ are identical vector $v$ which is the probability vector in $E_1$.\n        \\item For any probability vector $w$, $\\displaystyle \\lim_{m \\rightarrow \\infty} A^m w = v$.\n    \\end{enumerate}    \n\\end{theorem}\n\\begin{proof}\n    Since $AL = L$, $L$ are columns of eigenvector for eigenvalue $1$. Let $y = \\displaystyle \\lim_{m \\rightarrow \\infty} A^m w = Lw$, $Ay = ALw = Lw = y$. So $y$ is an eigenvector for eigenvalue $1$, and $y = v$.\n\\end{proof}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "f2014054ea430e6a4828b4827adb8cb990e8075b", "size": 23111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra/la.5.diagonalization.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/linear_algebra/la.5.diagonalization.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linear_algebra/la.5.diagonalization.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": 41.343470483, "max_line_length": 457, "alphanum_fraction": 0.6336376617, "num_tokens": 7935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.6683254676701359}}
{"text": "\\section{Introducing differentiable binary arithmetic operations}\n\\label{sec:Nalu}\nWe define our problem as learning a set of static arithmetic operations between selected elements of a vector. E.g. for a vector $\\mathbf{x}$ learn the function ${(x_5 + x_1) \\cdot x_7}$. The approach taking in this paper, is to develop layers around specific operations, and then let each layer decide which inputs to include using backpropagation.\n\nWe develop these layers by taking inspiration from a theoretical analysis of Neural Arithmetic Logic Unit (NALU) by \\citet{trask-nalu}.\n\n\\subsection{Introducing NALU}\nThe Neural Arithmetic Logic Unit (NALU) consists of two sub-units; the $\\text{NAC}_{+}$ and $\\text{NAC}_{\\bullet}$. The sub-units represent either the $\\{+, -\\}$ or the $\\{\\times, \\div \\}$ operations. The NALU then assumes that either $\\text{NAC}_{+}$ or $\\text{NAC}_{\\bullet}$ will be selected exclusively, using a sigmoid gating-mechanism.\n\nThe $\\text{NAC}_{+}$ and $\\text{NAC}_{\\bullet}$ are defined accordingly,\n\\begin{align}\nW_{h_\\ell, h_{\\ell-1}} &= \\tanh(\\hat{W}_{h_\\ell, h_{\\ell-1}}) \\sigma(\\hat{M}_{h_\\ell, h_{\\ell-1}}) \\label{eq:weight}\\\\\n\\textrm{NAC}_+:\\ z_{h_\\ell} &= \\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} W_{h_{\\ell}, h_{\\ell-1}} z_{h_{\\ell-1}} \\label{eq:naca}\\\\\n\\textrm{NAC}_\\bullet:\\ z_{h_\\ell} &= \\exp\\left(\\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} W_{h_{\\ell}, h_{\\ell-1}} \\label{eq:nacm}\\log(|z_{h_{\\ell-1}}| + \\epsilon) \\right)\n\\end{align}\nwhere $\\hat{\\mathbf{W}}, \\hat{\\mathbf{M}} \\in \\mathbb{R}^{H_{\\ell} \\times H_{\\ell-1}}$ are weight matrices and $z_{h_{\\ell-1}}$ is the input. The matrices are combined using a tanh-sigmoid transformation to bias the parameters towards a $\\{-1,0,1\\}$ solution. Having $\\{-1,0,1\\}$ allows $\\text{NAC}_{+}$ to perform exact $\\{+, -\\}$ operations between elements of a vector.\nThe $\\text{NAC}_{\\bullet}$ uses an exponential-log transformation to create the $\\{\\times, \\div \\}$ operations within $\\epsilon$ precision and for positive inputs only.\n\nThe NALU combines these units with a gating mechanism $\\mathbf{z} = \\mathbf{g} \\odot \\text{NAC}_{+} + (1 - \\mathbf{g}) \\odot \\text{NAC}_{\\bullet}$ given $\\mathbf{g} = \\sigma(\\mathbf{G} \\mathbf{x})$. Thus allowing NALU to decide between all of $\\{+, -, \\times, \\div\\}$ using backpropagation.\n\n\\subsection{Weight matrix construction  and the Neural Addition Unit}\\label{sssec:weight}\n\n\\citet{glorot-initialization} show that $E[z_{h_\\ell}] = 0$ at initialization is a desired property, as it prevents explosion of both the output and the gradients.\nTo satisfy this property with $W_{h_{\\ell-1},h_\\ell} = \\tanh(\\hat{W}_{h_{\\ell-1},h_\\ell}) \\sigma(\\hat{M}_{h_{\\ell-1},h_\\ell})$, an initialization must satisfy $E[\\tanh(\\hat{W}_{h_{\\ell-1},h_\\ell})] = 0$.\nIn NALU, this initialization is unbiased as it samples evenly between $+$ and $-$, or $\\times$ and $\\div$.\nUnfortunately, this initialization also causes the expectation of the gradient to become zero, as shown in \\eqref{eq:nac-weight-gradient}.\n\n\\begin{equation}\nE\\left[\\frac{\\partial \\mathcal{L}}{\\partial \\hat{M}_{h_{\\ell-1},h_\\ell}}\\right] = E\\left[\\frac{\\partial \\mathcal{L}}{\\partial W_{h_{\\ell-1},h_\\ell}}\\right] E\\left[\\tanh(\\hat{W}_{h_{\\ell-1},h_\\ell})\\right] E\\left[\\sigma'(\\hat{M}_{h_{\\ell-1},h_\\ell})\\right] = 0\n\\label{eq:nac-weight-gradient}\n\\end{equation}\n\nBesides the issue of initialization, our empirical analysis (table \\ref{tab:function-task-static-defaults}) shows that this weight construction \\eqref{eq:weight} do not create the desired bias for $\\{-1, 0, 1\\}$ for the addition and subtraction problem. This bias is desired as it restricts the solution space to exact addition, and in section \\label{sec:method:nmu} also exact multiplication, which is an intrinsic property of an underlying arithmetic function. However, it does not necessarily restrict the output space as a plain linear transformation will always be able to scale values accordingly. The bias also adds interpretability which is important for being confident in a model’s ability to extrapolate.\n\nTo solve these issues, we add a sparsifying regularizer to the loss function ($\\mathcal{L} = \\hat{\\mathcal{L}} + \\lambda_{\\mathrm{sparse}} \\mathcal{R}_{\\ell,\\mathrm{sparse}}$) and use simple linear weight construction, where $W_{h_{\\ell-1},h_\\ell}$ is clamped to $[-1, 1]$ in each iteration.\n\n\\begin{align}\nW_{h_{\\ell-1},h_\\ell} &= \\min(\\max(W_{h_{\\ell-1},h_\\ell}, -1), 1), \\\\\n\\mathcal{R}_{\\ell,\\mathrm{sparse}} &= \\frac{1}{H_\\ell \\cdot H_{\\ell-1}} \\sum_{h_\\ell=1}^{H_\\ell} \\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} \\min\\left(|W_{h_{\\ell-1},h_\\ell}|, 1 - \\left|W_{h_{\\ell-1},h_\\ell}\\right|\\right) \\\\\n\\textrm{NAU}:\\ z_{h_\\ell} &= \\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} W_{h_{\\ell}, h_{\\ell-1}} z_{h_{\\ell-1}}\n\\end{align}\n\n\\subsection{Challenges of division} \\label{sssec:nac-mul}\n\nThe $\\text{NAC}_{\\bullet}$, as formulated in equation \\ref{eq:nacm}, has the ability to perform exact multiplication and division, or more precisely multiplication of the inverse of elements from a vector, when a weight in $W_{h_{\\ell-1},h_\\ell}$ is $-1$.\n\nHowever, this flexibility creates critical optimization challenges. Expanding the exp-log-transformation, $\\text{NAC}_{\\bullet}$ can be expressed as\n\\begin{equation}\n\\textrm{NAC}_\\bullet:\\ z_{h_\\ell} = \\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} (|z_{h_{\\ell-1}}| + \\epsilon)^{W_{h_{\\ell}, h_{\\ell-1}}}\\ .\n\\label{eq:division:nac-mul-rewrite}\n\\end{equation}\n\nIn equation \\eqref{eq:division:nac-mul-rewrite}, if $|z_{h_{\\ell-1}}|$ is near zero ($E[z_{h_{\\ell-1}}] = 0$ is a desired property when initializing \\cite{glorot-initialization}), $W_{h_{\\ell-1},h_\\ell}$ is negative, and $\\epsilon$ is small, then the output will explode. This issue is present even for a reasonably large $\\epsilon$ value (such as $\\epsilon = 0.1$), and just a slightly negative $W_{h_{\\ell-1},h_\\ell}$, as visualized in figure \\ref{fig:nac-mul-eps-issue}. Also note that the curvature can cause convergence to an unstable area.\n\nThis singularity issue in the optimization space also makes multiplication challenging, which further suggests that supporting division is undesirable. These observations are also found empirically in \\citet[table 1]{trask-nalu} and Appendix \\ref{sec:appendix:comparison-all-models}.\n\n%However, backpropagation through the $\\text{NAC}_{\\bullet}$ unit (equation \\ref{eq:dz}, derivation in Appendix \\ref{sec:appendix:gradient-derivatives:gradient-nac-mul}) reveals that if $|z_{h_{\\ell-1}}|$ is near zero, $W_{h_{\\ell-1},h_\\ell}$ is negative and $\\epsilon$ is small, the gradient term will explode and oscillate between large positive and large negative values, which can be problematic in optimization \\cite{adam-optimization}, as visualized in figure \\ref{fig:nac-mul-eps-issue}.\n%\\begin{align}\n%\\frac{\\partial \\mathcal{L}}{\\partial W_{h_{\\ell}, h_{\\ell - 1}}} &= \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{\\partial z_{h_\\ell}}{\\partial W_{h_{\\ell}, h_{\\ell - 1}}} = \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} z_{h_\\ell} \\log(|z_{h_{\\ell-1}}| + \\epsilon) \\label{eq:dw}\\\\\n%\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}} &= \\sum_{h_\\ell = 1}^{H_\\ell} \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}} = \\sum_{h_\\ell = 1}^{H_\\ell} \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} z_{h_\\ell} W_{h_\\ell, h_{\\ell-1}} \\frac{\\mathrm{sign}(z_{h_{\\ell-1}})}{|z_{h_{\\ell-1}}| + \\epsilon}\\label{eq:dz}\n%\\end{align}\n\n%This is not an issue for positive values of $W_{h_{\\ell-1},h_\\ell}$ (multiplication), as $z_{h_{\\ell}}$ and $z_{h_{\\ell-1}}$ will be correlated causing the terms $z_{h_\\ell}$ and $\\frac{\\mathrm{sign}(z_{h_{\\ell-1}})}{|z_{h_{\\ell-1}}| + \\epsilon}$ to partially cancel out.\n\n% This gradient can be particular problematic when considering that $E[z_{h_{\\ell-1}}] = 0$ is a desired property when initializing \\cite{glorot-initialization}.\n% A desired multiplication unit should not explode for $z_{h_{\\ell-1}}$ near zero, which is why supporting division is likely infeasible.\n\n\\begin{figure}[h]\n\\centering\n\\begin{subfigure}{.33\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth,trim={0 0 0 4.35cm},clip]{graphics/nac-mul-eps-1em7.png}\n  \\caption{$\\mathrm{NAC}_{\\bullet}$ with $\\epsilon = 10^{-7}$}\n\\end{subfigure}%\n\\begin{subfigure}{.33\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth,trim={0 0 0 4.35cm},clip]{graphics/nac-mul-eps-1em1.png}\n  \\caption{$\\mathrm{NAC}_{\\bullet}$ with $\\epsilon = 0.1$}\n\\end{subfigure}\n\\begin{subfigure}{.33\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth,trim={0 0 0 4.35cm},clip]{graphics/nac-mul-eps-1.png}\n  \\caption{$\\mathrm{NAC}_{\\bullet}$ with $\\epsilon = 1$}\n\\end{subfigure}\n%\\begin{subfigure}{.33\\textwidth}\n%  \\centering\n%\\includegraphics[width=\\linewidth]{graphics/nac-mul-nmu.png}\n%  \\caption{Our NMU solution}\n%\\end{subfigure}\n\n\\caption{RMS loss curvature for a $\\mathrm{NAC}_{+}$ layer followed by a $\\mathrm{NAC}_{\\bullet}$. The weight matrices are constrained to $\\mathbf{W}_1 = \\left[\\protect\\begin{smallmatrix}\nw_1 & w_1 & 0 & 0 \\\\\nw_1 & w_1 & w_1 & w_1\n\\protect\\end{smallmatrix}\\right]$, $\\mathbf{W}_2 = \\left[\\protect\\begin{smallmatrix}\nw_2 & w_2\n\\protect\\end{smallmatrix}\\right]$. The problem is $(x_1 + x_2) \\cdot (x_1 + x_2 + x_3 + x_4)$ for $x = \\left(1, 1.2, 1.8, 2\\right)$.\nThe solution is $w_1 = w_2 = 1$ with many unstable alternatives.}\n\\label{fig:nac-mul-eps-issue}\n\\end{figure}\n\n\\subsection{Initialization of \\texorpdfstring{$\\mathrm{NAC}_{\\bullet}$}{NAC-mul}}\nInitialization is important to consider for fast and consistent convergence.\nOne desired property is that weights can be initialized such that $E[z_{h_\\ell}] = 0$ \\cite{glorot-initialization}. Using second order Taylor approximation and assuming all $z_{h_{\\ell-1}}$ are uncorrelated; the expectation of $\\mathrm{NAC}_{\\bullet}$ can be estimated as\n\\begin{equation}\nE[z_{h_\\ell}] \\approx \\left(1 + \\frac{1}{2} Var[W_{h_\\ell, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\\right)^{H_{\\ell-1}} \\Rightarrow E[z_{h_\\ell}] > 1.\n\\label{eq:nac-mul:expectation}\n\\end{equation}\nAs shown in equation \\ref{eq:nac-mul:expectation}, satisfying $E[z_{h_\\ell}] = 0$ for $\\mathrm{NAC}_{\\bullet}$ is likely impossible. The variance cannot be input-independently initialized and is expected to explode (proofs in Appendix \\ref{sec:appendix:moments:nac-mul}).\n\n\\subsection{Neural multiplication unit}\n\\label{sec:method:nmu}\nTo solve the the gradient and initialization challenges for $\\mathrm{NAC}_{\\bullet}$ we propose a new unit for multiplication: the Neural Multiplication Unit (NMU)\n\n\\begin{align}\nW_{h_{\\ell-1},h_\\ell} &= \\min(\\max(W_{h_{\\ell-1},h_\\ell}, 0), 1), \\\\\n\\mathcal{R}_{\\ell,\\mathrm{sparse}} &= \\frac{1}{H_\\ell \\cdot H_{\\ell-1}} \\sum_{h_\\ell=1}^{H_\\ell} \\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} \\min\\left(W_{h_{\\ell-1},h_\\ell}, 1 - W_{h_{\\ell-1},h_\\ell}\\right) \\\\\n\\textrm{NMU}:\\ z_{h_\\ell} &= \\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} \\left(W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell} \\right) \\label{eq:nmu-defintion}\n\\end{align}\nThe NMU is regularized similar to the NAU and has a multiplicative identity when $W_{h_{\\ell-1},h_\\ell}=0$.\nThe NMU do not support division by design.\n%Previous experiments using the NALU for division do not work well on division hence very little is lost with this modification \\cite{trask-nalu}.\nAs opposed to the $\\mathrm{NAC}_{\\bullet}$, the NMU can represent input of both negative and positive values and is not $\\epsilon$ bounded, which allows the NMU to extrapolate to $z_{h_{\\ell-1}}$ that are negative or smaller than $\\epsilon$. Its gradients are derived in Appendix \\ref{sec:appendix:gradient-derivatives:gradient-nmu}.\n\n\\subsection{Moments and initialization}\n\\label{sec:methods:moments-and-initialization}\nThe NAU is a linear layer and can be initialized using \\citet{glorot-initialization}. The $\\mathrm{NAC}_{+}$ unit can also achieve an ideal initialization, although it is less trivial (details in Appendix \\ref{sec:appendix:moments:weight-matrix-construction}).\n\nThe NMU is initialized with $E[W_{h_{\\ell}, h_{\\ell - 1}}] = \\nicefrac{1}{2}$. Assuming all $z_{h_{\\ell-1}}$ are uncorrelated, and $E[z_{h_{\\ell-1}}] = 0$, which is the case for most neural units \\cite{glorot-initialization}, the expectation can be approximated to\n\\begin{equation}\nE[z_{h_\\ell}] \\approx \\left(\\frac{1}{2}\\right)^{H_{\\ell-1}},\n\\end{equation}\nwhich approaches zero for $H_{\\ell-1} \\rightarrow \\infty$ (see Appendix \\ref{sec:appendix:moments:nmu}). The NMU can, assuming $Var[z_{h_{\\ell-1}}] = 1$ and $H_{\\ell-1}$ is large, be optimally initialized with $Var[W_{h_{\\ell-1},h_\\ell}] = \\frac{1}{4}$ (proof in Appendix \\ref{sec:appendix:moments:nmu:initialization}).\n\n\\subsection{Regularizer scaling}\nWe use the regularizer scaling as defined in \\eqref{eq:regualizer-scaling}. We motivate this by observing optimization consists of two parts: a warmup period, where $W_{h_{\\ell-1},h_\\ell}$ should get close to the solution, unhindered by the sparsity regularizer, followed by a period where the solution is made sparse.\n\\begin{equation}\n\\lambda_{\\mathrm{sparse}} = \\hat{\\lambda}_{\\mathrm{sparse}} \\max\\left(\\min\\left(\\frac{t - \\lambda_{\\mathrm{start}}}{\\lambda_{\\mathrm{end}} - \\lambda_{\\mathrm{start}}}, 1\\right), 0\\right)\n\\label{eq:regualizer-scaling}\n\\end{equation}\n\n\\subsection{Challenges of gating between addition and multiplication}\n\\label{sec:methods:gatting-issue}\nThe purpose of the gating-mechanism is to select either $\\text{NAC}_{+}$ or $\\text{NAC}_{\\bullet}$ exclusively.\nThis assumes that the correct sub-unit is selected by the NALU, since selecting the wrong sub-unit leaves no gradient signal for the correct sub-unit.\n\nEmpirically we find this assumption to be problematic.\nWe observe that both sub-units converge in the beginning of training whereafter the gating-mechanism, seemingly randomly, converge towards either the addition or multiplication unit. Our study shows that gating behaves close to random for both NALU and a gated NMU/NAU variant. However, when the gate correctly selects multiplication our NMU converge much more consistently. (in-depth empirical analysis in appendix \\ref{sec:appendix:nalu-gate-experiment}, with results for both a shared and non-shared weight matrix between $\\text{NAC}_{+}$ and $\\text{NAC}_{\\bullet}$, and a gated version of NAU/NMU).\n\nAs the problem size grows, randomly choosing the correct gating value becomes an exponential increasing problem. Because of these challenges we leave solving the problem of sparse gating for future work and focus on improving the sub-units $\\text{NAC}_{+}$ and $\\text{NAC}_{\\bullet}$.", "meta": {"hexsha": "deb68073f6c309fbf772bb1f44001e7376351b19", "size": 14589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/methods.tex", "max_stars_repo_name": "AndreasMadsen/stable-nalu", "max_stars_repo_head_hexsha": "b3296ace137ffa4854edeef3759f1578b7650210", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 147, "max_stars_repo_stars_event_min_datetime": "2019-10-07T11:01:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T02:51:18.000Z", "max_issues_repo_path": "paper/sections/methods.tex", "max_issues_repo_name": "AndreasMadsen/stable-nalu", "max_issues_repo_head_hexsha": "b3296ace137ffa4854edeef3759f1578b7650210", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-03T12:40:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T12:40:21.000Z", "max_forks_repo_path": "paper/sections/methods.tex", "max_forks_repo_name": "AndreasMadsen/stable-nalu", "max_forks_repo_head_hexsha": "b3296ace137ffa4854edeef3759f1578b7650210", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2019-12-21T15:58:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T08:32:38.000Z", "avg_line_length": 97.9127516779, "max_line_length": 715, "alphanum_fraction": 0.7182808966, "num_tokens": 4694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6683254575575726}}
{"text": "\\section*{Integration technics}\n\\cm{HAVE NO IDEA HOW TO START THIS SECTION}\nEuler first order explicit\n\\begin{align}\\label{eqn:euler}\n    \\begin{split}\n        &v(t+\\Delta{t}) = v(t) + a(t) * \\Delta{t}\\\\\n        &x(t+\\Delta{t}) = x(t) + v(t) * \\Delta{t}\n    \\end{split}\n\\end{align}\n\\par\nThe central difference scheme, also known as velocity Verlet is a very widely\nused integration method of second order. Velocities in the upcoming time step $t\n+ \\Delta{t}/2 $ and positions at $t + \\Delta{t}$ are calculated as\n\\begin{align}\\label{eqn:verlet}\n    \\begin{split}\n        &v(t + \\Delta{t}/2) = v(t + \\Delta{t}/2) +a(t - \\Delta{t}/2) * \\Delta{t}\\\\\n        &x(t + \\Delta{t}) = x(t) +v(t + \\Delta{t}/2) * \\Delta{t}\\\\\n    \\end{split}\n\\end{align}\n\\par\nThe fourth order Gear’s method (GPC4). In the prediction step positions and\ntheir higher derivatives are calculated based on Taylor series expansions as\n\\begin{equation}\\label{eqn:gearP}\n    \\begin{split}\n        b(t+\\Delta{t}, p) =& b(t)\\\\\n        a(t+\\Delta{t}, p) =& a(t) + b(t) *\\Delta{t}^2\\\\\n        v(t+\\Delta{t}, p) =& v(t) + a(t) *\\Delta{t} + \\frac{1}{2} * b(t) *\\Delta{t}^2\\\\\n        x(t+\\Delta{t}, p) =& x(t) + v(t) * \\Delta{t} + \\frac{1}{2} * a(t) *\\Delta{t}^2 +\\\\\n        &\\frac{1}{6} * b(t) *\\Delta{t}^3\\\\\n    \\end{split}\n\\end{equation}\nwith the first and second derivative of the accelerations for GPC3 calculated as:\n\\begin{align}\\label{eqn:gearJerk3}\n    b(t) = \\frac{\\Delta{a(t)}}{\\Delta{t}}, c(t) = 0\n\\end{align}\\par\nIn the evaluation step the difference in the accelerations calculated based on\nthe acceleration $a(t+ \\Delta{t}, p)$ and the acceleration $a(t+\\Delta{t})$\ncalculated from positions $x(t+\\Delta{t}, p)$ and velocities $v(t+\\Delta{t}, p)$\nis obtained by\n\\begin{align}\\label{eqn:gearDa}\n    \\Delta{a} = a(t + \\Delta{t}) - a(t + \\Delta{t}, p)\n\\end{align}\n\\par\nIn the following, correction step positions and their higher derivatives are\ncalculated based on their values from the previous time step and the obtained\ndifference in acceleration as\n\\begin{align}\\label{eqn:gearCorrector}\n    \\begin{split}\n        &x(t+\\Delta{t}) = x(t+\\Delta{t}, p) + k1 * \\Delta{a} * \\Delta{t}^2\\\\\n        &v(t+\\Delta{t}) = v(t+\\Delta{t}, p) + k2 * \\Delta{a} * \\Delta{t}\\\\\n        &a(t+\\Delta{t}) = a(t+\\Delta{t}, p) + k3 * \\Delta{a}\\\\\n        &b(t+\\Delta{t}) = b(t+\\Delta{t}, p) + k4 * \\frac{\\Delta{a}}{\\Delta{t}}\\\\\n    \\end{split}\n\\end{align}\n\\par\nGear’s scheme parameters k1-k5 for GPC3:\n$k_1=1/12$, $k_2=5/12$, $k_3=1$, $k_4=1$, $k_5=0$\\par", "meta": {"hexsha": "b65dfad43030d072abc6a6a8c787698ca30f3235", "size": 2501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "young_researchers_2021q1/integrationTechnics.tex", "max_stars_repo_name": "alexgubanow/phd_articles", "max_stars_repo_head_hexsha": "755fa2c17de7db928f536cb8b4d0789813ac4b6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "young_researchers_2021q1/integrationTechnics.tex", "max_issues_repo_name": "alexgubanow/phd_articles", "max_issues_repo_head_hexsha": "755fa2c17de7db928f536cb8b4d0789813ac4b6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "young_researchers_2021q1/integrationTechnics.tex", "max_forks_repo_name": "alexgubanow/phd_articles", "max_forks_repo_head_hexsha": "755fa2c17de7db928f536cb8b4d0789813ac4b6f", "max_forks_repo_licenses": ["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.8771929825, "max_line_length": 90, "alphanum_fraction": 0.606157537, "num_tokens": 922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6682737249002708}}
{"text": "This section presents previous work which inspired and laid the foundation for this thesis. Relevant publication on topics related to this thesis are presented in terms of methods and results. We focus on the fields of relational graph convolutions, graph encoders, and embedding-based link prediction.\n\n\\subsection{Relational Graph Convolutions}\nWe define a graph as $G=(\\mathcal{V}, \\mathcal{E})$  with a set of nodes $\\mathcal{V}$ and a set of edges $\\mathcal{E}$. The set of edges, with each edge connecting node $x$ and $y$, is defined by $\\left\\{(x, y) \\mid(x, y) \\in \\mathcal{V}^{2} \\wedge x \\neq y\\right\\}$ while the constraint $x \\neq y$ prohibits self-connections or self-loops, which is optional depending on the graphs function. Moreover, nodes and edges can have features, which contribute additional information about the nodes and their connection. In the literature, these features can be describing attributes and properties, in the context of this work we also use them as indicators to unique entities. Graph convolutions, make use of both these properties and the spectral information in a graphs adjacency matrix. In graph theory spectral properties are the characteristic polynomial, eigenvalues, and eigenvectors of the Laplacian and adjacency matrix \\cite{chung1997spectral}. Two popular tasks to evaluate the performance of a neural network on graphs, are node classification and link prediction. The first is a classification problem where the model predicts the class of a node. Link prediction is the task of completing a triple by correctly predicting the missing entity at either head or tail the triple. A in-depth explanation follows in section \\ref{ssec4:lpmetrics}.\n\n\n% Present the relational graph convolution model paper by Kipf and maybe others\nIn Kipf \\textit{et al.} paper on graph convolutions \\cite{kipf_semi-supervised_2017} a novel Graph Convolution Network (GCN) for semi-supervised classification is introduced. The model takes as input the adjacency matrix and optionally a feature matrix of the graph and predicts the classes of the nodes. Graph convolutions acts directly on the graph structure and are linearly scalable with the number of nodes. The GCN takes as input the adjacency matrix $A \\in \\mathbb{R}^{n \\times n}$ with $n$ being the number of nodes in the graph. In the case of undirected graphs, the adjacency matrix is symmetric. The output is a matrix $H \\in \\mathbb{R}^{n \\times d_h}$ where $d_h$ are the hidden dimensions or in case od the last layer, the number of classes to predict over. \nWhile the authors compare different propagation methods for the graph convolutions, their propagating rule using a first-order approximation of spectral graph convolutions, outperforms all other implementations. Propagation denotes the transformation of the input data between layers of a model. Kipf approximates the eigenvalues of the Laplacian with first order Chebyshev polynomials and circumvents the computationally expensive Eigendecomposition. The renormalization trick normalized the adjacency matrix and adds it to an identity matrix of same size. This keeps the eigenvalues in a range between $[0,2]$ which again leads to a stable training, avoiding numerical instabilities and vanishing gradients during learning. Additionally the feature information of neighboring nodes is propagated in every layer what shows improvement in comparison to earlier methods, where only label information is aggregated.\nKipf and Welling perform node classification on the three citation-network datasets, Citeseer, Cora and Pubmed as well as on the KG dataset NELL. In all classification tasks, their results outperform other recently proposed methods in this field and proves to be computationally more efficient than its competition. For more details on the implementation of graph convolutions we refer to section \\ref{ssec:gcn}. \n\n% Kipfs second paper \nIn their publication \\textit{Modeling Relational Data with Graph Convolutional Networks} Schlichtkrull \\textit{et al.} propose a relational graph convolutional network (RGCN) and evaluate it on link prediction on the FB15K-237 and WN18 dataset and node classification on the AIFB, MUTAG, BGS and AM datasets \\cite{gangemi_modeling_2018}. The RGCN, with its encoder properties, is used by itself as node classifier, yet for link prediction it is coupled with a DistMult model acting as decoder which scores triples encoded by the RGCN see figure \\ref{fig:RGCN}. We go into details of the embedding-based DistMult model in section \\ref{ssec:embedlp}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.55\\textwidth]{data/images/RGCN.png}\n    \\caption{RGCN with encoder-only for node classification and encoder-decoder architecture for link prediction experiments. Source \\cite{gangemi_modeling_2018}.}\n    \\label{fig:RGCN}\n\\end{figure}\n\nThe RGCN works on dense graphs stored as triples, creating a hidden state for each node. A novel message passing network is layer-wise propagated with the hidden states of the entities. As regularization the authors propose a \\textit{basis-} and \\textit{block-wise} decomposition. while the first  aims at an effective weight sharing between different relation types, the second  can be seen as a sparsity constraint on the relation type's weight. The model outperforms embedding based model on the link prediction task on the FB15K-237 dataset and scores competitive on the WN18 dataset. In the node classification task, the model sets state of the art results on the datasets AIFB and AM, while scoring competitive on the remaining. The authors conclude, that the model has difficulties encoding higher-degree hub nodes on datasets with many entities and low amount of classes. This is noticeable as it relates to the WN18RR \\cite{battaglia_relational_2018}, one of the two datasets used in this thesis.  \n\n\n\\subsection{Graph VAE}\n% Present different papers with graph VAEs\nWe have seen how graph convolutional neural networks can be combined in an encoder-decoder architecture, resulting in a generative model suitable for unsupervised learning. We present three recent publications with different methods and use cases of a graph generative model, in particular a VAE.\n\n% Kipfs VGAE\nKipf \\textit{et al.} introduce the the Variational Graph Autoencoder (VGAE), a framework for unsupervised learning on graph-structured data \\cite{kipf_variational_2016}. This generative model uses a GCN as encoder and a simple inner product module as decoder. Similar to the GCN, the VGAE incorporates node features, which significantly improves its performance on link prediction tasks compared to related models. The VGAE uses a two-layer GCN to encode the mean and the logvariance for the stochastic module to sample the latent space representation, more specifically, a latent vector per node. Referring to the above described GCN, the VGAE encoder outputs a latent matrix $H \\in \\mathbb{R}^{n \\times 2d_z}$ with $d_z$ denoting the latent dimension. The activation of the inner product of this latent matrix yields the reconstruction of the adjacency matrix. Figure \\ref{fig:kipfGVAE} shows how the model learns to cluster  nodes according to their class, without these labels being provided to the model during training.\nThis visualization shows that the VGAE learns successful learn an implicit representation of the data.\nThe VGAE with added features outperforms state of the art methods (to the time of publication) Spectral Clustering \\cite{tang2011leveraging} and Deepwalk \\cite{perozzi2014deepwalk} in the task of link prediction on the datasets Cora, Citeseer and Pubmed. The authors point out, that a Gaussian prior might be a poor choice combined with the inner-product decoder.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{data/images/KipGVAE.jpg}\n    \\caption{Visualization of the VGAE's latent representation of the Core citation network. Colors express the disentanglement of node classes. Source \\cite{kipf_variational_2016}}\n    \\label{fig:kipfGVAE}\n\\end{figure}\n\n% TODO I think it's important to state the difference between GVAE and GraphVAE very clear (that is the GVAE learns a latent vector per node and the GraphVAE learn a lv for the whole graph).\n\n\nSimonovsky \\textit{et al.} introduce the GraphVAE, which generates a probabilistic fully-connected molecule graph of a predefined maximum size\nin a one-shot approach \\cite{simonovsky_graphvae_2018}. In this context fully-connected denotes that all nodes are connected within a graph, in contrast to citation networks where subgraphs can be disconnected from each other. While molecule graphs have a lower node and edge count than citation networks, their edges and nodes are attributed, which constrains each connection. The model includes a standard graph matching algorithm, which finds the optimal permutation between the predicted graph and the ground truth and. The reconstruction loss considers the permutation instead of the raw prediction. In contrast to the previously presented publications, the input to this model is a threefold and sparse graph, defined as $G=(A, E, F)$ with $A$ being the adjacency matrix, $E$ the edge attribute matrix and $F$ the node attribute matrix, with $E$ and $F$ being one-hot encoded. Considering that this method lays the foundation for this thesis, we adopt this notation for our own methods in section \\ref{sec:mthods}. Figure \\ref{fig:graphvaefull} shows the architecture of the GraphVAE. The encoder is a feed forward network with edge-conditioned graph convolutions \\cite{simonovsky2017dynamic}, which takes as input the target graph $G$ with $n$ nodes. After the convolutions the result is flattened and conditioned on the node labels $y$. A fully-connected neural network encodes the stochastic latent representation, which is constrained by Standard Gaussian prior distribution. Note that in contrast to the GCN, which encodes one latent vector per node, the GraphVAE instead encodes a latent representation of the whole graph. This latent representation is again conditioned on the node labels $y$ and propagated through the decoder in form of a fully-connected neural network. The decoder reconstructs the latent representation to the graph prediction. The threefold decoder output is matched with the target using graph matching algorithm, which we discuss further in section \\ref{ssec:graphmatch}. The matched and permuted graph is then used for the reconstruction term of the GraphVAE loss. It should be noted, that, while the size of the target and prediction graph are fixed, they do not necessarily have to match. While this approach seems promising, it is limited by the maximum graph size, which has been experimented with up to a node count of $40$.\n\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{data/images/GraphVAEfull.png}\n    \\caption{Model architecture of the GraphVAE. Source \\cite{simonovsky_graphvae_2018}.}\n    \\label{fig:graphvaefull}\n\\end{figure}\n\nThe model is trained on the QM9 dataset, containing the graph structure of 134k organic molecules with experiments on latent space dimension in the range of $[20,80]$. On the free generation task, about $50\\%$ of the generated molecules are chemically valid and thereof remarkably $60\\%$ are not included in the training dataset. When testing the model for robustness, it showed little disturbance when adding Gaussian noise to the input graph $G$. The authors conclude that the problem of generating graphs\nfrom a continuous embedding was addressed successfully and that the GraphVAE performs better on small molecules, implying a low node count per graph.\n\n\nUntil here the presented models generate graphs in a single propagation through the model. For completeness we also present a successful approach for graph generation in autoregressive manner. Belli \\textit{et al.} introduce named approach for image-conditioned graph generation of road network graphs \\cite{belli_image-conditioned_2019}. While we focus on the generative model, their contribution ranges wider, namely the introduction of the graph-based roadmap dataset \\textit{Toulouse Road Network} and the task specific distance metric \\textit{StreetMover}. The authors propose the Generative Graph Transformer (GGT) a deep autoregressive model that makes use of attention mechanisms on images, to tackle the challenging task of road network extraction from image data. The GGT has a encoder-decoder architecture, with a CNN as encoder, taking the grayscale image as input signal and predicting a conditioning vector. The decoder is a self-attentive transformer, which takes as input the encoded condition vector and a hidden representation of the adjacency matrix $A$ and feature vector $X$ of the previous step. The adjacency matrix here indicates the links between steps and the features are normalized coordinates. A multi-head operator outputs the hidden representation of $A$ and $X$ which finally are decoded by a MLP to the graph representation. For the first step, a empty hidden representation is fed into the decoder. The model terminates the recurrent graph generation by predicting a end-of-sequence token, which signalizes the end of the graph. During learning, the generated graphs are matched to the target graphs using the \\textit{StreetMover} metric, based on the Sinkhorn distance. The authors attribute \\textit{StreetMover} as a scalable, efficient and permutation-invariant metric for graph comparison. The successful results of the experiments performed, show that this novel approach is suitable for the task of road network extraction and could yield similar success in graph generation task of different fields.\nWhile this publication does not directly align with the previously presented work, we find it of added value to present alternative approaches on our topic.\n\n% \\begin{itemize}\n%     \\item Belli recurrent VAE\n%     \\item GraphVAE paper\n%     \\item Variational Graph Auto-Encoders\n% \\end{itemize}\n\n\n\\subsection{Embedding-Based Link Prediction}\n\\label{ssec:embedlp}\nFinalizing this chapter, we look at embedding-based methods on KGs.\nCompared to the previously presented research, embedding models have a much simpler architecture and can be trained computationally very efficient on large graphs. Embedding-based models can only operate on triples, meaning a KG is represented as a set of triples with indices pointing to the unique entity and relation in the graph. Despite their simplicity, they achieve great results on node and link prediction tasks.\n\nAlready in 2013 Bordes \\textit{et al.} introduced in their paper \\textit{Translating Embeddings for Modeling Multi-relational Data} the low-dimensional embedding model TransE \\cite{bordes_translating_2013}. The core idea of this model is that relations can be represented as translations in the embedding space. Entities are encoded to a low-dimension embedding space and the relation is represented as vector between the head and tail entity. The assumption is that for correct triples the model learns to reduce the Euclidean distance between head and tail entity by placing them closer together in the embedding space. This results in correct triples having a lower norm of the relational vector than corrupted triples. Using this property, the model can predict the missing entity in link prediction.\n\nThe models loss function takes a set of corrupted triples for every triples in the training set and subtracts the translation vector of the corrupted triple in embedding space from the translation vector of the correct triple with added margin. To minimize the loss, the model has to place entities of correct triples closer together in embedding space. We think of a triple as $(s,r,o)$ and $(e_s,e_r,e_o)$ as its embedded representation, $d()$ the Euclidean distance, $\\gamma$ the positive margin and $S$ and $S^{\\prime}$ as sets of correct and corrupt triples, the loss function of TransE is \n\n\\begin{equation}\n    \\mathcal{L}=\\sum_{S} \\sum_{S^{\\prime}} \\left[\\gamma+d(\\boldsymbol{s}+\\boldsymbol{r}, \\boldsymbol{o})-d\\left(\\boldsymbol{s}^{\\prime}+\\boldsymbol{r}, \\boldsymbol{o}^{\\prime}\\right)\\right].\n\\end{equation}\n\nThe model is trained on a subset of the KGs Freebase and Wordnet, which is also the source for the datasets used in this thesis. TransE's link prediction results on both head and tail outperformed other competing methods of the time, such as RESCAL \\cite{nickel_three-way_nodate}.\n\nIn 2015, Yang \\textit{et al.} proposed a similar, yet better performing KG embedding method \\cite{yang_embedding_2015}. Their model DistMult captures relational semantics by matrix multiplication of the embedded entity representation and uses a bilinear learning objective. The main difference to TransE is the bilinear scoring function $d^{b}()$. Bilinear is indicated by the exponent $b$ and connotes the functions score-invariance of swapping the triples head and tail entity. For the embedding space representation of subject and object $e_s$ and $e_{o}$ and a diagonal matrix $\\operatorname{diag}(e_{r})$ with the embedded relation $e_r$ on the diagonal, the scoring function is\n\n\\begin{equation}\n    d^{b}\\left((e_s,e_r,e_o)\\right)=e_s \\operatorname{diag}(e_{r}) e_o.\n    \\label{eq2:distmult}\n\\end{equation}\n\nThe publication goes on to explore the options of embedding-based rule extraction from KGs. Concluding, the authors state that the prediction scores achieved with the embeddings learned from the bilinear objective not only outperform the state of the art in link prediction but can also capture compositional semantics of relations and extract Horn rules using compositional reasoning.\n\nIn a more recent publication, Ruffinelli \\textit{et al.} present a comprehensive review of KG embedding models such as TransE and DistMult, coupled with state of the art techniques in deep learning. The authors start by pointing out the similarities and differences of most models. While all methods share the same embedding approach, they differ in their scoring function and their original hyperparameter search. The authors perform a quasi-random hyperparameter search on the five models RESCAL, TransE, DistMult, ComplEx and ConvE, which each use a characteristically different loss function. They are compared by their MRR and Hits@$10$ scores on the two datasets FB15K-237 and WN18. Since these metrics and datasets are used later on in our research, they are explained in section \\ref{ssec5:data}(datasets) and \\ref{ssec4:lpmetrics}(metrics). The tuned models report a higher MRR score of up to $24\\%$ compared to their first reported performance. The authors conclude that simple KG embedding methods can show strong performance when trained with state of the art techniques what indicates that higher complexity is not necessary. The optimal model configurations, which were found by a random search of the hyperparameter space, are included in this publication. \n\n% Graph Embeddings\\\\\n% TransE represents entities in in low-dimensional embedding. The relationships between entities are represented by the vector between two entities \\cite{bordes_translating_2013}.\n% (How are different relation between the same entities represented?)\n\n% OntoUSP\\\\\n% This method learns a hierarchical structure to better represent the relations between entities in embedding space.\n", "meta": {"hexsha": "85859d76a7455e41ea707b3194b76dc4ef891a9b", "size": 19339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/section2.tex", "max_stars_repo_name": "3lLobo/Thesis", "max_stars_repo_head_hexsha": "8c600c1a617406ff8e1ffb118b5dd6b1dbbe3097", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-10T16:15:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-10T16:15:04.000Z", "max_issues_repo_path": "sections/section2.tex", "max_issues_repo_name": "3lLobo/Thesis", "max_issues_repo_head_hexsha": "8c600c1a617406ff8e1ffb118b5dd6b1dbbe3097", "max_issues_repo_licenses": ["MIT"], "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/section2.tex", "max_forks_repo_name": "3lLobo/Thesis", "max_forks_repo_head_hexsha": "8c600c1a617406ff8e1ffb118b5dd6b1dbbe3097", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 191.4752475248, "max_line_length": 2367, "alphanum_fraction": 0.806246445, "num_tokens": 4218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6682165206721826}}
{"text": "\\documentclass[en,12pt]{elegantpaper}\n\n\\begin{document}\n    \\section*{2}\n    \\noindent Because normal distribution is exponential family, $\\bar{X}, S^2$ is the sufficient and complete (because the interior of the natural parameter space is not empty) statistics for $\\mu$ and $\\sigma^2$. And $\\bar{X}\\sim N(\\mu, \\sigma^2/n)$, \n    \\[\n        Var(\\bar{X})=\\mathbb{E}(\\bar{X}^2)-(\\mathbb{E}X)^2, \n    \\]\n    \\[\n        \\mathbb{E}(\\bar{X}^2)=\\mu^2+\\frac{\\sigma^2}{n}. \n    \\]\n    So, \\[\n        \\mathbb{E}\\left(\\bar{X}^2-\\frac{S^2}{n}\\right)=\\mu^2. \n    \\]\n    From \\emph{Lehman-Scheffe theorem}, we can know that $T(X)=\\bar{X}^2-S^2/n$ is UMVU of $\\mu^2$. \n\n\\end{document}", "meta": {"hexsha": "84dc3257e98d007720d6fb252ab6b05a35bfd0ab", "size": 670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/midterm1/2.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/2.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/2.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": 39.4117647059, "max_line_length": 253, "alphanum_fraction": 0.5880597015, "num_tokens": 256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6682165150827574}}
{"text": "\\subsection{Simply Periodic Functions}\r\nOur next goal is to classify meromorphic functions on other Riemann surfaces.\r\nMany Riemann surfaces we have described in the form $R=D/\\sim$ where $D$ is a domain and $\\sim$ is an equivalence relation.\r\nThis is useful in the sense that functions on $R$ are automatically periodic on $D$ with respect to $\\sim$.\r\n\\begin{definition}\r\n    Let $f:\\mathbb C\\to\\mathbb C_\\infty$ be meromorphic,\r\n    A period of $f$ is a complex number $\\omega\\in\\mathbb C$ such that $f(z+\\omega)=f(z)$ for all $z\\in\\mathbb C$.\r\n\\end{definition}\r\nNote that the periods of $f$ forms a additive subgroup $\\Omega\\le\\mathbb C$.\r\n\\begin{lemma}\r\n    Let $\\Omega$ be the set of periods of a meromorphic function $f$ on $\\mathbb C$, then one of the following holds:\\\\\r\n    (i) $\\Omega=\\{0\\}$.\\\\\r\n    (ii) $\\Omega=\\langle \\omega\\rangle\\cong\\mathbb Z$ for $\\omega\\neq 0$.\\\\\r\n    (iii) $\\Omega=\\langle w_1,w_2\\rangle\\cong\\mathbb Z^2$ where $\\omega_1,\\omega_2\\neq 0,\\omega_1/\\omega_2\\notin\\mathbb R$.\\\\\r\n    (iv) $\\Omega=\\mathbb C$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    See example sheet.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A meromorphic function $f$ on $\\mathbb C$ whose group of periods contains $\\langle\\omega\\rangle\\cong\\mathbb Z,\\omega\\neq 0$ is called simply periodic.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\exp$ has $\\Omega=\\langle 2\\pi i\\rangle$.\r\n\\end{example}\r\nObserve that $\\exp$ is also a covering map.\r\nIn fact,\r\n\\begin{proposition}\\label{simply_periodic}\r\n    If $f$ is a meromorphic function on $\\mathbb C$ and the periods of $f$ contains an infinite cyclic subgroup $\\langle\\omega\\rangle$, then there is a unique meromorphic function $\\bar{f}$ on $\\mathbb C_\\star$ such that $f(z)=\\bar{f}\\circ\\exp(2\\pi iz/\\omega)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Uniqueness is trivial.\r\n    For existence, we choose any branch of $\\log$ and define $\\bar{f}(w)=f(\\omega\\log(w)/(2\\pi i))$ which does satisfy $\\bar{f}\\circ\\exp(2\\pi iz/\\omega)=f$.\r\n    It remains to show that $\\bar{f}$ is well-defined.\r\n    Suppose we have chosen a different branch of $\\log$, then the function we obtained instead would be $\\hat{f}=f(\\omega(\\log w+2\\pi in)/(2\\pi i))$ for some $n\\in\\mathbb Z$.\r\n    But this is just $\\bar{f}(w)$ since $n\\omega$ is a period of $f$.\r\n\\end{proof}\r\nTherefore simply periodic functions are in one-to-one correspondence to functions on $\\mathbb C_\\star$.\r\nThis is natural since $\\mathbb C_\\star\\cong\\mathbb C/\\langle\\omega\\rangle$ conformally via $z\\mapsto\\exp(2\\pi iz/\\omega)$.", "meta": {"hexsha": "e7968936fae7068e64f2fea2c24862975eccedf2", "size": 2504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13/simply.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/simply.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/simply.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": 64.2051282051, "max_line_length": 262, "alphanum_fraction": 0.6916932907, "num_tokens": 781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.66821651113356}}
{"text": "\\chapter{The Basics of Classification \\label{chapter:classification}}\n\nClassification is a form of supervised learning in which our goal is to learn a mapping between some features, $x$, and an output, $y$. In classification, the output, $y$, is a category. In \\textbf{binary classification} (by far the most common), there are only two categories: yes or no, usually represented as ``0'' (no) or ``1'' (yes). In \\textbf{multi-class classification}, there are more than two categories.\n\nTo learn an appropriate mapping, we feed \\textbf{training data} to a \\textbf{learning algorithm}. Different algorithms learn different types of mappings.\n\n\\section{Definitions}\n\n\\begin{itemize}\n\\item \\textbf{Training data:} The data used, along with an appropriate learning algorithm, to create the mapping between input and output. It is composed of \\textbf{training examples}, a.k.a. \\textbf{samples}, each consisting of one or more input features and a single output.\n\\item \\textbf{Test data:} An independent dataset, not used in model training, on which the performance of a trained supervised learning model is evaluated. \n\\item \\textbf{Feature:} Also known as a \\textbf{predictor}, or \\textbf{covariate}, one of the inputs to a supervised learning algorithm.\n\\item \\textbf{Output:} Also known as the \\textbf{outcome}, or \\textbf{label}, the thing you are trying to predict.\n\\item \\textbf{Feature space:} Envisioning each feature as having its own axis that is orthogonal to all of the other features' axes, the multidimensional space spanned by those axes (or rather: unit vectors in the directions of those axes)\n\\item \\textbf{Extrapolation:} Making predictions outside the region of the feature space occupied by the training data. This will often lead to errors. \n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Visualizing the Classification Problem \\label{section:visualizingclass}}\n\nImagine we want to predict whether a patient will be readmitted to the emergency room (ER) within $30$~days of hospital discharge. We gather data on two predictors: a disease severity score ($x_1$), which characterizes the severity of illness, and a social determinants score ($x_2$), which characterizes the patient's socioeconomic status. We have data on $200$~patients.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-just-data.png}\n\\end{center}\n\nIn this figure, the color refers to whether a patient was readmitted (blue = ``no'', red = ``yes''). The location of each point is governed by the patient's disease severity score ($x_1$, horizontal axis) and social determinants score ($x_2$, vertical axis). Our goal in classification is to draw a \\textbf{decision boundary}\\index{decision boundary} through this space, on one side of which we will predict that the patient is readmitted, and on the other side not.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Three Classification Algorithms}\n\n\\subsection{Logistic Regression \\label{ssect:logreg}}\n\nThe simplest decision boundary is, arguably, a line. The logistic regression\\index{logistic regression} algorithm simply draws a line\\footnote{In a higher-dimensional feature space, the decision boundary for logistic regression is a \\textbf{hyperplane}.} through the feature space that divides the positive and negative training examples. \n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-logistic.png}\n\\end{center}\n\n\\noindent The output of a fitted logistic regression model from R looks like this:\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/glm-binomial-example.png}\n\\end{center}\n\n\\noindent The equation of the line (or, in higher dimensions, hyperplane) that forms the decision boundary in logistic regression can be obtained by setting the linear sum of coefficients of this model equal to zero. \n\\begin{align*} \n0.9780 + 0.1344 x_1 - 1.3981 x_2 = 0 \\\\\n\\implies x_2 = \\frac{0.9780 + 0.1344 x_1}{1.3981}\n\\end{align*}\n\n\\noindent At any point, $(x_1, x_2)$, in the feature space, the model's predicted probability of a positive outcome (i.e. probability of an ER readmission) is related to the coefficients by this equation\n$$ \\log \\frac{P[Y=1]}{1 - P[Y=1]} = 0.9780 + 0.1344 x_1 - 1.3981 x_2 $$\nThe decision boundary occurs when $P[Y=1] = 0.5$ (total uncertainty, e.g. a coin toss). Another way to write this equation is:\n$$ P[Y=1] = \\frac{1}{1 + \\exp(-(0.9780 + 0.1344 x_1 - 1.3981 x_2))} $$\nThe functional form on the right, $1/(1 + \\exp(-z))$, is called the \\textbf{logistic function}; this is how logistic regression got its name. We will learn much more about the math behind logistic regression in subsequent chapters. \n\n\\subsection{K Nearest Neighbors (KNN)}\n\nAnother -- completely different -- approach to classification is to start with no assumptions about the shape of the decision boundary. To make a prediction about a new patient, we simply identify the $K$ nearest neighbors to that patient from our training set and allow them to vote on whether or not the new patient will be readmitted. The parameter $K$ must be set independently and is called a \\textbf{hyperparameter}. \n\n\\noindent Here is the decision boundary for KNN with $K=15$:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-knn-15.png}\n\\end{center}\n\n\\subsection{Decision Tree \\label{ssect:class_decision_tree}}\n\nFinally, we may choose to use our training data to build a decision tree\\index{decision tree}, which will allow us to make predictions on new patients using a series of simple yes/no questions. There are different decision tree learning algorithms, but here is the tree produced by a famous one called CART:\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/esl-decision-tree-just-tree.png}\n\\end{center}\nAnd here is the decision boundary produced by this tree:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-decision-tree.png}\n\\end{center}\n\n\\begin{question}{}\nHow can you tell, just by looking at these images, which feature ($x_1$ or $x_2$) impacts the outcome the most? Which one is it?\n\\end{question}\n\n\\begin{question}{}\nThere are six rectangular regions in the picture of the decision tree decision boundary. Each corresponds to one of the six leaves of the tree. Identify all six and which leaves they correspond to on the decision tree.\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Classification with Probabilities}\n\nWe can think of classification as simply drawing a decision boundary, but underlying each algorithm is a quantitative assessment of each point in the feature space. Each algorithm is, in its own way, able to provide a degree of certainty, or \\textbf{probability}\\footnote{Pedantic footnote: this is a Bayesian definition of probability, as opposed to a frequentist definition. More on that later.}, that a point belongs to the positive outcome class. \n\nFor example, here is the feature space of the example we just saw, colored by the probability, according to logistic regression, that a sample at each point should be classified as positive (i.e. the patient will be readmitted to the ER): \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-logistic-prob.png}\n\\end{center}\n\nThe solid line is the decision boundary, and the dashed lines indicate where the probability of a positive outcome (ER readmission) is 25\\% (top line) and 75\\% (bottom line). You can see that the color of the background gets purer red or purer blue the further you get from the decision boundary, but that near the decision boundary, the color is rather murky. That murkiness reflects the algorithm's uncertainty about the outcome. At the decision boundary, it is maximally uncertain. There the probability of a positive outcome is 50\\%: a coin toss. Here is a similar plot for KNN ($K=15$): \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-knn-15-prob.png}\n\\end{center}\n\nYou can see that the shapes of the 25\\% and 75\\% probability lines have much more complex shapes than for logistic regression, but the story is the same: you have regions of pure blue or red, where the algorithm is certain, and you have a murky region near the decision boundary. Now, finally, here is the same plot for the decision tree:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/esl-decision-tree-prob.png}\n\\end{center}\nThe color of the background in the regions corresponding to the six leaves of the tree is the same throughout each region. That's because the probability in each rectangular region (corresponding to each leaf of the tree) is constant. It equals the number of red dots in that region divided by the total number of dots. \n\n\\begin{question}{}\nWhat are the advantages and disadvantages of each algorithm?\n  \\begin{enumerate}\n  \\item Logistic regression?\n  \\item KNN ($K=15$)?\n  \\item Decision tree?\n  \\end{enumerate}\n\\end{question}\n\n\\begin{question}{}\nWhat makes a good classification algorithm? Consider issues of accuracy, generalizability, and speed (both to train the algorithm and to use it to make predictions on new samples). \n\\end{question}\n\n", "meta": {"hexsha": "4207d5b46914f707d7b64c4c8e0cfb6cdaccf459", "size": 9165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-classification.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-classification.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-classification.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": 74.512195122, "max_line_length": 592, "alphanum_fraction": 0.7523186034, "num_tokens": 2213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6682165055441341}}
{"text": "\\section*{Week 6A: Financial Statement Analysis and Ratios}\n\n\\subsection*{Solvency and Liquidity Ratios}\n\n$Debt/EquityRatio = \\frac{Total Liabilibies}{Total Shareholder's Equity}$ \\\\\n\n$Leverage Ratio = \\frac{TotalAssets}{Total Shareholder's Equity}$ \\\\\n\n$Leverage Ratio = \\frac{A}{L}=\\frac{E+L}{L} = 1+ Debt/EquityRatio$ \n\n\n$Current Ratio = \\frac{Current Assets}{Current Liabilities}$ \\\\\n\n\n$Working Capital = \\\\ Current Assets - Current Liabilities $ \n\n\n\n\\subsection*{Solvency and Liquidity Ratios}\n\n$Net Margin = \\frac{Net Income}{Revenue}$ \\\\\n\n$Gross Margin = \\frac{Revenue - COGS}{Revenue}$ \\\\\n\n$ROA = \\frac{Net Income}{Total Assets}$ \\\\\n\n$ROE = \\frac{Net Income}{Shareholders' Equity}$ \n\n\\subsection*{Operating Efficiency}\n\n$Asset Turnover = \\frac{Revenue}{Total Assets}$  \\\\\n\n$A/R Turnover = \\frac{Revenue}{Net Accounts Receivable}$  \\\\\n\n$Inventory Turnover = \\frac{COGS}{Inventory}$  \\\\\n\n$Days Receivable = \\frac{365}{A/R Turnover}$  \n\n\\subsection*{DuPont Decomposition}\n\n$ROE = \\frac{NI}{Equity}$ \\\\\n\n$ROE = \\frac{NI}{Assets} \\frac{Assets}{Equity} = ROA \\cdot Leverage$  \\\\\n\n$ROE = \\frac{NI}{Sales} \\frac{Sales}{Assets}\\frac{Assets}{Equity} \\\\\n ROE = ProfitMargin \\cdot AssetTurnover \\cdot Leverage $  \\\\\n \n\n\\section*{Week 6B: Income Taxes}\n\n$AccountingIncome \\neq Taxable Income$ \\\\\n$Tax Expense \\neq Cash Taxes $ \\\\\n\n\n\\subsection*{Deferred Tax Liability - DTL}\n\nDeferred tax liabilities increase when a timing difference leads to: \\\\\n $PretaxIncome_{GAAP}>Taxable Income_{TaxCode}\t$\n\nBalance sheet equation for cash paid in tax vs tax liability and income tax expense:\n\\begin{tabular}{ |c||c|c| } \n\t\\hline\n\t  Assets = & Liab +  & S/E\t \\\\ \n\t\\hline\n\t  CashTax & DefTaxLiab  & InTaxExp\t \\\\ \n   \t\n\t\\hline\n\\end{tabular}\n\nIf a company has a net deferred tax liability on its balance sheet, cash taxes in the future will be higher than future tax expense.\n \n\\subsection*{ Deferred Tax Assets - DTA}\n \nDeferred tax assets increase when a timing difference leads to: \\\\\n $PretaxIncome_{GAAP}<Taxable Income_{TaxCode}\t$ \\\\\nmore tax cash early, less cash taxes later.  $DefTaxAsset$ is similar to prepaid expense:\n \n\\begin{tabular}{ |c||c|c| } \n\t\\hline\n\tAssets = & Liab +  & S/E\t \\\\ \n\t\\hline\n\tCashTax  DefTaxAsset &  & InTaxExp\t \\\\ \n\t\n\t\\hline\n\\end{tabular}   \n\n\\subsection*{ Tax Disclosures}\n\nWhen the tax rate falls, the  DTA (or DTL) shrinks. When a company has net DTL, we can think of this shrinking DTL as a one-time tax benefit which will reduce tax expense.\n\nThe DTL will shrink by the ratio of the rates:  $\\frac{tax_{new}}{tax_{old}}$ \\\\\n\n$ DTL_{new} = DTL _{old} \\frac{tax_{new}}{tax_{old}} $ \\\\\n\n$ \\Delta DTL = DTL_{new} - DTL_{old} = (\\frac{tax_{new}}{tax_{old}}-1)DTL_{old}$\n\n \n\\begin{tabular}{ |c||c|c| } \n\t\\hline\n\tAssets = & Liab +  & S/E\t \\\\ \n\t\\hline\n\t& $\\Delta DTL$ &   $-\\Delta DTL$\t \\\\ \n\t\n\t\\hline\n\\end{tabular}   \n\nSimilarly when a company has a net DTA: \\\\\n\n$ \\Delta DTA = DTA_{new} - DTA_{old} = (\\frac{tax_{new}}{tax_{old}}-1)DTA_{old}$\n\n\n\\begin{tabular}{ |c||c|c| } \n\t\\hline\n\tAssets = & Liab +  & S/E\t \\\\ \n\t\\hline\n\t $\\Delta DTA$ &  & $\\Delta DTA$\t \\\\ \n\t\n\t\\hline\n\\end{tabular} \n\n\\subsection*{ Effective Tax Rate}\n\n$EffectiveTaxRate = \\frac{TaxExpense}{GAAPpretaxIncome}$  \\\\\n$ pretaxIncome = NetIncome + TaxExpense $ \\\\\n$EffectiveTaxRate = \\frac{TaxExpense}{TaxExpense+NetIncome}$  \n\n\\subsection*{DTAs and Valuation Allowance}\n\nDeferred tax assets arise when future taxes payable will be less than future tax expense. DTAs are like “pre-paid” assets.\nFirms reduce deferred tax assets by creating a valuation allowance, a contra-asset that is\nsimilar to the allowance for doubtful accounts.\\\\\n\n\nExample: In 2015, a firm has a \\$30,000 deferred tax asset.\nSuppose instead, at end of 2016, management expects that it will not have enough future income\nto use the DTA:\n\\begin{tabular}{ |c|c||c|c| } \n\t\\hline\n\tAsset &-ContraAsset = & Liab +  & S/E\t \\\\ \n\t\\hline\n\t& $30000$ &  & $-30000$\t \\\\ \t\n\t\\hline\n\\end{tabular} ", "meta": {"hexsha": "1a44c366e16e3db26d71e5ad28145bc17c71af79", "size": 3929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.516x/assets/week_06.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.516x/assets/week_06.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.516x/assets/week_06.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": 27.4755244755, "max_line_length": 171, "alphanum_fraction": 0.680071265, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028205, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.6682090112083868}}
{"text": "% !TeX program = lualatex\n\\documentclass[]{article}\n\n\\usepackage{caption,subcaption,graphicx,float,url,amsmath,amssymb,amsthm,tocloft,cancel,thmtools,gensymb,braket,tikz-feynman,mathtools,color, colortbl}\n\\usepackage[toc,nonumberlist]{glossaries}\n\\usepackage{glossaries-extra}\n\\usepackage[toc,page]{appendix}\n\n\\newcommand\\numberthis{\\addtocounter{equation}{1}\\tag{\\theequation}}\n\\renewcommand{\\thesection}{1.\\arabic{section}}\n\\newtheorem{thm}{Theorem}\n\\newtheorem{defn}[thm]{Definition}\n\\newtheorem{cor}[thm]{Corollary}\n\\newtheorem{lemma}[thm]{Lemma}\n\\graphicspath{{figs/}}\n\\widowpenalty10000\n\\clubpenalty10000\n\\setcounter{tocdepth}{2}\n\\tikzfeynmanset{compat=1.1.0}\n\\definecolor{Gray}{gray}{0.5}\n\\DeclareMathOperator{\\Tr}{Tr \\;}\n\\newcommand{\\Lagr}{\\mathcal{L}}\n\\setlength{\\cftsubsecindent}{0em}\n\\setlength{\\cftsecnumwidth}{3em}\n\\setlength{\\cftsubsecnumwidth}{3em}\n\n%opening\n\\title{Quantum Field Theory\\\\\nPart I: Motivation and Foundation}\n\\author{Simon Crase (compiler)\\\\simon@greenweaves.nz}\n\n\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n\nThis document contains derivations of equations from \\cite[Part I: Motivation and Foundation]{zee2010quantum}.\n\n\\end{abstract}\n\n\\tableofcontents\n\n\n\\section{Path Integral Formulation}\n\n\\begin{thm}[Some useful integrals]\n\t\\begin{align*}\n\t\t\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}x^2} =& \\sqrt{2\\pi} \\numberthis \\label{eq:integral:gaussian0}\\\\\n\t\t\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} =& \\bigg(\\frac{2\\pi}{a}\\bigg)^\\frac{1}{2} \\numberthis \\label{eq:integral:gaussian}\\\\\n\t\t\\int_{-\\infty}^{\\infty} dx\\,e^{-\\frac{a}{2} x^2+Jx}=&\\bigg(\\frac{2\\pi}{a}\\bigg)^\\frac{1}{2}e^\\frac{J^2}{2a} \\numberthis \\label{eq:integral:gaussian1}\\\\\n\t\t\\int_{-\\infty}^{\\infty} dx\\,e^{-\\frac{a}{2} x^2+iJx}=&\\bigg(\\frac{2\\pi}{a}\\bigg)^\\frac{1}{2}e^{-\\frac{J^2}{2a}} \\numberthis \\label{eq:integral:gaussian2}\n\t\\end{align*}\n\\end{thm}\n\n\\begin{proof}\n\t\\begin{align*}\n\t\t\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}x^2}\\big)\\big(\\int_{-\\infty}^{\\infty} dy e^{-\\frac{1}{2}y^2}\\big) =& \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} dx dy e^{-\\frac{1}{2}(x^2+y^2)} \\\\\n\t\t=& \\int_{0}^{2\\pi} d\\theta \\int_{0}^{\\infty}dr\\;r\\;e^\\frac{-r^2}{2} \\text{, substituting $x=r\\cos{\\theta}$,$y=r\\sin{\\theta}$}\\\\\n\t\t=&- 2\\pi \\int_{0}^{\\infty}du e^{-u}\\;\\text{, substituting $u=\\frac{-r^2}{2}$}\\\\\n\t\t=&- 2\\pi e^{-u}\\bigg\\vert_0^\\infty\\\\\n\t\t=& 2\\pi\n\t\\end{align*}\n\tTaking square roots of both side, we get \\eqref{eq:integral:gaussian0}.\n\t\\begin{align*}\n\t\t\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} =&\\frac{1}{\\sqrt{a}} \\int_{-\\infty}^{\\infty} dx^\\prime e^{-\\frac{1}{2}{x^\\prime}^2} \\text{, substituting $x^\\prime = \\sqrt{a}x$} \\\\\n\t\t=& \\bigg(\\frac{2\\pi}{a}\\bigg)^\\frac{1}{2} \\text{, from \\eqref{eq:integral:gaussian0}, \twhich gives \\eqref{eq:integral:gaussian}}\n\t\\end{align*}\n\n\t\\begin{align*}\n\t\t\\int_{-\\infty}^{\\infty} dx\\,e^{-\\frac{a}{2} x^2+Jx}=&\\int_{-\\infty}^{\\infty} dx\\,e^{-\\frac{a}{2} \\big[x^2-2 \\big(\\frac{J}{a}\\big)x+\\big(\\frac{J}{a}\\big)^2\\big]} e^{\\frac{a}{2}\\big(\\frac{J}{a}\\big)^2}\\text{, completing the square}\\\\\n\t\t=&e^\\frac{J^2}{2a}\\int_{-\\infty}^{\\infty} dx e^{-\\frac{a}{2} \\big[x-\\frac{J}{a}\\big]^2} \\text{, now substitute $x^\\prime=x-\\frac{J}{a}$}\\\\\n\t\t=&e^\\frac{J^2}{2a}\\int_{-\\infty}^{\\infty} dx^\\prime e^{-\\frac{a}{2} {x^\\prime}^2}\n\t\\end{align*}\n\tSubstituting \\eqref{eq:integral:gaussian} gives \\eqref{eq:integral:gaussian1}. Replacing $J$ by $iJ$ gives \\eqref{eq:integral:gaussian2}.\n\\end{proof}\n\n\n\n\\begin{thm}[Feynman Path Integral--Exercise I.2.1 - eq(5)]\n\tIf the Hamiltonian is given by\n\t\\begin{align*}\n\t\tH =& \\frac{\\hat{p}^2}{2m} + V(\\hat{q}) \\text{, and the corresponding Lagrangian is} \\numberthis \\label{eq:H} \\\\\n\t\tL =& \\frac{\\hat{p}^2}{2m} - V(\\hat{q}) \\text{, then} \\numberthis \\label{eq:L}\\\\\n\t\t\\braket{q_F\\vert H\\vert q_I} =& \\int Dq(t) e^{i \\int_{0}^{T}dt L} \\text{, where}\\numberthis \\label{eq:Path:itegral}\\\\\t\n\t\t\\int Dq(t)\\triangleq& \\lim_{N\\rightarrow\\infty} \\big(\\frac{-i m}{2\\pi \\delta t}\\big)^\\frac{N}{2} \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big) \\numberthis \\label{eq:D}\n\t\\end{align*}\n\\end{thm}\n\\begin{proof}\n\tFor some N, define $\\delta t =T/N$ and $q_j= q(j \\delta t)$.\n\t\n\t\\begin{align*}\n\t\t\\braket{q_F\\vert H\\vert q_I} =& \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big)\\prod_{i=0}^{N-1} \\braket{q_{j+1} \\vert e^{-iHT} \\vert q_j}\\\\\n\t\t=& \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big)\\prod_{i=0}^{N-1} \\braket{q_{j+1} \\vert e^{-i\\big(\\frac{\\hat{p}^2}{2m} + V(\\hat{q})\\big)\\delta t} \\vert q_j} \\text{, from \\eqref{eq:H}}\\\\\n\t\t=& \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big)\\prod_{i=0}^{N-1} \\braket{q_{j+1} \\vert e^{-i\\frac{\\hat{p}^2}{2m} \\delta t} e^{-i V(\\hat{q}) \\delta t} \\vert q_j} \\text{, we'll expand in eigenvectors of $\\hat{q}$}\\\\\n\t\t=& \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big)\\prod_{i=0}^{N-1} \\int dq \\braket{q_{j+1} \\vert e^{-i\\frac{\\hat{p}^2}{2m} \\delta t}\\vert q} \\braket{q\\vert e^{-i V(\\hat{q}) \\delta t} \\vert q_j} \\text{, since $\\ket{q}\\bra{q}=I$} \\numberthis \\label{eq:qHq}\n\t\\end{align*}\n\t We will evaluate the integrand in two steps, starting with the potential energy.\n\t\\begin{align*}\n\t\t\\braket{q\\vert e^{-i V(\\hat{q}) \\delta t} \\vert q_j} =& \\braket{ e^{i V(\\hat{q}) \\delta t} q \\vert q_j}\\\\\n\t\t=& \\braket{ e^{i V(q) \\delta t} q \\vert q_j} \\text{, since $\\ket{q}$ is an eigenvector, with eigenvalue $q$}\\\\\n\t\t=& \\braket{ e^{i V(q) \\delta t} q \\vert q_j} \\\\\n\t\t=& e^{-i V(q) \\delta t} \\braket{ q \\vert q_j}  \\numberthis \\label{eq:qVq}\n\t\\end{align*}\n\tNow for the kinetic energy.\n\t\\begin{align*}\n\t\t\\braket{q_{j+1} \\vert e^{-i\\frac{\\hat{p}^2}{2m} \\delta t}  \\vert q}=& \\int \\frac{dp}{2\\pi}\\braket{q_{j+1} \\vert e^{-i\\frac{\\hat{p}^2}{2m} \\delta t}  \\vert p} \\braket{p\\vert q}\\\\\n\t\t=& \\int \\frac{dp}{2\\pi} e^{-i\\frac{p^2}{2m} \\delta t} \\braket{q_{j+1} \\vert p} \\braket{p\\vert q} \\text{, since $\\ket{p}$ is an eigenvector of $\\hat{p}$}\\\\\n\t\t=& \\int \\frac{dp}{2\\pi} e^{-i\\frac{p^2}{2m} \\delta t} e^{ip q_{j+1}} e^{-ip q} \n\t\\end{align*}\n\tUsing \\eqref{eq:integral:gaussian2} with $a=\\frac{i \\delta t}{m}$ and $J=q_{j+1}-q$:\n\t\\begin{align*}\n\t\\braket{q_{j+1} \\vert e^{-i\\frac{\\hat{p}^2}{2m} \\delta t}  \\vert q}=& \\int \\frac{dp}{2\\pi} e^{\\frac{-i \\delta t}{2m}p^2} e^{ip [q_{j+1}-q]} \\\\\n\t=& \\frac{1}{2\\pi} \\big(\\frac{2\\pi m}{i \\delta t}\\big)^\\frac{1}{2} e^{-\\frac{m (q_{j+1}-q)^2}{2 i \\delta t}}\\\\\n\t=& \\big(\\frac{-i m}{2\\pi \\delta t}\\big)^\\frac{1}{2} e^{i \\delta t \\frac{m (q_{j+1}-q)^2}{2  {\\delta t}^2}}  \\numberthis \\label{eq:qP2q}\n\t\\end{align*}\n\tSubstituting \\eqref{eq:qVq} and \\eqref{eq:qP2q} in \\eqref{eq:qHq}: \n\t\\begin{align*}\n\t\t\\braket{q_F\\vert H\\vert q_I} =& \\big(\\frac{-i m}{2\\pi \\delta t}\\big)^\\frac{N}{2} \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big) \\prod_{i=0}^{N-1} \\big(\\frac{-i m}{2\\pi \\delta t}\\big)^\\frac{1}{2} \\int dq e^{i \\delta t \\frac{m (q_{j+1}-q)^2}{2  {\\delta t}^2}} e^{-i V(q) \\delta t} \\underbrace{\\braket{ q \\vert q_j}}_\\text{$=m^2$}\\delta(q-q_j) \\\\\n\t\t=& \\big(\\frac{-i m}{2\\pi \\delta t}\\big)^\\frac{N}{2} \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big) \\prod_{j=0}^{N-1}  e^{i \\delta t \\bigg[\\frac{m (q_{j+1}-q_j)^2}{2  {\\delta t}^2} - V(q_j)\\bigg]}\\\\\n\t\t=& \\big(\\frac{-i m}{2\\pi \\delta t}\\big)^\\frac{N}{2} \\big(\\prod_{j=1}^{N-1} \\int dq_j\\big)  e^{i  \\sum_{i=0}^{N-1} \\delta t \\bigg[\\frac{m (q_{j+1}-q_j)^2}{2  {\\delta t}^2} - V(q_j)\\bigg]} \\numberthis \\label{eq:big:feynman:sum}\n\t\\end{align*}\n\tNow, as $N\\rightarrow\\infty$\n\t\\begin{align*}\n\t\\sum_{i=0}^{N-1} \\delta t \\rightarrow &\\int dt\\\\\n\t\\frac{m (q_{j+1}-q_j)^2}{2  {\\delta t}^2} \\rightarrow & \\frac{m \\dot{q}}{2} \\text{, so, substituting \\eqref{eq:L} and \\eqref{eq:D}, \\eqref{eq:big:feynman:sum} becomes}\\\\\n\t\\braket{q_F\\vert H\\vert q_I} \\rightarrow& \\int Dq(t) e^{i \\int_{0}^{T}dt L} \\text{i.e. \\eqref{eq:Path:itegral}}\n\t\\end{align*}\n\\end{proof}\n\n\n\n\n\\begin{thm}\n\t\\begin{align*}\n\t\t\\frac{\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}x^{2n}}{\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}} =&\\frac{\\prod_{k=1}^{n}\\big(2k-1\\big)}{a^n}\n\t\\end{align*}\n\\end{thm}\n\n\\begin{proof}\n\tThe proof by mathematical induction starts by defining the proposition $P(n)$:\n\t\\begin{align*}\n\t\tP(n) \\equiv& \\bigg[\\frac{\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}x^{2n}}{\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}}=\\frac{\\prod_{k=1}^{n}\\big(2k-1\\big)}{a^n}\\bigg]\n\t\\end{align*}\n\t\\begin{lemma}\\label{thm:P_0}\n\t\tP(0) is true.\n\t\\end{lemma}\n\t\\begin{proof}\n\t\t$P(0)$ reduces to $\\frac{\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}}{\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}}=1$\n\t\\end{proof}\n    \\begin{lemma}\\label{lemma:uniform:convergence}\n    \t\\begin{align*}\n    \t\t\\forall \\alpha >0 \\text{, }\\frac{d}{d\\alpha}\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}\\alpha x^2}x^{2n} =&\\int_{-\\infty}^\\infty dx \\frac{\\partial}{\\partial \\alpha} \\big[e^{-\\frac{1}{2}\\alpha x^2}x^{2n}\\big]\n    \t\\end{align*}\n    \\end{lemma}\n\t\\begin{proof}\n\t\t\\begin{align*}\n\t\t\t\\forall a>0, \\forall \\alpha_0 \\in (0,\\alpha)\\; \\int_{a}^\\infty dx e^{-\\frac{1}{2}\\alpha x^2}x^{2n} =&\\int_{a}^\\infty dx e^{-\\frac{1}{2}\\alpha_0 x^2} e^{-\\frac{1}{2}(\\alpha-\\alpha_0) x^2}x^{2n} \\\\\n\t\t\t\\text{Now define}\\; M(x) =& e^{-\\frac{1}{2}\\alpha_0 x^2}\n\t\t\\end{align*}\n\t\tWe can choose $a$ large enough that $e^{-\\frac{1}{2}(\\alpha-\\alpha_0) x^2}x^{2n}$ is monotone decreasing for $x>a$. Clearly\n\t\t\\begin{align*}\n\t\t\te^{-\\frac{1}{2}\\alpha_0 x^2} e^{-\\frac{1}{2}(\\alpha-\\alpha_0) x^2}x^{2n} \\in C\\\\\n\t\t\t\te^{-\\frac{1}{2}\\alpha_0 x^2} \\in C\\\\\n\t\t\te^{-\\frac{1}{2}\\alpha_0 x^2} e^{-\\frac{1}{2}(\\alpha-\\alpha_0) x^2}x^{2n}<&M(x)\\; \\forall x>a \\text{ and}\\\\\n\t\t\t\\int_{a}^\\infty dx M(x)<&\\infty\n\t\t\\end{align*}\n\t\t for $\\alpha$ in closed interval [A,B] that includes $\\alpha_0$; the Weierstrass M-Test \\cite[Chapter 10, 6.1]{widder1961advanced} shows that the integral converges uniformly for $\\alpha\\in[A,B]$. Hence we can differentiate under the integral sign \\cite[Chapter 10, 8.3]{widder1961advanced}.\n\t\tNow\n\t\t\\begin{align*}\n\t\t\t\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}\\alpha x^2}x^{2n} =& 2 \\int_{a}^\\infty dx e^{-\\frac{1}{2}\\alpha x^2}x^{2n} + \\int_{-a}^a dx e^{-\\frac{1}{2}\\alpha x^2}x^{2n}\n\t\t\\end{align*}\n\tNoting that $e^{-\\frac{1}{2}\\alpha x^2}x^{2n} \\in C^1$ for x in [-a,a], we can also differentiate the second integral.\n\t\\end{proof}\n\n\t\\begin{lemma}\\label{thm:P_1}\n\t\t$P(0) \\implies P(1)$\n\t\\end{lemma}\n\t\\begin{proof}\n\t\tSince (\\ref{eq:integral:gaussian}) converges uniformly, Lemma \\ref{lemma:uniform:convergence} allows us to differentiate under the integral sign\\cite{widder1961advanced}.\n\t\t\\begin{align*}\n\t\t\t-2\\frac{d}{da}\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} =& -2\\frac{d}{da} \\bigg(\\frac{2\\pi}{a}\\bigg)^\\frac{1}{2}\\\\\n\t\t\t\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} x^2 =& \\bigg(\\frac{2\\pi}{a^3}\\bigg)^\\frac{1}{2}\\\\\n\t\t\t=& \\bigg(\\frac{2\\pi}{a}\\bigg)^\\frac{1}{2} \\frac{1}{a}\\\\\n\t\t\t=& \\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} \\frac{1}{a}\n\t\t\\end{align*}\n\t\\end{proof}\n\t\\begin{lemma}\\label{thm:P_n}\n\t\t$P(n) \\land P(1)\\implies P(n+1)$\n\t\\end{lemma}\n\t\\begin{proof}\n\t\t\\begin{align*}\n\t\tP(n) \\implies &\\\\\n\t\t\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}x^{2n}=&\\prod_{k=1}^{n}\\big(2k-1\\big)\t\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2} \\frac{1}{a^n}\\\\\n\t\t-2\\frac{d}{da}\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}x^{2n}=&-2 \\prod_{k=1}^{n}\\big(2k-1\\big)\\frac{d}{da} \\big[\t\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2} \\frac{1}{a^n}\\big]\\\\\n\t\t\\int_{-\\infty}^\\infty dx e^{-\\frac{1}{2}ax^2}x^{2(n+1)}=&-2 \\prod_{k=1}^{n}\\big(2k-1\\big)\\bigg[\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} (-\\frac{1}{2}x^2)\\frac{1}{a^n}-\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2}\\frac{n}{a^{n+1}}\\bigg] \\\\\n\t\t=&\\prod_{k=1}^{n}\\big(2k-1\\big)\\bigg[\\underbrace{\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2}x^2}_\\text{Now we apply $P(1)$} \\frac{1}{a^n}+2\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2}\\frac{n}{a^{n+1}}\\bigg]\\\\\n\t\t=&\\prod_{k=1}^{n}\\big(2k-1\\big)\\bigg[ \\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2}\\frac{1}{a} \\frac{1}{a^n} + \\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2} \\frac{2n}{a^{n+1}}\\bigg]\\\\\n\t\t=&\\prod_{k=1}^{n}\\big(2k-1\\big) \\frac{2n+1}{a^{n+1}}\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2}\\\\\n\t\t=&\\prod_{k=1}^{n+1}\\big(2k-1\\big) \\frac{1}{a^{n+1}}\\int_{-\\infty}^{\\infty} dx e^{-\\frac{1}{2}ax^2}\\\\\n\t\t\\equiv& P(n+1)\n\t\t\\end{align*}\n\t\\end{proof}\n\tSummarizing:\n\t\\begin{align*}\n\t\t\\text{Lemma }\\ref{thm:P_0} \\implies& P(0)\\\\\n\t\tP(0) \\land \\text{Lemma } \\ref{thm:P_1} \\implies& P(1)\\\\\n\t\tP(0) \\land P(1)\\land P(n) \\land \\text{Lemma } \\ref{thm:P_n} \\implies& P(n+1)\n\t\\end{align*}\n\\end{proof}\n\n\\begin{thm}\n\tIf $A$ is a symmetric matrix\n\t\\begin{align*}\n\t\t\\int_{-\\infty}^{\\infty}dx_1 dx_2...dx_N e^{-\\frac{1}{2}\\vec{x}A\\vec{x} + \\vec{J} \\cdot \\vec{x}} =& \\bigg(\\frac{(2\\pi)^N}{\\vert A \\vert}\\bigg)^\\frac{1}{2} e^{\\frac{1}{2}\\vec{J}\\cdot A^{-1} \\vec{J}} \\numberthis \\label {eq:Zee_I_2_22}\n\t\\end{align*}\n\\end{thm}\n\\begin{proof}\n\tSince $A$ is symmetric, there exists an orthogonal matrix $O$ such that $A=O^T D O$, where $D$ is a diagonal matrix--\\cite{bellman1970introduction}. Define\n\t\\begin{align*}\n\t\ty_i =& \\sum_j O_{ij}x_j\\\\\n\t\t\\int_{-\\infty}^{\\infty}dx_1 dx_2...dx_N e^{-\\frac{1}{2}\\vec{x}A\\vec{x} + \\vec{J} \\cdot \\vec{x}}=&\\bigg(\\frac{1}{\\vert O \\vert}\\bigg)^N \\int_{-\\infty}^{\\infty}dy_1 dy_2...dy_Ne^{-\\frac{1}{2}\\vec{x}O^T D O\\vec{x} + \\vec{J} \\cdot \\vec{x}}\\\\\n\t\t=& \\int_{-\\infty}^{\\infty}dy_1 dy_2...dy_N e^{-\\frac{1}{2}(\\vec{x}O^T) D (O\\vec{x}) + \\vec{J} \\cdot \\vec{x}}\\\\\n\t\t=& \\int_{-\\infty}^{\\infty}dy_1 dy_2...dy_N e^{- \\frac{1}{2} \\vec{y}D \\vec{y} + (O\\vec{J})\\cdot \\vec{y}}\\\\\n\t\t=& \\prod_{i=1}^N \\int_{-\\infty}^{\\infty}dy_i e^{- \\frac{1}{2} D_{ii}y_i^2 + (OJ)_i y_i}\\\\\n\t\t=& \\prod_{i=1}^N \\bigg[\\bigg(\\frac{2\\pi}{D_{ii}}\\bigg)^\\frac{1}{2} e^{\\big(\\frac{[(OJ)_i]^2}{2D_{ii}}\\big)}\\bigg] \\numberthis \\label {eq:Zee_I_2_22_a}\n\t\\end{align*}\n\tBut\n\t\\begin{align*}\n\t\t\\prod_{i=1}^N \\bigg(\\frac{2\\pi}{D_{ii}}\\bigg) =& \\frac{({2\\pi})^N}{\\vert D \\vert}\\\\\n\t\t=& \\frac{({2\\pi})^N}{\\vert A \\vert} \\text{, since $O$ is orthogonal} \\numberthis \\label {eq:Zee_I_2_22_b}\n\t\\end{align*}\n\tAnd\n\t\\begin{align*}\n\t\t\\prod_{i=1}^N e^{\\big(\\frac{[(OJ)_i]^2}{2D_{ii}}\\big)} =& e^{\\sum_{i=1}^N {\\big(\\frac{[(OJ)_i]^2}{2D_{ii}}\\big)}}\\\\\n\t\t\\sum_{i=1}^N {\\big(\\frac{[(OJ)_i]^2}{2D_{ii}}\\big)} =& \\frac{1}{2} \\sum_{i=1}^N (OJ)_i (D^{-1})_{ii} (OJ)_i\\\\\n\t\t =& \\frac{1}{2} \\sum_{i,j,k,l=1}^N O_{ik} J_k (D^{-1})_{ij} O_{jl} J_l\\\\\n\t\t =& \\frac{1}{2} \\sum_{i,j,k,l=1}^N J_k O^T_{ki}  (D^{-1})_{ij} O_{jl} J_l \\\\\n\t\t =& \\frac{1}{2} \\sum_{k,l=1}^N J_k \\bigg(\\sum_{k,l=1}^N O^T_{ki}  (D^{-1})_{ij} O_{jl}\\bigg) J_l\\\\\n\t\t  \\\\\n\t\t =& \\frac{1}{2} \\sum_{k,l=1}^N J_k \\big(A^{-1}\\big)_{kl} J_l \\\\\n\t\t =& \\frac{1}{2} J A^{-1} J \\numberthis \\label {eq:Zee_I_2_22_c}\n\t\\end{align*}\n\tSubstituting (\\ref{eq:Zee_I_2_22_b}) and (\\ref{eq:Zee_I_2_22_c}) in (\\ref{eq:Zee_I_2_22_a}), we obtain (\\ref{eq:Zee_I_2_22}).\n\\end{proof}\n\n\\section{From Field to Particle to Force}\n\\begin{align*}\n\tW(J) =& - \\frac{1}{2} \\int \\int d^4x d^4y J(x) D(x-y) J(y)\\\\\n\tD(x-y) =& \\int \\frac{d^4k}{(2\\pi)^4} \\frac{e^{ik(x-y)}}{k^2-m^2+i\\epsilon}\\\\\n\tJ(x) =& J_1(x) + J_2(x) \\text{, where}\\\\\n\tJ_{a}(x) =&\\delta^{(3)}(\\vec{x}-\\vec{x_a}) \n\\end{align*}\nConsidering only the cross terms\n\\begin{align*}\n\tW(J) =& - \\int \\frac{1}{(2\\pi)^4} \\cancel{2} \\cancel{\\frac{1}{2}} \\int \\int d^4x d^4y d^4k \\delta^{(3)}(\\vec{x}-\\vec{x_1})   \\frac{e^{ik(x-y)}}{k^2-m^2+i\\epsilon} \\delta^{(3)}(\\vec{y}-\\vec{x_2}))\\\\\n\t=& - \\frac{1}{(2\\pi)^4} \\int \\int \\int \\int \\int \\int dx^0 d\\vec{x} dy^0 d\\vec{y} dk^0 d\\vec{k}  \\delta^{(3)}(\\vec{x}-\\vec{x_1})   \\frac{e^{ik^0(x^0-y^0)-i\\vec{k} \\cdot (\\vec{x}-\\vec{y})}}{k^2-m^2+i\\epsilon} \\delta^{(3)}(\\vec{y}-\\vec{x_2}))\\\\\n\t=& - \\frac{1}{(2\\pi)^4} \\int \\int \\int \\int \\int dx^0 d\\vec{x} dy^0 dk^0 d\\vec{k}  \\delta^{(3)}(\\vec{x}-\\vec{x_1})   \\frac{e^{ik^0(x^0-y^0)-i\\vec{k} \\cdot (\\vec{x}-\\vec{x_2})}}{k^2-m^2+i\\epsilon} \\\\\n\t=& - \\frac{1}{(2\\pi)^4} \\int \\int \\int \\int dx^0  dy^0 dk^0 d\\vec{k} \\;    \\frac{e^{ik^0(x^0-y^0)-i\\vec{k} \\cdot (\\vec{x_1}-\\vec{x_2})}}{k^2-m^2+i\\epsilon}\\\\\n\t=& - \\frac{1}{(2\\pi)^3} \\int \\int dx^0  dy^0 \\underbrace{\\int \\frac{dk^0}{2\\pi} e^{ik^0(x^0-y^0)}}_\\text{$\\delta(x^0-y^0)$} \\int d\\vec{k} \\; \\frac{e^{i\\vec{k} \\cdot (\\vec{x}-\\vec{y})}}{k^2-m^2+i\\epsilon}\\\\\n\t=& - \\frac{1}{(2\\pi)^3} \\int  dx^0  \\int d\\vec{k} \\; \\frac{e^{i\\vec{k} \\cdot (\\vec{x}-\\vec{y})}}{k^2-m^2+i\\epsilon}\n\\end{align*}\n\n\\section{Coulomb and Newton}\nThe Lagrangian Density is given by:\n\\begin{align*}\n\t\\Lagr =& -\\frac{1}{4} F_{\\mu\\nu}F^{\\mu\\nu} + \\frac{1}{2}m^2 A_{\\mu}A^{\\mu} + A_{\\mu}J^{\\mu} \\text{, where}\\\\\n\tF_{\\mu\\nu} =& \\partial_{\\mu} A_{\\nu} - \\partial_{\\nu} A_{\\mu} \\text{ and}\\\\\n\t\\partial_{\\mu}J^{\\nu}=& 0 \\text{. We define the action} \\numberthis \\label{eq:EM_continuity}\\\\\n\tS(A) =&\\int d^4 \\Lagr\\\\\n\t=&  \\int d^4x \\bigg[-\\frac{1}{4} F_{\\mu\\nu}F^{\\mu\\nu} + \\frac{1}{2}m^2 A_{\\mu}A^{\\mu} + A_{\\mu}J^{\\mu} \\bigg]\n\\end{align*}\nExpanding the first term in the Lagrangian\n\\begin{align*}\n\tF_{\\mu\\nu}F^{\\mu\\nu}=& g^{\\mu\\rho} g^{\\nu\\sigma}F_{\\mu\\nu}F_{\\rho\\sigma}\\\\\n\t=& g^{\\mu\\rho} g^{\\nu\\sigma} \\big(\\partial_{\\mu} A_{\\nu} - \\partial_{\\nu} A_{\\mu}\\big)\\big(\\partial_{\\rho} A_{\\sigma} - \\partial_{\\sigma} A_{\\rho}\\big)\\\\\n\t=& g^{\\mu\\rho} g^{\\nu\\sigma}\\big[\\partial_{\\mu} A_{\\nu}\\partial_{\\rho} A_{\\sigma} -\\partial_{\\mu} A_{\\nu}\\partial_{\\sigma} A_{\\rho} -\\partial_{\\nu} A_{\\mu}\\partial_{\\rho} A_{\\sigma} + \\partial_{\\nu} A_{\\mu}\\partial_{\\sigma} A_{\\rho}\\big]\\\\\n\t=& g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\rho} A_{\\sigma} -g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\sigma} A_{\\rho} -\\underbrace{g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\nu} A_{\\mu}\\partial_{\\rho} A_{\\sigma}}_\\text{substitute: $\\mu\\nu\\rho\\sigma\\rightarrow\\nu\\mu\\sigma\\rho$} +\\underbrace{g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\nu} A_{\\mu}\\partial_{\\sigma} A_{\\rho}}_\\text{$\\mu\\nu\\rho\\sigma\\rightarrow\\nu\\mu\\sigma\\rho$}\t\\\\\n\t=& g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\rho} A_{\\sigma} -g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\sigma} A_{\\rho} - g^{\\nu\\sigma} g^{\\mu\\rho} \\partial_{\\mu} A_{\\nu}\\partial_{\\sigma} A_{\\rho} +g^{\\nu\\sigma} g^{\\mu\\rho} \\partial_{\\mu} A_{\\nu}\\partial_{\\rho} A_{ssigma}\t\\\\\n\t=& 2 \\big[g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\rho} A_{\\sigma} -g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\sigma} A_{\\rho}\\big]\n\\end{align*}\nSo the first term in the action is\n\\begin{align*}\n\t -\\frac{1}{4} \\int d^4x F_{\\mu\\nu}F^{\\mu\\nu} =&  -\\frac{2}{4} \\int d^4x \\big[g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\rho} A_{\\sigma} -g^{\\mu\\rho} g^{\\nu\\sigma} \\partial_{\\mu} A_{\\nu}\\partial_{\\sigma} A_{\\rho}\\big] \\text{. Integrating by parts gives}\\\\\n\t =& \\frac{1}{2} \\int d^4x \\big[g^{\\mu\\rho} g^{\\nu\\sigma}  A_{\\nu}\\partial_{\\mu}\\partial_{\\rho} A_{\\sigma} -g^{\\mu\\rho} g^{\\nu\\sigma}  A_{\\nu}\\partial_{\\mu} \\partial_{\\sigma} A_{\\rho}\\big]\\\\\n\t =& \\frac{1}{2} \\int d^4x \\big[ g^{\\nu\\sigma}  A_{\\nu}\\partial^2 A_{\\sigma} -  A_{\\nu}\\partial^{\\rho} \\partial^{\\nu} A_{\\rho}\\big]\\\\\n\t =& \\frac{1}{2} \\int d^4x A_{\\nu} \\big[ g^{\\nu\\sigma}  \\partial^2  -  \\partial^{\\sigma} \\partial^{\\nu} \\big] A_{\\sigma}\n\\end{align*}\n\nSo the action becomes\n\\begin{align*}\n\t\\int d^4 \\Lagr=&  \\int d^4x \\bigg[\\frac{1}{2} A_{\\nu} \\big[ g^{\\nu\\sigma}  \\partial^2  -  \\partial^{\\sigma} \\partial^{\\nu} \\big] A_{\\sigma} + \\frac{1}{2}m^2 A_{\\mu}A^{\\mu} + A_{\\mu}J^{\\mu} \\bigg]\\\\\n\t=&\\int d^4x \\bigg[\\frac{1}{2} A_{\\nu} \\big[ g^{\\nu\\sigma}  (\\partial^2 +m^2)  -  \\partial^{\\sigma} \\partial^{\\nu} \\big] A_{\\sigma} +  A_{\\mu}J^{\\mu} \\bigg]\n\\end{align*}\n\n\\begin{align*}\n\tD_{\\mu\\nu} \\big(D^{-1}\\big)^{\\nu\\lambda} =& \\delta_{\\mu}^{\\lambda}\n\\end{align*}\nFrom Lecture. How do we get a repulsive force? This is tied up with spin. If we want particles fro field to have spin 1, we need a vector--$A_{\\mu}$. We need to reduce $A_{\\mu}$ to 3 degrees of freedom (polarization), and \\eqref{eq:EM_continuity} is the only Lorentz invariant way to do this. We will start with the physics--Figure \\ref{fig:electromagnetic:current}.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\caption{Electromagnetic Field with source and sink}\\label{fig:electromagnetic:current}\n\t\t\\includegraphics[width=0.5\\textwidth]{qft_liecture2_1}\n\t\\end{center}\n\\end{figure}\n\\begin{align*}\n\tJ \\phi \\rightarrow& J_{\\mu} A^{\\mu}\\\\\n\t\\frac{1}{k^2 + m^2} \\rightarrow& \\frac{1}{k^2 + m^2} \\underbrace{\\underbrace{\\sum_{a=1}^{3}}_\\text{3 polarizations} \\epsilon_\\mu^{(a)}(k) \\epsilon_\\nu^{(a)}(k)}_\\text{A Lorentz tensor, $-G_{\\mu\\nu}$ say} \\numberthis \\label{eq:em:propagator}\n\\end{align*}\nWe will evaluate in the rest frame of the particle, where $k=(m,0,0,0)$, and polarization is the 3 directions in Cartesian space.\n\\begin{align*}\n\t\\epsilon_\\mu^{(1)}(k) =& (0,1,0,0)\\\\\n\t\\epsilon_\\mu^{(2)}(k) =& (0,0,1,0)\\\\\n\t\\epsilon_\\mu^{(3)}(k) =& (0,0,0,1)\\\\\n\tk^{\\mu}\\epsilon_\\mu =& 0 \\text{, since $k=(m,0,0,0)$} \\numberthis \\label{eq:k_mu_0}\n\\end{align*}\n\\eqref{eq:k_mu_0} is Lorentz Invariant! c.f. $\\partial_{\\mu}A^{\\mu}=0$. We will establish the tensor $G_{\\mu\\nu}$ in \\eqref{eq:em:propagator} using symmetry and Lorentz invariance. There are only two things to construct $G_{\\mu\\nu}$ from, $k_{\\mu}$ and $g_{\\mu\\nu}$.\n\\begin{align*}\n\t- G_{\\mu\\nu} =& A k_{\\mu} k_{\\nu} + B g_{\\mu\\nu}\\\\\n\t G_{\\mu\\nu} k^{\\mu} =& 0 \\text{ from \\eqref{eq:k_mu_0}, whence}\\\\\n\t \\big(A k_{\\mu} k_{\\nu} + B g_{\\mu\\nu}\\big) k^{\\mu} =& 0\\\\\n\t \\big(A \\underbrace{k^2}_\\text{$=m^2$}+B\\big)k_{\\nu} =& 0\\\\\n\t A =& -\\frac{B}{m^2}\\\\\n\t - G_{\\mu\\nu} =& -\\big(g_{\\mu\\nu}-\\frac{k_{\\mu}k_{\\nu}}{m^2}\\big) \\text{. Normalization fixed by rest frame.}\\\\\n\t \\frac{1}{k^2 + m^2} \\rightarrow& \\frac{-g_{\\mu\\nu}+\\frac{k_{\\mu}k_{\\nu}}{m^2}}{k^2 + m^2}\n\\end{align*}\nImagine two stationary charges: then $J^i=0$\n\\begin{align*}\n\tW(J) =& \\int  \\frac{d^4k}{(2\\pi)4} J^{\\mu}(k)^* \\frac{-g_{\\mu\\nu}+\\frac{k_{\\mu}k_{\\nu}}{m^2}}{k^2 + m^2} J^{\\nu}(k)\\\\\n\t\\partial_{\\mu} J^{\\mu} =& 0 \\text{ implies}\\\\\n\tk_{\\mu} J^{\\mu} =& 0\\\\\n\tW(J) =& \\int  \\frac{d^4k}{(2\\pi)4} J^0(k)^* \\frac{-g_{00}}{k^2 + m^2} J^0(k)\\\\\n\t=& \\int  \\frac{d^4k}{(2\\pi)4} J^0(k)^* \\frac{-1}{k^2 + m^2} J^0(k) \\text{--Like charges repel}\n\\end{align*}\n\nSpin 2 has two indices $h_{\\mu\\nu}$. Two sign switches cancel!\n\nEven spin can exchange lumps, but not odd.\n\n\\begin{thm}\n\t\\begin{align*}\n\t\t\\big(\\delta^2+m^2\\big) A^{\\mu}=&0 \\text{ and} \\numberthis \\label{eq:cn:1}\\\\\n\t\t \\partial_{\\mu} A^{\\mu}=&0 \\text{ are equivalent to } \\numberthis \\label{eq:cn:2}\\\\\n\t\t \\big(g^{\\mu\\nu}\\partial^2-\\partial^\\mu\\partial^\\nu\\big)A_\\nu + m^2 A^\\mu=&0 \\numberthis \\label{eq:cn:3}\n\t\\end{align*}\n\\end{thm}\n\\begin{proof}[Proof: $\\eqref{eq:cn:1} \\land \\eqref{eq:cn:2} \\implies \\eqref{eq:cn:3}$]\n\t From\t\\eqref{eq:cn:2} \n\t\\begin{align*}\n\t\t \\partial^\\nu A_\\nu =& 0 \\text{, whence}\\\\\n\t\t \\partial^\\mu \\partial^\\nu A_\\nu =& 0 \\text{. Now \\eqref{eq:cn:1} can be rearranged} \\numberthis \\label{eq:cn:4}\\\\\n\t\t \\partial^2 \\big(g^{\\mu\\nu}A_\\nu\\big) + m^2 A^\\mu =&0\\\\\n\t\t g^{\\mu\\nu} \\partial^2 A_\\nu + m^2 A^\\mu =&0 \\text{. Now, using \\eqref{eq:cn:4}}\\\\\n\t\t g^{\\mu\\nu} \\partial^2 A_\\nu - \\partial^\\mu \\partial^\\nu A_\\nu + m^2 A^\\mu =&0 \\text{, which rearranges to \\eqref{eq:cn:3}}\n\t\\end{align*}\n\\end{proof}\n\\begin{proof}[$\\eqref{eq:cn:3} \\implies \\eqref{eq:cn:1} \\land \\eqref{eq:cn:2}$]\n\tFrom \\eqref{eq:cn:3}\n\t\\begin{align*}\n\t \tm^2 A^\\mu=&\\big(\\partial^\\mu\\partial^\\nu-g^{\\mu\\nu}\\partial^2\\big)A_\\nu \\\\\n\t \tm^2 \\partial_\\mu A^\\mu =&\\partial_\\mu \\big(\\partial^\\mu\\partial^\\nu-g^{\\mu\\nu}\\partial^2\\big)A_\\nu\\\\\n\t \t=&\\partial_\\mu\\partial^\\mu\\partial^\\nu A_\\nu -  g^{\\mu\\nu}\\partial_\\mu\\partial^2A_\\nu\\\\\n\t \t=&\\partial^2\\partial^\\nu A_\\nu - \\partial^\\nu\\partial^2A_\\nu\\\\\n\t \t=& 0 \\text{, which is \\eqref{eq:cn:2}. Now \\eqref{eq:cn:3} becomes}\\\\\n\t \tg^{\\mu\\nu}\\partial^2 A_\\nu-\\cancel{\\partial^\\mu\\partial^\\nu A_\\nu} + m^2 A^\\mu=&0 \\text{, which is \\eqref{eq:cn:1}}\n\t\\end{align*}\n\\end{proof}\n\n\\section{Feynman Diagrams}\n\n\\begin{align*}\n\tZ(J,\\lambda) =& \\int D\\phi \\; e^{i\\int d^4x\\;\\big[\\frac{1}{2}[(\\partial \\phi)^2-m^2\\phi^2]-\\frac{\\lambda}{4!}\\phi^4+J\\phi\\big]}\\\\\n\t=& \\int D\\phi \\; e^{i\\int d^4x\\;\\big[\\frac{1}{2}[(\\partial \\phi)^2-m^2\\phi^2]+J\\phi\\big]e^{-i\\frac{\\lambda}{4!}\\phi^4}}\n\\end{align*}\n\nThe \\emph{functional derivative} is defined in \\cite{enwiki:1034704989}:\n\\begin{align*}\n\t\\int \\frac{\\delta F(x)}{\\delta \\rho} \\phi(x) dx \\triangleq& \\lim_{\\epsilon \\rightarrow 0} \\frac{F(\\rho + \\epsilon \\phi)-f[\\rho]}{\\epsilon}\\\\\n\t=&\\bigg[\\frac{dF(\\rho+\\epsilon\\phi)}{d\\rho}\\bigg]_\\text{$\\epsilon=0$}\n\\end{align*}\n\n\n\\begin{thm}\n\t\\begin{align*}\n\t\tZ(J,\\lambda) =&\te^{-\\frac{i\\lambda}{4!}\\int dx \\frac{\\delta^4}{(\\delta J)^4}}Z(J,0)\n\t\\end{align*}\n\\end{thm}\n\n\\begin{proof}\n\tAfter \\cite{straub2004feynman}...\t\n\\end{proof}\n\n\n% Endmatter\n\n\\bibliographystyle{unsrt}\n\\addcontentsline{toc}{section}{Bibliography}\n\\raggedright\n\\bibliography{tm}\n\n\\end{document}\n", "meta": {"hexsha": "7fa445ad4b1da35fcac13e5bbb209f4428f434df", "size": 24410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "qft1.tex", "max_stars_repo_name": "weka511/tm", "max_stars_repo_head_hexsha": "091aa09764b70d860cca7926658937363a9e1e83", "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": "qft1.tex", "max_issues_repo_name": "weka511/tm", "max_issues_repo_head_hexsha": "091aa09764b70d860cca7926658937363a9e1e83", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2021-07-15T19:53:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-03T22:54:10.000Z", "max_forks_repo_path": "qft1.tex", "max_forks_repo_name": "weka511/tm", "max_forks_repo_head_hexsha": "091aa09764b70d860cca7926658937363a9e1e83", "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.4207920792, "max_line_length": 453, "alphanum_fraction": 0.5956165506, "num_tokens": 11529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6682090023299148}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{xcolor}\n\\usepackage[T1]{fontenc}\n\\usepackage{pagecolor}\n\\usepackage{amssymb}\n\\usepackage{lmodern}\n\\usepackage{mathtools, nccmath}\n\\usepackage{courier}\n\\usepackage[overload]{empheq}\n\\usepackage[inline, shortlabels]{enumitem}\n\\usepackage{amsmath}\n\\usepackage{mathtools} \n\\color{white}\n\\title{Solution to Number Theory \\# 1}\n\\author{@all.about.mathematics}\n\n\n\\pagecolor{black}\n\\begin{document}\n\\maketitle\n\\section{Problem}\nLet $S\\subset\\mathbb{N}$ such that $|S|=n$. Prove that $\\exists A\\subseteq S$ such that the sum of all elements in $A$ are divisible by $n$.\n\\section{Solution}\nLet $S=\\{a_1,a_2,\\cdots,a_n\\}$. \nThen define the following sums: $$S_1=a_1$$\n$$S_2=a_1+a_2$$\n$$\\vdots$$\n$$S_n=a_1+a_2+\\cdots+a_n$$\n\\subsection{Case 1}\nIf one of the above sums are divisible by $n$, then the claim is proved in this case.\n\\subsection{Case 2}\nIf none of the sums are divisible by $n$, then, by the Pigeonhole Principle, at least 2 of the sums must have the same remainder when divided by $n$. This implies that we can pick 2 sums $S_b$ and $S_c$  with $b>c$ such that \n$$S_b-S_c=a_c+1+\\cdots+a_b\\equiv0(mod\\:n)$$\nTherefore the claim is proved in this case.\n\n\\end{document}", "meta": {"hexsha": "1ed02e21588850b1101b3233e9f595eb46d97ddb", "size": 1236, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Number theory/all.about.mathematics' questions/Number theory 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": "Number theory/all.about.mathematics' questions/Number theory 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": "Number theory/all.about.mathematics' questions/Number theory 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": 33.4054054054, "max_line_length": 225, "alphanum_fraction": 0.7370550162, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.6682089988342178}}
{"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 4: Square Systems}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Plane Equations}\n\nAn equation of the form \n$ax + by + cz = d \\; \\textnormal{(a, b, c, d are constants)}$ defines a plane.\n\n\\begin{example}\n  Find the equation of the plane through the origin with a normal vector \n  $\\vec{N} = <1, 5, 10>$.\n\n  By thinking geometrically, a point $P$ is in the plane $\\iff$ \n  $OP \\perp \\vec{N}$ $\\iff$ $\\vec{OP} \\cdot \\vec{N} = 0$. Therefore, the \n  equation of the described plane is\n  \\[\n    <x, y, z> \\cdot <1, 5, 10> = 0\n  \\]\n  \\[\n    x + 5y + 10z = 0\n  \\]\n\\end{example}\n\n\\begin{example}\n  Find the equation of the plane through the point $P_0$ (2, 1, -1) with a \n  normal vector $\\vec{N} = <1, 5, 10>$.\n\n  Similarly by thinking geometrically, a point $P$ (x, y, z) is in the plane \n  $\\iff$ $\\vec{P_0P} \\perp \\vec{N}$ $\\iff$ $\\vec{P_0P} \\cdot \\vec{N} = 0$. \n  Therefore, the equation of the described plane is \n  \\[\n    <x - 2, y - 1, z + 1> \\cdot <1, 5, 10> = 0\n  \\]\n  \\[\n    (x - 2) + 5(y - 1) + 10(z + 1) = 0\n  \\]\n  \\[\n    x + 5y + 10z = -3\n  \\]\n\\end{example}\n\nFrom the above example we can see that the coefficients of the equation of a \nplane are actually the components of one of its normal vectors.\n\nThe right-hand side constant in the equation of a plane is an indicator of the \ndistance to its parallel plane through the origin. For example, we can derive \nthat $x + 5y + 10z = 3$ and $x + 5y + 10z = -3$ are in the two sides of the \nplane $x + 5y + 10z = 0$ respectively, and $x + 5y + 10z = -1$ has a short \ndistance to $x + 5y + 10z = 0$ than $x + 5y + 10z = -3$.\n\n\\begin{example}\n  The vector $\\vec{v} = <1, 2, -1>$ and the plane $x + y + 3z = 5$ are \\underline{A}.\n\n  A. parallel \\\\\n  B. perpendicular \\\\\n  C. neither\n\n  Reasons: \\\\\n  A normal vector of the plane $x + y + 3z = 5$ is $\\vec{N} = <1, 1, 3>$. Then\n  \\[\n    \\begin{split}\n    \\vec{v} \\cdot \\vec{N} &= <1, 2, -1> \\cdot <1, 1, 3> \\\\\n                          &= 1 + 2 - 3 \\\\\n                          &= 0\n    \\end{split}\n  \\]\n  Hence $\\vec{v} \\perp \\vec{N}$, from which we can derive that $\\vec{v}$ is \n  perpendicular to the plane.\n\\end{example}\n\n\\section{Geometric Interpretation of Linear Systems}\n\n\\subsection{Linear systems in geometry}\n\nA linear system describes the intersection of some objects or point sets in \ngeometry.\n\nTake a $3 \\times 3$ linear system as an example:\n\\[\n  \\left\\{ \\begin{array}{ll}\n  x + z = 1 \\\\\n  x + y = 2 \\\\\n  x + 2y + 3z = 3 \\\\\n  \\end{array} \\right.\n\\]\nThe solution to this linear system is the set of points $(x, y, z)$ satisfying \nall three linear equations, where each of them defines a plane. Therefore, the \npoints in the solution set are in all of three planes. Hence, the solution to \nthe linear system describes the intersection of these three planes in geometry.\n\nTo find the solution to a linear system, algebraic methods are easier than \ngeometric methods. Recall that a linear system can be expressed with matrix \nproducts as:\n\\[\n  AX = B\n\\]\n\\[\n  X = A^{-1}B\n\\]\n$A^{-1}B$ is the unique solution to the linear system, which is the \nintersection point in geometry.\n\n\\subsection{Exceptions of unique solution in geometry}\n\nHowever, there are exceptions to this algebraic method.\n\\begin{example}\n  If the solution set to a $3 \\times 3$ linear system is not a single point, it \n  could be \\underline{A C E}.\n\n  A. no solution \\\\\n  B. two points \\\\\n  C. a line \\\\\n  D. a tetrahedron \\\\\n  E. a plane \\\\\n  F. I don't know\n\n  Reasons:\n  For A, the situation would be at least two of the three planes are parallel to \n  each other and not the same plane, or the intersection line of two planes is \n  parallel to and not contained in the third plane.\n\n  For C, the situation would be the intersection of two planes, which is a line, \n  is contained in the third plane.\n\n  For E, the situation would be that the three planes are the same.\n\\end{example}\nThe exceptions to a single solution to a linear system are described in the \nabove example.\n\n\\subsection{Algebraic point of view on exceptions of unique solutions}\n\nRecall that the formula of the unique solution to a linear system is\n\\[\n  X = A^{-1}B\n\\]\nIt turns out this formula doesn't always hold. In those exception cases, \n$A^{-1}$ doesn't exist, i.e. $A$ is not invertible.\n\n\\[\n  A^{-1} = \\frac{1}{det(A)}adj(A)\n\\]\nSince $adj(A)$ always exists, $A^{-1}$ exists $\\iff$ $A$ is invertible $\\iff$ \n$det(A) \\neq 0$.\n\n\\bigskip\n\nFurther discussion on different cases:\n\n1. Homogeneous cases: $AX = 0$\n\nFor Homogeneous cases, there is always a trivial solution $X = 0$ since all \nplanes pass through the origin.\n\nIf $det(A) \\neq 0$, then $A$ is invertible, then the linear system has a unique \nsolution, which must be $0$ since $0$ is always a solution to the linear \nsystem. We can also derive the conclusion in algebra:\n\\[\n  X = A^{-1}0 = 0\n\\]\n\nIf $det(A) = 0$, then since each row in $A$ is a normal vector of the \ncorresponding plane, $det(\\vec{N_1}, \\vec{N_2}, \\vec{N_3}) = 0$, which means \nthat $\\vec{N_1}$, $\\vec{N_2}$, $\\vec{N_3}$ are coplanar.\n\n  If $\\vec{N_1}$, $\\vec{N_2}$, $\\vec{N_3}$ are the same, then the planes in the \n  linear system are the same, so the solution set is the plane.\n\n  If $\\vec{N_1}$, $\\vec{N_2}$, $\\vec{N_3}$ are different, then the line passing \n  through the origin and perpendicular to the plane containing $\\vec{N_1}$, \n  $\\vec{N_2}$, and $\\vec{N_3}$ must be in all three planes in the linear \n  system. Therefore, the solution is $\\vec{N_1} \\times \\vec{N_2}$, or \n  $\\vec{N_2} \\times \\vec{N_3}$, or $\\vec{N_1} \\times \\vec{N_3}$.\n\n2. General cases: $AX = B$\n\nIf $det(A) \\neq 0$, there is a unique solution to the linear system.\n\nIf $det(A) = 0$, there is either none or infinite solution to the linear system.\n\n\\end{document}", "meta": {"hexsha": "765b33fdfc53f61e62b7ef115054e693703289b6", "size": 6137, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture4.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": "lecture4.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": "lecture4.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.5323383085, "max_line_length": 85, "alphanum_fraction": 0.6571614796, "num_tokens": 2023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.6681975135457375}}
{"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.2.1}\nIn an effort to estimate the mean amount spent per customer for dinner at a major Atlanta restaurant, data were collected for a sample of 49 customers. Assume a population standard deviation of \\$5.\n\\begin{enumerate}\n  \\item At 95\\% confidence, what is the margin of error?\n  \\begin{align*}\n    \\sigma &= 5\\\\\n    n &= 49\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.05/2}(5/ \\sqrt{49})\\\\\n    &=Z_{.025}(5/7)\\\\\n    &=1.96(5/7)\\\\\n    &=1.4\\\\\n  \\end{align*}\n  \\item If the sample mean is \\$24.80, what is the 95\\% confidence interval for the population mean?\n  \\begin{align*}\n    \\bar{x} &= 24.80\\\\\n    interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n    &= 24.80 \\pm 1.4\\\\\n    &= (23.40, 26.20)\n  \\end{align*}\n\\end{enumerate}\n\n\\section*{3.2.2}\nThe Wall Street Journal reported that automobile crashes cost the United States \\$162 billion annually (The Wall Street Journal, March 5, 2008). The average cost per person for crashes in the Tampa, Florida, area was reported to be \\$1,599. Suppose this average cost was based on a sample of 50 persons who had been involved in car crashes and that the population standard deviation is $\\sigma = 600$\n\\begin{enumerate}\n  \\item What is the margin of error for a 95\\% confidence interval?\n  \\begin{align*}\n    \\sigma &= 600\\\\\n    n &= 50\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.05/2}(600/ \\sqrt{50})\\\\\n    &=Z_{.025}(84.8528137423)\\\\\n    &=1.96(84.8528137423)\\\\\n    &=166.311514\\\\\n  \\end{align*}\n  \\item What would you recommend if the study required a margin of error of \\$150 or less?\n\n  We should reduce the confidence interval to get a smaller error margin\n\\end{enumerate}\n\n\\pagebreak\n\n\\section*{3.2.3}\nThe National Quality Research Center at the University of Michigan provides a quarterly measure of consumer opinions about products and services (The Wall Street Journal, February 18, 2003). A survey of 10 restaurants in the Fast Food/Pizza group showed a sample mean customer satisfaction index of 71. Past data indicate that the population standard deviation of the index has been relatively stable with $\\sigma = 5$.\n\\begin{enumerate}\n  \\item What assumption should the researcher be willing to make if a margin of error is desired?\n\n  That the data has a normal distribution and that you can based the margins in that\n\n  \\item Using 95\\% confidence, what is the margin of error?\n  \\begin{align*}\n    \\sigma &= 5\\\\\n    n &= 10\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.05/2}(5/ \\sqrt{10})\\\\\n    &=Z_{.025}(1.58113883)\\\\\n    &=1.96(1.58113883)\\\\\n    &=3.0990321\\\\\n  \\end{align*}\n\n  \\item What is the margin of error if 99\\% confidence is desired?\n  \\begin{align*}\n    \\sigma &= 5\\\\\n    n &= 10\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.01/2}(5/ \\sqrt{10})\\\\\n    &=Z_{.005}(1.58113883)\\\\\n    &=2.576(1.58113883)\\\\\n    &=4.07301362\\\\\n  \\end{align*}\n\\end{enumerate}\n\n\\section*{3.1.4}\nPlaybill magazine reported that the mean annual household income of its readers is \\$119,155 (Playbill, January 2006). Assume this estimate of the mean annual household income is based on a sample of 80 households, and based on past studies, the population standard deviation is known to be $\\sigma = \\$30,000$.\n\\begin{enumerate}\n  \\item Develop a 90\\% confidence interval estimate of the population mean.\n  \\begin{align*}\n    \\sigma &= 30,000\\\\\n    n &= 80\\\\\n    \\bar{x} &= 119,155\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.1/2}(30,000/ \\sqrt{80})\\\\\n    &=Z_{.05}(3354.101966)\\\\\n    &=1.645(3354.101966)\\\\\n    &=5,517.4977344\\\\\n    interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n    &= 119,155 \\pm 5,517.4977344\\\\\n    &= (113637.5022656, 124672.4977344)\n  \\end{align*}\n\n  \\item Develop a 95\\% confidence interval estimate of the population mean.\n  \\begin{align*}\n    \\sigma &= 30,000\\\\\n    n &= 80\\\\\n    \\bar{x} &= 119,155\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.05/2}(30,000/ \\sqrt{80})\\\\\n    &=Z_{.025}(3354.101966)\\\\\n    &=1.96(3354.101966)\\\\\n    &=6,574.0398538\\\\\n    interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n    &= 119,155 \\pm 6,574.0398538\\\\\n    &= (112580.9601462, 125729.0398538)\n  \\end{align*}\n\n  \\item Develop a 99\\% confidence interval estimate of the population mean.\n  \\begin{align*}\n    \\sigma &= 30,000\\\\\n    n &= 80\\\\\n    \\bar{x} &= 119,155\\\\\n    \\text{Error Margin} &= Z_{a/2}(\\sigma / \\sqrt{n})\\\\\n    &=Z_{.01/2}(30,000/ \\sqrt{80})\\\\\n    &=Z_{.005}(3354.101966)\\\\\n    &=2.576(3354.101966)\\\\\n    &=8,640.166665\\\\\n    interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n    &= 119,155 \\pm 8,640.166665\\\\\n    &= (110514.833335, 127795.166665)\n  \\end{align*}\n  \\item Discuss what happens to the width of the confidence interval as the confidence level is increased. Does this result seem reasonable? Explain.\n\n  We can see that the width of the confidence interval grows as the confidence level is increased. It seems reasonable because a confidence interval of 99 must include 99\\% of the results, which logically must be a wider part than a 95\\% or 90\\%.\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "74a0afbba41037ee8a28e4895997c945f2690d6a", "size": 5586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework3_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/Homework3_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/Homework3_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": 38.2602739726, "max_line_length": 419, "alphanum_fraction": 0.6541353383, "num_tokens": 1855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6681411521448896}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n\\begin{document}\n\\section{Dimension}%\n\\label{cha:dimension}\n\\begin{defn}[Dimension]\n\tThe \\textbf{dimension} of a finite-dimensional vector space is the length of any basis of the vector space.\n\\end{defn}\n\\begin{lemma}[Dimension of a subspace]\n\tIf $V$ is finite-dimensional and $U$ is a subspace of $V$, then\n\t\\begin{align*}\n\t\\text{dim}U \\leq \\text{dim}V.\n\t\\end{align*}\n\\end{lemma}\n\n\\begin{lemma}\n\tSuppose $V$ is finite-dimensional. Then every linearly independent list of vectors in $V$ with length $\\text{dim}V$ is a basis of $V$.\n\\end{lemma}\n\\subsection{Dimension of a sum of two spaces}\n\\begin{prop}\nLet $U_1,U_2 \\in V$ be finite dimensional vector spaces over some field $F$.\\\\\n\nThen\n\\begin{align*}\n\t\\textrm{dim}(U_1+U_2) = \\textrm{dim}U_1 + \\textrm{dim}U_2 - \\textrm{dim}(U_1\\cap U_2)\n\\end{align*}\n\\end{prop}\n\\begin{cor}\n\tSuppose $V$ is finite-dimensional and $U$ is a subspace of $V$ such that $\\text{dim}U = \\text{dim}V$. Then $U = V$.\n\\end{cor}\n\\end{document}\n", "meta": {"hexsha": "74ac518bd3dc735f33e84e63f67a5d0d6de2af27", "size": 1012, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/09-18-19-Dim.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-18-19-Dim.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-18-19-Dim.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": 30.6666666667, "max_line_length": 135, "alphanum_fraction": 0.7084980237, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.668141128928547}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 9, 2022}\n\\subsection{Asymmetric/Public Key Cryptography}\nThe premise is that we have \\emph{Alice} and \\emph{Bob} who are communicating, and \\emph{Eve} intercepts \\ul{all} communications between them. There is \\textbf{no} communication between Alice and Bob ahead of time. A priori, it's not entirely obvious that this is possible\\dots\n\nWe'll see that this is indeed possible!\n\n\\begin{example}\n    \\ul{Analogy}: Alice and Bob are communicating by writing messages on pieces of paper.\n\n    Symmetric cryptography is having a shared safe, Alice and Bob both have the key/know the combination to, and both can leave messages and retrieve messages.\n\n    \\begin{enumerate}\n        \\item Alice sets up a box with a thin slot with a lock on it. Alice has the key to this lock.\n        \\item Bob is able to deposit messages into the slot in the box, and Alice can retrieve it using her key.\n    \\end{enumerate}\n\\end{example}\n\nOur key is now $k = (k_\\mathsf{priv}, k_\\mathsf{pub})\\in \\mathcal{K} = \\mathcal{K}_\\mathsf{priv}\\times \\mathcal{K}_\\mathsf{pub}$ which consists of a private key and public key.\n\nOur encryption and decryption functions are now\n\\begin{align*}\n    e & : \\mathcal{K}_\\mathsf{pub} \\times \\mathcal{M} \\to \\mathcal{C}  \\\\\n    d & : \\mathcal{K}_\\mathsf{priv} \\times \\mathcal{C} \\to \\mathcal{M}\n\\end{align*}\n\\[d(k_\\mathsf{priv}, e(k_\\mathsf{pub}, m)) = m\\]\nWe want it to be easy to compute $e_{k_\\mathsf{pub}}$ and $d_{k_\\mathsf{priv}}$, but hard to compute $d_{k_\\mathsf{priv}}$ only knowing $k_\\mathsf{pub}$.\n\nSomething easier to construct, before a full-fledged public key system, is a key exchange:\n\\subsection{Diffie-Hellman Key Exchange}\n\\textbf{Q: How can Alice and Bob agree on a secret key over an insecure channel?}\n\n\\begin{example}\n    \\ul{Analogy}: A lockbox that can only be used by one person...and both people have to participate to set it up.\n\\end{example}\n\nBoth parties have to agree on a key and have a line of communication before agreeing on a key. This can only be used if both parties are online at the same time.\n\nWe start with a prime $p$ and $g\\in(\\ZZ/p\\ZZ)^\\times$ suitably. Alice and bob does the following, all mod $p$:\n\\begin{center}\n    \\begin{tabular}{ll}\n        \\toprule\n        Alice              & Bob                 \\\\ \\midrule\n        Generates $a$      & Generates $b$       \\\\\n        \\quad $\\downarrow$ & \\quad $\\downarrow$  \\\\\n        Computes $g^a$     & Computes $g^b$      \\\\\n        Send $g^a$ to Bob  & Send $g^b$ to Alice \\\\\n        Computes $(g^b)^a$ & Computes $(g^a)^b$  \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{center}\n\nAlice and Bob now know $g^{ab}$, which is the secret key. Eve, however, only knows $g^a$ and $g^b$. Alice and Bob can now use this shared secret $g^{ab}$ as a key for symmetric cryptography.\n\n\\begin{definition}[The Diffie-Hellman Problem (DHP)]\n    Given $g^a, g^b$, calculate $g^{ab}$.\n\\end{definition}\n\\begin{remark}\n    If we can solve the discrete log problem, we can solve the Diffie-Hellman problem.\n\\end{remark}\n\nVice versa? Can one solve DLP given solution to DHP? \\emph{This is unknown\\footnote{There is no known method.}.}\n\n\\subsection{Elgamal Public Key Cryptography}\nWe again start with $p$ prime and $g\\in (\\ZZ/p\\ZZ)^\\times$ suitably. This could be public knowledge, or Alice selects these.\n\nAlice: We have $a$ be Alice's private key, and $A = g^a$ be Alice's public key.\n\nBob: Has message $m$ he wishes to send. Bob does the following:\n\\begin{enumerate}\n    \\item Generate random $k$ (used only once, to send this message).\n    \\item Compute the following:\n          \\begin{enumerate}\n              \\item $c_1 = g^k\\mod{p}$\n              \\item $c_2 = m\\cdot A^k \\mod{p}$\n          \\end{enumerate}\n    \\item Send $c_1$ and $c_2$ to Alice.\n\\end{enumerate}\n\nAlice:\n\\[(c_1^a) = A^k \\text{ so } c_2\\cdot (c_1^a)^{-1}\\equiv m\\left((g^a)^k\\right)\\cdot \\left((g^a)^k\\right)^{-1} \\equiv m\\]\nBasically, they are using Diffie-Hellman key exchange, except $g^a$ is a public key and Bob assumes a secret key, and uses that to encrypt the message and sends it in one go.\n\n\\subsubsection{Implementation}\nWe have the following algorithm for encryption and decryption in Elgamal: \n\\begin{lstlisting}[language=Python]\nimport ext_gcd, pow_mod\nfrom random import randrange\ndef e(A, m): \n    k = randrange(p)\n    return (pow_mod(g, k, p), m * pow_mod(A, k, p))\n\ndef d(a, c):\n    pow_mod(c[0])\n    ...\n\\end{lstlisting}\n\\emph{to be continued...}", "meta": {"hexsha": "7f5e405b7b398da5082df8a17ab7a63916a5ba7f", "size": 4465, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-09.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-02-09.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-02-09.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": 46.0309278351, "max_line_length": 277, "alphanum_fraction": 0.6790593505, "num_tokens": 1341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.6681411284897243}}
{"text": "\\documentclass[main.tex]{subfiles}\n\n\\begin{document}\n\n%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Geometry}\nThere is a lot of equation and stuff to remember for DG. A lot of connection stuff, but I think (thankfully) no gauge theory.\n\n%%%%%%%%%%%%%%%%%%%%\n\\subsection{Connection and curvature}\n\n\n\\begin{definition}\nA connection $\\nabla$ on a vector bundle $E$ on a manifold $M$ is a linear map \n$$\n\\nabla: \\Gamma(M, E) \\rightarrow \\Gamma(M, \\Omega^1(M) \\otimes E )\n$$\nsatisfying the Leibniz rule:\n$$\n\\nabla(f s) = f \\nabla(s) + df \\otimes s\n$$\nwhere $f \\in C^{\\infty}M$ and $s \\in \\Gamma(M)$. Given $X \\in \\Gamma(M)$, we can define \n$\\nabla_X(s) \\coloneqq \\nabla(s) (\\mu)$. Note that this is $C^{\\infty}M$-linear in $X$, that is, $\\nabla_{fX}(s) = f \\nabla_{X}(s)$\n\\end{definition}\n\nNaturally, if I have a connection $\\nabla$ on $p: E \\rightarrow M$, and a map $f : N \\rightarrow M$, then we get pullback connection $f^*\\nabla$ on $f^*E \\rightarrow N$.\n\nIn local coordinates, we have basis $s_j$ for $E$ and $dx^i$ for $T^*M$, then we have \n$$\n\\nabla(s_j) = \\Gamma_{ij}^k dx^i \\otimes s_k\n$$\nEquivalently, \n$$\n\\nabla_{\\partial_i} s_j = \\Gamma_{ij}^k s_k\n$$\n$\\Gamma_{ij}^k$ are called the Christoffel symbols.\n\nAlternatively, one can write\n$$\n\\omega(s_j) = \\omega_j ^k s_k\n$$\nwhere $\\omega_j ^k = \\Gamma_{ij}^k dx^i$ are connection 1-forms.\n\nFrom this and Leibnitz rule we can determine the formula for any local section.\nGiven a covariant derivative $\\nabla$ on $E$, we can extend $d_\\nabla: \\Gamma(M, \\Omega^i(M) \\otimes E) \\rightarrow \\Gamma(M, \\Omega^{i+1}(M) \\otimes E)$. \n\nWe also get connection on tensors, direct sums, and duals of a vector bundle:\n\\begin{construction}\nGiven $(E, \\nabla')$, $(F, \\nabla'')$, we get a connection $\\nabla$ on $E \\sum F$ as follows:\n$$\n\\nabla(s, t) = (\\nabla' s, \\nabla'' t)\n$$\n\nSimilarly, we have connection $\\nabla$ on $E \\otimes F$:\n$$\n\\nabla s\\otimes t = \\nabla's \\otimes t + s \\otimes \\nabla'' t\n$$\n\nThe formula on the symmetric and exterior powers are the same.\n\nlastly, there is a connection on the dual, defined by:\n$$\n\\nabla \\alpha (s) \\coloneqq d (\\alpha(s)) -  \\alpha (\\nabla' s) \n$$\nThis is uniquely determined by making the pairing map $(E \\otimes E^*, \\nabla' \\otimes \\nabla) \\rightarrow (\\underline{\\mathbb{R}}, d)$ a map of bundles with connections (that is, taking connection commutes).\n\\end{construction}\n\n\n%%%%%%%%%%%%%%\n\\subsubsection{Curvature}\n\n\\todo[inline]{Mean curvature, scalar curvature etc, Ricci curvature, the symmetry of the Riemann curvature tensor}\nFrom this, we can define the curvature of a connection:\n\n\\begin{definition}\nGiven a connection $\\nabla$ on $E$, we have the curvature:\n$$\nR(\\mu, \\nu) s  \\coloneqq \\nabla_{\\mu} \\nabla_{\\nu} s - \\nabla_{\\nu} \\nabla_{\\mu} s  - \\nabla_{[\\mu, \\nu]} s\n$$\nIn fact, $R: \\Gamma(E) \\rightarrow \\Gamma(\\Omega^2(M) \\otimes E)$ is precisely $d_\\nabla ^2$. It is in fact a tensor (that is it is linear in $\\mu, \\nu$ and $s$).\n\nIn coordinates, \n$$\nR^l _{k, i, j} = dx^l (R(\\partial_i, \\partial_j) \\partial_k) = \\partial_i \\Gamma_{jk}^l - \\partial_j \\Gamma_{ik}^l + \\Gamma_{im}^l \\ \\Gamma_{jk}^m   -  \\Gamma_{jm}^l \\  \\Gamma_{ik}^m \n$$\n\nUsing connection 1-forms $\\omega$, we have \n$$\nR \\coloneqq d\\omega + \\omega \\wedge \\omega\n$$\nNote $\\omega \\wedge \\omega$ does matrix multiplication on the $(k,l)$ components. \n\nA connection is flat if its curvature is 0. Thus gives local systems on the manifold.\n\\end{definition}\n\n\n\\subsubsection{Torsion}\nThe most interesting connections are the ones on the tangent bundle, which is what we called a connection on a manifold.\n\n\\begin{definition}Given a connection $\\nabla$ on $M$ ($TM$), then its torsion tensor is \n$$\nT(X,Y) \\coloneqq \\nabla_X(Y) - \\nabla_Y(X) - [X,Y]\n$$\nIt can be shown that this is a tensor ($C^{\\infty}M$-linear) and ofc anti-symmetric.\n\\end{definition}\n\nIn local coordinates and Christoffel symbols, this means that \n$$\n\\Gamma_{ij}^k = \\Gamma_{ji}^k\n$$\n%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Parallel Transport}\nGiven a bundle $E$ over the interval $[0,1] \\in \\mathbb{R}$, together with a connection $\\nabla$. At any point $v \\in E|_0$, there exists a unique section $s_v : [0,1] \\rightarrow E$ with starting point $v$ such that $\\nabla_{\\partial_x} s_v = 0$.\n\nLocally, write a basis for $E$ with $s_v$ being an basis element (ofc, when $s_v$ is nonzero), and we have Christoffel symbol:\n$$\n\\nabla_{\\partial_x} s_i = \\Gamma_{i}^k s_k\n$$\nBy the fundamental theorem of ODE, we see that this has a unique solution that exists for all $x \\in [0,1]$.\n\nThus given a connection $\\nabla$ on $E \\rightarrow M$, and a path $\\gamma: [0,1] \\rightarrow M$, then we get a parallel transport map: $E|_{\\gamma(0)} \\rightarrow E|_{\\gamma(1)} $. Ofc this is compatible with concatenation. Moreover, the difference between how infinitesimally small path give different parallel transport is precisely measure by the curvature. So when the curvature vanishes, then any two homotopic smooth paths gives the same transport, and we get a local system. Another way to put it is that we have local flat sections, over a local neighborhood, not just a path.\n\n%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Geodesics}\nGiven a connection $\\nabla$ on (the tangent space of) manifold $M$. Given any path $\\gamma: [0,1] \\rightarrow M$, we can ask for the following\n$$\n\\nabla_{\\dot{\\gamma}} \\dot{\\gamma} = 0\n$$\nIn coordinates, where $t$ is the coordinate of the interval, and $x^i$ are the local coordinates of the manifold, we have the geodesic equations:\n$$\n\\frac{d^2 x^k}{dt ^2} + \\Gamma_{ij}^k \\frac{dx^i}{dt} \\frac{dx^j}{dt} = 0\n$$\nNote that this is $n$ 2nd order ODE in $n$ variables, and the existence and uniqueness theorem tells us that there exists locally a unique solution, determined by the starting point as well as the velocity. That is, given any $p \\in M$ and $v \\in T_p M$, there is locally a unique geodesic going through $p$ with velocity $v$.\n%%%%%%%%%%%%%%%%%%%%\n\\subsection{Riemannian Geometry: General Theory}\nLet $(M, g)$ be a Riemannian manifold, then we have an inner product \n$(-,-)$ on $T_p M$ for every point $p \\in M$. This identifies vectors with covectors, and gives us a way to turn $(i, j)$ tensors to $(i-1, j+1)$ tensors and vice versa. This is the raising and lowering of indicies.\n\nGiven a Riemnnian metric $g$ on a vector bundle $E$, a connection $\\nabla$ on $E$ is compatible with the metric if $\\nabla g = 0$. In formula, this means that for any $X \\in TM$, $s, t$ sections of $E$, we have \n$$\nd(s,t) = (\\nabla s, t) + (s, \\nabla t)\n$$\n\n\\begin{definition}\nThere is a unique torsion-free, compatible connection $\\nabla$ associated to $g$, called the Levi-Civita connection.\n\\end{definition}\nIn local coordinates, \n$$\n\\Gamma_{ij}^k = \\frac{1}{2} g^{kl}(\\partial_i g_{jl} + \\partial_j g_{il} - \\partial_l g_{ij})\n$$\n\\begin{remark}\nGiven a 1-form $\\alpha$, its covariant derivative $\\nabla \\alpha$ is the dual of $\\nabla V_\\alpha$, where $V_\\alpha$ is the dual of $\\alpha$.\n\\end{remark}\n\n\\begin{remark}\nOn a Riemannian manifold $M$, the holonomy around a loop $C$ is the parallel transport of the tangent vector around the loop.\n\\end{remark}\n\n\\subsubsection{Curvature of Riemannian manifolds}\nRecall that we have the curvature tensor $R_{ijk}^l$. We can also lower the $l$ to get the tensor $R_{ijkl}$. This tensor has a lot of symmetries:\n$$\nR_{ijkl} = R_{klij}, R_{ijkl} = -R_{jikl} (R_{ijkl} = - R_{ijlk}), R_{ijkl} + R_{iljk} + R_{iljk} = 0\n$$\nIn dimension $n$, it has \n$$\n\\frac{n^2 (n^2 - 1)}{12}\n$$\ncomponents.\nTaking trace gives us the Ricci curvature:\n\\begin{definition}\nThe Ricci curvature tensor is \n$$\nR_{jk} = R^i _{kij}\n$$\nIt is symmetric in j and k. \n\\end{definition}\n\nTaking trace once more, we get the scalar curvature\n$S = R^j _j = g^{ij} R_{ij}$.\n\n%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Riemannian Geometry: Submanifolds}\n\nGiven an immersion of manifold $i: N \\rightarrow M$, then a Riemannian metric $g$ on $M$ pullback to a Riemannian metric $g'$ on $N$. However, we can define the Levi-Civita connection\n$\\nabla'$ on $N$ more easily:\n\\begin{lemma}\n$\\nabla'_{\\mu} \\nu = pr (\\nabla_{\\mu} \\nu)$, where the projection is $TM \\rightarrow TN$ using the metric $g$ on $M$. \n\\end{lemma}\n\nWe can also project down to the normal bundle:\n\\begin{definition}\n$II: TN \\times TN \\rightarrow N$ is defined as $II(X, Y) \\coloneqq (\\nabla_{X} Y)^\\perp$, where $\\perp$ is the projection $TM \\rightarrow N$, where $N$ is the normal bundle. This is symmetric because the Levi-Civita connection is torsion-free (and the lie bracket of two tangent vector field that lies on a submanifold stays on the submanifold).\nGiven $\\mathfrak{n} \\in N$, then we get a pairing $II_\\mathfrak{n}: TN \\times TN \\rightarrow \\mathbb{R}$ given by \n$$\nX, Y \\mapsto (\\nabla_{X} Y, \\mathfrak{n}) = - (\\nabla_{X} \\mathfrak{n}, Y)\n$$\nNote that the equation is by the compatibility of $\\nabla$ with $g$ as well as the fact that $(Y, \\mathfrak{n}) = 0$ as $\\mathfrak{n}$ is normal.\n\nThe compatibility conditions implies that \n$\\nabla_X v$ is perpedicular to $v$ when $v$ is unit lenghth. Thus the holonomy are in $SO(T_pM)$. \n\nHere's some equivalent definition for $\\nabla$ to be compatible with $g$:\n\\begin{enumerate}\n    \\item $\\nabla g = 0$.\n    \\item the pairing $(-,-): TM \\times TM \\rightarrow \\underline{\\mathbb{R}}$ is map of bundles with connections.\n    \\item the iso $TM \\cong T^*M$ arising from $g$ is a map of bundles with connections.\n\\end{enumerate}\n\nNote the last one tells us how to compute covariant derivative for 1-forms: just dualize.\n\nDually, we have the shape operator associated to $\\mathfrak{n}$: \n\\begin{align*}\nS_{\\mathfrak{n}}: TN &\\rightarrow TN \\\\ \nX  \\mapsto & - (\\nabla_{X} \\mathfrak{n}) \n\\end{align*}\n\\end{definition}\n\nIn coordinates, we have \n$$\nS^i _j =  II^{ik} g_{kj}\n$$\nOne can check that $\\nabla_{X} \\mathfrak{n}$ lies on the tangent space of $M$\n\nAs the shape operator is symmetric (with respect to the Riemannian inner product of $N$), its eigenvalues are all real, and they are all orthogonal, no generalize eigenspaces. Thus there are eigenvalues and eigensubspaces of $S$. The eigenvalues are called the principal curvatures and the tangent vector there curve in circle around the normal vector.\n\n\\subsubsection{Geodesics in a Riemannian manifold}\nGiven a Riemann manifold $(M, g)$, since it has a Levi-Civita connection, thus we can ask for geodesics. But in fact there is a more direct interpretation (and use more often for quals), which is using the Lagrangian formulism.\n\nGiven any path $\\gamma: [0,1] \\rightarrow M$, we have the following functional \n$$\n\\mathcal{L} \\coloneqq \\int_{[0,1]} g_{ab} \\dot{\\gamma^a} \\dot{\\gamma b}\n$$, this is a form of length (or energy) of the path.\n\nwhose Euler Lagrange equation is precisely the geodesic equation. \n\nRecall the Euler-Lagrange equation, whose solution are the local extrema of the variation problem is given by \n$$\n\\frac{\\partial \\mathcal{L}}{\\partial x^i} - \\frac{d}{dt} \\frac{\\partial \\mathcal{L}}{\\partial \\dot{x^i}} = 0\n$$\n\n\\subsubsection{Covariant derivative in Orthogonal frames}\n\nOn a Riemannian manifold $(M, g)$, given an orthogonal frame $\\theta_i$ and coframe $\\theta^i$, we would like to calculate the covariant derivative (Christoffel symbols) of the Levi-Civita connection $\\nabla$ from the frame. Using torsion-free and compatibility property.\n\n\\todo[inline]{Orthonormal frame and Cartan's structure equation, also using the connection 1-form $\\omega$}\n\nIn this frame, we have the connection 1-form \n$$\n\\nabla \\theta_j = \\omega_j ^k \\theta_k\n$$\nwith \n$$\n\\omega_j ^k = \\Gamma_{ij}^k \\theta^i\n$$\nAs $(s_i, s_j) = \\delta_{i,j}$, the compatibility condition says that \n$$\n(\\nabla \\theta_j, \\theta_k) = -(\\nabla \\theta_k, \\theta_j)\n$$\nOn coordinates, this means that \n$$\n\\omega_j ^k = - \\omega_k ^j\n$$\n\nUsing the torsion free assumption, we also have the 1st Cartan's structural formula:\n$$\nd\\theta^k = \\omega_i ^k \\wedge \\theta^i\n$$\nThis formula is super important in calculating covariant derivatives. This is a part of the orthonormal decomposition method!\n(evaluating both sides at $(\\theta_m, \\theta_l)$, then the left hand side is given by $-\\theta^k([\\theta_m, \\theta_l])$ while the right hand side gives the corresponding $k$-th Christoffel symbol for $\\nabla_{\\theta_m} \\theta_l - \\nabla_{\\theta_m}\\theta_l \\ d\\theta^k= \\omega^k _{ml} - \\omega^k _{lm}$.\n\n\\subsubsection{Gauss map}\nGiven a immersion $i: M \\rightarrow \\mathbb{R}^{n+1}$ where $M$ is a compact oriented $n$-dimensional manifold (aka a hypersurface), then taking the (oriented) normal vector gives a map $N_i: M \\rightarrow S^n$. The differential of this map is the shape operator (because we have doing $\\partial_i \\mathfrak{n} = \\nabla_{\\partial_i} \\mathfrak{n}$). \nIf $n=2$, then the Jacobian (the determinant of the differential) it thus the Gaussian curvature. \nMoreoever, the degree of this map is 1/2 of the Euler characteristic of $M$. This is because the Euler characteristic is the Euler class of the tangent bundle of the sphere, which pulls back to the tangent bundle of the manifold. And taking Euler class intertwines between vector bundles and cohomology classes. Lastly the Euler class of the sphere is $1 = \\frac{1}{2} \\chi(S^2)$.\n\n\n\\subsection{Riemannian Geometry: Surfaces in $\\mathbb{R}^3$}\n\\todo[inline]{Gauss map, interpreting the curvature from the Gauss map, Gauss-Bonnet theorem.}\n\nLet $S \\subset \\mathbb{R}^3$ be an embedded smooth surface, and $\\mathfrak{n}$ a normal vector (this implicitly assumed a co-orientation of $S$, equivalently, an orientation of $S$, since $\\mathbb{R}^3$ is oriented).\n\nSince there is a canonical choice of normal vector, we get the second fundamental form. At any point $p$, the shape has two (not necessarily distinct) eigenvalues, $k1$ and $k2$, and they are the maximal point of the curvature of the normal planes intersecting with the curve. The Gaussian curvature $K \\coloneqq k_1 k_2$. It is the determinant of the shape operator, equivalently, in any coordinate, \n$$\nK = det S = \\frac{det II}{det I}\n$$\n\nThe mean curvature is $k_1 + k_2$ and it is the trace of the shape operator:\n$$\nH = tr(S) = g_{ij} II^{ij}\n$$\n\nFor the Euclidean space $\\mathbb{R}^n$ with its standard coordinates $x^i$, the covariant derivative is simply taking derivative, that is, all the Christoffel symbol are all zero.\n\nIn three dimensions, there are vector calculus calculations we can use, namely the cross product. Given a parametrized surface $\\Phi: U \\rightarrow \\mathbb{R}^3$, to find the normal vector, we take two independent local vector field $\\mu$, $\\nu$ on $U$, then we $\\Phi_* {\\mu}$ and $\\Phi_* \\nu$ spans the tangent spaces of the surfaces, and the cross product $\\Phi_* \\mu \\times \\Phi_* \\nu$ is perpendicular to both, those spans the normal line bundle. Therefore \n$$\n\\mathfrak{n} \\coloneqq \\frac{\\Phi_* \\mu \\times \\Phi_* \\nu}{|\\Phi_* \\mu \\times \\Phi_* \\nu|}\n$$\nis a unit length normal vector. \n\n\\subsubsection{Curvature in 2 space}\n\nIn two dimensions, the Riemann curvature tensor only have 1 degree of freedom and is determined by \n$R^1 _{212}$. \n\nThe relationship between Riemann curvature and Gaussian curvature is as follows:\n$$\nR_{1212} = det(g) K\n$$\nThus in with orthonormal frames they are the same. Coordinate independently, we have \n$$\nR_{klij} = K (g_{ki}g_{lj} - g_{kj}g_{lj})\n$$\nand multiple with $g^{ki}$, we get \n$$\nRic_{lj} = K g_{lj}\n$$\nMultiple with $g^{lj}$, we get that the scalar curvature:\n$$\nS = 2K\n$$\n\n\\begin{remark}\nNote that holonomies of loops on a surface are rotations as $SO(2) = U(1)$.\n\\end{remark}\n\\subsubsection{Gauss-Bonnet, Theorem-Egrenium}\n\\todo[inline]{State those theorem, at least know the proof of Theorem-Egrenium, and how does Guass-Bonnet relate to the first chern class of the tangent bundle?}\n\nGiven a surface $S \\subset \\mathbb{R}^3$, Theorem Egregium relates the Gaussian curvature, an external curvature invariant, with the Riemann curvature tensor coefficients (or the scalar curvature). It says that \n$$\nK = R(X, Y) X Y\n$$\nfor $X, Y$ local orthonormal vector fields. \n\nOn the other hand, the Gauss-Bonnet theorem says that the integral of the Gaussian curvature is a topological invariant:\n$$\n\\int_S K dA = 2 \\pi \\chi(M)\n$$\n\nIt has an extension to compact Riemannian manifold $S$ with boundary:\n$$\n\\int_S K dA + \\int_{\\partial S}k_g ds = 2\\pi \\chi(M)\n$$\nwhere $k_g$ is the geodesic curvature of the boundary of $S$ (as a curve in $S$).\n\nGiven a curve $\\gamma$, then \n$$\n\\nabla_{\\dot{\\gamma}} \\dot{\\gamma}\n$$\nis the normal vector of the curve. In dimension 2, this is a multiple of the normal vector, thus we get a scalar $k_g$.\n\n\\subsubsection{Orthonormal method to compute curvature of surfaces}\nThis is a standard method for computing curvature in 2-dimensions. First we take a orthonormal coframe $\\theta^i$ and the dual frame $\\theta_i$. We have the connection 2-form $\\omega_j ^k$. From above, we have that \n$$\n\\omega_j ^k = - \\omega_k ^j\n$$\nThis tells us right away that we only have to calculate \n$$\n\\omega_1 ^2 = - \\omega_2 ^1\n$$\nThen using Cartan's structural equation we have $$\nd\\theta^k = \\omega^k _i \\wedge \\theta^i\n$$\nand this gives us two equations\n$$\nd\\theta^1 = \\omega^1 _2 \\wedge \\theta^i\n$$ and \n$$\nd\\theta^2 = \\omega^2 _1 \\wedge \\theta^1\n$$. \nHopefully this is enough to compute $\\omega^1_2$. Then we have \n$$\nR = d \\omega + \\omega \\wedge \\omega\n$$\n\n\n\\subsection{Calculus of differential forms}\nLie brackets and exterior derivatives are in some sense dual.\n\nThe Lie bracket has the unique properties  that \n\\begin{enumerate}\n    \\item $\\mathcal{L}_X \\sigma \\otimes \\tau = \\mathcal{L}_X \\sigma \\otimes \\tau + \\sigma \\otimes \\mathcal{L}_X \\tau$\n    \\item $\\mathcal{L}_X f = X f = df (X)$\n    \\item $\\mathcal{L}_X \\sigma(Y_1, ..., Y_n) = \\mathcal{L_X} (\\sigma)(Y_1, ..., Y_n) + \\sigma (\\mathcal{L_X}Y_1, Y_2,...) + ...$\n\\end{enumerate}\n\nFor a 0-form $f$, we have \n$$\ndf(X) = X(f) = \\mathcal{L}_X f\n$$\n\nFor a 1-form $\\omega$, we have \n$$\nd\\omega(X,Y) = X(\\omega(Y)) - Y(\\omega(X)) - \\omega([X,Y])\n$$\n\nWe have the Cartan's magic formula:\n$$\n\\mathcal{L}_X \\omega = (\\iota_X d + d \\iota_X) \\omega\n$$\n\nThere is a formula expressing $d\\omega$ as evaluation of $\\omega$ and lie brackets.\nUsing the Cartan's magic formula as well as expanding $\\mathcal{L}_X$ on pairings of vectors and covectors.\n\n\\subsection{Standard Coordinates}\nThe polar coordinates on $\\mathbb{R}^2 - {0}$:\n$$\nx = r cos \\theta, y = r sin \\theta\n$$\n. The standard metric becomes \n$$\nds^2 = dr^2 + r^2 d\\theta^2\n$$\nwith $r \\in \\mathbb{R}^{>0}$ and $\\theta \\in [0,2\\pi)$\nThe spherical coordinate on $S^2$ is \n$$\nx = cos \\phi \\ sin \\theta, \ny = sin \\phi \\ sin \\theta, \nz = cos \\theta \n$$\nwith $\\phi \\in [0,2\\pi)$ and $\\theta \\in (0, \\pi)$\nthe sphere metric becomes \n$$\nds^2 = d\\theta^2 + sin^2 \\theta \\ d\\phi^2\n$$\n\n\n\\end{document}\n", "meta": {"hexsha": "67250eb51a82042aaa8d23f4bce53c22e77c600e", "size": 18726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DG.tex", "max_stars_repo_name": "leon2k2k2k/harvard-qual", "max_stars_repo_head_hexsha": "c3abbcee3d77a688ce060de697f31e92b60ee393", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DG.tex", "max_issues_repo_name": "leon2k2k2k/harvard-qual", "max_issues_repo_head_hexsha": "c3abbcee3d77a688ce060de697f31e92b60ee393", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DG.tex", "max_forks_repo_name": "leon2k2k2k/harvard-qual", "max_forks_repo_head_hexsha": "c3abbcee3d77a688ce060de697f31e92b60ee393", "max_forks_repo_licenses": ["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.7523364486, "max_line_length": 584, "alphanum_fraction": 0.6976396454, "num_tokens": 5919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6681402536684662}}
{"text": "\\chapter{Balanced Search Tree}\n\\section{2-3 Search Tree}\n\\subsection{Insertion}\nInsertion into a 3-node at bottom:\n\\begin{enumerate}\n\\item Add new key to the 3-node to create a temporary 4-node.\n\\item Move middle key of the 4-node into the parent (including root's parent).\n\\item Split the modified 4-node.\n\\item Repeat recursively up the trees as necessary.\n\\end{enumerate}\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.8]{23insert1}}\n\\caption{Insertion 1}\n\\label{fig:LABEL}\n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.8]{23insert2}}\n\\caption{insert 2}\n\\label{fig:LABEL}\n\\end{figure}\n\n\\subsection{Splitting}\nSummary of splitting the tree. \n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.65]{23splitting}}\n\\caption{Splitting temporary 4-ndoe summary}\n\\label{fig:splitting}\n\\end{figure}\n\n\\subsection{Properties}\nWhen inserting a new key into a 2-3 tree, under which one of the following scenarios must the height of the 2-3 tree increase by one? When every node on the search path from the root is a 3-node\n\n\\section{Red-Black Tree}\\label{rbtree}\n\\subsection{Properties}\nRed-black tree is an implementation of 2-3 tree using \\textbf{leaning-left red link}. \\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=1.1]{rbtree11}}\n\\caption{RB-tree and 2-3 tree}\n\\label{fig:LABEL}\n\\end{figure}\nThe height of the RB-tree is at most $2\\lg N$ where alternating red and black links. Red is the special link while black is the default link. \n\n\\runinhead{Perfect black balance.}Every path from root to null link has the same number of black links.\n\\subsection{Operations}\n\\runinhead{Elementary operations:}\n\\begin{enumerate}\n\\item Left rotation: orient a (temporarily) right-leaning red link to lean left. Rotate leftward. \n\\item Right rotation: orient a (temporarily) left-leaning red link to lean right. \n\\item Color flip: Recolor to split a (temporary) 4-node. Rotate rightward. \n\\end{enumerate}\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=1.20]{rbrotate}}\n\\caption{Rotate left/right}\n\\label{fig:LABEL}\n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=1.20]{rbflip}}\n\\caption{Flip colors}\n\\label{fig:LABEL}\n\\end{figure}\n\n\\runinhead{Insertion.} When doing insertion, from the child's perspective, need to have the information of current leaning direction and parent's color. Or from the parent's perspective - need to have the information of children's and grandchildren's color and directions.\n\nFor every new insertion, the node is always attached with red links. \n\nThe following code is the simplest version of RB-tree insertion: \n\\newpage\n\\begin{java}\nNode put(Node h, Key key, Value val) {\n  if (h == null)  // std red insert (link to parent).\n    return new Node(key, val, 1, RED);\n  int cmp = key.compareTo(h.key);\n  if      (cmp < 0) h.left  = put(h.left,  key, val);\n  else if (cmp > 0) h.right = put(h.right, key, val);\n  else h.val = val; // pass\n\n  if (isRed(h.right) && !isRed(h.left))    \n    h = rotateLeft(h);\n  if (isRed(h.left) && isRed(h.left.left)) \n    h = rotateRight(h);\n  if (isRed(h.left) && isRed(h.right))     \n    flipColors(h);\n\n  h.N = 1+size(h.left)+size(h.right);\n  return h; \n}\n\\end{java}\n\nRotate left, rotate right, then flip colors.\n\n\\runinhead{Illustration of cases.} Insert into a single 2-node: Figure-\\ref{fig:rb_2}. Insert into a single 3-node: Figure-\\ref{fig:rb_3}\n\\begin{figure}[t]\n\\begin{tabular}{cc}\n  \\includegraphics[height = 1.7in]{rb_left} &\n  \\includegraphics[height = 1.7in]{rb_right}\\\\\n\\end{tabular}\n\\caption{(a) smaller than 2-node (b) larger than 2-nod}\n\\label{fig:rb_2}\n\\end{figure}\n\n\\begin{figure}[t]\n        \\centerline{\\includegraphics[height = 2.8in]{rb_3_left_right_btw}}\n        \\caption{(a) larger than 3-node (b) smaller than 3-node (c) between 3-node.}\n    \\label{fig:rb_3}\n\\end{figure}\n\n\\runinhead{Deletion.} Deletion is more complicated. \n\n\\section{B-Tree}\nB-tree is the generalization of 2-3 tree. \n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.50]{b-tree}}\n\\caption{B-Tree}\n\\label{fig:b-tree}\n\\end{figure}\n\\subsection{Basics}\nHalf-full principle: \n\n\\begin{tabular}{lll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Attrs} & \\textbf{Non-leaf} & \\textbf{Leaf} \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\nPtrs & \\lceil\\frac{n+1}{2}\\rceil & \\lfloor\\frac{n+1}{2}\\rfloor \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\n\\caption{Nodes at least half-full}\n\\end{tabular}\n\n\\subsection{Operations}\nCore clues\n\\begin{enumerate}\n\\item \\textbf{Invariant}: children balanced or left-leaning\n\\item \\textbf{Split}: split half, thus invariant.\n\\item \\textbf{Leaf-Up}: no delete, recursively move up the right node's first child;\nthus invariant.\n\\item \\textbf{Nonleaf-Up}: delete and recursively move up the left's last if left-leaning\nor right's first if balanced; thus invariant. \n\\end{enumerate}\n\n\\section{AVL Tree}\nTODO\n\n\\section{Cartesian Tree}\n\\subsection{Basics}\nAlso known as max tree (or min tree). The root is the maximum number in the array. The left subtree and right subtree are the max trees of the subarray divided by the root number.\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.60]{Cartesian_tree}}\n\\caption{Cartesian Tree}\n\\label{fig:cartesianTree}\n\\end{figure}\n\\begin{java}\nGiven [2, 5, 6, 0, 3, 1], the max tree is\n     6\n    / \\\n   5   3\n  /   / \\\n 2   0   1\n\\end{java}\n\\runinhead{Construction algorithm.} Similar to all nearest smaller (or larger) values problem - Section \\ref{allNearestSmaller}.\n\nCore clues:\n\\begin{enumerate}\n\\item Use stack to maintain a \\textit{strictly decreasing} stack, similar to find the all nearest large elements.\n\\itm Maintain the tree for currently scanning $A_i$ with the subarray $A[:i]$.\n\\begin{enumerate}\n\\item \\rih{Left tree.} For each currently scanning node $A_i$, if ${stk}_{-1} \\leq A_i$, then ${stk}_{-1}$ is the left subtree of $A_i$. Then pop the stack and iteratively look at ${stk}_{-1}$ again (previously ${stk}_{-2}$). Notice that the original left subtree of $A_i$ should become the right subtree of ${stk}_{-1} $, because the original left subtree appears later and satisfies the decreasing relationship.\n\\item \\rih{Right tree.} In this stack, ${stk}_{-1} < {stk}_{-2}$ and ${stk}_{-1}$ appears later than ${stk}_{-2}$; thus ${stk}_{-1}$ is the right subtree of ${stk}_{-2}$. The strictly decreasing relationship of stack will be processed when popping the stack. \n\\end{enumerate}\n\\end{enumerate}\n\n$O(n)$ since each node on the tree is pushed and popped out from stack once.\n\n\\newpage\n\\begin{python}\ndef maxTree(self, A):\n    stk = []\n    for a in A:\n        cur = TreeNode(a)\n        while stk and stk[-1].val <= cur.val:\n            pre = stk.pop()\n            pre.right = cur.left\n            cur.left = pre\n\n        stk.append(cur)\n\n    pre = None\n    while stk:\n        cur = stk.pop()\n        cur.right = pre\n        pre = cur\n\n    return pre\n\\end{python}\n\nUsually, min tree is more common. \n\\subsection{Treap}\n\\rih{Randomized Cartesian tree}. Heap-like tree. It is a Cartesian tree in which each key is given a (randomly chosen) numeric priority. As with any binary search tree, the inorder traversal order of the nodes is the same as the sorted order of the keys.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.80]{treap}}\n\\caption{Treap. Each node x is labeled with x.key: x.priority.}\n\\label{fig:treap}\n\\end{figure}\n\nConstruct a Treap for an array $A$ with index as the $x.key$ randomly chosen priority $x.priority$ $O(n)$. Thus support search, insert, delete into array (i.e. Treap) $O(\\log n)$ on average. \n\nInsertion and deletion - need to perform \\textit{rotations} to maintain the min-treap property. \n", "meta": {"hexsha": "10e18f4404b52aec4e6b84d60d20b147802e4e55", "size": 7711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterBalancedSearchTree.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": "chapterBalancedSearchTree.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": "chapterBalancedSearchTree.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": 35.534562212, "max_line_length": 413, "alphanum_fraction": 0.7184541564, "num_tokens": 2272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.6681402527525513}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{float}\n\\usepackage{breqn}\n\\usepackage{graphicx}\n\\usepackage[labelformat=empty]{caption}\n\\usepackage{outlines}\n\\author{Calvin A. Whealton (caw324@cornell.edu)}\n\\title{Geothermal Play Fairway Analysis Code Documentation}\n\n\\renewcommand{\\thesection}{}\n\\renewcommand{\\thesubsection}{}\n\n\\setcounter{tocdepth}{5}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\newpage\n\nThe following document provides supporting information for codes written by Calvin Whealton for the Geothermal Play Fairway Analysis grant. This is not a comprehensive list of all code written for the project. Section 1 is for bottom-hole temperature corrections, section 2 is for outlier identification, and section 3 is for reservoir ideality. \n\n\\section*{Bottom-hole Temperature Corrections}\n\nThese scripts, code, and documents pertain to the bottom-hole temperature correction calculations.\n\n\\subsection*{\\textsf{func\\_BHT\\_NY\\_PA\\_WV\\_corr.R}}\n\n\\textbf{Description}: Script with a function to compute bottom-hole temperature corrections for NY, PA, and WV based on the region. Function accepts an R data frame and returns the data frame with two additional columns for the corrected bottom-hole temperature and the error.\n\n\\begin{table}[H]\n\\begin{tabular} {p{2cm} p{11cm}}\n\\hline\n\\textbf{Variable} & \\textbf{Description}\\\\\n\\hline\n\\textsf{X} \t\t\t & R data frame with variables named\\\\\n & \\textsf{bht\\_c}: Recorded bottom-hole temperature in Celsius\\\\\n & \\textsf{calc\\_depth\\_m}: Calculated depth of well in meters\\\\\n & \\textsf{reg}:  Region for that point\\\\\n & 0=Rome Trough and areas south east in PA \\\\\n & 2=West VA Correction\\\\\n & 3=Allegheny Plateau with drilling fluid information\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\nThe output is a data frame with the following columns added.\n\n\\begin{table}[H]\n\\begin{tabular} {p{2cm} p{11cm}}\n\\hline\n\\textbf{Output} & \\textbf{Description}\\\\\n\\hline\n\\textsf{corr\\_bht\\_c} \t & Corrected bottom-hole temperature in Celsius \\\\\n\\textsf{corr\\_error}\t\t & Error from calculation of correcting the bottom-hole temperature\\\\\n  & 0: no errors\\\\\n  & 20: depth outside of normal range\\\\\n  & 21: depth is negative\\\\\n  & 22: depth is missing for Allegheny Plateau or West Virginia data\\\\\n  & 30: categorical variable not 0, 2, or 3\\\\\n  & 32: categorical variable missing\\\\\n  & 42: bottom-hole missing\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\n\\textbf{Equations}: The equations used to calculate the temperature correction $\\Delta T$ are given below. Depth ($z_0$) is in meters and temperature correction ($\\Delta T$) is in Celsius. See Frone and Blackwell (2010) for details on the modified Harrison correction. If no region is specified no temperature correction is computed and an error is printed in the output.\n\n\n\\begin{equation} \\label{DT_rt}\n{\\Delta T}_{Rome Tr.} = 0\n\\end{equation}\n\n\\begin{equation} \\label{DT_wv}\n{\\Delta T}_{W Va.} = \\min\\{15, -1.99 + 0.00652z_0 \\}\n\\end{equation}\n\n\\begin{equation} \\label{AP_mud}\n{\\Delta T}_{Alle. Plat., mud} =  \\left\\{\n\\begin{array}{ll}\n0.0155\\left[ \\left(1650^3 + z_0^3\\right)^{1/3} - 1650 \\right],\t& (z_0 < 4000 \\mathrm{m})\\\\\n37.8,  & (z_0 > 4000 \\mathrm{m})\\\\\n\\end{array} \\right .\n\\end{equation}\n\n\\begin{equation} \\label{AP_air}\n{\\Delta T}_{Alle. Plat., air} =  \\left\\{\n\\begin{array}{ll}\n0.0104\\left[ \\left(1090^3 + z_0^3\\right)^{1/3} -1090 \\right],\t& (z_0 < 2500 \\mathrm{m})\\\\\n15.4,  & (z_0 > 2500\\mathrm{m})\\\\\n\\end{array} \\right .\n\\end{equation}\n\n\\begin{equation} \\label{AP_oth}\n{\\Delta T}_{Alle. Plat., other} = \\mathrm{Prob}(mud) {\\Delta T}_{Alle. Plat., mud} + \\mathrm{Prob}(air){\\Delta T}_{Alle. Plat., air}\n\\end{equation}\n\n\n\\subsection*{\\textsf{example\\_bht\\_corr.R}}\n\n\\textbf{Description}: Script to run the function \\textsf{func\\_BHT\\_NY\\_PA\\_WV\\_corr.R} with synthetic data in \\textsf{bht\\_test\\_data.csv}. The output should be corrected BHTs and cases that generate all errors for missing values or values outside typical ranges.\n\n\\subsection*{\\textsf{bht\\_test\\_data.csv}}\n\n\\textbf{Description}: Synthetic data to test \\textsf{func\\_BHT\\_NY\\_PA\\_WV\\_corr.R} for proper corrections and generating all possible errors.\n\n\\newpage\n\n\\section*{Outliers}\nThese codes, scripts, and files pertain to the outlier identification procedures.\n\n\\subsection*{\\textsf{outlier\\_identification.R}}\n\n\\textbf{Description}: Script with several functions to compute outliers using one of the specified algorithms with the specified inputs. Most algorithms have separate functions described below.\n\n\\begin{table}[H]\n\\begin{tabular} {p{2.5cm} p{10cm}}\n\\hline\n\\textbf{Function} & \\textbf{Description}\\\\\n\\hline\n\\textsf{outlier\\_iden} & General function to call other functions and perform outlier identification \\\\\n\\textsf{outlier\\_loc\\_pts} & Local outlier identification for \\textsf{algo}=1\\\\\n\\textsf{outlier\\_loc\\_rad} & Local outlier identification for \\textsf{algo}=2\\\\\n\\textsf{outlier\\_loc\\_grid} & Local outlier identification for \\textsf{algo}=3\\\\\n\\textsf{outlier\\_glob} & Global outlier identification\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\n\\begin{table}[H]\n\\begin{tabular} {p{2cm} p{11cm}}\n\\hline\n\\textbf{Variable} & \\textbf{Description}\\\\\n\\hline\n\\textsf{X} \t\t\t & R data frame with variables named \\\\\n & \\textsf{x\\_coord}: Longitude coordinate in km\\\\\n & \\textsf{y\\_coord}: Latitude coordinate in km\\\\\n & \\textsf{test}: Variable to be tested for being an outlier\\\\\n\\textsf{algo} & algorithm for determining local outlier\\\\\n & 1: (Default) Finds nearest points\\\\\n & 2: Finding all points within a given radius\\\\\n & 3: Gridding data\\\\\n\\textsf{outcri} & Outlier criteria\\\\\n & 1: (Default) Only local outliers flagged as outliers\\\\\n & 2: Only local and global outliers flagged as outliers\\\\\n & 3: Only global outliers flagged as outliers\\\\\n\\textsf{pt\\_eval} & Number of points used in when \\textsf{algo}=1 (default = 25)\\\\\n\\textsf{rad\\_eval} & Radius (in km) at which to take points when \\textsf{algo}=2 (default = 16)\\\\\n\\textsf{box\\_size} & Size of spacing (in km) to form grids when \\textsf{algo}=3 (default = 32)\\\\\n\\textsf{pt\\_min} & Minimum number of points required to perform local test for \\textsf{algo}=2 or 3 (default = 25)\\\\\n\\textsf{rad\\_max} & Maximum radius (in km) at which to take points when \\textsf{algo}=1 (default = 16)\\\\\n\\textsf{k\\_glob} & Constant multiplied by the upper- and lower-half quartile ranges in global analysis (default = 3)\\\\\n\\textsf{k\\_loc} & Constant multiplied by the upper- and lower-half quartile ranges in local analysis (default = 3)\\\\\n\\textsf{type}\t & Type of quantile estimation (default = 7, see R documentation)\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\nThe output is a data frame with the following columns added. The local outlier columns will only be added when \\textsf{outcri}=1 or 2. The global outlier columns will only be added when \\textsf{outcri}=2 or 3. The \\textsf{outs} column will be present in all output.\n\n\\begin{table}[H]\n\\begin{tabular} {p{2cm} p{11cm}}\n\\hline\n\\textbf{Output} & \\textbf{Description}\\\\\n\\hline\n\\textsf{outs}\t & Binary variable for points being an outlier (1=outlier)\\\\\n\\hline\n\\textsf{out\\_loc\\_lo} & Binary variable for point being a local low outlier (1=outlier)) \\\\\n\\textsf{out\\_loc\\_hi} & Binary variable for point being a local high outlier (1=outlier) \\\\\n\\textsf{out\\_loc\\_lq} & Lower quartile for local outlier test (NA if not tested) \\\\\n\\textsf{out\\_loc\\_mq} & Median for local outlier test (NA if not tested) \\\\\n\\textsf{out\\_loc\\_uq} & Upper for local outlier test (NA if not tested) \\\\\n\\textsf{out\\_loc\\_lb} & Lower bound for local outlier test (NA if not tested)\\\\\n\\textsf{out\\_loc\\_ub} & Upper bound for local outlier test (NA if not tested)\\\\\n\\textsf{out\\_loc\\_rad} & Maximum distance to point (only for algo=1)\\\\\n\\textsf{out\\_loc\\_pts} & Number of points in local area (only for algo=2 and 3)\\\\\n\\textsf{out\\_loc\\_error} & Error in local outlier calculation\\\\\n & 0: No errors\\\\\n & 1: Some points outside \\textsf{rad\\_max} when \\textsf{algo}=1)\\\\\n & 2: Fewer than \\textsf{pt\\_min} points in region when \\textsf{algo}=2 or 3)\\\\\n\\hline\n\\textsf{out\\_glob\\_lo} &  Binary variable for points being an global low outlier (1=outlier)\\\\\n\\textsf{out\\_glob\\_hi} &  Binary variable for points being an global high outlier (1=outlier)\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\n\\textbf{Equations}: The equations used to calculate low and high outlier bounds are given below. In these equations $q$ is a variable of interest (\\textsf{test} in the data) with subscripts denoting quantiles and $k$ is the constant (\\textsf{k\\_loc} or \\textsf{k\\_glob}). The equations can be applied locally or globally. Aguirre (2014) uses an outlier test that is similar, but the version implemented in this code is more flexible.\n\n\\begin{equation} \\label{lb}\nB_{lower} = q_{0.25} - k(q_{0.5} - q_{0.25})\n\\end{equation}\n\n\\begin{equation} \\label{ub}\nB_{upper} = q_{0.75} + k(q_{0.75} - q_{0.5})\n\\end{equation}\n\n\\subsection*{\\textsf{example\\_outlier\\_code.R}}\n\n\\textbf{Description}: Script to run outlier identification functions with test data and the Cornell dataset. Later portions do not need to be run because they were testing sensitivity of the algorithm to the input parameters. They are kept in the code for potential future analysis.\n\n\\subsection*{\\textsf{out\\_test\\_grid.csv}}\n\n\\textbf{Description}: Synthetic data to test the local outlier identification algorithm that uses gridding.\n\n\\subsection*{\\textsf{out\\_test\\_rad.csv}}\n\n\\textbf{Description}: Synthetic data to test the local outlier identification algorithm that uses maximum radius.\n\n\\subsection*{\\textsf{out\\_test\\_pt.csv}}\n\n\\textbf{Description}: Synthetic data to test the local outlier identification algorithm that uses number of points.\n\n\\subsection*{\\textsf{cornell\\_data.csv}}\n\n\\textbf{Description}: Cornell heat flow database with 8,919 points used to test sensitivity of the outlier identification algorithm. See Cornell University (2014).\n\n\\newpage\n\n\\section*{Reservoir Ideality}\n\n\\subsection*{\\textsf{MainIdeality.m}}\n\n\\textbf{Description}: Script that runs the reservoir ideality uncertainty analysis. Subsidiary functions are called from this script. This script also imports an example dataset and uncertainty mapping from \\textsf{TestFormationData.csv} and \\textsf{TestUncertaintyLevels.csv}, respectively. This script can be modified to include more graphs and statistical analysis.\n\n\\subsection*{\\textsf{GenRandNums.m}}\n\n\\textbf{Description}: Function to generate random numbers from uniform, triangular, normal, or lognormal distributions.\n\n\\begin{table}[H]\n\\begin{tabular} {p{2cm} p{11cm}}\n\\hline\n\\textbf{Variable} & \\textbf{Description}\\\\\n\\hline\n\\textsf{mean} \t\t\t & Mean value of the distribution (real-space)\\\\\n\\textsf{unc} & uncertainty (spread) of the distribution as a percentage of the mean\\\\\n & uniform: bounds are defined from uncertainty\\\\\n & triangular: bounds are defined from uncertainty\\\\\n & normal: 95\\% central region of distribution defined by uncertainty\\\\\n & lognormal: real-space coefficient of variation  defined by uncertainty\\\\\n\\textsf{dist} & Distribution selected\\\\\n & 1: Non-standard uniform distribution\\\\\n & 2: Triangular distribution, symmetric\\\\\n & 3: Normal distribution\\\\\n & 4: Lognormal distribution\\\\\n\\textsf{reps} & Number of replicates to generate\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\nThe output is a column vector with of numbers for the specified distribution.\n\n\\subsection*{\\textsf{MonteCarloApprox.m}}\n\n\\textbf{Description}: Function to calculate Monte Carlo Approximation of the distribution of reservoir ideality.\n\n\\begin{table}[H]\n\\begin{tabular} {p{2cm} p{11cm}}\n\\hline\n\\textbf{Variable} & \\textbf{Description}\\\\\n\\hline\n\\textsf{mat} \t\t\t & Matrix of random values for reservoir ideality calculation\\\\\n & column 1: $k$, permeability/conductivity\\\\\n & column 2: $H$, thickness\\\\\n & column 3: $P_o$, pressure\\\\\n & column 4: $P_b$, pressure\\\\\n & column 5: $R_o$, radius\\\\\n\\textsf{mu} & Viscosity\\\\\n\\textsf{Rb} & Casing radius\\\\\n\\textsf{ideality} & ideality metric\\\\\n & 1: $(2\\pi/\\mu)kH(P_o - P_b)/(\\ln(R_b) - \\ln(R_o))$\\\\\n & 2: not currently used\\\\\n\\textsf{reps} & Number of replicates to generate\\\\\n\\hline\n\\end{tabular} \n\\end{table}\n\nNote that in the code $P_{diff} = -|P_o - P_b|$ is used. The difference between $P_o$ and $P_b$ should be large so that this is generally not necessary, but it ensures that there are no problems. The output is a column vector with the distribution of the reservoir ideality.\n\n\\subsection*{\\textsf{TestFormationData.csv}}\n\n\\textbf{Description}: Example file for input of formation data. The version of MATLAB used to develop this could not handle strings and numbers, so all input converted to numbers. The header line is dropped when reading-in the file.\n\n\\subsection*{\\textsf{TestUncertaintyLevels.csv}}\n\n\\textbf{Description}: Example file for mapping uncertainty levels in \\textsf{TestFormationData.csv} to percentage uncertainty. Column 1 is the uncertainty mapping (1-5). Columns 2-6 are the percentage uncertainty associated with that level for $k$, $H$, $P_o$, $P_b$, and $R_o$, respectively.\n\n\\newpage\n\n\\section*{References}\n\nAguirre, G. A. (2014). \\textit{Geothermal Resource Assessment: A Case Study of Spatial Variability and Uncertainty Analysis for the States of New York and Pennsylvania}. Master's Thesis, Environmental and Water Resources Systems Engineering, School of Civil and Environmental Engineering, Cornell University.\\hfill\n\\bigskip\n\n\\noindent\nCornell University (2014). Cornell University Heat Flow Database (NY and PA). Southern Methodist University Geothermal Laboratory. (Accessed 16 June 2014) geothermal.smu.edu/static/DownloadFilesButtonPage.htm \\hfill\n\\bigskip\n\n\\noindent\nFrone, Z. and Blackwell, D. (2010). Geothermal Map of the Northeastern United States and the West Virginia Thermal Anomaly. \\textit{Geothermal Resources Council Transactions 34}:339-344.\n\\end{document}", "meta": {"hexsha": "6e3f4b62358c7603db683c9fc945ff9955e5420a", "size": 13881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geothermal_bhts_outliers_documentation.tex", "max_stars_repo_name": "calvinwhealton/geothermal_bhts_outliers", "max_stars_repo_head_hexsha": "b50887fe78885d4dde4bb801c4211cf460c2d071", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-01-07T20:49:37.000Z", "max_stars_repo_stars_event_max_datetime": "2016-01-07T20:49:37.000Z", "max_issues_repo_path": "geothermal_bhts_outliers_documentation.tex", "max_issues_repo_name": "calvinwhealton/geothermal_pfa", "max_issues_repo_head_hexsha": "b50887fe78885d4dde4bb801c4211cf460c2d071", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "geothermal_bhts_outliers_documentation.tex", "max_forks_repo_name": "calvinwhealton/geothermal_pfa", "max_forks_repo_head_hexsha": "b50887fe78885d4dde4bb801c4211cf460c2d071", "max_forks_repo_licenses": ["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.2149837134, "max_line_length": 433, "alphanum_fraction": 0.7454794323, "num_tokens": 4034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6681402488093504}}
{"text": "\\section{Categories, functors, natural transformations}\n%Office hours. Hood Chatham's are Mondays, 1:30 - 3:30, in 2-390A. Miller's is Tuesdays, 3:00-5:00 in 2-478. (commented out because not relevant to readers)\n%Replaced \\mathbf{C} with \\cC as brought up in ``Stuff to fix.''\n%Rearranged some stuff. Added a notational remark following the definition of a category.\nFrom spaces and continuous maps, we constructed graded abelian groups and homomorphisms. We now cast this construction in the more general language of category theory.\n\nOur discussion of category theory will be interspersed throughout the text, introducing new concepts as they are needed. Here we begin by introducing the basic definitions.\n\n\\begin{definition}\nA \\emph{category} $\\cc$ is a class $\\mathrm{ob}(\\cc)$ of objects, such that for every two objects $X$ and $Y$ there is a set of \\emph{morphisms} $\\cc(X,Y)$ (thought of as a set of maps from $X$ to $Y$). We require that for all $X\\in\\mathrm{ob}(\\cc)$, there exists an identity element $1_X\\in\\cc(X,X)$, and for all $X,Y,Z\\in\\mathrm{ob}(\\cc)$, there is a composition $\\cc(X,Y)\\times\\cc(Y,Z)\\to\\cc(X,Z)$ sending $(f,g)\\mapsto g \\circ f$. These in turn satisfy the following:\n\\begin{itemize}\n\\item $1_Y\\circ f=f$, and $f\\circ 1_X=f$.\n\\item Composition is associative.\n\\end{itemize}\n\\end{definition}\nNote that, for set-theoretic reasons, we require the collection of objects to be a class. This enables us to talk about a ``category of all sets'' for example, but not a ``category of all categories'' because that is too large.\n\nWe will often write $X\\in\\cc$ to mean $X\\in\\mathrm{ob}(\\cc)$, and $f\\colon X\\to Y$ to mean $f\\in \\cc(X,Y)$.\n\\begin{definition}\nIf $X,Y\\in \\cc$, then $f\\colon X\\to Y$ is an \\emph{isomorphism} if there exists $g\\colon Y\\to X$ with $f \\circ g=1_Y$ and $g\\circ f=1_X$, and we write $X\\cong Y$. \n\\end{definition}\n\n\\begin{example}\nMany common mathematical structures can be arranged in categories.\n\\begin{itemize}\n\\item Sets and functions between them form a category $\\set$.\n\\item Abelian groups and homomorphisms form a category $\\mathbf{Ab}$.\n\\item Topological spaces and continuous maps form a category $\\mathbf{Top}$.\n\\item Simplicial sets and their maps form a category $s\\set$.\n\\item A monoid is the same as a category with one object, where the elements of the monoid are the morphisms in the category.\n\\item The sets $[n]=\\{0,\\ldots,n\\}$ for $n\\geq 0$ together with weakly order-preserving maps between them form the simplex category $\\Delta$.\n\\item A poset forms a category in which there is a morphism from $x$ to $y$ iff $x\\leq y$. However, note that $x\\leq y$ and $y\\leq x$ imply $x\\cong y$ rather than $x=y$. The latter holds if the only isomorphisms are identities.\n\\end{itemize}\n\\end{example}\nA small category is one such that $\\mathrm{ob}(\\cc)$ is a set, not necessarily a class. While we cannot consider the category of all categories, it is sensible to define the category $\\mathbf{Cat}$ of all small categories. But first, we must first define a ``morphism of categories.''\n\\begin{definition}\nLet $\\cc,\\cd$ be categories. A \\emph{functor} $F\\colon\\cc\\to\\cd$ is a function $\\mathrm{ob}(\\cc)\\to\\mathrm{ob}(\\cd)$, such that for all $x,y\\in\\mathrm{ob}(\\cc)$, there is a map $\\cc(x,y)\\to\\cc(F(x),F(y))$ that respects composition and the identity.\n\\end{definition}\nThe diagram at the beginning of the previous section shows the functors we have built thus far (although explicit verification of functoriality is left to the reader).\n\nWe go a step further. Suppose we fix categories $\\cc$ and $\\cd$ and consider all functors $\\cc\\to\\cd$. What is a ``morphism of functors''?\n\\begin{definition}\nLet $F,G\\colon \\cc\\to\\cd$. A \\emph{natural transformation} $\\theta\\colon F\\to G$ consists of maps $\\theta(X)\\colon F(X)\\to G(X)$ for all $X\\in\\mathrm{ob}(\\cc)$ such that the following diagram commutes for all $f\\colon X\\to Y$:\n\\begin{equation*}\n\\xymatrix{F(X)\\ar[d]^{F(f)}\\ar[r]^{\\theta(X)} & G(X)\\ar[d]^{G(f)}\\\\\nF(Y)\\ar[r]^{\\theta(Y)} & G(Y)}\n\\end{equation*}\n\\end{definition}\n\\begin{definition}\nIf $\\cc,\\cd$ are categories, $\\mathbf{Fun}(\\cc,\\cd)$ is the category whose objects are functors $\\cc\\to\\cd$ and whose morphisms are natural transformations.\n\\end{definition}\nGoing further down the rabbit hole leads to higher category theory, which we will not delve into.\n\nNatural transformations are central to algebraic topology. We will frequently describe certain maps as ``natural,'' which is to say that they are natural transformations. The reader should determine the functors involved if they are not explicitly stated.\n\\begin{example}\nThe boundary map $\\partial\\colon S_n\\to S_{n-1}$ is a natural transformation.\n\nLet $G$ be a group viewed as a one-point category. Any element $F\\in\\mathrm{Fun}(G,\\mathbf{Ab})$ is simply a group action of $G$ on $F(\\ast)=A$, i.e., a representation of $G$ in abelian groups. Given another $F^\\prime\\in\\mathrm{Fun}(G,\\mathbf{Ab})$ with $F^\\prime(\\ast)=A^\\prime$, then a natural transformation from $F\\to F^\\prime$ is precisely a $G$-equivariant map $A\\to A^\\prime$.\n\\end{example}\n", "meta": {"hexsha": "bd64a180ada46191cb4527de81e2e264c917929f", "size": 5072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-3-categories.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-3-categories.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-3-categories.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 84.5333333333, "max_line_length": 471, "alphanum_fraction": 0.7298895899, "num_tokens": 1493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6681402451843365}}
{"text": "\\section{Calculation of structure factor and Ewald energy: first version}\n\nStructure factor\n\n\\begin{juliacode}\n# Calculate structure factor\n# special case: only for 1 species with Z = 1\nfunction structure_factor( Xpos::Array{Float64,2}, G::Array{Float64,2} )\n  Ng = size(G)[2]\n  Na = size(Xpos)[2]\n  Sf = zeros(Complex128,Ng)\n  for ia = 1:Na\n    for ig = 1:Ng\n      GX = Xpos[1,ia]*G[1,ig] +\n           Xpos[2,ia]*G[2,ig] +\n           Xpos[3,ia]*G[3,ig]\n      Sf[ig] = Sf[ig] + cos(GX) - im*sin(GX)\n    end\n  end\n  return Sf\nend\n\\end{juliacode}\n\nA simple method to calculate Ewald energy\n\n\\begin{juliacode}\nfunction calc_ewald( pw::PWGrid, Xpos, Sf; sigma=0.25 )\n  #\n  const Npoints = pw.Npoints\n  const Ω  = pw.Ω\n  const r  = pw.r\n  const Ns = pw.Ns\n  const G2 = pw.G2\n  #\n  # Generate array of distances\n  center = sum(pw.LatVecs,2)/2\n  dr = gen_dr( r, center )\n  #\n  # Generate charge density\n  rho = gen_rho( Ns, dr, sigma, Sf )\n  intrho = sum(rho)*Ω/Npoints\n  #\n  # Solve Poisson equation and calculate Hartree energy\n  ctmp = 4.0*pi*R_to_G( Ns, rho )\n  ctmp[1] = 0.0\n  for ip = 2:Npoints\n    ctmp[ip] = ctmp[ip] / G2[ip]\n  end\n  phi = real( G_to_R( Ns, ctmp ) )\n  Ehartree = 0.5*dot( phi, rho ) * Ω/Npoints\n  #\n  Eself = 1.0/(2*sqrt(pi))*(1.0/sigma)*size(Xpos,2)\n  return Ehartree - Eself\nend\n\\end{juliacode}\n", "meta": {"hexsha": "14ee8aac534360fb75484d450d8a1bf97562a7c2", "size": 1315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PW/Doc/ewald_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/ewald_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/ewald_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": 23.4821428571, "max_line_length": 73, "alphanum_fraction": 0.6258555133, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6679804919158037}}
{"text": "\\newpage\n\\section{Boltzmann Machines and RBMs}\n\n\\subsection{Before BMs\\cite{rojas1996hopfield, hopfield, coursera_nn}}\n\n\\subsubsection{General RNNs}\nIn early 1980-x general \\textbf{recurrent neural networks} (RNNs), described by (general) \\emph{asyclic} graph began to arise.\n\\begin{itemize}\n\\item     mostly binary units, $\\{0, 1\\}$ (or $\\{-1, 1\\}$);\n\\gooditem signal feedback $\\Rightarrow$ \\textbf{memory} compared to FF NNs (more specifically, \\emph{content-addressable memory} (CAM) $\\Leftrightarrow$ weights themselves are used to store patterns);\n\\baditem  in general if activations are non-linear function they are hard to train (oscillations and chaotic behavior).\n\\end{itemize}\n\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.4]{img/general_rnn.png}\n\\centering\n\\caption{Example architecture of RNN}\n\\label{fig:general_rnn}\n\\end{mdframed}\n\\end{figure}\n\n\\vspace{1em}\n\\subsubsection{Hopfield Nets}\nLater in $\\approx$1982 John Hopfield has shown that if RNN has symmetric weights ($W_{ij}=W_{ji}$), and has no self-loops ($W_{ii}=0$), network's dynamics \\textbf{is guaranteed} to converge to some stationary state. Fully-connected variant (complete graph) of such a network is called a \\emph{Hopfield Network}.\n\nMoreover, he also shown that each state of the Hopfield Net is associated with a scalar value referred to as the \\emph{energy} of the network ($s_{i}\\in\\{-1, 1\\}$ -- state of i-th neuron, $b_{i}$ -- bias of i-th neuron ($-b_{i}$ is activation threshold for the unit)):\n\\begin{align}\nE = -\\frac{1}{2}\\sum_{i,j}W_{ij}s_is_j-\\sum_{i}b_is_i=\\commenttwo{$W_{ij}=W_{ji}$,}{$W_{ii}=0$} = -\\sum_{i<j}W_{ij}s_is_j-\\sum_{i}b_is_i\n\\end{align}\nand local minima of $E(\\mathbf{s};\\mathbf{W}, \\mathbf{b})\\;\\Leftrightarrow\\;$ stable configurations of network. It is the first example of so-called \\textbf{energy-based model}. Learning algorithm for such a model alter its (global) energy function to achieve desired properties. For instance, if a Hopfield Net is trained as autoassociator, the goal of learning is to shape energy function in such a way, that its local minima correspond to training examples (= patterns to \"remember\").\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.2]{img/energy_landscape.png}\n\\centering\n\\caption{Energy Landscape of a Hopfield Network, highlighting the current state of the network (up the hill), an attractor state to which it will eventually converge, a minimum energy level and a basin of attraction shaded in green. Note how the update of the Hopfield Network is always going down in Energy.}\n\\label{fig:energy_landscape}\n\\end{mdframed}\n\\end{figure}\n\n\\vspace{1em}\n\\subsubsection{Learning algorithms for Hopfield Nets}\nThere are exist couple of learning algorithms for Hopfield Nets.\nFirst, thanks to simple quadratic shape of $E$, it is straightforward to calculate how i-th neuron influences the global energy:\n\\begin{gather*}\n\\Delta E_i = E(\\mathbf{s}|s_i=\\text{off}) - E(\\mathbf{s}|s_i=\\text{on}) = E(\\mathbf{s}|s_i=0) - E(\\mathbf{s}|s_i=1) =\\\\= -\\sum_{k<j}W_{kj}s_ks_j\\evalat{s_i=0} -\\sum_{j}b_js_j\\evalat{s_i=0}  + \\sum_{k<j}W_{kj}s_ks_j\\evalat{s_i=1} + \\sum_{j}b_js_j\\evalat{s_i=1} =\\\\=\n\\underbrace{-\\l( \\sum_{k<j, k \\neq i, j \\neq i}W_{kj}s_ks_j + \\sum_{j \\neq i}b_js_j \\r) + \\l( \\sum_{k<j, k \\neq i, j \\neq i}W_{kj}s_ks_j + \\sum_{j \\neq i}b_js_j \\r)}_{=0} +\n\\underbrace{\\sum_{j<i}W_{ji}s_j}_{k=i} + \\underbrace{\\sum_{i<k}W_{ik}s_k}_{j=i} + b_i =\\\\= \\comment{$W_{ij}=W_{ji}$, $W_{jj}=0$} = \\sum_jW_{ij}s_is_j + b_i\n\\end{gather*}\nThis lead to the learning algorithm called \\textbf{Binary Threshold Decision Rule} (BTDR):\n\\begin{itemize}\n\\item Randomly initialize states (or to desired pattern if want CAM);\n\\item While not converged or for fixed number of iterations:\n\t\\subitem For each neuron:\n\t\t\\subsubitem Change its state if this will decrease global energy. More specifically:\n\t\t $$\n\t\t s_i \\leftarrow\n\t\t \\begin{cases}\n\t\t +1,  \\;\\;\\Delta E_i > 0,\\\\\n\t\t s_i, \\;\\;\\Delta E_i = 0,\\\\\n\t\t -1,  \\;\\;\\Delta E_i < 0.\\\\\n\t\t \\end{cases}\n\t\t $$\n\\end{itemize}\nThis learning algorithm is \\emph{local} and \\emph{incremental}, thus biologically plausible. Also neurons could have been updated simultaneously, but it is less likely that there is exists \"global clock\" in biological system, and such kind of updates can also cause oscillation or chaotic behavior.\n\nOne important \\underline{drawback} of such an algorithm, is that once we stuck in poor local minimum, we cannot escape it, it is also one of the reasons why Boltzmann Machines was more successful.\n\n\\vspace{2em}\nAnother learning algorithm is based on famous \\textbf{Hebb rule}: \"Cells that fire together, wire together\". In the simplest case it simply says:\n\\begin{gather}\nW_{ij} \\leftarrow x_ix_j,\n\\end{gather}\nwhere $\\mathbf{x}=\\{x_1 \\ldots x_N\\}$ is binary input pattern. If $x_i$ and $x_j$ are the same, then $W_{ij}$ is positive thus i-th and j-th state tend to become equal. Opposite happens when $x_i$ and $x_j$ are different. Now one can show that network's dynamics will be the same if\n\\begin{gather}\nW_{ij} \\leftarrow \\frac{1}{N}x_ix_j\n\\end{gather}\nIf we need to remember not 1 but $P$ patterns, sum corresponding update for each pattern (for each pattern pretend there are no others):\t\t\n\\begin{gather}\nW_{ij} \\leftarrow \\frac{1}{N}\\sum_{p=1}^Px_i^{(p)}x_j^{(p)}\n\\end{gather}\nThis way network will act as CAM, see Fig. \\ref{fig:hopfield}. The network will converge to a \"remembered\" state if it is given only part of the state $\\Rightarrow$ can be used to recover from a distorted input to the trained state that is most similar to the input.\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.4]{img/hopfield.png}\n\\centering\n\\caption{A Hopfield network as an autoassociator. One enters a pattern in\nblue nodes and let the network evolve. After a while one reads out the yellow\nnodes. The memory of the Hopfield network associates the yellow node pattern\nwith the blue node pattern.}\n\\label{fig:hopfield}\n\\end{mdframed}\n\\end{figure}\n\n\\vspace{1em}\nFor instance, train Hopfield net such that $(1, -1, 1, -1, 1)$ is a local minimum of $E$ (phase 1 -- memorization). Next, if the network is properly trained, it can recover $(1, -1, 1, -1, 1)$ from $(1, -1, \\mathbf{-1}, -1, 1)$ input (phase 2 -- recognition). Hopfield nets can be used for denoising of simple fonts.\t\n\n\\vspace{1em}\nMany generalizations of this rule exist, but fundamentally Hopfield nets had quite some drawbacks (even for binary data):\n\\begin{itemize}\n\\baditem patterns are stored in the network itself, thus can be intractable for large $N$;\n\\baditem capacity, one can reliably store only $P << N$ patterns;\n\\baditem spurious minima, poor local minima;\n\\baditem no probabilistic interpretation.\n\\end{itemize}\nBut anyway Hopfield Nets and energy-based models played a big role in development of deep learning and now we proceed to the one of the most famous modification of Hopfield Net -- Boltzmann Machine.\n\n\\subsection{Boltzmann Machines\\cite{coursera_nn, aarts1988simulated, fischer2012introduction, tutorial2014lisa}}\n\\subsubsection{Main ideas}\nBoltzmann Machine (developed $\\approx$1980-85 by G. Hinton) is a \\emph{stochastic}, \\emph{generative} counter-part of Hopfield Nets. From PGM point of view, it is an example of MRF (undirected graphical model). It is also an example of Ising model.\n\\\\[1em]\nTwo main ideas:\n\\begin{enumerate}\n\\item Instead of storing \"memories\" in stable configurations of Hopfield net, use them for \"interpretation\" of the input data. Thus, all units are divided into 2 groups: \\emph{visible} and \\emph{hidden} (see Fig. \\ref{fig:bm}).\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.4]{img/bm.png}\n\\centering\n\\caption{A graphical representation of an example Boltzmann machine. Each undirected edge represents dependency. In this example there are 3 hidden units and 4 visible units. This is not a restricted Boltzmann machine.}\n\\label{fig:bm}\n\\end{mdframed}\n\\end{figure}\n\n\\item To escape local minima, assume units are \\emph{Gibbs distibuted} with the same energy function (1) and use more advanced learning algorithms (see below).\n\\end{enumerate}\n\n\\subsubsection{Historical development and informal explanation}\nInspired from statistical physics, assume that units' states are Gibbs distributed (= Boltzmann distributed) random variables for global energy (1) $\\;\\Rightarrow\\;$ energy of the state is proportional to the negative log-probability of that state and also the following identity holds:\n\\begin{gather}\n\\Delta E_i = E(\\mathbf{s}|s_i=0) - E(\\mathbf{s}|s_i=1) \\;\\propto\\; -k_BT\\log p\\{s_i=0\\}+k_BT\\log p\\{s_i=1\\},\n\\end{gather}\nBy absorbing Boltzmann's constant $k_B$ into introduced notion of (artificial) temperature $T$ ($T\\leftarrow k_BT$) ($\\Leftrightarrow$ by considering \\emph{dimensionless} units where $k_B=1$) , we can rearrange equation (5) and solve for $ p\\{s_i=1\\}$. We will obtain so-called \\emph{normal logistic equation}:\n\\begin{gather}\n p\\{s_i=1\\}=\\frac{1}{1+\\exp\\l(-\\frac{\\Delta E_i}{T}\\r)}=\\text{sigm}\\l(-\\frac{\\Delta E_i}{T}\\r)\n\\end{gather} \nWe obtained a \\textbf{Modified BTDR}:\n\\begin{itemize}\n\\item Randomly initialize states;\n\\item In cycle for each unit if its state reversal will yield energy decrease, reverse its state with probability described by (6).\n\\end{itemize}\nAfter running for long enough time at certain $T$, it turns out that probability of a global state of network will \\emph{depend only upon global state's energy}, and not on the initial state (in accordance with Boltzmann distribution). \n\\\\$\\Rightarrow$ Distribution of all possible configurations (global states) converges to same \\emph{stationary distribution} (this state in physics is called thermal equilibrium). Note that being in thermal equilibrium, system does not necessary is in the state of the lowest energy, which still might be oscillating, \\textbf{but} if we start running the network from a high temperature, and gradually decrease it over time until we reach a thermal equilibrium at low $T$, we may converge to a distribution where the energy level fluctuates around the global minimum (at least this can happen with higher probability than in Hopfield Nets). \n\\\\This process is called \\textbf{simulated annealing}. Yes, it seems like development of BMs gave fundament to one of the most famous and successful algorithms of global optimization.\n\\\\[1em]\nNow if we want to train the network so that the chance it will converge to a global state is according to an external distribution (e.g. data) that we have over these states, we need to \\emph{set the weights} so that the global states with the highest probabilities will get the lowest energies. By altering parameters we can shape the distribution produced by BM using (6), it is the main idea of Boltzmann machine.\n\\\\[1em]\nBM is interpreted in the following way. Visible units provide open interface to the world and represent data. Hidden units represent hidden patterns in the data. Usually it is trained by using maximum likelihood estimation using approximate (why see below) gradient ascent. It is also equivalent \\cite{goodfellow2016deep} to minimizing KL-divergence between external distribution (which is usually empirical data distribution) and model distribution produced by the network.\n\n\\subsubsection{More formal derivations}\n\\u{Notations}:\n\\\\$\\mathbf{v}\\in\\{0,1\\}^D=\\{0,1\\}^V$ -- vector of visible units,\n\\\\$\\mathbf{h}\\in\\{0,1\\}^H$ -- vector of hidden units,\n\nEnergy of a particular state $(\\mathbf{v},\\mathbf{h})$ is:\n\\begin{gather}\nE(\\mathbf{v},\\mathbf{h};\\bs{\\psi})=-\\frac{1}{2}\\mb{v}^T\\mb{L}\\mb{v}-\\frac{1}{2}\\mb{h}^T\\mb{J}\\mb{h}-\\mb{v}^T\\mb{W}\\mb{h}-\\mb{b}^T\\mb{v}-\\mb{c}^T\\mb{h},\n\\end{gather}\nit is nothing else but (1) with old $\\mb{W}$ split into $\\mb{L}$ describing vis-vis weights, $\\mb{J}$ describing hid-hid weights, and new $\\mb{W}$ describing vis-hid connections, and the same for biases. The reason is to keep notations consistent with later parts where we will get rid of $\\mb{L}$ and $\\mb{J}$. Of course, $\\mb{L}$ and $\\mb{J}$ are symmetric with zeros on the main diagonal. $\\bs{\\psi}=\\{\\mb{L},\\mb{J},\\mb{W},\\mb{b},\\mb{c}\\}$ are model parameters.\n\nProbability of the configuration $(\\mb{v},\\mb{h})$ is (according to the Boltzmann distribution):\n\\begin{gather}\np(\\mathbf{v},\\mathbf{h};\\bs{\\psi})=\\frac{e^{-E(\\mathbf{v},\\mathbf{h};\\bs{\\psi})}}{\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}} e^{-E(\\mathbf{\\t{v}},\\mathbf{\\t{h}};\\bs{\\psi})} }=:\\frac{p^*(\\mb{v},\\mb{h}; \\bs{\\psi})}{Z(\\bs{\\psi})},\n\\end{gather}\nwhere $p^*(\\mb{v},\\mb{h}; \\bs{\\psi})$ is unnormalized probability of the configuration and $Z(\\bs{\\psi})$ is a normalizer also called \\emph{partition function}.\n\\\\$\\Rightarrow$\n\\\\Probability that model assigns to a visible vector $\\mb{v}$ is\n\\begin{gather}\np(\\mb{v};\\bs{\\psi})=\\sum_{\\mb{h}}p(\\mathbf{v},\\mathbf{h};\\bs{\\psi})=:\\frac{e^{-\\mathcal{F}(\\mb{v};\\bs{\\psi})}}{\\sum_{\\mb{\\t{v}}} e^{-\\mathcal{F}(\\mb{\\t{v}};\\bs{\\psi})} },\n\\end{gather}\nwhere\n\\begin{gather}\n\\mc{F}(\\mb{v};\\bs{\\psi})=-\\log\\l( \\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})} \\r)\n\\end{gather}\nis called \\emph{free energy} (\\emph{free} because all the hidden states are marginalized out; the name is inspired again from physics), useful quantity which will be used later.\n\\\\[1em]\n\\u{Now lets calculate} $p(v_i=1|\\mb{h},\\mb{v}_{-i})$: (omit $\\bs{\\psi}$ for brevity)\n\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\np(v_i=1|\\mb{h},\\mb{v}_{-i})=\\frac{p(v_i=1,\\mb{v}_{-i},\\mb{h})}{p(\\mb{v}_{-i},\\mb{h})}=\n\\frac{p(v_i=1,\\mb{v}_{-i},\\mb{h})}{p(v_i=0,\\mb{v}_{-i},\\mb{h})+p(v_i=1,\\mb{v}_{-i},\\mb{h})}\n\\\\=\\frac{e^{-E(v_i=1,\\mb{v}_{-i},\\mb{h})}}{e^{-E(v_i=0,\\mb{v}_{-i},\\mb{h})} + e^{-E(v_i=1,\\mb{v}_{-i},\\mb{h})}}=\\frac{1}{1+e^{-\\l[E(v_i=0,\\ldots)-E(v_i=1,\\ldots)\\r]}}=\\text{sigm}\\l[E(v_i=0,\\ldots)-E(v_i=1,\\ldots)\\r]=\n\\\\=\\comment{$E(\\mb{v},\\mb{h})=-\\sum_{j<k}L_{jk}v_jv_k -\\sum_{l<m}J_{lm}h_lh_m -\\sum_{j,l}W_{jl}v_jh_l-\\sum_jb_jv_j-\\sum_lc_lh_l $}=\n\\\\=\\comment{sums w/o $v_i$ (2nd, 5th) cancel out}=\\text{sigm}\\l[\\underbrace{-\\ldots+\\sum_{j<k,j\\neq i, k\\neq i}L_{jk}v_jv_k}_{=0}+\\underbrace{\\sum_{i<k}L_{ik}v_k}_{j=i}+ \\underbrace{\\sum_{j<i}L_{ji}v_j}_{k=i} -\\r.\\\\\\l.\\underbrace{-\\ldots+\\sum_{j\\neq i, l}W_{jl}v_jh_l}_{=0}+  \\underbrace{\\sum_lW_{il}h_l}_{j=i}+b_i\\r]=\\comment{$L_{ij}=L_{ji}, L_{ii}=0$}=\\text{sigm}\\l[ \\sum_lW_{il}h_l+\\sum_kL_{ik}v_k+b_i \\r]\n\\end{empheq}\t\nSo:\n\\begin{gather}\n\\boxed{p(v_i=1|\\mb{h},\\mb{v}_{-i})=\\text{sigm}\\l( \\sum_kL_{ik}v_k+\\sum_lW_{il}h_l+b_i \\r)}\n\\end{gather}\n\\u{Symmetrically},\n\\begin{gather}\n\\boxed{p(h_j=1|\\mb{v},\\mb{h}_{-j})=\\text{sigm}\\l( \\sum_lJ_{jl}h_l+\\sum_iW_{ij}v_i+c_j \\r)}\n\\end{gather}\n\\\\[1em]\n\\u{Maximum Likelihood learning}\n\\\\Suppose we have dataset $\\mc{D}=\\{\\mb{x}_1,\\ldots\\mb{x}_N\\}, \\mb{x}_n\\in\\{0,1\\}^D$. The goal is to maximize $\\sum_{n=1}^N\\log p(\\mb{x}_n;\\bs{\\psi})$ for parameters $\\bs{\\psi}$. For a single training example $\\mb{v}$ and any parameter $\\theta$:\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\n\\frac{\\partial}{\\partial\\theta}\\log p(\\mb{v};\\bs{\\psi})=\n\\frac{\\partial}{\\partial\\theta}\\l(\\log \\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})}-\n\\log\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}}e^{-E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})} \\r)=\n\\\\=-\\frac{1}{\\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})}}\\sum_{\\mb{h}}\\l[e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})} \\cdot \\frac{\\partial}{\\partial\\theta}E(\\mb{v},\\mb{h};\\bs{\\psi}) \\r]+\n\\frac{1}{\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}}e^{-E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})}}\n\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}}\\l[e^{-E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})}\\cdot \\frac{\\partial}{\\partial\\theta} E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi}) \\r]=\n\\\\=\\comment{$\\frac{e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})}}{\\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})}}=\\frac{\\frac{1}{Z(\\theta)}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})}}{\\frac{1}{Z(\\theta)}\\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})}}=\\frac{p(\\mb{h},\\mb{v};\\bs{\\psi})}{p(\\mb{v};\\bs{\\psi})}=p(\\mb{h}|\\mb{v};\\bs{\\psi})$}=\n\\\\=-\\underbrace{\\sum_{\\mb{h}}p(\\mb{h}|\\mb{v};\\bs{\\psi})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{v},\\mb{h};\\bs{\\psi})}_{\\E_{\\mb{h}|\\mb{v};\\bs{\\psi}}\\l[\\frac{\\partial}{\\partial\\theta}E(\\mb{v},\\mb{h};\\bs{\\psi})\\r]}\n+\\underbrace{\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}}p(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})}_{\\E_{\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi}}\\l[\\frac{\\partial}{\\partial\\theta}E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})\\r]}\n\\end{empheq}\nThis we obtain\n\\begin{gather}\n\\boxed{\\frac{\\partial}{\\partial\\theta}\\log p(\\mb{v};\\bs{\\psi})=-\\E_{\\mb{h}|\\mb{v};\\bs{\\psi}}\\l[\\frac{\\partial E}{\\partial\\theta}(\\mb{v},\\mb{h};\\bs{\\psi})\\r]+\\E_{\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi}}\\l[\\frac{\\partial E}{\\partial\\theta}(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})\\r]}\n\\end{gather}\nAnd avegared over all data points:\n\\begin{gather}\n\\frac{1}{N}\\sum_{n=1}^N \\frac{\\partial}{\\partial\\theta} \\log p(\\mb{x}_n;\\bs{\\psi})=-\\frac{1}{N}\\sum_{n=1}^N \\E_{\\mb{h}|\\mb{v};\\bs{\\psi}}\\l[\\frac{\\partial E}{\\partial\\theta}(\\mb{x}_n,\\mb{h};\\bs{\\psi})\\r] + \\E_{\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi}}\\l[\\frac{\\partial E}{\\partial\\theta}(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})\\r]\n\\end{gather}\nor solely in terms of expectations:\n\\begin{gather}\n\\boxed{\\E_{\\mb{v}\\sim P_{\\text{data}}(\\mb{v})}\\l[ \\frac{\\partial}{\\partial\\theta}\\log p(\\mb{v};\\bs{\\psi}) \\r]=-\\E_{\\mb{v},\\mb{h}\\sim P_{\\text{data}}(\\mb{v},\\mb{h};\\bs{\\psi})}\\l[ \\frac{\\partial E}{\\partial\\theta}(\\mb{v},\\mb{h};\\bs{\\psi}) \\r] + \\E_{\\mb{v},\\mb{h}\\sim P_{\\text{model}}(\\mb{v},\\mb{h};\\bs{\\psi})}\\l[ \\frac{\\partial E}{\\partial\\theta}(\\mb{v},\\mb{h};\\bs{\\psi}) \\r]}\n\\end{gather}\nwhere $P_{\\text{data}}(\\mb{v})=\\frac{1}{N}\\sum_{n=1}^N \\delta_{\\mb{v},\\mb{x}_n}$ is \\emph{empirical distribution}, $P_{\\text{data}}(\\mb{v},\\mb{h};\\bs{\\psi})=p(\\mb{h}|\\mb{v};\\bs{\\psi})P_{\\text{data}}(\\mb{v})$ is \\emph{complete-data distribution} and $P_{\\text{model}}$ is a distribution modelled by BM.\n\\\\[1em]\nBefore we move on, there is one more equivalent form of gradient of data log-likelihood:\n\\begin{gather}\n-\\frac{\\partial}{\\partial\\theta}\\log p(\\mb{v};\\bs{\\psi})=\\frac{\\partial}{\\partial\\theta}\\mc{F}(\\mb{v})-\\sum_{\\mb{\\t{v}}}p(\\mb{\\t{v}})\\frac{\\partial}{\\partial\\theta}\\mc{F}(\\mb{\\t{v}})\n\\end{gather}\nNotice that the above gradient contains two terms, which are referred to as the \\textbf{positive} and \\textbf{negative} phase. The terms positive and negative do not refer to the sign of each term in the equation, but rather reflect their effect on the probability density defined by the model. The first term increases the probability of training data (by reducing the corresponding free energy), while the second term decreases the probability of samples generated by the model.\n\\\\[1em]\n\\u{Derivatives of the energy w.r.t. model parameters}:\n$$\nE(\\mathbf{v},\\mathbf{h};\\bs{\\psi})=-\\frac{1}{2}\\mb{v}^T\\mb{L}\\mb{v}-\\frac{1}{2}\\mb{h}^T\\mb{J}\\mb{h}-\\mb{v}^T\\mb{W}\\mb{h}-\\mb{b}^T\\mb{v}-\\mb{c}^T\\mb{h},\n$$\n\\begin{itemize}\n\\item $\\frac{\\partial E}{\\partial \\mb{L}}=-\\mb{v}\\mb{v}^T$ (remember that $\\mb{L}$ is symmetric)\n\\item Similarly $\\frac{\\partial E}{\\partial \\mb{J}}=-\\mb{h}\\mb{h}^T$ and $\\frac{\\partial E}{\\partial \\mb{W}}=-\\mb{v}\\mb{h}^T$\n\\item Finally $\\frac{\\partial E}{\\partial \\mb{b}}=-\\mb{v}$ and $\\frac{\\partial E}{\\partial \\mb{c}}=-\\mb{h}$\n\\end{itemize}\nSo 1 update of the weights $\\mb{W}$ using vanilla gradient ascent looks like:\n\\begin{align}\n\\mb{g}_{\\mb{W}} &\\;\\leftarrow\\; \\E_{\\mb{v},\\mb{h}\\sim P_{\\text{data}}(\\mb{v},\\mb{h};\\bs{\\psi})}\\l[\\mb{v}\\mb{h}^T\\r]-\\E_{\\mb{v},\\mb{h}\\sim P_{\\text{model}}(\\mb{v},\\mb{h};\\bs{\\psi})}\\l[\\mb{v}\\mb{h}^T\\r]\n\\\\ \n\\mb{W} &\\;\\leftarrow\\; \\mb{W} + \\alpha\\cdot\\mb{g}_{\\mb{W}}\n\\end{align}\nand similarly for other parameters.\n\\\\[1em]\n\\u{Problems}\n\\\\\nSo far it seems like everything is ok, but there is 1 very serious problem, \\textbf{both expectations in (13) $\\Leftrightarrow$ (15) are simply intractable}. First sum has $O\\l(2^H\\r)$ terms while the second one has $O\\l(2^{V+H}\\r)$ terms. Moreover, even $p(\\mb{h}|\\mb{v};\\bs{\\psi})$ or $p(\\mb{v},\\mb{h};\\bs{\\psi})$ are intractable because of partition function in denominators which itself has exponentially many in $V+H$ terms.\n\\\\[1em]To overcome this computational burden, G. Hinton and T. Sejnowski in 1983 proposed algorithm that uses Gibbs sampling to approximate both expectations. The idea is that both expectations are approximated by states of 2 Markov chains (Monte-Carlo sampling), which are updated using Gibbs sampling $\\forall$ training example during training.\n\\\\[1em]The main problem with the last algorithm is \\tb{time} required to approach distribution, especially when estimating the model's expectations, since the Gibbs chain may need to explore a highly multimodal energy landscape + exponential in machine size and magnitude of weights time to collect equilibrium statistics. We will see that in RBM Gibbs sampling can be performed much more efficiently thus having much more efficient learning algorithm.\n\\\\[1em]\nTo summarize, Boltzmann Machines is a Monte Carlo version of Hopfield Net with discrimination between visible and hidden units and that uses annealed Gibbs sampling. Boltzmann Machines were one of the first neural networks capable of learning internal representations, and are able to represent and (given sufficient time) solve difficult combinatoric problems + they are again are considered a biologically plausiable because during learning only local information is used, i.e. the update for a particular weight connecting two units depend only on the statistics of those two units (this can be seen by considering equation (17) element-wisely).\n\\subsubsection{Additional facts}\n\\textbullet{} from formulae (11),(12) we can see that probability of one unit being on is given by a linear model (logistic regression) from the values of the other units.\n\\\\\n\\textbullet{} in the presence of hidden units, BM becomes a \\emph{universal approximator} in a sense that it can learn arbitraty point mass function over discrete variables (without hidden units it could have learned only linear relationships between variables) \\cite{goodfellow2016deep}\n\\\\\n\\textbullet{} it is also interesting that in this model we can compute $p(\\mb{h}|\\mb{v};\\bs{\\psi})$ exactly and efficiently, unlike many other models with hidden variables like VAE etc., and still this model can learn fairly complex distributions (+ previous bullet)\n\n\\subsection{Restricted Boltzmann Machines\\cite{coursera_nn, fischer2012introduction, tutorial2014lisa, hinton2010practical, fischer2014training, smolensky1986information, gibbs_wiki}}\n\\subsubsection{Intro and comparison with general BM}\nA \\emph{restricted Boltzmann machine} was invented by P. Smolensky in 1986 and is characterized by absense of hid-hid and vis-vis connections (see Fig. \\ref{fig:rbm}).\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.5]{img/rbm.png}\n\\centering\n\\caption{Diagram of a restricted Boltzmann machine with four visible units and three hidden units (no bias units).}\n\\label{fig:rbm}\n\\end{mdframed}\n\\end{figure}\nIn this case we have $\\mb{L}=\\mb{J}=\\mb{0}$ and the energy function for RBM simplifies:\n\\bg\nE(\\mathbf{v},\\mathbf{h};\\bs{\\psi})=-\\mb{v}^T\\mb{W}\\mb{h}-\\mb{b}^T\\mb{v}-\\mb{c}^T\\mb{h}\n\\eg\nBecause of the \\emph{bipartite} structure of the graph, in this MRF \\tb{all hidden units are conditionally independent given visible ones and vice versa} ($\\bs{\\psi}$ is omitted for brevity):\n\\bg\np(\\mb{h}|\\mb{v})=\\prod_jp(h_j|\\mb{v}), \\;\\;\\; p(\\mb{v}|\\mb{h})=\\prod_ip(v_i|\\mb{h})\n\\eg\n(Formally every path in this graphical model between different $h_j$ and $h_l$ is blocked by $\\mb{v}$ and vice versa).\n\\\\[1em]\nTaking this into account, formulae (11) and (12) simplify too:\n\\bg\np(v_i=1|\\mb{h})=\\text{sigm}\\l( \\sum_lW_{il}h_l+b_i \\r),\n\\\\\np(h_j=1|\\mb{v})=\\text{sigm}\\l( \\sum_iW_{ij}v_i+c_j \\r)\t\n\\eg\nvery important that each of these formulae can be computed \\tb{in parallel}:\n\\bg\np(\\mb{v}=\\mb{1}|\\mb{h})=\\text{sigm}\\l( \\mb{W}\\mb{h}+\\mb{b} \\r),\n\\\\\np(\\mb{h}=\\mb{1}|\\mb{v})=\\text{sigm}\\l( \\mb{W}^T\\mb{v}+\\mb{c} \\r)\t\n\\eg\nthis makes exact inference tractable (as opposed to general BM).\n\\\\[1em]\nIt is also easier to calculate marginalized distribution of the visible variables (see Fig. \\ref{fig:prod_experts})\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.4]{formulae/prod_experts.png}\n\\centering\n\\caption{$p(\\mb{v})$}\n\\label{fig:prod_experts}\n\\end{mdframed}\n\\end{figure}\n\\\\[1em]\n\\u{Gradient of Log-Likelihood}\n\\\\Recall\n$$\n\\frac{\\partial}{\\partial\\theta}\\log p(\\mb{v};\\bs{\\psi})=\n-\\sum_{\\mb{h}}p(\\mb{h}|\\mb{v};\\bs{\\psi})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{v},\\mb{h};\\bs{\\psi})\n+\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}}p(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{\\t{v}},\\mb{\\t{h}};\\bs{\\psi})\n$$\nFirst term for $\\theta=W_{ij}$ (omit $\\bs{\\psi}$):\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\n[1]=-\\sum_{\\mb{h}} \\prod_kp(h_k|\\mb{v}) \\cdot\\frac{\\partial}{\\partial W_{ij}}E(\\mb{v},\\mb{h})=\\comment{$\\frac{\\partial}{\\partial W_{ij}}E(\\mb{v},\\mb{h})=-v_ih_j$}=\\sum_{\\mb{h}} \\prod_kp(h_k|\\mb{v})v_ih_j=\n\\\\=\\sum_{h_j}\\sum_{\\mb{h}_{-j}}p(h_j|\\mb{v})p(\\mb{h}_{-j}|\\mb{v})h_jv_i=\n\\sum_{h_j\\in\\{0,1\\}}h_jp(h_j|\\mb{v})v_i \\underbrace{\\sum_{\\mb{h}_{-j}}p(\\mb{h}_{-j}|\\mb{v})}_{=1}=p(h_j=1|\\mb{v})\\cdot v_i\n\\end{empheq}\nThe second term\n$$\n[2]=\\sum_{\\mb{\\t{v}},\\mb{\\t{h}}}p(\\mb{\\t{v}},\\mb{\\t{h}})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{\\t{v}},\\mb{\\t{h}})=\\sum_{\\mb{\\t{v}}}p(\\mb{\\t{v}})\\l(\\sum_{\\mb{\\t{h}}}p(\\mb{\\t{h}}|\\mb{\\t{v}})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{\\t{v}},\\mb{\\t{h}})\\r)\n$$\nand thus can be computed in the same manner.\n\\\\Eventually we obtain the following expressions for log-likelihood gradients:\n\\begin{align}\n\\frac{\\partial}{\\partial W_{ij}}\\log p(\\mb{v};\\bs{\\psi}) &= p(h_j=1|\\mb{v})\\cdot v_i\n-\\sum_{\\mb{\\t{v}}}p(\\mb{\\t{v}})\\cdot p(h_j=1|\\mb{\\t{v}})\\cdot \\t{v}_i\n\\\\\n\\frac{\\partial}{\\partial b_{i}}\\log p(\\mb{v};\\bs{\\psi}) &= v_i -\\sum_{\\mb{\\t{v}}}p(\\mb{\\t{v}}) \\cdot \\t{v}_i\n\\\\\n\\frac{\\partial}{\\partial c_{j}}\\log p(\\mb{v};\\bs{\\psi}) &= p(h_j=1|\\mb{v}) - \\sum_{\\mb{\\t{v}}}p(\\mb{\\t{v}}) \\cdot p(h_j=1|\\mb{\\t{v}})\n\\end{align}\n+ use formulae (21), (22). Averaged over all training examples, these formulae can also be rewritten in terms of expectations. Note that $\\sum_{\\mb{\\t{v}}} p(\\mb{\\t{v}})[\\cdots]=\\E_{\\mb{\\t{v}}\\sim P_{\\text{\\text{model}}}}[\\cdots]$.\n\\\\[1em]\nDespite of the sound simplification and reducing of computational complexity because of the nice factorization, (25) - (27) are still intractable for regular RBMs because of the second terms which are exponential in $\\min\\{V, H\\}$ (if $H<V$ we can factorize $p(\\mb{v},\\mb{h})=p(\\mb{h})p(\\mb{v}|\\mb{h})$).\n\\\\[1em]Thus, to avoid this complexity, we will approximate expectations by samples from the model distribution using MCMC-based algorithm \\emph{Contrastive Divergence} (described below).\n\\\\[1em]\n\\u{Quick summary}\n\\begin{center}\n\\begin{tabular}{ |c|c|c| } \n\\hline\n& \\tb{general BM} & \\tb{RBM} \\\\\n\\hline\n\\tb{exact Maximum Likelihood learning} & \\color{red}intractable & intractable$^{*}$ \\\\\n\\hline\n\\tb{inference} & \\color{red}approximate & \\color{green}exact \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n$^{*}$ -- learning still can be done efficiently using Contrastive Divergence.\n\n\\subsubsection{Contrastive Divergence algorithm and modifications}\nAll common training algorithms for RBMs approximate expectations in log-likelihood gradients (25) - (27) by only single sample from RBM and perform gradient ascent on these approximations. \n\\\\[1em]\nSamples in RBM can be obtained by running a Markov chain to convergence, using Gibbs sampling as the transition operator. \nIn general, Gibbs sampling of the joint of $N$ random variables $\\bs{\\xi}=(\\xi_1\\ldots\\xi_N)$ is done through a sequence of $N$ sampling sub-steps of the form $\\xi_i\\sim p(\\xi_i|\\bs{\\xi}_{-i})$. If done sequentially, one can show that these sub-steps define reversible Markov chain with desired invariant joint distribution.\n\\\\[1em]\nFor RBMs, $\\xi$ consists of the set of visible and hidden units. However, since they are conditionally independent, $p(v_i|\\mb{h},\\mb{v}_{-i})=p(v_i|\\mb{h})$ and $p(h_j|\\mb{v},\\mb{h}_{-j})=p(h_j|\\mb{v})$ one can perform \\tb{block} Gibbs sampling (which is impossible in BM). In this setting, visible units are sampled simultaneously given fixed values of the hidden units. Similarly, hidden units are sampled simultaneously given the visibles. A step in the Markov chain is thus taken as follows:\n\\bg\n\\mb{h}^{(n+1)}\\;\\sim\\;\\text{Ber}(\\text{sigm}\\l( \\mb{W}^T\\mb{v}^{(n)}+\\mb{c} \\r)),\n\\\\\n\\mb{v}^{(n+1)}\\;\\sim\\;\\text{Ber}(\\text{sigm}\\l( \\mb{W}\\mb{h}^{(n+1)}+\\mb{b} \\r))\n\\eg\nGraphically:\n\\begin{figure}[h]\n\\begin{mdframed}\n\\includegraphics[scale=0.6]{img/gibbs.png}\n\\centering\n\\caption{Gibbs sampling in RBM.}\n\\label{fig:gibbs}\n\\end{mdframed}\n\\end{figure}\n\\\\\nAs $n \\rightarrow \\infty$, samples $\\left(\\mb{v}^{(n)},\\mb{h}^{(n)}\\right)$ are guaranteed to be accurate samples of the model joint.\n\\\\[1em]\nIn theory, each parameter update in the learning process would require running one such chain to convergence to obtain unbiased estimates of gradients of log-likelihood, which requires many sampling steps (prohibitively expensive) and moreover it is typically unclear for how long chain has to be run. As such, several algorithms have been devised for RBMs, in order to efficiently sample from.\n\\\\[1em]\n\\u{Contrastive Divergence} (CD-k)\n\\\\\nThis algorithm was proposed in 2002 by G.Hinton and uses two tricks to speed up the sampling process:\n\\begin{itemize}\n\\item since we eventually want $p_{\\text{model}}(\\mb{v}) \\approx p_{\\text{data}}(\\mb{v})$ (Maximum Likelihood $\\Leftrightarrow$ Minimizing KL divergence between $p_{\\text{model}}$ and $p_{\\text{data}}$ (empirical distribution)), \\emph{we initialize the Markov chain with a training example}, so that the chain will be already close to having converged to its desired distribution.\n\\item CD does not wait for the chain to converge. Samples are obtained after only $k$-steps of Gibbs sampling. In practice, $k=1$ has been shown to work surprisingly well.\n\\end{itemize}\nGeneral formula for gradient approximation:\n\\bg\n\\frac{\\partial}{\\partial\\theta}\\log p(\\mb{v}^{(0)};\\bs{\\psi})\\approx \n-\\sum_{\\mb{h}}p(\\mb{h}|\\mb{v}^{(0)};\\bs{\\psi})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{v}^{(0)},\\mb{h};\\bs{\\psi})\n+\\sum_{\\mb{h}}p(\\mb{h}|\\mb{v}^{(k)};\\bs{\\psi})\\cdot\\frac{\\partial}{\\partial\\theta}E(\\mb{v}^{(k)},\\mb{h};\\bs{\\psi})\n\\eg\nConcrete formulae for gradient approximations:\n\\begin{align}\ng_{W_{ij}} &\\leftarrow p(h_j=1|\\mb{v}^{(0)})\\cdot v_i^{(0)}-p(h_j=1|\\mb{v}^{(k)})\\cdot v_i^{(k)}\n\\\\\ng_{b_i} &\\leftarrow v_i^{(0)}-v_i^{(k)}\n\\\\\ng_{c_j} &\\leftarrow p(h_j=1|\\mb{v}^{(0)})-p(h_j=1|\\mb{v}^{(k)})\n\\end{align}\nwith $\\mb{v}^{(0)}:=\\mb{v}$ -- training example\n\\\\\nEach gradient is a difference of the corresponding \\tb{positive} and \\tb{negative} gradients, see (16). It is thus described through sequence of \\emph{positive phases}, where we clamp visible units to a particular state vector sampled from the training set $\\mb{v}\\leftarrow\\mb{x}_i \\sim p_{\\text{data}}$, and \\emph{negative phases}, where the network is run freely without fixing any states.\n\\\\[0.5em]\n\\tb{Note}: originally formulae (31)-(33) should contain instead of $p(h_j=1|\\mb{v})$ the samples of hidden units themselves (apart from sampling involved to estimate model's expectations), but stated variants typically provide slightly less noisy and thus faster learning, and it is not so important at all when RBM is used to pretrain hidden layer of units for DBN/DBM \\cite{hinton2010practical}.\n\\\\[1em]\nSince $\\mb{v}^{(k)}$ is not a sample from the stationary distribution the approximation the approximation (30) is biased. Obviously, as $k \\rightarrow \\infty$, bias vanishes. One can also show that CD does not maximize the likelihood of the data under the model, but minimize the difference of two KL-divergences:\n\\bg\nD_{\\text{KL}}(p_{\\text{data}}(\\mb{v})\\;\\|\\;p_{\\text{model}}(\\mb{v}))-D_{\\text{KL}}(p^{(k)}(\\mb{v})\\;\\|\\;p_{\\text{model}}(\\mb{v})),\n\\eg\nwhere $p^{(k)}(\\mb{v})$ is a distribution of visible variables after k steps of Markov chain. If chain already reached stationarity it holds that $p^{(k)}=p_{\\text{model}} \\;\\Rightarrow\\; D_{\\text{KL}}(p^{(k)}(\\mb{v})\\;\\|\\;p_{\\text{model}}(\\mb{v}))=0$ and the approximation error of CD is vanishes.\n\\\\[1em]\nCD does not follow the gradient of any function \\cite{hinton2010practical}.\n\\\\[1em]\n\\u{Persistent CD}\nIn \\cite{tieleman2008training} they rely on a single Markov chain, which has a persistent state (i.e., not restarting a chain for each observed example). For each parameter update, we extract new samples by simply running the chain for $k$-steps. The state of the chain is then preserved for subsequent updates. The general intuition is that if parameter updates are small enough compared to the mixing rate of the chain, the Markov chain should be able to \"catch up\" to changes in the model.\n\\\\[1em]\nTypically one uses as much markov chains as there are training examples in a minibatch. These persistent states of Markov chains can be used to generate samples after training. In \\cite{hinton2010practical} they mention PCD learns significantly better models than CD-k for various k and is the recommended method if the aim is to build the best density model of the data. We will use a modification of PCD for DBM training.\n\\\\[1em]\nAlso, recently the new algorithm \\u{Parallel tempering} is proposed \\cite{fischer2012introduction}. It introduces supplementary Gibbs chains that sample from more and more smoothed replicas of the original distribution. In the price of computational overhead it gives faster mixing Markov chain and thus less biased gradient approximation.\n\\subsubsection{Extensions}\n\\u{More general RBMs/BMs}\n\\\\[1em]\nSo far we considered only case of binary (Bernoulli) both visible and hiddent units. But RBMs (and BMs) can also be extended to model $\\R$-valued inputs/outputs. This can be achieved by altering the energy functio (more examples below). More generally RBM can be defined as any MRF (undirected graphical model) with conditionally independent visible units given hidden and vice versa and with energy function of the following kind:\n\\bg\nE(\\mb{v},\\mb{h};\\bs{\\psi})=\\sum_{i,j}\\phi_{ij}(v_i,h_j;\\bs{\\psi})+\\sum_i \\omega_i(v_i;\\bs{\\psi}) + \\sum_j \\nu_j(h_j;\\bs{\\psi})\n\\eg\nwith $\\R$-valued functions $\\phi_{ij}, \\omega_i, \\nu_j$ for which partition function is finite $Z(\\bs{\\psi})<\\infty$.\n\\\\[1em]\n\\u{Conditional RBMs}\n\\\\[1em]\nsome of the parameters in $E$ are replaced by parameterized functions of some conditioning random variables.\n\\\\[1em]\n\\u{Classification RBMs (cRBMs)}\n\\\\[1em]\nIn regular RBM we model $p(\\mb{x})$. In classification RBM there are couple of choices:\n\\begin{itemize}\n\\item model $p(\\mb{x},\\mb{y})$ (\\emph{generative mode})\n\\item model $p(\\mb{y}|\\mb{x})$ (\\emph{discriminative mode}), equivalent to the above via Bayes theorem\n\\item $\\alpha\\cdot p(\\mb{x},\\mb{y})+(1-\\alpha)\\cdot p(\\mb{y}|\\mb{x})\\rightarrow \\text{max}$ (\\emph{hybrid mode})\n\\end{itemize}\nSee more in \\cite{hinton2010practical}.\n\n\\subsubsection{Different types of RBM units}\nFor a binary unit, the probability of turning on is given by the logistic sigmoid function of its total input, $x$.\n\\bg\np=\\text{sigm}(x)=\\frac{1}{1+e^{-x}}=\\frac{e^x}{e^x+e^0}\n\\eg\nThe energy contributed by the unit is $-x$ if it is on and 0 if it is off. Equation (36) makes it clear that the probability of each of the two possible states is proportional to the negative exponential of its energy. This can be generalized to $K$ alternative states.\n\\\\[1em]\n\\u{Softmax units}\n\\bg\np_j=\\text{softmax}_j(\\mb{x})=\\frac{e^{x_j}}{\\sum_{k=1}^K e^{x_k}}\n\\eg\nIt is the appropriate way to deal with a quantity that has $K$ alternative \\emph{mutually exclusive} values which are not ordered in any way. When viewed in this way, the learning rule for the binary units in a softmax is identical to the rule for standard binary units.\n\\tb{The only difference is in the way the probabilities of the states are computed and the samples are taken} + Fig. \\ref{fig:softmax_sampling}.\n\\\\[0.5em]\nFormally, for binary visible and softmax hidden: \n$$\\mb{v}\\in\\{0,1\\}^D,\\mb{h}\\in\\text{One-hot}(H)=\\l\\{\\mb{q}\\in\\{0,1\\}^H \\bigg| \\sum_kq_k=1\\r\\}, H=K$$\nEnergy function has the same functional form, as for binary-binary RBM:\n\\bg\nE(\\mb{v},\\mb{h};\\bs{\\psi})=-\\sum_{j,l}W_{jl}v_jh_l-\\sum_jb_jv_j-\\sum_lc_lh_l\n\\eg\n\\\\[1em]\n\\u{Multinomial units}\n\\\\\nAfurther generalization of the softmax unit is to sample $M$ times (with replacement) from the probability distribution instead of just sampling once. The $K$ different states can then have integer values bigger than 1, but the values must add to $M$. This is called a \\emph{multinomial unit} and, again, the learning rule is unchanged. It is also equivalent \\cite{hinton2009replicated} to $M$ softmax units with shared weights.\n\\\\[0.5em]\nFormally, for binary visible and multinomial hidden with $M$ samples: \n$$\\mb{v}\\in\\{0,1\\}^D,\\t{\\mb{h}}\\in\\l\\{\\mb{q}\\in\\{0,1,\\ldots,M\\}^H \\bigg| \\sum_kq_k=M\\r\\}, H=K$$\nEnergy function has the same functional form, as for binary-binary RBM:\n\\bg\nE(\\mb{v},\\t{\\mb{h}};\\bs{\\psi})=-\\sum_{j,l}W_{jl}v_j\\t{h}_l-\\sum_jb_jv_j-\\sum_lc_l\\t{h}_l,\n\\eg\nwhere $\\t{h}_l=\\sum_{m=1}^M h_l^{(m)}$ -- count for $l$-th discrete value of hidden units. Typically, this variant of RBM is used for topic modelling \\cite{hinton2009replicated} (visible are Multinomial, hidden -- binary). Often $M$ is equal to $K$. In this case, it is also useful to scale hidden bias term by $M$, this will allow to behave sensible when deal with documents of the different lengths.\n\\\\[1em]\n\\u{Gaussian visible units}\n\\\\\nTo be able to model real-valued data $\\mb{v}\\in\\R^D$, one solution is to replace the binary visible units by linear units with independent Gaussian noise. The energy function then becomes:\n\\bg\nE(\\mb{v},\\mb{h};\\bs{\\psi})=\\frac{1}{2}\\sum_{i,j}\\frac{(v_i-b_i)^2}{\\sigma_i^2}-\\sum_jc_jh_j-\\sum_{i,j}W_{ij}\\frac{v_i}{\\sigma_i}h_j\n\\eg\nwhere $\\sigma_i$ is the standard deviation of the Gaussian noise for visible unit $i$. It is possible to learn the variance of the noise for each visible unit but this is difficult using CD-k. In many applications, it is much easier to first normalise each component of the data to have zero mean and unit variance and then to use noise free reconstructions, with the variance in equation (40) set to 1.\n\\\\[1em]\nFrom (38) one can derive formulae for activations \\cite{salakhutdinov2013learning, krizhevsky2009learning}:\n\\bg\np(h_j=1|\\mb{v})=\\text{sigm}\\l(\\sum_iW_{ij}\\frac{v_i}{\\sigma_i}+c_j\\r),\n\\\\\nv_i|\\mb{h}\\;\\sim\\;\\mc{N}\\l(\\sigma_i\\sum_jW_{ij}h_j+b_i;\\;\\sigma_i^2\\r)=\\sigma_i\\sum_jW_{ij}h_j+b_i+\\sigma_i\\cdot\\mc{N}(0; 1)\n\\eg\n\\\\[1em]\nThere also exist other types of units, such as gaussian for both visible and hidden units, binomial units, rectifier linear units etc., but they more rarely used and are out of the scope of these notes. See more in \\cite{hinton2010practical}.\n\n\\subsubsection{Free energies formulae}\n\\textbullet{} \\u{Free energy for binary visible and hidden units (19)} (Similarly to Fig. \\ref{fig:prod_experts}):\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\n\\mc{F}(\\mb{v};\\bs{\\psi})=-\\log\\l( \\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})} \\r)=\n-\\log \\sum_{\\mb{h}} \\exp\\l(\\sum_{i,j}W_{ij}v_ih_j+\\sum_ib_iv_i+\\sum_jc_jh_j\\r)=\\\\\n=-\\log \\l[\\exp\\l(\\sum_ib_iv_i\\r)\\cdot\\sum_{\\mb{h}} \\exp\\l(\\sum_{i,j}W_{ij}v_ih_j+\\sum_jc_jh_j\\r)\\r]=\\\\\n=-\\sum_ib_iv_i-\\log \\sum_{\\mb{h}} \\underbrace{\\exp\\l(\\sum_jh_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r)}_{\\prod_j \\exp\\l(h_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r)}=\\comment{$\\sum_{\\mb{h}}\\prod_j f_j(h_j)=\\prod_j\\sum_{h_j}f_j(h_j)$}=\\\\\n=-\\mb{b}\\cdot\\mb{v}-\\sum_j \\log\\l( \\underbrace{ \\sum_{h_j\\in\\{0,1\\}}\\exp \\l[h_i \\sum_iW_{ij}v_i+c_j\\r]}_{1+\\exp\\l(\\sum_iW_{ij}v_i+c_j\\r)}\\r)\n=-\\mb{b}\\cdot\\mb{v}-\\sum_j \\text{softplus}\\l(\\sum_iW_{ij}v_i+c_j\\r),\n\\end{empheq}\nwhere $\\text{softplus}(x):=\\log(1+e^x)$.\n\\begin{gather}\n\\boxed{\\mc{F}(\\mb{v};\\bs{\\psi})=-\\mb{b}\\cdot\\mb{v}-\\sum_j \\text{softplus}\\l(\\sum_iW_{ij}v_i+c_j\\r)}\n\\end{gather}\n\\\\[1em]\n\\textbullet{} \\u{Free energy for Bernoulli-Softmax RBM (38)}:\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\n\\mc{F}(\\mb{v};\\bs{\\psi})=-\\log\\l( \\sum_{\\mb{h}}e^{-E(\\mb{v},\\mb{h};\\bs{\\psi})} \\r)=\n-\\sum_ib_iv_i-\\log \\sum_{\\mb{h}} \\underbrace{\\exp\\l(\\sum_jh_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r)}_{\\prod_j \\exp\\l(h_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r)}=\\\\\n=-\\mb{b}\\cdot\\mb{v}-\\log \\sum_{j=1}^K\\exp\\l(\\sum_iW_{ij}v_i+c_j\\r),\n\\end{empheq}\n\\begin{gather}\n\\boxed{\\mc{F}(\\mb{v};\\bs{\\psi})=-\\mb{b}\\cdot\\mb{v}-\\log \\sum_{j=1}^K\\exp\\l(\\sum_iW_{ij}v_i+c_j\\r)}\n\\end{gather}\n\\\\[1em]\n\\textbullet{} \\u{Free energy for Bernoulli-Multinomial RBM (39)}:\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\n\\mc{F}(\\mb{v};\\bs{\\psi})=-\\log\\l( \\sum_{\\t{\\mb{h}}}e^{-E(\\mb{v},\\t{\\mb{h}};\\bs{\\psi})} \\r)=\n-\\sum_ib_iv_i-\\log \\sum_{\\t{\\mb{h}}} \\underbrace{\\exp\\l(\\sum_j\\t{h}_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r)}_{\\prod_j \\exp\\l(\\t{h}_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r)}=\\\\\n=-\\mb{b}\\cdot\\mb{v}-\\log \\sum_{\\t{h}_1+\\ldots+\\t{h}_K=M,0\\leq \\t{h}_l\\leq M}\\prod_j\\exp\\l(\\t{h}_j\\l(\\sum_iW_{ij}v_i+c_j\\r)\\r),\n\\end{empheq}\nFor large $M$ this equation seems to be intractable to compute. But we can approximate this by sampling $\\t{\\mb{h}}$ from Multinomial distribution with equiprobable states and applying appropriate scaling, note that\n$$\n\\l | \\l\\{\\mb{q}\\in\\{0,1,\\ldots,M\\}^H \\bigg| \\sum_kq_k=M\\r\\} \\r |=\\#_{M,K}=\\binom{M+K-1}{K-1}=\\frac{\\Gamma(M+K)}{\\Gamma(M+1)\\Gamma(K)}\n$$\nSo\n\\begin{empheq}[box={\\mybox[1em][1em]}]{gather*}\n\\t{\\mb{h}}\\;\\sim\\;\\text{Multinomial}\\l(\\mb{p}=\\l(\\frac{1}{K}\\ldots\\frac{1}{K}\\r); M\\r),\n\\\\\n\\mc{F}(\\mb{v};\\bs{\\psi}) \\approx -\\mb{b}\\cdot\\mb{v}-\\log \\l(\\frac{\\Gamma(M+K)}{\\Gamma(M+1)\\Gamma(K)}\\r)-\\sum_j \\t{h}_j \\l(\\sum_iW_{ij}v_i+c_j\\r)\n\\end{empheq}\n\\begin{gather}\n\\boxed{ \\mc{F}(\\mb{v};\\bs{\\psi})\\approx -\\mb{b}\\cdot\\mb{v}-\\texttt{lgamma}(M+K)+\\texttt{lgamma}(M+1)+\\texttt{lgamma}(K)-\\sum_j \\t{h}_j \\l(\\sum_iW_{ij}v_i+c_j\\r) }\n\\end{gather}\n\\\\[1em]\n\\textbullet{} \\u{Free energy for Gaussian-Bernoulli RBM}:\n\\\\Derivation is straightforward, the formula is very similar to (43), but with accordingly changed bias term for visible units, and scaled visible units by their resp. std. deviation:\n\\begin{gather}\n\\boxed{\\mc{F}(\\mb{v};\\bs{\\psi})=\\frac{1}{2}\\l\\|\\frac{\\mb{v}-\\mb{b}}{\\bs{\\sigma}}\\r\\|^2-\\sum_j \\text{softplus}\\l(\\sum_iW_{ij}\\frac{v_i}{\\sigma_i}+c_j\\r)}\n\\end{gather}\nor equivalently if $\\t{\\mb{v}}\\leftarrow \\mb{v}/\\bs{\\sigma}$ (element-wise division, and also in (46),(47)):\n\\begin{gather}\n\\boxed{\\mc{F}(\\mb{v};\\bs{\\psi})=\\frac{1}{2}\\l\\|\\t{\\mb{v}}-\\frac{\\mb{b}}{\\bs{\\sigma}}\\r\\|^2-\\sum_j \\text{softplus}\\l(\\sum_iW_{ij}\\t{v_i}+c_j\\r)}\n\\end{gather}\n", "meta": {"hexsha": "37dcd24d7510497a801d44e14a49718c45c7fa5d", "size": 42411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/chapter_1.tex", "max_stars_repo_name": "praisethemoon/boltzmann-machines", "max_stars_repo_head_hexsha": "bc49ba2c8c6c894af55b272e1b92f9cea3576136", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 196, "max_stars_repo_stars_event_min_datetime": "2019-03-16T14:50:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:24:00.000Z", "max_issues_repo_path": "tex/chapter_1.tex", "max_issues_repo_name": "praisethemoon/boltzmann-machines", "max_issues_repo_head_hexsha": "bc49ba2c8c6c894af55b272e1b92f9cea3576136", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2019-04-09T07:33:01.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-27T21:37:37.000Z", "max_forks_repo_path": "tex/chapter_1.tex", "max_forks_repo_name": "praisethemoon/boltzmann-machines", "max_forks_repo_head_hexsha": "bc49ba2c8c6c894af55b272e1b92f9cea3576136", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2019-03-16T14:51:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-10T13:47:40.000Z", "avg_line_length": 78.1049723757, "max_line_length": 648, "alphanum_fraction": 0.6977199311, "num_tokens": 14792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6678198007615935}}
{"text": "% Created 2021-07-22 Thu 19:21\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{State feedback}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={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{Apollo moon lander}\n\\label{sec:org1fe45b2}\n\\begin{frame}[label={sec:org431d74e}]{Example - The Apollo lunar module}\n\\begin{center}\n\\includegraphics[width=\\linewidth]{fig-apollo}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:org3448043}]{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} = k_1 u\\\\ \\dot{x}_2 = \\dot{\\theta} = x_1\\\\ \\dot{x}_3 = \\ddot{z} = k_2\\theta = k_2x_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}{k_2} &\\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}{k_1} \\\\ \\textcolor{red!60!black}{0} \\\\\\textcolor{red!60!black}{0}  \\end{bmatrix}}_{B} u \\]\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org0a7ddbd}]{Example - The Apollo lunar module}\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^2k_2}{2} & hk_2 & 1\\end{bmatrix} x(kh) + k_1 \\begin{bmatrix} h\\\\ \\frac{h^2}{2} \\\\ \\frac{k_2 h^3}{6} \\end{bmatrix} u(kh)\n\\end{align*}\n\\end{frame}\n\n\\section{Stability}\n\\label{sec:orgd7bcbae}\n\\begin{frame}[label={sec:org67bf27a}]{Stability}\n\\end{frame}\n\\begin{frame}[label={sec:orgbe68e19}]{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:org28643b7}]{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\\begin{frame}[label={sec:org49e757d}]{Eigenvalues and eigenvectors - exercise}\n\\alert{Activity} Verify that the vector\n\\[ v = \\begin{bmatrix}1\\\\0\\end{bmatrix}\\]\nis an eigenvector of\n\\[ \\Phi = \\begin{bmatrix} 2 & 0\\\\0 & \\frac{1}{2} \\end{bmatrix}. \\]\nWhat is the corresponding eigenvalue?\n\\end{frame}\n\n\\section{Controllability and observability}\n\\label{sec:org9bb04e3}\n\n\\begin{frame}[label={sec:orgcb694f3}]{Controllability}\nControllability is the answer to the question \\emph{Can we drive the state of the system to any location in the state space by a suitable input sequence \\(u(k),\\; k=0,1,2,\\ldots,n-1\\)?}\n\nConsider\n\\[ x(k+1) = \\Phi x(k) + \\Gamma u(k), \\quad x(0)= x_0 \\]\nwith solution\n\\begin{equation}\n\\begin{split}\nx(n) &= \\Phi^nx(0) + \\Phi^{n-1}\\Gamma u(0) + \\Phi^{n-2}\\Gamma u(1) + \\cdots + \\Gamma u(n-1)\\\\\n     &= \\Phi^nx(0) + W_c U, \n\\end{split}\n\\end{equation}\nwhere\n\\begin{align*}\nW_c &= \\bbm \\Gamma & \\Phi\\Gamma & \\cdots & \\Phi^{n-1}\\Gamma\\ebm\\\\\nU &= \\bbm u(n-1) & u(n-2) & \\cdots & u(0) \\ebm\\transp\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}[label={sec:orge71ee18}]{Controllability}\nTo find the input sequence \\(u(k)\\) that takes the state from  \\(x(0)=x_0\\) to \\(x(n) = x_d\\) we may solve for \\(U\\) in the equation\n\\[ x_d = \\Phi^nx_0 + W_cU.\\]\n\n\\[ U = W_c\\inv \\left(x_d - \\Phi^nx(0)\\right) \\]\n\nThis is possible when the matrix \\(W_x\\) is \\alert{invertible}:\n\nThe state-space system above is controllable if and only if the \\emph{Controllability matrix} \\(W_c\\)  has rank \\(n\\), i.e. \n\\[ \\det W_c \\neq 0.\\]\n\\end{frame}\n\n\\section{Observability}\n\\label{sec:org7e5fdb0}\n\\begin{frame}[label={sec:orgd9c3ab5}]{Observability}\n\\footnotesize\n\nObservability is the answer to the question \"Can we determine the initial state \\(x(0)\\) if we only know \\(y(k), \\; k=0,1,2,\\ldots, n-1\\)?\"\n\nThe first \\(n\\) values of the output sequence are given by\n\\begin{align*}\ny(0) &= Cx(0)\\\\\ny(1) &= Cx(1) = C \\left( \\Phi x(0) + \\Gamma u(0)  \\right)\\\\\n& \\vdots\\\\\ny(n-1) &= Cx(n-1) = C \\left( \\Phi^{n-1} x(0) + W_c U \\right).\n\\end{align*}\nThis gives the equation\n\\[ \\bbm C\\\\C\\Phi\\\\\\vdots\\\\C\\Phi^{n-1} \\ebm x(0) = \\bbm y(0)\\\\y(1) - C\\Gamma u(0)\\\\\\vdots\\\\ y(n-1) - CW_c U\\ebm \\]\nwhich can be solved for \\(x(0)\\) if and only if the matrix \n\\[W_o = \\bbm C\\\\C\\Phi\\\\\\vdots\\\\C\\Phi^{n-1} \\ebm\\] has full rank.\n\\end{frame}\n\n\\begin{frame}[label={sec:org3f9df66}]{Observability, contd}\nThe equation\n\\[ \\bbm C\\\\C\\Phi\\\\\\vdots\\\\C\\Phi^{n-1} \\ebm x(0) = \\bbm y(0)\\\\y(1) - C\\Gamma u(0)\\\\\\vdots\\\\ y(n-1) - CW_c U\\ebm \\]\n can be solved for \\(x(0)\\) if and only if the matrix \n\\[W_o = \\bbm C\\\\C\\Phi\\\\\\vdots\\\\C\\Phi^{n-1} \\ebm\\] has full rank. If this is the case, the system is said to be \\alert{observable}.\n\\end{frame}\n\n\\section{State feedback}\n\\label{sec:orgf1d8532}\n\\begin{frame}[label={sec:org24865e0}]{State feedback control}\n\\end{frame}\n\\begin{frame}[label={sec:org6fb357b}]{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) = -l_1x_1(k) - l_2x_2(k) - \\cdots - l_n x_n(k) + l_0u_c(k)\\\\\n      &= -Lx(k) + l_0u_c(k), \n\\end{split}\n\\end{equation*}\nwhere \\[ L = \\bbm l_1 & l_2 & \\cdots & 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 L \\right) x(k) + m\\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:orgc58c4bb}]{Pole placement by state feedback}\nGiven 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\nLinear state feedback gives the system\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma L \\right) x(k) + l_0\\Gamma u_c(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation}\nwith characteristic polynomial\n\\begin{equation}\n\\det\\left(zI - (\\Phi - \\Gamma L)\\right) = z^n + \\beta_1(l_1,\\ldots,l_n) z^{n-1} + \\cdots \\beta_n(l_1, \\ldots, l_n).\n\\label{eq:poles}\n\\end{equation}\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(l_1, \\ldots, l_n) &= \\alpha_1\\\\\n\\beta_2(l_1, \\ldots, l_n) &= \\alpha_2\\\\\n&\\vdots\\\\\n\\beta_n(l_1, \\ldots, l_n) &= \\alpha_n\n\\end{split}\n\\label{eq:coeffs}\n\\end{equation*}\n\\end{frame}\n\n\\begin{frame}[label={sec:org6a1ea81}]{Pole placement by state feedback}\nThe system of equations\n\\begin{equation*}\n\\begin{split}\n\\beta_1(l_1, \\ldots, l_n) &= \\alpha_1\\\\\n\\beta_2(l_1, \\ldots, l_n) &= \\alpha_2\\\\\n&\\vdots\\\\\n\\beta_n(l_1, \\ldots, l_n) &= \\alpha_n\n\\end{split}\n\\label{eq:coeffs}\n\\end{equation*}\nis always linear in the parameters of the controller, henc\n\\begin{equation*}\nM 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:org63429f3}]{Pole placement and controllability}\nIt can be shown that the controllability matrix\n\\[W_c = \\bbm \\Gamma & \\Phi\\Gamma & \\cdots & \\Phi^{n-1}\\Gamma\\ebm\\]\nis a factor of the matrix \\(M\\)\n\\[ M = \\bar{M} W_c. \\] Hence, in general, the equations\n\\begin{equation}\n\\bar{M}W_c L\\transp = \\alpha \\qquad \\Rightarrow \\qquad L\\transp = W_c^{-1}\\bar{M}^{-1}\\alpha\n\\label{eq:poleplace}\n\\end{equation}\nonly has a solution if \\(W_c\\) is invertible, that is when the system is \\emph{controllable}.\n\n Note that the equations \\eqref{eq:poleplace} may also have solutions when the system is not controllable, if  \\alert{\\(\\alpha\\) is in the column space of \\(M\\)}. That is \n\\[ \\alpha = b_1 M_{:,1} + b_2M_{:,2} + \\cdots + b_M_{:,m}, \\; m < n \\]\n\\end{frame}\n\n\\begin{frame}[label={sec:org58305a1},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 L \\right) x(k) + 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:org6cebb83}]{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 L \\right)}_{\\Phi_c} x(k) + l_0\\Gamma u_c(k)\\\\\n y(k) &= C x(k)\n\\end{split}\n\\end{equation*}\nhas the steady-state solution (\\(x(k+1)=x(k)\\)) for constant reference signal \\(u_c(k) = u_{c,f}\\)\n\\[ y_f = l_0 C(I - \\Phi_c)^{-1}\\Gamma u_{c,f}.\\]\nWe want \\(y_f =  u_{c,f}\\),\n\\[ \\Rightarrow \\qquad l_0 = \\frac{1}{C(I-\\Phi_c)^{-1}\\Gamma}\\]\n\\end{frame}\n\n\\section{Exercise}\n\\label{sec:org0d8e2aa}\n\n\\begin{frame}[label={sec:org31fcf52}]{Exercise - The harddisk drive arm}\n\\footnotesize\nThe model of the arm of the harddisk drive\n\\begin{center}\n\\includegraphics[width=0.2\\linewidth]{../../figures/hard-drive.png}\n\\end{center}\ncan, with suitable choice of sampling period, be written\n\n\\[x(k+1) = \\Phi x(k) + \\Gamma u(k) = \\begin{bmatrix} 1 & 0.4\\\\ 0 &1 \\end{bmatrix} x + \\begin{bmatrix}0.16\\\\0.8\\end{bmatrix}u.\\]\nWith linear state feedback \\(u(k) = -Lx(k) + l_0u_c(k)\\) the closed-loop system is\n\\begin{equation*}\n   \\begin{split}\n    x(k+1) &= \\left(\\Phi -\\Gamma L \\right) x(k) + l_0\\Gamma u_c(k)\\\\\n           &= \\begin{bmatrix} 1-0.16l_1 & 0.4 - 0.16l_2\\\\-0.8l_1 & 1-0.8l_2\\end{bmatrix} x(k) + l_0\\Gamma u_c(k).\n   \\end{split}\n\\end{equation*}\n\n\\alert{Determine} the characteristic polynomial of the closed-loop system \\(\\det \\Big( zI - (\\Phi - \\Gamma L)\\Big)\\)\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "88367e09ad2355e84655d086932fad44566e8342", "size": 11760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "state-space/slides/lecture-state-feedback.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": "state-space/slides/lecture-state-feedback.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": "state-space/slides/lecture-state-feedback.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": 37.4522292994, "max_line_length": 577, "alphanum_fraction": 0.6675170068, "num_tokens": 4597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473628, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6678197862156332}}
{"text": "\\input{../header_function}\n\n%---------- start document ---------- %\n \\section{prime -- primality test , prime generation}\\linkedzero{prime}\n%\n  \\subsection{trialDivision -- trial division test}\\linkedone{prime}{trialDivision}\n   \\func{trialDivision}\n   {\\hiki{n}{integer},\\ \\hikiopt{bound}{integer/float}{0}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Trial division primality test for an odd natural number.\\\\\n   \\spacing\n   % added document\n   %\\spacing\n   % input, output document\n   \\quad \\param{bound} is a search bound of primes. \n   If it returns \\(1\\) under the condition that \\param{bound} is given and \n   less than the square root of \\param{n}, \n   it only means there is no prime factor less than \\param{bound}.\n%\n  \\subsection{spsp -- strong pseudo-prime test}\\linkedone{prime}{spsp}\n   \\func{spsp}{\\hiki{n}{integer},\\ \\hiki{base}{integer},\\ \\hikiopt{s}{integer}{None},\\ \\hikiopt{t}{integer}{None}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Strong Pseudo-Prime test on base \\param{base}.\\\\\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   \\quad \\param{s} and \\param{t} are the numbers such that $n-1 = 2^\\param{s}\\param{t}$ and \\param{t} is odd.\n%\n \\subsection{smallSpsp -- strong pseudo-prime test for small number}\\linkedone{prime}{smallSpsp}\n   \\func{smallSpsp}{\\hiki{n}{integer},\\ \\hikiopt{s}{integer}{None},\\ \\hikiopt{t}{integer}{None}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Strong Pseudo-Prime test for integer \\param{n} less than $10^{12}$.\\\\\n   \\spacing\n   % added document\n   \\quad $4$ spsp tests are sufficient to determine whether an integer less than $10^{12}$ is prime or not.\n   \\spacing\n   % input, output document\n   \\quad \\param{s} and \\param{t} are the numbers such that $n-1 = 2^\\param{s}\\param{t}$ and \\param{t} is odd.\n%\n  \\subsection{miller -- Miller's primality test}\\linkedone{prime}{miller}\n   \\func{miller}\n   {\\hiki{n}{integer}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Miller's primality test.\\\\\n   \\spacing\n   % added document\n   \\quad This test is valid under GRH. See \\linkingzero{config}.\n   \\spacing\n   % input, output document\n   %\\quad \n%\n  \\subsection{millerRabin -- Miller-Rabin primality test}\\linkedone{prime}{millerRabin}\n   \\func{millerRabin}\n   {\\hiki{n}{integer},\\ \\hikiopt{times}{integer}{20}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Miller's primality test.\\\\\n   \\spacing\n   % added document\n   \\quad The difference from \\linkingone{prime}{miller} is that \n   the Miller-Rabin method uses fast but probabilistic algorithm.\n   On the other hand, \\linkingone{prime}{miller} employs deterministic\n   algorithm valid under GRH.\n   \\spacing\n   % input, output document\n   \\quad \\param{times} (default to $20$) is the number of repetition.\n   The error probability is at most $4^{-\\param{times}}$.\n%\n \\subsection{lpsp -- Lucas test}\\linkedone{prime}{lpsp}\n   \\func{lpsp}\n   {\\hiki{n}{integer},\\ \\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Lucas Pseudo-Prime test.\\\\\n   \\spacing\n   % added document\n   \\quad Return True if \\param{n} is a Lucas pseudo-prime of parameters \\param{a}, \\param{b},\n    i.e. with respect to $x^2-\\param{a}x+\\param{b}$.\n   \\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{fpsp -- Frobenius test}\\linkedone{prime}{fpsp}\n   \\func{fpsp}\n   {\\hiki{n}{integer},\\ \\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Frobenius Pseudo-Prime test.\\\\\n   \\spacing\n   % added document\n   \\quad Return True if \\param{n} is a Frobenius pseudo-prime of parameters \\param{a}, \\param{b},\n    i.e. with respect to $x^2-\\param{a}x+\\param{b}$.\n   \\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{by\\_primitive\\_root -- Lehmer's test}\\linkedone{prime}{by\\_primitive\\_root}\n   \\func{by\\_primitive\\_root}\n   {\\hiki{n}{integer},\\ \\hiki{divisors}{sequence}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Lehmer's primality test~\\cite{Lehmer1927}.\\\\\n   \\spacing\n   % added document\n   \\quad Return True iff \\param{n} is prime.\\\\\n    The method proves the primality of \\param{n} by existence of a primitive\n    root.\n   \\spacing\n   % input, output document\n   \\quad \\param{divisors} is a sequence (list, tuple, etc.) of prime divisors\n   of $n - 1$.\n   %\\quad \n%\n \\subsection{full\\_euler -- Brillhart \\& Selfridge's test}\\linkedone{prime}{full\\_euler}\n   \\func{full\\_euler}\n   {\\hiki{n}{integer},\\ \\hiki{divisors}{sequence}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Brillhart \\& Selfridge's primality test~\\cite{BS1967}.\\\\\n   \\spacing\n   % added document\n   \\quad Return True iff \\param{n} is prime.\\\\\n    The method proves the primality of \\param{n} by the equality\n    $\\varphi(n) = n - 1$, where $\\varphi$ denotes the Euler totient\n    (see \\linkingone{multiplicative}{euler}).\n    It requires a sequence of all prime divisors of $n - 1$.\n   \\spacing\n   % input, output document\n   \\quad \\param{divisors} is a sequence (list, tuple, etc.) of prime divisors\n   of $n - 1$.\n   %\\quad \n   \\quad\n%\n \\subsection{apr -- Jacobi sum test}\\linkedone{prime}{apr}\n   \\func{apr}\n   {\\hiki{n}{integer}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad APR (Adleman-Pomerance-Rumery) primality test or the Jacobi sum test.\\\\\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   \\quad Assuming \\param{n} has no prime factors less than $32$.\n    Assuming \\param{n} is spsp (strong pseudo-prime) for several bases.\n%\n \\subsection{aks -- Cyclotomic Congruence test}\\linkedone{prime}{aks}\n   \\func{aks}\n   {\\hiki{n}{integer}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad AKS (Agrawal-Kayal-Saxena) primality test or the cyclotomic congruence test.\\\\\n   \\spacing\n   % added document\n   \\quad Return True iff \\param{n} is prime.\\\\\n   The algorithm determines whether a number \\param{n} is prime or composite within polynomial time. For large number \\param{n}, you can use apr and any other test in practical use.\n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{primeq -- primality test automatically}\\linkedone{prime}{primeq}\n   \\func{primeq}\n   {\\hiki{n}{integer}}{\\out{True/False}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad A convenient function for primality test.\\\\\n   \\spacing\n   % added document\n   \\quad It uses one of \\linkingone{prime}{trialDivision}, \\linkingone{prime}{smallSpsp} or \\linkingone{prime}{apr} depending on the size of \\param{n}.\n   \\spacing\n   % input, output document\n   %\\quad \n%\n%\\subsection{bigprimeq -- primality test automatically}\\linkedone{prime}{bigprimeq}\n%   \\func{bigprimeq}\n%   {\\hiki{z}{integer}}{\\out{True/False}}\\\\\n%   \\spacing\n   % document of basic document\n%   \\quad Giving up rigorous proof of primality, return True for a probable prime.\n%   \\spacing\n   % added document\n%   \\quad \n%   \\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{prime -- $n$-th prime number}\\linkedone{prime}{prime}\n   \\func{prime}\n   {\\hiki{n}{integer}}{\\out{integer}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return the \\param{n}-th prime number.\\\\\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{nextPrime -- generate next prime}\\linkedone{prime}{nextPrime}\n   \\func{nextPrime}\n   {\\hiki{n}{integer}}{\\out{integer}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return the smallest prime bigger than the given integer \\param{n}.\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{randPrime -- generate random prime}\\linkedone{prime}{randPrime}\n   \\func{randPrime}\n   {\\hiki{n}{integer}}{\\out{integer}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return a random \\param{n}-digits prime.\\\\\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{generator -- generate primes}\\linkedone{prime}{generator}\n   \\func{generator}\n   {(None)}{\\out{generator}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Generate primes from $2$ to $\\infty$ (as generator).\\\\\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{generator\\_eratosthenes -- generate primes using Eratosthenes sieve}\\linkedone{prime}{generator\\_eratosthenes}\n   \\func{generator\\_eratosthenes}\n   {\\hiki{n}{integer}}{\\out{generator}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Generate primes up to \\param{n} using Eratosthenes sieve.\\\\\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{primonial -- product of primes}\\linkedone{prime}{primonial}\n   \\func{primonial}\n   {\\hiki{p}{integer}}{\\out{integer}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return the product\n   \\begin{equation*}\n   \\prod_{q \\in \\mathbb{P}_{\\le \\param{p}}} q=2\\cdot 3\\cdot 5\\cdots \\param{p}\\ .\n   \\end{equation*}\n   \\spacing\n   % added document\n   %\\quad \n   %\\spacing\n   % input, output document\n   %\\quad \n%\n \\subsection{properDivisors -- proper divisors}\\linkedone{prime}{properDivisors}\n   \\func{properDivisors}\n   {\\hiki{n}{integer}}{\\out{list}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return proper divisors of \\param{n} (all divisors of \\param{n} excluding $1$ and \\param{n}).\\\\\n   \\spacing\n   % added document\n   \\quad  It is only useful for a product of small primes.\n   Use \\linkingtwo{factor.misc}{FactoredInteger}{proper\\_divisors} in a more\n   general case.\n   \\spacing\n   % input, output document\n   \\quad The output is the list of all proper divisors.\\\\\n   \\paragraph{DEPRECATION:} This function will be removed in the next release.\n   Please use \\linkingtwo{factor.misc}{FactoredInteger}{proper\\_divisors} instead.\\\\\n%\n \\subsection{primitive\\_root -- primitive root}\\linkedone{prime}{primitive\\_root}\n   \\func{primitive\\_root}\n   {\\hiki{p}{integer}}{\\out{integer}}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return a primitive root of \\param{p}.\\\\\n   \\spacing\n   % added document\n   %\\quad  \n   %\\spacing\n   % input, output document\n   \\quad \\param{p} must be an odd prime.\n%\n \\subsection{Lucas\\_chain -- Lucas sequence}\\linkedone{prime}{Lucas\\_chain}\n   \\func{Lucas\\_chain}\n   {\\hiki{n}{integer},\\ \\hiki{f}{function},\\ \\hiki{g}{function},\\ \\hiki{x\\_0}{integer},\\ \\hiki{x\\_1}{integer}}{(\\out{integer},\\ \\out{integer})}\\\\\n   \\spacing\n   % document of basic document\n   \\quad Return the value of ($x_n$,\\ $x_{n+1}$) for the sequnce $\\{ x_i \\}$ defined as:\\\\\n   \\begin{eqnarray*}\n      x_{2i} = \\param{f}(x_i)\\\\\n      x_{2i+1} = \\param{g}(x_i, x_{i+1})\\ ,\n   \\end{eqnarray*}\n   where the initial values \\param{x\\_0},\\ \\param{x\\_1}.\\\\\n   \\spacing\n   % added document\n   %\\quad  \n   %\\spacing\n   % input, output document\n   \\quad \\param{f} is the function which can be input as $1$-ary integer.\n   \\param{g} is the function which can be input as $2$-ary integer.\\\\\n%\n\\begin{ex}\n>>> prime.primeq(131)\nTrue\n>>> prime.primeq(133)\nFalse\n>>> g = prime.generator()\n>>> g.next()\n2\n>>> g.next()\n3\n>>> prime.prime(10)\n29\n>>> prime.nextPrime(100)\n101\n>>> prime.primitive_root(23)\n5\n\\end{ex}%Don't indent!(indent causes an error.)\n\\C\n\n%---------- end document ---------- %\n\n\\input{../footer}\n", "meta": {"hexsha": "b7f617e3af9b1309ba095f0494151d64b4a1b441", "size": 11509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/prime.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/prime.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/prime.tex", "max_forks_repo_name": "turkeydonkey/nzmath3", "max_forks_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2630057803, "max_line_length": 181, "alphanum_fraction": 0.6656529672, "num_tokens": 3593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6678197837387978}}
{"text": "% !TEX root = ../main.tex\n% chktex-file 21\n% chktex-file 46\n\\section{Spectral Graph Theory}%\n\\label{sec:sgt}\n\nWe start with an introduction to spectral graph theory, which will allow us to characterize and compare the structure of graphs.\nGraphs are most commonly described in their vertex base, i.e.\\  the connection strength $w_{i j}$ of pairs $(v_i, v_j)$ of vertices.\n\\begin{align}\n\tG :=&\\, (\\mathcal{V}, \\mathcal{E}, W)\\quad\\text{with edges } \\mathcal{E} \\subseteq \\mathcal{V} \\times \\mathcal{V}\\text{, weights } W \\in \\mathbb{R}^{N \\times N}\\text{ and vertex count } N := |\\mathcal{V}|\n\\end{align}\nIn this paper we will only consider undirected graphs with non-negative real weights and without self-loops ($\\forall i: w_{i i} = 0$).\n\nThe core idea of spectral graph theory is to perform a change of basis of $W$ and describe graphs in terms of their so called \\textit{spectral base} instead of their \\textit{vertex base}.\nTo see what this means, we interpret the adjacency/weight matrix $W$ as a linear operator that operates on so called signals $x \\in \\mathbb{R}^N$.\nA signal $x$ can be interpreted as a function $x: \\mathcal{V} \\to \\mathbb{R}$ that assigns a signal strength to each vertex.\nBy applying $Wx$ the given signal strengths $x_i$ are shifted according to the connection strenghts $w_{i j}$ to neighboring vertices $v_j$.\nThis interpretation of graphs is very similar to that of Markov chains where signals represent probability distributions.\n\n\\subsection{Relating Graph Signals to Real-valued Functions}%\n\\label{sec:sgt:real}\n\nLet us now compare discrete graph signals $x: \\mathcal{V} \\to \\mathbb{R}$ to continuous real-valued functions $f: \\mathbb{R} \\to \\mathbb{R}$.\nBoth signatures only differ in their domain.\nThe domain $\\mathbb{R}$ of $f$ has an inherent structure, the real number line, which provides a strict ordering of its elements and a notion of distance between them.\nThe domain $\\mathcal{V}$ of $x$ however has no such inherent structure, i.e.\\  $v_1 < v_2$ for two vertices $v_1, v_2$ does not have a clear meaning.\nThe structure of $\\mathcal{V}$ fully depends on the graph $G$ that is acting on it.\nIntuitively graph signals can thus be understood as a discretized generalization of real-valued functions, where the underlying structure of the input domain is not fixed but can be freely chosen.\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{gfx/sgt/real-graph.pdf}\n\t\\caption{%\n\t\tIllustration of how the discretized real number line can be interpreted as an infinite linear graph, compared to some arbitrary finite non-linear graph.\n\t\tThe bars show the signal strengths $f(t)$ and $x_i$ at the vertices $b_t$ and $b_i$ respectively.\n\t}\\label{fig:sgt:realGraph}\n\\end{figure}\n\n\\Cref{fig:sgt:realGraph} shows that all real-valued functions $f$ can be seen as signals $x$ of the graph described by the real number line\\footnote{%\n\tTechnically this is not correct, since $\\mathbb{R}$ is continuous whereas all vertex sets $\\mathcal{V}$ have to be discrete.\n\tTo build an intuition for graph signals, this detail can however be ignored.\n}.\nBoth, real-valued functions and graph signals, can be described as vectors in their time and vertex base respectively:\n\\begin{equation*}\n\t\\begin{split}\n\t\tf = \\int_{\\mathbb{R}} f(t) b_t dt\n\t\t\\Rightarrow \\langle b_t, f \\rangle = f(t)\n\t\\end{split}\n\t\\quad\\text{and}\\quad\n\t\\begin{split}\n\t\tx = \\sum_{i = 1}^{N} x_i b_i\n\t\t\\Rightarrow \\langle b_i, x \\rangle = x_i\n\t\\end{split}\n\\end{equation*}\nIn this equation ${\\{ b_i \\}}_{v_i \\in \\mathcal{V}}$ denotes the standard basis of the adjacency matrix $W$, i.e.\\ $b_i \\in \\mathbb{R}^N$ has a signal strength of $0$ for all $v_{j \\neq i}$ and a signal strength of $1$ for $v_i$.\nSimilarly ${\\{ b_t \\}}_{t \\in \\mathbb{R}}$ denotes the infinite dimensional standard basis of the space of real functions, where $\\langle b_t, \\cdot \\rangle := \\delta_t(\\cdot)$, with $\\delta$ denoting the Dirac delta function.\n\n\\vspace{-1em}%\n\\subsection{Extending the Fourier Transform to Graphs}%\n\\label{sec:sgt:fourier}\n\nAs mentioned at the beginning of this section, the core idea of spectral graph theory is to express graph signal vectors $x$ in the spectral basis ${\\{ u_i \\}}_{i = 1}^{N}$ instead of the standard vertex basis ${\\{ b_i \\}}_{v_i \\in \\mathcal{V}}$.\nThis idea is analogous to the classical Fourier transform on real-valued functions.\nIn the first step we are going to give an intuition for the classical Fourier transform.\nAfterwards we will extend this intuition to the graph domain.\n\nThe Fourier basis ${\\{ u_\\xi \\}}_{\\xi \\in \\mathbb{R}}$ describes a function $f$ not in terms of the values $f(t) = \\langle b_t, f \\rangle$ it takes at position $t$ but instead in terms of the amplitudes $\\hat{f}(\\xi) = \\langle u_\\xi, f \\rangle$ of the complex exponentials $u_\\xi(t) = e^{2\\pi i \\xi t}$.\nUsing this perspective, the Fourier transform can be viewed as a change of basis operator from the orthonormal standard basis ${\\{ b_t \\}}_{t \\in \\mathbb{R}}$ to the also orthonormal Fourier basis ${\\{ u_\\xi \\}}_{\\xi \\in \\mathbb{R}}$:\n\\begin{align*}\n\tf = \\int_{\\mathbb{R}} \\underbrace{\\langle b_t, f \\rangle}_{f(t)} b_t dt\\quad=\\quad\\int_{\\mathbb{R}} \\underbrace{\\langle u_\\xi, f \\rangle}_{\\hat{f}(\\xi)} u_\\xi d\\xi\n\\end{align*}\nThis property of the Fourier transform by itself is not special; in fact there are infinitely many orthonormal bases on the space of real-valued functions.\nThe distinguishing property of ${\\{ u_\\xi \\}}_{\\xi \\in \\mathbb{R}}$, making it useful in many domains, is that it is an \\textit{eigenbasis} of the \\textit{Laplacian} $\\Updelta$, i.e.\\  $\\Updelta u_\\xi = \\lambda_\\xi u_\\xi$ for the eigenvalue $\\lambda_\\xi \\in \\mathbb{R}$.\nThe Laplacian is a multi\\-dimensional generalization of the second derivative.\nFor real-valued functions this boils down to $\\Updelta u_\\xi = \\frac{\\partial^2}{\\partial t^2} u_\\xi = -{(2 \\pi \\xi)}^2 e^{2 \\pi i \\xi t}$ with the eigenvalue $\\lambda_\\xi = {-(2\\pi\\xi)}^2$ depending solely on the frequency $\\xi$.\nThe original motivation to express functions in terms of the Laplacian's eigenbasis was to solve the physical heat equation\\footnote{%\n\tMore generally the Fourier basis turns out to be meaningful for all \\textit{linear time-invariant} (LTI) systems, of which the heat equations are only one instance.\n}.\nFor this reason it is a useful intuition to think about signals as temperature distributions that will converge to an equilibrium state over time.\nThis intuition also works in the graph setting where heat only flows between neighboring vertices in proportion to their connection strengths.\n\nNow that we have looked at the Fourier transform of real-valued functions, we will extend this notion to graphs.\nJust like the classical Fourier transform, the graph Fourier transform performs a change of basis of a signal $x$ from the vertex basis ${\\{ b_i \\}}_{v_i \\in \\mathcal{V}}$ to the Fourier basis ${\\{ u_k \\}}_{k = 1}^{N}$.\nThis Fourier basis again is characterized by it being an eigenbasis of the Laplacian, more specifically the so called \\textit{combinatorial graph Laplacian} $L$ in this case:\n\\begin{align}\n\tL := D - W\\quad\\text{with the degree matrix } D := {\n\t\t\\renewcommand*{\\arraystretch}{0.5}\n\t\t\\begin{pmatrix}\n\t\t\td_1 & & \\\\\n\t\t\t& \\ddots & \\\\\n\t\t\t& & d_N\n\t\t\\end{pmatrix}\n\t}, d_i := \\sum_{j = 1}^{N} w_{i j}\n\\end{align}\nUsing this definition, the application $L x$ is a discrete generalized analogue of the second derivative $\\frac{\\partial^2}{\\partial t^2} f$.\nPutting both Laplacian variants, $\\frac{\\partial^2}{\\partial t^2}$ and $L$, side-by-side gives an intuition for why this is the case:\n\\begin{equation*}\n\t\\begin{split}\n\t\t\\left(-\\frac{\\partial^2}{\\partial t^2} f\\right)\\mkern-4mu(t) = \\lim_{h \\to 0} \\frac{1}{h^2} (\\underbrace{f(t) - f(t-h)}_{\\Delta_{t, t-h}} + \\underbrace{f(t) -  f(t+h)}_{\\Delta_{t, t+h}})\n\t\\end{split}\n\t\\begin{split}\\ \\left|\\ %\n\t\t{(L x)}_i = \\sum_{j = 1}^{N} w_{i j} \\underbrace{(x_i - x_j)}_{\\Delta_{i, j}}\n\t\\right.\\end{split}\n\\end{equation*}\nThe second derivative of a function $f$ essentially averages the differences in signal strength in the neighborhood of a point $t$.\nFor real-valued functions this neighborhood only consists of the two infinitesimally close points to the left and to the right of $t$, i.e.\\ $t - h$ and $t + h$.\nThe graph Laplacian represents the same operation, where each point/vertex might however have more than two neighbors that need to be averaged.\n\nBased on the graph Laplacian $L$ we just defined, the graph Fourier basis ${\\{ u_k \\}}_{k = 1}^{N}$ is the set of eigenvectors of $L$.\nIn the rest of this paper we will assume that these eigenvectors $u_k$ are sorted in ascending order w.r.t.\\  their eigenvalues $\\lambda_k$, i.e.\\  $\\lambda_1 \\leq \\lambda_2 \\leq \\cdots \\leq \\lambda_N$.\n\\Cref{fig:sgt:graphFourier} shows how this definition generalizes the Fourier basis from the real number line to an arbitrary graph.\nIt also shows that the eigenvalues $\\lambda_k$ of the graph Fourier basis encode some notion of frequency, just like they do for the classical Fourier basis.\nAnalogous to the classical Fourier transform, the eigenvalues of a graph's Laplacian are therefore also called its \\textit{spectrum}.\n\\begin{figure}[ht]\n\t\\centering\n\t\\makebox[\\textwidth][c]{\\includegraphics[width=\\linewidth]{gfx/sgt/graph-fourier.pdf}}\n\t\\caption{%\n\t\tComparison between the basis functions/vectors of the classical Fourier transform and the graph Fourier transform.\n\t\tFor the eigenfunctions on the upper half only the real cosine components of the complex exponentials are shown.\n\t\t\\source[based on]{Shuman2013}\n\t}\\label{fig:sgt:graphFourier}\n\\end{figure}\n\n\\subsection{Spectral Properties of Graphs}%\n\\label{sec:sgt:spectrum}\n\nNext we will give an intuition for the relation between the spectrum of a graph and its structural properties\\footnote{%\n\tOnly a general overview will be given. For a more detailed discussion we refer to \\citet{Shuman2013}.\n}.\nFor any graph the smallest eigenvalue always is $\\lambda_1 = 0$ with the associated eigenvector $u_1 = \\frac{1}{\\sqrt{N}} {(1, \\dots, 1)}^\\top$ being a uniform signal over all vertices.\nUsing the heat analogy, this simply means that any system in which everything has the same temperature is in an equilibrium state and no heat is flowing.\nMore generally for graphs with $c$ separate connected components the first $c$ eigenvalues are all $0$ since each component can have its own equilibrium temperature without causing heat flow.\nIf the spectrum of a graph is known, this fact can be used to quickly determine whether a graph is connected or not.\n\nAnother meaningful eigenvalue is $\\lambda_2$ and its eigenvector $u_2$, also called the \\textit{Fiedler value} and \\textit{Fiedler vector} respectively.\nAs we have just seen, a Fiedler value of $\\lambda_2 = 0$ means that a graph is not connected.\nMore generally the Fielder value can be interpreted as a measure of overall graph connectivity\\footnote{%\n\tFormally this measure is called \\textit{algebraic connectivity}, as opposed to regular \\textit{graph connectivity}, which is defined as $\\min_{v_i \\in \\mathcal{V}} \\deg(v_i)$.\n}.\nIf there are two clusters of vertices $\\mathcal{V}_+$ and $\\mathcal{V}_-$ in a graph that are connected via relatively few edges (compared to the overall number of edges), the Fielder value is small;\nfor well connected graphs on the other hand the Fiedler value is large.\nUsing the heat analogy, the Fielder value essentially measures the ``width'' of a bottleneck between two parts of a graph through which heat will only flow very slowly or even not at all in case of $\\lambda_2 = 0$.\nThe partitioning of vertices into $\\mathcal{V}_+$ and $\\mathcal{V}_-$ can be retrieved via the Fiedler vector $u_2$;\nvertices with a positive signal strength in $u_2$ are in $\\mathcal{V}_+$, the other vertices are in $\\mathcal{V}_-$.\nThe so called \\textit{spectral clustering} algorithm is based on this relationship.\n\\Cref{fig:sgt:graphFourier} shows how the Fiedler vector $u_2$ partitions a graph via the signs of the vertex signal strengths.\n\nTo summarize, expressing a graph $G$ in terms of the spectrum of its Laplacian $L$ gives access to graph characteristics like its overall connectivity.\nSimilarly to how the low-frequency components of the Fourier transform of a function represent the overall shape of that function, the eigenvectors associated with the small eigenvalues of $L$ represent overall characteristics of $G$.\nThe details of a function or graph on the other hand are encoded in the high-frequency components of its Fourier transform, i.e.\\  the eigenvectors associated with large eigenvalues.\nThis perspective already hints at how spectral graph analysis might be useful to approximate graphs.\n", "meta": {"hexsha": "16aab7fbf3b4d90015e789ba8e489caf492da160", "size": 12698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/content/chapter-spectral-graph-theory.tex", "max_stars_repo_name": "Cortys/ml-seminar", "max_stars_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/content/chapter-spectral-graph-theory.tex", "max_issues_repo_name": "Cortys/ml-seminar", "max_issues_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/content/chapter-spectral-graph-theory.tex", "max_forks_repo_name": "Cortys/ml-seminar", "max_forks_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.0927152318, "max_line_length": 303, "alphanum_fraction": 0.7453929753, "num_tokens": 3513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387914176259, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6678197749954686}}
{"text": "\\documentclass[]{article}\n\n\n\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{hyperref}\n\\usepackage{makecell}\n\\usepackage{url}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{array}\n\\usepackage{times,color}\n\\usepackage[rflt]{floatflt}\n\\usepackage{epsfig,times,graphicx}\n\\usepackage{amsmath,amssymb,amsopn,algorithm,algorithmic,theorem,float,bbm,bm,enumerate,color,multirow}\n\\usepackage{rotating}\n\\usepackage{array}\n%\\usepackage{slashbox}\n\\usepackage{makecell}\n\\usepackage{multirow}\n\\usepackage{hhline}\n\\usepackage{xspace}\n\\usepackage{mathtools}\n\\usepackage{bm}\n\n\\input{notation}\n\n\n\\title{Projection onto Elastic Net Ball}\n\n\\begin{document}\n\t\nHow can we project to an arbitrary norm ball? \n\n\\section{Major Lessons}\nI think the general way of doing this is to go for proximal operators. Proximal operator of a closed proper convex function $f(\\cdot)$ is defined as: \n\\beq \n\\prox_f (\\v) = \\argmin_\\x \\frac{1}{2} \\norm{\\v - \\x}{2}^2 + f(\\x) \n\\eeq \nNote that the objective of the above optimization is strongly convex, so there is a unique minimizer for it. \n\n\\subsection{Generalizing Projection}\nProximal operator is a generalization of projection in the following sense. Remember the indicator of a set $\\cS$, i.e.,\n\\beq \n\\indic_\\cS(\\x) = \n\\begin{cases}\n\t0& \\x \\in \\cS \\\\\n\t\\infty& \\x \\notin \\cS \\\\ \n\\end{cases}\n\\eeq \nThen the proximal operator reduces to Euclidian projection:\n\\beq \n\\prox_f (\\v) = \\argmin_{\\x\\in \\cS} \\frac{1}{2} \\norm{\\v - \\x}{2}^2 = \\Pi_\\cS(\\v) \n\\eeq \n\\subsection{Generalizing Orthogonal Decomposition}\nLet $\\cS$ and $\\cS^\\perp$ be two orthogonal subspaces. Then for any vector $\\v$ we have:\n\\beq \n\\v = \\Pi_{\\cS}(\\v) + \\Pi_{\\cS^\\perp}(\\v)  \n\\eeq \nWe have the same decomposition for closed proper convex $f$ and its convex conjugate $f^*(\\y) = \\argmin_\\x \\x^T\\y - f(\\x)$:\n\\beq \n\\v = \\prox_f (\\v) + \\prox_{f^*} (\\v)\n\\eeq \nThe above result is known as {\\bf Moreau Decomposition}. \n\n{\\bf Proof:}\nFor the $\\u = \\prox_f (\\v)$, from the optimality condition we should have:\n\\beq \n\\v - \\u \\in \\partial f(\\u) \\iff \\u \\in \\partial f^*(\\v - \\u ) \\iff (\\v - \\u) = \\prox_{f^*}(\\u)\n\\eeq \n\nAbove, we used a useful property which relates subgradient of $f$ and $f^*$:\n\\beq \n\\u \\in \\partial f(\\v) \\iff \\v \\in \\partial f^*(\\u) \\iff f^*(\\u) + f(\\v) = \\u^T \\v \n\\eeq \n\n\\subsection{Moreau Decomposotion for a Norm}\nHere we first need to following for an arbitrary norm $f(\\x) = \\norm{\\x}{}$:\n\\beq \nf^*(\\y) = \\indic_{\\norm{\\cdot}{*} \\leq 1}(\\y)\n\\eeq \nwhere $\\norm{\\cdot}{*}$ is the daul norm. In other words, the convex conjugate of a norm is the indicator function of its dual norm. \n\nFrom the above equality and the Moreau decomposition we get: \n\\be \n\\v \n&= \\prox_{\\norm{\\cdot}{}} + \\prox_{\\indic_{\\norm{\\cdot}{*} \\leq 1}(\\cdot)} \n\\\\ \n&= \\prox_{\\norm{\\cdot}{}} + \\Pi_{\\indic_{\\norm{\\cdot}{*} \\leq 1}} (\\v)\n\\ee \nAbove equality gives us a way to switch between proximal operator $\\prox$ and projection $\\Pi$.\n\n\n\n\n\\end{document}", "meta": {"hexsha": "457153c87aae7d21c095115c3593f4267956b54d", "size": 2921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/latex2md/2018-01-29-projection-onto-elasticnet-ball.tex", "max_stars_repo_name": "VincentTam/aasiaeet.github.io", "max_stars_repo_head_hexsha": "2d2996f259318c50a2c65e5c2ba4bb08f5deea84", "max_stars_repo_licenses": ["BSD-3-Clause", "MIT"], "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/latex2md/2018-01-29-projection-onto-elasticnet-ball.tex", "max_issues_repo_name": "VincentTam/aasiaeet.github.io", "max_issues_repo_head_hexsha": "2d2996f259318c50a2c65e5c2ba4bb08f5deea84", "max_issues_repo_licenses": ["BSD-3-Clause", "MIT"], "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/latex2md/2018-01-29-projection-onto-elasticnet-ball.tex", "max_forks_repo_name": "VincentTam/aasiaeet.github.io", "max_forks_repo_head_hexsha": "2d2996f259318c50a2c65e5c2ba4bb08f5deea84", "max_forks_repo_licenses": ["BSD-3-Clause", "MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-05-24T12:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-13T17:12:10.000Z", "avg_line_length": 30.1134020619, "max_line_length": 150, "alphanum_fraction": 0.6826429305, "num_tokens": 1011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.6678197738358145}}
{"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\n\\title{MATH 505B Homework 4}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 6.14.1}\n\n\\begin{align*}\n\\langle\\ \\mathbf{x}, \\mathbf{Py} \\rangle &= \\sum_{k\\in \\theta} x_k (\\mathbf{Py})_k\\pi_k \\\\\n&= \\sum_{k\\in \\theta} x_k (\\sum_jp_{kj}y_j)\\pi_k\\\\\n&= \\sum_{k\\in \\theta} x_k (\\sum_jp_{kj}\\pi_ky_j)\\\\\n&= \\sum_{k,j} x_k p_{kj}\\pi_ky_j\\\\\n&= \\sum_{k,j} x_k (p_{jk}\\pi_jy_j) \\text{ using reversibility criterion  } \\pi_jp_{jk} = \\pi_kp_{kj}\\\\ \n&= \\sum_{j} p_{jk}x_k \\pi_jy_j\\\\\n&= \\sum_{j \\in \\theta} (\\sum_k p_{jk}x_k) \\pi_jy_j\\\\\n&= \\langle \\mathbf{Px,y} \\rangle\n\\end{align*}\n\n\\section*{Problem 6.14.2}\nFor reversibility: $\\pi_ip_{ij} = \\pi_jp_{ji}$:\n\n$p'_{ij}= b_{ij}g_{ij} = \\frac{\\pi_jg_{ji}g_{ij}}{\\pi_ig_{ij}+\\pi_jg_{ji}}$ and $p'_{ji} = \\frac{\\pi_ig_{ij}g_{ij}}{\\pi_ig_{ij}+\\pi_jg_{ji}}$\n\nHence, $\\pi_ip'_{ij} = \\pi_jp'_{ji}$ and hence $b_{ij}$ satisfies reversibility criterion besides $ 0 \\leq b_{ij} \\leq 1$.\n\n\\section*{Problem 7.2.1}\n\\subsection*{7.2.1(a)}\n\n\\begin{align*}\n\\{E(|X+Y|^p)\\}^{1/p} &= \\{E|X^p|\\}^{1/p} + \\{E|Y^p|^{1/p}\\}\\\\\nE[|X|] &= E[|X_n+X-X_n|]\\\\\n\\{E[|X|^p]\\}^{1/p} &= \\{E[|X_n+X-X_n|^p]\\}^{1/p}\\\\\n&\\leq \\{E[|X_n|^p]\\}^{1/p}+\\{E[|X-X_n|^p]\\}^{1/p}\\\\\n\\implies \\lim_{n \\longrightarrow \\infty} \\inf E[|X|^p] &\\leq E[|X_n|^p]^{1/p}\\numberthis \\label{eqn1} \\\\\n\\end{align*}\n\nSimilarly,\n\n\\begin{align*}\n\\{E[|X_n|^p]\\}^{1/p} &= \\{E[|X_n-X+X|^p]\\}^{1/p}\\\\\n&\\leq \\{E[|X|^p]\\}^{1/p} + \\{E[|X_n-X|]\\}^{1/p}\\\\\n\\implies  \\lim_{n \\longrightarrow \\infty} \\sup E[|X_n|^p] &\\leq E[|X|^p] \\numberthis \\label{eqn2}\n\\end{align*}\n\nCombining \\ref{eqn1}, \\ref{eqn2} : $E[|X_n|^p] \\longrightarrow\nE[|X|^p]$ $p \\geq 1$\n\n\\subsection*{7.2.1(b)}\nUsing $p=1$ in part (a)\n\\subsection*{7.2.1(c)}\nUsing part (a) $E[X_n^2] \\longrightarrow E[X^2]$\n$(X_n \\xrightarrow{2} X) \\Rightarrow (X_n \\xrightarrow{1} X)\\ \\implies E[X_n] \\longrightarrow E[X]$ and hence $Var(X_n) \\longrightarrow Var(X)$\n\n\\section*{Problem 7.2.3}\n\nConsider $k \\geq 0$, $ n\\geq 1$,  $X_n=k/n \\leq X < (k+1)/n$. \n$X-1/n \\leq X_n \\leq X$\n\nDefine similarly $Y_n$. $Y_n,X_n$ are independent by definition\n\n\n$E[X_n] \\longrightarrow E[X]$ and $E[Y_n] \\longrightarrow E[Y]$\n\nThus, using independence and convergence relations $E[X_nY_n] = E[X_n]E[Y_n] \\longrightarrow E[X]E[Y] $\n\nNow,\n\\begin{eqnarray*}\n(X-1/n)(Y-1/n)\\leq X_nY_n \\leq XY\\\\\n\\implies E[(X-1/n)(Y-1/n)]\\leq E[X_nY_n] \\leq E[XY]\\\\\nE[(X-1/n)(Y-1/n)] = E[XY-\\frac{X+Y}{n}+1/n^2] \n\\implies E[X_nY_n] \\longrightarrow E[XY]\n\\end{eqnarray*}\n\nThus combining, the above two results $E[X_nY_n] \\longrightarrow E[XY]$ and $E[X_nY_n] \\longrightarrow E[X][Y]$ \nwe get $E[XY]=E[X]E[Y]$\n\n\\section*{Problem 7.2.10}\n\n$\\sum_r X_r \\sim Poisson(\\sum_r \\lambda_r)$\n\nDefine $t=\\sum_{r=1}^n \\lambda_r$:\n\\begin{align*}\nP(\\sum_r X_r \\leq x) &= \\sum_{i=0}^x \\frac{e^{-t}t^i}{i!}\\\\\n\\lim_{n \\longrightarrow \\infty}P(\\sum_r X_r \\leq x)  &= \\begin{cases} 0 & t\\longrightarrow \\infty\\\\\nPoisson(t) & t \\text{is finite}\n\\end{cases}\n\\end{align*}\n\n\\section*{Problem 7.4.1}\n\n\\begin{align*}\nE[X_1] &= 0*(1-\\frac{1}{n\\log{n}} + 0*\\frac{1}{2n\\log n}\\\\\n&=0\\\\\nE[X_1^2] &= \\frac{2n^2}{2n\\log{n}}+0*(1-\\frac{1}{n\\log{n}}\\\\\n&= \\frac{n}{\\log{n}}\\\\\nE[(\\frac{1}{n}S_n-0)^2] &= \\frac{1}{n^2}Var(S_n)\\\\\n&= \\frac{1}{n^2}\\frac{n}{\\log{n}}\\\\\n&= \\frac{1}{n \\log{n}}\n&\\longrightarrow 0\n\\end{align*}\n\n$\\sum_i P(|X_i| \\geq i) \n\\longrightarrow \\infty$ Hence, using Borel-Cantelli Lemma(7.3.10b)\nwe have $P(|X_j| \\geq j) =1$ for some $j$\n$|X_j| = |S_j-S_{j-1}| \\geq j$ and hence $S_j/j$ diverges.\n\n\n\\section*{Problem 7.5.1}\nDefine $I_{i}(j)$ as the indicator variable denoting if the $X_j$ lies in the $i^{th}$ interval,\n\\begin{align*}\n\\log{R_m} &= \\sum_{i=1}^n Z_m(i) \\log p_i\\\\\n&= \\sum_{i=1}^n \\sum_{j=1}^m I_i(j) p_i\\\\\n\\end{align*}\nDefine $\\sum_{i=1}^m I_i(j)=Y_j$, then $\\log{R_m} = \\sum_{j=1}^m Y_j$ \n\n$E[Y_j]=\\sum_{i=1}^np_i\\log{p_i}=-h$\nThus, by strong law of convergence $\\frac{1}{m}\\sum_{j=1}^m Y_j = \\ \\longrightarrow -h=E[Y_j]$\n\n\\section*{Problem 7.5.3}\nTransient $P(X_n=i|X_0=i)< 1$\n\nUsing strong law $S_n/n \\longrightarrow E[X_1]$ If $E[X_1]\\neq 0$ then $P[S_n=0|S_1=0] < 1$ as $S_n=0$ happens only finitely often\n\n\\section*{Problem 7.7.1}\n\\begin{align*}\nE[X_iX_j] &= E[E[X_iX_j|X_0,X_1,\\dots, X_{j-1}]]\\\\\n&= E[E[X_i(S_j-S_{j-1})|X_0,X_1,\\dots,X_{j-1}]]\\\\\n&= E[X_i(E[S_j-S_{j-1}|X_0,X_1,\\dots,X_{j-1}])]\\\\\n&= E[X_i(E[S_j|X_0,X_1,\\dots,X_{j-1}]-S_{j-1})]\\\\\n&= E[X_i(S_{j-1}-S_{j-1})]\\\\\n&=0\n\\end{align*}\n\n\\section*{Problem 7.7.3}\n\\begin{align*}\nE[X_{n+1}|X_0,X_1,\\dots,X_n] &= aX_n+X_{n-1} \\\\\nE[S_{n+1}|X_0,X_1,\\dots, X_n] &= E[\\alpha X_{n+1}+X_{n}|X_0,X_1,\\dots,X_n]\\\\\n&= \\alpha E[X_{n+1}|X_0,X_1,\\dots, X_n] + X_n\\\\\n&= (\\alpha a+1)X_n + \\alpha bX_{n-1}\\\\\n&= S_n = \\alpha X_n+X_{n-1}\\\\\n\\implies \\alpha = \\frac{1}{1-a}, b=\\frac{1}{\\alpha}\n\\end{align*}\n\n\\section*{Problem 7.7.4}\n$X_n$: Net profit per unit stake on $n^{th}$ play.\n\n$S_{i} = S_{i-1}+f_{i}(X_1,X_2,\\dots,X_i)$ \nsuch that $S_1=X_1Y$\n\nThus, $S_{n} = \\sum_{i=1}^n X_if_{i-1}(X_1,X_2,\\dots, X_{i-1})$\n\n\\begin{align*}\nS_{n+1} &=  S_n + f_{n+1}(X_1,X_2,\\dots, X_n)X_{n+1}\\\\\nE[S_{n+1}-S_n|X_1,X_2,\\dots,X_n] &= E[X_{n+1}f_{n+1}(X_1,X_2,\\dots, X_n)|X_1,X_2,\\dots,X_n]\\\\ \n&= f_{n+1}(X_1,X_2,\\dots, X_n)E[X_{n+1}|X_1,X_2,\\dots,X_n]\\\\\n&= 0\\\\\n\\implies E[S_{n+1}|X_1,X_2,\\dots,X_n] &= S_n\n\\end{align*}\n\n\\section*{Problem 7.8.1}\n$E[X_i]=0$ \nBy Doob-Kolmogorov inquality: \n\n\\begin{align*}\nP(\\max_{i\\leq j \\leq n} |S_j| > \\epsilon) &\\leq \\frac{1}{\\epsilon^2} \\sum_{j=1}^{n}E[S_n^2]\\\\\nE[S_n^2] &= Var(S_n)+E[S_n]^2\\\\\n&= Var(S_n)\\\\\n&= \\sum Var(X_i)\\\\\n\\implies P(\\max_{i\\leq j \\leq n} |S_j| > \\epsilon) \\leq \\frac{1}{\\epsilon^2} \\sum_{j=1}^{n}Var(X_j)\n\\end{align*}\n\n\\section*{Problem 7.8.3}\nBy theorem 7.8.1 $S_n$ converges to $S$ almost surely\nNow, using the above proved fact that $S_n \\longrightarrow S \\implies Var(S_n) \\longrightarrow Var(S) \\implies Var(S) \\longrightarrow 0$\n\n\\end{document}", "meta": {"hexsha": "590bf3b6462174163f76c180e40336c1feba8e38", "size": 6047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-505B/HW4/hw4.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-505B/HW4/hw4.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-505B/HW4/hw4.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": 32.5107526882, "max_line_length": 143, "alphanum_fraction": 0.6060856623, "num_tokens": 2926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.6678175903580081}}
{"text": "\\section*{Appendix}\n\\begingroup\n\\def\\thetheorem{\\ref{lem:decrease}}\n\\begin{lemma}\nIf $f_i$ is continuously differentiable and log-concave, then the functions $l_i,d_i,v_i$ are continuous, strictly decreasing, and\n\\[l_i(p) < d_i(p) < v_i(p) \\text{ for all }p.\\]\n\\end{lemma}\n\\addtocounter{theorem}{-1}\n\\endgroup\n\\begin{proof}\nContinuity of $F_i,f_i,f'_i$ implies that of $l_i,d_i,v_i$. It's known~\\cite{concave} that log-concavity of $f_i$ implies log-concavity of both $F_i$ and $1-F_i$. As a result, $l_i$, $d_i$, and $v_i$ are derivatives of strictly concave functions; therefore, they are strictly decreasing. In particular, each of\n\n\\[v'_i(p) = \\frac{f'_i(p)}{F_i(p)} - \\frac{f_i(p)^2}{F_i(p)^2},\\quad\nl'_i(p) = \\frac{-f'_i(p)}{1-F_i(p)} - \\frac{f_i(p)^2}{(1-F_i(p))^2},\\]\n\nare negative for all $p$, so we conclude that\n\n\\begin{align*}\nd_i(p) - v_i(p)\n= \\frac{f'_i(p)}{f_i(p)} - \\frac{f_i(p)}{F_i(p)}\n&= \\frac{F_i(p)}{f_i(p)} v'_i(p)\n< 0,\n\\\\l_i(p) - d_i(p)\n= -\\frac{f'_i(p)}{f_i(p)} -\\frac{f_i(p)}{1-F_i(p)}\n&= \\frac{1-F_i(p)}{f_i(p)} l'_i(p)\n< 0.\n\\end{align*}\n\n\\end{proof}\n\n\\begingroup\n\\def\\thetheorem{\\ref{thm:uniq-max}}\n\\begin{theorem}\nSuppose that for all $j$, $f_j$ is continuously differentiable and log-concave. Then the unique maximizer of $\\Pr(P_i=p\\mid E^L_i,E^W_i)$ is given by the unique zero of\n\\[Q_i(p) = \\sum_{j \\succ i} l_j(p) + \\sum_{j \\sim i} d_j(p) + \\sum_{j \\prec i} v_j(p).\\]\n\\end{theorem}\n\\addtocounter{theorem}{-1}\n\\endgroup\n\n\\begin{proof}\nFirst, we rank the players by their buckets according to $\\floor{P_j/\\epsilon}$, and take the limiting probabilities as $\\epsilon\\rightarrow 0$:\n\\begin{align*}\n    \\Pr(\\floor{\\frac{P_j}\\epsilon} > \\floor{\\frac{p}\\epsilon})\n    &= \\Pr(p_j \\ge \\epsilon\\floor{\\frac{p}\\epsilon} + \\epsilon)\n    \\\\&= 1 - F_j(\\epsilon\\floor{\\frac{p}\\epsilon} + \\epsilon)\n    \\rightarrow 1 - F_j(p),\n    \\\\\\Pr(\\floor{\\frac{P_j}\\epsilon} < \\floor{\\frac{p}\\epsilon})\n    &= \\Pr(p_j < \\epsilon\\floor{\\frac{p}\\epsilon})\n    \\\\&= F_j(\\epsilon\\floor{\\frac{p}\\epsilon})\n    \\rightarrow F_j(p),\n    \\\\\\frac 1\\epsilon \\Pr(\\floor{\\frac{P_j}\\epsilon} = \\floor{\\frac{p}\\epsilon})\n    &= \\frac 1\\epsilon \\Pr(\\epsilon\\floor{\\frac{p}\\epsilon} \\le P_j < \\epsilon\\floor{\\frac{p}\\epsilon} + \\epsilon)\n    \\\\&= \\frac 1\\epsilon\\left( F_j(\\epsilon\\floor{\\frac{p}\\epsilon} + \\epsilon) - F_j(\\epsilon\\floor{\\frac{p}\\epsilon}) \\right)\n    \\rightarrow f_j(p).\n\\end{align*}\n\nLet $L_{jp}^\\epsilon$, $W_{jp}^\\epsilon$, and $D_{jp}^\\epsilon$ be shorthand for the events $\\floor{\\frac{P_j}\\epsilon} > \\floor{\\frac{p}\\epsilon}$, $\\floor{\\frac{P_j}\\epsilon} < \\floor{\\frac{p}\\epsilon}$, and $\\floor{\\frac{P_j}\\epsilon} = \\floor{\\frac{p}\\epsilon}$. respectively. These correspond to a player who performs at $p$ losing, winning, and drawing against $j$, respectively, when outcomes are determined by $\\epsilon$-buckets. Then,\n\\begin{align*}\n\\Pr(E^W_i,E^L_i\\mid P_i=p)\n&= \\lim_{\\epsilon\\rightarrow 0}\n\\prod_{j \\succ i} \\Pr(L_{jp}^\\epsilon)\n\\prod_{j \\prec i} \\Pr(W_{jp}^\\epsilon)\n\\prod_{j \\sim i, j\\ne i} \\frac{\\Pr(D_{jp}^\\epsilon)}\\epsilon\n\\\\&= \\prod_{j \\succ i} (1 - F_j(p)) \\prod_{j \\prec i} F_j(p) \\prod_{j \\sim i, j\\ne i} f_j(p),\n\\\\\\Pr(P_i=p \\mid E^L_i,E^W_i)\n&\\propto f_i(p) \\Pr(E^L_i,E^W_i\\mid P_i=p)\n\\\\&= \\prod_{j \\succ i} (1 - F_j(p)) \\prod_{j \\prec i} F_j(p) \\prod_{j \\sim i} f_j(p),\n\\\\\\ddp\\ln \\Pr(P_i=p \\mid E^L_i,& E^W_i) = \\sum_{j \\succ i} l_j(p) + \\sum_{j \\prec i} v_j(p) + \\sum_{j \\sim i} d_j(p) = Q_i(p).\n\\end{align*}\n\nSince \\Cref{lem:decrease} tells us that $Q_i$ is strictly decreasing, it only remains to show that it has a zero. If the zero exists, it must be unique and it will be the unique maximum of $\\Pr(P_i=p \\mid E^L_i,E^W_i)$.\n\nTo start, we want to prove the existence of $p^*$ such that $Q_i(p^*) < 0$. Note that it's not possible to have $f'_j(p) \\ge 0$ for all $p$, as in that case the density would integrate to either zero or infinity. Thus, for each $j$ such that $j\\sim i$, we can choose $p_j$ such that $f'_j(p_j) < 0$, and so $d_j(p_j) < 0$. Let $\\alpha = -\\sum_{j\\sim i} d_j(p_j) > 0$.\n\nLet $n = |\\{j:\\,j \\prec i\\}|$. For each $j$ such that $j \\prec i$, since $\\lim_{p\\rightarrow\\infty}v_j(p) = 0/1 = 0$, we can choose $p_j$ such that $v_j(p_j) < \\alpha/n$. Let $p^* = \\max_{j\\preceq i} p_j$. Then,\n\\[\n\\sum_{j \\succ i} l_j(p^*) \\le 0, \\quad \\sum_{j \\sim i} d_j(p^*) \\le -\\alpha, \\quad \\sum_{j \\prec i} v_j(p^*) < \\alpha.\n\\]\n\nTherefore,\n\\begin{align*}\nQ_i(p^*)\n&= \\sum_{j \\succ i} l_j(p^*) + \\sum_{j \\sim i} d_j(p^*) + \\sum_{j \\prec i} v_j(p^*)\n\\\\&< 0 - \\alpha + \\alpha = 0.\n\\end{align*}\n\nBy a symmetric argument, there also exists some $q^*$ for which $Q_i(q^*) > 0$. By the intermediate value theorem with $Q_i$ continuous, there exists $p\\in (q^*,p^*)$ such that $Q_i(p) = 0$, as desired.\n\\end{proof}", "meta": {"hexsha": "9db7d974d380aced7dc8ba9bf1d82d37365e6590", "size": 4748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/source/sections/appendix.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/appendix.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/appendix.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": 53.9545454545, "max_line_length": 443, "alphanum_fraction": 0.6358466723, "num_tokens": 1834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6678175876756287}}
{"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\\subsubsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Calibrations Curve Computing\n   \\item Generate sample data\n   \\item Call algorithm\n   \\item Display results\n   \\item Interpolate values\n   \\item Plot results\n\\end{itemize}\n\\begin{lstlisting}[style=mcode]\nclose all\n\\end{lstlisting}\n\n\n\\subsubsection*{Calibrations Curve Computing}\n\n\\begin{par}\nExample for algorithm CCC.\n\\end{par} \\vspace{1em}\n\\begin{par}\nCalibration Curves Computing is a software for the evaluation of instrument calibration curves\n\\end{par} \\vspace{1em}\n\n\n\\subsubsection*{Generate sample data}\n\n\\begin{par}\nAn dependence of amplitude error (Volts, ppm) on signal frequency (Hz) of an ADC was measured and uncertainties of measurement was estimated. The uncertainty of frequency can be considered as negligible.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\n%3.7+12.*x+3.*x.^2\nf = [10 1e2 1e3 1e4 1e5];\nerr = [19.700 32.700 69.700 90.700 148.700];\nerr_unc = [4 10 13 20 33];\n\\end{lstlisting}\n\\begin{par}\nSet independent and dependent variables for \\lstinline{CCC} algorithm. Lets operate in semi logarithm space for easy plotting.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI = [];\nDI.x.v = log10(f);\nDI.x.u = [];\nDI.y.v = err;\nDI.y.u = err_unc;\n\\end{lstlisting}\n\\begin{par}\nSuppose the ADC has quadratic dependence of the error on the signal frequency.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.exponents.v = [0 1 2];\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{CCC} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDO = qwtb('CCC', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: CCC wrapper: model was set by CCC wrapper to a value `Model 2a`.\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Display results}\n\n\\begin{par}\nResults is\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\ndisp(['offset          : ' num2str(DO.coefs.v(1)) ' +- ' num2str(DO.coefs.u(1))])\ndisp(['linear coeff.   : ' num2str(DO.coefs.v(2)) ' +- ' num2str(DO.coefs.u(2))])\ndisp(['quadratic coeff.: ' num2str(DO.coefs.v(3)) ' +- ' num2str(DO.coefs.u(3))])\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\noffset          : 12.6828 +- 16.9884\nlinear coeff.   : 1.9434 +- 19.1198\nquadratic coeff.: 4.9055 +- 3.9754\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Interpolate values}\n\n\\begin{par}\nInterpolate fitted polynom at values \\lstinline{t}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nt = [0:0.1:6];\nty = DO.func.v(t, DO.coefs.v);\n\\end{lstlisting}\n\\begin{par}\nCalculate uncertainties of interpolated values (\\lstinline{S} is sensitivity matrix, \\lstinline{CC} is covariance matrix of coefficients, \\lstinline{CT} is covariance matrix of interpolated values, \\lstinline{uty} is uncertainty of interpolated values).\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nfor i = 1:length(t);\n        S = t(i).^DI.exponents.v;\n        CC = diag(DO.coefs.u,0)*DO.coefs.c*diag(DO.coefs.u,0);\n        CT(i)=S*CC*S';\nend\nuty=CT.^0.5;\n\\end{lstlisting}\n\n\n\\subsubsection*{Plot results}\n\n\\begin{lstlisting}[style=mcode]\nhold on\nerrorbar(DI.x.v, DI.y.v, DI.y.u, 'xb')\nerrorbar(DI.x.v, DO.yhat.v, DO.yhat.u, 'og')\nplot(t, ty, '-r');\nplot(t, ty + uty, '-r');\nplot(t, ty - uty, '-r');\nxlabel('log(f)')\nylabel('error of amplitude')\nlegend('original data','fitted values','interpolated values', 'uncer. of int. val.','location','southeast')\nhold off\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/CCC_alg_example_01.pdf}\n\\end{center}\n\n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "9cc368dd3afb9e1e3ab66af1edf9b53a236ad1e3", "size": 4003, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_CCC.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_CCC.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_CCC.tex", "max_forks_repo_name": "qwtb/qwtb", "max_forks_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-11T02:12:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-17T12:59:18.000Z", "avg_line_length": 26.6866666667, "max_line_length": 253, "alphanum_fraction": 0.7007244567, "num_tokens": 1289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6676569308141738}}
{"text": "\\section*{Web Appendix D}\n\nThe publication bias and the \\textit{p}-hacking models have been defined as a selection model and a mixture model, respectively. To appreciate the difference between the models, and relate the selection biases to them, consider the following example. We want to perform a meta-analysis based on 10 studies. In the ideal situation with no publication bias and no \\textit{p}-hacking, 10 researchers perform their studies fairly, observe an effect size from its distribution $\\phi(x_{i}\\mid\\theta_i,\\sigma^2_{i})$ and publish the result. To perform our meta-analysis, we do not need much more than to estimate $\\theta_0$ by using $\\phi(x_{i}\\mid\\theta_i,\\sigma^2_{i})$ and $\\phi(\\theta_{i}\\mid\\theta_0,\\tau^2)$.\n\nIn a publication bias scenario, some of these 10 studies may not be published because their \\textit{p}-values $u_i$ are too large. Let us say that the first 3 have a \\textit{p}-value smaller than $0.025$ (group A), the following 4 between $0.025$ and $0.05$ (group B), and the remaining 3 larger than $0.05$ (group C). With an editor publishing all studies ($\\rho_{1} = 1$) with $u_i < 0.025$, half ($\\rho_{2} = 0.5$) of those with $0.025 \\leq u_i < 0.05$ and one-third ($\\rho_{3} = 0.33$) when $u_i \\geq 0.05$, we would expect to see all 3 studies in group A, 2 of Group B and only one of group $C$. It is clear that the density is not anymore the original $\\phi(x_{i}\\mid\\theta_i,\\sigma^2_{i})$, but a transformed one $f(x_{i}\\mid\\theta_i,\\sigma^2_{i})$ for which some values of $\\theta_i$ are underrepresented by the effect of a selection mechanism. In this case, by the selection probability function $w(u_i) = 1_{[0,0.025)}(u_i) + 0.5 \\cdot 1_{[0.25,0.05)}(u_i) + 0.33 \\cdot 1_{[0.05, 1]}(u_i)$. In practice we do not know $\\rho_{1}$, $\\rho_{2}$ and $\\rho_{3}$, and we need to estimate them in our model. In the ideal situation, they are all equal to 1, that means no selection bias, so $f(x_{i}\\mid\\theta_{i},\\sigma^2_{i}) = \\phi(x_{i}\\mid\\theta_i,\\sigma^2_{i})$.\n\nIn the \\textit{p}-hacking scenario, instead, we observe all our 10 studies, but not with their original effect size, because they have been modified in order to reach a specific significance value $\\alpha$. In mathematical terms, $x_i$ does not come from the original Gaussian $\\phi(x_{i}\\mid\\theta_i,\\sigma^2_{i})$ but from a truncated Gaussian $\\phi_\\alpha^{\\star}(x_{i}\\mid\\theta_i,\\sigma^2_{i})$, where the truncation excludes the possibility to get an $u_i$ larger than $\\alpha$. If every researchers decided to $p$-hack all studies at the same level, let us say $\\alpha = 0.05$, we could make inference on $\\theta_i$ using $\\phi_{0.05}^{\\star}(x_{i}\\mid\\theta,\\sigma^2_{i})$ and $\\phi(\\theta_{i}\\mid\\theta_0,\\tau^2)$. But researchers may choose to $p$-hack at a different $\\alpha$, for example at $\\alpha_1 = 0.025$ with probability $\\pi_1=  0.1$, at $\\alpha_2 = 0.05$ with probability $\\pi_2 = 0.7$ and no-hack ($\\alpha_3 = 1$) with probability $\\pi_3 = 0.2$. So the density from which our 10 studies will be in this case a mixture of the three truncated Gaussian, with mixing distribution $\\omega(\\alpha) = 0.2 \\cdot 1(\\alpha = 0.025) + 0.7 \\cdot 1(\\alpha = 0.05) + 0.2 \\cdot 1(\\alpha = 1)$. Also in this case we cannot know the probabilities $\\pi_1$, $\\pi_2$ and $\\pi_3$ in advance and we need to estimate them from the data. Here the ideal situation, no $p$-hacking, is $\\pi_1 = \\pi_2 = 0$ and $\\pi_3 = 1$.\n\nThe main difference between the models is then related to $\\theta_i$. The publication bias mechanism affects $\\phi(x_{i}\\mid\\theta_i,\\sigma^2_{i})$ once the study is done, i.e., we have already observed an instance of $\\theta_i$. If the study is not selected, we generate a new $\\theta_i$, i.e., we make a new study until we reach out 10. In contrast, in the $p$-hacking mechanism all studies are retained, just modified, so we keep all the generated $\\theta_i$. This difference affects the distribution of $\\theta_i$, $\\phi(\\theta_{i}\\mid\\theta_0,\\tau^2)$. If $\\theta_i = \\theta$ in all studies (fixed effect meta-analysis), it does not matter.\n", "meta": {"hexsha": "d914562ac17f608b0ca2cb1a17151b788066e331", "size": 4072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WebAppendix_D.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_D.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_D.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": 407.2, "max_line_length": 1416, "alphanum_fraction": 0.7170923379, "num_tokens": 1257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.6676569306946357}}
{"text": "% Created by Matthew Riehl  matthew.e.riehl@gmail.com\r\n% Copyright (c) <2021>, <matthew.e.riehl@gmail.com>\r\n% All rights reserved.\r\n\r\n% This source code is licensed under the MIT license found in the\r\n% README file in the root directory of this source tree. \r\n%\r\n\r\n\r\n\\documentclass[]{article}\r\n\\usepackage{fullpage}\r\n\\usepackage{tikz}\r\n\\usepackage{amsmath}\r\n\\usepackage{pgfplots}\r\n\\pgfplotsset{compat=newest}\r\n\\title{Projectile Motion}\r\n\\author{Dr. Matthew Riehl}\r\n\\date {17 August 2021}\r\n\r\n\r\n\r\n\\begin{document}\r\n\t\r\n\t\\section*{Projectile Motion}\r\n\tMotion of object with $x$-component and $y$-component which are independent of each other.  Can  be described with parametric equations ($x=f(t)\\ \\text{and }y=f(t)$).  Initial velocity is: $$\\vec{v}_0=v_{0x}\\hat\\i+v_{0y}\\hat\\j$$ and $x$- and $y$-components are $$v_{x0}=v_0\\cos{\\theta _0}\\text{ and }v_{y0}=v_0\\sin{\\theta _0}$$ where $\\theta _0$ is the angle between $v_0$ and the positive $x$ direction.\r\n\t\r\n\t\r\n\t\\begin{center}\r\n\t\t\\begin{tikzpicture}[scale=1]\r\n\t\t\t\\draw[very thin,color=gray!50] (0,0) grid (4,4);\r\n\t\t\t\\draw[->, blue] (0,0) -- (4,0) node[below right] {$x$};\r\n\t\t\t\\draw[->, blue] (0,0) -- (0,4) node[left] {$y$};\r\n\t\t\t\\draw[-stealth,red, line width =2pt] (0,0) -- (3.7,2.8) node[right]{$v_0$};\r\n\t\t\t\\draw[-stealth, line width = 1.5pt, green!60!black] (-.1,0) -- (-.1,2.8) node[left]{$v_{0y}$};\r\n\t\t\t\\draw[-stealth, line width = 1.5pt, yellow!60!black] (0,-.1) -- (3.7,-.1) node[below]{$v_{0x}$};\r\n\t\t\t\\draw[<->, red, thick] (1,0) arc (0:37.12:1cm) node[below right]{\\ \\footnotesize $\\theta=37\\,^\\circ$};\r\n\t\t\\end{tikzpicture}\r\n\t\\end{center}\r\n\t\r\n\tMotion is split into $x$-component and $y$-component.  Typically, $x$ is horizontal (no acceleration) and $y$ is vertical (acceleration due to gravity, $a=-9.81\\,\\text{m/s}^2$).  If $v_0=12\\,\\text{m/s}$ and $\\theta=37^\\circ$,  the motion is:\r\n\t\r\n\r\n\t\t\\begin{tikzpicture}[scale=1]\r\n\t\t\t\\draw[very thin,color=gray!50,step=1cm] (0,0) grid (15.5,3.5);\r\n\t\t\t\\draw[->, blue] (0,0) -- (15.5,0) node[below right] {$x$};\r\n\t\t\t\\draw[->, blue] (0,0) -- (0,3.5) node[left] {$y$};\r\n\t\t\t\\node[below left] at (0,0) {\\footnotesize $0$};\r\n\t\t\t\\foreach \\x in {1,2,...,15}\r\n\t\t\t\\draw[shift={(\\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {\\footnotesize $\\x$};\r\n\t\t\t\\foreach \\x in {1,2,3}\r\n\t\t\t\\draw[shift={(0,\\x)}] (2pt, 0pt) -- (-2pt,0pt) node[left] {\\footnotesize $\\x$};\r\n\t\t\t\\draw[red, thick, domain=0:1.48, samples=100] plot ({12*cos(37.12)*\\x}, {-0.5*9.81*\\x^2+12*sin(37.12)*\\x});\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t\\foreach \\x in {0,.1,.2,...,1.4,1.48}\r\n\t\t\t{\r\n\t\t\t\t\\node at ({12*cos(37.12)*\\x}, {-0.5*9.81*\\x^2+12*sin(37.12)*\\x})  {\\footnotesize \\textcolor{red}{\\textbullet}};\r\n\t\t\t\t\r\n\t\t\t\t\\draw[-stealth,green!80!black,line width=1.5pt] ({12*cos(37.12)*\\x}, {-0.5*9.81*\\x^2+12*sin(37.12)*\\x}) -- ({12*cos(37.12)*\\x+1.2*cos(37.12)}, {-0.5*9.81*\\x^2+12*sin(37.12)*\\x});\r\n\t\t\t\t\r\n\t\t\t\t\\draw[-stealth,yellow!80!black,line width=1.5pt] ({12*cos(37.12)*\\x}, {-0.5*9.81*\\x^2+12*sin(37.12)*\\x}) -- ({12*cos(37.12)*\\x}, {(-0.5*9.81*\\x^2+12*sin(37.12)*\\x)+0.1*(-9.81*\\x+12*sin(37.12))});\t\r\n\t\t\t}\r\n\t\t\\end{tikzpicture}\r\n\t\twhere the arrows represent the \\colorbox{pink!50}{\\emph{velocity}} in the $x$- and $y$-directions.  The parametric equations for \\colorbox{pink!50}{\\emph{position} vs. time} are: $$\\vec{x}=(12\\cos\\theta_0) t$$ and $$\\vec{y}=(12\\sin\\theta_0) t-\\frac{1}{2}\\cdot9.81 t^2$$ where $\\theta_0=37^\\circ$\r\n\t\\vspace{3cm}\r\n\t\\newpage\r\n\tThis is the same picture, but with different code. This requires the pgfplots package while the first requires only tikz.\\\\\r\n\t\\begin{tikzpicture}\r\n\t\t\\begin{axis}[width=15cm, height=5cm,xlabel={$x$}, ylabel={$y$},grid, thick,ymin=-1,\r\n\t\t\tymax=3,\r\n\t\t\txmin=-1,\r\n\t\t\txmax=15.5]\r\n\t\t\t\r\n\t\t\t\\addplot+[no marks,red,smooth,variable=t,domain=0:1.48]plot ({12*cos(37.12)*t}, {-0.5*9.81*t^2+12*sin(37.12)*t});\r\n\t\t\t\r\n\t\t\t\\foreach \\yValue in {0,.1,.2,...,1.4,1.48} {\r\n\t\t\t\t\\edef\\temp{\\noexpand\\draw [-stealth,green!80!black,line width=1.5pt] (axis cs:9.568*\\yValue,-0.5*9.81*\\yValue^2+12*0.6035*\\yValue) -- (axis cs:1.2*.9586+9.568*\\yValue,-0.5*9.81*\\yValue^2+12*0.6035*\\yValue);}\r\n\t\t\t\t\\temp\r\n\t\t\t\t\r\n\t\t\t\t\\edef\\temp{\\noexpand\\draw[-stealth,yellow!60!black,line width=1.5pt] (12*.7974*\\yValue, -0.5*9.81*\\yValue^2+12*.6035*\\yValue) -- (12*.7974*\\yValue, -0.5*9.81*\\yValue^2+12*.6035*\\yValue+0.1*(-9.81*\\yValue+12*.6035);}\r\n\t\t\t\t\\temp\r\n\t\t\t}\r\n\t\t\\end{axis}\r\n\t\t\r\n\t\\end{tikzpicture}\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "06da1cba6084df95a6bdff9ff328dad6fa08f382", "size": 4359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Projectile Motion.tex", "max_stars_repo_name": "pibondchem/LaTeX-figures", "max_stars_repo_head_hexsha": "30ebb5dbd067849d347954dc2257695acfc56578", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Projectile Motion.tex", "max_issues_repo_name": "pibondchem/LaTeX-figures", "max_issues_repo_head_hexsha": "30ebb5dbd067849d347954dc2257695acfc56578", "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": "Projectile Motion.tex", "max_forks_repo_name": "pibondchem/LaTeX-figures", "max_forks_repo_head_hexsha": "30ebb5dbd067849d347954dc2257695acfc56578", "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": 49.5340909091, "max_line_length": 406, "alphanum_fraction": 0.6040376233, "num_tokens": 1849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6676569182249334}}
{"text": "\\subsubsection{Proof of Safety}\n\nThe proof of safety relies on this observation from\nLemma~\\ref{lem:threshold_subsets}: two subsets with at least\na threshold number of validators in each subset will share at least one\nhonest validator.\n\n\\begin{lem}\n\\label{lem:threshold_subsets}\nLet $f$ be the number of malicious validators.\nGiven any two subsets with at least $2f+1$ validators in a system\ncontaining $3f+1$ validators, those two subsets share at least $f+1$ validators.\nThus, these two subsets share at least one honest validator.\n\\end{lem}\n\n\\begin{proof}\nLet $A$ and $B$ be two subsets with at least $2f+1$ validators\nchosen from $N = 3f+1$ validators.\nFrom De Morgan’s laws, we know\n\n\\begin{equation*}\n    A \\cap B = (A^{c} \\cup B^{c})^{c}.\n\\end{equation*}\n\n\\noindent\nHere, $A^{c}$ denotes the complement of $A$ (that is, the elements of the\nsystem not in A).\nIn what follows, $\\abs{A}$ denotes the number of elements in $A$.\nThus, we have\n\n\\begin{align*}\n    \\abs{A\\cap B} &= \\abs{(A^{c} \\cup B^{c})^{c}} \\\\\n        &= N - \\abs{A^{c} \\cup B^{c}} \\\\\n        &\\ge N - \\parens{\\abs{A^{c}} + \\abs{B^{c}}} \\\\\n        &\\ge N - 2f \\\\\n        &= f + 1.\n\\end{align*}\n\n\\noindent\nTheir intersection shares at least $f+1$ validators and there are $f$\nmalicious validators, so we see that $A$ and $B$ share at least one honest\nvalidator.\n\\end{proof}\n\nThis lemma ensures that honest participants will always agree when\nPreCommitting a proposal or submitting a NextHeight message in a given\nround, as the next two lemmas show.\n\n\\begin{lem}\n\\label{lem:2_honest_precommit}\nIn any round, any 2 honest participants who PreCommit a proposal will PreCommit\nthe same proposal.\n\\end{lem}\n\n\\begin{proof}\nSuppose two honest participants PreCommit proposals $P_{1}$ and $P_{2}$.\nTo PreCommit a proposal, they both must have knowledge of at least $2f+1$\nPreVote messages from participants.\nThere corresponds subsets $S_{1}$ and $S_{2}$, where $S_{1}$ contains\nthe participants who submitted prevotes for $P_{1}$ and $S_{2}$ contains\nthe participants who submitted PreVotes for $P_{2}$.\nBy Lemma~\\ref{lem:threshold_subsets},\n$S_{1}$ and $S_{2}$ share at least one honest participant.\nAn honest participant will only PreVote for one value in a round, so the\nproposals $P_{1}$ and $P_{2}$ must agree.\n\\end{proof}\n\n\\begin{lem}\n\\label{lem:2_honest_nextheight}\nIn any round, any 2 honest participants who submit a NextHeight message\nwill submit a NextHeight message for the same proposal.\n\\end{lem}\n\n\\begin{proof}\nMutatis mutandis, the proof is the same as that of\nLemma~\\ref{lem:2_honest_precommit}.\n\\end{proof}\n\nWe are now able to show the multiple distinct NextHeight messages from honest\nparticipants are not able to occur before the DeadBlockRound.\nThis is a stronger result than Lemma~\\ref{lem:2_honest_nextheight}\nand follows from the fact that a\nthreshold number of LockedValues must occur before submitting a NextHeight\nmessage.\n\n\\begin{lem}\n\\label{lem:2_distinct_nextheight}\nIn any round before the DeadBlockRound, any 2 honest participants\nwho submit a NextHeight message will submit a NextHeight message\nfor the same proposal.\n\\end{lem}\n\n\\begin{proof}\nSuppose we have not yet reached the DeadBlockRound.\nLet $P_{1}$ and $P_{2}$ be NextHeight messages from two honest participants\nwith corresponding signing subsets $S_{1}$ and $S_{2}$.\nWhen $P_{1}$ is signed, all members of $S_{1}$ are supposed to set\nLockedValue to the proposal corresponding to $P_{1}$ because they\nPreCommitted $P_{1}$.\nSimilarly, all members of $S_{2}$ are supposed to set LockedValue\nto the proposal corresponding to $P_{2}$ because they PreCommitted $P_{2}$.\nThis implies $S_{1}$ and $S_{2}$ are two subsets of participants of size\nat least $2f+1$ with LockedValue set.\nOnce an honest participant sets his LockedValue, it is never unset before the\nDeadBlockRound.\nBy Lemma~\\ref{lem:threshold_subsets},\n$S_{1}$ and $S_{2}$ have at least one honest participant in common\nwith his LockedValue set to one proposal.\nThus, we see that the $P_{1}$ and $P_{2}$ NextHeight messages must be\nfor the same proposal when they are submitted by honest participants.\n\\end{proof}\n\nLemma~\\ref{lem:honest_signed_nextround}\nis useful in bounding the number of honest validators who may not\nproceed to the next round.\n\n\\begin{lem}\n\\label{lem:honest_signed_nextround}\nIn order for $2f+1$ validators to enter a round, at least $f+1$\nhonest validators must have signed a NextRound message and at most $f$\nhonest validators failed to sign a NextRound message.\n\\end{lem}\n\n\\begin{proof}\nWe recall an honest validator may not enter a round without a valid\nRoundCertificate.\nA NextRound message contains two objects.\nThe first object is a RoundCertificate for the current round.\nThe second is a RoundShare object for the next round.\nA RoundCertificate contains both round number and block height as internal\nfields, and in order to form a valid Round Certificate, at least $2f+1$\nvalidators must have signed a RoundShare.\nBecause there are at most $f$ dishonest validators who signed for the\nRoundCertificate, at least $f+1$ honest validators must have also signed the\nRoundCertificate.\nThus, at most $f$ honest validators did not sign the RoundCertificate.\n\\end{proof}\n\nOnce validators reach the DeadBlockRound, they will not acknowledge any\nNextHeight messages for any preceding round.\nThis ensures that dishonest validators are not able to fork the chain by\nproducing a block based on those NextHeight messages.\n\n\\begin{lem}\n\\label{lem:sign_rc_dbr}\nIf at least $2f+1$ participants sign the RoundCertificate to the DeadBlockRound,\nthen it is not possible for $2f+1$ participants to form a valid NextHeight\nmessage for any round preceding the DeadBlockRound.\n\\end{lem}\n\n\\begin{proof}\nGiven Lemma~\\ref{lem:honest_signed_nextround}\nand the rule that any honest validator who has signed a\nNextRound message for the DeadBlockRound will never sign or acknowledge any\nNextHeight message from a previous round, at least $f+1$ honest validators must\nhave signed a NextRound message for the DeadBlockRound if there exists a\nRoundCertificate for the DeadBlockRound.\nIf at least $f+1$ honest validators are in the DeadBlockRound,\nat most $f$ honest validators may remain in a round preceding\nthe DeadBlockRound.\nIf at most $f$ honest validators remain in a preceding round, then the malicious\nvalidators are unable to use the signatures of $f$ honest validators to form a\nset of $2f+1$ valid NextHeight messages.\nTherefore, the malicious validators may not form a block from those NextHeight\nmessages.\n\\end{proof}\n\nWith this assurance, we allow for participants to safely proceed to the\nDeadBlockRound even if they previously were locked onto a NextHeight message.\n\n\\begin{lem}\n\\label{lem:safe_unlock_nh_dbr}\nIt is safe for any participant who is locked on a NextHeight message to unlock\nand proceed to the DeadBlockRound upon receiving a RoundCertificate for the\nDeadBlockRound.\n\\end{lem}\n\n\\begin{proof}\nThis follows from Lemma~\\ref{lem:sign_rc_dbr}.\n\\end{proof}\n\nThe previous work allows us to show that we will converge to the EmptyBlock\nwhen a RoundCertificate for the DeadBlockRound exists.\nThis ensures new blocks will be created even if no transactions are performed.\n\n\\begin{lem}\n\\label{lem:emptyblock_rc_dbr}\nThe DeadBlockRound must converge to the EmptyBlock if a RoundCertificate for\nthe DeadBlockRound exists.\n\\end{lem}\n\n\\begin{proof}\nUpon entering the DeadBlockRound, every valid process will immediately PreVote\nthe EmptyBlock and ignore all other contradicting votes.\nThese contradicting votes include any PreVote for a Proposal that is not the\nEmptyBlock, any NextRound message, any PreCommit that is not a PreCommit for\nthe EmptyBlock, and any PreVoteNil or PreCommitNil message as well.\nAs a result of Lemma~\\ref{lem:sign_rc_dbr},\nat least $f+1$ honest validators enter the DeadBlockRound.\nTherefore, the honest validators who enter the DeadBlockRound will only\nprogress once at least $f$ other validators also PreVote in the DeadBlockRound.\nBecause we assume all messages are eventually received, the at most $f$ honest\nvalidators who did not sign the NextRound Certificate for the DeadBlockRound\nwill eventually receive the RoundCertificate for the DeadBlockRound and PreVote\nfor the EmptyBlock in the DeadBlockRound.\nIt follows that the round eventually converges to the EmptyBlock and no other\npossible block.\n\\end{proof}\n\nThe previous work also allows us to show we will not converge to more\nthan one valid block at a given block height.\n\n\\begin{lem}\nIt is not possible for our system to converge to more than one valid block for\nany given block height.\n\\end{lem}\n\n\\begin{proof}\nIf the round enters the DeadBlockRound, then Lemma~\\ref{lem:emptyblock_rc_dbr}\nshows that we will converge to the EmtpyBlock.\nLemma~\\ref{lem:2_distinct_nextheight}\nproves that it is not possible to have more than one proposal for which\nan associated NextHeight message has been validly formed before the\nDeadBlockRound.\nLemma~\\ref{lem:safe_unlock_nh_dbr}\nallows for a safe transition into the DeadBlockRound.\n\\end{proof}\n\nThe next few lemmas assure the behavior of honest validators as it relates to\nvoting.\n\n\\begin{lem}\n\\label{lem:honest_must_prevote}\nAn honest validator who enters a round must eventually PreVote or PreVoteNil in\nthat round.\n\\end{lem}\n\n\\begin{proof}\nAll honest validators will either PreVote or PreVoteNil at the termination of\nthe ProposalTimeout.\nTherefore, they must eventually prevote.\n\\end{proof}\n\n\\begin{lem}\n\\label{lem:2fp1_precommit}\nAs long as $2f+1$ honest validators enter a round, there will be at least\n$2f+1$ PreCommits or PreCommitNils in that round.\n\\end{lem}\n\n\\begin{proof}\nBy Lemma~\\ref{lem:honest_must_prevote},\nall honest validators will eventually PreVote or PreVoteNil in a round.\nIn the event that a PreVote is received for a competing Proposal from the\nperspective of a validator who has already PreVoted, that validator will count\nthis PreVote as a PreVoteNil.\nFrom there, the honest validators will be able to either PreCommit or\nPreCommitNil, thus leading to $2f+1$ PreCommits or PreCommitNils.\n\\end{proof}\n\n\\begin{lem}\n\\label{lem:2fp1_nextround}\nAs long as $2f+1$ honest validators enter a round, there will be at least\n$2f+1$ NextRound or NextHeight messages in that round.\n\\end{lem}\n\n\\begin{proof}\nMutatis mutandis, the proof is the same as that of\nLemma~\\ref{lem:2fp1_precommit}.\n\\end{proof}\n\nWe now show that a round must terminate or a higher block is formed.\n\n\\begin{lem}\n\\label{lem:valid_rouncert_exists}\nIf at any time a valid RoundCertificate exists for a round, that round must\neventually terminate or a higher block must be formed.\n\\end{lem}\n\n\\begin{proof}\nWe first focus on the case when no validator has signed a DeadBlockRound\nRoundCertificate.\nIn this case, we may have that $f+1$ honest validators have signed a NextHeight\nmessage and the round cannot terminate but a new block will be formed because\nthe validators will eventually observe the previous NextHeight messages and\nwill follow them.\nOtherwise, at least $f+1$ honest validators will have entered the current round\nand it must eventually terminate; we will fall back to the previous case if any\nof these validators observe a NextHeight message.\n\nIn the case that a DeadBlockRound RoundCertificate exists, we have already\nproven termination by Lemma~\\ref{lem:emptyblock_rc_dbr}.\n\\end{proof}\n\nTaken together, we are now able to show that our blockchain will make forward\nprogress provided there are a limited number of faults.\n\n\\begin{lem}\nOur blockchain will always make forward progress so long as there are no more\nthan $f$ faults in the system.\n\\end{lem}\n\n\\begin{proof}\nIf there are at most $f$ faults, then all rounds must terminate or a new block\nwill be formed by Lemma~\\ref{lem:valid_rouncert_exists}.\n\\end{proof}\n", "meta": {"hexsha": "36770ec7ba5ec97e79ff152ee4d55498850ec8a0", "size": 11766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/consensus_proofs.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/consensus_proofs.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/consensus_proofs.tex", "max_forks_repo_name": "chgorman/MadNet-Whitepaper", "max_forks_repo_head_hexsha": "a4cd4946db20713aa0573674c6e1fcc17a76a48a", "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": 38.4509803922, "max_line_length": 80, "alphanum_fraction": 0.782508924, "num_tokens": 3033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137997, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6676373103479436}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[a4paper,margin=25mm]{geometry}\n\\usepackage{graphicx,subcaption}\n\\usepackage{amsmath,amsfonts}\n\\usepackage{amssymb}\n\\usepackage{accents}\n\n\\newcommand{\\rvec}[1]{\\accentset{\\leftarrow}{#1}}\n\\renewcommand{\\v}[1]{\\mathbf{#1}}\n\\renewcommand{\\c}[1]{{\\cal #1}}\n\n\\title{Gaussian Restricted Boltzmann Classifier}\n\\author{G.A. Jarrad}\n\n\\begin{document}\n\\maketitle\n\\numberwithin{equation}{section}\n\\numberwithin{figure}{section}\n\\numberwithin{table}{section}\n\\section{Definition}\\label{sec:intro}\nConsider a restricted Boltzmann machine (RBM) with a real-valued input layer,\na binary-valued hidden layer, and a binary-valued output layer, as shown in \nFigure~\\ref{fig:rbm}.\nA suitable energy function is given by\n\\begin{eqnarray}\n    E(\\v{x},\\v{h},\\v{y}; \\Theta) & = & \\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2\n    - \\v{b}^T\\v{h} - \\v{h}^T W\\v{x} - \\v{c}^T\\v{y} - \\v{h}^T U\\v{y}\\,,\n\\label{eq:energy}\n\\end{eqnarray}\nwith input feature vector $\\v{x}=(x_1,x_2,\\ldots,x_F)\\in\\mathbb{X}\\subseteq\\mathbb{R}^F$, \nhidden binary vector $\\v{h}=(h_1,h_2,\\ldots,h_H)\\in\\mathbb{H}=\\{0,1\\}^H$, and output \nbinary vector $\\v{y}=(y_1,y_2,\\ldots,y_C)\\in\\mathbb{Y}=\\{0,1\\}^C$.\nThe model parameters are $\\Theta=(\\v{a}, \\v{b}, \\v{c}, W, U)$.\nThe joint probability of $\\v{x}$, $\\v{y}$ and $\\v{h}$ is then\n\\begin{eqnarray}\n    p(\\v{x},\\v{h},\\v{y}\\;|\\;\\Theta) & = & \\frac{e^{-E(\\v{x},\\v{h},\\v{y}; \\Theta)}}\n{\\int_{\\mathbb{X}}\\sum_{\\v{h}'\\in\\mathbb{H}}\\sum_{\\v{y}'\\in\\mathbb{Y}}\ne^{-E(\\v{x}',\\v{h}',\\v{y}'; \\Theta)}\\,d|\\v{x}'|\n}\n\\,,\n\\end{eqnarray}\nwhich is intractible to compute in general.\n\nIn order to turn the RBM into a restricted Boltzmann classifier (RBC), let us now suppose that the binary vector $\\v{y}$\nis really a one-in-$C$ vector of $C-1$ zeros and a single one, restricted to the set\n$\\mathbb{Y}'=\\{\\v{y}\\in\\mathbb{Y}\\;|\\;\\sum_{k=1}^{C}y_k=1\\}$. Then there is a one-to-one correspondence between each\nvector $\\v{y}\\in\\mathbb{Y}'$ and some scalar $y\\in\\{1,2,\\ldots,C\\}$, such that, for example,\nthe term $U\\v{y}$ selects the $y$-th column of $U$, denoted by $\\v{u}_y$.\nHence we obtain a final mapping to a multinomial output, suitable for a classifier.\nThe joint probability then becomes\n\\begin{eqnarray}\n     p(\\v{x},\\v{h},y\\;|\\;\\Theta) &=&\n\\frac{\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2+\\v{b}^T\\v{h}+\\v{h}^T W\\v{x}+c_y+\\v{h}^T \\v{u}_y}\n}\n{\\int_{\\mathbb{X}}\\sum_{y'=1}^{C}\\sum_{\\v{h}'\\in\\mathbb{H}}\n   e^{-\\frac{1}{2}\\|\\v{x}'-\\v{a}\\|^2+\\v{b}^T\\v{h}'+\\v{h}'^T W\\v{x}'+c_{y'}+\\v{h}^T \\v{u}_{y'}}\n   \\,d|\\v{x}'|\n}\n\\nonumber\\\\&=&\n\\frac{\n    e^{c_y-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2}\n\\prod_{i=1}^{H}e^{h_i(b_i+ \\v{w}_i^T\\v{x}+u_{iy})}\n}\n{\\int_{\\mathbb{X}}\\sum_{y'=1}^{C}\n   e^{c_{y'}-\\frac{1}{2}\\|\\v{x}'-\\v{a}\\|^2}\n  \\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy}}\\right]\n  \\,d|\\v{x}'|\n}\n\\,,\n\\end{eqnarray}\nwhere $\\v{w}_i^T$ is the $i$-th row of $W$.\nThe discriminative form of the RBC can then be specified as\n\\begin{eqnarray}\n    p(y\\;|\\;\\v{x},\\Theta) & = & \n\\frac{\\sum_{\\v{h}'\\in\\mathbb{H}}p(\\v{x},\\v{h}',y\\;|\\;\\Theta)}\n{\\sum_{y'=1}^{C}\\sum_{\\v{h}'\\in\\mathbb{H}}p(\\v{x},\\v{h}',y'\\;|\\;\\Theta)}\n\\nonumber\\\\&=&\n\\frac{\n    e^{c_y-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy}}\\right]\n}\n{\\sum_{y'=1}^{C}\n   e^{c_{y'}-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy'}}\\right]\n}\n\\nonumber\\\\&=&\n\\frac{\n   e^{c_y}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy}}\\right]\n}\n{\n\\sum_{y'=1}^{C} \ne^{c_{y'}}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy'}}\\right]\n}\n\\,,\n\\label{eq:p_y_x}\n\\end{eqnarray}\nwhich is a nonlinear form of logistic classifier.\n\nNow, the bipartite restriction depicted in Figure~\\ref{fig:rbm} ensures that $\\v{x}$ and $y$\nare conditionally independent given $\\v{h}$.\nObserve, for instance, that\n\\begin{eqnarray}\n   p(\\v{x}\\;|\\;\\v{h},y,\\Theta) & = &\n\\frac{ p(\\v{x},\\v{h},y\\;|\\;\\Theta)}\n{ \\int_{\\mathbb{X}}p(\\v{x}',\\v{h},y\\;|\\;\\Theta)\\,d|\\v{x}'|}\n\\nonumber\\\\&=&\n\\frac{\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2+\\v{b}^T\\v{h}+\\v{h}^T W\\v{x}+c_y+\\v{h}^T \\v{u}_y}\n}\n{\n\\int_{\\mathbb{X}}\n    e^{-\\frac{1}{2}\\|\\v{x}'-\\v{a}\\|^2+\\v{b}^T\\v{h}+\\v{h}^T W\\v{x}'+c_y+\\v{h}^T \\v{u}_y}\n\\,d|\\v{x}'|\n}\n\\nonumber\\\\&=&\n\\frac{\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2+\\v{h}^T W\\v{x}}\n}\n{\n\\int_{\\mathbb{X}}\n    e^{-\\frac{1}{2}\\|\\v{x}'-\\v{a}\\|^2+\\v{h}^T W\\v{x}'}\n\\,d|\\v{x}'|\n}\n\\nonumber\\\\&=&\n\\frac{\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}-W^T\\v{h}\\|^2+\\v{h}^T W\\v{a}+\\frac{1}{2}\\v{h}^T WW^T \\v{h}}\n}\n{\n    \\int_{\\mathbb{X}}\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}-W^T\\v{h}\\|^2+\\v{h}^T W\\v{a}+\\frac{1}{2}\\v{h}^T WW^T \\v{h}}\n    \\,d|\\v{x}'|\n}\n\\nonumber\\\\&=&\n\\frac{\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}-W^T\\v{h}\\|^2}\n}\n{\n    \\int_{\\mathbb{X}}e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}-W^T\\v{h}\\|^2}\\,d|\\v{x}'|\n}\n\\nonumber\\\\&=& N(\\v{x}\\;|\\;\\v{a}+W^T\\v{h},I)\\,.\n\\end{eqnarray}\nHence, $\\v{x}$ is conditionally normally distributed with mean $\\v{a}+W^T\\v{h}$ and unit spherical \nvariance $I$ (the identity matrix).\n\nSimilarly, observe that\n\\begin{eqnarray}\n    p(y\\;|\\;\\v{x},\\v{h},\\Theta) & = & \n\\frac{p(\\v{x},\\v{h},y\\;|\\;\\Theta)}\n{\\sum_{y'=1}^{C}p(\\v{x},\\v{h},y'\\;|\\;\\Theta)}\n\\nonumber\\\\&=&\n\\frac{\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2+\\v{b}^T\\v{h}+\\v{h}^T W\\v{x}+c_y+\\v{h}^T\\v{u}_y}\n}\n{\n   \\sum_{y'=1}^{C}\n    e^{-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2+\\v{b}^T\\v{h}+\\v{h}^T W\\v{x}+c_{y'}+\\v{h}^T\\v{u}_{y'}}\n}\n\\nonumber\\\\&=&\n\\frac{e^{c_y+\\v{h}^T\\v{u}_y}}\n  {\\sum_{y'=1}^{C}e^{c_{y'}+\\v{h}^T \\v{u}_{y'}}}\\,.\n\\end{eqnarray}\nThis result is just the {\\em soft-max} function, or standard logistic classifier.\n\nConversely, $\\v{h}$ depends upon both $\\v{x}$ and $\\v{y}$ via\n\\begin{eqnarray}\n    p(\\v{h}\\;|\\;\\v{x},y,\\Theta) & = & \n    \\frac{p(\\v{x},\\v{h},y\\;|\\;\\Theta)}\n{\\sum_{\\v{h}'\\in\\mathbb{H}}p(\\v{x},\\v{h}',y\\;|\\;\\Theta)}\n\\nonumber\\\\&=&\n\\frac{\n    e^{c_y-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2}\n\\prod_{i=1}^{H}e^{h_i(b_i+ \\v{w}_i^T\\v{x}+u_{iy})}\n}\n{\n   e^{c_{y}-\\frac{1}{2}\\|\\v{x}-\\v{a}\\|^2}\n  \\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy}}\\right]\n}\n\\nonumber\\\\&=&\n\\frac{\n\\prod_{i=1}^{H}e^{h_i(b_i+ \\v{w}_i^T\\v{x}+u_{iy})}\n}\n{\n  \\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}+u_{iy}}\\right]\n}\n\\nonumber\\\\&=&\n  \\prod_{i=1}^{H}p(h_i\\;|\\;\\v{x},y,\\Theta)\n\\,,\n\\end{eqnarray}\nwhere \n\\begin{eqnarray}\n  p(h_i=1\\;|\\;\\v{x},y,\\Theta) & = & \n  \\frac{e^{b_i+\\v{w}_i^T\\v{x}+u_{iy}}}{1+e^{b_i+\\v{w}_i^T\\v{x}+u_{iy}}}\n~=~\\sigma(b_i+\\v{w}_i^T\\v{x}+u_{iy})\n  \\,.\n\\label{eq:ph1}\n\\end{eqnarray}\nThis is just the logistic sigmoid function.\n\n\\section{Supervised Discriminative Optimisation}\nConsider the problem of estimating the RBC parameters $\\Theta$ from a data-set of fully labelled feature vectors,\n$\\c{X}=(\\v{x}_1,\\v{x}_2,\\ldots,\\v{x}_N)$, with corresponding labels $\\c{Y}=(y_1,y_2,\\ldots,y_N)$.\nAssuming that the data items are independent, the discriminative likelihood is given by\n\\begin{eqnarray}\n  p(\\c{Y}\\;|\\;\\c{X},\\Theta) & = & \\prod_{d=1}^N p(y_d\\;|\\;\\v{x}_d,\\Theta)\n\\,,\n\\end{eqnarray}\n and hence, from equation~\\eqref{eq:p_y_x}, the average discriminative log-likelihood is given by\n\\begin{eqnarray}\n  \\c{L}_{\\c{Y}|\\c{X}}(\\Theta) & = & \\frac{1}{N}\\ln p(\\c{Y}\\;|\\;\\c{X},\\Theta)\n~=~ \n\\frac{1}{N}\\sum_{d=1}^N \\ln p(y_d\\;|\\;\\v{x}_d,\\Theta)\n\\nonumber\\\\& = & \n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\n  \\sum_{y'=1}^C \\delta_{y',y_d}\\ln\\left(\n   e^{c_{y'}}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}_d+u_{iy'}}\\right]\\right)\\right.\n\\nonumber\\\\&&\n{}-\\left.\\ln\\sum_{y'=1}^{C} \ne^{c_{y'}}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}_d+u_{iy'}}\\right]\n\\right\\}\n\\nonumber\\\\& = & \n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\n  \\sum_{y'=1}^C \\delta_{y',y_d}\\left(\n   c_{y'}+\\sum_{i=1}^{H}\\ln\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}_d+u_{iy'}}\\right]\\right)\\right.\n\\nonumber\\\\&&\n{}-\\left.\\ln\\sum_{y'=1}^{C} \ne^{c_{y'}}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}_d+u_{iy'}}\\right]\n\\right\\}\\,.\n\\end{eqnarray}\nHence, the gradient with respect to $c_y$ is\n\\begin{eqnarray}\n\\frac{\\partial\\c{L}_{\\c{Y}|\\c{X}}}{\\partial c_y}\n& = & \n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\n\\delta_{y,y_d}-\n\\frac{e^{c_{y}}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}_d+u_{iy}}\\right]}\n{\\sum_{y'=1}^{C} \ne^{c_{y'}}\\prod_{i=1}^{H}\\left[1+e^{b_i+ \\v{w}_i^T\\v{x}_d+u_{iy'}}\\right]}\n\\right\\}\n\\nonumber\\\\&=&\n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\n\\delta_{y,y_d}-p(y\\:|\\;\\v{x}_d,\\Theta)\n\\right\\}\n\\nonumber\\\\&=&\n\\frac{N_y}{N}-\\frac{1}{N}\\sum_{d=1}^N p(y\\:|\\;\\v{x}_d,\\Theta)\n\\,,\n\\end{eqnarray}\nwhere $N_y$ is the number of data labelled with class $y$.\n\nIn order to develop the remaining derivatives, we first observe that\n\\begin{eqnarray}\n\\frac{\\partial}{\\partial\\theta_i}\\left(\nc_{y}+\\sum_{i'=1}^{H}\\ln\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y}}\\right]\n\\right)\n&=&\n\\frac{\\partial}{\\partial\\theta_i}\\ln\\left[1+e^{b_{i}+ \\v{w}_{i}^T\\v{x}_d+u_{iy}}\\right]\n\\nonumber\\\\&=&\n\\frac{e^{b_{i}+ \\v{w}_{i}^T\\v{x}_d+u_{iy}}}\n{1+e^{b_{i}+ \\v{w}_{i}^T\\v{x}_d+u_{iy}}}\n\\frac{\\partial}{\\partial\\theta_i}(b_{i}+ \\v{w}_{i}^T\\v{x}_d+u_{iy})\n\\nonumber\\\\&=&\np(h_i=1\\;|\\;\\v{x}_d,y,\\Theta)\n\\frac{\\partial}{\\partial\\theta_i}(b_{i}+ \\v{w}_{i}^T\\v{x}_d+u_{iy})\\,,\n\\end{eqnarray}\nfrom equation~\\eqref{eq:ph1},\nand then use the fact that \n$\\nabla f(\\theta)=f(\\theta)\\nabla\\ln f(\\theta)$ to deduce that\n\\begin{eqnarray}\n&\\frac{\\partial}{\\partial\\theta_i}e^{c_{y}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y}}\\right]&\n\\nonumber\\\\&=&\\hspace*{-25mm}\ne^{c_{y}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y}}\\right]\n\\frac{\\partial}{\\partial\\theta_i}\\left(\nc_{y}+\\sum_{i'=1}^{H}\\ln\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y}}\\right]\n\\right)\n\\nonumber\\\\&=&\\hspace*{-25mm}\ne^{c_{y}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y}}\\right]\np(h_i=1\\;|\\;\\v{x}_d,y,\\Theta)\n\\frac{\\partial}{\\partial\\theta_i}(b_{i}+ \\v{w}_{i}^T\\v{x}_d+u_{iy})\\,.\n\\end{eqnarray}\nHence, the gradient of the log-likelihood with respect to $u_{iy}$ is\n\\begin{eqnarray}\n\\frac{\\partial\\c{L}_{\\c{Y}|\\c{X}}}{\\partial u_{iy}}\n& = & \n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\\rule{0pt}{5mm}\n\\delta_{y,y_d}\\,p(h_i=1\\;|\\;\\v{x}_d,y,\\Theta)\\right.\n\\nonumber\\\\&&\n{}-\\left.\\frac{e^{c_{y}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y}}\\right]}\n{\\sum_{y'=1}^{C}e^{c_{y'}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y'}}\\right]}\np(h_i=1\\;|\\;\\v{x}_d,y,\\Theta)\n\\right\\}\n\\nonumber\\\\&=&\n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\n\\delta_{y,y_d}-p(y\\;|\\;\\v{x}_d,\\Theta)\\right\\}\\,p(h_i=1\\;|\\;\\v{x}_d,y,\\Theta)\n\\,.\n\\end{eqnarray}\nSimilarly, the gradient of the log-likelihood with respect to $b_{i}$ is\n\\begin{eqnarray}\n\\frac{\\partial\\c{L}_{\\c{Y}|\\c{X}}}{\\partial b_{i}}\n& = & \n\\frac{1}{N}\\sum_{d=1}^N\\left\\{\\sum_{y'=1}^{C}\n\\delta_{y',y_d}\\,p(h_i=1\\;|\\;\\v{x}_d,y',\\Theta)\\right.\n\\nonumber\\\\&&\n{}-\\left.\\frac{\\sum_{y'=1}^{C}e^{c_{y'}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y'  }}\\right]\n\\,p(h_i=1\\;|\\;\\v{x}_d,y',\\Theta)}\n{\\sum_{y'=1}^{C}e^{c_{y'}}\\prod_{i'=1}^{H}\\left[1+e^{b_{i'}+ \\v{w}_{i'}^T\\v{x}_d+u_{i'y'}}\\right]}\n\\right\\}\n\\nonumber\\\\&=&\n\\frac{1}{N}\\sum_{d=1}^N\\sum_{y'=1}^{C}\\left\\{\n\\delta_{y',y_d}-p(y'\\;|\\;\\v{x}_d,\\Theta)\\right\\}\\,p(h_i=1\\;|\\;\\v{x}_d,y',\\Theta)\n\\nonumber\\\\&=&\n\\sum_{y=1}^{C}\\frac{\\partial\\c{L}_{\\c{Y}|\\c{X}}}{\\partial u_{iy}}\n\\,,\n\\end{eqnarray}\nand the gradient with respect to $\\v{w}_i$ is\n\\begin{eqnarray}\n\\frac{\\partial\\c{L}_{\\c{Y}|\\c{X}}}{\\partial \\v{w}_{i}}\n& = & \n\\frac{1}{N}\\sum_{d=1}^N\\v{x}_d\\sum_{y'=1}^{C}\\left\\{\n\\delta_{y',y_d}-p(y'\\;|\\;\\v{x}_d,\\Theta)\\right\\}\\,p(h_i=1\\;|\\;\\v{x}_d,y',\\Theta)\n\\,.\n\\end{eqnarray}\nConsequently, the discriminative log-likelihood $\\c{L}_{\\c{Y}|\\c{X}}$ can be maximised using standard or accelerated\ngradient ascent. Note, however, that the parameter $\\v{a}$ from equation~\\eqref{eq:energy}\ndoes not appear in the RBC~\\eqref{eq:p_y_x}, and therefore cannot be optimised discriminatively.\n\n\\end{document}\n", "meta": {"hexsha": "4d024d205a62d1155fd6259a4763605efdf7504b", "size": 11675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RBMModels/notes/gaussian-restricted-boltzmann.tex", "max_stars_repo_name": "gaj67/gaj-data-science", "max_stars_repo_head_hexsha": "aadcf6ee2cd00606563f213167c2eeeb42430c59", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "RBMModels/notes/gaussian-restricted-boltzmann.tex", "max_issues_repo_name": "gaj67/gaj-data-science", "max_issues_repo_head_hexsha": "aadcf6ee2cd00606563f213167c2eeeb42430c59", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RBMModels/notes/gaussian-restricted-boltzmann.tex", "max_forks_repo_name": "gaj67/gaj-data-science", "max_forks_repo_head_hexsha": "aadcf6ee2cd00606563f213167c2eeeb42430c59", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9230769231, "max_line_length": 120, "alphanum_fraction": 0.5644539615, "num_tokens": 5696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6676373057964374}}
{"text": "\\documentclass{standalone}\n\n\n\\begin{document}\n\t\n\t\\chapter{Differential Equations}\n\t\n\t\\section{First order differential equations}\n\t\\subsection{Exact differential equations}\n\tWhen solving \\textit{exact differential equations} we recognize that one side of the equation is of the form $u\\frac{dv}{dx} + v\\frac{du}{dx}$ and hence  $\\int u\\frac{dv}{dx} + v\\frac{du}{dx}\\,dx$ can be quoted as $uv+k$.\n\t\n\t\\subsection{Integrating factor}\n\tConsider a first order differential equation that can be written in the form $\\frac{dy}{dx} + f(x)y + g(x)$. The LHS of the differential equation ia not yet exact, but suppose that it becomes exact when it is multiplied by a function $I(x)$.\\\\\n\t\n\tThus, we have the exact differential equation: \\[I(x)\\left(\\frac{dy}{dx} + f(x)y =  g(x)\\right)\\]\n\t\n\tWhich is simplified to: \\[I(x)\\frac{dy}{dx} + I(x)f(x)y = I(x)g(x)\\]\n\t\n\tComparing the LHS with $v\\frac{du}{dx} + u\\frac{dv}{dx}$ we have: \n\t\\begin{align*}  v&=I &\\quad u&=y\\\\    \\frac{du}{dx} &= I(x)f(x) &\\quad \\frac{dv}{dx} &= \\frac{dy}{dx} \\end{align*}\n\t\n\tWhich results in: \n\t\\begin{align*}\n\t\t\\int\\frac{1}{I(x)}\\,dI(x)      & = \\int f(x)\\,dx         \\\\\n\t\t\\implies \\ln\\left| I(x)\\right| & = \\int f(x)\\, dx        \\\\\n\t\t\\therefore \\quad\tI(x)          & = e^{\\int f(x)\\,dx} \\qed \n\t\\end{align*}\n\t\n\t\\newpage\n\t\\section{Second order differential equations}\n\tA second order differential equation is one of the form: \\[a\\frac{d^2y}{dx^2} + b\\frac{dy}{dx} + cy= f(x)\\] with a general solution: \\[y=\\text{C.F.} + \\text{P.I.}\\]\n\t\n\t\\subsection{The complementary function}\n\tTo obtain this part of the solution, the general solution of the quadratic equation $ax^2 + bx + c=0$ by comparing it to $a\\frac{d^2y}{dx^2} + b\\frac{dy}{dx} + cy = 0$ when $f(x)$, or the \\textbf{RHS} $= 0$, and thus the two so called roots can be found. \n\t\n\t\\begin{center}\n\t\t\\renewcommand{\\arraystretch}{1.6}\n\t\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\tRoots                                        & General Solution                 \\\\ \\hline\n\t\t\tTwo real distinct roots $\\alpha$ and $\\beta$ & $y=Ae^{\\alpha x} + Be^{\\beta x}$ \\\\ \\hline\n\t\t\tTwo real equal roots $\\alpha$ and $\\alpha$   & $y=(A+Bx)e^{\\alpha x}$           \\\\ \\hline\n\t\t\tTwo complex roots $p\\pm qi$                  & $y=e^{px}(A\\cos qx + B\\sin qx)$  \\\\\\hline\n\t\t\\end{tabular}\n\t\\end{center}\t\n\t\n\t\\subsection{Type 2: $\\mathbf{f(x) \\neq 0}$}\n\tWhen $f(x) \\neq 0$ the general solution of such a differential equation is of the form $y=\\text{C.F. + P.I.}$, where C.F. is the complimentary function and P.I. is the particular integral.\n\n\tThe C.F. is obtained by finding the general solution of the differential equation $a\\frac{d^2y}{dx^2} + b\\frac{dy}{dx} + cy = 0$, similarly to the previous case.\\\\\n\n\tThe P.I. is any solution of the given differential equation. It depends on the function $f(x)$ and is usually a general form of it.\n\t\\begin{center}\n\t\t\\renewcommand{\\arraystretch}{1.6}\n\t\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\t$\\mathbf{f(x)}$\t\t& \\textbf{Trial Solution}\\\\\\hline\n\t\t\t$5$\t\t\t\t\t& $y=k$\\\\\\hline\n\t\t\t$2x+7$\t\t\t\t& $y=px+q$\\\\\\hline\n\t\t\t$3x^2+x-6$\t\t\t& $y=px^2+qx+r$\\\\\\hline\n\t\t\t$3e{7x}$\t\t\t& $y=ke^{7x}$\\\\\\hline\n\t\t\t$3xe^{-2x}$     \t& $y=(px+q)e^{-2x}$\\\\\\hline\n\t\t\t$2\\sin3x + 4\\cos3x$ & $y=p\\sin3x + q\\cos3x$\\\\\\hline\n\t\t\t$\\cos8x$ \t\t\t& $y=p\\sin8x + q\\cos8x$\\\\\\hline\n\t\t\t$\\sin x - 3\\cos2x$  & $y=p\\sin x + q\\cos x +r\\sin2x + t\\sin2x$\\\\\\hline\n\t\t\t$2x + 6e^{4x}$\t\t& $y=px+q+ke^{4x}$\\\\\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\newpage\n\t\n\tThe trial solution is to be chosen according to the above table and differentiated twice. These values are then substitued in the given differential equation, so that the unknown constant/s of the trial solution can be found.\\\\\n\t\n\tThe general solution $y=\\text{C.F.} + \\text{P.I.}$ is then written.\\\\\n\t\n\tThe unknown constants of the C.F. can be found if additional information is given  (i.e. $y=1$ and $\\frac{dy}{dx}=0$ when $x=0$).\\\\\n\t\n\tIn some cases (failure cases) the trial solution listed in the above table leads to an \\textit{inconsistent equation}. This usually happens when the trial solution is included in the complementary function. The correct trial solution is obtained by multiplying the trial solution in the above table by $x$ or $x^2$. Such trial solutions are usually given by the question. \n\t\n\\end{document}", "meta": {"hexsha": "294593d6c92eb302dc7c13ab98d0717e6a830cf1", "size": 4242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/differential_equations.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/differential_equations.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/differential_equations.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": 53.6962025316, "max_line_length": 373, "alphanum_fraction": 0.6357850071, "num_tokens": 1495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.6675578240444139}}
{"text": "%!TEX root = fastZKP.tex\n\n\\subsection{GKR Protocol}\\label{subsec::GKR}\n\nIn~\\cite{GKR}, Goldwasser et al. proposed an efficient interactive proof protocol for layered arithmetic circuits, which we use as a building block for our new zero-knowledge argument and is referred as the \\emph{GKR} protocol. We present the detailed protocol here.\n\n\n\n\\subsubsection{Sumcheck Protocol.}\n\\label{subsec::sumcheck}\nThe sumcheck problem is a fundamental problem that has various applications. The problem is to sum a polynomial $f: \\mathbb{F}^\\ell \\rightarrow \\mathbb{F}$ on the binary hypercube $$\\sum\\nolimits_{b_1,b_2,\\ldots,b_\\ell\\in\\{0,1\\}}f(b_1,b_2,...,b_\\ell).$$ \nDirectly computing the sum requires exponential time in $\\ell$, as there are $2^\\ell$ combinations of $b_1,\\ldots,b_\\ell$. Lund et al.~\\cite{sumcheck} proposed a \\emph{sumcheck} protocol that allows a verifier $\\mathcal{V}$ to delegate the computation to a computationally unbounded prover $\\mathcal{P}$, who can convince $\\mathcal{V}$ that $H$ is the correct sum. We provide a description of the sumcheck protocol in Protocol~\\ref{prot::sumcheck}.\n\\begin{figure}[t!]\n\\small{\n\\centering{\\centering\n\\framebox{\\parbox{.99\\linewidth}{\n\\begin{protocol}[\\textbf{Sumcheck}]\n\t\\label{prot::sumcheck}\n\tThe protocol proceeds in $\\ell$ rounds. \n\t\\begin{itemize}\n\t\t\\item In the first round, $\\P$ sends a univariate polynomial $$f_1(x_1)\\overset{def}{=}\\sum\\limits_{b_2,\\ldots,b_\\ell\\in\\{0,1\\}}f(x_1,b_2,\\ldots,b_\\ell)\\, ,$$ $\\V$ checks $H=f_1(0)+f_1(1)$. Then $\\V$ sends a random challenge $r_1\\in\\mathbb{F}$ to $\\P$.\n\t\t\\item In the $i$-th round, where $2\\le i \\le l-1$, $\\P$ sends a univariate polynomial\n\t\t$$f_{i}(x_{i})\\overset{def}{=}\\sum\\limits_{b_{i+1},\\ldots,b_\\ell\\in\\{0,1\\}}f(r_1,\\ldots, r_{i-1}, x_{i}, b_{i+1},\\ldots, b_{\\ell})\\, ,$$ \n\t\t$\\V$ checks $f_{i-1}(r_{i-1})=f_{i}(0)+f_{i}(1)$, and sends a random challenge $r_{i}\\in\\mathbb{F}$ to $\\P$.\n\t\t\\item In the $\\ell$-th round, $\\P$ sends a univariate polynomial $$f_{\\ell}(x_{\\ell})\\overset{def}{=}f(r_1, r_2, \\ldots, r_{l-1}, x_{\\ell})\\, ,$$ $\\V$ checks $f_{\\ell-1}(r_{\\ell-1})=f_{\\ell}(0)+f_{\\ell}(1)$. The verifier generates a random challenge $r_{\\ell}\\in\\mathbb{F}$. Given oracle access to an evaluation $f(r_1, r_2, \\ldots, r_\\ell)$ of $f$, $\\V$ will accept if and only if $f_{\\ell}(r_\\ell) = f(r_1, r_2, \\ldots, r_\\ell)$. The instantiation of the oracle access depends on the application of the sumcheck protocol.\n\t\\end{itemize}\n\\end{protocol}}}}}\n\\vspace{-0.2in}\n\\end{figure}\nThe proof size of the sumcheck protocol is $O(d\\ell)$, where $d$ is the variable-degree of $f$, as in each round, $\\P$ sends a univariate polynomial of one variable in $f$%\\babis{you mean the maximum degree accross all variableS?}\\yupeng{formally defined in 2.1}\\dawn{minor comment: this sentence can be interpreted wrongly; in each round, P only sends one univariate polynomial, not a univariate polynomial for each variable}\n, which can be uniquely defined by $d+1$ points. The verifier time of the protocol is $O(d\\ell)$. The prover time depends on the degree and the sparsity of $f$, and we will give the complexity later in our scheme. The sumcheck protocol is complete and sound with $\\epsilon = \\frac{d\\ell}{|\\mathbb{F}|}$. \n\n\n\\begin{definition}[\\textbf{Multi-linear Extension}]\n\tLet $V:\\{0, 1\\}^\\ell \\rightarrow \\mathbb{F}$ be a function. The \\textit{multilinear extension} of $V$ is the unique polynomial $\\tilde{V}: \\mathbb{F}^l \\rightarrow \\mathbb{F}$ such that $\\tilde{V}(x_1, x_2, ..., x_{l}) = V(x_1, x_2, ..., x_{l})$ for all $x_1, x_2, \\ldots, x_{l}\\in\\{0,1\\}^l$.\n\t\n\t\n\t$\\tilde{V}$ can be expressed as:\n\t$$\\tilde{V}(x_1, x_2, ..., x_{l})=\\sum\\nolimits_{b\\in\\{0,1\\}^\\ell}\\prod\\nolimits_{i=1}^{l}[((1-x_i)(1-b_i)+x_ib_i) \\times V(b)]$$\n\twhere $b_i$ is $i$-th bit of b.\n\t\n\t\n\\end{definition}\n\n\\paragraph{Multilinear extensions of arrays.} Inspired by the close form equation of the multilinear extension given above, we can view an array $\\textbf{A} = (a_0, a_1, \\ldots, a_{n-1})$ as a function $A: \\binary^{\\log n}\\rightarrow \\F$ such that $\\forall i\\in[0,n-1], A(i) = a_i$. Therefore, in this paper, we abuse the use of multilinear extension on an array as the multilinear extension $\\tilde{A}$ of $A$. Using the sumcheck protocol as a building block, Goldwasser et al.~\\cite{GKR} showed an interactive proof protocol for layered arithmetic circuits. \n\n\\smallskip\\noindent\\textbf{High Level Ideas.} Let $C$ be a layered arithmetic circuit with depth $d$ over a finite field $\\mathbb{F}$. Each gate in the $i$-th layer takes inputs from two gates in the $(i+1)$-th layer; layer $0$ is the output layer and layer $d$ is the input layer. The protocol proceeds layer by layer. Upon receiving the claimed output from $\\P$, in the first round, $\\V$ and $\\P$ run the sumcheck protocol to reduce the claim about the output to a claim about the values in the layer above. In the $i$-th round, both parties reduce a claim about layer $i-1$ to a claim about layer $i$ through the sumcheck protocol. Finally, the protocol terminates with a claim about the input layer $d$, which can be checked directly by $\\V$, or is given as an oracle access. If the check passes, $\\V$ accepts the claimed output. \n\n\\paragraph{Notation.} Before describing the GKR protocol, we introduce some additional notations. We denote the number of gates in the $i$-th layer as $S_i$ and let $s_i = \\ceil{\\log S_i}$. (For simplicity, we assume $S_i$ is a power of 2, and we can pad the layer with dummy gates otherwise.) We then define a function $V_i:\\binary^{s_i}\\rightarrow\\mathbb{F}$ that takes a binary string $b\\in\\binary^{s_i}$ and returns the output of gate $b$ in layer $i$, where $b$ is called the gate label. With this definition, $V_0$ corresponds to the output of the circuit, and $V_d$ corresponds to the input layer. Finally, we define two additional functions $add_i, mult_i: \\binary^{s_{i-1}+2s_i}\\rightarrow\\binary$, referred as \\emph{wiring predicates} in the literature. $add_i$ ($mult_i$) takes one gate label $z\\in\\binary^{s_{i-1}}$ in layer $i-1$ and two gate labels $x,y\\in\\binary^{s_i}$ in layer $i$, and outputs 1 if and only if gate $z$ is an addition (multiplication) gate that takes the output of gate $x,y$ as input. With these definitions, $V_i$ can be written as follows:\n\\begin{equation}\n    \\begin{aligned}\n\tV_i(z)=\\sum_{x, y \\in\\binary^{s_{i+1}}}(add_{i+1}(z,x,y)(V_{i+1}(x)+V_{i+1}(y))\\\\\n\t+mult_{i+1}(z,x,y)(V_{i+1}(x)V_{i+1}(y)))\n\t\\end{aligned}\n\\end{equation}\nfor any $z\\in\\binary^{s_i}$. \n\n\n\n\n\n\n\n\n\n\\ignore{\n\\yupeng{try to remove $\\beta$.}\n\n\\begin{definition}[Multilinear extension of identity function]\nHere we present a multilinear extension of identity function\n\\begin{eqnarray}\\beta_{l}(a, b)=\n\t\\begin{cases}\n\t1, &a=b\\cr 0, &a\\neq b\n\t\\end{cases}\n\\end{eqnarray}\nWhere $a, b$ are binary strings with length $l$. The multilinear extension is the following:\n\n$$\\tilde{\\beta_{l}}(a,b)\\overset{def}{=}\\prod_{j=1}^{l}((1-a_{j})(1-b_{j})+a_{j}b_{j})$$\n\nWe have $\\tilde{\\beta_{l}}(a,b)=\\beta_{l}(a, b)$ when $a, b$ are binary.\n\\end{definition}\n\n\\begin{definition}[Multilinear extension of $add$, $mult$]\nWe will define the multilinear extension of two component of $V_i$.\n$$\\tilde{add}_{i}(g, u, v)=\\sum_{(g', u', v') \\in G_{i, add}}\\tilde{\\beta}_{s_i}(g, g')\\tilde{\\beta}_{s_{i+1}}(u, u')\\tilde{\\beta}_{s_{i+1}}(v, v')$$\n\n$$\\tilde{mult}_{i}(g, u, v)=\\sum_{(g', u', v') \\in G_{i, mult}}\\tilde{\\beta}_{s_i}(g, g')\\tilde{\\beta}_{s_{i+1}}(u, u')\\tilde{\\beta}_{s_{i+1}}(v, v')$$\n\\end{definition}\n\n\\begin{definition}[Multilinear extension of $V_i(g)$]\n\t\\label{def::multilinear}\n\t%$$\\tilde{V}_{i}(z)=\\sum_{g\\in\\{0,1\\}^{s_i} u, v\\in \\{0,1\\}^{s_{i+1}}}f_{i,z}(g,u,v)$$\n\n\t%$$f_{i,z}(g,u,v)\\overset{def}{=}\\tilde{\\beta_{i}}(z, g)[\\tilde{mult}(g, u, v)(\\tilde{V}_{i+1}(u)\\tilde{V}_{i+1}(v))+\\tilde{add}(g,u,v)(\\tilde{V}_{i+1}(u)+\\tilde{V}_{i+1}(v))]$$\n\t%where $$\\tilde{\\beta_{i}}(z,g)\\overset{def}{=}\\prod_{j=1}^{s_{i}}((1-g_{j})(1-z_{j})+g_{j}z_{j})$$\n\n\t%$$\\tilde{mult}(g,u,v)\\overset{def}{=}\\sum_{(g', u', v')\\in G_{i,mult}}\\tilde{\\beta_{i}}(g,g')\\tilde{\\beta_{i+1}}(u,u')\\tilde{\\beta_{i+1}}(v,v')$$\n\n\t%$$\\tilde{add}(g,u,v)\\overset{def}{=}\\sum_{(g', u', v')\\in G_{i,add}}\\tilde{\\beta_{i}}(g,g')\\tilde{\\beta_{i+1}}(u,u')\\tilde{\\beta_{i+1}}(v,v')$$\n\n\t%when $a, b$ are binary strings, $\\tilde{\\beta_{i}}(a, b)$ will output $1$ when $a=b$, and $0$ otherwise. $\\tilde{mult},\\tilde{add}$ is the multilinear extension of the wiring predicates. A wiring predicates is a function of three gates $g_1, g_2, g_3$, and returns $1$ if $g_1$ takes $g_2, g_3$ as it's input.\n\n\tWe define the multilinear extension of $V_i(g)$ in the following way:\n\n\t$$\\tilde{V}_i(g)=\\sum_{u, v \\in \\{0,1\\}^{s_{i+1}}}(\\tilde{add}_{i+1}(g, u, v)(\\tilde{V}_{i+1}(u)+\\tilde{V}_{i+1}(v))+\\tilde{mult}_{i+1}(g,u,v)(\\tilde{V}_{i+1}(u)\\tilde{V}_{i+1}(v)))\\textnormal{,}$$\n\twhere $\\tilde{mult}$ and $\\tilde{add}$ are multilinear extension of $mult$ and $add$.\n\\end{definition}\n\n}\n\n\nIn the equation above, $V_i$ is expressed as a summation, so $\\V$ can use the sumcheck protocol to check that it is computed correctly. As the sumcheck protocol operates on polynomials defined on $\\mathbb{F}$, we rewrite the equation with their multilinear extensions:\n\n\\begin{align}\\label{eq:GKR}\n\\tV_i(g)=&\\sum\\nolimits_{x, y \\in\\binary^{s_{i+1}}}f_i(x,y)\\nonumber\\\\\n=&\\sum\\nolimits_{x, y \\in\\binary^{s_{i+1}}}(\\tadd_{i+1}(g,x,y)(\\tV_{i+1}(x)+\\tV_{i+1}(y))\\nonumber\\\\\n&+\\tmult_{i+1}(g,x,y)(\\tV_{i+1}(x)\\tV_{i+1}(y)))\\,,\n\\end{align}\nwhere $g\\in\\mathbb{F}^{s_i}$ is a random vector. \n\n\\paragraph{Protocol.} With Equation~\\ref{eq:GKR}, the GKR protocol proceeds as following. The prover $\\P$ first sends the claimed output of the circuit to $\\V$. From the claimed output, $\\V$ defines polynomial $\\tV_0$ and computes $\\tV_0(g)$ for a random $g\\in\\mathbb{F}^{s_0}$. $\\V$ and $\\P$ then invoke a sumcheck protocol on Equation~\\ref{eq:GKR} with $i=0$. As described in Section~\\ref{subsec::sumcheck}, at the end of the sumcheck, $\\V$ needs an oracle access to $f_i(u,v)$, where $u,v$ are randomly selected in $\\mathbb{F}^{s_{i+1}}$. To compute $f_i(u,v)$, $\\V$ computes $\\tadd_{i+1}(u,v)$ and $\\tmult_{i+1}(u,v)$ locally (they only depend on the wiring pattern of the circuit, but not on the values), asks $\\P$ to send $\\tV_1(u)$ and $\\tV_1(v)$ and computes $f_i(u,v)$ to complete the sumcheck protocol. In this way, $\\V$ and $\\P$ reduces a claim about the output to two claims about values in layer 1. $\\V$ and $\\P$ could invoke two sumcheck protocols on $\\tV_1(u)$ and $\\tV_1(v)$ recursively to layers above, but the number of claims and the sumcheck protocols would increase exponentially in $d$. \n\n\\smallskip\\noindent\\textbf{Combining two claims: condensing to one claim.} In~\\cite{GKR}, Goldwasser et al. presented a protocol to reduce two claims $\\tV_i(u)$ and $\\tV_i(v)$ to one as following. $\\V$ defines a line $\\gamma: \\mathbb{F} \\rightarrow \\mathbb{F}^{s_i}$ such that $\\gamma(0)=u, \\gamma(1)=v$. $\\V$ sends $\\gamma(x)$ to $\\P$. Then $\\P$ sends $\\V$ a degree $s_i$ univariate polynomial $h(x)=\\tilde{V_i}(\\gamma(x))$. $\\V$ checks that $h(0)=\\tV_i(u), h(1)=\\tV_i(v)$. Then $\\V$ randomly chooses $r\\in\\mathbb{F}$ and computes a new claim $h(r) = \\tV_i(\\gamma(r)) = \\tV_i(w)$ on $w=\\gamma(r) \\in \\mathbb{F}^{s_i}$. $\\V$ sends $r, w$ to $\\P$. In this way, the two claims are reduced to one claim $\\tV_i(w)$. Combining this protocol with the sumcheck protocol on Equation~\\ref{eq:GKR}, $\\V$ and $\\P$ can reduce a claim on layer $i$ to one claim on layer $i+1$, and eventually to a claim on the input, which completes the GKR protocol.\n\n\n\n\n\\smallskip\\noindent\\textbf{Combining two claims: random linear combination.}  In~\\cite{zksumcheck}, Chiesa et al. proposed an alternative approach using random linear combinations. Upon receiving the two claims $\\tV_i(u)$ and $\\tV_i(v)$, $\\V$ selects $\\alpha_i, \\beta_i\\in\\mathbb{F}$ randomly and computes $\\alpha_i\\tV_i(u)+\\beta_i\\tV_i(v)$. Based on Equation~\\ref{eq:GKR}, this random linear combination can be written as\n{\\footnotesize\n\\begin{align}\\label{eq:randomGKR}\n&\\alpha_i\\tV_i(u)+\\beta_i\\tV_i(v)\\nonumber\\\\\n=&\\alpha_i\\sum_{x, y \\in\\binary^{s_{i+1}}}(\\tadd_{i+1}(u,x,y)(\\tV_{i+1}(x)+\\tV_{i+1}(y))+\\tmult_{i+1}(u,x,y)(\\tV_{i+1}(x)\\tV_{i+1}(y)))\\nonumber\\\\+&\\beta_i\\sum_{x, y \\in\\binary^{s_{i+1}}}(\\tadd_{i+1}(v,x,y)(\\tV_{i+1}(x)+\\tV_{i+1}(y))+\\tmult_{i+1}(v,x,y)(\\tV_{i+1}(x)\\tV_{i+1}(y)))\\nonumber\\\\\n=&\\sum_{x, y \\in\\binary^{s_{i+1}}}((\\alpha_i\\tadd_{i+1}(u,x,y)+\\beta_i\\tadd_{i+1}(v,x,y))(\\tV_{i+1}(x)+\\tV_{i+1}(y))\\nonumber\\\\\n&+(\\alpha_i\\tmult_{i+1}(u,x,y)+\\beta_i\\tmult_{i+1}(v,x,y))(\\tV_{i+1}(x)\\tV_{i+1}(y)))\n\\end{align}\n}\n$\\V$ and $\\P$ then execute the sumcheck protocol on Equation~\\ref{eq:randomGKR} instead of Equation~\\ref{eq:GKR}. At the end of the sumcheck protocol, $\\V$ still receives two claims about $\\tV_{i+1}$, computes their random linear combination and proceeds to an layer above recursively until the input layer.\n\nIn our new ZKP scheme, we will mainly use the second approach. The full GKR protocol using random linear combinations is given in Protocol~\\ref{protocol::GKR} of Appendix~\\ref{app:gkr}.\n\n\\begin{theorem}\\cite{VSA13}\\cite{JT_Thesis}\\cite{CMT}\\cite{GKR}. Let $C$ : $\\mathbb{F}^n \\rightarrow \\mathbb{F}^k$ be a depth-$d$ layered arithmetic circuit. Protocol \\ref{protocol::GKR} is an interactive proof for the function computed by $C$ with soundness $O(d\\log {|C|}/|\\mathbb{F}|)$. It uses $O(d \\log |C|)$ rounds of interaction and running time of the prover $\\mathcal{P}$ is $O(|C|\\log |C|)$. Let the optimal computation time for all $\\tilde{add_i}$ and $\\tilde{mult_i}$ be $T$, the running time of $\\V$ is $O(n+k+d\\log |C|+T)$. For log-space uniform circuits it is $T=\\poly{\\log |C|}$.\n\\end{theorem}\n\\babis{is it possible to argue briefly why the prover time is $C\\log C$? This is important for the paper motivation.}\\yupeng{Explained in section 3.}", "meta": {"hexsha": "fac9ab1e85cad525182812d56247ef6288d54bd7", "size": 13860, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/manuscript/CMT.tex", "max_stars_repo_name": "niconiconi/Libra", "max_stars_repo_head_hexsha": "d8b4bebd70c1b0681fdecb66fbadeccb3f9d926e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T12:05:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-23T16:18:40.000Z", "max_issues_repo_path": "paper/manuscript/CMT.tex", "max_issues_repo_name": "niconiconi/Libra", "max_issues_repo_head_hexsha": "d8b4bebd70c1b0681fdecb66fbadeccb3f9d926e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-10T17:15:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-11T16:14:46.000Z", "max_forks_repo_path": "paper/manuscript/CMT.tex", "max_forks_repo_name": "niconiconi/Libra", "max_forks_repo_head_hexsha": "d8b4bebd70c1b0681fdecb66fbadeccb3f9d926e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-31T05:53:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-02T14:05:43.000Z", "avg_line_length": 96.9230769231, "max_line_length": 1109, "alphanum_fraction": 0.6812409812, "num_tokens": 4988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6675578213271615}}
{"text": "\n%%% Latex preamble\n\\documentclass[11pt]{article}\n\\oddsidemargin 0pt\n\\textwidth 6.5in\n\\topmargin -0.65in\n\\textheight 9.25in\n\n\\usepackage{epsfig}\n\\usepackage{natbib}\n\\usepackage{amsmath, mathrsfs,amsfonts,amssymb}\n\n%Get the citation punctuation correct\n\\bibpunct{(}{)}{;}{a}{}{,}\n\n%Set the space between paragraphs.\n%Uncomment this for single spacing, comment for double spacing\n\\setlength{\\parskip}{1.0ex plus0.5ex minus0.2ex}\n\n%Allow colour in your output (pdf only?)\n% \\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}\n% \\definecolor{darkgreen}{rgb}{0,.5,0}  %For example\n%%%End of preamble\n\n\\newcommand{\\Plwr}{\\ensuremath{P_{\\mathrm{lwr}}}}\n\\newcommand{\\Pupr}{\\ensuremath{P_{\\mathrm{upr}}}}\n\\renewcommand{\\hat}[1]{\\ensuremath{\\vec{#1}}}\n\\newcommand{\\vareps}{\\varepsilon}\n\n\\begin{document}\n\\begin{center}\n\\begin{Huge} Determining the duty cycle for Pandora \\end{Huge}\n\\end{center}\n\n\nPandora will be launched into a low Earth orbit, aligned so the spacecraft orbits in a plane roughly perpendicular the direction from the Earth to the sun. The duty cycle for a celestial object (e.g. a star) is the fraction of time that object is observable by Pandora and not obscured by the Earth, or the sun. The duty cycle depends on the star staying within both the Earth avoidance cone, and the sun avoidance cone.\n\n\n\\section{Calculating duty cycle due to Earth avoidance}\nLet \\hat{t} be the unit vector from the centre of the Earth to the telescope.\nLet \\hat{s} be the unit vector from the centre of the coordinate system (the barycentre of the solar system) to the target star. Assume the star is at infinity, so we don't have to adjust \\hat{s} for the exact location of the Earth.\n\nFrom the perspective of the telescope, a star is observable if it is near the zenith angle (away from the Earth, or ``up''), and unobservable if it is near the nadir-angle. The telescope (or zenith) vector will of course change as a function of orbital phase.  Let us define a maximum angle away from nadir for which a star is still observable, $\\vareps$. The the condition of observability is therefore that \n\n\\begin{equation}\n\\hat{t} \\cdot \\hat{s} < \\cos{\\vareps}\n\\end{equation}\n\n\nIf the right ascension and declination are labeled $\\lambda, \\phi$, respectively, \n\\begin{equation}\n\\hat{s} \n= \n\\begin{bmatrix}\ns_x\\\\\ns_y\\\\\ns_z\\\\\n\\end{bmatrix}\n= \n\\begin{bmatrix}\n\\cos{\\lambda} \\cos{\\phi}\\\\\n\\sin{\\lambda} \\cos{\\phi}\\\\\n\\sin{\\phi} \\\\\n\\end{bmatrix}\n\\end{equation}\n\nAll that remains is to determine \\hat{t}. The telescope vector will vary as a function of both orbital phase of the telescope around the Earth, and the orbital phase of the Earth around the Sun.\n\n\n\nLet \\hat{e} be the unit vector from the sun to the Earth. Assume, for the sake of simplicity, that the Earth's orbit is circular. Then, in ecliptic plane coordinates, \n\n\\begin{equation}\n\\hat{e} = ( \\cos{\\alpha}, \\sin{\\alpha}, 0)\n\\end{equation}\n\nwhere $\\alpha$ is the Earth orbital phase angle, which varies between 0 and $2\\pi$ over the course of a year.\n\nCall the plane of the telescope's orbit around the Earth {\\bf uv}. We seek basis vectors within the {\\bf uv}-plane that we can project the telescope vector onto.\nLet \\hat{u} and \\hat{v} be two vectors in the plane {\\bf uv} such that the vectors \\hat{u}, \\hat{v} and \\hat{t} are all perpendicular and satisfy the right hand rule. We further arbitrarily\\footnote{It is tempting to think of this is the condition that sets the orbital plane, but it just sets the direction of ``up'' in the plane.} define \\hat{v} = (0,0,1)$^\\intercal$. Then\n\n\\begin{eqnarray}\n\\hat{e} &=& \\hat{u} \\times \\hat{v} \\\\\n\\Rightarrow \\hat{u} &=& \\hat{v} \\times \\hat{u} \\\\\n\\Rightarrow \\hat{u} &=& (-\\sin{\\alpha}, \\cos{\\alpha}, 0)^\\intercal\n\\end{eqnarray}\n\n\n\nIf we assume a circular orbit for the telescope around the Earth, we can write \n\n\\begin{equation}\n\\hat{t} = \\cos{\\rho} \\hat{u} + \\sin{\\rho} \\hat{v}\n\\end{equation}\n\n%Want vertical vectors here\nwhere $\\rho$ is the telescope's orbital phase. We can then convert \\hat{t} into ecliptic plane coordinates as \n\n\\begin{equation}\n\\hat{t} = \n    \\begin{bmatrix}\n    \\hat{t} \\cdot \\hat{x} \\\\\n    \\hat{t} \\cdot \\hat{y} \\\\\n    \\hat{t} \\cdot  \\hat{z}\n    \\end{bmatrix} \n    =\n    \\begin{bmatrix}\n    -\\sin{\\alpha} \\cos{\\rho} \\\\\n    \\cos{\\alpha}, \\cos{\\rho} \\\\\n    \\sin{\\rho})\n    \\end{bmatrix}\n\\end{equation}\n    \n    \n\\subsection{Finding the extrema of observability}\nThe points in the orbit where the star comes in and out of observability are given by $\\hat{t} \\cdot \\hat{s} = \\cos{\\vareps}$\nWorking through the arithmetic, we end up with\n\n\\begin{equation}\n\\cos{\\rho} (\\cos{\\alpha} s_y - \\sin{\\alpha} s_x) + \\sin{\\rho} s_z - \\cos{\\vareps} = 0\n\\end{equation}\n\nSet\n\\begin{equation}\n\\begin{matrix}\nT_1 \\\\\nT_2 \\\\\nT_3 \\\\\n\\end{matrix}\n=\n\\begin{matrix}\n\\cos{\\alpha} s_y - \\sin{\\alpha} s_x \\\\\ns_z \\\\\n\\cos{\\vareps} \\\\\n\\end{matrix}\n\\end{equation}\n\nThen \n\\begin{equation}\nT_1\\cos{\\rho} = T_3 - T_2 \\sin{\\rho}  \\label{trig}\n\\end{equation}\n\nSquaring both sides, and replacing $\\cos^2{\\rho}$ with $1 - \\sin^2{\\rho}$ gives, after a little arithmetic\n\n\\begin{equation}\n(T_1^2 + T_2^2) \\sin^2{\\rho} - 2T_1 T_2 \\sin{\\rho} + (T_3^2 - T_1^2) = 0\n\\end{equation}\n\nWe can solve this quadratic equation to obtain two values for $\\sin{\\rho}$, the max and min orbital phase that a star can be observed at. Note that if a star is either continuously observable, or never observable, this equation will have no solutions, and we'll need to treat that separately.\n\nNow, the sine of an angle is only strictly defined within a quarter of a circle, and the arcsin function admits two acceptable answers, each 180 degrees away from each other. To figure out which is the correct answer, we return to Eqn~\\ref{trig} and re-write it as \n\n$$T_2 \\sin{\\rho}  = T_3 - T_1\\cos{\\rho}  $$\n\nAgain we square it, and replace $\\sin^2{\\rho}$ with $1- \\cos^2{\\rho}$, and end up with \n\n$$\n(T_1^2 + T_2^2) \\cos^2{\\rho} - 2T_1 T_3 \\sin{\\rho} + (T_3^2 - T_2^2) = 0\n$$\n\nIf we solve for both $\\sin{\\rho}$ and $\\cos{\\rho}$, we can figure out the correct quadrant for $\\rho$.\n\n\\end{document}\n", "meta": {"hexsha": "748eb2d87e29e3e49a07f7f50f5c0e84de83ed0a", "size": 6050, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pandora/dutycycle.tex", "max_stars_repo_name": "fergalm/pandora", "max_stars_repo_head_hexsha": "b9545b19dec3e4d606ad57a6affe71bf2d032849", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pandora/dutycycle.tex", "max_issues_repo_name": "fergalm/pandora", "max_issues_repo_head_hexsha": "b9545b19dec3e4d606ad57a6affe71bf2d032849", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pandora/dutycycle.tex", "max_forks_repo_name": "fergalm/pandora", "max_forks_repo_head_hexsha": "b9545b19dec3e4d606ad57a6affe71bf2d032849", "max_forks_repo_licenses": ["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.8902439024, "max_line_length": 420, "alphanum_fraction": 0.7059504132, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6675578124226224}}
{"text": "\n\\chapter{Harmonic Analysis of Functions}\n\\label{ch:harmonic}\n\nIn this chapter, we describe some tools for analyzing functions over probability\nspaces, for which the sample space exhibits a field structure, and the \ndistribution is defined in terms of the field operations.  In this case, we can \nobtain decompositions with special properties, that helps in \nanalysing such distributions. We will be concerned with\nthe sample space which is the vector space of functions of the \nform $f:\\F_p^R \\rightarrow \\F_p$ ($p$ is a prime).\n We  extend these decompositions and the associated results\n to the case when the domain is the subspace of low degree\n polynomials over $\\F_p$. We prove an  analogue of  hypercontractivity\n  for functions over this subspace (\\lref[Lemma]{thm:hyp-for-poly}), by \n reducing it to the result  on the full space (\\lref[Lemma]{thm:mov-to-poly}).\n This enables us to prove an analogue of a\n  result by Alon \\etal ~\\cite{AlonDFS2004} (\\lref[Lemma]{thm:dict}), to \n  functions on the subspace (\\lref[Lemma]{thm:derand-dict}). We use\nthese results later in \\lref[Chapter]{ch:graph-prod}, for proving some\nderandomized graph product results.\n  \n\\section{Harmonic Analysis for Fields}\n\\label{sec:harmonic}\n\nConsider the probability space $(\\F_p,\\mu)$ where $\\mu$ is the uniform\nprobability measure over $\\F_p$. We will be working with functions of the form\n$A:\\F_p^R \\rightarrow \\C$. Note that all such functions form a vector space over\n$\\C$ with dimension $p^R$. Characters are a natural orthogonal basis for this\nvector space.\n\n\\begin{definition}[Character] A \\emph{character} of $\\F_p^R$ is a function\n$\\chi:\\F_p^R \\rightarrow \\C$ such that \n$$\\chi(0) = 1~~~~ \\text{ and }~~~~ \\forall f,g\n\\in \\F_p^R,~ \\chi(f+g) = \\chi(f)\\chi(g).$$ \n\\end{definition}\n\nThe following lists the basic properties of characters, which can\nbe verified easily.\n\n\\begin{observation} \\label{lem:fourier} \nLet $\\{1,\\omega,\\cdots,\\omega^{p-1}\\}$ be the\n$p$th roots of unity and for $\\beta,f \\in \\F_p^R$, \n$$\\chi_\\beta(f) := \\omega^{ \\beta \\cdot f } ~~~~\\text{where}~~~~ \\beta \\cdot f := \\sum_{i=1}^R \\beta_i f_i \\mod p.$$ \n\\begin{itemize} \n\\item The characters of $\\F_p^R$ are $\\{ \\chi_\\beta : \\beta \\in \\F_p^R\\}$. \n\\item Characters forms an orthonormal basis for the vector space of \nfunctions from $\\F_p^R$ to $\\C$, under the inner product \n$$\\langle A, B\\rangle := \\E_{f \\in \\F_p^R}\\left[A(f)\\overline{B(f)}\\right].$$ \n\\item Any function $A:\\F_p^R \\rightarrow \\C$\ncan be uniquely decomposed as \n$$A(f) = \\sum_{\\beta \\in \\F_p^R}\\widehat{A}(\\beta) \\chi_\\beta(f)~~~~\\text{\nwhere} ~~~~\\widehat{A}(\\beta) := \\E_{g \\in \\F_p^R} \\left[A(g) \n\\overline{\\chi_\\beta(g)}\\right].$$ \n\\item For any function $A:\\F_p^R \\rightarrow\\C$, \n\\begin{equation}\n\\label{eqn:parseval}\n\\sum_{\\beta \\in \\F_p^R} |\\widehat A(\\beta)|^2 = \\E_{f\\in \\F_p^R} \\left[|A(f)|^2\\right].\n\\end{equation}\n\\item For any function $A:\\F_p^R\\rightarrow \\{1,\\omega,\\cdots,\\omega^{p-1}\\}$, \n\\begin{equation}\n\\label{eqn:plancheral}\n\\sum_{\\beta\\in \\F_p^R}|\\widehat A(\\beta)|^2 =1.\n\\end{equation}\n\\end{itemize} \n\\end{observation}\n\n\\begin{remark}\n\\label{rem:char-f2}\nNote that when $p=2$, the roots of unity are $\\{-1,+1\\}$. Then the characters\nare real valued functions. It is easy to see that they form a orthonormal\nbasis for the real vector space of functions of the form $A:\\F_2^R \\rightarrow\n\\R$. Hence all the above properties hold with respect to this vector space\nas well.\n\\end{remark}\n\n\\begin{definition}[Generalized Dictator] A \\emph{generalized dictator} function \n$A:\\F_p^R \\rightarrow\n\\C$ is one that depends only on a single coordinate. That is, $\\exists i \\in\n[R]$ such that for any $\\beta \\in \\F_p^R$, if it has a non-zero entry in some\n coordinate $j\\neq i$ then $\\widehat A(\\beta) = 0$. \n\\end{definition}\n\n\\begin{definition}[Fourier degree] The \\emph{Fourier degree} of a function\n$A:\\F_p^R \\rightarrow \\C$ is the smallest number $d$ such that $A$ can be\nwritten as $$A = \\sum_{\\beta: |\\beta| \\leq d} \\widehat A(\\beta) \\chi_\\beta$$\nwhere $|\\beta|$ is number of coordinates $i$ where $\\beta_i \\neq 0$.\n\\end{definition}\n\nAn interesting fact about functions of the form $A:\\F_2^R \\rightarrow \\{0,1\\}$\nis that, if $A$ has Fourier degree $1$ then $A$ is a generalized dictator function. \nThe\nfollowing theorem over $\\F_p$, says that if the sum of squares of absolute\nvalues of Fourier coefficients of $A$ with $|\\beta| >1$ is small, then it is\nclose to a generalized dictator function. It is a generalization of\nthe well known FKN Theorem (see \\cite{FriedgutKN2002}), which\ngives the result for $p=2$.\n\n\\begin{lemma}[Alon \\etal\\ \\cite{AlonDFS2004}] \\label{thm:dict} \nFor every prime $p$, there is constant\n$K$ (that depends on $p$) such that the following holds: \nIf $A:\\F_p^R \\rightarrow \\{0,1\\}$ satisfies\n$$\\sum_{|\\alpha| > 1} |\\widehat A(\\alpha)|^2 \\leq \\epsilon \\text{ and } \\widehat\nA(0) =\\delta$$ \nthen there exists a generalized dictator $B:\\F_p^R \\rightarrow \\{0,1\\}$ such that \n$$\\|A-B\\|_2 \\leq \\frac{K\\epsilon}{\\delta -\\delta^2 -\\epsilon}.$$\n\\end{lemma} \nThe above lemma is proved using the following hypercontractive\ninequality. \n\\begin{lemma}[Hypercontractivity] \\label{thm:hyp} \nFor every prime $p$, there is a\nconstant $C$ (that depends on $p$)\n such that for any function $A:\\F_p^R \\rightarrow \\C$ with $\\widehat\nA(\\alpha) = 0$ when $|\\alpha| > t$, \n$$ \\|A\\|_4 \\leq C^t \\|A\\|_2.$$ \n\\end{lemma}\n\nIn the next section we will prove derandomized versions of the above lemmas.\n\n\\section{Polynomial Subspaces} \n\nLet $\\Pe_{r,d}$ be the set of degree $d$\npolynomials on $r$ variables over $\\F_p$, with individual degrees $< p$\n(the prime $p$ will be clear from the context). Let\n$\\mathfrak F_r := \\Pe_{r,(p-1)r}$. Note that $\\mathfrak F_r$ is the set of all\nfunctions from $\\F_p^r$ to $\\F_p$. $\\mathfrak F_r$ is a $\\F_p$-vector space of\ndimension $p^r$ and $\\Pe_{r,d}$ is its subspace of dimension $r^{O(d)}$. The\n\\emph{Hamming distance} between $f$ and $g \\in \\mathfrak F_r$, denoted by\n$\\Delta(f,g)$, is the number of inputs on which $f$ and $g$ differ. When $S\n\\subseteq \\mathfrak F_r$, $\\Delta(f, S) := \\min_{g\\in S} \\Delta(f,g)$. We say\n$f$ is $\\Delta$-far from $S$ if $\\Delta(f,S) \\geq \\Delta$ and $f$ is\n$\\Delta$-close to $S$ otherwise. For a polynomial $\\alpha \\in \\Pe_{r,d}$,\nthe support size of the polynomial is $|\\alpha| := |\\{ x: \\alpha(x) \\neq 0\\}|$.  \nGiven $f,g, \\in \\mathfrak F_r$, the \\emph{dot\nproduct} between them is defined as \n$$ f \\cdot g  := \\sum_{x \\in\\F_p^r}f(x)g(x) \\mod p.$$ \nFor a subspace $S \\subseteq \\mathfrak F_r$, the \\emph{dual subspace}\nis defined as \n$$S^{\\perp} := \\{ g \\in \\mathfrak F_r : \\forall f \\in S,  g \\cdot f  = 0 \\}.$$ \nThe following theorem relating dual spaces is well known.\n\n\\begin{lemma} \\label{lem:dual}\n$\\Pe_{r,d}^\\perp =\\Pe_{r,(p-1)r-d-1}$\n\\end{lemma} \n\\begin{proof}\nFirst note that the dimensions of the two subspaces are equal by a counting argument.\nNext we show that $\\Pe_{r,d}^\\perp \\supseteq \\Pe_{r,(p-1)r-d-1}$. We just need to show that for any\nmonomial of degree $(p-1)r - d -1$ with individual degrees $<p$, the dot product with any monomial of\ndegree $d$ with individual degrees $<p$ is $0$. The product of any such pair of monomials\nis a monomial with total degree at most $(p-1)r - 1$, and hence has a variable with\ndegree $<p-1$. Without loss of generality, let this variable be $x_1$ with degree $t < p-1$. \n Notice that $\\sum_{x_1 \\in \\F_p} x_1^t = 0 \\mod p$  and hence the dot product is $0$. \n\\end{proof}\n\nWe need the following Schwartz-Zippel-like Lemma for degree $d$ polynomials. \n\n\\begin{lemma}[Schwartz-Zippel lemma~{\\cite[Lemma~3.2]{HaramatySS2013}}] \n\\label{lem:SZ} Let $f\\in \\F_p[x_1,\\cdots,x_r]$ be a\nnon-zero polynomial of degree at most $d$ with individual degrees at most $p-1$.\nThen the support size ($|f| := |\\{ x: f(x) \\neq 0\\}|$) satisfies\n$$|f| \\geq p^{r-d/(p-1)}.$$ \n\\end{lemma}\n The following lemma is an easy consequence of \\lref[Lemma]{lem:SZ}.\n \n \\begin{lemma} \\label{lem:low-deg-local-ind} Let $g$ be a\nuniformly random polynomial from $\\Pe_{r,d}$. Then its truth table as a random string of length $p^r$\nover the alphabet $\\F_p$, is $p^{\\lfloor (d+1)/(p-1) \\rfloor} - 1$-wise independent.\n\\end{lemma} \n\\begin{proof} From  \\lref[Lemma]{lem:SZ} and\n\\lref[Lemma]{lem:dual}, we know that any non-zero polynomial in $\\Pe^{\\perp}_{r,d} = \\Pe_{r,(p-1)r - d -1}$\nhas support size at least $p^{\\lfloor (d+1)/(p-1) \\rfloor}$. Suppose there is a subset $S$\nof size $p^{\\lfloor (d+1)/(p-1) \\rfloor}-1$, where $g$ is not uniform. Let $V \\subseteq \\F_p^{|S|}$\n be the set of restrictions of\ntruth tables of polynomials in $\\Pe_{r,d}$ to $S$. Note that $V$ is a subspace. Since\nthe truth table of $g$ restricted to S is not uniformly distributed, the dimension \nof $V$ is $<|S|$. Then $V^{\\perp} \\subseteq \\F_p^{|S|}$ is non-empty. Consider a\nnon-zero $v \\in V^{\\perp}$. Then the function $f$ which is zero outside $S$ and $f_{|S} = v$\ncorresponds to a non-zero polynomial which belongs to $\\Pe^{\\perp}_{r,d} = \\Pe_{r,(p-1)r - d -1}$\nwith support $< p^{\\lfloor (d+1)/(p-1) \\rfloor}$ which is a contradiction.\n\n\\end{proof}\n\n\nThe following lemma is an easy consequence of \\lref[Lemma]{lem:low-deg-local-ind} \n\\begin{lemma}\n\\label{lem:interpol}\n Let $d>1$, $X$ be a set of $p^{d}-1$ points in $\\F^r_p$ and\n$f:X \\rightarrow \\F_p$ an arbitrary function. Then there exists a polynomial $q$\nof degree at most $(p-1)d$ such that $q$ agrees with $f$ on all points in $X$.\n\\end{lemma} \n\\begin{proof} \nBy \\lref[Lemma]{lem:low-deg-local-ind}, \nthe truth table of a random polynomial $g$ of degree $(p-1)d$ is $p^d -1$-wise independent.\nHence $g_{|X} = f$ with non-zero probability.\n \\end{proof} \n\n\\section{Harmonic Analysis for Polynomial Subspaces} \n\\label{sec:har-poly}\n\nWe  define a\northonormal basis set of characters for the vector space of functions of the\nform $A:\\Pe_{r,d} \\rightarrow \\C$. \n\\begin{definition}[Character] \nA \\emph{character} of $\\Pe_{r,d}$ is a function $\\chi:\\Pe_{r,d} \\rightarrow \\C$\nsuch that \n$$\\chi(0) = 1 \\text{ and } \\forall f,g \\in \\Pe_{r,d},~ \\chi(f+g)=\\chi(f)\\chi(g).$$ \n\\end{definition}\n\nThe following lists the basic properties of characters \n(similar to \\lref[Observation]{lem:fourier}).  \n \n\\begin{observation}[{\\cite[Section II C]{DinurG2013}}]\n\\label{lem:fourier-poly} \nLet $\\{1,\\omega,\\cdots,\\omega^{p-1}\\}$ be the $p$th roots of\nunity and for $\\beta \\in \\mathfrak F_r, f \\in \\Pe_{r,d}$,\n\n $$\\chi_\\beta(f) := \\omega^{ \\beta \\cdot f } ~~~~\\text{where}\n ~~~~ \\beta \\cdot f := \\sum_{x \\in \\F_p^r} \\beta(x) f(x) \\mod p.$$ \n \n\\begin{itemize} \\item The characters of\n$\\Pe_{r,d}$ are $\\{ \\chi_\\beta : \\beta \\in \\mathfrak F_r\\}$. \\item For any\n$\\beta,\\beta' \\in \\mathfrak F_r$, $\\chi_\\beta = \\chi_\\beta'$ if and only if\n$\\beta-\\beta' \\in \\Pe_{r,d}^\\perp$. \n\\item For $\\beta \\in \\Pe_{r,d}^\\perp$,\n$\\chi_\\beta$ is the constant $1$ function. \n\\item\\label{item:minsup} $\\forall\n\\beta, \\exists \\beta'$ such that $\\beta-\\beta' \\in \\Pe_{r,d}^\\perp$ and\n$|\\beta'| = \\Delta(\\beta, \\Pe_{r,d}^\\perp)$ (i.e., the constant $0$\nfunction is (one of) the closest function to $\\beta'$ in $\\Pe_{r,d}^\\perp$). We\ncall such a $\\beta'$ a minimum support function for the coset $\\beta +\n\\Pe_{r,d}^\\perp$.  \n\\item Characters forms an orthonormal basis for the vector\nspace of functions from $\\Pe_{r,d}$ to $\\C$, under the inner product \n$$\\langle A,\nB\\rangle := \\E_{f \\in \\Pe_{r,d}} \\left[A(f)\\overline{B(f)}\\right].$$ \n\n\\item Any function $A:\\Pe_{r,d} \\rightarrow \\C$ can be uniquely decomposed as \n$$A(f) =\\sum_{\\beta \\in \\Lambda_{r,d}}\\widehat{A}(\\beta) \\chi_\\beta(f) \n~~~~ \\text{where} ~~~~ \\widehat{A}(\\beta) := \\E_{g \\in \\Pe_{r,d}} \\left[A(g)\n\\overline{\\chi_\\beta(g)}\\right]$$\n and $\\Lambda_{r,d}$ is the set of minimum\nsupport functions, one for each of the cosets in $\\mathfrak\nF_r/\\Pe_{r,d}^\\perp$, with ties broken arbitrarily. \n\\item For any function $A:\\Pe_{r,d} \\rightarrow\\C$, \n$$\\sum_{\\beta \\in \\Lambda_{r,d}} \\left|\\widehat A(\\beta)\\right|^2 = \\E_{f\\in \\Pe_{r,d}}\n\\left[\\left|A(f)\\right|^2\\right].$$ \n\\item For any function $A:\\Pe_{r,d}\\rightarrow\\{1,\\omega,\\cdots,\\omega^{p-1}\\}$, \n$$\\sum_{\\beta\\in \\Lambda_{r,d}}|\\widehat A(\\beta)|^2 =1.$$ \n\\end{itemize} \n\\end{observation} \nThe following lemma relates\ncharacters over different domains related by co-ordinate projections.\n\\begin{lemma} \\label{lem:char-projection} \nLet $m \\leq r$ and $\\pi:\\F_p^r\n\\rightarrow \\F_p^m$ be a (co-ordinate) projection i.e., there exist indices $1\n\\leq i_1 < \\cdots < i_m \\leq r$ such that $\\pi(x_1,\\dots,x_r) = (x_{i_1}, \\cdots\n,x_{i_m})$. Then for $f \\in \\Pe_{m,d}, ~\\beta \\in \\Pe_{r,d}$,\n$$\\chi_\\beta(f\\circ \\pi)= \\chi_{\\pi_p(\\beta)}(f),$$ \nwhere $\\pi_p(\\beta)(y):=\\sum_{x \\in \\pi^{-1}(y)} \\beta(x)$. \n\\end{lemma}\n\\begin{proof}\nWithout loss of generality, let $\\{i_1, \\cdots, i_m\\} = \\{1,\\cdots, m\\}$. Then\n\\begin{align*}\n \\chi_\\beta(f\\circ \\pi) &= \\omega^{\\sum_{x \\in \\F_p^r} f\\circ \\pi(x) \\cdot \\beta(x)} \\\\\n&= \\omega^{\\sum_{(x_1,\\cdots,x_m) \\in \\F_p^m} f(x_1,\\cdots,x_m)\\cdot( \\sum_{(x_{m+1},\\cdots, x_n)} \\beta(x))}\\\\\n&= \\chi_{\\pi_p(\\beta)}(f)\n\\end{align*}\n\\end{proof}\n\nInfluence and generalized dictators can be defined for functions on polynomial subspaces\nsimilar to the product setting.\n\n\\begin{definition}[Influence] For a function $A:\\Pe_{r,d} \\rightarrow \\C$ and a\nnumber $k < p^{\\lfloor (d+1)/(p-1) \\rfloor}/2$, the degree $k$ influence of $a\\in\n\\F_p^r$ is defined as \n$$\\Inf^{\\leq k}_a(A) = \\sum_{\\beta \\in \\Lambda_{r,d}:\\beta(a) \n\\neq 0 \\text{ and } |\\beta| \\leq k} |\\widehat A(\\beta)|^2.$$ \n\\end{definition}\n\n\n\\begin{definition}[Generalized Dictator] A function $A:\\Pe_{r,d} \\rightarrow \\C$ is a\ngeneralized dictator if there exists $x\\in \\F_p^r$ and $\\widehat A_0, \\widehat A_{1}, \\cdots,\n\\widehat A_{p-1} \\in \\C$ such that $A$ can be written as $A = \\widehat A_0 +\n\\sum_{i=1}^{p-1} \\widehat A_{i}\\chi_{ie_x}$ where $e_x:\\F_p^r\n\\rightarrow \\F_p$ the indicator function for $x$. \n\\end{definition}\n\n\\begin{lemma}\\label{lem:level1-dict}\nLet $A:\\Pe_{r,d} \\rightarrow \\{0,1\\}$ be such that all non-zero\nFourier coefficients have support size $\\leq 1$. Then $A$ is a generalized dicator.\n\\end{lemma}\n\\begin{proof}\nThe proof is similar to the proof of \\cite[Lemma 2.3]{AlonDFS2004}. Consider the function $(A(f))^2$. Since $A$ is $\\{0,1\\}$ valued $(A(f))^2 = A(f)$. Equation the Fourier coefficients on both sides will give that there is an $x\\in \\F_p^r$ such that $A(f)$ only depends on $f(x)$.\n\\end{proof}\n\n\n\n\nWe prove an analogue of \\lref[Theorem]{thm:hyp}, to functions over polynomial\nsubspaces. \n\n\\begin{lemma}\n\\label{thm:hyp-for-poly} For every prime $p$, \nthere is a constant $C$ such that for $4t\\leq p^{d-1}$\nand any function $A:\\Pe_{r,(p-1)d} \\rightarrow \\C$ with $\\widehat A_\\alpha = 0$ when\n$|\\alpha| > t$, $$\\|A\\|_4 \\leq C^t \\|A\\|_2.$$ \n\\end{lemma} \n\\begin{proof} Follows\nfrom \\lref[Lemma]{thm:mov-to-poly} and \\lref[Lemma]{thm:hyp}. \n\\end{proof}\n\nWe prove an analogue of \\lref[Theorem]{thm:dict}, to functions over polynomial\nsubspaces. \n\\begin{lemma} \\label{thm:derand-dict} \nFor every prime $p$, there is a constant $K$ such\nthat the following holds: If $A:\\Pe_{r,(p-1)d} \\rightarrow \\{0,1\\}$ satisfies\n$$\\sum_{|\\alpha| > 1} |\\widehat A(\\alpha)|^2 \\leq \\epsilon \\text{ and } \\widehat\nA(0) =\\delta$$ \nthen there exists a generalized dictator $B:\\Pe_{r,(p-1)d} \\rightarrow \\{0,1\\}$\nsuch that \n$$\\|A-B\\|^2_2 \\leq \\frac{K\\epsilon}{\\delta -\\delta^2-\\epsilon}.$$\n\\end{lemma} \n\\begin{proof}\nThe proof of the lemma is similar to the proof of \\cite[Lemma 2.4]{AlonDFS2004}.\nLet $K = 2 + 32C^8$ where $C$ is the constant\nfrom \\lref[Lemma]{thm:hyp-for-poly}.\nFirst if $\\epsilon \\geq \\frac{1}{32C^8}$, then the lemma is true. \nThis is because, for any $B:\\Pe_{r,(p-1)d}\\rightarrow\\{0,1\\}$, \n$A-B$ is a $\\{-1, 0,1\\}$ valued function and $\\| A-B\\|^2_2 \\leq 1$.\n\nNow assume $\\epsilon < \\frac{1}{32C^8}$. Let\n$$A_S = \\sum_{|\\alpha| \\leq 1} \\widehat A(\\alpha) \\chi_\\alpha \\mbox{ and } A_L = \\sum_{|\\alpha| > 1} \\widehat A(\\alpha) \\chi_\\alpha.$$\n($S$, $L$ stands for small and large). If $A_S$ were Boolean, it  has to be a dictator by \\lref[Lemma]{lem:level1-dict}. Then the lemma follows by taking $B=A_S$. Consider the following function\nwhich measures the farness of $A_S$ from being Boolean (it is identically $0$, for Boolean functions)\n$$H := A_S^2 - A_S.$$\nSince $A_S$ does not have any Fourier coeffcients with support $>1$, $H$ will have only Fourier coefficients  with $|\\alpha$ to be $0,1$ and $2$.\nLet $e_x$ be the function with $e_x(x)=1$ and $0$ otherwise. Then for $a,b \\in F_p, x,y \\in \\F_p^r$\n$$ \\widehat H(ae_x + be_y) = 2 \\widehat A(ae_x) \\widehat A(be_y).$$\nThe following claim says that the norm of $H$ is small.\n\\begin{claim}\\label{claim:h}\n$$\\|H\\|^2 \\leq 32C^8 \\epsilon.$$\n\\end{claim}\nThe claim is proved later. Let $a_x := \\sum_{ i \\in \\F_p} | \\widehat A(i e_x)|$. Note that\n\\begin{equation}\n\\sum_{x,y \\in \\F_p^r, x\\neq y} a_x a_y \\leq \\frac{\\|H\\|^2}{4} \\leq 8 C^8 .\n\\end{equation}\nAlso from assumptions in the claim, \n\\begin{equation}\n\\sum_{x \\in \\F_p^r} a_x = \\delta - \\delta^2 - \\epsilon.\n\\end{equation}\nLet $y$ be such that $a_y$ is maximal. Then\n$$(\\sum_x a_x)^2 \\leq \\sum_x a_x^2 + 16C^8 \\leq a_y \\sum_x a_x + 16C^8.$$\nThis gives that $a_y \\geq \\delta -\\delta^2 -\\epsilon(1+ 16C^8/(\\delta -\\delta^2 - \\epsilon))$.\nIf $B' := \\widehat A(0) + \\sum_{i \\in \\F_p} \\widehat A(i e_y) \\chi_{i e_y}$, then \nwe have that $\\|A - B'\\|^2_2 \\leq \\epsilon(1+ 16C^8/(\\delta -\\delta^2 - \\epsilon)).$\nNow rounding $B$ to the closest $[0,1]$ valued function $B'$ pointwise, we get that\n$$\\|A-B\\|_2^2 \\leq 2\\|A-B'\\|_2^2 \\leq  \\frac{K\\epsilon}{\\delta -\\delta^2-\\epsilon}.$$\n\n\n\\begin{proof}[Proof of Claim \\ref{claim:h} ]\nFirst notice,\n$$H = A_S^2 - A_S = (A-A_L)^2- (A-A_L) = A_L^2 +A_L(1-2A).$$\nLet $k=2C^4$ and $Z = \\{f : | A_L(f) \\leq k \\sqrt{\\epsilon}\\}$. Since $\\|A_L\\|_2^2 \\leq \\epsilon$,\nby a Markov argument, $\\Pr_f[Z] \\geq 1- 1/k^2$.  Also for every $f \\in Z$,\n$|H(f)| \\leq 2 |A_L(f)| \\leq 2k \\sqrt{\\epsilon}$. Since $H$ has only Fourier coefficients\nwith support size $0,1,2$, we can use \\lref[Lemma]{thm:hyp-for-poly} with $t=2$. The claim follows from\nthe following\n\\begin{align*}\n\\|H\\|_2^2 &= \\E_f |H(f)|^2 = \\Pr[Z] \\E_{f \\in Z} |H(f)|^2   + (1-\\Pr[Z]) \\E_{f \\notin Z} |H(f)|^2\\\\\n&\\leq 4k^2\\epsilon + \\frac{1}{k^2} \\sqrt{\\E_{f \\notin Z} |H(f)|^4}\\\\\n&\\leq 4k^2\\epsilon + \\frac{1}{k} \\sqrt{\\E_{f} |H(f)|^4}\\\\\n&\\leq 4k^2\\epsilon + \\frac{1}{k} C^4 \\|H\\|_2^2 \\leq 32C^8\\epsilon\n\\end{align*}\n\\end{proof}\n\n\\end{proof}\n\\begin{definition}[Lift]\\label{def:lift} For a function $B:\\Pe_{r,d}\n\\rightarrow \\C$ with the Fourier decomposition $B= \\sum_{\\alpha \\in\n\\Lambda_{r,d}} \\widehat{B}(\\alpha) \\chi_\\alpha$, the lift of $B$ denoted by $B'$\nis a function $B':\\Ef_r \\rightarrow \\C$ with the Fourier decomposition $B'=\n\\sum_{\\alpha \\in \\Lambda_{r,d}} \\widehat{B}(\\alpha) \\chi_\\alpha$. In the\ndecomposition of $B'$, $\\chi_\\alpha$'s are functions with domain $\\Ef_r$.\n\\end{definition} \n\\begin{lemma} \\label{thm:mov-to-poly} \nIf $2kt \\leq p^{d-1}$ and\n$B:\\Pe_{r,(p-1)d} \\rightarrow \\C$ be a function such that $\\widehat B(\\alpha) = 0$\nwhen $|\\alpha| > t$ then \n$$\\|B\\|_{2k} = \\|B'\\|_{2k}.$$ \n\\end{lemma} \n\\begin{proof}\nFrom the \\lref[Lemma]{lem:SZ} and \\lref[Lemma]{lem:dual}, we have that $\\forall\n\\alpha \\in \\Pe^{\\perp}_{r,(p-1)d}\\setminus \\{0\\},~|\\alpha| > p^{d-1}$. So if\n$\\exists \\{\\alpha_i,\\beta_i \\}_{i \\in [k]}$ with $|\\alpha_i|,|\\beta_i| \\leq t$,\nthen \\begin{equation} \\label{eqn:small-sup-is-zero} \\sum_{i \\in [k]} \\alpha_i\n-\\beta_i \\in \\Pe^{\\perp}_{r,(p-1)d} \\Rightarrow \\sum_{i \\in [k]} \\alpha_i -\\beta_i =\n0. \\end{equation} This is because $\\sum_{i \\in [t]} \\alpha_i -\\beta_i$ has\nsupport size at most $2kt < p^{d-1}$. We use this fact to prove the theorem as\nfollows: \\begin{align*} \\|B\\|_{2k}^{2k} & = \\E_{f \\in \\Pe_{r,(p-1)d}} |B(f)|^{2k} \n= \\E_{f \\in \\Pe_{r,(p-1)d}} \\prod_{i \\in [k]}B(f)\\overline {B(f)}\\\\\n&=\\sum_{\\alpha_1,\\beta_1,\\cdots,\\alpha_k,\\beta_k \\in \\Lambda_{r,(p-1)d}}\n\\left(\\prod_{i \\in [k]}\\widehat B_{\\alpha_i} \\overline{\\widehat\nB_{\\beta_i}}\\right) \\E_{f \\in \\Pe_{r,(p-1)d}} \\prod_{i \\in [k]} \\chi_{\\alpha_i}(f)\n\\overline{\\chi_{\\beta_i}(f)}\\\\\n&=\\sum_{\\substack{\\alpha_1,\\beta_1,\\cdots,\\alpha_k,\\beta_k \\in \\Lambda_{r,(p-1)d}\\\\\n\\sum_i \\alpha_i -\\beta_i \\in \\Pe^{\\perp}_{r,(p-1)d}}}~ \\prod_{i \\in [k]}\\widehat\nB_{\\alpha_i} \\overline{\\widehat B_{\\beta_i}} \\\\\n&=\\sum_{\\substack{\\alpha_1,\\beta_1,\\cdots,\\alpha_k,\\beta_k \\in \\Lambda_{r,(p-1)d} \\\\\n\\sum_i \\alpha_i -\\beta_i = 0}}~ \\prod_{i \\in [k]}\\widehat B_{\\alpha_i}\n\\overline{\\widehat B_{\\beta_i}}~~(\\text{ from }\n\\eqref{eqn:small-sup-is-zero}~)\\\\ &=\n\\sum_{\\alpha_1,\\beta_1,\\cdots,\\alpha_k,\\beta_k\\in \\Lambda_{r,(p-1)d}} \\left(\\prod_{i\n\\in [k]}\\widehat B_{\\alpha_i} \\overline{\\widehat B_{\\beta_i}}\\right) \\E_{f \\in\n\\Ef_r} \\prod_{i \\in [k]} \\chi_{\\alpha_i}(f) \\overline{\\chi_{\\beta_i}(f)}\\\\ &=\n\\E_{f \\in \\Ef_r} \\prod_{i \\in[k]}B'(f)\\overline {B'(f)} = \\E_{f \\in \\Ef_r}\n|B'(f)|^{2k}=\\|B'\\|_{2k}^{2k} \\end{align*} \\end{proof}\n\n\n\\subsection{Folding over Subspace} \n\n\\begin{definition}[Folded function over a subspace] \nFor any set $S$, a function $A: \\Pe_{r,(p-1)d} \\rightarrow S$ is said\nto be folded over a subspace $J \\subseteq \\Pe_{r,(p-1)d}$ if $A$ is constant\nover cosets of $J$ in $\\Pe_{r,(p-1)d}$. \n\\end{definition} \n\\begin{fact}\n\\label{fact:ideallift} Given a function $A:\\Pe_{r,(p-1)d}/J \\rightarrow S$ there\nis a unique function $A':\\Pe_{r,(p-1)d} \\rightarrow S$ that is folded over $J$\nsuch that for $g \\in \\Pe_{r,(p-1)d}, A'(g) = A(g + J)$. \n\\end{fact} \nGiven\n$q_1,\\cdots, q_k \\in \\Pe_{r,3(p-1)}$, let \n$$J(q_1,\\dots,q_k): = \\left\\{ \\sum_i r_i q_i : r_i \\in \\Pe_{r,(p-1)(d-3)}\\right\\}.$$ \nThe following lemma shows that\nif a function is folded over $J=J(q_1,\\dots,q_k)$, then it cannot have weight on\nsmall support characters that are non-zero on $J$ (this is a generalization of\nthe corresponding lemma by Dinur \\& Guruswami~\\cite{DinurG2013} to arbitrary\nfields). \n\\begin{lemma} \\label{lem:goodsupport} Let $\\beta \\in \\mathfrak F_r$ is\nsuch that $|\\supp(\\beta)| < p^{d-3}$, and there exists $x \\in \\supp(\\beta)$ with\n$q_i(x) \\neq 0$ for some $i$. Then if $A:\\Pe_{r,d}\\rightarrow \\C$ is folded over\n$J=J(q_1,\\dots,q_k)$, then $\\widehat{A}(\\beta) = 0$. \n\\end{lemma} \n\\begin{proof}\nConstruct a polynomial $t$ which is zero at all points in support of $\\beta$\nexcept at $x$. From \\lref[Lemma]{lem:interpol}, its possible to construct such a\npolynomial of degree at most $(p-1)(d -3)$. Then we have that $tq_i \\in J$ and\n$\\langle\\beta,tq_i\\rangle \\neq 0$. Now \n\\begin{align*}\n\\E_h\\left[A(h)\\chi_\\beta(h)\\right] &=\\frac{1}{p} \\E_h[ A(h)\\chi_\\beta(h) +\nA(h+tq_i)\\chi_\\beta(h+tq_i)+\\cdots \\\\\n&\\qquad + A(h+(p-1)tq_i)\\chi_\\beta(h+(p-1)tq_i)]\\\\\n &=\\frac{1}{p}\\E_h[ A(h)\\chi_\\beta(h) + A(h)\\chi_\\beta(h+tq_i) +\\cdots\\\\\n & \\qquad + A(h)\\chi_\\beta(h+(p-1)tq_i)]\\\\ \n &=\\frac{1}{p}\\E_h[ A(h)\\chi_\\beta(h)(1+\\chi_\\beta(tq_i)+\\cdots+\\chi_\\beta((p-1)tq_i)) ]\\\\ \n &=\\frac{1}{p}\\E_h[ A(h)\\chi_\\beta(h)(1+\\omega^{t(\\beta \\cdot q_i)}+\\cdots+\\omega^{(p-1)t(\\beta \\cdot q_i)}) ] =0\\qquad \\qedhere \n\\end{align*} \nThe last step is due to the fact that  the sum $(1+\\omega+\\cdots+ \\omega^{p-1}) =0$. Since $t(\\beta\\cdot q_i) \\neq 0$,\nthe previous equation contains this sum.\n\\end{proof}\n", "meta": {"hexsha": "067642374d15f4f3212c8b6c83a8a0d854cf4a96", "size": 23109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter3.tex", "max_stars_repo_name": "geevi/tifr-thesis", "max_stars_repo_head_hexsha": "885257ecb3b7323806213a38a6a6dc4252e25585", "max_stars_repo_licenses": ["MIT"], "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/chapter3.tex", "max_issues_repo_name": "geevi/tifr-thesis", "max_issues_repo_head_hexsha": "885257ecb3b7323806213a38a6a6dc4252e25585", "max_issues_repo_licenses": ["MIT"], "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/chapter3.tex", "max_forks_repo_name": "geevi/tifr-thesis", "max_forks_repo_head_hexsha": "885257ecb3b7323806213a38a6a6dc4252e25585", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-05-17T06:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-23T07:07:46.000Z", "avg_line_length": 50.2369565217, "max_line_length": 280, "alphanum_fraction": 0.6577091177, "num_tokens": 8717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6675578095548136}}
{"text": "\\subsection*{Binary boolean operators}\n\n\\subsubsection*{\\href{https://sourceacademy.org/sicpjs/1.1.6\\#p4}{Conjunction}}\n\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{\\&\\&}} \\ \\textit{expression}_2\n\\]\nstands for\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{?}} \\ \\textit{expression}_2 \\ \\textbf{\\texttt{:}}\\ \\textbf{\\texttt{false}}\n\\]\n\n\\subsubsection*{\\href{https://sourceacademy.org/sicpjs/1.1.6\\#p4}{Disjunction}}\n\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{||}} \\ \\textit{expression}_2\n\\]\nstands for\n\\[\n\\textit{expression}_1 \\ \\textbf{\\texttt{?}}\\ \\textbf{\\texttt{true}}\\  \\textbf{\\texttt{:}}\\ \\textit{expression}_2\n\\]\n\n\n\n", "meta": {"hexsha": "45e7dc2cdc911199207b4b939e81de0ab0c38dcb", "size": 620, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/specs/source_boolean_operators.tex", "max_stars_repo_name": "petermonky/js-slang", "max_stars_repo_head_hexsha": "5504655fbb313019e54ebe29351151e4dbd3b521", "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/specs/source_boolean_operators.tex", "max_issues_repo_name": "petermonky/js-slang", "max_issues_repo_head_hexsha": "5504655fbb313019e54ebe29351151e4dbd3b521", "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/specs/source_boolean_operators.tex", "max_forks_repo_name": "petermonky/js-slang", "max_forks_repo_head_hexsha": "5504655fbb313019e54ebe29351151e4dbd3b521", "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": 24.8, "max_line_length": 114, "alphanum_fraction": 0.6758064516, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6675578081961875}}
{"text": "\\lab{The SVD and Image Compression}{SVD}\n\n\\objective{Learn how to compute the compact SVD. Explore the SVD as a method of matrix approximation, and use it to perform image compression.}\n\\label{lab:SVD}\n% TODO\n% - write a more compelling objective.\n% - add references to the textbook and determine what is actually needed here. The explanation in the textbook is way better.\n%\n\n\nThe \\emph{Singular Value Decomposition} or \\emph{SVD} is a matrix decomposition that is widely used in both theoretical and applied mathematics.\nOriginally discovered by theoretical mathematicians, it is a canonical way to decompose a matrix.\nIts practical use became apparent later on when Erhard Schmidt showed that the SVD could be a computational tool for providing low-rank matrix approximations.\nModern developments continue to confirm the importance of the SVD in both computational and theoretical applications.\n\n\\begin{comment}\nThe theoretical use of the \\emph{Singular Value Decomposition} or \\emph{SVD} has long been appreciated.\nIn fact, the idea of a canonical way of decomposing a matrix was so alluring that the SVD was independently discovered by at least four people through use of both  integral equations and systems of linear equations.\n\nHowever, it wasn't until Erhard Schmidt showed how the SVD could be a computational tool for providing low-rank approximations that the practical applications became apparent.\nSince Schmidt's work, further developments have confirmed the importance of the SVD in both computational and theoretical applications.\n\\end{comment}\n\n\\begin{comment}\n\nThe \\emph{Singular Value Decomposition} is so important that it was discovered multiple times by different people in different ways.\nThe foundation work in systems of linear equations was laid by Gauss and Cauchy in the 1820's and later by Jacobi in 1846 with his work with the LU decomposition; however, the real work with the SVD started with Eugenio Beltrami.\nIn a paper he published in 1873 he was the first to work with the SVD; he was limited to real, square, nonsingular matrices with distinct singular values.\nA year later, Camille Jordan published his own independent work that was more rigourus and avoided some of the pitfalls of Beltrami's research.\nTogether, Beltrami and Jordan are considered the codiscoverers of the singular value decomposition.\n\nLater, James Joseph Sylvester independently presented an iterative algorithm and a rule for carrying out the reduction in 1889.\nThis rule was essentially Beltrami's work.\nHowever Sylvester sent the note detailing his rule to the same journal Jordan had published in, showing not just his ignorance of Jordan's and Beltrami's works but his perception of the importance of the SVD.\n\nThe concurrent and independant derivation of the SVD shows its importance as a theoretical tool, but it wasn't until Erhard Schmidt discovered a computational use for the SVD that the practical applications became apparent.\nSchmidt used integral equations rather than linear equations to derive the SVD, but\nhis most important contribution was showing how the SVD could be a computational tool to obtain optimal, low-rank approximations.\n\nSince Schmidt's work, further devolpments have confirmed the importance of the SVD in both practical and theoretical applications.\n\\end{comment}\n\n\\subsection*{Computing the SVD}\n\n\nThe Singular Value Decomposition decomposes an $m \\times n$ matrix $A$ into the form\n\\begin{equation*}\nA = U \\Sigma V\\hrm\n\\end{equation*}\nwhere $U$ and $V$ are square and unitary of sizes $m$ and $n$ respectively, and $\\Sigma$ is diagonal and of size $m \\times n$.\nThe values along the diagonal of $\\Sigma$ are called the \\emph{singular values} of $A$.\nThese are also the square roots of the eigenvalues of $A\\hrm A$.\n% if $A$ is square, are equal to the absolute value of the eigenvalues of $A$.\nCommonly the singular values are listed in decreasing order. Thus we have\n\n\\begin{equation*}\n\\Sigma = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_n)\n\\end{equation*}\nwhere $\\sigma_1 \\geq \\sigma_2 \\geq \\ldots \\geq \\sigma_n \\geq 0$ are the singular values of $A$.\n\nIf A is of rank $r$, then A has exactly $r$ nonzero singular values.\nThe first $r$ columns of U span the range of A, and the last $n -r$ columns span the null space of $A\\hrm$.\nLikewise, the first $r$ columns of V span the range of $A\\hrm$ and the last $m - r$ span the null space of $A$.\n\nFor a more in-depth definition and proof that the SVD exists for every matrix, refer to the section on the SVD in the text.\nHere we will focus on computing the SVD.\n\nFirst, we define two modifications of the regular SVD.\nIn the \\emph{compact SVD}, we only keep the $r$ nonzero singular values.\nOnly $r$ column vectors of $U$ and $r$ row vectors of $V\\hrm$, corresponding to the $r$ singular values, are calculated.\nThe compact SVD takes the form $A= U_r \\Sigma_r V_r\\hrm$ where $U_r$ is $m\\times r$, $\\Sigma_r$ is $r\\times r$ and diagonal, and $V_r\\hrm$ is $r\\times n$.\nAlthough we drop the decompositions of the nullspaces, by calculating $U_1 \\Sigma_1 V_1\\hrm$ we can still recover the full matrix $A$.\n\nThe \\emph{truncated SVD} is similar to the compact SVD, but instead of keeping all the nonzero singular values, we only keep the $k$ largest.\nWhile this saves space, it means that we cannot recover the whole matrix.\nInstead we end up with $\\widehat A_k = U_k\\Sigma_k V_k\\hrm$ where $\\widehat A_k$ is a rank $k$ approximation of $A$, $U_k$ is $m\\times k$, $\\Sigma$ is $k \\times k$ and diagonal, and $V_k\\hrm$ is $k \\times n$.\n\nThe components of the compact or truncated SVD can be calculated as follows:\n\\begin{itemize}\n\\item The singular values of $A$, which form the diagonal of $\\Sigma$, are the square roots of the eigenvalues of $A\\hrm A$.\nThese are sorted in descending order.\nFor the compact SVD, keep all of the nonzero singular values.\nFor the truncated SVD, keep only the largest $k$.\n\\item The columns of $V$ are the eigenvectors of $A\\hrm A$, where the $i$th column $V_i$ matches the $i$th singular value.\n\\item The columns of $U$ are $U_i = \\frac{1}{\\sigma_i} AV_i$.\n\\end{itemize}\n\n\\begin{comment}\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\caption{SVD for Full Rank Square Matrices.}\n\\label{Alg:svd_full}\n\\Procedure{SVD}{$A$}\n\\State $n \\gets \\shape{A}$\n\\State $eigs \\gets$ eigenvalues$(A\\hrm A)$\n\\State sort$(eigs)$\n\\State $V \\gets$ eigenvectors$(A\\hrm A)$\n\\State $svals \\gets \\sqrt{eigs}$\n\\State $U \\gets \\allocate{n,n}$\n\\For{$i=0\\ldots n-1$}\n      \\State $U_i \\gets  \\frac{1}{svals[i]} AV_i$\n\\EndFor\n\\State $S \\gets$ diag$(svals)$\n\\State \\pseudoli{return} $U, S, V\\hrm$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\\end{comment}\n\n\\begin{problem}\nWrite a function \\li{truncated_svd} that accepts a matrix $A$ and an optional integer \\li{k = None}.\nIf \\li{k} is \\li{None}, calculate the compact SVD. If \\li{k} is an integer, calculate the truncated SVD, keeping only the \\li{k} largest singular values.\n(Note: if there are fewer than \\li{k} nonzero singular values, the truncated SVD will come out the same as the compact SVD.)\nSince the only difference between these two processes is the number of singular values we keep, we only need to write one function.\n\nHere's an outline to follow:\n\n\\begin{enumerate}\n\\item Find the eigenvalues and eigenvectors of $A\\hrm A$.\n\\item Find the singular values of $A$. Keep only the greatest \\li{k}, and discard any that are equal to zero.\n\\item Calculate $V$.\n\\item Calculate $U$.\n\\end{enumerate}\n\nReturn U, the diagonal of $\\Sigma$, and V.\nCheck your function by calculating the compact SVD and seeing if $U\\Sigma V\\hrm = A$ using \\li{np.allclose()}.\n\nHint: When calculating the SVD, you will need to sort the eigenvalues while keeping track of their associated eigenvectors.\nConsider using the function \\li{np.argsort} for keeping the eigenvalues and eigenvectors in the same order while sorting.\n%Look for places to use fancy indexing when sorting and selecting the singular values.\n\\label{prob:calc_svd}\n\\end{problem}\n\n\\begin{comment}\n%Commented out because finding the rest of the SVD isn't important to this lab.\n%They can reference the book for this information.\nIf $A$ is full rank and square, it has $n$ nonzero singular values and this process gives us the full SVD.\nIf $A$ is not full rank or not square, we can compute the first $r$ columns of $U$ and $V$, where $r$ is the number of nonzero singular values, in this way.\nTo find the rest of the SVD, we can use Gram-Schmidt orthonormalization.\n\nMore specifically, let $r$ be the number of nonzero singular values.\nIf $r<n$ then we only have $r$ eigenvectors to fill $V$, which is a $n\\times n$ matrix.\nWe find the remaining columns of $V$ by using Gram-Schmidt orthonormalization to finish the basis for $n$-space.\nSimilarly, if $r<m$ then we only have $r$ columns of $U$ so we use Gram-Schmidt orthonormalization to finish the basis for $m$-space.\nThe compact SVD does not have this problem because $U_1$ and $V_1$ only have $r$ columns, the remaining columns are the decomposition of the null space of the matrix, and are not included.\nIn this lab we calculate the compact SVD for simplicity.\n\\end{comment}\n\n\\begin{info}\nIn practice, calculating $A\\hrm A$ in order to find its eigenvalues is unstable.\nWe use this method here because it is mathematically the simplest.\nHowever, industrial SVD solvers use different methods that avoid computing $A\\hrm A$.\n\\end{info}\n\n\\subsection*{Visualizing the SVD}\nRecall that a matrix is a way to express a linear transformation.\nAn $m\\times n$ matrix defines a linear transformation that sends points from $\\mathbb{R}^n$ to $\\mathbb{R}^m$.\n\nIntuitively, the SVD can be thought of as breaking a linear transformation into more basic steps.\nThe SVD decomposes a given matrix into two rotations and a scaling.\n$V\\hrm$ represents a rotation, $\\Sigma$ represents a rescaling along the principal axes, and $U$ represents another rotation.\n\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{unit_circle.pdf}\n  \\caption{The unit circle, $S$, with two unit vectors.}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{vcircle.pdf}\n  \\caption{$V\\hrm S$}\n  %\\label{fig:svals_plot}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{svcircle.pdf}\n  \\caption{$\\Sigma V\\hrm S$}\n  %\\label{fig:svals_plot}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{full_transformation.pdf}\n  \\caption{$U \\Sigma V\\hrm S$}\n  %\\label{fig:svals_plot}\n\\end{subfigure}\n\\caption{Each step in transforming the unit circle and two unit vectors using the matrix $A$.}\n\\label{fig:sol1}\n\\end{figure}\n\n\\begin{problem}\nIn this problem we will use the SVD to visualize how the matrix\n\\[A =  \\left[\\begin{array}{cc}3 & 1\\\\1 & 3\\end{array}\\right]\\]\nacts on points in $\\mathbb{R}^2$.\nGiven a set of points $S$ in $\\mathbb{R}^2$, we can calculate the transformation $AS$ in steps by using the SVD $A = U\\Sigma V\\hrm$.\n\nSpecifically, let $S$ be a set of points on the unit circle.\nTo generate the $x$- and $y$-coordinates of $S$, recall the equation for the unit circle in polar coordinates:\n\\begin{align*}x = \\cos(\\theta) && y = \\sin(\\theta),\\end{align*}\nwhere $\\theta \\in [0, 2\\pi].$\n\nPlot four separate subplots to demonstrate each step of the transformation, plotting $S$, $V\\hrm S$, $\\Sigma V\\hrm S$, then $U\\Sigma V\\hrm$.\nDo the same for the standard basis vectors $\\e_1 = [1, 0]\\trp$ and $\\e_2 = [0, 1]\\trp$.\nYour solution should look similar to Figure \\ref{fig:sol1}.\n\\\\(Hint: Force the plot to use the same scale on each of the axes with \\li{plt.axis(\"equal\")}. Otherwise, the circle will appear elliptical.)\n\\end{problem}\n\n\\begin{comment}\n\\subsection*{Image Data Compression}\nIn this lab, we explore how the SVD can be used to compress image data.\nRecall that an image is simply a matrix where each position is the color value for the pixel in that position.\nThe SVD lets us choose how much information to keep, and what information is most important.\nLarger eigenvalues correspond to columns of $U$ and $V$ that contain more information, while smaller eigenvalues correspond to less important columns.\nThis idea is used in many areas of applied mathematics including signal processing, statistics, semantic indexing (search engines), and control theory.\n\\end{comment}\n\n\\subsection*{The SVD and Data Compression}\nWe now turn to computational uses of the SVD. We will explore how the SVD is useful for matrix approximations, and use it to compress images.\n\n\\subsection*{Low-Rank Matrix Approximation}\nIf the rank $r$ of a matrix $A$ is significantly smaller than its dimensions, the compact SVD offers a way to store $A$ with less memory.\nStoring an $m\\times n$ matrix requires storing $mn$ values.\nBy decomposing the original matrix into the compact SVD, $U_r$, $\\Sigma_r$ and $V_r$ together require $mr+r+nr$ values.\nThis is an efficient storage method if $r$ is much smaller than both $m$ and $n$.\nFor example, suppose $m=100$, $n=200$ and $r=20$.\nThen the original matrix would require storing $20,000$ values, whereas the compact SVD only requires storing $6020$.\n\nThe truncated SVD allows even greater efficiency.\nBy only keeping the first $k$ singular values, we can create an approximation $\\widehat A_k = U_k\\Sigma_k V_k\\hrm$.\nThis requires storing only $mk+k+nk$ values.\nAs we make $k$ small, we eventually require very little storage. This comes at the cost of losing information from the original matrix.\n\nThe beauty of the SVD is that it makes it easy to only keep the information that is most important.\nLarger singular values correspond to columns of $U$ and $V$ that contain more information, so dropping the smallest singular values retains as much information as possible.\nIn mathematical terms, given a matrix $A$ and its rank-k truncated SVD approximation $\\widehat A_k = U_k\\Sigma_k V_k\\hrm$, the matrix $\\widehat A_k$ is the \\emph{best rank $k$ approximation} to $A$ (with respect to the induced 2-norm and Frobenius norm).\nThis is a very significant concept in applied mathematics, appearing in areas including signal processing, statistics, semantic indexing, and control theory.\n\n\n\\begin{comment}\nWe can also calculate $\\widehat A$ by finding the full SVD, and setting all singular values after the $k$th to zero.\nThus the modified $\\Sigma$ would be\n\\begin{equation*}\n\\Sigma_{\\widehat A} = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_s,0,\\ldots,0).\n\\end{equation*}\nMultiplying this matrix with the original $U$ and $V\\hrm$ will give the same $\\widehat A$ that was found by computing the truncated SVD directly.\n\\end{comment}\n\n\\subsection*{Implementation}\nWe can use SciPy's linear algebra module to create low-rank SVD approximations or a given matrix.\nThe code below computes the SVD of \\li{A}.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> import scipy.linalg as la\n>>> A = np.array([[1,1,3,4], [5,4,3,7], [9,10,10,12], [13,14,15,16], [17,18,19,20]])\n>>> U,s,Vh = la.svd(A, full_matrices=False)\n\\end{lstlisting}\nIn the last line of code, we included the keyword argument \\li{full_matrices=False} to calculate the\ncompact SVD rather than the full SVD. The arrays \\li{U} and \\li{Vh} correspond to the matrices\n$U_r$ and $V_r\\hrm$ discussed earlier. The array \\li{s} gives the nonzero singular values\nof the matrix \\li{A}, and we can find the rank of \\li{A} by inspecting the number of entries in \\li{s} (here we have a rank 4 matrix).\n\nNext, we calculate a rank 3 approximation.\nWe take the first three singular values, first three columns of \\li{U}, and first three rows of \\li{Vh}.\nWe omit the last singular value from the calculation along with the last column of \\li{U} and last row of \\li{Vh}.\n\n\\begin{lstlisting}\n>>> S = np.diag(s[:3])\n>>> Ahat = U[:,:3].dot(S).dot(Vh[:3,:])\n>>> la.norm(A-Ahat)\n\\end{lstlisting}\nNote that $\\widehat A$ is ``close'' to the original matrix $A$, but that its rank is 3 instead of 4.\n\n\\begin{problem}\nWrite a function \\li{svd_approx} that takes as input a matrix $A$ and a positive integer $k$ and returns\nthe best rank $k$ approximation to $A$ (with respect to the induced 2-norm and Frobenius norm).\nUse \\li{scipy.linalg.svd}.\n\\label{prob:svd_approx}\n\\end{problem}\n\n\\subsection*{Error of Low-Rank Approximations}\n\nRecall that the error between the best rank $s$ approximation $\\widehat{A_s}$ of $A$ with respect to the induced 2-norm is given by\n$$\n\\|A - \\widehat{A_s}\\|_2 = \\sigma_{s+1},\n$$\nwhere $\\sigma_{s+1}$ is the $(s+1)$-th singular value of $A$.\n(See the proof of the Schmidt-Eckard-Young-Mirsky theorem in the text).\n\nThis offers a way to approximate a matrix within an error tolerance:\nchoose the truncated SVD approximation such that the largest discarded singular value is less than the error tolerance.\n\n\\begin{problem}\nUsing \\li{scipy.linalg.svd}, write a function \\li{lowest_rank_approx} that takes as input a matrix $A$ and a positive number $e$ and returns\nthe lowest rank approximation of $A$ with error less than $e$ (with respect to the induced 2-norm).\nYou should only calculate the SVD once.\n\\end{problem}\n\n\n\\begin{comment}\nThe reduced form of the SVD also provides a way to approximate a matrix with another one of lower rank.\nThis idea is used in many areas of applied mathematics including signal processing, statistics, semantic indexing (search engines), and control theory.\nIf we are given a matrix $A$ of rank $r$, we can find an approximate matrix $\\widehat A$ of rank $s<r$ by taking the SVD of $A$ and setting all of its singular values after $\\sigma_s$ to zero, that is,\n\\begin{equation*}\n\\Sigma_{s} = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_s,0,\\ldots,0)\n\\end{equation*}\nand then multiplying the matrix back together again.\nThe more singular values we keep, the closer our approximation is to $A$.\nThe number of singular values we decide to preserve depends on how close of an approximation we need and what our size requirements are for $U_1$, $\\Sigma_{\\widehat A}$, and $V_1$.\nTry plotting the singular values.\n\\end{comment}\n\n\\subsection*{Application to Image Compression}\n\nSometimes there is not enough available bandwidth to transmit a full resolution photograph.\nSuppose you need to transmit an image from a remote location.\nYou might aim to reduce the amount of data being sent, while also minimizing the loss of detail in the image.\n\nThis can be done using the SVD.\nAn image is just a matrix of pixel values, which means it has a singular value decomposition.\nComputing and sending a low-rank SVD approximation of the image can considerably reduce the amount of data sent, while retaining a high level of image detail.\nAdditionally, successive levels of detail can be sent after the inital low-rank approximation by sending additional singular values and their corresponding columns of V and U.\n\nExamining the singular values of an image gives us an idea of how low-rank the approximation can be.\nFigure \\ref{fig:hubble} presents an image and a log plot of its singular values from greatest to least.\nThe plot in \\ref{fig:svals_plot} is typical for a photograph---the singular values start out large but drop off rapidly.\nIn this rank $670$ image, $624$ of the singular values are $50$ or more times smaller than the largest singular value.\nBy discarding these relatively small singular values, we can retain all but the finest image details, while storing only a rank 46 image!\nThis is a huge reduction in data size.\n\nFigure \\ref{fig:rankvalues} shows several low-rank approximations of the image in Figure \\ref{fig:hubble_original}.\nEven at a low rank the image is recognizable.\nBy rank 40, the approximation visibly differs very little from the original.\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth*5/6]{hubble_red}\n\\caption{NGC 3603 (Hubble Space Telescope).}\n\\label{fig:hubble_original}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{hubble_svals}\n\\caption{Singular values from greatest to smallest on a log scale}\n\\label{fig:svals_plot}\n\\end{subfigure}\n\\caption{An image and its singular values.}\n\\label{fig:hubble}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.35\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank1.jpg}\n\\caption{Rank 1}\n\\end{subfigure}\n\\begin{subfigure}[b]{.35\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank14.jpg}\n\\caption{Rank 14}\n\\end{subfigure}\n\n\\begin{subfigure}[b]{.35\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank27.jpg}\n\\caption{Rank 27}\n\\end{subfigure}\n\\begin{subfigure}[b]{.35\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank40.jpg}\n\\caption{Rank 40}\n\\end{subfigure}\n\\caption{Different rank approximations for SVD-based compression.  Notice that higher rank is needed to resolve finer detail.}\n\\label{fig:rankvalues}\n\\end{figure}\n\nThe following code demonstrates how to use \\li{plt.imread} and \\li{plt.imshow} to read in an image, convert it to black and white, and show it.\nThe function from Problem \\ref{prob:svd_approx} can then be used to calculate an approximation of \\li{X}.\n%Enter the following into IPython (note that any image you might have will work):\n\\begin{lstlisting}\n>>> import matplotlib.pyplot as plt\n>>> # Take only one layer (layer 0) of the image\n>>> X = plt.imread('hubble_image.jpg')[:,:,0].astype(float)\n% >>> X.nbytes     #number of bytes needed to store X  <---- this seems superfluous\n>>> plt.imshow(X, cmap=\"gray\")\n>>> plt.show()\n\\end{lstlisting}\n\\begin{comment}\nComputing the SVD of your image is simple.\nRemember to make the singular values a diagonal matrix before multiplying.\n\\begin{lstlisting}\n>>> U,s,Vt = svd(X, full_matrices=False)\n>>> S = sp.diag(s)\n\\end{lstlisting}\nIn the next code block, $k$ represents the desired rank of the output.\n\\begin{lstlisting}\n>>> k = 50\n>>> u1, s1, vt1 = U[:,0:n], S[0:n,0:n], Vt[0:n,:]\n>>> Xhat = u1.dot(s1).dot(vt1)\n>>> (u1.nbytes + np.diag(s1).nbytes + vt1.nbytes) - X.nbytes   #should be negative\n>>> plt.imshow(Xhat)\n>>> plt.show()\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{problem}\nUsing the \\li{svd_approx} function from Problem \\ref{prob:svd_approx}, write a function \\li{compress_img} that accepts two parameters \\li{filename} and \\li{k}. The function should plot the original image and the best rank k approximation of the original image.\n\nWhile \\li{svd_approx} worked for grayscale images, the \\li{compress_img} function should work on color images.\nYou may split the image into its three RGB layers and approximate each layer separately, then recombine them.\nTest your function on \\li{hubble_image.jpg}\nYour output should be similar to Figure \\ref{fig:compressed_image}.\n\nHints:\n\\begin{itemize}\n\\item Sometimes \\li{plt.imshow} does not behave as expected when being passed RGB values between 0 and 255. It behaves much better when being passed values between 0 and 1.\n\\item Since the SVD provides an approximation, it is possible that the SVD will generate values slightly outside the valid range of RGB values.\nTo fix this, use fancy indexing (as discussed in the NumPy and SciPy lab) to set values greater than 1 to 1 and values less than 0 to 0.\n\\end{itemize}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{compressed.jpg}\n\\caption{Correct output for the best rank 20 approximation.}\n\\label{fig:compressed_image}\n\\end{figure}\n\\end{problem}\n", "meta": {"hexsha": "837d46df38da4501d9334b3cdcfa9abb5c1eaa43", "size": 23391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1A/SVD/SVD.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/SVD/SVD.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/SVD/SVD.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": 54.2714617169, "max_line_length": 260, "alphanum_fraction": 0.7584968578, "num_tokens": 6295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.803173801068221, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.6675523243391337}}
{"text": "\\section{Natural Numbers}\nNow that we can write code in Agda, our next goal to understand why we\nwant to write code in Agda, i. e. we want to write code that can’t be\nwritten in other languages. Not even in Haskell—well not yet, or at\nleast not in an easy way.\n\nI mean of course the best feature a programming language can have\n\\emph{Dependent Types}. The standard example for Dependent Types is the\nfix length vector. Don’t worry, if you don’t know what I mean by that\nyou will soon.\n\nBefore we can describe fix length vectors we have to be able to describe\nlength. What better way to describe length but with natural numbers.\n\n\\begin{code}\nmodule Naturals where\n\ndata ℕ : Set where\n  zero : ℕ\n  suc  : ℕ → ℕ\n\\end{code}\n\nWhat's that? This is an algebraic data type similar to those we wrote and use\nin Haskell all day long, or at least we would if we could use Haskell all day\nlong at work.\n\n\\begin{haskell}\ndata Nat = Zero | Suc Nat\n\\end{haskell}\n\nIf we write the same with Haskells GADTs extension we see the resemblance:\n\n\\begin{haskell}\n{-# LANGUAGE GADTs #-}\n\ndata Nat where\n  Zero  :: Nat\n  Suc   :: Nat -> Nat\n\\end{haskell}\n\nSo far so good, but what about \\verb+Set Whe state that \\verb+Bool+ is of type\n\\verb+Set+, which is the type of small types. In Haskell we would say of kind `*`.\n\\verb+Set+ itself is of type \\verb+Set1+ which is of type \\verb+Set2+ and so on. In Haskell\nwe would say nothing like this.\n\n\\begin{haskell}\n{-# LANGUAGE GADTs          #-}\n{-# LANGUAGE KindSignatures #-}\n\ndata Bool :: * where\n  Zero  :: Nat\n  Suc   :: Nat -> Nat\n\\end{haskell}\n\nIn other word being a Type in Haskell means being a Set in Agda.\n\nThat's all we need, to describe every natural number possible.\nQuite cool when you think about it. No little-endian, no big-endian.\n\nLet's define some natural numbers:\n\\begin{code}\nnull : ℕ\nnull = zero\n\nthree : ℕ\nthree = suc (suc (suc zero))\n\\end{code}\n\n\\begin{exercise}\n  Define \\verb+fivethousand+.\n\\end{exercise}\n\nGOTCHA!!!\n\nWe can tell Agda to use Haskell builtin Integers as \\verb+ℕ+.\n\n\\begin{code}\n{-# BUILTIN NATURAL ℕ #-}\n\nfivethousand : ℕ\nfivethousand = 5000000\n\\end{code}\n\nLet's define additions.\n\\begin{code}\ninfixl 6 _+_\n_+_ : ℕ → ℕ → ℕ\n\\end{code}\n\nUsing \\verb+_+ in function names we define pre/in/mix/post-fix operators. The\n$n$-th arguments takes place of the $n$-th \\verb+_+.\n\\begin{code}\nzero + m = m\nsuc n + m = suc (n + m)\n\\end{code}\n\nSince we are all good programmers we want to test this function.\nWe need some imports.\n\\begin{code}\nimport Relation.Binary.PropositionalEquality as Eq\nopen Eq using (_≡_; refl; cong; sym)\nopen Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)\n\\end{code}\n\nWith this we can write a unit test for \\verb=_+_=.\n\\begin{code}\n_ : 2 + 3 ≡ 5\n_ = refl\n\\end{code}\nFor now (this little moment in time) you can think of \\verb+refl+ as\nof an assertion.\n\nWe can write the test in a more human readable form.\n\\begin{code}\n_ : 2 + 3 ≡ 5\n_ =\n  begin\n    2 + 3\n  ≡⟨⟩\n    suc (1 + 3)\n  ≡⟨⟩\n    suc (suc (0 + 3))\n  ≡⟨⟩\n    suc (suc 3)\n  ≡⟨⟩\n    5\n  ∎\n\\end{code}\n\nThis is a lot to take in. First we notice that \\verb=2 + 3 ≡ 5= is a type signature.\nAnd \\verb+_≡_+ is a type constructor.\n\\begin{verbatim}\ninfix 4 _≡_\ndata _≡_ {a} {A : Set a} (x : A) : A → Set a where\n  instance refl : x ≡ x\n\\end{verbatim}\n\\verb+x ≡ x+ is the type of elements which are equal to itself, hence \\emph{reflexive}.\n\nSo\n\\begin{verbatim}\n_ : 2 + 3 ≡ 5\n\\end{verbatim}\ndefines a variable \\verb+_+ containing the information that $2+3$ is equal to $5$.\nThe variable name \\verb+_+ states, that we don't care about the variable itself.\n\n\\begin{verbatim}\n_ = refl\n\\end{verbatim}\ntells Agda to construct an inhabitant of the type \\verb=2 + 3 ≡ 5=, if it can\nwe know they are equal.\n\n\\begin{exercise}\nWrite a test for $3+4$.\n\\end{exercise}\n\nUnlike humans, Agda does not need every step. In fact everything Agda\ndoes is to check, that every expression between \\verb+≡⟨⟩+ reduces to the\nsame expression. Since Agda can reduce the expressions without further\ninformation we could just use \\verb+refl+.\n\n\\subsection{Proofs}\nWith that in mind we could say that we did not just write a test $2+3$ but a proof.\nThe cool thing is, that Agda verifies the proof at compile time, so no need to\nactually “run the test”.\n\nWe just experienced the phenomenon of “Proposition as Types” — whooooo\n\nIf course this proof is as useful as any other unit test … not at all.\nWe test addition for 2 natural numbers this is a fraction of 0\\,\\%.\n\nWe could use QuickCheck to run property test. But again 0\\,\\% coverage.\n\nIn Agda we can do better but first we need some properties for addition to fulfill:\n\\begin{itemize}\n  \\item $0$ is the neutral element\n  \\item assosiative\n  \\item commutative\n\\end{itemize}\n\nFirst we show that \\verb+zero+ is the neutral element. We already\nknow that \\verb+zero+ is neutral rom the left by definition.\n\\begin{code}\n+-rightNeutral : ∀ (m : ℕ) → m + zero ≡ m\n+-rightNeutral zero =\n  begin\n    zero + zero\n  ≡⟨⟩\n    zero\n  ∎\n+-rightNeutral (suc m) =\n  begin\n    suc m + zero\n  ≡⟨⟩\n    suc (m + zero)\n  ≡⟨ cong  suc (+-rightNeutral m) ⟩ -- congruent\n    suc m\n  ∎\n\\end{code}\nAgda makes it explicit that proof by induction is the same a programming\nwith recursion.\n\n\\begin{exercise}\nWe defined \\verb=_+_= left inductive. Proof that it \\verb=_+_= is to right inductive, too.\nI. e. proof\n\n\\begin{code}\n+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)\n\\end{code}\n\\end{exercise}\n\n\\begin{code}\n+-suc zero n =\n  begin\n    zero + suc n\n  ≡⟨⟩\n    suc n\n  ≡⟨⟩\n    suc (zero + n)\n  ∎\n+-suc (suc m) n =\n  begin\n    suc m + suc n\n  ≡⟨⟩\n    suc (m + suc n)\n  ≡⟨ cong suc (+-suc m n) ⟩\n    suc (suc (m + n))\n  ≡⟨⟩\n    suc (suc m + n)\n  ∎\n\\end{code}\n\nWhit that lemma we can proof commutativity.\n\\begin{code}\n+-commutative : ∀ (n m : ℕ) → n + m ≡ m + n\n+-commutative zero m =\n  begin\n    zero + m\n  ≡⟨⟩\n    m\n  ≡⟨ sym (+-rightNeutral m) ⟩\n    m + zero\n  ∎\n+-commutative (suc n) m =\n  begin\n    suc n + m\n  ≡⟨⟩\n    suc (n + m)\n  ≡⟨ cong suc (sym (+-commutative m n)) ⟩\n    suc (m + n)\n  ≡⟨ sym (+-suc m n) ⟩\n    m + suc n\n  ∎\n\\end{code}\n\n\\begin{exercise}\nShow that $+$ is assosiative, i.e.\n\n\\begin{code}\n+-associativ : ∀ (l : ℕ) (m : ℕ) (n : ℕ)\n  → (l + m) + n ≡ l + (m + n)\n\\end{code}\n\\end{exercise}\n\n\\begin{code}\n+-associativ zero m n =\n  begin\n    (zero + m) + n\n  ≡⟨⟩\n    m + n\n  ≡⟨⟩\n    zero + (m + n)\n  ∎\n+-associativ (suc l) m n =\n  begin\n    ((suc l) + m) + n\n  ≡⟨⟩\n    (suc (l + m)) + n\n  ≡⟨⟩\n    suc ((l + m) + n)\n  ≡⟨ cong suc (+-associativ l m n) ⟩ -- congruent\n    suc (l + (m + n))\n  ≡⟨⟩\n   suc l + (m + n)\n  ∎\n\\end{code}\n\nNow we have tests for addition with 100\\,\\% coverage over the input domain,\nalso called \\emph{proofs}.\n\nMaybe we should stop here.\n\n\\begin{code}\ninfixl 7 _*_\n_*_ : ℕ → ℕ → ℕ\nzero * _ = zero\nsuc m * n = n + (m * n)\n\\end{code}\n\n\\begin{exercise}\nProof that $*$ distributive on $+$, .i.e.\n\n\\begin{code}\n*-distributive : ∀ (l : ℕ) (m : ℕ) (n : ℕ)\n  → l * (m + n) ≡ l * m + l * n\n\\end{code}\n\\end{exercise}\n\n\\begin{code}\n*-distributive zero m n =\n  begin\n    zero * (m + n)\n  ≡⟨⟩\n    zero\n  ≡⟨⟩\n    zero * zero\n  ≡⟨⟩\n    zero * m + zero * n\n  ∎\n*-distributive (suc l) m n =\n  begin\n    (suc l) * (m + n)\n  ≡⟨⟩\n    (m + n) + (l * (m + n))\n  ≡⟨ cong ((m + n) +_) (*-distributive l m n) ⟩\n    (m + n) + (l * m + l * n)\n  ≡⟨ +-associativ m n (l * m + l * n) ⟩\n    m + (n + (l * m + l * n))\n  ≡⟨ cong (m +_) (sym (+-associativ n (l * m) (l * n))) ⟩\n    m + ((n + l * m) + l * n)\n  ≡⟨ cong (m +_) (cong (_+ l * n) (+-commutative n (l * m))) ⟩\n    m + ((l * m + n) + l * n)\n  ≡⟨ cong (m +_) (+-associativ (l * m) n (l * n)) ⟩\n    m + (l * m + (n + l * n))\n  ≡⟨ sym (+-associativ  m (l * m) (n + l * n)) ⟩\n    (m + l * m) + (n + l * n)\n  ≡⟨⟩\n    suc l * m + suc l * n\n  ∎\n\\end{code}\n", "meta": {"hexsha": "dd4eb2b8b85b4b200cf6c6514b3b5e0594af5411", "size": 7729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hello-agda/src/Naturals.lagda.tex", "max_stars_repo_name": "neosimsim/merkdas", "max_stars_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-26T08:08:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-26T08:08:13.000Z", "max_issues_repo_path": "hello-agda/src/Naturals.lagda.tex", "max_issues_repo_name": "neosimsim/merkdas", "max_issues_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6", "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": "hello-agda/src/Naturals.lagda.tex", "max_forks_repo_name": "neosimsim/merkdas", "max_forks_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6", "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": 22.7323529412, "max_line_length": 91, "alphanum_fraction": 0.6209082676, "num_tokens": 2818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.803173791645582, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.6675523114685582}}
{"text": "\\documentclass[11pt]{amsbook}\n\n\\usepackage{../HBSuerDemir}\t% ------------------------\n\n\n\\begin{document}\n\n% ++++++++++++++++++++++++++++++++++++++\n\\hPage{b2p1/122}\n% ++++++++++++++++++++++++++++++++++++++\n\n\n\n% =======================================\n    \\[ \\left| C \\right| = \\sqrt[]{(\\frac{1}{9})^2 + (\\frac{4}{9})^2 + (\\frac{8}{9})^2 } = \\frac{1}{9} \\sqrt[]{1 + 16 + 64} = 1 \\]\n    \n    \n    \\\\ A vector having lenth equal to 1 is called a \\underline{unit vector}. In the above example, C is seen to be a unit vector.\n    \n    \n% =======================================\n\n\n    \\subsection*{\\underline{B. ALGEBRA OF VECTORS}}~\n    \n    \\\\1. \\underline{Addition}:\n    \\\\ The sum \\(\\vec{a} + \\vec{b}\\) of two vectors \\(\\vec{a}\\) and \\(\\vec{b}\\), in this order, is the vector whose initial point is that of the first and the extremity is that of the second when the latter is translated to have its initial point at the extremity of the first vector:\n    \\\\\\includegraphics[scale = 0.7]{images/b2p1-122_fig1} \\includegraphics[scale=0.7]{images/b2p1-122_fig2}\n    \n    \\\\ The following figures are the commutative law \n     \\[ \\vec{a} + \\vec{b} =  \\vec{b} + \\vec{a}\\]\n    \\\\ and the parallelogram law:\n    \\\\\\includegraphics[scale=0.7]{images/b2p1-122_fig3}\n    \\includegraphics[scale = 0.7]{images/b2p1-122_fig4}\n    \n    \\\\ The associative law\n     \\[ (\\vec{a} + \\vec{b}) + \\vec{c} =  \\vec{a} + (\\vec{b} + \\vec{c})\\]\n     \\\\ is the result congruency of the following pyramids:\n      \\\\\\includegraphics[scale=0.7]{images/b2p1-122_fig5}\n      \\includegraphics[scale = 0.7]{images/b2p1-122_fig6}\n      \n      \\\\ Because of this law the sum \\( \\vec{a} + \\vec{b} + \\vec{c} \\) has a meaning as defined by \\( (\\vec{a} + \\vec{b}) + \\vec{c} \\) or by \\( \\vec{a} + (\\vec{b} + \\vec{c}) \\)\n    \n    \n   \n% =======================================\n  \n\n% =======================================================\n\\end{document}  \n\n%==== templates ====\n\n%==== environments ====\n\n%\\begin{figure}[htb]\n%\t\\centering\n%\t\\includegraphics[width=0.9\\textwidth]{images/SD-1-1p15A}\n%\t\\caption{Classification of complex numbers}\n%\t\\label{fig:classificationOfComplexNumbersA}\n%\\end{figure}\n\n%\\begin{center}\n%\\begin{tabular}{cc}\n%\\end{tabular}\n%\\end{center}\n\n%\\begin{exmp}\n%\\begin{hSolution}\n%\\end{hSolution}\n%\\end{exmp}\n\n%\\begin{hEnumerateAlpha}\n%\\end{hEnumerateAlpha}\n\n%\\begin{hEnumerateRoman}\n%\\end{hEnumerateRoman}\n\n%$\n%\\begin{bmatrix}\n%\\end{bmatrix}\n%$\n\n%\\frac{aaaa}{bbb}\n%\\frac{a_{n}}{b_{n}}\n%\\left( aaaa \\right)\n%\\Longrightarrow\n\n%\\begin{multicols}{2}\n%\tbb\n%\\columnbreak\n%\taa\n%\\end{multicols}\n", "meta": {"hexsha": "3498890d2695156b2665c64493108ac3b4002bb0", "size": 2566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw2/non-merged/SERDAR ADA_38169_assignsubmission_file_/pages/b2p1-122.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/SERDAR ADA_38169_assignsubmission_file_/pages/b2p1-122.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/SERDAR ADA_38169_assignsubmission_file_/pages/b2p1-122.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.2978723404, "max_line_length": 284, "alphanum_fraction": 0.5502727981, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.6674896577511494}}
{"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*{Jensen's inequality}\nGiven positive real numbers $\\lambda_1,\\hdots,\\lambda_n$ for which $\\lambda_1+\\hdots+\\lambda_n=1$  and a convex function $f(x)$ the following holds:\n$$f(\\lambda_1 x_1 + \\hdots + \\lambda_n x_n) \\leq \\lambda_1 f(x_1) + \\hdots + \\lambda_n f(x_n)$$\nSimilarly, when $f(x)$ is a concave function, then \n$$f(\\lambda_1 x_1 + \\hdots + \\lambda_n x_n) \\geq \\lambda_1 f(x_1) + \\hdots + \\lambda_n f(x_n)$$\n\n\\subsection*{Problems}\n\\begin{enumerate}\n\t\\item\n\tProve Jensen's inequality. When does the equality hold?\n\t\n\t\\item \n\tProve the power mean inequality using Jensen's inequality.\n\t\n\t\\item % Vorratused 96\n\tProve for positive real numbers $a,b,c$\n\t$$\\frac{9}{2(a+b+c)} \\leq \\frac{1}{a+b} + \\frac{1}{b+c} + \\frac{1}{c+a} \\leq \\frac{1}{2} \\left( \\frac{1}{a} + \\frac{1}{b} + \\frac{1}{c} \\right) $$\n\t\n\t\\item % vorrat 118\n\t$\\alpha,\\beta,\\gamma$ are angles of an acute triangle. Prove that\n\t$$\\cos \\alpha + \\cos \\beta + \\cos \\gamma \\leq \\frac{3}{2}$$\n\t\n\t\\item % vorrat p68\n\t$a_1,\\hdots,a_n$ are positive real numbers and $b_1, \\hdots, b_n$ their permutation. Prove that\n\t$$\\left( a_1 + \\frac{1}{b_1} \\right) \n\t\\left( a_2 + \\frac{1}{b_2} \\right) \n\t\\hdots\n\t\\left( a_n + \\frac{1}{b_n} \\right) \n\t\\geq 2^n\n\t$$\n\tProve that for odd $n$, the equality holds if there exists $i$ for which $a_i=1$.\n\t\n\t\\item % BW2002-4\n\tLet $n$ be a positive  integer. Prove that\n\t\\[\n\t\\sum_{i=1}^{n}x_i(1-x_i)^2 \\leq \\left(1-\\frac{1}{n}\\right)^2\n\t\\]\n\tfor all nonnegative real numbers $x_1,x_2,\\ldots,x_n$ such that $x_1+x_2+\\cdots+x_n=1$.\n\t\n\t\\item % http://www.math.olympiaadid.ut.ee/eng/archive/prob1213.pdf S-6\n\tA class consists of 7 boys and 13 girls. During the first three months of the school year, each boy has communicated with each girl at least once. Prove that there exist two boys and two girls such that both boys communicated with both girls first time in the same month.\n\t\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "94fbee119bc31ec29fb472159a8af54c8fbf937f", "size": 2174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "09_jensen.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": "09_jensen.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": "09_jensen.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.4827586207, "max_line_length": 272, "alphanum_fraction": 0.6895124195, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6674630704491383}}
{"text": "\\subsection*{Q. 5}\n\\paragraph{(a)}$F(A, B, C, D)=\\Sigma(1, 3, 5, 8, 10, 14)$\n\\par D1, D3, D5, D8, D10, D14 should be connected to \\emph{signal 1}, while the left ports (D0, D2, D4, D6, D7, D9, D11, D12, D13, D15) should be connected to \\emph{signal 0}.\n\\paragraph{(b)}$F(A, B, C, D)=\\Pi(4, 7, 11)=\\Sigma(0, 1, 2, 3, 5, 6, 8, 9, 10, 12, 13, 14, 15)$\n\\par D4, D7, D11 should be connected to \\emph{signal 0}, while the left ports (D0, D1, D2, D3, D5, D6, D8, D9, D10, D12, D13, D14, D15) should be connected to \\emph{signal 1}.", "meta": {"hexsha": "60cc001452f62e2b070e5012f96e54a3e9f4dd5b", "size": 524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2021F/CS207/A3/q5.tex", "max_stars_repo_name": "HeZean/SUSTech-Archive", "max_stars_repo_head_hexsha": "0c89d78f232fdef427ca17b7e508881b782d7826", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2021F/CS207/A3/q5.tex", "max_issues_repo_name": "HeZean/SUSTech-Archive", "max_issues_repo_head_hexsha": "0c89d78f232fdef427ca17b7e508881b782d7826", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2021F/CS207/A3/q5.tex", "max_forks_repo_name": "HeZean/SUSTech-Archive", "max_forks_repo_head_hexsha": "0c89d78f232fdef427ca17b7e508881b782d7826", "max_forks_repo_licenses": ["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.8, "max_line_length": 175, "alphanum_fraction": 0.6106870229, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970717197771, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6674630535485485}}
{"text": "%!TEX root = TDT4265-Summary.tex\r\n\\section{Image segmentation}\\label{sec:segmentation}\r\nSegmentation divides an image into the regions or objects it consists of. Most algorithms here are based on intensity discontinuity and similarity.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Fundamentals}\\label{ssec:segmentation-fundamentals}\r\nWe pretty much just divide an image $R$ into $n$ regions $R_1 \\dots R_n$, and require the following to hold:\r\n\\begin{itemize}\r\n    \\item The union of all regions is equal to the whole image.\r\n    \\item Each region is a connected set.\r\n    \\item Each region is disjoint from the others.\r\n    \\item Some predicate\\footnote{A predicate can be e.g. the that the intensity of each pixel is in a certain range.} is true for each region separately.\r\n    \\item The predicate is false for the union of any adjacent regions.\r\n\\end{itemize}\r\n\r\nSegmentation is either edge-based or region-based.\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Point, line, and edge detection}\\label{ssec:edge-detection}\r\nThese methods detect sharp, local changes in intensity. First- and second-order derivatives are used, and can detect intensity ramps, isolated points, and steps. Simple spatial filters can realize 1st and 2nd derivatives.\r\n\r\n\\subsubsection{Point detection}\r\nPoints can be detected by a 2nd derivative mask and thresholding. (If the absolute value of the output of a 2nd derivative mask is above a threshold, that pixel is marked as a point.) A suitable mask for this is\r\n\\begin{equation}\\label{eq:2nd-derivative-mask}\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        1 &  1 & 1 \\\\\r\n        1 & -8 & 1 \\\\\r\n        1 &  1 & 1\r\n    \\end{BMAT}.\r\n\\end{equation}\r\n\r\n\\subsubsection{Line detection}\r\nThe same mask \\eqref{eq:2nd-derivative-mask} can be used. However, this mask gives a double line effect---negative values on one side of the line and positive on the other. This can be avoided by only keeping the positive-valued pixels. Note that lines must be thin compared to the mask in order to be detected as lines. Fat lines should be treated as regions.\r\n\r\n\\eqref{eq:2nd-derivative-mask} is independent of line direction. Other masks can be used to detect lines in specified directions.\r\n\r\n\\subsubsection{Edge models}\r\nEdges can be steps (sudden change), ramps (gradual change), or roofs (gradual increase followed by gradual decrease).\r\n\r\nThe magnitude of the 1st derivative can indicate an edge, and the sign of the 2nd derivative reveals if you are on the bright or dark side of it. Because this is done with derivatives, noisy edges are problematic.\r\n\r\n\\subsubsection{Basic edge detection}\\label{sssec:edge-detection}\r\nThe image gradient is\r\n\\begin{equation}\r\n    \\nabla f = \\mathrm{grad}(f)\r\n    =\r\n    \\begin{bmatrix} g_x \\\\ g_y \\end{bmatrix}\r\n    =\r\n    \\begin{bmatrix} \\pd{f}{x} \\\\[6pt] \\pd{f}{y} \\end{bmatrix}.\r\n\\end{equation}\r\nThe magnitude is the value of the rate of change in the direction of the gradient (steepness of the ramp). The direction of $\\nabla f$ is\r\n\\begin{equation}\r\n    \\alpha(x,y) = \\arctan \\left( \\frac{g_y}{g_x} \\right).\r\n\\end{equation}\r\nThis is the direction of the steepest ascent, and is therefore orthogonal to the edge.\r\n\r\nA often used and pretty good gradient mask is the Sobel operator\r\n\\begin{equation}\\label{eq:sobel}\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        -1 & -2 & -1 \\\\\r\n         0 &  0 &  0 \\\\\r\n         1 &  2 & 1\r\n    \\end{BMAT}\r\n    \\text{ and }\r\n    \\begin{BMAT}(e){|c|c|c|}{|c|c|c|}\r\n        -1 & 0 & 1 \\\\\r\n        -2 & 0 & 2 \\\\\r\n        -1 & 0 & 1\r\n    \\end{BMAT}.\r\n\\end{equation}\r\nThese two masks can detect vertical and horizontal edges, respectively. The same operator but with ones instead of twos is called the Prewitt operator. However, the $\\pm 2$-elements give some smoothing, which is good as derivatives are sensitive to noise. Sobel and Prewitt masks can also be rotated $45 \\degree$ to detect diagonal edges.\r\n\r\nTo maintain connectivity of edges and highlight the strongest edges, you must smoothe the image first, then extract edges, then threshold it.\r\n\r\n\\subsubsection{More advanced edge detection}\\label{sssec:adv-edge-detection}\r\nThese methods worry more about noise and the nature of edges.\r\n\r\n\\paragraph{The Marr-Hildreth edge detector (Laplacian of Gaussian)} This method uses masks of variant scales to detect edges of variant sharpness. The filter is the Laplacian of the Gaussian (LoG):\r\n\\begin{equation}\r\n    \\nabla^2 G(x,y)\r\n    =\r\n    \\left[\r\n        \\frac{x^2 + y^2 - 2 \\sigma^2}{\\sigma^4}\r\n    \\right]\r\n    \\euler^{-\\frac{x^2 + y^2}{2 \\sigma^2}}\r\n\\end{equation}\r\nThis formula can be used to create LoG masks of any size. The Gaussian part $G$ blurs the image without ringing. The Laplacian part $\\nabla^2$ is used to detect edges because it is isotropic\\footnote{Invariant to rotation.}, as opposed to the 1st derivative. In reality, Marr-Hildreth edge detection is done by\r\n\\begin{enumerate}\r\n    \\item Filter image with a Gaussian lowpass filter.\r\n    \\item Compute the Laplacian of the image.\r\n    \\item Find the zero-crossings.\r\n\\end{enumerate}\r\n\r\nNote that it is usually better to use a small positive threshold for zero-crossing. This removes a lot of ``noisy'' edges. Also note that the LoG can be approximated with a difference of Gaussian (DoG) operator.\r\n\r\n\\paragraph{The Canny edge detector} The Canny edge detector is an attempt to\r\n\\begin{enumerate}\r\n    \\item find all edges without false positives,\r\n    \\item locate edge points near the true edge, and\r\n    \\item return edges only one pixel wide.\r\n\\end{enumerate}\r\nThis is fairly well achieved by the following:\r\n\\begin{enumerate}\r\n    \\item Smooth the image with a Gaussian filter.\r\n    \\item Compute gradient magnitude and gradient angle images (using e.g. Sobel).\r\n    \\item Apply nonmaxima suppression to the gradient magnitude image.\r\n    \\item Detect and link edges with double thresholding and connectivity analysis.\r\n    \\item (Optional.) Use edge thinning to make sure all edges are one pixel wide.\r\n\\end{enumerate}\r\n\r\nCanny is generally better than Marr-Hildreth/LoG, but more complex and computationally heavy.\r\n\r\n\\paragraph{Edge linking and boundary detection} Done with local processing, regional processing, or global processing with the Hough transform.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Corner detection}\r\nThe dominant method for corner detection is the Harris corner detector.\r\n\r\n\\subsubsection{Harris corner detector}\r\nDefine a box of some size to move around the image and look for corners inside of. For each location, calculate gradients in $x$ and $y$ directions. In a flat area, the gradients will all be close to zero. Edges and corners give different non-zero responses. This can be quantified by\r\n\\begin{equation}\r\n    M = \\sum_{(x,y) \\in W}\r\n    \\begin{bmatrix}\r\n        I_x^2   & I_x I_y \\\\\r\n        I_x I_y & I_y^2\r\n    \\end{bmatrix}\r\n\\end{equation}\r\nwhere $I_x$ and $I_y$ are gradients in the $x$ and $y$ directions. $W$ is the window we are looking for corners in. We can then use the Harris corner response function\r\n\\begin{equation}\r\n    R = \\det(M) - \\alpha \\trace(M)^2 = \\lambda_1 \\lambda_2 - \\alpha (\\lambda_1 + \\lambda_2)^2\r\n\\end{equation}\r\nto assume features:\r\n\\begin{center}\r\n\\begin{tabular}{lll}\r\n    Response function & Eigenvalues & Feature found \\\\\r\n    \\hline\r\n    $R > 0$           & Both large  & Corner        \\\\\r\n    $R < 0$           & One large   & Edge          \\\\\r\n    $\\abs{R}$ small   & Both small  & Flat area\r\n\\end{tabular}\r\n\\end{center}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Thresholding}\r\nThresholding is an attempt to separate the image into object points and background points. It can be done globally (same threshold value everywhere) or variably (different value in different areas). Sometimes multiple thresholding is done, to separate the image into more than two parts.\r\n\r\nThresholding is made harder by noise, and uneven illumination/reflectance. Remedies are direct correction of shading pattern, top-hat transformation (Paragraph \\ref{par:top-hat}), and variable thresholding.\r\n\r\n\\subsubsection{Basic global thresholding}\r\nEasy, but we need a way to select the threshold automatically:\r\n\\begin{enumerate}\r\n    \\item Select initial threshold $T$.\r\n    \\item Segment image with $T$.\r\n    \\item Compute mean intensities $m_1$ and $m_2$ of the two groups.\r\n    \\item Compute new threshold $T = \\frac{1}{2}(m_1 + m_2)$.\r\n    \\item Repeat until convergence.\r\n\\end{enumerate}\r\nThis works well when there is a clear valley in the histogram.\r\n\r\n\\subsubsection{Otsu's method}\r\nOtsu's method is based on maximizing between-class variance:\r\n\\begin{enumerate}\r\n    \\item Compute normalized histogram $p_0 \\dots p_{L-1}$.\r\n    \\item Compute cumulative sums $P_1(0) \\dots P_1(L-1)$.\r\n    \\item Compute cumulative means $m(0) \\dots m(L-1)$.\r\n    \\item Compute global intensity mean $m_G$.\r\n    \\item Compute between-class variance $\\sigma_B^2(0) \\dots \\sigma_B^2(L-1)$.\r\n    \\item Obtain Otsu threshold $k^* = \\argmax_k \\sigma_B^2(k)$.\r\n    \\item Obtain separability measure $\\eta^*$.\r\n\\end{enumerate}\r\n\r\n\\subsubsection{Improving global thresholding with smoothing}\r\nEven with Otsu's, noise can make thresholding fail completely. Smoothing the image first can often make it succeed again, although heavy smoothing can distort the edges.\r\n\r\n\\subsubsection{Improving global thresholding with edges}\r\nIn some cases, such as with noisy images where the object is very small compared to the background, edge detection-based thresholding is useful.\r\n\\begin{enumerate}\r\n    \\item Compute an edge image with some method from Section \\ref{ssec:edge-detection}.\r\n    \\item Set a threshold $T$.\r\n    \\item Threshold the edge image.\r\n    \\item Compute a histogram of only the pixels in the original that are 1-valued in the edge image.\r\n    \\item Segment this histogram globally, with e.g. Otsu.\r\n\\end{enumerate}\r\n\r\n\\subsubsection{Multiple thresholds}\r\nSometimes you want to segment an image into three groups of intensity values, which is done with two thresholds. (More than two thresholds usually consider other properties than intensity.) A modification of Otsu exists for dual thresholds.\r\n\r\n\\subsubsection{Variable thresholding}\r\n\r\n\\paragraph{Image partitioning} Partition the image into smaller images, and threshold each part separately. Sufficiently small parts should make, say, uneven illumination appear fairly even within the part.\r\n\r\n\\paragraph{Thresholding based on local properties} Threshold based on a predicate of the neighborhood. If a function $Q$ of pixels near the current is true, mark that pixel a 1.\r\n\r\n\\paragraph{Moving average} Good for stuff such as images of text with uneven illumination. As long as the text stands out from the local background, it's marked a 1. Global thresholding will fail in such situations.\r\n\r\n\\subsubsection{Multivariable thresholding}\r\nWith color images, we might want to do thresholding based on more variables than greyscale intensity. An example is the ``distance'' from a pixel in the image to a given color, such as only keeping pixels that are sufficiently red.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Region-based segmentation}\r\nInstead of finding edges or doing thresholding, let's just find the regions directly.\r\n\r\n\\subsubsection{Region growing}\r\nStart with a ``seed'' of points, and grow these into regions:\r\n\\begin{enumerate}\r\n    \\item Erode connected components of the seeds to single pixels.\r\n    \\item Compute a predicate image with ones for all pixels that satisfy the predicate.\r\n    \\item Append to the seed points all ones from the predicate image that are 8-connected to the seed.\r\n    \\item Label each disjoint region.\r\n\\end{enumerate}\r\n\r\n\\subsubsection{Region splitting and merging}\r\nBased on splitting the image into sections and merging them to satisfy the list in Section \\ref{ssec:segmentation-fundamentals}. One method is to divide the image into quadrants, and for each quadrant that fails a predicate, divide it further. Afterwards, adjacent regions that fulfill the predicate are merged.\r\n\r\n\\subsubsection{$k$-means clustering}\r\n$k$-means clustering is a method that can be used to segment an image into $k$ categories based on some vector of quantitative features (such as color levels). The algorithm is\r\n\\begin{enumerate}\r\n    \\item In the space of all possible feature vectors, initialize the centers of $k$ categories randomly.\r\n    \\item Assign each pixel to the nearest category.\r\n    \\item Based on the pixels assigned to each category, compute the centroid of their feature vectors as the new category centroids.\r\n    \\item Repeat until convergence.\r\n\\end{enumerate}\r\nThis method\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Morphological watersheds}\r\nWe look at the image in a topographic way, letting intensity levels represent heights. Then ``fill'' the image by rising water from below. Notice which areas fill separately, and where the water connects when the level is high enough.\r\n\r\nAs the water fills, build pixel-wide dams to keep the basins from connecting. These dams define the segmentation boundaries between regions. Noise and irregularities lead to oversegmentation. You can preprocess to generate markers, which are the only allowable starting points for the water filling, in order to reduce this.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Using motion for segmentation}\r\nIt can be useful to detect regions by looking at movement.\r\n\r\n\\subsubsection{Spatial techniques}\r\nA very simple method is to look at pixel-level differences: Make a difference image of ones for all pixels that have changed significantly. To suppress noise, you can form 4- or 8-connected regions in the difference image and ignore too small regions.\r\n\r\nAnother method is accumulative differences: Increment a counter for a given pixel when a significant change occurs there.\r\n\r\nFor these methods to work, we need a good reference image. The best is one with only stationary elements. If you cannot capture a stationary image directly, it can be constructed from several images.\r\n", "meta": {"hexsha": "49d3a1df78f1d234799169b9868303f2b9b2b1c4", "size": 14227, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TDT4265 Computer vision/10-image-segmentation.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/10-image-segmentation.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/10-image-segmentation.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": 59.2791666667, "max_line_length": 361, "alphanum_fraction": 0.7172278063, "num_tokens": 3397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6674532887833668}}
{"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 3 - Riemann--Hurwitz}\n  \\date{}\n  \\maketitle\n\n\nFor today, let $X$ and $Y$ be compact connected Riemann surfaces with atlases $(U_i, \\varphi_i)$ and $(V_j,\\psi_j)$, respectively, and let $f: X \\rightarrow Y$ be a non-constant complex differentiable function between them.\n\n\n\n\n\n\n\n\n\\section{Ramified coverings of Riemann surfaces}\n\\begin{definition}\n  Pick a chart $\\varphi_i$ around a point $z \\in X$ and a chart $\\psi_j$ around $f(z) \\in Y$.\n  Define\n  \\begin{align*}\n    \\mathrm{index}_f (z) := \\mathrm{index}_{\\psi_j \\circ f \\circ \\varphi_i^{-1}}( \\varphi(z))\n  \\end{align*}\n\\end{definition}\n\n\\begin{qbox}\n  Let $g(z)$ be a non-constant holomorphic function on $U \\subseteq \\bbc$ with Taylor expansion\n  \\begin{align*}\n    g(z) - g(z_0) = a_k (z - z_0)^k + a_{k+1} (z-z_0)^{k+1} + \\dots\n  \\end{align*}\n  Let $\\psi$ be a biholomorphic function with Taylor expansion\n  \\begin{align*}\n    \\psi(w) - \\psi(w_0) = a_1 (z - w_0) + a_2 (z - w_0)^2 + \\dots\n  \\end{align*}\n  where $w_0 = g(z_0)$.\n  Find the first term in the Taylor expansions of $\\psi \\circ g $ at $z_0$ and argue that $f$ and $\\psi \\circ f $  have the same index at $z_0$.\n  Similar statement is true if we pre-compose instead of post-compose with a biholomorphic function.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that $\\mathrm{index}_f (z)$ does not depend on the choice of charts, and hence is well defined.\n\\end{qbox}\n\n\\begin{qbox}\n  Using the fact that $X$ and $Y$ are compact, show that the ramification and branch loci of $f$ are finite.\\hint{Use the fact that ramification and branch locus are isolated.}\n\\end{qbox}\n\n\\begin{definition}\n  For a point $ w \\in Y$, define\n  \\begin{align*}\n    \\mathrm{deg}_f(w) = \\sum_{z \\in f^{-1}(w)} \\mathrm{index}_f (z)\n  \\end{align*}\n  This definition makes sense as the right-hand side is finite.\n\\end{definition}\n\nLet $w_0$ be a point in $Y$.\nSuppose $f^{-1}(w_0) = \\set{z_1, \\dots, z_k}$ with ramification indices $\\set{e_1, \\dots, e_k}$. We can choose sufficiently small neighborhoods $W_i \\subseteq X$ around each $z_i$ such that\n\\begin{enumerate}\n  \\item $f:W_i \\rightarrow f(W_i) \\subseteq Y$ is a ramified covering of degree $e_i$ (so that  $f(z) \\approx z^{e_i}$)\n  \\item $f(W_i) = f(W_j)$ for all $1 \\le i,j \\le k$.\n\\end{enumerate}\nLet $W = f(W_i)$.\n\n\\begin{qbox}\n  Show that \\begin{align*}\n    \\mathrm{deg}_f: W &\\longrightarrow \\bbz \\\\\n    w &\\longmapsto \\mathrm{deg}_f w\n  \\end{align*} is a constant function.\n\\end{qbox}\n\nThus, for each point $w \\in Y$, we can find an open neighborhood $W$ on which $\\mathrm{deg}_f$ is a constant function. Because $Y$ is connected this gives us,\n\n\\begin{theorem}\n  $\\mathrm{deg}_f$ is constant function on $Y$.\n\\end{theorem}\nThis constant is called the \\emph{degree/order} of the ramified covering.\n\n\\begin{qbox}\n  Find the degree of a non-constant rational function\n  \\begin{align*}\n    f: \\bbp^1 &\\longrightarrow \\bbp^1 \\\\\n    z &\\longmapsto \\dfrac{p(z)}{q(z)}\n  \\end{align*}\n\\end{qbox}\n\n\\begin{qbox}\n  Show that every non-constant meromorphic function $f:X \\rightarrow \\bbp^1$ has the same number of zeroes and poles, counting multiplicities.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\\section{Riemann–Hurwitz formula}\n\n\\emph{General philosophy:}\\footnote{Not to be taken seriously.} Algebra and analysis are used for constructing maps and algebraic topology is used for proving non-existence, by providing obstructions to existence of maps.\n\n\n\\begin{theorem}[Riemann--Hurwitz]\n  \\label{thm:RiemannHurwitz}\n  Let $X$ and $Y$ be compact Riemann surfaces and let $f:X \\rightarrow Y$ be a non-constant complex differentiable map which is a ramified covering of order $N$ with ramification points $z_1, \\dots, z_k$. Then,\n  \\begin{align*}\n    \\chi (X)=N\\cdot \\chi (Y)-\\sum_{i = 1}^k\\left(\\mathrm{index}_f(z_i) - 1\\right)\n  \\end{align*}\n  where $\\chi$ is the Euler characteristic.\n\\end{theorem}\n\n  \\begin{lemma}\n      If we have a covering map $f:X \\rightarrow Y$ of degree $N$ of compact topological surfaces then $\\chi(X) = N \\cdot \\chi(Y)$.\n  \\end{lemma}\n\n  \\begin{proof}\n    Put a triangulation on $Y$ which is fine enough that its lift is a triangulation on $X$.\n    If the original triangulation had $V, E, F$ vertices, edges, and faces, respectively, then the lifted triangulation will have $N V, NE, NF$ vertices, edges, and faces, respectively.\n    The result follows.\n  \\end{proof}\n\n  \\begin{proof}[Proof of Theorem \\ref{thm:RiemannHurwitz}]\n    Put a triangulation on $Y$ which is fine enough that its lift is a triangulation on $X$.\n    Assume further that all the branch and ramification points are vertices in this triangulation.\n\n    Suppose the triangulation on $X$ has $V, E, F$ vertices, edges, and faces, respectively.\n    If there were no ramification points the triangulation on $Y$ would have $NV, NE, NF$ vertices, edges, and faces, respectively.\n\n    But now consider a ramified point $z \\in X$ with ramification degree $e$ and let $w = f(z) \\in Y$ be the corresponding branch point. Suppose there are $k$ triangles with vertex $w$.\n    \\begin{qbox}\n      Show that the triangles around $w$ have a total of $1 + k$ vertices, $2k$ edges, and $k$ faces.\n    \\end{qbox}\n    \\begin{qbox}\n      Show that in the lifted triangulation, the triangles around $z$ have a total of $1 + k \\cdot e$ vertices, $ 2k \\cdot e$ edges, and $k \\cdot e$ faces.\n    \\end{qbox}\n\n    If there was no ramification at $z$ then $f$ should have been an $e:1$ mapping and hence we should have had $(1 + k)\\cdot e$ vertices, $2k\\cdot e$ edges, and $k\\cdot e$ faces.\n    Hence, a ramification of index $e$ at $z$ results in a drop in the Euler characteristic by\n    \\begin{align*}\n      ((1 + k)\\cdot e - 2k\\cdot e + k\\cdot e) - ((1 + k \\cdot e) - 2k \\cdot e + k\\cdot e) = e - 1\n    \\end{align*}\n\n    The result follows.\n  \\end{proof}\n\n\\begin{qbox}\n  Explicitly lift the following triangulation for the function $f:\\bbp^1 \\rightarrow \\bbp^1$, $f(z) = z^2$ and verify the proof of the Riemann--Hurwitz formula.\n  \\begin{figure}[H]\n  \\centering\n    \\includegraphics[width=0.25\\textwidth]{images/octahedron.jpg}\n    \\caption{Triangulation of $\\bbp^1$: the north pole is $\\infty$, the south pole is $0$, ``the square equator\" is the unit circle in $\\bbc$.}\n  \\end{figure}\n\n\\end{qbox}\n\nUsing $\\chi(X) = 2 - 2g(X)$, we can rewrite Theorem \\ref{thm:RiemannHurwitz} as\n  \\begin{align*}\n    g(X) - 1 = N \\cdot (g(Y) - 1) + \\sum_{i = 1}^k \\left(\\mathrm{index}_f(z_i) - 1\\right) \\cdot 1/2\n  \\end{align*}\n  where $g$ is the genus.\n\n\n\n\n  \\begin{corollary}\n    For a compact Riemann surface $Y$, there are no non-constant differentiable functions $f: \\bbp^1 \\rightarrow Y$ if $Y \\not \\cong \\bbp^1$.\n  \\end{corollary}\n\n\n\n\n\\begin{corollary}\n  If $X$ and $Y$ are complex tori (genus=1) then any non-constant complex differentiable map $f:X \\rightarrow Y$ has no ramification points, i.e. the only maps between complex tori are (genuine) covering maps.\n\\end{corollary}\n\n\\begin{corollary}\n  If $X$ and $Y$ are compact Riemann surfaces and there is a non-constant complex differentiable map $f:X \\rightarrow Y$ which is not an isomorphism, then $g(X) \\ge g(Y)$.\n\\end{corollary}\n\n\\begin{qbox}\n  Prove the above corollaries using Theorem \\ref{thm:RiemannHurwitz}.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\\section{Elliptic curves}\n  \\emph{Analogy:} We can construct 1-dimensional real manifolds by looking at solutions to equations $f(x,y) = 0$ inside $\\bbr^2$.\n\n  We can do a similar thing for complex manifolds.\n  Consider\n  \\begin{align*}\n    S_p = \\set{(z,w) : p(z,w) = 0} \\subseteq \\bbc^2\n  \\end{align*}\n\n  Under certain restrictions on $p$, this defines a Riemann surface. In particular, this is true when $p(z,w) = z^2 - q(w)$ where $q(w)$ is a degree three polynomial with distinct roots. Further, it is possible to compactify this object by adding a single point at $\\infty$ and the resulting object is called an \\emph{elliptic curve}.\n  \\begin{align*}\n    \\cale ll_q = \\set{(z,w) : z^2 = q(w) } \\cup \\set{\\infty}\n  \\end{align*}\n\n  There is a natural map\n  \\begin{align*}\n    \\cale ll_q &\\longrightarrow \\bbp^1 \\\\\n    (z,w) &\\longmapsto w \\\\\n    \\infty &\\longmapsto \\infty\n  \\end{align*}\n  Turns out this is a complex differentiable map of degree 2 which has exactly 4 distinct ramification points, the three roots of $q$ and the point at infinity.\n  Plugging in the Riemann--Hurwitz formula we get\n  \\begin{align*}\n    \\chi(\\cale ll_q)\n    &= 2 \\chi(\\bbp^1) \\: + \\sum_{\\mbox{ 4 points}} (2 - 1) \\\\\n    &= 4 - 4 \\\\\n    &= 0\n  \\end{align*}\n  Hence, $\\cale ll_q$ is homeomorphic to a torus.\n\n  \\begin{mdframed}\n    Almost nothing in this section generalizes arbitrarily.\n    Not all compact Riemann surfaces can be embedded in $\\bbp^2$, not all non-compact Riemann surfaces can be compactified by adding a single point at infinity.\\\\\n\n    But things DO generalize with some effort. All compact Riemann surfaces can be embedded in $\\bbp^3$, many non-compact Riemann surfaces of interest can be compactified by adding multiple points at infinity.\n    It is a very non-trivial theorem in complex analysis that every Riemann surface admits a non-constant meromorphic function.\\\\\n\n    It is a remarkable accident that things work out to be so nice for elliptic curves.\\\\\n\n    We will make all of this rigorous (as much as possible) in the next two classes.\n  \\end{mdframed}\n\\end{document}\n", "meta": {"hexsha": "ab7b973b70d52ca35a9bf87abc21c9937ecd79f4", "size": 9417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PSet03.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": "PSet03.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": "PSet03.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": 38.9132231405, "max_line_length": 334, "alphanum_fraction": 0.6888605713, "num_tokens": 3023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8774767906859265, "lm_q1q2_score": 0.6674532840223114}}
{"text": "\n\\section{Syntax}\n\n%The symbol {\\tt\\char32} indicates a mandatory space.\n\n\\begin{center}\n\\begin{tabular}{clll}\n{\\it Math} & & {\\it Eigenmath} & {\\it Alternate form and/or comment} \\\\\n\\\\\n$-a$ & & {\\tt -a} \\\\\n\\\\\n$a+b$ & & {\\tt a+b} \\\\\n\\\\\n$a-b$ & & {\\tt a-b} \\\\\n\\\\\n$ab$ & & {\\tt a*b} & \\verb$a b$ \\hspace{10pt}\n{\\it with a space in between} \\\\\n\\\\\n$\\displaystyle{a\\over b}$ & & {\\tt a/b} \\\\\n\\\\\n$\\displaystyle{a\\over bc}$ & & {\\tt a/b/c} \\\\\n\\\\\n$a^2$ & & {\\tt a{\\char94}2} \\\\\n\\\\\n$\\sqrt{a}$ & & {\\tt a{\\char94}(1/2)} & {\\tt sqrt(a)} \\\\\n\\\\\n$\\displaystyle{1\\over\\sqrt a}$ & & {\\tt a{\\char94}(-1/2)} & {\\tt 1/sqrt(a)} \\\\\n\\\\\n$a(b+c)$ & & {\\tt a*(b+c)} & \\verb$a (b+c)$\n\\hspace{10pt} {\\it with a space in between} \\\\\n\\\\\n$f(a)$ & & {\\tt f(a)} \\\\\n\\\\\n$\n\\begin{pmatrix}a\\\\ b\\\\ c\\end{pmatrix}\n$\n& & {\\tt (a,b,c)}\n\\\\\n\\\\\n$\\begin{pmatrix}a&b\\\\ c&d\\end{pmatrix}$ & & {\\tt ((a,b),(c,d))} \\\\\n\\\\\n$T^{12}$ & & {\\tt T[1,2]} & {\\it tensor component access} \\\\\n\\\\\n$2\\,\\rm km$ & & {\\tt 2*\"km\"} & {\\it units of measure are quoted} \\\\\n\\end{tabular}\n\\end{center}\n", "meta": {"hexsha": "f4f4f374b97ddf5645e435706d095e5e151fbd49", "size": 1031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/syntax.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/syntax.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/syntax.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.9361702128, "max_line_length": 78, "alphanum_fraction": 0.4898157129, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6673745025079596}}
{"text": "\\chapter{Limits in categories (TO DO)}\nWe saw near the start of our category theory chapter\nthe nice construction of products by drawing\na bunch of arrows.\nIt turns out that this concept can be generalized immensely,\nand I want to give a you taste of that here.\n\nTo run this chapter, we follow the approach of \\cite{ref:msci}.\n\\todo{write introduction}\n\n\\section{Equalizers}\n\\prototype{The equalizer of $f,g : X \\to Y$ is the set of points with $f(x) = g(x)$.}\nGiven two sets $X$ and $Y$, and maps $X \\taking{f,g} Y$, we define their \\vocab{equalizer} to be\n\\[ \\left\\{ x \\in X \\mid f(x) = g(x) \\right\\}. \\]\nWe would like a categorical way of defining this, too.\n\nConsider two objects $X$ and $Y$ with two maps $f$ and $g$ between them.\nStealing a page from \\cite{ref:msci}, we call this a \\vocab{fork}:\n\\begin{diagram}\n\tX & \\pile{\\rTo^f \\\\ \\rTo_g} & Y\n\\end{diagram}\nA cone over this fork is an object $A$ and arrows over $X$ and $Y$ which make the diagram commute, like so.\n\\begin{diagram}\n\tA && \\\\\n\t\\dTo^q & \\rdDashed^{f \\circ q = g \\circ q} & \\\\\n\tX & \\pile{\\rTo^f \\\\ \\rTo_g} & Y\n\\end{diagram}\nEffectively, the arrow over $Y$ is just forcing $f \\circ q = g \\circ q$.\nIn any case, the \\vocab{equalizer} of $f$ and $g$ is a ``universal cone'' over this fork:\nit is an object $E$ and a map $E \\taking{e} X$ such that\nfor each $A \\taking q X$ the diagram\n\\begin{diagram}\n\t& A & \\\\\n\t\\ldTo(1,3)^q & \\dTo~{!\\exists h} & \\rdDashed(1,3) \\\\\n\t& E & \\\\\n\tX \\ldTo(1,1)^e & \\pile{\\rTo^f \\\\ \\rTo_g} & \\rdDashed(1,1) Y \\\\\n\\end{diagram}\ncommutes for a unique $A \\taking h E$.\nIn other words, any map $A \\taking{q} X$ as above\nmust factor uniquely through $E$.\nAgain, the dotted arrows can be omitted,\nand as before equalizers may not exist.\nBut when they do exist:\n\\begin{exercise}\n\tIf $E \\taking{e} X$ and $E' \\taking{e'} X$ are equalizers,\n\tshow that $E \\cong E'$.\n\\end{exercise}\n\n\\begin{example}\n\t[Examples of equalizers]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii In $\\catname{Set}$, given $X \\taking{f,g} Y$\n\t\tthe equalizer $E$ can be realized as $E = \\{x \\mid f(x) = g(x)\\}$,\n\t\twith the inclusion $e : E \\injto X$ as the morphism.\n\t\tAs usual, by abuse we'll often just refer to $E$ as the equalizer.\n\n\t\t\\ii Ditto in $\\catname{Top}$, $\\catname{Grp}$.\n\t\tOne has to check that the appropriate structures are preserved\n\t\t(e.g.\\ one should check that $\\{\\phi(g) = \\psi(g) \\mid g \\in G\\}$ is a group).\n\n\t\t\\ii In particular, given a homomorphism $\\phi : G \\to H$, the inclusion\n\t\t$ \\ker\\phi \\injto G $\n\t\tis an equalizer for the fork $G \\to H$ by $\\phi$ and the trivial homomorphism.\n\t\\end{enumerate}\n\\end{example}\n\nAccording to (c) equalizers let us get at the concept of a kernel\nif there is a distinguished\n``trivial map'', like the trivial homomorphism in $\\catname{Grp}$.\nWe'll flesh this idea out in the chapter on abelian categories.\n\n\\section{Pullback squares (TO DO)}\n\\todo{write me}\nGreat example: differentiable functions on $(-3,1)$ and $(-1,3)$\n\n\\begin{example}\n\t\\label{ex:diff_pullback}\n\\end{example}\n\n\\section{Limits}\nWe've defined cones over discrete sets of $X_i$ and over forks.\nIt turns out you can also define a cone over any general \\vocab{diagram} of objects and arrows;\nwe specify a projection from $A$ to each object and\nrequire that the projections from $A$ commute with the arrows in the diagram.\n(For example, a cone over a fork is a diagram with two edges and two arrows.)\nIf you then demand the cone be universal,\nyou have the extremely general definition of a \\vocab{limit}.\nAs always, these are unique up to unique isomorphism.\nWe can also define the dual notion of a \\vocab{colimit} in the same way.\n\n\n\\section{\\problemhead}\n\\begin{sproblem}[Equalizers are monic]\n\tShow that the equalizer of any fork is monic.\n\t\\label{prob:equalizer_monic}\n\\end{sproblem}\n\npushout square gives tenor product\n\np-adic\n\n\nrelative Chinese remainder theorem!!\n", "meta": {"hexsha": "0409ddabd738826aac9bd1db282fc700add43074", "size": 3850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/cats/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/cats/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/cats/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": 36.6666666667, "max_line_length": 107, "alphanum_fraction": 0.6963636364, "num_tokens": 1214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.884039278690883, "lm_q1q2_score": 0.6673745004633955}}
{"text": "\\subsection{Implicit Matrix Representation}\n\\label{adap_sec:mrep}\n\\paragraph{} \nMatrix representation of a parameterized algebraic curve allows an easy way to calculate the intersection between it with another curve and find the corresponding parameter based on the given point on the curve.\nFor an algebraic curve $t \\in \\mathbf{R}^1 \\xrightarrow{\\phi} \\left( \\frac{f_1(t)}{f_0(t)}, \\frac{f_2(t)}{f_0(t)},\\frac{f_3(t)}{f_0(t)} \\right) \\in \\mathbf{R}^3$, $f_0,f_1,f_2$ and $f_3$ are polynomials functions in parameter $t$ with degree $\\leq p$.\nThe procedure of constructing the matrix representation for NURBS curves are explained detail in \\citep{Laurent2014}.\n\\paragraph{}\nThe aim of this method is to find 4-tuples of polynomials\\\\\n$\\left( g_0(t),g_1(t),g_2(t),g_3(t) \\right)$ with order $v$ so that\n\\begin{equation}\n    \\sum_{i=0}^3 g_i(t) f_i(t) \\equiv 0\n    \\label{adap_eq_mRep_eq0}\n\\end{equation}\n%\nwho is a vector space and one of its bases can be:\n\\begin{equation}\n    \\mathbf{L_j}(t,X,Y,Z) = g_0(t) + Xg_1(t) + Yg_2(t) + Zg_3(t)\n    \\label{adap:eq:mrep_eq1}\n\\end{equation}\nSince $g$ is also a polynomial based function, it can be expressed in the vector space with a set of bases of $\\left\\{\\psi_1(t), \\psi_2(t), \\dots, \\psi_{m_v}(t) \\right\\}$ and the bases $\\mathbf{L_j}$ can be expressed as\n    \\begin{equation}\n        \\begin{aligned}\n            \\mathbf{L_j} &= \\sum^{m_v}_{i=1}\\left( \\lambda_{0,i}^{(j)} + \\lambda_{1,i}^{(j)}X + \\lambda_{2,i}^{(j)}Y + \\lambda_{3,i}^{(j)}Z\\right)\\psi_i(t)\\\\\n        & = \\sum_{i=1}^{m_v} \\Lambda_{i,j}(X,Y,Z)\\psi_i(t)\n        \\end{aligned}\n    \\end{equation}\n%\nFinally, a matrix which represents the mapping of $\\phi$ in a $m_v \\times r_v$-matrix $\\mathbf{M_v}$ with order $v$\n    \\begin{equation}\n        \\mathbf{M_v}(\\phi) = \n        \\begin{bmatrix}\n        \\Lambda_{1,1} & \\Lambda_{1,2} & \\dots & \\Lambda_{1,r_v} \\\\ \n        \\Lambda_{2,1} & \\Lambda_{2,2} & \\dots & \\Lambda_{2,r_v} \\\\ \n        \\vdots \t\t  & \\vdots \t\t  &  \t  &\\vdots\t\t\t\\\\\n        \\Lambda_{m_v,1}&\\Lambda_{m_v,2}&\\dots &\\Lambda_{m_v,r_v}\n        \\end{bmatrix}\n    \\end{equation}\n\n\n\n%=====================================================================================================================%\n\\subsection{Matrix Representation for Rational Bézier Curves}\nAn rational bézier curves can be defined by \n\\begin{equation}\n\t\\phi:t\\in \\mathbf{R}\\rightarrow \\frac{\\sum_{i=0}^pw_i\\mathbf{P}_iB_i^p(t) }{\\sum_{i=0}^pw_iB_i^p(t)}\n\\end{equation}\nwhere\n\\begin{equation}\n    B_i^p(t) = \\mathbf{C}_i^dt^i(1-t)^{d-i}\n    \\label{adap_eq_mrep_bbasis}\n\\end{equation}\n%\nThe aim is to find a matrix whose vector is in the form of\n\\begin{equation}\n    [\\alpha] =\n    \\begin{bmatrix}\n        \\alpha_{0,0} & \\alpha_{0,1}&  \\dots&  \\alpha_{0,v} & \\alpha_{1,0} & \\dots & \\alpha_{3,v} \n    \\end{bmatrix}^T\n\\end{equation}\n%\nwhere $g_j(t)$ in Eq.~\\ref{adap:eq:mrep_eq1} can be expressed as\n\\begin{equation}\n    g_j(t) = \\sum_{i=0}^v \\alpha_{j,i}B_i^v(t)\n\\end{equation}\n%\nBased on Eq.~\\eqref{adap_eq_mRep_eq0}, it can be concluded that $\\mathbf{R}\\times\\left[\\alpha\\right]=0$\n\\begin{equation}\n    \\mathbf{R} = \n    \\begin{bmatrix}\n        B_0^v(t)f_0(t) & \\dots & B_v^v(t)f_0(t) & B_0^v(t)f_1(t) & \\dots & B_v^v(t)f_3(t)\n    \\end{bmatrix}\n\\end{equation}\n%\nBy having another set of basis $\\mathbf{L_v}$ and the transformation matrix $\\mathbf{S}$ so that $\\mathbf{L_vS}=\\mathbf{R}$ where\n\\begin{equation}\n    \\mathbf{L_v}=\n    \\begin{bmatrix}\n        B_0^{v+d}(t) & B_1^{v+d}(t) & \\dots & B_{v+d}^{v+d}(t)\n    \\end{bmatrix}\n\\end{equation}\n%\nThis leads to\n\\begin{equation}\n    \\begin{bmatrix}\n        B_0^{v+d}(t) & B_1^{v+d}(t) & \\dots & B_{v+d}^{v+d}(t)\n    \\end{bmatrix}\\times \\mathbf{S}\\times\\left[\\alpha\\right] = R\\times\\left[\\alpha\\right] = 0\n\\end{equation}\nwhich indicates $\\left[ \\alpha\\right]$ is in the null space of $\\mathbf{S}$\n\nAfter substituting $f(t) = \\sum_{i=0}^dc_iB_i^d(t)$ into $\\mathbf{R}$, the following can be deduced\n\\begin{equation}\n    B_j^v(t)f(t) =  \\sum_{i=0}^dc_iB_i^d(t)B_j^v(t) =\\sum_{i=0}^d \\frac{\\mathbf{C}^v_j\\mathbf{C}^d_i}{\\mathbf{C}^{d+v}_{i+j}}c_i B_{i+j}^{d+v}(t)\n\\end{equation}\n%\nwhich indicates that\n\\begin{equation}\n    \\mathbf{S}_{i+j,j} = \\frac{\\mathbf{C}^v_j\\mathbf{C}^d_i}{\\mathbf{C}^{d+v}_{i+j}}c_i\n\\end{equation}\n%\nFinally, the null space of $\\mathbf{S_v}$, $\\mathbf{M_v}$ is the matrix representation of the rational bézier curve.\n\n\n\n%=====================================================================================================================%\n\\subsection{Intersection}\nThe calculation of the intersection is described in detail in \\citep{Buse2010, Ba2009}.\nAll intersections can be calculated at once by using matrix representation of the algebraic curve.\n\\paragraph{} \nGiven a rational curve/surface $C1$\n\\begin{equation}\n    \\mathbf{P}^1 \\xrightarrow{\\phi_1} \\mathbf{P}^n: (u,v) \\rightarrow(f_0,f_1,f_2,f_3)(u,v)\n\\end{equation}\n%\nthe aim is to find the intersection between it with another rational curve $C2$ via matrix representation\n\\begin{equation}\n    \\mathbf{P}^1 \\xrightarrow{\\phi_2} \\mathbf{P}^n: (t) \\rightarrow(g_0,g_1,g_2,g_3)(t)\n\\end{equation}\n%\nis to find\n\\begin{equation}\n    \\mathbf{M}_{v1}(\\phi_2(t) = 0\n\\end{equation}\n%\nwhich leads to\n\\begin{equation}\n    \\mathbf{M_0}g_0 + \\mathbf{M_1}g_1 + \\mathbf{M_2}g_2 + \\mathbf{M_3}g_3 = 0\n    \\label{mRep_intec_base}\n\\end{equation}\n%\nBy knowing $g_n$ is a polynomial function with order $p$, Eq.~\\eqref{mRep_intec_base} can be rearranged as\n\\begin{equation}\n    \\mathbf{M}(t) = \\sum_{i=0}^p \\mathbf{M_i}t^i\n\\end{equation}\n%\nAfter that, the generalized companion $q \\times p$-matrices $A, B$ with rank $\\rho$ are introduced\n\\begin{equation}\n    A = \n    \\begin{bmatrix}\n        0\t\t&I \t\t&\\dots \t\t&\\dots \t\t&0 \t\t\\\\\n        0 \t\t&0 \t\t&I \t\t\t&\\dots \t\t&0 \t\t\\\\\n        \\vdots \t&\\vdots &\\vdots \t&\\vdots \t&\\vdots \\\\\n        0 \t\t&0 \t\t&\\dots\t\t&\\dots \t\t&I \t\t\\\\\n        M_0^t \t&M_1^t \t&\\dots \t\t&\\dots \t\t&M_{d-1}^t\n    \\end{bmatrix}\n\\end{equation}\n%\n\\begin{equation}\n    B = \n    \\begin{bmatrix}\n        I \t\t&0 \t\t&\\dots \t\t&\\dots \t\t&0 \t\t\\\\\n        0 \t\t&I \t\t&0 \t\t\t&\\dots \t\t&0 \t\t\\\\\n        \\vdots \t&\\vdots &\\vdots \t&\\vdots \t&\\vdots \\\\\n        0 \t\t&0 \t\t&\\dots \t\t&I \t\t\t&0 \t\t\\\\\n        0 \t\t&0 \t\t&\\dots \t\t&\\dots \t\t&-M_d^t \\\\\t\t\n    \\end{bmatrix}\n\\end{equation}\n%\nBefore the eigenvalues are calculated, the regular part of a non-square pencil of the matrices shall be extracted first which is done by the following step\n%\n\\paragraph{Step 1}\nTransform $B$ into its column echelon form:\nSVD-decomposition is adopted to perform the task.\n\\begin{equation}\n\\begin{aligned}\n    B_1 = BV_0 = [\\underbrace{B_{1,1}}_{\\rho} |\\underbrace{0}_{q-\\rho}]\t\\\\\n    A_1 = AV_0 = [\\underbrace{A_{1,1}}_{\\rho} |\\underbrace{A_{1,2}}_{q-\\rho}]\n\\end{aligned}\n\\end{equation}\n%\n\\paragraph{Step 2}\nTransform $A_{1,2}$ into its row echelon form:\n\\begin{equation}\n    U_1A_{1,2} = \n    \\begin{bmatrix}\n        \\underline{A^\\prime_{1,2}}\\\\\n        0\n    \\end{bmatrix}\n\\end{equation}\n%\nwhere $A^\\prime_{1,2}$ is in full row rank.\\\\\nAt the end of step 2, matrix $A$ and $B$ can be represented as\n\\begin{equation}\n\\begin{aligned}\n    A^\\prime_1 &=\n    \\begin{bmatrix}\n        A^\\prime_{1,1} & A^\\prime_{1,2} \\\\\n        \\cmidrule(lr){1-2}\n        A_2 & 0\n    \\end{bmatrix}\\\\\n    B^\\prime_1 &=\n    \\begin{bmatrix}\n        B^\\prime_{1,1} & 0\\\\\n        \\cmidrule(lr){1-2}\n        B_2 & 0\n    \\end{bmatrix}\n\\end{aligned}\n\\end{equation}\nwhere $A^\\prime_{1,2}$ has full row rank\\\\\n$\n\\begin{bmatrix}\n\\underline{B^\\prime_{1,1}}\\\\\nB_2\n\\end{bmatrix}\n$ has full column rank\\\\\n$\n\\begin{bmatrix}\n\\underline{B^\\prime_{1,1}}\\\\\nB_2\n\\end{bmatrix}\n$ \nand $B_2$ are in echelon form\n\\paragraph{}\n$A_2$ and $B_2$ will be the new $A$ and $B$ matrices for next iteration until $B$ has full rank.\nIf $B$ has full row rank but not full rank, $A=A^T$ and $B=B^T$ are conducted.\n\\paragraph{}\nAfter these processes, $A$ and $B$ become two square matrices and $B$ is invertible so that the solution for the intersection parameter $t$ can be determined from the eigenvalue of the matrix $AB^{-1}$\n\\paragraph{}\nHowever, the method may fail when the intersection is under the case where nearly tangential geometric conditions happens and return two empty matrices.\nIt is addressed by adding another step after extracting the real part of the $A$ and $B$ if the results are empty matrices\\citep{Shen2016}.\nIf the input matrix $A$ and $B$ are not in full row rank or full column rank, it is considered that $C1 \\cap C2 = C2$.\nIf the input matrix $A$ and $B$ are in full row rank or full column rank, a rank $m$ square sub-pencil is extracted assuming $A$ and $B$ have a rank of $m$.\nThen the eigenvalues yield the intersections.\n", "meta": {"hexsha": "9c9ae1398a2baf905d367fbc6cbfb72e07b20626", "size": 8645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "adaptivity/mrep.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": "adaptivity/mrep.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": "adaptivity/mrep.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7668161435, "max_line_length": 251, "alphanum_fraction": 0.6253325622, "num_tokens": 3208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6673331863315832}}
{"text": "\\lab{Lorenz Equations}{Lorenz Equations}\n\\label{lab:lorenz}\n\n\\objective{Investigate the behavior of a system that exhibits chaotic behavior.\nDemonstrate methods for visualizing the evolution of a system.}\n\nChaos is everywhere.\nIt can crop up in unexpected places and in remarkably simple systems, and a great deal of work has been done to describe the behavior of chaotic systems.\nOne primary characteristic of chaos is that small changes in initial conditions result in large changes over time in the solution curves.\n\n\\section*{The Lorenz System}\nOne of the earlier examples of chaotic behavior was discovered by Edward Lorenz.\nIn 1963, while working to study atmospheric dynamics he derived the simple system of equations\n\\begin{align*}\n\\frac{\\partial x}{\\partial t} &= \\sigma \\left(y - x\\right) \\\\\n\\frac{\\partial y}{\\partial t} &= \\rho x - y - x z \\\\\n\\frac{\\partial z}{\\partial t} &= x y - \\beta z\n\\end{align*}\nwhere $\\sigma$, $\\rho$, and $\\beta$ are all constants.\nAfter deriving these equations, he plotted the solutions and observed some unexpected behavior.\nFor appropriately chosen values of $\\sigma$, $\\rho$, and $\\beta$, the solutions did not tend toward any steady fixed points, nor did the system permit any stable cycles.\nThe solutions did not tend off toward infinity either.\nWith further work, he began the study of what was called a strange attractor.\nThis system, though relatively simple, exhibits chaotic behavior.\n\n\\begin{problem}\n\\label{prob:lorenz_basic}\nUse Mayavi's \\li{plot3d} function to plot the trajectories of several points in the Lorenz system.\nUse $\\sigma = 10$, $\\beta = \\frac{8}{3}$, and $\\rho = 28$.\nChoose random initial values between $-15$ and $15$.\nThe result should look something like Figure \\ref{fig:lorenz_plot}.\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{lorenz_plot.png}\n\\caption{Approximate solutions to the Lorenz equations for several random starting points.}\n\\label{fig:lorenz_plot}\n\\end{figure}\n\n\\section*{Animation in Mayavi}\nHere we will take a brief diversion into some tools for plotting that will help us to visualize the evolution of systems like the one we are studying here.\nBoth Matplotlib and Mayavi allow for some kind of visualization.\n% As of this writing, Mayavi's support for 3D plotting is much more robust than the plotting in Matplotlib, so we will encourage students to use it instead of Matplotlib.\nHere we will work primarily with the animation functions in Mayavi, though similar functionality is available in Matplotlib.\n\n\\subsection*{Setting Data}\nSaid simply, most things you plot in Mayavi, allow you to change their data.\nFor things you plot using the basic built in plotting functions in the \\li{mlab} api this can be done using the \\li{set} and \\li{reset} methods of the \\li{mlab_source} attribute of the object created by the plotting function.\nFor example, the following short script will plot the curve $(t, \\cos(t), 0)$, in spite of the fact that we originally plot the data corresponding to the curve $(t, \\sin(t), 0)$.\n\\begin{lstlisting}\nimport numpy as np\nfrom mayavi import mlab\n\nx = np.linspace(- 2 * np.pi, 2 * np.pi)\ny = np.sin(x)\nz = np.zeros_like(x)\n# Plot the first curve.\ncurve = mlab.plot3d(x, y, z)\n# Change the y values.\ncurve.mlab_source.set(y=np.cos(x))\n# Show the new curve.\nmlab.show()\n\\end{lstlisting}\n\nWe can use this functionality in conjunction with some function decorators included in Mayavi to make a plot that continually evolves.\nFor example, we can continuously shift the phase of a curve like the one above using something like this:\n\\begin{lstlisting}\nfrom mayavi import mlab\nimport numpy as np\n\ndef animate_sine(resolution=101, step=1, delay=20):\n    # Compute the initial values for the curve.\n    # Leave off the last point so we can update by rolling the entries of the array from\n    # the end to the beginning.\n    x = np.linspace(0, 4 * np.pi, resolution)[:-1]\n    # Make the surface object and the initial plot.\n    c = mlab.plot3d(x, np.sin(x), np.zeros_like(x), line_width=.2)\n    # Use decorators to call the update the plot\n    # periodically with a given time delay.\n    # 'animate' is a generator that updates\n    # the plot each time it is called.\n    # The show decorator takes care of showing the figure.\n    @mlab.show\n    @mlab.animate(delay=delay)\n    def animate():\n        # Get 'y' back from the surface object.\n        y = c.mlab_source.y\n        # Update the plot at each iteration of this loop.\n        while True:\n            y = np.roll(y, step)\n            c.mlab_source.set(y=y)\n            yield\n    # Run the animation on the figure.\n    animate()\n# Run the full animation.\nanimate_sine()\n\\end{lstlisting}\n\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{harmonic1.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{harmonic2.png}\n\\end{subfigure}\n\\caption{Simple surfaces we can animate with Mayavi.}\n\\label{fig:harmonic_animations}\n\\end{figure}\n\nThe \\li{set} method can also be used on 3D surfaces.\nThe following two examples show how this is done.\nThe surfaces they animate are shown in Figure \\ref{fig:harmonic_animations}.\n\\begin{lstlisting}\nfrom mayavi import mlab\nimport numpy as np\n\ndef animate_harmonic(resolution=51, delay=25):\n    # Make the initial data for the surface.\n    x = np.linspace(0, np.pi, resolution)\n    y = np.linspace(0, np.pi, resolution)\n    x, y = np.meshgrid(x, y, copy=False)\n    z = np.sin(x) * np.sin(y)\n    # Plot the surface.\n    # For now use zeros as the z values.\n    # It will use the scalars values to select colors,\n    # so we'll have it match the colors to the z values now.\n    c = mlab.mesh(x, y, np.zeros_like(z), scalars=z)\n    # Animate it by changing the 'z' values.\n    @mlab.show\n    @mlab.animate(delay=delay)\n    def animate():\n        # We'll have it oscillate between its current value\n        # and the negative of its current value.\n        # We'll have scale range from values of 0 to 2 * np.pi.\n        scale = 0.\n        while True:\n            # Update the scale\n            scale += .05\n            # Cycle back toward 0 if necessary.\n            if scale > 2 * np.pi:\n                scale -= 2 * np.pi\n            # Update the plot\n            c.mlab_source.set(z = np.sin(scale) * z)\n            yield\n    # Run the animation on the figure.\n    animate()\n# Run the full animation.\nanimate_harmonic()\n\\end{lstlisting}\n\nHere is an example that uses this same approach to plot a more generic oscillating surface.\n\\begin{lstlisting}\nimport numpy as np\nfrom mayavi import mlab\n\ndef oscillate(x, y, z, delay=20):\n    @mlab.show\n    @mlab.animate(delay=delay)\n    def animate(x, y, z):\n        # Make the initial plot.\n        surface = mlab.mesh(x, y, np.zeros_like(z), scalars=z)\n        # Use this variable to scale it at each step in the animation.\n        scale = 0.\n        while True:\n            scale += .05\n            if scale > 2 * np.pi:\n                scale -= 2 * np.pi\n            # Update the 'z' values for the surface.\n            surface.mlab_source.set(z = np.sin(scale) * z)\n            yield\n    # Run the animation\n    animate(x, y, z)\n\n# Here's another fun example.\n# Construct the data for the plot.\nx = np.linspace(0, np.pi)\ny = np.linspace(0, np.pi)\nx, y = np.meshgrid(x, y, copy=False)\nz = np.sin(2 * x) * np.sin(2 * y)\n# Run the animation.\noscillate(x, y, z)\n\\end{lstlisting}\n\n\\subsection*{Resetting Data}\nThe \\li{set} method we have shown thus far is useful when we are changing the values of the data used in a plot, but it does not work when we need to change the \\emph{shape} of the arrays involved as well.\nSome times it is necessary to change the shapes of the arrays used for the plot.\nTo do this we must use the \\li{reset} method.\nHere is an example where we use the \\li{reset} method to trace out a helix curve like the one shown in Figure \\ref{fig:helix_animation}\n\\begin{lstlisting}\nfrom mayavi import mlab\nimport numpy as np\n\ndef trace_helix(resolution=401, delay=10, step=1):\n    z = np.linspace(0, 2, resolution)\n    x = np.cos(4 * np.pi * z)\n    y = np.sin(4 * np.pi * z)\n    # Make a line to start from.\n    # Note that the 'x', 'y', and 'z' coordinates for the curve must be contained in arrays or lists.\n    # Only passing the coordinates of the first point will not work.\n    # Notice how we are passing in the color.\n    # The color is expected to be a tuple (not a list or array) representing RGB values for the desired color.\n    c = mlab.plot3d(x[:1], y[:1], z[:1], line_width=.2, color=(1, 0, 0))\n    # Set the camera position to a good angle for this plot.\n    mlab.gcf().scene.camera.position = [3.95632052, 3.95626431, 4.95668558]\n    mlab.gcf().scene.camera.focal_point = [2.27987766e-04, 1.71780586e-04, 1.00059305]\n    mlab.gcf().scene.camera.clipping_range = [3.25443332, 11.39746923]\n    @mlab.show\n    @mlab.animate(delay=delay)\n    def animate():\n        scale = 0.\n        for i in xrange(2 + step, z.size, step):\n            # Reset the 'x', 'y', and 'z' coordinates for the graph.\n            c.mlab_source.reset(x=x[:i], y=y[:i], z=z[:i])\n            yield\n    animate()\ntrace_helix()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{helix.png}\n\\caption{A simple curve we can animate using Mayavi.}\n\\label{fig:helix_animation}\n\\end{figure}\n\nIf you want to reset the zoom at each update so that the view updates to match the plot you can do the following\n\\begin{lstlisting}\nfrom mayavi import mlab\nimport numpy as np\n\ndef trace_helix(resolution=401, delay=10, step=1):\n    z = np.linspace(0, 2, resolution)\n    x = np.cos(4 * np.pi * z)\n    y = np.sin(4 * np.pi * z)\n    c = mlab.plot3d(x[:1], y[:1], z[:1], line_width=.2, color=(1, 0, 0))\n    @mlab.show\n    @mlab.animate(delay=delay)\n    def animate():\n        scale = 0.\n        for i in xrange(2 + step, z.size, step):\n            c.mlab_source.reset(x=x[:i], y=y[:i], z=z[:i])\n            # Reset the zoom at each iteration.\n            mlab.gcf().scene.reset_zoom()\n            yield\n    animate()\ntrace_helix()\n\\end{lstlisting}\n\nIf you would like to find the proper configuration for the camera there are several different ways to do it.\nOne is to plot the full figure, and access the camera \\li{scene}, \\li{focal_point}, \\li{clipping_range}, \\li{viewing_angle}, and \\li{view_up} attributes, save their values and use them to configure the plot as shown in the first example involving the helix.\n\nYou can also use the Mayavi pipeline window.\nYou can open this window by clicking the button at the top-right of the window where your plot appears.\nIf you click the red record button, move your plot to the position you want it to have, then stop the recording, you will be able to get the desired camera positioning.\n\n\\begin{problem}\n\\label{prob:lorenz_animation}\nWrite a Python function that animates the Lorenz system using Mayavi.\nHave it accept a number of trajectories to plot, a final time value, a resolution for the plot, a stepping number (how many new points to include at each update of the plot), and a time delay to use between iterations.\nGenerate your starting points the same way you did in problem \\ref{prob:lorenz_basic}.\nUse different colors for each trajectory.\n\\end{problem}\n\nWe will now use animations to demonstrate that the Lorenz system is very sensitive to changes in the initial conditions.\n\n\\begin{problem}\n\\label{prob:lorenz_tol_sensitivity}\nWrite another Python function that produces a similar animation as the one in Problem \\ref{prob:lorenz_animation}.\nUse one initial guess, but solve the ODE system using the arguments \\li{atol=1E-14} and \\li{rtol=1E-12}, and then \\li{atol=1E-15} and \\li{rtol=1E-13} when you call \\li{scipy.odeint}.\nHave your function accept a final time value, a resolution for the curve, a stepping number, and a time delay to use between iterations.\nWhat happens as you let your solution curves evolve over time?\nTry running the simulation for longer periods of time.\n% The solution curves should stay together for a while, then separate.\n\\end{problem}\n\n\\begin{problem}\nWrite another animation that plots a single solution set and another solution set with slightly perturbed initial conditions.\nWe will perturb the initial conditions by the smallest representable floating point value.\nIf \\li{x0} is our first initial condition, let the second set of initial conditions, \\li{x1}, be \\li{x1 = y0 * (1. + 2.22E-16)}.\nWhat happens as you let your solution curves evolve over time?\nTry running the simulation for longer periods of time.\n% The solution curves should stay together for a while, then separate.\n\\end{problem}\n\n\\section*{Lyapunov Exponents}\nThe Lyapunov exponent of a dynamical system is one measure of how chaotic a system is.\nWhile there are more conditions for a system to be considered chaotic, one of the primary indicators of a chaotic system is \\emph{extreme sensitivity to initial conditions}.\nStrictly speaking, this is saying that a chaotic system is poorly conditioned.\nUsually, in dynamical systems, the sensitivity to changes in initial conditions depends exponentially on the time the system is allowed to evolve.\nIf $\\delta(t)$ represents the difference between two solution curves, when $\\delta(t)$ is small, the following approximation holds.\n\\[\\|\\delta(t)\\| \\sim \\|\\delta(0)\\| e^{\\lambda t}\\]\nwhere $\\lambda$ is a constant called the Lyapunov exponent.\nFor the Lorenz system, expirimentally it can be verified that $\\lambda \\approx .9$.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{lyapunov_plot.pdf}\n\\caption{A semilog plot of the separation between two solutions to the Lorenz equations together with a fitted line that gives a rough estimate of the Lyapunov exponent of the system.}\n\\label{fig:lyapunov_exponent}\n\\end{figure}\n\n\\begin{problem}\nGet a crude estimate of the lyapunov exponent for the Lorenz system.\nWrite a Python function that, finds an initial point on the strange attractor, runs the simulation to a given time $t$, and produces a semilog plot of the norm of the difference between the two solution curves.\nAlso have it plot an exponential line fitted to match the curve (this will be linear on the semilog plot).\nHave it return a rough estimate of the Lyapunov exponent.\nThe output should be something like Figure \\ref{fig:lyapunov_exponent}.\n\nNote: In order to get a good estimate of the Lyapunov exponent, your initial guess should already lie on the strange attractor.\nYou can get a value on the attractor by running the system for a while to find a good initial guess.\n\nHint: To find the fitting line, take the logarithm of the norms of the differences, compute a linear fit, then take the exponential function of the resulting line.\nThe Lyapunov exponent will be approximately equal to the slope found by the linear regression.\n\\end{problem}", "meta": {"hexsha": "cbe524fa0aaff8198d05c7e474c2922612f0f14d", "size": 14796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/LorenzEquations/LorenzEquations.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/LorenzEquations/LorenzEquations.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/LorenzEquations/LorenzEquations.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": 47.4230769231, "max_line_length": 257, "alphanum_fraction": 0.7209380914, "num_tokens": 3824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.667333175636012}}
{"text": "%!TEX root = ceres-solver.tex\n\\chapter{Powell's Function}\n\\label{chapter:tutorial:powell}\nConsider now a slightly more complicated example -- the minimization of Powell's function. Let $x = \\left[x_1, x_2, x_3, x_4 \\right]$ and\n\\begin{align}\n   f_1(x) &= x_1 + 10*x_2 \\\\\n   f_2(x) &= \\sqrt{5} * (x_3 - x_4)\\\\\n   f_3(x) &= (x_2 - 2*x_3)^2\\\\\n   f_4(x) &= \\sqrt{10} * (x_1 - x_4)^2\\\\\n\tF(x) & = \\left[f_1(x),\\ f_2(x),\\ f_3(x),\\ f_4(x) \\right]\n\\end{align}\n$F(x)$ is a function of four parameters, and has four residuals. Now,\none way to solve this problem would be to define four\n\\texttt{CostFunction} objects that compute the residual and Jacobians. \\eg the following code shows the implementation for $f_4(x)$.\n\\begin{minted}[mathescape]{c++}\nclass F4 : public ceres::SizedCostFunction<1, 4> {\n public:\n  virtual ~F4() {}\n  virtual bool Evaluate(double const* const* parameters,\n                        double* residuals,\n                        double** jacobians) const {\n    double x1 = parameters[0][0];\n    double x4 = parameters[1][0];\n    // $f_4 = \\sqrt{10} * (x_1 - x_4)^2$\n    residuals[0] = sqrt(10.0) * (x1 - x4) * (x1 - x4)\n    if (jacobians != NULL) {\n      jacobians[0][0] = 2.0 * sqrt(10.0) * (x1 - x4);   // $\\partial_{x_1}f_1(x)$\n      jacobians[0][1] = 0.0;                            // $\\partial_{x_2}f_1(x)$\n      jacobians[0][2] = 0.0;                            // $\\partial_{x_3}f_1(x)$\n      jacobians[0][3] = -2.0 * sqrt(10.0) * (x1 - x4);  // $\\partial_{x_4}f_1(x)$\n    }\n    return true;\n  }\n};\n\\end{minted}\n\nBut this can get painful very quickly, especially for residuals involving complicated multi-variate terms. Ceres provides two ways around this problem. Numeric and automatic symbolic differentiation.\n\n\\section{Automatic Differentiation}\n\\label{sec:tutorial:autodiff}\nWith its automatic differentiation support, Ceres allows you to define templated objects/functors that will compute the residual and it takes care of computing the Jacobians as needed and filling the \\texttt{jacobians} arrays with them. For example, for $f_4(x)$ we define\n\\begin{minted}[frame=lines,mathescape]{c++}\nclass F4 {\n public:\n  template <typename T> bool operator()(const T* const x1,\n                                        const T* const x4,\n                                        T* residual) const {\n    // $f_4 = \\sqrt{10} * (x_1 - x_4)^2$\n    residual[0] = T(sqrt(10.0)) * (x1[0] - x4[0]) * (x1[0] - x4[0]);\n    return true;\n  }\n};\n\\end{minted}\n\nThe important thing to note here is that \\texttt{operator()} is a\ntemplated method, which assumes that all its inputs and outputs are of\nsome type \\texttt{T}. The reason for using templates here is because Ceres will call \\texttt{F4::operator<T>()}, with $\\texttt{T=double}$ when just the residual is needed, and with a special type $T=\\texttt{Jet}$ when the Jacobians are needed.\n\nNote also that the parameters are not packed\ninto a single array, they are instead passed as separate arguments to\n\\texttt{operator()}. Similarly we can define classes \\texttt{F1,F2}\nand \\texttt{F4}.  Then let us consider the construction and solution of the problem. For brevity we only describe the relevant bits of code~\\footnote{The full source code for this example can be found in \\texttt{examples/powell.cc}.}\n\\begin{minted}[mathescape]{c++}\ndouble x1 =  3.0; double x2 = -1.0; double x3 =  0.0; double x4 =  1.0;\n// Add residual terms to the problem using the using the autodiff\n// wrapper to get the derivatives automatically. \nproblem.AddResidualBlock(\n  new ceres::AutoDiffCostFunction<F1, 1, 1, 1>(new F1), NULL, &x1, &x2);\nproblem.AddResidualBlock(\n  new ceres::AutoDiffCostFunction<F2, 1, 1, 1>(new F2), NULL, &x3, &x4);\nproblem.AddResidualBlock(\n  new ceres::AutoDiffCostFunction<F3, 1, 1, 1>(new F3), NULL, &x2, &x3)\nproblem.AddResidualBlock(\n  new ceres::AutoDiffCostFunction<F4, 1, 1, 1>(new F4), NULL, &x1, &x4);\n\\end{minted}\nA few things are worth noting in the code above. First, the object\nbeing added to the \\texttt{Problem} is an\n\\texttt{AutoDiffCostFunction} with \\texttt{F1}, \\texttt{F2}, \\texttt{F3} and \\texttt{F4} as template parameters. Second, each \\texttt{ResidualBlock} only depends on the two parameters that the corresponding residual object depends on and not on all four parameters.\n\n\nCompiling and running \\texttt{powell.cc} gives us:\n\\begin{minted}{bash}\nInitial x1 = 3, x2 = -1, x3 = 0, x4 = 1\n   0: f: 1.075000e+02 d: 0.00e+00 g: 1.55e+02 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e-04 li:  0\n   1: f: 5.036190e+00 d: 1.02e+02 g: 2.00e+01 h: 2.16e+00 rho: 9.53e-01 mu: 3.33e-05 li:  1\n   2: f: 3.148168e-01 d: 4.72e+00 g: 2.50e+00 h: 6.23e-01 rho: 9.37e-01 mu: 1.11e-05 li:  1\n   3: f: 1.967760e-02 d: 2.95e-01 g: 3.13e-01 h: 3.08e-01 rho: 9.37e-01 mu: 3.70e-06 li:  1\n   4: f: 1.229900e-03 d: 1.84e-02 g: 3.91e-02 h: 1.54e-01 rho: 9.37e-01 mu: 1.23e-06 li:  1\n   5: f: 7.687123e-05 d: 1.15e-03 g: 4.89e-03 h: 7.69e-02 rho: 9.37e-01 mu: 4.12e-07 li:  1\n   6: f: 4.804625e-06 d: 7.21e-05 g: 6.11e-04 h: 3.85e-02 rho: 9.37e-01 mu: 1.37e-07 li:  1\n   7: f: 3.003028e-07 d: 4.50e-06 g: 7.64e-05 h: 1.92e-02 rho: 9.37e-01 mu: 4.57e-08 li:  1\n   8: f: 1.877006e-08 d: 2.82e-07 g: 9.54e-06 h: 9.62e-03 rho: 9.37e-01 mu: 1.52e-08 li:  1\n   9: f: 1.173223e-09 d: 1.76e-08 g: 1.19e-06 h: 4.81e-03 rho: 9.37e-01 mu: 5.08e-09 li:  1\n  10: f: 7.333425e-11 d: 1.10e-09 g: 1.49e-07 h: 2.40e-03 rho: 9.37e-01 mu: 1.69e-09 li:  1\n  11: f: 4.584044e-12 d: 6.88e-11 g: 1.86e-08 h: 1.20e-03 rho: 9.37e-01 mu: 5.65e-10 li:  1\nCeres Solver Report: Iterations: 12, Initial cost: 1.075000e+02, \\\nFinal cost: 2.865573e-13, Termination: GRADIENT_TOLERANCE.\nFinal x1 = 0.000583994, x2 = -5.83994e-05, x3 = 9.55401e-05, x4 = 9.55401e-05\n\\end{minted}\nIt is easy to see that the  optimal solution to this problem is at $x_1=0, x_2=0, x_3=0, x_4=0$ with an objective function value of $0$. In 10 iterations, Ceres finds a solution with an objective function value of $4\\times 10^{-12}$.\n\n\\section{Numeric Differentiation}\nIf a templated implementation is not possible then a \\texttt{NumericDiffCostFunction} object can be used. The user defines a \\texttt{CostFunction} object whose \\texttt{Evaluate} method is only computes the residuals. A wrapper object \\texttt{NumericDiffCostFunction} then uses it to compute the residuals and the Jacobian using finite differencing.  \\texttt{examples/quadratic\\_numeric\\_diff.cc} shows a numerically differentiated implementation of \\texttt{examples/quadratic.cc}.\n\nWe recommend that if possible,  automatic differentiation should be used. The use of\nC++ templates makes automatic differentiation extremely efficient,\nwhereas numeric differentiation can be quite expensive, prone to\nnumeric errors and leads to slower convergence.", "meta": {"hexsha": "7fc94a35d0c56c90864565d4534a5c6396f979f7", "size": 6718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/powell.tex", "max_stars_repo_name": "pritasam/ceres-solver", "max_stars_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/powell.tex", "max_issues_repo_name": "pritasam/ceres-solver", "max_issues_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/powell.tex", "max_forks_repo_name": "pritasam/ceres-solver", "max_forks_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.2037037037, "max_line_length": 480, "alphanum_fraction": 0.6759452218, "num_tokens": 2527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6673331708335237}}
{"text": "\\chapter{Equations governing the motion of a fluid}\\label{c3}\n\\section{Material integrals in a moving fluid}\\label{c3s1}\n\\begin{itemize}\n\\item We prove that\n\\begin{equation}\\label{c3s1e1}\n\\td{\\tau^\\ast}{t} = (\\dive\\vec{u})\\tau^\\ast,\n\\end{equation}\nwhere\n\\begin{equation}\\label{c3s1e2}\n\\tau^\\ast = \\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{\\delta\\tau(t)}{\\delta\\tau(t_0)}\n\\end{equation}\nWe begin with the definition of the first derivative,\n\\[\n\\td{\\tau^\\ast}{t} = \\lim_{h \\rightarrow 0}\\frac{\\tau(t + h) - \\tau(t)}{h}\n\\]\nUsing \\eqref{c3s1e2},\n\\[\n\\td{\\tau^\\ast}{t} = \\lim_{h \\rightarrow 0}\\frac{1}{h}\\left(\\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{\\delta\\tau(t+h)}{\\delta\\tau(t_0)} - \n\\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{\\delta\\tau(t)}{\\delta\\tau(t_0)}\\right)\n\\]\nor,\n\\[\n\\td{\\tau^\\ast}{t} = \\lim_{h \\rightarrow 0}\\frac{1}{h}\\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{\\delta\\tau(t+h) - \\delta\\tau(t)}{\\delta\\tau(t_0)},\n\\]\nBut\n\\[\n\\delta\\tau(t+h) - \\delta\\tau(t) = h\\td{\\delta\\tau}{t},\n\\]\nwhich from equation (3.1.1) of the book is\n\\[\n\\delta\\tau(t+h) - \\delta\\tau(t) = h\\dive\\vec{u}\\delta\\tau(t)\n\\]\nso that\n\\[\n\\td{\\tau^\\ast}{t} = \\lim_{h \\rightarrow 0}\\frac{1}{h}\\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{h\\dive\\vec{u}\\delta\\tau(t)}{\\delta\\tau(t_0)} =\n\\lim_{h \\rightarrow 0}\\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{\\dive\\vec{u}\\delta\\tau(t)}{\\delta\\tau(t_0)}\n\\]\nSince the function no longer depends on $h$, the limit as $h \\rightarrow 0$ is ineffective and\n\\[\n\\td{\\tau^\\ast}{t} = \\dive\\vec{u}\\lim_{\\delta\\tau(t_0) \\rightarrow 0}\\frac{\\delta\\tau(t)}{\\delta\\tau(t_0)} = (\\dive\\vec{u})\\tau^\\ast\n\\]\n\n\\item We will now argue that, if $\\delta\\vec{l}$ is a material line element, then\n\\begin{equation}\\label{c3s1e3}\n\\td{\\delta\\vec{l}}{t} = \\delta\\vec{l}\\cdot\\grad\\vec{u} + o(|\\delta\\vec{l}|)\n\\end{equation}\nA material line element's length changes only if the velocity of the fluid at its either ends is not the same. Let $\\vec{u}_0$ and $\\vec{u}_1$ be the velocities of the two ends. Then, for\na small element, $\\vec{u}_1 = \\vec{u}_0 + \\delta\\vec{l}\\cdot\\grad\\vec{u} + o(|\\delta\\vec{l}|)$ so that the difference in velocities is $\\delta\\vec{l}\\cdot\\grad\\vec{u} + \no(|\\delta\\vec{l}|)$.\n\n\\item The volume of a cylindrical volume element with end faces of area $\\delta\\vec{S}$ and generator $\\delta\\vec{l}$ is $\\delta\\tau = \\delta\\vec{S}\\cdot\\delta\\vec{l}=\n\\delta S_i\\delta l_i$.\nSince we have\n\\[\n\\lim_{\\delta\\tau \\rightarrow 0}\\frac{1}{\\delta\\tau}\\td{\\delta\\tau}{t} = \\dive\\vec{u},\n\\]\nwe can as well write\n\\begin{equation}\\label{c3s1e4}\n\\td{\\delta\\tau}{t} = \\dive\\vec{u}\\delta\\tau + o(\\delta\\tau)\n\\end{equation}\nor\n\\[\n\\td{\\delta{l}_i}{t}\\delta S_i + \\delta{l}_i\\td{\\delta{S}_i}{t} = \\pdt{u_j}{x_j}\\delta S_i\\delta l_i + o(\\delta\\tau)\n\\]\nUsing \\eqref{c3s1e3} in Cartesian tensor form,\n\\[\n\\delta{l}_j\\pdt{u_i}{x_j}\\delta S_i + \\delta{l}_i\\td{\\delta{S}_i}{t} = \\pdt{u_j}{x_j}\\delta S_i\\delta l_i + o(\\delta\\tau)\n\\]\nInterchanging $i$ and $j$ in the first term,\n\\[\n\\delta{l}_i\\pdt{u_j}{x_i}\\delta S_j + \\delta{l}_i\\td{\\delta{S}_i}{t} = \\pdt{u_j}{x_j}\\delta S_i\\delta l_i + o(\\delta\\tau)\n\\]\nor\n\\[\n\\delta{l}_i\\left(\\pdt{u_j}{x_i}\\delta S_j + \\td{\\delta{S}_i}{t} - \\pdt{u_j}{x_j}\\delta S_i\\right) = o(\\delta\\tau)\n\\]\nIf this were to be true in general then,\n\\begin{equation}\\label{c3s1e5}\n\\td{\\delta{S}_i}{t} = \\pdt{u_j}{x_j}\\delta S_i - \\pdt{u_j}{x_i}\\delta S_j + o(|\\delta\\vec{S}|)\n\\end{equation}\nWe can use the above equation to obtain an expression for,\n\\begin{eqnarray}\n\\frac{d}{dt}(\\rho\\delta S_i) &=& \\rho\\td{\\delta S_i}{t} + \\delta S_i\\td{\\rho}{t} \\nonumber \\\\\n &=& \\rho\\left(\\pdt{u_j}{x_j}\\delta S_i - \\pdt{u_j}{x_i}\\delta S_j + o(|\\delta\\vec{S}|)\\right) + \\nonumber \\\\\n & & \\delta S_i\\left(-\\rho\\pdt{u_j}{x_j}\\right) \\nonumber \\\\\n &=& -\\rho\\delta S_j \\pdt{u_j}{x_i} + o(|\\delta\\vec{S}|) \\label{c3s1e6}\n\\end{eqnarray}\n\n\\item From \\eqref{c3s1e3},\n\\[\n2\\delta\\vec{l}\\cdot\\td{\\delta\\vec{l}}{t} = 2\\delta\\vec{l}\\cdot\\grad\\vec{u}\\cdot\\delta\\vec{l} + o(|\\delta\\vec{l}|^2)\n\\]\nor,\n\\[\n2\\delta{l}\\td{\\delta{l}}{t} = 2\\delta{l}m_i\\pdt{u_j}{x_i}\\delta{l}m_j + o(|\\delta\\vec{l}|^2)\n\\]\nor,\n\\begin{equation}\\label{c3s1e7}\n\\frac{1}{\\delta{l}}\\td{\\delta{l}}{t} = m_im_j\\pdt{u_j}{x_i} + o(|\\delta\\vec{l}|),\n\\end{equation}\nwhere we wrote $\\delta\\vec{l} = \\delta{l}\\vec{m}$, $\\vec{m}$ being a unit vector along the material line element. Similarly, from \\eqref{c3s1e6},\n\\begin{eqnarray}\n\\delta S_i \\frac{d}{dt}(\\rho\\delta S_i) &=& -\\rho\\delta S_j \\pdt{u_j}{x_i}\\delta S_i + o(|\\delta\\vec{S}|^2) \\nonumber \\\\\n\\delta S \\frac{d}{dt}(\\rho\\delta S) &=& -\\rho(\\delta S)^2 n_j\\pdt{u_j}{x_i}n_i + o(|\\delta\\vec{S}|^2) \\nonumber \\\\\n\\frac{1}{\\rho\\delta S}\\frac{d}{dt}(\\rho\\delta S) &=& -n_in_j\\pdt{u_j}{x_i} + o(|\\delta\\vec{S}|), \\label{c3s1e7a}\n\\end{eqnarray}\nwhere we wrote $\\delta\\vec{S} = \\delta{S}\\vec{n}$, $\\vec{n}$ being a unit vector normal to the material area element.\n\n\\item Let us consider the change of a line integral over a material element. Let\n\\[\nI = \\int_P^Q \\theta d\\vec{l},\n\\]\nwhere $\\theta$ is an intensive property of the fluid, dependent only on $\\vec{x}$ and $t$. We first express the integral as a Riemann sum,\n\\[\n\\int_P^Q \\theta d\\vec{l} = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\theta_n \\delta\\vec{l}_n,  \n\\]\nwhere $\\epsilon$ is the size of the largest sub-interval. Thus,\n\\begin{eqnarray*}\n\\frac{d}{dt}\\int_P^Q \\theta d\\vec{l} &=& \\frac{d}{dt}\\lim_{\\epsilon \\rightarrow 0}\\sum_n \\theta_n \\delta\\vec{l}_n \\\\\n &=& \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\frac{D}{Dt}\\left(\\theta_n \\delta\\vec{l}_n \\right) \\\\\n &=& \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n}\\delta\\vec{l}_n + \\theta_n\\md{\\delta\\vec{l}_n} \\right) \n\\end{eqnarray*}\nFor a material element, the material derivative is same as total derivative so that\n\\[\n\\frac{d}{dt}\\int_P^Q \\theta d\\vec{l} = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n}\\delta\\vec{l}_n + \\theta_n\\td{\\delta\\vec{l}_n}{t} \\right) \n\\]\nUsing \\eqref{c3s1e3},\n\\[\n\\frac{d}{dt}\\int_P^Q \\theta d\\vec{l} = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n}\\delta\\vec{l}_n + \\theta_n\\delta\\vec{l}\\cdot\\grad\\vec{u} + \\theta_no(|\\delta\\vec{l}|) \\right) \n\\]\nor, since $o(|\\delta\\vec{l}|) < \\epsilon$\n\\[\n\\frac{d}{dt}\\int_P^Q \\theta d\\vec{l} = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n}\\delta\\vec{l}_n + \\theta_n\\delta\\vec{l}\\cdot\\grad\\vec{u}\\right)\n\\]\nor\n\\begin{equation}\\label{c3s1e8}\n\\frac{d}{dt}\\int_P^Q \\theta d\\vec{l} = \\int_P^Q \\md{\\theta}d\\vec{l}_n + \\int_P^Q \\theta d\\vec{l}\\cdot\\grad\\vec{u}\n\\end{equation}\n\n\\item Now consider the surface integral over a material element,\n\\[\nI = \\int \\theta \\un dS = \\int \\theta dS_i\n\\]\nWriting the integral as a Riemann sum\n\\[\nI = \\lim_{\\epsilon \\rightarrow 0} \\sum_n \\theta_n \\delta S_i^{(n)},\n\\]\nwhere $\\epsilon$ is the size of the largest area interval and $\\delta S_i^{(n)}$ is the $n$th area element. Thus,\n\\begin{eqnarray*}\n\\td{I}{t} &=& \\frac{d}{dt}\\lim_{\\epsilon \\rightarrow 0} \\sum_n \\theta_n \\delta S_i^{(n)} \\\\\n &=& \\lim_{\\epsilon \\rightarrow 0} \\sum_n \\frac{D}{Dt}\\left(\\theta_n \\delta S_i^{(n)}\\right) \\\\\n &=& \\lim_{\\epsilon \\rightarrow 0} \\sum_n \\left(\\md{\\theta_n}\\delta S_i^{(n)} + \\theta_n \\md{\\delta S_i^{(n)}}\\right)\n\\end{eqnarray*}\nFor a material element, the material derivative is same as total derivative so that\n\\[\n\\td{I}{t} = \\lim_{\\epsilon \\rightarrow 0} \\sum_n \\left(\\md{\\theta_n}\\delta S_i^{(n)} + \\theta_n \\td{\\delta S_i^{(n)}}{t}\\right)\n\\]\nUsing \\eqref{c3s1e5},\n\\[\n\\td{I}{t} = \n\\lim_{\\epsilon \\rightarrow 0} \\sum_n \\left[\\md{\\theta_n}\\delta S_i^{(n)} + \\theta_n\\left(\\pdt{u_j}{x_j}\\delta S_i^{(n)} - \\pdt{u_j}{x_i}\\delta S_j^{(n)} + o(|\\delta\\vec{S}|)\\right)\\right]\n\\]\nSince $o(|\\delta\\vec{S}|) < \\epsilon$,\n\\[\n\\td{I}{t} = \\lim_{\\epsilon \\rightarrow 0} \\sum_n \\left[\\md{\\theta_n}\\delta S_i^{(n)} + \\theta_n\\left(\\pdt{u_j}{x_j}\\delta S_i^{(n)} - \\pdt{u_j}{x_i}\\delta S_j^{(n)}\\right)\\right]\n\\]\nor\n\\begin{equation}\\label{c3s1e9}\n\\frac{d}{dt}\\int \\theta dS_i = \\int\\md{\\theta}dS_i + \\int\\theta\\pdt{u_j}{x_j}dS_i - \\int\\theta\\pdt{u_j}{x_i}dS_j\n\\end{equation}\n\n\\item An integral over a material volume element is\n\\[\nI = \\int\\theta d\\tau,\n\\]\nExpressed as a Riemann sum,\n\\[\nI = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\theta_n \\delta \\tau_n,\n\\]\nwhere $\\epsilon$ is the size of the largest volume interval so that\n\\begin{eqnarray*}\n\\td{I}{t} &=& \\frac{d}{dt}\\lim_{\\epsilon \\rightarrow 0}\\sum_n \\theta_n \\delta \\tau_n \\\\\n &=& \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\frac{D}{Dt}\\left(\\theta_n \\delta \\tau_n\\right) \\\\\n &=& \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n} \\delta \\tau_n + \\theta_n\\md{\\delta \\tau_n}\\right)\n\\end{eqnarray*}\nFor a material element, the material derivative is same as total derivative so that\n\\[\n\\td{I}{t} = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n} \\delta \\tau_n + \\theta_n\\td{\\delta \\tau_n}{t}\\right)\n\\]\nUsing \\eqref{c3s1e1},\n\\[\n\\td{I}{t} = \\lim_{\\epsilon \\rightarrow 0}\\sum_n \\left(\\md{\\theta_n} \\delta \\tau_n + \\theta_n\\dive\\vec{u}\\delta \\tau_n\\right)\n\\]\nor\n\\begin{equation}\\label{c3s1e10}\n\\frac{d}{dt}\\int\\theta d\\tau = \\int\\md{\\theta} d\\tau + \\int\\theta\\dive\\vec{u} d\\tau\n\\end{equation}\n\n\\item A useful form of \\eqref{c3s1e10} is\n\\begin{eqnarray*}\n\\frac{d}{dt}\\int\\theta\\rho d\\tau &=& \\int\\left(\\md{(\\theta\\rho)} + \\theta\\rho\\dive{u}\\right)d\\tau \\\\\n &=& \\int\\left(\\md{\\theta}\\rho + \\theta\\md{\\rho} + \\theta\\rho\\dive{u}\\right)d\\tau \\\\\n\\end{eqnarray*}\nFrom the equation of mass conservation,\n\\[\n\\md{\\rho} = -\\rho\\dive{u}\n\\]\nso that\n\\begin{equation}\\label{c3s1e11}\n\\frac{d}{dt}\\int\\theta\\rho d\\tau = \\int\\rho\\md{\\theta}d\\tau\n\\end{equation}\n\n\\item Several conservation laws can be put in the form\n\\[\n\\frac{d}{dt}\\int\\theta\\rho d\\tau = \\int Q d\\tau\n\\]\nUsing \\eqref{c3s1e11}, the left hand side becomes,\n\\[\n\\int\\rho\\md{\\theta}d\\tau = \\int Qd\\tau,\n\\]\nwhich can be true only if\n\\begin{equation}\\label{c3s1e12}\n\\rho\\md{\\theta} = Q\n\\end{equation}\n\n\\item While deriving \\eqref{c3s1e12} we travelled with the material element. We can get to the same conclusion if we, instead, focus on a fixed volume in space. If $V$ is such a volume\nwith surface area $A$ then\n\\[\n\\frac{d}{dt}\\int\\rho\\theta dV\n\\]\nis the rate of change of the quantity $\\rho\\theta$ contained in $V$. The change can be either because of a flux through the boundary or a source (or a sink) in $V$. If $\\un$ is the\noutward normal,\n\\[\n\\frac{d}{dt}\\int\\rho\\theta dV = -\\int\\theta\\rho\\vec{u}\\cdot\\un dA + \\int QdV\n\\]\nSince the volume of integration is fixed, we can interchange the order of differentiation and integration on the left hand side to get\n\\[\n\\int\\frac{\\partial}{\\partial t} (\\theta\\rho) dV = -\\int\\theta\\rho\\vec{u}\\cdot\\un dA + \\int QdV\n\\]\nUsing the divergence theorem on the first term on the right,\n\\begin{equation}\\label{c3s1e13}\n\\int\\frac{\\partial}{\\partial t} (\\theta\\rho) dV = -\\int\\dive(\\theta\\rho\\vec{u})dV + \\int QdV\n\\end{equation}\nwhich immediately leads to the differential form,\n\\begin{equation}\\label{c3s1e14}\n\\frac{\\partial}{\\partial t} (\\theta\\rho) dV = -\\dive(\\theta\\rho\\vec{u}) + Q\n\\end{equation}\n\\end{itemize}\n\n\\section{Equations of motion}\\label{c3s2}\n\\begin{itemize}\n\\item We note that the relation between time derivative of a vector $\\vec{A}$ in a fixed and a rotating frame of reference is\n\\begin{equation}\\label{c3s2e1}\n\\left(\\td{\\vec{A}}{t}\\right)_f = \\left(\\td{\\vec{A}}{t}\\right)_r + \\vec{\\Omega} \\vp \\vec{A},\n\\end{equation}\nwhere the subscripts $f$ and $r$ mean \\enquote*{fixed} and \\enquote*{rotating}. $\\vec{\\Omega}$ is the angular velocity of the rotating frame of reference with respect to the fixed \nframe of reference. An immediate consequence of this equation is \n\\begin{equation}\\label{c3s2e2}\n\\left(\\td{\\vec{\\Omega}}{t}\\right)_f = \\left(\\td{\\vec{\\Omega}}{t}\\right)_r\n\\end{equation}\n\n\\item If $\\vec{A} = \\vec{x}$,\n\\[\n\\left(\\td{\\vec{x}}{t}\\right)_f = \\left(\\td{\\vec{x}}{t}\\right)_r + \\vec{\\Omega} \\vp \\vec{x},\n\\]\nDifferentiating once more\n\\[\n\\left(\\frac{d^2\\vec{x}}{dt^2}\\right)_f = \\left[\\frac{d}{dt}\\left(\\td{\\vec{x}}{t}\\right)_r\\right]_f + \\left(\\td{\\vec{\\Omega}}{t}\\right)_f\\vp\\vec{x} + \n\\vec{\\Omega}\\vp\\left(\\td{\\vec{x}}{t}\\right)_f \n\\]\nor\n\\[\n\\left(\\td{\\vec{x}}{t}\\right)_f = \\left(\\frac{d^2\\vec{x}}{dt^2}\\right)_r + \\vec{\\Omega}\\vp\\left(\\td{\\vec{x}}{t}\\right)_r + \\left(\\td{\\vec{\\Omega}}{t}\\right)_f \\vp \\vec{x} + \n\\vec{\\Omega}\\vp\\left[\\left(\\td{\\vec{x}}{t}\\right)_r + \\vec{\\Omega} \\vp \\vec{x}\\right] \n\\]\nor\n\\begin{equation}\\label{c3s2e3}\n\\left(\\frac{d^2\\vec{x}}{dt^2}\\right)_f = \\left(\\frac{d^2\\vec{x}}{dt^2}\\right)_r + \\left(\\td{\\vec{\\Omega}}{t}\\right)_r \\vp \\vec{x} + 2\\vec{\\Omega}\\vp\\left(\\td{\\vec{x}}{t}\\right)_r\n+ \\vec{\\Omega}\\vp(\\vec{\\Omega} \\vp \\vec{x})\n\\end{equation}\nwhere we used \\eqref{c3s2e2}.\n\n\\item The momentum density of a fluid element is $\\rho\\vec{u}$. The rate of change of this quantity is\n\\[\n\\frac{d}{dt}\\int\\rho\\vec{u}d\\tau,\n\\]\nwhich using \\eqref{c3s1e11} can be written as\n\\[\n\\int \\rho\\md{\\vec{u}}d\\tau\n\\]\nIf $\\vec{F}$ is the body force per unit volume and $\\sigma_{ij}$ is the surface force\nper unit area. then the total force is\n\\[\n\\int\\rho F_i d\\tau + \\int\\sigma_{ij}n_j dS = \\int\\rho F_i d\\tau + \\int\\pdt{\\sigma_{ij}}{x_j} d\\tau\n\\]\nBy Newton's second law, this quantity is equal to the total force acting on the fluid element, so that\n\\begin{equation}\\label{c3s2e4}\n\\int \\rho\\md{u_i}d\\tau = \\int\\rho F_i d\\tau + \\int\\pdt{\\sigma_{ij}}{x_j} d\\tau,\n\\end{equation}\nwhich, in differential form is,\n\\begin{equation}\\label{c3s2e5}\n\\rho\\md{u_i} = \\rho F_i + \\pdt{\\sigma_{ij}}{x_j},\n\\end{equation}\n\n\\item We can get an equation of motion even by considering a fixed volume $V$ of the fluid. The rate of change of momentum of fluid in $V$ is\n\\[\n\\frac{d}{dt}\\int\\rho u_i dV,\n\\]\nSince the volume of integration is fixed, we can as well write it as\n\\[\n\\int\\frac{\\partial}{\\partial t}(\\rho u_i)dV\n\\]\nThe flux of momentum through the surface $A$ of the volume is\n\\[\n-\\int\\rho u_i u_j n_j dA\n\\]\nwhile the \\enquote*{source terms} are\n\\[\n\\int\\rho F_i dV + \\int\\sigma_{ij}n_j dA\n\\]\nso that the equation of motion is\n\\begin{equation}\\label{c3s2e6}\n\\int\\frac{\\partial}{\\partial t}(\\rho u_i)dV = -\\int\\rho u_i u_j n_j dA + \\int\\rho F_i dV + \\int\\sigma_{ij}n_j dA\n\\end{equation}\nUsing divergence theorem for the last term on the right hand side,\n\\begin{equation}\\label{c3s2e7}\n\\int\\frac{\\partial}{\\partial t}(\\rho u_i)dV = -\\int\\rho u_i u_j n_j dA + \\int\\rho F_i dV + \\int\\pdt{\\sigma_{ij}}{x_j} dV\n\\end{equation}\n\n\\item If $\\vec{F}$ is a conservative force so that $\\rho\\vec{F} = -\\grad(\\rho\\Psi)$, for a potential function $\\Psi$, the second term on the right hand side of \\eqref{c3s2e6} can be\nwritten as\n\\[\n\\int\\rho F_i dV = -\\int\\pdt{\\rho\\Psi}{x_i}dV = -\\int\\rho\\Psi n_i dA\n\\]\nso that \n\\[\n\\int\\frac{\\partial}{\\partial t}(\\rho u_i)dV = -\\int\\rho u_i u_j n_j dA + \\int\\left(-\\rho\\Psi n_i + \\sigma_{ij}n_j\\right) dA\n\\]\nIf the motion is steady, the integrand on the left hand side is zero and\n\\begin{equation}\\label{c3s2e8}\n\\int\\rho u_i u_j n_j dA = \\int\\left(-\\rho\\Psi n_i + \\sigma_{ij}n_j\\right) dA\n\\end{equation}\nEquation \\eqref{c3s2e8} says that \\emph{under steady state} the convective flux of momentum out of the surface $A$ bounding $V$ is balanced by the resultant contact force exerted at\nthe boundary by the surrounding medium and the resultnt force at the boundary arising from the stress system equivalent to the body force. The loss of momemtum is exactly compensated by\nthe two forces.\n\\end{itemize}\n\n\\section{The expression for the stress tensor}\\label{c3s3}\n\\begin{itemize}\n\\item The average value of the normal component of stress on a surface element at $\\vec{x}$, over all directions of $\\un$ is\n\\[\n\\langle\\sigma\\rangle = \\frac{1}{4\\pi}\\int n_i\\sigma_{ij}n_j d\\Omega(\\un)\n\\]\nSince we are changing only the directions of the normals, staying at the same point $\\vec{x}$, we can pull out $\\sigma_{ij}$ out of the integral,\n\\[\n\\langle\\sigma\\rangle = \\frac{1}{4\\pi}\\sigma_{ij}\\int n_i n_j d\\Omega(\\un)\n\\]\nUsing \\eqref{c3sae1},\n\\begin{equation}\\label{c3s3e1}\n\\langle\\sigma\\rangle = \\frac{1}{4\\pi}\\sigma_{ij}\\frac{4\\pi}{3}\\delta_{ij} = \\frac{1}{3}\\sigma_{ii}\n\\end{equation}\n\n\\item For any tensor $\\{\\sigma_{ij}\\}$, the quantity $\\sigma_{ii}$ is an invariant under rotations. Therefore, from \\eqref{c3s3e1}, $\\langle\\sigma\\rangle$ is an invariant quantity. If\nthe fluid were static, $\\sigma_{ij} = -p\\delta_{ij}$ and hence $\\langle\\sigma\\rangle = -p$. Thus, the analog of pressure, in general flow conditions is $-\\langle\\sigma\\rangle$.\n\n\\item Taking the analogy in the reverse direction, we \\emph{define} the pressure at a point in a moving fluid as\n\\begin{equation}\\label{c3s3e2}\np = -\\frac{\\sigma_{ii}}{3}\n\\end{equation}\n\n\\item The pressure so defined is \\emph{not} the same as the thermodynamic pressure. The latter quantity is defined for equilibrium conditions while the former, being a purely mechanical\nquantity, is defined for fluids in motion. It is only when the fluid is at rest does the mechanical pressure defined by \\eqref{c3s3e2} become identical with thermodynamic pressure.\n\n\\item We write the stress tensor as a sum of an isotropic tensor and a \\enquote*{deviatoric} tensor. Thus,\n\\[\n\\sigma_{ij} = -p\\delta_{ij} + d_{ij}\n\\]\nThe deviatoric part, $d_{ij}$ is assumed to be proportional to the local velocity gradient. The most general linear relationship between the two tensors $d_{ij}$ and $\\grad\\vec{u}$ is\n\\[\nd_{ij} = A_{ijkl}\\pdt{u_k}{x_l}\n\\]\nSince we wrote\n\\[\n\\pdt{u_k}{x_l} = \\frac{1}{2}\\left(\\pdt{u_k}{x_l} + \\pdt{u_l}{x_k}\\right) + \\frac{1}{2}\\left(\\pdt{u_k}{x_l} - \\pdt{u_l}{x_k}\\right) = e_{kl} + \\xi_{kl}\n\\]\nand we further noticed that $\\xi_{kl}$ is an anti-symmetric tensor so that it can be expressed in terms of a single vector $\\vec{\\omega}$ as\n\\[\n\\xi_{kl} = -\\frac{1}{2}\\epsilon_{klm}\\omega_m\n\\]\nand hence\n\\[\nd_{ij} = A_{ijkl}e_{kl} - \\frac{1}{2}A_{ijkl}\\epsilon_{klm}\\omega_m\n\\]\nThe tensor $A_{ijkl}$ is a characteristic of the fluid alone. If the fluid is isotropic then so is $A_{ijkl}$. Now, an isotropic tensor of fourth order can be written, following \n\\eqref{mr12e18}, as\n\\[\nA_{ijkl} = \\mu\\delta_{ik}\\delta_{jl} + \\mu^\\op\\delta_{il}\\delta_{jk} + \\mu^\\tp\\delta_{ij}\\delta_{kl},\n\\]\nwhere $\\mu, \\mu^\\op$ and $\\mu^\\tp$ are scalars. Since the stress tensor is symmetric, $\\mu = \\mu^\\op$ so that\n\\[\nA_{ijkl} = \\mu(\\delta_{ik}\\delta_{jl} + \\delta_{il}\\delta_{jk}) + \\mu^\\tp\\delta_{ij}\\delta_{kl},\n\\]\nTherefore,\n\\begin{eqnarray*}\nd_{ij} &=& A_{ijkl}e_{kl} - \\frac{1}{2}A_{ijkl}\\epsilon_{klm}\\omega_m \\\\\n &=& \\mu(\\delta_{ik}\\delta_{jl} + \\delta_{il}\\delta_{jk})e_{kl} + \\mu^\\tp\\delta_{ij}\\delta_{kl}e_{kl} - \\\\\n & & \\frac{\\mu}{2}\\left(\\delta_{ik}\\delta_{jl} + \\delta_{il}\\delta_{jk}\\right)\\epsilon_{klm}\\omega_m - \\frac{\\mu^\\tp\\delta_{ij}\\delta_{kl}}{2}\\epsilon_{klm}\\omega_m \\\\\n &=& 2\\mu e_{ij} + \\mu^\\tp e_{kk} \\delta_{ij} - \\frac{\\mu}{2}(\\epsilon_{ijm} + \\epsilon_{jim})\\omega_m - \\frac{\\mu^\\tp}{2}\\delta_{ij}\\epsilon_{kkm}\\omega_m\n\\end{eqnarray*}\nNow, $\\epsilon_{ijm} + \\epsilon_{jim} = 0$ and $\\epsilon_{kkm} = 0$, so that\n\\begin{equation}\\label{c3s3e3}\nd_{ij} = 2\\mu e_{ij} + \\mu^\\tp\\Delta\\delta_{ij}\n\\end{equation}\n\n\\item Since the deviatoric tensor $d_{ij}$ does not contribute to the normal stress, $d_{ii} = 0$. From \\eqref{c2s3e3}, \n\\[\nd_{ii} = 2\\mu e_{ii} + \\mu^\\tp \\Delta \\delta_{ii} = 2\\mu\\Delta + 3\\mu^\\tp\\Delta = \\Delta(2\\mu + 3\\mu^\\tp)\n\\]\n$d_{ii} = 0$ implies \n\\[\n\\mu^\\tp = -\\frac{2}{3}\\mu,\n\\]\nso that \\eqref{c3s3e3} becomes,\n\\begin{equation}\\label{c3s3e4}\nd_{ij} = 2\\mu\\left(e_{ij} -\\frac{1}{3}\\Delta\\delta_{ij}\\right)\n\\end{equation}\n\n\\item Molecular relaxation times involving mass transport are usually of the order of $10^{-9}s$\\cite{bagchi2012molecular}. Time scale corresponding to macroscopic velocity gradient is \nreciprocal of $|\\grad\\vec{u}|$. Thus, only when $|\\grad\\vec{u}|$ is of $O(10^9)$ does molecular motion affect the continuum variables. That is the reason why the linear relationship \nbetween $d_{ij}$ and $\\grad\\vec{u}$ is valid for a very large range of gradients.\n\n\\item Using \\eqref{c3s3e4} in the expression for the stress tensor, we get\n\\begin{equation}\\label{c3s3e5}\n\\sigma_{ij} = -p\\delta_{ij} + 2\\mu\\left(e_{ij} - \\frac{1}{3}\\Delta\\delta_{ij}\\right)\n\\end{equation}\nPutting it in the equation of motion \\eqref{c3s2e5},\n\\begin{equation}\\label{c3s3e5a}\n\\rho\\md{u_i} = \\rho F_i - \\pdt{p}{x_i} + \\frac{\\partial}{\\partial x_j}\\left[2\\mu\\left(e_{ij} - \\frac{1}{3}\\Delta\\delta_{ij}\\right)\\right],\n\\end{equation}\nSince\n\\[\ne_{ij} = \\frac{1}{2}\\left(\\pdt{u_i}{x_j} + \\frac{u_j}{x_i}\\right),\n\\]\nthe divergence of rate-of-strain tensor is\n\\[\n\\frac{1}{2}\\left[\\frac{\\partial^2 u_i}{\\partial x_j \\partial x_j} + \\frac{\\partial}{\\partial x_i}\\left(\\pdt{u_j}{x_j}\\right)\\right] = \n\\frac{1}{2}\\left(\\nabla^2 u_i + \\pdt{\\Delta}{x_i}\\right)\n\\]\nTherefore, the equation of motion is\n\\begin{equation}\\label{c3s3e6}\n\\rho\\md{u_i} = \\rho F_i - \\pdt{p}{x_i} + \\mu\\left(\\nabla^2 u_i + \\frac{1}{3}\\pdt{\\Delta}{x_i}\\right)\n\\end{equation}\nThis is the Navier-Stokes equation. If the fluid is incompressible, it is simplified to\n\\[\n\\rho\\md{u_i} = \\rho F_i - \\pdt{p}{x_i} + \\mu\\nabla^2 u_i\n\\]\nand be expressed in Gibbs notation as\n\\begin{equation}\\label{c3s3e7}\n\\rho\\md{\\vec{u}} = \\rho\\vec{F} - \\grad p + \\mu\\nabla^2\\vec{u}\n\\end{equation}\n\n\\item Equation (1.3.2) of the book defined the vector $\\vec\\Sigma(\\un)$ as the force exerted by the fluid on the side of the surface element to which $\\un$ points, on the fluid on the\nside which $\\un$ points away from. Further, equation (1.3.5) of the book defined the stress tensor as $\\Sigma_j = \\sigma_{ij}n_j$. $\\sigma_{ij}$ is the $i$ component of the force per\nunit area exerted on a plane surface whose normal is in the $j$ direction. If we consider a simple shearing motion with velocity $(U(y), 0, 0)$, the only non-zero components of the\ndeviatoric stress tensor, in an incompressible fluid, are\n\\[\nd_{12} = d_{21} = \\mu\\td{U}{y}\n\\]\n$d_{12}$ is the $x$ component of the force per unit area on a plane surface element whose normal points in the positive $y$ direction. Further, it is the force exerted by the fluid on \nthe side to which the normal points on the fluid on the side which $\\un$ points away from. Therefore, if we consider an area element in the $xz$ plane, then the fluid in the upper part\n($y > 0$) exerts a force in the positive $x$ direction. Clearly, the force is in a direction to erase the velocity difference between a layer of fluid in the $xz$ plane and the one just\nabove it. This can happen only if $\\mu > 0$.\n\n\\item Consider an interface separating two media. Referring to figure (1.9.4) of the book, if $t_i$ denotes the tangent to the interface then the tangential stress in upper medium is\n$t_i\\sigma^\\tp_{ij}n_j$. Continuity of tangential stress implies\n\\begin{equation}\\label{c3s3e8}\nt_i\\sigma^\\tp_{ij}n_j = t_i\\sigma^\\op_{ij}n_j\n\\end{equation}\nUsing \\eqref{c1s7e7} for the normal components\n\\begin{equation}\\label{c3s3e9}\nn_i\\sigma^\\op_{ij}n_j - n_i\\sigma^\\tp_{ij}n_j = \\gamma\\left(\\frac{1}{R_1} + \\frac{1}{R_2}\\right)\n\\end{equation}\n\\end{itemize}\n\n\\subsection{Exercise}\n\\begin{enumerate}\n\\item Continuing to refer to figure (1.9.4) of the book, if the upper medium is a gas, then the continuity of tangential stress, given by \\eqref{c3s3e8} becomes\n\\[\n0 = t_i\\sigma^\\op_{ij}n_j\n\\]\nThus, if there is a material line element normal to the interface, then there is no tangential force acting on it. Therefore, it will continue to be in the normal direction.\n\n(Note that $\\sigma_{ij}$ is the force per unit area in the $i$ direction on a small material area element, normal to which points in the $j$ direction. Further, it is the force by the\nfluid in which the normal points, on the fluid on the side which the normal points away from. If we choose a coordinate system such that the interface lies in the $xy$ plane and the $z$\naxis points upwards then $\\sigma_{12}n_2$ is the force in the $x$ direction and $\\sigma_{12}n_1$ is the force in the $y$ direction. To get their magnitudes, we just need to take a\ndot product with a unit vector in that direction. Thus, the magnitude of the two forces in $xy$ plane are $n_1\\sigma_{12}n_2$ and $n_2\\sigma_{12}n_1$.)\n\\end{enumerate}\n\n\\section{Changes in the internal energy of a fluid in motion}\\label{c3s4}\n\\begin{itemize}\n\\item A material element of a fluid in motion is not a thermodynamic system in equilibrium. Therefore, it is not right to assign thermodynamic variables to it without close examination.\nOf the thermodynamical variables, density $\\rho$ can be defined as a local mass per unit volume even if the material element is not in equilibrium. The first law of thermodynamics is\napplicable even to systems not in equilibrium. Since the heat added to the element $\\dbar Q$ and the work done on it $\\dbar W$ are experimental quantities those can be observed, so is \ntheir sum $dU$. Therefore, even internal energy can be defined for a material element.\n\n\\item If the fluid is homogeneous, then we can use the instantenous values of $\\rho$ and $U$ to define other thermodynamic quantities. For instance, we can define $T$ using the equation \nof state. \n\n\\item Consider a fluid element of volume $\\tau$ and surface area $S$. The volume forces $F_i$ do a work on it at the rate\n\\[\n\\int u_i F_i d\\tau\n\\]\nwhile the surface forces $\\sigma_{ij}$ do work at the rate\n\\[\n\\int u_i\\sigma_{ij}n_j dS = \\int\\pdt{u_i\\sigma_{ij}}{x_j} d\\tau \n\\]\nThus, the rate at which all forces do work on the fluid is\n\\begin{eqnarray*}\n &=& \\int u_i F_i d\\tau + \\int\\pdt{u_i\\sigma_{ij}}{x_j} d\\tau \\\\\n &=& \\int u_i F_i d\\tau + \\int\\pdt{\\sigma_{ij}}{x_j}u_i d\\tau + \\int\\pdt{u_i}{x_j}\\sigma_{ij}d\\tau\n\\end{eqnarray*}\nThe second term above arises because of a variation in stress across the fluid element.It leads to change in the element's kinetic energy. The third term above arises because of a \nvariation in velocity across the fluid element. It causes the element to deform without a change in the element's kinetic energy. The work done in deformation shows as an increase in \ninternal energy of the element. The three integrals can be written as one with the integrand,\n\\[\nu_iF_i + \\pdt{\\sigma_{ij}}{x_j}u_i + \\pdt{u_i}{x_j}\\sigma_{ij} = u_i\\left(F_i + \\pdt{\\sigma_{ij}}{x_j}\\right) + \\pdt{u_i}{x_j}\\sigma_{ij}\n\\]\nUsing \\eqref{c3s2e5} the terms in the bracket can be combined to get\n\\begin{equation}\\label{c3s4e1}\n\\rho u_i\\md{u_i} + \\pdt{u_i}{x_j}\\sigma_{ij}\n\\end{equation}\nThe integrand, written above, can be interpreted as a the rate at which work is being done on a fluid element per unit volume. To get the rate per unit mass, we divide it be $\\rho$. Thus,\nthe rate at which work is done by volume and surface forces per unit mass is\n\\begin{equation}\\label{c3s4e2}\nu_i\\md{u_i} + \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} = \\frac{1}{2}\\md{(u_iu_i)} + \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j}\n\\end{equation}\nThe form on the right hand side makes it clear that the first term represents the change in kinetic energy while the second term represents the change in internal energy.\n\n\\item The rate at which heat enters a fluid element due to temperature gradient is\n\\[\n\\int k\\grad T\\cdot\\un dS = \\int\\dive(k\\grad T)d\\tau\n\\]\nThus the rate, per unit mass, of addition of heat to the element is\n\\begin{equation}\\label{c3s4e3}\n\\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\n\n\\item If $u$ is the internal energy per unit mass, then by first law of thermodynamics, the rate of its change per unit mass is\n\\begin{equation}\\label{c3s4e3a}\n\\md{u} = \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\nor\n\\[\n\\md{u} = \\frac{1}{2}\\left(\\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} + \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j}\\right) + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nWe can always interchange the indices in the second term in the bracket, it is a scalar after all, to get\n\\[\n\\md{u} = \\frac{1}{2}\\left(\\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} + \\frac{\\sigma_{ji}}{\\rho}\\pdt{u_j}{x_i}\\right) + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nBut the stress tensor is symmetric, so that\n\\[\n\\md{u} = \\frac{1}{2}\\left(\\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} + \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_j}{x_i}\\right) + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor\n\\begin{equation}\\label{c3s4e4}\n\\md{u} = \\frac{\\sigma_{ij}}{\\rho}e_{ij} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\nUsing \\eqref{c3s3e5},\n\\[\n\\md{u} = \\frac{e_{ij}}{\\rho}\\left[-p\\delta_{ij} + 2\\mu\\left(e_{ij} -\\frac{1}{3}\\Delta\\delta_{ij}\\right)\\right] + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor\n\\[\n\\md{u} = \\left[-p\\frac{e_{ii}}{\\rho} + 2\\frac{\\mu}{\\rho}\\left(e_{ij}e_{ij} -\\frac{1}{3}\\Delta e_{ii}\\right)\\right] + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nPutting $e_{ii} = \\Delta$,\n\\begin{equation}\\label{c3s4e5}\n\\md{u} = -p\\frac{\\Delta}{\\rho} + 2\\frac{\\mu}{\\rho}\\left(e_{ij}e_{ij} -\\frac{1}{3}\\Delta^2\\right) + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\n\n\\item We will now show that\n\\[\n-p\\Delta + 2\\mu\\left(e_{ij}e_{ij} - \\frac{\\Delta^2}{3}\\right) = -p\\delta_{ij}\\left(\\frac{\\Delta\\delta_{ij}}{3}\\right) + \n2\\mu\\left(e_{ij} - \\frac{\\Delta\\delta_{ij}}{3}\\right)\\left(e_{ij} - \\frac{\\Delta\\delta_{ij}}{3}\\right)\n\\]\n\\begin{eqnarray*}\n\\text{RHS} &=& -p\\delta_{ij}\\left(\\frac{\\Delta\\delta_{ij}}{3}\\right) + 2\\mu\\left(e_{ij} - \\frac{\\Delta\\delta_{ij}}{3}\\right)\\left(e_{ij} - \\frac{\\Delta\\delta_{ij}}{3}\\right) \\\\\n &=& -p\\Delta\\frac{\\delta_{ij}\\delta_{ij}}{3} + 2\\mu\\left(e_{ij}e_{ij} - 2e_{ij}\\frac{\\Delta\\delta_{ij}}{3} + \\frac{\\Delta^2\\delta_{ij}\\delta_{ij}}{9}\\right) \\\\\n &=& -p\\Delta + 2\\mu\\left(e_{ij}e_{ij} - \\frac{2}{3}\\Delta e_{ii} + \\frac{\\Delta^2}{3}\\right) \\\\\n &=& -p\\Delta + 2\\mu\\left(e_{ij}e_{ij} - \\frac{1}{3}\\Delta^2\\right) \\\\\n &=& \\text{LHS}\n\\end{eqnarray*}\n\n\\item In \\eqref{c3s4e5}, the first term on the right hand side involves only the isotropic part of stress and rate-of-strain while the second term has only the corresponding \ndeviatoric parts. Further, the second term is non-negative. It represents the heating of the element due to frictional forces. It is a quantity of interest and therefore deserves\na separate symbol\n\\begin{equation}\\label{c3s4e6}\n\\Phi = 2\\frac{\\mu}{\\rho}\\left(e_{ij}e_{ij} -\\frac{1}{3}\\Delta^2\\right)\n\\end{equation}\n\n\\item We have so far argued that the usual definitions of $\\rho$ and $U$ can be used in non-equilibrium states of the fluid element. We denote the pressure obtained from using \ninstantaneous values of $\\rho$ and $U$ in equilibrium equations of state by $p_e$. Recall that $p$, as used in the equations above, is \\emph{defined} to be the average stress at a \npoint. In general $p$ and $p_e$ are not the same when the fluid is in motion, although they are identical in a static fluid.\n\n\\item Since the difference between $p$ and $p_e$ is solely due to fluid's motion, we assume that $p - p_e$ depends only on the local velocity gradient. We further assume that the\ndependence is linear so that \n\\[\np - p_e = B_{ij}\\pdt{u_i}{x_j} = B_{ij}e_{ij} - \\frac{1}{2}B_{ij}\\epsilon_{ijk}\\omega_k\n\\]\nIf the fluid is isotropic, we can expect $B_{ij}$ to be an isotropic tensor. From section \\ref{mr12}, an isotropic sencond rank tensor is a scalar multiple of Kronecker delta. Therefore,\nlet\n\\begin{equation}\\label{c3s4e7}\nB_{ij} = -\\kappa\\delta_{ij}\n\\end{equation}\nso that\n\\begin{equation}\\label{c3s4e8}\np - p_e = -\\kappa\\Delta\n\\end{equation}\nThe constant $\\kappa$ is usually called the bulk viscosity of the fluid.\n\n\\item Since $p$ and $p_e$ are identical in a static fluid, we can surmise that $p - p_e$ is due to deviatoric part of the stress. If the fluid contracts during the motion, that is its \nlocal $\\Delta$ is negative, $p$ will be greater than $p_e$. Therefore, we can write $p - p_e = -\\kappa\\Delta$, assuming that $\\kappa > 0$. If the fluid expands during the motion, then\nits local $\\Delta$ is positive and $p$ will end up being smaller than $p_e$. Therefore, once again $p - p_e = -\\kappa\\Delta$ is a valid relation if $\\kappa > 0$. \n\n\\item We can now write the first term on the right hand side of \\eqref{c3s4e5} as\n\\begin{equation}\\label{c3s4e9}\n-p\\frac{\\Delta}{\\rho} = -p_e\\frac{\\Delta}{\\rho} + \\kappa\\frac{\\Delta^2}{\\rho}\n\\end{equation}\nThe term\n\\[\n-p_e\\frac{\\Delta}{\\rho}\n\\]\nis contribution by the reversible effects of equilibrium pressure while the term\n\\[\n\\kappa\\frac{\\Delta^2}{\\rho} \\ge 0\n\\]\nis the dissipative effect of bulk viscosity. Although the second term is usually much smaller than the first one on the right hand side of \\eqref{c3s4e9}, being a positive quantity,\nperiodic pressure variations over a long enough time can make it significant. That is why, it is important in transmission of sound waves in fluids.\n\n\\item We will now derive equation (3.4.11) of the book. Starting from \\eqref{c3s4e5} and \\eqref{c3s4e6},\n\\[\n\\md{u} = -p\\frac{\\Delta}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nFrom \\eqref{c3s4e9},\n\\[\n\\md{u} = -p_e\\frac{\\Delta}{\\rho} + \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nWe can write the mass conservation equation as\n\\[\n\\Delta = -\\frac{1}{\\rho}\\md{\\rho}\n\\]\nso that\n\\[\n\\md{u} = \\frac{p_e}{\\rho^2}\\md{\\rho} + \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor\n\\[\n\\md{u} = -p_e\\frac{D}{Dt}\\left(\\frac{1}{\\rho}\\right) + \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor, since volume per unit mass $v = 1/\\rho$,\n\\[\n\\md{u} = -p_e\\md{v} + \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor\n\\[\n\\md{u} + p_e\\md{v} = \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor\n\\begin{equation}\\label{c3s4e9a}\nT\\md{s} = \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\nwhere we have used the first part of equation (1.5.20) of the book, namely, $Tds = du + p_edv$. If we also use the second part, that is $Tds = c_pdT - \\beta v T dp_e$, we get\n\\[\nc_p\\md{T} - \\beta v T \\md{p_e} = \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nIf we were to use $\\rho$ throughout,\n\\begin{equation}\\label{c3s4e10}\nc_p\\md{T} - \\frac{\\beta T}{\\rho}\\md{p_e} = \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\n\\end{itemize}\n\n\\section{Bernoulli's theorem}\\label{c3s5}\n\\begin{itemize}\n\\item We will derive equation (3.5.1) of the book. To do so, we begin with the equation of motion \\eqref{c3s2e5}\n\\[\n\\rho\\md{u_i} = \\rho F_i + \\pdt{\\sigma_{ij}}{x_j}\n\\]\nwhich is same as\n\\[\nu_i\\md{u_i} = u_iF_i + \\frac{u_i}{\\rho}\\pdt{\\sigma_{ij}}{x_j}\n\\]\nNow,\n\\[\n\\frac{\\partial}{\\partial x_j} (u_i\\sigma_{ij}) = u_i\\pdt{\\sigma_{ij}}{x_j} + \\sigma_{ij}\\pdt{u_i}{x_j}\n\\]\nso that\n\\[\nu_i\\md{u_i} = u_iF_i + \\frac{1}{\\rho}\\pdt{(u_i\\sigma_{ij})}{x_j} - \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j}\n\\]\nor\n\\begin{equation}\\label{c3s5e1}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2}\\right) = u_iF_i + \\frac{1}{\\rho}\\pdt{(u_i\\sigma_{ij})}{x_j} - \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j}\n\\end{equation}\nFrom \\eqref{c3s4e3a}\n\\[\n\\md{u} = \\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nso that\n\\[\n-\\frac{\\sigma_{ij}}{\\rho}\\pdt{u_i}{x_j} = -\\md{u} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nPutting this in \\eqref{c3s5e1}, we get\n\\[\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2}\\right) = u_iF_i + \\frac{1}{\\rho}\\pdt{(u_i\\sigma_{ij})}{x_j} -\\md{u} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nor\n\\begin{equation}\\label{c3s5e2}\n\\frac{D}{Dt}\\left(u + \\frac{u_iu_i}{2}\\right) = u_iF_i + \\frac{1}{\\rho}\\pdt{(u_i\\sigma_{ij})}{x_j} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\n\n\\item If $\\vec{F}$ is a conservative force with a potential function $\\Psi$,\n\\[\nu_iF_i = -u_i\\pdt{\\Psi}{x_i} = -\\md{\\Psi} + \\pdt{\\Psi}{t}\n\\]\nIf $\\Psi$ is also independent of time, \n\\[\nu_iF_i = -\\md{\\Psi}\n\\]\nPutting it in \\eqref{c3s5e2}, we get\n\\begin{equation}\\label{c3s5e3}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2} + u + \\Psi\\right) = \\frac{1}{\\rho}\\pdt{(u_i\\sigma_{ij})}{x_j} + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\nFrom \\eqref{c3s3e5}\n\\[\n\\sigma_{ij} = -p\\delta_{ij} + 2\\mu\\left(e_{ij} -\\frac{1}{3}\\Delta\\delta_{ij}\\right)\n\\]\nso that\n\\[\nu_i\\sigma_{ij} = -pu_j + 2\\mu\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right)\n\\]\nand hence,\n\\begin{eqnarray*}\n\\pdt{(u_i\\sigma_{ij})}{x_j} &=& -\\pdt{(pu_j)}{x_j} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right) \\\\\n &=& -p\\pdt{u_j}{x_j} - u_j\\pdt{p}{x_j} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right) \\\\\n &=& -p\\pdt{u_j}{x_j} - \\md{p} + \\pdt{p}{t} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right)\n\\end{eqnarray*}\nand hence, from \\eqref{c3s5e3},\n\\begin{eqnarray*}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2} + u + \\Psi\\right) &=& \n\\frac{1}{\\rho}\\left[-p\\pdt{u_j}{x_j} - \\md{p} + \\pdt{p}{t} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right)\\right]\\\\\n & & + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{eqnarray*}\nUsing mass conservation equation,\n\\[\n\\pdt{u_j}{x_j} = -\\frac{1}{\\rho}\\md{\\rho}\n\\]\nso that\n\\begin{eqnarray*}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2} + u + \\Psi\\right) &=& \n\\frac{p}{\\rho^2}\\md{\\rho} - \\frac{1}{\\rho}\\md{p} + \\frac{1}{\\rho}\\left[\\pdt{p}{t} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right)\\right] \\\\\n & & + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{eqnarray*}\nNow,\n\\[\n\\frac{p}{\\rho^2}\\md{\\rho} - \\frac{1}{\\rho}\\md{p} = -p\\frac{D}{Dt}\\left(\\frac{1}{\\rho}\\right) - \\frac{1}{\\rho}\\md{p} = -\\frac{D}{Dt}\\left(\\frac{p}{\\rho}\\right),\n\\]\nso that\n\\begin{eqnarray*}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2} + u + \\Psi\\right) &=& \n-\\frac{D}{Dt}\\left(\\frac{p}{\\rho}\\right) + \\frac{1}{\\rho}\\left[\\pdt{p}{t} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right)\\right] \\\\\n & & + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{eqnarray*}\nor\n\\begin{eqnarray*}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2} + u + \\frac{p}{\\rho} + \\Psi\\right) &=& \n\\frac{1}{\\rho}\\left[\\pdt{p}{t} + 2\\mu\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right)\\right] \\\\\n & & + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{eqnarray*}\nIf the pressure is steady,\n\\begin{equation}\\label{c3s5e4}\n\\frac{D}{Dt}\\left(\\frac{u_iu_i}{2} + u + \\frac{p}{\\rho} + \\Psi\\right) = \\frac{2\\mu}{\\rho}\\frac{\\partial}{\\partial x_j}\\left(u_ie_{ij} -\\frac{\\Delta}{3} u_j\\right) +\n\\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\nIf the fluid is frictioness, $\\mu = 0$ and it is non-conducting, $k = 0$ so that\n\\begin{equation}\\label{c3s5e5}\n\\md{\\mathcal{H}} = 0,\n\\end{equation}\nwhere the function $\\mathcal{H}$ is defined as\n\\begin{equation}\\label{c3s5e6}\n\\mathcal{H} = \\frac{u_iu_i}{2} + u + \\frac{p}{\\rho} + \\Psi\n\\end{equation}\nIf we denote the speed of a fluid parcel by $q$,\n\\begin{equation}\\label{c3s5e7}\n\\mathcal{H} = \\frac{q^2}{2} + u + \\frac{p}{\\rho} + \\Psi\n\\end{equation}\n\n\\item Since $Tds = du + pdv$, $T\\grad S = \\grad u + p\\grad{v}$ or\n\\[\nT\\grad S = \\grad u + p\\grad\\left(\\frac{1}{\\rho}\\right) = \\grad u + \\grad\\left(\\frac{p}{\\rho}\\right) - \\frac{1}{\\rho}\\grad p,\n\\]\nor\n\\begin{equation}\\label{c3s5e8}\nT\\grad S + \\frac{1}{\\rho}\\grad p = \\grad\\left(u + \\frac{p}{\\rho}\\right)\n\\end{equation}\nFrom \\eqref{c3s5e7}\n\\[\n\\grad\\mathcal{H} = \\grad\\left(\\frac{q^2}{2} + \\Psi\\right) + \\grad\\left(u + \\frac{p}{\\rho}\\right)\n\\]\nFrom \\eqref{c3s5e8}, we get\n\\begin{equation}\\label{c3s5e9}\n\\grad\\mathcal{H} = T\\grad S + \\grad\\left(\\frac{q^2}{2} + \\Psi\\right) + \\frac{1}{\\rho}\\grad p\n\\end{equation}\n\n\\item For a steady flow of a frictionless fluid, the equation of motion \\eqref{c3s3e7} becomes\n\\[\n\\rho\\vec{u}\\cdot\\grad\\vec{u} = -\\rho\\grad\\Psi - \\grad p\n\\]\nSince\n\\[\n\\grad(\\vec{u}\\cdot\\vec{u}) = \\grad{q^2} = 2\\vec{u}\\cdot\\grad\\vec{u} + 2\\vec{u}\\vp\\curl\\vec{u},\n\\]\nwe have\n\\[\n\\grad\\left(\\frac{q^2}{2}\\right) = \\vec{u}\\cdot\\grad\\vec{u} + \\vec{u}\\vp\\vec{\\omega}\n\\]\nor\n\\[\n\\rho\\grad\\left(\\frac{q^2}{2}\\right) - \\rho\\vec{u}\\vp\\vec{\\omega} = -\\rho\\grad\\Psi - \\grad p\n\\]\nor\n\\[\n\\grad\\left(\\frac{q^2}{2} + \\psi\\right)  + \\frac{1}{\\rho}\\grad p = \\vec{u}\\vp\\vec{\\omega}\n\\]\nPutting this relation in \\eqref{c3s5e9}, we get\n\\begin{equation}\\label{c3s5e10}\n\\grad\\mathcal{H} = T\\grad S + \\vec{u}\\vp\\vec{\\omega}\n\\end{equation}\n\n\\item From the relation, $Tds = du + pdv$, we get\n\\[\nTds = du + pd\\left(\\frac{1}{\\rho}\\right) = du + d\\left(\\frac{p}{\\rho}\\right) - \\frac{1}{\\rho}dp\n\\]\nFor an isentropic (adiabatic) process,\n\\[\n\\frac{1}{\\rho}dp = d\\left(u + \\frac{p}{\\rho}\\right)\n\\]\nIf \n\\[\nc^2 = \\left(\\pdt{p}{\\rho}\\right)_S,\n\\]\nwe have\n\\[\ndp = c^2d\\rho\n\\]\nor\n\\[\n\\frac{1}{\\rho}dp = \\frac{c^2}{\\rho}d\\rho\n\\]\nso that\n\\[\n\\frac{c^2}{\\rho}d\\rho = d\\left(u + \\frac{p}{\\rho}\\right) \n\\]\nor\n\\begin{equation}\\label{c3s5e11}\nu + \\frac{1}{\\rho} = \\int\\frac{c^2}{\\rho}d\\rho\n\\end{equation}\nor\n\\begin{equation}\\label{c3s5e12}\n\\frac{D}{Dt}\\left(u + \\frac{1}{\\rho}\\right) = \\frac{D}{Dt}\\int\\frac{c^2}{\\rho}d\\rho\n\\end{equation}\nUsing \\eqref{c3s5e11} in the definition \\eqref{c3s5e7} we get\n\\begin{equation}\\label{c3s5e13}\n\\mathcal{H} = \\frac{q^2}{2} + \\int\\frac{c^2}{\\rho}d\\rho + \\Psi\n\\end{equation}\n\n\\item We will show that\n\\begin{equation}\\label{c3s5e14}\n-\\vec{\\Omega}\\vp(\\vec{\\Omega}\\vp\\vec{x}) = \\frac{1}{2}\\grad(\\vec{\\Omega}\\vp\\vec{x})^2\n\\end{equation}\nStarting from the right hand side,\n\\begin{equation}\\label{c3s5e15}\n\\frac{1}{2}\\grad(\\vec{\\Omega}\\vp\\vec{x})^2 = (\\vec{\\Omega}\\vp\\vec{x})\\cdot\\grad(\\vec{\\Omega}\\vp\\vec{x}) + (\\vec{\\Omega}\\vp\\vec{x})\\vp\\curl(\\vec{\\Omega}\\vp\\vec{x})\n\\end{equation}\nSince $\\vec{\\Omega}$ is a constant,\n\\[\n\\curl(\\vec{\\Omega}\\vp\\vec{x}) = \\vec{\\Omega}\\dive\\vec{x} - \\vec{\\Omega}\\cdot\\grad\\vec{x} = 3\\vec{\\Omega} - \\vec{\\Omega} = 2\\vec{\\Omega}\n\\]\nso that\n\\begin{equation}\\label{c3s5e16}\n(\\vec{\\Omega}\\vp\\vec{x})\\vp\\curl(\\vec{\\Omega}\\vp\\vec{x}) = 2(\\vec{\\Omega}\\vp\\vec{x})\\vp\\vec{\\Omega} = -2\\vec{\\Omega}\\vp(\\vec{\\Omega}\\vp\\vec{x})\n\\end{equation}\nNow consider\n\\begin{eqnarray*}\n(\\vec{\\Omega}\\vp\\vec{x})\\cdot\\grad(\\vec{\\Omega}\\vp\\vec{x}) &=& \n\\left(\\epsilon_{ijk}\\uvec{i}\\Omega_j x_k \\cdot \\uvec{l}\\frac{\\partial}{\\partial x_l}\\right)\\left(\\epsilon_{pqr}\\uvec{p}\\Omega_q x_r\\right) \\\\\n &=& \\epsilon_{ijk}\\Omega_j x_k\\frac{\\partial}{\\partial x_i}\\left(\\epsilon_{pqr}\\uvec{p}\\Omega_q x_r\\right) \\\\\n &=& \\epsilon_{ijk}\\Omega_j x_k \\epsilon_{pqr}\\uvec{p}\\Omega_q \\delta_{ir} \\\\\n &=& \\epsilon_{ijk}\\Omega_j x_k \\epsilon_{pqi}\\uvec{p}\\Omega_q \\\\\n &=& \\epsilon_{ijk}\\epsilon_{pqi} \\Omega_j\\Omega_q x_k\\uvec{p} \\\\\n &=& \\epsilon_{ijk}\\epsilon_{ipq} \\Omega_j\\Omega_q x_k\\uvec{p} \\\\\n &=& (\\delta_{jp}\\delta_{kq} - \\delta_{jq}\\delta_{kp})\\Omega_j\\Omega_q x_k\\uvec{p} \\\\\n &=& x_k\\Omega_k \\Omega_j\\uvec{j} - \\Omega_j\\Omega_j x_k\\uvec{k} \\\\\n &=& (\\vec{x}\\cdot\\vec{\\Omega})\\vec{\\Omega} - \\Omega^2\\vec{x} \n\\end{eqnarray*}\nThus,\n\\begin{equation}\\label{c3s5e17}\n(\\vec{\\Omega}\\vp\\vec{x})\\cdot\\grad(\\vec{\\Omega}\\vp\\vec{x}) = \\vec{\\Omega}\\vp(\\vec{\\Omega}\\vp\\vec{x})\n\\end{equation}\nPutting \\eqref{c3s5e16} and \\eqref{c3s5e17} on the right hand side of \\eqref{c3s5e15},\n\\[\n\\frac{1}{2}\\grad(\\vec{\\Omega}\\vp\\vec{x})^2 = -\\vec{\\Omega}\\vp(\\vec{\\Omega}\\vp\\vec{x})\n\\]\n\\end{itemize}\n\n\\section{The complete set of governing equations}\\label{c3s6}\n\\begin{itemize}\n\\item Flow of a Newtonian fluid is described by\n\\begin{enumerate}\n\\item Mass conservation, \\eqref{c2s2e1a},\n\\begin{equation}\\label{c3s6e1}\n\\frac{1}{\\rho}\\md{\\rho} + \\dive\\vec{u} = 0\n\\end{equation}\n\\item Momentum balance, \\eqref{c3s3e5a}\n\\begin{equation}\\label{c3s6e2}\n\\rho\\md{u_i} = \\rho F_i - \\pdt{p}{x_i} + \\frac{\\partial}{\\partial x_j}\\left[2\\mu\\left(e_{ij} - \\frac{1}{3}\\Delta\\delta_{ij}\\right)\\right]\n\\end{equation}\n\\item Energy balance, \\eqref{c3s4e9a} and \\eqref{c3s4e10}\n\\[\nT\\md{s} = c_p\\md{T} - \\frac{\\beta T}{\\rho}\\md{p_e} = \\kappa\\frac{\\Delta^2}{\\rho} + \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\]\nIf we ignore effects of expansion damping, we can drop the first term on the right hand side and replace $p_e$ with $p$ to get\n\\begin{equation}\\label{c3s6e3}\nT\\md{s} = c_p\\md{T} - \\frac{\\beta T}{\\rho}\\md{p} = \\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\n\\end{equation}\n\\end{enumerate}\nThe six quantities $\\rho, \\vec{u}, p$ and $T$ are the unknowns in these equations. Since these are only five equations, we need one more, namely the equation of state of the form\n\\begin{equation}\\label{c3s6e4}\nf(p, \\rho, T) = 0\n\\end{equation}\nto be able to solve for all the unknowns. The material parameters $\\mu$ and $k$ are given functions of $\\rho$ and $T$.\n\\end{itemize}\n\n\\subsection{Isentropic flows}\n\\begin{itemize}\n\\item Recall that an isentropic flow is the one for which entropy of a fluid element does not change throughout the course of its motion while a homentropic flow is the one for which \nentropy per unit mass $s$ is same throughout the fluid.\n\n\\item If we set the molecular transport coefficients, $\\mu$ and $k$ to zero, equation \\eqref{c3s6e3} gives,\n\\begin{equation}\\label{c3s6e5}\nc_p\\md{T} - \\frac{\\beta T}{\\rho}\\md{p}\n\\end{equation}\nSolving this equation gives $T$ as a function of $p$. Coupled with the equation of state, $f(p, \\rho, T) = 0$ gives $\\rho$ as a function of $p$. Now \n\\[\n\\md{s} = 0\n\\]\nimplies that $s$ is a constant. To indicate that $\\rho$ is a function of $p$ at constant entropy, we write\n\\begin{equation}\\label{c3s6e6}\n\\rho = \\rho(p, s)\n\\end{equation}\nIf the flow were homentropic, we would have written $\\rho = \\rho(p)$. For an isentropic flow, at a fixed entropy of a fluid element, \\eqref{c3s6e6} gives\n\\begin{eqnarray*}\n\\pdt{\\rho}{t} &=& \\pdt{\\rho}{p}\\pdt{p}{t} \\\\\n\\grad{\\rho} &=& \\pdt{\\rho}{p}\\grad p\n\\end{eqnarray*}\ntherefore,\n\\begin{equation}\\label{c3s6e7}\n\\md{\\rho} = \\pdt{\\rho}{p}\\md{p}\n\\end{equation}\nand hence equation \\eqref{c3s6e1} for mass conservation becomes\n\\begin{equation}\\label{c3s6e8}\n\\frac{1}{\\rho c^2}\\md{p} + \\dive\\vec{u} = 0\n\\end{equation}\nwhere we have used the relation\n\\begin{equation}\\label{c3s6e9}\nc^2 = \\left(\\pdt{p}{\\rho}\\right)_s\n\\end{equation}\nPutting $\\mu = 0$ also simplifies the momentum balance equation \\eqref{c3s6e2} to\n\\begin{equation}\\label{c3s6e10}\n\\rho\\md{\\vec{u}} = \\rho\\vec{F} - \\grad p\n\\end{equation}\n\n\\item Consider a fluid element at rest. Under the equilibrium condition, the pressure gradient and the body force balance each other so that $\\rho_0\\vec{F} = \\grad p_0$, where the \nsubscript $0$ indicates equilibrium values. Now let the fluid be slightly perturbed so that the pressure becomes $p = p_0 + p_1$ and as a result the density becomes $\\rho = \\rho_0 +\n\\rho_1$. Here, the subscript $1$ indicates the perturbed values. Now,\n\\[\n\\frac{1}{\\rho} = \\frac{1}{\\rho_0 + \\rho_1} = \\frac{1}{\\rho_0}\\left(\\frac{1}{1 + \\rho_1/\\rho_0}\\right) = \\frac{1}{\\rho_0}\\left(1 - \\frac{\\rho_1}{\\rho_0}\\right),\n\\]\nup to first order in $\\rho_1$. Further,\n\\[\n\\md{p} = \\md{p_0} + \\md{p_1},\n\\]\nso that\n\\[\n\\frac{1}{\\rho c^2}\\md{p} = \\frac{1}{\\rho_0 c^2}\\left(1 - \\frac{\\rho_1}{\\rho_0}\\right)\\left(\\md{p_0} + \\md{p_1}\\right)\n= \\frac{1}{\\rho_0 c^2}\\left(\\md{p_0} + \\md{p_1} - \\frac{\\rho_1}{\\rho_0}\\md{p_0}\\right),\n\\]\nup to first order terms in perturbed quantities. Under equilibrium conditions, \n\\[\n\\md{p_0} = \\pdt{p_0}{t} = 0,\n\\]\nbecause the equilibrium velocity $\\vec{u}_0 = 0$. Therefore,\n\\[\n\\frac{1}{\\rho c^2}\\md{p} = \\frac{1}{\\rho_0 c^2}\\md{p_1} = \\frac{1}{\\rho_0 c^2}\\pdt{p_1}{t}\n\\]\nSimilarly, $\\dive\\vec{u} = \\dive\\vec{u}_0 + \\dive\\vec{u}_1 = \\dive\\vec{u}_1$ so that the equation of mass conservation \\eqref{c3s6e8} becomes,\n\\begin{equation}\\label{c3s6e11}\n\\frac{1}{\\rho_0 c^2}\\pdt{p_1}{t} + \\dive\\vec{u}_1 = 0\n\\end{equation}\nNow,\n\\begin{eqnarray*}\n\\md{\\vec{u}} &=& \\md{\\vec{u}_0} + \\md{\\vec{u}_1} \\\\\n &=& \\md{\\vec{u}_1} \\\\ \n &=& \\pdt{\\vec{u_1}}{t} + \\vec{u}\\cdot\\grad{\\vec{u_1}} \\\\\n &=& \\pdt{\\vec{u}_1}{t},\n\\end{eqnarray*}\nup to first order terms in $\\vec{u}_1$. Therefore, the momentum balance equation \\eqref{c3s6e10} becomes\n\\[\n\\left(\\rho_0 + \\rho_1\\right)\\pdt{\\vec{u}_1}{t} = (\\rho_0 + \\rho_1)\\vec{F} - \\grad p_0 - \\grad p_1\n\\]\nor\n\\begin{equation}\\label{c3s6e12}\n\\rho_0\\pdt{\\vec{u}_1}{t} = \\rho_1\\vec{F} - \\grad p_1\n\\end{equation}\nwhere we used the equilibrium condition $\\rho_0\\vec{F} = \\grad p_0$. Differentiating \\eqref{c3s6e11} with respect to $t$ and substituting \\eqref{c3s6e12} in the result gives\n\\[\n\\frac{1}{c^2}\\pdt{p_1}{t} = \\nabla^2 p_1 - \\dive(\\rho_1\\vec{F})\n\\]\nNow,\n\\[\n\\dive(\\rho_1\\vec{F}) = \\rho_1\\dive\\vec{F} + \\vec{F}\\cdot\\grad\\rho_1 = \\rho_1\\dive\\vec{F} + \\vec{F}\\cdot\\left(\\pdt{\\rho_1}{p_1}\\grad p_1\\right) = \n\\rho_1\\dive\\vec{F} + \\frac{\\vec{F}\\cdot\\grad p_1}{c^2}\n\\]\nso that\n\\begin{equation}\\label{c3s6e13}\n\\frac{1}{c^2}\\pdt{p_1}{t} = \\nabla^2 p_1 - \\rho_1\\dive\\vec{F} - \\frac{\\vec{F}\\cdot\\grad p_1}{c^2}\n\\end{equation}\nIf the only external field is gravity, $\\vec{F} = \\vec{g}$ so that $\\dive{\\vec{g}} = 0$ and hence,\n\\[\n\\frac{1}{c^2}\\pdt{p_1}{t} = \\nabla^2 p_1 - \\frac{\\vec{g}\\cdot\\grad p_1}{c^2}\n\\]\nFor air under normal pressure, the velocity of sound $c \\approx 330$ $ms^{-1}$ and hence $g/c^2 \\approx 9 \\times 10^{-5}$. Thus, the second term on the right hand side is negligibly\nsmall and \n\\begin{equation}\\label{c3e6e14}\n\\frac{1}{c^2}\\pdt{p_1}{t} = \\nabla^2 p_1\n\\end{equation}\nwhich is the equation of sound waves in fluids.\n\\end{itemize}\n\n\\section{Incompressible flows}\\label{c3s7}\n\\begin{itemize}\n\\item Let the velocity $\\vec{u}$ be such that it varies appreciably only over distances comparable to $L$. In other words, variation in $\\vec{u}$ over distances small compared to $L$ is\nnegligible. Further, let the variation of $\\vec{u}$ in space or time be of a magnitude comparable to $U$. Then, the velocity field is approximately solenoidal if\n\\[\n|\\dive\\vec{u}| \\ll \\frac{U}{L}\n\\]\nor if\n\\begin{equation}\\label{c3s7e1}\n\\Big|\\frac{1}{\\rho}\\md{\\rho}\\Big| \\ll \\frac{U}{L}\n\\end{equation}\n\n\\item If we choose $\\rho$ and $s$ as independent variables, then we can express $p = p(\\rho, s)$. In that case,\n\\[\ndp = \\pdt{p}{\\rho}d\\rho + \\pdt{p}{s}ds\n\\]\nand hence\n\\[\n\\md{p} = \\pdt{p}{\\rho}\\md{\\rho} + \\pdt{p}{s}\\md{s}\n\\]\nor, writing in the usual thermodynamic convention,\n\\begin{equation}\\label{c3s7e2}\n\\md{p} = c^2\\md{\\rho} + \\left(\\pdt{p}{s}\\right)_\\rho\\md{s}\n\\end{equation}\nUsing this equation, we can write\n\\[\n\\md{\\rho} = \\frac{1}{c^2}\\md{p} - \\frac{1}{c^2}\\left(\\pdt{p}{s}\\right)_\\rho\\md{s}\n\\]\nand hence the condition for incompressibility \\eqref{c3e6e14} can be written as\n\\begin{equation}\\label{c3s7e3}\n\\Big|\\frac{1}{\\rho c^2}\\md{p} - \\frac{1}{\\rho c^2}\\left(\\pdt{p}{s}\\right)_\\rho\\md{s}\\Big| \\ll \\frac{U}{L}\n\\end{equation}\nThis relation is valid if each of the two terms on the left hand side have a magnitude small when compared with $U/L$. We will examine the two terms separately.\n\n\\item For the moment, assume that the flow is isentropic, in which case, the equation of motion \\eqref{c3s6e10} can be written as\n\\[\n\\grad p = \\rho\\vec{F} - \\rho\\md{\\vec{u}}\n\\]\nso that\n\\[\n\\vec{u}\\cdot\\grad p = \\rho\\vec{u}\\cdot\\vec{F} - \\rho\\vec{u}\\cdot\\md{\\vec{u}} = \\rho\\vec{u}\\cdot\\vec{F} - \\rho\\frac{D}{Dt}\\left(\\frac{q^2}{2}\\right)\n\\]\nand\n\\[\n\\md{p} = \\pdt{p}{t} + \\vec{u}\\cdot\\grad p = \\pdt{p}{t} + \\rho\\vec{u}\\cdot\\vec{F} - \\rho\\frac{D}{Dt}\\left(\\frac{q^2}{2}\\right)\n\\]\ndue to which the first term on the left hand side of \\eqref{c3s7e3} becomes\n\\[\n\\frac{1}{\\rho c^2}\\md{p} = \\frac{1}{\\rho c^2}\\pdt{p}{t} + \\frac{1}{c^2}\\vec{u}\\cdot\\vec{F} - \\frac{1}{c^2}\\frac{D}{Dt}\\left(\\frac{q^2}{2}\\right)\n\\]\nand its smallness means\n\\begin{equation}\\label{c3s7e4}\n\\Big|\\frac{1}{\\rho c^2}\\pdt{p}{t} + \\frac{\\vec{u}\\cdot\\vec{F}}{c^2} - \\frac{1}{2c^2}\\md{q^2} \\Big| \\ll \\frac{U}{L}\n\\end{equation}\n\\begin{enumerate}\n\\item Smallness of \n\\[\n\\Big|\\frac{1}{2c^2}\\md{q^2} \\Big|\n\\]\nmeans that the ratio\n\\[\n\\frac{U^2}{c^2} \\ll 1 \\Rightarrow \\frac{U}{c} \\ll 1\n\\]\nThe dimensionless quantity $U/c$ is called Mach number. If the Mach number of a flow is very small, then other terms on the left hand side of \\eqref{c3s7e1} and \\eqref{c3s7e2} also\nbeing small, the fluid can be considered effectively incompressible.\n\n\\item Dimension of pressure is same as $\\rho q^2$. If $U$ is the typical variation in velocity, $L$ is the typical length scale and $n$ the dominant frequency, $Ln$ too has dimensions\nof velocity and $ULn$ has dimensions of $q^2$. Thus the pressure change is of the order of $\\rho UL n$ and rate of change of pressure is of the order of $\\rho UL n^2$. Therefore,\n\\[\n\\Big|\\frac{1}{\\rho c^2}\\pdt{p}{t}\\Big| \\ll \\frac{U}{L} \\Rightarrow \\Big|\\frac{1}{\\rho c^2}\\rho UL n^2 \\Big| \\ll \\frac{U}{L}\n\\]\nwhich is same as\n\\begin{equation}\\label{c3s7e5}\n\\frac{L^2n^2}{c^2} \\ll 1\n\\end{equation}\nThis condition will be obviously violated if $L$ is of the order of the wavelength of a sound wave and $n$ is of the order of its frequency. Thus, compressibility cannot be ignored if\nthe flow is caused due to passage of sound.\n\n\\item Smallness of\n\\[\n\\Big|\\frac{\\vec{u}\\cdot\\vec{F}}{c^2}\\Big| \\ll \\frac{U}{L}\n\\]\nin the case of gravitational fields means\n\\[\n\\frac{gL}{c^2} \\ll 1\n\\]\nNow for air, $c^2 = \\gamma p/\\rho$ (refer to \\href{https://en.wikipedia.org/wiki/Speed_of_sound#Speed_of_sound_in_ideal_gases_and_air}{Wikipedia}) so that the smallness of the second \nterm on the left hand side of \\eqref{c3s7e2} is equivalent to\n\\[\n\\frac{\\rho g L}{\\gamma p} \\ll 1,\n\\]\nwhere $\\gamma$ is the adiabatic ratio. For air, \n\\[\n\\frac{p}{\\rho g} \\approx 8 \\text{ km }\n\\]\n(refer to p. 20 of the book) so that the relation\n\\[\n\\frac{\\rho g L}{\\gamma p} \\ll 1,\n\\]\nis valid for if $L$ is much lesser than $\\gamma \\time 8 = 11.2$ kilometer, which means always at the scale of the lab.\n\\end{enumerate}\n\n\\item We will now consider the term\n\\[\nT_2 = \\Big|\\frac{1}{\\rho c^2}\\left(\\pdt{p}{s}\\right)_\\rho\\md{s}\\Big| \n\\]\nFrom (3.6.19),\n\\[\n\\frac{1}{\\rho c^2}\\left(\\pdt{p}{s}\\right)_\\rho = \\frac{\\beta T}{c_p}\n\\]\nso that \n\\[\nT_2 = \\Big|\\frac{\\beta T}{c_p}\\md{s}\\Big| = \\Big|\\frac{\\beta}{c_p}T\\md{s}\\Big|\n\\]\nFrom \\eqref{c3s6e3},\n\\[\nT_2 = \\Big|\\frac{\\beta}{c_p}\\left[\\Phi + \\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right)\\right]\\Big|\n\\]\nNow,\n\\[\n\\frac{\\beta}{c_p}\\Phi = \\frac{\\beta}{c_p}\\frac{\\mu}{\\rho}\\frac{U^2}{L^2}\n\\]\nand\n\\[\n\\frac{\\beta}{c_p}\\frac{1}{\\rho}\\frac{\\partial}{\\partial x_i}\\left(k\\pdt{T}{x_i}\\right) = \\beta\\frac{k}{\\rho c_p}\\frac{\\theta}{L^2}\n\\]\nThus $T_2 \\ll U/L$ is possible is\n\\begin{eqnarray}\n\\frac{\\beta U}{c_p}\\frac{\\mu}{\\rho L} &\\ll& 1 \\label{c3s7e7} \\\\\n\\frac{\\beta\\theta\\kappa}{LU} &\\ll& 1 \\label{c3s7e8},\n\\end{eqnarray}\nwhere\n\\[\n\\kappa = \\frac{k}{\\rho c_p}\n\\]\nis the thermometric conductivity.\n\\end{itemize}", "meta": {"hexsha": "2f39df0edaad480f8ab21dbf01541a79c9930768", "size": 54943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "gkb/chap3.tex", "max_stars_repo_name": "amey-joshi/physics", "max_stars_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gkb/chap3.tex", "max_issues_repo_name": "amey-joshi/physics", "max_issues_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gkb/chap3.tex", "max_forks_repo_name": "amey-joshi/physics", "max_forks_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3654008439, "max_line_length": 188, "alphanum_fraction": 0.6691844275, "num_tokens": 21530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246077301781, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6672363445960241}}
{"text": "\\input{../../UCLHeader.tex}\n\\input{../../UCLCommands.tex}\n\\begin{document}\n\\title{Error Correction Lecture 2 }\n\\author{with Dan Browne}\n\\maketitle\n\\tableofcontents\n\n\\section{Correcting Errors of the Shor Code}\nRecall that the concatenated Shor code has the following initialisation circuit. \n\n\\begin{figure}[!ht]\n  \\caption{Shor code initialisation diagram.}\n  \\centering\n    \\includegraphics[width=\\textwidth]{Shor_Code_Initialisation.jpg}\n\\end{figure}\n\nFor an error represented by the operator\n\\beq\nX_1 = XII III III\n\\eeq\nwe get\n\\beq\nX_1 \\ket{0}_L = \\left( \\ket{100} + \\ket{011} \\right) \\left( \\ket{000} + \\ket{111} \\right)^{\\otimes 2}\n\\eeq\n\\beq\nX_1 \\ket{1}_L = \\left( \\ket{100} - \\ket{011} \\right) \\left( \\ket{000} - \\ket{111} \\right)^{\\otimes 2}\n\\eeq\nThis error is detected by the $Z_1$ and $Z_2$ parity measurements. In fact, we can write down the following table for error corrections, \n\\begin{tabular}{ccc}\n$Z_1Z_2$ & $Z_4Z_5$ & $Z_7Z_8$ \\\\\n$Z_2 Z_3$ & $Z_5 Z_6 $ & $Z_8 Z_9$ \\\\\n$(Z_3Z_1)$ & $(Z_4Z_6)$ & $(Z_7 Z_9)$\n\\end{tabular}\nWe have written the last row in brackets because just as before, it can be constructed from the other two rows and is thus superfluous. Note however that we cannot correct for two bitflip errors. The correction would introduce a factor of $-1$ on the $\\ket{1}_L$ state. \n\nHowever, we know that the operator $X_1 X_2 X_3 = \\bar{Z}$. This error is undetectable. As a consequence, we cannot detect any errors that happen on adjacent bits. \n\nIn general, we want\n\\beq\n\\mbox{error} \\cdot \\mbox{error correction} = \\identity\n\\eeq\n\n\\section{Phase errors}\nLet us introduce the error $Z_1$. It has the following effect:\n\\beq\nZ_1 \\ket{0}_L = \\left( \\ket{000} - \\ket{111} \\right) \\left( \\ket{000} + \\ket{111} \\right)^{\\otimes 2}\n\\eeq\n\\beq\nZ_1 \\ket{1}_L = \\left( \\ket{000} + \\ket{111} \\right) \\left( \\ket{000} - \\ket{111} \\right)^{\\otimes 2}\n\\eeq\nWe can detect this error with the operator $XXXIIIIII$. It has the following effect:\n\\beq\nXXX \\left( \\ket{000} \\pm \\ket{111} \\right) = \\pm \\left( \\ket{000} \\pm \\ket{111} \\right)\n\\eeq\nwhich enables us to see where the error has introduced a sign error. We get a negative eigenvalue for the error $XXX = \\bar{Z}$. But there is a problem. Since this error is a logical operator, its detection would allow us to distinguish between $\\ket{0}_L$ and $\\ket{1}_L$. We can't allow this, since it would collapse any superposition. So instead, we measure $X_1 X_2 X_3 X_4 X_5 X_6$. That is, measure two out of three registers. This will check the parity between the first three and the middle three states. So we get the error detection measurements\n\\begin{tabular}{c}\n$X_1 X_2 X_3 X_4 X_5 X_6$ \\\\\n$X_1 X_2 X_3 X_7X_8 X_9$ \\\\\n$(X_4 X_5 X_6 X_7 X_8 X_9)$\n\\end{tabular}\nThis can detect a single $Z$ error on every single qubit. We find the following syndrome table, using the three measurements above\n\\begin{tabular} {ccc}\n$Z_1$ & $Z_2$ $Z_3$ \\\\ \\hline\n-- & -- & -- \\\\\n-- & -- & -- \\\\\n+ & + & + \n\\end{tabular}\nBut notice that the syndrome looks the same for all three measurements! This means that we cannot distinguish between them. Say we detect $Z_2$, but we then implement the correction $Z_1$. Notice, however that the two commute. So we have\n\\beq\nZ_2 \\cdot Z_1 \\ket{0}_L = \\ket{0}_L\n\\eeq\n\\beq\nZ_2\\cdot Z_1 \\ket{1}_L = \\ket{1}_L\n\\eeq\nSo it works! This is the same as for the error detection operators for single bitflip errors. \n\nThis phenomenon is called \\textbf{degeneracy}. We have both non-degenerate and degenerate code. \n\nA non-degenerate code means that every possible correctable error has a unique syndrome. This is the case for all classical codes. \n\nIt is, understandably, easier to prove things for non-degenerate codes. Thus, some quantum questions are still completely open systems. \n\n\\section{Slight Generalisation}\nWe shall here look at the properties of Pauli operators and their tensor products. We shall use them extensively throughout the course, \nand most likely all of their properties. \n\nThe Pauli operators are $I, X, Y, Z$. We include the identity $I$ since some of the properties include it. \n\nThe Pauli operators have the following operators. \n\\begin{itemize}\n\\item \\textbf{All unitary} we find that for every Pauli operator, \n\\beq\nU^{-1} = U^\\dagger = U\n\\eeq\n\\item \\textbf{All Hermitian} we find\n\\beq\nU^\\dagger = U\n\\eeq\n\\item  \\textbf{All are self-inverse} that is, \n\\beq\nU = U^{-1}\n\\eeq\n\\item \\textbf{Recursive property} we can write\n\\beq\nY = i XZ\n\\eeq\nThen, \n\\beq\nY \\ket{\\psi} = i XZ \\ket{\\psi}\n\\eeq\nso that a $Y$-error can be written in terms of a bitflip and phase error. The $i$ is a global phase which we can ignore. \n\\item \\textbf{Commute or anti-commute} All Pauli matrices anti commute. That is\n\\beq\n\\{U_i, U_j\\} = 0 \\mbox{ if } i \\neq j\n\\eeq\n\\item \\textbf{All are traceless} except for $I$. \n\\item \\textbf{Tensor products of Pauli matrices commute} we find that \n\\beq\n[X\\otimes X, Z \\otimes Z] = 0\n\\eeq\n\n\\end{itemize}\nThe last property means that we can always correct for a combination of errors. It means that the following statements are equivalent:\n\\beq \nX_E Z_E X_C Z_C\n\\eeq\n\\beq\nX_E X_C Z_E Z_C\n\\eeq\nwhere $E$ stands for error and $C$ stands for correction. That is, it doesn't matter in which order we detect and correct the errors since all the operators anti-commute, which just introduces a global phase. \n\n\\section{Arbitrary errors}\nClaim: We can correct for arbitrary, unitary errors. Any operator which is a tensor product of Paulis can be written $O_XO_Z$ where $O_X$ contains $X$ and $I$, and $O_Z$ contains $Z$ and $I$. \nFor example, we can derive all possible $Y$ errors, \n\\beq\nYZIX = i(XIIX)(ZZII)\n\\eeq\nIn fact, the Pauli operators form a basis for $2^N \\times 2^N$ matrices that live in $\\mathbb{C}^{2^N\\times 2^N}$. Any $2\\times2$ matrix can be written as\n\\beq\nO = a I + bX + cY + dZ\n\\eeq\nTo check whether they actually form a basis, we can make use the Hilbert-Schmidt inner product. \n\\beq\n\\braket{A,B} = \\trace{AB}\n\\eeq\nwhich can be thought of as an orthogonality condition but for matrices. If you find a set of $D$ operators with zero Hilbert-Schmidt product where $D$ is also the dimension of the space where they live, you have a basis. \n\n\\section{Measuring Pauli's}\nWe can device a circuit for measuring the Pauli operators. For a number of $n$ qubits, we can imagine a projector\n\\beq\nP = P_1 \\otimes P_2 \\otimes P_3 \\otimes \\ldots \\otimes P_n\n\\eeq\nThis circuit would simply look like projectors acting on the individual qubits. \n\nWe know that all eigenvalues of $X,Y,Z$ are $\\pm 1$. If we have\n\\beq\nP \\ket{\\psi} = \\ket{\\psi}\n\\eeq\nwe measure a $+1$, and if we have\n\\beq\nP\\ket{\\psi} = - \\ket{\\psi}\n\\eeq\nwe measure $-1$. \n\n\\end{document}", "meta": {"hexsha": "d0353803b87a657f1dffe1774643f22c30a426fb", "size": 6664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Error Correction Lecture 24 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 24 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 24 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": 40.1445783133, "max_line_length": 555, "alphanum_fraction": 0.7207382953, "num_tokens": 2215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6672363369589986}}
{"text": "\n\\subsection{Treatment data}\n\n\\subsubsection{Recap}\n\nWith multilevel data with fixed coefficients we have:\n\n\\(y_{ij}=\\mathbf x_{ij}\\theta +m_j + \\epsilon_{ij}\\)\n\nWe can estimate \\(m_j\\) using fixed effects or similar methods.\n\n\\subsubsection{Treatment data}\n\nIf the data is grouped by whether an entity was treated then will have:\n\n\\begin{itemize}\n\\item \\(y_{i0}\\) - the outcome if the entity was not treated\n\\item \\(y_{i1}\\) - the outcome if the entity was treated\n\\end{itemize}\n\nHowever we only observe \\(y_i\\) and \\(D_i\\).\n\n\\(y_i=y_{i0}+D_i(y_{i1}-y_{10})\\)\n\n", "meta": {"hexsha": "f75ddc2d383f79d43749849c94e232a15fef7611", "size": 562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treatmentHomo/01-01-intro.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treatmentHomo/01-01-intro.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treatmentHomo/01-01-intro.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.48, "max_line_length": 71, "alphanum_fraction": 0.7117437722, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6671493579939769}}
{"text": "\\section{Appendix}\nIn the body of the text, we explain in detail how the scientific understanding of the geological processes that generated the data led to the development of the statistical model. Here in the appendix, we define the statistical models directly without the scientific motivation for clarity of model definition. \n\n\\subsection{Top-down mixing model}\n\nIn the top-down mixing model, observations are made on both the child sediments and parent sediments. The $n_y$ observed age measurements for the child sediment are given by the vector $\\mathbf{y} = (y_1, \\ldots, y_{n_y})'$ and are reported with an observed analytic measurement standard deviation $\\boldsymbol{\\sigma}_y = (\\sigma_{y1}, \\ldots, \\sigma_{yn_y})'$ associated with each observation. Assuming a normal distribution for the measurement process, the latent true ages are defined as $\\tilde{\\mathbf{y}} = (\\tilde{y}_1, \\ldots, \\tilde{y}_{n_y})'$ and are modeled by \n\\begin{align*}\n\\mathbf{y} | \\tilde{\\mathbf{y}}, \\boldsymbol{\\sigma}_y^2 & \\sim \\operatorname{N} (\\mathbf{y} | \\tilde{\\mathbf{y}}, \\operatorname{diag} ( \\boldsymbol{\\sigma}_y^2 ) ), \n\\end{align*}\nwhere $N(\\mathbf{x} | \\boldsymbol{\\mu}, \\boldsymbol{\\Sigma})$ is a multivariate normal distribution with data vector $\\mathbf{x}$, mean vector $\\boldsymbol{\\mu}$, and covariance matrix $\\boldsymbol{\\Sigma}$. The notation $\\operatorname{diag} (\\boldsymbol{\\sigma^2})$ represents a diagonal covariance matrix with $i,i$th element $\\sigma^2_i$ and off diagonal elements all equal to 0. \n\nLikewise, the $b = 1, \\ldots, B$ parent observations are each comprised of $n_b$ observations and are given by the vector $\\mathbf{z}_b = (z_{b1}, \\ldots z_{bn_b})'$  and are reported with an observed analytic measurement standard deviation $\\boldsymbol{\\sigma}_b = (\\sigma_{b1}, \\ldots, \\sigma_{bn_b})'$ associated with each observation. Assuming a normal distribution for the measurement process, the latent true ages are defined as $\\tilde{\\mathbf{z}}_b = (\\tilde{z}_{b1}, \\ldots, \\tilde{z}_{bn_b})'$ and are modeled by \n\\begin{align*}\n\\mathbf{z}_b | \\tilde{\\mathbf{z}}_b, \\boldsymbol{\\sigma}_{b}^2 & \\sim \\operatorname{N} (\\mathbf{z}_b | \\tilde{\\mathbf{z}}_b, \\operatorname{diag} ( \\boldsymbol{\\sigma}_{b}^2 ) )\n\\end{align*}\n\nThe latent parent age distributions for the $b = 1, \\ldots, B$ parents are modeled using a finite mixture of $K$ Gaussian distributions \n\\begin{align*}\n\\tilde{\\mathbf{z}}_b | \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\boldsymbol{p}_{b} & \\sim \\prod_{i=1}^{n_b} \\sum_{k=1}^K p_{bk} \\operatorname{N} \\left( \\tilde{z}_{ib} \\middle| \\mu_{k}, \\sigma^2_{k} \\right) \n\\end{align*}\nwhere $\\boldsymbol{\\mu} = (\\mu_1, \\ldots, \\mu_K)'$ and $\\boldsymbol{\\sigma}^2 = (\\sigma^2_1, \\ldots, \\sigma^2_K)'$ are the mean and variance of the mixture distributions (which are shared across each of the parents) and $\\mathbf{p}_{b} = (p_{b1}, \\ldots, p_{bK})'$ are mixture weights where for $k = 1, \\ldots, K,$ $p_{bk} > 0$ and $\\sum_{k=1}^K p_{bk} = 1$. For $k = 1, \\ldots, K$, the mixture distribution means are assigned independent, vague priors $N(\\mu_\\mu = 150 \\mbox{ Myr}, \\sigma^2_\\mu = 150^2 \\mbox{ Myr}^2)$ where Myr represents a million years. To ensure the mixing distributions are relatively concentrated with respect to geologic time, the mixing kernel standard deviations are assigned independent truncated half-Cauchy priors $\\sigma_k \\sim \\operatorname{Cauchy}^+(0, 25 \\mbox{ Myr})I\\{0 < \\sigma_k < 50 \\mbox{ Myr}\\}$, which enforces the mixing distribution scales (which represent geologic mineral formation events) to be small relative to the range of dates from about 0 to 300 Myr.\n\nFor each parent $b = 1, \\ldots, B$, the mixing probabilities $\\mathbf{p}_b$ are modeled by introducing $k = 1, \\ldots, K-1$ independent and identically distributed random variables $\\tilde{p}_{bk} \\sim Beta(1, \\alpha_b)$ random variables and transforming the $\\tilde{p}_{bk}$s by \n\\begin{align*}\np_{b k} & = \\begin{cases}\n\\tilde{p}_{b1} & \\mbox{for } k = 1,\\\\\n \\tilde{p}_{bk} \\prod_{s=1}^{k-1} (1 - \\tilde{p}_{bs}) & \\mbox{for } k=2, \\ldots, K-1, \\\\ \n\\prod_{s=1}^{k-1} (1 - p_{bs}) & \\mbox{for } k = K.\n\\end{cases}\n\\end{align*}\nwhich induces a finite approximation to the stick-breaking representation of a Dirichlet process so long as $K$ is chosen large enough (Section 3 \\citet{ishwaran2001gibbs} and \\citet{ishwaran2002exact}). For $b = 1, \\ldots, B$, $\\alpha_b$ is assigned a $gamma(1, 1)$ prior and the vector $\\boldsymbol{\\alpha} = (\\alpha_1, \\ldots, \\alpha_B)'$.\n\nCombining the parent distributions, the unobserved, latent ages are modeled using the finite mixture of mixtures\n\n\\begin{align*}\n\\tilde{\\mathbf{y}} | \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\{\\boldsymbol{p}_b \\}_{b=1}^B, \\boldsymbol{\\phi} & \\sim \\prod_{i=1}^{n_y} \\sum_{b=1}^B \\phi_b \\sum_{k=1}^K p_{bk} \\operatorname{N} \\left( \\tilde{y}_i \\middle| \\mu_{b}, \\sigma_{b}^2 \\right),\n\\end{align*}\nwhere the notation $\\{\\mathbf{p}_b\\}_{b=1}^{B}$ denotes the set of parameters $\\{ \\mathbf{p}_1, \\ldots, \\mathbf{p}_B\\}$. The parameter $\\boldsymbol{\\phi} = (\\phi_1, \\ldots, \\phi_B)'$ models the proportion of the child sediment $\\phi_b$ that comes from parent $b$ where $\\phi_b > 0$ and $\\sum_{b=1}^B \\phi_b = 1$. The mixing proportion $\\boldsymbol{\\phi}$ is a assigned a $Dirichlet(\\alpha_\\phi \\mathbf{1})$ prior where $\\mathbf{1}$ is a vector of ones of length $B$ and $\\alpha_\\phi$ is assigned a $gamma(1, 1)$ prior. \n\nAll combined, the top-down mixing model posterior is\n\n\\begin{align*}\n& \\left[ \\mathbf{\\tilde{y}}, \\{ \\mathbf{\\tilde{z}}_b \\}_{b=1}^B, \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\{ \\boldsymbol{p}_b \\}_{b=1}^B, \\boldsymbol{\\phi}, \\alpha_\\phi, \\boldsymbol{\\alpha} \\middle| \\mathbf{y}, \\boldsymbol{\\sigma}_y^2, \\{ \\mathbf{z}_b\\}_{b=1}^B, \\{\\boldsymbol{\\sigma}^2_b \\}_{b=1}^{B} \\right] \\propto \\\\\n& \\hspace{3cm} \\left[\\mathbf{y} \\middle| \\mathbf{\\tilde{y}}, \\boldsymbol{\\sigma}_y^2 \\right]\n\\prod_{b=1}^B \\left[\\mathbf{z}_b \\middle| \\mathbf{\\tilde{z}}_b, \\boldsymbol{\\sigma}_b^2 \\right] \\times \\\\\n& \\hspace{3cm} \n\\left[ \\mathbf{\\tilde{y}} \\middle| \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\{ \\boldsymbol{p}_b \\}_{b=1}^B, \\boldsymbol{\\phi} \\right]\n\\prod_{b=1}^B \n\\left[ \\mathbf{\\tilde{z}}_b \\middle| \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\boldsymbol{p}_b \\right] \\times\\\\\n& \\hspace{3cm} \n\\left[ \\boldsymbol{\\mu} \\right]\n\\left[ \\boldsymbol{\\sigma}^2 \\right]\n\\left[ \\boldsymbol{\\phi} | \\alpha_{\\phi} \\right]\n\\left[ \\alpha_{\\phi} \\right]\n\\left( \\prod_{b=1}^B \\left[ \\boldsymbol{p}_b \\middle| \\alpha_b \\right]\n\\left[ \\alpha_b \\right]\n \\right),\n\\end{align*}\nwhere each line on the right-hand side of the proportional symbol is the data, process, and prior model, respectively.\n\n\\subsection{Bottom-up unmixing model}\n\nIn the bottom-up unmixing model, observations are made on $d = 1, \\ldots, D$ child sediments whereas the parent sediments are unobserved. For each of the $d = 1, \\ldots, D$ children, the $n_d$ observed age measurements are given by the vector $\\mathbf{y}_d = (y_{d1}, \\ldots, y_{dn_d})'$ and are reported with an observed analytic measurement standard deviation $\\boldsymbol{\\sigma}_d = (\\sigma_{d1}, \\ldots, \\sigma_{dn_d})'$ associated with each observation. Assuming a normal distribution for the measurement process, the latent true ages are defined as $\\tilde{\\mathbf{y}}_d = (\\tilde{y}_{d1}, \\ldots, \\tilde{y}_{dn_d})'$ and are modeled by \n\\begin{align*}\n\\mathbf{y}_d | \\tilde{\\mathbf{y}}_d, \\boldsymbol{\\sigma}_d^2 & \\sim \\operatorname{N} (\\mathbf{y}_d | \\tilde{\\mathbf{y}}_d, \\operatorname{diag} ( \\boldsymbol{\\sigma}_d^2 ) ), \n\\end{align*}\n\nAs none of the parent ages are observed, the latent parent age distributions for the $b = 1, \\ldots, B$ parents are represented as a finite mixture of $K$ Gaussian distributions \n\\begin{align*}\n\\sum_{k=1}^K p_{bk} \\operatorname{N} \\left( \\mu_{k}, \\sigma^2_{k} \\right) \n\\end{align*}\nwhere $\\boldsymbol{\\mu} = (\\mu_1, \\ldots, \\mu_K)'$ and $\\boldsymbol{\\sigma}^2 = (\\sigma^2_1, \\ldots, \\sigma^2_K)'$ are the mean and variance of the mixture distributions (which are shared across each of the parents) and $\\mathbf{p}_{b} = (p_{b1}, \\ldots, p_{bK})'$ are mixture weights where for $k = 1, \\ldots, K,$ $p_{bk} > 0$ and $\\sum_{k=1}^K p_{bk} = 1$. For $k = 1, \\ldots, K$, the mixture distribution means are assigned independent, vague priors $N(\\mu_\\mu = 150 \\mbox{ Myr}, \\sigma^2_\\mu = 150^2 \\mbox{ Myr}^2)$ where Myr represents a million years. To ensure the mixing distributions are relatively concentrated with respect to geologic time, the mixing kernel standard deviations are assigned independent truncated half-Cauchy priors $\\sigma_k \\sim \\operatorname{Cauchy}^+(0, 25 \\mbox{ Myr})I\\{0 < \\sigma_k < 50 \\mbox{ Myr}\\}$, which enforces the mixing distribution scales (which represent geologic mineral formation events) to be small relative to the range of dates from about 0 to 300 Myr.\n\n\nBecause none of the parent ages are observed, the parent distributions are estimated entirely using child sediment observations. Assuming a fixed and known number of parents $B$, the bottom-up process model for the $d$th child is\n\n\\begin{align*}\n\\tilde{\\mathbf{y}}_{d} | \\boldsymbol{\\mu}, \\boldsymbol{\\sigma^2}, \\{ \\boldsymbol{p}_b \\}_{b=1}^B, \\boldsymbol{\\phi}_d & \\sim \\prod_{i1=}^{n_d} \\sum_{b=1}^B \\phi_{db} \\sum_{k=1}^K p_{bk} \\operatorname{N}(\\tilde{y}_{id} | \\mu_{k}, \\sigma^2_{k}),\n\\end{align*}\nwhere the $B$-dimensional vector of mixture proportions $\\boldsymbol{\\phi}_d = \\left( \\phi_{d1}, \\ldots, \\phi_{dB} \\right)'$ models the proportion of the $d$th child sediment that can be attributed to each of the $B$ parents where for $b = 1, \\ldots, B$, $\\phi_{db}>0$ and $\\sum_{b=1}^B \\phi_{db} = 1$. \nFor each of the $d = 1, \\ldots, D$ children, the mixing proportions $\\boldsymbol{\\phi}_d$ are a assigned independent $Dirichlet(\\alpha_{d} \\mathbf{1})$ prior where $\\mathbf{1}$ is a vector of ones of length $B$ and each $\\alpha_{d}$ is assigned a $gamma(1, 1)$ prior. The priors for $\\boldsymbol{\\mu}$, $\\boldsymbol{\\sigma^2}$, and $\\{\\mathbf{p}_{b}\\}_{b=1}^B$ (and their respective hyperparameters $\\boldsymbol{\\alpha} = (\\alpha_1, \\ldots, \\alpha_B)'$) are the same as in the top-down mixing model.\n\n\nThus, the bottom-up unmixing model posterior distribution is \n\n\\begin{align*}\n& \\left[ \\{ \\tilde{\\mathbf{y}}_d \\}_{d=1}^D, \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\{ \\boldsymbol{p}_b \\}_{b=1}^B, \\{ \\boldsymbol{\\phi}_d \\}_{d=1}^D, \\boldsymbol{\\alpha}_{\\phi}, \\boldsymbol{\\alpha} \\middle| \\{ \\mathbf{y}_d\\}_{d=1}^D, \\{\\boldsymbol{\\sigma}^2_{d} \\}_{d=1}^D \\right] \\propto \\\\\n& \\hspace{3cm} \\prod_{d=1}^D \\left[\\mathbf{y}_d \\middle| \\mathbf{\\tilde{y}}_d, \\boldsymbol{\\sigma}_{d}^2 \\right] \\times \\\\\n& \\hspace{3cm} \n\\prod_{d=1}^D \\left[ \\tilde{\\mathbf{y}}_d \\middle| \\boldsymbol{\\mu}, \\boldsymbol{\\sigma}^2, \\boldsymbol{\\phi}_d, \\{ \\boldsymbol{p}_b \\}_{b=1}^B \\right] \\times \\\\\n& \\hspace{3cm} \n\\left[ \\boldsymbol{\\mu}\\right]\n\\left[ \\boldsymbol{\\sigma}^2 \\right]\n\\left( \\prod_{b=1}^B \\left[ \\boldsymbol{p}_b \\middle| \\alpha_b \\right]\n\\left[ \\alpha_b \\right] \\right)\n\\left( \\prod_{d=1}^D \\left[ \\boldsymbol{\\phi}_d | \\alpha_{d} \\right]\n\\left[ \\alpha_{d} \\right] \\right),\n\\end{align*}\nwhere each line on the right-hand side of the proportional symbol is the data, process, and prior model, respectively.", "meta": {"hexsha": "33683b87347eb23ab2f7e1d63b78a1fb7fee3f74", "size": 11265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/stats-appendix.tex", "max_stars_repo_name": "jtipton25/mixing-manuscript", "max_stars_repo_head_hexsha": "b55093d467e9640116eaf4b6a81da473e8675aa1", "max_stars_repo_licenses": ["MIT"], "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/stats-appendix.tex", "max_issues_repo_name": "jtipton25/mixing-manuscript", "max_issues_repo_head_hexsha": "b55093d467e9640116eaf4b6a81da473e8675aa1", "max_issues_repo_licenses": ["MIT"], "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/stats-appendix.tex", "max_forks_repo_name": "jtipton25/mixing-manuscript", "max_forks_repo_head_hexsha": "b55093d467e9640116eaf4b6a81da473e8675aa1", "max_forks_repo_licenses": ["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.7878787879, "max_line_length": 1003, "alphanum_fraction": 0.6948069241, "num_tokens": 3884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6671493496506653}}
{"text": "\\section{Oriented bundles, Pontryagin classes, Signature theorem}\nWe have a pullback diagram\n$$\n\\xymatrix{\n    BSO(n)\\ar[r]\\ar[d]^{\\text{double cover}} & S^\\infty\\ar[d]\\\\\n    BO(n)\\ar[r]_{w_1} & B\\Z/2\\Z\n}\n$$\nThe bottom map is exactly the element $w_1\\in H^1(BO(n);\\FF_2)$. It follows\nthat a vector bundle $\\xi\\downarrow X$ represented by a map $f:X\\to BO(n)$ is\norientable iff $w_1(\\xi) = f^\\ast(w_1) = 0$, since this is equivalent to the\nexistence of a factorization:\n$$\n\\xymatrix{\n    & BSO(n)\\ar[r]\\ar[d] & S^\\infty\\ar[d]\\\\\n    X\\ar@{-->}[ur]\\ar[r]_{\\xi} & BO(n)\\ar[r]_{w_1} & B\\Z/2\\Z\n}\n$$\nThe fiber sequence $BSO(n)\\to BO(n)\\to \\RP^\\infty$ comes from a fiber sequence\n$SO(n)\\to O(n)\\to\\Z/2\\Z$ of groups. For $n\\geq 3$, we can kill $\\pi_1(SO(n)) =\n\\Z/2\\Z$,\nto get a double cover $\\Spin(n)\\to SO(n)$. The group $\\Spin(n)$ is called the\n\\emph{spin group}. We have a cofiber sequence\n$$B\\Spin(n)\\to BSO(n)\\xar{w_2} K(\\Z/2\\Z,2).$$\nIf $w_2(\\xi) = 0$, we get a further lift in the above diagram, begetting a\n\\emph{spin structure} on $\\xi$.\n\nBott computed that $\\pi_2(\\Spin(n)) = 0$. However, $\\pi_3(\\Spin(n)) = \\Z$;\nkilling this gives the \\emph{string group} $\\String(n)$. Unlike $\\Spin(n)$,\n$SO(n)$, and $O(n)$, this is not a finite-dimensional Lie group (since we have\nan infinite dimensional summand $K(\\Z,2)$). However, it can be realized as a\ntopological group. The resulting maps $$\\String(n)\\to \\Spin(n)\\to SO(n)\\to\nO(n)$$ are just the maps in the Whitehead tower for $O(n)$. Taking classifying\nspaces, we get\n$$\n\\xymatrix{\n    & B\\String(n)\\ar[d] & \\\\\n    & B\\Spin(n)\\ar[d] \\ar[r]^{p_1/2} & K(\\Z,4)\\\\\n    & BSO(n)\\ar[r]\\ar[d] & K(\\Z/2\\Z,2)\\\\\n    X\\ar@{-->}[ur]\\ar@{-->}[uur]\\ar@{-->}[uuur]\\ar[r]_{\\xi} & BO(n)\\ar[r]_{w_1}\n    & B\\Z/2\\Z\n}\n$$\n\nComputing the (mod $2$) cohomology of $BSO(n)$ is easy. We have a double cover\n$BSO(n)\\to BO(n)$ with fiber $S^0$. Consequently, there is a Gysin sequence:\n$$\n0\\to H^q(BO(n)) \\xar{w_1} H^{q+1}(BO(n)) \\xar{\\pi^\\ast} H^{q+1}(BSO(n)) \\to 0\n$$\nsince $w_1$ is a nonzero divisor. The standard argument shows that\n$$\nH^\\ast(BSO(n)) = \\FF_2[w_2,\\cdots,w_n].\n$$\nHowever, it is \\emph{not} easy to compute $H^\\ast(B\\Spin(n))$ and\n$H^\\ast(B\\String(n))$; these are extremely complicated (and only become more\ncomplicated for higher connective covers of $BO(n)$). However, we will remark\nthat they are concentrated in even degrees.\n\nTo define integral characteristic classes for oriented bundles, we will need to\nstudy Chern classes a little more.\n%Suppose $V$ is a complex vector space.  We can then get an\n%oriented real vector space $V_\\RR$, with a choice of ordered basis given by\n%$e_1,ie_1,\\cdots,e_2,ie_2$. This space has an involution $-$, given by the opposite\n%orientation. \n%\n%The vector spaces $\\overline{V}_\\RR$ and $V_\\RR$ are the same, but they have\n%different orientations.\n%%In fact, you have $\\overline{V}_\\RR = (-1)^{\\dim V} V_\\RR$.\n%I can also consider $(V\\otimes_\\RR\\cc)_\\RR$.\n%This is just $V\\oplus V$, and we get that $(V\\otimes_\\RR\\cc)_\\RR = (-1)^{\\dim V\\cdot(\\dim V - 1)/2} V\\oplus V$.\n%\n%Another one.\n%We know that $\\overline{(V\\otimes_\\RR\\cc)}\\simeq V\\otimes_\\RR\\cc$.\n%\n%We're going to use those identities.\nLet $\\xi$ be a complex $n$-plane bundle, and let $\\overline{\\xi}$ denote the\nconjugate bundle. What is the total Chern class $c(\\overline{\\xi})$? Recall\nthat the Chern classes $c_k(\\overline{\\xi})$ occur as coefficients in the\nidentity\n$$\\sum c_i(\\overline{\\xi}) e(\\lambda_{\\overline{\\xi}})^{n-i} = 0,$$\nwhere $\\lambda_{\\overline{\\xi}}\\downarrow \\PP(\\overline{\\xi})$. Note that\n$\\PP(\\overline{\\xi}) = \\PP(\\xi)$. By construction, $\\lambda_{\\overline{\\xi}} =\n\\overline{\\lambda_\\xi}$. In particular, we find that\n$$e(\\lambda_{\\overline{\\xi}}) = -e(\\lambda_\\xi).$$\nIt follows that\n$$\n0 = \\sum^n_{i=0}c_i(\\overline{\\xi})e(\\overline{\\lambda_\\xi})^{n-i} =\n\\sum^n_{i=0}c_i(\\overline{\\xi}) (-1)^{n-i}e(\\lambda_\\xi)^{n-i} = (-1)^n\ne(\\lambda_\\xi)^n + \\cdots\n$$\nThis is \\emph{not} monic, and hence doesn't define the Chern classes of\n$\\overline{\\xi}$. We do, however, get a monic polynomial by multiplying this\nidentity by $(-1)^n$:\n$$\n\\sum^n_{i=0}(-1)^ic_i(\\overline{\\xi})e(\\lambda_\\xi)^{n-i} = 0.\n$$\nIt follows that\n$$\n\\boxed{c_i(\\overline{\\xi}) = (-1)^ic_i(\\xi).}\n$$\nIf $\\xi$ is a real vector bundle, then\n$$c_i(\\xi\\otimes\\cC) = c_i(\\overline{\\xi\\otimes\\cC}) =\n(-1)^ic_i(\\xi\\otimes\\cC).$$\nIf $i$ is odd, then $2c_{i}(\\xi\\otimes\\cC) = 0$. If $R$ is a $\\Z[1/2]$-algebra,\nwe therefore define:\n%We know what the cohomology of $BSO(n)$ is in $\\FF_2$, and now I'm going to\n%tell you what $H^\\ast(BSO(n))$ is with coefficients in a $\\Z[1/2]$-algebra (so\n%$1/2$ exists). Then those odd Chern classes are just zero.\n\\begin{definition}\n    Let $\\xi$ be a real $n$-plane vector bundle. Then the $k$th Pontryagin\n    class of $\\xi$ is defined to be \n    $$p_k(\\xi) = (-1)^kc_{2k}(\\xi\\otimes\\cc)\\in H^{4k}(X;R).$$\n\\end{definition}\nNotice that this is $0$ if $2k>n$, since $\\xi\\otimes\\cc$ is of complex\ndimension $n$. The Whitney sum formula now says that:\n$$\n(-1)^k p_k(\\xi\\oplus\\eta) = \\sum_{i+j = k}(-1)^i p_i(\\xi) (-1)^j p_j(\\eta) =\n(-1)^k\\sum_{i+j=k}p_i(\\xi)p_j(\\eta).\n$$\nIf $\\xi$ is an oriented real $2k$-plane bundle, one can calculate that\n$$\np_k(\\xi) = e(\\xi)^2\\in H^{4k}(X;R).\n$$\nWe can therefore write down the cohomology of $BSO(n)$ with coefficients in a\n$\\Z[1/2]$-algebra:\n\\begin{center}\n    \\begin{tabular}{ c|c c c c c c} \n\t\\hline\n\t$\\ast = $ & 2 & 4 & 6 & 8 & 10 & 12\\\\\n\t\\hline\n\t$H^\\ast(BSO(2))$ & $e_2$ & $(e_2^2)$ & & & &\\\\\n\t$H^\\ast(BSO(3))$ & & $p_1$ & & & &\\\\\n\t$H^\\ast(BSO(4))$ & & $p_1,e_4$ & & $(e_4^2)$ & &\\\\\n\t$H^\\ast(BSO(5))$ & & $p_1$ & & $p_2$ & &\\\\\n\t$H^\\ast(BSO(6))$ & & $p_1$ & $e_6$ & $p_2$ & & $(e_6^2)$\\\\\n\t$H^\\ast(BSO(7))$ & & $p_1$ & & $p_2$ & & $p_3$\n    \\end{tabular}\n\\end{center}\nHere, $p_k \\mapsto e_{2k}^2$. In the limiting case (i.e., for $BSO =\nBSO(\\infty)$), we get a polynomial algebra on the $p_i$.\n\\subsection{Applications}\nWe will not prove any of the statements in this section; it only serves as an\noutlook. The first application is the following analogue of Theorem\n\\ref{thom-sw}:\n\\begin{theorem}[Wall]\n    Let $M^n,N^n$ be oriented manifolds. If all Stiefel-Whitney numbers and\n    Pontryagin numbers coincide, then $M$ is oriented cobordant to $N$, i.e.,\n    there is an $(n+1)$-manifold $W^{n+1}$ such that\n    $$\\partial W^{n+1} = M\\sqcup -N.$$\n\\end{theorem}\nThe most exciting application of Pontryagin classes is to Hirzebruch's\n``signature theorem''. Let $M^{4k}$ be an oriented $4k$-manifold. Then, the\nformula\n$$x\\otimes y\\mapsto\\langle x\\cup y,[M]\\rangle$$\ndefines a pairing\n$$H^{2k}(M)/\\mathrm{torsion}\\otimes H^{2k}(M)/\\mathrm{tors}\\to \\Z.$$\nPoincar\\'e duality implies that this is a perfect pairing, i.e., there is a\nnonsingular symmetric bilinear form on $H^{2k}(M)/\\mathrm{torsion}\\otimes \\RR$.\nEvery symmetric bilinear form on a real vector space can be diagonalized, so\nthat the associated matrix is diagonal, and the only nonzero entries are $\\pm\n1$. The number of $1$s minus the number of $-1$s is called the \\emph{signature}\nof the bilinear form. When the bilinear form comes from a $4k$-manifold as\nabove, this is called the signature of the manifold.\n\\begin{lemma}[Thom]\n    The signature is an oriented bordism invariant.\n\\end{lemma}\nThis is an easy thing to prove using Lefschetz duality, which is a deep\ntheorem. Hirzebruch's signature theorem says:\n\\begin{theorem}[Hirzebruch signature theorem]\n    There exists an explicit rational polynomial $L_k(p_1,\\cdots,p_k)$ of\n    degree $4k$ such that\n    $$\\langle L(p_1(\\tau_M),\\cdots,p_1(\\tau_M)),[M]\\rangle =\n    \\mathrm{signature}(M).$$\n\\end{theorem}\nThe reason the signature theorem is so interesting is that the polynomial\n$L(p_1(\\tau_M),\\cdots,p_1(\\tau_M))$ is defined only in terms of the tangent\nbundle of the manifold, while the signature is defined only in terms of the\ntopology of the manifold. This result was vastly generalized by Atiyah and\nSinger to the Atiyah-Singer index theorem.\n\\begin{example}\n    One can show that \n    $$L_1(p_1) = p_1/3.$$\n    The Hirzebruch signature theorem implies that $\\langle\n    p_1(\\tau),[M^4]\\rangle$ is divisible by $3$.\n\\end{example}\n\\begin{example}\n    From Hirzebruch's characterization of the $L$-polynomial, we have\n    $$L_2(p_1,p_2) = (7p_2 - p_1^2)/45.$$\n    This imposes very interesting divisibility constraints on the\n    characteristic classes of a tangent bundle of an $8$-manifold. This\n    particular polynomial was used by Milnor to produce ``exotic spheres'',\n    i.e., manifolds which are homeomorphic to $S^7$ but not diffeomorphic to\n    it.\n\\end{example}\n", "meta": {"hexsha": "71d2bf19547132d17b10335b83e1b95237c23ff8", "size": 8588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-74-oriented-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-74-oriented-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-74-oriented-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": 44.041025641, "max_line_length": 112, "alphanum_fraction": 0.6575454122, "num_tokens": 3163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6671246830078172}}
{"text": "% 01ManifoldsVector.tex\n\n\\subsection{Submanifolds of Euclidean Space}\n\n\\paragraph{1.1(3)}\n\nConsider for $F(A) = \\det{A}$, $F:\\mathbb{R^{n^2}} \\to \\mathbb{R}$, that \n\\[\n\\begin{gathered}\n  \\det{A + tB } = \\det{ A ( 1 + tA^{-1} B)  } = \\det{A} \\det{  1 + tA^{-1}B}\n\\end{gathered}\n\\]\n\nHow to deal with $\\det{1 + tA^{-1}B}$?  Recall that \n\\[\n\\det{  1 + tA^{-1}B} = \\det{A} ( 1 + t\\tr{A^{-1} B})\n\\]\nbecause for $ \\det{(1 + tX)}$, \n\n\\[\n\\begin{gathered}\n  \\det{(1+ tX)} = \\det{  \\matrixp{1& & \\\\ &\\ddots & \\\\ && 1 }  +  \\matrixp{ t x_{11} & \\dots & t x_{1n} \\\\ \\vdots & \\ddots & \\vdots \\\\ tx_{n1} & \\dots & t x_{nn} }   } = \n  \\det{  \\matrixp{ 1 + tx_{11}& \\dots & tx_{1n } \\\\ \n      \\vdots & \\ddots & \\vdots \\\\ \n      tx_{n1} & \\dots & 1 + tx_{nn}} } = \\\\\n  = 1 + t\\tr{X} + \\mathcal{O}(t^2)\n\\end{gathered}\n\\]\nsince recall $\\det{A} = \\sum_{\\sigma \\in S_n} \\text{sgn}{(\\sigma)} A_{1 \\sigma_1} A_{2\\sigma_2} \\dots A_{n\\sigma_n}$, where sum is over all permutations of $\\lbrace 1, \\dots, n \\rbrace$, and so only the $A_{11}\\dots A_{nn}$ term would have terms of $\\mathcal{O}(t)$.  \n\nSo\n\\[\n(DF) \\cdot B = \\frac{d}{dt}  F(x(t)) B = \\det{x} \\tr{x^{-1} B}\n\\]\nFor $x_0 \\in Sl(n)$, $\\det{x_0} = 1$.  Let $B = \\frac{r}{n} x$.  Then \n\\[\n(DF)\\cdot B = \\tr{x^{-1} \\frac{r}{n} x  } = r \n\\]\n$DF = F_*$ is surjective $\\forall \\, x \\in Sl(n)$\n\n\n\\subsection{Manifolds}\n\n\n\n\\subsection{Tangent Vectors and Mappings}\n\n\\subsubsection{ Tangent or ``Contravariant Vectors}\n\n\\subsubsection{ Vectors as Differential Operators}\n\n\n\n\\subsubsection{ The Tangent Space to $M^n$ at a Point }\n\n\n\\subsubsection{ Mappings and Submanifolds of Manifolds}\n\n\n\\begin{definition} $M^m \\subset N^n$ (embedded) submanifold of $N^n$.  If $M$ locally s.t. $F: N^n \\to \\mathbb{R}^{n-m}$ \n\\[\n\\begin{aligned}\n  & F^1(x^1 \\dots x^n) = 0 \\\\ \n  & \\vdots \\\\ \n  & F^{n-m}(x^1 \\dots x^n) = 0 \n\\end{aligned}\n\\]\n$n-m$ diff. $F^i$ s.t. $\\left| \\frac{ \\partial F^i}{ \\partial x^j} \\right| $ has rank $n-m$\n\\end{definition}\n\nBy implicit function thm., submanifold as graph.  \n\\[\n\\begin{gathered}\n  (x^1 \\dots x^m, y^{m+1} \\dots y^n ) \\\\ \n  \\begin{aligned}\n    & y^{m+1} = f^{m=1}(x^1 \\dots x^m)  \\\\ \n    & \\vdots \\\\ \n    & y^n = f^n(x^1 \\dots x^m)\n\\end{aligned}\n\\end{gathered}\n\\]\n\non $F(x) = 0$ \n\n\\begin{theorem}[1.12] Let $F: M^m \\to N^n$, $q \\in N^n$ s.t. $F^{-1}(q) \\subset M^m $, $F^{-1}(q) \\neq \\emptyset$ \\\\\nIf $F_*$ onto, i.e. $F_*$ rank $n$, $\\forall \\, F^{-1}(q)$, \\\\\n$F^{-1}(q)$ ($n-m$)-dim. submanifold of $M^m$\n\\end{theorem}\n\n\n\n\n\\subsubsection{ Change of Coordinates}\n\n\n", "meta": {"hexsha": "51dc98e6304e24330a6e9be612cb1d60e71a36b3", "size": 2515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX_and_pdfs/the geometry of physics problems/01ManifoldsVector.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/01ManifoldsVector.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/01ManifoldsVector.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": 26.1979166667, "max_line_length": 268, "alphanum_fraction": 0.5483101392, "num_tokens": 1092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951064805861, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6671246716145246}}
{"text": "\n\\outline{3}{Exercise 12.9}\n\\subsubsection*{Exercise 12.9}\n\n\\textit{Estimate the critical percolation threshold for the same forest fire\nmodel but with von Neumann neighborhoods. Confirm the analytical result by\nconducting simulations.}\n\n\\vspace{5mm}\nWith von Neumann\\textquotesingle s neighborhood, the system supports percolation\nin the cases on the left side, and those on the right side are unsupported:\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{./figures/12.9-supported-cases.png}\n  \\hspace{15mm}\n  \\includegraphics[width=0.25\\textwidth]{./figures/12.9-unsupported-cases.png}\n\\end{figure}\n\nSo that the critical percolation threshold is now given by:\n\\begin{equation}\n  p_c = {p_c}^4 + 4 {p_c}^3 (1-p_c) + 2 {p_c}^2 {(1-p_c)}^2,\n\\end{equation}\n\nand the cobweb plot for that equation is:\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.75\\textwidth]{./figures/12.9-cobweb-plot-for-von-neumann-neighborhood.pdf}\n  \\caption{\\texttt{12.9-cobweb-plot-for-von-neumann-neighborhood.py}}\n\\end{figure}\n\nIn which is easy to see two asymptotic states possible, $p_\\infty = 0$ and\n$p_\\infty = 1$ (the cobweb plot is about relations over scale, not about\ndynamics over time). There is an unstable equilibrium point around $p = 0.6$.\nThe exact value is given by:\n\\begin{equation}\n  p_c = \\frac{\\sqrt{5}}{2} - \\frac{1}{2} \\approx 0.6180.\n\\end{equation}\n\n\\vspace{5mm}\nTo verify this prediction, one could simulate the system a certain number of\ntimes for each values of $p$.\n\\begin{itemize}\n  \\item $p > p_c$: systems should show percolation in most cases;\n  \\item $p < p_c$: systems should not show percolation in most cases;\n  \\item $p \\approx p_c$: systems will show percolation in some cases.\n\\end{itemize}\n\nThe following figure is a simulation output for $n = 100$ and $p = 0.5875$:\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.75\\textwidth]{./figures/12.9-simulation-result.pdf}\n  \\caption{\\texttt{12.9-von-neumann-fire-ca.py}}\n\\end{figure}\n", "meta": {"hexsha": "27ad000c2314e6a942f6e11cd474780a4c1b11ab", "size": 1987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/subsubsections/12.9.tex", "max_stars_repo_name": "brenoec/cefetmg.msc.sayama.solutions", "max_stars_repo_head_hexsha": "ea3f16427b8ade2b217647b75909966e038c3dc2", "max_stars_repo_licenses": ["MIT"], "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/subsubsections/12.9.tex", "max_issues_repo_name": "brenoec/cefetmg.msc.sayama.solutions", "max_issues_repo_head_hexsha": "ea3f16427b8ade2b217647b75909966e038c3dc2", "max_issues_repo_licenses": ["MIT"], "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/subsubsections/12.9.tex", "max_forks_repo_name": "brenoec/cefetmg.msc.sayama.solutions", "max_forks_repo_head_hexsha": "ea3f16427b8ade2b217647b75909966e038c3dc2", "max_forks_repo_licenses": ["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.7962962963, "max_line_length": 101, "alphanum_fraction": 0.7393054857, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585669110203, "lm_q2_score": 0.9124361682155117, "lm_q1q2_score": 0.6670442775334147}}
{"text": "Consider a point-to-point MISO WIPT system in a multipath environment. The $M$-antenna transmitter delivers information and power simultaneously to the single-antenna receiver through $N$ orthogonal subbands. It is assumed the carrier frequencies are with even spacing $\\Delta f$ and equal bandwidth ${B_{\\text{s}}}$. The $n$-th subband has carrier frequency ${f_n} = {f_0} + n\\Delta f$ for $n = 0, \\ldots ,N - 1$. To maximize the rate-energy tradeoff, we employ a superposed signal consists of a multi-carrier deterministic multisine waveform and a multi-carrier modulated waveform for WIPT. Both components are transmitted on the same frequency bands.\n\n\n\n\\subsection{Transmitted Information Waveform}\\label{sec:transmitted-information-waveform}\nDenoting the information symbol carried by the modulated waveform on subband $n$ as ${{\\tilde x}_n}$, we assume the input symbol is with the capacity-achieving i.i.d. Circular Symmetric Complex Gaussian (CSCG) distribution with zero mean and unit variance \\cite{Varasteh2017a}:\n\n\\begin{equation}\\label{eqn:unmodulated_symbol}\n  {{\\tilde x}_n} = \\left| {{{\\tilde x}_n}} \\right|{e^{j{\\phi _{{{\\tilde x}_n}}}}}\\sim\\mathcal{C}\\mathcal{N}(0,1)\n\\end{equation}\n\nHence, the modulated signal on antenna $m = 1, \\ldots ,M$, subband $n = 1, \\ldots ,N$ writes as\n\n\\begin{equation}\\label{eqn:modulated_symbol}\n  {x_{n,m}} = {w_{I,n,m}}{{\\tilde x}_n}\n\\end{equation}\n\nwhere ${w_{I,n,m}}$ is the corresponding information weight and is a constant for a certain channel realization:\n\n\\begin{equation}\\label{eqn:weight_information}\n  {w_{I,n,m}} = \\left| {{w_{I,n,m}}} \\right|{e^{j{\\phi _{I,n,m}}}} = {s_{I,n,m}}{e^{j{\\phi _{I,n,m}}}}\n\\end{equation}\n\nNote the amplitude and phase are separated in the optimization. Define matrices ${{\\mathbf{S}}_I}$ and ${{\\mathbf{\\Phi }}_I}$ of size $N \\times M$ such that the $(n,m)$ entries hold ${s_{I,n,m}}$ and ${\\phi _{I,n,m}}$ respectively. In this way, the design of information waveform is converted into an optimization problem on both matrices, with the average WIT transmit power ${P_I} = \\frac{1}{2}\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2$. The modulated symbol \\eqref{eqn:modulated_symbol} can be further expressed as\n\n\\begin{equation}\\label{eqn:modulated_symbol_further}\n  {x_{n,m}} = {s_{I,n,m}}{e^{j{\\phi _{I,n,m}}}} \\cdot \\left| {{{\\tilde x}_n}} \\right|{e^{j{\\phi _{{{\\tilde x}_n}}}}} = {{\\tilde s}_{I,n,m}}{e^{j{{\\tilde \\phi }_{I,n,m}}}}\n\\end{equation}\n\nwith ${{\\tilde s}_{I,n,m}} = {s_{I,n,m}}\\left| {{{\\tilde x}_n}} \\right|$ and ${{\\tilde \\phi }_{I,n,m}} = {\\phi _{I,n,m}} + {\\phi _{{{\\tilde x}_n}}}$. In this way, the impact of symbol distribution and waveform design are combined. The modulated waveform also follows an i.i.d. CSCG distribution with variance equal to the subband power ${x_{n,m}}\\sim\\mathcal{C}\\mathcal{N}\\left( {0,s_{I,n,m}^2} \\right)$.\n\nTherefore, the information waveform ${x_{I,m}}(t)$ on antenna $m$ at time $t$ writes as\n\n\\begin{align}\\label{eqn:information_waveform}\n  {x_{I,m}}(t) &= \\sum\\limits_{n = 0}^{N - 1} {{{\\tilde s}_{I,n,m}}(t)\\cos \\left( {2\\pi {f_n}t + {{\\tilde \\phi }_{I,n,m}}(t)} \\right)}  \\hfill \\\\\n   &= \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{x_{n,m}}(t){e^{j2\\pi {f_n}t}}} } \\right\\} \\hfill \\\\\n   &= \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{w_{I,n,m}}{{\\tilde x}_n}(t){e^{j2\\pi {f_n}t}}} } \\right\\} \\hfill\n\\end{align}\n\nOn top of this, the WIT signal vector is spread over $M$ antennas\n\n\\begin{equation}\\label{eqn:wit_vector}\n  {{\\mathbf{x}}_I}(t) = \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{{\\mathbf{w}}_{I,n}}} {{\\tilde x}_n}(t){e^{j2\\pi {f_n}t}}} \\right\\}\n\\end{equation}\n\nwhere ${{\\mathbf{w}}_{I,n}} = {\\left[ {{w_{I,n,1}} \\cdots {w_{I,n,M}}} \\right]^T}$.\n\n\n\n\\subsection{Transmitted Power Waveform}\\label{sec:transmitted-power-waveform}\nCompared with the information component, the multisine power component is unmodulated and deterministic. Hence, there is no dependency on the distribution of input symbol $\\tilde{x}_{n}(t)$. The power waveform on antenna $m$, subband $n$ is given by\n\n\\begin{equation}\\label{eqn:unmodulated}\n  {w_{P,n,m}} = {s_{P,n,m}}{e^{j{\\phi _{P,n,m}}}}\n\\end{equation}\n\nwhere ${s_{P,n,m}}$ and ${{\\phi _{P,n,m}}}$ are the amplitude and phase of the multisine signal. Collecting them into the $(n,m)$ entries of matrices ${{\\mathbf{S}}_P}$ and ${{\\mathbf{\\Phi }}_P}$, the average power of the WPT waveform equals $\\frac{1}{2}\\left\\|\\mathbf{S}_{P}\\right\\|_{F}^{2}$. Similarly, the power waveform ${x_{P,m}}(t)$ on antenna $m$ at time $t$ is\n\n\\begin{align}\\label{eqn:power_waveform}\n  {x_{P,m}}(t) &= \\sum\\limits_{n = 0}^{N - 1} {{s_{P,n,m}}\\cos \\left( {2\\pi {f_n}t + {\\phi _{P,n,m}}} \\right)}  \\hfill \\\\\n   &= \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{w_{P,n,m}}{e^{j2\\pi {f_n}t}}} } \\right\\} \\hfill\n\\end{align}\n\nCombining the power signals on all $M$ antennas, the WPT signal vector writes as\n\n\\begin{equation}\\label{eqn:wpt_vector}\n  {{\\mathbf{x}}_P}(t) = \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{{\\mathbf{w}}_{P,n}}} {e^{j2\\pi {f_n}t}}} \\right\\}\n\\end{equation}\n\nwith ${{\\mathbf{w}}_{P,n}} = {\\left[ {{w_{P,n,1}} \\cdots {w_{P,n,M}}} \\right]^T}$.\n\n\n\n\\subsection{Channel and Received Waveform}\\label{sec:multipath-and-received-signal}\nConsider a multipath channel with $L$ paths. For the $l$-th path ($l = 1, \\ldots ,L$), denote the phase shift between the receive antenna and transmit antenna $m$ of subband $n$ as ${\\zeta _{n,m,l}}$. Let ${\\tau _l}$ and ${\\alpha _l}$ be the delay and magnitude gain, and indicate the transmit signal on subband $n$ of antenna $m$ as\n\n\\begin{equation}\\label{eqn:superposed_waveform}\n  {v_{n,m}}(t) = {w_{P,n,m}} + {w_{I,n,m}}{{\\tilde x}_n}(t)\n\\end{equation}\n\nThe superposed signal containing modulated information waveform and multisine power waveform is demonstrated to bring a two-fold benefit on rate and energy \\cite{Clerckx2019}. Also, the channel frequency response is expressed as\n\n\\begin{equation}\\label{eqn:channel}\n  {h_{n,m}} = \\sum\\limits_{l = 0}^{L - 1} {{\\alpha _l}{e^{j\\left( { - 2\\pi {f_n}{\\tau _l} + {\\zeta _{n,m,l}}} \\right)}}}  = {A_{n,m}}{e^{j{{\\bar \\psi }_{n,m}}}}\n\\end{equation}\n\nWe assume ${\\max _{l \\ne {l^\\prime }}}\\left| {{\\tau _l} - {\\tau _{{l^\\prime }}}} \\right| <  < 1/{B_{\\text{s}}}$ to ensure $v_{n, m}(t)$ and $\\tilde{x}_{n}(t)$ to be narrowband signals. It is also supposed that ${v_{n,m}}\\left( {t - {\\tau _l}} \\right) = {v_{n,m}}(t)$ and ${{\\tilde x}_n}\\left( {t - {\\tau _l}} \\right) = {{\\tilde x}_n}(t)$. The received component ${y_m}(t)$ corresponding to transmit antenna $m$ contains the power component $y_{P, m}(t)$ and the information component $y_{I, m}(t)$\n\n\\begin{align}\\label{eqn:received_signal_component}\n  {y_m}(t) &= {y_{P,m}}(t) + {y_{I,m}}(t) \\hfill \\\\\n   &= \\Re \\left\\{ {\\sum\\limits_{l = 0}^{L - 1} {\\sum\\limits_{n = 0}^{N - 1} {{\\alpha _l}} } {v_{n,m}}\\left( {t - {\\tau _l}} \\right){e^{j2\\pi {f_n}\\left( {t - {\\tau _l}} \\right) + {\\zeta _{n,m,l}}}}} \\right\\} \\hfill \\\\\n   &\\approx \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{h_{n,m}}} {v_{n,m}}(t){e^{j2\\pi {f_n}t}}} \\right\\} \\hfill\n\\end{align}\n\nHence, the total received signal can be obtained by stacking up \\eqref{eqn:received_signal_component} over all transmit signals\n\n\\begin{align}\\label{eqn:received_signal}\n  y(t) &= {y_P}(t) + {y_I}(t) \\hfill \\\\\n   &= \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {{{\\mathbf{h}}_n}} \\left( {{{\\mathbf{w}}_{P,n}} + {{\\mathbf{w}}_{I,n}}{{\\tilde x}_n}} \\right){e^{j2\\pi {f_n}t}}} \\right\\} \\hfill\n\\end{align}\n\nwhere the channel vector is defined as ${{\\mathbf{h}}_n} = \\left[ {{h_{n,1}} \\ldots {h_{n,M}}} \\right]$.\n\n\n\n\\subsection{Information Decoder}\\label{sec:information-decoder}\nIn the superposed transmit signal ${x_m}(t)$, the modulated component ${x_{I,m}}(t)$ carries all the information while the multisine component ${x_{P,m}}(t)$ completely serves the power. Since the latter is deterministic, it creates no interference and has zero contribution to the different entropy of ${x_m}(t)$ in terms of translation. Therefore, the achievable rate is equal to\n\n\\begin{equation}\\label{eqn:mutual_information}\n  I\\left( {{{\\mathbf{S}}_I},{{\\mathbf{\\Phi }}_I},\\rho } \\right) = \\sum\\limits_{n = 0}^{N - 1} {{{\\log }_2}} \\left( {1 + \\frac{{(1 - \\rho ){{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{I,n}}} \\right|}^2}}}{{\\sigma _n^2}}} \\right)\n\\end{equation}\n\nwhere ${\\sigma _n^2}$ is the total variance of the Gaussian noise at the RF-band and the noise introduced during the RF-to-baseband conversion (assumed Gaussian) on tone $n$. It reaches the maximum rate $I\\left( {{\\mathbf{S}}_I^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,0} \\right)$ and boils down to WIT by setting $\\rho  = 0$ then performing Maximum Ratio Transmission (MRT) and Water-Filling (WF) power allocation on subbands.\n\nA significant conclusion in \\cite{Clerckx2018} is that the rate \\eqref{eqn:mutual_information} is achievable with and without waveform cancellation. Since the multisine is deterministic, it can either be subtracted from the baseband signal or be used to construct the translated codebook. Conventional demodulation can be performed then.\n\n\n\n\\subsection{Energy Harvester}\\label{sec:energy-harvester}\nTo investigate the impact of the proposed waveform on the harvested power, we apply the received signal expression \\eqref{eqn:received_signal_component} to the diode current equation \\eqref{eqn:output_current_function}.\n\nFirst, we consider the multi-carrier multisine waveform ${y_P}(t)$. The approximated harvester DC current with multisine excitation writes as\n\n\\begin{equation}\\label{eqn:current_power}\n  {i_{\\text{out}}} \\approx k_0^\\prime  + \\sum\\limits_{i{\\text{ even }},i \\geqslant 2}^{{n_o}} {k_i^\\prime } {\\rho ^{i/2}}R_{\\text{ant}}^{i/2}\\mathbb{E}\\left[ {{y_P}{{(t)}^i}} \\right]\n\\end{equation}\n\nThe expectations of the received power waveform to the second and fourth orders were derived in \\cite{Clerckx2016} as\n\n\\begin{align}\\label{eqn:power_waveform_second_order}\n  \\mathbb{E}\\left[ {{y_P}{{(t)}^2}} \\right] &= \\frac{1}{2}\\sum\\limits_{n = 0}^{N - 1} {{{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{P,n}}} \\right|}^2}} \\\\\n   &= \\frac{1}{2}\\sum\\limits_{n = 0}^{N - 1} {\\sum\\limits_{{m_0},{m_1}} {{s_{P,n,{m_0}}}{s_{P,n,{m_1}}}{A_{n,{m_0}}}{A_{n,{m_1}}}\\cos \\left( {{\\psi _{P,n,{m_0}}} - {\\psi _{P,n,{m_1}}}} \\right)} }\n\\end{align}\n\n\\begin{align}\\label{eqn:power_waveform_fourth_order}\n  \\mathbb{E}\\left[ {{y_P}{{(t)}^4}} \\right] &= \\frac{3}{8}\\Re \\left\\{ {\\sum\\limits_{\\substack{{n_0},{n_1},{n_2},{n_3} \\\\ {n_0} + {n_1} = {n_2} + {n_3}}} {{{\\mathbf{h}}_{{n_0}}}{{\\mathbf{w}}_{P,{n_0}}}{{\\mathbf{h}}_{{n_1}}}{{\\mathbf{w}}_{P,{n_1}}}{{\\left( {{{\\mathbf{h}}_{{n_2}}}{{\\mathbf{w}}_{P,{n_2}}}} \\right)}^*}{{\\left( {{{\\mathbf{h}}_{{n_3}}}{{\\mathbf{w}}_{P,{n_3}}}} \\right)}^*}} } \\right\\} \\\\\n   &= \\frac{3}{8}\\sum\\limits_{\\substack{{n_0},{n_1},{n_2},{n_3} \\\\ {n_0} + {n_1} = {n_2} + {n_3}}} {\\sum\\limits_{{m_0},{m_1},{m_2},{m_3}} {\\left[ {\\prod\\limits_{j = 0}^3 {{s_{{P},{n_j},{m_j}}}} {A_{{n_j},{m_j}}}} \\right] }} \\nonumber \\\\\n   &\\quad \\cos \\left( {{\\psi _{{P},{n_0},{m_0}}} + {\\psi _{{P},{n_1},{m_1}}} - {\\psi _{{P},{n_2},{m_2}}} - {\\psi _{{P},{n_3},{m_3}}}} \\right)\n\\end{align}\n\nWe then turn to the multi-carrier modulated waveform ${y_I}(t)$. It can be treated as a multisine waveform for the input symbols $\\{ {{\\tilde x}_n}\\} $ that vary randomly with symbol rate $1/{B_{\\text{s}}}$. Similarly, the approximated DC current provided by the rectifier is given by\n\n\\begin{equation}\\label{eqn:current_information}\n  {i_{\\text{out}}} \\approx k_0^\\prime  + \\sum\\limits_{i{\\text{ even }},i \\geqslant 2}^{{n_o}} {k_i^\\prime } {\\rho ^{i/2}}R_{\\text{ant}}^{i/2}{\\mathbb{E}_{\\{ {{\\tilde x}_n}\\} }}\\left[ {{y_I}{{(t)}^i}} \\right]\n\\end{equation}\n\nTo obtain the expectation, we first extract the DC currents corresponding to a given set of amplitudes $\\{ {{\\tilde s}_{I,n,m}}\\} $ and phases $\\{ {{\\tilde \\phi }_{I,n,m}}\\} $, then take the expectation over the distribution of the input symbol ${{\\tilde x}_n}$. As an i.i.d. CSCG distribution ${{\\tilde x}_n}\\sim\\mathcal{C}\\mathcal{N}(0,1)$ is assumed, the amplitude square ${\\left| {{{\\tilde x}_n}} \\right|^2}$ is exponentially distributed with $\\mathbb{E}\\left[ {{{\\left| {{{\\tilde x}_n}} \\right|}^2}} \\right] = 1$. Using the moment generating function, we have\n\n\\begin{equation}\\label{eqn:modulation_gain}\n  \\mathbb{E}\\left[ {{{\\left| {{{\\tilde x}_n}} \\right|}^4}} \\right] = \\mathbb{E}\\left[ {{{\\left( {{{\\left| {{{\\tilde x}_n}} \\right|}^2}} \\right)}^2}} \\right] = 2\n\\end{equation}\n\nThis modulation gain measures the contribution of modulated waveform on the output current, which does not apply to multisine waveform. Following \\cite{Clerckx2018}, we can obtain the expectation of the received information waveform to the second and fourth orders\n\n\\begin{align}\\label{eqn:information_waveform_second_order}\n  \\mathbb{E}\\left[ {{y_I}{{(t)}^2}} \\right] &= \\frac{1}{2}\\sum\\limits_{n = 0}^{N - 1} {\\sum\\limits_{{m_0},{m_1}} {{s_{I,n,{m_0}}}} } {s_{I,n,{m_1}}}{A_{n,{m_0}}}{A_{n,{m_1}}}\\cos \\left( {{\\psi _{I,n,{m_0}}} - {\\psi _{I,n,{m_1}}}} \\right) \\\\\n   &= \\frac{1}{2}\\sum\\limits_{n = 0}^{N - 1} {{{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{I,n}}} \\right|}^2}}\n\\end{align}\n\n\\begin{align}\\label{eqn:information_waveform_fourth_order}\n  \\mathbb{E}\\left[ {{y_I}{{(t)}^4}} \\right] &= \\frac{6}{8}\\sum\\limits_{{n_0},{n_1}} {\\sum\\limits_{{m_0},{m_1},{m_2},{m_3}} {\\left[ {\\prod\\limits_{j = 0,2} {{s_{I,{n_0},{m_j}}}{A_{{n_0},{m_j}}}} } \\right]\\left[ {\\prod\\limits_{j = 1,3} {{s_{I,{n_1},{m_j}}}{A_{{n_1},{m_j}}}} } \\right]} } \\nonumber \\\\\n   &\\quad \\cos \\left( {{\\psi _{I,{n_0},{m_0}}} + {\\psi _{I,{n_1},{m_1}}} - {\\psi _{I,{n_0},{m_2}}} - {\\psi _{I,{n_1},{m_3}}}} \\right) \\\\\n   &= \\frac{6}{8}{\\left[ {\\sum\\limits_{n = 0}^{N - 1} {{{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{I,n}}} \\right|}^2}} } \\right]^2} \\label{eqn:waveform_end}\n\\end{align}\n\nIt is worth noting that the truncation order ${n_o}$ in \\eqref{eqn:current_information} determines the relationship between the received signal and the harvested power. On top of it, \\cite{Clerckx2016} proposed two diode models:\n\n\\begin{itemize}\n  \\item \\textit{diode linear model} (${n_o} = 2$) is the conventional perspective that assumes the total output power is the sum of the subband power. It omits the rectifier nonlinearity and is typically suitable for very low input power (below -30 dBm).\n  \\item \\textit{diode nonlinear model} (${n_o} > 2$) considers the contributions of higher-order terms to the harvested power. It captures the nonlinear behavior of the diode with the product terms\n      modeling the cross contribution of different frequencies (as indicated by ${{n_0},{n_1}}$ in \\eqref{eqn:information_waveform_fourth_order} and \\eqref{eqn:power_waveform_fourth_order}). The model is complicated but accurate, which especially fits the low power regime between -30 dBm and 0 dBm.\n\\end{itemize}\n\nIn the diode linear model corresponding to \\eqref{eqn:power_waveform_second_order} and \\eqref{eqn:information_waveform_second_order}, the output current is only a function of $\\sum\\limits_{n = 0}^{N - 1} {{{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{P/I,n}}} \\right|}^2}} $. Hence, it appears that multi-carrier multisine and modulated waveforms are equally suitable for WPT. On the other hand, the diode nonlinear model highlights a clear difference between the power delivered by both waveforms. For the modulated component, the second and fourth order terms in \\eqref{eqn:information_waveform_second_order} and \\eqref{eqn:information_waveform_fourth_order} share same dependencies on ${\\sum\\limits_{n = 0}^{N - 1} {{{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{I,n}}} \\right|}^2}} }$. It implies that for a modulated waveform with CSCG inputs, the higher order terms behave similarly to the second order term, and there is no essential difference between both models. In comparison, for the multisine waveform, the parts \\eqref{eqn:power_waveform_second_order} and \\eqref{eqn:power_waveform_fourth_order} are decomposed as the product of contributions from different subbands. Also, the second order term is a linear sum over each frequency while the nonlinear fourth order term shows some cross correlation between different subbands.\n\nIn this paper, we set ${n_o} = 4$ to explore the fundamental nonlinear behaviour of the diode and its impact on the harvested current. Therefore, the approximated output DC current \\eqref{eqn:output_current_function} reduces to\n\n\\begin{align}\\label{eqn:output_current_truncated}\n  {i_{\\text{out}}} &\\approx k_0^\\prime  + k_2^\\prime \\rho {R_{{\\text{ant}}}}\\mathbb{E}\\left[ {{y_P}{{(t)}^2}} \\right] + k_4^\\prime {\\rho ^2}R_{ant}^2\\mathbb{E}\\left[ {{y_P}{{(t)}^4}} \\right] \\nonumber \\\\\n   &\\quad + k_2^\\prime \\rho {R_{{\\text{ant}}}}\\mathbb{E}\\left[ {{y_I}{{(t)}^2}} \\right] + k_4^\\prime {\\rho ^2}R_{ant}^2\\mathbb{E}\\left[ {{y_I}{{(t)}^4}} \\right] \\nonumber \\\\\n   &\\quad + 6k_4^\\prime {\\rho ^2}R_{{\\text{ant}}}^2\\mathbb{E}\\left[ {{y_P}{{(t)}^2}} \\right]\\mathbb{E}\\left[ {{y_I}{{(t)}^2}} \\right]\n\\end{align}\n\nwhose corresponding target function is\n\n\\begin{align}\\label{eqn:target_function_truncated}\n  {z_{\\text{DC}}} &\\approx k_0  + k_2 \\rho {R_{{\\text{ant}}}}\\mathbb{E}\\left[ {{y_P}{{(t)}^2}} \\right] + k_4 {\\rho ^2}R_{ant}^2\\mathbb{E}\\left[ {{y_P}{{(t)}^4}} \\right] \\nonumber \\\\\n   &\\quad + k_2 \\rho {R_{{\\text{ant}}}}\\mathbb{E}\\left[ {{y_I}{{(t)}^2}} \\right] + k_4 {\\rho ^2}R_{ant}^2\\mathbb{E}\\left[ {{y_I}{{(t)}^4}} \\right] \\nonumber \\\\\n   &\\quad + 6k_4 {\\rho ^2}R_{{\\text{ant}}}^2\\mathbb{E}\\left[ {{y_P}{{(t)}^2}} \\right]\\mathbb{E}\\left[ {{y_I}{{(t)}^2}} \\right]\n\\end{align} ", "meta": {"hexsha": "9448600161629de8b8c1c9535c0ae431a9c67a06", "size": 17503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/thesis/from-wpt-to-wipt/signal-and-system-model.tex", "max_stars_repo_name": "SnowzTail/signal-optimisation-for-wireless-information-and-power-transmission", "max_stars_repo_head_hexsha": "f53382f99610becd8d78ee34cc9c3d49d2c7f61b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-07-10T21:31:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T18:01:41.000Z", "max_issues_repo_path": "tex/thesis/from-wpt-to-wipt/signal-and-system-model.tex", "max_issues_repo_name": "SnowzTail/signal-optimisation-for-wireless-information-and-power-transmission", "max_issues_repo_head_hexsha": "f53382f99610becd8d78ee34cc9c3d49d2c7f61b", "max_issues_repo_licenses": ["MIT"], "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/thesis/from-wpt-to-wipt/signal-and-system-model.tex", "max_forks_repo_name": "SnowzTail/signal-optimisation-for-wireless-information-and-power-transmission", "max_forks_repo_head_hexsha": "f53382f99610becd8d78ee34cc9c3d49d2c7f61b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-12T23:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T18:01:46.000Z", "avg_line_length": 92.1210526316, "max_line_length": 1329, "alphanum_fraction": 0.6581728846, "num_tokens": 6389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.666908020697884}}
{"text": "\\documentclass[12pt]{extarticle}\n\n\\usepackage{geometry}\n\\geometry{\n\tletterpaper,\n\tleft=20mm,\n\tright=20mm,\n\ttop=20mm,\n}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\begin{document}\n\\section{Parameters}%\n\\label{sec:Parameters}\n\n\\subsection{Data}\n\\label{sub:Data}\n\\begin{itemize}\n\t\\item $P$: set of all persons (rowers),\n\t\\item $B$: set of all boats,\n\t\\item $T$: set of all training times of the week (day and time),\n\t\\item $B_p$: set of boats that person $p$ can row (based on her skill and weight class),\n\t\\item $T_p$: set of times the person $p$ is likely to row (union of her first and second choices),\n\t\\item $nb\\_asked_p$: number of training person $p$ wants to have in the week (number of first choices),\n\t\\item $E$: set of sets of exclusive training times. Used for non-compatible training sessions, for examples training times that are directly consecutive,\n\t\\item $u_{pt}$: utility for person $p$ of rowing at time $t$. Values used are $1$ if first choice, $0.1$ if second choice, not defined if $t$ not in choices of $p$.\n\\end{itemize}\n\n\\subsection{Variables}%\n\\label{sub:Variables}\n\\begin{itemize}\n\t\\item $s \\in \\mathbb{R}$: minimal utility across all people,\n\t\\item $x_{pbt} \\in \\{0, 1\\}$: binary variable, $1$ if person $p$ is scheduled to row boat $b$ at time $t$, $0$ otherwise.\n\\end{itemize}\n\n\n\\section{Model}%\n\\label{sec:Model}\n\n\n\\begin{align}\n\t\\max_{x, s} \\quad\t\t\t& \\lambda s + \\sum_{p \\in P} \\sum_{b \\in B_p} \\sum_{t \\in T_p} u_{pt} x_{pbt}\t& \\label{eq:obj}\\\\\n\t\\text{subject to:} \\qquad\t& s \\leq \\sum_{b \\in B_p} \\sum_{t \\in T_p} u_{pt} x_{pbt} \t\t\t\t\t\t& \\forall p \\in P \\label{eq:min-util}\\\\\n\t\t\t\t\t\t\t\t& \\sum_{b \\in B_p} \\sum_{t \\in T_p} x_{pbt} \\leq nb\\_asked_p\t\t\t\t\t& \\forall p \\in P \\label{eq:training-upper}\\\\\n\t\t\t\t\t\t\t\t& \\sum_{b \\in B_p} x_{pbt} \\leq 1\t\t\t\t\t\t\t\t\t\t\t\t& \\forall p \\in P, t \\in T_p \\label{eq:only-one-boat}\\\\\n\t\t\t\t\t\t\t\t& \\sum_{b \\in B_p} \\sum_{t \\in E} x_{pbt} \\leq 1\t\t\t\t\t\t\t\t& \\forall p \\in P \\label{eq:exclusive-times}\\\\\n\t\t\t\t\t\t\t\t& \\sum_{p \\in P(b,t)} x_{pbt} \\leq 1\t\t\t\t\t\t\t\t\t\t\t& \\forall b \\in B, \\forall t \\in T \\label{eq:only-one-person}\n\\end{align}\n\n\\section{Explainations}%\n\\label{sec:Explainations}\n\nThis model is run weekly. A few days in advance, rowers submit their schedule preferences via an online form.\nThese preferences consist of \"first choices\", that correspond to when a rowers would ideally want to row, and \"second choices\", which are backup times at which they would be available, in case it's not possible for them to row one of their \"first choice\".\\\\\n\n\\noindent More details about the objective function and the constraints:\n\\begin{itemize}\n\t\\item \\eqref{eq:obj}: The objective function is made of two components. The first one $\\lambda s$ maximizes the lowest utility value that a person gets. The second one maximizes the sum of utilities across all people. The coefficient $\\lambda$ should be large enough to ensure that the maximum value of $s$ is reached before optimizing the sum of utilities. This is to ensure fairness, i.e. make sure it's not possible that a small set of people receive a schedule with very low utility value, just to maximize the overall utility. The minimal value of this coefficient can be computed, but I've been using $500$ which I am sure is enough for the size of my problem, and does not hit the CPU time in a significant way,\n\t\\item \\eqref{eq:min-util}: ensure that $s$ is the minimum utility across people,\n\t\\item \\eqref{eq:training-upper}: cap the max number of training at the number of trainings asked for each person. We don't want the utility to be increased by assigning more trainings to someone than they asked,\n\t\\item \\eqref{eq:only-one-boat}: one person can only row one boat per training (otherwise, would increase utility artificially),\n\t\\item \\eqref{eq:exclusive-times}: ensure that we don't assign someone to training that are mutually exclusive (according to $E$),\n\t\\item \\eqref{eq:only-one-person}: each boat can only accommodate one person per training.\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "2de0b1af78848ed9507066b1767c744bd8532852", "size": 3982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "details/model.tex", "max_stars_repo_name": "aurelienserre/boat_allocator", "max_stars_repo_head_hexsha": "cabfce17a868b75e63b1b65c42062e6cf3b3610c", "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": "details/model.tex", "max_issues_repo_name": "aurelienserre/boat_allocator", "max_issues_repo_head_hexsha": "cabfce17a868b75e63b1b65c42062e6cf3b3610c", "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": "details/model.tex", "max_forks_repo_name": "aurelienserre/boat_allocator", "max_forks_repo_head_hexsha": "cabfce17a868b75e63b1b65c42062e6cf3b3610c", "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.5588235294, "max_line_length": 719, "alphanum_fraction": 0.7114515319, "num_tokens": 1189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.66690801571089}}
{"text": "%---------------------------Jacobian---------------------------\n\\section{Jacobian}\n\nThis is the minimum determinant of the Jacobian matrix evaluated at each corner and the center of the element:\n\\[\nq = \\min\\left\\{\\left\\{\\alpha_i\\right\\}_{i=0}^7, \\frac{\\alpha_8}{64} \\right\\}.\n\\]\nThis can also be interpreted as the minimum pointwise volume of local map\nat the 8 corners and the center of the hexahedron.\n\n\\hexmetrictable{Jacobian}%\n{$L^3$}%                                      Dimension\n{$[0,DBL\\_MAX]$}%                             Acceptable range\n{$[0,DBL\\_MAX]$}%                             Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%                     Full range\n{$1$}%                                        Cube\n{\\cite{knu:00}}%                              Citation\n{v\\_hex\\_jacobian}%                           Verdict function name\n", "meta": {"hexsha": "78ae2b5ae4563f65f54259eaca2dc93d0f45561a", "size": 841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexJacobian.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/HexJacobian.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/HexJacobian.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": 44.2631578947, "max_line_length": 110, "alphanum_fraction": 0.4922711058, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6669053230150398}}
{"text": "\\documentclass[11pt]{article}\r\n\r\n\\usepackage{a4wide}\r\n\\usepackage{amsmath}\r\n\\setlength{\\parindent}{0pt}\r\n\r\n\\begin{document}\r\n\r\n    \\pagestyle{empty}\r\n    \\vspace*{-9em}\r\n\r\n    \\title{Useful Inequalities}\r\n    \\author{Carlos Luna-Mota}\r\n    \\date{\\today}\r\n    \r\n    \\begin{center}\r\n        \\section*{\\Huge Useful Inequalities}\r\n    \\end{center}\r\n\r\n    \\vspace*{2em}\r\n\r\n        For any pair of sorted sequences of real numbers of equal length ($x_0 \\leq x_1 \\leq \\dots \\leq x_n$ and $y_0 \\leq y_1 \\leq \\dots \\leq y_n$) and for any arbitrary permutation $\\sigma$ of their index set:\\bigskip\r\n\r\n        \\paragraph{Rearrangement Inequality:} $\\displaystyle \\boxed{\\sum x_i y_{n-i} \\;\\leq\\; \\sum x_i y_{\\sigma(i)} \\;\\leq\\; \\sum x_i y_i}$ \\bigskip\r\n\r\n        with the equality holding if and only if the permutated $y_i$ are equal. \\bigskip\r\n\r\n    \\hrulefill \\bigskip\r\n\r\n        For any pair of finite or infinite sequences of real numbers ($x_1, x_2, \\dots$ and $y_1, y_2, \\dots$) and for any set of non-negative weights $w_i\\geq0$:\r\n\r\n        \\paragraph{Weighted Cauchy-Schwarz Inequality:} $\\displaystyle \\boxed{\\left( \\sum w_i x_i y_i\\right)^2 \\;\\leq\\;\\left(\\sum w_i x^2_i\\right) \\left(\\sum w_i y^2_i\\right)}$ \\bigskip\r\n\r\n        with equality if and only if $\\vec x$ and $\\vec y$ are linearly dependent.\r\n\r\n    \\hrulefill \\bigskip\r\n\r\n        For any set of nonnegative weights $w_i \\geq 0$ such that $\\sum w_i = 1$ and any set $x_1, \\dots, x_n$ of nonnegative real numbers:\r\n\r\n        \\paragraph{Weighted AM-GM Inequality:} $\\displaystyle \\boxed{{\\min \\{x_i\\} \\;\\leq\\;} \\prod x_i^{w_i} \\;\\leq\\; \\sum w_i x_i {\\;\\leq\\; \\max \\{x_i\\}}}$ \\bigskip\r\n\r\n        with the middle equality holding if and only if all $x_i$ such that $w_i > 0$ are equal. \\bigskip\r\n\r\n    \\hrulefill \\bigskip\r\n\r\n        For any $m\\times n$ matrix of nonnegative real numbers $x_{ij} \\geq 0\\quad \\forall\\;i\\in\\{1,\\dots, m\\};\\; \\forall\\;j\\in\\{1, \\dots, n\\}$ and any set of $n$ nonnegative weights $w_j \\geq 0$ such that $\\sum w_j = 1$:\r\n        \r\n        \\paragraph{Generalized H\\\"older Inequality:} $\\displaystyle \\boxed{\\sum_{i=1}^{m}{\\left(\\prod_{j=1}^{n} {x_{ij}}^{w_j}\\right)} \\;\\leq\\; \\prod_{j=1}^{n}\\left(\\sum_{i=1}^{m} x_{ij}\\right)^{w_j}}$ \\bigskip\r\n\r\n        with the equality holding if and only if two colums of the $x_{ij}$ matrix are linearly dependent. \\bigskip\r\n\r\n    \\hrulefill \\bigskip\r\n\r\n        For any function $\\phi(x)$ that is convex in a given interval, any set of points $x_1, x_2, \\dots$ of that interval and any set of nonnegative weights $w_i \\geq 0$ such that $\\sum w_i = 1$:  \r\n\r\n        \\paragraph{Weighted Jensen Inequality:} $\\displaystyle \\boxed{\\phi\\left(\\sum w_i x_i\\right) \\;\\leq\\; \\sum w_i \\phi(x_i)}$ \\bigskip\r\n\r\n        A continuous function $\\phi(x)$ is convex in a given interval if and only if, for any $x_1, x_2$ in the interval, it satisfies $\\phi\\left(\\tfrac{x_1+x_2}{2}\\right) \\leq \\tfrac{\\phi(x_1)+\\phi(x_2)}{2}$. In the cases where $\\phi''(x)$ exists, $\\phi(x)$ is convex if $\\phi''(x) \\;\\geq\\;0$ in the interval.\r\n\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "5f47f2f3316f95ab77de101ee93c80e4d6d411c7", "size": 3050, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Inequalities.tex", "max_stars_repo_name": "CarlosLunaMota/Useful-Inequalities", "max_stars_repo_head_hexsha": "ce38aafe6812ca810c0fcb1a5ffccae4186e89a2", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-01T16:39:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-01T16:39:54.000Z", "max_issues_repo_path": "Inequalities.tex", "max_issues_repo_name": "CarlosLunaMota/Useful-Inequalities", "max_issues_repo_head_hexsha": "ce38aafe6812ca810c0fcb1a5ffccae4186e89a2", "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": "Inequalities.tex", "max_forks_repo_name": "CarlosLunaMota/Useful-Inequalities", "max_forks_repo_head_hexsha": "ce38aafe6812ca810c0fcb1a5ffccae4186e89a2", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-09-01T16:39:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-01T16:39:55.000Z", "avg_line_length": 49.1935483871, "max_line_length": 311, "alphanum_fraction": 0.6363934426, "num_tokens": 1049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6668719074306113}}
{"text": "% !TEX root = ../main_lecture_notes.tex\n\\chapter{Decentralization of blockchain system}\\label{chap:decentralization}\nDecentralization represents the fairness of the distribution of the accounting right of the nodes in the blockchain network. The consensus protocol must be designed so that the decision power does not eventually concentrate on a few nodes leading to a centralized system. In leader based consensus protocols, each peer is associated to a probability of being chosen. Measuring decentrality then reduces to computing the entropy of the probability distribution of the random variable equal to the peer selected  \\\\\n\n\\noindent \\cref{sec:decentralization_pos} focuses on the \\PoS protocol by modelling the evolution of the stakes of the nodes by a stochastic process with reinforcement. \\cref{sec:decentralization_pow} presents the concept of mining pool and discusses the threat they represent for the decentralized aspect of the network.\n\n\\section{Decentralization in PoS}\\label{sec:decentralization_pos}\nThe \\textit{Proof-of-Stake} protocol is a leader based consensus protocol that appoints a block validator depending on how many cryptocoins he owned which corresponds to its stake. In its most basic form a coins is drawn at random, the owner of that coin appends a block and collect a reward. The stake of each peers is governed by stochastic processes with reinforcement similar to that studied in the Polya's urn problem. In Polya's urn, there are balls of various colors. At each time step a ball is drawn, the ball is then replaced in the urn together with a ball of the same color. The coins are the balls and the color is the peer that owns the balls. This analogy has been used to study the decentralization\\\\\n\n\\noindent Let the network be of size $p$ and denote by $r$ the reward collected at each round $n\\in\\mathbb{N}$ by the lucky node $x\\in \\{1, \\ldots, p\\} = E$. At time $n=0$, each peer $x\\in E$ has $Z^{(x)}_0$ coins so that the total number of coins is $Z_0 = \\sum_{x\\in E}Z^{(x)}_0$. The number of coins owned by each peers evolve over time as\n$$\nZ^{(x)}_n = Z^{(x)}_0 + r\\sum_{k = 1}^n\\mathbb{I}_{A_{k}^{(x)}}\\text{ and }Z_n = \\sum_{x\\in E}Z^{(x)}_n = Z_0 + nr,    \n$$\nwhere $A_{n}^{(x)}$ is the event that a coin own by peer $x\\in E$ is drawn at time $n\\in\\mathbb{N}$. Let $(Z_n^{(x)})_{n\\geq0}$ be the proportion of coins owned by peer $x$ at time $n$, given by \n$$\nW_n^{(x)} = \\frac{Z^{(x)}_n}{Z_n}. \n$$\nLet $\\mathcal{F}_n = \\sigma(\\{Y_k^{(x)}\\text{ , }x\\in E, k\\leq n\\})$. Note that \n$$\n\\mathbb{P}\\left(A_{n}^{(x)}|\\mathcal{F}_{n-1}\\right) = W_{n-1}^{(x)}.\n$$\n\\subsection{Average stake owned by each peer}\nThe following result provide the average behaviour of the share of coins owned by each peer.\n\\begin{prop}\\label{prop:average_stakes}\n$$\n\\mathbb{E}(W_n^{(x)}) = \\frac{Z_0^{(x)}}{Z_0},\\text{ }x\\in E\\text{ }, n\\geq0.\n$$\n\\end{prop}\n\\begin{proof}\nWe show that $(W_n^{(x)})_{n\\geq0}$ is a martingale. We have that \n\\begin{eqnarray*}\n\\mathbb{E}\\left[W_n^{(x)}|\\mathcal{F}_{n-1}\\right]&=& \\mathbb{E}\\left[\\frac{Z^{(x)}_{n-1} + r\\mathbb{I}_{A_n^{(x)}}}{Z_0 + rn}\\Big \\rvert\\mathcal{F}_{n-1}\\right]\\\\\n&=& \\frac{Z^{(x)}_{n-1} }{Z_0 + rn}+\\frac{rW_{n-1}^{x}}{Z_0 + rn}\\\\\\\n&=& \\frac{Z^{(x)}[Z_0 + r(n-1)]}{Z_0 + rn}+\\frac{rW_{n-1}^{x}}{Z_0 + rn}\\\\\n&=&W_{n-1}^{x}.\n\\end{eqnarray*}\nIt then follows that \n$$\n\\mathbb{E}\\left(W_n^{(x)}\\right) = \\frac{Z_0^{(x)}}{Z_0},\\text{ }x\\in E\\text{ }, n\\geq0.\n$$\n\\end{proof}\nThe long term average of the stake of each peer is stable, we focus on their asymptotic distribution in the following section.\n\\subsection{Asymptotic distribution of the stakes}\\label{ssec:stakes_distribution}\nTo go beyond the mean and study the distribution of the stake of the peers, we have to consider the case $r = 1$. We can then show that the joint distribution of $(W_\\infty^{(1)},\\ldots,  W_\\infty^{(p)})$ is the Dirichlet one. \n% \\begin{definition}\\label{def:dirichlet}\n% A random variable $X$ has a gamma distribution $\\text{Gamma}(\\alpha,\\beta)$ if it has \\pdf\n% \\[\n% f(x) = \n% \\begin{cases}\n% \\frac{e^{-\\beta x}x^{\\alpha-1}\\beta^{\\alpha}}{\\Gamma(\\alpha)},& x>0, \\\\\n% 0,&\\text{ otherwise}, \n% \\end{cases}\n% \\]\n% where $\\Gamma(\\alpha) = \\int_0^{\\infty}e^{-x}x^{\\alpha-1}\\text{d}x$ is the gamma function.\n% \\end{definition}\n\\begin{definition}\\label{def:dirichlet}\nA random vector $(W_1,\\ldots, W_p)$ has a Dirichlet distribution $\\text{Dir}(\\alpha_1,\\ldots, \\alpha_p)$ if it has a joint \\pdf given by \n\\begin{equation}\\label{eq:dirichlet_pdf}\nf(w_1,\\ldots, w_p;\\alpha_1,\\ldots, \\alpha_p) = \\frac{1}{B(\\alpha)}\\prod_{i=1}^p w_i^{\\alpha_i-1}, \n\\end{equation}\nfor $\\alpha_1,\\ldots, \\alpha_p>0$, $0< w_1,\\ldots, w_p <1$ and $\\sum_{i=1}^pw_i=1$, where \n$$\nB(\\alpha) = \\frac{\\prod_{i = 1}^p \\Gamma(\\alpha_i)}{\\Gamma(\\sum_{i=1}^p \\alpha_i)},\n$$\nand $\\Gamma(\\alpha) = \\int_{0}^{\\infty}\\e^{-x}x^{\\alpha-1}\\text{d}x$ is the gamma function.\n\\end{definition}\n\\noindent A Dirichlet random vector can be generated by independent Gamma random variables. Recall that $X\\sim\\GammaDist(\\alpha, \\beta)$ if $X$ has \\pdf\n\\begin{equation}\\label{eq:gamma_pdf}\nf_{X}(x) = \\begin{cases}\n\\frac{e^{-\\beta x}x^{\\alpha-1}\\beta^\\alpha}{\\Gamma(\\alpha_i)},&\nx>0\\\\\n0,&\\text{otherwise}.\\end{cases}\n\\end{equation}\n\n\\begin{prop}\\label{prop:gamma_to_dirichlet}\nLet $X_i\\sim \\GammaDist(\\alpha_i,1)$ for $i = 1,\\ldots, p$ be independent ranodm variables then \n\\[\n\\left(\\frac{X_1}{\\sum_{i=1}^{p}X_i},\\ldots, \\frac{X_p}{\\sum_{i=1}^{p}X_i}\\right)\\sim\\text{Dir}(\\alpha_1,\\ldots, \\alpha_p)\n\\]\n\\end{prop}\n\\begin{proof}\nNote that because $(w_1,\\ldots, w_p)$ belongs to the $p-1$ simplex then the \\pdf \\eqref{eq:dirichlet_pdf} may be rewritten as \n$$\nf(w_1,\\ldots, w_p;\\alpha_1,\\ldots, \\alpha_p) = \\frac{1}{B(\\alpha)}\\prod_{i=1}^{p-1} w_i^{\\alpha_i-1}\\left(1-\\sum_{i=1}^{p-1} w_i\\right)^{\\alpha_p-1}, \n$$\nwhich means that we are only interested in the distribution of the vector $\\left(W_1,\\ldots, W_{p-1}\\right) = \\left(X_{1}/\\sum_{i=1}^{p}X_i,\\ldots, X_{p-1}/\\sum_{i=1}^{p}X_i\\right)$.\nLet $g:\\mathbb{R}^p\\mapsto \\mathbb{R}^+$ be measurable and bounded and consider\n\\begin{eqnarray*}\n&&\\mathbb{E}\\left[g\\left(\\frac{X_1}{\\sum_{i=1}^{p}X_i},\\ldots, \\frac{X_{p-1}}{\\sum_{i=1}^{p}X_i}\\right)\\right]\\\\\n&=&\\int_{\\mathbb{R_+^p}}g\\left(\\frac{x_1}{\\sum_{i=1}^{p}x_i},\\ldots, \\frac{x_{p-1}}{\\sum_{i=1}^{p}x_i}\\right)\\frac{e^{-\\sum_{i}^px_i}\\prod_{i=1}^px_i^{\\alpha_i-1}}{\\prod_{i=1}^p\\Gamma(\\alpha_i)}\\text{d}\\lambda(x_1,\\ldots, x_p)\n\\end{eqnarray*}\nWe use the change of variable \n\\[\n\\Phi:(w_1,\\ldots, w_{p-1}, v) \\mapsto \\left[vw_1,\\ldots, vw_{p-1}, v\\left(1-\\sum_{i=1}^{p-1}w_i\\right)\\right] = \\left(x_1, \\ldots, x_{p-1},\\sum_{i=1}^{p}x_i\\right)   \n\\]\nminding the change in the integration domain as \n$$\n\\Phi(\\Delta_{p-1}\\times \\mathbb{R}_+) = \\mathbb{R}^p_+ ,\n$$\n$\\Delta_{p-1}$ is the $p-1$ simplex and the Jacobian $\\left|\\frac{\\text{d}\\Phi}{\\text{d}(w_1,\\ldots, w_{p-1},v)}\\right|=v^{p-1}$, we get \n \\begin{eqnarray*}\n &&\\mathbb{E}\\left[g\\left(\\frac{X_1}{\\sum_{i=1}^{p}X_i},\\ldots, \\frac{X_{p-1}}{\\sum_{i=1}^{p}X_i}\\right)\\right]\\\\\n&=&\\int_{\\Delta_{p-1}}\\int_{\\mathbb{R}_+}g\\left(w_1,\\ldots, w_{p-1}\\right) \\frac{e^{- v}\\prod_{i=1}^{p-1}w_i^{\\alpha_i-1}\\left(1-\\sum_{i=1}^{p-1}w_i\\right)^{\\alpha_p-1}v^{\\sum_{i=1}^{p-1}\\alpha_i-1}}\n{\\prod_{i=1}^p\\Gamma(\\alpha_i)}\\text{d}\\lambda(w_1,\\ldots, w_{p-1}, v)\\\\\n&=&\\int_{\\Delta_{p-1}}g\\left(w_1,\\ldots, w_{p-1}\\right) \\frac{\\Gamma\\left(\\sum_{i =1}^{p}\\alpha_i\\right)}{\\prod_{i=1}^p\\Gamma(\\alpha_i)}\\prod_{i=1}^{p-1}w_i^{\\alpha_i-1}\\left(1-\\sum_{i=1}^{p-1}w_i\\right)^{\\alpha_p-1}\\text{d}\\lambda(w_1,\\ldots, w_{p-1}).\n\\end{eqnarray*} \n\\end{proof}\nTo show that the stochastic process $(W_n^{(1)},\\ldots, W_n^{(p)})$ has a Dirichlet limiting distribution we need to introduce a counting process known as Yule process.\n\\begin{definition}\\label{def:yule_process}\nA Yule process $(Y_t)_{t\\geq0}$ is a pure birth process with linear birth rate given as \n\\[\n\\mathbb{P}(Y_{t+h} = y+1|Y_{t} =y) = nh+o(h).\n\\] \n\\end{definition}\nThe Yule process models the population of some particle over time, assuming that there is one particle at time $0$, so $Y_0=1$ this particle will split in two after some exponential time and this going on and on, see the illustration on \\cref{fig:yule_tree}. \n\n%définitiondesstyles \n\\tikzstyle{lien}=[-,>=stealth',rounded corners=5pt,thick] \\tikzset{individu/.style={draw,thick}, individu/.default={green}} \n%définitiondel’arbre \n\\begin{figure}[!ht]\n\\begin{center}\n\\begin{tikzpicture} \n\\node[individu] (1) at (0,0) {}; \n\\node[individu] (11) at (-3,-2) {}; \n\\node[individu] (12) at (3,-2) {}; \n\\node[individu] (111) at (-4.5,-4) {}; \n\\node[individu] (112) at (-1.5,-4) {}; \n\\node[individu] (1121) at (-2,-6.5) {}; \n\\node[individu] (1122) at (-1,-6.5) {}; \n\\node[individu] (121) at (1.5,-8) {}; \n\\node[individu] (122) at (4.5,-8) {}; \n\\draw[lien] (1) |- (-1,-1.7)  coordinate[label = {above:$\\ExpDist(1)$}] -|  (11); \n\\draw[lien] (1) |- (1,-1.7)-| (12); \n\\draw[lien] (11) |- (-3.5,-3.7) coordinate[label = {above:$\\ExpDist(1)$}]-| (111); \n\\draw[lien] (11) |- (-2.5,-3.7)-| (112); \n\\draw[lien] (112) |- (-1.5,-6.2) coordinate[label = {above left:$\\ExpDist(1)$}]-| (1121); \n\\draw[lien] (112) |- (-1.5,-6.2)-| (1122);\n\\draw[lien] (12) |- (2.5,-7.7) coordinate[label = {above:$\\ExpDist(1)$}]-| (121); \n\\draw[lien] (12) |- (3.5,-7.7)-| (122);\n\\draw (122) -- (4.5,-9);\n\\draw (121) -- (1.5,-9);\n\\draw (111) -- (-4.5,-9);\n\\draw (1121) -- (-2,-9);\n\\draw (1122) -- (-1,-9);\n\\draw[->] (-5,0) -- (-5,-10) coordinate[label = {below:$t$}] (xmax);\n\\draw[-, thick, dashed] (-5.5,-7) coordinate[label = {below left:$Y_t = 4$}] -- (5,-7)  (xmax);\n\\end{tikzpicture}\n\\caption{Yule tree}\n\\label{fig:yule_tree}\n\\end{center}\n\\end{figure}\nBefore moving forward, two remarks.\n\\begin{remark}\\label{rem:yule_process_initial}\nIf we have $Y_0 = y_0$ particles at the initial state, then it is like starting $y_0$ independent copies of the Yule process with one particle and summing up at time $t$ the number of particles of all the Yule processes. Namely, let $(Y_t)_{t\\geq0}$ be a Yule process such that $Y_0 = y_0$, then\n$$\nY_t = \\sum_{i = 1}^{y_0}Y_t^{(i)},\n$$   \nwhere the $Y_t^{(i)}$'s are independent Yule processes such that $Y_t^{(i)}=1$ for $i = 1,\\ldots, y_0$.\n\\end{remark}\n\\begin{remark}\\label{rem:stopped_yule_process}\nThe Yule process $(Y_t)_{t\\geq0}$ is strong Markov in the sense that for any stopping time $\\tau$, the stopped process \n$$\n\\tilde{Y}_t = Y_{\\tau+t},\\text{ }t\\geq0\n$$\nis again a Yule process such that $\\tilde{Y}_0 = Y_\\tau$.\n\\end{remark}\n\\begin{prop}\\label{prop:yule_process_dist}\nLet $(Y_t)_{t\\geq0}$ be a Yule process such that $Y_0 = 1$ then \n$$\n\\mathbb{P}(Y_t = y) = \\left(1-\\e^{-t}\\right)^{y-1}e^{-t}.\n$$\n\n\\end{prop}\n\\begin{proof}\nThe inter-arrival times $(\\Delta^T_n)_{n\\geq1}$ of the Yule process are independent random variable such that $\\Delta^T_n = \\ExpDist(n)$. If we have $n$ particles at some time $t\\geq0$, that's $n$ exponential $\\ExpDist(1)$ competing and a new particle appears as soon as one of them ring. We then have $\\Delta^T_n = \\min(X_1,\\ldots, X_{n})$, where $X_1,\\ldots, X_n \\overset{\\text{i.i.d.}}{\\sim}\\ExpDist(1)$ and so $\\Delta^T_n \\sim \\ExpDist(n)$. The arrival time of the $n^{th}$ particles is given by   \n$$\nT_n = \\sum_{k =1}^{n-1}\\Delta^T_k,\\text{ }n\\geq2.\n$$\nBy induction on $n\\geq2$, we can show that \n\\[\n\\mathbb{P}(T_n\\leq t) = \\left(1-e^{-t}\\right)^{n-1}.\n\\]\nWe further deduce that \n\\[\n\\mathbb{P}(Y_t = y) = \\mathbb{P}(Y_t > y) - \\mathbb{P}(Y_t > y+1) = \\mathbb{P}(T_{y} \\leq t) - \\mathbb{P}(T_{y+1} \\leq t)=\\left(1-\\e^{-t}\\right)^{y-1}e^{-t}   \n\\]\n\\end{proof}\n\\begin{theo}\\label{theo:convergence_yule_process}\nWe have that \n\\[\ne^{-t}Y_t\\overset{\\mathcal{D}}{\\longrightarrow}\\ExpDist(1),\\text{ as }t\\rightarrow \\infty.\n\\]\n\\end{theo}\n\\begin{proof}\nLet us show that $\\left(e^{-t}Y_t\\right)_{t\\geq0}$ is a martingale. We have that, for $s\\leq t$, \n\\[\n\\mathbb{E}(e^{-t}Y_t|\\mathcal{F}_s) = e^{-t}\\mathbb{E}(Y_t|\\mathcal{F}_s) = e^{-t}Y_se^{t-s} = e^{-s}Y_s.\n\\]\nBecause of the martingale convergence theorem, we know that $\\left(e^{-t}Y_t\\right)_{t\\geq0}$ has a limiting distribution. Consider the Laplace transform \n\\[\n\\mathbb{E}\\left(\\e^{-\\theta e^{-t}Y_t}\\right) = \\frac{\\e^{-\\theta \\e^{-t}}\\e^{-t} }{1-\\e^{-\\theta \\e^{-t}}(1-\\e^{-t})}=\\frac{1}{e^t\\left(\\e^{\\theta\\e^{-1}}-1\\right)+1}\\rightarrow\\frac{1}{1+\\theta},\\text{ as }t\\rightarrow\\infty.\n\\]\nwhich coincides with that of an exponential random variable $\\ExpDist(1)$.\n\n\\end{proof}\nWe finally link the asymptotic behavior of the Yule processes to our initial question about the asymptotic distributions of the stakes.\n\\begin{theo}\nWe have that \n\\[\n\\left(W_\\infty^{(1)},\\ldots, W_\\infty^{(p)}\\right)\\sim\\text{Dir}\\left(Z_0^{(1)},\\ldots, Z_0^{(p)}\\right).\n\\]\n\\end{theo}\n\\begin{proof}\nAssume that each coin owned at time $n=0$ is like the initial particle of a Yule process. That's $Z_0$ Yule processes $(Y_t^{i,j})_{t\\geq0}$ for $i = 1, \\ldots, Z_0^{(j)}$ and $j = 1,\\ldots, p$. Each time step $n$ corresponds to the jump of one of the Yule processes $\\tau_n$. The number of coins owned by peer $j=1,\\ldots, p$ is then \n\\[\nZ_n^{(j)} = \\sum_{i=1}^{Z_0^{(j)}} Y^{i,j}_{\\tau_n},\n\\]\nwe have $\\tau_n\\rightarrow\\infty$ as $n\\rightarrow\\infty$ and therefore \n\\[\ne^{-\\tau_n}Z_n^{(j)} = \\sum_{i=1}^{Z_0^{(j)}} Y^{i,j}_{\\tau_n}e^{-\\tau_n}\\overset{\\mathcal{D}}{\\longrightarrow} \\GammaDist\\left(Z_0^{(j)}, 1\\right),\\text{ as }n\\rightarrow\\infty\n\\]\nFinally \n\\[\n\\left(W_n^{(1)},\\ldots, W_n^{(p)}\\right) = \\left(\\frac{e^{-\\tau_n}Z_n^{(1)}}{\\sum_{j=1}^{p}e^{-\\tau_n}Z_n^{(j)}},\\ldots, \\frac{e^{-\\tau_n}Z_n^{(p)}}{\\sum_{j=1}^{p}e^{-\\tau_n}Z_n^{(j)}}\\right)\\overset{\\mathcal{D}}{\\longrightarrow}\\text{Dir}(Z_0^{(1)},\\ldots, Z_0^{(p)})\n,\\text{ as }n\\rightarrow\\infty.\n\\]\n\\end{proof}\n\\begin{remark}\\label{req:alternative_proof}\nOne can take a shorter road to show the above result. Let $(X_n)_{n\\geq1}$ be the color of the ball drawn during the $n^{th}$ round. We have that \n\\begin{equation}\\label{eq:polya_sequence_1}\n\\mathbb{P}(X_1=x) = \\frac{Z_0^{(x)}}{Z_{0}}\n\\end{equation}\nand \n\\begin{equation}\\label{eq:polya_sequence_2}\n\\mathbb{P}(X_{n+1}=x) = \\frac{Z_0^{(x)} + \\sum_{i=1}^n\\delta_{X_i}(x)}{Z_0+n} = \\frac{Z_0^{(x)} + \\lambda_n(x)}{Z_0+n} = m_n(x)\n\\end{equation}\nwhere $\\delta_{X_i}$ denotes the Dirac measure at $X_i$.\nA sequence that satisfies \\eqref{eq:polya_sequence_1} and \\eqref{eq:polya_sequence_2} is said to be a Polya sequence with parameter $N_x\\text{, }x\\in E$.\n\\begin{lemma}\nThe following statements are equivalent:\n\\begin{itemize}\n\\item[(i)] $X_1,X_2,\\ldots,$ is a Polya sequence\n\\item[(ii)] $\\mu^{\\ast}\\sim \\text{Dir}(N_x,x\\in E)$ and $X_1,X_2,\\ldots$ given $\\mu^\\ast$ are \\iid as $\\mu^\\ast$\n\\end{itemize}\n\\end{lemma}\nConsider the event $A_n = \\{X_1 = x_1,\\ldots, X_n = x_n\\}$. Induction on $n$ allows us to show that (i) is equivalent to \n\\begin{equation}\\label{eq:P_A_polya_i}\n\\mathbb{P}(A_n) = \\frac{\\prod_{x\\in E} \\left(Z_0^{(x)}\\right)^{[\\lambda_n(x)]}}{Z_0^{[n]}},\n\\end{equation}\nwhere $\\lambda_n(x)$ is the number of $i$'s in $1,\\ldots, n$ for which $x_i = x$ and $a^{[k]} = a(a+1)\\ldots(a+k-1)$.  Now assume that $(ii)$ holds true, then \n$$\n\\mathbb{P}(A_n|\\mu^\\ast) = \\prod_{x\\in E}\\mu^\\ast(x)^{\\lambda_n(x)},\n$$\nrecall that $\\mu^\\ast$ is a random vector, indexed on $E$, We denote by $\\mu^\\ast(x)$ the component associated with $x\\in E$. The law of total probability then yields\n\\begin{equation}\\label{eq:P_A_polya_ii}\n\\mathbb{P}(A_n) = \\mathbb{E}\\left[\\prod_{x\\in E}\\mu^\\ast(x)^{\\lambda_n(x)}\\right],\n\\end{equation}\nwhich is the same as \\eqref{eq:P_A_polya_i}. Applying the lemma together with the law of large number yields \n$$\nn^{-1}\\sum_{i=1}^n\\delta_{X_i}(x) \\rightarrow \\mu^{\\ast}(x)\\text{ as } n\\rightarrow\\infty.\n$$\nand then $m_n(x)\\rightarrow\\mu^{\\ast}(x)$. This proof is taken from \\citet{Blackwell1973}.\n\\end{remark}\nThe asymptotic distribution of the stakes among the peers is a Dirichlet random vector denoted by $\\mu^{\\ast}$ which may be considered as a probability distribution over the set of peers. Decentralization is achieved when the weights do not concentrate around a few nodes. The most desirable situation corresponds to all the peers being equally likely to be selected. It would corresponds to a uniform distribution over the set of peers which would maximizes the Shannon entropy. For $\\mu^{\\ast}\\sim \\text{Dir}(Z^{(x)}_0)$, we have \n$$\nH(\\mu^\\ast) = -\\mathbb{E}\\left\\{\\sum_x \\mu^\\ast(x)\\ln[\\mu^\\ast(x)]\\right\\} = -\\sum_x\\frac{Z_0}{Z_0^{(x)}}\\left[\\psi(Z_0^{(x)}+1)-\\psi(Z_0+1)\\right],\n$$\nwhere $\\psi(x) = \\frac{\\text{d}}{\\text{d}x}\\ln[\\Gamma(x)]$ is the digamma function, to be compared to $\\ln(p)$.\n\n\\section{Decentralization in PoW}\\label{sec:decentralization_pow}\nIn \\cref{chap:security}, we have observed that mining blocks in a \\PoW equipped blockchain is a risky business. Nodes may deviate from the prescribed protocol to counteract that but the most common way to mitigate the underlying risk is to join forces by forming mining pool. A mining pool is a joint initiative of miners that pool their computing ressources to make their capital gains more frequent and therefore have a steadier income. Consider a network of $n$ miners of hashpower $p_i, \\text{ }i = 1,\\ldots, n$ and assume that a subset $I\\in \\{1,\\ldots, n\\}$ decides to form a mining pool. The cumulated hashpower of this pool is then\n\\[\np_I = \\sum_{i\\in I}p_i.\n\\]\nand the arrival rate of block rewards for a given miner $i$ rises from $p_i\\cdot\\lambda$ to $p_I\\cdot\\lambda$. Because the reward is shared among the pool participants, the size of the reward collected by miner $i$ decreases from $b$ to $p_i\\cdot b$. The expected surplus is the same when mining solo and mining for a pool, but the variance (and therefore the risk) is smaller when mining for a pool. The management of a mining pool relies heavily on the reward distribution mechanism set up by a pool manager. For the redistribution system to be fair, each miner must be remunerated in proportion to her calculation effort. Miner $i$ must earn a share $p_i/p_I$\nof the mining pool total income. The pool manager has to find a way to estimate the contribution of each pool participant. This is done by submitting \\textit{shares} which are partial solutions to the cryptopuzzle easier to find than the actual solution. For instance, if the target is such that the hash value for finding a block must starts with $4$ leading zeros then a partial solution could be a hash value with $3$ leading zeros.  If the current difficulty of the cryptopuzzle is $D$, then the difficulty for finding a \\textit{share} is set to $q\\cdot D$ by the pool manager, where $q\\in(0,1)$. The manager's cut is a fraction $f\\in(0,1)$ of the block discovery reward $b$.\\\\\n\n\\noindent \\cref{ssec:mining_pool_reward_system} presents the mining pool remuneration schemes and introduces the \\textit{Pay-per-Share} (PpS) system on which we will focus. \\cref{ssec:mining_pool_risk_analysis} defines risk models for miners and pool managers participating to a PpS pool.\n\n\\subsection{Mining pools and reward systems}\\label{ssec:mining_pool_reward_system}\n\\subsubsection{Proportional reward system}\nThe proportional reward system splits time in \\textit{rounds} which correspond to the time elapsed between two block discoveries. During these \\textit{rounds}, the miners submit \\textit{shares}. The ratio of the number of \\textit{shares} submitted by miner $i$ over the total number of \\textit{shares} submitted by her fellow mining pool participants determines her share of the reward and should converge to her share of the mining pool computing power, that is $p_i/p_I$ (for sufficiently low complexity of the shares, the latter limit will be a very good approximation for the actual situation indeed). The surplus of miner $i$ is then given \n\\begin{equation}\\label{eq:surplus_miner_proportional}\nR_t^i = u - c_i\\cdot t + N^I_t\\cdot (1-f)\\cdot \\frac{p_i}{p_I}\\cdot b,\\text{ }t\\geq0, \n\\end{equation}\nwhere $(N^I_t)$ is a Poisson proccess of intensity $p_I\\cdot\\lambda$ that gives the number of blocks appended to the blockchain by the mining pool. The duration of a \\textit{round} is exponentially distributed $\\text{Exp}\\left[(p_I\\lambda)^{-1}\\right]$. The uncertainty on the length of the round has undesirable consequences on the time value of the \\textit{shares} submitted by the miners. Indeed, if $n$ shares are submitted during a round, then the value of a given \\textit{share} is $(1-f)\\cdot b / n$. The longer a \\textit{round} lasts, the greater the value of $n$ is. The \\textit{shares} are worth less in longer rounds which triggers an exodus behavior of miners toward mining pools with shorter rounds. This phenomenon, called pool hopping, has been documented in the early work of Rosenfeld \\citet{rosenfeld2011analysis}. Yet another drawback is that a miner that has found a full solution may delay the submission until her ratio of \\textit{shares} submitted reflects her fraction of the mining pool computing power. The proportional system is not \\textit{incentive-compatible} using the terminology of Schrijvers et al. \\citet{Schrijvers2017}. A discounting factor may be applied to compensate the decreasing value of shares over time, see for instance the slush's method \\citet{slush}. Now if we take a look at the risk undertaken by pool managers. Within the frame of the proportional reward system, the surplus of the pool manager is given by\n\\begin{equation}\\label{eq:surplus_pool_manager_proportional} \nR_t^I = u + N^I_t\\cdot f\\cdot b,\\text{ }t\\geq0.\n\\end{equation}\nModel \\eqref{eq:surplus_pool_manager_proportional} does not account for any mining pool operating cost. The mining costs are entirely borne by miners and the mining pool manager only serves as coordinator. A proportional-type reward system should therefore lead to a low management fee $f$. \\\\\n\n\\noindent Although this system provides fairness, it has weaknesses that justify the introduction of a more sophisticated distribution mechanism. In particular, if miners seek to actually transfer some of the risk associated to the mining activity to the pool manager, then they should rather turn to a mining pool based on a \\textit{Pay-per-Share} system, which is the focus of the next section.\n\\subsubsection{Pay-per-Share reward system}\\label{eq:pps}\nIn a \\textit{Pay-per-Share} reward system, the pool manager immediately rewards the miners for each \\textit{share} submitted. Let $(M_t)_{t\\geq0}$ be a Poisson process of intensity $\\mu$ that counts the number of \\textit{shares} submitted by the entire network of miners up to time $t\\geq0$. Denote by $q\\in(0,1)$ the relative difficulty of finding a block compared to finding a share. Let $0<w<b$ be the reward for finding a \\textit{share}. The number of \\textit{shares} submitted by miner $i$ is then a (thinned) Poisson process $(M^i_t)_{t\\geq0}$ with intensity $p_i\\cdot\\mu$, $p_i$ being the share of the individual miner's network hashpower as defined above, and her surplus when joining a PpS mining pool becomes  \n\\begin{equation}\\label{eq:surplus_miner_pps}\nR_t^i = u - c_i\\cdot t + M^i_t\\cdot w,\\text{ }t\\geq0. \n\\end{equation}\nThe intensities of the processes $(N_t)_{t\\geq0}$ and $(M_t)_{t\\geq0}$ are linked through $\\lambda  = q\\cdot\\mu$. By setting $w=(1-f)\\cdot b\\cdot q$, we observe that the surplus \\eqref{eq:surplus_miner_proportional} and \\eqref{eq:surplus_miner_pps} have the same expectation at time $t$, but the variance and therefore the risk associated to \\eqref{eq:surplus_miner_pps} is lower. This reward system has been shown to be resistant to pool hopping and is incentive compatible. It also entails a significant transfer of risk to the pool manager whose surplus process is now given by\n\\begin{equation}\\label{eq:surplus_manager_pps}\nR^I_t = u - M_t^I\\cdot w + N_t^I\\cdot b,\\text{ }t\\geq0,\n\\end{equation}\nmaking her subject to the risk of bankruptcy.\n\n\\begin{remark}\\label{remark_Md}\nSince the process $(M_t^I)_{t\\geq 0}$ requires solving for a problem of lower complexitiy than $(N_t^I)_{t\\geq 0}$, ($N_t^I)_{t\\geq 0}$ is a subset of the path defined by the process $(M_t^I)_{t\\geq 0}$. It means that both processes are not independent. Concretely, at the moment of the block reward payment $b$, at the same time there is a realisation of the miners' reward $w$. As we sometimes need to isolate downward jumps without the simultaneous upward jump point, we define another process with a reduced intensity. We apply the superposition theorem (see e.g. \\cite{Kingman1993}) to the Poisson process $M_t^I$ by redefining the down jump process as $(M_t^{I,d})_{t\\geq 0} \\sim Poisson(\\mu_d)$, where $\\mu_d = \\mu-\\lambda$.\n\\end{remark}\n\\noindent In addition to the bounty for finding a new block, blockchain users usually include a small financial incentive for the network to process their transaction. These transaction fees (e.g.\\ referred to as \\textit{gas} within the ETHEREUM blockchain), are known to be variable as they highly depend on the network congestion at a given time. Note also that since the operational cost is paid by miners using a fiat currency, it would be more accurate to account for the exchange rate of the cryptocurrency to some fiat currency. We can therefore model the successive rewards for \\textit{shares} and blocks as sequences of nonnegative random variables denoted by $(W_k)_{k\\geq1}$ and $(B_k)_{k\\geq1}$ respectively, which for simplicity we will both assume to be \\textit{i.i.d.}\\  exponential variables in these notes. A reward system that features a \\textit{Pay-per-Share} mechanism and includes in the miners' reward the transaction fees is referred to as a \\textit{Full Pay-per-Share} reward system by practitioners. The surplus of miner $i$ in a mining pool applying the FPpS\\,system is given by  \n\\begin{equation}\\label{eq:surplus_miner_fpps}\nR_t^i = u - c_i\\cdot t + \\sum_{k = 1}^{M^i_t}W_k,\\text{ }t\\geq0,\n\\end{equation}\nand the surplus of the pool manager then becomes \n\\begin{equation}\\label{eq:surplus_manager_fpps}\nR^I_t = u - \\sum_{k = 1}^{M^I_t}W_k + \\sum_{l = 1}^{N_t^I}B_l,\\text{ }t\\geq0. \n\\end{equation}\nThe next section is devoted to deriving formulas for the ruin probability and expected surplus in case ruin did not occur up to a given time horizon for the models discussed above.\n\n\\subsection{Mining pool risk analysis}\\label{ssec:mining_pool_risk_analysis}\n\n\n\\subsubsection{From the miners' viewpoint}\\label{sssec:miner_viewpoint}\nConsider miner $i\\in \\{1,\\ldots, n\\}$ with hashpower $p_i\\in(0,1)$ that joined a FPpS mining pool $I\\subset\\{1,\\ldots, n\\}$ with relative difficulty $q\\in(0,1)$ and management fee $f\\in(0,1)$. Let $\\lambda$ the average number of solutions published by the network per time unit and let $\\mu = \\lambda/q$ be the average number of partial solutions. The surplus of miner $i$ in a mining pool applying the FPpS\\,system is given by\n\\begin{equation*}\nR_t^i = u - c_i\\cdot t + \\sum_{k = 1}^{M^i_t}W_k,\\text{ }t\\geq0,\n\\end{equation*}\nwhere $(M^i_t)_{t\\geq0}$ is a Poisson process with intensity $\\mu \\cdot p_i$, and the $W_k$'s are \\iid exponential variable with mean $w = (1-f)\\cdot q\\cdot b$. The ruin time is defined as \n$$\n\\tau_u^{(i)} = \\inf\\{t\\geq0\\text{ ; } R_t^i = 0\\},\n$$\nand the net profit condition reads as \n$$\n(1-f)\\cdot p^{i}\\cdot b\\cdot \\lambda>c_i.\n$$\nWe first provide the probability distribution of $\\tau_u^{i}$.\n\\begin{theo}\\label{theo:pdf_ruin_time_miner_in_pool}\nThe ruin time $\\tau_u^{(i)}$ takes value $t\\geq u/c_i$. It has an atom of probability with \n\\[\n\\mathbb{P}(\\tau_u^{(i)} = u/c_i) = \\mathbb{P}(M^{(i)}_{u/c_i}=0)=\\e^{-p_i\\mu u/c_i}\n\\]\nand \\pdf given by \n\\begin{equation}\\label{eq:pdf_ruin_time_miner_in_pool}\nf_{\\tau_u^{(i)}}(t)=\\frac{u}{t}\\mathbb{E}\\left[f_{W}^{\\ast M_t^{(i)}}(c_i t-u)\\mathbb{I}_{M^{(i)}_t \\geq1}\\right]\\text{, for }t\\geq u/c_i.\n\\end{equation}\n\\end{theo}\n\\begin{proof}\nRuin is not possible before time $u/c_i$. It may occur exactly at time $t = u/c_i$ if no capital gain occur before that time. Hence we have \n$$\n\\mathbb{P}(\\tau_u^{(i)} = u/c_i) = \\mathbb{P}(M_{u/c_i} = 0) = \\exp\\left(-p_i\\mu \\frac{u}{c_i}\\right).\n$$\nNow consider some time $t>u/c_i$. We have that \n\\begin{equation*}\n\\{\\tau_u^{(i)}\\in(t,t+\\text{dt})\\} = \\bigcup_{n = 1}^{+\\infty}\\left\\{M_t^{(i)} = n \\right\\}\\cap\\{\\tau_u^{(i)}\\in(t,t+\\text{dt})\\},\\\\\n\\end{equation*}\nand therefore\n\\begin{equation}\\label{eq:law_of_total_prob}\n\\mathbb{P}\\left[\\tau_u^{(i)}\\in(t,t+\\text{dt})\\right] = \\sum_{n = 1}^{+\\infty}\\mathbb{P}\\left[\\tau_u^{(i)}\\in(t,t+\\text{dt})\\big\\rvert M_t^{(i)} = n\\right]\\mathbb{P}\\left(M_t^{(i)} = n \\right).\n\\end{equation}\nNote that \n\\[\n\\left\\{M_t^{(i)} = n \\right\\}\\cap\\{\\tau_u^{(i)}\\in(t,t+\\text{dt})\\} =\\left\\{M_t^{(i)} = n \\right\\}\\cap\\bigcap_{k = 1}^{n}\\{T_k\\leq\\frac{S_{k-1}+u}{c_i}\\}\\cap\\left\\{\\frac{S_n+u}{c_i}\\in(t,t+\\text{dt})\\right\\}.\n\\]\nWe then have \n\\begin{eqnarray*}\n&&\\mathbb{P}\\left[\\tau_u^{(i)}\\in (t,t+\\text{d}t)\\big\\rvert M_t^{(i)} = n \\right]\\\\\n&=&\\mathbb{P}\\left[\\bigcap_{k = 1}^{n}\\left\\{T_k\\leq\\frac{S_{k-1}+u}{c_i}\\right\\}\\cap\\left\\{\\frac{S_n+u}{c_i}\\in(t,t+\\text{dt})\\right\\}\\big\\rvert M_t^{(i)} = n \\right]\\\\\n&=&\\mathbb{P}\\left[\\bigcap_{k = 1}^{n}\\left\\{\nU_{(k)}\\leq\\frac{S_{k-1}+u}{c_i t}\n\\right\\}\n\\Big\\rvert\\frac{S_n+u}{c_i}\\in(t,t+\\text{dt})\\right]\n\\mathbb{P}\\left[\\frac{S_n+u}{c_i}\\in(t,t+\\text{dt})\\right]\\\\\n&=&\\mathbb{P}\\left[\\bigcap_{k = 1}^{n}\\left\\{\nU_{(k)}\\leq\\frac{S_{k-1}+u}{c_i t}\n\\right\\}\n\\Big\\rvert S_{n}=c_i t -u\\right]\nc_i f_{W}^{\\ast(n)}(c_i t -u)\\\\\n&=&\\mathbb{E}\\left\\{\\mathbb{P}\\left[\\bigcap_{k = 1}^{n}\\left\\{\nU_{(k)}\\leq\\frac{S_{k-1}+u}{c_i t}\n\\right\\}\\Big\\rvert S_1,\\ldots, S_n\\right]\n\\Big\\rvert S_{n}=c_i t -u\\right\\}\nc_i f_{W}^{\\ast(n)}(c_i t -u)\\\\\n&=&\\mathbb{E}\\left\\{(-1)^nG_n\\left(0\\Big\\rvert \\frac{S_0+u}{c_i t}, \\ldots, \\frac{S_{n-1}+u}{c_i t}\\right)\n\\Big\\rvert S_{n}=c_i t -u\\right\\}\nc_i f_{W}^{\\ast(n)}(c_i t -u)\\\\\n&=&\\frac{(-1)^n}{(c_it)^{n} }\\mathbb{E}\\left[G_n\\left(-u\\Big\\rvert S_0, \\ldots, S_{n-1}\\right)\n\\Big\\rvert S_{n}=c_i t -u\\right]\nc_i f_{W}^{\\ast(n)}(c_i t -u)\\\\\n&=&\\frac{(-1)^n}{(c_it)^{n} }(-u)(-u-c_i t + u)^{n-1}\nc_i f_{W}^{\\ast(n)}(c_i t -u) \\\\\n&=& \\frac{u}{ t}f_{W}^{\\ast(n)}(c_i t -u) .\n\\end{eqnarray*}\nReinserting in \\eqref{eq:law_of_total_prob} yields the result.\n\n\\end{proof}\n\\noindent The infinite serie in \\eqref{eq:pdf_ruin_time_miner_in_pool} is problematic for numerical purposes although a workable approximation may be otained by truncating it. Just like in \\cref{chap:security}, we shall consider an exponential time horizon $T\\sim\\ExpDist(t)$ instead of a deterministic one and compute\n\\[\n\\widehat{\\psi}(u,t) = \\mathbb{P}(\\tau_u \\leq T),\\text{ and }\\widehat{V}(u,t) = \\mathbb{E}(R_T\\mathbb{I}_{\\tau_u > T}).\n\\]\nWe start with the ruin probability\n\\begin{prop}\\label{prop:rp_hat_miner_in_pool}\nThe ruin probability up to an exponential time horizon is given by \n\\[\n\\widehat{\\psi}(u,t) = e^{\\theta^{\\ast} u}\n\\]\nwhere $\\theta^{\\ast}$ is the solution of the equation\n\\[\np_i\\mu + 1/t - c_i \\theta = p_i\\mu\\mathbb{E}\\left(e^{-\\theta W}\\right)\n\\]\n\\end{prop}\n\\begin{proof}\nDefine the process\n\\[\nS_t^{(i)} = R^{(i)}_t-u =c_i t-\\sum_{k = 1}^{N_t}W_k,\n\\]\nas it is a Levy process then the process\n\\[\nM_t^{(i)}=\\exp\\left(\\theta S_t^{(i)} - t\\kappa(\\theta)\\right),\n\\]\nis a martingale, where \n\\[\n\\kappa(\\theta) =\\log \\mathbb{E}(e^{\\theta S_1^{(i)}}) = c_i\\theta + p_i\\mu \\mathbb{E}\\left(e^{-\\theta W}\\right) -\\mu p_i\n\\]\nWe apply the optional stopping theorem at time $\\tau_u\\land T_1$, where $T_1>0$ to get \n\\begin{eqnarray*}\n\\mathbb{E}\\left(M_0^{(i)}\\right) &=& \\mathbb{E}\\left(M_{\\tau_u^{(i)}\\land T_1}^{(i)}\\right)\\\\\n1 &=& \\mathbb{E}\\left(M_{\\tau_u^{(i)}}|\\tau_u^{(i)} < T_1\\right)\\mathbb{P}(\\tau_u^{(i)} < T_1)+\\mathbb{E}\\left(M_T|\\tau_u^{(i)} \\geq T_1\\right)\\mathbb{P}(\\tau_u^{(i)} \\geq T_1)\n\\end{eqnarray*}\nBy letting $T_1\\rightarrow \\infty$ we get \n\\begin{eqnarray*}\n1 &=& \\mathbb{E}\\left(M_{\\tau_u^{(i)}}|\\tau_u^{(i)} < \\infty\\right)\\mathbb{P}(\\tau_u^{(i)} < \\infty)\\\\\n1 &=& \\e^{\\theta u}\\mathbb{E}\\left(\\e^{-\\kappa(\\theta) \\tau_u^{(i)}}|\\tau_u^{(i)} < \\infty\\right)\\mathbb{P}(\\tau_u^{(i)} < \\infty)\n\\end{eqnarray*}\nLet $s>0$ and $\\theta(s)$ be the unique positive solution of the equation $\\kappa(\\theta) =s$, then \n\\begin{eqnarray*}\n1 &=& \\e^{\\theta(s) u}\\mathbb{E}\\left(\\e^{-\\kappa(\\theta(s)) \\tau_u^{(i)}}|\\tau_u^{(i)} < \\infty\\right)\\mathbb{P}(\\tau_u^{(i)} < \\infty)\\\\\n1 &=& \\e^{\\theta(s) u}\\mathbb{E}\\left(\\e^{-s\\tau_u^{(i)}}|\\tau_u^{(i)} < \\infty\\right)\\mathbb{P}(\\tau_u^{(i)} < \\infty)\\\\\n1 &=& \\e^{\\theta(s) u}\\mathbb{E}\\left(\\e^{-s\\tau_u^{(i)}}\\right)\\\\\n\\mathbb{E}\\left(\\e^{-s\\tau_u^{(i)}}\\right) &=& \\e^{-\\theta(s) u}\\\\\n\\end{eqnarray*}\nNote that \n\\[\n\\widehat{\\psi}(u,t) = \\mathbb{P}(\\tau_u^{i}\\geq T) = \\mathbb{E}(e^{-\\tau_u^{(i)}/t}) = \\e^{-\\theta(1/t) u}.\n\\]\n\\end{proof}\n\\begin{prop}\\label{prop:rp_hat_miner_in_pool}\nThe expected wealth up to an exponential time horizon is given by \n\\[\n\\widehat{V}(u,t) = t(c_i-p_i\\mu w)e^{-\\theta^{\\ast} u}+u +t(p_i\\mu w - c_i)\n\\]\nwhere $\\theta^{\\ast}$ is the positive solution of the equation\n\\[\n-c_i\\theta^{2}+\\theta\\left(\\frac{1}{t}+p_i\\mu-\\frac{c_i}{w}\\right)+\\frac{1}{wt} = 0.\n\\]\n\\end{prop}\n\\begin{proof}\nConditionning upon the events that may occur over th time interval $(0,h)$ with \n\\begin{itemize}\n    \\item $T>h$ and no partial solution submitted\n    \\item $T\\leq h$ and no partial solution submitted\n    \\item A partial solution submitted before $T$ and $h$\n\\end{itemize}\nIt then holds that \n\\begin{eqnarray*}\n\\widehat{V}(u,t) &=&\\e^{-h(1/t + \\mu p_i)}\\widehat{V}(u-ch,t)+\\int_{0}^{h}\\frac{1}{t}\\e^{-h(1/t + \\mu p_i)}(u-cs)\\text{d}s\\\\\n&+& \\int_{0}^{h}\\int_{0}^{+\\infty}\\mu p_i\\e^{-h(1/t + \\mu p_i)}\\widehat{V}(u-cs+x,t)\\frac{\\e^{-x/w}}{w}\\text{d}x\\text{d}s.\n\\end{eqnarray*}\nDifferentiating with respect to $h$ and letting $h\\rightarrow\\infty$ yields\n\\begin{equation}\\label{eq:integro_differentiql_equation_miner_in_pool}\n\\left(\\frac{1}{t}+p_i\\mu\\right)\\widehat{V}(u,t)+c_i\\widehat{V}'(u,t)-\\frac{u}{t}-\\int_0^{+\\infty}\\widehat{V}(u+x,t)\\frac{p_i\\mu}{w}\\e^{-x/w}\\text{d}x=0,\n\\end{equation}\nwith boundary conditions \\(\\widehat{V}(0,t) = 0\\) and \\(0\\leq \\widehat{V}(u,t)\\leq u-c_i t +p_i\\mu w\\). The solution is of the form \n\\begin{equation}\\label{eq:ansatz}\n\\widehat{V}(u,t) = A+Bu+C\\e^{-\\theta u},\n\\end{equation}\nso that \n\\begin{equation}\\label{eq:ansatz_derivative}\n\\widehat{V}'(u,t) = B-\\theta C\\e^{-\\theta u}.\n\\end{equation}\nReinserting \\eqref{eq:ansatz} and \\eqref{eq:ansatz_derivative} into \\eqref{eq:integro_differentiql_equation_miner_in_pool}, together with the boundary condition, yields the following system of equation\n\\begin{equation}\n\\begin{cases}\n\\frac{A}{t}-Bp_i\\mu w+Bc =0\\\\\nB\\left(\\frac{1}{t}+p_i\\mu\\right)-\\frac{1}{t}-Bp_i\\mu = 0\\\\\n\\left(\\frac{1}{t}+p_i\\mu\\right)-\\theta c -\\frac{p_i\\mu}{1+\\theta w}=0\\\\\nA+C = 0 \n\\end{cases}\n\\end{equation}\nIt follows that $B = 1$, $A = t(p_i\\mu w-c_i)$, $C = -A$ and $\\theta^{\\ast}$ is solution to \n$$\n-c_i\\theta^{2}+\\theta\\left(\\frac{1}{t}+p_i\\mu-\\frac{c}{w}\\right)+\\frac{1}{wt} = 0.\n$$\n\n\\end{proof}\n\\begin{ex}\\label{ex:miner_in_pool}\nConsider a miner with haspower $p = 0.01$. Let the BTC price be $\\$36347.89$, and the reward be $\\text{BTC}6.25 = \\$248460.12$. If the time unit is the hour then $\\lambda = 6$ so that one block is generated every ten minutes on average. The network consumes $10914487\\text{kWh}$ per time unit. Suppose that our miner is joining a mining pool with a management fee $f = 0.05$. The ruin probability of the miner as a function of the initial reserve $u$ for a time horizon of one week is shown in \\cref{fig:rp_miner_in_pool} for various relative difficulty $q = 0.25, 0.5, 0.75$.\n\\begin{figure}[!ht]\n  \\begin{center}\n      \\includegraphics[width = 0.5\\textwidth]{../Figures/rp_miner_in_pool}\n    \\caption{Ruin probability of a miner in mining pool as a function of the initial reserves depending on the relative difficulty proposed by the pool manager $q\\in \\{0.25, 0.5, 0.75\\}$.}\n    \\label{fig:rp_miner_in_pool}\n  \\end{center}\n\\end{figure}\nThe ruin probability of a miner, mining on his own is also plotted. We see that joining a mining pool is beneficial as it reduces significantly the ruin probability.\n\\end{ex}\n\n\n\\subsubsection{From the pool manager's viewpoint}\\label{ssec:manager_viewpoint}\nConsider a pool manager that coordinate a FPpS mining pool $I\\subset\\{1,\\ldots, n\\}$. The manager sets the relative difficulty of finding a share compared to finding a block to $q\\in(0,1)$. If we let $(N_t)_{t\\geq0}$ and $(M_t)_{t\\geq0}$ be Poisson processes with respective intensity $\\lambda$ and $\\mu$ equal to the number of block and \\textit{shares} find by the network then we have $\\lambda = q\\mu$. Note that a \\textit{share} that turns out to be a proper solution triggers a jump for both $(N_t)_{t\\geq0}$ and $(M_t)_{t\\geq0}$. The two processes are dependent because the paths of $(N_t)_{t\\geq0}$ is a subset of the path of $(M_t)_{t\\geq0}$. To isolate the jumps of the two processes we define a Poisson process $(\\tilde{M}_t)_{t\\geq0}$ of intensity $\\mu^{\\ast} = \\mu -\\lambda$ which corresponds to the \\textit{share} that do not solve the cryptopuzzle. We have that \n\\[\nM_t = N_t+\\tilde{M}_t,\\text{ }t\\geq0\\text{ a.s.,}\n\\] \nwhere $N_t$ and $\\tilde{M}_t$ are independent Poisson processes. The number of shares and blocks found by the pool are then thinned versions $(N_t^I)$ and $\\tilde{M}_t^{I}$ of the former processes with respective intensity $p_I\\lambda$ and $p_I\\mu^{\\ast}$. The wealth of the pool manager is given by \n\\begin{equation}\\label{eq:wealth_pool_manager_fpps}\nR^I_t = u - \\sum_{k = 1}^{\\tilde{M}^I_t}\\tilde{W}_k + \\sum_{l = 1}^{N_t^I}\\tilde{B}_l,\\text{ }t\\geq0, \n\\end{equation}\nwhere $\\tilde{B}_l\\overset{iid}{\\sim}\\ExpDist\\left(1/b^{\\ast}\\right)$, $b^{\\ast} = b-w$, and $W_k\\overset{iid}{\\sim}\\ExpDist(1/w)$. The following result provides formulas for the ruin probability $\\widehat{\\psi}(u,t)$ and expected surplus $\\widehat{V}(u,t)$ of the pool manager up to an exponential time horizon $T\\sim \\ExpDist(1/t)$. The ruin time is defined as \n\\[\n\\tau_u = \\inf\\{t\\geq0\\text{ ; }R^I_t<0\\},\n\\]\nwhich means that the pool manager may start with no initial reserves. In the following theorem we omit the superscript $I$ and remove the $p^{I}$ from the intensities of the Poisson processes\n\\begin{theo}\nThe ruin probability is given by \n\\begin{equation*}\\label{psiexpe}\n    \\widehat{\\psi}(u,t) = (1-Rw)  e^{-R u},\\;u\\ge 0,\n\\end{equation*}\nand the expected profit is given by\n\\begin{equation*}\\label{Vcombexpe}\n    \\widehat{V}(u,t) = (1 - Rw)[w-t(\\lambda b^\\ast-\\mu^\\ast w)] e^{-R u}+u+t(\\lambda b^\\ast-\\mu^\\ast w),\n\\end{equation*}\nwhere $R$ is the (unique) solution with positive real part of \n\\begin{equation*} \\label{VLunde}\n    -(t^{-1}+\\lambda+\\mu^\\ast)+\\lambda(1+b^\\ast r)^{-1}+\\mu^\\ast(1-wr)^{-1}=0.\n\\end{equation*}\n\\end{theo}\n\\begin{proof}\nLet us consider only $\\widehat{V}(u,t)$ (the reasoning is the same for $\\widehat{\\psi}(u,t)$).\nWe condition upon what happen during the time interval $(0,h)$. Four possibilities\n\\begin{itemize}\n  \\item[(i)] $T>h$ and no jump during $(0,h)$\n  \\item[(ii)] $T<h$ and no jump over $(0,T)$\n  \\item[(iii)] An upward jump in the interval $(0,h)$\n  \\item[(iv)] A downward jump in the interval $(0,h)$\n\\end{itemize}\n  \\begin{eqnarray*}\\label{neu0}\n      \\widehat{V}(u,t)&=& e^{-(\\frac{1}{t}+\\lambda+\\mu^\\ast)h}\\widehat{V}(u,t) + \\frac{1}{t}\\int_0^h e^{-{s}/{t}}e^{-(\\lambda +\\mu^\\ast) s} u\\,ds\\\\\n      & +& \\lambda\\int_0^he^{-\\lambda s} e^{-({1}/{t}+\\mu^\\ast) s} \\int_0^\\infty\\widehat{V}(u+x,t)\\,dF_{B}(x)\\,ds\\\\\n      &  +&\\mu^\\ast \\int_0^he^{-\\mu^\\ast s} e^{-({1}/{t}+\\lambda) s}\\int_0^u \\widehat{V}(u-y,t) \\,dF_W(y)\\,ds.\n  \\end{eqnarray*}\n  Differentiating with respect to $h$ and letting $h\\rightarrow 0$ yields the following integral equation\n  \\begin{equation} \\label{inteq}\n    \\lambda\\int_0^\\infty\\widehat{V}(u+x,t)\\,dF_{B}(x)-(\\lambda+\\mu^\\ast+{1}/{t})\\widehat{V}(u,t)+\\mu^\\ast\\int_0^u \\widehat{V}(u-y,t) \\,dF_W(y)+{u}/{t}=0,\\quad u\\ge 0,\n  \\end{equation}\n  with boundary conditions $\\widehat{V}(u,t)=0$ for all $u<0$ and $0\\leq\\widehat{V}(u,t)\\leq u+(\\lambda b^\\ast - \\mu^\\ast w)t$. Let us plug in the ansatz\n  $$\n  Ae^{-ru}+Bu+C\n  $$\n  \\begin{itemize}\n    \\item Comparing the terms in $e^{-r u}$ gives and equation for $r$\n    $$\n    -(t^{-1}+\\lambda+\\mu^\\ast)+\\lambda(1+b^\\ast r)^{-1}+\\mu^\\ast(1-wr)^{-1}=0\n    $$\n    of which only the positive solution $R>0$ is valid due to the boundary conditions.\n    \\item Comparing the terms in $u$ yields $B = 1$\n    \\item Comparing the terms in $1$ yields\n    $$\n    C = t(\\lambda b^\\ast-\\mu^\\ast w)\n    $$\n    \\item Comparing the terms in $e^{-u/w}$\n    $$\n    A = (1 - Rw)[w-t(\\lambda b^\\ast-\\mu^\\ast w)]\n    $$\n\\end{itemize}\n\\end{proof}\n\n\\begin{ex}\\label{ex:rp_pool_manager}\nConsider a mining pool with hashpower $p_I = 0.1$ and management fee $f = 0.05$. Let the BTC price be $\\$36347.89$, and the reward be $\\text{BTC}6.25 = \\$248460.12$. If the time unit is the hour then $\\lambda = 6$ so that one block is generated every ten minutes on average. \\cref{fig:rp_pool_manager} displays the ruin probability of the pool manager as a function of the initial reserves depending on the relative difficulty.\n\\begin{figure}[!ht]\n  \\begin{center}\n      \\includegraphics[width = 0.5\\textwidth]{../Figures/rp_pool_manager}\n    \\caption{Ruin probability of a pool manager as a function of the initial reserves depending on the relative difficulty $q\\in \\{0.25, 0.5, 0.75\\}$.}\n    \\label{fig:rp_pool_manager}\n  \\end{center}\n\\end{figure}\nThe ruin probability is higher for low relative difficulty.\n\\end{ex}\n\\subsubsection{Risk of centralization?}\\label{ssec:numerical_illustrations}\nTh risk of centralization exists because a mining pool that is growing larger canb reduce the management fee while maintaining the same profitability. Consider a mining pool with initial reserves $u = 10^6$ and relative difficulty $q=0.25$. The time horizon is $t = 168$ (one week). \\cref{fig:level_plot_V_pool_manager_p_f} shows the expected wealth as a function of $p$ and $f$.  \n\\begin{figure}[!ht]\n  \\begin{center}\n      \\includegraphics[width = 0.5\\textwidth]{../Figures/level_plot_V_pool_manager_p_f}\n    \\caption{Expected wealth as a function of $p_I$ and $f$.}\n    \\label{fig:level_plot_V_pool_manager_p_f}\n  \\end{center}\n\\end{figure}\nA large mining pool offers lower fees, thus attracts more miner and grows even larger. However a large mining pool cannot offer the same level of risk transfer than smaller mining pool. Consider two mining pool with respective hashpower $p_1 = 0.05$ and $p_2 = 0.2$ and initial reserves $u = 10^6$. The time horizon is $t = 168$ (one week). \\cref{fig:level_plot_V_pool_manager_p_f} shows the expected wealth for each of these mining pool as a function of $q$ and $f$.  \n\\begin{figure}[!ht]\n  \\begin{center}\n      \\includegraphics[width = \\textwidth]{../Figures/level_plots_V_pool_manager_q_f}\n    \\caption{Expected wealth as a function of $p_I$ and $f$.}\n    \\label{fig:level_plots_V_pool_manager_q_f}\n  \\end{center}\n\\end{figure}\nTo offer the same level of risk transfer a larger mining pool needs to increase the fee. Centralization may prevail if the miner's preferences in terms of profitability and risk transfer are heterogenous. A game theoretic framework must be introduced to appropriately model the behaviors of the miners and mining pool manager, see the works of \\citet{li2019mean} and \\citet{Cong2020}.\n\\newpage", "meta": {"hexsha": "fee71be48e18a1a4c6fb47abf519cfd9f564e9e7", "size": 43235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/includes/decentralization.tex", "max_stars_repo_name": "LaGauffre/BLOCKASTICS", "max_stars_repo_head_hexsha": "4087304a4fb6fe55b5e8746315f524eddedc72e8", "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": "lecture_notes/includes/decentralization.tex", "max_issues_repo_name": "LaGauffre/BLOCKASTICS", "max_issues_repo_head_hexsha": "4087304a4fb6fe55b5e8746315f524eddedc72e8", "max_issues_repo_licenses": ["CC0-1.0"], "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/includes/decentralization.tex", "max_forks_repo_name": "LaGauffre/BLOCKASTICS", "max_forks_repo_head_hexsha": "4087304a4fb6fe55b5e8746315f524eddedc72e8", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-21T08:20:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T08:20:38.000Z", "avg_line_length": 71.8189368771, "max_line_length": 1458, "alphanum_fraction": 0.687591072, "num_tokens": 15440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.6668719059481149}}
{"text": "\\chapter{DT Block Diagrams}\n\n\\section{The Four Basic Motifs}\n\nBlock diagrams of DT systems are similar to CT systems.\n\nThe 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    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$\\mathcal{S}_1$};\n    \\node [output, right of=system] (output) {};\n\n\n    \\draw [draw,->] (input) -- node {$x[n]$} (system);\n    \\draw [->] (system) -- node {$y[n]$} (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\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\n    \\draw [draw,->] (input) -- node {$x[n]$} (system1);\n    \\draw [->] (system1) -- (system2);\n    \\draw [->] (system2) -- node {$y[n]$} (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\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[n]$} (conn);\n    \\node [output, right of=sum] (output) {};\n    \\draw [->] (sum) -- node {$y[n]$} (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    \\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[n]$} (sum);\n    \\draw [->] (sum) -- (block1);\n    \\node [output, right of=conn] (output) {};\n    \\draw [->] (conn) -- node {$y[n]$} (output);\n\\end{tikzpicture}\n\\end{itemize}\n\nNote the feedback is negative (the minus sign on the feedback summation input). As in CT, these can be use in various combinations.\n\n\\section{Connections to Convolution}\n\nEach subsystem, $\\mathcal{S}_i$, can be represented by a basic discrete time-domain operation (e.g. differences, running sums, addition, and scaling) or more generally by it's impulse response $h_i[n]$.\n\nFor example a block representing an system acting as a delay of one sample is typically drawn 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] {};\n    \\node [block, right of=input] (system) {$D$};\n    \\node [output, right of=system] (output) {};\n    \\draw [draw,->] (input) -- node {$x[n]$} (system);\n    \\draw [->] (system) -- node[pos=2] {$y[n] = x[n-1]$} (output);\n\\end{tikzpicture}\n\\end{center}\nThis is equivalent to an impulse response $h[n] = \\delta[n-1]$ 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    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$h[n] = \\delta[n-1]$};\n    \\node [output, right of=system] (output) {};\n\n    \\draw [draw,->] (input) -- node {$x[n]$} (system);\n    \\draw [->] (system) -- node[pos=4] {$y[n] = x[n] * \\delta[n-1] = x[n-1]$} (output);\n\\end{tikzpicture}\n\\end{center}\n\nSimilarly, a block representing an system acting as an advance of one sample is typically drawn 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] {};\n    \\node [block, right of=input] (system) {$E$};\n    \\node [output, right of=system] (output) {};\n    \\draw [draw,->] (input) -- node {$x[n]$} (system);\n    \\draw [->] (system) -- node[pos=2] {$y[n] = x[n+1]$} (output);\n\\end{tikzpicture}\n\\end{center}\nThis is equivalent to an impulse response $h[n] = \\delta[n+1]$ 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    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$h[n] = \\delta[n+1]$};\n    \\node [output, right of=system] (output) {};\n\n    \\draw [draw,->] (input) -- node {$x[n]$} (system);\n    \\draw [->] (system) -- node[pos=4] {$y[n] = x[n] * \\delta[n+1] = x[n+1]$} (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\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$h_1[n]$};\n    \\node [output, right of=system] (output) {};\n\n    \\draw [draw,->] (input) -- node {$x[n]$} (system);\n    \\draw [->] (system) -- node[pos=2] {$y[n] = h_1[n]*x[n]$} (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[n]$};\n    \\node [block, right of=system1,node distance=4cm] (system2) {$h_2[n]$};\n    \\node [output, right of=system2] (output) {};\n\n    \\draw [draw,->] (input) -- node {$x[n]$} (system1);\n    \\draw [->] (system1) -- (system2);\n    \\draw [->] (system2) -- node[pos=3] {$y[n] = \\left(h_1[n]*h_2[n]\\right)*x[n]$} (output);\n\\end{tikzpicture}\n  \\end{center}\n  which can be reduced to a single convolution $y[n] = h_3[n]*x[n]$ where $h_3[n] = h_1[n]*h_2[n]$.\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[n]$};\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[n]$};\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[n]$} (conn);\n    \\node [output, right of=sum] (output) {};\n    \\draw [->] (sum) -- node[pos=3] {$y[n]= \\left(h_1[n]*x[n]\\right) +  \\left(h_2[n]*x[n]\\right) =  \\left(h_1[n]+h_2[n]\\right)*x[n]$} (output);\n\\end{tikzpicture}  \n  \\end{center}\n  which is equivalent to a single convolution $y[n] = h_3[n]*x[n]$ where $h_3[n] = h_1[n] + h_2[n]$.\n\\item In the feedback connection let $w[n]$ 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[n]$};\n\n    \\node[block] at (4,-2) (block2) {$h_2[n]$};\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[n]$} (sum);\n    \\draw [->] (sum) -- (block1);\n    \\node [output, right of=conn] (output) {};\n    \\draw [->] (conn) -- node {$y[n]$} (output);\n    \\draw node at (3,0.3) {$w[n]$};\n\\end{tikzpicture}\n  \\end{center}\n  Then $y[n] = h_1[n]*w[n]$ and $w[n] = x[n] - h_2[n]*y[n]$. Substituting the later into the former gives $y[n] = h_1*(x-h_2[n]*y[n])$. Using the distributive property we get $y[n] = h_1[n]*x[n] - h_1[n]*h_2[n]*y[n]$. Isolating the input on the right-hand side and using $y[n] = \\delta[n]*y[n]$ we get\n  \\[\n  y[n] + h_1[n]*h_2[n]*y[n] = \\left(\\delta[n] + h_1[n]*h_2[n]\\right)*y[n] = h_1[n]*x[n] \n  \\]\n  We can solve this for $y[n]$ using the concept of inverse systems. Let $h_3[n]* \\left(\\delta[n] + h_1[n]*h_2[n]\\right)= \\delta[n]$, i.e. $h_3$ is the inverse system of $\\delta[n] + h_1[n]*h_2[n]$. Then\n  \\[\n  y[n] = h_3[n]*h_1[n]*x[n]\n  \\]\n\\end{itemize}\n\nRecall, when the system is instantaneous (memoryless) the impulse response is $a\\delta[n]$ 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[n]$} (system);\n  \\draw [draw,->] (system) -- node[pos=1] {$y[n] = ax[n]$} (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[n] = \\left(\\frac{1}{2}\\right)^n\\, u[n] + \\left(\\frac{3}{4}\\right)^n\\, u[n]\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[n] = \\left(\\frac{1}{2}\\right)^nu[n]$};\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[n] = \\left(\\frac{3}{4}\\right)^nu[n]$};\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[n]$} (conn);\n    \\node [output, right of=sum] (output) {};\n    \\draw [->] (sum) -- node[pos=1] {$y[n]$} (output);\n\\end{tikzpicture}\n  \\end{center}\n\\end{example}\n\n\\section{Connections to LCCDE}\n\nThe other DT system representation we have seen are linear, constant-coefficient difference equations. These can be expressed as combinations of advance or delay blocks. This is straightforward compared the CT system case.\n\n\\subsection*{First-Order System}\n\nTo illustrate this consider the first-order LCCDE\n\\[\ny[n+1] + ay[n]= x[n+1]\n\\]\nWe can solve this for $y[n]$\n\\[\ny[n] = -\\frac{1}{a}y[n+1]  + \\frac{1}{a}x[n+1]\n\\]\nand can express this as a feedback motif using the advance operator $E$\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [left of=input] {$x[n]$};\n    \\node[block, right of=input, node distance=5em] (block1) {$E$};\n    \\node [sum, right of=block1, node distance=5em] (sum) {$\\Sigma$};\n    \\node[block] at (5,-1) (block2) {$E$};\n    \\node [shape=coordinate, name=conn] at (6,0) {};\n    \\node[shape=coordinate] at (7,0) (output) {};\n    \\node [right of=output] {$y[n]$};\n    \n    \\draw [->] (input) -- node {$\\frac{1}{a}$} (block1);\n    \\draw [->] (block1) -- (sum);\n    \\draw (sum) -- (conn);\n    \\draw [->] (conn) -- (output);\n    \\draw [->] (conn) |- (block2);\n    \\draw [->] (block2) -| node {$-\\frac{1}{a}$} (sum);\n  \\end{tikzpicture}\n\\end{center}\n\nAlternatively we could rewrite the difference equation in recursive delay form\n\\[\ny[n] = -ay[n-1] +x[n]\n\\]\nwhich can be expressed as a block diagram using the delay operator, $D$\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [left of=input] {$x[n]$};\n    \\node [sum, right of=input, node distance=5em] (sum) {$\\Sigma$};\n    \\node[block] at (3,-1) (block2) {$D$};\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node[shape=coordinate] at (5,0) (output) {};\n    \\node [right of=output] {$y[n]$};\n    \n    \\draw [->] (input) -- (sum);\n    \\draw (sum) -- (conn);\n    \\draw [->] (conn) -- (output);\n    \\draw [->] (conn) |- (block2);\n    \\draw [->] (block2) -| node {$-a$} (sum);\n  \\end{tikzpicture}\n\\end{center}\n\nThe choice of using advance or delay blocks results in a non-causal or causal (respectively) system. Thus, delay blocks are required for real-time DT system implementations.\n\n\\subsection*{Second-Order System}\n\nNow consider the second-order system\n\\[\ny[n+2] + ay[n+1] + by[n] = x[n+2]\n\\]\nAgain, writing in recursive delay form \n\\[\ny[n] = -ay[n-1] - by[n-2] + x[n]\n\\]\nwe obtain the block diagram\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [left of=input] {$x[n]$};\n    \\node [sum] at (2,0) (sum1) {$\\Sigma$};\n    \\node [block] at (4,-1) (block1) {$D$};\n    \\node [block] at (4,-3) (block2) {$D$};\n    \\node [shape=coordinate, name=conn1] at (4,-2) {};\n    \\node [shape=coordinate, name=conn2] at (4,-4) {};\n    \\node [sum] at (2,-2) (sum2) {$\\Sigma$};\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node [shape=coordinate] at (5,0) (output) {};\n    \\node [right of=output] {$y[n]$};\n    \n    \\draw [->] (input) -- (sum1);\n    \\draw (sum1) -- (conn);\n    \\draw [->] (conn) -- (output);\n    \\draw [->] (conn) -- (block1);\n    \\draw (block1) -- (conn1);\n    \\draw [->] (conn1) -- node {$-a$} (sum2);\n    \\draw [->] (conn1) -- (block2);\n    \\draw (block2) -- (conn2);\n    \\draw [->] (conn2) -| node {$-b$} (sum2);\n    \\draw [->] (sum2) -- (sum1);\n  \\end{tikzpicture}\n\\end{center}\n\n\\section{Implementing a DT System}\n\nAs in the CT case, one of the most powerful uses of block diagrams is the implementation of a DT system in hardware. As we shall see later in the semester, designing a DT system 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 digital circuit, implement using a digital signal processor, or write an equivalent program to run on an embedded or general purpose computer.\n\n\\begin{tabular}{cc}\n\n  Block & Typical Digital 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[n]$} (signal1);\n    \\draw (signal1) -- node {$a$} (signal2);\n    \\draw [->] (signal2) -- node[pos=1] {$y[n]$} (output);\n  \\end{tikzpicture}  \n\n  &\n  Multiplier (ALU)\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[n]$} (sum1);\n    \\draw [->] (input2) -| node[pos=0] {$x_2[n]$} (sum1);\n    \\draw [->] (sum1) -- node[pos=1] {$y[n]$} (output);\n  \\end{tikzpicture}  \n  &\n  Adder (ALU)\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[block] at (2,0) (block1) {$D$};\n    \\node [output, right of=block1] (output) {};\n\n    \\draw [->] (input) -- node {$x[n]$} (block1);\n    \\draw [->] (block1) -- node[pos=1] {$y[n]$} (output);\n  \\end{tikzpicture}  \n\n  &\n  Shift Register\\\\\n  \\hline\n\\end{tabular}\n\n\\begin{example} The following C++ code implements the second order system given by\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [left of=input] {$x[n]$};\n    \\node [sum] at (2,0) (sum1) {$\\Sigma$};\n    \\node [block] at (4,-1) (block1) {$D$};\n    \\node [block] at (4,-3) (block2) {$D$};\n    \\node [shape=coordinate, name=conn1] at (4,-2) {};\n    \\node [shape=coordinate, name=conn2] at (4,-4) {};\n    \\node [sum] at (2,-2) (sum2) {$\\Sigma$};\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node [shape=coordinate] at (5,0) (output) {};\n    \\node [right of=output] {$y[n]$};\n    \n    \\draw [->] (input) -- (sum1);\n    \\draw (sum1) -- (conn);\n    \\draw [->] (conn) -- (output);\n    \\draw [->] (conn) -- (block1);\n    \\draw (block1) -- (conn1);\n    \\draw [->] (conn1) -- node {$-\\frac{1}{2}$} (sum2);\n    \\draw [->] (conn1) -- (block2);\n    \\draw (block2) -- (conn2);\n    \\draw [->] (conn2) -| node {$-\\frac{1}{9}$} (sum2);\n    \\draw [->] (sum2) -- (sum1);\n  \\end{tikzpicture}\n\\end{center}\nusing floating point calculations. It assumes the current input is obtained via the function \\texttt{read}, and the output written using the function \\texttt{write}. The delayed values of the output are stored in the array \\texttt{buffer} and are initialized to zero (\"at rest\" prior to application of the input).\n\\begin{verbatim}\ndouble buffer[2] = {0.0,0.0};\nwhile(true){\n  double x = read();\n  double y = -0.5*buffer[1] - buffer[0]/9.0 + x;\n  write(y);\n  buffer[0] = buffer[1];\n  buffer[1] = y;\n}\n\\end{verbatim}\nNote in real applications it is common to replace the floating point calculations with fixed-width (scaled integer) ones.\n$\\blacksquare$\n\\end{example}\n\n", "meta": {"hexsha": "2edb00745be21bc66dfab62bf5d48c7e5fd772fb", "size": 20330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11-dt-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": "11-dt-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": "11-dt-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.4980079681, "max_line_length": 619, "alphanum_fraction": 0.6016724053, "num_tokens": 7140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867729389246, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6668719034197084}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Bias and mean squared error}\\label{sec:}\n\n%We now consider various notions of what constitutes a good estimator.\n%\\bigskip\n\n%Let $X$ be a random variable and let $F_X(x;\\theta)$ denote its CDF, where $\\theta\\in\\Theta$ is an unknown parameter. Let $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$, and let $T(X_1,X_2,\\ldots,X_n)$ be an estimator of the unknown parameter $\\theta$. Intuitively, we would like the value $T(x_1,x_2,\\ldots,x_n)$ to be `close' to $\\theta$ for `most' sample realisations $(x_1,x_2,\\ldots,x_n)$.\n\nLet $X$ be a random variable and let $F_X(x;\\theta)$ denote its CDF where $\\theta\\in\\Theta$ is an unknown parameter. Let $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the distribution of $X$ and let $T(\\mathbf{X})$ be an estimator of $\\theta$. Intuitively, we would like the estimate $T(\\mathbf{x})$ to be ``close'' to the true value $\\theta$ for ``most'' sample realisations $\\mathbf{x}\\in\\R^n$.\n\n%-----------------------------\n\\subsection{Bias}\n\n\\begin{definition}\nThe \\emph{bias} of an estimator $T$ is the expected difference between $T(\\mathbf{X})$ and the true parameter value $\\theta$,\n\\[\n\\bias(T;\\theta) = \\expe\\big[T(\\mathbf{X}) - \\theta\\big].\n\\]\nIf $\\bias(T;\\theta)=0$ for all $\\theta\\in\\Theta$ then $T$ is said to be an \\emph{unbiased} estimator of $\\theta$.\n\\end{definition}\n\n% example: sample variance\n\\begin{example}\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the $N(\\mu,\\sigma^2)$ distribution and consider the sample mean estimator of $\\sigma^2$ defined by\n\\[\nT(\\mathbf{X}) = \\frac{1}{n}\\sum_{i=1}^n (X_i-\\bar{X})^2 \\quad\\text{where}\\quad \\bar{X} = \\frac{1}{n}\\sum_{i=1}^n X_i.\n\\]\n\\ben\n\\it Show that $T$ is a biased estimator of $\\sigma^2$ and find its bias.\n\\it Show how can $T$ be modified to produce an unbiased estimator of $\\sigma^2$.\n\\een\n\\begin{solution}\n\\ben\n\\it % <<<\nRecall that $\\expe(\\Xbar) = \\mu$ and $\\var(\\Xbar) = \\sigma^2/n$. First,\n\\[\n\\expe(T)\t= \\expe\\left(\\frac{1}{n}\\sum_{i=1}^n (X_i-\\Xbar)^2\\right)\n\t\t\t= \\frac{1}{n}\\sum_{i=1}^n \\expe(X_i^2) - \\expe(\\Xbar^2).\n\\]\nSince $\\expe(X_i^2)\t= \\var(X_i)+\\expe(X_i)^2$ and $\\expe(\\Xbar^2) = \\var(\\Xbar)+\\expe(\\Xbar)^2$, we have\n\\[\n\\expe(X_i^2) = \\sigma^2 + \\mu^2 \\quad\\text{and}\\quad \\expe(\\Xbar^2) = \\frac{\\sigma^2}{n} + \\mu^2.\n\\]\nso\n\\[\n\\expe(T) \n\t= \\frac{1}{n}\\left[ n(\\sigma^2+\\mu^2)-n\\left(\\frac{\\sigma^2}{n} + \\mu^2\\right)\\right] \n\t= \\left(\\frac{n-1}{n}\\right)\\sigma^2.\n\\]\nThus $T$ is a biased estimator of $\\sigma^2$, and its bias is\n\\[\n\\bias(T;\\sigma^2) = \\expe(T - \\sigma^2) = \\expe(T) - \\sigma^2 = -\\frac{\\sigma^2}{n}.\n\\]\nWe say that $\\hat{\\sigma}^2$ is a \\emph{negatively biased} estimator of $\\sigma^2$ (it underestimates the true value).\n\\it % <<<\nLet\n\\[\nS^2(\\mathbf{X}) = \\left(\\frac{n}{n-1}\\right)T(\\mathbf{X}) = \\frac{1}{n-1}\\sum_{i=1}^n (X_i-\\bar{X})^2 \n\\]\nIt is easy to see that $S^2$ is an unbiased estimator of $\\sigma^2$. This is called the \\emph{sample variance}.\n\\een\n\\end{solution}\n\\end{example}\n\n% exercise: uniform\n\\begin{exercise}\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the $\\text{Uniform}(0,\\theta)$ distribution, where $\\theta>0$ is unknown. \n\\ben\n\\it Find the bias of $T_1(\\mathbf{X}) = 2\\Xbar$ as an estimator of $\\theta$.\n\\it Find the bias of $T_2(\\mathbf{X}) = \\max\\{X_1,X_2,\\ldots,X_n\\}$ as an estimator of $\\theta$.\n\\it How can $T_2$ be modified to produce an unbiased estimator of $\\theta$?\n\\een\n\\begin{answer}\n\\ben\n\\it % <<<\n$T_1$ is an \\emph{unbiased} estimator of $\\theta$ because\n\\[\n\\bias(T_1)\n\t= \\expe(T_1 - \\theta)\n\t= \\expe(T_1) - \\theta\n\t= 2\\expe(\\Xbar) -\\theta\n\t= 2(\\theta/2) - \\theta\n\t= 0.\n\\]\n\\it % <<<\nBecause the $X_i$ are independent, the CDF of $T_2$ is\n\\[\n\\prob(T_2 \\leq t) = \\left\\{\\begin{array}{ll}\n\t0\t\t\t\t& t \\leq 0, \\\\\n\t(t/\\theta)^n \t& 0 < t < \\theta, \\\\\n\t1\t\t\t\t& t \\geq \\theta.\n\\end{array}\\right.\n\\]\nA simple calculation shows that \n\\[\n\\displaystyle\\expe(T_2) = \\left(\\frac{n}{n+1}\\right)\\theta.\n\\]\nHence $T_2$ is a \\emph{negatively biased} estimator of $\\theta$:\n\\[\n\\bias(T_2) = \\expe(T_2 - \\theta) = \\left(-\\frac{1}{n+1}\\right)\\theta.\n\\]\n\\it % <<<\nA \\emph{bias correction} can be applied to $T_2$ to give an unbiased estimator $T_3 = \\displaystyle\\left(\\frac{n+1}{n}\\right)T_2$.\n\\een\n\\end{answer}\n\\end{exercise}\n%-----------------------------\n\\subsection{Mean squared error}\n\\bit\n\\it The bias of $T$ as an estimator of $\\theta$ is the \\emph{mean estimation error} $\\expe\\big[T-\\theta\\big].$ \n\\it The magnitude of the error can be quantified by the \\emph{mean squared estimation error} $\\expe\\big[(T-\\theta)^2\\big]$.\n\\eit\n\n% definition\n\\begin{definition}\nThe \\emph{mean squared error} of $T$ as an estimator of $\\theta$ is\n\\[\n\\mse(T;\\theta) = \\expe\\big[\\big(T(\\mathbf{X})-\\theta\\big)^2\\big].\n\\]\n\\end{definition}\n\nThe accuracy of an unbiased estimator can be quantified by its variance. For biased estimators, the MSE also takes the bias into account. The following result is easily proved by writing $T-\\theta$ as $[T-\\expe(T)]+[\\expe(T)-\\theta]$ then expanding the square and applying the linearity of expectation.\n% theorem\n\\begin{theorem}\n$\\mse(T;\\theta) = \\var(T) + \\bias(T;\\theta)^2$.\n\\end{theorem}\n%\\begin{proof}\n%\\begin{align*}\n%\\mse(T,\\theta) = \\expe\\big[(T-\\theta)^2\\big]\n%\t& = \\expe\\big[(T-\\expe(T) + \\expe(T)-\\theta)^2\\big] \\\\\n%\t& = \\expe\\big[(T-\\expe(T))^2 + 2(T-\\expe(T))(\\expe(T)-\\theta)+ (\\expe(T)-\\theta)^2 \\big] \\\\\n%\t& = \\expe\\big[(T-\\expe(T))^2\\big] + 2\\expe(T-\\expe(T))(\\expe(T)-\\theta)+ (\\expe(T) - \\theta)^2  \\\\\n%\t& = \\expe\\big[(T-\\expe(T))^2\\big] + \\big[\\expe(T) - \\theta\\big]^2 \\\\\n%\t& = \\var(T) + \\bias(T,\\theta)^2.\t\t\t\t\n%\\end{align*}\n%\\end{proof}\nAs the following example shows, a biased estimator with small variance is often ``better'' than an unbiased estimator with large variance.\n\n% example\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from a distribution with mean $\\mu$ and variance $\\sigma^2$. The sample mean $\\bar{X}$ is an unbiased estimator of $\\mu$, while the following statistic is a biased estimator of $\\mu$:\n\\[\nT(X_1,X_2,\\ldots,X_n) = \\frac{1}{n+1}\\sum_{i=1}^n X_i.\n\\]\n\\ben\n\\it Find $\\mse(\\bar{X};\\mu)$ and $\\mse(T;\\mu)$.\n\\it Find a condition involving $\\mu$ and $\\sigma$ under which $\\mse(T;\\mu) < \\mse(\\bar{X};\\mu)$.\n\\een\n\n\\begin{solution}\n\\begin{enumerate}\n\\item\n\\begin{align*}\n\\mse(\\bar{X};\\mu) \n\t= \\expe\\big[(\\bar{X}-\\mu)^2\\big] \n\t& = \\var(\\bar{X}) + \\expe(\\bar{X}-\\mu)^2 \n\t= \\var(\\bar{X}) \n\t= \\frac{\\sigma^2}{n}. \\\\\n\\mse(T;\\mu)\n\t= \\expe\\big[(T-\\mu)^2\\big] \n\t& = \\var(T) + \\expe(T-\\mu)^2 \\\\\n\t& = \\var\\left(\\frac{X_1+X_2+\\ldots+X_n}{n+1}\\right) + \\left(\\frac{n}{n+1}\\mu - \\mu\\right)^2 \\\\\n\t& = \\frac{n\\sigma^2}{(n+1)^2} + \\frac{\\mu^2}{(n+1)^2}\n\\end{align*}\n\\item\nComparing $\\mse(T;\\mu)$ with $\\mse(\\bar{X};\\mu)$:\n\\begin{align*}\n\\mse(T;\\mu) - \\mse(\\bar{X};\\mu)\n\t& = \\left(\\frac{n\\sigma^2}{(n+1)^2} + \\frac{\\mu^2}{(n+1)^2}\\right) - \\frac{\\sigma^2}{n} \\\\\n\t& = \\frac{\\mu^2}{(n+1)^2} - \\left(\\frac{1}{n} - \\frac{n}{(n+1)^2}\\right)\\sigma^2 \\\\\n\t& = \\frac{1}{(n+1)^2}\\left[\\mu^2 - \\left(\\frac{2n+1}{n}\\right)\\sigma^2\\right].\n\\end{align*}\n\nThis shows that \n\\[\n\\mse(T;\\mu) < \\mse(\\bar{X};\\mu) \\text{\\quad whenever\\quad} \\mu^2 < \\left(\\frac{2n+1}{n}\\right)\\sigma^2.\n\\]\n\\end{enumerate}\n\\end{solution}\n\\end{example}\n\n%----------------------------------------\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nLet $X_1, X_2, ...,X_n$ be a random sample of observations from the $\\text{Uniform}[\\theta,\\theta+1]$ distribution, where $\\theta$ is an unknown parameter.\n\\ben\n\\it Show that the sample mean $\\bar{X}$ is a biased estimator of $\\theta$, and find its bias.\n\\it Find the variance and mean squared error of $\\bar{X}$.\n\\it How can $\\bar{X}$ be modified to produce an unbiased estimator of $\\theta$?\n\\een\n\\begin{answer}\n\\ben\n\\it % <<<\nThe sample mean is biased because $\\expe(\\bar{X}) = \\theta +\\frac{1}{2} \\neq \\theta$. The bias is given by\n\\[\n\\bias(\\bar{X}) = \\expe(\\bar{X}-\\theta) = \\expe(\\bar{X})-\\theta = \\frac{1}{2}.\n\\]\n\\it % <<<\nThe variance and mean squared error of $\\bar{X}$ as an estimator of $\\theta$ are\n\\begin{align*}\n\\var(\\bar{X})\n\t& = \\frac{\\var(X)}{n} = \\frac{1}{12n}. \\\\\n\\mse(\\bar{X})\n\t&  = \\var(\\bar{X}) + \\bias(\\bar{X})^{2} = \\frac{1}{12n} + \\frac{1}{4} = \\frac{(1+3n)}{12n}.\n\\end{align*}\n\\it % <<<\n$\\bar{X} -\\frac{1}{2}$ is an unbiased estimator of ${\\theta}$, because $\\expe(\\bar{X} -\\frac{1}{2}) =\\expe(\\bar{X}) - 1/2 = \\theta$. \n\\een\n\\end{answer}\n\n\\question\nLet $X$ be a continuous random variable with the following PDF, where $\\alpha>0$ is known but $\\theta>0$ is unknown. \n\\[\nf(x;\\theta) = \\begin{cases}\n\t\\displaystyle \\frac{\\alpha x^{\\alpha-1}}{\\theta^{\\alpha}}\t& 0\\leq x\\leq \\theta, \\\\[2ex]\n\t0\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nA random sample $X_1,X_2,\\ldots,X_n$ is taken from the distribution of $X$. An estimator of $\\theta$ is provided by\n\\[\nT = \\max\\{X_1,X_2,\\ldots,X_n\\}.\n\\]\n\\begin{parts}\n\\part % << (1)\nShow that\n\\[\n\\expe(T) = \\displaystyle\\left(\\frac{n\\alpha}{n\\alpha+1}\\right)\\theta\n\\quad\\text{and}\\quad\n\\var(T) = \\displaystyle\\left(\\frac{n\\alpha}{n\\alpha+2}\\right)\\theta^2-\\left(\\frac{n\\alpha}{n\\alpha+1}\\right)^2\\theta^2.\n\\]\n\\begin{answer}\nTo find $\\expe(T)$ and $\\var(T)$ we first need to find the distribution of $T$. Let $F_X$ denote the CDF of $X$. \n\\[\nF_X(x;\\theta) = \\begin{cases}\n\t0 & x < 0 \\\\\n\t\\displaystyle\\left( \\frac{x}{\\theta } \\right) ^{\\alpha }  & 0 \\leq x \\leq \\theta \\\\\n\t1 & x > \\theta.\n\\end{cases}\n\\]\nIt is easy to show that the CDF of $T=\\max\\{X_1,X_2,\\ldots,X_n\\}$ is \n\\[\nF_{T}(v) = \\prob(T\\leq t) = \\big[F_X(t)\\big]^{n}.\n\\]\nIn this case,\n\\[\nF_{T}(t;\\theta) = \n\\begin{cases}\n\t0\t& t < 0, \\\\[1ex]\n\t\\displaystyle\\left( \\frac{t}{\\theta } \\right) ^{n\\alpha }  & 0 \\leq t \\leq \\theta, \\\\[1ex]\n\t1\t& t > \\theta,\n\\end{cases}\n\\]\t\nHence the PDF of $T$ is\n\\[\nf_{T}(t;\\theta) = \\begin{cases}\n\t\\displaystyle\\frac{n\\alpha }{\\theta ^{n\\alpha } } t^{(n\\alpha -1)} & 0 \\leq t \\leq \\theta \\\\[2ex]\n\t0\t& \\text{otherwise.}\n\\end{cases}\n\\]\t\nThe expected value and variance of $T=\\max\\{X_1,X_2,\\ldots,X_n\\}$ are computed as follows:\n\\begin{align*}\n\\expe(T)\n\t& = \\frac{n\\alpha}{\\theta^{n\\alpha}} \\int_{0}^{\\theta}  t^{n\\alpha }\\,dt\n\t  = \\frac{n\\alpha}{\\theta^{n\\alpha}} \\left[\\frac{t^{n\\alpha +1} }{(n\\alpha +1)} \\right] _{0}^{\\theta }\n\t= \\frac{n\\alpha }{(n\\alpha +1)} \\theta, \\\\\n\\expe(T^2)\n\t& = \\int_{0}^{\\theta }\\frac{n\\alpha }{\\theta ^{n\\alpha } }  t^{(n\\alpha +1)}\\,dt\n\t= \\frac{n\\alpha }{\\theta ^{n\\alpha } } \\left[ \\frac{t^{n\\alpha +2} }{n\\alpha +2} \\right] _{0}^{\\theta }\n\t= \\frac{n\\alpha }{(n\\alpha +2)} \\theta ^{2}, \\\\\n\\var(T)\n\t& = \\frac{n\\alpha }{(n\\alpha +2)} \\theta ^{2} -\\frac{n^{2} \\alpha ^{2} }{(n\\alpha +1)^{2} } \\theta ^{2}.\n\\end{align*}\t\n\\end{answer}\n\n\\part % << (2)\nShow that $T$ is a biased estimator of $\\theta$.\n\\begin{answer}\n$T$ is a biased estimator of ${\\theta}$ because\n\\[\n\\expe(T) = \\left(\\frac{n\\alpha }{n\\alpha +1}\\right) \\theta,\n\\]\nso $\\expe(T)\\neq\\theta$. The bias is \n\\[\n\\bias(T) \n\t= \\expe(T-{\\theta})\n\t= \\expe(T)-{\\theta} \n\t= \\frac{n\\alpha }{(n\\alpha +1)} \\theta -\\theta =\\frac{-\\theta }{(n\\alpha +1)}\n\\]\n\\end{answer}\n\n\\part % << (3)\nFind a multiple of $T$ that yields an unbiased estimator of $\\theta$.\n\\begin{answer}\nThe estimator $\\displaystyle\\left(\\frac{n\\alpha +1}{n\\alpha}\\right)T$ is an unbiased estimator of $\\theta$ because\n\\[\n\\expe\\left[\\left(\\frac{n\\alpha +1}{n\\alpha}\\right)T\\right] \n\t= \\left(\\frac{n\\alpha +1}{n\\alpha}\\right)\\expe(T)\n\t= \\left(\\frac{n\\alpha +1}{n\\alpha}\\right)\\frac{n\\alpha }{(n\\alpha +1)} \\theta \n\t= \\theta.\n\\]\n\\end{answer}\n\n\\part % << (4)\nFind the mean squared error of $T$.\n\\begin{answer}\nThe mean squared error of $T$ as an estimator of $\\theta$ is\n\\begin{align*}\n\\mse(\\hat{\\theta }) \n\t& = \\var(\\hat{\\theta }) + \\bias(T)^{2} \\\\\n\t& = \\frac{n\\alpha }{(n\\alpha +2)} \\theta ^{2} -\\frac{n^{2} \\alpha ^{2} }{(n\\alpha +1)^{2} } \\theta ^{2} + \\frac{\\theta ^{2} }{(n\\alpha +1)^{2} } \\\\\n\t& = \\frac{2\\theta ^{2} }{(n\\alpha +2)(n\\alpha +1)}\n\\end{align*}\n\\end{answer}\n\n\\end{parts}\n\n\\end{questions}\n\\end{exercise}\n\n", "meta": {"hexsha": "575c932596d5e3dc44968ff8c441f164dc904d11", "size": 11971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/07D_bias_and_mse.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/07D_bias_and_mse.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/07D_bias_and_mse.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": 36.9475308642, "max_line_length": 417, "alphanum_fraction": 0.6083869351, "num_tokens": 4708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.867035752930664, "lm_q1q2_score": 0.6668200715907505}}
{"text": "\\section{Countably Infinite Types} \\label{infinite}\nWe have now built up a substantial amount of theory relating to finite types.\nIn this section, we will look at the \\emph{countable} types: we will see that\nthere is a parallel kind of classification of predicates to the finiteness\npredicates, with some notable differences.\n\\subsection{Countability}\nFor our first countability predicate, we will mirror split enumerability:\n\\begin{definition}[Split Countability]\n  A type is ``split countable'' if there is a \\emph{stream} which contains all\n  of its elements.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Infinite/Split.tex]{split-count}\n  \\end{agdalisting*}\n\\end{definition}\nThe similarity to split enumerability should be clear: the only difference\nbetween the two definitions, in fact, is the type of the container.\n\nFor countability we use \\emph{streams}: these are basically infinite lists.\nTo a Haskeller, normal lists themselves often fulfil this purpose, but in a\ntotal language like Agda, we need a totally different type.\nLists, as an inductive type, are not permitted to be infinitely large.\n\\begin{definition}[Streams]\n  In Agda the type of streams can be given as a container:\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Container/Stream.tex]{stream-def}\n  \\end{agdalisting*}\n  Although this definition is so simple it is more common to define it without\n  reference to the usual container machinery:\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Codata/Stream.tex]{stream-def}\n  \\end{agdalisting*}\n  By inlining the definition of the container primitives it's clear that the two\n  types are isomorphic, but by defining streams in these terms we're able to\n  use things like the membership function on containers.\n\\end{definition}\n\nIn the previous sections we saw different flavours of finiteness which were\nreally just different flavours of relations to \\AgdaFunction{Fin}.\nUnsurprisingly, given the definition of streams, we will see in this subsection\nthat different flavours of countability are really just different flavours of\nrelations to \\Nat.\nCase in point: our definition of split enumerability is definitionally equal to\na split surjection from \\Nat.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Infinite/Split.tex]{split-surj}\n\\end{agdalisting*}\nFrom this we can derive decidable equality, just like we could with split\nenumerability. \\todo{Explain better?}\n\nWe also have equivalents to manifest enumerability, or even cardinal finiteness,\nin the countable setting: they are less interesting than split countability,\nhowever.\n\\subsection{Closure}\nThe closure proofs are where countability begins to differ from split\nenumerability.\nWe will see one closure proof that stays the same, one that is absent, and one\nthat is additional.\n\\paragraph{Instances for Finite Types}\nBefore we move on to the proper closure proofs, it is worth pointing out that\nall (non-empty) finite types are also countable.\nSplit countability, like split enumerability, does not disallow duplicates: this\nmeans that for any non-empty type we can simply repeat one of its elements\ninfinitely to produce a countability proof.\n\\paragraph{Closure Under \\(\\Sigma\\)}\nThe proof that split enumerability was closed under \\AgdaDatatype{\\(\\Sigma\\)}\nwas quite straightforward:\nwe were able to use the ``normal'' pattern of taking the Cartesian product of\ntwo lists in order to generate the finite support list for\n\\AgdaDatatype{\\(\\Sigma\\)}.\nUnfortunately this doesn't work for infinite types: the reason for which can be\nseen in \\Cref{pairings}.\n\n% \\todo{Explain this notion of exploration better:\n%   \\begin{itemize}\n%     \\item Talk about how we have to figure out a surjection from the natural\n%       numbers.\n%     \\item This is like trying to figure out a pattern which hits every number.\n%     \\item Or like a way to map some type to the numbers.\n%     \\item When doing this in some kind of closure-like proof, we can pretend\n%       that the input types (i.e. \\(A\\) and \\(B\\) in \\(A \\times B\\)) are simply\n%       \\(\\mathbb{N}\\).\n%   \\end{itemize}\n% }\n\n\\input{figures/pairing-functions}\n\nThe depth-first pattern is what we used previously: this explores the first list\nexhaustively before exploring anything other than the first element of the\nsecond list.\nThis clearly won't work for streams, as it would mean that nothing other than\nthe first element of the second type could be found in the entire support\nstream.\n\nSo instead we use the second pattern: breadth-first search.\nThe way we actually code this pattern up is a little complex: we treat the\nsearch space as having several ``levels''.\nEach item in each input list has a level (its position in that input list); the\noutput level for two items is the \\emph{sum} of those levels.\nIn pseudo-set-builder notation: \n\\begin{equation*}\n  (\\mathit{xs}\\times\\mathit{ys})_n =\n    \\left[ (\\mathit{xs}_i , \\mathit{ys}_j) \\vert i \\leftarrow \\left[ 0 \\ldots n \\right] ; j \\leftarrow \\left[ 0 \\ldots n \\right] ; i + j = n  \\right]\n\\end{equation*}\nAnd then this is flattened to give the output support list.\n\nOne last detail of this function before we actually provide it: we use yet\nanother definition of lists in its implementation, instead of the normal lists,\nas it is useful for termination proofs.\n\\begin{agdalisting*}\n  \\begin{multicols}{2} \\centering\n    \\ExecuteMetaDataInline[agda/Data/List/Kleene.tex]{plus-def} \\columnbreak\n    \\ExecuteMetaDataInline[agda/Data/List/Kleene.tex]{star-def}\n  \\end{multicols}\n\\end{agdalisting*}\nThis definition of lists interleaves the definition of non-empty lists with the\ndefinition of possibly-empty lists.\nThis makes it much easier to switch between the two without conversion\nfunctions.\n\nFinally, we can provide the function which actually performs the breadth-first\nsearch two streams.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Infinite/Split.tex]{sigma-sup}\n\\end{agdalisting*}\nThe corresponding cover proof is relatively straightforward, so we don't include\nit here.\n\\paragraph{Closure Under The Kleene Star}\nOne of the more useful types we can prove to be countably infinite is the\n\\emph{list}.\nThis proof is significantly more complex than the previous, however: we need to\nfind a pattern which eventually covers any given element of type\n\\AgdaDatatype{List}\\;\\(A\\), given \\AgdaFunction{\\(\\aleph\\)!}\\;\\(A\\).\nAgain we will tackle this pattern by first treating the exploration space as a\nseries of finite \\emph{levels}: we can then concatenate all of these levels\ntogether to a final exploration pattern.\nThe next trick is to figure out how to define those levels: we'll do it by\nsaying the lists of a given level \\(n\\) each must sum (after incrementing the\nindices of each element) to \\(n\\).\nThat means that the 0th level consists only of the empty list, the 1st level\nconsists of the list \\(\\left[ 0 \\right]\\), the 2nd of \\(\\left[ 0 , 0\n\\right]\\) and \\(\\left[ 1 \\right]\\), and so on.\nAgain, in pseudo set-builder notation:\n\\begin{equation*}\n  \\Nat\\star_i \\coloneqq \\left[ \\left[ \\mathit{xs}_{j - 1} \\mid j \\in \\mathit{js} \\right] \\mid \\mathit{js} : \\AgdaDatatype{List}\\;\\Nat ; \\AgdaFunction{sum}\\;\\mathit{js} = i ; 0 \\notin \\mathit{js}  \\right]\n\\end{equation*}\n\\todo{Include code?}\n\\paragraph{No Closure Under \\(\\Pi\\)}\nOne closure proof that is certainly not possible is closure under \\(\\Pi\\):\nit is not the case that functions from countable types are themselves countable.\nWhile this is a pretty basic fact in computer science, we include it here to\nshow how simple its proof in Agda can be:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Infinite/Split.tex]{cantor-diag}\n\\end{agdalisting*}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../paper\"\n%%% End:\n", "meta": {"hexsha": "82f7f2e63dfb5299aee526c3c745d9e52819d428", "size": 7759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/countable-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/countable-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/countable-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": 48.49375, "max_line_length": 203, "alphanum_fraction": 0.7665936332, "num_tokens": 1973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6668200631084333}}
{"text": "\\chapter{Convolutional Neural Networks}\n\\label{appx:simulation}\n\nConvolutional Neural Networks for image classification \\cite{krizhevsky2012imagenet} take an image as an input, process it, and output category to which that image belongs. The processing part consists of a series of layers through which image is propagated in order to learn features, which in turn determine to which class an image belongs. (\\textcolor{red}{\\autoref{fig:cnn1}}).\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale=2]{cnn.jpg}\n\t\\caption{Convolutional Neural Network consisting of two Convolutional layers, two Max-Pooling layers, Flatten layer and two Fully-Connected (Dense) layers, source \\cite{alom2019state}}\n\t\\label{fig:cnn1}\n\\end{figure}\n\nThe most commonly used layers in CNN architectures are convolutional layer, max-pooling layer, flatten layer, dense layer, and dropout layer.\n\n\\section{Convolutional Layer}\n\nThe convolutional layer is the building block of the CNN architecture. Its primary purpose is to extract features from an input image, such as edges, lines, curves, colors. As we go deeper inside the network, it starts identifying more complex features, such as shapes, objects. This layer consists of multiple filters (feature extractors, usually 3$\\times$3 matrices) whose parameters need to be learned.\n\\section{Max-Pooling Layer}\n\nThe max-pooling layer is located after a series of convolutional layers in CNN architecture. It is a downsampling method that reduces dimensionality, thus decreasing the number of parameters and computational power needed in order to train the network, while retaining important features and patterns. It is achieved by applying a max filter to non-overlapping subregions (usually 2$\\times$2 matrices), thus reducing the size of each feature map by a factor of 2.\n\n\\section{Flatten Layer}\n\nThe output of the convolutional base of the network (series of convolutional and max-pooling layers) is a two-dimensional matrix, and before feeding that data to the classification top of the network, it needs to be transformed. Flatten layer reshapes the output matrix to a vector, thus removing all dimensions but one in the process, making the data prepared for the series of fully-connected layers.\n\n\\section{Fully-Connected Layer}\n\nAfter the high-level features of the image have been detected, a series of fully-connected (dense) layers are attached to the top of the network in order to classify an image into a label. Dense layers consist of a huge number of nodes (neurons), which provide a way of learning non-linear combinations of features outputted by a convolutional base, and determine which features most correlate to a particular class.\n\n\\section{Dropout Layer}\n\nThe fully-connected layer contains the most parameters in the network, and as a result neurons develop co-dependency amongst each other during training, which leads to overfitting the data (not generalizing well on new, unseen images). In order to prevent that, dropout layers are positioned right after dense layers in CNN architecture as a means of regularizing the network. Dropout consists of randomly ignoring (dropping out) fraction of neurons of fully-connected layer, which in turn makes network learn more robust features, and achieve better performance.\n\\clearpage\n", "meta": {"hexsha": "173d67792e86804ba72b08d968e6d4a300e21261", "size": 3286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis_paper/appendices/cnn.tex", "max_stars_repo_name": "bmarko98/histopathologic-cancer-detection", "max_stars_repo_head_hexsha": "e3223856026a4bebeaeca46ea15dd42957c1e7da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-17T11:40:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T12:48:29.000Z", "max_issues_repo_path": "thesis_paper/appendices/cnn.tex", "max_issues_repo_name": "bmarko98/histopathologic-cancer-detection", "max_issues_repo_head_hexsha": "e3223856026a4bebeaeca46ea15dd42957c1e7da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-03T22:19:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-03T22:19:35.000Z", "max_forks_repo_path": "thesis_paper/appendices/cnn.tex", "max_forks_repo_name": "bmarko98/histopathologic-cancer-detection", "max_forks_repo_head_hexsha": "e3223856026a4bebeaeca46ea15dd42957c1e7da", "max_forks_repo_licenses": ["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.6470588235, "max_line_length": 563, "alphanum_fraction": 0.8079732197, "num_tokens": 703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6667915035192373}}
{"text": "\\section{Strong Markov Property}\r\n\\begin{definition}\r\n    A random variable $T=\\Omega\\to\\{0,1,\\ldots\\}\\cup\\{\\infty\\}$ is a stopping time if the event $\\{T=n\\}$ only depends on $X_0,\\ldots,X_n$.\r\n\\end{definition}\r\n\\begin{example}\r\n    (a) The first passage time $T_j=\\inf\\{n\\ge 1:X_n=j\\}$ is a stopping time.\\\\\r\n    (b) The hitting time $H^A$ of a subset $A\\subset I$ is a stopping time.\\\\\r\n    (c) (non-example) The last exit time of a subset $A\\subset I$, defined by $L^A=\\sup\\{n\\ge 0:X_n\\in A\\}$ is in general not a stopping time.\r\n\\end{example}\r\n\\begin{theorem}[Strong Markov Property]\\label{strong_markov}\r\n    Let $(X_n)_{n\\ge 0}$ be $\\operatorname{Markov(\\lambda,P)}$ and $T$ be a stopping time for $(X_n)$.\r\n    Then, conditional on $T<\\infty$ and $X_T=i$, the sequence $(X_{T+n})_{n\\ge 0}$ is $\\operatorname{Markov}(\\delta_i,P)$ and independent of $X_0,\\ldots,X_T$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $B$ be an event determined by $X_0,\\ldots,X_T$, then $B\\cap\\{T=m\\}$ is determined by $X_0,\\ldots,X_m$.\r\n    So\r\n    \\begin{align*}\r\n        &\\phantom{=}\\mathbb P[\\{X_T=j_0,\\ldots,X_{T=n}=j_n\\}\\cap B\\cap\\{T=m\\}\\cap\\{X_T=i\\}]\\\\\r\n        &=\\mathbb P[X_T=j_0,\\ldots,X_{T=n}=j_n]\\mathbb P[B\\cap\\{T=m\\}\\cap\\{X_T=i\\}\r\n    \\end{align*}\r\n    Summing over $m$ gives\r\n    \\begin{align*}\r\n        &\\phantom{=}\\mathbb P[\\{X_T=j_0,\\ldots,X_{T=n}=j_n\\}\\cap B\\cap\\{T<\\infty\\}\\cap\\{X_T=i\\}]\\\\\r\n        &=\\mathbb P[X_T=j_0,\\ldots,X_{T=n}=j_n]\\mathbb P[B\\cap\\{T<\\infty\\}\\cap\\{X_T=i\\}]\r\n    \\end{align*}\r\n    If $\\mathbb P[T<\\infty,X_T=i]>0$, we then have\r\n    \\begin{align*}\r\n        &\\phantom{=}\\mathbb P[\\{X_T=j_0,\\ldots,X_{T=n}=j_n\\}\\cap B|T<\\infty,X_T=i]\\\\\r\n        &=\\mathbb P[X_T=j_0,\\ldots,X_{T=n}=j_n]\\mathbb P[B|T<\\infty,X_T=i]\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\n\\begin{example}[Gambler's Ruin Continued]\r\n    Back to our previous example where for $i>0$, $p_{i,i+1}=p$ and $p_{i,i-1}=q=1-p$ and $p_{0,0}=1$.\r\n    We previously found the hitting probability of $\\{0\\}$.\r\n    We now want to find the distribution of time to hit it starting from $1$.\r\n    Let $H_j=\\inf\\{n\\ge 0:X_n=j\\}$ and\r\n    $$\\phi(s)=\\mathbb E[s^{H_0}]=\\mathbb E[s^{H_0}1_{H_0<\\infty}]=\\sum_{n=0}^\\infty s^n\\mathbb P[H_0=n]$$\r\n    where $s\\in [0,1)$.\r\n    We claim that $\\mathbb E_2[s^{H_0}]=\\phi(s)^2$.\r\n    To show this, we shall use the strong Markov property.\r\n    Conditional on $H_1<\\infty$ under $\\mathbb P_2$, we can write $H_0=H_1+\\tilde{H}_0$ where $\\tilde{H}_0$ is the time it takes after $H_1$ to reach state $0$.\r\n    Since $H_1$ is a stopping time, by applying Theorem \\ref{strong_markov} on $H_1$ we get $\\tilde{H}_0$ is independent of $H_1$ as it only depends on $(X_{H_1+n})_{n\\ge 0}$, so\r\n    \\begin{align*}\r\n        \\mathbb E_2[s^{H_0}]&=\\mathbb E_2[s^{H_1}|H_1<\\infty]\\mathbb E_2[s^{\\tilde{H}_0}|H_1<\\infty]\\mathbb P[H_1<\\infty]\\\\\r\n        &=\\mathbb E_2[s^{H_1}1_{H_1<\\infty}]\\mathbb E_2[s^{\\tilde{H}_0}|H_1<\\infty]\\\\\r\n        &=\\phi(s)^2\r\n    \\end{align*}\r\n    Our second claim is that $ps\\phi(s)^2-\\phi(s)+qs=0$.\r\n    Conditional on $X_1=2$, we have $H_0=1+\\bar{H}_0$ where $\\bar{H}_0$ is the time takes after $1$ step to reach $0$.\r\n    Then $\\bar{H}_0$ under $\\mathbb P[\\cdot|X_2=2]$ is the same distribution as $H_0$ under $\\mathbb P_2$.\r\n    So\r\n    \\begin{align*}\r\n        \\phi(s)&=\\mathbb E_1[s^{H_0}]\\\\\r\n        &=p\\mathbb E_1[s^{H_0}|X_1=2]+q\\mathbb E_1[s^{H_0}|X_1=0]\\\\\r\n        &=p\\mathbb E_1[s^{1+\\bar{H}_0}|X_1=2]+qs\\\\\r\n        &=ps\\mathbb E_1[s^{\\bar{H}_0}|X_1=2]+qs\\\\\r\n        &=ps\\mathbb E_2[s^{H_0}]+qs\\\\\r\n        &=ps\\phi(s)^2+qs\r\n    \\end{align*}\r\n    which shows the claim.\r\n    This means that\r\n    $$\\phi(0)=0,\\phi(s)=\\frac{1\\pm\\sqrt{1-4pqs^2}}{2ps},s>0$$\r\n    since $\\phi(s)\\le 1$ for all $s$ and $\\phi$ is continuous, only the minus case is possible in the quadratic formula, so we get, for $s>0$,\r\n    $$s\\mathbb P[H_0=1]+s^2\\mathbb P[H_0=2]+\\cdots=\\phi(s)=\\frac{1-\\sqrt{1-4pqs^2}}{2ps}=qs+pq^2s^3+\\cdots$$\r\n    In particular, $\\mathbb P[H_0=1]=q,\\mathbb P[H_0=2]=0,\\ldots$.\r\n    In addition, as $s\\to 1^-$, we have $\\phi(s)\\to\\mathbb P_1[H_0<\\infty]$, so\r\n    $$\\mathbb P_1[H_0<\\infty]=\\frac{1-\\sqrt{1-4pq}}{2p}=\\begin{cases}\r\n        1\\text{, if $p\\le q$}\\\\\r\n        q/p\\text{, if $p>q$}\r\n    \\end{cases}$$\r\n    which is our previous result.\r\n    Also, in the case $p\\le q$,\r\n    $$\\mathbb E_1[H_0]=\\mathbb E_1[H_01_{H_0<\\infty}]=\\lim_{s\\to 1^-}\\phi^\\prime(s)=\\lim_{s\\to 1^-}\\frac{p\\phi(s)^2+q}{1-2ps\\phi(s)}=\\frac{1}{1-2p}=\\frac{1}{q-p}$$\r\n\\end{example}", "meta": {"hexsha": "718dac2826c2dbbbe97faeed0b5e50fab5a1f498", "size": 4489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/strong.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": "4/strong.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": "4/strong.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": 59.8533333333, "max_line_length": 179, "alphanum_fraction": 0.5905546892, "num_tokens": 1914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.6667914948814032}}
{"text": "\\section{Neural Networks: Regression \\& Multinomial Classification}\nsupervised learning. \n\\subsection{Terminology}\n\\paragraph{Training Example} has form ($x_n, y_n$), with $x_n$ as input vector, $y_n$ expected/true output vector.\n\n\\paragraph{Loss/Cost Function} maps values of one or more variables onto a number representing \\textbf{loss/cost}.\n\nLearning $\\rightarrow$ minimizing a loss function.\n\n\\paragraph{Risk Function} \\textbf{expectation} of the \\textbf{loss function}. In neural network, we minimizes our risk by  \\textbf{minimizing the empirical risk function -- average loss of all training examples}.\n\n\\paragraph{Activation Function} \n\\begin{itemize}\n\t\\item linear activation  \n\t\\item sigmoid activation: \\textbf{focus of this lecture},  $\\sigma(x) = \\frac{e^x}{1 + e^x}$\n\t\\item Perceptron activation\n\t\\item ReLU activation\n\\end{itemize}\n\\paragraph{Epoch} one \\textbf{forward pass} and one \\textbf{backward pass} of \\textbf{all} training examples. One pass = forward + backward pass.\n\\begin{itemize}\n\t\\item Forward Pass: calculate the output of \\textbf{all training } through the neural network.\n\t\\item Backward Pass: Backpropagation \n\\end{itemize}\n\n\\paragraph{Backpropagation} calculate a \\textbf{gradient} that is needed in \\textbf{calculation of weights} to be used in network. It describes how a \\textbf{single training example} starting from \\textbf{output neurons} determines the goal for the neurons on the next layer and \\textbf{steps backwards recursively}.\n\n\\paragraph{Multi-Layer Feed-Forward Networks} represent arbitrary \\textbf{non-linear} functions. It consists of\n\\begin{itemize}\n\t\\item input layer\n\t\\item hidden layer with \\textbf{activation}\n\t\\item output layer with \\textbf{activation}\n\\end{itemize}\n\\textbf{Weights and biases} need to be adapted in the neural network. \n\n$\\rightarrow$ updated by \\textbf{backpropagation (gradient descent)}.\n\n\\subsection{Multi-Layer Feed-Forward Network}\n\\subsubsection{Setup of a Neural Network}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\textwidth]{nn.png}\n\\end{figure}\n\n\\subsubsection{Process}\nGoal of training: \\textbf{minimizes loss function, minimizes empirical risk}.\n\\\\ \\ \\\\\nAssume a network with 1 hidden layer, 1 output layer:\n\n\\begin{enumerate}[label= \\protect \\circled{\\arabic*} ]\n\t\\item \\textbf{Forward Pass}: from input layer to output layer (with \\textbf{sigmoid} activation).\n\t\n\tIf we are asked to perform, this calculation can done \\textbf{matrix-wise}!! No need to separate each observation.\n\t\n\t\\begin{align*}\n\t\tz^{[1]} &= W^{[1]}\\cdot a^{[0]} + b^{[1]} =  W^{[1]}\\cdot x + b^{[1]}\\\\\n\t\ta^{[1]} &= g^{[1]}(z^{[1]}) = \\sigma(z^{[1]}) \\\\\n\t\tz^{[2]} &= W^{[2]}\\cdot a^{[1]} + b^{[2]} \\\\\n\t\ta^{[2]} &= g^{[2]}(z^{[2]}) = \\sigma(z^{[2]})\n\t\\end{align*}\n\t\n\t\\item \\textbf{Loss Function}: calculate the loss of the network output according to the loss function $l(y, \\hat{y})$\n\t\n\tIf we evaluate the model using \\textbf{cross-entropy loss}: the calculation for $y \\ln\\hat{y}$ is a dot product(element-wise multiplication).\n\t$$l(y,\\hat{y}) = - [y \\ln \\hat{y} + (1-y)\\ln(1 - \\hat{y})]$$\n\t\\item \\textbf{Empirical Risk}: calculate the empirical risk $\\mathcal{L}$ by \\textbf{averaging} the loss.\n\t$$\\mathcal{L}(y,\\hat{y}) = \\frac{1}{n} \\cdot \\Sigma l(y,\\hat{y})$$\n\t\n\t\\item \\textbf{Backpropagation}: readapt the \\textbf{weights and biases} using \\textbf{gradient descent}. \n\t\n\texample in updating layer 2:\n\t\\begin{align*}\n\t\tW^{[2]}_{t+1} &= W^{[2]}_t - \\alpha \\cdot dW =W^{[2]}_t - \\alpha \\cdot \\frac{\\partial L}{\\partial W^{[2]}} \\\\\n\t\tb^{[2]}_{t+1} &= b^{[2]}_t - \\alpha \\cdot db =b^{[2]}_t - \\alpha \\cdot \\frac{\\partial L}{\\partial b^{[2]}} \n\t\\end{align*}\n\t\\begin{itemize}\n\t\t\\item $\\frac{\\partial L}{\\partial W^{[2]}}, \\frac{\\partial L}{\\partial b^{[2]}}$: chain rule\n\t\t$$\\frac{\\partial L_n}{\\partial W} = \\frac{\\partial L_n}{\\partial a_{n}} \\cdot \\frac{\\partial a_{n}}{\\partial z_{n}} \\cdot \\frac{\\partial z_n}{\\partial W}$$\n\t\\end{itemize}\n\t\\begin{align*}\n\t\tL_n &= \\frac{1}{2} (y_{n} - g(w_{kl}a_{kn} + b_l))^2 = \\frac{1}{2} (y_n - a_{ln})^2, \\quad &\\frac{\\partial L_n}{\\partial a_{ln}} &= -(y_n - a_{ln})\\\\\n\t\ta_{ln} &= g(z_{ln}) , \\quad &\\frac{\\partial L_n}{\\partial z_{ln}} &= g'(z_{ln}) \\\\\n\t\tz_{ln} &= w_{kl}a_{kn} + b_l, \\quad &\\frac{\\partial L_n}{\\partial w_{ln}} &= a_{kn} \t\n\t\\end{align*}\n\n\tIf the activation is a sigmoid activation: $\\sigma(x) = \\frac{e^x}{1 + e^x}$, $\\sigma'(x) = \\sigma(x)(1 - \\sigma(x))$.\n\t$$dW^{[2]} = -(y- a^{[2]})\\cdot a^{[1]^{T}} = (a^{[2]} - y) \\cdot a^{[1]^{T}}$$\n\\end{enumerate}\n\n\\subsubsection{Trainable Parameters}\nNumber of trainable parameters: the \\textbf{free parameters} of the neural network are \\textbf{weights and biases}-- $W^{[1]}, b^{[1]}, W^{[2]}, b^{[2]}, \\dots$. \n\n$\\rightarrow$ define the \\textbf{dimension} of these parameters, add up all possible trainable elements. \n\n(eg: $W^{[1]}$ is 2x2-matrix, therefore 4 trainable parameters)\n\\subsection{Gradient Descent for Backpropagation}\n\\begin{itemize}\n\t\\item Goal: given any function f, find $x^* = \\arg\\min_{x} f(x)$\n\t\\item \\textbf{Gradient} at position x is defined as the \\textbf{partial derivative}: \n\t$$\\nabla f(x) = \\begin{bmatrix}\n\t\\frac{\\partial f(x)}{x_1} \\\\ \\vdots \\\\ \\frac{\\partial f(x)}{x_d}\n\t\\end{bmatrix}$$ \n\t\\begin{itemize}\n\t\t\\item Interpretation: in d-dimensional space, gradient points in \\textbf{direction of steepest ascent} of f at point x. \t\n\t\\end{itemize}\n\t$\\rightarrow$ to \\textbf{minimize loss function} $\\rightarrow$ \\textbf{descent}, the opposite direction $\\mathbf{- \\nabla f(x)}$.\n\t\n\\end{itemize}\n\\subsubsection{General Process}\n\\begin{enumerate}[label= \\protect \\circled{\\arabic*} ]\n\t\\item choose an \\textbf{initial point}\n\t\\item choose a \\textbf{step size (either fixed or dynamic)}.\n\t\\item take a step in the \\textbf{direction opposite the gradient}.\n\t\\begin{itemize}\n\t\t\\item fixed step size:\n\t\t$$\\begin{bmatrix}\n\t\tx_n \\\\y_n\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\tx_{n-1} \\\\ y_{n-1}\n\t\t\\end{bmatrix} - \\alpha \\cdot \\nabla f(x_{n-1}, y_{n-1})$$\n\t\t\\item dynamic step size:\n\t\t$$\\begin{bmatrix}\n\t\tx_n \\\\y_n\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\tx_{n-1} \\\\ y_{n-1}\n\t\t\\end{bmatrix} - \\alpha_{n} \\cdot \\nabla f(x_{n-1}, y_{n-1})$$\n\t\\end{itemize}\n\t\\item repeat till convergence.\n\\end{enumerate}\n\nConvergence to optimum: depends on the \\textbf{step size}. \n\\begin{itemize}\n\t\\item too small: would converge eventually, but takes long time.\n\t\\item too large: value \\textbf{oscillates}, doesn't converge.\n\t\\item would stall if $\\nabla f(x) = 0$. \n\t\\item can stuck at saddle point.\n\\end{itemize}\nCriteria: \n\\begin{itemize}\n\t\\item function f is \\textbf{convex}\n\t\\item step size $\\alpha$ is square summable, but not summable.\n\\end{itemize}\n$\\rightarrow$ Alternative: introduce \\textbf{momentum}.\n\n\\subsubsection{Process with Momentum Introduced}\n\\begin{itemize}\n\t\\item Idea: uses an exponential averaging of gradients to \\textbf{make sudden changes in direction less likely}.\n\\end{itemize}\n\\begin{align*}\n\td_n &= \\beta \\cdot d_{n-1} + \\alpha \\cdot\\nabla f(x_{n-1})\\\\\n\tx_n &= x_{n-1} - d_n\n\\end{align*}\n", "meta": {"hexsha": "b4fe7663bea2f3725a8c8c98de7a112ba581fd00", "size": 6994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/nn.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/nn.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/nn.tex", "max_forks_repo_name": "YourPsychiatrist/TUM", "max_forks_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 46.0131578947, "max_line_length": 316, "alphanum_fraction": 0.6824420932, "num_tokens": 2352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6667430377792074}}
{"text": "\nLet us begin with a simple example, displaying some of the\ndifficulties we may have.\n\n\\begin{Problem}{unbounded-inverse}\n  On the space $\\ell_2(\\R)$ define the operator $A$ by its eigenvalue\n  decomposition\n  \\begin{align}\n    A: \\ell_2(\\R) &\\to \\ell_2(\\R)\\\\\n    e_k & \\mapsto \\tfrac1k e_k.\n  \\end{align}\n  Here, $\\{e_k\\}$ is the orthogonal basis of unit vectors of the form\n  \\begin{gather}\n    \\arraycolsep0.1em\n    \\begin{array}{cccccccc}\n      e_k =(0&,\\ldots,&0&,&1&,&0&,\\ldots)^\\transpose.\\\\\n      &&&&\\uparrow\\\\\n      &&&&k\n    \\end{array}\n  \\end{gather}\n  \\begin{enumerate}\n  \\item Show that this operator does not have a bounded inverse, albeit\n    its eigenvalues are positive.\n  \\item Show that the range of $A$ is not closed in $\\ell_2(\\R)$\n  \\end{enumerate}\n\\begin{solution}\n  \\begin{enumerate}\n  \\item For each $e_k$, the inverse is $A^{-1} e_k = k e_k$. In particular, $A$ is injective.\n    On the other hand, it holds\n    \\begin{gather}\n      \\lim_{k\\to\\infty}\\frac{\\norm{A^{-1}e_k}}{\\norm{e_k}}=\\lim_{k\\to\\infty}k=\\infty\n    \\end{gather}\n      and the inverse cannot be bounded.\n  \\item We have to construct a convergent sequence in the range of $A$\n    such that the pre-image of the sequence does not converge.\n    \\begin{enumerate}\n    \\item Choose\n      \\begin{gather}\n        v_n = \\sum_{k=1}^n \\frac1k e_k.\n      \\end{gather}\n      \\item $v_n$ is a Cauchy-sequence, since\n        \\begin{gather}\n          \\norm{v_m-v_n}^2 = \\norm*{\\sum_{k=m}^n \\frac1k e_k}^2\n          = \\sum_{k=m}^n \\frac1{k^2}\\norm*{e_k}^2\n          \\le \\frac1{m^2} \\sum_{k=1}^\\infty \\frac1{k^2}\n          = \\frac{\\pi^2}{6} \\frac1{m^2}.\n        \\end{gather}\n      \\item We conclude that $v=\\lim_{n\\to\\infty}v_n$ exists in the\n        closure of the range of $A$.\n      \\item There holds\n        \\begin{gather}\n          v_n = A \\sum_{k=1}^n e_k =: A u_n.\n        \\end{gather}\n      \\item Due to the injectivity of $A$ for $v$ to be in the range of $A$,\n            $u_n$ has to converge in $\\ell_2(\\R)$.\n      \\item The sequence $u_n$ is not a Cauchy sequence, since\n        \\begin{gather}\n          \\norm{v_m-v_n}^2 = \\norm*{\\sum_{k=m}^n e_k}^2\n          = \\sum_{k=m}^n \\norm*{e_k}^2\n          = n-m.\n        \\end{gather}\n    \\end{enumerate}\n  \\end{enumerate}\n\\end{solution}\n\\end{Problem}\n\n\\section{Finite-dimensional problems}\n\\begin{intro}\n  So far, our power horse for well-posedness was the Lax-Milgram\n  lemma, which can be applied under the conditions\n  \\begin{xalignat}2\n    a(u,v) &\\le M \\norm{u}\\norm{v} & \\forall u,v&\\in V\\\\\n    a(u,u) &\\ge \\ellipa \\norm{u}^2 & \\forall u&\\in V.\n  \\end{xalignat}\n  The second condition can also be rewritten in terms of the\n  \\putindex{Rayleigh quotient} as\n  \\begin{gather}\n    0 < \\ellipa = \\inf_{u\\in V}\\frac{a(u,u)}{\\norm{u}^2}.\n  \\end{gather}\n  Restricting this to a finite dimensional space, the notation usually\n  changes from\n  \\begin{gather}\n    a(u,v) = f(v)\n    \\qquad\\text{to}\\qquad\n    v^\\transpose A u = v^\\transpose f,\n  \\end{gather}\n  where $A\\in \\R^{n\\times n}$ is the matrix associated with the\n  bilinear form. The bound for the Rayleigh quotient means nothing but\n  that the real parts of all eigenvalues of $A$ are bounded from below\n  by $\\ellipa$. Thus, a matrix $A$ for which we can apply the\n  Lax-Milgram lemma is positive definite. And the statement of the\n  lemma in finite dimension is, that a positive definite matrix is\n  invertible. We know from linear algebra that this is true, but we\n  also know that the condition is all but necessary.\n\\end{intro}\n\n\\begin{intro}\n  Why did we replace this clear theorem by the weaker Lax-Milgram\n  lemma, when we studied elliptic partial differential equations?  For\n  the first condition, it should be noted that spectral properties of\n  operators between spaces of infinite dimension are much harder to\n  obtain. Further, we do not need information on the whole spectrum,\n  but only on the eigenvalue closest to zero. Therefore, we used a\n  simple estimate in order to avoid discussing the spectrum at\n  all. But, there is an important difference between\n  Theorem~\\ref{Theorem:la-invertible} and the\n  estimate~\\eqref{eq:infsup:elliptic}: the assumption of the theorem\n  is qualitative, $\\lambda \\neq 0$, while the assumption of Lax-Milgram\n  is quantitative,\n  \\begin{gather}\n    \\Re\\lambda \\ge \\ellipa> 0.\n  \\end{gather}\n  The following problem shows why such a change is necessary.\n\\end{intro}\n\n\n\\begin{Problem}{lax-milgram-not-applicable}\n  Find an invertible, symmetric matrix $A\\in \\R^{2\\times 2}$ and a\n  vector $v\\in \\R^2$ such that $v^\\transpose A v=0$ and thus the Lax-Milgram\n  lemma is inconclusive.\n\\begin{solution}\n  \\begin{gather}\n    A =\n    \\begin{pmatrix}\n      1 & 0 \\\\ 0 & -1\n    \\end{pmatrix}\n  \\end{gather}\n\\end{solution}\n\\end{Problem}\n\nThe question of well-posedness in finite dimensions can be answered by:\n\n\\begin{Theorem}{la-invertible}\n  A matrix $A\\in\\R^{n\\times n}$ is invertible if and only if one of\n  the following equivalent conditions holds:\n  \\begin{enumerate}\n  \\item all its (possibly complex) eigenvalues are nonzero,\n  \\item all its singular values are nonzero,\n  \\item for each nonzero $v\\in\\R^n$ holds $Av\\neq 0$.\n  \\end{enumerate}\n\\end{Theorem}\n\n\\begin{intro}\n  We focus on the second and third conditions, respectively, in\n  Theorem~\\ref{Theorem:la-invertible}.\n  But, the problem above tells us that we\n  will run into trouble, if we do not quantify this. Therefore, we\n  start our attempt by requiring:\n  \\begin{gather}\n    \\norm{Au}^2 \\ge \\ellipa \\norm{u}^2 \\qquad\\forall u\\in V.\n  \\end{gather}\n  But while this is a condition we can easily write down for matrices\n  and operators, it does not work that well for bilinear forms. Thus,\n  we first look at the singular value decomposition.\n\\end{intro}\n\n\\input{svd}\n\n\\begin{Definition}{ker-range-rn}\n  \\index{ker}\n  Let $A: V\\to W$ be a linear operator. Then, we define\n  the \\define{kernel} and the \\define{range} of $A$ as\n  \\begin{align}\n    \\ker A &= \\bigl\\{ v\\in V \\big| Av = 0\\bigr\\} \\\\\n    \\range A &= \\bigl\\{ w\\in W \\big| \\;\\exists\\,v\\in V: Av=w\\bigr\\}.\n  \\end{align}\n\\end{Definition}\n\n\\begin{Definition}{orthogonal1}\n  Let $V\\subset\\R^n$ be a subspace. We define the \\define{orthogonal\n    complement} of $V$ as\n  \\begin{gather}\n    \\label{eq:infsup:4}\n    \\ortho{V} = \\bigl\\{w\\in \\R^n \\big| \\;\\forall\\,v\\in V \\scal(w,v) = 0 \\bigr\\}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{ker-coker-rn}\n  Let $A\\in \\R^{m\\times n}$ and $A^\\transpose$ its transpose. Then, there holds\n  \\begin{gather}\n    \\label{eq:infsup:5}\n    \\begin{split}\n      \\ker A &= \\ortho{\\range{A^\\transpose}}\\\\\n      \\range A &= \\ortho{\\ker{A^\\transpose}}\\\\\n      \\ker{A^\\transpose} &= \\ortho{\\range A}\\\\\n      \\range{A^\\transpose} &= \\ortho{\\ker{A}}\n    \\end{split}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  % First, we note that\n  % \\begin{gather}\n  %   \\R^n = \\ker A \\oplus \\ortho{\\ker A},\n  %   \\qquad\n  %   \\R^m = \\ker{A^\\transpose} \\oplus \\ortho{\\ker{A^\\transpose}}.\n  % \\end{gather}\n  Let $A=U\\Sigma V^\\transpose$ be the singular value decomposition of $A$ and\n  $r$ be the number of nonzero singular values. Then, the first $r$\n  vectors of $U$ span the range of $A$ and the last $n-r$ vectors of\n  $V$ span its kernel. Furthermore,\n  \\begin{gather}\n    A^\\transpose = \\bigl(U\\Sigma V^\\transpose\\bigr)^\\transpose = V \\Sigma U^\\transpose.\n  \\end{gather}\n  Therefore, the first $r$ vectors of V span the range of\n  $A^\\transpose$ and the last $n-r$ vectors of $U$ span its\n  kernel. The lemma follows since $U$ and $V$ are orthogonal.\n\\end{proof}\n\n\\begin{Corollary}{ker-coker-iso}\n  Let $A\\in \\R^{m\\times n}$ and $A^\\transpose$ its transpose. Then, the\n  restrictions $A\\colon \\ortho{\\ker A} \\to \\range A$ and $A^\\transpose\\colon\n  \\ortho{\\ker{A^\\transpose}} \\to \\range{A^\\transpose}$ are isomorphisms.\n  \n  The linear system $Ax=f\\in\\R^m$ has at least one solution if and\n  only if $f\\in \\range A$. If $x\\in\\R^n$ is such a solution, then\n  every $y\\in\\R^n$ with $y-x\\in\\ker A$ is a solution as well.\n\\end{Corollary}\n\n\\begin{proof}\n  We note that $\\dim \\range A = \\dim \\range{A^\\transpose}$. Thus, by\n  \\slideref{Lemma}{ker-coker-rn} the dimensions of domain and range of\n  each of the restricted operators are equal, say $\\dim \\range A =\n  r$. The singular value decomposition of the operators is\n  \\begin{gather}\n    A = U\\Sigma V^\\transpose \\qquad A^\\transpose = V\\Sigma U^\\transpose,\n  \\end{gather}\n  where all matrices are in $\\R^{r\\times r}$ and\n  \\begin{gather}\n    \\Sigma = \\diag(\\sigma_1,\\dots,\\sigma_r),\n  \\end{gather}\n  and all singular values are positive. Thus, $A$ and $A^\\transpose$ are invertible.\n\\end{proof}\n\n\\begin{Corollary}{svd-infsup}\n  Let $r=\\dim \\ortho{\\ker A}$. Then, for the smallest nonzero singular\n  value there holds\n  \\begin{gather}\n    \\label{eq:infsup:6}\n    \\sigma_r\n    = \\inf_{v\\in \\ortho{\\ker A}} \\sup_{w\\in \\R^m} \\frac{w^\\transpose A v}{\\norm{v}\\norm{w}}\n    = \\inf_{w\\in \\ortho{\\ker{A^\\transpose}}} \\sup_{v\\in \\R^n} \\frac{w^\\transpose A v}{\\norm{v}\\norm{w}}.\n  \\end{gather}\n\\end{Corollary}\n\n\\begin{proof}\n  Since the Cauchy-Schwarz inequality turns into an equation if and\n  only if the two vectors are coaligned, there holds for any $v\\in \\R^n$:\n  \\begin{gather}\n    \\sup_{w\\in\\R^m}\\frac{w^\\transpose A v}{\\norm{w}} = \\frac{v^\\transpose A^\\transpose A v}{\\norm{Av}} = \\frac{\\norm{Av}^2}{\\norm{Av}}.\n  \\end{gather}\n  Therefore,\n  \\begin{gather}\n    \\inf_{v\\in \\ortho{\\ker A}} \\sup_{w\\in \\R^m}\n    \\frac{w^\\transpose A v}{\\norm{v}\\norm{w}}\n    = \\inf_{v\\in \\ortho{\\ker A}} \\frac{\\norm{Av}}{\\norm{v}}.\n  \\end{gather}\n  Now, let $v = \\sum \\alpha_i v_i$ where $v_i$ are the columns of $V$\n  in the SVD of $A$. Then,\n  \\begin{gather}\n    \\norm{Av}^2 = \\norm*{A\\sum_{i=1}^r \\alpha_i v_i}^2\n    = \\norm*{\\sum_{i=1}^r \\sigma_i \\alpha_i u_i}^2\n    = \\sum_{i=1}^r \\sigma_i^2 \\alpha_i^2.\n  \\end{gather}\n  The quotient\n  \\begin{gather}\n    \\frac{\\sum_{i=1}^r \\sigma_i^2 \\alpha_i^2}{\\sum_{i=1}^r \\alpha_i^2}\n  \\end{gather}\n  clearly has its minimum if $\\alpha_1 = \\dots=\\alpha_{r-1} = 0$.\n\\end{proof}\n\n\\begin{Definition}{infsup1}\n  A bilinear form $a(\\cdot,\\cdot)$ on $V\\times W$ is said to admit the\n  \\define{inf-sup condition} or is called \\define{inf-sup stable}, if\n  there holds\n  \\begin{gather}\n    \\label{eq:infsup:1}\n    \\inf_{u\\in V} \\sup_{w\\in W} \\frac{a(u,w)}{\\norm{u}_V\\norm{w}_W}\n    \\ge \\ellipa > 0.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{remark}\n  In this finite dimensional exposition, is clear that $V$ and $W$\n  must have the same dimension, and thus $V=W=\\R^n$. This will be\n  different, when we consider infinite dimensional spaces and indeed\n  consider different spaces $V$ and $W$.\n\\end{remark}\n\n\\begin{todo}\n  The last statement uses the wrong spaces. Either restrict the whole\n  argument here to $\\R^n$ or think about dual spaces.\n\\end{todo}\n\n\\begin{Lemma}{infsup2}\n  The following statements are equivalent to the inf-sup\n  condition~\\eqref{eq:infsup:1}:\n  \\begin{gather}\n    \\label{eq:infsup:2}\n    \\forall u\\in V \\;\\exists w\\in W \\;:\\;\n    a(u,w) \\ge \\ellipa \\norm{u}_V\\norm{w}_W\n  \\end{gather}\n  \\begin{gather}\n    \\label{eq:infsup:3}\n    \\forall u\\in V\n    \\;\\exists w\\in W \\;:\\;\n    \\left\\{\n    \\arraycolsep0.3ex\n    \\begin{array}{rcl}\n      \\norm{w}_W &\\le&\\norm{u}_V\\\\\n      a(u,w) &\\ge& \\ellipa \\norm{u}_V^2\n    \\end{array}\n    \\right.\n  \\end{gather}\n  \\begin{gather}\n    \\label{eq:infsup:3a}\n    \\forall u\\in V\n    \\;\\exists w\\in W \\;:\\;\n    \\left\\{\n    \\arraycolsep0.3ex\n    \\begin{array}{rcl}\n      \\ellipa \\norm{w}_W &\\le&\\norm{u}_V\\\\\n      A^\\transpose w &=& u\n    \\end{array}\n    \\right.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Problem}{inf-sup-equivalence}\n  Prove \\slideref{Lemma}{infsup2}.\n\\begin{solution}\n  We have to prove the following statements are equivalent to the inf-sup condition:\n  \\begin{align}\n    \\forall u\\in V \\;\\exists w\\in W \\;:\\; a(u,w) \\ge \\ellipa \\norm{u}_V\\norm{w}_W     \\tag{1}\n  \\end{align}\n  \\begin{align}\n   \\begin{aligned}\n    \\forall u\\in V \\;\\exists w\\in W \\;:\\;\n    \\begin{cases}\n      \\norm{w}_W \\le\\norm{u}_V\\\\\n      a(u,w) \\ge \\ellipa \\norm{u}_V^2\n    \\end{cases}\n   \\end{aligned}\n   \\tag{2}\n  \\end{align}\n  \\begin{align}\n   \\begin{aligned}\n    \\forall u\\in V \\;\\exists w\\in W \\;:\\;\n    \\begin{cases}\n      \\ellipa \\norm{w}_W \\le \\norm{u}_V\\\\\n      Aw = u\n      \\end{cases}\n  \\end{aligned}\n      \\tag{3}\n  \\end{align}\n  The inf-sup condition reads\n  \\begin{align}\n   \\inf_{u\\in V} \\sup_{w\\in W} \\frac{a(u,w)}{\\norm{u}_V\\norm{w}_W} \\ge \\ellipa \\tag{IS}\n  \\end{align}\n\n  $(IS)\\Rightarrow(3)$\\\\\n  The inf-sup condition is equivalent to $A: ker(A)^\\perp\\to V^*$ being an isomorphism.\n  By the Riesz representation theorem there exists for a given $u\\in V$ a $w\\in W$ such that\n  $Aw=J u$ where $J$ is the Riesz map. Hence, it holds\n  \\begin{align}\na(u,w)=\\langle A w, u\\rangle = \\langle J u, u\\rangle = \\norm{u}_V^2.\n  \\end{align}\n Due to $w\\in ker(A)^\\perp$, $A^{-1}$ is bounded and\n \\begin{align}\n \\norm{w}_W=\\norm{A^{-1}u}_V\\leq \\frac{1}{\\ellipa}\\norm{u}_V.\n  \\end{align}\n\n  $(3)\\Rightarrow(2)$ \\\\\n  Define $\\tilde{w}=\\ellipa w$. Then,\n  \\begin{align}\na(u,\\tilde{w})=\\ellipa a(u,w) = \\ellipa \\norm{u}_V^2\n  \\end{align}\n  and\n  \\begin{align}\n\\norm{\\tilde{w}}_W=\\ellipa \\norm{w}_W\\leq\\norm{u}_V\n  \\end{align}\n\n  $(2)\\Rightarrow(1)$ \\\\\n  \\begin{align}\n  a(u,w) \\ge \\ellipa \\norm{u}_V^2 \\ge \\ellipa \\norm{u}_V \\norm{w}_W\n  \\end{align}\n\n  $(1)\\Rightarrow(IS)$ \\\\\n  \\begin{align}\n  &\\forall u\\in V \\exists w\\in W: a(u,w)\\ge \\ellipa \\norm{u}_V\\norm{w}_W\\\\\n  &\\Rightarrow \\forall u\\in V: \\sup_{w\\in W} \\frac{a(u,w)}{\\norm{w}_W}\\ge \\ellipa \\norm{u}_V\\\\\n  &\\Rightarrow \\inf_{u\\in V}\\sup_{w\\in W} \\frac{a(u,w)}{\\norm{w}_W\\norm{u}_V}\\ge \\ellipa\n  \\end{align}\n\\end{solution}\n\\end{Problem}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Infinite dimensional Hilbert spaces}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  In the previous section, we derived quantitative conditions to\n  ensure the invertibility of a matrix $A$ or its restriction to its\n  cokernel $\\ortho{\\ker A}$. The arguments there have a natural\n  extension to infinite dimensional Hilbert spaces, which we will\n  derive in this section. We already saw in\n  \\slideref{Problem}{unbounded-inverse} that we may run into trouble\n  if the range of $A$ is not closed. On the other hand, it turns out\n  that most notions of linear algebra related to orthogonality can be\n  maintained in Hilbert spaces if closed subspaces are considered.\n  We begin by citing the most important results.\n\n  The presentation here is neither complete nor self-contained. It\n  just highlights some of the important facts. In particular, we\n  assume the validity of the \\putindex{Riesz representation theorem}\n  and the existence of a \\putindex{Schauder basis} a priori.\n\\end{intro}\n\n\\begin{Notation}{musical-isomorphisms}\n  The \\putindex{Riesz representation theorem} induces isomorphisms\n  between a Hilbert space $V$ and its dual $V^*$. We call them\n  \\define{Riesz isomorphism}s. Following custom in differential\n  geometry, we denote them as \\define{musical isomorphism}s\n  \\begin{xalignat}2\n    I_\\flat\\colon V&\\to V^*\n    &I_\\sharp\\colon V^*&\\to V\\\\\n    v&\\mapsto v^\\flat\n    &\\phi&\\mapsto \\phi^\\sharp.\n  \\end{xalignat}\n  \\index{sharp@$\\sharp$}\\index{flat@$\\flat$}\\index{b@$\\flat$}\n\\end{Notation}\n\n\\begin{Problem*}{riesz-h10}{Riesz Isomorphisms}\n  Let $V=H^1_0(\\domain)$ on the domain $\\domain=(0,1)$ be equipped with the\n  inner product\n  \\begin{gather}\n    \\scal(u,v)_V = \\int_0^1 u'v'\\dt.\n  \\end{gather}\n  \\begin{enumerate}\n  \\item Show that for any function $f\\in L^2(\\domain)$ the functional\n    $\\phi_f$ defined by\n    \\begin{gather}\n      \\phi_f(v) = \\int_0^1 f v \\dt\n    \\end{gather}\n    is in $V^*$, even if $f\\not\\in V$.\n  \\item Discuss this for the function $f\\equiv 1$ and compute $f^\\sharp$.\n  \\end{enumerate}\n\\end{Problem*}\n\n\\begin{Example}{solution-pressure}\n  When we look at computing the pressure in Stokes' equations, we have\n  to solve a weak formulation of the form: find $p\\in Q$ such that\n  \\begin{gather}\n    \\form(\\div \\vv,p) = g(v) \\qquad \\forall \\vv\\in \\vV.\n  \\end{gather}\n  Here $\\vg\\in \\vV^*$ consists of the parts of the momentum equation not\n  containing the pressure. If we define $B^\\transpose$ by\n  \\begin{gather}\n    \\scal(B^\\transpose q,\\vv)_{V^*\\times V} = \\form(\\div \\vv,q)\n    \\qquad \\forall \\vv\\in \\vV, q \\in Q,\n  \\end{gather}\n  then the operator form of the problem posed in $\\vV^*$ is\n  \\begin{gather}\n    B^\\transpose p = g\n  \\end{gather}\n  Since this equation involves two different spaces, we require an\n  extension of \\slideref{Lemma}{ker-coker-rn}.\n\\end{Example}\n\n\\begin{Definition}{polar-orthogonal}\n  Let $W\\subset V$ be a subspace of a Hilbert space $V$. We define its\n  \\define{orthogonal complement} $\\ortho{W}\\subset V$ and its\n  \\define{polar space} $\\polar{W}\\subset V^*$ by\n  \\begin{gather}\n    \\label{eq:infsup:7}\n    \\begin{aligned}\n    \\ortho{W} &= \\bigl\\{v\\in V &\\big|&& \\scal(v,w)_{V} &= 0\n    &\\forall\\,w&\\in W\\bigr\\},\n    \\\\\n    \\polar{W} &= \\bigl\\{f\\in V^* &\\big|&& \\scal(f,w)_{V^*\\times V} &= 0\n    &\\forall\\,w&\\in W\\bigr\\}.\n    \\end{aligned}\n  \\end{gather}\n  For a subspace $U\\subset V^*$, we define its polar space\n  \\begin{gather}\n    \\dualpolar{U} = \\bigl\\{v\\in V \\quad\\big|\\quad \\scal(u,v)_{V^*\\times V} = 0\n    \\quad\\forall\\,u\\in U\\bigr\\}\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Problem}{polar-orthogonal}\n  Show that $\\polar{W} = I_\\flat \\ortho{W}$ and $\\dualpolar{U} = I_\\sharp \\ortho{U}$.\n\\end{Problem}\n\n\\begin{Lemma}{orthogonal-closed}\n  The polar space $\\polar{W}$ and the orthogonal complement $\\ortho{W}$ of a\n  subspace $W\\subset V$ are both closed. So is the polar space $\\dualpolar{U}$\n  of a subspace $U\\subset V^*$.\n\\end{Lemma}\n\n\\begin{proof}\n  Consider the mapping\n  \\begin{align}\n    \\Phi_w\\colon V^* &\\to \\R,\\\\\n    \\phi&\\mapsto \\scal(\\phi,w)_{V^*\\times V}.\n  \\end{align}\n  For any $w$, the kernel of $\\Phi_w$ is closed as\n  the pre-image of a closed set. $\\polar{W}$ is closed since it is the\n  intersection of these kernels for all $w\\in W$.\n\n  The inner product is continuous on $V\\times V$. Therefore, the\n  mapping\n  \\begin{align}\n    \\Psi_w\\colon V &\\to \\R,\\\\\n    v&\\mapsto \\scal(v,w),\n  \\end{align}\n  is continuous. The argument continues as above. Similar for $\\dualpolar{U}$.\n\\end{proof}\n\n\\begin{Theorem}{orthogonal-complement}\n  Let $W$ be a subspace of a Hilbert space $V$ and $\\ortho{W}$ its\n  orthogonal complement. Then, $\\ortho{W} =\n  \\ortho{\\overline{W}}$. Furthermore, there holds\n  \\begin{gather}\n    V = W \\oplus \\ortho{W}\n    \\qquad\\Longleftrightarrow\\qquad\n    \\text{$W$ is closed.}\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{proof}\n  Clearly, $\\ortho{\\overline{W}} \\subset \\ortho{W}$ since\n  $W\\subset\\overline{W}$. Let now $u\\in \\ortho{W}$. Then, $\\phi =\n  \\scal(u,\\cdot)$ is a continuous linear functional on $V$. Therefore,\n  if a sequence $w_n \\subset W$ converges to $w\\in \\overline{W}$, we\n  have\n  \\begin{gather}\n    \\scal(u,w) = \\lim_{n\\to\\infty} \\scal(u,w_n) = 0.\n  \\end{gather}\n  Hence, $u\\in \\ortho{\\overline{W}}$ and $\\ortho{W} = \\ortho{\\overline{W}}$.\n\n  Now, the ``only if'' follows by the fact, that if $W$ is not\n  closed, there is an element $w\\in \\overline{W}$ but not in $W$ such that\n  $\\scal(w,u)=0$ for all $u\\in \\ortho{W}$. Thus, $w\\not\\in \\ortho{W}$ and\n  consequently $w\\not\\in \\ortho{W} \\oplus W$.\n\n  Let now $W$ be closed. We show that there is a unique decomposition\n  \\begin{gather}\n    \\label{eq:infsup:8}\n    v = w + u,\\qquad w\\in W, \\;u\\in \\ortho{W},\n  \\end{gather}\n  which is equivalent to $V = W \\oplus \\ortho{W}$. Uniqueness follows,\n  since\n  \\begin{gather}\n    v = w_1+u_1 = w_2+u_2\n  \\end{gather}\n  implies that for any $y\\in V$\n  \\begin{gather}\n    0 = \\scal(w_1-w_2+u_1-u_2,y) = \\scal(w_1-w_2,y) + \\scal(u_1-u_2,y).\n  \\end{gather}\n  Choosing $y=u_1-u_2$ and $w_1-w_2$ in turns, we see that one of the\n  inner products vanishes for orthogonality and the other implies that\n  the difference is zero.\n\n  If $v\\in W$, we choose $w=v$ and $u=0$. For $v\\not\\in W$, we prove\n  existence by considering that due to the closedness of $W$ there holds\n  \\begin{gather}\n    d=\\inf_{w\\in W} \\norm{v-w} >0.\n  \\end{gather}\n  Let $w_n$ be a minimizing sequence. Using the parallelogram identity\n  \\begin{gather}\n    \\norm{a+b}^2+\\norm{a-b}^2 = 2\\norm{a}^2+2\\norm{b}^2,\n  \\end{gather}\n  we prove that $\\{w_n\\}$ is a Cauchy sequence by\n  \\begin{align}\n    \\norm{w_m-w_n}^2 &= \\norm{(v-w_n)-(v-w_m)}^2\\\\\n    &= 2\\norm{v-w_n}^2+2\\norm{v-w_m}^2-\\norm{2v-w_m-w_n}^2\\\\\n    &= 2\\norm{v-w_n}^2+2\\norm{v-w_m}^2-4\\norm*{v-\\frac{w_m+w_n}2}^2\\\\\n    &\\le 2\\norm{v-w_n}^2+2\\norm{v-w_m}^2-4d^2,\n  \\end{align}\n  since $(w_m+w_n)/2\\in W$ and $d$ is the infimum. Now we use the\n  minimizing property to obtain\n  \\begin{gather}\n    \\lim_{m,n\\to\\infty}\\norm{w_m-w_n}^2 = 2d^2-2d^2 -4d^2=0.\n  \\end{gather}\n  By completeness of $V$, $w=\\lim w_n$ exists and by the closedness of\n  $W$, we have $w\\in W$. Let $u=v-w$. By continuity of the norm, we\n  have $\\norm{u}=d$. It remains to show that $u\\in \\ortho{W}$. To this\n  end, we introduce the variation $w+\\epsilon \\tilde w$ with $\\tilde\n  w\\in W$ to obtain\n  \\begin{align}\n    d^2 &\\le \\norm{v-w-\\epsilon \\tilde w}^2\\\\\n    &= \\norm{u}^2-2\\epsilon\\scal(u,\\tilde w)+\\epsilon^2 \\norm{\\tilde w},\n  \\end{align}\n  implying for any $\\epsilon>0$\n  \\begin{gather}\n    0\\le-2\\epsilon\\scal(u,\\tilde w)+\\epsilon^2 \\norm{\\tilde w},\n  \\end{gather}\n  which requires $\\scal(u,\\tilde w) = 0$.\n\\end{proof}\n\n\\begin{Definition}{orthogonal-projection}\n  Let $V$ be a Hilbert space and $W\\subset V$ be a closed\n  subspace. For a vector $v\\in V$, let $v=w+u$ be the unique\n  decomposition with $w\\in W$ and $u\\in \\ortho{W}$. Then we call $w$ and\n  $u$ the \\define{orthogonal projection}s of $v$ into $W$ and $\\ortho{W}$,\n  respectively. We write\n  \\begin{gather}\n    \\Pi_W v = w, \\qquad \\Pi_{\\ortho{W}} v = u.\n  \\end{gather}\n\\end{Definition}\n\n% \\begin{Lemma}{polar-orthogonal-hilbert}\n%   Let $V$ be a Hilbert space and $W\\subset V$ be a closed\n%   subspace. Then, the polar space $\\polar{W}\\subset V^*$ and the orthogonal\n%   space $\\ortho{W}$ can be isometrically identified by \\putindex{Riesz\n%     representation}.\n% \\end{Lemma}\n\n% \\begin{proof}\n%   For every $f$ in the\n%   dual of $\\ortho{W}$, define $g\\in V^*$ by\n%   \\begin{gather}\n%     \\scal(g,v)_{V^*\\times V} =\n%     \\scal(f,\\Pi_{\\ortho{V}}v)_{(\\ortho{V})^*\\times \\ortho{V}}.\n%   \\end{gather}\n%   Clearly, $g(v)=0$ for $v\\in W$, therefore $g\\in \\polar{W}$.\n% \\end{proof}\n\n% \\begin{Corollary}\n\n% \\end{Corollary}\n\n\n\\begin{Theorem*}{closed-range}{Closed Range Theorem}\n  Let $V,W$ be Hilbert spaces and $A\\colon V\\to W$ a continuous linear\n  operator. Then, the following statements are equivalent:\n  \\begin{gather}\n    \\label{eq:infsup:9}\n    \\begin{split}\n      \\range A &\\text{ is closed in } W,\\\\\n      \\range{A^\\transpose} &\\text{ is closed in } V^*,\\\\\n      \\range A &= \\dualpolar{\\ker{A^\\transpose}},\\\\\n      \\range{A^\\transpose} &= \\polar{\\ker A}.\n    \\end{split}\n  \\end{gather}\n\\end{Theorem*}\n\n\\begin{remark}\n  This is the famous \\emph{\\putindex{closed range theorem}} by Banach.\n  It actually holds under weaker assumptions, for instance $V,W$ only\n  Banach spaces. The proof can be found for instance\n  in~\\cite[p.~205--209]{Yosida80}.\n\\end{remark}\n\n\\begin{Theorem*}{open-mapping}{Open Mapping Theorem}\n  Let $A\\colon V\\to W$ be continuous and surjective. Then, the image\n  $A(U)\\subset W$ of any open set $U\\subset V$ is open.\n\\end{Theorem*}\n\n\\begin{remark}\n  This is the \\emph{\\putindex{open mapping theorem}} by Banach. The\n  proof can be found for instance in~\\cite[p.75--76]{Yosida80}.\n\\end{remark}\n\n\\begin{Lemma}{closed-infsup}\n  Let $A\\colon V\\to W$ be continuous. Then, $\\range A$ is closed in\n  $W$ if and only if there exists $\\ellipa>0$ such that\n  \\begin{gather}\n    \\label{eq:infsup:10}\n    \\forall w\\in \\range A\\;\n    \\exists v\\in V\\quad\n    Av = w\n    \\;\\wedge\\;\n    \\ellipa \\norm{v}_V \\le \\norm{w}_W.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  We first show that the inf-sup condition~\\eqref{eq:infsup:10}\n  implies $\\range A$ closed. To this end, let $\\{w_n\\}$ be a Cauchy\n  sequence in $\\range A$ converging to a point $w\\in W$. By the assumption,\n  there\n  is a sequence $\\{v_n\\}$ in $V$ such that $Av_n = w_n$ and\n  $\\ellipa \\norm{v_n} \\le \\norm{w_n}$. Hence, using\n  \\begin{gather}\n    \\norm{v_m-v_n}_V \\le \\frac1\\ellipa \\norm{w_m-w_n}_W,\n  \\end{gather}\n  we realize that $\\{v_n\\}$ is a Cauchy sequence in $V$. Therefore, $v_n\\to v\\in\n  V$ and due to continuity of $A$ we obtain $Av=w$ and thus $w\\in\n  \\range A$.\n\n  Conversely, let $\\range A$ be closed in $W$. Thus, it is a Banach\n  space and the \\putindex{open mapping theorem} applies to $A\\colon\n  V\\to\\range A$. We map the open unit ball $B_1(0)\\subset V$ and\n  obtain that $A(B_1(0))$ is open in $\\range A$, implying that there\n  is an open ball $B_\\delta(0) \\subset A(B_1(0))$. This is sufficient\n  to construct $v$:\n\n  Let $w\\in\\range A$. Then,\n  \\begin{gather}\n    \\tilde w = \\frac\\delta2 \\frac{w}{\\norm{w}}\n    \\in B_\\delta(0) \\subset A(B_1(0)).\n  \\end{gather}\n  Hence, there is $v\\in V$ with $\\norm{v}<1$ such that $Av=\\tilde w$,\n  which proves the lemma.\n\\end{proof}\n\n\\begin{Theorem}{infsup-well-equivalence}\n  Let $a(\\cdot,\\cdot)$ on $V\\times W$ be a bounded bilinear form % such that\n%  \\begin{gather}\n%    a(v,w) \\le M \\norm{v}_V \\norm{w}_W,\n%  \\end{gather}\n  and $A\\colon V\\to W^*$ its associated operator.\n  Then, the following statements are equivalent:\n  \\begin{enumerate}\n  \\item There exists $\\ellipa>0$ such that\n    \\begin{gather}\n      \\label{eq:infsup:11}\n      \\inf_{w\\in W}\\sup_{v\\in V}\n      \\frac{a(v,w)}{\\norm{v}_V\\norm{w}_W}\n      \\ge \\ellipa.\n    \\end{gather}\n  \\item The operator $A^\\transpose\\colon W\\to \\polar{\\ker A}$ is an isomorphism and\n    \\begin{gather}\n      \\label{eq:infsup:12}\n      \\norm{A^\\transpose w}_{V^*} \\ge \\ellipa \\norm{w}_{W} \\qquad\\forall w\\in W.\n    \\end{gather}\n  \\item The operator $A\\colon \\ortho{\\ker A}\\to W^*$ is an isomorphism\n    and\n    \\begin{gather}\n      \\label{eq:infsup:13}\n      \\norm{Av}_{W^*} \\ge \\ellipa\\norm{v}_V\\qquad \\forall v\\in \\ortho{\\ker A}.\n    \\end{gather}\n  \\end{enumerate}\n\\end{Theorem}\n\n\\begin{proof}\n  First, we show the equivalence of the first two statements. Let us\n  use equivalently to the inf-sup condition~\\eqref{eq:infsup:11}\n  \\begin{gather}\n    \\norm{A^\\transpose w}_{V^*}\n    = \\sup_{v\\in V}\\frac{\\scal(A^\\transpose w,v)}{\\norm{v}_V}\n    = \\sup_{v\\in V}\\frac{a(v,w)}{\\norm{v}_V}\n    \\ge \\ellipa\\norm{w} \\qquad\n    \\forall w\\in W.\n  \\end{gather}\n  Thus, equations~\\eqref{eq:infsup:11} and~\\eqref{eq:infsup:12} are\n  equivalent and we have already proven that the second statement\n  implies the first. It remains to show the $A^\\transpose$ is an isomorphism\n  from $W$ onto $\\polar{\\ker A}$. Equation~\\eqref{eq:infsup:12} implies that\n  $A^\\transpose\\colon W \\to \\range{A^\\transpose}$ is an isomorphism and its inverse is\n  bounded by $1/\\ellipa$ (multiply both sides by $A^{-1}$). Using\n  \\slideref{Lemma}{closed-infsup}, we obtain that $\\range{A^\\transpose}$ is\n  closed in $V^*$ and the \\putindex{closed range theorem} settles the\n  issue.\n\n  In order to prove equivalence of the second and third statement, we\n  use the result of \\slideref{Problem}{polar-orthogonal} to isometrically\n  identify $(\\ortho{\\ker A})^*$ with $\\polar{\\ker A}$. Thus, $A$ is an\n  isomorphism from $\\ortho{\\ker A}$ onto $W^*$ if and only if $A^\\transpose$ is an\n  isomorphism from $W$ onto $(\\ortho{\\ker A})^* = \\polar{\\ker A}$. and\n  \\begin{gather}\n    \\norm{A}_{W^*\\to \\ortho{\\ker A}} = \\norm{A^\\transpose}_{\\polar{\\ker A}\\to W}.\n  \\end{gather}\n\\end{proof}\n\n\\begin{Corollary}{infsup-well-posedness1}\n  Let $a(\\cdot,\\cdot)$ on $V\\times W$ be a bounded bilinear form. %such that\n  %\\begin{gather}\n  %  a(v,w) \\le M \\norm{v}_V \\norm{w}_W.\n  %\\end{gather}\n  Let the inf-sup-condition\n  \\begin{gather}\n    \\inf_{w\\in W}\\sup_{v\\in V}\n    \\frac{a(v,w)}{\\norm{v}_V\\norm{w}_W}\n    \\ge \\ellipa > 0\n  \\end{gather}\n  hold.  Then, the problem finding $w\\in W$ such that\n  \\begin{gather}\n    a(v,w) = f(v) \\qquad\\forall v\\in V,\n  \\end{gather}\n  has a unique solution for $f\\in \\polar{\\ker A}$ and\n  \\begin{gather}\n    \\norm{w}_W \\le \\frac1\\ellipa \\norm{f}_{V^*}.\n  \\end{gather}\n  The opposite implication holds true.\n\\end{Corollary}\n\n\\begin{remark}\n  \\slideref{Corollary}{infsup-well-posedness1} exhibits an asymmetry\n  between the left and right argument. In particular, we obtain a\n  unique solution only for the adjoint operator $A^\\transpose$, which is\n  exactly what we need, when we compute say a pressure from the\n  divergence of a velocity field. In general, we consider the\n  restriction of $f$ to the polar set of the kernel in the above\n  well-posedness result detrimental and would prefer a result that\n  holds for all $f\\in V^*$. This on the other hand requires\n  $\\ker A=\\{0\\}$, or $\\overline{\\range{A^\\transpose}} = W^*$. Then, on the\n  other hand, we see that $\\range{A^\\transpose}$ is closed since $\\range{A}$ is\n  closed and the closed range theorem holds. Therefore, we obtain the\n  following theorem for the case that we require a unique solution for\n  all right hand sides.\n\\end{remark}\n\n\\begin{Theorem}{infsup-well-posedness2}\n  Let $a(\\cdot,\\cdot)$ on $V\\times W$ be a bounded bilinear form. % such that\n%  \\begin{gather}\n%    a(v,w) \\le M \\norm{v}_V \\norm{w}_W.\n%  \\end{gather}\n  Let for some $\\ellipa>0$ the inf-sup-conditions\n  \\begin{align}\n    \\inf_{w\\in W}\\sup_{v\\in V}\n    \\frac{a(v,w)}{\\norm{v}_V\\norm{w}_W}\n    &\\ge \\ellipa,\\\\\n    \\inf_{v\\in V}\\sup_{w\\in W}\n    \\frac{a(v,w)}{\\norm{v}_V\\norm{w}_W}\n    &\\ge \\ellipa\n  \\end{align}\n  hold.  Then, the problem finding $v\\in V$ such that\n  \\begin{gather}\n    a(v,w) = f(w) \\qquad\\forall w\\in W,\n  \\end{gather}\n  has a unique solution for $f\\in W^*$ and\n  \\begin{gather}\n    \\norm{v}_V \\le \\frac1\\ellipa \\norm{f}_{W^*}.\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{Problem}{closed-range}\n  Assume for $A\\colon V\\to W^*$ that $\\range A$ is closed. Show\n  \\begin{enumerate}\n  \\item $A:V\\to W^*$ is surjective if and only if $A^\\transpose$ is\n    injective.\n  \\item Show that with all other assumptions unchanged, the second\n    inf-sup condition in \\slideref{Theorem}{infsup-well-posedness2} is\n    not only sufficient, but equivalent to $A$ injective.\n  \\item \\slideref{Theorem}{infsup-well-posedness2} seems excessive if\n    we only want to establish one of the statements\n    \\begin{xalignat}3\n      \\forall f&\\in W^*& \\exists u&\\in V& a(u,w) &= f(w)\\\\\n      \\forall g&\\in V^*& \\exists u&\\in W& a(v,u) &= g(v)\n    \\end{xalignat}\n    Is this true or is there equivalence of both inf-sup conditions\n    with only one of these statements?\n  \\end{enumerate}\n\\end{Problem}\n\n\\begin{remark}\n  If we compare \\slideref{Theorem}{infsup-well-posedness2} with\n  \\slideref{Corollary}{infsup-well-posedness1}, we see that the only\n  difference lies in the fact that the second inf-sup condition\n  ensures surjectivity of $A$ by injectivity of $A^\\transpose$. In some cases\n  it may be impossible difficult to prove both inf-sup conditions. Then, it is\n  sufficient to prove one inf-sup condition, say the first, and then\n  only injectivity of $A^\\transpose$. Although we verify less than the\n  assumptions of \\slideref{Theorem}{infsup-well-posedness2}, the\n  closed range theorem saves us from the additional work. We further\n  note that this notion is symmetric between $A$ and $A^\\transpose$, that is,\n  it is sufficient to prove inf-sup for either operator and\n  injectivity for the other.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The inf-sup condition for mixed problems}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  In the previous section, we have developed a framework for\n  well-posedness of problems which are not $V$-elliptic. In principle,\n  this theory can be applied to the bilinear form\n  $\\mathcal A((u,p),(v,q))$ as a whole. On the other hand, we can\n  formally split the solution of a constrained minimization problem\n  into the reduced problem and then computing the Lagrange multiplier,\n  which more clearly exhibits the relation of the two spaces $V$ and\n  $Q$ involved in the mixed formulation. Here are the resulting\n  theorems.\n\\end{intro}\n\n\\begin{Definition}{mixed-weak}\n  The abstract saddle-point problem in weak form reads:\n  find $(u,p)\\in V\\times Q$ such that\n  \\begin{gather}\n    \\label{eq:saddle-point-weak}\n    \\arraycolsep.1em\n    \\begin{matrix}\n      a(u,v) &+& b(v,p) &=& f(v) &\\quad&\\forall v\\in V, \\\\\n      b(u,q) && &=& g(q) &&\\forall q\\in Q.\n    \\end{matrix}\n  \\end{gather}\n  Here, $V$ and $Q$ are Hilbert spaces chosen, such that $a(.,.)$ and\n  $b(.,.)$ are bounded bilinear forms on $V\\times V$ and $V\\times Q$,\n  respectively. The bounds $\\bounda$ and $\\boundb$ are such that\n  \\begin{gather}\n    \\label{eq:saddle-point-bounds}\n    \\sup_{u,v\\in V}\\frac{a(u,v)}{\\norm{u}_V\\norm{v}_V} = \\bounda,\n    \\qquad\n    \\sup_{\\substack{v\\in V\\\\q\\in Q}}\\frac{b(v,q)}{\\norm{v}_V\\norm{q}_Q} = \\boundb.\n  \\end{gather}\n\\end{Definition}\n\n\n\\begin{Theorem}{infsup-mixed1}\n  Let $V$ and $Q$ be Hilbert spaces. Let $a(\\cdot,\\cdot)$ and\n  $b(\\cdot,\\cdot)$ be bounded bilinear forms. Then, the weak\n  formulation find $u\\in V$ and $p\\in Q$ such that\n  \\begin{gather}\n    a(u,v) + b(v,p) + b(u,q)\n    = f(v)+g(q)\n    \\qquad\\forall v\\in V, q\\in Q,\n  \\end{gather}\n  has a unique solution for any $f\\in V^*$ and any $g\\in Q^*$ if and\n  only if there exists $\\ellipa>0$ such that\n  \\begin{gather}\n    \\label{eq:infsup:system-infsup}\n    \\inf_{\\substack{u\\in V\\\\p\\in Q}}\n    \\sup_{\\substack{v\\in V\\\\q\\in Q}}\n    \\quad \\frac{a(u,v) + b(v,p) + b(u,q)}{\\norm{(u,p)}_{V\\times\n        Q}\\norm{(v,q)}_{V\\times Q}} \\ge \\ellipa.\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{proof}\n  Straight application of \\slideref{Theorem}{infsup-well-posedness2}.\n\\end{proof}\n\nOften, like in the case of Stokes' equations, the properties of the\nform $a(\\cdot,\\cdot)$ or the form $b(\\cdot,\\cdot)$ are already known\nand you want to combine them to a mixed formulation. Thus, the theorem\nabove is unwieldy, since it requires to do the analysis from\nscratch. We thus provide an equivalence theorem, which allows us to\nseparate the properties of the bilinear forms.\n\n\\begin{Theorem}{infsup-mixed2}\n  Let $V$ and $Q$ be Hilbert spaces and let\n  \\begin{gather}\n    \\begin{split}\n      \\ker B &= \\bigl\\{v\\in V \\big| b(v,q) = 0 \\;\\forall q\\in Q\\bigr\\}.\n    \\end{split}\n  \\end{gather}\n  Then, the mixed problem finding $(u,p)\\in V\\times Q$ such that\n  \\begin{gather}\n    a(u,v) + b(v,p) + b(u,q) = f(v) \\quad\\forall v\\in V, q\\in Q,\n  \\end{gather}\n  is well-posed if and only if the reduced problem\n  finding $u\\in \\ker B$ such that\n    \\begin{gather}\n      a(u,v) = f(v) \\quad\\forall v\\in \\ker B\n    \\end{gather}\n    is well-posed for any $f\\in V^*$ and there is a positive constant\n    $\\infsupc$ such that\n    \\begin{gather}\n      \\inf_{q\\in Q}\\sup_{v\\in V} \\frac{b(v,q)}{\\norm{v}_V\\norm{q}_Q} \\ge \\infsupc.\n    \\end{gather}\n\\end{Theorem}\n\n\\begin{proof}\n  In order to show the ``if'', we note that by well-posedness of the\n  reduced problem, $u\\in V$ is well-determined and bounded by the data\n  $f\\in V^*$ without knowledge of the Lagrange\n  multiplier. Furthermore, there holds $b(u,q) = 0$.\n  \n  Entering this into the mixed formulation, the Lagrange multiplier\n  $p$ is determined by\n  \\begin{gather}\n    b(v,p) = f(v) - a(u,v), \\qquad\\forall v\\in V.\n  \\end{gather}\n  Applying \\slideref{Corollary}{infsup-well-posedness1} to the\n  bilinear form $b(.,.)$, we deduce that this equation has a unique\n  solution $p\\in Q$ if and only if $f-a(u,\\cdot) \\in \\polar{\\ker B}$, which\n  is true due to the statement of the reduced problem.\n\n  For the only if, we note that choosing $v=0$ in the mixed problem,\n  we see that there holds\n  \\begin{gather}\n    b(u,q) = 0 \\qquad \\forall q\\in Q,\n  \\end{gather}\n  and thus $u\\in \\ker B$. For such $u$ holds in the mixed formulation\n  \\begin{gather}\n    f(v) = a(u,v) + b(v,p) = a(u,v) \\qquad \\forall v \\in \\ker B.\n  \\end{gather}\n  In order to deduce the inf-sup condition, we note that\n  well-posedness of the mixed problem implies the inf-sup\n  condition~\\eqref{eq:infsup:system-infsup}. Since the infimum will\n  not decrease by taking a subset, we confine the set to $u=0$ and\n  obtain\n  \\begin{align}\n    &\\inf_{p\\in Q}\\sup_{v\\in V} \\frac{b(v,p)}{\\norm{v}_V\\norm{q}_Q}\n    \\\\ = &\n           \\inf_{p\\in Q}\n           \\sup_{\\substack{v\\in V\\\\q\\in Q}}\n    \\frac{a(0,v) + b(v,p) + b(0,q)}{\\norm{(0,p)}_{V\\times Q} \\norm{(v,q)}_{V\\times Q}}\n    \\\\ \\ge&\n            \\inf_{\\substack{u\\in U\\\\p\\in Q}}\n    \\sup_{\\substack{v\\in V\\\\q\\in Q}}\n    \\frac{a(u,v) + b(v,p) + b(u,q)}{\\norm{(u,p)}_{V\\times Q} \\norm{(v,q)}_{V\\times Q}} \\\\\\ge& \\ellipa > 0\n  \\end{align}\n\\end{proof}\n\n\\begin{Problem}{inhomogeneous-continuity}\n  Show that \\slideref{Theorem}{infsup-mixed2} can be extended to the\n  case with right hand side $f(v)+g(q)$ with $g\\in Q^*$.\n\n\\begin{solution}\n  We want to solve the problem\n  \\begin{align}\n    a(u,v) + b(v,p) + b(u,q) = f(v)+g(q) \\quad\\forall v\\in V, q\\in Q,\n  \\end{align}\n  where $b(v,p)$ fulfills a inf-sup condition.\n\n  \\begin{enumerate}\n  \\item Due to \\slideref{Theorem}{infsup-well-equivalence}, the\n    operator $B: V\\to Q^*$ is surjective and thus, there exists\n    $u_g\\in V$ such that\n    \\begin{gather}\n      b(u_g,q) = q(q) \\quad\\forall q\\in Q.\n    \\end{gather}\n  \\item Now consider the function $u_0 = u-u_g$. For $u$ to solve the\n    original problem $u_0$ has to solve\n    \\begin{align}\n      a(u_0+u_g,v) + b(v,p) + b(u_0+u_g,q) = f(v)+g(q) \\quad\\forall v\\in V, q\\in Q\\\\\n      \\Leftrightarrow a(u_0,v) + b(v,p) + b(u_0,q) = f(v)-a(u_g,v) \\quad\\forall v\\in V, q\\in Q\n    \\end{align}\n  \\item Due to $a(u_g,v) \\leq \\bounda \\norm{u_g}_V\\norm{v}_V$,\n    the right-hand side $f(\\cdot)-a(u_g,\\cdot)$ is in $V^*$\n    and we are in the setting of\n    \\slideref{Theorem}{infsup-mixed2}.\n  \\end{enumerate}\n\\end{solution}\n\\end{Problem}\n\n\\begin{remark}\n  Since $V$ is a Hilbert space, the decomposition\n  $V = \\ker B \\oplus \\ker B^\\perp$ is uniquely determined and there is\n  a corresponding decomposition $V^* = \\polar{(\\ker B^\\perp)} \\oplus \\polar{\\ker B} = I_\\flat\\ker B \\oplus I_\\flat \\ortho{\\ker B} $,\n  such that $f = f^0+f^\\perp$ above. The way we solve the reduced\n  problem first and then compute the Lagrange multiplier implies that\n  the solution $u$ only depends on $f^\\perp$ only.\n\\end{remark}\n\n\\begin{remark}\n  We have imposed well-posedness of the reduced problem only in an\n  abstract way. Depending on $a(.,.)$ we can formulate two conditions:\n  ellipticity on $\\ker B$ or inf-sup stability on $\\ker B$. Indeed,\n  most problems considered in this class will have symmetric bilinear\n  forms $a(.,.)$, such that ellipticity serves as our usual\n  assumption.  In these cases, note that $V$-ellipticity already\n  implies the well-posedness on $\\ker B$.\n\\end{remark}\n\n\\begin{Notation}{v0-kernel}\n  Since the kernels of the bilinear form $b(\\cdot,\\cdot)$ play an\n  important role, we abbreviate\n  \\begin{gather}\n    \\begin{split}\n      V^0 = \\ker B &= \\bigl\\{v\\in V \\;\\big|\\; b(v,q) = 0 \\quad\\forall q\\in Q\\bigr\\},\\\\\n      Q^0 = \\ker{B^\\transpose} &= \\bigl\\{q\\in Q \\;\\big|\\; b(v,q) = 0 \\quad\\forall v\\in V\\bigr\\}.\n    \\end{split}\n  \\end{gather}\n  We als define for $g\\in Q^*$ and for $f\\in V^*$ the affine spaces\n  \\begin{gather}\n    \\begin{split}\n      V^g &= \\bigl\\{v\\in V \\;\\big|\\; b(v,q) = g(q) \\quad\\forall q\\in Q\\bigr\\},\\\\\n      Q^f &= \\bigl\\{q\\in Q \\;\\big|\\; b(v,q) = f(v) \\quad\\forall v\\in V\\bigr\\}.\n    \\end{split}\n  \\end{gather}\n\\end{Notation}\n\n\\begin{intro}\n  We summarize the results of this section in a theorem for\n  well-posedness of the mixed formulation in\n  \\slideref{Definition}{mixed-weak} with simplified assumptions.  It\n  will be the basis for further results in this course. We know from\n  the discussion above that this assumption is only sufficient and\n  weaker conditions may be imposed on $a(.,.)$. But indeed, it helps\n  us through a lot of problems and is a good compromise between\n  generality and ease of use.\n\\end{intro}\n\n\\begin{Theorem}{mixed-elliptic}\n  Let the bilinear form $a(.,.)$ be positive semi-definite on $V$ and\n  elliptic on $V^0 = \\ker B$. Let the bilinear form $b(\\cdot,\\cdot)$\n  be inf-sup stable. Thus, there are constants $\\ellipa>0$ and\n  $\\infsupc>0$\n  \\begin{gather}\n    \\inf_{v\\in V^0} \\frac{a(v,v)}{\\norm{u}_V^2} = \\ellipa,  \\qquad\n    \\inf_{q\\in Q}\\sup_{v\\in V} \\frac{b(v,q)}{\\norm{v}_V\\norm{q}_Q} = \\infsupc.\n  \\end{gather}\n  Then, the abstract mixed problem in \\slideref{Definition}{mixed-weak}\n  has a unique solution.\n\\end{Theorem}\n\n\\begin{Problem}{mixed-elliptic}\n  Derive bounds for the solutions $u\\in V$ and $p\\in Q$ using the\n  assumptions of the previous theorem.\n\\end{Problem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Galerkin approximation of mixed problems}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\input{../mixed/galerkin}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "ce7a3e6f009700791128cbbe8e21ee447a8aeb0c", "size": 41486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mixed/infsup.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mixed/infsup.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "mixed/infsup.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 37.1738351254, "max_line_length": 135, "alphanum_fraction": 0.6392759003, "num_tokens": 14457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.6667430261026678}}
{"text": "\\section{Discriminant Analysis I}\n\n\\begin{frame}\n  \\frametitle{Discriminant Analysis}\n\n  \\structure{Discriminant analysis} methods are \\emph{discriminative modeling} methods that model the posterior through its factorization \n  \n  \\begin{displaymath}\n    p(y|\\vec x) = \\frac{p(y)\\cdot p(\\vec x|y)}{\\sum_y p(y)\\cdot p(\\vec x|y)}\n  \\end{displaymath}\n\\end{frame}\n\n\n\\subsection{Gaussian Classifier}\n\n\\begin{frame}\n  \\frametitle{Gaussian Classifier}\n\n  We call the Bayesian classifier \\structure{Gaussian}, if the class conditional density $p(\\vec x|y)$ is Gaussian, i.\\,e.\n\n  \\begin{eqnarray*}\n     p(\\vec x | y) &=& \\mathcal {N} (\\vec x ;\\vec {\\mu}_y, \\mat\\Sigma_y) \\\\\n                   &=& \\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%\n  where\n%\n  \\begin{center}\n    \\begin{minipage}{0.6\\textwidth}\n      \\begin{itemize}\n        \\item[$\\vec x \\in \\real^d$:] $d$-dimensional feature vector\\\\\n        \\item[$\\vec {\\mu}_y \\in \\real^d $:] mean vector of class y\\\\\n        \\item[$ \\mat\\Sigma_y \\in \\real^{d\\times d}$:] positive definite covariance matrix.\n      \\end{itemize}\n    \\end{minipage}\n  \\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Gaussian Classifier \\cont}\n\n  \\structure{Facts about Gaussian classifiers:}\n\n  \\begin{itemize}\n    \\item In general the decision boundary is \\structure{quadratic} in the components $x_i$ \\\\ \n      of the feature vector $\\vec x$. \\\\[.5cm]\n    \\item If all classes share the same covariance, the decision boundary is \\structure{linear} \\\\\n      in the components $x_i$ of the feature vector $\\vec x$. \\\\[.5cm]\n    \\item If all covariance matrices are diagonal matrices, \\\\\n      then we get a \\structure{Na{\\\"i}ve Bayes} classifier.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Gaussian Classifier \\cont}\n\n  \\structure{Facts about Gaussian classifiers (cont.):}\n  \n  \\begin{itemize}\n    \\item If the joint covariance matrix is $\\mat\\Sigma$ and priors are identical, \\\\\n      classification requires the minimization of the \\structure{Mahalanobis distance}\n      \\begin{eqnarray*}\n        y^* &=& \\argmin_{y} \\frac{1}{2} (\\vec x-\\vec\\mu_y)^T\\mat\\Sigma^{-1}(\\vec x-\\vec\\mu_y)\n      \\end{eqnarray*}\n      \\pause \n    \\item If all covariance matrices are the identity matrix, we get the \\\\\n      \\structure{Nearest Neighbor} classifier based on the $L_2$-norm:\n      \\begin{eqnarray*}\n        y^* &=& \\argmin_{y} \\frac{1}{2} (\\vec x-\\vec\\mu_y)^T(\\vec x-\\vec\\mu_y)\n      \\end{eqnarray*}\n      The prototype vectors are the mean vectors.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Gaussian Classifier \\cont}\n  \n  \\structure{From linear to quadratic decision boundaries:} \\\\[.5cm]\n  \n  A compromise between linear and quadratic decision boundaries \\\\\n  can be achieved by using \\structure{regularized covariance matrices}:\n%  \n  \\begin{eqnarray*}\n    \\mat\\Sigma_y (\\alpha)= \\alpha \\mat\\Sigma_y + (1-\\alpha)\\mat\\Sigma\n  \\end{eqnarray*}\n%  \n  where $\\alpha\\in [0,1]$ and $\\mat\\Sigma$ denotes the joint covariance.\n  \\spread\n  \n  Obviously we have the extremes:\n  \\begin{itemize}\n    \\item Linear decision boundary: $\\quad ~~\\alpha = 0$\n    \\item Quadratic decision boundary: $\\alpha =1$\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Feature Transform}\n\n\\begin{frame}\n  \\frametitle{Feature Transform}\n\n  Can we find a feature transform\n%  \n  \\begin{eqnarray*}\n    \\phi: \\real^d &\\rightarrow &\\real^d\n   \\end{eqnarray*}\n%\n  to generate features $\\phi(\\vec x)$ that share the same covariance matrix?\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transform \\cont}\n\n  The symmetric positive semidefinite covariance matrix $\\mat\\Sigma\\in \\real^{d\\times d}$ \\\\\n  can be decomposed using SVD:\n%  \n  \\begin{eqnarray*}\n    \\mat\\Sigma&=& \\pause \\mat{U}\\mat{D}\\mat{U}^T \\pause = (\\mat{U}\\mat{D}^{\\frac{1}{2}})(\\mat{U}\\mat{D}^{\\frac{1}{2}})^T \\pause =  \n    (\\mat{U}\\mat{D}^{\\frac{1}{2}})\\cdot \\mat{I} \\cdot(\\mat{U}\\mat{D}^{\\frac{1}{2}})^T\n  \\end{eqnarray*}\n%\n  where $\\mat{I}\\in \\real^{d\\times d}$ is the identity matrix.\n  \\pause\n   \n  \\begin{itemize}\n    \\item \\structure{Determinant:}  \n      \\begin{displaymath}\n        \\det \\mat\\Sigma = \\prod_{i=1}^d d_{i,i},\n      \\end{displaymath}\n      where $d_{i,i}$ are the diagonal elements of $\\mat D$, i.\\,e.\\ the \\structure{singular values}. \\pause\n    \\item \\structure{Inverse:}\n      \\begin{displaymath}\n        \\mat\\Sigma^{-1} = \\mat{U}\\mat{D}^{-1}\\mat{U}^T\n                          = (\\mat{U}\\mat{D}^{-\\frac{1}{2}})\\cdot \\mat{I} \\cdot(\\mat{U}\\mat{D}^{-\\frac{1}{2}})^T\n      \\end{displaymath}\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transform \\cont}\n \n   Now we incorporate this:\n   \n  \\begin{eqnarray*}\n    \\mathcal {N} (\\vec x ;\\vec {\\mu}, \\mat\\Sigma) \n      &=& \\frac{1}{\\sqrt{\\det 2\\pi  \\mat\\Sigma}} \n          e^{-\\frac{1}{2}(\\vec x -\\vec{\\mu})^T \\, \\mat\\Sigma^{-1} \\, (\\vec x - \\vec{\\mu})} \\\\[.3cm] \\pause\n      &=& \\frac{1}{\\sqrt{\\det 2\\pi  \\mat\\Sigma}} \n          e^{-\\frac{1}{2}(\\vec x -\\vec{\\mu})^T \\, (\\mat{U}\\mat{D}^{-\\frac{1}{2}})\\cdot \\mat{I} \\cdot(\\mat{U}\\mat{D}^{-\\frac{1}{2}})^T \\, (\\vec x - \\vec{\\mu})} \\\\[.3cm] \\pause\n      &=& \\frac{1}{\\sqrt{\\det 2\\pi  \\mat\\Sigma}} \n          e^{-\\frac{1}{2} \\big( (\\mat{D}^{-\\frac{1}{2}}\\mat{U}^T)\\vec x - (\\mat{D}^{-\\frac{1}{2}}\\mat{U}^T)\\vec\\mu \\big)^T \\,\\mat{I} ~\n          \\big( (\\mat{D}^{-\\frac{1}{2}}\\mat{U}^T)\\vec x- (\\mat{D}^{-\\frac{1}{2}}\\mat{U}^T)\\vec\\mu \\big) }\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transform \\cont}\n \n  The classwise transform $\\phi_y$ is even a linear function:\n%\n  \\begin{displaymath}\n    \\vec x' \\quad = \\quad \\phi_y(\\vec x) \\quad = \\quad \\mat{D}_y^{-\\frac{1}{2}}\\mat{U}^T_y\\vec x\n  \\end{displaymath}\n  \\pause \n\n  It is straight forward  to show that $\\vec x'$ is normally distributed\n  \\begin{displaymath}\n     p(\\vec x' | y) \\quad = \\quad \\mathcal {N} (\\vec x' ; \\vec {\\mu}'_y, \\mat\\Sigma'_y) \n                    \\quad = \\quad \\mathcal {N} (\\vec x' ; \\mat{D}_y^{-\\frac{1}{2}}\\mat{U}^T_y\\vec {\\mu}_y, \\mat{I}) \n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Feature Transform \\cont}\n\n  \\structure{Conclusions:}\n  \n  \\begin{itemize}\n    \\item All classes $y$ share the same covariance matrix that is the identity matrix. \\\\[.3cm]\n    \\item The decision boundary is linear. \\\\[.5cm] \\pause\n    \\item \\vorsicht \\structure{Huge disadvantage:} \\\\ \n      feature transform depends on class number $y$! \\\\[.3cm]\n    \\item If we have a classified training set, we can compute a transform \\\\\n      for each class such that all covariance matrices are the identity matrix. \\\\[.3cm]\n    \\item Classification requires the application of different transforms.\n  \\end{itemize}\n\\end{frame}\n\n\\input{nextTime.tex}\n\n\\subsection{Linear Discriminant Analysis}\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis}\n\n  \\begin{algorithmic}\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) \\}$\n      \\pause\n    \\STATE 1. ML estimation of the \\structure{joint covariance matrix}:\n      \\begin{displaymath}\n        \\widehat{\\mat\\Sigma}= \\frac{1}{m} \\sum_{i=1}^m (\\vec x_i - \\vec \\mu_{y_i})(\\vec x_i - \\vec \\mu_{y_i})^T\n      \\end{displaymath}\n      \\pause\n     \\STATE 2. Compute SVD of covariance matrix: $\\widehat{\\mat \\Sigma}= \\mat{U}\\mat{D}\\mat{U}^T$ \\pause \n     \\STATE 3. Assign transform: \n       \\begin{displaymath}\n         \\phi= \\mat D^{-\\frac{1}{2}} \\mat{U}^T\n       \\end{displaymath}\n       \\pause\n     \\STATE 4. Compute mean vectors for all $y$\n       \\begin{displaymath}\n          \\vec{\\mu}'_y = \\phi(\\vec\\mu_y)= \\mat{D}^{-\\frac{1}{2}} \\mat{U}^T \\vec{\\mu}_y\n       \\end{displaymath}\n       \\pause \\vspace{-.5cm}\n     \\STATE \\structure{Output:} feature transform $\\phi$, transformed mean vectors $\\vec{\\mu}'_y$\n  \\end{algorithmic}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis \\cont}\n\n  Decision rule using \\structure{sphered data $\\phi(\\vec x)$}:\n\n  \\begin{eqnarray*}\n    y^* &=& \\pause \\argmax_y p(y|\\vec \\phi(\\vec x))\\\\ \\pause\n        &=& \\argmax_y \n              \\left\\{ \n                \\log p(y) - \\frac{1}{2} \\big( \\phi(\\vec x) - \\phi(\\vec\\mu_y) \\big)^T \\big( \\phi(\\vec x)-\\phi(\\vec\\mu_y) \\big)\n              \\right\\} \\\\ \\pause\n        &=& \\argmin_y \\left\\{ \\frac{1}{2}\\left\\|\\phi(\\vec x)-\\phi(\\vec\\mu_y) \\right\\|_2^2 - \\log p(y) \\right\\}\n  \\end{eqnarray*}\n\n  where $\\|.\\|_2$ denotes the $L_2$ norm.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis \\cont}\n\n  \\structure{Conclusions:}\n  \n  \\begin{itemize}\n    \\item If all classes share the \\structure{same prior}, \\\\ the decision rule is the\n      \\structure{Nearest Neighbor} decision rule, \\\\ \n      where transformed mean vectors serve as prototypes. \\\\[.5cm]\n    \\item The feature transform $\\phi$ does not change the dimension of features.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis \\cont}\n\n  \\begin{figure}\n    \\resizebox{0.35\\linewidth}{!}{\n      \\input{\\texfigdir/lda_nearest_neighbor.pstex_t}\n    }\n    \\caption{Nearest Neighbor classification for two classes}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis \\cont}\n\n  \\structure{2 classes:} insights from geometrical analysis of sphered data \\\\[.3cm]\n\n  \\begin{itemize}\n    \\item Angle between $\\phi(\\vec x)$ and $(\\phi(\\vec \\mu_1)-\\phi(\\vec \\mu_0))$ can be used \\\\\n      for decision making.\\\\[.5cm]\n    \\item Decision rule:\n      {\\small\n      \\begin{displaymath}\n        y^* = \\left\\{\n                \\begin{array}{cl}\n                  0, & \\quad \\mbox{if} \\quad \n                       \\phi(\\vec x)^T \\big( \\phi(\\vec\\mu_1) - \\phi(\\vec\\mu_0) \\big) < \n                       \\frac{1}{2} \\big( \n                         \\phi(\\vec{\\mu}_1)^T \\phi(\\vec{\\mu}_1) - \n                         \\phi(\\vec{\\mu}_0)^T \\phi(\\vec{\\mu}_0) \n                        \\big) \\\\[.3cm]\n%                       \\big( \\phi(\\vec{\\mu}_1) + \\phi(\\vec{\\mu}_0) \\big)^T\n%                       \\big( \\phi(\\vec{\\mu}_1) - \\phi(\\vec{\\mu}_0) \\big) \\\\[.3cm]\n                  1, & \\quad \\mbox{otherwise}.\n                \\end{array}\n              \\right.\n      \\end{displaymath}\n      }\n    \\item Coordinate orthogonal to the 1-D subspace spanned by $(\\phi(\\vec \\mu_1)-\\phi(\\vec \\mu_0))$ does not affect relative distances.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis \\cont}\n\n  \\structure{$K$ classes:} insights from geometrical analysis of sphered data \\\\[.3cm]\n\n  \\begin{itemize}\n    \\item Class centroids span $(K-1)$-dimensional subspace. \\\\[.5cm]\n    \\item Relative differences are not affected by coordinates in the $(d-K+1)$-dimensional\n          subspace that is orthogonal to the  $(K-1)$-dimensional subspace spanned \n          by class centroids.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Linear Discriminant Analysis \\cont}\n\n  \\structure{Objective:} \\\\[.5cm]\n\n  Will we gain an advantage if we transform features by $$\\phi: \\real^d\\rightarrow \\real^k$$ in higher $(k>d)$ or lower dimensional $(k<d)$ spaces?\n\\end{frame}\n\n\n\\subsection{Lessons Learned}\n\n\\begin{frame}\n  \\frametitle{Lessons Learned}\n \n \\begin{itemize}\n    \\item Relationship between Bayesian classifier, Gaussian classifier, and \\\\\n      Nearest Neighbor classifier. \\\\[.5cm]\n    \\item Mahalanobis distance \\\\[.5cm]\n    \\item Linear Discriminant Analysis is a regularized Nearest Neighbor classifier \\\\[.5cm]\n    \\item Class centroids span $(K-1)$-dimensional subspace \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  You are required to be familiar with \\structure{linear algebra} and \\structure{matrix calculus}:\n\n  \\begin{itemize}\n    \\item SIAMS best selling book in the last decade:\\\\[.15cm]\n      Lloyd N. Trefethen, David Bau III: \\\\\n      \\structure{Numerical Linear Algebra}, \\\\\n      SIAM, Philadelphia, 1997. \\\\[0.15cm]\n    \\item All about matrix derivatives and related problems is described in the Matrix Cookbook:\n      \\structure{\\url{http://www.matrixcookbook.com}} \\\\[.3cm]\n  \\end{itemize}\n\n  Basics on \\structure{discriminant analysis} can be found in\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.\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 a Gaussian classifier? \\\\[1cm]\n    \\item What is the idea behind the feature transform for the LDA? \\\\[1cm]\n    \\item Formulate the LDA for normally distributed classes. \\\\[1cm]\n    \\item What is the dimensionality of the LDA subspace for $K$ classes?\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "150c3492c0c2ff25f2c595a93c33f9ab8da2173d", "size": 12935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "06_discriminant_analysis.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": "06_discriminant_analysis.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": "06_discriminant_analysis.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": 33.8612565445, "max_line_length": 174, "alphanum_fraction": 0.6198685736, "num_tokens": 4247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6667430160250716}}
{"text": "\\section{Math equations}\n\n\\subsection{Inline equations (in text)}\nHave you ever heard of Pythagorean theorem: \\(a^2 + b^2 = c^2\\) ? It's pretty neat.\n\n\\subsection{Display equations (n separate lines)}\nIn physics, the mass-energy equivalence is stated by the equation:\n\\begin{center}\n    $E=mc^2$\n\\end{center}\nAlbert Einstein discovered it in 1905!\n\n\\subsection{Fractions, summations, products, roots, powers}\n    \\textbf{Fractions}\\\\\n        This is 0.5 presented as a fraction: \\( \\frac{1}{2} \\). Neat right?\\\\\n        \\vspace{0.5cm}\n\n    \\textbf{Summation can be inserted as shown on Eqn. \\ref{eq:sum}}\\\\\n        \\begin{equation}\n            \\sum_{x=1}^{n}x^2=1\n            \\label{eq:sum}\n        \\end{equation}\n        \\vspace{0.5cm}\n    \n    \\textbf{Product sequence can be inserted as shown in Eqn. \\ref{eq:prod}}\\\\\n        \\begin{equation}\n            \\prod_{x=1}^{n}x^2\n            \\label{eq:prod}\n        \\end{equation}\n        \\vspace{0.5cm}\n\n    \\textbf{Square Root}\\\\\n        The square root of 100 is \\(\\sqrt{100}=10\\). \n        \\vspace{0.5cm}\n\n    \\textbf{Power}\\\\\n        Two to the power of five is \\(2^5 = 32 \\). \n        \\vspace{0.5cm}", "meta": {"hexsha": "a46cbab05eaed344a47609edf17b69767af998c4", "size": 1152, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/chapters/mathequations.tex", "max_stars_repo_name": "SOFT2021-UFO/Assignment-2-Professional-Typesetting-using-LaTeX", "max_stars_repo_head_hexsha": "27b667feebaf777b89f5e18cac7c15d683a68019", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/chapters/mathequations.tex", "max_issues_repo_name": "SOFT2021-UFO/Assignment-2-Professional-Typesetting-using-LaTeX", "max_issues_repo_head_hexsha": "27b667feebaf777b89f5e18cac7c15d683a68019", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pages/chapters/mathequations.tex", "max_forks_repo_name": "SOFT2021-UFO/Assignment-2-Professional-Typesetting-using-LaTeX", "max_forks_repo_head_hexsha": "27b667feebaf777b89f5e18cac7c15d683a68019", "max_forks_repo_licenses": ["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.3157894737, "max_line_length": 83, "alphanum_fraction": 0.5946180556, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.6665490599369431}}
{"text": "\\subsection{2016 Free-Response Answers}\r\n\r\n\\begin{enumerate}\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item We can approximate $R^\\prime(2)$ as the tangent slope between 1 and 3.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tR^\\prime(2) \\approx \\frac{R(3)-R(1)}{3-1} = \\frac{950-1190}{2} = -120.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, we estimate $R^\\prime(3)$ to be -120 liters/hour$^2$.\r\n\t\t\\item Using a left Riemann sum using the values in the table,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{0}^{8}{R(t)\\d{t}} \\approx (1-0)1340 + (3-1)1190 + (6-3)950 + (8-6)740 = 1340 + 2380 + 2850 + 1480 = 8050.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, the left Riemann sum approximates the total water removed to be 8050 liters.\r\n\t\t\\item Using our answer from part (b) and integrating, we can find the total amount of water added or removed.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\Delta \\text{Water} = -8050 + \\int_{0}{8}{2000e^{-t^2/20}\\d{t}} \\approx -214.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince we know there is 50000 liters of water at $t=0$, we can add the net change to find the amount of water at $t=8$.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\text{Water}_8 = \\text{Water}_0 + \\Delta \\text{Water} = 50000 - 214 = 49768.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, to the nearest liter, we approximate the amount of water in the tank at $t=8$ to be 49768 liters.\r\n\t\t\\item At $t=0$, $W(0) = 2000 > R(0) = 1340$, so $W(0)-R(0) > 0$.\r\n\t\t\tAt $t=8$, $W(8) = 81.52 < R(8) = 700$, so $W(8)-R(8) < 0$.\r\n\t\t\tSince both $W$ and $R$ are continuous, so is $W - R$.\r\n\t\t\tSo, by the Intermediate Value Theorem, there is some $0 < t < 8$ such that $W(t)-R(t)=0$, or $W(t)=R(t)$.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item We can apply the Fundamental Theorem of Calculus to find $x(3)$.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{0}^{3}{\\dd{x}{t}\\d{t}} = x(3) - x(0) = x(3) - 5 = 9.377 \\implies x(3) = 14.377.\r\n\t\t\t\\end{equation*}\r\n\t\t\tLooking at the graph, we see that $y(3)=-\\frac{1}{2}$.\r\n\t\t\tSo, at $t=3$, the particle's position is $\\left(14.377, -0.5\\right)$.\r\n\t\t\\item Looking at the graph, we see that $y^\\prime(3) = \\frac{1}{2}$.\r\n\t\t\tEvaluating $\\dd{x}{t}$ at $t=3$, we see that $x^\\prime(3) = 9+\\sin{27}$.\r\n\t\t\tSo,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{y}{x} = \\frac{\\dd{y}{t}}{\\dd{x}{t}} = \\frac{\\frac{1}{2}}{9+\\sin{27}} \\approx 0.0502.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Using our formula for parametric speed,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\ts = \\sqrt{(x^\\prime(t))^2 + (y^\\prime(t))^2} = \\sqrt{\\left(\\frac{1}{2}\\right)^2 + \\left(9+\\sin{27}\\right)^2} \\approx 9.969.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Starting with the formula for parametric arc length and splitting the integral into two peices,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\int_{0}^{2}{\\sqrt{\\left(y^\\prime(t)\\right)^2+\\left(x^\\prime(t)\\right)^2}\\d{t}} &= \\int_{0}^{1}{\\sqrt{(-2)^2+(t^2+\\sin{(3t^2)})^2}\\d{t}} + \\int_{1}^{2}{\\sqrt{(0)^2+(t^2+\\sin{(3t^2)})^2}\\d{t}} \\\\\r\n\t\t\t\t&\\approx 2.237 + 2.112 \\\\\r\n\t\t\t\t&= 4.439.\r\n\t\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Since we know by the Fundamental Theorem of Calculus that $f$ is the derivative of $g$, $g$ has critical points where $f$ is 0.\r\n\t\t\t$x=10$ is one such critical point.\r\n\t\t\tBoth to the left and right of $x=10$, $f$ is negative.\r\n\t\t\tSo, although $x=10$ is a critical point, it is neither a relative minimum or relative maximum of $g$ because $g$ is decreasing both left and right of $x=10$.\r\n\t\t\\item Inflection points occur when the second derivative changes sign.\r\n\t\t\tSince $f$ is the derivative of $g$, inflection points of $g$ occur when the derivative of $f$ changes sign.\r\n\t\t\tTo the left of $x=4$, the derivative of $f$ is positive.\r\n\t\t\tTo the right of $x=4$, the derivative of $f$ is negative.\r\n\t\t\tSo, $x=4$ is indeed an inflection point for $g$.\r\n\t\t\\item $g$ has critical points where $f$ is 0, which is at $x=-2$, $x=2$, $x=6$, and $x=10$.\r\n\t\t\tOf these, $x=2$ and $x=10$ do not change sign, so they cannot be absolute extrema.\r\n\t\t\tEvaluating the remaining critical points and the endpoints using the geometry of the graph of $f$,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tg(-4) &= -4 \\\\\r\n\t\t\t\tg(-2) &= -8 \\\\\r\n\t\t\t\tg(6) &= 8 \\\\\r\n\t\t\t\tg(12) &= -4.\r\n\t\t\t\\end{align*}\r\n\t\t\tSo, the absolute minimum of $g$ is at $x=-2$, and the absolute maximum of $g$ is at $x=6$.\r\n\t\t\\item To the left $x=2$, $g(x)$ is negative whenever there is more area between $f$ and the $x$-axis above the $x$-axis than below.\r\n\t\t\tSo, all points $[-4,2]$ have $g(x) \\leq 0$.\r\n\t\t\tTo the left of $x=2$, the opposite is true.\r\n\t\t\tSo, all points $[10,12]$ have $g(x) \\leq 0$.\r\n\t\t\tPutting these two results together, $g(x) \\leq 0$ on $[-4,2] \\cup [10,12]$. \r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Implicitly differentiating,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\d{^2y}{x^2} = 2x - \\frac{1}{2}\\dd{y}{x} = 2x - \\frac{1}{2}\\left(x^2 - \\frac{1}{2}y\\right).\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Since we have expression for the first and second derivatives, it makes the most sense to apply a second derivative test.\r\n\t\t\tFirst, checking that $(-2,8)$ is indeed a critical point,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{y}{x}_{(-2,8)} = (-2)^2 - \\frac{1}{2}(8) = 0.\r\n\t\t\t\\end{equation*}\r\n\t\t\tNext, evaluating the second derivative,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{^2y}{x^2}_{(-2,8)} = 2(-2) - \\frac{1}{2}\\left((-2)^2 - \\frac{1}{2}(8)\\right) = -4 - 0 = -4.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince the second derivative is negative at this critical point, the second derivative test tells us that this is a relative maximum.\r\n\t\t\\item Since we know that $g(-1)=2$, both the numerator and denominator of the limit are in an indeterminate form of 0/0.\r\n\t\t\tSo, we can apply L'H\\^{o}pital's Rule.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\lim_{x\\to -1}{\\left(\\frac{g(x)-2}{3(x+1)^2}\\right)} = \\lim_{x\\to-1}\\left(\\frac{g^\\prime(x)}{6(x+1)}\\right).\r\n\t\t\t\\end{equation*}\r\n\t\t\tUsing the given differential equation, we can see that at $(-1,2)$, $g^\\prime(-1)=0$.\r\n\t\t\tSo again we have an indeterminate form of 0/0 and can apply L'H\\^{o}pital's Rule.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\lim_{x\\to-1}\\left(\\frac{g^\\prime(x)}{6(x+1)}\\right) = \\lim_{x\\to -1}{\\frac{g^{\\prime\\prime}(x)}{6}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tUsing our answer from part (b), we know that at $(-1,2)$, $g^{\\prime\\prime}(-1) = -2$.\r\n\t\t\tSo,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\lim_{x\\to -1}{\\frac{g^{\\prime\\prime}(x)}{6}} = \\frac{-2}{6} = -\\frac{1}{3}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Applying two iterations of Euler's method starting at $(0,2)$ with $\\Delta x = \\frac{1}{2}$,\r\n\t\t\t\\begin{table}[H]\r\n\t\t\t\t\\begin{center}\r\n\t\t\t\t\t\\begin{tabular}{|c|c|c|c|c|}\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t$(x,y)$ & $\\dd{y}{x}$ & $\\Delta x$ & $\\Delta y = \\Delta x\\dd{y}{x}$ & $(x+\\Delta x, y+\\Delta y)$ \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t$(0,2)$ & $-1$ & $\\frac{1}{2}$ & $-\\frac{1}{2}$ & $(\\frac{1}{2},\\frac{3}{2})$ \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t$(\\frac{1}{2},\\frac{3}{2})$ & $-\\frac{1}{2}$ & $\\frac{1}{2}$ & $-\\frac{1}{4}$ & $(1,\\frac{5}{4})$ \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t\\end{center}\r\n\t\t\t\\end{table}\r\n\t\t\tSo, our application of Euler's method approximates $h(1)$ to be 5/4.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Applying the formula for average value,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\frac{1}{10-0}\\int_{0}^{10}{\\frac{1}{20}\\left(3+h^2\\right)\\d{h}} = \\frac{1}{200}\\left(3h+\\frac{h^3}{3}\\right) = \\frac{109}{60}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, the average radius of the funnel is $\\frac{109}{60}$ inches.\r\n\t\t\\item Applying the volume formula for a solid of revolution,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tV &= \\pi\\int_{0}^{10}{\\left(\\frac{1}{20}\\left(3+h^2\\right)\\right)\\d{h}} \\\\\r\n\t\t\t\t&= \\frac{\\pi}{400}\\left(\\frac{h^5}{5}+2h^3+9h\\right)\\biggr\\rvert_0^{10} \\\\\r\n\t\t\t\t&= \\frac{\\pi}{400}\\left(20000+2000+90\\right) \\\\\r\n\t\t\t\t&= \\frac{2209\\pi}{40}.\r\n\t\t\t\\end{align*}\r\n\t\t\\item Applying the chain rule,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\dd{r}{t} &= \\dd{r}{h}\\dd{h}{t} \\\\\r\n\t\t\t\t&= \\frac{1}{10}h\\dd{h}{t}.\r\n\t\t\t\\end{align*}\r\n\t\t\tSolving with the information given,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t-\\frac{1}{5} = \\frac{1}{10}(3)\\dd{h}{t} \\implies \\dd{h}{t} = -\\frac{2}{3}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, at this instant, the height of the liquid is decreasing at 2/3 inches per second.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Finding several derivatives at $x=1$,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tf(1) &= 1 \\\\\r\n\t\t\t\tf^\\prime(1) &= -\\frac{1}{2} \\\\\r\n\t\t\t\tf^{\\prime\\prime}(1) &= \\frac{1}{4} \\\\\r\n\t\t\t\tf^{(3)}(1) &= -\\frac{1}{4}.\r\n\t\t\t\\end{align*}\r\n\t\t\tApplying the Taylor Series formula centered at $x=1$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tf(x) = 1 - \\frac{1}{2}(x-1) + \\frac{1}{8}(x-1)^2 - \\frac{1}{24}(x-1)^3 + \\ldots + (-1)^n\\frac{1}{n2^n}(x-1)^n.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Since we know that the series is centered at $x=1$ and the radius of convergence is 2, we know the series converges on $(-1,3)$ and need to check the endpoints.\r\n\t\t\tWhen $x=-1$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\sum_{n=1}^{\\infty}{(-1)^n\\frac{1}{n2^n}(-1-1)^n} = \\sum_{n=1}^{\\infty}{\\frac{1}{n}}\r\n\t\t\t\\end{equation*}\r\n\t\t\tdiverges by the P-Test.\r\n\t\t\tWhen $x=3$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\sum_{n=1}^{\\infty}{(-1)^n\\frac{1}{n2^n}(3-1)^n} = \\sum_{n=1}^{\\infty}{(-1)^n\\frac{1}{n}}\r\n\t\t\t\\end{equation*}\r\n\t\t\tconverges by the Alternating Series Test.\r\n\t\t\tSo, the invterval of convergence is $(-1,3]$.\r\n\t\t\\item Using the first three terms of our series from part (a) with $x=1.2$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tf(1.2) \\approx 1 - \\frac{1}{2}(1.2-1) + \\frac{1}{8}(1.2-1)^2 = 1 - \\frac{1}{10} + \\frac{1}{200} = 0.905.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Since this series is alternating, we can apply the Alternating Series Estimation Theorem.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\abs{f(1.2)-P_2(1.2)} \\leq \\abs{\\frac{-1}{2^3\\cdot 3} (.2)^3 } = \\frac{1}{3000} \\leq 0.001.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, by the Alternating Series Estimation Theorem, the error is certainly at most 0.001.\r\n\t\\end{enumerate}\r\n\\end{enumerate}", "meta": {"hexsha": "06f83b5f09a64639b0cd9617e99efbf9813b2aa8", "size": 9601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/additional_materials/2016_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/2016_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/2016_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": 51.0691489362, "max_line_length": 199, "alphanum_fraction": 0.5865014061, "num_tokens": 3837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.6665444391338499}}
{"text": "\n\nGreen's functions are a cornerstone of scalar and vector scattering analysis. Fundamentally, a Green's function is the impulse response of a partial differential equation, in this case, a wave equation with associated boundary conditions. The classic text on dyadic Green's functions for vector electromagnetic waves is \\cite{tai1994dyadic}, along with \\cite{chew1995waves,tsang1985theory}.  \n\nScalar and dyadic Green's functions allow us to cast scattering problems as surface or volume integral equations. These enable solutions of the scattered fields through the use of powerful numerical methods like the Method of Moments and the Conjugate Gradient FFT. In addition, Green's functions help reveal the nature of wave propagation: for example, in 3D free-space, the Green's function shows that the amplitude of waves radiated from a point source decay geometrically with distance and that information is carried undiminished in the phase of the wave.\n\nIn this chapter, we list for reference the scalar Green's function in 1D, 2D, and 3D, with far-field expressions for 2D and 3D. We provide routines for the dyadic Green's function for vector electromagnetic waves. We give the volume integral equations (VIE) for scalar and vector waves as well as the expression for the VIE under the far-field Born approximation. The Green's function is singular when evaluated at the origin, however this singularity is integrable. We give the results for the volume-integrated Green's function at singular and non-singular points which are needed when discretizing the VIE. Last, we setup the Method of Moments solution of the VIEs for both scalar and vector cases.\n\n\n\\section{Scalar Green's Function}\n\nThe scalar Green's function is the solution to the Helmholtz wave equation for a point source in a homogeneous medium\n\\eq{\\nabla^2 g(\\bb{r},\\bb{r}') + k^2 g(\\bb{r},\\bb{r}') = -\\delta(\\bb{r}-\\bb{r}')}\n\n\\noindent where $k$ is the background wavenumber, $\\bb{r}$ is the observation point, and  $\\bb{r}'$ is the source point. This wave equation is linear, therefore a scalar field, $\\phi(\\br)$, due to a distributed source, $s(\\br)$, is given by the volume integral over the Green's function as, \\cite{chew1995waves}\n\\eq{\\phi(\\br) = -\\int g(\\br,\\br') s(\\br') dV' \\label{sourceintscalar}}\n\nIn short, the Green's function is the impulse response of the linear system that is the wave equation for homogeneous media. \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{1D Scalar Green's Function}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe 1D free-space scalar Green's function is \n\\eq{g(x,x')  = \\dfrac{i}{2k} e^{ik\\vert x-x' \\vert}}\n\n\\noindent where $x$ is the observation point, $x'$ is the source point, and $k$ is background wavenumber. This has no far-field approximation because there is no wave spreading in 1D.   \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{2D Scalar Green's Function}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe 2D free-space scalar Green's function is \n\\eq{g(\\boldsymbol{\\rho},\\boldsymbol{\\rho}') = \\dfrac{i}{4} H_0^{(1)}\\left(k \\vert \\boldsymbol{\\rho} - \\boldsymbol{\\rho}'\\vert\\right) }\n\n\\noindent where $\\boldsymbol{\\rho}$ is the observation point, $\\boldsymbol{\\rho}'$ is the source point, $k$ is the background wavenumber and $H_0^{(1)}$ is the Hankel function, \\cite{chew1995waves}. This is the solution to the Helmholtz wave equation in a homogenous medium due to 2D line source. This has far-field approximation \n%\\eq{g(\\boldsymbol{\\rho},\\boldsymbol{\\rho}') \\approx \\dfrac{i}{4} \\sqrt{\\dfrac{2}{\\pi k \\rho }} e^{k\\rho - \\frac{n\\pi}{2} - \\frac{\\pi}{4} }}\n\\eq{g(\\boldsymbol{\\rho},\\boldsymbol{\\rho}') \\approx  \\sqrt{\\dfrac{1}{8 \\pi k \\rho }} e^{i\\pi/4 } e^{i k\\rho } e^{-ik \\hat{\\boldsymbol{\\rho}}\\cdot\\boldsymbol{\\rho}' }}\n\nThis shows that fields decay like $1/\\sqrt{\\rho}$ in 2D. \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{3D Scalar Green's Function}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe 3D free-space scalar Green's function is \n\\eq{g(\\br,\\br') = \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi \\vert \\br - \\br' \\vert}}\n\\noindent where $k$ is the background wavenumber, $\\br'$ is the source point, $\\br$ is the observation point.  This is the solution to the Helmholtz wave equation due to a point source in three dimensions.  The far-field approximation is \n\\eq{g(\\br,\\br') \\approx \\dfrac{e^{ikr}}{4\\pi r} e^{-ik \\hat{\\br}\\cdot\\br' } }\n\nThis shows the classic result that fields decay like $1/r$ in 3D. \n\n\\section{Dyadic Green's Function}\n\nThe free-space electric field dyadic Green's function satisfies the vector wave equation \\cite{chew1995waves,tai1994dyadic}\n\\eq{\\nabla \\times \\nabla \\times  \\overline{\\bb{G}}(\\br,\\br') - k^2 \\overline{\\bb{G}}(\\br,\\br') = \\overline{\\bb{I}} \\delta(\\br - \\br')}\n\n\\noindent where $\\overline{\\bb{I}}$ is the identity dyad. This is often notated $\\overline{\\bb{G}}_e(\\br,\\br')$ to distinguish it from the magnetic field dyadic Green's function.  The electric field due to a distributed current density $\\bb{J}(\\br)$ is given by \n\n\\eq{\\bb{E}(\\br) = i\\omega\\mu\\int \\G{} \\cdot \\bb{J}(\\br') dV'  \\label{evolintj}}\n\nThe dyadic Green's function is given by \n\\begin{equation}\n \\overline{\\bb{G}}(\\br,\\br') = \\left[\\overline{\\bb{I}} + \\dfrac{1}{k^2} \\nabla\\nabla \\right] \\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi \\vert \\br - \\br' \\vert} \\label{dgreens}\n \\end{equation}\n\n\\noindent where $k$ is the background wavenumber, $\\br'$ is the source point, $\\br$ is the observation point, and \n\n\\begin{equation}\n\\nabla = \\dfrac{d}{dx} \\hat{x} + \\dfrac{d}{dy} \\hat{y}  + \\dfrac{d}{dz} \\hat{z} \n\\end{equation}\n\n\nWriting out \\eqref{dgreens},\n\\begin{equation}\n\\overline{\\bb{G}}(\\br,\\br')  = \\thbth\n{k^2 + \\dfrac{\\partial^2}{\\partial x^2}}{\\dfrac{\\partial^2}{\\partial x\\partial y}} {\\dfrac{\\partial^2}{\\partial x\\partial z}} \n{\\dfrac{\\partial^2}{\\partial y\\partial x}} {k^2 + \\dfrac{\\partial^2}{\\partial y^2}} {\\dfrac{\\partial^2}{\\partial y\\partial z}} \n{\\dfrac{\\partial^2}{\\partial z\\partial x}} {\\dfrac{\\partial^2}{\\partial z\\partial y}} {k^2 + \\dfrac{\\partial^2}{\\partial z^2}}\n\\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi k^2 \\vert \\br - \\br' \\vert}\n\\end{equation}\n\nThe dyadic Green's function is symmetric with six unique dyadic components. In Cartesian coordinates the components are \n\\begin{eqnarray}\nG_{xx} &=& (1+c_1(x-x')^2+c_2)c_3 \\\\\nG_{yy} &=& (1+c_1(y-y')^2+c_2)c_3 \\\\ \nG_{zz} &=& (1+c_1(z-z')^2+c_2)c_3 \\\\\nG_{xy} &=& c_1(x-x')(y-y')c_3 \\\\\nG_{xz} &=& c_1(x-x')(z-z')c_3 \\\\ \nG_{yz} &=& c_1(y-y')(z-z')c_3 \n\\end{eqnarray}\n\n\\noindent where\n\\begin{eqnarray}\nr &=& \\vert \\br - \\br' \\vert \\\\\nc_1 &=& -\\dfrac{1}{r^2} - \\dfrac{3i}{k r^3} + \\dfrac{3}{k^2 r^4} \\\\\nc_2 &=& \\dfrac{i}{kr} - \\dfrac{1}{k^2r^2} \\\\\nc_3 &=& \\dfrac{e^{ikr}}{4\\pi r}\n\\end{eqnarray}\n\nThe far field approximation of the dyadic Green's function is \n\\begin{equation} \\overline{\\bb{G}}(\\br,\\br') \\approx \\left[\\overline{\\bb{I}} - \\hat{r}\\hat{r}\\right] \\dfrac{e^{ikr}}{4\\pi r} e^{-ik \\hat{\\br}\\cdot\\br' \\label{dyadicGff}} \n \\end{equation}\n \n\\noindent where $\\overline{\\bb{I}} - \\hat{r}\\hat{r} = \\hat{\\theta}\\hat{\\theta} + \\hat{\\phi}\\hat{\\phi}$ in spherical coordinates.  The curl of the dyadic Green's function is used in surface integral equations and is given by \n\\eq{\\curl \\G{} = \\nabla g(\\br,\\br') \\times \\overline{\\bb{I}}}\n\nWritten out it is \n\\begin{equation}\n\\curl \\G{} = \\thbth\n{0}{-\\dd{}{z} } {\\dd{}{y} } \n{\\dd{}{z} } {0} {-\\dd{}{x}}\n{-\\dd{}{y} } {\\dd{}{x}} {0}\n\\dfrac{e^{ik\\vert \\br - \\br' \\vert}}{4\\pi   \\vert \\br - \\br' \\vert}\n\\end{equation}\n\n\n\nThe unique components, to within a sign, are \n\\begin{eqnarray}\n\\left[\\curl \\G{}\\right]_{xy}  &=& -(z-z') f(r) \\\\\n\\left[\\curl \\G{}\\right]_{xz}&=& (y-y') f(r) \\\\ \n\\left[\\curl \\G{}\\right]_{yz}&=& - (x-x') f(r) \\\\\nf(r) &=& (i k r-1) \\dfrac{e^{i k r}}{4 \\pi r^3} \n\\end{eqnarray}\n\nA useful property is\n\\eq{\\curl \\G{}= -\\nabla'\\times \\G{} \\label{dyadicGreenscurlprime}}\n\n\\clearpage\n\\newpage\nThe routine \\texttt{dyadicGreens} takes as input the wavenumber $k$, and components of the difference vector $\\br - \\br'$ in Cartesian coordinates and returns the six unique matrix entries of the dyadic Green's function.  The routine \\texttt{curlDyadicGreens} takes the same inputs and returns the six matrix entries of the curl of the dyadic Green's function. These are straight computations. No provisions are made for the singularity.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/GreensFunctions/dyadicGreens.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/GreensFunctions/curlDyadicGreens.m}\n}\n\n\\clearpage\n\\newpage\n\\section{Volume Integral Equation}\n\nThe volume integral equation (VIE) formulates the scattering solution of a heterogeneous distribution of material in terms of the Green's function for homogenous media, \\cite{chew1995waves}. The VIE applies to both scalar and vector problems and is the basis of many numerical solvers, such as the Method of Moments. It serves as the basis for many inverse scattering algorithms. \n\n\\subsection{Scalar VIE}\nStart with the Helmholtz wave equation where the wavenumber of the medium is a function of position\n\\eq{\\nabla^2 \\phi(\\br) + k^2(\\br) \\phi(\\br) = s(\\br)}\n\nThis equation is classified as an inhomogeneous, linear, second-order partial differential equation with non-constant coefficients. Assuming that the material object is bounded and sits in a background medium with wavenumber $k_b$, the next step is to add and subtract $k_b^2$ from the object as\n\\eq{\\nabla^2 \\phi(\\br) + (k^2(\\br) + k_b^2 - k_b^2)\\phi(\\br) = s(\\br)}\n\nKeeping the factor of $+k_b^2$ on the LHS and moving everything else to the RHS \n\\eq{\\nabla^2 \\phi(\\br) +  k_b^2\\phi(\\br) = s(\\br) -  (k^2(\\br) - k_b^2)\\phi(\\br) }\n\nThe LHS is the wave equation for the homogenous background which is sourced by everything on the RHS. The field solution is given by integrating the RHS with the free-space Green's function per \\eqref{sourceintscalar} \n\\eq{\\phi(\\br) = -\\int g(\\br,\\br') s(\\br') dV' +  \\int g(\\br,\\br') (k^2(\\br') - k_b^2)\\phi(\\br') dV'}\n\nThe first term on the RHS is the field due to the source in the absence of the object. This is the incident field, $\\phi_{inc}(\\br)$. The scalar VIE is then written\n\\eq{\\phi(\\br) = \\phi_{inc}(\\br) +  \\int g(\\br,\\br') O(\\br') \\phi(\\br') dV' \\label{scalarVIE}}\n\n\\noindent where the object function, $O(\\br) = k^2(\\br) - k_b^2 $, is the contrast of the object relative to the background.  This is a Fredholm integral equation of the second kind because the total field, $\\phi(\\br)$, appears inside and outside the integral. The integral term is defined as the scattered field. The scattered field modifies the incident field to give the total field. The scattered field exists inside and outside the object, even though the scattered field depends on the total field in the object. We can express this idea simply as\n\\eq{\\phi(\\br) = \\phi_{inc}(\\br) +  \\phi_{sca}(\\br) }\n\nIn experiment, only the incident and total fields can be measured directly using sources and receivers placed away from the object. The incident field is measured in the absence of the object and the total field measured in the presence of the object. The scattered field is obtained by subtracting the measured incident and total fields. For situations in which the object cannot be removed, the incident field has to be predicted using a model of the source and receiver. %In order to make the measurements and computations of the VIE consistent, the total field solution should be obtained using an incident field from the same source model.\n\n\\subsection{Vector VIE}\n\nThe vector VIE is derived from the vector wave equation in the same way as the scalar VIE is derived from the Helmholtz wave equation. The vector wave equation for the total electric field in an isotropic inhomogeneous non-magnetic dielectric medium is \\cite{chew1995waves}\n\\eq{\\nabla \\times \\nabla \\times  \\bb{E}(\\br) - k^2(\\br) \\bb{E}(\\br) = i\\omega\\mu_o \\bb{J}(\\br)}\n\nAdding and subtracting the background wavenumber, $k_b^2$, to $k^2(\\br)$, rearranging, and integrating the source terms with the free-space dyadic Green's function, the vector VIE is \n\\eq{\\bb{E}(\\br) = \\bb{E}_{inc}(\\br) + \\int \\G{} \\cdot O(\\br') \\bb{E}(\\br') dV' \\label{vectorVIE} }\n\n$\\bb{E}_{inc}(\\br)$ is the incident field in the absence of the object and can be computed with \\eqref{evolintj} given a the source distribution $\\bb{J}(\\br)$. The object function is \n\\ea{O(\\br) &=& k^2(\\br) - k_b^2 \\\\\n\\ &=& k_o^2 \\left(  \\delta\\epsilon_r(\\br) + i\\dfrac{\\delta \\sigma(\\br)}{\\epsilon_o \\omega}\\right) \\label{objectfunction} \\\\\n\\delta\\epsilon_r(\\br) &=& \\epsilon_r(\\br) - \\epsilon_{rb} \\\\\n\\delta \\sigma(\\br) &=& \\sigma(\\br) - \\sigma_b}\n\n\\noindent where $k_b = \\omega\\sqrt{\\mu_o\\epsilon_b}$ is the background wavenumber, $\\epsilon_b$ is the background permittivity, and $k_o^2 = \\omega^2\\mu_o\\epsilon_o$ is the lossless free-space background wavenumber. The complex permittivity is, generally, $\\epsilon = \\epsilon_o(\\epsilon_r + i\\sigma/(\\omega\\epsilon_o))$, where $\\epsilon_r$ is the real part, $\\sigma$ is the conductivity, and $\\omega$ the natural frequency, \\cite{chew1995waves}. Using this, one can derive the functions $\\delta\\epsilon(\\br)$ and $\\delta \\sigma(\\br)$ which are the permittivity and conductivity contrasts relative to the background. Note, the dyadic Green's function is evaluated with the background wavenumber $k_b$. \n\nUsing \n\\eq{\\bb{E}(\\br) = \\bb{E}_{inc}(\\br) + \\bb{E}_{sca}(\\br)}\n\nthe scattered field is given by the integral term\n\\eq{\\bb{E}_{sca}(\\br)=  \\int \\G{} \\cdot O(\\br') \\bb{E}(\\br') dV' \\label{vie}}\n\n%\\noindent where the object function is\n%\\ea{O(\\br) &=& k^2(\\br) - k_b^2 \\\\\n%\\ &=& k_o^2 \\left(  \\delta\\epsilon(\\br) + i\\dfrac{\\delta \\sigma(\\br)}{\\epsilon_b \\omega}\\right) \\label{objectfunction} \\\\\n%\\epsilon_b \\delta\\epsilon(\\br) &=& \\epsilon(\\br) - \\epsilon_b \\\\\n%\\delta \\sigma(\\br) &=& \\sigma(\\br) - \\sigma_b}\n%\n%\\noindent where $k_b = \\omega\\sqrt{\\mu_b\\epsilon_b}$ is the background wavenumber, $k_o^2 = \\omega^2\\mu_o\\epsilon_b$ is the lossless background wavenumber, $\\epsilon_b = \\epsilon_o \\epsilon_{rb}$ is the real part background permittivity. The functions $\\delta\\epsilon(\\br)$ and $\\delta \\sigma(\\br)$ are the permittivity and conductivity contrast relative to the background. In general, the complex permittivity is given by $\\epsilon = \\epsilon_o(\\epsilon_r + i\\sigma/(\\omega\\epsilon_o))$, where $\\epsilon_r$ is the real part, $\\sigma$ is the conductivity, and $\\omega$ the natural frequency, \\cite{chew1995waves}.\n\n\n%  The background dyadic Green's function is\n\n%\\eq{\\G{} = \\left[ \\overline{\\bb{I}} + \\dfrac{\\nabla'\\nabla'}{k^2} \\right] \\dfrac{e^{ik \\vert \\br - \\br'\\vert}}{4\\pi  \\vert \\br - \\br'\\vert}  }\n\n%and \n%\\eq{k^2 = k_o^2\\left(1 + i \\dfrac{\\sigma_b}{\\epsilon_b \\omega} \\right)}\n\n%Using \\eqref{dyadicGff}, the far-field approximation of the Green's function in the scattered field direction is \n%\\eq{\\G{} \\approx \\left[ \\overline{\\bb{I}}  - \\hat{r}\\hat{r} \\right] \\dfrac{e^{ikr}}{4\\pi r} \\exp(-i \\bb{k}_s\\cdot\\br' ) \\label{dgff} } \n\n%\\noindent where $\\bb{k}_s$ is the wave vector in the scattered or radial direction. % In spherical coordinates $\\overline{\\bb{I}}  - \\hat{r}\\hat{r} = \\hat{\\theta}\\hat{\\theta} + \\hat{\\phi}\\hat{\\phi}$.\n\n\n\\section{Far-field Born Approximation}\n\\label{bornapprox}\n\nWe give the classic expression for the vector field volume integral equation under the far-field Born approximation. The Born approximation refers to any instance in which the total field in an object is approximated by the incident field. In the far-field Born approximation, the VIE is simplified with three assumptions:\n\\begin{enumerate}\n\\item The Born approximation is made for the total field in the object: $\\bb{E}(\\br) = \\bb{E}_{inc}(\\br)$,\n\\item The incident field is a plane wave, $\\bb{E}_{inc}(\\br) = \\bb{E}_i\\exp(i \\bb{k}_i \\cdot \\br)$,\n\\item The far-field dyadic Green's function, \\eqref{dyadicGff}, is used in the scattered field direction, $\\bb{k}_s$:\n\\eq{\\G{} \\approx \\left[ \\overline{\\bb{I}}  - \\hat{r}\\hat{r} \\right] \\dfrac{e^{ikr}}{4\\pi r} e^{-i \\bb{k}_s\\cdot\\br'} \\nonumber } \n\\end{enumerate}\n\nSubstituting these into \\eqref{vie}, the far-field Born approximation for the VIE is \n%\\eq{\\bb{E}_{sca}(\\br)=  \\int \\left[ \\overline{\\bb{I}}  - \\hat{r}\\hat{r} \\right] \\dfrac{e^{ikr}}{4\\pi r} \\exp(-i \\bb{k}_s\\cdot\\br' ) \\cdot O(\\br') \\bb{E}_i \\exp(i \\bb{k}_i \\cdot \\br')  dV' }\n\\eq{\\bb{E}_{sca}(\\br)\\approx  \\dfrac{e^{ikr}}{4\\pi r} \\left[ \\overline{\\bb{I}}  - \\hat{r}\\hat{r} \\right] \\cdot  \\bb{E}_i  \\int O(\\br') e^{i (\\bb{k}_i-\\bb{k}_s) \\cdot \\br'}  dV'  \\label{baesca} }\n\nThe integral is the 3D Fourier transform of the object function, $O(\\br)$, \\eqref{objectfunction}, in the wave vector difference domain. There is no multiple scattering or depolarization due to scattering: the incident polarization is simply projected onto the scattered field polarizations based on the geometry of the source and observer. The Born approximation is a weak assumption because it assumes that the total field solution is unaffected by the object. It is only valid when the objects are very small compared to the wavelength or have very low contrast. This expression is the foundation of the $k$-space mapping between source/receiver direction pairs and the Fourier spectral components of the object, and is the basis of diffraction tomography imaging algorithms, \\cite{devaney1984geophysical,chew1995waves}. \n\n\n\n\\section{Volume-Integrated Free-space Green's Functions}\n\\label{volintfsgf}\nThe VIEs need to be discretized for numerical computation, for example, in the Method of Moments or Conjugate Gradient FFT. The discretization can be done with cubic voxels that are small enough so that the total field and object are considered constant in the voxel after which only the Green's function has to be integrated over the voxel. The Green's function, and therefore the integrand, will be singular whenever $\\br = \\br'$. However, the singularity is integrable in both the scalar and vector cases. When $\\br \\ne \\br'$, the volume-integrated Green's function takes a different but constant value. The solutions to integrating the singularity are analytical if the voxel is spherical, therefore, cubic voxels are replaced with volume-equivalent spheres. The derivations are  involved (e.g., principal values, exclusion volumes), but the result is a straightforward replacement of the continuous VIE with a sum over discrete cells and appropriate scale factors.\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\paragraph{3D Voxel Integration}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nFrom \\cite{chew1995waves,gao2005analytical}, the volume-integrated 3D scalar and dyadic Green's functions at the singular points are \n\\eq{g(\\br = \\br') \\rightarrow \\dfrac{1}{k_b^2} \\left(-1 + (1-ik_b a) e^{ik_b a}\\right) \\label{singint}}\nand\n\\eq{\\bb{G}(\\br=\\br') \\rightarrow \\dfrac{1}{k_b^2} \\left( -1 + \\dfrac{2}{3} (1 - i k_b a) e^{i k_b a}\\right) \\overline{\\bb{I}} \\label{singintvec}} \n\\noindent where $a$ is the radius of the volume-equivalent sphere of the cubic voxels and $k_b$ is the background wavenumber. These values replace the voxel-integrated Green's function at the singularity and no factor of differential volume is needed. The source, object, or total field is assumed constant at the singular point and sampled directly. When substituted into the VIE, the factor of $1/k_b^2$ will cancel the dimensions of the object function, $O(\\br)$, which has dimensions of $k_b^2$, leaving only the dimensions of the total field. \n\nFor non-singular points, assuming that the observation point is outside of the sphere surrounding the singular point, the Green's function, source, object or total field is sampled directly, but the differential volume is replaced with, \\cite{gao2005analytical},  \n\\eq{\\Delta V = \\dfrac{4\\pi a}{k_b^2} \\left( \\dfrac{\\sin(k_b a)}{k_b a} - \\cos(k_b a)\\right) \\label{voxelint}}\n\nThis applies to both scalar and dyadic cases. Note, $\\Delta V$ has dimensions of length cubed. To gain more physical insight, we can rewrite this as\n\\eq{\\Delta V = \\dfrac{4}{3}{\\pi a^3} \\left( 3 \\dfrac{\\sin(k_b a) - k_b a \\cos(k_b a)}{(k_b a)^3}\\right)}\n\nThe oscillating term in parentheses accounts for the coherence/decoherence of summing the phase term of the Green's function over the sphere. It has a maximum value of 1 when $k_b a \\rightarrow 0$. This means that as the voxel size decreases, the integration of the Green's function becomes less important, and the volume element can be approximated just as well with the cubic volume. This expression is nearly identical to that derived in Section \\ref{sec:volumephaseint} for the volume phase integral over a sphere.\n\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\paragraph{2D Voxel Integration}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\nWhen the volume integrals are 2D, and discretized with squares, the singular point of the 2D scalar Green's function integrates to, \\cite{gao2005analytical},\n\\eq{g(\\boldsymbol{\\rho} = \\boldsymbol{\\rho}') \\rightarrow -\\dfrac{1}{k_b^2} + \\dfrac{i\\pi a}{2k_b} H_1^{(1)}(k_ba) }\n\nThis has dimensions of the length squared, which cancels the dimensions of the object function in the VIE. The differential surface element is replaced with\n\\eq{\\Delta S = \\dfrac{2\\pi a}{k_b} J_1(k_ba) \\label{voxelsurfint}}\n\n\\noindent where $a$ is the radius of the area-equivalent disk, $k_b$ is the background wavenumber and $\\Delta S$ has dimensions of length squared. Similar to \\eqref{voxelint}, \\eqref{voxelsurfint} is equal to the area of the voxel when $k_b a \\rightarrow 0$.\n\nThe routine \\texttt{volintGreens} returns the volume-integrated Green's function and discrete volume element for the cases above. It takes as input the radius of the circular or spherical voxel, $a$, the background wavenumber, $k_b$, and a string switch with three options: \\texttt{'2D'} for scalar 2D, \\texttt{'3D'} for scalar 3D, or \\texttt{'dyadic'} for the 3D dyadic version. Often $a$ and $k_b$ are constant in a given VIE discretization, but the routine is vectorized to take arrays of values.\n\n{\\footnotesize\n\\VerbatimInput{\\code/GreensFunctions/volintGreens.m}\n}\n\n\\clearpage\n\\newpage\n\n\n\\section{Method of Moments}\n\nThe VIEs provide a framework for solving for the total field solution inside an inhomogeneous distribution of material and then using the total field solution to predict the scattered field at points away from the object. In their continuous forms, the VIEs are nonlinear functions of the total field. The Method of Moments (MoM, or Moment Method) is a procedure to discretize the VIEs in order to cast the scattering problem as a system of linear equations to which linear algebra algorithms can be applied. In general, for an accurate solution an object must be discretized better than $\\lambda/10$ for the wavelength in the highest dielectric constant in the object. \n\n\\subsection{Pulse Basis Function}\nThe simplest discretization of the VIE are pulse basis functions. The object and field are sampled with non-overlapping cubic voxels, where it is assumed the the object and field are constant in each voxel. The object function is approximated as \n\\eq{O(\\br) \\approx \\sum_{n} O_{n} \\delta_{n}(\\br)}\n\\eq{\\delta_{n}(\\br) = \\begin{cases} 1, \\quad \\br \\in \\textrm{voxel } n \\\\\n0, \\quad \\textrm{otherwise}  \\end{cases} \\label{pulsebf}\n}\n\n\\noindent where $n$ indexes the set of voxels in 2D or 3D.  \n\n\\subsection{Scalar MoM} \n\nUsing the pulse basis function, two versions of the MoM for the scalar VIE can be derived. The first is written as a solution for the total field. This is useful for inverse scattering problems when the total field is needed separate from the object.  The second version is written in terms of the induced source, or contrast source, \\cite{van1997contrast}. The induced source is advantageous if a) the total field is not needed, b) there are many objects to simulate, because  the object only appears the diagonal of the MoM matrix, or c) only the scattered field away from the object needs to be computed.\n\n\\paragraph{Total Field}\n\nSubstituting the pulse basis function discretization of the object, \\eqref{pulsebf}, into the VIE, \\eqref{scalarVIE}\n\\eq{\\phi(\\br) = \\phi_{inc}(\\br) +  \\sum_{n} \\int g(\\br,\\br') O_{n} \\delta_{n}(\\br')\\phi(\\br') dV' }\n\nNext, the incident and total fields are assumed constant in each voxel and the fields outside of the integral are sampled as the same points as those in the integrand, but indexed separately\n\\eq{\\phi(\\br_m) = \\phi_{inc}(\\br_m) +  \\sum_{n} \\int g(\\br_m,\\br') O_{n} \\delta_{n}(\\br')\\phi(\\br_n) dV' }\n\nThe last step is to integrate the Green's function over the voxels. Using the results of Section \\eqref{volintfsgf}, this becomes\n\\eq{\\phi_m = \\phi_{inc,m} +  \\sum_{n} g_{mn} O_{n} \\phi_n \\label{phidiscrete} }\n\\eq{g_{mn} = \\begin{cases} g(\\bb{r}_m,\\bb{r}_n) \\Delta V, \\quad m \\neq n\\\\\ng(\\bb{r}_m=\\bb{r}_n), \\qquad m = n\\end{cases}}\n\n\\noindent where $\\Delta V$ is given by \\eqref{voxelint}, and the integration over the singular point is given by \\eqref{singint}, where the cubic voxels have been replaced by volume-equivalent spheres. The same procedure applies in 2D.  \n\nWriting \\eqref{phidiscrete} in matrix notation \n\\eq{\\left(\\bb{I} - \\bb{G} \\bb{O} \\right)\\boldsymbol{\\phi}  = \\boldsymbol{\\phi}_{inc} \\label{momscalarfield}}\n\n\\noindent where $\\bb{I}$ is the identity matrix, $\\boldsymbol{\\phi}$ is the vector of unknown total field values at each voxel, $\\boldsymbol{\\phi}_{inc}$ is the known incident field at the same voxels, $\\bb{G}$ is a full, symmetric matrix containing the Green's function values, and $\\bb{O}$ is a diagonal matrix containing the values of the object function at each voxel. The right multiplication of $\\bb{O}$ to $\\bb{G}$ makes the final matrix asymmetric for inhomogeneous objects.  A zero-contrast voxel has the effect of zeroing-out a column of the Green's function matrix, but the identity matrix makes the overall MoM matrix safe to invert. This last feature is one reason why the total field formulation is useful for iterative inverse scattering problems where the object contrast is not known ahead of time.  Put another way, when the object contrast is zero, the total field solution is not necessarily zero. \n\n\\paragraph{Induced Source}\n\nThe induced source, or contrast source, is defined as the product of the object contrast and the total field\n\\eq{w(\\bb{r}) = O(\\br) \\phi(\\br)}\n\nMultiplying \\eqref{scalarVIE} by $O(\\br)$, the VIE can be written\n\\eq{w(\\br) = w_{inc}(\\br) +  O(\\br) \\int g(\\br,\\br') w(\\br') dV' \\label{wvie}}\n\nApplying the MoM, we get the linear system\n\\eq{\\left(\\bb{I} - \\bb{O} \\bb{G}\\right) \\boldsymbol{w}  = \\boldsymbol{w}_{inc} \\label{wmomvie}}\n\nThis is similar to \\eqref{momscalarfield} where the LHS matrix is asymmetric.  Alternatively, taking \\eqref{wvie} or \\eqref{wmomvie} and multiplying through by $1/O(\\br)$ we can write\n\\eq{\\left(\\bb{O}^{-1} - \\bb{G}\\right) \\boldsymbol{w}  = \\boldsymbol{\\phi}_{inc} \\label{mominducediag}}\n\nIn this form the object only appears along the diagonal which makes the entire LHS matrix symmetric. This is similar to the more standard representation of the MoM, \\cite{peterson1998computational}, when it is given in terms of the impedance matrix, the induced current, and the incident field. In \\eqref{mominducediag}, if the object contrast of a voxel is zero, then the diagonal matrix element is infinite. The matrix either has to be reformed to exclude the rows and columns of the zero contrast, or a large numerical value needs to be substituted for the inverse contrast. In general, \\eqref{mominducediag} is useful for simulating sparse dielectric objects, such as snow aggregates or vegetation, because the MoM matrix only needs to contain the interactions between voxels that have non-zero contrast. \n\n\\begin{figure}[H] \n   \\centering\n      \\begin{tabular}{cc}\n     \\subfigure{\\includegraphics[width=2.5in]{GreensFunctions/Figures/green2d}}\n     \\subfigure{\\includegraphics[width=2.5in]{GreensFunctions/Figures/green2d_v2}}\n  \\end{tabular}\n  \\label{}\n\\caption{2D scalar Green's function matrix, $\\bb{G}$. Left: absolute value of the elements for the full matrix for a 20 $\\times$ 20 grid of points sampled at $\\lambda/10$ (total size $2\\lambda \\times 2 \\lambda$). Right: zoom in. The blocks are due to vectorizing the 2D grid of points and then taking all possible pairs of interactions. For example, the upper left 20 $\\times$ 20 block contains the $20^2$ interactions between the 20 points along one edge of the 2D grid. The diagonal of the matrix contains the self terms.}\n\\end{figure}\n\n\n\\begin{figure}[H] \n   \\centering\n      \\begin{tabular}{cc}\n     \\subfigure{\\includegraphics[width=2.5in]{GreensFunctions/Figures/green3d}}\n     \\subfigure{\\includegraphics[width=2.5in]{GreensFunctions/Figures/green3d_v2}}\n  \\end{tabular}\n  \\label{}\n\\caption{3D scalar Green's function matrix, $\\bb{G}$. Left: full matrix for a 10 $\\times$ 10 $\\times$ 10 grid of points sampled at $\\lambda/5$ (total size of $2\\lambda \\times 2\\lambda \\times 2\\lambda$). Note, this discretization step is for illustration purposes and is insufficient for an accurate solution. Right: zoom in. The appearance of blocks and subblocks is due to first vectorizing the 3D grid of points, and then taking all possible pairs of interactions which are arranged across rows and columns. For example, the first upper left subblock (sized 10 $\\times$ 10), contains the 100 pairs of interactions between the 10 points along one edge of the 3D grid. The diagonal of the matrix are the self terms. }\n\\end{figure}\n\n\n\\vspace{-5mm}\n\\paragraph{Routines} The routine \\texttt{momGmatrix2D} returns the 2D scalar Green's function matrix for the MoM solution. It takes as input the side length of the square voxel, $\\Delta x$, which is assumed constant for all voxels, the background wavenumber $k_b$, and the $(x,y)$ and $(x',y')$ coordinate pairs at which the Green's function will be evaluated. The voxel size length is used to evaluate the volume-integrated singular and non-singular scalar factors which are automatically included in the matrix elements. The arrays of unprimed and primed coordinate pairs can be different sizes: the output matrix is sized $M \\times N$ where $M$ is the total number of unprimed points down rows, and $N$ is the total number of primed points across columns. The inputs of primed and unprimed coordinates are separated to facilitate the construction of $\\bb{G}$ in subblocks when the number of points is large. If the complete matrix is desired, just input the same arrays for unprimed and primed coordinates, and the routine will return the full square matrix. The points are vectorized column-wise, so the corresponding object function or incident field need to be vectorized column-wise to be consistent. \n\n\n{\\scriptsize\n\\VerbatimInput{\\code/GreensFunctions/momGmatrix2D.m}\n}\n\n\\clearpage\nThe routine \\texttt{momGmatrix3D} returns the 3D scalar Green's function matrix for the MoM solution. It takes as input the side length of the cubic voxel, $\\Delta x$, which is assumed constant for all voxels, the background wavenumber $k_b$, and the $(x,y,z)$ and $(x',y',z')$ coordinate pairs at which to evaluate the matrix. It otherwise works the same as \\texttt{momGmatrix2D}. Because the MoM matrix scales as $O(N^2)$ with the number of 3D voxels, $N$, the total number of elements scales as $O(L^6)$, where $L$ is the side length of a cubic simulation region.\n\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/GreensFunctions/momGmatrix3D.m}\n}\n\n\n\n\\subsection{Vector MoM}\n\nThe vector MoM is derived the same way as the scalar MoM. The major difference is in bookkeeping the vector components and the size of the final matrix. The full vector formulation is needed for any 3D vector scattering problem.  \n\n\\paragraph{Total Field}\n\nStarting with the vector VIE, \\eqref{vectorVIE}, and substituting the pulse basis function\n\\eq{\\bb{E}(\\br) = \\bb{E}_{inc}(\\br) + \\sum_{n}  \\int \\G{} \\cdot O_{n} \\delta_{n}(\\br') \\bb{E}(\\br') dV' }\n\nAs with the scalar case, the field is assumed constant in each voxel and indexed as\n\\eq{\\bb{E}(\\br_m) = \\bb{E}_{inc}(\\br_m) + \\sum_{n}  \\int \\overline{\\bb{G}}(\\br_m,\\br')  \\cdot O_{n} \\delta_{n}(\\br') \\bb{E}(\\br_n) dV' }\n\nAssuming Cartesian vector components, $u = (x,y,z)$ and $v = (x,y,z)$, and integrating the dyadic Green's function over the volume-equivalent sphere of the cubic voxel, this is written as a sum for each total field component as\n\\eq{E_{u,m} = E_{inc,u,m} +  \\sum_{v}\\sum_{n} G_{uv,mn} O_{n} E_{v,n} \\label{Ediscrete} }\n\\eq{G_{uv,mn} = \\begin{cases} G_{uv}(\\bb{r}_m,\\bb{r}_n) \\Delta V, \\quad m \\neq n\\\\\nG_{uv}(\\bb{r}_m=\\bb{r}_n), \\qquad m = n, u = v \\quad (0, u \\ne v)  \\end{cases}}\n\n\\noindent where $\\Delta V$ is given by \\eqref{voxelint}. The value of the singular integration at the self term, \\eqref{singintvec}, is equal to a constant times the identity dyad. The identity dyad means that the self-term only applies to the diagonal elements of the dyad (i.e., $G_{xx}, G_{yy}, G_{zz}$) and is zero for the off-diagonal elements of the dyad. Writing this in matrix notation for the three unknown total field components \n\\eq{\\left(\\bb{I} - \\thbth\n{\\bb{G}_{xx}}{\\bb{G}_{xy}}{\\bb{G}_{xz}}\n{\\bb{G}_{yx}}{\\bb{G}_{yy}}{\\bb{G}_{yz}}\n{\\bb{G}_{zx}}{\\bb{G}_{zy}}{\\bb{G}_{zz}} \n\\thbth{\\bb{O}}{}{}{}{\\bb{O}}{}{}{}{\\bb{O}}  \\right) \\thrcol{\\bb{E}_x}{\\bb{E}_y}{\\bb{E}_z} = \\thrcol{\\bb{E}_{inc,x}}{\\bb{E}_{inc,y}}{\\bb{E}_{inc,z}} \\label{mommatrixtot}}\n\n\\noindent where $\\bb{I}$ is the identity matrix, $\\bb{G}_{uv}$ is the Green's function matrix block for a given polarization pair, $\\bb{E}_{inc,v}$ and $\\bb{E}_{v}$ are vectors of the incident field and total field solution, respectively, $\\bb{O}$ is the diagonal matrix of the object function which is applied to each component. The self term (diagonals) of $\\bb{G}_{xx}, \\bb{G}_{yy}, \\bb{G}_{zz}$, take the value, \\eqref{singintvec}, while the self terms of the other blocks are zero. Recall, $\\bb{G}_{uv} = \\bb{G}_{vu}$, and each block matrix is square symmetric. The size of each block matrix and field vector is the same size as the scalar case. The field components lead to 3 times as many unknowns as compared to the scalar cases, and polarization mixing makes the MoM matrix 9 times larger than the 3D scalar case. \n\n\n\\paragraph{Induced Current}\n\nDefine the induced current as the product of the contrast and the total field at a given point\n\\eq{ \\bb{J}(\\br)  =  O(\\br) \\bb{E}(\\br)}\n\nThen \\eqref{mommatrixtot} can be written \n\\eq{\\left(\\thbth{\\bb{O}^{-1}}{}{}{}{\\bb{O}^{-1}}{}{}{}{\\bb{O}^{-1}}  - \\thbth\n{\\bb{G}_{xx}}{\\bb{G}_{xy}}{\\bb{G}_{xz}}\n{\\bb{G}_{yx}}{\\bb{G}_{yy}}{\\bb{G}_{yz}}\n{\\bb{G}_{zx}}{\\bb{G}_{zy}}{\\bb{G}_{zz}} \n \\right) \\thrcol{\\bb{J}_x}{\\bb{J}_y}{\\bb{J}_z} = \\thrcol{\\bb{E}_{inc,x}}{\\bb{E}_{inc,y}}{\\bb{E}_{inc,z}}  }\n\n\n\\begin{figure}[H] \n   \\centering\n      \\begin{tabular}{cc}\n     \\subfigure{\\includegraphics[width=1.9in]{GreensFunctions/Figures/green3dyadic1}}\n     \\subfigure{\\includegraphics[width=1.9in]{GreensFunctions/Figures/green3dyadic2}} \n     \\subfigure{\\includegraphics[width=1.9in]{GreensFunctions/Figures/green3dyadic3}} \\\\\n     \\subfigure{\\includegraphics[width=1.9in]{GreensFunctions/Figures/green3dyadic4}} \n     \\subfigure{\\includegraphics[width=1.9in]{GreensFunctions/Figures/green3dyadic5}}\n     \\subfigure{\\includegraphics[width=1.9in]{GreensFunctions/Figures/green3dyadic6}}\n  \\end{tabular}\n  \\label{}\n\\caption{3D dyadic Green's function block matrices, $\\bb{G}_{uv}$. Full block matrices for a 10 $\\times$ 10 $\\times$ 10 grid of points sampled at $\\lambda/5$ (total size of $2\\lambda \\times 2\\lambda \\times 2\\lambda$). The zero elements in $\\bb{G}_{u \\ne v}$ happen when voxels have common coordinates in either $u$ or $v$. This is a result of $\\bb{G}_{u \\ne v}$ being proportional to the difference of primed and unprimed coordinates in $u$ or $v$. }\n\\end{figure}\n\n\\paragraph{Routine} The routine \\texttt{momGmatrixDyadic} returns the 6 unique block matrices of the 3D dyadic MoM matrix.  It takes as input the side length of the cubic voxel, $\\Delta x$, which is assumed constant for all voxels, the background wavenumber $k_b$, and the $(x,y,z)$ and $(x',y',z')$ coordinate pairs at which to evaluate the matrix. It works similarly to \\texttt{momGmatrix2D} and \\texttt{momGmatrix3D}, but calls \\texttt{dyadicGreens} which takes the relative positions as input. The arrays of unprimed and primed coordinate pairs can be different sizes. The output matrix is sized $M \\times N$ where $M$ is the total number of unprimed points down rows, and $N$ is the total number of primed points across columns. In the routine, the volume integrated constants are applied to all entries. The singularity constant is applied to the self terms of the blocks $\\bb{G}_{u = v}$, while the self terms of the blocks $\\bb{G}_{u \\ne v}$ are set to zero. \n\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/GreensFunctions/momGmatrixDyadic.m}\n}\n\n\\clearpage\n\\newpage\n\n\\section{Scattered Field VIE}\n\nOnce the total field solution is found, the scattered field away from the object is computed again with the VIE. Here, the unprimed position vector of the Green's function is evaluated at an observation point outside of the object domain. In this case, the Green's function is often referred to as the receiver Green's function. This can be a point of confusion when comparing it to the Green's function as used in the MoM solution, where the unprimed position vector is evaluated throughout the object domain including at singular points. In the end, the receiver Green's function is the same as the one used in the MoM solution, except that the unprimed position vector is simply evaluated outside of the object at a point that is also usually associated with a sensor.\n\nFrom reciprocity, it turns out that the receiver Green's function is equivalent to the incident field generated by a point source at the observation location. This is practically and conceptually useful. It links the incident field needed when solving for the total field solution to the scattered field VIE needed to compute the measurements from sources or receivers at the same location. This idea is generalized to the case of real antennas fed by waveguides using the waveport vector Green's function described in \\cite{haynes2012vector}. The overarching idea here is that only the incident field of a source or an antenna needs to be known in order to compute both the total field solution and the received voltage measurements in a consistent way. \n\n\\subsection{Receiver Green's Function}\n\\paragraph{Scalar case}\nLet a source be at location $\\br_i$. This generates an incident field, $\\phi_{inc,i}(\\br)$, for which the total field solution in the object is $\\phi_{i}(\\br)$. The scattered field observed at a point, $\\br_j$, outside the object is\n\\eq{\\phi_{sca,ji}(\\br_j) = \\int g(\\br_j,\\br') O(\\br') \\phi_i(\\br') dV', \\qquad \\br_{j} \\notin V \\label{scalarscaji}}\n\n\\noindent where, $g(\\br_j,\\br')$ is the receiver Green's function. The receiver Green's function is named this way because the unprime variable is evaluated at the receiver, or observation, point. This VIE is discretized the same way as the MoM: the Green's function is integrated over volume-equivalent voxels so that\n\\eq{\\phi_{sca,ji}(\\br_j) \\approx \\Delta V \\sum_{n} g(\\br_j,\\br_n) O(\\br_n) \\phi_i(\\br_n) \\label{scalarscadiscrete}}\n \n\\noindent where $\\Delta V$ is given by \\eqref{voxelint} in the 3D case. Because $\\br_{j} \\notin V$, there is no singular point to deal with.\n\n\\paragraph{Vector case}\n\nLet a vector source, like an antenna, be located at $\\br_i$. This generates an incident field, $\\bb{E}_{inc,i}(\\br)$, for which the total field solution in the object is $\\bb{E}_{i}(\\br)$. The scattered field observed at a point, $\\br_j$, outside the object is\n\\eq{\\bb{E}_{sca,ji}(\\br_j)=  \\int \\overline{\\bb{G}}(\\br_j,\\br')\\cdot O(\\br') \\bb{E}_i(\\br') dV', \\qquad \\br_{j} \\notin V \\label{vectorscaji} }\n\nHere, $\\overline{\\bb{G}}(\\br_j,\\br')$ is the dyadic receiver Green's function. Discretized like the MoM, this is \n\\eq{\\bb{E}_{sca,ji}(\\br_j) \\approx   \\Delta V\\sum_{n}  \\overline{\\bb{G}}(\\br_j,\\br_n)  \\cdot O(\\br_n) \\bb{E}_i(\\br_n) \\label{vectorscadiscrete} }\n\n\\noindent where $\\Delta V$ is given by \\eqref{voxelint}, there is no singular point, and the dyadic Green's function is evaluated normally. \n\n\\subsection{Incident Field Reciprocity}\n\nThe receiver Green's function is equivalent to the incident field generated by a point source at the receiver location when used in transmit mode. This is a consequence of the definition of the Green's function and reciprocity. The derivation is simple, but the idea has important implications for linking the VIE to measurements in experimental setups. In short, the incident field alone fully characterizes the transmit and receive characteristics of a reciprocal sensor. We derive the results for scalar and vector point sources, but the results hold for arbitrary source distributions. \n\n\\paragraph{Scalar case}\n\nDefine a scalar point source at location $\\br_j$ as $s(\\br) = -\\delta(\\br - \\br_j)$. Using \\eqref{sourceintscalar}, the incident field from this source is\n\\ea{\\phi_{inc,j}(\\br) &=&  -\\int g(\\br,\\br') s(\\br') dV' \\\\\n\\ &=& \\int g(\\br,\\br') \\delta(\\br' - \\br_j) dV' \\\\\n\\ &=&  g(\\br,\\br_j) }\n\nThis is another way of stating the definition of the Green's function. Using the fact that $g(\\br,\\br_j) = g(\\br_j,\\br)$, and substituting this into \\eqref{scalarscaji}, the scattered field VIE is\n\\eq{\\phi_{sca,ji}(\\br_j) = \\int \\phi_{inc,j}(\\br') O(\\br') \\phi_i(\\br') dV' \\label{scalarscajiinc}}\n\nThe incident field from the point source takes the place of the receiver Green's function. From linearity, this holds for an incident field from an arbitrary source distribution so long as the same device is used as the receiver. Finally, \\eqref{scalarscajiinc} is discretized the same as \\eqref{scalarscadiscrete}. \n\n\\paragraph{Vector case}\n\nLet the current source be an infinitesimal dipole at $\\br_j$ with strength $I$ and polarization $\\hat{\\bb{p}}$\n\\eq{\\bb{J}(\\br) = I \\hat{\\bb{p}} \\delta(\\br - \\br_j)}\n\nSubstituting this into \\eqref{evolintj}\n\\ea{\\bb{E}_{inc,j}(\\br) &=& i\\omega\\mu\\int \\overline{\\bb{G}}(\\br,\\br') \\cdot \\bb{J}(\\br') dV' \\\\\n \\ &=& i\\omega\\mu I \\int \\overline{\\bb{G}}(\\br,\\br') \\cdot \\hat{\\bb{p}} \\delta(\\br' - \\br_j) dV'  \\\\\n  \\ &=& i\\omega\\mu I  \\overline{\\bb{G}}(\\br,\\br_j) \\cdot \\hat{\\bb{p}} }\n\nor\n\\ea{ \\overline{\\bb{G}}(\\br,\\br_j) \\cdot \\hat{\\bb{p}} = \\dfrac{1}{i\\omega\\mu I }\\bb{E}_{inc,j}(\\br)  }\n\nA similar expression can be found in \\cite{cui2004study} for 2D problems. The columns of the dyadic receiver Green's function are found by computing the incident field due to three orthogonal dipoles in turn. Denote these incident fields $\\bb{E}_{inc,j,p}$ for dipole polarizations $p = [x, y, z]$ located at the observation point. Then using the fact that $\\overline{\\bb{G}}(\\br,\\br_j) = \\left[ \\overline{\\bb{G}}(\\br_j,\\br)\\right]^{t}$, we have\n\\eq{ \\overline{\\bb{G}}(\\br_j,\\br)  = \\dfrac{1}{i\\omega\\mu I }\\cvec{\\bb{E}_{inc,j,x}^t(\\br)}{\\bb{E}_{inc,j,y}^t(\\br)}{\\bb{E}_{inc,j,z}^t(\\br)} \\label{incdyad}}\n\nThe matrix on the right hand side is denoted the incident field dyad. The transposes place the $[x,y,z]$ vector components of each dipole incident field along the rows of the dyad, which maps the three-vector total field (or induced source) in the domain to the polarizations of the source dipole at the receiver location. Substituting this into \\eqref{vectorscaji}, the scattered field VIE for the electric field is\n\\eq{\\bb{E}_{sca,ji}(\\br_j)= \\dfrac{1}{i\\omega\\mu I }\\int \\cvec{\\bb{E}_{inc,j,x}^t(\\br')}{\\bb{E}_{inc,j,y}^t(\\br')}{\\bb{E}_{inc,j,z}^t(\\br')} \\cdot O(\\br') \\bb{E}_i(\\br') dV' \\label{vectorscajiinc} }\n\nIn simulation, one can set $I = 1/i\\omega\\mu$ to cancel the scale factor and \\eqref{vectorscajiinc} can be discretized like \\eqref{vectorscadiscrete}. The physical interpretation of \\eqref{vectorscajiinc} is the following. The three source dipoles at the observation location independently map to a three-vector incident field in the object domain. Concurrently, each vector component of the induced current in the domain radiates all three vector components to the observation point. The columns of the incident field dyad, \\eqref{incdyad}, map any single component of the induced current to the three components at the observation location in proportion to the strength of the incident fields created by the corresponding source dipoles. This is another way of stating reciprocity. %For example, an $x$ directed current in the object radiates all three vector components at the observation point and the weights of this mapping are determined are determined by the $x$ components of each of the three incident fields. The same happens for the other two components to accomplish the full dyadic mixing. \n\n\n\\subsection{Waveport Vector Green's Function}\nWhen measuring fields with real antennas, we never measure the three electric field components directly. We measure a voltage on a feeding waveguide or transmission line. The three vector components of the scattered field are effectively integrated over the surface of the antenna and produce the voltage on the waveguide. The incident field dyad above collapses to three-vector incident field with certain scale factors. This was formalized in \\cite{haynes2012vector} in the form a waveport vector Green's function. The idea is fundamentally the same as the receiver Green's function and incident field dyad, except that it is specialized for S-parameter measurements between two antennas that are made using a vector network analyzer (VNA) with calibrated reference planes on the feeding transmission lines. \n\n\\begin{figure}[H] \n\\centering\n\\includegraphics[width=3in]{GreensFunctions/Figures/SparamVIE}\n\\caption{Network model of two antennas and a scattering object. $S$-parameters are measured between the reference planes on antenna transmission lines, \\cite{haynes2012vector}.}\n\\label{sparamviefig}\n\\end{figure}\n\nLet two antennas in frames $i$ and $j$ be used to probe an object with a VNA that measures the entire system as a 2-port device, as shown in Figure \\ref{sparamviefig}. The complex excitation amplitudes on each transmission line are $a_o^i$ and $a_o^j$, while the received amplitudes are $b_o^i$ and $b_o^j$. The VNA is calibrated to the reference planes on the transmission lines. Assume that the spatial distribution of the antenna incident field is referenced to a fixed coordinate origin of the antenna, and the excitation (amplitude and phase) is referenced to the calibration planes on the transmission line. The waveport vector Green's function is\n\\eq{\\bb{g}(\\br) = -\\dfrac{Z_o}{2a_o}\\dfrac{1}{i\\omega\\mu} \\bb{E}_{inc}(\\br)}\n\n\\noindent where $Z_o$ is the characteristic impedance of the receiver transmission line and $a_o$ is the excitation used to create the incident field $\\bb{E}_{inc}(\\br)$. The waveport vector Green's replaces the dyadic receiver Green's function \\eqref{incdyad} and effectively collapses the dyad.\nWhen used in the VIE, the 2-port scattered field $S$-parameter measurement, $S_{ji}$, is given by \n\\eq{S_{ji} = -\\dfrac{1}{2i\\omega\\mu} \\dfrac{Z_o^j}{a_o^j a_o^i} \\int \\bb{E}_{inc,j}(\\br') \\cdot O(\\br') \\bb{E}_{i}(\\br') dV'}\n\n\\noindent where $a_o^j$ is the excitation used to create the incident field of the receiver, $\\bb{E}_{inc,j}(\\br')$, and $a_o^i$ is the excitation used to create the incident field of the transmitter $\\bb{E}_{inc,i}(\\br')$ which in turn is used to compute the solution of the total field $\\bb{E}_{i}(\\br')$.  In practice, if we know the average transmit power on the transmission line, $P_{ave}$, then from transmission line analysis the magnitude of $a_o$ is given by \n\\eq{\\vert a_o \\vert = \\sqrt{2 Z_o P_{ave}}}\n\nThe phase of $a_o$ can be found by comparing the transmission line reference plane used to measure or simulate the incident fields to the reference planes used in measurement. \n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "915c2739b719d428ab186ec8f90054605a7df72b", "size": 47931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/GreensFunctions/GreensFunctions.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/GreensFunctions/GreensFunctions.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/GreensFunctions/GreensFunctions.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": 90.4358490566, "max_line_length": 1208, "alphanum_fraction": 0.730946569, "num_tokens": 14170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152325073083131, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6665132919504427}}
{"text": "\\documentclass{scrartcl}\n\n\\input{../../shared.tex}\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\\usepackage{enumerate}\n\n\\begin{document}\n\n\\begin{definition}\n  Given a vector space $V$ a \\textbf{norm} $\\Vert \\cdot \\Vert$ is mapping from $V$ to $[0, +\\infty)$ such that\n  \\begin{enumerate}\n    \\item \\textbf{positive definiteness:} $\\Vert x \\Vert = 0$ if and only if $x=0$.\n    \\item \\textbf{absolute homogeneity:} $\\Vert \\lambda x \\Vert = \\vert \\lambda \\vert \\Vert x \\Vert$ for all $\\lambda \\in \\R$.\n      \\item \\textbf{triangle inequality:} $\\Vert x+y \\Vert \\le \\Vert x \\Vert + \\Vert y \\Vert$ for all $x,y \\in V$.\n  \\end{enumerate}\n\\end{definition}\n\n\\section{Problem set}%\n\n\\begin{enumerate}[(i)]\n  \\item (2P) Show that all norms are \\emph{convex} functions.\n  \\item (2P) Let $g: \\R^m \\to \\R$ be a convex function and $A \\in \\R^{m \\times d}$ a linear operator (matrix). Show that $f(\\cdot) = g(A \\cdot)$ is also convex.\n  \\item (3P) Let $x^*$ be local minimum of a convex function $f:\\R^d\\to \\R$. Show that $x^*$ is a global minimum.\n  \\item (2P) If $\\bar{x}$ is a stationary point of the \\textbf{convex} function $f$, then $\\bar{x}$ is a global minimizer of $f$ (give a geometric intuition).\n  \\item (1P) Install and familiarize yourself with python and Jupyter Notebook. (no need to upload anything)\n\\end{enumerate}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "0b9223d035fba9953230a371d73d0c727ed28c01", "size": 1362, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/01_Convexity/exercises-convexity.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/01_Convexity/exercises-convexity.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/01_Convexity/exercises-convexity.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": 42.5625, "max_line_length": 160, "alphanum_fraction": 0.6732745962, "num_tokens": 441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6665132917876213}}
{"text": "\\section{Common Families of Distributions}\n\n\n\\begin{center}\n    \\emph{Lots of this chapter is standard definitions of distributions, so is omitted}\n\\end{center}\n\n\n\\subsection{Some Distributions}\n\n\\begin{definition}[Normal Distribution]\n    If $\\vec{X} \\sim \\n(\\vec{\\mu}, \\bm{\\Sigma})$ then $\\vec{X}$ has pdf\n    \\[\n    f_{\\vec{X}}(x_1, \\dots, x_k \\vert{} \\vec{\\mu}, \\bm{\\Sigma})  = \\frac{1}{\\sqrt{(2\\pi)^k \\det\\bm{\\Sigma}}} \\exp\\left(-\\frac12 (\\vec{ x}-\\vec{\\mu})^\\top \\bm{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu})\\right)\n    \\].\n\\end{definition}\n\n\\subsubsection{Chi-Squared Distribution}\n\\begin{definition}\n    The \\emph{chi-squared distribution with $p$ degrees of freedom} has pdf\n    \\[\n        \\chi_p^2 \\sim \\frac{1}{\\Gamma(p/2)2^{p/2}} x^{(p/2)-1} e^{-x/2}, \\quad 0< x< \\infty.\n    \\]\n\\end{definition}\n\n\\begin{theorem}[Some facts]\n    \\mbox{}\n    \\begin{enumerate}[a.]\n        \\item If $Z \\sim \\n(0, 1)$ then $Z^2 \\sim \\chi_1^2$\n        \\item If $X_1, \\dots, X_n$ are independent $X_i \\sim \\chi_{p_i}^2$ then $X_1 + \\cdots + X_n \\sim \\chi_{p_1 + \\cdots + p_n}^2$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\subsubsection{Student's $t$-Distribution}\n\\begin{definition}[Student's $t$-distribution]\n    $T \\sim t_p$, a \\emph{$t$-distribution with $p$ degrees of freedom} if it has pdf\n    \\[\n        f_T(t) = \\frac{\\Gamma\\left(\\frac{p+1}{2}\\right)}{\\Gamma\\left(\\frac{p}{2}\\right)} \\frac{1}{\\sqrt{p\\pi}} \\frac{1}{(1 + t^2/p)^{(p+1)/2}}, \\quad t \\in \\R{}\n    \\]\n\\end{definition}\n\nIf $p = 1$ then this is the Cauchy distribution.\n\n\\begin{remark}\n    If $X_1, \\dots, X_n$ are a random sample from $\\n(\\mu, \\sigma^2)$ then\n    \\[\n        \\frac{\\bar{X} - \\mu}{S/\\sqrt{n}} \\sim t_{n-1}.\n    \\]\n    This is often taken as the definition. Note that the denominator is independent of the numerator.\n\\end{remark}\n\n\\begin{lemma}[Moments and mgf of $t$-distribution]\n    Student's $t$ has no mgf because it does not have moments of all orders: $t_p$ has only $p-1$ moments. If $T_p \\sim t_p$ then\n    \\begin{align*}\n        \\E{}[T_p] &= 0 \\quad p > 1 \\\\\n        \\Var{}[T_p] &= \\frac{p}{p-2} \\quad p > 2\n    \\end{align*}\n\\end{lemma}\n\n\\subsubsection{Snedcor's $F$-Distribution}\n\n\\begin{definition}[Snedcor's $F$-distribution]\n    A random variable $X \\sim F_{p,q}$ has \\emph{$F$-distribution with p and q degrees of freedom} if its pdf is\n    \\[\n        f_X(x) = \\frac{\\Gamma\\left(\\frac{p+q}{2}\\right)}{\\Gamma\\left(\\frac p2 \\right)\\Gamma\\left(\\frac q2 \\right)} (p/q)^{p/2} \\frac{x^{(p/2) - 1}}{(1 + px/q)^{(p+q)/2}}, \\quad 0 < x < \\infty.\n    \\]\n\\end{definition}\n\n\\begin{remark}\n    If $X_1, \\dots, X_n$ is a random sample from $\\n(\\mu_X, \\sigma_X^2)$ and $Y_1, \\dots, Y_m$ is an independent random sample from $\\n(\\mu_Y, \\sigma_Y^2)$, then\n    \\[\n        \\frac{S^2_X/\\sigma^2_X}{S_Y^2/\\sigma_Y^2} \\sim F_{n-1, m-1}.\n    \\]\n    This is often taken as the definition.\n\\end{remark}\n\n\\begin{theorem}[Some facts]\n    \\mbox{}\n    \\begin{enumerate}[a.]\n        \\item $X \\sim F_{p,q} \\,\\, \\implies \\,\\, 1/X \\sim F_{q,p}$\n        \\item $X \\sim t_q \\,\\, \\implies \\,\\, X^2 \\sim F_{1,q}$\n        \\item $X \\sim F_{p,q} \\,\\, \\implies \\,\\, \\frac{(p/q)X}{1 + (p/q)X} \\sim \\text{beta}(p/2, q/2)$\n    \\end{enumerate}\n\\end{theorem}\n\n\\subsubsection{Multinomial Distribution}\n\\begin{definition}[Multinomial Distribution]\n    Let $m$ and $n$ be positive integers and let $p_1, \\dots, p_n \\in [0, 1]$ satisfy $\\sum_{i=1}^n p_i = 1$. Then the random vector $(X_1, \\dots, X_n)$ has \\emph{multinomial distribution with m trials and cell probabilities $p_1, \\dots, p_n$} if the joint pmf of $(X_1, \\dots, X_n)$ is \n    \\[\n        f(x_1, \\dots , x_n) = \\frac{m!}{x_1! \\cdots x_n!} p_1^{x_1} \\cdots\np_n^{x_n} = m! \\prod_{i=1}^n \\frac{p_i^{x_i}}{x_i!} \n    \\]\n    on the set of $(x_1, \\dots, x_n)$ such that each $x_i$ is a nonnegative integer and $\\sum_{i=1}^n x_i = m$.\n\\end{definition}\n\n\\begin{remark}\n    The marginal distributions have $X_i \\sim \\text{binomial}(m, p_i)$.\n\\end{remark}\n\n\\begin{theorem}[Multinomial Theorem]\n    Let $m$ and $n$ be positive integers and let $\\mathcal{A}$ be the set of vectors $\\vec{x} = (x_1, \\dots, x_n)$ such that each $x_i$ is a nonnegative integer and $\\sum_{i=1}^n x_i = m$. Then for any real numbers $p_1, \\dots, p_n$,\n    \\[\n        (p_1 + \\cdots + p_n)^m = \\sum_{\\vec{x} \\in \\mathcal{A}} \\frac{m!}{x_1! \\cdots x_n!} p_1^{x_1}\\cdots p_n^{x_n}.\n    \\]\n\\end{theorem}\n\n\n\\subsection{Exponential Families}\n\n\\begin{definition}[Exponential family 1]\n    A family of pmfs/pdfs is called an \\emph{exponential family} if it can be expressed\n    \\[\n          f(x|\\vec{\\theta}) = h(x)c(\\vec{\\theta})\\exp\\left( \\sum_{i=1}^k w_i(\\vec{\\theta}) t_i(x) \\right)\n    \\]\n    where $h(x) \\geq 0$, the $t_i$ are real valued functions of the observation $x$ that do not depend on $\\vec{\\theta}$ and $c(\\theta) \\geq 0$ and the $w_i(\\vec{\\theta})$ are real valued functions of $\\vec{\\theta}$ that do not depend on $x$.\n\\end{definition}\n\n\\begin{theorem}\n    If $X$ is a random variable from an exponential family distribution then\n    \\[\n        \\E{}\\left[ \\sum_{i=1}^k \\frac{\\pd w_i(\\vec{\\theta})}{\\pd \\theta_j} t_i(X) \\right] = - \\frac{\\pd}{\\pd \\theta_j} \\log c(\\vec{\\theta})\n    \\]\n    and\n    \\[\n        \\Var\\left[ \\frac{\\pd w_i(\\vec{\\theta})}{\\pd \\theta_j} t_i(X) \\right] = - \\frac{\\pd^2}{\\pd \\theta_j^2} \\log c(\\vec{\\theta}) - \\E{}\\left[ \\sum_{i=1}^{k} \\frac{\\pd^2 w_i(\\vec{\\theta})}{\\pd \\theta_j^2} t_i(X) \\right]\n    \\]\n\\end{theorem}\n\n\\begin{definition}[Exponential family 2]\n    We can write another parameterisation of the exponential family\n    \\[\n        f(x | \\vec{\\eta}) = h(x) c^{*}(\\vec{\\eta}) \\exp(\\vec{\\eta} \\cdot \\vec{t}(x))\n    \\]\n    where $\\vec{\\eta}$ is called the \\emph{natural parameter} and the set $\\H{} = \\{\\vec{\\eta} : \\int_\\R{} f(x|\\eta) \\d x < \\infty \\}$ is called the \\emph{natural parameter space} and is convex.\n\\end{definition}\n\n\\begin{remark}\n    $\\{\\vec{\\eta}: \\vec{\\eta} = \\vec{w}(\\vec{\\theta}), \\,\\, \\vec{\\theta} \\in \\Theta\\} \\subseteq \\H{}$. So there may be more parameterisations here than previously.\\\\\n    \nThe natural parameter provides a convenient mathematical formulation, but sometimes lacks simple interpretation.\n\\end{remark}\n\n\\begin{definition}[Curved exponential family]\n    A \\emph{curved exponential family} distribution is one for which the dimension of $\\vec{\\theta}$ is $d < k$. If $d = k$ then we have a \\emph{full exponential family}.\n\\end{definition}\n\n\\subsection{Location and Scale Families}\n\n\\begin{definition}[Location family]\n    Let $f(x)$ be any pdf. The family of pdfs $f(x - \\mu)$ for $\\mu \\in \\R{}$ is called the \\emph{location family with standard pdf $f(x)$} and $\\mu$ is the \\emph{location parameter} of the family.\n\\end{definition}\n\n\\begin{definition}[Scale family]\n    Let $f(x)$ be any pdf. For any $\\sigma > 0$ the family of pdfs $\\frac{1}{\\sigma} f(x/\\sigma)$ is called the \\emph{scale family with standard pdf $f(x)$} and $\\sigma$ is the \\emph{scale parameter} of the family.\n\\end{definition}\n\n\\begin{definition}[Location-Scale family]\n    Let $f(x)$ be any pdf. For $\\mu \\in \\R{}$ and $\\sigma > 0$ the family of pdfs $\\frac{1}{\\sigma} f(\\frac{x - \\mu}{\\sigma})$ is called the \\emph{location-scale family with standard pdf $f(x)$}; $\\mu$ is the \\emph{location parameter} and $\\sigma$ is the \\emph{scale parameter}.\n\\end{definition}\n\n\\begin{theorem}[Standardisation]\n    Let $f$ be any pdf, $\\mu \\in \\R{}$ and $\\sigma \\in \\R{}_{>0}$. Then $X$ is a random variable with pdf $\\frac{1}{\\sigma}f(\\frac{x - \\mu}{\\sigma})$ if and only if there exists a random variable $Z$ with pdf $f(z)$ and $X = \\sigma Z + \\mu$.\n\\end{theorem}\n\n\\begin{remark}\n    Probabilities of location-scale families can be computed in terms of their standard variables $Z$\n    \\[\n        \\P{}(X \\leq x) = \\P{}\\left(Z \\leq \\frac{x - \\mu}{\\sigma} \\right)\n    \\]\n\\end{remark}\n\n\\subsection{Inequalities and Identities}\n\n\\begin{theorem}[Chebychev's inequality]\n    Let $X$ be a random variable and let $g(x)$ be a nonnegative function. Then, for any $r > 0$,\n    \\[\n        \\P{}(g(X) \\geq r) \\leq \\frac{\\E{}[g(X)]}{r}.\n    \\]\n\\end{theorem}\n\n\\begin{remark}\n    This bound is conservative and almost never attained. \n\\end{remark}\n\n\\begin{remark}[Markov inequality]   \n    The Markov inequality is the special case with $g = \\mathbb{I}$.\n\\end{remark}\n\n\\begin{theorem}\n    Let $X_{\\alpha, \\beta}$ denote a gamma$(\\alpha, \\beta)$ random variable with pdf $f(x \\vert{} \\alpha, \\beta)$, where $\\alpha > 1$. Then for any constants $a$ and $b$:\n    \\[\n        \\P{}(a < X_{\\alpha, \\beta} < b) = \\beta (f(a \\vert{} \\alpha, \\beta) - f(b \\vert{} \\alpha, \\beta)) + \\P{}(a < X_{\\alpha - 1, \\beta} < b)\n    \\]\n\\end{theorem}\n\n\\begin{lemma}[Stein's Lemma]\n    Let $X \\sim \\n(\\theta, \\sigma^2)$ and let $g$ be a differentiable function with $\\E{}[g'(x)] < \\infty$. Then\n    \\[\n        \\E{}[g(X)(X - \\theta)] = \\sigma^2 \\E{}[g'(X)]\n    \\]\n\\end{lemma}\nThe proof is just integration by parts.\n\n\\begin{remark}\n    Stein's lemma is useful for moment calculations\n\\end{remark}\n\n\\begin{theorem}\n    Let $\\chi^2_p$ denote a chi squared distribution with $p$ degrees of freedom. For any function $h(x)$,\n    \\[\n        \\E{}[h(\\chi^2_p)] = p \\E{}\\left[\\frac{h(\\chi_{p+2}^2)}{\\chi_{p+2}^2}\\right]\n    \\]\n    provided the expressions exist.\n\\end{theorem}\n\n\\begin{theorem}\n    Let $g(x)$ be a function that is bounded at $-1$ and has finite expectation, then\n    \\begin{enumerate}[a.]\n        \\item If $X \\sim \\text{Poisson}(\\lambda)$,\n            \\[\n                \\E{}[\\lambda g(X)] = \\E{}[Xg(X-1)].\n            \\]\n        \\item If $X\\sim \\text{negative-binomial}(r, p)$,\n            \\[\n                \\E{}[(1-p)g(X)] = \\E{}\\left[ \\frac{X}{r + X - 1}g(X) \\right].\n            \\]\n    \\end{enumerate}\n\\end{theorem}\n\n\n\n\n\n\n", "meta": {"hexsha": "498a936b9182754fe7820a79cd82c68737f6cd7a", "size": 9691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter3/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/chapter3/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/chapter3/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": 41.2382978723, "max_line_length": 287, "alphanum_fraction": 0.608399546, "num_tokens": 3447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.6665132790816372}}
{"text": "\\section{Sparse Grids}\n\\label{sec:23sparseGrids}\n\n\\minitoc{67mm}{4}\n\n\\noindent\nThe idea of sparse grids is to use the\nhierarchical splitting \\eqref{eq:hierSplittingMV}\nto keep only the most important hierarchical subspaces,\nomitting the remaining ones.\nThere are three main ``flavors'' of sparse grids:\nregular, dimensionally adaptive, and spatially adaptive.\n\n\n\n\\subsection{Regular Sparse Grids}\n\\label{sec:231regularSG}\n\n\\paragraph{Hierarchical contributions}\n\nTo assess the importance of a subspace, we consider again the\ninterpolant $\\fgintp{\\*l} \\in \\ns{\\*l}$ of a function $\\objfun\\colon \\clint{\\*0, \\*1} \\to \\real$.\nAccording to the splitting \\eqref{eq:hierSplittingMV}, the interpolant can\nbe written as\n\\begin{equation}\n  \\label{eq:interpHierFullGrid}\n  \\fgintp{\\*l}\n  = \\sum_{\\*l'=\\*0}^\\*l \\sum_{\\*i' \\in \\hiset{\\*l'}}\n  \\surplus{\\*l',\\*i'} \\basis{\\*l',\\*i'},\\quad\n  \\falarge{\\*i = \\*0, \\dotsc, \\*2^\\*l}{\\fgintp{\\*l}(\\gp{\\*l,\\*i}) = \\objfun(\\gp{\\*l,\\*i})}.\n\\end{equation}\nThe coefficients $\\surplus{\\*l',\\*i'}$ with respect to the hierarchical basis\n$\\basis{\\*l',\\*i'}$ are the \\term{hierarchical surpluses.}\nWhen using the hat function basis $\\bspl{\\*l,\\*i}{1}$,\none can prove the following representation\nfor the corresponding surpluses \\multicite{Bungartz04Sparse,Garcke13Sparse}:\n\\begin{equation}\n  \\label{eq:surplusIntegral}\n  \\surplus{\\*l',\\*i'}\n  = (-1)^d 2^{-\\normone{\\*l'+\\*1}}\n  \\int_\\*0^\\*1 \\bspl{\\*l',\\*i'}{1}(\\*x)\\,\n  \\partialderiv[2d]{\\partialdiff x_1^2 \\dotsm \\partialdiff x_d^2}{\\objfun}(\\*x)\n  \\diff{}\\*x,\n\\end{equation}\nif $\\*l \\ge \\*1$ and\n$\\objfun$ is twice continuously differentiable in every dimension simultaneously,\ni.e.,\n$\\partialderiv[2d]{\\partialdiff x_1^2 \\dotsm \\partialdiff x_d^2}{\\objfun}$\nexists and is continuous.%\n\\footnote{%\n  Again, the notation implies that the integration domain is\n  the unit hyper-cube $\\clint{\\*0, \\*1} = \\clint{0, 1}^d$.%\n}\\multiplefootnoteseparator%\n\\footnote{%\n  The statement is even valid for functions in the Sobolev space\n  $H_\\mathrm{mix}^2(\\clint{\\*0, \\*1})$ with dominating mixed derivative,\n  as its proof mainly relies on integration by parts\n  \\multicite{Bungartz04Sparse,Garcke13Sparse}.%\n}\nConsequently, the contribution of the summand of level $\\*l$\ncan be estimated by\n\\begin{equation}\n  \\label{eq:componentEstimation}\n  \\normLtwoscaled{\n    \\sum_{\\*i' \\in \\hiset{\\*l'}}\n    \\surplus{\\*l',\\*i'} \\bspl{\\*l',\\*i'}{1}\n  }\n  \\le 3^{-d} \\cdot 2^{-2 \\normone{\\*l}} \\cdot\n  \\normLtwoscaled{\n    \\partialderiv[2d]{\\partialdiff x_1^2 \\dotsm \\partialdiff x_d^2}{\\objfun}\n  }\n\\end{equation}\nfor the hat function surpluses $\\surplus{\\*l',\\*i'}$\n\\multicite{Bungartz04Sparse,Garcke13Sparse}.\n\n\\paragraph{Definition of regular sparse grids}\n\nEquation \\eqref{eq:componentEstimation} motivates to omit those summands\nfrom the sum \\eqref{eq:interpHierFullGrid} whose level sum $\\normone{\\*l}$\nexceeds a certain value $n \\in \\natz$,\nas their contribution can be neglected compared to the summands\nwith coarser level sums.\nMore formally, the selection of the relevant subspaces can be formulated as a\ncontinuous knapsack problem~\\cite{Bungartz04Sparse},\nassuming homogeneous boundary conditions.\n\\usenotation{zzzzs}\nThis motivates\n\\begin{equation}\n  \\label{eq:regularSG}\n  \\regsgspace{n}{d}\n  \\ceq \\bigoplus_{\\normone{\\*l} \\le n} \\hs{\\*l},\\qquad\n  \\regsgset{n}{d}\n  \\ceq \\bigdotcup_{\\normone{\\*l} \\le n}\n  \\{\\gp{\\*l,\\*i} \\mid \\*i \\in \\hiset{\\*l}\\}\n\\end{equation}\nas the definitions for the \\term{regular sparse grid space} and\n\\term{regular sparse grid} of level $n$, respectively.\nThe functions $\\regsgintp{n}{d}$ contained in\n$\\regsgspace{n}{d}$ have the form\n\\begin{equation}\n  \\label{eq:regularSGInterpolant}\n  \\regsgintp{n}{d}\n  = \\sum_{\\normone{\\*l} \\le n} \\sum_{\\*i \\in \\hiset{\\*l}}\n  \\surplus{\\*l,\\*i} \\basis{\\*l,\\*i}.\n\\end{equation}\nTo better distinguish the different grids,\nwe call the grids corresponding to the nodal spaces \\term{full grids.}\nWe generalize the definition to arbitrary bases $\\basis{\\*l,\\*i}$,\nalthough sparse grids have been motivated using the hat function\nbasis $\\bspl{\\*l,\\*i}{1}$\n(the estimate \\eqref{eq:componentEstimation} does not hold anymore\nin the general case).\n\\Cref{fig:regularSG} shows the construction of a\nregular sparse grid in two dimensions.\n\n\\begin{figure}\n  \\subcaptionbox{%\n    Hierarchical splitting and subspace selection.\n    The rectangles indicate the support of the\n    bivariate hat basis functions.%\n  }[85mm]{%\n    \\includegraphics{sg_1}%\n  }%\n  \\hfill%\n  \\begin{minipage}[b]{59mm}\n    \\subcaptionbox{%\n      Full grid obtained by adding all subspaces of level $\\*l \\le n \\cdot \\*1$.%\n    }[59mm]{%\n      \\includegraphics{sg_2}%\n    }\\\\[4mm]%\n    \\subcaptionbox{%\n      Regular sparse grid obtained by adding all subspaces\n      whose level $\\*l$ satisfies $\\normone{\\*l} \\le n$\n      \\emph{\\textcolor{mittelblau}{(blue)}.}%\n    }[59mm]{%\n      \\includegraphics{sg_3}%\n    }%\n  \\end{minipage}%\n  \\caption[%\n    Regular two-dimensional sparse grid%\n  ]{%\n    Regular sparse grid of level $n = 3$ in two dimensions.%\n  }%\n  \\label{fig:regularSG}%\n\\end{figure}\n\n\\paragraph{Grid size and interpolation error}\n\nOne can prove that for homogeneous boundary conditions\n$\\restrictfcn{\\objfun}{\\bndrydomain{\\clint{\\*0,\\*1}}} \\equiv 0$,\nthe number of required inner grid points\n($\\gp{\\*l,\\*i} \\in \\regsgset{n}{d}$ where $\\*l \\ge \\*1$)\ngrows like $\\landauO{\\ms{n}^{-1} (\\log_2 \\ms{n}^{-1})^{d-1}}$\n\\multicite{Bungartz04Sparse,Garcke13Sparse}, which is much less than\nthe corresponding number $\\landauO{(\\ms{n}^{-1})^d}$ in the full grid case\n(see \\eqref{eq:dimensionFG}).\nThe $\\Ltwo$ error of the sparse grid interpolant\n$\\regsgintp{n}{d} \\in \\regsgspace{n}{d}$ using hat functions\n(still assuming homogeneous boundary conditions) decays like\n\\begin{equation}\n  \\normLtwo{\\objfun - \\regsgintp{n}{d}}\n  = \\landauO{\\ms{n}^2 (\\log_2 \\ms{n}^{-1})^{d-1}},\n\\end{equation}\nwhich is only slightly worse than the full grid error by the factor of\n$(\\log_2 \\ms{n}^{-1})^{d-1}$\n\\multicite{Bungartz04Sparse,Garcke13Sparse}.\n\n\n\n\\subsection{Dimensionally Adaptive Sparse Grids}\n\\label{sec:232dimensionallyAdaptiveSG}\n\nThe idea of dimensional adaptivity is to spend more grid\npoints along specific dimensions depending on the objective function.\nDifferent criteria for the choice of dimensions exist,\nfor example the maximal absolute value of the linear hierarchical surpluses.\nTo incorporate dimensional adaptivity into sparse grids,\none has to generalize the symmetric\nchoice of subspaces in the definition of regular sparse grids\nto allow asymmetric preferences.\nGenerally, function spaces~$\\sgspace$ and grid sets $\\sgset$\nof \\term{dimensionally adaptive sparse grids} have the form\n\\begin{equation}\n  \\label{eq:dimensionallyAdaptiveSG}\n  \\sgspace\n  = \\bigoplus_{\\*l \\in \\levelset} \\hs{\\*l},\\qquad\n  \\sgset\n  = \\bigdotcup_{\\*l \\in \\levelset} \\{\\gp{\\*l,\\*i} \\mid \\*i \\in \\hiset{\\*l}\\},\n\\end{equation}\nwhere $\\levelset$ is a \\term{downward closed} set, i.e.,\na finite subset $\\levelset \\subset \\natz^d$\nfor which $\\fafa{\\*l \\in \\levelset}{\\*l' \\le \\*l}{\\*l' \\in \\levelset}$.\nRegular sparse grids are a special case by setting\n$\\levelset = \\{\\*l \\in \\natz^d \\mid \\normone{\\*l} \\le n\\}$.\n\n\\paragraph{Combination technique}\n\nThe key advantage of dimensionally adaptive sparse grids over\nspatially adaptive approaches is the\nso-called \\term{combination technique.}\nFor regular sparse grids, one can show that the sparse grid interpolant\n$\\regsgintp{n}{d}$ can be written as\n\\begin{equation}\n  \\label{eq:combiTechnique}\n  \\regsgintp{n}{d}\n  = \\sum_{q=0}^{d-1} (-1)^q \\binom{d-1}{q} \\sum_{\\normone{\\*l} = n-q}\n  \\sum_{\\*i=\\*0}^{\\*2^\\*l} \\interpcoeff{\\*l,\\*i} \\basis{\\*l,\\*i},\n\\end{equation}\nwhere the $\\interpcoeff{\\*l,\\*i} \\in \\real$ ($\\*i = \\*0, \\dotsc, \\*2^\\*l$)\nare the interpolation coefficients on the full grid\n$\\fgset{\\*l}$ of level~$\\*l$, i.e.,\n$\\fa{\\*i' = \\*0, \\dotsc, \\*2^\\*l}{%\n  \\sum_{\\*i=\\*0}^{\\*2^\\*l} \\interpcoeff{\\*l,\\*i} \\basis{\\*l,\\*i}(\\gp{\\*l,\\*i'})\n  = \\objfun(\\gp{\\*l,\\*i'})%\n}$ \\multicite{Smolyak63Quadrature,Zenger91Sparse}.\nFor general dimensionally adaptive sparse grids, a similar formula exists\n\\cite{Nobile16Adaptive}.\nThe combination formula \\eqref{eq:combiTechnique} splits the\nsparse grid interpolant into a weighted sum of full grid interpolants\n(see \\cref{fig:combinationTechnique}).\nIn applications, each grid can be processed in parallel,\ndrastically speeding up computations like the solution of \\pdes{}\n\\cite{Heene18Massively}.\nIn addition, existing code working on nodal bases does not have to be\nrewritten in terms of implementing hierarchical functions,\nwhich means that the combination technique allows sparse grids to be employed\nin existing software in a minimally invasive way.\n\n\\begin{SCfigure}\n  \\includegraphics{sg_4}%\n  \\caption[%\n    Sparse grid combination technique%\n  ]{%\n    The combination technique combines nodal subspaces in a weighted\n    sum to form a regular sparse grid space of level $n = 3$ in two dimensions.\n    The \\textcolor{C1}{red subspaces} ($q = 1$ in \\eqref{eq:combiTechnique})\n    are subtracted from the sum of the\n    \\textcolor{C4}{green subspaces} ($q = 0$).%\n  }%\n  \\label{fig:combinationTechnique}%\n\\end{SCfigure}\n\n\n\n\\subsection{Spatially Adaptive Sparse Grids}\n\\label{sec:233spatiallyAdaptiveSG}\n\nDimensional adaptivity does not suffice to resolve local features of the\nobjective function.\nEspecially in some applications, it is crucial for the\ninterpolant to be highly accurate in specific regions of the domain.\nFor instance in optimization, it is not necessary to have a small global\ninterpolation error.\nInstead, high accuracy near the optima is important.\n\nThis can be achieved by \\term{spatially adaptive sparse grids,}\non which this thesis focuses.\nGenerally, their function spaces $\\sgspace$\nand grid sets $\\sgset$ have the form\n\\begin{equation}\n  \\label{eq:spatiallyAdaptiveSG}\n  \\sgspace\n  = \\spn\\{\\basis{\\*l,\\*i} \\mid (\\*l,\\*i) \\in \\liset\\},\\qquad\n  \\sgset\n  = \\{\\gp{\\*l,\\*i} \\mid (\\*l,\\*i) \\in \\liset\\},\n\\end{equation}\nwhere $\\liset$ is a finite set of level-index pairs $(\\*l,\\*i)$\nwith $\\*l \\in \\natz^d$ and $\\*i \\in \\hiset{\\*l}$.\nAn example for a spatially adaptive sparse grid is shown in\n\\cref{fig:spatiallyAdaptiveSG}.\n\n\\begin{figure}\n  \\subcaptionbox{%\n    Hierarchical splitting and grid point selection.\n    The rectangles indicate again the support of the\n    bivariate hat basis functions.%\n  }[85mm]{%\n    \\includegraphics{sg_5}%\n    \\hspace*{1.411224mm}%\n  }%\n  \\hfill%\n  \\subcaptionbox{%\n    Resulting spatially adaptive sparse grid.%\n  }[59mm]{%\n    \\includegraphics{sg_6}%\n  }%\n  \\caption[%\n    Construction of spatially adaptive sparse grids%\n  ]{%\n    Spatially adaptive sparse grid in two dimensions.\n    More grid points were generated in the top right corner,\n    which can help to resolve fine oscillations of the objective function.%\n  }%\n  \\label{fig:spatiallyAdaptiveSG}%\n\\end{figure}\n\nAlgorithms for sparse grids often make specific assumptions about $\\liset$.\nIf they are not met, then the algorithms do not produce the correct results.\nFor example when working with hat functions $\\bspl{\\*l,\\*i}{1}$,\nthe grid should contain the hierarchical ancestors of every grid point.\nOtherwise, the so-called unidirectional principle \\cite{Balder94Adaptive},\nwhich is used for instance to efficiently calculate\nhierarchical surpluses, does not hold in general.\nHowever, as we will see in \\cref{chap:40algorithms},\nthe unidirectional principle cannot be applied\nto B-splines of general degree, even if the hierarchical ancestors exist.\nHence, for most of our considerations, we will not restrict the\nchoice of $\\liset$.\n", "meta": {"hexsha": "51ce2de8b1e3c0c88e46aa5736995b51af7465dd", "size": 11624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/23sparseGrids.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/23sparseGrids.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/23sparseGrids.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.6181229773, "max_line_length": 97, "alphanum_fraction": 0.7118891948, "num_tokens": 3694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6665132682107303}}
{"text": "\\section{Matrix Completion, Imputation}\nImputation or Matrix completion problems deal with missing observations. The most famous application is probably the Netflix prize, in which a very large, very sparse data matrix encodes the preferences of Netflix users. Missing entries correspond to the case where it is not known what a certain user might think of a movie.\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=0.7\\textwidth]{impute_05.png}\n    \\caption{Results for different imputation methods reconstructing the image of the man rumored to be Bayes himself after 50\\% of the pixels are removed.}\n    \\label{fig:impute_05}\n\\end{figure}\n\n\n\\subsection{Nuclear Norm Regularization}\nGiven a matrix $\\mathbf{X}\\in\\mathbb{R}^{m\\times n}$, in which observed entries are indexed by the set $\\Omega = \\{(i,j) : X_{i,j}\\mathrm{\\ is\\ observed.} \\}$\\cite{hastie2015matrix}. Define the projection $P_{\\Omega}(\\mathbf{X}) \\in \\mathbb{R}^{m\\times n}$ to be the matrix so that $P_{i,j} = X_{i,j}\\ \\forall\\ (i,j) \\in \\Omega$ and $P_{i,j} = 0\\ \\mathrm{if\\ }(i,j)\\notin\\Omega$, which is to say: take the matrix $\\mathbf{X}$ and set all the unobserved entries to $0$. \n\nNuclear norm regularization corresponds to expressing completing $\\mathbf{X}$ in terms of the convex optimization problem:\n\n\\begin{equation}\n\\argmin_{\\mathbf{M}} H(\\mathbf{M}) = \\frac{1}{2}||P_{\\Omega}(\\mathbf{X-M})||^2_F + \\lambda ||\\mathbf{M}||_{*}\n\\end{equation}\n\nWhere $||\\cdot||_{*}$ is the nuclear norm of $\\mathbf{M}$ (cf. section \\ref{sec:nuclearnorm}). The loss function is a tradeoff between accurately reproducing $\\mathbf{X}$ and doing so with as low a rank as possible. Except, using the rank of $\\mathbf{M}$ would make the optimization non-convex, so instead the nuclear norm is used, which is the sum of the singular values. Solving this problem is computationally still quite expensive, but is a lot of work on solving this problem for large datasets, for example \\texttt{softImpute}, texttt{softImpute+}, which use soft-singular value thresholding that amounts to leveraging lower-rank representations of the data \\cite{mazumder2010spectral}.", "meta": {"hexsha": "0566168451a0dfc2dc37aba0a11fde649f128a8f", "size": 2119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/unsup_matrixcompletion.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/unsup_matrixcompletion.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/unsup_matrixcompletion.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": 100.9047619048, "max_line_length": 692, "alphanum_fraction": 0.7461066541, "num_tokens": 595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673269042768, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6664645078879791}}
{"text": "\\chapter{Deductive Calculus of First Order Logic}\n\n\\section{Deductive Calculus}\n\nProofs are (purely) syntactic constructs that caputre \\emph{derivability of facts}. Deductive calculi provide descriptions of proofs in logic. There are more than one forms for deductive calculi.\n\nWe adopt the Hilbert-style deductive calculus, which contains\n\n\\begin{itemize}\n    \\item A set $\\Lambda$ of wffs called \\textbf{logical axioms}\n    \\item A \\emph{single} \\textbf{rule of inference} for forming a new wff from a pair of wffs\n\\end{itemize}\n\nWe then systematically generate a set of wffs from the axioms by using the rules of inference. They are called \\textbf{derivable} wffs.\n\nAnother deductive calculus is called the natural calculus, which has many rules of inference and one single axiom (\\emph{“排中律”}, that a proposition is either True or False).\n\nYet another deductive calculus is called the sequent calculus, which contains no axiom and a set of symmetric rules.\n\n\\subsection{Introduction to Soundness and Completeness}\n\nThe goal is to prove that for any language $\\mathbb{L}$, the following are equivalent\n\n\\begin{itemize}\n    \\item The set of derivable wffs in $\\mathbb{L}$\n    \\item The set of valid wffs in $\\mathbb{L}$\n\\end{itemize}\n\nThis is done by proving the soundness and completeness\n\n\\begin{theorem}[Soundness]\n    \\label{thm:FOSoundness}\n    Every derivable of wff is valid.\n\\end{theorem}\n\n\\begin{theorem}[Completeness]\n    \\label{thm:FOCompleteness}\n    Every valid wff is derivable.\n\\end{theorem}\n\n\\section{Logical Axioms}\n\n\\begin{definition}[Generalization]\n    A \\textbf{generalization} of the wff $\\alpha$ is any wff obtained by putting zero or more universal quantifiers in front of $\\alpha$\n\\end{definition}\n\nFor example, $\\forall x\\forall y\\forall y\\alpha$ is a generalization of $\\alpha$.\n\nNote that every wff is a generalization of itself.\n\n\\begin{definition}[Axioms]\n    Let $\\mathbb{L}$ be a first-order language. The set $\\Lambda$ of logical axioms of $\\mathbb{L}$ consists of all generalizations of the wffs in the following groups\n    \\begin{axiom}\n        \\label{axiom:InstanceOfTautology}\n        Instances of tautologies.\n    \\end{axiom}\n    \\begin{axiom}\n        \\label{axiom:Substitution}\n        Wffs of the form $\\forall x\\alpha \\to \\alpha_t^x$ such that the term $t$ is \\textbf{substitutable} for $x$ in $\\alpha$. As a special case, $\\forall x\\alpha \\to \\alpha$, where we replace $x$ with $t=x$\n    \\end{axiom}\n    \\begin{axiom}\n        \\label{axiom:PushUniversalIntoImplication}\n        Wffs of the form $\\forall x(\\alpha\\to\\beta) \\to (\\forall x \\alpha\\to \\forall x \\beta)$.\n    \\end{axiom}\n    \\begin{axiom}\n        \\label{axiom:QuantifyBoundedVar}\n        Wffs of the form $\\alpha\\to\\forall x \\alpha$ if $x$ \\emph{does not occur free} in $\\alpha$\n    \\end{axiom}\n    \\begin{axiom}\n        \\label{axiom:Equality}\n        Wffs of the form $x \\doteq x$\n    \\end{axiom}\n    \\begin{axiom}\n        \\label{axiom:EqualitySubstitution}\n        Wffs of the form $x \\doteq y \\to (\\alpha \\to \\alpha')$ where $\\alpha$ is atomic and $\\alpha'$ is obtained from $\\alpha$ by replacing zero or more free occurrences of $x$ in $\\alpha$ by $y$\n    \\end{axiom}\n\\end{definition}\n\n\\begin{lemma}\n    A wff $\\varphi$ is valid $\\iff$ $\\forall{x}\\varphi$ is valid.\n\\end{lemma}\n\nFor example,\n\n\\begin{itemize}\n    \\item $\\alpha=Py$, $Py \\to \\forall x Py$ is an instance of Axiom \\ref{axiom:QuantifyBoundedVar}\n    \\item $\\alpha=Py$, $\\forall y(Py\\to \\forall xPy)$ is a \\emph{generalization} of instance of Axiom \\ref{axiom:QuantifyBoundedVar}\n    \\item $\\alpha = Px$, $x \\doteq y \\to Px\\to Py$ is an instance of Axiom \\ref{axiom:EqualitySubstitution}\n    \\item $\\alpha = Px$, $x \\doteq y \\to Px \\to Px$ is also an instance of Axiom \\ref{axiom:EqualitySubstitution} because zero or more $x$ can be substituted\n    \\item $\\alpha = Qxx$, $x\\doteq y \\to Qxx \\to Qxy$ is also an instance of Axiom~\\ref{axiom:EqualitySubstitution}\n\\end{itemize}\n\nDespite being axioms, we can prove the validity of some of these axioms. We detail the proof of \\ref{axiom:InstanceOfTautology} and \\ref{axiom:Substitution}. Proof of others are trivial.\n\n\\subsection{Instance of Tautologies}\n\nIn this section we show the validity of Axiom~\\ref{axiom:InstanceOfTautology}.\n\n\\begin{definition}[Instance of WFFs of Sentential Logic]\n    Let $\\alpha_1,\\dots,\\alpha_n,\\dots$ be an infinite sequence of wffs of the first-order language of $\\mathbb{L}$, $\\varphi$ be a wff of sentential logic with junst the connectives $\\to$ and $\\neg$, $\\varphi^\\ast$ be the wff of $\\mathbb{L}$ obtained by replacing every occurrence of the sentence symbol $A_n$ in $\\varphi$ by $\\alpha_n$ for each $m$. We say that $\\varphi^\\ast$ is an \\textbf{instance} of $\\varphi$\n\\end{definition}\n\nFor example, let $\\varphi=A_1\\to A_3$, $\\varphi^\\ast = \\alpha_1 \\to \\alpha_3$ is an instance of $\\varphi$.\n\n\\begin{definition}[Instance of Tautologies]\n    For any tautologies $\\varphi$ in the sentential logic, $\\varphi^\\ast$ is an instance of the tautology $\\varphi$\n\\end{definition}\n\n\\begin{lemma}\n    Given a structure $\\frakA$ for language $\\mathbb{L}$,\n    \\begin{itemize}\n        \\item $s$ be an assignment function\n        \\item $\\varphi$ be a wff of sentential logic\n        \\item $\\varphi^\\ast$ be the instance of $\\varphi$\n        \\item $v$ be the truth assignment such that\n        \\[ v(A_i) = T \\iff \\sat{A}{\\alpha_i}{s} \\]\n    \\end{itemize}\n    Then\n    \\[ \\bar{v}(\\varphi) = T \\iff \\sat{A}{\\varphi^\\ast}{s} \\]\n\\end{lemma}\n\\begin{proof}\n    Prove by induction.\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} $\\varphi = A_i$ follows immediately from the assumption that $v(A_i) = T \\iff \\sat{A}{\\alpha_i}{s}$\n        \\item[] \\textbf{Inductive.} \\begin{enumerate}\n            \\item $\\varphi = \\neg \\beta$.\n            \\begin{itemize}\n                \\item[] $\\bar{v}(\\neg\\beta) = T \\iff \\sat{A}{(\\neg\\beta)^\\ast}{s}$\n                \\item[$\\equiv$] $\\bar{v}(\\beta) = F \\iff \\unsat{A}{\\beta^\\ast}{s}$ \n                \\item[$\\equiv$] $\\bar{\\beta} = T \\iff \\sat{A}{\\beta^\\ast}{s}$\n            \\end{itemize}\n            \\item $\\varphi = \\gamma \\to \\beta$\n            \\begin{itemize}\n                \\item[] $\\bar{v}(\\gamma\\to\\beta) = T \\iff \\sat{A}{\\gamma\\to\\beta}{s}$\n                \\item[$\\equiv$] If $\\bar{v}(\\gamma) = T$ then $\\bar{v}(\\beta) = T$ $\\iff$ If $\\sat{A}{\\gamma}{s}$ then $\\sat{A}{\\beta}{s}$ \n            \\end{itemize}\n        \\end{enumerate}\n    \\end{itemize}\n\\end{proof}\n\n\\begin{corollary}\n    Every instance of a tautology is valid.\n\\end{corollary}\n\n\\subsection{Substitutions}\n\n\\begin{definition}[Substitution for Terms]\n    Let $u$ be a term, $x$ be a variable, and $t$ be a term. $u_t^x$ is the result of replacing every occurrence of $x$ in $u$ by $t$\n\\end{definition}\n\n\\begin{definition}[Substitution for Formulas]\n    For a wff $\\alpha$, a variable $x$, let $\\alpha_t^x$ be the result of replacing every free occurence of $x$ in $\\alpha$ by $t$,\n\n    \\begin{itemize}\n        \\item If $\\alpha$ is atomic. $\\alpha = Pu_1,\\dots,u_n$, then $\\alpha_t^x = Pu_{1t}^x,\\dots,u_{nt}^x$\n        \\item If $\\alpha = \\neg \\beta$, then $\\alpha_t^x = \\neg\\beta_t^x$\n        \\item if $\\alpha = \\beta\\to\\gamma$, then $\\alpha_t^x = \\beta_t^x \\to \\gamma_t^x$\n        \\item If $\\alpha = \\forall y \\beta$, then $\\alpha_t^x = \\alpha$ if $y=x$, and $\\alpha_t^x = \\forall y \\beta_t^x$\n    \\end{itemize}\n\\end{definition}\n\nNow we return to Axiom~\\ref{axiom:Substitution}. Is every $\\forall x \\alpha \\to \\alpha_t^x$ valid?\n\nOf course the answer is ``No'', or otherwise we would not have required that $t$ is \\emph{substitutable} for $x$ in $\\alpha$.\n\nTo see this, let $\\alpha = \\exists y x\\neq y$, $t=y$, then\n\n\\[ \\forall x \\exists y x\\neq y \\to \\exists y y\\neq y \\]\n\nwhich is obviously not valid.\n\nThe problem here is that by this substitution we made $x$ ``local/bounded'' (\\emph{capture of free variables}), and the new formula is semantically different from the original one.\n\n\\begin{definition}[Substitutability]\n    Let $\\alpha$ be a wff, $x$ be a variable, and $t$ be a term. $t$ is substitutable for $x$ in $\\alpha$ if\n    \\begin{itemize}\n        \\item $\\alpha$ is atomic\n        \\item $\\alpha = \\neg\\beta$ and $t$ is substitutable for $x$ in $\\beta$.\n        \\item $\\alpha = \\beta \\to \\gamma$ and $t$ is substitutable for $x$ in $\\beta$ and $\\gamma$\n        \\item $\\alpha = \\forall y \\beta$ and\n        \\begin{itemize}\n            \\item either $x$ does not occur free in $\\forall y \\beta$\n            \\item or $x$ occurs free in $\\forall y\\beta$ (which implies $x\\neg y$), and $t$ is substitutable for $x$ in $\\beta$, and $y$ does not occur in $t$\n        \\end{itemize}\n    \\end{itemize}\n\\end{definition}\n\nWe can check this with our previous example $\\alpha = \\exists y x\\neq y$, $t=y$. $\\alpha = \\neg\\forall y (\\neg x \\neq y)$. Notice that $y$ ocurrs in $t$ ($t=y$), therefore $y$ is not substitutable for $x$ in $\\alpha$.\n\n\\subsubsection{Substitution Lemma}\n\n\\begin{lemma}\n    Given a first-order language $\\mathbb{L}$, let $\\frakA$ be a structure for $\\mathbb{L}$, $s$ be an assignment for $\\frakA$, $u$ and $t$ be two terms and $x$ be a variable. Then\n    \\[ \\bar{s}(u_t^x) = \\overline{s(x|\\bar{s}(t))}(u) \\]\n\\end{lemma}\n\nThis looks very intuitive. It just states that the assignment for substitution is equal to first changing the assignment function and then apply the assignment on original term.\n\n\\begin{proof}\n    Prove by induction.\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} (1) If $u = c$, trivial. (2) If $u=x$, then LHS would be $\\bar{s}(t)$, RHS would also be $\\bar{s}(t)$. (3) $u=y\\neq x$, then LHS and RHS will both be $\\bar{s}(y)$.\n        \\item[] \\textbf{Inductive.} If $u = ft_1\\dots t_n$.\n        \\[ \\bar{s}(u_t^x) = \\bar{s}(ft_{1t}^x\\dots f(t_{nt}^x)) = f(\\bar{s}(t_{1t}^x\\dots t_{nt}^x)) \\]\n        which can be shown equal to RHS by applying inductive hypothesis\n    \\end{itemize}\n\\end{proof}\n\n\\begin{lemma}[Substitution Lemma]\n    \\label{lem:SubstitutionLemma}\n    Let $s$ be an assignment function for $\\frakA$. If $t$ is substitutable for $x$ in $\\alpha$, then\n    \\[ \\sat{A}{\\alpha_t^x}{s} \\iff \\sat{A}{\\alpha}{s(x|\\bar{s}(t))} \\]\n\\end{lemma}\n\\begin{proof}\n    Prove by induction on $\\alpha$.\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} $\\alpha = Pt_1\\dots t_n$\n        \\begin{itemize}\n            \\item[] $\\sat{A}{(Pt_1\\dots t_n)}{s}$\n            \\item[$\\iff$] $\\sat{A}{Pt_{1t}^x\\dots t_{nt}^x}{s}$ \n            \\item[$\\iff$] $(\\bar{s}(t_{1t}^x),\\dots,\\bar{s}(t_{nt}^x)) \\in P^\\frakA$\n            \\item[$\\iff$] $(\\bar{s'}(t_1),\\dots,\\bar{s'}(t_n)) \\in P^\\frakA$\n            \\item[$\\iff$] $\\sat{A}{\\alpha}{s(x|\\bar{s}(t))}$\n        \\end{itemize}\n        \\item[] \\textbf{Inductive.} \\begin{enumerate}\n            \\item  $\\alpha = \\neg \\beta$\n            \\begin{itemize}\n                \\item[] $\\sat{A}{\\neg \\beta_t^x}{s}$\n                \\item[$\\iff$] $\\unsat{A}{\\beta_t^x}{s}$\n                \\item[$\\iff$] $\\unsat{A}{\\beta}{s'}$\n                \\item[$\\iff$] $\\sat{A}{\\neg\\beta}{s'}$\n            \\end{itemize}\n            \\item $\\alpha = \\beta \\to \\gamma$. Similar.\n            \\item $\\alpha = \\forall y \\beta$.\n            \\begin{itemize}\n                \\item[] $\\sat{A}{\\forall y \\beta_t^x}{s}$\n                \\item[$\\iff$] For any $d \\in |\\frakA|$, $\\sat{A}{\\beta_t^x}{s(y|d)}$\n                \\item[] $\\sat{A}{\\forall y\\beta}{s'}$\n                \\item[$\\iff$] For any $d \\in |\\frakA|$, $\\sat{A}{\\beta}{s(x|\\bar{s}(t))(y|d)}$\n                \\item[] Since $y \\neq x$, we can exchange the order of assignment overwriting\n                \\item[] For any $d \\in |\\frakA|$, $\\sat{A}{\\beta}{s(y|d)(x|\\bar{s}(t))}$. For brevity denote $s(y|d)$ by $s''$. By induction hypothesis, we have $\\sat{A}{\\beta_t^x}{s''} \\iff \\sat{A}{\\beta}{s''(x|\\bar{s}''(t))}$. And by Substitutability, we have $\\bar{s}''(t) = \\bar{s}(t)$. Then we have proved the lemma.\n            \\end{itemize}\n        \\end{enumerate} \n    \\end{itemize}\n\\end{proof}\n\n\\subsubsection{Validity of Axiom~\\ref{axiom:Substitution}}\n\n\\begin{theorem}\n    If $t$ is substitutable for $x$ in $\\alpha$, then $\\forall \\alpha \\to \\alpha_t^x$ is valid.\n\\end{theorem}\n\\begin{proof}\n    If $\\sat{A}{\\forall x \\alpha}{s}$, since $s(x|\\bar{s}(t))$ is an instance of ``for all $x$'', it holds that $\\sat{A}{\\alpha}{s(x|\\bar{s}(t))}$. Then by the Substitution Lemma~\\ref{lem:SubstitutionLemma}, we have $\\sat{A}{\\alpha_t^x}{s}$.\n\\end{proof}\n\nNow we have proved that every member in the set of axioms $\\Lambda$ is valid.\n\n\\section{Deductions}\n\n\\subsection{Rule of Inference}\n\n\\begin{definition}[Modus Ponens]\n    Given any wffs $\\alpha$ and $\\beta$, the rule of \\textbf{modus ponens} provides the operation for deriving $\\beta$ from $\\alpha\\to\\beta$ and $\\alpha$.\n\\end{definition}\n\n\\subsection{Deduction}\n\n\\begin{definition}[Deduction]\n    Let $\\Gamma$ be a set of wffs of $\\mathbb{L}$. A \\textbf{deduction from $\\Gamma$} is a finite sequence\n    \\[ \\alpha_0,\\dots,\\alpha_n \\]\n    of wffs such that for every $\\alpha_i$, at least one of the following holds\n    \\begin{itemize}\n        \\item $\\alpha\\in\\Gamma$\n        \\item $\\alpha\\in\\Lambda$\n        \\item $\\alpha$ is inferred by modus ponens from two wffs $\\alpha_j$ and $\\alpha_k$ s.t. $j,k < i$.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}\n    $\\Gamma\\vdash\\alpha$ ($\\alpha$ is a theorem of $\\Gamma$) if there is a deduction $\\alpha_0,\\dots,\\alpha_n$ from $\\Gamma$ s.t. $\\alpha=\\alpha_n$.\n\n    We write $\\vdash\\alpha$ for $\\emptyset\\vdash\\alpha$\n\\end{definition}\n\nNotice that deduction is purely based on symtax, and the logical implications we have learned before requires semantics.\n\nAs an example, we show that $\\vdash Px \\to \\exists yPy$. Since $\\Gamma = \\emptyset$, we can only derive the conclusion from the axioms and modus ponens.\n\n\\[ Px \\to \\exists yPy \\iff Px \\to \\neg\\forall y \\neg Py \\]\n\n$\\forall y \\neg Py \\to \\neg x$ is in axiom group~\\ref{axiom:Substitution}. Further, $(\\forall y \\neg Py \\to \\neg x) \\to (Px \\to \\neg \\forall y \\neg Py)$ is an instance of tautology $(A_1 \\to \\neg A_2) \\to (A_2 \\to \\neg A_1)$. We can then finish the proof by applying modus ponens.\n\nThe proof can be formatted into a tree. But I cannot draw it so please refer to slides. A key problem is that few human beings (if any) is able to prove things like this, as it gradually ``factorizes'' the target wffs into members in $\\Gamma$ or $\\Lambda$. Fortunately we will later see some more helper rules to help normal people prove theorems in first-order logic.\n\n\\subsection{Properties of Deductions}\n\n\\begin{itemize}\n    \\item If $\\Gamma\\vdash\\varphi$, then there must be a finite subset $\\Delta$ of $\\Gamma$ s.t. $\\Gamma\\vdash\\varphi$. This is guaranteed by definition of deduction: it is finite.\n    \\item If $\\alpha_1,\\dots,\\alpha_n$ is a deduction from $\\Gamma$ and $\\beta_1,\\dots,\\beta_m$ is a deduction from $\\Gamma$, then $\\alpha_1,\\dots,\\alpha_n,\\beta_1,\\dots,\\beta_m$ is also a deduction from $\\Gamma$\n    \\item If $\\varphi\\in\\Gamma$ then $\\Gamma\\vdash\\varphi$\n    \\item If $\\Gamma\\vdash\\varphi$ and $\\Gamma\\subseteq\\Delta$ then $\\Delta\\vdash\\varphi$\n    \\item If $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\alpha\\to\\beta$, then $\\Gamma\\vdash\\beta$\n    \\item (Cut Rule) If $\\Gamma\\vdash\\alpha$ and $\\alpha\\to\\beta$, then $\\Gamma\\vdash\\beta$. This property allows proving some theorem $\\beta$ by one or more lemmas $\\alpha$\n    \\item If $\\Gamma\\to\\alpha$ then for any $\\beta$, $\\Gamma\\vdash\\beta\\to\\alpha$. Notice that $\\alpha\\to\\left( \\beta\\to\\alpha \\right)$ is an instance of tautology.\n    \\item If $\\Gamma\\vdash\\alpha\\wedge\\beta$, then $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\beta$. Notice that $\\alpha\\wedge\\beta = \\neg\\left( \\alpha\\to\\neg\\beta \\right)$, and that $\\neg\\left( \\alpha\\to\\neg\\beta \\right) \\to \\alpha$ (or $\\beta$) are two instances of tautologies.\n    \\item If $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\beta$ then $\\Gamma\\vdash\\alpha\\wedge\\beta$\n    \\item If $\\Gamma\\vdash\\alpha$ or $\\Gamma\\vdash\\beta$ then $\\Gamma\\vdash\\alpha\\vee\\beta$\n    \\item If $\\Gamma\\vdash\\alpha\\to\\beta$ then $\\Gamma;\\alpha\\to\\beta$\n\\end{itemize}\n\n\\subsection{Relations between Tautologies and Derivations}\n\n\\begin{definition}\n    In first-order logic, a set of wffs $\\Gamma$ \\textbf{tautologically implies} $\\varphi$ if there is a wff $\\alpha$ and a set $\\Sigma$ of wffs in the sentential logic such that for some $*$ of $\\mathbb{L}$\n    \\begin{itemize}\n        \\item For every $\\beta\\in\\Sigma$, $\\beta^*\\in\\Gamma$\n        \\item $\\varphi=\\alpha^*$\n        \\item $\\Sigma$ tautologically implies $\\alpha$ in the sentential logic ($\\Sigma\\vDash\\alpha$)\n    \\end{itemize}\n\\end{definition}\n\n\\begin{lemma}\n    $\\Gamma\\vdash\\varphi$ iff $\\Gamma\\cup\\Lambda$ tautologically implies $\\varphi$\n\\end{lemma}\n\n\\begin{lemma}[Rule T (Enderton)]\n    \\label{lem:RuleT}\n    If $\\Gamma\\vdash\\alpha_1,\\dots,\\Gamma\\vdash\\alpha_n$ and $\\{\\alpha_1,\\dots,\\alpha_n\\}$ tautologically implies $\\beta$ then $\\Gamma\\vdash\\beta$\n\\end{lemma}\n\n\\section{Deduction Theorem and Generalization Theorem}\n\n\\subsection{The Deduction Theorem}\n\n\\begin{theorem}[Deduction Theorem]\n    \\label{thm:DeductionTheorem}\n    If $\\Gamma;\\alpha\\to\\beta$, then $\\Gamma\\vdash\\alpha\\to\\beta$\n\\end{theorem}\n\\begin{proof}\n    By induction on $\\Gamma;\\alpha\\to\\beta$.\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} If $\\beta\\in\\Lambda$, then\n        \\[ \\vdash\\beta \\Rightarrow \\vdash \\alpha\\to\\beta \\Rightarrow \\Gamma\\vdash\\alpha\\to\\beta \\]\n        If $\\beta\\in\\Gamma$, then\n        \\[ \\Gamma\\vdash\\beta \\Rightarrow \\Gamma\\vdash\\alpha\\to\\beta \\]\n        If $\\beta=\\alpha$, then it is an instance of tautology so it is in $\\Lambda$\n        \\item[] \\textbf{Inductive.} If $\\Gamma;\\alpha\\vdash\\gamma\\to\\beta$ and $\\Gamma;\\alpha\\vdash\\gamma$. By IH, $\\Gamma\\vdash\\alpha\\to(\\gamma\\to\\beta)$ and $\\Gamma\\vdash\\alpha\\to\\gamma$. Notice that $\\{ \\alpha\\to(\\gamma\\to\\beta), \\alpha\\to\\gamma \\}$ tautologically imply $\\alpha\\to\\beta$. Then we apply ``Rule T''~\\ref{lem:RuleT}.\n    \\end{itemize}\n\\end{proof}\n\n\\subsubsection{Contraposition}\n\n\\emph{Contraposition} is a corollary of the deduction theorem\n\n\\begin{theorem}[Contraposition]\n    $\\Gamma;\\varphi\\vdash\\neg\\psi$ iff $\\Gamma;\\psi\\vdash\\neg\\varphi$\n\\end{theorem}\n\\begin{proof}\n    \\begin{itemize}\n        \\item[$\\Rightarrow$] If $\\Gamma;\\varphi\\vdash\\neg\\psi$, then by Deduction Theorem~\\ref{thm:DeductionTheorem}, $\\Gamma\\vdash\\varphi\\to\\neg\\psi$. Notice that $\\left( \\varphi\\to\\neg\\psi \\right) \\to \\left( \\psi\\to\\neg\\varphi \\right)$ is an instance of tautological implication in sentential logic. Therefore by Rule T~\\ref{lem:RuleT} $\\Gamma\\vdash\\psi\\to\\neg\\varphi$, and $\\Gamma;\\psi\\to\\neg\\varphi$. The converse is similar\n    \\end{itemize}\n\\end{proof}\n\n\\subsection{The Generalization Theorem}\n\n\\begin{theorem}[Generalization Theorem]\n    \\label{thm:GeneralizationTheorem}\n    If $\\Gamma\\vdash\\varphi$ and $x$ does not occur free in any member of $\\Gamma$ then $\\Gamma\\vdash\\forall x \\varphi$\n\\end{theorem}\n\\begin{proof}\n    By induction on $\\varphi$\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} If $\\varphi\\in\\Gamma$, then $x$ does not occur free in $\\varphi$. Notice that we have $\\varphi\\to\\forall x \\varphi \\in \\Lambda$ (axiom~\\ref{axiom:QuantifyBoundedVar}), and we have $\\varphi\\in\\Gamma$, by modus ponens we have $\\forall x \\varphi$.\n        \n        If $\\varphi\\in\\Lambda$, $\\forall x\\varphi$ is a generalization of $\\varphi$.\n        \\item[] \\textbf{Inductive.} $\\Gamma\\vdash\\gamma\\to\\varphi$; $\\Gamma\\vdash\\gamma$. By inductive hypothesis, $\\Gamma\\to\\forall x(\\gamma\\to\\varphi)$, and $\\Gamma\\vdash\\forall x \\gamma$. Notice that $\\forall x(\\gamma\\to\\varphi) \\to \\forall x \\gamma\\to\\forall x\\varphi$ (axiom~\\ref{axiom:PushUniversalIntoImplication}).\n    \\end{itemize}\n\\end{proof}\n\nThe Deduction Theorem and the Generalization Theorem are ``meta-theorem''s that applies to deductive calculi. In Hilbert-style Calculus, we use the six logical axioms to derive these meta-theorems. In other calculi, they may use other axioms, or directly use these meta-theorems.\n\n\\subsubsection{Generalization on Constants}\n\n\\begin{theorem}\n    \\label{thm:GeneralizationOnConsts}\n    If $\\Gamma\\vdash\\varphi$ and $c$ is a constant symbol that is not in any member of $\\Gamma$, then there is some variable $y$ not in $\\varphi$ s.t. $\\Gamma\\vdash\\forall y \\varphi_y^c$ ($c$ replaced by $y$).\n\n    Furthermore, there is a deduction of $\\forall y \\varphi_y^c$ from $\\Gamma$ in which $c$ does not occur.\n\\end{theorem}\n\nIntuitively, if $\\varphi$ can be derived from $\\Gamma$, then the constant $c$ in $y$ is somewhat like a quantified variable $y$.\n\n\\begin{proof}\n    Since $\\Gamma\\vdash\\varphi$, we have a deduction\n    \\[ \\varphi_0,\\varphi_1,\\dots,\\varphi_n \\]\n    s.t. $\\varphi_n=\\varphi$.\n\n    We first show by induction (on deduction $\\Gamma\\vdash\\varphi_i$) that\n    \\[ \\varphi_{0y}^c,\\dots,\\varphi_{ny}^c \\]\n    is a deduction from $\\Gamma$.\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} If $\\varphi_i \\in \\Gamma$, since $c$ does not occur in members of $\\Gamma$, we have $\\varphi_{iy}^c = \\varphi_i$. Then $\\Gamma\\vdash\\varphi_{iy}^c$. If $\\varphi_i\\in\\Lambda$, it can be verified by checking all 6 axioms.\n        \\item[] \\textbf{Inductive.} If $\\varphi_j = \\varphi_k\\to\\varphi_i$, $\\varphi_k$, $k,j < i$. By IH, $\\Gamma\\vdash\\varphi_{ky}^c \\to \\varphi_{iy}^c$ and $\\Gamma\\vdash\\varphi_{ky}^c$. We are done by Modus Ponens\n    \\end{itemize}\n\n    We have shown so far that $\\Gamma\\vdash\\varphi_y^c$ and $y$ does not occur in $\\varphi$ (and the finite deduction sequence $\\Delta$ that derives $\\varphi$). Therefore we have $\\Gamma\\vdash\\forall y \\varphi_y^c$\n\n    It also follows from this proof that the deduction does not contain $c$\n\\end{proof}\n\n\\begin{corollary}[Corollary 24G]\n    \\label{coroll:Corollary24G}\n    If $\\Gamma\\vdash\\varphi_c^x$, and $c$ is a constant symbol that is not in $\\varphi$ or any member of $\\Gamma$, then $\\Gamma\\vdash\\varphi$\n\\end{corollary}\n\n\\begin{corollary}[Rule El]\n    If $\\Gamma;\\varphi_c^x\\vdash\\psi$ and $c$ does not occur in $\\varphi,\\psi,\\Gamma$, then $\\Gamma;\\exists x \\varphi\\vdash\\psi$.\n    \n    Furthermore, there is a deduction of $\\psi$ from $\\Gamma;\\exists x \\varphi$ in which $c$ does not occur.\n\\end{corollary}\n\\begin{proof}\n    To be completed.\n\\end{proof}\n\n\\subsection{The Re-Replacement Lemma}\n\n\\begin{lemma}[Re-Replacement Lemma]\n    \\label{lem:ReReplacementLemma}\n    If $y$ does not occur in $\\varphi$, then $x$ is substitutable for $y$ in $\\varphi_y^x$ and $\\varphi_{yx}^{xy} = \\varphi$\n\\end{lemma}\n\n\\subsection{Consistency}\n\n\\begin{definition}[Consistency]\n    $\\Gamma$ is \\textbf{inconsistent} if there is some wff $\\alpha$ s.t. $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\neg\\alpha$\n\n    $\\Gamma$ is \\textbf{consistent} if it is not inconsistent.\n\\end{definition}\n\nSome properties of consistency\n\n\\begin{itemize}\n    \\item If $\\Gamma$ is inconsistent then for every $\\beta$, $\\Gamma\\vdash\\beta$\n    \\begin{itemize}\n        \\item[] $\\Gamma\\vdash\\alpha$, $\\Gamma\\vdash\\alpha$\n        \\item[$\\Rightarrow$] $\\Gamma;\\beta\\vdash\\alpha$ $\\Gamma;\\neg\\beta\\vdash\\alpha$ (Add $\\beta$ to $\\Gamma$ and the deduction should still hold)\n        \\item[$\\Rightarrow$] $\\Gamma\\vdash\\neg\\beta\\to\\alpha$ $\\Gamma\\vdash\\neg\\beta\\to\\neg\\alpha$ (Deduction Theorem)\n        \\item[$\\Rightarrow$] Notice that $\\neg\\beta\\to\\alpha, \\neg\\beta\\to\\neg\\alpha$ tautologically implies $\\beta$. By Rule T we have $\\Gamma\\vdash\\beta$ \n    \\end{itemize}\n    \\item If $\\Gamma\\nvdash\\alpha$ $\\iff$ $\\Gamma;\\neg\\alpha$ is consistent.\n    \\begin{itemize}\n        \\item Equivalently, $\\Gamma\\vdash\\alpha$ iff $\\Gamma;\\neg\\alpha$ is inconsistent. $\\Rightarrow$ is trivial.\n        \\item $\\Leftarrow$ If $\\Gamma;\\neg\\alpha$ is inconsistent, then there exists some $\\beta$ s.t. $\\Gamma;\\neg\\alpha\\vdash\\beta$ and $\\Gamma;\\neg\\alpha\\vdash\\neg\\beta$. The rest is similar to the previous proof.\n    \\end{itemize}\n    \\item $\\Gamma$ is consistent $\\iff$ every finite subset of $\\Gamma$ is consistent.\n    \\begin{itemize}\n        \\item[] Equivalent to $\\Gamma$ is inconsistent $\\iff$ there is some subset of $\\Gamma$ which is inconsistent\n        \\item[$\\Rightarrow$] $\\Gamma\\vdash\\alpha$, $\\Gamma\\vdash\\neg\\alpha$. Then there exists some finite subset $\\beta_1\\vdash\\alpha$ and $\\beta_2\\vdash\\neg\\alpha$. And the union of $\\beta_1$ and $\\beta_2$ is the desired subset.\n        \\item[$\\Leftarrow$] Trivial. \n    \\end{itemize}\n    \\item If $\\Gamma$ is consistent, then for every $\\alpha$, either $\\Gamma;\\alpha$ is consistent or $\\Gamma;\\neg\\alpha$ is consistent.\n    \\begin{itemize}\n        \\item Prove by contradiction. Assume for some $\\alpha$, $\\Gamma;\\alpha$ is inconsistent, and $\\Gamma;\\neg\\alpha$ is also inconsistent. Notice that $\\Gamma;\\neg\\alpha$ is inconsistent iff $\\Gamma\\vdash\\alpha$, so we have $\\Gamma\\vdash\\alpha$. We also have $\\Gamma\\vdash\\neg\\alpha$ iff $\\Gamma;\\neg\\neg\\alpha$\\footnote{We are working on pure grammatical level, so if the wffs ``looks'' different, then they are different, so we cannot directly say that $\\Gamma;\\neg\\neg\\alpha$ is inconsistent iff $\\Gamma;\\alpha$ is inconsistent.}. Further, it can be shown that $\\Gamma;\\neg\\neg\\alpha$ is inconsistent iff $\\Gamma;\\alpha$ is inconsistent.\n    \\end{itemize}\n\\end{itemize}\n\n\\begin{theorem}[Reductio Ad Absurdum]\n    \\label{thm:ReductioAdAbsurdum}\n    If $\\Gamma;\\alpha$ is inconsistent, then $\\Gamma\\vdash\\neg\\alpha$\n\\end{theorem}\n\n\\section{Backward Inference and Prove Strategies}\n\n\\subsection{Backward Inference}\n\nWith all the properties derived so far, we can formulate a general method to prove theorems.\n\nAssume we are showing $\\Gamma\\vdash\\varphi$\n\n\\begin{itemize}\n    \\item If $\\varphi = \\alpha\\to\\beta$, then it suffices to show $\\Gamma;\\alpha\\to\\beta$ (Deduction Theorem)\n    \\item If $\\varphi = \\forall x \\alpha$, and $x$ does not occur free in $\\Gamma$, then it suffices to show $\\Gamma\\vdash\\alpha$ (Generalization Theorem)\n    \\item If $\\varphi = \\forall x\\alpha$, and $x$ occurs free in $\\Gamma$, then we pick a variable $y$ that does not occur in $\\alpha$ and $\\Gamma$, then we have $\\forall y \\alpha_y^x\\vdash\\forall x\\alpha$ and it suffices to show $\\Gamma\\vdash\\forall y \\alpha_y^x$\n    \\begin{itemize}\n        \\item To show why we have $\\forall y \\alpha_y^x\\vdash\\forall x\\alpha$, it suffices to show $\\forall y \\alpha_y^x\\vdash\\alpha$. We have $\\forall y \\alpha_y^x \\to \\left( \\alpha_y^x \\right)_x^y = \\alpha$ (by Axiom of Substitution and Re-Replacement Lemma).\n    \\end{itemize}\n    \\item If $\\varphi = \\neg\\left( \\alpha\\to\\beta \\right)$, then it suffices to show $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\neg\\beta$ (Rule T)\n    \\item If $\\varphi=\\neg\\neg\\alpha$, then it suffices to show that $\\alpha$ (Rule T)\n    \\item If $\\varphi=\\neg\\forall x \\alpha$, then it suffices to show that $\\Gamma\\vdash\\neg\\alpha_t^x$ for some $t$ substitutable for $x$ in $\\alpha$\n    \\begin{itemize}\n        \\item This is not always possible, because there are cases where $\\Gamma\\vdash\\neg\\forall x\\alpha$, but $\\Gamma\\nvdash\\neg\\alpha_t^x$ for all $t$. In this case, try Contraposition or Reductio Ad Absurdum\n    \\end{itemize}\n    \\item For atomic and negations of atomic formula, try contraposition.\n\\end{itemize}\n\nNote that due to that applying this method will not always lead to a proof, or may lead to something that is not provable, this method is \\emph{incomplete}.\n\n\\subsubsection{Examples}\n\n\\begin{enumerate}\n    \\item Assume $x$ does not occur free in $\\beta$, derive\n\n    \\begin{itemize}\n        \\item $\\vdash\\forall x \\left( \\alpha \\to \\beta \\right) \\rightarrow \\left( \\alpha\\to\\forall x \\beta \\right)$\n        \\item[$\\Leftarrow$] $\\forall x \\left( \\alpha\\to\\beta \\right)\\vdash\\exists x\\alpha\\to\\beta$ (Deduction Thm)\n        \\item[$\\Leftarrow$] $\\forall x \\left( \\alpha\\to\\beta \\right), \\exists x \\alpha \\vdash \\beta$ (Deduction Thm)\n        \\item[$\\Leftarrow$] $\\forall x \\left( \\alpha\\to\\beta \\right), \\exists x \\alpha \\vdash \\neg\\neg\\beta$ (Rule T)\n        \\item[$\\Leftarrow$] $\\forall x \\left( \\alpha\\to\\beta \\right),\\neg\\beta \\vdash \\neg\\neg\\forall x\\neg \\alpha$ (Contraposition)\n        \\item[$\\Leftarrow$] $\\dots \\vdash \\forall x\\neg \\alpha$\n        \\item[$\\Leftarrow$] $\\dots\\vdash\\neg\\alpha$ (Generalization, note that $x$ does not occur free in $\\beta$)\n        \\item[$\\Leftarrow$] $\\forall x \\left( \\alpha\\to\\beta \\right),\\alpha\\vdash\\neg\\neg\\beta$ (Contraposition)\n        \\item[$\\Leftarrow$] $\\dots\\vdash\\beta$   \n    \\end{itemize}\n\n    \\item Show $\\vdash\\forall x \\forall z Pxz \\to \\forall{y} Pyy$\n    \\begin{itemize}\n        \\item[$\\Leftarrow$] $\\forall x \\forall z Pxz \\vdash \\forall y Pyy$\n        \\item[$\\Leftarrow$] $\\forall x \\forall z Pxz \\vdash Pyy$\n        \\item[$\\Leftarrow$] $\\forall x \\forall z Pxz \\to \\forall z Pyz$ (Substitution)\n        \\item[] Suffice to show $\\forall zPyz \\vdash \\forall z Pyz$, again can be proved by substitution.  \n        \\item[] However, cannot prove $\\vdash\\forall x\\forall y Pxy \\to \\forall y Pyy$ like this, although this formula is semantically valid ($\\vDash$)\n    \\end{itemize}\n\n    \\item Show $\\vdash\\forall x \\forall y Pxy \\to \\forall{y} Pyy$\n    \\begin{itemize}\n        \\item[] We have shown that Show $\\vdash\\forall x \\forall z Pxz \\to \\forall{y} Pyy$\n        \\item[] We will show that $\\forall x\\forall y Pxy \\vdash\\forall{x}\\forall{z}Pxz$\n        \\item[$\\Leftarrow$] $\\forall{x}\\forall{y}Pxy \\vdash Pxz$ (Generalization)\n        \\item[] Done. (Substitution)\n    \\end{itemize}\n\\end{enumerate}\n\n\\subsection{Alphabetic Variants}\n\n\\begin{theorem}[Alphabetic Variants]\n    \\label{thm:AlphabeticVariants}\n    Given a wff $\\alpha$, a term $t$ and a variable $x$. There is a wff $\\alpha'$ s.t. $\\alpha'$ differs from $\\alpha$ only in quantified variables; $\\vdash \\alpha\\leftrightarrow\\alpha'$ and $t$ is substitutable for $x$ in $\\alpha'$.\n\\end{theorem}\n\nIntuitively, we can always find a $\\alpha'$ such that we can do substitution whenever there is a conflicting variable in $\\alpha$. For the examples mentioned above, $\\alpha=\\forall{x}\\forall{y}Pxy$, and $\\alpha'=\\forall{x}\\forall{z}Pxz$\n\nCan be proved by induction on $\\alpha$, and can refer to Enderton.\n\n\\subsubsection{Example}\n\nShow $\\forall{x}\\forall{y}Pxy\\vdash\\forall{y}Pyy$, and $y$ is \\emph{not} substitutable for $x$ in $\\forall{y}Pxy$.\n\nApply the alphabetic variants theorem to $\\forall{y}Pxy$ to get $\\forall{z}Pxz$.\n\n\\begin{itemize}\n    \\item $\\vdash\\forall{y}Pxy\\leftrightarrow\\forall{z}Pxz$\n    \\item $\\forall{x}\\forall{y}Pxy\\to\\forall{x}\\forall{z}Pxz$ (Generalization)\n    \\item $\\forall{x}\\forall{z}Pxz$ TO BE COMPLETED.\n\\end{itemize}\n\n\\section{The Soundness Theorem}\n\n\\begin{lemma}\n    Given a set $\\Gamma$ of wffs and the wffs $\\alpha$ and $\\beta$, if $\\Gamma\\vDash\\alpha\\to\\beta$ and $\\Gamma\\vDash\\alpha$, then $\\Gamma\\vDash\\beta$\n\\end{lemma}\n\n\\begin{theorem}[Soundness Theorem]\n    \\label{thm:SoundnessTheorem}\n    If $\\Gamma\\vdash\\alpha$, then $\\Gamma\\vDash\\alpha$\n\\end{theorem}\n\\begin{proof}\n    Prove by induction on the deduction. Assume $\\Gamma=\\{ \\gamma_0,\\dots,\\gamma_n \\}$, we show that $\\Gamma\\vdash\\varphi_i$ for all $i$\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} If $\\varphi_i \\in \\Lambda$, by validity of all axioms, it holds. If $\\varphi_i \\in \\Gamma$, then obviously $\\Gamma\\vDash\\varphi_i$\n        \\item[] \\textbf{Inductive.} Suppose there exists some $\\varphi_j$ and $\\varphi_k$ s.t. $j,k \\le i$. Let $\\varphi_k = \\varphi_j \\to \\varphi_i$, and $\\Gamma\\vdash\\varphi_j, \\Gamma\\vdash\\varphi_k$. By inductive hypothesis we have $\\Gamma\\vDash\\varphi_j$ and $\\Gamma\\vDash\\varphi_k=\\varphi_j\\to\\varphi_i$. Therefore by lemma we have $\\Gamma\\vDash\\varphi_i$. \n    \\end{itemize}\n\\end{proof}\n\n\\begin{corollary}\n    If $\\vdash\\alpha$, then $\\vDash\\alpha$.\n\\end{corollary}\n\n\\begin{corollary}\n    If $\\vdash\\varphi\\leftrightarrow\\psi$, then $\\varphi$ and $\\psi$ are logically equivalent.\n\\end{corollary}\n\\begin{proof}\n    If $\\vdash\\varphi\\rightarrow\\psi$, then $\\varphi\\vDash\\psi$. The converse is similar.\n\\end{proof}\n\n\\begin{corollary}\n    If $\\varphi'$ is an alphabetic variant of $\\varphi$, then $\\varphi$ and $\\varphi'$ are logically equivalent.\n\\end{corollary}\n\n\\subsection{Soundness and Satisfiability}\n\n\\begin{corollary}\n    If $\\Gamma$ is satisfiable, then $\\Gamma$ is consistent.\n\\end{corollary}\n\nIn fact, soundness is equivalent to the above corollary.\n\n\\begin{theorem}\n    The following two statements are equivalent.\n    \\begin{itemize}\n        \\item For any $\\Gamma$ and $\\alpha$, if $\\Gamma\\vdash\\alpha$, then $\\Gamma\\vDash\\alpha$\n        \\item For any $\\Gamma$, if $\\Gamma$ is satisfiable, then $\\Gamma$ is consistent.\n    \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n    \\begin{itemize}\n        \\item[$\\Rightarrow$] If we have soundness, we prove consistency by contradiction. Assume $\\Gamma$ is satisfiable, but $\\Gamma$ is inconsistent. Then there exists some $\\varphi$ s.t. $\\Gamma\\vdash\\varphi$ and $\\Gamma\\vdash\\neg\\varphi$. By soundness we have $\\Gamma\\vDash\\varphi$ and $\\Gamma\\vDash\\neg\\varphi$. Since $\\Gamma$ is satisfiable, there is some structure $\\frakA$ and assignment $s$ s.t. $\\sat{A}{\\varphi}{s}$ and $\\sat{A}{\\neg\\varphi}{s}$. 寄!\n        \\item[$\\Leftarrow$] Conversely, if we have the latter, we prove soundness by contradiction. Assume $\\Delta\\vdash\\alpha$ but $\\Delta\\nvDash\\alpha$. Then $\\Delta;\\neg\\alpha$ is satisfiable. So $\\Delta;\\neg\\alpha$ is consistent. By property of consistency we have $\\Delta\\nvdash\\alpha$. 寄!\n    \\end{itemize}\n\\end{proof}\n\n\\section{The Completeness Theorem}\n\n\\begin{theorem}[G\\\"{o}del Extended Completeness Theorem]\n    If $\\Gamma\\vDash\\alpha$, then $\\Gamma\\vdash\\alpha$.\n\\end{theorem}\n\n\\begin{corollary}[G\\\"odel Completeness Theorem]\n    If $\\vDash\\alpha$, then $\\vdash\\alpha$.\n\\end{corollary}\n\n\\subsection{Equivalent Statement for Completeness}\n\n\\begin{theorem}\n    The following statements are equivalent\n    \\begin{itemize}\n        \\item For any $\\Gamma$ and $\\alpha$, if $\\Gamma\\vDash\\alpha$, then $\\Gamma\\vdash\\alpha$\n        \\item For any $\\Gamma$, if $\\Gamma$ is consistent then $\\Gamma$ is satisfiable\n    \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n    \\begin{itemize}\n        \\item[$\\Rightarrow$] Assmue completeness, and assume $\\Gamma$ is consistent. Assume for contradiction that $\\Gamma$ is unsatisfiable. Then $\\Gamma\\vDash\\alpha$ and $\\Gamma\\vDash\\neg\\alpha$. By completeness $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\neg\\alpha$, which means $\\Gamma$ is inconsistent.\n        \\item[$\\Leftarrow$] Assume the latter, we prove completeness by constradiction. Assume $\\Gamma\\vDash\\alpha$ but $\\Gamma\\nvdash\\alpha$. Then by property of consistency $\\Gamma;\\neg\\alpha$ is consistent and thus satisfiable. Therefore $\\Gamma\\vDash\\neg\\alpha$. 寄!\n    \\end{itemize}\n\\end{proof}\n\n\\subsection{Proof of Completeness}\n\n\\emph{“20世纪逻辑学最重要的发现之一。”}\n\nThe proof is similar to that for compactness.\n\n\\begin{enumerate}\n    \\item Extend $\\Gamma$ to $\\Delta\\supseteq\\Gamma$ s.t. $\\Delta$ is consistent and maximal (for any $\\alpha$, either $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$)\n    \\item Define a structure $\\frakA$ and an assignment $s$ for $\\frakA$ s.t. $\\frakA$ satisfies $\\Gamma$ with $s$\n\\end{enumerate}\n\nBut the actual proof is more complex, because we have to deal with $\\doteq$. The actual proof consists of 6 steps.\n\n\\subsubsection{Expanding a Language with Constants}\n\nLet $\\Gamma$ be a consistent set of wffs in a \\emph{countable} language. We expand the language with a countably infinite set of new constant symbols $c_1,\\dots,c_n,\\dots$\n\nAssume $\\Gamma$ is defined in $\\mathbb{L}$, and let\n\\[ \\mathbb{L}' = \\mathbb{L}\\cup\\{ c_1,\\dots,c_n,\\dots \\} \\]\n\nWe show by contradiction that $\\Gamma$ is also consistent in $\\mathbb{L}'$.\n\n\\begin{proof}\n    Assume $\\Gamma$ is inconsistent in $\\mathbb{L}'$. Then there is some wff $\\alpha$ s.t. $\\Gamma\\vdash\\alpha$ and $\\Gamma\\vdash\\neg\\alpha$. Therefore $\\Gamma\\vdash\\alpha\\wedge\\neg\\alpha$. $\\alpha$ may contain the new introduced constant symbols, but since we have Generalization on Constants, we can show that there is some deduction\n    \\[ \\alpha_1',\\dots,\\alpha_n' = \\alpha'\\wedge\\neg\\alpha' \\]\n    where $\\alpha_i'$ is $\\alpha_i$ with all constants not in $\\mathbb{L}$ replaced with some variable. Therefore $\\Gamma$ is inconsistent in $\\mathbb{L}$.\n\\end{proof}\n\n\\subsubsection{Preparing for Satisfiability of Quantified WFFs}\n\nIn the new language, for any pair of wff $\\varphi$ and variable $x$, we introduce a formula\n\\[ \\neg\\forall{x}\\varphi \\to \\neg\\varphi_c^x \\]\n\nwhere $c$ is a new constant symbol. Let $\\Theta$ be the set of all these formulas. This is essentially (1) $c$ identifies a \\emph{counter example} for $\\varphi$, and (2) $\\Gamma\\cup\\Theta$ is consistent.\n\nNote that the pairs of $\\varphi$ and $x$ are enumerable\n\n\\[ (\\varphi_1,x_1), (\\varphi_2,x_2),\\dots \\]\n\nand the newly introduced constant are also enumerable\n\n\\[ c_1,c_2,\\dots \\]\n\nSince each $\\varphi$ contains finitely many constants, there must be some certain way of enumeration such that $c_{i+1}$ does not occur in $\\varphi_1,\\dots,\\varphi_i$.\n\nWe now show that $\\Gamma\\cup\\Theta$ is consistent.\n\n\\begin{proof}\n    Assume for contradiction that $\\Gamma\\cup\\Theta$ is inconsistent. Then $\\Gamma\\cup\\Theta\\vdash\\alpha$ and $\\Gamma\\cup\\Theta\\vdash\\neg\\alpha$.\n\n    So there is some finite subset $\\Theta_k = \\{\\theta_1,\\dots,\\theta_k\\} \\subseteq \\Theta$ s.t. $\\Gamma\\cup\\Theta_k$ is inconsistent. This is guaranteed by the finiteness of deduction. Notice that since $\\Gamma$ itself is consistent, $\\Theta_k$ cannot be empty. Let $k$ be the minimal number s.t. $\\Gamma\\cup\\Theta_k$ is inconsistent.\n\n    By Reductio Ad Absurdum, we have\n    \\[ \\Gamma:=\\Gamma\\cup\\{ \\theta_1,\\dots,\\theta_{k-1} \\} \\vdash \\neg \\theta_k \\]\n    where\n    \\[ \\theta_k = \\neg\\forall x \\varphi_k \\to \\neg \\varphi_{kc_k}^x \\]\n\n    Therefore\n    \\[ \\Gamma' \\vdash \\neg\\forall{x}\\varphi_k \\wedge \\varphi_{kc_k}^k \\]\n    i.e. $\\Gamma' \\vdash \\neg\\forall{x}\\varphi_k$ and $\\Gamma'\\vdash\\varphi_{kc_k}^k$\n\n    Note that from a corollary of Generalization on constants \\ref{coroll:Corollary24G}. We have $\\Gamma'\\vdash\\varphi_{kc_k}^k\\Longrightarrow \\Gamma'\\vdash\\forall{x}\\varphi_k$. This shows that $\\Gamma'$ is inconsistent, which is contradictory to our assumption that $k$ (not $k-1$) is the smallest number that makes $\\Gamma\\cup\\Theta_k$ inconsistent.\n\\end{proof}\n\n\\subsubsection{Generate Maximally Consistent Set}\n\nWe extend $\\Gamma\\cup\\Theta$ to a set $\\Delta$ s.t.\n\n\\begin{itemize}\n    \\item $\\Delta$ is consistent.\n    \\item For each wff $\\alpha$, either $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$\n\\end{itemize}\n\n\\begin{proof}\n    $\\Gamma\\cup\\Theta$ is consistent.\n    \\begin{itemize}\n        \\item There is no $\\beta$ s.t. $\\Gamma\\cup\\Theta\\vdash\\beta$ and $\\Gamma\\cup\\Theta\\vdash\\neg\\beta$.\n        \\item[$\\Leftrightarrow$] There is no $\\beta$ s.t. $\\Gamma\\cup\\Theta\\cup\\Lambda$ tautologically imply $\\beta$ and $\\neg\\beta$\n        \\item[$\\Rightarrow$] Therefore $\\Gamma\\cup\\Theta\\cup\\Lambda$ is satisfiable \\emph{in the sense of sentential logic}\n        \\item[$\\Rightarrow$] There is some truth assignment $v$ satisfying $\\Gamma\\cup\\Theta\\cup\\Lambda$. Therefore we pick\n        \\[ \\Delta = \\{ \\varphi | \\bar{v}(\\varphi) = T \\} \\]\n    \\end{itemize}\n\\end{proof}\n\nWe continue to show some properties of $\\Delta$.\n\n\\begin{proposition}\n    For any $\\alpha$, either $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$, but not both.\n\\end{proposition}\n\\begin{proof}\n    If $\\bar{v}(\\alpha) = T$, then $\\alpha\\in\\Delta$. $\\bar{v}(\\neg\\alpha)=F$. Then $\\neg\\alpha\\notin\\Delta$. Conversely, if $\\bar{v}(\\alpha)=F$, then $\\neg\\alpha\\in\\Delta$, and thus $\\alpha\\notin\\Delta$.\n\\end{proof}\n\n\\begin{proposition}\n    $\\Delta$ is a \\emph{theory}. That is,\n    \\[ \\Delta\\vdash\\alpha \\Longrightarrow \\alpha\\in\\Delta \\]\n\\end{proposition}\n\\begin{proof}\n    If $\\Delta\\vdash\\alpha$, then $\\Delta\\cup\\Lambda$ tautologically implies $\\alpha$. This is equivalent to $\\Delta$ tautologically implies $\\alpha$, because by definition of $\\Delta$ we have $\\Lambda\\subseteq\\Delta$. Since we know that $v$ satisfies $\\Delta$ (in sentential logic), by tautological implication we know that $v$ should also satisfy $\\alpha$. Thus $\\alpha\\in\\Delta$\n\\end{proof}\n\n\\begin{proposition}\n    $\\Delta$ is consistent.\n\\end{proposition}\n\\begin{proof}\n    If $\\Delta$ is inconsistent, then there exists some formula $\\beta$ s.t. $\\Delta\\vdash\\beta$ and $\\neg\\beta$. Then $\\beta\\in\\Delta$ and $\\neg\\beta\\in\\Delta$. 噔噔咚\n\\end{proof}\n\n\\subsubsection{Make a Structure for the New Language}\n\nWe make a structure $|\\frakA|$ from $\\Delta$ for the new language where $\\doteq$ is replaced by a 2-nary symbol $E$.\n\nsudo make install!\n\n\\begin{itemize}\n    \\item Let $|\\frakA|$ be the set of all terms in the new language\n    \\item $(u,t)\\in E^\\frakA \\iff u\\doteq t \\in \\Delta$\n    \\item For any n-ary predicate symbol,\n    \\[ (t_1,\\dots,t_n) \\in P^\\frakA \\iff Pt_1\\dots t_n \\in \\Delta \\]\n    \\item For any n-ary predicate symbol,\n    \\[ f^\\frakA (t_1,\\dots,t_n) = ft_1\\dots t_n \\]\n    \\item For any constant symbol $c$, $c^\\frakA=c$\n\\end{itemize}\n\nThen we make an assignment function $s:V\\mapsto|\\frakA|$\n\\[ s(x)=x \\]\n\nThen $\\bar{s}(t)=t$. For any wff $\\varphi$, let $\\varphi^*$ be $\\varphi$ with $\\doteq$ replaced by $E$. We have\n\\[ \\sat{A}{\\varphi^*}{s} \\iff \\varphi\\in\\Delta \\]\n\nNotice that once we prove this, we have already found a structure $\\frakA$ and an assignment $s$ that satisfies $\\Delta$. That is, if the language does not contain $\\doteq$, we have proved completeness.\n\n\\begin{proof}\n    Assume $n$ is the number of connectives in $\\varphi$. Prove by induction on $n$. We do induction on $n$ to avoid $\\doteq$'s in $\\varphi$ that may cause troubles.\n    \\begin{itemize}\n        \\item[] \\textbf{Base.} $n=0$. Then $\\varphi$ is $u\\doteq t$ or $Pt_1\\dots t_n$. If $\\varphi$ is $u\\doteq t$, then $\\varphi^*$ is $Eut$.\n        \\[ \\sat{A}{Eut}{s} \\iff (\\bar{s}(u), \\bar{s}(t)) \\in E^\\frakA \\iff (u,t) \\in E^\\frakA \\iff u\\doteq t \\in \\Delta \\]\n        If $\\varphi$ is $Pt_1\\dots t_n$, the proof is similar.\n\n        \\item[] \\textbf{Inductive.} If $\\varphi = \\neg\\alpha$, then $\\varphi^*=\\neg\\alpha^*$.\n        \\[ \\sat{A}{\\neg\\alpha^*}{s} \\iff \\unsat{A}{\\alpha^*}{s} \\iff \\alpha\\notin\\Delta\\iff\\neg\\alpha\\in\\Delta \\]\n        The second step uses the inductive hypothesis.\n\n        If $\\varphi=\\alpha\\to\\beta$, then $\\varphi^*=\\alpha^*\\to\\beta^*$.\n        \\[ \\sat{A}{\\alpha^*\\to\\beta^*}{s} \\iff \\unsat{A}{\\alpha^*}{s}\\text{ or }\\sat{A}{\\beta^*}{s} \\iff \\alpha\\notin\\Delta \\text{ or }\\beta\\in\\Delta \\]\n        \\begin{itemize}\n            \\item We first show $\\alpha\\notin\\Delta$ or $\\beta\\in\\Delta$ implies $\\alpha\\to\\beta\\in\\Delta$. To show this, it suffices to show that $\\Delta\\vdash\\alpha\\to\\beta$, and it suffices to show that $\\Delta;\\alpha\\vdash\\beta$. Then 分类讨论两种前提 and we are done.\\footnote{“事实上我也忘了这个怎么证明，我们来证一下。”}\n            \\item To show $\\alpha\\to\\beta\\in\\Delta\\Rightarrow\\alpha\\notin\\Delta$ or $\\beta\\in\\Delta$.\n            \\[ \\alpha\\to\\beta\\in\\Delta\\iff\\Delta\\vdash\\alpha\\to\\beta\\Longleftarrow\\Delta;\\alpha\\vdash\\beta \\]\n        \\end{itemize}\n\n        If $\\varphi=\\forall{x}\\alpha$. $\\varphi^*=\\forall{x}\\alpha^*$.\n        \\[ \\sat{A}{\\forall{x}\\alpha^*}{s} \\iff \\text{For every $t\\in|\\frakA|$,} \\sat{A}{\\alpha^*}{s(x|t)} \\]\n        \\begin{itemize}\n            \\item[$\\iff$] $\\sat{A}{\\alpha^*}{s(x|\\bar{s}(t))}$\n            \\item[$\\iff$] $\\sat{A}{(\\alpha^*)^x_t}{s}$ (Substitution Lemma)\n            \\item[$\\iff$] $\\sat{A}{(\\alpha^x_t)^*}{s}$\n            \\item[$\\iff$] $\\alpha_t^x \\in \\Delta$ (IH) \n            \\item[$\\Longrightarrow$] $\\alpha_c^x\\in\\Delta$ \n        \\end{itemize}\n        Notice that $\\neg\\forall{x}\\alpha\\to\\neg\\alpha_c^x \\in \\Delta$. Since we have $\\alpha_c^x\\in\\Delta$, the condition $\\neg\\forall{x}\\alpha$ cannot hold, so $\\forall{x}\\alpha\\in\\Delta$\n\n        So far we have proved $\\Rightarrow$. Now consider the other side $\\forall{x}\\alpha\\in\\Delta\\Rightarrow\\sat{A}{\\forall{x}\\alpha^*}{s}$. This is equivalent to showing\n        \\[ \\unsat{A}{\\forall{x}\\alpha^*}{s} \\Longrightarrow \\forall{x}\\alpha\\notin\\Delta \\]\n        Assume there is some $t$ s.t. $\\unsat{A}{\\alpha^*}{s(x|t)}$, equivalent to $\\unsat{A}{(\\alpha_t^x)^*}{s}$.\n        \n        Let $\\beta$ be alphabetic equivalent to $\\alpha$ s.t. $t$ is substitutable for $x$ in $\\beta$. We have $\\alpha\\vDash\\Dashv\\beta$ by alphabetical equivalence.\n\n        Therefore previous equation is equivalent to\n        \\[ \\unsat{A}{(\\beta_t^x)^*}{s} \\iff \\beta_t^x \\notin \\Delta \\]\n\n        If $\\forall{x}\\alpha\\in\\Delta$, then $\\Delta\\vdash\\forall{x}\\alpha$, and thus $\\Delta\\vdash\\forall{x}\\beta$. We have axiom $\\forall{x}\\beta\\to\\beta_t^x$ since $t$ is substitutable for $x$ in $\\beta$. Thus $\\Delta\\vdash\\beta_t^x$ and $\\beta_t^x\\in\\Delta$. Contradiction. So $\\forall{x}\\alpha\\notin\\Delta$, we are done.\n    \\end{itemize}\n\\end{proof}\n\nUntil now, we are done if the language does not contain $\\doteq$. But to actually complete the proof for all cases, we need an extra step.\n\n\\subsubsection{Deal with Equality}\n\nNot enough time. Pigeoned. Refer to slides or reference books.\n", "meta": {"hexsha": "6ba014949d61e0f170882d7b8fcdfa79573ec76e", "size": 44928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic/DeductiveCalculus.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/DeductiveCalculus.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/DeductiveCalculus.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": 54.9914320685, "max_line_length": 644, "alphanum_fraction": 0.668514067, "num_tokens": 14482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6664644968769368}}
{"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}\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, one can draw three arbitrary points and draw a new value for one of the points given 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 later. Further when this new value is drawn the two other values must be adjusted to fullfill the sufficient statistics. This is the idea behind our Gibbs sampler. \n\\subsection{Drawing a new value}\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 5.2. Another assumption is that all values in the samples must be between 0 and 1. Hence $\\tau = 1$. This makes it easier for the uniform distribution. To draw a new value we need to use tranformation of variables. The tranformation is\n\\begin{equation}\nZ = (\\sum_{i=1}^{3} X_i, \\prod_{i=3}^{2} X_i, X_3),\n\\end{equation}\nwhere $X_3$ is going to be updated. 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\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},\n\\end{equation}\nwhich is\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}\nThe density we are going to draw from is then\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. It is imoportant that this density has some requirements. These are listed below.\n\\begin{align}\n0 \\leq X_3 \\leq \\min(\\tau, a) \\\\\n0 \\leq (a - X_3) ± \\sqrt{(a - X_3)^2 - \\frac{4b}{X_3}} \\leq 1.\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$ fullfills these requirements. If not the probability of accepting this new value is zero. If the requirements are fullfilled then the acceptance probability is defined as,\n\\begin{equation}\n\\alpha = \\min\\left(1, \\frac{\\Pi(X_{prop})}{\\Pi(X_{curr})}\\right)\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 X's\n\\STATE Caclulate sum and product of these.\n\\STATE Draw a proposal $X_3$ from $U[0,1]$\n\\STATE Check requirements\n\\STATE Calculate $\\alpha$\n\\STATE Accept with probability $\\alpha$\n\\STATE Repeat desired times.\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 is done before for another distribution in \\cite{lockhart2007use}. The pros of this method is that you new values for all the indices. However the cons is that the values for the sufficient statistics are sensitive to large and small values when the number data points in a sample is large.\n", "meta": {"hexsha": "127c23c7eea12b93dd6c5cdc941500fefd1e9267", "size": 4879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/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/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/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": 70.7101449275, "max_line_length": 686, "alphanum_fraction": 0.7661406026, "num_tokens": 1318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118222, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.6664644952976082}}
{"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{Some aspects of Koszul complexes}\n\nThis lecture is a faithful replay of the relevant sections of \\cite{Bour80} and \\cite{Bour98}; the main aim here is to complete the proof of Theorem \\ref{prop:regular-vs-depth}. In what follows, we work with a chosen ring $R$. We impose no Noetherian or finiteness conditions here.\n\n\\section{Preparations in homological algebra}\nFor any $R$-module $L$, denote its \\emph{exterior algebra}\\index{exterios algebra} over $R$ by\n\\[ \\bigwedge L := \\bigoplus_{n \\geq 0} \\bigwedge^n L. \\]\nIt is the quotient of the tensor algebra $T(L) = \\bigoplus_{n \\geq 0} (T^n(L) := L^{\\otimes n})$ by the graded ideal generated by the pure tensors\n\\[ \\cdots \\otimes x \\otimes x \\otimes \\cdots, \\quad x \\in L. \\]\nThe multiplication operation in $\\bigwedge L$ is written as $\\wedge$. Note that $\\bigwedge^0 L = T^0(L) = R$ by convention. The traditional notion of exterior algebras encountered in differential geometry is recovered when $\\Q \\subset R$.\n\nGiven $u \\in \\Hom_R(L, R)$, one can define the corresponding \\emph{contractions} $i_u: \\bigwedge^{n+1} L \\to \\bigwedge^n L$, given concretely as\n\\[ i_u (x_0 \\wedge \\cdots \\wedge x_n) = \\sum_{i=0}^n (-1)^i u(x_i) \\cdot x_0 \\wedge \\cdots \\widehat{x_i} \\cdots \\wedge x_n \\]\nwhere $\\widehat{x_i}$ means $x_i$ is omitted. It is routine to check that $i_u$ satisfies $i_u \\circ i_u = 0$, thereby giving rise to a chain complex.\n\n\\begin{definition}\\label{def:Koszul-general}\\index{Koszul complex}\n\tLet $L$ and $u$ be as above. Define the corresponding \\emph{Koszul complex} as $K_\\bullet(u) := (\\bigwedge^\\bullet L, i_u)$. For any $R$-module $M$, put\n\t\\begin{align*}\n\t\tK_\\bullet(u; M) & := M \\dotimes{R} K_\\bullet(u), \\\\\n\t\tK^\\bullet(u; M) & := \\Hom_A(K_\\bullet(u), M)\n\t\\end{align*}\\index{$K^\\bullet(u; M)$}\n\twhich is naturally a chain (resp. cochain) complex in positive degrees; here one regards $M$ as a complex in degree zero. These definitions generalize to the case of any complex $M$, and are functorial in $M$.\n\\end{definition}\n\nThe reader might have encountered the following result in differential geometry.\n\\begin{proposition}[Homotopy formula]\n\tFor any $x \\in L$ and $\\omega \\in \\bigwedge^n L$, we have\n\t\\[ i_u (x \\wedge \\omega) + x \\wedge (i_u(\\omega)) = u(x) \\omega. \\]\n\\end{proposition}\n\\begin{proof}\n\tConsider $\\omega = x_1 \\wedge \\cdots \\wedge x_n$. Put $x_0 := x$. The left-hand side equals\n\t\\[ \\sum_{i=0}^n (-1)^i \\cdot u(x_i) \\cdots \\wedge \\widehat{x_i} \\wedge \\cdots  \\]\n\twhereas the right-hand side equals\n\t\\[ \\sum_{i=1}^n (-1)^{i+1} \\cdot u(x_i) x_0 \\wedge \\cdots \\wedge \\widehat{x_i} \\wedge \\cdots. \\]\n\tThe terms with a $\\widehat{x_i}$ (non-existant --- hopefully this won't generate metaphysical issues) where $i > 0$ cancel out. We are left with $u(x_0) x_1 \\wedge \\cdots \\wedge x_n = u(x) \\omega$.\n\\end{proof}\nObviously, the same formula extends to all $\\omega \\in \\bigwedge L$ by linearity.\n\n\\begin{proposition}\\label{prop:Koszul-u-vanishing}\n\tSet $\\mathfrak{q} := u(L)$, which is an ideal of $R$. Then $\\mathfrak{q}$ annihilates each homology (resp. cohomology) of $K_\\bullet(u; M)$ (resp. $K^\\bullet(u; M)$). Again, this generalizes to general complexes $M$.\n\\end{proposition}\n\\begin{proof}\n\tGiven $t \\in \\mathfrak{q}$, the homotopy formula implies that the endomorphism $\\omega \\mapsto t\\omega$ of $K_\\bullet(u)$ is homotopic to zero, hence so are the induced endomorphisms of $K_\\bullet(u; M)$ and $K^\\bullet(u; M)$ by standard homological algebra.\n\\end{proof}\n\n\\begin{proposition}\\label{prop:Koszul-long-exact-sequence}\n\tSuppose $L$ is projective over $R$ and $0 \\to M' \\to M \\to M'' \\to 0$ is exact. Then there is a natural short exact sequence of complexes\n\t\\[ 0 \\to K^\\bullet(u; M') \\to K^\\bullet(u; M) \\to K^\\bullet(u; M'') \\to 0 \\]\n\twhich gives rise to a long exact sequence of cohomologies of the Koszul complexes in question.\n\\end{proposition}\n\\begin{proof}\n\tStandard. It suffices to note that $L$ is projective implies each graded piece $\\bigwedge^n L$ of $\\bigwedge L$ is projective as well.\n\\end{proof}\n\n\\begin{exercise}\n\tJustify the assertion above concerning the projectivity of $\\bigwedge^n L$. Hint: suppose $L$ is a direct summand of a free module $F$, show that $\\bigwedge^n L$ is a direct summand of $\\bigwedge^n F$ and $\\bigwedge^n F$ is free.\n\\end{exercise}\n\nSimilar properties hold for the homological version when $L$ is flat over $R$. One needs the property that $\\bigwedge^n L$ is flat if $L$ is.\n\\begin{exercise}\n\tProve the assertion above concerning flatness of $\\bigwedge^n L$. Consult the proof in \\cite[p.15]{Bour80} if necessary.\n\\end{exercise}\n\n\\section{Auxiliary results on depth}\nWe fix an ideal $I \\subset R$.\n\\begin{proposition}\\label{prop:depth-prod}\n\tFor every family $\\{M_\\beta\\}_{\\beta \\in \\mathcal{B}}$ of $R$-modules, we have\n\t\\[ \\mathrm{depth}_I\\left(\\prod_\\beta M_\\beta \\right) = \\inf_\\beta \\mathrm{depth}_I(M_\\beta). \\]\n\\end{proposition}\n\\begin{proof}\n\tThis follows from $\\Ext^n_R(R/I, \\prod_i M_i) = \\prod_{i \\in I} \\Ext^n_R(R/I, M_i)$, as is easily seen by taking a projective resolution of $R/I$ and using the fact the $\\Hom_R$ preserves direct products in the second variable.\n\\end{proof}\n\n\\begin{remark}\n\tBy stipulation, the empty product is $0$, the zero object of the category $R\\dcate{Mod}$. In parallel we define $\\inf\\emptyset := \\infty$, so that Proposition \\ref{prop:depth-prod} remains true in this case, since the zero module has infinite depth.\n\\end{remark}\n\n\\begin{proposition}\n\tSuppose $N$ is an $R$-module annihilated by some $I^m$, where $m \\geq 1$. Then $\\Ext^i_R(N,M)=0$ whenever $i < \\mathrm{depth}_I(M)$.\n\\end{proposition}\n\\begin{proof}\n\tTo show $\\Ext^i_R(N,M)=0$ for $i < \\text{depth}_I(M)$, we begin with the case $m=1$. This case follows by a dimension-shifting argument based on the short exact sequence\n\t\\[ 0 \\to K \\to (R/I)^{\\oplus I} \\to M \\to 0, \\]\n\ttogether with induction on $i$ (note that $\\Ext^{<0}_R(N,M)=0$ for trivial reasons). The case of general $m$ follows by a standard \\emph{dévissage} using\n\t\\[ 0 \\to JN \\to N \\to N/JN \\to 0 \\]\n\tand the associated long exact sequence.\n\\end{proof}\n\n\\begin{lemma}\\label{prop:depth-power}\n\tSuppose $J$ is an ideal satisfying $J \\supset I^m$ for some $m \\geq 1$. Then $\\mathrm{depth}_I(M) \\leq \\mathrm{depth}_J(M)$.\n\\end{lemma}\n\\begin{proof}\n\tFrom the previous Proposition, we have $\\Ext^i_R(R/J, M) = 0$ for $i < \\text{depth}_I(M)$ since $I^m$ annihilates $R/J$. The assertion follows upon recalling the definition of depth.\n\\end{proof}\n\nThe following technical results will be invoked in the proof of Theorem \\ref{prop:Koszul-depth}.\n\\begin{proposition}\\label{prop:depth-vanishing-aux}\n\tLet $C^\\bullet$ be a cochain complex of $R$-modules such that $n \\ll 0 \\implies C^n = 0$. Let $h \\in \\Z$  such that for all integers $n \\leq k \\leq h$, the depth of $C^n$ with respect to $J_k := \\mathrm{ann}(H^k(C^\\bullet))$ is $> k-n$, then\n\t\\[ H^{\\leq h}(C^\\bullet)=0. \\]\n\\end{proposition}\nIn what follows, we write $H^n = H^n(C^\\bullet) = Z^n/B^n$ in the usual notation for homological algebra.\n\\begin{proof}\n\tAssume on the contrary that there exists $k \\leq h$ with $H^{< k} = 0$ whereas $H^k \\neq 0$. Write $J = J_k$. As $J$ annihilates the nonzero $R$-module $H^k$, the criterion of depth-zero modules (Proposition \\ref{prop:depth-zero}) implies that $\\text{depth}_J(H^k) = 0$. By assumption $\\text{depth}_J(C_k) > k-k = 0$, it follows that $\\text{depth}_J(Z_k) > 0$ since $Z_k \\subset C_k$, by applying the aforementioned criterion of depth-zero. From the short exact sequence\n\t\\[ 0 \\to B^k \\to Z^k \\to H^k \\to 0 \\]\n\twe deduce distinguished triangles in $D(R\\dcate{Mod})$\n\t\\begin{gather*}\n\t\t\\mathcal{H}\\text{om}(R/J, B^k) \\to \\mathcal{H}\\text{om}(R/J, Z^k) \\to \\mathcal{H}\\text{om}(R/J, H^k) \\xrightarrow{+1}, \\\\\n\t\t\\mathcal{H}\\text{om}(R/J, H^k)[-1] \\to \\mathcal{H}\\text{om}(R/J, B^k) \\to \\mathcal{H}\\text{om}(R/J, Z^k) \\xrightarrow{+1}.\n\t\\end{gather*}\n\tAs the leftmost and rightmost terms of the last line are in $D^{\\geq 1}(R\\dcate{Mod})$, we see\n\t\\[ \\text{depth}_J(B^k) \\geq 1; \\]\n\tmoreover, the piece $\\Ext_R^0(R/J, Z^k) \\to \\Ext_R^0(R/J, H^k) \\to \\Ext_R^1(R/J, B^k)$ from the long exact sequence shows that $\\text{depth}_J(B^k) = 1$. Now for $n < k$ we have short exact sequences\n\t\\[ 0 \\to \\underbracket{B^n}_{= Z^n} \\to C^n \\to B^{n+1} \\to 0. \\]\n\tAgain, one infers from the distinguished triangle\n\t\\[ \\mathcal{H}\\text{om}(R/J, B^{n+1})[-1] \\to \\mathcal{H}\\text{om}(R/J, B^n) \\to \\mathcal{H}\\text{om}(R/J, C^n) \\xrightarrow{+1} , \\]\n\tthe assumption $\\text{depth}_J(C^n) > k-n$ and descending induction on $n$ that $n < k \\implies \\text{depth}_J(B_n) = k-n+1$. This is impossible since $B_{\\ll 0} = 0$ has infinite depth.\n\\end{proof}\n\n\\begin{corollary}\\label{prop:depth-vanishing}\n\tLet $I \\subset R$ be an ideal, $C^\\bullet$ be a cochain complex with $n \\ll 0 \\implies C_n=0$, and $h \\in \\Z$. Suppose that $n \\leq h$ implies $I \\cdot H^n(C^\\bullet) = 0$ and $\\mathrm{depth}_I(C^n) > h-n$. Then $H^{\\leq h}(C^\\bullet) = 0$.\n\\end{corollary}\n\\begin{proof}\n\tFor $k \\leq h$ we have $J_k := \\text{ann}(H^k(C^\\bullet)) \\supset I$. Hence Lemma \\ref{prop:depth-power} entails that\n\t\\[ n \\leq k \\leq h \\implies \\text{depth}_{J_k}(C^n) \\geq \\text{depth}_I(C^n) > h-n \\geq k-n. \\]\n\tNow apply Proposition \\ref{prop:depth-vanishing-aux}.\n\\end{proof}\n\n\\section{Koszul complexes and depth}\nThe simplest Koszul complexes are defined as follows. Given $x \\in R$, we form the cochain complex in degrees $\\{0,1\\}$\n\\[ K(x) := \\left[ R \\xrightarrow{x} R \\right]. \\]\nMore generally, for any $R$-module $M$, viewed as a complex concentrated in degree zero, and a family $\\mathbf{x} = (x_\\alpha)_{\\alpha \\in \\mathcal{A}}$ of element of $R$, we define the associated \\emph{Koszul complex}\\index{Koszul complex} as\n\\[ K^\\bullet(\\mathbf{x}; M) := K^\\bullet(u; M), \\]\nwhere we take $u: R^{\\oplus \\mathcal{A}} \\to R$ corresponding to $\\mathbf{x}$ in Definition \\ref{def:Koszul-general}. Unfolding definitions, we have \\index{$K^\\bullet(\\mathbf{x};M)$}\n\\[ K^h(\\mathbf{x}; M) = \\begin{cases}\n\t\\Hom_R\\left( \\bigwedge^h (R^{\\oplus \\mathcal{A}}), M \\right), & h \\geq 0 \\\\\n\t0, & h < 0. \n\\end{cases} \\]\nTherefore $K^h(\\mathbf{x}; M)$ consists of families $m(\\alpha_1, \\ldots, \\alpha_h) \\in M$ that are alternating in the variables $\\alpha_1, \\ldots, \\alpha_h \\in \\mathcal{A}$. The differential is\n\\begin{align*}\n\t\\partial^h: K^h(\\mathbf{x}; M) & \\longrightarrow K^{h+1}(\\mathbf{x}; M) \\\\\n\tm & \\longmapsto \\left[ (\\alpha_0, \\ldots, \\alpha_h) \\mapsto \\sum_{j=0}^h (-1)^j x_{\\alpha_j} \\cdot m(\\ldots, \\widehat{\\alpha_j}, \\ldots) \\right].\n\\end{align*}\nWe shall abbreviate the cohomologies of $K^\\bullet(\\mathbf{x}; M)$ as the \\emph{Koszul cohomologies}.\n\nWhen $\\mathcal{A} = \\{1, \\ldots, n\\}$ we revert to\n\\[ K^\\bullet(x_1, \\ldots, x_n; M) := M \\otimes K(x_1) \\otimes \\cdots \\otimes K(x_n) \\]\nwith the well-known sign convention. Also note that $R^{\\oplus \\mathcal{A}}$ is projective, hence the Proposition \\ref{prop:Koszul-long-exact-sequence} can always be applied to Koszul cohomologies.\n\nLet $I$ denote the ideal generated by $\\{x_\\alpha: \\alpha \\in \\mathcal{A} \\}$. The reader is invited to verify that\n\\begin{itemize}\n\t\\item $K^\\bullet\\left( \\mathbf{x}, \\prod_{\\beta \\in \\mathcal{B}} M_\\beta \\right) = \\prod_{\\beta \\in \\mathcal{B}} K^\\bullet(\\mathbf{x}; M_\\beta)$ for any family $\\{M_\\beta\\}_{\\beta \\in \\mathcal{B}}$ of $R$-modules, and same for their cohomologies;\n\t\\item the $0$-th cohomology of $K^\\bullet(\\mathbf{x}; M)$ is $\\Hom_R(R/I, M) = \\{x \\in M: Ix=0 \\}$, the $I$-torsion part of $M$;\n\t\\item if $|A| = n$, the $n$-th cohomology of $K^\\bullet(\\mathbf{x}; M)$ is $M/IM$.\n\\end{itemize}\nThese facts will cast in our later arguments.\n\n\\begin{lemma}\\label{prop:Koszul-coho-ann}\n\tEach cohomology of $K^\\bullet(\\mathbf{x}; M)$ is annihilated by $I$.\n\\end{lemma}\n\\begin{proof}\n\tApply Proposition \\ref{prop:Koszul-u-vanishing} by observing that $\\mathfrak{q} = I$ in our setting.\n\\end{proof}\n\n\\begin{theorem}\\label{prop:Koszul-depth}\\index{depth}\n\tLet $M$ be an $R$-module and $\\mathbf{x} = \\{x_\\alpha \\}_{\\alpha \\in \\mathcal{A}}$ be a family of elements of $R$, which generate an ideal $I$ of $A$. Then $\\mathrm{depth}_I(M)$ equals\n\t\\[ \\inf \\left\\{n \\geq 0: H^n(K^\\bullet(\\mathbf{x}; M)) \\neq 0 \\right\\} \\in \\Z_{\\geq 0} \\sqcup \\{\\infty \\} . \\]\n\tConsequently, if $I \\subset R$ is an ideal generated by elements $x_1, \\ldots, x_n$ and $IM \\neq M$, then we have\n\t\\[ \\mathrm{depth}_I(M) \\leq n. \\]\n\\end{theorem}\n\\begin{proof}\n\tLet $d := \\text{depth}_I(M)$. Since $K^h(\\mathbf{x}; M)$ is a direct product of copies of $M$ (possibly the empty product $=0$), by Proposition \\ref{prop:depth-prod} its depth equals either $d$ or $\\infty$. Combining Lemma \\ref{prop:Koszul-coho-ann} and Corollary \\ref{prop:depth-vanishing} (with $h = d-1$), we see that $H^{< d}(K^\\bullet(\\mathbf{x}; M)) = 0$. It remains to show $H^d(K^\\bullet(\\mathbf{x}; M)) \\neq 0$ provided that $d < \\infty$, which we assume from now onwards.\n\n\tThe case $d=0$ is clear since there exists $\\mathfrak{p} \\in \\text{Ass}(M) \\cap V(I)$, therefore $R/\\mathfrak{p} \\hookrightarrow M$ and $\\exists x \\in M$ with $\\mathfrak{p} x \\supset Ix = \\{0\\}$, whence $H^0(K^\\bullet(\\mathbf{x}; M)) \\neq 0$. Now suppose $d \\in \\Z_{\\geq 1}$ and assume $H^d(K^\\bullet(\\mathbf{x}; M)) = 0$. Take a free resolution $F_\\bullet \\to R/I \\to 0$ and put $C^\\bullet := \\Hom_R(F_\\bullet, M)$, so that\n\t\\[ H^i(C^\\bullet) \\simeq \\Ext^i_R(R/I, M), \\quad i \\geq 0. \\]\n\tHence for $i < d$ we have short exact sequences\n\t\\[ 0 \\to B^i \\to C^i \\to B^{i+1} \\to 0 \\]\n\tas usual; recall $B^i, Z^i \\subset C^i$. Note that each $C^i$ is a direct product of copies of $M$, hence $H^{\\leq d}(K^\\bullet(\\mathbf{x}; C^i)) = 0$. Indeed, $H^{< d}(K^\\bullet(\\mathbf{x}; M))=0$ has been settled in the first step, whilst $H^d(K^\\bullet(\\mathbf{x}; M))$ is the hypothesis to be refuted. It then follows from the long exact sequence for Koszul cohomologies (Proposition \\ref{prop:Koszul-long-exact-sequence}) that\n\t\\[ (s \\leq d) \\wedge (i < d) \\implies H^s(K^\\bullet(\\mathbf{x}; B^{i+1})) \\hookrightarrow H^{s+1}(K^\\bullet(\\mathbf{x}; B^i)). \\]\n\tSuppose $i < d$. As $B^0 = 0$, an iteration yields\n\t\\[ H^{d-i}(K^\\bullet(\\mathbf{x}; B^{i+1})) \\hookrightarrow \\cdots \\hookrightarrow H^{d+1}(K^\\bullet(\\mathbf{x}; B^0)) = 0. \\]\n\tIn particular, $i=d-1$ gives rise to $H^1(K^\\bullet(\\mathbf{x}; B^d)) = 0$. Hence the short exact sequence $0 \\to B^d \\to Z^d \\to H^d \\to 0$ (for $C^\\bullet$) together with Proposition \\ref{prop:Koszul-long-exact-sequence} give rise to\n\t\\[ H^0(K^\\bullet(\\mathbf{x}; Z^d)) \\twoheadrightarrow H^0(K^\\bullet(\\mathbf{x}; H^d)). \\]\n\tAs $H^d := H^d(C^\\bullet) \\simeq \\Ext^d_R(R/I, M)$ is nonzero and annihilated by $I$, the right-hand side is nonzero. Hence $H^0(K^\\bullet(\\mathbf{x}; Z^d)) \\neq 0$ and then $H^0(K^\\bullet(\\mathbf{x}; C^d)) \\neq 0$, as the zeroth Koszul cohomology is nothing but the $I$-torsion part.\n\t\n\tFinally, recall that $C^d \\neq \\{0\\}$ is a direct product of copies of $M$, consequently\n\t\\[ H^0(K^\\bullet(\\mathbf{x}; M)) \\neq 0. \\]\n\tHowever, this contradicts the earlier result that $H^{<d}(K^\\bullet(\\mathbf{x}; M))=0$ since $d \\geq 1$.\n\\end{proof}\n\nThis yields an alternative characterization of depth. It also completes the proof of Theorem \\ref{prop:regular-vs-depth} as promised in the previous lecture.\n\n% Finalizing...\n\\vfill\n\\begin{figure}[h]\n\t\\centering \\includegraphics[height=200pt]{WanFeng.jpg} \\\\ \\vspace{1em}\n\t\\begin{minipage}{0.7\\textwidth}\\begin{center}\n\t\t\t\\small \\fontspec{Noto Serif CJK SC} 《晚风》, 李桦, 木刻版画, 1963 年.\n\t\\end{center}\\end{minipage}\n\\end{figure}\n\\vfill", "meta": {"hexsha": "ba89782c8a62efb4c1feda452f2d1eb7dc48a101", "size": 15913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "YAlg3-8.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-8.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-8.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": 76.1387559809, "max_line_length": 482, "alphanum_fraction": 0.675736819, "num_tokens": 5740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6664644950185042}}
{"text": "\\section*{Problem 2 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item \n\nThe total mass-energy of the excited $^{236}$U atom is the sum of the masses of the reactants: the $^{235}$U atom and the neutron.\n\\begin{align*}\nm(^{236}\\text{U}^*)\t&= m(^{235}\\text{U}) + m_n \\\\\n\t\t\t\t\t&= 235.043930\\text{ amu} + 1.00866492\\text{ amu} \\\\\n\t\t\t\t\t&= 236.052595\\text{ amu}\n\\end{align*}\nThe excitation energy of $^{236}$U is the difference between the total mass-energy of the system and the rest-mass of $^{236}$U (multiplied by $c^2$, converting the mass-energy in amu to MeV).\n\\begin{align*}\nE_{\\text{ex}}\t&= \\left[m(^{236}\\text{U}^*) - m(^{236}\\text{U})\\right]c^2 \\\\\n\t\t\t\t&= \\left[236.052595\\text{ amu} - 236.045568\\text{ amu}\\right]c^2 \\\\\n\t\t\t\t&= (0.007027\\text{ amu})c^2 \\\\\nE_{\\text{ex}}\t&= 6.545\\text{ MeV} \n\\end{align*}\n\n\n\\item\n\nThe total mass-energy of the excited $^{239}$U atom is the sum of the masses of the reactants: the $^{238}$U atom and the neutron.\n\\begin{align*}\nm(^{239}\\text{U}^*)\t&= m(^{238}\\text{U}) + m_n \\\\\n\t\t\t\t\t&= 238.050788\\text{ amu} + 1.00866492\\text{ amu} \\\\\n\t\t\t\t\t&= 239.059453\\text{ amu}\n\\end{align*}\nThe excitation energy of $^{239}$U is the difference between the total mass-energy of the system and the rest-mass of $^{239}$U (multiplied by $c^2$, converting the mass-energy in amu to MeV).\n\\begin{align*}\nE_{\\text{ex}}\t&= \\left[m(^{239}\\text{U}^*) - m(^{239}\\text{U})\\right]c^2 \\\\\n\t\t\t\t&= \\left[239.059453\\text{ amu} - 239.054293\\text{ amu}\\right]c^2 \\\\\n\t\t\t\t&= (0.005160\\text{ amu})c^2 \\\\\nE_{\\text{ex}}\t&= 4.806\\text{ MeV} \n\\end{align*}\n\n\n\\item\n\nThe 6.545 MeV excitation energy of the $^{236}$U is greater than the 6.2 MeV activation energy of the fission process for that nucleus. This means that even when a $^{235}$U nucleus absorbs a neutron with zero kinetic energy, fission is possible---$^{235}$U is fissile. $^{238}$U does not exhibit this property. When $^{238}$U absorbs a neutron and forms $^{239}$U, the excitation energy of 4.806 MeV is less than the activation energy of 6.6 MeV for fission to occur. This means that the absorbed neutron must have more than about 1.8 MeV of kinetic energy to trigger fission, and so $^{238}$U is fissionable.\n\n\n\\item\n\nThis absorption reaction is given by\n$$ ^{238}\\text{U} + n + 2\\text{ MeV} = ^{132}\\text{Sn} + ^{106}\\text{Mo} + n + \\blacksquare\\text{ MeV} .$$\nUsing the masses provided, we can calculate the mass-energy of the reactants to be\n\\begin{align*}\nE_r\t&= \\left[m(^{238}\\text{U}) + m_n\\right]c^2 \\\\\n\t&= \\left(238.050788\\text{ amu} + 1.00866492\\text{ amu}\\right)c^2 \\\\\n\t&= 222.673\\text{ GeV},\n\\end{align*}\nand the mass energy of the products to be\n\\begin{align*}\nE_p\t&= \\left[m(^{132}\\text{Sn}) + m(^{106}\\text{Mo}) + m_n\\right]c^2 \\\\\n\t&= \\left(131.917816\\text{ amu} + 105.918137\\text{ amu} + 1.00866492\\text{ amu}\\right)c^2 \\\\\n\t&= 222.473\\text{ GeV}\n\\end{align*}\nWhen we add the 2 MeV of kinetic energy, $T$ of the incoming neutron, we find that the $Q$-value of this fission reaction is\n$$ E_r + T - E_p = 222.673\\text{ GeV}\n + 0.002\\text{ GeV} - 222.473\\text{ GeV} = 205\\text{ MeV} $$\nWe are told that the product neutron carries 2.5\\% of this energy,\n\\begin{align*}\nE_n\t&= 0.025(205\\text{ MeV}) \\\\\n\t&= 5.125\\text{ MeV}. \n\\end{align*}\n\n\\underline{This is more than the 1.8 MeV of kinetic energy required to trigger another fission in $^{238}$U, and fission may occur.}\n\\end{enumerate}\n\\-\\\\\n{\\small *Remember that not all neutrons are born with this energy, but rather in an energy spectrum. In reality, many neutrons produced from a $^{238}$U fission event will not cause subsequent fission events.} \n\n", "meta": {"hexsha": "2798f36d66729d892a195365a2cc5ee080acd7c8", "size": 3567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc03/disc03_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/disc03/disc03_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/disc03/disc03_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": 48.2027027027, "max_line_length": 610, "alphanum_fraction": 0.6627417998, "num_tokens": 1315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101077, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6664644807092527}}
{"text": "\\section*{Exercise 5.1}\r\nWe know that $\\bar{x}=26.035$, $s=4.78476$. Here the null hypothesis is\r\n\\spl{\r\n    H_0:\\ \\mu\\leq25.\r\n}\r\n\r\nHence,\r\n\\spl{\r\n    &P[\\overline{X}\\geq\\overline{x}\\big|\\mu\\leq25]\\leq P[\\overline{X}\\geq\\overline{x}\\big|\\mu=25]\\\\\r\n    =&P[\\frac{\\bar{X}-25}{s/\\sqrt{n}}\\geq\\frac{26.035-25}{s/\\sqrt{n}}]\\\\\r\n    =&P[T_{19}\\geq\\frac{26.035-25}{4.78476}]\\\\\r\n    =&P[T_{19}\\geq0.97]\\\\\r\n    \\approx&0.17>0.05.\r\n}\r\n\r\nIf we set $\\alpha=0.05$, then $t_{0.05}(19)=1.729$.\r\n\r\nWe can reject $H_0$ if $t=0.97>t_{0.05}(19)$ but we fail, which means we say that we have no significant evidence to reject that $\\mu\\leq25$. Hence, we support the claim. The P-value is approximately 0.17.\r\n\r\n\\section*{Exercise 5.2}\r\n\\enum{\r\n\\item\r\nWe denote that $Z=\\frac{\\overline{X}-\\mu_0}{\\sigma/\\sqrt{n}}$.\r\n\\spl{\r\n    \\alpha&=P[\\text{reject }H_0\\big|H_0 \\text{ true}]\\\\\r\n    &=P[\\overline{X}\\geq\\overline{x}\\big|\\mu\\leq4]\\\\\r\n    &\\leq P[\\overline{X}\\geq\\overline{x}\\big|\\mu=4]\\\\\r\n    &=P[Z\\geq\\frac{\\overline{x}-4}{0.2/\\sqrt{50}}]\\\\\r\n    &=P[Z\\geq z_{\\alpha}]\\\\\r\n    &\\overset{!}{=}0.05.\r\n}\r\n\r\nSince $z_{0.05}=1.645$, then\r\n\\spl{\r\n    \\frac{\\overline{x}-4}{0.2/\\sqrt{50}}&=1.645\\\\\r\n    \\overline{x}&=4.047.\r\n}\r\n\r\nThus the critical region is\r\n\\spl{\r\n    \\overline{X}\\geq4.047.\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    P&=P[\\text{reject } H_0\\big|H_1 \\text{ true}]\\\\\r\n    &=P[Z\\geq z_{\\alpha=0.05}\\big|\\mu\\geq4.5]\\\\\r\n    &\\geq P[\\frac{\\overline{X}-4}{0.2/\\sqrt{50}}\\geq1.645\\big|\\mu=4.5]\\\\\r\n    &=P[\\overline{X}\\geq4.047\\big|\\mu=4.5]\\\\\r\n    &=1-\\Phi(\\frac{4.047-4.5}{0.2/\\sqrt{50}})\\\\\r\n    &=1.\r\n}\r\n\r\nHence, the power of this test is 1.\r\n\r\n\\item\r\nSince $z_{1-0.97}=-1.885$, then $z\\leq-1.885$, which means\r\n\\spl{\r\n    \\frac{\\overline{X}-4.5}{0.2/\\sqrt{n}}=\\frac{(z_{0.05}\\times0.2/\\sqrt{n}+4)-4.5}{0.2/\\sqrt{n}}&\\leq-1.885,\\\\\r\n}\r\nwhich gives $n\\geq1.99$.\r\n\r\nHence, the sample size is at least 2.\r\n\r\n\\item\r\nSince $\\bar{x}=4.05>4.047$, we conclude that we can reject $H_0$ at $p<0.05$. \r\n\r\nA 95\\% confidence interval for $\\mu$ is $4.05\\pm\\frac{z_{0.025}\\cdot0.2}{\\sqrt{50}}=4.05\\pm0.06$\r\n}\r\n\r\n\\section*{Exercise 5.3}\r\n\\enum{\r\n\\item\r\n\\spl{\r\n    n=8,\\quad \\sigma=4,\\quad \\mu_0=100.\r\n}\r\n\r\nThus the normalized statistic is\r\n\\spl{\r\n    z=\\frac{\\bar{x}-100}{4/\\sqrt{8}}=1.556\r\n}\r\n\r\nSince $z_{0.05}=1.645<1.556$, then we conclude that we reject $H_0$ at $p<0.05$ .\r\n\r\n\\item\r\n\\spl{\r\n    p&=P[\\overline{X}\\geq\\bar{x}\\big|\\mu\\leq100]\\\\\r\n    &\\leq P[Z\\geq1.556]\\\\\r\n    &=(0.0606+0.5904)/2\\\\\r\n    &=0.06.\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    \\text{Power}&=P[\\text{reject }H_0\\big|\\mu=105]=P[Z\\geq z_{0.05}\\big|\\mu=105]\\\\\r\n    &=P[\\frac{\\overline{X}-100}{4/\\sqrt{8}}\\geq z_{0.05}\\big|\\mu=105]\\\\\r\n    &=P[\\overline{X}\\geq102.3\\big|\\mu=105]\\\\\r\n    &=1-\\Phi(\\frac{102.3-105}{4/\\sqrt{8}})\\\\\r\n    &=0.9706.\r\n}\r\n\r\n\\item\r\nSince $z_{1-0.85}=-1.035$, then $z\\leq-1.035$, which means\r\n\\spl{\r\n    \\frac{\\overline{X}-105}{4/\\sqrt{n}}=\\frac{(z_{0.05}\\times4/\\sqrt{n}+100)-105}{4/\\sqrt{n}}&\\leq-1.035,\\\\\r\n}\r\nwhich gives $n\\geq4.60$.\r\n\r\nHence, the sample size is at least 5.\r\n\r\n\\item\r\nIf we construct a 95\\% lower confidence bound for $\\mu$, which is\r\n\\spl{\r\n    \\mu\\geq\\overline{X}-\\frac{z_{0.05}\\cdot4}{\\sqrt{8}}=102.2-2.3=99.9.\r\n} \r\nHence, we can say $\\mu\\geq99.9$ with the confidence of 95\\%. It's equivalent to the test in part(i). The results are both rejecting $H_0$.\r\n}\r\n\r\n\\section*{Exercise 5.4}\r\nDenote that\r\n\\spl{\r\n    G&=\\sum_{k=1}^nX_k,\\\\\r\n    K&=\\frac{2}{\\beta}\\sum_{k=1}^nX_k.\r\n}\r\n\r\n\\spl{\r\n    F_K(y)&=P[K\\leq y]=P[G\\leq y\\cdot\\beta/2],\\\\\r\n    f_K(y)&=F_K'(y)=\\frac{\\beta}{2}f_G(y\\cdot\\frac{\\beta}{2}).\r\n}\r\n\r\nThen when $y>0$,\r\n\\spl{\r\n    f_K(y)&=\\frac{\\beta}{2}\\frac{1}{\\Gamma(n)\\beta^n}\\bigg(y\\cdot\\frac{\\beta}{2}\\bigg)^{n-1}e^{-\\frac{y\\beta}{\\beta\\cdot2}}\\\\\r\n    &=\\bigg(\\frac{\\beta}{2}\\bigg)^n\\frac{1}{\\Gamma(n)\\beta^{n}}y^{n-1}e^{-\\frac{y}{2}}\\\\\r\n    &=\\frac{1}{\\Gamma(n)2^{n}}y^{n-1}e^{-\\frac{y}{2}}\\\\\r\n    &=\\frac{1}{\\Gamma(n'/2)2^{n'/2}}y^{n'/2-1}e^{-\\frac{y}{2}}\\\\\r\n    &=f_{\\chi_{n'}^2}(y).\r\n}\r\n\r\nwhere $n'=2n$.\r\n\r\nHence, $K$ follows a chi-squared distribution with $2n$ degrees of freedom.\r\n\r\nFor $H_0:\\ \\beta=\\beta_0$,\r\n\\spl{\r\n    \\chi_{1-\\alpha/2,2n}^2 &\\leq K\\leq\\chi_{\\alpha/2,2n}^2\\\\\r\n    \\chi_{1-\\alpha/2,2n}^2 &\\leq \\frac{2}{\\beta}\\sum_{k=1}^n \\overline{X}_k\\leq\\chi_{\\alpha/2,2n}^2\\\\\r\n    \\frac{\\chi_{1-\\alpha/2,2n}^2}{2\\sum_{k=1}^n \\overline{X}_k} &\\leq \\frac{1}{\\beta}\\leq\\frac{\\chi_{\\alpha/2,2n}^2}{2\\sum_{k=1}^n \\overline{X_k}}\\\\ \r\n    \\frac{2\\sum_{k=1}^n \\overline{X_k}}{\\chi_{\\alpha/2,2n}^2}&\\leq\\beta\\leq\\frac{2\\sum_{k=1}^n \\overline{X_k}}{\\chi_{1-\\alpha/2,2n}^2}.\r\n}\r\n\r\nHence the critical region is \r\n\\spl{\r\n    \\beta\\leq\\frac{2\\sum_{k=1}^n \\overline{X_k}}{\\chi_{\\alpha/2,2n}^2}\\text{ or }\\beta\\geq\\frac{2\\sum_{k=1}^n \\overline{X_k}}{\\chi_{1-\\alpha/2,2n}^2}.\r\n}\r\n\r\nFor $H_0:\\ \\beta\\leq\\beta_0$,\r\n\\spl{\r\n    K&\\geq\\chi_{\\alpha,2n}^2\\\\\r\n    \\beta&\\leq\\frac{2\\sum_{k=1}^n \\overline{X_k}}{\\chi_{\\alpha,2n}^2}.\r\n}\r\n\r\nHence the critical region is \r\n\\spl{\r\n    \\beta\\geq\\frac{2\\sum_{k=1}^n \\overline{X_k}}{\\chi_{\\alpha,2n}^2}.\r\n}", "meta": {"hexsha": "ed134b8048f1e096aee190105556d22682049d9b", "size": 4988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE401ProbStat/Assignments/Assignment5/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/Assignment5/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/Assignment5/sections/solution.tex", "max_forks_repo_name": "PANDApcd/Calculus", "max_forks_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0481927711, "max_line_length": 206, "alphanum_fraction": 0.5635525261, "num_tokens": 2301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6664591170804501}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Definition}\n\n\\objective{Describe and predict the general shape of a polynomial graph}\n\n\nA polynomials is sum of terms, all of which are of the form $a\\cdot{}x^n$, where $a$\nis any rational number and $n$ is a whole number.\n\n\\subsubsection{Degree}\n``In the long run, the biggest exponent always wins.''  While it may sound like a odd\ncliche from a movie, it is certainly true.  What is more, there are only two possibilities\nfor polynomials: either larger and larger numbers are being raised to an even degree,\nor they are being raised to an odd one.  Positive numbers grow more positive in either case.\nNegative numbers become positive, when raised to an even degree.  They grow more\nnegative when raised to an odd degree.\n\nOf course, in the short, all manner of other behaviors may be manifested, but it is \nimportant to consider limits at the infinities, so that we may be sure of the ultimate\nleftward or rightward behavior of a function.\n\n\\personfeature[-1in]{\\chapdir/pics/1983_CPA_5426}{Muhammad ibn Musa al-Khwarizmi}{\n780-850}{was a Persian/Uzbekh mathematician, astronomer, and geographer \nduring the Abbasid Caliphate, a scholar in the House of Wisdom in Baghdad.\n``Algebra'' is derived from al-jabr, one of the two operations he used to solve quadratic equations. \n``Algorithm'' stems from the Latin form of his name.\n\\href{https://en.wikipedia.org/wiki/Muhammad_ibn_Musa_al-Khwarizmi}{Wikipedia}}\n\n\\subsubsection{Leading Coefficient}\nWhile it is true that there are only two possibilities for the integer $n$ in the \nexpression $x^n$ (either it is even, or it is odd), there are two more things that could \nhappen, when we consider $a\\cdot{}x^n$: $a$ could be positive or negative.\nIn summary, even polynomials go ``up'' at both ``ends'', unless the leading coefficient\nis negative, in which case both ends go ``down''.  Odd functions go up to the right and\ndown to the left, unless the leading coefficient is negative, in which case the opposite\nhappens.\n\nIf we are designing a function ourselves, it can still be useful to consider\nend-run behavior.  For example, we might construct a polynomial to have\n$x$-intercepts 3, 5, and $-\\frac{1}{2}$.  We would write $f(x)=(x-3)(x-5)(2x+1)$,\nseemingly obfuscating the leading term.  However, if we multiply only the $x$ terms,\nwe can still find it quickly.  $x \\cdot x \\cdot 2x$ is $2x^3$, so we can see this is\na positive, odd polynomial, going up to the right and down to the left.\n\n\\subsubsection{$y$-intercept}\nAnother facet of polynomials that is still quickly discernible even in factored form\nis the constant term.  This term (even if it is 0, i.e. absent) provides useful information.\nWhen $x=0$ (which typically corresponds to something like an initial condition), the\nonly term not to cancel will be the constant one.  In the previous example, we can \neasily multiply the plain numbers: $-3 \\cdot -5 \\cdot 1 = 15$, so we know the\n$y$-intercept of the function will be 15.  If we need a different number, the function\ncan always be scaled by multiplying on the outside by a constant, which could even\nbe negative.\n\n\\subsection{Factored Forms}\nWhen we examined quadratics, there were some cases in which the vertex of the\nparabola was found on the $x$-axis.  A similar case can be found in polynomials of\nhigher degree, and can be seen in their factored forms.  For example,\n$f(x)= (x-2)^2(x+5)$ is a cubic equation  (with leading term $x^3$ and constant term\n20) which seems to have only two zero's: 2 and -5.  However, the number 2 works as\na solution \\emph{twice}, and so we say it has a \\textbf{multiplicity} of 2.\n\nGraphically, multiplicity means the graph resembles the exponent of the factored term.\nThis means $f(x)$ will behave like $x^2$ in the vicinity of 2.  Note that this behavior\nmay be upside-down, depending on the equation.  Generalizing even more, we can say\nthat even powers on a factor will result in the graph \\emph{not} crossing the $x$-axis\nat that zero, but only ``bouncing'' off.  On the other hand, odd powers on a factor\n(even including 1!) will appear as the graph proceeding \\emph{through} the $x$-axis.\n\n", "meta": {"hexsha": "8e849458380be1d2ae0a07a4b0a8a9261754fc8f", "size": 4140, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch06/0601.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/0601.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/0601.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.3098591549, "max_line_length": 101, "alphanum_fraction": 0.7572463768, "num_tokens": 1101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6664591106300561}}
{"text": "\\documentclass{article}\n%\\usepackage{tikzpicture}\n\\begin{document}\n\n\\tableofcontents\n\n\\section{Introduction}\n\n\\subsection{Natural numbers}\n\n$N$ - natural numbers, $N = \\{1, 2, 3, \\dots\\}$\nOperations: +, *\n\\paragraph{Properties of addition and multiplication}\n\\begin{itemize}\n    \\item $a + b = b + a$ - commutative law for addition\n    \\item $(a + b) + c = a + (b + c)$ - associative law for addition\n    \\item $a * b = b * a$ - commutative law for multiplication\n    \\item $(a * b) * c = a * (b * c)$ - associative law for multiplication\n    \\item $(a + b) * c = ac + bc$ - distributive law\n\\end{itemize}\n\n\\subsection{Mathematical induction}\n\n\\paragraph{Theorem:}\\mbox{} \\\\\nIf $A \\subset N$ and\\\\\n\\indent a) $1 \\in A$\\\\\n\\indent b) If $k \\in A$, then $k + 1 \\in A$\\\\\nthen\\\\\n\\indent $A = N$\n\n\\paragraph{Theorem: The Principle of Mathematical Induction}\\mbox{} \\\\\nIf $p_1, p_2, \\dots$ are statements (true/false) and\\\\\n\\indent a) $p_1$ is true\\\\\n\\indent b) If $p_k$ is true, then $p_{k+1}$ is also true\\\\\nthen\\\\\n\\indent all the statements $p_1, p_2, \\dots$ are true\\\\\n\\\\\n\\textbf{\\textit{Proof:}}\\\\\n$Let A = \\{k \\in N: p_k\\;is\\;true\\}$\\\\\nClearly, if $1 \\in A$ and if $k \\in A$, then $k \\neq 1 \\in A$\\\\\nSo $A = N$\\\\\n\\\\\n\\textbf{\\textit{Examples:}}\n\\begin{itemize}\n    \\item $1 + 2 + \\dots + n = \\frac{n(n + 1)}{2}$, $n \\in N$\\\\\n    a) for $n = 1$: $1 = \\frac{1(1 + 1)}{2}$\\\\\n    b) suppose for some $k$: $1 + 2 + \\dots = \\frac{k(k+1)}{2}$\\\\\n    then\\\\\n    $1 + 2 + \\dots + (k + 1) = \\frac{(k+1)(k+2)}{2}$\\\\\n    $1 + 2 + \\dots + k + (k + 1) = \\frac{(k+1)(k+2)}{2}$\\\\\n    so\n    $1 + 2 + \\dots + n = \\frac{n(n+1)}{2}$ for all $n \\in N$\\\\\n\\end{itemize}\n\n\\paragraph{Theorem: The Generalized Principle of Mathematical Induction}\\mbox{} \\\\\nIf $p_1, p_2, \\dots$ are statements (true/false) and\\\\\n\\indent a) $p_{k_o}$ is true\\\\\n\\indent b) If $p_k$ is true, then $p_{k+1}$ is also true\\\\\nthen\\\\\n\\indent all the statements $p_{k_o}, p_{k_o+1}, \\dots$ are true\\\\\n\\\\\n\n\\subsection{Sigma notation}\n\\paragraph{Definition}\\mbox{} \\\\\nIf $a_1, a_2, \\dots, a_n \\in R$\\\\\nthen their sum $a_1 + a_2 + \\dots + a_n$ will be denoted by $\\sum^{n}_{k=1}a_k$.\n\\paragraph{Properties}\n\\begin{itemize}\n    \\item $\\sum^{n}_{k=1}(a_k + b_k) = \\sum^{n}_{k=1}(a_k) + \\sum^{n}_{k=1}(b_k)$\n    \\item $\\sum^{n}_{k=1}(c*a_k) =  c*\\sum^{n}_{k=1}(a_k)$\n\\end{itemize}\n\n\\subsection{Binomial expansion}\n\\paragraph{Pascal's triangle}\\mbox{}\\\\\\\\\n\\newcommand{\\ap}{\\ensuremath{\\swarrow\\,\\searrow}}\n\\setlength{\\tabcolsep}{0pt}\n\\begin{tabular}{ccccccccc}\n  &     &     &      & 1   &      &      &     & \\\\\n  &     &     &      & \\ap &      &      &     & \\\\\n  &     &     & 1    &     &  1   &      &     & \\\\\n  &     &     & \\ap  &     &  \\ap &      &     & \\\\\n  &     & 1   &      & 2   &      & 1    &     & \\\\\n  &     & \\ap &      & \\ap &      & \\ap  &     & \\\\\n  & 1   &     & 3    &     &  3   &      & 1   & \\\\\n  &\\ap  &     & \\ap  &     &  \\ap &      & \\ap & \\\\\n1 &     & 4   &      & 6   &      & 4    &     & 1\n\\end{tabular}\n\\paragraph{Binomial coefficient (Newton's symbol)}\\mbox{}\\\\\n${n \\choose k} = \\frac{n!}{k!(n-k)!}$ - number of k-element subsets of n-element set\\\\\n\\paragraph{Theorem: Newton's binomial expansion formula}\\mbox{}\\\\\n$(a+b)^n={n \\choose 0}a^{n}b^{0}+{n \\choose 1}a^{n-1}b^{1}+\\dots+{n \\choose k}a^{n-k}b^{k}+\\dots+{n \\choose n}a^{0}b^{n}$\\\\\n$(a+b)^n=\\sum^n_{k=0} {n \\choose k}a^{n-k}b^k$\n\n\\subsection{Logic}\n%TODO here\n\\begin{displaymath}\n    \\begin{array}{|c c|c|}\n        p & q & p \\land q\\\\ % Use & to separate the columns\n        \\hline % Put a horizontal line between the table header and the rest.\n        T & T & T\\\\\n        T & F & F\\\\\n        F & T & F\\\\\n        F & F & F\\\\\n    \\end{array}\n\\end{displaymath}\n\n\\subsection{Quantifiers}\n%TODO here\ntodo\n\n\\section{Complex numbers}\n\\subsection{Introduction}\n\\paragraph{Definition}\nComplex number is a pair of real numbers.\\\\\nExamples: $(2,3)$, $\\sqrt{2},5)$\\\\\nWe will usually denote them by $z, w, \\dots$.\\\\\nIf $z=(x,y)$ ($x, y \\in R$ - we can skip it)\\\\\nthen $x$ is called the \\textbf{real part} of \\textbf{z} and it will be denoted by $Re z$, $y$ will be called the \\textbf{imaginary part} of \\textbf{z} and denoted by $Im z$.\\\\\nThe set of all complex numbers will be denoted by $C$, so\\\\\n$C = \\{(x, y): x, y \\in R\\}$\n\\paragraph{Geometric interpretation of C}\\mbox{}\\\\\n% \\begin{tikzpicture}\n%     \\begin{axis}[\n%     axis x line=center,\n%     axis y line=none,\n%     xmin=-3,xmax=3,\n%     ]\n%     \\end{axis}\n% \\end{tikzpicture}\n\\begin{itemize}\n    \\item points on a plane\n    \\item vectors on a plane\n    \\item free vectors (not starting at origin, but at any point)\n\\end{itemize}\n\\subsection{Algebra on complex numbers}\\mbox{}\\\\\n\\begin{itemize}\n    \\item addition\\\\\n    If $z = (x_1, y_1), w = (x_2, y_2)$ then $z + w$ is defined as\\\\\n    $(x_1 + x_2, y_1 + y_2)$ (just like addition of vectors).\n    %TODO theorem\n    \\item multiplication\\\\\n    If $z = (x_1, y_1), w = (x_2, y_2)$ then $z * w$ is defined as\\\\\n    $(x_1 x_2 - y_1 y_2,\\;x_1 y_2 + x_2 y_1)$\n\\end{itemize}\n\\end{document}", "meta": {"hexsha": "a9997b21fe301ba64e9ba2a5a167eacf73c3cc7b", "size": 5020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "year-1/algebra/algebra.tex", "max_stars_repo_name": "Kartm/university-notes", "max_stars_repo_head_hexsha": "5816ad615f338d52f764af944b67b61f3b6fea63", "max_stars_repo_licenses": ["MIT"], "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/algebra/algebra.tex", "max_issues_repo_name": "Kartm/university-notes", "max_issues_repo_head_hexsha": "5816ad615f338d52f764af944b67b61f3b6fea63", "max_issues_repo_licenses": ["MIT"], "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/algebra/algebra.tex", "max_forks_repo_name": "Kartm/university-notes", "max_forks_repo_head_hexsha": "5816ad615f338d52f764af944b67b61f3b6fea63", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-12T11:43:40.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-12T11:43:40.000Z", "avg_line_length": 34.6206896552, "max_line_length": 175, "alphanum_fraction": 0.5517928287, "num_tokens": 1972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.6664591069338378}}
{"text": "\\chapter{Predicate Formulas}\n\\label{chapter:predicate-formulas}\n\\marginurl{%\n  Predicate Formulas:\\\\\\noindent\n  Introduction to Mathematical Logic \\#5\n}{youtu.be/yb9NvmXyFfg}\n\nIn the previous chapters we studied propositional logic. But in real mathematics\nthere are many non propositional formulas. For example, we may wish to prove\nthat if a relation $R$ on $M$ is transitive, then\n\\[\n  (R(w, x) \\land R(x, y) \\land R(y, z)) \\implies R(w, z)\n\\]\nis true for any $w, x, y, z \\in M$. This chapter defines a logical\nsystem that allows us to formally prove such statements.\n\nLet us write the previous statement in a formula-like form:\n\\begin{multline*}\n    \\overbrace{\n        \\left(\n          \\forall x, y, z \\in M ~ (R(x, y) \\land R(y, z)) \\implies R(x, z)\n         \\right)\n    }^{R \\text{ is transitive}} \\implies \\\\\n    \\underbrace{(\n        \\forall w, x, y, z \\in M ~ (R(w, x) \\land R(x, y) \\land R(y, z))\n        \\implies\n        R(x, z)\n    )}_\\text{the desired conclusion}.\n\\end{multline*}\nNote that there are several things we need to explain if we wish to define\nformally formulas like this:\n\\begin{itemize}\n    \\item we need to explain what kind of sets we can use (in this case we need\n        to define $M$),\n    \\item we need to explain what kind of relations we can use (in this case we\n        need to define $R$),\n\\end{itemize}\n\nAnother example of a statement we may wish to prove is saying that if\n$f : M \\to M$ is an inverse of itself (i.e. $f(f(x)) = f(x)$ for any $x \\in M$),\nthen $f(f(f(x))) = f(x)$ for any $x \\in M$; more formally, we may wish to prove\nthe statement\n\\[\n    \\underbrace{\n        (\\forall x \\in M ~ f(f(x)) = x)}_{f \\text{is an inverse of itself}}\n    \\implies\n    \\underbrace{\n        (\\forall x \\in M ~ f(f(f(x))) = f(x))\n    }_\\text{the desired conclusion}.\n\\]\nIn order to explain what we mean by such formulas\n\\begin{itemize}\n  \\item we need to explain what kind functions we can use (in this case we need\n    to define $f$).\n\\end{itemize}\n\n\\paragraph{Signature.}\nIn predicate logic, formula uses just symbols for all these objects. We specify\nthese symbols only when we wish to compute actual truth value of the formula.\nWe also assume that all the quantifiers are over the same set so we do not need\na symbol for the set $M$.\n\nSignature is the way to define the list of all these symbols, it consists of\nthree objects:\n\\begin{itemize}\n  \\item a set (possibly empty) of symbols for relations,\n  \\item a set (possibly empty) of symbols for functions,\n  \\item arities of these functions and relations (i.e. how many arguments they\n    may take).\n\\end{itemize}\nAn example of a signature is a triple $(\\set{\\text{``R''}}, \\set{\\text{``f''}},\na)$, where\n\\[\n  a(s) = \\begin{cases}\n    2 & \\text{if } s =  \\text{``R''} \\\\\n    1 & \\text{if } s =  \\text{``f''}\n  \\end{cases}.\n\\]\nThis signature is enough to define the formulas we discussed. Now we are ready\nto define the predicate formulas.\n\n\\begin{definition}\n  Let $\\signature{S} = (S_\\mathrm{rel}, S_\\mathrm{fun}, a)$ be a signature and $V$\n  be some set.\n\n  We say that $t$ is a \\emph{term} in the signature $\\signature{S}$ over the variables\n  from $V$ if\n  \\begin{itemize}\n    \\item either $t$ is equal to $x$ for $x \\in V$,\n    \\item or $t$ is equal to $f(t_1, \\dots, t_{a(f)})$, where\n      $f \\in S_\\mathrm{fun}$ and $t_1$, \\dots, $t_{a(f)}$ are terms in the\n      signature $\\mathcal{S}$ over the variables from $V$.\n  \\end{itemize}\n\n  We say that $\\phi$ is a \\emph{predicate formula} in the signature\n  $\\signature{S}$ over the variables from $V$ if\n  \\begin{itemize}\n    \\item either $\\phi$ is equal to $R(t_1, \\dots, t_{a(R)})$, where\n      $R \\in S_\\mathrm{rel}$ and $t_1$, \\dots, $t_{a(R)}$ are terms in the\n      signature $\\signature{S}$ over the variables from $V$,\n    \\item or $\\phi$ is equal to $(\\psi_1 \\land \\psi_2)$, or\n      $(\\psi_1 \\lor \\psi_2)$, or $(\\psi_1 \\limplies \\psi_2)$, where $\\psi_1$ and\n      $\\psi_2$ are predicate formulas in the signature $\\signature{S}$ over the\n      variables from $V$,\n    \\item or $\\phi$ is equal to $(\\lnot \\psi)$, where $\\psi$ is a predicate\n      formula in the signature $\\signature{S}$ over the variables from $V$,\n    \\item or $\\phi$ is equal to $\\left( \\exists x_i~\\psi \\right)$ or \n      $\\left( \\forall x_i~\\psi \\right)$ where\n      $\\psi$ is a predicate formula in the signature $\\signature{S}$ over the\n      variables from $V$.\n  \\end{itemize}\n\n  We denote by $\\pred{V}{\\signature{S}}$ the set of all predicate formulas in\n  $\\signature{S}$ over the variables from $V$; we also denote by\n  $\\term{V}{\\signature{S}}$ the set of all terms in $\\signature{S}$ over the\n  variables from $V$.\n\\end{definition}\n\nIn order to compute the truth value of a predicate formula, we need to specify\nthe values of all the free variables and all the symbols from the signature.\nThe specification of the symbols from the signature is called structure; i.e.\na structure for a signature \n$\\signature{S} = (S_\\mathrm{rel}, S_\\mathrm{fun}, a)$\nis a triple $\\structure{M} = (M, F_\\mathrm{rel}, F_\\mathrm{fun})$ such that\n\\begin{itemize}\n  \\item $F_\\mathrm{rel}$ assigns a relation to every relation symbol in\n    $\\signature{S}$; i.e., \n    $F_\\mathrm{rel} : S_\\mathrm{rel} \\to \\bigcup_{i = 0}^\\infty 2^{M^i}$\n    such that $F_\\mathrm{rel}(R) \\in 2^{M^{a(R)}}$ and\n  \\item $F_\\mathrm{fun}$ assignes a function to every function symbol in\n    $\\signature{S}$; i.e.,\n    $F_\\mathrm{fun} : S_\\mathrm{fun} \\to \\bigcup_{i = 0}^\\infty M^{M^i}$\n    such that $F_\\mathrm{fun}(f) \\in M^{M^{a(f)}}$.\n\\end{itemize}\nThe set $M$ in the structure is called the \\emph{domain} of the structure and\ndenoted by $\\domain{\\structure{M}}$. We also denote $F_\\mathrm{rel}(R)$ by\n$R^{\\structure{M}}$ and $F_\\mathrm{fun}(f)$ by $f^{\\structure{M}}$.\n\n\n\\begin{definition}\n  Let $\\signature{S} = (S_\\mathrm{rel}, S_\\mathrm{fun}, a)$ be a signature and\n  $\\structure{M}$ be a structure for $\\signature{S}$.\n\n  Let $\\rho : V \\to \\domain{\\structure{M}}$.\n  The valuation of terms in $\\signature{S}$ over the variables from $V$\n  corresponding to the assignement $\\rho$ is the function \n  $\\substitute{\\cdot}{\\rho, \\structure{M}} : \n    \\term{V}{\\signature{S}} \\to \\domain{\\structure{M}}$ such that\n  \\begin{itemize}\n    \\item $\\substitute{x}{\\rho, \\structure{M}} = \\rho(x)$ for any $x \\in V$,\n    \\item $\\substitute{f(t_1, \\dots, t_\\ell)}{\\rho, \\structure{M}} = \n      f^{\\structure{M}}(\n        \\substitute{t_1}{\\rho, \\structure{M}},\n        \\dots,\n        \\substitute{t_\\ell}{\\rho, \\structure{M}}\n      )$ \\,\n      for any function symbol $f \\in S_\\mathrm{fun}$ and \n      terms $t_1, \\dots, t_\\ell \\in \\term{V}{\\signature{S}}$.\n  \\end{itemize}\n\n  Similarly we may define valuations of predicate formulas (we will abuse the\n  notation and denote them by $\\substitute{\\cdot}{\\rho, \\structure{M}}$ too).\n  The valuation of predicate formulas in $\\signature{S}$ over the variables from\n  $V$ corresponding to the assignement $\\rho$ is the function\n  $\\substitute{\\cdot}{\\rho, \\structure{M}} :\n    \\pred{V}{\\signature{S}} \\to \\domain{\\structure{M}}$ such that\n  \\begin{itemize}\n    \\item $\\substitute{R(t_1, \\dots, t_\\ell)}{\\rho, \\structure{M}} = \n      R^{\\structure{M}}(\n        \\substitute{t_1}{\\rho, \\structure{M}}),\n        \\dots,\n        \\substitute{t_\\ell}{\\rho, \\structure{M}})\n      $\\,\n      for any relation symbol $R \\in S_\\mathrm{rel}$ \n      and terms $t_1, \\dots, t_\\ell \\in \\term{V}{\\signature{S}}$,\n    \\item \n      $\n        \\substitute{\\psi_1 \\land \\psi_2}{\\rho, \\structure{M}} = \n        \\substitute{\\psi_1}{\\rho, \\structure{M}} \\land\n        \\substitute{\\psi_2}{\\rho, \\structure{M}}\n      $\\,\n      for any $\\psi_1, \\psi_2 \\in \\pred{V}{\\signature{S}}$,\n    \\item \n      $\n        \\substitute{\\psi_1 \\lor \\psi_2}{\\rho, \\structure{M}} = \n        \\substitute{\\psi_1}{\\rho, \\structure{M}} \\lor\n        \\substitute{\\psi_2}{\\rho, \\structure{M}}\n      $\\,\n      for any $\\psi_1, \\psi_2 \\in \\pred{V}{\\signature{S}}$,\n    \\item \n      $\n        \\substitute{\\psi_1 \\limplies \\psi_2}{\\rho, \\structure{M}} = \n        \\substitute{\\psi_1}{\\rho, \\structure{M}} \\limplies\n        \\substitute{\\psi_2}{\\rho, \\structure{M}}\n      $\\,\n      for any $\\psi_1, \\psi_2 \\in \\pred{V}{\\signature{S}}$,\n    \\item \n      $\n        \\substitute{\\lnot \\psi}{\\rho, \\structure{M}} = \n        \\lnot \\substitute{\\psi_1}{\\rho, \\structure{M}}\n      $\\,\n      for any $\\psi \\in \\pred{V}{\\signature{S}}$,\n    \\item for $\\psi \\in \\pred{V}{\\signature{S}}$,\n      $\n        \\substitute{\\exists x \\  \\psi}{\\rho, \\structure{M}} = \n        \\ltrue  \n      $ iff \n      $\\substitute{\\psi}{\\assign{\\rho}{x}{v}, \\structure{M}} = \\ltrue$\n      for some $v \\in \\domain{\\structure{M}}$, and\n    \\item for $\\psi \\in \\pred{V}{\\signature{S}}$,\n      $\n        \\substitute{\\forall x \\  \\psi}{\\rho, \\structure{M}} = \n        \\ltrue  \n      $ iff \n      $\\substitute{\\psi}{\\assign{\\rho}{x}{v}, \\structure{M}} = \\ltrue$\n      for all $v \\in \\domain{\\structure{M}}$.\n  \\end{itemize}\n\n  Let $V = \\set{x_1, \\dots, x_n}$ then we denote the assignement $\\rho : V \\to\n  \\domain{\\structure{M}}$ such that $\\rho(x_i) = v_i$ by \n  $x_1 = v_1, \\dots, x_n = v_n$.\n\\end{definition}\n\nWe say that $\\structure{M}$ is a model of a formula $\\phi$\n(written $\\structure{M} \\models \\phi$)\\footnote{\n  Sometimes ``$\\structure{M}$ is a model of $\\phi$'' is written\n  as $\\models_{\\structure{M}} \\phi$.\n} over the variables\nfrom $V$ iff $\\substitute{\\psi}{\\rho, \\structure{M}} = \\ltrue$ for all $\\rho : V\n\\to \\domain{\\structure{M}}$.\n\nWe also say that $\\phi$ is true in $\\structure{M}$ if $\\structure{M} \\models \\phi$,\nand we say that $\\phi$ is false in $\\structure{M}$ if $\\structure{M} \\not\\models \\phi$.\n\nLet us consider an example:\n\\begin{itemize}\n  \\item First, we define a signature\n    $\\signature{S} = (\\set{=, <}, \\set{+, \\cdot}, a)$ (we write \n    $S = (=, <; +, \\cdot)$ when arities of the functions and relations are clear\n    from the context),\n    where $a(x) = 2$ for any $x \\in \\set{<, =, +, \\cdot}$.\n  \\item After this we define the structure $\\structure{M}$ in signature\n    $\\signature{S}$ such that\n    \\begin{gather*}\n      f^{\\structure{M}}(x, y) = \\begin{cases}\n        x \\cdot y & \\text{if } f \\text{ is } \\cdot \\\\\n        x + y & \\text{if } f \\text{ is } +\n      \\end{cases} \\\\\n      \\text{and} \\\\\n      R^{\\structure{M}}(x, y) \\begin{cases}\n        x = y & \\text{if } R \\text{ is } = \\\\\n        x < y & \\text{if } R \\text{ is } <\n      \\end{cases}\n    \\end{gather*}\n    Note that such a definition is pretty cumbersome, especially considering the\n    fact that we use standard $+$ instead of the symbol $+$,\n    standard $=$ instead of the symbol $=$ etc. So in similar cases we\n    write $\\structure{M} = (\\R; =, <; +, \\cdot)$.\n  \\item Finally, we consider the formulas in $\\signature{S}$ over the set of\n    variables $\\set{x, y, z}$:\n    \\begin{gather*}\n      \\forall x \\ \\forall y \\ x + y = y + x \\\\\n      \\text{and} \\\\\n      \\forall x \\ \\forall y \\ \\forall z \\ (x < y \\implies x + z < y + z).\n    \\end{gather*}\n    (Note that we write $a = b$ instead of $=(a, b)$ and $a + b$ instead of\n    $a + b$, this is a common notation when the standard mathematical\n    operations and relations are used in the signature.)\n\\end{itemize}\nThe first formula says that addition is commutative, which is true in $\\R$, so\nthe value of the formula is true in $\\structure{M}$. \n(Note that we do not mention the values of the variables $x$ and $y$\nsince both of them are not free.) Indeed, consider $a, b \\in \\R$, note that\n$\\substitute{x + y}{x = a, y = b, \\structure{M}} = a + b = b + a = \n  \\substitute{y + x}{x = a, y = b, \\structure{M}}$. Hence, \n$\\substitute{\\forall x \\ \\forall y \\ x + y = y + x}{\\rho, \\structure{M}} = \\ltrue$\nfor all $\\rho$.\n\nThe second formula says that the inequalities are additive, so it should be also\ntrue with respect to the structure $\\structure{M}$.\n\n\\begin{chapterendexercises}\n  \\exercise\n    Show that the second formula is true in $\\structure{M}$.\n  \\exercise\n    Let us consider a signature $(=; +, \\cdot, 0, 1)$ and two models with this\n    signature: $\\structure{R} = (\\R; =; +, \\cdot, 0, 1)$, and\n    $\\structure{Q} = (\\Q; =; +, \\cdot, 0, 1)$.\n    Find a predicate formula $\\phi$ in this signature such that\n    $\\structure{R} \\models \\phi$ but $\\structure{Q} \\not\\models \\phi$.\n\\end{chapterendexercises}\n\n", "meta": {"hexsha": "232690ad0454c543bbb9564d5f85d12db762abe0", "size": 12303, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_7/chapter_33_predicate_formulas.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_7/chapter_33_predicate_formulas.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_7/chapter_33_predicate_formulas.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.9897610922, "max_line_length": 87, "alphanum_fraction": 0.6171665447, "num_tokens": 4035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.666403200247073}}
{"text": "\\section{Fuzzy Inference}\n\nA simplified Sugeno-style fuzzy inference system is developed with functionalities for fuzzy rule / set parsing, input fuzzification, fuzzy inferencing and output defuzzification.\n\n\\subsection{Determining Fuzzy sets}\n\nAs mentioned in the previous section, the noises in the image inevitably introduces uncertainties to our system. Therefore \\textbf{the feature values referenced in our rules have to be represented in fuzzy sets}.\n\nTo determine the \\textbf{best fuzzy sets capturing the appropriate degree of uncertainties}, we use the statistics from the training set to find the optimal threshold.\n\nFor $Thinness$, we use 3 fuzzy sets for ellipse-like, rectangle-like and triangle-like $Extent$ ratio. For $Extent$, we use 2 fuzzy sets for circle-like and square-like $Thinness$ ratio. The shapes and boundries of these fuzzy sets are determined based on the \\textbf{distribution and percentiles of feature values} in the training set. We consider the area between 25th percentile and 75th percentile as the \\textbf{high confidence range}, while the remaining area plus a small portion of area adjacent to the extreme values (to tolerate some outliners) are considered as the \\textbf{low confidence range}. The corresponding polygons are then constructed based on these two ranges to represent the fuzzy sets. The final fuzzy sets are illustrated in Figure 3 (Figures not drawn to scale).\n\n\\begin{figure}\n\n\\begin{subfigure}[b]{\\columnwidth}\n\\includegraphics[width=\\columnwidth]{Figure_3_Fuzzy_Sets_1.png}\n\\caption{Fuzzy Set of Extent}\\end{subfigure}\n\n\\begin{subfigure}[b]{\\columnwidth}\n\\includegraphics[width=\\columnwidth]{Figure_4_Fuzzy_Sets_2.png}\n\\caption{Fuzzy Set of Thinness}\n\\end{subfigure}\n\n\\caption{Fuzzy Sets}\n\n\\end{figure}\n\n\\subsection{Implementing Inference Engine}\n\nNow that the fuzzy sets are determined, we have to implement the inference engine. But the specific nature of our task requires us to make some adaptations to the the usual fuzzy inference engine.\n\nFirstly, unlike the example from the textbook, the set of possible outputs in our task is \\textbf{NOT} a set of linguistic values which can be represented by a series of contiguous intervals. We can't compute a COG-like output and decide which category it falls in, because it's not possible to assign a reasonable order to the shapes.\n\nSecondly, rules derived in the previous section are all of the format:\n\n\\textit{IF X IS LIKE A AND Y IS NOT LIKE B THEN Shape IS C}\n\nNote that the consequent of each rule is an assertion about the shape of the input figure and that \\textbf{each rule corresponds to the recognition process for one specific shape}. In fact a fuzzy inference system of this kind is essentially \\textbf{a flattened decision tree}, with \\textbf{each rule acting as a filter to calculate the possibility of one specific shape}. The only difference is that in our expert system rules are separated from inference, making it easily maintainable.\n\nThus, in order to gain the advantages brought by fuzzy inference without over-complicating our task, we choose to implement \\textbf{a simplified Sugeno-style inference engine}. In the final defuzzification stage, we don't compute a weighted average of the rule outputs. Instead we examine all the possible values for the target variable $Shape$ and \\textbf{choose the one with the highest possibility as the output}.\n", "meta": {"hexsha": "e820bcf620d74ea21e38260b31150eb2173e0822", "size": 3383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/fuzzy_inference.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/fuzzy_inference.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/fuzzy_inference.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": 82.512195122, "max_line_length": 789, "alphanum_fraction": 0.8034289093, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6664031984572452}}
{"text": "\\section{The classifying type of a group}\n\n\\subsection{The classifying type of a group}\n\n\\begin{thm}\n  For every group $G$ there is a pointed connected $1$-type $BG$ equipped with group isomorphism\n  \\begin{equation*}\n    \\loopspace{BG} \\simeq G\n  \\end{equation*}\n\\end{thm}\n", "meta": {"hexsha": "0cf0b4c1c9514e3a7c567648f6ad6812a3e34940", "size": 274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/classifying.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/classifying.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/classifying.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": 24.9090909091, "max_line_length": 96, "alphanum_fraction": 0.7189781022, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6663980711591135}}
{"text": "\n\\input{../preamble}\n\\DeclareMathOperator{\\Ce}{Re}\n\n\n\n\\begin{document}\n\\title{Crash Course on Representation Theory - Day 1}\n\\author{Apurva Nakade}\n\\thispagestyle{fancy}\n\\maketitle\n\n\n\n\nAll the vector spaces will be finite dimensional vector spaces over $\\C$. $G$ will denote a finite group. $V$ will denote a vector space of dimension $d$ over $\\C$. All representations will be finite dimensional.\n\n\\section{Introduction}\nRepresentation theory is based on the philosophy: When life gives you groups, linearize. Groups in general have very little structure on them (only 1 product) and hence are notoriously difficult to analyze. On the other hand there are a lot ways to exploit matrices: addition, multiplication, diagonalization, eigenvalues and eigenvectors, the various canonical forms, etc. As such it is usually quite fruitful to reduce a problem in group theory to one in linear algebra.\n\nTheorems in basic representation theory can be very broadly broken into two kinds: i) structural theorems about existence and classification of representations coming from linear algebra, ii) constructive theorems which actually construct these representations using other techniques like combinatorics. In this class we'll only look at theorems of the first kind.\n\n\\subsection{Frobenius determinant}\nHistorically, a generalization of the following question prompted Frobenius to develop representation theory.\nFor variables $x_0, x_1, \\ldots, x_{n-1}$ define the Frobenius matrix to be a matrix whose $i,j^{th}$ entry is $x_{(i-j \\mod n)}$ i.e. in the $j^{th}$ column $x_i$ is in the row $i+j \\mod n$.\n\\begin{align}\n\tF_n & = \\begin{bmatrix} x_0 & x_{n-1} & \\cdots & x_{1} \\\\ x_{1} & x_0 & \\cdots & x_{2} \\\\ \\vdots&& \\ddots &\\vdots \\\\ x_{n-1} & x_{n-2} & \\cdots & x_0 \\end{bmatrix}\n\\end{align}\n\\begin{ques}\n\tWhat are the irreducible factors of the determinant of $F_n$?\n\\end{ques}\nWe'll use representation theory to answer this question. For small dimensions it is a fun exercise to work out the factors by hand.\n\\begin{align}\n\t\\det \\begin{bmatrix} x_0 & x_1 \\\\ x_1 & x_0 \\end{bmatrix} &= x_0^2 - x_1^2 = (x_0 - x_1)(x_0 + x_1) \\\\\n\t\\det \\begin{bmatrix} x_0 & x_1 & x_2 \\\\ x_1 & x_0 & x_2 \\\\ x_2 & x_1 & x_0 \\end{bmatrix} &= x_0^3 + x_1^3 + x_2^3 - 3 x_0 x_1 x_2\n\t= \\: ??\n\\end{align}\n\n\n\n\\section{Definitions}\nA $d$ dimensional \\textbf{representation} of $G$ is a group homomorphism $$\\rho: G \\rightarrow GL(V)$$ where $V$ is a $d$ dimensional vector space over $\\C$ and $GL(V)$ denotes the group of invertible linear transformations $V \\rightarrow V$. We say that $G$ acts on $V$ or that $V$ has an action of $G$ on it, denoted $G \\circlearrowright V$. It is common to abuse notation and say that $V$ is a representation of $G$. More explicitly, we assign to each element $g \\in G$ a linear transformation $\\rho(g)$ satisfying\n\\begin{enumerate}\n\t\\item $\\rho(e) = I_{V}$ where $e$ is the identity in $G$ and $I_V$ is the trivial linear transformation on $V$\n\t\\item $\\rho(gh) = \\rho(g)\\rho(h)$\n\t\\item $\\rho(g^{-1}) = \\rho(g)^{-1}$\n\\end{enumerate}\nAn \\textbf{equivariant} map between two representations $\\rho$ and $\\tau$ of $G$ is a linear map $f: V \\rightarrow W$ such that the induced map $GL(f)$ fits in the following commutative diagram\n\\begin{align}\n\t\\xymatrix{\n\t                 & GL(V) \\ar^{GL(f)}[d] \\\\\n\tG \\ar[ur] \\ar[r] & GL(W)                \\\\\n\t}\n\\end{align}\nTo be more explicit a linear map $f:V \\rightarrow W$ is equivariant if for any $v \\in V$ we have $f(\\rho(g)(v)) = \\tau(g)(f(v))$. An \\textbf{isomorphism} of representations is an invertible equivariant map $f: V \\rightarrow W$.\n\n\nA \\textbf{sub-representation} of $V$ is a subspace $W \\subsetneq V$ such that $W$ is itself a representation of $G$ i.e. for every $g \\in G$, $w \\in W$ we have $\\rho(g)w \\in W$. We say that $W$ is closed under the action of $G$. A representation of $G$ which has no sub-representation is called an \\textbf{irreducible} representation. We say that a representation $V$ is \\textbf{decomposable} if it there are sub-representations $V_1, V_2$ such that $V_1 \\oplus V_2 \\cong V$.\n\nIrreducible representations are the analogues of prime numbers in representation theory. One of the central goals of representation theory is to classify all the possible irreducible representations and to decompose arbitrary representations into irreducible ones.\n\n\n\n\n\n\n\n\n\n\n\\section{Examples}\n\n\\subsection{Trivial Representation}\nFor any finite group $G$ and any vector space $V$ there is a \\textbf{trivial} representation $\\rho : G \\rightarrow GL(V)$ which sends every element in $G$ to the identity transformation $I_V$.\n\n\\subsection{Cyclic Groups}\nFor the abelian group $\\Z/n$ with generator $a$ every representation is completely determined by where $a$ is mapped. Any $n \\times n$ matrix $A$ satisfying $A^n = 1$ gives a representation $\\Z/n \\rightarrow GL(V), a \\mapsto A$. In particular for each $0 \\le k < n$ the $n^{th}$ root of unity $e^{2 \\pi i k/n}$ gives us a 1 dimensional representation of $\\Z/n$. It is easy to see that no two of these representations are isomorphic.\n\n\n\n\\subsection{Symmetric Group}\nEvery symmetric group $S_n$ has an $n$ dimensional representation called the \\textbf{standard representation}. $S_n$ acts on $\\C^n$ as follows: If $e_1, \\cdots, e_n$ is the standard basis for $\\C^n$ then the permutation $g \\in S_n$ acts on $\\C^n$ via\n\\begin{align}\n\t\\rho(g){e _ i} & = e_ {\\sigma(i)}\n\\end{align}\nThe matrices of $\\rho(g)$ in the standard basis are called the \\textbf{permutation matrices}.\n\nThe standard representation of $S_n$ is not irreducible. Consider the 1-dimensional subspace $ W$ generated by the element $e_1 + e_2 + \\cdots + e_n$. This subspace is invariant under the action of $S_n$ and hence is a sub-representation of $\\C^n$. Let $W^{\\perp}$ be the vector space of $\\C^n$ consisting of vectors which are perpendicular to $W$ i.e. $W^{\\perp} = \\{ c_1.e_1 + \\cdots + c_n.e_n  : c_1 + \\cdots + c_n = 0\\}$. It is easy to see that $W^{\\perp}$ is also a sub-representation of $\\C^n$ and hence $V \\cong W \\oplus W^{\\perp}$ as representations.\n\n\\subsection{Sign Representation}\nEvery symmetric group $S_n$ has a 1 dimensional representation $\\mathrm{sign}: S_n \\rightarrow GL_1(\\C)$ called \\textbf{sign representation} defined as follows: Every transposition $(i,j)$ maps to $-1$. Every permutation can be written (non-uniquely) as a product of transpositions and hence we can extend this map to the entire $S_n$. We can then show that this extension is well defined.\n\n\n\\subsection{Dihedral group}\nLet $D_{2n}$ denote the \\textbf{dihedral group} which is the group of symmetries of a regular $n$ sided polygon in $\\R^2$. $D_{2n}$ has a presentation\n\\begin{align}\n\tD_{2n} = \\langle x,y \\mid x^2 = 1, y^n = 1, xyxy=1\\rangle\n\\end{align}\n$x$ denotes reflection about a line that passes through the center of the polygon and $y$ denotes a reflection about the center of the polygon by an angle of $2 \\pi / n$. We can show that $D_{2n}$ contains exactly $2n$ elements and every element is of the form $y^d$ or $xy^d$ for some $0 \\le d \\le n - 1$, hence the subscript $2n$. $D_{2n}$ has a natural 2 dimensional representation\n\\begin{align}\n\t\\rho : D_{2n} &\\rightarrow GL_2(\\C) \\\\\n\tx & \\mapsto \\begin{bmatrix} 0               & 1                \\\\ -1 & 0 \\end{bmatrix} \\\\\n\ty & \\mapsto \\begin{bmatrix} \\cos(2 \\pi / n) & -\\sin(2 \\pi / n) \\\\ sin(2 \\pi / n) & \\cos(2 \\pi / n) \\end{bmatrix}\n\\end{align}\nOne can show that the standard 2 dimensional representation of $D_{2n}$ is irreducible.\n\n\\subsection{Quaternions}\nThe \\textbf{quaternion group} $Q_8$ defined by the presentation\n\\begin{align}\n\tQ_8 = \\langle i,j,k, -1 \\mid i^2 = j^2 = k^2 = -1 = ijk, (-1)^2 = 1  \\rangle\n\\end{align}\nhas a 1 dimensional \\textbf{sign representation} given by mapping $i$ to 1 and $j$, $k$ to $-1$, and similarly two other sign representations. $Q_8$ also has a 2-dimensional representation $Q_8 \\rightarrow GL(\\C^2)$ given by\n\\begin{align}\n\ti \\mapsto \\begin{bmatrix} i & 0 \\\\ 0 & -i \\end{bmatrix}\n\t\\qquad\n\tj \\mapsto \\begin{bmatrix} 0 & 1 \\\\ -1 & 0 \\end{bmatrix}\n\t\\qquad\n\tk \\mapsto \\begin{bmatrix} 0 & i \\\\ i & 0 \\end{bmatrix}\n\\end{align}\n\n\\subsection{Regular Representation}\nEvery group $G$ has a $|G|$ dimensional representation called a \\textbf{regular representation}. Consider the free vector space $V$ over $G$ i.e. $V$ is a $|G|$ dimensional vector space with a basis given by $\\{ e_g : g \\in G\\}$. $G$ acts on $V$ via\n\\begin{align}\n\t\\rho(g)(e_h) = e_{gh}\n\\end{align}\nThe regular representation is not irreducible as it contains a 1 dimensional vector space spanned by $\\sum _ {g \\in G} e_g$ which is invariant under the action of $G$.\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{`Prime' representations}\nRepresentation theory of finite groups over $\\C$ asserts the existence of finitely many irreducible representations up to isomorphism. Further these representations can be detected by their characters.\n\nRecall that two elements $g_1, g_2 \\in G$ are called \\textbf{conjugates} of each other if there exists an $h \\in G$ such that $h^{-1} g_1 h = g_2$. Being a conjugate is an equivalence relation and the equivalence classes are called \\textbf{conjugacy classes}.\n\n\\begin{thm} Up to isomorphism there are finitely many irreducible representations of $G$. Suppose $\\rho_1, \\rho_2, \\ldots, \\rho_r$ are the distinct irreducible representations of $G$ with dimensions $d_1$, $d_2$, \\ldots, $d_r$ respectively then,\n\t$\\quad$\n\t\\begin{enumerate}\n\t\t\\item $r$ equals the number of conjugacy classes in $G$.\n\t\t\\item $d_i \\mid |G|$ where $|G|$ denotes the size of $G$.\n\t\t\\item $|G| = d_1^2 + d_2^2 + \\cdots + d_r^2$\n\t\\end{enumerate}\n\\end{thm}\n\n\\begin{thm}[Maschke's theorem]\n\tEvery reducible representation is decomposable.\n\\end{thm}\n\n\\begin{thm}[Schur's lemma]\n\tUsing the same notation as in the previous theorem, every finite dimensional representation $\\tau$ of $G$ has a unique decomposition\n\t\\begin{align}\n\t\t\\tau \\cong \\rho_1^{\\oplus k_1} \\oplus \\rho_2^{\\oplus k_2} \\oplus \\cdots \\oplus \\rho_r^{\\oplus k_r}\n\t\\end{align}\n\tfor some positive integers $k_1, k_2, \\cdots, k_r$ where by $\\rho_i \\oplus \\rho_j$ we mean the representation $G \\xrightarrow{\\rho_i \\oplus \\rho_j} GL(V_i \\oplus V_j)$.\n\\end{thm}\nIn terms of matrices $(\\rho_i \\oplus \\rho_j)(g)$ is the block matrix with two blocks given by $\\rho_i(g)$ and $\\rho_j(g)$ respectively. This theorem can be interpreted as saying that for every representation $\\tau: G \\rightarrow GL(V)$ it is possible to choose a basis for $V$ such that all the matrices $\\tau(g)$ become block diagonal in this basis, further each of the blocks are obtained from the irreducible representations.\n\nThese two theorems should be thought of as saying that in the world of $G$ representations there are finitely many `primes'. Every other representation can be uniquely written as a `product'(=direct sum) of these primes.\n\n\\subsection{Examples}\n\\begin{description}\n\t\\item[Dihedral group $D_6$:]\n\t$D_6$ which is the same as the symmetric group $S_3$ has 3 conjugacy classes $\\{ \\{1 \\}$, $\\{ (1,2)$; $(1,3)$; $(2,3) \\}$, $\\{(1,2,3)$; $(1,3,2)\\} \\}$ and hence has 3 irreducible representations of dimensions say $d_1, d_2, d_3$ which satisfy i) $d_i | 6$ and ii) $d_1^2 + d_2^2 + d_3^2 = 6$. The only such numbers are $1,1,2$. Further we know what they are: the trivial representation, the sign representation and the standard representation of the dihedral group $D_6$.\n\n\t\\item[Quaternion group $Q_8$:]\n\tThe quaternion group $Q_8$ has 5 conjugacy classes $\\{ 1\\}$, $\\{ -1\\}$, $\\{i, -i\\}$, $\\{ j, -j\\}$, and $\\{ k, -k\\}$ and hence has 5 distinct irreducible representations. But we know 5 irreducible representations of $Q_8$: the trivial representation, the 3 sign representations, and the two dimensional representation.\n\n\t\\item[Cyclic group:]\n\tLet $G$ be the cyclic group $\\Z/n$. As $G$ is abelian $ghg^{-1} = h$ for all $h$ i.e. each conjugacy class contains exactly 1 element and hence the number of conjugacy classes of $G$ is $n$. So $G$ has exactly $n$ distinct irreducible representations. Suppose their dimensions are $d_1, \\cdots, d_n$ then we must have $n = d_1^2 + \\cdots + d_n^2$. The only possibility is $d_i = 1$ for all $i$ i.e. all the irreducible representations of $\\Z/n$ are 1 dimensional. But we already know $n$ one dimensional representations of $\\Z/n$ (given by the roots of unity). More generally we get\n\n\t\\begin{proposition}\n\t\tEvery irreducible representation of an a abelian group is 1 dimensional.\n\t\\end{proposition}\n\n\t\\item[$p^2$ groups:]\n\tLet $G$ be a group of size $p^2$ where $p$ is a prime. Suppose $G$ has $r$ irreducible representations of dimensions $d_1, d_2, \\cdots, d_r$ then we must have $d_i | p^2$ so each $d_i$ is in the set $\\{ 1, p , p^2 \\}$. We also have $p^2 = d_1 ^2 + d_2 ^2 + \\cdots + d_r^2$. Every group has a trivial representation so that one of the $d_i's$ is 1. The only possibility is $d_i = 1$ for all $i$ and hence $r = p^2$. But this forces $G$ to have $p^2$ conjugacy classes and hence every conjugacy class contains exactly 1 element i.e. $G$ is abelian.\n\n\t\\begin{proposition}\n\t\tEvery group of size $p^2$ is abelian.\n\t\\end{proposition}\n\n\t\\item[Symmetric groups]\n\tThe symmetric groups $S_n$ have size $n!$. The conjugacy classes of $S_n$ are given by cycle types. One can show that the number of cycle types is equal to the number of ways of partitioning $n$ and hence for every partition of the number $n$ we get an irreducible representation of $S_n$.\n\\end{description}\n\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "88126df9a0841327b6373378b60aff5c57c910cb", "size": 13443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05 Representation theory/01 Representation Theory.tex", "max_stars_repo_name": "apurvnakade/mc2017", "max_stars_repo_head_hexsha": "ebec59bce5ee1979872e0f37208da6abd91dbb75", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "05 Representation theory/01 Representation Theory.tex", "max_issues_repo_name": "apurvnakade/mc2017", "max_issues_repo_head_hexsha": "ebec59bce5ee1979872e0f37208da6abd91dbb75", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05 Representation theory/01 Representation Theory.tex", "max_forks_repo_name": "apurvnakade/mc2017", "max_forks_repo_head_hexsha": "ebec59bce5ee1979872e0f37208da6abd91dbb75", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.5495049505, "max_line_length": 583, "alphanum_fraction": 0.7105556795, "num_tokens": 4134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.6663669577051868}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Graphically, find the point $(x,y)$ which\n  lies on both of the lines $x+3y=1$ and $4x-y=3$. That is, graph each line\n  and see where they intersect.\n\n  \\begin{sol}\n    $\n    \\begin{array}{c}\n      x+3y=1 \\\\\n      4x-y=3\n    \\end{array}$, Solution is: $\\mat{x=\\frac{10}{13},y=\\frac{1}{13}}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Graphically, find the point of intersection of the two lines $\n  3x+y=3$ and $x+2y=1$. That is, graph each line\n  and see where they intersect.\n\n  \\begin{sol}\n    $\n    \\begin{array}{c}\n      3x+y=3 \\\\\n      x+2y=1\n    \\end{array}\n    $, Solution is: $\\mat{x=1,y=0}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} You have a system of $k$ equations in two variables, $k\\geq 2$.\n  Explain the geometric significance of\n\n  \\begin{enumerate}\n  \\item No solution.\n\n  \\item A unique solution.\n\n  \\item An infinite number of solutions.\n  \\end{enumerate}\n\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Draw a picture of three planes such that no two of the planes are\n  parallel, but the three planes have no common intersection.\n\n  \\begin{sol}~\\par\\vspace{-2ex}\\quad\n    \\begin{tikzpicture}[xscale=0.2,yscale=0.15]\n      \\draw[fill=gray!30] (-6,0) -- ++(7,7) -- ++(4,0) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!90] (-2,-8) -- ++(7,7) -- ++(2,4) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!60] (2,-8) -- ++(7,7) -- ++(-2,4) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!60] (0,-4) -- ++(7,7) -- ++(-2,4) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!60] (-2,0) -- ++(7,7) -- ++(-2,4) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!30] (-2,0) -- ++(7,7) -- ++(4,0) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!90] (0,-4) -- ++(7,7) -- ++(2,4) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!30] (2,0) -- ++(7,7) -- ++(4,0) -- ++(-7,-7) -- cycle;\n      \\draw[fill=gray!90] (2,0) -- ++(7,7) -- ++(2,4) -- ++(-7,-7) -- cycle;\n    \\end{tikzpicture}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "403cf780726b4b4608af497382210306f9b6ae35", "size": 1912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.9696969697, "max_line_length": 78, "alphanum_fraction": 0.5251046025, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.6663669547553828}}
{"text": "\\section{Kruskal's and Prim's Algorithms}\t\\label{section:mst-algs}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[fragile]{Kruskal's Algorithm}\n  \\begin{lstlisting}[style = code]\n  sort (non-descreasingly) the edges $E$\n\n  $X = \\emptyset$\n  for $e \\in E$ in non-descreasing order\n    if $X \\cup \\set{e}$ does not produce cycle\n       $X \\gets X \\cup \\set{e}$\n  \\end{lstlisting}\n\n  \\importikznocaption{0.45\\textwidth}{0.70\\textwidth}{tikz-in-beamer/mst-kruskal-example-overlay.tex}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[fragile]{Kruskal's Algorithm}\n  \\begin{description}\n\t\\item[State:] forest $\\triangleq$ a collection of connected components\n\t\\item[Ops:] on connected components\n\t  \\begin{itemize}\n\t\t\\item cycle detection\n\t\t\\item union two CCs\n\t  \\end{itemize}\n  \\end{description}\n\n  \\pause\n\n  \\begin{center}\n\tUsing the \\textcolor{red}{\\bf disjoint-set} data structure.\n  \\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[fragile]{Prim's Algorithm}\n  \\begin{lstlisting}[style = code]\n  $X = \\emptyset$\n  $S = \\set{s}$    // pick any $s \\in V$\n  $R = V \\setminus S$\n  while $R \\neq \\emptyset$\n    $e = (u,v) \\gets$ a lightest edge across $(S, R)$ \n    $X \\gets X \\cup \\set{e}$\n    $S \\gets S \\cup \\set{u} \\quad R \\gets R \\setminus \\set{v}$\n  \\end{lstlisting}\n\n  \\importikznocaption{0.45\\textwidth}{0.70\\textwidth}{tikz-in-beamer/mst-prime-example-overlay.tex}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[fragile]{Prim's Algorithm}\n  \\begin{description}\n\t\\item[State:] a growing tree (CC)\n\t\\item[Op:] identifying a lightest edge\n  \\end{description}\n\n  \\pause\n\n  \\begin{center}\n\tUsing the \\textcolor{red}{\\bf priority-queue (min-heap)} data structure.\n  \\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "6002dfe0f7a4cdadf37cceea0872560b757d0161", "size": 1793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm-lecture-mst/sections/mst-algs.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-algs.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-algs.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": 27.5846153846, "max_line_length": 101, "alphanum_fraction": 0.6068042387, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.666366953222341}}
{"text": "\\documentclass[10pt]{article}\n\\author{Alex Peyrard}\n\\title{Information and coding theory assignment 3}\n\n\\begin{document}\n\\maketitle\n\n\\section{Inequalities}\nGiven $U\\rightarrow X\\rightarrow Y\\rightarrow V$ a Markov chain, we can find :\n\\[I(U,V)\\leq I(U,Y)\\]\n\\[I(U,V)\\leq I(X,V)\\]\n\n\\[I(U,V)\\leq I(U,X)\\]\n\\[I(U,V)\\leq I(X,Y)\\]\n\\[I(U,V)\\leq I(Y,V)\\]\n\n\\[I(U,Y)\\leq I(U,X)\\]\n\\[I(U,Y)\\leq I(X,Y)\\]\n\n\\[I(X,V)\\leq I(X,Y)\\]\n\\[I(X,V)\\leq I(Y,V)\\]\n\n\\section{Fano's inequality}\n\n\\section{Kraft's inequality}\nWe want to prove that for a uniquely decodable code, then $\\sum\\limits_{k=1}^{m}D^{-l_{k}}\\leq 1$\nWith $D$ the size of the size of the alphabet, $m$ the number of words, and $l_{k}$ the length of the $k^{th}$ word.\n\nFor the code to be uniquely decodable, it can't have a code that is the beginning of a following code. For a D-ary code, this means that if there are $D$ words of code length $l$, there can't be words of length superior to $l$.\n\nThus, for the D-ary code to be uniquely decodable, we can at most have $D-1$ words of code length $l < l_{max}$, and $D$ words of code length $l_{max}$.\n\nThis means that we have :\n\\[\\sum\\limits_{k=1}^{m}D^{-l_{k}}=(D-1)\\sum\\limits_{i=1}^{l_{max-1}}D^{-i}+D*D^{-l_{max}}\\]\n\\[\\sum\\limits_{k=1}^{m}D^{-l_{k}}=(D-1)\\sum\\limits_{i=1}^{l_{max}}D^{-i}+D^{-l_{max}}\\]\n\\[\\sum\\limits_{k=1}^{m}D^{-l_{k}}=(D-1)\\frac{D^{-l_{max}}(D^{l_{max}-1})}{D-1}+D^{-l_{max}}\\]\n\\[\\sum\\limits_{k=1}^{m}D^{-l_{k}}=1\\]\nSince this is at the most, a code is uniquely decodable if\n\\[\\sum\\limits_{k=1}^{m}D^{-l_{k}}\\leq1\\]\nQED\n\n\\end{document}", "meta": {"hexsha": "37b1f84b15b679deb6f78f9d205d80f101fce832", "size": 1551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ICT/assignment3.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/assignment3.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/assignment3.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": 36.9285714286, "max_line_length": 227, "alphanum_fraction": 0.6324951644, "num_tokens": 611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942472, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6663669332193694}}
{"text": "\\problemname{Vaccine Efficacy}\n\nTo determine the efficacy of a vaccine against a disease, a clinical\ntrial is needed.  Some participants are given the real vaccine, while\nothers are given a placebo as the control group.  The participants are\ntracked to determine if they are infected by three different strains\n(A, B, and C) of a virus.  The efficacy of the vaccine against\ninfection by a particular strain is simply the percentage reduction of\nthe infection rate of the vaccinated group compared to the control group.\n\nFor example, suppose that there are $40$ people in the vaccinated\ngroup, $8$ of which are infected by strain B.  Then the infection rate\nis $20$\\%.  Further suppose that $50$ people are in the control group,\nand $30$ people are infected by strain B.  Then the infection rate for\nthe control group is $60$\\%.  Thus the vaccine efficacy against\ninfection is approximately $66.67$\\% (since $20$\\% is a $66.67$\\%\npercentage reduction of $60$\\%).  If the infection rate for a\nparticular strain in the vaccinated group is not lower than that of\nthe control group, the vaccine is not effective against infection by\nthat strain.\n\nWhat is the vaccine efficacy against infection by the three strains?\n\n\\section*{Input}\n\nThe first line of input contains an integer $N$\n($2 \\leq N \\leq 10\\,000$) containing the number of participants in the\nclinical trial.\n\nThe next $N$ lines describe the participants. Each of these lines contains\na string of length four. Each letter is either `Y' or `N'.  The first letter\nindicates whether the participant is vaccinated with the real vaccine,\nand the remaining three letters indicate whether the participant is\ninfected by strain A, B, and C, respectively.\n\nThere is at least one participant in the vaccinated group and the\ncontrol group.  There is at least one participant in the control group\ninfected by each strain (but they may be different participants).\n\n\\section*{Output}\n\nDisplay the vaccine efficacy against infection by strain A, B, and C\nin that order.  If the vaccine is not effective against infection by a\nparticular strain, display \\texttt{Not Effective} for that strain\ninstead.  Answers with an absolute error or relative error of at most\n$10^{-2}$ will be accepted.\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "f3eabb3be2f21c96e2ad0dca1597950bb4b4ba1c", "size": 2296, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/vaccineefficacy/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/vaccineefficacy/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/vaccineefficacy/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": 44.1538461538, "max_line_length": 76, "alphanum_fraction": 0.7722125436, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6662206539211375}}
{"text": "% jam 2004-09-10\n\n\\section{Classifying projected simplexes}\n\\label{sec:classifying}\n\n%-----------------------------------------------------------------\n\nThe convex hull of a $(m-1)$ dimensional projection of a $m$-simplex\nis either a $(m-1)$-simplex or a $(m-1)$ dimensional cross polytope.\n\n\\begin{Lemma}\n\\label{rambau-lemma}\nAny set $Z$ of $(m+2)$ points whose convex hull is of dimension $m$\nhas exactly two triangulations denoted $T_{Z^+}$ and $T_{Z^-}$.\n\\end{Lemma}\n\nSee Rambau~\\cite[Lemma~1.1.2]{rambau-jorg-1996}.\n\nLet $S=(\\p_0, \\p_1 \\ldots  \\p_m)$ be an $m$-simplex in $\\Reals^{n}$.\nLet $\\pi$ be a projection from $\\Reals^{n}$ to $Q$, an $(m-1)$-dimensional\naffine subspace of $\\Reals^{n}$.\nAssume $\\pi$ is chosen so that the points\n$\\{\\pi \\p_0, \\pi \\p_1 \\ldots  \\pi \\p_m\\}$ are in {\\it general position},\nthat is, any $l+1$ of the projected points spans an $l$-dimensional\naffine subspace of $Q$.\n\nBy Lemma \\ref{rambau-lemma},\nthere are two exactly triangulations of the convex hull of the projected points.\nThe $(m-1)$-simplexes of the triangulations are images of the $(m-1)$-simplexes of $S$,\nand two triangulations correspond to a partition of $(m-1)$-simplexes of $S$\ninto two subsets, the \"top\" and \"bottom\" of $S$ with respect to $\\pi$.\n\nTo see why this is true, and to further classify the triangulations,\nconsider the fact that the boundary of the convex hull of $\\pi S$\nmust contain either $m$ or $m+1$ of the $\\pi \\p_i$.\n(Any fewer and the points cannot be in general position.)\n\n\\begin{Theorem}\n\\label{one-simplex-case}\nIf the boundary of the convex hull of $\\pi S$\ncontains $m$ of the $\\pi \\p_i$,\nthen it is a $(m-1)$-simplex\nand the image of one of the $(m-1)$-simplexes, $F$, in $S$.\nThe first triangulation is just $\\pi F$.\nThe second triangulation consists of the images of\nall the remaining $(m-1)$-simplexes of $S$.\nThe second triangulation is itself the mutual refinement of both.\n\\end{Theorem}\n\nThe first 2 statements are obvious.\nIf we label the vertices so that $\\{\\pi \\p_1 \\ldots  \\pi \\p_m\\}$\nare on the boundary, and $\\pi \\p_0$ is in the interior,\nthen the second triangulation results from refining the first\ntriangulation {\\it pulling}\n\\cite{lee-hdcg-17-2004} the vertex $\\pi \\p_0$.\nThe faces of the triangulation formed by pulling\nare the images of the $m$ $(m-1)$-simplexes\nof $S$ that contain $\\p_0$, that is, all the $(m-1)$-simplexes in $S$,\nother than $(\\p_1 \\ldots  \\pi \\p_m)$.\n\n\\begin{Theorem}\n\\label{two-simplex-case}\nIf the boundary of the convex hull of $\\pi S$\ncontains all $m+1$ of the $\\pi \\p_i$,\nthen it is the image of 2 of the $(m-1)$-simplexes in $S$,\nwhich share a common $(m-2)$-simplex.\nThese 2 simplexes are the first triangulation.\nThe second triangulation consists of the images\nof the remaining $m-1$ $(m-1)$-simplexes of $S$,\nwhich share a common $1$-simplex.\nThe mutual refinement is formed by splitting either\nthe shared $(m-2)$-simplex in the first triangulation\nor the shared $1$-simplex in the second.\n\\end{Theorem}\n\n\\subsection{Implementation}\n\nLet $\\Vspace$ be a $d$-dimensional real inner product space.\nLet $\\p() : \\Integers^{+} \\mapsto \\Vspace,$\nso that $\\p(\\Ssimplex)$ is a geometric realization of the $d$-simplex $\\Ssimplex$.\nLet $\\Projection_{\\Aspace}$ be the orthogonal projection onto\n$\\Aspace$, a $(d-1)$-dimensional affine subspace of $\\Vspace$.\nAssume that the $\\affine_span \\left( \\p(\\Ssimplex) \\right)$\nis $(d-1)$-dimensional.\n\nLet $\\Kcomplex_{d-1}$ be an oriented version of the $(d-1)$-skeleton of $\\Ssimplex$.\n\nBy the results above, the oriented $(d-1)$-simplices,\n$\\{ \\Ffacet_0 \\ldots \\Ffacet_d \\}$ in $\\Kcomplex_{d-1}$\ncan be partitioned into two subsets, $\\Kcomplex_{d-1}^{+}$\nand $\\Kcomplex_{d-1}^{-}$, such that\n$\\Projection_{\\Aspace} \\left( \\p ( \\Kcomplex_{d-1}^{+} ) \\right)$\nand\n$\\Projection_{\\Aspace} \\left( \\p ( \\Kcomplex_{d-1}^{-} ) \\right)$\nare each triangulations of\n$\\convex_span \\left( \\Projection_{\\Aspace} \\left( \\p ( \\Ssimplex ) \\right) \\right)$.\nThe two subsets can be determined by computng the signed\nvolumes of the realizations of the oriented facets,\nwith the positive volumes forming one triangulation and the negative the other.\n\nWhat I want to do is to create a mutual refinement of the two subsets,\n$\\Kcomplex_{d-1}^{1}$,\nwhich triangulates\n$\\convex_span \\left( \\Projection_{\\Aspace} \\left( \\p ( \\Ssimplex ) \\right) \\right)$.\nI then want to split and collapse simplices in any complex containing $\\Ssimplex$\nso that the $d$-simplex $\\Ssimplex$ is replaced by the $(d-1)$-dimensional\ncomplex $\\Kcomplex_{d-1}^{1}$.\n\nThere are two cases:\n\\begin{enumerate}\n\n\\item $\\convex_span \\left( \\Projection_{\\Aspace} \\left( \\p ( \\Ssimplex ) \\right) \\right)$\nhas $d$-corners, which are the projected realizations of $d$\nof the vertices of $\\Ssimplex$.\nThe remaining vertex, $\\Vvertex_0$,\nis such that\n$\\Projection_{\\Aspace} \\left( \\p ( \\Vvertex_0 ) \\right)$,\ncan be expressed\nas a convex combination of the projected realizations of the corner vertices.\n\nIn this case, one of $\\Kcomplex_{d-1}^{\\pm}$ is a single facet $\\Ffacet_d$\nand the other contains the remaining $d$ facets $\\{\\Ffacet_0 \\ldots \\Ffacet_{d-1} \\}$,\nwhich share $\\Vvertex_0$.\nTo get the mutual refinement, we split $\\Ffacet_d$ around a new vertex $\\Vvertex_1$.\nTo reduce the split children of $\\Ssimplex$ to $\\Kcomplex_{d-1}^{1}$,\nwe collapse the edge $\\{ \\Vvertex_0 , \\Vvertex_1 \\}$.\n\nNote that the number of vertices in any complex containing $\\Ssimplex$\nis unchanged.\n\n\\item All the $\\Projection_{\\Aspace} \\left( \\p ( \\Vvertex_i ) \\right) $\nare corners of\n$\\convex_span \\left( \\Projection_{\\Aspace} \\left( \\p ( \\Ssimplex ) \\right) \\right)$.\n\nIn this case, one of $\\Kcomplex_{d-1}^{\\pm}$\ncontains two facets, $\\Ffacet_{d-1}$ and $\\Ffacet_{d}$,\nand the other contains the remaining $(d-1)$ facets, $\\{\\Ffacet_0 \\ldots \\Ffacet_{d-2} \\}$.\n$\\Ffacet_{d-1}$ and $\\Ffacet_{d}$ share a common $(d-2)$-simplex, $\\Tsimplex$.\n$\\{\\Ffacet_0 \\ldots \\Ffacet_{d-2} \\}$ share a common edge.\nThe common edge connects the vertex $\\Vvertex_{d-1}$,\nwhich is opposite $\\Tsimplex$ in $\\Ffacet_{d-1}$,\nand the vertex $\\Vvertex_{d}$\nwhich is opposite $\\Tsimplex$ in $\\Ffacet_{d}$.\nTo get the mutual refinement, we split $\\Eedge$ around a new vertex $\\Vvertex_0$\nand split $\\Tsimplex$ around a new vertex $\\Vvertex_1$.\nTo reduce the split children of $\\Ssimplex$ to $\\Kcomplex_{d-1}^{1}$,\nwe collapse the edge $\\{ \\Vvertex_0 , \\Vvertex_1 \\}$.\n\nNote that the number of vertices in any complex containing $\\Ssimplex$\nis increased by 1.\n\n\\end{enumerate}\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "1f234b340b221ba9ee48cc5645c5a0f16e358b69", "size": 6501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/flatten.tex", "max_stars_repo_name": "palisades-lakes/les-elemens", "max_stars_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/old/fosm/flatten.tex", "max_issues_repo_name": "palisades-lakes/les-elemens", "max_issues_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/old/fosm/flatten.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3788819876, "max_line_length": 91, "alphanum_fraction": 0.696662052, "num_tokens": 2087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.6662206532701063}}
{"text": "\\providecommand{\\main}{..}\n\\documentclass[\\main/thesis.tex]{subfiles}\n\\begin{document}\n\\chapter{Generalizations}\\label{generalizations}\n\n\n\\section{Base}\n\nRecall the evaluation function.\n\n$$\n    [\\![d_0d_1d_2...d_n]\\!]_{base}\n    =\n    \\bar{d_0}\\times base^0 + \\bar{d_1}\\times base^1 + \\bar{d_2}\\times base^2 + ... + \\bar{d_n}\\times base^n\n$$\n%\nwhere $ \\bar{d_n} $ ranges from $ 0 $ to $ base - 1 $ for all $ n $.\n\nAs we can see the base of numeral systems has already been generalized.\nBut nonetheless, it is a good start and we will continue to abstract more things\naway.\n\n\\section{Offset}\n\nTo cooperate unary numerals, we relax the constraint on the range of digit\nassignment by introducing a new variable, \\textit{offset}:\n\n$$\n    [\\![d_0d_1d_2...d_n]\\!]_{base}\n    =\n    \\bar{d_0}\\times base^0 + \\bar{d_1}\\times base^1 + \\bar{d_2}\\times base^2 + ... + \\bar{d_n}\\times base^n\n$$\n\nThe evaluation of numerals remains the same but the assignment of digits has changed from\n\n$$\n    { 0, 1, ..., \\mathit{base} - 1 }\n$$\n\nto\n\n$$\n    { \\mathit{offset}, \\mathit{offset} + 1, ..., \\mathit{offset} + \\mathit{base} - 1 }\n$$\n\nThe codomain of the digit assignment function is \\textit{shifted} by \\textit{offset}.\nNow that unary numerals would have an offset of $ 1 $\nand systems of other bases would have offsets of $ 0 $.\n\n\\paragraph{1-2 binary system}\nRecall \\textit{1-2 random access lists} from the previous chapter,\nwhich is the numerical representation of a binary numeral system with an offset\nof $ 1 $.\nLet us see how to count to ten in the 1-2 binary system.\n\\footnote{As a reminder, the order of non-decimal numerals are reversed.}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{adjustbox}{max width=\\textwidth}\n    \\begin{tabular}{ | l | l |}\n    \\textbf{Number} & \\textbf{Numeral} \\\\\n    \\hline\n    1 & 1  \\\\\n    2 & 2  \\\\\n    3 & 11 \\\\\n    4 & 21 \\\\\n    5 & 12 \\\\\n    \\end{tabular}\n    \\quad\n    \\begin{tabular}{ | l | l | }\n    \\textbf{Number} & \\textbf{Numeral} \\\\\n    \\hline\n    6  & 22 \\\\\n    7  & 111 \\\\\n    8  & 211 \\\\\n    9  & 121 \\\\\n    10 & 221 \\\\\n    \\end{tabular}\n    \\end{adjustbox}\n\\caption{1-2 binary numeral system}\n\\label{table:8}\n\\end{table}\n\nThere are no restrictions on the symbols of digits.\nBut nonetheless, it is reasonable to choose symbols that match their assigned\nvalues, as we choose the symbol ``1'' and ``2'' as digits for the 1-2 binary system.\n\n% \\begin{center}\n%     \\begin{adjustbox}{max width=\\textwidth}\n%     \\begin{tabular}{ | l | r | r | }\n%     \\textbf{Numeral system} & \\textbf{Base} & \\textbf{Offset} \\\\\n%     \\hline\n%     decimal         & 10 & 0 \\\\\n%     binary          & 2  & 0 \\\\\n%     hexadecimal     & 16 & 0 \\\\\n%     unary           & 1  & 1 \\\\\n%     1-2 binary      & 2  & 1 \\\\\n%     \\end{tabular}\n%     \\end{adjustbox}\n% \\end{center}\n\n\\paragraph{bijective numerations}\nSystems with an offset of $ 1 $ are also known as \\textit{bijective numerations}\nbecause every number can be represented by exactly one numeral. In other words,\nthe evaluation function is bijective. The 1-2 binary system is one such numeration.\n\n\\paragraph{zeroless representations}\nA numeral system is said to be \\textit{zeroless} if no digits are assigned $ 0 $,\ni.e., $ \\mathit{offset} \\textgreater 0 $.\nData structures modeled after zeroless systems are called \\textit{zeroless representations}.\nThese containers are preferable to their ``zeroful'' counterparts.\nThe reason is that a digit of value $ 0 $ corresponds to a building block with\n$ 0 $ elements, and a building block that contains no element is not only useless,\nbut also hinders traversal as it takes time to skip over these empty nodes,\nas we have seen in random access lists from the previous chapter.\n\n\\section{Number of Digits}\n\nThe binary numeral system running in circuits looks different from what we have\nin hand.\nSurprisingly, these binary numbers can fit into our representation with just a tweak.\nIf we allow a system to have more digits,\nthen a fixed-precision binary number can be regarded as a single digit!\nTo illustrate this,\na 32-bit binary number (\\textit{Int32}) would become a single digit that ranges\nfrom $ 0 $ to $ 2^{32} $, while everything else including the base remains the same.\n\nFormerly in our representation,\nthere are exactly \\textit{base} number of digits and their assignments range from:\n\n$$\n    \\mathit{offset}  ...  \\mathit{offset} + \\mathit{base} - 1\n$$\n\nBy introducing a new index \\textit{\\#digit} to generalize the number of digits,\ntheir assignments range from:\n\n$$\n    \\mathit{offset}  ...  \\mathit{offset} + \\mathit{\\#digit} - 1\n$$\n\n\\paragraph{Redundancy}\n\nNumeral systems like \\textit{Int32} are said to be \\textbf{redundant}\nbecause there is more than one way to represent a number.\nIn fact, systems that admit $ 0 $ as one of the digits must be redundant,\nsince we can always take a numeral and add leading zeros without changing it's value.\n\nIncrementing a decimal numeral such as $ 999999 $ takes much more time than\n$ 999998 $ because carries or borrows can propagate.\nRedundancy provides ``buffer'' against these carries and borrows.\nIn this case, incrementing $ 999999 $ and $ 999998 $ of \\textit{Int32} both\nresults in a cost of constant time.\n\nNumerical representations modeled after redundant numeral systems also enjoy\nsimilar properties. When designed properly, redundancy can improve the performance\nof operations of data structures.\n\n\n\\section{Relations with Natural Numbers}\n\nThe following table contains all of the numeral systems we have addressed so far,\nwith \\textit{base}, \\textit{offset}, and \\textit{\\#digit} taken into account.\n\\footnote{\n\\textit{Int32} and \\textit{Int64} are respectively 32-bit and 64-bit machine\nintegers.\n}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{adjustbox}{max width=\\textwidth}\n    \\begin{tabular}{ | l | r | r | r | }\n    \\textbf{Numeral system} & \\textbf{Base} & \\textbf{\\#Digit} & \\textbf{Offset} \\\\\n    \\hline\n    decimal         & 10 & 10 & 0 \\\\\n    binary          & 2  & 2  & 0 \\\\\n    hexadecimal     & 16 & 16 & 0 \\\\\n    unary           & 1  & 1  & 1 \\\\\n    1-2 binary      & 2  & 2  & 1 \\\\\n    Int32           & 2  & $ 2^{32} $ & 0 \\\\\n    Int64           & 2  & $ 2^{64} $ & 0 \\\\\n    \\end{tabular}\n    \\end{adjustbox}\n\\caption{Summary of indices of common numeral systems}\n\\label{table:9}\n\\end{table}\n\n\nAlthough we are now capable of expressing those numeral systems with just a few\nindices, there are also some unexpected inhabitants included in this representation.\nThere is always a trade-off between expressiveness and properties.\n\nWe will explore the various types of numeral systems and define operations on\nthem in the chapter~\\ref{constructions}.\n\n\\end{document}\n", "meta": {"hexsha": "5ae75d831aec23bd1f0d2f1f68483a034171b241", "size": 6660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/NCTU-CS/tex/generalizations.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/NCTU-CS/tex/generalizations.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/NCTU-CS/tex/generalizations.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": 33.807106599, "max_line_length": 107, "alphanum_fraction": 0.6831831832, "num_tokens": 1936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.666220648042164}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{tikz}\n\n\\begin{document}\n\n\\title{Approximately Euclidean Grids}\n\\author{Moshe Looks}\n\n\\maketitle\n\nThe distance $d_G(u, v)$ between vertices in an undirected graph $G = (V, E)$ is the number\nof edges in a shortest path between $u$ and $v$. The distance $d_2(p, q)$ between points\nEuclidean space is the $2$-norm of the line segment between $u$ and $v$. A non-trivial\nmapping $f : V \\to \\mathbb{N}^2$ cannot satisfy $d_G(u, v) = d_2(f(u), f(v))$ because of the\nincommensurability of the side and diagonal of the square. Nonetheless, $d_G(u, v)$ can be\nused to approximate $d_2(f(u), f(v))$; the approximation will be better or worse depending on\nour choices of $G$ and $f$. How well can $d_G$ approximate $d_2$, assuming $|V| = N$?\n\nThis is an interesting question that is difficult to answer in full generality. Let's\nconsider the special case of a graph with $N = n^2$ vertices mapped onto the square grid\n$\\{1, \\ldots, n\\} \\times \\{1, \\ldots, n\\}$. If we add edges between horizontal and vertical\nneighbors, we get Manhattan distances ($d_1$, based on the $1$-norm). If we additionally add\nedges between diagonal neighbors, then we get chessboard distances ($d_\\infty$, based on the\n$\\infty$-norm).\n\n\\setlength{\\tabcolsep}{15pt}\n\\begin{tabular}{ l r}\n  \\input{manhattan.tex} & \\input{chessboard.tex}\n\\end{tabular}\n\nWe have the nice property that $d_1(p, q) \\leq d_2(p, q) \\leq d_\\infty(p, q)$, although\nneither one of these constructs gives us a very good approximation of $d_2$. It is easy to\nsee that in both cases, the divergences from $d_2$ grow unboundedly with $n$.  In fact,\nTobias Fritz has \\href{https://arxiv.org/abs/1109.1963}{proven} that this divergence happens\nfor \\emph{every} distance function based on a periodic graph. But nothing prevents us from\nconsidering aperiodic graphs. What happens if we start with a graph corresponding to $d_1$\nand we add edges between only \\emph{some} diagonal neighbors? Let's call this sort of graph\nwith $|V| = n^2$, where $d_G$ is meant to approximate $d_2$, an order-$n$ Eugrid (Euclidean\ngrid). Here is an interesting order-5 Eugrid:\n\n\\begin{center}\n  \\input{eugrid5.tex}\n\\end{center}\n\nWhat makes it interesting is that for every Pythagorean triple\\footnote{Triples of natural\nnumbers $(a, b, c)$ s.t. $a^2 + b^2 = c^2$; eg. $(3, 4, 5)$, $(12, 5, 13)$, \\&c.}  $(a, b,\nc)$ and every pair of vertices $(p, q)$ corresponding respectively to $(x, y)$ and $(x \\pm a,\ny \\pm b)$, the distance relation $d(p, q) = c$ is satisfied. Let's call a Eugrid that\nsatisfies this property \\emph{Pythagorean}. Pythagorean triples are dense in the rational\nnumbers. Consequently, a Pythagorean Eugrid of sufficiently high order would, in a certain\nsense, perfectly reflect the structure of Euclidean space, insofar as it is \\emph{can} be\nreflected by a finite square grid. But do high-order Pythagorean Eugrids exist? As it turns\nout, they do not; order-12 is as high as they go. Unlucky 13! The space of order-13 Eugrids\nis rather large, and so the proof that none of them are Pythagorean is based on a rather\ntricky branch-and-bound search; refer to \\hyperref[sec:appendix]{the appendix} for details.\nElegance eluding us, we henceforth resort to heuristics and approximations. Such is the lot\nof the computer ``scientist''.\n\n\\section{An approximate approach}\n\nLet us consider for the moment only distances from $\\mathbf{1} = (1, 1)$ to other points, and\nthus only concern ourselves with diagonals corresponding to line segments $\\{p + (\\Delta,\n\\Delta) \\, | \\, 0 \\leq \\Delta \\leq 1\\}$. The distance $d_G(\\mathbf{1}, (x+1, y+1))$ may be\ncalculated via a simple recurrence relation as\n\\begin{equation*}\n  D_1(x, y) := 1 + d_G(\\mathbf{1}, (x, y))\n\\end{equation*}\nin the presence of a diagonal edge originating at $(x, y)$ and\n\\begin{equation*}\n  D_2(x, y) := 1 + \\min(d_G(\\mathbf{1}, (x + 1, y)), d_G(\\mathbf{1}, (x, y + 1)))\n\\end{equation*}\nin the absence of a diagonal. This immediately suggests a simple greedy approach where we\nvisit each potential diagonal exactly once\\footnote{Taking care to visit $(x+1, y+1)$ after\nwe have visited $(x+1,y)$ and $(x,y+1)$.} and decide whether or not to add it to the graph by\ncomparing the quantities\n\\begin{equation*}\n  L_1(x, y) := |\\sqrt{x^2 + y^2} - D_1(x, y)|\n\\end{equation*}\nand\n\\begin{equation*}\n  L_2(x, y) := |\\sqrt{x^2 + y^2} - D_2(x, y)|\n\\end{equation*}\nthat characterize the ``loss'' for adding vs. omitting a given edge. This gives us\n\\begin{center}\n  \\includegraphics[scale=1.95]{simple.png}\n\\end{center}\nwhich is black where $L_1 < L_2$, white where $L_1 < L_2$, and gray where $L_1 = L_2$. The\nunderlying graph structure is aperiodic so Fritz's no-go theorem does not apply; arcs around\n$\\mathbf{1}$ become increasingly circular as the radius increases.\n\\begin{center}\n  \\includegraphics[scale=1.95]{simple_arcs.png}\n\\end{center}\n\nThe moment we shift our perspective however, things begin to seem rather worse. If we center\nourselves at $(16, 8)$ for example we see instead\n\\begin{center}\n  \\includegraphics[scale=1.95]{simple_ugly_arcs.png}\n\\end{center}\nwhere black arcs are for graph structure based on $L_1 < L_2$ and gray arcs are for graph\nstructure based on $L_1 \\leq L_2$; neither one is very good.\n\nHow can we make better Eugrids? We can generalize this simple greedy approach and consider\ndistances to more points than just $\\mathbf{1}$. What is left is to specify \\emph{which}\npoints, and how to weight their relative contributions, since adding a particular diagonal\nedge may make some distance more Euclidean, and other less so.\n\nFor the vertex $u$ at $(x_u, y_u)$ we can potentially calculate distances to all vertices $v$\nat $(x_v, y_v)$ such that $x_v < x_u$ and $y_v < y_u$. But since this both highly redundant\nand scales badly with $n$, we restrict ourselves to points on the edges of the Eugrid, i.e.\nof the forms $(x_v, 1)$ and $(1, y_v)$. This gives us nice coverage and is computationally\ntractable, but requires careful normalization to balance relative contributions.\n\nIf we ima\n\nThere is one more\n\n\\begin{equation*}\n\\sum_{i=1}^{x+y-1} \\frac{\\theta_i \\cdot |\\sqrt{x_i^2 + y_i^2} - D_i|}{\\min(x_i, y_i)}\n\\end{equation*}\n\n\n\n\n\nand distances between pairs of vertices\nmapping to pairs of points placed at pairs of points of the form $(p, p + \\Delta) \\, | \\, p,\n\\Delta _\\in \\mathbb{N}^2$.\n\nIn the spirit of trying simple things first, lets see what happens if we take a greedy\napproach and only consider distance to  It can be easily seen that\nif there is an edge between the vertices corresponding to points $(i, j)$ and $(i + 1, j+1)$\nthen\n\\begin{equation}\n  d_G(\\mathbf{1}, (i+1, j+1)) =\n\\end{equation}\nand that otherwise\n\\begin{equation}\n  d_G(\\mathbf{1}, (i+1, j+1)) =\n\\end{equation}\n\nThis suggests simply\n\n\nThis approach gives us very nice circular arcs around $\\mathbf{1}$\n\n\\includegraphics[scale=0.2]{cs.png}\n\nBut very ugly circular arcs around other vertices.\n\n\\includegraphics[scale=0.2]{cs2.png}\n\n\n\\section*{Appendix: Searching for Pythagorean Eugrids}\n\\label{sec:appendix}\n\nWe can construct a state space to search for order-$n$ Eugrids by putting undirected graphs\nin correspondence with $(n - 1) \\times (n - 1)$ bit matrices where $1$s correspond to the\npresence of edges between diagonal neighbors.\\footnote{Eugrids include all edges between\nhorizontal and vertical neighbors, by definition.} For example, the order-$5$ Eugrid\nexhibited above corresponds to a $4 x 4$ Eugridean matrix:\n\n\\begin{equation*}\n\\begin{matrix}\n  0 & 0 & 0 & 0 \\\\\n  0 & 0 & 1 & 0 \\\\\n  0 & 1 & 0 & 1 \\\\\n  0 & 0 & 1 & 0\n\\end{matrix}\n\\end{equation*}\n\nThe state space for order $n$ has $2^{(n-1)^2}$ elements. For $n=5$ this is only 65,536 and\nwe can brute-force it to see that there are 10,948 order-$5$ Eugrids; they are rather thick\non the ground. What to do about higher orders where exponential growth makes things\nunpleasant? We can make some headway by noticing that higher-order Eugrids must be composed\nof lower-order ones. In particular, if matrix $\\mathbf{A}$ corresponds to an order-$n$\nEugrid, then all submatrices $\\mathbf{A}_{1:m,1:m}$ correspond to order-$m$ Eugrids.\n\nThis naturally suggests a partition of the full $(n-1)^2$-dimensional state space into\n$(n-1)$ disjoint ``layers'', like so:\n\n\\begin{center}\n  \\input{onion.tex}\n\\end{center}\n\nPossible diagonals for the $m$th layer correspond to squares numbered $m$. So rather than\nconstructing an entire state in one go, we only ever construct substates corresponding to\nindividual layers. When constructing a substate corresponding to layer $m+1$, we can assume\nthat all substates corresponding to layers $1 \\ldots m$ are valid (i.e. correspond to\nlower-order Eugrids). We may have to backtrack of course; some lower-order Eugrids are dead\nends.\n\nThis is a good start towards tractability but is insufficient; the state subspace for layer\n$m$ still has $2^{2m-1}$ elements. What we need is a more intelligent search pro\n\nWe have more work to do in order to make the search tractable. The first step is to move away\nfrom brute-force enumeration when considering diagonals for layer $n+1$ given layer $n$\nalready contains a Eugrid.\\footnote{The $n=0$ case corresponds to a layer only a single\nsearch space variable, so we don't mind enumerating over it.} The basic idea here is that\nevery region of the space corresponding to a Pythagorean triple $(a, b, c)$ with lower-left\ncorner $(x, y)$ corresponds to a set of constraints on the diagonals inside of it, and we\nwill end up with a Eugrid iff \\emph{all} such sets of constraints are satisfied.\n\nWhat are these constraints, exactly? If all variables corresponding to diagonals in a\nparticular region have been assigned, then obviously the constraints require the shortest\npaths from $(x, y)$ to $(x+a, y+b)$ have length $c$. But we can do better than this and\nimpose constraints on partially assigned regions as well. For example, no Eugridean matrix\ncan contain\n\\begin{equation*}\n\\begin{matrix}\n  1 & * & * \\\\\n  * & 1 & * \\\\\n  * & * & 1\n\\end{matrix}\n\\end{equation*}\nas a proper submatrix (where ``*'' may be either a 1 or a 0) because if so then it would be\ncontained within a $3x4$ region\\footnote{Corresponding to the Pythagorean triple $(3, 4,\n5)$.} with a shortest path for the hypotenuse of length $< 5$ in violation of Eugrideanity.\nLikewise $0_{2 x 4}$ is not a submatrix of any Eugridean, because it would lead to a similar\nregion with hypotenuse of length $> 5$.\n\nSince graph distance equals shortest path length, $d(u, v) = c$ requires both that no path\nfrom $u$ to $v$ be shorter than $c$, \\emph{and} that at least one path be no longer than $c$.\nThe partition of a square grid into layers as we have done dictates that all shortest pathsbetween.\n\nTo get tight bounds, recall that Eugridean distance is lower-bounded by $L_\\infty$ and\nupper-bounded by $L_1$.\n\nFor every literal \\verb|x| and corresponding vertex $x$, \\emph{if} there exists a region\n$r = (p, q, c)$ s.t. $d(p, x) + d_1(x, q) == c$, \\emph{then} $r$ is unconstrained \\emph{and}\n\\verb|x| is negated.\n\nFor every region $r = (p, q, c)$, \\emph{if} there exists a vertex $x$ s.t.\n$d(p, x) + d_{\\infty}(x, q) < c$, \\emph{then} $r$ is unconstrained.\n\nAll other regions are constrained. For every constrained region $r = (p, q, c)$ at least one\nliteral \\verb|x| corresponding to vertex $x$ that satisfies $d(p, x) + d_{\\infty}(x, q) = c$\nmust be affirmed.\n\nWe can thus construct a logical conjunction of clauses where every clauses is either a\nnegated literal or a disjunction of non-negated literals s.t. the layer is valid iff the the\nconjunction is satisfied. Whereas general Boolean satisfiability is a hard problem, formulae\nwith this special form are easily checkable. We can easily enumerate all valid assignments\nusing depth-first search.\n\nThis leads to a backtracking search procedure for finding Eugrids:\n\nLet $1$ be the active layer.\n\nGenerate a satisfying assignment for the active layer. If no satisfying assignment exist, or\nif we have already generated all satisfying assignments, backtrack to the previous layer.\n\nAdvance to the next layer.\n\n\n\\end{document}\n", "meta": {"hexsha": "22c918fc69d53e9674e4b4831f1186c0c5a0dbb6", "size": 12193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "figures/paper.tex", "max_stars_repo_name": "moshelooks/eugrid", "max_stars_repo_head_hexsha": "f13adbc53910801276111295fd894b19a44f3038", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "figures/paper.tex", "max_issues_repo_name": "moshelooks/eugrid", "max_issues_repo_head_hexsha": "f13adbc53910801276111295fd894b19a44f3038", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "figures/paper.tex", "max_forks_repo_name": "moshelooks/eugrid", "max_forks_repo_head_hexsha": "f13adbc53910801276111295fd894b19a44f3038", "max_forks_repo_licenses": ["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.7164750958, "max_line_length": 99, "alphanum_fraction": 0.732879521, "num_tokens": 3606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.6662206464622744}}
{"text": "\\chapter{Eigen value problems}\n\\section{Eigen values and eigen function}\n The values of energy $E_n$ for which Schrodinger steady state equation can be solved are called eigen values and the corresponding wavefunctions $\\psi_{n}$ are called eigen functions.\\\\\n  The condition that a certain dynamical variable G be restricted to the descrete values $G_n$- in other words, that G be quandized-is that the wavefunction $\\psi_{n}$ of the system be such that \\\\\n  Eigen value equation $\\implies \\hat{G}\\psi_{n}=G_n \\psi_{n}$\n  \\section{Particle in a one dimensional box}\n  \\begin{figure}[H]\n  \t\\centering\n  \t\\includegraphics[height=4cm,width=5.5cm]{particle in abox}\n  \t\\caption{Particle in a 1-D box}\n  \t\\label{Particle in a 1-D box}\n  \\end{figure}\n  Consider a particle of mass ' $m$ ' and energy ' $E$ ' is moving along $x$ -axis, in the region from $x=0$ to $x=L$ under the following potential i.e.\n  \\begin{equation}\\label{key}\n  V(x) = \\begin{cases} \n  0 & 0<x<L  \\\\\n  \\infty & \\text{Otherwise.}\n  \\end{cases}\n  \\end{equation}\n  Here, the particle can move only on a line of finite length.The potential energy $V$ of the particle is infinite on both sides of the box, while $V$ is a constant-say $ 0 $ for convenience - on the inside (Figure.\\ref{Particle in a 1-D box}. ). Because the particle cannot have an infinite amount of energy, it cannot exist outside the box, and so its wave function $\\psi$ is $ 0 $ for $x \\leq 0$ and $x \\geq L$. Our task is to find what $\\psi$ is within the box, namely, between $x=0$ and $x=L$.\n  \\begin{align}\n  -\\frac{\\hbar^{2}}{2 m} \\frac{d^{2} \\psi(x)}{d x^{2}}+V \\psi(x)&=E \\psi(x)\n  \\intertext{Within the box Schrödinger's equation becomes,}\n  -\\frac{\\hbar^{2}}{2 m} \\frac{d^{2} \\psi}{d x^{2}}&=E \\psi \\quad \\text{Since, }\\ V(x)=0\\  \\text{for} \\ 0<x<L\\\\\n  \\frac{d^{2} \\psi}{d x^{2}}+\\frac{2 m}{\\hbar^{2}} E \\psi&=0\\\\\n  \\frac{d^{2} \\psi}{d x^{2}}+k^{2} x&=0\\qquad \\text { Where, }\\ k^{2}=\\frac{2 m E}{\\hbar^{2}}\\label{particle1} \n  \\intertext{The solution of the equation.\\ref{particle1} can be written as, }\n  \\psi(x)&=A \\sin k x+B \\cos k x\\\\\n  \\psi&=A \\sin \\frac{\\sqrt{2 m E}}{\\hbar} x+B \\cos \\frac{\\sqrt{2 m E}}{\\hbar} x\n  \\end{align}\n  \\subsubsection{Boundary conditions}\n  $\\psi(x)$ will be continuous at $x=0$ and $x=a$.\n  \\begin{enumerate}\n  \t\\item Applying $\\left.\\psi(x)\\right|_{x=0}=0 \\quad \\Rightarrow B=0$\n  \t\\item Applying $\\left.\\psi(x)\\right|_{x=L}=0 \\quad \\Rightarrow A \\sin k L=0 \\quad \\Rightarrow k L=n \\pi \\Rightarrow k=\\frac{n \\pi}{L}$\\\\\\\\\n  \t$\\Rightarrow \\psi(x)=A \\sin \\left(\\frac{n \\pi {x}}{L}\\right)\\quad (n=1,2,3, \\ldots \\ldots \\ldots)$ \\ for\\ $0<x<a$\n  \\end{enumerate}\n  If $n=0 \\Rightarrow k=0 \\Rightarrow E=0 \\Rightarrow \\psi(x)=0$ everywhere inside the box. Therefore, there will be no admissible particle with zero energy within the box.\n  \\begin{center}\n  \t\\framebox{\n  \t\t\\parbox[t][2cm]{6cm}{\n  \t\t\t\n  \t\t\t\\addvspace{0.2cm} \\centering \n  \t\t\t\n  \t\t\t\\textbf{Particle in a one- dimensional box}\\\\ \\vspace{0.3cm}\n  \t\t\t$\\psi(x)=A \\sin \\left(\\frac{n \\pi {x}}{L}\\right)$\n  \t\t\t\n  \t} }\n  \\end{center}\n  \\subsection{Normalisation of the wavefunction of a particle in a box}\n  The wave function $\\psi_{n}$ corresponding to $\\mathrm{n}^{\\text {th }}$ quantum state is,\n  \\begin{equation}\n  \\psi(x) = \\begin{cases} \n  A \\sin \\frac{n \\pi x}{L} & 0<x<L  \\\\\n  0 & \\text{Otherwise.}\n  \\end{cases}\n  \\end{equation}\n  Since, the particle must be somewhere within the box, the total probability of finding the particle inside the box is unity i.e.\n  \\begin{align}\n  \\int_{0}^{L} \\psi_{n}^{*}(x) \\psi_{n}(x) d x&=1 \\\\\n  \\int_{0}^{L} A^{2} \\sin ^{2} \\frac{n \\pi x}{L} d x&=1\\\\\n  A^{2} \\int_{0}^{L} \\frac{1}{2}\\left[1-\\cos \\frac{2 \\pi n x}{L}\\right] d x&=1\\\\\n  A&=\\sqrt{\\frac{2}{L}}\n  \\intertext{Therefore the normalised wave function of a particle in a one-dimensional box becomes,}\n  \\psi_{n}(x)&=\\sqrt{\\frac{2}{L}} \\sin \\left(\\frac{n \\pi x}{L}\\right) \\quad(n=1,2,3, \\ldots \\ldots \\ldots \\ldots \\ldots)\n  \\end{align}\n  \\begin{center}\n  \t\\framebox{\n  \t\t\\parbox[t][2cm]{6cm}{\n  \t\t\t\n  \t\t\t\\addvspace{0.2cm} \\centering \n  \t\t\t\n  \t\t\t\\textbf{Wavefunction of a particle in a box} \\\\ \\vspace{0.3cm}\n  \t\t\t$\\psi_{n}(x)=\\sqrt{\\frac{2}{L}} \\sin \\left(\\frac{n \\pi x}{L}\\right)$} }\n  \\end{center}\n  \\subsection{Energy of a particle in a box}\n  We have found that the solution is subject to the boundary condition.  The sine term always yields $\\psi=0$ at $x=0$, as required, but $\\psi$ will be 0 at $x=L$ only when\n  \\begin{align}\n  \\frac{\\sqrt{2 m E}}{\\hbar} L&=n \\pi \\quad n=1,2,3, \\ldots \\label{particle2}\n  \\intertext{It is clear that the energy of the particle can have only certain values, solving equation.\\ref{particle2},}\n  E_{n}&=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{2 m L^{2}} \\quad n=1,2,3, \\ldots\n  \\end{align}\n  \\begin{center}\n  \t\\framebox{\n  \t\t\\parbox[t][2cm]{6cm}{\n  \t\t\t\n  \t\t\t\\addvspace{0.2cm} \\centering \n  \t\t\t\n  \t\t\t\\textbf{Energy of a particle in a box} \\\\ \\vspace{0.3cm}\n  \t\t\t$E_{n}=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{2 m L^{2}}$ } }\n  \\end{center}\n  So, we get an infinite sequence of descrete energy levels that corresponds to all integral values of $n$, where $n$ is called the quantum number representing the different states of the particle.\n  \\begin{align}\n  \\text{The ground state energy,} \\quad E_{1}&=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}\\\\\n  \\text{The first excited state energy,} \\quad \n  E_{2}&=\\frac{4 \\pi^{2} \\hbar^{2}}{2 m a^{2}}\\\\\n  \\text{In general}\\quad E_{n}&=n^{2} E_{1}\n  \\intertext{The difference in energy between two consecutive energy levels,}\n  {\\Delta E}_{n}&=E_{n+1}-E_{n}=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}\\left[(n+1)^{2}-n^{2}\\right]\\\\&=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}(2 n+1)\n  \\end{align}\n  \\begin{figure}[H]\n  \t\\centering\n  \t\\includegraphics[height=5cm,width=6cm]{particle in a box1}\n  \t\\caption{}\n  \t\\label{}\n  \\end{figure}\n  The normalized wave functions $\\psi_{1}, \\psi_{2}$, and $\\psi_{3}$  the probability densities $\\left|\\psi_{1}\\right|^{2},\\left|\\psi_{2}\\right|^{2}$, and $\\left|\\psi_{3}\\right|^{2}$ are plotted in Figure.\\ref{Variation of wave function with eigen states.} and Figure.\\ref{Variation of probability density with eigen states.} respectively, Although $\\psi_{n}$ may be negative as well as positive, $\\left|\\psi_{n}\\right|^{2}$ is never negative and, since $\\psi_{n}$ is normalized, its value at a given $x$ is equal to the probability density of finding the particle there. In every case $\\left|\\psi_{n}\\right|^{2}=0$ at $x=0$ and $x=L$, the boundaries of the box.\n  \\begin{figure}[H]\n  \t\\begin{minipage}{0.30\\textwidth}\n  \t\t\\includegraphics[height=3cm,width=4cm]{particle in a box5}\n  \t\\end{minipage}\n  \t\\begin{minipage}{0.30\\textwidth}\n  \t\t\\includegraphics[height=3cm,width=4cm]{particle in a box6}\n  \t\\end{minipage}\n  \t\\begin{minipage}{0.30\\textwidth}\n  \t\t\\includegraphics[height=3cm,width=4cm]{particle in a box7}\n  \t\\end{minipage}\n  \t\\caption{Variation of probability density with eigen states.}\n  \t\\label{Variation of wave function with eigen states.}\n  \\end{figure}\n  \\begin{figure}[H]\n  \t\\begin{minipage}{0.30\\textwidth}\n  \t\t\\includegraphics[height=3cm,width=4cm]{particle in a box3}\n  \t\\end{minipage}\n  \t\\begin{minipage}{0.30\\textwidth}\n  \t\t\\includegraphics[height=3cm,width=4cm]{particle in a box2}\n  \t\\end{minipage}\n  \t\\begin{minipage}{0.30\\textwidth}\n  \t\t\\includegraphics[height=3cm,width=4cm]{particle in a box4}\n  \t\\end{minipage}\n  \t\\caption{Variation of probability density with eigen states.}\n  \t\\label{Variation of probability density with eigen states.}\n  \\end{figure}\n  \\section{Expectation values of \\Large{ $\\hat{x}, \\hat{p}_{x}, \\hat{x}^{2}, \\hat{p}_{x}^{2}$}}\n  \\subsection{Expectation values of  position \\Large{ $\\hat{x}$}}\n  \\begin{align*}\n  \\langle x\\rangle &=\\int_{-\\infty}^{\\infty} \\psi^{*} x \\psi =\\int_{-\\infty}^{\\infty} x|\\psi|^{2} d x=\\frac{2}{L} \\int_{0}^{L} x \\sin ^{2} \\frac{n \\pi x}{L} d x \\\\\n  &=\\frac{2}{L}\\left[\\frac{x^{2}}{4}-\\frac{x \\sin (2 n \\pi x / L)}{4 n \\pi / L}-\\frac{\\cos (2 n \\pi x / L)}{8(n \\pi / L)^{2}}\\right]_{0}^{L}\n  \\intertext{Since $\\sin n \\pi=0, \\cos 2 n \\pi=1$, and $\\cos 0=1$, for all the values of $n$ the expectation value of $x$ is}\n  \\langle x\\rangle&=\\frac{2}{L}\\left(\\frac{L^{2}}{4}\\right)\\\\&=\\frac{L}{2}\n  \\end{align*}\n  \\subsection{Expectation values of  momentum \\Large{$\\hat{p_{x}}$}}\n  \\begin{align*}\n  \\langle p\\rangle&=\\int_{-\\infty}^{\\infty} \\psi^{*} \\hat{p} \\psi d x\\\\&=\\int_{-\\infty}^{\\infty} \\psi^{*}\\left(\\frac{\\hbar}{i} \\frac{d}{d x}\\right) \\psi d x\n  \\intertext{Then we have to find the derivative of the wavefunction $\\psi$}\n  \\psi^{*} &=\\psi_{n}=\\sqrt{\\frac{2}{L}} \\sin \\frac{n \\pi x}{L} \\\\\n  \\frac{d \\psi}{d x} &=\\sqrt{\\frac{2}{L}} \\frac{n \\pi}{L} \\cos \\frac{n \\pi x}{L}\n  \\intertext{Then ,}\n  \\langle p\\rangle&=\\frac{\\hbar}{i} \\frac{2}{L} \\frac{n \\pi}{L} \\int_{0}^{L} \\sin \\frac{n \\pi x}{L} \\cos \\frac{n \\pi x}{L} d x\\\\&=\\frac{\\hbar}{i L}\\left[\\sin ^{2} \\frac{n \\pi x}{L}\\right]_{0}^{L}\\quad \\text{Since,} \\\\\n  &=0\n  \\intertext{The expectation value $\\langle p\\rangle$ of the particle's momentum is $0 .$}\n  \\intertext{In expectation value of momentum what we are realy determining is, the average value of the momentum .We know that the momentum eigenvalues of a particle in a box is given by,}\n  p_{n}&=\\pm \\sqrt{2 m E_{n}}=\\pm \\frac{n \\pi \\hbar}{L} \\quad (\\text{Which is not equal to zero.})\\\\\n  p_{\\mathrm{av}}&=\\frac{(+n \\pi \\hbar / L)+(-n \\pi \\hbar / \\mathrm{L})}{2}\\\\&=0\n  \\end{align*}\n  \\subsection{Expectation values of    \\Large{$\\hat{{x}}^{2}$}}\n  \\begin{align*}\n  \\left\\langle x^{2}\\right\\rangle&=\\int_{0}^{L} \\psi^{*} x^{2} \\psi d x\\\\&=\\frac{2}{L} \\int_{0}^{L} x^{2} \\sin ^{2} \\frac{n \\pi x}{L} d x\n  \\\\&=\\frac{2}{L} \\int_{0}^{L} x^{2}\\left[ 1- \\cos 2 \\frac{n \\pi x}{L}\\right]  d x\n  \\\\&=\\frac{1}{L}\\left[\\left(\\frac{x^{3}}{3}\\right)_{0}^{L}-\\left(x^{2} \\frac{(\\sin 2 n \\pi x / L)}{(2 n \\pi / L)}\\right)_{0}^{L}+\\int_{0}^{L} 2 x \\cdot \\sin \\frac{(2 n \\pi x / L)}{(2 n \\pi / L)} d x\\right]\\\\\n  &=\\frac{1}{L}\\left[\\frac{L ^{3}}{3}-0+2\\left\\{-x \\frac{\\cos \\frac{2 n \\pi x}{L}}{\\left(\\frac{2 n \\pi}{L}\\right)^{2}}+\\frac{\\sin \\frac{2 n \\pi x}{L}}{\\left(\\frac{2 n \\pi}{L}\\right)^{2}}\\right\\}_{0}^{L}\\right]\\\\&=\\frac{1}{L}\\left[\\frac{L^{3}}{3}-\\frac{L^{3}}{2(n \\pi)^{2}}\\right]\\\\&=\\frac{L^{2}}{3}-\\frac{L^{2}}{2 n^{2} \\pi^{2}}\n  \\end{align*}\n  \\subsection{Expectation values of \\Large{$\\hat{{p_{x}}}^{2}$}}\n  \\begin{align*}\n  \\left\\langle p^{2}\\right\\rangle&=\\frac{2}{L} \\int_{0}^{a} \\sin \\left(\\frac{n \\pi x}{a}\\right)\\left(-\\hbar^{2} \\frac{\\partial^{2}}{\\partial x^{2}}\\right) \\sin \\left(\\frac{n \\pi x}{L}\\right) d x\\\\&=\\frac{2}{L}\\left(-\\hbar^{2}\\right)\\left(\\frac{n \\pi}{L}\\right)^{2}(-1) \\int_{0}^{L} \\sin ^{2}\\left(\\frac{n \\pi x}{L}\\right) d x\\\\\n  &=\\frac{2}{L}\\left(-\\hbar^{2}\\right)\\left(\\frac{n \\pi}{L}\\right)^{2}(-1) \\int_{0}^{L} \\sin ^{2}\\left(\\frac{n \\pi x}{a}\\right) d x\\\\\n  &=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{L^{2}} \\int_{0}^{L}\\left[1-\\cos \\left(\\frac{2 n \\pi x}{L}\\right)\\right] d x\n  \\\\&=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{L^{3}} \\left[  x-\\frac{\\sin \\frac{2n\\pi x}{L}}{\\frac{2n\\pi x}{L}}\\right] _{0}^{L}\\\\&=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{L^{2}}\n  \\end{align*}\n  \\subsection{Uncertainty in Position and Momentum}\n  {\\textbf{Uncertainty in Position:}}\n  \\begin{align*}\n  \\Delta \\mathrm{x}&=\\left[\\left\\langle\\mathrm{x}^{2}\\right\\rangle-\\langle\\mathrm{x}\\rangle^{2}\\right]^{1 / 2}\\\\&=\\left[\\frac{L^{2}}{3}-\\frac{\\mathrm{L}^{2}}{2 {\\mathrm{n}}^{2} \\pi^{2}}-\\frac{{L}^{2}}{4}\\right]^{1 / 2}\\\\\n  &=\\left[\\frac{\\mathrm{L}^{2}}{12}-\\frac{\\mathrm{L}^{2}}{2 \\mathrm{n}^{2} \\pi^{2}}\\right]^{1 / 2}=L\\left[  \\frac{1}{12}-\\frac{1}{2 \\mathrm{n}^{2} \\pi^{2}}\\right]^{1 / 2} \n  \\end{align*}\n  {\\textbf{Uncertainty in Momentum:}}\n  \\begin{align*}\n  \\Delta\\mathrm{p}&=\\left[\\left\\langle\\mathrm{p}^{2}\\right\\rangle-\\langle\\mathrm{p}\\rangle^{2}\\right]^{1 / 2}\\\\&=\\left[ \\frac{n^{2} \\pi^{2} \\hbar^{2}}{L^{2}}-0\\right]^{\\frac{1}{2}} \\\\&=\\frac{\\mathrm{n} \\pi \\hbar}{\\mathrm{L}}\\\\\n  \\intertext{Therefore, the uncertainty product,} \\Delta \\mathrm{x} \\Delta \\mathrm{p}&= L\\left[  \\frac{1}{12}-\\frac{1}{2 \\mathrm{n}^{2} \\pi^{2}}\\right]^{1 / 2}   \\frac{n\\hbar }{L}\\\\&=\\mathrm{n} \\pi \\hbar\\left[\\frac{1}{12}-\\frac{1}{2 \\mathrm{n}^{2} \\pi^{2}}\\right]^{1 / 2}\n  \\intertext{For \\ $  n=1 $ ,}\n  \\Delta \\mathrm{x} \\Delta \\mathrm{p}&=1.136\\left(\\frac{\\hbar}{2}\\right) \\geq \\hbar / 2\n  \\end{align*}\n  \\subsection{Particle in a 2-D Box}\n  Consider a free particle of mass ${m}$ confined to move non-relativistically in a two-dimensional potential box of sides $L_{x}$ and $L_{y}$ parallel to the $x$ and $y$ -axes respectively. Since the particle is free, the potential inside the box is $V(x, y, )=0$. So, the total energy of the particle inside the box is equal to it's kinetic energy which is always a positive quantity.\n  \\begin{align}\n  \\intertext{Since the particle is confined two move in 2- dimensions i.e. \\ $x$\\  and \\ $y$\\, the  wavefunction of the system can be represented as,}\n  \\psi&= \\psi{({x,y})}= \\psi(x) \\psi(y)\\\\\n  \\intertext{The potential inside the box is given by,}\n  V(x, y)&=\\left\\{\\begin{array}{ll}\n  0, & \\text { For }\\quad  0<x<L_{x}\\ ;\\ 0<y<L_{y}\\\\\n  \\infty & \\text { Elsewhere } \n  \\end{array}\\right.\\\\\n  \\intertext{The schrodinger equation of the system,}\n  \\nabla^{2} \\psi{({x,y})}+ \\frac{2m}{\\hbar^{2}} (E-V)&=0\\\\\n  \\nabla^{2} \\psi{({x,y})}+ \\frac{2m}{\\hbar^{2}} E&=0\\quad (\\text{Since,} \\quad V=0)\\\\\n  \\nabla^{2}=\\frac{\\partial^{2}}{\\partial x^{2}}+ \\frac{\\partial^{2}}{\\partial y^{2}} \\quad &\\text{And} \\quad \\psi{({x,y})}=X(x)Y(y) \\\\ \\text{Then,}\\quad\n  \\left( \\frac{\\partial^{2}}{\\partial x^{2}}+ \\frac{\\partial^{2}}{\\partial y^{2}}\\right)   X(x)Y(y)+ \\frac{2m}{\\hbar^{2}} E&=0\\\\\n  Y\\frac{\\partial^{2} X}{\\partial x^{2}}+X\\frac{\\partial^{2} Y}{\\partial y^{2}}+ \\frac{2m}{\\hbar^{2}} E&=0 \\label{Particle 2-d}\n  \\intertext{Divide equation.\\ref{Particle 2-d} by (XY) gives,}\n  \\frac{1}{X}\\frac{\\partial^{2} X}{\\partial x^{2}}+\\frac{1}{Y}\\frac{\\partial^{2} Y}{\\partial y^{2}}+\\frac{2m(E_{x}+E_{y})}{\\hbar^{2}}&=0  \\label{particle 2d-1}\\\\\n  \\intertext{Then,}\\quad \\frac{1}{X}\\frac{\\partial^{2} X}{\\partial x^{2}}+\\frac{2m(E_{x})}{\\hbar^{2}}+\\frac{1}{Y}\\frac{\\partial^{2} Y}{\\partial y^{2}}+\\frac{2m(E_{y})}{\\hbar^{2}}&=0\n  \\intertext{The two terms must be equal to zero individually. Then,}\n  \\frac{1}{X}\\frac{\\partial^{2} X}{\\partial x^{2}}+\\frac{2m(E_{x})}{\\hbar^{2}}&=0 \\quad \\text{And}\\quad \\frac{1}{Y}\\frac{\\partial^{2} Y}{\\partial y^{2}}+\\frac{2m(E_{y})}{\\hbar^{2}}=0\\\\\n  \\frac{\\partial^{2} X}{\\partial x^{2}}+k_{x}^{2} X&=0 \\quad \\text{And}\\quad \\frac{\\partial^{2} Y}{\\partial y^{2}}+k_{y}^{2} Y=0\\\\\n  \\text{Where, }\\quad k_{x}^{2}&={\\frac{\\sqrt{2mE_{x}}}{\\hbar}}\n  \\intertext{The solutions of the above equations can be found as,}\n  X=\\sqrt{\\frac{2}{L_{x}}}\\sin{\\frac{n_{x}\\pi x}{L_{x}}} \\quad &\\text{And} \\quad  Y=\\sqrt{\\frac{2}{L_{y}}}\\sin{\\frac{n_{y}\\pi y}{L_{y}}}\\\\\n  \\text{Where, }\\quad k_{x}=\\frac{n_{x}\\pi }{L_{x}} \\quad &\\text{And } \\quad  k_{y}=\\frac{n_{y}\\pi}{L_{y}}\\\\\n  \\psi(x,y)&=\\sqrt{\\frac{2}{L_{x}}} \\sqrt{\\frac{2}{L_{y}}} \\sin{\\frac{n_{x}\\pi x}{L_{x}}}\\sin{\\frac{n_{y}\\pi y}{L_{y}}}\n  \\end{align}\n  \\subsection{Energy of a particle in a 2D Box}\n  \\begin{alignat*}{2}\n  \\intertext{We know that the total kinetic  energy of the particle can be written as,}\n  &\\left. \\right. &&E=E_{x}+E_{y}\\\\\n  &\\text{Where, } \\quad && E_{x}= \\frac{p_{x}^{2}}{2m} \\quad \\text{and} \\quad E_{y}= \\frac{p_{y}^{2}}{2m}\\\\\n  &\\text{But,} \\quad  &&p_{x}= \\frac{\\hbar^{2} k_{x}^{2}}{2m} \\quad \\text{and}\\quad  p_{y}= \\frac{\\hbar^{2} k_{y}^{2}}{2m}\\\\\n  &\\text{Then,} \\quad  &&E_{x}=\\frac{{ n_{x}^{2}\\hbar^{2}} {\\pi}^{2}}{2m {L_{x}}^{2}} \\quad \\text{and}\\quad E_{y}=\\frac{{ n_{y}^{2}\\hbar^{2}} {\\pi}^{2}}{2m {L_{y}}^{2}}\\\\\n  &\\text{Or,} \\quad &&E=  \\frac{\\hbar^{2}}{2m}\\left(  k_{x}^{2}+k_{y}^{2}\\right) \\\\\n  &\\text{Or,}\\quad &&E= \\frac{\\hbar^{2} \\pi^{2}}{2m}\\left(  \\frac{n_{x}^{2}}{L_{x}^{2}}+ \\frac{n_{y}^{2}}{L_{y}^{2}}\\right)\n  \\end{alignat*}\n  \\begin{center}\n  \t\\framebox{\n  \t\t\\parbox[t][2cm]{6cm}{\n  \t\t\t\n  \t\t\t\\addvspace{0.2cm} \\centering \n  \t\t\t\\textbf{Energy of a particle in 2-D box}\\\\ \\vspace{0.2cm}\n  \t\t\t$E= \\frac{\\hbar^{2} \\pi^{2}}{2m}\\left(  \\frac{n_{x}^{2}}{L_{x}^{2}}+ \\frac{n_{y}^{2}}{L_{y}^{2}}\\right)$} }\n  \\end{center}\n  \\subsubsection{Degeneracy of 2D box}\n  \\begin{align*}\n  \\intertext{Energy of a particle in 2-D box,}\n  E&= \\frac{\\hbar^{2} \\pi^{2}}{2m}\\left(  \\frac{n_{x}^{2}}{L_{x}^{2}}+ \\frac{n_{y}^{2}}{L_{y}^{2}}\\right)\\\\\n  \\text{Let,}\\quad L_{x}&=L_{y}=L\\\\\n  \\text{Then,}\\quad E&= \\frac{\\hbar^{2} \\pi^{2}}{2mL^{2}}\\left({n_{x}^{2}}+ {n_{y}^{2}}\\right)\\\\\n  \\text{Where,}\\quad n_{x}&=n_{y}=1,2,3\\cdots\\\\\\\\\n  \\text{Degeneracy of 2-D box}\\quad &= 1\\quad 2 \\quad 1 \\quad 2 \\quad 2 \\quad 2 \\cdots\n  \\end{align*}\n  \\begin{table}[H]\n  \t\\centering\n  \t\\arrayrulecolor{ocre}\n  \t\\newcolumntype{P}[1]{>{\\centering\\arraybackslash}p{#1}}\n  \t\\renewcommand*{\\arraystretch}{1.2}\n  \t\\begin{tabular}{|P{1cm}|P{1cm}|P{4cm}|P{3cm}|P{3cm}|}\n  \t\t\\hline\n  \t\t\\multicolumn{5}{|c|}{\\textbf{Degeneracy of 2-D box}}\\\\\\hline\\hline\n  \t\t$\\mathbf{n_{x}}$&$\\mathbf{n_{y}}$&\\textbf{Energy}-$\\mathbf{\\left({n_{x}^{2}}+ {n_{y}^{2}}+{n_{z}^{2}}\\right)\\varepsilon}$& $\\mathbf{\\psi(x,y,z)}$&\\textbf{Degeneracy}\\\\\\hline\\hline\n  \t\t1&1&2$\\varepsilon$&$\\psi(1,1)$ &None \\\\\\hline\n  \t\t1&2&5$\\varepsilon$ &$\\psi(1,2)$&\\multirow{2}{*}{Two fold } \\\\\\cline{1-4}\n  \t\t2&1&5$\\varepsilon$ &$\\psi(1,2)$&\\\\\\hline\n  \t\t2&2&8$\\varepsilon$ &$\\psi(2,2)$&None\\\\\\hline\n  \t\t1&3&10$\\varepsilon$ &$\\psi(1,3)$&\\multirow{2}{*}{Two fold } \\\\\\cline{1-4}\n  \t\t3&1&10$\\varepsilon$ &$\\psi(3,1)$&\\\\\\hline\n  \t\t2&3&13$\\varepsilon$ &$\\psi(2,3)$&\\multirow{2}{*}{Two fold } \\\\\\cline{1-4}\n  \t\t3&2&13$\\varepsilon$ &$\\psi(3,2)$&\\\\\\hline\n  \t\t1&4&17$\\varepsilon$ &$\\psi(1,4)$&\\multirow{2}{*}{Two fold } \\\\\\cline{1-4}\n  \t\t4&1&17$\\varepsilon$ &$\\psi(4,1)$&\\\\\\hline\n  \t\\end{tabular}\n  \\end{table}\n  \\subsection{Particle in a 3-D Box}\n  The particle in a 3-D box problem can be solved in the same way as that of particle in a 3-D box. Consider a free particle of mass ${m}$ confined to move non-relativistically in a three-dimensional potential box of sides $L_{x}, L_{y}$ and $L_{z}$ parallel to the $x, y$ and $z$ -axes respectively. Since the particle is free, the potential inside the box is $V(x, y, z)=0$. So, the total energy of the particle inside the box is equal to it's kinetic energy which is always a positive quantity.\n  \\begin{align}\n  \\intertext{If $ v $ be the velocity, then the momentum of the particle $p=m v$ and it's energy,}\n  E&=\\frac{1}{2}{m v}^{2}=\\frac{p^{2}}{2 m}\n  \\intertext{The potential inside the box is given by,}\n  V(x, y, z)=&\\left\\{\\begin{array}{ll}\n  0, & \\text { For }\\quad  0<x<L_{x}, 0<y<L_{y}, 0<z<L_{z}\\\\\n  \\infty & \\text { For } \\quad x>L_{x}, \\quad y>L_{y}, \\quad z>L_{z}\n  \\end{array}\\right.\n  \\intertext { The wave equation describing the motion of the particle can be writen as, }\\\\\n  \\hat{H} \\psi&=-\\frac{\\hbar^{2}}{2 m} \\nabla^{2} \\psi=E \\psi \\\\ \\frac{\\partial^{2} \\psi}{\\partial x^{2}}+\\frac{\\partial^{2} \\psi}{\\partial y^{2}}+\\frac{\\partial^{2} \\psi}{\\partial z^{2}}+\\frac{2 m E}{\\hbar^{2}} \\psi&=0 \\label{particle in 3d-3}\n  \\intertext{As $V(x, y, z)=\\infty$\\  at the boundaries and outside the box $\\psi(x, y, z)=0$ at the boundaries and outside the potential box. The boundary conditions can be written as,}\n  \\left.\\begin{array}{r}\n  \\psi(x, y, z)=0 \\text { at } x=0 \\text { and } x=a \\\\\n  y=0 \\text { and } y=b \\\\\n  z=0 \\text { and } z=c\n  \\end{array}\\right\\}\n  \\intertext{The solution of the equation can be written as,}\n  \\psi(x, y, z)&=X(x) Y(y) Z(z) \\label{particle in 3d-4}\n  \\intertext{ When we substitute equation.\\ref{particle in 3d-4} in \\ref{particle in 3d-3}, we get,}\n  Y Z \\frac{d^{2} X}{d x^{2}}+Z X \\frac{d^{2} Y}{d y^{2}}+X Y \\frac{d^{2} Z}{d z^{2}}+\\frac{2 m E}{\\hbar^{2}} X Y Z&=0  \\label{particle in 3d-5}\n  \\intertext{Dividing equation. \\ref{particle in 3d-5} by (XYZ)\\ we get,}\n  \\frac{1}{X} \\frac{d^{2} X}{d x^{2}}+\\frac{1}{Y} \\frac{d^{2} Y}{d y^{2}}+\\frac{1}{Z} \\frac{d^{2} Z}{d z^{2}}+\\frac{2 m E}{\\hbar^{2}}&=0\n  \\intertext{If $v_{x}, y_{y}$ and $v_{z}$ be the component of velocity of the particle along the $x, y$ and $z$ -axes respectively, then the corresponding kinetic energies of the particle are,}\n  E_{x}=\\frac{1}{2} m v_{x}^{2}, \\quad E_{y}&=\\frac{1}{2} m v_{y}^{2} \\ \\text { And } E_{z}=\\frac{1}{2} m v_{z}^{2}\\\\\\\\ \\text { Such that, }\\quad E&=E_{x}+E_{y}+E_{z}\\\\\\\\\n  \\left[\\frac{1}{X} \\frac{d^{2} X}{d x^{2}}+\\frac{2 m E_{x}}{\\hbar^{2}}\\right]&+\\left[\\frac{1}{Y} \\frac{d^{2} Y}{d y^{2}}+\\frac{2 m E_{y}}{\\hbar^{2}}\\right]+\\left[\\frac{1}{Z} \\frac{d^{2} Z}{d z^{2}}+\\frac{2 m {E}_{z}}{ \\hbar^{2}}\\right]=0\\\\\\\\\n  \\frac{1}{X} \\frac{d^{2} X}{d x^{2}}+\\frac{2 m E_{x}}{\\hbar^{2}} X=0 \\quad &\\text{and}\\quad\n  \\frac{1}{Y} \\frac{d^{2} Y}{d y^{2}}+\\frac{2 m E_{y}}{\\hbar^{2}} Y=0  \\quad \\text{and}\\quad\n  \\frac{1}{Z} \\frac{d^{2} Z}{d z^{2}}+\\frac{2 m E_{z}}{\\hbar^{2}} Z=0\\\\\n  X(x)=A_{1} \\sin k_{x} x+B_{1} \\cos k_{x} x \\ &\\text { where }\\ k_{x}=\\frac{\\sqrt{2 m E_{x}}}{\\hbar}\\\\\n  Y(y)=A_{2} \\sin{k}_{{y}} y+B_{2} \\cos k_{y} y  \\ & \\text { where }\\ k_{y}=\\frac{\\sqrt{2 m E_{y}}}{\\hbar}\\\\\n  Z(z)=A_{3} \\sin k_{z} z+B_{3} \\cos k_{z} z  \\ & \\text { where }\\ k_{z}=\\frac{\\sqrt{2 m E_{z}}}{\\hbar}\n  \\intertext{Then the solution of the Schrodinger equation for the wavefunction becomes,}\n  \\psi(x,y,z)&=\\sqrt{\\frac{2}{L_{x}}} \\sqrt{\\frac{2}{L_{z}}} \\sqrt{\\frac{2}{L_{x}}}\\sin{\\frac{n_{x}\\pi x}{L_{x}}}\\sin{\\frac{n_{y}\\pi y}{L_{y}}}\\sin{\\frac{n_{z}\\pi z}{L_{z}}}\n  \\end{align}\n  \\subsection{Energy of a particle in a 3D Box}\n  \\begin{alignat*}{2}\n  \\intertext{We know that the total kinetic  energy of the particle can be written as,}\n  &\\left. \\right. &&E=E_{x}+E_{y}+E_{z}\\\\\n  &\\text{Where, } \\quad && E_{x}= \\frac{p_{x}^{2}}{2m} \\quad \\text{and} \\quad E_{y}= \\frac{p_{y}^{2}}{2m}\\quad \\text{and} \\quad E_{z}= \\frac{p_{z}^{2}}{2m}\\\\\n  &\\text{But,} \\quad  &&p_{x}= \\frac{\\hbar^{2} k_{x}^{2}}{2m} \\quad \\text{and}\\quad  p_{y}= \\frac{\\hbar^{2} k_{y}^{2}}{2m}\\quad \\text{and}\\quad  p_{z}= \\frac{\\hbar^{2} k_{z}^{2}}{2m}\\\\\n  &\\text{Then,} \\quad  &&E_{x}=\\frac{{ n_{x}^{2}\\hbar^{2}} {\\pi}^{2}}{2m {L_{x}}^{2}} \\quad \\text{and}\\quad E_{y}=\\frac{{ n_{y}^{2}\\hbar^{2}} {\\pi}^{2}}{2m {L_{y}}^{2}} \\quad \\text{and}\\quad E_{z}=\\frac{{ n_{z}^{2}\\hbar^{2}} {\\pi}^{2}}{2m {L_{z}}^{2}}\\\\\n  &\\text{Or,} \\quad &&E=  \\frac{\\hbar^{2}}{2m}\\left(  k_{x}^{2}+k_{y}^{2}+k_{z}^{2}\\right) \\\\\n  &\\text{Or,}\\quad &&E= \\frac{\\hbar^{2} \\pi^{2}}{2m}\\left(  \\frac{n_{x}^{2}}{L_{x}^{2}}+ \\frac{n_{y}^{2}}{L_{y}^{2}}+\\frac{n_{z}^{2}}{L_{z}^{2}}\\right)\n  \\end{alignat*}\n  \\begin{center}\n  \t\\framebox{\n  \t\t\\parbox[t][2cm]{6cm}{\n  \t\t\t\n  \t\t\t\\addvspace{0.2cm} \\centering \n  \t\t\t\\textbf{Energy of a particle in 3-D box}\\\\ \\vspace{0.2cm}\n  \t\t\t$E= \\frac{\\hbar^{2} \\pi^{2}}{2m}\\left(  \\frac{n_{x}^{2}}{L_{x}^{2}}+ \\frac{n_{y}^{2}}{L_{y}^{2}} + \\frac{n_{z}^{2}}{L_{z}^{2}}\\right)$} }\n  \\end{center}\n  \\subsubsection{Degeneracy of 3-D box}\n  \\begin{align*}\n  \\intertext{Energy of a particle in 3-D box,}\n  E&= \\frac{\\hbar^{2} \\pi^{2}}{2m}\\left(  \\frac{n_{x}^{2}}{L_{x}^{2}}+ \\frac{n_{y}^{2}}{L_{y}^{2}}+\\frac{n_{z}^{2}}{L_{z}^{2}}\\right)\\\\\n  \\text{Let,}\\quad L_{x}&=L_{y}=L_{z}=L\\\\\n  \\text{Then,}\\quad E&= \\frac{\\hbar^{2} \\pi^{2}}{2mL^{2}}\\left({n_{x}^{2}}+ {n_{y}^{2}}+{n_{z}^{2}}\\right)\\\\\n  \\text{Where,}\\quad n_{x}&=n_{y}=n_{z}=1,2,3\\cdots\\\\\\\\\n  \\text{Degeneracy of 3-D box}\\quad &= 1\\quad 3 \\quad 3 \\quad 3 \\quad 3 \\quad 6 \\quad 3  \\cdots\n  \\end{align*}\n  \n  \n  \\begin{table}[H]\n  \t\\centering\n  \t\\arrayrulecolor{ocre}\n  \t\\newcolumntype{P}[1]{>{\\centering\\arraybackslash}p{#1}}\n  \t\n  \t\\renewcommand*{\\arraystretch}{1.2}\n  \t\\begin{tabular}{|P{1cm}|P{1cm}|P{1cm}|P{2.5cm}|P{3cm}|P{3cm}|}\n  \t\t\\hline\n  \t\t\\multicolumn{6}{|c|}{\\textbf{Degeneracy of 3-D box}}\\\\\\hline\\hline\n  \t\t$\\mathbf{n_{x}}$&$\\mathbf{n_{y}}$&$\\mathbf{n_{z}}$& \\textbf{Energy}\\newline$\\mathbf{\\left({n_{x}^{2}}+ {n_{y}^{2}}+{n_{z}^{2}}\\right)\\varepsilon}$& $\\mathbf{\\psi(x,y,z)}$&\\textbf{Degeneracy}\\\\\\hline\\hline\n  \t\t1&1&1&3$\\varepsilon$&$\\psi(1,1,1)$ &None \\\\\\hline\n  \t\t1&1&2&6$\\varepsilon$ &$\\psi(1,1,2)$&\\multirow{3}{*}{Three fold } \\\\\\cline{1-5}\n  \t\t1&2&1&6$\\varepsilon$ &$\\psi(1,2,1)$&\\\\\\cline{1-5}\n  \t\t2&1&1&6$\\varepsilon$ &$\\psi(2,1,1)$&\\\\\\hline\n  \t\t1&2&2&9$\\varepsilon$ &$\\psi(1,1,3)$&\\multirow{3}{*}{Three fold } \\\\\\cline{1-5}\n  \t\t2&1&2&9$\\varepsilon$ &$\\psi(1,3,1)$&\\\\\\cline{1-5}\n  \t\t2&2&1&9$\\varepsilon$ &$\\psi(3,1,1)$&\\\\\\hline\n  \t\t1&1&3&11$\\varepsilon$ &$\\psi(1,1,3)$&\\multirow{3}{*}{Three fold } \\\\\\cline{1-5}\n  \t\t1&3&1&11$\\varepsilon$ &$\\psi(1,3,1)$&\\\\\\cline{1-5}\n  \t\t3&1&1&11$\\varepsilon$ &$\\psi(3,1,1)$&\\\\\\hline\n  \t\t2&2&2&12$\\varepsilon$ &$\\psi(2,2,2)$& None\\\\\\hline\n  \t\t1&2&3&14$\\varepsilon$ &$\\psi(1,1,2)$&\\multirow{6}{*}{Six fold } \\\\\\cline{1-5}\n  \t\t2&1&3&14$\\varepsilon$ &$\\psi(1,2,1)$&\\\\\\cline{1-5}\n  \t\t3&2&1&14$\\varepsilon$ &$\\psi(1,2,1)$&\\\\\\cline{1-5}\n  \t\t3&1&2&14$\\varepsilon$ &$\\psi(1,2,1)$&\\\\\\cline{1-5}\n  \t\t1&3&2&14$\\varepsilon$ &$\\psi(1,2,1)$&\\\\\\cline{1-5}\n  \t\t2&3&1&14$\\varepsilon$ &$\\psi(1,2,1)$&\\\\\\hline\n  \t\t3&2&2&17$\\varepsilon$ &$\\psi(1,1,3)$&\\multirow{3}{*}{Three fold } \\\\\\cline{1-5}\n  \t\t2&3&2&17$\\varepsilon$ &$\\psi(1,3,1)$&\\\\\\cline{1-5}\n  \t\t2&2&3&17$\\varepsilon$ &$\\psi(3,1,1)$&\\\\\\hline\n  \t\t\n  \t\t\n  \t\t\n  \t\\end{tabular}\n  \\end{table}\n  \\begin{figure}[H]\n  \t\\centering\n  \t\\includegraphics[height=7cm,width=7.5cm]{3D degeneracy}\n  \t\\caption{Energy levels of 3D box}\n  \t\\label{Energy levels of 3D box.}\n  \\end{figure}\n\\section{Finite potential well}\n\nWe have discussed potential wells with infinite potentials but in our real physical world \nPotential energies are never infinite , and the box with infinitely hard\nwalls  has no physical counterpart. However, potential wells\nwith barriers of finite height certainly do exist. Let us see what the wave functions and\nenergy levels of a particle in such a well are.\n\\begin{align*}\nV(x)&=\\left\\{\\begin{array}{ccc}\n-V_{0}, & \\text { For } & -L < x< L \\\\\n0, & \\text { For } & |x| \\geq L\n\\end{array}\\right.\n\\end{align*}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=7cm,width=9cm]{finite squre well}\n\t\\caption{Finite potential well}\n\t\\label{}\n\\end{figure}\n\nThe potential energy is zero for $|x|>a$. The potential energy is negative and equal to $-V_{0}$ in the well, because we defined $V_{0}$ to be a positive number. The width of the well is $2 a$.The width of the well is $2 a$.\nentering regions $ I $ and $ III $. In quantum mechanics, the particle also bounces back and forth, but now it has a certain probability of penetrating into regions ${I}$ and $ III $ even though $E<U$. In regions $ I $ and $ III $ Schrödinger's steady-state equation is.\n\\begin{align}\n\\intertext{We have to find the Schrodinger equation in the potential well in the regions I,II and I. The schrodinger equation In regions I,}\n\\frac{d^{2} \\psi_{I}}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}(E-V) \\psi_{I}&=0\\\\\n\\frac{d^{2} \\psi_{I}}{d x^{2}}-\\frac{2 m}{\\hbar^{2}}(V-E) \\psi_{I}&=0\\\\\nD^{2}-K_{1}^{2}&=0\\\\\nD&=\\pm K_{1}\\\\\\text{Then the wavefunction,}\\quad  \\psi_{I}&=A e^{-K_{1}x} +B e^{K_{1}x}\n\\intertext{In regions II Schrödinger's steady-state equation is,}\n\\frac{d^{2} \\psi_{II}}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}(E-V) \\psi_{II}&=0\\\\\n\\frac{d^{2} \\psi_{II}}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}E \\psi_{II}&=0\\\\\nD^{2}+K_{2}^{2}&=0\\\\\nD&=\\pm i K_{2}\\\\\n\\psi_{II}&=C\\cos K_{2}x+D\\sin K_{2}x\n\\intertext{The schrodinger equation In regions III,}\n\\frac{d^{2} \\psi_{III}}{d x^{2}}-\\frac{2 m}{\\hbar^{2}}(V-E) \\psi_{III}&=0\\\\\nD^{2}-K_{1}^{2}&=0\\\\\nD&=\\pm K_{1}\\\\\\text{Then the wavefunction,}\\quad  \\psi_{III}&=F e^{-K_{1}x} +G e^{K_{1}x}\n\\end{align}\n\\begin{align}\n\\intertext{Both $\\psi_{I}$ and $\\psi_{\\mathrm{III}}$ must be finite everywhere. Since $e^{-K_{1} x} \\rightarrow \\infty$ as $x \\rightarrow-\\infty$ and $e^{K_{1} x} \\rightarrow \\infty$ as $x \\rightarrow \\infty$, the coefficients $A$ and $F$ must therefore be $0 .$ Hence we have,}\n\\psi_\\mathrm{I} &=B e^{K_{1} x} \\quad \\text{And }\\quad  \\psi_{\\mathrm{III}} =F e^{-K_{1} x}\n\\intertext{These wave functions decrease exponentially inside the barriers at the sides of the well. Within the well Schrödinger's equation is the same as that of in infinite potential well and its solution is again.}\n\\psi_{\\mathrm{II}}&=C \\sin \\frac{\\sqrt{2 m E}}{\\hbar} x+D \\cos \\frac{\\sqrt{2 m E}}{\\hbar} x \\label{finite potential well}\n\\intertext{Here we have to apply the following rigid boundary conditions. Since the potential is an even function we only need to apply boundary condition on one side of the potential. (Say, x>a , at the region III)}\n\\text { 1. }\\left(\\psi_{I}\\right)_{x=0}\\hspace{0.6cm} &=\\left(\\psi_{II}\\right)_{x=0}\\\\\n\\text { 2. }\\left(\\frac{d \\psi_{I}}{d x}\\right)_{x=0}&=\\left(\\frac{d \\psi_{II}}{d x}\\right)_{x=0}\n\\intertext{Applying these boundary conditions to equation. \\ref{finite potential well} we get,}\n\\intertext{The continuity of $\\psi(x)$, at $x=L$, says}\nF e^{-K_{1} L}&=D \\cos (K_{2} L)\\label{finite 2}\n\\intertext{And the continuity of $d \\psi / d x$, says,}\n-K_{1} F e^{-K_{1} a}&=-K_{2} D \\sin (K_{2}L)\\label{finite 3}\n\\intertext{Dividing equation \\ref{finite 2} by equation \\ref{finite 3}, we find that,}\nK_{1}=K_{2} \\tan (K_{2} L) \n\\intertext{This is a formula for the allowed energies, since $K_{1}$ and $K_{2}$ are both functions of $E$. To solve for $E$, we first adopt some nicer notation: Let}\nz \\equiv K_{2} L, \\quad \\text { and } \\quad z_{0} \\equiv \\frac{L}{\\hbar} \\sqrt{2 m V_{0}}\n\\end{align}\n\\section{Step potential}\nrepresent a particle undergoing scattering in some potential. Here we examine the step potential  defined by,\n$$\nV(x)=\\left\\{\\begin{array}{ll}\n0, & x<0 \\\\\nV_{0}, & x \\geq 0\n\\end{array}\\right.\n$$ \nOur solutions to the Schrödinger equation with this potential will be scattering states of definite energy $E .$ We can consider two cases: \n\\begin{enumerate}\n\t\\item $E>V_{0}$. \n\t\\item $E<V_{0}$.\n\\end{enumerate}\nIn both cases the wavefunction extends infinitely to the left and is non-normalizable.\n\\subsection{Step Potential with $E>V_{0}$.}\nLet us begin with the case $E>V_{0}$.\n\\begin{align*}\n\\intertext{The potential in the region I ,\\ $ V=0 $ ,}\n\\frac{d^{2} \\psi_{I}}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}(E-V) \\psi_{\\text{I}}&=0\n\\intertext{The  Schrödinger equation in the region can be written as,}\n\\frac{d^{2} \\psi_{\\text{I}}}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}E \\psi_{\\text{I}}&=0\\\\\nD^{2}+ K_{1}^{2}&=0\\\\\nD&=\\pm iK_{1}\\\\\n\\psi_{\\text{II}}&=Ae^{iK_{1}x}+Be^{-iK_{1}x}\n\\intertext{The potential in the region II ,\\ $ V=V_{0} $ ,}\n\\intertext{The  Schrödinger equation in the region II can be written as,}\n\\frac{d^{2} \\psi_{\\text{II}}}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}E \\psi_{\\text{II}}&=0\\\\\nD^{2}+ K_{2}^{2}&=0\\\\\nD&=\\pm iK_{2}\\\\\n\\psi_{\\text{II}}&=Ce^{iK_{2}x}+De^{-iK_{2}x}\n\\end{align*}\n\\subsection{Tunnel Effect}\nAlthough the walls of the potential well were of finite height, they were assumed to be infinitely thick. As a result the particle was trapped forever even though it could penetrate the walls. We next look at the situation of a particle that strikes a potential barrier of height $U$, again with $E<\\mathrm{U}$, but here the barrier has a finite width. What we will find is that the particle has a certain probability not necessarily great, but not zero either of passing through the barrier and emerging on the other side.\n\\section{The potential barrier}\nConsider a beam of particle of mass m that are sent from the left on the potential barrier\\\\\n$V(x)= \\begin{cases}0, & x<0 \\\\ V_{0}, & 0 \\leq x \\leq a \\\\ 0, & x>a\\end{cases}$\nThis potential, which is repulsive, supports no bound states. We are dealing here, as in the case of the potential step, with a one-dimensional scattering problem.\n\nAgain, let us consider the following two cases which correspond to the particle energies being respectively larger and smaller than the potential barrier.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=9cm,width=15cm]{diagram-20220112-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n\\subsection{The case $E>V_0$}\nClassically ,the particle that approach the barrier from the left at constant momentum,$p_1=\\sqrt{2mE}$,as they enter the region $0\\leq x \\leq a$ will slow down to a momentum $p_2=\\sqrt{2m(E-V_0)}$.They will maintain the momentum $p_2$ until they reach the point $x=a$.Then as soon as they pass beyond the point $x=a$ they will accelerate to the momentum $p_3=\\sqrt{2mE}$ and maintain this value in the entire region $x>a$.Since the particles have enough energy to cross the barrier none of the particle will be reflected back;all the particles will emerge on the right side of $x=a$:\\textit{total transmission}\\\\\nThe wavefunction in three region can be written as \n$$\\psi(x)= \\begin{cases}\\psi_{1}(x)=A e^{i k_{1} x}+B e^{-i k_{1} x}, & x \\leq 0, \\\\ \\psi_{2}(x)=C e^{i k_{2} x}+D e^{-i k_{2} x}, & 0<x<a, \\\\ \\psi_{3}(x)=E e^{i k_{1} x}, & x \\geq a,\\end{cases}$$\nwhere $k_{1}=\\sqrt{2 m E / \\hbar^{2}}$ and $k_{2}=\\sqrt{2 m\\left(E-V_{0}\\right) / \\hbar^{2}}$. The constants $B, C, D$, and $E$ can be obtained in terms of $A$ from the boundary conditions: $\\psi(x)$ and $d \\psi / d x$ must be continuous at $x=0$ and $x=a$, respectively:\n$$\\begin{aligned}\n\t&\\psi_{1}(0)=\\psi_{2}(0), \\quad \\frac{d \\psi_{1}(0)}{d x}=\\frac{d \\psi_{2}(0)}{d x}, \\\\\n\t&\\psi_{2}(a)=\\psi_{3}(a), \\quad \\frac{d \\psi_{2}(a)}{d x}=\\frac{d \\psi_{3}(a)}{d x} .\n\\end{aligned}$$\nThese equations yield\n$$\n\\begin{aligned}\nA+B &=C+D, \\quad i k_{1}(A-B)=i k_{2}(C-D), \\\\\nC e^{i k_{2} a}+D e^{-i k_{2} a} &=E e^{i k_{1} a}, \\quad i k_{2}\\left(C e^{i k_{2} a}-D e^{-i k_{2} a}\\right)=i k_{1} E e^{i k_{1} a} .\n\\end{aligned}\n$$\nSolving for $E$, we obtain\n$$\n\\begin{aligned}\nE &=4 k_{1} k_{2} A e^{-i k_{1} a}\\left[\\left(k_{1}+k_{2}\\right)^{2} e^{-i k_{2} a}-\\left(k_{1}-k_{2}\\right)^{2} e^{i k_{2} a}\\right]^{-1} \\\\\n&=4 k_{1} k_{2} A e^{-i k_{1} a}\\left[4 k_{1} k_{2} \\cos \\left(k_{2} a\\right)-2 i\\left(k_{1}^{2}+k_{2}^{2}\\right) \\sin \\left(k_{2} a\\right)\\right]^{-1} .\n\\end{aligned}\n$$\nThe transmission coefficient is thus given by\n$$\n\\begin{aligned}\nT &=\\frac{k_{1}|E|^{2}}{k_{1}|A|^{2}}=\\left[1+\\frac{1}{4}\\left(\\frac{k_{1}^{2}-k_{2}^{2}}{k_{1} k_{2}}\\right)^{2} \\sin ^{2}\\left(k_{2} a\\right)\\right]^{-1} \\\\\n&=\\left[1+\\frac{V_{0}^{2}}{4 E\\left(E-V_{0}\\right)} \\sin ^{2}\\left(a \\sqrt{2 m I_{0} / \\hbar^{2}} \\sqrt{E / V_{0}-1}\\right)\\right]^{-1} .\n\\end{aligned}\n$$\n$$\\left(\\frac{k_{1}^{2}-k_{2}^{2}}{k_{1} k_{2}}\\right)^{2}=\\frac{V_{0}^{2}}{E\\left(E-V_{0}\\right)}$$\nUsing the notation $\\lambda=a \\sqrt{2 m V_{0} / \\hbar^{2}}$ and $\\varepsilon=E / V_{0}$, we can rewrite $T$ as\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][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\t $$\n\t\t\t T=\\left[1+\\frac{1}{4 \\varepsilon(\\varepsilon-1)} \\sin ^{2}(\\lambda \\sqrt{\\varepsilon-1})\\right]^{-1} .\n\t\t\t $$\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n\nSimilarly, we can show that reflection coefficient R\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][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\t $$\n\t\t\t R=\\frac{\\sin ^{2}(\\lambda \\sqrt{\\varepsilon-1})}{4 \\varepsilon(\\varepsilon-1)+\\sin ^{2}(\\lambda \\sqrt{\\varepsilon-1})}=\\left[1+\\frac{4 \\varepsilon(\\varepsilon-1)}{\\sin ^{2}(\\lambda \\sqrt{\\varepsilon-1})}\\right]^{-1} .\n\t\t\t $$\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n\\subsection{The case $E<V_0$:Tunneling}\nWe are now going to show that the quantum mechanical predictions differ sharply from their classical counterparts, for the wave function is not zero beyond the barrier. The solutions of the Schrödinger equation in the three regions yield expressions that are similar to (4.36) except that $\\psi_{2}(x)=C e^{i k_{2} x}+D e^{-i k_{2} x}$ should be replaced with $\\psi_{2}(x)=C e^{k_{2} x}+D e^{-k_{2} x}:$\\\\\n$$\\psi(x)= \\begin{cases}\\psi_{1}(x)=A e^{i k_{1} x}+B e^{-i k_{1} x}, & x \\leq 0 \\\\ \\psi_{2}(x)=C e^{k_{2} x}+D e^{-k_{2} x}, & 0<x<a \\\\ \\psi_{3}(x)=E e^{i k_{1} x}, & x \\geq a\\end{cases}$$\nwhere $k_{1}^{2}=2 m E / \\hbar^{2}$ and $k_{2}^{2}=2 m\\left(V_{0}-E\\right) / \\hbar^{2}$. The behavior of the probability density corresponding to this wave function is expected, as displayed in Figure, to be oscillatory in the regions $x<0$ and $x>a$, and exponentially decaying for $0 \\leq x \\leq a$.\\\\\nTo find the reflection and transmission coefficients,\n$$\nR=\\frac{|B|^{2}}{|A|^{2}}, \\quad T=\\frac{|E|^{2}}{|A|^{2}},\n$$\nwe need only to calculate $B$ and $E$ in terms of $A$. The continuity conditions of the wave function and its derivative at $x=0$ and $x=a$ yield\n$$\\begin{aligned}\n\tA+B &=C+D, \\\\\n\ti k_{1}(A-B) &=k_{2}(C-D), \\\\\n\tC e^{k_{2} a}+D e^{-k_{2} a} &=E e^{i k_{1} a}, \\\\\n\tk_{2}\\left(C e^{k_{2} a}-D e^{-k_{2} a}\\right) &=i k_{1} E e^{i k_{1} a} .\n\\end{aligned}$$\nThe last two equations lead to the following expressions for $C$ and $D$ :\n$$\nC=\\frac{E}{2}\\left(1+i \\frac{k_{1}}{k_{2}}\\right) e^{\\left(i k_{1}-k_{2}\\right) a}, \\quad D=\\frac{E}{2}\\left(1-i \\frac{k_{1}}{k_{2}}\\right) e^{\\left(i k_{1}+k_{2}\\right) a} .\n$$\nFrom these equations we can deduce the expression for Reflection coefficient and transmission coefficients as\\\\\nR in terms of T,\\\\\n$$R=\\frac{1}{4} T\\left(\\frac{k_{1}^{2}+k_{2}^{2}}{k_{1} k_{2}}\\right)^{2} \\sinh ^{2}\\left(k_{2} a\\right) $$\nWhere T is \\\\\n$$T=\\left[1+\\frac{1}{4}\\left(\\frac{k_{1}^{2}+k_{2}^{2}}{k_{1} k_{2}}\\right)^{2} \\sinh ^{2}\\left(k_{2} a\\right)\\right]^{-1} $$\nNow since\n$$\n\\left(\\frac{k_{1}^{2}+k_{2}^{2}}{k_{1} k_{2}}\\right)^{2}=\\left(\\frac{V_{0}}{\\sqrt{E\\left(V_{0}-E\\right)}}\\right)^{2}=\\frac{V_{0}^{2}}{E\\left(V_{0}-E\\right)}\n$$\nNow R and T becomes\\\\\n$$\\begin{aligned}\n\tR &=\\frac{1}{4} \\frac{V_{0}^{2} T}{E\\left(V_{0}-E\\right)} \\sinh ^{2}\\left(\\frac{a}{\\hbar} \\sqrt{2 m\\left(V_{0}-E\\right)}\\right) \\\\\n\tT &=\\left[1+\\frac{1}{4} \\frac{V_{0}^{2}}{E\\left(V_{0}-E\\right)} \\sinh ^{2}\\left(\\frac{a}{\\hbar} \\sqrt{2 m\\left(V_{0}-E\\right)}\\right)\\right]^{-1},\n\\end{aligned}$$\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][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\t $$\\begin{aligned}\n\t\t\t R &=\\frac{T}{4 \\varepsilon(1-\\varepsilon)} \\sinh ^{2}(\\lambda \\sqrt{1-\\varepsilon}) \\\\\n\t\t\t T &=\\left[1+\\frac{1}{4 \\varepsilon(1-\\varepsilon)} \\sinh ^{2}(\\lambda \\sqrt{1-\\varepsilon})\\right]^{-1}\n\t\t\t \\end{aligned}$$\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n$\\text { where } \\lambda=a \\sqrt{2 m V_{0} / \\hbar^{2}} \\text { and } \\varepsilon=E / V_{0} \\text {. }$\\\\\n\\textbf{Special cases}\n\\begin{enumerate}\n\t\\item  If $E \\ll V_{0}$, hence $\\varepsilon \\ll 1$ or $\\lambda \\sqrt{1-\\varepsilon} \\gg 1$, we may approximate $\\sinh (\\lambda \\sqrt{1-\\varepsilon}) \\simeq$ $\\frac{1}{2} \\exp (\\lambda \\sqrt{1-\\varepsilon})$. We can thus show that the transmission coefficient becomes asymptotically equal to\n\t$$\n\t\\begin{aligned}\n\tT & \\simeq\\left\\{\\frac{1}{4 \\varepsilon(1-\\varepsilon)}\\left[\\frac{1}{2} e^{2 \\sqrt{1-\\varepsilon}}\\right]^{2}\\right\\}^{-1}=16 \\varepsilon(1-\\varepsilon) e^{-2 i \\sqrt{1-\\varepsilon}} \\\\\n\t&=\\frac{16 E}{V_{0}}\\left(1-\\frac{E}{V_{0}}\\right) e^{-(2 a / \\hbar) \\sqrt{2 m\\left(V_{0}-E\\right)}}\n\t\\end{aligned}\n\t$$\n\tThis shows that the transmission coefficient is not zero, as it would be classically, but has a finite value. So, quantum mechanically, there is a finite tunneling beyond the barrier, $x>a$.\n\t\\item Taking the classical limit $\\hbar \\rightarrow 0$, the coefficients reduce to the classical result: $R \\rightarrow 1$ and $T \\rightarrow 0$.\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Harmonic Oscillator}\nThere are only a very few potentials for which the Schrodinger equation can be solved analytically. The most important of these is the potential of the harmonic oscillator.\n$$\nV(x)=\\frac{1}{2} kx^{2}=\\frac{1}{2} km\\omega^{2}x^{2}\n$$\nbecause so many of the systems encountered in nuclear physics, condensed matter physics, and elementary particle physics can be treated, to a first approximation, as a set of coupled harmonic oscillators. As we know harmonic motion takes place when a system of some kind vibrates about an equilibrium configuration.\n\\subsection{Harmonic Oscillator-Classical treatement}\nIn the special case of simple harmonic motion, the restoring force $F$ on a particle of mass $m$ is linear; that is, $F$ is proportional to the particle's displacement $x$ from its equilibrium position and in the opposite direction.\nNewton's law of motion $F=m a$ is generally non-linear, since $F(x)$ is usually a nonlinear function of $x$. However, if $F$ depends linearly on $x$, it follows that the potential depends quadratically on $x$, which implies a harmonic oscillator. We can write the equation of motion as,\n\\begin{align}\nF &\\propto -x \\Rightarrow  F =-k x \\\\\n\\intertext{The potential of a 1-dimensional harmonic potential can be written as,}\nU(x)&=\\frac{1}{2}k x^{2} \\\\ \\text{But,}\\ k&=m\\omega^{2}\\quad  \\text{And} \\ \\omega= \\sqrt{\\frac{k}{m}}\\quad \\Rightarrow \\quad  \\nu=\\frac{1}{2\\pi}\\sqrt{\\frac{k}{m}}\\quad (\\text{Angular frequency})\\\\\nU(x)&=\\frac{1}{2}m\\omega^{2} x^{2}\n\\intertext{According to  Newton's laws of motion,}\nF&=m a\\\\\n-k x&=m \\frac{d^{2} x}{d t^{2}}\\\\\n\\frac{d^{2} x}{d t^{2}}+\\frac{k}{m} x&=0\\\\\n\\frac{d^{2} x}{d t^{2}}+\\omega^{2} x&=0\\\\\n\\intertext{The solution of the equation can be written as,}\nx(t)&=A \\cos (\\omega t)+A \\sin (\\omega t)\n\\intertext{Applying initial conditions, the solution will become}\nx(t)&=A \\cos (\\omega t+\\phi) \\text{Where $A$ is the amplitude  of the wave}\n\\end{align}\nThe value of $\\phi$, the phase angle, depends upon what $x$ is at the time $t=0$ and on the direction of motion then. The importance of the simple harmonic oscillator in both classical and modern physics lies not in the strict adherence of actual restoring forces to Hooke's law, which is seldom true, but in the fact that these restoring forces reduce to Hooke's law for small displacements $x$. As a result, any system in which something executes small vibrations about an equilibrium position behaves very much like a simple harmonic oscillator.\n\\subsubsection{Total energy of the system}\n\\begin{align}\n\\intertext{The kinetic energy of the system can be written as,}T&=\\frac{1}{2} m\\left(\\frac{d x}{d t}\\right)^{2}\\\\&=\\frac{1}{2} m a^{2} \\omega^{2} \\cos ^{2}(\\omega t+\\phi)\\\\&=\\frac{1}{2} m \\omega^{2} a^{2}\\left[1-\\sin ^{2}(\\omega t+\\phi)\\right]\\\\&=\\frac{1}{2} m \\omega^{2}\\left(a^{2}-x^{2}\\right)\n\\intertext{Therefore, the total energy of the particle at $x$ is,}\nE&=K.E+P.E\\\\\n&=\\frac{1}{2} m \\omega^{2}\\left(a^{2}-x^{2}\\right)+\\frac{1}{2} m \\omega^{2} x^{2}\\\\ E&=\\frac{1}{2} m \\omega^{2} a^{2} \\quad \\text{Which is a constant.}\n\\intertext{The total energy $E$ is proportional to $a^{2} .$ Classically, the particle can oscillate with any amplitude $a$ and as such the total energy increases with the increase of $a$.The potential energy, $V=\\frac{1}{2} k x^{2}$ has a parabolic form figure signifying that the particle executes motion in a potential well of parabolic form.}\\notag\n\\end{align}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=5cm]{SHMclassical}\n\t\\caption{The potential energy curve of Simple harmonic oscillator}\n\t\\label{}\n\\end{figure}\n\n\\section{Harmonic oscillator-Quantum mechanical treatment}\nThere are only a very few potentials for which the Schrodinger equation can be solved analytically. The most important of these is the potential of the harmonic oscillator.\\\\\nThe Hamiltonian of a particle of mass $m$ which oscillates with an angular frequency $\\omega$ under the influence of a one-dimensional harmonic potential is\\\\\n$$\\hat{H}=\\frac{\\hat{P}^{2}}{2 m}+\\frac{1}{2} m \\omega^{2} \\hat{X}^{2} $$\nThe problem is how to find the energy eigenvalues and eigenstates of this Hamiltonian. This problem can be studied by means of two separate methods. The first method, called the analytic method, consists in solving the time-independent Schrödinger equation (TISE) for the Hamiltonian. The second method, called the ladder or algebraic method, does not deal with solving the Schrödinger equation, but deals instead with operator algebra involving operators known as the creation and annihilation or ladder operators; this method is in essence a matrix formulation, because it expresses the various quantities in terms of matrices.\n\\subsection{Analytical method}\n\\begin{align}\n\\intertext{The Schrodinger equation is given  by,}\n\\frac{d^{2} \\psi}{d x^{2}}+\\frac{2 m}{\\hbar^{2}}\\left(E-U\\right) \\psi&=0\n\\intertext{In the case of Harmonic oscillator, the potential energy, $U=\\frac{1}{2}m\\omega^{2}x^{2}$,}\n\\intertext{Then the Schrodinger equation becomes,}\n\\frac{-\\hbar^{2}}{2 m}\\frac{d^{2} \\psi}{d x^{2}}+\\frac{1}{2}m\\omega^{2}x^{2} \\psi&=E\\psi\n\\intertext{The above differential equation is complex in form and thus need to be solved by Frobenious method. Then the general wavefunction of Harmonic oscillator can be found as,}\n\\psi_{n}(x)&=\\left(\\frac{\\alpha}{2^{n}n!\\sqrt{\\pi}  }\\right)^{1 / 2} e^{-\\frac{1}{2}\\alpha x^{2} } H_{n}({\\alpha} x)\n\\intertext{Where $ H_{n}(\\sqrt{\\alpha} x)$\\ is the Hermite polynomial.}\n\\text{For $n=0$}\\quad \\psi_{0}(x)&=\\left(\\frac{\\alpha}{\\pi}\\right)^{1 / 4} e^{-\\alpha x^{2} / 2}\\\\\n\\text{For $n=1$}\\quad \\psi_{1}(x)&=\\left(\\frac{\\alpha}{2\\sqrt{\\pi}}\\right)^{1 / 2} e^{-\\alpha x^{2} / 2}(4(\\alpha x)^{2}-2)\\\\\n\\end{align}\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][1cm]{8cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\n\t\t\t$\\psi_{n}(x)=\\left(\\frac{\\alpha}{2^{n}n!\\sqrt{\\pi}  }\\right)^{1 / 2} e^{-\\frac{1}{2}\\alpha x^{2} } H_{n}({\\alpha} x)$} }\n\\end{center}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=7cm,width=10cm]{SHM1}\n\t\\caption{Wavefunctions and Probability densities of Harmonic wavefunction}\n\t\\label{ Harmonic wavefunction}\n\\end{figure}\n\\begin{note}\n\t\\textbf{Hermite Polynomial values}\n\t\\begin{align*}\n\tH_{0}(x)&=1 \\\\\n\tH_{1}(x)&=2 x \\\\\n\tH_{2}(x)&=4 x^{2}-2 \\\\\n\tH_{3}(x)&=8 x^{3}-12 x \\\\\n\tH_{4}(x)&=16 x^{4}-48 x^{2}+12 \\\\\n\tH_{5}(x)&=32 x^{5}-160 x^{3}+120 x \\\\\n\t\\end{align*}\n\\end{note}\n\n\\subsubsection{Energy levels of Harmonic oscillator}\nThe energy eigen values of the Harmonic oscillator is given by,\n\\begin{align*}\nE_{n}&=(n+\\frac{1}{2})\\hbar \\omega\n\\intertext{The energy eigen values at different states,}\n\\text{At \\ $n=0$\\ } \\quad ; \\quad & E_{0}=\\frac{1}{2}\\hbar \\omega \\quad (\\text{i.e., The energy eigen value at ground state is not equal to zero.})\\\\\n\\text{At \\ $n=1$\\ } \\quad ; \\quad & E_{1}=\\frac{3}{2}\\hbar \\omega\\\\\n\\text{At \\ $n=2$\\ } \\quad ; \\quad & E_{2}=\\frac{5}{2}\\hbar \\omega\\\\\n\\text{At \\ $n=3$\\ } \\quad ; \\quad & E_{3}=\\frac{7}{2}\\hbar \\omega\\\\\n\\end{align*}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=8cm,width=9cm]{shm energy level}\n\t\\caption{Energy levels of Harmonic Oscillator}\n\t\\label{Energy levels of Harmonic Oscillator}\n\\end{figure}\n\\subsection{Algebraic method(ladder method)}\n   Let us now show how to solve the harmonic oscillator eigen value problem using the algebraic method.For this we need to rewrite the hamiltonian interms of two hermitian dimensionless operators $\\hat{p}=\\hat{P}/\\sqrt{m\\hbar \\omega}$ and $\\hat{q}=\\hat{X}\\sqrt{m\\omega/\\hbar}$\\\\\n   $$\\hat{H}=\\frac{\\hbar \\omega}{2}\\left( \\hat{p}^2+\\hat{q}^2\\right) $$\n   And then introduce two non hermitian dimensioless operators:\n   $$\\hat{a=\\frac{1}{\\sqrt{2}}}(\\hat{q}+i\\hat{p}), \\quad \\quad \\hat{a}^{\\dagger}=\\frac{1}{\\sqrt{2}}(\\hat{q}-i\\hat{p})$$\n   Note that $\\hat{a}^{\\dagger}\\hat{a}=\\frac{1}{2}(\\hat{q}-i\\hat{p})(\\hat{q}+i\\hat{p})=\\frac{1}{2}\\left( \\hat{q}^2+\\hat{p}^2+i\\hat{q}\\hat{p}-i\\hat{p}\\hat{q}\\right) =\\frac{1}{2}(\\hat{q}^2+\\hat{p}^2)+\\frac{i}{2} \\left[ \\hat{q},\\hat{p}\\right] $\\\\\\\\\n   Where using $ \\left[ \\hat{X}, \\hat{P} \\right] =i\\hbar$, we can verify that the commuttator between $\\hat{q}$ and $\\hat{p}$ is \\\\\n   $$\\left[ \\hat{q}, \\hat{p}\\right] =\\left[ \\sqrt{\\frac{m\\omega}{\\hbar}}\\hat{X},\\frac{1}{\\sqrt{\\hbar m\\omega}}\\hat{P}\\right]=\\frac{1}{\\hbar}\\left[ \\hat{X},\\hat{P}\\right] =i$$\n   $$\\begin{aligned}\n   \t&\\hat{a}^{\\dagger} \\hat{a}=\\frac{1}{2}\\left(\\hat{q}^{2}+\\hat{p}^{2}\\right)-\\frac{1}{2} \\\\\n   \t&\\frac{1}{2}\\left(\\hat{q}^{2}+\\hat{p}^{2}\\right)=\\hat{a}^{\\dagger} \\hat{a}+\\frac{1}{2}\n   \\end{aligned}$$\n   Inserting this into Hamiltonian we will get \\\\\n   $$\\hat{H}=\\hbar \\omega\\left(\\hat{a}^{\\dagger} \\hat{a}+\\frac{1}{2}\\right)=\\hbar \\omega\\left(\\hat{N}+\\frac{1}{2}\\right) \\quad \\text { with } \\quad \\hat{N}=\\hat{a}^{\\dagger} \\hat{a}$$\n   where $\\hat{N}$ is known as the number operator or occupation number operator, which is clearly Hermitian.\\\\\n   Let us now derive the commutator $\\left[\\hat{a}, \\hat{a}^{\\dagger}\\right]$. Since $[\\hat{X}, \\hat{P}]=i \\hbar$ we have $[\\hat{q}, \\hat{p}]=\\frac{1}{\\hbar}[\\hat{X}, \\hat{P}]=$ $i$; hence\n   $$\n   \\left[\\hat{a}, \\hat{a}^{\\dagger}\\right]=\\frac{1}{2}[\\hat{q}+i \\hat{p}, \\hat{q}-i \\hat{p}]=-i[\\hat{q}, \\hat{p}]=1\n   $$\n   or $$ \\left[\\hat{a}, \\hat{a}^{\\dagger}\\right]=1$$\n   \\paragraph{Energy eigen values}\n   Note that $\\hat{H}$  commutes with $\\hat{N}$, since $\\hat{H}$ is linear in $\\hat{N}$. Thus, $\\hat{H}$ and $\\hat{N}$ can have a set of joint eigenstates, to be denoted by $|n\\rangle$ :\n   $$\n   \\hat{N}|n\\rangle=n|n\\rangle\n   $$\n   and\n   $$\n   \\hat{H}|n\\rangle=E_{n}|n\\rangle\n   $$\n   Now we need the following commutators\\\\\n$$[\\hat{a}, \\hat{H}]=\\hbar \\omega \\hat{a}, \\quad\\left[\\hat{a}^{\\dagger}, \\hat{H}\\right]=-\\hbar \\omega \\hat{a}^{\\dagger}$$\nThese commutation relation along with  $\\hat{H}|n\\rangle=E_{n}|n\\rangle$ lead to\n$$\\begin{aligned}\n\t\\hat{H}(\\hat{a}|n\\rangle) &=(\\hat{a} \\hat{H}-\\hbar \\omega \\hat{a})|n\\rangle=\\left(E_{n}-\\hbar \\omega\\right)(\\hat{a}|n\\rangle), \\\\\n\t\\hat{H}\\left(\\hat{a}^{\\dagger}|n\\rangle\\right) &=\\left(\\hat{a}^{\\dagger} \\hat{H}+\\hbar \\omega \\hat{a}^{\\dagger}\\right)|n\\rangle=\\left(E_{n}+\\hbar \\omega\\right)\\left(\\hat{a}^{\\dagger}|n\\rangle\\right) .\n\\end{aligned}$$\nThus, $\\hat{a}|n\\rangle$ and $\\hat{a}^{\\dagger}|n\\rangle$ are eigenstates of $\\hat{H}$ with eigenvalues $\\left(E_{n}-\\hbar \\omega\\right)$ and $\\left(E_{n}+\\hbar \\omega\\right)$, respectively. So the actions of $\\hat{a}$ and $\\hat{a}^{\\dagger}$ on $|n\\rangle$ generate new energy states that are lower and higher by one unit of $\\hbar \\omega$ respectively.As a result $\\hat{a}$ and $\\hat{a}^{\\dagger}$ are respectively known as the lowering and the raising opertors or the annilation and creation opetaors,They are also known as ladder operators.\\\\\nLet us now find out how the operators $\\hat{a}$ and $\\hat{a}^{\\dagger}$ act on the energy eigenstates $|n\\rangle$. Since $\\hat{a}$ and $\\hat{a}^{\\dagger}$ do not commute with $\\hat{N}$, the states $|n\\rangle$ are eigenstates neither to $\\hat{a}$ nor to $\\hat{a}^{\\dagger}$. Using $ \\left[\\hat{a}, \\hat{a}^{\\dagger}\\right]=1$ along with $[\\hat{A} \\hat{B}, \\hat{C}]=\\hat{A}[\\hat{B}, \\hat{C}]+[\\hat{A}, \\hat{C}] \\hat{B}$, we can show that\\\\\n$$[\\hat{N}, \\hat{a}]=-\\hat{a}, \\quad\\left[\\hat{N}, \\hat{a}^{\\dagger}\\right]=\\hat{a}^{\\dagger}$$\nhence $\\hat{N} \\hat{a}=\\hat{a}(\\hat{N}-1)$ and $\\hat{N} \\hat{a}^{\\dagger}=\\hat{a}^{\\dagger}(\\hat{N}+1) .$ Combining these relations with $\n\\hat{N}|n\\rangle=n|n\\rangle\n$, we obtain \\\\\n$$\\begin{aligned}\n\t\\hat{N}(\\hat{a}|n\\rangle) &=\\hat{a}(\\hat{N}-1)|n\\rangle=(n-1)(\\hat{a}|n\\rangle), \\\\\n\t\\hat{N}\\left(\\hat{a}^{\\dagger}|n\\rangle\\right) &=\\hat{a}^{\\dagger}(\\hat{N}+1)|n\\rangle=(n+1)\\left(\\hat{a}^{\\dagger}|n\\rangle\\right) .\n\\end{aligned}$$\nThese relations reveal that $\\hat{a}|n\\rangle$ and $\\hat{a}^{\\dagger}|n\\rangle$ are eigenstates of $\\hat{N}$ with eigenvalues $(n-1)$ and $(n+1)$, respectively. This implies that when $\\hat{a}$ and $\\hat{a}^{\\dagger}$ operate on $|n\\rangle$, respectively, they decrease and increase $n$ by one unit. That is, while the action of $\\hat{a}$ on $|n\\rangle$ generates a new state $|n-1\\rangle$ (i.e., $\\hat{a}|n\\rangle \\sim|n-1\\rangle$ ), the action of $\\hat{a}^{\\dagger}$ on $|n\\rangle$ generates $|n+1\\rangle$.\\\\\n Hence from $\\hat{N}(\\hat{a}|n\\rangle) =\\hat{a}(\\hat{N}-1)|n\\rangle=(n-1)(\\hat{a}|n\\rangle)$ we can write\n $$\\hat{a}|n\\rangle=c_{n}|n-1\\rangle$$\n where $c_{n}$ is a constant to be determined from the requirement that the states $|n\\rangle$ be normalized for all values of $n$. On the one hand, the above equation  yields\n $$\\left(\\langle n| \\hat{a}^{\\dagger}\\right) \\cdot(\\hat{a}|n\\rangle)=\\left\\langle n\\left|\\hat{a}^{\\dagger} \\hat{a}\\right| n\\right\\rangle=\\left|c_{n}\\right|^{2}\\langle n-1 \\mid n-1\\rangle=\\left|c_{n}\\right|^{2}$$\n On the other hand $\\hat{N}|n\\rangle=n|n\\rangle $ gives\n $$\\left(\\langle n| \\hat{a}^{\\dagger}\\right) \\cdot(\\hat{a}|n\\rangle)=\\left\\langle n\\left|\\hat{a}^{\\dagger} \\hat{a}\\right| n\\right\\rangle=n\\langle n \\mid n\\rangle=n $$\n When combined, the last two equations yield\n $$\n \\left|c_{n}\\right|^{2}=n .\n $$\n This implies that $n$, which is equal to the norm of $\\hat{a}|n\\rangle$, cannot he negative, $n \\geq 0$, since the norm is a positive quantity. Substituting the above result  into $\\hat{a}|n\\rangle=c_{n}|n-1\\rangle$  we end up with\n $$\\hat{a}|n\\rangle=\\sqrt{n}|n-1\\rangle$$\n This equation shows that repeated applications of the operator $\\hat{a}$ on $|n\\rangle$ generate a sequence of eigenvectors $|n-1\\rangle,|n-2\\rangle,|n-3\\rangle, \\ldots$. Since $n \\geq 0$ and since $\\hat{a}|0\\rangle=0$, this sequence has to terminate at $n=0$; this is true if we start with an integer value of $n$. But if we start with a noninteger $n$, the sequence will not terminate; hence it leads to eigenvectors with negative values of $n$. But as shown above, since $n$ cannot be negative, we conclude that $n$ has to be a nonnegative integer.\\\\\n Similarly we can show that \\\\\n $$\\hat{a}^{\\dagger}|n\\rangle=\\sqrt{n+1}|n+1\\rangle$$\n This implies that repeated applications of $\\hat{a}^{\\dagger}$ on $|n\\rangle$ generate an infinite sequence of eigenvectors $|n+1\\rangle,|n+2\\rangle,|n+3\\rangle, \\ldots$ Since $n$ is a positive integer, the energy spectrum of a harmonic oscillator  is therefore discrete:\n$$ E_{n}=\\left(n+\\frac{1}{2}\\right) \\hbar \\omega \\quad(n=0,1,2,3, \\ldots)$$\n\\paragraph{Energy eigenstate}\nThe algebraic or operator method can also be used to determine the energy eigenvectors.  we see that the various eigenvectors can be written in terms of the ground state | 0) as follows:\\\\\n|1) $=\\hat{a}^{\\dagger}|0\\rangle$,\\\\\n$|2\\rangle=\\frac{1}{\\sqrt{2}} \\hat{a}^{\\dagger}|1\\rangle=\\frac{1}{\\sqrt{2 !}}\\left(\\hat{a}^{\\dagger}\\right)^{2}|0\\rangle$,\\\\\n$|3\\rangle=\\frac{1}{\\sqrt{3}} \\hat{a}^{\\dagger}|2\\rangle=\\frac{1}{\\sqrt{3 !}}\\left(\\hat{a}^{\\dagger}\\right)^{3}|0\\rangle$,\\\\\n$|n\\rangle=\\frac{1}{\\sqrt{n}} \\hat{a}^{\\dagger}|n-1\\rangle=\\frac{1}{\\sqrt{n !}}\\left(\\hat{a}^{\\dagger}\\right)^{n}|0\\rangle .$\\\\\n$\\text { So, to find any excited eigenstate }|n\\rangle, \\text { we need simply to operate } \\hat{a}^{\\dagger} \\text { on }|0\\rangle n \\text { successive times. }$\n \\paragraph{Energy eigen state in position space}\n $\\text { Iet us now determine the harmonic oscillator wave function in the position representation. }$ \\\\\n Starting with The operator $\\hat{p}$, defined by $\\hat{p}=\\hat{P} / \\sqrt{m \\hbar \\omega}$, is given in the position space by\n $$\n \\hat{p}=-\\frac{i \\hbar}{\\sqrt{m \\hbar \\omega}} \\frac{d}{d x}=-i x_{0} \\frac{d}{d x}\n $$\n where, as mentioned above, $x_{0}=\\sqrt{\\hbar /(m \\omega)}$ is a constant that has the dimensions of length; it sets the length scale of the oscillator. We can easily show that the annihilation and creation operators $\\hat{a}$ and $\\hat{a}^{\\dagger}$ can be written in the position representation as\n $$\\begin{gathered}\n \\hat{a}=\\frac{1}{\\sqrt{2}}\\left(\\frac{\\hat{X}}{x_{0}}+x_{0} \\frac{d}{d x}\\right)=\\frac{1}{\\sqrt{2} x_{0}}\\left(\\hat{X}+x_{0}^{2} \\frac{d}{d x}\\right), \\\\\n \\hat{a}^{\\dagger}=\\frac{1}{\\sqrt{2}}\\left(\\frac{\\hat{X}}{x_{0}}-x_{0} \\frac{d}{d x}\\right)=\\frac{1}{\\sqrt{2} x_{0}}\\left(\\hat{X}-x_{0}^{2} \\frac{d}{d x}\\right) .\n \\end{gathered}$$\n With these equations and after completing few more steps we will get energy eigen function as \\\\\n $$\\psi_{n}(x)=\\frac{1}{\\sqrt{\\sqrt{2}2^{n}n!x_{0}}}e^{-\\frac{x^2}{2x_0^2}}H_n\\left( \\frac{x}{x_0}\\right) $$\n This wavefunction is identical with the one obtained from the first method.\\\\\n \\paragraph{The matrix representation of various operators}\n \\begin{enumerate}\n \t\\item N $\\implies$\n \t\t$\\left\\langle n^{\\prime}|\\hat{N}| n\\right\\rangle=n \\delta_{n^{\\prime}, n}$ \\\\\n \t\t$\\hat{N}=\\left(\\begin{array}{cccc}\n \t\t\t0 & 0 & 0 & \\ldots \\\\\n \t\t\t0 & 1 & 0 & \\ldots \\\\\n \t\t\t0 & 0 & 2 & \\ldots \\\\\n \t\t\t\\vdots & \\vdots & \\vdots & \\ddots\n \t\t\\end{array}\\right)$\n \t\\item Hamiltonian(H) $\\implies$\n \t$\\left\\langle n^{\\prime}|\\hat{H}| n\\right\\rangle=\\hbar \\omega\\left(n+\\frac{1}{2}\\right) \\delta_{n^{\\prime}, n} ;$ \\\\\n \t$\\hat{H}=\\frac{\\hbar \\omega}{2}\\left(\\begin{array}{cccc}\n \t1 & 0 & 0 & \\ldots \\\\\n \t0 & 3 & 0 & \\ldots \\\\\n \t0 & 0 & 5 & \\ldots \\\\\n \t\\vdots & \\vdots & \\vdots & \\ddots\n \t\\end{array}\\right)$ .\n \n \t\\item  Lowering operator $\\implies$\n \t$\n \t\\left\\langle n^{\\prime}|\\hat{a}| n\\right\\rangle=\\sqrt{n} \\delta_{n^{\\prime}, n-1}\n \t$\\\\\n \t$\n \t\\hat{a}=\\left(\\begin{array}{ccccc}\n \t0 & \\sqrt{1} & 0 & 0 & \\cdots \\\\\n \t0 & 0 & \\sqrt{2} & 0 & \\cdots \\\\\n \t0 & 0 & 0 & \\sqrt{3} & \\cdots \\\\\n \t0 & 0 & 0 & 0 & \\cdots \\\\\n \t\\vdots & \\vdots & \\vdots & \\vdots & \\ddots\n \t\\end{array}\\right) \\text {, }\n \t$\n \t\\item Raising operator $\\implies$\n \t$\\left\\langle n^{\\prime}\\left|\\hat{a}^{\\dagger}\\right| n\\right\\rangle=\\sqrt{n+1} \\delta_{n^{\\prime}, n+1} ;$ \\\\\n \t$\\hat{a}^{\\dagger}=\\left(\\begin{array}{ccccc}\n \t0 & 0 & 0 & 0 & \\ldots \\\\\n \t\\sqrt{1} & 0 & 0 & 0 & \\ldots \\\\\n \t0 & \\sqrt{2} & 0 & 0 & \\ldots \\\\\n \t0 & 0 & \\sqrt{3} & 0 & \\ldots \\\\\n \t\\vdots & \\vdots & \\vdots & \\vdots & \\ddots\n \t\\end{array}\\right)$ .\n \t\\item Position operator($\\hat{X}$) $\\implies$\n \t$\\hat{X}=\\sqrt{\\frac{\\hbar}{2 m \\omega}}\\left(\\hat{a}+\\hat{a}^{\\dagger}\\right)$\\\\\n \t$\\left\\langle n^{\\prime}|\\hat{X}| n\\right\\rangle=\\sqrt{\\frac{\\hbar}{2 m \\omega}}\\left(\\sqrt{n} \\delta_{n^{\\prime}, n-1}+\\sqrt{n+1} \\delta_{n^{\\prime}, n+1}\\right)$\\\\\n \t$\\hat{X}=\\sqrt{\\frac{\\hbar}{2 m \\omega}}\\left(\\begin{array}{ccccc}\n \t\t0 & \\sqrt{1} & 0 & 0 & \\cdots \\\\\n \t\t\\sqrt{1} & 0 & \\sqrt{2} & 0 & \\cdots \\\\\n \t\t0 & \\sqrt{2} & 0 & \\sqrt{3} & \\cdots \\\\\n \t\t0 & 0 & \\sqrt{3} & 0 & \\cdots \\\\\n \t\t\\vdots & \\vdots & \\vdots & \\vdots & \\ddots\n \t\\end{array}\\right)$\n \t\\item Momentum operator($\\hat{P}$)$\\implies$\n \t$\\hat{P}=i \\sqrt{\\frac{m \\hbar \\omega}{2}}\\left(\\hat{a}^{\\dagger}-\\hat{a}\\right)$\\\\\n \t$\\left\\langle n^{\\prime}|\\hat{P}| n\\right\\rangle=i \\sqrt{\\frac{m \\hbar \\omega}{2}}\\left(-\\sqrt{n} \\delta_{n^{\\prime}, n-1}+\\sqrt{n+1} \\delta_{n^{\\prime}, n+1}\\right)$\\\\\n \t$\\hat{P}=i \\sqrt{\\frac{m \\hbar \\omega}{2}}\\left(\\begin{array}{ccccc}\n \t\t0 & -\\sqrt{1} & 0 & 0 & \\cdots \\\\\n \t\t\\sqrt{1} & 0 & -\\sqrt{2} & 0 & \\cdots \\\\\n \t\t0 & \\sqrt{2} & 0 & -\\sqrt{3} & \\cdots \\\\\n \t\t0 & 0 & \\sqrt{3} & 0 & \\cdots \\\\\n \t\t\\vdots & \\vdots & \\vdots & \\vdots & \\ddots\n \t\\end{array}\\right)$\\\\\n \tin particular\n \t$$\n \t\\langle n|\\hat{X}| n\\rangle=\\langle n|\\hat{P}| n\\rangle=0 .\n \t$$\n \\end{enumerate}\n\\paragraph{Expectation values of various operator}\nLet us evaluate the expectation values for $\\hat{X}^{2}$ and $\\hat{P}^{2}$ in the $N$-representation:\n$$\n\\begin{aligned}\n&\\hat{X}^{2}=\\frac{\\hbar}{2 m \\omega}\\left(\\hat{a}^{2}+\\hat{a}^{\\dagger 2}+\\hat{a} \\hat{a}^{\\dagger}+\\hat{a}^{\\dagger} \\hat{a}\\right)=\\frac{\\hbar}{2 m \\omega}\\left(\\hat{a}^{2}+\\hat{a}^{\\dagger 2}+2 \\hat{a}^{\\dagger} \\hat{a}+1\\right), \\\\\n&\\hat{P}^{2}=-\\frac{m \\hbar \\omega}{2}\\left(\\hat{a}^{2}+\\hat{a}^{\\dagger 2}-\\hat{a} \\hat{a}^{\\dagger}-\\hat{a}^{\\dagger} \\hat{a}\\right)=-\\frac{m \\hbar \\omega}{2}\\left(\\hat{a}^{2}+\\hat{a}^{\\dagger 2}-2 \\hat{a}^{\\dagger} \\hat{a}-1\\right)\n\\end{aligned}\n$$\nwhere we have used the fact that $\\hat{a} \\hat{a}^{\\dagger}+\\hat{a}^{\\dagger} \\hat{a}=2 \\hat{a}^{\\dagger} \\hat{a}+1 .$ Since the expectation values of $\\hat{a}^{2}$ and $\\hat{a}^{\\dagger 2}$ are zero, $\\left\\langle n\\left|\\hat{a}^{2}\\right| n\\right\\rangle=\\left\\langle n\\left|\\hat{a}^{\\dagger 2}\\right| n\\right\\rangle=0$, and $\\left\\langle n\\left|\\hat{a}^{\\dagger} \\hat{a}\\right| n\\right\\rangle=n$, we have\\\\\n$$\\left\\langle n\\left|\\hat{a} \\hat{a}^{\\dagger}+\\hat{a}^{\\dagger} \\hat{a}\\right| n\\right\\rangle=\\left\\langle n\\left|2 \\hat{a}^{\\dagger} \\hat{a}+1\\right| n\\right\\rangle=2 n+1$$\nhence\n$$\\begin{aligned}\n\t&\\left\\langle n\\left|\\hat{X}^{2}\\right| n\\right\\rangle=\\frac{\\hbar}{2 m \\omega}\\left\\langle n\\left|\\hat{a} \\hat{a}^{\\dagger}+\\hat{a}^{\\dagger} \\hat{a}\\right| n\\right\\rangle=\\frac{\\hbar}{2 m \\omega}(2 n+1), \\\\\n\t&\\left\\langle n\\left|\\hat{P}^{2}\\right| n\\right\\rangle=\\frac{m \\hbar \\omega}{2}\\left\\langle n\\left|\\hat{a} \\hat{a}^{\\dagger}+\\hat{a}^{\\dagger} \\hat{a}\\right| n\\right\\rangle=\\frac{m \\hbar \\omega}{2}(2 n+1) .\n\\end{aligned}$$\n\\begin{exercise}\n\t(a)Calculate the expectation value of the operator $\\hat{X}^4$ in the N-represesntation with respect to the state $|n\\rangle$(ie $\\langle n|\\hat{X}^4 |n\\rangle$)\\\\\n\t(b)Use the result of (a) to calculate the energy $E_n$ for a particle whose Hamiltonian is $\\hat{H}=\\hat{P}^2/2m+\\frac{1}{2}m\\omega^2\\hat{X}^2-\\lambda\\hat{X}^4$\n\\end{exercise}\n\\begin{answer}\n\t(a) Since $\\sum_{m=0}^{\\infty}|m\\rangle\\langle m|=1$ we can write the expectation value of $\\hat{X}^{4}$ as\n\t$$\n\t\\left\\langle n\\left|\\hat{X}^{4}\\right| n\\right\\rangle=\\sum_{m=0}^{\\infty}\\left\\langle n\\left|\\hat{X}^{2}\\right| m\\right\\rangle\\left\\langle m\\left|\\hat{X}^{2}\\right| n\\right\\rangle=\\sum_{m=0}^{\\infty}\\left|\\left\\langle m\\left|\\hat{X}^{2}\\right| n\\right\\rangle\\right|^{2} .\n\t$$\n\tNow since\n\t$$\n\t\\hat{X}^{2}=\\frac{\\hbar}{2 m \\omega}\\left(\\hat{a}^{2}+\\hat{a}^{\\dagger 2}+\\hat{a} \\hat{a}^{\\dagger}+\\hat{a}^{\\dagger} \\hat{a}\\right)=\\frac{\\hbar}{2 m \\omega}\\left(\\hat{a}^{2}+\\hat{a}^{\\dagger 2}+2 \\hat{a}^{\\dagger} \\hat{a}+1\\right) .\n\t$$\n\tthe only terms $\\left\\langle m\\left|\\hat{X}^{2}\\right| n\\right\\rangle$ that survive are\n\t$$\n\t\\begin{aligned}\n\t\\left\\langle n\\left|\\hat{X}^{2}\\right| n\\right\\rangle &=\\frac{\\hbar}{2 m \\omega}\\left\\langle n\\left|2 \\hat{a}^{\\dagger} \\hat{a}+1\\right| n\\right\\rangle=\\frac{\\hbar}{2 m \\omega}(2 n+1), \\\\\n\t\\left\\langle n-2\\left|\\hat{X}^{2}\\right| n\\right\\rangle &=\\frac{\\hbar}{2 m \\omega}\\left\\langle n-2\\left|\\hat{a}^{2}\\right| n\\right\\rangle=\\frac{\\hbar}{2 m \\omega} \\sqrt{n(n-1)}, \\\\\n\t\\left\\langle n+2\\left|\\hat{X}^{2}\\right| n\\right\\rangle &=\\frac{\\hbar}{2 m \\omega}\\left\\langle n+2\\left|\\hat{a}^{\\dagger 2}\\right| n\\right\\rangle=\\frac{\\hbar}{2 m \\omega} \\sqrt{(n+1)(n+2)} .\n\t\\end{aligned}\n\t$$\n\tThus\n\t$$\n\t\\begin{aligned}\n\t\\left\\langle n\\left|\\hat{X}^{4}\\right| n\\right\\rangle &=\\left|\\left\\langle n\\left|\\hat{X}^{2}\\right| n\\right\\rangle\\right|^{2}+\\left|\\left\\langle n-2\\left|\\hat{X}^{2}\\right| n\\right\\rangle\\right|^{2}+\\left|\\left\\langle n+2\\left|\\hat{X}^{2}\\right| n\\right\\rangle\\right|^{2} \\\\\n\t&=\\frac{\\hbar^{2}}{4 m^{2} \\omega^{2}}\\left[(2 n+1)^{2}+n(n-1)+(n+1)(n+2)\\right] \\\\\n\t&=\\frac{\\hbar^{2}}{4 m^{2} \\omega^{2}}\\left(6 n^{2}+6 n+3\\right) .\n\t\\end{aligned}\n\t$$\n\t(b) Using the above equation and since the Hamiltonian can be expressed in terms of the harmonic oscillator, $\\hat{H}=\\hat{H}_{H O}-\\lambda \\hat{X}^{4}$, we immediately obtain the particle energy:\n\t$$\n\tE_{n}=\\left\\langle n\\left|\\hat{H}_{H O}\\right| n\\right\\rangle-\\lambda\\left\\langle n\\left|\\hat{X}^{4}\\right| n\\right\\rangle=\\hbar \\omega\\left(n+\\frac{1}{2}\\right)-\\frac{\\lambda \\hbar^{2}}{4 m^{2} \\omega^{2}}\\left(6 n^{2}+6 n+3\\right) .\n\t$$\n\\end{answer}\n\\subsection{3-D Harmonic oscillator}\nWe are going to begin with the anisotropic oscillator, which displays no symmetry, and then consider the isotropic oscillator where the $x y z$ axes are all equivalent.\\\\\n\\textbf{ The Anisotropic Oscillator}\\\\\nConsider a particle of mass $m$ moving in a three-dimensional anisotropic oscillator potential\n$$\n\\hat{V}(\\hat{x}, \\hat{y}, \\hat{z})=\\frac{1}{2} m \\omega_{x}^{2} \\hat{Y}^{2}+\\frac{1}{2} m \\omega_{y}^{2} \\hat{Y}^{2}+\\frac{1}{2} m \\omega_{z}^{2} \\hat{Z}^{2}\n$$\nIts Schrödinger equation separates into three equations\n$$\n-\\frac{\\hbar^{2}}{2 m} \\frac{d^{2} X(x)}{d x^{2}}+\\frac{1}{2} m \\omega_{x} x^{2} X(x)=E_{x} X(x)\n$$\nwith similar equations for $Y(y)$ and $Z(z)$. The eigenenergies corresponding to the potential can be expressed as\n$$\nE_{n_{x} n_{y} n_{z}}=E_{n_{x}}+E_{n_{y}}+E_{n_{z}}=\\left(n_{x}+\\frac{1}{2}\\right) \\hbar \\omega_{x}+\\left(n_{y}+\\frac{1}{2}\\right) \\hbar \\omega_{y}+\\left(n_{z}+\\frac{1}{2}\\right) \\hbar \\omega_{z},\n$$\nwith $n_{x}, n_{y}, n_{z}=0,1,2,3, \\ldots$. The corresponding stationary states are\n$$\n\\psi_{n_{x} n_{y} n_{z}}(x, y, z)=X_{n_{x}}(x) Y_{n_{y}}(y) Z_{n_{z}}(z),\n$$\nwhere $X_{n_{x}}(x), Y_{n_{y}}(y)$, and $Z_{n_{z}}(z)$ are one-dimensional harmonic oscillator wave functions. These states are not degenerate, because the potential  has no symmetry (it is anisotropic).\\\\\n\\textbf{ The Isotropic Harmonic Oscillator}\\\\\nConsider now an isotropic harmonic oscillator potential. Its energy eigenvalues can be obtained  by substituting $\\omega_{x}=\\omega_{y}=\\omega_{z}=\\omega$, in anisotropic energy equation.\n$$\nE_{n_{x} n_{y} n_{z}}=\\left(n_{x}+n_{y}+n_{z}+\\frac{3}{2}\\right) \\hbar \\omega\n$$\nSince the energy depends on the sum of $n_{x}, n_{y}, n_{z}$, any set of quantum numbers having the same sum will represent states of equal energy.\n\nThe ground state, whose energy is $E_{000}=3 \\hbar \\omega / 2$, is not degenerate. The first excited state is threefold degenerate, since there are three different states, $\\psi_{100,} \\psi_{010} , \\psi_{001}$, that correspond to the same energy $5 \\hbar(1) / 2$. The second excited state is sixfold degenerate; its energy is $7 \\hbar \\omega / 2$.\nIn general, we can show that the degeneracy $g_{n}$ of the $n$th excited state, which is equal to the number of ways the nonnegative integers $n_{x}, n_{y}, n_{z}$ may be chosen to total to $n$, is given by\n$$\ng_{n}=\\frac{1}{2}(n+1)(n+2),\n$$\nwhere $n=n_{x}+n_{y}+n_{z}$. Table displays the first few energy levels along with their degeneracies.\\\\\\\\\n\\renewcommand*{\\arraystretch}{1.7}\n$$\\begin{tabular}{|c|c|c|c|}\n\\hline $n$ & $2 E_{n} /(\\hbar \\omega)$ & $\\left(n_{x} n_{y} n_{z}\\right)$ & $g_{n}$ \\\\\n\\hline 0 & 3 & (000) & 1 \\\\\\hline\n1 & 5 & (100),(010),(001) & 3 \\\\\n\\hline\n2 & 7 & (200),(020),(002) & 6 \\\\\n&   & (110),(101),(011) &   \\\\\n\\hline\n3& 9& (300),(030),(003) & 10\\\\\n& \t& (210),(201),(021) & \\\\\n& \t& (120),(102),(012) & \\\\\n& \t& (111) & \\\\\n\\hline\n\\end{tabular}$$\\\\\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 1\n\t\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item The energy of the first excited quantum state of a particle in the two-dimensional potential $V(x, y)=\\frac{1}{2} m \\omega^{2}\\left(x^{2}+4 y^{2}\\right)$ is\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 \\hbar \\omega$\n\t\\task[\\textbf{B.}]$3 \\hbar \\omega$\n\t\\task[\\textbf{C.}]$\\frac{3}{2} \\hbar \\omega$\n\t\\task[\\textbf{D.}] $\\frac{5}{2} \\hbar \\omega$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $|0\\rangle$ and $|1\\rangle$ denote the normalized eigenstates corresponding to the ground and first excited states of a one dimensional harmonic oscillator. The uncertainty $\\Delta p$ in the state $\\frac{1}{\\sqrt{2}}(|0\\rangle+|1\\rangle)$, is\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\Delta p=\\sqrt{\\hbar m \\omega} / 2$\n\t\\task[\\textbf{B.}]$\\Delta p=\\sqrt{\\hbar m \\omega / 2}$\n\t\\task[\\textbf{C.}]$\\Delta p=\\sqrt{\\hbar m \\omega}$\n\t\\task[\\textbf{D.}]$\\Delta p=\\sqrt{2 \\hbar m \\omega}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ is in a cubic box of size $a$. The potential inside the box $(0 \\leq x<a, 0 \\leq y<a, 0 \\leq z<a)$ is zero and infinite outside. If the particle is in an eigenstate of energy $E=\\frac{14 \\pi^{2} \\hbar^{2}}{2 m a^{2}}$, its wavefunction is\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\psi=\\left(\\frac{2}{a}\\right)^{3 / 2} \\sin \\frac{3 \\pi x}{a} \\sin \\frac{5 \\pi y}{a} \\sin \\frac{6 \\pi z}{a}$\n\t\\task[\\textbf{B.}] $\\psi=\\left(\\frac{2}{a}\\right)^{3 / 2} \\sin \\frac{7 \\pi x}{a} \\sin \\frac{4 \\pi y}{a} \\sin \\frac{3 \\pi z}{a}$\n\t\\task[\\textbf{C.}]$\\psi=\\left(\\frac{2}{a}\\right)^{3 / 2} \\sin \\frac{4 \\pi x}{a} \\sin \\frac{8 \\pi y}{a} \\sin \\frac{2 \\pi z}{a}$\n\t\\task[\\textbf{D.}]$\\psi=\\left(\\frac{2}{a}\\right)^{3 / 2} \\sin \\frac{\\pi x}{a} \\sin \\frac{2 \\pi y}{a} \\sin \\frac{3 \\pi z}{a}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { A particle in one-dimension is in the potential }$\n\t$V(x)=\\left\\{\\begin{array}{llll}\n\t\\infty & , & \\text { if } & x<0 \\\\\n\t-V_{0} & , & \\text { if } & 0 \\leq x \\leq l \\\\\n\t0 & & \\text { if } & x>l\n\t\\end{array}\\right.$\n\t$\\text { If there is at least one bound state, the minimum depth of potential is }$\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\hbar^{2} \\pi^{2}}{8 m l^{2}}$\n\t\\task[\\textbf{B.}]$\\frac{\\hbar^{2} \\pi^{2}}{2 m l^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{2 \\hbar^{2} \\pi^{2}}{m l^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{\\hbar^{2} \\pi^{2}}{m l^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The energy eigenvalues of a particle in the potential } V(x)=\\frac{1}{2} m \\omega^{2} x^{2}-a x \\text { are }$\n\t\\exyear{NET DEC 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $E n=\\left(n+\\frac{1}{2}\\right) \\hbar \\omega-\\frac{a^{2}}{2 m \\omega^{2}}$\n\t\\task[\\textbf{B.}]$E n=\\left(n+\\frac{1}{2}\\right) \\hbar \\omega+\\frac{a^{2}}{2 m \\omega^{2}}$\n\t\\task[\\textbf{C.}]$E n=\\left(n+\\frac{1}{2}\\right) \\hbar \\omega-\\frac{a^{2}}{m \\omega^{2}}$\n\t\\task[\\textbf{D.}]$E n=\\left(n+\\frac{1}{2}\\right) \\hbar \\omega$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle is in the ground state of an infinite square well potential is given by,\n\t$$\n\tV(x)= \\begin{cases}0 & \\text { for }-a \\leq x \\leq a \\\\ \\infty & \\text { otherwise }\\end{cases}\n\t$$\n\tThe probability to find the particle in the interval between $-\\frac{a}{2}$ and $\\frac{a}{2}$ is\n\t\\exyear{NET DEC 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{2}$ \n\t\\task[\\textbf{B.}]$\\frac{1}{2}+\\frac{1}{\\pi}$\n\t\\task[\\textbf{C.}]$\\frac{1}{2}-\\frac{1}{\\pi}$\n\t\\task[\\textbf{D.}]$\\frac{1}{\\pi}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ in the potential $V(x, y)=\\frac{1}{2} m \\omega^{2}\\left(4 x^{2}+y^{2}\\right)$, is in an eigenstate of energy $E=\\frac{5}{2} \\hbar \\omega$. The corresponding un-normalized eigen function is\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $y \\exp \\left[-\\frac{m \\omega}{2 \\hbar}\\left(2 x^{2}+y^{2}\\right)\\right]$\n\t\\task[\\textbf{B.}]$x \\exp \\left[-\\frac{m \\omega}{2 \\hbar}\\left(2 x^{2}+y^{2}\\right)\\right]$\n\t\\task[\\textbf{C.}]$y \\exp \\left[-\\frac{m \\omega}{2 \\hbar}\\left(x^{2}+y^{2}\\right)\\right]$\n\t\\task[\\textbf{D.}]$x y \\exp \\left[-\\frac{m \\omega}{2 \\hbar}\\left(x^{2}+y^{2}\\right)\\right]$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ in three dimensions is in the potential\n\t$$\n\tV(r)= \\begin{cases}0, & r<a \\\\ \\infty, & r>a\\end{cases}\n\t$$\n\tIts ground state energy is\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}$\n\t\\task[\\textbf{B.}]$\\frac{\\pi^{2} \\hbar^{2}}{m a^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{3 \\pi^{2} \\hbar^{2}}{2 m a^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{9 \\pi^{2} \\hbar^{2}}{2 m a^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle in the infinite square well potential\n\t$$\n\tV(x)= \\begin{cases}0 & , 0<x<a \\\\ \\infty & \\text { otherwise }\\end{cases}\n\t$$\n\tis prepared in a state with the wavefunction\n\t$$\n\t\\psi(x)= \\begin{cases}A \\sin ^{3}\\left(\\frac{\\pi x}{a}\\right), & 0<x<a \\\\ 0 & \\text { otherwise }\\end{cases}\n\t$$\n\tThe expectation value of the energy of the particle is\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{5 \\hbar^{2} \\pi^{2}}{2 m a^{2}}$\n\t\\task[\\textbf{B.}]$\\frac{9 \\hbar^{2} \\pi^{2}}{2 m a^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{9 \\hbar^{2} \\pi^{2}}{10 m a^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{\\hbar^{2} \\pi^{2}}{2 m a^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state energy of the attractive delta function potential\n\t$$\n\tV(x)=-b \\delta(x),\n\t$$\n\twhere $b>0$, is calculated with the variational trial function\n\t$$\n\t\\psi(x)=\\left\\{\\begin{array}{ccc}\n\tA \\cos \\frac{\\pi x}{2 a}, & \\text { for } & -a<x<a, \\\\\n\t0, & & \\text { otherwise, }\n\t\\end{array}\\right\\} \\text { is }\n\t$$\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{m b^{2}}{\\pi^{2} \\hbar^{2}}$\n\t\\task[\\textbf{B.}]$-\\frac{2 m b^{2}}{\\pi^{2} \\hbar^{2}}$\n\t\\task[\\textbf{C.}]$-\\frac{m b^{2}}{2 \\pi^{2} \\hbar^{2}}$\n\t\\task[\\textbf{D.}]$-\\frac{m b^{2}}{4 \\pi^{2} \\hbar^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $|\\psi\\rangle=c_{0}|0\\rangle+c_{1}|1\\rangle$ (where $c_{0}$ and $c_{1}$ are constants with $c_{0}^{2}+c_{1}^{2}=1$ ) be a linear combination of the wavefunctions of the ground and first excited states of the onedimensional harmonic oscillator. For what value of $c_{0}$ is the expectation value $\\langle x\\rangle$ a maximum?\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\langle x\\rangle=\\sqrt{\\frac{\\hbar}{m \\omega}}, \\quad c_{0}=\\frac{1}{\\sqrt{2}}$\n\t\\task[\\textbf{B.}]$\\langle x\\rangle=\\sqrt{\\frac{\\hbar}{2 m \\omega}}, \\quad c_{0}=\\frac{1}{2}$\n\t\\task[\\textbf{C.}]$\\langle x\\rangle=\\sqrt{\\frac{\\hbar}{2 m \\omega}}, \\quad c_{0}=\\frac{1}{\\sqrt{2}}$\n\t\\task[\\textbf{D.}]$\\langle x\\rangle=\\sqrt{\\frac{\\hbar}{m \\omega}}, \\quad c_{0}=\\frac{1}{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ratio of the energy of the first excited state $E_{1}$, to that of the ground state $E_{0}$, to that of a particle in a three-dimensional rectangular box of side $L, L$ and $\\frac{L}{2}$, is\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $3: 2$\n\t\\task[\\textbf{B.}]$2: 1$\n\t\\task[\\textbf{C.}]$4: 1$\n\t\\task[\\textbf{D.}]$4: 3$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state energy of a particle in potential $V(x)=g|x|$, estimated using the trail wavefunction\\\\\n\t$\\psi(x)= \\begin{cases}\\sqrt{\\frac{c}{a^{5}}}\\left(a^{2}-x^{2}\\right), & x<|a| \\\\ 0, & x \\geq|a|\\end{cases}$\\\\\n\t$\\text { (where } g \\text { and } c \\text { are constants) is }$\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{15}{16}\\left(\\frac{\\hbar^{2} g^{2}}{m}\\right)^{1 / 3}$\n\t\\task[\\textbf{B.}]$\\frac{5}{6}\\left(\\frac{\\hbar^{2} g^{2}}{m}\\right)^{1 / 3}$\n\t\\task[\\textbf{C.}] $\\frac{3}{4}\\left(\\frac{\\hbar^{2} g^{2}}{m}\\right)^{1 / 3}$\n\t\\task[\\textbf{D.}] $\\frac{7}{8}\\left(\\frac{\\hbar^{2} g^{2}}{m}\\right)^{1 / 3}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The state of a particle of mass $m$ in a one dimensional rigid box in the interval 0 to $L$ is given by the normalized wavefunction $\\psi(x)=\\sqrt{\\frac{2}{L}}\\left(\\frac{3}{5} \\sin \\left(\\frac{2 \\pi x}{L}\\right)+\\frac{4}{5} \\sin \\left(\\frac{4 \\pi x}{L}\\right)\\right)$. If its energy is measured the possible outcomes and the average value of energy are, respectively\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{h^{2}}{2 m L^{2}}, \\frac{2 h^{2}}{m L^{2}}$ and $\\frac{73}{50} \\frac{h^{2}}{m L^{2}}$\n\t\\task[\\textbf{B.}] $\\frac{h^{2}}{8 m L^{2}}, \\frac{h^{2}}{2 m L^{2}}$ and $\\frac{19}{40} \\frac{h^{2}}{m L^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{h^{2}}{2 m L^{2}}, \\frac{2 h^{2}}{m L^{2}}$ and $\\frac{19}{10} \\frac{h^{2}}{m L^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{h^{2}}{8 m L^{2}}, \\frac{2 h^{2}}{m L^{2}}$ and $\\frac{73}{200} \\frac{h^{2}}{m L^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of charge $q$ in one dimension is in a simple harmonic potential with angular frequency $\\omega .$ It is subjected to a time- dependent electric field $E(t)=A e^{-\\left(\\frac{t}{\\tau}\\right)^{2}}$, where $A$ and $\\tau$ are positive constants and $\\omega \\tau \\gg 1$. If in the distant past $t \\rightarrow-\\infty$ the particle was in its ground state, the probability that it will be in the first excited state as $t \\rightarrow+\\infty$ is proportional to\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $e^{-\\frac{1}{2}(\\omega \\tau)^{2}}$ \n\t\\task[\\textbf{B.}] $e^{\\frac{1}{2}(\\omega \\tau)^{2}}$\n\t\\task[\\textbf{C.}] 0\n\t\\task[\\textbf{D.}]$\\frac{1}{(\\omega \\tau)^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a potential barrier $A$ of height $V_{0}$ and width $b$, and another potential barrier $B$ of height $2 V_{0}$ and the same width $b$. The ratio $T_{A} / T_{B}$ of tunnelling probabilities $T_{A}$ and $T_{B}$, through barriers $A$ and $B$ respectively, for a particle of energy $V_{0} / 100$ is best approximated by\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}](a) $\\exp \\left[(\\sqrt{1.99}-\\sqrt{0.99}) \\sqrt{8 m V_{0} b^{2} / \\hbar^{2}}\\right]$\n\t\\task[\\textbf{B.}]$\\exp \\left[(\\sqrt{1.98}-\\sqrt{0.98}) \\sqrt{8 m V_{0} b^{2} / \\hbar^{2}}\\right]$\n\t\\task[\\textbf{C.}] $\\exp \\left[(\\sqrt{2.99}-\\sqrt{0.99}) \\sqrt{8 m V_{0} b^{2} / \\hbar^{2}}\\right]$\n\t\\task[\\textbf{D.}]$\\exp \\left[(\\sqrt{2.98}-\\sqrt{0.98}) \\sqrt{8 m V_{0} b^{2} / \\hbar^{2}}\\right]$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item  Using the trial function\n\t$\\psi(x)=\\left\\{\\begin{array}{cc}\n\tA\\left(a^{2}-x^{2}\\right), & -a<x<a \\\\\n\t0 & \\text { otherwise }\n\t\\end{array}\\right.$\\\\\n\tthe ground state energy of a one-dimensional harmonic oscillator is \n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\hbar \\omega$\n\t\\task[\\textbf{B.}] $\\sqrt{\\frac{5}{14}} \\hbar \\omega$\n\t\\task[\\textbf{C.}]$\\frac{1}{2} \\hbar \\omega$\n\t\\task[\\textbf{D.}] $\\sqrt{\\frac{5}{7}} \\hbar \\omega$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ is confined in a three-dimensional box by the potential\n\t$$\n\tV(x, y, z)=\\left\\{\\begin{array}{lc}\n\t0, & 0 \\leq x, y, z \\leq a \\\\\n\t\\infty & \\text { otherwise }\n\t\\end{array}\\right.\n\t$$\n\tThe number of eigenstates of Hamiltonian with energy $\\frac{9 \\hbar^{2} \\pi^{2}}{2 m a^{2}}$ is\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]1\n\t\\task[\\textbf{B.}]6\n\t\\task[\\textbf{C.}]3\n\t\\task[\\textbf{D.}]4\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item At $t=0$, the wavefunction of an otherwise free particle confined between two infinite walls at $x=0$ and $x=L$ is $\\psi(x, t=0)=\\sqrt{\\frac{2}{L}}\\left(\\sin \\frac{\\pi x}{L}-\\sin \\frac{3 \\pi x}{L}\\right)$. Its wave function at a later time $t=\\frac{m L^{2}}{4 \\pi h}$ is\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sqrt{\\frac{2}{L}}\\left(\\sin \\frac{\\pi x}{L}-\\sin \\frac{3 \\pi x}{L}\\right) e^{i \\pi / 6}$\n\t\\task[\\textbf{B.}]$\\sqrt{\\frac{2}{L}}\\left(\\sin \\frac{\\pi x}{L}+\\sin \\frac{3 \\pi x}{L}\\right) e^{-i \\pi / 6}$\n\t\\task[\\textbf{C.}]$\\sqrt{\\frac{2}{L}}\\left(\\sin \\frac{\\pi x}{L}-\\sin \\frac{3 \\pi x}{L}\\right) e^{-i \\pi / 8}$\n\t\\task[\\textbf{D.}]$\\sqrt{\\frac{2}{L}}\\left(\\sin \\frac{\\pi x}{L}+\\sin \\frac{3 \\pi x}{L}\\right) e^{-i \\pi / 6}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state energy of an anisotropic harmonic oscillator described by the potential $V(x, y, z)=\\frac{1}{2} m \\omega^{2} x^{2}+2 m \\omega^{2} y^{2}+8 m \\omega^{2} z^{2}$ (in units of $\\hbar \\omega$ ) is\n\t\\exyear{NET DEC 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{5}{2}$\n\t\\task[\\textbf{B.}]$\\frac{7}{2}$\n\t\\task[\\textbf{C.}]$\\frac{3}{2}$\n\t\\task[\\textbf{D.}]$\\frac{1}{2}$\n\\end{tasks}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{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{a}&8&\\textbf{a}\\\\\\hline\n\t\t9&\\textbf{c}&10&\\textbf{b}\\\\\\hline\n\t\t11&\\textbf{c}&12&\\textbf{a}\\\\\\hline\n\t\t13&\\textbf{a}&14&\\textbf{a}\\\\\\hline\n\t\t15&\\textbf{a}&16&\\textbf{a}\\\\\\hline\n\t\t17&\\textbf{b}&18&\\textbf{c}\\\\\\hline\n\t\t19&\\textbf{d}&20&\\textbf{b}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 2\n\t\\end{abox}\n\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item Which of the following is an allowed wavefunction for a particle in a bound state? $N$ is a constant and $\\alpha, \\beta>0$.\n\t\t\\exyear{GATE 2010}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\psi=N \\frac{e^{-\\alpha r}}{r^{3}}$ \n\t\t\\task[\\textbf{B.}]$\\psi=N\\left(1-e^{-\\alpha r}\\right)$\n\t\t\\task[\\textbf{C.}]$\\psi=N e^{-\\alpha x} e^{-\\beta\\left(x^{2}+y^{2}+z^{2}\\right)}$\n\t\t\\task[\\textbf{D.}]$\\psi= \\begin{cases}\\text { non - zero constant } & \\text { if } r<R \\\\ 0 & \\text { if } r>R\\end{cases}$\n\t\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ is confined in an infinite potential well:\n\t$$\n\tV(x)= \\begin{cases}0, & \\text { if } 0<x<L, \\\\ \\infty, & \\text { otherwise. }\\end{cases}\n\t$$\n\tIt is subjected to a perturbing potential $V_{p}(x)=V_{o} \\sin \\left(\\frac{2 \\pi x}{L}\\right)$ within the well. Let $E^{(1)}$ and $E^{(2)}$ be corrections to the ground state energy in the first and second order in $V_{0}$, respectively. Which of the following are true?\n\t\\exyear{GATE 2010}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4cm]{diagram-20210824-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $E^{(1)}=0 ; E^{(2)}<0$\n\t\\task[\\textbf{B.}]$E^{(1)}>0 ; E^{(2)}=0$\n\t\\task[\\textbf{C.}]$E^{(1)}=0 ; E^{(2)}$ depends on the sign of $V_{0}$\n\t\\task[\\textbf{D.}]$E^{(1)}<0 ; E^{(2)}<0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electron with energy $E$ is incident from left on a potential barrier, given by\n\t$$\n\tV(x)= \\begin{cases}0, & \\text { for } x<0 \\\\ V_{0}, & \\text { for } x>0\\end{cases}\n\t$$\n\tas shown in the figure. For $E<V_{0}$, the space part of the wavefunction for $x>0$ is of the form\n\t\\exyear{GATE 2011}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210824(6)-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $e^{a x}$\n\t\\task[\\textbf{B.}] $e^{-a x}$\n\t\\task[\\textbf{C.}] $e^{i a x}$\n\t\\task[\\textbf{D.}]$e^{-i a x}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ is confined in a two dimensional square well potential of dimension $a$. This potential $V(x, y)$ is given by\n\t$$\n\t\\begin{aligned}\n\tV(x, y) &=0 \\text { for }-a<x<a \\text { and }-a<y<a \\\\\n\t&=\\infty \\text { elsewhere }\n\t\\end{aligned}\n\t$$\n\tThe energy of the first excited state for this particle is given by,\n\t\\exyear{GATE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\frac{\\pi^{2} \\hbar^{2}}{m a^{2}}$\n\t\\task[\\textbf{B.}] $\\frac{2 \\pi^{2} \\hbar^{2}}{m a^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{5 \\pi^{2} \\hbar^{2}}{8 m a^{2}}$\n\t\\task[\\textbf{D.}] $\\frac{4 \\pi^{2} \\hbar^{2}}{m a^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A proton is confined to a cubic box, whose sides have length $10^{-12} \\mathrm{~m}$. What is the minimum kinetic energy of the proton? The mass of proton is $1.67 \\times 10^{-27} \\mathrm{~kg}$ and Planck's constant is $6.63 \\times 10^{-34} J_{S}$.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $1.1 \\times 10^{-17} \\mathrm{~J}$\n\t\\task[\\textbf{B.}] $3.3 \\times 10^{-17} \\mathrm{~J}$\n\t\\task[\\textbf{C.}]$9.9 \\times 10^{-17} \\mathrm{~J}$\n\t\\task[\\textbf{D.}]$6.6 \\times 10^{-17} \\mathrm{~J}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a system of eight non-interacting, identical quantum particles of spin $-\\frac{3}{2}$ in a one dimensional box of length $L$. The minimum excitation energy of the system, in units of $\\frac{\\pi^{2} \\hbar^{2}}{2 m L^{2}}$ is\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item A two-dimensional square rigid box of side $L$ contains six non-interacting electrons at $T=0 K .$ The mass of the electron is $m .$ The ground state energy of the system of electrons, in units of $\\frac{\\pi^{2} \\hbar^{2}}{2 m L^{2}}$ is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ and energy $E$, moving in the positive $x$ direction, is incident on a step potential at $x=0$, as indicated in the figure. The height of the potential is $V_{0}$, where $V_{0}>E$. At $x=x_{0}$, where $x_{0}>0$, the probability of finding the electron is $\\frac{1}{e}$ times the probability of finding it at $x=0$. If $\\alpha=\\sqrt{\\frac{2 m\\left(V_{0}-E\\right)}{\\hbar^{2}}}$, the value of $x_{0}$ is\n\t\\exyear{GATE 2016}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{gate 5-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{2}{\\alpha}$\n\t\\task[\\textbf{B.}] $\\frac{1}{\\alpha}$\n\t\\task[\\textbf{C.}]$\\frac{1}{2 \\alpha}$\n\t\\task[\\textbf{D.}]$\\frac{1}{4 \\alpha}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A free electron of energy $1 \\mathrm{eV}$ is incident upon a one-dimensional finite potential step of height $0.75 \\mathrm{eV}$. The probability of its reflection from the barrier is........... (up to two decimal places).\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state energy of a particle of mass $m$ in an infinite potential well is $E_{0} .$ It changes to $E_{0}\\left(1+\\alpha \\times 10^{-3}\\right)$, when there is a small potential pump of height $V_{0}=\\frac{\\pi^{2} \\hbar^{2}}{50 m L^{2}}$ and width $a=L / 100$, as shown in the figure. The value of $\\alpha$ is (up to two decimal places).\n\t\\exyear{GATE 2018}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item $ \\text { Consider a potential barrier } V(x) \\text { of the form: }$\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210825(3)-crop}\n\t\\end{figure}\n\twhere $V_{0}$ is a constant. For particles of energy $E<V_{0}$ incident on this barrier from the left which of the following schematic diagrams best represents the probability density $|\\psi(x)|^{2}$ as a function of $x$ ?\n\t\\exyear{GATE 2019}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210825(4)-crop}\n\t\\end{figure}\n\t\\task[\\textbf{B.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210825(5)-crop}\n\t\\end{figure}\n\t\\task[\\textbf{C.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210825(6)-crop}\n\t\\end{figure}\n\t\\task[\\textbf{D.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210825(7)-crop}\n\t\\end{figure}\n\\end{tasks}\n\\end{enumerate}\n\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{c}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{b}&4&\\textbf{c}\\\\\\hline\n\t\t5&\\textbf{c}&6&\\textbf{5}\\\\\\hline\n\t\t7&\\textbf{24}&8&\\textbf{c}\\\\\\hline\n\t\t9&\\textbf{0.11}&10&\\textbf{0.81}\\\\\\hline\n\t\t11&\\textbf{a}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\newpage\n\\begin{abox}\n\tPractice set 3\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Consider a Hamiltonian $H=-\\frac{\\hbar^{2}}{2 m} \\frac{d^{2}}{d x^{2}}$ and corresponding Eigen state is\n\t$$\n\t\\phi_{n}(x)=\\left\\{\\begin{array}{cc}\n\t\\sqrt{\\frac{2}{a}} \\sin \\frac{n \\pi x}{a} & 0<x<a \\\\\n\t0 & \\text { otherwise }\n\t\\end{array}\\right.\n\t$$\n\tA state $\\psi(t=0)$ is defined as\n\t$$\n\t\\psi=3 \\phi_{1}(x)+4 \\phi_{3}(x)\n\t$$\n\t(a) if energy is measured on state $\\psi$ what is measurement with what probability?\\\\\n\t(b) Find $\\langle E\\rangle$ on state $\\psi$\\\\\n\t(c) Find $\\left\\langle E^{2}\\right\\rangle$ on state $\\psi$\\\\\n\t(d) Find $\\Delta E . \\Delta t$ on state $\\psi$\\\\\n\t$\\text { (e) After what time } t \\psi(t=t) \\text { is orthogonal to } \\psi(t=0)$\n\\end{minipage}\n\\begin{answer}\n\t$ \\psi=3 \\phi_{1}(x)+4 \\phi_{3}(x)$\\\\\n\tNormalised $\\psi,\\langle\\psi \\mid \\psi\\rangle=1$\\\\\n\t(a) measurements are $\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}, \\frac{9 \\pi^{2} \\hbar^{2}}{2 m a^{2}}$, associated with $\\phi_{1}(x)$ and $\\phi_{3}(x)$ with probability\\\\\\\\\n\ti.e. $P\\left(\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}\\right)=\\frac{\\left|\\left\\langle\\phi_{1} \\mid \\psi\\right\\rangle\\right|^{2}}{\\langle\\psi \\mid \\psi\\rangle}=\\frac{9}{25}, P\\left(\\frac{9 \\pi^{2} \\hbar^{2}}{2 m a^{2}}\\right)=\\frac{\\left|\\left\\langle\\phi_{3} \\mid \\psi\\right\\rangle\\right|^{2}}{\\langle\\psi \\mid \\psi\\rangle}=\\frac{16}{25}$\\\\\\\\\n\t(b) $\\langle E\\rangle=\\sum a_{n} P\\left(a_{n}\\right)$ where $a_{n}$ is eigen value\n\t$=\\frac{9}{25} \\epsilon_{0}+\\frac{16}{25} \\times 9 \\epsilon_{0}=\\frac{153 \\epsilon_{0}}{25} \\quad$ where $\\quad \\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}=\\epsilon_{0}$\\\\\\\\\n\t(c) $\\left\\langle E^{2}\\right\\rangle=\\sum a_{n}^{2} P\\left(a_{n}\\right)$\n\t$\\frac{9}{25} \\epsilon_{0}^{2}+\\frac{16}{25} \\times 81 \\epsilon_{0}^{2}=\\frac{1305}{25} \\epsilon_{0}^{2}$ \\\\\\\\\n\tso $\\Delta E=\\sqrt{\\left\\langle E^{2}\\right\\rangle-\\langle E\\rangle^{2}}=\\frac{96}{25} \\epsilon_{0}$\\\\\\\\\n\t(d) $\\Delta t=\\frac{2 \\pi \\hbar}{\\Delta E}=\\frac{2 \\pi \\hbar}{9 \\epsilon_{0}-\\epsilon_{0}}=\\frac{2 \\pi \\hbar}{8 \\epsilon_{0}}$\\\\\\\\\n\t$\\Rightarrow \\Delta E . \\Delta t=\\frac{96}{25} \\epsilon_{0} \\times \\frac{2 \\pi \\hbar}{8 \\epsilon_{0}}=\\frac{12 h}{25}$\n\t\\begin{align*}\n\t\t&\\text { (e) }|\\psi(x, t)\\rangle=\\frac{3}{5} \\phi_{1}(x) e^{\\frac{-i \\epsilon_{0} t}{\\hbar}}+\\frac{4}{5} \\phi_{3}(x) e^{\\frac{-i \\theta_{0} t}{\\hbar}} \\\\\n\t\t&\\text { now }\\langle\\psi(x, 0) \\mid \\psi(x, t)\\rangle=0 \\Rightarrow \\frac{9}{25} e^{\\frac{-i \\epsilon_{0} t}{\\hbar}}+\\frac{16}{25} e^{\\frac{-\\frac{-19 \\epsilon_{0} t}{\\hbar}}{\\hbar}}=0 \\\\\n\t\t&\\Rightarrow \\frac{16}{25} e^{\\frac{-19 \\epsilon_{0} t}{h}}=-\\frac{9}{25} e^{\\frac{-i \\epsilon_{0} t}{\\hbar}} \\Rightarrow \\cos \\frac{\\left(9 \\varepsilon_{0}-\\epsilon_{0}\\right) t}{\\hbar}=\\frac{-9}{16} \\\\\n\t\t&\\Rightarrow t=\\frac{\\hbar}{8 \\epsilon_{0}} \\cos ^{-1} \\frac{-9}{16} \\Rightarrow t=\\frac{m a^{2}}{4 \\pi^{2} \\hbar} \\cos ^{-1}\\left(\\frac{-9}{16}\\right)\n\t\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A particle in the infinite well has initial wave function\n\t$$\n\t\\psi(x, 0)= \\begin{cases}A x(a-x) ; & (0 \\leq x<a) \\\\ 0 ; & \\text { otherwise }\\end{cases}\n\t$$\n\tIf Eigen state of system is given by\n\t$$\n\t\\phi_{n}= \\begin{cases}\\sqrt{\\frac{2}{a}} \\sin \\frac{n \\pi x}{a} ; & 0<x<a \\\\ 0 & ; \\quad \\text { otherwise }\\end{cases}\n\t$$\n\tand if normalized $\\psi(x, 0)$ is defined as $\\psi(x, 0)=c_{1} \\phi_{1}(x)+c_{2} \\phi_{2}(x)+c_{3} \\phi_{3}(x)$, then find the value of $c_{1}, c_{2}$ and $c_{3} .$\n\\end{minipage}\n\\begin{answer}\n\t$\\text { Normalization of } \\psi \\Rightarrow\\langle\\psi \\mid \\psi\\rangle=1 \\Rightarrow \\int_{0}^{a} A^{2} x^{2}(a-x)^{2} d x=1 \\quad \\Rightarrow \\quad A=\\sqrt{\\frac{30}{a^{5}}}$\\\\\n\t\\begin{align*}\n\t\t&\\psi(x, 0)=c_{1} \\phi_{1}(x)+c_{2} \\phi_{2}(x)+c_{3} \\phi_{3}(x) \\\\\n\t\t&\\Rightarrow c_{1}=\\left\\langle\\phi_{1} \\mid \\psi\\right\\rangle, c_{2}=\\left\\langle\\phi_{2} \\mid \\psi\\right\\rangle, \\quad c_{3}=\\left\\langle\\phi_{3} \\mid \\psi\\right\\rangle\\\\\n\t\t&\\text { now } c_{1}=\\left\\langle\\phi_{1} \\mid \\psi\\right\\rangle=\\int_{0}^{a} \\sqrt{\\frac{30}{a^{5}}} \\sqrt{\\frac{2}{a}}\\left(a x-x^{2}\\right) \\sin \\frac{\\pi x}{a} d x \\\\\n\t\t&=\\sqrt{\\frac{60}{a^{6}}}\\left[\\int_{0}^{a} a x \\frac{\\sin \\pi x}{a} d x-\\int_{0}^{a} x^{2} \\sin \\frac{\\pi x}{a} d x\\right] \\\\\n\t\t&\\Rightarrow c_{1}=\\sqrt{\\frac{60}{a^{6}}}\\left[-\\frac{2 a^{3}}{\\pi^{3}} \\cos \\left(\\frac{\\pi x}{a}\\right)\\right]_{0}^{a} \\Rightarrow c_{1}=\\frac{4 a^{3}}{\\pi^{3}} \\times \\sqrt{\\frac{60}{a^{6}}}=0.99807\\\\\n\t\t&c_{2}=\\left\\langle\\phi_{2} \\mid \\psi\\right\\rangle=\\int_{0}^{a} \\sqrt{\\frac{30}{a^{5}}}\\left(a x-x^{2}\\right) \\sqrt{\\frac{2}{a}} \\sin \\left(\\frac{2 \\pi x}{a}\\right) d x \\\\\n\t\t&=\\sqrt{\\frac{60}{a^{6}}}\\left[\\int_{0}^{a} a x \\sin \\left(\\frac{2 \\pi x}{a}\\right) d x-\\int_{0}^{a} x^{2} \\sin \\left(\\frac{2 \\pi x}{a}\\right) d x\\right] \\\\\n\t\t&=\\sqrt{\\frac{60}{a^{6}}}\\left[-\\frac{a^{2}}{2 \\pi^{2}}(1-1)\\right]=0 \\Rightarrow c_{2}=0\\\\\n\t\t&c_{3}=\\left\\langle\\phi_{3} \\mid \\psi\\right\\rangle=\\int_{0}^{a} \\sqrt{\\frac{30}{a^{5}}} \\sqrt{\\frac{2}{a}}\\left(a x-x^{2}\\right) \\sin \\left(\\frac{3 \\pi x}{a}\\right) d x \\\\\n\t\t&=\\sqrt{\\frac{60}{a^{6}}}\\left[\\int_{0}^{a} a x \\sin \\left(\\frac{3 \\pi x}{a}\\right) d x-\\int_{0}^{a} x^{2} \\sin \\left(\\frac{3 \\pi x}{a}\\right) d x\\right] \\\\\n\t\t&=\\sqrt{\\frac{60}{a^{6}}}\\left[\\frac{4 a^{3}}{27 \\pi^{3}}\\right]=0.036965 \\Rightarrow c_{3}=0.0369\n\t\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ is confined to one-dimensional region $0 \\leq x \\leq a$ where potential is given by\n\t$$\n\tV(x)= \\begin{cases}\\infty ; & x \\leq 0, \\quad x \\geq a \\\\ 0 ; & 0<x<a\\end{cases}\n\t$$\n\tIts normalized wave function is given by\n\t$$\n\t\\psi(x, t=0)=\\sqrt{\\frac{8}{5 a}}\\left[1+\\cos \\frac{\\pi x}{a}\\right] \\sin \\frac{\\pi x}{a}\n\t$$\n\t(a) What is the wave function at a later time $t=t_{0}$\\\\\n\t(b) What is the average energy of the system at $t=0$ and $t=t_{0}$.\\\\\n\t(c) What is the probability that the particle is found in the left half of the box at $t=0$\\\\\n\t(d) Find $\\langle x\\rangle$ on state $\\psi$ at $t=0$\n\\end{minipage}\n\\begin{answer}\n$\\psi(x, t=0)=\\sqrt{\\frac{8}{5 a}}\\left[1+\\cos \\left(\\frac{\\pi x}{a}\\right)\\right] \\sin \\left(\\frac{\\pi x}{a}\\right)$\\\\\n$=\\sqrt{\\frac{8}{5 a}} \\sin \\left(\\frac{\\pi x}{a}\\right)+\\sqrt{\\frac{8}{5 a}} \\cos \\frac{\\pi x}{a} \\cdot \\sin \\frac{\\pi x}{a}=\\sqrt{\\frac{4}{5}} \\sqrt{\\frac{2}{a}} \\sin \\frac{\\pi x}{a}+\\frac{1}{\\sqrt{5}} \\sqrt{\\frac{2}{a}} \\sin \\left(\\frac{2 \\pi x}{a}\\right)$\\\\\n$\\psi(x, 0)=\\sqrt{\\frac{4}{5}} \\phi_{1}(x)+\\frac{1}{\\sqrt{5}} \\phi_{2}(x)$\\\\\n(a) $\\psi\\left(x, t=t_{0}\\right)=\\sqrt{\\frac{4}{5}} \\phi_{1}(x) e^{\\frac{-i \\epsilon_{0} t_{0}}{\\hbar}}+\\frac{1}{\\sqrt{5}} \\phi_{2}(x) e^{\\frac{-i 4 \\epsilon_{0} t_{0}}{\\hbar}}$\n$$\n\\left(\\because \\in_{0}=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}\\right)\n$$\n$\\text { (b) }\\langle E\\rangle=\\sum a_{n} p\\left(a_{n}\\right)$\\\\\\\\\ni.e. $P\\left(\\epsilon_{0}\\right)=\\frac{\\left|\\left\\langle\\phi_{1} \\mid \\psi\\right\\rangle\\right|^{2}}{\\langle\\psi \\mid \\psi\\rangle}=\\frac{4}{5}$\\\\\\\\\n and $P\\left(4 \\epsilon_{0}\\right)=\\frac{\\left|\\left\\langle\\phi_{2} \\mid \\psi\\right\\rangle\\right|^{2}}{\\langle\\psi \\mid \\psi\\rangle}=\\frac{1}{5} \\Rightarrow\\langle E\\rangle=\\frac{4}{5} \\times \\epsilon_{0}+\\frac{1}{5} \\times 4 \\in_{0}=\\frac{8}{5} \\epsilon_{0}$\\\\\\\\\n and $\\psi\\left(x, t=t_{0}\\right)=\\sqrt{\\frac{4}{5}} \\phi_{1} \\in_{0} e^{\\frac{-i \\epsilon_{0} t}{\\hbar}}+\\frac{1}{\\sqrt{5}} \\phi_{2} e^{\\frac{-i 4 \\epsilon_{0} t}{\\hbar}}$\\\\\\\\\nProbability of getting $\\epsilon_{0}$ and $4 \\epsilon_{0}$ are $\\frac{4}{5}$ and $\\frac{1}{5}$ respectively and $\\langle E\\rangle=\\frac{8 \\epsilon_{0}}{5}$.\\\\\n(c) probability that particle will in first half of box\n$$\n\\begin{gathered}\n\\int_{0}^{\\frac{a}{2}}|\\psi|^{2} d x \\Rightarrow \\int_{0}^{\\frac{a}{2}} \\frac{4}{5}\\left|\\phi_{1}\\right|^{2} d x+\\frac{1}{5} \\int_{0}^{\\frac{a}{2}}\\left|\\phi_{2}\\right|^{2} d x+2 \\cdot \\sqrt{\\frac{4}{5}} \\cdot \\frac{1}{\\sqrt{5}} \\int_{0}^{\\frac{a}{2}} \\phi_{1} \\phi_{2} d x \\\\\n\\Rightarrow \\frac{4}{5} \\cdot \\frac{1}{2}+\\frac{1}{5} \\cdot \\frac{1}{2}+\\frac{4}{5 a} \\int_{0}^{\\frac{a}{2}} 2 \\sin \\frac{\\pi x}{a} \\cdot \\sin \\frac{2 \\pi x}{a} d x \\Rightarrow \\frac{1}{2}+\\frac{4}{5 a}\\left[\\int_{0}^{\\frac{a}{2}}\\left[\\cos \\left(\\frac{\\pi x}{a}\\right)-\\cos \\left(\\frac{3 \\pi x}{a}\\right) d x\\right]\\right] \\\\\n\\Rightarrow \\frac{1}{2}+\\frac{4}{5 a}\\left\\{\\frac{a}{\\pi}+\\frac{a}{3 \\pi}\\right\\} \\Rightarrow \\frac{1}{2}+\\frac{16}{15 \\pi}\n\\end{gathered}\n$$\n(d) $\\langle x\\rangle=\\frac{\\langle\\psi|X| \\psi\\rangle}{\\langle\\psi \\mid \\psi\\rangle}=\\frac{4}{5}\\left\\langle\\phi_{1}|x| \\phi_{1}\\right\\rangle+\\frac{1}{5}\\left\\langle\\phi_{2}|x| \\phi_{2}\\right\\rangle+2 \\sqrt{\\frac{4}{5}} \\frac{1}{\\sqrt{5}} \\int_{0}^{a} \\phi_{1}^{*} x \\phi_{2} d x$\\\\\\\\ $\\Rightarrow\\langle x\\rangle=\\frac{4}{5} \\cdot \\frac{a}{2}+\\frac{1}{5} \\cdot \\frac{a}{2}+\\frac{4}{5 a} \\int_{0}^{a}\\left[x \\cos \\frac{\\pi x}{a}-x \\cos \\frac{3 \\pi x}{a}\\right] d x$\n\\begin{align*}\n&\\Rightarrow\\langle x\\rangle=\\frac{a}{2}+\\frac{4}{5 a}\\left[\\frac{a}{\\pi} \\frac{\\cos \\frac{x}{a}}{\\frac{\\pi}{a}}-\\frac{3 \\pi}{a} \\frac{\\cos \\frac{3 \\pi x}{a}}{\\frac{3 \\pi}{a}}\\right]_{0}^{a} \\\\\n&\\Rightarrow\\langle x\\rangle=\\frac{a}{2}+\\frac{4}{5 a}\\left[\\frac{a^{2}}{\\pi^{2}}(-1-1)-\\frac{a^{2}}{9 \\pi^{2}}(-1-1)\\right] \\Rightarrow\\langle x\\rangle=\\frac{a}{2}-\\frac{64 a}{45 \\pi^{2}}\n\\end{align*}\t\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Particles of energy $9 \\mathrm{eV}$ are sent towards a potential step $8 \\mathrm{eV}$ high. What percentage of particles will reflect back?\n\\end{minipage}\n\\begin{answer}\n\t$\\left(\\frac{\\sqrt{E}-\\sqrt{E-V_{0}}}{\\sqrt{E}+\\sqrt{E-V_{0}}}\\right)^{2}=\\left(\\frac{\\sqrt{9}-\\sqrt{1}}{\\sqrt{9}+\\sqrt{1}}\\right)^{2}=\\frac{1}{4}$\\\\\\\\\n\t$\\text { So, } 25 \\% \\text { of the particles will reflect back. }$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Electrons of $1 \\mathrm{eV}$ are incident on a barrier of height $10 \\mathrm{eV}$ and width $0.5 \\mathrm{~nm} .$ Find the transmission probability. What will be the probability if the particle is proton instead of electron?\n\\end{minipage}\n\\begin{answer}\n\t$\\text { We have } \\gamma=\\sqrt{\\frac{2 m\\left(V_{0}-E\\right)}{\\hbar^{2}}}=\\sqrt{\\frac{9 \\mathrm{eV}}{38 \\times 10^{-3} \\mathrm{eVnm}^{2}}} \\approx 15 \\mathrm{~nm}^{-1}$\\\\\n\t$\\text { or, } \\quad 2 \\gamma L=2 \\times 15 \\times 0.5=15$\\\\\n\tAs it is quite large as compared to 1 , one can use the approximation\n\t$$\n\tT: \\approx e^{-2 \\gamma L}=e^{-15} \\approx 3 \\times 10^{-7}\n\t$$\n\tIf the particle is a proton,\n\t$$\n\t\\gamma=\\sqrt{\\frac{1836 m_{e}\\left(V_{0}-E\\right)}{\\hbar^{2}}}=\\sqrt{1836} \\times 15 \\mathrm{~nm}^{-1}=643 \\mathrm{~nm}^{-1} .\n\t$$\n\tFor $2 \\gamma L \\approx 643$, the transmission probability\n\t$$\n\tT=e^{-2 \\gamma L}=e^{-643} \\approx 10^{-279} .\n\t$$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ moves in the potential $V(x)=\\frac{1}{2} m \\omega^{2} x^{2} .$ It has wave function $\\psi(x)$ at time $t=0$. What will be the wave function at time, $t=2 \\pi / \\omega$ (one time period)?\n\\end{minipage}\n\\begin{answer}\n\tLet the wave function at $t=0$ be $\\psi(x)=\\sum_{n} C_{n}\\left|\\phi_{n}\\right\\rangle$\\\\\n\tThe wave function at time $t$ will be\n\t$$\n\t\\psi(x, t)=\\sum_{n} C_{n}\\left|\\phi_{n}\\right\\rangle e^{-\\frac{i}{\\hbar} E_{n t}}=\\sum_{n} C_{n}\\left|\\phi_{n}\\right\\rangle e^{-\\frac{i}{\\hbar}\\left(n+\\frac{1}{2}\\right) h\\omega t}\n\t$$\n\t$$=\\sum_{n} C_{n}\\left|\\phi_{n}\\right\\rangle e^{-i\\left(n+\\frac{1}{2}\\right) 2 \\pi}=\\sum_{n} C_{n}\\left|\\phi_{n}\\right\\rangle e^{-i \\pi}=\\sum_{n} C_{n}\\left|\\phi_{n}\\right\\rangle=-\\psi(x)$$\n\tIn one time period the wave function becomes negative of its original form. In two time periods, it regains its original shape.\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A quantum mechanical particle in a harmonic oscillator potential with potential $\\frac{1}{2} m \\omega^{2} x^{2}$ has the initial wave function $\\psi=\\phi_{0}(x)+\\phi_{1}(x)$, where $\\phi_{0}$ and $\\phi_{1}$ are the real wave functions in the ground and first excited state of the harmonic oscillator Hamiltonian.\\\\\n\t(a) Find the average value of energy on state $\\psi=\\phi_{0}(x)+\\phi_{1}(x)$,\\\\\n\t(b) Find average value of $X$ on state $\\psi$.\\\\\n\t(c) Find average value of $X^{2}$ on state $\\psi$\n\\end{minipage}\n\\begin{answer}\n$\\text { (a) If energy is measured on state } \\psi \\text { the measurement is } \\frac{\\hbar \\omega}{2} \\text { and } \\frac{3 \\hbar \\omega}{2} \\text { with }$\\\\\nprobability $\\frac{1}{2}$ for each measurement .\\\\\\\\\n$\\langle E\\rangle=\\frac{1}{2}\\left(\\frac{\\hbar \\omega}{2}\\right)+\\frac{1}{2}\\left(\\frac{3 \\hbar \\omega}{2}\\right)=\\hbar \\omega$\\\\\\\\\n$\\text { (b) }|\\psi\\rangle=\\frac{1}{\\sqrt{2}}\\left(\\left|\\phi_{0}\\right\\rangle+\\left|\\phi_{1}\\right\\rangle\\right)$\\\\\n$\\left|\\phi_{0}\\right\\rangle=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 4} e^{\\frac{-m \\omega x^{2}}{2 \\hbar}} \\quad \\text { and }\\left|\\phi_{1}\\right\\rangle=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 4} \\cdot \\sqrt{2} \\cdot\\left(\\frac{m \\omega}{\\hbar}\\right)^{1 / 2} \\cdot x . e^{\\frac{-m \\omega x^{2}}{2 \\hbar}},\\langle\\psi \\mid \\psi\\rangle=1$\\\\\\\\\n$\\langle X\\rangle=\\frac{1}{2}\\left\\langle\\phi_{0}|X| \\phi_{0}\\right\\rangle+\\frac{1}{2}\\left\\langle\\phi_{1}|X| \\phi_{1}\\right\\rangle+\\left\\langle\\phi_{0}|X| \\phi_{1}\\right\\rangle ; \\quad\\left\\langle\\phi_{0}|X| \\phi_{0}\\right\\rangle=0,\\left\\langle\\phi_{1}|X| \\phi_{1}\\right\\rangle=0$\\\\\\\\\n$\\left\\langle\\phi_{0}|X| \\phi_{1}\\right\\rangle=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2} \\cdot \\sqrt{2}\\left(\\frac{m \\omega}{\\hbar}\\right)^{1 / 2} \\cdot \\int_{-\\infty}^{\\infty} x^{2} e^{\\frac{-m \\omega x^{2}}{\\hbar}} d x=\\frac{1}{\\sqrt{2}}\\left(\\frac{m \\omega}{\\hbar}\\right)\\left(\\frac{\\hbar}{m \\omega}\\right)^{3 / 2}=\\sqrt{\\frac{\\hbar}{2 m \\omega}}$\\\\\\\\\n$$\\langle X\\rangle=\\sqrt{\\frac{\\hbar}{2 m \\omega}}$$\n(c) $\\left\\langle X^{2}\\right\\rangle=\\frac{1}{2}\\left\\langle\\phi_{0}\\left|X^{2}\\right| \\phi_{0}\\right\\rangle+\\frac{1}{2}\\left\\langle\\phi_{1}\\left|X^{2}\\right| \\phi_{1}\\right\\rangle+\\frac{1}{2}\\left\\langle\\phi_{0}\\left|X^{2}\\right| \\phi_{1}\\right\\rangle+\\frac{1}{2}\\left\\langle\\phi_{1}\\left|X^{2}\\right| \\phi_{0}\\right\\rangle$\\\\\\\\\n$\\left\\langle\\phi_{0}\\left|X^{2}\\right| \\phi_{1}\\right\\rangle=0,\\left\\langle\\phi_{1}\\left|X^{2}\\right| \\phi_{0}\\right\\rangle=0$\t\\\\\\\\\n\\begin{align*}\n\t&\\left\\langle\\phi_{0}\\left|X^{2}\\right| \\phi_{0}\\right\\rangle=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2} \\int_{-\\infty}^{\\infty} x^{2} \\cdot e^{\\frac{-m \\omega x^{2}}{\\hbar}} d x=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2}\\left(\\frac{\\hbar}{m \\omega}\\right)^{3 / 2} \\times \\frac{1}{2} \\sqrt{\\pi}=\\left(\\frac{\\hbar}{2 m \\omega}\\right) \\\\\n\t&\\left\\langle\\phi_{1}\\left|X^{2}\\right| \\phi_{1}\\right\\rangle=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2}(\\sqrt{2})^{2}\\left(\\frac{m \\omega}{\\hbar}\\right) \\int_{-\\infty}^{\\infty} x^{4} e^{\\frac{-m \\omega x^{2}}{\\hbar}} d x=\\frac{3}{2}\\left(\\frac{\\hbar}{m \\omega}\\right)\n\\end{align*}\n\n$$\\text { Hence }\\left\\langle X^{2}\\right\\rangle=\\left(\\frac{\\hbar}{4 m \\omega}\\right)+\\frac{3}{4}\\left(\\frac{\\hbar}{m \\omega}\\right)=\\left(\\frac{\\hbar}{m \\omega}\\right)$$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A Particle of mass in harmonic oscillator potential starts out in state $\\psi(x, 0)=A\\left[3 \\psi_{0}(x)+4 \\psi_{1}(x)\\right] .$ Where $\\psi_{0}$ is ground state and $\\psi_{1}$ is first excited state.\\\\\n\t(a) Find $A$\\\\\n\t(b) construct $\\psi(x, t)$ and $|\\psi(x, t)|^{2}$\\\\\n\\end{minipage}\n\\begin{answer}\n\t$\\text { (a) } \\psi(x, 0)=A\\left[3 \\psi_{0}(x)+4 \\psi_{1}(x)\\right]$\\\\\\\\\n\t$\\text { From normalization condition } A=\\frac{1}{\\sqrt{9+16}}=\\frac{1}{5}$\\\\\n(b)\t\\begin{align*}\n\t\t&\\psi(x, 0)=\\frac{3}{5} \\psi_{0}(x)+\\frac{4}{5} \\psi_{1}(x) \\\\\n\t\t&\\psi(x, t)=\\frac{3}{5} \\psi_{0}(x) e^{-\\frac{\\hbar \\omega e r}{2 \\hbar}}+\\frac{4}{5} \\psi_{1} e^{-i \\frac{3 h \\omega t}{2 \\hbar}} \\\\\n\t\t&\\quad=\\frac{3}{5} \\psi_{0}(x) e^{\\frac{-i \\omega t}{2}}+\\frac{4}{5} \\psi_{1} e^{-\\frac{i 3 \\omega t}{2}} \\\\\n\t\t&|\\psi(x, t)|^{2}=\\frac{9}{25}\\left|\\psi_{0}\\right|^{2}+\\frac{16}{25}\\left|\\psi_{1}\\right|^{2}+2 \\times \\frac{3}{5} \\times \\frac{4}{5} \\psi_{0} \\psi_{1} \\cos \\left(\\frac{3 \\hbar \\omega}{2}-\\frac{\\hbar \\omega}{2}\\right) t / h \\\\\n\t\t&\\quad=\\frac{9}{25}\\left|\\psi_{0}\\right|^{2}+\\frac{16}{25}\\left|\\psi_{1}\\right|^{2}+\\frac{24}{25} \\psi_{0} \\psi_{1} \\cos \\omega t\n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "ded69160e7e985ef25d40deaedf8fe5a2c1ddbb4", "size": 102677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/eigen value 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": "QM -CSIR/chapter/eigen value 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": "QM -CSIR/chapter/eigen value 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": 63.2637091805, "max_line_length": 662, "alphanum_fraction": 0.619612961, "num_tokens": 42035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.6662206464622743}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}\n\n\n\\title{Maxwell's Equations}\n\n\\author{Joe Bentley}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\n\\section{Electrostatics}\n\nConsider the electric field $\\mathbf{E}(\\mathbf{r})$ at a point $\\mathbf{r}$ due to a charge distribution $\\rho(\\mathbf{r'})$. The point $\\mathbf{r}$ is the point at which we want to measure the electric field, and the point $\\mathbf{r'}$ is the point at which the source of the charge we are considering resides. The infinitesimal charge at that point is given by,\n\n\\begin{align*}\n  dq' = \\rho(\\mathbf{r'}) dV'\n\\end{align*}\n\nThe infinitesimal volume $dV'$ can also be written as $dV' = d^3\\mathbf{r'}$. Coulomb's law gives us that the infinitesimal electric field at point $\\mathbf{r}$ is,\n\n\\begin{align*}\n  d\\mathbf{E}(\\mathbf{r}) &= \\frac{dq'}{4\\pi\\epsilon_0 {|\\mathbf{r}-\\mathbf{r'}|}^2} \\frac{(\\mathbf{r} - \\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|} \\\\\n  &= \\frac{\\rho(\\mathbf{r'})(\\mathbf{r}-\\mathbf{r'})}{4\\pi\\epsilon_0{|\\mathbf{r}-\\mathbf{r'}|}^3} dV' \\\\\n  \\mathbf{E}(\\mathbf{r}) &= \\frac{\\rho(\\mathbf{r'})(\\mathbf{r}-\\mathbf{r'})}{4\\pi\\epsilon_0{|\\mathbf{r}-\\mathbf{r'}|}^3} dV'\n\\end{align*}\n\nIn the second line we substitute in our expression for an infinitesimal charge element $dq' = \\rho(\\mathbf{r'}) dV'$. The divergence of the electric field is then given by,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{E}(\\mathbf{r}) &= \\int\\frac{\\rho(\\mathbf{r'})}{4\\pi\\epsilon_0} \\nabla r \\cdot \\frac{(\\mathbf{r}-\\mathbf{r'})}{{|\\mathbf{r}-\\mathbf{r'}|}^3} d^3\\mathbf{r'}\n  &= \\int \\frac{\\rho(\\mathbf{r'})}{4\\pi\\epsilon_0} 4\\pi\\delta^3(\\mathbf{r} - \\mathbf{r'}) d^3\\mathbf{r'}\n\\end{align*}\n\nIn the distributions notes we showed that $\\nabla\\cdot\\frac{\\mathbf{r}}{r^3}=4\\pi\\delta^3(\\mathbf{r})$, which is what we wrote on the second line of the last equation. By cancelling the values of $4\\pi$ and then integrating the delta function over volume, we obtain our first Maxwell equation,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{E}(\\mathbf{r}) = \\frac{\\rho(\\mathbf{r})}{\\epsilon_0}\n\\end{align*}\n\nIf we integrate both sides of this over a volume $V$, bounded by a surface $S = \\partial V$ and apply the divergence theorem we get,\n\n\\begin{align*}\n  \\int_V \\nabla\\cdot\\mathbf{E} dV = \\int_V \\frac{\\rho(\\mathbf{r})}{\\epsilon_0} dV\n\\end{align*}\n\nWhich gives us an equation known as Gauss' law,\n\n\\begin{align*}\n  \\oint_S \\mathbf{E}\\cdot d\\mathbf{S} = \\frac{Q}{\\epsilon_0}\n\\end{align*}\n\nWe can show that the curl of the electric field is zero, $\\nabla\\times\\mathbf{E}=0$, since we can write the electric field as the gradient of a scalar field $\\mathbf{E} = -\\nabla\\phi$, where $\\phi(r)$ is given by,\n\n\\begin{align*}\n  \\phi(r) = \\int_V \\frac{\\rho(\\mathbf{r'})d^3\\mathbf{r'}}{4\\pi\\epsilon_0 |\\mathbf{r} - \\mathbf{r'}|}\n\\end{align*}\n\nWe therefore know that the curl of the electric field must be zero, from the vector identity that the curl of a gradient of a scalar field is always zero $\\nabla\\times(\\nabla\\phi) = \\mathbf{0}$. However this is only true in the static case, where there is no time dependence in the electric or magnetic fields. We will explore the electromagnetic case later.\n\n\n\\section{Magnetostatics}\n\n\nThe Biot-Savart law gives us that the magnetic field $\\mathbf{B}(\\mathbf{r})$ due to a current density distribution $\\mathbf{j}(\\mathbf{r'})$ is given by,\n\n\\begin{align*}\n  \\mathbf{B}(\\mathbf{r})=\\frac{\\mu_0}{4\\pi}\\int_V\\frac{\\mathbf{j}(\\mathbf{r'})\\times(\\mathbf{r}-\\mathbf{r'})}{{|\\mathbf{r}-\\mathbf{r'}|}^3} d^3\\mathbf{r'}\n\\end{align*}\n\nThe cross product shows us that the magnetic field $\\mathbf{B}(\\mathbf{r})$ will be perpendicular to both the current density $\\mathbf{j}(\\mathbf{r'})$ (and thus the current) and the radial direction $(\\mathbf{r} - \\mathbf{r'})$.\n\nWe can rewrite this by noting that if a vector $\\mathbf{c}$ is constant in space, then we can write,\n\n\\begin{align*}\n  \\nabla\\times(\\phi\\mathbf{c}) = \\nabla\\phi\\times\\mathbf{c}+\\phi\\nabla\\times\\mathbf{c} = \\nabla\\phi\\times\\mathbf{c}\n\\end{align*}\n\nThe second term $\\phi\\nabla\\times\\mathbf{c} = 0$ because the curl of a constant vector is zero, since it is unchanging in space so the derivative of each component will be zero. In this case our constant vector is given by,\n\n\\begin{align*}\n  \\mathbf{c} = \\frac{(\\mathbf{r}-\\mathbf{r'})}{{|\\mathbf{r}-\\mathbf{r'}|}^3}\n\\end{align*}\n\nand then by applying this to the expression inside the integral in the Biot-Savart law,\n\n\\begin{align*}\n  \\mathbf{j}(\\mathbf{r'})\\times\\frac{(\\mathbf{r}-\\mathbf{r'})}{{|\\mathbf{r}-\\mathbf{r'}|}^3} &= -\\frac{(\\mathbf{r}-\\mathbf{r'})}{{|\\mathbf{r}-\\mathbf{r'}|}^3}\\times \\\\\n  &= \\left(\\nabla_r \\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\\right)\\times\\mathbf{j}(\\mathbf{r'}) \\\\\n  &= \\nabla_r\\times\\left(\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}\\right)\n\\end{align*}\n\nBy applying these results, the Biot-Savart law may be rewritten as,\n\n\\begin{align*}\n  \\mathbf{B}(\\mathbf{r}) = \\frac{\\mu_0}{4\\pi}\\int_V\\nabla_r\\times\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|} d^3\\mathbf{r'}\n\\end{align*}\n\nIt follows that we can write the magnetic field as,\n\n\\begin{align*}\n  \\mathbf{B}(\\mathbf{r}) = \\nabla\\times\\mathbf{A}(\\mathbf{r})\n\\end{align*}\n\nwhere,\n\n\\begin{align*}\n  \\mathbf{A}(\\mathbf{r}) = \\frac{\\mu_0}{4\\pi}\\int_V\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'}\n\\end{align*}\n\nWe immediately see from our vector identities, that taking the divergence of the magnetic field is taking the divergence of the curl of a vector field, which our vector identities show is zero, $\\nabla\\cdot(\\nabla\\times\\mathbf{A})=0$. Therefore the divergence of the magnetic field is zero,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{B}(\\mathbf{r}) = 0\n\\end{align*}\n\nwhich is another of Maxwell's equations.\n\nThe curl of the magnetic field can be calculated using the vector identity,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{B}=\\nabla\\times(\\nabla\\times\\mathbf{A})=\\nabla(\\nabla\\cdot\\mathbf{A})-\\nabla^2\\mathbf{A}\n\\end{align*}\n\nFirst we will calculate the laplacian of the vector field, as this is much easier than the first term,\n\n\\begin{align*}\n  \\nabla_r^2\\mathbf{A}(\\mathbf{r})&=\\frac{\\mu_0}{4\\pi}\\int_V\\left(\\nabla_r^2\\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\\right)\\mathbf{j}(\\mathbf{r'})d^3\\mathbf{r'} \\\\\n  &= \\frac{\\mu_0}{4\\pi}\\int_V -4\\pi\\delta^3(\\mathbf{r}-\\mathbf{r'})\\mathbf{j}(\\mathbf{r'})d^3\\mathbf{r'} \\\\\n  &= -\\mu_0\\mathbf{j}(\\mathbf{r'})\n\\end{align*}\n\nNext we need to calculate the first term. First we will try and work out a nice form for the divergence of $\\mathbf{A}$,\n\n\\begin{align*}\n  \\nabla_r\\cdot\\int_V\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'}=\\int_V\\nabla_r\\cdot\\left[\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}\\right]d^3\\mathbf{r'}\n\\end{align*}\n\nMuch as with the curl of a scalar field multiplied by a constant vector, we can write $\\nabla\\cdot(\\phi\\mathbf{c})=(\\nabla\\phi)\\cdot\\mathbf{c}+\\phi\\nabla\\cdot\\mathbf{c}=(\\nabla\\phi)\\cdot\\mathbf{c}$. We know that the second term is zero, since the divergence of a constant vector must be zero due to the fact that vector is unchanging in space. We can therefore write,\n\n\\begin{align*}\n  \\int_V\\nabla_r\\left[\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}\\right]d^3\\mathbf{r'}=\\int_V\\left[\\nabla_r\\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\\right]\\cdot\\mathbf{j}(\\mathbf{r'})d^3\\mathbf{r'}\n\\end{align*}\n\nWe want to know this in terms of $\\nabla_{r'}$ instead of $\\nabla_r$. We can write,\n\n\\begin{align*}\n  \\nabla_{r'} \\frac{1}{|\\mathbf{r}-\\mathbf{r'}|} = \\frac{(\\mathbf{r}-\\mathbf{r'})}{{|\\mathbf{r}-\\mathbf{r'}|}^3} = -\\nabla_r\\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\n\\end{align*}\n\nUsing this we can write,\n\n\\begin{align*}\n  \\nabla_r\\cdot\\int_v\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r}=-\\int_V\\left[\\nabla_{r'}\\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\\right]\\cdot\\mathbf{j}(\\mathbf{r'})d^3\\mathbf{r'}\n\\end{align*}\n\nHere we can use the vector identity, $\\nabla\\cdot(\\phi\\mathbf{A})=(\\nabla\\phi)\\cdot\\mathbf{A}+\\phi\\nabla\\cdot\\mathbf{A}$, so that we can write,\n\n\\begin{align*}\n  \\nabla_{r'}\\cdot\\left[\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}\\right] = \\left[\\nabla_{r'}\\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\\right]\\cdot\\mathbf{j}(\\mathbf{r'}) + \\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}\\nabla_{r'}\\cdot\\mathbf{j}(\\mathbf{r'})\n\\end{align*}\n\nSubtituting this back into our integral we obtain,\n\n\\begin{align*}\n  \\nabla_r\\cdot\\int\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'}&=-\\int_V\\nabla_{r'}\\cdot\\left[\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}\\right]d^3\\mathbf{r'} + \\int_V\\frac{\\nabla_{r'}\\cdot\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'} \\\\\n  &=-\\oint_S\\frac{\\mathbf{j}(\\mathbf{r'})\\cdot d\\mathbf{S'}}{|\\mathbf{r}-\\mathbf{r'}|} + \\int_V\\frac{\\nabla_{r'}\\cdot\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'}\n\\end{align*}\n\n\nFor the first term we have used the divergence theorem to convert the volume integral into a surface intagral at infinity. Since $\\mathbf{j}(\\mathbf{r'})=\\mathbf{0}$ along the surface, this integral will be zero.\n\nFrom the continuity equation we have that,\n\n\\begin{align}\n  \\label{eq:continuity}\n  \\nabla_{r'}\\cdot\\mathbf{j}(\\mathbf{r'}, t) = -\\frac{\\partial\\rho(\\mathbf{r'}, t)}{\\partial t} = 0\n\\end{align}\n\nThis is zero as charge (and thus current) is always conserved.\n\nSince we have already shown that the first integral is zero, and this shows that the second integral is zero, we therefore have that in the static case,\n\n\\begin{align*}\n  \\nabla_{r'}\\cdot\\mathbf{A}(\\mathbf{r}) = \\frac{\\mu_0}{4\\pi}\\int_V\\nabla_r\\cdot\\left[\\frac{\\mathbf{j}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}\\right]d^3\\mathbf{r'} = 0\n\\end{align*}\n\nTherefore, in the case where the magnetic and electric fields are constant in time, we have that,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{B}(\\mathbf{r})&=\\nabla(\\nabla\\cdot\\mathbf{A})-\\nabla^2\\mathbf{A} \\\\\n  &=\\mu_0\\mathbf{j}(\\mathbf{r})\n\\end{align*}\n\nIn the general, non static case, we calculate the divergence of $\\mathbf{A}$ as,\n\n\\begin{align*}\n  \\nabla_r\\cdot\\mathbf{A}(\\mathbf{r}, t)&=\\frac{\\mu_0}{4\\pi}\\int_V\\nabla_r\\cdot\\left[\\frac{\\mathbf{j}(\\mathbf{r'}, t)}{|\\mathbf{r}-\\mathbf{r'}|}\\right]d^3\\mathbf{r'} \\\\\n  &=\\frac{\\mu_0}{4\\pi}\\int_V\\frac{\\nabla_{r'}\\cdot\\mathbf{j}(\\mathbf{r'}, t)}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'} \\\\\n  &=-\\frac{\\mu_0}{4\\pi}\\frac{\\partial}{\\partial t}\\int_V\\frac{\\rho(\\mathbf{r'}, t)}{|\\mathbf{r}-\\mathbf{r'}|}d^3\\mathbf{r'}\n\\end{align*}\n\nIn the third line we have used the continuity equation, eq.~\\ref{eq:continuity}. By taking the gradient of this we get the result we need,\n\n\\begin{align*}\n  \\nabla_r\\left(\\nabla_r\\cdot\\mathbf{A}(\\mathbf{r}, t)\\right) &=\\frac{\\mu_0}{4\\pi}\\frac{\\partial}{\\partial t}\\int_{V'}\\frac{\\rho(\\mathbf{r'}, t)}{{|\\mathbf{r}-\\mathbf{r'}|}^3}d^3\\mathbf{r'} \\\\\n  &= \\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}(\\mathbf{r}, t)}{\\partial t}\n\\end{align*}\n\nWe therefore have, in the general case where the magnetic and electric field need not be constant,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{B}=\\mu_0\\mathbf{j}+\\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}\n\\end{align*}\n\n\\section{Faraday's Law}\n\nOur final (and easiest) equation to find is the non-static form of $\\nabla\\times\\mathbf{E}$. This is a very simple equation to find as it is not much more than a restatement of an empirical law known as Faraday's law.\n\nFaraday's law tells us that the emf induced in a loop $C$ is equal to the rate of change of the magnetic flux through the loop,\n\n\\begin{align*}\n  \\epsilon &= -\\frac{d\\Phi_B}{dt}\n\\end{align*}\n\nWhere the magnetic flux is defined as $\\Phi_B = \\int_S\\mathbf{B}\\cdot d\\mathbf{S}$. The emf is also defined by the integral of the electric field around the closed loop,\n\n\\begin{align*}\n  \\epsilon &= \\oint_C\\mathbf{E}\\cdot d\\mathbf{r}\n\\end{align*}\n\nUsing these with Faraday's law we have that,\n\n\\begin{align*}\n  \\oint_C\\mathbf{E}\\cdot d\\mathbf{r}=-\\frac{\\partial}{\\partial t}\\int_S\\mathbf{B}\\cdot d\\mathbf{S}=-\\int_S\\frac{\\partial\\mathbf{B}}{\\partial t}\\cdot d\\mathbf{S}\n\\end{align*}\n\nBy applying Stokes' theorem we have,\n\n\\begin{align*}\n  \\int_S(\\nabla\\times\\mathbf{E})\\cdot d\\mathbf{S} = -\\int_S\\frac{\\partial\\mathbf{B}}{\\partial t}\\cdot d\\mathbf{S}\n\\end{align*}\n\nTherefore we have our final Maxwell equation, which is now valid for the non-static case,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{E}=-\\frac{\\partial\\mathbf{B}}{\\partial t}\n\\end{align*}\n\n\n\n\\section{Helmholtz's Theorem}\n\nAny vector field $\\mathbf{V}(\\mathbf{r})$ which is defined on all space and falls off at infinite at least as fast as $1 / r^2$ can be written as the sum of the gradient of some scalar field $\\phi$ and the curl of some vector field $\\mathbf{A}$.\n\nTo prove this, consider the fields $\\phi(\\mathbf{r})$ and $\\mathbf{V}(\\mathbf{r})$, defined by,\n\n\\begin{align*}\n  \\phi(\\mathbf{r})&=\\nabla\\cdot\\mathbf{B}(\\mathbf{r}) \\\\\n  \\mathbf{A}(\\mathbf{r})&=\\nabla\\times\\mathbf{B}(\\mathbf{r}) \\\\\n\\end{align*}\n\nwhere,\n\n\\begin{align*}\n  \\mathbf{B}(\\mathbf{r})=\\frac{1}{4\\pi}\\int\\frac{\\mathbf{V}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|} d^3r'\n\\end{align*}\n\nIt therefore follows from our vector identities that,\n\n\\begin{align*}\n  -\\nabla\\phi + \\nabla\\times\\mathbf{A} &= -\\nabla(\\nabla\\cdot\\mathbf{B})+\\nabla\\times(\\nabla\\times\\mathbf{B}) \\\\\n                                       &= -\\nabla^2\\mathbf{B}\n\\end{align*}\n\nBy looking at the definition of $\\mathbf{B}(\\mathbf{r})$ and applying the Laplacian,\n\n\\begin{align*}\n  \\nabla^2\\mathbf{B}(\\mathbf{r})&=\\frac{1}{4\\pi}\\nabla^2\\int\\frac{\\mathbf{V}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3r' \\\\\n                                &=\\frac{1}{4\\pi}\\int\\mathbf{V}(\\mathbf{r'})\\nabla_r^2\\frac{1}{|\\mathbf{r}-\\mathbf{r'}|}d^3r' \\\\\n                                &=\\frac{1}{4\\pi}\\int\\mathbf{V}(\\mathbf{r'})\\left[-4\\pi\\delta^3(\\mathbf{r}-\\mathbf{r'})\\right]d^3r' \\\\\n                                &=-\\mathbf{V}(\\mathbf{r})\n\\end{align*}\n\nIn the third line we just used that the Laplacian of $1/|r|$ is given by the delta function, which we have shown in other notes.\n\nWe have therefore proved that,\n\n\\begin{align*}\n  -\\nabla\\phi+\\nabla\\times\\mathbf{A}=-\\nabla^2\\mathbf{B}=\\mathbf{V}(\\mathbf{r})\n\\end{align*}\n\nA vector field $\\mathbf{V}(\\mathbf{r})$ with $\\nabla\\cdot\\mathbf{V}=0$ is known as solenoidal, and with $\\nabla\\times\\mathbf{V}=0$ is known as irrotational. Since if we take the divergence, we get $\\nabla\\cdot(\\nabla\\times\\mathbf{A})=0$ or if we take the curl $\\nabla\\times\\nabla\\phi=\\mathbf{0}$, we can express a vector field as the sum of a solenoidal and irrotational part. In $\\mathbf{V}=-\\nabla\\phi+\\nabla\\times\\mathbf{A}$, $-\\nabla\\phi$ is the irrotational part, as when the curl is taken this part goes to zero, and $\\nabla\\times\\mathbf{A}$ is the solenoidal part, as when the divergence is taken that part goes to zero.\n\nUsing some vector calculus we can show that $\\phi(\\mathbf{r})$ and $\\mathbf{A}(\\mathbf{r})$ can be written in terms of the divergence $D(\\mathbf{r})=\\nabla\\cdot\\mathbf{V}(\\mathbf{r})$, and the curl $\\mathbf{C}(\\mathbf{r})=\\nabla\\times\\mathbf{V}(\\mathbf{r})$,\n\n\\begin{align*}\n  \\phi(\\mathbf{r})&=\\frac{1}{4\\pi}\\int\\frac{D(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3r' \\\\\n  \\mathbf{A}(\\mathbf{r})&=\\frac{1}{4\\pi}\\int\\frac{\\mathbf{C}(\\mathbf{r'})}{|\\mathbf{r}-\\mathbf{r'}|}d^3r'\n\\end{align*}\n\nTherefore Helmholtz shows that any vector field $\\mathbf{V}(\\mathbf{r})$ which is defined on all space and falls off at infinity at least as fast as $1/r^2$ is uniquely defined by its divergence and curl,\n\n\\begin{itemize}\n  \\item If $\\mathbf{V}$ is solenoidal, and therefore $\\phi=0$, then $\\mathbf{V}$ can be written as just the curl of $\\mathbf{A} \\to \\mathbf{V}=\\nabla\\times\\mathbf{A}(\\mathbf{r})$\n  \\item If $\\mathbf{V}$ is irrotational, and therefore $\\mathbf{A}=\\mathbf{0}$, then $\\mathbf{V}$ can be written as just the gradient of $\\phi \\to \\mathbf{V}=-\\nabla\\phi$.\n\\end{itemize}\n\n\\section{Example: Maxwell's Equations}\n\nWriting out the differential form of Maxwell's equations,\n\n\\begin{alignat*}{2}\n  &\\nabla\\cdot\\mathbf{E}=\\frac{\\rho}{\\epsilon_0}\\qquad&&\\nabla\\times\\mathbf{E}=-\\frac{\\partial\\mathbf{B}}{\\partial t} \\\\\n  &\\nabla\\cdot\\mathbf{B}=0\\qquad&&\\nabla\\times\\mathbf{B}=\\mu_0\\mathbf{j}+\\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}\n\\end{alignat*}\n\nwe notice that two of the equations involve a source term. These equations are $\\nabla\\cdot\\mathbf{E}$ and $\\nabla\\times\\mathbf{B}$, which contain the source terms $\\rho$, and $\\mathbf{j}$ respectively. They both contain a term which is the source of the field.\n\nConsider the two other equations which do not have a source term. Firstly we have $\\nabla\\cdot\\mathbf{B}=0$, this means that $\\mathbf{B}$ is solenoidal, and therefore as we have shown by Helmholtz's theorem, $\\mathbf{B}$ can be written as the curl of another vector field $\\mathbf{A}$, $\\mathbf{B}=\\nabla\\times\\mathbf{A}$.\n\nNext we have $\\nabla\\times\\mathbf{E}$. As we have just shown we can write the $\\mathbf{B}=\\nabla\\times\\mathbf{A}$, which allows us to write,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{E} = -\\frac{\\partial\\mathbf{B}}{\\partial t} = -\\frac{\\partial}{\\partial t}(\\nabla\\times\\mathbf{A}) = -\\nabla\\times\\frac{\\partial\\mathbf{A}}{\\partial t}\n\\end{align*}\n\nBy grouping both terms onto one side we can see that,\n\n\\begin{align*}\n  \\nabla\\times\\left(\\mathbf{E}\\times\\frac{\\partial\\mathbf{A}}{\\partial t}\\right) = \\mathbf{0}\n\\end{align*}\n\nThis means that the part between the parenthesis is irrotational, and thus from Helmholtz this can be written as the gradient of a scalar field, $\\mathbf{E} + \\frac{\\partial\\mathbf{A}}{\\partial t} = -\\nabla\\phi$.\n\nWe have shown that we can write the electric and magnetic field in terms of a scalar and vector potential $\\phi$ and $\\mathbf{A}$,\n\n\\begin{align*}\n  \\mathbf{B}&=\\nabla\\times\\mathbf{A}\\\\\n  \\mathbf{E}&=-\\nabla\\phi-\\frac{\\partial\\mathbf{A}}{\\partial t}\n\\end{align*}\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "facacf4d89be73aea13ac29aa8ae3fcae5b40a5b", "size": 17887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths/maxwell/maxwell.tex", "max_stars_repo_name": "unanimousarc/physics", "max_stars_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-13T14:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T14:27:57.000Z", "max_issues_repo_path": "maths/maxwell/maxwell.tex", "max_issues_repo_name": "unanimousarc/physics", "max_issues_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maths/maxwell/maxwell.tex", "max_forks_repo_name": "unanimousarc/physics", "max_forks_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:14:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:14:51.000Z", "avg_line_length": 50.385915493, "max_line_length": 627, "alphanum_fraction": 0.6748476547, "num_tokens": 6750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6662124815509355}}
{"text": "\n\\chapter{Quicksort recurrences}\n\n\\section{On the average number of checks}\n\nLet $c_{n}$ be the number of checks occuring on the computation\nof Quicksort algorithm on a vector of length $n$. After some manipulation\nstarting from a general relation over $c_{n}$, which is derived from\nQuicksort algorithm implementation directly, the following\nrecurrence relation can be derived:\n\\begin{equation}\n    \\label{eq:quicksort-checks-recurrence}\n    \\frac{c_{n}}{n + 1} = \\frac{2}{n + 1} + \\frac{1}{n} c_{n - 1}\n\\end{equation}\none unfolding step allows us to rewrite term $\\frac{1}{n} c_{n - 1}$, \nrewriting the starting relation as:\n\\begin{displaymath}\n    \\frac{c_{n}}{n + 1} = \\frac{c_{n - 2}}{n - 1} + \\frac{2}{n} + \\frac{2}{n + 1}\n\\end{displaymath}\nDoing $3$ more unfolding steps from the above recurrence yield the\nnew recurrence:\n\\begin{displaymath}\n    \\frac{c_{n}}{n + 1} = \\frac{2}{n - 3} + \\frac{c_{n - 5}}{n - 4} + \\frac{2}{n + 1} + \\frac{2}{n} + \\frac{2}{n - 1} + \\frac{2}{n - 2}\n\\end{displaymath}\nTo reach previous recurrence, the following subterms have been unfolded,\naccording \\autoref{eq:quicksort-checks-recurrence}:\n\\begin{displaymath}\n    \\left \\{ \\frac{1}{n} c_{n - 1} : \\frac{c_{n - 2}}{n - 1} + \\frac{2}{n}, \\quad \\frac{c_{n - 4}}{n - 3} : \\frac{2}{n - 3} + \\frac{c_{n - 5}}{n - 4}, \\quad \\frac{c_{n - 3}}{n - 2} : \\frac{2}{n - 2} + \\frac{c_{n - 4}}{n - 3}, \\quad \\frac{c_{n - 2}}{n - 1} : \\frac{2}{n - 1} + \\frac{c_{n - 3}}{n - 2}\\right \\}\n\\end{displaymath}\n\n\n", "meta": {"hexsha": "3f00c14cf7f7b28f060bf5071170ca6c789e1903", "size": 1478, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/chapters/quicksort.tex", "max_stars_repo_name": "massimo-nocentini/Ph.D", "max_stars_repo_head_hexsha": "7b5174c669d2c1acfe4538e69338064d8acfbe92", "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/quicksort.tex", "max_issues_repo_name": "massimo-nocentini/Ph.D", "max_issues_repo_head_hexsha": "7b5174c669d2c1acfe4538e69338064d8acfbe92", "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/quicksort.tex", "max_forks_repo_name": "massimo-nocentini/Ph.D", "max_forks_repo_head_hexsha": "7b5174c669d2c1acfe4538e69338064d8acfbe92", "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.1875, "max_line_length": 308, "alphanum_fraction": 0.6332882273, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6661679538410185}}
{"text": "\\chapter{CT Convolution}\n\n\\section{Review CT LTI systems and superposition property}\n\nRecall the superposition property of LTI systems. If a CT system is LTI then the superposition property holds. Given a system where\n\\[   \nx_i(t) \\mapsto y_i(t) \\; \\forall\\; i\n\\]\nthen\n\\[\n\\sum\\limits_{i} a_i x_i(t) \\mapsto \\sum\\limits_{i} a_i y_i(t) \n\\]\n\nSuperposition enables a powerful problem reduction strategy. The overall idea for is that if:\n\n\\begin{itemize}\n\\item we can write an aribtrary signal as a sum of simple signals, and \n\\item we can determine the response to the simple signals, then\n\\item we can easily express the output due to the input using superposition\n\\end{itemize}\n\nThis will be a recurring pattern in this course. In this lecture, the simple signals are weighted, time shifts of one signal, the delta function, $\\delta(t)$.\n\n\\section{Convolution Integral}\n\nTo derive this we start with the sifting property of the CT impulse function (from lecture 2)\n\\[\n\\int\\limits_{a}^{b} x(t)\\delta(t-t_0) \\; dt = x(t_0)\n\\]\nfor any $a < t_0 < b$. A slight change of variables ($t_0 \\rightarrow \\tau$) and limits ($a \\rightarrow -\\infty$ and $b \\rightarrow \\infty$) gives:\n\\[\nx(t) = \\int\\limits_{-\\infty}^{\\infty} x(\\tau)\\delta(t-\\tau) \\; d\\tau\n\\]\nshowing that we can write any CT signal as an infinite sum (integral) of weighted and time-shifted impluse functions.\n\nLet $h(t)$ be the CT {\\it impulse response}, the output due to the input $\\delta(t)$, i.e. $\\delta(t) \\mapsto h(t)$. Then if the system is time-invariant: $\\delta(t-\\tau) \\mapsto h(t-\\tau)$ and by superposition if the input is writen as\n\\[\nx(t) = \\int\\limits_{-\\infty}^{\\infty} x(\\tau)\\delta(t-\\tau) \\; d\\tau\n\\]\nthen the output is given by\n\\[\n  y(t) = \\int\\limits_{-\\infty}^{\\infty} x(\\tau)h(t-\\tau) \\; d\\tau = x(t) * h(t)\n\\]\nThis is called the \\emph{convolution integral} \\index{CT Convolution}.\n\nIt is worth pausing here to see the signifigance. For a LTI CT system, if I know it's impulse response $h(t)$, I can find the response due to \\textbf{any} input using convolution. For this reason the impulse response is another way to represent an LTI system.\n\n\\section{Graphical View of the Convolution Integral.}\n\nLets break the convolution expression down into pieces. In it's general form the convolution of two signals $x_1(t)$ and $x_2(t)$ is\n\\[\nx_1(t) * x_2(t) = \\int\\limits_{-\\infty}^{\\infty} x_1(\\tau)x_2(t-\\tau) \\; d\\tau\n\\]\n\nSuppose $x_1(t)$ and $x_2(t)$ are signals that look like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/convolution-explain1.pdf}\n\\end{center}\n\nThen $x_1(\\tau)$ and $x_2(-\\tau)$ look like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/convolution-explain2.pdf}\n\\end{center}\nThe signal $x_2(t-\\tau)$ is $x_2(-\\tau)$ shifted by $t$ (since $x_2(-\\tau+t)= x_2(t-\\tau)$) and then looks like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/convolution-explain3.pdf}\n\\end{center}\nThen the integrand of convolution is the product $x_1(\\tau)x_2(t-\\tau)$ whose plot depends of the value of $t$. Some examples, where the individual signals are dashed and their product is in bold:\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/convolution-explain4.pdf}\n\\end{center}\nThen convolution is the total integral of the product (bold curves above) for that value of $t$. For the example above we see the integral will be zero for $t$ less than $t_0$ since the two signals do not overlap and their product is zero. For $t_0 < t < t_1$ the signals overap and the product is non-zero, and the effective bounds of integration are $[t_0,t]$. For $t > t_1$ the signals again overap and the product is non-zero, but the effective bounds of integration are $[t_0,t_1]$. \n\n\\section{Examples of CT Convolution}\n\n\\begin{example}[$u(t) * u(t)$] Consider the convolution of two unit step functions.\n  \\[\n  u(t) * u(t) = \\int\\limits_{-\\infty}^{\\infty} u(\\tau)u(t-\\tau) \\; d\\tau\n  \\]\n  The product $u(\\tau) u(t-\\tau)$ is non-zero only when $t\\geq 0$ as illustrated here\n  \\begin{center}\n  \\includegraphics[scale=1]{graphics/convolution-step.pdf}\n\\end{center}\n  The convolution integral is then the shaded area\n  \\[\nu(t) * u(t) = \\left\\{ \\begin{array}{lc}\n  0 & t< 0\\\\\n  \\int\\limits_{0}^{t} d\\tau = t  & t \\geq 0\\\\\n\\end{array}\\right.\n\\]\nCombining this back into a single expression gives:\n\\[\nu(t) * u(t) = tu(t)\n\\]\nThus the convolution of two step signals is a ramp signal.\\\\$\\blacksquare$\n\\end{example}\n\n\\begin{example}[$u(t) * e^{-at}u(t)$] Let $x_1(t) = u(t)$ and $x_2(t) = e^{-at}u(t)$ for constant $a\\in\\mathbb{C}$, then\n  \\[\nu(t) * e^{-at}u(t) = \\int\\limits_{-\\infty}^{\\infty} u(\\tau)e^{-a(t-\\tau)}u(t-\\tau) \\; d\\tau\n\\]\nSimilar to the previous example, the product $u(\\tau) e^{-a(t-\\tau)} u(t-\\tau)$ is non-zero only when $t\\geq 0$\n  \\begin{center}\n  \\includegraphics[scale=1]{graphics/convolution-expstep.pdf}\n  \\end{center}\n  The convolution integral is then the shaded area\n  \\[\nu(t) * e^{-at}u(t) = \\left\\{ \\begin{array}{lc}\n  0 & t< 0\\\\\n  \\int\\limits_{0}^{t} e^{-a(t-\\tau)} d\\tau = \\frac{1-e^{-at}}{a}  & t \\geq 0\\\\\n\\end{array}\\right.\n\\]\nCombining this back into a single expression gives:\n\\[\nu(t) * e^{-at}u(t) = \\frac{1-e^{-at}}{a}u(t)\n\\]\n$\\blacksquare$\n\\end{example}\n\n\\begin{example}[Convolution with a delta function] Let $x_1(t) = \\delta(t)$ and $x_2(t)$ be an arbitrary signal. Then\n  \\[\n  \\delta(t) * x_2(t) = \\int\\limits_{-\\infty}^{\\infty} \\delta(\\tau)x_2(t-\\tau) \\; d\\tau\n  \\]\n  By the sifting property of the delta function this evaluates to\n  \\[\n  \\delta(t) * x_2(t) = x_2(t)\n  \\]\n  or in other words convolution with a delta function just results in the signal it was convolved with. That is it acts like the identity function, with respect to convolution.\\\\\n  $\\blacksquare$\n\\end{example}\n\nThe following table lists several convolution results.\n\n\\begin{center}\n  Short Table of Representative Convolution Integrals\n  \\vspace{1em}\n  \n\\bgroup\n\\def\\arraystretch{2}\n\\setlength\\tabcolsep{2em}\n\\begin{tabular}{|c|c|c|}\n  \\hline\n  $x_1(t)$ & $x_2(t)$ & $x_1(t) * x_2(t)$\\\\\n  \\hline\n  \\hline\n  $e^{a t}u(t)$ & $u(t)$ & $\\frac{1-e^{a t}}{-a}u(t)$\\\\\n  $u(t)$ & $u(t)$ & $tu(t)$\\\\\n  $e^{a_1 t}u(t)$ & $e^{a_2 t}u(t)$ & $\\frac{e^{a_1 t}-e^{a_2 t}}{a_1 - a_2}u(t)$ for $a_1 \\neq a_2$\\\\\n  $e^{a t}u(t)$ & $e^{a t}u(t)$ & $te^{a t}u(t)$\\\\\n  $te^{a_1 t}u(t)$ & $e^{a_2 t}u(t)$ & $\\frac{e^{a_2 t}-e^{a_1 t} + (a_1-a_2)te^{a_1 t}}{(a_1 - a_2)^2}u(t)$ for $a_1 \\neq a_2$\\\\\n  $e^{a_1 t}\\cos(\\beta t + \\theta)u(t)$ & $e^{a_2 t}u(t)$ & $\\frac{\\cos(\\theta - \\phi)e^{a_2 t} - e^{a_1 t}\\cos(\\beta t + \\theta - \\phi)}{\\sqrt{(a_1 + a_2)^2 + \\beta^2}}u(t)$\\\\\n  & & $\\phi = \\arctan\\left( \\frac{-\\beta}{a_1 + a_2}\\right)$\\\\\n\\hline                       \n\\end{tabular}\n\\egroup\n\n\\end{center}\n\n\\section{Properties of CT Convolution}\nThere are several useful properties of convolution. We do not prove these here, but it is not terribly difficult to do so. Given signals $x_1(t)$, $x_2(t)$, and $x_3(t)$:\n\n\\begin{description}\n\\item [Communative Property] The ordering of the signals does not matter.\n  \\[\nx_1(t) * x_2(t) = x_2(t) * x_1(t)\n  \\]\n\\item [Distributive Propery] Convolution is distributed over addition.\n  \\[\n  x_1(t) * \\left[x_2(t) + x_3(t)\\right] = \\left[x_1(t) * x_2(t) \\right] + \\left[x_1(t) * x_3(t) \\right] \n  \\]\n\\item [Associative Property] The order of convolution does not matter.\n    \\[\n  x_1(t) * \\left[x_2(t) * x_3(t)\\right] = \\left[x_1(t) * x_2(t) \\right] * x_3(t) \n  \\]\n\\item [Time Shift] Given $x_3(t) = x_1(t) * x_2(t)$ then for time shifts $\\tau_1, \\tau_2 \\in \\mathbb{R}$\n  \\[\n  x_1(t-\\tau_1) * x_2(t-\\tau_2) = x_3(t-\\tau_1 - \\tau_2)\n  \\]\n\\item [Multiplicative Scaling] Given $x_3(t) = x_1(t) * x_2(t)$ then for constants $a,b \\in \\mathbb{C}$\n  \\[\n  \\left[a\\, x_1(t)\\right] * \\left[b\\, x_2(t)\\right] = a\\, b\\, x_3(t)\n  \\]\n\\end{description}\n\nThese properties can be used in combination with a table like that above to compute the convolution of a wide variety of signals without evaluating the integrals.\n\n\\begin{example} Here is a simple example. Let $x_1(t) = e^tu(t)$ and $x_2(t) = 2\\delta(t) + 5e^{-3t}u(t)$.\n  \\[\n  x_1(t) * x_2(t) =  e^tu(t) * \\left[2\\delta(t) + 5e^{-3t}u(t)\\right] \n  \\]\n  Using the distributive property\n  \\[\n  x_1(t) * x_2(t) =  2\\left[\\delta(t) * e^tu(t)\\right]  + 5\\left[e^tu(t) * e^{-3t}u(t)\\right]\n  \\]\n  Using previously derived results involving the delta function and the table row 3\n  \\[\n  x_1(t) * x_2(t) = 2 e^t\\, u(t) + 5\\left[ \\frac{e^t-e^{-3t}}{4}\\right]u(t)\n  \\]\n  Doing some simplification gives the result\n  \\[\n  x_1(t) * x_2(t) = \\left[ \\frac{13}{4}e^t-\\frac{5}{4}e^{-3t}\\right]u(t)\n  \\]\n  \n$\\blacksquare$\n\\end{example}\n\n\\begin{example} Here is a more complicated example. Let $x_1(t) = 2e^{-5t}u(t-1)$ and $x_2(t) = \\left(1-e^{-t}\\right)u(t)$.\n  \\[\n  x_1(t) * x_2(t) = \\left[2e^{-5t}u(t-1)\\right] * \\left[\\left(1-e^{-t}\\right)u(t)\\right]\n  \\]\n  We first rewrite $e^{-5t}u(t-1)=e^{-5}e^{-5(t-1)}u(t-1) = e^{-5}e^{-5t}u(t)\\Big|_{t=t-1}$ so that we can remove the time shift\n  \\[\n  x_1(t) * x_2(t) = 2e^{-5}\\left[e^{-5t}u(t)\\right] * \\left[\\left(1-e^{-t}\\right)u(t)\\right]\\Big|_{t=t-1}\n  \\]\n  We now apply the distributive property\n  \\[\nx_1(t) * x_2(t) = 2e^{-5}\\left[\\left(e^{-5t}u(t) * u(t)\\right) - \\left(e^{-5t}u(t)* e^{-t}u(t)\\right)\\right]\\Big|_{t=t-1}\n  \\]\n  Using the table rows 1 and 3 we get\n  \\[\n  x_1(t) * x_2(t) = 2e^{-5}\\left[\\frac{1}{5}\\left(1-e^{-5t}\\right)u(t) + \\frac{1}{4}\\left(e^{-5t} - e^{-t}\\right)u(t)\\right]\\Big|_{t=t-1}\n  \\]\n  Combining terms we simplify to\n  \\[\nx_1(t) * x_2(t) = 2e^{-5}\\left[\\frac{1}{5} - \\frac{1}{4}e^{-t} + \\frac{1}{20}e^{-5t} \\right]u(t)\\Big|_{t=t-1}\n\\]\nReplacing the time shift gives the final result\n\\[\nx_1(t) * x_2(t) = 2e^{-5}\\left[\\frac{1}{5} - \\frac{1}{4}e^{-(t-1)} + \\frac{1}{20}e^{-5(t-1)} \\right]u(t-1)\n\\]\nwhich can be cleaned up a bit more by distributing the leading term\n\\[\nx_1(t) * x_2(t) =\\left[\\frac{2}{5}e^{-5} -\\frac{1}{2}e^{-(t+4)} +\\frac{1}{10}e^{-5t}\\right]u(t-1)\n\\]\n  \n$\\blacksquare$\n\\end{example}\n\n", "meta": {"hexsha": "fb37ea93fdc2b4c39510546d6c20136646e90a9f", "size": 9906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "08-ct-conv.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": "08-ct-conv.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": "08-ct-conv.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": 41.4476987448, "max_line_length": 488, "alphanum_fraction": 0.6406218453, "num_tokens": 3774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255927, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.6661679336004487}}
{"text": "\\chapter{Cardinals}\nAn ordinal measures a total ordering.\nHowever, it does not do a fantastic job at measuring size.\nFor example, there is a bijection between the elements of $\\omega$ and $\\omega+1$:\n\\[\n\t\\begin{array}{rccccccc}\n\t\t\\omega+1 = & \\{ & \\omega & 0 & 1 & 2 & \\dots & \\} \\\\\n\t\t\\omega = & \\{ & 0 & 1 & 2 & 3 & \\dots & \\}.\n\t\\end{array}\n\\]\nIn fact, as you likely already know,\nthere is even a bijection between $\\omega$ and $\\omega^2$:\n\\[\n\t\\begin{array}{l|cccccc}\n\t\t+ & 0 & 1 & 2 & 3 & 4 & \\dots \\\\ \\hline\n\t\t0 & 0 & 1 & 3 & 6 & 10 & \\dots \\\\\n\t\t\\omega & 2 & 4 & 7 & 11 & \\dots & \\\\\n\t\t\\omega \\cdot 2 & 5 & 8 & 12 & \\dots & & \\\\\n\t\t\\omega \\cdot 3 & 9 & 13 & \\dots & & & \\\\\n\t\t\\omega \\cdot 4 & 14 & \\dots & & & &\n\t\\end{array}\n\\]\nSo ordinals do not do a good job of keeping track of size.\nFor this, we turn to the notion of a cardinal number.\n\n\\section{Equinumerous sets and cardinals}\n\\begin{definition}\n\tTwo sets $A$ and $B$ are \\vocab{equinumerous}, written $A \\approx B$,\n\tif there is a bijection between them.\n\\end{definition}\n\n\\begin{definition}\n\tA \\vocab{cardinal} is an ordinal $\\kappa$ such that\n\tfor no $\\alpha < \\kappa$ do we have $\\alpha \\approx \\kappa$.\n\\end{definition}\n\\begin{example}[Examples of cardinals]\n\tEvery finite number is a cardinal.\n\tMoreover, $\\omega$ is a cardinal.\n\tHowever, $\\omega+1$, $\\omega^2$, $\\omega^{2015}$ are not,\n\tbecause they are countable.\n\\end{example}\n\\begin{example}[$\\omega^\\omega$ is countable]\n\tEven $\\omega^\\omega$ is not a cardinal,\n\tsince it is a countable union\n\t\\[ \\omega^\\omega = \\bigcup_n \\omega^n \\]\n\tand each $\\omega^n$ is countable.\n\\end{example}\n\\begin{ques}\n\tWhy must an infinite cardinal be a limit ordinal?\n\\end{ques}\n\n\\begin{remark}\n\tThere is something fishy about the definition of a cardinal:\n\tit relies on an \\emph{external} function $f$.\n\tThat is, to verify $\\kappa$ is a cardinal I can't just look at $\\kappa$ itself;\n\tI need to examine the entire universe $V$ to make sure\n\tthere does not exist a bijection $f : \\kappa \\to \\alpha$ for $\\alpha < \\kappa$.\n\tFor now this is no issue, but later in model theory\n\tthis will lead to some highly counterintuitive behavior.\n\\end{remark}\n\n\\section{Cardinalities}\nNow that we have defined a cardinal, we can discuss the size\nof a set by linking it to a cardinal.\n\n\\begin{definition}\n\tThe \\vocab{cardinality} of a set $X$\n\tis the \\emph{least} ordinal $\\kappa$ such that $X \\approx \\kappa$.\n\tWe denote it by $\\left\\lvert X \\right\\rvert$.\n\\end{definition}\n\\begin{ques}\n\tWhy must $\\left\\lvert X \\right\\rvert$ be a cardinal?\n\\end{ques}\n\\begin{remark}\n\tOne needs the well-ordering theorem (equivalently, choice)\n\tin order to establish that such an ordinal $\\kappa$ actually exists.\n\\end{remark}\nSince cardinals are ordinals, it makes sense to ask whether $\\kappa_1 \\le \\kappa_2$,\nand so on.\nOur usual intuition works well here.\n\\begin{proposition}[Restatement of cardinality properties]\n\tLet $X$ and $Y$ be sets.\n\t\\begin{enumerate}[(i)]\n\t\t\\ii $X \\approx Y$ if and only $\\left\\lvert X \\right\\rvert = \\left\\lvert Y \\right\\rvert$,\n\t\tif and only if there's a bijection from $X$ to $Y$.\n\t\t\\ii $\\left\\lvert X \\right\\rvert \\le \\left\\lvert Y \\right\\rvert$\n\t\tif and only if there is an injective map $X \\injto Y$.\n\t\\end{enumerate}\n\\end{proposition}\nDiligent readers are invited to try and prove this.\n\n\\section{Aleph numbers}\n\\prototype{$\\aleph_0 = \\omega$, and $\\aleph_1$ is the first uncountable ordinal.}\nFirst, let us check that cardinals can get arbitrarily large:\n\\begin{proposition}\n\tWe have $\\left\\lvert X \\right\\rvert < \\left\\lvert \\PP(X) \\right\\rvert$ for every set $X$.\n\\end{proposition}\n\\begin{proof}\n\tThere is an injective map $X \\injto \\PP(X)$\n\tbut there is no injective map $\\PP(X) \\injto X$ by \\Cref{lem:cantor_diag}.\n\\end{proof}\n\nThus we can define:\n\\begin{definition}\n\tFor a cardinal $\\kappa$, we define $\\kappa^+$ to be the least cardinal above $\\kappa$,\n\tcalled the \\vocab{successor cardinal}.\n\\end{definition}\nThis $\\kappa^+$ exists and has $\\kappa^+ \\le \\left\\lvert \\PP(\\kappa) \\right\\rvert$.\n\nNext, we claim that:\n\\begin{exercise}\n\tShow that if $A$ is a set of cardinals, then $\\cup A$ is a cardinal.\n\\end{exercise}\n\nThus by transfinite induction we obtain that:\n\\begin{definition}\n\tFor any $\\alpha \\in \\On$, we define the \\vocab{aleph numbers} as\n\t\\begin{align*}\n\t\t\\aleph_0 &= \\omega \\\\\n\t\t\\aleph_{\\alpha+1} &= \\left( \\aleph_\\alpha \\right)^+ \\\\\n\t\t\\aleph_{\\lambda} &= \\bigcup_{\\alpha < \\lambda} \\aleph_\\alpha.\n\t\\end{align*}\n\\end{definition}\n\nThus we have the sequence of cardinals\n\\[\n\t0 < 1 < 2 < \\dots < \\aleph_0 < \\aleph_1 < \\dots < \\aleph_\\omega < \\aleph_{\\omega+1} < \\dots.\n\\]\nBy definition, $\\aleph_0$ is the cardinality of the natural numbers,\n$\\aleph_1$ is the first uncountable ordinal, \\dots.\n\nWe claim the aleph numbers constitute all the cardinals:\n\\begin{lemma}[Aleph numbers constitute all infinite cardinals]\n\tIf $\\kappa$ is a cardinal then\n\teither $\\kappa$ is finite (i.e.\\ $\\kappa \\in \\omega$) or\n\t$\\kappa = \\aleph_\\alpha$ for some $\\alpha \\in \\On$.\n\\end{lemma}\n\\begin{proof}\n\tAssume $\\kappa$ is infinite, and take $\\alpha$ minimal with $\\aleph_\\alpha \\ge \\kappa$.\n\tSuppose for contradiction that we have $\\aleph_\\alpha > \\kappa$.\n\tWe may assume $\\alpha > 0$, since the case $\\alpha = 0$ is trivial.\n\n\tIf $\\alpha = \\ol\\alpha + 1$ is a successor, then\n\t\\[ \\aleph_{\\ol\\alpha} < \\kappa < \\aleph_{\\alpha}\n\t\t= (\\aleph_{\\ol\\alpha})^+ \\]\n\twhich contradicts the definition of the successor cardinal.\n\t\n\tIf $\\alpha = \\lambda$ is a limit ordinal, then $\\aleph_\\lambda$ is the\n\tsupremum $\\bigcup_{\\gamma < \\lambda} \\aleph_\\gamma$.\n\tSo there must be some $\\gamma < \\lambda$ with $\\aleph_\\gamma > \\kappa$,\n\twhich contradicts the minimality of $\\alpha$.\n\\end{proof}\n\n\\begin{definition}\n\tAn infinite cardinal which is not a successor cardinal\n\tis called a \\vocab{limit cardinal}.\n\tIt is exactly those cardinals of the form $\\aleph_\\lambda$,\n\tfor $\\lambda$ a limit ordinal, plus $\\aleph_0$.\n\\end{definition}\n\n\n\\section{Cardinal arithmetic}\n\\prototype{$\\aleph_0 \\cdot \\aleph_0 = \\aleph_0 + \\aleph_0 = \\aleph_0$}\nRecall the way we set up ordinal arithmetic.\nNote that in particular, $\\omega + \\omega > \\omega$ and $\\omega^2 > \\omega$.\nSince cardinals count size, this property is undesirable, and\nwe want to have\n\\begin{align*}\n\t\\aleph_0 + \\aleph_0 &= \\aleph_0 \\\\\n\t\\aleph_0 \\cdot \\aleph_0 &= \\aleph_0\n\\end{align*}\nbecause $\\omega + \\omega$ and $\\omega \\cdot \\omega$ are countable.\nIn the case of cardinals, we simply ``ignore order''.\n\nThe definition of cardinal arithmetic is as expected:\n\\begin{definition}[Cardinal arithmetic]\n\tGiven cardinals $\\kappa$ and $\\mu$, define\n\t\\[ \\kappa + \\mu\n\t\t\\defeq\n\t\t\\left\\lvert \n\t\t\\left( \\left\\{ 0 \\right\\} \\times \\kappa \\right)\n\t\t\\cup\n\t\t\\left( \\left\\{ 1 \\right\\} \\times \\mu \\right)\n\t\t\\right\\rvert\n\t\\]\n\tand\n\t\\[\n\t\t\\kappa \\cdot \\mu\n\t\t\\defeq\n\t\t\\left\\lvert \\mu \\times \\kappa \\right\\rvert\n\t\t.\n\t\\]\n\\end{definition}\n\n\n\\begin{ques}\n\tCheck this agrees with what you learned in pre-school\n\tfor finite cardinals.\n\\end{ques}\n\n\\begin{abuse}\n\tThis is a slight abuse of notation since we are using\n\tthe same symbols as for ordinal arithmetic,\n\teven though the results are different ($\\omega \\cdot \\omega = \\omega^2$\n\tbut $\\aleph_0 \\cdot \\aleph_0 = \\aleph_0$).\n\tIn general, I'll make it abundantly clear whether I am talking\n\tabout cardinal arithmetic or ordinal arithmetic.\n\\end{abuse}\nTo help combat this confusion, we use separate symbols for ordinals and cardinals.\nSpecifically, $\\omega$ will always refer to $\\{0,1,\\dots\\}$ viewed as an ordinal;\n$\\aleph_0$ will always refer to the same set viewed as a cardinal.\nMore generally,\n\\begin{definition}\n\tLet $\\omega_\\alpha = \\aleph_\\alpha$ viewed as an ordinal.\n\\end{definition}\n\nHowever, as we've seen already we have that $\\aleph_0 \\cdot \\aleph_0 = \\aleph_0$.\nIn fact, this holds even more generally:\n\n\\begin{theorem}[Infinite cardinals squared]\n\tLet $\\kappa$ be an infinite cardinal.\n\tThen $\\kappa \\cdot \\kappa = \\kappa$.\n\\end{theorem}\n\\begin{proof}\n\tObviously $\\kappa \\cdot \\kappa \\ge \\kappa$,\n\tso we want to show $\\kappa \\cdot \\kappa \\le \\kappa$.\n\n\tThe idea is to try to repeat the same proof\n\tthat we had for $\\aleph_0 \\cdot \\aleph_0 = \\aleph_0$,\n\tso we re-iterate it here. We took the ``square'' of\n\telements of $\\aleph_0$, and then\n\t\\emph{re-ordered} it according to the diagonal:\n\t\\[\n\t\\begin{array}{l|cccccc}\n\t\t  & 0 & 1 & 2 & 3 & 4 & \\dots \\\\ \\hline\n\t\t0 & 0 & 1 & 3 & 6 & 10 & \\dots \\\\\n\t\t1 & 2 & 4 & 7 & 11 & \\dots & \\\\\n\t\t2 & 5 & 8 & 12 & \\dots & & \\\\\n\t\t3 & 9 & 13 & \\dots & & & \\\\\n\t\t4 & 14 & \\dots & & & &\n\t\\end{array}\n\t\\]\n\tWe'd like to copy this idea for a general $\\kappa$;\n\thowever, since addition is less well-behaved for infinite ordinals\n\tit will be more convenient to use $\\max\\{\\alpha,\\beta\\}$\n\trather than $\\alpha+\\beta$.\n\tSpecifically, we put the ordering $<_{\\text{max}}$\n\ton $\\kappa \\times \\kappa$ as follows:\n\tfor $(\\alpha_1, \\beta_1)$ and $(\\alpha_2, \\beta_2)$ in $\\kappa \\times \\kappa$\n\twe declare $(\\alpha_1, \\beta_1) <_{\\text{max}} (\\alpha_2, \\beta_2)$ if\n\t\\begin{itemize}\n\t\t\\ii $\\max \\left\\{ \\alpha_1, \\beta_1 \\right\\} < \\max \\left\\{ \\alpha_2, \\beta_2 \\right\\}$ or\n\t\t\\ii $\\max \\left\\{ \\alpha_1, \\beta_1 \\right\\} = \\max \\left\\{ \\alpha_2, \\beta_2 \\right\\}$ and $(\\alpha_1, \\beta_1)$\n\t\tis lexicographically earlier than $(\\alpha_2, \\beta_2)$.\n\t\\end{itemize}\n\tThis alternate ordering (which deliberately avoids referring\n\tto the addition) looks like:\n\t\\[\n\t\\begin{array}{l|cccccc}\n\t\t  & 0 & 1 & 2 & 3 & 4 & \\dots \\\\ \\hline\n\t\t0 & 0 & 1 & 4 & 9 & 16 & \\dots \\\\\n\t\t1 & 2 & 3 & 5 & 10 & 17 & \\dots \\\\\n\t\t2 & 6 & 7 & 8 & 11 & 18 & \\dots \\\\\n\t\t3 & 12 & 13 & 14 & 15 & 19 & \\dots \\\\\n\t\t4 & 20 & 21 & 22 & 23 & 24 & \\dots \\\\\n\t\t\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\ddots \\\\\n\t\\end{array}\n\t\\]\t\n\n\tNow we proceed by transfinite induction on $\\kappa$.\n\tThe base case is $\\kappa = \\aleph_0$, done above.\n\tNow, $<_{\\text{max}}$ is a well-ordering of $\\kappa \\times \\kappa$,\n\tso we know it is in order-preserving bijection with some ordinal $\\gamma$.\n\tOur goal is to show that $\\left\\lvert \\gamma \\right\\rvert \\le \\kappa$.\n\tTo do so, it suffices to prove that for any $\\ol\\gamma \\in \\gamma$,\n\twe have $\\left\\lvert \\ol\\gamma \\right\\rvert < \\kappa$.\n\n\tSuppose $\\ol\\gamma$ corresponds to the point $(\\alpha, \\beta) \\in \\kappa \\times \\kappa$\n\tunder this bijection.\n\tIf $\\alpha$ and $\\beta$ are both finite\n\tthen certainly $\\ol\\gamma$ is finite too.\n\tOtherwise, let $\\ol\\kappa = \\max \\{\\alpha, \\beta\\} < \\kappa$;\n\tthen the number of points below $\\ol\\gamma$ is at most\n\t\\[ \n\t\t\\left\\lvert \\alpha \\right\\rvert \\cdot \\left\\lvert \\beta \\right\\rvert\n\t\t\\le \\ol\\kappa \\cdot \\ol\\kappa\n\t\t= \\ol\\kappa\n\t\\]\n\tby the inductive hypothesis.\n\tSo $\\left\\lvert \\ol\\gamma \\right\\rvert \\le \\ol\\kappa < \\kappa$ as desired.\n\\end{proof}\n\nFrom this it follows that cardinal addition and multiplication is really boring:\n\\begin{theorem}[Infinite cardinal arithmetic is trivial]\n\tGiven cardinals $\\kappa$ and $\\mu$,\n\tone of which is infinite, we have\n\t\\[ \\kappa \\cdot \\mu = \\kappa + \\mu\n\t= \\max\\left\\{ \\kappa, \\mu \\right\\}.\\]\n\\end{theorem}\n\\begin{proof}\n\tThe point is that both of these are less than the square of the maximum.\n\tWriting out the details:\n\t\\begin{align*}\n\t\t\\max \\left\\{ \\kappa, \\mu \\right\\}\n\t\t&\\le \\kappa + \\mu \\\\\n\t\t&\\le \\kappa \\cdot \\mu \\\\\n\t\t&\\le \\max \\left\\{ \\kappa, \\mu \\right\\}\n\t\t\t\\cdot \\max \\left\\{ \\kappa, \\mu  \\right\\} \\\\\n\t\t&= \\max\\left\\{ \\kappa, \\mu \\right\\}. \\qedhere\n\t\\end{align*}\n\\end{proof}\n\n\n\n\n\\section{Cardinal exponentiation}\n\\prototype{$2^\\kappa = \\left\\lvert \\PP(\\kappa) \\right\\rvert$.}\n\\begin{definition}\n\tSuppose $\\kappa$ and $\\lambda$ are cardinals.\n\tThen\n\t\\[ \\kappa^\\lambda\n\t\t\\defeq \\left\\lvert \\mathscr F(\\lambda, \\kappa) \\right\\rvert.\n\t\\]\n\tHere $\\mathscr F(A,B)$ is the set of functions from $A$ to $B$.\n\\end{definition}\n\n\\begin{abuse}\n\tAs before, we are using the same notation for\n\tboth cardinal and ordinal arithmetic. Sorry!\n\\end{abuse}\n\nIn particular, $2^\\kappa = \\left\\lvert \\PP(\\kappa) \\right\\rvert > \\kappa$,\nand so from now on we can use the notation $2^\\kappa$ freely.\n(Note that this is totally different from ordinal arithmetic;\nthere we had $2^\\omega = \\bigcup_{n\\in\\omega} 2^n = \\omega$.\nIn cardinal arithmetic $2^{\\aleph_0} > \\aleph_0$.)\n\nI have unfortunately not told you what $2^{\\aleph_0}$ equals.\nA natural conjecture is that $2^{\\aleph_0} = \\aleph_1$; this is called the\n\\vocab{Continuum Hypothesis}.\nIt turns out that this is \\emph{undecidable} -- it is not possible\nto prove or disprove this from the $\\ZFC$ axioms.\n\n\\section{Cofinality}\n\\prototype{$\\aleph_0$, $\\aleph_1$, \\dots\\ are all regular, but $\\aleph_\\omega$ has cofinality $\\omega$.}\n\n\\begin{definition}\n\tLet $\\lambda$ be an ordinal (usually a limit ordinal),\n\tand $\\alpha$ another ordinal.\n\tA map $f : \\alpha \\to \\lambda$ of ordinals is called \\vocab{cofinal}\n\tif for every $\\ol\\lambda < \\lambda$, there is some $\\ol\\alpha \\in \\alpha$\n\tsuch that $f(\\ol\\alpha) \\ge \\ol\\lambda$.\n\tIn other words, the map reaches arbitrarily high into $\\lambda$.\n\\end{definition}\n\\begin{example}\n\t[Example of a cofinal map]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The map $\\omega \\to \\omega^\\omega$ by $n \\mapsto \\omega^n$ is cofinal.\n\t\t\\ii For any ordinal $\\alpha$, the identity map $\\alpha \\to \\alpha$ is cofinal.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}\n\tLet $\\lambda$ be a limit ordinal.\n\tThe \\vocab{cofinality} of $\\lambda$, denoted $\\cof(\\lambda)$,\n\tis the smallest ordinal $\\alpha$ such that there is a cofinal map\n\t$\\alpha \\to \\lambda$.\n\\end{definition}\n\\begin{ques}\n\tWhy must $\\alpha$ be an infinite cardinal?\n\\end{ques}\n\nUsually, we are interested in taking the cofinality of a cardinal $\\kappa$.\n\nPictorially, you can imagine standing at the bottom of the universe and looking\nup the chain of ordinals to $\\kappa$.\nYou have a machine gun and are firing bullets upwards, and you want to get arbitrarily\nhigh but less than $\\kappa$.\nThe cofinality is then the number of bullets you need to do this.\n\nWe now observe that ``most'' of the time, the cofinality of a cardinal is itself.\nSuch a cardinal is called \\vocab{regular}.\n\\begin{example}[$\\aleph_0$ is regular]\n\t$\\cof(\\aleph_0) = \\aleph_0$, because no finite subset of\n\t$\\aleph_ 0 = \\omega$ can reach arbitrarily high.\n\\end{example}\n\\begin{example}[$\\aleph_1$ is regular]\n\t$\\cof(\\aleph_1) = \\aleph_1$.\n\tIndeed, assume for contradiction that some countable\n\tset of ordinals $A = \\{ \\alpha_0, \\alpha_1, \\dots \\} \\subseteq \\aleph_1$\n\treaches arbitrarily high inside $\\aleph_1$.\n\tThen $\\Lambda = \\cup A$ is a \\emph{countable} ordinal,\n\tbecause it is a countable union of countable ordinals.\n\tIn other words $\\Lambda \\in \\aleph_1$.\n\tBut $\\Lambda$ is an upper bound for $A$, contradiction.\n\\end{example}\nOn the other hand, there \\emph{are} cardinals which are not regular;\nsince these are the ``rare'' cases we call them \\vocab{singular}.\n\\begin{example}[$\\aleph_\\omega$ is not regular]\n\tNotice that $\\aleph_0 < \\aleph_1 < \\aleph_2 < \\dots$ reaches\n\tarbitrarily high in $\\aleph_\\omega$, despite only having $\\aleph_0$ terms.\n\tIt follows that $\\cof(\\aleph_\\omega) = \\aleph_0$.\n\\end{example}\n\nWe now confirm a suspicion you may have:\n\\begin{theorem}\n\t[Successor cardinals are regular]\n\tIf $\\kappa = \\ol\\kappa^+$ is a successor cardinal,\n\tthen it is regular.\n\\end{theorem}\n\\begin{proof}\n\tWe copy the proof that $\\aleph_1$ was regular.\n\n\tAssume for contradiction that for some $\\mu \\le \\ol\\kappa$,\n\tthere are $\\mu$ sets reaching arbitrarily high in $\\kappa$ as a cardinal.\n\tObserve that each of these sets must have cardinality at most $\\ol\\kappa$.\n\tWe take the union of all $\\mu$ sets, which gives an ordinal $\\Lambda$\n\tserving as an upper bound.\n\n\tThe number of elements in the union is at most\n\t\\[ \\#\\text{sets} \\cdot \\#\\text{elms}\n\t\t\\le \\mu \\cdot \\ol\\kappa = \\ol\\kappa \\]\n\tand hence $\\left\\lvert \\Lambda \\right\\rvert \\le \\ol\\kappa < \\kappa$.\n\\end{proof}\n\n\\section{Inaccessible cardinals}\nSo, what about limit cardinals?\nIt seems to be that most of them are singular: if $\\aleph_\\lambda \\ne \\aleph_0$ is a limit ordinal,\nthen the sequence $\\{\\aleph_\\alpha\\}_{\\alpha \\in \\lambda}$ (of length $\\lambda$) is certainly cofinal.\n\n\\begin{example}[Beth fixed point]\n\tConsider the monstrous cardinal\n\t\\[ \\kappa = \\aleph_{\\aleph_{\\aleph_{\\ddots}}}. \\]\n\tThis might look frighteningly huge, as $\\kappa = \\aleph_\\kappa$,\n\tbut its cofinality is $\\omega$ as it is the limit of the sequence\n\t\\[ \\aleph_0, \\aleph_{\\aleph_0}, \\aleph_{\\aleph_{\\aleph_0}}, \\dots \\]\n\\end{example}\n\nMore generally, one can in fact prove that\n\\[ \\cof(\\aleph_\\lambda) = \\cof(\\lambda). \\]\nBut it is actually conceivable that $\\lambda$ is so large\nthat $\\left\\lvert \\lambda \\right\\rvert = \\left\\lvert \\aleph_\\lambda \\right\\rvert$.\n\nA regular limit cardinal other than $\\aleph_0$ has a special name: it is \\vocab{weakly inaccessible}.\nSuch cardinals are so large that it is impossible to prove or disprove their existence in $\\ZFC$.\nIt is the first of many so-called ``large cardinals''.\n\nAn infinite cardinal $\\kappa$ is a strong limit cardinal if\n\\[ \\forall \\ol\\kappa < \\kappa \\quad 2^{\\ol\\kappa} < \\kappa \\]\nfor any cardinal $\\ol\\kappa$.  For example, $\\aleph_0$ is a strong limit cardinal.\n\\begin{ques}\n\tWhy must strong limit cardinals actually be limit cardinals?\n\t(This is offensively easy.)\n\\end{ques}\nA regular strong limit cardinal other than $\\aleph_0$\nis called \\vocab{strongly inaccessible}.\n\n\\section\\problemhead\n\\begin{problem}\n\tCompute $\\left\\lvert V_\\omega \\right\\rvert$.\n\t\\begin{hint}\n\t\t$\\sup_{k \\in \\omega} \\left\\lvert V_k \\right\\rvert$.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tProve that for any limit ordinal $\\alpha$, $\\cof(\\alpha)$ is a \\emph{regular} cardinal.\n\t\\begin{hint}\n\t\tRearrange the cofinal maps to be nondecreasing.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{sproblem}\n\t[Strongly inaccessible cardinals]\n\t\\label{prob:strongly_inaccessible}\n\tShow that for any strongly inaccessible $\\kappa$,\n\twe have $\\left\\lvert V_\\kappa \\right\\rvert = \\kappa$.\n\\end{sproblem}\n\n\\begin{problem}\n\t[K\\\"onig's theorem]\n\tShow that \\[ \\kappa^{\\cof(\\kappa)} > \\kappa \\] for every infinite cardinal $\\kappa$.\n\\end{problem}\n", "meta": {"hexsha": "08aca7bd4450bea184514148dbae852d5a035bb4", "size": 18020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/set-theory/cardinal.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/cardinal.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/cardinal.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.1546391753, "max_line_length": 115, "alphanum_fraction": 0.6882352941, "num_tokens": 5986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.8824278741843883, "lm_q1q2_score": 0.6661580367829096}}
{"text": "\n\\subsection{Geodesics}\n\nHow do we have straight line on a curve? eg going round equator, but not going via uk.\n\nTake start direction and find tangent vectors. geodesic is where tangent vectors stay parallel.\n\n", "meta": {"hexsha": "87b75c437495f98ada2911462f568ee8e37df0b9", "size": 210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsRiemann/03-05-geodesic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsRiemann/03-05-geodesic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsRiemann/03-05-geodesic.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.25, "max_line_length": 95, "alphanum_fraction": 0.7857142857, "num_tokens": 48, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6661580212161214}}
{"text": "\\subsection{Markov Logic networks (MLNs)}\nMarkov Logic networks \\cite{markovLogicNetworks} are defined as a collection of first order logical formulas \\(F_j\\) (for \\(j\\in 1\\ldots K\\)), each associated with a real number \\(w_j\\), the {\\em weight} of the rule. Assume given a set of constants \\(\\{c_1,\\ldots, c_L\\}\\) (in a 1-1 relationship with intended domain of interpretation), and \\(a_1,\\ldots, a_N\\), an enumeration of the ground atoms (built from the given constants and the predicates in the formulas). Then the joint probability of the network given the truth values \\(X_1, \\ldots, X_n\\) (for the ground atoms \\(a_i\\)) is given by:\n\\[ joint(X_1,\\ldots, X_n)= (1/Z)\\times \\prod_{F_j} e^{w_j n_j}\n\\]\n\\noindent where \\(n_j\\) is the number of true groundings of \\(F_j\\) for the given assignment. \\(Z\\) is the normalization factor.\n\nWe can represent this MLN as a PCC agent \\mcode{joint(X1,...,Xn)} using an interpreter for quantifier-free first-order formulas written in CCP (see the agent {\\tt v/2}). \nFor any formula \\(F_i\\) let \\(F_i^1, \\ldots, F_i^{p_i}\\) enumerate its \\(p_i\\) groundings. For any ground formula \\(F\\), let \\([F]\\) stand for the formula obtained by replacing each occurrence of \\(a_k\\) by the variable \\(X_k\\) (for all \\(k\\)). \n\nThe predicate \\mcode{joint/n} has a single rule with \\(n+2\\times\\Pi_{j\\in 1\\ldots K} p_j\\) atoms in the body. The \\(n\\) \\mcode{b(Xi)} agents each probabilistically guess the value of \\mcode{Xi} (drawn from the domain \\mcode{\\{true,false\\}}. Thus computation will result in one probabilistic branch for each of these valuations, each with a probability factor of \\(0.5^{n}\\) contributed by the \\mcode{b/1} agents (hence these factors will get normalized out). The subsquent pairs of agents force a a value for \\(\\mbox{\\tt Y}_{\\mbox{\\tt i}}^{\\mbox{\\tt j}}\\) (for {\\tt i} ranging from {\\tt 1} to {\\tt K} and for {\\tt j} ranging from {\\tt 1} to \\(\\mbox{\\tt p}_{\\mbox{\\tt i}}\\) ) by evaluating the formula \\(\\mbox{\\tt [F}_{\\mbox{\\tt i}}^{\\mbox{\\tt j}}\\mbox{\\tt ]}\\) (for the given valuation provided by \\(\\mbox{\\tt X}_{\\mbox{\\tt i}}\\)), and contribute a probability factor for this choice. \n\\begin{lstlisting}[mathescape=true]\njoint(X$_1,\\ldots, $X$_n$) ->\n  b(X$_1$), ..., b(X$_n$),\n  Y$_1^1 \\sim $ true/exp(w$_1$)+ false/1, v([F$_1^1$],Y$^1_1$),\n  ...,\n  Y$_1^{p_1}\\sim$ true/exp(w$_1$)+ false/1 , v([F$_1^{p_1}$],Y$_{p_1}^1$),\n  ...,\n  Y$_K^1\\sim$ true/exp(w$_K$)+ false/1,  v([F$_K^1$],Y$_K^1$)\n  ...,\n  Y$_K^{p_K}\\sim$ true/exp(w$_K$)+ false/1,  v([F$_K^{p_k}$],Y$_K^{p_K}$),\n\t\nb(X) -> X$\\sim$true/0.5 + false/0.5.\n\\end{lstlisting}\n\\noindent Note that the variables \\(\\mbox{\\tt Y}_{\\mbox{\\tt i}}\\) are local to the body (existentially quantified).\n\nThe valuation predicate {\\tt v/2} is straightforward to define -- it simply evaluates the first argument based on the values of the \\(\\mbox{\\tt X}_{\\mbox{\\tt i}}\\) supplied at the leaves, using standard CCP idioms.\n\\begin{lstlisting}[mathescape=true]\nv(and(A,B),V) -> v(A,VA), v(B,VB), and(VA,VB,V).\nv(or(A,B),V) -> v(A,VA), v(B,VB), or(VA,VB,V).\nv(not(A),V) -> v(A, VA), not(VA,V).\nv(v(X),V) -> X=V.\nand(false, \\_, Y) -> Y=false.\nand(\\_, false, Y) -> Y=false.\nand(true,true,Y) -> Y=true.\nor(true, \\_, Y) -> Y=true.\nor(\\_, true, Y) -> Y=true.\nor(false,false,Y) -> Y=false.\nnot(true,Y) -> Y=false.\nnot(false,Y)->Y=true.\n\\end{lstlisting}\n\n\\begin{example}\\label{ex_mln}\nFollowing the example given by Richardson et al. \\cite{markovLogicNetworks}, we consider the following three formulas $F_1$, $F_2$ and $F_3$: \\emph{``Smoking causes cancer''} $F_1=\\neg sm(X) \\vee ca(X)$ with weight $w_1=1.5$; \n\\emph{``If two people are friends, either both smoke or neither does''} $F_2 = \\neg fr(X, Y) \\vee sm(X) \\vee \\neg sm(Y)$ and $F_3= \\neg fr(X, Y) \\vee \\neg sm(X) \\vee sm(Y) $ with weights $w_2=w_3=1.1$.\n\\begin{figure}[h!]\n\\centering\n\\begin{tikzpicture}[scale=0.53]\n\\scriptsize\n\\tikzstyle{every node}=[draw,shape=ellipse,fill=gray!30];\n\\node (x1) at (0, 2) {$fr(a,a)$};\n\\node (x2) at (2, 0) {$ca(a)$};\n\\node (x3) at (4, 2) {$sm(a)$};\n\\node (x4) at (6, 0) {$fr(b,a)$};\n\\node (x5) at (6, 4) {$fr(a,b)$};\n\\node (x6) at (8, 2) {$sm(b)$};\n\\node (x7) at (10, 0) {$ca(b)$};\n\\node (x8) at (12, 2) {$fr(b,b)$};\n\\draw [-]  (x1) -- (x3);\n\\draw [-]  (x2) -- (x3);\n\\draw [-]  (x3) -- (x4);\n\\draw [-]  (x3) -- (x5);\n\\draw [-]  (x3) -- (x6);\n\\draw [-]  (x6) -- (x8);\n\\draw [-]  (x6) -- (x7);\n\\draw [-]  (x6) -- (x4);\n\\draw [-]  (x6) -- (x5);\n%\\coordinate [label=right:$c_1$] (p) at (5.5,2.8);\n%\\coordinate [label=right:$c_2$] (p) at (5.5,1.3);\n%\\coordinate [label=right:$c_3$] (p) at (1.6,2.3);\n%\\coordinate [label=right:$c_4$] (p) at (2.2,1.2);\n%\\coordinate [label=right:$c_6$] (p) at (8.6,1.2);\n%\\coordinate [label=right:$c_5$] (p) at (9.3,2.3);\n\\end{tikzpicture}\n\\caption{MLN of Example \\ref{ex_mln}}\n\\label{mln}\n\\end{figure}\nIn Figure \\ref{mln} we can see the graph of the ground Markov network defined by formulas $F_1$, $F_2$ and $F_3$ and the constants \\emph{Anna} ($a$) and \\emph{Bob} ($b$).\n\n\nThe equivalent PCC agent is defined as follows. Assume the ground atomic formulas are enumerated as:\n\\lstinline|fr(a,b)|,\n\\lstinline|fr(a,a)|,\n\\lstinline|sm(a)|,\n\\lstinline|sm(b)|,\n\\lstinline|fr(b,b)|,\n\\lstinline|ca(a)|,\n\\lstinline|fr(b,a)| and\n\\lstinline|ca(b)|. Then we have:\n\\begin{lstlisting}[mathescape=true]\njoint(X$_1$,...,X$_8$) $\\rightarrow$ \n  b(X$_1$), ... , b(X$_8$),\n  Y$_1^1$$\\sim$ true/e$^{w_1}$+ false/1, \n  v(or(not(X$_3$), X$_6$),Y$_1^1$),\n  Y$_1^2$$\\sim$ true/e$^{w_1}$+ false/1, \n  v(or(not(X$_4$), X$_8$),Y$_1^2$),\t\n  Y$_2^1$$\\sim$ true/e$^{w_2}$+ false/1,\n  v(or(not(X$_1$),or(X$_3$, not(X$_4$)),Y$_2^1$),\n  Y$_2^2$$\\sim$ true/e$^{w_2}$+ false/1,\n  v(or(not(X$_2$),or(X$_3$, not(X$_3$)),Y$_2^2$),\n  Y$_2^3$$\\sim$ true/e$^{w_2}$+ false/1,\n  v(or(not(X$_5$),or(X$_4$, not(X$_4$)),Y$_2^3$),\n  Y$_2^4$$\\sim$ true/e$^{w_2}$+ false/1,\n  v( or(not(X$_7$),or(X$_4$, not(X$_3$)),Y$_2^4$),\n  Y$_3^1$$\\sim$ true/e$^{w_3}$+ false/1,\n  v(or(not(X$_1$),or(not(X$_3$), X$_4$)),Y$_3^1$),\n  Y$_3^2$$\\sim$ true/e$^{w_3}$+ false/1,\n  v(or(not(X$_2$),or(not(X$_3$), X$_3$)),Y$_3^2$),\n  Y$_3^3$$\\sim$ true/e$^{w_3}$+ false/1,\n  v(or(not(X$_5$),or(not(X$_4$), X$_4$)),Y$_3^3$),\t\n  Y$_3^4$$\\sim$ true/e$^{w_3}$+ false/1, \n  v(or(not(X$_7$),or(not(X$_4$), X$_3$)),Y$_3^4$).\n\\end{lstlisting}\n\\end{example}\n\n\nIt is important to notice that the PCC representation of a MLN has un-normalised weights for its random variables. It is easy to find a normalisation constant that allow to recover the original MLN probability distribution over complete truth assignment of the variables (corresponding to successful executions of the PCC agent) since in the PCC formulation the probability of an execution is the product of the probability over the full set of variables (in each execution we sample all the random variables). So we consider a random variable of the form:\n\\begin{lstlisting}[mathescape=true]\nY$_i^j$$\\sim$ true/e$^{w_i}$+false/e$^0$\n\\end{lstlisting}\nas:\n\\begin{lstlisting}[mathescape=true]\nY$_i^j$ $\\sim$ true/$\\frac{e^{w_i}}{e^{w_i}+e^0 }$+false/$\\frac{e^0}{e^{w_i}+e^0 }$\n\\end{lstlisting}\n and at the end of the computation we multiply every execution probability for the following normalisation constant:\n $$Z=\\prod_{i=1}^k \\prod_{j=1}^{p_i} (e^{w_i} +e^0)=\\prod_{i=1}^k (e^{w_i} +e^0)^{p_i}$$\n\n\n\n\n\n\n\\begin{theorem}\nGiven a MLN $\\mathcal{M}$ defined over a set of clauses $F_j$ and its PCC translation $\\mathcal{P}$ \nthe probability distribution $pd_{\\mathcal{M}}$ defined by $\\mathcal{M}$ over the complete truth assignments of the ground atoms  is equal to the probability distribution $pd_{\\mathcal{P}}$ defined by $\\mathcal{P}$ over the complete truth assignments of the ground atoms.\n\\end{theorem}\n\\begin{proof}\nGiven a input $x_1, \\ldots ,x_n$ where $x_1, \\ldots , x_n$ are the truth values of the ground atoms $a_1,\\ldots, a_n$ generated by the MLN, we want to prove that the probability of $pd_{\\mathcal{P}}$ is equal to $pd_{\\mathcal{M}}$ on this input. Given the definition of MLN, we have that $pd_{\\mathcal{M}}(x_1, \\ldots ,x_n)=\\prod_{F_j} e^{w_j n_j}$.\n\nEach execution of the PCC agent provide a complete instantiation of the variables $Y_i^j$ by definition of the predicate $jt$. We have thus that the truth value of each grounding formula $[F]_i^j$ is defined: \\lstinline[mathescape=true]{v([F]$_i^j$,Y$_i^j$)}. \n\nThe probability of such combination (and the corresponding execution) is the product of the factors associated with each choice: we have a factor $e^{w_i}$ for each \\lstinline[mathescape=true]{v([F]$_i^j$,true)} used and $1$ for each \\lstinline[mathescape=true]{v([F]$_i^j$,false)} used. Only one of these combinations will succeed, since the input $x_1, \\ldots ,x_n$ determines uniquely only one consistent instantiation of the $[F]_i^j$. \nThus there is only one sampling execution that will succeeds, since every input $x_1,\\ldots,x_N$ is consistent with only one instantiation of the $[F]_i^j$.\n\\end{proof}\n\n%We can define a the same encoding of MLNs in PCCs also in SLPs with minor modifications that we omit due to lack of space. It is important to notice that the SLP formalisation of MLN corresponds to an un-normalised and impure SLP program: un-normalised because the sum of the weights for clauses whose heads share the same predicate could be greater than $1$, and impure since there are rules that don't have a weight.\n\n", "meta": {"hexsha": "0f5c53c4f706bf2390a3c6a6676f2ccb5abcf6aa", "size": 9351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/pcc-properties/MLN.tex", "max_stars_repo_name": "saraswat/pcc", "max_stars_repo_head_hexsha": "623629a9ab830170be1eb8d8fb80c1e9f39b32d2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-08-04T20:12:00.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-19T20:40:46.000Z", "max_issues_repo_path": "doc/pcc-properties/MLN.tex", "max_issues_repo_name": "saraswat/pcc", "max_issues_repo_head_hexsha": "623629a9ab830170be1eb8d8fb80c1e9f39b32d2", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-04-11T11:27:00.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-11T11:27:28.000Z", "max_forks_repo_path": "doc/pcc-properties/MLN.tex", "max_forks_repo_name": "saraswat/pcc", "max_forks_repo_head_hexsha": "623629a9ab830170be1eb8d8fb80c1e9f39b32d2", "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": 63.612244898, "max_line_length": 885, "alphanum_fraction": 0.6585391937, "num_tokens": 3416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251362048962, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6660653450483415}}
{"text": "\\documentclass{article}\n\\usepackage{geometry}\n\\usepackage{amsmath, amsfonts, amsthm, amssymb}\n\n\\title{Exercises and Solutions for \\textbf{An Introduction to Stochastic Differential Equations}}\n\\author{Zehao Dou}\n\\date{September 2021}\n\n\\begin{document}\n\\allowdisplaybreaks[4]\n\\maketitle\n\n\\newpage\n\\paragraph{Problem 1} Show, using the formal manipulations for Ito's chain rule, that\n\\[Y(t) := e^{W(t)-\\frac{t}{2}}\\]\nsolves the stochastic differential equation\n\\begin{equation*}\n\\begin{cases}\ndY &= YdW\\\\\nY(0) &= 1.\n\\end{cases} \n\\end{equation*}\n(Hint: If $X(t):=W(t)-\\frac{t}{2}$, then $dX=-\\frac{dt}{2}+dW$.)\n\n\\paragraph{Solution of Problem 1}\nAccording to the Ito's chain rule: since function $X(t):=W(t)-\\frac{t}{2}$ satisfies the equation $X(t)=-\\frac{dt}{2}+dW$, for $Y(t)=\\exp(X(t))$, it holds that:\n\\[dY=\\left(e^{X}\\cdot\\left(-\\frac{1}{2}\\right)+\\frac12\\cdot e^{X}\\right)dt+e^{X}dW= 0+YdW=YdW.\\]\nAlso, it's easy to verify that $Y(0)=1$. Therefore, the solution\n\\[Y(t) := e^{W(t)-\\frac{t}{2}}\\]\nactually solves the SDE we want. \n\n\\paragraph{Problem 2} Show that, \n\\[S(t)=s_0e^{\\sigma W(t)+\\left(\\mu-\\frac{\\sigma^2}{2}\\right)t}\\]\nsolves\n\\begin{equation*}\n\\begin{cases}\ndS &= \\mu Sdt + \\sigma SdW\\\\\nS(0) &= s_0.\n\\end{cases} \n\\end{equation*}\n\n\\paragraph{Solution of Problem 2}\nAgain we use the Ito's chain rule: for function $X(t):= W(t)+\\frac{\\mu-\\sigma^2/2}{\\sigma}t$, we have:\n\\[dX= dW + \\frac{\\mu-\\sigma^2/2}{\\sigma} dt.\\]\nTherefore, for function $S(t)=s_0 e^{\\sigma\\cdot X(t)}$, it holds that:\n\\begin{equation*}\n\\begin{aligned}\ndS &= \\left(\\sigma s_0 e^{\\sigma X(t)}\\cdot \\frac{\\mu-\\sigma^2/2}{\\sigma} +\\frac12\\cdot \\sigma^2 s_0 e^{\\sigma X(t)}\\right)dt + \\sigma s_0 e^{\\sigma X(t)}dW\\\\\n&= \\mu s_0 e^{\\sigma X(t)}dt + \\sigma s_0 e^{\\sigma X(t)}dW = \\mu Sdt+\\sigma SdW.\n\\end{aligned}    \n\\end{equation*}\nAlso, it's easy to verify that $S(0)=s_0$, which comes to our conclusion. \n\\paragraph{Problem 3} (1) Let $(\\Omega, \\mu, P)$ be a probability space and let $A_1\\subseteq A_2\\subseteq\\ldots\\subseteq A_n\\subseteq\\ldots$ be events. Show that \n\\[P\\left(\\bigcup_{n=1}^{\\infty}A_n\\right)=\\lim_{m\\rightarrow \\infty} P(A_m).\\]\n(Hint: Look at the disjoint events $B_n :=A_{n+1}-A_n$.)\\\\\n~\\\\\n(2) Likewise, show that if $A_1\\supseteq A_2 \\supseteq\\ldots\\supseteq A_n\\supset\\ldots$, then\n\\[P\\left(\\bigcap_{n=1}^{\\infty}A_n\\right)=\\lim_{m\\rightarrow\\infty} P(A_m).\\]\n\n\\paragraph{Solution of Problem 3}~\\\\\n(1) Consider the disjoint events $B_n=A_{n+1}-A_n$, then we know that these events are disjoint since for $\\forall m<n$, it holds that:\n\\[B_m=A_{m+1}-A_m\\subseteq A_{m+1}\\subseteq A_n, ~A_{n+1}-A_n =B_n\\cap A_n = \\varnothing,\\]\nso we can conclude that $B_m\\cap B_n=\\varnothing$, which means $\\{B_n\\}$ are disjoint events. Also, we have $\\bigcup_{n=1}^{\\infty}A_n=\\bigcup_{n=0}^{\\infty}B_n$. It is because for $\\forall x\\in \\bigcup_{n=1}^{\\infty}A_n$, there exists a smallest $k$ such that $x\\in A_k\\Rightarrow x\\in A_k-A_{k-1}=B_k\\subseteq\\bigcup_{n=0}^{\\infty}B_n$, which leads to\n\\[\\bigcup_{n=1}^{\\infty}A_n\\subseteq\\bigcup_{n=0}^{\\infty}B_n.\\]\nOn the other hand, for $\\forall x\\in \\bigcup_{n=0}^{\\infty}B_n$, there exists $k$ such that $x\\in B_k\\subseteq A_{k+1}\\subseteq\\bigcup_{n=1}^{\\infty}A_n$, which leads to\n\\[\\bigcup_{n=1}^{\\infty}A_n\\supseteq\\bigcup_{n=0}^{\\infty}B_n.\\]\nTherefore, we conclude that $\\bigcup_{n=1}^{\\infty}A_n=\\bigcup_{n=0}^{\\infty}B_n$. Also, notice that $A_m=B_0\\cup B_1\\cup\\ldots B_{m-1}$, which leads to\n\\[P(A_m)=\\sum_{n=0}^{m-1}P(B_m).\\]\nHere, we use the countable additivity of $P(\\cdot)$ under disjoint events $\\{B_n\\}$. Finally, it holds that:\n\\begin{equation*}\n\\begin{aligned}\n&P\\left(\\bigcup_{n=1}^{\\infty}A_n\\right) = P\\left(\\bigcup_{n=0}^{\\infty}B_n\\right) = \\sum_{n=0}^{\\infty}P(B_n) =\\lim_{m\\rightarrow\\infty}\\sum_{n=0}^{m-1}P(B_n) = \\lim_{m\\rightarrow\\infty} P(A_m)\n\\end{aligned}    \n\\end{equation*}\nIn the final step, we use the fact that the sequence $p_m := \\sum_{n=0}^{m-1}P(B_n)=P(A_m)$ is non-decreasing and upper bounded by 1, and therefore it converges. \\\\\n~\\\\\n(2) Similarly, we have $A_1^c\\subseteq A_2^c\\subseteq\\ldots\\subseteq A_n^c\\subseteq\\ldots$. By using the conclusion of (1), we have:\n\\[P\\left(\\bigcap_{n=1}^{\\infty}A_n\\right)=1-P\\left(\\bigcup_{n=1}^{\\infty}A_n^c\\right)=1-\\lim_{m\\rightarrow\\infty}P(A_m^c)=\\lim_{m\\rightarrow\\infty}P(A_m),\\]\nwhich comes to our conclusion.\n\n\\paragraph{Problem 4} Let $\\Omega$ be any set and $\\mathcal A$ any collections of subsets of $\\Omega$. Show that there exists a unique smallest $\\sigma$-algebra $\\mu$ of subsets of $\\Omega$ containing $\\mathcal A$. We call $\\mu$ the $\\sigma$-algebra generated by $\\mathcal A$. \\\\\n(Hint: Take the intersection of all the $\\sigma$-algebras containing $\\mathcal A$. )\n\n\\paragraph{Solution of Problem 4} Obviously, there exists a $\\sigma$-algebra containing $\\mathcal A$ (for example, $2^{\\Omega}$ itself). Now, we take the intersection of all the $\\sigma$-algebras containing $\\mathcal A$, denoted by $\\mu$. In order to prove that there exists a unique smallest $\\sigma$-algebra $\\mu$ of subsets of $\\Omega$ containing $\\mathcal A$, we only need to prove that the intersection of all $\\sigma$-algebras is also a $\\sigma$-algebra of $\\Omega$ containing $\\mathcal A$. On one hand, since all the $\\sigma$-algebras considered by us contain $\\mathcal A$, so their intersection $\\mu$ also contains $\\mathcal A$. On the other hand,\n\\begin{itemize}\n\\item For all $\\sigma$-algebra $S$ that contains $\\mathcal A$, we have $\\varnothing \\in S$ by the definition of $\\sigma$-algebra. Therefore, the intersection holds $\\varnothing\\in \\mu$ obviously. \n\\item For $\\forall A\\in\\mu$, we have $A\\in S$ for any $\\sigma$-algebra $S$ that contains $\\mathcal A$, so it holds that $A^c\\in S$. Therefore, we have $A^c\\in\\mu$. \n\\item For $A_1, A_2, \\ldots, \\in\\mu$, we know that for any $\\sigma$-algebra $S$ that contains $\\mathcal A$, $\\bigcup_{i=1}^{+\\infty} A_i\\in S$. Therefore:\n\\[\\bigcup_{i=1}^{+\\infty} A_i\\in \\mu.\\]\n\\end{itemize}\nAfter combining all the items above, we know that $\\mu$ is also a $\\sigma$-algebra of $\\Omega$ containing $\\mathcal A$, which comes to our conclusion. \n\n\\paragraph{Problem 5} Show that if $A_1, A_2,\\ldots, A_n$ are events, then\n\\begin{equation*}\n\\begin{aligned}\nP\\left(\\bigcup_{i=1}^{n}A_i\\right) &= \\sum_{i=1}^{n} P(A_i) -\\sum_{1\\leqslant i<j\\leqslant n}P(A_i\\cap A_j)\\\\\n&~~~+ \\sum_{1\\leqslant i<j<k\\leqslant n} P(A_i\\cap A_j\\cap A_k)\\\\\n&~~~-\\ldots+(-1)^n P(A_1\\cap A_2\\cap\\ldots\\cap A_n).\n\\end{aligned}    \n\\end{equation*}\n(Hint: Do the case $n=2$ first and then the general case by induction.)\n \n\\paragraph{Solution of Problem 5} We use the method of induction. When $n=2$, we know that:\n\\[P(A\\cup B)=P(A)+P((A\\cup B)-A)=P(A)+P(B-(A\\cap B))=P(A)+P(B)-P(A\\cap B).\\]\nSuppose the condition holds for $n$, then for $n+1$, we have:\n\\begin{align}\n&~~P(A_1\\cup A_2\\cup\\ldots\\cup A_{n+1}) = P((A_1\\cup A_2\\cup\\ldots\\cup A_n)\\cup A_{n+1})\\notag\\\\\n&= P(A_1\\cup A_2\\cup\\ldots\\cup A_n)+P(A_{n+1})-P((A_1\\cup A_2\\cup\\ldots\\cup A_n)\\cap A_{n+1})\\notag\\\\\n&= P(A_{n+1})+\\sum_{i=1}^{n} P(A_i) -\\sum_{1\\leqslant i<j\\leqslant n}P(A_i\\cap A_j)+\\ldots+(-1)^n P(A_1\\cap A_2\\cap\\ldots\\cap A_n)\\notag\\\\\n&~~-P\\left((A_1\\cap A_{n+1})\\cup (A_2\\cap A_{n+1})\\cup\\ldots\\cup (A_n\\cap A_{n+1})\\right)\\notag\\\\\n&= P(A_{n+1})+\\sum_{i=1}^{n} P(A_i) -\\sum_{1\\leqslant i<j\\leqslant n}P(A_i\\cap A_j)+\\ldots+(-1)^n P(A_1\\cap A_2\\cap\\ldots\\cap A_n)\\notag\\\\\n&~~-\\sum_{i=1}^{n} P(A_i\\cap A_{n+1})+\\sum_{1\\leqslant i<j\\leqslant n}P((A_i\\cap A_{n+1})\\cap(A_j\\cap A_{n+1}))-\\ldots\\notag\\\\\n&~~-(-1)^n P((A_1\\cap A_{n+1})\\cap (A_2\\cap A_{n+1})\\cap\\ldots\\cap (A_n\\cap A_{n+1}))\\notag\\\\\n&= \\sum_{i=1}^{n+1} P(A_i) -\\sum_{1\\leqslant i<j\\leqslant n+1}P(A_i\\cap A_j)+\\ldots+(-1)^{n+1} P(A_1\\cap A_2\\cap\\ldots\\cap A_{n+1})\\notag,\n\\end{align}    \nwhich completes the induction and comes to our conclusion. \n\n\\paragraph{Problem 6} Let $X=\\sum_{i=1}^{k}a_i\\chi_{A_i}$ be a simple random variable, where the real numbers $a_i$ are distinct, the events $A_i$ are pairwise disjoint, and $\\Omega=\\bigcup_{i=1}^{k}A_i$. Let $\\mu(X)$ be the $\\sigma$-algebra generated by $X$.\\\\\n(1) Describe precisely which sets are in $\\mu(X)$.\\\\\n(2) Suppose the random variable $Y$ is $\\mu(X)$-measurable. Show that $Y$ is constant on each set $A_i$.\\\\\n(3) Show that therefore $Y$ can be written as a function of $X$. \n\n\\paragraph{Solution of Problem 6}~\\\\\n(1) Since the real numbers $a_i$ are distinct, we can assume that\n\\[a_1<a_2<\\ldots<a_k\\]\nwithout loss of generality. We are going to prove that $\\mu(X)=\\sigma(\\{A_i:~i\\in[k]\\})$ which is the $\\sigma$-algebra generated by the pairwise disjoint events $A_i$. On one hand, notice that: $\\forall i\\in[k]$,\n\\[A_i=\\{X=a_i\\}\\in\\mu(X)~\\Rightarrow~\\sigma(\\{A_i:~i\\in[k]\\}\\subseteq \\mu(X).\\]\nOn the other hand, for any $B\\in\\mathcal B(\\mathbb{R})$, we have:\n\\[\\{X\\in B\\}=\\bigcup_{a_i\\in B}A_i \\in\\sigma(\\{A_i:~i\\in[k]\\}),\\]\nwhich leads to:\n\\[\\mu(X)=\\sigma\\left(\\{X\\in B\\}\\right)\\subseteq \\sigma(\\{A_i:~i\\in[k]\\}).\\]\nTo sum up, $\\mu(X)=\\sigma(\\{A_i:~i\\in[k]\\})$, which means all the sets in $\\mu(X)$ are $\\bigcup_{i\\in S}A_i$ for some $S\\subseteq [k]$. \n\n~\\\\\n(2) Random variable $Y$ is $\\mu(X)$-measurable. Then, for any $B\\in\\mathcal B(\\mathbb{R})$, it holds that event $\\{Y\\in B\\}\\in\\mu(X)$. From the conclusion of (1), we know that \n\\[\\mu(X)=\\left\\{\\bigcup_{i\\in S}A_i:~S\\subseteq [k]\\right\\}.\\]\nNow we suppose that $Y$ is not constant on each set $A_i$. Without loss of generality, we assume $Y$ is not constant on $A_1$, then there exists $x,y\\in A_1$ such that $Y(x)<Y(y)$. Consider the event $E = \\{Y=Y(x)\\}\\in\\mu(X)$, then $x\\in E$ but $y\\notin E$. Since $E$ must be the union of some $A_i$-s, from $x\\in E$, we know that $A_1\\subseteq E$. From $y\\notin E$, we know that $A_1\\cap E=\\varnothing$, which contradict with each other. Therefore, $Y$ must be constant on each set $A_i$.\n\n~\\\\\n(3) According to the conclusion of (2), we can assume that $Y$ equals to constant $b_i$ on the set $A_i$. Then:\n\\[Y=\\sum_{i=1}^{k}b_i\\chi_{A_i}.\\]\nTherefore, $Y$ can be written as $f(X)$ where $f(a_i)=b_i$ for $\\forall i\\in[k]$, which comes to our conclusion. \n\n\n\\paragraph{Problem 7} Verify:\n\\[\\int_{-\\infty}^{\\infty}e^{-x^2}dx=\\sqrt{\\pi},~~~\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\int_{-\\infty}^{\\infty}xe^{-\\frac{(x-m)^2}{2\\sigma^2}}dx=m,\\]\n\\[\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\int_{-\\infty}^{\\infty}(x-m)^2e^{-\\frac{(x-m)^2}{2\\sigma^2}}dx=\\sigma^2.\\]\n\n\\paragraph{Solution of Problem 7} For the first conclusion, we consider the following equation: denote $S=\\int_{-\\infty}^{\\infty}e^{-x^2}dx$, then:\n\\begin{equation*}\n\\begin{aligned}\nS^2&=\\int_{-\\infty}^{\\infty}e^{-x^2}dx \\cdot\\int_{-\\infty}^{\\infty}e^{-y^2}dy = \\int_{\\mathbb{R}^2}e^{-(x^2+y^2)}dxdy\\\\\n& = \\int_{0}^{+\\infty}\\int_{-\\pi}^{\\pi} e^{-r^2}r\\cdot drd\\theta = \\pi\\cdot \\int_{0}^{+\\infty}e^{-r^2}\\cdot 2rdr = \\pi\\cdot \\int_{0}^{+\\infty}e^{-r^2}dr^2 = \\pi.\n\\end{aligned}    \n\\end{equation*}\nIt is obvious that $S>0$, therefore $S=\\sqrt{\\pi}$. For the following two equations, let $x=m+\\sqrt{2}\\sigma y$, then:\n\\begin{equation*}\n\\begin{aligned}\n&\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\int_{-\\infty}^{\\infty}xe^{-\\frac{(x-m)^2}{2\\sigma^2}}dx = \\frac{1}{\\sqrt{\\pi}}\\int_{-\\infty}^{\\infty}(m+\\sqrt{2}\\sigma y)e^{-y^2}dy\\\\\n=~&\\frac{m}{\\sqrt{\\pi}}\\int_{-\\infty}^{\\infty}e^{-y^2}dy+\\frac{\\sqrt{2}\\sigma}{\\sqrt{\\pi}}\\int_{-\\infty}^{\\infty}ye^{-y^2}dy = m+0=m.\n\\end{aligned}    \n\\end{equation*}\nHere, we use the conclusion of $\\int_{-\\infty}^{\\infty}e^{-y^2}dy=\\sqrt{\\pi}$ and the fact that $ye^{-y^2}$ is an odd function, whose integral over $\\mathbb{R}$ must be 0. \n\\begin{equation*}\n\\begin{aligned}\n&\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\int_{-\\infty}^{\\infty}(x-m)^2e^{-\\frac{(x-m)^2}{2\\sigma^2}}dx = \\frac{1}{\\sqrt{\\pi}}\\int_{-\\infty}^{\\infty}2\\sigma^2 y^2 e^{-y^2}dy\\\\\n=~&\\frac{\\sigma^2}{\\sqrt{\\pi}}\\int_{-\\infty}^{\\infty}y\\cdot 2ye^{-y^2}dy = \\frac{\\sigma^2}{\\sqrt{\\pi}}\\int_{-\\infty}^{\\infty}-y de^{-y^2} = \\frac{\\sigma^2}{\\sqrt{\\pi}}\\cdot \\left(-ye^{-y^2}\\Bigg|_{-\\infty}^{\\infty}+\\int_{-\\infty}^{\\infty}e^{-y^2}dy\\right)\\\\\n=~&\\frac{\\sigma^2}{\\sqrt{\\pi}}\\cdot\\sqrt{\\pi}=\\sigma^2.\n\\end{aligned}    \n\\end{equation*}\nHere, we again use the equation $\\int_{-\\infty}^{\\infty}e^{-y^2}dy=\\sqrt{\\pi}$.\n\n\n\\paragraph{Problem 8} Suppose $A$ and $B$ are independent events in some probability space. Show that $A^c$ and $B$ are independent. Likewise, show that $A^c$ and $B^c$ are independent. \n\n\\paragraph{Solution of Problem 8} Since $A$ and $B$ are independent events, we have:\n\\[P(A\\cap B)=P(A)P(B).\\]\nTherefore, we have the following two equations:\n\\[P(A^c\\cap B)=P(B)-P(A\\cap B)=P(B)-P(A)P(B)=(1-P(A))P(B)=P(A^c)P(B).\\]\n\\begin{equation*}\n\\begin{aligned}\nP(A^c\\cap B^c) &= 1-P(A\\cup B)=1-P(A)-P(B)+P(A\\cap B)=1-P(A)-P(B)+P(A)P(B)\\\\\n&=(1-P(A))(1-P(B))=P(A^c)\\cdot P(B^c).\n\\end{aligned}    \n\\end{equation*}\nThese two equations conclude that $A^c$ and $B$ are independent. Also, $A^c$ and $B^c$ are independent. \n\n\n\\paragraph{Problem 9} Suppose we have three cards: one is red on both sides, one is red on one side and white on the other side, and one is white on both sides. \\\\\n(1) Pick a card and then one of its sides at random. What is the probability it is red?\\\\\n(2) Given that the side of the card is red, what is the probability that the other side is red?\n\n\\paragraph{Solution of Problem 9}~\\\\\n(1) We denote R as red and W as white, then:\n\\[P(R)=P(RR)\\cdot 1+P(RB)\\cdot \\frac12 + P(BB)\\cdot 0 = \\frac13+\\frac16=\\frac12.\\]\nThe probability of red side is $\\frac12$. \n\n~\\\\\n(2) By using Bayes' formula, we have:\n\\[P(RR|R)=\\frac{P(RR)\\cdot P(R|RR)}{P(RR)\\cdot P(R|RR)+P(RB)\\cdot P(R|RB)+P(BB)\\cdot P(R|BB)}=\\frac{1/3}{1/3+1/6+0}=\\frac23.\\]\nThe probability for the other side to be red is $\\frac23$.\n\n\n\n\n\\paragraph{Problem 10} Suppose that $A_1, A_2,\\ldots, A_m$ are disjoint events, each of positive probability, such that $\\Omega=\\bigcup_{j=1}^{m} A_j$. Prove Bayes' formula:\n\\[P(A_k|B)=\\frac{P(B|A_k)P(A_k)}{\\sum_{j=1}^{m}P(B|A_j)P(A_j)}\\]\nfor $k=1,2,\\ldots, m$ provided $P(B)>0$.\n\n\\paragraph{Solution of Problem 10} Since $A_1, A_2, \\ldots, A_m$ all have positive probabilities, so:\n\\[P(B|A_j)P(A_j)=P(B\\cap A_j).\\]\nAlso, they are disjoint and $\\bigcup_{j=1}^{m}A_j=\\Omega$, which leads to $\\{B\\cap A_j\\}_{j\\in[m]}$ are also disjoint and $\\bigcup_{j=1}^{m}(B\\cap A_j)=B\\cap \\Omega=B$. Therefore:\n\\[\\frac{P(B|A_k)P(A_k)}{\\sum_{j=1}^{m}P(B|A_j)P(A_j)}=\\frac{P(B\\cap A_k)}{\\sum_{j=1}^{m}P(B\\cap A_j)}=\\frac{P(B\\cap A_k)}{P(B)}=P(A_k|B),\\]\nwhich comes to our conclusion. Here, we used the additivity of probability measures.\n\n\n\\paragraph{Problem 11} During one fall semester 105 women applied to Miskatonic University, of whom 76 were accepted, and 400 men applied, of whom 230 were accepted. During the subsequent spring semester, 300 women applied, of whom 100 were accepted, and 112 men applied, of whom 21 were accepted. Calculate numerically:\\\\\n(a) the probability of a female applicant being accepted during the fall,\\\\\n(b) the probability of a male applicant being accepted during the fall, \\\\\n(c) the probability of a female applicant being accepted during the spring,\\\\\n(d) the probability of a male applicant being accepted during the spring.\\\\\nConsider now the total applicant pool for both semesters together and calculate. \\\\\n(e) the probability of a female applicant being accepted,\\\\\n(f) the probability of a male applicant being accepted.\\\\\nAre the university's admission policies biased towards females or towards males?\n\n\\paragraph{Solution of Problem 11} ~\\\\\n(a) $76/105 = 0.7238$.\\\\\n(b) $230/400 = 0.5750$.\\\\\n(c) $100/300 = 0.3333$.\\\\\n(d) $21/112 = 0.1875$.\\\\\n(e) $(100+76)/(300+105) = 0.4346$.\\\\\n(f) $(230+21)/(400+112) = 0.4902$.\\\\\n~\\\\\nAlthough in each semester, the probability of acceptance of females is higher than males, the university's admission policies biased towards males.\n\n\\paragraph{Problem 12} Let $X$ be a real-valued, $\\mathcal N(0,1)$ random variable, and set $Y:=X^2.$ Calculate the density $g$ of the distribution function for $Y$. \\\\\n(Hint: You must find $g$ so that $P(-\\infty<Y\\leqslant a)=\\int_{-\\infty}^{a}gdy $ for all $a$.)\n\n\\paragraph{Solution of Problem 12} Notice that $Y=X^2 \\geqslant 0$ always holds, which means $P(Y<0)=0$. For $\\forall t\\geqslant 0$, we have:\n\\[P(-\\infty<Y\\leqslant t)=P(X^2\\leqslant t)=P(-\\sqrt{t}\\leqslant X\\leqslant \\sqrt{t})=\\int_{-\\sqrt{t}}^{\\sqrt{t}}\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{x^2}{2}\\right)dx = 2\\phi(\\sqrt{t}).\\]\nwhere $\\phi(u)=\\int_{0}^{u}\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{x^2}{2}\\right)dx$. Then: $\\phi'(u)=\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{u^2}{2}\\right)$. Now, we can conclude that, the density function for distribution $Y$ is:\n\\[g(t)=\\frac{d}{dt}2\\phi(\\sqrt{t})= \\frac{\\frac{1}{\\sqrt{2\\pi}}\\cdot\\exp(-t/2)}{\\sqrt{t}}=\\frac{\\exp(-t/2)}{\\sqrt{2\\pi t}}~~~~~(t\\geqslant 0).\\]\nTo sum up, the density function is:\n\\[g(t)=\\frac{\\exp(-t/2)}{\\sqrt{2\\pi t}}\\cdot\\mathbb{I}[t>0].\\]\n\n\n\\paragraph{Problem 13} Take $\\Omega = [0,1]\\times [0,1]$, with $\\mathcal U$ the Borel sets and $P$ Lebesgue measure. Let $g:[0,1]\\rightarrow\\mathbb{R}$ be a continuous function.\\\\\nDefine the random variables \n\\[X_1(\\omega):=g(x_1), X_2(\\omega):=g(x_2)~~\\text{for}~\\omega=(x_1,x_2)\\in\\Omega.\\]\nShow that $X_1$ and $X_2$ are independent and identically distributed. \n\n\\paragraph{Solution of Problem 13} For $\\forall A\\in\\mathcal B(\\mathbb{R})$, we have:\n\\[P(X_1\\in A) = P(g^{-1}(A)\\times [0,1])= P([0,1]\\times g^{-1}(A))=P(X_2\\in A).\\]\nHere, since $g$ is a continuous function, we know that $g^{-1}(A)\\in \\mathcal B([0,1])$. Therefore, $X_1$ and $X_2$ are identically distributed. Next, we are going to prove that they are independently distributed. For $\\forall A, B\\in\\mathcal B(\\mathbb{R})$, we have:\n\\[P(X_1\\in A, X_2\\in B) = P(g^{-1}(A)\\times g^{-1}(B))=P'(g^{-1}(A))\\times P'(g^{-1}(B)) = P(X_1\\in A)\\cdot P(X_2\\in B),\\]\nwhere $P'$ is the Lebesgue measure on $\\mathbb{R}$. Therefore, we can conclude that $X_1$ and $X_2$ are independently distributed. \n\n\\paragraph{Problem 14} Let $f:[0,1]\\rightarrow\\mathbb{R}$ be continuous and define the Bernstein polynomial \n\\[b_n(x):=\\sum_{k=0}^{n}f\\left(\\frac{k}{n}\\right)\\binom{n}{k}x^k(1-x)^{n-k}.\\]\nProve that $b_n\\rightarrow f$ uniformly on $[0,1]$ as $n\\rightarrow\\infty$, by providing the details for the following steps.\\\\\n(1) Since $f$ is uniformly continuous, for each $\\varepsilon > 0$ there exists $\\delta(\\varepsilon)>0$ such that $|f(x)-f(y)|\\leqslant \\varepsilon$ if $|x-y|\\leqslant \\delta(\\varepsilon)$.\\\\\n(2) Given $x\\in[0,1]$, take a sequence of independent random variables $X_k$ such that $P(X_k=1)=x, P(X_k=0)=1-x$. Write $S_n=X_1+X_2+\\ldots+X_n$. Then $b_n(x)=\\mathbb{E}f\\left(\\frac{S_n}{n}\\right)$.\\\\\n(3) Therefore\n\\begin{equation*}\n\\begin{aligned}\n|b_n(x)-f(x)|&\\leqslant \\mathbb{E}\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|\\\\\n&= \\int_A\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|dP + \\int_{A^c}\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|dP,\n\\end{aligned}    \n\\end{equation*}\nfor $A:=\\left\\{\\omega\\in\\Omega|~|\\frac{S_n}{n}-x|\\leqslant \\delta(\\varepsilon)\\right\\}$. \\\\\n(4) Then show that\n\\[|b_n(x)-f(x)|\\leqslant \\varepsilon+\\frac{2M}{\\delta(\\varepsilon)^2}\\cdot V\\left(\\frac{S_n}{n}\\right)=\\varepsilon+\\frac{2M}{n\\delta(\\varepsilon)^2}V(X_1),\\]\nfor $M=\\max|f|$. Conclude that $b_n\\rightarrow f$ uniformly.\n \n\\paragraph{Solution of Problem 14} ~\\\\\n(1) For any $\\varepsilon > 0, x\\in[0,1]$, there exists $\\delta_x>0$ such that $|u-x|< \\delta_x\\Rightarrow |f(u)-f(x)|\\leqslant \\varepsilon/2$. Then: $\\cup_{x\\in[0,1]}(x-\\delta_x, x+\\delta_x)\\supseteq[0,1]$. According to the Heine-Borel Covering Theorem: there exists a finite sub-covering. We denote it by $(a_1, b_1), (a_2, b_2), \\ldots, (a_n, b_n)$.  Let $\\delta = \\min_{i,j}\\{|a_i-b_j|>0\\}$, then for $\\forall x,y\\in[0,1]$ such that $|x-y|<\\delta$, they belong to the same interval, which leads to $|f(x)-f(y)|\\leqslant \\varepsilon$, and it comes to our conclusion. \n\n~\\\\\n(2) Notice that:\n\\begin{equation*}\n\\begin{aligned}\n\\mathbb{E}f\\left(\\frac{S_n}{n}\\right) &= f\\left(\\frac{k}{n}\\right)\\cdot P(\\{\\text{There are }k\\text{ 1-s and }n-k\\text{ 0-s in }X_1, X_2, \\ldots, X_n\\})\\\\\n&= f\\left(\\frac{k}{n}\\right)\\cdot\\binom{n}{k}x^k(1-x)^{n-k}=b_n(x),\n\\end{aligned}    \n\\end{equation*}\nwhich comes to our conclusion. \n\n~\\\\\n(3) Notice that for any random variable $X$, we have:\n\\[-\\mathbb{E}|X|\\leqslant \\mathbb{E}X \\leqslant \\mathbb{E}|X|~\\Rightarrow |\\mathbb{E}X|\\leqslant \\mathbb{E}|X|.\\]\nTherefore:\n\\begin{equation*}\n\\begin{aligned}\n|b_n(x)-f(x)| &= |\\mathbb{E}[f(S_n/n)-f(x)]|\\leqslant \\mathbb{E}\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|\\\\\n&= \\int_A\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|dP + \\int_{A^c}\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|dP,\n\\end{aligned}\n\\end{equation*}\nfor $A:=\\{\\omega\\in\\Omega|~|\\frac{S_n}{n}-x|\\leqslant \\delta(\\varepsilon)\\}.$\n\n~\\\\\n(4) If $\\omega\\in A$, we have:$|\\frac{S_n}{n}-x|\\leqslant \\delta(\\varepsilon)\\Rightarrow \\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|\\leqslant \\varepsilon$. Therefore:\n\\[\\int_A\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|dP\\leqslant \\varepsilon\\cdot P(A)\\leqslant \\varepsilon.\\]\nOn the other hand,\n\\begin{equation*}\n\\begin{aligned}\n&\\int_{A^c}\\left|f\\left(\\frac{S_n}{n}\\right)-f(x)\\right|dP \\leqslant 2M\\cdot P(A^c)\\leqslant 2M\\cdot\\mathbb{E}\\frac{\\left(\\frac{S_n}{n}-x\\right)^2}{\\delta(\\varepsilon)^2}\\\\\n&=\\frac{2M}{\\delta(\\varepsilon)^2}V\\left(\\frac{S_n}{n}\\right)=\\frac{2M}{n\\delta(\\varepsilon)^2}V(X_1).\n\\end{aligned}    \n\\end{equation*}\nAfter adding up the two inequalities above, we have:\n\\[\\|b_n-f\\|_{\\infty}\\leqslant \\varepsilon+\\frac{2M}{n\\delta(\\varepsilon)^2}V(X_1).\\]\nThen we have:\n\\[\\lim_{n\\rightarrow\\infty}\\|b_n-f\\|_{\\infty}\\leqslant \\varepsilon.\\] \nSince $\\varepsilon > 0$ can be any positive real number, we have:\n\\[\\lim_{n\\rightarrow\\infty}\\|b_n-f\\|_{\\infty} = 0,\\]\nwhich comes to our conclusion. \n\n\\paragraph{Problem 15} Let $X$ and $Y$ be independent random variables, and suppose that $f_X$ and $f_Y$ are the density functions for $X, Y$. Show that the density function for $X+Y$ is \n\\[f_{X+Y}(z)=\\int_{-\\infty}^{\\infty} f_X(z-y)f_Y(y)dy.\\]\n(Hint: If $g:\\mathbb{R}\\rightarrow\\mathbb{R}$, we have\n\\[\\mathbb{E}[g(X+Y)]=\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)g(x+y)dxdy,\\]\nwhere $f_{X,Y}$ is the joint density function of $X,Y$. )\n\n\\paragraph{Solution of Problem 15} Notice that, \n\\[\\mathbb{E}[g(X+Y)]=\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)g(x+y)dxdy.\\]\nLet $Z=X+Y$, then:\n\\begin{equation*}\n\\begin{aligned}\n&\\int_{-\\infty}^{\\infty} g(z)\\cdot f_Z(z)dz = \\mathbb{E}[g(X+Y)] = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)g(x+y)dxdy\\\\\n&= \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}f_X(x) f_Y(y)\\cdot g(x+y)dxdy = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} f_Y(y)f_X(z-y) g(z) dzdy\\\\\n&= \\int_{-\\infty}^{\\infty}g(z)\\left(\\int_{-\\infty}^{\\infty}f_Y(y)f_X(z-y)dy\\right)dz.\n\\end{aligned}    \n\\end{equation*}\nHere, we use the fact that $X,Y$ are independent random variables and we also use the coordinate change of integration. Since $g$ can be any function on $Z$, we can conclusion that:\n\\[f_{X+Y}(z) = \\int_{-\\infty}^{\\infty}f_Y(y)f_X(z-y)dy,\\]\nwhich comes to our conclusion. \n\n\\paragraph{Problem 16} Let $X$ and $Y$ be two independent positive random variables, each with density \n\\[f(x)=\\begin{cases}e^{-x}~~~~\\mbox{if $x\\geqslant 0$}\\\\ 0~~~~~~~\\mbox{if $x < 0$}\\end{cases}.\\]\nFind the density of $X+Y$. \n\n\\paragraph{Solution of Problem 16} Notice that for $\\forall z\\geqslant 0$, we have:\n\\begin{equation*}\n\\begin{aligned}\n&P(X+Y\\leqslant z) =\\mathbb{E}\\mathbb{I}[X+Y\\leqslant z] = \\mathbb{E}_Y [\\mathbb{E}\\mathbb{I}[X+Y\\leqslant z]|Y] = \\mathbb{E}_Y P(X\\leqslant z-Y)\\\\\n&= \\int_{0}^{z} e^{-y}dy\\cdot \\int_{0}^{z-y} e^{-x} dx = \\int_{0}^{z} e^{-y}(1-e^{-(z-y)})dy = 1-e^{-z}-ze^{-z} = 1-(z+1)e^{-z}.\n\\end{aligned}    \n\\end{equation*}\nAfter taking derivative over $z$, we know that the density of $X+Y$ is:\n\\[g(z)=ze^{-z}~~(z\\geqslant 0).\\]\n\n\\paragraph{Problem 17} Show that\n\\[\\lim_{n\\rightarrow\\infty}\\int_0^1\\int_0^1\\ldots\\int_0^1  f\\left(\\frac{x_1+x_2+\\ldots+x_n}{n}\\right)dx_1 dx_2\\ldots dx_n = f\\left(\\frac12\\right)\\]\nfor each continuous function $f$.\n\n(Hint: Let $X_1, X_2,\\ldots, X_n$ be independent random variables, each of which has density function $f_i(x)=1$ if $0\\leqslant x\\leqslant 1$ and $=0$ otherwise. Then $P\\left(\\left|\\frac{X_1+X_2+\\ldots+X_n}{n}-\\frac12\\right|>\\varepsilon\\right)\\leqslant \\frac{1}{\\varepsilon^2}V\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right)=\\frac{1}{12\\varepsilon^2 n}$.)\n\n\\paragraph{Solution of Problem 17} Let $X_1, X_2,\\ldots, X_n$ be independent random variables, each of which follows the uniform distribution over $[0,1]$. Then, we only need to prove that:\n\\[\\lim_{n\\rightarrow\\infty} \\mathbb{E} f\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right)=f(1/2).\\]\n\nAs we know that:\n\\[P\\left(\\left|\\frac{X_1+X_2+\\ldots+X_n}{n}-\\frac12\\right|>\\varepsilon\\right)\\leqslant \\frac{1}{\\varepsilon^2}V\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right)=\\frac{1}{12\\varepsilon^2 n}.\\]\nSince $f$ is continuous function, $f$ is bounded on the closed interval $[0,1]$, which means there exists $L>0$ such that $|f(x)-f(1/2)|<L$ holds for $\\forall x\\in [0,1]$. Also, $f$ is continuous at $1/2$. Therefore, for $\\forall \\varepsilon > 0$, there exists $\\delta > 0$ such that $|x-1/2|<\\delta\\Rightarrow |f(x)-f(1/2)|<\\varepsilon$. Then:\n\\[P\\left(\\left|f\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right)-f(1/2)\\right|>\\varepsilon\\right)\\leqslant P\\left(\\left|\\frac{X_1+X_2+\\ldots+X_n}{n}-\\frac12\\right|>\\delta\\right)\\leqslant \\frac{1}{12\\delta^2 n},\\]\nwhich leads to:\n\\[\\left|\\mathbb{E}f\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right) -f(1/2)\\right|\\leqslant \\varepsilon + \\frac{L}{12\\delta^2 n}.\\]\nLet $n\\rightarrow\\infty$:\n\\[\\lim_{n\\rightarrow\\infty}\\left|\\mathbb{E}f\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right)-f(1/2)\\right|\\leqslant \\varepsilon.\\]\nSince $\\varepsilon$ can be any positive real number, we can finally conclude that:\n\\[\\lim_{n\\rightarrow\\infty}f\\left(\\frac{X_1+X_2+\\ldots+X_n}{n}\\right)=f(1/2).\\]\n\n\\paragraph{Problem 18} Prove that:\\\\\n(1) $\\mathbb{E}[\\mathbb{E}[X|\\mathcal V]]=\\mathbb{E}[X]$.\\\\\n(2) $\\mathbb{E}[X] = \\mathbb{E}[X|\\mathcal W]$, where $\\mathcal W = \\{\\emptyset, \\Omega\\}$ is the trivial $\\sigma$-algebra. \n\n\\paragraph{Solution of Problem 18} According to the definition of conditional expectation, we know that $\\mathbb{E}[X|\\mathcal V]$ is a random variable on $\\Omega$ such that $\\mathbb{E}[X|\\mathcal V]$ is $\\mathcal V$-measurable and $\\int_A XdP = \\int_A \\mathbb{E}[X|\\mathcal V]dP$ for all $A\\in\\mathcal V$.\\\\\n(1) $\\mathbb{E}[\\mathbb{E}[X|\\mathcal V]] = \\int \\mathbb{E}[X|\\mathcal V] d\\mu = \\int Xd\\mu = \\mathbb{E}[X]$.\\\\\n(2) Since $\\mathcal W=\\{\\emptyset, \\Omega\\}$ is the trivial $\\sigma$-algebra, and random variable $\\mathbb{E}[X|\\mathcal W]$ is $\\mathcal W$-measurable, which means $\\mathbb{E}[X|\\mathcal W]$ is a constant variable. By the conclusion of (1), we have:\n\\[\\mathbb{E}[X|\\mathcal W]=\\mathbb{E}[X],\\]\nwhich comes to our conclusion. \n\n\n\\paragraph{Problem 19} Let $X,Y$ be two real-valued random variables and suppose their joint distribution function has the density $f(x,y)$. Show that \n\\[\\mathbb{E}[X|Y]=\\Phi(Y)~~a.s.\\]\nfor\n\\[\\Phi(y)=\\frac{\\int_{-\\infty}^{\\infty}xf(x,y)dx}{\\int_{-\\infty}^{\\infty}f(x,y)dx}.\\]\n\n\\paragraph{Solution of Problem 19} According to the definition of conditional expectation, we know that: for all $A\\in\\mathcal U(Y)$,\n\\[\\int_A XdP=\\int_A \\mathbb{E}[X|Y] dP = \\int_A \\Phi(Y)dP.\\]\nFor any Borel subset of $\\mathbb{R}$, denoted by $B$, let $A=\\{Y\\in B\\}\\in \\mathcal U(Y)$:\n\\[\\int_A XdP=\\int_{\\omega}\\chi_B(Y)XdP=\\int_{-\\infty}^{\\infty}\\int_B xf(x,y)dydx.\\]\n\\[\\int_A \\Phi(Y)dP = \\int_{-\\infty}^{\\infty} \\int_B \\Phi(y)f(x,y)dydx.\\]\nAfter switching the order of integrals, we know that:\n\\[\\int_{-\\infty}^{\\infty}xf(x,y)dx = \\int_{-\\infty}^{\\infty}\\Phi(y)f(x,y)dx = \\Phi(y)\\int_{-\\infty}^{\\infty}f(x,y)dx.\\]\nIt directly leads to\n\\[\\Phi(y) = \\frac{\\int_{-\\infty}^{\\infty}xf(x,y)dx}{\\int_{-\\infty}^{\\infty}f(x,y)dx},\\]\nwhich comes to our conclusion.  \n\n\\paragraph{Problem 20} A smooth function $\\Phi:\\mathbb{R}\\rightarrow\\mathbb{R}$ is called convex if $\\Phi''(x)\\geqslant 0$ for all $x\\in\\mathbb{R}$.\\\\\n(1) Show that if $\\Phi$ is convex, then:\n\\[\\Phi(y)\\geqslant \\Phi(x)+\\Phi'(x)(y-x)~~~\\text{for all }x,y\\in\\mathbb{R}.\\]\n(2) Show that \n\\[\\Phi\\left(\\frac{x+y}{2}\\right)\\leqslant \\frac12\\Phi(x)+\\frac12\\Phi(y)~~~\\text{for all }x,y\\in\\mathbb{R}.\\]\n(3) A smooth function $\\Phi:\\mathbb{R}^n\\rightarrow\\mathbb{R}$ is called convex if the matrix $D^2\\Phi=((\\Phi_{x_i x_j}))$ is nonnegative definite for all $x\\in\\mathbb{R}^n$. (This means that $\\sum_{i,j=1}^n \\Phi_{x_i x_j}\\xi_i\\xi_j\\geqslant 0$ for all $\\xi\\in\\mathbb{R}^n$.) Prove that \n\\[\\Phi(y)\\geqslant \\Phi(x)+D\\Phi(x)\\cdot (y-x),\\]\n\\[\\Phi\\left(\\frac{x+y}{2}\\right)\\leqslant \\frac12\\Phi(x)+\\frac12\\Phi(y)\\]\nfor all $x,y\\in\\mathbb{R}^n$.\n\n\\paragraph{Solution of Problem 20} ~\\\\\n(1) Notice that, by using Lagrangian Theorem\n\\[\\Phi(y)-\\Phi(x) = \\Phi'(x')(y-x)\\]\nholds for some $x'=x+t(y-x)~(t\\in[0,1])$. Then:\n\\[\\Phi(y)-\\Phi(x)-\\Phi'(x)(y-x)=(y-x)(\\Phi'(x')-\\Phi(x))=(y-x)(x'-x)\\Phi''(x'')=t(y-x)^2\\Phi''(x'').\\]\nSince $t\\geqslant 0$ and $\\Phi''(x'')\\geqslant 0$, we can conclude that:\n\\[\\Phi(y)\\geqslant \\Phi(x)+\\Phi'(x)(y-x).\\]\n(2) By using Lagrangian Theorem, there exists $t_1, t_2 \\in[0,1/2]$, such that:\n\\[\\Phi\\left(\\frac{x+y}{2}\\right)-\\Phi(x)=\\Phi'(x+t_1(y-x))\\cdot\\frac{y-x}{2},\\]\n\\[\\Phi(y)-\\Phi\\left(\\frac{x+y}{2}\\right) = \\Phi'(y-t_2(y-x))\\cdot\\frac{y-x}{2}.\\]\nTherefore, we have:\n\\begin{equation*}\n\\begin{aligned}\n&\\frac12\\Phi(x)+\\frac12\\Phi(y)-\\Phi\\left(\\frac{x+y}{2}\\right) = \\frac{y-x}{4}\\cdot \\left[\\Phi'(y-t_2(y-x))-\\Phi'(x+t_1(y-x))\\right]\\\\\n&=\\frac{(1-t_1-t_2)(y-x)^2}{4}\\cdot\\Phi''(x'')\\geqslant 0,\n\\end{aligned}\n\\end{equation*}\nsince $1-t_1-t_2\\geqslant 0$ and $\\Phi''(x'')\\geqslant 0$, which comes to our conclusion.\n\n~\\\\\n(3) Notice that:\n\\begin{equation*}\n\\begin{aligned}\n&\\Phi(y)-\\Phi(x)-D\\Phi(x)\\cdot(y-x) = \\int_0^1 \\langle D\\Phi(x+t(y-x)), y-x\\rangle dt - D\\Phi(x)\\cdot(y-x)\\\\\n=& \\int_0^1 \\langle D\\Phi(x+t(y-x))- D\\Phi(x), y-x\\rangle dt =\\int_0^1 dt\\int_0^t (y-x)^{\\top} D^2\\Phi(x+t'(y-x))\\cdot (y-x)dt'\\geqslant 0,\n\\end{aligned}    \n\\end{equation*}\nwhich comes to our conclusion. Then, by using this inequality, we have:\n\\[\\Phi(x)-\\Phi\\left(\\frac{x+y}{2}\\right)\\geqslant -D\\Phi\\left(\\frac{x+y}{2}\\right)\\cdot\\frac{y-x}{2},\\]\n\\[\\Phi(y)-\\Phi\\left(\\frac{x+y}{2}\\right)\\geqslant D\\Phi\\left(\\frac{x+y}{2}\\right)\\cdot\\frac{y-x}{2}.\\]\nAfter adding them up, we obtain that:\n\\[\\Phi\\left(\\frac{x+y}{2}\\right)\\leqslant \\frac12\\Phi(x)+\\frac12\\Phi(y).\\]\n\n\\paragraph{Problem 21} ~\\\\\n(1) Prove Jensen's Inequality:\n\\[\\Phi(\\mathbb{E}X)\\leqslant \\mathbb{E}(\\Phi(X)),\\]\nfor a random variable $X:\\Omega\\rightarrow\\mathbb{R}$, where $\\Phi$ is convex. (Hint: Use assertion (3) from the previous exercise.)\\\\\n(2) Prove the conditional Jensen Inequality:\n\\[\\Phi(\\mathbb{E}(X|\\mathcal V))\\leqslant \\mathbb{E}(\\Phi(X)|\\mathcal V).\\]\n\n\\paragraph{Solution of Problem 21}~\\\\\n(1) According to the assertion (3) of the previous exercise, we have:\n\\[\\Phi(X)-\\Phi(\\mathbb{E}(X))\\geqslant D\\Phi(\\mathbb{E}(X))\\cdot(X-\\mathbb{E}X).\\]\nTherefore, after taking the expectation, it holds that:\n\\[\\mathbb{E}\\Phi(X)-\\Phi(\\mathbb{E}(X))\\geqslant D\\Phi(\\mathbb{E}(X))\\cdot \\mathbb{E}\\left(X-\\mathbb{E}X\\right) = 0,\\]\nwhich comes to our conclusion. \\\\\n(2) Again by using assertion (3), we know that:\n\\[\\Phi(X)-\\Phi(\\mathbb{E}(X|\\mathcal V))\\geqslant D\\Phi(\\mathbb{E}(X|\\mathcal V))\\cdot(X-\\mathbb{E}(X|\\mathcal V)).\\]\nBy taking conditional expectation $p(\\cdot|\\mathcal V)$:\n\\[\\mathbb{E}(\\Phi(X)|\\mathcal V)-\\Phi(\\mathbb{E}(X|\\mathcal V))\\geqslant D\\Phi(\\mathbb{E}(X|\\mathcal V))\\cdot\\mathbb{E}\\left(X-\\mathbb{E}(X|\\mathcal V)|\\mathcal V\\right)=0,\\]\nwhich comes to our conclusion.\n\n\n\n\n\\paragraph{Problem 22} Let $W(\\cdot)$ be a one-dimensional Brownian motion. Show that\n\\[\\mathbb{E}[W^{2k}(t)]=\\frac{(2k)!t^k}{2^k k!}~~(t>0).\\]\n\n\\paragraph{Solution of Problem 22} According to the property of Brownian motions, $W(t)\\sim\\mathcal N(0,t)$. Therefore:\n\\[\\mathbb{E}[W^{2k}(t)]=\\mathbb{E}_{z\\sim\\mathcal N(0,1)}(\\sqrt{t}z)^{2k}= t^k\\cdot\\mathbb{E}[z^{2k}]=t^k(2k-1)!!=\\frac{(2k)!t^k}{2^k k!},\\]\nwhich comes to our conclusion. \n\n\n\\paragraph{Problem 23} Show that if $W(\\cdot)$ is an $n$-dimensional Brownian motion, then so are:\\\\\n(1) $W(t+s)-W(s)$ for all $s\\geqslant 0$.\\\\\n(2) $cW(t/c^2)$ for all $c>0$. (Brownian scaling)\n\n\n\\paragraph{Solution of Problem 23} ~\\\\\n(1) For any $k\\in[n]$, $W^k(t)$ is a one-dimensional Brownian motion, then $W^k(t+s)-W^k(s)$ is a Gaussian process and \n\\[\\mathbb{E}[(W^k(u+s)-W^k(s))(W^k(v+s)-W^k(s))]=\\min(u+s,v+s)+s-\\min(u+s,s)-\\min(v+s,s)=\\min(u,v),\\]\nwhich means $W^k(t+s)-W^k(s)$ is also a one-dimensional Brownian motion. Also $\\{W^k(t+s)-W^k(s)\\}_{k\\in[n]}$ are independent. Therefore, $W(t+s)-W(s)$ is a Brownian motion. \\\\\n(2) For any $k\\in[n]$, $W^k(t)$ is a one-dimensional Brownian motion, then $cW^k(t/c^2)$ is a Gaussian process and \n\\[\\mathbb{E}[cW(u/c^2)\\cdot cW(v/c^2)]=c^2\\min(u/c^2,v/c^2)=\\min(u,v).\\]\nSo $cW^k(t/c^2)$ is a one-dimensional Brownian motion. Also $\\{cW^k(t/c^2)\\}_{k\\in[n]}$ are independent. Therefore, $cW(t/c^2)$ is a Brownian motion.  \n\n\n\\paragraph{Problem 24} Let $W(\\cdot)$ be a one-dimensional Brownian motion, and define \n\\[\\overline{W}(t)=\\begin{cases}tW\\left(\\frac{1}{t}\\right)~~~\\mbox{for $t>0$}\\\\ 0 ~~~~~~~~~~~~\\mbox{for $t=0$}\\end{cases}.\\]\nShow that $\\overline{W}(t)-\\overline{W}(s)$ is $\\mathcal N(0,t-s)$ for times $0\\leqslant s\\leqslant t$. ($\\overline{W}(\\cdot)$ also has independent increments and so is a one-dimensional Brownian motion. You do not need to show this.)\n\n\\paragraph{Solution of Problem 24} For times $0\\leqslant s\\leqslant t$, we know that:\n\\[\\overline{W}(t)-\\overline{W}(s) = tW\\left(\\frac{1}{t}\\right) - sW\\left(\\frac{1}{s}\\right)= (t-s)W\\left(\\frac{1}{t}\\right)-s\\left(W\\left(\\frac{1}{s}\\right)-W\\left(\\frac{1}{t}\\right)\\right).\\]\nNotice that $0<\\frac1t\\leqslant \\frac1s$, and so $W\\left(\\frac{1}{t}\\right)$ are independent with $W\\left(\\frac{1}{s}\\right)-W\\left(\\frac{1}{t}\\right)$. We know that:\n\\[W\\left(\\frac{1}{t}\\right)\\sim\\mathcal N(0,1/t),~~W\\left(\\frac{1}{s}\\right)-W\\left(\\frac{1}{t}\\right)\\sim\\mathcal N(0, 1/s-1/t).\\]\nTherefore, $\\overline{W}(t)-\\overline{W}(s)$ follows the zero-centered Gaussian distribution with its variance\n\\[(t-s)^2\\cdot\\frac1t + s^2\\cdot\\left(\\frac1s-\\frac1t\\right)=t-s.\\]\nTo sum up, we conclude that $\\overline{W}(t)-\\overline{W}(s)\\sim\\mathcal N(0,t-s)$.\n\n\\paragraph{Problem 25} Define $X(t):=\\int_0^t W(s)ds$, where $W(\\cdot)$ is a one-dimension Brownian motion. Show that \n\\[\\mathbb{E}[X^2(t)]=\\frac{t^3}{3}~~~~~\\text{for each }t>0.\\]\n\n\\paragraph{Solution of Problem 25} The Brownian motion can be written as: $W(t)=\\sum_{k=0}^{+\\infty} A_k s_k(t)$. Therefore:\n\\[X(t)=\\sum_{k=0}^{+\\infty}A_k \\int_0^t s_k(s)ds:=\\sum_{k=0}^{+\\infty}A_k U_k(t).\\]\nThen, since $\\{A_k\\}$ are independent random variables sampled from standard Gaussian. Therefore:\n\\[\\mathbb{E}[X^2(t)]=\\sum_{k=0}^{+\\infty} U_k^2(t).\\]\nNotice that:\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{k=0}^{+\\infty} U_k^2(t) &= \\sum_{k=0}^{+\\infty}\\int_0^t\\int_0^t s_k(x)s_k(y)dxdy = \\int_0^t\\int_0^t \\left[\\sum_{k=0}^{+\\infty}s_k(x)s_k(y)\\right]dxdy\\\\\n&= \\int_0^t\\int_0^t\\min(x,y)dxdy = 2\\cdot\\int_0^t xdx\\int_x^t dy = 2\\int_0^t x(t-x)dx= 2\\left(\\frac{t^3}{2}-\\frac{t^3}{3}\\right)=\\frac{t^3}{3},\n\\end{aligned}    \n\\end{equation*}\nwhich comes to our conclusion.\n\n\n\\paragraph{Problem 26} Define $X(t)$ as in the previous exercise. Show that \n\\[\\mathbb{E}e^{\\lambda X(t)}=e^{\\frac{\\lambda^2 t^3}{6}}~~~~\\text{for each }t>0.\\]\n(Hint: $X(t)$ is a Gaussian random variable, the variance of which we know from the previous exercise.)\n\n\\paragraph{Solution of Problem 26} From the exercise above, we know that $X(t)=\\sum_{k=0}^{+\\infty}A_k U_k(t)$. Then:\n\\begin{equation*}\n\\begin{aligned}\n\\mathbb{E}e^{\\lambda X(t)}&=\\prod_{k=0}^{+\\infty}\\mathbb{E} e^{\\lambda A_k U_k(t)} = \\prod_{k=0}^{+\\infty}\\exp\\left(-\\frac{\\lambda^2 U_k(t)^2}{2}\\right)\\\\\n&= \\exp\\left(-\\frac{\\lambda^2 \\sum_{k=0}^{+\\infty}U_k(t)^2}{2}\\right) = e^{-\\frac{\\lambda^2 t^3}{6}}.\n\\end{aligned}    \n\\end{equation*}\nHere, we use the conclusion from the previous exercise. \n\n\n\n\n\\paragraph{Problem 27} Define $U(t) := e^{-t} W(e^{2t})$, where $W(\\cdot)$ is a one-dimensional Brownian motion. Show that \n\\[\\mathbb{E}[U(t)U(s)]=e^{-|t-s|}~~~\\text{for all}~~-\\infty<s,t<\\infty.\\]\n\n\\paragraph{Solution of Problem 27} Without loss of generality, we can assume that $s\\leqslant t$. Then:\n\\begin{equation*}\n\\begin{aligned}\n\\mathbb{E}[U(t)U(s)] &= e^{-t-s}\\cdot\\mathbb{E}[W(e^{2t})W(e^{2s})] = e^{-t-s}\\cdot\\mathbb{E}\\left[W(e^{2s})^2 + W(e^{2s})\\cdot(W(e^{2t})-W(e^{2s}))\\right]\\\\\n&= e^{-t-s}\\cdot(e^{2s} + 0)  = e^{-t+s} = e^{-|t-s|},\n\\end{aligned}    \n\\end{equation*}\nwhich comes to our conclusion. Here, we use the fact that $W(x)\\sim\\mathcal N(0,x)$ for all $x\\geqslant 0$ and $W(x)-W(y)\\sim \\mathcal N(0,x-y)$ for all $0<y<x$ which is independent of $W(y)$. \n\n\\paragraph{Problem 28} Let $W(\\cdot)$ be a one-dimensional Brownian motion. Show that \n\\[\\lim_{m\\rightarrow\\infty}\\frac{W(m)}{m}=0~~~\\text{almost surely.}\\]\n(Hint: Fix $\\varepsilon > 0$ and define the event $A_m:=\\left\\{\\left|\\frac{W(m)}{m}\\right|\\geqslant \\varepsilon\\right\\}$. Then $A_m=\\{|X|\\geqslant \\sqrt{m}\\varepsilon\\}$ for the $\\mathcal N(0,1)$ random variable $X=\\frac{W(m)}{\\sqrt{m}}$. Apply the Borel-Cantelli Lemma.)\n\n\\paragraph{Solution of Problem 28} Notice that, the event $\\left\\{\\lim_{m\\rightarrow\\infty}\\frac{W(m)}{m}\\neq 0\\right\\}$ is equivalent to the event that there exists $\\delta>0$ such that there are infinitely many $m$-s satisfy $\\left|\\frac{W(m)}{m}\\right|>\\delta$, which means:\n\\[E := \\left\\{\\lim_{m\\rightarrow\\infty}\\frac{W(m)}{m}\\neq 0\\right\\} = \\lim_{k\\rightarrow\\infty}E_k\\]\nwhere \n\\[E_k = \\left\\{\\text{There are infinitely many }m\\text{-s satisfy }\\left|\\frac{W(m)}{m}\\right|>\\frac1k\\right\\}.\\]\nNotice that\n\\[E_k = \\lim\\sup_{m\\rightarrow\\infty}\\left\\{\\left|\\frac{W(m)}{m}\\right|>\\frac1k\\right\\}.\\]\nAccording to the fact that $W(m)\\sim\\mathcal N(0,m)$, we have:\n\\[P\\left(\\left|\\frac{W(m)}{m}\\right|>\\frac1k\\right)=P\\left(\\left|\\frac{W(m)}{\\sqrt{m}}\\right|>\\frac{\\sqrt{m}}{k}\\right) = \\widetilde{\\Phi}\\left(\\frac{\\sqrt{m}}{k}\\right)\\leqslant \\exp\\left(-\\frac{m}{2k^2}\\right).\\]\nThen their sum:\n\\[\\sum_{m=1}^{\\infty}P\\left(\\left|\\frac{W(m)}{m}\\right|>\\frac1k\\right)\\leqslant \\sum_{m=1}^{\\infty}\\exp\\left(-\\frac{m}{2k^2}\\right) = \\frac{1}{1-\\exp(-1/2k^2)},\\]\nwhich means the infinite sum actually converges. By using Borel-Cantelli Lemma, we know that:\n\\[P(E_k)=\\left(\\lim\\sup_{m\\rightarrow\\infty}\\left\\{\\left|\\frac{W(m)}{m}\\right|>\\frac1k\\right\\}\\right)=0,\\]\nand then:\n\\[P(E)=\\lim_{k\\rightarrow\\infty}P(E_k)=0~~~\\Rightarrow~~P(\\overline{E})=1,\\]\nwhich comes to our conclusion.\n\n\n\\paragraph{Problem 29} (1) Let $0<\\gamma\\leqslant 1$. Show that $f:[0,T]\\rightarrow \\mathbb{R}^n$ is uniformly Holder continuous with exponent $\\gamma$, it is also uniformly Holder continuous with each exponent $0<\\delta<\\gamma$. \\\\\n(2) Show that $f(t)=t^{\\gamma}$ is uniformly Holder continuous with exponent $\\gamma$ on the interval $[0,1]$.\n\n\\paragraph{Solution of Problem 29} (1) Since $f$ is uniformly Holder continuous with exponent $\\gamma$, we have:\n\\[\\|f(x)-f(y)\\|\\leqslant K |x-y|^{\\gamma}\\]\nholds for $\\forall x,y\\in[0,T]$ and a constant $K$. Then if $|x-y|\\leqslant 1$, we have: $|x-y|^{\\gamma}\\leqslant |x-y|^{\\delta}$, which directly leads to\n\\[\\|f(x)-f(y)\\|\\leqslant K |x-y|^{\\delta}.\\]\nIf $|x-y|>1$, we have: $|x-y|^{\\gamma}=|x-y|^{\\gamma-\\delta}\\cdot|x-y|^{\\delta}\\leqslant T^{\\gamma-\\delta}\\cdot |x-y|^{\\delta}$. To sum up, for $\\forall x,y\\in[0,T]$, it holds that:\n\\[\\|f(x)-f(y)\\|\\leqslant K\\max(1,T^{\\gamma-\\delta}) |x-y|^{\\delta},\\]\nwhich comes to our conclusion.\\\\\n\n(2) We only need to prove that for $\\forall x,y\\in[0,1]$, it uniformly holds that:\n\\[|x^{\\gamma}-y^{\\gamma}|<K|x-y|^{\\gamma}\\]\nfor some constant $K$. Without loss of generality, we can assume that $0\\leqslant y\\leqslant x\\leqslant 1$. Let $\\delta = x-y$, then we need to prove that:\n\\[g(y):=(y+\\delta)^{\\gamma}-y^{\\gamma} < K \\delta^{\\gamma}\\]\nfor some constant $K$. Since $\\gamma\\in(0,1]$, we have:\n\\[g'(y)=\\gamma\\cdot\\left((y+\\delta)^{\\gamma-1}-y^{\\gamma-1}\\right)\\leqslant 0.\\]\nIt means $g$ is a decreasing function. Therefore:\n\\[g(y)\\leqslant g(0) = \\delta^{\\gamma}\\]\nholds for $\\forall y$. We can make $K=2$ and it comes to our conclusion.\n\n\n\\paragraph{Problem 30} Let $0<\\gamma<\\frac12$. We showed in Chapter 3 that if $W(\\cdot)$ is a one-dimensional Brownian motion, then for almost every $\\omega$ there exists a constant $K$, depending on $\\omega$, such that \n\\[|W(t,\\omega)-W(s,\\omega)|\\leqslant K|t-s|^{\\gamma}~~~\\text{for all }0\\leqslant s,t\\leqslant 1.\\]\nShow that there does not exist a constant $K$ such that it holds for almost all $\\omega$. \n\n\\paragraph{Solution of Problem 30} Assume there exists a constant $K$ such that if holds for almost all $\\omega$. Then:\n\\begin{equation*}\n\\begin{aligned}\n1&=\\mathbb{P}_{\\omega}\\left[|W(t,\\omega)-W(s,\\omega)|\\leqslant K|t-s|^{\\gamma}~~\\forall 0\\leqslant s,t\\leqslant 1\\right] \\leqslant \\mathbb{P}_{\\omega}\\left[|W(1,\\omega)-W(0,\\omega)|\\leqslant K\\right]\\\\\n&= \\mathbb{P}_{\\omega}\\left[|W(1,\\omega)|\\leqslant K\\right] = 1-2\\widetilde{\\phi}(K).\n\\end{aligned}    \n\\end{equation*}\nwhich leads to a contradiction. \n\n\\paragraph{Problem 31} Prove that if $G,H\\in\\mathbb{L}^2(0,T)$, then:\n\\[\\mathbb{E}\\left(\\int_0^T GdW \\int_0^T HdW\\right) = \\mathbb{E}\\left(\\int_0^T GHdt\\right).\\]\n(Hint: $2ab=(a+b)^2-a^2-b^2$.)\n\n\\paragraph{Solution of Problem 31} Notice that:\n\\[\\mathbb{E}\\left(\\int_0^T GdW +\\int_0^T HdW\\right)^2 = \\|G+H\\|_2^2, ~\\mathbb{E}\\left(\\int_0^T GdW\\right)^2 = \\|G\\|_2^2, ~\\mathbb{E}\\left(\\int_0^T HdW\\right)^2 = \\|H\\|_2^2.\\]\nTherefore: we have \n\\[\\mathbb{E}\\left(\\int_0^T GdW \\int_0^T HdW\\right) = \\frac{1}{2}\\left(\\|G+H\\|_2^2-\\|G\\|_2^2-\\|H\\|_2^2\\right)=\\langle G,H\\rangle=\\int_0^T GHdt,\\]\nwhich comes to our conclusion. \n\n\\paragraph{Problem 32} Let $(\\Omega, \\mathcal U, P)$ be a probability space, and take $\\mathcal F(\\cdot)$ to be a filtration of $\\sigma$-algebras. Assume $X$ to be an integrable random variable, and define $X(t):=\\mathbb{E}[X|\\mathcal F(t)]$ for times $t\\geqslant 0$. Show that $X(\\cdot)$ is a martingale. \n\n\\paragraph{Solution of Problem 32} According to the definition of martingale, we know that $\\mathcal F(t)\\supseteq \\mathcal F(s)$ when $t>s$. So for $\\forall t>s$, it holds that:\n\\[\\mathbb{E}[X(t)|\\mathcal F(s)]=\\mathbb{E}[\\mathbb{E}[X|\\mathcal F(t)]|\\mathcal F(s)] = \\mathbb{E}[X|\\mathcal F(t)\\cap \\mathcal F(s)]=\\mathbb{E}[X|\\mathcal F(s)]=X(s),\\]\nwhich shows us that $\\{X(t)\\}$ is a martingale. \n\n\\paragraph{Problem 33} Show directly that $I(t):=W^2(t)-t$ is a martingale. \\\\\n(Hint: $W^2(t)=(W(t)-W(s))^2-W^2(s)+2W(t)W(s)$. Take the conditional expectation with respect to $\\mathcal W(S)$, the history of $W(\\cdot)$, and then condition with respect to the history of $I(\\cdot)$.)\n\n\\paragraph{Solution of Problem 33} Notice that $W^2(t)=(W(t)-W(s))^2-W^2(s)+2W(t)W(s)$, then:\n\\[\\mathbb{E}[W^2(t)-t|\\mathcal W(s)] = (t-s)+W^2(s)-t = W^2(s)-s,\\]\nholds for $\\forall t>s$, which means $\\mathbb{E}[I(t)|\\mathcal W(s)]=I(s)$. Then, we need to take condition with respect to the history of $I(\\cdot)$. Since the conditional expectation above only depends on $W^2(s)$, so:\n\\[\\mathbb{E}[W^2(t)-t|\\mathcal W^2(s)] = W^2(s)-s,\\]\nwhich leads to:\n\\[\\mathbb{E}[I(t)|\\mathcal I(s)] = I(s).\\]\nIt shows us that $I(t)$ is a martingale. \n\n\\paragraph{Problem 34} Suppose $X(\\cdot)$ is a real-valued martingale and $\\Phi:\\mathbb{R}\\rightarrow\\mathbb{R}$ is convex. Assume also that $\\mathbb{E}(|\\Phi(X(t))|)<\\infty$ for all $t\\geqslant 0$. Show that $\\Phi(X(\\cdot))$ is a submartingale. (Hint: Use the conditional Jensen Inequality.)\n\n\\paragraph{Solution of Problem 34} Since $X(\\cdot)$ is a real-valued martingale, we have: for $\\forall t>s$\n\\[\\mathbb{E}(X(t))|\\mathcal F(s))=X(s).\\]\nThen, by using conditional Jensen Inequality, we have:\n\\[\\mathbb{E}(\\Phi(X(t))|\\mathcal F(s))\\geqslant \\Phi(\\mathbb{E}(X(t)|\\mathcal F(s)))=\\Phi(X(s)).\\]\nTherefore, $\\Phi(X(\\cdot))$ is a submartingale.\n\n\\paragraph{Problem 35} Use the Itô chain rule to show that $Y(t):=e^{\\frac{t}{2}}\\cos(W(t))$ is a martingale.\n\n\\paragraph{Solution of Problem 35} By using the Itô chain rule, let $X(t) = W(t)$, we know that: $dX(t)= dW(t)$. Then: $dY(t)=d u(X,t)$ where $u(X,t)=e^{t/2}\\cos X$. Therefore,\n\\begin{equation*}\n\\begin{aligned}\ndY(t)&=du(X,t)=(u_t+\\frac12 u_{xx})dt + u_x dW = \\left(\\frac12 e^{t/2}\\cos X-\\frac12 e^{t/2}\\cos X\\right)dt-e^{t/2}\\sin W(t)dW\\\\\n&= -e^{t/2}\\sin W(t)dW,\n\\end{aligned}    \n\\end{equation*}\nwhich shows us that $Y(t)$ is a martingale.\n\n\n\\paragraph{Problem 36} Let $\\mathbf{W}(\\cdot)=(W^1, \\ldots, W^n)$ be an $n$-dimensional Brownian motion, and write $Y(t):=|\\mathbf{W}(t)|^2-nt$ for times $t\\geqslant 0$. Show that $Y(\\cdot)$ is a martingale. (Hint: Compute $dY$.)\n\n\\paragraph{Solution of Problem 36} We are going to compute $dY(t)$. Since $dW^2 = 2WdW+ dt$, so it's easy for us to compute that:\n\\[dY(t) = \\sum_{i=1}^{N} d(W^i(t))^2 - ndt = \\sum_{i=1}^{N} \\left[2W^i(t) dW^i(t) + dt\\right]-ndt = \\sum_{i=1}^{N} 2W^i(t) dW^i(t),\\]\nwhich shows us that $Y(t)$ is a martingale.\n\n\\paragraph{Problem 37} Show that\n\\[\\int_0^T W^2dW = \\frac13 W^3(T)-\\int_0^T Wdt\\]\nand \n\\[\\int_0^T W^3 dW = \\frac14 W^4(T) - \\frac32 \\int_0^T W^2dt.\\]\n\n\\paragraph{Solution of Problem 37}~\\\\\n(1) By using the Itô's chain rule, we know that:\n\\[dW^3 = 3W^2 dW + 3W dt.\\]\nTherefore:\n\\[W^3(T)=\\int_0^T dW^3(t) = 3\\int_0^T W^2 dW + 3\\int_0^T Wdt~~\\Rightarrow~~\\int_0^T W^2 dW=\\frac13 W^3(T)-\\int_0^T Wdt,\\]\nwhich comes to our conclusion.\\\\\n\n(2) Again by using the Itô's chain rule, we know that:\n\\[dW^4 = 4W^3 dW + 6W^2 dt.\\]\nTherefore:\n\\[W^4(T)=\\int_0^T dW^4(t) = 4\\int_0^T W^3 dW + 6\\int_0^T W^2 dt~~\\Rightarrow~~\\int_0^T W^3 dW=\\frac14 W^4(T)-\\frac32 \\int_0^T W^2 dt,\\]\nwhich comes to our conclusion. \n\n\n\\paragraph{Problem 38} Recall from the text that \n\\[Y := e^{\\int_0^t gdW - \\frac12 \\int_0^t g^2 ds}\\]\nsatisfies \n\\[dY = gYdW.\\]\nUse this to prove \n\\[\\mathbb{E}\\left(e^{\\int_0^T gdW}\\right)=e^{\\frac12 \\int_0^T g^2 ds}.\\]\n\n\n\\paragraph{Solution of Problem 38} Define $F = \\int_0^t gdW - \\frac12 \\int_0^t g^2 ds$, then we know that:\n\\[dF = - \\frac12 g^2 dt + gdW.\\]\nSince $Y=e^F$, we have:\n\\[dY = e^F dF + \\frac12 e^F g^2dt = e^F gdW = gY dW.\\]\nThen, we can conclude that $Y(t)$ is a martingale, which leads to the fact that:\n\\[\\mathbb{E}Y(t)=\\mathbb{E}Y(0)=1~~\\Rightarrow~~\\mathbb{E}\\left(e^{\\int_0^T gdW}\\right)=e^{\\frac12 \\int_0^T g^2 ds}.\\]\n\n\n\\paragraph{Problem 39} Let $u=u(x,t)$ be a smooth solution of the backwards diffusion equation\n\\[u_t+\\frac12 u_{xx}=0,\\]\nand suppose $W(\\cdot)$ is a one-dimensional Brownian motion. Show that for each time $t>0$\n\\[\\mathbb{E}(u(W(t),t)) = u(0,0).\\]\n\n\n\\paragraph{Solution of Problem 39} Let $Y(t) = u(W(t),t)$. By using Itô's chain rule, we know that:\n\\[dY = u_x dW + u_t dt +\\frac12 u_{xx} dt = u_x dW + (u_t+\\frac12 u_{xx})dt = u_x dW.\\]\nTherefore, $Y(t)$ is a martingale, which leads to:\n\\[\\mathbb{E} u(W(t),t)=\\mathbb{E} Y(t) = Y(0)=u(0,0).\\]\n\n\n\\paragraph{Problem 40} Calculate $\\mathbb{E}(B^2(t))$ for the Brownian bridge $B(\\cdot)$, and show in particular that $\\mathbb{E}(B^2(t))\\rightarrow 0$ as $t\\rightarrow 1^{-}$.\n\n\\paragraph{Solution of Problem 40} We have already known that the Brownian bridge has the following formulation:\n\\[B(t)=(1-t)\\int_0^t\\frac{1}{1-s}dW(s).\\]\nThen, we can obtain that:\n\\[\\mathbb{E}[B^2(t)]=(1-t)^2\\cdot\\int_0^t\\frac{1}{(1-s)^2}ds = (1-t)^2\\cdot\\left(\\frac{1}{1-t}-1\\right)=t(1-t).\\]\nFurthermore, it's obvious to verify that when $t\\rightarrow 1^-$, $\\mathbb{E}[B^2(t)]=t(1-t)\\rightarrow 0$, which comes to our conclusion. \n\n\\paragraph{Problem 41} Let $X$ solve the Langevin equation, and suppose that $X_0$ is an $\\mathcal N(0,\\frac{\\sigma^2}{2b})$ random variable. Show that \n\\[\\mathbb{E}[X(s)X(t)]=\\frac{\\sigma^2}{2b}e^{-b|t-s|}.\\]\n\n\n\\paragraph{Solution of Problem 41} According to the formulation of the solution for the Langevin equation, we have:\n\\[X(t) = e^{-bt}X_0+\\sigma\\int_0^t e^{-b(t-c)}dW(c),~~X(s) = e^{-bs}X_0+\\sigma\\int_0^s e^{-b(s-c)}dW(c).\\]\nWithout loss of generality, we assume that $t>s$, then:\n\\[\\mathbb{E}[X(t)X(s)]=e^{-b(t+s)}\\mathbb{E}X_0^2 + \\sigma^2\\cdot\\mathbb{E}\\left[\\int_0^t e^{-b(t-c)}dW(c)\\cdot \\int_0^s e^{-b(s-c)}dW(c)\\right]\\]\nsince the other two terms have expectation 0. Then:\n\\begin{equation*}\n\\begin{aligned}\n&\\mathbb{E}\\left[\\int_0^t e^{-b(t-c)}dW(c)\\cdot \\int_0^s e^{-b(s-c)}dW(c)\\right] \\\\\n&= \\mathbb{E} \\left[\\int_0^s e^{-b(t-c)}dW(c)\\cdot \\int_0^s e^{-b(s-c)}dW(c) + \\int_s^t e^{-b(t-c)}dW(c)\\cdot \\int_0^s e^{-b(s-c)}dW(c)\\right]\\\\\n&= \\int_0^s e^{-b(t+s-2c)}dc + 0 = \\frac{e^{-b(t-s)}-e^{-b(t+s)}}{2b}.\n\\end{aligned}    \n\\end{equation*}\nAlso, $\\mathbb{E}X_0^2 = \\frac{\\sigma^2}{2b}$. To sum up, we finally obtain that:\n\\[\\mathbb{E}[X(s)X(t)]= \\frac{\\sigma^2}{2b}e^{-b(t-s)}= \\frac{\\sigma^2}{2b}e^{-b|t-s|}.\\]\n\n\n\n\\paragraph{Problem 42} (1) Consider the ODE\n\\begin{equation*}\n\\begin{cases}\n\\dot{x} &= x^2~~~(t>0)\\\\\nx(0) &= x_0.\n\\end{cases}    \n\\end{equation*}\nShow that if $x_0 > 0$, the solution \"blows up to infinity\" in finite time.\n\n~\\\\\n(2) Next, look at the ODE\n\\begin{equation*}\n\\begin{cases}\n\\dot{x} &= x^{1/2}~~~(t>0)\\\\\nx(0) &= 0.\n\\end{cases}    \n\\end{equation*}\nShow that this problem has infinitely many nonnegative solutions. \\\\\n(Hint: $x\\equiv 0$ is a solution. Find also a solution which is positive for times $t>0$, and then combine these solutions to find ones which are zero for some time and then become positive.)\n\n\\paragraph{Solution of Problem 42} ~\\\\\n(1) Notice that $\\dot{x}=x^2\\geqslant 0$, which means $x(t)$ is a monotonic function and therefore $x(t)\\geqslant x(0)=x_0 > 0$ holds for all $t\\geqslant 0$. Since:\n\\[\\frac{dx}{dt}=x^2~~\\Rightarrow~~\\frac{dx}{x^2}=dt~~\\int_{0}^T \\frac{dx(t)}{x(t)^2}=T,\\]\nwhere we used $x(t)> 0$. Then we have:\n\\[\\frac{1}{x_0}-\\frac{1}{x(T)}=T~~\\Rightarrow~~x(T)=\\frac{x_0}{1-Tx_0}\\]\nholds for all $T > 0$. Therefore, this solution blows up to infinity at $T=\\frac{1}{x_0}$, which is a finite time. \n\n~\\\\\n(2) Consider the following functions:\n\\[x_{s}(t)=\\begin{cases}&0~~~\\mbox{when $0\\leqslant t \\leqslant s$}\\\\ &\\frac{(t-s)^2}{2}~~~\\mbox{when $t>s$}\\end{cases}.\\]\nHere $s > 0$. Then, we notice that for $\\forall s >0$, function $x_s(t)$ satisfies the given ODE, and it is non-negative, which comes to our conclusion. \n\n\n\n\\paragraph{Problem 43} (1) Use the substitution $X=u(W)$ to solve the SDE\n\\[\\begin{cases}dX&=-\\frac12 e^{-2X}dt+e^{-X}dW\\\\ X(0)&=x_0\\end{cases}.\\]\n\n~\\\\\n(2) Show that the solution blows up at a finite, random time. \n\n\\paragraph{Solution of Problem 43} ~\\\\\n(1) We use the substitution $X=u(W)$, then:\n\\[dX = u'(W(t))dW(t) + \\frac12 u''(W(t))dt.\\]\nWe need: \n\\[u' = e^{-u}, u''=-e^{-2u}, u(0)=x_0.\\]\nThen $u(t)=\\ln(t+e^{x_0})$. To sum up, the solution of the SDE is:\n\\[X(t)=\\ln(W(t)+e^{x_0}).\\]\n\n(2) The blowup time is the following stopping time $\\tau = \\min\\{t : W(t) = -e^{x_0}\\}$. For any positive integer $n$, define the event $E_n := \\{\\tau\\geqslant n\\}$. Then: by using Reflection Theorem, we know that:\n\\[\\mathbb{P}\\{E_n\\} = \\mathbb{P}\\{|W(n)| < e^{x_0}\\}=2\\Phi\\left(\\frac{e^{x_0}}{\\sqrt{n}}\\right).\\]\nAlso, it is obvious that $E_1 \\supseteq E_2 \\supseteq \\ldots$, and when $n\\rightarrow \\infty$, we have:\n\\[\\lim_{n\\rightarrow\\infty}\\mathbb{P}\\{E_n\\}=0,\\]\nwhich means:\n\\[0=\\mathbb{P}\\left\\{\\lim_{n\\rightarrow\\infty}E_n\\right\\}=\\mathbb{P}\\{E\\}\\]\nwhere $E:=\\{\\tau=+\\infty\\}$. It means the solution blows up at time $\\tau$, which is a random time. With probability 1, this time is finite. \n\n\n\n\\paragraph{Problem 44} Solve the SDE $dX=-Xdt+e^{-t}dW$.\n\n\\paragraph{Solution of Problem 44} We use the substitution $X=e^{-t}W(t)+f(t)$, then:\n\\[dX = -e^{-t}W(t)dt+e^{-t}dW(t) + f'(t)dt = e^{-t}dW(t) + (-e^{-t}W(t)+f'(t))dt.\\]\nNow we just need $f(t)=-f'(t)~\\Rightarrow~ f(t)=Ae^{-t}$. To sum up, the solution of the SDE is:\n\\[X = e^{-t}W(t)+Ae^{-t},\\]\nwhere $A=X(0)$ can be any real constant. \n\n\n\n\\paragraph{Problem 45} Let $\\mathbf{W}=(W^1,W^2,\\ldots, W^n)$ be an $n$-dimensional Brownian motion and write \n\\[R := |\\mathbf{W}|=\\left(\\sum_{i=1}^{n}(W^i)^2\\right)^{1/2}.\\]\nShow that $R$ solves the stochastic Bessel equation\n\\[dR=\\frac{n-1}{2R}dt+\\sum_{i=1}^{n}\\frac{W^i}{R}dW^i.\\]\n\n\\paragraph{Solution of Problem 45} Denote function  $F:\\mathbb{R}^n\\rightarrow\\mathbb{R}$ as $F(x):= \\|x\\|_2$. Then:\n\\[F_k'(x)=\\frac{x_k}{\\|x\\|_2},~~F_{kk}''(x)=\\frac{\\|x\\|_2^2-x_k^2}{\\|x\\|_2^3}.\\]\nAccording to Itô's chain rule, it holds that:\n\\[dR = \\frac{1}{R}\\sum_{i=1}^{n} W^i dW^i + \\frac{1}{2R^3}\\sum_{i=1}^{n}(R^2-x_k^2) dt = \\sum_{i=1}^{n}\\frac{W^i}{R}dW^i + \\frac{nR^2-R^2}{2R^3}dt = \\frac{n-1}{2R}dt+\\sum_{i=1}^{n}\\frac{W^i}{R}dW^i,\\]\nwhich comes to our conclusion.\n\n\\paragraph{Problem 46} (1) Show that $\\mathbf{X}=(\\cos(W),\\sin(W))$ solves the system of SDE\n\\[\\begin{cases}dX^1&=-\\frac12 X^1dt-X^2dW\\\\ dX^2&=-\\frac12 X^2 dt+X^1 dW\\end{cases}.\\]\n(2) Show also that if $\\mathbf{X}=(X^1,X^2)$ is any other solution, then $|\\mathbf{X}|$ is constant in time.\n\n\\paragraph{Solution of Problem 46} ~\\\\\n(1) We only need to verify the SDE solution. \n\\[dX^1 = d\\cos(W) = -\\sin(W) dW -\\frac12 \\cos(W) dt = -X^2 dW -\\frac12 X^1 dt.\\]\n\\[dX^2 = d\\sin(W) = \\cos(W) dW -\\frac12 \\sin(W) dt = X^1 dW - \\frac12 X^2 dt.\\]\n(2) Denote $F = (X^1)^2 + (X^2)^2$, then:\n\\begin{equation*}\n\\begin{aligned}\ndF &= 2X^1 dX^1 + (X^2)^2 dt + 2X^2 dX^2 + (X^1)^2 dt\\\\\n&= 2X^1(-X^2 dW -\\frac12 X^1 dt) + 2X^2(X^1 dW - \\frac12 X^2 dt) + Fdt \\\\\n&= -Fdt + Fdt = 0\n\\end{aligned}    \n\\end{equation*}\nTherefore, $F=|\\mathbf{X}|^2$ is constant in time, which leads to the fact that $|\\mathbf{X}|$ is also constant in time. \n\n\\paragraph{Problem 47} Solve the system \n\\[\\begin{cases} dX^1 &= dt+dW^1\\\\ dX^2 &= X^1 dW^2,\\end{cases}\\]\nwhere $\\mathbf{W}=(W^1, W^2)$ is a Brownian motion. \n\n\\paragraph{Solution of Problem 47} From the first equation, we easily know that \n\\[X^1 = t+W^1(t)+c_1\\]\nwhere $c_1$ can be any real constant. Then, $X^2$ satisfies:\n\\[dX^2 = (t+c_1+W^1(t))dW^2.\\]\nWe can simply write down the following formulation:\n\\[X^2 = c_1W^2(t) + c_2 + \\int_{0}^t (s+W^1(s))dW^2(s).\\]\nTo sum up, the solution of the SDE is:\n\\begin{equation*}\n\\begin{cases}\nX^1 &= t+W^1(t)+c_1\\\\\nX^2 &= c_1 W^2(t) + c_2 + \\int_0^t (s+W^1(s))dW^2(s).\n\\end{cases}    \n\\end{equation*}\n\n\\paragraph{Problem 48} Solve\n\\begin{equation*}\n\\begin{cases}\ndX^1 &= X^2 dt + dW^1\\\\\ndX^2 &= X^1 dt + dW^2.\n\\end{cases}    \n\\end{equation*}\n\n\n\\paragraph{Solution of Problem 48} Denote $W_1 := \\frac{W^1+W^2}{\\sqrt{2}}, W_2 := \\frac{W^1-W^2}{\\sqrt{2}}$. Also, we denote $X=X_1+X_2, Y=X_1-X_2$. Then, $\\{W_1(t)\\}, \\{W_2(t)\\}$ are Brownian motions. After adding the two equations above, we obtain that:\n\\[dX = Xdt + \\sqrt{2}dW_1,\\]\nwhich is a Langevin equation. The solution is:\n\\[X = e^t\\left(c_1 + \\sqrt{2}\\int_0^t e^{-s}dW_1(s)\\right)= e^t\\left(c_1 + \\int_0^t e^{-s}dW^1(s)+\\int_0^t e^{-s}dW^2(s)\\right).\\]\nSimilarly, after subtracting the two equations above, we obtain that:\n\\[dY = -Ydt + \\sqrt{2}dW_2,\\]\nwhich is also a Langevin equation. The solution is:\n\\[Y = e^{-t}\\left(c_2 + \\sqrt{2}\\int_0^t e^{s}dW_2(s)\\right)= e^{-t}\\left(c_2 + \\int_0^t e^{s}dW^1(s)-\\int_0^t e^{s}dW^2(s)\\right). \\]\nTherefore, the solution of this SDE is:\n\\[\\begin{cases}\nX^1 &= \\frac{c_1 e^t + c_2 e^{-t}}{2} + \\int_0^t \\frac{e^{t-s}+e^{s-t}}{2}dW^1(s) + \\int_0^t \\frac{e^{t-s}-e^{s-t}}{2}dW^2(s)\\\\\nX^2 &= \\frac{c_1 e^t - c_2 e^{-t}}{2} + \\int_0^t \\frac{e^{t-s}-e^{s-t}}{2}dW^1(s) + \\int_0^t \\frac{e^{t-s}+e^{s-t}}{2}dW^2(s).\n\\end{cases}\\]\n\n\\paragraph{Problem 49} Solve\n\\[\\begin{cases}\ndX &= \\frac12 \\sigma'(X)\\sigma(X)dt + \\sigma(X) dW\\\\\nX(0) &= 0\n\\end{cases}\\]\nwhere $W$ is a one-dimensional Brownian motion and $\\sigma$ is a smooth, positive function.\\\\\n(Hint: Let $f(x):=\\int_0^x \\frac{dy}{\\sigma(y)}$ and set $g:=f^{-1}$, the inverse function of $f$. Show that $X=g(W)$.)\n\n\n\\paragraph{Solution of Problem 49} Denote function $f(x):=\\int_0^x \\frac{dy}{\\sigma(y)}$ and $Y = f(X)$. Then $Y(0)=0$ and \n\\begin{equation*}\n\\begin{aligned}\ndY &= f'(X) dX + \\frac12 f''(X)\\cdot\\sigma^2(X) dt = \\frac{1}{\\sigma(X)}dX -\\frac{\\sigma'(X)}{2\\sigma^2(X)}\\cdot  \\sigma^2(X) dt\\\\\n&= \\frac12 \\sigma'(X)dt + dW - \\frac12 \\sigma'(X)dt = dW.\n\\end{aligned}    \n\\end{equation*}\nSince $Y(0)=0$, we have: $Y(t)=W(t)$. Therefore, the solution of the SDE is:\n\\[X = f^{-1}(Y)=g(W).\\]\n\n\n\\paragraph{Problem 50} Let $\\tau$ be the first time a one-dimensional Brownian motion hits the half-open interval $(a,b]$. Show that $\\tau$ is a stopping time. \n\n\\paragraph{Solution of Problem 50} We are going to prove $\\tau$ is a stopping time by the definition. When $a<0\\leqslant b$, we have $\\tau=0$, which means for $\\forall t \\geqslant 0$, the event $\\{\\tau\\leqslant t\\}$ is always true. When $a\\leqslant 0$, it holds that:\n\\[\\{\\tau> t\\} = \\{\\forall s\\leqslant t, W(s)\\leqslant a\\}\\in \\mathcal F(t).\\]\nWhen $b>0$, it holds that:\n\\[\\{\\tau> t\\} = \\{\\forall s\\leqslant t, W(s)>b\\}\\in \\mathcal F(t).\\]\nTo sum up, $\\tau$ is a stopping time, which comes to our conclusion.\n\n\\paragraph{Problem 51} Let $\\mathbf{W}$ denote an $n$-dimensional Brownian motion for $n\\geqslant 3$. Write $\\mathbf{X}=\\mathbf{W}+x_0$, where the point $x_0$ lies in the region $U=\\{0<R_1<|x|<R_2\\}$. Calculate explicitly the probability that $\\mathbf{X}$ will hit the outer sphere $\\{|x|=R_2\\}$ before hitting the inner sphere $\\{|x|=R_1\\}$. \\\\\n(Hint: Check that\n\\[\\Phi(x)=\\frac{1}{|x|^{n-2}}\\]\nsatisfies $\\Delta\\Phi=0$ for $x\\neq 0$. Modify $\\Phi$ to build a function $u$ which equals 0 on the inner sphere and 1 on the outer sphere. \n\n\\paragraph{Solution of Problem 51} Suppose the probability function we want is $u(x)$ where $R_1<|x|<R_2$. Then the function $u$ satisfies the following conditions.\n\\begin{equation*}\n\\begin{cases}\n\\nabla u &= 0\\\\\nu(x) &= 0 \\mbox{$|x|=R_1$}\\\\\nu(x) &= 1 \\mbox{$|x|=R_2$}\n\\end{cases}    \n\\end{equation*}\nAs we see, for $\\Phi(x)=\\frac{1}{|x|^{n-2}}$, we have:\n\\[\\frac{\\partial}{\\partial x_i}\\Phi(x) =\\sum_{i=1}^{n}-\\frac{(n-2)x_i}{|x|^n},~\\frac{\\partial^2}{\\partial x_i^2}\\Phi(x) =\\sum_{i=1}^{n}-\\frac{(n-2)}{|x|^n}+\\frac{n(n-2)x_i^2}{|x|^{n+2}}.\\]\nTherefore:\n\\[\\Delta\\Phi = \\sum_{i=1}^{n}-\\frac{(n-2)}{|x|^n}+\\frac{n(n-2)x_i^2}{|x|^{n+2}} = -\\frac{n(n-2)}{|x|^n}+\\frac{n(n+2)}{|x|^n}=0.\\]\nSo, for any constant $a,b$, we have $\\Delta(a\\Phi+b)=0$. Let \n\\[a = -\\frac{R_1^{n-2}R_2^{n-2}}{R_2^{n-2}-R_1^{n-2}},~b=\\frac{R_2^{n-2}}{R_2^{n-2}-R_1^{n-2}}.\\]\nThen, function $a\\Phi+b$ meets our satisfaction. To sum up, the probability function we need is:\n\\[u(x)=\\frac{R_2^{n-2}}{R_2^{n-2}-R_1^{n-2}}\\cdot\\left(1-\\frac{R_1^{n-2}}{|x|^{n-2}}\\right).\\]\n\n\\end{document}\n", "meta": {"hexsha": "6e2b38c1def3364d2acc1660512fc55b5b913354", "size": 58551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic-Differential-Equations/main.tex", "max_stars_repo_name": "ZehaoDou-official/Solutions-for-Math-Textbooks", "max_stars_repo_head_hexsha": "17358104674242ebc7b52c54a91072d53ebf2630", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2021-11-10T09:37:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T04:10:15.000Z", "max_issues_repo_path": "Stochastic-Differential-Equations/main.tex", "max_issues_repo_name": "ZehaoDou-official/Solutions-for-Math-Textbooks", "max_issues_repo_head_hexsha": "17358104674242ebc7b52c54a91072d53ebf2630", "max_issues_repo_licenses": ["MIT"], "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-Differential-Equations/main.tex", "max_forks_repo_name": "ZehaoDou-official/Solutions-for-Math-Textbooks", "max_forks_repo_head_hexsha": "17358104674242ebc7b52c54a91072d53ebf2630", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-10T13:54:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-15T04:06:41.000Z", "avg_line_length": 63.7810457516, "max_line_length": 655, "alphanum_fraction": 0.6436440027, "num_tokens": 24011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8962513641273354, "lm_q1q2_score": 0.6660653414947315}}
{"text": "\\chapter{Background}\n\\label{chapter:overview}\n\nWe define term rewriting systems and give some background. We briefly describe Halide and the Halide expression language we will be operating on throughout this work. We then describe the uses of term rewriting systems within the Halide compiler, including the term rewriting algorithm used by the compiler, the requirements that led to its design choices, and the two term rewriting systems we use as case studies in this work, the simplifier and the variable solver.\n\n\\section{Term Rewriting Systems}\n\nTerm rewriting systems~\\citep{gorn1967} are sets of \\textit{rewrite rules} used to transform expressions into a new form.  Such systems are widely\nused in theorem proving~\\citep{baader1999term} and abstract interpretation~\\citep{cousot1977abstract, cousot1979systematic}.\n\nTerms are defined inductively over a set of variables $V$ and a set of function symbols $\\Sigma$. Every variable $v \\in V$ is a term, and for any function symbol $f \\in \\Sigma$ with arity $n$ and any terms $t_1, ..., t_n$, the application of the symbol to the terms $f(t_1, ..., t_n)$ is also a term. (Constants are considered zero-arity functions.) We refer to the set of terms constructed from the variables $V$ and the function symbols $\\Sigma$ as $T(\\Sigma, V)$.\n\nA \\emph{rewrite rule} is a directed binary relation $l \\rewrites r$ such that $l$ is not a variable, and all variables present in $r$ are also present in $l$ (i.e., $\\mathcal{V}ar(l) \\supseteq \\mathcal{V}ar(r)$). A set of rewrite rules is called a \\emph{term rewriting system}.\n\nConsider a set of terms $T(\\Sigma, V)$ such that $\\Sigma = \\{\\clubsuit, \\diamondsuit\\}$ and $V$ is an infinite set of variables. \n\\newpage\nLet the term rewriting system $R$ consist of a single rule:\n\n\\[ R = \\{ x_1 \\clubsuit x_2 \\rewrites x_1 \\diamondsuit x_2 \\} \\]\nWe use $R$ to rewrite the term\n\n\\[ \n(y_1 \\diamondsuit y_1) \\clubsuit (y_2 \\clubsuit y_3)\n\\]\nThe first step is matching; we find a substitution that will unify the left-hand side (LHS) of the rule with the term we are rewriting. Here, one possible substitution is:\n\n\\[\n\\{ x_1 \\mapsto (y_1 \\diamondsuit y_1), x_2 \\mapsto (y_2 \\clubsuit y_3) \\}\n\\]\nWe then apply this substitution to the right-hand side (RHS) of the rule to obtain the rewritten version of the original term:\n\n\\[ \n(y_1 \\diamondsuit y_1) \\diamondsuit (y_2 \\clubsuit y_3)\n\\]\n\n\\section{Halide and the Halide expression language}\n\nThe Halide compiler contains term rewriting systems that manipulate terms in the Halide expression language. This language\noperates over vectors and scalars of integers, booleans, and real values.  However, in\nthis work we concentrate on the TRS as it applies to integer and boolean values, for\nboth vectors and scalars, because the most important uses of the TRS within the compiler\napply to these types.\nThe Halide expression language contains the usual arithmetic operators and uses the Euclidean definition for division and modulo. It also contains the boolean operators and, or, and not, as well as the usual comparators. The \\texttt{select} operator takes three arguments and behaves like an if-then-else statement, returning the second argument if its first evaluates to true and the third argument otherwise. There are two operators that can create vectors from scalars: $\\texttt{broadcast}(v, s)$, which creates a vector of size $s$ with each value initialized to $v$, and $\\texttt{ramp}(v, s, k)$, which creates a vector of size $s$ where the first value is initialized to $v$ and each subsequent value is increased by the stride $k$. Most operators that take integer or boolean arguments can also take vector arguments whose values are integer or boolean type respectively. For the full Halide expression grammar, see appendix~\\ref{a:grammar}.\n\n\\section{Term rewriting systems in the Halide compiler}\n\n\n\\begin{figure*}\n\\centering\n\\begin{tabular}{cccc}\n\n%\\Tree [.+ [.- [.min a b ] [.max c c ] ] [.max c c ]]\n\\begin{tikzpicture}[level distance=12mm]\n\\tikzstyle{level 1}=[sibling distance=15mm]\n\\tikzstyle{level 2}=[sibling distance=10mm]\n\\tikzstyle{level 3}=[level distance=10mm,sibling distance=5mm]\n\n\n%\\Tree [.+ [.- [.min a b ] c ] [.max c c ]]\n\\node (+) {+}\n  child { node (-) {-}\n    child { node (min) {\\hmin}\n      child {node (a) {a}}\n      child {node (b) {b}}\n    }\n    child { node (max2) {\\hmax}\n      child {node (c4) {c}}\n      child {node (c5) {c}}\n    }\n  }\n  child { node (max) {\\hmax}\n    child { node (c2) {c}}\n    child { node (c3) {c}}\n  };\n\\begin{pgfonlayer}{background}\n\\fill[red,opacity=0.3] \\convexpath{c4,max2,c5}{10pt};\n\\end{pgfonlayer}\n\\end{tikzpicture}\n\n&\n\\begin{tikzpicture}[level distance=12mm]\n\\tikzstyle{level 1}=[sibling distance=15mm]\n\\tikzstyle{level 2}=[sibling distance=7mm]\n\\tikzstyle{level 3}=[level distance=10mm,sibling distance=5mm]\n%\\Tree [.+ [.- [.min a b ] c ] [.max c c ]]\n\\node (+) {+}\n  child {  node (-) {-}\n    child { node (min) {\\hmin}\n      child {node (a) {a}}\n      child {node (b) {b}}\n    }\n    child { node (c) {c}}\n  }\n  child { node (max) {\\hmax}\n    child { node (c2) {c}}\n    child { node (c3) {c}}\n  };\n\\begin{pgfonlayer}{background}\n\n\\fill[blue,opacity=0.3] \\convexpath{c2,max,c3}{10pt};\n%\\fill[red,opacity=0.3] \\convexpath{c}{10pt};\n\\draw[fill=red,opacity=0.3,draw=none](c) circle (10pt);\n\n\\end{pgfonlayer}\n\\end{tikzpicture}\n&\n\\begin{tikzpicture}[level distance=12mm]\n\\tikzstyle{level 1}=[sibling distance=15mm]\n\\tikzstyle{level 2}=[sibling distance=10mm]\n\\tikzstyle{level 3}=[level distance=10mm,sibling distance=5mm]\n%\\Tree [.+ [.- [.min a b ] c ] c ]\n\\node (+) {+}\n  child { node (-) {-}\n    child { node (min) {\\hmin}\n      child {node (a) {a}}\n      child {node (b) {b}}\n    }\n    child { node (c) {c} }\n  }\n  child { node (c2) {c}};\n\n\n\n  \\begin{pgfonlayer}{background}\n\\fill[green,opacity=0.3] \\convexpath{b,a,min,-,+,c2,c}{10pt};\n\\draw[fill=blue,opacity=0.3,draw=none](c2) circle (10pt);\n%\\draw[red,fill=blue,opacity=0.3](c2.north) to[closed,curve through={($(c2.north east)!1.0!(c2.south east)$) .. ($(c2.south west)!1.0!(c2.north west)$)}] (c2.north);\n\\end{pgfonlayer}\n\\end{tikzpicture}\n&\n\\vspace{0pt}\n\\begin{tikzpicture}[level distance=12mm]\n\\tikzstyle{level 1}=[sibling distance=15mm]\n\\tikzstyle{level 2}=[sibling distance=10mm]\n\\tikzstyle{level 3}=[level distance=10mm,sibling distance=5mm]\n\\node (min) {\\hmin}\n  child { node (a) {a}\n     % [red,opacity=0.0]\n    child {     [red,opacity=0.0] node (fake1) {f}\n      child {    [red,opacity=0.0] node (fake2) {f}}\n      child {    [red,opacity=0.0] node (fake3) {f}}\n    }\n    child {     [red,opacity=0.0] node (fake4) {f}\n    [red,opacity=0.0]\n    child { [red,opacity=0.0] node (fake) {f}}\n    child { [red,opacity=0.0] node (fake2) {f}}\n    }\n  }\n  child { node (b) {b}\n     % [red,opacity=0.0]\n    child {     [red,opacity=0.0] node (fake5) {f}}\n    child {     [red,opacity=0.0] node (fake6) {f}}\n  };\n  \\begin{pgfonlayer}{background}\n\\fill[green,opacity=0.3] \\convexpath{a,min,b}{10pt};\n\\end{pgfonlayer}\n\n\\end{tikzpicture} \\\\\n(i) & (ii) & (iii) & (iv)\n\\end{tabular}\n\\caption{We demonstrate the Halide rewriting algorithm using a TRS $R = \\{\\hmax(x, x) \\rewrites x, (x - y) + y \\rewrites x\\}$ and an expression $\\hmin(a,b) - \\hmax(c,c) + \\hmax(c,c)$. The algorithm attempts to simplify all subtrees bottom up; here, no rule applies to $\\hmin(a,b)$ so it is not changed. Next (i), rule 1 rewrites $\\hmax(c,c)$ to $c$. No rule applies to $\\hmin(a,b) - c$, so we move to the rightmost subtree and rewrite again (ii) to obtain $c$ from $\\hmax(c,c)$. Finally, we consider the entire tree $\\hmin(a,b) - c) + c$ (iii) and apply rule 2 to produce $\\hmin(a,b)$. No rules match this expression, so we are left with $\\hmin(a,b)$ (iv).}\n\\label{fig:algoexample}\n\\end{figure*}\n\n\\subsection{The Halide rewriting algorithm}\n\\label{sec:customalgo}\n\nA term rewriting system is simply a set of rewrite rules; when we use a TRS to transform an expression, we also need to define a procedure for \napplying those rewrite rules to the expression.  In a TRS, a single rule may be able to match an input expression in \nmultiple ways, and there may be multiple rules in the ruleset which could be used \nto rewrite the expression. A term rewriting algorithm might choose one of many alternatives \nand later backtrack if it turns out not to be fruitful; it might make use of \nheuristics to choose a next step; it might exercise all the alternatives and keep \nthe results in equivalence classes, as in an e-graph. The Halide term rewriting algorithm\nkeeps only one expression in state and applies rules greedily, in a fixed priority.\nThis is very fast and requires very little memory; the tradeoff is that the algorithm \nmay pick the ``wrong'' rule and have no way of undoing that decision. \nSince the rewriter is invoked thousands of times with each call of the compiler, \nit chooses to sacrifice some solving power in exchange for performance.\n\nThe Halide term rewriting algorithm simplifies an input expression in a\ndepth-first, bottom-up traversal of the expression AST. At each node, it \nuses the root node to pick a list of rules, then\nattempts to match the subtree expression with the rule LHSs in a fixed priority. Matching\nis performed purely syntactically, using C++ template metaprogramming.\n Halide rewrite rules contain special metavariables,\ncalled \\emph{symbolic constants}, that can match only with constant values; all other\nvariables can match any subterm as usual.\nWhen a match is found, the algorithm rewrites the\nsubtree expression using the RHS of that rule, and then recurses and starts applying rewrites on the newly rewritten expression. If no rule matches the subtree, the traversal\ncontinues; when the entire expression cannot be simplified further, the\nrewritten expression is returned. See Figure~\\ref{fig:algoexample} for a worked\nexample.\n\nThe rewrite rules optionally contain a predicate guard. \nThese guards contain only special variables whose values are known at the time of rule application\\footnote{Existing \nrules sometimes have predicates that check if\n  non-constant variables can be shown to have certain properties at compile\n  time, but these are expensive and used sparingly.}; when the LHS of a rule\nmatches an expression, its guard is evaluated and only if it\nis true will the rewrite be applied.\n\nHalide rewrite rules are applied in a fixed priority, organized so that the TRS \nfirst attempts very basic rules such as constant folding, then tries more specific \nrules before more general ones. (We do not evaluate the current rule priority in this work.)\n\nAssociativity and commutativity laws are particularly troublesome for term rewriting systems. \nFor one expression $e$, the number of semantically equivalent expressions grows \nexponentially in terms of the number of AC operations $e$ contains. Some term rewriting \nsystems perform a full \\emph{AC matching} step during rewriting. Halide's TRS does not\nperform this matching, but instead\nincludes multiple AC variations of rules.\nHowever, a small number of Halide's rewrite rules have the effect of canonicalizing some commutative\nexpressions. (For example, if a commutative expression has a multiplication as its \nfirst operand and a subtraction as its second operand, a rule will switch their positions.)\nThese rules are all early in the application priority, so later rules can rely on\nexpressions having a quasi-canonical form.\n\n\\subsection{The rewriting algorithm's design requirements}\n\nBecause a reasoning engine implemented as a term rewriting system may be invoked thousands of times in a single compilation, the rewriting algorithm outlined above was designed to be fast and use very little memory. For that reason the algorithm is non-backtracking and keeps only one expression in state, sacrificing some potential solving power for performance. \nIn this work, we operate within the scope of Halide's TRS algorithm\n  and work to make the TRSs used by that algorithm as correct, general, and robust as possible.  Because\n  the space of expressions we consider constitutes an undecidable theory, any complete\n  TRS is impossible.  Instead, we strive to improve correctness by ensuring the TRSs\n  will always terminate on any expression and that each individual rewrite\n  preserves semantics; and we improve generality by expanding the rulesets to\n  contain rewrites that apply to real-world expressions, rather than\n  arbitrary new rules that may not apply to any expressions the compiler will encounter.\n\nThese improvements require overcoming challenging obstacles.  First,\n  we must perform a post-hoc verification of a large body of existing rules;\n  proving a subset of rules correct or that a subset of rules do not result in infinite\n  rewriting loops is insufficient to guarantee robust behavior.  Secondly,\n  these rewrites operate in an undecidable theory, making automated verification\n  difficult.  Finally, because of this undecidability, we cannot necessarily\n  rely on traditional automated techniques to discover new rules.\n\n\\begin{table}\n\\caption{We compare the performance of Z3 and the Halide TRS in proving a set of 4304 expressions gathered from realistic compiler output. Note that expressions in the ``not proven'' column include expressions that are true but not found to be so by the solvers as well as expressions that are not true. }\n\\centering\n\\begin{tabular}{l|r|r|r}\nTool & Runtime & Proven expressions & Not proven \\\\\n\\hline\nZ3 & 7m29s & 1125 & 3179 \\\\\nHalide TRS & 2s & 885 & 3419 \n\\end{tabular}\n\\label{tab:simplifiervsz3}\n\\end{table}\n\n\nGiven that we make use of the Z3 solver~\\citep{de2008z3} for both verification and synthesis, it is natural to ask why Halide could not simply call Z3 as its reasoning engine. Z3 is the product of extensive development and is a very powerful, general-purpose solver. However, the Halide term rewriting system has a few key properties that Z3 does not: deterministic output, low memory and compute requirements, and domain-specific optimizations.\n\nAs discussed above, the Halide compiler must return the same schedule every time the same pipeline is run. Z3 can fix a random seed, but long-running queries may complete on a more powerful server while timing out on a different machine.\n\nWhile the Halide algorithm is less powerful than Z3, its deterministic, greedy rule application strategy\ngives it a smooth performance curve, whether it succeeds or fails in simplifying an input expression.\nA solver like Z3 tends to give very good performance most of the time but gets bogged down in difficult cases, requiring the use of timeouts. The Halide algorithm ``fails fast'': on an input expression which does not match any rule,  the Halide algorithm will complete in time linear to the size of the expression, taking on the order of one CPU cycle per term in the expression per rule in the TRS. To demonstrate this performance tradeoff, we gathered 4304 expressions from queries the Halide compiler made when compiling realistic pipelines, including both provably true expressions and expressions that are not provably true. Z3 could prove approximately 30\\% more expressions true (within a 60 second timeout), but was starkly less performant. As shown in Table~\\ref{tab:simplifiervsz3}, Z3 took over 7 minutes to check the set of expressions while the Halide TRS took just 2 seconds. This set of expressions is much smaller than the number of calls the compiler makes to the rewriter in compiling a single pipeline.\n\nBecause the Halide algorithm at every step chooses one rule to apply to the single expression it is working on, it scales well in terms of the number of rules in the TRS. See Section~\\ref{ssec:compilationspeed} for an evaluation of the effects of adding newly synthesized rules on the performance of the compiler. \n\nFinally, Z3 is a very powerful general-purpose solver, but Halide TRSs can be targeted for their specific use cases. For example, when rewriting an expression to be shorter, gathering like terms in some cases can actually prevent Halide or LLVM optimizations from applying. The Halide TRSs use domain-specific strategies to guide expressions into more optimizable forms and can be changed or tuned as needed if further optimizations are discovered. \n\n\n\\subsection{The Simplifier}\n\\label{sec:uses-of-trs}\n\nTo compile an image processing pipeline written in the\n  Halide language, the compiler must perform a variety of analyses of\n  the pipeline's properties. For example, if the user marks a\n  loop to be fully unrolled, the compiler must infer a constant upper\n  bound for the extent of the loop. If the user marks\n  a loop as parallel, the compiler must prove the absence of data\n  races. These analyses also affect performance more than in most\n  compilers. In Halide, the compiler infers loop bounds and allocation sizes.\n  If these are overestimated, the generated code may\n  perform an amount of wasted work sufficient to alter the\n  computational complexity of the algorithm. These analyses all depend\n  critically on the quality of Halide's expression simplifier. In\n  fact, Halide relies so heavily on its simplifier that restricting it\n  to mere constant-folding causes a geomean 5.1$\\times$ increase in\n  compilation times and a 26.4$\\times$ increase in runtimes across\n  Halide's benchmark suite.  \n\nWhile the Halide compiler makes use of the TRS in numerous ways, the most important\n  applications of the TRS are its uses as a fast simplifier and as a proof engine.  \n  In many parts of the compiler, the TRS is used to rewrite expressions into simpler forms,\n  which are easier for the compiler to reason about, and result in less code being generated for\n  LLVM to consume at the backend.  Most importantly, the compiler uses the TRS to simplify expressions\n  into constants or expressions that are monotonic with respect to loop bounds; these simplifications are core to Halide's\n  ability to generate drastically different loop nests for different schedules.\n\nFor example, consider the simple two-stage imaging pipeline $g(x) = f(x - 1) + f(x) + f(x + 1)$.\n  Halide enables programmers to fuse the computation of $f$ into $g$ at an arbitrary granularity\n  using the \\texttt{compute\\_at} scheduling directive.  This requires Halide to automatically reason\n  about which region of $f$ is required for a specific sub-region (or tile) of $g$, using interval\n  arithmetic over symbolic values for the size of a tile of $g$.  For a tile size of 8, a tile of $g$\n  is the region \\texttt{[g.tile\\_min, g.tile\\_min+7]};  the region of $f$ required is\n  \\texttt{[g.tile\\_min-1, g.tile\\_min+8]}; and the number of values of $f$ to compute is then\n  \\texttt{g.tile\\_min + 8 + 1 - (g.tile\\_min - 1)}.  If the TRS can determine this is a static value\n  of 10, the Halide compiler can then safely perform transformations requested by the user.  In this\n  case, the compiler can use stack memory instead of inserting a dynamic allocation; or the loop can be\n  completely unrolled; the loop can be vectorized; or $f$ can be mapped to GPU threads (since a single\n  threadblock must have a compile-time-known size).  More generally, this kind of region analysis\n  operates most effectively when the expressions are monotonic in the loop bounds; otherwise, interval\n  arithmetic can result in vast overestimates of required regions.  These simplifications are essential\n  for the compiler to work, and are usually not as simple as this example.\n\nThe rules for simplifying to perform cancellations and\n  ensure monotonicity are incredibly important for compiler\n  performance. When we disabled all but the constant-folding rules to\n  measure the importance of the simplifier, it was the absence of\n  these specific rules that caused the (26.4$\\times$) slow-down\n  mentioned in Section~\\ref{sec:intro}. Without these rules,\n  Halide is useless for high-performance image\n  processing.\n\n%% Fodder from synthesis section:\n%% For example, Halide relies on symbolic interval arithmetic to determine how much memory\n%% to allocate and how many values to compute for each stage.  Symbolic interval arithmetic\n%% is exact when an expression monotonically increases or decreases over a loop.}\n%% For example, if $x \\in [0, 100]$, then symbolic interval arithmetic states that\n%% $\\hmax(x, x/2 + 20) \\in [20, 100]$, which is the tightest correct\n%% bound; this bound is obtained by substituting in the lower and upper bounds of $x$\n%% into the expression. However, in the presence of anti-correlated subexpressions\n%% interval arithmetic becomes inexact, and is prone to overestimating\n%% bounds. The expression $\\hmin(x, 100 - x)$ when $x \\in [0, 100]$ is bounded above by 50, but\n%% symbolic interval arithmetic makes the weaker claim that it is bounded\n%% above by 100, by setting the first instance of $x$ to 100 and the\n%% second instance of $x$ to zero.\n\nThe use as a proof engine occurs when the compiler must prove properties about the code in order to guarantee the\n  correctness of specific transformations or the relationships between bounds of\n  different loops or producer-consumer relationships.  In such cases, the compiler constructs\n  an expression that must be true (or false) in order to guarantee correctness, then applies\n  the TRS to see if the expression simplifies to a single constant boolean value.\n\nFor example, Halide uses Euclidean division, which rounds according to the sign of the\n  denominator.  Lowering this to code requires emitting several instructions, which can be\n  slower than native division.  When the compiler can statically prove the signs of the numerator\n  and denominator, in some cases the code can be replaced by native division or even a different\n  instruction altogether.  For example, for an expression \\texttt{x / max(y, 1)} the compiler\n  will try to prove $0 < \\hmax(y, 1)$.  The TRS first invokes a rule to transform this to\n  $0 < y\\; ||\\; 0 < 1$, which then is transformed to true (since the second clause is always true).\n  Thus, the compiler is able to replace Euclidean division with machine division.\n\nSimplifier failures have adverse results on the compiler, making it unpredictable and\n  thus difficult for Halide program authors to reason about the performance of their schedules.  \n  When the TRS fails to properly simplify an expression or\n  prove a property, the consequences include: \n\\begin{itemize}\n\\item Insufficiently tight bounds on loops and allocations, which may result in\n  runtime failures (e.g. due to memory overallocation) or performance issues;\n\n\\item Failure of the compiler to apply optimizations, also resulting in slow performance;\n\n\\item Dynamic checks in the generated code for properties that could have been proven\n  at compile time, leading to slower code;\n\n\\item Compilation failures, when the compiler is unable to correctly produce code\n  even though the properties required hold, or when the proof engine itself crashes\n  or loops infinitely.\n\\end{itemize}\n\nThus, correctness and generality of the simplifier are essential qualities for making the compiler\nrobust and able to generate fast code.\n\n\\subsection{The Variable Solver}\n\\label{sec:thevariablesolver}\n\nThe Halide compiler contains a $\\texttt{SolveExpression}$ class that implements functionality that we will refer to as a variable solver in this work. It takes an expression and a variable name as inputs and `solves' the expression for that variable, isolating it on the left of an expression.\n\n$\\texttt{SolveExpression}$ currently rewrites expressions using a recursive visitor that ``matches'' the expression using if statements. We have translated this into a term rewriting system that contains about a hundred rules. This system is much smaller and less mature than the simplifier, and using synthesis to author new rulesets will potentially result in much bigger performance gains than we saw with the more highly optimized simplifier.\n\nWe formally define the purpose of the variable solver as follows. Let $|t|_x$ represent the number of occurrences of the variable $x$ in the term $t$. We use the special variable $x^t$ to stand for the target variable, or the variable that the TRS is 'solving' for.\n\nWe say that a term $t$ is in \\emph{solved form} if it is in the form:\n\\begin{enumerate}\n  \\item $|t|_{x^t} = 0$ (the term $t$ does not contain the target variable $x^t$). If we took the term $(x^t - x^t) + y$ and rewrote it to $y$, $y$ would be in solved form, as it does not contain any instances of $x^t$.\n  \\item $t = x^t$ (the term $t$ is precisely the target variable $x^t$). If we took the term $x^t + (y * (z - z))$ and rewrote it to $x^t$, $x^t$ would then be in solved form, as it consists of the target variable alone.\n  \\item $t = x^t \\odot t'$, where $\\odot$ is any binary operator in the Halide expression language, and $|t'|_{x^t} = 0$. Terms in this form are only considered `solved' if no term $u$ in either of the above two forms exist such that $t =_e u$. If we took the term $(y + x^t) + z$ and rewrote it to $x^t + (y + z)$, it would then be in solved form. (Note that $x^t + (z + y)$ would also in solved form.) However, $x^t + (y - y)$ would not be in solved form, since a semantically equivalent term $x^t$ is in the second form.\n\\end{enumerate}\n\nThe variable solver in the Halide compiler is used to reason about the bounds over variables and about their dependencies. As a worked example, let's consider the TrimNoOps stage of the compiler, in which the compiler tries to identify regions of loops in which no work is performed and thus those loop iterations can be skipped completely.\n\n%\\begin{itemize}\n%\t\\item \\textbf{Trimming no-ops} The variable solver is used in analyzing the conditions under which work is performed within nested for-loops. For example, imagine that the body of an inner for-loop over some variable $x$ only performs an operation when the condition of some if-statement is true. If the compiler can show that this condition will only hold for a limited range of the values for $x$, then it can skip the regions where only a no-op will be performed by truncating the loop. Isolating $x$ as much as possible is helpful in performing this analysis.\n%\t\\item \\textbf{Breaking dependencies in GPU code} By `solving' expressions within functions for relevant variables, the variable solver can remove spurious dependencies and allow the compiler to place computations over GPU code more efficiently.\n%\t\\item \\textbf{Proving associativity} If the operations within a function can be shown to be associative (for example, a sequence of adds and multiplies), the compiler can rearrange the associative components in whatever order will be most efficient. `Solving' such an expression for each variable in turn has the effect of normalizing it, making associativity easier to prove.\n%\\end{itemize}\n\n\n\nConsider a simple Halide function over the variables $x$ and $y$. Whenever $2 \\cdot x$ is greater than $y$, the function returns 5, otherwise it returns nothing. The function is then tiled using a 4 by 4 tile size.\n\n\\begin{verbatim}\n\tFunc F;\n\tVar x, y;\n\tf(x, y) = select(2 * x < y, 5, undef<int>());\n\n\tVar xi, yi;\n\tf.tile(x, y, xi, yi, 4, 4);\n\\end{verbatim}\n\nThe code is lowered to a set of nested for loops. The variables $x$ and $y$ now represent the number of tiles in their respective dimensions; at each iteration, they calculate the starting point for the next tile as the variables $yi\\_base$ and $xi\\_base$. The variables $xi$ and $yi$ then iterate over each point in the current tile.\n\n\\begin{verbatim}\nfor(y=0; y < (y_extent+3)/4; y++) {\n    yi_base = min(y * 4, y_extent - 4);\n    for(x=0; x < (x_extent+3)/4; x++) {\n        xi_base = min(x * 4, x_extent - 4);\n        for(yi=0; yi<4; yi++) {\n            for(xi=0; xi<4; xi++) {\n                if (xi_base + xi)*2 < (yi_base + yi) {\n                    f[idx] = 5;\n                }\n            }\n        }\n    }\n}\n\\end{verbatim}\n\nNote that the body of the innermost for loop is an if statement. If the condition of the if statement is true, the loop will set the current location of the output (here idealized as $idx$) to the value 5. If the condition of the if statement is not true, then the loop will do nothing. Thus, if we can identify regions of the innermost loop where the condition of the if statement can never be true, we can optimize by skipping those regions entirely.\n\nTo see if we can identify such a region, we take the condition of the if statement:\n\n\\begin{verbatim}\n\t(xi_base + xi) * 2 < (yi_base + yi)\n\\end{verbatim}\n\nand use the variable solver to `solve' for the variable $xi$. \n\n\\begin{verbatim}\n\txi <= ((yi_base + yi) - (xi_base* 2) - 1)/2\n\\end{verbatim}\n\nHere the variable solver is successful in rewriting the condition in terms of $xi$. Furthermore, we are able to state the expression as an upper bound of $xi$. We can thus calculate the maximum value of $xi$ for which the inner loop will perform any work. \n\n\\begin{verbatim}\n\txi_new_max = ((yi_base + yi) - (xi_base* 2) - 1)/2\n\\end{verbatim}\n\nWe can then use this new maximum as a new extent for the loop, allowing us to skip loop iterations where no work will be performed:\n\n\\begin{verbatim}\n    for(xi=0; xi<(xi_new_max + 1); xi++) {\n        if (xi_base + xi)*2 < (yi_base + yi) {\n            f[idx] = 5;\n        }\n    }\n\\end{verbatim}\n\nThe variable solver is used in various other places in the compiler as well. For example, by `solving' expressions within functions for relevant variables, the variable solver can remove spurious dependencies and allow the compiler to place computations over GPU code more efficiently. The variable solver is also used to attempt to prove associativity of functions. If the operations within a function can be shown to be associative (for example, a sequence of adds and multiplies), the compiler can rearrange the associative components in whatever order will be most efficient. `Solving' such an expression for each variable in turn has the effect of normalizing it, making associativity easier to prove.", "meta": {"hexsha": "6fbcaea429b1b2b848298fec0beb28c6bd4f6f87", "size": 29932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02-overview.tex", "max_stars_repo_name": "jn80842/UWThesis", "max_stars_repo_head_hexsha": "39a2749980fd32fce4ef2a8363a3e10eded55071", "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/02-overview.tex", "max_issues_repo_name": "jn80842/UWThesis", "max_issues_repo_head_hexsha": "39a2749980fd32fce4ef2a8363a3e10eded55071", "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/02-overview.tex", "max_forks_repo_name": "jn80842/UWThesis", "max_forks_repo_head_hexsha": "39a2749980fd32fce4ef2a8363a3e10eded55071", "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": 66.0750551876, "max_line_length": 1021, "alphanum_fraction": 0.7503340906, "num_tokens": 7632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912749233991, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6660458905731345}}
{"text": "\\section{Integral Theorems}\r\n\\subsection{Green's Theorem}\r\n\\begin{proposition}[Green's Theorem]\r\n    For continuously differentiable functions $P=P(x,y),Q=Q(x,y)$ and a bounded region $A\\subset\\mathbb R^2$ with piecewise smooth boundary $\\partial A$, we have\r\n    $$\\oint_{\\partial A}P\\,\\mathrm dx+Q\\,\\mathrm dy=\\iint_A\\left( \\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y} \\right)\\,\\mathrm dx\\,\\mathrm dy$$\r\n    where the direction of $\\partial A$ is taken such that the region on the left of motion.\r\n\\end{proposition}\r\nNote that the choice of direction is consistent with the convention we used for surfaces in $\\mathbb R^3$ if we consider the normal to be pointing out of paper.\r\nWe shall prove the case where $A$ is rectangular, i.e. $A=\\{(x,y):x\\in [a,b],y\\in[c,d]\\}$.\r\n\\begin{proof}[Proof of Rectangular Case]\r\n    \\begin{align*}\r\n        \\iint_A\\left( \\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y} \\right)\\,\\mathrm dx\\,\\mathrm dy\r\n        &=\\int_c^d\\int_a^b\\frac{\\partial Q}{\\partial x}\\,\\mathrm dx\\,\\mathrm dy-\\int_a^b\\int_c^d\\frac{\\partial P}{\\partial y}\\,\\mathrm dy\\,\\mathrm dx\\\\\r\n        &=\\int_c^dQ(b,y)-Q(a,y)\\,\\mathrm dy-\\int_a^bP(x,d)-P(x,c)\\,\\mathrm dx\\\\\r\n        &=\\oint_{\\partial A}P\\,\\mathrm dx+Q\\,\\mathrm dy\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nThe general case can be thought of gluing many rectangles together.\r\n\\begin{example}\r\n    Suppose $Q=x/2,P=-y/2$, then\r\n    $$\\oint_{\\partial A}P\\,\\mathrm dx+Q\\,\\mathrm dy=\\iint_A\\,\\mathrm dx\\,\\mathrm dy=\\operatorname{Area}(A)$$\r\n    Let $A$ be the ellipse $x^2/a^2+y^2/b^2\\le1$, which by integrating the line integral on the left, we get $\\operatorname{Area}(A)=\\pi ab$.\r\n\\end{example}\r\n\\subsection{Stokes' Theorem}\r\n\\begin{proposition}\r\n    For a continuously differentiable vector field $\\underline{F}$ and any orientable surface $S$ with piecewise smooth boundary, then\r\n    $$\\int_S\\nabla\\times \\underline{F}\\cdot\\mathrm d\\underline{S}=\\oint_{\\partial S}\\underline{F}\\cdot\\mathrm d\\underline{x}$$\r\n\\end{proposition}\r\nThe orientability is important since we will need a consistent choice of normal on $S$ that varies smoothly from point to point.\r\nSo surfaces can be said to have two sides, the inside and outside.\r\nAn example of a non-orientable surface is the Mobius strip.\r\n\\begin{example}\r\n    Consider a spherical cap\r\n    $$S=\\{\\underline{x}=(\\cos\\phi\\sin\\theta,\\sin\\phi\\sin\\theta,\\cos\\theta)^\\top:\\phi\\in[0,2\\pi],\\theta\\in[0,\\alpha]\\}$$\r\n    Let $F(\\underline{x})=(-x^2y,0,0)^\\top$, so $\\nabla\\times\\underline{F}=(0,0,x^2)^\\top$.\r\n    Now $\\mathrm d\\underline{S}=\\underline{e_r}\\sin\\theta\\,\\mathrm d\\theta\\mathrm d\\phi$.\r\n    So\r\n    $$\\int_S\\nabla\\times\\underline{F}\\cdot\\mathrm d\\underline{S}=\\int_0^\\alpha\\int_0^{2\\pi}(\\cos\\phi\\sin\\theta)^2\\cos\\theta\\sin\\theta\\,\\mathrm d\\phi\\mathrm d\\theta=\\frac{\\pi}{4}\\sin^4\\alpha$$\r\n    Now $\\partial S:[0,2\\pi]\\ni t\\mapsto (\\cos t\\sin\\alpha,\\sin t\\sin\\alpha,\\cos\\alpha)^\\top$, we can calculate to find\r\n    $$\\oint_{\\partial S}\\underline{F}\\cdot\\mathrm d\\underline{x}=\\frac{\\pi}{4}\\sin^4\\alpha$$\r\n    Which is equal to the original value.\r\n\\end{example}\r\n\\begin{example}\r\n    If $S$ is a closed surface, then its boundary is $0$, hence by Stokes' Theorem,\r\n    $$\\int_S\\nabla \\times\\underline{F}\\cdot\\mathrm d\\underline{S}=0$$\r\n    which just looks like what we get when we integrate a closed loop.\r\n\\end{example}\r\n\\begin{proposition}\r\n    If $\\underline{F}$ is continuously differentiable and\r\n    $$\\oint_C\\underline{F}\\cdot\\mathrm d\\underline{x}=0$$\r\n    for any closed loop $C$, then $\\nabla F=\\underline{0}$.\r\n\\end{proposition}\r\nHence zero circulation implies irrotaion.\r\n\\begin{proof}\r\n    Suppose $\\underline{F}$ satisfies all conditions but $\\nabla\\times\\underline{F}\\neq \\underline{0}$, then there is a unit vector $\\underline{k}$ such that it is nonzero in the $\\underline{k}$ direction, then if there is some $\\epsilon>0$ such that $\\underline{k}\\cdot(\\nabla\\times\\underline{F}(\\underline{x_0}))>\\epsilon$, then there is some $\\delta>0$ such that $|\\underline{x}-\\underline{x_0}|<\\delta$ implies $\\underline{k}\\cdot(\\nabla\\times\\underline{F})>\\epsilon/2>0$.\\\\\r\n    Now consider the ball $|\\underline{x}-\\underline{x_0}|<\\delta$ and we choose a disk $D$ inside it, we have\r\n    $$0=\\left|\\oint_{\\partial D}\\underline{F}\\,\\mathrm d\\underline{x}\\right|=\\left|\\int_D\\nabla\\times\\underline{F}\\cdot\\mathrm d\\underline{S}\\right|\\ge\\frac{\\epsilon}{2}\\operatorname{Area}(D)>0$$\r\n    Contradiction.\r\n\\end{proof}\r\n\\begin{example}\r\n    Let $S_{\\epsilon}$ be any sufficiently nice surface contained inside a disk with radius $\\epsilon>0$ centered at $\\underline{x}=\\underline{x_0}$ with normal $\\underline{k}$.\r\n    If\r\n    \\begin{align*}\r\n        \\int_{S_\\epsilon}\\nabla\\times\\underline{F}\\cdot\\mathrm d\\underline{S}&=\\int_{S_\\epsilon}\\nabla\\times\\underline{F}(\\underline{x_0})\\cdot\\mathrm d\\underline{S}+\\left( \\int_{S_\\epsilon}\\nabla\\times(\\underline{F}-\\underline{F}(\\underline{x_0}))\\cdot\\mathrm d\\underline{S} \\right)\r\n        \\\\\r\n        &=\\underline{k}\\cdot\\nabla\\times\\underline{F}(\\underline{x_0})\\operatorname{Area}(S_\\epsilon)+\\int_{S_\\epsilon}\\nabla\\times(\\underline{F}-\\underline{F}(\\underline{x_0}))\\cdot\\mathrm d\\underline{S}\r\n    \\end{align*}\r\n    Now we claim that the last term is $o(\\operatorname{Area}(S_\\epsilon))$ as $\\epsilon\\to 0$.\r\n    Indeed,\r\n    \\begin{align*}\r\n        \\left| \\int_{S_\\epsilon}\\nabla\\times(\\underline{F}-\\underline{F}(\\underline{x_0}))\\cdot\\mathrm d\\underline{S} \\right|\r\n        &\\le\\int_{S_\\epsilon}|\\nabla\\times(\\underline{F}-\\underline{F}(\\underline{x_0}))|\\cdot\\mathrm d\\underline{S}\\\\\r\n        &\\le\\sup_{\\underline{x}\\in S_\\epsilon}|\\nabla\\times(\\underline{F}(\\underline{x})-\\underline{F}(\\underline{x_0}))|\\operatorname{Area}(S_\\epsilon)\\\\\r\n        &=o(\\operatorname{Area}(S_\\epsilon))\r\n    \\end{align*}\r\n    As $\\underline{F}$ is continuously differentiable.\r\n    Therefore by Stokes' Theorem,\r\n    \\begin{align*}\r\n        \\frac{1}{\\operatorname{Area}(S_\\epsilon)}\\oint_{\\partial S_\\epsilon}\\underline{F}\\cdot\\mathrm d\\underline{x}\r\n        &=\\frac{1}{\\operatorname{Area}(S_\\epsilon)}\\int_{S_\\epsilon}\\nabla\\times\\underline{F}\\cdot\\mathrm d\\underline{S}\\\\\r\n        &=\\underline{k}\\cdot\\nabla\\times\\underline{F}(\\underline{x_0})+o(1)\r\n    \\end{align*}\r\n    As $\\epsilon\\to 0$.\r\n    So the curl is the infinitesimal circulation around the normal $\\underline{k}$ per unit area.\r\n\\end{example}", "meta": {"hexsha": "925259f6e9e0e8e059dcee20e6dc44cdfb3d0038", "size": 6397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/stokes.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/stokes.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/stokes.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.3837209302, "max_line_length": 479, "alphanum_fraction": 0.6792246365, "num_tokens": 2088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.6660458905383486}}
{"text": "\\section{Regular Languages and Finite State Automata}\n\n% \\subsection{Description}\nIn this section we will introduce the definitions of \\textit{Regular Language} and \\textit{Automaton} over an alphabet $\\Sigma$ since these notions are crucial to understand the two algorithms L* and NL*.\n% An automaton $\\A$ is a computing device used in abstract computer science to understand regular languages seen as a set of words formed with the concatenation of zero or more letters \\letter{} belonging to an alphabet noted \\alphabet{}. We note $\\Sigma^*$ as the set of all words over the alphabet $\\Sigma$, including $\\E$: the word of length 0.\n\n\\begin{theorem}[Kleene's theorem]\n  \\label{th:kleene}\n  A language is called regular if it can be represented by a regular expression or equivalently by a finite state automaton.\n\\end{theorem}\n\nLet $\\Sigma^*$ be the set of all words over the alphabet $\\Sigma$ (including the word of length $0$ noted $\\E$).\n\nA recursive definition of a regular language can be expressed by the following grammar:\n\\[ L = \\varnothing \\mid \\E \\mid \\alpha \\mid L \\cup L \\mid \\overline{L} \\mid L \\cdot L \\mid L^* \\]\nwhere:\n\\begin{itemize}\n  \\item $\\varnothing$ is the empty language;\n  \\item $\\E$ is the word of length 0;\n  \\item $\\alpha$ is a symbol belonging to the alphabet $\\Sigma$;\n  \\item $L_1 \\cup L_2 = \\{\\omega \\in \\Sigma^* \\mid \\omega \\in L_1 \\vee \\omega \\in L_2\\}$, which is the union of $L_1$ and $L_2$ ;\n  \\item $L_1 \\cdot L_2 = \\{\\omega \\in \\Sigma \\mid \\exists w_1 \\in L_1, \\exists w_2 \\in L_2 \\text{ and } w_1 \\cdot w_2 = \\omega\\footnote{Note $ w_1 \\cdot w_2$ is the concatenation of the word $w_1$ followed by the word $w_2$}\\}$, which is the concatenation of all words in $L_1$ with all words in $L_2$;\n  \\item $\\overline{L} = \\{\\omega \\in \\Sigma^* \\mid \\omega \\notin L\\}$, called the complement of the language $L$;\n  \\item To define $L^*$ let $L^0 = {\\E}$, $L^1 = L$ and $L^{i+1} = L^i \\cdot L$, then $L^* = \\bigcup\\limits_{i=0}^{\\infty} L_{i}$. This operation is called the \\textit{Kleene's star}\n\\end{itemize}\n\nSome properties are not listed since they can be derived from the previous definition, for example the intersection betweem languages ($L_1 \\cap L_2 = \\overline{\\overline{L_1} \\cup \\overline{L_2}}$).\n\n\\begin{definition}[Automaton]\n  An automaton $\\A$ is represented by a 5-tuple $\\left\\langle \\Sigma, \\Q, \\delta, q_I, F\\right\\rangle $ where \\alphabet{} is the alphabet, \\states{} is the set of states composing the automaton, $\\delta$ is the set of transition, \\qzero{} $\\in \\statesN{}$ is the initial state and $F \\subseteq \\Q$ is the set of accepting states. A transition $\\delta$ is a mapping $Q \\times \\Sigma \\rightarrow Q$.\n\\end{definition}\n\n\\begin{example}\n  A transition like $\\delta(q_i, \\alpha) = q_j$ means that we can move from state $q_i$ to state $q_j$ when reading symbol $\\alpha$.\n\\end{example}\n\nA state $q_i$ is called successor of $q_j$ if it exists $\\delta(q_i, \\alpha) = q_j$ for some $\\alpha \\in \\Sigma$. If $q_j$ is successor of $q_i$ then $q_i$ is the predecessor of $q_j$.\n\nFollowing the construction of the automaton $\\A$, and especially focusing on its transition function, it is possible to classify $\\A$ into two different classes.\n\n\\begin{definition}[DFA and NFA]\n  If for every state $q_i \\in \\statesN{}$ and for every letter $\\alpha \\in \\Sigma$ there exists only one successor by $\\alpha$ then the automaton is \\textit{deterministic} and noted \\textit{DFA}, otherwise the automaton is called \\textit{non-deterministic} and noted \\textit{NFA}.\n\\end{definition}\n\nWe can define a \\textit{DFA} also with a logic formula:\n\\[\\forall q_i \\in \\Q, \\forall \\alpha \\in \\Sigma \\text{ if } \\exists \\delta_1, \\delta_2 \\in \\delta \\text{ such that } \\delta_1(q_i, \\alpha) = q_j' \\text{ and } \\delta_2(q_i, \\alpha) = q_j'' \\text{ then } q_j' = q_j'' \\]\n\nSince every regular language can be represented by an automaton, be it deterministic or not, the operations like intersection, union and complementation are also available on automata. Among these properties, the most difficult to compute is the complementation when the automaton is non-deterministic as it asks first to make the \\textit{NFA} deterministic \\footnote{This operation is called determinisation} which is a \\textit{PSPACE-complete} problem.\n\nHowever, \\textit{NFA}s have a big advantage since they can be exponentially smaller than the corresponding \\textit{DFA} and this may be interesting mainly if we care about space resources.\n\n\\begin{remark}\n  \\textit{NFA} and \\textit{DFA} have the same expressive power meaning that \\[\\bigcup NFA = \\bigcup DFA = \\bigcup RegularLanguages\\]\n\\end{remark}\n\n\\begin{definition}[Minimal automaton]\n  \\label{lemma:minimalAut}\n  An automaton $\\A$ is minimal if it is not possible to construct a smaller automaton $\\A'$ for the same language having less states than $\\A$. Moreover, a minimal \\textit{DFA} (noted \\textit{mDFA}), for a given regular language, is \\textit{unique}. However there may exists several minimal \\textit{NFA}, noted \\textit{mNFA}, for a regular language $\\U$.\n\\end{definition}\n\nFinally, we define, Regular Expressions (or \\textit{RegEx}) with the following grammar:\n\\[R = \\omega \\mid R + R \\mid R \\cdot R \\mid R^* \\mid (R)\\]\nwhere $\\omega$ is a word belonging to $\\Sigma^*$, the ``$+$'' symbol indicates the union operator, ``$\\cdot$'' is the concatenation of two regular expression, the ``$*$'' is defined as for regular languages and finally parentheses allows to introduce priority over the other operators.\n\n\\begin{example}[DFA vs NFA]\n  In \\cref{fig:nfa_vs_dfa} we have an example of two minimal automata for the language $L = (a+b)^*a(a+b)$ where we can see that the NFA needs less states then the corresponding minimal DFA.\n  \\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.45\\textwidth}\n      \\centering\n      \\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n        \\node[state,initial, initial text=] (q_I) {$q_I$};\n        \\node[state] (q_1) [right=of q_I] {$q_1$};\n        \\node[state, accepting] (q_2) [right=of q_1] {$q_2$};\n        \\path[->]\n        (q_I) edge [loop above] node {a,b} ()\n        (q_I) edge  node {a} (q_1)\n        (q_1) edge  node {a,b} (q_2);\n      \\end{tikzpicture}\n      \\caption{NFA}\n      \\label{subfig:nfa_x_star_ax}\n    \\end{subfigure}\n    \\begin{subfigure}{0.45\\textwidth}\n      \\centering\n      \\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n        \\node[state,initial, initial text=] (q_I) {$q_I$};\n        \\node[state] (q_1) [right=of q_I] {$q_1$};\n        \\node[state, accepting] (q_2) [above right=of q_1] {$q_2$};\n        \\node[state, accepting] (q_3) [below right=of q_1] {$q_3$};\n        \\path[->]\n        (q_I) edge [loop above] node {b} ()\n        (q_2) edge [loop above] node {a} ()\n        (q_I) edge  node {a} (q_1)\n        (q_1) edge  node {a} (q_2)\n        (q_1) edge  node {a} (q_2)\n        (q_2) edge  node {b} (q_3)\n        (q_3) edge[bend left, below]  node {b} (q_I)\n        (q_3) edge[bend left, below]  node {a} (q_1)\n        (q_1) edge[bend left, above]  node {b} (q_3);\n      \\end{tikzpicture}\n      \\caption{DFA}\n      \\label{subfig:dfa_x_star_ax}\n    \\end{subfigure}\n    \\caption{Minimal NFA vs minimal DFA}\n    \\label{fig:nfa_vs_dfa}\n  \\end{figure}\n\\end{example}\n\n\\subsection{Some notation}\nWe will note an automaton $\\A$, $L = \\LA$ means that the regular language recognized by the automaton $\\A$ is $L$. An expression of type $L = (a+b)$ indicates that $L$ is recognized by the regular expression $(a+b)$. If not specified we suppose $\\Sigma$ to be equal to ${a, b}$ and $\\omega$ be a word over $\\Sigma^*$.\n", "meta": {"hexsha": "bdd390ea056b39d7f371e0cb1caba53625f0774a", "size": 7603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/Automaton.tex", "max_stars_repo_name": "FissoreD/TER-M1-M1S2", "max_stars_repo_head_hexsha": "bfc624f83b2c6e69fe0be42e4a2bf29bbc72218f", "max_stars_repo_licenses": ["MIT"], "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/Automaton.tex", "max_issues_repo_name": "FissoreD/TER-M1-M1S2", "max_issues_repo_head_hexsha": "bfc624f83b2c6e69fe0be42e4a2bf29bbc72218f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-21T17:29:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T17:29:10.000Z", "max_forks_repo_path": "report/sections/Automaton.tex", "max_forks_repo_name": "FissoreD/TER-M1-M1S2", "max_forks_repo_head_hexsha": "bfc624f83b2c6e69fe0be42e4a2bf29bbc72218f", "max_forks_repo_licenses": ["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.4954954955, "max_line_length": 454, "alphanum_fraction": 0.6886755228, "num_tokens": 2351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.779992900254107, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6660458890884536}}
{"text": "% !TeX spellcheck = en_EN\n%\\documentclass[12pt,a4paper]{article}\n%\\usepackage{import}\n%\\subimport{../}{uebung.tex}\n\n%\\toggletrue{showSolution}\n\n\n%\\title{\\thetitle{}\\\\Tutorial 4}\n%\\date{\\WeeksAfter{3}}\n\n\n%\\begin{document}\n\n%\\maketitle\n\n\\BoSSSopen{tutorial4/tutorial4}\n\\graphicspath{{tutorial4/tutorial4.texbatch/}}\n\n\\BoSSScmd{\n///\\section*{What's new:} \n///\\begin{itemize}\n///    \\item{generating .plt-files for visualization}\n///    \\item{implementing a numerical flux}\n///    \\item{definition and evaluation of the spatial operator}\n///    \\item{explicit time integration}\n///\\end{itemize}\n///\\section*{Prerequisites:} \n///\\begin{itemize}\n///    \\item{projection onto a DG-field}\n///\\end{itemize} \n///Within this tutorial, we are going to implement the scalar transport equation via the definition of a spatial operator and an explicit time integrator. The implementation of the numerical flux is described on the basis of a upwinding scheme. For the visualization of the results, we are generating .plt-files, which can be opened by a viewer of your choice\n///\\section{Problem statement}\n///We are considering the following definition of the scalar transport equation with\n///\\begin{equation}\n///   \\label{eq:divergenceTerm}\n///   \\frac{\\partial c}{\\partial t} + \\nabla \\cdot (\\vec{u} c) = 0,\n///\\end{equation}\n///where $c = c(x,y,t) \\in \\mathbb{R}$ is the unknown concentration and\n///\\begin{equation*}\n///     \\vec{u} = \\begin{pmatrix}\n///         y\\\\-x\n///     \\end{pmatrix}\n///\\end{equation*}\n///is a given velocity field in $\\domain = [-1, 1] \\times [-1, 1]$. Furthermore, the exact solution is given by\n///\\begin{equation*}\n///    c_\\text{Exact}(x,y,t) = \\cos(\\cos(t) x - \\sin(t) y) \\quad \\text{ for } (x,y) \\in \\domain\n///\\end{equation*}\n///In this tutorial we will simulate the evolution of the concentration $c(x,y,t)$.\n///\\section{Solution within the \\BoSSS{} framework}\n///We start a new project\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nrestart\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nusing System.IO;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Delete old plots in the current directory if any\nDirectory.GetFiles(\".\", \"*.plt\").ForEach(file => File.Delete(file));\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Projection and visualization}\n/// In this first section we get to know the plotting tool \\code{Tecplot}, which generates .plt-files of our \\code{DGFields}. \n/// Previously, we define the exact solution $c_{Exact}(x,y,t)$ and the scalar components of the velocity field $\\vec{u}$ as functions, \nFunc<double[], double, double> cExact =  \\newline \n\\btab (X, t) => Math.Cos(Math.Cos(t)*X[0] - Math.Sin(t)*X[1]);\n }\n\\BoSSSexe\n\\BoSSScmd{\nFunc<double[], double> u = X => X[1];\n }\n\\BoSSSexe\n\\BoSSScmd{\nFunc<double[], double> v = X => -X[0];\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Next, we need to construct the computational domain, i.e a unit square with one cell.\ndouble[] nodes = GenericBlas.Linspace(-1.0, 1.0, 2); \\newline \nGridCommons grid = Grid2D.Cartesian2DGrid(nodes, nodes); \\newline \nGridData gridData = new GridData(grid);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We instantiate the \\code{SinglePhaseField} \\emph{ch} with a \\code{Basis} of DG-degreee of 2. Then we can project the initial value $c(x,y,0.0)$ onto \\emph{ch}.\nint dgDegree = 2;  \\newline \nBasis basis = new Basis(gridData, dgDegree);  \\newline \nSinglePhaseField ch = new SinglePhaseField(basis, \"ch\");  \\newline \nch.ProjectField(X => cExact(X, 0.0));\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now, we can export the initial projection in our \\code{Tecplot} format.\nusing BoSSS.Solution.Tecplot;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// One important parameter for visualization is \\textit{superSampling}. It is essential for higher order methods since almost all\n/// plotting tools work with piecewise linear interpolations of the data in the vertices. For our\n/// case, the plot with \\code{superSampling=0} would just show a constant value! By increasing the\n/// rate of the \\emph{superSampling}, we provide more sampling points for the plot tool.\n/// \\begin{itemize}\n/// \\item This has nothing to do with the computation! Only required for visualization!\n/// \\item The number of sampling points grows exponentially with the value of\n///  \\code{superSampling}. Never use a value above 5 or 6!\n/// \\end{itemize}\n }\n\\BoSSSexe\n\\BoSSScmd{\nuint superSampling = 0;  \\newline \nTecplot tecplot    = new Tecplot(gridData, superSampling);\\newline \ntecplot.PlotFields( \\newline \n\\btab \"plot\\_tutorial4\\_superSampling0\", \\newline \n\\btab 0.0, \\newline \n\\btab ch);\n }\n\\BoSSSexe\n\\BoSSScmd{\nsuperSampling = 3;  \\newline \ntecplot    = new Tecplot(gridData, superSampling); \\newline \ntecplot.PlotFields( \\newline \n\\btab \"plot\\_tutorial4\\_superSampling3\", \\newline \n\\btab 0.0, \\newline \n\\btab ch);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// There should now be two plot-files in your current directory. Those can be opened by any standard viewer for .plt-files.\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Implementation of the (numerical) flux}\n/// Before we can define the spatial operator for the scalar transport equation, we need to implement \n/// the flux for the given problem, i.e. the flux of the divergence operator. A flux defines the volume term \n/// (the \\emph{flux}) as well as the boundary terms (via the \\emph{numerical flux}).\n/// We derive such a flux from the class \\code{NonlinearFlux} which simplifies the implementation of fluxes in\n/// flux-based formulations. \nusing BoSSS.Platform.LinAlg;  \\newline \nclass ScalarTransportFlux : NonlinearFlux \\{  \\newline \n \\newline \n    /// \\leftskip=1cm \\code{ArgumentOrdering} defines on which arguments this flux depends, and in which order. \n    /// Here, we have just one argument (the concentration $c$). The name is arbitrary at this point, but has to be \n    /// referenced when defining the spatial operator (see next section). Since this flux only depends on one\n    /// argument, the parameters \\code{U}, \\code{Uin} and \\code{Uout} will have a length of 1 and will contain the\n    /// local values of $c$ in the first entry, i.e. \\code{U[0]} in the method \\code{Flux(...)}\n\\btab public override IList<string> ArgumentOrdering \\{  \\newline \n\\btab \\btab get \\{ return new string[] \\{ \"c\" \\}; \\}  \\newline \n\\btab \\}  \\newline \n \\newline \n    /// \\code{Flux(...)} defines the volume term. The array \\code{output} (whose length is determined by the\n    /// spatial dimension of the problem) has to contain the evaluated \\emph{flux} on exit.\n\\btab protected override void Flux(double time, double[] x, double[] U, double[] output) \\{  \\newline \n\\btab \\btab output[0] = u(x) * U[0];  \\newline \n\\btab \\btab output[1] = v(x) * U[0];  \\newline \n\\btab \\}  \\newline \n \\newline \n    /// \\code{InnerEdgeFlux(...)} defines the \\emph{numerical flux} between inner edges. The parameters \n    /// \\code{Uin} and \\code{Uout} contain the value from the \\emph{in} and \\emph{out} side, respectively, \n    /// where the normal vector \\code{normal} points from \\emph{in} to \\emph{out}\n\\btab protected override double InnerEdgeFlux(double time, double[] x, double[] normal, \\newline \n\\btab double[] Uin, double[] Uout, int jEdge) \\{  \\newline \n\\btab \\btab Vector n              = new Vector(normal);  \\newline \n\\btab \\btab Vector velocityVector = new Vector(u(x), v(x));  \\newline \n \\newline \n\\btab \\btab if (velocityVector * n > 0) \\{  \\newline \n\\btab \\btab \\btab return (velocityVector * Uin[0]) * n;  \\newline \n\\btab \\btab \\} else \\{  \\newline \n\\btab \\btab \\btab return (velocityVector * Uout[0]) * n;  \\newline \n\\btab \\btab \\}  \\newline \n\\btab \\}  \\newline \n \\newline \n    /// \\code{BorderEdgeFlux(...)} defines the \\emph{numerical flux} at boundary edges, where only inner values \n    /// (\\code{Uin}) are given. Here, we reuse \\code{InnerEdgeFlux(...)} and the exact solution \\code{cExact} \n    /// to define a suitable boundary condition.\n\\btab protected override double BorderEdgeFlux(double time, double[] x, double[] normal, \\newline \n\\btab byte EdgeTag, double[] Uin, int jEdge) \\{  \\newline \n\\btab \\btab double[] Uout = new double[] \\{ cExact(x, time) \\};  \\newline \n\\btab \\btab return InnerEdgeFlux(time, x, normal, Uin, Uout, jEdge);  \\newline \n\\btab \\}  \\newline \n\\} \\newline \n/// \\leftskip=0cm\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Definition of a spatial operator}\n/// The next step is the definition of the spatial operator.\nvar spatialTerm = new SpatialOperator( \\newline \n\\btab new string[] \\{ \"c\" \\},        // Domain variable \\newline \n\\btab new string[] \\{ \"div\" \\},      // Co-domain variable\\newline \n\\btab QuadOrderFunc.NonLinear(2)); // Order of integration\\newline \n/// The name of the \\emph{domain variable} must be the same used in \\code{ArgumentOrdering}\n/// in the definition of the flux, i.e \\code{ScalarTransportFlux}.\n/// The name of the \\emph{co-domain variable} is arbitrary and is used when the \n/// fluxes are added. In our case, we only have one type of flux.\n/// \\code{QuadOrderFunc.NonLinear(int x)} computes the required integration order \n/// for a non-linear flux. Here, the flux is given by $\\vec{u} c$, where $\\vec{u}$ is linear. \n/// So, we have second order terms (flux times the ansatz functions), i.e the required\n/// order is \\code{2*dgDegree+1} \\newline\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We add the flux of the divergence operator to the corresponding equation component, identified by the \n/// \\emph{co-domain variable},\nspatialTerm.EquationComponents[\"div\"].Add(new ScalarTransportFlux());\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// and finalize the definition of the operator\nspatialTerm.Commit();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Time integration}\n/// Finally, we have to specify a time stepping scheme to solve the time dependent\n/// scalar transport equation \\eqref{eq:divergenceTerm}. For simplification, we use \n/// the \\code{ExplicitEuler} scheme, which just needs the \\code{SpatialOperator} and \n/// the \\code{DGField} as arguments.\nusing BoSSS.Solution.Timestepping;\n }\n\\BoSSSexe\n\\BoSSScmd{\nExplicitEuler timeStepper = new ExplicitEuler(spatialTerm, ch);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We want to perform a full revolution ($t \\in [0, 2\\pi]$) with 24 timesteps.\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble endTime = 2.0 * Math.PI; \\newline \nint numberOfTimesteps = 24;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Plot the initial data\ntecplot.PlotFields( \\newline \n\\btab \"plot\\_tutorial4\\_0\", \\newline \n\\btab 0.0, \\newline \n\\btab ch); \\newline \n/// Now, we can start the simulation, where the \\code{timestepper} performs in each iteration one\n/// explicit euler timestep with the timestep size \\code{dt}\ndouble dt = endTime / numberOfTimesteps; \\newline \nfor (int i = 1; i <= numberOfTimesteps; i++) \\{ \\newline \n\\btab timeStepper.Perform(dt); \\newline \n\\btab tecplot.PlotFields(          // plot each timestep\\newline \n\\btab \\btab \"plot\\_tutorial4\\_\" + i, \\newline \n\\btab \\btab timeStepper.Time, \\newline \n\\btab \\btab ch); \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Furthermore, we can postprocess our simulation data in various ways: For example, \n/// we can compute the L2-Error at the end of the simulation\ndouble error = ch.L2Error(X => cExact(X, timeStepper.Time)); \\newline \nerror;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\section{Advanced topics}\n/// So far we used the \\code{timestepper} to evaluate the \\code{SpatialOperator} in order to get \n/// the current change rate for the explicit Euler scheme. In the next section we will evaluate the operator \n/// in each iteration manually. But first we set the \\code{DGField} back to the initial values and plot\nch.ProjectField(X => cExact(X, 0.0));\\newline \ntecplot.PlotFields( \\newline \n\\btab \"plot\\_tutorial4\\_advanced\\_0\", \\newline \n\\btab 0.0, \\newline \n\\btab ch);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Evaluation of the spatial operator}\n/// To evaluate the \\code{SpatialOperator}, we have to provide a mapping of the DG-coordinates of \\emph{ch}.\n/// This describes a bijective mapping between \\emph{local unique indices} and \\emph{global unique indices}\nvar mapping = new CoordinateMapping(ch);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// In other words, it maps the DG-coordinates into one long, one-dimensional \\code{CoordinateVector}\nvar DGCoordinates = new CoordinateVector(mapping);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now, we can create an evaluator of the \\code{SpatialOperator} for the \\code{DGField} \\emph{ch} \nvar evaluator = spatialTerm.GetEvaluator(mapping.Fields, mapping);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// In our case this evaluator computes the fluxes of the divergence operator evaluated for the \\code{DGField} \\emph{ch}\ndouble[] flux = new double[ch.CoordinateVector.Count]; \\newline \nevaluator.time = 0.0;\\newline \nevaluator.Evaluate(1.0, 0.0, flux);\\newline \n/// After the evaluation the output \\code{flux} is $\\code{flux} = 0.0 \\cdot \\code{flux} + 1.0 \\cdot \\code{spatialTerm(time: 0.0)}$\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Finally, we can use this kind of \\code{spatial operator} evaluation to implement the explicit Euler scheme manually.   \ndouble physTime = 0.0;\\newline \nfor (int i = 1; i <= numberOfTimesteps; i++) \\{ \\newline \n\\btab evaluator.time = physTime;\\newline \n\\btab evaluator.Evaluate(1.0, 0.0, flux);\\newline \n\\btab DGCoordinates.axpy<double[]>(flux, -dt);\\newline \n\\btab physTime += dt;\\newline \n\\btab tecplot.PlotFields(        \\newline \n\\btab \\btab \"plot\\_tutorial4\\_advanced\" + i, \\newline \n\\btab \\btab physTime, \\newline \n\\btab \\btab ch); \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble error = ch.L2Error(X => cExact(X, physTime)); \\newline \nerror;\n }\n\\BoSSSexe\n", "meta": {"hexsha": "966aebd76a62aaa2e7c079b889d83846c2c98d65", "size": 13340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/handbook/tutorial4/tutorial4.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/tutorial4/tutorial4.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/tutorial4/tutorial4.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": 41.4285714286, "max_line_length": 359, "alphanum_fraction": 0.7086956522, "num_tokens": 3935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985637, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6660458847735538}}
{"text": "\\documentclass{article}\r\n\r\n\\usepackage[preprint]{./template/neurips_2020}\r\n\r\n\\usepackage[utf8]{inputenc} % allow utf-8 input\r\n\\usepackage[T1]{fontenc}    % use 8-bit T1 fonts\r\n\\usepackage{hyperref}       % hyperlinks\r\n\\usepackage{url}            % simple URL typesetting\r\n\\usepackage{booktabs}       % professional-quality tables\r\n\\usepackage{amsfonts}       % blackboard math symbols\r\n\\usepackage{nicefrac}       % compact symbols for 1/2, etc.\r\n\\usepackage{microtype}      % microtypography\r\n\\usepackage{physics}\r\n\\usepackage{amsmath}\r\n\r\n\r\n\\title{Chapter 2: Introduction to Quantum Mechanics}\r\n\r\n\\author{\r\n  John Martinez \\\\\r\n  \\texttt{john.r.martinez14@gmail.com} \\\\\r\n  % examples of more authors\r\n  % \\And\r\n  % Coauthor \\\\\r\n  % Affiliation \\\\\r\n  % Address \\\\\r\n  % \\texttt{email} \\\\\r\n  % \\AND\r\n  % Coauthor \\\\\r\n  % Affiliation \\\\\r\n  % Address \\\\\r\n  % \\texttt{email} \\\\\r\n  % \\And\r\n  % Coauthor \\\\\r\n  % Affiliation \\\\\r\n  % Address \\\\\r\n  % \\texttt{email} \\\\\r\n  % \\And\r\n  % Coauthor \\\\\r\n  % Affiliation \\\\\r\n  % Address \\\\\r\n  % \\texttt{email} \\\\\r\n}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\r\n%\\begin{abstract}\r\n%  The abstract paragraph should be indented \\nicefrac{1}{2}~inch (3~picas) on\r\n%  both the left- and right-hand margins. Use 10~point type, with a vertical\r\n%  spacing (leading) of 11~points.  The word \\textbf{Abstract} must be centered,\r\n%  bold, and in point size 12. Two line spaces precede the abstract. The abstract\r\n%  must be limited to one paragraph.\r\n%\\end{abstract}\r\n\\section{Intro to Quantum Mechanics}\r\n\\subsection{Linear Algebra}\r\nVector space\r\n\\begin{center}\r\n  $\\begin{bmatrix}\r\n    z_{1} \\\\\r\n    \\vdots \\\\\r\n    z_{n}\r\n  \\end{bmatrix}$\r\n\\end{center}\r\n\r\n%%% Section 1.1.1\r\n\\subsubsection{Bases and Linear Independence}\r\nA \\emph{spanning set} for a vector space is a set of vectors\r\n$\\ket{v_{1}},...,\\ket{v_{n}}$ such that any vector $\\ket{v}$ in the vector\r\nspace can be written as a linear combination\r\n$\\ket{v} = \\displaystyle\\sum_{i}a_{i}\\ket{v_{i}}$ in that set. The spanning\r\nset for the vector space $\\mathbb{C}^{2}$ is the set\r\n  \\begin{center}\r\n    $\\ket{v_{1}} \\equiv \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix};\\mspace{10mu}\r\n    \\ket{v_{2}} \\equiv \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$\r\n  \\end{center}\r\n\r\nA second spanning set in $\\mathbb{C}^{2}$ is\r\n  \\begin{center}\r\n    $\r\n    \\ket{v_{1}} \\equiv \\frac{1}{\\sqrt{2}}\r\n      \\begin{bmatrix} 1 \\\\ 1\r\n      \\end{bmatrix};\\mspace{10mu}\r\n    \\ket{v_{2}} \\equiv \\frac{1}{\\sqrt{2}}\r\n      \\begin{bmatrix} 1 \\\\ -1\r\n      \\end{bmatrix}$\r\n  \\end{center}\r\n\r\nA set set of non-zero vectors $\\ket{v_{1}},...,\\ket{v_{n}}$ are\r\n\\emph{linear dependent} if there exists a set of complex numbers\r\n$a_{1},...,a_{n}$ with $a_{i} \\neq 0$ for at least one value of $i$, such that\r\n\\begin{center}\r\n  $a_{1}\\ket{v_{1}} + a_{2}\\ket{v_{2}} + \\hdots + a_{n}\\ket{v_{n}} = 0$.\r\n\\end{center}\r\n\r\n%%% Section 1.1.2\r\n\\subsubsection{Linear Operators and Matrices}\r\nA \\emph{linear operator} between vector spaces $V$ and $W$ is defined to be any\r\nfunction $A : V \\rightarrow W$ which is linear in its inputs\r\n  \\begin{center}\r\n    $A\\left(\\displaystyle\\sum_{i}a_{i}\\ket{v_{i}}\\right) =\r\n    \\displaystyle\\sum_{i}a_{i}A(\\ket{v_{i}})$\r\n  \\end{center}\r\n\r\n%%% Section 1.1.3\r\n\\subsubsection{Pauli Matrices}\r\n  \\begin{center}\r\n    $\r\n    \\sigma_{0} \\equiv I \\equiv\r\n      \\begin{bmatrix} 1 & 0 \\\\\r\n      0 & 1 \\end{bmatrix};\\mspace{10mu}\r\n    \\sigma_{1} \\equiv \\sigma_{x} \\equiv X \\equiv\r\n      \\begin{bmatrix} 0 & 1 \\\\\r\n      1 & 0 \\end{bmatrix}\r\n    $\r\n  \\end{center}\r\n\r\n  \\begin{center}\r\n    $\r\n    \\sigma_{2} \\equiv \\sigma_{y} \\equiv Y \\equiv\r\n      \\begin{bmatrix} 0 & -i \\\\\r\n      i & 0 \\end{bmatrix};\\mspace{10mu}\r\n    \\sigma_{3} \\equiv \\sigma_{z} \\equiv Z \\equiv\r\n      \\begin{bmatrix} 1 & 0 \\\\\r\n      0 & -1 \\end{bmatrix}\r\n    $\r\n  \\end{center}\r\n\r\n%%% Section 1.1.4\r\n\\subsubsection{Inner Products}\r\nAn \\emph{inner product} is a function which takes as input two vectors\r\n$\\ket{v}$ and $\\ket{w}$ form a vector space and produces a complex number\r\nas output.\r\n\r\nA function from $V \\times V \\rightarrow \\mathbb{C}$ is an inner product if it\r\nsatisfies the requiments that:\r\n\r\n(1) (., .) is linear in the second argument\r\n  \\begin{center}\r\n    $\r\n      \\left(\\ket{v}, \\displaystyle\\sum_{i}\\lambda_{i}\\ket{w_{i}}\\right) = \r\n      \\displaystyle\\sum_{i}\\lambda_{i}(\\ket{v}, \\ket{w_{i}})\r\n    $\r\n  \\end{center}\r\n\r\n(2) $(\\ket{v}, \\ket{w}) = (\\ket{w}, \\ket{v})^{*}$\r\n\r\n(3) $(\\ket{v}, \\ket{v}) \\geq 0$ with equality if and only if $\\ket{v} = 0$\r\n\r\nFor example, $\\mathbb{C}^{n}$ has an inner product defined by\r\n  \\begin{center}\r\n    $\r\n      ((y_{1},...,y_{n}),(z_{1},...,z_{n})) \\equiv\r\n      \\displaystyle\\sum_{i}y_{i}^{*}z_{i} =\r\n      \\begin{bmatrix}\r\n      y_{1}^{*} \\hdots y_{n}^{*}\r\n      \\end{bmatrix}\r\n      \\begin{bmatrix}\r\n      z_{1} \\\\\r\n      \\vdots \\\\\r\n      z_{n}\r\n      \\end{bmatrix}\r\n    $\r\n  \\end{center}\r\n\r\nVectors $\\ket{v}$ and $\\ket{v}$ are \\emph{orthogonal} if their inner product\r\nis zero. We define the \\emph{norm} of a vector $\\ket{v}$ by\r\n  \\begin{center}\r\n    $\\|\\ket{v}\\| \\equiv \\sqrt{\\bra{v}\\ket{v}}$\r\n  \\end{center}\r\n\r\nA \\emph{unit vector} is a vector $\\ket{v}$ such that $\\|\\ket{v}\\| = 1$.\r\n\r\nSuppose $\\ket{w_{1}},\\hdots,\\ket{w_{d}}$ is a basis set for some vector space\r\n$V$ with an inner product. There is a useful method, the \\emph{Gram-Schmidt}\r\nprocedure, which can be used to produce an orthonormal basis set\r\n$\\ket{v_{1}},\\hdots,\\ket{v_{d}}$ for a vector space $V$. Define\r\n$\\ket{v_{1}} \\equiv \\frac{\\ket{w_{1}}}{\\|\\ket{w_{1}}\\|}$ and for\r\n$1 \\leq k \\leq d-1$ define $\\ket{v_{k+1}}$ inductively by\r\n  \\begin{center}\r\n  $\r\n    \\ket{v_{k+1}} \\equiv\r\n    \\frac{\\ket{w_{k+1}} - \\sum_{i=1}^{k}\\bra{v_{i}}\\ket{w_{k+1}}\\ket{v_{i}}}{\r\n    \\|\\ket{w_{k+1}} - \\sum_{i=1}^{k}\\bra{v_{i}}\\ket{w_{k+1}}\\ket{v_{i}}\\|}\r\n  $\r\n  \\end{center}\r\n\r\n%%% Section 1.1.5\r\n\\subsubsection{Eigenvectors and Eigenvalues}\r\nAn \\emph{eigenvector} of a linear operator $A$ on a vector space is a non-zero\r\nvector $\\ket{v}$ such that $A\\ket{v} = v\\ket{v}$, where $v \\in \\mathbb{C}$ and\r\nis known as the \\emph{eigenvalue} of $A$ corresponding to $\\ket{v}$. The\r\n\\emph{characteristic function} is defined as\r\n$c(\\lambda) \\equiv det |A - \\lambda I|$ where det is the \\emph{determinant}\r\nfunction of matrices. The solutions to the characteristic equation,\r\n$c(\\lambda) = 0$, are the eigenvalues of the operator $A$.\r\n\r\nA \\emph{diagonal representation} for an operator $A$ on a vector space $V$ is\r\na representation\r\n  \\begin{center}\r\n    $A = \\displaystyle\\sum_{i}\\lambda_{i}\\ket{i}\\bra{i}$\r\n  \\end{center}\r\nwhere the vectors $\\ket{i}$ form an orthonormal set of eigenvectors for $A$.\r\nA diagonal representation of Pauli $Z$ matrix:\r\n  \\begin{center}\r\n    $Z = \\begin{bmatrix} 1 & 0 \\\\ 0 & -1\\end{bmatrix} =\r\n    \\ket{0}\\bra{0} - \\ket{1}\\bra{1}$\r\n  \\end{center}\r\n\r\n%%% Section 1.1.6\r\n\\subsubsection{Adjoints and Hermitian Operators}\r\nSuppose $A$ is any linear operator on a Hilbert space, $V$, then\r\n$\\exists A^{\\dagger}$ on $V$ such that $\\forall \\ket{v}, \\ket{w} \\in V$,\r\n  \\begin{center}\r\n    $(\\ket{v}, \\ket{w}) = (A^{\\dagger}\\ket{v}, \\ket{w})$.\r\n  \\end{center}\r\n\r\nThis linear operator is know ad the \\emph{adjoint} or \\emph{Hermitian conjugate}\r\nof the operator $A$.\r\n\r\nNote: $(AB)^{\\dagger} = B^{\\dagger}A^{\\dagger}$\r\n\r\n($\\dagger$) is called \"dagger\" and is equal to\r\n$A^{\\dagger} \\equiv (A^{*})^{T}$, which is the transpose of the complex\r\nconjugate. Example:\r\n  \\begin{center}\r\n    $\r\n    \\begin{bmatrix}\r\n      1 + 3i & 2i \\\\\r\n      1 + i & 1 - 4i\r\n    \\end{bmatrix}^{\\dagger} = \r\n    \\begin{bmatrix}\r\n      1 - 3i & 1 - i \\\\\r\n      -2i & 1 + 4i\r\n    \\end{bmatrix}\r\n    $\r\n  \\end{center}\r\n\r\n%%% Section 1.1.7\r\n\\subsubsection{Tensor Products}\r\nThe \\emph{tensor product} if a way of putting vector spaces together to form\r\nlarger vector spaces. Suppose $V$ and $W$ are vector spaces of dimensions $m$\r\nand $n$ respectively, then $V \\otimes W$ is an $nm$ dimensional vector space.\r\nThe elements of $V \\otimes W$ are linear combinations of tensor products\r\n$\\ket{v}\\otimes\\ket{w}$ of elements $\\ket{v}$ of $V$ and $\\ket{w}$ of $W$. A\r\nmore intuitive way to represent this is through the \\emph{Kronecker product}.\r\nSuppose A is an $m$ by $n$ matrix and B is a $p$ by $q$ matrix then:\r\n  \\begin{center}\r\n  $ A \\otimes B = \r\n  \\begin{bmatrix}\r\n    A_{11}B & A_{12}B & \\cdots & A_{1n}B \\\\\r\n    A_{21}B & A_{22}B & \\cdots & A_{2n}B \\\\\r\n    \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\r\n    A_{m1}B & A_{m2}B & \\cdots & A_{mn}B\r\n  \\end{bmatrix}$\r\n  \\end{center}\r\nproduces an $nq \\cross mp$ matrix.\r\n\r\nExample:\r\n  \\begin{center}\r\n    $\r\n    \\begin{bmatrix}\r\n      1 \\\\ 2\r\n    \\end{bmatrix} \\otimes\r\n    \\begin{bmatrix}\r\n      2 \\\\ 3\r\n    \\end{bmatrix} = \r\n    \\begin{bmatrix}\r\n      2 \\\\ 3 \\\\ 4 \\\\ 6\r\n    \\end{bmatrix}\r\n    $.\r\n  \\end{center}\r\n\r\n%%% Section 1.1.8\r\n\\subsubsection{Operator Functions}\r\nLet $A = \\sum_{a}a\\ket{a}\\bra{a}$ be a spectral decomposition for a normal\r\noperator $A$. Define $f(A) \\equiv \\sum_{a}f(a)\\ket{a}\\bra{a}$.\r\n\r\nExample:\r\n  \\begin{center}\r\n  $e^{\\theta Z} =\r\n    \\begin{bmatrix}\r\n      e^{\\theta} & 0 \\\\\r\n      0 & e^{-\\theta}\r\n    \\end{bmatrix}$\r\n  \\end{center}\r\n\r\nSince $Z$ has eigenvectors $\\ket{0}$ and $\\ket{1}$.\r\n\r\nThe \\emph{trace} of $A$ is defined to be the sum of its diagonal elements,\r\n  \\begin{center}\r\n    $tr(A) \\equiv \\displaystyle\\sum_{i} A_{ii}$.\r\n  \\end{center}\r\nSome important properities:\r\n\r\nThe trace is \\emph{cyclic}: \r\n  \\begin{center}$tr(AB) = tr(BA)$\\end{center}\r\n\r\nThe trace is \\emph{linear}:\r\n  \\begin{center}$tr(A + B) = tr(A) + tr(B)$ and $tr(zA) = z tr(A)$\\end{center}\r\n\r\nThe trace is invariant under the \\emph{unitary similarity transform}:\r\n  \\begin{center}$A \\rightarrow UAU^{\\dagger}$\\end{center}\r\nas\r\n  \\begin{center}$tr(UAU^{\\dagger}) = tr(U^{\\dagger}UA) = tr(A)$\\end{center}\r\n\r\nSuppose $\\ket{\\psi}$ is a unit vector and $A$ is an arbitrary operator. To\r\nevaluate $tr(A\\ket{\\psi}\\bra{\\psi})$ use the Gram-Schmidt procedure to extend\r\n$\\ket{\\psi}$ to an orthonormal basis $\\ket{i}$ which includes $\\ket{\\psi}$ as\r\nthe first element. Then we have\r\n\r\n  \\begin{center}\r\n    $\r\n      tr(A\\ket{\\psi}\\bra{\\psi}) =\r\n      \\displaystyle\\sum_{i}\\bra{i}A\\ket{\\psi}\\bra{\\psi}\\ket{i}\r\n    $\r\n  \\end{center}\r\n  \\begin{center}\r\n    $\r\n      = \\bra{\\psi}A\\ket{\\psi}\r\n    $\r\n  \\end{center}\r\n\r\n%%% Section 1.1.9\r\n\\subsubsection{The Commutator and Anti-Commutator}\r\nThe \\emph{commutator} between two operators $A$ and $B$ is defined to be\r\n  \\begin{center}\r\n    $[A, B] \\equiv AB - BA$.\r\n  \\end{center}\r\n\r\nIf $[A, B] = 0$, that is, $AB = BA$, then we say that $A$ \\emph{commutes} with \r\n$B$.  The \\emph{anti-commutator} is defined as:\r\n  \\begin{center}\r\n    $\\{A, B\\} \\equiv AB + BA$\r\n  \\end{center}\r\nAnd we say $A$ \\emph{anti-commutes} with $B$ if $\\{A, B\\} = 0$.\r\n\r\n%%% Section 1.1.10\r\n\\subsubsection{Polar and Singular Value Decomposition}\r\nLet $A$ be a linear operator on a vector space $V$. $\\exists$ a unitary $U$\r\nand positive operators $J$ and $K$ such that $A = UJ = KU$, defined by\r\n$J \\equiv \\sqrt{A^{\\dagger}A}$ and $K \\equiv \\sqrt{AA^{\\dagger}}$.\r\n\r\nLet $A$ be a square matrix. Then $\\exists$ unitary matrics $U$ and $V$, and a\r\ndiagonal matrix $D$ with non-negative entries such that $A = UDV$. The\r\ndiagonal elements $D$ are called the \\emph{singular values} of $A$.\r\n\r\n\\subsection{Postulates of Quantum Mechanics}\r\n\\subsubsection{State Space}\r\n\\textbf{Postulate 1}: Assocaited to any isolated physical system is a complex\r\nvector space with inner product (that is, Hilbert space) know as the\r\n\\emph{state space} of the system. The system is completely described by its\r\n\\emph{state vector}, which is a unit vector in the system's state space.\r\n\r\nThe simplest quantum mechanical system is the \\emph{qubit}. An arbitrary\r\nvector in the state space can be written $\\ket{\\psi} = a\\ket{0} + b\\ket{1}$\r\nwhere $a, b \\in \\mathbb{C}$. The conditional that $\\ket{\\psi}$ be a unit\r\nvector, $\\bra{\\psi}\\ket{\\psi} = 1$, is equivalent to\r\n$|a|^{2} + |b|^{2} = 1$\r\n\r\n\\subsubsection{Evolution}\r\nHow does the state, $\\ket{\\psi}$, of a quantum mechanical system change with\r\ntime?\r\n\r\n\\textbf{Postulate 2.1}: The evolution of a \\emph{closed} quantum system is\r\ndescribed by a \\emph{unitary transformation}. That is, the state\r\n$\\ket{\\psi}$ of the system at time $t_{1}$ is related to the state\r\n$\\ket{\\psi'}$ of the system at time $t_{2}$ by a unitary operator\r\n$U$ which depends only on the times $t_{1}$ and $t_{2}$:\r\n  \\begin{center}\r\n    $\\ket{\\psi'} = U\\ket{\\psi}$.\r\n  \\end{center}\r\n\r\n\\textbf{Postulate 2.2}: The time evolution of the state of a closed quantum\r\nsystem is described by the \\emph{Schrödinger equation}.\r\n\r\n  \\begin{center}\r\n    $i\\hbar\\frac{\\partial \\ket{\\psi}}{\\partial t} = H\\ket{\\psi}$\r\n  \\end{center}\r\n\r\n\\subsubsection{Quantum Measurement}\r\n\\textbf{Postulate 3}: Quantum measurements are describled by a collection\r\n${M_{m}}$ of \\emph{measurement operators}.\r\n\r\nIf the state of the quantum system is $\\ket{\\psi}$ immediately before the\r\nmeasurement then the probability that the result $m$ occurs is give by\r\n  \\begin{center}\r\n    $p(m) = \\bra{\\psi}M_{m}^{\\dagger}M_{m}\\ket{\\psi}$\r\n  \\end{center}\r\nand the state after the measurement is\r\n  \\begin{center}\r\n    $\\frac{M_{m}\\ket{\\psi}}{\\sqrt{\\bra{\\psi}M_{m}^{\\dagger}M_{m}\\ket{\\psi}}}$\r\n  \\end{center}\r\n\r\n\\subsubsection{Distinguishing Quantum States}\r\n\\end{document}\r\n", "meta": {"hexsha": "e5d209d1e1ff55bab9ef7c88c6b4ee06b4a1d3f3", "size": 13303, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "two/notes.tex", "max_stars_repo_name": "gobrewers14/quantum-computing-notes", "max_stars_repo_head_hexsha": "af3d11703ecafd2a45da31b1a74112fe3937af35", "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": "two/notes.tex", "max_issues_repo_name": "gobrewers14/quantum-computing-notes", "max_issues_repo_head_hexsha": "af3d11703ecafd2a45da31b1a74112fe3937af35", "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": "two/notes.tex", "max_forks_repo_name": "gobrewers14/quantum-computing-notes", "max_forks_repo_head_hexsha": "af3d11703ecafd2a45da31b1a74112fe3937af35", "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.5088161209, "max_line_length": 82, "alphanum_fraction": 0.6191836428, "num_tokens": 4661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6660458789391882}}
{"text": "% \\documentclass[draft,11pt]{article}\n%\\documentclass[11pt]{article}\n\n\\chapter{Introduction to Spectral Graph Theory}\n\n%\\allowdisplaybreaks\n\n%%% for this lecture\n%\\newcommand\\gap{\\text{gap}}\n%\\newcommand{\\Zhao}[1]{{\\color{red} Zhao: #1}}\n\n%\\begin{document}\n\\sloppy\n%\\lecture{4 --- Wednesday, March 11th}\n%{Spring 2020}{Rasmus Kyng}{Introduction to Spectral Graph Theory}\n\nIn this chapter, we will study graphs through linear algebra. This\napproach is known as Spectral Graph Theory and turns out to be\nsurprisingly powerful.\nAn in-depth treatment of many topics in this area can be found in \\cite{S19}.\n\n\\section{Recap: Incidence and Adjacency Matrices, the Laplacian\n  Matrix and Electrical Energy}\n\nIn Chapter \\ref{sec:intro}, we looked at undirected graphs and we introduce the\nincidence matrix and the Laplacian of the graph. Let us recall these.\n\nWe consider an undirected weighted graph $G=(V, E, \\ww)$, with\n$n=\\sizeof{V}$ vertices and $m = \\sizeof{E}$ edges, where $\\ww \\in\n\\R_+^E$ assigns positive weight for every edge.\nLet's assume $G$ is connected.\n\nTo introduce the \\emph{edge-vertex incidence matrix} of the graph,\nwe first have to associate an arbitrary direction to every edge.\nWe then let\n$\\BB \\in \\R^{V \\times E}$.\n\\[\n  \\BB(v,e) =\n  \\begin{cases}\n    1 & \\text{ if } e = (u,v) \\\\\n    -1 &\\text{ if } e = (v,u) \\\\\n    0 &\\text{ o.w.}\n  \\end{cases}\n\\]\nThe edge directions are only there to help us track the meaning of signs of\nquantities defined on edges: The math we do should not depend on the\nchoice of sign.\n\nLet $\\WW \\in \\R^{E \\times E}$ be the diagonal matrix given by $\\WW =\n\\diag(\\ww)$, i.e $\\WW(e,e) = \\ww(e)$.\nWe define the Laplacian of the graph as $\\LL = \\BB\\WW\\BB^{\\trp}$.\nNote that in the first lecture, we define the Laplacian as\n$\\BB\\RR^{-1}\\BB^{\\trp}$,\nwhere $\\RR$ is the diagonal matrix with edge resistances on the\ndiagonal.\nWe want to think of high \\emph{weight} on an edge as expressing that two\nvertices are highly connected, whereas we think of high resistance on\nan edge as expressing that the two vertices are poorly connected, so\nwe let $\\ww(e) = 1/\\RR(e,e)$.\n\nThe weighted adjacency matrix $\\AA \\in \\R^{V \\times V}$ of a graph is\ngiven by\n\\[\n  \\AA(u,v) =\n  \\begin{cases}\n    \\ww(u,v) & \\text{ if } \\setof{u,v} \\in E \\\\\n    0  & \\text{ otherwise. }\n  \\end{cases}\n\\]\nNote that we treat the edges as undirected here, so $\\AA^{\\trp} = \\AA$.\nThe weighted degree of a vertex is defined as $\\dd(v) = \\sum_{\\setof{u,v}\n  \\in E} w(u,v)$. Again we treat the edges as undirected.\nLet $\\DD = \\diag(\\dd)$ be the diagonal matrix in $\\R^{V \\times V}$\nwith weighted degrees on the diagonal.\n\nIn Problem Set 1, you showed that $\\LL = \\DD - \\AA$, and that for $\\xx\n\\in \\R^V$,\n\\[\n\\xx^{\\trp} \\LL \\xx = \\sum_{\\setof{a,b} \\in E} \\ww(a,b) (\\xx(a) - \\xx(b))^2.\n  \\]\n\nNow we can express the net flow constraint that $\\ff$ routes $\\dd$ by\n\\[\n  \\BB \\ff = \\dd\n  .\n\\]\nThis is also called a conservation constraint. In our examples so far,\nwe have $\\dd(s) = -1$, $\\dd(t) = 1$ and $\\dd(u) = 0$ for all $u\\in V\\setminus\\setof{s,t}$.\n\nIf we let $\\RR = \\diag_{e \\in E} \\rr(e)$\nthen Ohm's law tells us that electrical voltages $\\xx$ will induce an\nelectrical flow $\\ff = \\RR^{-1}\\BB^{\\trp} \\xx$.\nWe defined the electrical energy of a flow $\\ff \\in \\R^E$ to be\n\\[\n  \\energy(\\ff) = \\sum_e \\rr(e) \\ff(e)^2 = \\ff^{\\trp} \\RR \\ff.\n\\]\nAnd, from Ohm's Law, we can then see that\n\\[\n \\energy(\\ff) = \\ff^{\\trp} \\RR \\ff = \\xx^{\\trp} \\LL \\xx.\n\\]\nHence, define the electrical energy associated with a set of voltages\nto be\n\\[\n \\energy(\\xx) = \\xx^{\\trp} \\LL \\xx.\n\\]\n\\paragraph{The Courant-Fisher Theorem.} Let us also recall the\nCourant-Fischer theorem, which we proved in Chapter 3 (Theorem \\ref{thm:courant-fischer}).\n\\begin{theorem}[The Courant-Fischer Theorem]\n  \\label{thm:courant-fischer}\n  Let $\\AA$ be a symmetric matrix in $\\R^{n\\times n}$, with\n  eigenvalues $\\lambda_1\\leq \\lambda_2 \\leq \\ldots \\leq \\lambda_n$.\n  Then\n  \\begin{enumerate}\n  \\item\n  \\label{thm:courant-fischer:minmax}\n    \\[\n    \\lambda_i = \\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  \\]\n\\item\n  \\label{thm:courant-fischer:maxmin}\n    \\[\n    \\lambda_i\n    =\n    \\max_{\n      \\substack{\n        \\mathrm{subspace~} W \\subseteq \\R^n\n        \\\\\n        \\dim{W} = n+1-i\n      }\n    }\n    \\min_{\n      \\xx \\in W, \\xx \\neq \\veczero\n    }\n    \\frac{\\xx^\\trp \\AA\\xx}{\\xx^\\trp\\xx}\n    \\]\n  \\end{enumerate}\n\\end{theorem}\n\nIn fact, from our proof of the Courant-Fischer theorem in Chapter 3,\nwe can also extract a slightly different statement: \n\n\\begin{theorem}[The Courant-Fischer Theorem, eigenbasis version]\n  \\label{thm:courant-fischer-eigvec}\n  Let $\\AA$ be a symmetric matrix in $\\R^{n\\times n}$, with\n  eigenvalues $\\lambda_1\\leq \\lambda_2 \\leq \\ldots \\leq \\lambda_n$,\n  and corresponding eigenvectors $\\xx_1, \\xx_2, \\ldots, \\xx_n$ which\n  form an othernormal basis.\n  Then\n  \\begin{enumerate}\n  \\item\n  \\label{thm:courant-fischer-eigvec:minmax}\n    \\[\n    \\lambda_i =\n    \\min_{\n      \\substack{ \\xx \\perp \\xx_1, \\ldots \\xx_{i-1}\n        \\\\ \\xx \\neq \\veczero}\n    }\n    \\frac{\\xx^\\trp \\AA\\xx}{\\xx^\\trp\\xx}\n  \\]\n\\item\n  \\label{thm:courant-fischer2:maxmin}\n    \\[\n    \\lambda_i =\n    \\max_{\n      \\substack{  \\xx \\perp \\xx_{i+1}, \\ldots \\xx_{n}\n        \\\\ \\xx \\neq \\veczero}\n    }\n    \\frac{\\xx^\\trp \\AA\\xx}{\\xx^\\trp\\xx}\n    \\]\n  \\end{enumerate}\n\\end{theorem}\n\nOf course, we also have $\\lambda_i(\\AA) = \\frac{\\xx_i ^\\trp \\AA \\xx_i\n}{\\xx_i^\\trp\\xx_i}$.\n\\section{Understanding Eigenvalues of the Laplacian}\nWe would like to understand the eigenvalues of the Laplacian matrix of\na graph.\n\nBut first, why should we care? It turns out that Laplacian eigenvalues can help\nus understand many properties of a graph.\nBut we are going to start off with simple motivating observation: Electrical\nvoltages $\\xx \\in \\R^V$ consume electrical energy $\\energy(\\xx) =\n\\xx^{\\trp} \\LL \\xx$.\nThis means that by the Courant-Fischer Theorem\n\\[\n  \\energy(\\xx) =\n  \\xx^{\\trp} \\LL \\xx \\leq \\lambda_n(L)  \\xx^{\\trp} \\xx\n\\]\nAnd, for any voltages $\\xx \\perp \\vecone$, \n\\[\n  \\energy(\\xx) =\n  \\xx^{\\trp} \\LL \\xx \\geq \\lambda_2(L)  \\xx^{\\trp} \\xx.\n\\]\nThus, we can use the eigenvalues to give upper and lower bounds on how\nmuch electrical energy will be consumed by the flow induced by $\\xx$,\nin terms compared to $\\xx^{\\trp} \\xx = \\norm{\\xx}_2^2$.\n\nIn a couple of chapters, we will also prove the following claim, which\nshows that the Laplacian eigenvalues can directly tell us about the\nelectrical energy that is required to route a given demand.\n\n\\begin{claim}\n  Given a demand vector\n  $\\dd \\in \\R^V$ such that $\\dd \\perp \\vecone$,\n  the electrical voltages $\\xx$ that route $\\dd$ satisfy $\\LL \\xx =\n  \\dd$ and the electrical energy of these voltages satifies\n  \\[\n\\frac{\\norm{\\dd}_2^2}{\\lambda_n} \\leq \\energy(\\xx) \\leq \\frac{\\norm{\\dd}_2^2}{\\lambda_2}\n    \\]\n\\end{claim}\n\n\n\\paragraph{Eigenvalues of the Laplacian of a Complete Graph.}\nTo get a sense of how Laplacian eigenvalues behave, let us start by considering the $n$ vertex complete graph with unit weights,\nwhich we denote by $K_n$.\nThe adjacency matrix of $K_n$ is $\\AA = \\vecone \\vecone^\\trp - \\II$,\nsince it has ones everywhere, except for the diagonal, where entries\nare zero.\nThe degree matrix $\\DD = (n-1) \\II$.\nThus the Laplacian is $\\LL =  \\DD - \\AA = n\\II - \\vecone\n\\vecone^\\trp$.\n\nThus for any $\\yy \\perp \\vecone$, we have\n$\\yy^{\\trp} \\LL \\yy = n \\yy^{\\trp} \\yy - (\\vecone^{\\trp} \\yy)^2 = n \\yy^{\\trp} \\yy$.\n\nFrom this, we can conclude that any $\\yy \\perp \\vecone$ is an\neigenvector of eigenvalue $n$, and that all $\\lambda_2 = \\lambda_3 =\n\\ldots = \\lambda_n = n$.\n\nNext, let us try to understand $\\lambda_2$ and $\\lambda_n$ for\n$P_n$, the $n$ vertex path graph with unit weight edges.\nI.e. the graph has edges $E = \\setof{ \\setof{i,i+1}  \\text{ for } i = 1 \\text{ to\n  } (n-1) }$.\n\nThis is in a sense the least well-connected unit weight graph on $n$\nvertices, whereas $K_n$ is the most well-connected.\n\n\\subsection{Test Vector Bounds on $\\lambda_2$ and $\\lambda_n$}\nWe can use the eigenbasis version of the Courant-Fisher theorem to observe\nthat the second-smallest eigenvalue of the Laplacian is given by\n\\begin{align}\n  \\label{eq:lambda2bymin}\n\\lambda_2(\\LL) = \\min_{ \\substack{ \\xx \\neq \\veczero \\\\ \\xx^\\top \\vecone = 0} } \\frac{ \\xx^\\top \\LL \\xx}{ \\xx^\\top \\xx}.\n\\end{align}\n\nWe can get a better understanding of this particular case through a couple of simple\nobservations. Suppose $\\xx = \\yy + \\alpha \\vecone$, where $\\yy \\perp\n\\vecone$.\nThen $\\xx^{\\trp} \\LL \\xx = \\yy^{\\trp} \\LL \\yy$, and $\\norm{\\xx}_2^2 =\n\\norm{\\yy}^2 + \\alpha^2 \\norm{\\vecone}^2$.\nSo for any given vector, you can increase the value of $\\frac{\n  \\xx^\\top \\LL \\xx}{ \\xx^\\top \\xx}$, by instead replacing $\\xx$ with\nthe component orthogonal to $\\xx$, which we denoted by $\\yy$.\n\nWe can conclude from Equation~\\eqref{eq:lambda2bymin} that for \\emph{any} vector $\\yy \\perp \\vecone$,\n\\begin{align*}\n\\lambda_2 \\leq \\frac{ \\yy^\\trp \\LL \\yy}{ \\yy^\\trp \\yy}\n\\end{align*}\nWhen we use a vector $\\yy$ in this way to prove a bound on an eigenvalue, we call it a \\emph{test vector}.\n\nNow, we'll use a test vector to give an upper bound on $\\lambda_2(\\LL_{P_n})$.\nLet $\\xx \\in \\R^V$ be given by $\\xx ( i ) = ( n + 1 ) - 2 i$, for $i\n\\in [n]$. This vector satisfies $\\xx \\bot \\vecone$.\nWe picked this because we wanted a sequence of values growing linearly along\nthe path, while also making sure that the vector is orthogonal to\n$\\vecone$.\nNow\n\\begin{align*}\n\\lambda_2(\\LL_{P_n})\n\\leq & ~ \\frac{ \\sum_{i \\in [n-1]} ( \\xx(i) - \\xx(i+1) )^2  }{ \\sum_{i=1}^n \\xx(i)^2 } \\\\\n= & ~ \\frac{ \\sum_{i=1}^{n-1} 2^2 }{ \\sum_{i=1}^n ( n + 1 - 2 i )^2 } \\\\\n= & ~ \\frac{ 4 ( n - 1 ) }{ ( n + 1 ) n ( n - 1 ) / 3 } \\\\\n= & ~ \\frac{ 12 } { n ( n + 1 ) } \\leq \\frac{ 12 } { n^2 }.\n\\end{align*}\n\nLater, we will prove a lower bound that shows this value is right up\nto a constant factor.\nBut the test vector approach based on the Courant-Fischer theorem\ndoesn't immediately work\nwhen we want to prove lower bounds on $\\lambda_2(\\LL)$.\n\nWe can see from either version of the Courant-Fischer theorem that\n\\begin{align}\n  \\label{eq:lambda2bymin}\n\\lambda_n(\\LL) = \\max_{ \\substack{ \\vv \\neq \\veczero} } \\frac{ \\vv^\\top \\LL \\vv}{ \\vv^\\top \\vv}.\n\\end{align}\nThus for \\emph{any} vector $\\yy \\neq 0$,\n\\begin{align*}\n\\lambda_n \\geq \\frac{ \\yy^\\trp \\LL \\yy}{ \\yy^\\trp \\yy}.\n\\end{align*}\nThis means get a test vector-based lower bound on $\\lambda_n$.\nLet us apply this to the Laplacian of $P_n$.\nWe'll try the vector $\\xx \\in \\R^V$ be given by $\\xx ( 1 ) = -1$,\nand $\\xx(n) = 1$ and $\\xx(i) = 0$ for $i \\neq 0,1$.\n\nHere we get\n\\begin{align*}\n\\lambda_n(\\LL_{P_n}) \\geq \\frac{ \\yy^\\trp \\LL \\yy}{ \\yy^\\trp \\yy} = \\frac{2}{2} = 1.\n\\end{align*}\n\nAgain, it's not clear how to use the Courant-Fischer theorem to prove\nan upper bound on $\\lambda_n(\\LL) $.\nBut, later we'll see how to prove an upper that shows that\nfor $P_n$, the lower bound we obtained is right up to constant factors.\n\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{Graphic Inequalities}\n% I begin by recalling an extremely useful piece of notation that is used in the Optimization community. For a symmetric matrix ${\\bf A}$, we write\n% \\begin{align*}\n% {\\bf A} \\succeq 0\n% \\end{align*}\n% if ${\\bf A}$ is positive semidefinite. That is, if all of the eigenvalues of ${\\bf A}$ are nonnegative, which is equivalent to\n% \\begin{align*}\n% \\vv^\\top {\\bf A} \\vv\\geq 0,\n% \\end{align*}\n% for all $\\vv$. We similarly write\n% \\begin{align*}\n% {\\bf A} \\succeq {\\bf B}\n% \\end{align*}\n% if\n% \\begin{align*}\n% {\\bf A} - {\\bf B} \\succeq 0\n% \\end{align*}\n% which is equivalent to\n% \\begin{align*}\n% \\vv^\\top {\\bf A} \\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% {\\bf A} \\succeq {\\bf B}, \\mathrm{~and~} {\\bf B} \\succeq {\\bf C} \\mathrm{~implies~} {\\bf A} \\succeq {\\bf C},\n% \\end{align*}\n% and\n% \\begin{align*}\n% {\\bf A} \\succeq {\\bf B} \\mathrm{~implies~} {\\bf A} + {\\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}\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.\n\n% For example, we will\n% \\begin{align*}\n% (n-1) \\cdot P_n \\succeq G_{1,n},\n% \\end{align*}\n% where $P_n$ is the path from vertex $1$ to vertex $n$, and $G_{1,n}$ is the graph with just the edge $(1,n)$. All of these edges are unweighted.\n\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\n% We need to show that for every $x \\in \\in \\R^n$,\n% \\begin{align*}\n% (n-1) \\cdot \\sum_{i=1}^{n-1} ( x(i+1) - x(i) )^2 \\geq ( x(n) - x(1) )^2.\n% \\end{align*}\n% For $i \\in [n-1]$, set\n% \\begin{align*}\n% \\Delta (i) = x(i+1) - x(i).\n% \\end{align*}\n% The inequality we need to prove then becomes\n% \\begin{align*}\n% (n-1) \\sum_{i=1}^{n-1} ( \\Delta(i) )^2 \\geq \\left( \\sum_{i=1}^{n-1} \\Delta (i)  \\right)^2.\n% \\end{align*}\n% But, this is just the Cauchy-Schwartz inequality. I'll remind you that Cauchy-Schwartz just follows from the fact that the inner product of two vectors is at most the product of their norms:\n% \\begin{align*}\n% (n-1) \\sum_{i=1}^{n-1} ( \\Delta (i) )^2\n% = & ~ \\| \\vecone_{n-1} \\|^2 \\cdot \\| \\Delta \\|^2 \\\\\n% = & ~ ( \\| \\vecone_{n-1} \\| \\cdot \\| \\Delta \\|^2 )^2 \\\\\n% \\geq & ~  ( \\vecone^\\top_{n-1} \\Delta )^2  \\\\\n% = & ~ (  \\sum_{i=1}^{n-1} \\Delta(i) )^2\n% \\end{align*}\n\n% \\end{proof}\n\n% \\Zhao{We skip Lemma 4.6.2}\n\n% \\subsubsection{Bounding $\\lambda_2$ of a Path Graph}\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\n% To prove a lower bound on $\\lambda_2 (P_n)$, we will prove that some multiple of the path is at least the complete graph. To this end, write\n% \\begin{align*}\n% L_{K_n} = \\sum_{i < j} L_{G_{i,j}}\n% \\end{align*}\n% and recall that\n% \\begin{align*}\n% \\lambda_2 (K_n) = n.\n% \\end{align*}\n\n% For every edge $(i,j)$ in the complete graph, we apply the only inequality available in the path :\n% \\begin{align*}\n% G_{i,j}\n% \\preceq & ~ (j-i) \\sum_{k=i}^{j-1} G_{k,k+1} \\\\\n% \\preceq & ~ (j-i) P_n.\n% \\end{align*}\n% This 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\n% Summing inequality (4.3) over all edges $(i,j) \\in K_n$ gives\n% \\begin{align*}\n% K_n = \\sum_{i < j} G_{i,j} \\preceq \\sum_{i,j} (j-i)P_n.\n% \\end{align*}\n% To finish the proof, we compute\n% \\begin{align*}\n% \\sum_{1 \\leq i < j \\leq n} (j-i)\n% = & ~ \\sum_{k=1}^{n-1} k (n-k) \\\\\n% = & ~ n (n+1) (n-1)/6.\n% \\end{align*}\n\n% So\n% \\begin{align*}\n% L_{K_n} \\preceq \\frac{ n(n+1) (n-1) }{6} \\cdot L_{P_n}.\n% \\end{align*}\n\n% Applying Lemma 4.4.1, we obtain\n% \\begin{align*}\n% \\frac{6}{ (n+1)(n-1) } \\leq \\lambda_2 (P_n).\n% \\end{align*}\n% This only differs from the upper bound (4.1) by a factor of 2. \\Zhao{will fix (4.1) later.}\n\n\n\n\n% \\subsection{The complete binary tree}\n\n% Let's do the same analysis with the complete binary tree.\n\n% One way of understanding the complete binary tree of depth $d+1$ is to identify the vertices of the tree strings over $\\{0,1\\}$ of length at most $d$. The root of the tree is the empty string. Every other node has one ancestor, which is obtained by removing the last character of its string, and two children, which are obtained by appending one character to its label.\n\n% Alternatively, you can describe it as the graph on $n = 2^{d+1} - 1$ nodes with edges of the form $(i,2i)$ and $(i,2i+1)$ for $i < n$.\n% We will name this graph $T_d$.\n\n% \\Zhao{Let's ignore the picture for now.}\n\n% Let's first upper bound $\\lambda_2 (T_d)$ by constructing a test vector $x$. Set $x(1) = 0$, $x(2) = 1$, and $x(3) = -1$. Then, for every vertex $u$ that we can reach from node $2$ without going through node $1$, we set $x(u) = 1$. For all the other nodes, we set $x(u) = -1$.\n\n% We then have\n% \\begin{align*}\n% \\lambda_2\n% \\leq & ~ \\frac{ \\sum_{ (i,j) \\in T_d } ( x_i - x_j )^2 } { \\sum_i x_i^2 } \\\\\n% = & ~ \\frac{ (x_1 - x_2)^2 + (x_1 - x_3)^2  }{ n - 1 } \\\\\n% = & ~ 2/ (n-1).\n% \\end{align*}\n\n% We will again prove a lower bound comparing $T_d$ to the complete graph. For each edge $(i,j) \\in K_n$, let $T_d^{i,j}$ denote the unique path in $T$ from $i$ to $j$. This path will have length at most $2d$. So, we have\n% \\begin{align*}\n% K_n\n% = & ~ \\sum_{i < j} G_{i,j} \\\\\n% \\preceq & ~ \\sum_{i < j} (2d) T_d^{i,j} \\\\\n% \\preceq & ~ \\sum_{i < j} (2 \\log_2 n) T_d \\\\\n% = & ~ {n \\choose 2} (2\\log_2 n) T_d\n% \\end{align*}\n% SO, we obtain the bound\n% \\begin{align*}\n% {n \\choose 2} \\cdot (2 \\log_2 n) \\lambda_{2} (T_d) \\geq n,\n% \\end{align*}\n% which implies\n% \\begin{align*}\n% \\lambda_2 (T_d) \\geq \\frac{1}{ (n-1) \\log_2 n }\n% \\end{align*}\n% In the next problem set, I will ask you to improve this lower bound to $1/(cn)$ for some constant $c$.\n\n\n\n\n\n% \\section{Graded HW notes}\n\n% \\begin{itemize}\n% \\item I'd like an exercise about applying accelerated gradient\n%   descent to\n% \\end{itemize}\n\n\n%\\FloatBarrier\n%\\bibliographystyle{alpha}\n%\\bibliography{refs}\n\n\n\n\n%\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"agao21_script\"\n%%% TeX-engine: luatex\n%%% End:\n", "meta": {"hexsha": "3e9bd41d53f304ef1c44ff638772f129858f8d86", "size": 21024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture4_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/lecture4_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/lecture4_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": 36.1237113402, "max_line_length": 371, "alphanum_fraction": 0.6440258752, "num_tokens": 7452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401362, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6660256376824082}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\begin{document}\n\n\\title{Analysis}\n\\date{Lent 2016}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Differentiation}\n\\begin{thm}(IFT)\nAssume $I$ is an open interval, $f:I\\to \\R$ is differentiable on $I$, $f'\\left(x\\right)\\neq 0 \\forall x\\in I$. Then $J=f\\left(I\\right)$ is an open interval, $f$ is strictly monotonic, and hence bijection $I\\to J$. Moreover, $f^{-1}:J\\to I$ is differentiable, and\n\\begin{equation*}\n\\left(f^{-1}\\right)'\\left(y\\right)=\\frac{1}{f'\\left(f^{-1}\\left(y\\right)\\right)}.\n\\end{equation*}\n\\begin{proof}\n\\underline{$f$ is injective}: if $x<y$ and $f\\left(x\\right)=f\\left(y\\right)$. Then by Rolle's theorem ($f$ differentiable and hence continuous on $I$),$\\exists c\\in \\left(x,y\\right)$s.t. $f'\\left(c\\right)=0$. Contradiction.\\\\\n\\underline{$f$ is strictly monotonic}: $\\forall x<y$ in $I$, either $f\\left(x\\right)<f\\left(y\\right)$ or $f\\left(x\\right)>f\\left(y\\right)$. We next show that $\\forall a<b<c$ in $I$ either $f\\left(a\\right)<f\\left(b\\right)<f\\left(c\\right)$ or $f\\left(a\\right)>f\\left(b\\right)>f\\left(c\\right)$. If not then $\\exists a<b<c$ in $I$ s.t.\\\\\neither $f\\left(a\\right)<f\\left(b\\right), f\\left(b\\right)>f\\left(c\\right)$\\\\\nor $f\\left(a\\right)>f\\left(b\\right), f\\left(b\\right)<f\\left(c\\right)$.\\\\\nIn the first case, fix $w$ s.t. $\\max\\left(f\\left(a\\right),f\\left(c\\right)\\right)<w<f\\left(b\\right)$. Then $f\\left(a\\right)<w<f\\left(b\\right)$ so by IVT, $\\exists x\\in \\left(a,b\\right)$ s.t. $f\\left(x\\right)=w$, and $f\\left(b\\right)>w>f\\left(c\\right)$ so by IVT $\\exists y\\in \\left(b,c\\right)$ s.t. $f\\left(y\\right)=w$. Contradicts with injectivity.\\\\\nThe other case is similar (apply the first case to $\\left(-f\\right)$).\\\\\nFix $a<b$ in $I$. We show that if $f\\left(a\\right)<f\\left(b\\right)$ then $f$ is strictly increasing on $I$. The case $f\\left(a\\right)>f\\left(b\\right)$ will be similar and then $f$ is strictly decreasing on $I$.\\\\\nLet $x\\in I$. If $x<a$ then considering the triple $x<a<b$ we obtain $f\\left(x\\right)<f\\left(a\\right)$. If $a<x$ then\\\\\neither $x<b$ and considering $a<x<b$, get $f\\left(a\\right)<f\\left(x\\right)$\\\\\nor $x>b$ and considering $a<b<x$, get $f\\left(a\\right)<f\\left(x\\right)$\\\\\nor $x=b$ and then $f\\left(a\\right)<f\\left(b\\right)=f\\left(x\\right)$.\\\\\nSo far we have $\\forall x<y$ in $I$ if $x=a$ or $y=a$ then $f\\left(x\\right)<f\\left(y\\right)$.\\\\\nFor arbitrary $x<y$ in $I$ with $a\\neq x$ and $a \\neq y$ we have 3 cases: $a<x<y$,$x<a<y$,$x<y<a$, applying the previous claim we get $f\\left(x\\right)<f\\left(y\\right)$.\\\\\n\\underline{$J$ is an interval}: Let $x<y<z$ in $\\R$ s.t. $x,z\\in J$. We have $a,b\\in I$ s.t. $x=f\\left(a\\right)$,$z=f\\left(b\\right)$. So by IVT, $\\exists c$ between $a,b$ s.t. $f\\left(c\\right)=y$, so $y\\in J$.\\\\\n\\underline{$J$ is an open interval}: Given $y\\in J$,$\\exists b\\in I$ s.t. $f\\left(b\\right)=y$.\\\\\n$I$ is an open interval, so $\\exists a,c\\in I$,$a<b<c$.\\\\\nThen either $f\\left(a\\right)<f\\left(b\\right)<f\\left(c\\right)$ or $f\\left(a\\right)>f\\left(b\\right)>f\\left(c\\right)$.\\\\\nSo $y$ is not an endpoint of $J$.\\\\\n\nNow $f:I\\to J$ is a strictly monotonic bijection, so $f^{-1}:J\\to I$ is continuous by Theorem 3.6.\\\\\n\\underline{$f^{-1}$ differentiable}: Let $y\\in J$. We consider\n\\begin{equation*}\n\\frac{f^{-1}\\left(y+k\\right)-f^{-1}\\left(y\\right)}{k} \\text{ as } k\\to 0.\n\\end{equation*}\nFor given $k$, let $h=f^{-1}\\left(y+k\\right)-f^{-1}\\left(y\\right)$ and let $x=f^{-1}\\left(y\\right)$.\\\\\nThen $f^{-1}\\left(y+k\\right)=h+f^{-1}\\left(y\\right)=x+h$,\\\\\n$k=f\\left(x+h\\right)-f\\left(x\\right)$,\n\\begin{equation*}\n\\begin{aligned}\n\\frac{f^{-1}\\left(y+k\\right)-f^{-1}\\left(y\\right)}{k}&=\\frac{h}{f\\left(x+h\\right)-f\\left(x\\right)}\\\\\n&=\\frac{1}{\\frac{f\\left(x+h\\right)-f\\left(x\\right)}{h}}\n\\end{aligned}\n\\end{equation*}\nHere $h=h\\left(k\\right)$ depends on $k$, $h\\left(k\\right) \\neq 0$ if $k\\neq 0$ and $h\\left(k\\right) \\to 0$ as $k \\to 0$ since $f^{-1}$ is continuous.\\\\\nSo\n\\begin{equation*}\n\\frac{f^{-1}\\left(y+k\\right)-f^{-1}\\left(y\\right)}{k} \\to \\frac{1}{f'\\left(x\\right)} = \\frac{1}{f'\\left(f^{-1}\\left(y\\right)\\right)}.\n\\end{equation*}\n\\end{proof}\n\\end{thm}\n\n\\begin{eg}\nFix $n\\in \\N$, consider $f:\\left(0,\\infty\\right)\\to\\R$,$f\\left(x\\right)=x^n$.\\\\\n$f$ is strictly increasing, onto $\\left(0,\\infty\\right)$, differentiable, $f'\\left(x\\right)=nx^{n-1}$.\\\\\nWe have $f^{-1}:\\left(0,\\infty\\right)\\to\\left(0,\\infty\\right)$,$f^{-1}\\left(x\\right)=x^{\\frac{1}{n}}$(definition).\\\\\nThe extra information from IFT is that $f^{-1}$ is differentiable, and\n\\begin{equation*}\n\\begin{aligned}\n\\left(f^{-1}\\right)'\\left(y\\right)&=\\frac{1}{f'\\left(f^{-1}\\left(y\\right)\\right)}\\\\\n&=\\frac{1}{n\\left(y^{\\frac{1}{n}}\\right)^{n-1}}\\\\\n&=\\frac{1}{n} y^{\\frac{1}{n}-1}.\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\nFor $\\alpha=\\frac{p}{q}$, $p,q\\in\\N$, $x^\\alpha = \\left(x^{\\frac{1}{q}}\\right)^p$ is differentiable by Chain Rule:\\\\\n$\\frac{d}{dx}\\left(x^\\alpha\\right)=p\\left(x^\\frac{1}{q}\\right)^{p-1}\\cdot\\frac{1}{q}x^{\\frac{1}{q}-1}=\\alpha x^{\\alpha-1}$.\\\\\nFor $\\alpha\\in\\Q$,$\\alpha<0$,$x^\\alpha = \\frac{1}{x^{-\\alpha}}$ is differentiable, and\\\\\n$\\frac{d}{dx}\\left(x^\\alpha\\right)=-\\frac{1}{\\left(x^{-\\alpha}\\right)^2}\\cdot\\left(-\\alpha\\right)x^{-\\alpha-1}=\\alpha x^{\\alpha-1}$.\\\\\nNeed $exp$, $log$ for $\\alpha \\in \\R$.\\\\\n\n\\subsection{Complex differentiation}\nGiven $f:\\C\\to\\C$, $a\\in\\C$, we say $f$ is complex differentiable at $a$ if \n\\begin{equation*}\n\\begin{aligned}\n\\lim_{h\\to 0} \\frac{f(\\left(a+h\\right)-f\\left(a\\right)}{h}\n\\end{aligned}\n\\end{equation*}\nexists and we denote the limit by $f'\\left(a\\right)$ and call it the \\emph{derivative of $f$ at $a$}.\\\\\nSay $f$ is \\emph{complex differentiable} on $\\C$ (or \\emph{holomorphic}) if it's complex differentiable at every $a\\in\\C$.\\\\\n$f$ is complex differentiable at $a$ $\\iff$ $\\exists \\lambda\\in\\C$ $f\\left(a+\\right)=f\\left(a\\right)+\\lambda h+\\epsilon\\left(h\\right)\\cdot h$, where $\\epsilon\\left(h\\right)\\to 0$ as $h\\to 0$. Then $\\lambda = f'\\left(a\\right)$.\\\\\n\n\\begin{prop}\n$f$ is complex differentiable at $a$ $\\implies$ $f$ is continuous at $a$.\n\\end{prop}\nProperty 2, Theorem 3 also hold.\\\\\n\nFor $z\\in\\C$, $\\sum_{n=0}^\\infty \\frac{z^n}{n!}$ converges absolutely and hence converges.\\\\\nFor $z=0$ ok, for $z\\neq 0$ we use the ratio test:\n\\begin{equation*}\n\\frac{|\\frac{z^{n+1}}{\\left(n+1\\right)!}|}{|\\frac{z^n}{n!}|}=\\frac{|z|}{n+1}\\to 0 \\text{ as } n\\to \\infty.\n\\end{equation*}\n\nWe define the \\emph{exponential function} $\\exp :\\C\\to\\C$ by $\\exp\\left(z\\right)=\\sum_{n=0}^\\infty \\frac{z^n}{n!}$.\\\\\n\n\\begin{thm} (Properties of $\\exp$)\\\\\n1) $\\exp\\left(z+n\\right)=\\exp\\left(z\\right)\\exp\\left(w\\right)$ $\\forall z,w\\in\\C$;\\\\\n2) $\\exp\\left(0\\right)=1$,$\\exp\\left(z\\right)\\neq 0 \\forall z\\in\\C$;\\\\\n3) $\\overline{\\exp\\left(z\\right)}=\\exp\\left(\\overline{z}\\right)$;\\\\\n4) $\\exp\\left(x\\right)\\in\\R \\forall x\\in\\R$;\\\\\n5) $\\exp\\left(ix\\right)\\in T=\\left\\{z\\in\\C | |z|=1\\right\\} \\forall x\\in\\R$;\\\\\n6) $\\exp$ is complex differentiable at $0$, $\\exp'\\left(0\\right)=1$;\\\\\n7) $\\exp$ is holomorphic, and $\\exp'\\left(z\\right) = \\exp\\left(z\\right)$.\\\\\n\\begin{proof}\n1) Let $a_{k}=\\frac{z^n}{n'}$,$b_{n}=\\frac{w^n}{n!}$,$c_{n}=\\frac{\\left(z+w\\right)^n}{n!}$ for $n\\geq 0$.\\\\\n$c_{n} = \\frac{1}{n!}\\sum_{j=0}^n {n \\choose j} z^j w^{n-j} = \\sum_{j=0}^n \\frac{1}{j!\\left(n-j\\right)!}z^j w^{n-j} = \\sum_{j+k=n} a_{j} b_{j}$.\\\\\n\\begin{equation*}\n\\begin{aligned}\n|\\sum_{n=0}^N c_{n} - \\left(\\sum_{n=0}^N a_{n}\\right)\\left(\\sum_{n=0}^N b_{n}\\right)|\\\\\n&= |\\sum_{n=0}^N \\sum_{j+k=n} a_{j} b_{k} - \\sum_{j,k=0}^N a_{j} b_{k}|\\\\\n&= |\\sum_{j,k=0,j+k>N}^N a_{j} b_{k}|\\\\\n&\\leq \\sum_{j,k=0,j+k>N}^N |a_{j}||b_{k}|\\\\\n&\\leq \\sum_{j,k=0,j>\\frac{N}{2} \\text{ or } k>\\frac{N}{2}}^N |a_{j}| |b_{k}|\\\\\n&\\leq \\sum_{\\frac{N}{2}<j\\leq N} |a_{j}| \\cdot \\sum_{k=0}^N |b_{k}| + \\sum_{\\frac{N}{2}<k\\leq N} |b_{k}| \\cdot \\sum_{j=0}^N |a_{j}|\\\\\n&\\to 0 \\text{ as } N\\to\\infty.\n\\end{aligned}\n\\end{equation*}\nSo $\\sum_{n=0}^\\infty c_{n} = \\left(\\sum_{n=0}^\\infty a_{n}\\right)\\left(\\sum_{n=0}^\\infty b_{n}\\right)$.\\\\\n\n2) $\\exp\\left(0\\right)$ by definition.\\\\\n$1=\\exp\\left(0\\right)=\\exp\\left(z+\\left(-z\\right)\\right)=\\exp\\left(z\\right)\\exp\\left(-z\\right)$.\\\\\nSo $\\exp\\left(z\\right)\\neq 0 \\forall z\\in \\C$.\\\\\n\n3) $\\overline{\\exp\\left(z\\right)}=\\exp\\left(\\overline{z}\\right) \\forall z\\in \\C$.\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\overline{\\exp\\left(z\\right)}&=\\left(\\lim_{N\\to\\infty} \\sum_{n=0}^N \\frac{z^n}{n!}\\right)\\\\\n&=\\lim_{N\\to\\infty} \\overline{\\left(\\sum_{n=0}^N \\frac{z^n}{n!}\\right)}\\\\\n&=\\lim_{N\\to\\infty} \\sum_{n=0}^N \\frac{\\left(\\overline{z}\\right)^n}{n!}\\\\\n&=\\exp\\left(\\overline{z}\\right).\n\\end{aligned}\n\\end{equation*}\n\n4) $\\exp\\left(x\\right)\\in\\R \\forall x\\in\\R$ and $\\exp\\left(ix\\right)\\in T \\forall x\\in\\R$.\\\\\n$\\overline{\\exp\\left(x\\right)} = \\exp\\left(\\overline{x}\\right)=\\exp\\left(x\\right)$, so $\\exp\\left(x\\right)\\in\\R$.\\\\\n\\begin{equation*}\n\\begin{aligned}\n|\\exp\\left(ix\\right)|^2 &= \\exp\\left(ix\\right)\\\\\n\\overline{\\exp\\left(ix\\right)}\\\\\n&=\\exp\\left(ix\\right)\\exp\\left(-ix\\right)\\\\\n&=\\exp\\left(0\\right)\\\\\n&=1.\n\\end{aligned}\n\\end{equation*}\n\n5) $\\exp'\\left(0\\right)=1$.\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\exp\\left(h\\right)&=\\sum_{n=0}^\\infty \\frac{h^n}{n!}\\\\\n&= 1+h+\\sum_{n=2}^\\infty \\frac{h^n}{n!}\\\\\n&= \\exp\\left(0\\right)+h+h\\sum_{n=2}^\\infty \\frac{h^{n-1}}{n!}.\n\\end{aligned}\n\\end{equation*}\nDefine $\\epsilon\\left(h\\right) = \\sum_{n=2}^\\infty \\frac{h^{n-1}}{n!}$. Need $\\epsilon\\left(h\\right)\\to 0$ as $h\\to 0$.\\\\\nWe have\n\\begin{equation*}\n\\begin{aligned}\n|\\epsilon\\left(h\\right)|&\\leq \\sum_{n=2}^\\infty |\\frac{h^{n-1}}{n!}\\\\\n&= \\sum_{n=2}^\\infty \\frac{|h|^{n-1}}{n!}\\\\\n&\\leq \\sum_{n=2}^\\infty |h|^{n-1} \\text{  assume }|h| \\leq 1\\\\\n&=\\frac{|h|}{1-|h|}\n\\end{aligned}\n\\end{equation*}\nSo $\\epsilon\\left(h\\right)\\to 0$ as $h\\to 0$. Done.\\\\\n\n6) $\\exp: \\C\\to\\C$ is holomorphic.\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\exp\\left(z+h\\right)-\\exp\\left(z\\right)}{h}\\\\\n&= \\frac{\\exp\\left(z\\right)\\cdot\\exp\\left(h\\right)-\\exp\\left(z\\right)}{h}\\\\\n&=\\exp\\left(z\\right)\\frac{\\exp\\left(h\\right)-\\exp\\left(0\\right)}{h}\\\\\n&\\to \\exp\\left(z\\right)\n\\end{aligned}\n\\end{equation*}\nas $h\\to 0$.\\\\\nSo $\\exp'\\left(z\\right) = \\exp\\left(z\\right)$.\n\\end{proof}\n\\end{thm}\n\nBy 4) we have a real function $\\exp:\\R\\to\\R$.\\\\\n\n\\begin{thm}\n$\\exp:\\R\\to\\R$ is a strictly increasing, differentiable bijection of $\\R$ onto $\\R^+$;\\\\\nFor $x\\geq 0$, $\\exp\\left(x\\right)\\geq 1+x$ so $\\exp\\left(x\\right)\\to\\infty$ as $x\\to\\infty$;\\\\\nFor $x\\leq 0$, $\\exp\\left(x\\right)=\\frac{1}{\\exp\\left(-x\\right)}\\to 0$ as $x\\to -\\infty$.\\\\\n\\begin{proof}\nFor $x\\geq 0$, $\\exp\\left(x\\right)=\\sum_{n=0}^\\infty \\frac{x^n}{n!} \\geq 1+x > 0$.\nSo for $x \\leq 0$,\n\\begin{equation*}\n\\begin{aligned}\n1&=\\exp\\left(x+\\left(-x\\right)\\right)\\\\\n&= \\exp\\left(x\\right)\\exp\\left(-x\\right)\n\\end{aligned}\n\\end{equation*}\nSo $\\exp\\left(x\\right) = \\frac{1}{\\exp\\left(-x\\right)} > 0$\\\\\nsince $\\exp'\\left(x\\right)=\\exp\\left(x\\right)>0 \\forall x\\in\\R$.\n\\end{proof}\n\\end{thm}\n\nBy Corollary 6, $\\exp:\\R\\to\\R^+$ is strictly increasing.\\\\\nGiven $y\\in\\R^+$, choose $n\\in\\N$ s.t. $n>y>\\frac{1}{n}$. So $\\exp\\left(n\\right)\\geq 1+n > y$, and $\\exp\\left(-n\\right)=\\frac{1}{\\exp\\left(n\\right)}\\leq \\frac{1}{1+n}<\\frac{1}{n}<y$.\\\\\nBy IVT, $\\exists x\\in\\left(-n,n\\right)$, $\\exp\\left(x\\right) = y$.\\\\\nFinally, $\\exp\\left(x\\right)\\geq 1+x\\to\\infty$ as $x\\to\\infty$ for $x\\geq 0$.\\\\\nFor $x\\leq 0$, $\\exp\\left(x\\right) = \\frac{1}{\\exp\\left(-x\\right)}\\to 0$ as $x\\to -\\infty$.\\\\\n\nWe define the \\emph{logarithm} to be the function $\\log:\\R^+\\to\\R$ that is the inverse of $\\exp:\\R\\to\\R^+$.\n\n\\begin{thm}\n$\\log:\\R^+\\to\\R$ is a strictly increasing, differentiable bijection. For $y>0$, $\\log'\\left(y\\right)=\\frac{1}{y}$, $\\log1=0$,$\\log\\left(xy\\right)=\\log x+\\log y \\forall x,y>0$, $\\log x\\to\\infty$ as $x\\to\\infty$, $\\log x\\to\\infty$ as $x\\to 0$.\\\\\n\\begin{proof}\nIf $0<x<y$ and $\\log x\\geq \\log y$ then\\\\\n$x=\\exp\\left(\\log x\\right)\\geq \\exp\\left(\\log y\\right) = y$, contradiction.\\\\\nSince $\\exp'\\left(x\\right)=\\exp\\left(x\\right)\\neq 0 \\forall x\\in\\R$, by IFT, $\\log$ is differentiable, and\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\log'\\left(y\\right)=\\frac{1}{\\exp\\left(\\log y\\right)}=\\frac{1}{y}.\n\\end{aligned}\n\\end{equation*}\n$\\log 1=0$ since $1=\\exp\\left(0\\right)$.\\\\\n$\\exp\\left(\\log x+\\log y\\right) = \\exp\\left(\\log x\\right)\\exp\\left(\\log y\\right)=xy$;\\\\\nApply log:\\\\\n$\\log x+\\log y = \\log \\left(xy\\right)$.\\\\\nSince $\\log$, $\\exp$, are strictly increasing, $\\log x>c \\iff x>\\exp c$, $\\log x<c \\iff x<\\exp c$.\\\\\nSo it follows immediately that\\\\\n$\\log x\\to\\infty$ as $x\\to\\infty$,\\\\\n$\\log x\\to -\\infty$ as $x\\to 0^+$.\n\\end{proof}\n\\end{thm}\n\n\\begin{defi}\nDefine for $x>0$, $\\alpha\\in\\R$\n\\begin{equation*}\n\\begin{aligned}\nx^\\alpha = \\exp\\left(\\alpha \\log x\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{thm}\n$\\bullet$ 1) for $\\alpha \\in \\Q$, $x^\\alpha$ agrees with the previous definition.\\\\\n$\\bullet$ 2) for $\\alpha > 0$, $x\\to x^\\alpha$ is a strictly increasing differentiable bijection: $\\R^+\\to\\R^+$;\\\\\nfor $\\alpha < 0$, $x\\to x^\\alpha$ is a strictly decreasing differentiable bijection: $\\R^+\\to\\R^+$;\n$\\forall \\alpha$, $f\\left(x\\right)=x^\\alpha$, $f'\\left(x\\right)=\\alpha x^{\\alpha-1}$;\\\\\n\n$\\forall x,y>0, \\forall \\alpha,\\beta\\in\\R$:\\\\\n$\\bullet$ 3) $\\left(xy\\right)^\\alpha = x^\\alpha y^\\alpha$,\\\\\n$x^{\\alpha+\\beta} = x^\\alpha x^\\beta$,\n$\\left(x^\\alpha\\right)^\\beta = x^{\\alpha\\beta}$;\\\\\n$\\bullet$ 4) $\\frac{x^\\alpha}{\\exp\\left(x\\right)} \\to 0$ as $x\\to \\infty \\forall x\\in\\R$,\\\\\n$\\frac{\\log x}{x^\\alpha} \\to 0$ as $x\\to\\infty \\forall x>0$.\n\\begin{proof}\n1)\n\\begin{equation*}\n\\begin{aligned}\nx^n&=\\exp\\left(n\\log x\\right)\\\\\n&= \\exp\\left(\\log x+\\log x+...+\\log x\\right) \\text{ n times}\\\\\n&= \\exp\\left(\\log x\\right)\\exp\\left(\\log x\\right)...\\exp\\left(\\log x\\right) \\text{ n times}\\\\\n&= x\\cdot x\\cdot...\\cdot x \\text{ n times}\n\\end{aligned}\n\\end{equation*}\nwhich is the old definition of $x^n$.\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\left(x^\\frac{1}{n}\\right)^n &= \\left(\\exp\\left(\\frac{1}{n}\\log x\\right)\\right)^n\\\\\n&= \\exp\\left(\\frac{1}{n}\\log x\\right)\\cdot\\exp\\left(\\frac{1}{n}\\log x\\right)\\cdot...\\cdot\\exp\\left(\\frac{1}{n}\\log x\\right) \\text{ n times}\\\\\n&= \\exp\\left(\\log x\\right)\\\\\n&= x.\n\\end{aligned}\n\\end{equation*}\nSo the new $x^\\frac{1}{n}$ is the unique $y>0$ such that $y^n=x$, also same as the old definition.\\\\\nSo now for $\\alpha\\in\\Q^+$, it follows that the two definitions coincide.\\\\\nFor $\\alpha\\in\\Q^-$,\n\\begin{equation*}\n\\begin{aligned}\nx^\\alpha &= \\exp\\left(\\alpha \\log x\\right)\\\\\n&= \\exp\\left(-\\left(-\\alpha\\right)\\log x\\right)\\\\\n&= \\frac{1}{\\exp\\left(-\\alpha \\log x\\right)}\\\\\n&= \\frac{1}{x^{-\\alpha}}\n\\end{aligned}\n\\end{equation*}\nalso the old definition.\\\\\n\n2) Immediate from properties of $\\log$ and $\\exp$.\\\\\ne.g. for $f\\left(x\\right)=x^\\alpha = \\exp\\left(\\alpha \\log x\\right)$, by chain rule, \\\\\n\\begin{equation*}\n\\begin{aligned}\nf'\\left(x\\right)&=\\exp\\left(\\alpha \\log x\\right)\\alpha \\frac{1}{x}\\\\\n&=\\alpha \\frac{\\exp\\left(\\alpha \\log x\\right)}{\\exp\\left(\\log x\\right)}\\\\\n&= \\alpha \\exp\\left(\\alpha \\log x-\\log x\\right)\\\\\n&=\\alpha \\exp\\left(\\left(\\alpha-1\\right)\\log x\\right)\\\\\n=\\alpha x^{\\alpha-1}.\n\\end{aligned}\n\\end{equation*}\n\n3) also immediate from properties of $\\log$ and $\\exp$. (exercise)\\\\\n\n4) For $x>0$, $\\exp\\left(x\\right)>\\frac{x^n}{n!}$ for any $n\\in\\N$.\\\\\nGiven $\\alpha\\in\\R$, choose $n\\in\\N, n>\\alpha$, then\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\frac{x^\\alpha}{\\exp\\left(x\\right)}&<\\frac{x^\\alpha}{x^{-n} n!}\\\\\n&=\\left(n!\\right) x^{\\alpha - n}\\\\\n&=\\left(n!\\right)\\exp\\left(\\left(\\alpha - n\\right)\\log x\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\nas $x\\to\\infty$.\n\nNow let $y=\\log\\left(x\\alpha\\right) = \\alpha \\log x \\to \\infty$ as $x \\to \\infty$, so $\\frac{\\log x}{x^\\alpha}=\\frac{1}{\\alpha}\\frac{y}{\\exp\\left(y\\right)}\\to 0$ as $x\\to\\infty$.\n\\end{proof}\n\\end{thm}\n\nWe can define $x^\\alpha = \\exp\\left(\\alpha\\log x\\right)$ for $x\\in\\R, x>0$ and $\\alpha\\in\\C$.\\\\\nExercise: define $e=\\lim_{n\\to\\infty} \\left(1+\\frac{1}{n}\\right)^n$.\\\\\nShow that $e=\\exp\\left(1\\right)$, $e^z=\\exp\\left(z\\right)$.\\\\\nNeed $e^z=e^w \\iff z-w\\in 2\\pi\\Z$ (what is $\\pi$?)\n\n\\subsection{Trigonometric and Hyperbolic functions}\n\\begin{defi}\nDefine functions $\\sin,\\cos,\\sinh,\\cosh:\\C\\to\\C$:\n\\begin{equation*}\n\\begin{aligned}\n\\sin z &= \\frac{e^iz-e^-iz}{2i} = \\sum_{n=0}^\\infty \\frac{\\left(-1\\right)^n z^{2n+1}}{\\left(2n+1\\right)!} = z-\\frac{z^3}{6}+\\frac{z^5}{120}-...\\\\\n\\cos z &= \\frac{e^iz+e^-iz}{2} = \\sum_{n=0}^\\infty \\frac{\\left(-1\\right)^n z^{2n}}{\\left(2n\\right)!} = 1-\\frac{z^2}{2}+\\frac{z^4}{24}-...\\\\\n\\sinh z &= \\frac{e^z-e^-z}{2} = \\sum_{n=0}^\\infty \\frac{z^{2n+1}}{\\left(2n+1\\right)!}\\\\\n\\cosh z &= \\frac{e^z+e^-z}{2} = \\sum_{n=0}^\\infty \\frac{z^{2n}}{\\left(2n\\right)!}\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{prop} (Properties of trigonometric functions)\\\\\n1) If $f$ is any of these trigonometric functions, then $\\overline{f\\left(z\\right)}>f\\left(\\overline{z}\\right)$.\\\\\nAlso $f\\left(-z\\right)=-f\\left(z\\right)$ for $f=\\sin, \\sinh$ (odd),\\\\\n$f\\left(-z\\right)=f\\left(z\\right)$ for $f=\\cos,\\cosh$ (even),\\\\\n$\\sin\\left(0\\right) =\\sinh\\left(0\\right) = 0$, $\\cos\\left(0\\right) = \\cosh \\left(0\\right) = 1$.\\\\\n\n2)\n\\begin{equation*}\n\\begin{aligned}\n\\sin\\left(z+w\\right)&=\\sin z\\cos w + \\cos z \\sin w, \\sin\\left(2z\\right)=2\\sin z\\cos z\\\\\n\\cos\\left(z+w\\right)&=\\cos z\\cos w - \\sin z \\sin w, \\cos\\left(2z\\right)=\\cos^2 z-\\sin^2 z\\\\\n\\sinh \\left(z+w\\right)&=\\sinh z\\cosh w + \\cosh z\\sinh w, \\sinh \\left(2z\\right)=2\\sinh z\\cosh z\\\\\n\\cosh\\left(z+w\\right)&=\\cosh z\\cosh w + \\sinh z\\sinh w, \\cosh\\left(2z\\right)=\\cosh^2 z+\\sinh^2 z.\n\\end{aligned}\n\\end{equation*}\n3)\n\\begin{equation*}\n\\begin{aligned}\n1&=\\cos\\left(0\\right)=\\cos^2 z+\\sin^2 z\\\\\n1&=\\cosh\\left(0\\right) = \\cosh^2 z - \\sinh^2 z\n\\end{aligned}\n\\end{equation*}\n4)\n\\begin{equation*}\n\\begin{aligned}\ne^{iz} &= \\cos z + i\\sin z\\\\\ne^z &= \\cosh z + \\sinh z\n\\end{aligned}\n\\end{equation*}\n5) All the four functions are complex differentiable, with\n\\begin{equation*}\n\\begin{aligned}\n\\sin'z = \\cos z, \\cos'z = -\\sin z, \\sinh'z = \\cosh z, \\cosh' z= \\sinh z.\n\\end{aligned}\n\\end{equation*}\n\\begin{proof} Immediate from the previous theorem.\n\\end{proof}\n\\end{prop}\n\nThis implies that $\\sin x, \\cos x \\in \\R$ for $x\\in\\R$.\\\\\nSince $\\cos^2 x + \\sin^2 x = 1$, we have $\\cos x, \\sin x \\in [-1,1]$.\\\\\nHave functions $\\sin,\\cos: \\R \\to [-1,1]$\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\cos x &= \\sum_{n=0}^\\infty \\left(-1\\right)^n \\frac{x^{2n}}{\\left(2n\\right)!} = 1-\\frac{x^2}{2} + \\frac{x^4}{24}+\\left(-\\frac{x^6}{6!}+\\frac{x^8}{8!}\\right) + \\left(-\\frac{-x^10}{10!} + \\frac{x^12}{12!}\\right)+...\n\\end{aligned}\n\\end{equation*}\nAt $x=2$, each term in the brackets is negative.\\\\\nSo \n\\begin{equation*}\n\\begin{aligned}\n\\cos\\left(z\\right) < 1-\\frac{2^2}{2}+\\frac{2^4}{4!} = 1-2+\\frac{16}{84}<0\n\\end{aligned}\n\\end{equation*}\nSince $\\cos \\left(0\\right)=1>0$ and $\\cos$ is continuous, by IVT\n\\begin{equation*}\n\\begin{aligned}\n\\exists z\\in\\left(0,2\\right) s.t. \\cos\\left(z\\right)=0.\n\\end{aligned}\n\\end{equation*}\nSo $A=\\left\\{z\\geq 0|\\cos\\left(z\\right)=0\\right\\} \\neq \\phi$ is bounded below by 0, so $\\inf A$ exists.\\\\\n\n\\begin{defi}\n$\\pi = 2\\times \\inf A$, i.e. $\\frac{\\pi}{2} = \\inf A$.\n\\end{defi}\nClaim:\n\\begin{equation*}\n\\begin{aligned}\n\\cos\\frac{\\pi}{2} = 0\n\\end{aligned}\n\\end{equation*}\nand so $\\frac{\\pi}{2}\\geq 0$, and it is the least positive zero of $\\cos$.\\\\\n\\begin{proof}\n$\\forall n\\in\\N$, $\\frac{\\pi}{2}+\\frac{1}{n} > \\inf A$, so $\\exists x_n \\in A$ s.t. $\\frac{\\pi}{2} + \\frac{1}{n} > x_n \\geq \\frac{\\pi}{2}$.\\\\\nSo $x_n \\to \\frac{\\pi}{2}$ and have $\\cos \\left(x_n\\right) \\to \\cos\\frac{\\pi}{2}$.($\\cos$ is continuous). So $\\cos\\frac{\\pi}{2} = 0$.\\\\\n$\\cos\\left(x\\right)>0$ for $x\\in\\left(0,\\frac{\\pi}{2}\\right)$. So $\\sin'\\left(x\\right)=\\cos x<0$ and hence $\\sin$ is strictly increasing on $[0,\\frac{\\pi}{2}]$.\n\\end{proof}\nSo $\\sin^2\\frac{\\pi}{2} = 1-\\cos^2\\frac{\\pi}{2}=1$, so $\\sin\\frac{\\pi}{2} = 1$.\\\\\nAnd $\\sin x>0$ on $\\left(0,\\frac{\\pi}{2}\\right)$ and hence $\\cos$ is strictly decreasing on $[0,\\frac{\\pi}{2}]$.\\\\\n$\\sin\\pi = 2\\sin\\frac{\\pi}{2}\\cos\\frac{\\pi}{2}=0$, $\\cos\\pi=\\cos^2\\frac{\\pi}{2}-\\sin^2\\frac{\\pi}{2}=-1$.\\\\\n$\\sin\\left(\\pi-x\\right)=\\sin\\pi\\cos\\left(-x\\right)+\\cos\\pi\\sin\\left(-x\\right)=\\sin x$.\\\\\n$x\\to\\frac{\\pi}{2}+x$, $\\sin\\left(\\frac{\\pi}{2}-x\\right) =\\sin\\left(\\frac{\\pi}{2}+x\\right)$;\\\\\n$x\\to -x$, $\\sin\\left(\\pi+x\\right)=\\sin\\left(-x\\right)=-\\sin\\left(x\\right)=-\\sin\\left(\\pi+x\\right)$;\\\\\n$\\sin\\left(2\\pi+x\\right)=-\\sin\\left(-x\\right)=\\sin x$.\\\\\nSo $\\sin\\left(2\\pi n+x\\right)=\\sin x \\forall x\\in \\R \\forall n\\in\\Z$.\\\\\n$\\sin\\left(x+\\frac{\\pi}{2}\\right)=\\sin x\\cos\\frac{\\pi}{2} + \\cos x \\sin \\frac{\\pi}{2} = \\cos x \\implies$ usual properties of $\\cos$ (symmetry, periodicity).\n\n\\begin{prop}\nFor $z\\in\\C,e^z=1 \\iff z\\in2\\pi i \\Z$.\\\\\nSo $e^z = e^w \\iff z-w\\in2\\pi i\\Z$.\n\\begin{proof}\nIf $z=2\\pi in,n\\in \\Z$ then\n\\begin{equation*}\n\\begin{aligned}\ne^z &= e^{\\left(2\\pi n\\right)}i\\\\\n&= \\cos\\left(2\\pi n\\right)+2\\sin\\left(2\\pi n\\right)\\\\\n&= \\cos\\left(0\\right)+i\\sin\\left(0\\right)\\\\\n&=1.\n\\end{aligned}\n\\end{equation*}\nConversely, assume $e^z=1$ and write $z=x+iy$, $x,y\\in\\R$,\n\\begin{equation*}\n\\begin{aligned}\n1=e^z=e^x e^{iy}\n\\end{aligned}\n\\end{equation*}\ntaking modulus,\n\\begin{equation*}\n\\begin{aligned}\n1=e^x\n\\end{aligned}\n\\end{equation*}\nSo$x=0$.\\\\\nSo $1=e^{iy}=\\cos\\left(y\\right)+i\\sin\\left(y\\right)$ and hence $\\cos\\left(y\\right) = 1$.\\\\\nSince $\\cos$ is strictly decreasing on $[0,\\pi]$, we have\n\\begin{equation*}\n\\begin{aligned}\n\\cos t = 1, t\\in[0,\\pi] \\iff t=0\n\\end{aligned}\n\\end{equation*}\nSince $\\cos$ is symmetric in $x=\\pi$, for $t\\in[0,2\\pi)$,\n\\begin{equation*}\n\\begin{aligned}\n\\cos t=1 \\iff t=0\n\\end{aligned}\n\\end{equation*}\nNow choose $n\\in\\Z$ s.t. $y-2\\pi n\\in[0,2\\pi)$.\\\\\nThen $\\cos\\left(y-2\\pi n\\right)=\\cos\\left(y\\right)=1$ and so $y-2\\pi n = 0$. Hence $z\\in 2\\pi i\\Z$.\n\\end{proof}\n\\end{prop}\n\nFor $x\\in\\R$,\n\\begin{equation*}\n\\begin{aligned}\n\\sinh x&=\\frac{e^x-e^{-x}}{2} \\in \\R, \\sinh:\\R\\to\\R\\\\\n\\cosh x&=\\frac{e^x+e^{-x}}{2} \\in \\R, \\cosh:\\R\\to\\R\n\\end{aligned}\n\\end{equation*}\n$\\cosh x>0$, $\\sinh'\\left(x\\right)=\\cosh\\left(x\\right)$. So $\\sinh$ is strictly increasing.\\\\\n$\\cosh'\\left(x\\right)=\\sinh\\left(x\\right) > 0$ for $x>0$.\\\\\nSo $\\cosh$ is strictly increasing on $[0,\\infty)$.\\\\\n$\\cosh x > \\sinh x$, and\\\\\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\cosh x}{\\sinh x} = \\frac{1+e^{-2x}}{1-e^{-2x}} \\to 1\n\\end{aligned}\n\\end{equation*}\nas $x\\to\\infty$.\\\\\nDefine $\\tan z = \\frac{\\sin z}{\\cos z}$, $\\tanh z = \\frac{\\sinh z}{\\cosh z}$.\n\n\\subsection{Derivative of higher orders}\n\\begin{defi}\nLet $A\\subset \\R, f:A\\to\\R$ be a function.\\\\\nFor $a\\in A$, say $f$ is twice differentiable at $a$ if $f$ is defined and differentiable on some open interval $I$ containing $a$ ($I\\subset A$), and $f':I\\to \\R$, $x\\to f'\\left(x\\right)$ is differentiable at $a$.\nThe second derivative of $f$ at $a$ is $\\left(f'\\right)'\\left(a\\right)$.\\\\\nWe denote this by $f''\\left(a\\right)$ or $f^{\\left(2\\right)} \\left(a\\right)$ (also sometimes write $f^{\\left(1\\right)}$ for $f'$,$f^{\\left(0\\right)}$ for $f$).\\\\\n$f$ is twice differentiable on $A$ if $f$ is twice differentiable at every $a\\in A$, then the second derivative of $f$ is the function $f'':A\\to \\R, x\\to f''\\left(x\\right)$.\\\\\nIn this case $\\forall a\\in A \\exists r>0, \\left(a-r,a+r\\right)\\subset A$.\\\\\nTypically $A=\\R$ or some open interval or $\\R \\backslash \\left\\{0\\right\\}$.\\\\\n\nIn general for $n\\geq 2$, $f$ is $n$ times differentiable at $a$ if $f$ is $n-1$ times differentiable on some open interval $I$ containing $a$, and $f^{\\left(n-1\\right)}:I\\to \\R, x \\to f^{\\left(n-1\\right)} \\left(x\\right)$ is differentiable at $a$. We write $f^{\\left(n\\right)}\\left(a\\right)$ for $\\left(f^{\\left(n-1\\right)}\\right)'\\left(a\\right)$ called the $n^{th}$ derivative of $f$ at $a$.\\\\\n$f$ is $n$ times differentiable on $A$ if $f$ is $n$ times differentiable at every $a\\in A$. Then the $n^{th}$ derivative of $f$ on $A$ is the function: $f^{\\left(n\\right)}:A \\to \\R, x \\to f^{\\left(n\\right)}\\left(x\\right)$.\\\\\n$f$ is infinitely differentiable on $A$ (or $C^\\infty$) if $f$ is $n$ times differentiable on $A$ $\\forall n\\in \\N$.\\\\\n$f$ is $n$ times continuously differentiable on $A$ (or $C^n$) if $f$ is $n$ times differentiable on $A$, and $f^{\\left(n\\right)}: A\\to\\R$ is continuous.\n\\end{defi}\n\n\\begin{eg}\nLet\n\\begin{equation*}\n\\begin{aligned}\np\\left(x\\right) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n \n\\end{aligned}\n\\end{equation*}\nbe a polynomial. Then\n\\begin{equation*}\n\\begin{aligned}\np'\\left(x\\right)=a_1 + 2a_2 x + 3a_3 x^2 + ... + n a_n x^{n-1}\n\\end{aligned}\n\\end{equation*}\nis also a polynomial. So by induction, $p$ is $C^\\infty$.\n\\end{eg}\n\n\\begin{thm}\nLet $n\\in \\N$, $a\\in \\R$, let $f$ be $n$ times differentiable at $a$. Then $\\exists \\delta > 0$ and a function $R_n:\\left(-\\delta,\\delta\\right)\\to\\R$ s.t.\n\\begin{equation}\\label{eq:1}\n\\begin{aligned}\nf\\left(a+h\\right)&=f\\left(a\\right)+f'\\left(a\\right)h + \\frac{f''\\left(a\\right)}{2}h^2 + ... + \\frac{f^{\\left(n\\right)}\\left(a\\right)}{n!} + R_n\\left(h\\right)\n\\end{aligned}\n\\end{equation}\nfor all $h\\in\\left(-\\delta,\\delta\\right)$, and $R_n\\left(h\\right) = o\\left(h^n\\right)$, i.e.\n\\begin{equation*}\n\\begin{aligned}\n\\frac{R_n\\left(h\\right)}{h^n} \\to 0\n\\end{aligned}\n\\end{equation*}\nas $h\\to 0$.\n\\begin{proof}\nBy definition, $\\exists \\delta > 0$ s.t. $f$ is defined and is $n-1$ times differentiable on $\\left(a-\\delta,a+\\delta\\right)$, and\n\\begin{equation*}\n\\begin{aligned}\nf^{\\left(n\\right)}\\left(a\\right) &= \\lim_{h\\to 0} \\frac{f^{\\left(n-1\\right)} \\left(a+h\\right)-f^{\\left(n-1\\right)} \\left(a\\right)}{h}.\n\\end{aligned}\n\\end{equation*}\nWe define\n\\begin{equation*}\n\\begin{aligned}\nR_n\\left(n\\right) &= f\\left(a+h\\right)-\\sum_{k=0}^n \\frac{f^{\\left(k\\right)} \\left(a\\right)}{k!}h^k, |h| < \\delta\n\\end{aligned}\n\\end{equation*}\nSo (\\ref{eq:1}) holds.\\\\\n$\\bullet n=1:$\n\\begin{equation*}\n\\begin{aligned}\n\\frac{R_1\\left(h\\right)}{h} = \\frac{f\\left(a+h\\right)-f\\left(a\\right)}{h}-f'\\left(a\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\n$\\bullet n\\geq 2:$ $R_n\\left(h\\right)$ is ($n-1$) times differentiable, and\n\\begin{equation*}\n\\begin{aligned}\nR_n^{\\left(k\\right)}\\left(h\\right) &= f^{\\left(k\\right)}\\left(a+h\\right)\\\\\n&=\\sum_{l=k}^n \\frac{f^{\\left(l\\right)}\\left(a\\right)}{l!} l\\left(l-1\\right)...\\left(l-k+1\\right)h^{l-k},\\\\\nR_n^{\\left(k\\right)}\\left(0\\right) &= 0 \\text{  }\\forall k=0,1,...,n-1.\n\\end{aligned}\n\\end{equation*}\nNow let\n\\begin{equation*}\n\\begin{aligned}\ng\\left(h\\right)&=h^n,\\\\\ng^{\\left(k\\right)}\\left(h\\right)&=n\\left(n-1\\right)...\\left(n-k+1\\right)h^{n-k},\\\\\ng^{\\left(k\\right)}\\left(0\\right)&=0,\\\\\ng^{\\left(k\\right)}\\left(h\\right)&\\neq 0 \\text{  }\\forall 0<|h|<\\delta.\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\frac{R_n^{\\left(n-1\\right)}\\left(h\\right)}{g^{\\left(n-1\\right)}\\left(h\\right)} &= \\frac{f^{\\left(n-1\\right)}\\left(a+h\\right)-f^{\\left(n-1\\right)}\\left(a\\right)-hf^{\\left(n\\right)}\\left(a\\right)}{\\left(n!\\right)h}\\\\\n&= \\left(\\frac{1}{n!}\\right) \\left[\\frac{f^{\\left(n-1\\right)}\\left(a+h\\right)-f^{\\left(n-1\\right)}\\left(a\\right)}{h}-f^{\\left(n\\right)}\\left(a\\right)\\right] \\to 0\n\\end{aligned}\n\\end{equation*}\nas $h\\to 0$.\\\\\nSo apply L' H$\\hat{o}$pital's rule $\\left(n-1\\right)$ times, we obtain\n\\begin{equation*}\n\\begin{aligned}\n\\frac{R_n\\left(h\\right)}{h^n}\\to 0\n\\end{aligned}\n\\end{equation*}\nas $h\\to 0$.\n\\end{proof}\n\\end{thm}\n\nSuppose $f$ is a $C^\\infty$ function. Then the previous theorem applies for all $n$. So does\n\\begin{equation*}\n\\begin{aligned}\nf\\left(a+h\\right) &= \\sum_{k=0}^n \\frac{f^{\\left(k\\right)}\\left(a\\right)}{k!}h^k + R_n\\left(h\\right)\\\\\n\\implies(?) f\\left(a+h\\right)&= \\sum_{k=0}^\\infty \\frac{f^{\\left(k\\right)}\\left(a\\right)}{k!}h^k\n\\end{aligned}\n\\end{equation*}\n(called the \\emph{Taylor series}) on $\\left(-\\delta,\\delta\\right)$ on some $\\delta >0$?\n\n\\begin{eg}\n$f=\\exp:\\R \\to \\R$.\\\\\n$f'=f$, so $f$ is $C^\\infty$ and $f^{\\left(n\\right)} = f$ $\\forall n$.\\\\\nTaylor series at 0:\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{k=0}^\\infty \\frac{1}{k!}h^k = \\exp\\left(h\\right)\n\\end{aligned}\n\\end{equation*}\nfor all $h\\in\\R$...\n\\end{eg}\n\nIn general the answer is NO!\n\\begin{prob}\n$R_n$ depends on $n$. What if $R_n\\left(h\\right)=n^{n+1}h^{n+1}$?\\\\\nFor all $n$, $\\frac{R_n\\left(h\\right)}{h^n}\\to 0$ as $h\\to 0$.\\\\\nFor fixed $h\\neq 0$, $R_n\\left(h\\right) \\not\\to 0$ as $n\\to \\infty$.\n\\end{prob}\n\n\\begin{thm}(Taylor's theorem with the Lagrange remainder)\\\\\nLet $a\\in\\R$, $\\delta>0$, $n\\in\\N$. Assume $f:\\left(a-\\delta,a+\\delta\\right)\\to\\R$ is $n$ times differentiable. Then $\\forall h\\in\\left(-\\delta,\\delta\\right)$, $\\exists \\theta\\in\\left(0,1\\right)$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(a+h\\right) = f\\left(a\\right)+\\sum_{k=1}^{n-1} \\frac{f^{\\left(k\\right)}\\left(a\\right)}{k!}\nh^k + \\frac{f^{\\left(n\\right)}\\left(a+\\theta h\\right)}{n!}h^n.\n\\end{aligned}\n\\end{equation*}\n\\begin{rem}\n$\\bullet$ when $n=1$:\n\\begin{equation*}\n\\begin{aligned}\n&f\\left(a+h\\right) = f\\left(a\\right) + f'\\left(a+\\theta h\\right)h,\\\\\n&\\frac{f\\left(a+h\\right)-f\\left(a\\right)}{h} = f'\\left(a+\\theta h\\right)\n\\end{aligned}\n\\end{equation*}\nwhile $a+\\theta h$ is between $a$ and $a+h$. So this is MVT!\\\\\n$\\bullet$ (\\ref{eq:1}) says\n\\begin{equation*}\n\\begin{aligned}\n&f\\left(a+h\\right)=f\\left(a\\right)+\\sum_{k=1}^n \\frac{f^{\\left(k\\right)}\\left(a\\right)}{k!}h^k +R_n\\left(h\\right),\\\\\n&R_n\\left(h\\right)=\\frac{h^n}{n!}\\left(f^{\\left(n\\right)}\\left(a+\\theta h\\right) - f^{\\left(n\\right)} \\left(a\\right)\\right)\n\\end{aligned}\n\\end{equation*}\nThis is not obviously $o\\left(h^n\\right)$.\n\\end{rem}\n\\begin{proof}\nFor $n=1$ the theorem is just MVT.\\\\\nFor $n \\geq 2$, fix $h\\in\\left(-\\delta,\\delta\\right)$, WLOG $h\\neq 0$. Choose $A\\in \\R$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(a+h\\right) &= f\\left(a\\right)+\\sum_{k=1}^{n-1} \\frac{f^{\\left(k\\right)}\\left(a\\right)}{k!}h^k + \\frac{A h^n}{n!}\n\\end{aligned}\n\\end{equation*}\nwant to prove:\n\\begin{equation*}\n\\begin{aligned}\nA=f^{\\left(n\\right)} \\left(a+\\theta h\\right)\n\\end{aligned}\n\\end{equation*}\nfor some $\\theta \\in \\left(0,1\\right)$.\\\\\nDefine\n\\begin{equation*}\n\\begin{aligned}\ng\\left(t\\right)&=f\\left(t\\right)+\\sum_{k=1}^{n-1}\\frac{f^{\\left(k\\right)}\\left(t\\right)}{k!}\\left(a+h-t\\right)^k + \\frac{A}{n!}\\left(a+h-t\\right)^n\n\\end{aligned}\n\\end{equation*}\nFor $t$ in the closed interval between $a$ and $a+b$.\\\\\n$g$ is continuous differentiable on the open interval between $a$ and $a+h$.\\\\\nTaylor expansion of $f$ about $t$:\n\\begin{equation*}\n\\begin{aligned}\nf\\left(t+u\\right)=f\\left(t\\right) = \\sum_{k=1}^{n-1} \\frac{f^{\\left(k\\right)} \\left(t\\right)}{k!} u^k + \\text{  error}\n\\end{aligned}\n\\end{equation*}\nwhen $u=a+h-t$,\n\\begin{equation*}\n\\begin{aligned}\nf\\left(a+h\\right)=f\\left(t\\right) + \\sum_{k=1}^{n-1} \\frac{f^{\\left(k\\right)} \\left(t\\right)}{k!}\\left(a+h-t\\right)^k + \\text{  error}\n\\end{aligned}\n\\end{equation*}\nNow\n\\begin{equation*}\n\\begin{aligned}\ng\\left(a\\right)=f\\left(a+h\\right),\\\\\ng\\left(a+h\\right)=f\\left(a+h\\right)\n\\end{aligned}\n\\end{equation*}\nBy Rolle's theorem, $\\exists \\theta \\in \\left(0,1\\right)$ s.t. $g'\\left(a+\\theta h\\right)=0$.\n\\begin{equation*}\n\\begin{aligned}\ng'\\left(t\\right) &= f'\\left(t\\right) + \\sum_{k=1}^{n-1} \\left[-\\frac{f^{\\left(k\\right)} \\left(t\\right)}{\\left(k-1\\right)!}\\left(a+h-t\\right)^{k-1} + \\frac{f^{\\left(k+1\\right)}\\left(t\\right)}{k!}\\left(a+h-t\\right)^k\\right] - A\\frac{\\left(a+h-t\\right)^{n-1}}{\\left(n-1\\right)!}\\\\\n&= \\frac{f^{\\left(n\\right)} \\left(t\\right)}{\\left(n-1\\right)!}\\left(a+h-t\\right)^{n-1} - A \\frac{\\left(a+h-t\\right)^{n-1}}{\\left(n-1\\right)!}\n\\end{aligned}\n\\end{equation*}\nSo $g'\\left(a+\\theta h\\right) = 0$, which implies $A=f^{\\left(n\\right)} \\left(a+\\theta h\\right)$.\n\\end{proof}\n\\end{thm}\n\n\\begin{eg}\nFix $\\alpha \\in \\R$, $f:\\left(-1,\\infty\\right)\\to\\R$.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(x\\right) &= \\left(1+x\\right)^\\alpha = \\exp\\left(\\alpha \\log\\left(1+x\\right)\\right)\\\\\nf'\\left(x\\right) &= \\alpha \\left(1+x\\right)^{\\alpha-1}\\\\\nf''\\left(x\\right) &= \\alpha\\left(\\alpha-1\\right)\\left(1+x\\right)^{\\alpha-2}\\\\\nf^{\\left(n\\right)}\\left(x\\right) &= \\alpha\\left(\\alpha - 1\\right)...\\left(\\alpha - n + 1\\right)\\left(1+x\\right)^{\\alpha-n}\n\\end{aligned}\n\\end{equation*}\nSo $f$ is $C^\\infty$ on $\\left(-1,\\infty\\right)$ and its Taylor series at 0 is\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=0}^\\infty {\\alpha \\choose n} x^n = 1+\\alpha x + \\frac{\\alpha\\left(\\alpha-1\\right)}{2}x^2+...\n\\end{aligned}\n\\end{equation*}\nThis converges to $f\\left(x\\right)$ $\\forall x\\in\\left(-1,1\\right)$ (binomial theorem).\n\\end{eg}\n\\begin{rem}\n$\\bullet$ $\\alpha \\in \\Z, \\alpha \\geq 0$, then $\\alpha^{\\underline{n}} = 0 \\forall n > \\alpha$.(c.f. number and sets, falling power)\\\\\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=0}^\\infty {\\alpha \\choose n} x^n = \\sum_{n=0}^\\alpha {\\alpha \\choose n} x^n = \\left(1+x\\right)^n\n\\end{aligned}\n\\end{equation*}\n$\\bullet$ $\\alpha = -1$:\n\\begin{equation*}\n\\begin{aligned}\n\\left(1+x\\right)^{-1} = \\frac{1}{1-\\left(-x\\right)} = \\sum_{n=0}^\\infty \\left(-x\\right)^n\\\\\n\\alpha^{\\underline{n}} = \\left(-1\\right)\\left(-2\\right)...\\left(-n\\right) = \\left(-1\\right)^n n!\n\\end{aligned}\n\\end{equation*}\nProof for general $\\alpha$ deferred until Chapter 6(integration).\\\\\nWe an give a proof for $|x| < \\frac{1}{2}$.\nFrom the previous theorem:\n\\begin{equation*}\n\\begin{aligned}\nf\\left(x\\right) = \\sum_{k=0}^n {\\alpha \\choose k} x^k + {\\alpha \\choose n+1} \\left(1+\\theta_n x\\right)^{n+1} x^{n+1}\n\\end{aligned}\n\\end{equation*}\nfor some $\\theta_n\\in\\left(0,1\\right)$.\n\\begin{equation*}\n\\begin{aligned}\n|\\frac{x^{n+1}}{\\left(n+1\\right)!}\\alpha^{\\underline{n+1}}\\left(1+\\theta_n x\\right)^{\\alpha-n-1}| \\leq C\\cdot n^m \\left(2|x|\\right)^n\n\\end{aligned}\n\\end{equation*}\n(for $m<\\in \\N, m>|\\alpha|$)\n\\begin{equation*}\n\\begin{aligned}\n|\\frac{x}{1+\\theta_n x} \\leq \\frac{|x|}{1-|\\theta_n x|}\\leq 2|x|\n\\end{aligned}\n\\end{equation*}\n\\end{rem}\n\n\\newpage\n\n\\section{Power series}\n\\begin{defi}\nA series of the form\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n\n\\end{aligned}\n\\end{equation*}\nis a power series about $a$. Here $\\left(a_n\\right)_{n=0}^\\infty$ is a complex sequence, $a,z\\in\\C$. Think of $a,\\left(a_n\\right)$ as fixed and $z$ as a variable.\\\\\nConsider\n\\begin{equation*}\n\\begin{aligned}\nD=\\left\\{z\\in\\C | \\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n \\text{  converges  } \\right\\}\n\\end{aligned}\n\\end{equation*}\nand define $f:D\\to \\C$,\n\\begin{equation*}\n\\begin{aligned}\nf\\left(z\\right)=\\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{eg}\n1) $\\sum_{n=0}^\\infty \\frac{1}{n!}z^n$. $a_n = \\frac{1}{n!}$, $a=0$.\\\\\nHere $D=\\C$ and $f=\\exp$.\\\\\n2) $\\sum_{n=1}^\\infty \\frac{-1}{n}\\left(1-z\\right)^n$. $a=1$, $a_n = \\frac{\\left(-1\\right)^{n-1}}{n}$, $a_0 = 0$ (note $\\left(1-z\\right)^n = \\left(-1\\right)^n \\left(z-1\\right)^n$).\\\\\n3) $\\sum_{n=1}^\\infty n^n z^n$. $a_n = n$, $n\\geq 1$, $a_0 = 0$, $a=0$.\\\\\nD=$\\left\\{0\\right\\}$: given $z\\neq 0$, $\\exists N$ s.t. $|Nz|>1$. Then $\\forall n\\geq N$, $|\\left(nz\\right)^n| \\geq 1$. So $\\left(nz\\right)^n \\not\\to 0$.\n\\end{eg}\n\n\\begin{notation}\n$D\\left(a,r\\right)=\\left\\{z\\in\\C||z-a|<r\\right\\}$  the open disc with centre $a$, radius $r$.\\\\\n$\\bar{D}\\left(a,r\\right)=\\left\\{z\\in\\C||z-a|<r\\right\\}$  the closed disc with centre $a$, radius $r$.\n\\end{notation}\n\nNote: $\\left\\{z|\\sum a_n\\left(z-a\\right)^n \\text{  converges  }\\right\\} = \\left\\{z|\\sum a_n z^n \\text{  converges  }\\right\\} + a$. So WLOG $a=0$.\n\n\\begin{thm}\nSuppose $\\sum_{n=0}^\\infty a_n w^n$ converges. Then $\\forall z\\in\\C$, if $|z| < |w|$, then $\\sum_{n=0}^\\infty a_n z^n$ converges absolutely.\n\\begin{proof}\nSince $\\sum a_n w^n$ converges, $a_n w^n \\to 0$ as $n\\to \\infty$.\\\\\nSo $\\exists N \\leq \\N$, $\\forall n \\geq N$, $|a_n w^n| \\leq 1$. Then $\\forall n\\geq \\N$,\n\\begin{equation*}\n\\begin{aligned}\n|a_n z^n| = |a_n w^n \\left(\\frac{z}{w}\\right)^n| \\leq |\\frac{z}{w}|^n\n\\end{aligned}\n\\end{equation*}\nThis converges as $|\\frac{z}{w}|<1$ (geometric series). So by comparison test, $\\sum a_n z^n$ converges absolutely.\n\\end{proof}\n\\end{thm}\n\n\\begin{conv}\n1) Let $\\left[0,\\infty\\right] = \\left[0,\\infty\\right) \\cup \\left\\{ \\infty\\right\\}$.\\\\\nExtend $\\leq$ to $\\left[0,\\infty\\right]$ by $x\\leq \\infty$ $\\forall x\\in\\left[0,\\infty\\right]$, so $x<\\infty$ $\\forall x\\in\\left[0,\\infty\\right]$.\\\\\n2) So $|z|<\\infty$ $\\forall z<\\C$, and $\\not\\exists z\\in\\C, |z|>\\infty$. Write $D\\left(a,\\infty\\right) = \\C$ by convention.\\\\\n3) $A\\subset\\left[0,\\infty\\right)$, $a\\neq \\phi$. If $a$ is not bounded above then $\\forall C \\geq 0$, $\\exists a\\in A$ s.t. $a>C$. We define $\\sup A = \\infty$.\n\\end{conv}\n\n\\begin{thm}\nFor power series\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=0}^\\infty a_n\\left(z-a\\right)^n\n\\end{aligned}\n\\end{equation*}\nThere exists a unique $R\\in\\left[0,\\infty\\right]$ s.t. $\\forall z\\in \\C$, \n\\begin{equation*}\n\\begin{aligned}\n&|z-a| < R \\implies \\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n \\text{    converges absolutely},\\\\\n&|z-a| > R \\implies \\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n \\text{    diverges.}\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nWLOG let $a=0$.\\\\\n$\\bullet$ uniqueness: Suppose $R<S$ both work. Then fix $z\\in\\C$ with $R<|z|<S$.\\\\\nDefinition of $R$ $\\implies$ $\\sum a_n z^n$ diverges;\\\\\nDefinition of $S$ $\\implies$ $\\sum a_n z^n$ converges absolutely. Contradiction.\\\\\n$\\bullet$ existence: Let\n\\begin{equation*}\n\\begin{aligned}\nA=\\left\\{|z| \\mid \\sum_{n=0}^\\infty a_n z^n \\text{   converges}\\right\\}\n\\end{aligned}\n\\end{equation*}\n$A\\neq \\phi$ as $0\\in A$. Let $R=\\sup A$ (recall that $\\sup A=\\infty$ when $A$ is not bounded above).\\\\\nLet $z\\in\\C$. If $|z|<R$, then $\\exists w\\in\\C$ s.t. $|z|<|w|$ and $\\sum_{n=0}^\\infty a_n w^n$ converges. Hence by the previous theorem, $\\sum_{n=0}^\\infty a_n z^n$ converges absolutely.\\\\\nIf $|z|>R$, then $|z| \\in A$, so $\\sum_{n=0}^\\infty a_n z^n$ diverges.\n\\end{proof}\n\\end{thm}\n\n\\begin{defi}\n$R$ is called the \\emph{radius of convergence} of $\\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n$.\n\\end{defi}\n\n\\begin{rem}\nThis theorem says nothing about convergence or otherwise of the power series when $|z-a|=R$.\\\\\n\\end{rem}\n\n\\begin{eg}\n$\\bullet$ 1)\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=0}^\\infty z^n\n\\end{aligned}\n\\end{equation*}\nconverges if $|z|<1$ (to $\\frac{1}{1-z}$).\\\\\nWhen $|z| \\geq 1$, then $|z^n|\\geq 1$ $\\forall n$, so $z^n \\not\\to 0$ and $\\sum z^n$ is divergent.\\\\\nIt follows that $R=1$.\\\\\n$\\bullet$ 2)\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=1}^\\infty \\frac{z^n}{n}\n\\end{aligned}\n\\end{equation*}\nconverges if $z=-1$ by the alternating series test. So $R\\geq 1$.\\\\\nOn the other hand, this diverges when $z=1$ (harmonic series). So $R\\leq 1$.\\\\\nSo $R=1$.\\\\\n(in fact the series converges $\\forall z$ s.t. $|z|=1, z\\neq 1$).\\\\\n$\\bullet$ 3)\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=1}^\\infty \\frac{z^n}{n^2}\n\\end{aligned}\n\\end{equation*}\nHere\n\\begin{equation*}\n\\begin{aligned}\n|z|\\leq 1 \\implies |\\frac{z^n}{n^2}|\\leq\\frac{1}{n^2}\n\\end{aligned}\n\\end{equation*}\nSo by the comparison test, the series converges absolutely. So $R\\geq 1$.\\\\\nWhen $|z|>1$ then $|\\frac{z^n}{n^2}|=\\frac{|z^n|}{n^2} \\to \\infty$ as $n\\to\\infty$. So the series diverges. So $R\\leq 1$.\\\\\nSo $R=1$ (the series converges absolutely for all $|z|=1$).\n\\end{eg}\n\n\\begin{thm}\nAssume\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n\n\\end{aligned}\n\\end{equation*}\nhas radius of convergence $R>0$.\\\\\nLet $f: D\\left(a,R\\right) \\to \\C$ ($D\\left(a,R\\right)$ is the disc with centre $a$ and radius $R$) be defined by\n\\begin{equation*}\nf\\left(z\\right) = \\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n\n\\begin{aligned}\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=1}^\\infty n a_n \\left(z-a\\right)^{n-1}\n\\end{aligned}\n\\end{equation*}\nalso has radius of convergence $R$.\\\\\nSetting\n\\begin{equation*}\n\\begin{aligned}\n&g:D\\left(a,R\\right) \\to \\C,\\\\\n&g\\left(z\\right) = \\sum_{n=1}^\\infty n a_n \\left(z-a\\right)^{n-1}\n\\end{aligned}\n\\end{equation*}\nwe have $f$ is complex differentiable on $D\\left(a,R\\right)$, and\n\\begin{equation*}\n\\begin{aligned}\nf'\\left(z\\right) = g\\left(z\\right) \\forall z\\in D\\left(a,R\\right).\n\\end{aligned}\n\\end{equation*}\n\\begin{rem}\nSo we can differentiate a power series term-by-term inside the radius of convergence. i.e.,\n\\begin{equation*}\n\\begin{aligned}\n\\frac{d}{dz}\\sum_{n=0}^\\infty = \\sum_{n=0}^\\infty \\frac{d}{dz}\n\\end{aligned}\n\\end{equation*}\nBut this is dangerous in general.\n\\end{rem}\n\\end{thm}\n\n\\begin{coro}\nA power series is infinitely complex differentiable inside the radius of convergence.\n\\end{coro}\n\n\\begin{eg}(non-examinable)\\\\\nThe previous theorem tells that $\\exp$ is differentiable. We'll deduce that\n\\begin{equation*}\n\\begin{aligned}\n\\exp\\left(z+w\\right) = \\exp z \\cdot \\exp w\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nLet\n\\begin{equation*}\n\\begin{aligned}\nf\\left(z\\right) = \\exp\\left(z\\right)\\cdot\\exp\\left(-z\\right).\n\\end{aligned}\n\\end{equation*}\nSo $f' \\equiv 0$(?), i.e. $f \\equiv 1$, so $\\exp\\left(-z\\right) = \\frac{1}{\\exp\\left(z\\right)}$.\\\\\nThen fix $w$, $g\\left(z\\right) = \\exp\\left(z+w\\right)\\exp\\left(-z\\right)$. So $g' \\equiv 0$, $g\\equiv \\exp w$.\\\\\nSo $\\forall z$,\n\\begin{equation*}\n\\begin{aligned}\n\\exp\\left(z+w\\right)\\exp\\left(-z\\right) = \\exp w,\\\\\n\\exp\\left(z+w\\right) = \\exp\\left(z\\right) \\exp\\left(w\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{eg}\n\n\\begin{thm}(non-examinable)\\\\\nSuppose\n\\begin{equation*}\n\\begin{aligned}\nf: D\\left(a,R\\right) \\to \\C\n\\end{aligned}\n\\end{equation*}\nis complex differentiable. Then $\\exists \\left(a_n\\right)_{n=0}^\\infty$ in $\\C$, s.t.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(z\\right) = \\sum_{n=0}^\\infty a_n \\left(z-a\\right)^n \\forall z\\in D\\left(a,R\\right)\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nWLOG let $a=0$. Fix $z\\in D\\left(0,R\\right)$. Fix $\\delta >0$ s.t. $|z|+\\delta < R$ for $0<|h| < \\delta$. Then\n\\begin{equation}\\label{eq:2}\n\\begin{aligned}\n|\\frac{f\\left(z+h\\right)-f\\left(z\\right)}{h} - g\\left(z\\right)| &= \\sum_{n=1}^\\infty |a_n| |\\left[\\frac{\\left(z+h\\right)^n-z^n}{h} - nz^{n-1}\\right]|\n\\end{aligned}\n\\end{equation}\nThen look at the second term, i.e. (let $\\delta = |h|$)\n\\begin{equation*}\n\\begin{aligned}\n|\\frac{\\left(z+h\\right)^n-z^n-hnz^{n-1}}{h}| &\\leq \\sum_{k=2}^n {n \\choose k} |z|^{n-k} \\delta^{k}\\frac{|h|}{\\delta^2}\\\\\n&\\leq \\left(|z|+\\delta\\right)^n \\frac{|h|}{\\delta^2}\n\\end{aligned}\n\\end{equation*}\nSo (\\ref{eq:2}) is at most\n\\begin{equation*}\n\\begin{aligned}\n\\left(\\sum_{n=0}^\\infty |a_n| \\left(|z|+\\delta\\right)^n\\right) \\frac{|h|}{\\delta^2}\\to 0\n\\end{aligned}\n\\end{equation*}\nas $h\\to 0$.\n\\end{proof}\n\\end{thm}\n\n\\begin{coro}(non-examinable)\\\\\nIf\n\\begin{equation*}\n\\begin{aligned}\nf: D\\left(a,R\\right) \\to \\C\n\\end{aligned}\n\\end{equation*}\nis complex differentiable, then it is infinitely complex differentiable (holomorphic).\\\\\n\\begin{equation*}\n\\begin{aligned}\nf^{\\left(k\\right)} \\left(z\\right) = \\sum_{n=k}^\\infty n\\left(n-1\\right)\\left(n-2\\right) ... \\left(n-k+1\\right) a_n \\left(z-a\\right)^{n-k}\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\nf^{\\left(k\\right)} \\left(a\\right) = n! a_n\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\nf\\left(z\\right) = \\sum_{n=0}^\\infty \\frac{f^{\\left(n\\right)} \\left(a\\right)}{n!}\\left(z-a\\right)^n\n\\end{aligned}\n\\end{equation*}\nis the taylor series!\n\\end{coro}\n\n\\begin{coro}(non-examinable)\\\\\nLet\n\\begin{equation*}\n\\begin{aligned}\nf,g: D\\left(a,R\\right) \\to \\C\n\\end{aligned}\n\\end{equation*}\nbe complex differentiable.\\\\\nSuppose $\\exists \\delta > 0\\left(\\delta < R\\right)$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nf \\equiv g \\text{  on  } D\\left(a,\\delta\\right)\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\nf \\equiv g \\text{  on  } D\\left(a,R\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{coro}\n\n\\newpage\n\\section{Integration}\nSuppose $\\left[a,b\\right]$ is a closed bounded interval with $a\\leq b$, and\n\\begin{equation*}\n\\begin{aligned}\nf: \\left[a,b\\right] \\to \\R\n\\end{aligned}\n\\end{equation*}\nis a bounded function, i.e. $\\exists C$ s.t. $|f\\left(t\\right)| \\leq C$ $\\forall t\\in \\left[a,b\\right]$.\\\\\n\nA \\emph{dissection of $\\left[a,b\\right]$} is a finite sequence\n\\begin{equation*}\n\\begin{aligned}\n\\D: a=x_0 < x_1 < x_2 < ... < x_n = b\n\\end{aligned}\n\\end{equation*}\nThe \\emph{lower sum of $f$ w.r.t. $\\D$} is\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D} \\left(f\\right) = \\sum_{k=1}^n \\left(x_k - x_{k-1}\\right) \\inf f\\left[x_{k-1},x_k\\right] \n\\end{aligned}\n\\end{equation*}\nThe \\emph{upper sum of $f$ w.r.t. $\\D$} is\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D} \\left(f\\right) = \\sum_{k=1}^n \\left(x_k - x_{k-1}\\right) \\sup f\\left[x_{k-1},x_k\\right] \n\\end{aligned}\n\\end{equation*}\n\\begin{notation}\nFor $A\\subset \\left[a,b\\right]$,\n\\begin{equation*}\n\\begin{aligned}\n\\sup_A f = \\sup \\left\\{f\\left(x\\right)|x\\in A\\right\\}\n\\end{aligned}\n\\end{equation*}\n\\end{notation}\n\nNote that $\\S_{\\D}\\left(f\\right) \\leq S_{\\D}\\left(f\\right)$.\n\\begin{defi}\n$\\D'$ is a \\emph{refinement} of $\\D$ if it contains all the points in $\\D$. Write $\\D \\leq \\D'$.\n\\end{defi}\n\n\\begin{lemma}\nLet $f:\\left[a,b\\right]\\to \\R$ be a bounded function. Let $\\D,\\D'$ be dissections of $[a,b]$ with $\\D \\leq \\D'$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\S_\\D\\left(f\\right) \\leq \\S_{\\D'}\\left(f\\right) \\leq S_{\\D'}\\left(f\\right) \\leq S_\\D\\left(f\\right).\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nSay $\\D: a=x_0 < x_1 < ... < x_n = b$.\\\\\nWe may assume that $\\D'$ has only one extra point $c$, then the rest can be done by induction.\\\\\nChoose $k$ s.t. $x_{k-1} < c < x_k$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\inf_{\\left[x_{k-1},x_k\\right]} f \\cdot \\left(x_k - x_{k-1}\\right) &= \\left(c-x_{k-1}\\right) \\cdot \\inf_{\\left[x_{k-1},x_k\\right]} f + \\left(x_k+c\\right)\\inf_{\\left[x_{k-1},x_k\\right]} f\\\\\n&\\leq \\left(c-x_{k-1}\\right) \\inf_{\\left[x_{k-1},c\\right]}  f + \\left(x_k-c\\right) \\inf_{\\left[c,x_k\\right]} f\n\\end{aligned}\n\\end{equation*}\nWe obtain\n\\begin{equation*}\n\\begin{aligned}\n\\S_\\D\\left(f\\right) \\leq \\S_{\\D'} \\left(f\\right).\n\\end{aligned}\n\\end{equation*}\nSimilarly,\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D'}\\left(f\\right) \\leq S_\\D \\left(f\\right)\n\\end{aligned}\n\\end{equation*}\nand we always have\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D'} \\left(f\\right) \\leq S_{\\D'} \\left(f\\right)\n\\end{aligned}\n\\end{equation*}\nSo done.\n\\end{proof}\n\\end{lemma}\n\n\\begin{coro}\nIf $\\D_1$, $\\D_2$ are two dissections of $\\left[a,b\\right]$, then\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D_1}\\left(f\\right) \\leq S_{\\D_2} \\left(f\\right)\n\\end{aligned}\n\\end{equation*}\nHere $f$ is as in the previous lemma.\n\\begin{proof}\nLet $D=\\D_1 \\cup \\D_2$, the common refinement of $\\D_1$ and $\\D_2$, i.e. the union of the points of $\\D_1$ and $\\D_2$.\\\\\nBy the previous lemma,\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D_1}\\left(f\\right) \\leq \\S_{\\D}\\left(f\\right) \\leq S_{\\D}\\left(f\\right) \\leq S_{\\D_2}\\left(f\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{coro}\n\n\\begin{defi}\nLet $f:\\left[a,b\\right]\\to \\R$ be a bounded function.\\\\\nThe \\emph{upper (Riemann) integral} of $f$ on $\\left[a,b\\right]$ is\n\\begin{equation*}\n\\begin{aligned}\n\\bar{\\int_a^b} f = \\inf_\\D S_\\D \\left(f\\right)\n\\end{aligned}\n\\end{equation*}\ni.e. (the inf taken over all dissections $\\D$ of $\\left[a,b\\right]$.\\\\\nThe \\emph{lower (Riemann) integral} of $f$ on $\\left[a,b\\right]$ is\n\\begin{equation*}\n\\begin{aligned}\n\\underline{\\int_a^b} f = \\sup_\\D \\S_\\D\\left(f\\right)\n\\end{aligned}\n\\end{equation*}\nBy the previous corollary, given a dissection $\\D_1$, $\\S_{\\D_1} \\left(f\\right)$ is a lower bound of $\\left\\{S_\\D \\left(f\\right)|\\D \\text{  any dissection of  }\\left[a,b\\right]\\right\\}$. So the upper integral exists and is at least $\\S_{\\D_1}\\left(f\\right)$.\\\\\nSince $\\D_1$ was arbitrary, $\\bar{\\int_a^b} f$ is an upper bound of $\\left\\{\\S_\\D \\left(f\\right)|\\D \\text{  any dissection of  }\\left[a,b\\right]\\right\\}$. Hence $\\underline{\\int_a^b} f$ exists and\n\\begin{equation*}\n\\begin{aligned}\n\\underline{\\int_a^b} f \\leq \\bar{\\int_a^b} f.\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{defi} (Integrability)\\\\\nSay $f$ is (Riemann) integrable on $\\left[a,b\\right]$ if it is bounded, and\n\\begin{equation*}\n\\begin{aligned}\n\\underline{\\int_a^b} f = \\bar{\\int_a^b} f\n\\end{aligned}\n\\end{equation*}\nWe define the integral of $f$ on $\\left[a,b\\right]$ to be the common value of them, and denote it by\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\n\\end{aligned}\n\\end{equation*}\nor\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(t\\right) dt.\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{prop}\nSuppose $f:\\left[a,b\\right]\\to\\R$ is integrable and let\n\\begin{equation*}\n\\begin{aligned}\nm=\\inf_{\\left[a,b\\right]} f\\\\\nM=\\sup_{\\left[a,b\\right]} f\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\nm\\left(b-a\\right) \\leq \\int_a^b f \\leq M\\left(b-a\\right)\n\\end{aligned}\n\\end{equation*}\nand\n\\begin{equation*}\n\\begin{aligned}\n|\\int_a^b f| \\leq \\left(b-a\\right) \\sup_{\\left[a,b\\right]} |f|\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nConsider $\\D:a<b$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\S_\\D \\left(f\\right) = m\\left(b-a\\right)\\\\\nS_\\D\\left(f\\right) = M\\left(b-a\\right)\n\\end{aligned}\n\\end{equation*}\nIn addition\n\\begin{equation*}\n\\begin{aligned}\nM&\\leq \\sup_{\\left[a,b\\right]} |f|\\\\\nm&\\geq -\\sup_{\\left[a,b\\right]} |f|\n\\end{aligned}\n\\end{equation*}\nSo the result follows.\n\\end{proof}\n\\end{prop}\n\n\\begin{eg}\n$\\bullet$ 1) If $f\\left(x\\right)=c$ $\\forall x\\in \\left[a,b\\right]$ then $f$ is integrable, and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(t\\right) dt = c\\left(b-a\\right)\n\\end{aligned}\n\\end{equation*}\nNote that $m=M=c$. Then\n\\begin{equation*}\n\\begin{aligned}\nc\\left(b-a\\right)=m\\left(b-a\\right) \\leq \\underline{\\int_a^b}f\\leq\\bar{\\int_a^b} f\\leq M\\left(b-a\\right) = c\\left(b-a\\right)\n\\end{aligned}\n\\end{equation*}\nSo the upper and lower integral are equal and the value is $c\\left(b-a\\right)$.\n\\end{eg}\n\n$\\bullet$ 2) $f:\\left[0,1\\right] \\to \\R$, $f\\left(x\\right) = x$.\\\\\nConsider\n\\begin{equation*}\n\\begin{aligned}\n\\D_n: 0\\leq\\frac{1}{n}\\leq\\frac{2}{n}\\leq...\\leq\\frac{n}{n}=1\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D_n}\\left(f\\right) = \\sum_{k=1}^n \\frac{1}{n}\\frac{k-1}{n} = \\frac{\\left(n-1\\right)n}{2n^2} = \\frac{n-1}{2n} \\to \\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\underline{\\int_0^1} f \\geq \\sup_n \\S_{\\D_n}\\left(f\\right) = \\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nSimilarly,\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n}\\left(f\\right) = \\sum_{k=1}^n \\frac{1}{n}\\frac{k}{n} = \\frac{\\left(n+1\\right)n}{2n^2} = \\frac{n+1}{2n}\\to \\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\bar{\\int_0^1}f \\leq \\inf_n S_{\\D_n}\\left(f\\right) = \\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nSo it follows that $f$ is integrable and is equal to $\\frac{1}{2}$.\n\n\\begin{thm}\nA bounded function $f:\\left[a,b\\right]\\to\\R$ is integrable if and only if\n\\begin{equation*}\n\\begin{aligned}\n\\forall \\epsilon > 0 \\exists \\D \\text{ s.t. } S_\\D \\left(f\\right) - \\S_\\D\\left(f\\right) < \\epsilon\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\n$\\bullet$ Forward: Since\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b = \\inf_\\D S_\\D \\left(f\\right) = \\sup_\\D \\S_\\D\\left(f\\right)\n\\end{aligned}\n\\end{equation*}\nwe know that $\\exists \\D_1,\\D_2$ with\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_1}\\left(f\\right) < \\int_a^b f+\\frac{\\epsilon}{2},\\\\\n\\S_{\\D_2}\\left(f\\right) > \\int_a^b f-\\frac{\\epsilon}{2}.\n\\end{aligned}\n\\end{equation*}\nSet $\\D = \\D_1 \\cup \\D_2$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f-\\frac{\\epsilon}{2} < \\S_{\\D_2} \\left(f\\right) \\leq \\S_\\D \\left(f\\right) \\leq S_\\D \\left(f\\right) \\leq S_{\\D_1}\\left(f\\right) < \\int_a^b f + \\frac{\\epsilon}{2}\n\\end{aligned}\n\\end{equation*}\n\n$\\bullet$ Backward: Suppose\n\\begin{equation*}\n\\begin{aligned}\nS_\\D \\left(f\\right) - \\S_\\D \\left(f\\right) < \\epsilon\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\bar{\\int_a^b}f \\leq S_\\D\\left(f\\right) < \\S_\\D \\left(f\\right) + \\epsilon \\leq \\underline{\\int_a^b}f+\\epsilon\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\bar{\\int_a^b}f \\leq \\underline{\\int_a^b}f + \\epsilon \\forall \\epsilon > 0\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\n\\bar{\\int_a^b}f \\leq \\underline{\\int_a^b}f\n\\end{aligned}\n\\end{equation*}\nSo $f$ is integrable.\n\\end{proof}\n\\end{thm}\n\n\\begin{coro}\nA bounded function $f:\\left[a,b\\right]\\to\\R$ is integrable if and only if there exists a sequence $\\D_n$ of dissections s.t.\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n} \\left(f\\right) - \\S_{\\D_n} \\left(f\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\nas $n\\to\\infty$. Then both $\\S_{\\D_n}\\left(f\\right)$ and $S_{\\D_n}\\left(f\\right)$ converge to $\\int_a^b f$.\\\\\nMoreover, if\n\\begin{equation*}\n\\begin{aligned}\n\\D_n: a = x_0^{\\left(n\\right)}<x_1^{\\left(n\\right)}<...<x_{m_n}^{\\left(n\\right)}=b\n\\end{aligned}\n\\end{equation*}\nand\n\\begin{equation*}\n\\begin{aligned}\n\\xi_k^{\\left(n\\right)} \\in \\left[x_{k-1}^{\\left(n\\right)},x_k^{\\left(n\\right)}\\right]\n\\end{aligned}\n\\end{equation*}\nFor $k=1,2,...,m_n$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{k=1}^{m_n} f\\left(\\xi_k^{\\left(n\\right)}\\right)\\left(x_k^{\\left(n\\right)}-x_{k-1}^{\\left(n\\right)}\\right) \\to \\int_a^b f\n\\end{aligned}\n\\end{equation*}\nas $n\\to\\infty$.\n\\begin{proof}\nThe first part is immediate from the previous theorem.\\\\\nFor the second part,\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f &\\leq S_{\\D_n}\\left(f\\right)\\\\\n&= \\S_{\\D_n} \\left(f\\right) + \\left(S_{\\D_n} \\left(f\\right) - \\S_{\\D_n}\\left(f\\right)\\right)\\\\\n&\\leq \\int_a^b f + \\left(S_{\\D_n} \\left(f\\right) - \\S_{\\D_n}\\left(f\\right)\\right)\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n}\\left(f\\right) \\to \\int_a^b f\n\\end{aligned}\n\\end{equation*}\nas $n\\to \\infty$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D_n}\\left(f\\right) = S_{\\D_n}\\left(f\\right) - \\left(S_{\\D_n}\\left(f\\right) - \\S_{\\D_n}\\left(f\\right)\\right) \\to \\int_a^b f\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\nTogether with\n\\begin{equation*}\n\\begin{aligned}\n\\inf_{\\left[x_{k-1}^{\\left(n\\right)},x_k^{\\left(n\\right)}\\right]} f \\leq f\\left(\\xi_k^{\\left(n\\right)} \\right) \\leq \\sup_{\\left[x_{k-1}^{\\left(n\\right)},x_k^{\\left(n\\right)}\\right]} f\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\n\\S_{\\D_n}\\left(f\\right) \\leq \\sum_{k=1}^{m_n} f\\left(\\xi_k^{\\left(n\\right)}\\right) \\left(x_k^{\\left(n\\right)} - x_{k-1}^{\\left(n\\right)}\\right) \\leq S_{\\D_n} \\left(f\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{coro}\n\n\\begin{rem}\n\\emph{Darboux}: if $f$ is integrable and \n\\begin{equation*}\n\\begin{aligned}\n\\D_n : a=x_0^{\\left(n\\right)}<x_1^{\\left(n\\right)}<...<x_{m_n}^{\\left(n\\right)} = b\n\\end{aligned}\n\\end{equation*}\nis such that \n\\begin{equation*}\n\\begin{aligned}\n|\\D_n| = \\max_{1\\leq k \\leq m_n} \\left(x_k^{\\left(n\\right)} - x_{k-1}^{\\left(n\\right)}\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n} \\left(f\\right) - \\S_{\\D_n} \\left(f\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\n\\end{rem}\n\n\\begin{lemma}\nLet $f,g:\\left[a,b\\right] \\to \\R$ be bounded functions. Assume there exists $k\\geq 0$ such that\n\\begin{equation*}\n\\begin{aligned}\n|f\\left(x\\right) - f\\left(y\\right)| \\leq K|g\\left(x\\right) - g\\left(y\\right)| \\forall x,y\\in\\left[a,b\\right]\n\\end{aligned}\n\\end{equation*}\nThen if $g$ is integrable, then $f$ is also integrable.\n\\begin{proof}\nGiven $\\epsilon>0$, there exists $\\D$ such that\n\\begin{equation*}\n\\begin{aligned}\nS_\\D \\left(g\\right) - \\S_\\D\\left(g\\right) < \\epsilon\n\\end{aligned}\n\\end{equation*}\nNow let \n\\begin{equation*}\n\\begin{aligned}\n\\D: a=x_0 < x_1 < ... < x_n = b\n\\end{aligned}\n\\end{equation*}\nAnd let $I=\\left[x_{k-1},x_k\\right]$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\sup_I f - \\inf_I f &= \\sup_{x,y\\in I} |f\\left(x\\right)-f\\left(y\\right)| \\\\\n&\\leq K\\sup_{x,y\\in I} |g\\left(x\\right)-g\\left(y\\right)|\\\\\n&= K\\left(\\sup_I g - \\inf_I g\\right)\n\\end{aligned}\n\\end{equation*}\nMultiply by $|I| = x_k - x_{k-1}$ and sum over $k$,\n\\begin{equation*}\n\\begin{aligned}\nS_\\D \\left(f\\right) - \\S_\\D \\left(f\\right) \\leq K\\left(S_\\D\\left(g\\right) - \\S_\\D \\left(g\\right) \\right) < k\\epsilon\n\\end{aligned}\n\\end{equation*}\nAs $\\epsilon$ is arbitrary, $f$ is integrable.\n\\end{proof}\n\\end{lemma}\n\n\\begin{thm}\nLet $f,g: \\left[a,b\\right] \\to \\R$ be integrable functions. Then\\\\\n1) $\\lambda f + \\mu g$ is integrable, and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b\\left(\\lambda f+\\mu y\\right) = \\lambda \\int_a^b f + \\mu \\int_a^b g\n\\end{aligned}\n\\end{equation*}\n2) If $f\\leq g$, then \n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f \\leq \\int_a^b g\n\\end{aligned}\n\\end{equation*}\n3) $|f|$ is integrable, and\n\\begin{equation*}\n\\begin{aligned}\n|\\int_a^b f | \\leq \\int_a^b |f|\n\\end{aligned}\n\\end{equation*}\n4) $\\max\\left(f,g\\right)$, $\\min\\left(f,g\\right)$ are integrable;\\\\\n5) $f \\cdot g$ is integrable, and (Cauchy-Schwarz inequality)\n\\begin{equation*}\n\\begin{aligned}\n|\\int_a^b fg | \\leq \\left(\\int_a^b f^2 \\right)^\\frac{1}{2} \\left(\\int_a^b g^2 \\right)^\\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\n1) Enough to consider $f+g$, $\\lambda f$ for $\\lambda \\geq 0$, and $-f$.\\\\\nWe know from a previous corollary that there exists a sequence $\\D_n$ of dissections of $\\left[a,b\\right]$ s.t. $S_{\\D_n} \\left(f\\right)$, $\\S_{\\D_n} \\left(f\\right)$ both converge to $\\int_a^b f$, and$S_{\\D_n} \\left(g\\right)$, $\\S_{\\D_n} \\left(g\\right)$ both converge to $\\int_a^b g$.\\\\\nFor an interval $I\\subset\\left[a,b\\right]$, we have\n\\begin{equation*}\n\\begin{aligned}\n&\\sup_I \\left(f+g\\right) \\leq \\sup_I f + \\sup_I g\\\\\n&\\inf_I \\left(f+g\\right) \\geq \\inf_I f + \\inf_I g\\\\\n&\\S_{\\D_n} \\left(f\\right) + \\S_{\\D_n} \\left(g\\right) \\leq \\S_{\\D_n} \\left(f+g\\right) \\leq S_{\\D_n} \\left(f+g\\right) \\leq S_{\\D_n} \\left(f\\right) + S_{\\D_n} \\left(g\\right)\n\\end{aligned}\n\\end{equation*}\nAs $n\\to \\infty$, LHS and RHS both tend to $\\int_a^b f + \\int_a^b g$. So $f+g$ is integrable and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b \\left(f+g\\right) = \\int_a^b f + \\int_a^b g\n\\end{aligned}\n\\end{equation*}\nAlso\n\\begin{equation*}\n\\begin{aligned}\n\\sup_I \\left(\\lambda f\\right) = \\lambda \\sup_I f\\\\\n\\inf_I \\left(\\lambda f\\right) = \\lambda \\inf_I f\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n} \\left(\\lambda f\\right) = \\lambda S_{\\D_n} \\left(f\\right) \\to \\lambda \\int_a^b f\\\\\n\\S_{\\D_n} \\left(\\lambda f\\right) = \\lambda \\S_{\\D_n} \\left(f\\right) \\to \\lambda \\int_a^b f\n\\end{aligned}\n\\end{equation*}\nBy the previous corollary, $\\lambda f$ is integrable and \n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b \\left(\\lambda f\\right) = \\lambda \\int_a^b f\n\\end{aligned}\n\\end{equation*}\nFinally,\n\\begin{equation*}\n\\begin{aligned}\n\\sup_I \\left(-f\\right) = -\\inf_I f,\\\\\n\\inf_I \\left(-f\\right) = -\\sup_I f\n\\end{aligned}\n\\end{equation*}\nWe get\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n} \\left(-f\\right) = -\\S_{\\D_n} \\left(f\\right) \\to -\\int_a^b f,\\\\\n\\S_{\\D_n} \\left(-f\\right) = -S_{\\D_n} \\left(f\\right) \\to -\\int_a^b f\n\\end{aligned}\n\\end{equation*}\nHence $-f$ is integrable and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b \\left(-f\\right) = -\\int_a^b f.\n\\end{aligned}\n\\end{equation*}\n2) If $f\\leq g$ then $g-f\\geq 0$. Hence\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b g - \\int_a^b f = \\int_a^b \\left(g-f\\right) \\geq \\left(b-a\\right) \\inf_{\\left[a,b\\right]} \\left(g-f\\right) \\geq 0\n\\end{aligned}\n\\end{equation*}\n3)Note that\n\\begin{equation*}\n\\begin{aligned}\n||f\\left(x\\right)| - f\\left(y\\right)|| \\leq |f\\left(x\\right) - f\\left(y\\right) |\n\\end{aligned}\n\\end{equation*}\nfor all $x,y\\in\\left[a,b\\right]$. So by the previous lemma, together with the assumption that $f$ is integrable, we know that $|f|$ is integrable. Since\n\\begin{equation*}\n\\begin{aligned}\nf\\leq |f|, -f \\leq |f|,\n\\end{aligned}\n\\end{equation*}\nby 2) we know that\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f \\leq \\int_a^b |f|,\\\\\n-\\int_a^b f = \\int_a^b \\left(-f\\right) \\leq \\int_a^b |f|\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\n|\\int_a^b f| \\leq \\int_a^b |f|.\n\\end{aligned}\n\\end{equation*}\n4) Given $s,t\\in \\R$,\n\\begin{equation*}\n\\begin{aligned}\n\\max\\left(s,t\\right) = \\frac{s+t}{2} + \\frac{|s-t|}{2}\n\\end{aligned}\n\\end{equation*}\nSo if $h=\\max\\left(f,g\\right)$, then for all $x\\in\\left[a,b\\right]$,\n\\begin{equation*}\n\\begin{aligned}\nh\\left(x\\right) = \\frac{f\\left(x\\right) + g\\left(x\\right)}{2} + \\frac{|f\\left(x\\right) - g\\left(x\\right)|}{2}\n\\end{aligned}\n\\end{equation*}\nHence $h$ is integrable by 1) and 3).\\\\\n($\\min\\left(f,g\\right)$ can be proved similarly).\\\\\n5) Let\n\\begin{equation*}\n\\begin{aligned}\nM=\\sup_{\\left[a,b\\right]} |f|\n\\end{aligned}\n\\end{equation*}\nThis exists since $f$ must be bounded on $\\left[a,b\\right]$. Then for all $x,y\\in\\left[a,b\\right]$,\n\\begin{equation*}\n\\begin{aligned}\n|f^2\\left(x\\right) - f^2\\left(y\\right)| = |f\\left(x\\right) - f\\left(y\\right)| \\cdot |f\\left(x\\right) + f\\left(y\\right)| \\leq 2M |f\\left(x\\right) - f\\left(y\\right)|\n\\end{aligned}\n\\end{equation*}\nSo by the previous lemma, $f^2$ is integrable. Hence by 1),\n\\begin{equation*}\n\\begin{aligned}\nfg = \\frac{1}{2}\\left[\\left(f+g\\right)^2 - f^2 - g^2\\right]\n\\end{aligned}\n\\end{equation*}\nis integrable.\\\\\nNext, we have\n\\begin{equation*}\n\\begin{aligned}\n0\\leq \\int_a^b \\left(f-\\lambda g\\right)^2 = \\int_a^b f^2 + \\lambda ^2 \\int_a^b g^2 - 2\\lambda \\int_a^b fg\n\\end{aligned}\n\\end{equation*}\n(using 2) and 1) respectively) for all $\\lambda\\in\\R$.\\\\\nNow put\n\\begin{equation*}\n\\begin{aligned}\n\\lambda = \\frac{\\int_a^b fg}{\\int_a^b g^2}\n\\end{aligned}\n\\end{equation*}\nAfter \\emph{some algebra}, we obtain the required inequality.\n\\end{proof}\n\\end{thm}\n\n\\begin{prop}\n1) Assume $h:\\left[a,b\\right]\\to\\R$ satisfies that $h\\left(x\\right)=0$ for all but finitely many $x$. Then $h$ is integrable, and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b h = 0\n\\end{aligned}\n\\end{equation*}\n2) Assume $f:\\left[a,b\\right] \\to \\R$ is integrable, and $g\\left(x\\right) = f\\left(x\\right)$ for all but finitely many $x$. Then $g$ is integrable, and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b g = \\int_a^b f\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nChoose\n\\begin{equation*}\n\\begin{aligned}\na=c_0 < c_1 < ... < c_n = b\n\\end{aligned}\n\\end{equation*}\ns.t. $h\\left(x\\right) = 0$ $\\forall x\\in \\left[a,b\\right]\\backslash\\left\\{c_0,c_1,...,c_n\\right\\}$ (it is not necessary for all of $f\\left(c_i\\right)$ to be non-zero).\\\\\nIf\n\\begin{equation*}\n\\begin{aligned}\nM=\\max_{0\\leq i \\leq n} |h\\left(c_i\\right)|\n\\end{aligned}\n\\end{equation*}\nThen $|h\\left(x\\right)| \\leq M$ $\\forall x$, so $h$ is bounded.\\\\\nFix $\\delta > 0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\delta < \\frac{1}{2}\\left(c_k - c_{k-1}\\right)\n\\end{aligned}\n\\end{equation*}\nfor all $1\\leq k \\leq n$.\\\\\nNow consider $\\D: a,a+\\delta, c_1-\\delta, c_1+\\delta, c_2-\\delta, c_2+\\delta,...,c_n-\\delta,c_n=b$. We have\n\\begin{equation*}\n\\begin{aligned}\n\\inf_{\\left[c_{k-1}+\\delta, c_k-\\delta\\right]} h = \\sup_{\\left[c_{k-1}+\\delta, c_k-\\delta\\right]} h = 0\n\\end{aligned}\n\\end{equation*}\nfor all $1\\leq k \\leq n$.\\\\\nIf $I=\\left[c_k - \\delta, c_k + \\delta\\right]$ ($1\\leq k \\leq n-1$) or $I=\\left[a,a+\\delta\\right]$ or $I=\\left[b-\\delta,b\\right]$, we have\n\\begin{equation*}\n\\begin{aligned}\n\\sup_I h \\leq M\\\\\n\\inf_I h \\geq -M\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\n\\S_\\D \\left(h\\right) \\geq \\left(n-1\\right) 2\\delta \\left(-M\\right) + 2\\delta \\left(-M\\right) = -2Mn\\delta,\\\\\nS_\\D \\left(h\\right) \\leq \\left(n-1\\right)2\\delta M + 2\\delta M = 2Mn \\delta\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\n-2Mn\\delta \\leq \\underline{\\int_a^b}h \\leq \\bar{\\int_a^b} h \\leq 2Mn\\delta\n\\end{aligned}\n\\end{equation*}\nBut $\\delta$ is arbitrary. So $h$ is integrable and the integral is 0.\\\\\n2) $g=f+\\left(g-f\\right)$. By 1) $g-f$ is integrable, and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b \\left(g-f\\right) = 0\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b g = \\int_a^b f\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{prop}\n\n\\begin{thm}\nEvery continuous function is integrable.\n\\begin{proof}\nLet $f:\\left[a,b\\right]\\to \\R$ be continuous. That means\n\\begin{equation*}\n\\begin{aligned}\n\\forall x\\in\\left[a,b\\right] \\forall \\epsilon < 0 \\exists \\delta > 0 \\forall y \\in \\left[a,b\\right] |y-x|<\\delta \\implies |f\\left(y\\right) - f\\left(x\\right)|<\\epsilon\n\\end{aligned}\n\\end{equation*}\nWe claim that\n\\begin{equation*}\n\\begin{aligned}\n\\forall \\epsilon < 0 \\exists \\delta > 0 \\forall x,y\\in\\left[a,b\\right] |y-x|<\\delta \\implies |f\\left(y\\right)-f\\left(x\\right)|<\\epsilon\n\\end{aligned}\n\\end{equation*}\n(actually this is the definition of uniform convergence).\\\\\nProof of claim: Suppose otherwise. Then\n\\begin{equation*}\n\\begin{aligned}\n\\exists \\epsilon > 0 \\forall \\delta > 0 \\exists x,y\\in\\left[a,b\\right] |y-x|<\\delta, |f\\left(y\\right) - f\\left(x\\right)| \\geq \\epsilon\n\\end{aligned}\n\\end{equation*}\nIn particular, \n\\begin{equation*}\n\\begin{aligned}\n\\forall n\\in \\N, \\exists x_n, y_n \\in \\left[a,b\\right] \\text{  s.t.  } |x_n-y_n|<\\frac{1}{n}, |f\\left(x_n\\right) - f\\left(y_n\\right) | \\geq \\epsilon\n\\end{aligned}\n\\end{equation*}\nNow $\\left(x_n\\right)$ is bounded. So by B-W theorem, $\\exists k_1<k_2<k_3<...$ in $\\N$ s.t. $\\left(x_{k_n}\\right)_{n=1}^\\infty$ converges to some $x\\in \\R$.\\\\\nSince $a\\leq x_{k_n} \\leq b$ for all $n$, we have $x\\in \\left[a,b\\right]$. Then since\n\\begin{equation*}\n\\begin{aligned}\n|y_{k_n}-x_{k_n} | < \\frac{1}{k_n} \\leq \\frac{1}{n} \\to 0\n\\end{aligned}\n\\end{equation*}\nas $n\\to\\infty$, so\n\\begin{equation*}\n\\begin{aligned}\ny_{k_n} = x_{k_n} + \\left(y_{k_n}-x_{k_n}\\right) \\to x\n\\end{aligned}\n\\end{equation*}\nas $n\\to \\infty$.\\\\\nAs $f$ is continuous, \n\\begin{equation*}\n\\begin{aligned}\n\\epsilon\\leq|f\\left(x_{k_n}\\right) - f\\left(y_{k_n}\\right)| \\to |f\\left(x\\right) - f\\left(x\\right)| = 0\n\\end{aligned}\n\\end{equation*}\nContradiction.\\\\\nNow back to the main proof.\\\\\nGiven $n\\in \\N$, choose $\\delta_n > 0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\forall x,y, |x-y|<\\delta_n \\implies |f\\left(x\\right) - f\\left(y\\right) | < \\frac{1}{n}\n\\end{aligned}\n\\end{equation*}\nThen choose a dissection $\\D_n$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n|\\D_n| < \\delta_n\\\\\n(\\text{  if  } \\D: a=x_0<x_1<...<x_m = b, \\text{  then  } |\\D| = \\max_{1\\leq_k\\leq m} \\left(x_k-x_{k-1}\\right) )\n\\end{aligned}\n\\end{equation*}\nIf $I$ is an interval of $\\D_n$ then \n\\begin{equation*}\n\\begin{aligned}\n\\sup_I f - \\inf_I f \\leq \\frac{1}{n}\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n}\\left(f\\right) - \\S_{\\D_n} \\left(f\\right) \\leq \\frac{1}{n}\\left(b-a\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\nas $n\\to\\infty$. So $f$ is integrable.\n\\end{proof}\n\\end{thm}\n\n\\begin{thm}\nMonotonic functions are integrable.\n\\begin{proof}\nLet $f:\\left[a,b\\right] \\to \\R$ be a monotonic function. WLOG let $f$ be increasing (otherwise look at $-f$).\\\\\nLet\n\\begin{equation*}\n\\begin{aligned}\n\\D_n: a+\\frac{k}{n}\\left(b-a\\right), 0\\leq n (n\\in \\N)\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n}\\left(f\\right) - \\S_{\\D_n} \\left(f\\right) &= \\sum_{k=1}^n \\frac{b-a}{n}\\left(\\sup_{\\left[a+\\frac{k-1}{n}\\left(b-a\\right),a+\\frac{k}{n}\\left(b-a\\right)\\right]} f - \\inf_{\\left[a+\\frac{k-1}{n}\\left(b-a\\right),a+\\frac{k}{n}\\left(b-a\\right)\\right]}\\right)\\\\\n&= \\frac{b-a}{n}\\sum_{k=1}^n \\left(f\\left(a+\\frac{k}{n}\\left(b-a\\right)\\right) - f\\left(a+\\frac{k-1}{n}\\left(b-a\\right)\\right)\\right)\\\\\n&= \\frac{b-a}{n} \\left(f\\left(b\\right) - f\\left(a\\right)\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\nas $n \\to \\infty$. So $f$ is integrable by the previous corollary.\n\\end{proof}\n\\end{thm}\n\n(A note on the proof of the integral form of Cauchy-Schwarz inequality:\n\\begin{equation*}\n\\begin{aligned}\n0\\leq \\int_a^b \\left(f-\\lambda g\\right)^2 = \\int_a^b f^2 + \\lambda^2 \\int_a^b g^2 - s\\lambda \\int_a^b fg\n\\end{aligned}\n\\end{equation*}\nfor all $\\lambda \\in \\R$.\\\\\nPutting\n\\begin{equation*}\n\\begin{aligned}\n\\lambda = \\frac{\\int_a^b fg}{\\int_a^b g^2}\n\\end{aligned}\n\\end{equation*}\nyields the result, provided the denominator is not zero.\\\\\nIf $\\int_a^b g^2 = 0$, then we get\n\\begin{equation*}\n\\begin{aligned}\n2\\lambda \\int_a^b fg \\leq \\int_a^b f^2\n\\end{aligned}\n\\end{equation*}\nfor all $\\lambda \\in \\R$.\\\\\nSince $\\lambda$ is arbitrary, this forces\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b fg = 0\n\\end{aligned}\n\\end{equation*}\nso the result still holds.)\n\n\\begin{thm}\nLet $a<b$, $f$ a bounded function on $\\left[a,b\\right]$.\\\\\n1) If $a<c<b$ and $f$ is integrable on $\\left[a,c\\right]$ and $\\left[c,b\\right]$, then it's integrable on $\\left[a,b\\right]$, and\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f = \\int_a^c f + \\int_c^b f\n\\end{aligned}\n\\end{equation*}\n2) If $f$ is integrable on $\\left[a,b\\right]$, then $f$ is integrable on $\\left[c,d\\right]$ whenever $a\\leq c<d\\leq b$.\n\\begin{proof}\n1) There exists sequences $\\D_n'$ and $\\D_n''$ of dissections of $\\left[a,c\\right]$ and $\\left[c,b\\right]$ respectively, such that\n\\begin{equation*}\n\\begin{aligned}\nS_{D'_n} \\left(f\\right), \\S_{\\D'_n} \\left(f\\right) \\to \\int_a^c f\\\\\nS_{D''_n} \\left(f\\right), \\S_{\\D''_n} \\left(f\\right) \\to \\int_c^b f\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\D_n = \\D'_n \\cup \\D''_n\n\\end{aligned}\n\\end{equation*}\nis a dissection of $\\left[a,b\\right]$, and\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_n} \\left(f\\right) = S_{\\D'_n}\\left(f\\right) + S_{\\D''_n} \\left(f\\right) \\to \\int_a^c f + \\int_c^b f\\\\\n\\S_{\\D_n} \\left(f\\right) = \\S_{\\D'_n}\\left(f\\right) + \\S_{\\D''_n} \\left(f\\right) \\to \\int_a^c f + \\int_c^b f\n\\end{aligned}\n\\end{equation*}\nSo $f$ is integrable on $\\left[a,b\\right]$ and tends to the expected value.\\\\\n2) Given $\\epsilon>0$, there is a dissection $\\D$ of $\\left[a,b\\right]$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nS_\\D \\left(f\\right) - \\S_\\D \\left(f\\right) < \\epsilon\n\\end{aligned}\n\\end{equation*}\nWLOG we may assume that $c,d$ are in $\\D$ (otherwise add them into $\\D$ which refines it, and will make the difference between the upper and lower integral even smaller).\\\\\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\D:a=x_0<x_1<...<x_n = b, c= x_{j-1}, d=x_k\n\\end{aligned}\n\\end{equation*}\nfor some $1\\leq j \\leq k \\leq n$.\\\\\nThen\n\\begin{equation*}\n\\begin{aligned}\nD': x_{j-1} < x_j < ... < x_k\n\\end{aligned}\n\\end{equation*}\nis a dissection of $\\left[c,d\\right]$. Then\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D'} \\left(f\\right) - S_{D'} \\left(f\\right) &= \\sum_{i=j}^k \\left(x_i-x_{i-1}\\right) \\left(\\sup_{\\left[x_{i-1},x_i\\right]} f - \\inf_{\\left[x_{i-1},x_i\\right]} f\\right)\\\\\n&\\leq \\sum_{i=1}^n \\left(x_i-x_{i-1}\\right) \\left(\\sup_{\\left[x_{i-1},x_i\\right]} f - \\inf_{\\left[x_{i-1},x_i\\right]} f\\right)\\\\\n&= S_\\D \\left(f\\right) - \\S_\\D \\left(f\\right)\\\\\n&<\\epsilon\n\\end{aligned}\n\\end{equation*}\nSo $S$ is integrable on $\\left[c,d\\right]$.\n\\end{proof}\n\\end{thm}\n\n\\begin{coro}\nLet $a,b,f$ be as in the previous theorem. Consider\n\\begin{equation*}\n\\begin{aligned}\na=c_0 < c_1 < ... < c_k = b\n\\end{aligned}\n\\end{equation*}\nThen $f$ is integrable on $\\left[a,b\\right]$ if and only if $f$ is integrable on $\\left[c_{j-1}, c_j\\right]$, for all $1\\leq j\\leq k$, and then\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f = \\sum_{j=1}^k \\int_{c_{j-1}}^{c_j} f\n\\end{aligned}\n\\end{equation*}\n\\end{coro}\n\n\\begin{coro}\nPiecewise monotonic functions are integrable. $f:\\left[a,b\\right]\\to \\R$ is \\emph{piecewise monotonic} if there exists $a=c_0 < c_1 < ... < c_k = b$ such that $f$ is monotonic on each $\\left[c_{j-1},c_j\\right]$.\\\\\n\\begin{proof}\nBy the theorem that monotonic functions are integrable, and the previous corollary.\n\\end{proof}\n\\end{coro}\n\n\\begin{thm}\nIf $a<b$, $f$ is a bounded function on $\\left[a,b\\right]$, continuous at all except finitely many points. Then $f$ is integrable.\n\\begin{proof}\nChoose\n\\begin{equation*}\n\\begin{aligned}\na=c_0 < c_1 < ... < c_k = b\n\\end{aligned}\n\\end{equation*}\nsuch that $f$ is continuous at $x$ if $x \\not\\in\\left\\{c_0, c_1, ..., c_k\\right\\}$.\\\\\nLet $M = \\sup_{\\left[a,b\\right]} |f|$. Choose $\\delta > 0$ such that $\\delta < \\frac{1}{2}\\left(c_j - c_{j-1}\\right)$ for all $j$ and $4M\\delta k < \\frac{\\epsilon}{2}$.\\\\\n$f$ is continuous on $\\left[c_{j-1}+\\delta, c_j-\\delta\\right]$ for $1\\leq j \\leq k$. So it's integrable, so there exists a dissection $\\D_j$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nS_{\\D_j} \\left(f\\right) - \\S_{\\D_j} \\left(f\\right) < \\frac{\\epsilon}{2k}\n\\end{aligned}\n\\end{equation*}\nNow consider\n\\begin{equation*}\n\\begin{aligned}\n\\D = \\bigcup_{j=1}^k \\D_j \\bigcup \\left\\{a,b\\right\\}\n\\end{aligned}\n\\end{equation*}\nwhich is a dissection of $\\left[a,b\\right]$. Then\n\\begin{equation*}\n\\begin{aligned}\nS_\\D \\left(f\\right) - \\S_\\D\\left(f\\right) &= \\sum_{j=1}^k \\left(S_{\\D_j} \\left(f\\right) - \\S_{\\D_j} \\left(f\\right)\\right) + \\text{  contributions from the small segments around  } c_j's\\\\\n&\\leq k\\cdot \\frac{\\epsilon}{2k} + 2\\delta \\cdot 2M \\cdot \\left(k-1\\right) + \\delta \\cdot 2M \\cdot 2\\\\\n&= \\frac{\\epsilon}{2} + 4M\\delta k\\\\\n&< \\epsilon\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{thm}\n\n\\begin{eg} (a function that is not integrable)\\\\\nLet\n\\begin{equation*}\n\\begin{aligned}\nf\\left(x\\right) = \\left\\{\n\\begin{array}{ll}\n0 & x\\in \\Q\\\\\n1 & x\\not\\in \\Q\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nfor any interval $I\\subset \\left[0,1\\right]$ of positive length, we have\n\\begin{equation*}\n\\begin{aligned}\n\\sup_I f = 1, \\inf_I f = 0\n\\end{aligned}\n\\end{equation*}\nThen for all dissection $\\D$, $S_\\D\\left(f\\right)=1$, $\\S_\\D\\left(f\\right)=0$. So\n\\begin{equation*}\n\\begin{aligned}\n\\bar{\\int_0^1}f = 1 \\neq 0 = \\underline{\\int_0^1} f\n\\end{aligned}\n\\end{equation*}\nSo $f$ is not integrable.\n\\end{eg}\n\n\\begin{defi}\nGiven $a<b$, $f$ integrable on $\\left[a,b\\right]$, we \\emph{define}\n\\begin{equation*}\n\\begin{aligned}\n\\int_b^a = -\\int_a^b f\n\\end{aligned}\n\\end{equation*}\nSo if $f$ is integrable on some closed, bounded interval containing $a,b,c$ (in any order), then\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f = \\int_a^c f + \\int_c^b f\n\\end{aligned}\n\\end{equation*}\nThis comes from the theorem about integrals on union of intervals and this definitions (a few cases for signs).\\\\\n(eg if $c<b<a$ then\n\\begin{equation*}\n\\begin{aligned}\n\\int_c^a f = \\int_c^b f + \\int_b^a f\\\\\n-\\int_a^c f = \\int_c^b f - \\int_a^b f\n\\end{aligned}\n\\end{equation*}\nSo consistent.)\\\\\nNote:\n\\begin{equation*}\n\\begin{aligned}\n|\\int_a^b f| \\leq |b-a| \\sup_{\\left[a,b\\right]} |f|\n\\end{aligned}\n\\end{equation*}\nSince if $a<b$, this holds by proposition 3;\\\\\nif $b<a$ then\n\\begin{equation*}\n\\begin{aligned}\n|\\int_a^b f| &= |-\\int_b^a f| = |\\int_b^a f|\\\\\n&\\leq \\left(a-b\\right) \\sup |f| = |b-a| \\sup |f|.\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{defi} (indefinite integral)\\\\\nSuppose $a<b$, $f$ is integrable on $\\left[a,b\\right]$ and $c\\in \\left[a,b\\right]$. The function\n\\begin{equation*}\n\\begin{aligned}\nF\\left(x\\right) = \\int_c^x f\\left(t\\right)dt, x\\in\\left[a,b\\right]\n\\end{aligned}\n\\end{equation*}\nis called \\emph{\\underline{an} indefinite integral of $f$ on $\\left[a,b\\right]$} (since this depends on c).\\\\\nNote:\n\\begin{equation*}\n\\begin{aligned}\nF\\left(y\\right) - F\\left(x\\right) = \\int_x^y f\\left(t\\right) dt\n\\end{aligned}\n\\end{equation*}\nThis does not depend on $c$.\n\\end{defi}\n\n\\begin{thm}\nIf $a<b$, $f$ integrable on $\\left[a,b\\right]$, $F$ is an indefinite integral of $f$ on $\\left[a,b\\right]$, then $F$ is continuous. In fact, there exists some $k\\geq 0$ such that\n\\begin{equation*}\n\\begin{aligned}\n|F\\left(y\\right) - F\\left(x\\right)| \\leq k |y-x|\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nLet $K=\\sup_{\\left[a,b\\right]} |f|$. Then\n\\begin{equation*}\n\\begin{aligned}\n|F\\left(y\\right) - F\\left(x\\right)| &= |\\int_x^y f\\left(t\\right) dt|\\\\\n&\\leq |y-x| \\cdot \\sup_{\\left[a,b\\right]} |f|\\\\\n&=K|y-x|\n\\end{aligned}\n\\end{equation*}\nSo the second part is done.\\\\\nNow given $x\\in\\left[a,b\\right], \\epsilon > 0$, letting $\\delta = \\frac{\\epsilon}{k}$, we have\n\\begin{equation*}\n\\begin{aligned}\n\\forall y\\in\\left[a,b\\right], |y-x|<\\delta \\implies |F\\left(y\\right) - F\\left(x\\right)| < \\epsilon.\n\\end{aligned}\n\\end{equation*}\nSo $F$ is continuous.\n\\end{proof}\n\\end{thm}\n\n\\begin{thm} (Fundamental theorem of Calculus)\\\\\nLet $a,b,f,F$ be as in the previous theorem. If $c\\in\\left[a,b\\right]$ and $f$ is continuous at $c$, then $F$ is differentiable at $c$, and\n\\begin{equation*}\n\\begin{aligned}\nF'\\left(c\\right) = f\\left(c\\right)\n\\end{aligned}\n\\end{equation*}\nNote: if $c=a$,\n\\begin{equation*}\n\\begin{aligned}\nF'\\left(a\\right) = \\lim_{h\\to 0^+} \\frac{F\\left(a+h\\right) - F\\left(a\\right)}{h}\n\\end{aligned}\n\\end{equation*}\nand if $c=b$,\n\\begin{equation*}\n\\begin{aligned}\nF'\\left(b\\right) = \\lim_{h\\to 0^-} \\frac{F\\left(b+h\\right) - F\\left(b\\right)}{h}.\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nGiven $\\epsilon>0$, there is a $\\delta>0$ s.t. \n\\begin{equation*}\n\\begin{aligned}\n\\forall t\\in\\left[a,b\\right] |t-c|<\\delta \\implies |f\\left(t\\right) - f\\left(c\\right)| < \\epsilon\n\\end{aligned}\n\\end{equation*}\nNow we have\n\\begin{equation*}\n\\begin{aligned}\n|\\frac{F\\left(c+h\\right)-F\\left(c\\right)}{h}-f\\left(c\\right)| &= |\\frac{1}{h}\\int_c^{c+h} f\\left(t\\right)dt-f\\left(c\\right)|\\\\\n&=|\\frac{1}{h} \\int_c^{c+h} \\left(f\\left(t\\right)-f\\left(c\\right)\\right) dt|\\\\\n&\\leq \\frac{1}{|h|}|h| \\cdot \\sup \\left\\{|f\\left(t\\right)-f\\left(c\\right)|: c \\leq t \\leq c+h\\right\\}\\\\\n&\\leq \\epsilon\n\\end{aligned}\n\\end{equation*}\nWhenever $0<|h|<\\delta$ (provided $c+h\\in\\left[a,b\\right]$).\n\\end{proof}\n\\end{thm}\n\nLet $a<b$, $f,F$ be functions on $\\left[a,b\\right]$. We say $F$ is an \\emph{antiderivative of $f$ on $\\left[a,b\\right]$} if $F$ is differentiable on $\\left[a,b\\right]$ and $F'\\left(x\\right) = f\\left(x\\right)$ for all $x\\in\\left[a,b\\right]$.\n\n\\begin{coro}\nLet $a<b$, $f$ a continuous function on $\\left[a,b\\right]$. Then $f$ has an antiderivative $F$ on $\\left[a,b\\right]$. Moreover, if $G$ is any antiderivative of $f$ on $\\left[a,b\\right]$, then\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(t\\right)dt = G\\left(b\\right) - g\\left(a\\right)\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nFor the first part, just take $F$ to be an indefinite integral of $f$ on $\\left[a,b\\right]$.\\\\\nFor the second part, we have\n\\begin{equation*}\n\\begin{aligned}\n\\left(F-G\\right)'\\left(x\\right) = F'\\left(x\\right) - G'\\left(x\\right) = f\\left(x\\right) - f\\left(x\\right) = 0\n\\end{aligned}\n\\end{equation*}\nfor all $x$.\\\\\nSo (by mean value theorem) $F-G$ is a constant. Hence\n\\begin{equation*}\n\\begin{aligned}\nG\\left(b\\right) - G\\left(a\\right) = F\\left(b\\right) - F\\left(a\\right) = \\int_a^b f\\left(t\\right) dt\n\\end{aligned}\n\\end{equation*}\nby definition of indefinite integrals.\n\\end{proof}\n\\end{coro}\n\n\\begin{rem}\n$\\bullet$ this corollary shows that the differential equation\n\\begin{equation*}\n\\begin{aligned}\n\\frac{dy}{dt}=f\n\\end{aligned}\n\\end{equation*}\nhas a solution when $f$ is continuous, and it is unique up to a constant.\\\\\nSo given $y_0\\in \\R$, the initial value problem\n\\begin{equation*}\n\\begin{aligned}\n\\left\\{\\begin{array}{ll}\n\\frac{dy}{dt}=f\\\\\ny\\left(a\\right) = y\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nhas a unique solution.\\\\\n$\\bullet$ this corollary provides a way for computing\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(t\\right) dt\n\\end{aligned}\n\\end{equation*}\nwhen $f$ is continuous.\n\\end{rem}\n\n\\begin{thm}\nLet $a<b$, $f$ integrable on $\\left[a,b\\right]$. Assume $f$ has an antiderivative $G$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(t\\right) dt = G\\left(b\\right) - G\\left(a\\right)\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nBy a previous corollary(5) we know that there exists a sequence $\\D_n$ of dissections of $\\left[a,b\\right]$ such that $S_{\\D_n} \\left(f\\right)$ and $\\S_{\\D_n} \\left(f\\right)$ both converge to $\\int_a^b f\\left(t\\right) dt$.\\\\\nSay\n\\begin{equation*}\n\\begin{aligned}\n\\D_n: a=x_0^{\\left(n\\right)} < x_1^{\\left(n\\right)} < ... < x_{m_n}^{\\left(n\\right)} = b\n\\end{aligned}\n\\end{equation*}\nfor some $m_n \\in \\N$.\\\\\nApply mean value theorem to $G$ on $\\left[x_{k-1}^{\\left(n\\right)},x_k^{\\left(n\\right)}\\right]$ we get, there exists $\\xi_k^{\\left(n\\right)} \\in \\left(x_{k-1}^{\\left(n\\right)},x_k^{\\left(n\\right)}\\right)$ such that\n\\begin{equation*}\n\\begin{aligned}\n\\frac{G\\left(x_k^{\\left(n\\right)}\\right) - G \\left(x_{k-1}^{\\left(n\\right)}\\right)}{x_k^{\\left(n\\right)-x_{k-1}^{\\left(n\\right)}}}=G'\\left(\\xi_k^{\\left(n\\right)}\\right) = f\\left(\\xi_k^{\\left(n\\right)}\\right)\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{k=1}^{m_n} f\\left(\\xi_k^{\\left(n\\right)}\\right) \\left(x_k^{\\left(n\\right)}-x_{k-1}^{\\left(n\\right)}\\right)\n=\\sum_{k=1}^{m_n} \\left(G\\left(x_k^{\\left(n\\right)}\\right) - G \\left(x_{k-1}^{\\left(n\\right)}\\right)\\right) = G\\left(b\\right) - G\\left(a\\right)\n\\end{aligned}\n\\end{equation*}\nThen by corollary 5, $LHS \\to \\int_a^b f\\left(t\\right)dt$ as $n\\to\\infty$.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\nLet $f,G$ be as in the previous theorem. Then\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^x f\\left(t\\right) dt = G\\left(x\\right) - G\\left(a\\right)\n\\end{aligned}\n\\end{equation*}\nfor all $x\\in\\left[a,b\\right]$.\\\\\nSo any indefinite integral of $f$ must be differentiable.\n\\end{rem}\n\n\\begin{coro}\nLet $a<b$, $f,g$ be integrable functions on $\\left[a,b\\right]$. Assume $F,G$ are antiderivatives of $f,g$ respectively on $\\left[a,b\\right]$. (eg this happens if $f,g$ are continuous)\\\\\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b fG = G\\left(b\\right) F\\left(b\\right) - G\\left(a\\right)F\\left(a\\right) - \\int_a^b Fg\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nLet\n\\begin{equation*}\n\\begin{aligned}\nH\\left(x\\right) = F\\left(x\\right)G\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\nfor $x\\in\\left[a,b\\right]$. By product rule, $H$ is differentiable, and\n\\begin{equation*}\n\\begin{aligned}\nH'\\left(x\\right) = f\\left(x\\right)G\\left(x\\right) + F\\left(x\\right) g\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\nRHS is integrable. Thus\n\\begin{equation*}\n\\begin{aligned}\nH\\left(b\\right)-H\\left(a\\right) = \\int_a^b \\left(fG+Fg\\right)\n\\end{aligned}\n\\end{equation*}\nrearrange to get the desired result.\n\\end{proof}\n\\end{coro}\n\n\\begin{coro} (Change of variable)\\\\\nLet $a<b$, $\\varphi:\\left[a,b\\right] \\to \\R$ be continuously differentiable. Let $f$ be a continuous function on the closed bounded interval $\\varphi\\left(\\left[a,b\\right]\\right)$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\int_{\\varphi\\left(a\\right)}^{\\varphi\\left(b\\right)} = \\int_a^b f\\left(\\varphi\\left(t\\right)\\right)\\varphi'\\left(t\\right) dt\n\\end{aligned}\n\\end{equation*}\n\n\\begin{rem}\nAs $\\varphi$ is continuous, there exists $c,d\\in\\left[a,b\\right]$ such that $\\varphi\\left(c\\right) \\leq \\varphi\\left(x\\right) \\leq\\varphi\\left(d\\right)$ for all $x\\in\\left[a,b\\right]$. Then by IVT, \n\\begin{equation*}\n\\begin{aligned}\n\\varphi\\left(\\left[a,b\\right]\\right) = \\left[\\varphi\\left(c\\right),\\varphi\\left(d\\right)\\right]\n\\end{aligned}\n\\end{equation*}\nWe do not assume that $\\varphi\\left(a\\right)$, $\\varphi\\left(b\\right)$ are the end points of this interval.\n\\end{rem}\n\\begin{proof}\nLet $F$ be an antiderivative of $f$ on $\\varphi\\left(\\left[a,b\\right]\\right)$ (this exists by a previous corollary(17)). By chain rule,\n\\begin{equation*}\n\\begin{aligned}\n\\left(F\\circ\\varphi\\right)'\\left(t\\right) = F'\\left(\\varphi\\left(t\\right)\\right)\\varphi'\\left(t\\right) = f\\left(\\varphi\\left(t\\right)\\right) \\varphi'\\left(t\\right)\n\\end{aligned}\n\\end{equation*}\nans is continuous. By corollary 17,\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(\\varphi\\left(t\\right)\\right) \\varphi'\\left(t\\right) dt = F\\left(\\varphi\\left(b\\right)\\right) - F\\left(\\varphi\\left(a\\right)\\right) = \\int_{\\varphi\\left(a\\right)}^{\\varphi\\left(b\\right)} f\\left(y\\right) dy\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{coro}\n\nNote that this corollary remains true if $\\varphi$ is differentiable, $\\varphi'$ is integrable, $f$ is integrable, and $f$ has antiderivative.\\\\\n(need: $\\varphi$ continuous, $f$ integrable $\\implies$ $f\\circ\\varphi$ integrable).\n\n\\begin{thm} (Taylor's theorem with the integral remainder)\\\\\nAssume $a,\\delta \\in \\R$, $\\delta>0$, $f:\\left(a-\\delta, a+\\delta\\right) \\to \\R$ is $n$ times continuously differentiable. Then for all $h\\in\\left(-\\delta,\\delta\\right)$,\n\\begin{equation*}\n\\begin{aligned}\nf\\left(a+h\\right)=\\sum_{k=0}^{n-1} \\frac{f^{\\left(k\\right)} \\left(a\\right)}{k!} h^k + \\frac{1}{\\left(n-1\\right)!}\\int_0^h \\left(h-t\\right)^{n-1} f^{\\left(n\\right)} \\left(a+t\\right) dt\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nInduction on $n$:\\\\\n$n=1$:\n\\begin{equation*}\n\\begin{aligned}\nRHS &= f\\left(a\\right) + \\int_0^h f'\\left(a+t\\right) dt\\\\\n&= f\\left(a\\right) + f\\left(a+h\\right) - f\\left(a\\right)\\\\\n&= LHS.\n\\end{aligned}\n\\end{equation*}\n$n\\geq 1$: assume result for $n$. Then\n\\begin{equation*}\n\\begin{aligned}\n&\\frac{1}{n!}\\int_0^h \\left(h-t\\right)^n f^{\\left(n+1\\right)} \\left(a+t\\right) dt\\\\\n&= \\left[\\frac{\\left(h-t\\right)^n}{n!}f^{\\left(n\\right)} \\left(a+t\\right)\\right]_0^h + \\frac{1}{n!} \\int_0^h n\\left(h-t\\right)^{n-1} \\cdot f^{\\left(n\\right)} \\left(a+t\\right) dt\\\\\n&= -\\frac{h^n}{n!} f^{\\left(n\\right)} \\left(a\\right) + \\frac{1}{\\left(n-1\\right)!} \\int_0^h \\left(h-t\\right)^{n-1} f^{\\left(n\\right)} \\left(a+t\\right)dt\\\\\n&=-\\frac{h^n}{n!} f^{\\left(n\\right)} \\left(a\\right) + \\left(f\\left(a+h\\right) - \\sum_{k=0}^{n-1} \\frac{f^{\\left(k\\right)} \\left(a\\right)}{k!} h^k\\right)\n\\end{aligned}\n\\end{equation*}\nrearrange to get the desired results.\n\\end{proof}\n\\end{thm}\n\n\n\\end{document}", "meta": {"hexsha": "4f985744e9ee583c82f2ea668559caa14cb4f65c", "size": 84588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Analysis.tex", "max_stars_repo_name": "raoxiaojia/raoxiaojia.github.io", "max_stars_repo_head_hexsha": "d20c23a64794b500f2e0356fd01017ee31830fa2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-25T17:34:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-25T17:34:25.000Z", "max_issues_repo_path": "Notes/Analysis.tex", "max_issues_repo_name": "raoxiaojia/raoxiaojia.github.io", "max_issues_repo_head_hexsha": "d20c23a64794b500f2e0356fd01017ee31830fa2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/Analysis.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": 36.6499133449, "max_line_length": 394, "alphanum_fraction": 0.6382229158, "num_tokens": 35567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6660256323137774}}
{"text": "\\chapter{Decidable Sets}\n\\marginpar{%\n  This part is mainly based on the amazing book\n  ``Computable Functions''\n  by Shen and Vereshchagin.\n}\nIn this part we study what computers can compute and what they cannot compute.\nUsually study of this subject starts from a formal definition of an algorithm.\nHowever, we believe that this is unnecessary nowadays because of rise of\ncomputers. One may think about algorithms as programs on some programming\nlanguage such as C/C++, Java, Python etc.\n\nAn algorithms are taking several natural numbers $x_1$, \\dots, $x_n$\nas an input and either print another number $y$ as an output or never\nterminates. In the first case we say $\\Algorithm{A}(x_1, \\dots, x_n) = y$\nand in the second case we say $\\Algorithm{A}(x_1, \\dots, x_n)$ never terminates.\n\n\\section{Computable Functions}\nThe first and the most basic definition in the computability theory is the\ndefinition of a computable function.\n\\begin{definition}\n    Let $S \\subseteq \\N^\\ell$ and $f : S \\to \\N$.\n    We say that $f$ is \\emph{computable} if there is an algorithm\n    $\\Algorithm{A}$ such that\n    \\begin{enumerate}\n        \\item $\\Algorithm{A}(x) = f(x)$ for any $x \\in S$ and\n        \\item $\\Algorithm{A}(x)$ never terminates for any $x \\notin S$.\n    \\end{enumerate}\n\n    We say that $\\Algorithm{A}$ \\emph{computes} $f$.\n\\end{definition}\n\nIt is important to note that nonetheless that we say that the algorithms are\nsaid to take and print natural numbers, we could allow algorithm to work with\nstrings of bits (elements of the set\n$\\strings = \\bigcup_{n \\in \\N_0} \\set{0, 1}^n$).\nMoreover, these two definitions are  equivalent since there is a one-to-one\ncorrespondence between natural numbers and strings:\n$x \\mapsto 2^n + \\sum_{i = 1}^\\ell 2^{i - 1} x[i]$, where $x[i]$ denotes the\n$i$th symbol of the string $i$ and $n$ is the length of $x$.\nIt is also clear that using binary strings we may encode all sorts of objects\nsuch as pairs of integers, integers, rational numbers etc. (However, in order\nto encode real number we need more complicated definitions and we are not\ngoing to discuss them in here.)\n\n\\begin{exercise}\n  Let $f : \\strings \\to \\strings$ be the function such that $f(x)$ is\n  reversed $x$. Show that $f$ is computable.\n\\end{exercise}\n\nOne may show that composition of computable functions is computable.\nMoreover, one may prove the following a bit stronger statement.\n\\begin{theorem}\n\\label{theorem:composition-computable}\n    Let $S \\subseteq \\N$, and let\n    $f : \\N \\to \\N$, and $g : S \\to \\N$ be computable\n    functions. Then $f \\circ g$ is also computable.\n\\end{theorem}\n\\begin{proof}\n  Since $f$ and $g$ are computable, there are algorightms $\\Algorithm{F}$ and\n  $\\Algorithm{G}$ computing f and g respectively.\n\n  Let us consider the following algorithm.\n  \\begin{algorithm}\n      \\begin{algorithmic}[1]\n          \\Function{$\\Algorithm{A}$}{$x$}\n              \\State{$y \\gets \\Algorithm{G}(x)$}\n              \\State{\\Return{$\\Algorithm{F}(y)$}}\n          \\EndFunction\n      \\end{algorithmic}\n      \\caption{The algorithm computing the composition of the functions\n        computed by $\\Algorithm{F}$ and $\\Algorithm{G}$}\n  \\end{algorithm}\n  It is clear that if $x \\notin S$, then $\\Algorithm{A}(x)$ never terminates.\n\n  However, if $x \\in S$, then $y = g(x)$ and therefore the algorithm prints\n  $\\Algorithm{F}(g(x)) = f(g(x)) = (f \\circ g)(x)$.\n\\end{proof}\n\n\\section{Decidable Sets}\nAnother important notion is the notion of a decidable set.\n\\begin{definition}\n    We say that a set $S \\subseteq \\N$ is \\emph{decidable} iff there is\n    an algorithm $\\Algorithm{A}$ such that\n    $\\Algorithm{A}(x) = 1$ if $x \\in S$ and $\\Algorithm{A}(x) = 0$ if\n    $x \\notin S$.\n\\end{definition}\nIt is easy to note that a set $S \\subseteq \\N$ is decidable iff the\ncharacteristic function $\\chi_S$ of $S$ is computable.\nThe function $\\chi_S$ is defined as follows:\n\\[\n    \\chi_S(x) =\n    \\begin{cases}\n        1 & \\text{if } x \\in S, \\\\\n        0 & \\text{otherwise}.\n    \\end{cases}\n\\]\nSimilarly we may define decidable sets of strings, pairs of integers etc.\n\nWe illustrate this concept by proving that\n$U_e = \\set[q > e]{q \\in \\Q}$. It is known that\n\\begin{enumerate}\n    \\item $(1 + \\frac{1}{n})^n < e$ and\n        $\\lim\\limits_{n \\to \\infty} (1 + \\frac{1}{n})^n = e$ and\n    \\item $(1 + \\frac{1}{n})^{n + 1} > e$ and\n        $\\lim\\limits_{n \\to \\infty} (1 + \\frac{1}{n})^{n + 1} = e$.\n\\end{enumerate}\nHence, in order to check whether $q \\in U_e$ or not, it is enough to either find\n$n$ such that $(1 + \\frac{1}{n})^{n + 1} < q$ or $(1 + \\frac{1}{n})^n > q$.\nIn order to do this we can check all positive integers one after another\nand at some point one of the inequalities became true.\n\n\\begin{exercise}\n  Let $k \\in \\N$. Show that $[k]$ is decidable.\n\\end{exercise}\n\nHowever, sometimes it is possible to show that some set is decidable without\npresenting the algorithm explicitly.\nFor example, consider the $S \\subseteq \\N$ such that $n \\in S$ iff base $10$\nexpansion of $\\pi$ has $n$ consecutive $9$s. It is possible to show that $S$ is\ndecidable. Indeed, it is easy to see that either $S = \\N$ or $S = [k]$ for some\n$k \\in \\N$, however, in both cases the set is decidable.\n\n\nIt is easy to show that decidable sets have several good properties.\n\\begin{theorem}\n\\label{theorem:operations-decidable}\n  Let $S_1, S_2 \\subseteq \\N^\\ell$ be decidable sets. Then $S_1 \\cup S_2$,\n  $S_1 \\cap S_2$, and $S_1 \\setminus S_2$ are all decidable.\n\\end{theorem}\n\nTo prove the theorem, we generalize \\Cref{theorem:composition-computable}.\n\\begin{theorem}\n\\label{theorem:composition-computable-generalization}\n  Let $S \\subseteq \\N^\\ell$ and let $f_1, f_2 : S \\to \\N$ and $g : \\N^2 \\to \\N$\n  be computable functions. Then the function $h : S \\to \\N$ such that\n  $h(x) = g(f_1(x), f_2(x))$ is computable.\n\\end{theorem}\n\n\\begin{proof}[Proof of \\Cref{theorem:operations-decidable}]\n  Let us prove that $S_1 \\cup S_2$ is decidable. Since $S_1$ and $S_2$ are\n  decidable, there are algorithms $\\Algorithm{A}_1$ and $\\Algorithm{A}_2$\n  computing characteristic functions $\\chi_{S_1}$ and $\\chi_{S_2}$\n  for the sets $S_1$ and $S_2$, respectively.\n  Consider the function $g : \\N^2 \\to \\N$ such that\n  \\[\n    g(x, y) = \\begin{cases}\n      0 & \\text{if } x = 1 \\text{ or } y = 1 \\\\\n      1 & \\text{otherwise}\n    \\end{cases}.\n  \\]\n  It is clear that $h : \\N \\to \\N$ such that\n  $h(x) = g(\\chi_{S_1}(x), \\chi_{S_2}(x))$ is a characteristic function for\n  $S_1 \\cup S_2$. Hence, $S_1 \\cup S_2$ is decidable by\n  \\Cref{theorem:composition-computable-generalization}.\n\n  The proof of decidability of $S_1 \\cap S_2$, and $S_1 \\setminus S_2$\n  is essentially the same.\n\\end{proof}\n\n\\section{Enumeratable Sets}\nThe algorithm constructed in the proof of decidability of $U_e$ consisted of\ntwo important parts: first one allowed to show that $q$ is defenetely not in the\nset $U_e$ and the second part allowed to show that $q$ is defenetely in the set.\n\nThis observation leads to the following definition.\n\\begin{definition}\n  We say that a set $S \\subseteq \\N$ is \\emph{(computably) enumerable},\n  we also say that it is \\emph{recursively enumerable} and \\emph{semidecidable},\n  iff there is an algorithm $\\Algorithm{A}$ such that\n  \\begin{enumerate}\n    \\item $\\Algorithm{A}(x) = 1$ for any $x \\in S$ and\n    \\item either $\\Algorithm{A}(x) = 0$ or $\\Algorithm{A}$ never terminates for\n      any $x \\notin S$.\n  \\end{enumerate}\n\n  We say that $S$ is \\emph{semidecided} by $\\Algorithm{A}$.\n\\end{definition}\n\nWe can easily show that both sets $L_e = \\set[q < e]{q \\in \\Q}$ and\n$U_e = \\set[q > e]{q \\in \\Q}$ are enumerable. Indeed, we can try all possible\n$n \\in n$ until $q < (1 + \\frac{1}{n})^n$ if we find such $n$, we know that\n$q \\in L_e$. Similarly, we can try all possible $n$ until\n$q > (1 + \\frac{1}{n})^{n + 1}$ and if we find such $n$, then $q \\in U_e$.\nThe following allows us to show that the fact that $L_e$ is decidable is not\na coincedence.\n\\begin{theorem}[Post's Theorem]\n\\label{theorem:enumerable-to-decidable}\n  Let $S \\subseteq \\N$. If $S$ is decidable, then $S$ is enumerable.\n  Moreover, if $S$ and $\\N \\setminus S$ are enumerable, then $S$ is\n  decidable.\n\\end{theorem}\n\\begin{proof}\n  The first part is obvious. Let us prove the ``moreover'' part.\n  Let $\\Algorithm{A}_1$ and $\\Algorithm{A}_2$ be the algorithms deciding\n  $S$ and $\\N \\setminus S$ respectively. Then the algorithm $\\Algorithm{A}$\n  deciding $S$ is the following: on onput $x$ it runs $\\Algorithm{A}_1(x)$ and\n  $\\Algorithm{A}_2(x)$ in parallel and if the first one prints $1$,\n  $\\Algorithm{A}$ prints $1$ as well;\n  however, if the second prints $1$, $\\Algorithm{A}$ prints $0$.\n\n  We need to prove that the algorithm works correctly.\n  \\begin{itemize}\n    \\item If $x \\in S$, then $\\Algorithm{A}_1(x) = 1$ and $\\Algorithm{A}_2(x)$\n      never terminates. So $\\Algorithm{A}(x)$ prints $1$.\n    \\item If $x \\notin S$, then $\\Algorithm{A}_1(x)$ never terminates and\n      $\\Algorithm{A}_2(x) = 1$. So $\\Algorithm{A}(x)$ prints $0$.\n  \\end{itemize}\n\\end{proof}\n\nThe given definition of enumerable set does not explain the name. However,\nthere is an alternative definition that explains it.\n\\begin{theorem}\n\\label{theorem:enumerable-semidecidable}\n  Let $S \\subseteq \\N$. The set $S$ is decidable iff there is an algorithm\n  $\\Algorithm{A}$ such that\n  \\begin{enumerate}\n    \\item $\\Algorithm{A}(n)$ terminates for any $n \\in \\N$ and\n    \\item $\\set[n \\in  \\N]{\\Algorithm{A}(n)} = S$.\n  \\end{enumerate}\n\n  We say that this $\\Algorithm{A}$ is enumerating $S$.\n\\end{theorem}\n\\begin{proof}\n  To prove this theorem, we generalize the idea of\n  \\Cref{theorem:enumeratable-to-decidable}. Assume that $S$ is infinite.\n  Let $\\Algorithm{A}'$ be the algorithm semideciding $S$ and\n  let $\\Algorithm{A}$ be \\Cref{algorithm:enumerating-from-semideciding}.\n  \\begin{algorithm}\n      \\begin{algorithmic}[1]\n          \\Function{$\\Algorithm{A}$}{$n$}\n              \\State{$i \\gets 1$}\n              \\State{Let $V$ be a map from integers to $\\set{0, 1}$}\n              \\While{$V$ has less than $n$ keys with the value $1$}\n                \\Parallel\n                  \\State{Let $y = \\Algorithm{A}'(i)$}\n                  \\State{Put $(i, y)$ into $V$}\n                \\EndParallel\n                \\State{$i \\gets (i + 1)$}\n              \\EndWhile\n              \\State{\\Return{the $i$th key in $V$ with the value $1$}}\n          \\EndFunction\n      \\end{algorithmic}\n      \\caption{The algorithm enumerating the set that is semidecided by\n        $\\Algorithm{A}'$.}\n      \\label{algorithm:enumerating-from-semideciding}\n  \\end{algorithm}\n  It is clear that $\\Algorithm{A}$ satisfies the constraints of the theorem.\n\n  Let us prove the statement in the opposite direction. Let us assume that\n  there is an algorithm $\\Algorithm{A}'$ enumerating $S$. Let $\\Algorithm{A}$\n  be \\Cref{algorithm:semideciding-from-enumerating}.\n  \\begin{algorithm}\n      \\begin{algorithmic}[1]\n          \\Function{$\\Algorithm{A}$}{$x$}\n              \\State{$n \\gets 1$}\n              \\While{$\\Algorithm{A}'(n) \\neq x$}\n              \\label{line:while-semideciding-from-enumerating}\n                \\State{$n \\gets n + 1$}\n              \\EndWhile\n              \\State{\\Return{$1$}}\n          \\EndFunction\n      \\end{algorithmic}\n      \\caption{The algorithm semideciding the set that is enumerated by\n        $\\Algorithm{A}'$.}\n      \\label{algorithm:semideciding-from-enumerating}\n  \\end{algorithm}\n  We need to prove that $\\Algorithm{A}$ semidecide the set $S$.\n  \\begin{enumerate}\n    \\item Let us consider some $x \\notin S$. In this case,\n      $\\Algorithm{A}'(n) \\neq x$ for any $n \\in \\N$. Hence, $\\Algorithm{A}$\n      never terminates.\n    \\item Let $x \\in S$. Then there is $n \\in \\N$ such that\n      $\\Algorithm{A}(n) \\neq x$.\n      Therefore, the number of iterations of\n      \\Cref{line:while-semideciding-from-enumerating} in\n      \\Cref{algorithm:semideciding-from-enumerating} is finite and the\n      algorithm returns $1$.\n  \\end{enumerate}\n\\end{proof}\n\nOne may also establish a connection between computable functions and\nenumerable sets.\n\\begin{theorem}\n\\label{theorem:enumerable-via-computable-funcitons}\n  Let $S \\subseteq \\N$.\n  \\begin{enumerate}\n    \\item The set $S$ is enumerable iff there is a computable function\n      $f : S \\to \\N$.\n    \\item The set $S$ is enumerable iff there is a computable function\n      $f : \\N \\to \\N$ so that $\\Im{f} = S$.\n  \\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n  \\begin{enumerate}\n    \\item To prove this part of the statement from right to left\n        it is enough to note that\n        the function $f : S \\to \\N$ such that $f(x) = 1$ is computable iff\n        $S$ is enumerable. Indeed, if $\\Algorithm{A}$ enumerates $S$, then\n        it computes $f$; if $\\Algorithm{A}$ computes $f$ it enumerates $S$.\n\n        To prove it from left to right, we may notice that $g : \\N \\to \\N$\n        such that $g(x) = 1$ is computable.\n        Therefore $(g \\circ f) : S \\to \\N$ is\n        computable. This implies that $S$ is enumerable since\n        $(g \\circ f)(x) = 1$ for all $x \\in S$.\n    \\item This part directly follows from\n        \\Cref{theorem:enumerable-semidecidable}.\n  \\end{enumerate}\n\\end{proof}\n\nIn the rest of this part we refer to functions $f : S \\to B$,\nwhere $S \\subseteq A$ as partial functions from $\\N$ to $\\N$. We say\nthat $S$ is preimage of $f$. Moreover, when we say that a function\nfrom $\\N$ to $\\N$ is computable we mean that it is a partial computable\nfunction. Using this notation \\Cref{theorem:enumerable-via-computable-funcitons}\ncan be rephrased as follows.\n\\begin{corollary}\n\\label{corollary:enumerable-via-computable-funcitons}\n  \\begin{enumerate}\n    \\item The set $S$ is enumerable iff there is a computable function\n      $f : \\N \\to \\N$ such that the preimage of $f$ is equal to $S$.\n    \\item The set $S$ is enumerable iff there is a computable function\n      $f : \\N \\to \\N$ such that the image of $f$ is equal to $S$.\n  \\end{enumerate}\n\\end{corollary}\nSince the notation between functions and partial functions is that similar,\nin the rest of this part we say that a partial function from $A$ to $B$ is\ntotal iff the preimage of the function is equal to $A$.\n\n\\begin{chapterendexercises}\n  \\exercise[recommended] Let $S \\subseteq \\N$ be a nonempty set.\n    Show that $S$ is decidable iff there is a function $f : \\N \\to \\N$ such\n    that $f$ is computable, $f$ is nondecreasing, and $\\Im{f} = S$.\n  \\exercise Let $A, B \\subseteq \\N$ be enumerable sets. Show that\n    $A \\times B$ is enumerable.\n  \\exercise Let $F \\subseteq \\N^2$ be enumerable. Prove that exists a\n    set $S \\subseteq \\N$ and a computable function $f: S \\to \\N$ such that\n    $S = \\set[(x, y) \\in F]{x \\in \\N}$ and $(x, f(x)) \\in F$ for any $x \\in S$.\n  \\exercise\n    Let $S =\n      \\set[\n        x^n + y^n = z^n \\text{ has an integer solution}\n      ]{n \\in \\N}$. Show that $S$ is decidable.\n      (You should not use Fermat's Last Theorem.)\n\\end{chapterendexercises}\n", "meta": {"hexsha": "d4c61b7b78d83fc77d54a59953fd0a99a3d6dac1", "size": 14965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_9/chapter_35_decidable_sets.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_9/chapter_35_decidable_sets.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_9/chapter_35_decidable_sets.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 43.1268011527, "max_line_length": 80, "alphanum_fraction": 0.66020715, "num_tokens": 4645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145404, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6660256284557492}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 5.4 Eigenvalues and Eigenvectors 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 and right eigenvectors of a real N $\\times $ N unsymmetric\nmatrix $A$. Some or all of the eigenvalues and eigenvectors 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){\\bf %\n, VI}($\\geq $ N){\\bf , VEC}(LDA,$\\geq $N), WORK($\\geq $N)\n\n\\item[INTEGER]  \\ LDA, N, IFLAG($\\geq $N)\n\\end{description}\n\nAssign values to A(,), LDA, and N.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SEVVUN(A, LDA, N, VR, VI,\\\\\nVEC, IFLAG, WORK)\\\\\n\\end{tabular}}\n\\end{center}\n\nResults are returned in VR(), VI(), VEC(,), and IFLAG(1). The contents of\nA(,), IFLAG(), and WORK() will be modified.\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 and eigenvectors are to be\ncomputed. The integer LDA is the dimension of the first subscript of the\narrays A(,) and VEC. Require LDA $\\geq $ N. On return the contents\nof 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 VR($J$), and the\nimaginary part in VI($J$). If the $J^{th}$ eigenvalue is real VI($J$) will be\nzero. 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)|\\leq\n|$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[VEC(,)]  \\ [out] The eigenvectors will be stored in this array. If the $%\nJ^{th}$ eigenvalue is real then the $J^{th}$ eigenvector will be real and\nwill be stored in column $J$ of VEC(,). It will be normalized to have unit\nEuclidean length.\n\nIf the $J^{th}$ and $(J+1)^{st}$ eigenvalues are a complex conjugate pair,\nthen the $J^{th}$ eigenvector will be complex, say ${\\bf u}+i{\\bf v}$, and\nthe $(J+1)^{st}$ eigenvector will be its complex conjugate vector, ${\\bf u}-i%\n{\\bf v}$. The subroutine will store ${\\bf u}$ in column $J$ of VEC(,) and will\nstore ${\\bf v}$ in column $J+1$ of VEC(,). The eigenvector ${\\bf u}+i{\\bf v}$\nwill be normalized to have unit unitary norm and real first component, $i.e\n$. the first component of ${\\bf v}$ will be zero.\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\n\\item[WORK()] \\ [scratch] Working space.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange SEVVUN to DEVVUN, and the REAL type statement to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nThe following unsymmetric matrix $A$ is\ngiven on page~84 of~\\cite{Gregory:1969:ACM}.\n\\begin{equation*}\nA=\\left[\n\\begin{array}{rrr}\n8 & -1 & -5 \\\\\n-4 & 4 & -2 \\\\\n18 & -5 & -7\n\\end{array}\n\\right] .\n\\end{equation*}\n\nThe eigenvalues are 1, $2+4i$, and $2-4i$. The (unnormalized) right\neigenvectors are column vectors with the following triples of\nelements:  (1, 2, 1), (1, $1+i$, $1-i$), and (1, $1-i$, $1+i$).  This\nexample illustrates the way SEVVUN returns complex eigenvalues and\neigenvectors in storage.\n\nThe demonstration program DRSEVVUN below applies SEVVUN to compute\neigenvalues and eigenvectors for the above matrices. The results are\nin the file ODSEVVUN. Before the call to SEVVUN, the matrix is saved in\norder to compute the relative residual matrix $D$ defined as%\n\\begin{equation*}\nD=\\left( AW-W\\Lambda \\right) /\\gamma ,\n\\end{equation*}\nwhere $A$ denotes the current test matrix, $W$ is the matrix whose columns are\nthe computed eigenvectors of $A$, $\\Lambda $ is the diagonal matrix of\neigenvalues, and $\\gamma $ is the maximum-row-sum norm of $A$. The\n(possibly complex) matrix $D$ is packed into the array D(,) and printed.\n\n\\subsection{Functional Description.}\n\nGiven an N $\\times $ N real unsymmetric matrix $A$ there exists an N $\\times $ N nonsingular\nmatrix $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. Note\nthat $\\lambda $ is an eigenvalue of $A$ if and only if $A-\\lambda I$ is\nsingular.\n\nA nonzero vector ${\\bf w}$ is a right eigenvector of $A$ associated with an\neigenvalue $\\lambda $ if%\n\\begin{equation*}\nA{\\bf w}={\\bf w}\\lambda\n\\end{equation*}\nIf $A$ has N distinct eigenvalues then it will also have N linearly\nindependent eigenvectors. If the eigenvalues of $A$ are not all distinct then\nan eigenvalue $\\lambda $ of multiplicity $\\mu $ may have any number of\nlinearly independent eigenvectors from~1 to $\\mu $. If some multiple\neigenvalue of $A$ has fewer linearly independent eigenvectors than its\nmultiplicity the matrix is called defective.\n\nIf a set of computed eigenvalues returned by SEVVUN are equal or nearly equal,\nit is not uncommon for the associated computed eigenvectors to be\nlinearly dependent, or nearly so.  This subroutine cannot be used\nto distinguish between defective and nondefective matrices.\n\nThe subroutine SEVVUN was developed using the\nsubroutines BALANC, ELMHES, ELTRAN, HQR2, and BALBAK from the EISPACK\npackage of eigenvalue-eigenvector subroutines, \\cite{Smith:1974:MER}. The Fortran\nsubroutines in EISPACK are based directly on the earlier set of Algol\nprocedures described in \\cite{Wilkinson:1971:HAC}.\n\nSubroutine SEVVUN 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. Then, applies diagonal similarity scaling to balance the\nsize 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 SEVVUN consists of a minor modification of three\nEISPACK subroutines: ELTRN, HQR2, and BALBAK.\n\nELTRN computes explicitly the matrix $G$ that was stored in factored form by\nSEVBH.\n\nHQR2 applies the QR algorithm to $H$. This is an iterative process which\nreduces $H$ to a real nearly-upper-triangular matrix $R$%\n\\begin{equation*}\nR=Q^THQ.\n\\end{equation*}\nThe transformations applied to $H$ are also applied to $G$ forming%\n\\begin{equation*}\nK=GQ.\n\\end{equation*}\nThe matrix $R$ has a mixture of single elements and $2\\times 2$\nblocks on its diagonal 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\nThe eigenvectors of $R$, say ${\\bf z}_1$, ..., ${\\bf z}_N$ are each computed\nby a single back substitution process without any iteration. These\neigenvectors are transformed to eigenvectors of $B$, say ${\\bf s}_1$, ..., $%\n{\\bf s}_N$ by computing%\n\\begin{equation*}\n{\\bf s}_j=K{\\bf z}_j,\\quad j=1,...,N.\n\\end{equation*}\nBALBAK transforms the vectors $s_j$ to eigenvectors of $A$, say $w_j$, $j=1$,\n..., N by computing%\n\\begin{equation*}\n{\\bf w}_j=PD{\\bf s}_j,\\quad j=1,...,N.\n\\end{equation*}\nSEVVUN normalizes each eigenvector ${\\bf w}_j$ to have unit unitary norm\nand a real first component, and then reorders the eigenvalues along with\ntheir associated eigenvectors, to achieve the ordering described 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\nan error level of 0 to print an error message.  Upon return, IFLAG(1) = 3\nor~4 to indicate N $\\leq $ 0 or convergence failure, respectively.\nIn these error conditions all computed eigenvalues and eigenvectors should\nbe regarded as invalid.\n\nIf a set of computed eigenvalues are equal or nearly equal, the set of\nassociated computed eigenvectors will frequently not have as large a\nnumerical rank as would be possible for the given matrix.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\nThe EISPACK package of Fortran subroutines was acquired at JPL\nfrom Argonne National Laboratories where it was developed with financial\nsupport from the AEC and the NSF. The subroutine SEVVUN was written by F. T.\nKrogh, JPL, October~1991.\n\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDEVVUN & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DEVBH, DEVVUN, DNRM2, DSCAL, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\\nSEVVUN & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SEVBH, SEVVUN, SNRM2, SSCAL}\\\\\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 DRSEVVUN}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sevvun}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSEVVUN}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sevvun}}\n\\end{document}\n", "meta": {"hexsha": "8ef14340c85b8a010e8ab84ad89c2ff8b33c07c2", "size": 9890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch05-04.tex", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "doc/doctex/ch05-04.tex", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "doc/doctex/ch05-04.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.6328125, "max_line_length": 98, "alphanum_fraction": 0.732760364, "num_tokens": 3032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6660256271543522}}
{"text": "\\section{Methodology}\n\n\\subsection{Equivalent-layer technique for gravity data processing}\n\nLet $d^{o}_{i}$ be the observed gravity data at\nthe point $(x_{i}, y_{i}, z_{i})$, $i = 1, ..., N$, of a local Cartesian\nsystem with $x$-axis pointing to north, the $y$-axis pointing to east and \nthe $z$-axis pointing downward.\nLet us consider an equivalent layer composed by a set of $N$ point masses \n(equivalent sources) over a layer located at depth $z_0$ ($z_0 >z_i$) and whose \n$x$- and $y$- coordinates of each point mass coincides with the corresponding coordinates \nof the observation directly above.\nThere is a linear relationship that maps the unknown mass distribution onto the gravity \ndata given by\n\\begin{equation}\n\\mathbf{d}(\\mathbf{p}) = \\mathbf{A} \\mathbf{p} \\: ,\n\\label{eq:predicted-data-vector}\n\\end{equation}\nwhere $\\mathbf{d}$ is an $N \\times 1$ vector whose $i$th element is the predicted gravity \ndata at the $i$th point ($x_i$,$y_i$,$z_i$), $\\mathbf{p}$ is the unknown $N \\times 1$ \nparameter vector whose $j$th element $p_j$  is the mass of the $j$th equivalent source \n(point mass) at the $j$th Cartesian coordinates ($x_j$,$y_j$,$z_0$) and $\\mathbf{A}$ \nis an $N \\times N$  sensitivity matrix whose $ij$th element is given by \n\\begin{equation}\na_{ij}= \\frac{c_{g} \\, G \\, (z_{0} - z_{i})}{\\left[(x_{i} - x_{j})^{2} +\n(y_{i} - y_{j})^{2} +\t(z_{i} - z_{0})^{2} \\right]^{\\frac{3}{2}}} \\; ,\n\\label{eq:aij}\n\\end{equation}\nwhere $G$ is the Newton's gravitational constant and $c_{g} = 10^{5}$ \ntransforms from $\\mathrm{m/s^2}$ to mGal.\nNote that the sensitivity matrix depends on the $i$th coordinate of the observation \nand the $j$th coordinate of the equivalent source. For convenience, we designate \nthese coordinates as \\textit{matrix coordinates} and the indices $i$ and $j$ as \n\\textit{matrix indices}.\nIn the classical equivalent-layer technique, we estimate the regularized parameter vector \nfrom the observed gravity data $\\mathbf{d}^{o}$ by\n\\begin{equation}\n\\hat{\\mathbf{p}} = \\left( \\mathbf{A}^{\\top}\\mathbf{A} + \n\\mu \\, \\mathbf{I} \\right)^{-1}\n\\mathbf{A}^{\\top} \\mathbf{d}^{o} \\: .\n\\label{eq:estimated-p-parameter-space}\n\\end{equation}\n\n\\subsection{Fast equivalent-layer technique}\n\n\\citet{siqueira-etal2017} develop an iterative least-squares method to estimate the mass \ndistribution over the equivalent layer based on the excess of mass and the positive correlation \nbetween the observed gravity data and the masses on the equivalent layer. They showed \nthat the fast equivalent-layer technique has a better computational efficiency than the \nclassical equivalent layer approach (equation \\ref{eq:estimated-p-parameter-space}) if the \ndataset is greater than 200 observation points, even using a large number of iterations.\n\nConsidering one equivalent source (point mass) directly beneath each observation point, \nthe iteration of the \\citeauthor{siqueira-etal2017}'s~(\\citeyear{siqueira-etal2017}) method \nstarts by an initial approximation of mass distribution given by\n\\begin{equation}\n\\hat{\\mathbf{p}}^0 = \\tilde{\\mathbf{A}}^{-1} \\mathbf{d}^{o} \\: ,\n\\label{eq:p0_fast_eqlayer}\n\\end{equation}\nwhere $\\tilde{\\mathbf{A}}^{-1}$ is an $N \\times N$ diagonal matrix with elements\n\\begin{equation}\n\\tilde{a}_{ii}^{-1} = \\frac{\\Delta s_i}{(2 \\pi \\, G \\, c_g)} \\: ,\n\\label{eq:aii_tilde_inv_fast_eqlayer}\n\\end{equation}\nwhere $\\Delta s_i$ is the $i$th element of surface area located at the $i$th horizontal \ncoordinates $x_i$ and $y_i$ of the $i$th observation.\nAt the $k$th iteration, the masses of the equivalent sources are updated by\n\\begin{equation}\n\\hat{\\mathbf{p}}^{k+1} = \\hat{\\mathbf{p}}^{k} + \\mathbf{\\Delta} \\hat{\\mathbf{p}}^{k} \\: ,\n\\label{eq:p_k+1_fast_eqlayer}\n\\end{equation}\nwhere the mass correction is given by\n\\begin{equation}\n\\mathbf{\\Delta} \\hat{\\mathbf{p}}^{k+1} = \\tilde{\\mathbf{A}}^{-1} (\\mathbf{d}^{o} - \\mathbf{A} \\hat{\\mathbf{p}}^{k}) \\: .\n\\label{eq:delta_p_k_fast_eqlayer}\n\\end{equation}\n\nAt the $k$th iteration of \\citeauthor{siqueira-etal2017}'s~(\\citeyear{siqueira-etal2017}) method, \nthe matrix-vector product \n$\\tensor{A} \\hat{\\mathbf{p}}^{k} = \\mathbf{d}(\\hat{\\mathbf{p}}^{k})$ must be calculated \nto obtain a \nnew residual $\\mathbf{d^0} - \\tensor{A} \\hat{\\mathbf{p}}^{k}$, which represents a bottleneck. \nConsidering the limitation of 16 Gb of RAM memory in our system, we could run the \n\\citeauthor{siqueira-etal2017}'s~(\\citeyear{siqueira-etal2017}) method only up to $22,500$  observation points;\nOtherwise, it is costly and can be prohibitive in terms of RAM \nmemory to maintain such operation.\n\n\\subsection{Structure of matrix $\\mathbf{A}$ for regular grids}\n\nConsider that the observed data are located on an $N_{x} \\times N_{y}$ regular grid of\npoints spaced by $\\Delta x$ and $\\Delta y$ along the $x$- and $y$-directions,\nrespectively, on a horizontal plane defined by the constant vertical coordinate $z_{1} < z_{0}$. \nAs a consequence, a given pair of matrix coordinates $(x_{i}, y_{i})$, defined by the matrix index \n$i$, $i = 1, \\dots, N = N_{x} N_{y}$, is equivalent to a pair of coordinates $(x_{k}, y_{l})$\ngiven by:\n\\begin{equation}\nx_{i} \\equiv x_{k} = x_{1} + \\left[ k(i) - 1 \\right] \\, \\Delta x \\: , \n\\label{eq:xi}\n\\end{equation}\nand\n\\begin{equation}\ny_{i} \\equiv y_{l} = y_{1} + \\left[ l(i) - 1 \\right] \\, \\Delta y \\: ,\n\\label{eq:yi}\n\\end{equation}\nwhere $k(i)$ and $l(i)$ are integer functions of the matrix index $i$.\nThese equations can also be used to define the matrix coordinates \n$x_{j}$ and $y_{j}$ associated with the $j$th equivalent source,\n$j = 1, \\dots, N = N_{x}N_{y}$. In this case, the integer functions\nare evaluated by using the index $j$ instead of $i$.\nFor convenience, we designate $x_{k}$ and $y_{l}$ as \\textit{grid coordinates}\nand the indices $k$ and $l$ as \\textit{grid indices}, which are computed with\nthe integer functions.\n\nThe integer functions assume different forms depending on the \norientation of the regular grid of data.\nConsider the case in which the grid is oriented along the\n$x$-axis (Figure \\ref{fig:methodology}a). For convenience, we designate these grids as \n$x$-\\textit{oriented grids}. For them, we have the following integer functions:\n\\begin{equation}\ni(k, l) = (l - 1) \\, N_{x} + k \\quad ,\n\\label{eq:i-x-oriented}\n\\end{equation}\n\\begin{equation}\nl(i) = \\Bigg\\lceil \\frac{i}{N_{x}} \\Bigg\\rceil\n\\label{eq:l-x-oriented}\n\\end{equation}\nand\n\\begin{equation}\nk(i)  = i - \\Bigg\\lceil \\frac{i}{N_{x}} \\Bigg\\rceil N_{x} + N_{x} \\quad ,\n\\label{eq:k-x-oriented}\n\\end{equation}\nwhere $\\lceil \\cdot \\rceil$ denotes the ceiling function \\citep[][ p. 67]{graham-etal1994}.\nThese integer functions are defined in terms of the matrix index $i$, but they can \nbe defined in the same way by using the index $j$.\nFigure \\ref{fig:methodology}a illustrates an $x$-oriented grid defined by $N_{x} = 4$ and $N_{y} = 3$.\nIn this example, the matrix coordinates $x_{7}$ and $y_{7}$, defined by the matrix index $i = 7$ (or $j = 7$), \nare equivalent to the grid coordinates $x_{3}$ and $y_{2}$, which are defined by the grid indices\n$k = 3$ and $l = 2$, respectively. These indices are computed with equations \\ref{eq:l-x-oriented}\nand \\ref{eq:k-x-oriented}, by using the matrix index $i = 7$ (or $j = 7$).\n\nNow, consider the case in which the regular grid of data is oriented along \nthe $y$-axis (Figure \\ref{fig:methodology}b). For convenience, we call them $y$-\\textit{oriented grids}.\nSimilarly to $x$-oriented grids, we have the following integer functions associated with\n$y$-oriented grids:\n\\begin{equation}\ni(k, l) = (k - 1) \\, N_{y} + l \\quad ,\n\\label{eq:i-y-oriented}\n\\end{equation}\n\\begin{equation}\nk(i) = \\Bigg\\lceil \\frac{i}{N_{y}} \\Bigg\\rceil\n\\label{eq:k-y-oriented}\n\\end{equation}\nand\n\\begin{equation}\nl(i) = i - \\Bigg\\lceil \\frac{i}{N_{y}} \\Bigg\\rceil N_{y} + N_{y} \\quad .\n\\label{eq:l-y-oriented}\n\\end{equation}\nFigure \\ref{fig:methodology}b illustrates an $y$-oriented grid defined by $N_{x} = 4$ and $N_{y} = 3$.\nIn this example, the matrix coordinates $x_{7}$ and $y_{7}$, defined by the matrix index \n$i = 7$ (or $j = 7$), are equivalent to the grid coordinates $x_{3}$ and $y_{1}$, which are \ndefined by the grid indices $k = 3$ and $l = 1$, respectively. Differently from the example\nshown in Figure \\ref{fig:methodology}a, the grid indices of the present example are \ncomputed with equations \\ref{eq:k-y-oriented} and \\ref{eq:l-y-oriented}, by using the \nmatrix index $i = 7$ (or $j = 7$).\n\nThe element $a_{ij}$ (equation \\ref{eq:aij}) can be rewritten \nby using equations \\ref{eq:xi} and \\ref{eq:yi}, giving rise to:\n\\begin{equation}\na_{ij} = \\frac{c_{g} \\, G \\, \\Delta z}{ \\left[ \n\t\\left( \\Delta k_{ij} \\, \\Delta x \\right)^{2} + \n\t\\left( \\Delta l_{ij} \\, \\Delta y \\right)^{2} + \n\t\\left( \\Delta z \\right)^{2} \\right]^{\\frac{3}{2}}} \\: ,\n\\label{eq:aij-regular-grids}\n\\end{equation}\nwhere $\\Delta z = z_{0} - z_{1}$, \n$\\Delta k_{ij} = k(i) - k(j)$ (equations \\ref{eq:k-x-oriented} or \\ref{eq:k-y-oriented}) and\n$\\Delta l_{ij} = l(i) - l(j)$ (equations \\ref{eq:l-x-oriented} or \\ref{eq:l-y-oriented}).\nNotice that the structure of matrix $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) for \nthe case in which its elements are given by $a_{ij}$ (equation \\ref{eq:aij-regular-grids}) is \ndefined by the coefficients $\\Delta k_{ij}$ and $\\Delta l_{ij}$.\n\nFor $x$-oriented grids, the coefficients $\\Delta k_{ij}$ and $\\Delta l_{ij}$ are \ncomputed by using equations \\ref{eq:k-x-oriented} and \\ref{eq:l-x-oriented}, respectively.\nIn this case, $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) is \ncomposed of $N_{y} \\times N_{y}$ blocks, where each block is formed by $N_{x} \\times N_{x}$ elements.\nFor $y$-oriented grids, the coefficients $\\Delta k_{ij}$ and $\\Delta l_{ij}$ are \ncomputed by using equations \\ref{eq:k-y-oriented} and \\ref{eq:l-y-oriented}, respectively.\nIn this case, $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) is a \ncomposed of $N_{x} \\times N_{x}$ blocks, where each block is formed by $N_{y} \\times N_{y}$ elements.\nIn both cases, $\\mathbf{A}$ is Toeplitz blockwise, i.e., the blocks lying at the same block \ndiagonal are equal to each other.\nBesides, the blocks located above the main diagonal are equal to those \nlocated below and each block is itself a Toeplitz matrix.\nThese symmetries come from the fact that the coefficients\n$\\Delta k_{ij}$ and $\\Delta l_{ij}$ are squared at the denominator of \n$a_{ij}$ (equation \\ref{eq:aij-regular-grids}).\nMatrices with this well-defined pattern are called \nDoubly Block Toeplitz \\citep[][ p. 28]{jain1989} or symmetric Block-Toeplitz Toeplitz-Block (BTTB),\nfor example. We opted for using the second term.\n\nThis well-defined pattern is better represented by using the \\textit{block indices} $q$ and $p$. \nWe represent $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) as a grid of $Q \\times Q$ blocks \n$\\mathbf{A}_{q}$, $q = 0, \\dots, Q - 1$, given by\n\\begin{equation}\n\t\\mathbf{A} = \\begin{bmatrix}\n\t\\mathbf{A}_{0}   & \\mathbf{A}_{1} & \\cdots         & \\mathbf{A}_{Q-1} \\\\\n\t\\mathbf{A}_{1}   & \\mathbf{A}_{0} & \\ddots         & \\vdots           \\\\ \n\t\\vdots           & \\ddots         & \\ddots         & \\mathbf{A}_{1}   \\\\\n\t\\mathbf{A}_{Q-1} & \\cdots         & \\mathbf{A}_{1} & \\mathbf{A}_{0}                 \n\t\\end{bmatrix}_{N \\times N} \\: ,\n\t\\label{eq:BTTB_A}\n\\end{equation}\nwhere each block has $P \\times P$ elements conveniently represented by $a^{q}_{p}$, \n$p = 0, \\dots, P - 1$, as follows:\n\\begin{equation}\n\t\\mathbf{A}_{q} = \\begin{bmatrix}\n\ta^{q}_{0}   & a^{q}_{1} & \\cdots    & a^{q}_{P-1} \\\\\n\ta^{q}_{1}   & a^{q}_{0} & \\ddots    & \\vdots           \\\\ \n\t\\vdots      & \\ddots    & \\ddots    & a^{q}_{1}   \\\\\n\ta^{q}_{P-1} & \\cdots    & a^{q}_{1} & a^{q}_{0}                 \n\t\\end{bmatrix}_{P \\times P} \\: ,\n\t\\label{eq:Aq_block}\n\\end{equation}\nwith $N = QP$. The index $q$ defines the block diagonal where $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}) \nlies within the BTTB matrix $\\mathbf{A}$ (equation \\ref{eq:BTTB_A}). \nThis index varies from $0$, at the main diagonal, to $Q - 1$, at\nthe corners of $\\mathbf{A}$. Similarly, the index $p$ defines the diagonal where $a^{q}_{p}$ \nlies within $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}). This index varies from $0$, \nat the main diagonal, to $P - 1$, at the corners of $\\mathbf{A}_{q}$.\nFor $x$-oriented grids, $Q = N_{y}$, $P = N_{x}$ and the block indices\n$q$ and $p$ are defined, respectively, by the following integer functions \nof the matrix indices $i$ and $j$:\n\\begin{equation}\nq(i, j) = \\; \\mid l(i) - l(j) \\mid\n\\label{eq:q-x-oriented}\n\\end{equation}\nand\n\\begin{equation}\np(i, j) = \\; \\mid k(i) - k(j) \\mid \\quad ,\n\\label{eq:p-x-oriented}\n\\end{equation}\nwhere $l(i)$ and $l(j)$ are defined by equation \\ref{eq:l-x-oriented} \nand $k(i)$ and $k(j)$ are defined by equation \\ref{eq:k-x-oriented}.\nFor $y$-oriented grids, $Q = N_{x}$, $P = N_{y}$ and the block indices\n$q$ and $p$ are defined, respectively, by the following integer functions \nof the matrix indices $i$ and $j$:\n\\begin{equation}\nq(i, j) = \\; \\mid k(i) - k(j) \\mid \n\\label{eq:q-y-oriented}\n\\end{equation}\nand\n\\begin{equation}\np(i, j) = \\; \\mid l(i) - l(j) \\mid \\quad ,\n\\label{eq:p-y-oriented}\n\\end{equation}\nwhere $k(i)$ and $k(j)$ are defined by equation \\ref{eq:k-y-oriented}\nand $l(i)$ and $l(j)$ are defined by equation \\ref{eq:l-y-oriented}.\nNote that, for each element $a_{ij}$ (equation \\ref{eq:aij-regular-grids}),\ndefined by matrix indices $i$ and $j$, there is a corresponding block element\n$a^{q}_{p}$, defined by block indices $q$ (equations \\ref{eq:q-x-oriented} or \n\\ref{eq:q-y-oriented}) and $p$ (equations \\ref{eq:p-x-oriented} or \\ref{eq:p-y-oriented}),\nso that\n\\begin{equation}\n\ta^{q}_{p} \\equiv a_{ij} \\quad .\n\t\\label{eq:aqp_equiv_aij}\n\\end{equation}\nWe also stress that matrix $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) defined \nby elements $a_{ij}$ (equation \\ref{eq:aij-regular-grids}) in terms of matrix indices \n$i$ and $j$ is strictly the same BTTB matrix $\\mathbf{A}$ (equation \\ref{eq:BTTB_A}) defined \nby the blocks $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}) and block elements \n$a^{q}_{p}$ (equation \\ref{eq:aqp_equiv_aij}) in terms of the block indices \n$q$ (equations \\ref{eq:q-x-oriented} or \\ref{eq:q-y-oriented}) and $p$ \n(equations \\ref{eq:p-x-oriented} or \\ref{eq:p-y-oriented}).\n\nIt is important to note that different matrix indices $i$ or $j$ produce the same \nabsolute values for the grid indices $k$ (equations \\ref{eq:k-x-oriented} or \n\\ref{eq:k-y-oriented}) and $l$ (equations \\ref{eq:l-x-oriented} or \n\\ref{eq:l-y-oriented}). As a consequence, different pairs of matrix indices $i$\nand $j$ generate the same absolute values for the coefficients $\\Delta k_{ij}$ and\n$\\Delta l_{ij}$ that compose the denominator of $a_{ij}$ \n(equation \\ref{eq:aij-regular-grids}) and also the same values for the block indices\n$q$ (equations \\ref{eq:q-x-oriented} or \\ref{eq:q-y-oriented}) and \n$p$ (equations \\ref{eq:p-x-oriented} or \\ref{eq:p-y-oriented}), as well as the same\nblock element $a^{q}_{p}$ (equation \\ref{eq:aqp_equiv_aij}). \nIt means that elements $a_{ij}$ defined\nby different matrix indices $i$ and $j$ have the same value. The key point for\nunderstanding the structure of BTTB matrix $\\mathbf{A}$ (equation \\ref{eq:BTTB_A})\nis then, given a single element $a_{ij}$\ndefined by matrix indices $i$ and $j$, compute the grid indices \n$k$ (equations \\ref{eq:k-x-oriented} or \\ref{eq:k-y-oriented}) and\n$l$ (equations \\ref{eq:l-x-oriented} or \\ref{eq:l-y-oriented}).\nThese grid indices are used to \n(1) compute the coefficients $\\Delta k_{ij}$ and \n$\\Delta l_{ij}$ and determine the value of $a_{ij}$ with equation \n\\ref{eq:aij-regular-grids} and \n(2) compute the block indices $q$ (equations \\ref{eq:q-x-oriented} \nor \\ref{eq:q-y-oriented}) and $p$ (equations \\ref{eq:p-x-oriented} or \n\\ref{eq:p-y-oriented}) and determine the corresponding block element $a^{q}_{p}$ \n(equation \\ref{eq:aqp_equiv_aij}) forming $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}). \n\nConsider the $x$-oriented grid of $N_{x} \\times N_{y}$ points shown in Figure \\ref{fig:methodology}a, \nwith $N_{x} = 4$, $N_{y} = 3$ and $N = N_{x} \\, N_{y} = 12$.\nTo illustrate the relationship between the matrix indices ($i$ and $j$) and \nthe block indices ($q$ and $p$), consider the element $a_{ij}$ defined by \n$i = 2$ and $j = 10$, which is\nlocated in the 2nd line and 10th column of $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}).\nBy using equations \\ref{eq:l-x-oriented} and \\ref{eq:k-x-oriented}, we obtain the \ngrid indices $l(i) = 1$, $l(j) = 3$, $k(i) = 2$ and $k(j) = 2$.\nThese grid indices result in the coefficients $\\Delta k_{ij} = 0$ and $\\Delta l_{ij} = -2$,\nwhich are used to compute the element $a_{ij}$ (equation \\ref{eq:aij-regular-grids}),\nas well as in the block indices $q = 2$ (equation \\ref{eq:q-x-oriented}) and \n$p = 0$ (equation \\ref{eq:p-x-oriented}).\nThese block indices indicate that this element $a_{ij}$ appears in the main diagonal\nof the blocks $\\mathbf{A}_{2}$ (equation \\ref{eq:Aq_block}), which are located at the corners \nof $\\mathbf{A}$ (equation \\ref{eq:BTTB_A}).\nTo verify this, let us take the matrix indices associated with these elements.\nThey are $(i, j)$ = $(1, 9)$, $(2, 10)$, $(3, 11)$, $(4, 12)$, $(9, 1)$, $(10, 2)$, \n$(11, 3)$ and $(12, 4)$. By using these matrix indices, it is easy to verify that all\nof them produce the same grid indices $l(i)$, $l(j)$, $k(i)$ and $k(j)$ \n(equations \\ref{eq:l-x-oriented} and \\ref{eq:k-x-oriented}) as those associated with\nthe element defined by $i = 2$ and $j = 10$ or vice versa ($i = 10$ and $j = 2$). \nConsequently, all of them produce\nelements $a_{ij}$ (equation \\ref{eq:aij-regular-grids}) having the same value.\nBesides, it is also easy to verify that all these matrix indices produce the same block\nindices $q = 2$ (equation \\ref{eq:q-x-oriented}) and $p = 0$ (equation \\ref{eq:p-x-oriented})\nand the same block element $a^{q}_{p}$ (equation \\ref{eq:aqp_equiv_aij}).\nBy repeating this procedure for all elements $a_{ij}$, $i = 1, \\dots, 12$, $j = 1, \\dots, 12$, \nforming the matrix $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) obtained from our \n$x$-oriented grid (Figure \\ref{fig:methodology}a), we can verify that\n\\begin{equation}\n\\mathbf{A} = \\begin{bmatrix}\n\\mathbf{A}_{0} & \\mathbf{A}_{1} & \\mathbf{A}_{2} \\\\\n\\mathbf{A}_{1} & \\mathbf{A}_{0} & \\mathbf{A}_{1} \\\\\n\\mathbf{A}_{2} & \\mathbf{A}_{1} & \\mathbf{A}_{0}\n\\end{bmatrix}_{N \\times N} \\quad ,\n\\label{eq:A-x-oriented-example}\n\\end{equation}\nwhere $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}), $q = 0, \\dots, Q -1$, $Q = N_{y}$, \nare symmetric Toeplitz matrices given by:\n\\begin{equation}\n\\mathbf{A}_{q} = \\begin{bmatrix}\na^{q}_{0} & a^{q}_{1} & a^{q}_{2} & a^{q}_{3} \\\\\na^{q}_{1} & a^{q}_{0} & a^{q}_{1} & a^{q}_{2} \\\\\na^{q}_{2} & a^{q}_{1} & a^{q}_{0} & a^{q}_{1} \\\\\na^{q}_{3} & a^{q}_{2} & a^{q}_{1} & a^{q}_{0}\n\\end{bmatrix}_{N_{x} \\times N_{x}} \\quad ,\n\\label{eq:Aq-x-oriented}\n\\end{equation}\nwith elements $a^{q}_{p}$ (equation \\ref{eq:aqp_equiv_aij}) defined by \n$p = 0, \\dots, P - 1$, $P = N_{x}$.\n\nThis procedure can also be used to verify that the matrix $\\mathbf{A}$ \n(equation \\ref{eq:predicted-data-vector}) obtained\nfrom the $y$-oriented grid illustrated in Figure \\ref{fig:methodology}b is given by\n\\begin{equation}\n\\mathbf{A} = \\begin{bmatrix}\n\\mathbf{A}_{0} & \\mathbf{A}_{1} & \\mathbf{A}_{2} & \\mathbf{A}_{3} \\\\\n\\mathbf{A}_{1} & \\mathbf{A}_{0} & \\mathbf{A}_{1} & \\mathbf{A}_{2} \\\\\n\\mathbf{A}_{2} & \\mathbf{A}_{1} & \\mathbf{A}_{0} & \\mathbf{A}_{1} \\\\\n\\mathbf{A}_{3} & \\mathbf{A}_{2} & \\mathbf{A}_{1} & \\mathbf{A}_{0}\n\\end{bmatrix}_{N \\times N} \\quad ,\n\\label{eq:A-y-oriented-example}\n\\end{equation}\nwhere $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}), $q = 0, \\dots, Q - 1$, $Q = N_{x}$, \nare symmetric Toeplitz matrices given by:\n\\begin{equation}\n\\mathbf{A}_{q} = \\begin{bmatrix}\na^{q}_{0} & a^{q}_{1} & a^{q}_{2} \\\\\na^{q}_{1} & a^{q}_{0} & a^{q}_{1} \\\\\na^{q}_{2} & a^{q}_{1} & a^{q}_{0}\n\\end{bmatrix}_{N_{y} \\times N_{y}} \\quad ,\n\\label{eq:Aq-y-oriented}\n\\end{equation}\nwith elements $a^{q}_{p}$ (equation \\ref{eq:aqp_equiv_aij}) defined by \n$p = 0, \\dots, P - 1$, $P = N_{y}$.\n\nThese examples (equations \\ref{eq:A-x-oriented-example}--\\ref{eq:Aq-y-oriented}) show \nthat the entire $N \\times N$ BTTB matrix $\\mathbf{A}$ \n(equations \\ref{eq:predicted-data-vector} and \\ref{eq:BTTB_A}) \ncan be defined by using only the elements \nforming its first column (or row). Notice that a column contains the gravitational effect \nproduced by a single equivalent source at all $N$ observation points.\n\n\\subsection{BTTB matrix-vector product}\n\nThe matrix-vector product $\\tensor{A} \\hat{\\mathbf{p}}^{k}$ (equation \n\\ref{eq:delta_p_k_fast_eqlayer}) required by the fast equivalent-layer \ntechnique \\citep{siqueira-etal2017} accounts for most of its total computation time \nand can cause RAM memory shortage when processing large data sets.\nThis computational load can be drastically reduced by exploring the well-defined structure of \nmatrix $\\mathbf{A}$ (equation \\ref{eq:predicted-data-vector}) for the particular case in which \nits elements $a_{ij}$ are defined by equation \\ref{eq:aij-regular-grids}. \nIn this case, $\\mathbf{A}$ is a symmetric BTTB matrix (equations \\ref{eq:BTTB_A} and \n\\ref{eq:A-x-oriented-example}--\\ref{eq:Aq-y-oriented}) and the predicted data vector \n$\\mathbf{d}(\\mathbf{p})$ (equation \\ref{eq:predicted-data-vector}) can be efficiently\ncomputed by using the 2D Discrete Fourier Transform (DFT).\nTo do this, let us first rewrite $\\mathbf{d}(\\mathbf{p})$ and\n$\\mathbf{p}$ (equation \\ref{eq:predicted-data-vector}) as the following partitioned vectors:\n\\begin{equation}\n\\mathbf{d}(\\mathbf{p}) = \\begin{bmatrix}\n\\mathbf{d}_{0}(\\mathbf{p}) \\\\\n\\vdots \\\\\n\\mathbf{d}_{Q - 1}(\\mathbf{p})\n\\end{bmatrix}_{N \\times 1}\n\\label{eq:predicted-data-vector-partitioned}\n\\end{equation}\nand\n\\begin{equation}\n\\mathbf{p} = \\begin{bmatrix}\n\\mathbf{p}_{0} \\\\\n\\vdots \\\\\n\\mathbf{p}_{Q - 1}\n\\end{bmatrix}_{N \\times 1} \\quad ,\n\\label{eq:parameter-vector-partitioned}\n\\end{equation}\nwhere $\\mathbf{d}_{q}(\\mathbf{p})$ and $\\mathbf{p}_{q}$, $q = 0, \\dots, Q - 1$,\nare $P \\times 1$ vectors. Notice that $q$ is the block index defined by equations \n\\ref{eq:q-x-oriented} and \\ref{eq:q-y-oriented}, $Q$ defines the number of blocks\n$\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}) forming $\\mathbf{A}$ (equation \\ref{eq:BTTB_A}) \nand $P$ defines the number of elements forming each block $\\mathbf{A}_{q}$.\nThen, by using the partitioned vectors \n(equations \\ref{eq:parameter-vector-partitioned} and \\ref{eq:predicted-data-vector-partitioned}) \nand remembering that $N = QP$, we define the auxiliary linear system\n\\begin{equation}\n\\mathbf{w} = \\mathbf{C} \\mathbf{v} \\: ,\n\\label{eq:w_Cv}\n\\end{equation}\nwhere\n\\begin{equation}\n\\mathbf{w} = \\begin{bmatrix}\n\\mathbf{w}_{0} \\\\\n\\vdots \\\\\n\\mathbf{w}_{Q - 1} \\\\\n\\mathbf{0}_{2N \\times 1}\n\\end{bmatrix}_{4N \\times 1} \\quad ,\n\\label{eq:w-vector}\n\\end{equation}\n\\begin{equation}\n\\mathbf{w}_{q} = \\begin{bmatrix}\n\\mathbf{d}_{q}(\\mathbf{p}) \\\\\n\\mathbf{0}_{P \\times 1}\n\\end{bmatrix}_{2P \\times 1}\n\\label{eq:wq-vector} \\quad ,\n\\end{equation}\n\\begin{equation}\n\\mathbf{v} = \\begin{bmatrix}\n\\mathbf{v}_{0} \\\\\n\\vdots \\\\\n\\mathbf{v}_{Q - 1} \\\\\n\\mathbf{0}_{2N \\times 1}\n\\end{bmatrix}_{4N \\times 1} \\quad ,\n\\label{eq:v-vector}\n\\end{equation}\nand\n\\begin{equation}\n\\mathbf{v}_{q} = \\begin{bmatrix}\n\\mathbf{p}_{q} \\\\\n\\mathbf{0}_{P \\times 1}\n\\end{bmatrix}_{2P \\times 1}\n\\label{eq:vq-vector} \\quad ,\n\\end{equation}\nwith $\\mathbf{d}_{q}(\\mathbf{p})$ and $\\mathbf{p}_{q}$ defined by\nequations \\ref{eq:predicted-data-vector-partitioned} and \n\\ref{eq:parameter-vector-partitioned}, respectively.\nFinally $\\mathbf{C}$ (equation \\ref{eq:w_Cv}) is a \n$4N \\times 4N$ symmetric Block Circulant matrix with Circulant Blocks (BCCB) \n\\citep[][ p. 184]{davis1979}. A detailed description of this matrix and\nsome of its relevant properties are presented in Appendix A. \n\nWhat follows shows a step-by-step description of how we use the auxiliary \nsystem (equation \\ref{eq:w_Cv}) to compute the matrix-vector product \n$\\tensor{A} \\hat{\\mathbf{p}}^{k}$ (equation \\ref{eq:delta_p_k_fast_eqlayer}) in \na computationally efficient way by exploring the structure of matrix $\\mathbf{C}$.\nBy substituting equation \\ref{eq:C-diagonalized} in the auxiliary system \n(equation \\ref{eq:w_Cv}) and premultiplying both\nsides of the result by $\\left(\\mathbf{F}_{2Q} \\otimes \\mathbf{F}_{2P} \\right)$\n(see the details in Appendix A), we obtain\n\\begin{equation}\n\\boldsymbol{\\Lambda} \\left(\\mathbf{F}_{2Q} \\otimes \\mathbf{F}_{2P} \\right) \n\\mathbf{v} = \\left(\\mathbf{F}_{2Q} \\otimes \\mathbf{F}_{2P} \\right) \n\\mathbf{w} \\: .\n\\label{eq:vec-DFT-system}\n\\end{equation}\nNow, by applying the $vec$-operator to both sides of equation \\ref{eq:vec-DFT-system} \n(see the details in Appendix B), we obtain:\n\\begin{equation}\n\\mathbf{F}_{2Q}^{\\ast} \\left[ \n\\mathbf{L} \\circ \\left(\\mathbf{F}_{2Q} \\, \\mathbf{V} \\, \\mathbf{F}_{2P} \\right) \n\\right] \\mathbf{F}_{2P}^{\\ast} = \\mathbf{W} \\: ,\n\\label{eq:DFT-system}\n\\end{equation}\nwhere ``$\\circ$'' denotes the Hadamard product \\citep[][ p. 298]{horn_johnson1991} and \n$\\mathbf{L}$, $\\mathbf{V}$ and $\\mathbf{W}$ are $2Q \\times 2P$ matrices obtained \nby rearranging, along their rows, the elements forming the diagonal of matrix \n$\\boldsymbol{\\Lambda}$, vector $\\mathbf{v}$ and vector $\\mathbf{w}$, respectively.\nThe left side of equation \\ref{eq:DFT-system} contains the 2D \nInverse Discrete Fourier Transform (IDFT) of the term in brackets, which in turn\nrepresents the Hadamard product of matrix $\\mathbf{L}$ (equation \\ref{eq:left_side_DFT_system_3})\nand the 2D DFT of matrix $\\mathbf{V}$ (equation \\ref{eq:left_side_DFT_system_1}).\nMatrix $\\mathbf{L}$ contains the eigenvalues \nof $\\boldsymbol{\\Lambda}$ (equation \\ref{eq:C-diagonalized}) and can be \nefficiently computed by using only the first column of the BCCB matrix \n$\\mathbf{C}$ (equation \\ref{eq:w_Cv}) (see the details in Appendix C).\nHere, we evaluate equation \\ref{eq:DFT-system} and compute matrix $\\mathbf{L}$\nby using the 2D Fast Fourier Transform (2D FFT).\nThis approach, that have been used in potential-field methods\n\\citep[e.g.,][]{zhang-wong2015, zhang-etal2016, qiang_etal2019}, is actually \na fast 2D discrete convolution \\citep[e.g.,][ p. 213]{vanloan1992}.\n\nAt each iteration $k$th of the fast equivalent-layer technique, \n(equation \\ref{eq:delta_p_k_fast_eqlayer}), we efficiently compute \n$\\mathbf{A} \\hat{\\mathbf{p}}^{k} = \\mathbf{d}(\\hat{\\mathbf{p}}^{k})$ by following \nthe steps below:\n\n\\begin{itemize}\n\\item[\\textbf{(1)}] Use equation \\ref{eq:aij-regular-grids} to compute the first column \nof each block $\\mathbf{A}_{q}$ (equation \\ref{eq:Aq_block}), $q = 0, \\dots, Q-1$, forming \nthe BTTB matrix $\\mathbf{A}$ (equation \\ref{eq:BTTB_A});\n\n\\item[\\textbf{(2)}] Rearrange the first column of $\\mathbf{A}$ according to equations \n\\ref{eq:C-first-column-blocks} and \\ref{eq:Cq-first-column} to obtain the\nfirst column $\\mathbf{c}_{0}$ of the BCCB matrix $\\mathbf{C}$ (equation \\ref{eq:w_Cv});\n\n\\item[\\textbf{(3)}] Rearrange $\\mathbf{c}_{0}$ along the rows of matrix $\\mathbf{G}$\n(equation \\ref{eq:DFT_G}) and use the 2D FFT to compute matrix $\\mathbf{L}$ \n(equation \\ref{eq:DFT_G});\n\n\\item[\\textbf{(4)}] Rearrange the parameter vector $\\hat{\\mathbf{p}}^{k}$ \n(equation \\ref{eq:predicted-data-vector}) in its partitioned form \n(equation \\ref{eq:parameter-vector-partitioned}) to define the auxiliary vector \n$\\mathbf{v}$ (equation \\ref{eq:v-vector});\n\n\\item[\\textbf{(5)}] Rearrange $\\mathbf{v}$ to obtain matrix $\\mathbf{V}$, use the 2D FFT \nto compute its DFT and evaluate the left side of equation \\ref{eq:DFT-system-preliminary};\n\n\\item[\\textbf{(6)}] Use the 2D FFT to compute the IDFT of the result obtained in step (5) to \nobtain the matrix $\\mathbf{W}$ (equation \\ref{eq:DFT-system});\n\n\\item[\\textbf{(7)}] Use the $vec$-operator (equation \\ref{eq:vec-operator}) and equations \n\\ref{eq:w-vector} and \\ref{eq:wq-vector} to rearrange $\\mathbf{W}$ in order to obtain the predicted \ndata vector $\\mathbf{d}(\\hat{\\mathbf{p}}^{k})$.\n\n\\end{itemize}\n\n\n\\subsection{Computational performance}\n\n\nThe number of flops (floating-point operations) necessary to estimate the \n$N \\times 1$ parameter vector $\\mathbf{p}$ in the fast equivalent-layer technique \n\\citep{siqueira-etal2017} is\n\\begin{equation}\nf_{0} = N^{it} (3N + 2N^{2}) \\; ,\n\\label{eq:float_fast_eqlayer}\n\\end{equation}\nwhere $N^{it}$ is the number of iterations. In this equation, the term $2N^2$ is associated \nwith the matrix-vector product $\\mathbf{A} \\hat{\\mathbf{p}}^{k}$ (equation \n\\ref{eq:delta_p_k_fast_eqlayer}) and accounts for most of the computational complexity \nof this method.\nOur method replace this matrix-vector product by three operations: \none DFT, one Hadamard product and one IDFT involving $2Q \\times 2P$ matrices \n(left side of equation \\ref{eq:DFT-system}). \nThe Hadamard product requires $24N$ flops, $N = QP$, because the entries are \ncomplex numbers.\nWe consider that a DFT/IDFT requires $\\kappa \\, 4N \\log_{2}(4N)$ flops to be computed via 2D FFT, \nwhere $\\kappa$ is a constant depending on the algorithm. \nThen, the resultant flops count of our method is given by:\n\\begin{equation}\nf_{1} = N^{it} \\left[ 27N + \\kappa \\, 8N \\log_{2}(4N) \\right] \\: .\n\\label{eq:float_bccb}\n\\end{equation}\nFigure \\ref{fig:float} shows the flops counts $f_{0}$ and $f_{1}$ (equations \\ref{eq:float_fast_eqlayer}\nand \\ref{eq:float_bccb}) associated with the fast equivalent-layer technique \\citep{siqueira-etal2017} and \nour method, respectively, as a function of the number $N$ of observation points. \nWe considered a fixed number of $N^{it} = 50$ iterations and $\\kappa = 5$ (equation \\ref{eq:float_bccb}),\nwhich is compatible with a radix-2 FFT \\citep[][ p. 16]{vanloan1992}.\nAs we can see, the number of flops is drastically decreased in our method.\n\nAnother advantage of our method is concerned with the real $N \\times N$ matrix $\\mathbf{A}$ \n(equations \\ref{eq:predicted-data-vector} and \\ref{eq:BTTB_A}).\nIn the fast equivalent-layer technique, the full matrix \nis computed once and stored during the entire iterative process.\nOn the other hand, our method calculates only one column of $\\mathbf{A}$ \nand uses it to compute the complex $2Q \\times 2P$ matrix $\\mathbf{L}$ \n(equation \\ref{eq:DFT_G}) via 2D FFT, which is stored during all iterations.\nTable \\ref{tab:RAM-usage} shows the RAM memory usage needed to store the \nfull matrix $\\mathbf{A}$, a single column of $\\mathbf{A}$ and the full matrix \n$\\mathbf{L}$. These quantities were computed for different numbers of observations $N$. \nNotice that $N = 1,000,000$ observations require nearly $7.6$ TB of memory \nto store the whole matrix $\\mathbf{A}$.\n\nFigure \\ref{fig:time_fast_eqlayer_bccb} compares the runtime of the fast equivalent-layer technique \n\\citep{siqueira-etal2017} and of our method, considering a constant number of iterations $N^{it} = 50$. \nWe used a PC with an Intel Core i7 4790@3.6GHz processor and 16 GB of RAM memory.\nThe computational efficiency of our approach is significantly superior to that of the \nfast equivalent-layer technique for a number of observations $N$ greater than $10,000$. \nWe could not perform this comparison with a number of observations greater than $22,500$\ndue to limitations of our PC in storing the full matrix $\\mathbf{A}$.\nFigure \\ref{fig:time_bccb} shows the running time of our method with a number of observations \nup to  $25$ millions. \nThese results shows that, while the running time of our method is $\\approx 30.9$ s for \n$N = 1,000,000$, the fast equivalent-layer technique spends $\\approx 46.8$ s for $N = 22,500$.", "meta": {"hexsha": "1a88f034fb06a6eb08176c6b9e87c7cce62576b0", "size": 31616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/methodology.tex", "max_stars_repo_name": "pinga-lab/Eq_Layer-Toeplitz", "max_stars_repo_head_hexsha": "d56b40f99e9059c07a504efe3ad53aff8462622f", "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": "manuscript/methodology.tex", "max_issues_repo_name": "pinga-lab/Eq_Layer-Toeplitz", "max_issues_repo_head_hexsha": "d56b40f99e9059c07a504efe3ad53aff8462622f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-19T22:42:42.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-19T23:32:26.000Z", "max_forks_repo_path": "manuscript/methodology.tex", "max_forks_repo_name": "pinga-lab/Eq_Layer-Toeplitz", "max_forks_repo_head_hexsha": "d56b40f99e9059c07a504efe3ad53aff8462622f", "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": 52.5182724252, "max_line_length": 120, "alphanum_fraction": 0.6921495445, "num_tokens": 10609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6660059945664195}}
{"text": "\\def\\module{M3P14 Number Theory}\n\\def\\lecturer{Prof Toby Gee}\n\\def\\term{Autumn 2018}\n\\def\\cover{\n\\begin{align*}\n\\pi\n& = 3 + \\cfrac{1}{7 + \\cfrac{1}{15 + \\cfrac{1}{1 + \\cfrac{1}{292 + \\cfrac{1}{1 + \\cfrac{1}{1 + \\cfrac{1}{1 + \\cfrac{1}{\\ddots}}}}}}}} \\\\\n& = 0 + \\cfrac{4}{1 + \\cfrac{1^2}{2 + \\cfrac{3^2}{2 + \\cfrac{5^2}{\\ddots}}}}\n= 0 + \\cfrac{4}{1 + \\cfrac{1^2}{3 + \\cfrac{2^2}{5 + \\cfrac{3^2}{\\ddots}}}}\n= 3 + \\cfrac{1^2}{6 + \\cfrac{3^2}{6 + \\cfrac{5^2}{6 + \\cfrac{7^2}{\\ddots}}}} \\\\\n& = 2 + \\cfrac{2}{\\tfrac{1}{1} + \\cfrac{1}{\\tfrac{1}{2} + \\cfrac{1}{\\tfrac{1}{3} + \\cfrac{1}{\\ddots}}}}\n= 2 + \\cfrac{2}{1 + \\cfrac{1 \\cdot 2}{1 + \\cfrac{2 \\cdot 3}{1 + \\cfrac{3 \\cdot 4}{\\ddots}}}}\n= 2 + \\cfrac{4}{3 + \\cfrac{1 \\cdot 3}{4 + \\cfrac{3 \\cdot 5}{4 + \\cfrac{5 \\cdot 7}{\\ddots}}}} \\\\\n& = 3 + \\cfrac{1^3}{6 + \\cfrac{1^3 + 2^3}{6 + \\cfrac{1^3 + 2^3 + 3^3 + 4^3}{6 + \\cfrac{1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3}{6 + \\cfrac{1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3 + 7^3 + 8^3}{\\ddots}}}}}\n\\end{align*}\n}\n\\def\\syllabus{Prime numbers and factorisation. Euclid's algorithm and consequences. Congruences. The structure of $ \\unit{n} $. Primality testing and factorisation. RSA algorithm. Quadratic reciprocity. Sums of squares. Pell's equation. Continued fractions. Diophantine approximation. Primes in arithmetic progressions. Arithmetic functions. The distribution of prime numbers.}\n\n\\input{../style/header}\n\n% Macros\n\\newcommand{\\jacobi}[2]{\\br{\\tfrac{#1}{#2}}}\n\\newcommand{\\unit}[1]{\\br{\\ZZ / #1\\ZZ}^\\times}\n\n\\begin{document}\n\n\\input{../style/cover}\n\n\\section{Introduction}\n\n\\lecture{1}{Friday}{05/10/18}\n\nRoughly speaking number theory is the study of the integers. More specifically, problems in number theory often have a lot to do with primes and divisibility, congruences, and include problems about the rational numbers. For example, solving equations in integers or in the rationals, such as $ x^2 - 2y^2 = 1 $, etc. We will be looking at problems that can be tackled by elementary means, but this does not mean easy. Also the statements of problems can be elementary without the solution being elementary, such as Fermat's last theorem, or even known, such as the twin prime conjecture. Sometimes we will state interesting things, like the prime number theorem, without proving them. Typically these will be things that we could prove if the course was much longer. We will start the course with a look at prime numbers and factorisation, a review of Euclid's algorithm and consequences, congruences, the structure of $ \\unit{n} $, RSA algorithm, and quadratic reciprocity. We will return to primes at the end, too. The following are typical questions here.\n\\begin{itemize}\n\\item How do you tell if a number is prime?\n\\item How many primes are there congruent to $ a \\mod b $ for given $ a $ and $ b $?\n\\item How many primes are there less than $ n $?\n\\end{itemize}\nA warning is that we will be using plenty of things from the compulsory first and second year algebra courses, about groups, rings, ideals, fields, Lagrange's theorem, the first isomorphism theorem, and so on. You may want to revise this material if you are not comfortable with it. The course is not based on any particular book, although some material, such as continued fractions, was drawn from the following.\n\\begin{itemize}\n\\item A Baker, A concise introduction to the theory of numbers, 1984\n\\end{itemize}\nNot everything we will do is in that book, though.\n\n\\pagebreak\n\n\\section{Euclid's algorithm and unique factorisation}\n\n\\subsection{Divisibility}\n\n\\begin{definition}\nIf $ a, b \\in \\ZZ $, we say that $ a $ \\textbf{divides} $ b $, and $ a \\mid b $, if there exists $ c \\in \\ZZ $ such that $ b = ac $. If $ a $ does not divide $ b $, write $ a \\nmid b $.\n\\end{definition}\n\nIf $ a \\mid b $ and $ a \\mid c $ then $ a \\mid rb + sc $ for any $ r, s \\in \\ZZ $.\n\n\\begin{definition}\nThe \\textbf{greatest common divisor (gcd)} or \\textbf{highest common factor (hcf)} of $ a $ and $ b $ is the largest positive integer dividing $ a $ and $ b $. Write it as $ \\br{a, b} $.\n\\end{definition}\n\n\\begin{example*}\n$ \\br{-10, 15} = 5 $.\n\\end{example*}\n\n\\begin{note*}\nThe ring $ \\ZZ $ is a principal ideal domain (PID). If $ f_1, \\dots, f_n \\in R $, write $ \\br{f_1, \\dots, f_n} $ for the ideal generated by the $ f_i $. Then for $ a, b \\in \\ZZ $, the ideal $ \\br{a, b} $ is generated by the gcd $ \\br{a, b} $, by Theorem \\ref{thm:6} below.\n\\end{note*}\n\n\\begin{definition}\n$ n \\in \\ZZ $ is \\textbf{prime} if $ n $ has exactly two positive divisors, namely $ 1 $ and $ n $.\n\\end{definition}\n\n\\begin{note*}\nFrequently when people talk about prime numbers they restrict to the positive case. If we write, let $ p $ be a prime number, then we will usually mean $ p > 0 $.\n\\end{note*}\n\n\\begin{note*}\n$ 1 $ is not prime.\n\\end{note*}\n\n\\subsection{Euclid's algorithm}\n\n\\begin{proposition}\nIf $ a, b \\in \\ZZ $, not both zero, then for any $ n \\in \\ZZ $, $ \\br{a, b} = \\br{a, b - na} $.\n\\end{proposition}\n\n\\begin{proof}\nBy definition, it is enough to show that if $ r \\mid a $ and $ r \\mid b $ then $ r \\mid a $ and $ r \\mid b - na $ and conversely.\n\\end{proof}\n\n\\begin{theorem}\n\\label{thm:5}\nLet $ a, b \\in \\ZZ $ with $ b > 0 $. Then there exist unique $ q, r \\in \\ZZ $ with $ 0 \\le r < b $ and $ a = qb + r $.\n\\end{theorem}\n\n\\begin{proof}\nTake $ q = \\fbr{a / b} $. By definition $ 0 \\le a / b - q < 1 $, that is $ 0 \\le a - qb < b $, so take $ r = a - qb $. Uniqueness is easy.\n\\end{proof}\n\n\\textbf{Euclid's algorithm} is as follows. Let $ a, b \\in \\ZZ $ not both zero. Without loss of generality, $ 0 \\le b \\le a $.\n\\begin{enumerate}[leftmargin=0.5in, label=Step \\arabic*.]\n\\item If $ b = 0 $, output $ a $.\n\\item Otherwise, replace $ \\br{a, b} $ with $ \\br{b, r} $ as in Theorem \\ref{thm:5}. Then go to step 1.\n\\end{enumerate}\nThis algorithm terminates because $ \\abs{a} + \\abs{b} $ decreases when we apply step $ 2 $.\n\n\\begin{example*}\n\\hfill\n\n\\begin{minipage}{0.5\\textwidth}\n\\begin{align*}\n\\br{120, 87}\n& = \\br{87, 33} & 120 = 87 + 33 \\\\\n& = \\br{33, 21} & 87 = 2\\br{33} + 21 \\\\\n& = \\br{21, 12} & 33 = 21 + 12 \\\\\n& = \\br{12, 9} & 21 = 12 + 9 \\\\\n& = \\br{9, 3} & 12 = 9 + 3 \\\\\n& = \\br{3, 0} & 9 = 3\\br{3} + 10.\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.4\\textwidth}\n\\begin{align*}\n3\n& = 12 - 9 \\\\\n& = 12 - \\br{21 - 12} \\\\\n& = 2\\br{12} - 21 \\\\\n& = 2\\br{33 - 21} - 21 \\\\\n& = 2\\br{33} - 3\\br{21} \\\\\n& = 2\\br{33} - 3\\br{87 - 2\\br{33}} \\\\\n& = 8\\br{33} - 3\\br{87} \\\\\n& = 8\\br{120 - 87} - 3\\br{87} \\\\\n& = 8\\br{120} - 11\\br{87}.\n\\end{align*}\n\\end{minipage}\n\\end{example*}\n\n\\begin{theorem}\n\\label{thm:6}\nIf $ a, b \\in \\ZZ $, not both zero, then there exist $ r, s \\in \\ZZ $ such that $ \\br{a, b} = ra + sb $.\n\\end{theorem}\n\n\\begin{proof}\nIdea is to write $ \\br{a_n, b_n} $ for the sequence of pairs in Euclid's algorithm, and use downwards induction on $ n $. \\footnote{Exercise}\n\\end{proof}\n\n\\pagebreak\n\n\\subsection{Unique factorisation}\n\n\\begin{proposition}\n\\label{prop:7}\nLet $ n, a, b \\in \\ZZ $ with $ n \\mid ab $ and $ \\br{n, a} = 1 $. Then $ n \\mid b $.\n\\end{proposition}\n\n\\begin{proof}\nSince $ \\br{n, a} = 1 $, we can write $ rn + sa = 1 $, so $ b = n\\br{rb} + \\br{ab}s $, which is divisible by $ n $.\n\\end{proof}\n\nIf $ \\br{n, a} = 1 $, we say that $ n $ and $ a $ are \\textbf{coprime}.\n\n\\lecture{2}{Tuesday}{09/10/18}\n\n\\begin{corollary}\n\\label{cor:8}\nIf $ p $ is prime and $ p \\mid ab $ then $ p \\mid a $ or $ p \\mid b $.\n\\end{corollary}\n\n\\begin{proof}\nIf $ p \\nmid a $ then $ \\br{p, a} = 1 $, so Proposition \\ref{prop:7} implies $ p \\mid b $.\n\\end{proof}\n\n\\begin{proposition}\n\\label{prop:9}\nIf $ \\br{a, b} = 1 $, and $ a \\mid n $ and $ b \\mid n $, then $ ab \\mid n $.\n\\end{proposition}\n\n\\begin{proof}\nBy \\ref{thm:6}, we can write $ 1 = ra + sb $ with $ r, s \\in \\ZZ $. So $ n = r\\br{na} + s\\br{nb} $, which is divisible by $ ab $.\n\\end{proof}\n\nWe say that $ m_1, \\dots, m_n \\in \\ZZ $ are \\textbf{pairwise coprime} if $ \\br{m_i, m_j} = 1 $ for all $ i \\ne j $.\n\n\\begin{corollary}\n\\label{cor:10}\nIf $ m_1, \\dots, m_n $ are pairwise coprime and $ m_i \\mid N $ for all $ i $ then $ m_1 \\dots m_n \\mid N $.\n\\end{corollary}\n\n\\begin{proof}\nInduction on $ n $, where $ n = 2 $ is Proposition \\ref{prop:9}. \\footnote{Exercise}\n\\end{proof}\n\n\\begin{proposition}\n\\label{prop:11}\nEvery $ n \\in \\ZZ^* $ can be written as $ \\pm p_1 \\dots p_r $ where $ p_i $ are prime, and $ r $ could be zero.\n\\end{proposition}\n\n\\begin{proof}\nUse induction on $ \\abs{n} $. The case $ \\abs{n} $ is trivial, so suppose $ \\abs{n} > 1 $. Then either $ \\abs{n} $ is prime, or $ \\abs{n} = ab $ for $ 1 < a, b < \\abs{n} $, and by induction each of $ a $ and $ b $ is a product of primes.\n\\end{proof}\n\n\\begin{theorem}\nEvery $ n \\in \\ZZ_{> 0} $ can be written as $ \\pm p_1 \\dots p_r $ where $ p_i $ are prime and are uniquely determined up to ordering.\n\\end{theorem}\n\n\\begin{proof}\nExistence is Proposition \\ref{prop:11}. Suppose that $ n = p_1 \\dots p_r = q_1 \\dots q_s $, with $ p_i $ and $ q_i $ prime. Then without loss of generality suppose $ r, s \\ge 1 $. Then $ p_1 \\mid p_1 \\dots p_r $, so $ p_1 \\mid q_1 \\dots q_s $. By Corollary \\ref{cor:8}, either $ p_1 \\mid q_1 $ or $ p_1 \\mid q_2 \\dots q_s $. Proceeding inductively, eventually $ p_1 \\mid q_i $ for some $ i $. Since $ q_i $ is prime this means $ p_1 = q_i $. We then have $ p_2 \\dots p_r = q_1 \\dots q_{i - 1}q_{i + 1} \\dots q_s $. Since this product is smaller than $ n $, by the inductive hypothesis we must have $ r - 1 = s - 1 $ and the $ p_i $, except $ p_1 $, are a rearrangement of the $ q_j $, except $ q_i $.\n\\end{proof}\n\n\\subsection{Linear diophantine equations}\n\nLet $ a, b, c \\in \\ZZ^* $. Want to solve\n$$ ax + by = c, \\qquad x, y \\in \\ZZ. $$\n\n\\begin{example*}\n$ 2x + 6y = 3 $ has no solutions.\n\\end{example*}\n\nIn general, there are no solutions if $ \\br{a, b} \\nmid c $. Suppose that $ \\br{a, b} \\mid c $. Then\n$$ ax + by = c \\qquad \\iff \\qquad \\dfrac{a}{\\br{a, b}}x + \\dfrac{b}{\\br{a, b}}y = \\dfrac{c}{\\br{a, b}}. $$\nBy Theorem \\ref{thm:6}, since $ \\br{a / \\br{a, b}, b / \\br{a, b}} = 1 $, we can find $ r, s \\in \\ZZ $ with $ ar / \\br{a, b} + bs / \\br{a, b} = 1 $, so\n$$ \\dfrac{a}{\\br{a, b}}\\br{\\dfrac{rc}{\\br{a, b}}} + \\dfrac{b}{\\br{a, b}}\\br{\\dfrac{sc}{\\br{a, b}}} = \\dfrac{c}{\\br{a, b}}. $$\nSo $ x = rc / \\br{a, b} $ and $ y = sc / \\br{a, b} $ is a solution. Then $ X $ and $ Y $ is another solution if and only if\n$$ \\dfrac{a}{\\br{a, b}}X + \\dfrac{b}{\\br{a, b}}Y = \\dfrac{a}{\\br{a, b}}x + \\dfrac{b}{\\br{a, b}}y \\qquad \\iff \\qquad \\dfrac{a}{\\br{a, b}} \\ \\Bigg| \\ y - Y, \\qquad \\dfrac{b}{\\br{a, b}} \\ \\Bigg| \\ X - x. $$\nSee that the solutions are exactly\n$$ X = x + \\dfrac{nb}{\\br{a, b}}, \\qquad Y = y - \\dfrac{na}{\\br{a, b}}. $$\n\n\\pagebreak\n\n\\section{Congruences and modular arithmetic}\n\n\\subsection{Congruences}\n\n\\begin{definition}\nLet $ n \\in \\ZZ^* $, usually $ n > 0 $. Let $ a, b \\in \\ZZ $. We say that $ a $ is \\textbf{congruent to $ b \\mod n $} if and only if $ n \\mid a - b $. Write $ a \\equiv b \\mod n $.\n\\end{definition}\n\n$ \\equiv $ is an equivalence relation, and we write $ \\ZZ / n\\ZZ $ for the equivalence classes, which is a ring.\n\n\\begin{example*}\nIf $ a \\equiv b \\mod n $ and $ c \\equiv d \\mod n $, then\n$$ a + c \\equiv b + d \\mod n, \\qquad ac \\equiv bd \\mod n. $$\n\\end{example*}\n\nIf $ a \\in \\ZZ $, we sometimes write $ \\overline{a} $ for the image of $ a $ in $ \\ZZ / n\\ZZ $.\n\n\\begin{example*}\nIf $ n = 12 $, then $ \\overline{25} = \\overline{1} $.\n\\end{example*}\n\nSo every element of $ \\ZZ / n\\ZZ $ is equal to $ \\overline{r} $ for some unique $ r \\in \\cbr{0, \\dots, n - 1} $. We often write\n$$ \\ZZ / n\\ZZ = \\cbr{0, \\dots, n - 1}. $$\n\n\\begin{example*}\nIf $ n = 6 $, we could write $ 3 + 4 = 1 $ and $ 3 \\times 4 = 0 $.\n\\end{example*}\n\nLet $ R $ be a commutative ring with unity. Then a \\textbf{unit} of $ R $ is an element $ x $ such that there exists $ y \\in R $ with $ xy = 1 $. Write $ R^\\times $ for the set of units in $ R $. This is a group under multiplication.\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ \\ZZ^\\times = \\cbr{\\pm 1} $.\n\\item $ \\QQ^\\times = \\QQ \\setminus \\cbr{0} = \\cbr{x \\in \\QQ \\st x \\ne 0} $.\n\\end{itemize}\n\\end{example*}\n\nWe want to understand $ \\unit{n} $. Which elements of $ \\cbr{0, \\dots, n - 1} $ are in $ \\unit{n} $? If $ r \\in \\ZZ $ and $ r \\in \\unit{n} $ then there exists $ s \\in \\ZZ $ such that $ rs \\equiv 1 \\mod n $. This implies that $ \\br{r, n} = 1 $. Conversely, if $ \\br{r, n} = 1 $, then there exist $ x, y \\in \\ZZ $ such that $ rx + ny = 1 $, that is $ rx \\equiv 1 \\mod n $, that is $ r $ is a unit. So\n$$ \\unit{n} = \\cbr{0 \\le i < n \\st \\br{i, n} = 1}. $$\n\n\\begin{example*}\nIf $ p $ is a prime, then\n$$ \\unit{p} = \\cbr{1, \\dots, p - 1}. $$\nSo $ \\ZZ / p\\ZZ $ is a ring with the property that every non-zero element has a multiplicative inverse, so it is a field. Another equivalent way to see this is to check that $ p\\ZZ $ is a maximal ideal of $ \\ZZ $.\n\\end{example*}\n\nThus every non-zero congruence class modulo $ p $ is a unit.\n\n\\subsection{Linear congruence equations}\n\n\\lecture{3}{Wednesday}{10/10/18}\n\nConsider the question of solving\n$$ ax \\equiv b \\mod c, \\qquad a, b, c, x \\in \\ZZ. $$\nThis is equivalent to solving\n$$ ax + cy = b, \\qquad y \\in \\ZZ. $$\nWe saw yesterday that this has solutions if and only if $ \\br{a, c} \\mid b $. Furthermore, there is a unique solution modulo $ c / \\br{a, c} $, because all the solutions are obtained by adding multiples of $ c / \\br{a, c} $ to our given $ x $, and subtracting the corresponding multiple of $ a / \\br{a, c} $ from $ y $. This implies that there are $ \\br{a, c} $ solutions to the original congruence modulo $ c $. If $ x_0 $ is one solution, the others are\n$$ x_0 + \\dfrac{cj}{\\br{a, c}}, \\qquad 0 \\le j < \\br{a, c}. $$\nIn particular, if $ \\br{a, c} = 1 $ then there is a unique solution to $ ax \\equiv b \\mod c $. Indeed $ a \\in \\unit{c} $, so it has an inverse $ a^{-1} $, and $ x \\equiv a^{-1}b \\mod c $ is the unique solution.\n\n\\pagebreak\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ 2x \\equiv 3 \\mod 6 $ has no solutions as $ \\br{2, 6} = 2 \\nmid 3 $.\n\\item $ 2x \\equiv 4 \\mod 6 $ if and only if $ x \\equiv 2 \\mod 3 $, which has solutions $ x \\equiv 2 \\mod 6 $ and $ x \\equiv 5 \\mod 6 $.\n\\end{itemize}\n\\end{example*}\n\n\\subsection{The Chinese remainder theorem}\n\n\\begin{theorem}[Chinese remainder theorem]\n\\label{thm:14}\nLet $ m_1, \\dots, m_n \\in \\ZZ_{> 0} $ be pairwise coprime. Then the natural map\n$$ \\ZZ / m_1 \\dots m_n\\ZZ \\xrightarrow{\\sim} \\ZZ / m_1\\ZZ \\times \\dots \\times \\ZZ / m_n\\ZZ $$\nis an isomorphism of rings. Consequently,\n$$ \\unit{m_1 \\dots m_n} \\xrightarrow{\\sim} \\unit{m_1} \\times \\dots \\times \\unit{m_n} $$\nis an isomorphism of abelian groups.\n\\end{theorem}\n\n\\begin{remark*}\nThis is false without the assumption that $ m_i $ pairwise coprime, such as $ m_1 = m_2 = 2 $.\n\\end{remark*}\n\n\\begin{proof}\nThe map\n$$ \\ZZ / m_1 \\dots m_n\\ZZ \\to \\ZZ / m_1\\ZZ \\times \\dots \\times \\ZZ / m_n\\ZZ $$\nis a ring homomorphism between two rings of order, or cardinality, $ m_1 \\dots m_n $. So to show that it is an isomorphism, it is enough to show that it is an injection, so we only need to check that the kernel is zero. So we need to know that if $ m_i \\mid N $ for all $ i $, then $ m_1 \\dots m_n \\mid N $. This is Corollary \\ref{cor:10}. For the second part, just use that if $ R $ and $ S $ are rings, then\n$$ \\br{R \\times S}^\\times \\cong R^\\times \\times S^\\times. $$\n\\end{proof}\n\nThe first part says that given any $ a_i \\in \\ZZ $, there is a unique $ x \\mod m_1 \\dots m_n $ with $ x \\equiv a_i \\mod m_i $. Write\n$$ M = m_1 \\dots m_n, \\qquad M_i = \\dfrac{M}{m_i}. $$\nChoose $ q_i $ such that $ q_iM_i \\equiv 1 \\mod m_i $, using $ \\br{M_i, m_i} = 1 $ because $ \\br{m_j, m_i} = 1 $ for all $ j \\ne i $. Then take\n$$ x = a_1q_1M_1 + \\dots + a_nq_nM_n. $$\nThen\n$$ x \\equiv a_iq_iM_i \\equiv a_i \\mod m_i. $$\n\n\\pagebreak\n\n\\section{The structure of \\texorpdfstring{$ \\unit{n} $}{Z/nZ}}\n\n\\subsection{The Euler \\texorpdfstring{$ \\Phi $}{Phi} function}\n\nLet $ \\Phi\\br{n} $ be the order of $ \\unit{n} $, that is\n$$ \\Phi\\br{n} = \\#\\cbr{1 \\le i < n \\st \\br{i, n} = 1}. $$\n\n\\begin{example*}\nIf $ p $ is prime, $ \\Phi\\br{p} = p - 1 $.\n\\end{example*}\n\n$ \\Phi $ is called \\textbf{Euler's $ \\Phi $ function}.\n\n\\begin{definition}\nLet $ f $ be a function on the positive integers. Say that $ f $ is \\textbf{strongly multiplicative} if\n$$ f\\br{mn} = f\\br{m}f\\br{n}, $$\nfor all $ m $ and $ n $. Say $ f $ is \\textbf{multiplicative} if this holds whenever $ \\br{m, n} = 1 $.\n\\end{definition}\n\n$ \\Phi $ is multiplicative by Theorem \\ref{thm:14}, because if $ \\br{m, n} = 1 $ then\n$$ \\unit{mn} \\xrightarrow{\\sim} \\unit{m} \\times \\unit{n}. $$\n$ \\Phi $ is not strongly multiplicative, since $ \\Phi\\br{4} = 2 \\ne 1 = \\Phi\\br{2}\\Phi\\br{2} $. Write $ n = \\prod_i p_i^{a_i} $, where $ p_i $ are distinct primes. Then $ \\Phi\\br{n} = \\prod_i \\Phi\\br{p_i^{a_i}} $. If $ p $ is prime then\n$$ \\Phi\\br{p^a} = \\#\\cbr{1 \\le i < p^a \\st \\br{i, p^a} = 1} = \\#\\cbr{1 \\le i < p^a \\st p \\nmid i} = p^a - p^{a - 1} = p^a\\br{1 - \\dfrac{1}{p}}. $$\nIf $ n = \\prod_i p_i^{a_i} $, then\n$$ \\Phi\\br{n} = \\prod_i \\Phi\\br{p_i^{a_i}} = \\prod_i p_i^{a_i}\\br{1 - \\dfrac{1}{p_i}} = n\\prod_i \\br{1 - \\dfrac{1}{p_i}} = n\\prod_{p \\mid n} \\br{1 - \\dfrac{1}{p}}. $$\n\n\\subsection{Euler's theorem}\n\n\\begin{theorem}[Euler's theorem]\n\\label{thm:16}\nIf $ \\br{a, n} = 1 $, then\n$$ a^{\\Phi\\br{n}} \\equiv 1 \\mod n. $$\n\\end{theorem}\n\n\\begin{proof}\nThis is equivalent to showing that $ \\overline{a}^{\\Phi\\br{n}} = 1 $ in $ \\unit{n} $. This is a group of order $ \\Phi\\br{n} $, so this is immediate from Lagrange's theorem.\n\\end{proof}\n\n\\begin{corollary}[Fermat's little theorem]\nIf $ p $ is prime and $ p \\nmid a $, then\n$$ a^{p - 1} \\equiv 1 \\mod p. $$\n\\end{corollary}\n\n\\begin{proof}\nTheorem \\ref{thm:16} with $ n = p $, so $ \\Phi\\br{n} = p - 1 $.\n\\end{proof}\n\nNext, want to understand the structure of $ \\unit{n} $. By Theorem \\ref{thm:14}, it is enough to study the case that $ n $ is a prime power. We will begin by considering the case that $ n $ is prime.\n\n\\begin{example*}\nLet $ n = 5 $. Then$ \\unit{5} = \\cbr{1, 2, 3, 4} $. This has order four. So it is either cyclic of order four or a product of two cyclic groups of order two. Since $ 2^2 = 4 $, $ 2^3 = 3 $, and $ 2^4 = 1 $, $ \\unit{5} $ is cyclic of order four.\n\\end{example*}\n\nNext, $ \\unit{p} $ is cyclic of order $ p - 1 $ for any prime $ p $.\n\n\\lecture{4}{Friday}{12/10/18}\n\n\\begin{definition}\nIf $ G $ is a group and $ g \\in G $ is an element, the \\textbf{order} of $ g $ is the least $ a \\ge 1 $ such that $ g^a = 1 $. In particular, if $ \\br{g, n} = 1 $, then we write $ \\ord_n g $ for the order of $ g $ in $ \\unit{n} $, the \\textbf{order of $ g $ modulo $ n $}.\n\\end{definition}\n\n\\begin{proposition}\n\\label{prop:19}\nIf $ G $ is a group and $ g $ is an element of order $ a $, then $ g^n = 1 $ if and only if $ a \\mid n $.\n\\end{proposition}\n\n\\begin{proof}\nIf $ n = ab $ then $ g^n = \\br{g^a}^b = 1^b = 1 $. Conversely, write $ n = ab + r $ with $ 0 \\le r < a $. Then $ g^r = 1 $ and since $ r < a $ we have $ r = 0 $.\n\\end{proof}\n\n\\pagebreak\n\nIn particular, if $ \\br{g, n} = 1 $, then $ g^{\\Phi\\br{n}} = 1 $, by Euler's theorem, so Proposition \\ref{prop:19} implies that $ \\ord_n g \\mid \\Phi\\br{n} $. We want to prove that if $ p $ is prime, then $ \\unit{p} $ is cyclic. Equivalently, we need to show that there exists $ g $ such that $ \\ord_p g = \\Phi\\br{p} = p - 1 $. We will do this by counting the number of elements of each order. The key point is that $ \\ZZ / p\\ZZ $ is a field. For any $ d \\ge 1 $, the elements of $ \\unit{p} $ of order dividing $ d $ are exactly the roots of the $ X^d - 1 $ in $ \\ZZ / p\\ZZ $, by Proposition \\ref{prop:19}.\n\n\\begin{example*}\nThe equation $ X^2 = 1 $ has exactly two solutions modulo $ p $ for any prime $ p $, namely $ \\pm 1 $, but it can have more modulo $ n $ if $ n $ is composite. For example, if $ n = 15 $, then $ 4 $ and $ 11 $ are also solutions, since $ X^2 - 1 \\equiv 0 \\mod n $ if and only if $ n \\mid \\br{X + 1}\\br{X - 1} $, for example $ 15 \\mid \\br{4 + 1}\\br{4 - 1} $.\n\\end{example*}\n\n\\begin{definition}\n$ g \\in \\ZZ $ with $ \\br{g, p} = 1 $ is a \\textbf{primitive root} if $ \\ord_p g = p - 1 $, that is $ \\unit{p} = \\abr{g} $.\n\\end{definition}\n\n\\begin{lemma}\n\\label{lem:21}\nLet $ R $ be a commutative ring, and let $ P\\br{X} \\in R\\sbr{X} $. If $ \\alpha \\in R $ has $ P\\br{\\alpha} = 0 $, then there exists $ Q\\br{X} \\in R\\sbr{X} $ such that $ P\\br{X} = \\br{X - \\alpha}Q\\br{X} $.\n\\end{lemma}\n\n\\begin{example*}\nIf $ R = \\ZZ / 15\\ZZ $, $ X^2 - 1 = \\br{X + 1}\\br{X - 1} = \\br{X + 4}\\br{X - 4} $.\n\\end{example*}\n\n\\begin{proof}\nInduction on $ \\deg P $, where $ \\deg P = 0 $ is obvious. Let $ \\deg P = d $, and assume the result holds for degree at most $ d - 1 $. Let $ P\\br{X} = cX^d + \\dots $ and $ S\\br{X} = P\\br{X} - cX^{d - 1}\\br{X - \\alpha} $. Then $ S\\br{X} $ has degree at most $ d - 1 $. Also $ S\\br{\\alpha} = 0 $. By induction, we can write $ S\\br{X} = \\br{X - \\alpha}R\\br{X} $. Set $ Q\\br{X} = cX^{d - 1} + R\\br{X} $. Then $ \\br{X - \\alpha}Q\\br{X} = cX^{d - 1}\\br{X - \\alpha} + S\\br{X} = P\\br{X} $.\n\\end{proof}\n\n\\begin{theorem}\n\\label{thm:22}\nLet $ F $ be a field. Let $ P\\br{X} $ be a polynomial in $ F\\sbr{X} $. Then $ P\\br{X} $ has at most $ d $ distinct roots in $ F $.\n\\end{theorem}\n\n\\begin{proof}\nInduction on $ d = \\deg P $, where $ d = 1 $ is obvious. If $ P $ has no roots, then we are done. Otherwise, let $ \\alpha $ be a root. By Lemma \\ref{lem:21}, $ P\\br{X} = \\br{X - \\alpha}Q\\br{X} $, and $ Q\\br{X} $ has degree $ d - 1 $, so we are done by induction.\n\\end{proof}\n\n\\begin{corollary}\n\\label{cor:23}\nLet $ d $ be any divisor of $ p - 1 $. Then there are exactly $ d $ elements of $ \\unit{p} $ of order dividing $ d $.\n\\end{corollary}\n\n\\begin{proof}\nWe have to show that $ X^d - 1 $ has exactly $ d $ roots in $ \\ZZ / p\\ZZ $. By Fermat's little theorem, $ X^{p - 1} - 1 $ has exactly $ p - 1 $ roots. Since $ d \\mid p - 1 $, we can write\n$$ X^{p - 1} - 1 = \\br{X^d - 1}\\br{\\br{X^d}^{\\tfrac{p - 1}{d} - 1} + \\dots + 1} = \\br{X^d - 1}Q\\br{X}, \\qquad \\deg Q = p - 1 - d. $$\nThen $ X^{p - 1} - 1 $ has exactly $ p - 1 $ roots, $ X^d - 1 $ has at most $ d $ roots, and $ Q\\br{X} $ has at most $ p - 1 - d $ roots, by Theorem \\ref{thm:22}. So $ X^d - 1 $ has exactly $ d $ roots.\n\\end{proof}\n\n\\begin{example*}\nLet $ p = 7 $. There are\n\\begin{itemize}\n\\item one element of order one,\n\\item two elements of order dividing two, so one element of order two,\n\\item three elements of order dividing three, so two elements of order three, and\n\\item six elements of order dividing six, so two elements of order six.\n\\end{itemize}\n\\end{example*}\n\n\\begin{lemma}\n\\label{lem:24}\nFor any $ n \\ge 1 $, we have\n$$ \\sum_{d \\mid n} \\Phi\\br{d} = n. $$\n\\end{lemma}\n\n\\begin{proof}\nFor each $ d \\mid n $, the elements of $ \\cbr{1, \\dots, n} $ with $ \\br{i, n} = n / d $ are exactly those of the form $ i = \\br{n / d}j $ for $ 1 \\le j \\le d $ and $ \\br{j, d} = 1 $. There are exactly $ \\Phi\\br{d} $ such elements. Since the $ n / d $ run over all the divisors of $ n $, we are done.\n\\end{proof}\n\n\\pagebreak\n\n\\begin{theorem}\n\\label{thm:25}\nLet $ p $ be prime, and let $ d \\mid p - 1 $. Then there are exactly $ \\Phi\\br{d} $ elements of $ \\unit{p} $ of order $ d $. In particular, there are $ \\Phi\\br{p - 1} $ primitive roots, and $ \\unit{p} $ is cyclic.\n\\end{theorem}\n\n\\begin{proof}\nInduction on $ d $, where $ d = 1 $ is obvious. Assume the result holds for all $ d' \\mid d $ and $ d' \\ne d $. Then by Lemma \\ref{lem:24},\n$$ \\Phi\\br{d} = d - \\sum_{d' \\mid d, \\ d' \\ne d} \\Phi\\br{d'}. $$\nNow use the inductive hypothesis and Corollary \\ref{cor:23}.\n\\end{proof}\n\n\\lecture{5}{Tuesday}{16/10/18}\n\n\\begin{proposition}\nLet $ p $ be an odd prime and $ n \\ge 1 $. Then $ \\unit{p^n} $ is cyclic.\n\\end{proposition}\n\n\\begin{proof}\nConsider three cases.\n\\begin{itemize}[leftmargin=0.5in]\n\\item[$ n = 1 $.] Theorem \\ref{thm:25}.\n\\item[$ n = 2 $.] Let $ g $ be a primitive root modulo $ p $. Claim that either $ g^{p - 1} \\not\\equiv 1 \\mod p^2 $ and $ g $ is a generator for $ \\unit{p^2} $, or $ g^{p - 1} \\equiv 1 \\mod p^2 $ and $ g + p $ is a generator for $ \\unit{p^2} $. Either way, $ \\unit{p^2} $ is cyclic. Suppose firstly that\n$$ g^{p - 1} \\not\\equiv 1 \\mod p^2. $$\nThen $ \\#\\unit{p^2} = \\Phi\\br{p^2} = p\\br{p - 1} $. So $ \\ord_{p^2} g \\mid p\\br{p - 1} $. On the other hand, $ g^{\\ord_{p^2} g} \\equiv 1 \\mod p^2 $, so $ g^{\\ord_{p^2} g} \\equiv 1 \\mod p $, so $ p - 1 \\mid \\ord_{p^2} g $, because $ \\ord_p g = p - 1 $ by assumption. But $ \\ord_{p^2} g \\ne p - 1 $, as $ g^{p - 1} \\not\\equiv 1 \\mod p^2 $. So $ \\ord_{p^2} g = p\\br{p - 1} $, as required. Suppose now that\n$$ g^{p - 1} \\equiv 1 \\mod p^2. $$\nIt suffices to show that $ \\br{g + p}^{p - 1} \\not\\equiv 1 \\mod p^2 $, as we can then apply the analysis above with $ g + p $ in place of $ g $. By the binomial theorem,\n$$ \\br{g + p}^{p - 1} \\equiv g^{p - 1} + \\br{p - 1}g^{p - 2}p \\equiv 1 + \\br{p - 1}g^{p - 2}p \\mod p^2. $$\nSince $ p \\nmid \\br{p - 1}g^{p - 2} $, $ \\br{g + p}^{p - 1} \\not\\equiv 1 \\mod p^2 $, as required.\n\\item[$ n \\ge 2 $.] It suffices to show that if $ \\ord_{p^2} g = p\\br{p - 1} $, then $ \\ord_{p^n} g = p^{n - 1}\\br{p - 1} $. We do this by induction on $ n $. So assume that $ \\ord_{p^n} g = p^{n - 1}\\br{p - 1} $. Then $ \\ord_{p^n} g \\mid \\ord_{p^{n + 1}} g $, and $ \\ord_{p^{n + 1}} g \\mid \\Phi\\br{p^{n + 1}} = p^n\\br{p - 1} $. So either $ \\ord_{p^{n + 1}} g = p^n\\br{p - 1} $, or $ \\ord_{p^{n + 1}} g = p^{n - 1}\\br{p - 1} $. So we need to show that\n$$ g^{p^{n - 1}\\br{p - 1}} \\not\\equiv 1 \\mod p^{n + 1}. $$\nTo do this, consider $ g^{p^{n - 2}\\br{p - 1}} $ modulo $ p^{n - 1} $ and modulo $ p^n $. Since $ \\Phi\\br{p^{n - 1}} = p^{n - 2}\\br{p - 1} $, by Euler's theorem, $ g^{p^{n - 2}\\br{p - 1}} \\equiv 1 \\mod p^{n - 1} $. Write $ g^{p^{n - 2}\\br{p - 1}} = 1 + p^{n - 1}t $. Since $ \\ord_{p^n} g = p^{n - 1}\\br{p - 1} $ by assumption, $ g^{p^{n - 2}\\br{p - 1}} \\not\\equiv 1 \\mod p^n $, that is $ p \\nmid t $. Then\n\\begin{align*}\ng^{p^{n - 1}\\br{p - 1}}\n& = \\br{g^{p^{n - 2}\\br{p - 1}}}^p\n= \\br{1 + p^{n - 1}t}^p\n= 1 + p^nt + \\binom{p}{2}p^{2\\br{n - 1}}t^2 + \\dots + p^{p\\br{n - 1}}t^p \\\\\n& \\equiv 1 + p^nt \\mod p^{n + 1},\n\\end{align*}\nsince $ r\\br{n - 1} \\ge n + 1 $ if and only if $ \\br{r - 1}n \\ge r + 1 $ and $ p > 2 $, so\n$$ p^{n + 1} \\ \\Bigg| \\ p^{2n - 1} = p^{2\\br{n - 1} + 1} \\ \\Bigg| \\ \\binom{p}{2}p^{2\\br{n - 1}}. $$\nSo $ g^{p^{n - 1}\\br{p - 1}} \\not\\equiv 1 \\mod p^{n + 1} $, because $ p \\nmid t $.\n\\end{itemize}\n\\end{proof}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ \\unit{2} = \\cbr{1} $.\n\\item $ \\unit{4} = \\cbr{1, 3} $ is cyclic of order two, with $ 3 $ as a generator.\n\\item $ \\unit{8} = \\cbr{1, 3, 5, 7} $ is not cyclic, since $ 1^2 \\equiv 3^2 \\equiv 5^2 \\equiv 7^2 \\equiv 1 \\mod 8 $, so every element has order two.\n\\end{itemize}\n\\end{example*}\n\n\\pagebreak\n\n\\begin{lemma}\n\\label{lem:27}\nFor $ n \\ge 0 $ we have\n$$ 5^{2^n} \\equiv 1 + 2^{n + 2} \\mod 2^{n + 3}. $$\n\\end{lemma}\n\n\\begin{proof}\nInduction on $ n $, where $ n = 0 $ is obvious. Assume that $ 5^{2^n} = 1 + 2^{n + 2}t $ with $ t $ odd. Then\n$$ 5^{2^{n + 1}} = \\br{1 + 2^{n + 1}t}^2 = 1 + 2^{n + 3}t + 2^{2\\br{n + 2}}t^2 = 1 + 2^{n + 3}\\br{t + 2^{n + 1}t^2}, $$\nwhere $ t + 2^{n + 1}t^2 $ is odd.\n\\end{proof}\n\n\\begin{proposition}\nIf $ n \\ge 2 $ then there is an isomorphism\n$$ \\unit{2^n} \\xrightarrow{\\sim} \\ZZ / 2\\ZZ \\times \\ZZ / 2^{n - 2}\\ZZ. $$\nIn particular, if $ n \\ge 3 $, then $ \\unit{2^n} $ is not cyclic.\n\\end{proposition}\n\n\\begin{proof}\nLet $ \\abr{g} $ denote the group $ \\cbr{1, \\dots, g^{\\ord g - 1}} $ generated by $ g $. Consider the natural map\n$$ \\abr{-1} \\times \\abr{5} \\to \\unit{2^n}. $$\nThis is injective, because if $ \\pm 1\\br{5}^s \\equiv 1 \\mod 2^n $ then in particular $ \\pm 1\\br{5}^s \\equiv 1 \\mod 4 $ so $ \\pm 1 \\equiv 1 \\mod 4 $, so we must have $ 5^s \\equiv 1 \\mod 2^n $, that is $ 5^s = 1 $ in $ \\abr{5} $. Then $ \\abr{-1} $ has order $ 2 $ and $ \\abr{5} $ has order $ \\ord_{2^n} 5 = 2^{n - 2} $ by Lemma \\ref{lem:27}. So $ \\abr{-1} \\times \\abr{5} $ has order $ 2\\br{2^{n - 2}} = 2^{n - 1} = \\Phi\\br{2^n} = \\#\\unit{2^n} $. So the map $ \\abr{-1} \\times \\abr{5} \\to \\unit{2^n} $ is an injection of groups of the same order, so it is a bijection.\n\\end{proof}\n\n\\begin{theorem}\n$ \\unit{n} $ is cyclic if and only if either\n\\begin{itemize}\n\\item $ n = 1, 2, 4 $,\n\\item $ n = p^r $ for $ p > 2 $ prime and $ r \\ge 1 $, or\n\\item $ n = 2p^r $ for $ p > 2 $ prime and $ r \\ge 1 $.\n\\end{itemize}\n\\end{theorem}\n\n\\lecture{6}{Wednesday}{17/10/18}\n\nPrimitive roots are generators of $ \\unit{n} $. Find them in practice by guessing small values of $ g $, and seeing if $ g $ is a generator. There are $ \\Phi\\br{p - 1} $ primitive roots, which means that you have a high probability of success. Could work out $ 1, \\dots, g^{p - 2} $ and check these are distinct. This would be inefficient. Better is to check for some prime $ q \\mid p - 1 $ whether $ g^{\\br{p - 1} / q} = 1 $ or not. This works, because if $ g^{\\br{p - 1} / q} = 1 $ then $ g $ is not a primitive root, while if $ g^{\\br{p - 1} / q} \\ne 1 $ then $ \\ord_p g \\mid p - 1 $ and $ \\ord_p g \\nmid \\br{p - 1} / q $. If this holds for all $ q \\mid p - 1 $, then $ \\ord_p g = p - 1 $, because otherwise it would be a proper divisor, and so would divide $ \\br{p - 1} / q $ for some prime $ q \\mid p - 1 $.\n\n\\begin{example*}\nLet $ p = 31 $, so $ p - 1 = 30 = \\br{2}\\br{3}\\br{5} $. Then $ g $ is a primitive root if and only if\n$$ g^{15} \\ne 1, \\qquad g^{10} \\ne 1, \\qquad g^{6} \\ne 1. $$\n\\begin{itemize}\n\\item Is $ 2 $ a primitive root? $ 2^2 = 4, 2^4 = 16, 2^6 = 2 $, but $ 2^{10} = 2^{15} = 1 $ because $ 2^5 = 32 = 1 $.\n\\item How about $ 3 $? $ 3^2 = 9, 3^4 = 19, 3^6 = 16, 3^8 = 20, 3^{10} = 25, 3^{15} = 30 $. So $ 3 $ is a primitive root modulo $ 31 $.\n\\end{itemize}\n\\end{example*}\n\n\\pagebreak\n\n\\section{Primality testing and factorisation}\n\nThe idea is that testing whether $ n \\in \\ZZ $ is prime is easy. Factoring $ n $ is expected to be hard. Easy here means that there is an algorithm to check whether $ n $ is prime or not which runs in time polynomial in $ \\log n $. It is known that a deterministic algorithm exists to do this, the \\textbf{Agrawal-Kayal-Saxena (AKS) algorithm}, in 2005. We will see an algorithm that runs faster than this in practice. On the other hand, for factoring there are algorithms which are better than exponential in $ \\log n $, but there is nothing close to polynomial time, and the general expectation is that no such algorithm should exist.\n\n\\subsection{Factorisation}\n\nHow do we factor three digit numbers, or small four digit numbers, say at most $ 400 $ if we wanted to factor with a paper or a calculator? If $ n \\le 400 $ and $ n $ is composite, then it has a prime factor at most $ \\sqrt{400} = 20 $, since if $ d \\mid n $ then $ d\\br{n / d} = n $, so either $ d \\le \\sqrt{n} $ or $ n / d \\le \\sqrt{n} $. So you only have to be able to check for divisibility by\n$$ 2, \\quad 3, \\quad 5, \\quad 7, \\quad 11, \\quad 13, \\quad 17, \\quad 19. $$\n\\begin{itemize}[leftmargin=0.75in]\n\\item[$ 2, 5 $.] Checking for divisibility is easy, by just looking at the last digit.\n\\item[$ 3, 11 $.] Use that $ 10 \\equiv 1 \\mod 3 $ and $ 10 \\equiv -1 \\mod 3 $. So\n$$ \\sum_i a_i10^i \\equiv \\sum_i a_i \\mod 3, \\qquad \\sum_i a_i10^i \\equiv \\sum_i a_i\\br{-1}^i \\mod 11. $$\nSo you can check divisibility by $ 3 $, or $ 9 $, by checking for the sum of the digits, and $ 11 $ by taking the alternating sum.\n\\item[$ 7 $.] $ 10x + y \\equiv 0 \\mod 7 $ if and only if $ -2\\br{10x + y} \\equiv 0 \\mod 7 $, if and only if $ x - 2y \\equiv 0 \\mod 7 $.\n\\item[$ 13, 17, 19 $.] There are no good tests.\n\\end{itemize}\nIf $ n \\le 400 $ and $ n $ is not divisible by $ 2, 3, 5, 7, 11 $, then the smallest prime factor of $ n $ is at least $ 13 $. Since $ 13^3 > 400 $, it can have at most two prime factors. So if you want to factor numbers at most $ 400 $, you only have to remember a short list\n$$ 13^2, \\quad 13\\br{17}, \\quad 13\\br{19}, \\quad 13\\br{23}, \\quad 13\\br{29}, \\quad 17^2, \\quad 17\\br{19}, \\quad 17\\br{23}, \\quad 19^2. $$\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ 143 \\equiv 1 - 4 + 3 \\equiv 0 \\mod 11 $.\n\\item $ 144 \\equiv 1 + 4 + 4 \\equiv 0 \\mod 9 $.\n\\item $ 154 \\equiv 15 - 2\\br{4} = 7 \\equiv 0 \\mod 7 $.\n\\end{itemize}\n\\end{example*}\n\n\\lecture{7}{Friday}{19/10/18}\n\nFactor four digit numbers by an algorithm due to Fermat. The idea is to first check for small prime factors by hand, say $ p = 2, \\dots, 19 $. If $ n $ is composite and does not have any small factors, then the prime factors of $ n $ should be close to $ \\sqrt{n} $. If $ n = ab $ for $ a $ and $ b $ odd and $ a \\le b $, then\n$$ n = ab = \\br{\\dfrac{a + b}{2}}^2 - \\br{\\dfrac{b - a}{2}}^2, \\qquad \\br{\\dfrac{a + b}{2}}^2 - n = \\br{\\dfrac{b - a}{2}}^2. $$\nIf you know $ \\br{a + b} / 2 $ and $ \\br{b - a} / 2 $, you can recover $ a $ and $ b $. So take $ m $ such that $ m^2 \\le n < \\br{m + 1}^2 $. If $ n = m^2 $, done. Otherwise check if $ \\br{m + i}^2 - n $ is a square for increasing $ i $.\n\n\\begin{example*}\nLet $ n = 6077 $. Then $ 77^2 < 6077 < 78^2 $, so\n\\begin{align*}\n78^2 - 6077 & = 7, \\\\\n79^2 - 6077 & = 164, \\\\\n80^2 - 6077 & = 323, \\\\\n81^2 - 6077 & = 484 = 22^2.\n\\end{align*}\nThus $ 6077 = 81^2 - 22^2 = \\br{103}\\br{59} $.\n\\end{example*}\n\n\\pagebreak\n\nThere exist algorithms for factoring $ n $ which run in better than exponential time in $ \\log n $, such as the quadratic sieve and the general number field sieve.\n\n\\begin{example*}\nLet $ n = 1649 $. Then $ 40^2 < 1649 < 41^2 $, so\n\\begin{align*}\n41^2 - 1649 & = 32 = 2^5, \\\\\n42^2 - 1649 & = 115, \\\\\n43^2 - 1649 & = 200 = \\br{2}^3\\br{5}^2.\n\\end{align*}\nSince $ 41^2 \\equiv 2^5 \\mod 1649 $ and $ 43^2 \\equiv \\br{2}^3\\br{5}^2 \\mod 1649 $,\n$$ 80^2 \\equiv \\br{41}^2\\br{43}^2 = 1763^2 \\equiv 114^2 \\mod 1649. $$\nThen\n$$ 0 \\equiv 114^2 - 80^2 = \\br{194}\\br{34} = \\br{2}^2\\br{17}\\br{97} \\mod 1649. $$\nIn fact, $ 1649 = \\br{17}\\br{97} $. Better for this last step would be to have computed\n$$ \\br{194, 1649} = 97, \\qquad \\br{34, 1649} = 17. $$\nCan do this quickly using Euclid's algorithm. To make this into an efficient algorithm, need to have a way given $ x_1, \\dots, x_r $ to find a subset whose product is a square. If we know the prime factorisation for the $ x_i $, we can write\n$$ x_i = p_1^{a_{i1}} \\dots p_k^{a_{ik}}. $$\nWant to choose $ \\epsilon_i = 0, 1 $ such that $ \\prod_{i = 1}^r x_i^{\\epsilon_i} $ is a square. Equivalently, for each $ j $, want the exponent of $ p_j $ to be even, that is\n$$ \\sum_{i = 1}^r \\epsilon_ia_{ij} \\equiv 0 \\mod 2. $$\nLet\n$$ x_1 = 2^5, \\qquad x_2 = \\br{5}\\br{23}, \\qquad x_3 = \\br{2}^3\\br{5}^2, \\qquad p_1 = 2, \\qquad p_2 = 5, \\qquad p_3 = 23. $$\nIgnore all numbers with a large prime factor, so here ignore $ 23 $. Then\n$$ \\onebytwo{\\epsilon_1}{\\epsilon_2}\\twobytwo{5}{0}{3}{2} \\equiv \\onebytwo{0}{0} \\mod 2 \\qquad \\iff \\qquad \\onebytwo{\\epsilon_1}{\\epsilon_2}\\twobytwo{1}{0}{1}{0} = \\onebytwo{0}{0} $$\nin $ \\ZZ / 2\\ZZ $, a field $ \\FF_2 $, that is $ \\epsilon_1 + \\epsilon_2 = 0 $, so $ \\epsilon_1 = \\epsilon_2 = 1 $.\n\\end{example*}\n\nThis step, solving linear equations in $ \\ZZ / 2\\ZZ $, can be done efficiently. The remaining difficulty is to find a supply of $ m \\in \\ZZ $ such that $ m^2 - n $ has only small prime factors. The idea is that if we fix a list of small primes to start with, we get congruence conditions on $ m $. It turns out that there is a straightforward algorithm for solving $ m^2 \\equiv n \\mod p $. This gives two possible values for $ m \\mod p $. If you do this for lots of primes $ p $, you get a supply of congruence conditions for $ m $, so you can eliminate ever considering $ m $ such that $ m^2 - n $ has large prime factors.\n\n\\begin{example*}\n$ m^2 = 1649 \\equiv 2 \\mod 3 $ has no solutions.\n\\end{example*}\n\n\\subsection{Testing primality}\n\n\\lecture{8}{Tuesday}{23/10/18}\n\nEuler's theorem states that if $ \\br{a, n} = 1 $ then $ a^{\\Phi\\br{n}} \\equiv 1 \\mod n $. In particular if $ p $ is prime then $ a^{p - 1} \\equiv 1 \\mod p $ for $ 1 \\le a \\le p - 1 $. In particular, if $ 2^{n - 1} \\not\\equiv 1 \\mod n $, then $ n $ cannot be prime. The problem is that there exists $ n $ composite such that $ a^{n - 1} \\equiv 1 \\mod n $ for all $ \\br{a, n} = 1 $, the \\textbf{Carmichael numbers}. It is known that infinitely many of these exist. The \\textbf{Miller-Rabin test} is a test for whether odd $ n \\in \\ZZ $ is prime or not. Today let $ n \\equiv 3 \\mod 4 $. Example sheet is $ n \\equiv 1 \\mod 4 $.\n\n\\begin{lemma}\n\\label{lem:30}\nLet $ n > 1 $ be congruent to $ 3 \\mod 4 $. Then $ n $ is prime if and only if\n$$ a^{\\tfrac{n - 1}{2}} \\equiv \\pm 1 \\mod n, \\qquad \\br{a, n} = 1. $$\n\\end{lemma}\n\n\\pagebreak\n\n\\begin{proof}\n\\hfill\n\\begin{itemize}\n\\item If $ n $ is prime, then $ a^{n - 1} \\equiv 1 \\mod n $ by Fermat's little theorem, so $ \\br{a^{\\br{n - 1} / 2}}^2 \\equiv 1 \\mod n $, so $ a^{\\br{n - 1} / 2} \\equiv \\pm 1 \\mod n $.\n\\item Suppose firstly that $ n = p^k $ with $ p $ prime, and $ k \\ge 2 $. Try\n$$ a = 1 + p. $$\nThen\n$$ a^{\\tfrac{n - 1}{2}} \\equiv 1 + \\br{\\dfrac{n - 1}{2}}p \\mod p^2, $$\nby the binomial theorem. If $ a^{\\br{n - 1} / 2} \\equiv \\pm 1 \\mod n $, then\n$$ \\pm 1 \\equiv a^{\\tfrac{n - 1}{2}} \\equiv 1 + \\br{\\dfrac{n - 1}{2}}p \\equiv 1 \\mod p, $$\nso\n$$ 1 \\equiv 1 + \\br{\\dfrac{n - 1}{2}}p \\mod p^2, $$\nthen $ p \\mid \\br{n - 1} / 2 $, so $ p \\mid n - 1 $. But $ p \\mid n $, a contradiction.\n\\item The remaining case is that $ n $ is composite but not a power of a prime. Write $ n = rs $ for $ r, s > 1 $, and odd, and $ \\br{r, s} = 1 $. By the Chinese remainder theorem,\n$$ \\ZZ / n\\ZZ \\cong \\ZZ / r\\ZZ \\times \\ZZ / s\\ZZ. $$\nChoose $ a $ such that\n$$ a \\equiv -1 \\mod r, \\qquad a \\equiv 1 \\mod s. $$\nThen $ \\br{a, r} = \\br{a, s} = 1 $, so $ \\br{a, n} = 1 $. Since $ n \\equiv 3 \\mod 4 $, $ \\br{n - 1} / 2 $ is odd, so\n$$ a^{\\tfrac{n - 1}{2}} \\equiv -1 \\mod r, \\qquad a^{\\tfrac{n - 1}{2}} \\equiv 1 \\mod s. $$\nSo $ a^{\\br{n - 1} / 2} \\not\\equiv \\pm 1 \\mod n $.\n\\end{itemize}\n\\end{proof}\n\n\\begin{lemma}\n\\label{lem:31}\nSuppose that $ n \\equiv 3 \\mod 4 $ is composite. Then the set of $ a \\in \\unit{n} $ which satisfy $ a^{\\br{n - 1} / 2} \\equiv \\pm 1 \\mod n $ is a proper subgroup of $ \\unit{n} $.\n\\end{lemma}\n\n\\begin{proof}\nCertainly $ 1^{\\br{n - 1} / 2} \\equiv 1 \\mod n $. If $ a^{\\br{n - 1} / 2} \\equiv \\pm 1 \\mod n $ and $ b^{\\br{n - 1} / 2} \\equiv \\pm 1 \\mod n $,\n$$ \\br{ab}^{\\tfrac{n - 1}{2}} \\equiv a^{\\tfrac{n - 1}{2}}b^{\\tfrac{n - 1}{2}} \\equiv \\br{\\pm 1}\\br{\\pm 1} \\equiv \\pm 1 \\mod n, \\qquad \\br{a^{-1}}^{\\tfrac{n - 1}{2}} \\equiv \\br{a^{\\tfrac{n - 1}{2}}}^{-1} \\equiv \\br{\\pm 1}^{-1} \\equiv \\pm 1 \\mod n. $$\nSo this set is a subgroup of $ \\unit{n} $. It is a proper subgroup by Lemma \\ref{lem:30}.\n\\end{proof}\n\n\\begin{corollary}\nAt most half the elements of $ \\unit{n} $ satisfy $ a^{\\br{n - 1} / 2} \\equiv \\pm 1 \\mod n $.\n\\end{corollary}\n\n\\begin{proof}\nThe set of such elements is a proper subgroup of $ \\unit{n} $ by Lemma \\ref{lem:31}, so it has index at least two.\n\\end{proof}\n\nIn fact, with a bit more work, you can improve this to show that at least $ \\tfrac{3}{4} $ of the numbers $ 1 \\le a \\le n - 1 $ satisfy $ a^{\\br{n - 1} / 2} \\not\\equiv \\pm 1 \\mod n $. So if you randomly choose numbers $ 1 \\le a \\le n - 1 $ $ x $ times, and $ n $ is composite, the probability that you find some $ a $ with $ a^{\\br{n - 1} / 2} \\not\\equiv \\pm 1 \\mod n $ is at least $ 1 - \\br{\\tfrac{1}{4}}^x $. This gives a probabilistic algorithm to check if $ n $ is prime in polynomial time. If you assume the generalised Riemann hypothesis (GRH) you can find some\n$$ 1 \\le a \\le \\left\\lceil 2 \\br{\\log n}^2 \\right\\rceil, \\qquad a^{\\tfrac{n - 1}{2}} \\not\\equiv \\pm 1 \\mod n. $$\nIn practice it is even better.\n\n\\begin{example*}\nIf $ n < 341550071728321 $, then one of $ a = 2, 3, 5, 7, 11, 13, 17 $ will work.\n\\end{example*}\n\n\\pagebreak\n\n\\section{Public-key cryptography}\n\nPublic-key cryptography is private communication and identity verification.\n\n\\subsection{Messages as sequences of classes modulo \\texorpdfstring{$ n $}{n}}\n\nHow do we turn messages into numbers in $ \\ZZ / n\\ZZ $? The idea is to choose $ n $ very large. Say $ n > 2^{8k} $. Write down your message. Break it up into strings of at most $ k $ characters. Encode each character as an $ 8 $ bit binary number. String these integers together to get an $ 8k $ bit binary number. Regard that as an integer modulo $ n $.\n\n\\subsection{The Rivest-Shamir-Adleman (RSA) algorithm}\n\nNow apply some function $ f : \\ZZ / n\\ZZ \\to \\ZZ / n\\ZZ $, and then tell whoever you are trying to communicate with the result of this computation. Then they should apply some other function $ g : \\ZZ / m\\ZZ \\to \\ZZ / n\\ZZ $, to get back the number you started with. So want $ f $ to be injective. Want to be able to make $ f $ public without making $ g $ public. The idea is to choose two large prime numbers $ p $ and $ q $ and set $ n = pq $. Choose $ \\br{e, \\Phi\\br{n}} = 1 $. Find $ d $ such that\n$$ de = 1 \\mod \\Phi\\br{n} = \\br{p - 1}\\br{q - 1} = n - \\br{p + q} + 1. $$\nPublish $ n $ and $ e $, and you keep $ p, q, \\Phi\\br{n}, d $ secret. Let $ f\\br{x} = x^e \\mod n $ and $ g\\br{x} = x^d \\mod n $. Then\n$$ \\br{x^e}^d \\equiv x^{de} \\equiv x \\mod n, $$\nbecause $ de \\equiv 1 \\mod \\Phi\\br{n} $ and $ x^{\\Phi\\br{n}} \\equiv 1 \\mod n $. So if someone wants to send you a message $ c \\in \\ZZ / n\\ZZ $, they compute $ c^e \\in \\ZZ / n\\ZZ $, and send it to you. To decode it, you compute\n$$ \\br{c^e}^d \\equiv c^{de} \\equiv c \\mod n. $$\nThis assumes that $ \\br{c, n} = 1 $, but the probability of this is extremely high. The prevailing assumption is that with only the information $ n $ and $ e $, it is hopeless to discover $ d $, or to find any other way of recovering $ c $ from $ c^e $.\n\n\\lecture{9}{Wednesday}{24/10/18}\n\nLecture 9 is a problems class.\n\n\\subsection{Signing with RSA}\n\n\\lecture{10}{Friday}{26/10/18}\n\nIf you have functions $ f, g : \\ZZ / n\\ZZ \\to \\ZZ / n\\ZZ $ with $ f \\circ g = g \\circ f = \\id $, then you can also verify your identity, that is sign messages. Again, make $ f $ public, and any time you publish a message $ m $, you also publish $ g\\br{m} $. Then anyone can apply $ f $ to $ g\\br{m} $ to recover $ m = f\\br{g\\br{m}} $, but without $ g $, no one can forge your signature.\n\n\\subsection{Discrete logarithms}\n\nSuppose that $ n $ is prime, or more generally that $ \\unit{n} $ is cyclic. Let $ g $ be a generator for this group, that is a primitive root. For any $ a \\in \\unit{n} $, we can write $ a = g^m $ for some unique $ 0 \\le m < \\Phi\\br{n} $. We call $ m $ the \\textbf{discrete logarithm} of $ a $ to base $ g $, and write $ m = \\log_g\\br{a} $.\n\n\\begin{example*}\nIf you want to solve\n$$ x^r \\equiv a \\mod n, $$\nwrite $ x = g^y $, and the congruence becomes equivalent to\n$$ yr \\equiv \\log_g\\br{a} \\mod \\Phi\\br{n}. $$\n\\end{example*}\n\nUnfortunately, or fortunately for cryptography, computing $ \\log_g $ is believed to be a hard problem. In particular, there is no known polynomial time algorithm.\n\n\\begin{example*}\nImagine that you have a system where you need to store passwords for different users, but you do not want to store the actual passwords. One way to do this is to choose a large prime $ p $ and a primitive root $ g $, and if someone inputs $ x $ as their password, you store $ g^x \\mod p $. If they later input $ y $, you compute $ g^y $, and check it matches what you stored. If it does then $ y \\equiv x \\mod p - 1 $.\n\\end{example*}\n\n\\pagebreak\n\n\\section{Quadratic reciprocity}\n\n\\subsection{Quadratic residues}\n\nLet $ p $ be a prime number.\n\n\\begin{definition}\nIf $ \\br{a, p} = 1 $, then $ a $ is a \\textbf{quadratic residue (QR)} if and only if there is a solution to $ x^2 \\equiv a \\mod p $. If $ \\br{a, p} = 1 $ and is not a QR, it is called a \\textbf{quadratic non-residue (QNR)}.\n\\end{definition}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item If $ p = 2 $, $ 1 $ is a QR.\n\\item If $ p = 3 $, $ 1 $ is a QR, and $ -1 $ is a QNR, since $ 1^2 \\equiv \\br{-1}^2 \\equiv 1 \\mod 3 $.\n\\item If $ p = 5 $, $ 1 $ and $ 4 $ are QRs, and $ 2 $ and $ 3 $ are QNRs, since $ 1^2 \\equiv 4^2 \\equiv 1 \\mod 5 $ and $ 2^2 \\equiv 3^2 \\equiv 4 \\mod 5 $.\n\\end{itemize}\n\\end{example*}\n\n\\begin{lemma}\n\\label{lem:34}\nIf $ p > 2 $ then there are exactly $ \\br{p - 1} / 2 $ QRs, and $ \\br{p - 1} / 2 $ QNRs modulo $ p $.\n\\end{lemma}\n\n\\begin{proof}\nThe map\n$$ \\function{\\unit{p}}{\\unit{p}}{x}{x^2} $$\nis a group homomorphism with kernel $ \\cbr{\\pm 1} $. So the image has order $ \\br{p - 1} / 2 $, and the image is exactly the QRs.\n\\end{proof}\n\n\\begin{proposition}\n\\label{prop:35}\nSuppose that $ \\br{a, p} = \\br{b, p} = 1 $. Then\n\\begin{itemize}\n\\item if $ a $ and $ b $ are both QRs, then $ ab $ is a QR,\n\\item if one of $ a $ and $ b $ is a QR and one is a QNR, then $ ab $ is a QNR, and\n\\item if $ a $ and $ b $ are both QNRs, then $ ab $ is a QR.\n\\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\nLet $ H $ be the image of\n$$ \\function{\\unit{p}}{\\unit{p}}{x}{x^2}, $$\nthat is $ H $ is the QRs. Then $ \\unit{p} / H $ is a group of order two by Lemma \\ref{lem:34}, so it is cyclic of order two. This statement is a restatement of Proposition \\ref{prop:35}, since $ \\unit{p} = H \\cup 1 + H $.\n\\end{proof}\n\n\\begin{definition}\nLet $ a \\in \\ZZ $ and $ p $ a prime. Then the \\textbf{Legendre symbol} is\n$$ \\jacobi{a}{p} =\n\\begin{cases}\n1 & a \\ \\text{is a QR modulo} \\ p \\\\\n0 & p \\mid a \\\\\n-1 & a \\ \\text{is a QNR modulo} \\ p\n\\end{cases}.\n$$\n\\end{definition}\n\nProposition \\ref{prop:35} can be restated as saying that\n$$ \\function{\\unit{p}}{\\cbr{\\pm 1}}{a}{\\jacobi{a}{p}} $$\nis a group homomorphism, that is\n$$ \\jacobi{ab}{p} = \\jacobi{a}{p}\\jacobi{a}{p}. $$\nEven holds if we do not assume that $ \\br{a, p} = \\br{b, p} = 1 $.\n\n\\lecture{11}{Tuesday}{30/10/18}\n\n\\begin{theorem}[Euler's criterion]\nIf $ p $ is an odd prime, and $ p \\nmid a $, then\n$$ \\jacobi{a}{p} \\equiv a^{\\tfrac{p - 1}{2}} \\mod p. $$\n\\end{theorem}\n\n\\pagebreak\n\n\\begin{proof}\nLet $ g $ be a primitive root modulo $ p $, and write $ a \\equiv g^r \\mod p $ for $ 0 \\le r < p - 1 $. Now $ \\br{g^{\\br{p - 1} / 2}}^2 = g^{p - 1} \\equiv 1 \\mod p $. So $ g^{\\br{p - 1} / 2} \\equiv \\pm 1 \\mod p $. Since $ g $ is a primitive root, $ g^{\\tfrac{p - 1}{2}} \\not\\equiv 1 \\mod p $, so $ g^{\\br{p - 1} / 2} \\equiv -1 \\mod p $. So\n$$ a^{\\tfrac{p - 1}{2}} \\equiv \\br{g^r}^{\\tfrac{p - 1}{2}} \\equiv \\br{g^{\\tfrac{p - 1}{2}}}^r \\equiv \\br{-1}^r \\mod p. $$\nBut\n\\begin{align*}\n\\jacobi{a}{p} = 1 \\qquad\n& \\iff \\qquad \\exists s \\in \\ZZ, \\ \\br{g^s}^2 \\equiv a \\mod p \\\\\n& \\iff \\qquad 2s \\equiv r \\mod p - 1 \\\\\n& \\iff \\qquad r \\in 2\\ZZ \\\\\n& \\iff \\qquad \\br{-1}^r \\equiv 1 \\mod p.\n\\end{align*}\n\\end{proof}\n\n\\subsection{Computing Legendre symbols}\n\n\\begin{proposition}\n$ -1 $ is a square modulo $ p $ if and only if $ p = 2 $ or $ p \\equiv 1 \\mod 4 $.\n\\end{proposition}\n\n\\begin{proof}\n$ p = 2 $ is trivial. If $ p > 2 $, then by Euler's criterion,\n$$ \\jacobi{-1}{p} \\equiv \\br{-1}^{\\tfrac{p - 1}{2}} \\mod p, $$\nso in fact\n$$ \\jacobi{-1}{p} = \\br{-1}^{\\tfrac{p - 1}{2}}. $$\nThen\n$$ \\br{-1}^{\\tfrac{p - 1}{2}} =\n\\begin{cases}\n1 & p \\equiv 1 \\mod 4 \\\\\n-1 & p \\equiv 3 \\mod 4\n\\end{cases}.\n$$\n\\end{proof}\n\n\\begin{proposition}[Gauss' lemma]\n$$ \\jacobi{2}{p} =\n\\begin{cases}\n1 & p \\equiv \\pm 1 \\mod 8 \\\\\n-1 & p \\equiv \\pm 3 \\mod 8\n\\end{cases},\n$$\nthat is\n$$ \\jacobi{2}{p} = \\br{-1}^{\\tfrac{p^2 - 1}{8}}. $$\n\\end{proposition}\n\n\\begin{proof}\n$$ \\jacobi{2}{p} \\equiv 2^{\\tfrac{p - 1}{2}} \\mod p, $$\nby Euler's criterion. Let $ q = \\br{p - 1} / 2 $, and let\n$$ Q = \\br{2}\\br{4} \\dots \\br{p - 3}\\br{p - 1} = \\br{2\\br{1}} \\dots \\br{2\\br{q}} = 2^qq! = 2^{\\tfrac{p - 1}{2}}q!. $$\nSubtracting $ p $ from every term which is bigger than $ q $,\n$$ Q \\equiv \\br{2}\\br{4} \\dots \\br{-3}\\br{-1} \\equiv \\br{-1}^rq! \\mod p, $$\nwhere $ r $ is the number of odd integers in $ 1, \\dots, q $. Since $ p \\nmid q! $, we have $ 2^{\\br{p - 1} / 2} \\equiv \\br{-1}^r \\mod p $. Now the following holds. \\footnote{Exercise}\n$$ \\br{-1}^r =\n\\begin{cases}\n1 & p \\equiv \\pm 1 \\mod 8 \\\\\n-1 & p \\equiv \\pm 3 \\mod 8\n\\end{cases}.\n$$\n\\end{proof}\n\n\\pagebreak\n\n\\begin{example*}\nIf $ p \\equiv 1 \\mod 8 $, say $ p = 1 + 8n $, then $ q = 4n $. Odd integers in $ 1, \\dots, 4n $ are $ 1, 3, \\dots, 4n - 3, 4n - 1 $, so $ r = 2n $.\n\\end{example*}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ \\jacobi{2}{7} = 1 $, since $ 2 \\equiv 3^2 \\mod 7 $.\n\\item $ \\jacobi{2}{11} = -1 $, since squares modulo $ 11 $ are $ 1, 4, 9, 5, 3 $.\n\\item $ \\jacobi{-1}{11} = -1 $, so $ \\jacobi{-2}{11} = \\jacobi{2}{11}\\jacobi{-1}{11} = \\br{-1}^2 = 1 $, since $ -2 \\equiv 3^2 \\mod 11 $.\n\\end{itemize}\n\\end{example*}\n\n\\begin{theorem}[Law of quadratic reciprocity]\n\\label{thm:40}\nIf $ p $ and $ q $ are odd primes, then\n$$ \\jacobi{p}{q} = \\jacobi{q}{p}\\br{-1}^{\\br{\\tfrac{p - 1}{2}}\\br{\\tfrac{q - 1}{2}}}, $$\nthat is $ \\jacobi{p}{q} = \\jacobi{q}{p} $ unless $ p \\equiv q \\equiv 3 \\mod 4 $, when $ \\jacobi{p}{q} = -\\jacobi{q}{p} $.\n\\end{theorem}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ \\jacobi{5}{p} = \\jacobi{p}{5} $ for $ p \\ne 5 $. QRs modulo $ 5 $ are $ 1 $ and $ 4 $. So\n$$ \\jacobi{5}{p} =\n\\begin{cases}\n1 & p \\equiv \\pm 1 \\mod 5 \\\\\n-1 & p \\equiv \\pm 2 \\mod 5\n\\end{cases}.\n$$\n\n\\item What is $ \\jacobi{3}{p} $ for $ p \\ne 3 $? If $ p \\equiv 1 \\mod 4 $, then\n$$ \\jacobi{3}{p} = \\jacobi{p}{3} =\n\\begin{cases}\n1 & p \\equiv 1 \\mod 3 \\\\\n-1 & p \\equiv -1 \\mod 3\n\\end{cases}.\n$$\nIf $ p \\equiv -1 \\mod 4 $, then\n$$ \\jacobi{3}{p} = -\\jacobi{p}{3} =\n\\begin{cases}\n1 & p \\equiv -1 \\mod 3 \\\\\n-1 & p \\equiv 1 \\mod 3\n\\end{cases}.\n$$\nSo\n$$ \\jacobi{3}{p} =\n\\begin{cases}\n1 & p \\equiv \\pm 1 \\mod 12 \\\\\n-1 & p \\equiv \\pm 5 \\mod 12\n\\end{cases}.\n$$\nFor example, $ \\jacobi{3}{7} = -1 $, since QRs are $ 1, 2, 4 $, and $ \\jacobi{3}{11} = 1 $, since $ 5^2 \\equiv 3 \\mod 11 $.\n\\item $ \\jacobi{6}{19} = \\jacobi{2}{19}\\jacobi{3}{19} = \\br{-1}\\br{-1} = 1 $, since $ \\jacobi{2}{19} = -1 $, because $ 19 \\equiv 3 \\mod 8 $, and $ \\jacobi{3}{19} \\equiv -1 \\mod 12 $, by the above.\n\\end{itemize}\n\\end{example*}\n\nIn general to compute $ \\jacobi{a}{p} $, we could do the following. Use that if $ a \\equiv b \\mod p $ then $ \\jacobi{a}{p} = \\jacobi{b}{p} $. So without loss of generality $ \\abs{a} < p $. Then write $ a = \\pm\\prod_i q_i^{s_i} $ for $ q_i $ prime. Then\n$$ \\jacobi{a}{p} = \\jacobi{\\pm 1}{p} \\prod_i \\jacobi{q_i}{p}^{s_i}. $$\nIf $ s_i $ is even, then $ \\jacobi{q_i}{p}^{s_i} = 1 $. If $ s_i $ is odd, then $ \\jacobi{q_i}{p}^{s_i} = \\jacobi{q_i}{p} $. We have formulas for $ \\jacobi{-1}{p} $ and $ \\jacobi{2}{p} $. If $ q $ is an odd prime, $ q < p $, then use quadratic reciprocity to relate $ \\jacobi{q}{p} $ and $ \\jacobi{p}{q} $. Then repeat modulo $ q $.\n\n\\pagebreak\n\n\\subsection{Proof of quadratic reciprocity}\n\n\\lecture{12}{Wednesday}{31/10/18}\n\nThe proof of this is due to Rousseau, in 1991. This resembles the proof we gave that $ \\jacobi{2}{p} = \\br{-1}^{\\br{p^2 - 1} / 8} $.\n\n\\begin{theorem}[Wilson's theorem]\nIf $ p $ is prime, then $ \\br{p - 1}! \\equiv -1 \\mod p $.\n\\end{theorem}\n\n\\begin{proof}[Proof of Theorem \\ref{thm:40}]\nWe will write down several choices of coset representatives for $ \\cbr{\\pm 1} $, and compare them, that is we will write down choices of $ x $ or $ -x $ for each $ x \\in \\unit{pq} $. Write elements of $ \\unit{pq} $ as pairs $ \\br{\\alpha, \\beta} \\in \\unit{p} \\times \\unit{q} $.\n\\begin{itemize}\n\\item For our first set of coset representatives, take\n$$ \\cbr{\\br{x, y} \\st 1 \\le x \\le \\tfrac{p - 1}{2}, \\ 1 \\le y \\le q - 1}. $$\nLet $ A $ be the product of these coset representatives. This is by definition\n$$ A = \\br{\\br{\\br{\\tfrac{p - 1}{2}}!}^{q - 1}, \\br{-1}^{\\tfrac{p - 1}{2}}}. $$\n\\item The second set of representatives is\n$$ \\cbr{\\br{x, y} \\st 1 \\le x \\le p - 1, \\ 1 \\le y \\le \\tfrac{q - 1}{2}}. $$\nLet $ B $ be the product of these representatives. Then by symmetry,\n$$ B = \\br{\\br{-1}^{\\tfrac{q - 1}{2}}, \\br{\\br{\\tfrac{q - 1}{2}}!}^{p - 1}}. $$\n\\item For the third set of representatives, select the pairs $ \\br{x, y} $ which correspond via the Chinese remainder theorem to the set\n$$ \\cbr{1 \\le i \\le \\tfrac{pq - 1}{2} \\st \\br{i, pq} = 1}. $$\nLet $ C $ be the product of these coset representatives. What is the $ x $-coordinate of $ C $? It is\n$$ \\prod_{i = 1, \\ \\br{i, pq} = 1}^{\\tfrac{pq - 1}{2}} i. $$\nSo\n\\begin{equation}\n\\label{eq:1}\n\\prod_{i = 1, \\ \\br{i, pq} = 1}^{\\tfrac{pq - 1}{2}} i = \\br{\\prod_{i = 1, \\ \\br{i, p} = 1}^{\\tfrac{pq - 1}{2}} i} \\ \\Bigg/ \\ \\br{\\prod_{i = 1, \\ \\br{i, p} = 1, \\ q \\mid i}^{\\tfrac{pq - 1}{2}} i},\n\\end{equation}\n\\begin{equation}\n\\label{eq:2}\n\\prod_{i = 1, \\ \\br{i, p} = 1}^{\\tfrac{pq - 1}{2}} i = \\br{\\prod_{i = 1, \\ \\br{i, p} = 1}^{p\\br{\\tfrac{q - 1}{2}}} i}\\br{\\prod_{i = p\\br{\\tfrac{q - 1}{2}} + 1, \\ \\br{i, p} = 1}^{p\\br{\\tfrac{q - 1}{2}} + \\tfrac{p - 1}{2}} i},\n\\end{equation}\n\\begin{equation}\n\\label{eq:3}\n\\prod_{i = 1, \\ \\br{i, p} = 1, \\ q \\mid i}^{\\tfrac{pq - 1}{2}} i = \\prod_{j = 1, \\ \\br{j, p} = 1}^{\\tfrac{p - 1}{2}} qj = q^{\\tfrac{p - 1}{2}}\\br{\\tfrac{p - 1}{2}}!.\n\\end{equation}\nCombining $ \\br{\\ref{eq:1}}, \\br{\\ref{eq:2}}, \\br{\\ref{eq:3}} $, get that the $ x $-coordinate of the product is\n$$ \\prod_{i = 1, \\ \\br{i, pq} = 1}^{\\tfrac{pq - 1}{2}} i = \\dfrac{\\br{p - 1}!^{\\tfrac{q - 1}{2}}\\br{\\tfrac{p - 1}{2}}!}{q^{\\tfrac{p - 1}{2}}\\br{\\tfrac{p - 1}{2}}!} = \\dfrac{\\br{-1}^{\\tfrac{q - 1}{2}}}{q^{\\tfrac{p - 1}{2}}}. $$\nSo $ C $, the product of these representatives, is\n$$ C = \\br{\\br{-1}^{\\tfrac{q - 1}{2}}\\jacobi{q}{p}, \\br{-1}^{\\tfrac{p - 1}{2}}\\jacobi{p}{q}}. $$\n\\end{itemize}\n\n\\pagebreak\n\n$ A, B, C $ all agree up to sign, that is up to multiplication by $ \\pm 1 $, that is up to multiplication by\n$$ \\br{-1, -1} \\in \\unit{p} \\times \\unit{q}. $$\nLooking at $ y $-coordinates, $ C = \\jacobi{p}{q}A $. Similarly $ C = \\jacobi{q}{p}B $. So $ B = \\jacobi{q}{p}\\jacobi{p}{q}A $. To swap between $ A $ and $ B $, just change the signs of everything with $ 1 \\le x \\le \\br{p - 1} / 2 $ and $ \\br{q + 1} / 2 \\le y \\le q - 1 $. So\n$$ B = \\br{-1}^{\\br{\\tfrac{p - 1}{2}}\\br{\\tfrac{q - 1}{2}}}A. $$\nSo\n$$ \\jacobi{q}{p}\\jacobi{p}{q} = \\br{-1}^{\\br{\\tfrac{p - 1}{2}}\\br{\\tfrac{q - 1}{2}}}. $$\n\\end{proof}\n\n\\subsection{Jacobi symbols}\n\nThese are an extension of Legendre symbols which are useful for making computations.\n\n\\begin{definition}\nWrite $ b = \\prod_i p_i^{r_i} $ for $ p_i $ distinct primes. Then the \\textbf{Jacobi symbol} is\n$$ \\jacobi{a}{b} = \\prod_i \\jacobi{a}{p_i}^{r_i}. $$\n\\end{definition}\n\nA warning is that $ \\jacobi{a}{b} = 1 $ does not imply that $ a $ is a square modulo $ b $. On the other hand, $ \\jacobi{a}{b} = -1 $ implies that $ a $ is not a square modulo $ b $.\n\n\\lecture{13}{Friday}{02/11/18}\n\n\\begin{lemma}\n\\hfill\n\\begin{enumerate}\n\\item $ \\jacobi{a_1a_2}{b} = \\jacobi{a_1}{b}\\jacobi{a_2}{b} $ and $ \\jacobi{a}{b_1b_2} = \\jacobi{a}{b_1}\\jacobi{a}{b_2} $.\n\\item $ \\jacobi{a}{b} $ depends only on $ a \\mod b $.\n\\item $ \\jacobi{a^2}{b} = 1 $.\n\\item $ \\jacobi{-1}{b} = \\br{-1}^{\\br{b - 1} / 2} $.\n\\item $ \\jacobi{2}{b} = \\br{-1}^{\\br{b^2 - 1} / 8} $.\n\\item If $ a, b > 0 $ are both odd\n$$ \\jacobi{a}{b}\\jacobi{b}{a} = \\br{-1}^{\\br{\\tfrac{a - 1}{2}}\\br{\\tfrac{b - 1}{2}}}. $$\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{proof}\nAll of these statements are true for Legendre symbols, that is for $ b $ prime, and $ a $ prime in $ 6 $. $ 1 $ to $ 3 $ follow immediately, and $ 4 $ to $ 6 $ also follows from $ 1 $ and the corresponding statements for Legendre symbols. For $ 5 $, it is enough to show that if it holds for $ b_1 $ and $ b_2 $, then it holds for $ b_1b_2 $. Since\n$$ \\jacobi{2}{b_1b_2} = \\jacobi{2}{b_1}\\jacobi{2}{b_2}, $$\nwe need to show that\n$$ \\br{-1}^{\\tfrac{b_1^2 - 1}{8}}\\br{-1}^{\\tfrac{b_2^2 - 1}{8}} = \\br{-1}^{\\tfrac{\\br{b_1b_2}^2 - 1}{8}}, $$\nthat is need\n$$ \\br{b_1^2 - 1} + \\br{b_2^2 - 1} \\equiv \\br{b_1b_2}^2 - 1 \\mod 16, $$\nthat is $ \\br{b_1^2 - 1}\\br{b_2^2 - 1} \\equiv 0 \\mod 16 $. This is true because $ b_1^2 \\equiv b_2^2 \\equiv 1 \\mod 4 $.\n\\end{proof}\n\n\\begin{example*}\nSince\n\\begin{align*}\n\\jacobi{7411}{9283}\n& = -\\jacobi{9283}{7411} = -\\jacobi{1872}{7411} = -\\jacobi{16}{7411}\\jacobi{117}{7411} = -\\jacobi{117}{7411} = -\\jacobi{7411}{117} = -\\jacobi{40}{117} \\\\\n& = -\\jacobi{8}{117}\\jacobi{5}{117} = -\\jacobi{2}{117}\\jacobi{5}{117} = \\jacobi{5}{117} = \\jacobi{117}{5} = \\jacobi{2}{5} = -1,\n\\end{align*}\n$ 7411 $ is not a square modulo $ 9283 $.\n\\end{example*}\n\n\\pagebreak\n\n\\section{Sums of squares}\n\nWhich integers are the sum of two squares? Which integers are the sum of four squares?\n\n\\subsection{Sums of two squares}\n\n\\begin{definition}\nWe say that $ n \\in \\ZZ $ is a \\textbf{sum of two squares} if\n$$ n = x^2 + y^2, \\qquad x, y \\in \\ZZ. $$\n\\end{definition}\n\n\\begin{example*}\nIf $ n = x^2 + y^2 $, then since $ x^2, y^2 \\equiv 0, 1 \\mod 4 $, we cannot have $ n \\equiv 3 \\mod 4 $.\n\\end{example*}\n\n\\begin{example*}\n$ 21 \\equiv 1 \\mod 4 $, but $ 21 $ is not a sum of two squares. On the other hand, we will see that all primes which are $ 1 \\mod 4 $ are sums of two squares.\n\\end{example*}\n\n\\begin{definition}\nThe \\textbf{Gaussian integers} $ \\ZZ\\sbr{i} $ are the subring of $ \\CC $ consisting of\n$$ a + bi, \\qquad a, b \\in \\ZZ. $$\n\\end{definition}\n\nThe \\textbf{norm} is defined by\n$$ \\function[\\N]{\\ZZ\\sbr{i}}{\\ZZ_{> 0}}{a + bi}{a^2 + b^2}, $$\nthat is $ \\N\\br{z} = z\\bar{z} $. Then $ \\N\\br{zw} = \\br{zw}\\br{\\bar{zw}} = \\br{z\\bar{z}}\\br{w\\bar{w}} = \\N\\br{z}\\N\\br{w} $.\n\n\\begin{lemma}\n\\label{lem:46}\nIf $ m $ and $ n $ are each a sum of two squares, then so is $ mn $.\n\\end{lemma}\n\n\\begin{proof}\nIf $ z = a + bi $ and $ w = c + di $, then $ zw = \\br{ac - bd} + \\br{ad + bc}i $, so\n$$ \\br{a^2 + b^2}\\br{c^2 + d^2} = \\br{ac - bd}^2 + \\br{ad + bc}^2. $$\n\\end{proof}\n\n\\begin{theorem}[Fermat's two square theorem]\n\\label{thm:47}\nIf $ p \\equiv 1 \\mod 4 $ is prime, then $ p $ is a sum of two squares.\n\\end{theorem}\n\nLemma \\ref{lem:46} and Theorem \\ref{thm:47} together allow you to give a complete classification of the integers which are sums of two squares, in terms of their prime factorisations.\n\n\\begin{definition}\nA ring $ R $ is a \\textbf{Euclidean domain} if it is an integral domain, that is $ ab = 0 $ implies that $ a = 0 $ or $ b = 0 $, and there exists a function $ \\N : R \\to \\ZZ_{\\ge 0} $ such that for all $ a, b \\in R $ with $ b \\ne 0 $, there exist $ q, r \\in R $ such that $ a = qb + r $, and $ r = 0 $ or $ \\N\\br{r} < \\N\\br{b} $.\n\\end{definition}\n\nIf $ R $ is a Euclidean domain, then you can carry out Euclid's algorithm. In particular, irreducible elements are the same as prime elements, and every element can be factored as a product of primes, uniquely up to reordering and multiplication by units. Then $ \\ZZ\\sbr{i} $ together with $ \\N $ is a Euclidean domain. By definition, $ n \\in \\ZZ $ is a sum of two squares if and only if there exists $ z \\in \\ZZ\\sbr{i} $ with $ \\N\\br{z} = n $. Since $ \\N\\br{zw} = \\N\\br{z}\\N\\br{w} $, all we have to do is to figure out what the primes in $ \\ZZ\\sbr{i} $ are, and what their norms are. The units in $ \\ZZ\\sbr{i} $ are $ \\pm 1 $ and $ \\pm i $. \\footnote{Exercise} Two elements of $ \\ZZ\\sbr{i} $ are \\textbf{associates} if their ratio is a unit, that is $ z $ and $ w $ are associates if $ z = uw $ for $ u = \\pm 1, \\pm i $.\n\n\\lecture{14}{Tuesday}{06/11/18}\n\n\\begin{lemma}\nLet $ p $ be a prime in $ \\ZZ\\sbr{i} $. Then there is a prime $ q $ of $ \\ZZ $ such that either $ \\N\\br{p} = q $ or $ \\N\\br{p} = q^2 $. In the latter case, $ p $ is an associate of $ q $. Given $ q $ a prime in $ \\ZZ $, there exists $ p $ such that $ \\N\\br{p} = q $ if and only if $ q $ is a sum of two squares.\n\\end{lemma}\n\n\\begin{proof}\nWrite $ n = \\N\\br{p} $, and let $ n = q_1^{s_1} \\dots q_r^{s_r} $ be the prime factorisation of $ n $ in $ \\ZZ $. By definition $ n = p\\bar{p} $, so $ p \\mid n $ in $ \\ZZ\\sbr{i} $, and so since $ p $ is prime, $ p \\mid q_i $ for some $ i $. Write $ q = q_i $. Then $ p \\mid q $ implies that $ q = pv $ for some $ v $, so $ \\N\\br{p}\\N\\br{v} = \\N\\br{pv} = \\N\\br{q} = q^2 $. If $ \\N\\br{p} = 1 $, then $ p $ is a unit, a contradiction. So $ \\N\\br{p} \\mid q^2 $, so $ \\N\\br{p} = q $ or $ \\N\\br{p} = q^2 $, as claimed. If $ \\N\\br{p} = q^2 $, then $ \\N\\br{v} = 1 $, so $ v $ is a unit, and since $ q = pv $, $ p $ is an associate of $ q $, by definition. If $ \\N\\br{p} = q $, then writing $ p = a + bi $, we have $ q = a^2 + b^2 $. Conversely, if $ q = a^2 + b^2 = \\br{a + bi}\\br{a - bi} $,\nthen since $ p \\mid q $, we have either $ p \\mid a + bi $ or $ p \\mid a - bi $, so $ \\N\\br{p} \\mid \\N\\br{a + bi} = q $ or $ \\N\\br{p} \\mid \\N\\br{a - bi} = q $, and either way $ \\N\\br{p} = q $.\n\\end{proof}\n\n\\pagebreak\n\n\\begin{corollary}\n\\label{cor:50}\nThe primes in $ \\ZZ\\sbr{i} $ are either of the form $ a + bi $ with $ a^2 + b^2 $ a prime in $ \\ZZ $, or are primes of $ \\ZZ $ which are not sums of two squares.\n\\end{corollary}\n\n\\begin{theorem}\nIf $ p = 2 $ or $ p \\equiv 1 \\mod 4 $, then $ p $ is a sum of two squares.\n\\end{theorem}\n\n\\begin{proof}\nBy Corollary \\ref{cor:50}, we just have to show that $ p $ is not a prime in $ \\ZZ\\sbr{i} $. There exists $ n $ such that $ n^2 \\equiv -1 \\mod p $. If $ p = 2 $ obvious, and if $ p \\equiv 1 \\mod 4 $,\n$$ \\jacobi{-1}{p} = \\br{-1}^{\\tfrac{p - 1}{2}} = 1, $$\nby Euler's criterion. That is, $ p \\mid n^2 + 1 = \\br{n + i}\\br{n - i} $. If $ p $ were prime, then $ p \\mid n + i $ or $ p \\mid n - i $, that is there exist $ c, d \\in \\ZZ $ such that $ n \\pm i = p\\br{c \\pm di} $, so $ 1 = pd $, a contradiction.\n\\end{proof}\n\n\\begin{remark*}\nIf $ p \\equiv 3 \\mod 4 $ then $ p $ is not a sum of two squares, even modulo four.\n\\end{remark*}\n\n\\begin{remark*}\nIn practice, to go from $ n^2 + 1 \\equiv 0 \\mod p $ to finding $ a $ and $ b $ with $ a^2 + b^2 = p $, you just compute $ \\br{n + i, p} = a + bi $. You can do this computation with Euclid's algorithm in $ \\ZZ\\sbr{i} $.\n\\end{remark*}\n\n\\begin{theorem}\n$ n \\in \\ZZ $ is a sum of two squares if and only if its prime factorisation only contains primes congruent to $ 3 \\mod 4 $ to even powers, that is\n$$ n = 2^a\\prod_{p_i \\equiv 1 \\mod 4} p_i^{r_i}\\prod_{q_i \\equiv 3 \\mod 4} q_i^{2s_i}. $$\n\\end{theorem}\n\n\\begin{proof}\nSuppose $ n $ is of this form. Then $ 2 $, each $ p_i $, and each $ q_i^2 $ are all sums of two squares, so $ n $ is a sum of two squares by Lemma \\ref{lem:46}. Conversely suppose that $ n = a^2 + b^2 $, and write $ a + bi $ as a product of primes in $ \\ZZ\\sbr{i} $. Then $ n = \\N\\br{a + bi} $ is the product of the norms of these primes, and we already saw that the norms of primes in $ \\ZZ\\sbr{i} $ are either $ 2 $, a prime which is $ 1 \\mod 4 $, or the square of a prime which is $ 3 \\mod 4 $.\n\\end{proof}\n\n\\subsection{Sums of four squares - the ring of quaternions}\n\nLagrange's theorem states that every positive integer is a sum of four squares.\n\n\\begin{definition}\n$ \\HH $, the \\textbf{ring of quaternions}, is the ring of sums\n$$ a + bi + cj + dk, \\qquad a, b, c, d \\in \\RR, $$\nsuch that\n\\begin{itemize}\n\\item addition is\n$$ \\br{a + bi + cj + dk} + \\br{A + Bi + Cj + Dk} = \\br{a + A} + \\br{b + B}i + \\br{c + C}j + \\br{d + D}k, $$\n\\item multiplication is\n$$ ij = -ji = k, \\qquad jk = -kj = i, \\qquad ki = -ik = j. $$\n\\end{itemize}\nIf $ z = a + bi + cj + dk $, we write $ z^* = a - bi - cj - dk $, so $ \\br{zw}^* = w^*z^* $.\n\\end{definition}\n\nDefine\n$$ \\N\\br{z} = zz^* = a^2 + b^2 + c^2 + d^2. $$\nThen $ \\N\\br{zw} = zw\\br{zw}^* = zww^*z^* = z\\N\\br{w}z^* = zz^*\\N\\br{w} = \\N\\br{z}\\N\\br{w} $, because $ \\N\\br{w} \\in \\RR $. So\n\\begin{align*}\n\\br{a^2 + b^2 + c^2 + d^2}\\br{x^2 + y^2 + z^2 + w^2}\n= \\ & \\N\\br{a + bi + cj + dk}\\N\\br{x + yi + zj + wk} \\\\\n= \\ & \\N\\br{\\br{a + bi + cj + dk}\\br{x + yi + zj + wk}} \\\\\n= \\ & \\br{ax - by - cz - dw}^2 + \\br{ay + bx + cw - dz}^2 \\\\\n+ & \\br{az - bw + cx + dy}^2 + \\br{aw + bz - cy + dx}^2.\n\\end{align*}\nIn particular, if $ m $ and $ n $ are sums of four squares, then $ mn $ is a sum of four squares. So to prove Lagrange's theorem, it suffices to show that all primes are sums of four squares.\n\n\\pagebreak\n\n\\subsection{Proof of Lagrange's theorem}\n\nWe already saw that $ 2 $, and any prime congruent to $ 1 \\mod 4 $, is a sum of two squares. It remains to show that any prime congruent to $ 3 \\mod 4 $ is a sum of four squares.\n\n\\lecture{15}{Wednesday}{07/11/18}\n\n\\begin{lemma}\n\\label{lem:54}\nIf $ p \\equiv 3 \\mod 4 $ is prime, then there exist $ x $ and $ y $ such that\n$$ x^2 + y^2 + 1 \\equiv 0 \\mod p. $$\n\\end{lemma}\n\n\\begin{proof}\nFirstly, claim there exists $ a $ such that $ \\jacobi{a}{p} = 1 $ and $ \\jacobi{a + 1}{p} = -1 $. If not, since $ \\jacobi{1}{p} = 1 $, we must have\n$$ \\jacobi{2}{p} = \\dots = \\jacobi{p - 1}{p} = 1. $$\nBut we know that there are $ \\br{p - 1} / 2 $ values of $ b $ with $ 1 \\le b \\le p - 1 $ and $ \\jacobi{b}{p} = -1 $, a contradiction. Since $ p \\equiv 3 \\mod 4 $, $ \\jacobi{-1}{p} = -1 $ by Euler's criterion. So\n$$ \\jacobi{-\\br{a + 1}}{p} = \\jacobi{a + 1}{p}\\jacobi{-1}{p} = 1. $$\nChoose $ x $ and $ y $ such that\n$$ x^2 \\equiv a \\mod p, \\qquad y^2 \\equiv -\\br{a + 1} \\mod p. $$\nThen $ x^2 + y^2 \\equiv -1 \\mod p $.\n\\end{proof}\n\nBy Lemma \\ref{lem:54}, there exist $ x, y \\in \\ZZ $ such that\n$$ x^2 + y^2 + 1 = pr, $$\nfor some $ r $. Since the congruence $ x^2 + y^2 + 1 \\equiv 0 \\mod p $ only depends on $ x $ and $ y $ modulo $ p $, we can find $ x $ and $ y $ with $ -p / 2 < x, y < p / 2 $. Then\n$$ \\dfrac{x^2 + y^2 + 1}{p} = r < p. $$\n\n\\begin{proposition}\n\\label{prop:55}\nSuppose that\n$$ x^2 + y^2 + z^2 + w^2 = pr, \\qquad 1 \\le r < p. $$\nIf $ r > 1 $, there exist $ x', y', z', w', r' $ such that\n$$ x'^2 + y'^2 + z'^2 + w'^2 = pr', \\qquad 1 \\le r' < r. $$\n\\end{proposition}\n\nProposition \\ref{prop:55} implies that $ p $ is a sum of four squares, starting with $ x, y, r $ as above, $ z = 1 $, and $ w = 0 $.\n\n\\begin{proof}\n\\hfill\n\\begin{itemize}\n\\item Suppose firstly that $ r $ is even. Then either $ x, y, z, w $ are all even, all odd, or two are even and two are odd. So without loss of generality $ x \\equiv y \\mod 2 $ and $ z \\equiv w \\mod 2 $. Then take\n$$ x' = \\dfrac{x + y}{2}, \\qquad y' = \\dfrac{x - y}{2}, \\qquad z' = \\dfrac{z + w}{2}, \\qquad w' = \\dfrac{z - w}{2}, \\qquad r' = \\dfrac{r}{2}. $$\n\n\\pagebreak\n\n\\item Suppose now that $ r $ is odd, and choose $ a, b, c, d \\in \\br{-r / 2, r / 2} $ such that\n$$ x \\equiv a \\mod r, \\qquad y \\equiv b \\mod r, \\qquad z \\equiv c \\mod r, \\qquad w \\equiv d \\mod r. $$\nThen\n$$ a^2 + b^2 + c^2 + d^2 \\equiv x^2 + y^2 + z^2 + w^2 = pr \\equiv 0 \\mod r. $$\nWrite $ a^2 + b^2 + c^2 + d^2 = rr' $. Then $ rr' < 4\\br{r / 2}^2 = r^2 $, so $ 0 \\le r' < r $. If $ r' = 0 $ then $ a = b = c = d = 0 $, so $ r' $ divides each of $ x, y, z, w $. Since $ x^2 + y^2 + z^2 + w^2 = pr $, we get $ r^2 \\mid pr $ so $ r \\mid p $, and since $ r < p $, we get $ r = 1 $, and we are done. Otherwise $ 1 \\le r' < r $. Then\n\\begin{align*}\n\\br{rr'}\\br{rp}\n= \\ & \\br{a^2 + b^2 + c^2 + d^2}\\br{x^2 + y^2 + z^2 + w^2} \\\\\n= \\ & \\br{ax + by + cz + dw}^2 + \\br{-ay + bx + cw - dz}^2 \\\\\n+ & \\br{-az - bw + cx + dy}^2 + \\br{-aw + bz - cy + dx}^2.\n\\end{align*}\nThen\n\\begin{align*}\nax + by + cz + dw \\equiv x^2 + y^2 + z^2 + w^2 & \\equiv 0 \\mod r, \\\\\n-ay + bx + cw - dz \\equiv -xy + yx + zw - wz & \\equiv 0 \\mod r, \\\\\n-az - bw + cx + dy \\equiv -xz - yw + zx + wy & \\equiv 0 \\mod r, \\\\\n-aw + bz - cy + dx \\equiv -xw + yz - zy + wx & \\equiv 0 \\mod r.\n\\end{align*}\nSo take\n$$ x' = \\dfrac{ax + by + cz + dw}{r}, \\qquad y' = \\dfrac{-ay + bx + cw - dz}{r}, $$\n$$ z' = \\dfrac{-az - bw + cx + dy}{r}, \\qquad w' = \\dfrac{-aw + bz - cy + dx}{r}. $$\n\\end{itemize}\n\\end{proof}\n\n\\begin{remark}\nThis can be interpreted as a version of Euclid's algorithm in the ring\n$$ \\cbr{\\dfrac{a + bi + cj + dk}{2} \\st a \\equiv b \\equiv c \\equiv d \\mod 2}. $$\n\\end{remark}\n\n\\begin{note*}\nThis ring is non-commutative, and also, for example, $ 5 = \\br{1 - 2i}\\br{1 - 2i} = \\br{1 + 2j}\\br{1 - 2j} $, so you have to be careful with unique factorisation, etc.\n\\end{note*}\n\n\\subsection{Sums of three squares}\n\n$ 7 $ is the smallest positive integer which is not a sum of three squares. In fact no integer congruent to $ 7 \\mod 8 $ can be a sum of three squares, because the squares modulo $ 8 $ are $ 0, 1, 4 $.\n\n\\begin{theorem}\nA positive integer is not a sum of three squares if and only if it is of the form\n$$ 4^a\\br{8k + 7}. $$\n\\end{theorem}\n\nProving that numbers are not of this form is beyond this course. Serre's a course in arithmetic is a good place to look.\n\n\\pagebreak\n\n\\section{Pell's equation}\n\n\\subsection{Pell's equation}\n\nLet $ d \\in \\ZZ_{> 1} $ be squarefree. \\textbf{Pell's equation} is\n$$ x^2 - dy^2 = 1. $$\n\n\\begin{example*}\nLet $ d = 2 $. Then $ \\br{x, y} = \\br{3, 2} $ is a solution. In fact, there are infinitely many solutions, and this is true for any $ d $.\n\\end{example*}\n\nWe will find it useful to write\n$$ x^2 - dy^2 = \\br{x + \\sqrt{d}y}\\br{x - \\sqrt{d}y}. $$\nThis suggests that we should look at a ring like\n$$ \\ZZ\\sbr{\\sqrt{d}} = \\cbr{a + b\\sqrt{d} \\st a, b \\in \\ZZ}. $$\n\n\\begin{definition}\nIf $ \\alpha \\in \\CC $, then $ \\ZZ\\sbr{\\alpha} $ is the \\textbf{smallest subring of $ \\CC $ containing $ \\alpha $}.\n\\end{definition}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item If $ \\alpha = 1 $, then $ \\ZZ\\sbr{\\alpha} = \\ZZ $.\n\\item If $ \\alpha = i $, $ \\ZZ\\sbr{i} $ is what we wrote before.\n\\item On the other hand $ \\ZZ\\sbr{\\pi} $ is the ring of $ a_0 + \\dots + a_n\\pi^n $ for $ a_i \\in \\ZZ $ and $ n $ arbitrary.\n\\item Also $ \\ZZ\\sbr{\\sqrt[3]{2}} $ is not just the set $ \\cbr{a + b\\sqrt[3]{2} \\st a, b \\in \\ZZ} $, because this set does not contain $ \\br{\\sqrt[3]{2}}^2 = \\sqrt[3]{4} $.\n\\item Also $ \\ZZ\\sbr{\\tfrac{1}{p}} $ contains $ 1 / p^n $ for all $ n $, so in fact $ \\ZZ\\sbr{\\tfrac{1}{p}} = \\cbr{a / p^n \\st a \\in \\ZZ, \\ n \\ge 0} $.\n\\end{itemize}\n\\end{example*}\n\nAn alternative definition is that $ \\ZZ\\sbr{\\alpha} $ is the intersection of all subrings of $ \\CC $ containing $ \\alpha $.\n\n\\lecture{16}{Friday}{09/11/18}\n\nLecture 16 is a problems class.\n\n\\subsection{Quadratic subrings of \\texorpdfstring{$ \\CC $}{C}}\n\n\\lecture{17}{Tuesday}{13/11/18}\n\n\\begin{definition}\nSay that $ \\alpha \\in \\CC $ is an \\textbf{algebraic integer of degree two} if it is a root of a polynomial\n$$ X^2 + aX + b, \\qquad a, b \\in \\ZZ, \\qquad \\alpha \\notin \\ZZ. $$\n\\end{definition}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ \\alpha = i $ is a root of $ X^2 + 1 $.\n\\item $ \\alpha = \\sqrt{d} $ is a root of $ X^2 - d $ for $ d > 1 $ squarefree.\n\\end{itemize}\n\\end{example*}\n\n\\begin{proposition}\nIf $ \\alpha $ is an algebraic integer of degree two, then\n$$ \\ZZ\\sbr{\\alpha} = \\cbr{x + y\\alpha \\st x, y \\in \\ZZ}. $$\n\\end{proposition}\n\n\\begin{proof}\nSince $ \\alpha \\notin \\ZZ $, we have $ \\alpha \\notin \\QQ $, since if $ \\alpha = r / s $ for $ \\br{r, s} = 1 $ then $ r^2 + ars + bs^2 = 0 $,\nso $ s \\mid r^2 $, so $ s \\mid 1 $, so $ \\alpha \\in \\ZZ $. So if $ x, y \\in \\ZZ $ and $ x + y\\alpha = 0 $, then $ x = y = 0 $. Certainly every $ x + y\\alpha \\in \\ZZ\\sbr{\\alpha} $. The set $ \\cbr{x + y\\alpha} $ is closed under addition and subtraction, so we only have to check that is closed under multiplication. But\n\\begin{align*}\n\\br{x + y\\alpha}\\br{X + Y\\alpha}\n& = xX + \\br{xY + yX}\\alpha + yY\\alpha^2 \\\\\n& = xX + \\br{xY + yX}\\alpha + yY\\br{a\\alpha + b} \\\\\n& = \\br{xX + byY} + \\br{xY + yX + ayY}\\alpha.\n\\end{align*}\n\\end{proof}\n\n\\pagebreak\n\nIf $ \\alpha $ is an algebraic integer of degree two, say that $ \\ZZ\\sbr{\\alpha} $ is a \\textbf{real quadratic subring} of $ \\CC $ if $ \\alpha \\in \\RR $, and an \\textbf{imaginary quadratic subring} of $ \\CC $ if $ \\alpha \\notin \\RR $. Let $ \\alpha^* $ be the other root of $ X^2 + aX + b = 0 $.\n\n\\begin{example*}\n$ i^* = -i = \\bar{i} $ and $ \\sqrt{d}^* = -\\sqrt{d} $.\n\\end{example*}\n\nIf $ z = x + y\\alpha \\in \\ZZ\\sbr{\\alpha} $, write $ z^* = x + y\\alpha^* $. If $ \\ZZ\\sbr{\\alpha} $ is imaginary quadratic, then $ \\alpha^* = \\bar{\\alpha} $, and $ z^* = \\bar{z} $. This is not true if $ \\ZZ\\sbr{\\alpha} $ is real quadratic. Define $ \\N\\br{z} = zz^* $. Since $ \\alpha $ and $ \\alpha^* $ are the roots of $ X^2 + aX + b $, we have $ \\alpha + \\alpha^* = -a $ and $ \\alpha\\alpha^* = b $. If $ z = x + y\\alpha $, then\n$$ \\N\\br{z} = \\br{x + y\\alpha}\\br{x + y\\alpha^*} = x^2 + xy\\br{\\alpha + \\alpha^*} + y^2\\alpha\\alpha^* = x^2 - axy + by^2 \\in \\ZZ. $$\nWe have $ \\br{zw}^* = z^*w^* $, so $ \\N\\br{z}\\N\\br{w} = zz^*ww^* = \\br{zw}\\br{zw}^* = \\N\\br{zw} $. So $ \\N : \\ZZ\\sbr{\\alpha} \\to \\ZZ $ is multiplicative. Then $ \\N\\br{x + y\\alpha} = 0 $ if and only if $ x = y = 0 $. \\footnote{Exercise} If $ \\ZZ\\sbr{\\alpha} $ is imaginary quadratic then $ z^* = \\bar{z} $, and $ \\N\\br{z} \\ge 0 $. If $ \\ZZ\\sbr{\\alpha} $ is real quadratic, we can have $ \\N\\br{z} < 0 $.\n\n\\begin{example*}\nIf $ \\alpha = \\sqrt{d} $, then $ \\N\\br{\\sqrt{d}} = \\br{\\sqrt{d}}\\br{-\\sqrt{d}} = -d < 0 $, and\n$$ \\N\\br{x + y\\sqrt{d}} = \\br{x + y\\sqrt{d}}\\br{x + y\\sqrt{d}}^* = \\br{x + y\\sqrt{d}}\\br{x - y\\sqrt{d}} = x^2 - dy^2. $$\nSo solutions to Pell's equation are the same thing as elements of $ \\ZZ\\sbr{\\alpha} $ of norm one.\n\\end{example*}\n\n\\subsection{Factorisation in quadratic rings}\n\n\\begin{definition}\nThe \\textbf{units} of $ \\ZZ\\sbr{\\alpha} $ are by definition the elements with multiplicative inverses, and they form a group $ \\ZZ\\sbr{\\alpha}^\\times $ under multiplication. We say that $ z, w \\in \\ZZ\\sbr{\\alpha} $ are \\textbf{associates} if $ z = uw $ for $ u \\in \\ZZ\\sbr{\\alpha}^\\times $.\n\\end{definition}\n\nIf $ u \\in \\ZZ\\sbr{\\alpha}^\\times $, then write $ 1 = uv $. Then $ 1 = \\N\\br{1} = \\N\\br{u}\\N\\br{v} $, so $ \\N\\br{u} = \\pm 1 $. Conversely if $ \\N\\br{u} = \\pm 1 $, then $ \\pm 1 = \\N\\br{u} = u\\br{u^*} $, so $ u\\br{\\pm u^*} = 1 $, so $ u \\in \\ZZ\\sbr{\\alpha}^\\times $. So\n$$ \\ZZ\\sbr{\\alpha}^\\times = \\cbr{z \\in \\ZZ\\sbr{\\alpha} \\st \\N\\br{z} = \\pm 1}. $$\nWrite\n$$ \\ZZ\\sbr{\\alpha}^{\\times, 1} = \\cbr{z \\in \\ZZ\\sbr{\\alpha} \\st \\N\\br{z} = 1}. $$\nThen $ \\ZZ\\sbr{\\alpha}^{\\times, 1} $ is a multiplicative subgroup of $ \\ZZ\\sbr{\\alpha}^\\times $.\n\n\\subsection{Back to Pell's equation}\n\n\\begin{example*}\nIf $ \\alpha = \\sqrt{d} $ for $ d > 1 $ squarefree, then\n$$ \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} = \\cbr{x + y\\sqrt{d} \\st x^2 - dy^2 = 1}. $$\n\\end{example*}\n\nIf $ \\ZZ\\sbr{\\alpha} $ is imaginary quadratic, then $ \\ZZ\\sbr{\\alpha}^\\times = \\ZZ\\sbr{\\alpha}^{\\times, 1} $ is finite. What are the possibilities for this group? \\footnote{Exercise} What is $ \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $? Certainly contains $ \\pm 1 $. Anything else will be of the form $ x + y\\sqrt{d} $ with $ x, y \\ne 0 $.\n\n\\begin{lemma}\n\\label{lem:62}\nLet $ x + y\\sqrt{d} $ be an element of $ \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $. Then\n\\begin{align*}\nx > 0, \\qquad y > 0 \\qquad & \\iff \\qquad x + y\\sqrt{d} > 1, \\\\\nx > 0, \\qquad y < 0 \\qquad & \\iff \\qquad 0 < x + y\\sqrt{d} < 1, \\\\\nx < 0, \\qquad y > 0 \\qquad & \\iff \\qquad -1 < x + y\\sqrt{d} < 0, \\\\\nx < 0, \\qquad y < 0 \\qquad & \\iff \\qquad x + y\\sqrt{d} < -1.\n\\end{align*}\n\\end{lemma}\n\n\\begin{proof}\nIf $ x, y > 0 $ then $ x + y\\sqrt{d} > y\\sqrt{d} \\ge \\sqrt{d} > 1 $. Then $ x - y\\sqrt{d} = 1 / \\br{x + y\\sqrt{d}} \\in \\br{0, 1} $. So replacing $ y $ by $ -y $, we get $ x > 0 $ and $ y < 0 $, so $ 0 < x + y\\sqrt{d} < 1 $. Replacing $ \\br{x, y} $ with $ \\br{-x, -y} $ gives the forward in the third and fourth lines. Since the four possibilities for the right hand side are exhaustive for $ x, y \\ne 0 $, we are done.\n\\end{proof}\n\n\\pagebreak\n\n\\begin{lemma}\n\\label{lem:63}\nLet $ z = x + y\\sqrt{d} $ and $ z' = x' + y'\\sqrt{d} $ be two elements of $ \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $ with $ z, z' > 1 $, that is $ x, y, x', y' > 0 $. Then $ z > z' $ if and only if $ y > y' $.\n\\end{lemma}\n\n\\begin{proof}\n$ z - 1 / z = x + y\\sqrt{d} - \\br{x - y\\sqrt{d}} = 2y\\sqrt{d} $, so just need to check that $ z > z' $ if and only if $ z - 1 / z > z' - 1 / z' $. But $ z - 1 / z $ is increasing, since its derivative is $ 1 + 1 / z^2 > 0 $.\n\\end{proof}\n\n\\lecture{18}{Wednesday}{14/11/18}\n\nSuppose that there exists $ z \\in \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $, so $ z \\ne \\pm 1 $. By replacing $ z $ by $ \\pm z^{\\pm 1} $, we can assume that $ z > 1 $. So by Lemma \\ref{lem:62}, if $ z = x + y\\sqrt{d} $, then $ x, y > 0 $. Let\n$$ \\epsilon = x + y\\sqrt{d} \\in \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1}, \\qquad x, y > 0, $$\nwith $ y $ as small as possible. Call $ \\epsilon $ the \\textbf{fundamental $ 1 $-unit} of $ \\ZZ\\sbr{\\sqrt{d}} $.\n\n\\begin{proposition}\nSuppose that $ \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} \\ne \\cbr{\\pm 1} $, and let $ \\epsilon $ be the fundamental $ 1 $-unit. Then every element of $ \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $ is of the form $ \\pm\\epsilon^n $ for some $ n \\in \\ZZ $. Conversely, $ \\N\\br{\\pm\\epsilon^n} = \\N\\br{\\pm 1}\\N\\br{\\epsilon}^n = 1 $.\n\\end{proposition}\n\n\\begin{proof}\nLet $ z \\in \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $, so $ z \\ne \\pm 1 $. After replacing $ z $ by $ \\pm z^{\\pm 1} $, we may assume that $ z > 1 $. Choose $ n \\ge 0 $ such that $ \\epsilon^n \\le z < \\epsilon^{n + 1} $. Then $ 1 \\le z\\epsilon^{-n} < \\epsilon $, and $ \\N\\br{z\\epsilon^{-n}} = \\N\\br{z}\\N\\br{\\epsilon}^{-n} = 1 $. So $ z\\epsilon^{-n} \\in \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $. So by the choice of $ \\epsilon $, and Lemma \\ref{lem:63}, we have $ z\\epsilon^{-n} = 1 $, that is $ z = \\epsilon^n $.\n\\end{proof}\n\n\\begin{example*}\nLet $ d = 2 $ and $ x^2 - 2y^2 = 1 $. Then $ y = 2 $ and $ x = 3 $ is a solution. So $ \\epsilon = 3 + 2\\sqrt{2} $. Then $ \\epsilon^2 = \\br{3 + 2\\sqrt{2}}^2 = 17 + 12\\sqrt{2} $, and $ 17^2 - 2\\br{12}^2 = 1 $.\n\\end{example*}\n\n\\subsection{Constructing the fundamental \\texorpdfstring{$ 1 $}{1}-unit}\n\nThe idea is that if $ x^2 - dy^2 = 1 $ for $ x, y > 0 $, then $ x / y \\approx \\sqrt{d} $. Then $ \\abs{x - y\\sqrt{d}} = 1 / \\abs{x + y\\sqrt{d}} $, which is small. So one way to try to find $ 1 $-units is to find rational numbers which are good approximations to $ \\sqrt{d} $. Want to make $ \\abs{x / y - \\sqrt{d}} $ as small as possible for $ y $ of a given size. More generally, if $ \\alpha \\in \\RR \\setminus \\QQ $, we might want to find $ x, y > 0 $ such that\n$$ \\abs{\\dfrac{x}{y} - \\alpha} < \\dfrac{C}{y^n}, $$\nwhere $ C $ and $ n $ are fixed.\n\\begin{itemize}[leftmargin=1in]\n\\item[$ n = 0 $.] Trivial.\n\\item[$ n = 1 $, $ C = 1 $.] Trivial, by just choosing any $ y $ and $ x / y $ as close to $ \\alpha $ as you can.\n\\item[$ n = 2 $, $ C = 1 $.] Not obvious. In fact there always exist infinitely many $ x $ and $ y $ with $ \\abs{x / y - \\alpha} < 1 / y^2 $, as we now show.\n\\end{itemize}\n\n\\begin{theorem}[Dirichlet's theorem]\n\\label{thm:65}\nLet $ \\alpha \\in \\RR \\setminus \\QQ $, and let $ Q \\in \\ZZ_{> 1} $. Then there exist $ p, q \\in \\ZZ $, such that\n$$ 1 \\le q < Q, \\qquad \\abs{p - q\\alpha} < \\dfrac{1}{Q}. $$\n\\end{theorem}\n\n\\begin{proof}\nFor $ 1 \\le k \\le Q - 1 $, let $ a_k = \\fbr{k\\alpha} $. Then $ 0 < k\\alpha - a_k < 1 $. Consider the $ Q $ intervals\n$$ \\sbr{0, \\dfrac{1}{Q}}, \\qquad \\dots, \\qquad \\sbr{\\dfrac{Q - 1}{Q}, 1}. $$\nThe set\n$$ \\cbr{0, \\alpha - a_1, \\dots, \\br{Q - 1}\\alpha - a_{Q - 1}, 1}, $$\ncontains $ Q + 1 $ elements, so some pair of them must be in the same interval. The difference of these two elements is of the form $ p - q\\alpha $ for $ 1 \\le q < Q $.\n\\end{proof}\n\n\\pagebreak\n\n\\begin{corollary}\n\\label{cor:66}\nFor any $ \\alpha \\in \\RR \\setminus \\QQ $, there exist infinitely many pairs $ p, q \\in \\ZZ $ such that\n$$ \\abs{\\alpha - \\dfrac{p}{q}} < \\dfrac{1}{q^2}. $$\n\\end{corollary}\n\n\\begin{proof}\nCertainly there exists $ p $ for $ q = 1 $. It is then enough to prove that if $ \\abs{\\alpha - p / q} < 1 / q^2 $, there exist $ p' $ and $ q' $ such that\n$$ \\abs{\\alpha - \\dfrac{p'}{q'}} < \\dfrac{1}{\\br{q'}^2}, \\qquad \\abs{\\alpha - \\dfrac{p'}{q'}} < \\abs{\\alpha - \\dfrac{p}{q}}. $$\nChoose $ Q $ such that $ 1 / Q < \\abs{\\alpha - p / q} $. By Theorem \\ref{thm:65}, there exist $ p' $ and $ q' $ with\n$$ 1 \\le q' < Q, \\qquad \\abs{\\alpha - \\dfrac{p'}{q'}} < \\dfrac{1}{Qq'} < \\dfrac{1}{\\br{q'}^2}. $$\nAlso\n$$ \\abs{\\alpha - \\dfrac{p'}{q'}} < \\dfrac{1}{Qq'} \\le \\dfrac{1}{Q} < \\abs{\\alpha - \\dfrac{p}{q}}, $$\nas required.\n\\end{proof}\n\nWe can now show the following.\n\n\\begin{theorem}\nIf $ d > 1 $ is squarefree, then there exist $ x $ and $ y $ such that $ y \\ne 0 $ and $ x^2 - dy^2 = 1 $.\n\\end{theorem}\n\n\\begin{proof}\nBy Corollary \\ref{cor:66}, there exist infinitely many $ \\br{p_i, q_i} $ for $ p_i, q_i > 0 $ such that $ \\abs{p_i / q_i - \\sqrt{d}} < 1 / q_i^2 $, that is $ \\abs{p_i - q_i\\sqrt{d}} < 1 / q_i $. Then\n$$ \\abs{p_i + q_i\\sqrt{d}} \\le \\abs{p_i - q_i\\sqrt{d}} + 2q_i\\sqrt{d} < \\dfrac{1}{q_i} + 2q_i\\sqrt{d} < 3q_i\\sqrt{d}. $$\nSo\n$$ \\abs{\\N\\br{p_i + q_i\\sqrt{d}}} = \\abs{p_i + q_i\\sqrt{d}}\\abs{p_i - q_i\\sqrt{d}} < 3q_i\\sqrt{d}\\br{\\dfrac{1}{q_i}} = 3\\sqrt{d}. $$\nSo there exists $ M \\in \\br{-3\\sqrt{d}, 3\\sqrt{d}} $ such that $ \\N\\br{p_i + q_i\\sqrt{d}} = M $ for infinitely many $ i $. Then there exists $ \\br{p_0, q_0} $ such that\n$$ p_i \\equiv p_0 \\mod M, \\qquad q_i \\equiv q_0 \\mod M, $$\nfor infinitely many $ i $. Now consider $ \\br{p_i, q_i} \\ne \\br{p_j, q_j} $ of this form, that is\n$$ \\N\\br{p_i + q_i\\sqrt{d}} = \\N\\br{p_j + q_j\\sqrt{d}} = M, \\qquad p_i \\equiv p_j \\mod M, \\qquad q_i \\equiv q_j \\mod M. $$\nThen\n$$ \\dfrac{p_i - q_i\\sqrt{d}}{p_j - q_j\\sqrt{d}} = \\dfrac{\\br{p_i - q_i\\sqrt{d}}\\br{p_j + q_j\\sqrt{d}}}{M} = \\dfrac{\\br{p_ip_j - dq_iq_j} + \\br{p_iq_j - p_jq_i}\\sqrt{d}}{M}, $$\n$$ p_iq_j \\equiv p_jq_i \\mod M, \\qquad p_ip_j - dq_iq_j \\equiv p_i^2 - dq_i^2 = M \\equiv 0 \\mod M. $$\nSo\n$$ \\N\\br{\\dfrac{p_i - q_i\\sqrt{d}}{p_j - q_j\\sqrt{d}}} = \\dfrac{M}{M} = 1, $$\nso $ \\br{p_i - q_i\\sqrt{d}} / \\br{p_j - q_j\\sqrt{d}} \\in \\ZZ\\sbr{\\sqrt{d}}^{\\times, 1} $, as required.\n\\end{proof}\n\n\\subsection{The equation \\texorpdfstring{$ x^2 - dy^2 = - 1 $}{x2 - dy2 = -1}}\n\n\\lecture{19}{Friday}{16/11/18}\n\n$ x^2 - dy^2 = -1 $ has a solution if and only if there exists $ u \\in \\ZZ\\sbr{\\sqrt{d}}^\\times $ such that $ \\N\\br{u} = -1 $. Given such a $ u $, all solutions to the equation are given by $ \\pm u\\epsilon^n $ for $ n \\in \\ZZ $, since $ \\N\\br{v} = -1 $ if and only if $ \\N\\br{v} = \\N\\br{u} $, if and only if $ \\N\\br{v / u} = 1 $.\n\n\\begin{example*}\nIf $ d = 3 $, there are no solutions, as $ X^2 \\equiv -1 \\mod 3 $ has no solutions.\n\\end{example*}\n\n\\pagebreak\n\n\\section{Continued fractions}\n\n\\subsection{Rational continued fractions}\n\nLet $ p / q \\in \\QQ $. Write\n$$ \\dfrac{p}{q} = a_0 + r_0, \\qquad a_0 = \\fbr{\\dfrac{p}{q}} \\in \\ZZ, \\qquad 0 \\le r_0 < 1. $$\nIf $ r_i \\ne 0 $, write\n$$ \\dfrac{1}{r_i} = a_{i + 1} + r_{i + 1}, \\qquad a_{i + 1} = \\fbr{\\dfrac{1}{r_i}} \\in \\ZZ_{\\ge 1}, \\qquad 0 \\le r_{i + 1} < 1. $$\nEventually get some $ r_n = 0 $. Write\n$$ \\dfrac{p}{q} = a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{\\dots + \\dfrac{1}{a_n}}}. $$\n\n\\begin{example*}\n$$ \\dfrac{40}{19} = 2 + \\dfrac{2}{19}, \\qquad \\dfrac{19}{2} = 9 + \\dfrac{1}{2} \\qquad \\implies \\qquad \\dfrac{40}{19} = 2 + \\dfrac{1}{9 + \\dfrac{1}{2 + 0}}. $$\n\\end{example*}\n\n\\subsection{Infinite continued fractions}\n\nLet $ \\alpha \\in \\RR \\setminus \\QQ $. As above, set $ a_0 = \\fbr{\\alpha} $, write\n$$ \\alpha = a_0 + r_0, \\qquad a_0 = \\fbr{\\alpha} \\in \\ZZ, \\qquad 0 \\le r_0 < 1. $$\nDefine sequences $ a_i $ and $ r_i $ by\n$$ \\dfrac{1}{r_i} = a_{i + 1} + r_{i + 1}, \\qquad a_{i + 1} = \\fbr{\\dfrac{1}{r_i}} \\in \\ZZ_{\\ge 1}, \\qquad 0 \\le r_{i + 1} < 1. $$\nBy definition, $ a_i \\ge 1 $ if $ i > 0 $. Write\n$$ \\alpha = a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{a_2 + \\dfrac{1}{\\dots}}}. $$\n\n\\begin{example*}\nLet $ \\alpha = \\sqrt{3} $. Then\n\\begin{align*}\n& a_0 = 1, \\qquad r_0 = \\sqrt{3} - 1, \\qquad \\dfrac{1}{r_0} = \\dfrac{1}{\\sqrt{3} - 1} = \\dfrac{\\sqrt{3} + 1}{2} = 1 + \\dfrac{\\sqrt{3} - 1}{2}, \\\\\n& a_1 = 1, \\qquad r_1 = \\dfrac{\\sqrt{3} - 1}{2}, \\qquad \\dfrac{1}{r_1} = \\dfrac{2}{\\sqrt{3} - 1} = \\sqrt{3} + 1 = 2 + \\br{\\sqrt{3} - 1}, \\\\\n& a_2 = 2, \\qquad r_2 = \\sqrt{3} - 1 = r_0, \\qquad \\dfrac{1}{r_2} = \\dfrac{1}{\\sqrt{3} - 1} = \\dfrac{1}{r_0},\n\\end{align*}\nso\n$$ a_i =\n\\begin{cases}\n1 & i > 0 \\ \\text{odd} \\\\\n2 & i > 0 \\ \\text{even}\n\\end{cases}.\n$$\n\\end{example*}\n\nIf $ a_0, \\dots, a_n \\in \\RR $, then\n$$ \\sbr{a_0; a_1, \\dots, a_n} = a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{\\dots + \\dfrac{1}{a_n}}}. $$\n\n\\pagebreak\n\n\\begin{lemma}\n\\label{lem:68}\nIf $ a_0, \\dots, a_n \\in \\RR $, define $ p_i $ and $ q_i $ for $ 0 \\le i \\le n $ by\n$$ p_0 = a_0, \\qquad q_0 = 1, \\qquad p_1 = a_0a_1 + 1, \\qquad q_1 = a_1, \\qquad p_i = a_ip_{i - 1} + p_{i - 2}, \\qquad q_i = a_iq_{i - 1} + q_{i - 2}. $$\nAssuming that no $ q_i = 0 $, we have $ \\sbr{a_0; a_1, \\dots, a_n} = p_n / q_n $.\n\\end{lemma}\n\n\\begin{proof}\nInduction on $ n $.\n\\begin{itemize}[leftmargin=0.5in]\n\\item[$ n = 0 $.] $ a_0 = a_0 / 1 $ is trivial.\n\\item[$ n = 1 $.] $ a_0 + 1 / a_1 = \\br{a_0a_1 + 1} / a_1 $ is trivial.\n\\item[$ n > 1 $.] Define sequences $ p_i' $ and $ q_i' $ for $ 0 \\le i \\le n - 1 $ by applying the definition to the sequence\n$$ a_0, \\dots, a_{n - 2}, a_{n - 1} + \\dfrac{1}{a_n}. $$\nBy definition, $ p_i' = p_i $ and $ q_i' = q_i $ if $ i \\le n - 2 $. By induction,\n$$ \\sbr{a_0; a_1, \\dots, a_{n - 2}, a_{n - 1} + \\dfrac{1}{a_n}} = \\dfrac{p_{n - 1}'}{q_{n - 1}'}. $$\nBy definition,\n$$ \\sbr{a_0; a_1, \\dots, a_n} = \\sbr{a_0; a_1, \\dots, a_{n - 2}, a_{n - 1} + \\dfrac{1}{a_n}}. $$\nSo we only need to show that $ p_{n - 1}' / q_{n - 1}' = p_n / q_n $, and\n\\begin{align*}\n\\dfrac{p_{n - 1}'}{q_{n - 1}'}\n& = \\dfrac{\\br{a_{n - 1} + 1 / a_n}p_{n - 2}' + p_{n - 3}'}{\\br{a_{n - 1} + 1 / a_n}q_{n - 2}' + q_{n - 3}'}\n= \\dfrac{\\br{a_{n - 1} + 1 / a_n}p_{n - 2} + p_{n - 3}}{\\br{a_{n - 1} + 1 / a_n}q_{n - 2} + q_{n - 3}} \\\\\n& = \\dfrac{\\br{a_na_{n - 1} + 1}p_{n - 2} + a_np_{n - 3}}{\\br{a_na_{n - 1} + 1}q_{n - 2} + a_nq_{n - 3}}\n= \\dfrac{a_n\\br{a_{n - 1}p_{n - 2} + p_{n - 3}} + p_{n - 2}}{a_n\\br{a_{n - 1}q_{n - 2} + q_{n - 3}} + q_{n - 2}}\n= \\dfrac{a_np_{n - 1} + p_{n - 2}}{a_nq_{n - 1} + q_{n - 2}}\n= \\dfrac{p_n}{q_n}.\n\\end{align*}\n\\end{itemize}\n\\end{proof}\n\nSuppose now that $ a_i \\ge 1 $ if $ i \\ge 1 $. Then $ q_i = a_iq_{i - 1} + q_{i - 2} \\ge q_{i - 1} + q_{i - 2} $. So the $ q_i $ form an increasing sequence, in fact with $ q_i \\ge q_{i - 1} + q_{i - 2} \\ge 2q_{i - 2} $, so it even increases exponentially. If $ a_0, a_1, \\dots \\in \\RR $ is an infinite sequence with $ a_i \\ge 1 $ for all $ i $, say that $ p_i / q_i $ is the \\textbf{$ i $-th convergent} to\n$$ a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{a_2 + \\dfrac{1}{\\dots}}}. $$\n\n\\begin{lemma}\n\\label{lem:69}\nFor all $ n $,\n$$ p_nq_{n - 1} - q_np_{n - 1} = \\br{-1}^{n - 1}. $$\n\\end{lemma}\n\n\\begin{proof}\nObvious for $ n = 1 $. For the inductive step,\n\\begin{align*}\np_nq_{n - 1} - q_np_{n - 1}\n& = \\br{a_np_{n - 1} + p_{n - 2}}q_{n - 1} - \\br{a_nq_{n - 1} + q_{n - 2}}p_{n - 1} \\\\\n& = p_{n - 2}q_{n - 1} - q_{n - 2}p_{n - 1} \\\\\n& = -\\br{p_{n - 1}q_{n - 2} - q_{n - 1}p_{n - 2}}.\n\\end{align*}\n\\end{proof}\n\n\\begin{note*}\nIf $ a_i \\in \\ZZ $, then $ p_i, q_i \\in \\ZZ $, and Lemma \\ref{lem:69} implies that $ \\br{p_n, q_n} = 1 $. In general, Lemma \\ref{lem:69} implies that\n$$ \\abs{\\dfrac{p_n}{q_n} - \\dfrac{p_{n - 1}}{q_{n - 1}}} = \\dfrac{1}{q_nq_{n - 1}}. $$\nIf $ a_i \\ge 1 $ for all $ i \\ge 1 $, then the sequence $ q_i $ increases exponentially. So $ \\sum_{i = 1}^n 1 / q_iq_{i - 1} $ converges, so that $ \\br{p_n / q_n} $ is a Cauchy sequence, so it converges.\n\\end{note*}\n\n\\pagebreak\n\n\\lecture{20}{Tuesday}{20/11/18}\n\n\\begin{lemma}\n\\label{lem:70}\nLet $ \\alpha \\in \\RR \\setminus \\QQ $, and let $ \\sbr{a_0; a_1, a_2, \\dots} $ be the corresponding continued fraction. Then $ p_n / q_n < \\alpha $ if $ n $ is even, and $ p_n / q_n > \\alpha $ if $ n $ is odd.\n\\end{lemma}\n\n\\begin{proof}\nInduction on $ n $.\n\\begin{itemize}[leftmargin=0.5in]\n\\item[$ n = 0 $.] $ a_0 = \\fbr{\\alpha} < \\alpha $ and $ p_0 / q_0 = a_0 / 1 = a_0 $.\n\\item[$ n $ odd.] By induction, we have $ \\sbr{a_1; a_2, \\dots, a_n} < 1 / \\br{\\alpha - a_0} $, since $ \\alpha = a_0 + 1 / \\br{a_1 + 1 / \\dots} $. That is, $ \\alpha - a_0 < 1 / \\sbr{a_1; a_2, \\dots, a_n} $, that is\n$$ \\alpha < a_0 + \\dfrac{1}{\\sbr{a_1; a_2, \\dots, a_n}} = \\sbr{a_0; a_1, \\dots, a_n} = \\dfrac{p_n}{q_n}. $$\n\\item[$ n $ even.] The same argument with $ > $.\n\\end{itemize}\n\\end{proof}\n\n\\begin{corollary}\nAssume $ \\alpha \\in \\RR \\setminus \\QQ $ and $ a_0, a_1, \\dots \\in \\ZZ $ be coming from its continued fraction. Let $ p_n / q_n = \\sbr{a_0; a_1, \\dots, a_n} $ be the $ n $-th convergent. Then\n$$ \\abs{\\alpha - \\dfrac{p_n}{q_n}} < \\dfrac{1}{q_nq_{n + 1}}. $$\nIn particular, $ p_n / q_n \\to \\alpha $ as $ n \\to \\infty $.\n\\end{corollary}\n\n\\begin{proof}\nEither $ p_n / q_n < \\alpha < p_{n + 1} / q_{n + 1} $ or $ p_n / q_n > \\alpha > p_{n + 1} / q_{n + 1} $, by Lemma \\ref{lem:70}. Either way,\n$$ \\abs{\\dfrac{p_n}{q_n} - \\alpha} < \\abs{\\dfrac{p_n}{q_n} - \\dfrac{p_{n + 1}}{q_{n + 1}}} \\le \\dfrac{1}{q_nq_{n + 1}}, $$\nby Lemma \\ref{lem:69}.\n\\end{proof}\n\n\\begin{note*}\n$ 1 / q_nq_{n + 1} < 1 / q_n^2 $, so the sequence $ \\br{p_n / q_n} $ satisfies the requirements of Dirichlet's theorem.\n\\end{note*}\n\n\\subsection{Best approximations}\n\nFix $ \\alpha \\in \\RR \\setminus \\QQ $. Define $ a_i $ and $ r_i $ by\n$$ \\alpha = a_0 + r_0, \\qquad a_0 = \\fbr{\\alpha} \\in \\ZZ, \\qquad 0 < r_0 < 1, $$\nIf $ i \\ge 1 $,\n$$ \\dfrac{1}{r_i} = a_{i + 1} + r_{i + 1}, \\qquad a_{i + 1} = \\fbr{\\dfrac{1}{r_i}} \\in \\ZZ_{\\ge 1}, \\qquad 0 < r_{i + 1} < 1. $$\n\n\\begin{lemma}\n\\label{lem:72}\nFor all $ n $,\n$$ \\alpha = \\dfrac{p_n + p_{n - 1}r_n}{q_n + q_{n - 1}r_n}. $$\n\\end{lemma}\n\n\\begin{proof}\n$ \\alpha = \\sbr{a_0; a_1, \\dots, a_n, 1 / r_n} $, so set $ p_{n + 1} = p_n / r_n + p_{n - 1} $ and $ q_{n + 1} = q_n / r_n + q_{n - 1} $. Then by Lemma \\ref{lem:68},\n$$ \\alpha = \\dfrac{p_{n + 1}}{q_{n + 1}} = \\dfrac{p_n / r_n + p_{n - 1}}{q_n / r_n + q_{n - 1}} = \\dfrac{p_n + p_{n - 1}r_n}{q_n + q_{n - 1}r_n}. $$\n\\end{proof}\n\n\\begin{corollary}\nFor all $ n $,\n$$ \\abs{\\alpha q_n - p_n} < \\abs{\\alpha q_{n - 1} - p_{n - 1}}, \\qquad \\abs{\\alpha - \\dfrac{p_n}{q_n}} < \\abs{\\alpha - \\dfrac{p_{n - 1}}{q_{n - 1}}}. $$\n\\end{corollary}\n\n\\begin{proof}\nBy Lemma \\ref{lem:72}, $ \\alpha\\br{q_n + q_{n - 1}r_n} = p_n + p_{n - 1}r_n $, so $ \\alpha q_n - p_n = r_n\\br{p_{n - 1} - \\alpha q_{n - 1}} $. So $ \\abs{\\alpha q_n - p_n} = r_n\\abs{\\alpha q_{n - 1} - p_{n - 1}} < \\abs{\\alpha q_{n - 1} - p_{n - 1}} $, so\n$$ \\abs{\\alpha - \\dfrac{p_n}{q_n}} = \\dfrac{1}{q_n}\\abs{\\alpha q_n - p_n} < \\dfrac{1}{q_n}\\abs{\\alpha q_{n - 1} - p_{n - 1}} < \\dfrac{1}{q_{n - 1}}\\abs{\\alpha q_{n - 1} - p_{n - 1}} = \\abs{\\alpha - \\dfrac{p_{n - 1}}{q_{n - 1}}}. $$\n\\end{proof}\n\n\\pagebreak\n\n\\begin{theorem}\n\\label{thm:74}\nLet $ h, k \\in \\ZZ $ and $ 0 < \\abs{k} < q_{n + 1} $. Then\n$$ \\abs{k\\alpha - h} \\ge \\abs{\\alpha q_n - p_n}, $$\nwith equality only if $ \\abs{k} = q_n $. If $ \\abs{k} \\le q_n $, then\n$$ \\abs{\\dfrac{h}{k} - \\alpha} \\ge \\abs{\\dfrac{p_n}{q_n} - \\alpha}, $$\nwith equality if and only if $ h / k = p_n / q_n $.\n\\end{theorem}\n\n\\begin{proof}\nBy Lemma \\ref{lem:69} there exist $ u, v \\in \\ZZ $ such that $ h = up_n + vp_{n + 1} $ and $ k = uq_n + vq_{n + 1} $, since\n$$ \\twobyone{h}{k} = \\twobytwo{p_n}{p_{n + 1}}{q_n}{q_{n + 1}}\\twobyone{u}{v} \\qquad \\iff \\qquad \\twobyone{u}{v} = \\twobytwo{p_n}{p_{n + 1}}{q_n}{q_{n + 1}}^{-1}\\twobyone{h}{k} = \\dfrac{1}{\\br{-1}^n}\\twobytwo{q_{n + 1}}{-p_{n + 1}}{-q_n}{p_n}\\twobyone{h}{k}. $$\nBy assumption, $ 0 < \\abs{k} < q_{n + 1} $. So $ u \\ne 0 $, else $ k = vq_{n + 1} $, so $ \\abs{v} < 1 $ is a contradiction. If $ v \\ne 0 $, then $ u $ and $ v $ have opposite signs, else\n$$ \\abs{k} = \\abs{uq_n} + \\abs{vq_{n + 1}} \\ge q_n + q_{n + 1} > q_{n + 1}. $$\nIf $ v = 0 $, then $ h = up_n $ and $ k = uq_n $, and everything is easy. If $ v \\ne 0 $, then write\n$$ k\\alpha - h = u\\br{\\alpha q_n - p_n} + v\\br{\\alpha q_{n + 1} - p_{n + 1}}. $$\nThen $ u $ and $ v $ have opposite signs. By Lemma \\ref{lem:70}, $ \\alpha q_n - p_n $ and $ \\alpha q_{n + 1} - p_{n + 1} $ also have opposite signs. So $ u\\br{\\alpha q_n - p_n} $ and $ v\\br{\\alpha q_{n + 1} - p_{n + 1}} $ have the same sign. So\n$$ \\abs{k\\alpha - h} = \\abs{u\\br{\\alpha q_n - p_n}} + \\abs{v\\br{\\alpha q_{n + 1} - p_{n + 1}}} > \\abs{\\alpha q_n - p_n}, $$\nif $ u, v \\ne 0 $. For the last part, if $ \\abs{k} \\le q_n $ then $ 1 / \\abs{k} \\ge 1 / q_n $. So $ \\abs{k\\alpha - h} / \\abs{k} \\ge \\abs{q_n\\alpha - p_n} / q_n $, that is $ \\abs{\\alpha - h / k} \\ge \\abs{\\alpha - p_n / q_n} $.\n\\end{proof}\n\n\\begin{corollary}\n\\label{cor:75}\nIf $ h, k \\in \\ZZ $ with $ \\abs{\\alpha - h / k} < 1 / 2k^2 $, then\n$$ \\dfrac{h}{k} = \\dfrac{p_n}{q_n}, $$\nfor some $ n $.\n\\end{corollary}\n\n\\begin{proof}\nWithout loss of generality $ k \\ge 1 $, and $ q_n \\le k < q_{n + 1} $ for some $ n $. Then\n\\begin{align*}\n\\abs{\\dfrac{p_n}{q_n} - \\dfrac{h}{k}}\n& \\le \\abs{\\dfrac{p_n}{q_n} - \\alpha} + \\abs{\\alpha - \\dfrac{h}{k}}\n= \\dfrac{1}{q_n}\\abs{\\alpha q_n - p_n} + \\dfrac{1}{k}\\abs{\\alpha k - h} \\\\\n& \\le \\br{\\dfrac{1}{q_n} + \\dfrac{1}{k}}\\abs{\\alpha k - h}\n= k\\br{\\dfrac{1}{q_n} + \\dfrac{1}{k}}\\abs{\\alpha - \\dfrac{h}{k}}\n< \\dfrac{1}{2k}\\abs{\\dfrac{1}{q_n} + \\dfrac{1}{k}}\n\\le \\dfrac{1}{kq_n},\n\\end{align*}\nby Theorem \\ref{thm:74}. So $ \\abs{p_n / q_n - h / k} < 1 / kq_n $. So $ p_n / q_n - h / k = 0 $, as required.\n\\end{proof}\n\n\\subsection{Returning to Pell's equation}\n\n\\lecture{21}{Wednesday}{21/11/18}\n\nPell's equation is $ x^2 - dy^2 = 1 $. If $ \\br{x, y} $ is a solution, then $ \\abs{\\sqrt{d} - x / y} $ is small.\n\n\\begin{proposition}\nLet $ d > 1 $ be squarefree, and let $ p_n / q_n $ be the sequence of convergents for the continued fraction for $ \\sqrt{d} $. If $ x, y > 0 $ with $ x^2 - dy^2 = \\pm 1 $, then $ x = p_n $ and $ y = q_n $ for some $ n $.\n\\end{proposition}\n\n\\begin{proof}\n\\hfill\n\\begin{itemize}\n\\item Firstly suppose $ x^2 - dy^2 = 1 $. It is enough to show that $ x / y = p_n / q_n $ for some $ n $. Since $ \\br{p_n, q_n} = 1 $, this implies that $ x = rp_n $ and $ y = rq_n $ for some $ r $, and then $ 1 = x^2 - dy^2 = r^2\\br{p_n^2 - dq_n^2} $, so $ r = 1 $. By Corollary \\ref{cor:75}, it suffices to prove that $ \\abs{\\sqrt{d} - x / y} < 1 / 2y^2 $. Since $ x - y\\sqrt{d} = 1 / \\br{x + y\\sqrt{d}} > 0 $, so $ x > y\\sqrt{d} $, and $ x / y > \\sqrt{d} $. So\n$$ \\abs{\\dfrac{x}{y} - \\sqrt{d}} = \\dfrac{x}{y} - \\sqrt{d} = \\dfrac{1}{y}\\br{x - y\\sqrt{d}} = \\dfrac{1}{y}\\br{\\dfrac{1}{x + y\\sqrt{d}}} < \\dfrac{1}{y}\\br{\\dfrac{1}{y\\sqrt{d} + y\\sqrt{d}}} = \\dfrac{1}{2\\sqrt{d}y^2} < \\dfrac{1}{2y^2}. $$\n\n\\pagebreak\n\n\\item Now assume $ x^2 - dy^2 = -1 $. Again enough to show that $ x / y = p_n / q_n $. Trick is to rewrite as $ y^2 - x^2 / d = 1 / d $. Then $ y - x / \\sqrt{d} = \\br{1 / d} / \\br{y + x / \\sqrt{d}} > 0 $. So $ y > x / \\sqrt{d} $, so\n$$ \\abs{\\dfrac{y}{x} - \\dfrac{1}{\\sqrt{d}}} = \\dfrac{y}{x} - \\dfrac{1}{\\sqrt{d}} = \\dfrac{1}{x}\\br{y - \\dfrac{x}{\\sqrt{d}}} = \\dfrac{1}{x}\\br{\\dfrac{1 / d}{y + x / \\sqrt{d}}} < \\dfrac{1}{x}\\br{\\dfrac{1 / d}{x / \\sqrt{d} + x / \\sqrt{d}}} = \\dfrac{1 / \\sqrt{d}}{2x^2} < \\dfrac{1}{2x^2}. $$\nSo Corollary \\ref{cor:75} implies that $ y / x $ is a convergent for the continued fraction of $ 1 / \\sqrt{d} $. Then $ \\fbr{1 / \\sqrt{d}} = 0 $, so the continued fraction for $ 1 / \\sqrt{d} $ is of the form $ \\sbr{0; a_0, a_1, \\dots} $. The next step is $ 1 / \\br{1 / \\sqrt{d}} = \\sqrt{d} $. So if $ \\sqrt{d} = \\sbr{a_0; a_1, a_2, \\dots} $, then $ 1 / \\sqrt{d} = \\sbr{0; a_0, a_1, \\dots} $, since\n$$ \\sqrt{d} = a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{a_2 + \\dfrac{1}{\\dots}}}, \\qquad \\dfrac{1}{\\sqrt{d}} = 0 + \\dfrac{1}{a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{\\dots}}}. $$\nSo the convergents for $ 1 / \\sqrt{d} $ are the $ q_n / p_n $. So $ y / x = q_n / p_n $ for some $ n $, and $ x / y = p_n / q_n $.\n\\end{itemize}\n\\end{proof}\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item $ \\sqrt{3} = \\sbr{1; 1, 2, 1, 2, \\dots} = \\sbr{1; \\overline{1, 2}} $.\n\\item $ \\sqrt{2} = 1 + \\br{\\sqrt{2} - 1} $, $ 1 / \\br{\\sqrt{2} - 1} = \\sqrt{2} + 1 = 2 + \\br{\\sqrt{2} - 1} $, so $ \\sqrt{2} = \\sbr{1; \\overline{2}} $.\n\\item $ \\sqrt{5} = 2 + \\br{\\sqrt{5} - 2} $, $ 1 / \\br{\\sqrt{5} - 2} = \\sqrt{5} + 2 = 4 + \\br{\\sqrt{5} - 2} $, so $ \\sqrt{5} = \\sbr{2; \\overline{4}} $.\n\\item $ \\sqrt{7} = \\sbr{2; \\overline{1, 1, 1, 4}} $.\n\\item $ \\sqrt{13} = \\sbr{3; \\overline{1, 1, 1, 1, 6}} $.\n\\item $ \\sqrt{43} = \\sbr{6; \\overline{1, 1, 3, 1, 5, 1, 3, 1, 1, 12}} $.\n\\end{itemize}\n\\end{example*}\n\n\\begin{definition}\nWe say that $ \\sbr{a_0; a_1, a_2, \\dots} $ is \\textbf{eventually periodic} if there exist $ N, d > 0 $ such that $ a_{n + d} = a_n $ for all $ n \\ge N $. We say that it is \\textbf{periodic} if we can take $ N = 0 $.\n\\end{definition}\n\n\\begin{fact}\nThe following are facts.\n\\begin{itemize}\n\\item The continued fraction of $ \\sqrt{d} $ is eventually periodic.\n\\item In fact, it is of the form\n$$ \\sbr{a_0; \\overline{a_1, \\dots, a_{m - 1}, 2a_0}}. $$\n\\item $ a_1, \\dots, a_{m - 1} $ is symmetric, that is $ a_i = a_{m - i} $ for $ 1 \\le i \\le m - 1 $.\n\\item The $ n $ for which $ p_n^2 - dq_n^2 = \\pm 1 $ are exactly the $ n $ for which $ n \\equiv -1 \\mod m $. If $ n = lm - 1 $, then\n$$ p_n^2 - dq_n^2 = \\br{-1}^{lm}. $$\n\\item The fundamental $ 1 $-unit is\n$$\n\\begin{cases}\np_{m - 1} + q_{m - 1}\\sqrt{d} & m \\ \\text{even} \\\\\np_{2m - 1} + q_{2m - 1}\\sqrt{d} & m \\ \\text{odd}\n\\end{cases}.\n$$\n\\item There is a solution to $ x^2 - dy^2 = -1 $ if and only if $ m $ is odd, in which case the solutions are\n$$ \\br{x, y} = \\br{p_n, q_n}, \\qquad n \\equiv m - 1 \\mod 2m. $$\n\\end{itemize}\n\\end{fact}\n\n\\pagebreak\n\n\\begin{example*}\n\\hfill\n\\begin{itemize}\n\\item Let $ x^2 - 43y^2 = \\pm 1 $, so $ m = 10 $ is even, so there are no solutions to $ x^2 - 43y^2 = -1 $. The smallest solution for $ x^2 - 43y^2 = 1 $ is $ p_9 $ and $ q_9 $. Then\n$$\n\\begin{array}{c|cccccccccc}\ni & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n\\hline\na & 6 & 1 & 1 & 3 & 1 & 5 & 1 & 3 & 1 & 1 \\\\\np & 6 & 7 & 13 & 46 & 59 & 341 & 400 & 1541 & 1941 & 3482 \\\\\nq & 1 & 1 & 2 & 7 & 9 & 52 & 61 & 235 & 296 & 531\n\\end{array},\n$$\nso $ p_9 = 3482 $, so $ 3482^2 - 43\\br{531}^2 = 1 $ is the smallest solution.\n\\item For $ 13 $, $ m = 5 $ so $ p_4 $ and $ q_4 $ is the smallest solution for $ x^2 - 13y^2 = -1 $ and $ p_9 $ and $ q_9 $ is the smallest solution for $ x^2 - 13y^2 = 1 $. Then\n$$\n\\begin{array}{c|ccccc}\ni & 0 & 1 & 2 & 3 & 4 \\\\\n\\hline\na & 3 & 1 & 1 & 1 & 1 \\\\\np & 3 & 4 & 7 & 11 & 18 \\\\\nq & 1 & 1 & 2 & 3 & 5\n\\end{array},\n$$\nso $ 18^2 - 13\\br{5}^2 = -1 $ is the smallest solution, and $ \\N\\br{18 + 5\\sqrt{13}} = -1 $, so\n$$ \\N\\br{\\br{18 + 5\\sqrt{13}}^2} = \\N\\br{649 + 180\\sqrt{13}} = 1. $$\nIn fact, it follows from our facts that this is the fundamental $ 1 $-unit, that is $ p_9 + q_9\\sqrt{13} $.\n\\end{itemize}\n\\end{example*}\n\n\\subsection{Periodic continued fractions}\n\n\\lecture{22}{Friday}{23/11/18}\n\n\\begin{definition}\n$ \\alpha \\in \\RR \\setminus \\QQ $ is a \\textbf{quadratic irrational} if it is a root of some $ aX^2 + bX + c = 0 $, for $ a, b, c \\in \\QQ $ not all zero.\n\\end{definition}\n\n\\begin{proposition}\nIf $ \\alpha $ has an eventually periodic continued fraction, then $ \\alpha $ is a quadratic irrational.\n\\end{proposition}\n\n\\begin{proof}\n\\hfill\n\\begin{itemize}\n\\item Suppose firstly that the continued fraction of $ \\alpha $ is periodic. Suppose $ a_{n + d} = a_n $ for all $ n $, for some $ d \\ge 1 $. Then\n$$ \\alpha = a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{\\dots + \\dfrac{1}{a_{d - 1} + \\dfrac{1}{\\alpha}}}}. $$\nThis gives an equation of the form $ \\alpha = \\br{x\\alpha + y} / \\br{z\\alpha + w} $ for $ w, x, y, z \\in \\ZZ $, by applying Lemma \\ref{lem:72} to $ \\sbr{a_0; a_1, \\dots, a_{d - 1}, \\alpha} $. Then $ \\br{z\\alpha + w}\\alpha - \\br{x\\alpha + y} = 0 $, that is $ z\\alpha^2 + \\br{w - x}\\alpha - y = 0 $. Since $ \\alpha \\in \\RR \\setminus \\QQ $, we conclude that $ \\alpha $ is a quadratic irrational.\n\\item Suppose now that $ \\alpha $ is only eventually periodic. Then\n$$ \\alpha = a_0 + \\dfrac{1}{a_1 + \\dfrac{1}{\\dots + \\dfrac{1}{a_N + \\dfrac{1}{\\beta}}}}, $$\nwhere $ \\beta $ has a periodic continued fraction. So $ \\beta $ is a quadratic irrational. To complete the proof, we need to show that if $ \\gamma $ is a quadratic irrational, then $ 1 / \\gamma $ and $ \\gamma + n $ are quadratic irrationals for any $ n \\in \\ZZ $. If $ \\gamma $ is a root of $ aX^2 + bX + c = 0 $, then $ 1 / \\gamma $ is a root of $ cX^2 + bX + a = 0 $, and $ \\gamma + n $ is a root of $ a\\br{X - n}^2 + b\\br{X - n} + c = 0 $.\n\\end{itemize}\n\\end{proof}\n\nIn fact, the converse is also true. All quadratic irrationals have eventually periodic continued fractions.\n\n\\pagebreak\n\n\\section{Diophantine approximation}\n\n\\subsection{Liouville's theorem}\n\n\\begin{definition}\nLet $ d \\in \\ZZ_{\\ge 1} $. Then $ \\alpha \\in \\CC $ is \\textbf{algebraic of degree $ d $} if there exists a polynomial of degree $ d $ with integer coefficients and $ \\alpha $ as a root, and there does not exist such a polynomial of smaller degree.\n\\end{definition}\n\n\\begin{example*}\n$ d = 1 $ is $ \\QQ $ and $ d = 2 $ is the quadratic irrationals.\n\\end{example*}\n\n\\begin{theorem}[Liouville's theorem]\nLet $ \\alpha \\in \\RR $ be algebraic of degree $ d $. Then for any $ e \\in \\RR_{> d} $, there are only finitely many $ p / q \\in \\QQ $ with\n$$ \\abs{\\dfrac{p}{q} - \\alpha} < \\dfrac{1}{q^e}. $$\n\\end{theorem}\n\n\\begin{proof}\nLet $ P\\br{X} $ be a polynomial of degree $ d $ with coefficients in $ \\ZZ $, with $ P\\br{\\alpha} = 0 $. Choose $ \\epsilon > 0 $ such that the only root of $ P\\br{X} $ in $ \\sbr{\\alpha - \\epsilon, \\alpha + \\epsilon} $ is $ \\alpha $. Write $ P\\br{X} = \\br{X - \\alpha}Q\\br{X} $. Then $ Q\\br{X} $ is a polynomial of degree $ d - 1 $ with real coefficients, so in particular it is continuous, so there exists $ K $ such that $ \\abs{Q\\br{x}} \\le K $ for $ x \\in \\sbr{\\alpha - \\epsilon, \\alpha + \\epsilon} $. Assume that $ \\abs{p / q - \\alpha} < 1 / q^e $. We may assume that $ q $ is large enough that $ 1 / q^e < \\epsilon $. Since $ P $ has integer coefficients and is of degree $ d $, we have $ \\abs{P\\br{p / q}} \\ge 1 / q^d $. Note that $ P\\br{p / q} \\ne 0 $, or we could replace $ P $ by $ P' $ with $ P\\br{X} = \\br{qX - p}P'\\br{X} $. Since $ \\abs{p / q - \\alpha} < \\epsilon $, $ p / q \\in \\sbr{\\alpha - \\epsilon, \\alpha + \\epsilon} $, so\n$$ \\dfrac{1}{q^d} \\le \\abs{P\\br{\\dfrac{p}{q}}} = \\abs{\\dfrac{p}{q} - \\alpha} \\abs{Q\\br{\\dfrac{p}{q}}} \\le K \\abs{\\dfrac{p}{q} - \\alpha} < \\dfrac{K}{q^e}. $$\nSo $ K > q^{e - d} $, so $ K^{1 / \\br{e - d}} > q $. So there are only finitely many possible $ q $, so only finitely many $ p / q $.\n\\end{proof}\n\n\\subsection{Constructing transcendentals}\n\nRecall that $ \\alpha \\in \\CC $ is \\textbf{algebraic} if it is algebraic of some degree $ d $, and otherwise it is \\textbf{transcendental}. The set of polynomials with integer coefficients is countable, so the set of algebraic numbers is countable. Since $ \\RR $ is uncountable, transcendental numbers exist. Liouville's theorem gives a criterion. If for every $ e > 0 $, there are infinitely many $ p / q $ with $ \\abs{\\alpha - p / q} < 1 / q^e $, then $ \\alpha $ cannot be algebraic.\n\n\\begin{example*}\nLet $ \\alpha = \\sum_{n \\ge 1} 10^{-n!} $ and $ \\alpha_k = \\sum_{n = 1}^k 10^{-n!} $. Then $ \\alpha_k $ is rational with denominator $ q = 10^{k!} $, and\n$$ \\abs{\\alpha - \\alpha_k} = \\sum_{n = k + 1}^\\infty \\dfrac{1}{10^{n!}} = \\dfrac{1}{10^{\\br{k + 1}!}}\\br{1 + \\dfrac{1}{10^{\\br{k + 2}! - \\br{k + 1}!}} + \\dots} = \\dfrac{1}{q^{k + 1}}\\br{1 + \\dfrac{1}{10^{k + 1}} + \\dots} < \\dfrac{2}{q^{k + 1}}. $$\nIf $ d \\in \\ZZ_{> 0} $, and $ k > d $, then $ 2 / q^{k + 1} < 1 / q^d $. So there exist infinitely many $ p / q = \\alpha_k $ such that $ \\abs{\\alpha - p / q} < 1 / q^d $. Take $ d $ arbitrarily large, so $ \\alpha $ is transcendental.\n\\end{example*}\n\n\\subsection{Roth's theorem}\n\n\\lecture{23}{Tuesday}{27/11/18}\n\n\\begin{theorem}[Roth's theorem]\nSuppose that $ \\alpha $ is algebraic. Then for any $ \\epsilon > 0 $, there exist only finitely many $ x / y \\in \\QQ $ with $ \\abs{\\alpha - x / y} < 1 / y^{2 + \\epsilon} $.\n\\end{theorem}\n\nThis can be used to show that many more numbers are transcendental than Liouville's theorem could.\n\n\\begin{example*}\n$ \\sum_{n \\ge 1} 10^{-3^n} $ is transcendental.\n\\end{example*}\n\n\\begin{example*}\nWe saw that if $ d > 1 $ is squarefree, then $ x^2 - dy^2 = 1 $ has infinitely many solutions with $ x, y \\in \\ZZ $. Suppose now that $ d > 1 $, and consider $ x^3 - dy^3 = 1 $.\n\\begin{itemize}\n\\item $ d = e^3 $ is a cube. Then $ x^3 - dy^3 = x^3 - \\br{ey}^3 = 1 $, so either $ \\br{x, y} = \\br{1, 0} $ or $ \\br{x, y} = \\br{0, 1} $ and $ d = 1 $.\n\\item $ d $ is not a cube. Then $ \\sqrt[3]{d} \\in \\RR \\setminus \\QQ $ is algebraic, as $ X^3 - d = 0 $. Suppose $ x > 1 $, so $ x > \\sqrt[3]{d}y $. Then\n$$ x - \\sqrt[3]{d}y = \\dfrac{x^3 - dy^3}{x^2 + x\\sqrt[3]{d}y + \\sqrt[3]{d^2}y^2} = \\dfrac{1}{x^2 + x\\sqrt[3]{d}y + \\sqrt[3]{d^2}y^2} < \\dfrac{1}{3\\sqrt[3]{d^2}y^2} = \\dfrac{1}{3\\sqrt[3]{d^2}y^2}. $$\nSo $ \\abs{x / y - \\sqrt[3]{d}} < 1 / 3\\sqrt[3]{d^2}y^3 $. Choose any $ 0 < \\epsilon < 1 $. Then $ 1 / 3\\sqrt[3]{d^2}y^3 < 1 / y^{2 + \\epsilon} $, for all $ y $ sufficiently large. So Roth's theorem tells us that there are only finitely many solutions. Similarly if $ x < 0 $.\n\\end{itemize}\n\\end{example*}\n\n\\pagebreak\n\n\\section{Primes in arithmetic progressions}\n\n\\subsection{Primes in arithmetic progressions}\n\nA question is how are the prime numbers distributed modulo $ n $? Are there infinitely many primes congruent to $ a \\mod n $ for each $ a $ and $ n $? The answer is no in general.\n\n\\begin{example*}\nThere are finitely many primes congruent to $ 2 \\mod 4 $, or $ 0 \\mod 2 $.\n\\end{example*}\n\nIf $ \\br{a, n} \\ne 1 $ then since any number is congruent to $ a \\mod n $ is divisible by $ \\br{a, n} $, we can have at most one prime. If $ \\br{a, n} = 1 $, there is no obvious obstruction.\n\n\\begin{example*}\nThere are infinitely many primes congruent to $ 1 \\mod 2 $.\n\\end{example*}\n\n\\begin{theorem}[Dirichlet's theorem]\nIf $ \\br{a, n} = 1 $, then there are infinitely many primes congruent to $ a \\mod n $.\n\\end{theorem}\n\nWe will prove this for $ a = 1 $.\n\n\\subsection{Elementary results}\n\n\\begin{theorem}\nThere are infinitely many primes.\n\\end{theorem}\n\n\\begin{proof}\nLet $ S $ be a finite set of primes, and let\n$$ Q = 1 + \\prod_{p \\in S} p. $$\nThen $ Q > 1 $, so it has a prime factor $ q $. Then $ q \\notin S $, so we are done.\n\\end{proof}\n\n\\begin{theorem}\nThere are infinitely many primes congruent to $ 3 \\mod 4 $.\n\\end{theorem}\n\n\\begin{proof}\nLet $ S $ be a finite set of primes which are congruent to $ 3 \\mod 4 $. Let\n$$ Q = 2 + \\prod_{p \\in S} p^2. $$\nThen $ Q > 1 $, and $ Q \\equiv 3 \\mod 4 $, so $ Q $ has a prime factor $ q $ which has $ q \\equiv 3 \\mod 4 $. Then $ q \\notin S $, so we are done.\n\\end{proof}\n\n\\begin{lemma}\n\\label{lem:87}\nLet $ x $ be even, and $ p $ be a prime factor of $ x^2 + 1 $, then $ p \\equiv 1 \\mod 4 $.\n\\end{lemma}\n\n\\begin{proof}\nCertainly $ p $ is odd. Then $ x^2 + 1 \\equiv 0 \\mod p $, so $ x^2 \\equiv -1 \\mod p $, so $ \\jacobi{-1}{p} = 1 $, so $ p \\equiv 1 \\mod 4 $.\n\\end{proof}\n\n\\begin{theorem}\nThere are infinitely many primes congruent to $ 1 \\mod 4 $.\n\\end{theorem}\n\n\\begin{proof}\nLet $ S $ be a finite set of primes congruent to $ 1 \\mod 4 $. Let\n$$ Q = 1 + 4\\prod_{p \\in S} p^2 = 1 + \\br{2\\prod_{p \\in S} p}^2. $$\nThen $ Q > 1 $, and if $ q $ is a prime factor of $ Q $ then $ q \\notin S $, and $ q \\equiv 1 \\mod 4 $ by Lemma \\ref{lem:87}.\n\\end{proof}\n\nThe general idea is to find a polynomial $ P\\br{x} $ such that every prime factor of $ P\\br{nx} $ is congruent to $ a \\mod n $, or at least one. Turns out that this can be done only when $ a^2 \\equiv 1 \\mod n $. We will find such polynomials for $ a = 1 $.\n\n\\begin{theorem}\nFor any prime $ q $, there are infinitely many primes congruent to $ 1 \\mod q $.\n\\end{theorem}\n\n\\begin{definition}\nThe $ q $-th \\textbf{cyclotomic polynomial} is\n$$ \\Phi_q\\br{X} = \\dfrac{X^q - 1}{X - 1} = X^{q - 1} + \\dots + 1. $$\n\\end{definition}\n\n\\pagebreak\n\n\\begin{theorem}\n\\label{thm:91}\nLet $ p \\ne q $ be prime, and let $ a \\in \\ZZ $. Then $ p \\mid \\Phi_q\\br{a} $ if and only if $ a $ has order $ q \\mod p $.\n\\end{theorem}\n\n\\begin{proof}\n$ a $ has order $ q \\mod p $ if and only if $ a^q \\equiv 1 \\mod p $ and $ a \\not\\equiv 1 \\mod p $. If $ p \\mid \\Phi_q\\br{a} $ then $ p \\mid a^q - 1 $. If also $ a \\equiv 1 \\mod p $, then $ \\Phi_q\\br{a} \\equiv \\Phi_q\\br{1} \\equiv q \\not\\equiv 0 \\mod p $, a contradiction. Conversely if $ a^q \\equiv 1 \\mod p $ and $ a \\not\\equiv 1 \\mod p $, then $ \\br{a^q - 1} / \\br{a - 1} \\equiv 0 \\mod p $.\n\\end{proof}\n\n\\lecture{24}{Wednesday}{28/11/18}\n\n\\begin{corollary}\n\\label{cor:92}\nIf $ p \\ne q $ is prime, and $ a \\in \\ZZ $, and $ p \\mid \\Phi_q\\br{a} $, then $ p \\equiv 1 \\mod q $.\n\\end{corollary}\n\n\\begin{proof}\nBy Theorem \\ref{thm:91}, $ a $ has order $ q \\mod p $. But $ a^{p - 1} \\equiv 1 \\mod p $, by Fermat's little theorem. So $ q \\mid p - 1 $.\n\\end{proof}\n\n\\begin{theorem}\nLet $ q $ be prime. Then there are infinitely many primes with $ p \\equiv 1 \\mod q $.\n\\end{theorem}\n\n\\begin{proof}\nLet $ S $ be a finite set of primes which are congruent to $ 1 \\mod q $. Let\n$$ R = \\prod_{p \\in S} p. $$\nConsider $ \\Phi_q\\br{qR} \\ge qR + 1 > 1 $. Let $ p $ be a prime factor of $ \\Phi_q\\br{qR} $. By Corollary \\ref{cor:92}, either $ p = q $, or $ p \\equiv 1 \\mod q $. Since $ \\Phi_q\\br{qR} = \\br{qR}^{q - 1} + \\dots + 1 \\equiv 1 \\mod qR $, so $ p \\ne q $, $ p \\notin S $, and $ p \\equiv 1 \\mod q $.\n\\end{proof}\n\n\\subsection{Cyclotomic polynomials}\n\n\\begin{definition}\nLet $ n \\in \\ZZ_{\\ge 1} $. Then\n$$ \\Phi_n\\br{X} = \\prod_{1 \\le a \\le n, \\ \\br{a, n} = 1} \\br{X - e^{\\tfrac{2\\pi ai}{n}}}. $$\n\\end{definition}\n\n\\begin{lemma}\n\\label{lem:95}\nFor any $ n $, we have\n$$ X^n - 1 = \\prod_{d \\mid n, \\ d > 0} \\Phi_d\\br{X}. $$\n\\end{lemma}\n\n\\begin{proof}\nEach side is a monic polynomial, so we just need to check that the roots are the same, with multiplicities. The left hand side are the $ n $-th roots of unity, with multiplicity one each. The right hand side is $ \\Phi_d $, the primitive $ d $-th roots of unity, with multiplicity one. Each $ n $-th root of unity is a primitive $ d $-th root of unity for some unique $ d \\mid n $. The result follows.\n\\end{proof}\n\nFrom this it is easy to deduce the following.\n\n\\begin{lemma}\nFor any $ n \\ge 1 $, $ \\Phi_n\\br{X} \\in \\ZZ\\sbr{X} $.\n\\end{lemma}\n\n\\begin{proof}\nBy induction on $ n $. If $ n = 1 $, $ \\Phi_1\\br{X} = X - 1 $. Assume that the result holds for all $ d \\mid n $ for $ d < n $. By Lemma \\ref{lem:95}, if we set\n$$ P\\br{X} = \\prod_{d \\mid n, \\ 0 < d < n} \\Phi_d\\br{X}, $$\nthen $ P\\br{X} \\in \\ZZ\\sbr{X} $, $ P\\br{X} $ is monic, and $ X^n - 1 = \\Phi_n\\br{X}P\\br{X} $. Write\n$$ \\Phi_n\\br{X} = \\sum_i a_iX^i, \\qquad P\\br{X} = \\sum_i b_iX^i, $$\nand assume that not all $ a_i \\in \\ZZ $. Let $ q $ be maximal with $ a_q \\notin \\ZZ $. Let $ e = \\deg P $, so $ P\\br{X} = X^e + b_{e - 1}X^{e - 1} + \\dots + b_0 $. Then the coefficient of $ X^{q + e} $ in $ \\Phi_n\\br{X}P\\br{X} $ is\n$$ a_q + a_{q + 1}b_{e - 1} + \\dots + a_{q + e}b_0, \\qquad a_{q + 1}b_{e - 1} + \\dots + a_{q + e}b_0 \\in \\ZZ. $$\nSince $ \\Phi_n\\br{X}P\\br{X} = X^n - 1 \\in \\ZZ\\sbr{X} $, this is a contradiction.\n\\end{proof}\n\n\\pagebreak\n\n\\begin{definition}\nLet $ F $ be any field, and let $ P\\br{X} \\in F\\sbr{X} $. Then $ P'\\br{X} $, the \\textbf{derivative} of $ P\\br{X} $, is defined as follows. If $ P\\br{X} = \\sum_{n = 0}^d a_nX^n $, then\n$$ P'\\br{X} = \\sum_{n = 1}^d na_nX^{n - 1}. $$\n\\end{definition}\n\n\\begin{note*}\n$ \\br{P + Q}' = P' + Q' $ and $ \\br{PQ}' = P'Q + PQ' $.\n\\end{note*}\n\n\\begin{lemma}\n\\label{lem:98}\nSuppose that $ \\br{X - \\alpha}^2 $ divides $ P\\br{X} $. Then $ \\alpha $ is a root of both $ P $ and $ P' $.\n\\end{lemma}\n\n\\begin{proof}\nWrite $ P\\br{X} = \\br{X - \\alpha}^2R\\br{X} $. Then\n$$ P'\\br{X} = \\br{X - \\alpha}^2R'\\br{X} + 2\\br{X - \\alpha}R\\br{X} = \\br{X - \\alpha}\\br{\\br{X - \\alpha}R'\\br{X} + 2R\\br{X}}. $$\n\\end{proof}\n\n\\begin{corollary}\n\\label{cor:99}\nIf $ p \\nmid n $, then $ \\Phi_n\\br{X} $ has no repeated roots modulo $ p $.\n\\end{corollary}\n\n\\begin{proof}\nIt suffices to show that $ X^n - 1 $ has no repeated roots modulo $ p $. The derivative of $ X^n - 1 $ is $ nX^{n - 1} $, so its only root is zero, which is not a root of $ X^n - 1 $. So we are done by Lemma \\ref{lem:98}.\n\\end{proof}\n\n\\begin{note*}\nIf $ n = p $,\n$$ X^p - 1 \\equiv \\br{X - 1}^p \\mod p, \\qquad \\Phi_p\\br{X} \\equiv \\br{X - 1}^{p - 1} \\mod p. $$\n\\end{note*}\n\n\\begin{theorem}\n\\label{thm:100}\nSuppose $ p \\nmid n $ and $ a \\in \\ZZ $. Then $ p \\mid \\Phi_n\\br{a} $ if and only if $ a $ has order exactly $ n \\mod p $.\n\\end{theorem}\n\n\\begin{proof}\nFirstly suppose that $ a $ has order exactly $ n $. Then $ a $ is a root of $ X^n - 1 \\mod p $, but not a root of $ X^d - 1 $ for any $ d \\mid n $ for $ d < n $. Since $ \\Phi_d\\br{X} \\mid X^d - 1 $, $ a $ cannot be a root of $ \\Phi_d\\br{X} $ for any $ d \\mid n $ for $ d < n $. Let\n\\begin{equation}\n\\label{eq:4}\nX^n - 1 = \\Phi_n\\br{X}\\prod_{d \\mid n, \\ 0 < d < n} \\Phi_d\\br{X},\n\\end{equation}\nso $ a $ is a root of $ \\Phi_n\\br{X} \\mod p $, that is $ p \\mid \\Phi_n\\br{a} $. Conversely, suppose that $ p \\mid \\Phi_n\\br{a} $. Then $ a $ is a root of $ \\Phi_n\\br{X} \\mod p $, so by $ \\br{\\ref{eq:4}} $, $ a $ is a root of $ X^n - 1 \\mod p $. We need to show that $ a $ is not a root of $ X^d - 1 $ for any $ d \\mid n $ for $ d < n $. Writing\n$$ X^d - 1 = \\prod_{e \\mid d} \\Phi_e\\br{X}, $$\n$ a $ would be a root of $ \\Phi_e\\br{X} $ for some $ e \\mid d \\mid n $. So by $ \\br{\\ref{eq:4}} $, $ a $ is a root of both $ \\Phi_n\\br{X} $ and $ \\Phi_e\\br{X} $, so $ a $ is a repeated root of $ X^n - 1 \\mod p $. This contradicts Corollary \\ref{cor:99}.\n\\end{proof}\n\n\\begin{corollary}\n\\label{cor:101}\nIf $ p \\nmid n $, and $ a \\in \\ZZ $, then if $ p \\mid \\Phi_n\\br{a} $, then $ p \\equiv 1 \\mod n $.\n\\end{corollary}\n\n\\begin{proof}\n$ a $ has order $ n \\mod p $ by Theorem \\ref{thm:100}, so $ n \\mid p - 1 $, by Fermat's little theorem.\n\\end{proof}\n\n\\subsection{Primes congruent to \\texorpdfstring{$ 1 \\mod n $}{1 mod n}}\n\nWe are now in a position to prove the following.\n\n\\begin{theorem}\nIf $ n \\in \\ZZ_{\\ge 1} $, there are infinitely many primes $ p $ with $ p \\equiv 1 \\mod n $.\n\\end{theorem}\n\n\\begin{proof}\nLet $ S $ be a finite set of primes congruent to $ 1 \\mod n $, and let\n$$ R = \\prod_{p \\in S} p. $$\nFor each $ k $, let $ Q_k = \\Phi_n\\br{knR} \\in \\ZZ $. Note that not all $ Q_k $ are $ \\pm 1 $, since $ \\Phi_n\\br{X} $ is a non-constant polynomial. Thus choose $ k $ large enough that $ Q_k > 1 $, so there is a prime $ p $ dividing $ Q_k $. Since $ Q_k $ divides $ \\br{knR}^n - 1 $, no prime dividing $ n $ or $ R $ can divide $ Q_k $. Thus $ p $ is not in $ S $, and by Corollary \\ref{cor:101} $ p $ is congruent to $ 1 \\mod n $.\n\\end{proof}\n\n\\lecture{25}{Friday}{30/11/18}\n\nLecture 25 is a problems class.\n\n\\pagebreak\n\n\\section{Arithmetic functions}\n\n\\lecture{26}{Tuesday}{04/12/18}\n\nAn \\textbf{arithmetic function} is a function $ f : \\ZZ_{\\ge 1} \\to \\CC $, such as $ \\Phi $.\n\n\\subsection{Dirichlet convolution}\n\nThe set of arithmetic functions is a ring in the following way. Addition is $ \\br{f + g}\\br{n} = f\\br{n} + g\\br{n} $. Multiplication is \\textbf{Dirichlet convolution} $ f * g $,\n$$ \\br{f * g}\\br{n} = \\sum_{d \\mid n, \\ d \\ge 1} f\\br{d}g\\br{\\dfrac{n}{d}} = \\sum_{a, b \\ge 1, \\ ab = n} f\\br{a}g\\br{b}. $$\nWe have $ f * g = g * f $ and $ f * \\br{g * h} = \\br{f * g} * h $, and both are given by\n$$ \\br{f * g * h}\\br{n} = \\sum_{a, b, c \\ge 1, \\ abc = n} f\\br{a}g\\br{b}h\\br{c}. $$\nThen $ f * \\br{g + h} = f * g + f * h $. There exists a multiplicative unit $ \\epsilon $, that is $ f * \\epsilon = \\epsilon * f = f $. This is easy to figure out. We need\n$$ f\\br{n} = \\br{f * \\epsilon}\\br{n} = \\sum_{ab = n} f\\br{a}\\epsilon\\br{b}. $$\n\n\\begin{example*}\n$ f\\br{4} = f\\br{4}\\epsilon\\br{1} + f\\br{2}\\epsilon\\br{2} + f\\br{1}\\epsilon\\br{4} $. This forces $ \\epsilon\\br{1} = 1 $ and $ \\epsilon\\br{2} = \\epsilon\\br{4} = 0 $.\n\\end{example*}\n\nSo\n$$ \\epsilon\\br{n} =\n\\begin{cases}\n1 & n = 1 \\\\\n0 & n > 1\n\\end{cases}.\n$$\n\n\\subsection{M\\\"obius inversion}\n\nThe \\textbf{M\\\"obius function} $ \\mu : \\ZZ_{\\ge 1} \\to \\CC $ is defined as follows.\n$$ \\mu\\br{n} =\n\\begin{cases}\n1 & n = 1 \\\\\n\\br{-1}^k & n = p_1 \\dots p_k \\ \\text{is a product of distinct prime factors} \\\\\n0 & \\text{otherwise}\n\\end{cases}.\n$$\n\n\\begin{lemma}\n\\label{lem:103}\nIf $ 1 $ is the function $ 1\\br{n} = 1 $ for all $ n $, then $ 1 * \\mu = \\epsilon $.\n\\end{lemma}\n\n\\begin{proof}\n$ \\epsilon\\br{1} = \\br{1 * \\mu}\\br{1} = 1 \\times 1 $. If $ n > 1 $, we just have to check that\n$$ \\sum_{d \\mid n} \\mu\\br{d} = \\sum_{ab = n} 1\\br{a}\\mu\\br{b} = 0. $$\nLet $ p_1, \\dots, p_k $ be the distinct primes dividing $ n $. Then\n$$ \\sum_{d \\mid n} \\mu\\br{d} = \\sum_{\\br{\\epsilon_1, \\dots, \\epsilon_k}, \\ \\epsilon_i = 0, 1} \\br{-1}^{\\epsilon_1 + \\dots + \\epsilon_k} = \\br{\\sum_{\\epsilon_1 = 0}^1 \\br{-1}^{\\epsilon_1}} \\dots \\br{\\sum_{\\epsilon_k = 0}^1 \\br{-1}^{\\epsilon_k}} = 0, \\qquad n = \\prod_{i = 1}^k p_i^{\\epsilon_i}. $$\n\\end{proof}\n\n\\begin{proposition}[M\\\"obius inversion]\nIf $ f $ and $ g $ are arithmetic functions then $ g = f * 1 $ if and only if $ f = g * \\mu $.\n\\end{proposition}\n\n\\begin{proof}\n$ \\br{f * 1} * \\mu = f * \\br{1 * \\mu} = f * \\epsilon = f $, by Lemma \\ref{lem:103}, and $ \\br{g * \\mu} * 1 = g * \\br{\\mu * 1} = g * \\epsilon = g $.\n\\end{proof}\n\n\\begin{example*}\nLet $ \\id\\br{n} = n $. Then $ \\id = \\Phi * 1 $. That is, $ n = \\sum_{d \\mid n} \\Phi\\br{d} $. So $ \\Phi = \\id * \\mu $. So\n$$ \\Phi\\br{n} = \\sum_{d \\mid n} \\mu\\br{d}\\dfrac{n}{d} = n\\sum_{d \\mid n} \\dfrac{\\mu\\br{d}}{d}. $$\n\\end{example*}\n\n\\pagebreak\n\n\\section{The distribution of prime numbers}\n\nLet $ \\pi\\br{X} $ be the number of primes $ p $ such that $ p \\le X $.\n\n\\subsection{Reminder of asymptotic notation}\n\n$ A \\ll B $, or $ A = \\O\\br{B} $, means there exists a constant $ C > 0 $ such that $ \\abs{A} \\le CB $, and $ B \\gg A $ means $ A \\ll B $.\n\n\\begin{example*}\nIf $ x \\ge 1 $, $ x \\ll x^2 \\ll e^x / x^{100} $.\n\\end{example*}\n\n$ A \\ll_k B $ means $ A \\ll B $ with the constant $ C $ depending on $ k $.\n\n\\begin{example*}\n$ kx \\ll_k x $.\n\\end{example*}\n\n$ A = \\o\\br{B} $ means for all $ \\epsilon > 0 $ we have $ \\abs{A} \\le \\epsilon B $ as some other specified parameter becomes large enough.\n\n\\begin{example*}\n$ 1 / \\log x = \\o\\br{1} $ as $ x \\to \\infty $.\n\\end{example*}\n\n$ A \\sim B $ means $ A = \\br{1 + \\o\\br{1}}B $.\n\n\\subsection{The prime number theorem}\n\n\\begin{theorem}[Prime number theorem]\n$$ \\pi\\br{X} \\sim \\dfrac{X}{\\log X}, \\qquad X \\to \\infty. $$\n\\end{theorem}\n\n\\begin{theorem}\nThere exist constants $ 0 < c_1 < 1 < c_2 $ such that for all sufficiently large $ X $,\n$$ c_1\\dfrac{X}{\\log X} \\le \\pi\\br{X} \\le c_2\\dfrac{X}{\\log X}. $$\n\\end{theorem}\n\nThis implies that\n$$ \\pi\\br{X} = \\O\\br{\\dfrac{X}{\\log X}}. $$\n\n\\lecture{27}{Wednesday}{05/12/18}\n\n\\begin{proof}\n\\hfill\n\\begin{itemize}\n\\item Firstly consider the lower bound. We will prove that for some $ C_1 > 1 $, we have\n\\begin{equation}\n\\label{eq:5}\n\\prod_{p \\le 2n} \\ge C_1^n.\n\\end{equation}\nGiven $ \\br{\\ref{eq:5}} $, we have\n$$ \\br{2n}^{\\pi\\br{2n}} \\ge \\prod_{p \\le 2n} p \\ge C_1^n. $$\nTaking logarithms,\n$$ \\pi\\br{2n} \\ge \\br{\\dfrac{1}{2}\\log C_1}\\dfrac{2n}{\\log 2n}. $$\nThis gives the lower bound if $ X = 2n \\in \\ZZ $ is even, but since $ \\pi\\br{X + 1} - \\pi\\br{X} \\le 1 $, it is easy to get the lower bound for all $ X $. We will prove $ \\br{\\ref{eq:5}} $ by considering the prime factors of\n$$ \\binom{2n}{n} = \\prod_{p \\le 2n} p^{\\v_p\\br{n}}. $$\nClaim that\n\\begin{enumerate}\n\\item if $ p > \\sqrt{2n} $ then $ \\v_p\\br{n} \\le 1 $,\n\\item for all $ p \\le 2n $, $ p^{\\v_p\\br{n}} \\le 2n $, and\n\\item $ \\prod_{p \\le 2n} p^{\\v_p\\br{n}} \\ge 4^n / \\br{2n + 1} $.\n\\end{enumerate}\n\n\\pagebreak\n\nSuppose $ 1 $ to $ 3 $ are true. Then\n\\begin{align*}\n\\dfrac{4^n}{2n + 1}\n& \\le \\prod_{p \\le 2n} p^{\\v_p\\br{n}}\n= \\prod_{p \\le \\sqrt{2n}} p^{\\v_p\\br{n}} \\prod_{\\sqrt{2n} < p \\le 2n} p^{\\v_p\\br{n}} & \\text{by} \\ 3 \\\\\n& \\le \\br{2n}^{\\pi\\br{\\sqrt{2n}}} \\prod_{\\sqrt{2n} < p \\le 2n} p^{\\v_p\\br{n}} & \\text{by} \\ 2 \\\\\n& \\le \\br{2n}^{\\pi\\br{\\sqrt{2n}}} \\prod_{\\sqrt{2n} < p \\le 2n} p & \\text{by} \\ 1 \\\\\n& \\le \\br{2n}^{\\pi\\br{\\sqrt{2n}}} \\prod_{p \\le 2n} p\n\\le \\br{2n}^{\\sqrt{2n}} \\prod_{p \\le 2n} p.\n\\end{align*}\nSo\n$$ \\prod_{p \\le 2n} p \\ge \\dfrac{4^n}{\\br{2n + 1}\\br{2n}^{\\sqrt{2n}}}. $$\nFor $ n $ sufficiently large, and any $ 4 > C_1 $, the right hand side is at least $ C_1^n $, that is if $ K > 1 $, $ K^n \\ge \\br{2n + 1}\\br{2n}^{\\sqrt{2n}} $ for all $ n $ sufficiently large. \\footnote{Exercise}\n\\begin{enumerate}\n\\item In the first example sheet question $ 11 $, the exact power of $ p $ dividing $ m! $ is $ \\sum_{i = 1}^\\infty \\fbr{m / p^i} $. So\n$$ \\binom{2n}{n} = \\dfrac{\\br{2n}!}{n!n!} \\qquad \\implies \\qquad \\v_p\\br{n} = \\sum_{i = 1}^\\infty \\br{\\fbr{\\dfrac{2n}{p^i}} - 2\\fbr{\\dfrac{n}{p^i}}}. $$\nFor any $ x \\in \\RR $, $ \\fbr{2x} - 2\\fbr{x} \\ge 0 $, and in fact $ \\fbr{2x} - 2\\fbr{x} = 0 $ or $ \\fbr{2x} - 2\\fbr{x} = 1 $. If $ p > \\sqrt{2n} $, then $ p^2 > 2n $, so all terms in the sum vanish if $ i \\ge 2 $, so the sum is at most one.\n\\item Note that the terms in the sum are zero as soon as $ p^i > 2n $, that is\n$$ i > \\dfrac{\\log 2n}{\\log p} \\qquad \\implies \\qquad \\v_p\\br{n} \\le \\dfrac{\\log 2n}{\\log p} \\qquad \\implies \\qquad p^{\\v_p\\br{n}} \\le 2n. $$\n\\item\n$$ 4^n = 2^{2n} = \\br{1 + 1}^{2n} = \\sum_{i = 0}^{2n} \\binom{2n}{i} \\le \\br{2n + 1}\\binom{2n}{n} \\qquad \\implies \\qquad \\prod_{p \\le 2n} p^{\\v_p\\br{n}} = \\binom{2n}{n} \\ge \\dfrac{4^n}{2n + 1}. $$\n\\end{enumerate}\n\\item Claim that there exists $ C_2 > 1 $ such that for all $ X $ sufficiently large, we have\n\\begin{equation}\n\\label{eq:6}\n\\prod_{\\tfrac{X}{2} \\le p \\le X} p \\le C_2^X.\n\\end{equation}\nSuppose we know $ \\br{\\ref{eq:6}} $. Then\n$$ C_2^X \\ge \\prod_{\\tfrac{X}{2} \\le p \\le X} p \\ge \\br{\\dfrac{X}{2}}^{\\pi\\br{X} - \\pi\\br{\\tfrac{X}{2}}}. $$\nTaking logarithms,\n\\begin{equation}\n\\label{eq:7}\n\\pi\\br{X} \\le \\pi\\br{\\dfrac{X}{2}} + \\dfrac{X\\log C_2}{\\log \\tfrac{X}{2}}.\n\\end{equation}\nSuppose that $ X $ is large enough that $ \\br{\\ref{eq:6}} $ holds for $ X, \\dots, X / 2^{m - 1} $. Substituting $ X, \\dots, X / 2^{m - 1} $ into $ \\br{\\ref{eq:7}} $, and summing,\n$$ \\pi\\br{X} \\le \\pi\\br{\\dfrac{X}{2^m}} + 2\\log C_2\\sum_{i = 1}^m \\dfrac{\\tfrac{X}{2^i}}{\\log \\tfrac{X}{2^i}}. $$\n\n\\pagebreak\n\nNow fix $ X $ and choose $ m $ to be largest possible with $ 2^m \\le \\sqrt{X} $. Then $ X / 2^m \\ge \\sqrt{X} $, so $ \\br{\\ref{eq:6}} $ is indeed valid for $ X, \\dots, X / 2^{m - 1} $ provided that $ X $ is sufficiently large. Since $ m $ is maximal such that $ 2^m \\le \\sqrt{X} $, we have $ 2^m \\ge \\sqrt{X} / 2 $. So\n$$ \\pi\\br{\\dfrac{X}{2^m}} \\le \\dfrac{X}{2^m} \\le 2\\sqrt{X}. $$\nSo substituting into the above,\n$$ \\pi\\br{X} \\le 2\\sqrt{X} + 2\\log C_2\\sum_{i = 1}^m \\dfrac{\\tfrac{X}{2^i}}{\\log \\tfrac{X}{2^i}} \\le 2\\sqrt{X} + \\dfrac{2\\log C_2}{\\tfrac{1}{2}\\log X}\\sum_{i = 1}^m \\dfrac{X}{2^i} \\le 2\\sqrt{X} + \\br{4\\log C_2}\\br{\\dfrac{X}{\\log X}}. $$\nThis gives our upper bound, because $ \\sqrt{X} \\ll X / \\log X $. Now remains to prove $ \\br{\\ref{eq:6}} $. We saw above that if $ n \\in \\ZZ $ then\n$$ \\prod_{n < p \\le 2n} p \\le \\binom{2n}{n} \\le 4^n = \\sum_{i = 0}^{2n} \\binom{2n}{i}. $$\nTake $ n = \\fbr{X / 2} $. Then $ 2n \\le X $, and we get\n$$ \\prod_{\\tfrac{X}{2} < p \\le 2\\fbr{\\tfrac{X}{2}}} p \\le 2^{2n} \\le 2^X \\qquad \\implies \\qquad \\prod_{\\tfrac{X}{2} < p \\le X} p \\le X2^X < C_2^X, $$\nfor $ X $ sufficiently large, for any $ C_2 > 2 $.\n\\end{itemize}\n\\end{proof}\n\n\\lecture{28}{Friday}{07/12/18}\n\nLecture 28 is a problems class.\n\n\\subsection{The Brun-Titchmarsh theorem and the Selberg sieve}\n\n\\lecture{29}{Tuesday}{11/12/18}\n\nWhat can we say about the number of primes $ p $ with $ X < p \\le X + Y $? That is, $ \\pi\\br{X + Y} - \\pi\\br{X} $. Think of $ Y $ being fixed for a moment. The best possible lower bound is zero.\n\n\\begin{example*}\n$ n! + 2, \\dots, n! + n $ is a sequence of consecutive composite numbers.\n\\end{example*}\n\nIt was conjectured, in 1920s, by Hardy and Littlewood that $ \\pi\\br{X + Y} \\le \\pi\\br{X} + \\pi\\br{Y} $, that is $ \\pi\\br{X + Y} - \\pi\\br{X} \\le \\pi\\br{Y} $. This is no longer believed.\n\n\\begin{theorem}\n\\label{thm:107}\n$$ \\pi\\br{X + Y} - \\pi\\br{X} \\le \\dfrac{\\br{2 + \\o\\br{1}}Y}{\\log Y}, $$\nwhere $ \\o\\br{1} $ is as $ Y \\to \\infty $ and $ X $ is fixed.\n\\end{theorem}\n\nIn $ X + 1, \\dots, X + Y $, about half of these are divisible by two, about a third of these are divisible by three, and about a sixth of these are divisible by six. If $ p_1, \\dots, p_k $ are primes, the error term is $ 2^k $, so can only consider the first $ \\log Y $ primes, which implies Theorem \\ref{thm:107} for $ Y / \\log \\log Y $. Selberg's idea is to weight the inclusion-exclusion count.\n\n\\begin{proof}\nLet $ \\lambda_1, \\lambda_2, \\dots \\in \\RR $ be any sequence with $ \\lambda_1 = 1 $. Let $ R < Y $ be fixed for now. Later we will choose $ R = Y^{\\tfrac{1}{2} - \\epsilon} $. Set\n$$ \\nu\\br{n} = \\br{\\sum_{d \\mid n, \\ d \\le R} \\lambda_d}^2 \\ge 0. $$\nSuppose that $ p $ is prime, and $ p > R $. Then by definition, $ \\nu\\br{p} = \\lambda_1^2 = 1 $, so\n$$ \\pi\\br{X + Y} - \\pi\\br{X} = \\sum_{X < p \\le X + Y} 1 \\le \\pi\\br{R} + \\sum_{X < n \\le X + Y} \\nu\\br{n} \\le R + \\sum_{X < n \\le X + Y} \\nu\\br{n}. $$\n\n\\pagebreak\n\nNow have to choose $ \\lambda_i $ to minimise $ \\sum_{X \\le n \\le X + Y} \\nu\\br{n} $, so\n\\begin{align*}\n\\sum_{X < n \\le X + Y} \\nu\\br{n}\n& = \\sum_{X < n \\le X + Y} \\br{\\sum_{d \\mid n, \\ d \\le R} \\lambda_d}^2\n= \\sum_{X < n \\le X + Y} \\br{\\sum_{d_1 \\mid n, \\ d_1 \\le R} \\lambda_{d_1}}\\br{\\sum_{d_2 \\mid n, \\ d_2 \\le R} \\lambda_{d_2}} \\\\\n& = \\br{\\sum_{d_1, d_2 \\le R} \\lambda_{d_1}\\lambda_{d_2}}\\br{\\sum_{X < n \\le X + Y, \\ d_1 \\mid n, \\ d_2 \\mid n} 1}\n= \\br{\\sum_{d_1, d_2 \\le R} \\lambda_{d_1}\\lambda_{d_2}}\\br{\\dfrac{Y\\br{d_1, d_2}}{d_1d_2} + \\O\\br{1}},\n\\end{align*}\nsince $ \\lcm\\br{d_1, d_2} = d_1d_2 / \\br{d_1, d_2} $. Putting this together,\n$$ \\pi\\br{X + Y} - \\pi\\br{X} \\le Y\\sum_{d_1, d_2 \\le R} \\dfrac{\\lambda_{d_1}\\lambda_{d_2}\\br{d_1, d_2}}{d_1d_2} + R + \\O\\br{1}\\sum_{d_1, d_2 \\le R} \\abs{\\lambda_{d_1}\\lambda_{d_2}}, $$\nwhere the leading term is\n$$ Y\\sum_{d_1, d_2 \\le R} \\dfrac{\\lambda_{d_1}\\lambda_{d_2}\\br{d_1, d_2}}{d_1d_2}, $$\nand the error term is\n$$ R + \\O\\br{1}\\sum_{d_1, d_2 \\le R} \\abs{\\lambda_{d_1}\\lambda_{d_2}}. $$\nNow choose $ \\lambda_i $ such that $ \\lambda_1 = 1 $, in such a way as to minimise the leading term. Then choose $ R = Y^c $ for $ c < \\tfrac{1}{2} $. Check that for any $ \\epsilon > 0 $, we have $ \\lambda_d \\ll_\\epsilon d^\\epsilon $. Then\n$$ \\sum_{d_1d_2} \\abs{\\lambda_{d_1}\\lambda_{d_2}} \\le R^{2 + 2\\epsilon} = Y^{2c\\br{1 + \\epsilon}}. $$\nChoose $ \\epsilon < 1 / 2c - 1 $, then $ Y^{2c\\br{1 + \\epsilon}} \\ll Y / \\log Y $. Write $ \\overrightarrow{\\lambda} = \\br{\\lambda_1, \\lambda_2, \\dots} $, so\n$$ Q\\br{\\overrightarrow{\\lambda}} = \\sum_{d_1, d_2 \\le R} \\dfrac{\\lambda_{d_1}\\lambda_{d_2}\\br{d_1, d_2}}{d_1d_2}. $$\nWant to minimise this subject to $ \\lambda_1 = 1 $. Want to diagonalise $ Q\\br{\\overrightarrow{\\lambda}} $. Use, a slight variant of, M\\\"obius inversion. For any $ m $, $ m = \\sum_{d \\mid m} \\Phi\\br{d} $. Take $ m = \\br{d_1, d_2} $. Then $ \\br{d_1, d_2} = \\sum_{\\delta \\mid \\br{d_1, d_2}} \\Phi\\br{\\delta} $, so\n$$ Q\\br{\\overrightarrow{\\lambda}} = \\sum_{d_1, d_2 \\le R} \\dfrac{\\lambda_{d_1}\\lambda_{d_2}\\br{d_1, d_2}}{d_1d_2} = \\sum_{\\delta \\le R} \\Phi\\br{\\delta}\\br{\\sum_{\\delta \\mid d, \\ d \\le R} \\dfrac{\\lambda_d}{d}}^2, $$\nby using that $ \\delta \\mid d_1 $ and $ \\delta \\mid d_2 $ if and only if $ \\delta \\mid d_1d_2 / \\br{d_1, d_2} $. Set $ u_\\delta = \\sum_{\\delta \\mid d, \\ d \\le R} \\lambda_d / d $. Then\n$$ Q\\br{\\overrightarrow{\\lambda}} = \\sum_{\\delta \\le R} \\Phi\\br{\\delta}u_\\delta^2. $$\n\n\\lecture{30}{Wednesday}{12/12/18}\n\nClaim that\n\\begin{equation}\n\\label{eq:8}\n\\dfrac{\\lambda_d}{d} = \\sum_{d \\mid \\delta, \\ \\delta \\le R} \\mu\\br{\\dfrac{\\delta}{d}}u_\\delta.\n\\end{equation}\nThe right hand side is\n$$ \\sum_{d \\mid \\delta, \\ d \\le R} \\mu\\br{\\dfrac{\\delta}{d}}\\br{\\sum_{\\delta \\mid d', \\ d' \\le R} \\dfrac{\\lambda_{d'}}{d'}} = \\sum_{d' \\le R} \\dfrac{\\lambda_{d'}}{d'}\\br{\\sum_{d \\mid \\delta \\mid d'} \\mu\\br{\\dfrac{\\delta}{d}}}. $$\nSo we need to show that\n$$ \\sum_{d \\mid \\delta \\mid d'} \\mu\\br{\\dfrac{\\delta}{d}} =\n\\begin{cases}\n1 & d = d' \\\\\n0 & \\text{otherwise}\n\\end{cases}.\n$$\n\n\\pagebreak\n\nThe sum is equal to\n$$ \\sum_{m \\mid d' / d} \\mu\\br{m} = \\br{1 * \\mu}\\br{\\dfrac{d'}{d}} = \\epsilon\\br{\\dfrac{d'}{d}}. $$\nThe condition that $ \\lambda_1 = 1 $ translates via $ \\br{\\ref{eq:8}} $ to the condition that $ 1 = \\sum_{\\delta \\le R} \\mu\\br{\\delta}u_\\delta $. The Cauchy-Schwarz inequality is $ \\abs{ab} \\le \\abs{a}\\abs{b} $, that is\n$$ \\sum_i a_ib_i \\le \\br{\\sum_i a_i^2}^{\\tfrac{1}{2}}\\br{\\sum_i b_i^2}^{\\tfrac{1}{2}}, $$\nwith equality if and only if there exists $ \\lambda $ such that $ b_i = \\lambda a_i $ for all $ i $. So\n$$ 1 = \\sum_{\\delta \\le R} \\mu\\br{\\delta}u_\\delta \\le \\br{\\sum_{\\delta \\le R}\\Phi\\br{\\delta}u_\\delta^2}^{\\tfrac{1}{2}}\\br{\\sum_{\\delta \\le R}\\dfrac{\\mu\\br{\\delta}^2}{\\Phi\\br{\\delta}}}^{\\tfrac{1}{2}}. $$\nSo\n$$ Q\\br{\\overrightarrow{\\lambda}} = \\sum_{\\delta \\le R} \\Phi\\br{\\delta}u_\\delta^2 \\ge \\dfrac{1}{D}, \\qquad D = \\sum_{\\delta \\le R} \\dfrac{\\mu\\br{\\delta}^2}{\\Phi\\br{\\delta}}. $$\nEquality holds when $ u_\\delta = \\mu\\br{\\delta} / D\\Phi\\br{\\delta} $. We are going to show that $ D \\ge \\log R + \\O\\br{1} $. Since $ R = Y^c $, this gives us a leading term of\n$$ \\dfrac{Y}{\\log R} = \\dfrac{Y}{\\log Y^c} = \\dfrac{1}{c}\\br{\\dfrac{Y}{\\log Y}}. $$\n$ c < \\tfrac{1}{2} $ implies that $ 1 / c > 2 $, so\n$$ D = \\sum_{\\delta \\le R} \\dfrac{\\mu\\br{\\delta}^2}{\\Phi\\br{\\delta}} = \\sum_{\\delta \\le R, \\ \\delta \\ \\text{squarefree}} \\dfrac{1}{\\Phi\\br{\\delta}}. $$\nIf $ \\delta $ is squarefree, write $ \\delta = p_1 \\dots p_k $. Then\n$$ \\Phi\\br{\\delta} = \\br{p_1 - 1} \\dots \\br{p_k - 1} = p_1 \\dots p_k\\br{1 - \\dfrac{1}{p_1}} \\dots \\br{1 - \\dfrac{1}{p_k}}. $$\nSo\n$$ D = \\sum_{\\delta \\le R, \\ \\delta \\ \\text{squarefree}} \\dfrac{1}{\\delta}\\prod_{p \\mid \\delta} \\br{1 - \\dfrac{1}{p}}^{-1}. $$\nNow, $ \\br{1 - 1 / p}^{-1} = 1 + 1 / p + \\dots $. So\n$$ D = \\sum_{\\delta \\le R, \\ \\delta \\ \\text{squarefree}} \\dfrac{1}{\\delta}\\prod_{p \\mid \\delta} \\br{1 + \\dfrac{1}{p} + \\dots} \\ge \\sum_{n \\le R} \\dfrac{1}{n} = \\log R + \\O\\br{1}, $$\nby taking $ n \\le R $, and writing $ n = p_1^{a_1} \\dots p_m^{a_m} $ and $ \\delta = p_1 \\dots p_m \\le R $ squarefree, so\n$$ \\dfrac{1}{n} = \\dfrac{1}{\\delta}\\br{\\dfrac{1}{p_1^{a_1 - 1}} \\dots \\dfrac{1}{p_m^{a_m - 1}}}. $$\nThe only thing remaining is to show that $ \\lambda_d \\ll_\\epsilon d^\\epsilon $. Recall that $ u_\\delta = \\mu\\br{\\delta} / D\\Phi\\br{\\delta} $. So\n$$ \\lambda_d = d\\sum_{d \\mid \\delta, \\ \\delta \\le R} \\mu\\br{\\dfrac{\\delta}{d}}u_\\delta = \\dfrac{d}{D}\\sum_{d \\mid \\delta, \\ \\delta \\le R} \\dfrac{\\mu\\br{\\tfrac{\\delta}{d}}\\mu\\br{\\delta}}{\\Phi\\br{\\delta}} = \\dfrac{d}{D}\\sum_{d \\mid \\delta, \\ \\delta \\le R, \\ \\delta \\ \\text{squarefree}} \\dfrac{\\mu\\br{\\tfrac{\\delta}{d}}\\mu\\br{\\delta}}{\\Phi\\br{\\delta}}. $$\nWrite $ \\delta' = \\delta / d $. Since $ \\delta = \\delta'd $, and $ \\delta $ is squarefree, we have $ \\br{\\delta', d} = 1 $, so $ \\Phi\\br{\\delta} = \\Phi\\br{\\delta'}\\Phi\\br{d} $. So\n$$ \\abs{\\lambda_d} \\le \\dfrac{d}{\\Phi\\br{d}D}\\sum_{\\delta' \\le R, \\ \\delta' \\ \\text{squarefree}} \\dfrac{1}{\\Phi\\br{\\delta'}} = \\dfrac{d}{\\Phi\\br{d}}. $$\nNeed to show that $ \\Phi\\br{d} \\gg_\\epsilon d^{1 - \\epsilon} $ if $ d $ is squarefree, where $ \\Phi\\br{d} = \\prod_{p \\mid d} \\br{p - 1} $. If $ p $ is sufficiently large, then $ p - 1 \\ge p^{1 - \\epsilon} $. If $ p $ is not sufficiently large, then $ \\br{p - 1} / p > 0 $ can be regarded as a constant.\n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "57e8523f87a6043ca4bc45aabcf53459fa256c89", "size": 130477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "M3P14 Number Theory/M3P14.tex", "max_stars_repo_name": "icl-notes/GANT", "max_stars_repo_head_hexsha": "0228d21307fbaa7971f4446d89a160d7dfc174a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2019-04-19T17:03:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-18T06:57:07.000Z", "max_issues_repo_path": "M3P14 Number Theory/M3P14.tex", "max_issues_repo_name": "Multramate/IC-GANT", "max_issues_repo_head_hexsha": "ea1e3a1d97a2761bc1d0b60eea0c2cec91e17917", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-06T15:04:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-06T16:14:54.000Z", "max_forks_repo_path": "M3P14 Number Theory/M3P14.tex", "max_forks_repo_name": "Multramate/IC-GANT", "max_forks_repo_head_hexsha": "ea1e3a1d97a2761bc1d0b60eea0c2cec91e17917", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-28T02:00:45.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-06T13:09:15.000Z", "avg_line_length": 54.3427738442, "max_line_length": 1059, "alphanum_fraction": 0.5795887398, "num_tokens": 54969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.6659980119438089}}
{"text": "\\documentclass{article}\n\\input{homework.sty}\n\n\\title{Homework 1}\n\\author{Austin Gill}\n\n\\begin{document}\n\\maketitle\n\\begingroup\n\\hypersetup{linkcolor=black}\n\\tableofcontents\n\\endgroup\n\\newpage\n\nThe Jupyter notebooks containing the work for each of the following problems, as well as the\n\\LaTeX{} source code for this document can be found at\n\\url{https://github.com/Notgnoshi/natural-computing/tree/master/homework/hw1}\n\n\\section{Function Optimization via Simulated Annealing}\\label{prob:1}\n\n\\subsection{Statement}\nCompare the effectiveness of the text's iterated hill climbing and simulated annealing algorithms\nto find the max of\n\\[ f(x) = 2^{-2{\\left(\\frac{(x - 0.1)}{0.9}\\right)}^2}{\\big(\\sin(5\\pi x)\\big)}^6\\]\nwith $x\\in [0,1]$. Use a real valued representation. Include a plot of the function with the\nlocation of the max and a plot of the estimate as a function of the iteration number. How sensitive\nare the algorithms to initial values?\n\n\\subsection{Method}\n\n\\subsubsection{Problem Setup and Gradient Methods}\n\nFor completeness and curiosity, I chose to attack the problem from a symbolic perspective first.\nThis gives an opportunity to get comfortable with the problem, and get my workflow setup correctly\nbecause I've recently reinstalled Ubuntu and subsequently all of my commonly used Python libraries.\n\nThe python \\mintinline{python}{sympy} library provides decent symbolic computation capabilities\nthat I have had good luck with in the past. The only real surprising implementation detail is in\nthe definition of the objective function.\n\n\\begin{minted}[highlightlines={7-8}]{python}\ndef f(x):\n    \"\"\"The objective function to evaluate.\n\n    This function returns a sympy symbolic function, float, or np.ndarray\n    depending on the type of the input.\n    \"\"\"\n    # Use symbolic sine, pi if necessary.\n    sin, pi = (sympy.sin, sympy.pi) if isinstance(x, sympy.Symbol) else (np.sin, np.pi)\n\n    return 2 ** (-2 * ((x - 0.1) / 0.9) ** 2) * sin(5 * pi * x) ** 6\n\\end{minted}\n\nIf the given type is a symbolic variable, return a symbolic representation of the function rather\nthan the default numerical computation. Then this function can be given individual float values,\nnumpy arrays, and sympy symbols.\n\n\\begin{figure}[h]\n    \\centering\n    % Make sure to run the notebook before this will compile.\n    \\includegraphics{prob1/figures/prob1-function.pdf}\n    \\caption{The objective function $f(x)$}\\label{fig:prob1:function}\n\\end{figure}\n\nThe very first thing to do when dealing with optimizing a function is to plot anything you can get\nyour hands on, including the neighbor's cat. The objective function and its derivative are shown in\n\\autoref{fig:prob1:function} and \\autoref{fig:prob1:derivative} respectively.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics{prob1/figures/prob1-derivative.pdf}\n    \\caption{The objective function's derivative}\\label{fig:prob1:derivative}\n\\end{figure}\n\nWe can immediately pick out the local and global extrema by visual inspection. The maxima\nperiodically occur at $\\frac{n}{5} - \\frac{1}{10}$ with the global maximum occuring at\n$\\frac{1}{10}$. The minima periodically occur at $\\frac{n}{5}$ with value $0$.\n\nWe can produce a symbolic version of the objective function easily with\n\\begin{minted}{python}\n    x = sympy.Symbol('x')\n    print(f(x))\n\\end{minted}\nwhich displays\\footnote{When coerced with \\mintinline{python}{sympy.init_printing()} in a Jupyter\n    notebook.}\n\\[2^{- 2 {\\left(1.11 x - 0.11\\right)}^{2}} \\sin^{6}{\\left (5 \\pi x\n        \\right)}\\]\nThen we compute the atrocious derivative symbolically.\n\\begin{minted}{python}\n    fp = sympy.diff(f(x), x)\n    print(fp)\n\\end{minted}\nwhich displays the trivial derivative\\footnote{Coincidentally, the programmatically generated, and\n    subsequently auto-formatted \\LaTeX{} code for these functions is, I think, the ugliest thing\n    I've ever seen.}\n% This garbage is what sympy + my autoformatter gives. I'm not fixing it.\n\\[2^{- 2 \\left(1.11 x - 0.11\\right)^{2}} \\left(- 4.938 x +\n    0.4938\\right) \\log{\\left (2 \\right )} \\sin^{6}{\\left (5 \\pi x \\right )} + 30 \\cdot\n    2^{-2\n            \\left(1.11 x - 0.11\\right)^{2}} \\pi \\sin^{5}{\\left (5 \\pi\n        x\\right)}\\cos{\\left(5 \\pi x \\right )}\\]\nwhich we can then set equal to $0$ and solve\n\\begin{minted}{python}\n    # solve f'(x) = 0\n    print(sympy.solveset(fp, x))\n\\end{minted}\nto get $\\frac{n}{5} - \\frac{1}{10}$ after simplification:\n% ditto\n\\[\\left\\{x \\mid x \\in \\mathbb{C} \\wedge \\left(\\left(- 4.938 x + 0.4938\\right) \\log{\\left (2\n            \\right)} \\sin{\\left (5 \\pi x \\right )} + 30 \\pi \\cos{\\left (5 \\pi x \\right )}\\right)\n    \\sin^{5}{\\left (5\n        \\pi x \\right )} = 0 \\right\\} \\setminus \\left\\{x \\mid x \\in \\mathbb{C} \\wedge 2^{2\n            \\left(1.11 x -\n            0.11\\right)^{2}} = 0 \\right\\}\\]\n\nIt's also helpful to compare the results of your typical gradient optimization method against the\nmethods discussed later in this report.\n\n\\begin{minted}{python}\n    # Convert the symbolic derivative to a numpy-compatable function for plotting.\n    fp = sympy.lambdify([x], fp, 'numpy')\n\n    # Minimizing -f(x) will maximize it.\n    result = scipy.optimize.minimize(lambda x: -f(x), 0.19, bounds=[(0, 1)])\n    print(result.x)\n    result = scipy.optimize.minimize(lambda x: -f(x), 0.2, bounds=[(0, 1)])\n    print(result.x)\n    result = scipy.optimize.minimize(lambda x: -f(x), 0.21, bounds=[(0, 1)])\n    print(result.x)\n\\end{minted}\n\\vspace{-1cm}\n\\begin{minted}{text}\n    0.1\n    0.2\n    0.29953865\n\\end{minted}\n\\vspace{-1cm}\n\nOn either side of the minima at $x = 0.2$ the gradient optimizer\\footnote{The optimization\n    algorithm scipy chose for this function was the L-BFGS-B algorithm. I don't know anything about\n    how well and under what conditions it performs, but I assume it works better than anything I\n    could write by hand.} finds the next closest local maxima. This agrees with my intuitive\nunderstanding of gradient methods; without some kind of correction, they too are susceptible to\nfinding local optima of oscillatory functions.\n\n\\subsubsection{Hill Climbing}\n\nThis hill climbing algorithm discussed in the book is listed in \\autoref{alg:hill-climbing}.\n\n\\begin{algorithm}[h]\n    % \\begin{noindent}\n    \\begin{algorithmic}\n        \\Function{hill-climbing}{$f$}\n            \\State{Initialize $x$}\n            \\While{not done}\\IComment{can be convergence or fixed iteration}\n                \\State{$x' = x + \\text{perturbation}$}\n                \\If{$f(x') < f(x)$}\\IComment{this minimizes $f(x)$}\n                    \\State{$x = x'$}\n                \\EndIf{}\n            \\EndWhile{}\n            \\State\\Return{$x$}\n        \\EndFunction{}\n    \\end{algorithmic}\n    % \\end{noindent}\n    \\caption{The hill climbing algorithm}\\label{alg:hill-climbing}\n\\end{algorithm}\n\nThis can easily be implemented in Python as\n\n\\begin{minted}{python}\n    def hill_climbing(func, bounds, sigma, iters):\n        \"\"\"Minimize the given function using the Hill Climbing algorithm.\n\n        :param func: The function to minimize.\n        :param bounds: The lower and upper bounds on the feasible region.\n        :param sigma: The standard deviation to use when perturbing the current guess.\n        :param iters: The number of iterations to run the hill climbing algorithm for.\n        :returns: The path of points visited from the initial guess to the final solution.\n        \"\"\"\n        path = np.zeros(iters)\n        x0 = np.random.uniform(*bounds)\n        for i in range(iters):\n            xp = perturb(x0, bounds, sigma)\n            if func(xp) < func(x0):\n                x0 = xp\n            path[i] = x0\n        return path\n\\end{minted}\n\nwith \\mintinline{python}{perturb(x, bounds, sigma)} defined as\n\n\\begin{minted}{python}\n    def perturb(x, bounds, sigma):\n        \"\"\"Perturb the given value by adding zero-mean white noise.\n\n        :param x: The value to perturb.\n        :param bounds: The lower and upper bounds on the feasible region.\n        :param sigma: The standard deviation to use when adding white noise.\n        \"\"\"\n        m, M = bounds\n        xp = x + np.random.normal(scale=sigma)\n        while xp >= M or xp <= m:\n            xp = x + np.random.normal(scale=sigma)\n        return xp\n\\end{minted}\n\nNote that my implementation of \\mintinline{python}{perturb(x)} will not perturb the given point\noutside of the feasible region for the problem.\n\nOne of the easiest ways to improve the quality of the results from the hill climbing algorithm is\nto run it multiple times and take the best result. This is the iterated hill climbing algorithm\nfrom the book, listed in \\autoref{alg:iterated-hill-climbing}.\n\n\\begin{algorithm}[h]\n    % \\begin{noindent}\n    \\begin{algorithmic}\n        \\Function{iterated-hill-climbing}{$f, n$}\n            \\State{$solutions = map\\big(\\Call{hill-climbing}{f}, \\{1, \\dots, n\\}\\big)$}\\IComment{A trivially parallelizable operation}\n            \\State\\Return{The best solution}\n        \\EndFunction{}\n    \\end{algorithmic}\n    % \\end{noindent}\n    \\caption{The iterated hill climbing algorithm}\\label{alg:iterated-hill-climbing}\n\\end{algorithm}\n\nThis algorithm can easily (even with parallelization) be implemented in Python as follows\n\\begin{minted}[highlightlines={18}]{python}\nimport itertools\nimport multiprocessing\n# I wonder why it's called dummy?\nfrom multiprocessing.dummy import Pool as ThreadPool\n\ndef iterated_hill_climbing(func, bounds, sigma, inner_iters, iters):\n    \"\"\"Repeatedly climb the hill to find the less-local extremum.\n\n    :param func: The function to minimize.\n    :param bounds: The lower and upper bounds on the feasible region.\n    :param sigma: The standard deviation to use when perturbing the current guess.\n    :param inner_iters: The number of iterations to use for each run of the algorithm.\n    :param iters: The number of times to run the algorithm.\n    :returns: An array of solutions from each run, sorted by their fitness.\n    \"\"\"\n    pool = ThreadPool(multiprocessing.cpu_count())\n    # starmap consumes the given iterable in parallel until it is exhausted, collecting the results.\n    results = pool.starmap(hill_climbing, itertools.repeat((func, bounds, sigma, inner_iters), times=iters))\n    # Each result is a full path, not the optimal value\n    optimums = [r[-1] for r in results]\n    # Sort the optimums by their fitness.\n    optimums.sort(key=func)\n    return np.array(optimums)\n\\end{minted}\nThis implementation runs the desired number of iterations in parallel using as many threads as you\nhave processors before collecting all of the results and sorting the optimums by the objective\nfunction.\n\n\\subsubsection{Simulated Annealing}\n\nThe simulated annealing algorithm from the book (listed in \\autoref{alg:simulated-annealing}) is\nfar more interesting. Similar to the hill climbing algorithm, it too perturbs the current solution\nin order to move around the feasible region. However, it not only accepts solutions that improve\nthe current solution's fitness, it accepts solutions that \\textit{decrease} the current solution's\nfitness with probability decreasing with the system temperature.\n\nThe simulated annealing algorithm accepts such solutions in an attempt to move out of local optima.\nBut in order to converge, and to a more reasonable value, it does so with a decreasing probability.\n\n\\begin{algorithm}[H]\n    % \\begin{noindent}\n    \\begin{algorithmic}\n        \\Function{simulated-annealing}{$f$}\n            \\State{Initialize $T$}\n            \\State{Initialize $x$}\n            \\While{not done}\\IComment{prefer convergence over fixed iterations}\n                \\State{$x' = x + \\text{perturbation}$ }\n                \\If{$\\displaystyle rand(0, 1) < e^{\\frac{\\left(f(x) - f(x')\\right)}{T}}$}\n                    \\State{$x = x'$}\n                \\EndIf{}\n                \\State{Update $T$}\n            \\EndWhile{}\n            \\State\\Return{$x$}\n        \\EndFunction{}\n    \\end{algorithmic}\n    % \\end{noindent}\n    \\caption{The simulated annealing algorithm}\\label{alg:simulated-annealing}\n\\end{algorithm}\n\n\\autoref{alg:simulated-annealing} too, isn't difficult to implement\\footnote{Although it can be a\n    bitch to tune.} in Python. The difficulty lies in the choice of the perturbation method and the\ncooling schedule. I chose the same \\mintinline{python}{perturb(x, bounds, sigma)} from above,\nalthough as mentioned later, picking the proper standard deviation required significant trial and\nerror.\n\n\\begin{minted}{python}\n    def simulated_annealing(func, bounds, sigma, temp, cooling_factor):\n        \"\"\"Use simulated annealing to optimize the given function.\n\n        :param func: The function to minimize.\n        :param bounds: The lower and upper bounds on the feasible region.\n        :param sigma: The standard deviation to use when perturbing the current guess.\n        :param temp: The initial temperature of the system.\n        :param cooling_factor: How quickly the system should cool.\n        :returns: An array of points *accepted* by the random condition.\n        \"\"\"\n        # Pick a random starting point somewhere in the domain.\n        x0 = np.random.uniform(*bounds)\n        current = func(x0)\n        path = []\n        while temp > 0.001:\n            xp = perturb(x0, bounds, sigma)\n            potential = func(xp)\n            if potential < current or np.random.random() < np.exp((current - potential) / temp):\n                x0 = xp\n                path.append(x0)\n                current = potential\n            temp *= 1 - cooling_factor\n\n        return np.array(path)\n\\end{minted}\n\nNote that my implementation does not return an array of points at each iteration of the algorithm.\nIt instead returns an array of points that the algorithm has accepted, whether the point improved\nthe current solution's fitness or not. Also, note that the number of iterations the simulated\nannealing algorithm takes to converge depends on the initial temperature of the system and the\ncooling schedule. Contrast this with the hill climbing algorithm, which terminates after some\npredetermined number of steps.\n\nAlthough not required, I implemented an iterated version of the simulated annealing algorithm,\nechoing \\autoref{alg:iterated-hill-climbing}.\n\n\\begin{algorithm}[H]\n    % \\begin{noindent}\n    \\begin{algorithmic}\n        \\Function{iterated-simulated-annealing}{$f, n$}\n            \\State{$solutions = map\\big(\\Call{simulated-annealing}{f}, \\{1, \\dots, n\\}\\big)$}\\IComment{A trivially parallelizable operation}\n            \\State\\Return{The best solution}\n        \\EndFunction{}\n    \\end{algorithmic}\n    % \\end{noindent}\n    \\caption{The iterated simulated annealing algorithm}\\label{alg:iterated-simulated-annealing}\n\\end{algorithm}\n\nThe algorithms are essentially identical, as are their implementations.\n\n\\begin{minted}[highlightlines={14}]{python}\n    def iterated_simulated_annealing(func, bounds, sigma, temp, cooling_factor, iters):\n        \"\"\"Repeatedly run simulated annealing to improve the quality of the results.\n\n        :param func: The function to minimize.\n        :param bounds: The lower and upper bounds on the feasible region.\n        :param sigma: The standard deviation to use when perturbing the current guess.\n        :param temp: The initial temperature of the system.\n        :param cooling_factor: How quickly the system should cool.\n        :param iters: The number of times to run the algorithm.\n        :returns: An array of solutions from each run, sorted by their fitness.\n        \"\"\"\n        pool = ThreadPool(multiprocessing.cpu_count())\n        # starmap consumes the given iterable in parallel until it is exhausted, collecting the results.\n        results = pool.starmap(simulated_annealing, itertools.repeat((func, bounds, sigma, temp, cooling_factor), times=iters))\n        # Each result is a full path, not the optimal value\n        optimums = [r[-1] for r in results]\n        # Sort the optimums by their fitness.\n        optimums.sort(key=func)\n        return np.array(optimums)\n\\end{minted}\n\n\\subsection{Results}\n\n\\subsubsection{Hill Climbing}\n\nRecall that the implementation of \\autoref{alg:hill-climbing} picks a random starting point\nsomewhere inside the feasible region. There is also randomness in the perturbation of the current\nsolution as the algorithm progresses. This means one cannot run the algorithm once to get a sense\nof how well it performs. Thus I ran the hill climbing algorithm a great many times\\footnote{Three.\n    I ran it three times.} and plotted the results, summarized in\n\\autoref{fig:prob1:hill-climbing-results}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{prob1/figures/prob1-hill-climbing-results.pdf}\n    \\caption{Results from successive runs of the hill climbing\n        algorithm}\\label{fig:prob1:hill-climbing-results}\n\\end{figure}\n\nIn the left column, there is the accepted solution graphed as a function of the iteration number.\nIn the right column, there is a plot of the accepted solutions overlayed on top of the objective\nvalue.\n\nInterestingly, the plot of the accepted solution as a function of the iteration number was often a\nvery ``stairsteppy'' function, with riser height of $0.1$. That is, the accepted solutions very\noften seem to jump from peak to peak, without hitting the sides of the peaks. I believe this is a\nfigment of my imagination, and is a consequence of the combination of the hill climbing algorithm\nonly accepting values that improve the current solution and the nature of the function being\noptimized --- with steep, narrow peaks.\n\nSince the iterated hill climbing algorithm in \\autoref{alg:iterated-hill-climbing} takes the best\nsolution out of $n$ runs of the algorithm, it's useful to plot the results of all $n$ runs on the\nsame plot. \\autoref{fig:prob1:iterated-hill-climbing-solutions} shows the results of the iterated\nhill climbing algorithm.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics{prob1/figures/prob1-hill-climbing-solution.pdf}\n    \\caption{Solutions from multiple runs of the hill climbing\n        algorithm}\\label{fig:prob1:iterated-hill-climbing-solutions}\n\\end{figure}\n\nNotice that every near\\footnote{It's bad form to save a binary file in a Git repository, so I have\n    to generate these plots every time I build this document from scratch. Since the algorithms are\n    random, this results in different plots every time --- so the result that makes it into the\n    final version may not be what I'm looking at now. There are fixes for this problem, but none\n    that I care to implement.} every peak is a solution returned by at least one iteration of the\nhill climbing algorithm. Also note that the solutions cluster around the peaks, rather than\nconverge on the actual peaks themselves. This is due to the steep nature of each peak; a small\nchange in $x$ results in a fairly large change in $f(x)$. This means that random perturbations of\n$x$ are more likely to land below the current solution than above.\n\n\\subsubsection{Simulated Annealing}\n\nAfter a considerable\\footnote{As an aside, it's very frustrating to not know if you're being an\n    idiot and implemented an algorithm incorrectly, or if you're being an idiot and picked\n    unreasonable metaparameters.} amount of tuning, I was able to get simulated annealing to yield\nbetter results than the hill climbing algorithm. The tunable metaparameters that I tweaked were the\nstandard deviation of the perturbation function, the initial temperature, and the cooling factor.\n\nPicking an appropriate standard deviation is important because the scale of the domain is small\nenough that noise following a standard normal distribution is \\textit{too} noisy --- resulting in\nconvergence to a random peak \\textit{despite exploring the entire damn feasible region}. Picking\nthe cooling factor is important because we need to give the algorithm enough time to get its\nrebellious teenager phase out of the way before it starts settling down to a single value.\n\nThe initial temperature of the system is interesting. After finding good values for the\nperturbation\\footnote{Fun fact: I've had enough to drink that I first spelled this as\n    ``preturnabtion'', which is bad enough that my spell-checking extension failed to detect as an\n    error.} standard deviation and the cooling factor, I attempted to use temperatures of the same\norder of magnitude as the example solution of the Travelling Salesman Problem. Such temperatures\n\\textit{did} yield correct solutions, but only after an extreme amount of exploration; it took\nlonger to display the plot than it did to generate the solutions due to the amount of data\ninvolved.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{prob1/figures/prob1-simulated-annealing-results.pdf}\n    \\caption{Simulated annealing results after an inordinate amount of\n        tuning}\\label{fig:prob1:simulated-annealing-results}\n\\end{figure}\n\nAfter figuring out appropriate values for the perturbation standard deviation and the cooling\nschedule, I was able to observe that modifying the initial temperature did not seem to modify the\nquality of the solution, or the value the iterated algorithm converged to, but \\textit{did} impact\nthe rate of convergence. I attempted values ranging from $8000$ to $0.002$, all of which eventually\nconverged to the same value.\n\nI eventually settled on an initial temperature of $0.01$ even though $0.002$ worked just as well,\nbecause an iterative algorithm that converges after only $15$ iterations isn't very exciting.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics{prob1/figures/prob1-simulated-annealing-solutions.pdf}\n    \\caption{Iterated simulated annealing results}\\label{fig:prob1:simulated-annealing-solutions}\n\\end{figure}\n\nObserve from \\autoref{fig:prob1:simulated-annealing-solutions} that, with the proper\nmetaparameters, the simulated annealing algorithm has \\textit{much} better results than the hill\nclimbing results summarized in \\autoref{fig:prob1:iterated-hill-climbing-solutions}. Each of the\nruns of the simulated annealing algorithm results in the same peak marked as the solution. Further,\nnote that the solutions \\textit{seem to be the same point}, as opposed to the fairly loose clusters\nof the hill climbing algorithm. This is a consequence of the convergence condition of the simulated\nannealing algorithm, versus the fixed number of iterations of the hill climbing algorithm.\n\nIn summary, I have several observations.\n\\begin{itemize}\n    \\item The simulated annealing algorithm converges closer to the actual peaks of the objective\n          function.\n    \\item Simulated annealing required a considerable amount of tuning.\n    \\item The tunable metaparameters that affected the correctness of the solution the most were\n          the standard deviation of the perturbation, and the cooling factor. The parameter that\n          affected speed of convergence the most was the initial temperature.\n    \\item The solutions from repeated runs of the simulated annealing algorithm clustered much more\n          tightly than the solutions from repeated runs of the hill climbing algorithm.\n    \\item When considering the standard deviation of the perturbation, you want enough noise to\n          explore the feasible region, yet not so cuh that you jump all over the place.\n    \\item Temperatures ranging from $8000$ to $0.002$ (because 0.001 is the convergence criterion)\n          worked well, but smaller temperatures converged much faster.\n\\end{itemize}\n\n\\section{The TSP with Mutation Only}\\label{prob:2}\n\n\\subsection{Statement}\nIn lecture we addressed the Traveling Salesman Problem using Simulated Annealing. To speed up\nconvergence and increase the odds of finding the global extremal, it makes sense to try an\nevolutionary algorithm. The mutation operator can be adapted from the SA algorithm. Skip\nrecombination in this problem. Write an evolutionary algorithm to solve the TSP as generated in the\nsample program. Compare deterministic and stochastic selection operators.\n\n\\subsection{Method}\nThere are a number of decisions to make when implementing the standard evolutionary algorithm\nlisted in \\autoref{alg:standard-ea}. There are a great many ways to perform each of the steps\n(Initialization, Recombination, Mutation, and Selection, as well as the stopping criterion), and\npicking the \\textit{right} method constitutes the difficulty of the problem.\n\n\\begin{algorithm}[h]\n    % \\begin{noindent}\n    \\begin{algorithmic}\n        \\Function{standard-ea}{}\n            \\State{Initialize $population$}\n            \\While{not done}\n                \\State{Recombine $population$}\n                \\State{Mutate $population$}\n                \\State{Select $population$}\n            \\EndWhile{}\n            \\State\\Return{$population$}\n        \\EndFunction{}\n    \\end{algorithmic}\n    % \\end{noindent}\n    \\caption{The standard evolutionary algorithm}\\label{alg:standard-ea}\n\\end{algorithm}\n\nIn this problem, there will be no recombination of the population, only mutation and selection.\nRecombination will be done in \\autoref{prob:3}, however, so it is useful to keep recombination in\nmind when implementing the solution for this problem.\n\n\\subsubsection{Solution Representation}\nOf particular importance is the choice of solution representation. The representations for a\nproblem make an extreme effect on the performance, ease, and usability of a solution. In many cases\neven, your choice of data structure makes the proper algorithm for solving the problem obvious,\nwhile an improper choice makes implementing the solution tedious, nonintuitive, and ill-performant.\n\nFor this problem, the most obvious representation for a solution is an ordered path\n\\[\\lbrack C_1, C_2, \\dots C_n \\rbrack \\]\nof cities. There are other representations, however. As a reference,~\\cite{tsp_ea} enumerates a\ngreat deal of variations for the representations of solutions, mutation operators, and\nrecombination operators. Briefly, the solution representation options that~\\cite{tsp_ea} lists are\nlisted\\footnote{I'm running out of nested \\LaTeX{} subsections!} below.\n\n\\paragraph{Bitstring}\nThe bitstring representation is the most common solution representation in traditional evolutionary\nand genetic algorithm literature. In this representation, with a problem with $n$ cities, a\nparticular city is encoded as a bitstring of length $\\ceil*{\\log_2 n}$, and a path of cities (a\nsolution) as a bitstring of $n\\ceil*{\\log_2 n}$ concatenated cities.\n\nHowever, this representation provides some difficulty when implementing \\autoref{alg:standard-ea}.\nNamely, the mutation and recombination operators must be more sophisticated than simple bitwise\noperations because some $\\ceil*{\\log_2 n}$ long bitstrings might not represent a valid city, and\nsome $n\\ceil*{\\log_2 n}$ long bitstrings might not represent a valid solution to the problem. There\nare some solutions to these problems, which~\\cite{tsp_ea} mentions, but they are more tedious than\nI would prefer.\n\n\\paragraph{Matrix}\nThe paper~\\cite{tsp_ea} lists two different binary matrix representations of a solution.\n\\begin{enumerate}\n    \\item Represent an individual as a matrix $M = \\{m_{ij}\\}$ where $m_{ij} = 1$ if and only if\n          the city $i$ is visited before the city $j$ in the represented tour. The paper lists the\n          following properties that hold for a valid tour represented in this manner.\n          \\begin{enumerate}\n              \\item $\\displaystyle \\sum_i^n \\sum_j^n m_{ij} = \\frac{n(n - 1)}{2}$\n              \\item $\\displaystyle m_{ii} = 0$\n              \\item $\\displaystyle (m_{ij} = 1) \\wedge (m_{jk} = 1) \\Rightarrow m_{ik} = 1$\n          \\end{enumerate}\n    \\item Represent an individual as a matrix $M = \\{m_{ij}\\}$ where $m_{ij} = 1$ if and only if\n          city $j$ is visited immediately after city $i$. That is, a valid tour is represented by a\n          matrix with exactly one $1$ in every row and in every column.\n\\end{enumerate}\n\n\\paragraph{Adjacency List}\nAn uncommon representation is that of an adjacency list, where city $j$ occurs in the $i$th\nposition of the list if and only if the tour leads from city $i$ to city $j$. However, the proposed\nmutation and recombination operators good subpaths in parents, so this representation is not widely\nused.\n\n\\paragraph{Ordered Path}\nAs mentioned above, this is the most obvious representation, and the one~\\cite{tsp_ea} exclusively\ndeals with. Here, a path is represented as an ordered list\n\\[C_1, C_2, \\dots C_n \\]\nwhere $C_i$ occurs at the $j$th position if it is the $j$th city to be visited.\n\nThis representation yields itself nicely to the fitness evaluation of individuals in your\npopulation, and is useful as the final representation of a returned solution. However, the\nclassical mutation and recombination operators typically performed on bitstrings will not work on\nthis representation because they can (will) result in invalid paths.\n\nThis will be the representation I use, and is thus the only representation I attempt to define\nmutation and (in \\autoref{prob:3}) recombination operators on. In this representation, we can\ngenerate a starting collection of cities with\n\n\\begin{minted}{python}\n    def generate_cities(n, scale=100):\n        \"\"\"Generates an array of cities of the given size.\n\n        Pick random coordinates in the `scale`x`scale` grid uniformly.\n\n        :param n: The size of the individual to generate.\n        :param scale: How much to scale the individual's coordinates by.\n        \"\"\"\n        # Scale up the uniform values from [0, 1].\n        return np.random.rand(n, 2) * scale\n\\end{minted}\n\nand a random population of different orderings for a collection of cities with\n\n\\begin{minted}{python}\n    def generate_population(cities, size, scale=100):\n        \"\"\"Generate a population of individuals with the given size.\n\n        Each individual is an array of indices into the given cities array.\n\n        :param cities: An unsorted array of city locations.\n        :param size: The number of individuals to generate.\n        :param scale: How much to scale the individual's coordinates by.\n        \"\"\"\n        n = len(cities)\n        population = np.zeros((size, n), dtype=int)\n        for i in range(size):\n            individual = np.arange(n, dtype=int)\n            np.random.shuffle(individual)\n            population[i] = individual\n        return population\n\\end{minted}\n\nNote that in this representation, an individual is a list of indices into the\n\\mintinline{python}{cities} array. This is to prevent repeatedly duplicating the array of the same\ncities in different orders.\n\nThe \\mintinline{python}{generate_individual()} function generates a single individual as shown in\n\\autoref{fig:prob2:random-individual}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics{prob2/figures/prob2-random-individual.pdf}\n    \\caption{A randomly generated individual}\\label{fig:prob2:random-individual}\n\\end{figure}\n\nNote that each city is an $(x, y)$ pair so that we can more easily compute the distance between\nthem without explicitly saving that information in a graph datastructure.\n\n\\subsubsection{Fitness}\nWith this representation as an individual as an ordered list of ordered pairs, an individual's\nsolution is given as the sum of the pairwise distances between cities. To implement this, it is\nhelpful to use the\n\\href{https://docs.python.org/3/library/itertools.html#itertools-recipes}{itertools pairwise\n    recipe} for iterating over a sequence in pairs.\n\\begin{minted}{python}\n    import itertools\n\n    def pairwise(iterable):\n        \"\"\"Iterate over the given iterable in pairs.\n\n        pairwise([1, 2, 3, 4]) -> (1, 2), (2, 3), (3, 4)\n        \"\"\"\n        a, b = itertools.tee(iterable)\n        # Advance b one step\n        next(b, None)\n        return zip(a, b)\n\\end{minted}\nThen the fitness function for an individual can be written succinctly as\n\\begin{minted}{python}\n    def fitness(cities, path):\n        \"\"\"Evaluate the fitness of the given path.\n\n        Compute the Euclidean distance between every pair of cities in the path\n        and add them together.\n\n        :param cities: The array of cities through which to compute a path.\n        :param path: The path through the given cities to compute the fitness for.\n        :returns: The fitness of the individual.\n        \"\"\"\n        individual = cities[path]\n        return 1 / sum(np.linalg.norm(c1 - c2) for c1, c2 in pairwise(individual))\n\\end{minted}\n\nNote that the sum is inverted, because we want to \\textit{minimize} the fitness. I also played\naround with simply negating the fitness, which worked quite well in some cases. However, in the\nstochastic selection discussed below, I wanted to further separate the good individuals from the\npoor individuals. Inverting the fitness seemed to have a good result.\\footnote{What happens if you\n    leave the fitness alone, without negating or inverting? I couldn't even \\textit{begin} to\n    guess, although I'm sure a naive student might spend hours and hours wondering why their\n    implementation was giving them the exact opposite of what they wanted.}\n\n\\subsubsection{Mutation Methods}\\label{sec:mutation-methods}\nThere are a number of possible mutation operators that will work on the chosen solution\nrepresentation. Note that these implementations are sometimes not as simple as one would think,\nbecause an array access (\\mintinline{python}{v = a[i]}) returns a \\textit{view} of the original\narray. And when you modify a view, it modifies the original array. This has particular importance\nwhen dealing with multidimensional arrays because the returned items are now \\textit{views} rather\nthan direct scalar values.\n\n\\paragraph{Swap Mutation} This mutation randomly swaps two cities in the tour.\n\\begin{minted}{python}\n    def swap_mutation(path):\n        \"\"\"Swap two random cities in the path.\n\n        Returns a new mutated copy of the given array.\n        \"\"\"\n        # Arrays are (kind of) passed by reference in Python.\n        x = np.copy(path)\n        # Generate two valid indices to swap.\n        i = np.random.randint(0, len(x) - 2)\n        j = np.random.randint(i, len(x) - 1)\n        # array indexing returns views, not copies\n        temp = np.copy(x[i])\n        x[i] = x[j]\n        x[j] = temp\n\n        return x\n\\end{minted}\n\n\\paragraph{Insertion Mutation} This mutation is similar to a swap. It picks a random city, removes\nit from the list, and inserts it at some randomly selected position.\n\\begin{minted}{python}\n    def insertion_mutation(path):\n        \"\"\"Insert a random value in the list somewhere else in the list.\n\n        Returns a new mutated copy of the given array.\n        \"\"\"\n        i = np.random.randint(0, len(path) - 2)\n        j = np.random.randint(i, len(path) - 1)\n        # Delete the element at index j and insert it before index i.\n        temp = np.delete(path, j, axis=0)\n        temp = np.insert(temp, i, path[j], axis=0)\n\n        return temp\n\\end{minted}\n\n\\paragraph{Displacement Mutation} This is a natural extension of the insertion mutation. Rather\nthan removing and inserting a single city, remove and insert an entire subpath.\n\\begin{minted}{python}\n    def displacement_mutation(path):\n        \"\"\"Inserts a random subarray in the list somewhere else.\n\n        Returns a new mutated copy of the given array.\n        \"\"\"\n        # Pick a random subarray\n        i = np.random.randint(0, len(path) - 2)\n        j = np.random.randint(i, len(path) - 1)\n        subarray = path[i:j]\n        # Delete the given subarray\n        tmp = np.delete(path, range(i, j), axis=0)\n        k = np.random.randint(0, len(tmp) - 1)\n\n        return np.insert(tmp, k, subarray, axis=0)\n\\end{minted}\n\n\\paragraph{Shuffle Mutation} This mutation is not used much, because it can destroy good genetic\ninformation in a parent. It picks a random subpath in a solution and shuffles it.\n\\begin{minted}{python}\n    def shuffle_mutation(path):\n        \"\"\"Shuffles a random subarray in the given path.\n\n        Returns a new mutated copy of the given array.\n        \"\"\"\n        # Pick a random subarray\n        i = np.random.randint(0, len(path) - 2)\n        j = np.random.randint(i, len(path) - 1)\n        x = np.copy(path)\n        np.random.shuffle(x[i:j])\n\n        return x\n\\end{minted}\n\n\\paragraph{Inversion Mutation} This is the mutation used in the simulated annealing example shown\nin class. It picks a random subpath in a solution, and reverses it. This is a useful operator\nbecause it breaks only two links between cities, and leaves the rest intact. All of the other\nmutations can be implemented as a sequence of inversions. A proof of this remark is given in\n\\autoref{app:proof}. This mutation can also be extended to act like the displacement mutation where\na random subpath is removed, inverted, and reinserted somewhere else in the tour.\n\\begin{minted}{python}\n    def inversion_mutation(path):\n        \"\"\"Inverts a random subarray in the given path.\n\n        Returns a new mutated copy of the given array.\n        \"\"\"\n        i = np.random.randint(0, len(path) - 2)\n        j = np.random.randint(i, len(path) - 1)\n        x = np.copy(path)\n        # Invert the subarray.\n        x[i:j] = x[i:j][::-1]\n\n        return x\n\\end{minted}\n\nGiven these mutation methods, I define the \\mintinline{python}{mutate()} function for ease of use.\n\n\\begin{minted}{python}\n    def mutate(path, method='inversion'):\n        \"\"\"Mutate the given individual via the given method.\n\n        Returns a new mutated copy of the given array.\n\n        :param method: One of 'swap', 'insertion', 'displacement',\n        'shuffle', or 'inversion'. Defaults to 'inversion'.\n        \"\"\"\n        methods = {\n            'swap': swap_mutation,\n            'insertion': insertion_mutation,\n            'displacement': displacement_mutation,\n            'shuffle': shuffle_mutation,\n            'inversion': inversion_mutation,\n        }\n        return methods[method](path)\n\\end{minted}\n\n\\subsubsection{Selection Methods}\nIn my implementation, I will deal with two different selection methods: stochastic and\ndeterministic. The stochastic selection will rank the population according to their fitness and\nsample the sorted population by some probability distribution where the probability of being chosen\nis directly proportional to an individual's fitness. The deterministic method will rank the\npopulation by their fitness and select the top $n$ to survive.\n\nWe can implement deterministic selection by\n\\begin{minted}{python}\n    def deterministic_selection(population, size, func, cities):\n        \"\"\"Deterministically select the most fit from the given population.\n\n        Use the given fitness function to rank the population, then pick\n        the next `size` of the population to move on. This assumes that,\n        for a problem without recombination, the mutated individuals have\n        been mixed in with the original population.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :returns: The culled population, sorted upwards in increasing fitness.\n        \"\"\"\n        fitnesses = np.array([func(cities, p) for p in population])\n        indices = np.argsort(fitnesses, axis=0)\n        euthanize = len(population) - size\n        return population[indices][euthanize:]\n\\end{minted}\nstochastic selection by\n\\begin{minted}{python}\n    def stochastic_selection(population, size, func, cities):\n        \"\"\"Randomly select the most fit from the given population.\n\n        Select without replacement an individual with probability\n        proportional to its fitness.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :returns: The culled population, unsorted.\n        \"\"\"\n        fitnesses = np.array([func(cities, p) for p in population])\n        probabilities = fitnesses / np.sum(fitnesses)\n        survivors = np.random.choice(len(population), size, replace=False, p=probabilities)\n        return population[survivors]\n\\end{minted}\nand finally, a nice helper function\n\\begin{minted}{python}\n    def select(population, size, func, cities, method='deterministic'):\n        \"\"\"Select the `size` most fit from the given population.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :param method: One of 'deterministic' or 'stochastic'.\n        :returns: The culled population, in arbitrary order.\n        \"\"\"\n        methods = {\n            'stochastic': stochastic_selection,\n            'deterministic': deterministic_selection,\n        }\n        return methods[method](population, size, func, cities)\n\\end{minted}\n\n\\subsubsection{The Evolutionary Algorithm}\nWith all of the above snippets defined, implementing the evolutionary algorithm listed in\n\\autoref{alg:standard-ea} (without recombination) can be done simply as\n\n\\begin{minted}{python}\n    def simple_ea(cities, size, func, iters, mutation='inversion', selection='deterministic'):\n        \"\"\"Run the standard evolutionary algorithm to solve the TSP.\n\n        This implementation does not use recombination.\n\n        :param cities: The array of city locations.\n        :param size: The population size to use.\n        :param func: The fitness function to use.\n        :param iters: The number of iterations (generations) to run.\n        :param mutation: The type of mutation to use. One of 'swap', 'insertion',\n        'displacement', 'shuffle', or 'inversion'.\n        :param selection: The type of selection to use. One of 'deterministic',\n        or 'stochastic'.\n        \"\"\"\n        n = len(cities)\n        population = generate_population(cities, size)\n        best_fitnesses = np.zeros(iters)\n        best_individuals = np.zeros((iters, n), dtype=int)\n        for i in range(iters):\n            # Do not recombine population.\n            mutations = np.array([mutate(p, method=mutation) for p in population], dtype=int)\n            # This is a $(\\mu + \\lambda)$ selection.\n            combined = np.concatenate((population, mutations))\n            population = select(combined, size, func, cities, method=selection)\n            fitnesses = np.array([func(cities, p) for p in population])\n            # Record the current best individual\n            best = fitnesses.argmax()\n            best_fitnesses[i] = fitnesses[best]\n            best_individuals[i] = population[best]\n\n        return best_fitnesses, best_individuals\n\\end{minted}\n\nNote that this implementation does not have a convergence criterion. It simply runs for the\nspecified number of iterations.\n\n\\subsubsection{Simulated Annealing}\nSince we talked about it in class, and we essentially already have the code for this problem, I\nwent ahead and implemented simulated annealing by tweaking the example given in class to satisfy my\nsensibilities.\n\n\\begin{minted}{python}\n    def evaluate(tour):\n        \"\"\"Evaluate the length of the given tour.\n\n        Compute the Euclidean distance between every pair of cities in the tour\n        and add them together.\n\n        :param tour: An array of cities, where each city is n (x, y) pair.\n        \"\"\"\n        return sum(np.linalg.norm(c1 - c2) for c1, c2 in pairwise(tour))\n\n    def perturb(x):\n        \"\"\"Perturb the given array.\n\n        Perform a sublist inversion in the interior of the given array.\n\n        :param x: The array to perturb. Is not modified.\n        \"\"\"\n        # Compute two random indices, avoiding the endpoints.\n        i = np.random.randint(0, len(x) - 2)\n        j = np.random.randint(i, len(x) - 1)\n        # Produce a copy of the given array and invert a random sublist inside.\n        y = np.copy(x)\n        y[i:j] = y[i:j][::-1]\n        return y\n\n    def simulated_annealing(cities, temperature=800, cooling_factor=0.001):\n        \"\"\"Run the simulated annealing algorithm to solve the TSP.\n\n        :param cities: An array of (x, y) city coordinates.\n        :param temperature: The starting temperature of the system, defaults to 800\n        :param cooling_factor: How quickly to cool the system, defaults to 0.001\n        \"\"\"\n        current = evaluate(cities)\n        energies = [current]\n        while temperature > 0.001:\n            new_solution = perturb(cities)\n            energy = evaluate(new_solution)\n            if np.random.random() < np.exp((current - energy) / temperature)\n                cities = new_solution\n                current = energy\n                energies.append(current)\n            temperature *= 1 - cooling_factor\n        return cities, np.array(energies)\n\\end{minted}\n\nNote that this implementation uses the uninverted fitness function, so in order to compare apples\nto pears and grapefruit to plums, the returned array of fitnesses must be inverted as well.\n\n\\subsection{Results}\nIn \\autoref{prob:1}, each run of the hill climbing and simulated annealing functions generated the\ninitial random starting point. Here, however, since we're comparing the results of three different\nalgorithms, I generated the random cities ahead of time.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics{prob2/figures/prob2-city-locations.pdf}\n    \\caption{The city locations to use for the TSP}\\label{fig:prob2:city-locations}\n\\end{figure}\n\nThen I chose to use only the inversion mutation and compare stochastic and deterministic selection\nmethods against the solution from the simulated annealing algorithm.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob2/figures/prob2-fitness-stochastic.pdf}\n        \\caption{Fitness over time}\\label{fig:prob2:stochastic-fitness}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob2/figures/prob2-best-stochastic.pdf}\n        \\caption{The best solution}\\label{fig:prob2:stochastic-best}\n    \\end{subfigure}\n    \\caption{The stochastic selection operator results}\\label{fig:prob2:stochastic-selection}\n\\end{figure}\n\nNotice in \\autoref{fig:prob2:stochastic-fitness} that the fitness of the best individual in the\npopulation over time has a lot of variability when using stochastic selection. I attempted several\nvariations on the stochastic selection, and I saw results similar to this in every case. Often the\nbest solution was the very first one attempted, and no solution past that point improved on it. In\nother cases the best fitness show no overall trend upwards or downwards.\n\nMoving from simply negating the fitness function to \\textit{minimize} the tour length to leaving it\npositive and inverting it seemed to have the best results. However poor results slightly improved\nare still poor results.\n\nChanging the \\mintinline{python}{numpy.random.choice} function to sample with and without\nreplacement did not seem to have a substantial impact on the end solution, so I chose to sample\nwithout replacement because I'm cruel and merciless.\n\nTo fix this behavior, I think the simple implementation\n\\begin{minted}{python}\n    def stochastic_selection(population, size, func, cities):\n        \"\"\"Randomly select the most fit from the given population.\n\n        Select without replacement an individual with probability\n        proportional to its fitness.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :returns: The culled population, unsorted.\n        \"\"\"\n        fitnesses = np.array([func(cities, p) for p in population])\n        probabilities = fitnesses / np.sum(fitnesses)\n        survivors = np.random.choice(len(population), size, replace=False, p=probabilities)\n        return population[survivors]\n\\end{minted}\nshould be modified to not kill the very best individuals, or should use a probability distribution\nmore heavily weighted towards the top than a uniform distribution weighted by an individual's\nfitness. Another option would be to decrease the randomness in the selection as time progresses, as\ndoes simulated annealing. This, combined with some kind of convergence criterion would be the best\noption, but more difficult to implement than what I'm willing to tackle with only half of my\nhomework done and the deadline quickly approaching.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob2/figures/prob2-fitness-deterministic.pdf}\n        \\caption{Fitness over time}\\label{fig:prob2:deterministic-fitness}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob2/figures/prob2-best-deterministic.pdf}\n        \\caption{The best solution}\\label{fig:prob2:deterministic-best}\n    \\end{subfigure}\n    \\caption{The deterministic selection operator results}\\label{fig:prob2:deterministic-selection}\n\\end{figure}\n\nNotice from \\autoref{fig:prob2:deterministic-fitness} that the fitness of the best individual over\ntime, when using deterministic selection, grows steadily before tapering off. Also notice that it\ntapers off at a value almost double that of the highest peak of\n\\autoref{fig:prob2:stochastic-fitness}. We can plainly see that the best individual found, shown in\n\\autoref{fig:prob2:deterministic-best}, is a much more reasonable solution than that of stochastic\nselection displayed in \\autoref{fig:prob2:stochastic-best}.\n\nHowever, there are still improvements that can be picked out visually.\\footnote{Again, each\n    run produces different figures, so this statement was true when I wrote it.} We might be able\nto improve on this solution method by using a different mutation operator, but none of the ones\nlisted in \\autoref{sec:mutation-methods} yielded any better results.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob2/figures/prob2-simulated-annealing-fitness.pdf}\n        \\caption{}\\label{fig:prob2:simulated-annealing-fitness}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob2/figures/prob2-simulated-annealing.pdf}\n        \\caption{}\\label{fig:prob2:simulated-annealing-best}\n    \\end{subfigure}\n    \\caption{The simulated annealing results}\\label{fig:prob2:simulated-annealing}\n\\end{figure}\n\nSimulated annealing produced results similar in quality to the evolutionary algorithm, with\ndeterministic selection, and much better results than with the stochastic selection operator.\nFurther, the simulated annealing algorithm terminates \\textit{much} faster than the evolutionary\nalgorithm. This is expected, due to the amount of work being done, because the simulated annealing\nalgorithm works on a single individual, while the evolutionary algorithms work on an entire\npopulation.\n\nThere are a number of tuneable parameters that I played with. There are, in my implementation,\n\\begin{itemize}\n    \\item The transformation on the fitness function\n    \\item The mutation operator\n    \\item Deterministic/stochastic selection\n    \\item Population size\n    \\item Number of generations\n\\end{itemize}\nThe transformation of the fitness function (simple negation or inversion) \\textit{seemed} to have\nan effect, but nothing measured. The mutation operator had a substantial impact, with the best one\nbeing the sublist inversion. Using a deterministic selection operator consistently yielded the best\nresults. Being slightly impatient, I did not experiment with very large populations or large\nnumbers of generations. I think there is some parallelism that I could have taken advantage of to\nmake it easier to wait, but moving on to \\autoref{prob:3} is currently more important.\n\n\\section{The TSP with Mutation and Recombination}\\label{prob:3}\n\n\\subsection{Statement}\nIn \\autoref{prob:2} we implemented EA code to solve the Traveling Salesman Problem. In this\nproblem, implement recombination (crossover) in your EA. For this problem you will need to use an\nencoding that prevents crossover that creates an invalid candidate. As before, compare\ndeterministic and stochastic selection operators.\n\n\\subsection{Method}\nAs mentioned in \\autoref{prob:2}, I found a paper~\\cite{tsp_ea} listing many different mutation and\nrecombination operators on the simple ordered-path encoding for a solution to the TSP. I used the\nsame mutation and selection operators given in \\autoref{sec:mutation-methods}. The interesting\nstuff in this problem are the recombination operators given in~\\cite{tsp_ea}.\n\n\\subsubsection{Partially-Mapped Crossover (PMX)}\nAccording to~\\cite{tsp_ea}, the PMX crossover is the most widely used recombination operator for\npath-type problems. This operator combines parents $P_1$ and $P_2$ to get children $C_1$ and $C_2$.\nThe second child is produced in exactly the same manner as the first, but with the parents swapped.\nIt works as follows\n\\begin{enumerate}\n    \\item Choose two crossover points at random, and copy the sublist between them from $P_1$ into\n          $C_1$ at the same location.\\footnote{God damn it, these are really simple pictures, and\n              were very easy to make, but to get nice colors took about 5 hours longer than it\n              should have.}\n          \\begin{figure}[H]\n              \\centering\n              \\begin{tikzpicture}[font=\\ttfamily,\n                      array/.style={\n                              matrix of nodes,\n                              nodes={\n                                      draw,\n                                      anchor=center,\n                                      minimum size=7mm,\n                                      inner sep=0pt\n                                  },\n                              column sep=-\\pgflinewidth,\n                              row sep=-\\pgflinewidth,\n                              nodes in empty cells\n                          }]\n\n                  \\matrix[array] (P1) {\n                      1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n                  };\n                  \\matrix[array, below of=P1, yshift=-1cm] (P2) {\n                      9 & 3 & 7 & 8 & 2 & 6 & 5 & 1 & 4 \\\\\n                  };\n\n                  \\matrix[array, right of=P2-1-9, anchor=west, yshift=1cm] (C1) {\n                       &  &  & 4 & 5 & 6 & 7 &  & \\\\\n                  };\n                  \\node[left of=P1-1-1] {$P_1$};\n                  \\node[left of=P2-1-1] {$P_2$};\n                  \\node[right of=C1-1-9] {$C_1$};\n\n                  % Highlight the sublist.\n                  \\begin{scope}[on background layer]\n                      \\fill[__minted_background_color] (P1-1-1.north west) rectangle (P1-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P1-1-4.north west) rectangle (P1-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (P2-1-1.north west) rectangle (P2-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P2-1-4.north west) rectangle (P2-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (C1-1-1.north west) rectangle (C1-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (C1-1-4.north west) rectangle (C1-1-7.south\n                      east);\n                  \\end{scope}\n              \\end{tikzpicture}\n              \\caption{Step 1, copy subarray}\\label{fig:prob3:pmx-step-1}\n          \\end{figure}\n    \\item Starting from the first crossover point, look for elements of $P_2$ that were not copied\n          to $C_1$.\n          \\begin{figure}[H]\n              \\centering\n              \\begin{tikzpicture}[font=\\ttfamily,\n                      array/.style={\n                              matrix of nodes,\n                              nodes={\n                                      draw,\n                                      anchor=center,\n                                      minimum size=7mm,\n                                      inner sep=0pt\n                                  },\n                              column sep=-\\pgflinewidth,\n                              row sep=-\\pgflinewidth,\n                              nodes in empty cells\n                          }]\n\n                  \\matrix[array] (P1) {\n                      1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n                  };\n                  \\matrix[array, below of=P1, yshift=-1cm] (P2) {\n                      9 & 3 & 7 & 8 & 2 & 6 & 5 & 1 & 4 \\\\\n                  };\n\n                  \\matrix[array, right of=P2-1-9, anchor=west, yshift=1cm] (C1) {\n                       &  &  & 4 & 5 & 6 & 7 &  & \\\\\n                  };\n                  \\node[left of=P1-1-1] {$P_1$};\n                  \\node[left of=P2-1-1] {$P_2$};\n                  \\node[right of=C1-1-9] {$C_1$};\n\n                  % Highlight the sublist.\n                  \\begin{scope}[on background layer]\n                      \\fill[__minted_background_color] (P1-1-1.north west) rectangle (P1-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P1-1-4.north west) rectangle (P1-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (P2-1-1.north west) rectangle (P2-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P2-1-4.north west) rectangle (P2-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (C1-1-1.north west) rectangle (C1-1-9.south\n                      east);\n                      %   \\fill[__minted_highlight_color] (C1-1-4.north west) rectangle (C1-1-7.south\n                      %   east);\n                      \\fill[red!30] (P2-1-4.north west) rectangle (P2-1-5.south east);\n                  \\end{scope}\n              \\end{tikzpicture}\n              \\caption{Step 2, find uncopied elements}\\label{fig:prob3:pmx-step-2}\n          \\end{figure}\n    \\item For each of these non-copied elements $i$, find the element $j$ of the first parent that\n          was copied in place of $i$. Place $i$ into the position occupied by $j$ in $P_2$.\n          \\begin{figure}[H]\n              \\centering\n              \\begin{tikzpicture}[\n                      font=\\ttfamily,\n                      array/.style={\n                              matrix of nodes,\n                              nodes={\n                                      draw,\n                                      anchor=center,\n                                      minimum size=7mm,\n                                      inner sep=0pt\n                                  },\n                              column sep=-\\pgflinewidth,\n                              row sep=-\\pgflinewidth,\n                              nodes in empty cells\n                          },\n                      >=stealth]\n\n                  \\matrix[array] (P1) {\n                      1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n                  };\n                  \\matrix[array, below of=P1, yshift=-1cm] (P2) {\n                      9 & 3 & 7 & 8 & 2 & 6 & 5 & 1 & 4 \\\\\n                  };\n\n                  \\matrix[array, right of=P2-1-9, anchor=west, yshift=1cm] (C1) {\n                       &  &  & 4 & 5 & 6 & 7 &  & 8 \\\\\n                  };\n                  \\node[left of=P1-1-1] {$P_1$};\n                  \\node[left of=P2-1-1] {$P_2$};\n                  \\node[right of=C1-1-9] {$C_1$};\n\n                  \\draw[->] (P2-1-4) edge (P1-1-4) (P1-1-4.south) edge (P2-1-9.north);\n\n                  % Highlight the sublist.\n                  \\begin{scope}[on background layer]\n                      \\fill[__minted_background_color] (P1-1-1.north west) rectangle (P1-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P1-1-4.north west) rectangle (P1-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (P2-1-1.north west) rectangle (P2-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P2-1-4.north west) rectangle (P2-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (C1-1-1.north west) rectangle (C1-1-9.south\n                      east);\n                      \\fill[red!30] (P2-1-4.north west) rectangle (P2-1-5.south east);\n                      \\fill[__minted_highlight_color] (P2-1-9.north west) rectangle (P2-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (C1-1-9.north west) rectangle (C1-1-9.south\n                      east);\n                  \\end{scope}\n              \\end{tikzpicture}\n              \\caption{Step 3, find a free spot to stuff things}\\label{fig:prob3:pmx-step-3}\n          \\end{figure}\n    \\item If the position occupied by $j$ in $P_2$ has already been filled in $C_1$ by an element\n          $k$, put $i$ in the position occupied by $k$ in $P_2$.\n          \\begin{figure}[H]\n              \\centering\n              \\begin{tikzpicture}[\n                      font=\\ttfamily,\n                      array/.style={\n                              matrix of nodes,\n                              nodes={\n                                      draw,\n                                      anchor=center,\n                                      minimum size=7mm,\n                                      inner sep=0pt\n                                  },\n                              column sep=-\\pgflinewidth,\n                              row sep=-\\pgflinewidth,\n                              nodes in empty cells\n                          },\n                      >=stealth]\n\n                  \\matrix[array] (P1) {\n                      1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n                  };\n                  \\matrix[array, below of=P1, yshift=-1cm] (P2) {\n                      9 & 3 & 7 & 8 & 2 & 6 & 5 & 1 & 4 \\\\\n                  };\n\n                  \\matrix[array, right of=P2-1-9, anchor=west, yshift=1cm] (C1) {\n                       &  & 2 & 4 & 5 & 6 & 7 &  & 8 \\\\\n                  };\n                  \\node[left of=P1-1-1] {$P_1$};\n                  \\node[left of=P2-1-1] {$P_2$};\n                  \\node[right of=C1-1-9] {$C_1$};\n\n                  \\draw[->] (P2-1-5) edge (P1-1-5) (P1-1-5.south) edge (P2-1-7.north) (P2-1-7) edge\n                  (P1-1-7) (P1-1-7.south) edge (P2-1-3.north);\n\n                  % Highlight the sublist.\n                  \\begin{scope}[on background layer]\n                      \\fill[__minted_background_color] (P1-1-1.north west) rectangle (P1-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P1-1-4.north west) rectangle (P1-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (P2-1-1.north west) rectangle (P2-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P2-1-4.north west) rectangle (P2-1-7.south\n                      east);\n                      \\fill[__minted_background_color] (C1-1-1.north west) rectangle (C1-1-9.south\n                      east);\n                      %   \\fill[__minted_highlight_color] (C1-1-4.north west) rectangle (C1-1-7.south\n                      %   east);\n                      \\fill[red!30] (P2-1-5.north west) rectangle (P2-1-5.south east);\n                      \\fill[__minted_highlight_color] (P2-1-9.north west) rectangle (P2-1-9.south\n                      east);\n                      %   \\fill[__minted_highlight_color] (C1-1-9.north west) rectangle (C1-1-9.south\n                      %   east);\n                      \\fill[__minted_highlight_color] (P2-1-3.north west) rectangle (P2-1-3.south\n                      east);\n                      \\fill[__minted_highlight_color] (C1-1-3.north west) rectangle (C1-1-3.south\n                      east);\n                  \\end{scope}\n              \\end{tikzpicture}\n              \\caption{Step 4, find better uncopied elements}\\label{fig:prob3:pmx-step-4}\n          \\end{figure}\n    \\item Once each of the uncopied portions of $P_2$'s sublist have been placed, fill the\n          remaining positions from $P_2$.\n          \\begin{figure}[H]\n              \\centering\n              \\begin{tikzpicture}[font=\\ttfamily,\n                      array/.style={\n                              matrix of nodes,\n                              nodes={\n                                      draw,\n                                      anchor=center,\n                                      minimum size=7mm,\n                                      inner sep=0pt\n                                  },\n                              column sep=-\\pgflinewidth,\n                              row sep=-\\pgflinewidth,\n                              nodes in empty cells\n                          }]\n\n                  \\matrix[array] (P1) {\n                      1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n                  };\n                  \\matrix[array, below of=P1, yshift=-1cm] (P2) {\n                      9 & 3 & 7 & 8 & 2 & 6 & 5 & 1 & 4 \\\\\n                  };\n\n                  \\matrix[array, right of=P2-1-9, anchor=west, yshift=1cm] (C1) {\n                      9 & 3 & 2 & 4 & 5 & 6 & 7 & 1 & 8 \\\\\n                  };\n                  \\node[left of=P1-1-1] {$P_1$};\n                  \\node[left of=P2-1-1] {$P_2$};\n                  \\node[right of=C1-1-9] {$C_1$};\n\n                  % Highlight the sublist.\n                  \\begin{scope}[on background layer]\n                      \\fill[__minted_background_color] (P1-1-1.north west) rectangle (P1-1-9.south\n                      east);\n                      \\fill[__minted_background_color] (P2-1-1.north west) rectangle (P2-1-9.south\n                      east);\n                      \\fill[__minted_background_color] (C1-1-1.north west) rectangle (C1-1-9.south\n                      east);\n                      \\fill[__minted_highlight_color] (P1-1-4.north west) rectangle (P1-1-7.south\n                      east);\n                      \\fill[__minted_highlight_color] (P2-1-3.north west) rectangle (P2-1-7.south\n                      east);\n                      \\fill[__minted_highlight_color] (P2-1-9.north west) rectangle (P2-1-9.south\n                      east);\n\n                      \\fill[__minted_highlight_color] (C1-1-1.north west) rectangle (C1-1-2.south\n                      east);\n                      \\fill[__minted_highlight_color] (C1-1-8.north west) rectangle (C1-1-8.south\n                      east);\n                  \\end{scope}\n              \\end{tikzpicture}\n              \\caption{Step 5, fill in the rest of $P_2$}\\label{fig:prob3:pmx-step-5}\n          \\end{figure}\n\\end{enumerate}\n\nThe second child $C_2$ is created in the same manner, with parents swapped. This crossover operator\nwas surprisingly tricky\\footnote{Want to play a game? It's called ``Find The Bug'', and I hear\n    there's a prize this year.} to implement, and especially so with Numpy arrays over the usual\nPython lists due to missing functionality.\n\n\\begin{minted}{python}\n    def pmx(mom, dad):\n        \"\"\"Recombination using the Partially-Mapped Crossover algorithm.\n\n        :param mom: The first parent.\n        :type mom: list\n        :param dad: The second parent.\n        :type dad: list\n        :returns: The recombined child.\n        :rtype: list\n        \"\"\"\n        # Pick a random chunk 1/3 the length of mom's genes to flat-out copy.\n        l = len(mom) // 3\n        i = np.random.randint(0, len(mom) - l)\n        j = i + l\n        child = [0] * len(mom)\n        sublist1 = mom[i:j]\n        sublist2 = dad[i:j]\n        # Copy a chunk of mom's genes.\n        child[i:j] = sublist1\n        copied = set(sublist1)\n        non_copied = (e for e in sublist2 if e not in sublist1)\n\n        # Find a place for each element of dad's gene that won't clobber mom's.\n        for elem in non_copied:\n            # Get the index of the element in the dad array.\n            idx = dad.index(elem)\n            # Find a spot that won't be taken.\n            while mom[idx] in copied:\n                idx = dad.index(mom[idx])\n            # Copy the element into the child.\n            child[idx] = elem\n            copied.add(elem)\n\n        # Add the rest of dad's genes.\n        for i in range(len(mom)):\n            if dad[i] not in copied:\n                child[i] = dad[i]\n                copied.add(dad[i])\n        return child\n\\end{minted}\n\n\\subsubsection{Order Crossover (OX)}\nExplanation, implementation, and analysis left as an exercise to the reader.\n\\subsubsection{Maximal Preservative Crossover (MPX)}\n\\subsubsection{Cycle Crossover (CX)}\n\\subsubsection{Position Base Crossover (PBX)}\n\\subsubsection{Heuristic Crossover (HX)}\n\\subsubsection{Edge Recombination Crossover (ERX)}\n\n\\subsubsection{Mutation and Recombination with the Stack Encoding}\nGiven a genome encoded via the stack encoding, we can decode the corresponding city ordering with\n\\begin{minted}{python}\n    def decode(n, genome):\n        \"\"\"Decode a given stack-encoded genome.\n\n        :param n: The number of city locations.\n        :param genome: The genome to decode into a phenome.\n        :returns: The indices for a valid tour path.\n        \"\"\"\n        cities = list(range(n))\n        phenome = []\n        for allele in genome:\n            idx = allele % len(cities)\n            phenome.append(cities[idx])\n            cities.pop(idx)\n        return phenome\n\\end{minted}\nNow the traditional point mutation and splicing recombination will result in valid paths.\n\n\\begin{minted}{python}\n    def stackx(mom, dad):\n        \"\"\"Recombination with stack encoding.\"\"\"\n        return mom[:len(mom) // 2] + dad[len(dad) // 2:]\n\\end{minted}\n\n\\begin{minted}{python}\n    def recombine(mom, dad, encoding='stack'):\n        methods = {\n            'path': pmx,\n            'stack': stackx,\n        }\n        return methods[encoding](mom, dad)\n\\end{minted}\n\nSince I'm implementing this problem using plain Python lists, almost everything from\n\\autoref{prob:2} needs to be redefined.\n\n\\begin{minted}{python}\n    def generate_cities(n, scale=100):\n        return np.random.rand(n, 2) * scale\n\n    def generate_population(sities, size):\n        n = len(cities)\n        population = [0] * size\n        for i in range(size):\n            individual = list(range(n))\n            random.shuffle(individual)\n            population[i] = individual\n        return population\n\\end{minted}\n\nThe fitness function needs to be aware of the solution encoding.\n\n\\begin{minted}{python}\n    def fitness(cities, path, encoding='path'):\n        \"\"\"Evaluate the fitness of the given path.\n\n        Compute the Euclidean distance between every pair of cities in the path\n        and add them together.\n\n        :param cities: The array of cities through which to compute a path.\n        :param path: The path through the given cities to compute the fitness for.\n        :param encoding: One of 'path' or 'stack'.\n        :returns: The fitness of the individual.\n        \"\"\"\n        if encoding == 'path':\n            individual = cities[path]\n        elif encoding == 'stack':\n            individual = cities[decode(path)]\n        else:\n            raise ValueError('invalid encoding')\n        return 1 / sum(np.linalg.norm(c1 - c2) for c1, c2 in pairwise(individual))\n\\end{minted}\n\nI experimented with different mutations, but with the stack encoding a simple random swap (as\nopposed to an inversion) seemed to work best.\n\n\\begin{minted}{python}\n    def mutate(path):\n        i = np.random.randint(0, len(path) - 1)\n        j = np.random.randint(i, len(path))\n        x = path.copy()\n        # Swap two random elements.\n        x[i], x[j] = x[j], x[i]\n\n        return x\n\\end{minted}\n\nThen the selection operators need some TLC to work with the new encoding.\n\n\\begin{minted}{python}\n    def deterministic_selection(population, size, func, cities, encoding='stack'):\n        \"\"\"Deterministically select the most fit from the given population.\n\n        Use the given fitness function to rank the population, then pick\n        the next `size` of the population to move on. This assumes that,\n        for a problem without recombination, the mutated individuals have\n        been mixed in with the original population.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :returns: The culled population, sorted upwards in increasing fitness.\n        \"\"\"\n        population.sort(key=lambda p: func(cities, p, encoding))\n        euthanize = len(population) - size\n        return population[euthanize:]\n\\end{minted}\n\n\\begin{minted}{python}\n    def stochastic_selection(population, size, func, cities, encoding='stack'):\n        \"\"\"Randomly select the most fit from the given population.\n\n        Select without replacement an individual with probability\n        proportional to its fitness.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :returns: The culled population, unsorted.\n        \"\"\"\n        fitnesses = np.array([func(cities, p, encoding) for p in population])\n        probabilities = fitnesses / np.sum(fitnesses)\n        survivors = np.random.choice(len(population), size, replace=False, p=probabilities)\n        return [population[i] for i in survivors]\n\\end{minted}\n\n\\begin{minted}{python}\n    def select(population, size, func, cities, method='deterministic', encoding='stack'):\n        \"\"\"Select the `size` most fit from the given population.\n\n        :param population: The population to cull.\n        :param size: The desired size of the population.\n        :param func: The fitness function to rank the population by.\n        :param cities: The array of city locations.\n        :param method: One of 'deterministic' or 'stochastic'.\n        :param encoding: One of 'path' or 'stack'\n        :returns: The culled population, in arbitrary order.\n        \"\"\"\n        methods = {\n            'stochastic': stochastic_selection,\n            'deterministic': deterministic_selection,\n        }\n        return methods[method](population, size, func, cities, encoding)\n\\end{minted}\n\n\\subsubsection{The Evolutionary Algorithm}\nThe algorithm for this problem is not much different than that for \\autoref{prob:2}. The biggest\ndifference is the recombination.\n\n\\begin{minted}{python}\n    def ea(cities, size, func, iters, selection='deterministic', encoding='stack'):\n        \"\"\"Run the evolutionary algorithm to solve the TSP.\n\n        :param cities: The array of city locations.\n        :param size: The population size to use.\n        :param func: The fitness function to use.\n        :param iters: The number of generations to run.\n        :param selection: One of 'deterministic' or 'stochastic'.\n        :param encoding: One of 'path' or 'stack'. Determines recombination method.\n        \"\"\"\n        n = len(cities)\n        population = generate_population(cities, size)\n        best_fitnesses = np.zeros(iters)\n        best_individuals = np.zeros((iters, n), dtype=int)\n        for i in range(iters):\n            population.sort(key=lambda p: func(cities, p, encoding))\n            population = population[n // 3:]\n            random.shuffle(population)\n\n            children = [recombine(mom, dad, encoding) for mom, dad in pairwise(population)]\n            mutations = [mutate(c) for c in population]\n            combined = population + children + mutations\n            population = select(combined, size, func, cities, method=selection, encoding=encoding)\n\n            fitnesses = np.array([func(cities, p, encoding) for p in population])\n            best = fitnesses.argmax()\n            best_fitnesses[i] = fitnesses[best]\n            best_individuals[i] = decode(population[best]) if encoding == 'stack' else population[best]\n        return best_fitnesses, best_individuals\n\\end{minted}\n\nNotice that I am sorting the population by their fitness, and culling the bottom third before\nshuffling and recombining pairwise. This is one of the simple changes I made to get better results.\n\n\\subsection{Results}\nThe most surprising and discouraging\\footnote{Like seriously; I didn't even want to turn the rest\n    of this in\\dots} result was that I found my PMX recombination implementation\nbuggy. On occasion, it results in a child with a duplicated city, but only ever on the second\niteration of the evolutionary algorithm. This is frustrating, because I spent an inordinate amount\nof time attempting to, first understand the operator, second draw the nice pictures like\n\\autoref{fig:prob3:pmx-step-3}, and third debug my implementation. This is particularly\ndisappointing because I wanted very badly to compare the ordered-path based recombination operators\nto that of the simple splicing on the stack encoding.\n\nSo unfortunately I was only able to compare the results of the stochastic and deterministic\nselection operators with only the stack encoding. As with \\autoref{prob:2}, I first generated an\narray of cities, shown in \\autoref{fig:prob3:city-locations}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics{prob3/figures/prob3-city-locations.pdf}\n    \\caption{The city locations}\\label{fig:prob3:city-locations}\n\\end{figure}\n\nBoth of the selection operators gave wildly varying results. However, the stochastic operator\nconsistently beat the deterministic one, even if only by a tiny amount. Unfortunately, as\n\\autoref{fig:prob3:deterministic-fitness} shows, the fitness of the best individual caps out\nrelatively quickly, indicating that it is a locally optimal solution. This is unfortunate, because\nthe mutation operator does not introduce enough variation to push the population away from the\nfound solution.\n\nI experimented with other mutation operators, and surprisingly the swap mutation worked the best.\nWith the stack encoding, I lack the intuitive understanding to understand what impact swapping two\nelements in the genome has on the actual ordering of the cities.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob3/figures/prob3-fitness-deterministic-stack.pdf}\n        \\caption{The best individual's fitness over time}\\label{fig:prob3:deterministic-fitness}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob3/figures/prob3-best-deterministic-stack.pdf}\n        \\caption{The overall best individual}\\label{fig:prob3:deterministic-best}\n    \\end{subfigure}\n    \\caption{Results using deterministic selection}\\label{fig:prob3:deterministic-results}\n\\end{figure}\n\nNote also, from \\autoref{fig:prob3:deterministic-best} that the best solution found is nowhere near\nas good as \\textit{any} of the solutions given in \\autoref{prob:2}. (I think) Even manual\nimprovement of the solution would not beat those solutions.\n\nI expected the stochastic selection operator to fail like it did in \\autoref{prob:2}, but it\nsurprised me. Compare the population's best individual's fitness from\n\\autoref{fig:prob2:stochastic-fitness} to that shown in \\autoref{fig:prob3:stochastic-fitness}. In\n\\autoref{fig:prob3:stochastic-fitness}, the fitness shows a steady climb, with several small peaks.\nIn \\autoref{fig:prob2:stochastic-fitness}, the fitness shows no observable trend.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob3/figures/prob3-fitness-stochastic-stack.pdf}\n        \\caption{The best individual's fitness over time}\\label{fig:prob3:stochastic-fitness}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{prob3/figures/prob3-best-stochastic-stack.pdf}\n        \\caption{The overall best individual}\\label{fig:prob3:stochastic-best}\n    \\end{subfigure}\n    \\caption{Results using stochastic selection}\\label{fig:prob3:stochastic-results}\n\\end{figure}\n\nHowever, the best individual found, shown in \\autoref{fig:prob3:stochastic-best}, bears no visual\nimprovement on that of the deterministic selection operator.\n\nHad I more time, I would be \\textit{very} interested to see how the recombination operators\nfrom~\\cite{tsp_ea} perform, especially the PMX crossover, which~\\cite{tsp_ea} claims is the most\ncommon operator for path-based problems.\n\n\\appendix\\appendixpage{}\\addappheadtotoc{}\n\\section{Inversion Proof}\\label{app:proof}\n\nSince the best proofs are constructive, I thought I would get meta and programmatically construct a\nproof that swaps, insertions, displacements, and shuffles can be implemented as a sequence of\ninversions.\n\nUnfortunately, I cannot claim to be the original author of such an excellent class of program. The\ninspiration came from a fellow sufferer of topology,\n\\href{https://www.reddit.com/user/kwprules}{u/kwprules}, a year previous to my own suffering. The\nilluminated discussion on their proof technique may be found\n\\href{https://www.reddit.com/r/math/comments/7gqhlc/what\\_to\\_say\\_instead\\_of\\_trivially/}{here}.\n\n\\inputminted{python}{proof.py}\n\n\\bibliographystyle{ieeetr}\n\\bibliography{homework}{}\n\n\\end{document}\n", "meta": {"hexsha": "ba14e0ff78b0c3d1df4417fbe9a5e440438b9dd2", "size": 81593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework/hw1/hw1.tex", "max_stars_repo_name": "Notgnoshi/natural-computing", "max_stars_repo_head_hexsha": "af6e10aaa4efcc6787bd5f71fb43fb66e67154ce", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "Notgnoshi/natural-computing", "max_issues_repo_head_hexsha": "af6e10aaa4efcc6787bd5f71fb43fb66e67154ce", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "Notgnoshi/natural-computing", "max_forks_repo_head_hexsha": "af6e10aaa4efcc6787bd5f71fb43fb66e67154ce", "max_forks_repo_licenses": ["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.2728852839, "max_line_length": 140, "alphanum_fraction": 0.6626303727, "num_tokens": 19771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.6659980071722996}}
{"text": "% Author: Bhishan Poudel\n% Dates I worked:\n%  Nov 2, 2017\n%\n%\n%#*******************************************************\n%#=======================================================\n%# Chapter 2: Galaxy Fitting\n%#=======================================================\n%#*******************************************************\n%\n%\n\\section{Galaxy Fitting}\\label{sec:chap2}\nIn this section, we want to fit the bulge and disk component fitting to the base \ngalaxy images provided from HST survey. We use the software called \n\\textit{Galfit} \\footnote{https://users.obs.carnegiescience.edu/peng/work/galfit/galfit.html}\nto get the reasonable components of the base galaxy. Galfit is an image analysis\nalgorithm that can model profiles of any given astronomical objects in the given\nfits image of the data sample. For example, if an fits image contains a galaxy,\nwe can use galfit to fit the bulge and disk components to that galaxy.\n\nHere, for the bulge part of the galaxy, we use the de Vaucouleurs profile in \nGalfit.\nThe de Vaucouleurs profile describes how the surface brightness of a giant\nelliptical galaxy changes as a  function of the radius R from the center of the\ngalaxy.\n\nLet $R_e$ be the radius of an isophote containing the half of the total \nluminosity for a galaxy, then, for a de Voucouleurs profile, the surface \nbrightness enclosed by the radius $R$ in that galaxy is given by:\n\n\\begin{eqnarray}\\label{[eq:devauc]}\n    I(R) = I_e e^{-7.669 [ (R/R_e)^{1/4} -1]  }\n\\end{eqnarray}\n\nGalfit has this formula as a built-in feature to get the bulge component of the\ngalaxy.\n\nSimilarly, to fit the disk profile to a galaxy, we use the profile called \n\\textit{exponential disk profile} in Galfit. This exponential disk profile \nis a special case of Sersic profile. In the Sersic\nprofile, the total surface brightness enclosed by the radius R around the center\nof a galaxy is given by\n\n\\begin{eqnarray}\\label{[eq:sersic]}\n    ln \\ I(R) = ln \\ I_0 - k R^{1/n}\n\\end{eqnarray}\n\nwhere, $I_0$ is the central surface brightness at $R = 0$ and the parameter n is \ncalled \\textit{Sersic index} which determines the curviness of the Sersic profile.\n\nFor the most of the spiral galaxies and dwarf elliptical galaxies, the Sersic index\nis close to 1. This case when the Sersic index n is equal to 1 is called\nexponential disk profile.\nIn exponential disk profile, the surface brightness inside the radius R is given\nby\n\n\\begin{eqnarray}\\label{[eq:expdisk]}\n    ln \\ I(R) = ln \\ I_0 - k R\n\\end{eqnarray}\n\nIn this project we have 201 base galaxies obtained from the HST survey. As we \nknow that some of the galaxies have both bulge and disk components and some\ndo not have it. For the case, when the base galaxy has bulge-disk components,\nGalfit gives nice bulge and disk components, however, when the base galaxy itself\ndoes not have reasonable bulge-disk component, Galfit can not give bulge and disk\ncomponents of that galaxy. In that case either Galfit fails to give two \ncomponents or, gives bad parameter. We can see the whether the fitted parameters\nare good or bad in the log file created from the Galfit. If a parameter is \nenclosed by \\* then, we can not trust the fitting, and we treat like the given\ngalaxy does not have reasonable bulge-disk components.\n\nLet's say we get two successful bulge and disk components of\na base galaxy, then we choose devauc profile as the bulge and exponential profile\nas the disk image. On the other hand, if either the Galfit fails to produce\ntwo component fittings or gives non-reliable fitting parameters, then we make some \nassumptions how to choose bugle and disk components. \nIf the single component fitting of \\textit{devauc profile} gives the better fit \nparameters than single component fitting of \\textit{expdisk profile} ,\nwe choose the base galaxy as the bulge component and we\nchoose an empty image as the disk component. \nSimilarly, if the single component \\textit{expdisk profile} gives better fitting than \nsingle component \\textit{devauc} fitting, we choose the base galaxy as the disk component \nand we choose an empty image as the bulge component. We may notice that,\nwhile doing the galaxy fitting to our 201 base galaxies, we found that most the galaxies\ngave better fit for the \\textit{devauc profile} than the \\textit{expdisk profile}.\nAn example of input parameter file for \\textit{Galfit} is shown next page.\n\\newpage\n\n\\verbatiminput{sections/expdisk_devauc.sh}\n\n\nAnother point to note is that, to use the Galfit program, we need to use a PSF image\nto convolve the original galaxy with the given PSF. The PSF image is different for \ndifferent filter images of a given galaxy. That is, for F814W filter of a base\ngalaxy $galaxy\\_f814w0.fits$ we use the psf $psf\\_f814w.fits$ and for the galaxy\n$galaxy\\_f660w0.fits$ we use the psf $psf\\_f606w.fits$. For all the F814W filter\nimages we use the same $psf\\_f814w.fits$ and for all the F606W filter images we use\nthe same $psf\\_f066w.fits$.\n\nHere, in our project we use the F814W filter images taken from the HST ACS Wide Field Channel Camera.\nTo create the relevant PSF, we use an on-line tool called  \\textit{STScI TinyTim Web Application} \n\\footnote{http://www.stsci.edu/hst/observatory/focus/TinyTim}.\n\nThe TinyTim web application needs some parameters to create a psf.\nFor this project we chose the following parameters:\n\n\\begin{table}[!h]\n\\centering\n\\caption{Tiny Tim Parameters}\n\\label{tiny-tim}\n\\begin{tabular}{ll}\nCamera         & ACS - Wide Field Channel \\\\\nChip           & 1                        \\\\\nPixel Position & 301 301                  \\\\\nFilter         & F814w                    \\\\\nSpectrumtype   & Blackbody                \\\\\nSpectrumvalue  & 6000                     \\\\\nPSF diameter   & 5.0 arcsec               \\\\\nFocus          & 0.0                     \n\\end{tabular}\n\\end{table}\n\n", "meta": {"hexsha": "04e146da25772f5b929a236fc9a89e1320775d63", "size": 5809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Prospectus/prospectus/sections/chap2_galaxy_fitting.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/chap2_galaxy_fitting.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/chap2_galaxy_fitting.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": 46.8467741935, "max_line_length": 101, "alphanum_fraction": 0.7178516096, "num_tokens": 1499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6659163617611578}}
{"text": "\\section{\\texorpdfstring{Perfect security, secret sharing, symmetric ciphers}{Perfect security, secret sharing, symmetric ciphers}}\n\\vspace{5mm}\n\\large\n\n\\subsection{Perfect Security}\n%2nd lecture, but belongs to 3rd by topic\n\\begin{definition}\n\t\\textbf{One time pad (also known as Vernam's Cipher)} - is the only! cipher, we can prove secure.\n\n\tThe key $k \\in \\{ 0, 1 \\}^n $ is chosen uniformly at random. The message $x \\in \\{ 0, 1 \\}^n$.\n\n\tcipher text is defined as\n\t\\[ y = x \\oplus k \\iff y_i = x_i \\oplus k_i \\]\n\n\tDecryption, using the associativity of XOR.\n\t\\[ y \\oplus k = (x \\oplus k) \\oplus k = x \\oplus (k \\oplus k) = x \\]\n\tTherefore encryption function is the same as decryption.\n\n\tFrom the observation \\cref{random_bit}, XOR with random bits produces uniform random bit.\n\tOnly the size of the information could be deduced from the cipher text. Extremely strong result!\n\tNo matter how much computational power the attacker has, he cannot deduce plain text from cypher text.\n\n\tFor other ciphers we can only prove that brute force attack is extremely slow, or $P = NP$ should be true to break the cipher.\n\n\tSuch property is called \\textbf{Informational-theoretic security} or \\textbf{perfect security}.\n\n\\end{definition}\n\n\\begin{definition}\\label{gen_one_time_p}\n\t\\textbf{Generilized one-time pad}\n\n\tConsider some group additive G $(G, +, 0, -)$.\n\n\tWe pick some $k \\in G$ randomly, then\n\t\\[ E(x, k) = x + k, D(y, k) = y - k = y + (k)^{-1} \\]\n\n\tFor example we can choose $\\Z_t$.\n\\end{definition}\n\n\\begin{definition}\n\tA symmetric cipher is \\emph{perfectly secure} iff\n\t\\[ \\forall x \\forall y Pr_k[ E(x, k) = y ] = Pr_k[ D(y, k) = x ] = const \\]\n\n\tFor any plain text, all cipher texts should be equally likely.\n\\end{definition}\n\n\\begin{example}\n\tFor example, for generalized one time pad \\cref{gen_one_time_p}\n\t\\[ \\forall x \\forall y \\exists !k: x + k = y \\Rightarrow k = y + x^{-1} \\]\n\n\tTherefore the probability is $\\frac{1}{|G|}$. As a result, one time pad is perfectly secure.\n\\end{example}\n\n\\begin{properties}\nUsefulness of the OTP:\n\t\\begin{enumerate}\n\t\t\\item never use same key twice. Since xor of the cypher text is the same as xor of the plain text.\n\t\t\\[ x_1 \\oplus k = y_1 \\land x_2 \\oplus k = y_2 \\Rightarrow y_1 \\oplus y_2 = x_1 \\oplus k \\oplus x_2 \\oplus k = x_2 \\oplus x_1 \\]\n\t\t\\item Codebook - a long list of generated Keys.\n\t\t\tIt has already happen during WW2, soviet agents ran out of keys in codebook and started to used same keys from the beginning.\n\t\t\tNot only were Americans able to read new messages, they have also decoded old ones.\n\t\t\\item replace randomness by pseudorandomness. A key is produced by PRNG (pseudo random number generator) which is parametrized by another key and ideally by nonce (initialization vector).\n\t\t\\item if attacker changes specific bit of the cipher text same plain text bit is changed. Since XOR is done bit by bit.\n\t\\end{enumerate}\n\\end{properties}\n\n\\begin{theorem}[Perfect cipher]\n\tIf \\# of keys $<$ \\# of messages $\\Rightarrow$ the cipher is not perfectly secure.\n\\end{theorem}\n\\begin{proof}\n\tLet's take some cipher text $y$ and get all plain text that a mapped by the inverse of the encryption function to the some $T \\subset $ Plain Texts. Since \\# of keys $<$ \\# of messages $\\Rightarrow$ some of the keys $\\notin T$.\n\tTherefore\n\t\\[ Pr_k[x \\notin T \\land D(y, k) = x] = 0, Pr_k[x \\in T \\land D(y, k) = x] > 0 \\]\n\tAnd the distribution of keys are not uniform. Cipher is not perfectly secure by the definition.\n\\end{proof}\n\n\\begin{note}\n\tPerfect security is also called \\textbf{Shannon security}. He is the father of the information theory and cryptography.\n\\end{note}\n\n\\subsection{Secret Sharing}\n\nAssume we have a secret information. We want to break secret into shared. The whole secret can be restored only having all the pieces.\nWe can use the OTP:\n\n$S_1, ..., S_{k-1}$ are random numbers. $S_k = x \\oplus S_1 \\oplus ... \\oplus S_{k-1}$.\nShareholders can decode x by xoring all $S_i$. Otherwise they will get random numbers.\n\n\\begin{definition}\n\t$(k, l)$ - threshold scheme. Split secret $x$ into $k$ shares $S_1, ..., S_k$.\n\tHaving any $l$ shared agents can decode $x$. However $X$ cannot be decoded with $< l$ \\# of shares. No info should be given.\n\\end{definition}\n\n\\begin{example}\n\t$(k, 2)$ scheme. Let F be finite field, the secret is a function $f = ax + b$ s.t.:\n\t\\[ f(0) = x, f(1) \\in_R F \\]\n\n\tGeometrically, we have $x$ as the point with coordinates $(0, t)$ for some $t$.\n\tAll $S_i$ for a straight line. As line can be deduced by any 2 points, 2 agents can decode $x$ using their points $S_i$.\n\n\tDistribution of the secrets $x$ is uniform $\\Rightarrow$ perfectly secure.\n\\end{example}\n\nLet's consider polynomials over field F.\nAccording to results from Algebra, a polynomial of degree $d$ has at most $d$ roots.\n\nGraph of the polynomial is a set of values for every point $\\in F$.\nPolynomials with the same graph share the roots $\\Rightarrow$ should be equal.\n\n\\begin{theorem}[Lagrange interpolation]\n\tFor every $x_1, ..., x_d, x_i \\neq x_j, i \\ne j, P(i) = 0$ distinct roots of P and $y_1, ..., y_d$\n\t\\[ \\exists! P, deg(P) < d: \\forall i\\ P(x_i) = y_i \\]\n\\end{theorem}\n\\begin{proof}\n\tLet $ \\overline{x} = (x_1, ..., x_d) \\in F^d$ be a vector of coefficients of polynomial P, X is a set of all such vectors. $|X| = |F|^d$.\n\n\tLet Y be a set of all choices of $y_i$, graphs of the polynomials.\n\n\tFinally, let $f:X \\to Y$ be a map from polynomials to graphs of polynomials. Which evaluates polynomial at d points.\n\n\tSince polynomials with the same graph are equal, $f$ is injective. $|X| = |Y| \\Rightarrow f$ is bijection.\n\\end{proof}\n\n\\begin{consequence}\n\tScheme based on graphs of the polynomials is perfectly secure, since according to the Lagrange theorem we have bijection between them $\\Rightarrow$ uniform distribution.\n\\end{consequence}\n\n\\begin{example}\n\t$(k, l)$ scheme. Instead of lines we pick some polynomial P, $deg(P) = d$. Then we randomly pick $k$ values of the P.\n\tHaving exactly $k$ shared agents can obtain P. Otherwise, all $X = P(0)$ are uniformly distributed.\n\\end{example}\n", "meta": {"hexsha": "f364062f23023c8ff33f7a3553869471b59da557", "size": 6068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/prednasky/03_prednaska.tex", "max_stars_repo_name": "karlov/NDMI100", "max_stars_repo_head_hexsha": "8a2c78790212b79c55083663ef0aaf27ef54d596", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/prednasky/03_prednaska.tex", "max_issues_repo_name": "karlov/NDMI100", "max_issues_repo_head_hexsha": "8a2c78790212b79c55083663ef0aaf27ef54d596", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/prednasky/03_prednaska.tex", "max_forks_repo_name": "karlov/NDMI100", "max_forks_repo_head_hexsha": "8a2c78790212b79c55083663ef0aaf27ef54d596", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.9696969697, "max_line_length": 228, "alphanum_fraction": 0.7092946605, "num_tokens": 1794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6659163599874732}}
{"text": "\\chapter{Inference for Statistical Experiments}\\label{S:StatExps}\n\\section{Introduction}\\label{S:ExpsIntro}\nWe formalize the notion of a staistical experiment.  Let us first motivate the need for a statistical experiment.  Recall that statistical inference or learning is the process of using observations or data to infer the distribution that generated it.  A generic question is:\n\\[\n\\text{Given realizations from $X_1, X_2, \\ldots, X_n \\sim$ some unknown DF $F$, how do we infer $F$} ?\n\\]\nHowever, to make this question tractable or even sensible it is best to restrict ourselves to a particular  class or family of DFs that may be assumed to contain the unknown DF $F$.\n\n\\begin{definition}[Experiment]\nA statistical experiment $\\EE{E}$ is a set of probability distributions (DFs, PDFs or PMFs) \n$\\Pz := \\{\\P_{\\theta} : \\theta \\in \\BB{\\Theta} \\}$ associated with a RV $X$ and indexed by the set $\\BB{\\Theta}$.  \nWe refer to $\\BB{\\Theta}$ as the parameter space or the index set and $d:\\BB{\\Theta} \\rightarrow \\Pz$ that associates to each $\\theta \\in \\BB{\\Theta}$ a probability $\\P_{\\theta} \\in \\Pz$ as the index map:\n\\[ \\BB{\\Theta} \\ni \\theta \\mapsto \\P_{\\theta} \\in \\Pz \\enspace .\\]\n\\end{definition}\n\n\\section{Some Common Experiments}\nNext, let's formally consider some experiments we have already encountered.\n\\begin{Exp}[The Fundamental Experiment]\\label{Exp:Uniform01}\nThe `uniformly pick a number in the interval $[0,1]$' experiment is the following singleton family of DFs  :\n\\[\n\\Pz = \\{ \\,  F(x) = x \\BB{1}_{[0,1]}(x)  \\, \\} \n\\]\nwhere, the only distribution $F(x)$ in the family $\\Pz$ is a re-expression of~\\eqref{E:Uniform01DF} using the indicator function $\\BB{1}_{[0,1]}(x)$.  The parameter space of the fundamental experiment is a singleton whose DF is its own inverse, ie.~$F(x) = F^{[-1]}(x)$. \nRecall from Exercise~\\ref{underMPSA} that this is equivalent to infinitely many independent and identical $\\bernoulli(1/2)$ trials, i.e., independently tossing a fair coint infinitely many times.\n%The two dimensional parameter space or index set for this experiment is $\\BB{\\Theta} = \\{ -\\infty < a < b < \\infty \\} = \\{ (a,b) \\in \\Rz \\times \\Rz :  a < b \\}$, a half-plane.\n\\end{Exp}\n\n\\begin{Exp}[Bernoulli]\\label{Exp:Bernoulli}\nThe `toss 1 times' experiment is the following family of densities (PMFs) :\n\\[\n\\Pz = \\{ \\,  f(x; \\theta) :  \\theta \\in [0,1] \\, \\} \n\\]\nwhere, $f(x; \\theta)$ is given in~\\eqref{E:Bernoullipdf}.  The one dimensional parameter space or index set for this experiment is  $\\BB{\\Theta} = [0,1] \\subset \\Rz$.\n\\end{Exp}\n\n\\begin{Exp}[Point~Mass]\\label{Exp:PointMass}\nThe `deterministically choose a specific real number' experiment is the following family of DFs :\n\\[\n\\Pz = \\{ \\,  F(x; a) :  a \\in \\Rz \\, \\} \n\\]\nwhere, $F(x; a)$ is given in~\\eqref{E:PointMasscdf}.  The one dimensional parameter space or index set for this experiment is $\\BB{\\Theta} = \\Rz$, the entire real line.\n\\end{Exp}\nNote that we can use the PDF's or the DF's to specify the family $\\Pz$ of an experiment.  When an experiment can be parametrized by finitely many parameters it is said to a {\\bf parametric} experiment.  \\hyperref[Exp:Bernoulli]{Experiment~\\ref*{Exp:Bernoulli}} involving discrete RVs as well as \\hyperref[Exp:PointMass]{Experiment \\ref*{Exp:PointMass}} are {\\bf parametric} since they both have only one parameter (the parameter space is one dimensional for Experiments \\ref*{Exp:Bernoulli} and \\ref*{Exp:PointMass}).   The \\hyperref[Exp:Uniform01]{Fundamental Experiment \\ref*{Exp:Uniform01}} involving the continuous RV of \\hyperref[M:Uniform01]{Model \\ref*{M:Uniform01}} is also parametric since its parameter space, being a point, is zero-dimensional.  The next example is also parametric and involves $(k-1)$-dimensional families of discrete RVs.\n\n\\begin{Exp}[{de~Moivre[k]}]\\label{Exp:GenDiscrete}\nThe `pick a number from the set $[k] := \\{1,2,\\ldots,k\\}$ somehow' experiment is the following family of densities (PMFs) :\n\\[\n\\Pz = \\{ \\,  f(x; \\theta_1,\\theta_2,\\ldots,\\theta_k) :   (\\theta_1,\\theta_2,\\ldots,\\theta_k) \\in \\bigtriangleup_k \\, \\} \n\\]\nwhere, $f(x; \\theta_1,\\theta_2,\\ldots,\\theta_k)$ is any PMF such that \n\\[\nf(x; \\theta_1,\\theta_2,\\ldots,\\theta_k) = \\theta_x, \\qquad x \\in \\{1,2,\\ldots,k\\} \\ .\n\\]\nThe $k-1$ dimensional parameter space $\\BB{\\Theta}$ is the $k$-Simplex $\\bigtriangleup_k$.  This as an `exhaustive' experiment since all possible densities over the finite set $[k] := \\{1,2,\\ldots,k\\}$ are being considered that can be thought of as ``the outcome of rolling a convex polyhedral die with $k$ faces and an arbirtary center of mass specified by the $\\theta_i$'s.''\n\\begin{figure}\n\\caption{Geometry of the $\\BB{\\Theta}$'s for $\\demoivre[k]$ Experiments with $k \\in \\{1, 2, 3, 4\\}$.}\n\\vspace{5cm}\n\\end{figure}\n\\end{Exp}\nAn experiment with infinite dimensional parameter space $\\BB{\\Theta}$ is said to be {\\bf nonparametric} .  Next we consider two nonparametric experiments.\n\\begin{Exp}[All DFs]\\label{Exp:AllDFs}\nThe `pick a number from the Real line in an arbitrary way' experiment is the following family of distribution functions (DFs) :\n\\[\n\\Pz = \\{ \\,  F(x; F) :  F~is~a~DF \\, \\} = \\BB{\\Theta} \n\\]\nwhere, the DF $F(x; F)$ is indexed or parameterized by itself. Thus, the parameter space \n\\[\n\\BB{\\Theta}=\\Pz=\\{ \\text{all DFs}\\}\n\\]\nis the infinite dimensional space of {\\bf All DFs} ''.\n\\end{Exp}\nNext we consider a {\\bf nonparametric} experiment involving continuous RVs.\n\\begin{Exp}[Sobolev Densities]\\label{Exp:Sob}\nThe `pick a number from the Real line in some reasonable way' experiment is the following family of densities (pdfs) :\n\\[\n\\Pz = \\left\\{ \\,  f(x; f) :  \\int(f''(x))^2 < \\infty \\, \\right\\} = \\BB{\\Theta} \n\\]\nwhere, the density $f(x; f)$ is indexed by itself.  Thus, the parameter space $\\BB{\\Theta}=\\Pz$ is the infinite dimensional {\\bf Sobolev space} of ``not too wiggly functions''.\n\\end{Exp}\n\n\\section{Typical Decision Problems with Experiments}\nSome of the concrete problems involving experiments include:\n\\begin{itemize}\n\\item {\\bf Simulation:} Often it is necessary to simulate a RV with some specific distribution to gain insight into its features or simulate whole systems such as the air-traffic queues at `London Heathrow' to make better management decisions.\n\\item {\\bf Estimation:} \n\\begin{enumerate}\n\\item {\\bf Parametric Estimation:} Using samples from some unknown DF $F$ parameterized by some unknown $\\theta$, we can estimate $\\theta$ from a statistic $T_n$ called the estimator of $\\theta$ using one of several methods (maximum likelihood, moment estimation, or parametric bootstrap).\n\\item {\\bf Nonparametric Estimation of the DF:}  Based on $n$ IID observations from an unknown DF $F$, we can estimate it under the general assumption that $F \\in \\{ \\text{all DFs} \\}$.\n\\item {\\bf Confidence Sets:}  We can obtain a $1-\\alpha$ confidence set for the point estimates, of the unknown parameter $\\theta \\in \\BB{\\Theta}$ or the unknown  DF $F \\in \\{ \\text{all DFs} \\}$\n\\end{enumerate}\n\\item {\\bf Hypothesis Testing:}  Based on observations from some DF $F$ that is hypothesized to belong to a subset $\\BB{\\Theta}_0$ of $\\BB{\\Theta}$ called the space of null hypotheses, we will learn to test (attempt to reject) the falsifiable null hypothesis that $F \\in \\BB{\\Theta}_0 \\subset \\BB{\\Theta}$.\n\\item $\\ldots $ \n\\end{itemize}\n\n\n\\section{Decision Problems and Procedures for Actions}\\label{S:Decisions}\n\nWrite down the Table from lectures 1 \\& 2 giving examples of decision problems, procedures and action spaces for typical estimation, hypothesis testing and prediction problems with associated principles (Maximum Likelihood, Empirical Risk Minimisation where risk is expectation of specific loss functions, etc.) and algorithms (including optimisation (Stochastic)Newton/gradient-descent, etc.).\n\n\\vspace{10cm}~\\\\\n\n\n", "meta": {"hexsha": "e9c8d1858d506785baa5612b518f8f0ab27ffbe5", "size": 7799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/Experiments.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/Experiments.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/Experiments.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": 75.7184466019, "max_line_length": 851, "alphanum_fraction": 0.7204769842, "num_tokens": 2294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384735, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6659163439229798}}
{"text": "\\section{Algorithm Analysis}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Algorithm analysis}\n  \\begin{itemize}\n\t\\item Given a problem $P$\n\t\\item Design algorithms $A, A', \\ldots$\n\t\\item Input space $\\mathcal{X}_{n}$: inputs of size $n$\n  \\end{itemize}\n\n  \\pause\n  \\[\n\tT_{A}(n) \\triangleq \\max_{X \\in \\mathcal{X}_{n}} T_A(X)\n  \\]\n\n  \\pause\n  \\[\n\tT_{P}(n) \\triangleq \\min_{A \\text{ solves } P}T_{A}(n) \\pause = \\min_{A \\text{ solves } P} \\max_{X \\in \\mathcal{X}_{n}} T_A(X)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Algorithm analysis}\n  \\begin{columns}\n\t\\column{0.40\\textwidth}\n\t  Sorting:\n\t  \\begin{align*}\n\t\t\\onslide<2->{& n! \\\\}\n\t\t\\onslide<3->{& \\implies n^2 \\\\}\n\t\t\\onslide<4->{& \\implies n \\log n \\\\}\n\t\t\\onslide<6->{n \\log n & \\Longleftarrow \\\\}\n\t\t\\onslide<5->{& n \\\\}\n\t  \\end{align*}\n\t\\column{0.40\\textwidth}\n\t  Selection (median):\n\t  \\begin{align*}\n\t\t\\onslide<7->{& n^2 \\\\}\n\t\t\\onslide<8->{& \\implies n \\log n \\\\}\n\t\t\\onslide<9->{& \\implies 16n \\\\}\n\t\t\\onslide<10->{& \\implies 2.95n \\\\}\n\t\t\\onslide<13->{2n & \\Longleftarrow \\\\}\n\t\t\\onslide<12->{\\frac{3n}{2} - \\frac{3}{2} \\log n & \\Longleftarrow \\\\}\n\t\t\\onslide<11->{& n \\\\}\n\t  \\end{align*}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "2548cb4c8dea8ce49a52001798a0cb9398fc1186", "size": 1275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-algorithm-analysis-20170412/sections/algorithm-analysis.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/algorithm-analysis.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/algorithm-analysis.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.0, "max_line_length": 127, "alphanum_fraction": 0.5137254902, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516187, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6659163436578999}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 2.20  Binomial Coefficients\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology,\n  \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nCompute the binomial coefficient $\\displaystyle \\binom{n}{k} =\n\\frac{n!}{(n-k)!\\, k!}$ which gives the number of ways one can select\n$k$ items from a set containing $n$ items.  Binomial coefficients also\nappear in a number of other contexts.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\\begin{description}\n\\item[REAL] \\ {\\bf SBINOM, ANS}\n\\item[INTEGER] \\ {\\bf N, K}\n\\end{description}\nAssign values to N and K.\n$\n\\fbox{\\bf ANS = SBINOM(N, K)}\n$\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[N, K] \\ [in] The input integers $n$ and $k$ as described in\n\"Purpose\" above.  One must have $0 \\leq \\text{K} \\leq \\text{N}.$\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double-precision usage change the name SBINOM to DBINOM, and\nchange the REAL declaration to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nThe program DRSBINOM compares the true values with the results of\ncomputing the binomial coefficients for two large values of N where SBINOM\nuses a different algorithm internally.  It then finds the first case where\nresults using the Pascal triangle give different results from SBINOM (the\ntrue value for the case printed is 67863915, which is slightly closer to\nthe value given by SBINOM).  If one is computing binomial coefficients for\nstrictly increasing values of N, one may want to use the Pascal triangle\ncode in DRSBINOM instead of SBINOM for computing the binomial\ncoefficients.\n\n\\subsection{Functional Description}\n\nFor N $\\leq$ 150, the routine maintains and uses a table of saved\nfactors of factorials, $\\phi_j$.  If the input N is larger than any\nseen so far, this table is extended.  When there is no problem with\noverflow, $\\phi_j = j \\phi_{j-1}$.  To deal with overflow a second\ntable $i_\\nu$ is maintained.  Initially $\\nu=0$.  When adding entry\n$j$ to the table would cause an overflow, $\\nu$ is incremented,\n$i_\\nu$ is set to $j-1$, and $\\phi_j$ to $j$.\n\nTo compute the binomial coefficients, the code uses\n\\begin{equation*}\n\\binom{n}{k} = \\frac{n!}{(n-k)!\\,k!}, \\quad\nj!  = \\Big (\\prod_{\\ell = 1}^{\\nu-1} \\phi(i_{\\ell}) \\Big ) \\phi (j),\n\\end{equation*}\nwith $\\nu $ such that $ i_{\\nu-1} < j \\leq i_\\nu$.  When a factorial is so\nlarge it is represented by more than one piece, the pieces are combined in\nsuch a way as to avoid overflow.  Finally, for large values, the result is\nrefined by setting the result equal to $p \\times \\lfloor r / p + .5\n\\rfloor $, where $r$ is the originally computed result, $p$ is either one\nprime or the product of two primes in the interval $\\big (\\max(n-k,\\ k),\\\nn \\big ]$ and $ \\lfloor \\cdot \\rfloor$ denotes the integer part.\n\nIn the case of IEEE single precision arithmetic, only one piece of the\nfactorial is needed for $\\text{N} \\leq 33$, and for IEEE double precision\n$150!$ does not overflow.  When only one piece is needed for the factorial\nand it is already computed, the binomial coefficient is computed with one\nmultiply, one divide, and a few tests.\n\n\nIf N $>$ 150, the log gamma function from Chapter~2.3 is used.  In this\ncase\n\\begin{equation*}\n\\binom{n}{k} = e^{\\log \\Gamma (n+1) - \\log \\Gamma (n-k+1) -\n\\log \\Gamma (k+1)}\n\\end{equation*}\nIt is very easy to shorten the code by replacing the call to the log\ngamma function for large N with an error message reporting too large an N.\nIt is only slightly more difficult to replace the code for keeping pieces\nof the factorial with code that calls log gamma whenever N!\\ would\noverflow.  This would lose some precision as illustrated by the difference\nin the errors for N = 150 and N = 151 in the results.\n\n\n\\subsection{Error Procedures and Restrictions}\n\nAn error exit is taken if the condition $0 \\leq \\text{K} \\leq \\text{N}$\nis not satisfied, or if the result would overflow.  Errors are\nprocessed using the routines in Chapter 19.2.  If one references one\nof these routines to change the error action, then instead of stopping on\nan error, the routine will return with a result of $-1$.\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} \\\\\nDBINOM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DBINOM, DERM1, DERV1, DLGAMA, DGAMMA, ERFIN, ERMSG, IERM1,\nIERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSBINOM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, IERM1, IERV1, SBINOM, SERM1, SERV1, SLGAMA,\nSGAMMA\\rule[-5pt]{0pt}{8pt}}\\\\ \\end{tabular}\n\nAlgorithm and code due to F. T. Krogh, JPL, December~1995.\n\n\n\\begcodenp\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSBINOM}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sbinom}}\n\n\\vspace{20pt}\\centerline{\\bf \\large ODSBINOM}\\vspace{0pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sbinom}}\n\\end{document}\n", "meta": {"hexsha": "0119a48a0adc6ebdd884ab6215828feab46cff2b", "size": 5141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch02-20.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-20.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-20.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.6541353383, "max_line_length": 74, "alphanum_fraction": 0.7385722622, "num_tokens": 1558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.66591634064069}}
{"text": "%!TEX root = ../main.tex\n%-------------------------------------------------------------------------------\n\\subsection{Calibration procedure}\n%-------------------------------------------------------------------------------\nEKW models are calibrated to data on observed individual decisions and experiences under the hypothesis that the individual behaves according to the model. The goal is to back out information on utility functions, preference parameters, and transition probabilities. This requires the full parameterization $\\theta$ of the model.\n\nEconomists have access to information for $i = 1, \\hdots, N$ individuals in each time period $t = 1, \\dots, T_i$. For every observation $(i, t)$ in the data, we observe the action $a_{it}$, some components $\\bar{u}_{it}$ of the utility, and a subset $\\bar{s}_{it}$ of the state $s_{it}$. Therefore, from an economist's point of view, we need to distinguish between two types of state variables $s_{it} = (\\bar{s}_{it}, \\epsilon_{it})$. At time $t$, the economist and individual both observe $\\bar{s}_{it}$ while $\\epsilon_{it}$ is only observed by the individual. In summary, the data $\\mathcal{D}$ has the following structure:\n%\n\\begin{align*}\n  \\mathcal{D} = \\{a_{it}, \\bar{s}_{it}, \\bar{u}_{it}: i = 1, \\hdots, N; t = 1, \\hdots, T_i\\},\n\\end{align*}\nwhere $T_i$ is the number of observations for which we observe individual $i$.\n\nNumerous calibration procedures for different settings exist \\citep{Davidson.2003, Gourieroux.1996}. We briefly outline likelihood-based and simulation-based calibration. Independent of the calibration criterion, it is necessary to solve for the optimal policy $\\pi^*$ at each candidate parameterization of the model.\n\nLikelihood-based calibration seeks to find the parameterization $\\hat{\\theta}$ that maximizes the likelihood function $\\mathcal{L}(\\theta\\mid\\mathcal{D})$, i.e. the probability of observing the given data as a function of $\\theta$. As we only observe a subset $\\bar{s}_t$ of the state, we can determine the probability $p_{it}(a_{it}, \\bar{u}_{it} \\mid \\bar{s}_{it}, \\theta)$ of individual $i$ at time $t$ in $\\bar{s}_{it}$ choosing $a_{it}$ and receiving $u_{it}$ given parametric assumptions about the distribution of $\\epsilon_{it}$. The objective function takes the following form:\n%\n\\begin{align*}\n  \\hat{\\theta} \\equiv \\argmax_{\\theta \\in \\Theta}  \\underbrace{\\prod^N_{i= 1} \\prod^{T_i}_{t= 1}\\, p_{it}(a_{it}, \\bar{u}_{it} \\mid \\bar{s}_{it}, \\theta)}_{\\mathcal{L}(\\theta\\mid\\mathcal{D})}.\n\\end{align*}\n\n\\noindent In simulation-based calibration, our goal is to find the parameterization $\\hat{\\theta}$ that yields a simulated data set from the model that closest resembles the observed data. More precisely, the goal is often to minimize the weighted squared distance between a set of moments $M_D$ computed on the observed data and the same set of moments computed on the simulated data $M_S(\\theta)$. The objective function takes the following form:\n%\n\\begin{align*}\n    \\hat{\\theta} \\equiv \\argmin_{\\theta \\in \\Theta} (M_D - M_S(\\theta))' W (M_D - M_S(\\theta)).\n\\end{align*}\n", "meta": {"hexsha": "57a7e50f04c296cfb7c1a74aa92c1f6408f0707c", "size": 3089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/s-setup-calibration.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-calibration.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-calibration.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": 114.4074074074, "max_line_length": 627, "alphanum_fraction": 0.6950469408, "num_tokens": 797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6658812588022851}}
{"text": "\\chapter{Trees}\n\\label{chapter:trees}\nLet us consider the following problem. Given a network of several computers,\nin this network if a computer $A$ receives some message from a computer $B$,\nit broadcasts it to all the connected computers except $B$.\nHowever, in such setting there is an issue known as broadcast radiation.\nAssume we have three computers $A$, $B$, and $C$ such that they form a cycle.\nIf $A$ sends something to $B$ and $C$ both of them send received information to\n$C$ and $B$, respectively; after that $B$ and $C$ send this information to $A$\nand $A$ start sending this information again, which leads to an infinite\ncycle.\\footnote{%\n  This problem is a simplified version of a problem that is solved by STP\n  protocols in the modern networks.\n}\n\nTherefore to avoid such problem we need to disable some connecion so that the\ngraph of this network does not have cycles.\nIn this chapter we are going to study properties of the graphs without cycles.\n\\begin{definition}\n  We say that a connected graph $G$ is a \\emph{tree} iff $G$ does not have cycles.\n\\end{definition}\n\n\\section{Minimally Connected Graphs}\nFirst we may make the following observation.\n\\begin{theorem}\n  Let $G = (V, E)$ be a connected graph. Then the following statements are\n  equivalent.\n  \\begin{itemize}\n    \\item $G$ is a tree.\n    \\item $G$ is minimally connected, that is, $G - e$ is not connected for any\n      $e \\in E$.\n  \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n  Assume that $G$ is minimally connected but $G$ has a cycle\n  $v_1$, \\dots, $v_k$. Consider $G' = G - (v_1, v_k)$, we claim that $G'$\n  is still connected. Indeed, let $x$ and $y$ be some vertices of $G'$.\n  Since $G$ is connected, there is a path $p$ from $x$ to $y$. If $p$ does not\n  contain the edge $(v_1, v_k)$, then $x$ and $y$ are connected in $G'$. If\n  $p$ contains $(v_1, v_k)$, then we replace this edge by the path $v_1$, \\dots,\n  $v_k$, so $x$ and $y$ are connected in $G'$. Therefore $G$ is not a minimally\n  connected graph, which is a contradiction.\n\n  Let us now assume that $G$ is not minimally connected, we wish to prove that\n  it implies that $G$ is not a tree. Since $G$ is not minimally connected, there\n  is an edge $(x, y) \\in E$ such that $G - e$ is connected. Since $G - (x, y)$\n  is connected, there is a path $x = v_1, \\dots, v_k = y$ in $G - (x, y)$.\n  Therefore $v_1, \\dots, v_k$ is a cycle in $G$, which is a contradiction.\n \\end{proof}\n\nTherefore in order to get a tree from a graph, we just need to delete edges\nin an arbitrary way until the moment when we cannot delete them anymore.\n\\begin{corollary}\n  For any connected graph $G = (V, E)$, there is a tree $T = (V, E')$ such\n  that $T$ is a subgraph of $G$. Such a tree is called a spanning tree of $G$.\n\\end{corollary}\n\nAnother question we may ask is how many edges we need to delete in this process.\nApparenly, the answer is always $m - n + 1$, where $m$ is the number of edges in\nthe initial graph and $n$ is the number of vertices.\n\\begin{theorem}\n\\label{theorem:tree-is-minimally-connected}\n  Let $G$ be a connected graph on $n$ vertices.\n  If $G$ is a tree, then it has $n - 1$ edges. Moreover, if $G$ has $n - 1$\n  edge, then it is a tree.\n\\end{theorem}\n\nBefore we prove the theorem, let us prove the following lemma.\n\\begin{lemma}\n  If a tree $T$ has at least $2$ vertices, then it has at least two\n  vertices whose degree is $1$.\n\\end{lemma}\n\\begin{proof}\n  Let us choose a vertex $v$ of $T$ such that its degree is not $1$ (if such a\n  vertex does not exist, then we found at least $2$ vertices whose degree is\n  $1$). Let us start walking from $v$ to its neighbour, then to a new neighbor\n  of this neighbor, and so on, never revisiting a vertex. As $T$ has finite\n  number of vertices, we will eventually have to stop at a vertex $u$. We claim\n  that the only reason for us to stop at $u$ could be that $u$ is of degree $1$.\n  Indeed, the only possible other reason would be that $u$ has neighbors other\n  than the neighbor $u'$ we reached $u$ from, but they have all been visited\n  already. However, that would mean that there are at least two paths from $v$\n  to $u$, and that cannot happen in a tree. So $u$ is of degree $1$. To get\n  another vertex of degree $1$, remember that $v$ is of degree more than $1$.\n  So take another neighbor of $v$, and repeat this argument. This will result in\n  another vertex $w$ of degree $1$, and $u \\neq w$ as that would again yield two\n  paths from $v$ to $u$.\n\\end{proof}\nThe vertices of a tree that have degree $1$ are called \\emph{leaves}.\n\n\\begin{proof}[Proof of Theorem~\\ref{theorem:tree-is-minimally-connected}]\n  We prove the statement using induction by $n$. If $n = 1$, the statement is\n  clearly true.\n  Assume that the statement is true for trees on $n$ vertices. Consider a tree\n  $T$ on $n + 1$ vertices. Consider a leaf $\\ell$ of $T$. Note that $T - \\ell$\n  is a tree as well, therefore by the induction hypothesis, it has $n - 2$\n  edges. Hence, $T$ has $n - 1$ edges.\n\n  Let us now prove that if a graph $G$ has $n - 1$ edges and is connected,\n  then $G$ is a tree. Assume that it is not a tree, we start deleting edges as\n  long as the graph is connected, we call the resulting graph $T$. Note that\n  $T$ is minimally connected, so $T$ is a tree. Note that $T$ has $n$ vertices.\n  Therefore, it has $n - 1$ eges, which implies that we removed $0$ edges and\n  $T = G$. As a result, $G$ is a tree.\n\\end{proof}\n\n\\begin{exercise}\n  A graph such that every connected component of this graph is a tree is called\n  a \\emph{forest}.\n  Show that a forest with $k$ connected components has $n - k$ edges.\n\\end{exercise}\n\n\\section{Minimum-weight Spanning Trees}\nIn the initial example about the network, we missed an important detail: not\nall the connections are equally fast. Let us label each connection\n(edge in our graph) with the weight (the number that represents how slow is this\nconnection). So now we need to choose a spanning tree of\nthe graph of the network so that it has the minimal possible sum of weights.\n\\begin{definition}\n  Let $G = (V, E)$ be a connected graph, and $w : E \\to \\R$ be weights of edges.\n  Then we say that a spanning tree $T = (V, E')$ of $G$ is a\n  \\emph{minimum-weight spanning tree} of $G$ if\n  $\\sum_{e \\in E'} w(e) \\le \\sum_{e \\in E''} w(e)$ for any spanning tree\n  $T' = (V, E'')$ of $G$.\n\n  The number $\\sum_{e \\in E'} w(e)$ is called the \\emph{weight} of $T$.\n\\end{definition}\n\nIt is obvious that such a tree exists. The question is\n``how to find efficiently the minimum-weight spanning tree''.\n\\begin{exercise}\n  Let $G = (V, E)$ be some graph and $w : E \\to \\R$ be a weight function such\n  that $w(e) = 1$. How to to find efficiently the minimum-weight spanning tree\n  of $G$?\n\\end{exercise}\n\n\nSurprisingly, one may find such a minimum-weight spanning tree using a simple\ngreedy algorithm (Algorithm~\\ref{algorithm:kruskal}).\n\\begin{algorithm}\n  \\begin{algorithmic}[1]\n    \\Function{MinimumSpanningTree}{$n$, $E$, $w$}\n      \\State Let $e_1$, \\dots, $e_m$ be the edges from $E$ sorted in the\n        ascending order with respect to $w$.\n      \\State $i \\gets 1$\n      \\State Set $T$ to be an empty graph on $[n]$.\n      \\label{line:kruskal-while}\n      \\While{$i \\le n$}\n        \\If{$T + e_i$ does not have cycles}\n          \\State $T \\gets T + e_i$\n        \\EndIf\n        \\State Increase $i$ by $1$.\n      \\EndWhile\n      \\State \\Return{$T$}\n    \\EndFunction\n  \\end{algorithmic}\n  \\caption{Kruskal's algorithm, the algorithm that returns a minimum-weight\n  spanning tree of the graph on $[n]$ with the set of edges $E$.}\n  \\label{algorithm:kruskal}\n\\end{algorithm}\n\n\\begin{theorem}\n\\label{theorem:kruskal}\n  If the graph $([n], E)$ is connected, then Algorithm~\\ref{algorithm:kruskal}\n  returns a minimum-weight spanning tree of the graph $([n], E)$.\n\\end{theorem}\n\nTo prove this statement we need a technical lemma.\n\\begin{lemma}\n  Let $F_1$ and $F_2$ be forests on the same vertex set $V$. If $F_1$ has less\n  edges than $F_2$, then $F_2$ has an edge $e$ not in $F_1$ so\n  that the graph $F_1 + e$ is still a forest.\n\\end{lemma}\n\\begin{proof}\n  Let $E_i$ be the set of edges of $F_i$.\n  Assume that there such edge does not exist; i.e., $F_1 + e$ has a cycle for\n  any edge $e \\in E_2 \\setminus E_1$.\n\n  Therefore any edge of $F_2$ is between two vertices in the same component of\n  $F_1$. Hence, $F_2$ has at least as many connected components as $F_1$.\n  Indeed, consider two connected components $U_1$ and $U_2$ of $F_1$ we claim\n  that they any $x \\in U_1$ and $y \\in U_2$ are not connected in $F_2$ since\n  there are no edges going outside of $U_1$ and $U_2$ in $F_2$.\n\n  However, $F_i$ has $n - |E_i|$ connected components, which contradicts to the\n  fact that $|E_1| < |E_2|$.\n\\end{proof}\n\n\\begin{proof}[Proof of Theorem~\\ref{theorem:kruskal}]\n  Let $T_1$, \\dots, $T_m$ be the states of $T$ after iterations of\n  line~\\ref{line:kruskal-while} of Algorithm~\\ref{algorithm:kruskal}.\n  Note that $T_i$ does not have cycles for $i \\in \\range{m}$. Therefore $T_i$ is a\n  forest for $i \\in \\range{m}$.\n\n  First we need to prove that Algorithm~\\ref{algorithm:kruskal} returns a\n  spanning tree; i.e. that $T_m$ is connected.\n  Assume the opposite. Consider two vertices $x, y \\in \\range{n}$ such that\n  they are not connected in $T$. Since $G = ([n], E)$ is connected there is a\n  path $x = v_1, \\dots, v_k = y$ in $G$. Consider the minimal $i \\in [k - 1]$\n  such that $(v_i, v_{i + 1})$ is not an edge of $T_m$. Let\n  $e_j = (v_i, v_{i + 1})$. It is easy to see that $T_m + (v_i, v_{i + 1})$ does\n  not have cycles so $T_{j - 1} + e_j$ does not have cycles as well and $T_j =\n  T_{j - 1} + e_j$ which implies that $T_m$ has the edge $(v_i, v_{i + 1})$\n  which is a contradiction.\n\n  Before we start the second part of the proof note that if $w(e) < w(e_i)$,\n  then $T_{i - 1} + e_i$ has a cycle.\n\n  Now we need to prove that $T_m$ is a minimum-weight spanning tree. Assume\n  that there is a spanning tree $H$ such that the weight of $H$ is less than\n  the weight of $T_m$. Consider the edges $t_1$, \\dots, $t_{n - 1}$ of $T_m$\n  and the edges $h_1$, \\dots, $h_{n - 1}$ of $H$ such that\n  $w(t_1) \\le w(t_2) \\le \\dots \\le w(t_{n - 1})$ and\n  $w(h_1) \\le w(h_2) \\le \\dots \\le w(h_{n - 1})$.\n  Let us consider the first step when $H$ is better than $T_m$; i.e., the\n  minimal $i$ so that $\\sum_{j = 1}^i w(h_j) < \\sum_{j = 1}^i w(t_j)$\n  (obviously $i > 1$).\n\n  It is easy to see that $h_i < t_i$. Let $e_j = t_i$ and\n  $H_i = H[h_1, \\dots, h_i]$. Since $H_i$ has more edges than $T_j$ there is an\n  edge $h_{i'}$ ($i' < i$) such that $T_{j - 1} + h_{i'}$ does not have cycles.\n  Wich is a contradiction since $h_{i'} < h_i < t_i$.\n\\end{proof}\n\n\n\\begin{chapterendexercises}\n  \\exercise[recommended] Let $G$ be a graph with $k$ connected components and\n    $n - k$ edges. Show that $G$ is a forest.\n  \\exercise Prove that if $G$ is a simple graph on $[n]$, then at least one of\n    $G$ and its complement is connected. Show an example when they are both\n    connected. The complement $\\bar{G}$ of $G$ has the same vertex set as $G$\n    and $(x, y)$ is an edge in $\\bar{G}$ if and only if it is not an edge in\n    $G$.\n  \\exercise[recommended] Let $H$ be a simple graph on $n$ vertices that has $m$\n    edges. Prove that $H$ contains at least $m - n - 1$ cycles.\n    \\begin{solution}\n      First of all, let us consider the case when $G$ is connected. We prove\n      this statement using induction by $d = m - n + 1$. Note that if $d = 0$,\n      then the statement is obviously true (since number of cycles should be at\n      least $0$).\n\n      Let us prove now the induction step: let $G$ be a graph having $m > n - 1$\n      edges. It is not a tree, hence there is a cycle. Let $e$ be any edge of this\n      cycle. Note that $G - e$ has $m - 1$ edges, hence, there are at least $m -\n      1 - n + 1$ cycles, additionally, note that number of cycles in $G$ is at\n      least number of cycles in $g - e$ plus one. As a result, there are at\n      least $m - 1 - n + 1$ cycles in $G$.\n\n      If $G$ is not connected, we denote connected component of $G$ by $G_1$,\n      \\dots, $G_\\ell$ with number of vertices $n_1$, \\dots, $n_\\ell$ and number\n      of edges $m_1$, \\dots, $m_\\ell$. We prove that there are \n      $\\sum_{i = 1}^\\ell m_i - n_i + 1 = m - n + \\ell \\ge m - n + 1$ cycles in\n      $G$.\n    \\end{solution}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "68f9912188e5105b021ac188348787eabb6294cc", "size": 12388, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_8/chapter_34_trees.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_8/chapter_34_trees.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_8/chapter_34_trees.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": 48.390625, "max_line_length": 82, "alphanum_fraction": 0.6702453988, "num_tokens": 3983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.6658812543289357}}
{"text": "\\subsection{End Behaviour and Comparative Growth Rates}\n\nLet us now look at the last two subsections and go deeper. In the last two\nsubsections we looked at horizontal and slant asymptotes. Both are special\ncases of the end behaviour of functions, and both concern situations where\nthe graph of a function approaches a straight line as $x\\to \\infty$\nor $-\\infty$. But not all functions have this kind of end behviour. For\nexample, $f(x)=x^2$ and $f(x)=x^3$ do not\napproach a straight line as $x\\to \\infty$ or $-\\infty$. The best\nwe can say with the notion of limit developed at this stage are that%\n\\begin{eqnarray*}\n\t\\lim_{x\\to \\infty}x^2 &=&\\infty\\text{, }\\lim_{x\\to -\\infty}x^2=\\infty, \\\\\n\t\\lim_{x\\to \\infty}x^3 &=&\\infty\\text{, }\\lim_{x\\to -\\infty}x^3=-\\infty.\n\\end{eqnarray*}%\nSimilarly, we can describe the end behaviour of transcendental functions\nsuch as $f(x)=e^x$ using limits, and in this case, the graph\napproaches a line as $x\\to -\\infty$ but not as $x\\to \\infty$.\n\\begin{equation*}\n\\lim_{x\\to -\\infty}e^x=0\\text{, }\\lim_{x\\to \\infty}e^x=\\infty.\n\\end{equation*}\n\nPeople have found it useful to make a finer distinction between these end\nbehaviours all thus far captured by the symbols $\\infty$ and $-\\infty$.\nSpecifically, we will see that the above functions have different growth\nrates at infinity. Some increases to infinty faster than others.\nSpecifically,\n\n\\begin{definition}{Comparative Growth Rates}{CompareGrowthRates}\nSuppose that $f$ and $g$ are two functions such that $\\lim\\limits_{x%\n\t\\to \\infty }f\\left( x\\right) =\\infty $ and $\\lim\\limits_{x%\n\t\\to \\infty }g\\left( x\\right) =\\infty .$ We say that $f\\left(\nx\\right) $ grows faster than $g\\left( x\\right) $ as $x\\to \\infty $\nif the following holds:%\n\\begin{equation*}\n\\lim_{x\\to \\infty }\\frac{f\\left( x\\right) }{g\\left( x\\right) }%\n=\\infty ,\n\\end{equation*}%\nor equivalently,%\n\\begin{equation*}\n\\lim_{x\\to \\infty }\\frac{g\\left( x\\right) }{f\\left( x\\right) }=0.\n\\end{equation*}\n\\end{definition}\n\nHere are a few obvious examples:\n\n\\begin{example}{}{ComparingMonomials}\nShow that if $m>n$ are two positive integers, then $f(x)=x^m$ grows faster\nthan $g(x)=x^n$ as $x\\to \\infty$.\n\\end{example}\n\\begin{solution}\nSince $m>n,$ $m-n$ is a positive integer. Therefore,%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{f(x)}{g(x)}=\\lim_{x\\to \\infty}\\frac{x^m}{x^n}=\\lim_{x\\to \\infty}x^{m-n}=\\infty.\n\\end{equation*}\n\\end{solution}\n\n\\begin{example}{}{CompareMonicPoly}\nShow that if $m>n$ are two positive integers, then any monic polynomial\n$P_{m}(x)$ of degree $m$ grows faster than any monic polynomial\n$P_{n}(x)$ of degree $n$ as $x\\to \\infty$. [Recall that\na polynomial is monic if its leading coefficient is 1.]\n\\end{example}\n\\begin{solution}\nBy assumption, $P_{m}(x)=x^m+$ terms of degrees less than \n$m=x^{m}+a_{m-1}x^{m-1}+\\ldots$, and $P_{n}(x)=x^n+$ terms of\ndegrees less than $n=x^{n}+b_{n-1}x^{n-1}+\\ldots$. Dividing the numerator and\ndenominator by $x^n$, we get%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{f(x)}{g(x)}=\\lim_{x\\to \\infty}\\frac{x^{m-n}+a_{m-1}x^{m-n-1}+\\ldots}{1+\\frac{%\n\t\tb_{n-1}}{x}+\\ldots}=\\lim_{x\\to \\infty}x^{m-n}(\\frac{1+\\frac{%\n\t\ta_{m-1}}{x}+\\ldots}{1+\\frac{b_{n-1}}{x}+\\ldots}) =\\infty,\n\\end{equation*}%\nsince the limit of the bracketed fraction is 1 and the limit of $x^{m-n}$ is \n$\\infty$, as we showed in Example~\\ref{exa:ComparingMonomials}.\n\\end{solution}\n\n\\begin{example}{}{HighestDegreeTermGrowth}\nShow that a polynomial grows exactly as fast as its highest degree term\nas $x\\to \\infty$ or $-\\infty$. That is, if $P(x)$ is\nany polynomial and $Q(x)$ is its highest degree term, then both limits\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{P(x)}{Q(x)}\\text{ and }\\lim_{x\\to -\\infty}\\frac{P(x)}{Q(x)}\n\\end{equation*}%\nare finite and nonzero.\n\\end{example}\n\\begin{solution}\nSuppose that $P(x)=a_{n}x^{n}+a_{n-1}x^{n-1}+\\ldots+a_{1}x+a_{0},$ where $a_{n}\\neq 0.$ Then the\nhighest degree term is $Q\\left( x\\right) =a_{n}x^{n}.$ So,%\n\\begin{equation*}\n\\lim_{x\\to \\infty }\\frac{P\\left( x\\right) }{Q\\left( x\\right) }%\n=\\lim_{x\\to \\infty }\\left( a_{n}+\\frac{a_{n-1}}{x}+...+\\frac{a_{1}}{%\n\tx^{n-1}}+\\frac{a_{0}}{x^{n}}\\right) =a_{n}\\neq 0.\n\\end{equation*}\n\\end{solution}\n\nLet's state a theorem we mentioned when we discussed the last example in the\nlast subsection:\n\n\\begin{theorem}{}{}\nLet $n$ be any positive integer and let $a>1$. Then $f(x)=a^x$\ngrows faster than $g(x)=x^n$ as $x\\to \\infty$:\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{a^x}{x^n}=\\infty\\text{, }\\lim_{x\\to \\infty}\\frac{x^n}{a^x}=0.\n\\end{equation*}%\nIn particular,%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{e^x}{x^n}=\\infty\\text{, }\\lim_{x\\to \\infty}\\frac{x^n}{e^x}=0.\n\\end{equation*}\n\\end{theorem}\n\nThe easiest way to prove this is to use the L'H\\^{o}pital's Rule, which we will\nintroduce in a later chapter. For now, one can plot and compare the graphs\nof an exponential function and a power function. Here is a comparison\nbetween $f(x)=x^2$ and $g(x)=2^x$:\n\n\\begin{center}\n\\begin{tikzpicture}[]\n\\begin{axis}[\n\taxis lines=middle,\n\tymin=0,\n\tymax=130,\n\txmin=0,\n\txmax=7,\n\txlabel={$x$},\n\t]\n\t\\addplot [mark=none,samples=200,red] {x^2};\n\t\\addplot [mark=none,samples=200,blue] {2^x};\n\\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\nNotice also that as $x\\to -\\infty$, $x^n$ grows in size but\n$e^x$ does not. More specifically, $x^n\\to \\infty$ or $-\\infty$\naccording as $n$ is even or odd, while $e^x\\to 0$. So, it is\nmeaningless to compare their ``growth''\nrates, although we can still calculate the limit\n\\begin{equation*}\n\\lim_{x\\to -\\infty}\\frac{e^x}{x^n}=0.\n\\end{equation*}\n\nLet's see an application of our theorem.\n\n\\begin{example}{}{}\nFind the horizontal asymptote(s) of $f(x)=\\dfrac{x^3+2e^x}{e^x-4x^2}$.\n\\end{example}\n\\begin{solution}\nTo find horizontal asymptotes, we calculate the limits of $f(x)$\nas $x\\to \\infty$ and $x\\to -\\infty$. For $x\\to \\infty$,\nwe divide the numerator and the denominator by $e^x$,\nand then we take limit to get%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\dfrac{x^3+2e^x}{e^x-4x^2}=%\n\\lim_{x\\to \\infty}\\dfrac{\\frac{x^3}{e^x}+2}{1-4\\frac{x^2}{e^x}}%\n=\\frac{0+2}{1-4(0)}=2.\n\\end{equation*}%\nFor $x\\to -\\infty$, we divide the numerator and the denominator by $x^2$ to get \n\\begin{equation*}\n\\lim_{x\\to -\\infty}\\dfrac{x^3+2e^x}{e^x-4x^2}%\n=\\lim_{x\\to -\\infty}\\dfrac{x+2\\frac{e^x}{x^2}}{\\frac{e^x}{x^2}-4}.\n\\end{equation*}%\nThe denominator now approaches $0-4=-4$. The numerator has limit $-\\infty$.\nSo, the quotient has limit $\\infty$: \n\\begin{equation*}\n\\lim_{x\\to -\\infty}\\dfrac{x+2\\frac{e^x}{x^2}}{\\frac{e^x}{x^2}-4}=\\infty.\n\\end{equation*}%\nSo, $y=2$ is a horizontal asymptote. The function $y=f(x)$\napproaches the line $y=2$ as $x\\to \\infty$. And this is the only\nhorizontal asymptote, since the function $y=f(x)$ does not\napproach any horizontal line as $x\\to -\\infty$.\n\\end{solution}\n\nSince the growth rate of a polynomial is the same as that of its leading\nterm, the following is obvious:\n\n\\begin{example}{}{}\nIf $P(x)$ is any polynomial, then%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{P(x)}{e^x}=0.\n\\end{equation*}\n\\end{example}\n\nAlso, if $r$ is any real number, then we can place it between two\nconsecutive integers $n$ and $n+1.$ For example, $\\sqrt{3}$ is between 1 and\n2, $e$ is between 2 and 3, and $\\pi$ is between 3 and 4. Then the following\nis totally within our expectation:\n\n\\begin{example}{}{}\nProve that if $a>1$ is any basis and $r>0$ is any exponent,\nthen $f(x)=a^x$ grows faster than $g(x)=x^r$\nas $x\\to \\infty$.\n\\end{example}\n\\begin{solution}\nLet $r$ be between consecutive integers $n$ and $n+1$. Then for\nall $x>1$, $x^{n}\\leq x^{r}\\leq x^{n+1}$. Dividing by $a^{x}$, we get%\n\\begin{equation*}\n\\frac{x^n}{a^x}\\leq \\frac{x^r}{a^x}\\leq \\frac{x^{n+1}}{a^x}.\n\\end{equation*}%\nSince \n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{x^n}{a^x}=0.\n\\end{equation*}\n\\end{solution}\n\nWhat about exponential functions with different bases? We recall from the\ngraphs of the exponential functions that for any base $a>1$,%\n\\begin{equation*}\n\\lim_{x\\to \\infty}a^x=\\infty.\n\\end{equation*}\n\nSo, the exponential functions with bases greater than 1 all grow to infinity\nas $x\\to \\infty$. How do their growth rates compare?\n\n\\begin{theorem}{}{}\nIf $1<a<b$, then $f(x)=b^x$ grows faster than\n$g(x)=a^x$ as $x\\to \\infty$.\n\\end{theorem}\n\\begin{proof}\nProof. Since $a<b$, we have $\\frac{b}{a}>1$. So,%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{b^x}{a^x}=\\lim_{x\\to \\infty}\\left(\\frac{b}{a}\\right)^x=\\infty.\n\\end{equation*}\n\\end{proof}\n\nAnother function that grows to infinity as $x\\to \\infty$ is\n$g(x)=\\ln x$. Recall that the natural logarithmic function is\nthe inverse of the exponential function $y=e^x$. Since $e^x$ grows very\nfast as $x$ increases, we should expect $\\ln x$ to grow very slowly as $x$\nincreases. The same applies to logarithmic functions with any basis $a>1$.\nThis is the content of the next theorem.\n\n\\begin{theorem}{}{}\nLet $r$ be any positive real number and $a>1$. Then \n\n\\begin{enumerate}[(a)]\n\\item\t$f(x)=x^r$ grows faster than $g(x)=\\ln x$ as $x\\to \\infty$.\n\\item\t$f(x)=x^r$ grows faster than $g(x)=\\log_{a}x$ as $x\\to \\infty$.\n\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n\\begin{enumerate}\n\\item\tWe use a change of variable. Letting $t=\\ln x$, then $x=e^t$.\nSo, $x\\to \\infty$ if and only if $t\\to \\infty$, and \n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{\\ln x}{x^r}=\\lim_{t\\to \\infty}\\frac{t}{(e^t)^r}%\n=\\lim_{t\\to \\infty}\\frac{t}{(e^r)^t}.\n\\end{equation*}%\nNow, since $r>0$, $a=e^r>1$. So, $a^t$ grows as $t$ increases, and it\ngrows faster than $t$ as $t\\to \\infty$. Therefore,%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{\\ln x}{x^{r}}%\n=\\lim_{t\\to \\infty}\\frac{t}{(e^r)^t}=\\lim_{t\\to \\infty}\\frac{t}{a^t}=0.\n\\end{equation*}\n\\item\tThe change of base identity $\\log_{a}x=\\dfrac{\\ln x}{\\ln a}$ implies\nthat $\\log_{a}x$ is simply a constant multple of $\\ln x$. The result now\nfollows from (a).\n\\end{enumerate}\n\\end{proof}", "meta": {"hexsha": "25e1181016e1b2c2834b6374ab553780bc21a57c", "size": 9813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-5-4-end-behaviour-growth-rate.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-5-4-end-behaviour-growth-rate.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-5-4-end-behaviour-growth-rate.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1828793774, "max_line_length": 103, "alphanum_fraction": 0.6747172119, "num_tokens": 3754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.737158174177441, "lm_q2_score": 0.90329420279886, "lm_q1q2_score": 0.6658707052802747}}
{"text": "\\chapter{A Brief Survey of Approaches for Unconstrained Optimization Problems}\n\n\\section{Basic Conceptions}\n\\subsection{Problem Description}\nThe goal of unconstrained optimization problem is to minimize the objective function f\n\t\n\\begin{eqnarray*}\n\t\t\t\\min\\limit_{x\\in\\Rn} \\quad f(x),\n\\end{eqnarray*}\nwhere $f: \\Rn \\longmapsto \\R$. \n\nThe objective function f can be convex or nonconvex, differentiable or non-differentiable. The acquirable information include function value, derivative and so on.\n\nOn the other hand, the constrained optimization contains some constraints\n\\begin{eqnarray*}\n\t    \t\\min\\limits_{x\\in\\Rn} \\quad f(x), \\quad \\st \\quad x\\in C.\n\\end{eqnarray*}\nIt is equivalent to the unconstrained optimization problem in the way \n\\begin{eqnarray*}\n\t    \t\\min\\limits_{X\\in\\Rn} \\,\\, f(x) + \\delta_C(x), where~  \\delta_C(x):=\\ifelse{0, & \\mbox{if\\,}x\\in C;\\\\ 1, & \\mbox{otherwise.}}\n\\end{eqnarray*}\nMeanwhile we can have exact penalty functions such as $\\ell_1$ penalty, augmented Lagrangian, etc.\n\n\n\n%******************************************************\n\\subsection{Optimality Conditions}\nThere are several cases as to the optimality conditions.\n\n\t\\subsubsection{First-order optimality conditions}\nWhen it's the first-order optimality conditions, $f$ is differentiable: $\\nabla f(x)=0$. Moreover, $f$ is nondifferentiable but convex\n\t\t$$0\\in \\partial f(x):=\\{g\\mid f(y)\\geq f(x)+ g\\zz (y-x),\\,\\forall\\, y \\}.$$\t\t\n\t\\subsubsection{Second-order necessary (sufficient) optimality conditions}\nOn the other hand, when the optimality condition is the second-order necessary (sufficient) optimality condition, $f$ is second-order differentiable: \n\\begin{eqnarray*}\n\t    \t\\nabla^2 f(x)\\succeq (\\succ) 0.\n\\end{eqnarray*}\n\n\n\n\t\\subsubsection{Optimization condition (differentiability is assumed)}\nWhen only differentiability is assumed, there are many cases.\nIt is simple when $f$ is convex: $x^*$ is a global minimizer $\\Leftrightarrow\\,\\nabla f(x^*)=0$.\n\nWhen $f$ is nonconvex:\n\t\t\\begin{itemize}\n\t\t\t\\item \\clr{$x^*$ is a first-order stationary point $\\Leftrightarrow\\,\\nabla f(x^*)=0$\\qquad\n\t\t\t$\\bigstar$}\\\\[1mm]\n\t\t\t\\item \\clr{$x^*$ is a local minimizer $\\Rightarrow\\,\\nabla f(x^*)=0$}\\\\[1mm]\n\t\t\t\\item \\clg{$x^*$ is a second-order stationary point\n\t\t\t\t$\\Leftrightarrow\\,{\\color{red}\\bigstar}\\mbox{\\,\\,and}\\,\\,\\nabla^2 f(x^*)\\succeq 0$}\\\\[1mm]\n\t\t\t\\item \\clg{$x^*$ is a local minimizer $\\Rightarrow\\,\\nabla^2 f(x^*)\\succeq 0$}\\\\[1mm]\n\t\t\t\\item \\clb{$x^*$ is a local minimizer $\\Leftarrow\\,{\\color{red}\\bigstar}\\mbox{\\,\\,and}\\,\\,\\nabla^2 f(x^*)\\succ 0$}\n\t\t\\end{itemize}\n\t\n\n\t\\subsubsection{Finding a minimizer (nonconvexness is assumed)}\nWhen the non-convexness is assumed, we have some conclusions\n\t\\begin{itemize}\n\t\t\\item finding global minimizer is \\clb{numerically impossible}\n\t\t\\item finding global minimizer for quartic polynomial is already \\clb{NP-hard}\n\t\t\\item finding local minimizer is \\clb{not easier}\n\t\\end{itemize}\n\nWith all the discussions above, the task of numerical optimization methods becomes clear. \nAs for the first-order methods, it is to find first-order stationary point.\nWe want to find second-order stationary point for second-order methods. What's more, finding global minimizer or local minimizer becomes possible only when $f$ is structured. \n\t\n\n\n%******************************************************\n\\subsection{Iterative Methods}\nWe can use the iterative methods to find the desired stationary points.\n\n\t\\subsubsection{Framework}\nThe framework of the iterative methods is as follows.\n\t\\begin{itemize}\n\t\t\\item[(1)] Input: initial guess $x^0$, tolerance $\\epsilon$, $k:=0$;\n\t\t\\item[(2)] Main iteration: $x^{k+1} = h(x^k)$;\n\t\t\\item[(3)] Check stopping criterion, if satisfied, then terminate and return $x^{k+1}$;\n\t\totherwise, set $k:=k+1$ and goto step (2).\n\t\\end{itemize}\nThe stopping criterions is different according to the orders.\nFor first-order criterion, it is $||\\nabla f(x)||<\\epsilon$.\nIt is $\\lambda_{\\min}(\\nabla^2 f(x))>-\\epsilon$ for second-order criterion.\n\n\t\n\n\n\t\\subsubsection{Choosing $h$}\nA question naturally arises that how do we choose an appropriate iteration function h.\nFor line search methods such as gradient methods and Newton methods, we let $x^{k+1} = x^k + \\alpha^k d^k$ with$\\alpha^k$ as the stepsize.\nThe $h$ can be so different as for trust region methods, block coordinate descent methods and so on.\n\t\n\t\\subsubsection{Fixed-point convergence -- contraction}\nMoreover we can find the desired points with fixed-point convergence if $||\\mathcal{J}_h(x)||<1$ holds for a given norm $||\\cdot||$ and any $x\\in\\Rn$, where $\\mathcal{J}_h$ stands for the Jacobian of $h$. \nBut we should note that the following example shows that $\\rho\\left(\\mathcal{J}_h(x)\\right)<1$ is not sufficient for nonstationary iteration\n\\begin{eqnarray*}\n\t\\small \\mathcal{J}_h(x^{2k-1}) &=\\mat{cc}{0.5 & 10\\\\ 0 & 0.5},\n\\\\\t\\mathcal{J}_h(x^{2k}) &=\\mat{cc}{0.5 & 0\\\\ 10 & 0.5},  \\forall\\, k=1, ...\n\\end{eqnarray*}\n\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Iterative Methods (Cont'd)}\n\t\\subsubsection{Global convergence -- to stationarity}\nHowever, it is not so easy to find the global stationary points. Some conditions of $f$ need to be met as following\n\t\\begin{itemize}\n\t\t\\item objective is bounded below: \\clg{$f(x)>-\\infty$}.\n\t\t\\item sufficient function value reduction:\n\t\t\\clr{\n\t\t$$f(x^k)-f(x^{k+1})\\geq c||\\nabla f(x^k)||_2^2.$$\n\t\t}\n\t\t\\vspace{-6mm}\n\t\t\n\t\t\\item convergence to first-order\n\t\tstationarity: \\clb{$\\lim\\limits_{k\\rightarrow +\\infty} \\nabla f(x^k)=0$}\n\t\t\\end{itemize}\nAnd we should note\n\t\t\\begin{itemize}\n\t\t\\item if iterate sequence is bounded, \\clb{subsequence convergence to a stationary point}\n\t\\end{itemize}\n\n\n\t\\subsubsection{Local convergence}\nSuppose we have \n\t\\begin{eqnarray*}\n\t\t\\lim\\limits_{k\\rightarrow +\\infty} x^k=x^*,\\qquad q^k = \\frac{||x^{k+1}-x^*||}{||x^{k}-x^*||^p}.\n\t\\end{eqnarray*}\nThen the local convergence rate is defined accordingly as following\t\n\t\\begin{itemize}\n\t\t\\item \\clm{$p=1$}, \\clg{\\small $\\lim\\limits_{k\\rightarrow +\\infty}q^k=q=1$}:\n\t\tlocal Q-sublinear convergence\n\t\t\\item \\clm{$p=1$}, \\clg{\\small $\\lim\\limits_{k\\rightarrow +\\infty}q^k=q\\in(0,1)$}:\n\t\tlocal Q-linear convergence\n\t\t\\item \\clm{$p=1$}, \\clg{\\small $\\lim\\limits_{k\\rightarrow +\\infty}q^k=q=0$}:\n\t\tlocal Q-superlinear convergence\n\t\t\\item \\clm{$p>1$}, \\clg{\\small $\\lim\\limits_{k\\rightarrow +\\infty}q^k=q$}:\n\t\tlocal convergence with order $p$\n\t\t\\begin{itemize}\n\t\t\t\\item $p=2$, quadratic\n\t\t\t\\item $p=3$, cubic\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\\vspace{-5mm}\n\t\n\n\t\\begin{eqnarray*}\n\t\t\\lim\\limits_{k\\rightarrow +\\infty} x^k=x^*,\\qquad\n\t\t||x^k-x^*|| \\leq cq^k.\n\t\\end{eqnarray*}\n\t\\begin{itemize}\n\t\t\\item \\clg{$q\\in(0,1)$}, local R-linear convergence rate\n\t\\end{itemize}\n\n\n\t\\subsubsection{Worst case complexity/Global convergence rate}\nThe  complexity for global convergence rate varies a lot.\\\\\nWe get $\\epsilon-$solution after $O\\left(\\log \\frac{1}{\\epsilon}\\right)$ iterations as for global linear convergence. \\\\\nBut in the worst case, we get $\\epsilon-$solution after $O\\left(\\frac{1}{\\epsilon^{1/q}}\\right)$ iterations for global sublinear convergence:\n\\begin{eqnarray*}\n\t\t\t\\lim\\limits_{k\\rightarrow +\\infty} f(x^k)=f^*,\\qquad\n\t\t\tf(x^k)-f^*<\\frac{c}{k^q},\\quad q>0.\n\\end{eqnarray*}\n\n\t\\subsubsection{Global convergence -- iterate convergence}\nThe global convergence can be achieved by the considering iterate convergence in several ways\n\t\\begin{itemize}\t\n\t\t\\item {\\color{blue} Sufficient reduction:}\n\t\t\\vspace{-1mm}\n\t\t\\clm{\\begin{eqnarray*}\n\t\t\t\tf(x^{k})-f(x^{k+1})\\geq c_1 ||x^k-x^{k+1}||_2^2.\n\t\t\\end{eqnarray*}}\n\t\t\\vspace{-8mm}\n\t\t\\item {\\color{blue} Asmptotic small stepsize safe-guard:}\n\t\t\\vspace{-1mm}\n\t\t\\clm{\\begin{eqnarray*}\n\t\t\t\t||x^k-x^{k+1}||_2\\geq c_2 ||g^k||_2,\\qquad g^k\\in\\partial f(x^k).\n\t\t\\end{eqnarray*}}\n\t\t\\vspace{-8mm}\n\t\t\\item {\\color{blue}\\L{}ojasiewicz property:} {$\\exists\\, \\theta\\in[0,1)$ such that}\n\t\t\\vspace{-1mm}\n\t\t\\clm{\n\t\t\t\\begin{eqnarray*}\n\t\t\t\t|f(x)- f(x^*)|^\\theta\\leq  c_3||g||_2,\\qquad \\forall x\\in {\\cal B}(x^*,\\epsilon),\n\t\t\t\t\\quad \\forall g\\in \\partial f(x).\n\t\t\\end{eqnarray*}}\n\t\t\\vspace{-6mm}\n\t\t\\item \\clg{iterate convergence:}  \\clr{$\\sum\\limits_{k=1}^\\infty ||x^k-x^{k+1}||_2 < +\\infty.$}\n\t\t\\item \\clg{local convergence rate}\n\t\t\\begin{itemize}\n\t\t\t\\item if $\\theta = 0$, the sequence $\\{x^k\\}_{k\\in\\N}$ \\clb{finite termination;}\\\\[1mm]\n\t\t\t\\item if $\\theta \\in \\left(0,\\frac{1}{2}\\right]$, there exist $c>0$ and $Q\\in[0,1)$\n\t\t\tsuch that\n\t\t\t\\clb{$||x^k-x^*||_2\\leq {c}\\cdot{q^k}$;}\\\\[1mm]\n\t\t\t\\item if $\\theta \\in \\left(\\frac{1}{2},1\\right)$, there exist $c>0$ such that\n\t\t\t\\clb{$||x^k-x^*||_2\\leq {c}\\cdot{k^{-\\frac{1-\\theta}{2\\theta-1}}}$.}\n\t\t\\end{itemize}\n\t\\end{itemize}\n\n\n\n%********************* section ********************\n\\section{Classical Optimization Methods}\n\\iffalse\n%\\begin{frame}\n\t\\begin{center}\n\t\t\\huge\\color{blue}\\bf\n\t\tSection 2. Classical Optimization Methods\n\t\\end{center}\n%\\end{frame}\n\\fi\n\\subsection{Gradient Methods}\n%\\begin{frame}\n%\t\\frametitle{Gradient Methods}\n\t\\subsubsection{Line search}\n\tIf we got the iterative direction $d^k$, we need to find the step size $\\alpha^k$ in the $k$-th step \n\t\\clr{\\begin{eqnarray*}\n\t\tx^{k+1} = x^k + \\alpha^k d^k.\n\t\\end{eqnarray*}}\t\n\tThere are many line search methods. We can classify them into 2 classes. \\\\\n\tOne is exact line search which solve the $\\alpha$ exactly, namely $\\alpha$ satisfies\\\\\n\t \\clm{$\\alpha^k=\\argmin\\limits_{\\alpha\\in\\R} f( x^k + \\alpha d^k)$}.\\\\\n\tAnother one is inexact line search, an example of the inexact line search is Armijo line search:\n\t\\begin{itemize}\n\t\t\\item Armijo line search (back tracking):\n\t\t\\begin{itemize}\n\t\t\t\\item set $c_1\\in(0,1)$, $\\tau\\in(0,1)$, $\\alpha_0>0$, and $j:=0$;\\\\[1mm]\n\t\t\t\\item if \\clg{$f(x^k)-f(x^k+\\alpha_j d^k)\\geq -\\alpha_j c_1\\nabla f(x^k)\\zz d^k$,} return\n\t\t\t\\clm{$\\alpha^k := \\alpha_j$;}\\\\[1mm]\n\t\t\t\\item otherwise, set $j:=j+1$ and \\clb{$\\alpha_{j}=\\tau \\alpha_{j-1}$.}\n\t\t\\end{itemize}\n\t\t\\item Wolfe condition: {\\small additional curvature condition with $c_2\\in (c_1,1)$,}\n\t\t\\vspace{-1mm}\n\t\t\\clg{\n\t\t\\begin{eqnarray*}\n\t\t\t-\\nabla f(x^k + \\alpha_j d^k)\\zz d^k \\leq - c_2 \\nabla f(x^k)\\zz d^k.\n\t\t\\end{eqnarray*}}\n\t\\end{itemize}\n%\\end{frame}\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Gradient Methods (Cont'd)}\n\t\\subsubsection{Gradient methods}\n\tIn gradient methods, the iterative direction is the negative direction of gradient:\n\t\\clm{\\begin{eqnarray*}\n\t\t\td^k = - \\nabla f(x^k).\n\t\\end{eqnarray*}}\n\tThen we have many strategies to find the stepsize:\n\t\\begin{itemize}\n\t\t\\item steepest descent: exact line search\n\t\t\\item gradient descent with inexact line search:\n\t\tglobal convergence and local linear rate related\n\t\tto $\\kappa(\\nabla^2 f(x^*))$.\\\\[1mm]\n\t\t\\item Barzilai-Borwein (BB) stepsize:\n\t\t\\clb{\\begin{eqnarray*}\n\t\t\t\\alpha^k =\\frac{{s^k}\\zz y^k}{{y^k}\\zz y^k},\\quad \\mbox{or}\n\t\t\t\\quad \\alpha^k =\\frac{{s^k}\\zz s^k}{{s^k}\\zz y^k}.\n\t\t\\end{eqnarray*}}\n\t\t\\vspace{-3mm}\n\t\t\n\t\twhere \\clg{$s^k=x^k-x^{k-1} \\clm{=\\alpha^{k-1}d^{k-1}}$, $y^k=\\nabla f(x^k)-\\nabla f(x^{k-1})$,}\\\\[1mm]\n\t\t\n\t\t global convergence and local linear convergence only\n\t\tfor $f(x)=\\frac{1}{2}x\\zz Ax +b\\zz x$ with $A\\succ 0$; local superlinear convergence\n\t\tin the case $n=2$; global convergence if combined with nonmonotone line search.\n\t\\end{itemize}\n%\\end{frame}\n\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Gradient Methods (Cont'd)}\n\t\\subsubsection{Conjugate gradient methods}\n\tThe conjugate gradient methods are  originally proposed for solving linear system. We use the combination of gradient and the last step's direction to generate this step's direction.\n\t\\clm{\\begin{eqnarray*}\n\t\t\td^k = - \\nabla f(x^k) + \\beta^k d^{k-1}.\n\t\\end{eqnarray*}}\n\tThe strategies of choosing parameters:\n\t\\begin{itemize}\n\t\t\n\t\t\\item $\\alpha^k$: exact line search\n\t\t\\item updating rules for $\\beta^k$\n\t\t\\begin{itemize}\n\t\t\t\\item Fletcher-Reeves: \\clb{$\\beta^k = \\nabla f(x^k)\\zz \\nabla f(x^k)\\left/\\,\\nabla f(x^{k-1})\\zz \\nabla f(x^{k-1}) \\right.$;}\\\\[1mm]\n\t\t\t\\item Polak-Ribi\\`{e}re: \\clb{$\\beta^k = \\nabla f(x^k)\\zz y^k\\left/\\,\\nabla f(x^{k-1})\\zz \\nabla f(x^{k-1}) \\right.$;}\\\\[1mm]\n\t\t\t\\item Hestenes-Stiefel: \\clb{$\\beta^k = \\nabla f(x^k)\\zz y^k\\left/\\,{d^{k-1}}\\zz y^k \\right.$;}\\\\[1mm]\n\t\t\t\\item Dai-Yuan: \\clb{$\\beta^k = \\nabla f(x^k)\\zz \\nabla f(x^k)\\left/\\,{d^{k-1}}\\zz y^k \\right.$.}\n\t\t\\end{itemize}\n\t\t\\item subspace strategy:\n\t\t\\clm{\n\t\t\\begin{eqnarray*}\n\t\t\tx^{k+1} :=\\argmin_{x-x^k \\,\\in\\, \\mathrm{span}\\{\\nabla f(x^k),\\, d^{k-1}\\}}\\quad\n\t\t\tf(x).\n\t\t\\end{eqnarray*}\n\t\t}\n\t\n\t\t\\vspace{-2mm}\n\t\t\\clr{\\footnotesize global convergence if combined with line search, local linear convergence rate not related to $\\kappa(\\nabla^2 f(x^*))$.}\n\t\\end{itemize}\n%\\end{frame}\n\n\n%********************* section ********************\n\\subsection{Newton Methods}\n%\\begin{frame}\n%\t\\frametitle{Newton Methods}\n\tThe gradient methods only use 1-order derivative information of $f$. The Newton methods need to use 2-order derivative information.\n\t\\subsubsection{Newton methods}\n\tThe step direction of Newton methods is:\n\t\\clm{\\begin{eqnarray*}\n\t\t\td^k = - {\\nabla^2 f(x^k)}\\inv \\nabla f(x^k).\n\t\\end{eqnarray*}}\n\tThe strategies of choosing parameters:\n\t\\begin{itemize}\n\t\t\\item original ones: \\clb{$\\alpha^k = 1$ or exact line search}\\\\[1mm]\n\t\t\\clr{\\footnotesize local quadratic convergence.}\n\t\t\\item hybrid Newton method: \\clg{$d^k = -\\beta \\nabla f(x^k) - {\\nabla^2 f(x^k)}\\inv \\nabla f(x^k)$}\n\t\t\\item negative curvature descent: set \\clg{$d^k=d$} if $d\\zz \\nabla^2 f(x^k) d<0$.\n\t\t\\item damped Newton method: \\clb{$\\alpha^k= 1\\left/\\left(1+ \\sqrt{\\nabla f(x^k)\\zz {\\nabla^2 f(x^k)}\\inv \\nabla f(x^k)}\\right) \\right.$}\\\\[1mm]\n\t\t\\clr{\\footnotesize global convergence.}\n\t\\end{itemize}\n%\\end{frame}\n\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Newton Methods (Cont'd)}\n\t\\subsubsection{Motivation of quasi-Newton methods}\n\tBecause we need to spend lots of time on calculating the $\\nabla^2 f(x)$ every step, the quasi-Newton methods use the approximation of $\\nabla^2 f(x^k)$ written as $B^k$ which is much easier to calculate to get the direction:\n\t\\clm{\\begin{eqnarray*}\n\t\t\td^k = - {B^k}\\inv \\nabla f(x^k).\n\t\\end{eqnarray*}}\n\t\\vspace{-7mm}\n\t\\begin{itemize}\n\t\t%\\item $\\clb{B^k}$ is an approximation of $\\nabla^2 f(x^k)$\n\t\t\\item easy to calculate, possess the essential characteristics of Hessian, descent direction (positive definiteness of $B^k$)\n\t\t\\item solution: \\clg{the secant equation}\n\t\t\\clr{\\begin{eqnarray*}\n\t\t\t\tB^k s^k = y^k.\n\t\t\\end{eqnarray*}}\n\t\t\\vspace{-7mm}\n\t\t\\item SR$-1$ (symmetric rank$-1$ update) can not guarantee the positive definiteness\n\t\t\\item rank$-2$ update is more favorable\n\t\t\\begin{itemize}\n\t\t\t\\item start from \\clb{$B^0$}, (e.g. $\\alpha I_n$.)\\\\[1mm]\n\t\t\t\\item in each iteration, add rank$-2$ update\n\t\t\t\\clb{$B^{k+1}=B^k+\\alpha uu\\zz +vv\\zz$;}\\\\[1mm]\n\t\t\t\\item choose \\clb{$u=y^k$, $v=B^ks^k$,} we arrive at -- \\clr{BFGS.}\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Newton Methods (Cont'd)}\n\t\\subsubsection{BFGS (Broyden-Fletcher-Goldfarb-Shanno)}\n\t\\clm{\\footnotesize $$B^{k+1}_{\\tiny\\mbox{BFGS}} = B^k + \\frac{{y^k}\\zz {y^k}}{{y^k}\\zz s^k} -\\frac{B^ks^k{s^k}\\zz B^k}\n\t\t{{s^k}\\zz B^ks^k}.$$}\n\t\\vspace{-5mm}\n\t\\begin{itemize}\n\t\t\\item consider the update for inverse $H^k={B^k}\\inv$\n\t\t\\clr{\\footnotesize  $$H^{k+1}_{\\tiny\\mbox{BFGS}} = \\left(I-\\frac{{s^k}{y^k}\\zz}{{s^k}\\zz y^k}\\right)H^k\\left(I-\\frac{{s^k}{y^k}\\zz}{{s^k}\\zz y^k}\\right) + \\frac{{s^k} {s^k}\\zz}{{s^k}\\zz y^k}.$$}\n\t\t\\vspace{-5mm}\n\t\t\\item minimum change property:\n\t\t\\clb{\\small  $$H^{k+1}=\\min\\limits_{H\\in\\Sn} ||H-H^k||_G,\\quad \\st \\quad Hy^k = s^k$$}\n\t\t\\vspace{-5mm}\n\t\t{\\footnotesize where $||A||_G = ||G^{\\frac{1}{2}}AG^{\\frac{1}{2}}||\\ff$, $G\\in\\{G\\mid Gs^k=y^k\\}$,\n\t\te.g. $G=\\int_0^1 \\nabla^2 f(x^k+\\tau \\alpha^k d^k)d\\tau$}\\\\[7mm]\n\t\\end{itemize}\n\n\t\\clr{\\footnotesize global convergence if combined with line search; local linear convergence\n\t\tif $f$ is strict convex; local superlinear convergence if $f$ is strongly convex.}\n%\\end{frame}\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Newton Methods (Cont'd)}\n\t\\subsubsection{DFP (Davidon-Fletcher-Powell)}\n\t\\clm{\\footnotesize $$B^{k+1}_{\\tiny\\mbox{DFP}} = \\left(I-\\frac{{s^k}{y^k}\\zz}{{s^k}\\zz y^k}\\right)B^k\\left(I-\\frac{{s^k}{y^k}\\zz}{{s^k}\\zz y^k}\\right) + \\frac{{y^k} {y^k}\\zz}{{s^k}\\zz y^k}.$$}\n\t\\vspace{-5mm}\n\t\\begin{itemize}\n\t\t\\item consider the update for inverse $H^k={B^k}\\inv$\n\t\t\\clg{\\footnotesize  $$H^{k+1}_{\\tiny\\mbox{DFP}} = H^k + \\frac{{s^k}\\zz {s^k}}{{y^k}\\zz s^k} -\\frac{H^ky^k{y^k}\\zz H^k}\n\t\t\t{{y^k}\\zz H^ky^k}.$$}\n\t\\end{itemize}\n\t\n\t\\clr{\\footnotesize global convergence if combined with line search and local linear convergence\n\t\tif $f$ is strict convex; local superlinear convergence if $f$ is strongly convex.}\n\t\\bigskip\n\t\n%\t\\structure{\\bf The Broyden family}\n\t\\begin{eqnarray*}\n\t\tB^{k+1} = (1-\\phi^k) B^{k+1}_{\\tiny\\mbox{BFGS}} + \\phi^k B^{k+1}_{\\tiny\\mbox{DFP}},\\qquad \\phi^k\\in[0,1].\n\t\\end{eqnarray*}\n\t\\clr{\\footnotesize $\\phi^k\\in[0,1)$ same convergence property with BFGS.}\n%\\end{frame}\n\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Newton Methods (Cont'd)}\n\t\\subsubsection{Limited memory quasi-Newton method}\n\t\\begin{itemize}\n\t\t\\item if the storage of \\clr{$B^k$} (\\clr{$H^k$}) is not affordable\\footnote{\n\t\tThe difference between using $B^k$ or $H^k$ appears at the computational cost, and the storage\n\t    is a whole other story.}\n\t\t\\item rank$-2$ update provides a limited memory strategy\n\t\t\\begin{itemize}\n\t\t\t\\item store \\clb{$\\mathcal{L}:=\\{s^k,s^{k-1},...,s^{\\max\\{k-l+1,0\\}},y^k,y^{k-1}),...,y^{\\max\\{k-l+1,0\\}}\\}$;}\\\\[1mm]\n\t\t\t\\item $H^k$ is built up from $H^0$ by a \\clm{rank$-2\\max\\{l,k\\}$ update}\\\\[1mm]\n\t\t\t\\item reduce the storage from $O(n^2)$ to \\clg{$O(mn)$} at a cost of $O(mn)$ arithmetic operation\\\\[1mm]\n\t\t\t\\item reduce the computational cost from $O(n^2)$ to \\clg{$O(mn)$}, if there is no structure\n\t\t\\end{itemize}\n\t\t\\item numerically successful\n\t\t\\begin{itemize}\n\t\t\t\\item BFGS update\\\\[1mm]\n\t\t\t\\item $m=10$\\\\[2mm]\n\t\t\\end{itemize}\n\t\\end{itemize}\n\n\t\\clr{\\footnotesize global convergence if combined with line search and local linear convergence.}\n%\\end{frame}\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Newton Methods (Cont'd)}\n\t\\subsubsection{The explanation of BB stepsize}\n\t\\clb{\\begin{eqnarray*}\n\t\t\tx^{k+1} = x^k -\\alpha^k \\nabla f(x^k),\\quad \\mbox{with} \\quad\n\t\t\t\\clr{\\alpha^k =\\frac{{s^k}\\zz y^k}{{y^k}\\zz y^k}},\\quad \\mbox{or}\n\t\t\t\\quad \\clm{\\alpha^k =\\frac{{s^k}\\zz s^k}{{s^k}\\zz y^k}}.\n\t\\end{eqnarray*}}\n    \\vspace{-3mm}\n    \\begin{itemize}\n    \t\\item Using $\\frac{1}{\\alpha}\\cdot I$ to approximate $\\nabla^2 f(x^k)$\n    \t\\clm{$$\\alpha^k = 1 \\left/ \\argmin\\limits_{\\beta\\in\\R} \\left\\|\\beta s^k -y_k\\right\\|_2^2\\right.. $$}\n    \t\\vspace{-5mm}\n    \t\\item Using $\\alpha\\cdot I$ to approximate ${\\nabla^2 f(x^k)}\\inv$\n    \t\\clr{$$\\alpha^k = \\argmin\\limits_{\\alpha\\in\\R} ||\\alpha y^k -s_k||_2^2. $$}\n    \\end{itemize}\n%\\end{frame}\n\n\n%********************* section ********************\n\\subsection{Trust Region Methods}\n%\\begin{frame}\n%\t\\frametitle{Trust Region Methods}\n\tRegion Methods are another kinds of optimize methods. The motivation of them are finding the minimize of the quadratic approximation of $f$ in a limited region. If the quadratic approximation can approximate $f$ well, expand the region, else reduce the region. In mathematics,\n\t\\clr{\\begin{eqnarray*}\n\t\t\tx^{k+1} &=& x^k + s^k,\\\\\n\t\t\ts^k &=& \\argmin\\limits_{s\\in \\R} \\quad m^k(s),\\quad \\st\\quad ||s||_2\\leq \\Delta^k.\n\t\t\\end{eqnarray*}\n\t}\n\t\\vspace{-5mm}\n\t\\begin{itemize}\n\t\t\\item $m^k(s)$ quadratic approximation of $f(x^k+s)$ at $x^k$\n\t\t\\clb{\\begin{eqnarray*}\n\t\t\t\tm^k(s) := \\nabla f(x^k)\\zz s + \\frac{1}{2}s\\zz B^k s.\n\t\t\\end{eqnarray*}}\n\t\t\\vspace{-5mm}\n\t\t\\item solving subproblem\n\t\t\\begin{itemize}\n\t\t\t\\item exactly solver: \\clg{Mor\\'{e}-Sorensen}\n\t\t\t\\item approximate: Chauchy point, dog-leg\n\t\t\t\\item inexact solver: \\clg{truncated CG, $2-$D subspace minimization}\n\t\t\\end{itemize}\n\t\t\\item the choice of \\clb{$B^k$}\n\t\t\\begin{itemize}\n\t\t\t\\item $\\nabla^2 f(x^k)$\\\\[1mm]\n\t\t\t\\item quasi-Newton update\\\\[1mm]\n\t\t\t\\item other approximation of $\\nabla^2 f(x^k)$\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Trust Region Methods (Cont'd)}\n\t\\begin{itemize}\n\t\t\\item approximation ratio\n\t\t\\clm{\\small $$\\eta^k = \\frac{\\mbox{red}_{\\mbox{\\tiny real}}}{\\mbox{red}_{\\mbox{\\tiny pred}}}\n\t\t= \\frac{f(x^k)-f(x^k+s^k)}{m(0)-m(s^k)}.$$}\n\t\t\\vspace{-5mm}\n\t\t\\item accept trial step of not:\n\t\t\\clb{\\small\n\t\t$$x^{k+1} = \\ifelse{\n\t\tx^k + s^k, & \\mbox{if\\,} \\eta^k>0;\\\\\n\t\tx^k, & \\mbox{otherwise.}\n\t    }$$\n\t\t}\n\t\t\\vspace{-5mm}\n\t\t\\item updating trust region radius \\clg{$\\Delta^k$}\n\t\t\\clb{\\small\n\t\t\t$$\\Delta^{k+1} = \\ifelse{\n\t\t\t\tb_2 \\Delta^k, & \\mbox{if\\,} \\eta^k > c_2;\\\\\n\t\t\t\t\\Delta^k, & \\mbox{if\\,} c_2\\geq \\eta^k>c_1;\\\\\n\t\t\t\tb_1 \\Delta^k, & \\mbox{otherwise.}\n\t\t\t}$$\n\t\t}\n\t\t\\vspace{-5mm}\n\t\t{\\small where  $0<c_1<c_2<1$, $0<b_1<1<b_2$}.\\\\[7mm]\n\t\\end{itemize}\n\n\t\\clr{\\footnotesize global convergence only requires subproblem inexactly solved; convergence to second-order stationary point if $B^k=\\nabla^2 f(x^k)$ and subproblem exactly solved.}\n%\\end{frame}\n\n%********************* section ********************\n\\subsection{Methods for Nonlinear Least Squares}\n%\\begin{frame}\n%\t\\frametitle{Methods for Nonlinear Least Squares}\n\t\\subsubsection{Nonlinear least squares}\n\tFor nonlinear least squares, the objective function $f$ reads:\n\t\\clm{\n\t$$f(x)= ||F(x)||_2^2 = \\sum\\limits_{i=1}^m f^2_i(x)~.$$\n\t}\n\t\\vspace{-5mm}\n\t\\begin{itemize}\n\t\t\\item $F(x):=\\left(f_1(x),...,f_m(x)\\right)\\zz$, each $f_i(x):\\Rn\\mapsto \\R$ ($i=1,...,m$)\n\t\t\\item Jacobian matrix: \\clb{$\\mathcal{J}_F(x)=\\left(\\nabla f_1(x),...,\\nabla f_m(x)\\right)\\zz$}\n\t\t\\item gradient: \\clr{$\\nabla f(x) = \\mathcal{J}_F(x)\\zz F(x)$}\n\t\t\\item Hessian: \\clr{$\\nabla^2 f(x) = \\mathcal{J}_F(x)\\zz \\mathcal{J}_F(x) + \\sum\\limits_{i=1}^m\n\t\t\tf_i(x)\\nabla^2 f_i(x)$}\n\t\t\\item linear approximation:\\clr{ $F(x) \\approx F(x^{(k)})+\\mathcal{J}_F(x^{(k)})(x-x^{(k)}) $}\n\t\t\\item new approximation of Hessian: \\clg{$\\mathcal{J}_F(x)\\zz \\mathcal{J}_F(x)$}\n\t\t\\begin{itemize}\n\t\t\t\\item approximation quality depends on residuals $f_i(x)$  ($i=1,...,m$)\\\\[1mm]\n\t\t\t\\item obtain partial Hessian information by collecting derivatives\\\\[1mm]\n\t\t\t\\item positive definiteness\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n%******************************************************\n%\\begin{frame}\n%\t\\frametitle{Methods for Nonlinear Least Squares (Cont'd)}\n\t\\subsubsection{Gauss Newton method}\n\tThe step direction of Gauss Newton methods is:\n\t\\clm{\n\t\t$$d^k = - \\left(\n\t\t\\mathcal{J}_F(x^k)\\zz \\mathcal{J}_F(x^k)\t\\right)\\inv \\nabla f(x^k)$$\n\t}\n\t\\vspace{-6mm}\n\t\\begin{itemize}\n\t\t\\item similar performance as Newton method if small residual\n\t\t\\item similar performance as gradient method if large residual\n\t\t\\item numerically unstable if \\clr{$\\mathcal{J}_F(x^k)$} is singular or close to singular\n \t\\end{itemize}\n    \\medskip\n\n%    \\structure{\\bf Levenberg-Marquardt method}\n    \\clg{\n    \t$$s^k = - \\left(\n    \t\\mathcal{J}_F(x^k)\\zz \\mathcal{J}_F(x^k) + \\clb{\\mu^k} \\cdot I\\right)\\inv \\nabla f(x^k)$$\n    }\n    \\vspace{-6mm}\n    \\begin{itemize}\n    \t\\item regularization parameter $\\clb{\\mu^k}$ can be tuned\n    \t\\begin{itemize}\n    \t\t\\item in the same manner as trust region radius\n    \t\t\\item \\clb{$||F(x^k)||_2^t$ ($t=[1,2]$)}\\\\[3mm]\n    \t\\end{itemize}\n    \\end{itemize}\n\n\t\\clr{\\footnotesize global convergence; quadratic local convergence rate if $\\mu^k\\rightarrow 0$\n\t\tand zero residual at solution}\n%\\end{frame}\n\n\n%********************* section ********************\n\\subsection{Block Coordinate Descent}\n%\\begin{frame}\n%\t\\frametitle{Block Coordinate Descent}\n\t\\clr{\n\t\\begin{eqnarray*}\n\t\t\\left\\{\n\t\t\\begin{array}{l}\n\t\t\tx^{k+1}_1 = \\argmin\\limits_{x_1\\in\\R^{n_1}} f(x_1,x_2^k,...,x_p^k);\\\\\n\t\t\tx^{k+1}_2 = \\argmin\\limits_{x_2\\in\\R^{n_2}} f(x_1^{k+1},x_2,x_3^k...,x_p^k);\\\\\n\t\t\t\\cdots \\cdots\\\\\n\t\t\tx^{k+1}_p = \\argmin\\limits_{x_p\\in\\R^{n_p}} f(x_1^{k+1},...,x_{p-1}^{k+1},x_p).\n\t\t\\end{array}\n\t\t\\right.\n\t\\end{eqnarray*}\n\t}\n\t\\begin{itemize}\n\t\t\\item $x=(x_1\\zz,x_2\\zz,...,x_p\\zz)\\zz$, $x_i\\in\\R^{n_i}$ ($i=1,...,p$)\n\t\t\\item convergence under strongly convex\n\t\t\\item essentially \\clb{Gauss-Seidel} iteration: \\clg{\\small $f=\\frac{1}{2}x\\zz Ax -b\\zz x$ with $A\\succ 0$}\n\t\t\\footnote{This condition can be relaxed to $A\\succeq 0$, $A_{ii}\\succeq 0$ ($i=1,...,p$).}\n\t\t\\item \\clm{question: does Jacobi iteration work?} linear proximal variant:\n\t\t\\clr{$$\n\t\tx^{k+1}_i = \\argmin\\limits_{x_i\\in\\R^{n_i}} \\nabla_{x_i} f(x^k)\\zz x_i\n\t\t+ \\frac{\\beta^k}{2}||x_i-x_i^k||_2^2,\\quad i=1,...,p.\n\t\t$$}\n\t\\end{itemize}\n%\\end{frame}\n\n\n%********************* section ********************\n\\section{Global Optimization Strategies}\n\\iffalse\n\\begin{frame}\n\t\\begin{center}\n\t\t\\huge\\color{blue}\\bf\n\t\tSection 3. Global Optimization Strategies\n\t\\end{center}\n\\end{frame}\n\\fi\nGlobal optimization for non-convex function is a very difficult problem. We can only use it on some special problems. This section discuss a few strategies which try to solve this problem:\n\\subsection{Overview}\n%\\begin{frame}\n%\t\\frametitle{Overview}\n\t\\subsubsection{A few strategies}\n\t\\begin{itemize}\n\t\t\\item deterministic methods\\footnote{Combinatorial optimization\n\t\t\tcan be modeled as binary variable programming. Since $x\\in\\{0,1\\}\\,\\Leftrightarrow\\, x^2=x$,\n\t\t\tit can be viewed as a special nonlinear programming.}\n\t\t\\begin{itemize}\n\t\t\t\\item branch and bound\n\t\t\t\\item cutting plane\n\t\t\t\n\t\t\\end{itemize}\n\t\t\\item undeterministic methods\n\t\t\\begin{itemize}\n\t\t\t\\item homotopy\n\t\t\t\\item randomly multi-start\n\t\t\t\\item simulated annealing\n\t\t\t\\item {genetic algorithm}\n\t\t\t\\item {ant colony algorithm}\n\t\t\\end{itemize}\n\t\t\\item approximation methods\n\t\t\\begin{itemize}\n\t\t\t\\item \\clb{SDP relaxation:} $x\\zz Ax=\\langle A,xx\\zz \\rangle$,\\quad $xx\\zz \\Rightarrow X\\succeq 0$\n\t\t\\end{itemize}\n\t\t\\item problems have nice properties\n\t\t\\begin{itemize}\n\t\t\t\\item \\clg{special quartic objective: phase retrieval, matrix completion, ...}\n\t\t\t\\item \\clm{problem input obeys a certain distribution}\n\t\t\t\\item \\clm{no nonglobal local minimizer: stationary $\\Leftrightarrow$ global or saddle}\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n\n%**************************************************\n\\subsection{Undeterministic Methods}\n%\\begin{frame}\n%\t\\frametitle{Undeterministic Methods}\n\t\\subsubsection{Homotopy (Global continuation)}\n\t\\begin{itemize}\n\t\t\\item let \\clb{$g(x)$} be a convex relaxation\\footnote{Usually, it means that the epigraph of $g(x)$,\n\t\t\t$\\{(x,v)\\mid v\\geq f(x)  \\}$, completely contains the epigraph of $f(x)$.} of \\clr{$f(x)$}\n\t\t\\item define the homotopy function: \\clg{$F(x,t) :\\Rn\\times [0,1]\\mapsto \\R$}\n\t\t\\begin{itemize}\n\t\t\t\\item \\clr{$F(x,0)=f(x)$;}\\\\[1mm]\n\t\t\t\\item \\clb{$F(x,1)=g(x)$;}\\\\[1mm]\n\t\t\t\\item e.g. \\clg{$F(x,t)= (1-t)\\cdot f(x) + t\\cdot g(x)$.}\n\t\t\\end{itemize}\n\t\t\\item main idea -- solving\n\t\t\\clm{$$\\min\\limits_{x\\in\\Rn} \\quad F(x,t),$$}\n\t\twith \\clg{$t$} varying from \\clb{$1$} to \\clr{$0$}.\n\t\t\\item particularly useful for problems\n\t\t\\begin{itemize}\n\t\t\t\\item one main valley\n\t\t\t\\item surrounded by side valleys\n\t\t\t\\item side valleys occur by oscillation\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n%**************************************************\n%\\begin{frame}\n%\t\\frametitle{Undeterministic Methods (Cont'd)}\n\t\\subsubsection{Randomly multi-start}\n\t\\begin{itemize}\n\t\t\\item different with multi-start from grids or other patterns\n\t\t\\item main procedure\n\t\t\\begin{itemize}\n\t\t\t\\item[1.] input: $\\mbox{MaxL}\\in\\N$, $\\mbox{MaxW}\\in\\N$.\n\t\t\t\\item[2.] set $\\mbox{CL} :=0$, $\\mbox{CW} := 0$, \\clm{$x^{\\tiny\\mbox{rec}}:=0$,}\n\t\t\t\\clg{$f^{\\tiny\\mbox{rec}}=+\\infty$.}\n\t\t\t\\item[3.] certain \\clb{random sampling procedure:} obtain $x^{\\tiny\\mbox{sp}}$.\n\t\t\t\\item[4.] certain \\clr{local search procedure:} obtain $x^{\\tiny\\mbox{loc}}$,\n\t\t\t $\\mbox{CL}:=\\mbox{CL}+1$.\n\t\t\t\\item[5.] if $f(x^{\\tiny\\mbox{loc}})< f^{\\tiny\\mbox{rec}}$, set\n\t\t\t\t\\clm{$x^{\\tiny\\mbox{rec}} := x^{\\tiny\\mbox{loc}}$,} \\clg{$f^{\\tiny\\mbox{rec}}\n\t\t\t\t= f(x^{\\tiny\\mbox{loc}})$,} $\\mbox{CW} := 0$, goto 3.\n\t\t\t\\item[6.] otherwise, $\\mbox{CW}:=\\mbox{CW}+1$.\n\t\t\t\\item[7.] if $\\mbox{CL}=\\mbox{MaxL}$ or $\\mbox{CW}=\\mbox{MaxW}$, terminate\n\t\t\tand return \\clm{$x^{\\tiny\\mbox{rec}}$.}\n\t\t\t\\item[8.] otherwise, goto 3.\n\t\t\\end{itemize}\n\t\t\\item trade off between \\clb{sampling phase} and \\clr{local search phase}\n\t\t\\item convergence\n\t\t\\begin{itemize}\n\t\t\t\\item finding global minimizer in a compact domain\n\t\t\t\\item locally Lipschitz\n\t\t\t\\item \\clg{when $\\mbox{MaxL}\\rightarrow +\\infty$,} \\clm{probability approaches $1$}\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n%**************************************************\n%\\begin{frame}\n%\t\\frametitle{Undeterministic Methods (Cont'd)}\n\t\\subsubsection{Simulated annealing}\n\tThis method's inspiration comes from annealing in metallurgy.\n\t\\begin{itemize}\n\t\t\\item main framework\n\t\t\\begin{itemize}\n\t\t\t\\item[1.] input: initial temperature \\clg{$T\\gg 1$,} initial point \\clr{$x$,} $L\\in\\N$,\n\t\t\t$\\mbox{MaxW}\\in\\N$; set \\clm{$\\mbox{CW} := 0$,} $i:=0$.\\\\[1mm]\n\t\t\t\\item[2.] if $i=L$, goto Step 7; otherwise, goto Step 3.\\\\[1mm]\n\t\t\t\\item[3.] \\clb{find a new point $x'$} by certain simple procedure.\\\\[1mm]\n\t\t\t\\item[4.] evaluate the incremental $\\Delta':=f(x')-f(x)$.\\\\[1mm]\n\t\t\t\\item[5.] if $\\Delta'\\leq 0$, \\clr{$x:=x'$,} \\clm{$\\mbox{CW} = 0$;} else if, set\n\t\t\t\\clr{$x:=x'$,} \\clm{$\\mbox{CW} = 0$} in probability \\clb{$\\exp(-\\Delta'/(kT))$}\\footnote{$k$ takes Boltzmann constant.}; otherwise,\n\t\t\t\\clm{$\\mbox{CW}:=\\mbox{CW}+1$.}\\\\[1mm]\n\t\t\t\\item[6.] if \\clm{$\\mbox{CW}\\geq\\mbox{MaxW}$} and \\clg{$T=0$,} terminate; otherwise,\n\t\t\tset $i:=i+1$ and goto Step 2.\\\\[1mm]\n\t\t\t\\item[7.] \\clg{decrease temperature $T$ slowly,} set $i:=0$ and goto Step 2.\n\t\t\\end{itemize}\n\t\\end{itemize}\n%\\end{frame}\n\n", "meta": {"hexsha": "7b2a518e5668b9ab13513c45ddf3d7579e5d2d2c", "size": 29932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/UnconstrainedOptimizationProblemsXinLiu0324.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/UnconstrainedOptimizationProblemsXinLiu0324.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/UnconstrainedOptimizationProblemsXinLiu0324.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.002739726, "max_line_length": 277, "alphanum_fraction": 0.6336028331, "num_tokens": 11219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6657819386237279}}
{"text": "% !TEX root = ../main_lecture_notes.tex\n\\chapter{Efficiency of blockchain systems}\\label{chap:efficiency}\n\n\\section{A queueing model with bulk service}\\label{sec:queue}\nBlockchain users send transactions to the network of validators according to some rate $\\lambda$. These transactions enter a queue of pending transactions. The validators select a subset of $b$ transactions to be recorded in the next block. The block is built by a leader elected via a consensus protocol. The block is then communicated to the other validators and the $b$ transactions exit the queue. We assume that building a block takes some exponentially distributed time with mean $\\mu$. What we just described is exactly a single server with bulk service queueing system, described for instance in \\citet{Bailey1954} and \\citet{Chaudhry1981} with exponential arrival times, that processes $k$ items at a time, with an exponential service time. This a $M/M^b/1$ queue in Kendall's notation summarized in \\cref{fig:blockchain_queue}.  \n\\begin{figure}[!ht]\n\\begin{center}\n\\begin{tikzpicture}[-, >=stealth', auto, semithick, node distance=1cm]\n\n\\tikzstyle{phantom block}=[rectangle, fill=white,draw=white, thick,text=black,scale=2]\n\\tikzstyle{block}=[rectangle, fill=white,draw=black,thick,text=black,scale=4]\n\\tikzstyle{Intensity}=[circle, fill=white,draw=blue,very thick, text=black,scale=1.2]\n\\tikzstyle{transaction pending}=[circle, fill=white,draw=blue,very thick, text=black,scale=1]\n\\tikzstyle{transaction considered}=[circle, fill=blue, text=black, scale=1]\n\\node[Intensity]    (1){$\\lambda$};\n\\node[phantom block]  (2)[right of=1] {};\n\\node[transaction pending] (3)[right of=2] {};\n\\node[transaction pending] (4)[above of=3] {};\n\\node[transaction pending] (5)[above of=4] {};\n\\node[transaction pending] (6)[above of=5] {};\n\\node[transaction pending] (7)[below of=3] {};\n\\node[transaction pending] (8)[below of=7] {};\n\\path\n(1) edge[->,bend left]     node{} (4)\n    edge[->, bend right]     node{}          (7);\n\n\\node[Intensity]  (14)[above of=6]{$\\mu$};\n% \\path\n% (1) edge[->,bend left]     node{$\\text{Exp}(\\lambda)$}        (4)\n%     edge[->, bend right]     node{}          (7);\n\n\\node[transaction considered] (3)[right of=2] {};\n\\node[transaction considered] (4)[above of=3] {};\n\\node[transaction considered] (5)[above of=4] {};\n\\node[transaction considered] (6)[above of=5] {};\n\n\n\\node[phantom block]  (10)[right of=3] {};\n\\node[block]  (11)[right of=10] {};\n\\path\n(6) edge[->]   node{} (11)\n(5) edge[->]   node{} (11)\n(4) edge[->]   node{} (11)\n(3) edge[->]   node{} (11)\n;\n\\node[Intensity]  (12)[above of=11] {$\\mu$};\n\\node[phantom block]  (13)[above of=12] {};\n\n\\path\n(11) edge[-]     node{}        (12);\n\\path\n(12) edge[->]     node{}        (13);\n\n\\end{tikzpicture}\n\\end{center}\n\\caption{Blockchain queue}\n\\label{fig:blockchain_queue}\n\\end{figure}\nOne specificity of this queue is that the server is always busy. Our goal is to assess the efficiency which is characterized by\n\\begin{itemize}\n  \\item Throughputs: Number of transaction being processed per time unit\n  \\item Latency: Average transaction confirmation time\n\\end{itemize} \nThis can be done by studying the distribution of the number of pending transaction in the queue over the long run. A stationary state can only be reached if \n\\begin{equation}\\label{eq:stationarity_cond}\n\\mu \\cdot b > \\lambda.\n\\end{equation}\nDenote by $N^q$ the length of the queue upon stationarity, The following result holds.\n\\begin{theo}\nAssume that \\eqref{eq:stationarity_cond} holds then $N^q$ is geometrically distributed \n$$\n\\mathbb{P}(N^q = n) = (1-p)\\cdot p^n,\\text{ } n\\geq0\n$$\nwhere $p = 1/z^\\ast$ and $z^\\ast$ is the only root of \n$$\n-\\frac{\\lambda}{\\mu}z^{b+1}+z^b\\left(\\frac{\\lambda}{\\mu}+1\\right) - 1,\n$$\nsuch that $|z^\\ast$|>1.  \n\\end{theo}\n\\begin{proof}\nLet $N^q_t$ be the number of transactions in the queue at time $t\\geq0$ and $X_t$ the time elapsed since the last block was found. Further define\n\\[\nP_{n}(x,t)\\text{d}x  =\\mathbb{P}[N_t^q = n, X_t \\in(x, x + \\text{dx})] \n\\]\nIf $\\lambda < \\mu\\cdot b$ holds then the process admits a limiting distribution given by \n\\[\n\\underset{t\\rightarrow\\infty}{\\lim}P_{n}(x,t) = P_{n}(x).\n\\]\nAdding the variable $X_t$ is a known trick going back to \\citet{Cox1955}, it allows us to make the process $(N_t^q)_{t\\geq0}$ Markovian. We aim at finding the distribution of the queue length upon stationarity\n\\begin{equation}\\label{eq:alpha_n}\n\\mathbb{P}(N^q=n):=\\alpha_n =\\int_{0}^\\infty P_{n}(x)\\text{d}x, \\text{ }n\\geq0.\n\\end{equation}\nConsider the possible transitions over a small time lapse \\text{h} during which no block is being generated. Over this time interval, either \n\\begin{itemize}\n  \\item no transactions arrives\n  \\item one transaction arrives\n\\end{itemize}\nWe have for $n\\geq1$\n\\[\nP_{n}(x+h) = e^{-\\mu h}\\left[e^{-\\lambda h}P_{n}(x)+\\lambda h e^{-\\lambda h}P_{n-1}(x)\\right].\n\\]\nDifferentiating with respect to $h$ and letting $h\\rightarrow0$ leads to \n\\begin{equation}\\label{eq:diff_eq_n_geq_1}\nP_{n}'(x) = -(\\lambda+\\mu)P_{n}(x)+\\lambda P_{n-1}(x),\\text{ }n \\geq1.\n\\end{equation}\nSimilarly for $n = 0$, we have \n\\begin{equation}\\label{eq:diff_eq_n_eq_0}\nP_{0}'(x) = -(\\lambda+\\mu)P_{0}(x).\n\\end{equation}\nWe denote by \n$$\n\\xi(x)\\text{d}x =\\mathbb{P}(x\\leq X< x+\\text{d}x|X\\geq x)= \\mu\\text{d}x,\n$$\nthe hazard function of the block arrival time (constant as it is exponentially distributed). The system of differential equations \\eqref{eq:diff_eq_n_geq_1}, \\eqref{eq:diff_eq_n_eq_0} admits boundary conditions at $x = 0$ with \n\\begin{equation}\\label{eq:boundary_cond_1}\n\\begin{cases}\nP_{n}(0) = \\int_0^{+\\infty} P_{n+b}(x)\\xi(x)\\text{d}x = \\mu\\alpha_{n+b},&n \\geq1,\\\\\nP_{0}(0) = \\mu\\sum_{n=0}^{b}\\alpha_n,&n = 0,\\ldots,b\\\\\n\\end{cases}\n\\end{equation}\nDefine the probability generating function of $N^q$ at some elapsed service time $x\\geq 0$ as \n$$\nG(z;x) = \\sum_{n=0}^\\infty P_{n}(x)z^n.\n$$\nBy differentiating with respect to $x$, we get (using \\eqref{eq:diff_eq_n_geq_1} and \\eqref{eq:diff_eq_n_eq_0})\n$$\n\\frac{\\partial}{\\partial x}G(z;x) = -\\left[\\lambda(1-z)+\\mu\\right]G(z;x),\n$$\nand therefore\n$$\nG(z;x) = G(z;0)\\exp\\left\\{-\\left[\\lambda(1-z)+\\mu\\right]x\\right\\}.\n$$\nWe get the probability generating function of $N^q$ by integrating over $x$ as \n\\begin{equation}\\label{eq:G_z_solve_ODE}\nG(z) = \\frac{G(z;0)}{\\lambda(1-z)+\\mu}.\n\\end{equation}\nUsing the boundary conditions \\eqref{eq:boundary_cond_1}, we write \n\\begin{eqnarray}\nG(z;0) &= &\\sum_{n = 0}^\\infty P_{n}(0)z^n \\nonumber\\\\\n&= &P_{0}(0)+\\sum_{n=1}^{+\\infty}P_{n}(0)z^n\\nonumber\\\\\n&=& \\mu\\sum_{n = 0}^{b}\\alpha_n  + \\mu\\sum_{n=1}^{+\\infty}\\alpha_{n+b} z^n\\nonumber\\\\\n&=& \\mu\\sum_{n = 0}^{b}\\alpha_n + \\mu z^{-b}\\left[G(z)-\\sum_{n = 0}^{b}\\alpha_n z^n\\right]\\label{eq:G_z_0}\n\\end{eqnarray}\nReplacing the left hand side of \\eqref{eq:G_z_0} by \\eqref{eq:G_z_solve_ODE}, multiplying on both side by $z^b$ and rearranging yields \n\\begin{equation}\\label{eq:G_z_as_rational_function}\n\\frac{G(z)}{M(z)}[z^b - M(z)] =\\sum_{n=0}^{b-1}\\alpha_n(z^b - z^n), \n\\end{equation}\nwhere $M(z) = \\mu/(\\lambda(1-z)+\\mu)$. Using Rouche's theorem, we find that both side of the equation shares $b$ zeros inside the circle $\\mathcal{C} = \\{z\\in\\mathbb{C}\\text{ ; }|z| <1+\\epsilon\\}$ for some epsilon. \n\\begin{lemma}\nLet $\\mathcal{C}\\in \\mathbb{C}$ and $f$ and $g$ two holomorphic functions on $\\mathcal{C}$. Let $\\partial\\mathcal{C}$ be the contour of $\\partial\\mathcal{C}$. If \n$$\n|f(z)-g(z)|<|g(z)|\\text{, }\\forall z\\in\\partial\\mathcal{C}\n$$ \nthen $Z_f-P_f = Z_g-P_g$, where $Z_f$, $P_f$, $Z_g$, and $P_g$ are the number of zeros and poles of $f$ and $g$ respectively.\n\\end{lemma}\nWe have $\\partial\\mathcal{C} =\\{z\\in\\mathbb{C}\\text{ ; }|z| =1+\\epsilon\\}$. The left hand side can be rewritten as\n$$\nG(z)\\left[-\\frac{\\lambda}{\\mu}z^{b+1} + \\left(1 + \\frac{\\lambda}{\\mu}\\right)z^b -1\\right].\n$$\nDefine $f(z) = -\\frac{\\lambda}{\\mu}z^{b+1} + \\left(1 + \\frac{\\lambda}{\\mu}\\right)z^b -1$ and $g(z)=\\left(1 + \\frac{\\lambda}{\\mu}\\right)z^b$. We have \n $$\n|f(z) - g(z)| = |-\\frac{\\lambda}{\\mu}z^{b+1}-1|\\leq \\frac{\\lambda}{\\mu}(1+\\epsilon)^{b+1}+1< \\left(1 + \\frac{\\lambda}{\\mu}\\right)(1+\\epsilon)^b= |g(z)| ,\\text{ with }\\epsilon \\rightarrow 0. \n$$\nRegarding the right hand side, define $f(z) = \\sum_{n=0}^{b-1}\\alpha_n(z^b - z^n)$ and $g(z) =\\sum_{n=0}^{b-1}\\alpha_nz^b $. We have \n$$\n|f(z) - g(z)| < |\\sum_{n=0}^{b-1}\\alpha_n z^n| \\leq \\sum_{n=0}^{b-1}\\alpha_n (1+\\epsilon)^n<(1+\\epsilon)^b\\sum_{n=0}^{b-1}\\alpha_n = |g(z)|.\n$$\nWe deduce from Rouche's theorem that both sides have $b$ share roots inside $\\mathcal{C}$. Note that one of them is $1$, and we denote by $z_k$, $k = 1,\\ldots, b-1$ the remaining $b-1$ roots. Given the polynomial form of the right hand side of \\eqref{eq:G_z_as_rational_function}, the fundamental theorem of algebra indicates that the number of zero is $b$. Given the left hand side \n$$\nG(z)\\left[-\\frac{\\lambda}{\\mu}z^{b+1} + \\left(1 + \\frac{\\lambda}{\\mu}\\right)z^b -1\\right].\n$$\nwe deduce that there is one zeros outside $\\mathcal{C}$, we can further show that it is a real number $z^\\ast$. Multiplying both side of \\eqref{eq:G_z_as_rational_function} by $(z-1)\\prod_{k =1}^{b-1}(z-z_k)$, and using $G(1)=1$ yields\n$$\nG(z) = \\frac{1-z^\\ast}{z-z^{\\ast}}.\n$$\n$N^q$ is then a geometric random variable with parameter $p = \\frac{1}{z^\\ast}.$\n\\end{proof}\nThe result above can be found in \\citet{Bailey1954}. The application to blockchain under more general assumptions over the block discovery time is given in \\citet{Kawase2017}.\n\\section{Latency and throughputs computation}\\label{sec:latency_throughputs}\nThe practical computation of latency and throughputs then follow from a standard result in queueing, known as Little's law, see \\citet{Little1961}.\n\\begin{theo}\nConsider a stationary queueing system and denote by \n\\begin{itemize}\n  \\item $1/\\lambda$ the mean of the unit inter-arrival times\n  \\item $L$ be the mean number of units in the system\n  \\item $W$ be the mean time spent by units in the system\n\\end{itemize}\nWe have\n$$\nL = \\lambda \\cdot W\n$$\n\\end{theo}\n\\begin{itemize}\n  \\item Latency is the confirmation time of a transaction \n    $$\n    \\text{Latency} = W + \\frac{1}{\\mu} = \\frac{\\mathbb{E}(N^q)}{\\lambda} + \\frac{1}{\\mu} =  \\frac{p}{(1-p)\\lambda} + \\frac{1}{\\mu}.\n    $$\n  \\item Throughput is the number of transaction confirmed per time unit\n  $$\n    \\text{Throughput} = \\mu\\mathbb{E}(N^q\\mathbb{I}_{N^q\\leq b}+b\\mathbb{I}_{N^q> b}) = \\mu\\sum_{n = 0}^bn(1-p)p^n + bp^{b+1}.\n  $$\n\\end{itemize}\nAvenue for future research includes \n\\begin{itemize}\n\t\\item the inclusion of priority consideration, accounting for the transaction fee, see \\citet{Kawase2020}\n\t\\item Refine the hypothesis of the queueing system to better adapt to the different consensus protocol, see \\citet{Li2018} and \\citet{Li2019}.\n\\end{itemize}\n\\newpage", "meta": {"hexsha": "ac2fd30610c5bc85a3148029af79874582cd3338", "size": 10792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/includes/efficiency.tex", "max_stars_repo_name": "LaGauffre/BLOCKASTICS", "max_stars_repo_head_hexsha": "4087304a4fb6fe55b5e8746315f524eddedc72e8", "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": "lecture_notes/includes/efficiency.tex", "max_issues_repo_name": "LaGauffre/BLOCKASTICS", "max_issues_repo_head_hexsha": "4087304a4fb6fe55b5e8746315f524eddedc72e8", "max_issues_repo_licenses": ["CC0-1.0"], "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/includes/efficiency.tex", "max_forks_repo_name": "LaGauffre/BLOCKASTICS", "max_forks_repo_head_hexsha": "4087304a4fb6fe55b5e8746315f524eddedc72e8", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-21T08:20:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T08:20:38.000Z", "avg_line_length": 51.8846153846, "max_line_length": 839, "alphanum_fraction": 0.6785581913, "num_tokens": 3835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6657819347183325}}
{"text": "\\documentclass[letterpaper]{article}\n\\usepackage{pythontex}\n\\usepackage[]{amsmath}\n\\usepackage{amssymb}\n\\usepackage{acronym}\n\\usepackage[]{graphicx}\n\\usepackage[margin=1.2in]{geometry}\n\\graphicspath{{./pythontex-files-coloring_sat/}}\n\n\\acrodef{CNF}{Conjunctive Normal Form}\n\n\\let\\vel\\vee\n\\let\\at\\wedge\n\n\\title{Generating Closed Modular Colorings of Graphs Using a SAT Solver}\n\n\\author{Jan Hlavacek and Garry L.~Johns\\\\Saginaw Valley State University}\n\n\\begin{document}\n\\maketitle\n\\section{Introduction}\nWe start with a graph $G$.  To keep things simple, we will assume\nthat $G$ has no true twins.  We color all vertices with colors from $0$ to $k-1$.  Then we\ncalculate the closed modular coloring:  for each vertex you add the colors of\nall its neighbours, add it to its color, and assign that number mod $k$ as its\nnew color. \n\nA coloring is proper if no two adjacent vertices have the same color. \n\nWe are trying to see if it is possible to color a graph $G$ so that the\nresulting closed modular coloring is proper. \n\n\\section{Description using logic}\n\nWe will have $k$ colors, $0,1,\\cdots,k-1$.  We try to describe the condition of\nhaving a closed modular coloring using logic formulas, so we can\nuse a SAT-solver to find out if the condition is satisfiable for\nthe graph G. We will need to introduce a number of logical\nvariables and write a logic formula using these variables that\nwill be equivalent to $G$ having a proper closed modular coloring.\n\n\\subsection{Vertices}\n\n\\subsubsection{Coloring a vertex}\n\nFor each vertex $v$, there will be $k$ color variables $c_v^i$, $i =\n0,\\dots,k-1$.  Exactly one of those will be true at a time, since a vertex cannot\nhave more than one color:\n\\begin{gather}\n   c_v^1 \\vel c_v^2 \\vel c_v^3 \\vel \\dots \\vel c_v^k \\label{eq:colors1}\\\\\n   \\neg c_v^i \\vel \\neg c_v^j \\text{ for $i \\neq j$\\label{eq:colors2}}\n\\end{gather}\n\n\\subsubsection{Modular coloring}\n\nNow we need to figure out what will be the new color of the vertex in the\nmodular coloring.  That will depend on the neighbouring vertices, as well as on\nthe vertex itself.\n\nWe will take a list of all the neighbours of the vertex $v$, including the\nvertex $v$ itself, and go through all\nthe possible colorings of this list.  Each such coloring $C_s$ will be assigned\na variable $n_v^s$, that will be equivalent to all the neighbouring vertices\nhaving exactly the colors from $C_s$. \n\nFor example, if the list of neighbours of $v$ is $[v,w,y,x,z]$, then for coloring\n$C_s = [2,1,3,2,4]$ of those vertices the variable $n_v^s$ will satisfy\n\\begin{equation}\n n_v^s \\equiv c_v^2 \\at c_w^1 \\at c_y^3 \\at c_x^2 \\at c_z^4\n   \\label{eq:neighbours}\n\\end{equation}\n\nFor each color $j$, there will be possibly several colorings $C_{s_1}, C_{s_2},\n\\dots, C_{s_{t_j}}$ of the neighbouring vertices that will produce $j$ as the\nmodular coloring of the vertex $v$.  We introduce $k$ variables $m_v^j$ for $j\n= 1, 2, \\dots, k$, satisfying\n\\begin{equation}\n   m_v^j \\equiv n_v^{s_1} \\vel n_v^{s_2} \\vel \\cdots \\vel n_v^{s_{t_j}}\n   \\label{eq:modular}\n\\end{equation}\n\n\\subsection{Edges}\n\nThe rules for edges will be simple enough.  All we need to assure is that the\nresulting modular coloring is proper, that is for each edge $(v,w)$, the\nmodular coloring of the vertex $v$ is different than the modular coloring of\nthe vertex $w$.   That means that for each color $j = 0,\\dots,k-1$, $m_v^j$ and\n$m_w^j$ cannot be both true:\n\\begin{equation}\n   \\neg m_v^j \\vel \\neg m_w^j \\text{ for $j = 0,\\dots,k-1$}\n   \\label{eq:edge}\n\\end{equation}\n\n\\section{Translation to CNF}\n\nSatisfiability solvers typically require their input to be in the \\ac{CNF}, that is\na written as a conjunction of clauses, where each clause is a disjunction of\nsingle variables or their negations.  We see that equations \\eqref{eq:colors1},\n\\eqref{eq:colors2} and \\eqref{eq:edge} already are in \\ac{CNF}, while\n\\eqref{eq:neighbours} and \\eqref{eq:modular} need to be translated. \n\nThe formula $a \\equiv (b \\at c)$ can be translated into \\ac{CNF} as \n\\begin{equation}\n   \\left(c \\vee \\neg a\\right) \\wedge \\left(b \\vee \\neg a\\right) \\wedge \\left(a \\vee \\neg b \\vee \\neg c\\right)\n   \\label{eq:trans1}\n\\end{equation}\nwhile the formula $a \\equiv (b \\vel c)$ can be translated to \n\\begin{equation}\n   \\left(a \\vee \\neg c\\right) \\wedge \\left(a \\vee \\neg b\\right) \\wedge \\left(b \\vee c \\vee \\neg a\\right)\n   \\label{eq:trans2}\n\\end{equation}\n\nEquation \\eqref{eq:neighbours} will then translate to \n\\begin{gather}\n   \\label{eq:neighbour_trans_1} (c_v^2 \\vel \\neg n_v^s) \\at (c_w^1 \\vel \\neg n_v^s) \\at (c_y^3 \\vel \\neg\n   n_v^s) \\at (c_x^2 \\vel \\neg n_v^s) \\at (c_z^4 \\vel \\neg n_v^s)\\\\\n   \\label{eq:neighbour_trans_2} n_v^s \\vel \\neg c_v^2 \\vel \\neg c_w^1 \\vel \\neg c_y^3 \\vel \\neg\n   c_x^2 \\vel \\neg c_z^4\n\\end{gather}\nIn general, for each coloring $C_s$ of the neighbours of vertex $v$, we will have the conjunction of \n\\begin{equation}\n   c_w^j \\vel \\neg n_v^s\n   \\label{eq:general_neighbour_1}\n\\end{equation}\nwhere $w$ runs through all the neighbors of $v$, including $v$, and for each $w$, $j$ is the\ncolor of $w$ in the coloring $C_s$, with \n\\begin{equation}\n   n_v^s \\vel \\neg c_{w_1}^{j_1} \\vel \\neg c_{w_2}^{j_2} \\vel \\cdots\n   \\label{eq:general_neighbour_2}\n\\end{equation}\nwhere $w_i$ are all the neighbors of $v$, including $v$, and $j_i$ are their corresponding\ncolors in $C_s$. \n\nThe formula \\eqref{eq:modular} will translate to \n\\begin{gather}\n   \\label{eq:modular_general_1} m_v^j \\vel \\neg n_v^{s_i}\\\\\n   \\label{eq:modular_general_2} n_v^{s_1} \\vel n_v^{s_2} \\vel \\cdots \\vel\n   n_v^{s_{t_j}} \\vel \\neg m_v^j\n\\end{gather}\nwhere $j$ runs through all the colors $1$ to $k$, and $s_i$ runs through all\nindices $s$ such that the corresponding coloring $C_s$ of all the neighbours of\n$v$ will produce the modular coloring of $v$ with the color $j$. \n\n\\section{Implementation}\n\n\\subsection{Imports and Setup}\n\nWe will use the \\pyv|pycosat| module, which provides a Python interface to the\npicosat SAT solver.  We will also need few functions from the \\pyv|itertools|\nmodule. We will use the \\pyv|graph_tool| module to handle the graph\nstuff. \n\n\\begin{pyblock}\nimport pycosat\nfrom itertools import count, islice, product\nimport graph_tool as gt\n\\end{pyblock}\n\nThe \\pyv|pycosat| module requires variables to be represented by integers. Each\nvariable will have to be associated with a unique integer.  To keep track which\nintegers we already used, we will use the \\pyv|count()| function from\nthe \\pyv|itertools| module. \n\n\\subsection{Assigning Variables}\n\nGiven a graph, we will need to assign the initial variables for original colors\n($c_v^j$) and for colors of a modular coloring ($m_v^j$).  We need to create two property maps for the\ngiven graph, one for original colors, and one for the closed modular coloring.\nEach property will be a vector of integers of length $k$, where $k$ is the\nnumber of colors.  The following function will create and populate one such map\n\n\\begin{pyblock}\ndef assign_color_vars(g, no_of_colors, vars_generator):\n   \"\"\"\n   Create property map for graph g, containing variable numbers \n   for colors.\n\n   Args:\n      g: A graph\n      no_of_colors: the number of colors used for graph coloring.\n      vars_generator: generator that produces numbers for logical\n         variables, to be used in pycosat clauses.\n\n   Returns:\n      A vertex property map of 'vector<int>' type, filled with \n      numbers of pycosat variables corresponding to possible \n      colors for each vertex.\n   \"\"\"\n   colors_map = g.new_vertex_property(\"vector<int>\")\n   for v in g.vertices():\n      colors_map[v] = list(islice(vars_generator, no_of_colors))\n   return colors_map\n\\end{pyblock}\n\nWe will call this function twice for each graph, first time to generate\nvariable numbers for all $c_v^j$ variables, the second time to generate numbers\nfor all $m_v^j$ variables. \n\n\\subsection{Generating Clauses}\n\nNow we will write some functions that will generate clauses for the SAT solver.\nEach clause will be a list of positive or negative integers.  Positive number\nmeans that the variable with the number appear in the conjunction, while a\nnegative number means that the negation of the variable with the opposite\nnumber appears in the conjunction. \n\n\\subsubsection{Clauses from equations \\eqref{eq:colors1} and \\eqref{eq:colors2}}\n\nThese clauses are grouped by individual vertices.  We will write a function\nthat will receive a vertex and generate all these clauses for that vertex.  For\nthe equation \\eqref{eq:colors2}, we will only need the clauses for $j < i$,\nsince disjunction is commutative.\n\n\\begin{pyblock}\ndef vertex_color_clauses(v, color_map):\n   \"\"\"\n   Return a list of clauses dealing with individual vertex \n   initial color.\n\n   Args:\n      v: a graph vertex\n      color_map: a vertex property map that assigns variable \n      numbers to colors of individual vertices.\n\n   Returns:\n      A list of lists, each of them representing one clause.\n   \"\"\"\n   l = []\n   colors = color_map[v]\n   l.append(list(colors))\n   for i in range(1,len(colors)):\n      for j in range(i):\n         l.append([-colors[i],-colors[j]])\n   return l\n\\end{pyblock}\n\n\\subsubsection{Clauses from equation \\eqref{eq:edge}}\n\nThere will be a group of clauses for each edge, assuring that the resulting\nmodular coloring is proper.  The function will receive an edge, and return a\nlist of clauses. It will need the lists of modular coloring colors for each end\nof the edge, and create a list of clauses assuring that the colors on the ends\nof the edge are not the same.  \n\n\\begin{pyblock}\ndef edge_clauses(e, modular_color_map):\n   \"\"\"\n   Return a list of clauses assuring that the colors of the \n   modular coloring on the ends of the edge are different.\n\n   Args:\n      e: an edge of a graph\n      modular_color_map: a vertex property map that assigns \n      variable numbers to colors in modular coloring of \n      individual vertices.\n\n   Returns:\n      A list of lists, each of which correspond to one clause.\n   \"\"\"\n   l = []\n   mc1 = modular_color_map[e.source()]\n   mc2 = modular_color_map[e.target()]\n   for i,j in zip(mc1,mc2):\n      l.append([-i,-j])\n   return l\n\\end{pyblock}\n\n\\subsubsection{Clauses from equations \\eqref{eq:general_neighbour_1},\n\\eqref{eq:general_neighbour_2}, \\eqref{eq:modular_general_1} and\n\\eqref{eq:modular_general_2}}\n\nThis is the trickiest part.  For a given vertex $v$, we take the list of all\nthe neighbours of $v$, including $v$.  Then we will go through all the possible colorings of\nthis list, for each coloring we allocate a new variable, and make it equivalent\nto a conjunction of the vertex color variables corresponding to the colors in\nthe coloring.  At the same time, we will check what color would a modular\ncoloring produced by this coloring of neighbours of $v$ produce at $v$.   We\nwill add the variable we allocated to this coloring to a list of variables for\nthe obtained modular color. At the end we will go through all the modular color\nvariables for vertex $v$, and generate clauses that will make each equivalent\nto the disjunction of all the variables added to their lists.\n\nWe will start with two auxiliary functions.  Each will receive a variable\nnumber as the first argument, and a list of variable numbers as its second\nargument.  The first will generate clauses making the first variable equivalent\nto the conjunction of all the variables in the list, the second one will do the\nsame for a disjunction of all the variables on the list. \n\n\\begin{pyblock}\ndef equiv_to_conjunction(a,vars):\n   \"\"\"\n   Return a list of clauses that assure that the variable a is \n   equivalent to the conjunction of all the variables in the list \n   vars.\n\n   Args:\n      a: integer, a number of a variable\n      vars: a list of integers, each corresponding to a variable\n\n   Returns:\n      a list of lists of integers.  Each list of integers \n      corresponds to one clause.  The conjunction of all the \n      clauses will be a CNF version of the equivalence of the \n      variable a with the conjunction of variables in l.\n   \"\"\"\n   l = [[a] + [-b for b in vars]]\n   for b in vars:\n      l.append([b,-a])\n   return l\n\ndef equiv_to_disjunction(a,vars):\n   \"\"\"\n   Return a list of clauses that assure that the variable a is \n   equivalent to the disjunction of all the variables in the list \n   vars.\n\n   Args:\n      a: integer, a number of a variable\n      vars: a list of integers, each corresponding to a variable\n\n   Returns:\n      a list of lists of integers.  Each list of integers \n      corresponds to one clause.  The conjunction of all the \n      clauses will be a CNF version of the equivalence of the \n      variable a with the disjunction of variables in l.\n   \"\"\"\n   l = [[-a] + vars]\n   for b in vars:\n      l.append([-b,a])\n   return l\n\\end{pyblock}\n\nThe next function will receive a vertex $v$, and produce all the clauses from\nequations \\eqref{eq:general_neighbour_1}, \\eqref{eq:general_neighbour_2},\n\\eqref{eq:modular_general_1} and \\eqref{eq:modular_general_2}. \n\n\\begin{pyblock}\ndef modular_coloring_clauses(v,color_map,modular_color_map,\n                             vars_generator):\n   \"\"\"\n   Return the list of clauses that will assure that the colors in \n   the modular_coloring_map are created as a closed modular \n   coloring from the colors in the color_map.\n\n   Args:\n      v: a vertex of a graph\n      color_map: a vertex property map that assigns variable \n         numbers to colors of individual vertices.\n      modular_color_map: a vertex property map that assigns \n         variable numbers to colors in modular coloring of \n         individual vertices.\n      vars_generator: generator that produces numbers for logical\n         variables, to be used in pycosat clauses.\n\n   Returns:\n      A list of lists, each of which correspond to one clause.\n\n   Notes:\n      May allocate new pycosat variables using the vars_generator.\n   \"\"\"\n   modular_colors = list(modular_color_map[v])\n   k = len(modular_colors) # number of colors\n   m_lists = {m:[] for m in modular_colors}\n   neighbours = list(v.out_neighbours()) + [v]\n   colorings = product(range(k),repeat=len(neighbours))\n   l = []\n   for cs in colorings:\n      new_var = next(vars_generator)\n      modular_color = sum(cs) % k\n      m_lists[modular_colors[modular_color]] += [new_var]\n      neighbour_color_vars = []\n      for w,c in zip(neighbours,cs):\n         neighbour_color_vars.append(color_map[w][c])\n      l += equiv_to_conjunction(new_var,neighbour_color_vars)\n\n   for m,s in m_lists.items():\n      l += equiv_to_disjunction(m,s)\n\n   return l\n\\end{pyblock}\n\n\\subsubsection{Putting all clauses together}\n\nNow we need to put all the clause generating functions together. The following\nfunction will take a graph and a number of colors, and generate all the clauses\nfor the graph.  The result can then be fed directly to the pycosat solver. \n\nThe steps will be:\n\\begin{enumerate}\n   \\item Create a new variable generator.\n   \\item Assign color and modular color variables to all vertices.\n   \\item For each vertex:\n      \\begin{enumerate}\n         \\item Generate all the clauses for equations \\eqref{eq:colors1} and\n            \\eqref{eq:colors2}.\n         \\item Generate all the clauses for equations\n            \\eqref{eq:general_neighbour_1}, \n            \\eqref{eq:general_neighbour_2}, \n            \\eqref{eq:modular_general_1} and \n            \\eqref{eq:modular_general_2}.\n      \\end{enumerate}\n   \\item For each edge, generate all clauses for equation \\eqref{eq:edge}.\n   \\item Return a complete list of all the generated clauses.  Also return the\n      two vertex property maps, since we will need them to decode the result.\n\\end{enumerate}\n\n\\begin{pyblock}\ndef graph_clauses(g,num_of_colors):\n   \"\"\"\n   Return the complete lists of all the clauses describing \n   conditions for a proper closed modular coloring of g.\n\n   Args:\n      g: a graph_tool graph\n      num_of_colors: number of colors for the modular coloring\n\n   Returns: \n      a list of lists of integers: each list of integers\n      corresponds to a disjunction of variables or their\n      negations, and two vertex property maps containing \n      the colors for the original coloring and the corresponding \n      modular coloring.\n   \"\"\"\n   l = []\n   vars_generator = count(1)\n   color_map = assign_color_vars(g,num_of_colors,vars_generator)\n   modular_color_map = assign_color_vars(g,num_of_colors,\n                                         vars_generator)\n\n   for v in g.vertices():\n      l += vertex_color_clauses(v,color_map)\n      l += modular_coloring_clauses(v,color_map,modular_color_map,\n                                    vars_generator)\n\n   for e in g.edges():\n      l +=  edge_clauses(e, modular_color_map)\n\n   return l, color_map, modular_color_map\n\\end{pyblock}\n\n\\subsection{Making sense of the result}\n\nThe pycosat solver returns a long list of positive or negative integers, one\nfor each variable.  Each number corresponds to one variable, and is positive if\nthe corresponding variable is true, and negative if the variable is false.  We\nare only interested in the variables on the beginning, the ones that correspond\nto the color variables and modular color variables for each vertex. Out of\nthese, we only want to know, for each vertex, which of its color variables and\nwhich of its modular color variables has a positive number in the result. \n\nA safe way (see below for some ideas that could make things easier if we could\nrely on some assumptions) would be:\n\\begin{enumerate}\n   \\item Discard all negative entries from the list\n   \\item Create a set from the positive entries, to make lookup faster\n   \\item Iterate through vertices of the graph:\n      \\begin{enumerate}\n         \\item For each vertex, iterate through the colors, asking if each is\n            in the set, until you find one\n         \\item Do the same for modular colors\n      \\end{enumerate}\n   \\item For each vertex, remember the found color and modular color.\n\\end{enumerate}\n\nIf we could assume that:\n\\begin{itemize}\n   \\item Iteration through vertices of a graph always happens in the same\n      order. (that is probably true)\n   \\item The variables returned by pycosat solver always come ordered by\n      absolute value. (that is also probably true.  We could also sort the list\n      ourselves)\n   \\item The first (number of colors)*(number of vertices) variables correspond\n      to the colors, the next to modular colors (that is true, but it would be\n      too hackish to rely on it.  Changing one part of the code could\n      completely mess up the other part, introducing messy hard to detect\n      errors.)\n\\end{itemize}\nwe could simply discard all negative variables, zip together the first (number\nof vertices) of the remaining numbers with the vertices of the graph to get the\ncolors, and zip together the next (number of vertices) of the numbers with the\nvertices to get the modular coloring. \n\n\\begin{pyblock}\ndef extract_colors(g,vertex_map,result_list):\n   \"\"\"\n   Extract colors of each vertex from the result list.\n\n   Args:\n      g: a graph_tool graph\n      vertex_map: a vertex property map.  Each vertex has a list\n         of its color variables. Could be original color map or\n         modular map.\n      result_list: the list of variable values returned by the\n         pycosat solver.\n\n   Returns:\n      a new vertex property map: one integer for each vertex, the\n      color of the vertex in the coloring found by the solver.\n   \"\"\"\n   s = set(i for i in result_list if i > 0)\n   coloring = g.new_vertex_property('int')\n   for v in g.vertices():\n      for i,n in enumerate(vertex_map[v]):\n         if n in s:\n            coloring[v] = i\n            break\n\n   return coloring\n\\end{pyblock}\n\nWe will try to plot the graph to verify that the solver indeed found a coloring\nwith the right properties.  We can either use colors to show the original\ncoloring and numbers to show the modular coloring (default), or numbers to show\nthe original coloring and colors to show the modular coloring (set\n\\pyv|color_orig| to \\pyv|False|).  The default setting will make it easier to\nsee patterns in the original coloring that lead to a closed modular coloring,\nwhile the alternative setting will make it easier to quickly verify that the\nresulting coloring is indeed a proper closed modular coloring generated by the\noriginal coloring.\n\n\\begin{pyblock}\nfrom graph_tool.draw import graph_draw\n\ndef plot_graph(g,coloring,modular_coloring,\n               color_names,layout,\n               filename,size=(600,600),\n               color_orig=True):\n   fcolors = g.new_vertex_property('string')\n   labels = g.new_vertex_property('string')\n   if color_orig:\n      for v in g.vertices():\n         fcolors[v] = color_names[coloring[v]]\n         labels[v] = str(modular_coloring[v])\n   else:\n      for v in g.vertices():\n         fcolors[v] = color_names[modular_coloring[v]]\n         labels[v] = str(coloring[v])\n\n   graph_draw(g,vertex_fill_color=fcolors,\n              vertex_text=labels,\n              pos=layout,\n              output_size=size,\n              output=filename)\n\\end{pyblock}\n\n\\section{Check the coloring}\n\nJust to make sure, we will make an independent check if\n\\begin{enumerate}\n   \\item the produced coloring is indeed a closed modular coloring obtained\n      from the original coloring.\n   \\item the produced coloring is proper.\n\\end{enumerate}\n\nThese can be done the following way:\n\\begin{enumerate}\n   \\item Loop through vertices, calculating modular coloring and comparing it\n      with the assigned modular color.\n   \\item Loop through edges, making sure the two colors at the ends of the edge\n      are different. \n\\end{enumerate}\n\n\\begin{pyblock}\ndef is_modular(g,coloring,modular_coloring,k):\n   \"\"\"\n   Check if the coloring described by modular_coloring is really a\n   modular coloring. \n\n   Args:\n      g: a graph-tool graph\n      coloring: a vertex property map describing the original\n         coloring\n      modular_coloring: a vertex property map describing the\n         coloring that is tested for modularity\n      k: an integer, the number of colors available\n\n   Returns:\n      True if the coloring in modular_coloring is really modular,\n      False otherwise\n   \"\"\"\n   for v in g.vertices():\n      neighbours = list(v.out_neighbours()) + [v]\n      true_modular_color = sum(coloring[w] \n                               for w in neighbours) % k\n      if modular_coloring[v] != true_modular_color:\n         return False\n\n   return True\n\ndef is_proper(g,coloring):\n   \"\"\"\n   Check if the coloring of g described by coloring is proper\n\n   Args:\n      g: a graph-tool graph\n      coloring: a vertex property map describing a coloring of g\n\n   Return:\n      True if the coloring is proper, False otherwise\n   \"\"\"\n   for e in g.edges():\n      if coloring[e.source()] == coloring[e.target()]:\n         return False\n\n   return True\n\\end{pyblock}\n\n\\subsection{Test a given graph}\n\nNow we take the generated clauses and feed them into the\nSAT-solver.  Then we decode the result, and return a tuple whose\nfirst element will be \\pyv|True| if we found a solution, or\n\\pyv|False| if we did not. \n\nIn the case a solution was found, the second element will be the\nstring \\pyv|'SAT'|, and the third and fourth element will be the\noriginal coloring and the modular coloring, respectively. \n\nIf the solution was not found, the second element of the tuple\nwill be a string explaining what happened:\n\\begin{description}\n   \\item[UNSAT] the solver decided that there is no solution.\n   \\item[UNKNOWN] the solver was not able to find a solution, and\n      was not able to prove that there is none.\n   \\item[NOT MODULAR] the solver found a solution, but the\n      supposedly modular coloring returned by the solver is not a\n      closed modular coloring generated by the original coloring\n      returned by the solver. This should \\emph{never} happen!\n   \\item[NOT PROPER] the solver found a solution, but the\n      supposedly modular coloring returned by the solver is not a\n      proper. This should \\emph{never} happen!\n\\end{description}\n\n\\begin{pyblock}\ndef g_has_pcmc(g,k):\n   l, c_m, m_c_m = graph_clauses(g,k)\n   result = pycosat.solve(l)\n   \n   if (result == 'UNSAT') or (result == 'UNKNOWN'):\n      return (False,result)\n\n   coloring = extract_colors(g,c_m,result)\n   modular_coloring = extract_colors(g,m_c_m,result)\n\n   if not is_modular(g,coloring,modular_coloring,k):\n      return(False,'NOT MODULAR',coloring,modular_coloring)\n   if not is_proper(g,modular_coloring):\n      return(False,'NOT PROPER',coloring,modular_coloring)\n\n   return(True,'SAT',coloring,modular_coloring)\n\\end{pyblock}\n\n\\subsection{Iteration over all colorings}\n\nThe Pycosat solver makes it possible to iterate over all solutions, using the\n\\pyv|itersolve| function.  We will use this to attempt to find all colorings of\na given graph that produce a proper closed modular coloring.  For graphs that\nhave a large number of such colorings, this can be rather lengthy process, and,\nespecially for larger graphs, will require a large amount of memory.  We will\ntherefore provide an option to limit the number of coloring found.  We will\nalso provide an option to check if the resulting colorings are proper and\nclosed modular.\n\n\\begin{pyblock}\ndef g_all_pcmc(g,k,limit=0,check=True):\n   l, c_m, m_c_m = graph_clauses(g,k)\n   if limit==0:\n      results = list(pycosat.itersolve(l))\n   else:\n      results = list(islice(pycosat.itersolve(l),limit))\n   \n   colorings = [extract_colors(g,c_m,r) for r in results]\n   modular_colorings = [extract_colors(g,m_c_m,r) for r in results]\n\n   combined = zip(colorings, modular_colorings)\n\n   return [(c,m) for c,m in combined if (not check) or \n      (is_modular(g,c,m,k) and is_proper(g,m))]\n\\end{pyblock}\n\n\n\\section{Try it on $K_5$}\n\nSince $K_5$ has true twins, and since we do not check for true\ntwins, there will not be a proper modular coloring of $K_5$. \n\n\\begin{pyblock}\ng = gt.Graph(directed=False)\n\nvs = [g.add_vertex() for i in range(5)]\nfor v in vs:\n   for w in vs:\n      if v != w:\n         g.add_edge(v,w)\n\nres = g_has_pcmc(g,3)\n\nif not res[0]:\n   print(res[1])\nelse:\n   print('Modular coloring is proper')\n\\end{pyblock}\n\nThe result was \\printpythontex.\n\n\\section{Grid Graphs}\n\nWe will see if the solver can find closed modular colorings for\nsome grid graphs. \n\nWe will start by some imports and some code for properly laying\nout grid graphs. Grid graphs are available in graph-tool in the\n\\pyv|graph_tool.generation| module, and are called 'lattice'\ngraphs.  Automatic layout algorithms do not work well for them, so\nwe define our own layout.\n\\begin{pyblock}\nfrom graph_tool.generation import lattice  \n\ndef grid_layout(g,rows,cols):\n   grid_pos = g.new_vertex_property(\"vector<float>\")\n\n   for i in range(cols):\n      for j in range(rows):\n         grid_pos[g.vertex(rows*i + j)] = [i,j]\n\n   return grid_pos\n\\end{pyblock}\n\nThe following function will receive a list of pairs $(m,n)$ and an integer $k$,\nand return a dictionary containing, for each pair $(m,n)$, the result of\n\\pyv|g_has_pcmc| for the grid graph $G_{m,n}$. It will only return the Boolean\nresult and the string result, without the actual colorings. \n\\begin{pyblock}\ndef check_grids(pairs,k):\n   return {p:g_has_pcmc(lattice(p),k)[0:2] for p in pairs}\n\\end{pyblock}\n\nSince the graphs $G_{m,n}$ and $G_{n,m}$ are equivalent from our point of view,\nwe only need to check $G_{m,n}$ for $n\\le m$.  The following function will\ngenerate all such pairs:\n\\begin{pyblock}\ndef triangle(K):\n   return ((i,j) for i in range(2,K) for j in range(2,i+1))\n\\end{pyblock}\n\nThe following function will then check all the grid graphs $G_{m,n}$ for $2 \\le\nm,n < K$ (using the above mentioned symmetry), and print the results.\n\\begin{pyblock}\ndef check_all_grids(K,k):\n   def format_g(pair):\n      return '$G_{{{:d},{:d}}}$'.format(*pair)\n\n   results = check_grids(triangle(K),k)\n   graphs_without = [p for p in results if not results[p][0]]\n   if len(graphs_without) == 0:\n      print('All of the graphs have proper {:d}-modular coloring'.format(k))\n   else:\n      print('Proper {:d}-modular coloring not found for '.format(k) + \n         ', '.join(format(g) for g in sorted(graphs_without)))\n\\end{pyblock}\n\n\\subsection{$k = 3$}\n\nFirst we will look at grid graphs $G_{m,n}$ for $2 \\le m,n < 21$:\n\\begin{pyblock}\ncheck_all_grids(21,3)\n\\end{pyblock}\n\\printpythontex\n\n\\subsection{$k = 2$}\n\nNow we will try with $k=2$:\n\\begin{pyblock}\ncheck_all_grids(21,2)\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{All Colorings for $3\\times m$}\nWe will look at coloring by 2 colors for $3\\times m$ graphs.\n\n\\begin{pyblock}\ndef all_for_grid(m,n,k,color_names=['black','white']):\n   g = lattice([m,n])\n   results = g_all_pcmc(g,k)\n   print('There are {} proper closed modular colorings mod {} for the graph $G_{{{:d},{:d}}}$.'.format(len(results),k,m,n))\n\n   for i,r in enumerate(results):\n      filename = 'grid_{:d}_{:d}_{:d}_{:d}.pdf'.format(m,n,k,i)\n      plot_graph(g,r[0],r[1],\n                    color_names,\n                    grid_layout(g,m,n),\n                    filename,size=(50*(n-1),50*m))\n      frm = 'width=\\\\linewidth' if n > 10 else ''\n      print('\\n\\n\\\\includegraphics[' + frm + ']{' + filename + '}\\n\\n')\n\\end{pyblock}\n\n\\printpythontex\n\n\\begin{pyblock}\nfor n in range(2,21):\n   print('\\n\\\\subsection{{Colorings for $G_{{3,{:d}}}$}}'.format(n))\n   all_for_grid(3,n,2)\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{All Colorings for $4\\times m$}\nThe same code can be used to generate all coloring by 2 colors for $4\\times m$ graphs, \nfor $m \\le 20$:\n\n\\begin{pyblock}\nfor n in range(2,21):\n   print('\\n\\\\subsection{{Colorings for $G_{{4,{:d}}}$}}'.format(n))\n   all_for_grid(4,n,2)\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{All Colorings for $5\\times m$}\nThe same code can be used to generate all coloring by 2 colors for $5\\times m$ graphs, \nfor $m \\le 40$:\n\n\\begin{pyblock}\nfor n in range(2,41):\n   print('\\n\\\\subsection{{Colorings for $G_{{5,{:d}}}$}}'.format(n))\n   all_for_grid(5,n,2)\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{All Colorings for $6\\times m$}\nThe same code can be used to generate all coloring by 2 colors for $6\\times m$ graphs, \nfor $m \\le 40$:\n\n\\begin{pyblock}\nfor n in range(2,41):\n   print('\\n\\\\subsection{{Colorings for $G_{{6,{:d}}}$}}'.format(n))\n   all_for_grid(6,n,2)\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{A Matrix}\n\nNext we will calculate how many closed 2-modular colorings are there for grid\ngraphs $G_{m,n}$ for $2 \\le m,n < 18$.  Since the calculation is very long for\ngraphs that have large number of such colorings, we will stop after finding 33\ncolorings for each graph.  We will list these as ``$>32$'' in the table. \n\n\\begin{pyblock}\nk = 2\nL = 18\nM = [[0]*(L-2) for i in range(2,L)]\nfor m in range(2,L):\n   for n in range(2,m+1):\n      g = lattice([m,n])\n      l, c_m, m_c_m = graph_clauses(g,k)\n      M[m-2][n-2] = len(list(islice(pycosat.itersolve(l),33)))\n      M[n-2][m-2] = M[m-2][n-2]\n\\end{pyblock}\n\n\\begin{pyblock}\nprint('\\\\begin{tabular}{r|' + 'c'*(L-2) + '}\\n')\nprint('&' + '&'.join(str(i) for i in range(2,L)) + '\\\\\\\\\\\\hline\\n')\nfor i,R in enumerate(M):\n   print(str(i+2) + '&' + '&'.join(str(j) if j < 33 else '$>32$' for j in R) + '\\\\\\\\\\n')\nprint('\\\\end{tabular}')\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{All Colorings for $10\\times m$}\n\n\\begin{pyblock}\nfor n in range(2,41):\n   print('\\n\\\\subsection{{Colorings for $G_{{10,{:d}}}$}}'.format(n))\n   all_for_grid(10,n,2)\n\\end{pyblock}\n\n\\printpythontex\n\n\\subsection{All Colorings for $14\\times m$}\n\n\\begin{pyblock}\nfor n in range(2,41):\n   print('\\n\\\\subsection{{Colorings for $G_{{14,{:d}}}$}}'.format(n))\n   all_for_grid(14,n,2)\n\\end{pyblock}\n\n\\printpythontex\n\\end{document}\n", "meta": {"hexsha": "317e6b67a3c62daae03ef6d228d5f52de8740fa3", "size": 31621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "coloring_sat.tex", "max_stars_repo_name": "lahvak/close_mod_sat", "max_stars_repo_head_hexsha": "eed6001873a2cd77333b6745db9d2658ac94aeb4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "coloring_sat.tex", "max_issues_repo_name": "lahvak/close_mod_sat", "max_issues_repo_head_hexsha": "eed6001873a2cd77333b6745db9d2658ac94aeb4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "coloring_sat.tex", "max_forks_repo_name": "lahvak/close_mod_sat", "max_forks_repo_head_hexsha": "eed6001873a2cd77333b6745db9d2658ac94aeb4", "max_forks_repo_licenses": ["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.4098544233, "max_line_length": 123, "alphanum_fraction": 0.7058284052, "num_tokens": 8635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6657819340436981}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 1.1 Verify symmetry of $\\Gamma^{a}{}_{bc}$}\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   g_{a b}::Metric.\n\n   \\partial{#}::PartialDerivative.\n\n   Gamma := \\Gamma^{a}_{b c} -> (1/2) g^{a d} (  \\partial_{b}{g_{d c}}\n                                               + \\partial_{c}{g_{b d}}\n                                               - \\partial_{d}{g_{b c}} ).\n\n   diff := \\Gamma^{a}_{b c} - \\Gamma^{a}_{c b}.   # cdb (ex-0101.101,diff)\n\n   substitute    (diff, Gamma)                    # cdb (ex-0101.102,diff)\n   distribute    (diff)                           # cdb (ex-0101.103,diff)\n   canonicalise  (diff)                           # cdb (ex-0101.104,diff)\n\\end{cadabra}\n\n\\begin{align*}\n   \\cdb{ex-0101.101} &= \\cdb{ex-0101.102}\\\\\n                     &= \\cdb{ex-0101.103}\\\\\n                     &= \\cdb{ex-0101.104}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "7b6012043a8664cbe90dabfa5fe708f8203c23ab", "size": 1111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0101.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-0101.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-0101.tex", "max_forks_repo_name": "leo-brewin/cadabra-tutorial", "max_forks_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-22T13:52:19.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-22T13:52:19.000Z", "avg_line_length": 30.8611111111, "max_line_length": 94, "alphanum_fraction": 0.4374437444, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.6657819305573239}}
{"text": "\\section{Second Order Linear Equations - Method of Undetermined Coefficients}{}{}\\label{sec:second order linear equations}\nNow we consider second order equations of the form $\\ds ay''+by'+cy=f(t)$,\nwith $a$, $b$, and $c$ constant. Of course, if $a=0$ this\nis really a first order equation, so we assume $a\\not=0$.\n%Also, much\n%as in exercise~\\xrefn{exer:second order really first order} of\n%section~\\xrefn{sec:second order homogeneous}, \nAlso, if $c=0$ we can solve\nthe related first order equation $\\ds ah'+bh=f(t)$, and then solve\n$\\ds h=y'$ for $y$. So we will only examine examples in which\n$c\\not=0$.\n\nSuppose that\n$\\ds y_1(t)$ and $\\ds y_2(t)$ are solutions to $\\ds ay''+by'+cy=f(t)$,\nand consider the function $\\ds h=y_1-y_2$. We substitute\nthis function into the left hand side of the differential equation and\nsimplify: \n$$\na(y_1-y_2)''+b(y_1-y_2)'+c(y_1-y_2)=ay_1''+by_1'+cy_1 -\n(ay_2''+by_2'+cy_2)=f(t)-f(t)=0.\n$$ \nSo $h$ is a solution to the homogeneous equation $\\ds ay''+by'+cy=0$.\nSince we know how to find all such $h$, then with\njust one particular solution $\\ds y_2$ we can express all possible\nsolutions $\\ds y_1$, namely, $\\ds y_1=h+y_2$, where now $h$ is the\ngeneral solution to the homogeneous equation. Of course, this is\nexactly how we approached the first order linear equation.\n\nTo make use of this observation we need a method to find a single\nsolution $y_2$. This turns out to be somewhat more difficult than the\nfirst order case, but if $f(t)$ is of a certain simple form, we can\nfind a solution using the \n\\dfont{method of undetermined coefficients}, sometimes \nmore whimsically called the\n\\dfont{method of judicious guessing}.\n\n\\begin{example}{Second Order Linear Equation}{Second Order Linear Equation 1}\\label{Second Order Linear Equation 1}\n Solve the differential equation \n$y''-y'-6y=18t^2+5.$\n\\end{example}\n\n\\begin{solution}\nThe general solution of the homogeneous equation is\n$\\ds Ae^{3t}+Be^{-2t}$. We guess that a solution to the\nnon-homogeneous equation might look like $f(t)$ itself, namely,\na quadratic $\\ds y=at^2+bt+c$. Substituting this guess into the\ndifferential equation we get\n$$\ny''-y'-6y = 2a-(2at+b)-6(at^2+bt+c) = -6at^2+(-2a-6b)t+(2a-b-6c).\n$$\nWe want this to equal $18t^2+5$, so we need \n\\begin{eqnarray*}\n-6a&=&18\\cr\n-2a-6b&=&0\\cr\n2a-b-6c&=&5\n\\end{eqnarray*}\nThis is a system of three equations in three unknowns and is not hard\nto solve: $a=-3$, $b=1$, $c=-2$. Thus the general solution to the\ndifferential equation is $\\ds Ae^{3t}+Be^{-2t}-3t^2+t-2$.\n\\end{solution}\n\nSo the ``judicious guess'' is a function with the same form as $f(t)$\nbut with undetermined (or better, yet to be determined)\ncoefficients. This works whenever $f(t)$ is a polynomial.\n\n\\begin{example}{Mass-Spring System with No Damping}{Mass-Spring System with No Damping}\\label{Mass-Spring System with No Damping}\nAnalyze the initial value problem $\\ds my'' +ky=-mg$,\n$y(0)=2$, $\\ds y'(0)=50$.\n\\end{example}\n\n\\begin{solution}\nThe left hand side represents a mass-spring\nsystem with no damping, i.e., $b=0$. Unlike the homogeneous case, we\nnow consider the force due to gravity, $-mg$, assuming the spring is\nvertical at the surface of the earth, so that $g=980$. To be specific,\nlet us take $m=1$ and $k=100$. The general solution to the homogeneous\nequation is $\\ds A\\cos(10t)+B\\sin(10t)$. For the solution to the \nnon-homogeneous equation we guess simply a constant $y=a$, since $-mg=-980$\nis a constant. Then $\\ds y''+100y= 100a$ so $a=-980/100=-9.8$. The\ndesired general solution is then $\\ds A\\cos(10t)+B\\sin(10t)-9.8$.\nSubstituting the initial conditions we get\n\\begin{eqnarray*}\n2&=&A-9.8\\cr\n50&=&10B\n\\end{eqnarray*}\nso $A=11.8$ and $B=5$ and the solution is $\\ds 11.8\\cos(10t)+5\\sin(10t)-9.8$.\n\\end{solution}\n\nMore generally, this method can be used when a function similar to\n$f(t)$ has derivatives that are also similar to $f(t)$; in the\nexamples so far, since $f(t)$ was a polynomial, so were its derivatives.\nThe method will work if $f(t)$ has the form $p(t)e^{\\alpha t}\\cos(\\beta t)+\nq(t)e^{\\alpha t}\\sin(\\beta t)$, where $p(t)$ and $q(t)$ are\npolynomials; when $\\alpha=\\beta=0$ this is simply $p(t)$, a\npolynomial. In the most general form it is not simple to describe the\nappropriate judicious guess; we content ourselves with some examples\nto illustrate the process.\n\n\\begin{example}{Solving a Second Order Linear Equation}{Solving a Second Order Linear Equation 2}\\label{Solving a Second Order Linear Equation 2}\n Find the general solution to $\\ds y''+7y'+10y=e^{3t}.$\n\\end{example}\n\n\\begin{solution}\nThe characteristic equation is $r^2+7r+10=(r+5)(r+2)$,\nso the solution to the homogeneous equation is\n$Ae^{-5t}+Be^{-2t}$. For a particular solution to the inhomogeneous\nequation we guess $Ce^{3t}$. Substituting we get\n$$\n9Ce^{3t}+21Ce^{3t}+10Ce^{3t}=e^{3t}40C.\n$$\nWhen $C=1/40$ this is equal to $f(t)=e^{3t}$, so the solution is\n$Ae^{-5t}+Be^{-2t}+(1/40)e^{3t}$.\n\\end{solution}\n\n\\begin{example}{Solving a Second Order Linear Equation}{Solving a Second Order Linear Equation 3}\\label{Solving a Second Order Linear Equation 3}\n Find the general solution to \n$\\ds y''+7y'+10y=e^{-2t}.$\n\\end{example}\n\n\\begin{solution}\nFollowing the last example we might guess\n$Ce^{-2t}$, but since this is a solution to the homogeneous equation\nit cannot work. Instead we guess $Cte^{-2t}$. Then\n$$\n(-2Ce^{-2t}-2Ce^{-2t}+4Cte^{-2t})+7(Ce^{-2t}-2Cte^{-2t})+10Cte^{-2t}\n=e^{-2t}(-3C).\n$$\nThen $C=-1/3$ and the solution is $Ae^{-5t}+Be^{-2t}-(1/3)te^{-2t}$.\n\\end{solution}\n\nIn general, if $f(t)=e^{kt}$ and $k$ is one of the roots of the\ncharacteristic equation, then we guess $Cte^{kt}$ instead of\n$Ce^{kt}$. If $k$ is the only root of the characteristic equation,\nthen $Cte^{kt}$ will also not work, so we must guess $Ct^2e^{kt}$.\n\n\\begin{example}{Solving a Second Order Linear Equation}{Solving a Second Order Linear Equation 4}\\label{Solving a Second Order Linear Equation 4}\n Find the general solution to \n$\\ds y''-6y'+9y=e^{3t}.$\n\\end{example}\n\n\\begin{solution}\nThe characteristic equation is \n$\\ds r^2-6r+9=(r-3)^2$, so the general solution to the homogeneous\nequation is $Ae^{3t}+Bte^{3t}$. Guessing $Ct^2e^{3t}$ for the\nparticular solution, we get\n$$\n(9Ct^2e^{3t}+6Cte^{3t}+6Cte^{3t}+2Ce^{3t})-6(3Ct^2e^{3t}+2Cte^{3t})+9Ct^2e^{3t}\n=e^{3t}2C.\n$$\nThus, the solution is $\\ds Ae^{3t}+Bte^{3t}+(1/2)t^2e^{3t}$.\n\\end{solution}\n\nIt is common in various physical systems to encounter an $f(t)$ of the\nform $\\ds a\\cos(\\omega t)+b\\sin(\\omega t)$.\n\n\\begin{example}{Solving a Second Order Linear Equation}{Solving a Second Order Linear Equation 5}\\label{Solving a Second Order Linear Equation 5}\n Find the general solution to \n$\\ds y''+6y'+25y=\\cos(4t).$\n\\end{example}\n\n\\begin{solution}\nThe roots of the characteristic equation are\n$-3\\pm 4i$, so the solution to the homogeneous equation is\n$\\ds e^{-3t}(A\\cos(4t)+B\\sin(4t))$. For a particular solution, we\nguess $C\\cos(4t)+D\\sin(4t)$. Substituting as usual:\n$$(-16C\\cos(4t)+-16D\\sin(4t))+6(-4C\\sin(4t)+4D\\cos(4t))+25(C\\cos(4t)+D\\sin(4t))$$\n$$=(24D+9C)\\cos(4t)+(-24C+9D)\\sin(4t).$$\nTo make this equal to $\\cos(4t)$ we need\n\\begin{eqnarray*}\n24D+9C&=&1\\cr\n9D-24C&=&0\n\\end{eqnarray*}\nwhich gives $C=1/73$ and $D=8/219$. The full solution is then\n$\\ds e^{-3t}(A\\cos(4t)+B\\sin(4t))+(1/73)\\cos(4t)+(8/219)\\sin(4t)$.\n\nThe function $\\ds e^{-3t}(A\\cos(4t)+B\\sin(4t))$ is a damped\noscillation as in example~\\ref{Mass-Spring System with No Damping},\nwhile $\\ds(1/73)\\cos(4t)+(8/219)\\sin(4t)$ is a simple undamped\noscillation. As $t$ increases, the sum $\\ds\ne^{-3t}(A\\cos(4t)+B\\sin(4t))$ approaches zero, so the solution\n$$e^{-3t}(A\\cos(4t)+B\\sin(4t))+(1/73)\\cos(4t)+(8/219)\\sin(4t)$$\nbecomes more and more like the simple oscillation\n$\\ds(1/73)\\cos(4t)+(8/219)\\sin(4t)$---notice that the initial\nconditions don't matter to this long term behavior. The damped portion\nis called the \n\\dfont{transient} [part of the]\n\\dfont{solution}, and the simple oscillation is called the \n\\dfont{steady state} [part of the] \\dfont{solution}. \nA physical example is a mass-spring system. If the only force on the\nmass is due to the spring, then the behavior of the system is a damped\noscillation. If in addition an external force is applied to the mass,\nand if the force varies according to a function of the form\n $\\ds a\\cos(\\omega t)+b\\sin(\\omega t)$, then the long term behavior\nwill be a simple oscillation determined by the steady state portion of the\ngeneral solution; the initial position of the mass will not matter.\n\\end{solution}\n\nAs with the exponential form, such a simple guess may not work.\n\n\\begin{example}{Solving a Second Order Linear Equation}{Solving a Second Order Linear Equation 6}\\label{Solving a Second Order Linear Equation 6}\n Find the general solution to $\\ds y''+16y=-\\sin(4t).$\n\\end{example}\n\n\\begin{solution}\nThe roots of the characteristic equation are $\\pm4i$, so the\nsolution to the homogeneous equation is $A\\cos(4t)+B\\sin(4t)$. Since\nboth $\\cos(4t)$ and $\\sin(4t)$ are solutions to the homogeneous\nequation,  $C\\cos(4t)+D\\sin(4t)$ is also, so it cannot be a solution\nto the non-homogeneous equation. Instead, we guess\n$Ct\\cos(4t)+Dt\\sin(4t)$. Then substituting:\n$$(-16Ct\\cos(4t)-16D\\sin(4t)+8D\\cos(4t)-8C\\sin(4t)))+16(Ct\\cos(4t)+Dt\\sin(4t))$$\n$$=8D\\cos(4t)-8C\\sin(4t).$$\nThus $C=1/8$, $D=0$, and the solution is\n$\\ds C\\cos(4t)+D\\sin(4t)+(1/8)t\\cos(4t)$.\n\\end{solution}\n\nIn general, if $f(t)=a\\cos(\\omega t)+b\\sin(\\omega t)$, and $\\pm \\omega\ni$ are the roots of the characteristic equation, then instead of \n$C\\cos(\\omega t)+D\\sin(\\omega t)$ we guess $Ct\\cos(\\omega t)+Dt\\sin(\\omega t)$.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:second order linear equations}}\n\n\\begin{enumialphparenastyle}\n\nFind the general solution to the differential equation.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'' -10y'+25y=\\cos t$\n\\begin{sol}\n $Ae^{5t}+Bte^{5t}+(6/169)\\cos t-(5/338)\\sin t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+2\\sqrt2y'+2y=10$\n\\begin{sol}\n $\\ds Ae^{-\\sqrt2t}+Bte^{-\\sqrt2t}+5$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+16y=8t^2+3t-4$\n\\begin{sol}\n $\\ds A\\cos(4t)+B\\sin(4t)+ (1/2)t^2+(3/16)t-5/16$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+2y=\\cos(5t)+\\sin(5t)$\n\\begin{sol}\n $\\ds A\\cos(\\sqrt2t)+B\\sin(\\sqrt2t)-(\\cos(5t)+\\sin(5t))/23$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-2y'+2y=e^{2t}$\n\\begin{sol}\n $\\ds e^{t}(A\\cos t+B\\sin t)+e^{2t}/2$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-6y+13=1+2t+e^{-t}$\n\\begin{sol}\n $\\ds Ae^{\\sqrt6t}+Be^{-\\sqrt6t}+2-t/3-e^{-t}/5$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+y'-6y=e^{-3t}$\n\\begin{sol}\n $\\ds Ae^{-3t}+Be^{2t}-(1/5)te^{-3t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-4y'+3y=e^{3t}$\n\\begin{sol}\n $\\ds Ae^t+Be^{3t}+(1/2)te^{3t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+16y=\\cos(4t)$\n\\begin{sol}\n $\\ds A\\cos(4t)+B\\sin(4t)+(1/8)t\\sin(4t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'' +9y=3\\sin(3t)$\n\\begin{sol}\n $\\ds A\\cos(3t)+B\\sin(3t)-(1/2)t\\cos(3t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+12y'+36y=6e^{-6t}$\n\\begin{sol}\n $\\ds Ae^{-6t}+Bte^{-6t}+3t^2e^{-6t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-8y'+16y=-2e^{4t}$\n\\begin{sol}\n $\\ds Ae^{4t}+Bte^{4t}-t^2e^{4t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+6y'+5y=4$\n\\begin{sol}\n $\\ds Ae^{-t}+Be^{-5t}+(4/5)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-y'-12y=t$\n\\begin{sol}\n $\\ds Ae^{4t}+Be^{-3t}+(1/144)-(t/12)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+5y=8\\sin(2t)$\n\\begin{sol}\n $\\ds A\\cos(\\sqrt5t)+B\\sin(\\sqrt5t)+8\\sin(2t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-4y=4e^{2t}$\n\\begin{sol}\n $\\ds Ae^{2t}+Be^{-2t}+te^{2t}$\n\\end{sol}\n\\end{ex}\n\n\n\\noindent Solve the initial value problem.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''-y=3t+5$, $y(0)=0$, $\\ds y'(0)=0$\n\\begin{sol}\n $\\ds 4e^{t}+e^{-t}-3t-5$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+9y=4t$, $y(0)=0$, $\\ds y'(0)=0$\n\\begin{sol}\n $\\ds -(4/27)\\sin(3t)+(4/9)t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'' +12y' +37y=10e^{-4t}$, $y(0)=4$, $\\ds y'(0)=0$\n\\begin{sol}\n $\\ds e^{-6t}(2\\cos t+20\\sin t)+2e^{-4t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y''+6y'+18y=\\cos t-\\sin t$, $y(0)=0$, $\\ds y'(0)=2$ \n\\begin{sol}\n $\\ds\n\\left(-{23\\over 325}\\cos(3t)+{592\\over 975}\\sin(3t)\\right)+\n{23\\over325}\\cos t-{11\\over325}\\sin t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Find the solution for the mass-spring equation\n$\\ds y''+4y'+29y=689\\cos(2t)$.\n\\begin{sol}\n $\\ds e^{-2t}(A\\sin(5t)+B\\cos(5t))+8\\sin(2t)+25\\cos(2t)$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Find the solution for the mass-spring equation\n$\\ds3y''+12y'+24y=2\\sin t$.\n\\begin{sol}\n $\\ds e^{-2t}(A\\sin(2t)+B\\cos(2t))+(14/195)\\sin t-(8/195)\\cos t$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the differential \nequation $\\ds my''+by'+ky=\\cos(\\omega t)$,\nwith $m$, $b$, and $k$ all positive and $\\ds b^2<2mk$; this equation\nis a model for a damped mass-spring system with external \ndriving force $\\cos(\\omega t)$.\nShow that the steady state part of the solution has amplitude\n$${1\\over \\sqrt{(k-m\\omega^2)^2+\\omega^2b^2}}.$$\nShow that this amplitude is largest when \n$\\ds \\omega={\\sqrt{4mk-2b^2}\\over 2m}$. This is the \n\\dfont{resonant frequency} of the system.\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "bb81062b91b39bd99d6e2b5dca22f40db03d57b8", "size": 13338, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-6-second-order-linear-undetermined-coefficients.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-6-second-order-linear-undetermined-coefficients.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-6-second-order-linear-undetermined-coefficients.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7723214286, "max_line_length": 145, "alphanum_fraction": 0.6533213375, "num_tokens": 5055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.8688267762381843, "lm_q1q2_score": 0.6657764355741883}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{fullpage,latexsym,amsmath,graphicx}\n\\setlength{\\textheight}{25cm}\n\\pagestyle{empty}\n\\title{on random hex (draft)}\n\\author{RBH etc}\n\\date{April 2013}\n\\begin{document}\n\\maketitle\n\\section{intro}\nConsider a game of random Hex on an $n$$\\times$$n$ board.\nBlack and White alternate moves, and the first player to connect their two opposing sides wins. Each move is uniformly randomly selected\nfrom the set of all available moves (i.e., empty cells) at that point.\nFor each player, and for each positive integer $t$,\nwe are interested in $w_n^t$, the probability that the player wins the game with their $t$'th move.\n\nHex on an $n$$\\times$$n$ board has certain symmetries that simplify the computation of $w$.\n\nDefine $f_n^t$ as the probability that, \na uniformly randomly chosen\n$t$-subset of the $n$$\\times$$n$ cell locations yields a winning configuration\nfor a fixed player --- say Black.\nBy the symmetry of the $n$$\\times$$n$ board, and since \neach filled board yields a win for exactly one player (draws are not possible in Hex),\nthere is a bijection between $t$-subsets that\nyield a win for Black and $t$-subsets that yield a win for White.\nThus $f_n^t$ is the same for each player.\n\nSince each move is uniform random, \n$f_n^t$ is just the cumulative distribution of $w_n^t$,\nnamely\n\\[ f_n^t = \\sum_{j=1}^t w_n^j \\: .  \\]\n\n\n%\\input{code/data/gn/winrate.11}\n\\ \\hfill \\includegraphics{code/data/gn/winrate.21.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.20.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.19.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.18.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.17.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.16.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.15.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.13.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.11.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.9.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.7.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.5.eps} \\hfill \\ \n\n\\ \\hfill \\includegraphics{code/data/gn/winrate.3.eps} \\hfill \\ \n\n\\section{random hex win prob \\ \\ (draft ??)}\ndefine $b(n)$ (resp.\\ $w(n)$)\nas probability that first (second) player wins $n$$\\times$$n$ hex\n\nOnce one player has a connection, filling any unoccupied cells\ndoes not change the outcome.\nSo $b(n)$ is the fraction\nof final board positions (exactly $\\lceil n^2/2 \\rceil$ black cells)\nthat connect black's two sides, \n$w(n)$ is the fraction\nof final board positions (exactly $\\lfloor n^2/2 \\rfloor$ white cells)\nthat connect white's two sides.\nFlipping colors and reflecting through the main\ndiagonal maps a winning position to a winning position,\nand so $b(n)=w(n)$ if $n$ is even.\n\n\\section{n odd}\nFor $n=2t+1$, we are interested in $b(n)-w(n)$.\nAny corresponding position corresponds \nto a game that black wins on the last move;\nafter the initial $n-1$ stones have been played, the\nblack subset is not winning, and neither is the white.\nThe white subset is a non-winning $t$-subset,\nthe black subset is a non-winning $t$-subset,\nwhich the final stone transforms into a winning $t+1$-subset.\nThus the last stone is a cut vertex of the final winning\nblack connecting set.\nSo this difference can be found by finding the \nratio $c(n)$ of cut vertices to total vertices over\nall black winning subsets.\n\\[ c(n) = \\frac{b(n)-w(n)}{b(n)} \n\\: \\: \\: \\: \\: \\mbox{\\rm and } \\: \\: \\: \\: \\:  \nb(n) + w(n) = 1\n\\: \\: \\: \\: \\: \\mbox{\\rm so }  \\: \\: \\: \\: \\: \nb(n) = \\frac{1}{2 - c(n)}\\] \nso $b(n)$ goes to 0.5 if $c(n)$ goes to 0.\n\n\\vfill\n\n\\noindent{\\bf Data generated by counting subsets}\n\n\\begin{tabular}{ccccccc}\n$n$ & subsets & w-win & b-win & $w(n)$ & $b(n)$ & $c(n)$ \\\\\n1   &  1      &  0    & 1     & 1         & 0     &  1     \\\\\n3   &  126    & 42    & 84    & .333333... & .666666... & .5 \\\\\n5   &  5200300 &  2219059 & 2981241 & .426717... & .573282... & .255659... \n\\end{tabular}\n\n\\vfill\n\n\\noindent{\\bf Data generated by $10^6$ pseudorandom samples, error about .001}\n\n\\begin{verbatim}\n 3 .332755 .667051\n 5 .427192 .573638\n 7 .456181 .544021\n 9 .469588 .530459\n11 .476214 .522408\n13 .482711 .519231\n15 .485096 .515169\n17 .487105 .512194\n19 .489548 .511278\n21 .491369 .510176\n23 .491933 .508733\n25 .492264 .507082\n\\end{verbatim}\n\\newpage\n\\vspace*{-3cm}\n\\input{4subs}\n\\newpage\n\\section{probs}\nusing sampling, we approximate the prob that a particular\ncell is the black winning move (namely, that the game ends with that move)\n\neg. on 3x3, prob a1 wins?\n\\begin{verbatim}\nwinning path\n! . .        \n x . .\n  x . .\nwins on move 3 prob (1/(9 choose 2)) * 1/7\nwins on move 4 prob (5/(9 choose 3)) * 1/6\nwins on move 5 prob (9/(9 choose 4)) * 1/5\n! . .        (not the above => bottom left cell not black)\n x x .\n  . x .\nwins on move 4 prob (1/(9 choose 3)) * 1/6\nwins on move 5 prob (2/(9 choose 4)) * 1/5\n! . .        \n x x x\n  . . x\nwins on move 5 prob (1/(9 choose 4)) * 1/5\n\ntotal\n(1/(9 choose 2))*1/7 + (1/(9 choose 3)) + (12/5)(1/(9 choose 4)) = \n11/(9*7*5) = 0.0349206349...\n\nby contrast, the prob that black wins after playing at a1\nis 12/126 = 0.095238...\n\\end{verbatim}\n\nprob game goes to last move is 1 - 2*prob(n2-1)/2 stones connect\n= prob (n2-1)/2 stones connect in neither direction\n\n\\newpage\n\\ \\hfill \\includegraphics[scale=1]{draw/bigboard.eps} \\hfill \\ \n\n\n\n\\end{document}\n", "meta": {"hexsha": "cd3c25ba9c476ac2281af6bed3d8edfb6709e37a", "size": 5480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "simple/hex/random/randomwin.tex", "max_stars_repo_name": "feiooo/games-puzzles-algorithms", "max_stars_repo_head_hexsha": "66d97135d163fb04e820338068d9bd9e12d907e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "simple/hex/random/randomwin.tex", "max_issues_repo_name": "feiooo/games-puzzles-algorithms", "max_issues_repo_head_hexsha": "66d97135d163fb04e820338068d9bd9e12d907e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "simple/hex/random/randomwin.tex", "max_forks_repo_name": "feiooo/games-puzzles-algorithms", "max_forks_repo_head_hexsha": "66d97135d163fb04e820338068d9bd9e12d907e9", "max_forks_repo_licenses": ["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.8604651163, "max_line_length": 136, "alphanum_fraction": 0.678649635, "num_tokens": 1843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6657764303687929}}
{"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{Approximation Approach}\n\nAs the Minimum Domating Set requires a brute force approach, sufficiently large graphs can have enormous run times.\nTo counter these problems, approximation algorithms are developed.\nThese are designed to find an answer that is often considered good enough for the task at hand, while having a much lower complexity.\n\nWe explored one such approach.\nThis approach uses a greedy technique for finding a dominating set.\nWhile the set is not covered, it selects the node with the highest out-degree of nodes that are not yet dominated.\nThis node gets added to the current list of dominating nodes, and repeats until the entire graph is covered.\nThis greatly improves our runtime complexity to $O(n^2)$.\n\nTo put this concept into pseudocode:\n\n\\begin{algorithm}[H]\n\n    \\caption{Minimum Dominating Set approximation algorithm}\n\n    \\begin{algorithmic}[1]\n        \\Procedure{Approximate Dominating Set}{}\n            \\While{the graph is not dominated}\n                \\For{each node not yet domianted}\n                    \\State Find its out-degree of nodes not yet dominated\n                \\EndFor\n                \\State Get the node with the highest out-degree\n                \\State Set all of its neighbors to be dominated\n            \\EndWhile\n        \\EndProcedure\n    \\end{algorithmic}\n\n\\end{algorithm}\n\nAs evident, this algorithm is much simpler.\nHowever, there is no guarantee that this algorithm will produce a minimal set, or even a set that is close to minimal.\nDepending on the task at hand, this approximate solution using a greedy technique may be preferred to a guaranteed minimal set.\n\nWe show some results of our experimental data in the next section.\n\n\\end{document}", "meta": {"hexsha": "411508d00760234f9f3833c15fba4a9ac7c5c6ee", "size": 2009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/Minimum Dominating Set/docs/tex/approximation.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/approximation.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/approximation.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": 36.5272727273, "max_line_length": 133, "alphanum_fraction": 0.743653559, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8688267796346598, "lm_q1q2_score": 0.6657764289026302}}
{"text": "\\section{Moments}\n\\label{sec:appendix:moments}\n\n\\subsection{Overview}\n\\subsubsection{Moments and initialization for addition}\nThe desired properties for initialization are according to Glorot et al. \\cite{glorot-initialization}:\n\\begin{equation}\n\\begin{aligned}\nE[z_{h_\\ell}] &= 0 & E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &= 0 \\\\\nVar[z_{h_\\ell}] &= Var\\left[z_{h_{\\ell-1}}\\right] &\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &= Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell}}}\\right]\n\\end{aligned}\n\\end{equation}\n\n\\subsubsection{Initialization for addition}\n\nGlorot initialization can not be used for $\\mathrm{NAC}_{+}$ as $W_{h_{\\ell-1},h_{\\ell}}$ is not sampled directly. Assuming that $\\hat{W}_{h_\\ell, h_{\\ell-1}} \\sim \\mathrm{Uniform}[-r, r]$ and $\\hat{M}_{h_\\ell, h_{\\ell-1}} \\sim \\mathrm{Uniform}[-r, r]$, then the variance can be derived (see proof in Appendix \\ref{sec:appendix:moments:weight-matrix-construction}) to be:\n\\begin{equation}\nVar[W_{h_{\\ell-1},h_{\\ell}}] = \\frac{1}{2r} \\left(1 - \\frac{\\tanh(r)}{r}\\right) \\left(r - \\tanh\\left(\\frac{r}{2}\\right)\\right)\n\\end{equation}\nOne can then solve for $r$, given the desired variance ($Var[W_\n{h_{\\ell-1},h_{\\ell}}] = \\frac{2}{H_{\\ell-1} + H_{\\ell}}$) \\cite{glorot-initialization}.\n\n\\subsubsection{Moments and initialization for multiplication}\nUsing second order multivariate Taylor approximation and some assumptions of uncorrelated stochastic variables, the expectation and variance of the $\\mathrm{NAC}_{\\bullet}$ layer can be estimated to:\n\\begin{equation}\n\\begin{aligned}\nf(c_1, c_2) &= \\left(1 + c_1 \\frac{1}{2} Var[W_{h_\\ell, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\\right)^{c_2\\ H_{\\ell-1}} \\\\\nE[z_{h_\\ell}] &\\approx f\\left(1, 1\\right) \\\\\nVar[z_{h_\\ell}] &\\approx f\\left(4, 1\\right) - f\\left(1, 2\\right) \\\\\nE\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &= 0 \\\\\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell}}}\\right] H_{\\ell}\\ f\\left(4, 1\\right)\\ Var[W_{h_{\\ell}, h_{\\ell-1}}] \\\\\n&\\cdot \\left(\\frac{1}{\\left(|E[z_{h_{\\ell-1}}]| + \\epsilon\\right)^2} + \\frac{3}{\\left(|E[z_{h_{\\ell-1}}]| + \\epsilon\\right)^4} Var[z_{h_{\\ell-1}}]\\right)\n\\end{aligned}\n\\end{equation}\n\nThis is problematic because $E[z_{h_\\ell}] \\ge 1$, and the variance explodes for $E[z_{h_{\\ell-1}}] = 0$. $E[z_{h_{\\ell-1}}] = 0$ is normally a desired property \\cite{glorot-initialization}. The variance explodes for $E[z_{h_{\\ell-1}}] = 0$, and can thus not be initialized to anything meaningful.\n\nFor our proposed NMU, the expectation and variance can be derived (see proof in Appendix \\ref{sec:appendix:moments:nmu}) using the same assumptions as before, although no Taylor approximation is required:\n\\begin{equation}\n\\begin{aligned}\nE[z_{h_\\ell}] &\\approx \\left(\\frac{1}{2}\\right)^{H_{\\ell-1}} \\\\\nE\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx 0 \\\\\nVar[z_{h_\\ell}] &\\approx \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1}} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1}} - \\left(\\frac{1}{4}\\right)^{H_{\\ell-1}} \\\\\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] H_\\ell \\\\\n&\\cdot \\left(\n\\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1}} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1} - 1}\\right)\n\\end{aligned}\n\\end{equation}\n\nThese expectations are better behaved. It is unlikely that the expectation of a multiplication unit can become zero, since the identity for multiplication is 1. However, for a large $H_{\\ell-1}$ it will be near zero.\n\nThe variance is also better behaved, but do not provide a input-independent initialization strategy. We propose initializing with $Var[W_{h_{\\ell-1},h_\\ell}] = \\frac{1}{4}$, as this is the solution to $Var[z_{h_\\ell}] = Var[z_{h_{\\ell-1}}]$ assuming $Var[z_{h_{\\ell-1}}] = 1$ and a large $H_{\\ell-1}$ (see proof in Appendix \\ref{sec:appendix:moments:nmu:initialization}). However, more exact solutions are possible if the input variance is known.\n\n\\subsection{Expectation and variance for weight matrix construction in NAC layers}\n\\label{sec:appendix:moments:weight-matrix-construction}\n\nThe weight matrix construction in NAC, is defined in scalar notation as: \n\\begin{equation}\nW_{h_\\ell, h_{\\ell-1}} = \\tanh(\\hat{W}_{h_\\ell, h_{\\ell-1}}) \\sigma(\\hat{M}_{h_\\ell, h_{\\ell-1}})\n\\end{equation}\n\nSimplifying the notation of this, and re-expressing it using stochastic variables with uniform distributions this can be written as:\n\\begin{equation}\n\\begin{aligned}\nW &\\sim \\tanh(\\hat{W}) \\sigma(\\hat{M}) \\\\\n\\hat{W} &\\sim ~ U[-r, r] \\\\\n\\hat{M} &\\sim ~ U[-r, r] \n\\end{aligned}\n\\end{equation}\n\nSince $\\tanh({\\hat{W}})$ is an odd-function and $E[\\hat{W}] = 0$, deriving the expectation $E[W]$ is trivial.\n\\begin{equation}\n\\mathrm{E}[W] = \\mathrm{E}[\\tanh(\\hat{W})]\\mathrm{E}[\\sigma(\\hat{M})] = 0 \\cdot \\mathrm{E}[\\sigma(\\hat{M})] = 0\n\\end{equation}\n\nThe variance is more complicated, however as $\\hat{W}$ and $\\hat{M}$ are independent, it can be simplified to:\n\\begin{equation}\n\\mathrm{Var}[W] = \\mathrm{E}[\\tanh(\\hat{W})^2] \\mathrm{E}[\\sigma(\\hat{M})^2] - \\mathrm{E}[\\tanh(\\hat{W})]^2 \\mathrm{E}[\\sigma(\\hat{M})]^2 = \\mathrm{E}[\\tanh(\\hat{W})^2] \\mathrm{E}[\\sigma(\\hat{M})^2]\n\\end{equation}\n\nThese second moments can be analyzed independently. First for $\\mathrm{E}[\\tanh(\\hat{W})^2]$:\n\\begin{equation}\n\\begin{aligned}\n\\mathrm{E}[\\tanh(\\hat{W})^2] &= \\int_{-\\infty}^{\\infty} \\tanh(x)^2 f_{U[-r, r]}(x)\\ \\mathrm{d}x \\\\\n&= \\frac{1}{2r} \\int_{-r}^{r} \\tanh(x)^2\\ \\mathrm{d}x \\\\\n&= \\frac{1}{2r} \\cdot 2 \\cdot (r - \\tanh(r)) \\\\\n&= 1 - \\frac{\\tanh(r)}{r}\n\\end{aligned}\n\\end{equation}\n\nThen for $\\mathrm{E}[\\tanh(\\hat{M})^2]$:\n\\begin{equation}\n\\begin{aligned}\n\\mathrm{E}[\\sigma(\\hat{M})^2] &= \\int_{-\\infty}^{\\infty} \\sigma(x)^2 f_{U[-r, r]}(x)\\ \\mathrm{d}x \\\\\n&= \\frac{1}{2r} \\int_{-r}^{r} \\sigma(x)^2\\ \\mathrm{d}x \\\\\n&= \\frac{1}{2r} \\left(r - \\tanh\\left(\\frac{r}{2}\\right)\\right)\n\\end{aligned}\n\\end{equation}\n\nWhich results in the variance:\n\\begin{equation}\n\\mathrm{Var}[W] = \\frac{1}{2r} \\left(1 - \\frac{\\tanh(r)}{r}\\right) \\left(r - \\tanh\\left(\\frac{r}{2}\\right)\\right)\n\\end{equation}\n\n\\subsection{Expectation and variance of \\texorpdfstring{$\\mathrm{NAC}_{\\bullet}$}{NAC-mul}}\n\\label{sec:appendix:moments:nac-mul}\n\\subsubsection{Forward pass}\n\n\\paragraph{Expectation} Assuming that each $z_{h_{\\ell-1}}$ are uncorrelated, the expectation can be simplified to:\n\\begin{equation}\n\\begin{aligned}\nE[z_{h_\\ell}] &= E\\left[\\exp\\left(\\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} W_{h_{\\ell}, h_{\\ell-1}} \\log(|z_{h_{\\ell-1}}| + \\epsilon) \\right)\\right] \\\\\n&= E\\left[\\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} \\exp(W_{h_{\\ell}, h_{\\ell-1}} \\log(|z_{h_{\\ell-1}}| + \\epsilon)) \\right] \\\\\n&\\approx \\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} E[\\exp(W_{h_{\\ell}, h_{\\ell-1}} \\log(|z_{h_{\\ell-1}}| + \\epsilon))] \\\\\n&= E[\\exp(W_{h_{\\ell}, h_{\\ell-1}} \\log(|z_{h_{\\ell-1}}| + \\epsilon))]^{H_{\\ell-1}} \\\\\n&= E\\left[(|z_{h_{\\ell-1}}| + \\epsilon)^{W_{h_{\\ell}, h_{\\ell-1}}}\\right]^{H_{\\ell-1}} \\\\\n&= E\\left[f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})\\right]^{H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nHere we define $g$ as a non-linear transformation function of two independent stochastic variables:\n\\begin{equation}\nf(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}}) = (|z_{h_{\\ell-1}}| + \\epsilon)^{W_{h_{\\ell}, h_{\\ell-1}}}\n\\end{equation}\n\nWe then apply second order Taylor approximation of $f$, around $(E[z_{h_{\\ell-1}}], E[W_{h_{\\ell}, h_{\\ell-1}}])$.\n\\begin{equation}\n\\begin{aligned}\n&E[f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})] \\approx\nE\\Bigg[\\\\\n&f(E[z_{h_{\\ell-1}}], E[W_{h_{\\ell}, h_{\\ell-1}}])\\\\\n&+ \\begin{bmatrix}\nz_{h_{\\ell-1}} - E[z_{h_{\\ell-1}}] \\\\ W_{h_{\\ell}, h_{\\ell-1}} - E[W_{h_{\\ell}, h_{\\ell-1}}]\n\\end{bmatrix}^T \\begin{bmatrix}\n\\frac{\\partial f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial z_{h_{\\ell-1}}} \\\\\n\\frac{\\partial f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial W_{h_{\\ell}, h_{\\ell-1}}}\n\\end{bmatrix} \\Bigg\\rvert_{\n\\begin{cases}\nz_{h_{\\ell-1}} = E[z_{h_{\\ell-1}}] \\\\\nW_{h_{\\ell}, h_{\\ell-1}} = E[W_{h_{\\ell}, h_{\\ell-1}}]\n\\end{cases}\n} \\\\\n&+ \\frac{1}{2} \\begin{bmatrix}\nz_{h_{\\ell-1}} - E[z_{h_{\\ell-1}}] \\\\ W_{h_{\\ell}, h_{\\ell-1}} - E[W_{h_{\\ell}, h_{\\ell-1}}]\n\\end{bmatrix}^T \\\\\n&\\bullet \\begin{bmatrix}\n\\frac{\\partial^2 f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial^2 z_{h_{\\ell-1}}} & \\frac{\\partial^2 f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial z_{h_{\\ell-1}} \\partial W_{h_{\\ell}, h_{\\ell-1}}} \\\\\n\\frac{\\partial^2 f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial z_{h_{\\ell-1}} \\partial W_{h_{\\ell}, h_{\\ell-1}}} & \\frac{\\partial^2 f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial^2 W_{h_{\\ell}, h_{\\ell-1}}}\n\\end{bmatrix} \\Bigg\\rvert_{\n\\begin{cases}\nz_{h_{\\ell-1}} = E[z_{h_{\\ell-1}}] \\\\\nW_{h_{\\ell}, h_{\\ell-1}} = E[W_{h_{\\ell}, h_{\\ell-1}}]\n\\end{cases}\n} \\\\\n&\\bullet \\begin{bmatrix}\nz_{h_{\\ell-1}} - E[z_{h_{\\ell-1}}] \\\\ W_{h_{\\ell}, h_{\\ell-1}} - E[W_{h_{\\ell}, h_{\\ell-1}}]\n\\end{bmatrix}\\Bigg]\n\\end{aligned}\n\\end{equation}\n\nBecause $E[z_{h_{\\ell-1}} - E[z_{h_{\\ell-1}}]] = 0$, $E[W_{h_{\\ell}, h_{\\ell-1}} - E[W_{h_{\\ell}, h_{\\ell-1}}]] = 0$, and $Cov[z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}}] = 0$. This simplifies to:\n\\begin{equation}\n\\begin{aligned}\n&E[g(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})] \\approx\ng(E[z_{h_{\\ell-1}}], E[W_{h_{\\ell}, h_{\\ell-1}}])\\\\\n&+ \\frac{1}{2} Var\\begin{bmatrix}\nz_{h_{\\ell-1}} \\\\ W_{h_{\\ell}, h_{\\ell-1}}\n\\end{bmatrix}^T \\begin{bmatrix}\n\\frac{\\partial^2 g(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial^2 z_{h_{\\ell-1}}} \\\\\n\\frac{\\partial^2 g(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})}{\\partial^2 W_{h_{\\ell}, h_{\\ell-1}}}\n\\end{bmatrix} \\Bigg\\rvert_{\n\\begin{cases}\nz_{h_{\\ell-1}} = E[z_{h_{\\ell-1}}] \\\\\nW_{h_{\\ell}, h_{\\ell-1}} = E[W_{h_{\\ell}, h_{\\ell-1}}]\n\\end{cases}\n}\n\\end{aligned}\n\\end{equation}\n\nInserting the derivatives and computing the inner products yields:\n\\begin{equation}\n\\begin{aligned}\n&E[f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})] \\approx\n(|E[z_{h_{\\ell-1}}]| + \\epsilon)^{E[W_{h_{\\ell}, h_{\\ell-1}}]} \\\\\n&+ \\frac{1}{2} Var[z_{h_{\\ell-1}}] (|E[z_{h_{\\ell-1}}]| + \\epsilon)^{E[W_{h_{\\ell}, h_{\\ell-1}}] - 2} E[W_{h_{\\ell}, h_{\\ell-1}}] (E[W_{h_{\\ell}, h_{\\ell-1}}] - 1) \\\\\n&+ \\frac{1}{2} Var[W_{h_{\\ell}, h_{\\ell-1}}] (|E[z_{h_{\\ell-1}}]| + \\epsilon)^{E[W_{h_{\\ell}, h_{\\ell-1}}]} \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2 \\\\\n&=1 + \\frac{1}{2} Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\n\\end{aligned}\n\\label{eq:appendix:nac:forward-pass:expectation:taylor}\n\\end{equation}\n\nThis gives the final expectation:\n\\begin{equation}\n\\begin{aligned}\nE[z_{h_\\ell}] &= E\\left[g(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})\\right]^{H_{\\ell-1}} \\\\\n&\\approx\\left(1 + \\frac{1}{2} Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\\right)^{H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nWe evaluate the error of the approximation, where $W_{h_{\\ell}, h_{\\ell-1}} \\sim U[-r_w,r_w]$ and $z_{h_{\\ell-1}} \\sim U[0, r_z]$. These distributions are what is used in the  arithmetic dataset. The error is plotted in figure \\ref{fig:nac-mul-expectation-estimate}.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=\\linewidth]{graphics/nac-mul-expectation-estimate.pdf}\n\\caption{Error between theoretical approximation and the numerical approximation estimated by random sampling of $100000$ observations at each combination of $r_z$ and $r_w$.}\n\\label{fig:nac-mul-expectation-estimate}\n\\end{figure}\n\n\\paragraph{Variance} The variance can be derived using the same assumptions as used in ``expectation'', that all $z_{h_{\\ell-1}}$ are uncorrelated.\n\\begin{equation}\n\\begin{aligned}\nVar[z_{h_\\ell}] &= E[z_{h_\\ell}^2] - E[z_{h_\\ell}]^2 \\\\\n&= E\\left[\\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} (|z_{h_{\\ell-1}}| + \\epsilon)^{2 \\cdot W_{h_{\\ell}, h_{\\ell-1}}} \\right]\n- E\\left[\\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} (|z_{h_{\\ell-1}}| + \\epsilon)^{W_{h_{\\ell}, h_{\\ell-1}}}\\right]^2 \\\\\n&= E\\left[f(z_{h_{\\ell-1}}, 2 \\cdot W_{h_{\\ell}, h_{\\ell-1}}) \\right]^{H_{\\ell-1}}\n- E\\left[f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})\\right]^{2\\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nWe already have from the expectation result in \\eqref{eq:appendix:nac:forward-pass:expectation:taylor} that:\n\\begin{equation}\nE\\left[f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})\\right] \\approx 1 + \\frac{1}{2} Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\n\\end{equation}\n\nBy substitution of variable we have that:\n\\begin{equation}\n\\begin{aligned}\nE\\left[f(z_{h_{\\ell-1}}, 2 \\cdot W_{h_{\\ell}, h_{\\ell-1}})\\right] &\\approx 1 + \\frac{1}{2} Var[2 \\cdot W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2 \\\\\n&\\approx 1 + 2 \\cdot Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\n\\end{aligned}\n\\end{equation}\n\nThis gives the variance:\n\\begin{equation}\n\\begin{aligned}\nVar[z_{h_\\ell}] &= E\\left[g(z_{h_{\\ell-1}}, 2 \\cdot W_{h_{\\ell}, h_{\\ell-1}}) \\right]^{H_{\\ell-1}}\n- E\\left[f(z_{h_{\\ell-1}}, W_{h_{\\ell}, h_{\\ell-1}})\\right]^{2\\cdot H_{\\ell-1}} \\\\\n&\\approx \\left(1 + 2 \\cdot Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\\right)^{H_{\\ell-1}} \\\\\n&- \\left(1 + \\frac{1}{2} \\cdot Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\\right)^{2\\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\n\\subsubsection{Backward pass}\n\n\\paragraph{Expectation} The expectation of the back-propagation term assuming that $\\delta_{h_{\\ell+1}}$ and $\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}$ are mutually uncorrelated:\n\\begin{equation}\nE[\\delta_{h_\\ell}] = E\\left[\\sum_{h_{\\ell+1}=1}^{H_{\\ell+1}} \\delta_{h_{\\ell+1}} \\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}\\right] \\approx H_{\\ell+1} E[\\delta_{h_{\\ell+1}}] E\\left[\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}\\right]\n\\end{equation}\n\nAssuming that $z_{h_{\\ell+1}}$, $W_{h_{\\ell+1},h_\\ell}$, and $z_{h_\\ell}$ are uncorrelated:\n\\begin{equation}\nE\\left[\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}\\right] \\approx E[{z_{h_{\\ell+1}}}] E[W_{h_{\\ell+1}, h_{\\ell}}] E\\left[ \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right] = E[z_{h_{\\ell+1}}] \\cdot 0 \\cdot E\\left[ \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_\\ell}| + \\epsilon}\\right] = 0\n\\end{equation}\n\n\\paragraph{Variance} Deriving the variance is more complicated:\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}\\right] &= Var\\left[z_{h_{\\ell+1}} W_{h_{\\ell+1}, h_{\\ell}} \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right]\n\\end{aligned}\n\\end{equation}\n\nAssuming again that $z_{h_{\\ell+1}}$, $W_{h_{\\ell+1},h_\\ell}$, and $z_{h_\\ell}$ are uncorrelated, and likewise for their second moment:\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}\\right] & \\approx E[z_{h_{\\ell+1}}^2] E[W_{h_{\\ell+1}, h_{\\ell}}^2] E\\left[\\left( \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right)^2\\right] \\\\\n&- E[z_{h_{\\ell+1}}]^2 E[W_{h_{\\ell+1}, h_{\\ell}}]^2 E\\left[ \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right]^2 \\\\\n&= E[z_{h_{\\ell+1}}^2] Var[W_{h_{\\ell+1}, h_{\\ell}}] E\\left[\\left( \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right)^2\\right] \\\\\n&- E[z_{h_{\\ell+1}}]^2 \\cdot 0 \\cdot E\\left[ \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right]^2 \\\\\n&= E[z_{h_{\\ell+1}}^2] Var[W_{h_{\\ell+1}, h_{\\ell}}] E\\left[\\left( \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon}\\right)^2\\right]\n\\end{aligned}\n\\end{equation}\n\nUsing Taylor approximation around $E[z_{h_{\\ell}}]$ we have:\n\\begin{equation}\n\\begin{aligned}\nE\\left[\\left(\\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z| + \\epsilon}\\right)^2\\right] &\\approx\\frac{1}{\\left(|E[z_{h_{\\ell}}]| + \\epsilon\\right)^2} + \\frac{1}{2} \\frac{6}{\\left(|E[z_{h_{\\ell}}]| + \\epsilon\\right)^4} Var[z_{h_{\\ell}}] \\\\\n&= \\frac{1}{\\left(|E[z_{h_{\\ell}}]| + \\epsilon\\right)^2} + \\frac{3}{\\left(|E[z_{h_{\\ell}}]| + \\epsilon\\right)^4} Var[z_{h_{\\ell}}]\n\\end{aligned}\n\\end{equation}\n\nFinally, by reusing the result for $E[z_{h_\\ell}^2]$ from earlier the variance can be expressed as:\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell}}}\\right] H_{\\ell}\\ \\left(1 + 2 \\cdot Var[W_{h_{\\ell}, h_{\\ell-1}}] \\log(|E[z_{h_{\\ell-1}}]| + \\epsilon)^2\\right)^{H_{\\ell-1}} \\\\\n&\\cdot Var[W_{h_{\\ell}, h_{\\ell-1}}] \\left(\\frac{1}{\\left(|E[z_{h_{\\ell-1}}]| + \\epsilon\\right)^2} + \\frac{3}{\\left(|E[z_{h_{\\ell-1}}]| + \\epsilon\\right)^4} Var[z_{h_{\\ell-1}}]\\right)\n\\end{aligned}\n\\end{equation}\n\n\\subsection{Expectation and variance of NMU}\n\\label{sec:appendix:moments:nmu}\n\\subsubsection{Forward pass}\n\\paragraph{Expectation} Assuming that all $z_{h_{\\ell-1}}$ are independent:\n\\begin{equation}\n\\begin{aligned}\nE[z_{h_\\ell}] &= E\\left[\\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} \\left(W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell} \\right)\\right] \\\\\n&\\approx E\\left[W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell} \\right]^{H_{\\ell-1}} \\\\\n&\\approx \\left(E[W_{h_{\\ell-1},h_\\ell}] E[z_{h_{\\ell-1}}] + 1 - E[W_{h_{\\ell-1},h_\\ell}] \\right)^{H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nAssuming that $E[z_{h_{\\ell-1}}] = 0$ which is a desired property and initializing $E[W_{h_{\\ell-1},h_\\ell}] = \\nicefrac{1}{2}$, the expectation is:\n\\begin{equation}\n\\begin{aligned}\nE[z_{h_\\ell}] &\\approx \\left(E[W_{h_{\\ell-1},h_\\ell}] E[z_{h_{\\ell-1}}] + 1 - E[W_{h_{\\ell-1},h_\\ell}] \\right)^{H_{\\ell-1}} \\\\\n&\\approx\\left(\\frac{1}{2}\\cdot0 + 1 - \\frac{1}{2}\\right)^{H_{\\ell-1}} \\\\\n&=\\left(\\frac{1}{2}\\right)^{H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\n\\paragraph{Variance} Reusing the result for the expectation, assuming again that all $z_{h_{\\ell-1}}$ are uncorrelated, and using the fact that $W_{h_{\\ell-1},h_\\ell}$ is initially independent from $z_{h_{\\ell-1}}$:\n\\begin{equation}\n\\begin{aligned}\nVar[z_{h_\\ell}] &= E[z_{h_\\ell}^2] - E[z_{h_\\ell}]^2 \\\\\n&\\approx E[z_{h_\\ell}^2] - \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&= E\\left[\\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}}\\left(W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}\\right)^2\\right] - \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&\\approx E[\\left(W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}\\right)^2]^{H_{\\ell-1}}- \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&= \\Big(E[W_{h_{\\ell-1},h_\\ell}^2] E[z_{h_{\\ell-1}}^2] - 2 E[W_{h_{\\ell-1},h_\\ell}^2] E[z_{h_{\\ell-1}}]+ E[W_{h_{\\ell-1},h_\\ell}^2] \\\\\n&\\quad\\quad + 2 E[W_{h_{\\ell-1},h_\\ell}] E[z_{h_{\\ell-1}}] - 2 E[W_{h_{\\ell-1},h_\\ell}] + 1\\Big)^{H_{\\ell-1}}- \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nAssuming that $E[z_{h_{\\ell-1}}] = 0$, which is a desired property and initializing $E[W_{h_{\\ell-1},h_\\ell}] = \\nicefrac{1}{2}$, the variance becomes:\n\\begin{equation}\n\\begin{aligned}\nVar[z_{h_\\ell}] &\\approx \\left(E[W_{h_{\\ell-1},h_\\ell}^2] \\left(E[z_{h_{\\ell-1}}^2] + 1\\right)\\right)^{H_{\\ell-1}}- \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&\\approx \\left(\\left(Var[W_{h_{\\ell-1},h_\\ell}] + E[W_{h_{\\ell-1},h_\\ell}]^2\\right) \\left(Var[z_{h_{\\ell-1}}] + 1\\right)\\right)^{H_{\\ell-1}}- \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&= \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1}} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1}} - \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\n\\subsubsection{Backward pass}\n\n\\paragraph{Expectation} For the backward pass the expectation can, assuming that $\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}$ and $\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}$ are uncorrelated, be derived to:\n\\begin{equation}\n\\begin{aligned}\nE\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right]\n&= H_\\ell E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] \\\\\n&\\approx H_\\ell E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] E\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] \\\\\n&= H_\\ell E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] E\\left[\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}} W_{h_{\\ell-1},h_\\ell}\\right] \\\\\n&= H_\\ell E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] E\\left[\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right]E\\left[W_{h_{\\ell-1},h_\\ell}\\right]\n\\end{aligned}\n\\end{equation}\n\nInitializing $E[W_{h_{\\ell-1},h_\\ell}] = \\nicefrac{1}{2}$, and inserting the result for the expectation $E\\left[\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right]$.\n\\begin{equation}\n\\begin{aligned}\nE\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx H_\\ell E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] \\left(\\frac{1}{2}\\right)^{H_{\\ell-1}-1} \\frac{1}{2} \\\\\n&= E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] H_\\ell \\left(\\frac{1}{2}\\right)^{H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nAssuming that $E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] = 0$, which is a desired property \\cite{glorot-initialization}.\n\\begin{equation}\n\\begin{aligned}\nE\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx 0 \\cdot H_\\ell \\cdot \\left(\\frac{1}{2}\\right)^{H_{\\ell-1}} \\\\\n&= 0\n\\end{aligned}\n\\end{equation}\n\n\n\\paragraph{Variance} For the variance of the backpropagation term, we assume that $\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}$ is uncorrelated with $\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}$.\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &= H_\\ell Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] \\\\\n&\\approx H_\\ell \\Bigg(Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] E\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right]^2 + E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right]^2 Var\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] \\\\\n&+ Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] Var\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right]\\Bigg)\n\\end{aligned}\n\\end{equation}\n\nAssuming again that $E\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] = 0$, and reusing the result $E\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] = \\left(\\frac{1}{2}\\right)^{H_{\\ell-1}}$.\n\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] H_\\ell \\left(\\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} + Var\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right]\\right)\n\\end{aligned}\n\\end{equation}\n\nFocusing now on $Var\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right]$, we have:\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] &= E\\left[\\left(\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right)^2\\right] E[W_{h_{\\ell-1},h_\\ell}^2] \\\\\n&- E\\left[\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right]^2 E[W_{h_{\\ell-1},h_\\ell}]^2\n\\end{aligned}\n\\end{equation}\n\nInserting the result for the expectation $E\\left[\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right]$ and Initializing again $E[W_{h_{\\ell-1},h_\\ell}] = \\nicefrac{1}{2}$.\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx E\\left[\\left(\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right)^2\\right] E[W_{h_{\\ell-1},h_\\ell}^2] \\\\\n&- \\left(\\frac{1}{2}\\right)^{2 \\cdot \\left(H_{\\ell-1}-1\\right)} \\left(\\frac{1}{2}\\right)^2 \\\\\n&= E\\left[\\left(\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right)^2\\right] E[W_{h_{\\ell-1},h_\\ell}^2] \\\\\n&- \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nUsing the identity that $E[W_{h_{\\ell-1},h_\\ell}^2] = Var[W_{h_{\\ell-1},h_\\ell}] + E[W_{h_{\\ell-1},h_\\ell}]^2$, and again using $E[W_{h_{\\ell-1},h_\\ell}] = \\nicefrac{1}{2}$.\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx E\\left[\\left(\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right)^2\\right] \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right) \\\\\n&- \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nTo derive $E\\left[\\left(\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right)^2\\right]$ the result for $Var[z_{h_\\ell}]$ can be used, but for $\\hat{H}_{\\ell-1} = H_{\\ell-1} - 1$, because there is one less term. Inserting $E\\left[\\left(\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}\\right)^2\\right] = \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1} - 1} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1} - 1}$, we have:\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1} - 1} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1} - 1} \\\\\n&\\cdot \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right) - \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&= \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1}} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1} - 1} - \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}}\n\\end{aligned}\n\\end{equation}\n\nInserting the result for $Var\\left[\\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}}\\right]$ into the result for $Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right]$:\n\\begin{equation}\n\\begin{aligned}\nVar\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}}\\right] &\\approx Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] H_\\ell \\Bigg(\n\\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}} \\\\\n&+ \\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1}} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1} - 1} - \\left(\\frac{1}{2}\\right)^{2 \\cdot H_{\\ell-1}}\\Bigg) \\\\\n&= Var\\left[\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}\\right] H_\\ell \\\\\n&\\cdot \\left(\n\\left(Var[W_{h_{\\ell-1},h_\\ell}] + \\frac{1}{4}\\right)^{H_{\\ell-1}} \\left(Var[z_{h_{\\ell-1}}] + 1\\right)^{H_{\\ell-1} - 1}\\right)\n\\end{aligned}\n\\label{eq:appendix:nmu:variance:result}\n\\end{equation}\n\n\\subsubsection{Initialization}\n\\label{sec:appendix:moments:nmu:initialization}\n\nThe $W_{h_{\\ell-1},h_\\ell}$ should be initialized with $E[W_{h_{\\ell-1},h_\\ell}] = \\frac{1}{2}$, in order to not bias towards inclusion or exclusion of $z_{h_{\\ell-1}}$. Using the derived variance approximations \\eqref{eq:appendix:nmu:variance:result}, the variance should be according to the forward pass:\n\n\\begin{equation}\nVar[W_{h_{\\ell-1},h_\\ell}] = \\left((1 + Var[z_{h_\\ell}])^{-H_{\\ell-1}}Var[z_{h_\\ell}] + (4 + 4Var[z_{h_\\ell}])^{-H_{\\ell-1}}\\right)^{\\frac{1}{H_{\\ell-1}}} - \\frac{1}{4}\n\\end{equation}\n\nAnd according to the backward pass it should be:\n\\begin{equation}\nVar[W_{h_{\\ell-1},h_\\ell}] = \\left( \\frac{ \\left(Var[z_{h_\\ell}] + 1\\right)^{1 - H_{\\ell-1}} }{H_{\\ell}} \\right)^{\\frac{1}{H_{\\ell-1}}} - \\frac{1}{4}\n\\end{equation}\n\nBoth criteria are dependent on the input variance. If the input variance is know then optimal initialization is possible. However, as this is often not the case one can perhaps assume that $Var[z_{h_{\\ell-1}}] = 1$. This is not an unreasonable assumption in many cases, as there may either be a normalization layer somewhere or the input is normalized. If unit variance is assumed, the variance for the forward pass becomes:\n\\begin{equation}\nVar[W_{h_{\\ell-1},h_\\ell}] = \\left(2^{-H_{\\ell-1}} + 8^{-H_{\\ell-1}}\\right)^{\\frac{1}{H_{\\ell-1}}} - \\frac{1}{4} = \\frac{1}{8} \\left(\\left(4^{H_{\\ell-1}} + 1\\right)^{H_{\\ell-1}} - 2\\right)\n\\end{equation}\n\nAnd from the backward pass:\n\\begin{equation}\nVar[W_{h_{\\ell-1},h_\\ell}] = \\left( \\frac{ 2^{1 - H_{\\ell-1}} }{H_{\\ell}} \\right)^{\\frac{1}{H_{\\ell-1}}} - \\frac{1}{4}\n\\end{equation}\n\nThe variance requirement for both the forward and backward pass can be satisfied with  $Var[W_{h_{\\ell-1},h_\\ell}] = \\frac{1}{4}$ for a large $H_{\\ell-1}$.\n", "meta": {"hexsha": "6f5181070199053327d80e69f88820bb9dac4e10", "size": 28655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/appendix/moments.tex", "max_stars_repo_name": "wlm2019/Neural-Arithmetic-Units", "max_stars_repo_head_hexsha": "f9de9d004bb2dc2ee28577cd1760d0a00c185836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 147, "max_stars_repo_stars_event_min_datetime": "2019-10-07T11:01:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T02:51:18.000Z", "max_issues_repo_path": "paper/appendix/moments.tex", "max_issues_repo_name": "wlm2019/Neural-Arithmetic-Units", "max_issues_repo_head_hexsha": "f9de9d004bb2dc2ee28577cd1760d0a00c185836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-03T12:40:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T12:40:21.000Z", "max_forks_repo_path": "paper/appendix/moments.tex", "max_forks_repo_name": "wlm2019/Neural-Arithmetic-Units", "max_forks_repo_head_hexsha": "f9de9d004bb2dc2ee28577cd1760d0a00c185836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2019-12-21T15:58:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T08:32:38.000Z", "avg_line_length": 63.5365853659, "max_line_length": 509, "alphanum_fraction": 0.6276740534, "num_tokens": 12107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6655065878148411}}
{"text": "\\subsection{Producer nodes selection}\nThe selection of producers among the worker pool can be achieved for each ledger cycle using a randomised approach. Since a producer generates a ledger state update for a ledger cycle based on transactions collected during the previous ledger cycle(s), such assignment to a node should be revealed at least one cycle ahead. In fact, we use a method that reveals at the beginning of a ledger cycle $\\mathcal{C}_n$ the list of nodes selected to be producers for a ledger cycle $\\mathcal{C}_{n+1}$ using information available one cycle ahead ($\\mathcal{C}_{n-1}$).\\\\\n\nAt the beginning of a ledger cycle $\\mathcal{C}_n$, at time $t = t_{n,0}$, a pseudo-random number $r_{n+1}$ is drawn using the Merkel tree root of the ledger state update produced during the the cycle $\\mathcal{C}_{n-1}$, as seed to the pseudo-random number generator. The random number $r_{n+1}$ is then used to define the list of workers selected to become producers for the next cycle $\\mathcal{C}_{n+1}$ in the following way: for each worker node identifier $Id_i$ the quantity $u_i = Id_i \\oplus r_{n+1}$ is defined, where $\\oplus$ is an XOR function (for binary-based modulus addition). The list of new identifiers $\\{u_i \\}_{i=1,...,N}$ ($N$ is the total number of nodes in the worker pool) is sorted in ascending order and the first $P$ identifiers in that list are the identifiers of the nodes selected to be producers for the next cycle $\\mathcal{C}_{n+1}$.\n\n\\subsection{Worker nodes selection}\n\nIn a large network, it can be anticipated that a large number of nodes have available resources to be used to manage the ledger database and try to join the worker pool (which translates as a high demand for work). The size of the worker pool must however be determined by security as well as economical factors. Indeed, it must be profitable for a node to join the worker pool. Said otherwise, the average number of tokens earned by a producer over a period of time should at the very least cover its operational cost. As there might be more nodes willing to work than required for the worker pool, nodes may join a secondary pool, called \\textit{worker queue}, and wait to be called to join the worker pool. In order for these nodes to join the worker pool, there must be a mechanism that limits the time period during which a node can persist in the worker pool. The approach considered is to grant nodes joining the worker pool a worker pass which is valid for a limited period of time. \\\\\n\n\\begin{comment}\nFor security reasons explained in section~\\ref{Sec:ConSec}, rather than defining a strict expiry time, a decay rate is used to determine the validity of a worker pass. Similarly to unstable nuclear elements the work pass has a 50\\% chance to remain valid after the worker sits in the worker pool for a period of time equal to the its worker pass mean lifetime (see section~\\ref{Sec:PassVal}). The decay rate is not fixed over time but instead can vary depending on the quality of work performed by the worker when acting as a producer. It can also vary to account for the demand for work, \\textit{i.e.} the length of the worker queue, although a threshold is considered to mitigate the risk of a malicious entity (or group of entities) trying to simulate a highest demand for work than reality.\n\n\nThe list of identifiers of nodes in the worker pool can be maintained in a hash table ($DHT_w$) distributed across the network. Such table also stores the decay rate of each node worker pass. At the end of a ledger cycle, nodes in the network can therefore deduce the list of worker passes which validity has expired. Nodes on the network can update the table, freeing some slots that can be occupied by the nodes sitting in the worker queue. \\\\\n\\end{comment}\n\nThe list of identifiers of nodes in the worker pool is maintained in a hash table, $DHT_w$, distributed across the network. Such table also stores the time of issuance of the node worker pass. At the end of a ledger cycle, nodes in the network will be able to verify which worker passes are no longer valid and have expired. Nodes on the network can update the table, freeing some slots that can be occupied by the nodes sitting in the worker queue. \\\\\n\nBy providing proof of their available resource to the network \\cite{coremark,pos}, nodes can freely apply to become workers. These nodes join the worker queue before joining the worker pool. Nodes on the network store such proof alongside the node identifier in a secondary distributed hash table, $DHT_q$. As worker nodes leave the worker pool, some nodes listed in $DHT_q$ join the worker pool. A logic described below can be implemented such that nodes with identifiers at the top of the list of nodes in $DHT_q$ are the first ones to access the worker pool and be listed in $DHT_w$. Such an approach could however be seen as potentially accommodating Sybil-identity attacks~\\cite{sybil}, nevertheless expensive, if an entity controls a large number nodes at the top of the worker queue (at least equal to half the worker pool size $N/2$) and frequently adds many nodes to the worker queue such that the size of the worker queue is large enough to create an impression of a large demand for work. %The peer identification protocol on Catalyst network is designed to limit the number nodes on the same IP address entering a pool of nodes. \nWe therefore adapt our approach to define the dynamic of nodes leaving the worker queue and joining the worker pool that both prevents Sybil attack and incentivise nodes to join the worker queue during periods of low demand for work. We propose a method to sort out the nodes listed in the worker queue.\\\\\n\nA score (or ranking) is given to a node when it joins the worker queue. The nodes in the worker queue are then ordered based on their score in descending order, \\textit{i.e.} the nodes with the lowest score are at the top of the queue and are the first ones to leave the worker queue and be selected to join the worker pool when some slots are freed in the worker pool. The method to assign a score to a node joining the worker queue is not purely chronological-based. It depends on the volume of nodes trying to join the worker queue during an allotted time period $\\Delta t$. Assuming $S_t$ nodes apply to join the worker queue during a window of time $[t, t+\\Delta t]$. The $S_t$ nodes first register to a temporary queue, represented by a third hash table $DHT_s$. At the end of the time window, a fixed and limited number of nodes listed in $DHT_s$, $z \\leq S_t$, are randomly selected. $z$ is equal to the number of nodes who left the worker pool during the previous time window $[t-\\Delta t, t]$. These $z$ nodes are given a score drawn from a normal distribution centred around $R_q$, which is a predetermined threshold of the worker queue length. This means that some selected nodes may obtain a score lower than nodes currently at the bottom of the worker queue. The rest of the nodes in the temporary queue ($S_t-z$) are given a score drawn from a normal distribution centred around $R_l = R_q + s$, where $s$ is a shift proportional to the volume of nodes in $DHT_s$. Figure~\\ref{fig:NSM} summarises the process of score allocation for nodes joining the worker queue. \\\\\n%The rotation rate of nodes in the worker pool then depends on the size of the worker queue but only take into account the number of nodes with a ranking higher than a given threshold. \n\n\\newpage\n\\begin{landscape}\n\\begin{figure}\n\\centering\n\\includegraphics[width=22cm,height=42cm,keepaspectratio]{Figures/Work_Queue_Management}\n\\caption{\\label{fig:NSM}Illustration of the process followed by Catalyst network to add nodes to the worker queue.}\n\\end{figure}\n\\end{landscape}\n\n", "meta": {"hexsha": "412508735cdcb877f635f5b7aded2448a8051824", "size": 7738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper-tex-files/catalyst-network/node-role-assignment/node-role-assignment.tex", "max_stars_repo_name": "Atlas3T/consensus-whitepaper", "max_stars_repo_head_hexsha": "68cc6e4938ae266e964448a513d471cc48622fe2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper-tex-files/catalyst-network/node-role-assignment/node-role-assignment.tex", "max_issues_repo_name": "Atlas3T/consensus-whitepaper", "max_issues_repo_head_hexsha": "68cc6e4938ae266e964448a513d471cc48622fe2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper-tex-files/catalyst-network/node-role-assignment/node-role-assignment.tex", "max_forks_repo_name": "Atlas3T/consensus-whitepaper", "max_forks_repo_head_hexsha": "68cc6e4938ae266e964448a513d471cc48622fe2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-10T10:42:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-21T19:12:41.000Z", "avg_line_length": 227.5882352941, "max_line_length": 1582, "alphanum_fraction": 0.7825019385, "num_tokens": 1737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.665506308860015}}
{"text": "\\documentclass[en]{elegantpaper}\n\n\\begin{document}\n\\section*{1}\n\\noindent Because $\\mu_i=\\beta_1+\\beta_2z_i$, then\n\\begin{align*}\n    f(y_i|\\mu_i,\\sigma)&=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-\\frac{(y_i-(\\beta_1+\\beta_2z_i))^2}{2\\sigma^2}\\right)\\\\\n    &=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-\\frac{1}{2\\sigma^2}y_i^2+\\frac{\\beta_1}{\\sigma^2}y_i+\\frac{\\beta_2z_i}{\\sigma^2}y_i-\\frac{(\\beta_1+\\beta_2z_i)^2}{\\sigma^2}\\right). \n\\end{align*}\n$\\eta=(\\frac{\\beta_1}{\\sigma^2}, \\frac{\\beta_2z_i}{\\sigma^2}, -\\frac{1}{\\sqrt{2\\pi}\\sigma})$. So, $\\mathcal{E}=\\mathbb{R}\\times\\mathbb{R}\\times(-\\infty,0)$. \n\\section*{2}\n    \\noindent Because normal distribution is exponential family, $\\bar{X}, S^2$ is the sufficient and complete (because the interior of the natural parameter space is not empty) statistics for $\\mu$ and $\\sigma^2$. And $\\bar{X}\\sim N(\\mu, \\sigma^2/n)$, \n    \\[\n        Var(\\bar{X})=\\mathbb{E}(\\bar{X}^2)-(\\mathbb{E}X)^2, \n    \\]\n    \\[\n        \\mathbb{E}(\\bar{X}^2)=\\mu^2+\\frac{\\sigma^2}{n}. \n    \\]\n    So, \\[\n        \\mathbb{E}\\left(\\bar{X}^2-\\frac{S^2}{n}\\right)=\\mu^2. \n    \\]\n    From \\emph{Lehman-Scheffe theorem}, we can know that $T(X)=\\bar{X}^2-S^2/n$ is UMVU of $\\mu^2$. \n    \\section*{3}\n    \\noindent For Beta($\\alpha. \\alpha$), \n    \\[\n        f(x|\\alpha)=\\mathbf{1}_{0<x<1}\\exp\\left((\\alpha-1)\\log(x(1-x))-\\log\\left(\\frac{\\Gamma^2(\\alpha)}{\\Gamma(2\\alpha)}\\right)\\right). \n    \\]\n    Let $\\eta=\\alpha-1$, then $A(\\eta)=\\log\\frac{\\Gamma^2(\\eta+1)}{\\Gamma(2\\eta+2)}$. And we know that $T(X)=\\log(X(1-X))$ is a sufficient statistics. So, \n    \\[\n        \\begin{aligned}\n            \\mathbb{E}(T(X))=A'(\\eta){}&=\\log(\\Gamma^2(\\eta+1))-\\log(\\Gamma(2\\eta+2))\\\\&=\\frac{2\\Gamma(\\eta+1)\\Gamma'(\\eta+1)}{\\Gamma^2(\\eta+1)}-\\frac{2\\Gamma'(2\\eta+2)}{\\Gamma(2\\eta+2)}\\\\\n            &=\\frac{2\\Gamma(\\alpha)\\Gamma'(\\alpha)}{\\Gamma^2(\\alpha)}-\\frac{2\\Gamma'(2\\alpha)}{\\Gamma(2\\alpha)}\n        \\end{aligned}\n    \\]\n    where $\\Gamma'(n)=(n-1)!\\left(\\sum_{i=1}^{n-1}\\frac{1}{i}-\\gamma\\right)$, $\\gamma$ is Euler's constant. \n    \\section*{4}\n    \\noindent For Gamma distribution, \n    \\[\n        f(\\mathbf{x}|\\alpha_0, \\lambda)=\\frac{\\prod{x_i}^{\\alpha_0-1}}{\\Gamma^n(\\alpha_0)}\\exp\\left(-\\lambda\\sum^n x_i+n\\alpha_0\\log(\\lambda)\\right). \n    \\]\n    So, $T(X)=\\bar{X}$ is a sufficient and complete statistics for $\\lambda$. Next, we need to prove that $X_1/\\bar{X}$ is an ancillary statistics. \n\n    Let $Z\\sim\\Gamma(\\alpha_0, 1)$, then \n    \\[\n        X\\sim\\lambda^{\\alpha_0}e^{-\\lambda}Z, \\quad \\bar{X}\\sim \\lambda^{\\alpha_0}e^{-\\lambda}\\bar{Z}. \n    \\]\n    So, \n    \\[\n        \\frac{X_1}{\\bar{X}}\\sim\\frac{\\lambda^{\\alpha_0}e^{-\\lambda}Z_1}{\\lambda^{\\alpha_0}e^{-\\lambda}\\bar{Z}}=\\frac{Z_1}{\\bar{Z}}. \n    \\]\n    This ratio is independent on $\\lambda$, i.e., it is an ancillary statistics. So, from \\emph{Basu theorem}, $X_1/\\bar{X}$ is independent with $\\bar{X}$. \n    \\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    \\section*{6}\n    \\noindent  For Poisson distribution, \n    \\[\n        f(x=k|\\lambda)=\\frac{\\lambda^k}{k!}e^{-\\lambda}=1/k!\\exp\\left(k\\log\\lambda-\\lambda\\right), \n    \\]\n    \\[\n        f(X=K|\\lambda)=1\\Big/\\prod k_i!\\exp\\left(\\log\\lambda\\sum_{i=1}^n(k_i)-n\\lambda\\right). \n    \\]\n    So, \\(T(X)=\\sum_{i=1}^{n} X_{i}\\) is sufficient and complete for \\(\\lambda\\). Let $\\log\\lambda=\\theta$, \n    \\[\n        \\mathbb{E}(T)=\\left(ne^\\theta\\right)'=n\\lambda. \n    \\]\n    Hence, UMVU for $\\lambda$ is $T/n$. Let $h(t)$ be UMVU for $\\lambda^r$, then\n    \\[\n        \\mathbb{E}(h(T))=\\sum_{i=0}^\\infty\\frac{h(i)n^i}{i!}\\lambda^i=e^{n\\lambda}\\lambda^r=\\sum_{i=0}^\\infty\\frac{(n\\lambda)^i}{i!}\\lambda^r. \n    \\]\n    Then, compare the coefficients for both sides, when $t<r$, \n    \\[\n        h(t)=0. \n    \\]\n    But when $t\\geqslant r$, \n    \\[\n        h(t)=\\frac{t!}{n^r(t-r)!}. \n    \\]\n\\end{document}", "meta": {"hexsha": "516f1f5f847fca6b9fde34bb5e9c2b86058ce6ce", "size": 4673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/midterm1/Midterm.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/Midterm.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/Midterm.tex", "max_forks_repo_name": "Addasecond86/MS-Stat-Tulane", "max_forks_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.8137254902, "max_line_length": 253, "alphanum_fraction": 0.5610956559, "num_tokens": 1909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430604060731, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.6654896069940511}}
{"text": "\\section{Operators on Complex Vector Spaces}\n\\subsection{Generalized Eigenvectors and Nilpotent Operators}\n  \\paragraph{3.}\n  \\begin{proof}\n    Suppose $\\dim V= N$. \n    \\begin{align*}\n      v\\in G(T\\inv, \\lambda\\inv) \n      &\\Leftrightarrow (T\\inv v-\\lambda\\inv I)^nv = 0 \\\\\n      &\\Leftrightarrow \n        \\left(\\sum_{k=0}^n\\binom{n}{k}T^{-k}(-\\lambda\\inv)^{n-k}\\right)v=0 \\\\\n      &\\Leftrightarrow\n        T^n(-\\lambda)^n\n        \\left(\\sum_{k=0}^n\\binom{n}{k}T^{-k}(-\\lambda)^{k-n}\\right)v=0 \\\\\n      &\\Leftrightarrow\n        \\left(\\sum_{k=0}^n\\binom{n}{k}T^{n-k}(-\\lambda)^{k}\\right)v=0 \\\\\n      &\\Leftrightarrow (T-\\lambda I)^nv = 0 \\\\\n      &\\Leftrightarrow v\\in G(T,\\lambda).\n    \\end{align*}\n  \\end{proof}\n\n  \\paragraph{5.}\n    Intuitively, $\\nul T,\\dots,\\nul T^n$ is a sequence of subspaces where the \n    preceding ones are contained by succeeding ones. And $T^{k}v$ lies in the \n    additional part between two successive subspaces.\n  \\begin{proof}\n    Note that $T^{m-1}v\\ne 0$ but $T^mv=0$ implies for $k=1,\\dots,m$\n    \\[\n      T^{m-k}v\\in\\nul T^k,\\quad T^{m-k}v\\notin\\nul T^{k-1}.\n    \\]\n    Therefore, $T^{m-k}v\\notin\\spn(T^{m-1}v,\\dots,T^{m-k+1}v)$; otherwise, \n    $T^{m-k}v=x_1T^{m-1}v+\\cdots+x_{m-k+1}T^{m-k+1}v$, implying that $T^{m-k}v\n    \\in\\nul T^{k-1}$. Hence, $v, \\dots, T^{m-1}v$ are linearly independent.\n  \\end{proof}\n\n  \\paragraph{7.}\n  \\begin{proof}\n    It follows immediately from 8.19.\n  \\end{proof}\n\n  \\paragraph{9.}\n  \\begin{proof}\n    Suppose that $v$ is nonzero and $(TS-\\lambda I)v=0$. Then \n    \\[\n      (STS-\\lambda S)v=0 \\quad\\Rightarrow\\quad\n      (ST-\\lambda I)Sv=0.\n    \\]\n    If $Sv=0$, then $0=(TS-\\lambda I)v=T(Sv)-\\lambda v$ implies $\\lambda=0$. If\n    $Sv\\ne 0$, then $\\lambda$ is an eigenvalue of $ST$ and therefore equals $0$\n    by Exercise 7. Hence, in every case, $\\lambda=0$. Thus, $TS$ is also \n    nilpotent.\n  \\end{proof}\n\n  \\paragraph{13.}\n  \\begin{proof}\n    We are going to show that $N^{k-1}=0$ if $N^k=0$ for $k>1$ to conclude that \n    $N=0$. Suppose that $N^k=0$ and let $M=N^{k-1}$. Then for every $v\\in V$,\n    \\[\n      \\|M^*Mv\\|^2 = \\langle M^*Mv, M^*Mv\\rangle\n      = \\langle M^*MM^*Mv,v\\rangle = \\langle M^*M^*MMv,v\\rangle.\n    \\]\n    Since $M^2=N^{2k-2}=0$, this implies $M^*M=0$. Hence, with the polar \n    decomposition, $M=0$.\n  \\end{proof}\n\n  \\paragraph{15.}\n  \\begin{proof}\n    Suppose $\\dim V=n$. Since $\\nul N^{n-1}\\ne\\nul N^n$,\n    \\[\n      0<\\dim N < \\cdots < \\dim N^n.\n    \\]\n    Hence, $\\dim\\nul N^j=j$ for $0\\le j\\le n$. Since $\\dim\\nul N^n=n$, $\\nul N^n\n    =V$ and therefore $N$ is nilpotent.\n  \\end{proof}\n% end\n\n\\subsection{Decomposition of an Operator}\n  \\paragraph{10.}\n  \\begin{proof}\n    By 8.29, there exists a basis of $V$ with respect to which $\\mathcal{M}(T)$\n    has the form described in 8.29. Suppose $\\mathcal{M}(D)$ be the diagonal\n    matrix whose diagonal entries are the ones of $\\mathcal{M}(T)$ and \n    $\\mathcal{M}(N)=\\mathcal{M}(T)-\\mathcal{M}(D)$. Clear that $N$ is nilpotent\n    and \n    \\[\n      \\mathcal{M}(N) = \n      \\begin{bmatrix}\n        A_1-\\lambda_1 I_1 &        & 0 \\\\\n                          & \\ddots &   \\\\\n        0                 &        & A_m-\\lambda_m I_m\n      \\end{bmatrix}\n    \\]\n    where each $I_k$ is the identity matrix with corresponding size. Note that\n    $\\lambda_k I_k$ and $A_k-\\lambda_k I_k$ are commuting. Hence, by Problem 9,\n    $\\mathcal{M}(N)$ and $\\mathcal{M}(D)$ are commuting and so do $D$ and $N$.\n  \\end{proof}\n% end\n", "meta": {"hexsha": "d42843bff5a03a1ce07a6cd1c81d588857d07aaa", "size": 3472, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear_algebra_done_right_3rd/ch8_opertators_on_complex_vector_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": "linear_algebra_done_right_3rd/ch8_opertators_on_complex_vector_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": "linear_algebra_done_right_3rd/ch8_opertators_on_complex_vector_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": 35.793814433, "max_line_length": 80, "alphanum_fraction": 0.5708525346, "num_tokens": 1338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.665489602272577}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage[english]{babel}\n\\usepackage{amsthm}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{enumerate}\n\n\\author{Jayadev Naram}\n\\title{Number Theory and Cryptology}\n\n\n\\begin{document}\n\\maketitle \n\n\\part{Number Theory}\n  \n\\newtheorem{theorem}{Theorem}\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{mydef}{Definition}\n\\newtheorem*{remark}{Remark}\n\\newtheorem*{prop}{Proposition}\n\\newcommand{\\leg}[2]{\\big(\\frac{#1}{#2}\\big)}\n\\newcommand{\\modp}[2]{#1(mod\\;#2)}\n\t\n\\begin{mydef}[Binary Operation]\nA binary operation on a set S is a function from $S\\times{S}$ to $S$.\n\\\\* Eg: $A:\\mathbb{Z}\\times{\\mathbb{Z}} \\to \\mathbb{Z}$, i.e, $(a,b) \\mapsto a+b$\n\\end{mydef}\n\n\\begin{mydef}[Domain]\nA domain is triple $(D,+,\\cdot), where\\, \\vert{D}\\vert > 1 \\;and\\; + \\;and\\; \\cdot \\;are\\; two\\; operations\\; on\\; D\\; such\\; that\\;{:}$\n\\begin{enumerate}[i)]\n\t\\item $a+b = b+a \\;and\\; a\\cdot{b} = b\\cdot{a}, \\forall\\, a,b \\in D$\n\t\\item $(a+b)+c = a+(b+c) \\;and\\; (a\\cdot{b})\\cdot{c} = a\\cdot(b\\cdot{c}), \\forall\\, a,b,c \\in D$\n\t\\item $\\exists\\, 0,1 \\in D, a+0 = a\\;and\\;a\\cdot{1} = a, \\forall a \\in D$\n\t\\item $a\\cdot(b+c) = a\\cdot{b} + a\\cdot{c}, \\forall\\, a,b,c \\in D$\n\t\\item $\\forall\\,a\\in D, \\exists\\,\\;a^{\\prime},\\;a+a^{\\prime} = 0$\n\t\\item $a\\cdot{b} = 0 \\implies either\\;a\\, = 0\\;or\\;b= 0$\n\\end{enumerate}\nEg: $(\\mathbb{Z},+,\\cdot) \\;and\\; (\\mathbb{R}[X],+,\\cdot), where\\; \\mathbb{R}[X]$ is the Set of real polynomials\n\\end{mydef}\n\n\\begin{mydef}[Field]\nIf every non-zero elements of a domain D has an inverse, i.e, units are $D-\\{0\\}$, then D is called a field.\n\\end{mydef}\n\n\\section*{Division Algorithm}\n\n\\begin{theorem}\nLet $a \\in \\mathbb{Z}$ and $b \\in \\mathbb{N}$. Then $\\exists$ unique q,r $\\in \\mathbb{Z}$ such that $$a=bq+r,\\, 0\\,{\\le}r<b$$\n\\end{theorem}\n\n\\begin{proof}\nIf $a=0$ (trivial). Let's prove for $a \\in \\mathbb{N}$ by induction. \nIf $a = 1$, take $r = 1$ and $q = 0$ (Base Case).\nAssume the statement is true $\\forall n \\in \\mathbb{N}, n < a$, then we prove the statement for a. \nIf $a \\ge b\\, then\\; a-b<a$. \nThen by induction, we have $$a-b = qb+r, \\; 0\\, \\le r <b \\implies a = (q+1)b+r$$\nIf $a<b$, then take $q = 0 \\;and\\;r=a$. Hence the theorem is proved for $a\\in \\mathbb{N}$ \\\\\nNow let $a\\in \\mathbb{Z}_{-}$. Then $-a\\in\\mathbb{N}$. \n\\begin{align*}\n&\\exists\\; \\text{q and r,} -a = bq+r,\\,  0\\, \\le r <b \\\\\n&\\implies a = (-q)b + (-r) \\\\\n&\\implies a = (-q-1)b + (b-r),\\; where\\;  0\\, \\le b- r <b\n\\end{align*}\nThis ends the existence proof.\\\\\nNow we prove the uniqueness. Let $(q,r) and (q^{\\prime},r^{\\prime})$ be two pairs that satisfy the theorem. Then,\n$$a=bq+r,\\, 0\\,{\\le}r<b$$\n$$a=bq^{\\prime}+r^{\\prime},\\, 0\\,{\\le}r^{\\prime}<b$$\nWLOG, assume $r^{\\prime}\\ge r$, then\n\\begin{align*}\n&\\implies 0\\;\\le r^{\\prime}-r<b \\\\\n&\\implies bq+r = bq^{\\prime}+r^{\\prime} \\\\\n&\\implies b(q-q^{\\prime}) = r^{\\prime}-r \\\\\n&\\implies b\\,|\\,(r^{\\prime}-r) \\\\\n&\\implies r^{\\prime}=r \\;and\\; q^{\\prime}=q \\qquad(\\text{since }r^{\\prime}-r<b)\n\\end{align*}\nThis completes the uniqueness proof.\n\\end{proof}\n\n\\begin{lemma}[Modified Division Algorithm]\nLet $a \\in \\mathbb{Z}$ and $b \\in \\mathbb{N}$. Then $\\exists$ unique q,r $\\in \\mathbb{Z}$ such that $$a=bq+r,\\, \\vert r\\vert\\le \\frac{b}{2}$$\n\\end{lemma}\n\n\\begin{theorem}\nLet $a(X),\\,b(X) \\in \\mathbb{R}[X]$. Then $\\exists$ q(X),r(X) $\\in \\mathbb{R}[X]$ such that $$a(X)=b(X)q(X)+r(X),\\, either\\; r(X) = 0 \\;or\\; deg(r(X))<deg(b(X))$$\n\\end{theorem}\n\n\\begin{proof}\nProof by induction on deg(a(X)). If $deg(a(X))<deg(b(X))$, then take $q(X) = 0 \\;and\\; r(X) = a(X)$. If $deg(b(X)) = 0,$ i.e, $b(X) = b_{0}$, then take $q(X) = {b_{0}}^{-1}a(X)$ and $r(X) = 0$.\\\\\nNow assume $deg(b(X)) > 0$ and $deg(a(X))\\ge deg(b(X))$ and also assume the theorem is true $\\forall\\; h(X) \\in \\mathbb{R}[X],\\; deg(h(X))<deg(a(X))$. \\\\\nThen if $deg(a(X)) = m \\;and\\; deg(b(X)) = n$,\n\\begin{align*}\n&\\implies a(X) = a_{0} + a_{1}X + \\cdots + a_{m}X^{m}\\\\\n& and\\;\\;\\;\\; b(X) = b_{0} + b_{1}X + \\cdots + b_{n}X^{n},\\qquad(m\\ge n)\n\\end{align*}\nNow consider the polynomial $g(X) = a(X)-{b_{n}}^{-1}a_{m}X^{m-n}b(X)$. It can be easily verified that $deg(g(X)) < m$. Then,\n$$\\exists\\; q(X),r(X)\\in \\mathbb{R}[X], g(X) = b(X)q(X)+r(X),$$\n\\begin{flushright}\n$where\\; r(X) = 0\\,\\; or\\; deg(r(X)) \\le deg(b(X))$\n\\end{flushright}\n\\begin{align*}\n&\\implies a(X)-{b_{n}}^{-1}a_{m}X^{m-n}b(X) = b(X)q(X)+r(X) \\\\\n&\\implies a(X) = b(X)(q(X)+{b_{n}}^{-1}a_{m}X^{m-n})+r(X),\n\\end{align*}\n\\begin{flushright}\n$where\\;r(X) = 0\\,\\; or\\; deg(r(X)) \\le deg(b(X))) $\n\\end{flushright}\n\\end{proof}\n\n\\begin{mydef}[Unit]\nThe multiplicatively invertible elements in a domain are caleed units of a domain.\n\\\\* Eg: Units in $\\mathbb{Z} = \\{\\pm 1\\}$ and Units in $\\mathbb{R}[X] = \\{c\\mid c \\in \\mathbb{R}-\\{0\\}\\}$\n\\end{mydef}\n\n\\begin{mydef}[Prime]\na is prime if $a = uv \\implies$ either u or v is a unit, but not both.\n\\end{mydef}\n\n\\begin{mydef}[Associate]\nb is an associate of a if $a\\mid b \\; and \\; b\\mid a$ or equivalently $a = ub$, where u is a unit.\n\\end{mydef}\n\n\\begin{theorem}\nIf x is a prime and u is a unit, then ux is also a prime.\n\\end{theorem}\n\n\\begin{proof}\nSuppose $ux=st$. Since u is a unit, $x=(u^{-1}s)t$. But we know, x is a prime, then either of $u^{-1}s \\; or \\; t$ is a unit. If t is unit, proof is completed. Else $u^{-1}s$ must be a unit. We know that the product of two units is again a unit. So is $uu^{-1}s$, i.e, s is a unit.\n\\end{proof}\n\n\\begin{mydef}[Greatest Common Divisor]\nd is said to be gcd of a and b if $d\\mid a\\;and\\;d\\mid b$ and every common divisor c of a and b must divide d, i.e, if $c\\mid a\\;and\\;c\\mid b$, then $c\\mid d$. It is written as d = (a,b).\n\\end{mydef}\n\n\\begin{remark}\nIf d is a gcd a and b and then an associate of d is also a gcd of a and b, i.e, if u is a unit, then $d = (a,b) = ud$.\n\\end{remark}\n\n\\begin{mydef}\nIf a and b $\\in\\; \\mathbb{Z}$, then we define $$a\\mathbb{Z}+b\\mathbb{Z} = \\{ax+by\\mid x, y\\in\\mathbb{Z}\\}$$\n\\end{mydef}\n\n\\begin{remark}\nIt can be seen that $a,b \\in a\\mathbb{Z}+b\\mathbb{Z}$ and if $s_{1} \\;and\\; s_{2} \\in a\\mathbb{Z}+b\\mathbb{Z}$ then $s_{1}x+s_{2}y \\in a\\mathbb{Z}+b\\mathbb{Z},\\; \\forall x,y \\in\\mathbb{Z}$. Therefore $a\\mathbb{Z}+b\\mathbb{Z} \\cap \\mathbb{N} \\neq \\emptyset$.\n\\end{remark}\n\n\\begin{theorem}\nIf a, b $\\in \\mathbb{Z}$, then $\\exists d \\in \\mathbb{Z}, a\\mathbb{Z}+b\\mathbb{Z} = d\\mathbb{Z}\\text{, where }d = (a,b).$\n\\end{theorem}\n\n\\begin{proof}\nWe first prove the existence of such a d. Since $a\\mathbb{Z}+b\\mathbb{Z} \\cap \\mathbb{N} \\neq \\emptyset$, let d be is least natural number in $a\\mathbb{Z}+b\\mathbb{Z}$. Then $d\\mathbb{Z} \\subseteq a\\mathbb{Z}+b\\mathbb{Z}$. Now let $s \\in a\\mathbb{Z}+b\\mathbb{Z}$, then by division algorithm on $\\mathbb{Z},$ \n\\begin{align*}\n&\\exists \\,q,r \\in \\mathbb{Z}, s = qd+r, 0\\,\\le r < d. \\\\\n&\\implies r = s-qd \\in \\mathbb{Z} \\\\\n&\\implies r = 0,\\, i.e,\\; s = qd \\\\\n&\\implies a\\mathbb{Z}+b\\mathbb{Z} \\subseteq d\\mathbb{Z} \\\\\n& \\;\\;Therefore,\\; a\\mathbb{Z}+b\\mathbb{Z} = d\\mathbb{Z}.\n\\end{align*}\nNow we prove that $d  = (a,b)$. Since $a,b \\in a\\mathbb{Z}+b\\mathbb{Z},\\, d\\mid a \\;and\\; d\\mid b$. But $d \\in a\\mathbb{Z}+b\\mathbb{Z}, \\;so\\; d=ax+by$ for some $x,y\\in\\mathbb{Z}$. Suppose $c\\mid a\\;and\\;c\\mid b$, then $a = a_{1}c \\;and\\; b=b_{1}c$. Then $d = c(xa_{1}+yb_{1})$, implies $c\\mid d$.\n\\end{proof}\n\n\\begin{corollary}\nIf $a\\mid bc\\;and\\;(a,b) = 1,\\;then\\;a\\mid c$.\n\\end{corollary}\n\n\\begin{theorem}\n$\\mathbb{Z}$ is a UFD (Unique factorization Domain), i.e, every non-zero, non-unit can be written as product of primes and this factorzation is unique upto order and association, i.e, if n is a non-zero, non-unit in $\\mathbb{Z}$, and $n = p_{1}p_{2}{\\cdots}p_{r} = q_{1}q_{2}{\\cdots}q_{s}$, where ${p_{i}}^{\\prime}s$ and ${q_{i}}^{\\prime}s$ are primes, then $r=s$ and every $p_{i}$ is an associate of some $q_{j}$ and vice versa.\n\\end{theorem}\n\n\\begin{proof}\nThe exitence of such factorization can be proved by using stroing induction for non-negative integers and using this result, we can multiply by a -1 (unit) and show it's true for negative integers as well. \\\\\nNow, we prove the uniqueness by induction. Suppose n is a non-zero, non-unit.$$Suppose\\;n = p_{1}p_{2}{\\cdots}p_{r} = q_{1}q_{2}{\\cdots}q_{s}.$$\nIf $r = 1\\;(Base\\;Case),\\;then\\; n = p_{1} = q_{1}q_{2}{\\cdots}q_{s}$. But $p_{1}$ is a prime, therefore, $s=1\\;and\\;n=p_{1}=uq_{1},$ where u is a unit. Assume the statement is true $\\forall\\;a\\in\\mathbb{N},\\;a<n$. Now we prove the statement for n. $$p_{r}\\mid n,\\;i.e,\\; p_{r}\\mid q_{1}(q_{2}{\\cdots}q_{s}).$$\n$$\\text{If }(p_{r},q_{1})=1\\implies p_{r}\\mid q_{2}(q_{3}{\\cdots}q_{s})$$\nThis way, we get some $q_{j}$ which is an associate of $p_{r}$. WLOG, we can assume $p_{r}$ is an associate of $q_{s}$, i.e, $up_{r} = q_{s}.$\n\\begin{align*}\n&\\implies p_{1}p_{2}{\\cdots}p_{r} - uq_{1}q_{2}{\\cdots}q_{s-1}p_{r}=0 \\\\\n&\\implies p_r(p_{2}{\\cdots}p_{r-1} - uq_{1}q_{2}{\\cdots}q_{s-1}) = 0 \\\\\n&\\implies p_{2}{\\cdots}p_{r-1} = uq_{1}q_{2}{\\cdots}q_{s-1} < n\n\\end{align*}\n\\end{proof}\n\n\\begin{mydef}[$\\mathbb{Z}\\lbrack\\omega\\rbrack$]\n$\\mathbb{Z}\\lbrack\\omega\\rbrack = \\{a+b\\omega\\mid a,b\\in \\mathbb{Z}\\} \\subset \\mathbb{C}$, where $\\omega  = \\frac{-1\\pm i\\sqrt{3}}{2}$.\n\\begin{center}\nand $N(\\alpha) = {\\alpha}\\bar{\\alpha}.$ \\\\\n\\end{center}\n\\end{mydef}\n\n\\begin{remark}\nIf $\\alpha = a+b\\omega,$ then \n\\begin{align*}\nN(a+b\\omega) &= (a+b\\omega)(\\overline{a+b\\omega}) \\\\\n&= (a+b\\omega)(a+b{\\omega}^{2}) \\\\\n&= a^2 - ab + b^2 \\\\\n&= \\frac{(2a-b)^2+3{b^2}}{4}\n\\end{align*}\n\\end{remark}\n\n\\begin{remark}\nThe only element whose norm is 0 is 0.\n\\end{remark}\n\n\\begin{prop}\n$\\alpha \\in \\mathbb{Z}[\\omega]$ is a unit iff $N(\\alpha) = 1$.\n\\end{prop}\n\n\\begin{proof}\nSuppose $N(\\alpha) = 1$, then ${\\alpha}\\overline{\\alpha} = 1$. Therefore $\\alpha$ is a unit in $\\mathbb{Z}[\\omega]$. \\\\\nConversely, suppose $\\alpha$ is a unit $\\mathbb{Z}[\\omega]$.\n\\begin{align*}\n&\\exists {\\alpha}^{\\prime} \\in \\mathbb{Z}[\\omega], \\alpha{\\alpha}^{\\prime} = 1 \\\\\n&\\implies N(\\alpha{\\alpha}^{\\prime}) = 1 \\\\\n&\\implies N(\\alpha)N({\\alpha}^{\\prime}) = 1 \\\\\n&\\implies N(\\alpha)= 1 \\qquad(since,\\; N(\\alpha) \\in \\mathbb{N}, \\forall\\; \\alpha \\in \\mathbb{Z}[\\omega]).\n\\end{align*}\n\\end{proof}\n\n\\begin{theorem}\nThe units in $\\mathbb{Z}[\\omega]$ are $\\pm 1,\\;\\pm \\omega,\\;\\pm {\\omega}^{2}$.\n\\end{theorem}\n\n\\begin{theorem}\nThere is no element in $\\mathbb{Z}[\\omega]$ with norm 2.\n\\end{theorem}\n\n\\begin{theorem}\nThe only elements in $\\mathbb{Z}[\\omega]$ with norm 3 are $\\pm \\pi,\\;\\pm \\pi\\omega,\\;\\pm \\pi{\\omega}^{2}$, where $\\pi = 1-\\omega$.\n\\end{theorem}\n\n\\begin{theorem}\n$\\mathbb{Z}[\\omega]$ is a Euclidean Domain, i.e, $$\\forall \\alpha, \\beta \\in \\mathbb{Z}[\\omega],\\;\\beta\\neq 0,\\;\\exists \\gamma,\\delta \\in \\mathbb{Z}[\\omega],\\alpha=\\beta\\gamma+\\delta, N(\\delta)<N(\\beta).$$\n\\end{theorem}\n\n\\begin{proof}\nLet $\\alpha = a+b\\omega,\\;\\beta = c+d\\omega,a,b,c,d\\in\\mathbb{Z}[\\omega],\\;\\beta\\neq 0$, then $c,d\\neq 0$.\n\\begin{enumerate}[$\\text{Case }$i)]\n\t\\item Let $d=0$. Then by Modified Division Algorithm, we have \n\t\\begin{align*}\n\ta &= cq_{1}+r_{1}, \\qquad(q_{1},r_{1}\\in\\mathbb{Z}\\;and\\;\\vert r_{1}\\vert\\le\\frac{c}{2})\\\\\n\tb &= cq_{2}+r_{2}, \\qquad(q_{2},r_{2}\\in\\mathbb{Z}\\;and\\;\\vert r_{2}\\vert\\le\\frac{c}{2})\\\\\n\t\\implies \\;\\;\\;\\;\\;\\;\\alpha &= a+b\\omega = c(q_{1}+q_{2}\\omega)+(r_{1}+r_{2}\\omega) \\\\\n\t\\implies N(\\delta) &= N(r_{1}+r_{2}\\omega) \\\\\n\t&= {r_{1}}^2-r_{1}r_{2}+{r_{2}}^2 \\\\\n\t&\\le {\\vert r_{1}\\vert}^2+\\vert r_{1}\\vert\\vert r_{2}\\vert+{\\vert r_{2}\\vert}^2 \\\\\n\t&= \\frac{c^2}{4} + \\frac{c^2}{4} + \\frac{c^2}{4} \\\\\n\t&= \\frac{3c^2}{4} < c^2 = N(b) = N(\\beta)\n\t\\end{align*}\n\t\\item If $d\\neq 0,$ consider $\\alpha^{\\prime} = \\alpha\\overline{\\beta},\\;\\beta^\\prime = \\beta\\overline{\\beta}$,\\;then\\;$\\beta^\\prime \\in \\mathbb{Z}$, then by Case i), $$\\exists \\gamma^\\prime,\\delta^\\prime\\in\\mathbb{Z}[\\omega],\\alpha^\\prime = \\beta^\\prime\\gamma^\\prime+\\delta^\\prime, N(\\delta^\\prime)<N(\\beta^\\prime)={(N(\\beta))}^2.$$\nLet $\\delta = \\alpha-\\beta\\gamma$, then $\\delta\\overline{\\beta} = \\alpha\\overline{\\beta}-\\beta\\overline{\\beta}\\gamma = \\delta^\\prime. N(\\delta\\beta^\\prime) = N(\\delta^\\prime) < (N(\\beta))^2$\n\\begin{align*}\n&\\implies N(\\delta)N(\\beta)<(N(\\beta))^2 \\\\\n&\\implies N(\\delta)<N(\\beta).\n\\end{align*}\n\\end{enumerate}\n\\end{proof}\n\n\\begin{theorem}\nIf $\\alpha, \\beta \\in \\mathbb{Z}[\\omega]$, then $\\exists\\;\\delta \\in \\mathbb{Z}[\\omega], \\alpha\\mathbb{Z}[\\omega]+\\beta\\mathbb{Z}[\\omega] = \\delta\\mathbb{Z}[\\omega],\\\\ \\text{ where }\\delta = (\\alpha,\\beta).$\n\\end{theorem}\n\n\\begin{mydef}[]\nIf $a,b,m\\in\\mathbb{Z}$ and $m\\neq0$, we say thata is congruent to b modulo m if  $m\\mid b-a$. This relation is written $a\\equiv b\\;(m).$\n\\end{mydef}\n\n\\begin{mydef}[$\\mathbb{Z}_{n},\\;+_{n},\\;\\cdot_{n}$]\n-FILL IN-\n\\end{mydef}\n\n\\begin{theorem}\nIf $a\\in\\mathbb{Z}_n-\\{0\\}$ is a unit iff $(a,n)=1.$\n\\end{theorem}\n\n\\begin{proof}\nLet $a\\in\\mathbb{Z}_n-\\{0\\}$ be a unit. Then $\\exists\\,a^\\prime\\in\\mathbb{Z}_n-\\{0\\}$, such that $a\\cdot_n a^\\prime=1$, i.e, $\\exists\\;q,\\;aa^\\prime=qn+1.$ $$\\implies (a,n)=1.$$ \nNow let $(a,n)=1$, then $\\exists\\,u,v\\in\\mathbb{Z},\\;au+nv=1$. By Division Algorithm, $\\exists\\,q,r,\\;such\\;that\\;u=qn+r,\\,r\\in\\mathbb{Z}_n.$\n\\begin{align*}\n&\\implies a(qn+r)+nv=1 \\\\\n&\\implies ar=n(-aq-v)+1 \\\\\n&\\implies a\\cdot_n r=1 \\qquad(Since,\\;a,r\\in\\mathbb{Z}_n).\n\\end{align*}\nTherefore, a is a unit in $\\mathbb{Z}_n.$\n\\end{proof}\n\n\\begin{mydef}\nWe define $U_n$ to be the set of all units in $\\mathbb{Z}_n$ and $\\phi(n)$ to be the cardinality of $U_n$, where $\\phi_n$ is called Euler totient function, i.e, $$U_n=\\{a\\in\\mathbb{Z}_n-\\{0\\}\\mid (a,n)=1\\},\\;\\phi(n)=\\vert U_n\\vert.$$\nWe define $\\phi(1)=1.$\n\\end{mydef}\n\n\\begin{remark}\nIf $n=p,$ p is prime, then every element is relatively prime to p, i.e, $U_p=\\mathbb{Z}_p-\\{0\\}=\\{1,2,\\cdots,p-1\\}$. And also $(\\mathbb{Z}_p,+_p,\\cdot_p)$ is a field. If $n=p^t,\\;\\phi(n)=p^{t-1}(p-1).$ If $n=pq,\\;\\phi(n)=(p-1)(q-1).$\n\\end{remark}\n\n\\begin{theorem}[Euler's Theorem]\nIf $(a,n)=1$, then $a^{\\phi(n)}\\equiv 1\\,(mod\\,n).$\n\\end{theorem}\n\n\\begin{proof}\nLet's prove it for elements in $U_n$ first and then for any element in general. Let $U_n = \\{a_1,a_2,\\cdots,a_{\\phi(n)}\\}$ and let $a\\in U_n.$ Then,\n$$a\\cdot_n U_n=\\{a\\cdot_n a_1,a\\cdot_n a_2,\\cdots,a\\cdot_n a_{\\phi(n)}\\}\\subseteq U_n$$\n\\textbf{Claim.} All elements of $a\\cdot_n U_n$ are distinct, i.e, $a\\cdot_n U_n = U_n$. \\\\\nWe prove this by contradiction. Assume, $a\\cdot_n a_i = a\\cdot_n a_j,\\;such\\;that\\;i\\neq j$. Then $a^{-1}\\cdot_n a\\cdot_n a_i = a^{-1}\\cdot_n a\\cdot_n a_j$, hence $a_i=a_j$. Therefore, $a\\cdot_n U_n = U_n$. \n\\begin{align*}\n&\\implies \\prod_{i=1}^{\\phi(n)}a\\cdot_n a_i = \\prod_{j=1}^{\\phi(n)}a_j \\\\\n&\\implies a^{\\phi(n)}\\Bigg(\\prod_{i=1}^{\\phi(n)}a_i\\Bigg) = \\prod_{j=1}^{\\phi(n)}a_j \\\\\n&\\implies a^{\\phi(n)}b = b,\\;where\\;b=\\prod_{i=1}^{\\phi(n)}a_i \\in U_n \\\\\n&\\implies a^{\\phi(n)} = 1\\;in\\;(\\mathbb{Z}_{n},\\;+_{n},\\;\\cdot_{n}).\n\\end{align*}\nNow, let's prove the theorem for any $a\\in\\mathbb{Z},\\;such\\;that\\;(a,n)=1.$\nBy Division Algorithm, $\\exists\\,q,r,\\;such\\;that\\;a=qn+r,\\,r\\in\\mathbb{Z}_n.$ Since $(a,n)=1$, we have $(r,n)=1$.\n\\begin{align*}\n\\implies a^\\phi(n) &= (qn+r)^{\\phi(n)} \\\\\n&= r^{\\phi(n)} +  \\binom{\\phi(n)}{1}(nq)+\\cdots+(nq)^{\\phi(n)} \\\\\n&= r^{\\phi(n)} +nk \\\\\n\\implies a^\\phi(n)-1 &=r^{\\phi(n)}-1+nk \\\\\nBut\\;n\\mid r^{\\phi(n)}-&1,\\;then\\;n\\mid a^{\\phi(n)}-1\\\\\n\\implies a^{\\phi(n)}&\\equiv 1\\,(mod\\,n)\n\\end{align*}\n\\end{proof}\n\\textbf{Notation:} ${\\mathbb{Z}_p}^x=\\mathbb{Z}_p-\\{0\\}\\;and\\;{\\mathbb{Z}_p}^{x^2}$ to be set of elements in ${\\mathbb{Z}_p}^x$ which are square. Here p is a prime.\n\n\\begin{prop}\n$\\vert {\\mathbb{Z}_p}^{x^2}\\vert=\\frac{p-1}{2}$, therefore $\\exists\\,u\\in{\\mathbb{Z}_p}^x$ which is a non-sqaure. Then $u{\\mathbb{Z}_p}^{x^2}$ will be the set of all non-square in ${\\mathbb{Z}_p}^x$.\n\\end{prop}\n\n\\begin{proof}\nFirst, we prove that $\\vert {\\mathbb{Z}_p}^{x^2}\\vert=\\frac{p-1}{2}$. Consider the following mapping:\n\\begin{align*}\n{\\mathbb{Z}_p}^{x} &\\mapsto {\\mathbb{Z}_p}^{x^2} \\\\\nx &\\mapsto x^2 \\\\\n\\implies p-x &\\mapsto (p-x)^2 = p^2-2px+x^2 = x^2 + pk \\\\\n\\implies p-x &\\mapsto x^2\\;in\\;(\\mathbb{Z}_p,+_p,\\cdot_p)\n\\end{align*}\nTherefore this mapping is a 2-1 mapping and hence $\\vert {\\mathbb{Z}_p}^{x^2}\\vert=\\frac{p-1}{2}$. There are $\\frac{p-1}{2}$ non-sqaure elements in ${\\mathbb{Z}_p}^x$. Let u be a non-square. Then consider the following mapping:\n\\begin{align*}\n{\\mathbb{Z}_p}^{x^2} &\\mapsto u{\\mathbb{Z}_p}^{x^2} \\\\\nx^2 &\\mapsto ux^2 \\\\\n\\end{align*}\nWe prove that this mapping is bijective. It is enough to show that all the elements in $u{\\mathbb{Z}_p}^{x^2}$ are distinct and non-squares. Consider two elements $ux^2,uy^2\\in u{\\mathbb{Z}_p}^{x^2}$.\n\\begin{align*}\n\\text{If }ux^2&=uy^2 \\\\\n\\implies u^{-1}ux^2&=u^{-1}uy^2 \\qquad(\\text{since }\\mathbb{Z}_p\\text{ is a field})\\\\\n\\implies x^2&=y^2\n\\end{align*}\nThis shows that all the elements of $u{\\mathbb{Z}_p}^{x^2}$. Now we show that elements of $u{\\mathbb{Z}_p}^{x^2}$ are all the non-sqaure elements in ${\\mathbb{Z}_p}^{x}$. Suppose some element in $u{\\mathbb{Z}_p}^{x^2}$ is a square, i.e,\n\\begin{align*}\n&\\implies ux^2=y^2 \\\\\n&\\implies ux^2x^{-2}=y^2x^{-2} \\\\\n&\\implies u=(yx^{-1})^2 \\in {\\mathbb{Z}_p}^{x^2}\n\\end{align*}\nBut u is a non-square, which is a contradiction. Therefore, this mapping is not just a bijection, but none of the elements in one set belongs to other. Hence, $u{\\mathbb{Z}_p}^{x^2}$ is the set of all non-squares in ${\\mathbb{Z}_p}^x$.\n\\end{proof}\n\n\\begin{remark}\nFrom the above proposition it can be concluded that $${\\mathbb{Z}_p}^x=u{\\mathbb{Z}_p}^{x^2}\\oplus {\\mathbb{Z}_p}^{x^2}.$$\n\\end{remark}\n\n\\begin{mydef}\nWe define a mapping such that,\n\\begin{align*}\n\\mathbb{Z}&\\rightarrow\\mathbb{Z}_n \\\\\nx&\\mapsto\\bar{x},\\bar{x}=\\modp{x}{n}\n\\end{align*}\n\\end{mydef}\n\n\\begin{theorem}\nThe following properties hold for $x,\\,y\\in\\mathbb{Z}$:\n\\begin{align*}\n&i)\\;\\overline{x+y}=\\bar{x}+_n\\bar{y}\n&ii)\\;\\overline{xy}=\\bar{x}\\cdot_n\\bar{y}\n\\end{align*}\nDefine the following mapping from $\\mathbb{Z}_{mn}\\rightarrow\\mathbb{Z}_n$ in the similar way as above. Then the following properties hold:\n\\begin{align*}\n&i)\\;\\overline{x+_{mn}y}=\\bar{x}+_n\\bar{y}\n&ii)\\;\\overline{x\\cdot_{mn}y}=\\bar{x}\\cdot_n\\bar{y}\n\\end{align*}\n\\end{theorem}\n\n\\begin{theorem}[Chinese Remainder Theorem]\nSuppose $(m,n)=1$. Let $\\bar{x}=\\modp{x}{m}$ and $\\bar{\\bar{x}}=\\modp{x}{n}$, $x\\in\\mathbb{Z}.$ Then the following mapping is bijection which preserves operation:\n\\begin{align*}\n\\mathbb{Z}_{mn} &\\rightarrow\\mathbb{Z}_m\\times\\mathbb{Z}_n \\\\\nx&\\mapsto(\\bar{x},\\bar{\\bar{x}})\n\\end{align*}\n\\end{theorem}\n\n\\begin{proof}\nSince the sets are finite, by pigeon hole principle, it is enough to show the mapping $f:\\mathbb{Z}_{mn}\\rightarrow\\mathbb{Z}_m\\times\\mathbb{Z}_n,x\\mapsto(\\bar{x},\\bar{\\bar{x}})$ is onto for it to be bojective, i.e, if $\\forall\\;(u,v)\\in\\mathbb{Z}_m\\times\\mathbb{Z}_n\\;\\exists\\;x\\in\\mathbb{Z}_{mn},$ such that $\\bar{x}=\\modp{x}{m}$ and $\\bar{\\bar{x}}=\\modp{x}{n}$. \\\\\nWe will first show that $\\exists\\;x\\in\\mathbb{Z}$ satisfying the above conditions. Since $(m,n)=1,\\;\\exists\\;M,N\\in\\mathbb{Z},Mm+nN=1.$ Let $x=mMv+nNu,$ then $x-u=mMv+(nN-1)u=mM(v-u)=mq\\implies x=mq+u\\implies \\bar{x}=u.$ Similarly, $\\bar{\\bar{x}}=v.$ So $\\exists\\;x\\in\\mathbb{Z},\\;\\bar{x}=u,\\bar{\\bar{x}}=v$, then by division algortihm, $\\exists\\;r\\in\\mathbb{Z}_{mn},q,\\;x=mnq+r.$ Notice that $u=\\bar{x}=\\overline{mnq+r}=\\overline{mnq}+_m\\bar{r}=\\bar{r}$ and similarly $\\bar{\\bar{r}}=v.$ Therefore, $$\\exists\\;x\\in\\mathbb{Z},\\;\\bar{x}=\\modp{x}{m}\\;and\\;\\bar{\\bar{x}}=\\modp{x}{n}.$$\nWe know,\n\\begin{align*}\n&i)\\;\\overline{x+_{mn}y}=\\bar{x}+_m\\bar{y} &ii)\\;\\overline{x\\cdot_{mn}y}=\\bar{x}\\cdot_m\\bar{y} \\\\\n&i)\\;\\overline{\\overline{x+_{mn}y}}=\\bar{\\bar{x}}+_n\\bar{\\bar{y}} &ii)\\;\\overline{\\overline{x\\cdot_{mn}y}}=\\bar{\\bar{x}}\\cdot_n\\bar{\\bar{y}} \n\\end{align*}\n\\begin{align*}\nf(x+_{mn}y)&=(\\overline{x+_{mn}y},\\overline{\\overline{x+_{mn}y}})\\\\\n&=(\\bar{x}+_m\\bar{y},\\bar{\\bar{x}}+_n\\bar{\\bar{y}})\\\\\n&=(\\bar{x},\\bar{\\bar{x}})+(\\bar{y},\\bar{\\bar{y}})\\\\\n&=f(x)+f(y).\n\\end{align*}\nSimilarly, $f(x\\cdot_{mn}y)=f(x)\\times f(y)$. Here addition(+) and mutliplication($\\times$) are component-wise. Therefore, f is onto and hence bijective(???).\n\\end{proof}\n\n\n\\begin{theorem}\nIf $(m,n)=1,$ then $\\phi(m)=\\phi(m)\\phi(n)$.\n\\end{theorem}\n\n\\begin{proof}\nFirst we show that under this bijection mapping defined above the elements of $U_{mn}$ group map bijetively to the elements of $U_m\\times U_n$, i.e,\n\\begin{enumerate}[i)]\n\\item if $x\\in U_{mn},$ then $\\bar{x}\\in U_m\\;and\\;\\bar{\\bar{x}}\\in U_n.$ If $x\\in\\mathbb{Z}_{mn},$ then $(x,mn)=1$, i.e, $ax+bmn=1$, this implies $(x,m)=1\\;and\\;(x,n)=1$, i.e, $\\bar{x}\\in\\mathbb{Z}_m\\;and\\;\\bar{\\bar{x}}\\in\\mathbb{Z}_n$.\n\\item if $\\bar{x}\\in U_m\\;and\\;\\bar{\\bar{x}}\\in U_n,$ then $x\\in U_{mn}$. Then $\\exists\\;u\\in\\mathbb{Z}_m$ and $v\\in\\mathbb{Z}_n$, such that $\\bar{x}\\cdot_m u=1$ and $\\bar{\\bar{x}}\\cdot_n v=1$. Since f is onto, $\\exists\\;y\\in\\mathbb{Z}_{mn},\\;\\bar{y}=u\\;and\\;\\bar{\\bar{y}}=v.$ Then $\\overline{x\\cdot_{mn}y}=\\bar{x}\\cdot_m\\bar{y}=1$ and $\\overline{\\overline{x\\cdot_{mn}y}}=\\bar{\\bar{x}}\\cdot_m\\bar{\\bar{y}}=1$. Therefore, $f(x\\cdot_{mn}y)=(\\bar{1},\\bar{\\bar{1}})=f(1)$. Since f is one-to-one, $x\\cdot_{mn}y=1,$ i.e, $x\\in U_{mn}$.\n\\end{enumerate}\nTherefore, \n\\begin{align*}\nU_{mn}&\\leftrightarrow U_m\\times U_n\\\\\n\\implies |U_{mn}|&=|U_m||U_n|\\\\\n\\implies \\phi(mn)&=\\phi(m)\\phi(n).\n\\end{align*}\n\\end{proof}\n\n\\begin{theorem}\nSome important facts from group theory that are used later.\n\\begin{enumerate}[i)]\n\\item If order of an element in the group is equal to order of the group, then the group is cyclic.\n\\item Let $(G,*)$ be a finite group and $(H,*)$ be a subgroup of G, then $|H|\\bigm\\vert|G|.$\n\\item In a  finite group the order of an element must divide the order of the group.\n\\item If $a\\in G$, $(G,*)$ be a finite group, then $a^{|G|}=e.$\n\\item If $a\\in G$, $(G,*)$ be a finite group and if $a^i=e,$ then $o(a)\\mid i.$\n\\item If $a\\in G$, $(G,*)$ be a finite group, then $o(a^i)=\\frac{o(a)}{(i,o(a))}$ and $o(a^i)=o(a)$ iff $(i,o(a))=1.$ Therefore, there are $\\phi(n)$ generators in a cyclic group of order n.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{lemma}\n$\\sum_{d\\mid n}\\phi(d)=n\\;\\forall\\;n\\in\\mathbb{N}.$\n\\end{lemma}\n\n\\begin{proof}\nDefine $f(n)=\\sum_{d\\mid n}\\phi(d)$. We show that if $(m,n)=1$, then $f(mn)=f(m)f(n).$ Let $m=p^{e_1}_1p^{e_2}_2\\cdots p^{e_r}_r$ and $n=q^{e_1}_1q^{e_2}_2\\cdots q^{e_s}_s$. If $d\\mid mn$, then $d=(p^{l_1}_1p^{l_2}_2\\cdots p^{l_r}_r)(q^{r_1}_1q^{r_2}_2\\cdots q^{r_s}_s)=d_1d_2,$ such that $(d,m)=d_1$ and $(d,n)=d_2.$\nNow,\n\\begin{align*}\nf(mn)&=\\sum_{d\\mid mn}\\phi(d) = \\sum_{d_1\\mid m,\\;d_2\\mid n}\\phi(d_1d_2)= \\sum_{d_1\\mid m,\\;d_2\\mid n}\\phi(d_1)\\phi(d_2)\\\\\n&=\\sum_{d_1\\mid m}\\phi(d_1)\\sum_{d_2\\mid n}\\phi(d_2)=f(m)f(n)\n\\end{align*}\nLet n be a non-zero, such that $n>1$. Let $n=p^{e_1}_1p^{e_2}_2\\cdots p^{e_r}_r$, where $p_i$'s are distinct primes.\n\\begin{align*}\nf(p^{e_1}_1) &= \\sum_{d\\mid p^{e_1}_1}\\phi(d) = \\phi(1) + \\phi(p_1) + \\phi(p^2_1) + \\cdots + \\phi(p^{e_1}_1) \\\\\n&= 1+p_1+\\cdots+p^{e_1-1}_1(p_1-1) = p^{e_1}_1 \\\\\n\\text{Then, }f(n) &= f(p^{e_1}_1p^{e_2}_2\\cdots p^{e_r}_r) = f(p^{e_1}_1)f(p^{e_2}_2\\cdots p^{e_r}_r) \\\\\n&= p^{e_1}_1p^{e_2}_2\\cdots p^{e_r}_r = n = \\sum_{d\\mid n}\\phi(d).\n\\end{align*}\n\\end{proof}\n\n\\begin{theorem}\nLet $(\\mathbb{F},+,\\cdot)$ be a field and G a finite subgroup of $(\\mathbb{F}-\\{0\\},\\cdot)$, then G is a cyclic group.\n\\end{theorem}\n\n\\begin{proof}\nGiven that $G\\subseteq (\\mathbb{F}-\\{0\\},\\cdot)$ is finite, i.e, $|G|<\\infty$. Let $|G|=n.$ If $d\\mid n$ define $G_d$ as the set containing all the elements in G of order d. We have $G=\\coprod_{d\\mid n}\\,G_d$, then $|G|=\\sum_{d\\mid n}|G_d|$. If $G_d=\\phi,$ then $|G_d|=0.$ Suppose $|G_d|\\neq0,$ let $a\\in G_d$, then $o(a)=d$. \\\\\nConsider $H=\\{1,a,a^2,\\cdots,a^{d-1}\\},\\;a^d=1$. Then $X^d-1$ is a polynomial in $\\mathbb{F}[X]$. Notice that all the elements of H are the roots of the polynomial and these are the only roots of $X^d-1\\;in\\;\\mathbb{F}.$ Therefore, $G_d\\subseteq H$. Notice that the number of elements in H of order d are $\\phi(d)$, since $o(a^i)=o(a)=d$ iff $(i,d)=1$, then $|G_d|=\\phi(d).$ Hence, $G_d = \\phi(d)$ or $0$. \\\\\nWe know, $\\sum_{d\\mid n}\\phi(d)=n$ and $n=\\sum_{d\\mid n}|G_d|$, hence $|G_d|$ is never 0, i.e, $G_d$ is never empty $\\forall\\;d\\mid n$. In particular, $G_n\\neq \\phi$, therefore there exists an element of order n. Hence, G is cyclic.\n\\end{proof}\n\n\\begin{corollary}\n$(\\mathbb{Z}_p-\\{0\\},\\cdot_p)$ is cyclic group in $F=(\\mathbb{Z}_p-\\{0\\},+,\\cdot_p)$.\n\\end{corollary}\n\n\\begin{mydef}[Legendre Symbol]\nLet $c\\in\\mathbb{Z},\\;p$ is an odd prime. Then we define:\n\\[   \n\\leg{c}{p} = \n     \\begin{cases}\t\n       \\;\\;\\,0, &\\quad\\text{if }p\\mid c\\\\\n       \\;\\;\\,1, &\\quad\\text{if }\\exists\\;x\\in{Z},\\,x^2\\equiv c(mod\\;p) \\\\\n      -1, &\\quad\\text{otherwise}\\\\ \n     \\end{cases}\n\\]\n\\end{mydef}\n\n\n\\begin{theorem}\nThe properties of Legendre Symbol are listed below:\n\\begin{enumerate}[i)]\n\\item If $a\\equiv \\modp{b}{p}$, then $\\leg{a}{p}=\\leg{b}{p}.$\n\\item $\\leg{xy}{p}=\\leg{x}{p}\\leg{y}{p}.$\n\\item $\\leg{a}{p}={\\bar{a}}^{(\\frac{p-1}{2})},\\;where\\;\\bar{a}=\\modp{a}{p}.$\n\\item \n\\end{enumerate}\n\\end{theorem}\n\n\\end{document}", "meta": {"hexsha": "0156a4ecad8064ba345f5638320af2916c092d8a", "size": 25126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecnotesNT/lecnotesNT.tex", "max_stars_repo_name": "JayD1/Tex-files", "max_stars_repo_head_hexsha": "b5ea41b81aa993ee00b61440847b9d64edc08e1a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecnotesNT/lecnotesNT.tex", "max_issues_repo_name": "JayD1/Tex-files", "max_issues_repo_head_hexsha": "b5ea41b81aa993ee00b61440847b9d64edc08e1a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecnotesNT/lecnotesNT.tex", "max_forks_repo_name": "JayD1/Tex-files", "max_forks_repo_head_hexsha": "b5ea41b81aa993ee00b61440847b9d64edc08e1a", "max_forks_repo_licenses": ["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.555331992, "max_line_length": 581, "alphanum_fraction": 0.6100851707, "num_tokens": 10806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.6654895977157348}}
{"text": "\\documentclass{article}\n\n\\usepackage[sans, stdmargin, noindent]{../../rajeev}\n\\usepackage{mathtools}\n\\usepackage{dirtytalk}\n\n\\pagestyle{fancy}\n\\rhead{\\today}\n\\lhead{Math 291H HW \\#1}\n\n\\begin{document}\n\n\\begin{center}\n    \\Large \\textbf{Math 291H Homework \\#1}\n\\end{center}\n\\begin{center}\n    \\Large Rajeev Atla\n\\end{center}\n\n\nHonors Pledge Statement: \\say{The writeup of this submission is my own work alone.}\n\n\\problem{1.1}\n\n\\begin{align*}\n  \\pars{3, -1} &= s \\pars{2, 1} + t \\pars{1, 3} \\\\\n  \\pars{3, -1} &= \\pars{2s+t, s+3t} \\\\\n\\end{align*}\n\nWe turn this into a system of equations.\n$$\n\\begin{cases}\n  2s + t = 3 \\\\\n  s+3t = -1 \\\\\n\\end{cases}\n$$\n\nSolving, we find that \\boxed{s=2, t=-1}.\n\n\n\\problem{1.4}\n\n$$\\norm{\\bm{x}} = \\sqrt{4^2 + 7^2 + \\pars{-4}^2 + 1^2 + 2^2 + \\pars{-2}^2} =  \\boxed{\\sqrt{15}}$$\n\n$$\\norm{\\bm{y}} = \\sqrt{2^2 + 1^2 + 2^2 + 2^2 + \\pars{-1}^2 + \\pars{-1}^2} = \\boxed{\\sqrt{11}}$$\n\n\\begin{align*}\n  \\cos \\theta &= \\frac{\\bm{x} \\cdot \\bm{y}}{\\norm{\\bm{x}} \\norm{\\bm{y}}} \\\\\n              &= \\frac{4 \\cdot 2 + 7 \\cdot 1 + \\pars{-4} \\cdot 2 + 1 \\cdot \\pars{-1} + \\pars{-2} \\cdot \\pars{-1}}{\\sqrt{15} \\cdot \\sqrt{11}} \\\\\n              &= \\frac{8}{\\sqrt{165}} \\\\\n              &= \\frac{8 \\sqrt{165}}{165} \\\\\n  \\theta &= \\boxed{\\arccos{\\frac{8 \\sqrt{165}}{165}}} \\\\\n\\end{align*}\n\n\n\\problem{1.5}\n\n$$\\norm{\\bm{x}} = \\sqrt{4^2 + 7^2 + 4^2} =  \\boxed{9}$$\n\n$$\\norm{\\bm{y}} = \\sqrt{2^2 + 1^2 + 2^2} =  \\boxed{3}$$\n\n\\begin{align*}\n  \\cos \\theta &= \\frac{4 \\cdot 2 + 7 \\cdot 1 + 4 \\cdot 2}{9 \\cdot 3} \\\\\n              &= \\frac{23}{27} \\\\\n  \\theta &= \\boxed{\\arccos \\frac{23}{27}} \\\\\n\\end{align*}\n\n\n\n\\problem{1.7}\n\n\\subsection*{a}\n\n\\begin{align*}\n  \\bm{u}_1 \\cdot \\bm{u}_2 &= \\frac{1}{81} \\pars{1 \\cdot 8 + \\pars{-4} \\cdot 4 + \\pars{-8} \\cdot \\pars{-1}} = 0 \\\\\n  \\bm{u}_2 \\cdot \\bm{u}_3 &= \\frac{1}{81} \\pars{8 \\cdot 4 + 4 \\cdot \\pars{-7} + \\pars{-1} \\cdot 4} = 0 \\\\\n  \\bm{u}_1 \\cdot \\bm{u}_3 &= \\frac{1}{81} \\pars{1 \\cdot 4 + \\pars{-4} \\cdot \\pars{-7} + \\pars{-8} \\cdot 4} = 0 \\\\\n\\end{align*}\n\nTherefore, $\\set{\\bm{u}_1, \\bm{u}_2, \\bm{u}_3}$ \\emph{is} an orthonormal basis of $\\RR^3$.\n\n\\begin{align*}\n  \\bm{u}_1 \\times \\bm{u}_2 &= \\frac{1}{81} \\pars{1, -4, -8} \\times \\pars{8, 4, -1} \\\\\n                           &= \\frac{1}{81} \\pars{36, -63, 36} \\\\\n                           &= \\frac{1}{9} \\pars{4, -7, 4} \\\\\n                           &= \\bm{u}_3 \\\\\n\\end{align*}\nSince $\\bm{u}_1 \\times \\bm{u}_2 = \\bm{u}_3$, $\\set{\\bm{u}_1, \\bm{u}_2, \\bm{u}_3}$ is a \\emph{right-handed} orthonormal basis of $\\RR^3$.\n\n\n\\subsection*{b}\n\n\n\\begin{align*}\n  y_1 \\bm{u}_1 + y_2 \\bm{u}_2 + y_3 \\bm{u}_3 &= \\pars{10, 11, -11} \\\\\n  y_1 \\pars{1, -4, -8} + y_2 \\pars{8, 4, -1} + y_3 \\pars{4, -7, 4} &= \\pars{90, 99, -99} \\\\\n  \\pars{y_1 + 8 y_2 + 4 y_3, -4 y_1 + 4 y_2 - 7 y_3, -8 y_1 - y_2 + 4y_3} &= \\pars{90, 99, -99} \\\\\n\\end{align*}\n\nWe can solve this system to find \\boxed{y_1 = 6, y_2 = 15, y_3 = -9}.\n\n\\begin{align*}\n  \\norm{\\pars{y_1, y_2, y_3}} &= \\sqrt{6^2 + 15^2 + \\pars{-9}^2} \\\\\n                              &= \\boxed{3 \\sqrt{38}} \\\\\n  \\norm{\\pars{10, 11, -11}} &= \\sqrt{10^2 + 11^2 + \\pars{-11}^2} \\\\\n  &= \\boxed{3 \\sqrt{38}} \\\\\n\\end{align*}\n\n\n\n\\problem{1.14}\n\n\n\\subsection*{a}\n\nLet $\\bm{v}_1$ be the vector that passes through $\\bm{a}_1$ and $\\bm{a}_2$.\nLet $\\bm{v}_2$ be the vector that passes through $\\bm{a}_2$ and $\\bm{a}_3$.\nLet $\\bm{v}_3$ be the vector that passes through $\\bm{b}_1$ and $\\bm{b}_2$.\nLet $\\bm{v}_4$ be the vector that passes through $\\bm{b}_2$ and $\\bm{b}_3$.\n\n\\begin{align*}\n  \\bm{v}_1 &= \\pars{-2, 0, -4} \\\\\n  \\bm{v}_2 &= \\pars{3, -5, 1} \\\\\n  \\bm{v}_3 &= \\pars{0, -1, 1} \\\\\n  \\bm{v}_4 &= \\pars{-1, 1, 0} \\\\\n\\end{align*}\n\nSince $\\bm{v}_1, \\bm{v}_2$ lie in the plane $P_1$, their cross product $\\bm{n}_1$ is perpendicular to $P_1$.\nLikewise for $\\bm{v}_3, \\bm{v}_4, P_2, \\text{and }\\bm{n}_2$, respectively.\n\n\\begin{align*}\n  \\bm{n}_1 &= \\pars{20, -10, 10} \\\\\n  \\bm{n}_2 &= \\pars{-1, -1, -1} \\\\\n\\end{align*}\n\nWe substitute into the standard form equation for a plane:\n\n\\begin{align*}\n  P_1 : \\bm{n}_1 \\cdot \\bm{r} + d_1 &= 0 \\\\\n  P_2 : \\bm{n}_2 \\cdot \\bm{r} + d_2 &= 0 \\\\\n\\end{align*}\n\nSubstituting $\\bm{a}_1$ and $\\bm{b}_1$, respectively, we find that $d_1 = -10$ and $d_2 = 3$.\nAfter simplifying,\n\n\\begin{align*}\n  P_1 &: \\boxed{2x - y + z - 1 = 0} \\\\\n  P_2 &: \\boxed{x + y + z - 3 = 0} \\\\\n\\end{align*}\n\n\n\\subsection*{b}\n\nAdding and subtracting the two equations, respectively\n\n$$\n\\begin{cases}\n  x - 2y + 2 = 0 \\Longleftrightarrow y = \\frac{1}{2} x + 1 \\\\\n  3x + 2z - 4 = 0 \\Longleftrightarrow z = - \\frac{3}{2} x + 2 \\\\\n\\end{cases}\n$$\n\nLetting $t \\in \\RR$, we can write\n\n\\begin{align*}\n  \\bm{x} \\pars{t} &= \\pars{t, \\frac{1}{2} t + 1, - \\frac{3}{2} t + 2} \\\\\n  \\bm{x} \\pars{t} &= \\boxed{\\pars{0, 1, 2} + t \\pars{0, \\frac{1}{2}, - \\frac{3}{2}}} \\\\\n\\end{align*}\n\nThis is of the form $\\bm{x} \\pars{t} = \\bm{x}_0 + t \\bm{v}$.\nTo find the distance, we must first normalize $\\bm{v}$.\n\n\\begin{align*}\n  \\bm{u} &= \\frac{\\bm{v}}{\\norm{\\bm{v}}} \\\\\n  &= \\frac{\\sqrt{10}}{5} \\pars{0, \\frac{1}{2}, - \\frac{3}{2}} \\\\\n\\end{align*}\n\nSuppose the point on the line closest to $\\bm{a}_1$ is $\\bm{p}$.\nThe shortest distance is then\n\n\\begin{align*}\n  \\norm{\\bm{p} - \\bm{a}_1}^2 &= \\norm{\\bm{x}_0 - \\bm{a}_1}^2 - \\norm{\\pars{\\bm{x}_0 - \\bm{a}_1} \\cdot \\bm{u}}^2 \\\\\n                             &= \\norm{\\pars{0, 1, 2} - \\pars{1, 2, 1}}^2 - \\frac{10}{25} \\abs{\\pars{\\pars{0, 1, 2} - \\pars{1, 2, 1}} \\cdot \\pars{0, \\frac{1}{2}, - \\frac{3}{2}}}^2 \\\\\n                             &= \\norm{\\pars{-1, -1, 1}}^2 - \\frac{2}{5} \\abs{\\pars{-1, -1, 1} \\cdot \\pars{0, \\frac{1}{2}, - \\frac{3}{2}}} \\\\\n                             &= 3 - \\frac{2}{5} \\pars{2} \\\\\n                             &= \\frac{13}{5} \\\\\n  \\norm{\\bm{p} - \\bm{a}_1} &= \\boxed{\\sqrt{\\frac{13}{5}}} \\\\\n\\end{align*}\n\n\\subsection*{c}\n\n\\begin{align*}\n  \\bm{x} &= \\bm{b}_1 + t \\bm{a} \\\\\n\\end{align*}\n\nSuppose the line is at $\\bm{b}_1$ when $t=0$.\nIn addition, at $t=1$, suppose the line is at $\\bm{b}_2$.\nThen, $\\bm{a} = \\bm{b}_2 - \\bm{b}_1 = \\pars{0, -1, 1}$.\nTherefore,\n\n$$\n\\bm{x} = \\pars{1, 1, 0} + t \\pars{0, -1, 1}\n$$\n\nThe vector equation of the line is therefore\n\n\\begin{align*}\n  \\bm{a} \\times \\pars{\\bm{x} - \\bm{b}_1} &= 0 \\\\\n  \\pars{0, -1, 1} \\times \\pars{\\bm{x} - \\pars{1, 1, 0}} &= 0 \\\\\n  \\pars{0, -1, 1} \\times \\pars{x - 1, y - 1, z} &= 0 \\\\\n  \\pars{-y-z+1, x-1, x-1} &=0 \\\\\n\\end{align*}\n\nClearly, $x=1$ from the $\\bm{e}_2$ and $\\bm{e}_3$ components of this equation.\nIn addition, $y + z = 1$ from the $\\bm{e}_1$ component.\n\nThe equation for $P_1$ is $2x-y+z=1$.\nSubstituting $x=1$, we have\n\n$$\n\\begin{cases}\n  y + z = 1 \\\\\n  y - z = 1 \\\\\n\\end{cases}\n$$\n\nSolving, we find $y=1$ and $z=0$.\nFinally, the point of intersection is $\\boxed{\\pars{1, 1, 0}}$.\n\n\\problem{1.15}\nLet the orthonormal basis be composed of vectors $\\bm{a}, \\bm{b}, \\bm{c}$.\nWe let\n$$\\bm{c} := \\frac{\\bm{v}}{\\norm{\\bm{v}}} = \\frac{1}{\\sqrt{26}} \\pars{1, 4, 3}$$\n\nIn addition, we define\n$$\n\\bm{w} := \\pars{-4, 1, 0}\n$$\n\nNote that $\\bm{w}$ and $\\bm{c}$ are orthogonal.\nWe normalize and let the resultant unit vector be $\\bm{a}$.\n\n$$\n\\bm{a} := \\frac{1}{\\sqrt{17}} \\pars{-4, 1, 0}\n$$\n\nTo make $\\bm{b}$ orthogonal to the other two vectors, we can compute the final vector:\n\n\\begin{align*}\n  \\bm{y} & := \\bm{v} \\times \\bm{w} \\\\\n         &= \\pars{-3, -12, 15} \\\\\n  \\bm{b} &= \\frac{\\bm{y}}{\\norm{\\bm{y}}} \\\\\n  \\bm{b} &= \\frac{1}{\\sqrt{378}} \\pars{-3, -12, 15} \\\\\n\\end{align*}\n\n\n\\problem{1.16}\n\nLet the orthonormal basis be $\\bm{u}_1, \\bm{u}_2, \\bm{u}_3$.\n\n\\begin{align*}\n  \\bm{u}_1 &= \\frac{\\bm{a}}{\\norm{\\bm{a}}} \\\\\n           &= \\frac{1}{\\sqrt{26}} \\pars{1, 4, 3} \\\\\n  \\bm{u}_2 &= \\frac{\\bm{b}}{\\norm{\\bm{b}}} \\\\\n           &= \\frac{1}{\\sqrt{14}} \\pars{3, 2, 1} \\\\\n  \\bm{c} &= \\bm{a} \\times \\bm{b} \\\\\n           &= \\pars{-2, 8, -10} \\\\\n  \\bm{u}_3 &= \\frac{\\bm{c}}{\\norm{\\bm{c}}} \\\\\n  &= \\frac{1}{\\sqrt{168}} \\pars{-2, 8, -10} \\\\\n\\end{align*}\n\n\\problem{1.17}\n\n\\subsection*{a}\n\nLet $\\pars{s, t} = \\pars{0, 0}, \\pars{0, 1}, \\pars{1, 0}$ correspond to $\\bm{p}_1, \\bm{p}_2, \\bm{p}_3$, respectively.\nWe see that $\\bm{x}_0 = \\bm{p}_1 = \\pars{-2, 0, 2}$.\nFurther, we also see that $$\\bm{v}_1 = \\bm{p}_2 - \\bm{p}_1 = \\pars{3, -2, 0}$$ and $$\\bm{v}_2 = \\bm{p}_3 - \\bm{p}_1 = \\pars{5, -1, -4}$$\n\n$$\n\\bm{x} \\pars{s, t} = \\pars{-2, 0, 2} + s \\pars{3, -2, 0} + t \\pars{5, -1, -4}\n$$\n\n\\subsection*{b}\n\nLet $u=0$ at $\\bm{x}_0$, so $\\bm{z}_0 = \\bm{x}_0 = \\boxed{\\pars{1, 4, -2}}$.\nLetting $u=1$ at $\\bm{x}_1$ lets us see that $\\bm{w} = \\bm{z}_1 - \\bm{z}_0 = \\boxed{\\pars{-1, -7, 3}}$.\n\n\\subsection*{c}\nWe can compute the normal vector by\n\n\\begin{align*}\n  \\bm{n} &= \\bm{v}_1 \\times \\bm{v}_2 \\\\\n         &= \\pars{3, -2, 0} \\times \\pars{5, -1, -4} \\\\\n         &= \\pars{8, 12, 7} \\\\\n\\end{align*}\n\nWe know that $\\bm{n} \\cdot \\bm{x} + d = 0$ is the general vector equation for the plane.\nSubstituting $\\bm{x} = \\bm{p}_1$, we see that $d=2$.\nWe can then expand,\n$$\n\\boxed{8x + 12y + 7z + 2 =0}\n$$\n\n\\subsection*{d}\n\nThe general vector equation for a line is\n\\begin{align*}\n  \\bm{w} \\times \\pars{\\bm{z} - \\bm{z}_0} &= 0 \\\\\n  \\pars{-1, -7, 3} \\times \\pars{\\pars{x, y, z} - \\pars{1, 4, -2}} &= 0 \\\\\n  \\pars{-1, -7, 3} \\times \\pars{x - 1, y - 4, z + 2} &= 0 \\\\\n  \\pars{-2 - 3y - 7z, -1+3x+z, -3 + 7x - y} &= 0 \\\\\n\\end{align*}\n\nWe therefore have the system,\n\n$$\n\\begin{cases}\n  3y + 7z = -2 \\\\\n  3x + z = 1 \\\\\n  7x - y = 3 \\\\\n\\end{cases}\n$$\n\n\\subsection*{e}\nSolving for $y$ in the last equation,\n\n$$\ny = 7x - 3\n$$\n\nSubstituting into the equation for the plane,\n\n$$\n\\begin{cases}\n  92x + 7z + 2 = 0 \\\\\n  3x + z = 1 \\\\\n\\end{cases}\n$$\n\nSolving and resubstituting, we find $\\boxed{\\pars{\\frac{24}{71}, - \\frac{24}{71}, - \\frac{10}{71}}}$.\n\n\\subsection*{f}\n\nWe must first normalize $\\bm{w}$.\n\n\\begin{align*}\n  \\bm{u} &= \\frac{\\bm{w}}{\\norm{\\bm{w}}} \\\\\n  &= \\frac{1}{\\sqrt{59}} \\pars{-1, -7, 3} \\\\\n\\end{align*}\n\nSuppose the point on the line closest to $\\bm{p}_1$ is $\\bm{q}$.\n\n\\begin{align*}\n  \\norm{\\bm{p}_1 - \\bm{q}} &= \\norm{\\pars{\\bm{x}_0 - \\bm{p}_1} \\times \\bm{u}} \\\\\n                           &= \\frac{1}{\\sqrt{59}} \\norm{\\pars{\\pars{1, 4, -2} - \\pars{-1, -3, 0}} \\times \\pars{-1, -7, 3}} \\\\\n                           &= \\frac{1}{\\sqrt{59}} \\norm{\\pars{2, 7, -2} \\times \\pars{-1, -7, 3}} \\\\\n                           &= \\frac{1}{\\sqrt{59}} \\norm{\\pars{7, -4, -7}} \\\\\n                           &= \\boxed{\\sqrt{\\frac{114}{59}}} \\\\\n\\end{align*}\n\n\n\\subsection*{g}\n\nWe must first normalize $\\bm{n}$.\n\n\\begin{align*}\n  \\bm{u} &= \\frac{\\bm{n}}{\\norm{\\bm{n}}} \\\\\n  &= \\frac{1}{\\sqrt{257}} \\pars{8, 12, 7} \\\\\n\\end{align*}\n\nThe distance is then\n\n\\begin{align*}\n  \\abs{\\pars{\\bm{x}_0 - \\bm{z}_0} \\cdot \\bm{u}} &= \\frac{1}{\\sqrt{257}} \\abs{\\pars{-2, 0, 2} - \\pars{1, 4, -2} \\cdot \\pars{8, 12, 7}} \\\\\n                                                &= \\frac{1}{\\sqrt{257}} \\abs{\\pars{-3, -4, 4} \\cdot \\pars{8, 12, 7}} \\\\\n                                                &= \\frac{1}{\\sqrt{257}} \\abs{-44} \\\\\n                                                &= \\boxed{\\frac{44}{\\sqrt{257}}} \\\\\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "8a72db164efeca6367514d440ea2882232736d8f", "size": 11013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Assignment 1/assignment.tex", "max_stars_repo_name": "RajeevAtla/Math-291", "max_stars_repo_head_hexsha": "1aab6358d90b23ef62d57d8e67ae22124961a903", "max_stars_repo_licenses": ["MIT"], "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/Assignment 1/assignment.tex", "max_issues_repo_name": "RajeevAtla/Math-291", "max_issues_repo_head_hexsha": "1aab6358d90b23ef62d57d8e67ae22124961a903", "max_issues_repo_licenses": ["MIT"], "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/Assignment 1/assignment.tex", "max_forks_repo_name": "RajeevAtla/Math-291", "max_forks_repo_head_hexsha": "1aab6358d90b23ef62d57d8e67ae22124961a903", "max_forks_repo_licenses": ["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.905511811, "max_line_length": 181, "alphanum_fraction": 0.5021338418, "num_tokens": 4890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.665489585994365}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Implicitly Restarted Arnoldi's Method\\label{ch:IRAM} }\nA good restart vector is one where the undesired region of the spectrum of our linear operator is suppressed while the desired region is enhanced.  This is done by zeroing out the Ritz vectors associated with the Ritz values from the undesired region of the spectrum.  This is done explicitly in \\fref{eq:ExplicitRestartVector} and repeated here for clarity;\n\\begin{equation}\n    \\hat{v} = c_1y_1 + \\cdots + c_jy_j + 0\\,y_{j+1} + \\cdots + 0\\,y_n;\n    \\label{eq:RestartVector}\n\\end{equation} \nIn addition to saving computational expense the improved restarts \\emph{implicitly} restart Arnoldi's method with an improved restart vector and is thus called an implicit restart or implicitly restarted Arnoldi's method (IRAM).  To see how this is done, a brief discussion of the \\QR algorithm will first be presented and then IRAM will be shown.\n\n\\section*{\\QR Algorithm} \\label{sec:QRAlgorithm}\nA matrix $A \\in \\mathbb{R}^{n \\times n}$can be decomposed into two matrices\n\\begin{equation}\n    A = \\QR\n    \\label{eq:QRDecomposition}\n\\end{equation}\nwhere $Q, R \\in \\mathbb{C}^{n \\times n}$ with $Q$ unitary (orthonormal columns) and $R$ upper triangular.  The \\QR decomposition (\\fref{eq:QRDecomposition}) is unique \\citep[see][Chapter 3, pg. 204]{Watkins:2002Funda-0} for nonsingular matrices and $R$ with positive main diagonal entries.  The \\QR factors can be recombined in reverse order to form a new matrix \n\\begin{equation}\n    \\hat{A} = RQ.\n\\end{equation}\n\nThe decomposition of a matrix and the recombination of the factors is typically performed iteratively.  A simple change of notation makes this illustration clear\n\\begin{subequations}\n    \\label{eq:QRIteration}\n    \\begin{align}\n        A_{n-1} &= Q_nR_n \\label{eq:QRFactIter} \\\\\n        A_{n} &= R_nQ_n. \\label{eq:QRRecombineIter}\n    \\end{align}\n\\end{subequations}\nUsing this notation $A_0 = A$.  The decomposition of $A_{n-1}$ and formation of $A_n$ constitutes one \\QR iteration.\n\nWe can see from \\fref{eq:QRFactIter} that $R_n = Q_n^*A_{n-1}$.  Substituting this in \\fref{eq:QRRecombineIter} we obtain an alternative form for $A_n$\n\\begin{equation}\n    A_{n} = Q_n^*A_{n-1}Q_n.\n    \\label{eq:QRIterationAlternate}\n\\end{equation}\n\n\\section*{Shifted \\QR Iteration} \\label{sec:ShiftedQR}\nThe \\QR iteration can be shifted by subtracting the identity matrix multiplied by some scalar shift.  The factors in the shifted \\QR iteration can be recombined similarly to the non-shifted counterpart\n\\begin{subequations}\n    \\label{eq:ShiftedQRIteration}\n\\begin{gather}\n    A_{n-1} - \\nu_n I = Q_nR_n \\label{eq:ShiftedQRDecomposition} \\\\\n    A_n = R_nQ_n + \\nu_nI \\label{eq:ShiftedQRRecombine}\n\\end{gather}\n\\end{subequations}\nwhere $Q_n$ and $R_n$ are the same as in the non-shifted \\QR iteration, $I$ is the identity matrix, and $\\nu_n$ is the shift being applied.  Similarly to the non-shifted \\QR iteration, we can form $A_n$ alternatively.  To see this first note from \\fref{eq:ShiftedQRDecomposition} that \\[R_n = Q_n^*A_{n-1} - \\nu_nQ_n^*.\\]  Substituting this into \\fref{eq:ShiftedQRRecombine} we obtain\n\\begin{equation}\n    \\begin{split}\n        A_n &= \\left[ Q_n^*A_{n-1} - \\nu_nQ_n^* \\right]Q_n + \\nu_nI \\\\\n         &= Q_n^*A_{n-1}Q_n - \\nu_nQ_n^*Q_n + \\nu_nI \\\\\n         &= Q_n^*A_{n-1}Q_n - \\nu_nI + \\nu_nI \\\\\n         A_n &= Q_n^*A_{n-1}Q_n\n    \\end{split}\n    \\label{eq:ShiftedQRIterationAlternative}\n\\end{equation}\nEquation \\eqref{eq:ShiftedQRIterationAlternative} generalizes the alternative form of $A_m$ from \\fref{eq:QRIterationAlternate} to the shifted \\QR algorithm.  \n\nNow that the basic \\QR algorithm has been given we will proceed to to develop some identities that will be of use to us in analyzing implicit restarts for Arnoldi's method.\n\\begin{lem} \n    Let $Q_n$, $A_n$ be defined by equations \\eqref{eq:ShiftedQRIteration} and let\n\\begin{equation}\n    \\hat{Q}_n \\equiv Q_1Q_2\\cdots Q_n,\n    \\label{eq:QhatDefined}\n\\end{equation}\nthen\n\\begin{align}\n    A_n &= \\hat{Q}_n^*A\\hat{Q}_n  \\label{eq:QRRecombined} \\\\\n    \\hat{Q}_nA_n &= A\\hat{Q}_n. \\label{eq:QnAn}\n\\end{align}\n\\label{lem:QRRecombined}\n\\end{lem}\n\n\\begin{proof}\n    For $n=1$, we know from \\fref{eq:ShiftedQRIteration} \n    \\begin{equation}\n        A_1 = Q_1^*A_0Q_1 = \\hat{Q}_1^*A \\hat{Q}_1.\n    \\end{equation}\n    For $n=2$, after a second iteration, we have\n    \\begin{equation}\n        \\begin{split}\n            A_2 &= Q_2^*A_1Q_2 \\\\\n             &= Q_2^*\\left( Q_1^*A Q_1 \\right)Q_2 \\\\\n             &= \\hat{Q}_2^*A \\hat{Q}_2\n        \\end{split}\n    \\end{equation}\n    where $\\hat{Q}_2 = Q_1Q_2$.  We can prove this in general by induction on $n$:\n    \\begin{equation}\n        \\begin{split}\n            A_n &= Q_n^*A_{n-1}Q_n \\\\\n            &= Q_n^*\\left( \\hat{Q}_{n-1}^*A_{n-2} \\hat{Q}_{n-1} \\right)Q_n \\\\\n             &= Q_n^*Q_{n-1}^*\\cdots Q_1 A Q_1\\cdots Q_{n-1}Q_n \\\\\n             &= \\hat{Q}_n^*A \\hat{Q}_n\n        \\end{split}\n    \\end{equation}\n    where $\\hat{Q}_n = Q_1Q_2\\cdots Q_n$, as defined in \\fref{eq:QhatDefined}.  Equation \\eqref{eq:QnAn} immediately follows from \\fref{eq:QRRecombined} since $\\hat{Q}_n$ is a unitary matrix.\n\\end{proof}\n\n\\begin{lem}\n    Let $Q_n$, $A_n$ be defined by \\fref{eq:ShiftedQRDecomposition} and let $\\left\\{\\nu_1,\\ldots, \\nu_m\\right\\}$ be the shifts, then\n    \\begin{equation}\n        \\left(A-\\nu_nI\\right)\\hat{Q}_n = \\hat{Q}_n\\left(A_n - \\nu_nI\\right),\n    \\end{equation}\n    where $\\hat{Q}_n \\equiv Q_1Q_2\\cdots Q_n$.\n\\end{lem}\n\n\\begin{proof}\n    Using \\fref{eq:QnAn} this becomes trivial:\n    \\begin{equation}\n        \\begin{split}\n            \\left(A-\\nu_nI\\right)\\hat{Q}_n &= A\\hat{Q}_n - \\nu_n\\hat{Q}_n \\\\\n             &= \\hat{Q}_nA_n - \\nu_n\\hat{Q}_n \\\\\n             \\left(A-\\nu_nI\\right)\\hat{Q}_n &= \\hat{Q}_n\\left( A_n - \\nu_nI \\right).\n        \\end{split}\n    \\end{equation}\n\\end{proof}\n\nWith these two lemmas we now proceed to the theorem that is important to showing how IRAM restarts with the ideal restart vector.\n\\begin{thm} \\label{thm:QRPolynomial}\n    Let $\\hat{Q}_n$ be defined as in \\fref{eq:QhatDefined} and\n    \\begin{equation}\n        \\hat{R}_n \\equiv R_nR_{n-1}\\cdots R_1\n        \\label{eq:RhatDefined}\n    \\end{equation}\n    and using $\\left\\{\\nu_1,\\nu_2,\\ldots\\nu_n\\right\\}$ as the shifts of a shifted \\QR algorithm, then\n\\begin{equation}\n    \\poly{j}{A} = \\hat{Q}_j\\hat{R}_j,\n    \\label{eq:QRPolynomial}\n\\end{equation}\n    where $\\p_j$ is a polynomial of degree $j$ with zeros $\\nu_1,\\ldots,\\nu_j$\n    \\begin{equation}\n        \\poly{j}{z} = \\left(z-\\nu_1I\\right)\\left(z-\\nu_2I\\right)\\cdots\\left(z-\\nu_jI\\right).\n        \\label{eq:Polynomial}\n    \\end{equation}\n\\end{thm}\n\\begin{proof}\n    For $n=1$ \\fref{eq:QRPolynomial} is true by definition of the shifted \\QR decomposition given in \\fref{eq:ShiftedQRDecomposition}\n    \\begin{equation}\n        \\left(A - \\nu_1I\\right) = Q_1R_1 = \\hat{Q}_1\\hat{R}_1.\n    \\end{equation}\n    In general we can prove this by induction\n    \\begin{equation}\n        \\begin{split}\n            \\left(A-\\nu_nI\\right)\\left[\\left(A-\\nu_{n-1}I\\right)\\cdots\\left(A-\\nu_1I\\right)\\right] &= \\left(A-\\nu_nI\\right)\\left[\\hat{Q}_{n-1}\\hat{R}_{n-1}\\right] \\\\\n            &=\\left[A\\hat{Q}_{n-1} - \\nu_n\\hat{Q}_{n-1}\\right]\\hat{R}_{n-1} \\\\\n            &=\\left[\\hat{Q}_{n-1}A_{n-1} - \\nu_n\\hat{Q}_{n-1}\\right]\\hat{R}_{n-1} \\\\\n            &=\\hat{Q}_{n-1}\\left(A_{n-1} - \\nu_nI\\right)\\hat{R}_{n-1} \\\\\n            &=\\hat{Q}_{n-1}\\left(Q_nR_n\\right)\\hat{R}_{n-1} \\\\\n            \\left(A-\\nu_nI\\right)\\left[\\left(A-\\nu_{n-1}I\\right)\\cdots\\left(A-\\nu_1I\\right)\\right] &=\\hat{Q}_n\\hat{R}_n.\n        \\end{split}\n    \\end{equation}\n\\end{proof}\n\nEquation \\eqref{eq:QRPolynomial} shows that the product of the unitary ($\\hat{Q}_n$) and upper triangular ($\\hat{R}_n$) matrices from the \\QR algorithm are equivalent to a polynomial of $A$ of degree $n$ with the shifts as the zeros of the polynomial.  This is an important point in IRAM.\n\n\\section*{Updating Arnoldi Factorization by Shifted \\QR Iterations}\nTo show how IRAM uses the \\QR algorithm we begin with the Arnoldi factorization first introduced in \\fref{eq:ArnoldiFactorization}\n\\begin{equation}\n    A V_m = V_mH_m + v_{m+1}h_{m+1,m}e_m^T.\n    \\label{eq:ArnoldiFactorizationIRAM}\n\\end{equation}\nImplicitly restarted Arnoldi's method performs shifted \\QR iterations on $H_m$ using the eigenvalues estimates from the undesired region of the spectrum of $A$.  For Monte Carlo reactor analysis the eigenvalues largest in magnitude are of particular interest however, the following treatment is independent of what region of the spectrum is desired.\n\nWe note that the Arnoldi factorization in \\fref{eq:ArnoldiFactorizationIRAM} is shown after $m$ Arnoldi iterations.  For this discussion we assume that $k$ eigenvalues are desired and $m=k+j$ iterations are performed in each restart where $k \\sim j$.  After $m$ Arnoldi iterations we have $m$ Ritz values---eigenvalue estimates---of $A$; $k$ of them are the eigenvalues of interest and the other $j$ values are used as shifts for the shifted \\QR algorithm.\n\nIRAM performs $j$ iterations of the shifted \\QR algorithm on $H_m$ using the undesired Ritz values as described previously.  After $j$ iterations we obtain\n\\begin{equation}\n    \\hat{H}_j = \\hat{Q}_j^*H_m\\hat{Q}_j\n    \\label{eq:Hhat}\n\\end{equation}\nwhere $\\hat{Q}_j$ is defined in \\fref{eq:QhatDefined}.  Because $H_m$ is upper Hessenberg, we can show that $Q_i$ is upper Hessenberg and $\\hat{Q}_j$ is properly $j$-Hessenberg.  \n\n\\begin{thm}\n    Let $j$ be a non-negative integer.  A matrix $H$ is called $j$-Hessenberg if $h_{rc} = 0$ whenever $(r-c)>j$.  An Hessenberg matrix is said to be properly $j$-Hessenberg if $h_{rc} \\neq 0$ whenever $\\left(r-c\\right) = j$,\n    \\begin{equation}\n        h_{rc} = \\begin{cases}\n            0 & r-c > j \\\\\n            x & \\text{otherwise}.\n        \\end{cases}\n        \\label{eq:hrcDefined}\n    \\end{equation}\n    Then the product of a properly $j$-Hessenberg matrix ($H_j$) and a properly $k$-Hessenberg matrix $H_k$ is properly $(j+k)$-Hessenberg ($H_{j+k}$).\n    \\label{thm:jkHessenberg}\n\\end{thm}\n\\begin{proof}\n    The $r$th row of a properly $j$-Hessenberg matrix has $\\max\\left[r-j-1,0\\right]$ leading zeros.  The $c$th column of a properly $k$-Hessenberg matrix has $\\max\\left[m-\\left(c+k\\right),0\\right]$ trailing zeros. The elements of $H_{j+k}$, $h_{rc}$, are zero if the sum of the leading zeros of the $r$th row of $H_j$ is greater than or equal to the difference of the size of the matrix $m$ and the trailing zeros of the $c$th column of $H_k$; \\mbox{$h_{rc} = 0$} if \\mbox{$\\left( r-j-1 \\right) \\geq m-\\left[m-\\left(c+k\\right)\\right]$}.  Simplifying we obtain \\mbox{$\\left( r-j-1 \\right) \\geq \\left(c+k\\right)$} or equivalently\n    \\begin{equation}\n        h_{rc} = \\begin{cases}\n            0 & r-c > \\left(j+k\\right) \\\\\n            x & \\text{otherwise}.\n        \\end{cases}\n        \\label{eq:hrcProved}\n    \\end{equation}\n    We see that \\fref{eq:hrcProved} is equivalent to \\fref{eq:hrcDefined} for a $\\left(j+k\\right)$-Hessenberg matrix.\n\\end{proof}\n\nWhen performing the \\QR decomposition on an upper Hessenberg matrix we obtain\n\\begin{equation}\n    H_m = Q_1R_1\n    \\label{eq:HQR}\n\\end{equation}\nwith $Q_1$ and $R_1$ defined in \\fref{eq:QRDecomposition}.  This can be re-written as\n\\begin{equation}\n    Q_1 = H_mR_1^{-1}\n\\end{equation}\nwhere we note that the inverse of an upper triangular matrix is an upper triangular matrix.  An upper triangular matrix is properly $0$-Hessenberg and $H_m$ is $1$-Hessenberg so we can apply \\fref{thm:jkHessenberg} to show that $Q_1$ is properly $1$-Hessenberg.  \n\n\\begin{col}\n    Let $\\hat{Q}_n \\in \\mathbb{C}^{m \\times m}$ be the combined unitary matrix resulting from $n$ iterations of the \\QR iteration on an upper Hessenberg matrix, $H$.  \n    \\begin{comment}\n        Define a \\emph{properly $j$-Hessenberg} $B$ if $b_{ik} = 0$ whenever $\\left(i-k\\right)>j$ and when $b_{ij} \\neq 0$ whenever $\\left(i-k\\right)=j$.  \n    \\end{comment}\n    Then $\\hat{Q}_n$ is a properly $n$-Hessenberg matrix and that the row vector $e_m^T\\hat{Q}_n$ has $m-n-1$ leading zeros.\n    \\label{thm:QRHessenberg}\n\\end{col}\n\n\\begin{proof}\n    We know that the unitary matrix from the \\QR decomposition of an upper Hessenberg matrix is also upper Hessenberg.  $\\hat{Q}_n$ is the product of $n$ upper Hessenberg matrices, therefore $\\hat{Q}_n$ is properly $n$-Hessenberg.\n\n    The elements of product $e_m^T\\hat{Q}_n$ are non-zero when the element of the $m$th or last row of $\\hat{Q}_n$ is also non-zero.  The last row of $\\hat{Q}_n$ has $m-n-1$ leading zeros as given in \\fref{thm:jkHessenberg}.\n\\end{proof}\n\nLet's return to the Arnoldi method.  Solving \\fref{eq:Hhat} for $H_m$ and substituting into \\fref{eq:ArnoldiFactorizationIRAM} we obtain\n\\begin{align}\n    A V_m &= V_m\\left(\\hat{Q}_j\\hat{H}_j\\hat{Q}_j^*\\right) + v_{m+1}h_{m+1,m}e_m^T. \\\\\n    \\intertext{Now operate on the right by $\\hat{Q}_j$,}\n    \\begin{split}\n        A V_m\\hat{Q}_j &= V_m\\hat{Q}_j\\hat{H}_j\\hat{Q}_j^*\\hat{Q}_j + v_{m+1}h_{m+1,m}e_m^T\\hat{Q}_j \\\\\n        A \\hat{V}_m &= \\hat{V}_m\\hat{H}_m + v_{m+1}h_{m+1,m}e_m^T\\hat{Q}_j, \\label{eq:UpdatedIRAM}\n    \\end{split}\n\\end{align}\nwhere\n\\begin{equation}\n    \\hat{V}_m = V_m\\hat{Q}_j.\n\\end{equation}\n\nThe row vector \\mbox{$e_m^T\\hat{Q}_j$} in \\fref{eq:UpdatedIRAM} has \\mbox{$\\left( m-j-1 \\right)$} leading zeros according to \\fref{thm:QRHessenberg}.  If we drop the first $j$ columns of \\fref{eq:UpdatedIRAM} we obtain\n\\begin{equation}\n    \\begin{split}\n        A \\hat{V}_k &= \\hat{V}_{k+1}\\hat{H}_{k+1,k} + v_{m+1}h_{m+1,m}\\beta e_k^T \\\\\n        &= \\hat{V}_k\\hat{H}_k + \\left( \\check{v}_{k+1}\\check{h}_{k+1,k} + v_{m+1}h_{m+1,m}\\beta \\right) e_k^T\n    \\end{split}\n    \\label{eq:IRAMcheck}\n\\end{equation}\nwhere $\\beta e_k^T$ is the first $k+1$ columns of $e_m^T\\hat{Q}_j$ and we have defined \n\\begin{align}\n    \\hat{v}_{k+1} &= \\gamma\\left(\\check{v}_{m+1}\\check{h}_{m+1,m} + v_{m+1}h_{m+1,m}\\beta \\right)\n\\end{align}\nwhere $\\gamma$ is chosen to normalize $\\hat{v}_{k+1}$, $\\|\\hat{v}_{k+1}\\|_2 = 1$.  If we let $\\hat{h}_{k+1,k} = 1/\\gamma$ then \\fref{eq:IRAMcheck} becomes\n\\begin{equation}\n    A \\hat{V}_k = \\hat{V}_k\\hat{H}_k + \\hat{v}_{k+1}\\hat{h}_{k+1,k} e_k^T\n    \\label{eq:IRAMhat}\n\\end{equation}\nwhich is exactly like \\fref{eq:ArnoldiFactorizationIRAM} except we have added some hats on some symbols and replaced $m$ with $k$.  It can be shown \\citep[see][]{Watkins:2002Funda-0} that the Arnoldi vectors contained as the columns of $\\hat{V}_k$ are exactly those that would have been generated by explicitly starting with $\\hat{v}_1$.  Thus with IRAM we don't have have to start at the beginning of a restart, therefore we can jump right in at the $k$th iteration of the restart.  After $j$ additional steps we will have a Krylov subspace of size $m$, exactly as we would have had after $m$ iterations in explicit Arnoldi.\n\nBeing able to jump into the middle of an Arnoldi restart can save considerable computational expense by reducing the number applications of the linear operator A required.  (The application of the linear operator in Monte Carlo particle transport is responsible for > 80\\% of the computational runtime.)  In short, IRAM exchanges Arnoldi iterations for shifted \\QR iterations.  Shifted \\QR iterations are faster than Arnoldi iterations because $H_m$ is small.\n\n\\section*{How Implicit Restarts Suppresses Unwanted Eigenvalue Information}\nWe have just shown that implicit restarts can be computationally more efficient.  Here we show that implicit restarts are mathematically equivalent to restarting with a linear combination of the Ritz vectors from the desired region of the spectrum of $A$ \\citep[see][Chapter~5,~pg.~456]{Watkins:2002Funda-0}.\n\n\\begin{thm}\\label{thm:ArnoldiPolynomial}\n    Suppose we have the Arnoldi factorization\n    \\begin{equation}\n        AV_m = V_mH_m + v_{m+1}h_{m+1,m}e_m^T\n    \\end{equation}\n    and let $\\p_j$ be a polynomial of degree $j < m$ as shown in \\fref{eq:Polynomial}.  Then\n    \\begin{equation}\n        \\poly{j}{A}V_m = V_m\\poly{j}{H_m} + E_j,\n        \\label{eq:PolyAPolyHDefined}\n    \\end{equation}\n    where $E_j \\in \\mathbb{C}^{n \\times m}$ is identically zero, except in the last $j$ columns.\n\\end{thm}\n\n\\begin{proof}\nFor $m=1$ we can just apply a shift $\\nu_1$ to the Arnoldi factorization, \\fref{eq:ArnoldiFactorizationIRAM},\n\\begin{equation}\n    \\left(A-\\nu_1 I\\right)V_m = V_m\\left(H_m - \\nu_1 I\\right) + E_1\n    \\label{eq:ArnoldiPolynomialDegree1}\n\\end{equation}\nwhere $E_1 = h_{m+1,m}v_{m+1}e_m^T$.  We can see that $E_1$ is zero except for the last column by the product $ v_{m+1}e_m^T$.  $\\left(A-\\nu_1 I\\right)$ and $\\left(H_m - \\nu_1 I\\right)$ are polynomials of $A$ and $H_m$ respectively with degree $j=1$, both with root $\\nu_1$.\n\nAssuming this theorem holds for polynomials of degree $j-1$ (we have just shown this to be true for $j-1=1$) we can now show it is valid for polynomials of degree $j$.  We know:\n\\begin{equation}\n        \\left(A-\\nu_{j-1}I\\right)\\cdots\\left(A-\\nu_1I\\right)V_m = V_m\\left(H_m-\\nu_{j-1}I\\right)\\cdots\\left(H_m-\\nu_1I\\right) + E_{j-1}\n\\end{equation}\noperate on the left by $\\left( A-\\nu_jI \\right)$\n\\begin{multline}\n    \\left(A-\\nu_jI\\right)\\left(A-\\nu_{j-1}I\\right)\\cdots\\left(A-\\nu_1I\\right)V_m =  \\\\\n    \\left(A-\\nu_jI\\right)V_m\\left(H_m-\\nu_{j-1}I\\right)\\cdots\\left(H_m-\\nu_1I\\right) + \\left(A-\\nu_jI\\right)E_{j-1}.\n\\end{multline}\nSubstituting $\\nu_j$ for $\\nu_1$ in \\fref{eq:ArnoldiPolynomialDegree1} we see that\n\\begin{equation}\n    \\left(A-\\nu_j I\\right)V_m = V_m\\left(H_m - \\nu_j I\\right) E_1\n    \\label{eq:ArnoldiPolynomialDegreej}\n\\end{equation}\nwhich can be inserted into the previous equation\n\\begin{align}\n    \\lefteqn{\\left(A-\\nu_jI\\right)\\cdots\\left(A-\\nu_1I\\right)V_m} \\qquad \\nonumber \\\\\n    \\begin{split}\n    &= \\left[ \\left(A-\\nu_jI\\right)V_m \\right]\\left(H_m-\\nu_{j-1}I\\right)\\cdots\\left(H_m-\\nu_1I\\right) + \\left(A-\\nu_jI\\right)E_{j-1} \\\\\n     &= \\left[ V_m\\left(H_m-\\nu_jI\\right)+E_1 \\right]\\left(H_m-\\nu_{j-1}I\\right)\\cdots\\left(H_m-\\nu_1I\\right) + \\left(A-\\nu_jI\\right)E_{j-1} \\\\\n     &= V_m\\left(H_m-\\nu_jI\\right)\\cdots\\left(H_m-\\nu_1I\\right) + E_1\\left(H_m - \\nu_{j-1}I\\right)\\cdots\\left(H_m - \\nu_1I\\right) \\\\\n     &\\qquad + \\left(A-\\nu_jI\\right)E_{j-1} \\\\\n     &= V_m\\left(H_m-\\nu_jI\\right)\\cdots\\left(H_m-\\nu_1I\\right) + E_j\n     \\label{eq:PolyAPolyHProof}\n    \\end{split}\n\\end{align}\nwhere \n\\begin{equation}\n    \\label{eq:Ej}\n    E_j = E_1\\left(H_m - \\nu_{j-1}I\\right)\\cdots\\left(H_m - \\nu_1I\\right) + \\left(A-\\nu_jI\\right)E_{j-1}.\n\\end{equation}\nWe can simplify \\fref{eq:PolyAPolyHProof} further and write\n\\begin{equation}\n    \\poly{j}{A}V_m = V_m\\poly{j}{H_m} + E_j,\n    \\label{eq:PolyAPolyHProved}\n\\end{equation}\nwhere \\[\\poly{j}{A} = \\left(A-\\nu_jI\\right)\\cdots\\left(A-\\nu_1I\\right)\\] is a polynomial of degree $j$ on $A$ and \\[\\poly{j}{H_m} = \\left(H_m-\\nu_jI\\right)\\cdots\\left(H_m-\\nu_1I\\right)\\] is a polynomial of degree $j$ on $H_m$.  Equation \\eqref{eq:PolyAPolyHProved} is exactly what we want to prove \\fref{eq:PolyAPolyHDefined}.\n\nWe know that the columns of $E_{j-1}$ are zero except the last $j-1$ columns.  We can see by inspection that the second term on the right hand side of \\fref{eq:Ej} has the same structure.  From \\fref{thm:jkHessenberg} we know that the product $\\left(H_m - \\nu_{j-1}I\\right)\\cdots\\left(H_m - \\nu_1I\\right)$ is properly $j$-Hessenberg.  Multiply this by $E_1$ on the left and we obtain a zero matrix except in the last $j$ columns.  The right hand side of \\fref{eq:Ej} is therefore as we expected.\n\\end{proof}\n\nNow that we have the necessary mathematical basis to understand what happens with an implicit Arnoldi restart we can investigate how IRAM generates it's starting vector.    In IRAM the shifts $\\nu_1$, $\\nu_2$, \\ldots, $\\nu_j$ are chosen from the region of the eigenvalue spectrum that is to be suppressed.  These shifts are then used in $j$ iterations of the shifted \\QR algorithm on $H_m$ resulting in $\\hat{H}_j = \\hat{Q}_j^*H_m\\hat{Q}_j$ where $\\hat{Q}_j$ is the combined unitary factor in the \\QR factorization\n\\begin{equation}\n    \\poly{j}{H_m} = \\hat{Q}_j\\hat{R}_j\n    \\label{eq:HmPolynomial}\n\\end{equation}\nwhere $j$ indicates the number of shifted \\QR iterations performed and $\\poly{j}{z}$ is defined in \\fref{eq:Polynomial}.  When we apply \\fref{thm:ArnoldiPolynomial} and substitute \\fref{eq:HmPolynomial} we obtain\n\\begin{equation}\n    \\poly{j}{A}V_m = V_m\\hat{Q}_j\\hat{R}_m + E_j.\n    \\label{eq:PolyArnoldiFactAllColumns}\n\\end{equation}\nThe Arnoldi factorization is uniquely defined by the starting vector and the linear operator.  If we multiply \\fref{eq:PolyArnoldiFactAllColumns} by $e_1$ we get\n\\begin{equation}\n    \\poly{j}{A}V_me_1 = V_m\\hat{Q}_j\\hat{R}_je_1 + E_je_1.\n    \\label{eq:PolyArnoldiFactColumn1}\n\\end{equation}\n$E_je_1 = 0$ because the first column of $E_j$ is zero.  Since $\\hat{R}_j$ is upper triangular \\mbox{$\\hat{R}_je_1 = r_{11}e_1 = \\alpha e_1$} and the first term on the right hand side is \\mbox{$\\alpha V_m\\hat{Q}_m = \\alpha \\hat{v}_1$}.  The left hand side of \\fref{eq:PolyArnoldiFactColumn1} is just a polynomial of degree $j$ of $A$ multiplied by $v_1$ the starting vector for this Arnoldi process.  From \\fref{eq:PolyArnoldiFactColumn1} we can deduce\n\\begin{equation}\n    \\hat{v}_1 = \\frac{1}{\\alpha}\\poly{j}{A}v_1.\n    \\label{eq:IRAMRestartVector}\n\\end{equation}\n\nLet's return to the starting vector for an Arnoldi procedure.  We can write the vector as a linear combination of a set of basis vectors\n\\begin{equation}\n    v_1 = c_1x_1 + c_2x_2 + \\cdots + c_nx_n,\n\\end{equation}\nwhere the $x_i$'s are the basis vectors and the $c_i$'s are some expansion coefficients.  If we choose the eigenvectors of our linear operator $A$ as our basis vectors then things become interesting with respect to IRAM.  To see this, multiply $v_1$ by a polynomial of degree $1$ of $A$\n\\begin{equation}\n    \\begin{split}\n        \\poly{1}{A}v_1 &= \\left(A-\\nu_1I\\right)\\left(c_1x_1 + c_2x_2 + \\cdots + c_nx_n\\right) \\\\\n         &= c_1\\left(Ax_1 - \\nu_1x_1\\right) + \\cdots c_n\\left(Ax_n - \\nu_1x_n\\right)\n    \\end{split}\n        \\label{eq:PolyStartingVectorTerm1}\n\\end{equation}\nwhere we remember the $x_i$'s are the eigenvectors of $A$ and that $\\nu_1$ is the first undesired eigenvalue, $\\lambda_{k+1}$.  Equation \\eqref{eq:PolyStartingVectorTerm1} becomes\n\\begin{multline}\n    \\poly{1}{A}v_1 = c_1\\left(\\lambda_1x_1 - \\nu_1x_1\\right) + \\cdots \\\\\n    +c_{k+1}\\underbrace{\\left(\\lambda_{k+1}x_{k+1} - \\nu_1x_{k+1}\\right)}_{=0} + \\\\\n    \\cdots + c_n\\left(\\lambda_nx_n - \\nu_1x_n\\right)\n\\end{multline}\nwhere the vector $x_{k+1}$ has been completely eliminated.  \n\nIf we include all the terms of the polynomial $\\poly{j}{A}$ then all $j$ eigenvectors from the undesired region of the spectrum are removed from our restart vector\n\\begin{multline}\n    \\poly{j}{A}v_1 = c_1\\left(\\lambda_1x_1 - \\nu_1x_1\\right)\\left(\\lambda_1x_1 - \\nu_2x_1\\right)\\cdots\\left(\\lambda_1x_1 - \\nu_jx_1\\right) + \\cdots \\\\\n    + c_k\\left(\\lambda_kx_k - \\nu_kx_k\\right)\\cdots\\left(\\lambda_kx_k - \\nu_kx_k\\right) + 0.\n\\end{multline}\nWe can plug this result into \\fref{eq:IRAMRestartVector} and get our optimal restart vector as described in \\fref{eq:RestartVector}.\n\nThus we see that implicitly restarted Arnoldi's method is mathematically equivalent to explicitly restarted Arnoldi's method but can skip into the restart after $k$ iterations.  IRAM can save computational expense by trading expensive applications of the linear operator for cheap shifted \\QR iterations.\n\n%\\section*{Monte Carlo Implementation} \\label{sec:MCIRAM}\n", "meta": {"hexsha": "e49733c24f291634fccdc6ca039c755575f2e423", "size": 23576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Dissertation/QRAlgorithm/QRAlgorithm.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/QRAlgorithm/QRAlgorithm.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/QRAlgorithm/QRAlgorithm.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": 63.2064343164, "max_line_length": 627, "alphanum_fraction": 0.6890906006, "num_tokens": 8368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6654895835513113}}
{"text": "\\subsection{Dynamic Time Warping}\n\\label{dtw}\n\nThe question of how to take the difference between the demand curve and\nthe production curve is an important one. The na\\\"ive option is to simply\ntake the $L_1$ norm of the difference between these two time series, as\nseen in Equation \\ref{delta-l1}.  However, since the $g(t, \\Theta)$ computed\nfrom a simulation is expensive, any operation that can meaningfully\nexacerbate the difference between time series helps drive down the number\nof optimization iterations.\n\nDynamic time warping is just such a mechanism. It computes\na distance between any two time series which compounds the separation\nbetween the two. Additionally, the time series are not required to be of the\nsame length, though for optimization purposes there is no reason for them\nnot to be. DTW gives a measure of the amount that one time series would need to\nbe warped to become the other time series. It is, therefore, a holistic\nmeasure that operates over all times. Dynamic time warping\nis more fully covered in \\cite{muller}.  However, an\noptimization-relevant introduction is given here.\n\nFor the time series $f$ and $g$, there are three parts to dynamic time\nwarping. The first is the distance $d$, which will be minimized. The second\nis a cost matrix $C$ that helps compute $d$ by indicating how far a point\non $f$ is from another point on $g$. Thirdly, the warp path $u$ is the\nminimal cost curve through the $C$ matrix from the fist point in time to\nthe last. The DTW distance can thus be interpreted as the\ntotal cost of traveling the warp path.\n\nThe first step in computing a dynamic time warp distance is to\nassemble the cost matrix. Say that the demand time series $f$ has\nlength $A$ indexed by $a$, and the production time series $g$ has\nlength $B$ indexed by $b$. For the optimization problem here, $A$ and $B$\nare in practice both equal to $T$.  However, it is useful to have $a$ and\n$b$ index the two time series separately. Now denote an $A\\times B$ matrix\n$\\Delta L$ as the $L_1$ norm of the difference between $f$ and $g$:\n\\begin{equation}\n\\label{delta-l1}\n\\Delta L_{a,b} = \\left|f(a) - g(b, \\Theta)\\right|_1\n\\end{equation}\nSince $\\Delta L$ uses the $L_1$ norm, $f$ and $g$ may return vector\ndata. This enables multi-objective optimization. However it is recommended\nthat the components of the $f$ and $g$ are weighted, normalized, or otherwise\ndirectly comparable.\n\nThe cost matrix $C$ may now be defined as the $A\\times B$ sized matrix\nwhich follows the recursion relations seen in Equation \\ref{cost-matrix}.\n\\begin{equation}\n\\label{cost-matrix}\n\\begin{split}\nC_{1,1} & = \\Delta L_{1,1}\\\\\nC_{1,b+1} & = \\Delta L_{1,b} + C_{1,b}\\\\\nC_{a+1,1} & = \\Delta L_{a,1} + C_{a,1}\\\\\nC_{a+1,b+1} & = \\Delta L_{a,b} + \\min\\left[C_{a,b}, C_{a+1,b}, C_{a,b+1}\\right]\n\\end{split}\n\\end{equation}\nThe boundary conditions above are the same as setting an infinite cost to\nany $a \\le 0$ or $b \\le 0$. The cost matrix $C$ has the same units as the\ndemand curve. However, the scale of $C$ is\nlarger than the demand,\nexcept for in the fiducial case. This is because the cost matrix compounds the\nminimum value of previous entries.\n\nKnowing a cost matrix, the warp path can be computed by traversing the\nmatrix backwards from the $(A, B)$ corner to the $(1, 1)$ corner.\nIf the length of the warp is $I$ indexed by $i$, the warp path itself\ncan be thought of as a sequence of coordinate points $u_i$. For a given\npoint $u_i$ in the warp path, the previous point $u_{i-1}$ may be found by\npicking the minimum cost point among the locations one column over $(a,b-1)$,\none row over $(a-1,b)$, and one previous diagonal element to $(a-1,b-1)$.\nEquation \\ref{warp-path} expresses this mathematically.\n\\begin{equation}\n\\label{warp-path}\nu_{i-1} = \\argmin\\left[C_{a-1,b-1}, C_{a-1,b}, C_{a,b-1}\\right]\n\\end{equation}\nThe maximum possible length of $u$ is thus $\\max(I) = A + B$.\nThe minimum possible length, though, is $\\min(I) = \\sqrt{A^2 + B^2}$.\n\nThe dynamic time warping distance distance $d$ can now be stated as the\ncost of the final entry of the warp path normalized by the maximum possible\nlength of the warp path.\n\\begin{equation}\n\\label{d-calc-ab}\nd(f, g) = \\frac{C_{A,B}}{A + B}\n\\end{equation}\nHowever, because the demand curve and the production curve\nare often defined on the same time grid, $d$ can be further\nreduced to the following:\n\\begin{equation}\n\\label{d-calc}\nd(f, g) = \\frac{C_{T,T}}{2T}\n\\end{equation}\nTherefore, $d$ has the same units as the demand curve, production curve,\nand cost matrix.\n\nAs an example, take a 1\\% growth that starts with 90 GWe in the year\n2016 as the demand curve. Then consider a production curve that\nunder-produces the demand by 5\\% for 25 years before switching to\nover-producing this curve by 5\\% for the next 25 years.\nFigure \\ref{cost-demand-to-production} shows the dynamic time warping\ncost matrix between these two time series as a heat map.\n\n\\begin{figure}[htb]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{cost-demand-to-production.eps}\n\\caption{Heat map of the cost matrix between a 1\\% growth demand curve and\na production curve the under produces by 5\\% for the first 25 years and then\nover produces for the second 25 years.\nThe warp path $u$ is superimposed as the white curve on top of the\ncost matrix.}\n\\label{cost-demand-to-production}\n\\end{figure}\n\nAdditionally, the warp path between the example demand and production\ncurves is presented as the white curve on top of the heat map in\nFigure \\ref{cost-demand-to-production}.\nRecognize that $u$ is monotonic along both time axes. Furthermore, the precise\npath of $u$ minimizes the cost matrix at every step. Regions of increased\ncost in the cost matrix can be seen to repel the warp path. The\ndistance $d$ between the demand and production curves here happens\nto be 0.756 GWe.\n\nDynamic time warping distance can therefore be used as an objective function\nto minimize for any demand and production curves. However, using full\nsimulations to find $g(t, \\Theta)$ remains expensive, even though DTW itself\nis computationally cheap. Therefore, a mechanism to reduce the overhead\nfrom production curve evaluation is needed.\n", "meta": {"hexsha": "c12f6f5226f911ca9e90c648a993e7165d0fb9aa", "size": 6141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dtw.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": "dtw.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": "dtw.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.9765625, "max_line_length": 79, "alphanum_fraction": 0.7503663898, "num_tokens": 1700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6654267505659851}}
{"text": "\\chapter{Milestone 4}\n\\section{Force-Derivation from the Lenard Jones Potential}\n\n\\begin{comment}\n1. Put the python code here\n2. write the base equations (lj + f)\n3. write the result form the python code \n4. write some text\n5. c++ code that results from this?\n\\end{comment}\n%% equations\n\\begin{equation}\n\t\\overrightarrow{f_{k}} = \\sum_{i}^{}\\frac{\\partial V}{\\partial r_{ik}} \\hat{r_{ik}}\n\\end{equation}\n\n\\begin{equation}\n\tV(r) = 4\\epsilon\\bigg[\\Big(\\frac{\\sigma}{r}\\Big)^{12}- \\Big(\\frac{\\sigma}{r}\\Big)^{6} \\bigg]\n\\end{equation}\n\n\\begin{equation}\n\t\\frac{\\partial V}{\\partial r_{ik}} = 4\\epsilon\\Bigg(\\frac{6\\sigma^{6}}{r_{ik}^{6}} - \\frac{12\\sigma^{12}}{r_{ik}^{13}} \\Bigg)\n\\end{equation}\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{k+kn}{import} \\PY{n+nn}{sympy} \\PY{k}{as} \\PY{n+nn}{sp}\n\\PY{k+kn}{import} \\PY{n+nn}{warnings}\n\\PY{n}{warnings}\\PY{o}{.}\\PY{n}{filterwarnings}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{ignore}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{sp}\\PY{o}{.}\\PY{n}{init\\PYZus{}printing}\\PY{p}{(}\\PY{p}{)}\n\\PY{n}{eps} \\PY{o}{=} \\PY{n}{sp}\\PY{o}{.}\\PY{n}{Symbol}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{e}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{sig} \\PY{o}{=} \\PY{n}{sp}\\PY{o}{.}\\PY{n}{Symbol}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{s}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{rad} \\PY{o}{=} \\PY{n}{sp}\\PY{o}{.}\\PY{n}{Symbol}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{r}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{)}\n\\PY{n}{energyRad} \\PY{o}{=} \\PY{l+m+mi}{4} \\PY{o}{*} \\PY{n}{eps} \\PY{o}{*} \\PY{p}{(}\\PY{p}{(}\\PY{n}{sig}\\PY{o}{/}\\PY{n}{rad}\\PY{p}{)}\\PY{o}{*}\\PY{o}{*}\\PY{l+m+mi}{12} \\PY{o}{\\PYZhy{}} \\PY{p}{(}\\PY{n}{sig}\\PY{o}{/}\\PY{n}{rad}\\PY{p}{)}\\PY{o}{*}\\PY{o}{*}\\PY{l+m+mi}{6}\\PY{p}{)}\n\\PY{n}{energyRad}\\PY{o}{.}\\PY{n}{diff}\\PY{p}{(}\\PY{n}{rad}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\\prompt{Out}{outcolor}{4}{}\n\n    $\\displaystyle 4 e \\left(\\frac{6 s^{6}}{r^{7}} - \\frac{12 s^{12}}{r^{13}}\\right)$\n\n%%\n\n\n\n\\section{Different Time Steps}\n%plots for different timesteps\n\\begin{comment}\n- ploted for different timesteps to see diffrent results\n- all were stable expect the 0.03 which crashed the program while returning (SIGABRT)\n- discuss the curves\n- in the end choose the 0.01 timestep which in my Opinion was the best tradeoff between \n\taccuracy and time spent simulating\n- maybe also just plot them in one but will have tho smooth it out in this case\n\\end{comment}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale=1]{Figure/plot_001.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation with a time step of 0.001}\n\t\\label{Plot001}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/plot_005.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation with a time step of 0.005}\n\t\\label{Plot005}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale=1]{Figure/plot_01.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation with a time step of 0.01}\n\t\\label{Plot01}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/plot_02.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation with a time step of 0.02 }\n\t\\label{Plot02}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/plot_03.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation with a time step of 0.03 }\n\t\\label{Plot03}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/plot_04.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation with a time step of 0.04 }\n\t\\label{Plot04}\n\\end{figure}\n%Snapshots of the simulation (5)\n\\section{Simulation Snapshots}\n\\begin{comment}\n- not sure if i just use 2 \n- background kinda bad?!\n\\end{comment}\n\nReworked the graphs allready in the Discrition\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/1Image.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation }\n\t\\label{Simulation1}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale=1]{Figure/2Image.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation}\n\t\\label{Simulation2}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/3Image.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation }\n\t\\label{Simulation3}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{Figure/4Image.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation }\n\t\\label{Simulation4}\n\\end{figure}\n\\begin{figure}[!h]\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1]{/home/cm/CLionProjects/MDCode/AData//totalEnergyDrift.png}\n\t\\end{center}\n\t\\caption[Simulation]{Simulation }\n\t\\label{Simulation5}\n\\end{figure}", "meta": {"hexsha": "f39fd8c0a9274cb868afaa3690545cc7b3c3f4b1", "size": 4710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AALatex/Tex/milestone4.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/milestone4.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/milestone4.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": 33.6428571429, "max_line_length": 274, "alphanum_fraction": 0.6681528662, "num_tokens": 1791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6654267444543095}}
{"text": "\\chapter{Curvilinear Coordinates}\r\n\\noindent\r\nYou should already know about Cartesian $(x,y)$ coordinates and polar $(r,\\theta)$ coordinates in 2D. Cartesian extends to 3D as $(x,y,z)$, but there are multiple ways to extend polar coordinates into 3D.\\\\\r\n\r\n\\input{./curvilinearCoordinates/reviewPolarCoordinates}\r\n\\input{./curvilinearCoordinates/cylindricalCoordinates}\r\n\\input{./curvilinearCoordinates/sphericalCoordinates}", "meta": {"hexsha": "b088934bdee307dcaa3fd973603bfc1b475595b2", "size": 423, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/curvilinearCoordinates.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/curvilinearCoordinates.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/curvilinearCoordinates.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": 60.4285714286, "max_line_length": 207, "alphanum_fraction": 0.7943262411, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6654267425476557}}
{"text": "\\lab{Visualizing Complex-valued Functions}{Visualizing Complex-valued Functions}\n\\objective{Functions that map from the complex plane into the complex plane are difficult to fully visualize because the domain and range are both $2$-dimensional.\nHowever, such functions can be visualized at the expense of partial information.\nIn this lab we present methods for analyzing complex-valued functions visually, including locating their zeros and poles in the complex plane.\nWe recommend completing the exercises in a Jupyter Notebook.}\n\n\\section*{Representations of Complex Numbers} % ===============================\n\nA complex number $z = x+iy$ can be written in \\emph{polar coordinates} as $z = re^{i\\theta}$ where\n\\begin{itemize}\n\\item $r = |z| = \\sqrt{x^2+y^2}$ is the \\emph{magnitude} of $z$, and\n\\item $\\theta = \\arg(z) = \\arctan(y/x)$ is the \\emph{argument} of $z$, the angle in radians between $z$ and $0$.\n\\end{itemize}\nConversely, Euler's formula is the relation $re^{i\\theta} = r\\cos(\\theta) + ir\\sin(\\theta)$.\nThen setting $re^{i\\theta}=x+iy$ and equating real and imaginary parts yields the equations $x=r\\cos(\\theta)$ and $y=r\\sin(\\theta)$.\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[dot/.style={circle,fill=black,minimum size=3pt,\n    inner sep=0pt,outer sep=-1pt}, >=stealth', thick, xscale=1.4]\n\n\\draw[-](-.5,0)--(3,0);\n\\draw[-](0,-.5)--(0,3);\n\n\\draw[-, dashed, gray, anchor=east](2.6,2.3)--(0,2.3);\n\\node[draw=none]()at(-.3,2.3){$iy$};\n\\draw[-, dashed, gray, anchor=north ](2.6,2.3)--(2.6,0);\n\\node[draw=none]()at(2.6,-.3){$x$};\n\n\\draw[gray](.75,0) arc (0:45:.7 and .7);\n\n\\draw[-](0,0)--(2.6,2.3);\n\\node[dot,draw](point)at(2.6,2.3){};\n\\node[draw=none]()at(2.8,2.5){$z$};\n\\node[draw=none]()at(.9,.35){$\\theta$};\n\n\\draw [decorate,decoration={brace,amplitude=10pt},rotate=-45, gray] (0,0) --(.2,3.45);\n\\node[draw=none]()at(1.05,1.65){$r$};\n\n\\end{tikzpicture}\n\\caption{The complex number $z$ can be represented in Cartesian coordinates as $z = x+iy$ and in polar coordinates as $z = re^{i\\theta}$, when $\\theta$ is in radians.}\n\\label{fig:polar_coords}\n\\end{figure}\n\nNumPy makes it easy to work with complex numbers and convert between coordinate systems.\nThe function \\li{np.angle()} returns the argument $\\theta$ of a complex number (between $-\\pi$ and $\\pi$) and \\li{np.<<abs>>()} (or \\li{np.absolute()}) returns the magnitude $r$.\nThese functions also operate element-wise on NumPy arrays.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\n>>> z = 2 - 2*1j                    # 1j is the imaginary unit i = sqrt(-1).\n>>> r, theta = np.<<abs>>(z), np.angle(z)\n>>> print(r, theta)                 # The angle is between -pi and pi.\n2.82842712475 -0.785398163397\n\n# Check that z = r * e^(i*theta)\n>>> np.isclose(z, r*np.exp(1j*theta))\n<<True>>\n\n# These function also work on entire arrays.\n>>> np.<<abs>>(np.arange(5) + 2j*np.arange(5))\narray([ 0.        ,  2.23606798,  4.47213595,  6.70820393,  8.94427191])\n\\end{lstlisting}\n\n\\section*{Complex Functions} % ================================================\n\nA function $f: \\mathbb{C} \\rightarrow \\mathbb{C}$ is called a \\emph{complex-valued function}.\nVisualizing $f$ is difficult because $\\mathbb{C}$ has 2 real dimensions, so the graph of $f$ should be 4-dimensional.\nHowever, since it is possible to visualize 3-dimensional objects, $f$ can be visualized by ignoring one dimension.\nThere are two main strategies for doing this: assign a color to each point $z\\in\\mathbb{C}$ corresponding to either the argument $\\theta$ of $f(z)$, or to the magnitude $r$ of $f(z)$.\nThe graph that uses the argument is called a \\emph{complex color wheel graph}.\nFigure \\ref{fig:complex-identity-angle-mag} displays the identity function $f(z) = z$ using these two methods.\n\n\\begin{figure}[H] % f(z) = z\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/identity_angle.png}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/identity_magnitude.png}\n\\end{subfigure}\n\\caption{The identity function $f: \\mathbb{C} \\rightarrow \\mathbb{C}$ defined by $f(z)=z$. On the left, the color at each point $z$ represents the angle $\\theta = \\arg(f(z))$. As $\\theta$ goes from $-\\pi$ to $\\pi$, the colors cycle smoothly counterclockwise from white to blue to red and back to white (this colormap is called \\li{\"twilight\"}). On the right, the color represents the magnitude $r = |f(z)|$. The further a point is from the origin, the greater its magnitude (the colormap is the default, \\li{\"viridis\"}).\n}\n\\label{fig:complex-identity-angle-mag}\n\\end{figure}\n\nThe plots in Figure \\ref{fig:complex-identity-angle-mag} use Cartesian coordinates in the domain and polar coordinates in the codomain.\nThe procedure for plotting in this way is fairly simple.\nBegin by creating a grid of complex numbers: create the real and imaginary parts separately, then use \\li{np.meshgrid()} to turn them into a single array of complex numbers.\nPass this array to the function $f$, compute the angle and argument of the resulting array, and plot them using \\li{plt.pcolormesh()}.\nThe following code sets up the complex domain grid.\n\n\\begin{lstlisting}\n>>> x = np.linspace(-1, 1, 400)     # Real domain.\n>>> y = np.linspace(-1, 1, 400)     # Imaginary domain.\n>>> X, Y = np.meshgrid(x, y)        # Make grid matrices.\n>>> Z = X + 1j*Y                    # Combine the grids into a complex array.\n\\end{lstlisting}\n\nVisualizing the argument and the magnitude separately provides different perspectives of the function $f$.\nThe angle plot is generally more useful for visualizing function behavior, though the magnitude plot often makes it easy to spot important points such as zeros and poles.\n% Use both of these plots together to get as much information as possible about the function.\n\n\\begin{figure}[H] % f(z) = sqrt(z^2 - 1)\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/discontinuity_angle.png}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/discontinuity_magnitude.png}\n\\end{subfigure}\n\\caption{Plots of $f(z) = \\sqrt{z^2+1}$ on $\\{x+iy \\mid x,y \\in [-3,3]\\}$.\nNotice how a discontinuity is clearly visible in the angle plot on the left, but disappears from the magnitude plot on the right.}\n\\label{fig:complex-discontinuity}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that accepts a function $f:\\mathbb{C}\\rightarrow\\mathbb{C}$,  bounds $[r_{\\text{min}},r_{\\text{max}},i_{\\text{min}},i_{\\text{max}}]$ for the domain, an integer \\li{res} that determines the resolution of the plot, and a string to set the figure title.\nPlot $\\arg(f(z))$ and $|f(z)|$ on an equally-spaced \\li{res}$\\times$\\li{res} grid over the domain $\\{x + iy \\mid x \\in [r_{\\text{min}},r_{\\text{max}}],\\: y \\in [i_{\\text{min}},i_{\\text{max}}]\\}$ in separate subplots.\n\\begin{enumerate}\n\\item For $\\arg(f(z))$, set the \\li{plt.pcolormesh()} keyword arguments \\li{vmin} and \\li{vmax} to $-\\pi$ and $\\pi$, respectively.\nThis forces the color spectrum to work well with \\li{np.angle()}.\nUse the colormap \\li{\"twilight\"}, which starts and ends white, so that the color is the same for $-\\pi$ and $\\pi$.\n\n\\item For $|f(z)|$, set \\li{norm=matplotlib.colors.LogNorm()} in \\li{plt.pcolormesh()} so that the color scale is logarithmic.\nUse a sequential colormap like \\li{\"viridis\"} or \\li{\"magma\"}.\n\n\\item Set the aspect ratio to \\li{\"equal\"} in each plot.\nGive each subplot a title, and set the overall figure title with the given input string.\n\\end{enumerate}\n\nUse your function to visualize $f(z) = z$ on $\\{x+iy \\mid x,y \\in [-1,1]\\}$ and $f(z) = \\sqrt{z^2+1}$ on $\\{x+iy \\mid x,y \\in [-3,3]\\}$.\nCompare the resulting plots to Figures \\ref{fig:complex-identity-angle-mag} and \\ref{fig:complex-discontinuity}, respectively.\n\\label{prob:complex-plotting-function}\n\\end{problem}\n\n\\section*{Interpreting Complex Plots} % =======================================\n\nPlots of a complex function can be used to quickly identify important points in the function's domain.\n\n\\subsection*{Zeros} % ---------------------------------------------------------\n\nA complex number $z_0$ is called a \\emph{zero} of the complex-valued function $f$ if $f(z_0) = 0$.\n% $z_0$ is also called a \\emph{root} of the equation $f(z) = 0$.\nThe \\emph{mutliplicity} or \\emph{order} of $z_0$ is the largest integer $n$ such that $f$ can be written as $f(z) = (z - z_0)^n g(z)$ where $g(z_0) \\ne 0$.\n% In this case, $z_0$ is called a \\emph{zero of order $n$} of $f$.\nIn other words, $f$ has a zero of order $n$ at $z_0$ if the Taylor series of $f$ centered at $z_0$ can be written as\n\\[\nf(z) = \\sum_{k=n}^{\\infty} a_k(z-z_0)^k, \\qquad  a_n \\neq 0.\n\\]\n\nAngle and magnitude plots make it easy to locate a function's zeros and to determine their multiplicities.\n\n\\begin{problem} % Plot zeros.\nUse your function from Problem \\ref{prob:complex-plotting-function} to plot the following functions on the domain $\\{x+iy \\mid x,y \\in [-1,1]\\}$.\n\\begin{itemize}\n\\item $f(z) = z^n$ for $n=2,3,4$.\n\\item $f(z) = z^3 - iz^4 - 3z^6$.\nCompare the resulting plots to Figure \\ref{fig:complex-zeros}.\n\\end{itemize}\nUse a Markdown cell to write a sentence or two about how the zeros of a function and their multiplicity appear in angle and magnitude plots.\n\\label{prob:plot-complex-zeros}\n\\end{problem}\n\n% In other words, $f(z) = a_n(z-z_0)^n + a_{n+1}(z-z_0)^{n+1} + \\ldots$.\n% This explains why we can estimate the order of a zero by counting the number of times the colors circle a point (see Figure \\ref{fig:complex-zeros}).\n\nProblem \\ref{prob:plot-complex-zeros} shows that in an angle plot of $f(z) = z^n$, the colors cycle $n$ times counterclockwise around 0.\nThis is explained by looking at $z^n$ in polar coordinates,\n\\[\nz^n = (re^{i \\theta})^n = r^n e^{i(n\\theta)}.\n\\]\nMultiplying $\\theta$ by a number greater than $1$ compresses the graph along the ``$\\theta$-axis'' by a factor of $n$.\nIn other words, the output angle repeats itself $n$ times in one cycle of $\\theta$.\nThis is similar to taking a scalar-valued function $f:\\mathbb{R}\\rightarrow\\mathbb{R}$ and replacing $f(x)$ with $f(nx)$.\n\nProblem \\ref{prob:plot-complex-zeros} also shows that the plot of $f(z) = z^3 - iz^4 - 3z^6$ looks very similar to the plot of $f(z) = z^3$ near the origin.\nThis is because when $z$ is close to the origin, $z^4$ and $z^6$ are much smaller in magnitude than $z^3$, and so the behavior of $z^3$ dominates the function.\nIn terms of the Taylor series centered at $z_0 = 0$, the quantity $|z-z_0|^{n+k}$ is much smaller than $|z-z_0|^n$ for $z$ close to $z_0$, and so the function behaves similar to $a_n(z-z_0)^n$.\n\n\\begin{figure}[H] % f(z) = z^3 - iz^4 - 3z^6\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/zeros_angle.png}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/zeros_magnitude.png}\n\\end{subfigure}\n\\caption{The angle plot of $f(z)=z^3 - iz^4 - 3z^6$ on $\\{x+iy \\mid x,y \\in [-1,1]\\}$. The angle plot shows that $f(z)$ has a zero of order $3$ at the origin and $3$ distinct zeros of order $1$ scattered around the origin.\nThe magnitude plot makes it easier to pinpoint the location of the zeros.}\n% and shows that the basin around the origin is a little wider than the basins around the other zeros.}\n\\label{fig:complex-zeros}\n\\end{figure}\n\n\\subsection*{Poles} % ---------------------------------------------------------\n\nA complex number $z_0$ is called a \\emph{pole} of the complex-valued function $f$ if $f$ can be written as $f(z) = g(z) / (z - z_0)$ where $g(z_0) \\ne 0$.\nFrom this definition it is easy to see that $\\lim_{z\\rightarrow z_0}|f(z)| = \\infty$, but knowing that $\\lim_{z\\rightarrow z_1}|f(z)| = \\infty$ is not enough information to conclude that $z_1$ is a pole of $f$.\n\nThe \\emph{order} of $z_0$ is the largest integer $n$ such that $f$ can be written as $f(z) = g(z) / (z - z_0)^n$ with $g(z_0) \\ne 0$.\nIn other words, $f$ has a pole of order $n$ at $z_0$ if its Laurent series on a punctured neighborhood of $z_0$ can be written as\n\\[\nf(z) = \\sum_{k=-n}^\\infty a_k(z-z_0)^k  \\qquad, a_{-n} \\neq 0.\n\\]\n\n\\begin{problem} % Plot poles.\nPlot the following functions on domains that show all of its zeros and/or poles.\n\\begin{itemize}\n\\item $f(z) = z^{-n}$ for $n=1,2,3$.\n\\item $f(z) = z^2+iz^{-1}+z^{-3}$.\n\\end{itemize}\nUse a Markdown cell to write a sentence or two about how the poles of a function appear in angle and magnitude plots.\nHow can you tell the multiplicity of the poles from the plot?\n\\label{prob:plot-complex-poles}\n\\end{problem}\n\nProblem \\ref{prob:plot-complex-poles} shows that in angle plot of $z^{-1}$, the colors cycle $n$ times clockwise around $0$, as opposed to the counter-clockwise rotations seen around roots.\nAgain, this can be explained by looking at the polar representation,\n\\[\nz^{-n} = (re^{i \\theta})^{-n} = r^{-n} e^{i(-n\\theta)}.\n\\]\nThe minus sign on the $\\theta$ reverses the direction of the colors, and the $n$ makes them cycle $n$ times.\n\nFrom Problem \\ref{prob:plot-complex-poles} it is also clear that $f(z) = z^2+iz^{-1}+z^{-3}$ behaves similarly to $z^{-3}$ for $z$ near the pole at $z_0 = 0$.\nSince $|z-z_0|^{-n+k}$ is much smaller than $|z-z_0|^{-n}$ when $|z-z_0|$ is small, near $z_0$ the function behaves like $a_{-n}(z-z_0)^{-n}$.\nThis is why the order of a pole can be estimated by counting the number of times the colors circle a point in the clockwise direction.\n\n\\subsection*{Counting Zeros and Poles} % --------------------------------------\n\nThe \\emph{Fundamental Theorem of Algebra} states that a polynomial $f$ with highest degree $n$ has exactly $n$ zeros, counting multiplicity.\nFor example, $f(z) = z^2 + 1$ has two zeros, and $f(z) = (z-i)^3$ has three zeros, all at $z_0 = i$ (that is, $z_0=i$ is a zero with multiplicity $3$).\n\nThe number of poles of function can also be apparent if it can be written as a quotient of polynomials.\nFor example, $f(z) = z / (z+i)(z-i)^2$ has one zeros and three poles, counting multiplicity.\n\n\\begin{problem}\nPlot the following functions and count the number and order of their zeros and poles.\nAdjust the bounds of each plot until you have found all zeros and poles.\n\\begin{itemize}\n\\item $f(z) = -4z^5 + 2z^4 - 2z^3 - 4z^2 + 4z - 4$\n\\item $f(z) = z^7 + 6z^6 - 131z^5 - 419z^4 + 4906z^3 - 131z^2 - 420z + 4900$\n\\item $f(z) = \\frac{16z^4 + 32z^3 + 32z^2 + 16z + 4}{16z^4 - 16z^3 + 5z^2}$\n\\end{itemize}\n\\end{problem}\n\nIt is usually fairly easy to see how many zeros or poles a polynomial or quotient of polynomials has.\nHowever, it can be much more difficult to know how many zeros or poles a different function may or may not have without visualizing it.\n\n\\begin{problem}\n\\label{prob:findpz}\nPlot the following functions on the domain $\\{x+iy\\mid x,y\\in[-8,8]\\}$.\nExplain carefully in a Markdown cell what each graph reveals about the function and why the function behaves that way.\n\\begin{itemize}\n\\item $f(z) = e^z$\n\\item $f(z) = \\tan(z)$\n\\end{itemize}\n(Hint: use the polar coordinate representation to mathematically examine the magnitude and angle of each function.)\n\\end{problem}\n\n\\subsection*{Essential Poles} % -----------------------------------------------\n\nA complex-valued function $f$ has an \\emph{essential pole} at $z_0$ if its Laurent series in a punctured neighborhood of $z_0$ requires infinitely many terms with negative exponents.\nFor example,\n\\[\ne^{1/z} = \\sum_{k=0}^{\\infty}\\frac{1}{n! z^n} = 1+\\frac{1}{z}+\\frac{1}{2}\\frac{1}{z^2}+\\frac{1}{6}\\frac{1}{z^3}+\\cdots.\n\\]\nAn essential pole can be thought of as a pole of order $\\infty$.\nTherefore, in an angle plot the colors cycle infinitely many times around an essential pole.\n\n\\begin{figure}[H] % f(z) = e^(1/z)\n\\includegraphics[width=.7\\textwidth]{figures/poles_angle.png}\n\\caption{Angle plot of $f(z) = e^{1/z}$ on the domain $\\{x+iy \\mid x,y \\in [-1,1]\\}$.\nThe colors circle clockwise around the origin because it is a pole, not a zero.\nBecause the pole is essential, the colors repeat infinitely many times.}\n\\label{fig:complex-essential-pole}\n\\end{figure}\n\n\\begin{warn}\nOften, color plots like the ones presented in this lab can be deceptive because of a bad choice of domain.\nBe careful to validate your observations mathematically.\n\\end{warn}\n\n\\begin{problem}\nFor each of the following functions, plot the function on $\\{x+iy\\mid x,y\\in[-1,1]\\}$ and describe what this view of the plot seems to imply about the function.\nThen plot the function on a domain that allows you to see the true nature of the roots and poles and describe how it is different from what the original plot implied.\nUse Markdown cells to write your answers.\n\\begin{itemize}\n\\item $f(z) = 100z^2 + z$\n\\item $f(z) = \\sin\\left(\\frac{1}{100z}\\right)$.\n\\end{itemize}\n(Hint: zoom way in.)\n\\end{problem}\n\n\n\\begin{comment} % This part is confusing and not in the book.\n\\subsection*{Multi-Valued Functions} % ----------------------------------------\n\nEvery complex number has two complex square zeros, since if $w^2=z$, then also $(-w)^2=z$.\nIf $z$ is not zero, these zeros are distinct.\n\nOver the nonnegative real numbers, it is possible to define a continuous square root function.\nHowever, it is not possible to define a continuous square root function over any open set of the complex numbers that contains 0.\nThis is intuitive after graphing $\\sqrt{z}$ on the complex plane.\n\n\\begin{problem}\nPlot the following functions and explain why they look the way that they do.\n\\begin{itemize}\n\\item $f(z) = \\sqrt{z}$.\nUse \\li{np.sqrt()} to take the square root.\n\\item $f(z) = -\\sqrt{z}$.\n\\end{itemize}\n\\end{problem}\n\n% Just as raising $z$ to a positive integer compresses the $\\theta$-axis, making the color wheel repeat itself $n$ times around 0, raising $z$ to a fractional power \\emph{stretches} the $\\theta$-axis, so that only one $n$th of the color wheel appears around 0.\n% The colors at the ends of this $n$th-slice are not the same, but they appear next to each other in the plot of $z^{-n}$.\n% This discontinuity will appear in every neighborhood of the origin.\n%\n% If your domain does not contain the origin, it is possible to define a continuous root function by picking one of the zeros.\n\n\n\\section*{Multi-Valued Functions} % -------------------------------------------\n\nAnother important topic in Complex Analysis is the study of multiple valued functions.\nThese functions arise as we consider the inverses of functions that are not strictly one to one on the complex plane.\nA classic example is $\\sqrt{x}$, which may take two values for every nonzero point of the complex plane.\n\nIn the Real numbers we worked with functions like this by simply restricting their output on a certain domain.\nWe can do a similar thing in the Complex plane.\nLoosely speaking, such a restriction is called a branch.\nComputationally we restrict the output to a single portion of the actual possible values of the multifunction.\nInverse functions that have multiple values like this are called \\emph{multi-valued functions} or \\emph{multifunctions}.\nNumPy automatically restricts the output of multi-valued functions. So to get other cuts you have to modify the function to get the cut you want, like multiplying the output of the $\\sqrt{x}$ by $-1$.\nFigure \\ref{fig:sqrt} shows the two cuts surfaces for $\\sqrt{z}$ in the complex plane.\n\nThese are some very basic examples.\nAnother simple example is $\\ln\\left(z\\right)$, which has a single value for the real part and infinitely many possible values for its imaginary part.\nThis is because for any complex $z\\neq 0$, we have $e^z=e^{z+2n\\pi}$ where $n$ is any integer.\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem}\nWrite two functions, both accepting a natural number $n$.\nHave one function plot the Riemann surface for the real part $f(z)=\\sqrt[n]{z}$ and the other plot the imaginary part.\n\nHint: Convert $z$ in $f(z)=\\sqrt[n]{z}$ to polar form as $z=re^{\\theta + 2k\\pi}$\nIf you then plug this into $\\sqrt[n]{z}$ the function takes the form\n\\[f(z)=\\sqrt[n]{r} e^{i \\frac{\\theta + 2 \\pi k}{n}}\\]\nNotice that here $f(z)$ has distinct values for $k = 0, 1, \\dots, n-1$ (a total of $n$ different values). Each value of $k$ corresponds to a different branch, which you can plot as $n$ separate surfaces.\n\nIf you use just one surface to plot each branch you will get erroneous vertical lines from jump discontinuities. Split each branch into two surfaces to get rid of these lines. You can investigate where the discontinuities occur by first plotting it as just one surface. The discontinuities happen at the same place for all $n$;\n\\end{problem}\n\\end{comment}\n\n\n\\begin{comment} % Integration. This has been orphaned.\n\\section*{Contour Integrals in the Complex Plane}\n\nFrom multivariable calculus, you may recall that an integral may be taken along a path.\nThis is very similar to what can be done in the complex plane.\nConsider the function $f(z)$ on the complex plane.\nLet $z=x+iy$.\nLet $u$ and $v$ be the real and imaginary parts of $f$ respectively.\nWe integrate $f$ along some contour $C$ in the complex plane, beginning at $z=a$ and ending at $z=b$.\nThis integral may be written\n\\[\\int_c f(z)dz\\]\nParameterizing $z$, we have\n\\[\\int_a^b f\\left( c\\left(t\\right)\\right) c'\\left(t\\right) dt\\]\nExpanding into real and imaginary parts (where $c\\left(t\\right) = x\\left(t\\right) + i y\\left(t\\right)$), we have\n\\[\\int_a^b \\left(u \\left(c \\left(t\\right)\\right) x'\\left(t\\right)-v\\left(c \\left(t\\right)\\right) y'\\left(t\\right)\\right) dt + i \\int_a^b\\left(v \\left(c \\left(t\\right)\\right)x'\\left(t\\right)+u\\left(c \\left(t\\right)\\right) y'\\left(t\\right)\\right) dt\\]\nWe have now written this complex integral as the sum of two real valued integrals in $\\mathbb{R}$.\nNote that this implies that $\\int_C f(z) dz$ may depend on the contour we choose and not just on the endpoints $a$ and $b$.\n\n\\begin{problem}\nWrite a function which takes a complex function $f(z)$, a contour parameterization $c(t)$ of a contour $c$, and the integration bounds on $t$ and returns the integral of $f$ along the contour $c$.\nUse the numerical integration function \\li{sympy.mpmath.quad} and the numerical derivative function \\li{sympy.mpmath.diff} included in mpmath (which is, in turn, included as a submodule of sympy).\nThese functions already work for complex numbers.\nTo do something similar with the integration routines in SciPy, we would have to separate the function into real and imaginary parts, as is shown above.\n\nUsing the function you just defined, integrate the following functions along the following contours\n\\begin{itemize}\n\\item $\\bar{z}$ counterclockwise along the unit ball starting and ending at $1$\n\\item $\\bar{z}$ along a straight line from $0$ to $1+i$\n\\item $\\bar{z}$ along the real axis from $0$ to $1$, then along the line from $1$ to $1+i$\n\\item $\\bar{z}$ along the unit ball centered at $i$ from $0$ to $1+i$\n\\item $e^z$ counterclockwise along the unit ball starting and ending at $1$\n\\item $e^z$ along a straight line from $0$ to $1+i$\n\\item $e^z$ along the real axis from $0$ to $1$, then along the line from $1$ to $1+i$\n\\item $e^z$ along the unit ball centered at $i$ from $0$ to $1+i$\n\\end{itemize}\n\\end{problem}\n\nNotice that, for a holomorphic function on a simply connected domain, the integrals from one point to another are not path dependent for any contours that lie within the domain.\nAn immediate consequence of the theorem is that for a complex function $f$, holomorphic on a simply connected domain $D$, and a contour $C$ lying entirely within $D$ which begins and ends at some point $a\\in D$,\n\\[\\int_C f(z)dz=0\\]\n\nThe quadrature algorithms used in many of the integration algorithms work along a straight line between the integration bounds in the complex plane, so for holomorphic functions we should be able to use the integration function we wrote earlier.\nFor example, integrating $e^z$ from $-1-i$ to $1+i$ can be done numerically like this:\n\\begin{lstlisting}\nfrom sympy import mpmath as mp\nmp.quad(lambda z: mp.exp(z), (complex(-1, -1), complex(1, 1)))\n\\end{lstlisting}\n\n\\section*{The Cauchy Integral Formula}\n\nAnother major theorem in complex analysis is called Cauchy's Integral Formula (not to be confused with Cauchy's Integral Theorem).\nIt states that for a domain $D$ in the complex plane, containing some contour $C$ and the interior of $C$, for any $z_0$ in the interior of $C$,\n\\[f(z_0)=\\frac{1}{2\\pi i} \\int_C \\frac{f(z)}{z-z_0} dz\\]\n\nWith more work, this theorem can be used to show that any function $f$ holomorphic on some domain $D$ is also infinitely differentiable on that domain.\nIn fact, the $n$th derivative of $f$ is given by the formula\n\\[f^{(n)}(z_0) = \\frac{n!}{2\\pi i} \\int_C \\frac{f(z)}{(z-z_0)^{n+1}} dz\\]\nThis result is also important because it allows us to relate the value of $f$ on the inside of a contour to the value of $f$ on the contour itself.\nIn other words, the values of $f$ inside the contour depend only on the values of $f$ along the contour itself.\nA related theorem (the Morera theorem) states that if some function $f$ is continuous on a domain $D$ and for every contour beginning and ending at the same point, the formula $\\int_C f(z) dz = 0$ holds, then $f$ is holomorphic on $D$.\n\n\\begin{problem}\nUsing Cauchy's Integral Formula, write a python function which returns a callable function which evaluates a complex function $f$ along the interior of a contour $C$.\nIt should accept a callable function for the parameterization of $C$, a callable function for the values of $f$ along $C$, and the bounds on the parameter used.\nAssume in your function that $C$ begins and ends at the same point and that $f$ also begins and ends at the same value (so that $f$ is continuous along $C$)\nTry it out on simple functions like $e^x$ with complex values and compare what you get with what calling the functions normally gives you.\n\\end{problem}\n\nNotice that in Cauchy's Integral Formula, we are integrating along a contour that begins and ends at the same point.\nThe function is also holomorphic at every point except $z_0$. At $z_0$ the integrand is undefined and has a singularity.\nThis integral around a singularity has some useful properties.\nWe will discuss these properties later on.\n\n\\end{comment}\n\n\n\\begin{comment}\n\\section*{Appendix}\nIt is possible to visualize the argument and the modulus of the output of a complex function $f(z)$.\nOne way to do so is to assign the modulus to a \\emph{lightness} of color.\nFor example, suppose we have a complex number with argument 0, so it will map to red in the color plots described above.\nIf its modulus is very small, then we can map it to a blackish red, and if its modulus is large, we can map it to a whitish red.\nWith this extra rule, our complex plots will still be very much the same, except that zeros will look like black dots and poles will look like white dots (see Figure \\ref{fig:example} for an example).\n\nThe code below implements the map we just described.\nBe warned that this implementation does not scale well.\nFor example, if you try to plot a complex function whose outputs are all very small in modulus, the entire plot will appear black.\n\n\n\\begin{lstlisting}\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom colorsys import hls_to_rgb\n\ndef colorize(z):\n    '''\n    Map a complex number to a color (or hue) and lightness.\n\n    INPUT:\n    z - an array of complex numbers in rectangular coordinates\n\n    OUTPUT:\n    If z is an n x m array, return an n x m x 3 array whose third axis encodes\n    (hue, lightness, saturation) tuples for each entry in z. This new array can\n    be plotted by plt.imshow().\n    '''\n\n    zy=np.flipud(z)\n    r = np.abs(zy)\n    arg = np.angle(zy)\n\n    # Define hue (h), lightness (l), and saturation (s)\n    # Saturation is constant in our visualizations\n    h = (arg + np.pi)  / (2 * np.pi) + 0.5\n    l = 1.0 - 1.0/(1.0 + r**0.3)\n    s = 0.8\n\n    # Convert the HLS values to RGB values.\n    # This operation returns a tuple of shape (3,n,m).\n    c = np.vectorize(hls_to_rgb) (h,l,s)\n\n    # Convert c to an array and change the shape to (n,m,3)\n    c = np.array(c)\n    c = c.swapaxes(0,2)\n    c = c.swapaxes(0,1)\n    return c\n\\end{lstlisting}\n\nThe following code uses the \\li{colorize()} function to plot  $\\frac{z^2 - 1}{z}$. The output is Figure \\ref{fig:example}.\n\n\\begin{lstlisting}\n>>> f = lambda z :  (z**2-1)/z\n>>> x = np.linspace(-.5, 1.5, 401)\n>>> y = np.linspace(-1, 1, 401)\n>>> X,Y = np.meshgrid(x,y)\n>>> Z=f(X+Y*1j)\n>>> Zc=colorize(Z)\n>>> plt.imshow(Zc, extent=(-.5, 1.5, -1, 1))\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{figures/example.png}\n\\caption{Plot of the function $\\frac{z^2 - 1}{z}$ created with \\li{colorize()}.\nNotice that the zero at 1 is a black dot and the pole at 0 is a white dot.}\n\\label{fig:example}\n\\end{figure}\n\\end{comment}\n", "meta": {"hexsha": "c1bf7103eafc8620a4792128437e370691265846", "size": 29000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/ComplexFunctions/ComplexFunctions.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/ComplexFunctions/ComplexFunctions.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/ComplexFunctions/ComplexFunctions.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": 56.3106796117, "max_line_length": 520, "alphanum_fraction": 0.7041724138, "num_tokens": 8534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8918110360927155, "lm_q1q2_score": 0.6654149985125201}}
{"text": "\n\\subsection{Binary classification}\n\nClassification models are a type of regression model, where \\(y\\) is discrete rather than continuous.\n\nSo we want to find a mapping from a vector \\(X\\) to probabilities across discrete \\(y\\) values.\n\nA classifier takes \\(X\\) and returns a vector.\n\nFor a classifier we have \\(K\\) classes. \n\n\n\\subsection{Classification}\n\nConfusion matrix. true positve, false positive, false negative, true negative\n\nCan use this to get\n\nAccuracy: percentage correct\n\nPrecision: percentage of positive predictions which are correct\n\nRecall (sensitivity): percentage of poitive cases that were predicted as positive\n\nSpecificity: percentage of negative cases preicated as negative \n\n", "meta": {"hexsha": "7f80dbe44fc274548e5557f861046af507fa0df5", "size": 701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/parametric/02-01-classification.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-01-classification.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-01-classification.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.962962963, "max_line_length": 101, "alphanum_fraction": 0.7831669044, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6652529748659436}}
{"text": "\\section{Calculus}\n\n\\begin{definition}[Adiabatic]\n    adiabatic wall between two thermodynamic systems does not allow heat or\n    matter to pass across it. \n\n\\end{definition}\n\n\\begin{definition}[A priori estimate]\n    An estimate for a size of a solution or it's deriviates of a PDE.\\\n    The estimate is made before the solution is known to exists.\n\n\\end{definition}\n\n\\begin{definition}[Affine]\n    $ \n    f(x_{1}, x_{2}, \\dots, x_{n}) = \n    a_{1}x_{1}, a_{2}x_{2}, \\dots a_{n}x_{n}\n    $\n\\end{definition}\n\n\\begin{definition}[Analytic function]\n    A function given by~\\nameref{convergence}~\\nameref{powerseries}.\n    \n    Any polynomial, exponential and trigonometric function is analytic.\n    Functions that are not differentiable at given points are not analytic.\n\n\\end{definition}\n\n\\begin{definition}[arcsin]\n    \\begin{align*}\n        \\sin{y} &= x \\\\\n        \\arcsin{x} &= \\sin^{-1}{x} = y\n    \\end{align*}\n\n    Properties:\n    \\begin{itemize}\n        \\item $\\arcsin{x} = \\frac{\\pi}{2} - \\arccos{x} = 90º - \\arccos{x}$\n        \\item $\\cos{(\\arcsin{x})} = \\sin{(\\arccos{x})} = \\sqrt{1-x^{2}}$\n        \\item $ x = -1 \\rightarrow \\arcsin{x} = -1\\times\\frac{\\pi}{2}$\n        \\item $ x = 1 \\rightarrow \\arcsin{x} = \\frac{\\pi}{2}$\n        \\item $ x = 0 \\rightarrow \\arcsin{x} = 0$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[arccos]\\label{arccos}\n    Properties:\n    \\begin{itemize}\n        \\item $ x = -1 \\rightarrow \\arccos{x} = \\pi$\n        \\item $ x = 1 \\rightarrow \\arccos{x} = 0$\n        \\item $ x = 0 \\rightarrow \\arccos{x} = \\frac{\\pi}{2}$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Arc length]\n    Length of a curve when straightened out.\n\\end{definition}\n\\begin{definition}[arccos]\n    While cosine shows the relation between lengths in a triangle, \n    arccos gives the angle.\n\\end{definition}\n\n\\begin{definition}[Arithmetic-geometric mean inequality]\\label{arigeo}\n    $\n    \\newline {(\\prod\\limits_{i = 1}^{k} a_{i})}^{1/k}\n    \\leq {1 \\over k} \\sum\\limits_{i = 1}^{k} a_{i}\n    $\n\\end{definition}\n\n\\begin{definition}[Azimuth]\n     is an angular measurement in a spherical coordinate system. The vector\n     from an observer (origin) to a point of interest is projected\n     perpendicularly onto a reference plane; the angle between the projected\n     vector and a reference vector on the reference plane is called the\n     azimuth.\n\n     \\includegraphics[scale=0.3]{azimuth.png}\n\n\\end{definition}\n\n\\begin{definition}[Bijection]\n    \\begin{align}\n        S,R \\text{\\ are sets} \\\\\n        \\forall{i \\in S}, \\exists!{f(i) \\in R} \\wedge \\\\\n        \\forall{i \\in R}, \\exists!{f(i) \\in S} \\\\\n    \\end{align}\n\\end{definition}\n\n\\begin{definition}[Binomial]\\label{binomial}\n    A polynomial which is the sum of two terms.\n\\end{definition}\n\n\\begin{definition}[Boundary value problem]\n    A differential equation with additional restrains. A solution to a boundary\n    value problem is a solution to the differential equation which also\n    satisfies the boundary conditions.\n    \n\\end{definition}\n\n\n\\begin{definition}[Cauchy sequence]\n    a sequence whose elements become arbitrarily close to each other as the\n    sequence progresses.\n    Think of \\textit{two} curves that approximate each other.\n\n\\end{definition}\n\n\\begin{definition}[Cardinal number, ]\n    The size of a set.\n\\end{definition}\n\n\\begin{definition}[Closure]\n    The closure of a set is the points in the set including the limit points.\n\\end{definition}\n\n\\begin{definition}[Convergence]\\label{convergence}\n    A series is convergent is the sum of it's elements approaches a given \n    number.\n\\end{definition}\n\n\\begin{definition}[Convolution]\n    Dictionary: a coil or twist, especially one of many.\\newline\n    Informal: an expression of how a shape from one function is modified by \n        the other.\n\n    Can also be used to smoothen a discontinous a function (making it continous \n    on the given range). We need to normalize our $g(x - \\tau)$ so that we do\n    not continously increase the $f(x)$\n\n    A convolution in time domain is equal to multiplication in frequency domain.\n\n    Convolution is a common way to combine wavelet to recreate signals.\n\\end{definition}\n\n\\begin{definition}[Continuous]\nIn mathematics, a continuous function is a function for which\n``small'' changes in the input result in ``small'' changes in the output.\n\nAs an example, consider the function $h(t)$, which describes the height of a\ngrowing flower at time t. This function is continuous. By contrast, if $M(t)$\ndenotes the amount of money in a bank account at time t, then the function\njumps whenever money is deposited or withdrawn, so the function $M(t)$ is\ndiscontinuous.\n\n\\end{definition}\n\n\\begin{definition}[Continuous variables]\n    There are three types of continuous variables:\n    \\begin{center}\n    \\begin{description}\n        \\item[Nominal] Categorized within groups: box 1, 2, 3 or 4.\n        \\item[Dichotomous] Boolean, yes or no.\n        \\item[Ordinal] A nominal variable, just that different groups give\n            different values. E.g.\\ to like something on a scale of 1 to 10\n            gives you a ordinal range\n    \\end{description}\n\\end{center}\n\\end{definition}\n\n\\begin{definition}[Conjugate]\n    is a~\\nameref{binomial} formed by negating the second term of\n    a~\\nameref{binomial}. The conjugate of $x + y$ is $x − y$.\n\n    A functions' conjugate is often denoted $\\overline{f(x)}$.\n\n\\end{definition}\n\n\\begin{definition}[Concave]\n    Let $f$ be a function defined on the interval $[x_{1}, x_{2}]$.\n    This function is concave according to the definition if, for every pair of\n    numbers a and b with $x_{1} \\leq a \\leq x_{2}$ and $x_{1} \\leq b \\leq\n    x_{2}$, the line segment from $(a,  f (a))$ to $(b,  f (b))$\n    lies on or below the function.\n\n    \\begin{itemize}\n        \\item The sine function is concave on the interval $[0, \\pi]$\n        \\item Concave if every line segment joining two point is never above\n              the graph \n        \\item Concave functions has $f\\prime\\prime(x) \\leq 0$ in a given\n              interval \n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Congruence]\n    Similar shape and growth, just different scalar / rotation.\n\\end{definition}\n\n\n\\begin{definition}[Damping]\n    is an influence within or upon an oscillatory system that has the effect of\n    reducing, restricting or preventing its oscillations. \n    Underdamped systems will start bouncy and then stop.\n\n\\end{definition}\n\n\\begin{definition}[Differential operator]\n    An operator to do differentiation. This is mainly to abstract\n    differenentiation.\n\n\\end{definition}\n\n\\begin{definition}[Discrete Fourier Transform]\\label{dft}\n    converts a finite list of equally spaced samples of a function into the\n    list of coefficients of a finite combination of complex sinusoids, ordered\n    by their frequencies, that has those same sample values.\n\n\\end{definition}\n\n\\begin{definition}[Discrete Laplace transform]\n    An integral transfrom, which in 2d uses the kernel\n    % \\begin{bmatrix}   \n    %     0 & 1 & 0 \\\\  \n    %     1 & -4 & 1 \\\\ \n    %     0 & 1 & 0     \n    % \\end{bmatrix}     \n\\end{definition}\n\n\\begin{definition}[Discrete Sine Transform]\n    Similar to~\\nameref{dft}, but uses only a real matrix.\n\n\\end{definition}\n\n\\begin{definition}[Discretization]\n    concerns the process of transferring\n    continuous models and equations into discrete counterparts. \n    AKA\\ smoothening curves to avoid jumps.\n\n\\end{definition}\n\n\\begin{definition}[Displacement]\n    The shortest distance from source $s$ to $t$ (like air-distance).\n\n\\end{definition}\n\n\\begin{definition}[Divergence]\\label{divergence}\n    measures the magnitude of a~\\nameref{vectorfield}'s source or sink at a\n    given point, in terms of a signed scalar.\n\n    E.g.\\ air can be thought of to have a point $s \\text{ and } t$, where they\n    push out hot and cool air, respectively. From these points, you can create\n    a~\\nameref{vectorfield} that shows how air spreads from $s \\text{ and }\n    t$. The divergence measures the collected value from each of \n    these~\\nameref{vectorfield}s.\n\n    The operator for divergence is \\verb|{div}|, represented by nabla.\n\n    Given vector field $F = Ui, Vj, Wk$:\n    \\begin{align}\n            div \\textbf{F} = \\nabla \\cdot F = \n            \\frac{\\partial{U}}{\\partial{x}}+\n            \\frac{\\partial{V}}{\\partial{y}} +\n            \\frac{\\partial{W}}{\\partial{z}}\n    \\end{align}\n\n\\end{definition}\n\n\\begin{definition}[Elementary function]\n    In mathematics, an elementary function is a function of one variable built\n    from a finite number of exponentials, logarithms, constants, and $nth$ roots\n    through composition and combinations using the four elementary operations\n    $(+ – × ÷)$.\n\n\\end{definition}\n\n\\begin{definition}[Even function]\\label{evenfunc}\n    Kind of like a mirror (90 degrees) around an axis;\n    \\begin{align}\n        f(x) &= f(-x) \\\\\n    \\end{align}\n    See also~\\nameref{oddfunc}\n\\end{definition}\n\n\n\\begin{definition}[Expansion function]\n    A function, with a series, to express a function. The series will in\n    most cases be an approximation to the original function.\n    Signal functions are often modeled using expansion functions.\n\\end{definition}\n\n\\begin{definition}[Eulers formula]\n    $e^{ix} = \\cos{x} + i\\sin{x}$\n\\end{definition}\n\n\\begin{definition}[Explicit methods]\\label{explicitmethod}\n    In numerical analysis, an explicit method calculates the state of the system\n    using only earlier history. See also~\\nameref{implicitmethod}.\n\\end{definition}\n\n\n\\begin{definition}[Extreme point]\n    A point furthest away from something.\n\\end{definition}\n\n\\begin{definition}[Field]\n    A physcial quantity that has a value for each point in space and time.\n\\end{definition}\n\n\\begin{definition}[Finite difference]\n    The difference in a function for $f(x + a) - f(x + b)$.\n\n    There are three types:\n    \\begin{description}\n        \\item[Forward] is of the form $\\bigtriangleup{f}(x) = f(x + h) - f(x)$\n        \\item[Backward] is of the form $\\nabla{f}(x) = f(x) - f(x - h)$\n        \\item[Centered] is of the form $\\delta{f}(x) = f(x + \\frac{1}{2}h) - f(x - \\frac{1}{2}h)$\n    \\end{description}\n\\end{definition}\n\n\\begin{definition}[Finite element method]\n    (FEM) is a numerical technique for finding approximate solutions to\n    boundary value problems for differential equations. It uses variational\n    methods (the calculus of variations) to minimize an error function and\n    produce a stable solution.  Analogous to the idea that connecting many tiny\n    straight lines can approximate a larger circle, FEM encompasses all the\n    methods for connecting many simple element equations over many small\n    subdomains, named finite elements, to approximate a more complex equation\n    over a larger domain.\n\n\\end{definition}\n\n\\begin{definition}[Filter bank]\n    To take a signal and expose it to a series of filters that separate the\n    input signal into different channel. One example is sound equalizers:\n    you can adjust different parts of the signal.\n\\end{definition}\n\n\\begin{definition}[Fourier transform]\n    Map one function onto another function expressed in terms of a \n    series of sine and cosine terms, that when joined together form\n    a translated domain.\n\n    Fourier transforms have the property that they can cover all the frequencies\n    from the original input, but the mapped frequency loses the time domain:\n    one can not determine at what time what frequency ``stuff''  was sent.\n\n\\end{definition}\n\n\\begin{definition}[Fourier Analysis]\n    the study of the way general functions may be represented or approximated\n    by sums of simpler trigonometric functions\n\n\\end{definition}\n\n\\begin{definition}[Flow]\n    Motion of particles in a given set.\n\\end{definition}\n\n\\begin{definition}[Galerkin methods]\n    Methods to convert continous operator problems to discrete ones.\n\\end{definition}\n\n\\begin{definition}[Generalized function]\n   A distribution without steps, i.e.\\ it is continious. \n\\end{definition}\n\n\\begin{definition}[Group]\n    A set and an operator, such that if you take two elements from the set,\n    apply the operator to them, then you will ``receive'' an element that\n    could also be a part of the set (closure). Also it must satisfy for\n    $\\forall{a,b} \\in S \\rightarrow, (a \\cdot b) \\cdot c = a \\cdot (b \\cdot c)$ (associativity),\n    \\dots also indentity and inverses.\n    Example: integers and ``+''.\n\n    Groups have symmetry.\n\\end{definition}\n\n\\begin{definition}[Harmonic numbers]\n    $H_{n} = 1 + \\frac{1}{2} + \\frac{1}{3} + \\cdots + {1}{n} =\n    {\\sum\\limits_{k = 1}^{k}} \\frac{1}{k} \\simeq \\ln n$\n\\end{definition}\n\n\\begin{definition}[Heavyside Step Function]\n    $$\n    H(x) = \\left\\{\n            \\begin{array}{l l}\n                0 & \\text{for} x < 0 \\\\\n                \\frac{1}{2} & x = 0 \\\\\n                1 & \\text{for} x > 0 \\\\\n            \\end{array}\n        \\right.\n    $$\n    (it looks just like you think\\dots)\n\\end{definition}\n\n\\begin{definition}[Heisenberg's uncertanty principle]\n    kjkj\n\\end{definition}\n\n\\begin{definition}[Homogenous]\n    If a function $f$ is multiplied by a sclar $k$, then the result\n    is a number multiplied by the scalar raised to some power $a$.\n\\end{definition}\n\n\\begin{definition}[Hyperbolic]\n    Two curves that kind of face each other like bananas.\n\\end{definition}\n\n\\begin{definition}[Identity function]\n    $\\forall{x}, f (x) = x$\n\\end{definition}\n\n\\begin{definition}[Implicit method]\\label{implicitmethod}\n    In numerical analysis, an implicit method calculates the state of the system\n    using both the current state and future ones. E.g.\\ Gauss-seidel method\n    See also~\\nameref{explicitmethod}.\n\\end{definition}\n\n\\begin{definition}[Idempotence]\n    An operation that can be applied multiple times without changing the\n    the result. E.g.\\ $f (f (x)) = f (x) $\n\\end{definition}\n\n\\begin{definition}[Idenpendent variable]\n    A variable that may be given without considering the value of other\n    variables. E.g.\\ for $y = 4x + 2$, x is indepdent (can be chosen freely)\n    whereas $y$ is not: it depends on the value of $x$.\n\\end{definition}\n\n\\begin{definition}[Invariant]\n    A sentence that is believed to be true throughout some timespan.\n\\end{definition}\n\n\\begin{definition}[Integral]\n    The ``reverse'' to a derivate. \n\n    \\begin{align}\n        \\int_{a}^{b}x^{n} dx = \\frac{x^{n+1}}{n+1} + C \\\\\n    \\end{align}\n\n    A function is said to be \\textit{locally integrable} if it's integral is \n    finite in a given domain.\n\n    \\textbf{Integration by parts:} $\\int{u \\times v dx} = u\\int{v dx} - \\int{u\\prime{(v dx)}}dx $\n\n    Some identities:\n    \\begin{longtable}{|l|l|}\n        $\\int_{a}^{b}\\cos{x} $ & $\\sin{x} + C $ \\\\\n    $\\int_{a}^{b}\\sin{x}$ & $-1 \\times \\cos{x} + C $\\\\\n    $e^{x}$ & $e^{x} + C $\n    \\end{longtable}\n\n\\end{definition}\n\n\\begin{definition}[Integral transform]\\label{inttrans}\n    Input a function, and output another (using integrals).\n    To do the transformation, one typically usues a \\textit{kernel function} (e.g.\\ \n    using a stencil in a grid).\n\n    Usually, this is done to find a domain or function that is easier to compute\n    on. \n\n    After completing the computations, one performs an inverse integral transform\n    to translate back to the original domain.\n\\end{definition}\n\n\\begin{definition}[Interpolating polynomial]\n    Given a set of points, define a function $f$ that intersects these points.\n\\end{definition}\n\n\\begin{definition}[Kronecker delta]\n    A function for two variables, that returns 1 if the variables are equal,\n    and zero otherwise.\n    $$\n    \\delta_{i,j} = \\begin{array}{ll}\n        0 & if i \\neq j \\\\\n        1 & if i = j\n        \\end{array}\n    $$\n\\end{definition}\n\n\\begin{definition}[Law of cosines]\n    \\begin{align*}\n        v \\cdot u = |v||u|\\cos{\\theta} \\\\\n    \\end{align*}\n    Note that if $v, u$ are unit vectors, their lengths are both 1.\n    We can then rewrite the expression as\n    \\begin{align*}\n        v \\cdot u &= \\cos{\\theta} \\\\\n        \\arccos{(v \\cdot u)} &= \\theta\n    \\end{align*}\n\\end{definition}\n\n\\begin{definition}[Laplace operator]\n    Transform a function of $f$ of $t$ to a function $f$ of $s$\n\n    A differential operator given by the~\\nameref{divergence} of a gradient \n    function in euclidian space.\n\\end{definition}\n\n\\begin{definition}[Laplacian Matrix]\n    sometimes called admittance matrix, Kirchhoff matrix or discrete Laplacian,\n    is a matrix representation of a graph.\n\n\\end{definition}\n\n\\begin{definition}[Lattice]\n    In mathematics, especially in geometry and group theory, a lattice in\n    $\\mathbf{R}^n$ is a discrete subgroup of $\\mathbf{R}^n$ which spans the real\n    vector space $\\mathbf{R}^n$. Every lattice in $\\mathbf{R}^n$ can be generated\n    from a basis for the vector space by forming all linear combinations with\n    integer coefficients. \n\n\\end{definition}\n\n\\begin{definition}[Line integral]\n    An integral where the function to be integrated is along a curve.\n    The function is usually a~\\nameref{vectorfield} or~\\nameref{scalarfield}.\n\n\\end{definition}\n\n\\begin{definition}[Locus]\n    a set of points whose location satisfies or is determined by one or more\n    specified conditions\n\n\\end{definition}\n\n\\begin{definition}[Merit function]\n    A value that says something about how good we have acheived a goal.\n\\end{definition}\n\n\\begin{definition}[Moment]\n    TBD.\\\n\\end{definition}\n\n\\begin{definition}[Numerical analysis]\n    The study of algorithms that use numerical approximation (as opposed to\n    general symbolic manipulations) for the problems of mathematical analysis.\n\n    Given a space $V$, find a finite subspace of $V$, such that you can\n    calculate on it\\dots\n\n    \\includegraphics[scale=1.0]{fem.png}\n    A function in  with zero values at the endpoints (blue), and a piecewise\n    linear approximation (red)\n\n\\end{definition}\n\n\\begin{definition}[Odd function]\\label{oddfunc}\nA function with the same values when you rotate 180 degrees around\\dotso{}\n    \\begin{align}\n        - f(x) &= f(-x) \\\\\n        f(x) + f(-x) &= 0\n    \\end{align}\n    See also~\\nameref{evenfunc}\n\\end{definition}\n\n\\begin{definition}[Pathological]\n    Something that is counter-intuitive. The opposite is \\textbf{well-behaved}.\n\n\\end{definition}\n\n\\begin{definition}[Parabola]\n    A U-shaped, 2d, symmetrical curve.\n\\end{definition}\n\n\\begin{definition}[Parameterization]\n    Represent a curve as a function.\n    \\begin{align}\n        x = \\cos{t} \\\\\n        y = \\sin{t}\n    \\end{align}\n    is the parametric representation of a unit circle.\n\\end{definition}\n\n\\begin{definition}[Partial derivative]\n    Given a function $f$ with multiple parameters, a partial derivative is a\n    derivative with respect to one of those variables.\n\n    Partial derivatives are often denoted by $\\partial$.\n\n    To use partial derivation, you often assume that the other variables are \n    constants. Otherwise, there is an infinite number of tangent lines at\n    any point, so you will have to have some range on the tangents.\n\n\\end{definition}\n\n\\begin{definition}[Partial differential equation]\n    A set of variables, and equations that show how they are all linked \n    together.\n\\end{definition}\n\n\\begin{definition}[Pertubation theory]\\label{pertubation}\n    The ``art'' of finding an approximate solution to a problem by starting\n    with an exact solution to an easier problem.\n\\end{definition}\n\n\n\\begin{definition}[Power series]\\label{powerseries}\n    \\begin{align}\n        f(x) = \\sum\\limits_{n=0}^{\\infty}{a_{n}{(x-c)}^{n}}\n    \\end{align}\n\\end{definition}\n\n\\begin{definition}[Rectangle function]\n    $$\n    \\Pi(x) = \\left\\{\n            \\begin{array}{l l}\n                0 & \\text{for} x > \\frac{1}{2} \\\\\n                \\frac{1}{2} & \\text{for} x = \\frac{1}{2} \\\\\n                1 & \\text{for} x < \\frac{1}{2} \\\\\n            \\end{array}\n        \\right.\n    $$\n\\end{definition}\n\n\\begin{definition}[Reference value]\n    The optimal/starting value. Note that when calculating differences,\n    a reference value implies that order matters, i.e.\\ $ x - y \\neq y - x$.\n\n\\end{definition}\n\n\\begin{definition}[Residual]\n    In numerical analysis, this is the error from a result.\n    E.g.\\ in integration we have something-something + $C$, where C is the \n    the residual.\n\n    It can (perhaps betterly) be stated that residuals is the error that occurs\n    when approximating a function.\n\n\\end{definition}\n\n\\begin{definition}[Riemanns sum]\\label{riemannsum}\n    Sum from an integral. Divide the area under/over a curve into rectangles\n    or trapezoids, and sum together their area. The smaller the shapes, the\n    better.\n\n    It is important to note that~\\nameref{riemannsum} is an approximation - \n    one can not perfectly reconstruct the area under a curve.\n\\end{definition}\n\n\\begin{definition}[Risk function]\n    Gives the expected value from a lossy function (compare two results, diff).\n\\end{definition}\n\n\\begin{definition}[Sine wave]\nor sinusoid is a mathematical curve that describes a smooth repetitive\noscillation.\n\nIts most basic form as a function of time $(t)$ is:\n\n$y(t) = A\\sin(2 \\pi f t + \\varphi) = A\\sin(\\omega t + \\varphi)$\nwhere:\n\\begin{description}\n    \\item[A], the amplitude, is the peak deviation of the function from zero.\n    \\item[f], the ordinary frequency, is the number of oscillations (cycles)\n        that occur each second of time.\n    \\item[ω] = 2πf, the angular frequency, is the rate of change of the\n    function argument in units of radians per second \n    \\item[$\\varphi$], the phase, specifies (in radians) where in its cycle the\n        oscillation is at t = 0. I.e.\\ the ``horizontal shift'' from a regular\n        sine wave(????).\n    If you e.g.\\ represent two functions, $f(x) = \\sin{x}$ and $g(x) = \\sin{x} + 3$\n    , the difference, i.e.\\ phase shift, is 3. Note that these two functions\n    have the same amplitude and frequency.\n\\end{description}\n\n\\end{definition}\n\n\\begin{definition}[Standard form]\n    To write a number as a power of 10.\n\\end{definition}\n\n\\begin{definition}[Stiffness matrix]\n    A system of linear equations that must be solved to get an approximate\n    solution to a differential equation.\n\n    To do this, consider Poission problem:\n\\end{definition}\n\n\\begin{definition}[Taylor series]\n    A representation of a function as an infinite sum of terms that are \n    calculated from the derivatives at a point in the function.\n    The formula is:\n    \\begin{align}\n        \\sum\\limits_{n=0}^{\\infty}{\\frac{f^{(n)}(a)}{n!}{(x-a)}^{n}}\n    \\end{align}\n\\end{definition}\n\n\\begin{definition}[Shift invariant system]\n    A discrete form of~\\nameref{TIS} - the timesteps are discretized to follow\n    a lattice spacing.\n\\end{definition}\n\n\\begin{definition}[Stationary point]\n    A place in which the derivative is zero.\n\\end{definition}\n\n\\begin{definition}[Symmetric function]\n    A function where the ordering of the parameters does not matter.\n    \\begin{align}\n        f(x,y) &= x + y \\\\\n        f(y,x) &\\equiv f(x,y)\n    \\end{align}\n\\end{definition}\n\n\\begin{definition}[Time invariant system]\\label{TIS}\n    A function with an output that does not depend on the output:\n    \\begin{align}\n        x(t) &= y(t) \\\\\n        x(t + \\delta) &= y(t + \\delta)\n    \\end{align}\n\n    One example is the derivative function of polynomials (and others?) -\n    no matter what timestep you choose - the value if the same.\n\n    The ``antonym'' would be a time variant system.\n\\end{definition}\n\n\\begin{definition}[Translation invariant system]\n    A system such that after a translation from A to T, any operator\n    applied to A yields the same results in T.\n\\end{definition}\n\n\\begin{definition}[Unity]\n    The number one. ``Unit functions'', ``unit circles'' all have the number 1.\n\\end{definition}\n\n\\begin{definition}[Univariate]\n    An equation with only one variable.\n\\end{definition}\n\n\\begin{definition}[Vector Field]\\label{vectorfield}\n    An assigment of direction for a given set of points in an euclidian space.\n    E.g.\\ select every (10n, 10n) pixels in an image and get their derivative.\n\\end{definition}\n\n\\begin{definition}[Weak formulation]\n    Transfer a concept from linear algebra to solve equations in other field.\n\n    Equations that have weak formulations are not required to be correct for\n    all input (:: weak solutions, PDE might not have derivates but you make pretend)\n\n\\end{definition}\n\n\\begin{definition}[Window function]\n    A function that is zero outside of a given domain.\n\\end{definition}\n", "meta": {"hexsha": "1abe378418196d5ca2069cec741c43458f13661a", "size": 24459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/calculus.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/calculus.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/calculus.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.1422764228, "max_line_length": 97, "alphanum_fraction": 0.6869863854, "num_tokens": 6586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.6652405518403429}}
{"text": "\\section{Approximation results for various activation functions}\n\\input{6DL/BarronSpace}\n%\\input{6DL/FourierRepresentation}\n%\\input{6DL/DoubleFourier}\n%\\input{6DL/DoubleFourier2}\n\\input{6DL/BsplineApprox}\n%\\input{6DL/ReLUFourierSimple}\n%\\input{6DL/ReLUFourier}\n\\input{6DL/PeriodicActivation}\n\\endinput\n Since $f(x)$ is real-valued, it implies that, for $x, x_B\\in B$\n \\begin{equation}\n \\label{key}\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\\beta\n \t(\\omega)}|\\hat{f}(\\omega)|d\\omega \\\\\n &=\\int_{\\mathbb{R}^d}(\\cos(\\omega\\cdot\n x+\\beta(\\omega))-\\cos(\\omega\\cdot x_B+\\beta(\\omega)))|\\hat{f}(\\omega)|d\\omega \\\\\n &=\\int_{\\mathbb{R}^d}(\\cos(\\omega\\cdot(x-x_B)+\\beta_B(\\omega))-\\cos(\\beta_B(\\omega)))|\\hat{f}(\\omega)|d\\omega\n \\end{aligned}\n \\end{equation}\n where\n $$\n \\beta_B(\\omega)=\\omega\\cdot x_B+\\beta(\\omega),\\quad|\\omega|_B:=\\sup\\limits_{x\\in B}|\\omega\\cdot(x-x_B)|\n $$\n \\begin{lemma}\n \t\\begin{equation}\n \t\\label{eq:2}\n \tf(x)-f(x_B)=\\int_{\\mathbb{R}^d}k(x,\\omega)d\\omega\n \t\\end{equation}\n \t\\begin{equation}\n \t\\label{eq:1}\n \tk(x, \\omega)=\\cos(\\omega\\cdot(x-x_B)+\\beta_B(\\omega))-\\cos(\\beta_B(\\omega)))|\\hat{f}(\\omega)|  \n \t\\end{equation}\n \tsatisfying\n \t$$\n \t|D^\\alpha k(x, \\omega)|\\lesssim|\\omega|^{|\\alpha|}|\\hat{f}(\\omega)|  \n \t$$\n \\end{lemma}\n \n For simplicity, we take $x_B=0$, we then have\n \\begin{equation}\n \\label{eq:2}\n f(x)-f(0)=\\int_{\\mathbb{R}^d}k(x,\\omega)d\\omega\n \\end{equation}\n \\begin{equation}\n \\label{eq:1}\n k(x, \\omega)=(\\cos(\\omega\\cdot x+\\beta(\\omega))-\\cos(\\beta(\\omega)))|\\hat{f}(\\omega)|  \n \\end{equation}\n\n\n\\endinput\n\nUsing Lemma~\\ref{lem:sample}, we only need to find a function\n$\\rho(\\theta)$ so the following will give a good bound:\n\\begin{equation}\n\\label{f-sigma}\n\\int_{\\mathbb R^{d+1}} \n\\int_{\\Omega}|\\sigma(a^{-1}\\omega\\cdot  x+b)|^2dx \\frac{|\\hat{f}(\\omega)|^2}{\\rho(\\theta)}d\\theta\n\\end{equation}\n\n\nWe note that\n\\begin{equation}\n\\label{eq:4}\nD^\\alpha  k(x,\\theta)= \n\\frac{(a^{-1}\\omega)^\\alpha}{2\\pi\\hat{\\sigma}(a)}\n\\sigma^{(|\\alpha|)}\\left(a^{-1}\\omega\\cdot\nx+b\\right) |\\hat{f}(\\omega)|\\chi(\\omega, b)\n\\end{equation}\nThus\n$$\n|D^\\alpha  k(x,\\theta)|\\le C_a h(\\omega, b)(1+|\\omega|)^m |\\hat{f}(\\omega)|\n$$\nwhere \n$$\n|\\sigma^{(|\\alpha|)}(a^{-1}\\omega\\cdot x+b)|\\le h(\\omega, b)\n$$\n", "meta": {"hexsha": "af305366c884c54655caf9a72ab24acca37899cb", "size": 2381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Representations.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/Representations.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/Representations.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": 28.0117647059, "max_line_length": 110, "alphanum_fraction": 0.6299874003, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6652405506586706}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.\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}\n\\usepackage{epstopdf}\n\\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}\n\n\\usepackage{amsthm}\n\\newtheorem{theorem}{Theorem}\n\n\\title{Rotational Symmetry}\n\\author{Arthur Ryman}\n\\date{\\today}                                           % Activate to display a given date or no date\n\n\\begin{document}\n\\maketitle\n\\section{Introduction}\n\nI recently needed to generate a random sample from the uniform distribution on the sphere $S^n$ where $n$ was very large.\nMy strategy was to generate a rotationally symmetric sample of non-zero vectors $v$ in some region of $\\mathbb{R}^{n+1}$\nand then normalize those to get unit vectors $u = v/\\|v\\|$ on $S^n$.\nI first attempted to generate a random sample from the uniform distribution on the cube $[-1,1]^n$ and then take the subset of those\nvectors $v$ such that $0 < \\|v\\| \\leq 1$.\nHowever, it turns out that the volume enclosed by $S^n$ becomes a very small fraction of the volume of $[-1,1]^n$ as $n$ gets large.\nThe probability that $\\|v\\| \\leq 1$ goes to zero, so this approach fails.\n\nI then remembered the well-known fact that the distribution of $n$ independent and identically  distributed (IID) standard normal variates is rotationally symmetric.\nThis symmetry seems miraculous and in fact only occurs for the normal distribution.\nThis article gives a proof of that fact.\n\n\\section{Rotational Symmetry of $2$ IID Variates}\n\nLet the usual polar coordinate system on the plane be:\n$$\n\\begin{aligned}\nx &= r \\cos \\theta \\\\\ny &= r \\sin \\theta\n\\end{aligned}\n$$\n\nNote that:\n$$\n\\begin{aligned}\n\\frac{\\partial}{\\partial\\theta}\t&= \\frac{\\partial x}{\\partial\\theta} \\frac{\\partial}{\\partial x} + \\frac{\\partial y}{\\partial\\theta} \\frac{\\partial}{\\partial y} \\\\\n\t\t\t\t\t\t&= -r \\sin\\theta \\frac{\\partial}{\\partial x} + r \\cos\\theta \\frac{\\partial}{\\partial y} \\\\\n\t\t\t\t\t\t&= -y\\frac{\\partial}{\\partial x} + x\\frac{\\partial}{\\partial y} \n\\end{aligned}\n$$\n\nA function $F$ on the plane is rotationally symmetric when it is independent of $\\theta$, i.e.:\n$$\n\\frac{\\partial F}{\\partial \\theta} = 0\n$$\nor, in terms of $x$ and $y$:\n$$\n-y\\frac{\\partial F}{\\partial x} + x\\frac{\\partial F}{\\partial y} = 0\n$$\nTherefore, a rotationally symmetric function must satisfy the following linear partial differential equation:\n$$\nx\\frac{\\partial F}{\\partial y} = y\\frac{\\partial F}{\\partial x}\n$$\n\nThe probability density function $f$ of a normal distribution with mean zero and variance $\\sigma^2$ is\n$$\nf(x) = Ce^{-\\frac{x^2}{2\\sigma^2}}\n$$\nwhere the normalization factor is $C=1/\\sqrt{2\\pi}$.\n\n\\begin{theorem}\nThe joint distribution of two IID random variates is rotationally symmetric if and only the random variates are normally distributed with mean zero.\n\\end{theorem}\n\n\\begin{proof}\n\nFirst prove that the distribution of two IID normal variates with mean zero is rotationally symmetric.\nThe probability density function $F$ of the joint distribution is:\n$$\n\\begin{aligned}\nF(x,y)\t&= f(x)f(y) \\\\\n\t\t&= Ce^{-\\frac{x^2}{2\\sigma^2}}Ce^{-\\frac{y^2}{2\\sigma^2}} \\\\\n\t\t&= C^2e^{-\\frac{x^2}{2\\sigma^2}-\\frac{y^2}{2\\sigma^2}} \\\\\n\t\t&= C^2 e^{-\\frac{x^2+y^2}{2\\sigma^2}} \\\\\n\t\t&= C^2 e^{-\\frac{r^2}{2\\sigma^2}}\n\\end{aligned}\n$$\n\nwhich does not depend on $\\theta$.\nTherefore the joint distribution is rotationally symmetric.\n\nNow prove that if the joint distribution of two IID variates is rotationally symmetric then the variates are normally distributed with mean zero.\nLet $g$ be the probability density function of any random variate such that the joint distribution\n$$G(x,y) = g(x)g(y)$$ \nis rotationally symmetric.\nThe partial derivatives of $G$ are:\n$$\n\\begin{aligned}\n\\frac{\\partial G}{\\partial x} &= g'(x)g(y) \\\\\n\\frac{\\partial G}{\\partial y} &= g(x)g'(y)\n\\end{aligned}\n$$\nThe condition for rotational symmetry is:\n$$\nx\\frac{\\partial G}{\\partial y} = y\\frac{\\partial G}{\\partial x}\n$$\nSubstituting in the expressions for the partial derivatives of $G$ we have:\n$$\nx g(x)g'(y) = y g'(x)g(y)\n$$\nDividing both sides by $x y g(x) g(y)$ we have:\n$$\n\\frac{g'(x)}{x g(x)} = \\frac{g'(y)}{y g(y)}\n$$\nThe LHS depends only on $x$ and the RHS depends only on $y$.\nBut $x$ and $y$ can vary independently.\nTherefore each side of the equation must be equal to some constant, say $\\alpha$:\n$$\n\\frac{g'(x)}{x g(x)} = \\alpha\n$$\nUsing the identity $(\\ln g)'(x) = g'(x)/g(x)$ we can rewrite the preceeding equation as:\n$$\n(\\ln g)'(x) = \\alpha x\n$$\nIntegrating, we get:\n$$\n\\ln g(x) = \\frac{\\alpha}{2} x^2 + \\beta\n$$\nwhere $\\beta$ is a constant of integration.\nExponentiating, we get:\n$$\n\\begin{aligned}\ng(x) \t&= e^{\\frac{\\alpha}{2} x^2 + \\beta} \\\\\n\t&= B e^{\\frac{\\alpha}{2} x^2}\n\\end{aligned}\n$$\nwhere $B = e^\\beta$.\nSince $g$ is a probability density function we must have\n$$\n\\lim_{|x|\\rightarrow\\infty}g(x) = 0\n$$\nso $\\alpha$ must be negative.\n\nTherefore setting\n$$\n\\begin{aligned}\n\\alpha \t&= -\\frac{1}{\\sigma^2} \\\\\nB \t\t&= C\n\\end{aligned}\n$$\nwe see that $g$ is the probability density function of a normal distribution with mean zero and variance $\\sigma^2$.\n\\end{proof}\n\n\\section{Rotational Symmetry of $n$ IID Variates}\n\n\\begin{theorem}\nThe joint distribution of $n$ IID random variates is rotationally symmetric if and only the random variates are normally distributed with mean zero.\n\\end{theorem}\n\n\\begin{proof}\nClearly, the joint distribution of $n$ IID normal variates with mean zero is rotationally symmetric.\n\nTo prove the converse it suffices to consider rotations in the plane defined by any pair of coordinates. \nThe preceding theorem implies that the variates are normal with mean zero.\n\\end{proof}\n\n\\end{document}  ", "meta": {"hexsha": "84acd66dd5c6fd5797c17e82a1b20c4534ab7a05", "size": 5991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rotational-symmetry/rotational-symmetry.tex", "max_stars_repo_name": "agryman/probability-and-statistics", "max_stars_repo_head_hexsha": "4a6cd819c24b77764b588b8762d02a528db44cd0", "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": "rotational-symmetry/rotational-symmetry.tex", "max_issues_repo_name": "agryman/probability-and-statistics", "max_issues_repo_head_hexsha": "4a6cd819c24b77764b588b8762d02a528db44cd0", "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": "rotational-symmetry/rotational-symmetry.tex", "max_forks_repo_name": "agryman/probability-and-statistics", "max_forks_repo_head_hexsha": "4a6cd819c24b77764b588b8762d02a528db44cd0", "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.6607142857, "max_line_length": 165, "alphanum_fraction": 0.6925388082, "num_tokens": 1789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6652405503531288}}
{"text": "\\section{NFA with $\\epsilon$-transitions}\n\nWe shall now introduce another extension to NFA, called \\eNFA, which\nis a NFA whose labels can be the empty string, noted~\\(\\epsilon\\).\nThe interpretation of this new kind of transition, called\n\\(\\epsilon\\)-transition, is that the current state changes by\nfollowing this transition \\emph{without reading any input}. This is\nsometimes referred as a \\emph{spontaneous transition}. The rationale\nis that \\(\\epsilon a = a \\epsilon = a\\), so recognising~\\(\\epsilon a\\)\nor~\\(a\\epsilon\\) is the same as recognising~\\(a\\). In other words, we\ndo not need to read something more than~\\(a\\) as input.\n\nFor example, the \\fig~\\vref{fig:enfa_num} specifies signed natural and\ndecimal numbers by means of the \\eNFA.\n\\begin{figure}\n\\centering\n\\includegraphics[bb=49 660 288 758]{enfa_num}\n\\caption{Signed natural and decimal numbers\\label{fig:enfa_num}}\n\\end{figure}\nThis is not the simplest \\eNFA we can imagine for these numbers, but\nnote the utility of the \\(\\epsilon\\)-transition between~\\(q_0\\)\nand~\\(q_1\\). In case of lexical analysers, \\eNFA{s} enable the\nseparate design of a NFA for each token, then create an initial\n(respectively, final) state connected to all their initial\n(respectively, final) states with an \\(\\epsilon\\)-transition.\n\nFor instance, for keywords \\term{fun} and \\term{function} and\nidentifiers, we have\n\\begin{center}\n\\includegraphics[bb=48 630 421 732,scale=0.88]{enfa_kwd_id}\n\\end{center}\nIn lexical analysis, once we have a single \\eNFA, we can\n\\begin{itemize}\n\n  \\item either remove all the \\(\\epsilon\\)-transitions and either create\n  a NFA and then maybe a DFA, or create directly a DFA;\n\n  \\item or use a formal definition of \\eNFA that directly leads to a\n  recognition algorithm, just as we did for DFAs and NFAs.\n\n\\end{itemize}\nBoth methods assume that it is always possible to create an equivalent\nNFA, hence a DFA, from a given \\eNFA.  In other words, \\emph{DFA, NFA\n  and \\eNFA have the same expressive power.}\n\nThe first method constructs explicitly the NFA and maybe the DFA,\nwhile the second does not, at the possible cost of more computations\nat run-time.\n\nBefore entering into the details, we need to define formally an \\eNFA,\nas suggested by the second method. The only difference between an NFA\nand an \\eNFA is that the transition function~\\(\\delta_E\\) takes as\nsecond argument an element in \\(\\Sigma \\cup \\{\\epsilon\\}\\), with\n\\(\\epsilon \\not\\in \\Sigma\\), instead of~\\(\\Sigma\\) --~but the alphabet\nstill remains~\\(\\Sigma\\).\n\n\\subsection*{$\\epsilon$-closure}\n\nWe need now a function called \\emph{\\(\\eClose\\)}, which takes an\n\\eNFA~\\(\\mathcal{E}\\), a state~\\(q\\) of~\\(\\mathcal{E}\\) and returns\nall the states which are accessible in~\\(\\mathcal{E}\\) from~\\(q\\) with\nlabel~\\(\\epsilon\\). The idea is to achieve a \\emph{depth-first\n  traversal} of~\\(\\mathcal{E}\\), starting from~\\(q\\) and following\nonly \\(\\epsilon\\)-transitions. Let us call \\(\\eDFS\\)\n(`\\(\\epsilon\\)-Depth-First-Search') the function such that \\(\\eDFS(q,\nQ)\\) is the set of states reachable from~\\(q\\) following\n\\(\\epsilon\\)-transitions and which is not included in~\\(Q\\),\n\\emph{\\(Q\\) being interpreted as the set of states already visited in\n  the traversal}. The set \\(Q\\) ensures the termination of the\nalgorithm even in presence of cycles in the automaton. Therefore, let\n\\begin{equation*}\n\\eClose (q) = \\eDFS (q, \\varnothing), \\quad \\text{if} \\; q \\in Q_E,\n\\end{equation*}\nwhere the \\eNFA is \\(\\mathcal{E} = (Q_E, \\Sigma, \\delta_E, q_0,\nF_E)\\). Now we define \\(\\eDFS\\) as follows:\n\\begin{align}\n   \\eDFS (q, Q) \n&= \\varnothing,\n& \\text{if} \\; q \\in Q; \\label{eDFS_1}\\\\\n  \\eDFS (q, Q)\n&= \\{q\\} \\quad \\cup \\bigcup_{p \\in \\delta_E(q,\\epsilon)}{\\eDFS (p, Q\n    \\cup \\{q\\})},\n& \\text{if} \\; q \\not\\in Q. \\label{eDFS_2}\n\\end{align}\nThe \\eNFA in \\fig~\\vref{fig:enfa_num} leads to the following\n\\(\\epsilon\\)-closures:\n\\begin{align*}\n    \\eClose (q_0) &= \\{q_0, q_1\\}\\\\\n    \\eClose (q_1) &= \\{q_1\\}\\\\\n    \\eClose (q_2) &= \\{q_2\\}\\\\\n    \\eClose (q_3) &= \\{q_3, q_5\\}\\\\\n    \\eClose (q_4) &= \\{q_4, q_3, q_5\\}\n    \\eClose (q_5) &= \\{q_5\\}.\n\\end{align*}\nConsider, as a more difficult example, the following\n\\eNFA~\\(\\mathcal{E}\\):\n\\begin{center}\n\\includegraphics[bb=48 677 236 735]{enfa_eg}\n\\end{center}\n\\begin{align*}\n\\eClose (q_0)\n  &= \\eDFS (q_0, \\varnothing), \\quad \\text{since} \\; q_0 \\in Q_E\\\\\n  &= \\{q_0\\} \\cup \\eDFS (q_1, \\{q_0\\}) \\cup \\eDFS (q_4, \\{q_0\\})\n     \\quad \\text{by eq.~\\ref{eDFS_2}}\\\\\n  &= \\{q_0\\} \\cup \\biggl( \\{q_1\\} \\cup\n     \\bigcup_{p \\in \\delta_E(q_1,\\epsilon)}{\\eDFS (p, \\{q_0, q_1\\})}\\biggr)\n     \\quad \\text{by eq.~\\ref{eDFS_2}}\\\\\n  &\\mathrel{\\phantom{=}} \\phantom{\\{q_0\\}}{} \n     \\cup \\biggl( \\{q_4\\} \\cup \n     \\bigcup_{p \\in \\delta_E(q_4,\\epsilon)}{\\eDFS (p, \\{q_0, q_4\\})} \\biggr)\n     \\quad \\text{by eq.~\\ref{eDFS_2}}\\\\\n  &= \\{q_0\\} \\cup \\biggl( \\{q_1\\} \\cup\n     \\bigcup_{p \\in \\{q_2\\}}{\\eDFS (p, \\{q_0, q_1\\})}\\biggr)\\\\\n  &\\mathrel{\\phantom{=}} \\phantom{\\{q_0\\}}{} \n     \\cup \\biggl( \\{q_4\\} \\cup \\bigcup_{p \\in \\varnothing}{\\eDFS (p,\n     \\{q_0, q_4\\})} \\biggr)\\\\\n  &= \\{q_0\\} \\cup (\\{q_1\\} \\cup \\eDFS (q_2, \\{q_0, q_1\\}))\n     \\cup (\\{q_4\\} \\cup \\varnothing)\\\\\n  &= \\{q_0, q_1, q_4\\} \\cup \\eDFS (q_2, \\{q_0, q_1\\})\\\\\n  &= \\{q_0, q_1, q_4\\} \\cup \\biggl(\\{q_2\\} \\cup \\bigcup_{p \\in\n     \\delta_E(q_2,\\epsilon)}{\\eDFS (p, \\{q_0, q_1, q_2\\})}\\biggr)\\\\\n  &= \\{q_0, q_1, q_4\\} \\cup \\biggl(\\{q_2\\} \\cup \\bigcup_{p \\in\n     \\{q_1, q_3\\}}{\\eDFS (p, \\{q_0, q_1, q_2\\})}\\biggr)\\\\\n  &= \\{q_0, q_1, q_2, q_4\\} \\cup \\eDFS (q_1, \\{q_0, q_1, q_2\\})\\\\\n  &\\mathrel{\\phantom{=}} \\phantom{\\{q_0,q_2,q_2,q_4\\}} \\cup \\eDFS\n     (q_3, \\{q_0, q_1, q_2\\})\\\\\n  &= \\{q_0, q_1, q_2, q_4\\} \\cup \\varnothing \\qquad\\quad\n     \\text{by eq.~\\ref{eDFS_1}, since} \\; q_1 \\in \\{q_0, q_1, q_2\\}\\\\\n  &\\mathrel{\\phantom{=}} \\;\\,\n     \\cup \\biggl(\\{q_3\\} \\cup\n     \\bigcup_{p \\in \\delta_E(q_3, \\epsilon)}{\\eDFS (p, \\{q_0, q_1, q_2, q_3\\})}\\biggr)\n     \\quad \\text{by eq.~\\ref{eDFS_2}}\\\\\n  &= \\{q_0, q_1, q_2, q_3, q_4\\} \\cup \\bigcup_{p \\in\n     \\varnothing}{\\eDFS (p, \\{q_0, q_1, q_2, q_3\\})}\\\\\n  &= \\{q_0, q_1, q_2, q_3, q_4\\}.\n\\end{align*}\nIt is useful to extend \\(\\eClose\\) to sets of states, not just\nstates. Let us note \\(\\eCloseSet\\) this extension, which we can easily\ndefine as\n\\begin{equation*}\n\\eCloseSet (Q) = \\bigcup_{q \\in Q}{\\eClose (q)},\n\\end{equation*}\nfor any subset \\(Q \\subseteq Q_E\\) where the \\eNFA is \\(\\mathcal{E} =\n(Q_E, \\Sigma, \\delta_E, q_E, F_E)\\).\n\n\\subsection*{Optimisation}\n\\label{enfa_closure}\n\nLet us compute the \\(\\epsilon\\)-closure of~\\(q_0\\) in the following\n\\eNFA~\\(\\mathcal{E}\\):\n\\begin{center}\n\\includegraphics[bb=65 618 315 721]{enfa_closure}\n\\end{center}\nwhere the sub-\\eNFA~\\(\\mathcal{E'}\\) contains only\n\\(\\epsilon\\)-transitions and all its~\\(Q'\\) states are accessible\nfrom~\\(q_3\\).\n\\begin{align*}\n   \\eClose (q_0) \n&= \\eDFS (q_0, \\varnothing)\\\\\n&= \\{q_0\\} \\cup \\eDFS (q_1, \\{q_0\\}) \\cup \\eDFS (q_2, \\{q_0\\})\\\\\n&= \\{q_0\\} \\cup (\\{q_1\\} \\cup \\eDFS (q3, \\{q_0, q_1\\}))\\\\\n&\\mathrel{\\phantom{=}} \\phantom{\\{q_0\\}}{} \\cup (\\{q_2\\} \\cup \\eDFS\n   (q_3, \\{q_0, q_2\\}))\\\\\n&= \\{q_0, q_1, q_2\\} \\cup \\eDFS (q3, \\{q_0, q_1\\}) \\cup \\eDFS\n   (q_3, \\{q_0, q_2\\})\\\\\n&= \\{q_0, q_1, q_2, q_3,\\} \\cup (\\{q_3\\} \\cup Q') \\cup (\\{q_3\\} \\cup Q')\\\\\n&= \\{q_0, q_1, q_2, q_3,\\} \\cup Q'.\n\\end{align*}\nWe compute \\(\\{q_3\\} \\cup Q'\\) twice, that is, we traverse\ntwice~\\(q_3\\) and all the states of~\\(\\mathcal{E'}\\), which can be\ninefficient if~\\(Q'\\) is large. The way to avoid repeating traversals\nis to change the definitions of~\\(\\eClose\\) and\n\\(\\eCloseSet\\). Dually, we need a new definition of \\(\\eDFS\\) and\ncreate a function \\(\\eDFSset\\) which is similar to \\(\\eDFS\\), except\nthat it applies to set of states instead of one state:\n\\begin{align*}\n   \\eClose (q) \n&= \\eDFS (q, \\varnothing),\n&& \\text{if} \\; q \\in Q_E;\\\\\n   \\eCloseSet (Q)\n&= \\eDFSset (Q, \\varnothing),\n&& \\text{if} \\; Q \\subseteq Q_E.\n\\end{align*}\nWe interpret~\\(Q'\\) in \\(\\eDFS (q, Q')\\) and \\(\\eDFSset (Q, Q')\\) as\nthe set of states that have already been visited in the depth-first\nsearch. Variables~\\(q\\) and~\\(Q\\) denote, respectively, a state and a\nset of states that have to be explored. In the first definition we\ncomputed the \\emph{new reachable states}, whilst, in the new one, we\ncompute the \\emph{currently reached states}. Then let us redefine\n\\(\\eDFS\\) this way:\n\\begin{align*}\n  \\eDFS (q, Q')\n&= Q',\n&& \\text{if} \\; q \\in Q'; \\tag{1'}\\\\\n  \\eDFS (q, Q')\n&= \\eDFSset (\\delta_E (q, \\epsilon), Q' \\cup \\{q\\}),\n&& \\text{if} \\; q \\not\\in Q'. \\tag{2'}\n\\end{align*}\nContrast with the first definition\n\\begin{align*}\n   \\eDFS (q, Q') \n&= \\varnothing,\n& \\text{if} \\; q \\in Q'; \\tag{1} \\label{empty}\\\\\n  \\eDFS (q, Q') \n&= \\{q\\} \\quad \\cup \\bigcup_{p \\in \\delta_E(q,\\epsilon)}{\\eDFS (p, Q'\n    \\cup \\{q\\})},\n& \\text{if} \\; q \\not\\in Q'. \\tag{2} \\label{parallel}\n\\end{align*}\nHence, in~\\eqref{empty} we return \\(\\varnothing\\) because there is no\nnew state, that is, none not already in \\(Q'\\), whereas in (1') we\nreturn~\\(Q'\\) itself. The new definition of \\(\\eDFSset\\) is not more\ndifficult than the first one:\n\\begin{align}\n   \\eDFSset (\\varnothing, Q')\n&= Q',\\label{eDFSset:1}\\\\\n   \\eDFSset (\\{q\\} \\cup Q, Q')\n&= \\eDFSset (Q, \\eDFS (q, Q')),\n& \\text{if} \\; q \\not\\in Q. \\label{eDFSset:2}\n\\end{align}\nNotice that the definitions of \\(\\eDFS\\) and \\(\\eDFSset\\) are mutually\nrecursive. In~\\eqref{parallel} we traverse states in parallel\n(consider the union operator), starting from each element in\n\\(\\delta_E (q, \\epsilon)\\), whereas in~(2') and~\\eqref{eDFSset:2}, we\ntraverse them sequentially so we can use the information collected\n(currently reached states) in the previous searches.\n\nComing back to our example \\vpageref{enfa_closure}, we find\n\\begin{align*}\n   \\eClose (q_0) \n&= \\eDFS (q_0, \\varnothing)\n&& q_0 \\in Q_E\\\\\n&= \\eDFSset (\\{q_1, q_2\\}, \\{q_0\\})\n&& \\text{by eq.~(2')}\\\\\n&= \\eDFSset (\\{q_2\\}, \\eDFS (q_1, \\{q_0\\}))\n&& \\text{by eq.~(4)}\\\\\n&= \\eDFSset (\\{q_2\\}, \\eDFSset (\\{q_3\\}, \\{q_0,\n   q_1\\}))\n&& \\text{by eq.~(2')}\\\\\n&= \\eDFSset (\\{q_2\\}, \\eDFSset (\\varnothing, \\eDFS (q_3, \\{q_0, q_1\\})))\n&& \\text{by eq.~(4)}\\\\\n&= \\eDFSset (\\{q_2\\}, \\eDFS (q_3, \\{q_0, q_1\\}))\n&& \\text{by eq.~(3)}\\\\\n&= \\eDFSset (\\{q_2\\}, \\{q_0, q_1, q_3\\} \\cup Q')\\\\\n&= \\eDFSset (\\varnothing, \\eDFS (q_2, \\{q_0, q_1, q_3\\} \\cup Q'))\n&& \\text{by eq.~(4)}\\\\\n&= \\eDFS (q_2, \\{q_0, q_1, q_3\\} \\cup Q')\n&& \\text{by eq.~(3)}\\\\\n&= \\eDFSset (\\{q_3\\}, \\{q_0, q_1, q_2, q_3\\} \\cup Q')\n&& \\text{by eq.~(2')}\\\\\n&= \\eDFSset (\\varnothing, \\eDFS (q_3, \\{q_0, q_1, q_2, q_3\\} \\cup Q'))\n&& \\text{by eq.~(4)}\\\\\n&= \\eDFS (q_3, \\{q_0, q_1, q_2, q_3\\} \\cup Q')\n&& \\text{by eq.~(3)}\\\\\n&= \\{q_0, q_1, q_2, q_3\\} \\cup Q'\n&& \\text{by eq.~(1')}\\\\\n\\end{align*}\nThe important thing here is that we did not compute (traverse) several\ntimes~\\(Q'\\). Note that some equations can be used in a different\norder and~\\(q\\) can be chosen arbitrarily in equation~(4), but the\nresult is always the same.\n\n\\subsection*{Extended transition functions}\n\nThe \\(\\epsilon\\)-closure allows to explain how a \\eNFA recognises or\nrejects a given input. Let \\(\\mathcal{E} = (Q_E, \\Sigma, \\delta_E,\nq_0, F_E)\\). We want \\(\\hat{\\delta}_E (q, w)\\) be the set of states\nreachable from~\\(q\\) along a path whose labels, when concatenated, for\nthe string~\\(w\\). The difference here with NFAs is that\nseveral~\\(\\epsilon\\) can be present along this path, despite not\ncontributing to \\(w\\).  For all state \\(q \\in Q_E\\), let\n\\begin{align*}\n   \\hat{\\delta}_E (q, \\epsilon)\n&= \\eClose (q),\\\\\n   \\hat{\\delta}_E (q, wa)\n&= \\eCloseSet \\Biggl(\\bigcup_{p \\in \\hat{\\delta}_E (q, w)}{\\delta_N (p,\n     a)}\\Biggr),\n&& \\text{for all} \\; a \\in \\Sigma, w \\in \\Sigma^{*}.\n\\end{align*}\nThis definition is based on the regular identity \\(wa =\n((w\\epsilon^{*})a)\\epsilon^{*}\\).\n\nAs an illustration, let us consider again the \\eNFA in\n\\fig~\\vref{fig:enfa_num} and compute the states reached on the input\n\\verb+5.6+:\n\\begin{align*}\n   \\hat{\\delta}_E (q_0, \\epsilon)\n&= \\eClose (q_0) = \\{q_0, q_1\\};\\\\\n   \\hat{\\delta}_E (q_0, \\mathtt{5})\n&= \\eCloseSet \\Biggl( \\bigcup_{p \\in \\hat{\\delta}_E (q_0,\n   \\epsilon)}{\\delta_N (p, \\mathtt{5})} \\Biggr)\\\\\n&= \\eCloseSet (\\delta_N (q_0, \\mathtt{5}) \\cup \\delta_N (q_1,\n   \\mathtt{5})) = \\eCloseSet (\\varnothing \\cup \\{q_1, q_4\\})\\\\\n&= \\{q_1, q_3, q_4, q_5\\};\\\\\n   \\hat{\\delta}_E (q_0, \\mathtt{5.})\n&= \\eCloseSet \\Biggl( \\bigcup_{p \\in \\hat{\\delta}_N (q_0,\n   \\mathtt{5})}{\\delta_N (p, \\mathtt{.})} \\Biggr)\\\\\n&= \\eCloseSet (\\delta_N (q_1, \\mathtt{.}) \\cup \\delta_N (q_3,\n   \\mathtt{.}) \\cup \\delta_N (q_4, \\mathtt{.}) \\cup \\delta_N (q_5,\n   \\mathtt{.}))\\\\\n   \\hat{\\delta}_E (q_0, \\mathtt{5.})\n&= \\eCloseSet (\\{q_2\\} \\cup \\varnothing \\cup \\varnothing \\cup\n   \\varnothing)\n = \\{q_2\\};\\\\\n   \\hat{\\delta}_N (q_0, \\mathtt{5.6})\n&= \\eCloseSet \\Biggl( \\bigcup_{p \\in \\hat{\\delta}_E (q_0,\n     \\mathtt{5.})}{\\delta_N (p, \\mathtt{6})} \\Biggr)\\\\\n&= \\eCloseSet (\\delta_N (q_2, \\mathtt{6}))\n= \\eCloseSet (\\{q_3\\})\n= \\{q_3, q_5\\} \\ni q_5.\n\\end{align*}\nSince~\\(q_5\\) is a final state, the string \\verb+5.6+ is recognised as\na number.\n\n\\subsection*{Subset construction for \\eNFA{}s}\n\nLet us present now how to construct a DFA from a \\eNFA such that both\nrecognise the same language. The method is a variation of the subset\nconstruction we presented for NFA: we must take into account the\nstates reachable through \\(\\epsilon\\)-transitions, with help of\n\\(\\epsilon\\)-closures. Let us assume that \\(\\mathcal{E} = (Q, \\Sigma,\n\\delta, q_0, F)\\) is an \\eNFA. Let us define as follows the equivalent\nDFA \\(\\mathcal{D} = (Q_D, \\Sigma, \\delta_D, q_D, F_D)\\).\n\\begin{enumerate}\n\n  \\item \\(Q_D\\) is the set of subsets of \\(Q_E\\). More precisely, all\n    accessible states of \\(\\mathcal{D}\\) are \\(\\epsilon\\)-closed\n    subsets of \\(Q_E\\), that is to say, sets \\(Q \\subseteq Q_E\\) such\n    that \\(Q = \\eClose(Q)\\);\n\n  \\item \\(q_D = \\eClose (q_0)\\), in other words, we get the start\n    state of~\\(\\mathcal{D}\\) by \\(\\epsilon\\)-closing the set made of\n    only the start state of~\\(\\mathcal{E}\\);\n\n  \\item \\(F_D\\) is those sets of states that contain at least one\n    final state of \\(\\mathcal{E}\\), that is to say, \\(F_D = \\{Q \\,\n    \\lvert \\, Q \\in Q_D \\; \\text{and} \\; Q \\cap F_E \\neq\n    \\varnothing\\}\\);\n\n  \\item For all \\(a \\in \\Sigma\\) and \\(Q \\in Q_D\\), let \\(\\delta_D (Q,\n    a) = \\eCloseSet \\bigl(\\bigcup_{q \\in Q}{\\delta_E (q,\n      a)}\\bigr)\\).\n\n\\end{enumerate}\nLet us consider again the \\eNFA in \\fig~\\vref{fig:enfa_num}. Its\ntransition table is\n\\begin{equation*}\n\\begin{array}{r@{}l||c|c|c|c|c}\n\\multicolumn{2}{c||}{\\mathcal{E}} & + & - & 0, \\ldots, 9 & \\mathtt{.} &\n\\epsilon\\\\\n\\hhline{==::=====}\n\\rightarrow & q_0 & \\{q_1\\} & \\{q_1\\} & \\varnothing & \\varnothing \n                  & \\{q_1\\}\\\\\n            & q_1 & \\varnothing  & \\varnothing & \\{q_1, q_4\\} \n                  & \\{q_2\\} & \\varnothing\\\\\n            & q_2 & \\varnothing  & \\varnothing & \\{q_3\\} & \\varnothing\n                  & \\varnothing\\\\\n            & q_3 & \\varnothing & \\varnothing & \\{q_3\\} & \\varnothing\n                  & \\{q_5\\}\\\\\n            & q_4 & \\varnothing & \\varnothing & \\varnothing  \n                  & \\varnothing & \\{q_3\\}\\\\\n         \\# & q_5 & \\varnothing & \\varnothing & \\varnothing \n                  & \\varnothing & \\varnothing \n\\end{array}\n\\end{equation*}\nBy applying the subset construction to this \\eNFA, we get the table\n\\begin{equation*}\n\\begin{array}{r@{}l||c|c|c|c}\n\\multicolumn{2}{c||}{\\mathcal{D}} & + & - & 0, \\ldots, 9 & \\mathtt{.}\\\\\n\\hhline{==::====}\n\\rightarrow \n   & \\{q_0,q_1\\} \n             & \\{q_1\\} & \\{q_1\\} & \\{q_1, q_3, q_4, q_5\\} & \\{q_2\\}\\\\\n   & \\{q_1\\} & \\varnothing  & \\varnothing & \\{q_1, q_3, q_4, q_5\\} \n             & \\{q_2\\}\\\\\n\\# & \\{q_1, q_3, q_4, q_5\\} \n             & \\varnothing  & \\varnothing & \\{q_1, q_3, q_4, q_5\\} \n             & \\{q_2\\}\\\\\n   & \\{q_2\\} & \\varnothing & \\varnothing & \\{q_3, q_5\\} & \\varnothing\\\\\n\\# & \\{q_3, q_5\\}\n             & \\varnothing & \\varnothing & \\{q_3, q_5\\} & \\varnothing\n\\end{array}\n\\end{equation*}\nLet us rename the states of~\\(\\mathcal{D}\\) and get rid of the empty\nsets:\n\\begin{equation*}\n\\begin{array}{r@{}l||c|c|c|c}\n\\multicolumn{2}{c||}{\\mathcal{D}} & + & - & 0, \\ldots, 9 & \\mathtt{.}\\\\\n\\hhline{==::====}\n\\rightarrow \n   & A & B & B & C & D\\\\\n   & B &   &   & C & D\\\\\n\\# & C &   &   & C & D\\\\\n   & D &   &   & E &\\\\\n\\# & E &   &   & E &\n\\end{array}\n\\end{equation*}\nThe transition diagram of~\\(\\mathcal{D}\\) is shown in\n\\fig~\\vref{fig:nfa_num}.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[bb=49 610 208 758]{dfa_from_enfa_num}\n\\caption{Determinisation of the \\eNFA in \\fig~\\vref{fig:enfa_num}\n\\label{fig:nfa_num}}\n\\end{figure}\n", "meta": {"hexsha": "d483b47425c1af16c0dacb58e86e19f816062a4b", "size": 16538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "enfa.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": "enfa.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": "enfa.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": 40.8345679012, "max_line_length": 86, "alphanum_fraction": 0.6113193857, "num_tokens": 6796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6651486831963558}}
{"text": "\\section*{Problem 2 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item \n\nThe steady-state, continuous energy diffusion equation is\n$$ -\\nabla D(r,E) \\nabla \\phi(r,E) + \\Sigma_t(r,E) \\phi(r,E) = \\int_0^{\\infty} \\Sigma_s(r,E' \\rightarrow E)\\phi(r,E')\\,dE' + \\chi(E) \\int_0^{\\infty} \\nu(E') \\Sigma_f(r,E')\\phi(r,E')\\,dE' .$$\nAs a reminder, the terms are defined as:\n\\begin{align*}\n\\textbf{Loss terms (left side)} \\qquad\\qquad& \\\\\n-\\nabla D(r,E) \\nabla \\phi(r,E)&:\\text{ the neutrons with energy }E\\text{ streaming from location }r\\text{ to any other location} \\\\\n\\Sigma_t(r,E) \\phi(r,E)&:\\text{ the total interaction rate of neutrons with energy }E\\text{ at location }r  \\\\\n\\textbf{Gain terms (right side)} \\qquad\\qquad& \\\\\n\\int_0^{\\infty} \\Sigma_s(r,E' \\rightarrow E)\\phi(r,E')\\,dE'&:\\text{ the scattering rate of neutrons with any energy }E'\\text{ into energy }E\\text{ at location }r \\\\\n\\chi(E) \\int_0^{\\infty} \\nu(E') \\Sigma_f(r,E')\\phi(r,E')\\,dE'&:\\text{ the fission rate of neutrons with any energy }E'\\text{ at location }r; \\\\\n& \\quad\\chi(E)\\text{ is the fraction of neutrons produced by fission with energy }E\n\\end{align*}\nIt is given that $D$ and $\\nu$ are constants, and we are told that the reactor is homogeneous so none of the cross sections depend on $r$. Our diffusion equation simplifies down to\n$$\\boxed{ -D \\lap \\phi(r,E) + \\Sigma_t(E) \\phi(r,E) = \\int_0^{\\infty} \\Sigma_s(E' \\rightarrow E)\\phi(r,E')\\,dE' + \\chi(E) \\int_0^{\\infty} \\nu \\Sigma_f(E')\\phi(r,E')\\,dE' }.$$\n\n\\item\n\nWe are asked to derive the three-group multigroup equation, so we need to find the collective behavior in each group. We can do this by taking the integral of the continuous equation over the energy range corresponding to each group. This process will allow us to take the continuous equation which is valid for all energies (and which may not be able to be solved analytically), and turn it into a discretized form that can be solved either by hand, or more likely, with a computer.\n\nSay we take the integral over some energy group, $g$, spanning energies $E_{g-1}$ to $E_g$ (for the lowest energy group, $E_{g-1} = 0$, and for the highest energy group, $E_g = \\infty$). Our equation becomes\n\\begin{align*}\n\\int_{E_{g-1}}^{E_g} -D \\lap \\phi(r,E)\\,dE + \\int_{E_{g-1}}^{E_g} \\Sigma_t(E) \\phi(r,E)\\,dE = \\int_{E_{g-1}}^{E_g} \\int_0^{\\infty} \\Sigma_s(E' &\\rightarrow E)\\phi(r,E')\\,dE'\\,dE \\\\\n&+ \\int_{E_{g-1}}^{E_g} \\chi(E) \\int_0^{\\infty} \\nu \\Sigma_f(E')\\phi(r,E')\\,dE'\\,dE .\n\\end{align*}\nWe can similarly separate our integrals over $dE'$ on the right side into three intervals, one for each group. We will express our total integral, from $E' = 0$ to $E'=\\infty$, as the sum of the integrals over these three intervals, each ranging from $E_{g'-1}$ to $E_{g'}$.\n\\begin{align*}\n\\int_{E_{g-1}}^{E_g} -D \\lap \\phi(r,E)\\,dE + \\int_{E_{g-1}}^{E_g} \\Sigma_t(E) \\phi(r,E)\\,dE = &\\int_{E_{g-1}}^{E_g} \\sum_{g'=1}^3 \\int_{E_{g'-1}}^{E_{g'}} \\Sigma_s(E' \\rightarrow E)\\phi(r,E')\\,dE'\\,dE \\\\\n &+ \\int_{E_{g-1}}^{E_g} \\chi(E) \\sum_{g'=1}^3 \\int_{E_{g'-1}}^{E_{g'}} \\nu \\Sigma_f(E')\\phi(r,E')\\,dE'\\,dE \n\\end{align*}\nWhere neither $D$ nor the Laplacian depend on $E$, we can remove them from the integral in the first term. And, since the only factor in the fission term depending on $E$ is $\\chi(E)$, the fraction of fission-born neutrons produced into energy $E$, we can separate it as it's own integral. \n$$ \\chi_g = \\int_{E_{g-1}}^{E_g} \\chi(E)\\,dE $$\n$\\chi_g$ is just the fraction of fission-born neutrons produced in group $g$, the sum of the fraction of fission-born neutrons created in all energies from $E_{g-1}$ to $E_g$. Our diffusion equation simplifies to\n\\begin{align*}\n-D \\lap \\int_{E_{g-1}}^{E_g} \\phi(r,E)\\,dE + \\int_{E_{g-1}}^{E_g} \\Sigma_t(E) \\phi(r,E)\\,dE = \\int_{E_{g-1}}^{E_g} \\sum_{g'=1}^3 \\int_{E_{g'-1}}^{E_{g'}} \\Sigma_s(E' &\\rightarrow E)\\phi(r,E')\\,dE'\\,dE \\\\\n &+ \\chi_g \\nu \\sum_{g'=1}^3 \\int_{E_{g'-1}}^{E_{g'}} \\Sigma_f(E')\\phi(r,E')\\,dE' .\n\\end{align*}\nHere we recognize that the total flux in group $g$ is given by\n$$ \\phi_g(r) = \\int_{E_{g-1}}^{E_g} \\phi(r,E)\\,dE ,$$\nand that average cross sections for some energy group are equal to the flux-weighted average of the reaction rate over that group's energy range.\n$$ \\Sigma_g = \\frac{\\int_{E_{g-1}}^{E_g} \\Sigma(E)\\phi(r,E)\\,dE}{\\int_{E_{g-1}}^{E_g} \\phi(r,E)\\,dE} = \\frac{\\int_{E_{g-1}}^{E_g} \\Sigma(E)\\phi(r,E)\\,dE}{\\phi_g(r)} $$\nMultiplying both sides by $\\phi_g$ gives\n$$ \\Sigma_g \\phi_g = \\int_{E_{g-1}}^{E_g} \\Sigma(E)\\phi(E)\\,dE ,$$\nand so we can simplify all the flux and reaction rate integrals in the diffusion equation.\n$$ -D \\lap \\phi_g(r) + \\Sigma_{t,g} \\phi_g(r) = \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow g}\\phi_{g'}(r) + \\chi_g \\nu \\sum_{g'=1}^3 \\Sigma_{f,g'}\\phi_{g'}(r) $$\nRemember, this is actually a set of three equations, one for each group (1, 2, and 3).\n\\begin{align*}\n-D \\lap \\phi_1(r) + \\Sigma_{t,1} \\phi_1(r) &= \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow 1}\\phi_{g'}(r) + \\chi_1 \\nu \\sum_{g'=1}^3 \\Sigma_{f,g'}\\phi_{g'}(r) \\\\\n-D \\lap \\phi_2(r) + \\Sigma_{t,2} \\phi_2(r) &= \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow 2}\\phi_{g'}(r) + \\chi_2 \\nu \\sum_{g'=1}^3 \\Sigma_{f,g'}\\phi_{g'}(r) \\\\\n-D \\lap \\phi_3(r) + \\Sigma_{t,3} \\phi_3(r) &= \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow 3}\\phi_{g'}(r) + \\chi_3 \\nu \\sum_{g'=1}^3 \\Sigma_{f,g'}\\phi_{g'}(r)\n\\end{align*}\n\nNow we begin to impose the assumptions of the system. First, fission only produces neutrons in group 1, so $\\chi_2 = 0$ and $\\chi_3 = 0$. Also fission is only induced in group 3, so $\\Sigma_{f,1} = 0$ and $\\Sigma_{f,2} = 0$. Our set of equations is now:\n\\begin{align*}\n-D \\lap \\phi_1(r) + \\Sigma_{t,1} \\phi_1(r) &= \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow 1}\\phi_{g'}(r) + \\chi_1 \\nu \\Sigma_{f,3}\\phi_{3}(r) \\\\\n-D \\lap \\phi_2(r) + \\Sigma_{t,2} \\phi_2(r) &= \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow 2}\\phi_{g'}(r) \\\\\n-D \\lap \\phi_3(r) + \\Sigma_{t,3} \\phi_3(r) &= \\sum_{g'=1}^3 \\Sigma_{s,g' \\rightarrow 3}\\phi_{g'}(r) \n\\end{align*}\nThere is no upscattering---group 2 can only inscatter (scatter back into group 2) or scatter into group 3; group 3 can only inscatter. The groups are directly coupled, so group 1 can only scatter into group 2. These assumptions mean $\\Sigma_{s,1 \\rightarrow 3} = 0$, $\\Sigma_{s,2 \\rightarrow 1} = 0$, $\\Sigma_{s,3 \\rightarrow 1} = 0$, and $\\Sigma_{s,3 \\rightarrow 2} = 0$, and our equations (which we now right out explicitly) simplify further:\n\\begin{align*}\n-D \\lap \\phi_1(r) + \\Sigma_{t,1} \\phi_1(r) &= \\Sigma_{s,1 \\rightarrow 1}\\phi_1(r) + \\chi_1 \\nu \\Sigma_{f,3}\\phi_{3}(r) \\\\\n-D \\lap \\phi_2(r) + \\Sigma_{t,2} \\phi_2(r) &= \\Sigma_{s,1 \\rightarrow 2}\\phi_1(r) +\\Sigma_{s,2 \\rightarrow 2}\\phi_2(r) \\\\\n-D \\lap \\phi_3(r) + \\Sigma_{t,3} \\phi_3(r) &= \\Sigma_{s,2 \\rightarrow 3}\\phi_{2}(r) + \\Sigma_{s,3 \\rightarrow 3}\\phi_{3}(r).\\\\\n\\end{align*}\n\n\\item\n\nTo form a matrix equation, we will start by writing the multigroup equations suggestively, with everything but fission terms on the left and with our flux terms grouped together:\n\\begin{align*}\n\\left(-D \\lap + \\Sigma_{t,1} - \\Sigma_{s,1 \\rightarrow 1}\\right)&\\phi_1(r) && && &&= \\chi_1 \\nu \\Sigma_{f,3}\\phi_{3}(r) \\\\\n-\\Sigma_{s,1 \\rightarrow 2}&\\phi_1(r) &+ \\left(-D \\lap + \\Sigma_{t,2} - \\Sigma_{s,2 \\rightarrow 2}\\right)&\\phi_2(r) && &&= 0 \\\\\n&&- \\Sigma_{s,2 \\rightarrow 3}&\\phi_{2}(r) &+ \\left(-D \\lap + \\Sigma_{t,3} - \\Sigma_{s,3 \\rightarrow 3}\\right)&\\phi_{3}(r) &&= 0 \n\\end{align*}\nIn this form, we can more easily see that each term multiplying a flux could be an entry in a \nmatrix, with the matrix equation being given by\n$$\\begin{bmatrix}\n-D \\lap + \\Sigma_{t,1} - \\Sigma_{s,1 \\rightarrow 1} & 0 & 0 \\\\\n-\\Sigma_{s,1 \\rightarrow 2} & -D \\lap + \\Sigma_{t,2} - \\Sigma_{s,2 \\rightarrow 2} & 0 & \\\\\n0 & - \\Sigma_{s,2 \\rightarrow 3} & -D \\lap + \\Sigma_{t,3} - \\Sigma_{s,3 \\rightarrow 3}\n\\end{bmatrix}\\begin{bmatrix}\n\\phi_1 \\\\\n\\phi_2 \\\\\n\\phi_3\n\\end{bmatrix} = \\begin{bmatrix}\n0 & 0 & \\chi_1 \\nu \\Sigma_{f,3} \\\\\n0 & 0 & 0 \\\\\n0 & 0 & 0\n\\end{bmatrix}\\begin{bmatrix}\n\\phi_1 \\\\\n\\phi_2 \\\\\n\\phi_3\n\\end{bmatrix}$$\n\\end{enumerate}\n\n", "meta": {"hexsha": "b2d693e7648e0011bad648f36f242081599a5bea", "size": 8024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc12/disc12_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/disc12/disc12_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/disc12/disc12_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": 80.24, "max_line_length": 483, "alphanum_fraction": 0.6449401795, "num_tokens": 3125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6651048127259478}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Random variables}\\label{sec:rvs}\n\nLet $(\\Omega,\\prob)$ be a probability space associated with some random experiment. Random experiments with numerical outcomes lend themselves to mathematical analysis; for more abstract sample spaces we introduce the notion of \\emph{random variables}, which map sample spaces to the real numbers. Random variables are typically represented by uppercase letters.\n\n\\begin{definition}\nA \\emph{random variable} is a function which maps a sample space $\\Omega$ to the real numbers,\n\\[\n\\begin{array}{rccl}\n\tX:\t& \\Omega\t& \\to\t\t& \\R \\\\\n\t\t& \\omega\t& \\mapsto\t& X(\\omega)\n\\end{array}\n\\]\n\\end{definition}\n\nWe are often not directly interested in the outcome of a random experiment, but rather in some consequence of the outcome: a gambler might be more interested in his losses than in the outcomes of the individual games which led to them. Random variables can be used to pick out particular features of an experiment that are of interest.\n\n\n\\begin{example}\nA fair coin is tossed until a head is observed. Suppose we win \\pounds 3 if the coin is tossed an odd number of times and lose \\pounds 5 if the coin is tossed an even number of times. The sample space is the countably infinite set $\\Omega=\\{H,TH,TTH,TTTH,\\ldots\\}$. We win if event $A=\\{H,TTH, TTTTH,\\ldots\\}$ occurs and lose if event $A^c=\\{TH, TTTH, TTTTH,\\ldots\\}$ occurs. Because the coin is fair,\n\\[\\begin{array}{lll}\n\\prob(A) \t& = \\frac{1}{2} + \\frac{1}{8} + \\frac{1}{32} + \\ldots\t& = \\frac{2}{3}, \\\\ \n\\prob(A^c) \t& = \\frac{1}{4} + \\frac{1}{16} + \\frac{1}{64} + \\ldots \t& =  \\frac{1}{3}.\n\\end{array}\\]\nOur situation can be represented more concisely by the random variable $X:\\Omega\\to\\R$ defined by\n\\[\nX(\\omega) =\n  \\begin{cases}\n   +3 & \\text{if } \\omega\\in \\{H, TTH, TTTTH, \\ldots\\}, \\\\\n   -5 & \\text{if } \\omega\\in \\{TH, TTTH, TTTTTH, \\ldots\\}.\n  \\end{cases}\n\\]\nFrom here it follows that $\\prob(X=3)=2/3$ and $\\prob(X=-5)=1/3$.\n\\end{example}\n\n%-----------------------------\n\\subsection{Distributions}\\label{ss:dist}\n\nLet $B$ be a subset of $\\R$. We use the notation $\\{X\\in B\\}$ as shortand for the event $\\{\\omega: X(\\omega)\\in B\\}$ and $\\prob(X\\in B)$ as shorthand for the probability of this event. Thus $\\{X\\in B\\}$ is the event consisting of those outcomes that are mapped by $X$ into $B$, and $\\prob(X\\in B)$ is therefore the probability that $X$ takes a value in the set $B$.\n\n\\begin{definition}\\label{def:distribution}\nThe \\emph{distribution} of $X$ is the function $\\prob_X$ defined on subsets of $\\R$ by \n\\[\n\\prob_X(B) = \\prob(X\\in B) \n\\]\n\\end{definition}\n\n\\begin{theorem}\\label{th:distribution}\n$\\prob_X$ is a probability measure on subsets of $\\R$.\n\\begin{proof}\nFirst we check that $\\prob_X(\\R) = 1$:\n\\[\n\\prob_X(\\R) = \\prob(X\\in\\R) = \\prob\\big(\\big\\{\\omega:X(\\omega)\\in\\R\\big\\}\\big) = \\prob(\\Omega) = 1. \n\\]\nNext we show that $\\prob_X$ is countably additive. Let $B_1,B_2,\\ldots$ be a sequence of pairwise disjoint subsets of $\\R$. Then\n\\begin{align*}\n\\prob_X\\big(\\textstyle\\bigcup_{i=1}^{\\infty} B_i\\big)\n\t& = \\prob\\big(\\big\\{\\omega : X(\\omega)\\in \\textstyle\\bigcup_{i=1}^{\\infty} B_i\\big\\}\\big) \\\\\n\t& = \\prob\\big(\\textstyle\\bigcup_{i=1}^{\\infty} \\{\\omega : X(\\omega)\\in B_i\\}\\big) \\\\\n\t& = \\sum_{i=1}^{\\infty} \\prob\\big(\\{\\omega : X(\\omega)\\in B_i\\}\\big) \\quad\\text{because the $B_i$ are disjoint,} \\\\\n\t& = \\sum_{i=1}^{\\infty} \\prob_X(B_i),\n\\end{align*}\nas required.\n\\end{proof}\n\\end{theorem}\n\n\n%-----------------------------\n\\subsection{Indicator variables}\nEvery event can be represented by its \\emph{indicator} variable, which \\textit{indicates} whether or not the event occurs. Indicator variables provide an explicit link between random events and random variables. \n\n\\begin{definition}\\label{def:indicator}\nThe \\emph{indicator variable} of an event $A$ is the function $I_A:\\Omega\\to\\R$ defined by\n\\[\nI_A(\\omega) =\n  \\begin{cases}\n   1 & \\text{if } \\omega\\in A, \\\\\n   0 & \\text{if } \\omega\\notin A.\n  \\end{cases}\n\\]\n\\end{definition}\n\n\\begin{exercise}\nLet $A$ and $B$ be any two events. Show that $I_{A^c} = 1 - I_A$, $I_{A\\cap B} = I_A I_B$ and $I_{A\\cup B} = I_A + I_B - I_{A\\cap B}$. Note that two functions are equal if and only if they are equal at every point.\n\\end{exercise}\n\n\n%-----------------------------\n\\section{CDFs}\\label{sec:cdfs}\n\nA probability distribution $\\prob_X$ is uniquely determined by the values it takes on intervals of the form $(-\\infty, x\\,]$, and hence by its \\emph{cumulative distribution function} (CDF).\n\n%\\begin{definition}\n%The CDF of a random variable $X:\\Omega\\to\\R$ is the function\n%\\[\n%\\begin{array}{cccl}\n%F:\t& \\R\t& \\longrightarrow\t& [0,1] \\\\\n%\t& x \t\t\t& \\mapsto\t\t\t& \\prob(X\\leq x).\n%\\end{array}\n%\\]\n%\\end{definition}\n\n\\begin{definition}\nThe CDF of a random variable $X$ is the function $F:\\R\\to[0,1]$ given by\n\\[\nF(x) =  \\prob(X\\leq x).\n\\]\n\\end{definition}\n\n%\\begin{remark}\n%In the probability space $(\\R,\\prob_X)$, the measure of the interval $(a,b\\,]$ is\n%\\[\n%\\prob_X\\big[(a,b\\,]\\big] = \\prob(a < X\\leq b) = \\prob(X\\leq b)-\\prob(X\\leq a) \n%= F(b) - F(a).\n%\\]\n%Compare this to the usual measure of its length, $\\mathbb{L}\\big[(a,b\\,]\\big] = b - a$.\n%\\end{remark}\n\n%-----------------------------\n%\\subsection{Properties of CDFs}\n\nWe can use the properties of probability measures to derive some properties of CDFs. \n\n\\begin{theorem}[Properties of CDFs]\\label{thm:props_cdfs}\nLet $F:\\R\\to[0,1]$ be a CDF. Then\n\\ben\n\\it $F$ is an increasing function, \n\\it $F(x)\\to 0$ as $x\\to-\\infty$,\n\\it $F(x)\\to 1$ as $x\\to+\\infty$, and\n\\it $F(x+h)\\to F(x)$ as $h\\downarrow 0$ (right continuity).\n\\een\n\\end{theorem}\n\n\n\\begin{proof}\nLet $X:\\Omega\\to\\R$ be a random variable and let $F$ be its CDF.\n\\ben\n\\it % (i): increasing\nTo show that $F$ is increasing, let $x < y$ and consider the events $A = \\{X\\leq x\\}$ and $B = \\{X\\leq x'\\}$, i.e.\n\\[\nA\t= \\{\\omega: X(\\omega)\\leq x\\}\n\\quad\\text{and}\\quad\nB\t= \\{\\omega: X(\\omega)\\leq x'\\}.\n\\]\nBy construction, $F(x)=\\prob(A)$ and $F(x')=\\prob(B)$, and because $x < x'$ we have $A\\subseteq B$. By the monotonicity of probability measures, $\\prob(A)\\leq \\prob(B)$ or equivalently $F(x) \\leq F(x')$, so $F$ is an increasing function.\n\n\\it % (ii): F(x) -> 0 as x -> -\\infty\nTo show that $F(x)\\to 0$ as $x\\to-\\infty$, let $B_n = \\{X\\leq -n\\}$ for $n=1,2,\\ldots$. Then $F(-n)= \\prob(B_n)$, and $B_1,B_2,\\ldots$ is a decreasing sequence ($B_{n+1}\\subseteq B_n$), with \n\\[\n\\bigcap_{n=1}^{\\infty} B_n = \\emptyset.\n\\]\n(This is because for any $x$, there exists an $n$ such that $x\\notin (-\\infty,-n]$.) By the continuity of probability measures,\n\\[\n\\lim_{n\\to\\infty}F(-n) = \\lim_{n\\to\\infty}\\prob(B_n) = \\prob\\left(\\bigcap_{n=1}^n B_n\\right) = \\prob(\\emptyset) = 0.\n\\]\nBecause $F(x)$ is an increasing function, we conclude that $\\lim_{x\\to-\\infty}F(x)=0$.\n\n\n\\it % (iii): F(x) -> 1 as x -> \\infty\nTo show that $F(x)\\to 1$ as $x\\to\\infty$, let $A_n = \\{X\\leq n\\}$ for $n=1,2,\\ldots$. Then $F(n)= \\prob(A_n)$, and $A_1,A_2,\\ldots$ is an increasing sequence ($A_n\\subseteq A_{n+1}$), with \n\\[\n\\bigcup_{n=1}^{\\infty} A_n = \\Omega.\n\\]\n(This is because for any $x$, there exists an $n$ such that $x\\in (-\\infty,n]$).  By the continuity of probability measures,\n\\[\n\\lim_{n\\to\\infty}F(n) = \\lim_{n\\to\\infty}\\prob(A_n) = \\prob\\left(\\bigcup_{n=1}^{\\infty} A_n\\right) = \\prob(\\Omega) = 1,\n\\]\nBecause $F(x)$ is an increasing function, we conclude that $\\lim_{x\\to\\infty}F(x)=1$.\n\n\\it % (iv): right continuity\nTo show that $F(x)$ is right-continuous, let $B_n = \\{X\\leq x+1/n\\}$ for $n=1,2,\\ldots$. Then $F\\left(x+1/n\\right) = \\prob(B_n)$, and $B_1,B_2,\\ldots$ is a decreasing sequence ($B_{n+1}\\subseteq B_n$), with \\[\n\\bigcap_{n=1}^{\\infty} B_n = (-\\infty,x]. \n\\]\nBy the continuity of probability measures,\n\\[\nF(x) = \\prob\\left(\\bigcap_{n=1}^{\\infty} B_n\\right) = \\lim_{n\\to\\infty} \\prob(B_n) = \\lim_{n\\to\\infty}F\\left(x+\\frac{1}{n}\\right).\n\\]\nBecause $F(x)$ is an increasing function, we conclude that $\\lim_{h\\downarrow 0}F(x+h)=F(x)$.\n\\een\n\\end{proof}\n\n\\begin{exercise}\n%\\begin{questions}\n%\\question % GS 2.1.4\nIt can be shown that any function $F:\\R\\to[0,1]$ which has the four properties listed in Theorem~\\ref{thm:props_cdfs} is a CDF. With this in mind, show that if $F$ and $G$ are CDFs and $0<\\lambda<1$ is a constant, then $\\lambda F + (1-\\lambda)G$ is also a CDF.\n\\begin{answer}\nLet $H(x) = \\lambda F(x) + (1-\\lambda)G(x)$. \n\\ben\n\\it if $x < x'$ then \n\\[\nH(x) = \\lambda F(x) + (1-\\lambda)G(x) \\leq \\lambda F(x') + (1-\\lambda)G(x') = H(x').\n\\]\n\\it\n\\[\n\\lim_{x\\to-\\infty} H(x) \n\t= \\lim_{x\\to-\\infty}\\left[\\lambda F(x)+(1-\\lambda)G(x)\\right]\n\t=  \\lambda\\lim_{x\\to-\\infty} F(x) + (1-\\lambda)\\lim_{x\\to-\\infty} G(x) \n\t= 0.\n\\]\n\\it\n\\[\n\\lim_{x\\to\\infty} H(x) \n\t= \\lim_{x\\to\\infty}\\left[\\lambda F(x)+(1-\\lambda)G(x)\\right]\n\t=  \\lambda\\lim_{x\\to\\infty} F(x) + (1-\\lambda)\\lim_{x\\to\\infty} G(x) \n\t= \\lambda + (1-\\lambda)\n\t= 1.\n\\]\n\\it\n\\begin{align*}\n\\lim_{\\epsilon\\downarrow 0} H(x+\\epsilon) \n\t& = \\lim_{\\epsilon\\downarrow 0}\\left[\\lambda F(x+\\epsilon)+(1-\\lambda)G(x+\\epsilon)\\right] \\\\\n\t& = \\lambda\\lim_{\\epsilon\\downarrow 0} F(x+\\epsilon) + (1-\\lambda)\\lim_{\\epsilon\\downarrow 0} G(x+\\epsilon) \\\\\n\t& = \\lambda F(x) + (1-\\lambda)G(x) \n\t= H(x).\n\\end{align*}\n\\een\nThus $H$ satisfies the four properties of Theorem~\\ref{thm:props_cdfs}, and is therefore a CDF.\n\\end{answer}\n\n%\\question % GS 2.2.3\n%Let $X_1,X_2,\\ldots,X_n$ be independent and identically distributed random variables, and let $F$ denote their common CDF. If $F$ is unknown, find a way of estimating $F$ by considering the indicator variables of the events $\\{X_i\\leq x\\}$.\n%\\begin{answer}\n%Let $X$ be a random variable with same CDF, and let $I_i(x)$ the indicator variable of the event $\\{X_i\\leq x\\}$. Then\n%\\[\n%\\prob(X\\leq x) \\approx \\frac{1}{n}\\sum_{i=1}^{n} I_i(x),\n%\\]\n%which is the proportion of observations that are at most equal to $x$. This is called the \\emph{empirical CDF} of $X$.\n%\\end{answer}\n%\\end{questions}\n\\end{exercise}\n\n\n", "meta": {"hexsha": "422b08e56fb86980eaa69e19ab8a84b728f1a87a", "size": 9944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/03A_cdfs.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/03A_cdfs.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/03A_cdfs.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.314893617, "max_line_length": 401, "alphanum_fraction": 0.6415929204, "num_tokens": 3598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8947894534772126, "lm_q1q2_score": 0.6649788962681105}}
{"text": "\\chapter{Background}\\label{ch2}\n\nIn this chapter, the foundations of the thesis are elaborated. We formally define methods, concepts and tools used. Starting with the description of the 3D Morphable Model (3DMM) \\cite{Blanz:1999:MMS:311535.311556, Romdhani3DM} that we utilize, followed by an explanation of a novel fully probabilistic  method\nto interpret a single face image with the 3DMM\\cite{Schoenborn2017}. As well as, the important characteristics of the depth cameras. \n\n\\section{3D Morphable Model}\nThe 3DMM is a fully parametric generative face model constructed from 200 high quality face scans. The model contains probabilistic PCA (PPCA) models for shape, color and expression \\cite{8373814, EGGER2017115}.  In a traditional PCA-based settings the shape S, color C and facial expression E models are constructed through the parameter set $\\theta=\\{\\theta_S, \\theta_C, \\theta_E\\}$ as follows:\n\\begin{equation}\n    \\begin{split}\n    S(\\theta) &= \\mu_S + U_S D_S \\theta_S + \\mu_E + U_E D_E \\theta_E \\\\\n    C(\\theta) &= \\mu_C + U_C D_C\n    \\end{split}\n\\end{equation}\nWhere $\\mu$ denotes the mean of the corresponding model, $U$ is a matrix that contains the principal components, and $D$ denotes a diagonal matrix consisting of the variances along the principal directions. The expression model here, is modeled as a deformation of the neutral (mean) face shape. In a probabilistic setting the shape and color models are transformed into a distribution of shape $P(S \\mid \\theta)$ and color $P(C \\mid \\theta)$ components with the additive Gaussian noise\\cite{ALBRECHT2013959, EGGER2017115}:\n\n\\begin{equation}\n    \\begin{split}\n    P(S \\mid \\theta) &= \\mathcal{N}(S \\mid \\mu_S + U_S D_S \\theta_S + \\mu_E + U_E D_E \\theta_E, \\sigma_S^2 I) \\\\\n    P(C \\mid \\theta) &= \\mathcal{N}(C \\mid \\mu_C + U_C D_C, \\sigma_C^2 I)\n    \\end{split}\n\\end{equation}\n\nThe parameter set $\\theta$ follow a standard normal distribution in latent vector space\\cite{EGGER2017115} which is also defined outside the linear span of 200 scans:\n\n\\begin{equation}\n    P(\\theta) = \\mathcal{N}(\\theta \\mid 0, I)\n\\end{equation}\nTo generate realistic 3DMM instances (Figure \\ref{f2.1}) and render synthetic face images $\\mathcal{I}$, parameter set $\\theta$ contains an additional camera $\\theta_P$ and illumination $\\theta_L$ parameters that are modeled separately from the other three. \n\n\\begin{figure}\n    \\centering\n    \\captionsetup{labelformat=empty}\n    \\begin{minipage}{.32\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{Figures/Pictures/rs1_t.png}\n        \\caption*{Sample}\n      \\end{minipage}\n    \\begin{minipage}{.32\\textwidth}\n      \\centering\n      \\includegraphics[width=\\textwidth]{Figures/Pictures/mean_t.png}\n      \\caption*{Mean}\n    \\end{minipage}\n    \\begin{minipage}{.32\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{Figures/Pictures/rs2_expr_t.png}\n        \\caption*{Sample with expression}\n    \\end{minipage} \n      \\captionsetup{labelformat=default}   \n      \\caption{3DMM face model instances.}\n      \\label{f2.1}\n\\end{figure}\n\nThis allows us to synthesize the real world appearance of the face. By tuning all the mentioned parameters, we can approximate the appearance of the synthetic face to the target face. Besides parameter space, the model is also able to take care of the image rendering process $\\Re$ which renders an image $\\mathcal{I}(\\theta)$ based on given parameters through \n\\begin{equation}\n    \\mathcal{I}(\\theta) = \\Re(\\mathcal{M}(\\theta_S, \\theta_C, \\theta_E); \\theta_P, \\theta_L).\n\\end{equation}    \nThe 3DMM model also has a set of modified model versions that are either restricted to a certain region or are down-scaled, low-resolution versions\\footnote{Down-scaled versions usually have a lesser number of points and triangles hence are less flexible, but they perform the mesh operations faster} of the original model. The model restricted to a certain region is important for domain specific applications that only utilize specific parts of the model. For example, we use the model (Figure \\ref{f2.2}) from \\cite{Schoenborn2017} which only covers the face region and discards other parts like ears, neck, and part of the forehead. \n\n\\begin{figure}\n    \\centering\n    \\begin{minipage}{.32\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{Figures/Pictures/sideA_t.png}\n      \\end{minipage}\n      \\begin{minipage}{.33\\textwidth}\n          \\centering\n          \\includegraphics[width=\\textwidth]{Figures/Pictures/face_bfm_close_t.png}\n    \\end{minipage}\n    \\begin{minipage}{.32\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{Figures/Pictures/sideB_t.png}\n    \\end{minipage}\n    \\caption{Restricted face model displayed over the full model(dark)}\n    \\label{f2.2}\n\\end{figure}\n\nBeneficially to our application, this restriction also ignores parts of the model that are too complex, noisy or low quality, for example ears, that could potentially cause some problems during the fitting.\n\\section{Fitting Pipeline}\nHaving the flexible Parametric Appearance Model (PAM) as a basis of the fitting framework allows us to model a variety of real world scenes with challenging illumination conditions. In this section, we explain how standard fitting pipeline and its augmented variant utilizes Markov Chain Monte Carlo sampling to perform approximate inference.\\bigskip  \n\n\\subsection{Markov Chain Monte Carlo (MCMC)}\\label{s2.2.1}\nTo generate parametric face instances, the Analysis-by-Synthesis method employs a probabilistic image analysis using Bayesian inference. Formally, the fitting pipeline is a procedure that for any given face image returns a model fit which best corresponds to the face in the input image. It is important to note that commonly applications aim to obtain a single solution as a result, however, this is not the case for fitting pipeline. Instead of aiming for a single solution the fitting pipeline produces a posterior distribution of possible solutions. Since the true posterior distribution is unknown, the fitting process needs to approximate it. To perform approximate inference in this setting the Metropolis-Hastings (MH) algorithm is used. The algorithm is a method of Markov Chain Monte Carlo sampling and it is especially useful when sampling from distributions from which direct sampling is not feasible. The algorithm is an iterative process that draws random samples $\\theta'$ from a proposal distribution $Q(\\theta'\\mid\\theta)$ that are being evaluated based on their likelihood value. In the figure bellow single step of MH algorithm is shown.\\bigskip\n\n\\begin{algorithm}[H]\n    \\SetAlgoLined\n     $\\bullet$ Initialize sample $\\theta \\sim Q(\\theta)$\\;\n     $\\bullet$ Generate the next sample with current sample $\\theta$:\\\\\n     {\\addtolength{\\leftskip}{5mm}\n     1. Propose a sample $\\theta'$ based on current sample: $\\theta'\\sim Q(\\theta'\\mid\\theta)$\\;\n     2. With probability: $\\alpha = min\\Big\\lbrace\\frac{P(\\theta')}{P(\\theta)}\\frac{Q(\\theta\\mid\\theta')}{Q(\\theta'\\mid\\theta)}, 1\\Big\\rbrace$ accept or reject samples\\;\n\n      3. If sample $\\theta'$ is accepted set $\\theta'$ to be a new state $\\theta$, otherwise keep $\\theta$ unchanged\\; \n     }\n     \\caption{Metropolis-Hastings algorithm}\n     \\label{a1}\n\\end{algorithm}\\bigskip\n\nThe two principal parts of the algorithm are the proposal distribution $Q$ from which samples are drawn and the likelihood estimation $P(\\theta)$. Let us describe both of these key components in detail.  \\bigskip\n\nThe proposal distribution should be simple enough to draw random samples from it. In the settings of the fitting pipeline commonly used proposal distribution is a simple Gaussian random walk proposal distribution: \n\n\\begin{equation}\n   Q(\\theta'\\mid\\theta) = \\mathcal{N}(\\theta'\\mid\\theta, \\sigma^2 I_d). \n   \\label{2.5}\n\\end{equation}\n\nWhere $d$ stands for the dimension and $\\sigma$ controls the step size the algorithm makes at each sampling iteration. In the fitting pipeline we usually have more than one proposal distributions for each 3DMM parameter update $\\theta = \\{\\theta_S, \\theta_C, \\theta_E\\, \\theta_P, \\theta_L\\}$. Therefore, in practice, $Q(\\theta'\\mid\\theta)$ consists of multiple proposal distributions $Q_i$ combined into one mixture proposal distribution:\n\n\\begin{equation}\n    Q(\\theta' | \\theta) = \\sum_i c_i Q_i(\\theta'|\\theta), \\sum_i c_i = 1.\n    \\label{eq2.3}\n\\end{equation} \n\nWhere $\\theta$ is a current sample, $\\theta'$ is a newly proposed sample drawn from a proposal distribution $Q_i$, and $c_i$ coefficient controls how often samples are being drawn from the specific $Q_i$ distribution\\cite{Schoenborn2017}.\\bigskip\n\nThe second key part of the MH algorithm is a likelihood estimation term $P(\\theta)$ commonly written as $P(\\theta\\mid\\mathcal{I})$. It determines a posterior belief of the current sample parameter set $\\theta$ conditioned on the target image $\\mathcal{I}$. Computing the posterior directly is not possible, therefore, we employ the classical Bayes' theorem\\footnote{Bayes' theorem — \\url{https://en.wikipedia.org/wiki/Bayes'\\_theorem}} to approximate it based on the prior knowledge $P(\\theta)$ and an image likelihood $P(\\mathcal{I}\\mid\\theta)$:\n\n\\begin{equation}\n    P(\\theta \\mid \\mathcal{I}) = \\frac{P(\\theta)P(\\mathcal{I}\\mid \\theta)}{\\int P(\\mathcal{I}\\mid \\theta)P(\\theta)d\\theta}\n\\end{equation}\n\nIn this setting finding a single solution then becomes a problem of a maximum-a-posteriori (MAP) inference, which is finding the parameters with the highest posterior probability\\cite{10.1007/978-3-642-40602-7_11}. Since we are only interested in the ratio of two different likelihoods $P(\\theta\\mid\\mathcal{I})$ and $P(\\theta'\\mid\\mathcal{I})$ the normalization term can be ignored, and we can rewrite the above formulation as:\n\n\\begin{equation}\n    P(\\theta | \\mathcal{I}) \\propto P(\\theta)P(\\mathcal{I} | \\theta)\n    \\label{eq2.5}\n\\end{equation}\n\nThe prior probability $P(\\theta)$ of the model estimate $\\theta$ is usually defined as a normal distribution: \n\\begin{equation}\n    \\label{eq3}\n    P(\\theta) = \\mathcal N(\\theta | 0, \\mathcal I).\n\\end{equation}\n\nThe only missing part of the Equation \\ref{eq2.5} than is an image likelihood $P(\\mathcal{I}\\mid\\theta)$ which can be reformulated as $P(\\mathcal{I}\\mid\\theta) = \\mathcal{L}(\\theta;\\mathcal{I})$ with equation \\ref{eq2.5} transforming to:\n\n\\begin{equation}\n    \\label{eq2.5}\n    P(\\theta | \\tilde{\\mathcal I}) \\propto \\mathcal L(\\theta;\\tilde{\\mathcal I})P(\\theta)\n\\end{equation} \nAn image $\\mathcal{I}$ that appears in likelihood term means that during the fitting target image is treated as an observation of the 3DMM model instance.\nDepending on the phase the fitting pipeline is in, a combination of likelihood functions is used. We briefly discuss the most important likelihood functions used in the fitting pipeline alongside with the phase they are used in.   \n\n\\subsection{Landmark Fitting}\nDuring the starting phase of the fitting, it is important to have good pose estimation parameters since the pipeline is crucially dependent on it. If the pose is wrong, the rest of the model parameters cannot be inferred reliably. To deal with this problem, the standard fitting pipeline relies on the landmark fitting phase. During this phase fitting only modifies 3DMMs $\\theta_P$ and $\\theta_S$ parameters. It does so by evaluating a set of landmark point locations $x_i$ detected (by detection algorithm or manually) onto the target image and projected to the model instance using computer graphics. The projection method uses a pinhole camera model to align model instance to the target face by applying a rotation and translation parameters and then render individual landmarks onto the image plane. By treating those points as an observation of corresponding model points, the algorithm evaluates them using isotropic Gaussian likelihood function: \n\n\\begin{equation}\n\\mathcal L(\\theta; x_1, x_2,\\dots, x_N) = \\prod_{i=1}^{N} \\mathcal N(x_i\\mid y_i(\\theta), \\sigma^2_{LM} I_2) \\text{\\cite{Schoenborn2017}}.\n\\label{lmeval}\n\\end{equation}\n\nWhere $x_i$ are observed landmark positions and $y_i(\\theta)$ are model landmark positions based on $\\theta$. Proposed samples with new camera and shape parameters are getting accepted or rejected based on its likelihood value according to the procedure discussed earlier in Algorithm \\ref{a1}. Pose parameters that are part of $\\theta_P$ are a combination of Euler rotation angles \\textit{\\{yaw, nick, roll\\}}, translation vector $\\vec{t} = \\{t_x, t_y, t_z\\}$ with $t_z$ indicating the distance from the camera, and scaling parameter to control the focal length of the camera. The proposal distribution (Equation \n\\ref{eq2.3}) for landmark fitting consists of a mixture distribution over shape and camera (pose) parameter update proposals. As discussed previously, shape parameters $\\theta_S$ are PCA coefficients of the low-rank expansion of the Gaussian Process\\cite{8010438} model that are proposed by a weak isotropic Gaussian perturbation proposal\\cite{Schoenborn2017}.  The described process adjusts the pose and at the same time makes initial shape correction. Landmark fitting is usually a very fast process since the only few landmark points (usually less than 10) are getting evaluated at a time.\n\n\\subsection{Color Fitting}\n\nAfter the landmark fitting phase the pose of the model instance usually fits well with the target face in the image and the model instance is ready to be utilized for color, illumination and optionally expression proposals as well as shape update proposals. Thus, during the color fitting phase the mixture proposal $Q(\\theta'\\mid\\theta)$ will be a combination of all the above mentioned parameter proposals with various step size and drawing probability as of Equation \\ref{eq2.3}. To evaluate proposed samples in this phase the standard fitting pipeline together with landmark evaluation (Equation \\ref{lmeval}) relies on independent pixel evaluator likelihood which distinguishes foreground and background pixels\\cite{Schonborn:2015:BMG:2798342.2798359} and is formulated as follows:\n\n\\begin{equation}\n    \\mathcal L \\left (\\theta; \\tilde{\\mathcal I} \\right )\n= \\prod_{i \\in \\mathcal F} \\mathcal N \\left( \\tilde{\\mathcal I}_i \\,\\middle |\\, \\mathcal I_i(\\theta), \\sigma^2 I_3 \\right ) \\prod_{i \\in \\mathcal B} \\mathcal L_{\\text{BG}}\\left ( \\tilde{\\mathcal I}_i \\right ).\n\\label{eq2.7}\n\\end{equation}\n\nWhere the first product evaluates foreground pixels $i\\in\\mathcal F$ and second product evaluates background pixels $i\\in\\mathcal B$. The motivation behind incorporating background pixels into this likelihood and not ignoring them is that, when they are ignored, their likelihood value is assumed to be 1, which is not necessarily true in most cases. \\bigskip\n\nSo called propose-and-verify flow of the initial architecture of the Metropolis-Hastings algorithm used by \\cite{Schoenborn2017, Schoenborn2014} is shown in Figure \\ref{f2.3}. As we have mentioned previously, the architecture only uses color image and 2D landmarks as an input. \n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.85\\textwidth]{Figures/flow1.PNG}\n    \\caption{The architecture of the MH algorithm used by \\cite{Schoenborn2017} taken from \\cite{betschard2016}}.\n    \\label{f2.3}\n\\end{figure}\n\nAn augmented version of this flow by \\cite{betschard2016} can be seen in Figure \\ref{f2.4}, where authors introduced additional depth image and 3D landmark input sources, with respective evaluators. \\bigskip\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.85\\textwidth]{Figures/flow2.PNG}\n    \\caption{Augmented MH architecture proposed by \\cite{betschard2016}, changes made in the architecture are in bold.}\n    \\label{f2.4}\n\\end{figure}\n\nWe introduce an alternative way of dealing with this architecture. Instead of using just a depth image (only z-Buffer) we construct a triangle mesh from a point cloud obtained using the depth camera. Details of this process are described in Section \\ref{s3.3.3}. We were also forced to find a work-around way to obtain 3D landmarks (Section \\ref{s3.3.2}), since they are not provided by the camera SDK anymore. We split the standard fitting pipeline into two sub-fitting pipelines, one that deals with the shape and pose parameter estimation hereafter referred to as \\textit{shape fitting module} and the other with color, illumination, and expression with slight shape and pose parameter updates hereafter referred as \\textit{color fitting module}. Both of these modules are described in Section \\ref{s3.4}.\n\n\\section{Depth Camera}\n\nInferring the exact size of an object when analyzing color images is a challenging task, there is no effective way to reliably recover this information based on color intensities. The depth camera helps us to resolve this issue by providing a distance measure for each pixel (if it is available). There are a few different ways distance is obtained by the depth cameras. One of the algorithms commonly used (and the one our camera uses) to calculate distance is the depth from stereo algorithm better known as \\textbf{Stereoscopic Vision}\\footnote{\\url{https://en.wikipedia.org/wiki/Computer_stereo_vision}} which is a realization of a natural Binocular vision. The basic idea behind Stereoscopic vision is to estimate the distance from the camera to each point by calculating disparities between two parallel view-ports\\cite{serg, DBLP:journals/corr/KeselmanWGB17} (Figure \\ref{f2.5}). View-port parallelism is achieved with the traditional Image Rectification\\footnote{\\url{https://en.wikipedia.org/wiki/Image_rectification}} approach, which transforms images onto a common virtual image plane and makes sure that two view-port points are matching. \n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.55\\textwidth]{Figures/Pictures/stereo-ssd-1.png}\n    \\caption{Depth from stereo. Visualizing two separate view-ports that are being used to calculate disparities. Source: Intel}\n    \\label{f2.5}\n\\end{figure}\n \n\\subsection{De-projection}\nPixel-to-Point and Point-to-Pixel de-projection is a common use-case in computer vision. When needed this feature offers pixel to point mapping and vice-versa by relying on cameras' depth information and intrinsic parameters. Successful de-projection is based on the traditional pinhole camera model \\cite{Hartley:2003:MVG:861369} shown in Figure \\ref{f2.6}. \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{Figures/pcm.png}\n    \\caption{Pinhole camera model. $\\mathcal F_c$ is the center of the camera, (X, Y, Z) are coordinates of a 3D point in the world coordinate system, ($u$,$v$) are coordinates of a respective point projection in pixels, ($c_x, c_y$) indicates principal points usually located at the image center.  Source: \\url{https://docs.opencv.org}}\n    \\label{f2.6}\n\\end{figure}\n\n\nThe problem of point to pixel projection is formulated as follows. Given a 3D point coordinates $P_{3D}(X, Y, Z)$ with camera intrinsic parameters\\footnote{\\url{https://github.com/IntelRealSense/librealsense/blob/master/include/librealsense2/h/rs\\_types.h\\#L55}} containing ($width$, $height$, $ppx$, $ppy$, $f_x$, $f_y$), calculate the respective pixel coordinates $P(u, v)$ with no distortion introduced. Where in camera parameters, $width$ and $height$ are image dimensions in pixels, $ppx$ and $ppy$ are the horizontal and vertical coordinate of the principal point of the image given as an offset from the left and top edge respectively, and the $f_x$ and $f_y$ are the focal lengths of the image as a multiple of pixel width and height. The focal length is usually the distance from the center of the camera to the image plane also known as the focal plane. It is shown as gray square in Figure \\ref{f2.6}.  Once we have all these variables, then the $u$ and $v$ pixel coordinates of $P(u, v)$ are calculated as follows:\n\n\\begin{equation}\n    \\begin{split}\n    &x' = \\frac{X}{Z}\\\\\n    &y' = \\frac{Y}{Z}\\\\\n    &u = x' \\cdot f_x + ppx\\\\\n    &v = y' \\cdot f_y + ppy\\\\\n    \\end{split}\n\\end{equation}\n\nOn the other hand, the problem of de-projecting pixel coordinates into the 3D coordinate space to obtain a 3D point is formulated as follows. Given a pixel coordinates $P(u, v)$ and depth information $d = Z$ alongside the camera parameter set mentioned previously with no distortion introduced, compute the corresponding $P_{3D}(X, Y, Z)$ point in the 3D space. Then $P_{3D}(X, Y, Z)$ coordinates are being calculated as follows:\n\n\\begin{equation}\n    \\begin{split}\n    &x' = \\frac{u - ppx}{fx}\\\\\n    &y' = \\frac{v - ppy}{fy}\\\\\n    &X = d \\cdot x'\\\\\n    &Y = d \\cdot y'\\\\\n    &Z = d\n    \\end{split}\n\\end{equation}\n\nBoth techniques we have discussed are already implemented in the camera SDK for us, therefore, throughout the project, we make use of those default methods provided by the SDK.\n\n\n\n", "meta": {"hexsha": "7960dc6c28c9a5b4a0fa3579c4e593d1eb670a23", "size": 20843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Chapter2.tex", "max_stars_repo_name": "grigala/MScThesis", "max_stars_repo_head_hexsha": "d91ab383b264a0f9596cb43a54f5b29fb74b2cf7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-04T14:15:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-04T14:15:51.000Z", "max_issues_repo_path": "Chapters/Chapter2.tex", "max_issues_repo_name": "grigala/MScThesis", "max_issues_repo_head_hexsha": "d91ab383b264a0f9596cb43a54f5b29fb74b2cf7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-05-23T03:41:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-23T03:41:05.000Z", "max_forks_repo_path": "Chapters/Chapter2.tex", "max_forks_repo_name": "grigala/MScThesis", "max_forks_repo_head_hexsha": "d91ab383b264a0f9596cb43a54f5b29fb74b2cf7", "max_forks_repo_licenses": ["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.3177966102, "max_line_length": 1164, "alphanum_fraction": 0.7588638872, "num_tokens": 5330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6649788952255835}}
{"text": "%% NOTE: This section must follow the sections on Orthogonality\n\n\\section{Application: Raising a symmetric matrix to a high power}\n\nWe already have seen how to use matrix diagonalization to compute\npowers of matrices. This requires computing eigenvalues of the matrix\n$A$, and finding an invertible matrix of eigenvectors $P$ such that\n$P^{-1}AP$ is diagonal. In this section we will see that if the matrix\n$A$ is symmetric (see\nDefinition~\\ref{def:symmetric-and-antisymmetric}), then we can\nactually find such a matrix $P$ that is an orthogonal matrix of\neigenvectors. Thus $P^{-1}$ is simply its transpose $P^T$, and $P^TAP$\nis diagonal. When this happens we say that $A$ is \\textbf{orthogonally\n  diagonalizable}%\n\\index{matrix!orthogonally diagonalizable}.\n\nIn fact this happens if and only if $A$ is a symmetric matrix as shown\nin the following important theorem.\n\n\\begin{theorem}{Principal axis theorem}{principal-axis}\n  The following conditions are equivalent for an $n\\times n$-matrix\n  $A$:\n  \\begin{enumerate}\n  \\item $A$ is symmetric.\n  \\item $A$ has an orthonormal set of eigenvectors.\n  \\item $A$ is  orthogonally diagonalizable.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n  The complete proof is beyond this course, but to give an idea assume\n  that $A$ has an orthonormal set of eigenvectors, and let $P$ consist\n  of these eigenvectors as columns. Then $P^{-1}=P^T$, and $P^TAP=D$ a\n  diagonal matrix. But then $A=PDP^T$, and\n  \\begin{equation*}\n    A^T=(PDP^T)^T = (P^T)^TD^TP^T=PDP^T=A,\n  \\end{equation*}\n  so $A$ is symmetric.\n\n  Now given a symmetric matrix $A$, one shows that eigenvectors\n  corresponding to different eigenvalues are always orthogonal. So it\n  suffices to apply the Gram-Schmidt process on the set of basic\n  eigenvectors of each eigenvalue to obtain an orthonormal set of\n  eigenvectors.\n\\end{proof}\n\nWe demonstrate this in the following example.\n\n\\begin{example}{Orthogonal diagonalization of a symmetric matrix}{orthogonal-diagonalization}\n  Let $\\def\\arraystretch{1.2}A=\\begin{mymatrix}{rrr}\n    1 & 0 & 0 \\\\\n    0 & \\frac{3}{2} & \\frac{1}{2} \\\\\n    0 & \\frac{1}{2} & \\frac{3}{2}\n  \\end{mymatrix}$.  Find an orthogonal matrix $P$ such that $P^{T}AP$\n  is a diagonal matrix.\n\\end{example}\n\n\\begin{solution}\n  In this case, verify that the eigenvalues are 2 and 1. First we will\n  find an eigenvector for the eigenvalue $2$. This involves row\n  reducing the following augmented matrix:\n  \\begin{equation*}\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{ccc|c}\n      2 - 1 & 0 & 0 & 0 \\\\\n      0 & 2-\\frac{3}{2} & -\\frac{1}{2} & 0 \\\\\n      0 & -\\frac{1}{2} & 2-\\frac{3}{2} & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  The {\\rref} is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & 0 & 0 \\\\\n      0 & 1 & -1 & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix},\n  \\end{equation*}\n  and so an eigenvector is\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      0 \\\\\n      1 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Finally to obtain an eigenvector of length one (unit eigenvector) we\n  simply divide this vector by its length to yield:\n  \\begin{equation*}\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{c}\n      0 \\\\\n      \\frac{1}{\\sqrt{2}} \\\\\n      \\frac{1}{\\sqrt{2}}\n    \\end{mymatrix}.\n  \\end{equation*}\n  Next consider the case of the eigenvalue $1$. To obtain basic\n  eigenvectors, the matrix which needs to be row reduced in this case\n  is\n  \\begin{equation*}\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{ccc|c}\n      1-1 & 0 & 0 & 0 \\\\\n      0 & 1-\\frac{3}{2} & -\\frac{1}{2} & 0 \\\\\n      0 & -\\frac{1}{2} & 1-\\frac{3}{2} & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  The {\\rref} is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      0 & 1 & 1 & 0 \\\\\n      0 & 0 & 0 & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the eigenvectors are of the form\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      s \\\\\n      -t \\\\\n      t\n    \\end{mymatrix}.\n  \\end{equation*}\n  Note that all these vectors are automatically orthogonal to\n  eigenvectors corresponding to the first eigenvalue. This follows\n  from the fact that $A$ is symmetric, as mentioned earlier.\n  We obtain basic eigenvectors\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      0 \\\\\n      0\n    \\end{mymatrix} \\text{ and }\\begin{mymatrix}{r}\n      0 \\\\\n      -1 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since they are themselves orthogonal (by luck here) we do not need\n  to use the Gram-Schmidt process and instead simply normalize these\n  vectors to obtain\n  \\begin{equation*}\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      0 \\\\\n      0\n    \\end{mymatrix} \\text{ and }\\begin{mymatrix}{c}\n      0 \\\\\n      -\\frac{1}{\\sqrt{2}} \\\\\n      \\frac{1}{\\sqrt{2}}\n    \\end{mymatrix}.\n  \\end{equation*}\n  An orthogonal matrix $P$ to orthogonally diagonalize $A$ is then\n  obtained by letting these basic vectors be the columns.\n  \\begin{equation*}\n    \\def\\arraystretch{1.3}\n    P= \\begin{mymatrix}{ccc}\n      0 & 1 & 0 \\\\\n      -\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n      \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}}\n    \\end{mymatrix}.\n  \\end{equation*}\n  We verify this works. $P^{T}AP$ is of the form\n  \\begin{equation*}\n    \\def\\arraystretch{1.3}\n    \\begin{mymatrix}{ccc}\n      0 & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\n      \\\\\n      1 & 0 & 0 \\\\\n      0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\n    \\end{mymatrix} \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & \\frac{3}{2} & \\frac{1}{2} \\\\\n      0 & \\frac{1}{2} & \\frac{3}{2}\n    \\end{mymatrix} \\begin{mymatrix}{ccc}\n      0 & 1 & 0 \\\\\n      -\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n      \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}}\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    =\\allowbreak \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 2\n    \\end{mymatrix},\n  \\end{equation*}\n  which is the desired diagonal matrix.\n\\end{solution}\n\nWe can now apply this technique to efficiently compute high powers of\na symmetric matrix.\n\n\\begin{example}{Powers of a symmetric matrix}{powers-symmetric-matrix}\n  Let $\\def\\arraystretch{1.2}\n  A=\\begin{mymatrix}{rrr}\n    1 & 0 & 0 \\\\\n    0 & \\frac{3}{2} & \\frac{1}{2} \\\\\n    0 & \\frac{1}{2} & \\frac{3}{2}\n  \\end{mymatrix}$.\n  Compute $A^7$.\n\\end{example}\n\n\\begin{solution}\n  We found in Example~\\ref{exa:orthogonal-diagonalization} that\n  $P^TAP=D$ is diagonal, where\n  \\begin{equation*}\n    \\def\\arraystretch{1.3}\n    P= \\begin{mymatrix}{ccc}\n      0 & 1 & 0 \\\\\n      -\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n      \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}}\n    \\end{mymatrix} \\text{ and }\n    D = \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 2\n    \\end{mymatrix}.\n  \\end{equation*}\n  Thus $A=PDP^T$ and $A^7=PDP^T \\; PDP^T \\; \\cdots PDP^T = PD^7P^T$\n  which gives:\n  \\begin{equation*}\n    \\def\\arraystretch{1.3}\n    \\begin{array}{rr}\n      A^7 & =\n            \\begin{mymatrix}{ccc}\n              0 & 1 & 0 \\\\\n              -\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n              \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}}\n            \\end{mymatrix}\n            \\begin{mymatrix}{ccc}\n              1 & 0 & 0 \\\\\n              0 & 1 & 0 \\\\\n              0 & 0 & 2\n            \\end{mymatrix} ^7\n            \\begin{mymatrix}{ccc}\n              0 & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\\\\n              1 & 0 & 0 \\\\\n              0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\n            \\end{mymatrix}  \\\\\\\\[-2ex]\n          & =\n            \\begin{mymatrix}{ccc}\n              0 & 1 & 0 \\\\\n              -\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n              \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}}\n            \\end{mymatrix}\n            \\begin{mymatrix}{ccc}\n              1 & 0 & 0 \\\\\n              0 & 1 & 0 \\\\\n              0 & 0 & 2^7\n            \\end{mymatrix}\n            \\begin{mymatrix}{ccc}\n              0 & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\\\\n              1 & 0 & 0 \\\\\n              0 & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\n            \\end{mymatrix}  \\\\\\\\[-2ex]\n          & =\n            \\begin{mymatrix}{ccc}\n              0 & 1 & 0 \\\\\n              -\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n              \\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}}\n            \\end{mymatrix}\n            \\begin{mymatrix}{ccc}\n              0 & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\\\\n              1 & 0 & 0 \\\\\n              0 & \\frac{2^7}{\\sqrt{2}} & \\frac{2^7}{\\sqrt{2}}\n            \\end{mymatrix}  \\\\\\\\[-2ex]\n          & =\n            \\begin{mymatrix}{ccc}\n              1 & 0 & 0 \\\\\n              0 & \\frac{2^7+1}{2} & \\frac{2^7-1}{2}\\\\\n              0 & \\frac{2^7-1}{2} & \\frac{2^7+1}{2}\n            \\end{mymatrix}.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "bee261291f2f3a4308df62f353e3509f582e351c", "size": 8786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationPowerSymmetric.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/spectraltheoryApplicationsDiagonalizationPowerSymmetric.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/spectraltheoryApplicationsDiagonalizationPowerSymmetric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.7184115523, "max_line_length": 93, "alphanum_fraction": 0.553152743, "num_tokens": 3254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743167997235783, "lm_q2_score": 0.8947894555814343, "lm_q1q2_score": 0.6649788876521511}}
{"text": "\n\\section{Manual labelling of sharp-wave ripples}\n\n\nIn this section, we assess the amount of consensus between the scientists asked to label potential SWR events.\n\nA popular measure to quantify the agreement between two labellers is \\emph{Cohen's $\\kappa$}. It measures the proportion of events that are given the same label by both labellers (denoted by $p_o$), corrected by the expected proportion of events that are given the same label by chance (denoted by $p_e$). $\\kappa \\in [-1, 1]$ is defined as:\n\\begin{equation}\n\\kappa = \\frac{p_o - p_e}{1 - p_e},\n\\end{equation}\n%\nwhere $p_o$ and $p_e$ are estimated as in \\cite{McHugh2012}.\n\n\\begin{figure}\n\\img[1.2]{labellers_A}\n\\captionn{Example of scientist decisions}{Time series are two representative channels of the labelled LFP data. Each cluster of one to five vertical lines marks a candidate event. The colored lines indicate which labellers marked this event as a true SWR event (colors correspond to \\cref{fig:upset}). Grey lines indicate events that were marked by no-one as a true SWR event. See \\cref{fig:labellers_B} for additional examples.}\n\\label{fig:labellers_A}\n\\end{figure}\n\n\\begin{figure}\n    \\begin{subfigure}{0.6\\textwidth}\n    \\img{overlap}\n    \\end{subfigure}\n    \\begin{subfigure}{0.5\\textwidth}\n    \\vspace{4em}\n    \\begin{tabular}{r|l l l l l}\n    $N_\\text{accepted}$ & FK   & FM   & CK   & DC  & JS  \\\\ \\hline\n    Common set          & 111  & 137  & 147  & 78  & 151 \\\\\n    Personal set        & 112  & 101  & 123  & 92  & 111\n    \\end{tabular} \\\\[4em]\n    \\begin{tabular}{r|l l l l}\n    $\\kappa$ &  FM   & CK    & DC    & JS     \\\\ \\hline\n    FK       &  0.71 & 0.62  & 0.64  & 0.57   \\\\\n    FM       &       & 0.76  & 0.45  & 0.67   \\\\\n    CK       &       &       & 0.36  & 0.83   \\\\\n    DC       &       &       &       & 0.34\n    \\end{tabular}\n    \\end{subfigure}\n\\captionn{Labeller agreement}{Left: Agreement between the neuroscientists (denoted by their initials) asked to label potential SWR events. Each row represents the set of events that were given the same label by the neuroscientists that have a colored marker in that row. (Visualised using \\cite{Lex2014}). Top right: number of candidate events labelled as `true SWR events' by each neuroscientist, for both the set of events labelled by all neuroscientists (`Common set'), and the sets of events labelled only by one neuroscientist (`Personal set'). Each of these sets contained 200 candidate events in total. Bottom right: Cohen's $\\kappa$ for each pair of neuroscientists.}\n\\label{fig:upset}\n\\end{figure}\n", "meta": {"hexsha": "f7503c8f4df897412b0ccc0940982806acfee52b", "size": 2554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Scraps/Manual.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/Scraps/Manual.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/Scraps/Manual.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": 60.8095238095, "max_line_length": 675, "alphanum_fraction": 0.6789350039, "num_tokens": 763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.664972655079723}}
{"text": "\\documentclass[]{report}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{bm}\n\\usepackage{graphicx}\n\\usepackage{listings}\n\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks=true,\n    linkcolor=blue,\n    filecolor=magenta,      \n    urlcolor=cyan,\n}\n\n\\graphicspath{ {images/} }\n\n\\title{CSCI 567 HW \\# 6}\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\\[ J = \\frac{1}{N} \\sum_{i=1}^N {(x_i - p_{i1} e_1 - p_{i2} e_2)}^T (x_i - p_{i1} e_1 - p_{i2} e_2) \\]\n\tTaking the derivative w.r.t $p_{i2}$\n\t\\[ \\frac{\\partial{J}}{\\partial{p_{i2}}} = \\frac{1}{N} 2  (- e_2^T) (x_i - p_{i1} e_1 - p_{i2} e_2) = 0\\]\n\t\\[ = -e_2^T x_i + p_{i1} e_2^T e_1 + p_{i2} e_2^T e_2 = 0\\]\n\n\tSince, we know that $e_2^T e_1 = 0$ and $ {\\|e_2\\|}_2 = e_2^T e_2 = 1$, we get\n\t\\[ = p_{i2} - e_2^T x_i = 0 \\]\n\t\\[ p_{i2} = e_2^T x_i \\]\n\n\\paragraph{Sol. 1.2}\n\tGiven \n\t\\[ \\tilde{J} = -e_2^T S e_2 + \\lambda_2 {(e_2^T e_2 - 1)}  + \\lambda_{12} {(e_2^T e_1 - 0)} \\]\n\tTaking the derivative w.r.t $e_{2}$, we get \n\t\\begin{equation}\n\t\t \\frac{\\partial{\\tilde{J}}}{\\partial{e_2}} = -(S + S^T)e_2 + 2 \\lambda_2 e_2 + \\lambda_{12}e_1 = 0\n\t\\end{equation}\n\tSince, $S$ is symmetric, i.e. $S = S^T$, we get \n\t\\[ -2Se_2 + 2\\lambda_2 e_2 + \\lambda_{12} e_1 = 0\\]\n\tmultiplying with $e_1^T$ form left, we get \n\t\\[ -2 e_1^T S e_2 + 2 \\lambda_2 e_1^T e_2 + \\lambda_{12} e_1^T e_1  = 0 \\]\n\tsince, $ e_1^T e_2  = 0$ and $e_1^T e_1 = 1$\n\t\\[ -2 {(Se_1)}^T e_2 + \\lambda_{12} = 0\t\\]\n\tWe also know, that ${(Se_1)}^T e_2 = 0$ because $ e_1^T e_2  = 0$, hence \n\t\\[ \\lambda_{12} = 0\\]\n\tand therefore from equation (1), we get \n\t\\[ Se_2 = \\lambda_2 e_2 \\]\n\tand this proves that the value of $e_2$ which minimizes $\\tilde{J}$ is given by the second largest eigen vector of $S$.\n\n\\paragraph{Sol. 1.3}\n\tUsing \\href{https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eig.html}{numpy.linalg.eig}, we get the following eigenvalues\n\t\\[\\lambda_1 = 1626.5264,\\quad \\lambda_2 = 128.9860,\\quad \\lambda_3 = 7.0974 \\]\n\tand the following eigenvectors\n\t\\[ \n\t\tv_1 = \\begin{bmatrix}\n\t\t\t\t0.2179\\\\\n\t\t\t\t0.4144\\\\\n\t\t\t\t0.8835\n\t\t\t\\end{bmatrix}\n\t\\]\\[\t\n\t\tv_2 = \\begin{bmatrix}\n\t\t\t-0.2466 \\\\\n\t\t\t-0.8525 \\\\\n\t\t\t0.4607\n\t\t\\end{bmatrix}\n\t\\]\\[\t\n\t\tv_3 = \\begin{bmatrix}\n\t\t\t0.9442 \\\\\n\t\t\t-0.3183\\\\\n\t\t\t-0.0835\n\t\t\\end{bmatrix}\n\t\\]\n\n\n\\paragraph{Sol. 1.4}\n\tYes, we can omit the direction of the vector $v_3$, since $\\lambda_1$ and $\\lambda_2$ account for most the information. It can be shown that\n\tfor $\\lambda_1$, $\\frac{\\lambda_1}{\\lambda_1 + \\lambda_2 + \\lambda_2} = 0.9227$, i.e. $\\lambda_1$ is account for ~92.28\\% of the information and for \n\t$\\lambda_2$, $\\frac{\\lambda_2}{\\lambda_1 + \\lambda_2 + \\lambda_2} = 0.0731$, i.e. $\\lambda_2$ is account for ~7.32\\% of the information, which makes $\\lambda_3$\n\taccount for only ~0.4\\% for the information, and hence can be omitted.\n\n\n\\paragraph{Sol. 1.5}\n\tFor $v_1$, since all the elements of the vector have the same sign, it suggest that all the attributes increase and decrease w.r.t to each other, i.e. for example if the bird has large length, then it will also have large wing span and a higher weight and vice versa. This makes sense since, a large bird will tend to have all three attributes larger than a small bird.\n\n\\paragraph{Sol. 2.1}\n\tTo calculate $P(O;\\theta)$, we first calculate the following\n\t\\[ \\alpha_1(1) = \\pi_1 \\times b_{1A}  = 0.6 \\times 0.4 = 0.24 \\]\n\t\\[ \\alpha_1(2) = \\pi_2 \\times b_{2A}  = 0.4 \\times 0.2 = 0.08 \\]\n\t\n\t\\[ \\alpha_2(1) = b_{1C} (\\alpha_1 (1) a_{11} + \\alpha_1(2) a_{21}) = 0.2 \\times (0.24 \\times 0.7 + 0.08 \\times 0.4) = 0.04 \\]\n\t\\[ \\alpha_2(2) = b_{2C} (\\alpha_1 (1) a_{12} + \\alpha_1(2) a_{22}) = 0.4 \\times (0.24 \\times 0.3 + 0.08 \\times 0.6) = 0.048 \\]\n\n\t\\[ \\alpha_3(1) = b_{1C} (\\alpha_2 (1) a_{11} + \\alpha_2(2) a_{21}) = 0.2 \\times (0.04 \\times 0.7 + 0.048 \\times 0.4) = 0.00944 \\]\n\t\\[ \\alpha_3(2) = b_{2C} (\\alpha_2 (1) a_{12} + \\alpha_2(2) a_{22}) = 0.4 \\times (0.04 \\times 0.3 + 0.048 \\times 0.6) = 0.01632 \\]\n\n\t\\[ \\alpha_4(1) = b_{1G} (\\alpha_3 (1) a_{11} + \\alpha_3 (2) a_{21}) = 0.3 \\times (0.00944 \\times 0.7 + 0.01632 \\times 0.4) = 0.0039408 \\]\n\t\\[ \\alpha_4(2) = b_{2G} (\\alpha_3 (1) a_{12} + \\alpha_3(2) a_{22}) = 0.1 \\times (0.00944 \\times 0.3 + 0.01632 \\times 0.6) = 0.0012624 \\]\n\n\t\\[ \\alpha_5(1) = b_{1T} (\\alpha_4 (1) a_{11} + \\alpha_4 (2) a_{21}) = 0.1 \\times (0.0039408 \\times 0.7 + 0.0012624 \\times 0.4) = 0.000326352 \\]\n\t\\[ \\alpha_4(2) = b_{2T} (\\alpha_4 (1) a_{12} + \\alpha_4(2) a_{22}) = 0.3 \\times (0.0039408 \\times 0.3 + 0.0012624 \\times 0.6) = 0.000581904 \\]\t\n\n\t\\[ \\alpha_6(1) = b_{1A} (\\alpha_5 (1) a_{11} + \\alpha_5 (2) a_{21}) = 0.4 \\times (0.000326352 \\times 0.7 + 0.000581904 \\times 0.4) = 0.0001844832 \\]\n\t\\[ \\alpha_6(2) = b_{2A} (\\alpha_5 (1) a_{12} + \\alpha_5 (2) a_{22}) = 0.2 \\times (0.000326352 \\times 0.3 + 0.000581904 \\times 0.6) = 0.0000894096 \\]\t\n\tFinally,  \n\t\\[ P(O;\\theta) = \\alpha_6(1) + \\alpha_6(2) = 0.0001844832 + 0.0000894096 = 0.0002738928 \\]\n\n\\paragraph{Sol. 2.2}\n\tTo calculate $P(X_6 = S_i|O;\\theta)$, we first calculate the following\n\t\\[ \\beta_6(1) = 1 \\]\n\t\\[ \\beta_6(2) = 1 \\]\n\n\t\\[ \\beta_5(1) = (b_{1A}a_{11}\\beta_6(1) + b_{2A}a_{12}\\beta_6(2)) =  0.34\\]\n\t\\[ \\beta_5(2) = (b_{1A}a_{21}\\beta_6(1) + b_{2A}a_{22}\\beta_6(2)) =  0.28\\]\n\n\t\\[ \\beta_4(1) = (b_{1T}a_{11}\\beta_5(1) + b_{2T}a_{12}\\beta_5(2)) =  0.049 \\]\n\t\\[ \\beta_4(2) = (b_{1T}a_{21}\\beta_5(1) + b_{2T}a_{22}\\beta_5(2)) =  0.064 \\]\n\n\t\\[ \\beta_3(1) = (b_{1G}a_{11}\\beta_4(1) + b_{2G}a_{12}\\beta_4(2)) =  0.01221\\]\n\t\\[ \\beta_3(2) = (b_{1G}a_{21}\\beta_4(1) + b_{2G}a_{22}\\beta_4(2)) =  0.00972\\]\n\n\t\\[ \\beta_2(1) = (b_{1C}a_{11}\\beta_3(1) + b_{2C}a_{12}\\beta_3(2)) =  0.0028758\\]\n\t\\[ \\beta_2(2) = (b_{1C}a_{21}\\beta_3(1) + b_{2C}a_{22}\\beta_3(2)) =  0.0033096\\]\n\n\t\\[ \\beta_1(1) = (b_{1C}a_{11}\\beta_2(1) + b_{2C}a_{12}\\beta_2(2)) =  0.000799764\\]\n\t\\[ \\beta_1(2) = (b_{1C}a_{21}\\beta_2(1) + b_{2C}a_{22}\\beta_2(2)) =  0.001024368\\]\n\n\t\\[ P(X_6 = S_1 | O;\\theta) = \\frac{\\alpha_6(S_1) \\beta_6(S_1)}{\\alpha_6(S_1) \\beta_6(S_1) + \\alpha_6(S_2) \\beta_6(S_2)} \\]\n\t\\[  = \\frac{0.0001844832 \\times 1}{0.0001844832 \\times 1 + 0.0000894096 \\times 1}\\]\n\t\\[ = 0.67355987452 \\]\n\n\t\\[ P(X_6 = S_2 | O;\\theta) = 1 - P(X_6 = S_1 | O;\\theta) \\]\n\t\\[ = 1 - 0.67355987452 = 0.32644012548 \\]\n\n\\paragraph{Sol. 2.3}\n\t\\[ P(X_4 = S_1 | O;\\theta) = \\frac{\\alpha_4(S_1) \\beta_4(S_1)}{\\alpha_4(S_1) \\beta_4(S_1) + \\alpha_4(S_2) \\beta_4(S_2)} \\]\n\t\\[  = \\frac{0.0039408 \\times 0.049}{0.0039408 \\times 0.049 + 0.0012624 \\times 0.064}\\]\n\t\\[ = 0.70501743747 \\]\n\n\t\\[ P(X_4 = S_2 | O;\\theta) = 1 - P(X_4 = S_1 | O;\\theta) \\]\n\t\\[ = 1 - 0.70501743747 = 0.29498256253 \\]\n\n\n\\paragraph{Sol. 2.4}\n\t\\[ P(X_1 = S_1 | O;\\theta) = \\frac{0.24 \\times 0.000799764}{0.24 \\times 0.000799764 + 0.08 \\times 0.001024368 } = 0.70079739226 \\]\n\t\\[ P(X_1 = S_2 | O;\\theta) = 0.29920260773  \\]\n\n\t\\[ P(X_2 = S_1 | O;\\theta) = \\frac{0.04 \\times 0.0028758}{0.04 \\times 0.0028758 + 0.048 \\times 0.0033096 } = 0.41998913443 \\]\n\t\\[ P(X_2 = S_2 | O;\\theta) = 0.58001086556 \\]\n\n\t\\[ P(X_3 = S_1 | O;\\theta) =  \\frac{0.00944 \\times 0.01221}{0.00944 \\times 0.01221 + 0.01632 \\times 0.00972 } = 0.42083033946 \\]\n\t\\[ P(X_3 = S_2 | O;\\theta) = 0.57916966053\\]\n\n\t\\[ P(X_4 = S_1 | O;\\theta) =  0.70501743747\\]\n\t\\[ P(X_4 = S_2 | O;\\theta) = 0.29498256253  \\]\n\n\t\\[ P(X_5 = S_1 | O;\\theta) =  \\frac{0.000326352 \\times 0.34}{0.000326352 \\times 0.34 + 0.000581904 \\times 0.28} = 0.40512083559 \\]\n\t\\[ P(X_5 = S_2 | O;\\theta) = 0.5948791644 \\]\n\n\t\\[ P(X_6 = S_1 | O;\\theta) = 0.67355987452 \\]\n\t\\[ P(X_6 = S_2 | O;\\theta) = 0.32644012548 \\]\n\n\tSo, the most likely sequence is \n\t\\[ S_1 S_2 S_2 S_1 S_2 S_1\\]\n\n\\paragraph{Sol. 2.4}\n\t\\[ P(O_7 = A | O; \\theta) = P(X_6 = S_1| O; \\theta) \\times b_{1A} +  P(X_6 = S_2| O; \\theta) \\times b_{2A} \\] \\[ = 0.67355987452 \\times 0.4 + 0.32644012548 \\times 0.2 = 0.3347119749\\]\n\t\n\t\\[ P(O_7 = T | O; \\theta) = P(X_6 = S_1| O; \\theta) \\times b_{1T} +  P(X_6 = S_2| O; \\theta) \\times b_{2T} \\] \\[ = 0.67355987452 \\times 0.1 + 0.32644012548 \\times 0.3 = 0.16528802509\\]\n\t\n\t\\[ P(O_7 = G | O; \\theta) = P(X_6 = S_1| O; \\theta) \\times b_{1G} +  P(X_6 = S_2| O; \\theta) \\times b_{2G} \\] \\[ = 0.67355987452 \\times 0.3 + 0.32644012548 \\times 0.1 = 0.2347119749\\]\n\t\n\t\\[ P(O_7 = C | O; \\theta) = P(X_6 = S_1| O; \\theta) \\times b_{1C} +  P(X_6 = S_2| O; \\theta) \\times b_{2C} \\] \\[ = 0.67355987452 \\times 0.2 + 0.32644012548 \\times 0.4 = 0.26528802509\\]\n\t\n\t \\[ O_7 = argmax_O P(O|O; \\theta) = A \\]\n\\end{document}", "meta": {"hexsha": "2e91dd357301241698cb95e4857a2dd2677e52da", "size": 8457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2-6/HW6/hw6.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/HW6/hw6.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/HW6/hw6.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": 46.7237569061, "max_line_length": 370, "alphanum_fraction": 0.5915809389, "num_tokens": 4219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8774767986961401, "lm_q1q2_score": 0.6649469885755863}}
{"text": "\n\\section{Carrier-Greenspan periodic solution}\n\nPeriodic solutions for flows on a sloping beach were proposed by Carrier and Greenspan~\\cite{CG1958}. The solutions have been widely used to test the performance of numerical methods used to solve the shallow water equations~\\cite{Johns1982,MR2012CG}.\n\nThis test can be described in dimensional and dimensionless equations. For our reference, please note that dimensional quantities shall be denoted by starred variables, while dimensionless quantities by unstarred variables for brevity of our analytical presentation. This notational convention is used only in this test.\n\nThe problem is set up as follows. Consider a one dimensional domain through the $x^*$-axis. Recall the shallow water equations\n\\begin{equation} \\label{eq:mass_app}\nh^*_{t^*} +\\left(h^*u^*\\right)_{x^*}=0\\,,\n\\end{equation}\n\\begin{equation} \\label{eq:mom_app}\n\\left(h^*u^*\\right)_{t^*}+\\left(h^*{u^*}^2+\\frac{1}{2}g{h^*}^2\\right)_{x^*}=-gh^* z^*_{x^*}\\,.\n\\end{equation}\nHere,\n$x^*$ represents the one-dimensional domain,\n$t^*$ is the time variable,\n$u^*=u^*(x^*,t^*)$ represents the velocity,\n$z^*=z^*(x^*)$ denotes the water bed topography (elevation),\n$h^*=h^*(x^*,t^*)$ denotes the height (water depth), that is, the distance from the free surface to the water bed topography, and\n$g$ is the acceleration due to gravity.\nNow, consider the situation on a sloping beach. The topography changes linearly with $x^*$\n\\begin{equation}\nz^*=(h_0^*/L^*)x^*-h_0^*\\,,\n\\end{equation}\nin which $h_0^*$ is the vertical distance from the origin $O$ to the topography at any time, and $L^*$ is the horizontal distance from the origin $O$ to the topography when the water is still. This implies that when the water is still: $z^*=-h^*$ over the spatial domain, $z^*=-h_0^*$ at $x^*=0$\\,, and the position of the shoreline is $x^*=L^*$\\,. More detailed descriptions are given by Mungkasi and Roberts~\\cite{MR2012CG}.\n\n\n\nThe free surface or called stage is defined by $w^*:=h^*+z^*$\\,.\nScaling the horizontal distance by $L^*$\\,, the vertical distance by $h_0^*$\\,, the time by $L^*/\\sqrt{gh_0^*}$\\,, and the velocity by $\\sqrt{gh_0^*}$\\,, the nonconservative dimensionless shallow water equations can be expressed as\n\\begin{equation} \\label{eq:mass1_app}\nw_t + \\left[ \\left( w+1-x  \\right)u  \\right]_{x} = 0\\,,\n\\end{equation}\n\\begin{equation} \\label{eq:mom1_app}\nu_t + u u_x + w_{x} = 0\\,.\n\\end{equation}\nFor smooth solutions, equations (\\ref{eq:mass1_app}) and (\\ref{eq:mom1_app}) are equivalent to the conservative dimensionless shallow water wave equations\n\\begin{equation}\nh_t + \\left( hu \\right)_x = 0\\,,\n\\end{equation}\n\\begin{equation}\n\\left(hu\\right)_t + \\left( hu^2 + \\frac12 h^2  \\right)_x = -h z_x\\,.\n\\end{equation}\n\n\nCarrier and Greenspan showed that\n\\begin{equation} \\label{eq:w_johns_full}\nw = - \\frac12 u^2 + \\mathcal{A} J_0 \\left( \\frac{4 \\pi \\sqrt{ w+1-x}}{T} \\right) \n\\cos{\\left(\\frac{2 \\pi \\left( u+t \\right)}{T}\\right)}\\,,\n\\end{equation}\n\\begin{equation} \\label{eq:u_johns_full}\nu = - \\frac{\\mathcal{A}J_1\\left( \\frac{4 \\pi \\sqrt{w+1-x}}{T}  \\right)}{\\sqrt{w+1-x}}\n \\sin{\\left( \\frac{2 \\pi \\left(u+t \\right)}{T}  \\right)}\\,\n\\end{equation}\nsatisfies the shallow water equations. This was verified by Johns~\\cite{Johns1982} as well as Mungkasi and Roberts~\\cite{MR2012CG}. Equations (\\ref{eq:w_johns_full}) and (\\ref{eq:u_johns_full}) are the Carrier--Greenspan periodic solutions for flows on a sloping beach, which are written in the dimensionless form. Obviously, this can be rescalled back to the dimensional form.\n\n\nBecause this solution is periodic, the initial condition can be set by substituting $t=0$ into the analytical solution (\\ref{eq:w_johns_full}) and (\\ref{eq:u_johns_full}).\n\n\n\\subsection{Results}\n\nWe consider a spatial domain given by the interval $[-50, 55050]$\\,. The dimensional length is $L^*=50,000$\\,, dimensional height $h_0^*=500$\\,, and dimensional period $T^*=900$\\,. At $x^*=0$ the dimensional amplitude is $\\epsilon^*=1.0$\\,. After four cycles, periodic motions are clear.\n\nThe following figures show the stage, $x$-momentum, and $x$-velocity at several instants of time through a cross-section of the domain. Perturbation at the zero point of the spatial domain is also shown.\nWe should see excellent agreement between the analytical and numerical 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\\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\\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\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{perturbation_at_origin.png}\n\\end{center}\n\\caption{Perturbation at the origin}\n\\end{figure}\n\n\n\\endinput\n", "meta": {"hexsha": "bb8457337d05b25ecc530838f17c433139d34014", "size": 4898, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "validation_tests/analytical_exact/carrier_greenspan_periodic/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/carrier_greenspan_periodic/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/carrier_greenspan_periodic/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": 48.98, "max_line_length": 426, "alphanum_fraction": 0.7260106166, "num_tokens": 1556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312006227324, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.6649312829021706}}
{"text": "\\section{Convergence of Sequences and Series}\r\n\\subsection{Sequence}\r\n\\begin{definition}\r\n    Let $X$ be a set, then a sequence in $X$ is a function $f:\\mathbb N\\to X$.\r\n\\end{definition}\r\nWe denote the sequence in the form $a_n=f(n)$.\r\n\\begin{example}\r\n    1. The constant sequence $f\\equiv a$ for some constant $a\\in X$.\\\\\r\n    2. The sequence $f(n)=\\sqrt{n^2+17}$ is a sequence in positive real numbers.\\\\\r\n    3. Flip a coin.\r\n    The sequence\r\n    $$a_n=\\begin{cases}\r\n        1\\text{, if the $n^{th}$ flip is head}\\\\\r\n        0\\text{, if it is tail.}\r\n    \\end{cases}$$\r\n    Then $a_n$ is a sequence in $\\{0,1\\}$.\\\\\r\n    4. With last example, we can define $b_1=0,b_{n+1}=b_n+a_n$ makes a sequence $b_n$ in $\\mathbb Z$.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $(z_n)$ is a sequence of complex numbers, we say $z_n\\to z$ (or $z_n$ converges to $z$) as $n\\to\\infty$ if\r\n    $$\\forall\\epsilon>0,\\exists N\\in\\mathbb N,\\forall n>N,|z_n-z|<\\epsilon$$\r\n    Otherwise, we say $(z_n)$ diverges.\r\n\\end{definition}\r\nNote that $N$ depends on $\\epsilon$.\r\n\\begin{example}\r\n    1. The constant sequence $z_n=z$ converges to $z$.\\\\\r\n    2. The sequence $z_n=1/n$ converges to $0$.\r\n    Given $\\epsilon>0$ we can find $N$ such that $N>1/\\epsilon$ since $\\mathbb N$ has no upper bound, then whenever $n>N$, we have $|z_n-z|=|1/n|<1/N<\\epsilon$.\\\\\r\n    3. The sequence $z_n=n$ diverges.\\\\\r\n    4. The sequence $z_n=(-1)^n$ diverges.\r\n\\end{example}\r\n\\begin{proposition}\r\n    $z_n\\to z$ iff:\\\\\r\n    1. $z_n-z\\to 0$.\\\\\r\n    2. $|z_n-z|\\to 0$.\\\\\r\n    3. $\\forall m\\in N,\\exists N\\in\\mathbb N, \\forall n>N,|z_n-z|<1/m$.\r\n\\end{proposition}\r\n\\begin{proposition}\r\n    Suppose $z_n$ and $w_n$ are sequences in $\\mathbb C$.\r\n    If $z_n\\to z,w_n\\to w$, then\\\\\r\n    1. $z_n+w_n\\to z+w$.\\\\\r\n    2. $z_nw_n\\to zw$.\\\\\r\n    3. If $z\\neq 0$, then $\\exists N\\in\\mathbb N,\\forall n>N,z_n\\neq 0$ and for $n>N,1/z_n\\to 1/z$.\\\\\r\n    4. If $z_n=x_n+iy_n,z=x+iy$ with $x_n,x,y_n,y\\in\\mathbb R$, we have $z_n\\to z\\iff x_n\\to x\\land y_n\\to y$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. $1/(n^2)=(1/n)(1/n)\\to 0\\cdot 0=0$.\\\\\r\n    2. $1\\pm1/n^2\\to 1\\pm0=1$.\\\\\r\n    3. $1/(1\\pm 1/n^2)\\to 1/1=1$.\\\\\r\n    4. $(n^2-n)/(n^2+n)=(1+1/n)^{-1}(1-1/n)\\to 1\\cdot 1=1$.\r\n\\end{example}\r\n\\begin{remark}\r\n    2 implies that if $z_n\\to z$ then $cz_n\\to cz$.\r\n    Similarly 2,3 together show that if $z_n\\to z,w_n\\to w\\neq 0$, then $z_n/w_n$ is eventually well-defined and goes to $z/w$.\r\n\\end{remark}\r\n\\begin{corollary}[Uniqueness of Limit]\r\n    If $z_n\\to z$ and $z_n\\to z'$, then $z=z'$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    By 1 and 2, $0\\equiv z_n+(-1)z_n\\to z+(-1)z'=z-z'$, but if $0\\to w\\neq 0$, then $|w|>0$, therefore there is some $n$ such that $|w|=|w-0|<|w|/2<|w|$, contradiction.\r\n    So $z=z'$.\r\n\\end{proof}\r\nWe sometimes write\r\n$$\\lim_{n\\to\\infty}z_n=z$$\r\nif $z_n\\to z$.\r\nWe can write it so since limits are unique.\r\n\\begin{proposition}\r\n    Suppose $x_n\\to x,y_n\\to y$ are real sequences, then if $\\forall n,x_n\\ge y_n$, then $x>y$.\r\n\\end{proposition}\r\nNote that it is not true if we replace $\\ge$ by $>$.\r\n\\begin{proof}\r\n    It suffices to prove the case when $y_n\\equiv 0$.\\\\\r\n    If $x<0$, then there is a natural number $n$ such that $|x_n-x|<|x|$, but $|x_n-x|\\ge|x|$, which is a contradiction.\\\\\r\n    For the general case, just consider the sequence $x_n-y_n$.\r\n\\end{proof}\r\n\\begin{proposition}[Squeeze Rule]\r\n    If $x_n,c_n,y_n$ are real sequences with $\\forall n,x_n\\ge c_n\\ge y_n$ and $x_n\\to c,y_n\\to c$, then $c_n\\to c$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Given $\\epsilon>0$, pick $N_1$ such that $\\forall n>N_1,|x_n-c|<\\epsilon$ and $N_2$ such that $\\forall n>N_2,|y_n-c|<\\epsilon$, so $\\forall n>\\max\\{N_1,N_2\\}$. we have\r\n    $$c+\\epsilon>x_n\\ge c_n\\ge y_n>c-\\epsilon$$\r\n    so $|c_n-c|<\\epsilon$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Since\r\n    $$\\frac{n^2-1}{n^2}\\le\\frac{n^2+\\sin n}{n^2}\\le\\frac{n^2+1}{n^2}$$\r\n    we have $(n^2+\\sin n)/n^2\\to 1$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $x_n$ be a sequence in $\\mathbb R$.\r\n    We say it is monotone increasing if $x_{n+1}\\ge x_n$ for all $n\\mathbb N$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A sequence $x_n$ is bounded above if there is some constant $c\\in\\mathbb R$ such that $x_n\\ge c$ for any $n$.\r\n\\end{definition}\r\n\\begin{theorem}[Monotone Sequence Theorem]\r\n    A monotone increasing sequence in $\\mathbb R$ that is bounded above converges.\r\n\\end{theorem}\r\nNote that this theorem is false if we replace $\\mathbb R$ by $\\mathbb Q$\r\n\\begin{proof}\r\n    Let $x_n$ be such a sequence and we let $c=\\sup_{n\\in\\mathbb N}x_n$.\r\n    $c$ exists since $x_n$ is bounded above.\r\n    We shall show that $x_n\\to c$.\\\\\r\n    If $x_n$ does not tend to $c$, then there is some $\\epsilon>0$ such that $\\forall N\\in\\mathbb N,\\exists n>N,c-x_n=|x_n-c|\\ge\\epsilon$.\r\n    However, this would mean that for any $N\\in\\mathbb N$, we can choose such an $n$, then it gives $x_N\\le x_n\\le c-\\epsilon$, so $c$ is not the least upper bound, contradiction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $(x_n)$ be a sequence in $\\mathbb R$, we say $x_n\\to\\infty$ if $\\forall M\\in\\mathbb R,\\exists N\\in\\mathbb N,\\forall n>N,x_n>M$.\r\n\\end{definition}\r\nNote that a sequence that tends to infinity diverges.\r\n\\begin{proposition}\r\n    If the sequence $(x_n)$ is monotone increasing, then it either converges or tends to infinity.\r\n\\end{proposition}\r\n\\subsection{Series}\r\n\\begin{definition}\r\n    We say the infinite series\r\n    $$\\sum_{i=0}^\\infty c_i$$\r\n    converges (diverges) if the sequence $s_n=\\sum_{i=0}^nc_i$ converges (diverges).\\\\\r\n    If $s_n$ converges to $s$, we write\r\n    $$\\sum_{i=0}^\\infty c_i=s$$\r\n\\end{definition}\r\n\\begin{example}\r\n    Consider the geometric series $\\sum_{k=0}^\\infty z^k$ where $|z|<1$.\r\n    So $s_n=(1-z^{n+1})/(1-z)$.\r\n    Note that $z_{n+1}\\to 0$ as $n\\to\\infty$, hence $s_n\\to 1/(1-z)$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    If the series sum $\\sum_{i=0}^\\infty c_i$ converges, then $c_i\\to 0$ as $i\\to\\infty$.\r\n\\end{lemma}\r\nNote that the converse of the statement is false.\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Suppose $(a_n),(b_n)$ are sequences in $\\mathbb C$,\\\\\r\n    1. For any $K_1,K_2\\in\\mathbb N$, $\\sum_{i=K_1}^\\infty a_n$ cconverges iff $\\sum_{i=K_2}^\\infty a_n$ converges.\\\\\r\n    2. Suppose $\\sum_na_n\\to a,\\sum_nb_n\\to b$, then $\\sum_n(a_n+\\lambda b_n)\\to a+\\lambda b$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{theorem}[Comparison Test]\r\n    Suppose $(a_n),(b_n)$ are sequences in $\\mathbb R$, and $a_n\\ge b_n\\ge 0$ for all $n$, then if the series $\\sum_ia_i$ converges, so does $\\sum_ib_i$, and $\\sum_ia_i\\ge\\sum_ib_i\\ge 0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Indubitable.\r\n    \\footnote{The author is short of such sort of adjectives.}\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $(c_n)$ be a complex sequence, we say $\\sum_ic_i$ converges absolutely if $\\sum_i|c_i|$ converges.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $(c_n)\\in\\mathbb R$, then if $\\sum_{i}|c_i|$ converges, then $\\sum_ic_i$ converges.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Just sum up $c_n+|c_n|$ and use Comparison Test.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    If $(c_n)\\in\\mathbb C$ converges absolutely, then it converges.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Split real and imaginary part and use Comparison Test.\r\n\\end{proof}\r\nAlternatively one can also use triangle inequality.\r\n\\begin{theorem}[Strong Comparison Test]\r\n    Suppose $(c_n)\\in\\mathbb C$ and $(a_n)\\in\\mathbb R_+$ with $a_n\\ge |c_n|\\ge 0$.\r\n    Then if $\\sum_na_n$ converges, then $\\sum_nc_n$ converges absolutely.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Analogous.\r\n\\end{proof}\r\n\\begin{theorem}[Ratio Test]\r\n    Suppose $(c_n)\\in\\mathbb C$ such that\r\n    $$[0,\\infty]\\ni r=\\lim_{n\\to\\infty}\\left|\\frac{c_{n+1}}{c_n}\\right|$$\r\n    exists, then if $r<1$, $\\sum_{n}c_n$ converges, and if $r>1$, $\\sum_nc_n$ diverges.\r\n\\end{theorem}\r\nIf $r=1$, then both ways are possible.\r\n\\begin{example}\r\n    $$\\sum_{n=0}^\\infty\\frac{z^n}{n!}$$\r\n    where $z$ is a complex number.\r\n    This series converges absolutely since\r\n    $$\\lim_{n=\\to\\infty}\\frac{|z|^{n+1}n!}{|z|^n(n+1)!}=\\lim_{n\\to\\infty} \\frac{|z|}{n+1}\\to 0<1$$\r\n    by Ratio Test.\r\n    So we can really define $\\exp(z)$.\r\n\\end{example}\r\n\\begin{proof}\r\n    If $r>1$, then we can find $\\eta$ such that $1<\\eta<r$, and $\\exists N\\in\\mathbb N,\\forall n>N$ we have $|c_{n+1}|>\\eta|c_n|$, therefore $|c_n|\\to\\infty$, hence the series diverges.\\\\\r\n    If $r<1$, then we can find $\\eta$ such that $r<\\eta<1$ and $\\exists N\\in\\mathbb N,\\forall n>N,|c_{n+1}|\\le\\eta|c_n|$, so a comparison test with the geometric series shows the convergence. \r\n\\end{proof}\r\n\\begin{example}[Non-examples]\r\n    Consider the harmonic series $\\sum_n1/n$.\r\n    The ratio test is useless here as $(n+1)/n\\to 1$ as $n\\to\\infty$.\r\n    The sequence of the terms converges as well, so we cannot get anything from there either.\r\n    And in fact, it diverges.\r\n    We can compare it with the sequence $1+1/2+1/4+1/4+1/8+1/8+1/8+1/8+\\cdots$ to show that it is indeed actually diverges.\r\n\\end{example}\r\n\\begin{proposition}[Cauchy Condensation Test]\r\n    Suppose $(a_n)\\in\\mathbb R$ and $a_n\\ge a_{n+1}\\ge 0$ for any $n$.\r\n    Then $\\sum_na_n$ converges iff $\\sum_{k}2^ka_{2^k}$ converges.\r\n\\end{proposition}\r\nI'd like to think that we can replace $2$ by any natural number $p\\ge 2$.\r\n\\begin{example}\r\n    $\\sum_nn^{-p}$ converges iff $\\sum_k2^k2^{-kp}=\\sum_k(2^{1-p})^k$ converges iff $p>1$.\r\n\\end{example}\r\n\\begin{proof}\r\n    Comparison.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Suppose $(x_n)$ is a sequence in some set $X$.\r\n    A subsequence of $x_n$ is a sequence of the form $x_{n_k}$ where $(n_k)_{k\\in\\mathbb N}$ is strictly increasing.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    Suppose $c_n$ is a sequence in $\\mathbb C$ and $c_{n_k}$ is a subsequence, then if $c_n\\to c$, then $c_{n_k}\\to c$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nThe converse is obviously not true.\r\n\\begin{lemma}\r\n    If $(a_n)\\in\\mathbb R$ is monotone and a subsequence of it converges $a_{n_k}\\to a$, then $a_n\\to a$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Easy.\r\n\\end{proof}\r\n\\subsection{Bolzano-Weierstrass}\r\n\\begin{definition}\r\n    Let $(c_n)$ be a sequence of complex numbers.\r\n    We say $(c_n)$ is bounded if $\\exists M>0,\\forall n\\in\\mathbb N,|c_n|<M$.\r\n\\end{definition}\r\n\\begin{theorem}[Bolzano-Weierstrass]\r\n    Any bounded sequence has a converging subsequence.\r\n\\end{theorem}\r\nThis is false in $\\mathbb Q$ as one will expect.\\\\\r\nWe shall prove this by ``lion-hunting''.\r\nThe philosophy is like this:\r\nGiven an infinite sequence of lions in a rectangular zone.\r\nWe divide the rectangle by halving each side, then one of the four parts shall contain infinitely many lions.\r\nDo this again on the region having infinitely many lions.\r\nAnd do this again and again and again so there is a sequence of rectangles $A_0\\subset A_1\\subset A_2\\subset\\cdots$ such that each $A_n$ contains infinitely many lions and that the diameters of $A_n$ decreases (exponentially) to $0$ when $n\\to\\infty$.\r\nSo choosing a lion in each $A_n$ (such that its index is higher than the previous lion, possible since each $A_n$ is infinite) gives a subsequence of converging lions.\r\n\\begin{proof}\r\n    Suffices to show the real case.\r\n    Take $a_0=-M,b_0=M$, then $[a_0,b_0]$ contains infinitely many terms of the sequence.\r\n    Once we have chosen $a_n,b_n$ such that $[a_n,b_n]$ contains infinitely many terms of the sequence, at least one of $[a_n,(a_n+b_n)/2],[(a_n+b_n)/2,b_n]$ must contain infinitely many terms of the sequence.\r\n    For the former case we set $a_{n+1}=a_n,b_{n+1}=(a_n+b_n)/2$ and for the latter $a_{n+1}=(a_n+b_n)/2,b_{n+1}=b_n$.\r\n    Then $b_{n+1}-a_{n+1}=(b_n-a_n)/2=2M/2^{n+1}\\to 0$ as $n\\to\\infty$.\r\n    Also both $b_n,a_n$ converges as monotone sequences.\r\n    Then we can choose $x_{n_k}$ inductively:\r\n    Choose $x_{n_0}\\in [a_0,b_0]$, then once we have chosen $x_{n_k}$, we can choose $n_{k+1}$ by choosing one such that $x_{n_{k+1}}\\in [a_{k+1},b_{k+1}]$ and $n_{k+1}>n_k$, which is possible as $[a_{k+1},b_{k+1}]$ contains infinitely many terms.\r\n    So $x_{n_k}$ is squeezed by $a_k,b_k$ which converges to the same limit, hence this subsequence converges.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $(z_n)\\in\\mathbb C$ be a sequence in $\\mathbb C$, we say $z_n$ is Cauchy if $\\forall\\epsilon>0,\\exists N\\in\\mathbb N,\\forall n,m>N,|x_n-x_m|<\\epsilon$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    A complex sequence converges if and only if it is Cauchy.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The ``only if'' part is obvious.\r\n    For the other direction, it is easy that Cauchy sequences are bounded and that if it has a subsequence that converges, then it converges to the same value.\r\n    Then Bolzano-Weierstrass suffices.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $(z_n)\\in\\mathbb C$, then $\\sum_nz_n$ converges iff $\\forall\\epsilon>0,\\exists N\\in\\mathbb N,\\forall n>m>N$,\r\n    $$\\left|\\sum_{k=m+1}^nz_k\\right|<\\epsilon$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{proposition}[Alternating Series Test]\r\n    Suppose $(a_n)\\in\\mathbb R$ and $a_n\\ge a_{n+1}\\ge 0$ and $a_n\\to 0$, then\r\n    $$\\sum_{n=0}^\\infty(-1)^na_n$$\r\n    converges.\r\n\\end{proposition}\r\n\\begin{example}\r\n    So $\\sum_n(-1)^n/n$ converges even if the harmonic series diverges.\r\n\\end{example}\r\n\\begin{proof}\r\n    Let $s_n$ be the $n^{th}$ partial sum, then $s_{2n+1}=s_{2n-1}+a_{2n}-a_{2n+1}\\ge s_{2n-1}$ is monotone increasing and bounded above by $a_0$, so it converges.\r\n    Also $s_{2n}$ converges as well and we can squeeze it.\r\n\\end{proof}", "meta": {"hexsha": "0d6d0de0359a1d5bcb4eefa348fde7963d2d5c75", "size": 13620, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/conv.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/conv.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/conv.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": 47.9577464789, "max_line_length": 252, "alphanum_fraction": 0.6496328928, "num_tokens": 4897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312006227323, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6649312813554445}}
{"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{tfrridt}\n\\section*{\\hspace*{-1.6cm} tfrridt}\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}\nReduced Interference Distribution with triangular kernel.\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] = tfrridt(x)\n[tfr,t,f] = tfrridt(x,t)\n[tfr,t,f] = tfrridt(x,t,N)\n[tfr,t,f] = tfrridt(x,t,N,g)\n[tfr,t,f] = tfrridt(x,t,N,g,h)\n[tfr,t,f] = tfrridt(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        Reduced Interference Distribution with a kernel based on the\n        triangular (or Bartlett) window.  {\\ty tfrridt} computes either the\n        distribution of a discrete-time signal {\\ty x}, or the cross\n        distribution between two signals. This distribution has the\n        following expression :\n%\\begin{multline*}\n\\begin{eqnarray*}\nRIDT_x(t,\\nu)&=&\\int_{-\\infty}^{+\\infty} \nh(\\tau)\\,R_x(t,\\tau)\\,e^{-j2\\pi\\nu\\tau}\\ d\\tau\\\\\n{\\rm with}\\quad\nR_x(t,\\tau)&=&\n\\int_{-\\frac{|\\tau|}{2}}^{+\\frac{|\\tau|}{2}} \n\\frac{2\\,g(v)}{|\\tau|}(1-\\frac{2|v|}{|\\tau|})\\\nx(t+v+\\frac{\\tau}{2}) x^*(t+v-\\frac{\\tau}{2})\\,dv.\n\\end{eqnarray*}\n%\\end{multline*}\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-RIDT, or {\\ty [x1,x2]} if cross-RIDT ({\\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 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 output arguments, {\\ty tfrridt} 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(31,'rect'); h=window(63,'rect');  \n         tfrridt(sig,1:128,128,g,h,0);\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] J. Jeong, W. Williams ``Kernel Design for Reduced Interference\nDistributions'' IEEE Trans. on Signal Proc., Vol. 40, No. 2, pp. 402-412,\nFeb. 1992.\n\\end{minipage}\n\n", "meta": {"hexsha": "ae8b8edfdeffa163e29056917131a870afc49432", "size": 3151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrridt.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/tfrridt.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/tfrridt.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.2980769231, "max_line_length": 136, "alphanum_fraction": 0.5906061568, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6649312813554445}}
{"text": "\n    \\documentclass{article}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\begin{document}\n %Title \n \\section{Collatz Sequence for \\(n=10\\) }\n    %Collatz Function\n    \\[\n        f(n)=\n        \\begin{cases}\n        \\frac{n}{2}, & n \\mod 2=0\n        \\\\\n        3n+1, &n \\mod 2=1\n        \\end{cases} \\\\\n    \\]\n    % Path for given N\n    \\(\\textbf{Path for f(10)}\\\\[3mm]f(n), n=10\n \\\\ \n \\Rightarrow \\frac{10}{2} \n \\\\ \n \\Rightarrow n=5\n \\\\[3mm] \nf(n), n=5\n \\\\ \n \\Rightarrow 3(5) + 1\n \\\\ \n \\Rightarrow n=16\n \\\\[3mm] \nf(n), n=16\n \\\\ \n \\Rightarrow \\frac{16}{2} \n \\\\ \n \\Rightarrow n=8\n \\\\[3mm] \nf(n), n=8\n \\\\ \n \\Rightarrow \\frac{8}{2} \n \\\\ \n \\Rightarrow n=4\n \\\\[3mm] \nf(n), n=4\n \\\\ \n \\Rightarrow \\frac{4}{2} \n \\\\ \n \\Rightarrow n=2\n \\\\[3mm] \nf(n), n=2\n \\\\ \n \\Rightarrow \\frac{2}{2} \n \\\\ \n \\Rightarrow n=1\n \\\\[3mm] \n\n    \\section{Credits}\n    %Maybe add link to gitrepo and other shit, idk\n    This is created using Collatzer (https://github.com/Z1aaan/Collatzer).\n    Created By: Z1aaan\n    \n    README:\n    A program created to visualize and simulate a user-given value for \\textit{N} \n    and see what happens when it is put under the Collatz function.\n    \\end{document}", "meta": {"hexsha": "2bb3986117c1e515471fdcb487ba23fe27e1a8c7", "size": 1180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "other_samples/sample(10).tex", "max_stars_repo_name": "Z1aaan/Collatz-Conjecture", "max_stars_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:06:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:06:27.000Z", "max_issues_repo_path": "other_samples/sample(10).tex", "max_issues_repo_name": "Z1aaan/Collatzer", "max_issues_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "other_samples/sample(10).tex", "max_forks_repo_name": "Z1aaan/Collatzer", "max_forks_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.7301587302, "max_line_length": 82, "alphanum_fraction": 0.5559322034, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6649312770361969}}
{"text": "% !TeX root = ../notes.tex\n\n\\section{Textbook Query Optimization}\nTextbook query optimization involves techniques to perform a rough first optimization, which however is quite simple. There is a series of steps to translate raw SQL into logical and physical plans, each of them transforming input in a more optimal form.\n\nThe output is going to be \\textit{executable}, but still to be improved by non-trivial methods.\n\n\\subsection{Algebra and tuples}\nPlain relational algebra is not sufficient itself: it needs to be revisited ensuring \\textbf{correctness} (producing the same result) within a formal model. The most relevant problem to tackle is \\textbf{deciding whether two algebraic expressions are the same}, but this in difficult in practice.\n\nFor instance, performing a selection before a join might be correct (and faster) in case the considered criterion is equality, but can give a different result than selecting after an outer join. \n\nTo remedy this issue, it is possible to guarantee that two expressions are equivalent, not accepting false positing yet allowing false negatives. \n\nA formal definition of \\textbf{tuple} is an unordered mapping from attribute names to values of a domain. A schema consists in a set of attributes with domain $A(t)$.\n\nTuple operations are:\n\\begin{itemize}\n\t\\item \\textbf{Concatenation}, attaching one tuple to another regardless of ordering (union);\n\t\\item \\textbf{Projection}, producing a notation $t.a$ in which it is possible to access single values or multiple $t_{|\\{a, b\\}}$, getting a subset of the schema.\n\\end{itemize}\n\nA set of tuples with the same schema forms a \\textbf{relation}. Sets naturally do not comply with real data, since they not allow duplicates, but are used for simplicity.\n\nIn most cases, sets and bags can be used interchangeably, but the optimizer considers different semantics: logical algebra operates on \\textit{bags}, physical algebra on \\textit{streams} and sets are only considered after an \\textit{explicit duplicate elimination}.\n\n\\begin{figure}\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\\hspace{-2mm}\n\t\t\\includegraphics[width=0.83\\textwidth]{equivalences_1.png}\n\t\\end{minipage}\n\t\\begin{minipage}{0.5\\textwidth}\r\n\t\t\\hspace{-10mm}\n\t\t\\includegraphics[width=1.2\\textwidth]{equivalences_2.png}\n\t\\end{minipage}\r\n\t\\vspace{-15pt}\n\\end{figure}\n\nSet operations are the classic ones of union, intersection and difference, yet are \\textbf{subject to schema constraints}. On bags, operations are performed on frequencies. \n\nThere are also free variables, which first must be bounded to be evaluated: they are essentials for predicates and algebra expressions, such as dependent joins. \n\nIt is important to note that projection removes duplicates within sets, while keeping them in bags.\n\nThere are equivalences for selection and projection useful to derive whether a different ordering produces the same output. For instance, applying selection twice is the same as applying it once with two criteria plus an AND. Commutative property also holds.\n\n\\subsection{Canonical Query Translation}\nThe canonical query translation transforms SQL into \\textbf{algebra expressions}. The first approach involves some restrictions: it assumes no duplicates without aggregation and set operations.\n\nThe first step is translating the FROM clause:\n$$F = \\begin{cases}\nR_1 & k = 1 \\\\\n((\\dots (R_1 \\times R_2) \\times \\dots) \\times R_k)) & \\text{else}\n\\end{cases}$$\nIn short all relations are joined through a cross product. The next step is translating the WHERE clause:\n$$W = \\begin{cases}\nF & \\text{there is no WHERE clause} \\\\\n\\sigma_p(F) & \\text{otherwise}\n\\end{cases}$$\nThe SELECT clause is translated starting from the projection $a_1,\\ \\dots,\\ a_n$ or $*$. The expression is constructed:\n$$S = \\begin{cases}\nW & \\text{if the projection is ALL} \\\\\n\\prod_{a_1,\\ \\dots,\\ a_n}(W) & \\text{otherwise}\n\\end{cases}$$\nGROUP BY can also be translated, even though it is not part of the canonical translation. Let $g_1,\\ \\dots,\\ g_n$ be the attributes in the clause and $agg$ the aggregations within SELECT:\n$$G = \\begin{cases}\nW & \\text{there is no GROUP BY clause} \\\\\n\\Gamma_{g_1,\\ \\dots,\\ g_m:agg}(W) & \\text{otherwise}\n\\end{cases}$$\nHAVING is basically the same as WHERE, with the filter predicate on top of $G$.\n\n\\subsection{Logical Query Optimization}\nOnce obtained the relational algebra, equivalences span the \\textit{potential search space} and new expressions are derived thanks to them. Of course equivalence can be applied both ways, hence it is relevant to decide which one works better, and conditions have to be checked as well. This, however, makes the search more expensive since there are plenty of alternatives.\n\nTo speed the process up, sometimes some equivalences are ignored, even the simplest ones (for instance when choosing the join algorithm).\n\nQuery plans can only be compared if there is a cost function, often needing details which are not available merely through relational algebra (what kind of join is being used): logical query optimization is still a \\textbf{heuristic} and requires additional steps, since it is not enough to determine the runtime.\n\nMost algorithms, therefore, use the following strategy:\n\\begin{itemize}\n\t\\item Organization of equivalences into \\textbf{groups};\n\t\\item \\textbf{Directing equivalences}, deciding the preferred side and rewriting rules to apply them sequentially to the initial expression, trying to reduce the size of intermediate results.\n\\end{itemize}\nFor example, a projection on the output of a join can be preferred to a join of a projection. It is important to keep in mind that tuples are being removed in the process, and this only applies in certain circumstances (regular expressions, high selectivity of join).\n\nThe rule of thumb is simply to eliminate the most tuples during the intermediate step, to then perform computationally expensive operation with the smallest amount of data.\n\nTo summarize, the phases are:\n\\begin{itemize}\n\t\\item Breaking up conjunctive selection predicates, since simpler predicates can be moved around easier;\n\t\\item Pushing selections down, reducing the number of tuples early;\n\t\\item Introducing joins, which are cheaper than cross product (linear time);\n\t\\item Determining join order, a usually NP-hard problem which is tackled with different approaches;\n\t\\item Introducing and pushing down projections, removing redundant attributes.\n\\end{itemize}\nSome SQL queries have limitations: selections sometimes cannot be pushed down, since there might be no join predicate between tables (cross product). Choosing a different join order allows further push down. \n\n\\subsection{Physical Query Optimization}\nPhysical query optimization adds execution information to the plan, allowing actual cost calculation and optimizing over data structures, access path and operator implementation.\n\nData may be sorted or materialized, introducing results which can be reused and deciding where to store them.\n\nFirst of all, the access path is selected: lookup can be done through \\textbf{index} or \\textbf{table scan}, depending on the selectivity (fraction of the data satisfying the clause): in general, above 10\\% a table scan is recommended. \n\nScanning a table might be efficient since tuples are stored adjacent in memory; using index, instead, involves traversing a tree multiple times starting from the root. \n\nSometimes it is useful to just store in cache the output of a view, but that also depends on the query plan: intermediate results should actually be reused.\n\n\\textbf{Operator selection} is replacing a logical operator with a physical one, according to semantic restrictions (most operators require equi-join).\n\nA blockwise nested loop join is generally better than a natural join; sort merge join and hash join are better than both. In general, hash join is the best if not reusing sorts. This process must be performed for all operators: sort join requires ordered tuples, distributed databases need local data and there are multiple ways to model the properties (hashing).\n\nSort merge join might outperform the hash join if the amount of data is much larger than the available memory.\n\nMaterializing, on the other side, is quite relevant for nested loop joins: the first pass is expensive, but the afterwards ones are way cheaper, making it essential for multiple consumers. \n", "meta": {"hexsha": "65b6836b7b1b61642f9462b23423b5b7525f8049", "size": 8330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Query Optimization/lectures/textbook_query_optimization.tex", "max_stars_repo_name": "mrahtapot/TUM", "max_stars_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "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": "Query Optimization/lectures/textbook_query_optimization.tex", "max_issues_repo_name": "mrahtapot/TUM", "max_issues_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "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": "Query Optimization/lectures/textbook_query_optimization.tex", "max_forks_repo_name": "mrahtapot/TUM", "max_forks_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.8103448276, "max_line_length": 372, "alphanum_fraction": 0.7888355342, "num_tokens": 1845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6649312656546102}}
{"text": "\\subsection{Definition of the methods}\n\n\\begin{Algorithm*}{subspace-iteration}{Orthogonal subspace iteration}\n\n  Let $\\mata\\in\\Cnn$, $\\matx_0 \\in \\C^{n\\times m}$.\\\\\n  For $k=0,\\ldots$ until convergence repeat\n  \\begin{itemize}\n  \\item $\\matz_k = \\mata \\matx_k$.\n  \\item $\\matq_k\\matr_k = \\matz_k$ (QR factorization)\n  \\item $\\matx_{k+1} = \\matq_k$\n  \\end{itemize}\n\\end{Algorithm*}\n\n\\begin{Algorithm*}{qr-iteration}{QR iteration}\n  \n  Let $\\mata_1 = \\mata\\in\\Cnn$.\\\\\n  For $k=1,\\ldots$ until convergence repeat\n  \\begin{itemize}\n  \\item $\\matq_k\\matr_k = \\mata_k$ (QR factorization)\n  \\item $\\mata_{k+1} = \\matr_k\\matq_k$\n  \\end{itemize}\n\\end{Algorithm*}\n\n\\subsection{Analysis}\n\\begin{Theorem*}{schur-canonical}{Schur canonical form}\n  For every matrix $\\mata\\in\\Cnn$ there are a unitary matrix\n  $\\matq\\in\\Cnn$ and an upper triangular matrix $\\matr\\in\\Cnn$ such\n  that\n  \\begin{gather}\n    \\mata = \\matq \\matr \\matq^*.\n  \\end{gather}\n  The diagonal entries of $\\matr$ are the eigenvalues of $A$. The\n  column vectors of $\\matq$ are called \\define{Schur vectors}.\n\\end{Theorem*}\n\n\\begin{Lemma}{schur-canonical-1}\n  For any $k\\le n$ the span of the Schur vectors\n  $\\vq_1,\\dots,\\vq_k$ is invariant under the action of $\\mata$.\n\n  For $\\matq_k = (\\vq_1\\dots\\vq_k)$ and $R_k$ the upper left $k\\times k$ block of $\\matr$, there holds\n  \\begin{gather}\n    \\mata\\matq_k = \\matq_k \\matr_k.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Lemma}{schur-canonical-2}\n  The Schur vectors depend on the order chosen for the eigenvalues,\n  and in case of geometric multiplicity, the eigenvectors,\n  respectively. They are determined up to factors $e^{i\\phi}$\n\\end{Lemma}\n\n\\begin{Theorem}{convergence-subspace-iteration}\n  Let $\\mata\\in\\Cnn$ and\n  \\begin{gather}\n    \\abs{\\lambda_1} >\n    \\abs{\\lambda_2}>\\dots>\\abs{\\lambda_m}>\\abs{\\lambda}\n  \\end{gather}\n  for all\n  remaining eigenvalues $\\lambda\\in\\sigma(\\mata)$. Let\n  $\\matq = (\\vq_1\\dots\\vq_m)$ be the Schur vectors associated with the\n  first $m$ eigenvalues and $\\esp{1,\\dots,j}$ be the space spanned by\n  the first $j$ eigenvectors and $P_j$ the orthogonal projector\n  onto this space. Let the set of start vectors of the orthogonal subspace iteration\n  $\\matx_0 = (\\vx_1\\dots\\vx_m)$ be chosen that\n  \\begin{gather}\n    \\operatorname{span}\\{P_1 \\vx_1,\\dots,P_j\\vx_j\\} = \\esp{1,\\dots,j},\\qquad j=1,\\dots,m.\n  \\end{gather}\n  Then, the $j$-th column of $\\matx_k$ converges to $\\vq_j$ for $j=1,\\dots,m$ up to a factor $e^{i\\phi}$.\n\\end{Theorem}\n\n\\begin{Lemma}{qr-1}\n  The matrices $\\mata_k$ of the QR-iteration have the following properties:\n  \\begin{enumerate}\n  \\item $\\mata_{k+1} = \\matq_k^*\\mata_k\\matq_k = \\matq_k^*\\dots\\matq_1^*A\\matq_1\\dots\\matq_k$.\n  \\item $\\mata^k=\\matq_1\\dots\\matq_k\\matr_k\\dots\\matr_1$.\n  \\item If $\\mata$ is normal, so is $\\mata_k$ for any $k$.\n  \\item If $\\mata$ is symmetric, so is $\\mata_k$ for any $k$.\n  \\end{enumerate}\n\\end{Lemma}\n\n\\begin{Theorem}{convergence-qr-iteration}\nRemoved\n\\end{Theorem}\n\n\\subsection{Implementation issues}\n\\begin{intro}\n  In each step of the QR-iteration, a QR-decomposition of the matrix\n  is needed, which requires $\\bigo(n^3)$ operations. Thus, the\n  complexity of the iteration is highly unfavorable. The following\n  discussion will provide us with means to reduce the complexity of\n  the QR-decomposition to $\\bigo(n^2)$, in the symmetric case even to\n  $\\bigo(n)$.\n\\end{intro}\n\n\\begin{Definition}{hessenberg}\n  A matrix is in \\define{Hessenberg form} or is a \\define{Hessenberg\n    matrix}, if all its entries below the first subdiagonal are zero. Visually,\n  \\begin{gather}\n    H = \n    \\begin{pmatrix}\n      *&*&*&*&*&*\\\\\n      *&*&*&*&*&*\\\\\n      0&*&*&*&*&*\\\\\n      0&0&*&*&*&*\\\\\n      0&0&0&*&*&*\\\\\n      0&0&0&0&*&*\n    \\end{pmatrix}\n  \\end{gather}\n  A symmetric or Hermitian Hessenberg matrix is \\define{tridiagonal}.\n\\end{Definition}\n\n\\begin{Theorem}{Hessenberg-qr}\n  The QR-decomposition of a Hessenberg matrix $\\matH$ can be obtained\n  by $n-1$ givens rotations. The matrix $\\matr\\matq$ is again in\n  Hessenberg form. For a (complex) symmetric matrix $\\matH$, the\n  matrix $\\matr\\matq$ is even tridiagonal and (complex) symmetric.\n\\end{Theorem}\n\n\\begin{Corollary}{Hessenberg-qr}\n  The complexity of each step of a QR-iteration for Hessenberg matrices is $\\bigo(n^2)$. For tridiagonal (complex) symmetric matrices, it is $\\bigo(n)$.\n\\end{Corollary}\n\n\\begin{Theorem}{Hessenberg-householder}\n  Every matrix $\\mata\\in\\Cnn$ is unitarily similar to a Hessenberg matrix $\\matH$, that is,\n  \\begin{gather}\n    \\matH = \\matq \\mata \\matq^*.\n  \\end{gather}\n  The matrix $\\matq$ can be obtained by $n-2$ \\putindex{Householder\n    reflections}.\n\\end{Theorem}\n\n\\begin{Algorithm*}{qr-method}{The QR-Method}\n  Compute the spectrum of a matrix $\\mata\\in\\Cnn$ by\n  \\begin{enumerate}\n  \\item Use $n-2$ Householder transformations to transform $\\mata$ to\n    Hessenberg form\n    \\begin{gather}\n     \\matH = \\matq\\mata\\matq^*.\n   \\end{gather}\n \\item QR-iteration: let $\\matH_{0}=\\matH$ and perform until convergence\n   \\begin{align}\n     \\Omega^{(k)}_{1,2}\\times\\dots\\times\\Omega^{(k)}_{n-1,n} \\matr &= \\matH_k\\\\\n     \\matH_{k+1} &= \\matr \\Omega^{(k)}_{1,2}\\times\\dots\\times\\Omega^{(k)}_{n-1,n}.\n   \\end{align}\n \\item Store Householder vectors as well as $r$ and $c$ for each\n   Givens rotation if the eigenvectors are desired in the end.\n  \\end{enumerate}\n\\end{Algorithm*}\n\n\\begin{Theorem}{hessenberg-qr-convergence}\n    Let $\\matH\\in\\Cnn$ be a Hessenberg matrix with eigenvalues such that\n  \\begin{gather}\n    \\abs{\\lambda_1} >\n    \\abs{\\lambda_2}>\\dots>\\abs{\\lambda_n}.\n  \\end{gather}\n  Then, the sequences of the QR-iteration admit the following estimates:\n  \\begin{align}\n    \\dist(\\esp{1,\\dots,j},\\spann{\\vq_1^{(k)},\\dots,\\vq_j^{(k)}}) &= \\bigo \\left(\\abs*{\\frac{\\lambda_{j+1}}{\\lambda_j}}^k\\right),\n    \\\\\n    h_{j+1,j}^{(k)} &= \\bigo \\left(\\abs*{\\frac{\\lambda_{j+1}}{\\lambda_j}}^k\\right)\n                      .\n  \\end{align}\n  Here, $h_{ij}^{(k)}$ are the entries of $\\matH_k$.\n\\end{Theorem}\n\n\\begin{proof}\n  See~\\cite[Theorem 7.3-1]{GolubVanLoan83}.\n\\end{proof}\n\n\\subsection{Shifts and deflation}\n\n\\begin{intro}\n  The goal of this section is the development and justification of a\n  method which accelerates convergence of the QR-iteration and\n  reducing the effort at the same time. It is based on shifts, like\n  for the simple or inverse power method. But, shifts are much more\n  powerful here, since we compute not only ``converging subspace'',\n  but also its complement. The presentation follows\n  mostly~\\cite{GolubVanLoan83}.\n\\end{intro}\n\n\\begin{Theorem}{qr-reduction}\n  Let the matrix $\\matH^{(k)}\\in\\Cnn$ in the QR iteration be of the\n  form\n  \\begin{gather}\n    \\matH^{(k)} =\n    \\begin{pmatrix}\n      \\matH_{11} & \\mata_{12}\\\\0 & \\matH_{22}\n    \\end{pmatrix}\n  \\end{gather}\n  with Hessenberg matrices $\\matH_{11}\\in\\C^{p\\times p}$,\n  $\\matH_{22}\\in \\C^{n-p\\times n-p}$ and an arbitrary matrix\n  $\\mata_{12}\\in \\C^{p\\times n-p}$. Then, the matrix $\\matq^{(k)}$\n  decouples into two diagonal blocks and $\\matH^{(k+1)}$ has the same\n  form. Thus, the iteration decouples into two separate iterations.\n\\end{Theorem}\n\n\\begin{Definition}{hessenberg-unreduced}\n  A Hessenberg matrix is called \\define{unreduced} if all entries on\n  the first subdiagonal are nonzero. It is called \\define{reduced}\n  otherwise.\n\\end{Definition}\n\n\\begin{Algorithm*}{shifted-qr-iteration}{QR iteration with shift}\n  \n  Let $\\matH_1 = \\matq_0^*\\mata\\matq_0\\in\\Cnn$.\\\\\n  For $k=1,\\ldots$ until convergence repeat\n  \\begin{itemize}\n  \\item $\\matq_k\\matr_k = \\matH_k - \\sigma\\id$ (QR factorization)\n  \\item $\\matH_{k+1} = \\matr_k\\matq_k + \\sigma\\id$\n  \\end{itemize}\n\\end{Algorithm*}\n\n\\begin{Lemma}{shifted-qr-convergence}\n  The shifted QR-iteration admits the estimate\n  \\begin{gather}\n    h_{j+1,j}^{(k)} = \\bigo \\left(\\abs*{\\frac{\\lambda_{j+1}-\\sigma}{\\lambda_j-\\sigma}}^k\\right)\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Example*}{rayleigh-shift}{Rayleigh shift}\n  The Rayleigh quotient for the smallest eigenvalue by magnitude\n  converges to $h_{nn}$, as\n  \\begin{gather}\n    \\ve_n^* H^{(k)} \\ve_n = h_{nn}^{(k)}\n  \\end{gather}\n  and $\\vq_n$ is orthogonal to all eigenvectors for eigenvalues of\n  greater magnitude. Therefore, using $\\sigma_k = h_{nn}^{(k)}$ seems\n  a good idea, and often is. But it is not reliable, as in the example\n  \\begin{gather}\n    H =\n    \\begin{pmatrix}\n      0 & 1 \\\\ 1 & 0\n    \\end{pmatrix}.\n  \\end{gather}\n\\end{Example*}\n\n\\begin{Definition*}{wilkinson-shift}{Wilkinson shift}\n  Let\n  \\begin{gather}\n    \\matm =\n    \\begin{pmatrix}\n      h_{n-1,n-1}^{(k)}&h_{n-1,n}^{(k)}\\\\h_{n,n-1}^{(k)}&h_{nn}^{(k)}\n    \\end{pmatrix}.\n  \\end{gather}\n  Then, for $\\sigma_k$ use the eigenvalue of $\\matm$ which is closer\n  to $h_{nn}^{(k)}$.\n\\end{Definition*}\n\n\\begin{Remark}{wilkinson-shift}\n  The Wilkinson shift is reliable and the $h_{n,n-1}$ and $h_{nn}$\n  converge to zero and the smallest eigenvalue by magnitude,\n  respectively. They converge at least quadratically and cubically in\n  the symmetric case~\\cite[Section 8.2]{GolubVanLoan83}.\n\\end{Remark}\n\n\\begin{Algorithm*}{qr-deflation}{Deflation}\n  After each step of the shifted QR-iteration monitor the subdiagonal\n  elements of $\\matH^{(k)}$. Whenever\n  \\begin{gather}\n    \\abs{h_{j,j-1}} \\le \\eps \\bigl(\\abs{h_{j-1,j-1}}+\\abs{h_{jj}}\\bigr)\n  \\end{gather}\n  set $h_{j,j-1}=0$.\n\n  If this happens in the last row, consider $h_{nn}=\\lambda_n$\n  converged and proceed with a matrix of dimension $n-1\\times n-1$.\n\n  If this happens in the center of the matrix, proceed with both\n  remaining diagonal blocks separately.\n\\end{Algorithm*}\n\n\n\\subsection{Methods in real arithmetic}\n\n\\begin{Theorem*}{real-schur-form}{The real Schur form}\n  For every matrix $\\mata\\in \\Rnn$ there is an orthogonal matrix\n  $\\matq\\in\\Rnn$ and a matrix $\\matr\\in\\Rnn$ such that\n  \\begin{gather}\n    \\mata = \\matq\\matr\\matq^*,\n    \\qquad\n    \\matr =\n    \\begin{pmatrix}\n      R_{11} &* & *&*\\\\\n      &R_{22}&*&*\\\\\n      &&\\ddots&*\\\\\n      &&& R_{jj}\n    \\end{pmatrix},\n  \\end{gather}\n  where the diagonal blocks are either of dimension one containing the\n  real eigenvalues or of dimension 2 for complex conjugate eigenvalue\n  pairs. The latter correspond to scaled rotation matrices with the\n  according eigenvalue pair.\n\\end{Theorem*}\n\n\\begin{Remark}{francis-qr}\n  Using double shifts, the QR-iteration can be made to converge to the\n  real Schur form using double shifts in real arithmetic. This method\n  is also known as the \\define{Francis QR step}~\\cite[Algorithm\n  7.5-1]{GolubVanLoan83}.\n\\end{Remark}\n\n\\begin{Remark*}{real-symmetric-qr}{QR-Iteration for real, symmetric matrices}\n  In this case, many things simplify\n  \\begin{enumerate}\n  \\item Hessenberg form is tridiagonal\n  \\item The Schur normal form is\n    \\begin{gather}\n      \\mata = \\matq^T\\matd\\matq\n    \\end{gather}\n    with real, diagonal matrix $\\matd$\n  \\item QR-decomposition uses $\\bigo(n)$ operations and $\\matr$\n    consists only of the main diagonal and one upper diagonal.\n  \\end{enumerate}\n  Accumulating the matrix $\\matq$ still needs $\\bigo(n^2)$ operations\n\\end{Remark*}\n\n\\subsection{Singular Value Decomposition (SVD)}\n\n\\begin{Definition}{svd}\n  The \\define{singular value decomposition} (\\define{SVD}) of a matrix $\\mata\\in\\C^{m\\times n}$ is a facorization\n  \\begin{gather}\n    \\mata = \\matu\\matsigma\\matv^*\n  \\end{gather}\n  with unitary matrices $\\matu\\in\\C^{m\\times m}$ and $\\matv\\in\\Cnn$ as\n  well as a real, diagonal matrix $\\matsigma$ with diagonal entries\n  \\begin{gather}\n    \\sigma_1 \\ge \\sigma_2 \\ge \\dots \\ge \\sigma_p \\ge 0,\n  \\end{gather}\n  where $p = \\min\\{m,n\\}$.\n\\end{Definition}\n\n\\begin{Theorem}{svd}\n  Every matrix $\\mata\\in\\C^{m\\times n}$ admits a singular value\n  decomposition. Every real matrix admits a singular value\n  decomposition with orthogonal matrices $\\matu$, $\\matv$.\n\\end{Theorem}\n\n\\begin{Corollary}{svd-rank}\n  Let $\\mata = \\matu\\matsigma\\matv^*$ be the SVD of $\\mata$ with\n  \\begin{gather}\n    \\sigma_1 \\ge \\dots \\ge \\sigma_r > \\sigma_{r+1} = \\dots = \\sigma_p = 0.\n  \\end{gather}\n  Then, $\\rank \\mata = r$\n\\end{Corollary}\n\n\\begin{Corollary}{svd-inverse}\n  If $\\mata\\in\\Cnn$ is invertible, then\n  \\begin{gather}\n    \\mata^{-1} = \\matv\\matsigma^{-1}\\matu^*,\n  \\end{gather}\n  where\n  \\begin{gather}\n    \\matsigma^{-1} = \\diag\\left(\\frac1{\\sigma_1},\\dots,\\frac1{\\sigma_n}\\right).\n  \\end{gather}\n\\end{Corollary}\n\n\\begin{Remark}{svd-geometry}\n  Let\n  \\begin{gather}\n    E = \\bigl\\{ \\vy\\in \\R^m \\big| \\vy=\\mata\\vx, \\norm{\\vx}_2 = 1 \\bigr\\},\n  \\end{gather}\n  be the ellipsoid obtained by mapping the unit sphere though\n  $\\mata$. Then, the column vectors of $\\matu$ and the singular values\n  $\\sigma_i$ are the directions and lengths of the semi-axes of this\n  ellipsoid, respectively.\n\\end{Remark}\n\n\\begin{Lemma}{svd-ata}\n  The singular values of $\\mata$ are the square roots of the\n  eigenvalues of $\\mata^*\\mata$ and of $\\mata\\mata^*$, respectively. For $m\\ge n$ there holds\n  \\begin{align}\n    \\matv^*(\\mata^*\\mata)\\matv &= \\diag(\\sigma_1^2,\\dots,\\sigma_n^2)\n    &&\\in \\R^{n\\times n}\\\\\n    \\matu^*(\\mata\\mata^*)\\matu &= \\diag(\\sigma_1^2,\\dots,\\sigma_n^2, 0,\\dots,0)\n    &&\\in \\R^{m\\times m}\n  \\end{align}\n\\end{Lemma}\n\n\\begin{Theorem*}{implicit-Q}{Implicit Q-theorem}\n  Let $\\mata\\in\\Cnn$ arbitrary, let $\\matq,\\matv\\in\\Cnn$ unitary such that\n  \\begin{gather}\n    \\matq^*\\mata\\matq = \\matH,\\qquad \\matv^*\\mata\\matv = \\matg,\n  \\end{gather}\n  where $\\matH$ and $\\matg$ are Hessenberg matrices. Let $k$ denote\n  the smallest integer such that $h_{k+1,k} = 0$, or $k=n$ if $\\matH$\n  is unreduced. Assume $\\vv_1 = \\vq_1$. Then,\n  $\\vv_j = e^{i_j\\phi}\\vq_j$ and $\\abs{h_{j,j-1}} = \\abs{g_{j,j-1}}$\n  for $j=1,\\dots,k$. if $k<n$, then $g_{k+1,k} = 0$.\n\\end{Theorem*}\n\n\\begin{proof}\n  See \\cite[Theorem 7.4-2]{GolubVanLoan83}.\n\\end{proof}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "3955d8097327a9a5a9308ff65f210af5d1c82e5c", "size": 13828, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nla/qr.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nla/qr.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "nla/qr.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 34.656641604, "max_line_length": 152, "alphanum_fraction": 0.6730546717, "num_tokens": 4836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.6649269107467513}}
{"text": "\\subsubsection{USB3 Vision Interface}\n\\label{subsubsec:usb3_vision_interface}\n% \\todo[inline]{Citations are weird!, Table position? Leave it!}\n\nThe Baumer industrial camera VCXU-13C uses the USB3 Vision (U3V) interface with a maximum transfer rate of \\SI{5}{Gbit/s} $\\approx$ \\SI{596}{MiB}.\nThe max. frame rate is \\SI{222}{fps} and the total pixel count is equal to\n\\[\n\\text{Pixel}_\\text{tot} = \\text{Pixel}_\\text{width} \\cdot \\text{Pixel}_\\text{height} = \\SI{1280}{px} \\cdot \\SI{1024}{px} = \\SI{1310720}{px}.\n\\]\n\nTo calculate the required data rate in bytes per second, equation \\ref{eq:data_rate} can be used.\nBaumer transmits further information in addition to the actual image data (e.g. frame id, width and height).\nThis metadata is located in the so-called leader and can be neglected in the calculations due to its relatively small size \\cite{baumer_gapi}.\n\n\\begin{equation}\n  \\text{Req. data rate} = \\text{Pixel}_\\text{tot} \\cdot \\text{Bytes per pixel} \\cdot \\text{Frame rate}\n  \\label{eq:data_rate}\n\\end{equation}\n\nFor this application a fixed frame rate of \\SI{200}{fps} is sufficient and facilitates the calculations.\n\nTable \\ref{tab:data_rates} shows the required data rates for the Baumer pixel format \\texttt{BayerRG8} and \\texttt{BGR8}.\nIt is evident that due to the maximum transfer rate of \\SI{596}{MiB} of the U3V interface, only the Baumer \\texttt{BayerRG8} pixel format is suitable \\cite{baumer_ic}.\n\n\\begin{table}[h]\n  \\caption{Required data rate for the two Baumer pixel formats \\texttt{BayerRG8} and \\texttt{BGR8}}\n  \\label{tab:data_rates}\n  \\centering\n  \\begin{tabular}{lll}\n    \\toprule\n     & \\textbf{\\texttt{BayerRG8}} & \\textbf{\\texttt{BGR8}} \\\\\n    \\midrule\n    \\textbf{Bytes per pixel} & \\SI{1}{B} & \\SI{3}{B} \\\\\n    \\textbf{Frame rate} & \\SI{200}{fps} & \\SI{200}{fps} \\\\\n    \\textbf{Req. data rate} & \\SI{250}{MiB/s} & \\SI{750}{MiB/s} \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "abe558469477c4575cb37f51ebe681f78aef34b2", "size": 1913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/report/sections/sw/camera_interface/usb3_vision_interface.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/sw/camera_interface/usb3_vision_interface.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/sw/camera_interface/usb3_vision_interface.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": 49.0512820513, "max_line_length": 167, "alphanum_fraction": 0.7156299007, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114835, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6648086722898021}}
{"text": "\\section{Volume and Average Height}\\label{sec:VolumeAvgHeight}\n\nConsider a surface $f(x,y)$; you might temporarily think of this as\nrepresenting physical topography---a hilly landscape, perhaps. What is\nthe average height of the surface (or average\naltitude of the landscape) over some region?\n\nAs with most such problems, we start by thinking about how we\nmight approximate the answer. Suppose the region is a rectangle,\n$[a,b]\\times[c,d]$. We can divide the rectangle into a grid, $m$\nsubdivisions in one direction and $n$ in the other, as indicated in\nFigure~\\ref{fig:rectangulargrid}. We pick $x$ values $x_0$,\n$x_1$,\\dots, $x_{m-1}$ in each subdivision in the $x$ direction, and\nsimilarly in the $y$ direction.\nAt each of the points $(x_i,y_j)$ in one of the smaller rectangles in\nthe grid, we\ncompute the height of the surface: $f(x_i,y_j)$. Now the average\nof these heights should be (depending on the fineness of the grid)\nclose to the average height of the surface:\n\\[\\ds\\frac{f(x_0,y_0)+f(x_1,y_0)+\\cdots+f(x_0,y_1)+f(x_1,y_1)+\\cdots+\nf(x_{m-1},y_{n-1})}{mn}\\]\n\nAs both $m$ and $n$ go to infinity, we expect this approximation to\nconverge to a fixed value, the actual average height of the\nsurface. For reasonably nice functions this does indeed happen.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 4.1, y from 0 to 3.1\n\\axis left ticks withvalues $c$ $y_1$ $y_2$ $y_3$ $d$ / \nat 0.5 1 1.5 2 2.5 / /\n\\axis bottom ticks withvalues $a$ $x_1$ $x_2$ $x_3$ $x_4$ $x_5$ $b$ / \nat 0.5 1 1.5 2 2.5 3 3.5 / /\n\\put {$\\Delta x$} [t] <0pt,-3pt> at 2.75 0.5\n\\put {$\\Delta y$} [l] <3pt,0pt> at 3.5 1.75\n\\putrule from 0.5 0.5 to 3.5 0.5\n\\putrule from 0.5 1 to 3.5 1\n\\putrule from 0.5 1.5 to 3.6 1.5\n\\putrule from 0.5 2 to 3.6 2\n\\putrule from 0.5 2.5 to 3.5 2.5\n\\putrule from 0.5 0.5 to 0.5 2.5\n\\putrule from 1 0.5 to 1 2.5\n\\putrule from 1.5 0.5 to 1.5 2.5\n\\putrule from 2 0.5 to 2 2.5\n\\putrule from 2.5 0.4 to 2.5 2.5\n\\putrule from 3 0.4 to 3 2.5\n\\putrule from 3.5 0.5 to 3.5 2.5\n\\endpicture}}\n\\caption{A rectangular subdivision of $[a,b]\\times[c,d]$.}\n\\label{fig:rectangulargrid}\n\\end{figure}\n\nUsing sigma notation, we can rewrite the approximation:\n\\begin{align*}\n\\frac{1}{mn}\\sum_{i=0}^{n-1}\\sum_{j=0}^{m-1}f(x_j,y_i)\n  &=\\frac{1}{(b-a)(d-c)}\\sum_{i=0}^{n-1}\\sum_{j=0}^{m-1}f(x_j,y_i)\\frac{b-a}{m}\\frac{d-c}{n}\t\\\\\n  &=\\frac{1}{(b-a)(d-c)}\\sum_{i=0}^{n-1}\\sum_{j=0}^{m-1}f(x_j,y_i)\\Delta x\\Delta y.\n\\end{align*}\nThe two parts of this product have useful meaning: $(b-a)(d-c)$ is of\ncourse the area of the rectangle, and the double sum adds up $mn$\nterms of the form $f(x_j,y_i)\\Delta x\\Delta y$, which is the height of\nthe surface at a point multiplied by the area of one of the small rectangles\ninto which we have divided the large rectangle. In short, each term\n$f(x_j,y_i)\\Delta x\\Delta y$ is the volume of a tall, thin,\nrectangular box, and is approximately the volume under the surface and\nabove one of the small rectangles; see Figure~\\ref{fig:volumeapproximation}.\nWhen we add all of these up, we get an\napproximation to the volume under the surface and above the rectangle\n$R=[a,b]\\times[c,d]$. When we take the limit as $m$ and $n$ go to\ninfinity, the double sum becomes the actual volume under the surface,\nwhich we divide by $(b-a)(d-c)$ to get the average height.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/double_int_approx_constr.eps}}} at 0 -0.15\n\\endpicture}}\n\\caption{Approximating the volume under a surface.}\n\\label{fig:volumeapproximation}\n\\end{figure}\n\nDouble sums like this come up in many applications, so in a way it is\nthe most important part of this example; dividing by $(b-a)(d-c)$ is a\nsimple extra step that allows the computation of an average. As we did\nin the single variable case, we introduce a special notation for the\nlimit of such a double sum:\n\\[\\lim_{m,n\\to\\infty} \\sum_{i=0}^{n-1}\\sum_{j=0}^{m-1}f(x_j,y_i)\\Delta\n  x\\Delta y=\\iint_R f(x,y)\\,dx\\,dy=\\iint_R f(x,y)\\,dA,\\]\nthe \\dfont{double integral}\\index{double integral} \nof $f$ over the region $R$. The notation $dA$ indicates a small bit of\narea, without specifying any particular order for the variables $x$\nand $y$; it is shorter and more ``generic'' than writing $dx\\,dy$.\nThe average height of the surface in this notation is \n\\[\\frac{1}{(b-a)(d-c)}\\iint_R f(x,y)\\,dA.\\]\n\nThe next question, of course, is: How do we compute these double\nintegrals? You might think that we will need some two-dimensional\nversion of the Fundamental Theorem of Calculus, but as it turns out we\ncan get away with just the single variable version, applied twice.\n\nGoing back to the double sum, we can rewrite it to emphasize a\nparticular order in which we want to add the terms:\n\\[\\sum_{i=0}^{n-1}\\left(\\sum_{j=0}^{m-1}f(x_j,y_i)\\Delta x\\right)\\Delta y.\\]\nIn the sum in parentheses, only the value of $x_j$ is changing; $y_i$\nis temporarily constant. As $m$  goes to infinity, this sum has the\nright form to turn into an integral:\n\\[\\lim_{m\\to\\infty}\\sum_{j=0}^{m-1}f(x_j,y_i)\\Delta\n  x = \\int_a^b f(x,y_i)\\,dx.\\]\nSo after we take the limit as $m$ goes to infinity, the sum is\n\\[\\sum_{i=0}^{n-1}\\left(\\int_a^b f(x,y_i)\\,dx\\right)\\Delta y.\\]\nOf course, for different values of $y_i$ this integral has different\nvalues; in other words, it is really a function applied to $y_i$:\n\\[G(y)=\\int_a^b f(x,y)\\,dx.\\]\nIf we substitute back into the sum we get\n\\[\\sum_{i=0}^{n-1} G(y_i)\\Delta y.\\]\nThis sum has a nice interpretation. The value $G(y_i)$ is the area of\na cross section of the region under the surface $f(x,y)$, namely, when\n$y=y_i$. The quantity $G(y_i)\\Delta y$ can be interpreted as the\nvolume of a solid with face area $G(y_i)$ and thickness $\\Delta y$.\nThink of the surface $f(x,y)$ as the top of a loaf of sliced\nbread. Each slice has a cross-sectional area and a thickness;\n$G(y_i)\\Delta y$ corresponds to the volume of a single slice of\nbread. Adding these up approximates the total volume of the loaf. (This is\nvery similar to the technique we used to compute volumes in\nSection~\\ref{sec:volume}, \nexcept that there we need the cross-sections to be in\nsome way ``the same''.) Figure~\\ref{fig:volumeapproximationwithslices} \nshows this ``sliced loaf''\napproximation using the same surface as shown in \nFigure~\\ref{fig:volumeapproximation}.\nNicely enough, this sum looks just like the sort of sum that turns into an\nintegral, namely,\n\\begin{align*}\n\\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} G(y_i)\\Delta y&=\\int_c^d G(y)\\,dy\t\\\\\n&=\\int_c^d \\int_a^b f(x,y)\\,dx\\,dy.\n\\end{align*}\nLet's be clear about what this means: we first will compute the inner\nintegral, temporarily treating $y$ as a constant. We will do this by\nfinding an anti-derivative with respect to $x$, then substituting\n$x=a$ and $x=b$ and subtracting, as usual. The result will be an\nexpression with no $x$ variable but some occurrences of $y$. Then the\nouter integral will be an ordinary one-variable problem, with $y$ as\nthe variable.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize9cm\\epsfbox{images/sliced_loaf_2.eps}}} at 0 -0.15\n\\endpicture}}\n\\caption{Approximating the volume under a surface with slices.}\n\\label{fig:volumeapproximationwithslices}\n\\end{figure}\n\n\\begin{example}{Volume Under Surface}{VolumeUnderSurface}\nFigure~\\ref{fig:volumeapproximation} shows the function\n$\\sin(xy)+6/5$ on $[0.5,3.5]\\times[0.5,2.5]$. Find the volume under this surface.\n\\end{example}\n\\begin{solution}\nThe volume under this surface is\n\\[\\int_{0.5}^{2.5}\\int_{0.5}^{3.5} \\sin(xy)+{6\\over5}\\,dx\\,dy.\\]\nThe inner integral is\n\\[\\int_{0.5}^{3.5} \\sin(xy)+{6\\over5}\\,dx=\n\\left.{-\\cos(xy)\\over y}+{6x\\over5}\\right|_{0.5}^{3.5}=\n{-\\cos(3.5y)\\over y}+{\\cos(0.5y)\\over y}+{18\\over5}.\\]\nUnfortunately, this gives a function for which we can't find a simple\nanti-derivative. To complete the problem we could use Sage or similar\nsoftware to approximate the integral. Doing this gives a volume of\napproximately $8.84$, so the average height is approximately \n$8.84/6\\approx 1.47$.\n\\end{solution}\n\nBecause addition and multiplication are commutative and associative,\nwe can rewrite the original double sum:\n\\[\\sum_{i=0}^{n-1}\\sum_{j=0}^{m-1}f(x_j,y_i)\\Delta\n  x\\Delta y=\\sum_{j=0}^{m-1}\\sum_{i=0}^{n-1}f(x_j,y_i)\\Delta\n  y\\Delta x.\\]\nNow if we repeat the development above, the inner sum turns into\nan integral:\n\\[\\lim_{n\\to\\infty}\\sum_{i=0}^{n-1}f(x_j,y_i)\\Delta\n  y = \\int_c^d f(x_j,y)\\,dy,\\]\nand then the outer sum turns into an integral:\n\\[\\lim_{m\\to\\infty}\\sum_{j=0}^{m-1}\\left(\\int_c^d f(x_j,y)\\,dy\n\\right)\\Delta x = \\int_a^b\\int_c^d f(x,y)\\,dy\\,dx.\\]\nIn other words, we can compute the integrals in either order, first\nwith respect to $x$ then $y$, or vice versa. Thinking of the loaf of\nbread, this corresponds to slicing the loaf in a direction\nperpendicular to the first. \n\nWe haven't really proved that the value of a double integral is equal\nto the value of the corresponding two single integrals in either order\nof integration, but provided the function is reasonably nice, this is\ntrue; the result is called \\dfont{Fubini's Theorem}.\n\n\\begin{example}{Compute Volume in Two Ways}{ComputeVolumeTwoWays}\nWe compute $\\ds\\iint_R 1+(x-1)^2+4y^2\\,dA$, where\n$R=[0,3]\\times[0,2]$, in two ways.\n\\end{example}\n\\begin{solution}\nFirst,\n\\begin{align*}\n\\int_0^3\\int_0^2 1+(x-1)^2+4y^2\\,dy\\,dx\n&=\\int_0^3\\left. y+(x-1)^2y+{4\\over 3}y^3\\right|_0^2\\,dx\t\\\\\n&=\\int_0^3 2+2(x-1)^2+{32\\over 3}\\,dx\t\\\\\n&=\\left. 2x + {2\\over 3}(x-1)^3+{32\\over 3}x\\right|_0^3\t\\\\\n&=6+{2\\over 3}\\cdot 8 + {32\\over 3}\\cdot3-(0-1\\cdot{2\\over3}+0)\t\\\\\n&=44.\n\\end{align*}\nIn the other order:\n\\begin{align*}\n\\int_0^2\\int_0^3 1+(x-1)^2+4y^2\\,dx\\,dy\n&=\\int_0^2\\left. x+{(x-1)^3\\over3}+4y^2x\\right|_0^3\\,dy\t\\\\\n&=\\int_0^2 3+{8\\over3}+12y^2+{1\\over3}\\,dy\t\\\\\n&=\\left. 3y+{8\\over3}y+4y^3+{1\\over3}y\\right|_0^2\t\\\\\n&=6+{16\\over3}+32+{2\\over3}\t\\\\\n&=44.\n\\end{align*}\n\\end{solution}\n\nIn this example there is no particular reason to favor one direction\nover the other; in some cases, one direction might be much easier than\nthe other, so it's usually worth considering the two different\npossibilities. \n\nFrequently we will be interested in a region that is not simply a\nrectangle. Let's compute the volume under the surface $x+2y^2$ above\nthe region described by $0\\le x\\le1$ and $0\\le y\\le x^2$, shown in\nFigure~\\ref{fig:parabolicregion}.\n\n\\begin{figure}[H]\n\\hbox to \\hsize{\\hfill\n\\begin{tikzpicture}[baseline=0,x=2cm,y=2cm]\n\\draw (0,0) -- (1.1,0) ;\n\\draw (0,0) -- (0,1.1) ;\n\\foreach \\x in {0,1} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\n\\foreach \\y in {0,1} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east]\n{$\\y$};\n%\\gpad\n\\draw[color=black]  plot[id=fun,domain=0:1] function{x**2};\n\\draw (1,0) -- (1,1);\n\\fill[opacity=0.5,fill=red!20] (0,0) parabola (1,1) -- (1,0) -- (0,0); \n\\end{tikzpicture}\\hfill}\n\\caption{A parabolic region of integration.}\n\\label{fig:parabolicregion}\n\\end{figure}\n\nIn principle there is nothing more difficult about this problem. If we\nimagine the three-dimensional region under the surface and above the\nparabolic region as an oddly shaped loaf of bread, we can still slice\nit up, approximate the volume of each slice, and add these volumes\nup. For example, if we slice perpendicular to the $x$ axis at $x_i$, the\nthickness of a slice will be $\\Delta x$ and the area of the slice will\nbe \n\\[\\int_0^{x_i^2} x_i+2y^2\\,dy.\\]\nWhen we add these up and take the limit as $\\Delta x$ goes to 0, we\nget the double integral\n\\begin{align*}\n\\int_0^1 \\int_0^{x^2} x+2y^2\\,dy\\,dx\n&=\\int_0^1 \\left.xy+{2\\over3}y^3\\right|_0^{x^2}\\,dx\t\\\\\n&=\\int_0^1 x^3+{2\\over3}x^6\\,dx\t\\\\\n&=\\left. {x^4\\over4}+{2\\over21}x^7\\right|_0^1\t\\\\\n&={1\\over4}+{2\\over21}={29\\over84}.\n\\end{align*}\nWe could just as well slice the solid perpendicular to the $y$ axis,\nin which case we get\n\\begin{align*}\n\\int_0^1 \\int_{\\sqrt y}^1 x+2y^2\\,dx\\,dy\n&=\\int_0^1 \\left.{x^2\\over2}+2y^2x\\right|_{\\sqrt y}^1 \\,dy\t\\\\\n&=\\int_0^1 {1\\over2}+2y^2-{y\\over2}-2y^2\\sqrt y\\,dy\t\\\\\n&=\\left.{y\\over2}+{2\\over3}y^3-{y^2\\over4}-{4\\over7}y^{7/2}\\right|_0^1\t\\\\\n&={1\\over2}+{2\\over3}-{1\\over4}-{4\\over7}={29\\over84}.\n\\end{align*}\nWhat is the average height of the surface over this region? As before,\nit is the volume divided by the area of the base, but now we need to\nuse integration to compute the area of the base, since it is not a\nsimple rectangle. The area is\n$$\\int_0^1 x^2\\,dx={1\\over3},$$\nso the average height is $29/28$.\n\n\\begin{example}{Volume of Region}{VolumeRegion}\nFind the volume under the surface $\\ds z=\\sqrt{1-x^2}$ and above\nthe triangle formed by $y=x$, $x=1$, and the $x$-axis.\n\\end{example}\n\\begin{solution}\nLet's consider the two possible ways to set this up:\n$$\\int_0^1 \\int_0^x \\sqrt{1-x^2}\\,dy\\,dx \\qquad\\hbox{or}\\qquad\n\\int_0^1 \\int_y^1 \\sqrt{1-x^2}\\,dx\\,dy.\n$$\nWhich appears easier? In the first, the first (inner) integral is\neasy, because we need an anti-derivative with respect to $y$, and the\nentire integrand $\\ds\\sqrt{1-x^2}$ is constant with respect to $y$. Of\ncourse, the second integral may be more difficult. In the second, the\nfirst integral is mildly unpleasant---a trig substitution. So let's\ntry the first one, since the first step is easy, and see where that\nleaves us.\n\\[\\int_0^1 \\int_0^x \\sqrt{1-x^2}\\,dy\\,dx=\n\\int_0^1 \\left. y\\sqrt{1-x^2}\\right|_0^x\\,dx=\n\\int_0^1 x\\sqrt{1-x^2}\\,dx.\\]\nThis is quite easy, since the substitution $u=1-x^2$ works:\n\\[\\int x\\sqrt{1-x^2}\\,dx=-{1\\over 2}\\int \\sqrt u\\,du\n={1\\over3}u^{3/2}=-{1\\over3}(1-x^2)^{3/2}.\\]\nThen \n\\[\\int_0^1 x\\sqrt{1-x^2}\\,dx=\\left. -{1\\over3}(1-x^2)^{3/2}\\right|_0^1\n={1\\over3}.\\]\nThis is a good example of how the order of integration can affect the\ncomplexity of the problem. In this case it is possible to do the other\norder, but it is a bit messier. In some cases one order may lead to a\nvery difficult or impossible integral; it's usually worth considering\nboth possibilities before going very far.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:VolumeAvgHeight}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nCompute $\\ds \\int_{0}^{2}\\int_{0}^{4} 1+x \\,dy\\,dx$.\n\\begin{sol}\n$16$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{-1}^{1}\\int_{0}^{2} x+y\\,dy\\,dx$.\n\\begin{sol}\n$4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{1}^{2}\\int_{0}^{y} xy \\,dx\\,dy$.\n\\begin{sol}\n$15/8$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{0}^{1}\\int_{y^2/2}^{\\sqrt y} \\,dx\\,dy$.\n\\begin{sol}\n$1/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{1}^{2}\\int_{1}^{x} {x^2\\over y^2}\\,dy\\,dx$.\n\\begin{sol}\n$5/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{0}^{1}\\int_{0}^{x^2} {y\\over e^x}\\,dy\\,dx$.\n\\begin{sol}\n$12-65/(2e)$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{0}^{\\sqrt{\\pi/2}}\\int_{0}^{x^2} x\\cos y\\,dy\\,dx$.\n\\begin{sol}\n$1/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{0}^{\\pi/2}\\int_{0}^{\\cos\\theta}r^2\n(\\cos\\theta-r) \\,dr\\,d\\theta$.\n\\begin{sol}\n$\\pi/64$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute: $\\ds \\int_0^1\\int_{\\sqrt{y}}^1 \n\\sqrt{x^3+1}\\,dx\\,dy$.\n\\begin{sol}\n$(2/9)2^{3/2}-(2/9)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute: $\\ds \\int_0^1\\int_{y^2}^1 \ny\\sin(x^2)\\,dx\\,dy$.\n\\begin{sol}\n$(1-\\cos(1))/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute: $\\ds \\int_0^1 \\int_{x^2}^1 x\\sqrt{1+y^2}\\,dy\\,dx$\n\\begin{sol}\n$(2\\sqrt2-1)/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute: $\\ds \\int_0^1 \\int_0^y\n\t  {2\\over\\sqrt{1-x^2}}\\,dx\\,dy$\n\\begin{sol}\n$\\pi-2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute: $\\ds \\int_0^1 \\int_{3y}^3\n\t  e^{x^2}\\,dx\\,dy$\n\\begin{sol}\n$(e^9-1)/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{-1}^1\\int_0^{1-x^2} x^2-\\sqrt{y}\\,dy\\,dx$.\n\\begin{sol}\n$\\ds {4\\over15}-{\\pi\\over4}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute \n$\\ds \\int_{0}^{\\sqrt2/2}\\int_{-\\sqrt{1-2x^2}}^{\\sqrt{1-2x^2}} x\\,dy\\,dx$.\n\\begin{sol}\n$1/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint x^2\\,dA$ over the region in the first\nquadrant bounded by the hyperbola $xy=16$ and the lines $y=x$, $y=0$, and\n$x=8$.\n\\begin{sol}\n$448$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume below $z=1-y$ above the region\n$-1\\le x\\le 1$, $0\\le y\\le 1-x^2$.\n\\begin{sol}\n$4/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume bounded by $z=x^2+y^2$ and $z=4$.\n\\begin{sol}\n$8\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume in the first octant\nbounded by $y^2=4-x$ and $y=2z$.\n\\begin{sol}\n$2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume in the first octant\nbounded by $y^2=4x$, $2x+y=4$, $z=y$,\nand $y=0$.\n\\begin{sol}\n$5/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume in the first octant\nbounded by $x+y+z=9$, $2x+3y=18$, and $x+3y=9$.\n\\begin{sol}\n$81/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume in the first octant\nbounded by $x^2+y^2=a^2$ and $z=x+y$.\n\\begin{sol}\n$2a^3/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume bounded by $4x^2+y^2=4z$ and $z=2$.\n\\begin{sol}\n$4\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume bounded by $z=x^2+y^2$ and $z=y$.\n\\begin{sol}\n$\\pi/32$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume under the surface $z=xy$ above the triangle\nwith vertices $(1,1,0)$, $(4,1,0)$, $(1,2,0)$.\n\\begin{sol}\n$31/8$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume enclosed by $y=x^2$, $y=4$, $z=x^2$, $z=0$.\n\\begin{sol}\n$128/15$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA swimming pool is circular with a 40 meter diameter.  The\ndepth is constant along east-west lines and increases linearly from 2\nmeters at the south end to 7 meters at the north end.  Find the volume\nof the pool.  \n\\begin{sol}\n$1800\\pi$ ${\\rm m}^3$ \n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the average value of $f(x,y)=e^y\\sqrt{x+e^y}$ on the\n    rectangle with vertices $(0,0)$, $(4,0$), $(4,1)$ and $(0,1)$.\n\\begin{sol}\n$\\ds{(e^2+8e+16)\\over15}\\sqrt{e+4}-{5\\sqrt5\\over3}-{e^{5/2}\\over15}\n+{1\\over15}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFigure~\\ref{fig:colotemperatures} shows a temperature map\nof Colorado.  Use the data to estimate the average temperature in the\nstate using 4, 16 and 25 subdivisions.  Give both an upper and lower\nestimate.  Why do we like Colorado for this problem?  What other\nstate(s) might we like?\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\setcoordinatesystem units <2.5truecm,2.5truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize7cm\\epsfbox{images/weathermap.eps}}} at 0 0\n\\endpicture}}\n\\caption{Colorado temperatures.}\n\\label{fig:colotemperatures}\n\\end{figure}\n\\end{ex}\n\n\\begin{ex}\nThree cylinders of radius 1 intersect at right angles at the\norigin, as shown in Figure~\\ref{fig:threecylinders}. Find the\nvolume contained inside all three cylinders.\n\\begin{sol}\n$16-8\\sqrt{2}$\n\\end{sol}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/three_cylinders.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize4.5cm\\epsfbox{images/three_cylinders_inside.eps}}} at 4 0\n\\endpicture}}\n\\caption{Intersection of three cylinders.}\n\\label{fig:threecylinders}\n\\end{figure}\n\\end{ex}\n\n\\begin{ex}\nProve that if $f(x,y)$ is integrable and if $\\ds g(x,y)=\\int_a^x\n    \\int_b^y f(s,t) \\; dt \\; ds$ then $g_{xy}=g_{yx}=f(x,y)$.\n\\end{ex}\n\n\\begin{ex}\nReverse the order of integration on each of the following integrals\n\\begin{enumerate}\n\t\\item $\\ds\\int_0^9 \\int_0^{\\sqrt{9-y}} f(x,y)\\; dx \\; dy$\n\t\\item $\\ds\\int_1^2 \\int_0^{\\ln x} f(x,y) \\; dy \\; dx $\n\t\\item $\\ds\\int_0^1 \\int_{\\arcsin y}^{\\pi/2} f(x,y) \\; dx \\; dy$\n\t\\item $\\ds\\int_0^1 \\int_{4x}^{4} f(x,y) \\; dy \\; dx$\n\t\\item $\\ds\\int_0^3 \\int_{0}^{\\sqrt{9-y^2}} f(x,y) \\; dx \\; dy$\n\\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\nWhat are the parallels between Fubini's\n    Theorem and Clairaut's Theorem?\n%% /Balof\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "4ad1329eb3a01755a7c6078b2d7fe7cbc8fb81b0", "size": 19908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-multiple-integration/15-1-volume-avg-height.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "15-multiple-integration/15-1-volume-avg-height.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15-multiple-integration/15-1-volume-avg-height.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7973640857, "max_line_length": 95, "alphanum_fraction": 0.6825396825, "num_tokens": 7722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.6648086521243299}}
{"text": "\\chapter{Ramification theory}\nWe're very interested in how rational primes $p$ factor in a bigger number field $K$.\nSome examples of this behavior: in $\\ZZ[i]$ (which is a UFD!), we have factorizations\n\\begin{align*}\n\t(2) &= (1+i)^2 \\\\\n\t(3) &= (3) \\\\\n\t(5) &= (2+i)(2-i).\n\\end{align*}\nIn this chapter we'll learn more about how primes break down when they're thrown into bigger number fields.\nUsing weapons from Galois Theory, this will culminate in a proof of Quadratic Reciprocity.\n\n\\section{Ramified / inert / split primes}\n\\prototype{In $\\ZZ[i]$, $2$ is ramified, $3$ is inert, and $5$ splits.}\n\nLet $p$ be a rational prime, and toss it into $\\OO_K$.\nThus we get a factorization into prime ideals\n\\[ p \\cdot \\OO_K = \\kp_1^{e_1} \\dots \\kp_g^{e_g}. \\]\nWe say that each $\\kp_i$ is \\vocab{above} $(p)$.\\footnote{%\n\tReminder that $p \\cdot \\OO_K$ and $(p)$ mean the same thing, and I'll use both interchangeably.}\nPictorially, you might draw this as follows:\n\\begin{diagram}\n\tK & \\supset & \\OO_K & \\kp_i \\\\\n\t\\dLine && \\dLine & \\dLine \\\\\n\t\\QQ & \\supset & \\ZZ & (p)\n\\end{diagram}\nSome names for various behavior that can happen:\n\\begin{itemize}\n\t\\ii We say $p$ is \\vocab{ramified} if $e_i > 1$ for some $i$.\n\tFor example $2$ is ramified in $\\ZZ[i]$.\n\t\\ii We say $p$ is \\vocab{inert} if $g=1$ and $e_1=1$; i.e. $(p)$ remains prime.\n\tFor example $3$ is inert in $\\ZZ[i]$.\n\t\\ii We say $p$ is \\vocab{split} if $g > 1$.\n\tFor example $5$ is split in $\\ZZ[i]$.\n\\end{itemize}\n\\begin{ques}\n\tMore generally, for a prime $p$ in $\\ZZ[i]$:\n\t\\begin{itemize}\n\t\t\\ii $p$ is ramified exactly when $p = 2$.\n\t\t\\ii $p$ is inert exactly when $p \\equiv 3 \\pmod 4$.\n\t\t\\ii $p$ is split exactly when $p \\equiv 1 \\pmod 4$.\n\t\\end{itemize}\n\tProve this.\n\\end{ques}\n\n\\section{Primes ramify if and only if they divide $\\Delta_K$}\nThe most unusual case is ramification:\nJust like we don't expect a randomly selected polynomial to have a double root,\nwe don't expect a randomly selected prime to be ramified.\nIn fact, the key to understanding ramification is the discriminant.\n\nFor the sake of discussion, let's suppose that $K$ is monogenic,\n$\\OO_K = \\ZZ[\\theta]$, where $\\theta$ has minimal polynomial $f$.\nLet $p$ be a rational prime we'd like to factor.\nIf $f$ factors as $f_1^{e_1} \\dots f_g^{e_g}$, then we know that\nthe prime factorization of $(p)$ is given by\n\\[ p \\cdot \\OO_K = \\prod_i \\left( p, f_i(\\theta) \\right)^{e_i}. \\]\nIn particular, $p$ ramifies exactly when \\emph{$f$ has a double root mod $p$}!\nTo detect whether this happens, we look at the polynomial discriminant of $f$,\nnamely\n\\[ \\Delta(f) = \\prod_{i<j} (z_i - z_j)^2 \\]\nand see whether it is zero mod $p$ -- thus $p$ ramifies if and only if this is true.\n\nIt turns out that the na\\\"{\\i}ve generalization to any number field\nworks if we replace $\\Delta(f)$ by just the discriminant $\\Delta_K$ of $K$;\n(these are the same for monogenic $\\OO_K$ by \\Cref{prob:root_discriminant}).\nThat is,\n\\begin{theorem}\n\t[Discriminant detects ramification]\n\tLet $p$ be a rational prime and $K$ a number field.\n\tThen $p$ is ramified if and only if $p$ divides $\\Delta_K$.\n\\end{theorem}\n\\begin{example}[Ramification in the Gaussian integers]\n\tLet $K = \\QQ(i)$ so $\\OO_K = \\ZZ[i]$ and $\\Delta_K = 4$.\n\tAs predicted, the only prime ramifying in $\\ZZ[i]$ is $2$,\n\tthe only prime factor of $\\Delta_K$.\n\\end{example}\nIn particular, only finitely many primes ramify.\n\n\\section{Inertial degrees}\n\\prototype{$(7)$ has inertial degree $2$ in $\\ZZ[i]$ and $(2+i)$ has inertial degree $1$ in $\\ZZ[i]$.}\n\nRecall that we were able to define an ideal norm\n$\\Norm(\\ka) = \\left\\lvert \\OO_K / \\ka \\right\\rvert$\nmeasuring how ``roomy'' the ideal $\\ka$ is.\nFor example, $(5)$ has ideal norm $5^2 = 25$ in $\\ZZ[i]$, since\n\\[ \\ZZ[i] / (5) \\cong \\left\\{ a+bi \\mid a,b \\in \\Zc5 \\right\\} \\]\nhas $5^2 = 25$ elements.\n\nNow, let's look at\n\\[ p \\cdot \\OO_K = \\kp_1^{e_1} \\dots \\kp_g^{e_g} \\]\nin $\\OO_K$, where $K$ has degree $n$.\nTaking the ideal norms of both sides, we have that\n\\[ p^n = \\Norm(\\kp_1)^{e_1} \\dots \\Norm(\\kp_g)^{e_g}. \\]\nWe conclude that $\\kp_i = p^{f_i}$ for some integer $f_i \\ge 1$, and moreover that\n\\[ n = \\sum_{i=1}^g e_i f_i. \\]\n\\begin{definition}\n\tWe say $f_i$ is the \\vocab{inertial degree} of $\\kp_i$,\n\tand $e_i$ is the \\vocab{ramification index}.\n\\end{definition}\n\\begin{example}[Examples of inertial degrees]\n\tWork in $\\ZZ[i]$, which is degree $2$.\n\tThe inertial degree detects how ``spacy'' the\n\tgiven $\\kp$ is when interpreted in $\\OO_K$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The prime $7 \\cdot \\ZZ[i]$ has inertial degree $2$.\n\t\tIndeed, $\\ZZ[i]/ (7)$ has $7^2=49$ elements,\n\t\tthose of the form $a+bi$ for $a$, $b$ modulo $7$.\n\t\tIt gives ``two degrees'' of space.\n\t\t\\ii Let $(5) = (2+i)(2-i)$.\n\t\tThe inertial degrees of $(2+i)$ and $(2-i)$ are both $1$.\n\t\tIndeed, $\\ZZ[i] / (2+i)$ only gives ``one degree'' of space,\n\t\tsince each of its elements can be viewed as integers modulo $5$,\n\t\tand there are only $5^1=5$ elements.\n\t\\end{enumerate}\n\tIf you understand this, it should be intuitively clear\n\twhy the sum of $e_i f_i$ should equal $n$.\n\\end{example}\n\n\\section{The magic of Galois extensions}\nOK, that's all fine and well.\nBut something \\emph{really magical} happens when we add the\nadditional hypothesis that $K/\\QQ$ is \\emph{Galois}:\nall the inertial degrees and ramification degrees are equal.\nWe set about proving this.\n\nLet $K/\\QQ$ be Galois with $G = \\Gal(K/\\QQ)$.\nNote that if $\\kp \\subseteq \\OO_K$ is a prime above $p$,\nthen the image $\\sigma\\im(\\kp)$ is also prime for any $\\sigma \\in G$\n(since $\\sigma$ is an automorphism!).\nMoreover, since $p \\in \\kp$ and $\\sigma$ fixes $\\QQ$,\nwe know that $p \\in \\sigma\\im(\\kp)$ as well.\n\nThus, by the pointwise mapping, \\textbf{the Galois group acts\non the prime ideals above a rational prime $p$}.\nPicture:\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(6cm);\n\t\tpair P = MP(\"p\", (0,-2.8), dir(-90));\n\t\tpair A = MP(\"\\mathfrak p_1\", 0.8*dir(210), origin);\n\t\tpair B = MP(\"\\mathfrak p_2\", 0.5*dir(140), origin);\n\t\tpair C = MP(\"\\mathfrak p_3\", dir(70), origin);\n\t\tpair D = MP(\"\\mathfrak p_4\", 1.2*dir(-15), origin);\n\t\tpair E = MP(\"\\mathfrak p_5\", 1.4*dir(15), origin);\n\t\tpair F = MP(\"\\mathfrak p_6\", 1.5*dir(135), origin);\n\t\tdraw(dir(-90)--P);\n\t\tdraw(A--D, dashed, EndArrow, Margin(3,3));\n\t\tlabel(\"$\\sigma$\", A--D, dir(-90));\n\t\\end{asy}\n\\end{center}\n\nThe notation $\\sigma\\im(\\kp)$ is hideous in this context,\nsince we're really thinking of $\\sigma$ as just doing a group action,\nand so we give the shorthand:\n\\begin{abuse}\n\tLet $\\sigma\\kp$ be shorthand for $\\sigma\\im(\\kp)$.\n\\end{abuse}\n\nSince the $\\sigma$'s are all bijections (they are automorphisms!),\nit should come as no surprise that the prime ideals which are in the same\norbit are closely related.\nBut miraculously, it turns out there is only one orbit!\n\\begin{theorem}\n\t[Galois group acts transitively]\n\tLet $K/\\QQ$ be Galois with $G = \\Gal(K/\\QQ)$.\n\tLet $\\{\\kp_i\\}$ be the set of distinct prime ideals in\n\tthe factorization of $p \\cdot \\OO_K$ (in $\\OO_K$).\n\n\tThen $G$ acts transitively on the $\\kp_i$:\n\tfor every $i$ and $j$, we can find $\\sigma$ such that $\\sigma\\kp_i = \\kp_j$.\n\\end{theorem}\n\\begin{proof}\n\tFairly slick.\n\tSuppose for contradiction that no $\\sigma \\in G$ sends $\\kp_1$ to $\\kp_2$, say.\n\tBy the Chinese remainder theorem, we can find an $x \\in \\OO_K$ such that\n\t\\begin{align*}\n\t\tx &\\equiv 0 \\pmod{\\kp_1} \\\\\n\t\tx &\\equiv 1 \\pmod{\\kp_i} \\text{ for $i \\ge 2$}\n\t\t% \\pmod{(\\sigma\\inv)\\im(\\kp_2)} \\text{ for $\\sigma \\in G$.}\n\t\\end{align*}\n\tThen, compute the norm\n\t\\[ \\NK(x) = \\prod_{\\sigma \\in \\Gal(K/\\QQ)} \\sigma(x). \\]\n\tEach $\\sigma(x)$ is in $K$ because $K/\\QQ$ is Galois!\n\n\tSince $\\NK(x)$ is an integer and divisible by $\\kp_1$,\n\twe should have that $\\NK(x)$ is divisible by $p$.\n\tThus it should be divisible by $\\kp_2$ as well.\n\tBut by the way we selected $x$, we have $x \\notin \\sigma\\inv\\kp_2$ for every $\\sigma \\in G$!\n\tSo $\\sigma(x) \\notin \\kp_2$ for any $\\sigma$, which is a contradiction.\n\\end{proof}\n\\begin{theorem}[Inertial degree and ramification indices are all equal]\n\tAssume $K/\\QQ$ is Galois.\n\tThen for any rational prime $p$ we have\n\t\\[ p \\cdot \\OO_K = \\left( \\kp_1 \\kp_2 \\dots \\kp_g \\right)^e \\]\n\tfor some $e$, where the $\\kp_i$ are distinct prime ideals\n\twith the same inertial degree $f$.\n\tHence \\[ [K:\\QQ] = efg. \\]\n\\end{theorem}\n\\begin{proof}\n\tTo see that the inertial degrees are equal, note that each $\\sigma$\n\tinduces an isomorphism\n\t\\[ \\OO_K / \\kp \\cong \\OO_K / \\sigma(\\kp). \\]\n\tBecause the action is transitive, all $f_i$ are equal.\n\t\\begin{exercise}\n\t\tUsing the fact that $\\sigma \\in \\Gal(K/\\QQ)$,\n\t\tshow that \\[ \\sigma\\im(p \\cdot \\OO_K) = p \\cdot \\sigma\\im(\\OO_K) = p \\cdot \\OO_K. \\]\n\t\\end{exercise}\n\tSo for every $\\sigma$, we have that\n\t$p \\cdot \\OO_K = \\prod \\kp_i^{e_i} = \\prod (\\sigma\\kp_i)^{e_i}$.\n\tSince the action is transitive, all $e_i$ are equal.\n\\end{proof}\n\nLet's see an illustration of this.\n\\begin{example}[Factoring $5$ in a Galois/non-Galois extension]\n\tLet $p = 5$ be a prime.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $E = \\QQ(\\cbrt2)$.\n\t\tOne can show that $\\OO_E = \\ZZ[\\cbrt2]$, so \n\t\twe use the Factoring Algorithm on the minimal polynomial $x^3-2$.\n\t\tSince $x^3-2 \\equiv (x-3)(x^2+3x+9) \\pmod 5$ is the irreducible factorization,\n\t\twe have that\n\t\t\\[ (5) = (5,\\cbrt2-3)(5, \\cbrt4+3\\cbrt2+9) \\]\n\t\twhich have inertial degrees $1$ and $2$, respectively.\n\t\tThe fact that this is not uniform reflects that $E$ is not Galois.\n\n\t\t\\ii Now let $K = \\QQ(\\cbrt2,\\omega)$, which is the splitting\n\t\tfield of $x^3-2$ over $\\QQ$; now $K$ is Galois.\n\t\tIt turns out that\n\t\t\\[ \\OO_K = \\ZZ[\\eps] \\quad\\text{where}\\quad \\eps \\text { is a root of } t^6+3t^5-5t^3+3t+1. \\]\n\t\t(this takes a lot of work to obtain, so we won't do it here).\n\t\tModulo $5$ this has an irreducible factorization\n\t\t$(x^2+x+2)(x^2+3x+3)(x^2+4x+1) \\pmod 5$,\n\t\tso by the Factorization Algorithm,\n\t\t\\[ (5) = (5, \\eps^2+\\eps+2)(5, \\eps^2+3\\eps+3)(5, \\eps^2+4\\eps+1). \\]\n\t\tThis time all inertial degrees are $2$, as the theorem predicts for $K$ Galois.\n\t\\end{enumerate}\n\\end{example}\n\n\\section{(Optional) Decomposition and inertia groups}\nLet $p$ be a rational prime.\nThus\n\\[ p \\cdot \\OO_K = \\left( \\kp_1 \\dots \\kp_g \\right)^e \\]\nand all the $\\kp_i$ have inertial degree $f$.\nLet $\\kp$ denote a choice of the $\\kp_i$.\n\nWe can look at both the fields $\\OO_K / \\kp$ and $\\ZZ / p = \\mathbb F_p$.\nNaturally, since $\\OO_K / \\kp$ is a finite field we can view it as a field extension of $\\OO_K$.\nSo we can get the diagram\n\\begin{diagram}\n\tK & \\supset & \\OO_K & \\kp & & \\OO_K / \\kp \\cong \\FF_{p^f} \\\\\n\t\\dLine && \\dLine & \\dLine & & \\dLine \\\\\n\t\\QQ & \\supset & \\ZZ & (p) & & \\FF_p.\n\\end{diagram}\nAt the far right we have finite field extensions, which we know are \\emph{really} well behaved.\nSo we ask:\n\\begin{quote}\n\t\\itshape\n\tHow are $\\Gal\\left( (\\OO_K/\\kp) / \\FF_p \\right)$\n\tand $\\Gal(K/\\QQ)$ related?\n\\end{quote}\nAbsurdly enough, there is an explicit answer:\n\\textbf{it's just the stabilizer of $\\kp$, at least when\n$p$ is unramified}.\n\\begin{definition}\n\tLet $D_\\kp \\subseteq \\Gal(K/\\QQ)$ be the stabilizer of $\\kp$, that is\n\t\\[ D_\\kp \\defeq \\left\\{ \\sigma \\in \\Gal(K/\\QQ) \\mid \\sigma\\kp = \\kp \\right\\}. \\]\n\tWe say $D_\\kp$ is the \\vocab{decomposition group} of $\\kp$.\n\\end{definition}\nThen, every $\\sigma \\in D_\\kp$ induces an automorphism of $\\OO_K / \\kp$ by\n\\[ \\alpha \\mapsto \\sigma(\\alpha) \\pmod\\kp. \\]\nSo there's a natural map\n\\[ D_\\kp \\taking\\theta \\Gal\\left( (\\OO_K/\\kp) / \\FF_p \\right) \\]\nby declaring $\\theta(\\sigma)$ to just be ``$\\sigma \\pmod \\kp$''.\nThe fact that $\\sigma \\in D_\\kp$ (i.e.\\ $\\sigma$ fixes $\\kp$)\nensures this map is well-defined.\n\n\\begin{theorem}[Decomposition group and Galois group]\n\t\\label{thm:decomposition}\n\tDefine $\\theta$ as above. Then\n\t\\begin{itemize}\n\t\t\\ii $\\theta$ is surjective, and\n\t\t\\ii its kernel is a group of order $e$,\n\t\tthe ramification index.\n\t\\end{itemize}\n\tIn particular, if $p$ is unramified then\n\t$D_\\kp \\cong \\Gal\\left( (\\OO_K/\\kp)/\\FF_p \\right)$.\n\\end{theorem}\n(The proof is not hard, but a bit lengthy and in my opinion\nnot very enlightening.)\n\n\\begin{moral}\n\tIf $p$ is unramified, then taking\n\tmodulo $\\kp$ gives\n\t$D_\\kp \\cong \\Gal\\left( (\\OO_K/\\kp) / \\FF_p \\right)$.\n\\end{moral}\n\nBut we know exactly what $\\Gal\\left( (\\OO_K/\\kp)/\\FF_p \\right)$ is!\nWe already have $ \\OO_K / \\kp \\cong \\FF_{p^f} $, and the Galois group is\n\\[\n\t\\Gal\\left( (\\OO_K/\\kp) / \\FF_p \\right)\n\t\\cong \\Gal\\left( \\FF_{p^f} / \\FF_p \\right)\n\t\\cong \\left< x \\mapsto x^p \\right>\n\t\\cong \\Zc f.\n\\]\nSo \\[ D_\\kp \\cong \\Zc f \\] as well.\n\nLet's now go back to\n\\[ D_\\kp \\taking\\theta \\Gal\\left( (\\OO_K/\\kp) : \\FF_p \\right). \\]\nThe kernel of $\\theta$ is called the \\vocab{inertia group}\nand denoted $I_\\kp \\subseteq D_\\kp$; it has order $e$.\n\nThis gives us a pretty cool sequence of subgroups\n$\\{1\\} \\subseteq I \\subseteq D \\subseteq G$\nwhere $G$ is the Galois group (I'm dropping the $\\kp$-subscripts now).\nLet's look at the corresponding \\emph{fixed fields} via the Fundamental theorem of Galois theory.\nPicture:\n\\begin{diagram}\n\t\\kp \\subseteq \\OO_K \\subseteq & K & \\rIsom & \\{1\\} \\\\\n\t& \\dLine^{\\text{Ramify}} & & \\dLine_e \\\\\n\t& K^I & & I \\\\\n\t& \\dLine^{\\text{Inert}} & & \\dLine_f \\\\\n\t& K^D & & D \\\\\n\t& \\dLine^{\\text{Split}} & & \\dLine_g \\\\\n\t(p) \\subseteq \\ZZ \\subseteq & \\QQ & \\rIsom & G\n\\end{diagram}\nSomething curious happens:\n\\begin{itemize}\n\t\\ii When $(p)$ is lifted into $K^D$ it splits completely into $g$ unramified primes.\n\tEach of these has inertial degree $1$.\n\t\\ii When the primes in $K^D$ are lifted to $K^I$, they remain inert, and now have\n\tinertial degree $f$.\n\t\\ii When then lifted to $K$, they ramify with exponent $e$ (but don't split at all).\n\\end{itemize}\nPicture:\nIn other words, the process of going from $1$ to $efg$\ncan be very nicely broken into the three steps above.\nTo draw this in the picture, we get\n\\begin{diagram}\n\t(p) & \\rTo & \\kp_1 \\dots \\kp_g & \\rTo & \\kp_1 \\dots \\kp_g & \\rTo & (\\kp_1 \\dots \\kp_g)^e \\\\\n\t\\{f_i\\}: && 1,\\dots,1 && f,\\dots,f && f,\\dots,f \\\\\n\t\\QQ & \\hLine_{\\text{Split}} & K^D & \\hLine_{\\text{Inert}} & K^I & \\hLine_{\\text{Ramify}} & K\n\\end{diagram}\nIn any case, in the ``typical'' case that there is no ramification,\nwe just have $K^I = K$.\n\n\\section{Tangential remark: more general Galois extensions}\nAll the discussion about Galois extensions\ncarries over if we replace $K/\\QQ$ by some different Galois extension $K/F$.\nInstead of a rational prime $p$ breaking down in $\\OO_K$,\nwe would have a prime ideal $\\kp$ of $F$ breaking down as\n\\[ \\kp \\cdot \\OO_L = (\\kP_1 \\dots \\kP_g)^e \\]\nin $\\OO_L$ and then all results hold verbatim.\n(The $\\kP_i$ are primes in $L$ above $\\kp$.)\nInstead of $\\FF_p$ we would have $\\OO_F/\\kp$.\n\nThe reason I choose to work with $F = \\QQ$ is that capital Gothic $P$'s ($\\kP$)\nlook \\emph{really} terrifying.\n\n\\section\\problemhead\n\\todo{more problems}\n% Cyclic Galois groups?\n\n\\begin{dproblem}\n\tProve that no rational prime $p$ can remain inert in\n\t$K = \\QQ(\\cbrt2, \\omega)$, the splitting field of $x^3-2$.\n\tHow does this generalize?\n\t\\begin{hint}\n\t\tShow that no rational prime $p$ can remain\n\t\tinert if $\\Gal(K/\\QQ)$ is not cyclic.\n\t\tIndeed, if $p$ is inert then $D_p \\cong \\Gal(K/\\QQ)$.\n\t\\end{hint}\n\\end{dproblem}\n", "meta": {"hexsha": "2db7e9916ffab0cc05cdabb83eeba5ac51a66cf6", "size": 15108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-NT/ramification.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/ramification.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/ramification.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.5040214477, "max_line_length": 107, "alphanum_fraction": 0.6599152767, "num_tokens": 5334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125626441471, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.6648086468926813}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Inside and Outside}\n\n\\objective{Graph and apply absolute value transformation}\n\n\n\\index{Absolute Value!Transformation}\nConsider what applying absolute value does as a \\emph{transformation}.\nFirst of all, what would $y=|f(x)|$ do?  Obviously, this will prevent $y$ from ever being negative.\nBut what happens to those negative segments of the function?  They --- and they alone ---\nare reflected over the $x$-axis.  This creates cusps at every turn, moments that will\nbe un-differentiable.\n\nWhat if we try $f(|x|)$?  This will cause negative inputs to receive the output as if they were\npositive.  Graphically, this means the left-half of our graph will be the mirror image of the\nright half.\n\n\\index{Absolute Value!of motion, terms}\n\\subsection{Distance, Velocity, Jerk}\nAbsolute value was invented to describe distance.  The verbal question ``how far is $x_1$ \nfrom $x_2$?'' is best represented as $|x_1-x_2|$.  Typically, we have some function modeling \n\\textbf{position} and then we contrast that position with something else, \nand are asking a question of  \\textbf{distance}.  What would have to be true about \nsome graph to leave it susceptible to change \nby the application of absolute values?  How can absolute value transformation produce\nundifferentiable moments in a graph?\n\nAnother common function to deal with in physics is a speed graph.  This too can be negative,\nwhich when converted to \\textbf{velocity}, might make issues. Another source of difficulty\nis when we disregard the sign of our input, effectively transforming into $f(|x|)$.  Thinking\ngraphically, how would the left side correspond to the right?  What kind of symmetry would\nsuch a transformation enforce?  The derivative of speed is position.\n\nLastly, we will often consider acceleration.  Most processes effected by acceleration \ndo not care if it is positive or negative (deceleration).  The absolute value of the \nacceleration is sometimes called  ``jerk'', though this term is not universally standardized.  \nThe derivative of acceleration is speed.\n\nStudies have begun to come out about higher orders, functions whose derivative is acceleration \n(called snap, crackle, and pop), but these terms are so rarely needed that the names are trivial.\n  \n", "meta": {"hexsha": "a018ba7d342de84566286656d4bfc65690acc33c", "size": 2270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch04/0401.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/0401.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/0401.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.7906976744, "max_line_length": 99, "alphanum_fraction": 0.7762114537, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.6647592482602105}}
{"text": "\n\\chapter{Relevant electromagnetic theory}\n\\label{appendix_maxwell}\n\n\n\\section{Maxwell's and Lorentz's equations}\n\nThe following four equations give a complete (non-quantum\\footnotemark{})\ndescription of the electric ($\\E$) and the magnetic field ($\\B$), in terms of\ncharge ($\\rho$) and current distributions ($\\J$) and the mutual interactions\nof $\\E$ and $\\B$ over time.\n\n\\footnotetext{At very small scales and very high field strengths (that are\nnot relevant in neuroscience), the more general theory of quantum\nelectrodynamics is needed.}\n\n\\begin{align}\n\\div{\\E} &= \\frac{\\rho}{\\epsilon_0} \\\\\n\\curl{\\E} &= -\\pdv{\\B}{t} \\\\\n\\div{\\B} &= 0 \\\\\n\\curl{\\B} &= \\frac{1}{c^2} \\qty( \\pdv{\\E}{t} + \\frac{\\J}{\\varepsilon_0} )\n\\end{align}\n%\n$\\varepsilon_0 \\approx \\SI{10}{\\pF\\per\\m}$ is the distributed capacitance of\nfree space, and $c \\approx \\SI{3e8}{\\m\\per\\s} = \\SI{300}{\\GHz\\mm}$ is the\nspeed at which changes in $\\E$ and $\\B$ propagate. (For an intuitive explanation of the $\\div$ and $\\curl$ notation, see \\cref{sec:div_curl}).\n\n% The first equation means that the electric field emanating from a tiny region of space is proportional to the amount of charge inside that region\n\nOne additional equation, the Lorentz force law, completes the description of\nclassical electromagnetism. Whereas Maxwell's equations describe the fields\nas caused by matter, Lorentz's equation describes the influence of the fields\non matter. Namely, a charged particle with velocity $\\vb{v}$ and charge $q$\nexperiences the following force:\n\\begin{equation}\n\\F = q \\qty(\\E + \\vb{v} \\cross \\B)\n\\end{equation}\n\nMobile charges and the electric and magnetic fields therefore interact with\neach other through feedback. This results in often very complex charge\nmovements and field dynamics, until a steady state is reached.\n\n\n\n\n\n\\section{Statics}\n\nWhen the time derivatives in Maxwell's equations are negligible, the electric and magnetic field become decoupled. The four equations then reduce to the governing equations for electrostatics:\n%\n\\begin{align}\n\\div{\\E} &= \\frac{\\rho}{\\epsilon_0} \\\\\n\\curl{\\E} &= 0,\n\\end{align}\n\nand for magnetostatics:\n%\n\\begin{align}\n\\div{\\B} &= 0 \\\\\n\\curl{\\B} &= \\frac{\\J}{c^2 \\varepsilon_0}.\n\\end{align}\n\n\n\n\n\n\\section{Electric field potential}\n\\label{sec:appendix_potential}\n\nThe relationship between the electric field $\\E(\\loc,t)$ and the electric potential $\\phi(\\loc,t)$ is as follows. The electric potential difference between two points $\\loc_a$ and $\\loc_b$ is the negative line integral of the electric field along any curve connecting these two points (where $\\dd{\\s}$ is a tiny vector lying along the curve):\n%\n\\begin{equation}\n\\phi(\\loc_a,t) - \\phi(\\loc_b,t) \n    = - \\int_{\\loc_a}^{\\loc_b} \\E(\\loc,t) \\vdot \\dd{\\s}\n\\end{equation}\n%\nAn equivalent and arguably more elegant definition is the following. The electric field is the negative spatial gradient of the electric potential:\n%\n\\begin{equation}\n\\label{eq:potential_gradient}\n\\E(\\loc,t) = -\\grad{\\phi(\\loc,t)},\n\\end{equation}\n%\ni.e. the electric field points from locations of high potential to locations of lower potential.\n\nFrom \\cref{eq:potential_gradient}, it is clear that the electric potential is only defined up to a constant (and that therefore only the electric potential \\emph{difference} between two points is absolutely defined). We can easily define an absolute potential $\\phi(\\loc,t)$ however by fixing the voltage at a certain reference point. It makes sense to shift the electric potential such that it is zero for a reference point with no charges around (neither positive or negative); or equivalently, when the charges around this point balance each other out. (This is also what physicists do when they define the absolute electric potential at some point as the line integral of the electric field from that point to infinity, where it is implicitly assumed that infinity is uncharged).\n\n\n\n\n\n\n\n\\section{Divergence and curl}\n\\label{sec:div_curl}\n\n\\subsection{Divergence}\n\nThe divergence of a vector field at a certain point, $\\div{\\F}$, is a scalar\nvalue that measures the net flow of $\\F$ out of ($+$) or into ($-$) a very\nsmall volume centered on this point.\n\nThis net flow or `flux' $\\varphi$ of the field $\\F$ through a volume $V$ is\nthe sum of individual flows through the surface of the volume. To calculate\nthis sum, the bounding surface $S$ of the volume is divided into small\nsurface patches $\\dd{A}$. When the outward-pointing normal vector on such a\nsurface patch is denoted by $\\n$, the flow through this patch $\\dd{A}$ can be\nwritten as $\\F \\cdot \\n$. When the field vector $\\F$ and the normal vector\n$\\n$ point in the same direction, the field is flowing out of the volume at\nthat location, and this inner product is positive. When they point in\nopposite directions, the field is flowing into the volume, and the product is\nnegative.\n\nSymbolically, this is summarised as:\n\\[\n\\varphi = \\iint_S{\\F \\cdot \\n \\dd{A}},\n\\]\n\nThe divergence is then simply this flux for a very small volume $V$, and\nnormalised by the size of the volume, $\\abs{V}$:\n\\[\n\\div{\\F} = \\lim_{\\abs{V} \\to 0}{\\frac{\\varphi}{\\abs{V}}}\n\\]\n\n\n\\subsection{Curl}\n\nThe curl $\\curl{\\F}$ of a vector field is a similarly intuitive measure, in\nthe limit for small surfaces. In contrast with divergence however, the curl\nof a three-dimensional vector field at some point is not a scalar, but a\nthree-dimensional vector. (In two dimensions however, the curl is a\nscalar)\\footnote{This is because rotations in 2D are fully described with one\nnumber, while in 3D, curiously, three numbers are needed to fully describe\nthem}. We define one component of the curl, along one coordinate axis\n$\\xhatv$. The definitions for the other two coordinate axes are analogous.\n\nThe curl $\\qty(\\curl{\\F}) \\cdot \\xhatv$ of a vector field at a certain point\nand along the axis $\\xhatv$, is a scalar value that measures the rotation of\n$\\F$, or the net flow of $\\F$ along a small loop, around $\\xhatv$. This loop\nmust lie in a plane that is perpendicular to the $\\xhatv$ axis and that goes\nthrough the point where the curl is measured. The curl along $\\xhatv$ is\npositive when the net flow along this loop is counterclockwise, and negative\nwhen it is clockwise.\n\nLet the loop be a closed path $C$ that encloses a planar surface $A$. The\nloop $C$ is divided in many counterclockwise-oriented vectors $\\dd{\\vb{l}}$.\nThe rotation or net flow $O$ of $\\F$ along the loop $C$ is then:\n\\[\nO = \\int_C{\\F \\cdot \\dd{\\vb{l}}}\n\\]\n\nThe curl in the $\\xhatv$ direction is then this net loop flow, for a very\nsmall loop and normalised by the size of the enclosed surface, $\\abs{A}$:\n\\[\n\\qty(\\curl{\\F}) \\cdot \\xhatv = \\lim_{\\abs{A} \\to 0}{\\frac{O}{\\abs{A}}}\n\\]\n\n\n\n% \\section{Macroscopic formulation}\n\n% Here, we divide charges between free and bound:\n% Q = Q_b + Q_f\n% \\rho = \\rho_b + \\rho_f\n\n% The bound charge is most conveniently described in terms of the polarization P(r,t) of the material, its dipole moment per unit volume.\n% % If P is uniform, a macroscopic separation of charge is produced only at the surfaces where P enters and leaves the material. For non-uniform P, a charge is also produced in the bulk.\n% % Nunez: \"In tissue Pc [our P] is due mainly to membrane charge, which is much larger than the molecular and atomic charge effects common to physical materials.\"\n\n% Displacement field D (like E, but only due to free charges):\n% D(r,t) = eps_0 E(r,t) + P(r,t)\n\n% For linear, isotropic materials without additional polarisation\n% (\"constitutive law\"):\n% D(r,t) = eps E(r,t)\n\n% permittivity (distributed capacitance):\n% eps = eps_r eps_0\n% kappa = eps_r = eps / eps_0  (relative dielectric constant)\n\n% In anisotropic material, eps is a matrix.\n% In a nonlinear material, eps depends on the strength of the field.\n\n% The very complicated and granular bound charges and bound currents, therefore, can be represented on the macroscopic scale in terms of P and M, which average these charges and currents on a sufficiently large scale so as not to see the granularity of individual atoms, but also sufficiently small that they vary with location in the material.\n", "meta": {"hexsha": "2c5658bac665c5d2baafc40131be5d5e8386d50f", "size": 8096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Scraps/appendices/Maxwell.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/Scraps/appendices/Maxwell.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/Scraps/appendices/Maxwell.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": 43.7621621622, "max_line_length": 783, "alphanum_fraction": 0.7399950593, "num_tokens": 2138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6646868862730685}}
{"text": "\\chapter*{Notation}\n\nWe suggest to settle some notational issues as follows. \n\\begin{enumerate}\n\\item input data variables\n  \\begin{equation}\n    \\label{eq:1}\nx, \\quad y    \n  \\end{equation}\nIn MgNet paper we keep using $f$ for data to match the notation\nwith the PDE since this is a special case.\n\\item number of dimension of the input data\n  \\begin{equation}\n    \\label{dim}\nd, \\quad x\\in \\mathbb R^d    \n  \\end{equation}\n\\item the weights\n  \\begin{equation}\n    \\label{weights}\nWx+b; W\\in\\mathbb R^{\\kappa\\times d}, b\\in \\mathbb R^\\kappa,\n\\theta=(W,b)\\in\\mathbb R^{\\kappa\\times(d+1)}\n\\end{equation}\n\\item number of classification class:\n  \\begin{equation}\n    \\label{k} \\kappa    \n  \\end{equation}\n\\item Number of iterations\n  \\begin{equation}\n    \\label{iterations}\nt\n  \\end{equation}\nsuch as\n$$\n\\theta^{t+1}=\\theta^t-\\eta_t \\nabla f_{i_t}(\\theta^t)\n$$\n\\item Learning rate\n  \\begin{equation}\n    \\label{learningrate}\n\\eta    \n  \\end{equation}\n\n\\item independent variables for optimization algorithm\nfor general optimizations, use x,y, like\n$$\nx^*=\\arg\\min_{x}f(x)\n$$\nand\n$$\nf(y)\\ge f(x)+\\nabla f(x)\\cdot (y-x)\n$$\nWhen the problem involves deep learning or machine learning  models, use $\\theta$\n$$\n\\theta^*=\\arg\\min_{\\theta}f(\\theta)\n$$\n\\begin{remark}\nIn RDA, we will use w instead.\n\\end{remark}\n\n\n\\end{enumerate}\n\n\n", "meta": {"hexsha": "6fc85a64e28293b4bbd932e670855bc6cdc19464", "size": 1320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/notation.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/notation.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/notation.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": 20.9523809524, "max_line_length": 81, "alphanum_fraction": 0.6818181818, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.664686878141437}}
{"text": "\\documentclass[12pt,english]{article}\n\n\\usepackage[colorlinks=true, linkcolor=blue, citecolor=blue, plainpages=false, pdfpagelabels=true, urlcolor=blue]{hyperref}\n\\usepackage[bottom]{footmisc}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{assumption}{Assumption}[section]\n\n\\newtheorem{proposition}{Proposition}\n\\newtheorem{definition}{Definition}\n\n\\usepackage{blindtext}\n\n\\usepackage{mathtools}\n\\usepackage{bm}\n\n\\begin{document}\n\n\\title{Math Testing}\n\\author{\\href{http://fanwangecon.github.io/}{Fan Wang} \\thanks{See \\href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ} for more latex examples.}}\n\n\\maketitle\n\n\\section{Discrete Allocations}\n\n\\subsection{Binary Allocation}\n\nTheorems in each section and corollaries follow section numbering. See \\href{https://www.overleaf.com/learn/latex/Theorems_and_proofs}{theorems and proofs}\n\n\\subsubsection{Allocation Space}\n\n\\begin{assumption}\n    \\label{as:1a}\n    \\begin{align}\n         f(x)  &= a x^2+b x +c   &   g(x)  &= d x^3 \\\\\n         f'(x) &= 2 a x +b       &   g'(x) &= 3 d x^2\n    \\end{align}\n    \\end{assumption}\n    \n\\blindtext\n\n\\subsubsection{Optimal Targeting Queue}\n\n\\begin{theorem}\n\\label{thm:1a}\n\\blindtext\n\\begin{align}\n    f(x) &= (x+a)(x+b) \\\\\n         &= x^2 + (a+b)x + ab\n\\end{align}\n\\blindtext\n\\end{theorem}\n\n\\blindtext\n\n\\subsubsection{Special Cases}\n\n\\begin{corollary}\n\\label{corr:1a}\n$$x^n + y^n = z^n$$\n\\blinditemize\n\\end{corollary}\n\n\\begin{corollary}\n\\label{corr:1b}\n\\[\n f(x) = \\begin{dcases*}\n        x  & when $x$ is even\\\\\n        -x & when $x$ is odd\n        \\end{dcases*}\n\\]\n\\end{corollary}\n\n\\subsection{Discrete Allocations}\n\n\\subsubsection{Discrete Allocation Space}\n\n\\begin{assumption}\n\\label{as:1b}\n\\begin{equation}\n \\boxed{x^2+y^2 = z^2}\n\\end{equation}\n\\end{assumption}\n\n\\subsubsection{Optimal Targeting Discrete Queues}\n\n\\begin{theorem}\n\\label{thm:1b}\n\\blinddescription\n\\begin{alignat}{2}\n \\sigma_1 &= x + y  &\\quad \\sigma_2 &= \\frac{x}{y} \\\\\n \\sigma_1' &= \\frac{\\partial x + y}{\\partial x} & \\sigma_2'\n    &= \\frac{\\partial \\frac{x}{y}}{\\partial x}\n\\end{alignat}\n\\end{theorem}\n\n\\blindtext\n\n\\section{Continuous Allocations}\n\n\\blindtext\n\n\\subsection{Lower Bounded Continuous Allocations}\n\n\\subsubsection{Allocation Space}\n\n\\blindtext\n\n\\begin{assumption}\n\\label{as:2a}\n\\[\n u(x) =\n  \\begin{cases}\n   \\exp{x} & \\text{if } x \\geq 0 \\\\\n   1       & \\text{if } x < 0\n  \\end{cases}\n\\]\n\\end{assumption}\n\n\\subsubsection{Tageting Queues}\n\n\\begin{theorem}\n\\label{thm:2a}\n\\blindenumerate\n\\[\n\\lim_{x\\to 0}{\\frac{e^x-1}{2x}}\n\\overset{\\left[\\frac{0}{0}\\right]}{\\underset{\\mathrm{H}}{=}}\n\\lim_{x\\to 0}{\\frac{e^x}{2}}={\\frac{1}{2}}\n\\]\n\\blindtext\n\\end{theorem}\n\n\\subsubsection{Special cases}\n\n\\begin{corollary}\n\\label{corr:2a}\n\\[\nz = \\overbracket[3pt]{\n\t\t\\underbracket{x}_{\\text{real}} +\n\t\t\\underbracket[0.5pt][7pt]{iy}_{\\text{imaginary}}\n\t\t}^{\\text{complex number}}\n\\]\n\\blinditemize\n\\end{corollary}\n\n\\subsection{Lower and Upper Bounded Continuous Allocations}\n\\begin{theorem}\n\\label{thm:2b}\n\\begin{gather}\n a \\xleftrightarrow[under]{over} b\\\\\n%\n A \\xLeftarrow[under]{over} B\\\\\n%\n B \\xRightarrow[under]{over} C\\\\\n%\n C \\xLeftrightarrow[under]{over} D\\\\\n%\n D \\xhookleftarrow[under]{over} E\\\\\n%\n E \\xhookrightarrow[under]{over} F\\\\\n%\n F \\xmapsto[under]{over} G\\\\\n\\end{gather}\n\\end{theorem}\n\n\n\\end{document}\n", "meta": {"hexsha": "af302ad1f212063c4587916d1f7fdf78dffa86b8", "size": 3319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_support/math/file/theory_test.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": "_support/math/file/theory_test.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": "_support/math/file/theory_test.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": 19.6390532544, "max_line_length": 155, "alphanum_fraction": 0.6776137391, "num_tokens": 1181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6646040135248799}}
{"text": "\\chapter{Differential Equations}\nIn physics we encounter differential equations all the time. In fact the whole programme of classical mechanics is to develop a second order differential equation using Newton's laws of motion and then solving it.\\\\Sometimes these are ordinary\ndifferential equations in one variable (abbreviated ODEs). More often the equations are\npartial differential equations (PDEs) in two or more variables. Simply we can say , differential equations is a relation between a function and its derivatives.\n\\begin{definition}\n\tA differential equation is an equation which involves independent and dependent variables and their derivatives or differentials.\n\\end{definition}\n\\begin{example}\n\t\\hspace{1cm}\n\\begin{itemize}\n\t\t\\item $\\frac{dy}{dx}={4x-2}$\n\t\t\\item $\\frac{d^{2}y}{dx^{2}}=5\\frac{dy}{dx}+10$\n\t\t\\item $(1+\\frac{dy}{dx})^{3}=k\\frac{dy}{dx}$\n\t\t\\item $\\frac{dy}{dx}+xy=x^{3}y^{3}$\n\t\t\\item $\\frac{\\partial^{2}y}{\\partial^{2} x}=\\frac{1}{c^{2}} \\frac{\\partial^{2}y}{\\partial^{2} x} $\n\t\t\\item $\\frac{\\partial u}{\\partial t}=\\frac{\\partial u}{\\partial x}+\\frac{\\partial u}{\\partial y}$\n\t\\end{itemize}\n\\end{example}\n\\section{{Types of differential equation}}\nThere are mainly two types of differential equations,\n\t\\begin{itemize}\n\t\\item \\textbf{Ordinary differential equations.}\\par A differentnial equation involving derivatives with respect to a single variable is called an ordinary differential equation. \n\t\\\\\\\\\n\t\\textbf{General form:} $\\frac{d y}{d x}=f(x, y)=-\\frac{P(x, y)}{Q(x, y)}$\n\t\\begin{example}\n\t\t\\begin{align*}\n\t\tF&=m\\frac{d v}{dt}\\\\\n\t\t\\frac{dy}{dx}+x&= 1\n\t\t\\end{align*}\n\t\\end{example}\n\t\\item \\textbf{Partial differential equations.}\\par A differential equation involving partial derivatives with respect to more than one independent variable is called a partial differential equation.\n\t\\begin{example}\n\t\t\\begin{align*}\n\t\t\\intertext{\\textbf{Poisson's equation:}}\n\t\t\\nabla^{2}\\psi&= \\frac{\\rho}{\\epsilon_{0}}\\\\\n\t\t\\left( \\frac{\\partial ^{2}}{\\partial x^{2}}+\\frac{\\partial ^{2}}{\\partial y^{2}}+\\frac{\\partial ^{2}}{\\partial z^{2}}\\right)\\psi &= \\frac{\\rho}{\\epsilon_{0}}\\qquad (\\text{In cartesian coordinate system.})\n\t\t\\intertext{\\textbf{Schrodinger Equation:}}\n\t\t\\left(-\\frac{h^{2}}{2 m} \\nabla^{2}+V\\right) \\psi&=i \\hbar \\frac{\\partial \\psi}{\\partial t}\n\t\t\\end{align*} \n\t\\end{example}\n\t\\end{itemize}\n\\section{Order and Degree of a differential equation}\n\\textbf{Order:}\\\\The order of a differential equation is the highest differential in the equation.\\\\\\\\\n\\textbf{Degree:}\\\\The degree of a differential equation is the power of the highest differential in the equation.\n\\begin{example}\n\t\\hspace{0.5cm}\n\t\\begin{itemize}\n\t\t\\item $\\left(\\frac{\\partial^{2} y}{\\partial x^{2}}\\right)^{2}+\\left(\\frac{\\partial y}{\\partial x}\\right)-\\left(\\frac{\\partial^{3} y}{\\partial x^{3}}\\right)=x y$\\hspace{0.5cm}Order=2 ,Degree=2\n\t\t\\item   $ L \\frac{d^{2} q}{d t^{2}}+R \\frac{d q}{d t}+\\frac{q}{c}=E \\sin \\omega t$\\hspace{1cm}Order=2 ,Degree=1\n\t\t\\item $\\frac{dy}{dx}+xy=x^{3}y^{3}$ \\hspace{2.7cm}Order=1 ,Degree=1\n\t\t\\item $\\left(\\frac{\\mathrm{d}^{2} \\mathrm{y}}{\\mathrm{d} \\mathrm{x}^{2}}\\right)^{3}=\\left[1+\\left(\\frac{\\mathrm{dy}}{\\mathrm{dx}}\\right)^{4}\\right]^{5}$\n\t \\hspace{1.1cm} Order=2 ,Degree =3\n\t \\item $\\frac{d^{3} y}{d x^{3}}-\\left(\\frac{d y}{d x}\\right)^{\\frac{1}{2}}=0$ \\hspace{2.3cm} Order=3 ,Degree=2\n\t\\end{itemize}\n\\end{example}\n\\begin{exercise}\nFind the order and degree of the given differential equations, \n\n\\begin{enumerate}\n\t\\item $\\frac{d^{3} y}{d x^{3}}-\\left(\\frac{d y}{d x}\\right)^{\\frac{1}{2}}=0$\n\t\\item $\\left[1+\\frac{d^{2} y}{d x^{2}}\\right]^{\\frac{3}{2}}=a \\frac{d^{2} y}{d x^{2}}$\n\\end{enumerate}\n\\end{exercise}\n\\begin{answer}\\hspace{0.5cm}\n\\begin{enumerate}\n\t\\item Here we need to eliminate the radical sign.\n\tFor this write the equation as\n\t\\\\\\begin{align*}\n\t\\frac{d^{3} y}{d x^{3}}&=\\left(\\frac{d y}{d x}\\right)^{\\frac{1}{2}}\\\\\\text{ Squaring both sides, we get  }\\\\\\left(\\frac{d^{3} y}{d x^{3}}\\right)^{2}&=\\frac{d y}{d x}\\\\\n\t\\therefore \\quad  \\text{Order} =3,\\text{degree} =2\n\t\\end{align*}\n\t\\item Here we eliminate the radical sign. For this write the equation as\n\t\n   \\begin{align*}\n\t\\left[1+\\frac{d^{2} y}{d x^{2}}\\right]^{\\frac{3}{2}}&=a \\frac{d^{2} y}{d x^{2}}\n\t\\\\\\text{ Squaring both sides, we get  }\\\\\\left[1+\\frac{d^{2} y}{d x^{2}}\\right]^{3}&=a^{2}\\left(\\frac{d^{2} y}{d x^{2}}\\right)^{2}\\\\\n\t\\therefore \\quad  \\text{Order} =2,\\text{degree} =3\n\t\\end{align*}\n\\end{enumerate}\n\\end{answer}\n\\begin{note}\nThe direction of a curve at a particular point is given by the tangent line at that point and the slope of the tangent is given by $\\frac{dy}{dx}$ at that point.\t\n\\end{note}\n\\section{First order differential equation}\nAn equation of the general form\n$$\n\\frac{d y}{d x}=-\\frac{f(x, y)}{g(x, y)}\n$$\nIs said to be a first order differential equation.The equation contains first and no higher derivatives. The only derivative here $\\frac{d y}{d x}$ is a total or ordinarry derivative not a partial one.\n\\section{Geometrical meaning of First order First degree differential equations}\n\\begin{wrapfigure}{r}{0.5\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.25\\textwidth]{03-crop}\n\t\\end{center}\n\t\\caption{Geometrical meaning of Differential equation}\n\\end{wrapfigure}\nThe solution of every  first order first degree differential equations represent a family of curves.\n\\\\\\\\Let, $f\\left(x, y, \\frac{d y}{d x}\\right)=0$\\quad  represents a differential equation of  first order and first degree.\\\\\\\\\nTaking $A\\left(x_{0}, y_{0}\\right)$ as an initial point,we\ncan find $\\frac{d y}{d x}$ at $A\\left(x_{0}, y_{0}\\right)$. And with the help of that we can draw the tangent at the point $A$.\\\\\\\\\nOn the tangent line take a neighbouring point $B\\left(x_{1}, y_{1}\\right)$. Find $\\frac{d y}{d x}$ at the point $B\\left(x_{1}, y_{1}\\right)$and draw the tangent at $B$. And in this way draw another tangent at the point $C$ on the tangent line $B$ . Similarly draw, some more tangents by taking the neighbouring points on them. Again we take another starting point $A^{\\prime}\\left(x_{0}^{\\prime}, y_{0}^{\\prime}\\right)$. We can draw another curve starting from\n$A^{\\prime} .$ In this way we can draw a number of curves. They form a smooth curve. \\\\\nThat is the given difrential equation represents a family of curves.\n\n\\section{Solution of a differential equation}\nA solution of a differential equation is any relation\nbetween variables which is free of derivatives and which\nsatisfies the differential equation.\\\\\\\\\n\\textbf{General solution:}\\\\ A general solution is the solution in which the number\nof arbitrary constants and the order of the differential\nequation are same.\\\\\\\\\n\\textbf{Particular solution:}\\\\ A particular solution is the solution which can be\nobtained by giving particular values to arbitrary constants of general solution.\n\n\\section{Solution of First order differential equations}\nThe solutions of first order differential equations are obtained by various methods,\n\\section{ Method of seperation of variables}\nIf all functions of $x$ and $d x$ can be arranged on one side and $y$ and $d y$ on the other side, then the variables are separable. The solution of this equation is found by integrating the functions of $x$ and $y$.\n$$f(x) d x=g(y) d y\\Longrightarrow\n\\int f(x) d x=\\int g(y) d y+C\n$$\n\\textbf{\\large Method of solving:}\n\\begin{enumerate}\n\t\\item  Separate the variables as $f(x) d x=g(y) dy$.\n    \\item Integrate both sides as $\\int f(x) d x=\\int g(y) d y$.\n    \\item  Add an arbitrary constant $C$ on R.H.S.\n\\end{enumerate}\n\\begin{exercise}\nSolve\t$\\cos (x+y) d y=d x$\n\\end{exercise}\n\\begin{answer}[H]\n\t\\begin{align*}\n\t\t\\cos (x+y) d y&=d x \\\\\n\t\t\\frac{d y}{d x}&=\\sec (x+y)\\\\\n\t\t\\text{  Let, }x+y&=z\\\\\n\t\t\\text{  Then, }1+\\frac{d y}{d x}=\\frac{d z}{d x} \\quad & \\Rightarrow \\quad \\frac{d y}{d x}=\\frac{d z}{d x}-1 \\\\\n\t\t\\frac{d z}{d x}-1=\\sec z \\quad &\\Rightarrow \\quad  \\frac{d z}{d x}=1+\\sec z\\\\\n\t\t\\text{Separating the variables, we get, }\\\\\\frac{d z}{1+\\sec z}&=d x\\\\\n\t\t\\text{On integrating,}\\\\\n\t\t\\int \\frac{\\cos z}{\\cos z+1} d z&=\\int d x\\\\\n\t\t\\int\\left[1-\\frac{1}{\\cos z+1}\\right] d z&=x+C \\\\\n\t\t\\int\\left[ 1-\\frac{1}{2 \\cos ^{2} \\frac{z}{2}-1+1}\\right]  d z&=x+C \\\\\n\t\t\\int\\left(1-\\frac{1}{2} \\sec ^{2} \\frac{z}{2}\\right) d z&=x+C\\\\\n\t\t\\int\\left(1-\\frac{1}{2} \\sec ^{2} \\frac{z}{2}\\right) d z&=x+C\\\\\n\t\tz-\\tan \\frac{z}{2}&=x+C  \\\\\n\t\tx+y-\\tan \\frac{x+y}{2}&=x+C\\\\\n\t\t y-\\tan \\frac{x+y}{2}&=C \n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tSolve $e^{d y / d x}=(x+1) ;$ given $y=3$ at $x=0$\n\\end{exercise}\n\\begin{answer}\n\tTaking log of both sides we get, \n\t\\begin{align*}\n\t\t\\frac{d y}{d x}=\\ln (x+1)\\quad &\\Rightarrow \\quad d y=\\ln (x+1) d x\\\\\\text{on integration }, \\\\\\int d y=\\int 1 \\cdot \\ln (x+1) d x \\quad &\\Rightarrow \\quad y=x \\ln (x+1)-\\int \\frac{x}{(x+1)} d x+C\\\\\n\t\ty&=x \\ln (x+1)-\\int \\frac{(x+1)-1}{(x+1)} d x+C\\\\ y&=x \\ln (x+1)-\\int \\frac{(x+1)}{(x+1)} d x+\\int \\frac{1}{(x+1)} d x+C\\\\&=x \\ln (x+1)-x+\\ln (x+1)+C\\\\y&=(x+1) \\ln (x+1)-x+C\\\\\\text{Given: at,}\\ x&=0 \\quad y=3 \\Rightarrow \\quad C=3\\\\\n\t\t\\text{Therefore,}\\ y&=(x+1) \\ln (x+1)-x+3\n\t\\end{align*}\n\t\n\\end{answer}\n\\section{Solution of Homogeneous differential equation}\nHomogeneous equations are of the form,\n$$\n\\frac{d y}{d x}=\\frac{f(x, y)}{g(x, y)}\n$$\nWhere $f(x, y)$ and $g(x, y)$ are homogeneous functions of the same degree in $x$ and $y$. Homogeneous functions are those in which all the terms are of $n^{th}$  degree.\\\\\\\\ \n\\textbf{\\large Method of solving}\n\\begin{enumerate}\n\t\\item  Put, $y=v x,$ then $\\frac{d y}{d x}=v+x \\frac{d y}{d x}$.\n\t\\item  Separate $v$ and $x$ and then integrate.\\\\\\\\\n\t$\n\t\\begin{aligned}\n\t \\frac{d y}{d x}&=f(y / x) \\\\\n\t\\Rightarrow  \\hspace{1.1cm}y / x&=v \\\\\n\t\\Rightarrow \\hspace{0.3cm}\\frac{d v}{f(v)-v}&=\\frac{d x}{x} \\\\\n\t\\Rightarrow  \\int \\frac{d v}{f(v)-v}&=\\log x+C \n\t\\end{aligned}\n\t$\n\\end{enumerate}\n\\begin{exercise}\n\tSolve the differential equation $\\left(x^{2}-y^{2}\\right) d x+2 x y$ $d y=0,$ given that $y=1$ when $x=1$\n\\end{exercise}\n\\begin{answer}\n\n\t\\begin{alignat*}{2}\n\t\t\\left(x^{2}-y^{2}\\right) d x+2 x y d y&=0\\\\\n\t\t\t\\left(x^{2}-y^{2}\\right) d x&=-2 x y d y \\\\\n\t\t\t\\frac{d y}{d x}=-\\frac{x^{2}-y^{2}}{2 x y}&=\\frac{y^{2}-x^{2}}{2 x y}\\\\\n\t\t\t\\text{Putting  } y=v x  \\quad &\\text{and} \\quad \\frac{d y}{d x}=v+x \\frac{d v}{d x}\\\\\n\t\t\t\\text{ We get}\n\t\t\t\\quad v+x \\frac{d v}{d x}&=\\frac{v^{2} x^{2}-x^{2}}{2 x \\cdot v x}\\\\\n\t\t\t\\Rightarrow \\hspace{2cm}\\quad v+x \\frac{d v}{d x}&=\\frac{v^{2}-1}{2 v}\\\\\n\t\t\t\\Rightarrow\\hspace{2.7cm} x \\cdot \\frac{d v}{d x}&=\\frac{v^{2}-1}{2 v}-v\\\\&=\\frac{v^{2}-1-2 v^{2}}{2 v}\\\\&=-\\left[\\frac{v^{2}+1}{2 v}\\right]\\\\\n\t\t\t\\Rightarrow \\hspace{1.5cm}\\quad \\frac{2 v}{v^{2}+1} \\cdot d v&=-\\frac{d x}{x}, \\quad x \\neq 0\\\\\n\t\t\t\\Rightarrow \\hspace{1.1cm}\\quad \\int \\frac{2 v}{v^{2}+1} \\cdot d v&=-\\int \\frac{d x}{x}\\\\\n\t\t\t\\Rightarrow \\hspace{1.3cm}\\quad \\log \\left(v^{2}+1\\right)&=-\\log |x|+c\\\\\n\t\t\t\\Rightarrow \\quad \\log \\left(v^{2}+1\\right)+\\log |x|&=\\log c\\\\\n\t\t\t\\Rightarrow \\hspace{1.5cm}\\quad\\left(v^{2}+1\\right)|x|&=c\\\\\n\t\t\t\\text{Now, putting }v&=y / x\\\\\n\t\t\t\\left(y^{2} / x^{2}+1\\right)|x|&=c \\\\\n\t\t\t\\Rightarrow \\left(x^{2}+y^{2}\\right)&=c|x|\\\\\\text{\tWhich is similar to } x=1 \\quad \\text{and} \\quad y=1, \\text{we get,}c&=2\\\\\\text{Putting value of} \\quad c&=2 ,\\text{We get}\\\\x^{2}+y^{2}&=2 x \\text { or } x^{2}+y^{2}=2(-x)\\\\x=1 &\\quad \\text{and}\\quad y=1 \\\\\\text{Do not satisfy}\\quad x^{2}+y^{2}&=2(-x) \\\\\\text{Hence,}\\quad x^{2}+y^{2}&=2 x \\quad \\text{is the required solution.}\n\t\\end{alignat*}\n\\end{answer}\n\n\\subsection{Equations reducible to homogeneuos form}\nLet a differential equation be,\n$$\n\\frac{d y}{d x}=\\frac{a x+b y+c}{A x+B y+C}\n$$\n\\textbf{Type-1}\\\\\n\n\\begin{align*}\n\\text{If, in the above equation,}\\quad\\frac{a}{A}&\\neq\\frac{b}{B}\\\\\\text{Then we can substitute}\\quad x=X+h\\quad&,\\quad y=Y+k,\\text{($h, k$ being constants)}\\\\\n\\text{The given differential equation reduces to}\\\\\n\\frac{d Y}{d X}&=\\frac{a(X+h)+b(Y+k)+c}{A(X+h)+B(Y+k)+C}\\\\&=\\frac{a X+b Y+a h+b k+c}{A X+B Y+A h+B k+C}\\\\\n\\text{Choose $h, k$ so that} \\quad a h+b k+c&=0\\\\\nA h+K k+C&=0\\\\\n\\text{Then the given equation becomes homogeneous}\\\\\\frac{d Y}{d X}&=\\frac{a X+b Y}{A X+B Y}\n\\end{align*}\n\\textbf{Type-2}\\\\\n\\begin{align*}\n\\text{If}\\ \\frac{a}{A}&=\\frac{b}{B},\\\\\n\\text{Then the value of $h, k$ will not be finite.}\\\\\n\\frac{a}{A}&=\\frac{b}{B}=\\frac{1}{m}\\\\\nA=a m\\quad, \\quad B&=b \\mathrm{~m}\\\\\n\\text{The given equation becomes}\\quad\\frac{d y}{d x}&=\\frac{a x+b y+c}{m(a x+b y)+C}\n\\end{align*}\n Now put $a x+b y=z$ and apply the method of variables separable.\n \\begin{exercise}\n \tSolve $(x+2 y)(d x-d y)=d x+d y$\n \\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t(x+2 y)(d x-d y)&=d x+d y \\\\\\Rightarrow(x+2 y-1) d x-(x+2 y+1) d y&=0\\\\\n\t\\Rightarrow  \\frac{d y}{d x}&=\\frac{x+2 y-1}{x+2 y+1}\\\\\n\t\\text { Let } x+2 y&=z \\\\ 1+2 \\frac{d y}{d x}&=\\frac{d z}{d x} \\\\ \\frac{d z}{d x}&=\\frac{3 z-1}{z+1}\\quad  (\\text{Since, $ \\frac{d y}{d x}=\\frac{x+2 y-1}{x+2 y+1}$})\\\\\n\t\\int \\frac{z+1}{3 z-1} dz &=\\int dx\\\\\n\t\\text{L.H.L}&=\\int \\frac{z+1}{3 z-1} dz\\\\\n\t\\intertext{multiply numerator and denominator by 3, we get, }\n\t\t\\text{L.H.L}&=\\int \\frac{1}{3} \\frac{(3z+3)}{(3 z-1)} dz\\\\\n\t\t&=\\int \\frac{1}{3} \\frac{(3z-1+4)}{(3 z-1)} dz\\\\\n\t\t&=\\int \\frac{1}{3} \\frac{(3z-1)+4}{(3 z-1)} dz\\\\\n\t\t&=\\int \\frac{1}{3}\\left\\lbrace  \\frac{(3z-1)}{(3 z-1)}+ \\frac{4}{(3 z-1)}\\right\\rbrace dz\\\\\n\t\t&=\\int \\left\\lbrace  \\frac{1}{3}+  \\frac{1}{3} \\frac{4}{(3 z-1)}\\right\\rbrace dz\\\\\n\t\t&=\\int \\left\\lbrace  \\frac{1}{3}+  \\frac{4}{9} \\frac{1}{(3 z-1)}\\right\\rbrace dz\\\\\n\t\t&=\\frac{1}{3} z+\\frac{4}{9} \\ln (3 z-1)+c\n\t\t\\intertext{Then,}\n\t\t\\int \\frac{z+1}{3 z-1} dz &=\\int dx \\Rightarrow\t\\quad \n\t\t\\frac{1}{3} (x+2y)+\\frac{4}{9} \\ln (3 x+6 y-1)=2x+c\\\\\n\t\t3 x-3 y+a&=2 \\ln (3 x+6 y-1)\\\\\n\t\t4 \\ln (3 x+6 y-1)&=(6 x-6y)+c\\\\\n\t2 \\ln (3 x+6 y-1)&=(3 x-3y)+c\\\\\n\\end{align*}\n\\end{answer}\n\\section{Linear equation of first order}\nIf a differential equation has its dependent variables and its derivatives occur in the first degree and are not multiplied together, then the equation is said to be linear. The standard equation of a linear equation of first order is given as\n$$\n\\frac{d y}{d x}+P y=Q\n$$\nWhere $P$ and $Q$ are functions of $x$.\n\n\\begin{align*}\n\\text { Integrating factor }&=(\\text { I.F. })=e^{\\int P \\cdot d x} \\\\\n\\Rightarrow y \\cdot e^{\\int P \\cdot d x}&=\\int Q \\cdot e^{\\int P \\cdot d x} d x+C \\\\\n\\Rightarrow \\hspace{0.3cm}y(\\mathrm{I.F.})&=\\int Q(\\mathrm{I.F.}) d x+C\\\\\n\\end{align*}\n\n\\begin{exercise}\n\tSolve the differential equation $\\frac{d y}{d x}-\\frac{y}{x}=2 x^{2}, x>0$.\n\\end{exercise}\n\\begin{answer}\n\twe know,\n\t\n\t\\begin{align*}\n\t\t\\frac{d y}{d x}+\\left(\\frac{-1}{x}\\right) y &=2 x^{2}\\\\\n\t\t\\frac{d y}{d x}+P y=Q, \\text { where } P &=-\\frac{1}{x} \\text { and } Q=2 x^{2}\\\\\n\t\tI.F&=e^{\\int P \\cdot d x}=e^{\\int-1 / x \\cdot d x}\\\\&=e^{-\\log x}=e^{\\log x^{-1}}=x^{-1}=\\frac{1}{x}\\\\\n\t\t\\text{Multiplying both sides with $I.F$, we get}\\\\\\frac{1}{x} \\cdot \\frac{d y}{d x}-\\frac{1}{x^{2}} \\cdot y&=2 x\\\\\n\t\t\\text{Integrating both sides w.r.t. $x,$ we get}\\\\y \\cdot\\left(\\frac{1}{x}\\right)&=\\int 2 x \\cdot d x+C \\\\\n\t\t\\Rightarrow \\quad y \\cdot \\frac{1}{x}&=x^{2}+C\\\\\\Rightarrow\\hspace{0.9cm} y&=x^{3}+C x, x>0 \\quad \\text{is the required solution.}\n\t\\end{align*}\n\\end{answer}\n\\subsection{Equations reducible to linear form}\nThe differential equation of the form,\n$$\\frac{dy}{dx}+p(x)y=f(x)y^{n}$$is called the Bernoulli's equation or equation reducible to linear form.\nIt can be done by dividing by $y^{n}$ and substituting $\\frac{1}{y^{n-1}}=z$\n\\begin{alignat*}{2}\n&\\frac{1}{y^{n}} \\frac{d y}{d x}+\\frac{1}{y^{n-1}} P&&=Q\\\\&\\text{Put}\\quad \\frac{1}{y^{n-1}}&&=z\\\\&\\frac{(1-n)}{y^{n}} \\frac{d y}{d x}&&=\\frac{d z}{d x} \\\\ &\\Rightarrow \\quad \\frac{1}{y^{n}} \\frac{d y}{d x}&&=\\frac{d z}{1-n}\\\\\n&\\frac{1}{1-n} \\frac{d z}{d x}+P z&&=Q \\quad \\text{or}\\\\& \\frac{d z}{d x}+P(1-n) z&&=Q(1-n)\n\\end{alignat*}\nWhich is a linear equation and can be solved easily.\n\\begin{exercise}\n\tSolve $\\frac{d y}{d x}+x y=x^{3} y^{3}$\n\\end{exercise}\n\\begin{answer}We have,\n\t\\begin{align*}\n\\frac{d y}{d x}+x y&=x^{3} y^{3}\\\\\n\\frac{1}{y^{3}} \\frac{d y}{d x}+\\frac{x}{y^{2}}&=x^{3}\\\\\n\t\\text{putting}\\quad \\frac{1}{y^{2}}&=z \\\\\\Rightarrow \\quad \\frac{-2}{y^{3}} \\frac{d y}{d x}&=\\frac{d z}{d x} \\quad \\Rightarrow \\quad \\frac{1}{y^{3}} \\frac{d y}{d x}=\\frac{-1}{2} \\frac{d z}{d x}\\\\\\therefore \\quad-\\frac{1}{2} \\frac{d z}{d x}+x z&=x^{3} \\qquad\\Rightarrow \\quad \\frac{d z}{d x}-2 x z=-2 x^{3}\\\\\n\t\\mathrm{\\therefore I.F.}=e^{-\\int 2 x d x}&=e^{-x^{2}}\\\\\n\tz e^{-x^{2}}&=-2 \\int x^{3} e^{-x^{2}} d x\\\\\n\t\\text{Let}\\quad  -x^{2}&=t \\Rightarrow-2 x d x=d t\\\\\n\tz e^{-x^{2}}&=\\int t e^{t} d t=t e^{t}-e^{t}+c\\\\\n\t\\text{put}\\quad z=y^{-2} \\text{and}\\quad t=-x^{2}\\\\\n\t\\therefore \\frac{e^{-x^{2}}}{y^{2}}&=-x^{2} e^{-x^{2}}-e^{-x^{2}}+c\\\\\n\t\\frac{1}{y^{2}}&=-x^{2}-1+C e^{x^{2}}\n\t\\end{align*}\n\\end{answer}\n\\section{Exact differential equations}\nA differential equation of the form , $Mdx+Ndy=0$ is said to be  exact if it satisfy the following condition,$$\\frac{\\partial \\boldsymbol{M}}{\\partial \\boldsymbol{y}}=\\frac{\\partial N}{\\partial \\boldsymbol{x}}$$\n$\\frac{\\partial M}{\\partial \\boldsymbol{y}}\\quad-\\quad$Differential co-efficient of $M$ with respect to $y$ keeping $x$ constant\\\\\n$\\frac{\\partial N}{\\partial \\boldsymbol{x}}\\quad-\\quad$Differential co-efficient of $N$ with respect to $x$, keeping $y$ constant.\\\\\\\\\n\\textbf{\\large Method of solving:}\\\\\n\\textbf{Step 1:} Integrate $M$ w.r.t. $x$ keeping $y$ constant\\\\\n\\textbf{Step 2:} Integrate w.r.t. $y$, only those terms of $N$ which do not contain $x$.\\\\ \\textbf{Step 3:} Result of 1 + Result of 2 = Constant.\n\\begin{exercise}\n\tSolve $\\left(x^{2}+2 x y\\right) d x+\\left(x^{2}+y^{2}\\right) d y=0$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Here,}\\quad M=\\left(x^{2}+2 x y\\right) \\quad &\\text{and}\\quad N=\\left(x^{2}+y^{2}\\right)\\\\\\Rightarrow \\frac{\\partial M}{\\partial y}&=2 x\\\\\\text{and}\\quad\n\t\\frac{\\partial N}{\\partial x}&=2 x\\\\\n\t\\text{Hence, the given equation is exact}\\\\\n\t\\int\\left(x^{2}+2 x y\\right) d x+\\int y^{2} d y&=c\\\\\\frac{x^{3}}{3}+x^{2} y+\\frac{y^{3}}{3}&=C\\\\\\text { The solution is: } \\\\\\int\\left(x^{2}+2 x y\\right) d x+\\int y^{2} d y=c=\\frac{x^{3}}{43}+x^{2} y+\\frac{y^{3}}{3}&=6\\end{align*}\n\\end{answer}\n\\subsection{Equations reducible to Exact form}\nA differential equation which is not exact can be reduced to exact form  by multiplying it by a constant , here the integrating factor.\\\\\n\\textbf{Type 1:} If $ \\frac{\\frac{\\partial M}{\\partial y}-\\frac{\\partial N}{\\partial x}}{N}\\text { is a function of } x \\text { alone, say } f(x), \\text { then } \\mathrm{I.F}=e^{\\int f(x) d x}$\\\\\n\\textbf{Type 2:} If $\\frac{\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}}{M}$ is a function of $y$ alone, say $f(y),$ then\n$\n\\mathrm{I.F} =e^{\\int f(y) d y}\n$\n\\begin{exercise}\n\tSolve $(2 x \\log x-x y) d y+2 y d x=0$\n\\end{exercise}\n\\begin{answer}\n\\begin{align*}\nM &=2 y,\\quad N=2 x \\log x-x y\\notag\\\\\n\\frac{\\partial M}{\\partial y}&=2,\\quad\\frac{\\partial N}{\\partial x}=2(1+\\log x)-y\\\\\n\\text { Here, }\\notag \\\\\n\\quad \\frac{\\frac{\\partial M}{\\partial y}-\\frac{\\partial N}{\\partial x}}{N}&=\\frac{2-2-2 \\log x+y}{2 x \\log x-x y}\\\\&=\\frac{-(2 \\log x-y)}{x(2 \\log x-y)}=-\\frac{1}{x}=f(x)\\notag\\\\\\text { I.F. }&=e^{\\int f(x) d x}=e^{\\int-\\frac{1}{x} d x}\\\\&=e^{-\\log x}=e^{\\log x^{-1}}=x^{-1}=\\frac{1}{x}\\\\\n&\\text{On multiplying the given differential equation by}  \\frac{1}{x}, \\text{we get}\\\\\n\\frac{2 y}{x} d x+(2 \\log x-y) d y&=0 \\\\ \\Rightarrow \\quad \\int \\frac{2 y}{x} d x+\\int-y d y&=c \\\\\n\\Rightarrow  \\qquad\\quad 2 y \\log x-\\frac{1}{2} y^{2}&=c\n\\end{align*}\n\\end{answer}\n\\section{Orthogonal trajectories and Family of curves}\nGiven a one-parameter family of plane curves, it's orthogonal trajectories are another\none-parameter family of curves, each one of which is perpendicular to all the curves in the\noriginal family. For instance, if the original family consisted of all circles having center at the origin, it's orthogonal trajectories would be all rays (half-lines) starting at the origin.\n\\begin{definition}\n\tTwo families of curves are such that every curve of either family cuts each curve of the other family at right angles. They are called orthogonal trajectories of each other.\n\\end{definition}\nOrthogonal trajectories arise in different contexts in applications. If the\noriginal family represents the lines of force in a gravitational or electrostatic field, its orthogonal trajectories represent the equipotentials, the curves along which the gravitational or electrostatic potential is constant.\n\\begin{example}\\hspace{1cm}\n\t\\begin{enumerate}\n\t\t\\item The path of an electric field is perpendicular to equipotential curves.\n\t\t\\item  In fluid flow, the stream lines and equipotential lines are orthogonal trajectories.\n\t\t\\item The lines of heat flow is perpendicular to isothermal curves.\n\t\\end{enumerate}\n\\end{example}\n\\subsection{Finding orthogonal trajectories to the curve}\nLet a family of curves be given by the equation\n$$\ng(x, y)=C\n$$\nWhere $C$ is a constant. For the given family of curves, we can draw the orthogonal trajectories, that is another family of curves $f(x, y)=C$ that cross the given curves at right angles.\n\\subsubsection{Method of solving}\n\\textbf{Family of curves given ,then to find orthogonal trajectories.}\n\\begin{enumerate}\n\t\\item  By differentiating the equation of curves find the differential equations in the form $f\\left(x, y, \\frac{d y}{d x}\\right)=0$\n\t\\item  Replace $\\frac{d y}{d x}$ by $-\\frac{d x}{d y}$\\\\ ($ m_{1}m_{2}=-1$, where,$m_{1}$=given family,$m_{2}$=orthogonal  family)\n\t\\item  Solve the differential equation of the orthogonal trajectories i.e., $f\\left(x, y,-\\frac{d x}{d y}\\right)=0$\n\\end{enumerate}\n\\textbf{Orthogonal trajectories given , then to find Family of curves .}\n\\begin{enumerate}\n\t\\item Solve the differential equation of the orthogonal trajectory $f\\left(x, y,\\frac{d x}{d y}\\right)=0$ using appropriate method.\n\\end{enumerate}\n\\begin{note}\n\t\\textbf{Self-orthogonal:}. If the family of orthogonal trajectory is the same as the given family of curves,then it's called self orthogonal.\n\\end{note}\n\\begin{exercise}\n\t Find the orthogonal trajectories of the family of straight lines  $y=C x,$  where  $C$  is a parameter.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{we have,}\\quad y&=C x\\\\\n\t\\text{differentiating the given equation we get}\\\\\n\tdy&=cdx\\\\\n\tdy&=\\frac{y}{x}dx\\quad(\\because c=\\frac{y}{x})\\\\\n\t\\frac{dy}{dx}=\\frac{y}{x}\\\\\n\t{\\frac{dy}{dx}}_{(ortho)}&=\\frac{-x}{y}\\\\\n\t\\text{ using variable separable method}\\\\\n\t(-xdx&=ydy)\\\\\n\t\\int-xdx&=\\int ydy\\\\\n\t-\\frac{x^{2}}{2}&=\\frac{y^{2}}{2}+C\\\\\n\t\t\\frac{x^{2}}{2}+\\frac{y^{2}}{2}&=C\\\\\n\t\tx^{2}+y^{2}&=2C\\Longrightarrow \\text{Represents the family of circles}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the family of curves of the given trajectory,\t$\\frac{dy}{dx}=\\frac{x}{y}$\n\\end{exercise}\n\\begin{answer}\n\\begin{align*}\n\\text{given},\\frac{dy}{dx}&=\\frac{x}{y}\\\\\n\\text{using variable seperable method, we get}\\\\\n\\int xdx&=\\int ydy\\\\\n\\frac{x^{2}}{2}&=\\frac{y^{2}}{2}+C\\\\\n\\frac{x^{2}}{2}-\\frac{y^{2}}{2}&=C\\\\\nx^{2}-y^{2}&=2C\\Longrightarrow \\text{family of hyperbolas}\n\\end{align*}\n\\end{answer}\n\\section{Second order differential equations}\n\\subsection{Linear differential equation}\nIf the degree of the dependent variable and all derivatives is one, such differential equations are called linear differential equations.\n\\begin{example}\\hspace{0.5cm}\n\t\\begin{enumerate}\n\t\t\\item $2\\frac{d^{2} y}{d x^{2}}+3\\frac{d y}{d x}+4 y=x^{2}+x+1$\n\t\t\\item $ \\frac{d^{2} x}{d x^{2}}-\\frac{d y}{d x}-3 y=x$\n\t\t\\item $2 \\frac{d^{2} x}{d t^{2}}-\\frac{d x}{d t}-3 x=f(t)$\n\t\\end{enumerate}\n\\end{example}\n\\subsection{Non-Linear differential equation}\nIf the degree of the dependent variable and / or its derivatives are of greater than 1 such differential equations are called non-linear differential equations.\n\\begin{example}\\hspace{0.5cm}\n\t\\begin{enumerate}\n\t\t\\item $\\frac{d^{2} y}{d x^{2}}+\\frac{d y}{d x}+y^{2}=\\sin x$\n\t\t\\item  $\\frac{d^{2} y}{d x^{2}}+2\\left(\\frac{d y}{d x}\\right)^{2}+y^{2}=e^{x}$\n\t\t\\item  $\\left(\\frac{d^{2} x}{d t^{2}}\\right)^{2}+\\frac{d x}{d t}+x=f(t)$\n\t\\end{enumerate}\n\\end{example}\n\\subsection{Homogeneous differential equation}\nA differential equation of the form\n$y^{\\prime \\prime}+P(x) y^{\\prime}+Q(x) y=F(x)$, is said to be  homogeneous if $F(x)= 0$\n\\begin{example}\n\t\\hspace{0.5cm}\n\t\\begin{enumerate}\n\t\t\\item \t$\\frac{d^{2} y}{d x^{2}}-6 \\frac{d y}{d x}+13 y=0$\n\t\t\\item $\\frac{d^{2} y}{d x^{2}}+2\\left(\\frac{d y}{d x}\\right)^{2}+y^{2}=0$\n\t\\end{enumerate}\n\n\\end{example}\n\\subsection{Nonhomogeneous differential eqaution} A differential equation of the form\n$y^{\\prime \\prime}+P(x) y^{\\prime}+Q(x) y=F(x)$, is said to be  non-homogeneous if $F(x)\\neq 0$\n\\begin{example}\n\\hspace{0.5cm}\n\\begin{enumerate}\n\t\\item \t$\\frac{d^{2} y}{d x^{2}}-6 \\frac{d y}{d x}+ y=x^{2}+2$\n\t\\item $\\frac{d^{2} y}{d x^{2}}+2\\left(\\frac{d y}{d x}\\right)^{2}+y^{2}=e^{x}$\n\\end{enumerate}\n\\end{example}\n\\section{Linear independance and dependance of solutions}\nTwo solutions of a differential equation, $ y_{1}(x)$ and $ y_{2}(x)$ are said to be linearly independant if \\\\$$Ay_{1}(x)+By_{2}(x)\\neq 0 $$ given, $ A\\neq0 \\quad\\text{and}\\quad B\\neq0$\n\\subsection{Wronskian}\nA first-order homogeneous ODE has only one linearly independent solution. This is meant in the following sense. \"If two solutions are linearly dependent, by definition they satisfy $a y_{1}(x)+b y_{2}(x)=0$ with nonzero constants $a, b$ for all values of $x$\". If the only solution of this linear relation is $a=0=b$, then our solutions $y_{1}$ and $y_{2}$ are said to be linearly independent.\n\\\\To prove this theorem, suppose $y_{1}, y_{2}$ both solve the homogeneous ODE. Then,\n\\begin{equation*}\n\\frac{y_{1}^{\\prime}}{y_{1}}=-p(x)=\\frac{y_{2}^{\\prime}}{y_{2}} \\quad \\Rightarrow \\quad W(x) \\equiv y_{1}^{\\prime} y_{2}-y_{1} y_{2}^{\\prime} \\equiv 0\n\\end{equation*}\nThe functional determinant $W$ is called the \\textbf{Wronskian of the pair $y_{1}$, $y_{2}$}. We now show that $W \\equiv 0$ is the condition for them to be linearly dependent. Assuming linear dependence, that is.\n\\begin{equation*}\na y_{1}(x)+b y_{2}(x)=0\n\\end{equation*}\nIn matrix form, the Wronskian of two functions $y_{1}(x)$ and $y_{2}(x)$ is given by,\n\\begin{equation}\nW\\left(y_{1}, y_{2}, x\\right)=\\left|\\begin{array}{ll}\ny_{1}(x) & y_{2}(x) \\\\\ny_{1}^{\\prime}(x) & y_{2}^{\\prime}(x)\n\\end{array}\\right|=y_{1}(x) y_{2}^{\\prime}(x)-y_{1}^{\\prime}(x) y_{2}(x)\n\\end{equation}\n\\begin{enumerate}\n\t\\item If $W\\left(y_{1}, y_{2}, x\\right)=0,$ then $y_{1}(x)$ and $y_{2}(x)$ are linearly dependent.\n\t\\item If $W\\left(y_{1}, y_{2}, x\\right) \\neq 0,$ then $y_{1}(x), y_{2}(x)$ are linearly independent.\n\\end{enumerate}\n\\begin{note}\n\tThe wronskian of a differential equation can also be written as,\n\t$$ W(t)=e^{-\\int p(x)dx}$$\n\t\\end{note}\n\\begin{exercise}\nConsider two solutions $\\mathrm{x}_{1}(\\mathrm{t})$ and $\\mathrm{x}_{2}(\\mathrm{t})$ of the differential equation $\\frac{d^{2} x(t)}{d t^{2}}+x(t)=0, t>0$, such that $x_{1}(0)=1,\\left.\\frac{d x_{1}(t)}{d t}\\right|_{t=0}=0, x_{2}(0)=0,\\left.\\frac{d x_{2}(t)}{d t}\\right|_{t=0}=1$. The Wronskian $W(t)=\\left|\\begin{array}{ll}x_{1}(t) & x_{2}(t) \\\\ \\frac{d x_{1}(t)}{d t} & \\frac{d x_{2}(t)}{d t}\\end{array}\\right|$ at $t=\\frac{\\pi}{2}$ is,\t\n\\end{exercise}\n\\begin{answer}\n\tThe wronskian of a differential equation can also be written as,\n\t\\begin{align*}\n\tW(t)&=e^{-\\int p(x)dx}\\\\\n\t\\text{But here,}\\quad  p(x)&=0\\\\\n\t\\text{Then,} \\quad W(t)&=e^{0 \\ dx}=1\\\\\n\t\\text{So,}\\quad W(\\frac{\\pi}{2})&=1\n\t\\end{align*}\n\\end{answer}\n\\section{Linear Second Order Differential Equations With Constant Coefficients}\nThe general form of the linear differential equation of second order is\n$$\n\\frac{d^{2} y}{d x^{2}}+P \\frac{d y}{d x}+Q y=R\n$$\nWhere $P$ and $Q$ are constants and $R$ is a function of $x$ or constant.\\begin{note}\\textbf{Differential operator:}\\\\\n\tA differential operator can be represented as,\\quad $D=\\frac{d}{dx}$\n\\\\Then a differential equation can be written  in terms of differntial operators as,\n\\begin{align*}\nD^{2} y+P D y+Q y&=R \\\\ \\left(D^{2}+P D+Q\\right) y&=R\\\\\n\\text{Where,}\\quad D y&=\\frac{d y}{d x}, \\ \\text{and}\\ D^{2} y=\\frac{d^{2} y}{d x^{2}}\n\\end{align*}\n\n$\\frac{1}{D}$ stands for the operation of integration.\t\n\\end{note}\n\\section{Solution of Second order homogeneous differential equation.}\n\n\\subsection{Method of solving}\n\\begin{enumerate}\n\t\\item Let $y=C_{1} e^{m x}$ be the trial solution\n\t\\begin{equation}\n\t\\frac{d^{2} y}{d x^{2}}+P \\frac{d y}{d x}+Q y=0\\label{eq1}\n\t\\end{equation}\n\t\n\tPutting the values of $y,\\quad \\frac{d y}{d x}$ and $\\quad\\frac{d^{2} y}{d x^{2}}$ in  \\ref{eq1} then,\\\\ $C_{1} e^{m x}\\left(m^{2}+P m+Q\\right)=0$\n\t$\\Rightarrow$\n\t$m^{2}+P m+Q=0 .$ It is called Auxiliary equation.\n\t\\item Solve the auxiliary equation.\n\t\\subsubsection{{Case 1:}}\\textbf{ Roots are real and distinct}\\\\\n\tIf $m_{1}$ and $m_{2}$ are the roots, then the C.F. is\n\t$$\n\ty=C_{1} e^{m_{1} x}+C_{2} e^{m_{2} x}\n\t$$\n\t\\subsubsection{{Case 2:}}\\textbf{ Roots are real and  equal}\\\\\n\tIf both the roots are $m, m$ then the C.F. is\n\t$$\n\ty=\\left(C_{1}+C_{2} x\\right) e^{m x}\n\t$$\n\t\\subsubsection{{Case 3:}}\\textbf{ Roots are Imaginary}\\\\\n\t If the roots are $\\alpha \\pm i \\beta,$ then the solution will be\n\t$$\n\t\\begin{aligned}\n\ty &=C_{1} e^{(\\alpha+i \\beta) x}+C_{2} e^{(\\alpha-i \\beta) x}=e^{\\alpha x} \\cdot\\left[C_{1} e^{i \\beta x}+C_{2} e^{-i \\beta x}\\right] \\\\\n\t&=e^{\\alpha x}\\left[C_{1}(\\cos \\beta x+i \\sin \\beta x)+C_{2}(\\cos \\beta x-i \\sin \\beta x)\\right] \\\\\n\t&=e^{\\alpha x}\\left[\\left(C_{1}+C_{2}\\right) \\cos \\beta x+i\\left(C_{1}-C_{2}\\right) \\sin \\beta x\\right]\\\\&=e^{\\alpha x}[A \\cos \\beta x+B \\sin \\beta x]\n\t\\end{aligned}\n\t$$\n\\end{enumerate}\n\\setlength\\extrarowheight{10pt}\n\\begin{table}[H]\n\\begin{tabular}{|m{5cm}|m{4cm}|m{4cm}|}\n\\hline\nRoots&Basis of solution&General solution\\\\\\hline\nReal and  equal(repeated root $m$)& $e^{m x}$ and $xe^{m x}$&$\ny=\\left(C_{1}+C_{2} x\\right) e^{m x}\n$\\\\\\hline\nReal and  distinct($m_{1}$ , $m_{2}$)& $e^{m_{1} x}$ ,$\\quad e^{m_{2} x}$ &$\ny=C_{1} e^{m_{1} x}+C_{2} e^{m_{2} x}\n$\\\\\\hline\nImaginary roots ($\\alpha \\pm i \\beta$)&$ e^{(\\alpha+i \\beta) x}, e^{(\\alpha-i \\beta) x}$&$e^{\\alpha x}[A \\cos \\beta x+B \\sin \\beta x]$\\\\\\hline\n\n\\end{tabular}\n\\caption{Roots of homogeneous second order DE}\n\\end{table}\n\\begin{exercise}\n\tSolve $\\frac{d^{2} y}{d x^{2}}-8 \\frac{d y}{d x}+15 y=0$.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Given equation can be written as,}\\\\\n\t\\left(D^{2}-8 D+15\\right) y&=0\\\\\n\t\\text{Here auxiliary equation is,}\\\\ m^{2}-8 m+15&=0\\\\\n\t(m-3)(m-5)&=0 \\quad \\therefore m=3,5\\\\\\text{Hence, the required solution is,}\\\\\n\ty&=C_{1} e^{3 x}+C_{2} e^{5 x}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tSolve the differential equation:\n\t$\n\t\\frac{d^{2} y}{d x^{2}}+6 \\frac{d y}{d x}+9 y=0\n\t$\n\\end{exercise}\n\\begin{answer}\nWe have\n\\begin{align*}\n\\frac{d^{2} y}{d x^{2}}+6 \\frac{d y}{d x}+9 y&=0 \\\\\n\\Rightarrow \\left(D^{2}+6 D+9\\right) y&=0\\\\\n\\text{Auxiliary equation is}\\quad D^{2}+6 D+9&=0\\\\\n\\Rightarrow \\quad(D+3)^{2}&=0 \\Rightarrow D=-3,-3\\\\\n\\text{the solution, y}&=\\left(c_{1}+c_{2} x\\right) e^{-3 x}\n\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tSolve $\\left(D^{3}-1\\right) y=0$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{we have,}\\left(D^{3}-1\\right) y&=0\\\\\n\t\\text{The characteristic equation is,}\\\\\n\tm^{3}-1&=0 \\Rightarrow m=1, \\frac{-1 \\pm \\sqrt{3 i}}{2}\\\\\\text { y }&=A e^{x}+e^{-x / 2} \\cdot\\left[B \\cos \\frac{\\sqrt{3}}{2} x+C \\sin \\frac{\\sqrt{3}}{2} x\\right]\n\t\\end{align*}\n\\end{answer}\n\\section{Solution of Second order nonhomogeneous differential equation.}\nThe solution of a differential equation of the form,$$\\frac{d^{2} y}{d x^{2}}+P \\frac{d y}{d x}+Q y=R$$ consists of two parts,a complementary function and a particular integral.\n\\\\Complete Solution = Complementary Function + Particular Integral\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{y}\\quad=\\quad{C . F }\\quad+\\quad{P . I}} }\n\\end{center}\n\\subsubsection{Finding complementary function}\nComplementary function is the solution obtained by solving the equation replacing R.H.S by 0.Same as that explained in finding solution to homogeneous differential equations.\n\\subsubsection{Finding Particular solution}\nParticular integral (P.I) depends on the form of $R(x)$\\\\\nIf the differential equation is of the form,$$\\left(D^{n}+k_{1} D^{n-1}+k_{2} D^{n-2}+\\cdots+k_{n}\\right) y=R(x)$$\n\\\\Then the particular integral of the equation is given by,\n$$\n\\text { P.I. }=\\frac{1}{D^{n}+k_{1} D^{n-1}+k_{2} D^{n-2}+\\cdots+k_{n}} R(x)\n$$\nThe following cases arise for particular integrals:\n\\begin{enumerate}\n\t\\item When $X=e^{a x},$ then\n\t$$\n\t\\begin{aligned}\n\t\\text { P.I. } &=\\frac{1}{f(D)} e^{a x} \\\\\n\t&=\\frac{1}{f(a)} e^{a x},\\quad \\text { If }\\ f(a) \\neq 0 \\\\\n\t\\text { If } f(a)=0, \\text { then } \\\\\n\t\\text { P.I. } &=\\frac{x}{f^{\\prime}(a)} e^{a x}, \\quad \\text { If }\\ f^{\\prime}(a) \\neq 0\n\t\\end{aligned}\n\t$$\n\tIf $f^{\\prime}(a)=0,$ then\n\t$$\n\t\\text { P.I. }=\\frac{x^{2}}{f^{\\prime \\prime}(a)} e^{a x}, \\quad \\text { If }\\ f^{\\prime \\prime}(a) \\neq 0\n\t$$\n\t\\item  When $X=\\sin a x,$ then\n\t$$\n\t\\begin{array}{c}\n\t\\text { P.I. }=\\frac{1}{f\\left(D^{2}\\right)} \\sin a x \\\\\n\t=\\frac{1}{f\\left(-a^{2}\\right)} \\sin a x, \\text { if } f\\left(-a^{2}\\right) \\neq 0\n\t\\end{array}\n\t$$\n\t\\item When $X=\\cos a x,$ then\n\t$$\n\t\\begin{aligned}\n\t\\text { P.I. } &=\\frac{1}{f\\left(D^{2}\\right)} \\cos a x \\\\\n\t&=\\frac{1}{f\\left(-a^{2}\\right)} \\cos a x, \\text { if } f\\left(-a^{2}\\right) \\neq 0\n\t\\end{aligned}\n\t$$\n\t\\item  When $X=x^{m}$, then\n\t$$\n\t\\text { P.I. }=\\frac{1}{f(D)} x^{m}=[f(D)]^{-1} x^{m}\n\t$$\n\tExpansion of $[f(D)]^{-1}$ is to be carried up to the term $D^{m}$ because $(m+1)^{\\text {th }}$ and higher derivatives of $x^{m}$ are zero.\n\t\\item When $X=e^{a x} v(x)$, then\n\t$$\n\t\\begin{array}{l}\n\t\\text { P.I. }=\\frac{1}{f(D)} e^{a x} v(x) \\\\\n\t\\text { P.I. }=e^{a x} \\frac{1}{f(D+a)} v(x)\n\t\\end{array}\n\t$$\n\t\\item When $X=x v(x)$, then\n\t\\begin{align*}\n\t\\text { P.I. }&=\\frac{1}{f(D)} x v(x)\\\\&=\\left[x-\\frac{f^{\\prime}(D)}{f(D)}\\right] \\cdot \\frac{1}{f(D)} v(x)\n\t\\end{align*}\n\\end{enumerate}\n\\begin{exercise}\n\tSolve the differential equation:\n\t$$\n\t\\frac{d^{2} y}{d x^{2}}+6 \\frac{d y}{d x}+9 y=5 e^{3 x}\n\t$$\n\\end{exercise}\n\\begin{answer}\n\tWe have\n\t\\begin{align*}\n\t\\frac{d^{2} y}{d x^{2}}+6 \\frac{d y}{d x}+9 y&=5 e^{3 x} \\\\\n\t \\left(D^{2}+6 D+9\\right) y&=5 e^{3 x}\\\\\n\t\\text{Auxiliary equation is}\\quad D^{2}+6 D+9&=0\\\\\n(D+3)^{2}&=0 \\Rightarrow D=-3,-3\\\\\n\t\\text{The solution, y}&=\\left(c_{1}+c_{2} x\\right) e^{-3 x}\\\\\n\t\\text { Particular integral } &=\\frac{1}{D^{2}+6 D+9} \\cdot 5 e^{3 x} \\\\\n\t&=\\frac{5 e^{3 x}}{(3)^{2}+6(3)+9}=\\frac{5 e^{3 x}}{36}\\\\\n\t\\text{The complete solution is given by} y&=\\mathrm{C} . \\mathrm{F} .+\\mathrm{P} . \\mathrm{I}\\\\\n y&=\\left(c_{1}+c_{2} x\\right) e^{-3 x}+\\frac{5 e^{3 x}}{36}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the particular integral of the differential equation, $(D^{3}+8)=x^{4}-2x+1$\n\\end{exercise}\n\\begin{answer}\n\tWe have,\n\t\\begin{align*}\n\t(D^{3}+8)&=x^{4}-2x+1\\\\\n\t\\text{P.I}&=\\frac{1}{(D^{3}+8)}(x^{4}-2x+1)\\\\\n\t&=\\frac{1}{8(1+\\frac{D^{3}}{8})}(x^{4}-2x+1)\\\\\n\t&=\\frac{[1+\\frac{D^{3}}{8}]^{-1} }{8}(x^{4}-2x+1)\n\t\\intertext{Using Binomial expansion on $[1+\\frac{D^{3}}{8}]^{-1}$ we get,}\n\t[1+\\frac{D^{3}}{8}]^{-1}&=[1-\\frac{D^{3}}{8}+\\cdots]\n\t\\intertext{Higher terms in the expansion can be ommitted since , here the  highest power of $x$ is $4$ ($R(x)=x^{4}-2x+1$).}\n\t\\text{Then,}\\ \\text{P.I}&=\\frac{1}{8}[1-\\frac{D^{3}}{8}](x^{4}-2x+1)\\\\\n\t&=\\frac{1}{8}\\left[ (x^{4}-2x+1)-\\frac{D^{3} (x^{4}-2x+1)}{8}\\right] \\\\\n\t&=\\frac{1}{8}\\left[ (x^{4}-2x+1)-\\frac{24x}{8}\\right] \\\\\n\t&=\\frac{1}{8}\\left[ (x^{4}-2x+1)-3x\\right] \\\\\n\t&=\\frac{1}{8}\\left[ (x^{4}-x+1)\\right]\n\t\\end{align*}\n\\end{answer}\n\n\\section{Euler - Cauchy Differential equation}\nAlthough second-order linear equations with constant coefficients are the ones used most frequently in applications, there are a few other kinds of second-order equations and methods of solving them which are also important. one of them is the Euler-Cauchy equation. An equation of the form,\n \\begin{equation}\na_{n} x^{n} \\frac{d^{n} y}{d x^{n}}+a_{(n-1)} x^{(n-1)} \\frac{d^{(n-1)} y}{d x^{(n-1)}}+\\cdots \\cdots+a_{2} x^{2} \\frac{d^{2} y}{d x^{2}}+a_{1} x \\frac{d y}{d x}+a_{0} y=\\mathrm{Q(x)}\n\\end{equation}\nWhere, $a_{0},a_{1},a_{2}\\cdots a_{n} $ are constants is called an Euler or Cauchy equation. It can be reduced to a linear equation with constant coefficients by changing the independent variable from $x$ to $z$ where,\n$$\nx=e^{z} .\n$$\n\n$x \\frac{d y}{d x}=\\frac{d y}{d z}$\nand $x^{2} \\frac{d^{2} y}{d x^{2}}=\\frac{d^{2} y}{d z^{2}}-\\frac{d y}{d z}$.\n\n \\begin{align*}\n \\text{Put,} \\ \\mathrm{x}&=\\mathrm{e}^{z} \\Rightarrow \\log \\mathrm{x}=\\mathrm{z} \\Rightarrow \\frac{1}{x}=\\frac{d z}{d x}\\\\\n \\frac{d y}{d x}&=\\frac{d y}{d x} \\cdot \\frac{d z}{d x}\\\\&=\\frac{1}{x} \\frac{d y}{d z} \\\\ \\mathrm{x} \\frac{d y}{d x}&=\\frac{d y}{d z}\\\\\n \\frac{d^{2} y}{d x^{2}}&=\\frac{d}{d x}\\left(\\frac{d y}{d x}\\right)\\\\&=-\\frac{1}{x^{2}} \\frac{d y}{d z}+\\frac{1}{x} \\frac{d^{2} y}{d z^{2}}\\left(\\frac{d z}{d x}\\right)\\\\&=-\\frac{1}{x^{2}} \\frac{d y}{d z}+\\frac{1}{x^{2}} \\frac{d^{2} y}{d z^{2}} \\\\ x^{2} \\frac{d y}{d x^{2}}&=-\\frac{d y}{d z}+\\frac{d^{2} y}{d z^{2}}\n\\intertext{ Then neglecting the higher orders , the given equation becomes,}\n  a_{2} \\frac{d^{2} y}{d z^{2}}+\\left(a_{1}-a_{2}\\right) \\frac{d y}{d z}+a_{0} y&=\\mathrm{Q} \n \\end{align*}\n \\begin{exercise}\n \t$x^{2} \\frac{d^{2} y}{d x^{2}}+2 x \\frac{d y}{d x}-20 y=(x+1)^{2}$\n \\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tx&=e^{z} \\\\ \\log x&=z \\Rightarrow \\frac{1}{x}=\\frac{d z}{d x}\\\\\n\t\\text{Let,}\\ x \\frac{d y}{d x}&=\\frac{d y}{d z}\\\\\n\t\\text{and,} x^{2} \\frac{d^{2} y}{d x^{2}}&=\\frac{d^{2} y}{d z^{2}}-\\frac{d y}{d z}\\\\\n\t\\text{Then we get,} \\frac{d^{2} y}{d z^{2}}+\\frac{d y}{d z}-20 y&=\\left(e^{z}+1\\right)^{2}\\\\\n\t\\text{C.F.} &=c_{1} e^{4 z}+c_{2} e^{-5 z}\\\\&=c_{1} x^{4}+c_{2} x^{-5}\\\\\n\t\\text{P . I .}&=\\frac{1}{D^{2}+D-20}\\left(e^{z}+1\\right)^{2}\\\\&=\\frac{1}{D^{2}+D-20}\\left(e^{2 z}+2 e^{z}+1\\right)\\\\&=-\\frac{1}{14} e^{2 z}-\\frac{1}{9} e^{z}-\\frac{1}{20}\\\\\n\t\\text{Total solution} \\ y&=c_{1} x^{4}+c_{2} x^{-5}-\\frac{1}{14} x^{2}-\\frac{1}{9} x-\\frac{1}{20}\n\t\\end{align*}\n\\end{answer}\n\n%\\section{Singular Points}\n%The concept of singular point or singularity (as applied to a differential equation) stems from the ts usefulness in  classifying Ordinary Differential Equations  and  investigating the feasibility of a series solution (Series Solution method will be explained in the next section)\n%If we write our second-order homogeneous differential equation (in $y$ ) as,\n%\\begin{equation}\n%y^{\\prime \\prime}+P(x) y^{\\prime}+Q(x) y=0 \\label{DE001}\n%\\end{equation}\n%We are ready to define ordinary and singular points. If the functions $P(x)$ and $Q(x)$ remain finite at $x=x_{0}$, point $x=x_{0}$ is an ordinary point. However, if either $P(x)$ or $Q(x)$ (or both) diverges as $x \\rightarrow x_{0}$, point $x_{0}$ is a singular point. Using equation \\ref{DE001} we may distinguish between two kinds of singular points.\n%\\begin{enumerate}\n%\t\\item If either $P(x)$ or $Q(x)$ diverges as $x \\rightarrow x_{0}$ but $\\left(x-x_{0}\\right) P(x)$ and $\\left(x-x_{0}\\right)^{2} Q(x)$ remain finite as $x \\rightarrow x_{0}$, then $x=x_{0}$ is called a \\textbf{regular}, or \\textbf{nonessential, singular point.}\n%\t\\item If $P(x)$ diverges faster than $\\frac{1}{\\left(x-x_{0}\\right)} $ so that $\\left(x-x_{0}\\right) P(x)$ goes to infinity as $x \\rightarrow x_{0}$, or $Q(x)$ diverges faster than $\\frac{1}{\\left(x-x_{0}\\right)} ^{2}$ so that $\\left(x-x_{0}\\right)^{2} Q(x)$ goes to infinity as $x \\rightarrow x_{0}$, then point $x=x_{0}$ is labeled an \\textbf{irregular}, or \\textbf{essential, singularity}.\n%\\end{enumerate}\n \n\\newpage\n\\begin{abox}\n\tProblem Set -1\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\t\n\t\\item Let $x_{1}(t)$ and $x_{2}(t)$ be two linearly independent solutions of the differential equation $\\frac{d^{2} x}{d t^{2}}+2 \\frac{d x}{d t}+f(t) x=0$ and let $w(t)=x_{1}(t) \\frac{d x_{2}(t)}{d t}-x_{2}(t) \\frac{d x_{1}(t)}{d t} .$ If $w(0)=1$, then $w(1)$ is given by\n\t{\\exyear{ NET/JRF(DEC-2011)}}\n\t\t\t\\begin{tasks}(4)\n\t\t\t\\task[\\textbf{A.}] 1\n\t\t\t\\task[\\textbf{B.}] $e^{2}$\n\t\t\t\\task[\\textbf{C.}]  $1 / e$\n\t\t\t\\task[\\textbf{D.}] $1 / e^{2}$\n\t\t\\end{tasks}\n\\item Let $y(x)$ be a continuous real function in the range 0 and $2 \\pi$, satisfying the inhomogeneous differential equation: $\\sin x \\frac{d^{2} y}{d x^{2}}+\\cos x \\frac{d y}{d x}=\\delta\\left(x-\\frac{\\pi}{2}\\right)$ The value of $d y l d x$ at the point $x=\\pi / 2$\n{\\exyear{NET/JRF (JUNE-2012)}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] Is continuous\n\t\\task[\\textbf{B.}] Has a discontinuity of 3\n\t\\task[\\textbf{C.}] Has a discontinuity of $1 / 3$\n\t\\task[\\textbf{D.}] Has a discontinuity of 1\n\\end{tasks}\n\\item The solution of the partial differential equation\n$$\n\\frac{\\partial^{2}}{\\partial t^{2}} u(x, t)-\\frac{\\partial^{2}}{\\partial x^{2}} u(x, t)=0\n$$\nsatisfying the boundary conditions $u(0, t)=0=u(L, t)$ and initial conditions $u(x, 0)=\\sin (\\pi x / L)$ and $\\left.\\frac{\\partial}{\\partial t} u(x, t)\\right|_{t=0}=\\sin (2 \\pi x / L)$ is\n{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $\\sin (\\pi x / L) \\cos (\\pi t / L)+\\frac{L}{2 \\pi} \\sin (2 \\pi x / L) \\cos (2 \\pi t / L)$\n\t\t\\task[\\textbf{B.}] $2 \\sin (\\pi x / L) \\cos (\\pi t / L)-\\sin (\\pi x / L) \\cos (2 \\pi t / L)$\n\t\t\\task[\\textbf{C.}] $\\sin (\\pi x / L) \\cos (2 \\pi t / L)+\\frac{L}{\\pi} \\sin (2 \\pi x / L) \\sin (\\pi t / L)$\n\t\t\\task[\\textbf{D.}] $\\sin (\\pi x / L) \\cos (\\pi t / L)+\\frac{L}{2 \\pi} \\sin (2 \\pi x / L) \\sin (2 \\pi t / L)$\n\t\\end{tasks}\n\t\\item The solution of the differential equation\n\t$$\n\t\\frac{d x}{d t}=x^{2}\n\t$$\n\twith the initial condition $x(0)=1$ will blow up as $t$ tends to\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 1\n\t\t\\task[\\textbf{B.}] 2\n\t\t\\task[\\textbf{C.}] $\\frac{1}{2}$\n\t\t\\task[\\textbf{D.}] $\\infty$\n\t\\end{tasks}\n\t\\item Consider the differential equation\n\t$$\n\t\\frac{d^{2} x}{d t^{2}}+2 \\frac{d x}{d t}+x=0\n\t$$\n\twith the initial conditions $x(0)=0$ and $\\dot{x}(0)=1$. The solution $x(t)$ attains its maximum value when $t$ is\n\t{\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $1 / 2$\n\t\t\\task[\\textbf{B.}] 1\n\t\t\\task[\\textbf{C.}] 2\n\t\t\\task[\\textbf{D.}] $\\infty$\n\t\\end{tasks}\n\t\\item Consider the differential equation $\\frac{d^{2} x}{d t^{2}}-3 \\frac{d x}{d t}+2 x=0$. If $x=0$ at $t=0$ and $x=1$ at $t=1$, the value of $x$ at $t=2$ is\n\t{\\exyear{NET/JRF(JUNE-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $e^{2}+1$\n\t\t\\task[\\textbf{B.}] $e^{2}+e$\n\t\t\\task[\\textbf{C.}] $e+2$\n\t\t\\task[\\textbf{D.}] $2 e$\n\t\\end{tasks}\n\t\\item  If $y=\\frac{1}{\\tanh (x)}$, then $x$ is\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\ln \\left(\\frac{y+1}{y-1}\\right)$\n\t\t\\task[\\textbf{B.}] $\\ln \\left(\\frac{y-1}{y+1}\\right)$\n\t\t\\task[\\textbf{C.}]  $\\ln \\sqrt{\\frac{y-1}{y+1}}$\n\t\t\\task[\\textbf{D.}]  $\\ln \\sqrt{\\frac{y+1}{y-1}}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation $\\frac{d x}{d t}=2 \\sqrt{1-x^{2}}$, with initial condition $x=0$ at $t=0$ is\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $x=\\left\\{\\begin{array}{ll}\\sin 2 t, & 0 \\leq t<\\frac{\\pi}{4} \\\\ \\sinh 2 t, & t \\geq \\frac{\\pi}{4}\\end{array}\\right.$\n\t\t\\task[\\textbf{B.}] $x=\\left\\{\\begin{array}{cc}\\sin 2 t, & 0 \\leq t<\\frac{\\pi}{2} \\\\ 1, & t \\geq \\frac{\\pi}{2}\\end{array}\\right.$\n\t\t\\task[\\textbf{C.}] $x=\\left\\{\\begin{array}{cc}\\sin 2 t, & 0 \\leq t<\\frac{\\pi}{4} \\\\ 1, & t \\geq \\frac{\\pi}{4}\\end{array}\\right.$\n\t\t\\task[\\textbf{D.}] $x=1-\\cos 2 t, \\quad t \\geq 0$\n\t\\end{tasks}\n\t\\item   The function $y(x)$ satisfies the differential equation $x \\frac{d y}{d x}+2 y=\\frac{\\cos \\pi x}{x}$. If $y(1)=1$, the value of $y(2)$ is\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\pi$\n\t\t\\task[\\textbf{B.}] 1\n\t\t\\task[\\textbf{C.}] $1 / 2$\n\t\t\\task[\\textbf{D.}] $1 / 4$\n\t\\end{tasks}\n\t\\item   Consider the differential equation $\\frac{d y}{d t}+a y=e^{-b t}$ with the initial condition $y(0)=0$. Then the Laplace transform $Y(s)$ of the solution $y(t)$ is\n\t{\\exyear{NET/JRF(DEC-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{(s+a)(s+b)}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{b(s+a)}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{a(s+b)}$\n\t\t\\task[\\textbf{D.}] $\\frac{e^{-a}-e^{-b}}{b-a}$\n\t\\end{tasks}\n\t\\item The number of linearly independent power series solutions, around $x=0$, of the second order linear differential equation $x \\frac{d^{2} y}{d x^{2}}+\\frac{d y}{d x}+x y=0$, is\n\t{\\exyear{NET/JRF(DEC-2017)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] 0 (this equation does not have a power series solution)\n\t\t\\task[\\textbf{B.}] 1\n\t\t\\task[\\textbf{C.}] 2\n\t\t\\task[\\textbf{D.}] 3\n\t\\end{tasks}\n\t\\item The differential equation $\\frac{d y(x)}{d x}=\\alpha x^{2}$, with the initial condition $y(0)=0$, is solved using Euler's method. If $y_{E}(x)$ is the exact solution and $y_{N}(x)$ the numerical solution obtained using $n$ steps of equal length, then the relative error $\\left|\\frac{\\left(y_{N}(x)-y_{E}(x)\\right)}{y_{E}(x)}\\right|$ is proportional to\n\t{\\exyear{NET/JRF(DEC-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{n^{2}}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{n^{3}}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{n^{4}}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{n}$\n\t\\end{tasks}\n\t\\item  Consider the following ordinary differential equation\n\t$$\n\t\\frac{d^{2} x}{d t^{2}}+\\frac{1}{x}\\left(\\frac{d x}{d t}\\right)^{2}-\\frac{d x}{d t}=0\n\t$$\n\twith the boundary conditions $x(t=0)=0$ and $x(t=1)=1 .$ The value of $x(t)$ at $t=2$ is\n\t{\\exyear{NET/JRF(JUNE-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\sqrt{e-1}$\n\t\t\\task[\\textbf{B.}] $\\sqrt{e^{2}+1}$\n\t\t\\task[\\textbf{C.}]  $\\sqrt{e+1}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{e^{2}-1}$\n\t\\end{tasks}\n\t\\item  In terms of arbitrary constants $A$ and $B$, the general solution to the differential equation $x^{2} \\frac{d^{2} y}{d x^{2}}+5 x \\frac{d y}{d x}+3 y=0$ is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}]  $y=\\frac{A}{x}+B x^{3}$\n\t\t\\task[\\textbf{B.}] $y=A x+\\frac{B}{x^{3}}$\n\t\t\\task[\\textbf{C.}] $y=A x+B x^{3}$\n\t\t\\task[\\textbf{D.}] $y=\\frac{A}{x}+\\frac{B}{x^{3}}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation $x \\frac{d y}{d x}+(1+x) y=e^{-x}$ with the boundary condition $y(x=1)=0$, is\n\t{\\exyear{NET/JRF(JUNE-2019)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{(x-1)}{x} e^{-x}$\n\t\t\\task[\\textbf{B.}] $\\frac{(x-1)}{x^{2}} e^{-x}$\n\t\t\\task[\\textbf{C.}] $\\frac{(1-x)}{x^{2}} e^{-x}$\n\t\t\\task[\\textbf{D.}] $(x-1)^{2} e^{-x}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation $\\left(\\frac{d y}{d x}\\right)^{2}-\\frac{d^{2} y}{d x^{2}}=e^{y}$, with the boundary conditions $y(0)=0$ and $y^{\\prime}(0)=-1$, is\n\t{\\exyear{NET/JRF(JUNE-2020)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $-\\ln \\left(\\frac{x^{2}}{2}+x+1\\right)$\n\t\t\\task[\\textbf{B.}] $-x \\ln (e+x)$\n\t\t\\task[\\textbf{C.}] $-x e^{-x^{2}}$\n\t\t\\task[\\textbf{D.}]  $-x(x+1) e^{-x}$\n\t\\end{tasks}\n\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{D} &2&\\textbf{D}\\\\\\hline \n\t\t3&\\textbf{D} &4&\\textbf{A} \\\\\\hline\n\t\t5&\\textbf{B} &6&\\textbf{B} \\\\\\hline\n\t\t7&\\textbf{D}&8&\\textbf{C}\\\\\\hline\n\t\t9&\\textbf{D}&10&\\textbf{A}\\\\\\hline\n\t\t11&\\textbf{B} &12&\\textbf{D}\\\\\\hline\n\t\t13&\\textbf{C}&14&\\textbf{D}\\\\\\hline\n\t\t15&\\textbf{A}&16&\\textbf{A} \\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\newpage\n\\begin{abox}\n\tProblem Set -2\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item  The solution of the differential equation for $y(t): \\frac{d^{2} y}{d t^{2}}-y=2 \\cosh (t)$, subject to the initial conditions $y(0)=0$ and $\\left.\\frac{d y}{d t}\\right|_{t=0}=0$, is\n\t{\\exyear{GATE 2010}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2} \\cosh (t)+t \\sinh (t)$\n\t\t\\task[\\textbf{B.}] $-\\sinh (t)+t \\cosh (t)$\n\t\t\\task[\\textbf{C.}] $t \\cosh (t)$\n\t\t\\task[\\textbf{D.}] $t \\sinh (t)$\n\t\\end{tasks}\n\t\\item The solutions to the differential equation $\\frac{d y}{d x}=-\\frac{x}{y+1}$ are a family of\n\t{\\exyear{GATE 2011}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] Circles with different radii\n\t\t\\task[\\textbf{B.}] Circles with different centres\n\t\t\\task[\\textbf{C.}]  Straight lines with different slopes\n\t\t\\task[\\textbf{D.}]  Straight lines with different intercepts on the $y$-axis\n\t\\end{tasks}\n\t\\item The solution of the differential equation $\\frac{d^{2} y}{d t^{2}}-y=0$, subject to the boundary conditions $y(0)=1$ and $y(\\infty)=0$ is\n\t{\\exyear{GATE 2014}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\cos t+\\sin t$\n\t\t\\task[\\textbf{B.}] $\\cosh t+\\sinh t$\n\t\t\\task[\\textbf{C.}] $\\cos t-\\sin t$\n\t\t\\task[\\textbf{D.}]  $\\cosh t-\\sinh t$\n\t\\end{tasks}\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\\item Consider the linear differential equation $\\frac{d y}{d x}=x y$. If $y=2$ at $x=0$, then the value of $y$ at $x=2$ is given by\n\t{\\exyear{GATE 2016}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}]  $e^{-2}$\n\t\t\\task[\\textbf{B.}] $2 e^{-2}$\n\t\t\\task[\\textbf{C.}] $e^{2}$\n\t\t\\task[\\textbf{D.}]  $2 e^{2}$\n\t\\end{tasks}\n\t\\item Consider the differential equation $\\frac{d y}{d x}+y \\tan (x)=\\cos (x)$. If $y(0)=0, y\\left(\\frac{\\pi}{3}\\right)$ is ............... (up to two decimal places)\n\t{\\exyear{GATE 2017}}\n\t\\item Given\n\t$$\n\t\\frac{d^{2} f(x)}{d x^{2}}-2 \\frac{d f(x)}{d x}+f(x)=0\n\t$$\n\tand boundary conditions $f(0)=1$ and $f(1)=0$, the value of $f(0.5)$ is --------(up\n\tto two decimal places).\n\t{\\exyear{GATE 2018}}\n\t\\item  For the differential equation $\\frac{d^{2} y}{d x^{2}}-n(n+1) \\frac{y}{x^{2}}=0$, where $n$ is a constant, the product of\n\tits two independent solutions is\n\t{\\exyear{GATE 2019}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{x}$\n\t\t\\task[\\textbf{B.}] $x$\n\t\t\\task[\\textbf{C.}] $x^{n}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{x^{n+1}}$\n\t\\end{tasks}\n\t\\end{enumerate}\n\\newpage \n\\begin{abox}\n\tProblem Set -3\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item The order and degree of the differential equation $y+\\frac{d y}{d x}=\\frac{1}{4} \\int y \\cdot d x$ are\n\t\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]order $=2$ and degree $=1$ \n\t\t\\task[\\textbf{b.}]order $=1$ and degree $=2$\n\t\t\\task[\\textbf{c.}]order $=1$ and degree $=1$ \n\t\t\\task[\\textbf{d.}]order $=2$ and degree $=2$ \n\t\\end{tasks}\n\t\\begin{answer}\n\t\tWe have\n\t\t\\begin{align*}\n\t\ty+\\frac{d y}{d x}&=\\frac{1}{4} \\int y \\cdot d x \\\\\n\t\t\\Rightarrow \\frac{d y}{d x}+\\frac{d^{2} y}{d x^{2}}&=\\frac{1}{4} y \\quad \\text { [on  differentiating w.r.t. $x$] }\n\t\t\\end{align*}\n\t\tDifferential equation is of order 2 and degree $1 .$\\\\\\\\\n\t\tCorrect answer is \\textbf{option(a)}\n\t\\end{answer}\n\t\\item The following differential equation has\n\t$$\n\t3\\left(\\frac{d^{2} y}{d t^{2}}\\right)+4\\left(\\frac{d y}{d t}\\right)^{3}+y^{2}+2=x\n\t$$\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]Degree $=2,$ order $=1$  \n\t\t\\task[\\textbf{b.}]Degree $=1,$ order $=2$\n\t\t\\task[\\textbf{c.}]Degree $=4,$ order $=3$ \n\t\t\\task[\\textbf{d.}]Degree $=2,$ order $=3$ \n\t\\end{tasks}\n\t\\begin{answer}\n\t\tThe highest derivative term of the equation is $2,$ hence order $=2$. The power of highest derivative term is 1 , hence degree $=1$\n\t\t\\\\\\\\\tCorrect answer is \\textbf{option (b)}.\n\t\\end{answer}\n\t\\item  If $y(x)$ is the solution of the differential equation $-x \\frac{d y}{d x}+y=y^{2} \\log x$ with $y(1)=-1$\n\tthen\\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}] $y(x)$ is defined and finite in the range $-\\infty<x<0$ \n\t\t\\task[\\textbf{b.}]$y(x)$ is defined and finite in the range $0<x<3$\n\t\t\\task[\\textbf{c.}] $y(x)$ is defined and finite in the range $x \\geq 3$\n\t\t\\task[\\textbf{d.}]  $y(x)$ blows up at $x=e$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t-x \\frac{d y}{d x}+y&=y^{2} \\log x \\\\\\Rightarrow-\\frac{d y}{d x}+\\frac{y}{x}&=y^{2} \\frac{\\log x}{x}\\\\ \\Rightarrow-\\frac{1}{y^{2}} \\frac{d y}{d x}+\\frac{1}{x} \\times \\frac{1}{y}&=\\frac{\\log }{x}\\\\\n\t\t\\text { Let } \\frac{1}{y}&=z \\Rightarrow-\\frac{1}{y^{2}} \\frac{d y}{d x}=\\frac{d z}{d x}\\\\\n\t\t\\text { Therefore, } \\frac{d z}{d x}+\\frac{z}{x}&=\\frac{\\log x}{x} \\Rightarrow \\frac{d z}{d x}+\\frac{1}{x} z=\\frac{\\log x}{x}\\\\\n\t\t\\text { Here, } \\text { I.F. }&=e^{\\int \\frac{1}{x} d x}=e^{\\log x}=x\\\\\n\t\t\\text { Therefore, required solution will be }\\\\\\qquad z x=\\int \\frac{\\log x}{x} \\times x d x+c \\Rightarrow \\frac{x}{y}&=\\int \\log x+c \\Rightarrow \\frac{x}{y}=(x \\log x-x)+c \\\\\n\t\t\\text { Now, } y(1)=-1, \\text { put } x=1, y=-1 \\quad &\\Rightarrow-1=0-1+c \\Rightarrow c=0 \\\\\n\t\t\\text { Therefore, } \\frac{x}{y}&=x \\log x-x \\Rightarrow y=\\frac{1}{\\log x-1}\n\t\t\\end{align*}\n\t\tTherefore, for $y$ to be defined $\\log x$ must be defined i.e., $x>0$\\\\\n\t\t\\\\ The solution will not be defined when $(\\log x-1)=0\\Rightarrow \\log x=1 \\Rightarrow x=e \\simeq 2.73$\n\t\t\\\\\\\\So in the range $0<x<3$ [option (b)], there will be a point $x=2.73$ at which $y$ is not defined.\\\\\\\\ Then  Correct answers are \\textbf{option (c)} and \\textbf{option (d)}.\n\t\\end{answer}\n\t\\item The initial velocity of an object is $40 \\mathrm{~m} / \\mathrm{s}$. The acceleration $a$ of the object is given by the following expression:\n\t$$\n\ta=-0.1 v\n\t$$\n\twhere $v$ is the instantaneous velocity of the object. The velocity of the object after $3 \\mathrm{~s}$ will be\n\t\\begin{answer}\n\t\tWe are given the following expression:\n\t\t\n\t\t\\begin{align*}{c}\n\t\ta&=-0.1 v \\\\\n\t\t\\frac{d v}{d t}&=-0.1 v \\\\\n\t\t\\frac{d v}{v}&=-0.1 d t \n\t\t\\intertext{On integration we get,}\n\t\t\\ln v&=-0.1 t+\\ln k \\\\\n\t\tv&=k e^{-0.1 t}\\\\\n\t\t\\text{\tat $t=0 ; v=40$}\n\t\t\\Rightarrow k&=40\\\\\n\t\tv&=40 e^{-0.1 t}\\\\\n\t\t\\text{\tAt $t=3 \\mathrm{~s}$}, \n\t\tV&=40 e^{-0.1 \\times 3}=29.6327 \\mathrm{~m} / \\mathrm{s}\n\t\t\\end{align*}\n\t\t\n\t\t\n\t\t\n\t\\end{answer}\n\t\\item Solve $y d x-x d y+\\left(1+x^{2}\\right) d x+x^{2} \\sin y d y=0$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{\tDividing each term of the given equation by \\quad}x^{2}, \\text{we get}\\\\\n\t\t\\frac{y d x-x d y}{x^{2}}+\\frac{1+x^{2}}{x^{2}} d x+\\sin y d y&=0\\\\ \\Rightarrow-\\frac{x d y-y d x}{x^{2}}+\\left(\\frac{1}{x^{2}}+1\\right) d x+\\sin y d y&=0\\\\\n\t\t\\Rightarrow-d\\left(\\frac{y}{x}\\right)+\\left(1+\\frac{1}{x^{2}}\\right) d x+\\sin y d y&=0\\\\\n\t\t\\text{Integrating,}\\\\ -\\left(\\frac{y}{x}\\right)+x-\\frac{1}{x}&=\\cos y+c \\\\\\Rightarrow-y+x^{2}-1-x \\cos y&=c x\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item One of the possible solutions of the differential equation\n\t$y \\sqrt{\\left(1+x^{2}\\right)} d y+x \\sqrt{\\left(1+y^{2}\\right)} d x=0$ (where $c$ is some constant) is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\left(\\sqrt{1+y^{2}}\\right)\\left(\\sqrt{1+x^{2}}\\right)=c$ \n\t\t\\task[\\textbf{b.}]$\\frac{\\sqrt{1+y^{2}}}{\\sqrt{1+x^{2}}}=c$\n\t\t\\task[\\textbf{c.}]$\\sqrt{1+y^{2}}+\\sqrt{1+x^{2}}=c$ \n\t\t\\task[\\textbf{d.}]$\\sqrt{1+y^{2}}-\\sqrt{1+x^{2}}=c$ \n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\ty \\sqrt{\\left(1+x^{2}\\right)} d y+x \\sqrt{\\left(1+y^{2}\\right)} d x&=0\\\\ \\frac{y}{\\sqrt{1+y^{2}}} d y+ \\frac{x}{\\sqrt{1+x^{2}}} d x&=0 \\\\\n\t\t\\int \\frac{y}{\\sqrt{1+y^{2}}} d y+\\int \\frac{x}{\\sqrt{1+x^{2}}} d x&=c \n\t\t\\intertext{ Let,\\ $1+y^{2}=t$ and  $1+x^{2}=z$ }\n\t\t\\int \\frac{1}{2} t^{-1/2} d t+\\int \\frac{1}{2} z^{-1/2} d z&=c \\\\\n\t\t\\sqrt{t}+ \\sqrt{z}&=c \\\\\n\t\t\\sqrt{1+y^{2}}+\\sqrt{1+x^{2}}&=c\n\t\t\\end{align*}\n\t\tCorrect answer is \\textbf{option (c)}.\n\t\\end{answer}\n\t\\item The solution of the differential equation\n\t$\\left(e^{y}+2\\right) \\sin x d x-e^{y} \\cos x d y=0$ (where $c$ is some constant) is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\left(e^{y}+2\\right) \\sin x=c$ \n\t\t\\task[\\textbf{b.}]$\\left(e^{y}+2\\right) \\cos x=c$\n\t\t\\task[\\textbf{c.}] $\\left(e^{y}+2\\right) \\operatorname{cosec} x=c$\n\t\t\\task[\\textbf{d.}] $\\left(e^{y}+2\\right) \\sec x=c$ \n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tM&=\\left(e^{y}+2\\right) \\sin x \\quad  N=-e^{y} \\cos x \\\\ \\frac{\\partial M}{\\partial y}&=e^{y} \\sin x \\quad  \\frac{\\partial N}{\\partial x}=e^{y} \\sin x \\\\\n\t\t\\Rightarrow \\frac{\\partial M}{\\partial y}&=\\frac{\\partial N}{\\partial x} \\\\ \\int\\left(e^{y}+2\\right) \\sin x d x+0&=c \\\\\\left(e^{y}+2\\right) \\cos x&=-c=c\\\\\n\t\t\\left(e^{y}+2\\right) \\cos x&=c\n\t\t\\end{align*}\n\t\tCorrect answer is \\textbf{option (b)}.\t\n\t\\end{answer}\n\t\\item Solve $x(y-x) \\frac{dy}{dx}= y(y+x)$\n\t\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text {  Let, }\\ \\mathrm{y}&=\\mathrm{v} \\mathrm{x} ; \\quad  \\frac{d y}{d x}=\\mathrm{v}+\\mathrm{x} \\frac{d v}{d x}\\\\\n\t\t\\mathrm{v}+\\mathrm{x} \\frac{d v}{d x}&=\\frac{v^{2}x^{2}+v x^{2}}{v x^{2}-x^{2}}=\\frac{v^{2}+v }{v -1}\\\\\n\t\t\\mathrm{x} \\frac{d v}{d x}&=\\frac{2v}{v-1}\\\\\n\t\t\\frac{v-1}{2v}{d v}&=\\frac{1}{x}{d x}\\\\\n\t\t\\int \\frac{1}{2} dv-\\int \\frac{1}{2v} dv&=\\int \\frac{1}{x} dx\\\\\n\t\t\\int \\frac{1}{2} dv- \\frac{1}{2}\\int\\frac{1}{v} dv&=\\int \\frac{1}{x} dx\\\\\n\t\t\\frac{1}{2}v- \\frac{1}{2}\\log{v} &=\\log{x}+C\\\\\n\t\tv- \\log{v} &=2\\log{x}+C\\\\\n\t\tv&=\\frac{y}{x}\\\\\n\t\t\\text{Then,}\\ \\frac{y}{x}-\\log{{\\frac{y}{x}}x^{2}}&=C\\\\\n\t\t\\frac{y}{x}-\\log{xy}&=C\\\\\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Determine the order and degree of\n\t$$\n\t\\frac{\\left[1+(d y / d x)^{2}\\right]^{3 / 2}}{d^{2} y / d x^{2}}=K\n\t$$\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] Order =1 and Degree = 2\n\t\t\\task[\\textbf{b.}] Order =2 and Degree = 2\n\t\t\\task[\\textbf{c.}] Order =2 and Degree = 1\n\t\t\\task[\\textbf{d.}]Order =2 and Degree = 3\n\t\\end{tasks}\n\t\\begin{answer}\n\t\tThe given differential equation when written as a polynomial in derivatives becomes\n\t\t$$\n\t\tK^{2}\\left(\\frac{d^{2} y}{d x^{2}}\\right)^{2}=\\left[1+\\left(\\frac{d y}{d x}\\right)^{2}\\right]^{3}\n\t\t$$\n\t\tThe highest order differential coefficient in this\n\t\tequation is $\\frac{d^{2} y}{d x^{2}}$ and its power is 2 .\n\t\t\\\\The order is 2 and degree is 2 .\\\\\\\\The correct answer is option \\textbf{b} .\n\t\\end{answer}\n\t\\item Consider a linear ordinary differential equation:\n\t$\\frac{d y}{d x}+p(x) y=r(x)$. Functions $p(x)$ and $r(x)$ are defined and have a continuous first derivative. The integrating factor of this equation is non-zero. Multiplying this equation by its integrating factor converts this into a:\n\t\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}] Homogeneous differential equation \n\t\t\\task[\\textbf{b.}]Non-linear differential equation\n\t\t\\task[\\textbf{c.}]Second-order differential equation \n\t\t\\task[\\textbf{d.}]Exact differential equation\n\t\\end{tasks}\n\t\\begin{answer}\n\t\tLinear differential equation\n\t\t$$\n\t\ty^{\\prime}+p(x) y=r(x)\n\t\t$$\n\t\tMultiplying above equation by integrating factor $e^{\\int p(x) d x}$ makes the equation exact.\\\\The correct answer is option \\textbf{d} .\n\t\\end{answer}\n\t\\item \t The particular integral of the differential equation $\\left(D^{2}+D+1\\right) y=\\cos 2 x$ is $\\frac{1}{\\alpha}(2 \\sin 2 x-3 \\cos 2 x) .$ Then the value of $\\alpha$ is.....\n\n\\begin{answer}\n\t\\begin{align*}\n\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\\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\\end{align*}\n\tSo the correct answer is 13\n\\end{answer}\n\\item The particular integral of the differential equation $\\frac{d^{2} y}{d x^{2}}+2 \\frac{d y}{d x}+2 y=\\sin x$ is $\\frac{1}{5}(\\sin x-\\alpha \\cos x) .$ Then the value of $\\alpha$ is........\n\\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\tSo the correct answer is 2\n\\end{answer}\n\t\\item The particular integral of the differential equation $\\left(D^{2}+5 D+4\\right) y=3-2 x$ is $\\frac{1}{8}[\\alpha-4 x]$.\n\\begin{answer}\n\t\\begin{align*}\n\tP.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\\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\\end{align*}\n\tSo the correct answer is 11\n\\end{answer}\n\\item  Find the Wronskian $W(t)$ of the given differential equation without solving the equation. $\\left(1-x^{2}\\right) y ^{\\prime \\prime}-2 x y^{\\prime} +\\alpha(\\alpha+1) y=0$.\n\\begin{answer}\n\t\\begin{align*}\n\t\\intertext{ Writing the equation in standard form, we find that,}\n\tp(x)&=-2 x /\\left(1-x^{2}\\right)\\\\\n\t \\text{The Wronskian is }\\ W(t)&=c \\cdot \\exp \\left(-\\int \\frac{-2 x}{1-x^{2}} d x\\right)\\\\&=c \\cdot \\exp \\left(-\\ln \\left|1-x^{2}\\right|\\right)\\\\&=c\\left|1-x^{2}\\right|^{-1}\n\t \\intertext{where $c$ is some constant.}\n\t\\end{align*}\n\\end{answer}\n\\item Find whether the functions $1, x, \\sin x$ are linearly independent.\n\\begin{answer}\n\t We write and evaluate the Wronskian,\n\t $$\n\t W=\\left|\\begin{array}{rrr}\n\t 1 & x & \\sin x \\\\\n\t 0 & 1 & \\cos x \\\\\n\t 0 & 0 & -\\sin x\n\t \\end{array}\\right|=-\\sin x\n\t $$\n\t Since $-\\sin x$ is not identically equal to zero, the functions are linearly independent.\n\t \n\\end{answer}\n\n\t\n\\end{enumerate}\n\n\n\n\n", "meta": {"hexsha": "4feb75bc3a935f30c6ce0efc7ce3afd7a09fc46d", "size": 61545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Differential equations.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/Differential equations.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/Differential equations.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.2818627451, "max_line_length": 460, "alphanum_fraction": 0.6138922739, "num_tokens": 25251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385542, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.6645795807686375}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\n\\usepackage{ucs}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage[english]{babel}\n\\usepackage[T1]{fontenc}\n\\usepackage[pdftex]{graphicx}\n\\usepackage[margin=2.5cm]{geometry}\n\n\\usepackage[pdftex]{hyperref}\n\\usepackage{url}\n\n\\title{Frequentist coverage study: intervals for a binomial parameter}\n\\author{}\n\\date{}\n\n\\begin{document}\n \\maketitle\n \n We are studying the case of a binomial law:\n \n $$P(n) = B(n;N,p) = \\left( ^N_n \\right) p^n (1-p)^{N-n}$$\n \n This corresponds to repeating an experiment $N$ times, and counting $n$ the number of times of ``sucess'', where the probability for this success is $p$. $n$ is a random variable and follows this binomial law, of parameters $N$ and $p$. One real-life example is the estimation of an efficiency: for instance, $n$ could be the number of counts in a particle detector,\n or passing some selection, while $N$ is the total number of particles or events considered.\n \n Interval estimation of the binomial parameter $p$ is a common problem, however nontrivial because the problem is discrete. There is abundant bibliography on the subject, and we will review\n some of the most popular methods available, as well as their frequentist coverage.\n \n \\section{Prelude}\n \n \\begin{enumerate}\n  \\item Show that the mean is $E(n) = pN$ and the variance $V(n) = N p (1-p)$.\n  \\item What is the maximum likelihood estimate $\\hat{p}$? What is its variance?\n  \\item Propose a simple algorithm for generating $n$ following a binomial law $B(n;N,p)$, assuming a uniform generator between 0 and 1.\n  \\item Draw the binomial distribution for $N=10$, $p=0.9$.\n \\end{enumerate}\n \n \\section{Interval estimation}\n \n For convenience, we will use the notation \n \n $$Z_{\\alpha/2} = \\Phi^{-1}(1-\\alpha/2) = -\\Phi^{-1}(\\alpha / 2)$$\n \n where\n \n $$\\Phi(Z) = \\frac{1}{\\sqrt{2\\pi}} \\int_{-\\infty}^Z \\exp(-t^2 / 2) \\text{d} t = \\frac{1+\\text{erf}(Z/\\sqrt{2})}{2},$$\n \n so that\n \n $$Z = \\sqrt{2}\\, \\text{erf}^{-1} (1-\\alpha).$$\n \n Example: $Z_{\\alpha/2} = 1$ for $1-\\alpha = 0.6827$.\n \n \\begin{enumerate}\n  \\item \\textbf{Wald interval} This procedure (that we will see should be avoided) simply substitutes $\\hat{p}$ for $p$ in the variance of $n$, in a Gaussian approximation. Give explicitly\n  the Wald interval for any C.L.\n  \\item \\textbf{Wilson score interval} The Wald intervals neglect the fact that $V(\\hat{p})$ depends on p. E.B. Wilson proposed in 1927 to quote the largest interval $[p_1,p_2]$ such that $p_1 + Z_{\\alpha/2} \\sigma(p_1) < \\hat{p} < p_2-Z_{\\alpha/2}\\sigma(p_2)$. Give the expression for such interval.\n  \\item \\textbf{Agresti and Coull} These authors proposed to use the midpoint $\\tilde{p}$ of the Wilson interval in the formula for the Wald interval, instead of the MLE $\\hat{p}$. Give the corresponding interval.\n  \\item \\textbf{Clopper-Pearson} These intervals use the Neyman construction and ensure strict frequentist coverage. The ordering rule is as follows: the lower and upper limits are constructed separately, with C.L. $(1-\\alpha)/2$. \n%   \\begin{enumerate}\n    Write a function that builds the confidence belt in the $(n,p)$ plane. You may first build the lower limits, then the upper limits, and combine the two together. \n   Draw it for $N=10$ and with a step size in $p$ of 0.01.\n%    \\item The duality with hypothesis test inversion may also be used: use this method to give the C-P interval in $p$ for given $n$ and $N$. \n%    It can be done analytically using the following identity:\n%    $$\\sum_{i=n}^{N} \\left(^N_i\\right) p^i (1-p)^{N-i} = I_p (n,N-n+1)$$\n%    where $I_p (\\alpha,\\beta)$ is the regularised incomplete Beta function:\n%    $$I_p (\\alpha,\\beta) = \\frac{\\text{B}(p;\\alpha,\\beta)}{\\text{B}(\\alpha,\\beta)},$$\n%    defined from the incomplete Beta function,\n%    $$\\text{B} (p;\\alpha,\\beta)=\\int _{0}^{p}t^{\\alpha-1}\\,(1-t)^{\\beta-1}\\text{d}t.$$\n%    The incomplete Beta function is available in \\texttt{scipy} as \\texttt{scipy.special.betainc}.\n%   \\end{enumerate}\n%   \\item \\textbf{Feldman-Cousins} The Neyman construction is used again, this time with the likelihood ratio ordering. Write this likelihood ratio and repeat confidence belt construction\n%   as above.\n% %   \\item \\textbf{Lancaster mid-P} This methods aims at solving the large overcoverage of the Clopper-Pearson intervals. In the Neyman construction, this time half of the probability of the observed $n_\\text{obs}$ is added to the tail of the probability. \n%   \\item \\textbf{Bayesian with uniform prior} Give the posterior Bayesian probability for $p$ assuming a uniform prior, and use it to define the corresponding central interval (with equal posterior probability on both sides). It will be useful to use the Beta distribution: \n%   $$\\text{Beta}(p;\\alpha,\\beta) = \\frac{1}{B(\\alpha,\\beta)} p^{\\alpha-1} (1-p)^{\\beta-1}.$$\n%   \\item \\textbf{Bayesian with Jeffreys' prior} Show that Jeffreys' prior for $p$ is proportional to $1/\\sqrt{p(1-p)}$. Give the Bayesian posterior probability and the corresponding central interval with this prior.\n \\end{enumerate}\n\n \\subsection{Comparison of the intervals in particular cases}\n \n Compare the intervals on $p$ from the above methods, in the following cases:\n \n \\begin{itemize}\n \\item $N=10$, $n=10$\n  \\item $N=10$, $n=9$\n  \\item $N=10$, $n=5$\n  \\item $N=100$, $n=90$\n \\end{itemize}\n\n \n \\section{Study of frequentist coverage properties of various types of intervals}\n \n For each of the intervals above, study the frequentist properties of the interval estimation for $p$. In practice this is done in the following way:\n \\begin{itemize}\n  \\item Fix the true value of the parameters $p$ and $N$;\n  \\item Generate $n$ according to $B(n;N,p)$;\n  \\item Compute the interval knowing $n$ and $N$;\n  \\item Check if the true value of $p$ is in this interval;\n  \\item Repat $N_\\text{trials}$ times (e.g. 1000 times);\n  \\item Report the fraction of times that the true value of $p$ was inside the interval, and compare to the target confidence level (C.L.).\n \\end{itemize}\n\n We will study 68.27\\% C.L. intervals, in 3 ways:\n \n \\begin{enumerate}\n  \\item set $N=10$ and check coverage as a function of $p$ for $0 \\leq p \\leq 1$\n  \\item make a 2-dimensional plot of coverage as a function of $p$ and $N$, for $0 \\leq p \\leq 1$ and $2 \\leq N \\leq 20$\n  \\item average the previous plot over all values of $p$, to get the average coverage as a function of $N$.\n \\end{enumerate}\n\n \\begin{thebibliography}{9}\n  \\bibitem{Cousins:2009kz}\n  R.~D.~Cousins, K.~E.~Hymes and J.~Tucker,\n  %``Frequentist evaluation of intervals estimated for a binomial parameter and for the ratio of Poisson means,''\n  Nucl.\\ Instrum.\\ Meth.\\ A {\\bf 612} (2010) 388\n  doi:10.1016/j.nima.2009.10.156\n  [arXiv:0905.3831 [physics.data-an]].\n  %%CITATION = doi:10.1016/j.nima.2009.10.156;%%\n  %19 citations counted in INSPIRE as of 14 Nov 2018\n  \\bibitem{root} \\texttt{TEfficiency} class documentation, \\url{https://root.cern.ch/doc/master/classTEfficiency.html}.\n \\end{thebibliography}\n\n\n\\end{document}\n \n", "meta": {"hexsha": "569d13a716ba48ef063fcb0851e095feeccac535", "size": 7040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exercises/Exercise_Binomial.tex", "max_stars_repo_name": "echapon/CoursStatX", "max_stars_repo_head_hexsha": "2db74273a8a5e543fe034b7c9054c1976c0c9aa7", "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": "Exercises/Exercise_Binomial.tex", "max_issues_repo_name": "echapon/CoursStatX", "max_issues_repo_head_hexsha": "2db74273a8a5e543fe034b7c9054c1976c0c9aa7", "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": "Exercises/Exercise_Binomial.tex", "max_forks_repo_name": "echapon/CoursStatX", "max_forks_repo_head_hexsha": "2db74273a8a5e543fe034b7c9054c1976c0c9aa7", "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.7404580153, "max_line_length": 367, "alphanum_fraction": 0.7083806818, "num_tokens": 2148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6645795624233346}}
{"text": "\\section{Simplifying the expression \\texorpdfstring{$1-w_p(\\phi)^2$ from $y_p(\\phi)$}{}}\n\n\\textit{Objective:} obtain the simplest expression for $1-w_p(\\phi)^2$ in terms of $\\phi,\\beta$.\n\nThe original expression for $1-w_p(\\phi)^2$ is below, with the denominator removed for simplicity.\n\n{\\footnotesize\\begin{align}\n    (3\\pi+8)^2\\beta^4\\sin^2(2k)(1-w_p(\\phi)^2)&=\\underbrace{{(3\\pi+8)^2\\beta^4\\sin^2(2k)-\\left[(3\\pi+8)^2\\beta^4-8(3\\phi+2)(3\\pi+8)\\beta^2+16(3\\phi+2)^2\\right]}}_{\\gamma_1(\\phi)}\\\\\n    &-\\underbrace{{2\\sin(2k)(4\\sin^2(k)+6)((3\\pi+8)\\beta^2-4(3\\phi+2))}}_{\\gamma_2(\\phi)}\\\\\n    &-\\underbrace{{\\sin^2(2k)(16\\sin^4(k)+48\\sin^2(k)+36)}}_{\\gamma_3(\\phi)}\\\\\n    &=\\gamma_1(\\phi)-\\gamma_2(\\phi)-\\gamma_3(\\phi)\n\\end{align}}\n\nApplying Equations 1-3 to the denoted sub-functions $\\gamma_1(\\phi),\\gamma_2(\\phi),\\gamma_3(\\phi)$, we get \n\n\\begin{align}\n    \\gamma_1(\\phi)&=(3 \\pi+8)^{2} \\beta^{4}\\left(\\cos ^{2}(2 \\phi)-1\\right)+8(3 \\phi+2)\\left((3 \\pi+8) \\beta^{2}-2(3 \\phi+2)\\right)\\\\\n    \\gamma_2(\\phi)&=-2(8 \\cos (2 \\phi)+2\\sin(2\\phi)\\cos(2\\phi))\\left((3 \\pi+8) \\beta^{2}-4(3 \\phi+2)\\right)\\\\\n    &=-4\\cos(2\\phi)(\\sin(2\\phi)+2)\\left((3\\pi+8)\\beta^2-4(3\\phi+2)\\right)\\\\\n    \\gamma_3(\\phi)&=-\\cos ^{2}(2 \\phi)\\left(16 \\sin \\left(\\phi+\\frac{\\pi}{4}\\right)^{4}+48 \\sin ^{2}\\left(\\phi+\\frac{\\pi}{4}\\right)+36\\right)\\\\\n    &=-\\cos^2(2\\phi)\\left(4\\sin^2(2\\phi)+6\\right)^2\n\\end{align}\n\nPutting this together, a simplified expression is\n\n\\begin{align}\n    1-w_p(\\phi)^2&=\\frac{\\gamma_1}{(3\\pi+8)^2\\beta^4\\cos^2(2\\phi)}+\\frac{\\gamma_2}{(3\\pi+8)^2\\beta^4\\cos^2(2\\phi)}+\\frac{\\gamma_3}{(3\\pi+8)^2\\beta^4\\cos^2(2\\phi)}\\\\\n    &=\\underbrace{\\frac{\\cos^2(2\\phi)-1}{\\cos^2(2\\phi)}}_{\\frac{-(1-\\cos^2(2\\phi))}{\\cos^2(2\\phi)}=\\frac{-\\sin^2(2\\phi)}{\\cos^2(2\\phi)}=\\boxed{-\\tan^2(2\\phi)}}+\\frac{8(3\\phi+2)((3\\pi+8)\\beta^2-2(3\\phi+2))}{(3\\pi+8)^2\\beta^4\\cos^2(2\\phi)}\\\\\n    &-\\frac{4(\\sin(2\\phi)+2)((3\\pi+8)\\beta^2-4(3\\phi+2))}{(3\\pi+8)^2\\beta^4\\cos(2\\phi)}-\\frac{\\left(4\\sin^2(2\\phi)+6\\right)^2}{(3\\pi+8)^2\\beta^4}\n\\end{align}\n\nBecause $y_p(\\phi)=\\sqrt{1-w_p(\\phi)^2}\\sqrt{\\frac{\\mu}{r_0}}\\cot(\\phi+\\pi/4)$, by substitution\n\n{\\tiny\\begin{equation}\n    \\boxed{y_p(\\phi)=\\sqrt{-\\tan^2(2\\phi)+\\frac{8(3\\phi+2)((3\\pi+8)\\beta^2-2(3\\phi+2))}{(3\\pi+8)^2\\beta^4\\cos^2(2\\phi)}-\\frac{4(\\sin(2\\phi)+2)((3\\pi+8)\\beta^2-4(3\\phi+2))}{(3\\pi+8)^2\\beta^4\\cos(2\\phi)}-\\frac{\\left(4\\sin^2(2\\phi)+6\\right)^2}{(3\\pi+8)^2\\beta^4}}\\sqrt{\\frac{\\mu}{r_0}}\\cot(\\phi+\\pi/4)}\n\\end{equation}}", "meta": {"hexsha": "d96c86629f993722a81fbd322a363d55197a6aac", "size": 2449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/simplifying.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/simplifying.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/simplifying.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": 68.0277777778, "max_line_length": 299, "alphanum_fraction": 0.5928950592, "num_tokens": 1213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6645737055943244}}
{"text": "\\section{Computing the Time-Step Using Higher-Order DG Schemes}\n\nWhen making the jump to higher-order DG schemes, we can simply do the same as in the first-order scheme, except we compute the quantities in all of the nodal points instead of using a cell-average. This is valid because the cell-average is a convex combination...\\sd{Need to expand on this}. The proof starts with the discretized equation valid at each quadrature point, $q$:\n\\begin{equation}\n    \\bU_{q}^{n+1}=\\bU_{q}^{n}+\\Delta t\\,\\cL_{q}^{n},\n\\end{equation}\nwhere $\\cL_{q}^{n}$ is a general form of the RHS at time $t^{n}$. If we define a vector $\\ol{\\bU}\\equiv\\left(\\bU_{1},\\cdots,\\bU_{q},\\cdots,\\bU_{Q}\\right)^T$, where $Q$ is the total number of quadrature points, and $\\ol{\\bW}\\equiv\\left(\\bW_{1},\\cdots,\\bW_{q},\\cdots,\\bW_{Q}\\right)^T$ as a vector of quadrature weights, then we can write the cell-average of $\\bU$ as:\n\\begin{equation}\n    \\bU_{K}\\equiv\\ol{\\bW}^T\\ol{\\bU}.\n\\end{equation}\nIf we then compute the cell-average of the above equation, we get:\n\\begin{equation}\n    \\bU_{K}^{n+1}=\\bU_{K}^{n}+\\Delta t\\,\\ol{\\bW}^{T}\\,\\ol{\\cL}_{q}^{n}=\\ol{\\bW}^{T}\\left(\\ol{\\bU}^{n}+\\Delta t\\,\\ol{\\cL}^{n}\\right)\n\\end{equation}\n\n\\subsection{High-Order Time-Step Restriction for DG}\n\n\\blue{NOTE:} This closely follows Jesse's document CFLCondition.pdf.\n\nConsider the one-dimensional system of hyperbolic balance equations:\n\\begin{equation}\\label{Eq:HypBalEqns}\n    \\pd{\\left(\\sqrtgm\\,\\bU\\right)}{t}+\\pd{\\left(\\sqrtgm\\,\\bF^{1}\\left(\\bU\\right)\\right)}{1}=\\sqrtgm\\,\\bQ,\n\\end{equation}\nwhere $\\bU$ is a vector of conserved variables, $\\bF^{1}\\left(\\bU\\right)$ are the fluxes of those conserved variables in the $x^{1}$-direction, $\\bQ$ is a source term, and $\\sqrtgm$ is the square-root of the determinant of the spatial three-metric.\n\nWe define our reference element by:\n\\begin{equation}\n    I_{j}\\equiv\\left\\{x^{1}:x^{1}\\in\\left(x^{1}_{L},x^{1}_{H}\\right)=\\left(x^{1}_{\\jmh},x^{1}_{\\jph}\\right)\\right\\}.\n\\end{equation}\n\nWe proceed by multiplying \\eqref{Eq:HypBalEqns} with $v$, where $v=v\\left(x^{1}\\right)$ is a test function in the DG scheme, and integrate over the $\\jth$ element:\n\\begin{equation}\n    \\int_{I_{j}}\\pd{\\left(\\sqrtgm\\,\\bU\\right)}{t}\\,v\\,dx^{1}+\\int_{I_{j}}\\pd{\\left(\\sqrtgm\\,\\bF^{1}\\left(\\bU\\right)\\right)}{1}\\,v\\,dx^{1}=\\int_{I_{j}}\\sqrtgm\\,\\bQ\\,v\\,dx^{1}.\n\\end{equation}\nWe now move the flux term to the RHS and perform integration-by-parts on it, yielding:\n\\begin{equation}\\label{Eq:IntByParts}\n    \\int_{I_{j}}\\pd{\\left(\\sqrtgm\\,\\bU\\right)}{t}\\,v\\,dx^{1}=-\\left[\\sqrtgm\\,\\hat{\\bF^{1}}\\,v\\Big|_{x^{1}_{H}}-\\sqrtgm\\,\\hat{\\bF^{1}}\\,v\\Big|_{x^{1}_{L}}\\right]+\\int_{I_{j}}\\sqrtgm\\,\\bF^{1}\\,\\pd{v}{1}\\,dx^{1}+\\int_{I_{j}}\\sqrtgm\\,\\bQ\\,v\\,dx^{1},\n\\end{equation}\nwhere $\\hat{\\bF^{1}}$ is a numerical flux.\n\n\\blue{NOTE:} $v=1$ is in the space of test functions for the DG method, \\textit{and} $v=1$ yields the cell-average when substituted into \\eqref{Eq:IntByParts}, therefore the DG method evolves the cell-average.\n\nSubstituting $v=1$ into \\eqref{Eq:IntByParts} yields:\n\\begin{equation}\\label{Eq:CellAverageDG}\n    \\int_{I_{j}}\\pd{\\left(\\sqrtgm\\,\\bU\\right)}{t}\\,dx^{1}=-\\left[\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{H}}-\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{L}}\\right]+\\int_{I_{j}}\\sqrtgm\\,\\bQ\\,dx^{1}.\n\\end{equation}\nNote that the volume-term has dropped out because the derivative of a constant is equal to zero.\n\nWe define the cell-average of a quantity, $\\bX=\\bX\\left(x^{1},t\\right)$, as:\n\\begin{equation}\n    \\ol{\\bX}\\equiv\\f{1}{\\Delta V_{j}}\\int_{I_{j}}\\bX\\,\\sqrtgm\\,dx^{1}.\n\\end{equation}\n\n\\red{NEW ASSUMPTION:} We assume that the spatial three-metric is explicitly independent of time. This allows us to pull the metric determinant out of the first integral, yielding for \\eqref{Eq:CellAverageDG}:\n\\begin{equation}\n    \\f{d\\,\\ol{\\bU}}{dt}=-\\f{1}{\\Delta V_{j}}\\left[\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{H}}-\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{L}}\\right]+\\ol{\\bQ}.\n\\end{equation}\n\n\\red{NEW ASSUMPTION:} We now specialize this to using the forward-Euler time-stepping algorithm, yielding:\n\n\\begin{equation}\n    \\ol{\\bU}^{n+1}=\\ol{\\bU}^{n}-\\f{\\Delta t^{n}_{j}}{\\Delta V_{j}}\\left[\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{H}}-\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{L}}\\right]^{n}+\\Delta t^{n}_{j}\\,\\ol{\\bQ}^{n}\n\\end{equation}\n\\blue{NOTE:} Since the spatial three-metric is explicitly independent of time, we don't need to specify the time-step at which the volume is computed (i.e. we don't have to write $\\Delta V^{n}_{j}$).\n\nNow we define a parameter $\\ve\\in\\left(0,1\\right)$ a la \\citet{ZS2011b} and re-write the above equation as:\n\\begin{align}\n    \\ol{\\bU}^{n+1}&=\\ve\\left\\{\\ol{\\bU}^{n}-\\f{\\Delta t^{n}_{j}}{\\ve\\,\\Delta V_{j}}\\left[\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{H}}-\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{L}}\\right]^{n}\\right\\}+\\left(1-\\ve\\right)\\left\\{\\ol{\\bU}^{n}+\\f{\\Delta t^{n}_{j}}{1-\\ve}\\,\\ol{\\bQ}^{n}\\right\\}\\\\\n    &=\\ve\\,\\ol{\\bH}_{1}+\\left(1-\\ve\\right)\\ol{\\bH}_{2},\n\\end{align}\nwhere\n\\begin{equation}\\label{Eq:H1}\n    \\ol{\\bH}_{1}\\equiv\\ol{\\bU}^{n}-\\f{\\Delta t^{n}_{j}}{\\ve\\,\\Delta V_{j}}\\left[\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{H}}-\\sqrtgm\\,\\hat{\\bF^{1}}\\Big|_{x^{1}_{L}}\\right]^{n},\n\\end{equation}\nand\n\\begin{equation}\n    \\ol{\\bH}_{2}\\equiv\\ol{\\bU}^{n}+\\f{\\Delta t^{n}_{j}}{1-\\ve}\\,\\ol{\\bQ}^{n}.\n\\end{equation}\n\\red{NEW ASSUMPTION:} We assume that $\\ol{\\bU}^{n}\\in\\cG$, as defined in \\citet{Mignone2005}.\n\nAssuming that $\\ol{\\bU}^{n}\\in\\cG$, we now seek to derive the conditions that guarantee $\\ol{\\bU}^{n+1}\\in\\cG$.\n\n\\subsubsection{The numerical flux term: $\\ol{\\bH}_{1}$}\n\nWe start by numerically computing the cell-average using quadrature with the Gauss-Lobatto quadrature rule. We assume that the DG approximation polynomial for the conserved variables is of order $k$, and that the order of the approximate solution is of order $k+d$, where $d$ is an integer that depends on the metric determinant. For the case of Cartesian coordinates, $d=0$ (because $\\sqrtgm\\sim x^{0}$), and for spherical-polar coordinates in spherical symmetry, $d=2$ (because $\\sqrtgm\\sim r^{2}$). Gauss-Lobatto integration will give an exact result if we choose a sufficiently high number, $M$, of quadrature points:\n\\begin{equation}\n    2\\,M-3\\geq k+d\\implies M\\geq\\f{k+d+3}{2}.\n\\end{equation}\n\n\\blue{NOTE:} We do not use this restriction in the code. We simply take $M$ equal to the number of quadrature points (which is the same as the number of interpolation points). The difference will be accounted for by the presence of the CFL number.\n\n\\blue{NOTE:} We now drop the superscript $n$ for the rest of this subsection.\n\nAssuming that we choose a sufficient number of points, we can write the cell-average as:\n\\begin{align}\n    \\ol{\\bU}=\\f{1}{\\Delta V_{j}}\\sum\\limits_{q=1}^{M}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}\\,\\Delta x_{j}&=\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}+\\f{\\Delta x_{j}}{\\Delta V_{j}}\\,w_{1}\\,\\bU_{1}\\,\\sqrtgm_{1}+\\f{\\Delta x_{j}}{\\Delta V_{j}}\\,w_{M}\\,\\bU_{M}\\,\\sqrtgm_{M}\\\\\n    &=\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}+\\f{\\Delta x_{j}}{\\Delta V_{j}}\\,w_{1}\\,\\bU^{+}_{L}\\,\\sqrtgm_{L}+\\f{\\Delta x_{j}}{\\Delta V_{j}}\\,w_{M}\\,\\bU^{-}_{H}\\,\\sqrtgm_{H},\\label{Eq:CellAverageGL}\n\\end{align}\nwhere $w_{q}$ are the Gauss-Lobatto quadrature weights and $\\bU_{q}=\\bU\\left(x_{q}\\right)$, and $\\sqrtgm_{q}=\\sqrt{\\gamma\\left(x_{q}\\right)}$. The quantity $\\bU^{+}_{L}$ refers to the vector of conserved variables evaluated at the lower interface, but on the higher side, so that it is evaluated \\textit{in} the $\\jth$ cell. Similarly for $\\bU^{-}_{H}$.\n\nOur approach is to use the end-points to balance the troublesome terms in the numerical fluxes.\n\n\\red{NEW ASSUMPTION:} We now specialize to the local Lax-Friedrichs flux:\n\\begin{align}\n    \\hat{\\bF}^{1}\\Big|_{x^{1}_{L}}&=\\hat{\\bF}^{1}\\left(\\bU^{+}_{L},\\bU^{-}_{L}\\right)=\\f{1}{2}\\left[\\bF^{1}\\left(\\bU^{+}_{L}\\right)+\\bF^{1}\\left(\\bU^{-}_{L}\\right)-\\alpha_{L}\\left(\\bU_{L}^{+}-\\bU_{L}^{-}\\right)\\right]\\\\\n    &=\\f{1}{2}\\left\\{-\\alpha_{L}\\left[\\bU^{+}_{L}-\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{+}_{L}\\right)\\right]+\\alpha_{L}\\left[\\bU^{-}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{-}_{L}\\right)\\right]\\right\\},\n\\end{align}\nand\n\\begin{align}\n    \\hat{\\bF}^{1}\\Big|_{x^{1}_{H}}&=\\hat{\\bF}^{1}\\left(\\bU^{+}_{H},\\bU^{-}_{H}\\right)=\\f{1}{2}\\left[\\bF^{1}\\left(\\bU^{+}_{H}\\right)+\\bF^{1}\\left(\\bU^{-}_{H}\\right)-\\alpha_{H}\\left(\\bU_{H}^{+}-\\bU_{H}^{-}\\right)\\right]\\\\\n    &=\\f{1}{2}\\left\\{-\\alpha_{H}\\left[\\bU^{+}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{+}_{H}\\right)\\right]+\\alpha_{H}\\left[\\bU^{-}_{H}+\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{-}_{H}\\right)\\right]\\right\\},\n\\end{align}\nwhere $\\alpha_{H}=\\text{max}\\left(\\alpha_{j},\\alpha_{j+1}\\right)$ and $\\alpha_{L}=\\text{max}\\left(\\alpha_{j-1},\\alpha_{j}\\right)$ are the largest (in magnitude) wavespeeds as given by the flux-Jacobian.\nNow we substitute these expressions along with \\eqref{Eq:CellAverageGL} into \\eqref{Eq:H1}:\n\\begin{align}\n    \\ol{\\bH}_{1}=&\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}+\\f{\\Delta x_{j}}{\\Delta V_{j}}\\,w_{1}\\,\\bU^{+}_{L}\\,\\sqrtgm_{L}+\\f{\\Delta x_{j}}{\\Delta V_{j}}\\,w_{M}\\,\\bU^{-}_{H}\\,\\sqrtgm_{H}\\\\\n    &-\\f{\\Delta t_{j}}{\\ve\\,\\Delta V_{j}}\\left[\\sqrtgm_{H}\\f{1}{2}\\left\\{-\\alpha_{H}\\left[\\bU^{+}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{+}_{H}\\right)\\right]+\\alpha_{H}\\left[\\bU^{-}_{H}+\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{-}_{H}\\right)\\right]\\right\\}\\right]\\\\\n    &+\\f{\\Delta t_{j}}{\\ve\\,\\Delta V_{j}}\\left[\\sqrtgm_{L}\\f{1}{2}\\left\\{-\\alpha_{L}\\left[\\bU^{+}_{L}-\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{+}_{L}\\right)\\right]+\\alpha_{L}\\left[\\bU^{-}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{-}_{L}\\right)\\right]\\right\\}\\right].\n\\end{align}\nNow we combine terms with common factors of the metric determinant:\n\\begin{align}\n    \\ol{\\bH}_{1}=&\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}\\\\\n    &+\\f{\\sqrtgm_{L}}{\\Delta V_{j}}\\left\\{\\Delta x_{j}\\,w_{1}\\,\\bU^{+}_{L}+\\f{\\Delta t_{j}\\,\\alpha_{L}}{2\\,\\ve}\\left(-\\left[\\bU^{+}_{L}-\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{+}_{L}\\right)\\right]+\\left[\\bU^{-}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{-}_{L}\\right)\\right]\\right)\\right\\}\\\\\n    &+\\f{\\sqrtgm_{H}}{\\Delta V_{j}}\\left\\{\\Delta x_{j}\\,w_{M}\\,\\bU^{-}_{H}-\\f{\\Delta t_{j}\\,\\alpha_{H}}{2\\,\\ve}\\left(-\\left[\\bU^{+}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{+}_{H}\\right)\\right]+\\left[\\bU^{-}_{H}+\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{-}_{H}\\right)\\right]\\right)\\right\\}.\n\\end{align}\nNext we factor out $\\Delta x_{j}$ and the quadrature weights, yielding:\n\\begin{align}\n    \\ol{\\bH}_{1}=&\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}\\\\\n    &+\\f{\\sqrtgm_{L}\\,\\Delta x_{j}\\,w_{1}}{\\Delta V_{j}}\\left\\{\\bU^{+}_{L}+\\f{\\Delta t_{j}\\,\\alpha_{L}}{2\\,\\ve\\,\\Delta x_{j}\\,w_{1}}\\left(-\\left[\\bU^{+}_{L}-\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{+}_{L}\\right)\\right]+\\left[\\bU^{-}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{-}_{L}\\right)\\right]\\right)\\right\\}\\\\\n    &+\\f{\\sqrtgm_{H}\\,\\Delta x_{j}\\,w_{M}}{\\Delta V_{j}}\\left\\{\\bU^{-}_{H}-\\f{\\Delta t_{j}\\,\\alpha_{H}}{2\\,\\ve\\,\\Delta x_{j}\\,w_{M}}\\left(-\\left[\\bU^{+}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{+}_{H}\\right)\\right]+\\left[\\bU^{-}_{H}+\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{-}_{H}\\right)\\right]\\right)\\right\\}.\n\\end{align}\nNext we re-write the $\\bU^{+}_{L}$ and $\\bU^{-}_{H}$ that appear with the flux terms:\n\\begin{align}\n    \\bU^{+}_{L}&=2\\,\\bU^{+}_{L}-\\bU^{+}_{L}\\\\\n    \\bU^{-}_{H}&=2\\,\\bU^{-}_{H}-\\bU^{-}_{H}.\n\\end{align}\nThis gives:\n\\begin{align}\n    \\ol{\\bH}_{1}=&\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}\\\\\n    &+\\f{\\sqrtgm_{L}\\,\\Delta x_{j}\\,w_{1}}{\\Delta V_{j}}\\left\\{\\bU^{+}_{L}+\\f{\\Delta t_{j}\\,\\alpha_{L}}{2\\,\\ve\\,\\Delta x_{j}\\,w_{1}}\\left(-\\left[2\\,\\bU^{+}_{L}-\\bU^{+}_{L}-\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{+}_{L}\\right)\\right]+\\left[\\bU^{-}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{-}_{L}\\right)\\right]\\right)\\right\\}\\\\\n    &+\\f{\\sqrtgm_{H}\\,\\Delta x_{j}\\,w_{M}}{\\Delta V_{j}}\\left\\{\\bU^{-}_{H}-\\f{\\Delta t_{j}\\,\\alpha_{H}}{2\\,\\ve\\,\\Delta x_{j}\\,w_{M}}\\left(-\\left[\\bU^{+}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{+}_{H}\\right)\\right]+\\left[2\\,\\bU^{-}_{H}-\\bU^{-}_{H}+\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{-}_{H}\\right)\\right]\\right)\\right\\}.\n\\end{align}\nThis allows us to write the expression with factors similar to those in \\citet{Qin2016}. We find:\n\\begin{align}\n    \\ol{\\bH}_{1}=&\\f{\\Delta x_{j}}{\\Delta V_{j}}\\sum\\limits_{q=2}^{M-1}w_{q}\\,\\bU_{q}\\,\\sqrtgm_{q}\\\\\n    &+\\f{\\sqrtgm_{L}\\,\\Delta x_{j}\\,w_{1}}{\\Delta V_{j}}\\left\\{\\bU^{+}_{L}\\left(1-\\f{\\Delta t_{j}\\,\\alpha_{L}}{\\ve\\,\\Delta x_{j}\\,w_{1}}\\right)+\\f{\\Delta t_{j}\\,\\alpha_{L}}{2\\,\\ve\\,\\Delta x_{j}\\,w_{1}}\\left(\\left[\\bU^{+}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{+}_{L}\\right)\\right]+\\left[\\bU^{-}_{L}+\\f{1}{\\alpha_{L}}\\,\\bF^{1}\\left(\\bU^{-}_{L}\\right)\\right]\\right)\\right\\}\\\\\n    &+\\f{\\sqrtgm_{H}\\,\\Delta x_{j}\\,w_{M}}{\\Delta V_{j}}\\left\\{\\bU^{-}_{H}\\left(1-\\f{\\Delta t_{j}\\,\\alpha_{H}}{\\ve\\,\\Delta x_{j}\\,w_{M}}\\right)+\\f{\\Delta t_{j}\\,\\alpha_{H}}{2\\,\\ve\\,\\Delta x_{j}\\,w_{M}}\\left(\\left[\\bU^{+}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{+}_{H}\\right)\\right]+\\left[\\bU^{-}_{H}-\\f{1}{\\alpha_{H}}\\,\\bF^{1}\\left(\\bU^{-}_{H}\\right)\\right]\\right)\\right\\}.\n\\end{align}\nAll of the terms in the square brackets are similar the the $\\bH$ quantities in \\citet{Qin2016} and therefore belong to the set of admissible states, provided that:\n\\begin{equation}\n    \\alpha_{L/H}=\\alpha^{*}\\geq\\f{\\left|v^{1}\\right|\\left(h+1-2\\,h\\,\\tau\\right)\\,W^{2}+\\sqrt{\\tau^{4}\\left(h-1\\right)^{2}+\\tau^{2}\\left(h-1\\right)\\left(h+1-2\\,h\\,\\tau\\right)}}{W^{2}\\left(h+1-2\\,h\\,\\tau\\right)+\\tau^{2}\\left(h-1\\right)},\n\\end{equation}\nwhere $h$ is the relativistic specific enthalpy and\n\\begin{equation}\n    \\tau\\equiv\\f{\\Gamma-1}{\\Gamma},\n\\end{equation}\nwhere $\\Gamma$ is the adiabatic index.\n\nWe see that the expressions in the curly brackets are convex combinations (given a restriction on $\\Delta t_{j}$), because the coefficients sum to unity. Since the quadrature weights are symmetric (so $w_{1}=w_{M}\\equiv w_{GL}$), we find that the condition for $\\ol{\\bH}_{1}\\in\\cG$ is a time-step restriction:\n\\begin{equation}\n\\Delta t_{j}<\\ve\\,\\Delta x_{j}\\,w_{GL}\\,\\text{min}\\left(\\f{1}{\\alpha_{L}},\\f{1}{\\alpha_{H}},\\f{1}{\\alpha^{*}}\\right)\n\\end{equation}\nSince we want a time-step that is constant for all elements, we choose:\n\\begin{equation}\n\\Delta t<\\ve\\,w_{GL}\\,\\text{min}_{j}\\left(\\f{\\Delta x_{j}}{\\text{max}\\left(\\alpha_{L},\\alpha_{H},\\alpha^{*}\\right)}\\right).\n\\end{equation}\n\n\\red{NEW ASSUMPTION:} In order for this to work, we also demand that all of the $\\bU_{q}$ are within physical bounds.\n\n\\blue{NOTE:} We see the effect of the high-order approximation in the presence of the quadrature end-point weight $w_{GL}$. As the order increases, $w_{GL}$ decreases, thus making a tighter restriction on the time-step.\n\n\\blue{NOTE:} It is worth noting that this result is \\textit{not} independent of the metric, because it is incorporated through the wave-speed in the numerical flux.\n", "meta": {"hexsha": "8dae75e728f342fb72c87b0ee92d6895691e9670", "size": 15078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/Euler/SamsTexFiles/Time-Step_Restriction_High-Order.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/Time-Step_Restriction_High-Order.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/Time-Step_Restriction_High-Order.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": 87.1560693642, "max_line_length": 621, "alphanum_fraction": 0.6231595702, "num_tokens": 6112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6645171399005635}}
{"text": "\\section{Riemann Surfaces; Analytic Maps}\r\n\\subsection{Covering Maps}\r\nIn previous sections, we have seen the way of realising the complex logarithm by constructing functions $f,\\pi:R\\to\\mathbb C$ satisfying the $\\exp\\circ f=\\pi$.\r\nThat is, the diagram\r\n\\[\r\n    \\begin{tikzcd}\r\n        R\\arrow{r}{f}\\arrow[swap]{dr}{\\pi}&\\mathbb C\\arrow{d}{\\exp}\\\\\r\n        &\\mathbb C_\\star\r\n    \\end{tikzcd}\r\n\\]\r\nSadly, $\\pi$ is not exactly a homeomorphism, but it is the next best thing.\r\n\\begin{definition}\r\n    Let $\\tilde{X},X$ be path-connected Hausdorff topological spaces.\r\n    A covering map $\\pi:\\tilde{X}\\to X$ is a local homeomorphism.\r\n    That is, each $\\tilde{x}\\in\\tilde{X}$ has an open neighbourhood $\\tilde{U}$ such that $\\pi|_{\\tilde{U}}$ is a homoemorphism onto its image.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A covering map $\\pi:\\tilde{X}\\to X$ is regular if for each $x\\in X$ there is an open neighbourhood $U$ of $x$ and a discrete set $\\Delta_x$ such that $\\pi^{-1}(U)\\cong U\\times\\Delta_x$ and the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi^{-1}(U)\\arrow{r}{\\cong}\\arrow[swap]{dr}{\\pi}&U\\times\\Delta_x\\arrow{d}{(u,\\delta)\\mapsto u}\\\\\r\n            &U\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{definition}\r\nIn particular, $\\pi|_{\\pi^{-1}(U)}$ must has image $U$.\r\nA useful and non-confusing way of taking $U\\times\\Delta_x$ is to think of it as a disjoint union of copies of $U$.\r\n\\begin{example}\r\n    1. The map $\\pi:R\\to\\mathbb C$ we defined when treating $\\log$ is a regular convering map as\r\n    $$\\pi^{-1}(U_{I(n)})=\\coprod_{m\\equiv n\\pmod{4}}U_{I(m)}\\cong U_{I(n)}\\times\\mathbb Z$$\r\n    2. For each open interval $I\\subset\\mathbb R$, write\r\n    $$\\tilde{V}_I=\\mathbb R+iI=\\{x+iy:x\\in\\mathbb R,y\\in I\\}$$\r\n    As long as the length of $I$ is at most $2\\pi$, the exponential function restricts to a homeomorphism $\\tilde{V}_I\\to U_I$ with the obvious inverse obtained by taking a branch of $\\log$.\r\n    So\r\n    $$\\exp^{-1}(U_{I(n)})=\\coprod_{m\\equiv n\\pmod{4}}\\tilde{V}_{I(m)}\\cong U_{I(n)}\\times\\mathbb Z$$\r\n    which means $\\exp:\\mathbb C\\to\\mathbb C_\\star$ is a covering map.\\\\\r\n    3. (non-example) Consider $\\pi:\\mathbb D\\to\\mathbb C$ which is obviously a covering map and $z\\in\\mathbb T$ with a neighbourhood $U\\ni z$, then $\\pi^{-1}(U)=U\\cap\\mathbb D$.\r\n    But then the image of $\\pi|_{U\\cap\\mathbb D}$ is never $U$, so $\\pi$ is not regular.\\\\\r\n    4. The map $\\pi:R_k\\to\\mathbb C_\\star$ we constructed for $\\sqrt[k]{\\cdot}$ is also regular.\r\n\\end{example}", "meta": {"hexsha": "71536fe398e4216dda61568dfd3f06b0d56984f5", "size": 2502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/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": "3/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": "3/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": 61.0243902439, "max_line_length": 205, "alphanum_fraction": 0.6430855316, "num_tokens": 873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.6645062636237594}}
{"text": "\\documentclass{notes}\n\n  \\title{Hash functions}\n  \\author{ian.mcloughlin@gmit.ie}\n  \\date{\\today}\n\n\\begin{document}\n\n  \\section*{Hash function}\n  \\[h:\\{0,1\\}^* \\rightarrow \\{0,1\\}^n \\qquad n \\in \\mathbb{N}_0 \\] \\\\\n  \\textit{Compression:} arbitrary length to fixed length. \\\\[2mm]\n  \\textit{Ease of computation:} we know an efficient algorithm to perform \\(h\\).\n \n\n  \\section*{Collision}\n  \\[h(x_1) = h(x_2) \\]\n\n  \\section*{Preimage resistance}\n  Given \\(y\\) it's infeasible to find any \\(x\\) such that \\(h(x) = y\\).\n\n  \\section*{Second preimage resistance}\n  Given \\(x_1\\) it's infeasible to find another \\(x_2\\) such that \\(h(x_1) = h(x_2)\\).\n\n  \\section*{Collision resistance}\n  Infeasible to find \\(x_1\\) and \\(x_2\\) such that \\( x_1 \\neq x_2 \\) and \\(h(x_1) = h(x_2)\\).\n\n  \\section*{One-way}\n  Efficient algorithm to calculate \\(f(x) = y\\), no efficient algorithm to calculate \\(f^{-1}(y) = x\\).\n  No one has proved one-way functions really exist.\n  \n  \n  Not to be confused with not being one-to-one:\n\n  \\[\\mathtt{rshift}(0011) = \\mathtt{rshift}(0010) = 0001 \\]\n\n  Given \\(y\\), easy to find \\(x\\) such that \\(\\mathtt{rshift}(x) = y\\).\n\n  \\section*{SHA256}\n  \\[f: \\{0,1\\}^{256} \\times \\{0,1\\}^{512} \\rightarrow \\{0,1\\}^{256}\\]\n\n  \\section*{Padding}\n  \\[\\mathtt{pad}(m) = M\\]\n  \\begin{itemize}\n    \\item Append a 1 bit.\n    \\item Append 0 bits such that \\(|M| \\equiv_{512} 448\\).\n    \\item Append \\(|M|\\), least significant bit on right.\n  \\end{itemize}\n\n  Note padding with zeros or not padding would give easy collisions.\n\n  \\section*{Merkle-Damgrad}\n\n  \\begin{adjustbox}{max width={\\textwidth},center}\n    \\begin{tikzpicture}[node distance=2cm]\n      \\node (h_x) at (0,0) {};\n      \\node (h_y) at (5.5,0) {};\n      \\begin{scope}[every node/.style={draw}]\n        \\node (h_0) at (1,0) {\\(f\\)};\n        \\node (h_1) at (2,0) {\\(f\\)};\n        \\node (h_2) at (3,0) {\\(f\\)};\n        \\node (h_n) at (4.5,0) {\\(f\\)};\n      \\end{scope}\n      \\begin{scope}[every node/.style={draw}]\n        \\node (m_1) at (1,1.3) {\\(M_1\\)};\n        \\node (m_2) at (2,1.3) {\\(M_2\\)};\n        \\node (m_3) at (3,1.3) {\\(M_3\\)};\n        \\node (m_n) at (4.5,1.3) {\\(M_n\\)};\n\t\t\t\\end{scope}\n\t\t\t\\begin{scope}[every edge/.style={draw=black,->}]\n        \\path (h_x) edge node[below] {\\(H_0\\)} (h_0);\n        \\path (h_0) edge node[below] {\\(H_1\\)} (h_1);\n        \\path (h_1) edge node[below] {\\(H_2\\)} (h_2);\n        \\path (h_n) edge node[below] {\\(H_n\\)} (h_y);\n\n        \\path (m_1) edge node[below] {} (h_0);\n        \\path (m_2) edge node[below] {} (h_1);\n        \\path (m_3) edge node[below] {} (h_2);\n        \\path (m_n) edge node[below] {} (h_n);\n      \\end{scope}\n      \\begin{scope}[every edge/.style={draw=black,thick,->,dashed}]\n\t\t\t\t\\path (h_2) edge node[below] {} (h_n);\n\t\t\t\\end{scope}\n    \\end{tikzpicture}\n  \\end{adjustbox}\n\n  %\\bibliography{bibliography}\n\\end{document}\n", "meta": {"hexsha": "cc3448de5d4038c344231cde33e4e0564ef917dd", "size": 2852, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hash-functions.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": "hash-functions.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": "hash-functions.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": 32.4090909091, "max_line_length": 103, "alphanum_fraction": 0.5694249649, "num_tokens": 1098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.6645062561172728}}
{"text": "\\section{Solutions of TISE in One Dimension}\r\nIn one dimension, TISE restricts to\r\n$$-\\frac{\\hbar^2}{2m}X^{\\prime\\prime}+UX=EX$$\r\nwhere $E\\in\\mathbb R$.\r\n\\subsection{Infinte Potential Well}\r\nConsider the potential\r\n\\footnote{Unorthodox, I know. I have stopped caring.}\r\n$$U(x)=\\begin{cases}\r\n    0\\text{, if $|x|\\le a$}\\\\\r\n    \\infty\\text{, if $|x|>a$}\r\n\\end{cases}$$\r\nFor $|x|>a$ we take the solution $X(x)=0$.\r\nAnd we also want $X(\\pm a)=0$ as we want $X$ to be continuous.\r\nFor $|x|\\le a$, we are then aiming at the boundary value problem\r\n$$-\\frac{\\hbar^2}{2m}X^{\\prime\\prime}=EX\\iff X^{\\prime\\prime}+K^2X=0,K^2=\\frac{2mE}{\\hbar^2}\\ge 0$$\r\nsubject to $X(\\pm a)=0$.\r\nThis is known to have the general solution $X(x)=A\\sin(Kx)+B\\cos(Kx)$ for constants $A,B$.\r\nThe boundary conditions then require either $A=0$ and $K=n\\pi/2a$ for $n=1,3,5,\\ldots$ or $B=0$ and $K=n\\pi/2a$ with $n=2,4,6,\\ldots$.\r\nSo the allowed values of the energy would be\r\n$$E_n=\\frac{\\hbar^2\\pi^2}{8ma^2}n^2,n=1,2,3,\\ldots$$\r\nThe lowest positive energy (aka ground state energy) is then $E_1=\\hbar^2\\pi^2/(8ma^2)$.\r\nThe solutions are\r\n$$X_n(x)=\\frac{1}{\\sqrt{a}}\\begin{cases}\r\n    \\cos(n\\pi x/(2a))\\text{, for $n=1,3,5,\\ldots$}\\\\\r\n    \\sin(n\\pi x/(2a))\\text{, for $n=2,4,6,\\ldots$}\r\n\\end{cases}$$\r\nwhere the factor is obtained from the assumption that $X_n$ is normalised.\r\nI am too lazy to plot the functions, but whoever read this are encouraged to plot a few of these states.\r\nWithout plotting, however, one can immediately realise that when $n$ is large, $X$ tends to fluctuate a lot.\r\nThe solution also allows us to draw the analogy between these solutions and standing waves with two endpoints fixed at $\\pm a$.\r\nAlso, $X_n(-x)=(-1)^{n+1}X_n(x)$, so $X_n$ is either even or odd.\r\nThis is actually a general feature of the eigenfunctions of the Hamiltonian $\\hat{H}$.\r\n\\begin{proposition}\r\n    If $U$ is even and the energy spectrum is non-degenerate (i.e. we require $E_1<E_2<\\cdots$), then each eigenfunction is either even or odd.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $U$ is even then TISE is reflection invariant, so $x\\mapsto X(-x)$ is also a solution.\r\n    But it also has energy $E$, so $X(-x)=AX(x)$ where $A$ is a constant.\r\n    But then $X(x)=X(-(-x))=AX(-x)=A^2X(x)$, so $A=\\pm 1$ as $X$ is not identically zero.\r\n\\end{proof}\r\n\\subsection{Finite Potential Well}\r\nWe consider the potential of the form\r\n$$U(x)=\\begin{cases}\r\n    0\\text{, if $|x|\\le a$}\\\\\r\n    U_0\\text{, if $|x|>a$}\r\n\\end{cases}$$\r\nwhere $U_0>0$.\r\nWe only consider the case $E<U_0$.\r\nThe other case will be dealt with later.\r\nAlso we only look for even $X$.\r\nWe define the nonnegative real quantities\r\n$$K=\\sqrt{\\frac{2mE}{\\hbar^2}},\\kappa=\\sqrt{\\frac{2m(U_0-E)}{\\hbar^2}}$$\r\nFor $|x|\\le a$, we obtain the general solution $X(x)=A\\sin(Kx)+B\\cos(Kx)$ for $A,B$ constants.\r\nWe are looking for even states only, so we might as well write $X(x)=A\\cos(Kx)$.\r\nFor $|x|>a$, we have $X^{\\prime\\prime}-\\kappa^2X=0$ which has solution $X=Ce^{\\kappa x}+De^{-\\kappa x}$ for some constants $C,D$.\r\nBut the normalisation condition then tells us $C=0$ for $x>a$ and $D=0$ for $x<-a$.\r\nHence\r\n$$X(x)=\\begin{cases}\r\n    Ce^{\\kappa x}\\text{, for $x<-a$}\\\\\r\n    A\\cos(Kx)\\text{, for $|x|\\le a$}\\\\\r\n    De^{-\\kappa x}\\text{, for $x>a$}\r\n\\end{cases}$$\r\nThe continuity of $X$ and $X^\\prime$ that we assumed then yield $K\\tan(Ka)=\\kappa$.\r\nBut the definition of $K$ and $\\kappa$ yields $K\\tan(Ka)=\\kappa$.\r\nWe also know that $K^2+\\kappa^2=2mU_0/\\hbar^2$.\r\nDefine $\\xi=Ka$ and $\\eta=\\kappa a$, then the two equations become\r\n$$\\begin{cases}\r\n    \\xi\\tan\\xi=\\eta\\\\\r\n    \\eta^2+\\eta^2=r_0^2\r\n\\end{cases}$$\r\nwhere $r_0^2=2a^2mU_0/\\hbar^2$.\r\nBy a plot, we know that there are only finitely many solutions $\\{\\xi_1,\\ldots,\\xi_p\\}$ of $\\xi$ with $(n-1)\\pi\\le\\xi_n\\le(n-1/2)\\pi$ and the allowed energy are of the form\r\n$$E_n=\\frac{\\hbar^2}{2ma^2}\\xi_n^2,n=1,\\ldots,r$$\r\nAs $U_0\\to\\infty$, we can get $r_0\\to\\infty$, so $p\\to\\infty$.\r\nAnd the allowed energy would be\r\n$$E_n=\\frac{\\hbar^2}{2ma^2}\\xi_n^2=\\frac{\\hbar^2(2n-1)^2}{2ma^2}\\pi^2$$\r\nwhich is consistent with our result on infinite well.\r\nOf course we can determine all the eigenfunctions as we have enough number of conditions on the breaking points and the normalisation condition.\r\nOne can also show by some calculation that the eigenfunctions also go to the eigenfunctions of the infinite well solution as $U_0\\to\\infty$.\r\n\\subsection{Free Particle}\r\nIf we require that\r\n$$\\int_{-\\infty}^\\infty |X(x)|^2\\,\\mathrm dx=N\\in\\mathbb R_+$$\r\nthen necessarily\r\n$$\\lim_{R\\to\\infty}\\int_{|x|>R}|X(x)|^2\\,\\mathrm dx=0$$\r\nReturning to our TISE $X^{\\prime\\prime}+K^2X(x)=0$ where $K=\\sqrt{2mE/\\hbar^2}$ which has solutions in the form $X_K(x)=Ae^{iKx}$.\r\nThis is obviously a continuous spectrum of solutions (corresponding to different values of $E$).\r\nThey gives the solutions $\\psi_K(x,t)=X_k(x)e^{-i\\hbar K^2t/(2m)}$.\r\nBut they are not in general normalisable!\r\nIndeed,\r\n$$\\int_{\\mathbb R}|\\psi_K(x,t)|^2\\,\\mathrm dx=\\int_{\\mathbb R}|X_K(x,t)|^2\\,\\mathrm dx=|A|^2\\int_{\\mathbb R}\\mathrm dx=\\infty$$\r\nunless $A=0$.\r\nThe workaround is to consider the integral superposition\r\n$$\\psi(x,t)=\\int_{\\mathbb R}A(K)\\psi_K(x,t)\\,\\mathrm dK=\\int_{\\mathbb R}A(K)e^{iKx}e^{-i\\hbar K^2t/(2m)}\\,\\mathrm dK$$\r\nand choose $A$ that decreases fast enough as $K\\to\\infty$ so that $\\psi$ is well-defined and normalisable.\r\nA typical choice is the Gaussian wavepackage\r\n$$A(K)=\\exp\\left( -\\frac{\\sigma}{2}(K-K_0)^2 \\right)$$\r\nwhere $\\sigma>0$.\r\nSo using this we can write\r\n$$\\psi(x,t)=\\int_{\\mathbb R}\\exp F(K)\\,\\mathrm dK$$\r\nwhere\r\n\\begin{align*}\r\n    F(K)&=-\\frac{\\sigma}{2}(K-K_0)^2+i\\left(Kx-\\frac{\\hbar K^2}{2m}t\\right)\\\\\r\n    &=-\\frac{1}{2}\\left( \\sigma+\\frac{i\\hbar t}{m} \\right)K^2+(K_0\\sigma+ix)K-\\frac{\\sigma}{2}K_0^2\\\\\r\n    &=-\\frac{\\alpha}{2}\\left( K-\\frac{\\beta}{\\alpha} \\right)^2+\\frac{\\beta^2}{2\\alpha}+\\delta,\\alpha=\\sigma+\\frac{i\\hbar t}{m},\\beta=K_0\\sigma+ix,\\delta=-\\frac{\\sigma}{2}K_0^2\r\n\\end{align*}\r\nTherefore,\r\n\\begin{align*}\r\n    \\psi(x,t)(x,t)&=\\exp\\left( \\frac{\\beta^2}{2\\alpha}+\\delta \\right)\\int_{-\\infty}^\\infty\\exp\\left( -\\frac{\\alpha}{2}\\left( K-\\frac{\\beta}{\\alpha} \\right)^2 \\right)\\,\\mathrm dK\\\\\r\n    &=\\exp\\left( \\frac{\\beta^2}{2\\alpha}+\\delta \\right)\\int_{-\\infty-i\\nu}^{\\infty-i\\nu}\\exp\\left( -\\frac{\\alpha}{2}\\tilde{K}^2 \\right)\\,\\mathrm d\\tilde{K},\\tilde{K}=K-\\frac{\\beta}{\\alpha},\\nu=\\operatorname{Im}\\frac{\\beta}{\\alpha}\\\\\r\n    &=\\sqrt{\\frac{2\\pi}{\\alpha}}\\exp\\left( \\frac{\\beta^2}{2\\alpha}+\\delta \\right)\r\n\\end{align*}\r\nI know the last step is staggering.\r\nIt's ok, you are stong enough to handle these traumas in your life.\r\nAnyways, putting everything back gives\r\n$$\\psi(x,t)=\\sqrt{\\frac{2\\pi}{\\alpha}}\\exp\\left( -\\frac{\\sigma(x-\\hbar K_0t/m)^2}{2(\\sigma^2+\\hbar^2t^2/m^2)} \\right)$$\r\nAnd (with the help of God) we can obtain the probability density\r\n$$\\rho(x,t)=\\frac{C}{\\sqrt{\\sigma^2+\\hbar^2t^2/m^2}}\\exp\\left( -\\frac{\\sigma(x-\\hbar K_0t/m)^2}{\\sigma^2+\\hbar^2t^2/m^2} \\right)$$\r\nwhere $C$ is a normalisation constant, which can be determined by more calculation:\r\n$$\\int_{-\\infty}^\\infty\\rho(x,t)\\,\\mathrm dx=1\\implies C=\\sqrt{\\frac{\\sigma}{\\pi}}$$\r\nNow, by a little calculation we obtain the mean $\\langle x\\rangle=\\hbar K_0t/m$.\r\nWe write $v=\\hbar K_0/m$ as an analogy of velocity.\r\nThe standard deviation is\r\n$$\\Delta x=\\sqrt{\\langle x^2\\rangle-\\langle x\\rangle^2}=\\sqrt{\\frac{1}{2}\\left( \\sigma+\\frac{\\hbar^2t^2}{m^2\\sigma} \\right)}$$\r\nwhich increases as $t\\to\\infty$, therefore the distribution is more spreaded out as $t\\to\\infty$.\\\\\r\nBack to $\\psi_K(x,t)=Ae^{iKx}e^{-i\\hbar K^2t/(2m)}$, which as one can verify has standard deviation $\\Delta x=\\infty$ on position and $\\Delta p=0$ on momentum since the momentum is just $p=\\hbar K$.\r\nThese whole $\\Delta x,\\Delta p$ business will be dealt with later when we get to Heisenberg's Uncertainty Principle.\r\nIn fact, it is possible to show that the Gaussian wavepackage minimises uncertainty.\r\nNow $\\rho_K(x,t)=|A(K)|^2$ is then interpreted as the constant average density of a particle.\r\nThe probability current is\r\n$$J_K(x,t)=-\\frac{i\\hbar}{2m}\\left( \\psi_K^*\\frac{\\partial\\psi_K}{\\partial x}-\\psi_K\\frac{\\partial\\psi_K^*}{\\partial x} \\right)=|A|^2\\frac{\\hbar K}{m}=|A|^2\\frac{p}{m}$$\r\nThis is basically the product of the average density and velocity, which can be interpreted as the average flux of particles.\r\nIn some way, we are interpreting the state as a beam of particles where $A$ relates to the beam density.\r\n\\subsection{Scattering States}\r\nConsider $U_0>0$ and\r\n$$U(x)=\\begin{cases}\r\n    U_0\\text{, for $x\\in (0,a)$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nDefine\r\n$$R=\\lim_{t\\to\\infty}\\int_{-\\infty}^0|\\psi(x,t)|^2\\,\\mathrm dx,T=\\lim_{t\\to\\infty}\\int_0^\\infty|\\psi(x,t)^2|\\,\\mathrm dx$$\r\nIf we interpret the system as a wave moving towards $x=0$ being scattered (partially reflected and partially transmitted), then $R$ can be seens as the reflection probability and $T$ the transmission probability.\r\nIf $\\psi$ is normalised, then we have $R+T=1$.\r\nTake the solutions $\\psi_K(x,t)=X_K(x)e^{-i\\hbar K^2t/(2m)}$ where $X_K(x)=Ae^{iKx}$.\r\n\\subsubsection{Scattering off a Potential Step}\r\nTake $a\\to\\infty$ gives the potential\r\n$$U(x)=\\begin{cases}\r\n    0\\text{, for $x\\le 0$}\\\\\r\n    U_0\\text{, for $x>0$}\r\n\\end{cases}$$\r\nRestate the TISE\r\n$$-\\frac{\\hbar^2}{2m}X^{\\prime\\prime}+UX=EX$$\r\nFirst, we consider the case $E>U_0$.\r\nFor $x\\le 0$, if we throw in $K=\\sqrt{2mE/\\hbar^2}$ the system gives\r\n$$X_K(x)=X_K^{(+)}(x)+X_K^{(-)}(x),X_K^{(+)}(x)=Ae^{iKx},X_K^{(-)}(x)=Be^{-iKx}$$\r\nwhere $A,B$ are constants.\r\nThen we interpret $X_K^{(+)}$ as the beam of incident particles from $x=-\\infty$ with $p=\\hbar K$ and probability current $J_K^{(+)}=|A|^2\\hbar K/m$.\r\nThe $X_K^{(-)}$ is correspondingly interpreted as the beam of reflected particles going towards $x=-\\infty$ with $p=-\\hbar k$ and $J_K^{(-)}=-|B|^2\\hbar K/m$.\r\nNow for $x>0$ we have $X^{\\prime\\prime}+\\tilde{K}^2X=0$ where $\\tilde{K}=\\sqrt{2m(E-U_0)/\\hbar^2}$ which is well-defined as we assumed $U_0<E$.\r\nThis yield the solutions\r\n$$X_{\\tilde{K}}=X_{\\tilde{K}}^{(+)}+X_{\\tilde{K}}^{(+)},X_{\\tilde{K}}^{(+)}(x)=Ce^{i\\tilde{K}x},X_{\\tilde{K}}^{(-)}(x)=De^{-i\\tilde{K}x}$$\r\nAgain $X_{\\tilde{K}}^{(+)}$ is the beam of transmitted particles moving towards $x=+\\infty$ with $p=\\hbar\\tilde{K}$ and $X_{\\tilde{K}}^{(-)}$ is the beam if incident particles from $x=+\\infty$ with $p=-\\hbar \\tilde{K}$.\r\nWe only want to consider the scattering problem, so we can set $D=0$.\r\nContinuity of $X$ at $x=0$ gives $A+B=C$ and continuity of $X^\\prime$ at $x=0$ gives $iKA-iKB=i\\tilde{K}C$, therefore\r\n$$B=\\frac{K-\\tilde{K}}{K+\\tilde{K}}A,C=\\frac{2K}{K+\\tilde{K}}A$$\r\nSo the incident, reflective and transmitted probability current are\r\n$$J_{\\rm inc}=\\frac{\\hbar K}{m}|A|^2,J_{\\rm ref}=\\frac{\\hbar K}{m}\\left( \\frac{K-\\tilde{K}}{K+\\tilde{K}} \\right)^2|A|^2,J_{\\rm tr}=\\frac{\\hbar \\tilde{K}}{m}\\frac{4K^2}{(K+\\tilde{K})^2}|A|^2$$\r\nHence\r\n$$R=\\frac{J_{\\rm ref}}{J_{\\rm inc}}=\\left( \\frac{K-\\tilde{K}}{K+\\tilde{K}} \\right)^2,T=\\frac{J_{\\rm tr}}{J_{\\rm inc}}=\\frac{4K\\tilde{K}}{(K+\\tilde{K})^2}$$\r\nEasy to verify that $R+T=1$ and when $E\\to \\infty$ we have $K-\\tilde{K}\\to 0$ which implies $R\\to 0,T\\to 1$, which corresponds to the classical case.\\\\\r\nFor the case $E<U_0$, the equations become\r\n$$\\begin{cases}\r\n    X^{\\prime\\prime}+K^2X=0\\implies X=Ae^{iKx}+Be^{-iKx}\\text{, for $x\\le 0$}\\\\\r\n    X^{\\prime\\prime}-\\kappa^2X=0\\implies X=Ge^{\\kappa x}+Fe^{-\\kappa x}\\text{, for $x>0$}\r\n\\end{cases}$$\r\nwhere as you expect,\r\n$$K=\\sqrt{\\frac{2mE}{\\hbar^2}},\\kappa=\\sqrt{\\frac{2m(U_0-E)}{\\hbar^2}}$$\r\nWe have $G=0$ because we expect the wavefunction to not blow up at $+\\infty$.\r\nHence\r\n$$X(x)=\\begin{cases}\r\n    Ae^{iKx}+B^{-iKx}\\text{, for $x\\le 0$}\\\\\r\n    Fe^{-\\kappa x}\\text{, for $x>0$}\r\n\\end{cases}$$\r\nThen the assumed continuity of $X,X^\\prime$ at $0$ gives\r\n$$B=\\frac{iK+\\kappa}{iK-\\kappa}A,F=\\frac{2iK}{iK-\\kappa}A$$\r\nSo\r\n$$j_{\\rm tr}(x)=0,j_{\\rm inc}=\\frac{\\hbar K}{m}|A|^2,j_{\\rm ref}=\\frac{\\hbar K}{m}|B|^2=\\frac{\\hbar K}{m}|A|^2$$\r\nHence $R=1$ and $T=0$ just as we expect it.\r\n\\subsubsection{Scattering off a Potential Barrier}\r\nConsider $a\\in (0,\\infty)$, so\r\n$$U(x)=\\begin{cases}\r\n    U_0\\text{, for $x\\in (0,a)$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nWe deal with the $E\\le U_0$ case first.\r\nWe define\r\n$$K=\\sqrt{\\frac{2mE}{\\hbar^2}},\\bar{K}=\\sqrt{\\frac{2m(U_0-E)}{\\hbar^2}}$$\r\nTherefore\r\n$$\\begin{cases}\r\n    X^{\\prime\\prime}(x)-\\bar{K}^2X(x)=0\\text{, for $x\\in (0,a)$}\\\\\r\n    X^{\\prime\\prime}(x)+K^2X(x)=0\\text{, otherwise}\r\n\\end{cases}$$\r\nwhich gives the general (normalised) solution\r\n$$X(x)=\\begin{cases}\r\n    e^{iKx}+Ae^{-iKx}\\text{, for $x\\le 0$}\\\\\r\n    Be^{-\\bar{K}x}+Ce^{\\bar{K}x}\\text{, for $x\\in (0,a)$}\\\\\r\n    De^{iKx}+Fe^{-iKx}\\text{, for $x\\ge a$}\r\n\\end{cases}$$\r\nWe can set $F=0$ since we only consider the case where the incident beam is from $x=-\\infty$.\r\nBy continuity of $X,X^\\prime$ again we get\r\n$$D=\\frac{-4i\\bar{K}K}{(\\bar{K}-iK)^2e^{(\\bar{K}+iK)a}-(\\bar{K}+iK)^2e^{-(\\bar{K}-iK)a}}$$\r\nIn classical dynamics, the particle can never pass the barrier.\r\nBut our result just shows that this is not in general the case, since\r\n$$T=\\frac{j_{\\rm tr}}{j_{\\rm inc}}=\\frac{\\hbar K|D|^2/m}{\\hbar K/m}=|D|^2=\\frac{4K^2\\bar{K}^2}{(K^2+\\bar{K}^2)^2\\sinh^2(\\bar{K}a)+4K^2\\bar{K}^2}\\neq 0$$\r\nIn particular, for $\\bar{K}a>>1$, either $a>>1$ or $U_0>>E$ and\r\n$$T\\sim\\frac{16K^2\\bar{K}^2}{(K^2+\\bar{K}^2)^2}e^{-2\\bar{K}a}$$\r\nSo if the barrier is very wide or very tall, $T$ goes exponentially to $0$.\r\nWhen $E<U_0$ but a beam of particles is transmitted, this phenomenon is called quantum tunneling.\r\n\\subsubsection{Physical Examples of Quantum Tunneling}\r\n\\begin{example}[Cold Emission]\r\n    When light irradiates a metal surface, electrons are emitted when $\\hbar\\omega>W$ where $\\omega$ is the angular frequency of photons and $W$ is a constant (called the work function) associated with the metal.\r\n    An electron would be facing some sort of triangular barrier.\r\n    In addition to the potential step at $x=a$ because of the work function $W$, suppose $\\xi$ is the external electric field, then the resulting potential induced by the Lorentz force is $V_{\\rm Lorentz}(x)=-e\\xi(x-a)$.\r\n    Their superposition would be a triangular barrier with cliff at $x=a$.\r\n    So even for an electron with energy less than $W$, it can go to the part of the potential where it is low enough via quantum tunneling and excite from there.\r\n    This is knowns as cold emission in photoelectric effect.\r\n\\end{example}\r\n\\begin{example}[Radioactive Decay]\r\n    Consider the decay $\\text{N}_{Z}^A\\to \\text{M}_{Z-2}^{A-4}+\\text{He}_2^4$.\r\n    For the $\\alpha$ particle $\\text{He}_2^4$, we want to know the potential field it is in.\r\n    Indeed, if we let $r$ to be the distant between this $\\alpha$ particle and the center of the nucleus, then $U(r)$ will begin negative near $0$ because of the attractive nuclear force and eventually go up positive again after $r$ gets large enough since the repulsive Coulumb force comes in play.\r\n    Eventually, it goes down (but keep positive) and tends to $0$ as $r\\to\\infty$.\r\n    This is known as the Gamow model.\r\n    The curve certainly looks like a potential barrier.\r\n    If we let $T$ be the transmission coefficient, then the half-life of this decay is actually proportional to $T^{-1}$.\r\n\\end{example}\r\n\\subsection{The Harmonic Oscillator}\r\nThe potential of the harmonic oscillator can be written as $U(x)=Kx^2/2=m\\omega^2x^2/2$ where $K>0, \\omega=\\sqrt{k/m}>0$.\r\nIn classical mechanics, Newton's Second Law gives the equation $\\ddot{x}=-\\omega^2x$ which has solutions $x=A\\sin(\\omega t)+B\\cos(\\omega t)$ where $A,B$ are constants.\r\nSo the particle oscillates about $x=0$ with period $2\\pi/\\omega$.\\\\\r\nIn quantum mechanics, this gives the TISE\r\n$$-\\frac{\\hbar^2}{2m}\\frac{\\mathrm d^2X}{\\mathrm dx^2}+\\frac{1}{2}m\\omega^2x^2X(x)=EX(x)$$\r\nwhere we expect to find a discrete set of normalisable eigenfunctions by looking at the shape of the potential.\r\nAs seen earlier, we can guarantee to find eigenfunctions that are either even or odd.\r\nWrite $\\xi^2=m\\omega x^2/\\hbar$ and $\\mathcal E=2E/(\\hbar\\omega)$, then this change of variables yield\r\n$$-\\frac{\\mathrm d^2X}{\\mathrm d\\xi^2}+\\xi^2X(\\xi)=\\mathcal EX(\\xi)$$\r\nFor $\\mathcal E=1$ it reduces to $-X^{\\prime\\prime}(\\xi)+\\xi^2X=X$.\r\nEducated guess reveals that $X_0=A\\exp(-\\xi^2/2)$ is a family of solutions which is normalisable when $A\\neq 0$.\r\nThis gives one pair of eigenvalue $E_0=\\hbar\\omega/2$ and eigenfunction $X_0(x)=A\\exp(-m\\omega x^2/(2\\hbar))$ for $A\\neq 0$.\\\\\r\nFor the general case, set $X(\\xi)=f(\\xi)\\exp(-\\xi^2/2)$, which transforms the equation into\r\n$$-\\frac{\\mathrm d^2f}{\\mathrm d\\xi^2}+2\\xi\\frac{\\mathrm df}{\\mathrm d\\xi}+(1-\\mathcal E)f=0$$\r\nNow we are desperate, so the obvious thing to do is to plug in the power series solution $f(\\xi)=\\sum_na_n\\xi^n$ which gives\r\n$$0=\\sum_{n=0}^\\infty [(n+1)(n+2)a_{n+2}-2na_n+(\\mathcal E-1)a_n]\\xi^n$$\r\nwhich gives the recurrence\r\n$$a_{n+2}=\\frac{2n-\\mathcal E+1}{(n+1)(n+2)}a_n$$\r\nThe recurrence steps by $2$, so it has even or odd solutions.\r\nHere we need to prove an important claim\r\n\\begin{claim}\r\n    Suppose the series does not terminate then $X(\\xi)=f(\\xi)\\exp(-\\xi^2/2)$ is not normalisable.\r\n\\end{claim}\r\n\\begin{proof}\r\n    $a_{n+2}/a_n\\sim 2/n$ as $n\\to\\infty$, which means that $f(\\xi)\\sim\\exp(\\xi^2)$, hence $X$ is not normalisable.\r\n\\end{proof}\r\nTherefore, for a normalisable solution to exist, $\\mathcal E$ must be an odd positive integer, so we get the eigenvalues and eigenfunctions\r\n$$E_N=\\left( N+\\frac{1}{2} \\right)\\hbar\\omega,X_N(x)=f_N\\left( \\sqrt{\\frac{m\\omega}{\\hbar}} \\right)\\exp\\left( -\\frac{m\\omega x^2}{2\\hbar} \\right)$$\r\nwhere $f_N$ are the respective polynomials that yield from the series solution as the choice of $\\mathcal E$ makes it terminate.\r\nThese are called Hermite polynomials which, as one can verify, satisfies $f_N(-\\xi)=(-1)^Nf_N(\\xi)$ and\r\n$$f_N(\\xi)=(-1)^n\\exp(\\xi^2)\\frac{\\mathrm d^n}{\\mathrm d\\xi^n}\\exp(-\\xi^2)$$\r\nWe've got nothing better to do so why not calculate some of them.\r\n\\begin{center}\r\n    \\begin{tabular}{c|c|c|c}\r\n        $N$&$f_N(\\xi)$&$E_N$&$X_N(\\xi)$\\\\ \\hline\r\n        $0$&$1$&$\\hbar\\omega/2$&$\\exp(-\\xi^2/2)$\\\\\r\n        $1$&$\\xi$&$3\\hbar\\omega/2$&$\\xi\\exp(-\\xi^2/2)$\\\\\r\n        $2$&$1-2\\xi^2$&$5\\hbar\\omega/2$&$(1-2\\xi^2)\\exp(-\\xi^2/2)$\\\\\r\n        $3$&$\\xi-2\\xi^3/3$&$7\\hbar\\omega/2$&$(\\xi-2\\xi^3/3)\\exp(-\\xi^2/2)$\r\n    \\end{tabular}\r\n\\end{center}", "meta": {"hexsha": "b92923e79c51fb7e597366ede85937a72f78233a", "size": 18474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/tise1.tex", "max_stars_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_stars_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/tise1.tex", "max_issues_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_issues_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/tise1.tex", "max_forks_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_forks_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.6931407942, "max_line_length": 300, "alphanum_fraction": 0.6550828191, "num_tokens": 6928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6645062561172728}}
{"text": "\\chapter{Coding of integers}\n\nCoding of integers is important prerequisite to data compression. Some of these codes are unable to directly encode $0$ and none of these codes are able to directly encode negative numbers. Generally, these codes can be classified as uniquely decodable and non-uniquely decodable.\n\n\\section{Unary codes}\nEncoding\\sidenote{$\\alpha$-code is uniquely decodable (prefix) code with variable length. It does not have the ability to encode value $0$ or negative numbers directly, usually shift of values is introduced to handle such cases, for example encoding $x+1$ or $x+k, k\\geq1$.}:\n\n\\subsection{$\\alpha$-code}\n$$\\alpha(x)=0^{x-1}1$$\n\\subsection{$\\alpha'$-code}\nThis variant has $0$ and $1$ swapped.\\sidenote{This variant of $\\alpha$-code is primarily used in Golomb Codes.}\n$$\\alpha'(x)=1^{x-1}0$$\n\\section{Binary codes}\nEncoding\\sidenote{$\\beta$-codes are non-uniquely decodable codes with variable length. Fixed length binary codes are also widely used, they are uniquely decodable, but alsways encode to the same number of bits and they have a maximum value. $\\beta'$-code has leading $1$ removed.}:\n\\subsection{$\\beta$-code}\n$$\\beta(0)=0$$\n$$\\beta(1)=1$$\n$$\\beta(2i+j)=\\beta(i)\\beta(j)$$\n\\subsection{$\\beta'$-code}\n$$\\beta'(x) = \\beta(x)-10^{|\\beta(x)|-1}$$\n\n\\section{Ternary codes}\nThese codes introduce a special symbol $\\#$ for marking end of each keyword. \\sidenote{$\\tau$-codes are uniquely decodable (prefix) codes with variable length.}\n\n\\noindent\nEncoding:\n\n\\subsection{$\\tau$-code}\n$$\\tau(x) = \\beta(x)\\#$$\n\\subsection{$\\tau'$-code}\n$$\\tau'(x) = \\beta'(x)\\#$$\n\n\\section{Elias codes}\nEncoding\\sidenote{$\\gamma$-codes are uniquely decodable codes with variable length. Uniquely decodable $\\alpha$-code is combined with non-uniquely decodable $\\beta$-code. The difference between $\\gamma'$-code and $\\gamma$-code is that $\\gamma$-code is interleaved. $\\delta$-code is similar to $\\gamma'$-code, but $\\alpha$-code is replaced with $\\gamma$-code.}:\n\n\\subsection{$\\gamma'$-code}\n$$\\gamma'(x)=\\alpha(|\\beta(x)|)\\beta'(x)$$\n\n\\subsection{$\\gamma$-code}\n$$y=\\alpha(|\\beta(x)|), z=\\beta'(x)$$\n$$\\gamma(x)=y_1,z_1,y_2,z_2,\\ldots,z_{|\\beta(x)|-1},y_{|\\beta(x)|}$$\n\n\\subsection{$\\delta$-code}\n$$\\gamma(x)=\\gamma(|\\beta(x)|)\\beta'(x)$$\n\n\\noindent\nThe $\\omega$-codes have recursive prefix. The value is encoded by $\\beta$-code followed with $0$. If the encoded $\\beta$-code value is longer than $k, k \\geq 2$ then a prefix is recursively prolonged by the prepending the value of $\\beta$-code of the length of the previous part encoded by $\\beta'$-code (length of $\\beta$-code $-1$). If the length of $\\beta$-code is shorted then $k$ then zerozes are prepended to make it of length $k$.\n\n\\noindent\nEncoding\\sidenote{$\\omega$-codes are uniquely decodable codes with variable length. They do not have the ability to encode value $0$ or negative numbers directly}\n\n\\subsection{$\\omega$-code ($k=2$)}\n$$\\omega(1) = 0^{k-1} = 0$$\n$$\\omega(x)= \\text{<prefix>}\\beta(x)0$$\n\n\\subsection{$\\omega'$-code ($k=3$)}\n$$\\omega(1) = 0^{k-1} = 00$$\n$$\\omega(x)= \\text{<prefix>}\\beta(x)0$$\n\n\\section{Ternary Comma Code}\nIt is a simple code based on base 3 number representation and comma (c), which gives the following encoding:\n\n\\begin{table}\n\\begin{tabular}{|c|c|c|c|}\\hline\n    0 & 1 & 2 & c\\\\\\hline\n    00 & 01 & 10 & 11\\\\\\hline\n\\end{tabular}\n\\caption{Ternary Comma Code}\n\\end{table}\n\n\\section{Fibbonacci Code}\nBinary number is representation where each position corresponts to $2^i, i \\in \\mathbb{N}_0$. These powers of $2$ can be raplaced with numbers from Fibbonacci sequence, excluding the initial $1$:\n$$1, 2, 3, 5, 8, 13, 21, 34\\ldots$$.\n\nThis gives us multiple representations of each number as the two consecutive numbers can always be replaced with the next one, i.e. $11$ has the same meaning as $100$, for example: \n$$1*5+1*3=1*8+0*5+0*3.$$\nBecause of this, each number can be represented using this Fibbonacci representation as a sequeance of $0$ and $1$, where no two consecutive $1$ are present ($11$). When such number is reversed and additional $1$ is appended, it leads to a code, where each additional $1$ marks the end of the keyword.\n\n\\section{Golomb Code}\n$GC(x,m)$ is Golomb Code of $x$ in modulo $m$.\n\n\\noindent\nQuotient:\n$$q=\\floor{x/m}.$$\nReminder:\n$$r=x-qm.$$\nCoeficient:\n$$c=\\ceil{\\log_2 m}.$$\n\n\\noindent\nReminder table $R$:\\\\\n\\begin{tabular}{r l l l l}\n    $2^c-m$ & values of & $r$ & $\\beta$-code encoded by $c-1$ & bits,\\\\\n    $2m-2^c$ & values of & $r+2^c-m$ & $\\beta$-code encoded by $c$ & bits.\n\\end{tabular}\n\n\\noindent\nEncoding:\n$$GC(x,m)=\\alpha'(q+1)R(r).$$\n\n\\subsection{Examples of reminder tables}\n$R$ for $m=3$:\n\n\\begin{table}\n\\begin{tabular}{|c||c|c|}\\hline\n    0 & 1 & 2\\\\\\hline\n    0 & 10 & 11\\\\\\hline\n\\end{tabular}\n\\caption{Golomb Code $R$ for $m=3$}\n\\end{table}\n\n\\noindent\n$R$ for $m=4$:\n\n\\begin{table}\n\\begin{tabular}{||c|c|c|c|}\\hline\n    0 & 1 & 2 & 3\\\\\\hline\n    00 & 01 & 10 & 11\\\\\\hline\n\\end{tabular}\n\\caption{Golomb Code $R$ for $m=4$}\n\\end{table}\n\n\\noindent\n$R$ for $m=5$:\n\n\\begin{table}\n\\begin{tabular}{|c|c|c||c|c|}\\hline\n    0 & 1 & 2 & 3 & 4\\\\\\hline\n    00 & 01 & 10 & 110 & 111\\\\\\hline\n\\end{tabular}\n\\caption{Golomb Code $R$ for $m=5$}\n\\end{table}\n\n\\noindent\n$R$ for $m=6$:\n\n\\begin{table}\n\\begin{tabular}{|c|c||c|c|c|c|}\\hline\n    0 & 1 & 2 & 3 & 4 & 5\\\\\\hline\n    00 & 01 & 100 & 101 & 110 & 111\\\\\\hline\n\\end{tabular}\n\\caption{Golomb Code $R$ for $m=6$}\n\\end{table}\n\n\\noindent\n$R$ for $m=7$:\n\n\\begin{table}\n\\begin{tabular}{|c||c|c|c|c|c|c|}\\hline\n    0 & 1 & 2 & 3 & 4 & 5 & 6\\\\\\hline\n    00 & 010 & 011 & 100 & 101 & 110 & 111\\\\\\hline\n\\end{tabular}\n\\caption{Golomb Code $R$ for $m=7$}\n\\end{table}\n\n\\noindent\n$R$ for $m=8$:\n\n\\begin{table}\n\\begin{tabular}{||c|c|c|c|c|c|c|c|}\\hline\n    0 & 1 & 2 & 3 & 4 & 5 & 6 & 7\\\\\\hline\n    000 & 001 & 010 & 011 & 100 & 101 & 110 & 111\\\\\\hline\n\\end{tabular}\n\\caption{Golomb Code $R$ for $m=8$}\n\\end{table}\n\n\\noindent\n$R$ for $m=14$:\n\n\\begin{table*}\n\\begin{tabular}{|c|c||c|c|c|c|c|c|c|c|c|c|c|c|}\\hline\n    0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13\\\\\\hline\n    000 & 001 & 0100 & 0101 & 0110 & 0111 & 1000 & 1001 & 1010 & 1011 & 1100 & 1101 & 1110 & 1111\\\\\\hline\n\\end{tabular}\n\\\\\n\\caption{Golomb Code $R$ for $m=14$}\n\\end{table*}\n\n\\section{Rice Code}\n$RC(x,m) = GC(x,m)$ if $m = 2^k, k \\in \\mathbb{N}_0$. \n\n%\\section{Properties of codes}\n\n%Universal, Asymptotically optimal\n\n%\\section{Examples}\n\n%\\begin{table*}\n%\\begin{tabular}{|c|r|r|r|r|r|r|r|r|r|r|r|r|r|}\\hline\n%    x & $\\alpha$-code & $\\beta$-code & $\\beta'$-code & $\\gamma'$-code & $\\gamma$-code & $\\delta$-code & $\\omega$-code & $\\omega'$-code \\\\\\hline\n%    0  & -         & $0$      & -       & $\\blue1$      & $\\blue1$      & $\\blue1$      & & \\\\\n%    1  & $1$       & $1$      & $\\varepsilon$ & & & & & \\\\\n%    2  & $01$      & $10$     & $0$     & $\\blue01\\red0$     & $0$     & $0$     & & & \\\\\n%    3  & $001$     & $11$     & $1$     & $\\blue01\\red1$     & $1$     & $1$     & & \\\\\n%    4  & $0^31$    & $100$    & $00$    & $\\blue001\\red00$    & $00$    & $00$    & & \\\\\n%    5  & $0^41$    & $101$    & $01$    & $\\blue001\\red01$    & $01$    & $01$    & & \\\\\n%    6  & $0^51$    & $110$    & $10$    & $\\blue001\\red10$    & $10$    & $10$    & & \\\\\n%    7  & $0^61$    & $110$    & $11$    & $\\blue001\\red10$    & $10$    & $10$    & & \\\\\n%    8  & $0^71$    & $1000$   & $000$   & $\\blue0001\\red000$   & $000$   & $000$   & & \\\\\n%    9  & $0^81$    & $1001$   & $001$   & $\\blue0001\\red001$   & $001$   & $001$   & & \\\\\n%    10 & $0^91$    & $1010$   & $010$   & $\\blue0001\\red010$   & $010$   & $010$   & & \\\\\n%    11 & $0^{10}1$ & $1011$   & $011$   & $\\blue0001\\red011$   & $011$   & $011$   & & \\\\\n%    12 & $0^{11}1$ & $1100$   & $100$   & $\\blue0001\\red100$   & $100$   & $100$   & & \\\\\n%    13 & $0^{12}1$ & $1101$   & $101$   & $\\blue0001\\red101$   & $101$   & $101$   & & \\\\\n%    14 & $0^{13}1$ & $1110$   & $110$   & $\\blue0001\\red110$   & $110$   & $110$   & & \\\\\n%    15 & $0^{14}1$ & $1111$   & $111$   & $\\blue0001\\red111$   & $111$   & $111$   & & \\\\\n%    16 & $0^{15}1$ & $10000$  & $0000$  & $\\blue00001\\red0000$  & $0000$  & $0000$  & & \\\\\n%    23 & $0^{22}1$ & $10111$  & $0111$  & $\\blue00001\\red0111$  & $0111$  & $0111$  & & \\\\\n%    24 & $0^{23}1$ & $11000$  & $1000$  & $\\blue00001\\red1000$  & $1000$  & $1000$  & & \\\\\n%    31 & $0^{30}1$ & $11111$  & $1111$  & $\\blue00001\\red1111$  & $1111$  & $1111$  & & \\\\\n%    32 & $0^{31}1$ & $100000$ & $00000$ & $\\blue000001\\red00000$ & $00000$ & $00000$ & & \\\\\\hline\n%\\end{tabular}\n%\\\\\n%\\caption{Examples of coding of integers}\n%\\end{table*}\n", "meta": {"hexsha": "a0c5c22e0f3511bb8349cb5e80e0717938e58897", "size": 8596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kod/ch2.tex", "max_stars_repo_name": "exander77/handouts", "max_stars_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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": "kod/ch2.tex", "max_issues_repo_name": "exander77/handouts", "max_issues_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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": "kod/ch2.tex", "max_forks_repo_name": "exander77/handouts", "max_forks_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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.7962962963, "max_line_length": 437, "alphanum_fraction": 0.5834108888, "num_tokens": 3454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933271118222, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6645062452304259}}
{"text": "\\section{Computational Power of the Equipment}\n\n\\lettrine[nindent=0em,lines=3]{I}n this chapter we present an analysis on the features of the available equipment for our experiments and final implementation of the system. We will make emphasis on the number of operations per second (FLOPS) that our equipment can handle.\n\nFloating Point Operations per Second (FLOPS) is a measure of computer performance, useful in fields of scientific computations that require floating-point calculations. For such cases it is a more accurate measure than measuring instructions per second \\cite{flops_wikipedia}. The FLOPS value can be used to determine the power for both the CPU and GPU.\n\nThe amount of Giga FLOPS (GFLOPS) for each node/computer can be calculated by using the following equation \\cite{peak_theoretical_performance}.\n\n\\begin{equation}\nGFLOPS = \\textit{CPU speed in GHz} \\times \\textit{number of CPU cores} \\times \\textit{CPU instruction per cycle} \\times \\textit{number of CPUs per node} \n\\label{flops_eq_cpu}\n\\end{equation}\n\nFor the case of Graphics Processing Units (GPUs), the amount of flops the GPU can support can be computed by \\cite{gpu_flops}\n\n\\begin{equation}\nFLOPS = 2 \\times \\textit{number of parallel GPU processing cores} \\times \\textit{peak clock speed in MHz}\n\\label{flops_eq_gpu}\n\\end{equation}\n\nThe computer used for our experiments has an Intel Core i7-7700K Processor; with a CPU speed of 4.2 GHz average and 4.5 GHz overclocked, 4 cores \\cite{cpu_tech_specs}, and 16 IPC \\cite{determine_number_flops_cpu}.  Using these values and eq. \\eqref{flops_eq_cpu}, the FLOPS range for the CPU is: 268.8 GFLOPS to 288 GFLOPS.\n    \nThe computer used for our experiments also comes with a dedicated GPU. The GPU used in our system is a NVDIA GeForce GTX 1080Ti with 11GB GDDR5X; with a boost clock of 1582 MHz and 3584 NVIDIA CUDA Cores \\cite{gpu_tech_specs}. Using the given values and eq. \\eqref{flops_eq_gpu} the FLOPS value for the GPU is 11339.776 GFLOPS which is approximately 11,300 GFLOPS.\n\nBy combining the FLOPs value for both the CPU and GPU, the total FLOPs range of the server is 11608.576 GFLOPS to 11627.776 GFLOPS. This can be converted to FLOPS/month by multiplying the given range by $2592000$, using the assumption that a month is 30 days. This gives a final FLOPS/month of $3.00894 \\times 10^{19}$ FLOPS/month to $3.01392 \\times 10^{19}$ FLOPS/month.\n", "meta": {"hexsha": "f0bbe48350f99fb53bfab7ee0c1162173d80e862", "size": 2385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/Reports/Computational Power/computational_power.tex", "max_stars_repo_name": "jqsun1/intelligent_hvac_backend", "max_stars_repo_head_hexsha": "29762db6e428e228f4a6aebea4977140cd025c1b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Docs/Reports/Computational Power/computational_power.tex", "max_issues_repo_name": "jqsun1/intelligent_hvac_backend", "max_issues_repo_head_hexsha": "29762db6e428e228f4a6aebea4977140cd025c1b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Docs/Reports/Computational Power/computational_power.tex", "max_forks_repo_name": "jqsun1/intelligent_hvac_backend", "max_forks_repo_head_hexsha": "29762db6e428e228f4a6aebea4977140cd025c1b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 91.7307692308, "max_line_length": 371, "alphanum_fraction": 0.7865828092, "num_tokens": 655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6644129215919677}}
{"text": "\\section{Spherical Harmonics}\nSince $V\\to 0$ at $r\\to\\infty$, then $a_{lm}=0$.\nImpose boundary condition at $r=a$.\n\\begin{align}\n    \\sum_{l=0}^{n}\\sum_{m=-l}^{+l}\n    \\frac{b_{lm}}{a^{l + 1}} Y_{lm}\\left( \\theta, \\phi \\right)\n    =\n    V_0 \\left( \\theta, \\phi \\right)\n\\end{align}\nnote\n\\begin{align}\n    V\\left( \\theta, \\phi \\right)\n    &=\n    \\sum_{l,m}\n    \\left( a_{lm}\n    r^l\n    +\n    \\frac{b_{lm}}{r^{l + 1}}\\right)\n    Y_{lm}\\left( \\theta, \\phi \\right)\n\\end{align}\nUse orthogonality of spherical harmonics to find $b_{lm}$,\n\\begin{align}\n    \\int d\\Omega \\, Y_{l'm'}^* \\left( \\theta,\\phi \\right)\n    \\left\\{ \n    \\sum_{l,m}\n    \\frac{b_{lm}}{a^{l + 1}}\n    Y_{lm\\left( \\theta, \\phi \\right)}\n    \\right\\}\n    &=\n    \\int d\\Omega\\,\n    Y_{l'm'}^*\\left( \\theta, \\phi \\right)\n    V_0\\left( \\theta, \\phi \\right)\n\\end{align}\nso\n\\begin{align}\n    b_{lm}\n    &=\n    a^{l + 1}\n    \\int d\\Omega\\,\n    Y_{lm}^*\\left( \\theta, \\phi \\right)\n    V_0\\left( \\theta, \\phi \\right)\n\\end{align}\nso finally\n\\begin{align}\n    V\\left( r, \\theta, \\phi \\right)\n    &=\n    \\sum_{l=0}^{\\infty}\n    \\int_{m=-l}^{+l}\n    \\left( \\frac{a}{r} \\right)^{l + 1}\n    Y_{lm}\\left( \\theta, \\phi \\right)\n    \\int d\\Omega'\n    Y_{lm}^*\\left( \\theta', \\phi' \\right)\n    V_0\\left( \\theta', \\phi' \\right)\n\\end{align}\nI'll show you your formula sheet before the exam.\nUsually you just express the answer in terms of Legendre polynomials.\nUsually you're going to leave your answer in terms of the $Y_{lm}$ except where\nthere is spherical symmetry and you can write it in terms of Legendre\npolynomials.\n\nYou can either not bother with $Y_{lm}$ and use Legendre polynomials,\nor just use spherical harmonics and reduce it to the Legendre polynomials.\nRemember the relation between the spherical harmonics and the Legendre\npolynomials.\n\nLet's do another example.\n\\begin{example}\n    Find the Dirichlet Green function for a sphere of radius $b$ centered at\n    origin.\n    \\begin{align}\n        \\nabla^2 G\\left( \\vec{r}, \\vec{r}' \\right)\n        &=\n        -4\\pi \\delta^{3}\\left( \\vec{r} - \\vec{r}' \\right)\n    \\end{align}\n    such that $G\\left( \\vec{r}, \\vec{r}' \\right) = 0$\n    at $\\left|\\vec{r}\\right| = b$.\n\\end{example}\nThis is a very standard problem.\nI have a charge here somewhere in the sphere and I want to find the charge here.\nIt's Laplace's equation except for that one point,\nso we look for a solution like that.\n\nAwa from $\\vec{r}=\\vec{r}'$,\nthe Green function satisfies Laplace's equation\n\\begin{align}\n    G\\left( \\vec{r}, \\vec{r}' \\right)\n    &=\n    \\sum_{l=0}\n    \\sum_{m=-l}^{l}\n    g_{lm}\\left( r \\right)\n    Y_{l}^{\\,m}\\left( \\theta, \\phi \\right)\n\\end{align}\nSo we look for a separable solution.\nNow take this and plug it in to the definition of the Green function.\n\nAnd then yo get\n\\begin{align}\n    \\sum_{l,m}\n    \\left\\{ \n    \\frac{d^2 g_{lm}}{dr^2}\n    +\n    \\frac{2}{r}\n    \\frac{dg_{lm}}{dr}\n    -\n    \\frac{l(l + 1)}{r^2}g_{lm}\n    \\right\\}\n    Y_{l}^{\\,m}\\left( \\theta, \\phi \\right)\n    &=\n    -4\\pi \\delta^3 \\left( \\vec{r} - \\vec{r}' \\right)\n\\end{align}\nThen we multiply both sides by ${Y^*}_{l'}^{\\, m'}\\left( \\theta, \\phi \\right)$\nand integrate over $\\Omega$.\n\\begin{align}\n    \\frac{d^2 g_{l'm'}}{dr^2}\n    +\n    \\frac{2}{r} \\frac{dg_{l'm'}}{dr}\n    -\n    \\frac{l'\\left( l' + 1 \\right)}{r^2} g_{l'm'}\n    &=\n    -4\\pi\n    \\int d\\Omega\\,\n    {Y^*}_{l'}^{\\,m'}\\left( \\theta, \\phi \\right)\n    \\underbrace{\\delta^3\\left( \\vec{r} - \\vec{r}' \\right)}_{\n    \\frac{\\delta\\left( r - r' \\right)}{r^2}\n    \\delta\\left( \\cos\\theta - \\cos\\theta' \\right)\n    \\delta\\left( \\phi - \\phi' \\right)\n    }\\\\\n    &=\n    -\\frac{4\\pi}{r^2}\n    {Y^*}_{l'}^{\\,m'}\\left( \\theta, \\phi \\right)\n\\end{align}\nThis is much simpler because this is just an ODE,\nso like the 1D problem we solve.\n\nAway from $r=r'$,\n\\begin{align}\n    g_{lm}\\left( r \\right)\n    &=\n    A_{lm} r^l + B_{lm} \\frac{1}{r^{l + 1}}\n\\end{align}\nSo it's just like Laplace's equation.\nThe only difference is that you have a sphere and a delta function source\nsomewhere here.\nThis source is at $\\vec{r}'$.\nSo we have Laplace's equation everywhere except $\\vec{r}'$.\nSo we're going to get one value of the $A_{lm}$ for $r<r'$\nand another value for $r>r'$.\nSo we are solving Laplace's equation for $r<r'$ and then for $r>r'$\nand then we stick the two solutions together.\nThis is similar to what we did when we were solving for the Greens function for\nthe box,\nwhere we had a point charge in the middle of the box and we had to divide the\nbox into two pieces,\nwhich we solved and matched the distributions,\ndid using a more careful sophisticated way using the convergence theorem,\nbut here I'm doing it much quicker,\nas the two are mathematically equivalent,\nand you won't have time in an exam to do all those divergence theorems.\nSo this is equivalent to what we did.\nHere we are breaking the sphere into two pieces,\none $r<r'$ and $r>r'$,\njust done much more directly than the box,\nand this is much faster,\nbecause very quickly it gets reduced to a 1D ODE.\n\nSo in general,\n$A_{lm}$ and $B_{lm}$ will be different for $r<r'$\nand $r>r'$.\nThis $1/r^{l+1}$ blows up when $r=0$,\nso since $g_{lm}(r)$ must be regular at $r=0$,\nwe have\n\\begin{align}\n    g_{lm}^{<}\\left( r \\right)\n    &=\n    A_{lm}^{<} r^l\n\\end{align}\nwhich is the solution for $r < r'$.\nAlso, we need that\n\\begin{align}\n    g_{lm}\\left( r \\right) = 0\n\\end{align}\nat $r=b$,\nso\n\\begin{align}\n    g_{lm}^{>}\\left( r \\right)\n    &=\n    A_{lm}^{>}\n    \\left( \n    r^l\n    -\n    \\frac{b^{2l + 1}}{r^{l + 1}}\n    \\right)\n\\end{align}\nfor $r>r'$.\nThe solutions are different for $r<r'$ and $r>r'$,\nwhich is similar to the solution for the box\nwhere the solution was different above and below the box\nand you had to stick the solutions together at the boundary.\nSo now let's stitch the solutions together.\n\nSince solutions must be continuous at $r=r'$,\n\\begin{align}\n    g_{lm}^{<}\\left( r' \\right)\n    &=\n    g_{lm}^{>}\\left( r' \\right)\n\\end{align}\nso you get this condition\n\\begin{align}\n    A_{lm}^{<}\n    &=\n    A_{lm}^{>}\n    \\left( \n    1\n    -\n    \\frac{b^{2l + 1}}{r'^{2l + 1}}\n    \\right)\n\\end{align}\nAnd then integrate the ODE on both sides over $r$\nfrom $r=r' - \\epsilon$ to $r=r' + \\epsilon$,\nwhich is the region that contains the delta function.\nThen you get\n\\begin{align}\n    \\left\\frac{dg_{lm}}{dr}\\right|_{r' + \\epsilon}\n    -\n    \\left\\frac{dg_{lm}}{dr}\\right|_{r' - \\epsilon}\n    &=\n    -\\frac{4\\pi}{r'^2}\n    {Y^*}_{l}^{m}\\left( \\theta', \\phi' \\right)\n\\end{align}\nSo this is the second condition.\nAnd this is a lot messier.\n\\begin{align}\n    A_{lm}^{>}\n    \\left\\{ \n    l {r'}^{l - 1}\n    +\n    \\left( l + 1 \\right)\n    \\frac{b^{2l + 1}}{ {r'}^{l + 2}}\n    \\right\\}\n    -\n    A_{lm}^{,}\n    \\left\\{ \n    l {r'}^{l - 1}\n    \\right\\}\n    &=\n    - \\frac{4\\pi}{ {r'}^2 }\n    {Y^*}_{m}^{\\, l} \\left( \\theta', \\phi' \\right)\n\\end{align}\nAnd then you do some algebra,\nand the final answer is\n\\begin{align}\n    G\\left( \\vec{r}, \\vec{r}' \\right)\n    &=\n    \\sum_{l,m}\n    \\frac{4\\pi}{\\left( 2l + 1 \\right)}\n    r_{<}^{l}\n    r_{>}^{l}\n    \\left\\{ \n    \\frac{1}{r_{>}^{2l + 1}}\n    -\n    \\frac{1}{b^{2l + 1}}\n    \\right\\}\n    {Y^*}_{l}^{m}\\left( \\theta', \\phi' \\right)\n    Y_{l}^{\\;m}\\left( \\theta, \\phi \\right)\n\\end{align}\n\n\\section{Cylindrical Coordinates}\n\\begin{example}\n    Consider an infinitely long cylinder of radius $b$\n    that is aligned so its axis is along the $z$-axis.\n    The potential on surface is independent of $z$\n    and given by $V_0(\\phi)$.\n\n    Find the potential inside the cylinder.\n\\end{example}\nSo the cylinder has radius $b$ and you're given the potential $V_0(\\phi$ on the\nboundary surface.\nThe problem is to solve for $\\nabla^2 V=0$.\n\nOnce again we're going to use separation of variables.\n\\begin{align}\n    \\frac{1}{\\rho}\n    \\frac{\\partial}{\\partial \\rho}\n    \\left( \n    \\rho\n    \\frac{\\partial V}{\\partial \\rho}\n    \\right)\n    +\n    \\frac{1}{\\rho^2}\n    \\frac{\\partial^2 V}{\\partial \\phi^2}\n    +\n    \\frac{\\partial^2 V}{\\partial z^2}\n    &=\n    0\n\\end{align}\nNote it should be independent of $z$.\nSo we get\n\\begin{align}\n    \\frac{\\partial^2 V}{\\partial \\rho^2}\n    +\n    \\frac{1}{\\rho}\n    \\frac{\\partial V}{\\partial \\rho}\n    +\n    \\frac{1}{\\rho^2}\n    \\frac{\\partial^2 V}{\\partial \\phi^2}\n    &=\n    0\n\\end{align}\nUsing separation of variables,\n\\begin{align}\n    V\\left( \\rho, \\phi \\right)\n    &=\n    R\\left( \\rho \\right)\n    \\Phi\\left( \\phi \\right)\n\\end{align}\nso the equation becomes separable\n\\begin{align}\n    \\frac{\\rho^2}{R}\n    \\left\\{ \n    \\frac{d^2 R}{d\\rho^2}\n    +\n    \\frac{1}{\\rho}\n    \\frac{dR}{d\\rho}\n    \\right\\}\n    &=\n    -\\frac{1}{\\Phi}\n    \\frac{d^2 \\Phi}{d\\phi^2}\n    =\\nu^2\n\\end{align}\nwhere $\\nu$ is a constant.\nSo we have the ODE\n\\begin{align}\n    \\frac{d^2\\Phi}{d\\phi^2}\n    +\n    \\nu^2 \\Phi\n    &= 0\n\\end{align}\nwhich has the solution\n\\begin{align}\n    \\Phi\n    &=\n    A \\sin\\left( \\nu \\phi \\right)\n    +\n    B \\cos\\left( \\nu \\phi \\right)\n\\end{align}\nIf $\\phi$ runs from $0$ to $2\\pi$,\n$\\Phi(\\phi) = \\Phi\\left( \\phi + 2\\pi \\right)$,\nwhich means $\\nu$ must be an integer.\n\nNow for the other equation.\n\\begin{align}\n    \\frac{d^2 R}{d\\rho^2}\n    +\n    \\frac{1}{\\rho}\n    \\frac{dR}{d\\rho}\n    -\n    \\frac{\\nu^2}{\\rho^2}R\n    &=\n    0\n\\end{align}\nSo the solution should be something like $R\\sim \\rho^\\nu$\nand $R\\sim \\rho^{-\\nu}$.\nThere will be a homework problem with power law but imaginary power,\nbut for this problem it's not relevant now.\nBut what if $\\nu=0$ so there are no two independent solutions?\nWell in the case $\\nu=0$,\nthen we have the special case\n$R\\left( \\rho \\right) =$ constant and $R\\left( \\rho \\right) = \\log \\rho$.\n\nNow we can expand out the solution\n\\begin{align}\n    V\\left( \\rho, \\phi \\right)\n    &=\n    a_0 + b_0 \\log\\rho\n    +\n    \\sum_{n=1}^{\\infty}\n    a_n \\rho^n \\sin\\left( n\\phi + \\alpha_n \\right)\n    +\n    \\sum_{n=1}^{\\infty} b_n \\frac{1}{\\rho^n}\n    \\cos\\left( n \\phi + \\beta_n \\right)\n\\end{align}\nand this is the general solution.\nNote that the $\\frac{1}{\\rho^n}$ blows up at the origin,\nso we must have $b_n=0$ for our problem.\nSuppose we were looking for solutions outside the cylinder,\nthen in that case it wouldn't be.\nBut for our case,\n$b_n=0$.\nIn fact, $b_0$ is also $0$ because the logarithm also blows up at $\\rho=0$.\n\nSo then for our particular problem,\n\\begin{align}\n    V\\left( \\rho, \\phi \\right)\n    &=\n    a_0\n    +\n    \\sum_{n=1}^{\\infty}\n    a_n \\rho^n \\sin\\left( n\\phi + \\alpha_n \\right)\n\\end{align}\nNow we have to determine these coefficients.\nWhat we use to determine these coefficients is that we know\nthis is equal to $V_0(\\phi)$ at $\\rho = b$,\nso it's kind of like a Fourier series with the sum of trigonometric functions.\nFirst let's rewrite this as the standards Fourier series\n\\begin{align}\n    V\\left( \\rho, \\phi \\right)\n    &=\n    \\frac{1}{2} c_0\n    +\n    \\sum_{n=1}^{\\infty}\n    \\rho^n\\left\\{ \n    c_n \\cos\\left( n\\phi \\right)\n    +\n    d_n \\sin\\left( n\\phi \\right)\n    \\right\\}\n\\end{align}\nso it's been expanded in sine and cosine term.s.\nAt the surface of the cylinder $\\rho=b$,\n\\begin{align}\n    V\\left( b, \\phi \\right)\n    &=\n    V_0\n    +\n    \\frac{1}{2} b_0\n    \\sum_{n=1}^{\\infty}\n    b^n\n    \\left\\{ \n    c_n \\cos\\left( n\\phi \\right)\n    + d_n \\sin\\left( n\\phi \\right)\n    \\right\\}\n\\end{align}\nand now this really is exactly the form of a Fourier series,\nso now you can invert it to find the $c_n$ and $d_n$ coefficients.\nYou can use the standard formula for Fourier series.\n\\begin{align}\n    c_n &=\n    \\frac{1}{\\pi}\n    \\frac{1}{b^n}\n    \\int_{0}^{2\\pi}\n    d\\phi'\\,\n    V_0\\left( \\phi' \\right)\n    \\cos\\left( n\\phi' \\right)\\\\\n    d_n &=\n    \\frac{1}{\\pi}\n    \\frac{1}{b^n}\n    \\int_{0}^{2\\pi}\n    d\\phi'\n    V_0\\left( \\phi' \\right)\n    \\sin\\left( n\\phi' \\right)\n\\end{align}\nand it turns out with a page of algebra and mathematical tricks,\nit turns out you can resum this.\nGo through the notes to see the trick,\nand there is a homework problem where you have to use this trick.\nThe steps themselves are not very difficult,\njust follow the in the notes.\n", "meta": {"hexsha": "79e42636b9a4edf17700e21bcf097e0a3977242b", "size": 11974, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture27.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/lecture27.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/lecture27.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.2013129103, "max_line_length": 80, "alphanum_fraction": 0.6011357942, "num_tokens": 4322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6644129070323159}}
{"text": "%-----------------------------------------------------------------------------------------------\n\\section{General Solution}\n\n    Owing to Definition~\\ref{def:polyekthetic} being very broad, the focus  now  shifts  towards\n    the more applicable Definition~\\ref{def:polyekthetic.exponent}, i.e., in finding expressions\n    for constant-property polyekthetic exponents $k_{ij\\ell}$.\n\n    %---------------------------------------------------------------------------------------\n    \\subsection{In Partial Differential Notation}\n\n    Let property $\\ell\\!:\\!\\ell(i, j)$; then,  the  total  differential  of  $\\ell$  is,  for  a\n    const-$\\ell$ process:\n    %\n    \\begin{equation}\n        d\\ell = \\parxyz\\ell ij\\,di + \\parxyz\\ell ji\\,dj = 0\n        \\label{eq:polyek.dl}\n    \\end{equation}\n    %\n    \\noindent which must be recast into an ODE  whose  solution,  \\emph{at  least  locally},  is\n    Eq.~(\\ref{eq:polyekthetic}). Isolating $di$:\n    %\n    \\begin{equation}\n        di = -\\parxyz\\ell ji \\parxyz i\\ell j\\,dj,\n        \\label{eq:polyek.di}\n    \\end{equation}\n    %\n    \\noindent which can be arranged as:\n    %\n    \\begin{equation}\n        \\frac{di}{i} = \\frac{-j}{i} \\parxyz\\ell ji \\parxyz i\\ell j \\frac{dj}{j}.\n        \\label{eq:polyek.ode}\n    \\end{equation}\n\n    The polyekthetic exponent, $k_{ij\\ell}$, is therefore:\n    %\n    \\begin{equation}\n        k_{ij\\ell} = \\frac{j}{i} \\parxyz\\ell ji \\parxyz i\\ell j.\n        \\label{eq:polyek.k.raw}\n    \\end{equation}\n\n    Using the cyclic relationship:\n    %\n    \\begin{equation}\n        -1 = \\parxyz ji\\ell \\parxyz\\ell ji \\parxyz i\\ell j,\n        \\label{eq:cyclic}\n    \\end{equation}\n    %\n    \\noindent the polyekthetic exponent can be rewritten as:\n    %\n    \\begin{equation}\n        k_{ij\\ell} = \\frac{-j}{i} \\parxyz ij\\ell.\n        \\label{eq:polyek.k}\n    \\end{equation}\n\n    Eq.~(\\ref{eq:polyek.k}) is thus the general solution for $k_{ij\\ell}$.\n\n    %---------------------------------------------------------------------------------------\n    \\subsection{In Terms of Bridgman's Relations}\n\n    Perhaps the easiest way of expressing any polyekthetic  exponent  $k_{ij\\ell}$  (for  simple\n    properties $\\ell$) in terms of quantities measurable in laboratory is  by  rewriting  it  in\n    terms of Bridgman's relations~\\cite{2006-BejanA-Wiley}, which are expressed in  terms  of  a\n    peculiar notation.\n    %\n    \\begin{equation}\n        \\frac{\\bri i\\ell}{\\bri j\\ell} \\equiv \\parxyz ij\\ell.\n        \\label{eq:Bridgman}\n    \\end{equation}\n\n    Please note that the $\\equiv$ sign on Eq.~(\\ref{eq:Bridgman}) indicates  the  definition  of\n    the \\emph{ratio} between shown Bridgman's primitives $\\bri i\\ell$ and $\\bri j\\ell$ in  terms\n    of $\\inlxyz ij\\ell$, rather than the other way around.\n\n    Bridgman's relations are tabulated, and can be found on reference~\\cite{2006-BejanA-Wiley}.\n\n    The general expression for $k_{ij\\ell}$, using Bridgman's relations notation, is therefore:\n    %\n    \\begin{equation}\n        k_{ij\\ell} = \\frac{-j}{i}\\frac{\\bri i\\ell}{\\bri j\\ell}.\n        \\label{eq:k.bri}\n    \\end{equation}\n\n    %---------------------------------------------------------------------------------------\n    \\subsection{Properties of Polyekthetic Exponents}\n\n    \\begin{theorem}\\label{the:k.recip}\n        if  $k_{ij\\ell}$  is  a  constant-property  process  polyekthetic  exponent,  then   the\n        constant-property process polyekthetic exponent\n        %\n        \\begin{equation}\n            k_{ji\\ell} = \\frac{1}{k_{ij\\ell}}.\n            \\label{eq:k.recipr}\n        \\end{equation}\n    \\end{theorem}\n\n    \\begin{proof}\n        Let  $k_{ij\\ell}$  be  a  constant-property   process   polyekthetic   exponent,   then,\n        Eq.~(\\ref{eq:polyek.k}) holds.\n\n        Applying Eq.~(\\ref{eq:polyek.k}) for a $k_{ji\\ell}$, i.e.,  with  swapped  $i$  and  $j$\n        property indices, gives :\n        %\n        \\begin{align}\n            k_{ji\\ell} &= \\frac{-i}{j} \\parxyz ji\\ell\n                       & \\rightharpoondown\\\\\n            k_{ji\\ell} &= \\left[\\frac{-j}{i} \\parxyz ij\\ell\\right]^{-1}\n                       & \\rightharpoondown\\\\\n            k_{ji\\ell} &= \\left(k_{ij\\ell}\\right)^{-1} = \\frac{1}{k_{ij\\ell}},\n        \\end{align}\n        %\n        \\noindent thus proving the theorem.\n    \\end{proof}\n\n    \\begin{theorem}\\label{the:k.consti}\n        All constant-property process polyekthetic exponents $k_{iji} = 0$.\n    \\end{theorem}\n\n    \\begin{proof}\n        Let  $k_{ij\\ell}$  be  a  constant-property   process   polyekthetic   exponent,   then,\n        Eq.~(\\ref{eq:polyek.k}) holds.\n\n        Applying  Eq.~(\\ref{eq:polyek.k})  for  a  $k_{iji}$,  i.e.,   obtaining   a   const-$i$\n        polyekthetic exponent, gives\n        %\n        \\begin{align}\n            k_{iji} &= \\frac{-j}{i} \\parxyz iji\n                    & \\rightharpoondown\\\\\n            k_{iji} &= 0,\n        \\end{align}\n        %\n        \\noindent by properties of partial derivatives, thus proving the theorem.\n    \\end{proof}\n\n    \\begin{theorem}\\label{the:k.constj}\n        All constant-property process polyekthetic exponents $k_{ijj} \\to \\pm\\infty$.\n    \\end{theorem}\n\n    \\begin{proof}\n        From Theorem~\\ref{the:k.recip}, one has\n        %\n        \\begin{equation}\n            k_{ijj} = 1 / k_{jij},\n        \\end{equation}\n        %\n        \\noindent which, from Theorem~\\ref{the:k.consti} which establishes $k_{jij} = 0$,  leads\n        to\n        %\n        \\begin{equation}\n            k_{ijj} = 1 / 0 \\to \\pm\\infty,\n        \\end{equation}\n        %\n        \\noindent thus proving the theorem.\n    \\end{proof}\n\n    Moreover, from Theorems~\\ref{the:k.consti} and~\\ref{the:k.constj}, whenever property indices\n    are repeated, the corresponding polyekthetic exponent $k$ is a trivial one.\n\n    If properties $i$, $j$, and $\\ell$, $i \\neq j  \\neq  \\ell  \\neq  i$,  are  chosen  from  the\n    ``usual'' $\\{P, T, v, u, h, s, a, g\\}$ engineering thermodynamics  intensive  property  set,\n    there will be $8!/5! = 336$ combinations of non-trivial $k_{ij\\ell}$. However,  due  to  the\n    reciprocity  property  of  Theorem~\\ref{the:k.recip},  there  will  be  $168$   non-trivial,\n    non-reciprocal $k_{ij\\ell}$ required to easily deduce the remaining ones.\n\n%-----------------------------------------------------------------------------------------------\n\n", "meta": {"hexsha": "c7d4a0527c895efa7b2904a84cdc0f819b2bd333", "size": 6319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01-03-GenSolution.tex", "max_stars_repo_name": "cnaak/man-Polyekthetic", "max_stars_repo_head_hexsha": "0918d9d87e9e8841126059ce3346f15bd6826999", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01-03-GenSolution.tex", "max_issues_repo_name": "cnaak/man-Polyekthetic", "max_issues_repo_head_hexsha": "0918d9d87e9e8841126059ce3346f15bd6826999", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01-03-GenSolution.tex", "max_forks_repo_name": "cnaak/man-Polyekthetic", "max_forks_repo_head_hexsha": "0918d9d87e9e8841126059ce3346f15bd6826999", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0662650602, "max_line_length": 96, "alphanum_fraction": 0.5486627631, "num_tokens": 1904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6644129058631197}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 1, 2022}\n\\todo{Happy Lunar New Year! \\faHandPeaceO}\n\n\\emph{(Thanks Qinan and Andrew for allowing me to shamelessly copy their notes.)}\n\n\\subsection{Divisibility and Factorization}\nWe start with some commonly used notation:\n\\begin{definition}[Divisibility]\n    We use $a\\mid b$ to mean ``$a$ divides $b$'' and $a\\nmid b$ to mean ``$a$ does not divide $b$''.\n\\end{definition}\n\nNow for a series of definitions:\n\n\\begin{definition}[Primality]\n    A positive integer $p\\geq 2$ is said to be \\ul{prime} if its only positive divisors are $1$ and $p$.\n\\end{definition}\n\n\\begin{definition}[Positive Integers]\n    $\\ZZ_+$ will denote the \\ul{positive integers}.\n\\end{definition}\n\n\\begin{definition}[Order]\n    For a nonzero $n\\in \\ZZ$ and a prime $p$, there is a nonnegative integer $a$ such that $p^a\\mid n$ but $p^{a + 1}\\nmid n$. This number $a$ is called the \\ul{order} of $n$ at $p$, denoted by $\\ord_p n$.\n\n    For $n=0$, we set $\\ord_p 0 = \\infty$. We also have $\\ord_p n = 0\\Leftrightarrow p\\nmid n$.\n\\end{definition}\n\nWe prove a lemma as warm-up:\n\\begin{lemma}[Existence of Factorization]\n    Every nonzero integer can be written as a product of primes.\n\n    \\emph{We make an exception for $-1$. The empty product is $1$ so $1$ is fine.}\n\\end{lemma}\n\\begin{proof}\n    Suppose for the sake of contradiction otherwise, that some nonzero integer can be written as a product of primes. Let $N$ be the smallest integer greater than $2$ that cannot be written as a product of primes.\n\n    $N$ had better not be a prime number itself (since then it would be a product of itself). Then we can write $N = a\\cdot b$ where $1 < a, b < N$.\n\n    Since we took $N$ as the least such number that cannot be written as a product of primes, $a$ and $b$ which are less than $N$ can be written as a product of primes. Then $N$ is a product of primes since $a$ and $b$ individually are. This is a contradiction! Thus it had better be the case that \\emph{every} nonzero integer can be written as a product of primes.\n\\end{proof}\n\nThis is the theorem we will eventually work toward proving:\n\n\\begin{theorem}[Unique Factorization]\\label{thm:unique-factorization}\n    Every nonzero integer $n$ yields a \\emph{unique} prime factorization\n    \\begin{equation*}\n        n = (-1)^\\varepsilon\\cdot \\prod_{p}p^{a(p)}, a(p)\\geq 0\n    \\end{equation*}\n    where $\\varepsilon = 0$ or $1$, and $\\varepsilon, a(p)$ are uniquely determined by $n$. Moreover, we note that $a(p) = \\ord_p n$.\n\\end{theorem}\n\n\\subsection{Euclidean and Principal Ideal Domains}\nBefore this proof, we first recall a conclusion from Math 1530:\n\\begin{lemma}[Division Lemma]\\label{division-lemma}\n    If $a, b\\in \\ZZ$ and $b>0$, then there exists $q, r\\in \\ZZ$ such that\n    \\[a = bq + r\\]\n    with $0\\leq r < b$.\n\\end{lemma}\n\\begin{proof}\n    Consider the set\n    \\[S = \\{a - xb \\mid x\\in \\ZZ\\}\\]\n    We note that $S$ contains \\emph{some} positive elements. Let $r = a - qb$ be the least nonnegative element of $S$.\n\n    We claim that $0\\leq r < b$. Suppose for the sake of contradiction otherwise, then $r = a - qb \\geq b$ gives $a - qb - b \\leq 0$ and $a - (q+1)b\\leq 0$. Which is a contradiction since we took $r$ to be a the least nonnegative element in $S$ and we've found such smaller element $a - (q+1)b$.\n\n    Then it had better be that $0\\leq r < b$ for some $r, q\\in\\ZZ$.\n\\end{proof}\n\\begin{corollary}\\label{cor:z-euclidean}\n    $\\ZZ$ is a Euclidean domain, with a Euclidean function given by \\cref{division-lemma}.\n\\end{corollary}\n\n\\begin{definition}[Euclidean Domain]\n    Let $R$ be an integral domain. $R$ is a \\ul{Euclidean domain} if there exists a function $\\lambda: R\\setminus \\{0\\} \\to \\NN$ such that if $a, b\\in R$ with $b\\neq 0$, then there exists some $c, d\\in R$ with the property that $a = cb + d$ with $d=0$ or $\\lambda(d) < \\lambda(b)$.\n\\end{definition}\n\\begin{example}\n    $\\ZZ$ is a Euclidean domain with $\\lambda$ function given in \\cref{division-lemma}.\n\n    $R[x]$ for field $R$ is also a Euclidean domain, with $\\lambda = \\deg$.\n\n\\end{example}\n\n\\begin{proposition}\n    If $R$ is a Euclidean domain, then $R$ is a principal ideal domain. That is, if $I\\subseteq R$ is an ideal, then $\\exists a\\in R$ such that $I = Ra = \\{ra\\mid r\\in R\\}$.\n\\end{proposition}\n\\begin{proof}\n    Assume WLOG that $I$ is not the trivial ideal $I\\neq (0)$. Let $0\\neq a\\in I$ such that $\\lambda(a)\\leq \\lambda(b) \\forall b\\in I, b\\neq 0$.\n\n    We claim that $I = (a) = Ra$.\n\n    We know that $Ra\\subseteq I$ since $I$ is an ideal. Let $b\\in I$. Then $\\exists c, d\\in R$ such that $b = ca + d$ where $d = 0$ or $\\lambda(d) < \\lambda(a)$. Now we have $d = b-ca\\in I$, so we can't have $\\lambda(d) < \\lambda(a)$. Thus $d = 0$, so $b=ca\\in Ra$.\n\n    Hence we have $I\\subseteq Ra$. Together, we conclude that $I = Ra$.\n\\end{proof}\n\n\\begin{definition}[Principal Ideals, PIDs]\n    If $I = (a)$ for some $a\\in I$, then $I$ is said to be a \\ul{principal ideal}.\n\n    $R$ is a \\ul{principal ideal domain} (PID) if every ideal of $R$ is principal.\n\\end{definition}\n\nHere are some important properties of PIDs:\n\\begin{enumerate}\n    \\item Nonunit irreducible elements are exactly the prime elements in $R$.\n\n          \\recall $p\\in R$ is \\ul{irreducible} if $a\\mid p\\Rightarrow a$ is either a unit or an associate of $p$.\n\n          $p\\in R$ is \\ul{prime} if $p\\mid ab\\Rightarrow p\\mid a$ or $p\\mid b$ and $p$ is a nonzero, nonunit of $R$.\n\n    \\item GCDs always exist in PIDs.\n\\end{enumerate}\n\n\\subsection{Unique Prime Factorization}\nWe're nearly ready to prove unique factorization, after a lemma:\n\\begin{lemma}\\label{additive-orders}\n    Suppose $p$ is a prime, and $a, b\\in Z$. Then $\\ord_p(ab) = \\ord_p a + \\ord_p b$.\n\\end{lemma}\n\\begin{proof}\n    WLOG, assume $a, b\\neq 0$. We let\n    \\begin{align*}\n        \\alpha & = \\ord_p a \\\\\n        \\beta  & = \\ord_p b\n    \\end{align*}\n    Then we have\n    \\begin{align*}\n        a & = p^\\alpha\\cdot c \\text{ where }p\\nmid c \\\\\n        b & = p^\\beta\\cdot d \\text{ where }p\\nmid d\n    \\end{align*}\n    Thus, $ab = p^{\\alpha + \\beta}\\cdot cd$. We have that $p\\nmid cd$ since $p\\nmid c$ and $p\\nmid d$ (we rely on the fact that if $p$ is irreducible, $p$ is prime). Thus we have that $\\ord_p (ab) = \\alpha + \\beta$.\n\\end{proof}\n\n\\begin{proof}\n    (of \\cref{thm:unique-factorization}, that $\\ZZ$ is a UFD). Recall that for a nonzero $n\\in \\ZZ$, we write\n    \\[n = (-1)^\\varepsilon \\prod_{p}p^{a(p)}, \\text{where }\\varepsilon = 0\\text{ or }1\\text{ and }a(p)\\geq 0\\]\n    Given a positive prime $q$, we take $\\ord_q$ of both sides. By \\cref{additive-orders}, this yields\n    \\[\\ord_q n = \\varepsilon\\cdot \\ord_q (-1) + \\sigma_p a(p)\\ord_q(p)\\]\n    Since we have that $\\ord_q(-1) = 0$ and $\\ord_q(p) = 0, \\forall p\\neq q$, we've uniquely determined $a(q)$ since $\\ord_q(n) = a(q)$. That is, $a(q)$ is \\emph{uniquely determined} for all primes $q$. So $n$ has a \\emph{unique} prime factorization.\n\\end{proof}\n\n\\subsection{Greatest Common Divisors}\n\\begin{definition}\n    Let $R$ be an integral domain. Then $d\\in R$ is said to be a $\\gcd$ of two elements $a, b$ if\n    \\begin{enumerate}[i)]\n        \\item $d\\mid a$ and $d\\mid b$,\n        \\item if $d'\\mid a$ and $d'\\mid b$, then $d'\\mid d$.\n    \\end{enumerate}\n\\end{definition}\n\\begin{remark*}\n    An aside for ring theory enthusiasts: $\\gcd$ domains are a class of rings mroe general than PIDs or UFDs.\n\\end{remark*}\nWe will denote $(a, b)$ as the $\\gcd$ of $a$ and $b$.\n\n\\textbf{Caution, however!} $\\gcd$'s are only unique up to units.\n\n\\begin{example*}\n    $-5$ and $5$ are both $\\gcd$s of $-5$ and $10$ since $-1$ is a unit.\n\\end{example*}\n\nWe will make the convention that the $\\gcd$ of 2 integers is the positive $\\gcd$, that is, $(-5, 10) = 5$.\n\nAn edge case is that $\\gcd(0, 0)=0$.\n", "meta": {"hexsha": "c199679aa22675856a46aaa0e146c0a7f7628f9e", "size": 7754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-01.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-01.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-01.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.8641975309, "max_line_length": 365, "alphanum_fraction": 0.6550167655, "num_tokens": 2584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.766293653760418, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.6644040082181332}}
{"text": "\\section{Model Description}\n\nThe gravity effector module is responsible for calculating the effects of gravity from a body on a spacecraft. A spherical harmonics model and implementation is developed and described below. The iterative methods used for the software algorithms are also described. Finally, the results of the code unit tests are presented and discussed.\n\n\\subsection{Mathematical model}\n\n\\subsubsection{Relative Gravitational Dynamics Formulation}\n\nThe gravity effector module is critical to the propagation of spacecraft orbits in Basilisk. In order to increase the accuracy of spacecraft trajectories, a relative gravitational acceleration formulation can be used. Relative dynamics keep the acceleration, velocity, and distance magnitudes small, allowing more bits of a double variable to be used for accuracy, rather than magnitude. This additional accuracy is compounded via integration. This relative formulation is enforced when a user sets any planet in a multi-planet environment to have \\verb|isCentralBody = True|.\n\nIf no planets in a simulation are set as the central body, then an absolute formulation of gravitational acceleration is used. In the absolute formulation, acceleration of a spacecraft due to each massive body is summed directly to calculate the resultant acceleration of the spacecraft.\n\n\\begin{equation}\n\t\\ddot{\\bm{r}}_{B/N, \\mathrm{grav}} = \\sum_{i = 1}^{n} \\ddot{\\bm{r}}_{B/N, i}\n\\end{equation}\nwhere the accelerations on the right hand side are the acceleration due to the $i^{\\mathrm{th}}$ planet which is being modeled as a gravity body. In this absolute mode, spacecraft position and velocity are integrated with respect to the inertial origin, typically solar system barycenter.\n\nIn the relative formulation, the acceleration of the spacecraft is calculated \\textit{relative to} the central body. This is done by calculating the acceleration of the central body and subtracting it from the acceleration of the spacecraft.\n\n\\begin{equation}\n\t\\ddot{\\bm{r}}_{B/C, \\mathrm{grav}} =\\ddot{\\bm{r}}_{B/N, \\mathrm{grav}} - \\ddot{\\bm{r}}_{C/N, \\mathrm{grav}}\n\\end{equation}\n\nwhere $C$ is the central body. In this case, other accelerations of the central body (due to solar radiation pressure, for instance) are ignored.  For relative dynamics, the Basilisk dynamics integrator uses only \\textit{relative} acceleration to calculate \\textit{relative} position and velocity. The gravity module then accounts for this and modifies the spacecraft position and velocity by the central body's position and velocity after each timestep.\n\nThe above relative formulation leads to some questions regarding the accuracy of the dynamics integration. First, if acceleration due to gravity is being handled in a relative form, but accelerations due to external foces are handled absolutely, does Basilisk always produce the correct absolute position and velocity? Second, if dynamic state effectors such as hinged rigid bodies are using the gravitational acceleration that the spacecraft receives from the gravity module, are their states being integrated correctly?\n\nAbsolute accelerations (i.e. due to thrust) being integrated alongside the relative gravitational acceleration is handled easily due to the linearity of integration. In the absolute dynamics formulation there is:\n\n\\begin{equation}\n\t\\ddot{\\bm{r}}_{B/N} = \\ddot{\\bm{r}}_{B/N, \\mathrm{grav}}  + \\ddot{\\bm{r}}_{B/N, \\mathrm{thrust}} + \\ddot{\\bm{r}}_{B/N, \\mathrm{SRP}} + \\dots\n\t\\label{eq:absGrav}\n\\end{equation}\nand each term can be integrated separately on the right side so that\n\\begin{equation}\n      \\bm{r}_{B/N} = \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{grav}} \\mathrm{dtdt} +   \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{thrust}} \\mathrm{dtdt} +  \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{SRP}}\\mathrm{dt dt} +  \\dots\n\\end{equation}\nIn the derivation that follows, the double integral to position is used, but the logic holds for the first integral to velocity as well. Now, because accelerations also add linearly,\n\\begin{equation}\n\\ddot{\\bm{r}}_{B/N} = \\ddot{\\bm{r}}_{B/C} + \\ddot{\\bm{r}}_{C/N} = \\ddot{\\bm{r}}_{B/C, \\mathrm{grav}} +  \\ddot{\\bm{r}}_{C/N, \\mathrm{grav}}  + \\ddot{\\bm{r}}_{B/N, \\mathrm{thrust}} + \\ddot{\\bm{r}}_{B/N, \\mathrm{SRP}} + \\dots\n\\end{equation}\nwhich differs from Eq. \\ref{eq:absGrav} in the gravitational acceleration of the spacecraft being split at the acceleration of the central body. Applying the integrals:\n\\begin{equation}\n\\bm{r}_{B/N} = \\bm{r}_{B/C} + \\bm{r}_{C/N} = \\int \\int \\ddot{\\bm{r}}_{B/C, \\mathrm{grav}} \\mathrm{dt dt} + \\bm{r}_{C/N}  +   \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{thrust}} \\mathrm{dt dt} +  \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{SRP}}\\mathrm{dt dt} +  \\dots\n\\end{equation}\nwhere $\\ddot{\\bm{r}}_{C/N}$ is deliberately double integrated to $\\bm{r}_{C/N}$ to show that it can be removed from both sides and $\\bm{r}_{B/C}$ can be evaluated using relative gravitation acceleration combined with absolute accelerations due to external forces:\n\\begin{equation}\n\\bm{r}_{B/C}= \\int \\int \\ddot{\\bm{r}}_{B/C, \\mathrm{grav}} \\mathrm{dt dt} +   \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{thrust}} \\mathrm{dt dt} +  \\int \\int \\ddot{\\bm{r}}_{B/N, \\mathrm{SRP}}\\mathrm{dt dt} +  \\dots\n\\end{equation}\nOnce that is done, it is clear that the absolute position can be found by simply adding the position of the central body to the relative position just found:\n\\begin{equation}\n\t\\bm{r}_{B/N} = \\bm{r}_{B/C} + \\bm{r}_{C/N}\n\\end{equation}\nThis is how absolute position and velocity are found in Basilisk when using a relative dynamics formulation: the relative dynamics are integrated and the position and velocity of the central body are added afterward. The position and velocity of the central body are not integrated by Basilisk, but found from Spice.\n\nDynamic state effectors connected to the spacecraft hub can use the relative gravitational acceleration in their calculation for much the same reason. Effector positions and velocities are always integrated relative to the spacecraft. In fact, the absolute position and velocity of an effector is rarely, if ever, calculated or used. This is explains why a hinged body experiencing a relative acceleration does not quickly fall behind the spacecraft which is known to be moving along a course experiencing absolute gravitational acceleration. Additionally, because the effector is \"pulled along\" with the spacecraft when the spacecraft position is modified by the central body position, the effector sees the effect of absolute gravitational acceleration as well.\n\nFor intricacies related to using absolute vs relative dynamics, see the user manual at the end of this document.\n\n\\subsubsection{Gravity models}\n\nGravity models are usually based on solutions of the Laplace equation ($\\nabla^2 U(\\mathbf{\\bar r}) = 0$). It is very important to state that this equation only models a gravity potential outside a body. For computing a potential inside a body the Poisson equation is used instead.\n\nThe spherical harmonic potential is a solution of the Laplace equation using orthogonal spherical harmonics. It can be derived solving the Laplace equation in spherical coordinates, using the separation of variables technique and solving a Sturm-Liouville problem. In this work, the solution will be found using another technique, which essentially follows Vallado's book\\cite{vallado2013}.\n\nFor each element of mass $d m_\\text{Q}$ the potential can be written as\n\\begin{equation}\n\\D U(\\mathbf{\\bar r}) = G \\frac{\\D m_\\text{Q}}{\\rho_\\text{Q}}\n\\end{equation}\n\nwhere $\\rho_\\text{Q}$ is the distance between the element of mass and the position vector $\\mathbf{\\bar r}$ where the potential is computed. This position vector is usually given in a body-fixed frame. The relation between the position vector $\\mathbf{\\bar r}$, the position of the element of mass $\\mathbf{\\bar r_\\text{Q}}$ and $\\rho_\\text{Q}$ can be given using the cosine theorem and the angle $\\alpha$ between the two position vectors, as can be appreciated in Figure \\ref{fig:spher_harm}.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.3\\textwidth]{Figures/spherical_harmonics.png}\n\t\\caption{Geometry of the Spherical Harmonics Representation.}\\label{fig:spher_harm}\n\\end{figure}\n\n\\begin{equation}\n\\rho_\\text{Q} = \\sqrt{r^2 + r_\\text{Q}^2 - 2 r r_\\text{Q} \\cos(\\alpha)} = r \\sqrt{1 - 2 \\frac{r_\\text{Q}}{r} \\cos(\\alpha) + \\bigg(\\frac{r_\\text{Q}}{r}\\bigg)^2} = r \\sqrt{1 - 2 \\gamma \\cos(\\alpha) + \\gamma^2}\n\\end{equation}\nwhere $\\gamma = r_\\text{Q}/r$.\n\nThe potential can be obtained by integrating $dU$ through the whole body.\n\\begin{equation}\nU(\\mathbf{\\bar r}) = G \\int_{body} \\frac{\\D m_\\text{Q}}{r \\sqrt{1 - 2 \\gamma \\cos(\\alpha) + \\gamma^2}}\n\\end{equation}\n\nIf the potential is computed outside the body, $\\gamma$ will always be less than 1, and the inverse of the square root can be approximated using the Legendre polynomials $P_l[\\beta]$\\cite{vallado2013}. Even though this derivation does not use the Laplace equation, it still assumes that the potential is computed outside the body.\n\nThe Legendre polynomials can be written as\n\\begin{equation}\nP_l[\\beta] = \\frac{1}{2^l l!} \\frac{d^l}{d \\beta^l} (\\beta^2 - 1)^l\n\\end{equation}\n\nThe potential is\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{G}{r} \\int_{body} \\sum_{l=0}^\\infty \\gamma^l P_l[\\cos(\\alpha)] \\D m_\\text{Q}\n\\end{equation}\n\nThe angle $\\alpha$ must be integrated. However, the cosine of the angle $\\alpha$ can be decomposed using the geocentric latitude and the longitude associated to vectors $\\mathbf{\\bar r}$ and $\\mathbf{\\bar r_\\text{Q}}$. These angles will be called $(\\phi, \\lambda)$ and $(\\phi_\\text{Q}, \\lambda_\\text{Q})$ respectively. Using the addition theorem it is possible to write\\cite{vallado2013}.\n\\begin{equation}\nP_l[cos(\\alpha)] = P_l[\\sin(\\phi_\\text{Q})] P_l[\\sin(\\phi)] + 2 \\sum_{m=1}^l \\frac{(l-m)!}{(l+m)!} (a_{l,m} a'_{l,m} + b_{l,m} b'_{l,m})\n\\end{equation}\n\nwhere\n\\begin{align}\n\ta_{l,m} &= P_{l,m}[\\sin(\\phi_\\text{Q})] \\cos(m \\lambda_\\text{Q})\\\\\n\tb_{l,m} &= P_{l,m}[\\sin(\\phi_\\text{Q})] \\sin(m \\lambda_\\text{Q})\\\\\n\ta'_{l,m} &= P_{l,m}[\\sin(\\phi)] \\cos(m \\lambda)\\\\\n\tb'_{l,m} &= P_{l,m}[\\sin(\\phi)] \\sin(m \\lambda)\n\\end{align}\n\nwhere $P_{l,m}[x]$ are the associated Legendre functions. \"$l$\" is called degree and \"$m$\", order. The polynomials can be computed as\n\\begin{equation}\nP_{l,m}[\\beta] = (1 - \\beta^2)^\\frac{m}{2} \\frac{d^m}{d \\beta^m} P_l[\\beta]\\label{eq:legendre}\n\\end{equation}\n\nAs can be seen, $a_{l,m}$ and $b_{l,m}$ must be integrated, but $a'_{l,m}$ and $a'_{l,m}$ can be taken outside the integral.\nTherefore, it is possible to define\n\\begin{align}\n\tC'_{l,m} &= \\int_{body} (2 -\\delta_m) r_\\text{Q}^l \\frac{(l-m)!}{(l+m)!} a_{l,m} \\D m_\\text{Q}\\\\\n\tS'_{l,m} &= \\int_{body} (2 -\\delta_m) r_\\text{Q}^l \\frac{(l-m)!}{(l+m)!} b_{l,m} \\D m_\\text{Q}\n\\end{align}\nwhere $\\delta_m$ is the Kronecker delta.\n\nThen\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{G}{r} \\sum_{l=0}^\\infty C'_{l,0} \\frac{P_l[\\sin(\\phi)]}{r^l} + \\frac{G}{r} \\sum_{l=0}^\\infty \\sum_{m=1}^l \\frac{P_{l,m}[\\sin(\\phi)]}{r^l} \\big[C'_{l,m} \\cos(m \\lambda) + S'_{l,m} \\sin(m \\lambda)]\n\\end{equation}\n\nNon-dimensional coefficients $C_{l,m}$ and $S_{l,m}$ are usually used\n\\begin{align}\n\tC'_{l,m} &= C_{l,m} R_{\\text{ref}}^l m_\\text{Q}\\\\\n\tS'_{l,m} &= _\\text{CoM}S_{l,m} R_{\\text{ref}}^l m_\\text{Q}\n\\end{align}\nwhere $m_\\text{Q}$ is the total mass of the body and $R_{\\text{ref}}$ is a reference radius. If the coefficients $C_{l,m}$ and $S_{l,m}$ are given, the reference radius must be specified. Usually, the reference is chosen as the maximum radius or the mean radius\\cite{scheeres2012}.\n\nThe potential is then\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{\\mu}{r} \\sum_{l=0}^\\infty C_{l,0} \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l P_l[\\sin(\\phi)] + \\frac{\\mu}{r} \\sum_{l=0}^\\infty \\sum_{m=1}^l \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l P_{l,m}[\\sin(\\phi)] \\big[C_{l,m} \\cos(m \\lambda) + S_{l,m} \\sin(m \\lambda)\\big]\n\\end{equation}\n\nSince $P_l[x] = P_{l,0}[x]$ the potential can be written in a more compact way\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{\\mu}{r} \\sum_{l=0}^\\infty \\sum_{m=0}^l \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l P_{l,m}[\\sin(\\phi)] \\big[C_{l,m} \\cos(m \\lambda) + S_{l,m} \\sin(m \\lambda)\\big]\n\\end{equation}\n\nSome coefficients have a very interesting interpretation. \n\\begin{align}\n\tC_{0,0} &= 1\\\\\n\tS_{l,0} &= 0 \\quad \\forall l \\geq 0\\\\\n\tC_{1,0} &= \\frac{Z_{\\text{CoM}}}{R_{\\text{ref}}}\\\\\n\tC_{1,1} &= \\frac{X_{\\text{CoM}}}{R_{\\text{ref}}}\\\\\n\tS_{1,1} &= \\frac{Y_{\\text{CoM}}}{R_{\\text{ref}}}\n\\end{align}\n\nwhere $[X_\\text{CoM}, Y_\\text{CoM}, Z_\\text{CoM}]$ represents the center of mass of the celestial body. Therefore, if the origin of the coordinate system coincides with the center of mass, all these coefficients are identically zero. Similarly, the second order coefficients are related to the second order moments (moments of inertia).\n\nFinally, the coefficients and Legendre polynomials are usually normalized to avoid computational issues. The factor $N_{l,m}$ is called the normalization factor\n\\begin{equation}\nN_{l,m} = \\sqrt{\\frac{(l-m)! (2 -\\delta_m) (2 l +1)}{(l+m)!}}\n\\end{equation}\n\nThe normalized coefficients are\n\\begin{align}\n\t\\bar C_{l,m} &= \\frac{C_{l,m}}{N_{l,m}}\\\\\n\t\\bar S_{l,m} &= \\frac{S_{l,m}}{N_{l,m}}\n\\end{align}\n\nThe normalized associated Legendre functions are\n\\begin{equation}\n\\bar P_{l,m}[x] = P_{l,m}[x] N_{l,m}\n\\end{equation}\n\nThe potential may be written as\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{\\mu}{r} \\sum_{l=0}^\\infty \\sum_{m=0}^l \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l \\bar P_{l,m}[\\sin(\\phi)] \\big[\\bar C_{l,m} \\cos(m \\lambda) + \\bar S_{l,m} \\sin(m \\lambda)\\big]\n\\end{equation}\n\n\\subsubsection{Pines' Representation of Spherical Harmonics Gravity}\n\nThere are many ways to algorithmically compute the potential and its first and secondary derivatives. One of such algorithms is the one proposed by Pines\\cite{pines1973}.\n\nThe spherical harmonics representation as it was presented has a singularity at the poles for the gravity field. The Pines' formulation avoids this problem and is more numerically stable for high degree and high order terms.\n\nUnfortunately, this formulation does not contain the normalization factor which is necessary if the coefficients are normalized. In a paper written by Lundberg and Schutz\\cite{lundberg1988}, a normalized representation of the Pines' formulation is given, but it contains an approximation.\n\nFor this work, and in order to code the spherical harmonics formulation, a formulation similar to Pines' using the Lundberg-Schutz paper will be derived. However, no approximations will be used. Therefore, the algorithm will be developed here without using the exact formulations given in those papers. For the sake of brevity, not every single derivation will be carried out, but it is possible to get the results following the expressions obtained in this section.\n\nIn the Pines' formulation the radius and the director cosines are used as coordinates. The potential will be given as $U[r, s, t, u]$, where\n\\begin{align}\n\tr &= \\sqrt{x^2+y^2+z^2}\\\\\n\ts &= \\frac{x}{r}\\\\\n\tt &= \\frac{y}{r}\\\\\n\tu &= \\frac{z}{r}\n\\end{align}\n\nFor a function of these coordinates, the dependance will be given using square brackets (e.g. $f[r,s,t,u]$).\n\nSince $u = \\sin(\\phi) = \\cos(90^\\circ - \\phi)$, it is possible to write\n\\begin{equation}\nP_{l,m}[\\sin(\\phi)] = P_{l,m}[u]\n\\end{equation}\n\nThe derived Legendre functions $A_{l,m}[u]$ are defined such that\n\\begin{equation}\nP_{l,m}[u] = (1 - u^2)^\\frac{m}{2} A_{l,m}[u]\n\\end{equation}\n\nFrom the definition of $P_{l,m}$ (Equation \\refeq{eq:legendre}), it is possible to write\n\\begin{equation}\nA_{l,m}[u] = \\frac{d^m}{d u^m} P_l[u] = \\frac{1}{2^l l!} \\frac{d^{l+m}}{d u^{l+m}} (u^2 - 1)^l\\label{eq:der_leg}\n\\end{equation}\n\nThe term $(1 - u^2)^\\frac{m}{2}$ can be written as $(1 - \\sin^2(\\phi))^\\frac{m}{2} = |\\cos(\\phi)|^m = \\cos^m(\\phi)$.\n\nIf the complex number $\\xi$ is defined such that ($j$ is the imaginary unit)\n\\begin{equation}\n\\xi = \\cos(\\phi) \\cos(\\lambda) + j \\cos(\\phi) \\sin(\\lambda) = \\frac{x}{r} + j \\frac{y}{r} = s + j t\n\\end{equation}\n\nit is possible to write\n\\begin{equation}\n\\xi^m = \\cos^m(\\phi) e^{j m \\lambda} = (s + j t)^m\n\\end{equation}\n\nThe following sequences may be defined\n\\begin{align}\n\tR_m[s,t] &= Re\\{\\xi^m\\}\\\\\n\tI_m[s,t] &= Im\\{\\xi^m\\}\n\\end{align}\n\nPutting all together, it is possible to write\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{\\mu}{r} \\sum_{l=0}^\\infty \\sum_{m=0}^l \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l A_{l,m}[u] \\{C_{l,m} R_m[s,t] + S_{l,m} I_m[s,t]\\}\n\\end{equation}\n\nIn order to normalize the coefficients ($\\bar C_{l,m}$ and $\\bar S_{l,m}$) and the derived Legendre functions ($\\bar A_{l,m} = N_{l,m} A_{l,m}$), each term is divided an multiplied by the normalization factor $N_{l,m}$. Then\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\frac{\\mu}{r} \\sum_{l=0}^\\infty \\sum_{m=0}^l \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l \\bar A_{l,m}[u] \\{\\bar C_{l,m} R_m[s,t] + \\bar S_{l,m} I_m[s,t]\\}\n\\end{equation}\n\nThe sets $D_{l,m}[s,t]$, $E_{l,m}[s,t]$, and $F_{l,m}[s,t]$, are defined as\n\\begin{align}\n\tD_{l,m}[s,t] &= \\bar C_{l,m} R_m[s,t] + \\bar S_{l,m} I_m[s,t]\\\\\n\tE_{l,m}[s,t] &= \\bar C_{l,m} R_{m-1}[s,t] + \\bar S_{l,m} I_{m-1}[s,t]\\\\\n\tF_{l,m}[s,t] &= \\bar S_{l,m} R_{m-1}[s,t] - \\bar C_{l,m} I_{m-1}[s,t]\n\\end{align}\n\nThe value $\\rho_l[r]$ is also defined as\n\\begin{equation}\n\\rho_l[r] = \\frac{\\mu}{r} \\bigg(\\frac{R_{\\text{ref}}}{r}\\bigg)^l\n\\end{equation}\n\nThe gravity potential may be finally computed as\n\\begin{equation}\nU(\\mathbf{\\bar r}) = \\sum_{l=0}^\\infty \\sum_{m=0}^l \\rho_l[r] \\bar A_{l,m}[u] D_{l,m}[s,t]\n\\end{equation}\n\nThis is the final expression that will be used to compute the gravity potential.\n\n\\subsubsection{Recursion Formulas}\n\nSeveral recursion formulas are needed in order to algorithmically implement the Pines' formulation. They will be given without proof, but they are easily derived using the definitions above.\n\\begin{itemize}\n\n\n\\item{Recursion formula for $\\rho_l[r]$}\n\nInitial condition: $\\rho_0[r] = \\frac{\\mu}{r}$\n\\begin{equation}\n\\rho_l[r] = \\rho \\cdot \\rho_{l-1}[r]\n\\end{equation}\nwhere $\\rho = R_{\\text{ref}}/r$.\n\n\\item{Recursion formula for $R_m[s,t]$}\n\nInitial condition: $R_0[s,t] = 1$\n\\begin{equation}\nR_m[s,t] = s R_{m-1}[s,t] - t I_{m-1}[s,t]\n\\end{equation}\n\n\\item{Recursion formula for $I_m[s,t]$}\n\nInitial condition: $I_0[s,t] = 0$\n\\begin{equation}\nI_m[s,t] = s I_{m-1}[s,t] + t R_{m-1}[s,t]\n\\end{equation}\n\n\\item{Recursion formula for $\\bar A_{l,m}[u]$}\n\nFrom Equation \\eqref{eq:der_leg}, it is possible to see that\n\\begin{align}\n\tA_{l,l}[u] &= (2 l -1) A_{l-1,l-1}[u]\\label{eq:All}\\\\\n\tA_{l,l-1}[u] &= u A_{l,l}[u]\\label{eq:All_1}\n\\end{align}\n\\end{itemize}\nThere are several recursion formulas for computing Legendre polynomials $A_{l,m}[u]$, for $m < l-1$. The following formula, which is stable for high degrees\\cite{lundberg1988}, will be used:\n\\begin{equation}\nA_{l,m}[u] = \\frac{1}{l-m} ((2 l -1) u A_{l-1,m}[u] - (l+m-1) A_{l-2,m}[u])\\label{eq:Alm}\n\\end{equation}\n\nUsing Equations \\eqref{eq:All}, \\eqref{eq:All_1}, and \\eqref{eq:Alm}, and the definition $\\bar A_{l,m}[u] = N_{l,m} A_{l,m}[u]$, the following recursion formulas can be derived.\n\nInitial condition: $\\bar A_{0,0}[u] = 1$\n\nThe diagonal terms are computed as\n\\begin{equation}\n\\bar A_{l,l}[u] = \\sqrt{\\frac{(2 l - 1) (2 - \\delta_l)}{(2 l) (2 - \\delta_{l-1})}} \\bar A_{l-1,l-1}[u]\n\\end{equation}\n\nThe low diagonal terms are then calculated as\n\\begin{equation}\n\\bar A_{l,l-1}[u] = u \\sqrt{\\frac{(2 l) (2 - \\delta_{l-1})}{2 - \\delta_l}} \\bar A_{l,l}[u]\n\\end{equation}\n\nFinally, for $l \\geq (m+2)$, $N1_{l,m}$ and $N2_{l,m}$ are defined such that\n\\begin{align}\n\tN1_{l,m} &= \\sqrt{\\frac{(2 l + 1) (2 l - 1)}{(l - m) (l + m)}}\\\\\n\tN2_{l,m} &= \\sqrt{\\frac{(l + m - 1) (2 l + 1) (l - m -1)}{(l - m) (l + m) (2 l - 3)}}\n\\end{align}\n\nand $\\bar A_{l,m}[u]$ computed using\n\n\\begin{equation}\n\\bar A_{l,m}[u] = u N1_{l,m} \\bar A_{l-1,m}[u] - N2_{l,m} \\bar A_{l-2,m}[u]\n\\end{equation}\n\n\n\\subsubsection{Derivatives}\n\nThe first order derivatives of many of the values given are necessary to compute the gravity field (second order derivatives are needed if the Hessian is to be computed).\n\nIt is easy to show that\n\\begin{align}\n\t\\frac{\\partial D_{l,m}}{\\partial s}[s,t] &= m E_{l,m}[s,t]\\\\\n\t\\frac{\\partial D_{l,m}}{\\partial t}[s,t] &= m F_{l,m}[s,t]\n\\end{align}\n\n\\begin{equation}\n\\frac{d \\rho_l}{d r}[r] = -\\frac{(l+1)}{R_{\\text{ref}}} \\rho_{l+1}[r]\n\\end{equation}\n\n\\begin{align}\n\t\\frac{\\partial R_m}{\\partial s}[s,t] &= m R_{m-1}[s,t]\\\\\n\t\\frac{\\partial R_m}{\\partial t}[s,t] &= -m I_{m-1}[s,t]\\\\\n\t\\frac{\\partial I_m}{\\partial s}[s,t] &= m I_{m-1}[s,t]\\\\\n\t\\frac{\\partial I_m}{\\partial t}[s,t] &= m R_{m-1}[s,t]\n\\end{align}\n\n\\begin{equation}\n\\frac{d \\bar A_{l,m}}{d u}[u] = \\frac{N_{l,m}}{N_{l,m+1}} \\bar A_{l,m+1}[u]\n\\end{equation}\n\nThe gravity field can be computed using all the equations given. However, the gradient of the potential is needed. As a change of variables was realized, the chain rule must be applied. In order to avoid filling up pages with math derivations, the results will be given. With patience, the following results can be obtained applying the chain rule and using all the derivatives given.\n\nThe gravity field can be computed as\n\\begin{equation}\n\\mathbf{\\bar g} = (a_1[r,s,t,u] + s \\cdot a_4[r,s,t,u]) \\mathbf{\\hat i} + (a_2[r,s,t,u] + t \\cdot a_4[r,s,t,u]) \\mathbf{\\hat j} + (a_3[r,s,t,u] + u \\cdot a_4[r,s,t,u]) \\mathbf{\\hat k}\n\\end{equation}\n\nwhere\n\\begin{align}\n\ta_1[r,s,t,u] &= \\sum_{l=0}^\\infty \\sum_{m=0}^l \\frac{\\rho_{l+1}[r]}{R_{\\text{ref}}} m \\bar A_{l,m}[u] E_{l,m}[s,t]\\\\\n\ta_2[r,s,t,u] &= \\sum_{l=0}^\\infty \\sum_{m=0}^l \\frac{\\rho_{l+1}[r]}{R_{\\text{ref}}} m \\bar A_{l,m}[u] F_{l,m}[s,t]\\\\\n\ta_3[r,s,t,u] &= \\sum_{l=0}^\\infty \\sum_{m=0}^l \\frac{\\rho_{l+1}[r]}{R_{\\text{ref}}} m \\frac{N_{l,m}}{N_{l,m+1}} \\bar A_{l,m+1}[u] D_{l,m}[s,t]\\\\\n\ta_4[r,s,t,u] &= \\sum_{l=0}^\\infty \\sum_{m=0}^l \\frac{\\rho_{l+1}[r]}{R_{\\text{ref}}} m \\frac{N_{l,m}}{N_{l+1,m+1}} \\bar A_{l+1,m+1}[u] D_{l,m}[s,t]\n\\end{align}\n\nIn order to avoid computing factorials, it is easy to see that\n\\begin{align}\n\t\\frac{N_{l,m}}{N_{l,m+1}} &= \\sqrt{\\frac{(l-m) (2-\\delta_m)(l+m+1)}{2- \\delta_{m+1}}}\\\\\n\t\\frac{N_{l,m}}{N_{l+1,m+1}} &= \\sqrt{\\frac{(l+m+2)(l+m+1)(2l+1)(2-\\delta_m)}{(2l+3)(2-\\delta_{m+1})}}\n\\end{align}\n\nUsing all these expressions, the potential and the gravity field can be computed.\n\n\\subsubsection{Simple Gravity}\n\"Simple Gravity\", or gravitational potential and acceleration without taking spherical harmonics into account, is equivalent to using only the $0\\sup{th}$ term of the spherical harmonics equations. This is the equation that is used in basics physics courses and is most often used in Basilisk simulations. It assumes the gravitational body to be a point mass:\n\n\\begin{equation}\nU(\\mathbf{\\bar r}) = G \\frac{ m_\\text{Q}}{\\rho_\\text{Q}}\n\\end{equation}\n", "meta": {"hexsha": "70c994847fbea522b28cd9548e39d426162e4d3d", "size": 22839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/dynamics/gravityEffector/_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/gravityEffector/_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/gravityEffector/_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": 59.3220779221, "max_line_length": 763, "alphanum_fraction": 0.6939883533, "num_tokens": 7630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6644039818094712}}
{"text": "\\documentclass{article}\n\\usepackage[letterpaper, margin=1in]{geometry}\n\\usepackage[version=4]{mhchem}\n\\usepackage{amsmath}\n\\usepackage{systeme,mathtools}\n\\usepackage{url}\n\\setcounter{MaxMatrixCols}{20}\n\n\\let\\oldquote\\quote\n\\let\\endoldquote\\endquote\n\\renewenvironment{quote}[2][]\n{\\if\\relax\\detokenize{#1}\\relax\n\t\\def\\quoteauthor{#2}%\n\t\\else\n\t\\def\\quoteauthor{#2~---~#1}%\n\t\\fi\n\t\\oldquote}\n{\\par\\nobreak\\smallskip\\hfill(\\quoteauthor)%\n\t\\endoldquote\\addvspace{\\bigskipamount}}\n\\begin{document}\n\t\\title{(Ab)Using Linear Algebra to Balance Chemical Reaction Equations \\\\\\& \\\\  A Love Letter to Mathematics}\n\t\\author{Liang Wang}\n\t\\date{\\today}\n\t\\maketitle\n\t\n\t\\section{Mechanical Processes Should be Mechanical}\n\tBalancing chemical reaction equations is often taught as an imprecise process that involves lots of idiosyncratic tricks. While trying to balance them by hand is usually doable when the reaction is relatively simple, the process becomes less straightforward when more complex reactions are presented.\n\t\n\tHowever, balancing should be a fairly boring and mechanical process, and \\emph{mechanical processes should be mechanical}. Using linear algebra, we could balance any arbitrary reactions without the need for tricks, instead, the process becomes simple and repeatable.\n\t\n\t\\section{Abusing Linear Algebra to do Simple Math}\n\tThe goal of balancing chemical equations is to find the appropriate coefficients such that the number of each molecule is the same for the reactants and the products. The word `balancing' should remind you of solving equations, where equality is preserved as long as the operation is done to both sides of equations.\n\t\n\tIndeed, balancing chemical equations is just solving systems of linear equations. Solving a system of linear equations by substitution is often tedious and error-prone. Fortunately, linear algebra provides us with simpler ways of solving such problems. \n\t\n\t\\subsection{Homogeneous Systems}\n\tIn linear algebra, a homogeneous system refers to a equation with the form $A\\vec{x} = \\vec{0}$, where $A$ is a $m \\times n$ matrix and $\\vec{0}$ is the zero vector. When $m = n$, i.e.\\ the matrix $A$ is square, the system has infinite non-trivial solutions if  $\\mathrm{det}(A) \\neq 0$. When the matrix is rank-deficient, there are infinite non-trivial solutions. \n\t\n\t\\section{Simple Example}\n\tThe following\\footnote{Taken from \\url{http://myweb.astate.edu/mdraganj/BalanceEqn.html}} is an example of an unbalanced chemical equation that might require so time to solve.\n\t\\begin{center}\n\t\t\\ce{S + HNO3 -> H2SO4 + NO2 + H2O}\n\t\\end{center}\n\tThe complexity lies in that the number of reactants does not equate to the number of products. We shall see how linear algebra simplifies the process.\n\t\n\tWe assign each $x_i$ to each compound that appears in the equation from left to right. Hence we have the following system of equations.\n\t\\begin{equation*}\n\t\\ce{$x_1$S + $x_2$HNO3 -> $x_3$H2SO4 + $x_4$NO2 + $x_5$H2O} \\implies\n\t\\left\\{\n\t\\quad\n\t\\begin{aligned}\n\tx_1  &= x_3 &&\\text{Sulphur}\\\\\n\tx_2  &= 2x_3 + 2x_5 &&\\text{Hydrogen}\\\\\n\tx_2  &= x_4 &&\\text{Nitrogen}\\\\\n\t3x_2 &= 4x_3 + 2x_4 + x_5 &&\\text{Oxygen} \\\\\n\t\\end{aligned}\n\t\\right.\n\t\\end{equation*}\n\tWhich is equivalent to the following matrix.\n\t\\begin{equation*}\n\t\\begin{bmatrix} \n\t1 &  0 & -1 &  0 &  0 \\\\\n\t0 &  1 & -2 &  0 & -2 \\\\\n\t0 &  1 &  0 & -1 &  0 \\\\\n\t0 &  3 & -4 & -2 & -1 \\\\\n\t\n\t\\end{bmatrix}\n\t\\end{equation*}\n\tFinding the solution set entails finding the null space basis vectors. After row operations, we get the row reduced echelon form to be.\n\t\n\t\\begin{equation*}\n\t\\begin{bmatrix}\n\t1 &\t0\t&0&\t0\t&-0.5 \\\\ \n\t0 &\t1\t&0&\t0\t&-3 \\\\\n\t0 &\t0\t&1&\t0\t&-0.5 \\\\\n\t0&\t0\t&0&\t1\t&-3 \\\\\n\t\n\t\\end{bmatrix} \n\t\\end{equation*}\n\tMeaning that there is only one free variable, $x_5$.\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\begin{bmatrix}\n\tx_1 \\\\\n\tx_2 \\\\\n\tx_3 \\\\\n\tx_4 \\\\\n\tx_5 \\\\\n\t\\end{bmatrix} = \n\t\\begin{bmatrix}\n\t0.5x_5 \\\\ \n\t3x_5 \\\\\n\t0.5x_3 \\\\ \n\t3x_5 \\\\\n\tx_5 \\\\\n\t\\end{bmatrix} = \n\tx_5\n\t\\begin{bmatrix}\n\t0.5 \\\\ \n\t3 \\\\\n\t0.5 \\\\ \n\t3 \\\\\n\t1\\\\\n\t\\end{bmatrix}\n\t\\end{split}\n\t\\end{equation*}\n\tSince we want integer solutions, and $0.5x_5$ is a entry for our basis vector, we pick $x_5 = 2$ to get the smallest possible positive solution. \n\t$$ \\mathrm{solution} = \n\t\\begin{bmatrix}\n\t1 \\\\\n\t6 \\\\\n\t1 \\\\\n\t6 \\\\\n\t2 \\\\\n\t\\end{bmatrix}\n\t$$\n\tMeaning, \\ce{S + 6HNO3 -> H2SO4 + 6NO2 + 2H2O}. We see this is indeed the desired solution.\n\t\n\t\\section{Complex Example}\n\tOne can say the previous example is still relatively easy and can be attempted without the use of matrices. The section provides a complex example\\footnote{Taken from \\url{https://www.chembuddy.com/?left=balancing-stoichiometry-questions&right=balancing-questions}} where doing it by hand is borderline torture.\n\t\\begin{center}\n\t\t\\ce{K4[Fe(SCN)6] + K2Cr2O7 + H2SO4 -> Fe2(SO4)3 + Cr2(SO4)3 + CO2 + H2O + K2SO4 + KNO3}\n\t\\end{center}\n\tAs usual, we assign $x_i$ to be the coefficient of each compounds from left to right. We obtain the following system of equations.\n\t\\begin{equation*}\n\t\\left\\{\n\t\\quad\n\t\\begin{aligned}\n\t4x_1 + 2x_2 - 2x_8  - x_9&= 0 &&\\text{Potassium}\\\\\n\tx_1 - 2x_4          &= 0 &&\\text{Iron}\\\\\n\t6x_1 + x_3- 3x_4 - 3x_5 - x_8  &= 0 &&\\text{Sulphur}\\\\\n\t6x_1 - x_6          &= 0 &&\\text{Carbon} \\\\\n\t6x_1 - x_9          &= 0 &&\\text{Nitrogen}\\\\\n\t2x_2 - 2x_5         &= 0 &&\\text{Chromium}\\\\\n\t7x_2 + 4x_3 - 12x_4 - 12x_5 - 2x_6 -x_7 - 4x_8 - 3x_9 &= 0 &&\\text{Oxygen} \\\\\n\t2x_3 - 2x_7 &= 0 && \\text{Hydrogen} \\\\\n\t\\end{aligned}\n\t\\right.\n\t\\end{equation*}\n\tConverting it to matrix form gives us the following.\n\t$$\n\t\\begin{bmatrix}\n\t4   &       2  &        0    &      0   &       0   &       0   &       0 &        -2  &        -1 \\\\\n\t1   &       0  &        0    &     -2   &       0   &       0   &       0 &         0  &        0\\\\\n\t6   &       0  &        1    &     -3   &      -3   &       0   &       0 &        -1  &        0\\\\\n\t6   &       0  &        0    &      0   &       0   &      -1   &       0 &         0  &        0\\\\\n\t6   &       0  &        0    &      0   &       0   &       0   &       0 &         0  &       -1\\\\\n\t0   &       2  &        0    &      0   &      -2   &       0   &       0 &         0  &        0\\\\\n\t0   &       7  &        4    &    -12   &     -12   &      -2   &      -1 &        -4  &       -3\\\\\n\t0   &       0  &        2    &      0   &       0   &       0   &      -2 &         0  &        0\\\\\n\t\\end{bmatrix}\n\t$$\n\tWe simplify the matrix to its row reduced echelon form.\n\t$$\n\t\\begin{bmatrix}\n\t1   &       0     &     0   &       0  &        0    &      0   &       0    &      0  &     -1/6\\\\\n\t0   &       1     &     0   &       0  &        0    &      0   &       0    &      0  &   -97/36\\\\\n\t0   &       0     &     1   &       0  &        0    &      0   &       0    &      0  &  -355/36\\\\\n\t0   &       0     &     0   &       1  &        0    &      0   &       0    &      0  &    -1/12\\\\\n\t0   &       0     &     0   &       0  &        1    &      0   &       0    &      0  &   -97/36\\\\\n\t0   &       0     &     0   &       0  &        0    &      1   &       0    &      0  &       -1\\\\\n\t0   &       0     &     0   &       0  &        0    &      0   &       1    &      0  &  -355/36\\\\\n\t0   &       0     &     0   &       0  &        0    &      0   &       0    &      1  &   -91/36\\\\\n\t\\end{bmatrix}\n\t$$\n\tWe write the null space basis vector in terms of our one free variable, $x_9$.\n\t\\begin{equation*}\n\t\\begin{bmatrix}\n\tx_1 \\\\\n\tx_2 \\\\\n\tx_3 \\\\\n\tx_4 \\\\\n\tx_5 \\\\\n\tx_6 \\\\\n\tx_7 \\\\\n\tx_8 \\\\\n\tx_9 \\\\\n\t\\end{bmatrix}\n\t= \n\tx_9\n\t\\begin{bmatrix}\n\t1/6 \\\\\n\t97/36 \\\\\n\t355/36 \\\\\n\t1/12\\\\\n\t97/36\\\\\n\t1\\\\\n\t355/36\\\\\n\t91/36\\\\\n\t1 \\\\\n\t\\end{bmatrix}\n\t\\end{equation*}\n\tWe pick $x_9$ to the be the inverse of the least common factor, $\\mathrm{lcm}\\left(\\dfrac{1}{6},\\: \\dfrac{97}{36},\\: \\dfrac{355}{36},\\: \\dfrac{1}{12},\\: \\dfrac{97}{36},\\: 1,\\: \\dfrac{355}{36},\\: \\dfrac{91}{36},\\: 1\\right)^{-1} = 36$. We obtain the solution set of:\n\t\\begin{equation*}\n\t\\mathrm{solution} = \n\t\\begin{bmatrix}\n\t6 \\\\\n\t97 \\\\\n\t355 \\\\\n\t3 \\\\\n\t97 \\\\\n\t36 \\\\\n\t355 \\\\\n\t91 \\\\\n\t36 \\\\\n\t\\end{bmatrix}\n\t\\end{equation*}\n\tHenceforth, the complex reaction is as follows:\n\t\\begin{center}\n\t\t\\ce{6 K4[Fe(SCN)6] + 97 K2Cr2O7 + 355 H2SO4 -> 3 Fe2(SO4)3 + 97 Cr2(SO4)3 + 36 CO2 + 355 H2O + 91 K2SO4 + 36 KNO3}\n\t\\end{center}\n\tFeel free to verify the result using the \\emph{magic of internet}.\n\t\n\t\\section{A Love Letter to Mathematics}\n\t\\begin{quote}{Henri Poincaré}\n\t\tThe scientist does not study nature because it is useful to do so. He studies it because he takes pleasure in it, and he takes pleasure in it because it is beautiful. If nature were not beautiful it would not be worth knowing, and life would not be worth living\n\t\\end{quote}\n\t\n\t\\begin{quote}{Richard Dawkins}\n\t\tAfter sleeping through a hundred million centuries we have finally opened our eyes on a sumptuous planet, sparkling with colour, bountiful with life. Within decades we must close our eyes again. Isn’t it a noble, an enlightened way of spending our brief time in the sun, to work at understanding the universe and how we have come to wake up in it?\n\t\\end{quote}\n\t\n\tThe world is a wonderful place filled with wonders, it is the noblest pursuit to try to understand it. One may prefer traditional science in an attempt to directly understand the world, one may find philosophy intriguing in understanding humanity. As someone majoring in software, I have always found mathematics to be the beauty that unlocks the understanding of the world. \n\t\n\tMathematics has the interesting duality of both being immensely useful while desperately trying to be abstract and devoid of the real world. G.H.\\ Hardy, the famous English mathematician that worked with the great Srinivasa Ramanujan---famously depicted in the film \\textit{The Man Who Knew Infinity} once said:\n\t\\begin{quote}{G.H.\\ Hardy}\n\t\tWe have concluded that trivial mathematics is, on the whole, useful, and that the real mathematics, on the whole, is not.\n\t\\end{quote}\n\t\n\tMost mathematics, such as Group Theory, Category Theory, and Topology try to be as abstract as possible. Yet they all have proved to be critical tools in understanding large software. The concept of a monoid seems completely out of touch with reality until you realize it's everywhere in programming languages. \n\t\n\tEmbrace mathematics both for its abstract beauty and the applications, for which it is the language of both the abstract world and the world we live in.\n\\end{document}", "meta": {"hexsha": "bfe9084ef7ffd7a10d172b01755cc21f09bb63a7", "size": 10396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "Internal-Compiler-Error/linear-albegra-to-balance-chemical-equations", "max_stars_repo_head_hexsha": "61582a27e9c8c1667f044bee7eefc62791eabbe7", "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": "Internal-Compiler-Error/linear-albegra-to-balance-chemical-equations", "max_issues_repo_head_hexsha": "61582a27e9c8c1667f044bee7eefc62791eabbe7", "max_issues_repo_licenses": ["CC0-1.0"], "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": "Internal-Compiler-Error/linear-albegra-to-balance-chemical-equations", "max_forks_repo_head_hexsha": "61582a27e9c8c1667f044bee7eefc62791eabbe7", "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.6180257511, "max_line_length": 376, "alphanum_fraction": 0.6122547134, "num_tokens": 3593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6643840849952746}}
{"text": "\\subsection{Neural Network}\n\nNeural Network (NN) is a classifier that tries to replicate the structure of the human thought.\n\nBeing the purpose of the paper to compare the performance of SVM vs NN, our second approach was to implement a Neural Network with a Multi-layer Perceptron Classifier \\cite{nn-mlp-classifier}.\n\nJust as in our SVM flow, we initially divide our data in two subsets:\n\n\\begin{itemize} \n\\item Training subset:  \\(80\\%\\)\n\\item Testing subset:  \\(20\\%\\).\n\\end{itemize}\n\n\nSimilar to what was done in SVM, we used HOG as our feature extractor. Hence, the specific implementation we used has 3 layers: \\(Input Layer \\rightarrow Hidden Layer \\rightarrow Output Layer\\), with the follow specification:\n\n\\begin{itemize} \n\\item Input Layer: \\(128\\) neurons (the respective number of features extracted by HOG);\n\\item Hidden Layer: \\(10\\) neurons (as default value, the optimized number of neurons will be specified ahead);\n\\item Output Layer: \\(1\\) neuron.\n\\end{itemize}\n\nFurthermore, we used \\textit{RELU} as the activation function, the loss function we used was \\textit{Log-Loss Function}, using the \\textit{LBFGS} weight optimizer (we decide to use \\textit{LBFGS}, because, according to Scikit-Learn documentation \\cite{nn-mlp-classifier}, it can converge faster and perform better, given smaller datasets, which is our case), and has the default learning rate, we used \\( \\alpha = 0.001 \\), which will be optimized further ahead. To summarize we can see the initial configuration of our Neural Network in table \\ref{table:nn-initial-configuration}.\n\n\\begin{table}[htbp]\n\\centering\n\\caption{NN - Initial Configuration}\n\\begin{tabular}{ |c|c| } \n \\hline\n \\textbf{Train Data} & 80\\% \\\\ \n \\hline\n \\textbf{Test Data} & 20\\% \\\\ \n \\hline\n \\textbf{Input Layer} & \\(128\\) neurons \\\\ \n \\hline\n \\textbf{Hidden Layer} & [10, 20, 30, 40, 50, 60, 70] neurons, \\(default = 10\\) \\\\ \n \\hline\n \\textbf{Output Layer} & \\(1\\) neuron \\\\ \n \\hline\n \\textbf{Activation Function} & \\textit{RELU} \\\\ \n \\hline\n \\textbf{Loss Function} & \\textit{Log-Loss Function}, via \\textit{LBFGS} weight optimizer \\\\ \n \\hline\n \\textbf{Learning Rate (\\(\\alpha\\))} & [0.001, 0.01, 0.05, 0.1, 0.5, 1, 10], \\(default = 0.001\\) \\\\ \n \\hline\n \\textbf{Number of Iterations} & [100, 200, 300, ..., 900, 1000], \\(default = 100\\) \\\\ \n \\hline\n\\end{tabular}\n\\label{table:nn-initial-configuration}\n\\end{table}\n\nAs done in the previous section, the SVM aproach \\ref{svm}, we optimized the hyper-parameters of the NN model to enable its best performance. Just like in SVM, we did this by applying K-Fold Cross Validation, with \\(K = 5\\). The hyper-parameters we decided to vary, and consequently optimize, were as follows:\n\n\\begin{itemize} \n\\item Hidden Layer size (the number of neurons in the Hidden Layer);\n\\item Learning rate (\\(\\alpha\\));\n\\item Number of iterations.\n\\end{itemize}\n\nAfter validating every combination, as we can see in figure \\ref{fig:nn-cross-validation}, our model performed the best when:\n\n\\begin{itemize} \n\\item \\( HiddenLayerSize = 60 \\) neurons;\n\\item \\( \\alpha = 1 \\);\n\\item \\( NumberOfIterations = 700 \\).\n\\end{itemize}\n\n\\begin{figure}[htbp]\n\\centerline{\\includegraphics[width=1\\linewidth]{images/nn_cross_validation.png}}\n\\caption{NN - Cross-Validation using multiple-value combinations}\n\\label{fig:nn-cross-validation}\n\\end{figure}\n\nBased on the Cross Validation data, we created a Neural Network with a Multi-layer Perceptron Classifier, and a final configuration that can be seen in table \\ref{table:nn-final-configuration}.\n\n\\begin{table}[htbp]\n\\centering\n\\caption{NN - Final Configuration}\n\\begin{tabular}{ |c|c| } \n \\hline\n \\textbf{Train Data} & 80\\% \\\\ \n \\hline\n \\textbf{Test Data} & 20\\% \\\\ \n \\hline\n \\textbf{Input Layer} & \\(128\\) neurons \\\\ \n \\hline\n \\textbf{Hidden Layer} & \\(60\\) neurons \\\\ \n \\hline\n \\textbf{Output Layer} & \\(1\\) neuron \\\\ \n \\hline\n \\textbf{Activation Function} & \\textit{RELU} \\\\ \n \\hline\n \\textbf{Loss Function} & \\textit{Log-Loss Function}, via \\textit{LBFGS} \\\\ \n \\hline\n \\textbf{Learning Rate (\\(\\alpha\\))} & \\(\\alpha = 1\\) \\\\ \n \\hline\n \\textbf{Number of Iterations} & 700 \\\\ \n \\hline\n\\end{tabular}\n\\label{table:nn-final-configuration}\n\\end{table}\n\nFinally, and as we did in our SVM approach, to ensure that the model didn't end up in a local minimum, and that our model was actually learning we run the all process 50 times and calculated the mean values to both train and test phases.", "meta": {"hexsha": "879400025ed99ae8ae6d890d19248239d7bcd0cf", "size": 4411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/nn.tex", "max_stars_repo_name": "vascoalramos/image-face-detection", "max_stars_repo_head_hexsha": "c6aced3864343481dea27882a164134890fb001a", "max_stars_repo_licenses": ["MIT"], "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/nn.tex", "max_issues_repo_name": "vascoalramos/image-face-detection", "max_issues_repo_head_hexsha": "c6aced3864343481dea27882a164134890fb001a", "max_issues_repo_licenses": ["MIT"], "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/nn.tex", "max_forks_repo_name": "vascoalramos/image-face-detection", "max_forks_repo_head_hexsha": "c6aced3864343481dea27882a164134890fb001a", "max_forks_repo_licenses": ["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.8252427184, "max_line_length": 581, "alphanum_fraction": 0.7188846067, "num_tokens": 1286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6643213821318756}}
{"text": "\\subsubsection{Support Vector Regression}\n\\label{svm}\n\n\\cite{vapnik1963} and \\cite{vapnik1964} introduce the so-called support vector\n    machine (SVM) model, and \\cite{vapnik2013} summarizes the research\n    conducted since then.\nIn its basic version, SVMs are linear classifiers, modeling a binary\n    decision, that fit a hyperplane into the feature space of $\\mat{X}$ to\n    maximize the margin around the hyperplane seperating the two groups of\n    labels.\nSVMs were popularized in the 1990s in the context of optical character\n    recognition, as shown in \\cite{scholkopf1998}.\n\n\\cite{drucker1997} and \\cite{stitson1999} adapt SVMs to the regression case,\n    and \\cite{smola2004} provide a comprehensive introduction thereof.\n\\cite{mueller1997} and \\cite{mueller1999} focus on SVRs in the context of time\n    series data and find that they tend to outperform classical methods.\n\\cite{chen2006a} and \\cite{chen2006b} apply SVRs to predict the hourly demand\n    for water in cities, an application similar to the UDP case.\n\nIn the SVR case, a linear function\n    $\\hat{y}_i = f(\\vec{x}_i) = \\langle\\vec{w},\\vec{x}_i\\rangle + b$\n    is fitted so that the actual labels $y_i$ have a deviation of at most\n    $\\epsilon$ from their predictions $\\hat{y}_i$ (cf., the constraints\n    below).\nSVRs are commonly formulated as quadratic optimization problems as follows:\n$$\n\\text{minimize }\n\\frac{1}{2} \\norm{\\vec{w}}^2 + C \\sum_{i=1}^m (\\xi_i + \\xi_i^*)\n\\quad \\text{subject to }\n\\begin{cases}\ny_i - \\langle \\vec{w}, \\vec{x}_i \\rangle - b \\leq \\epsilon + \\xi_i\n\\text{,} \\\\\n\\langle \\vec{w}, \\vec{x}_i \\rangle + b - y_i \\leq \\epsilon + \\xi_i^*\n\\end{cases}\n$$\n$\\vec{w}$ are the fitted weights in the row space of $\\mat{X}$, $b$ is a bias\n    term in the column space of $\\mat{X}$, and $\\langle\\cdot,\\cdot\\rangle$\n    denotes the dot product.\nBy minimizing the norm of $\\vec{w}$, the fitted function is flat and not prone\n    to overfitting strongly.\nTo allow individual samples outside the otherwise hard $\\epsilon$ bounds,\n    non-negative slack variables $\\xi_i$ and $\\xi_i^*$ are included.\nA non-negative parameter $C$ regulates how many samples may violate the\n    $\\epsilon$ bounds and by how much.\nTo model non-linear relationships, one could use a mapping $\\Phi(\\cdot)$ for\n    the $\\vec{x}_i$ from the row space of $\\mat{X}$ to some higher\n    dimensional space; however, as the optimization problem only depends on\n    the dot product $\\langle\\cdot,\\cdot\\rangle$ and not the actual entries of\n    $\\vec{x}_i$, it suffices to use a kernel function $k$ such that\n    $k(\\vec{x}_i,\\vec{x}_j) = \\langle\\Phi(\\vec{x}_i),\\Phi(\\vec{x}_j)\\rangle$.\nSuch kernels must fulfill certain mathematical properties, and, besides\n    polynomial kernels, radial basis functions with \n    $k(\\vec{x}_i,\\vec{x}_j) = exp(\\gamma \\norm{\\vec{x}_i - \\vec{x}_j}^2)$ are\n    a popular candidate where $\\gamma$ is a parameter controlling for how the\n    distances between any two samples influence the final model.\nSVRs work well with sparse data in high dimensional spaces, such as\n    intermittent demand data, as they minimize the risk of misclassification\n    or predicting a significantly far off value by maximizing the error\n    margin, as also noted by \\cite{bao2004}.\n", "meta": {"hexsha": "c98d2ea0fb16c3868511fb9e0e44e59d97aaaa3d", "size": 3249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/3_ml/5_svm.tex", "max_stars_repo_name": "webartifex/urban-meal-delivery-paper-demand-forecasting", "max_stars_repo_head_hexsha": "9ee3396a24ce20c9886b4cde5cfe2665fd5a8102", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T19:40:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T19:40:56.000Z", "max_issues_repo_path": "tex/2_lit/3_ml/5_svm.tex", "max_issues_repo_name": "webartifex/urban-meal-delivery-demand-forecasting", "max_issues_repo_head_hexsha": "9ee3396a24ce20c9886b4cde5cfe2665fd5a8102", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2_lit/3_ml/5_svm.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": 53.262295082, "max_line_length": 78, "alphanum_fraction": 0.7217605417, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6643213713205451}}
{"text": "\n\n\n\\numberwithin{equation}{section}\n\n\n\n\n\n\n\\section{Deep Convolutional Neural Fields}\n\n\nIn this Appendix, we show some technical details about the proposed deep convolutional field model.\n\n\n\n\n\nLet $\\x$ be an image and $\\y=[y_1,\\ldots, y_n]^{\\T} \\in \\Real^n$ be\n%the continuous real-valued vectorized depth map of\na vector of continuous depth values corresponding to\n all $n$ superpixels in $\\x$.\n %Continuous \\crf (CCRF)\n Similar to conventional CRF,\n we model the conditional probability distribution of the data with the following density function:\n\\begin{equation}\\label{eq:prob}\n\\begin{aligned}\n\\Pr(\\y|\\x) = \\frac{1}{\\mathrm{Z}(\\x)} \\exp \\{ -E(\\y, \\x) \\},\n\\end{aligned}\n\\end{equation}\nwhere $E$ is the energy function and $Z(\\x)$ the partition function, defined respectively as:\n\\begin{equation}\\label{eq:feature}\nE(\\y, \\x) = \\sum_{p \\in {\\cal N} } (y_p - \\regress_p)^2\n+ \\sum_{(p,q) \\in {\\cal S}} \\half \\pws_{pq} (y_p - y_q)^2,\n\\end{equation}\n\\begin{equation}\\label{eq:partition}\n\\mathrm{Z}(\\x) = \\int_{\\y} \\exp \\{ -E(\\y, \\x) \\}\\mathrm{d}\\y,\n\\end{equation}\nin which,\n\\begin{equation} \\label{eq:def_R}\n\\pws_{pq} = \\sum_{k=1}^K \\beta_k S_{pq}^{(k)},\n\\end{equation}\nwhere $\\regress$ is the regressed depths parametrized by $\\btheta$ (namely, $\\regress$ is the abbreviation of $\\regress(\\btheta)$), $\\bbeta=[\\beta_1, \\ldots, \\beta_K]$ the pairwise parameter, $\\S^{(k)}$ the $k$-th similarity matrix (which is symmetric) and $K$ the number of pairwise terms considered.\nTo guarantee $Z(\\x)$ (Eq. \\eqref{eq:partition}) is integrable, $\\bbeta_k > 0$ are required.\nWe aim to jointly learn $\\regress(\\btheta)$ and $\\bbeta$ here.\n\n\nBy expanding Eq. \\eqref{eq:feature}, we then have:\n\\begin{align} \\label{eq:feature_expand}\nE(\\y, \\x) &= \\sum_p y_p^2 - 2\\sum_p y_p \\regress_p  + \\sum_p \\regress_p^2 + \\half \\sum_{pq} \\pws_{pq} y_p^2 - \\sum_{pq} \\pws_{pq} y_p y_q + \\half \\sum_{pq} \\pws_{pq} y_q^2 \\notag \\\\\n\t&= \\y^\\T \\y - 2\\bregress^\\T \\y  + \\bregress^\\T \\bregress +  \\y^\\T \\D \\y -  \\y^\\T \\bpws \\y  \\notag \\\\\n\t&= \\y^\\T (\\I+ \\D - \\bpws) \\y - 2\\bregress^\\T \\y + \\bregress^\\T \\bregress \\notag \\\\\n\t&= \\y^\\T \\A \\y - 2\\bregress^\\T \\y + \\bregress^\\T \\bregress,\n\\end{align}\n%\\bd = 2\\regress\n%\\underbrace{(2\\I+2\\bbeta \\D -2\\bbeta \\S)}_\\text{\\Sigma^{-1}}\nwhere\n\\begin{align} \\label{eq:def_A}\n\\A = \\I+ \\D - \\bpws.\n\\end{align}\nHere, $\\I$ is the n$\\times$n identity matrix; $\\D$ is a diagonal matrix with $\\D_{pp} = \\sum_q \\pws_{pq}$.\nSince $\\beta_k \\geq 0$ are enforced, $\\A$ is ensured to be positive definite ($\\A$ is symmetric, and strictly diagonally dominant with positive diagonal entries). We can then calculate the partition function according to the Gaussian integral formula as:\n\\begin{align} \\label{eq:part_expand}\nZ(\\x) &=\\int_\\y \\exp \\Big\\{ -E(\\y, \\x) \\Big\\}\\mathrm{d}\\y   \\notag \\\\\n\t&=  \\int_{\\y} \\exp \\Big\\{ - \\y^\\T \\A \\y + 2\\bregress^\\T \\y - \\bregress^\\T \\bregress \\Big\\}\\mathrm{d}\\y  \\notag  \\\\\n\t&=\\exp \\{  - \\bregress^\\T \\bregress \\} \\int_{\\y} \\exp \\Big\\{ - \\y^\\T \\A \\y + 2\\bregress^\\T \\y \\Big\\}\\mathrm{d}\\y \\notag  \\\\\n\t&= \\exp \\{  - \\bregress^\\T \\bregress \\}\\sqrt{\\frac{{(2\\pi)}^n}{|2\\A|}} \\exp \\{{ \\bregress ^\\T \\A^{-1} \\bregress}\\} \\notag  \\\\\n\t&= \\frac{{(\\pi)}^{\\frac{n}{2}}}{{|\\A|}^{\\frac{1}{2}}} \\exp \\{{ \\bregress ^\\T \\A^{-1} \\bregress   - \\bregress^\\T \\bregress }\\} ,\n\\end{align}\nwhere $|\\A|$ denotes the determinant of the matrix $\\A$, and $\\A^{-1}$ the inverse of $\\A$.\nFrom Eq. \\eqref{eq:prob}, \\eqref{eq:feature_expand}, \\eqref{eq:part_expand}, we can write the probability density function as:\n\\begin{align} \\label{eq:prob_gaussian}\n\\Pr(\\y|\\x) &=\\frac{\\exp \\Big\\{ -E(\\y, \\x) \\Big\\}} { Z(\\x)}  \\\\ \\notag\n\t&= \\frac{\\exp \\Big\\{ - \\y^\\T \\A \\y + 2\\bregress^\\T \\y - \\bregress^\\T \\bregress \\Big\\}}{\\frac{{(\\pi)}^{\\frac{n}{2}}}{{|\\A|}^{\\frac{1}{2}}} \\exp \\{{ \\bregress ^\\T \\A^{-1} \\bregress   - \\bregress^\\T \\bregress }\\}}  \\\\ \\notag\n\t&=\\frac{ |\\A|^{\\half}} {{\\pi^{\\frac{n}{2}}}} \\exp \\Big\\{ - \\y^\\T \\A \\y + 2\\bregress^\\T \\y -  \\bregress ^\\T \\A^{-1} \\bregress \\Big\\}. \\\\ \\notag\n\\end{align}\n%%\n%\n%\nAccording to Eq. \\eqref{eq:prob_gaussian}, we can then rewrite the negative log-likelihood $-\\log\\Pr(\\y|\\x)$ as:\n\\begin{align} \\label{eq:log-likelihood}\n-\\log\\Pr(\\y|\\x)&= \\y^\\T \\A \\y - 2\\bregress^\\T \\y + \\bregress ^\\T \\A^{-1} \\bregress - \\half\\log(|\\A|) + \\frac{n}{2}\\log(\\pi).\n\\end{align}\n\n\n%In learning, CCRF minimizes the negative conditional log-likelihood of the training data,\n%\\begin{equation} \\label{eq:ccrf}\n%(\\btheta^{\\star}, \\bbeta^{\\star}) = \\argmin_{\\btheta, \\bbeta} -L(\\btheta, \\bbeta) = \\argmin_{\\btheta, \\bbeta} -\\sum_{i=1}^N \\log\\Pr(\\y^{(i)} | \\x^{(i)}; \\btheta, \\bbeta)\n%\\end{equation}\nIn learning, we minimizes the negative conditional log-likelihood of the training data. Adding regularization to $\\btheta$, $\\bbeta$, we then arrive at the final optimization:\n\\begin{align} \\label{eq:ccrf_final}\n\\min_{\\btheta, \\bbeta \\geq \\zeros} &-\\sum_{i=1}^N \\log\\Pr(\\y^{(i)} | \\x^{(i)}; \\btheta, \\bbeta) + \\frac{\\lambda_1}{2} \\fnorm \\btheta + \\frac{\\lambda_2}{2} \\fnorm \\bbeta,\n\\end{align}\nwhere $\\x^{(i)}$, $\\y^{(i)}$ denote the $i$-th training image and the corresponding depth map; $N$ is the number of training images; $\\lambda_1$ and $\\lambda_2$ are weight decay parameters.\n\n\n\nFor the unary part,\nhere we calculate the partial derivatives of $-\\log\\Pr(\\y|\\x)$ with respect to $\\theta_l$ (one element of the network parameters $\\btheta$ for the unary part ). Recall that $\\A = \\I+ \\D - \\bpws$ (Eq. \\eqref{eq:def_A}), $\\A^{\\T}=\\A$, $(\\A^{-1})^{\\T}=\\A^{-1}$, $|\\A^{-1}|=\\frac{1}{|\\A|}$, we have:\n\\begin{align}  \\label{eq:derive_z}\n\\frac{\\partial \\{ -\\log\\Pr(\\y|\\x)\\} }{\\partial \\theta_l} &= \\frac{\\partial \\{-2\\bregress^\\T \\y + \\bregress ^\\T \\A^{-1} \\bregress\\}}{\\partial \\theta_l}   \\\\ \\notag\n&= \\frac{\\partial \\{-2\\bregress^\\T \\y \\} } {\\partial \\theta_l} + \\frac{\\partial \\{ \\bregress ^\\T \\A^{-1} \\bregress\\}}{\\partial \\theta_l}   \\\\ \\notag\n&= -2 \\frac{\\partial \\{ \\sum_p \\regress_p y_p \\} } {\\partial \\theta_l} + \\frac{\\partial \\{ \\sum_{pq} \\regress_p \\regress_q A^{-1}_{pq} \\}}{\\partial \\theta_l}   \\\\ \\notag\n&= -2 \\sum_p \\Big ( y_p\\frac{\\partial \\regress_p } {\\partial \\theta_l} \\Big ) + \\sum_{pq} \\Big ( z_p \\frac{\\partial  \\regress_q} {\\partial \\theta_l} + z_q \\frac{\\partial  \\regress_p} {\\partial \\theta_l} \\Big ) A^{-1}_{pq} \\\\ \\notag\n&= -2 \\y^{\\T} \\frac{\\partial \\bregress } {\\partial \\theta_l} + 2\\bregress^{\\T} \\A^{-1} \\frac{\\partial \\bregress } {\\partial \\theta_l}\\\\ \\notag\n&= 2 (\\A^{-1} \\bregress - \\y)^{\\T} \\frac{\\partial \\bregress}{\\partial \\theta_l} .\n\\end{align}\n\n\n\n%For the pairwise part, we first calculate the partial derivatives of $-\\log\\Pr(\\y|\\x)$ with respect to $\\pws_{pq}$:\n%\\begin{align}  \\label{eq:derive_R}\n%\\frac{\\partial \\{ -\\log\\Pr(\\y|\\x)\\} }{\\partial \\pws_{pq}} &= \\frac{\\partial \\{\\y^\\T \\A \\y + \\bregress ^\\T \\A^{-1} \\bregress - \\half\\log(|\\A|)\\}}{\\partial \\pws_{pq}}   \\notag \\\\\n%&= \\frac{\\partial \\{ \\y^\\T \\A \\y \\}}{\\partial \\pws_{pq}} +  \\frac{\\partial \\{\\bregress ^\\T \\A^{-1} \\bregress\\}}{\\partial \\pws_{pq}} - \\half \\frac{\\partial \\log(|\\A|)}{\\partial \\pws_{pq}}, \\notag \\\\\n%&=\\y^\\T\\frac{\\partial  \\A }{\\partial \\pws_{pq}}\\y - \\bregress^\\T \\A^{-1} \\frac{\\partial \\A }{\\partial \\pws_{pq}} \\A^{-1} \\bregress  - \\half \\frac{1}{|\\A|} \\frac{\\partial \\{|\\A|\\} }{\\partial \\pws_{pq}}, \\notag \\\\\n%&=\\y^\\T \\frac{\\partial  \\A }{\\partial \\pws_{pq}} \\y - \\bregress^\\T \\A^{-1} \\frac{\\partial \\A }{\\partial \\pws_{pq}} \\A^{-1} \\bregress  - \\half \\trace \\Big ( \\A^{-1}  \\frac{\\partial \\A} {\\partial \\pws_{pq}} \\Big ), \\notag \\\\\n%&=\\y^\\T \\G \\y - \\bregress^\\T \\A^{-1} \\G \\A^{-1} \\bregress  - \\half \\trace \\Big ( \\A^{-1}  \\G\\Big ).\n%\\end{align}\n%Here we introduce a matrix $\\G=\\frac{\\partial  \\A }{\\partial \\pws_{pq}}$. Each element of $\\G$ is:\n%\\begin{align} \\label{eq:def_G}\n%G_{pq} &= \\frac{\\partial A_{pq} }{\\partial \\pws_{pq}}  \\notag \\\\\n%&= \\frac{\\partial \\{  D_{pq} - \\pws_{pq} \\} }{\\partial \\pws_{pq}}  \\notag \\\\\n%%&= \\frac{\\partial \\{  \\sum_q \\pws_{pq} - \\pws_{pq} \\} }{\\partial \\pws_{pq}}  \\notag \\\\\n%&= -\\delta(p \\neq q),\n%\\end{align}\n%where $\\delta(\\cdot)$ is the indicator function, which equals 1 if $p \\neq q$ is true and 0 otherwise.\n\n\n\nNext, for the pairwise part, we calculate the  partial derivatives of $-\\log\\Pr(\\y|\\x)$ with respect to $\\beta_k$ as:\n\\begin{align}  \\label{eq:derive_beta}\n\\frac{\\partial \\{ -\\log\\Pr(\\y|\\x)\\} }{\\partial \\beta_k} &= \\frac{\\partial \\{\\y^\\T \\A \\y + \\bregress ^\\T \\A^{-1} \\bregress - \\half\\log(|\\A|)\\}}{\\partial \\beta_k}   \\notag \\\\\n&= \\frac{\\partial \\{ \\y^\\T \\A \\y \\}}{\\partial \\beta_k} +  \\frac{\\partial \\{\\bregress ^\\T \\A^{-1} \\bregress\\}}{\\partial \\beta_k} - \\half \\frac{\\partial \\log(|\\A|)}{\\partial \\beta_k}, \\notag \\\\\n&=\\y^\\T\\frac{\\partial  \\A }{\\partial \\beta_k}\\y - \\bregress^\\T \\A^{-1} \\frac{\\partial \\A }{\\partial \\beta_k} \\A^{-1} \\bregress  - \\half \\frac{1}{|\\A|} \\frac{\\partial \\{|\\A|\\} }{\\partial \\beta_k}, \\notag \\\\\n&=\\y^\\T \\frac{\\partial  \\A }{\\partial \\beta_k} \\y - \\bregress^\\T \\A^{-1} \\frac{\\partial \\A }{\\partial \\beta_k} \\A^{-1} \\bregress  - \\half \\trace \\Big ( \\A^{-1}  \\frac{\\partial \\A} {\\partial \\beta_k} \\Big ).\n\\end{align}\nWe here introduce matrix $\\J$ to denote $\\frac{\\partial  \\A }{\\partial \\beta_k}$. Each element of $\\J$ is:\n\\begin{align}  \\label{eq:def_J}\nJ_{pq} &= \\frac{\\partial A_{pq}}{\\partial \\beta_k}  \\notag \\\\\n&= \\frac{\\partial \\{ D_{pq} - R_{pq} \\} }{\\partial \\beta_k}  \\notag \\\\\n&= \\frac{\\partial D_{pq}  }{\\partial \\beta_k}  - \\frac{\\partial R_{pq}  }{\\partial \\beta_k} \\notag \\\\\n&= - \\frac{\\partial  \\pws_{pq} }{\\partial \\beta_k} + \\delta(p=q) \\sum_q \\frac{\\partial  \\pws_{pq} }{\\partial \\beta_k},\n\\end{align}\nwhere $\\delta(\\cdot)$ is the indicator function, which equals 1 if $p=q$ is true and 0 otherwise.\nFrom Eq. \\eqref{eq:derive_beta}, Eq. \\eqref{eq:def_J}, we can see that our framework is general, therefore more complicated networks for the pairwise part can be seamlessly incorporated.\nHere, in our case, with the definition of $\\pws_{pq}$ in Eq. \\eqref{eq:def_R}, we have $\\frac{\\partial  \\pws_{pq} }{\\partial \\beta_k}=S_{pq}^{(k)}$.\n\nAccording to Eq. \\eqref{eq:derive_beta} and the definition of  $\\J$ in \\eqref{eq:def_J}, we can now write the partial derivative of $-\\log\\Pr(\\y|\\x)$ with respect to $\\beta_k$  as:\n\\begin{equation}  \\label{eq:derive_beta_final}\n\\frac{\\partial \\{ -\\log\\Pr(\\y|\\x)\\} }{\\partial \\beta_k} =  \\y^{\\T} \\J \\y - \\bregress^{\\T} \\A^{-1} \\J \\A^{-1}\\bregress - \\half \\trace \\Big( \\A^{-1} \\J \\Big).\n\\end{equation}\n%%\n%Using the chain rule, we can write the partial derivatives of  $-\\log\\Pr(\\y|\\x)$ with respect to $\\theta_l$ as:\n%\\begin{align}\n%\\frac{\\partial \\{ -\\log\\Pr(\\y|\\x) \\} } {\\partial \\theta_l}\n% = \\; & \\frac{\\partial \\{ -\\log\\Pr(\\y|\\x) \\} }{\\partial \\bregress} \\frac{\\partial \\bregress }{\\partial \\theta_l}   \\notag \\\\\n% = \\; & \\Big( 2 \\A^{-1} \\bregress - 2\\y \\Big ) \\frac{\\partial \\bregress }{\\partial \\theta_l} , \\label{eq:derive_z}\n%\\end{align}\n\n\\paragraph{Depth prediction}\nPredicting the depths of a new image is to solve the MAP inference.\nBecause of the quadratic form of $\\y$ in Eq. \\eqref{eq:log-likelihood}, closed form solutions exist (details refer to supplementary): % \\cite{ccrf_nips08}:\n\\begin{align} \\label{eq:inf_solution1}\n\\y^{\\star}&=\\argmax_{\\y} \\Pr(\\y|\\x)  \\notag \\\\\n&=\\argmax_{\\y} \\log \\Pr(\\y|\\x) \\notag   \\\\\n&= \\argmax_{\\y} -\\y^\\T \\A \\y + 2\\bregress^\\T \\y .\n\\end{align}\nWith the definition of $\\A$ in Eq.\\eqref{eq:def_A}, $\\A$ is symmetric.\nThen by setting the partial derivative of $-\\y^\\T \\A \\y + 2\\bregress^\\T \\y$ with respect to $\\y$ to $\\zeros$ ($\\zeros$ is an n$\\times$1 column vector with all elements being 0), we have\n\\begin{align} \\label{eq:inf_deriv}\n&\\frac{\\partial \\{ -\\y^\\T \\A \\y + 2\\bregress^\\T \\y \\} } {\\partial \\y} =0  \\notag  \\\\\n\\Rightarrow \\;\\;&-(\\A + \\A^{\\T} ) \\y +2 \\bregress=0  \\notag  \\\\\n\\Rightarrow \\;\\;&-2\\A \\y +2 \\bregress=0  \\notag  \\\\\n\\Rightarrow \\;\\;&\\y = \\A^{-1} \\bregress.\n\\end{align}\nNow we can write the solution for the MAP inference in Eq. \\eqref{eq:inf_solution1} as:\n\\begin{align} \\label{eq:inf_solution2}\n\\y^{\\star}&= \\A^{-1} \\bregress\n\\end{align}\n\n%Because of the quadratic form of $\\y$ in Eq. \\eqref{eq:log-likelihood}, there exists closed form solution for the inference problem \\cite{ccrf_nips08}:\n%\\begin{equation} \\label{eq:inference}\n%\\y^{\\star}=\\argmax_{\\y} \\Pr(\\y|\\X) = \\argmax_{\\y} -\\y^\\T \\A \\y + 2\\regress^\\T \\y  = \\A^{-1} \\regress.\n%\\end{equation}\n%If the pairwise terms are ignored, namely $\\bbeta=\\zeros$, then Eq. \\eqref{eq:inference} degenerates to $\\y^{\\star}=\\regress$, which is a conventional regression model.\n\n\n\n\n\\section{Experiments}\nTo show how the superpixel number affects the performance of our model, we add an experiment to evaluate the root mean square (rms) errors and the training time of our pre-train model on the Make3D dataset by varying the superpixel number per image.\nFig. \\ref{fig:rmsVSspnum} shows the results.\nAs we can see, increasing the number of supperpixel per image yields further decrease in the rms error, but at the cost of more training time.\nWe use $\\sim 700$ superpixels per image in all other experiments in this paper, therefore by increasing it, we can expect better results.\n\n\n\\begin{figure} \\center\n     \\includegraphics[width=0.38\\textwidth, height=0.28\\textwidth]{./fig/Make3D/rmsVSspNum.pdf}\n     \\includegraphics[width=0.38\\textwidth, height=0.28\\textwidth]{./fig/Make3D/timeVSspNum.pdf}\n\\caption{Left: Root mean square (C2 rms)  errors  \\vs  varying superpixel numbers on the Make3D dataset.\nRight: Training time \\vs varying superpixel numbers per image on the Make3D dataset.\nClearly, increasing the number of supperpixels per image, we can further improve the results but at the cost of more training time.}  \\label{fig:rmsVSspnum}\n\\end{figure}\n\n\n", "meta": {"hexsha": "155e28b856034d878bbe60febbe3e1f01049616e", "size": 13641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/supp.tex", "max_stars_repo_name": "yihui-he/Estimated-Depth-Map-Helps-Image-Classification", "max_stars_repo_head_hexsha": "bfcc2d9d856ee04addc14c3eab75a2112fc19346", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2017-09-24T21:44:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-19T10:25:08.000Z", "max_issues_repo_path": "presentation/supp.tex", "max_issues_repo_name": "yihui-he/Estimated-Depth-Map-Helps-Image-Classification", "max_issues_repo_head_hexsha": "bfcc2d9d856ee04addc14c3eab75a2112fc19346", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-10-19T08:15:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-07T12:04:04.000Z", "max_forks_repo_path": "presentation/supp.tex", "max_forks_repo_name": "yihui-he/Estimated-Depth-Map-Helps-Image-Classification", "max_forks_repo_head_hexsha": "bfcc2d9d856ee04addc14c3eab75a2112fc19346", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2017-09-26T01:06:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-12T19:18:26.000Z", "avg_line_length": 65.8985507246, "max_line_length": 301, "alphanum_fraction": 0.6322850231, "num_tokens": 5158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6642311254393823}}
{"text": "The goal of this document is to make you acquainted with the concept of inference systems. You will learn various aspects of logic and inference system, which we will use to give rise to definitions of concepts such as numbers, boolean expressions, etc. As an advanced example you will also learn how to model programming languages constructs into inference systems. This leads to an important end result: you will learn the \\textit{what} of programming languages, in contrast to the \\textit{how} that you have studied so far. As a short conclusion we will discuss the strong relationship between logic and programming, and draw some conclusions about computability.\n\n\\subsection{Why bother?}\nTry drawing a circle or a similar shape. The circle starts out as a single ``piece''. Choose two points along the border and draw a connecting line between the two: the circle is now split into two pieces. Chose now a third point and connect it to the other two points: the circle is now split into four pieces. A clear pattern is emerging: every point we add, we get twice as many pieces. This suggests that by \\texttt{k} points we get $2^{k-1}$ pieces.\n\nThis seems all quite logical, but there is a catch. Try now doing this with six points along the border of the circle: instead of the expected 32 pieces, we will end up with 31. This means that the original conclusion was definitely not correct.\n\nWhat is the moral of this story? If you want (or need) to be absolutely sure about some assertion (often called \\textit{proposition} or \\textit{hypothesis}), then you cannot trust a few examples and an intuitively appealing story to show that some pattern will always hold true. In the practice, and certainly in that of informatics or medical technology, there are many situations where a few tests and an intuition of why the system works are sufficient. Would you dare fly in an airplane where the programmer concluded after a dozen of tests that ``it all works, send it to production''? Would you dare step into an MRI machine (which throws radioactive isotopes at your body) knowing that the software was quickly written during a weekend with a bit of unit testing? Of course not\\footnote{as a side note, if you are comfortable with these scenarios, then perhaps the motivation for the rest of the document will feel quite weak, so you might better go back to your vacation in Chernobyl or flying in planes held together by duct tape.}.\n\nThe use of logic as a foundation for programming does not automatically solve all our problems. It is very well possible (we will get there) that there is no single mathematical formalism or piece of software that will entirely remove the need for human intellect when writing software. \\textbf{In any case, the use of logic and formality when decomposing problems can greatly help in writing software that is better thought out and over which it is far easier to reason and prove properties.}\n\n\\subsection{Structure of the document}\nIn the rest of this document we will: \n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item introduce informal logical reasoning in Section \\ref{sec:informalIntroduction};\n\\item introduce a more formal logical formalism in Section \\ref{sec:inferenceSystems};\n\\item give a first example of logic in action to define basic boolean operators in Section \\ref{sec:booleanExpressions};\n\\item use logic to define \\textit{apparently atomic} and unrelated concepts such as numbers in Chapter \\ref{chap:numbers};\n\\item construct complex data structures such as lists, binary search trees, and even balanced binary search trees in Chapter \\ref{chap:dataStructures};\n\\item build a small programming language in Chapter \\ref{chap:aPL};\n\\item we conclude with a short and woefully incomplete presentation of fragments of computability in Chapter \\ref{chap:closingRemarks}.\n\\end{inparaenum}\n", "meta": {"hexsha": "bdea8fc651f40092f638c4a9eaa531c45d95b74b", "size": 3842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/introduction.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/introduction.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/introduction.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 167.0434782609, "max_line_length": 1041, "alphanum_fraction": 0.7998438313, "num_tokens": 815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.6642130687749597}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\hyphenation{SSVDRS ISCALE}\n\\begmath 4.3 Singular Value Decomposition and Analysis\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nAny M$\\times $N matrix, $A$, has a Singular Value Decomposition (SVD) of the\nform\n\\begin{equation*}\nA = USV^t\n\\end{equation*}\nwhere $U$ is an M$\\times $M orthogonal matrix, $V$ is an N$\\times $N\northogonal matrix, and $S$ is an M$\\times $N matrix having nonnegative\nelements on the diagonal and zeros elsewhere. It is customary to arrange\nthat the diagonal elements of $S$, called the singular values of $A$, are in\ndecreasing order. This is done in the software described here.\n\nThe SVD can be useful in analyzing a linear least-squares problem or other\nmatrix problems, particularly when there is reason to believe that the model\nis ill-conditioned. The SVD also has a role as a component in many\nspecialized algorithms of linear algebra and statistics.\n\nHere we describe three subroutines to facilitate use of the SVD:\n\n(1) Let a matrix, $A$, and a matrix or vector, $B$, be given. Denote the SVD\nof $A$ by $A$ $= USV^t$. Subroutine SSVDRS computes the SVD of a matrix, $A$%\n, and returns $S$, $V$, and the product, $U^tB$. If one needs to obtain the\nmatrix $U$ explicitly, call SSVDRS with $B$ set to be the $M^{th}$ order\nidentity matrix.\n\n(2) Subroutine SSVA uses SSVDRS and produces a report of quantities useful\nfor the singular value analysis of a least-squares problem, $A{\\bf x} \\simeq\n{\\bf b}.$\n\n(3) Subroutine SCOV3 can be used following SSVDRS to compute a covariance\nmatrix.\n\n\\subsection{Usage}\n\n\\subsubsection{Singular Value Decomposition with Computation of $U^tB$}\n\nCompute the Singular Value Decomposition, $USV^t$, of a matrix, $A$, and\noptionally return the product, $U^tB$, where $B$ is another given matrix.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf LDA, M, N, LDB, NB}\n\n\\item[REAL]  \\ {\\bf A}(LDA, $\\geq $N){\\bf , SING}($\\geq $N){\\bf , D}($\\geq $%\nN){\\bf ,\\\\ WORK}($\\geq 2\\times $N){\\bf , B}(LDB, $\\geq $NB) or {\\bf B}($\\geq\n$M)\n\\end{description}\n\nAssign values to A(,), LDA, M, N, B(), LDB, and NB.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SSVDRS (A, LDA, M, N, B,\\\\\nLDB, NB, SING, WORK)\\\\\n\\end{tabular}}\n\\end{center}\n\nComputed quantities are returned in A(,), B(), and SING().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] On entry, contains an M$\\times $N matrix, $A$. On\nreturn contains the N$\\times $N matrix, $V$, such that $A=USV^t.$\n\n\\item[LDA]  \\ [in] First dimensioning parameter for A(,). Require LDA $\\geq\n\\max (\\text{M},\\text{N}).$\n\n\\item[M,N]  \\ [in] Number of rows and columns, respectively, in the given\nmatrix, $A$. Either M $>$ N or M $\\leq $ N is permitted. Require M $>0$ and\nN $>0.$\n\n\\item[B()]  \\ [inout] On entry, contains an M-vector, ${\\bf b}$, or an M$%\n\\times $NB matrix, $B$. On return, contains the M-vector, ${\\bf g}=U^t{\\bf b}\n$, or the M$\\times $NB matrix, $G=U^tB$, where $U$ satisfies $USV^t=A.$ Note\nthat if $B$ is the $M^{th}$ order identity matrix on entry, then on return\nthe array B(,) will contain $U^t.$\n\n\\item[LDB]  \\ [in] First dimensioning parameter for the array B(,). Require\nLDB $\\geq \\max (\\text{M},\\text{N})$ when NB $\\geq 1$ and LDB $\\geq 1$ when\nNB = 0.\n\n\\item[NB]  \\ [in] Number of columns in the input matrix, $B$. Require NB $%\n\\geq 0$. If NB = 1, the array B() may be singly or doubly subscripted. If NB\n$>1$, the array B(,) must be doubly subscripted. If NB = 0, the array B()\nwill not be referenced.\n\n\\item[SING()]  \\ [out] On return, contains the singular values of $A$, in\ndescending order, in locations indexed 1 through N. If M $<$ N, SING(M+1)\nthrough SING(N) will be set to zero.\n\n\\item[WORK()]  \\ [scratch] Work space of length at least 2$\\times $N.\n\\end{description}\n\n\\subsubsection{Singular Value Analysis}\n\nComputes quantities useful for the singular value analysis of a\nleast-squares problem, $A{\\bf x} \\simeq {\\bf b}$. Optionally produces a\nreport, with options to select the full report or only parts of it, to\nselect the output unit for the report, and to specify the display width\navailable for the report.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf LDA, M, N, MDATA, ISCALE, KPVEC}(4)\n\n\\item[REAL]  \\ {\\bf A}(LDA, $\\geq $N){\\bf , B}($\\geq $M){\\bf , SING}($\\geq $%\nN){\\bf , D}($\\geq $N){\\bf , WORK}($\\geq 2 \\times \\text{N}$)\n\n\\item[CHARACTER]  \\ {\\bf NAMES}($\\geq N)*($lennam)\\\\\n{}[lennam $\\geq $ 1]\n\\end{description}\n\nAssign values to A(,), LDA, M, N, MDATA, B(), KPVEC(), NAMES(), ISCALE, and\noptionally to D().\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SSVA (A, LDA, M, N, MDATA,\\\\\nB, SING, KPVEC, NAMES,\\\\\nISCALE, D, WORK)\\\\\n\\end{tabular}}\n\\end{center}\n\nComputed quantities are returned in A(,), B(), SING(), and optionally in\nD(). A report is produced if selected by KPVEC().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] On entry, contains the M$\\times $N matrix, $A$, of the\nleast-squares problem to be analyzed. This could be a matrix obtained by\npreliminary orthogonal transformations applied to the actual problem matrix\nwhich may have had more rows (See MDATA below.) On return, contains an $%\nN^{th}$ order matrix in which the $j^{th}$ column is the $j^{th}$ candidate\nsolution for the least-squares problem, $i.e$. the solution computed as\nthough singular values $j+1$ through N were zero.\n\n\\item[LDA]  \\ [in] First dimensioning parameter for A(,). Require LDA $\\geq\n\\max (\\text{M},\\text{N}).$\n\n\\item[M,N]  \\ [in] Number of rows and columns, respectively, in the matrix, $A$.\nEither M $>$ N or M $\\leq $ N is permitted. Require M $>0$ and N $>0.$\n\n\\item[MDATA]  \\ [in] Number of rows in actual least-squares problem.\nGenerally MDATA\\ $\\geq $ M. MDATA is used only in computing statistics for\nthe report and is not used as a loop count or array dimension.\n\n\\item[B()]  \\ [inout] On entry, contains the right-side M-vector, ${\\bf b}$,\nof the least-squares problem. On return, contains the M-vector, ${\\bf g}=U^t%\n{\\bf b}$, where $U$ comes from the singular value decomposition of $A$.\n\n\\item[SING()]  \\ [out] On return, contains the singular values of $A$, in\ndescending order, in locations indexed 1 through N. If M $<$ N, SING(M+1)\nthrough SING(N) will be set to zero.\n\n\\item[KPVEC()]  \\ [in] Option array controlling report generation. If\nKPVEC(1) = 0, default settings will be used, producing the full report,\nsending it to the standard system output unit, formatted with a maximum line\nlength of~79. If KPVEC(1) = 1, the contents of KPVEC(I), I = 2,...,~4, set\noptions for the report, as follows:\n\\begin{description}\n\\item[KPVEC(2)] \\ The decimal representation of KPVEC(2) must be at\nmost 6~digits, each being 0~or~1. The decimal digits will be interpreted as\nindependent on/off flags for the 6 possible blocks of the report. Examples:\n101010 selects the 1st, 3rd, and 5th~blocks, 111111 selects all blocks, 0\nsuppresses the whole report, etc. The default value is 111111. The six\nblocks are:\n\n\\begin{itemize}\n\\item[1.]  Header, with size and scaling option parameters.\n\n\\item[2.]  $V$-matrix.\n\n\\item[3.]  Singular values and related quantities.\n\n\\item[4.]  Listing of YNORM and RNORM and their logarithms.\n\n\\item[5.]  Levenberg-Marquardt analysis.\n\n\\item[6.]  Candidate solutions.\n\\end{itemize}\n\n\\item[KPVEC(3)] \\ Define UNIT = KPVEC(3). If UNIT $\\geq $ 0, UNIT will be\nused as the output unit number. If UNIT $=-1$, output will be written to\nthe ``$\\ast $'' output unit, $i.e.$, the standard system output unit.\nThe default value is $-$1. The calling program unit is responsible for\nopening and/or closing the selected output unit if the host system\nrequires these actions.\n\n\\item[KPVEC(4)] Determines the width of blocks~2, 3, and~6 of the output report.\nDefine WIDTH = KPVEC(4). The default value is~79. Each output line will have\na leading blank for Fortran ``carriage control'' with line widths as\nfollows: Output blocks~1, 4, and~5 always have 63, 66, and 66~character\npositions respectively. Output blocks~2 and~6 will generally have at most\nWIDTH character positions. One output line will contain a row number, a name\nfrom NAMES(), and from one to eight floating point numbers. The space\nallocated for a name will be that needed for the longest name in NAMES(),\nwhich may be less than the declared length of elements of NAMES(). The line\nlength will only exceed WIDTH if this is necessary to accommodate the row\nnumber and name plus one floating-point number. Output block~3 will have\n69~character positions if WIDTH $<95$ and otherwise will have 95~character\npositions.\n\\end{description}\n\n\\item[NAMES()]  \\ [in] NAMES$(j)$, for $j=1$, ..., N, may contain a name for\nthe $j^{th}$ component of the solution vector. If NAMES(1) contains only\nblank characters, it will be assumed that no names have been provided, and\nthis subroutine will not access the NAMES() array beyond the first element.\n\n\\item[ISCALE]  \\ [in] Set by the user to~1, 2, or~3 to select the column\nscaling option.\n\n\\begin{itemize}\n\\item[1]  The subroutine will use identity scaling and ignore the D() array.\n\n\\item[2]  The subroutine will scale nonzero columns of $A$ to have unit\nEuclidean length, and will store reciprocal lengths of the original nonzero\ncolumns in D().\n\n\\item[3]  User supplies column scaling factors in D(). The subroutine will\nmultiply column $j$ by D($j)$, and remove the scaling from the solution at\nthe end.\n\\end{itemize}\n\n\\item[D()]  \\ [ignored or out or in] Usage of D() depends on ISCALE as\ndescribed above. When used, its length must be at least N.\n\n\\item[WORK()]  \\ [scratch] Scratch work space.\n\\end{description}\n\n\\subsubsection{Computation of the Covariance Matrix}\n\nSubroutine, SCOV3, can be used to compute the covariance matrix for the\nsolution vector of a least-squares problem, $A{\\bf x} \\simeq {\\bf b}$,\nfollowing use of SSVDRS in cases in which M $>$ N and all N singular values\nof $A$ are nonzero.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf LDA, N, IERR}\n\n\\item[REAL]  \\ {\\bf A}(LDA, $\\geq $N){\\bf , SING}($\\geq $N){\\bf , VAR,\\\\ WORK%\n}($\\geq $N)\n\\end{description}\n\nOn entry, the arguments, A(,), LDA, N, and SING() should contain the same\nvalues as on return from a previous call to SSVDRS.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SCOV3( A, LDA, N, SING,\\\\\nVAR, WORK, IERR)\\\\\n\\end{tabular}}\n\\end{center}\n\nComputed quantities are returned in A(,) and IERR.\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] On entry, contains the N$\\times $N matrix, $V$,\ncomputed by a previous call to SSVDRS. (Note that the quantities left in the\narray A() by SSVA are not appropriate for use as input to SCOV3.) On return\ncontains the N$\\times $N symmetric covariance matrix, $C$, for the solution\nvector of the least-squares problem, $A{\\bf x}\\simeq {\\bf b}.$\n\n\\item[LDA]  \\ [in] First dimensioning parameter for A(,). Must be the\nsame value used when SSVDRS was called to compute the $V$ matrix.\n\n\\item[N]  \\ [in] Number of rows and columns of the matrix, $V$, contained in\nthe array, A(,). Must be the same value used when SSVDRS was called\nto compute the $V$ matrix.\n\n\\item[SING()]  \\ [in] Contains the singular values of $A$ in locations indexed\n1 through N. Must all be nonzero.\n\n\\item[VAR]  \\ [in] User-supplied estimate of the variance of error in the\nvector, ${\\bf b}$, of the least-squares problem.\n\n\\item[WORK()]  \\ [scratch] Work space of length at least N.\n\n\\item[IERR]  \\ [out] Set to~0 if all of the N given singular values are\nnonzero. Otherwise IERR will be set to the index of the first zero element\nof the array, SING(). In this latter case the covariance matrix cannot be\ncomputed and the contents of A(,) on return will be meaningless.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double precision usage change all REAL type statements to DOUBLE\nPRECISION, and change the subroutine names from SSVA, SSVDRS, and SCOV3 to\nDSVA, DSVDRS, and DCOV3, respectively.\n\n\\subsection{Examples and Remarks}\n\nThe program, DRDSVA, illustrates the use of DSVA to compute and report\nquantities for the singular value analysis of a $15\\times 5$ least-squares\nproblem.  This is an artificially constructed problem that was used as an\nexample in \\cite{Lawson:1974:SLS}.  The output of this example is shown in\nODDSVA.\n\n\\subsubsection{Large problems}\n\nIf M $>>$ N and storage limitations make it awkward or impossible to\nallocate M$\\times $N locations for the array, A(,), one can use sequential\naccumulation of the rows of data to produce a smaller matrix to which SSVDRS\nor SSVA can then be applied. When the ratio M\\,/\\,N is sufficiently large this\napproach will be faster than direct application of SSVDRS to the original\nmatrix. See Chapter~4.4 for sequential accumulation.\n\n\\subsubsection{The pseudoinverse of $A$}\n\nThe pseudoinverse of $A$, conventionally denoted by $A^+$, can be computed\nusing results produced by SSVDRS. Set $B=I$, the $\\text{M}^{th}$ order identity\nmatrix. Then call SSVDRS obtaining $S$, $V$, and $U^t$. Since $S$ is diagonal,\nits pseudoinverse, $S^+$, is its transpose with nonzero elements replaced by\ntheir reciprocals. Depending on the application, it may be appropriate to\ntreat nonzero singular values that are smaller than some problem-related\nthreshold as though they were zero. After defining $S^+$, one can compute $%\nA^+ = VS^+U^t.$\n\n\\subsubsection{Solution of the least-squares problem,\\protect\\\\ $A{\\bf x}\n\\simeq {\\bf b}$}\n\nFrom $A$ and ${\\bf b}$, SSVDRS can compute $V$, $S$, and ${\\bf g} = U^t{\\bf b}$.\nThe user can then determine $S^+$ from $S$ as described in the preceding\nparagraph and compute the solution vector as ${\\bf x} = VS^+{\\bf g}.$\n\n\\subsection{Functional Description}\n\n\\subsubsection{Method in SSVDRS}\n\nSubroutine SSVDRS computes the singular value decomposition by an\nalgorithm due to G.  Golub and W.  Kahan, as described in\n\\cite{Lawson:1974:SLS}.  This method uses approximately 2N Householder\northogonal transformations to reduce the given $A$ matrix to a bidiagonal\nmatrix and then calls SQRBD to apply a specialized version of the QR\neigenvalue algorithm to the bidiagonal matrix to complete the reduction to\nthe diagonal $S$ matrix.  The QR algorithm generally requires about 2N\niterations to reach convergence to machine accuracy.  The product of the\northogonal transformations is accumulated to produce the $V$ matrix and\nthe product, $G = U^tB.$\n\nResults are permuted so the singular values are in decreasing order.\nThe largest singular value will be accurate to nearly the machine accuracy.\nOther singular values will have about the same absolute accuracy as the\nlargest one. The matrices $V$ and $U$ will be orthogonal to nearly machine\naccuracy.\n\nThis implementation gives special treatment to any column of $A$ that is\nexactly zero. If M $>$ N each such column will give rise to an exactly zero\nsingular value in the SING() array. This is convenient if one wishes to\nremove a variable from a problem by just zeroing its column in $A$.\n\n\\subsubsection{Method in SSVA}\n\nWhen the matrix of a least-squares problem is ill-conditioned it will\nfrequently be true that the vector ${\\bf x}$ that minimizes the residual\nnorm $\\|A{\\bf x} - {\\bf b}\\|$ is undesirably large, $i.e.$, $\\|{\\bf x}\\|$ is\nlarge. It is also generally true that there will be other vectors, ${\\bf x}$%\n, that are significantly smaller in norm than the exact solution vector,\nwith only a small increase in the residual norm. One of these\nvectors may be preferable to the true solution as an operational solution\nfor the problem.\n\nThere are various ways to define either a discrete or a continuous family of\ncandidate solutions for a least-squares problem that range from the true\nsolution through ${\\bf x}$'s having smaller norms but allowing\nlarger residual norms. This subroutine gives information on two such\nfamilies of candidate solutions.\n\nTo simplify the discussion we assume M $>$ N; however the subroutine also\nhandles M $\\leq $ N. A useful discrete family of candidate solutions is\nobtained by defining ${\\bf x}^{(i)}$ to be the solution obtained when all\nsingular values following the $i^{th}$ are set to zero. Then ${\\bf x}^{(%\n\\text{N})}$ is the true solution, ${\\bf x}^{(0)}$ is the zero vector, and\nthe intermediate candidate solution vectors satisfy the monotonicity\nconditions, $\\Vert {\\bf x}^{(i)}\\Vert \\leq \\Vert {\\bf x}^{(i+1)}\\Vert $ and $%\n\\Vert A{\\bf x}^{(i)}-{\\bf b}\\Vert \\geq \\Vert A{\\bf x}^{(i+1)}-{\\bf b}\\Vert .$\n\nA useful continuous family of candidate solutions is defined by letting $%\n{\\bf x}^\\lambda $, for $\\lambda \\geq 0$, be the vector that minimizes $\\Vert\nA{\\bf x}-{\\bf b}\\Vert ^2+\\lambda ^2\\Vert {\\bf x}\\Vert ^2$. This is\nequivalent to asking for the solution of the augmented least-squares problem:%\n\\begin{equation*}\n\\left[\n\\begin{array}{c}\nA \\\\\n\\lambda I\n\\end{array}\n\\right] {\\bf x}^\\lambda \\simeq \\left[\n\\begin{array}{c}\n{\\bf b} \\\\ {\\bf 0}\n\\end{array}\n\\right]\n\\end{equation*}\nwhere I denotes the $N^{th}$ order identity matrix. If $\\lambda <\\mu $ then $%\n\\Vert {\\bf x}^\\lambda \\Vert \\geq \\Vert {\\bf x}^\\mu \\Vert $ and $\\Vert A{\\bf x%\n}^\\lambda -{\\bf b}\\Vert \\leq \\Vert A{\\bf x}^\\mu -{\\bf b}\\Vert $. This family\nof candidate solutions is discussed in the literature under various names,\nsuch as ridge regression, damped least-squares, and Levenberg-Marquardt\nstabilization.\n\nSince the units in which variables are expressed is arbitrary and the value\nof $\\|{\\bf x}\\|$, and thus the family of candidate solutions, depends on the\nchoice of units, this subroutine gives the user the ability, via the\nparameters ISCALE and D(), to scale the columns of $A$ and thus the\ncomponents of ${\\bf x}.$\n\nGiven $A$ and ${\\bf b}$ defining a least-squares problem, $A{\\bf x} \\simeq\n{\\bf b}$, SSVA performs the following steps, doing the indicated printing\nonly if selected by the settings of KPVEC().\n\n\\begin{itemize}\n\\item[1a.]  As specified by the user's setting of ISCALE and D(),\nintroduce a nonsingular diagonal scaling matrix, $D$, reformulating the\nproblem as\\ $(AD)(D^{-1}{\\bf x})\\simeq {\\bf b}$. Let ${\\bf y}=D^{-1}{\\bf x}$\nso the problem can be written as $(AD){\\bf y}\\simeq {\\bf b}.$\n\n\\item[1b.]  Use SSVDRS to compute the singular value decomposition of $AD$,\nobtaining $U$, $S$, and $V$ satisfying $AD=USV^t$, and ${\\bf g}=U^t{\\bf b%\n}$. Let $s_i$ denote the $i^{th}$ diagonal element of $S$, $i.e$. the $i^{th}$\nsingular value of $AD$. The scaled solution vector, ${\\bf y}$, is given by $%\n{\\bf y}=VS^{+}U^t{\\bf b}$, and thus may be computed in two steps as ${\\bf p}%\n=S^{+}{\\bf g}$ and ${\\bf y}=V{\\bf p}$. Specifically the components of the\nN-vector ${\\bf p}$ are computed as $p_i=g_i/s_i$ if $s_i\\neq 0$ and $p_i=0$ if $%\ns_i=0.$\n\n\\item[2.]  Print the $V$ matrix.\n\n\\item[3.]  For $i=1$, ..., N, print $s_i$, $p_i$, $1/s_i$, $g_i$,\nand $g_i^2.$\n\nDefine $\\rho _j^2=\\Vert A{\\bf x}^{(j)}-{\\bf b}\\Vert ^2$. This\nquantity is computed as%\n\\begin{equation*}\n\\rho _j^2=\\sum_{i=j+1}^Ng_i^2\n\\end{equation*}\nand is printed with the heading ``Cumulative Sum of Squares.\"\n\nAn estimate of the variance of the errors in the data vector ${\\bf b}$,\nunder the assumption that the singular values following the $j^{th}$ are\nzero, is given by $\\sqrt{\\rho _j^2/(\\text{M}-j)}$. This quantity is printed\nwith the heading ``Scaled Sqrt of Cum. S.S.\" for Scaled Square Root of the\nCumulative Sum of Squares.\n\n\\item[4.]  The quantities $\\Vert {\\bf y}^{(j)}\\Vert $ are computed\n(using the $p_i$'s) and printed along with the corresponding values\nof $\\rho _j$, with the headings YNORM and RNORM.\n\n\\item[5.]  A range of values of the Levenberg-Marquardt parameter, $%\n\\lambda $, and associated $\\Vert {\\bf y}^\\lambda \\Vert $ and $\\Vert AD{\\bf y}%\n^\\lambda -{\\bf b}\\Vert $ are computed and printed. These quantities are\ncomputed from formulas involving $s_i$'s, ${p_i}$'s,\nand ${g_i}$'s.\n\n\\item[6.]  The candidate solutions, ${\\bf x}^{(j)}=D{\\bf y}^{(j)}$, are\ncomputed and printed.\n\\end{itemize}\n\nSSVA calls SPRTSV to print the $V$ matrix and the candidate solutions.\n\n\\subsubsection{Method for SCOV3}\n\nIf the variance of the error in the data vector, ${\\bf b}$, is VAR, the\ncovariance matrix, $C$, for the solution vector, ${\\bf x}$, is conventionally\ndefined as $C = \\text{VAR}\\times (A^tA)^{-1}$. Using the singular value\ndecomposition, $A = USV^t$, one can write $C =\\text{VAR}\\times\n(VS^tSV^t)^{-1} = \\text{VAR}\\times VS^+(VS^+)^t$. SCOV3 computes $C$ using\nthis latter formula.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIn SSVA, if M $\\leq 0$ or N $\\leq 0$ an immediate return will be made.\n\nSSVDRS will issue an error message, set SING$(1) = -1.0$, and do an\nimmediate return if any of the following conditions are noted.\n\n\\hspace{.2in}M $< 1$, N $< 1$, NB $< 0$, LDA $< \\max (\\text{M},\\text{N}),$\n\n\\hspace{.2in}LDB $<$ M when NB $> 0$, or LDB $< 1$ when NB $= 0.$\n\nSCOV3 requires N nonzero singular values. If this is satisfied it will set\nIERR = 0. Otherwise it will set IERR to the index of the first zero singular\nvalue and the results returned in A(,) will be meaningless.\n\nThe subroutine SCOV3 is intended for use following SSVDRS. It cannot be used\nfollowing SSVA since SSVA does not leave the $V$ matrix in the A(,) array on\nreturn.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\nThese subroutines were adapted from \\cite{Lawson:1974:SLS} for use with\nFortran~77 by C.  L.  Lawson and S.  Y.  Chiu, May~1986, June~1987.\nAltered March~1989 by Lawson to introduce the vector KPVEC() to provide\nmore report options.\n\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDCOV3 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDCOPY, DCOV3, DDOT, DSCAL, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDSVA & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DAXPY, DCOPY, DDOT, DHTCC, DHTGEN, DNRM2, DPRTSV, DQRBD, DROT, DROTG, DSVA, DSVDRS, DSWAP, ERFIN, ERMOR, ERMSG, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDSVDRS & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DAXPY, DCOPY, DDOT, DHTCC, DHTGEN, DNRM2, DQRBD, DROT, DROTG, DSVDRS, DSWAP, ERFIN, ERMOR, ERMSG, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSCOV3 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SCOPY, SCOV3, SDOT, SSCAL\\rule[-5pt]{0pt}{8pt}}\\\\\nSSVA & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMOR, ERMSG, IERV1, SAXPY, SCOPY, SDOT, SHTCC, SHTGEN, SNRM2, SPRTSV, SQRBD, SROT, SROTG, SSVA, SSVDRS, SSWAP\\rule[-5pt]{0pt}{8pt}}\\\\\nSSVDRS & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMOR, ERMSG, IERV1, SAXPY, SCOPY, SDOT, SHTCC, SHTGEN, SNRM2, SQRBD, SROT, SROTG, SSVDRS, SSWAP}\\\\\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 DRDSVA}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{dsva}}\n\\newpage\n\\enlargethispage*{8pt}\n\\centerline{\\bf \\large ODDSVA}\\vspace{5pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dsva}}\n\\end{document}\n", "meta": {"hexsha": "b8990829a8040b4bb99fe8f57d90ef1b4001e81e", "size": 23313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch04-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/ch04-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/ch04-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": 42.5419708029, "max_line_length": 148, "alphanum_fraction": 0.7135932741, "num_tokens": 7278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6642130649274312}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[margin=3cm]{geometry}\n\\usepackage{fontspec}\n\\usepackage{amsmath, amsfonts}\n\\usepackage{enumitem}\n\\usepackage{algorithm}\n\\usepackage{algorithmicx}\n\\usepackage{algpseudocode}\n\\PassOptionsToPackage{hyphens}{url}\\usepackage{hyperref}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{0.5em}\n\\def\\arraystretch{1.5}\n\n\\algnewcommand\\algorithmicinput{\\textbf{Input:}}\n\\algnewcommand\\INPUT{\\item[\\algorithmicinput]}\n\\algnewcommand\\algorithmicoutput{\\textbf{Output:}}\n\\algnewcommand\\OUTPUT{\\item[\\algorithmicoutput]}\t\n\n\\title{A public-key criptosystem}\n\\author{Arnau \\and Joan \\and Marc}\n\n\\begin{document}\n\\maketitle\n\\section*{Statement}\nLet us consider the following public-key cryptosystem based on \\textsc{Subset Sum}:\n\n\\begin{enumerate}[label=\\alph*)]\n\t\\item The \\emph{private key} consists of a \\emph{superincreasing} sequence $E = (e_1, ..., e_n)$ of integers, an integer $m$ greater that the sum of all the elements $e_1, ..., e_n$ and an integer $w$ that is relatively prime to $m$. (A sequence $e_1, ..., e_n$ is called \\emph{superincreasing} if each element $e_i$ is strictly greater than the sum of all previous elements).\n\t\\item The \\emph{public key} is a sequence $H = (h_1, ..., h_n)$ derived from the private key via $h_i = (we_i) \\pmod{m}$.\n\t\\item The encryption of an $n$-bit message $X = (x_1, ..., x_n)$ is the number $c = HX = \\sum_{i=1}^n h_ix_i$.\n\t\\item Decrypting the message amounts to solving $c = HX$ for $X \\in \\{0, 1\\}^n$, which is of course equivalent to solving \\textsc{Subset Sum} for H with target sum $c$. The owner of the private key, however, can simplify the decryption considerably by calculating $w^{-1}c \\equiv_m EX$.\n\t\n\t(Now the condition $m > \\sum_{i=1}^n e_i$ allows us to replace '$\\equiv_m$' by '$=$')\n\\end{enumerate}\n\n\\section*{Solution}\nLet us see that the problem of, given an encrypted message $c$ and a private key $\\langle E = (e_1, ..., e_n), m, w \\rangle$, decrypting $c$, can be solved in polynomial time.\n\\begin{enumerate}[label=\\roman*)]\n\t\\item Show that $w^{-1}c = EX$.\n\\end{enumerate}\nWe want to prove that $w^{-1}c = EX$ so, using all the previous definitions:\n\\begin{gather*}\n\tw^{-1}c = EX \\pmod{m} \\iff w^{-1}c = EX \\iff w^{-1}c = \\sum_{i=1}^{n} e_i x_i \\iff \\\\\n\t\\iff w^{-1} \\sum_{i=1}^n h_i x_i = \\sum_{i=1}^n e_i x_i \\iff \\sum_{i=1}^n \\underbrace{w^{-1}w}_1 e_i x_i = \\sum_{i=1}^n e_i x_i\n\\end{gather*}\n\n\\begin{enumerate}[resume, label=\\roman*)]\n\t\\item Prove that the following problem is a polynomial time computable:\n\t\n\tGiven integers $w$ and $m$ satisfying \\emph{a)}, and an integer $c$ satisfying \\emph{c)}, compute $(w^{-1}c) \\pmod{m}$.\n\\end{enumerate}\nTaking into account that $(w^{-1}c)\\equiv_m(w^{-1}\\mod{m})·(c \\mod{m})$, we know we can compute $w^{-1}\\mod{m}$ in $O(n^3)$ using the Extended Euclid algorithm:\n\n \\textbf{EXT-EUCLID}(w,m) returns (d,x,y) where $d=GCD(w,m)=wx + my=1$ because we know $w$ and $m$ are relatively prime. Working in modular arithmetic $my=_m0$, so $wx=_m 1$, and as a result $x=_m w^{-1}$.\n \n Being $c$ a number, computing $c \\mod{N}$ is also polynomial, and afterwards the only step left is to compute the product of the two results previously obtained and apply the module one last time in $(w^{-1}c) \\pmod{m}$, which are two polynomial operations too. AND WE ARE DONE.\n\n\\begin{enumerate}[resume, label=\\roman*)]\n\t\\item Show that \\textsc{Subset Sum} can be solved in polynomial time if the input sequence of integers is superincreasing. Recall that \\textsc{Subset Sum} is defined by:\n\t\n\tGiven a sequence of integers $e_1, ..., e_n$, and a target integer $W$, compute $X = \\{0, 1\\}^n$ such that $W = EX$ where $E = (e_1, ..., e_n)$. (\\emph{Hint}: be greedy).\n\t\n\tHence, given the superincreasing sequence $E$ and $W = (w^{-1}c) \\pmod{m}$, we can compute the decrypted original message $X$ in polynomial time.\n\\end{enumerate}\n\nThe following greedy algorithm solves the problem in linear time.\n\n\\begin{algorithm}[H]\n\t\\caption{\\textsc{Subset Sum} with superincreasing list}\n%\t\\KwData{}\n%\t\\KwResult{  }\n\\begin{algorithmic}\n\t\\INPUT $E= (e_1, ... , e_n), W $\n\t\\OUTPUT $ X = \\{0,1\\}^n $ such that $W=EX$\n\t\\State \\Comment Each variable $x_j$ is boolean in spirit: it indicates if you include $e_j$ in the sum or not.\n\t\\State $s := 0$ \\Comment Sum variable\n\t\\State $j := n$ \\Comment Index variable\n\t\\While{$ j>0 $ \\and $ s<W $}\n\t\t\\If{$ s + e_j \\leq W $} \\Comment Ifincluding  $e_j$ will not create overflow, we include it.\n\t\t\t\\State $s := s + e_j$\n\t\t\t\\State $x_j := 1$\n\t\t\\Else\n\t\t\t\\State $x_j := 0$\n\t\t\\EndIf\n\t\t\\State $ j := j-1 $\n\t\\EndWhile\n\\end{algorithmic}\n\\end{algorithm}\n\nReference: algorithm explained here \\rightarrow \\url{https://math.stackexchange.com/questions/378148/greedy-optimized-subset-sum-problem}.\n\nThis is a greedy algorithm that solves the \\textsc{Subset Sum} problem without guaranteeing an optimal solution (assuming that $E$ is still an ordered sequence). However, if the input list is superincreasing, the optimal is guaranteed.\n\n\\end{document}", "meta": {"hexsha": "6294d119b8425904b94e1d25e0969c645fb086d8", "size": 4991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examen_3/document.tex", "max_stars_repo_name": "jmigual/AA", "max_stars_repo_head_hexsha": "35ae430a1651cabfb3cfeb7df923272d2d80e84f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examen_3/document.tex", "max_issues_repo_name": "jmigual/AA", "max_issues_repo_head_hexsha": "35ae430a1651cabfb3cfeb7df923272d2d80e84f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examen_3/document.tex", "max_forks_repo_name": "jmigual/AA", "max_forks_repo_head_hexsha": "35ae430a1651cabfb3cfeb7df923272d2d80e84f", "max_forks_repo_licenses": ["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.9895833333, "max_line_length": 377, "alphanum_fraction": 0.6962532559, "num_tokens": 1638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.6642130553086094}}
{"text": "% !TeX root = ./main.tex\n% chktex-file 46\n% !TeX spellcheck = en-GB\n% !TeX encoding = utf8\n\nOur novel graph-based approach to model the dynamics of the agents' health states incorporates communal effects and temporal decease effects through a graph contribution and an individual health contribution term, respectively.\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\t\\label{eq:state_propagation}\n\th_{v_i, m}^{(l+1)}\n\t=\n\t\\underbrace{\n\t\t\\sum_k \\frac{\\hat{A}_{v_i, k}^{(l)}}{\\sum_j \\hat{A}_{v_i, j}^{(l)}} h_{k, m}^{(l)} \\delta_{m, 1}\n\t}_{\\text{\\textcolor{red}{Graph}}}\n\t+\n\t\\underbrace{\n\t\t{(h_{v_i}^{(l)}\\cdot T)}_m\n\t}_{\\text{\\textcolor{blue}{Temporal}}}\n\\end{equation}\nwith $m$ being the health state index ranging from $0$ to $2$, $\\hat{A}_{v_i, k}^{(l)}$ infection-adjusted adjacency matrix component, $\\delta$ the Kronecker delta and $T$ as temporal transition matrix.\n\nThe 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. Figure~\\ref{fig:state_propagation} visualises the propagation rule and the two subsequent sections explain the terms in greater detail.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\columnwidth]{img/state_propagation.pdf}\n\t\\caption{Visualisation of propagation rule from equation~\\eqref{eq:state_propagation}. The blue connection visualises the temporal term and the red connections visualise the graph term. The dashed red line is does not contribute to the graph term as the two nodes are not connected according to $\\hat{A}(l)$.}%\n\t\\label{fig:state_propagation}\n\\end{figure}\n\n\\subsection{Explanation of the graph contribution term}\n\nThe graph contribution models how infected agents spread the disease through contacts with susceptible agents. This is modeled by the term\n\n\\begin{equation}\n\t(h_{v_i, m}^{(l+1)})_{\\text{Graph}} = \n\t\\sum_k \\textcolor{cyan}{\\frac{\\hat{A}_{v_i, k}^{(l)}}{\\sum_j \\hat{A}_{v_i, j}^{(l)}}} h_{k, m}^{(l)} \\textcolor{orange}{\\delta_{m, 1}}.\n\\end{equation}\n\nA sum over all neighbouring agents' features $h_{k,m}^{(l)}$ is weighted by the normalised infection-adjusted graph connections as shown in cyan. The Kronecker delta, as shown in orange, ensures that only the I feature is added as this is the only one that matters during social contacts between agents.\n\nThe 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\t\n\\begin{itemize}\n\t\\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\t\\item The infection matrix is constructed as\n\t\\begin{equation}\n\tI =\n\t\\begin{pmatrix}\n\t0     &  0  & 0 \\\\\n\t\\beta &  0  & \\alpha \\\\\n\t0     &  0  & 0\n\t\\end{pmatrix}\n\t=\n\t{(I_{ij})}_{i,j}\n\t\\end{equation}\n\twith $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~\\cite{Bao2020.03.13.990226}.\n\t\\item $\\hat{A}$, with $\\hat{A}_{ij}\\in [0, 1]$, is the infection-adjusted adjacency matrix that takes the infection interactions into account and is computed as follows\n\t\\begin{equation}\n\t\\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\t\\end{equation}\n\tThe 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\nFigure~\\ref{fig:state_propagation} visualises the influence of the infection-adjusted adjacency matrix to the agents' states at the next time step. The two solid red lines contribute directly while the dashed red lines does not.\n\n\\subsubsection{Explanation of the temporal contribution term}\n\nThe transition of a person's health state $h_{v_i}^{(l)}$ is determined by three rules that are stated in the following:\n\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 complementary probability $1-\\gamma$ denotes that the person remains sick.\n\t\\item A recovered person could have a probability to be re-infected, but we assume this to be zero throughout this work. Thus a recovered person always stays recovered~\\cite{Bao2020.03.13.990226}.\n\\end{itemize}\n\nThese three rules are combined into a temporal transition matrix $T$, which describes the health state of an agent as time passes. This matrix reads as\n\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}\n\nThe temporal update rule based on the health status thus becomes\n\n\\begin{equation}\n\tH^{(l+1)} = H^{(l)} T.\n\\end{equation}\n\nFigure~\\ref{fig:state_propagation} visualises the influence of the temporal component as red line connecting agents at subsequent time steps.", "meta": {"hexsha": "836f37bfc250a79a3eed752f0bd1a0db9315e1c9", "size": 6167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sections/framework.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/sections/framework.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/sections/framework.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": 64.9157894737, "max_line_length": 665, "alphanum_fraction": 0.7392573374, "num_tokens": 1692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6641216390246453}}
{"text": "%---------------------------Oddy-----------------------------\n\\section{Oddy}\n\nLet $\\vec L_4 = \\vec L_0$. The Oddy metric is then defined as\n\\[\nq = \\max_{i\\in\\{0,1,2,3\\}}\\left\\{\n    \\frac{(\\normvec{L_i}^2 - \\normvec{L_{i+1}}^2)^2 \n    + 4 (\\vec L_i \\cdot \\vec L_{i+1})^2}\n    {2 \\normvec{N_{i+1}}^2 }\n  \\right\\}.\n\\]\nThis metric measures the maximum deviation of the metric tensor at the corners of the quadrilateral.\n\nNote that if $\\normvec{N_{i+1}}^2 < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\quadmetrictable{Oddy}%\n{$1$}%                                      Dimension\n{$[0,0.5]$}%                                Acceptable range\n{$[0,DBL\\_MAX]$}%                           Normal range\n{$[0,DBL\\_MAX]$}%                           Full range\n{$0$}%                                      Unit square\n{\\cite{odd:88}}%                            Citation\n{v\\_quad\\_oddy}%                            Verdict function name\n\n", "meta": {"hexsha": "099ad21425f69b4f8aa933d1d0fd64cc6750fede", "size": 915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadOddy.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/QuadOddy.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/QuadOddy.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 36.6, "max_line_length": 100, "alphanum_fraction": 0.443715847, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6641216100270927}}
{"text": "\\lesson{4}{Dec 01 2021 Wed (18:08:39)}{Solving and Graphing Polynomial Functions}{Unit 3}\n\nA function written in factored form gives us the roots of the equation. The roots and the end behavior rules below can be used to create a graph for the function.\n\nSome \\bf{Polynomial Functions} are far more complicated and should be graphed using graphing technology such as graphing software or a graphing calculator. The real number solutions of a \\bf{Polynomial Equation} can be found by identifying the \\bf{x-intercepts} from the graph of the function. Graph the function, using graphing technology and find the point(s) of intersection between the graph and the x-axis.\n\n\\begin{marginfigure}\n    \\centering\n    \\incfig{graph-technology}\n    \\sidecaption{$0.8x^{4} \\times 8x^{3} + 2x^{2} - 7x - 1$ Graphed.}\n    \\label{fig:graph-technology}\n\\end{marginfigure}\n\n\\begin{definition}[Average Rate of Change]\n    \\begin{align}\n        m = \\frac{y_2 - y_1}{x_2 - x_1}\n    \\end{align}\n    \n    \\paragraph{Increasing versus Decreasing}\n    \n    \\begin{itemize}\n        \\item\n        \\item If the \\bf{Average Rate of Change} is \\bf{Positive}, then the function is considered to be \\bf{Increasing}.\n        \\item If the \\bf{Average Rate of Change} is \\bf{Negative}, then the function is considered to be \\bf{Decreasing}.\n    \\end{itemize}\n    \n    \\paragraph{Minimums and Maximums}\n    \n    \\begin{itemize}\n        \\item\n        \\item \\bf{Minimums} are located on the \\bf{Lowest Point of a Graph}. A \\bf{Local Minimum} is the bottom of a \\bf{Valley} or \\bf{Turning Point} where the graph goes from \\bf{Decreasing} to \\bf{Increasing}.\n        \\item \\bf{Maximums} are located on the \\bf{Highest Point of a Graph}. A \\bf{Local Maximum} is the top of a \\bf{Hill} or \\bf{Turning Point} where the graph goes from \\bf{Increasing} to \\bf{Decreasing}.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{example}[Example 1]\n    Determine the zeros of the function $f(x) = (x - 2)(x - 5)(x + 1)$, and describe the end behavior of the graph.\n    The zeros of the function represent the values of $x$ that make the function equal to $0$. Replace the function notation with $0$ to determine the zeros of the function.\n    \n    \\begin{align}\n        f(x) &= (x - 2)(x - 5)(x + 1) \\\\\n        0 &= (x - 2)(x - 5)(x + 1) \\\\\n        0 &= x^3 - 6 \\times x^2 + 3x + 10 \\\\\n        0 &= x^3 - 6 \\times x^2 + 3x + 10 \\\\\n        x &= 0, x = 5, x = -1 \\\\\n    \\end{align}\n    \n    So, from this, we know that the zeros function from this function are: $0, 5, -1$, which means that's where they will intersect the $x-axis$.\n    \n    The function has an \\bf{Odd Degree}, so the ends will travel in the opposite directions. The leading coefficient is positive, so the left side continues down and the right side continues up.\n\\end{example}\n\n\\newpage\n", "meta": {"hexsha": "fec124a87698d6179fc82c73094a02a9ae7e8a77", "size": 2798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-3/lesson-4.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-3/lesson-4.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-3/lesson-4.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.8148148148, "max_line_length": 411, "alphanum_fraction": 0.6722659042, "num_tokens": 823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190226, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6640174276239186}}
{"text": "\\documentclass{article}\n\\usepackage{tabularx}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[top = 2cm, bottom = 2cm, right = 2cm, left = 2cm]{geometry}\n\\usepackage{cite}\n\\usepackage[final]{hyperref}\n\\usepackage{listings}\n\\hypersetup{\n\tcolorlinks=true,\n\tlinkcolor=blue,\n\tcitecolor=blue,\n\tfilecolor=magenta,\n\turlcolor=blue         \n}\n\n\\begin{document}\n\n\\title{Practicle 4\\\\Raytracer - Sphere}\n\\date{23/01/19}\n\\maketitle\n\n\\begin{abstract}\n\tThe last practicals focused on sending rays. Here, we will see how to grab information from a virtual scene and display it.\n\\end{abstract}\n\n\\section{Intersect a sphere}\nTo compute the intersection between a ray and a sphere we'll use an analytic method. The implicit function of a sphere is: $x^2+y^2+z^2 = R^2$ with $P(x, y, z)$ a point in the surface sphere centered in the origin with a rayon of R. We want only points on the ray so we just need to replace $P$ by the ray equation : \\\\\n$|O+Dt|^2 = R^2,$\\\\\n$O^2 + 2DtO + (Dt)^2 = R^2,$\\\\\n$O^2 + D^2t^2 + 2ODt = R^2,$\\\\\n$O^2 + D^2t^2 + 2ODt - R^2 = 0,$\\\\\nWe want to find the $t$ value for the ray.\\\\\n$ D^2t^2 + 2ODt + O^2 - R^2 = 0,$\\\\\nwith $a = D^2$, $b = 2OD$ and $c = O^2 - R^2$ we get a quadratic function ($f(t) = at^2+bt+c$)\\\\\nIf we want to move the sphere we just need to subtract the center $C$ to $P$ and $O$. The equation becomes: $|(O-C)+Dt|^2 = R^2;$\nWe get $a = D^2$, $b = 2(O-C)D$ and $c = (O-C)^2 - R^2$. Because the product for vector is the dot product and D is normalized, $a=1$\\\\\nRemember that quadratic function can be solved in this way: $t_i = \\frac{-b\\pm \\sqrt{b^2-4ac}}{2a}$\n\n\\section{C++ implementation}\nCreate a Sphere class into the device side for storing the center and the radius information. Create now the intersect function: \n\\begin{lstlisting}\n\t__device__ bool Sphere::intersect(const Ray& ray, float& t) {\n\t\tfloat t0, t1;\n\t\tVector3GPU OC = ray.getOrigin() - center_;\n\t\tfloat b = 2.f*dot(oc, ray.getDirection());\n\t\tfloat c = dot(oc, oc) - radius_*radius_;\n\t\t// ...\n\t}\n\\end{lstlisting}\nif the discriminant is negative you just have to return false and don't modify the final image buffer. If there is a collision, just return the red color. For information the smallest value of t is the nearest intersection point.\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale=0.6]{figures/intersect.png}\n\t\\caption{Intersection ray sphere}\n\\end{figure}\n\n\\newpage\n\\section{Compute and show normal information}\nWhen you intersect the sphere you can compute some geometry information like the normal of the point from the intersection point.\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale=0.4]{figures/normal.png}\n\t\\caption{Normal of a sphere}\n\\end{figure}\n\\begin{lstlisting}\n\tVector3 intersection = ray.getOrigin()+ray.getDirection()*t;\n\tVector3 normal = (intersection-world[wid].center_);\n\\end{lstlisting}\n\nTo be sure our normal is correctly computed we can show them on the sphere. We just have to be careful because normal are between (-1, -1, -1) and (1, 1, 1). So we just have to multiply the normal by 0.5 and add the vector (0.5, 0.5, 0.5) to match the $[0, 1]^3$ range.\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale=0.6]{figures/intersectnormal.png}\n\t\\caption{Intersection ray sphere}\n\\end{figure}\n\\newpage\n\\section{A world of spheres}\nTo avoid the creation of the world inside each kernel we can generate it one on the host side. Add the keyword \\_\\_host\\_\\_ to the constructor of the Sphere class and create a buffer of spheres. \n\\begin{lstlisting}\nstd::vector<Sphere> spheres;\nworld.push_back(Sphere(Vector3(0.f, 0.f, -3.f), 0.5f));\nworld.push_back(Sphere(Vector3(0.f, -100.5f, -3.f), 100.f));\nSphere* spheresGPU;\ncudaMalloc(&spheresGPU, sizeof(Sphere)*spheres.size());\ncudaMemcpy(spheresGPU, &spheres[0], sizeof(Sphere)*spheres.size(), cudaMemcpyHostToDevice);\n\\end{lstlisting}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/intersectnormaltwosphere.png}\n\t\\caption{Intersection ray two spheres}\n\\end{figure}\n\nFor advenced groups, you can take a look in other intersection at this address: http://iquilezles.org/www/articles/intersectors/intersectors.htm\n\n\\newpage\n\\section{CUDA errors}\nEach CUDA function return error value. We can store it in a cudaError\\_t.\n\\begin{lstlisting}\n\tcudaError_t err = cudaMalloc(...);\n\tif (err != cudaSuccess) {\n\t\tstd::cout<<cudaGetErrorString(err);\n\t}\n\\end{lstlisting}\nThe kernel computation don't return value. So if there is an error in the kernel we have to wait the end of the kernel execution and synchronize the device with the host and grab the last error.\\\\\nMost of the time, when we compute heavy algorithm we get some error about kernel configuration. Commun errors are:\n\\begin{itemize}\n\t\\item Too Many Resources Requested for Launch (That mean each thread need more registe that the SM can provide. Reducing the number of thread per block solve this error)\n\t\\item an illegal memory access was encountered. You may read values outside your buffers or you stack pointer (GPU threads are designed to be short process. If you use recursive function you may saturate one of your callstack and get this error. If you really need to call a lot of function, you can increase the size of your callstack using cudaDeviceSetLimit)\n\\end{itemize}\n\\begin{lstlisting}\n\tcudaError_t err = cudaGetLastError();\n\tif (err != cudaSuccess) {\n\t\tstd::cout<<cudaGetErrorString(err);\n\t}\n\\end{lstlisting}\n\n\\end{document}", "meta": {"hexsha": "b50cccce0d333ace560dce62f01cfbead534920f", "size": 5403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04_practicle/04_practicle.tex", "max_stars_repo_name": "robinfaurypro/cuda_lessons", "max_stars_repo_head_hexsha": "e161a6fd1138ea39b08673c2c9cb04a8126332ce", "max_stars_repo_licenses": ["MIT"], "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_practicle/04_practicle.tex", "max_issues_repo_name": "robinfaurypro/cuda_lessons", "max_issues_repo_head_hexsha": "e161a6fd1138ea39b08673c2c9cb04a8126332ce", "max_issues_repo_licenses": ["MIT"], "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_practicle/04_practicle.tex", "max_forks_repo_name": "robinfaurypro/cuda_lessons", "max_forks_repo_head_hexsha": "e161a6fd1138ea39b08673c2c9cb04a8126332ce", "max_forks_repo_licenses": ["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.7881355932, "max_line_length": 362, "alphanum_fraction": 0.7338515639, "num_tokens": 1591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401363, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.6639932535658885}}
{"text": "\\chapter{Preliminaries}\\label{chap:preliminaries}\n\n\\section{General Notation}\n\nWe'll refer to \\(\\reals\\) for the reals, \\(\\utri\\) represents\nthe unit triangle (or unit simplex) in \\(\\reals^2\\):\n\\(\\utri = \\left\\{(s, t) \\mid 0 \\leq s, t, s + t \\leq 1\\right\\}\\).\nWhen dealing with sequences with multiple indices, e.g.\n\\(s_{m, n} = m + n\\), we'll use bold symbols to represent\na multi-index: \\(\\bm{i} = (m, n)\\). We'll use \\(\\left|\\bm{i}\\right|\\) to\nrepresent the sum of the components in a multi-index.\nThe binomial coefficient\n\\(\\binom{n}{k}\\) is equal to \\(\\frac{n!}{k! (n - k)!}\\) and the trinomial\ncoefficient \\(\\binom{n}{i, j, k}\\) is equal to \\(\\frac{n!}{i! j! k!}\\)\n(where \\(i + j + k = n\\)). The notation \\(\\delta_{ij}\\) represents the\nKronecker delta, a value which is \\(1\\) when \\(i = j\\) and \\(0\\)\notherwise.\n\n\\section{Floating Point and Forward Error Analysis}\n\nWe assume all floating point operations obey\n\\begin{equation}\n  a \\star b = \\fl{a \\circ b} = (a \\circ b)(1 + \\delta_1) =\n  (a \\circ b) / (1 + \\delta_2)\n\\end{equation}\nwhere \\(\\star \\in \\left\\{\\oplus, \\ominus, \\otimes, \\oslash\\right\\}\\), \\(\\circ\n\\in \\left\\{+, -, \\times, \\div\\right\\}\\) and \\(\\left|\\delta_1\\right|,\n\\left|\\delta_2\\right| \\leq \\mach\\). The symbol \\(\\mach\\) is the unit round-off\nand \\(\\star\\) is a floating point operation, e.g.\n\\(a \\oplus b = \\fl{a + b}\\). (For IEEE-754 floating point double precision,\n\\(\\mach = 2^{-53}\\).) We denote the computed result of\n\\(\\alpha \\in \\reals\\) in floating point arithmetic by\n\\(\\widehat{\\alpha}\\) or \\(\\fl{\\alpha}\\) and use \\(\\floats\\) as the set of\nall floating point numbers (see \\cite{Higham2002} for more details).\nFollowing \\cite{Higham2002}, we will use the following classic properties in\nerror analysis.\n\n\\begin{enumerate}\n  \\item If \\(\\delta_i \\leq \\mach\\), \\(\\rho_i = \\pm 1\\), then\n      \\(\\prod_{i = 1}^n (1 + \\delta_i)^{\\rho_i} = 1 + \\theta_n\\),\n  \\item \\(\\left|\\theta_n\\right| \\leq \\gamma_n \\coloneqq\n      n \\mach / (1 - n \\mach)\\),\n  \\item \\((1 + \\theta_k)(1 + \\theta_j) = 1 + \\theta_{k + j}\\),\n  \\item \\(\\gamma_k + \\gamma_j + \\gamma_k \\gamma_j \\leq \\gamma_{k + j}\n    \\Longleftrightarrow (1 + \\gamma_k)(1 + \\gamma_j) \\leq 1 + \\gamma_{k + j}\\),\n  \\item \\((1 + \\mach)^j \\leq 1 / (1 - j \\mach) \\Longleftrightarrow\n  (1 + \\mach)^j - 1 \\leq \\gamma_j\\).\n\\end{enumerate}\n\n\\section{B\\'{e}zier Curves}\n\nA \\emph{B\\'{e}zier curve} is a mapping from the unit interval\nthat is determined by a set of control points\n\\(\\left\\{\\bm{p}_j\\right\\}_{j = 0}^n \\subset \\reals^d\\).\nFor a parameter \\(s \\in \\left[0, 1\\right]\\), there is a corresponding\npoint on the curve:\n\\begin{equation}\nb(s) = \\sum_{j = 0}^n \\binom{n}{j} (1 - s)^{n - j} s^j \\bm{p}_j \\in\n  \\reals^d.\n\\end{equation}\nThis is a combination of the control points weighted by\neach Bernstein basis function\n\\(B_{j, n}(s) = \\binom{n}{j} (1 - s)^{n - j} s^j\\).\nDue to the binomial expansion\n\\(1 = (s + (1 - s))^n = \\sum_{j = 0}^n B_{j, n}(s)\\),\na Bernstein basis function is in\n\\(\\left[0, 1\\right]\\) when \\(s\\) is as well. Due to this fact, the\ncurve must be contained in the convex hull of it's control points.\n\n\\subsection{de Casteljau Algorithm}\n\nNext, we recall\\footnote{We have used slightly non-standard notation for the\nterms produced by the de Casteljau algorithm: we start the superscript at\n\\(n\\) and count down to \\(0\\) as is typically done when describing Horner's\nalgorithm. For example, we use \\(b_j^{(n - 2)}\\) instead of\n\\(b_j^{(2)}\\).} the de Casteljau algorithm:\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{de Casteljau algorithm for polynomial evaluation.}}\n  \\label{alg:de-casteljau}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\mathtt{result} = \\mathtt{DeCasteljau}\\)}{$b, s$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\State \\(\\widehat{r} = 1 \\ominus s\\)\n      \\\\\n      \\For{\\(j = 0, \\ldots, n\\)}\n        \\State \\(\\widehat{b}_j^{(n)} = b_j\\)\n      \\EndFor\n      \\\\\n      \\For{\\(k = n - 1, \\ldots, 0\\)}\n        \\For{\\(j = 0, \\ldots, k\\)}\n          \\State \\(\\widehat{b}_j^{(k)} = \\left(\n              \\widehat{r} \\otimes \\widehat{b}_j^{(k + 1)}\\right) \\oplus\n              \\left(s \\otimes \\widehat{b}_{j + 1}^{(k + 1)}\\right)\\)\n        \\EndFor\n      \\EndFor\n      \\\\\n      \\State \\(\\mathtt{result} = \\widehat{b}_0^{(0)}\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\begin{theorem}[\\cite{Mainar1999}, Corollary 3.2]\nIf \\(p(s) = \\sum_{j = 0}^n b_j B_{j, n}(s)\\) and \\(\\mathtt{DeCasteljau}(p, s)\\)\nis the value computed by the de Casteljau algorithm then\\footnote{In the\noriginal paper the factor on \\(\\widetilde{p}(s)\\) is \\(\\gamma_{2n}\\),\nbut the authors did not consider round-off when computing\n\\(1 \\ominus s\\).}\n\\begin{equation}\n\\left|p(s) - \\mathtt{DeCasteljau}(p, s)\\right| \\leq \\gamma_{3n}\n\\sum_{j = 0}^n \\left|b_j\\right| B_{j, n}(s).\n\\end{equation}\n\\end{theorem}\n\nThe relative condition number of the evaluation of \\(p(s) = \\sum_{j = 0}^n\nb_j B_{j, n}(s)\\) in Bernstein form used in this work is (see\n\\cite{Mainar1999, Farouki1987}):\n\\begin{equation}\n\\cond{p, s} = \\frac{\\widetilde{p}(s)}{\\left|p(s)\\right|},\n\\end{equation}\nwhere\n\\(\\widetilde{p}(s) \\coloneqq \\sum_{j = 0}^n \\left|b_j\\right| B_{j, n}(s)\\).\n\nTo be able to express the algorithm in matrix form, we define\nthe vectors\n\\begin{equation}\nb^{(k)} = \\left[\\begin{array}{c c c} b_0^{(k)} & \\cdots &\nb_k^{(k)}\\end{array}\\right]^T, \\quad\n\\widehat{b}^{(k)} = \\left[\\begin{array}{c c c} \\widehat{b}_0^{(k)} & \\cdots &\n    \\widehat{b}_k^{(k)}\\end{array}\\right]^T\n\\end{equation}\nand the reduction matrices:\n\\begin{equation}\nU_k = U_k(s) = \\left[\\begin{array}{c c c c c c}\n    1 - s  & s      & 0      & \\cdots & \\cdots & 0      \\\\\n    0      & 1 - s  & s      & \\ddots &        & \\vdots \\\\\n    \\vdots & \\ddots & \\ddots & \\ddots & \\ddots & \\vdots \\\\\n    \\vdots &        & \\ddots & \\ddots & \\ddots & 0 \\\\\n    0      & \\cdots & \\cdots & 0      & 1 - s  & s\n\\end{array}\\right] \\in \\reals^{k \\times (k + 1)}.\n\\end{equation}\nWith this, we can express (\\cite{Mainar1999}) the de Casteljau algorithm as\n\\begin{equation}\\label{eq:matrix-de-casteljau}\nb^{(k)} = U_{k + 1} b^{(k + 1)}\n\\Longrightarrow b^{(0)} = U_1 \\cdots U_n b^{(n)}.\n\\end{equation}\n\nIn general, for a sequence \\(v_0, \\ldots, v_n\\) we'll refer to \\(v\\)\nas the vector containing all of the values:\n\\(v = \\left[\\begin{array}{c c c} v_0 & \\cdots &\n    v_n\\end{array}\\right]^T.\\)\n\n\\section{B\\'{e}zier Triangles}\n\nA \\emph{B\\'{e}zier triangle} (\\cite[Chapter~17]{Farin2001}) is a\nmapping from the unit triangle\n\\(\\utri\\) and is determined by a control net\n\\(\\left\\{\\bm{p}_{i, j, k}\\right\\}_{i + j + k = n} \\subset \\reals^d\\).\nA B\\'{e}zier triangle is a particular kind of B\\'{e}zier surface, i.e. one\nin which there are two cartesian or three barycentric input parameters.\nOften the term B\\'{e}zier surface is used to refer to a tensor product or\nrectangular patch.\nFor \\((s, t) \\in \\utri\\) we can define barycentric weights\n\\(\\lambda_1 = 1 - s - t, \\lambda_2 = s, \\lambda_3 = t\\) so that\n\\begin{equation}\n1 = \\left(\\lambda_1 + \\lambda_2 + \\lambda_3\\right)^n =\n  \\sum_{\\substack{i + j + k = n \\\\ i, j, k \\geq 0}} \\binom{n}{i, j, k}\n  \\lambda_1^i \\lambda_2^j \\lambda_3^k.\n\\end{equation}\nUsing this we can similarly define a (triangular) Bernstein basis\n\\begin{equation}\nB_{i, j, k}(s, t) = \\binom{n}{i, j, k} (1 - s - t)^i s^j t^k\n  = \\binom{n}{i, j, k} \\lambda_1^i \\lambda_2^j \\lambda_3^k\n\\end{equation}\nthat is in \\(\\left[0, 1\\right]\\) when \\((s, t)\\) is in \\(\\utri\\).\nUsing this, we define points on the B\\'{e}zier triangle as a\nconvex combination of the control net:\n\\begin{equation}\nb(s, t) = \\sum_{i + j + k = n} \\binom{n}{i, j, k}\n  \\lambda_1^i \\lambda_2^j \\lambda_3^k\n  \\bm{p}_{i, j, k} \\in \\reals^d.\n\\end{equation}\n\n\\begin{figure}\n  \\includegraphics{../images/preliminaries/main_figure01.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Cubic B\\'{e}zier triangle}\n  \\label{fig:cubic-bezier-example}\n\\end{figure}\n\n\\noindent Rather than defining a B\\'{e}zier triangle by the control net, it can\nalso be uniquely determined by the image of a standard lattice of\npoints in \\(\\utri\\): \\(b\\left(j/n, k/n\\right) = \\bm{n}_{i, j, k}\\);\nwe'll refer to these as \\emph{standard nodes}.\nFigure~\\ref{fig:cubic-bezier-example} shows these standard nodes for\na cubic triangle in \\(\\reals^2\\). To see the correspondence,\nwhen \\(p = 1\\) the standard nodes \\emph{are} the control net\n\\begin{equation}\nb(s, t) = \\lambda_1 \\bm{n}_{1, 0, 0} +\n\\lambda_2 \\bm{n}_{0, 1, 0} + \\lambda_3 \\bm{n}_{0, 0, 1}\n\\end{equation}\nand when \\(p = 2\\)\n\\begin{multline}\nb(s, t) = \\lambda_1\\left(2 \\lambda_1 - 1\\right) \\bm{n}_{2, 0, 0} +\n\\lambda_2\\left(2 \\lambda_2 - 1\\right) \\bm{n}_{0, 2, 0} +\n\\lambda_3\\left(2 \\lambda_3 - 1\\right) \\bm{n}_{0, 0, 2} + \\\\\n4 \\lambda_1 \\lambda_2 \\bm{n}_{1, 1, 0} +\n4 \\lambda_2 \\lambda_3 \\bm{n}_{0, 1, 1} +\n4 \\lambda_3 \\lambda_1 \\bm{n}_{1, 0, 1}.\n\\end{multline}\nHowever, it's worth noting that the transformation between\nthe control net and the standard nodes has condition\nnumber that grows exponentially with \\(n\\) (see \\cite{Farouki1991}, which\nis related but does not directly show this).\nThis may make working with\nhigher degree triangles prohibitively unstable.\n\nA \\emph{valid} B\\'{e}zier triangle is one which is\ndiffeomorphic to \\(\\utri\\), i.e. \\(b(s, t)\\) is bijective and has\nan everywhere invertible Jacobian. We must also have the orientation\npreserved, i.e. the Jacobian must have positive determinant. For example, in\nFigure~\\ref{fig:inverted-element}, the image of \\(\\utri\\) under\nthe map \\(b(s, t) = \\left[\\begin{array}{c c} (1 - s - t)^2 + s^2 & s^2 + t^2\n\\end{array}\\right]^T\\) is not valid because the Jacobian is zero along\nthe curve \\(s^2 - st - t^2 - s + t = 0\\) (the dashed line). Elements that\nare not valid are called \\emph{inverted} because they have regions with\n``negative area''. For the example, the image \\(b\\left(\\utri\\right)\\)\nleaves the boundary determined by the edge curves: \\(b(r, 0)\\),\n\\(b(1 - r, r)\\) and \\(b(0, 1 - r)\\) when \\(r \\in \\left[0, 1\\right]\\).\nThis region outside the boundary is traced twice, once with\na positive Jacobian and once with a negative Jacobian.\n\\begin{figure}\n  \\includegraphics{../images/preliminaries/inverted_element.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{The B\\'{e}zier triangle given by \\(b(s, t) = \\left[\n    (1 - s - t)^2 + s^2 \\; \\; s^2 + t^2 \\right]^T\\) produces an\n    inverted element. It traces the same region twice, once with\n    a positive Jacobian (the middle column) and once with a negative\n    Jacobian (the right column).}\n  \\label{fig:inverted-element}\n\\end{figure}\n\n\\section{Curved Elements}\\label{sec:curved-elements}\n\nWe define a curved mesh element \\(\\mathcal{T}\\) of degree \\(p\\)\nto be a B\\'{e}zier triangle in \\(\\reals^2\\) of the same degree.\nWe refer to the component functions of \\(b(s, t)\\) (the map that\ngives \\(\\mathcal{T} = b\\left(\\utri\\right)\\)) as \\(x(s, t)\\) and \\(y(s, t)\\).\n\nThis fits a typical definition (\\cite[Chapter~12]{FEM-ClaesJohnson})\nof a curved element, but gives a special meaning to the mapping from\nthe reference triangle. Interpreting elements as B\\'{e}zier triangles\nhas been used for Lagrangian methods where\nmesh adaptivity is needed (e.g. \\cite{CardozeMOP04}). Typically curved\nelements only have one curved side (\\cite{McLeod1972}) since they are used\nto resolve geometric features of a boundary. See also\n\\cite{Zlmal1973, Zlmal1974}.\nB\\'{e}zier curves and triangles have a number of mathematical properties\n(e.g. the convex hull property) that lead to elegant geometric\ndescriptions and algorithms.\n\nNote that a B\\'{e}zier triangle can be\ndetermined from many different sources of data (for example the control net\nor the standard nodes). The choice of this data may be changed to suit the\nunderlying physical problem without changing the actual mapping. Conversely,\nthe data can be fixed (e.g. as the control net) to avoid costly basis\nconversion; once fixed, the equations of motion and other PDE terms can\nbe recast relative to the new basis (for an example, see \\cite{Persson2009},\nwhere the domain varies with time but the problem is reduced to\nsolving a transformed conservation law in a fixed reference configuration).\n\n\\subsection{Shape Functions}\\label{subsec:shape-functions}\n\nWhen defining shape functions (i.e. a basis with geometric meaning) on a\ncurved element there are (at least) two choices. When the degree of the\nshape functions is the same as the degree of the function being\nrepresented on the B\\'{e}zier triangle,\nwe say the element \\(\\mathcal{T}\\) is \\emph{isoparametric}.\nFor the multi-index\n\\(\\bm{i} = (i, j , k)\\), we define \\(\\bm{u}_{\\bm{i}} =\n\\left(j/n, k/n\\right)\\) and the corresponding standard node\n\\(\\bm{n}_{\\bm{i}} = b\\left(\\bm{u}_{\\bm{i}}\\right)\\).\nGiven these points, two choices for shape functions present\nthemselves:\n\\begin{itemize}\n  \\itemsep 0em\n  \\item \\emph{Pre-Image Basis}:\n    \\(\\phi_{\\bm{j}}\\left(\\bm{n}_{\\bm{i}}\\right) =\n      \\widehat{\\phi}_{\\bm{j}}\\left(\\bm{u}_{\\bm{i}}\\right) =\n      \\widehat{\\phi}_{\\bm{j}}\\left(b^{-1}\\left(\n      \\bm{n}_{\\bm{i}}\\right)\\right)\\)\n    where \\(\\widehat{\\phi}_{\\bm{j}}\\) is a canonical basis function\n    on \\(\\utri\\), i.e.\n    \\(\\widehat{\\phi}_{\\bm{j}}\\) a degree \\(p\\) bivariate polynomial and\n    \\(\\widehat{\\phi}_{\\bm{j}}\\left(\\bm{u}_{\\bm{i}}\\right) =\n    \\delta_{\\bm{i} \\bm{j}}\\)\n  \\item \\emph{Global Coordinates Basis}:\n    \\(\\phi_{\\bm{j}}\\left(\\bm{n}_{\\bm{i}}\\right) =\n    \\delta_{\\bm{i} \\bm{j}}\\), i.e. a canonical basis function\n    on the standard nodes \\(\\left\\{\\bm{n}_{\\bm{i}}\\right\\}\\).\n\\end{itemize}\n\n\\noindent For example, consider a quadratic B\\'{e}zier triangle:\n\\begin{gather}\nb(s, t) = \\left[ \\begin{array}{c c}\n    4 (s t + s + t) & 4 (s t + t + 1)\n  \\end{array}\\right]^T \\\\\n\\Longrightarrow\n\\left[ \\begin{array}{c c c c c c}\n    \\bm{n}_{2, 0, 0} &\n    \\bm{n}_{1, 1, 0} &\n    \\bm{n}_{0, 2, 0} &\n    \\bm{n}_{1, 0, 1} &\n    \\bm{n}_{0, 1, 1} &\n    \\bm{n}_{0, 0, 2}\n  \\end{array}\\right] = \\left[ \\begin{array}{c c c c c c}\n    0 & 2 & 4 & 2 & 5 & 4 \\\\\n    4 & 4 & 4 & 6 & 7 & 8\n  \\end{array}\\right].\n\\end{gather}\nIn the \\emph{Global Coordinates Basis}, we have\n\\begin{equation}\n\\phi^{G}_{0, 1, 1}(x, y) = \\frac{(y - 4) (x - y + 4)}{6}.\n\\end{equation}\nFor the \\emph{Pre-Image Basis}, we need the inverse\nand the canonical basis\n\\begin{equation}\nb^{-1}(x, y) = \\left[ \\begin{array}{c c}\n    \\frac{x - y + 4}{4} & \\frac{y - 4}{x - y + 8}\n  \\end{array}\\right] \\quad \\text{and} \\quad\n\\widehat{\\phi}_{0, 1, 1}(s, t) = 4 s t\n\\end{equation}\nand together they give\n\\begin{equation}\n\\phi^{P}_{0, 1, 1}(x, y) = \\frac{(y - 4) (x - y + 4)}{x - y + 8}.\n\\end{equation}\nIn general \\(\\phi_{\\bm{j}}^P\\) may not even be a rational bivariate\nfunction; due to composition with \\(b^{-1}\\) we can only guarantee that\nit is algebraic (i.e. it can be defined as the zero set of polynomials).\n\n\\subsection{Curved Polygons}\\label{subsec:curved-polygons}\n\n\\begin{figure}\n  \\includegraphics{../images/preliminaries/main_figure26.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Intersection of B\\'{e}zier triangles form a curved polygon.}\n  \\label{fig:bezier-triangle-intersect}\n\\end{figure}\n\nWhen intersecting two curved elements, the resulting surface(s) will\nbe defined by the boundary, alternating between edges of each\nelement.\nFor example, in Figure~\\ref{fig:bezier-triangle-intersect}, a\n``curved quadrilateral'' is formed when two B\\'{e}zier triangles\n\\(\\mathcal{T}_0\\) and \\(\\mathcal{T}_1\\) are intersected.\n\nA \\emph{curved polygon} is defined by a collection of B\\'{e}zier curves\nin \\(\\reals^2\\) that determine the boundary. In order to be\na valid polygon, none of the boundary curves may cross, the\nends of consecutive edge curves must meet and the curves must be right-hand\noriented. For our example in\nFigure~\\ref{fig:bezier-triangle-intersect}, the triangles\nhave boundaries formed by three B\\'{e}zier curves:\n\\(\\partial \\mathcal{T}_0 = b_{0, 0} \\cup b_{0, 1} \\cup b_{0, 2}\\) and\n\\(\\partial \\mathcal{T}_1 = b_{1, 0} \\cup b_{1, 1} \\cup b_{1, 2}\\).\nThe intersection \\(\\mathcal{P}\\) is defined by four boundary\ncurves: \\(\\partial \\mathcal{P} =\nC_1 \\cup C_2 \\cup C_3 \\cup C_4\\). Each boundary\ncurve is itself a B\\'{e}zier curve\\footnote{A specialization of a\nB\\'{e}zier curve \\(b\\left(\\left[a_1, a_2\\right]\\right)\\)\nis also a B\\'{e}zier curve.}:\n\\(C_1 = b_{0, 0}\\left(\\left[0, 1/8\\right]\\right)\\),\n\\(C_2 = b_{1, 2}\\left(\\left[7/8, 1\\right]\\right)\\),\n\\(C_3 = b_{1, 0}\\left(\\left[0, 1/7\\right]\\right)\\) and\n\\(C_4 = b_{0, 2}\\left(\\left[6/7, 1\\right]\\right)\\).\n\nThough an intersection can be described in terms of the B\\'{e}zier triangles,\nthe structure of the control net will be lost. The region will not in general\nbe able to be described by a mapping from a simple space like\n\\(\\utri\\).\n\n\\section{Error-Free Transformation}\n\nAn error-free transformation is a computational method where both\nthe computed result and the round-off error are returned. It\nis considered ``free'' of error if the round-off can be represented\nexactly as an element or elements of \\(\\floats\\).\nThe error-free transformations used in this work are\nthe \\texttt{TwoSum} algorithm by Knuth (\\cite{Knuth1997}) and\n\\texttt{TwoProd} algorithm by Dekker (\\cite{Dekker1971}, Section 5),\nrespectively.\n\n\\begin{theorem}[\\cite{Ogita2005}, Theorem 3.4]\\label{thm:eft}\nFor \\(a, b \\in \\floats\\) and \\(P, \\pi, S, \\sigma \\in \\floats\\),\n\\texttt{TwoSum} and \\texttt{TwoProd} satisfy\n\\begin{alignat}{4}\n\\left[S, \\sigma\\right] &= \\mathtt{TwoSum}(a, b), & \\, S &= \\fl{a + b},\n  S + \\sigma &= a + b, \\sigma &\\leq \\mach \\left|S\\right|,\n  & \\, \\sigma &\\leq \\mach \\left|a + b\\right| \\\\\n\\left[P, \\pi\\right] &= \\mathtt{TwoProd}(a, b),\n  & \\, P &= \\fl{a \\times b}, P + \\pi &= a \\times b,\n  \\pi &\\leq \\mach \\left|P\\right|,\n  & \\, \\pi &\\leq \\mach \\left|a \\times b\\right|.\n\\end{alignat}\nThe letters \\(\\sigma\\) and \\(\\pi\\) are used to indicate that the\nerrors came from sum and product, respectively. See\nAppendix~\\ref{chap:appendix-algo} for implementation details.\n\\end{theorem}\n", "meta": {"hexsha": "6ea6e93673262a6e524fadc6b2adbc8d31217d3f", "size": 17911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/preliminaries.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/preliminaries.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/preliminaries.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": 43.3680387409, "max_line_length": 79, "alphanum_fraction": 0.6546814807, "num_tokens": 6405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303285397349, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.6638351630085586}}
{"text": "% Part: first-order-logic\n% Chapter: model-theory\n% Section: partial-iso\n\n\\documentclass[../../../include/open-logic-section]{subfiles}\n\n\\begin{document}\n\n\\olfileid{mod}{bas}{dlo}\n\\section{Dense Linear Orders}\n\n\\begin{defn}\n  A \\emph{dense linear ordering without endpoints} is !!a{structure}\n  $\\Struct{M}$ for the !!{language} containg a single 2-place\n  !!{predicate}~$<$ satisfying the following sentences:\n  \\begin{enumerate}\n  \\item $\\lforall[x][\\lnot x < x]$;\n  \\item $\\lforall[x][\\lforall[y][\\lforall[z][(x < y \\lif (y < z \\lif x\n    <z ))]]]$;\n  \\item $\\lforall[x][\\lforall[y][(x< y \\lor \\eq[x][y] \\lor y < x)]]$;\n  \\item $\\lforall[x][\\lexists[y][x < y]]$;\n  \\item $\\lforall[x][\\lexists[y][y < x]]$;\n  \\item $\\lforall[x][\\lforall[y][(x < y \\lif \\lexists[z][(x < z \\land\n        z < y))]]]$.\n \\end{enumerate}\n\\end{defn}\n\n\\begin{thm}\\ollabel{thm:cantorQ}\n  Any two !!{enumerable} dense linear orderings without\n  endpoints are isomorphic.\n\\end{thm}\n\n\\begin{proof}\n  Let $\\Struct{M_1}$ and $\\Struct{M_2}$ be !!{enumerable} dense linear\n  orderings without endpoints, with ${<_1} = \\Assign{<}{M_1}$ and ${<_2} =\n  \\Assign{<}{M_2}$, and let $\\PIso{I}$ be the set of all partial\n  isomorphisms between them. $\\PIso{I}$ is not empty since at least\n  $\\emptyset \\in \\PIso{I}$. We show that $\\PIso{I}$ satisfies the\n  Back-and-Forth property.  Then $\\Struct{M_1} \\iso[p] \\Struct{M_2}$,\n  and the theorem follows by \\olref[pis]{thm:p-isom1}.\n\n  To show $\\PIso{I}$ satisifes the Forth property, let $p \\in\n  \\PIso{I}$ and let $p(a_i) = b_i$ for $i = 1$, \\dots,~$n$, and\n  without loss of generality suppose $a_1 <_1 a_2 <_1 \\cdots <_1\n  a_n$. Given $a \\in \\Domain{M_1}$, find $b \\in \\Domain{M_2}$ as\n  follows:\n  \\begin{enumerate}\n  \\item if $a <_2 a_1$ let $b \\in \\Domain{M_2}$ be such that $b <_2\n    b_1$;\n  \\item if $a_n <_1 a$ let $b \\in \\Domain{M_2}$ be such that $b_n <_2 b$;\n \\item if $a_i <_1 a <_1 a_{i+1}$ for some $i$, then let $b \\in\n   \\Domain{M_2}$ be such that $b_i <_2 b <_2 b_{i+1}$.\n  \\end{enumerate}\n  It is always possible to find a $b$ with the desired property since\n  $\\Struct{M_2}$ is a dense linear ordering without endpoints. Define\n  $q = p \\cup \\{ \\langle a, b \\rangle \\}$ so that $q \\in \\PIso{I}$ is\n  the desired extension of $p$. This establishes the Forth\n  property. The Back property is similar. So $\\Struct{M_1} \\iso[p]\n  \\Struct{M_2}$; by \\olref[pis]{thm:p-isom1}, $\\Struct{M_1} \\iso\n  \\Struct{M_2}$.\n\\end{proof}\n\n\\begin{prob}\n  Complete the proof of \\olref[mod][bas][dlo]{thm:cantorQ} by\n  verifying that $\\PIso{I}$ satisfies the Back property.\n\\end{prob}\n\n\\begin{rem}\n  Let $\\Struct{S}$ be any !!{enumerable} dense linear ordering without\n  endpoints. Then (by \\olref{thm:cantorQ}) $\\Struct{S} \\iso\n  \\Struct{Q}$, where $\\Struct{Q} = (\\Rat, <)$ is the !!{enumerable}\n  dense linear ordering having the set $\\Rat$ of the rational numbers\n  as its domain. Now consider again the !!{structure} $\\Struct{R} =\n  (\\Real, <)$ from \\olref[thm]{remark:R}. We saw that there is\n  !!a{enumerable} !!{structure} $\\Struct{S}$ such that $\\Struct{R}\n  \\elemequiv \\Struct{S}$. But $\\Struct{S}$ is !!a{enumerable} dense\n  linear ordering without endpoints, and so it is isomorphic (and\n  hence elementarily equivalent) to the !!{structure}~$\\Struct{Q}$. By\n  transitivity of elementary equivalence, $\\Struct{R} \\elemequiv\n  \\Struct{Q}$. (We could have shown this directly by establishing\n  $\\Struct{R} \\iso[p] \\Struct{Q}$ by the same back-and-forth\n  argument.)\n\\end{rem}\n\\end{document}\n", "meta": {"hexsha": "7ab657231c80a05850a00633870dcaee6a856cdf", "size": 3507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/model-theory/basics/dlo.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/model-theory/basics/dlo.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/model-theory/basics/dlo.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": 41.2588235294, "max_line_length": 74, "alphanum_fraction": 0.6509837468, "num_tokens": 1270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6638351578910099}}
{"text": "\\problemname{Mixing Drinks}\nPia is a famous bartender at the hip Stockholm night club Supernova.\nOne of her most impressive feats is the mixing a series of drinks using each of the $N$ distinct drink ingredients in the bar exactly once.\nShe does this in the following way.\n\nFirst, Pia chooses a number of drinks to make.\nEach of the drink ingredients are then lined up in front of her in order $1, 2, \\dots, N$.\nFor the first drink, she uses some positive number $K$ of ingredients starting from the left, i.e. $1, 2, ..., K$.\nFor the next drink, she uses some positive number $L$ of ingredients starting from the first unused ingredient, i.e. $K + 1, K + 2, \\dots, K + L$.\nShe continues this process until the final drink, which uses some set of ingredients $N - M, N - M + 1, \\dots, N$.\n\nHowever, not every pair of ingredients work well in a drink.\nFor example, milk and water would not go very well together.\nShe may not include a bad pair of ingredients in any drink.\n\nSo far, she has managed to make a different set of drinks every night.\nFor how many nights can she mix a new set of drinks?\nWe call two sets of drinks different if they do not consist of the exact same drinks (though they are allowed to have drinks in common).\n\n\\section*{Input}\nThe first line of the input contains two integers $1 \\le N \\le 100\\,000$ and $0 \\le P \\le 100\\,000$, the number of ingredients and bad pairs of ingredients.\n\nEach of the next $P$ lines contains two integers $1 \\le a \\not= b \\le N$, two ingredients that do not work well together in a drink.\nThe same pair of ingredients may appear multiple times in this list.\n\n\\section*{Output}\nOutput a single integer, the number of nights Pia can construct a different set of drinks.\nSince this number may be large, output the remainder when divided by $10^9 + 7$.\n", "meta": {"hexsha": "6da9a14dcb9f484cde16426b17c4016fdffaec07", "size": 1803, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mixingdrinks/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": "mixingdrinks/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": "mixingdrinks/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": 62.1724137931, "max_line_length": 156, "alphanum_fraction": 0.7487520799, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6638351483789817}}
{"text": "\\chapter{The Cox Proportional Hazards Model \\label{chapter:cox}}\n\nWe just encountered the Kaplan-Meier estimate of the survival function in Chapter~\\ref{chapter:km}. Now we are going to talk about models that essentially treat the survival function as the \\emph{outcome} in a supervised learning problem. These models are called \\textbf{Cox proportional hazards models}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Survival and Hazard Functions}\n\nConsider a situation where we have some process that generates events, and we're trying to model the time to first event. The probability density for when the event occurs is $f(t)$. The cumulative probability of the event's having occurred by time $t$, also called the \\textbf{cumulative incidence}, is\n$$ F(t) = \\int_0^t f(t) dt.$$\nThe probability of an individual's \\emph{not} having experienced the event by time $t$ is\n$$ S(t) = 1 - F(t), $$\nwhich we call the \\textbf{survival}. The probability of experiencing the event in an infinitesimally small interval starting at $t$, given that one has not experienced it by time $t$, is:\n$$ \\lambda(t) = \\frac{f(t)}{S(t)} $$\nand is called the \\textbf{hazard}. The \\textbf{cumulative hazard} function is equal to\n$$ \\Lambda(t) = \\int_0^t \\lambda(t') dt' = -\\log S(t) $$\nso $S(t) = \\exp(-\\Lambda(t))$. \n\nHere is a graphical representation of some of these quantities. Remember that the probability distribution $f(t)$ must integrate to one.\n\n\\begin{center}\n\\includegraphics[width=0.85\\textwidth]{img/survival-function-example-fx.png}\n\\end{center}\n\n\\vspace{3mm}\n\n\\begin{question}{}\nWhat's the interpretation of the hazard, $\\lambda(t)$, on this image? What happens to the hazard if $S(t)$ is low vs. high for the same $f(x)$? \n\\end{question}\n\n\\begin{question}{}\nAssume $f(t)$ is exponential: $f(t) = b \\cdot \\exp(-bt)$, where $b$ is constant. Then $F(t) = 1 - \\exp(-bt)$ and $S(t) = \\exp(-bt)$. What is the hazard, $\\lambda(t)$? What is the cumulative hazard, $\\Lambda(t)$? \n\\end{question}\n\n\\vspace{3mm}\n\n\\begin{question}{}\nThe concept of a ``cumulative hazard'' is pretty weird. How should this quantity be interpreted?\n% 1. The total amount of risk accumulated up to time t.\n% 2. The number of times per subject that we would expect to observe failures over a given period if the failure event were repeatable.\n% 3. It is useful in terms of allowing us to test assumptions of Cox models. Sort of like the logit in that way. It pops out of the modeling, so we care about it, but it isn't what we usually think about. \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Estimating Survival and Cumulative Hazard}\n\nThe Kaplan-Meier estimate of survival (Chapter~\\ref{chapter:km}) is the most common estimate of the survival function. One can estimate the cumulative hazard using a couple of different methods. \n\\begin{enumerate}\n\\item Take the negative log of the Kaplan-Meier estimate of survival:\n\\begin{align*} \\hat{\\Lambda}_{KM}(t) &= -\\log \\hat{S}_{\\text{KM}}(t) \\\\\n&= -\\sum_{i:t_i < t} \\log \\left( 1 - \\frac{d_i}{n_i} \\right) \\end{align*}\n\\item Use the \\textbf{Nelson-Aalen estimator}\n$$ \\hat{\\Lambda}_{NA}(t) = \\sum_{i:t_i < t} \\frac{d_i}{n_i} $$\n\\end{enumerate}\n\nOne thing that is confusing about the R \\texttt{survival} package's output is that is uses the Kaplan-Meier estimate for survival by default, but it uses the Nelson-Aalen estimator for cumulative hazard by default. So if you exponentiate the negative cumulative hazard that comes out of \\texttt{survfit}, it won't match the survival estimate. The two are close in most cases, though. Here are some pictures for the ovarian cancer survival dataset we discussed in Chapter~\\ref{chapter:km}:\n\n\\begin{center}\n\\includegraphics[width=0.85\\textwidth]{img/ovarian-overall-survival.png}\\\\[3mm]\n\\includegraphics[width=0.85\\textwidth]{img/ovarian-overall-cumhaz.png}\n\\end{center}\n\n% From survfit.formula docs: \"The routine returns both an estimated probability in state and an estimated cumulative hazard estimate. The cumulative hazard estimate is the Nelson-Aalen (NA) estimate or the Fleming-Harrington (FH) estimate, the latter includes a correction for tied event times. The estimated probability in state can estimated either using the exponential of the cumulative hazard, or as a direct estimate using the Aalen-Johansen approach. For single state data the AJ estimate reduces to the Kaplan-Meier and the probability in state to the survival curve; for competing risks data the AJ reduces to the cumulative incidence (CI) estimator. For backward compatability the type argument can be used instead.\"\n\n\\newpage\n\n\\begin{question}{}\nHere is a plot showing the function $-\\log(1-x)$ vs. $x$. Look at the expressions for the two estimators for the cumulative hazard, above. Under what conditions will they be similar? Under what conditions will they be different? \n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/survival-na-km-comparison.png}\n\\end{center} \n\\end{question}\n\n\\vspace{3mm}\n\n\\begin{question}{}\nThe curvature of the Nelson-Aalen estimator gives you an idea of how the hazard varies with time. A concave shape is an indication of \\emph{deceleration} of the hazard; for example, if the event in question is death and time is patient age, this would represent higher infant/childhood mortality than adult mortality. A convex shape is an indication of \\emph{acceleration} of the hazard; in the death/age example, this would represent a process that accelerates as one ages (so called ``wear-out mortality''). \n\nLooking at the graph of the overall cumulative hazard, what do you notice about how the hazard for ovarian cancer changes since the initiation of treatment?\n\\end{question}\n\n\\newpage\n\n\\begin{question}{}\nHere are the raw data from treatment group $1$ of the \\texttt{ovarian} dataset. These are the same data we looked at when building the Kaplan-Meier curve in Chapter~\\ref{chapter:km}, Question~\\ref{question:kmo1}. Using these data, fill in the remaining cells of the table below. Here we are using the Nelson-Aalen estimator for the cumulative hazard. \n{\\footnotesize\n\\begin{center}\n\\begin{tabular}{rlrr}\n  \\toprule\n & rx & futime & fustat \\\\ \n  \\midrule\n  1 & 1 & 59 & 1 \\\\ \n  2 & 1 & 115 & 1 \\\\ \n  3 & 1 & 156 & 1 \\\\ \n  4 & 1 & 268 & 1 \\\\ \n  5 & 1 & 329 & 1 \\\\ \n  6 & 1 & 431 & 1 \\\\ \n  7 & 1 & 448 & 0 \\\\ \n  8 & 1 & 477 & 0 \\\\ \n  9 & 1 & 638 & 1 \\\\ \n  10 & 1 & 803 & 0 \\\\ \n  11 & 1 & 855 & 0 \\\\ \n  12 & 1 & 1040 & 0 \\\\ \n  13 & 1 & 1106 & 0 \\\\ \n  \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\\vspace{-5mm}\n{\\footnotesize\n\\begin{center}\n\\begin{tabular}{rrrrll}\n  \\toprule\n$j$ & $t_j$ & $n_j$ & $d_j$ & $\\hat{\\Lambda}(t_j)$ & Calculation \\\\ \n  \\midrule\n  0 & 0 & 13 & 0 & $0.000$ & $\\frac{0}{13}$ \\\\\n  1 & 59 & 13 & 1 & $0.077$ & $\\hat{\\Lambda}(t_0) + \\frac{1}{13}$ \\\\\n  2 & 115 & 12 & 1 & $0.160$ & $\\hat{\\Lambda}(t_1) + \\frac{1}{12}$ \\\\[2mm]\n  3 & 156 & \\\\[2mm] % 11 & 1 & $0.251$ & $\\hat{\\Lambda}(t_2) + \\frac{1}{11}$ \\\\\n  4 & 268 & \\\\[2mm] % 10 & 1 & $0.351$ & $\\hat{\\Lambda}(t_3) + \\frac{1}{10}$ \\\\\n  5 & 329 & 9 & 1 & $0.462$ & $\\hat{\\Lambda}(t_4) + \\frac{1}{9}$ \\\\\n  6 & 431 & 8 & 1 & $0.587$ & $\\hat{\\Lambda}(t_5) + \\frac{1}{8}$ \\\\\n  7 & 448 & 7 & 0 & $0.587$ & $\\hat{\\Lambda}(t_6) + \\frac{0}{7}$ \\\\\n  8 & 477 & 6 & 0 & $0.587$ & $\\hat{\\Lambda}(t_7) + \\frac{0}{6}$ \\\\\n  9 & 638 & 5 & 1 & $0.787$ & $\\hat{\\Lambda}(t_8) + \\frac{1}{5}$ \\\\[2mm]\n  10 & 803 & 4 & 0 & \\\\[2mm] % $0.787$ & $\\hat{\\Lambda}(t_9) + \\frac{0}{4}$ \\\\\n  11 & 855 & 3 & 0 & \\\\[2mm] % $0.787$ & $\\hat{\\Lambda}(t_{10}) + \\frac{0}{3}$ \\\\\n  12 & 1040 & 2 & 0 & \\\\[2mm] % $0.787$ & $\\hat{\\Lambda}(t_{11}) + \\frac{0}{2}$ \\\\\n  13 & 1106 & 1 & 0 & \\\\[2mm] % $0.787$ & $\\hat{\\Lambda}(t_{12}) + \\frac{0}{1}$ \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\\end{question}\n\n\\newpage\n\n\\begin{question}{}\nHere are plots of the cumulative hazard (Nelson-Aalen estimator) for patients by sex and by ECOG performance score status:\n\\begin{center}\n\\includegraphics[width=0.45\\textwidth]{img/ovarian-rx-cumhaz.png}\n\\hspace{4mm}\n\\includegraphics[width=0.45\\textwidth]{img/ovarian-ecog-cumhaz.png}\n\\end{center}\nHow does treatment group appear to impact the cumulative hazard? What about ECOG score? Do the cumulative hazards appear proportional (i.e., related by a common multiplier) in each case? \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Deriving the Cox Model}\n\nWe have spent considerable time on the hazard and cumulative hazard because these play important roles in what is perhaps the most famous survival analysis tool: the Cox proportional hazards model (``Cox model'', for short), developed by D.R. Cox in 1972. The model has the following form:\n$$ \\lambda(t|x) = \\lambda_0(t)\\exp(\\beta_1 x_1 + \\beta_2 x_2 + \\dots + \\beta_p x_p) $$\nand another way of writing it is:\n$$ \\log \\left( \\frac{\\lambda(t|x)}{\\lambda_0(t)} \\right) = \\beta_1 x_1 + \\beta_2 x_2 + \\dots + \\beta_p x_p. $$\nNote that for now we are assuming that the covariates do not depend on time. There is a variant of the Cox model called the \\textbf{extended Cox model} that allows time-dependent covariates. For now, we will just consider the fixed covariate case. \n\n\\vspace{3mm}\n\n\\begin{question}{}\nCompare the Cox model to a logistic regression model. What is the same? What is different?\n\\end{question}\n\nHere $\\lambda_0(t)$ is called the \\textbf{baseline hazard}. As usual, we symbolize the linear sum of the $\\beta$s as $\\beta^Tx$. Importantly, the baseline hazard can take any shape as a function of time. The $\\lambda_0(t)$ part of the equation is, therefore, referred to as the ``nonparametric'' part, while the $\\beta^Tx$ part is called the ``parametric'' part. The overall model is referred to as \\textbf{semiparametric}. \n\nThe ratio of the hazards for two different sets of covariates, $x$ and $z$, is\n$$ \\frac{\\lambda(t|x)}{\\lambda(t|z)} = \\frac{\\lambda_0(t)\\exp(\\beta^Tx)}{\\lambda_0(t)\\exp(\\beta^Tz)} = \\exp(\\beta^T (x-z)). $$\nTaking the log of this, we arrive at\n$$ \\log \\left( \\frac{\\lambda(t|x)}{\\lambda(t|z)} \\right) = \\beta^T (x-z). $$\nA single coefficient, $\\beta_j$, is therefore the \\textbf{hazard ratio} when the corresponding predictor, $x_j$, increases by one. This ratio is assumed to be constant over time. The hazard ratio is also called the \\textbf{relative risk}. \n\n\\vspace{5mm}\n\n\\begin{question}{}\nWhy doesn't the Cox model have an intercept, $\\beta_0$?\n\\end{question}\n\n\\vspace{1mm}\n\n\\begin{question}{}\nCompare the interpretation of the coefficients in a Cox model to their interpretation in a logistic regression model. \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Fitting the Cox Model \\label{section:coxfit}}\n\nFitting a Cox model means taking a sample of possibly right-censored data and deriving estimates for the parameters, $\\beta_1, \\dots, \\beta_p$. Cox models are fit using a variant of maximum likelihood estimation called \\textbf{partial likelihood estimation}.\n\nLet's consider all of the unique times, $t_i$, that events are observed. For now, we will assume that exactly one event is observed at each of these times (no ties). We will use $R(t_i)$ to refer to the set of subjects who are ``at risk'' (i.e., not censored) just prior to time $t_i$. At each failure time, $t_i$, the contribution to the partial likelihood is:\n\\begin{align*} \\mathcal{L}_i(\\beta) &= \\frac{P(\\text{person $i$ experiences event|still around at $t_i$)}}{\\sum_{l \\in R(t_i)} P(\\text{person $l$ experiences event|still around at $t_i$)}} \\\\\n&= \\frac{\\lambda(t_i|x_i)}{\\sum_{l \\in R(t_i)} \\lambda(t_i|x_l)} = \\frac{\\exp(\\beta^Tx^{(i)})}{\\sum_{l \\in R(t_i)} \\exp( \\beta^Tx^{(l)})} \\end{align*} \nThe complete partial likelihood over all $K$ observed event times, $t_i = t_1, \\dots, t_K$, is:\n$$ \\mathcal{L}(\\beta) = \\prod_{i=1}^K \\frac{\\exp(\\beta^Tx^{(i)})}{\\sum_{l \\in R(t_i)} \\exp( \\beta^Tx^{(l)})}.  $$\nThis is the thing that the model fitting process is trying to maximize. It is optimized numerically, using the same types of optimization procedures used by logistic regression and other generalized linear models.\n\n\\vspace{3mm}\n\n\\begin{question}{}\nWhy is this quantity called a ``partial likelihood'', instead of just a ``likelihood''?\n\\end{question} \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Interpreting Cox Models}\n\nHere is a simple Cox model for survival time vs. age, residual disease, ECOG score, and treatment group in the ovarian cancer dataset.\n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/ovarian-coxph-model.png}\n\\end{center}\n\n\\vspace{3mm}\n\n\\begin{question}{}\nInterpret the coefficients, exponentiated coefficients, standard errors of the coefficients, Z scores, and $p$-values in this model. Also try your hand at interpreting the second block of model output, which includes the exponentiated coefficients (again), the exponentiated negative coefficients, and the lower and upper bounds of a 95\\% confidence interval for the exponentiated coefficients.\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Making Predictions with Cox Models}\n\nThe Cox model fitted using the \\texttt{coxph} function can be used to make various predictions on the original dataset. This yields a lot of output. All of the available outputs for the \\texttt{ovarian} dataset are shown below. \n\n{\\scriptsize\n\\begin{center}\n\\begin{tabular}{rrrrrrrrrrrrr}\n  \\toprule\n & age & lp\\_age & resid.ds & lp\\_resid.ds & ecog.ps & lp\\_ecog.ps & rx & lp\\_rx & lp & risk & expected & surv \\\\ \n  \\midrule\n  1 & 72.33 & 9.03 & 2 & 0.83 & 1 & 0.00 & 1 & 0.00 & 2.67 & 14.43 & 0.16 & 0.85 \\\\ \n  2 & 74.49 & 9.30 & 2 & 0.83 & 1 & 0.00 & 1 & 0.00 & 2.94 & 18.90 & 0.46 & 0.63 \\\\ \n  3 & 66.47 & 8.30 & 2 & 0.83 & 2 & 0.34 & 1 & 0.00 & 2.27 & 9.71 & 0.40 & 0.67 \\\\ \n  4 & 53.36 & 6.66 & 2 & 0.83 & 1 & 0.00 & 2 & -0.91 & -0.61 & 0.54 & 0.11 & 0.89 \\\\ \n  5 & 50.34 & 6.28 & 2 & 0.83 & 1 & 0.00 & 1 & 0.00 & -0.08 & 0.93 & 0.25 & 0.78 \\\\ \n  6 & 56.43 & 7.04 & 1 & 0.00 & 2 & 0.34 & 1 & 0.00 & 0.19 & 1.21 & 0.33 & 0.72 \\\\ \n  7 & 56.94 & 7.11 & 2 & 0.83 & 2 & 0.34 & 2 & -0.91 & 0.17 & 1.18 & 0.40 & 0.67 \\\\ \n  8 & 59.85 & 7.47 & 2 & 0.83 & 2 & 0.34 & 2 & -0.91 & 0.53 & 1.71 & 0.70 & 0.49 \\\\ \n  9 & 64.18 & 8.01 & 2 & 0.83 & 1 & 0.00 & 1 & 0.00 & 1.65 & 5.21 & 2.15 & 0.12 \\\\ \n  10 & 55.18 & 6.89 & 1 & 0.00 & 2 & 0.34 & 2 & -0.91 & -0.88 & 0.42 & 0.24 & 0.79 \\\\ \n  11 & 56.76 & 7.08 & 1 & 0.00 & 2 & 0.34 & 1 & 0.00 & 0.24 & 1.27 & 0.94 & 0.39 \\\\ \n  12 & 50.11 & 6.25 & 1 & 0.00 & 1 & 0.00 & 2 & -0.91 & -1.84 & 0.16 & 0.12 & 0.89 \\\\ \n  13 & 59.63 & 7.44 & 2 & 0.83 & 2 & 0.34 & 2 & -0.91 & 0.51 & 1.66 & 1.23 & 0.29 \\\\ \n  14 & 57.05 & 7.12 & 2 & 0.83 & 1 & 0.00 & 2 & -0.91 & -0.15 & 0.86 & 0.63 & 0.53 \\\\ \n  15 & 39.27 & 4.90 & 1 & 0.00 & 1 & 0.00 & 1 & 0.00 & -2.28 & 0.10 & 0.08 & 0.93 \\\\ \n  16 & 43.12 & 5.38 & 1 & 0.00 & 2 & 0.34 & 1 & 0.00 & -1.47 & 0.23 & 0.17 & 0.84 \\\\ \n  17 & 38.89 & 4.85 & 2 & 0.83 & 2 & 0.34 & 1 & 0.00 & -1.17 & 0.31 & 0.23 & 0.79 \\\\ \n  18 & 44.60 & 5.57 & 1 & 0.00 & 1 & 0.00 & 1 & 0.00 & -1.62 & 0.20 & 0.15 & 0.86 \\\\ \n  19 & 53.91 & 6.73 & 1 & 0.00 & 1 & 0.00 & 2 & -0.91 & -1.37 & 0.25 & 0.19 & 0.83 \\\\ \n  20 & 44.21 & 5.52 & 2 & 0.83 & 1 & 0.00 & 2 & -0.91 & -1.76 & 0.17 & 0.13 & 0.88 \\\\ \n  21 & 59.59 & 7.44 & 1 & 0.00 & 2 & 0.34 & 2 & -0.91 & -0.33 & 0.72 & 0.53 & 0.59 \\\\ \n  22 & 74.50 & 9.30 & 2 & 0.83 & 2 & 0.34 & 1 & 0.00 & 3.28 & 26.49 & 1.65 & 0.19 \\\\ \n  23 & 43.14 & 5.38 & 2 & 0.83 & 1 & 0.00 & 1 & 0.00 & -0.97 & 0.38 & 0.04 & 0.96 \\\\ \n  24 & 63.22 & 7.89 & 1 & 0.00 & 2 & 0.34 & 2 & -0.91 & 0.13 & 1.14 & 0.18 & 0.84 \\\\ \n  25 & 64.42 & 8.04 & 2 & 0.83 & 1 & 0.00 & 2 & -0.91 & 0.77 & 2.16 & 0.45 & 0.64 \\\\ \n  26 & 58.31 & 7.28 & 1 & 0.00 & 1 & 0.00 & 2 & -0.91 & -0.82 & 0.44 & 0.09 & 0.91 \\\\ \n   \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\nThe term \\texttt{age} is the raw value for age for each patient, and the term \\texttt{lp\\_age} is the linear predictor, $\\beta_{\\text{age}} x_{\\text{age}}^{(i)}$, for patient $i$. The same is true for the other predictors. The term \\texttt{lp} is the entire linear predictor, $\\beta^Tx$, for each $x^{(i)}$. Confusingly, it has been centered, so its value is shifted from the sum of columns 2, 4, 6, and 8 by a fixed amount (Exercise: What is this amount?).  The \\texttt{risk} term is just the overall risk score, $\\exp(\\texttt{lp})$. The \\texttt{expected} term is the expected number of events given the covariates and follow-up time. The survival probability, \\texttt{surv}, for each subject is $\\exp(-\\texttt{expected})$. % answer: 7.184752 \n\nCox models make no assumptions about the shape of the baseline hazard, so to make predictions, they simply use the empirical survival (or cumulative hazard) curve for the entire dataset and then adjust it up or down depending on the values of the covariates. The way R does this is super confusing - it estimates the baseline hazard at the means of the covariates after centering, so the baseline hazard is not very interpretable. You can get it out of the model using the \\texttt{basehaz} function. In any case, here's what you get when you ask the model to predict the survival and cumulative hazard curves for all of the patients in the training set:\n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/ovarian-survplot-bypatient.png}\\\\\n\\includegraphics[width=0.9\\textwidth]{img/ovarian-cumhaz-bypatient.png}\n\\end{center}\n\n\\newpage\n\n\\begin{question}{}\nWhich patients have the lowest and highest risk scores? Where do they appear on the patient-level survival and cumulative hazard graphs?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Testing the Proportional Hazards Assumption}\n\nThe Cox model makes three important assumptions:\n\\begin{enumerate}\n\\item \\emph{Common baseline hazard.} At any time, $t$, all individuals experience the same baseline hazard, $\\lambda_0(t)$. \n\\item \\emph{Proportional hazards.} The hazard for one individual is proportional to the hazard of any other individual.\n\\item \\emph{Time-invariance.} The constant of proportionality between the hazards of any two individuals does not depend on time. \n\\end{enumerate}\nAll of them are potentially problematic. In particular, it's hard to come up with situations in which the hazards for \\emph{any} two individuals can reasonably be assumed to be proportional. Thus, it's important to check this assumption. \n\nThere are whole book chapters and papers devoted to model diagnostics for the Cox model. I will present a couple of common methods here and leave the others to the course website. \n\n\\subsection{Schoenfeld Residuals}\n\nIn Section~\\ref{section:coxfit}, we saw how the Cox model was fit using maximization of the partial likelihood. The quantity\n$$ \\frac{\\exp(\\beta^Tx^{(i)})}{\\sum_{l \\in R(t_i)} \\exp( \\beta^Tx^{(l)})} $$ \nwas important because it gave us the probability, according to the model, that the person observed to experience the event at time $t_i$ would experience it, given all the people in the risk set just prior to time $t_i$. The \\textbf{Schoenfeld residual} capitalizes on this idea.\n\n\\begin{quote}\n\\textbf{Schoenfeld residual:} The covariate value $x_j^{(i)}$ for the person ($i$) who actually experienced the event at time $t_i$, minus the expected value of the covariate for the risk set at $t_i$. Or:\n$$ \\text{residual} = x_j^{(i)} - \\sum_{l \\in R(t_i)} x_j^{(l)} \\frac{\\exp(\\beta^Tx^{(l)})}{\\sum_{m \\in R(t_i)} \\exp( \\beta^Tx^{(m)})} $$\n\\end{quote}\n\nThere is one Schoenfeld residual for each combination of observed event and covariate. Typically, they will be plotted against time to assess if there is a trend. The test for trend comes from a simple linear regression model of the residuals against time, conducted separately for each covariate. \n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/ovarian-cox-diagnostics-schoenfeld.png}\n\\end{center}\n\n\\begin{question}{}\nHow would you conduct the test for trend for each covariate using a simple linear regression model?\n\\end{question}\n\n\\begin{question}{}\nTry calculating the Schoenfeld residual for a single covariate and failure time (your choice). All of the information you need is in the table below. The \\texttt{risk} column is the same as in the previous table. It is $\\exp{(\\beta^Tx)}$. \n{\\small\n\\begin{center}\n\\begin{tabular}{rrrrrrrr}\n  \\hline\n & futime & fustat & age & resid.ds & ecog.ps & rx & risk \\\\ \n  \\hline\n1 & 59 & 1 & 72.33 & 2 & 1 & 1 & 14.43 \\\\ \n  2 & 115 & 1 & 74.49 & 2 & 1 & 1 & 18.90 \\\\ \n  3 & 156 & 1 & 66.47 & 2 & 2 & 1 & 9.71 \\\\ \n  22 & 268 & 1 & 74.50 & 2 & 2 & 1 & 26.49 \\\\ \n  23 & 329 & 1 & 43.14 & 2 & 1 & 1 & 0.38 \\\\ \n  24 & 353 & 1 & 63.22 & 1 & 2 & 2 & 1.14 \\\\ \n  25 & 365 & 1 & 64.42 & 2 & 1 & 2 & 2.16 \\\\ \n  26 & 377 & 0 & 58.31 & 1 & 1 & 2 & 0.44 \\\\ \n  4 & 421 & 0 & 53.36 & 2 & 1 & 2 & 0.54 \\\\ \n  5 & 431 & 1 & 50.34 & 2 & 1 & 1 & 0.93 \\\\ \n  6 & 448 & 0 & 56.43 & 1 & 2 & 1 & 1.21 \\\\ \n  7 & 464 & 1 & 56.94 & 2 & 2 & 2 & 1.18 \\\\ \n  8 & 475 & 1 & 59.85 & 2 & 2 & 2 & 1.71 \\\\ \n  9 & 477 & 0 & 64.18 & 2 & 1 & 1 & 5.21 \\\\ \n  10 & 563 & 1 & 55.18 & 1 & 2 & 2 & 0.42 \\\\ \n  11 & 638 & 1 & 56.76 & 1 & 2 & 1 & 1.27 \\\\ \n  12 & 744 & 0 & 50.11 & 1 & 1 & 2 & 0.16 \\\\ \n  13 & 769 & 0 & 59.63 & 2 & 2 & 2 & 1.66 \\\\ \n  14 & 770 & 0 & 57.05 & 2 & 1 & 2 & 0.86 \\\\ \n  15 & 803 & 0 & 39.27 & 1 & 1 & 1 & 0.10 \\\\ \n  16 & 855 & 0 & 43.12 & 1 & 2 & 1 & 0.23 \\\\ \n  17 & 1040 & 0 & 38.89 & 2 & 2 & 1 & 0.31 \\\\ \n  18 & 1106 & 0 & 44.60 & 1 & 1 & 1 & 0.20 \\\\ \n  19 & 1129 & 0 & 53.91 & 1 & 1 & 2 & 0.25 \\\\ \n  20 & 1206 & 0 & 44.21 & 2 & 1 & 2 & 0.17 \\\\ \n  21 & 1227 & 0 & 59.59 & 1 & 2 & 2 & 0.72 \\\\ \n   \\hline\n\\end{tabular}\n\\end{center}\n}\n\\end{question}\n\n\\begin{question}{}\nThe R function \\texttt{cox.zph} performs the test of trend for all predictors as well as a global test of trend using ANOVA (don't worry, we'll get to this later). Here is the output for this model:\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{img/ovarian-coxzph.png}\n\\end{center}\nFor which predictors is there a potentially worrying association between the Schoenfeld residuals and time?\n\\end{question}\n\n\\subsection{What to do if Violations are Found}\n\nInterpretation of the Cox model is relatively insensitive to deviations from proportionality, especially for large sample sizes. However, if nonproportionality is a huge issue for one or more predictors, there are a few strategies to deal with it.\n\n\\begin{enumerate}\n\\item \\emph{Stratify.} One can stratify the model by different levels of the problematic predictor(s), essentially building separate models for the other covariates at each different level of the problematic predictor(s). This only works for predictors that have discrete levels, however; otherwise, one would need to discretize. A potential downside is that stratification eliminates the model's ability to quantify the effect of the stratification variable(s).\n\\item \\emph{Partition the time axis.} Sometimes proportionality holds for the first part of the time axis but falls apart at the end. In that case, one can analyze the data from the first part of the study separately. The disadvantage, of course, is that one must throw out information from later parts of the study.\n\\item \\emph{Add a nonlinear effect term.} Continuous covariates with nonlinear effects on the outcome may lead to nonproportional hazards. Including transformations of these covariates may help to alleviate the nonproportional hazards. \n\\end{enumerate}\n\n", "meta": {"hexsha": "d9e5056e85606c6a7b20d2c32ccd09b3a8628a21", "size": 23569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-cox-model.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-cox-model.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-cox-model.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": 63.5283018868, "max_line_length": 744, "alphanum_fraction": 0.6583223726, "num_tokens": 7943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006920020959543, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.6637246774335909}}
{"text": "%Background (a brief technical discussion of the D* Lite search method you implemented); figures may be helpful here; \n\n\n\\section{Background}\n\tThis section will contain a brief technical discussion and intuition for each of the three approaches.\n\t\n\t\\subsection{Naive Re-planning A*}\n\t    The NRA* algorithm is an adaption of the classic A* Search to an environment that is partially observable. In an A* Search, a rational agent prioritizes nodes $s$ in the fringe based on a value $f(s) = g(s)+h(s)$, which corresponds to the cost to reach the current node, plus the heuristic cost to reach the goal. In NRA*, the only information that the agent can perceive are the four adjacent cells in the assumed grid-world environment. Therefore, the NRA* agent generates an optimal path, and follows it until one of two things occur: (a) it has reached the goal or (b) it encounters a previously-unobserved obstacle. In this second case, it updates the edge weights into the obstacle square, re-runs A* search from its current location, and repeats the process as before. N.B. that when this re-planning takes place, any previous route knowledge that might have been computed previously does not carry over to the next search, resulting in significant recomputation.\n\n\t\\subsection{Lifelong Planning A*}\n\t    The LPA* search algorithm is based on an incremental heuristic search \\cite{koenig2002d} \\cite{koenig2002improved}. Unlike NRA*, LPA* is able to use information from previous routefinding computations to inform new searches. To do so, LPA* keeps track of $g(s), rhs(s)$ 2-tuples for each node $s$ in the graph. Intuitively, $g(s)$ is an estimate of the cost so far, and corresponds to the same value from A* search. $rhs(s)$ is a one-step look-ahead estimate that takes into consideration the predecessors $s'$ of $s$, potentially providing a better estimate than $g(s)$. More formally, the $rhs$ is defined as 0 if $s=s_{start}$ and $min_{s'\\in pred(s)} g(s')+c(s',s)$ otherwise. The queuing strategy for fringe nodes is more complex than in (NR)A*, as it uses a tuple of keys that establish a dual-priority system. Since the $rhs(s)$ values are a ``potentially better informed'' version of the $g(s)$ values, a node is called locally inconsistent if $g(s) \\neq rhs(s)$. When a node becomes locally inconsistent, either through initialization or replanning, it is added to this queue.\n\t    \n\t    Initially, only the start state is locally inconsistent. By making the nodes locally consistent, and therefore making sure that the $rhs$ values are precisely the same as the $g$ values, an optimal path can be found based on the currently-known edge weights. Upon discovering environmental changes which affect the edge weights between nodes, it updates those affected nodes, and makes them locally inconsistent (or in other words, adds them to the priority queue) if necessary. It then repeats the pathfinding process until the graph is once again consistent. Note that edge weights can increase (locally overconsistent) or decrease (locally underconsistent) in general, but in our example scenario, edges can only increase. This corresponds to the agent encountering an impassable barrier. Once the graph is locally consistent, the shortest path to the goal can be found by starting at the goal state, transitioning back to the predecessor through the nodes which minimize the cost, continuing until the start state is reached.  \n\t\n\t\tA key drawback for LPA* is that it does not allow for changing start positions. For our motivational scenario, where the agent must directly observe the updated edge weights, this can cause significant backtracking.\n\t\n\t\\subsection{D* Lite}\n\t\t D* Lite \\cite{koenig2004lifelong} \\cite{simmons1995probabilistic} aims to improve on this by only updating nodes on the path from the in-progress current position to the goal state. To do so, modest changes to the LPA* algorithm are required; however, the core replanning approach of LPA* is maintained.\n\t\t\n\t\tLPA* iteratively attempts to find shortest paths from the start to the goal, incorporating new edge costs as it observes them through the local consistency approach described above. In contrast, D* Lite iteratively attempts to find the shortest path from the $current$ node to the goal, also incorporating new edge costs as it observes them, but only towards the goal. There are some other differences as well. In particular, the search direction in now switched, and the $g(s)$ values now represent the goal distance, not the backwards cost. Similarly, the $rhs$ values are now forward looking, i.e. one step look-ahead with respect to successors and their respective goal distances. Similar to LPA*, D* Lite also prioritizes nodes based on a tuple that is defined in terms of  $g(s), rhs(s)$. However, the definition of this tuple differs from that of LPA* in that its priorities are effectively lower bounds on those priorities from LPA*. It also maintains a priority offset $k_m$, which allows it to bound the replanning propagation. This re-formulation, along with a less strict terminating condition allow D* Lite to have better performance than LPA*.\n\t\t\n\t\tThe framework for D* Lite is as follows: it first attempts to compute the shortest path from the start to the goal node. It then takes steps along this path, and makes any changes to the edge costs and associated priority queue values when necessary. It then computes the shortest path using this new information, and repeats. The currently-optimal shortest path to the goal can be found by starting at the current start state, transitioning to the successor which minimizes the $rhs$ condition, i.e. one step look-ahead, and continuing until the goal state is reached. However, to extract the actual path taken by the agent including replanning, this information must be extracted retrospectively, by recording the steps taken.", "meta": {"hexsha": "d46378d188733f359a37d572dc293a4f5727a7c2", "size": 5876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/tex/2background.tex", "max_stars_repo_name": "hwbehrens/DStarLite", "max_stars_repo_head_hexsha": "31654185ed5ce595fb0cf516b2190af27525297f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-12T01:47:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T10:48:15.000Z", "max_issues_repo_path": "report/tex/2background.tex", "max_issues_repo_name": "Bharathgc/DStarLite", "max_issues_repo_head_hexsha": "22063acaa7d2938086db4076161ed71028e1e28e", "max_issues_repo_licenses": ["MIT"], "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/2background.tex", "max_forks_repo_name": "Bharathgc/DStarLite", "max_forks_repo_head_hexsha": "22063acaa7d2938086db4076161ed71028e1e28e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 267.0909090909, "max_line_length": 1159, "alphanum_fraction": 0.7853982301, "num_tokens": 1286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.6637246746086458}}
{"text": "\\section{Logistic Regression II}\n\n\\subsection{Parameterization}\n\n\\begin{frame}\n  \\frametitle{Parameterization}\n  \n  \\begin{itemize}\n    \\item Until now, $F(\\vec x)$ was some arbitrary function in $\\vec x$ \\\\[.1cm]\n      \\structure{Example:} $ F(\\vec x) = \\vec x^T \\mat A \\vec x + \\vec \\alpha^T\\vec x + \\alpha_0 $ with components defined by Gaussian distributions \\\\[.25cm] \\pause\n    \\item We can express a nonlinear $F(\\vec x)$ as a scalar product by lifting $\\vec x$ into a higher dimensional space: \\\\\n      Given \\\\\n      \\hspace{0.5cm} $\\vec x = \\left(x_1, x_2\\right)^T \\in \\real^2,~ \\mat A = \\left( \\begin{array}{cc} a_{11} & a_{12} \\\\ a_{21} & a_{22} \\end{array} \\right), ~ \\vec \\alpha = \\left(\\alpha_1, \\alpha_2 \\right)^T, ~\\alpha_0 $\\,, \\\\\n      then \\\\\n      \\hspace{0.5cm} $F(\\vec x) = a_{11} x_1^2 + (a_{12} + a_{21}) x_1 x_2 + a_{22} x_2^2 + \\alpha_1 x_1 + \\alpha_2 x_2 + \\alpha_0$\\,.\\\\[.25cm] \\pause\n    \\item Rewrite $F(\\vec x) = \\vec \\theta^T \\vec x'$ with $\\vec \\theta, \\vec x' \\in \\real^6$: \\\\ \\pause\n      \\hspace{0.5cm} $\\vec \\theta = (a_{11}, a_{12} + a_{21}, a_{22}, \\alpha_1, \\alpha_2, \\alpha_0)^T$ \\\\\n      \\hspace{0.5cm} $\\vec x' = ( x_1^2, x_1 x_2, x_2^2, x_1, x_2, 1)^T$\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Parameterization \\cont}\n\n  \\begin{citeblock}{Definition}\n\n    We write the parameterized logistic function in the following:\n    \\begin{eqnarray*}\n      g(\\vec \\theta^T \\vec x) &=& \\frac{1}{1+e^{-\\vec \\theta^T \\vec x}}\n    \\end{eqnarray*}\n    where $\\vec \\theta, \\vec x$ are the lifted parameters of the original decision function $F$ \\\\\n    (if it was not already linear).\n  \\end{citeblock}\n\\end{frame}\n\n\n\\subsection{Learning in Logistic Regression}\n\n\\subsubsection{Log-Likelihood Function}\n\n\\begin{frame}\n  \\frametitle{Log-Likelihood Function}\n \n  \\begin{itemize}\n    \\item Let us assume the posteriors are given by\n      \\begin{eqnarray*}\n        p(y=0|\\vec x) &=&  1-g(\\vec \\theta^T\\vec x) \\\\\n        p(y=1|\\vec x) &=&  g(\\vec \\theta^T\\vec x)\n      \\end{eqnarray*}\n      where $g(\\vec \\theta^T\\vec x)$ is the sigmoid function parameterized in $\\vec \\theta$. \\\\[.3cm]\n    \\item The parameter vector $\\vec{\\theta}$ has to be estimated from a set $S$ of $m$ training samples:\n      \\begin{eqnarray*}\n        S &=& \\{ (\\vec x_1, y_1), (\\vec x_2, y_2), (\\vec x_3, y_3), \\dots, (\\vec x_m, y_m) \\}\\quad .\n      \\end{eqnarray*}\n      \\pause\n    \\item Method of choice: Maximum Likelihood Estimation\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Log-Likelihood Function \\cont}\n \n  Before we work on the formulas of the ML-estimator, we rewrite the posteriors\n  using Bernoulli probability:\n\n  \\begin{eqnarray*}\n    p(y|\\vec x) &=& \\pause g(\\vec \\theta^T\\vec x)^{y}(1-g(\\vec \\theta^T\\vec x))^{1-y}\\\\[.3cm] \n  \\end{eqnarray*}\n\n  which shows the great benefit of the chosen notation for class numbers.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Log-Likelihood Function \\cont}\n \n  Now we can compute the log-likelihood function \\\\\n  (assuming that the training samples are mutually independent):\n \n  \\begin{eqnarray*}\n    \\mathcal{L} (\\vec \\theta) &=& \\log \\left( \\prod_{i=1}^m p(y_i|\\vec x_i) \\right) \\\\ \\pause\n                              &=& \\sum_{i=1}^m \\log \\left( g(\\vec \\theta^T\\vec x_i)^{y_i}\\,\\big(1-g(\\vec \\theta^T\\vec x_i)\\big)^{1-y_i} \\right) \\\\ \\pause\n                              &=& \\sum_{i=1}^m \\left(y_i \\log g(\\vec \\theta^T\\vec x_i) + (1-y_i)\\log\\big(1-g(\\vec \\theta^T\\vec x_i)\\big) \\right)\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Log-Likelihood Function \\cont}\n \n  Simplification of the log-likelihood function:\n \n  \\begin{eqnarray*}\n    \\mathcal{L} (\\vec \\theta) \n      &=& \\sum_{i=1}^m \\left( y_i \\log g(\\vec \\theta^T\\vec x_i) + (1-y_i)\\log\\big(1-g(\\vec \\theta^T\\vec x_i)\\big) \\right) \\\\ \\pause\n      &=& \\sum_{i=1}^m \\left( y_i \\log \\frac{e^{\\vec \\theta^T \\vec x_i}}{1 + e^{\\vec \\theta^T \\vec x_i}} + (1 - y_i) \\log \\frac{1}{1 + e^{\\vec \\theta^T \\vec x_i}} \\right) \\\\ \\pause\n      &=& \\sum_{i=1}^m \\left( y_i \\vec \\theta^T \\vec x_i + \\log \\frac{1}{1 + e^{\\vec \\theta^T \\vec x_i}} \\right) \\\\ \\pause\n      &=& \\sum_{i=1}^m \\left( y_i \\vec \\theta^T \\vec x_i + \\log \\big( 1 - g(\\vec \\theta^T \\vec x_i) \\big) \\right)\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Log-Likelihood Function \\cont}\n\n  \\structure{Notes for the expert:} \n\n  \\begin{itemize}\n    \\item The negative of the log-likelihood function is the cross entropy of\\\\\n      $y$ and $g(\\vec \\theta^T\\vec x)$. \\\\[.5cm]\n    \\item The negative of the log-likelihood function is a convex function.\n  \\end{itemize}\n\\end{frame}\n\n\n\\input{nextTime.tex}\n\n\\subsubsection{Newton-Raphson Iteration}\n\n\\begin{frame}\n  \\frametitle{Maximization of the log-likelihood function}\n\n  \\begin{itemize}\n    \\item The log-likelihood function is concave. \n    \\item We use the \\point\\href{http://www.stat.washington.edu/quinn/classes/560/Newton.pdf}{\\structure{Newton-Raphson}} algorithm to solve the unconstrained optimization problem:\n      \\spread\n\n      For the $(k+1)$-st iteration step, we get:\n%\n      \\begin{eqnarray*}\n        \\vec \\theta^{(k+1)} &=& \\vec \\theta^{(k)} - \\left(  \\frac{\\partial^2}{\\partial\\vec \\theta \\partial \\vec \\theta^T} \\mathcal{L} \\left(\\vec \\theta^{(k)} \\right)  \\right)^{-1}   \n       \\frac{\\partial}{\\partial\\vec \\theta} \\mathcal{L}\\left(\\vec \\theta^{(k)}\\right)\n      \\end{eqnarray*}\n  \\end{itemize}\n  \\spread\n \n  \\structure{Note:} If you write the Newton-Raphson iteration in matrix form, you will end up with a weighted least squares iteration scheme.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Newton-Raphson Iteration}\n\n  \\structure{Taylor's Theorem:}\\\\[.3cm]\n   \n  Approximation of a $k$-times differentiable function $f(x)$ \\\\\n  around a given point $x_0$:\n \n  {\\small\n  \\begin{displaymath}\n    f(x_0+h) = f(x_0) + f'(x_0) h + \\frac{f''(x_0)}{2!} h^2 + \\ldots +\n           \\frac{f^{(k)}(x_0)}{k!} h^k + r_k(x_0 + h) h^k, \n           \\quad \\lim_{h \\rightarrow 0} r_k(x_0 + h) = 0\n  \\end{displaymath}\n  }\n  \\pspread\n\n  \\structure{Second order Taylor polynomial:}\n  \\begin{displaymath}\n    f(x_0 + h) \\approx f(x_0) + f'(x_0) h + \\frac{1}{2} f''(x_0) h^2\n  \\end{displaymath}\n\\end{frame}\n  \n\n\\begin{frame}\n  \\frametitle{Newton-Raphson Iteration \\cont}\n\n  \\structure{Extremum:}\n\n  \\begin{eqnarray*}\n    f'(x_0 + h)         & = & f'(x_0) + f''(x_0) h ~\\stackrel{!}{=}~ 0 \\\\[.3cm]\n                \\hat{h} & = & - \\frac{f'(x_0)}{f''(x_0)} \\\\[.3cm]\n    x_1 = x_0 + \\hat{h} & = & x_0 - \\frac{f'(x_0)}{f''(x_0)} \n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Newton-Raphson Iteration \\cont}\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{Gradient of the Log-Likelihood Function}\n\n  \\structure{The gradient:}\n %\n  {\\small\n  \\begin{eqnarray*}\n    \\frac{\\partial}{\\partial \\theta_j} \\mathcal{L}(\\vec \\theta)\n      &=& \\frac{\\partial}{\\partial \\theta_j} \\left( \\sum_{i=1}^m \\left( y_i \\vec \\theta^T \\vec x_i + \\log \\big( 1 - g(\\vec \\theta^T \\vec x_i) \\big) \\right) \\right)\\\\ \\pause\n      &=& \\sum_{i=1}^m \\left( y_i x_{i,j} - \\frac{1}{1-g(\\vec \\theta^T\\vec x_i)} \\frac{\\partial}{\\partial \\theta_j}g(\\vec \\theta^T \\vec x_i) \\right)\n  \\end{eqnarray*}\n  }\n  \\pause \n%  \n  Now we use the derivative of the sigmoid function and get\n%\n  {\\small\n  \\begin{eqnarray*}\n     \\frac{\\partial}{\\partial \\theta_j} \\mathcal{L}(\\vec \\theta) \n       &=& \\sum_{i=1}^m \\left( y_i x_{i,j} - \\frac{1}{1-g(\\vec \\theta^T\\vec x_i)} g(\\vec \\theta^T \\vec x_i) \\big(1-g(\\vec \\theta^T \\vec x_i)\\big) x_{i,j} \\right) \\\\ \\pause\n       &=& \\sum_{i=1}^m \\left( y_i - g(\\vec \\theta^T\\vec x_i) \\right) x_{i,j}\n  \\end{eqnarray*}\n  }\n% \n   where $x_{i,j}$ is the $j$-th component of the $i$-th training feature vector.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Gradient of the Log-Likelihood Function \\cont}\n  \n  Finally, we have a quite simple gradient: \n  \n  {\\small\n  \\begin{eqnarray*}\n    \\frac{\\partial}{\\partial \\theta_j} \\mathcal{L}(\\vec \\theta) \n    &=& \\sum _{i=1}^m  \\left( y_i - g(\\vec \\theta^T\\vec x_i) \\right) x_{i,j}\n  \\end{eqnarray*}\n  }\n\n  where $x_{i,j}$ is the $j$--th component of the $i$--th training feature vector. \\\\[.3cm]\n \n  Or in vector notation:\n  {\\small\n  \\begin{eqnarray*}\n    \\frac{\\partial}{\\partial\\vec \\theta} \\mathcal{L}(\\vec \\theta) \n    &=& \\sum _{i=1}^m  \\left( y_i-g(\\vec \\theta^T\\vec x_i) \\right)\\vec x_{i}\n  \\end{eqnarray*}\n  }\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Hessian of the Log-Likelihood Function}\n\n  \\begin{itemize}\n    \\item The Newton-Raphson algorithm requires the Hessian matrix.\n    \\item Remember the derivative of the sigmoid function!\n  \\end{itemize}\n\n  \\begin{eqnarray*}\n    \\frac{\\partial^2}{\\partial\\vec \\theta \\partial \\vec \\theta^T} \\mathcal{L}(\\vec \\theta) &=& -\n    \\sum _{i=1}^m  g(\\vec \\theta^T\\vec x_i) \\left(1-g(\\vec \\theta^T\\vec x_i)\\right)\\vec x_i \\vec x_i^T\n  \\end{eqnarray*}  \n\\end{frame}\n\n\n\\subsection{Perceptron and Logistic Regression}\n\n\\begin{frame}\n   \\frametitle{Perceptron and Logistic Regression}\n   \n   \\begin{center}\n     \\resizebox{.7\\linewidth}{!}{\n       \\input{\\texfigdir/perceptron.pstex_t}\n     }\n   \\end{center}\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.\\\\[.5cm]\n    \\item Given the decision boundary $F(\\vec x)=0$, we can write down the posterior $p(y|\\vec x)$ right away.\\\\[.5cm]\n    \\item Decision boundary for normally distributed feature vectors for each class is a quadratic function.\\\\[.5cm]\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 \\cont}\n\n  \\begin{itemize}\n    \\item How can a nonlinear function be written as a scalar product? \\\\[.7cm] \\pause\n    \\item What is the objective function for the ML-estimation of the logistic regression parameters? \\\\[.7cm] \\pause\n    \\item What is the difference between a gradient descent and Newton-Raphson numerical optimization scheme? \\\\[.7cm] \\pause\n    \\item What is the parameter update rule for the logistic regression parameters using the Newton-Raphson scheme?\n  \\end{itemize}\n\\end{frame}\n\n", "meta": {"hexsha": "03694d05979e503f6e3afd1ebff61e2fdda70033", "size": 11344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04_logistic_regression_2.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": "04_logistic_regression_2.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": "04_logistic_regression_2.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": 34.1686746988, "max_line_length": 228, "alphanum_fraction": 0.6264985896, "num_tokens": 4086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6636810631443696}}
{"text": "\\chapter{One-dimensional spaces}\n\nWe can divide one-dimensional spaces into two categories:\n\\emph{lines} and \\emph{curves}.\nLines are straight.\nCurves may bend.\nThus every line is a curve.\n\n\\ResearchQuestion{%\nDrawing a line is easy,\nbut how do we describe a line \\emph{algebraically}?\n}\n\n\\ResearchQuestion{%\nA line is a straight one-dimensional space.\n\\emph{Straight} is defined by the ambient space that contains the line.\nHow do we define \\emph{straight}?\n}\n\n\\section{Defining a line}\n\nIf two points \\(a\\) and \\(b\\) are on a line,\nthen their midpoint \\((a + b) / 2\\) is also on the line.\n\n(These aren't obvious to the uninitiated?)\n\nIf both \\(a\\) and \\(b\\) are on a line,\nthen the point \\(k \\cdot (b - a) + a\\) is also on the line, for every \\(k:\\Real\\).\n\nIf three points \\(a,b,c\\) are on a line,\nthen the displacements \\(b-a\\) and \\(c-b\\) are parallel.\n\n\\paragraph{Infinite extension of a line segment}\nA \\emph{line segment} is what is drawn using a straightedge.\nA \\emph{line} is obtained by infinitely extending a line segment in both directions.\n\n\\paragraph{Embedding of \\(\\Real\\)}\n\\emph{A line is a straight embedding of \\(\\Real\\).}\nA line is something straight-shaped and isomorphic to \\(\\Real\\).\n\nBut there is a problem with that definition.\nThat definition may include a pathological sheet, which should be a two-dimensional object.\nThis is a mapping from \\(\\Real^2\\) to \\(\\Real\\):\nLet there be two real numbers \\(a\\) and \\(b\\).\nDefine the number \\(c\\) as \\(\\ldots a_1 b_1 a_0 b_0 . a_{-1} b_{-1} a_{-2} b_{-2} \\ldots\\).%\n\\footnote{\\url{https://math.stackexchange.com/questions/75107/injective-map-from-mathbbr2-to-mathbbr}}%\n\\footnote{\\url{https://math.stackexchange.com/questions/183361/examples-of-bijective-map-from-mathbbr3-rightarrow-mathbbr}}\n\nWe can define a line by a parametric equation: \\( x(k) = k g + p \\).\n\nWe can define a line by an algebraic equation: \\( a \\cdot x + b = 0 \\).\n\n\\subsection{Defining a line as a curve with constant velocity}\n\nThe \\emph{velocity} of the curve \\( x : \\Real \\to \\Real^n \\) is the derivative of \\(x\\).\nThe velocity of \\(x\\) is the rate of change of \\(x\\).\n\n\\emph{A line is a curve whose velocity is constant.}\n\n\\subsection{Defining a line as a geodesic}\n\n\\section{Describing lines in a two-dimensional ambient space}\n\nEvery line can be described as the set\n\\( \\{ (x,y) ~|~ (x,y) \\in \\Real^2, ~ a x + b y = c \\} \\).\n(Why?)\n\n\\subsection{Describing a line that passes two points}\n\nDescribe a line that passes \\((x_1,y_1)\\) and \\((x_2,y_2)\\).\n\nThe description is\n\\begin{align*}\n    a x_1 + b y_1 &= c\n    \\\\\n    a x_2 + b y_2 &= c\n\\end{align*}\nRearrange:\n\\begin{align*}\n    x_1 a + y_1 b &= c\n    \\\\\n    x_2 a + y_2 b &= c\n\\end{align*}\nSolve for \\(a,b,c\\).\n\\begin{align*}\n    \\Matrix{x_1 & y_1 \\\\ x_2 & y_2} \\Matrix{a \\\\ b} = \\Matrix{c \\\\ c}\n\\end{align*}\nWe can solve it using GNU Octave by typing \\verb@[x1,y1;x2,y2] \\ [c;c]@\nbut we have to substitute the variables with numbers first.\n\n\\subsection{Finding the angle formed by two lines}\n\n\\subsection{Translating lines and describing parallel lines}\n\nTranslating a line produces another line that is parallel to the original line.\n\nTwo lines \\(ax+by=c\\) and \\(a'x+b'y=c'\\) are parallel iff \\(\\abs{a/b} = \\abs{a'/b'}\\)?\n\n\\subsection{Describing orthogonal lines}\n\nThis is important for tangents, normals, and osculating circles.\n\n\\section{Describing higher-dimensional lines}\n\nEvery \\(n\\)-dimensional line can be described as\n\\( \\{ k g + p ~|~ k \\in \\Real \\} \\)\nif \\(g, p : \\Real^n\\).\n\nDescribe a line that passes \\(x_1\\) and \\(x_2\\).\nThe description is\n\\begin{align*}\n    x_1 &= k_1 g + p\n    \\\\\n    x_2 &= k_2 g + p\n\\end{align*}\n\n\\begin{align*}\n    x_i - p &= k_i g\n\\end{align*}\n\nHow do we solve the equation \\(a = kb\\) if \\(a,b\\) are vectors and \\(k\\) is a scalar?\n", "meta": {"hexsha": "0c127f0fb987fca371aa3537677e7c431c640027", "size": 3769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/line.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/line.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/line.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": 30.893442623, "max_line_length": 123, "alphanum_fraction": 0.6792252587, "num_tokens": 1175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6635968554061965}}
{"text": "\\section*{Probabilities}\n$\\mathbb{E}_x[X] = \\begin{cases}\n   \\int x \\cdot p(x) \\partial x  &|\\mathbb{E}_x[f(x)] =\\\\\n   \\sum_x x \\cdot p(x) &|\\int f(x) \\cdot p(x) \\partial x\n  \\end{cases}$\\\\\n%$\\mathbb{E}_x[f(x)] = \\int f(x) \\cdot p(x) \\partial x $\\\\\n$Var[X] = \\mathbb{E}[(X-\\mu_X)^2] = \\mathbb{E}[X^2] - \\mathbb{E}[X]^2$\\\\\n$P(A|B) = \\frac{P(B|A) \\cdot P(A)}{P(B)}$; $p(Z|X,\\theta) = \\frac{p(X,Z|\\theta)}{p(X|\\theta)}$\\\\\n$P(x,y) = P(x \\cap y)= P(y|x) \\cdot P(x) = P(x|y) \\cdot P(y)$\n\n%\\subsection*{Linearity of expectation}\n%$X, Y$ rand. var., $a, b \\in \\mathbb{R}$:\\\\\n%$\\mathbb{E}_{x,y}[aX + bY] = a\\mathbb{E}_x[X] + b \\mathbb{E}_y[Y]$\n", "meta": {"hexsha": "f33a2486b3ea6f03ab1d4d0e3d1e9567c6b1b265", "size": 635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Probabilities.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/Probabilities.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Probabilities.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3571428571, "max_line_length": 96, "alphanum_fraction": 0.5244094488, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731158685837, "lm_q2_score": 0.6893056104028799, "lm_q1q2_score": 0.6635759797522364}}
{"text": "\n\\begin{intro}\n  \\putindex{multigrid} Multigrid methods avoid the problems discussed\n  in the section on two-level Schwarz methods by using not only two,\n  but a whole hierarchy of mesh levels. On each level, an approximate\n  solver, a so called smoother is employed, which improves the error\n  somewhat, and then an approximation on a coarser level is used to\n  improve further. This is done down to the coarsest level, where we\n  assume that the solution process is cheap.\n\\end{intro}\n\n\\begin{Definition}{hierarchy-spaces}\n  A \\define{hierarchy of spaces} $\\{V_\\ell\\}_0\\le \\ell \\le L$ is a\n  sequence of the form\n  \\begin{gather}\n    V_0 \\subset V_1 \\subset \\dots \\subset V_L.\n  \\end{gather}\n  We assume that $V_L = V$ is the high resolution space on which we\n  want to solve~\\eqref{eq:itintro:1}, but where the condition number\n  of the matrix $\\mat A$ is bad. On the other end of the spectrum, we\n  assume that the solution of~\\eqref{eq:itintro:1} on $V_0$ is easily\n  possible.\n\\end{Definition}\n\n\\begin{Definition}{multigrid-method}\n  A \\define{multigrid method} consists of the following components:\n  \\begin{enumerate}\n  \\item A \\define{smoother} $R_\\ell$ acting on the level space\n    $V_\\ell$, usually an iterative method like Richardson, Jacobi,\n    Gauss-Seidel or a Schwarz method.\n  \\item A \\define{coarse grid solver} solving the problem on $V_0$\n    exactly.\n  \\item Transfer operators between the levels $V_{\\ell}$ and\n    $V_{\\ell+1}$. For standard finite element methods, this is\n    typically the embedding operator. The transfer in opposite\n    direction is achieved by the $L^2$-projection.\n  \\end{enumerate}\n  \n  On a given level $V_{\\ell}$, the multigrid level consists of an\n  alternating sequence of \\putindex{smoothing step}s and\n  \\putindex{coarse grid correction}s, where the latter consist of a\n  projection of the residual to the space $V_{\\ell-1}$ and then\n  recursive application of the same sequence. This is easiest\n  described by the function\n  \\begin{subequations}\n    \\label{eq:mg:5}\n  \\begin{gather}\n    \\label{eq:mg:1}\n    u_1 = MG_\\ell(u^{(0)}, g),\n  \\end{gather}\n  which takes an initial value $u^{(0)}$ and computes an approximation\n  $u_1$ to the solution to $A_\\ell u = g$ by the following scheme:\n  first, for $\\ell = 0$ let\n  \\begin{gather*}\n    MG_0(u^{(0)}, g) = A_0^{-1} g_0.\n  \\end{gather*}\n  On levels $\\ell \\neq 0$, perform the three steps\n  \\begin{itemize}\n  \\item Pre-smoothing: apply $m_{\\text{pre}}$ steps of a Richardson\n    iteration preconditioned with the smoother $R_\\ell$:\n    \\begin{gather}\n      \\label{eq:mg:2}\n      u^{(k+1)} = u^{(k)} - R_{\\ell}^{-1} \\left(A_\\ell u^{(k)} - g_\\ell\\right),\n      \\qquad 0 \\le k < m_{\\text{pre}}.\n    \\end{gather}\n    \\item Coarse grid correction: let $v^{(0)} \\in V_{\\ell-1}$ and\n      $g_{\\ell-1} \\in V_{\\ell-1}^*$ such that\n      \\begin{gather}\n        \\label{eq:mg:3}\n        g_{\\ell-1} = \\Pi_{\\ell-1}^T \\left(g_\\ell - A_\\ell u^{(m_{\\text{pre}})}\\right),\n        \\qquad\n        v^{(0)} = 0.\n      \\end{gather}\n      Then, compute \n      \\begin{gather}\n        \\label{eq:mg:4}\n        v^{(k+1)} = MG_{\\ell-1}(v^{(k)}, g_{\\ell-1}),\n      \\qquad 0 \\le k < m_{\\text{coarse}}.\n      \\end{gather}\n      Let $w^{(0)} \\in V_{\\ell}$ be given by $w^{(0)} =\n      u^{(m_{\\text{pre}})} + v^{(m_{\\text{coarse}})}$.\n  \\item Post-smoothing: apply $m_{\\text{post}}$ steps of a Richardson\n    iteration preconditioned with the smoother $R_\\ell$:\n    \\begin{gather}\n      \\label{eq:mg:2a}\n      w^{(k+1)} = w^{(k)} - R_{\\ell}^{-1} \\left(A_\\ell w^{(k)} - g_\\ell\\right),\n      \\qquad 0 \\le k < m_{\\text{post}}.\n    \\end{gather}\n    Assign $MG(u^{(0)}, g_\\ell) = w^{(m_{\\text{post}})}$.\n  \\end{itemize}    \n  \\end{subequations}\n  \n  This method has three parameters, the numbers of pre- and post\n  smoothing steps $m_{\\text{pre}}$ and $m_{\\text{post}}$ as well as\n  the number of coarse grid iterations $m_{\\text{coarse}}$. Here, it\n  is the last one which has a strong impact on the structure of the\n  iteration. It defines what is called the \\define{cycle type}, which\n  is either \\define{V-cycle} for $m_{\\text{coarse}} = 1$ or\n  \\define{W-cycle} for $m_{\\text{coarse}} = 2$. The structure of the\n  cycles can be seen in Figure~\\ref{fig:mg:1}.\n\\end{Definition}\n\\begin{figure}[tp]\n  \\centering\n  \\begin{minipage}[t]{.49\\linewidth}\n  \\begin{tikzpicture}[thick,scale=.7]\n    % Levels\n    \\draw[dotted](0,0) node[anchor=east]{$V_0$} -- (7,0);\n    \\draw[dotted](0,1) node[anchor=east]{$V_1$} -- (7,1);\n    \\draw[dotted](0,2) node[anchor=east]{$V_1$} -- (7,2);\n    \\draw[dotted](0,4) node[anchor=east]{$V_{L-2}$} -- (7,4);\n    \\draw[dotted](0,5) node[anchor=east]{$V_{L-1}$} -- (7,5);\n    \\draw[dotted](0,6) node[anchor=east]{$V_L$} -- (7,6);\n    \n    % Transfers\n    \\draw(0.5,6) -- (1.5,4);\n    \\draw[dashed](1.5,4) -- (2.5,2);\n    \\draw(2.5,2) -- (3.5,0) -- (4.5,2);\n    \\draw[dashed](4.5,2) -- (5.5,4);\n    \\draw(5.5,4) -- (6.5,6);\n    \n    % Smoothers and coarse grid correction\n    \\node at (0.5,6) [circle,draw=blue,fill=blue] {};\n    \\node at (1.0,5) [circle,draw=blue,fill=blue] {};\n    \\node at (1.5,4) [circle,draw=blue,fill=blue] {};\n    \\node at (2.5,2) [circle,draw=blue,fill=blue] {};\n    \\node at (3.0,1) [circle,draw=blue,fill=blue] {};\n    \\node at (4.0,1) [circle,draw=blue,fill=blue] {};\n    \\node at (4.5,2) [circle,draw=blue,fill=blue] {};\n    \\node at (5.5,4) [circle,draw=blue,fill=blue] {};\n    \\node at (6.0,5) [circle,draw=blue,fill=blue] {};\n    \\node at (6.5,6) [circle,draw=blue,fill=blue] {};\n    \\node at (3.5,0) [rectangle,draw=red,fill=red] {};\n  \\end{tikzpicture}    \n  \\end{minipage}\n  \\begin{minipage}[t]{.49\\linewidth}\n  \\begin{tikzpicture}[thick,yscale=.7,xscale=.6]\n    % Levels\n    \\draw[dotted](0,0) node[anchor=east]{$V_0$} -- (8.0,0);\n    \\draw[dotted](0,1) node[anchor=east]{$V_1$} -- (8.0,1);\n    \\draw[dotted](0,2) node[anchor=east]{$V_1$} -- (8.0,2);\n    \\draw[dotted](0,4) node[anchor=east]{$V_{L-2}$} -- (8.0,4);\n    \\draw[dotted](0,5) node[anchor=east]{$V_{L-1}$} -- (8.0,5);\n    \\draw[dotted](0,6) node[anchor=east]{$V_L$} -- (8.0,6);\n\n    % Transfers and smoothers\n    \\draw(0.2,6) node[circle,draw=blue,fill=blue] {}\n    -- (0.4,5) node[circle,draw=blue,fill=blue] {}\n    -- (0.6,4) node[circle,draw=blue,fill=blue] {};\n    \\draw[dashed](0.6,4) -- (1.0,2);\n    \\draw (1.0,2) node[circle,draw=blue,fill=blue] {}\n    -- (1.2,1) node[circle,draw=blue,fill=blue] {}\n    -- (1.4,0) node[rectangle,draw=red,fill=red] {}\n    -- (1.6,1)\n    -- (1.8,0) node[rectangle,draw=red,fill=red] {}\n    -- (2.0,1) node[circle,draw=blue,fill=blue] {}\n    -- (2.2,2)\n    -- (2.4,1) node[circle,draw=blue,fill=blue] {}\n    -- (2.6,0) node[rectangle,draw=red,fill=red] {}\n    -- (2.8,1)\n    -- (3.0,0) node[rectangle,draw=red,fill=red] {}\n    -- (3.2,1) node[circle,draw=blue,fill=blue] {}\n    -- (3.4,2) node[circle,draw=blue,fill=blue] {};\n    \\draw[dashed](3.4,2) -- (3.5,3) -- (3.7,0) -- (3.8,4);\n    \\draw(3.8,4) node[circle,draw=blue,fill=blue] {}\n    -- (4.0,5)\n    -- (4.2,4) node[circle,draw=blue,fill=blue] {};\n    \\draw[dashed] (4.2,4) -- (4.4,0) -- (4.5,3) \n    -- (4.6,2)\n    ;\n    \\draw (4.6,2) node[circle,draw=blue,fill=blue] {}\n    -- (4.8,1) node[circle,draw=blue,fill=blue] {}\n    -- (5.0,0) node[rectangle,draw=red,fill=red] {}\n    -- (5.2,1)\n    -- (5.4,0) node[rectangle,draw=red,fill=red] {}\n    -- (5.6,1) node[circle,draw=blue,fill=blue] {}\n    -- (5.8,2)\n    -- (6.0,1) node[circle,draw=blue,fill=blue] {}\n    -- (6.2,0) node[rectangle,draw=red,fill=red] {}\n    -- (6.4,1)\n    -- (6.6,0) node[rectangle,draw=red,fill=red] {}\n    -- (6.8,1) node[circle,draw=blue,fill=blue] {}\n    -- (7.0,2) node[circle,draw=blue,fill=blue] {};\n    \\draw[dashed] (7.0,2) -- (7.4,4);\n    \\draw (7.4,4) node[circle,draw=blue,fill=blue] {}\n    -- (7.6,5) node[circle,draw=blue,fill=blue] {}\n    -- (7.8,6) node[circle,draw=blue,fill=blue] {};    \n  \\end{tikzpicture}    \n  \\end{minipage}\n  \\caption{Smoothing and grid transfer of the V-cycle (left) and\n    W-cycle (right). Black lines indicate grid transfer, blue dots are\n  smoothing operations and red squares are coarse grid\n  solvers. ``Time'' is left to right.}\n  \\label{fig:mg:1}\n\\end{figure}\n\n\\begin{remark}\n  Figure~\\ref{fig:mg:1} shows that the recursive structure of the\n  W-cycle is much more complex than that of the V-cycle. The\n  complexity analysis below will show that higher values of\n  $m_{\\text{coarse}}$ do not lead to efficient algorithms.\n\\end{remark}\n\n\\begin{Definition}{variable-v-cycle}\n  If the numbers of pre- and post smoothing steps in the V-cycle are\n  dependent on the level $\\ell$, we speak of the \\define{variable\n    V-cycle}. A typical choice is $m_\\ell = 2^{L-\\ell} m_L$, thus\n  doubling the number of smoothing steps whenever stepping down one\n  level.\n\\end{Definition}\n\n\\begin{remark}\n  The variable V-cycle with $m_\\ell$ as mentioned in the previous\n  definition has as many smoothing steps per iteration as the W-cycle.\n\\end{remark}\n\n\\begin{remark}\n  If we use an additive or multiplicative Schwarz method (omitting the\n  coarse grid) as our smoother $R_\\ell$, it should be possible in\n  principle to use the analytical tools of\n  Chapter~\\ref{cha:iteration:schwarz-methods}. The difficulty then\n  consists in ensuring that the spectral radius of the iteration\n  matrix does not grow towards one if we proceed upwards on our scale\n  of spaces $V_\\ell$. This remark is a todo for the author and an\n  encouragement for the reader. Hints may be found\n  in~\\cite{GriebelOswald95,Xu92}.\n\\end{remark}\n\n\\begin{remark}\n  It turns out that the techniques used for the analysis of the\n  V-cycle and the W-cycle, respectively are quite\n  different. Therefore, we separate them into two sections.\n\\end{remark}\n\n\\begin{Theorem}{mg-complexity}\n  Let $n_\\ell$ be the dimension of $V_\\ell$. Assume that the effort\n  needed to for the operations in equations~\\eqref{eq:mg:5}b/c/e is\n  linear in $n_\\ell$ and assume that $ n_{\\ell+1}/n_\\ell \\approx 2^d$,\n  where $d$ is the space dimension of the grid. Assume that the effort\n  for the coarse grid solver is negligible. Then, the effort for\n  one step of the V-cycle is of order $n_L$. The effort for one step\n  of the W-cycle is of order $n_L$ for $d \\ge 2$, while it is of order\n  $n_L \\log(n_L)$ in one dimension.\n\\end{Theorem}\n\n\\begin{proof}\n  Start the recursion on level $L$ with the function $MG_L(0,\n  g)$. This function calls $MG_{L-1}(\\ldots)$ $m_{\\text{coarse}}$\n  times. Thus, by recursion, $MG_{\\ell}(\\ldots)$ is executed\n  $m_{\\text{coarse}}^{L-\\ell}$ times.\n  \n  By our assumptions, the amount of operations $\\breve N_\\ell$ in $MG_\\ell(\\ldots)$\n  without the coarse grid correction is linear in $n_\\ell$, say\n  bounded by $Cn_\\ell$. Then, the overall effort $N_L$ on level $L$ is\n  \\begin{gather}\n    \\label{eq:mg:6}\n    N_L \\le C \\sum_{\\ell=1}^L n_\\ell m_{\\text{coarse}}^{L-\\ell} \\le C\n    \\sum_{\\ell=1}^L n_L 2^{d(l-L)}m_{\\text{coarse}}^{L-\\ell}\n    = C n_L \\sum_{\\ell=1}^L \\left(\\frac{m_{\\text{coarse}}}{2^d}\\right)^l.\n  \\end{gather}\n  It remains to notice that the sum converges and is bounded\n  independent of $L$ if and only if $m_{\\text{coarse}}/2^d < 1$. The\n  statements of the theorem follow immediately, observing that $L\n  \\simeq \\log n_L$.\n\\end{proof}\n\n\\begin{Lemma}{mg-error-step}\n  Let $B_\\ell^{-1}$ be the operator associated with the action of the\n  multigrid preconditioner on level $\\ell$ for\n  $\\ell=0,\\ldots,L$. Then, the error after one step of the multigrid\n  method has the form\n  \\begin{gather}\n    \\label{eq:mg:7}\n    u^{(k+1)} - u = E_L \\left(u^{(k)} - u \\right),\n  \\end{gather}\n  where for $\\ell=0,\\ldots,L$ we denote by $E_\\ell$ the\n  \\putindex{error propagation operator}\n  \\begin{gather}\n    \\label{eq:mg:8}\n    E_\\ell = \\left(I-R_\\ell^{-1} A_\\ell\\right)^{m_{\\text{post}}}\n    \\left(I-B_{\\ell-1}^{-1}A_{\\ell-1} P_{\\ell-1}\\right)^{m_{\\text{coarse}}}\n     \\left(I-R_\\ell^{-1} A_\\ell\\right)^{m_{\\text{pre}}}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  For the smoother, we use the standard technique for Richardson's\n  method outlined in Lemma~\\ref{lemma:richardson:1}. For the coarse\n  grid correction, we use Lemma~\\ref{lemma:schwarz:2}.\n\\end{proof}\n\n\\begin{remark}\n  The structure of the error propagation operator~\\eqref{eq:mg:8}\n  already suggests the course of the multigrid analysis (as well as\n  the design of smoothers). Namely, we will have to decompose $V_l$\n  into $V_{l-1}$ and its $A$-orthogonal complement. Then, we use the\n  induction argument that $I-B_{\\ell-1}^{-1}A_{\\ell-1}$ is is small on\n  $V_{l-1}$, while bounded on its complement. Vice versa,\n  $I-R_\\ell^{-1} A_\\ell$ must be bounded on all of $V_\\ell$, while\n  providing good reduction properties on the complement of $V_{l-1}$.\n\\end{remark}\n\n\\section{The V-cycle}\n\n\\begin{assumption}\n  \\label{assumption:mg:1}\n  Let the smoother $R_\\ell$ be symmetric, positive definite and let\n  the following two conditions hold, the second for some positive\n  constant $\\alpha$ independent of $\\ell$:\n  \\begin{subequations}\n    \\label{eq:mg:9}\n    \\begin{xalignat}{2}\n      \\label{eq:mg:10}\n      a\\bigl((I-R_\\ell^{-1}A_\\ell)v,v\\bigr) & \\ge 0\n      & \\forall v &\\in V_\\ell, \\\\\n      \\label{eq:mg:20}\n      r(w,w) &\\le \\alpha a(w,w)\n      & \\forall v &\\in V_\\ell, \\quad w = (I-P_{\\ell-1}) v\n    \\end{xalignat}\n  \\end{subequations}\n\\end{assumption}\n\n\\begin{Theorem}{v-cycle-convergence}\n  Let $a(.,.)$ be symmetric, positive definite and let\n  Assumption~\\ref{assumption:mg:1} hold. Then, the V-cycle operator\n  with $m_{\\text{pre}} =m_{\\text{post}} = m$ admits the estimate\n  \\begin{gather}\n    \\label{eq:mg:11}\n    0 \\le a(\\bigl((I-B_\\ell^{-1}A_\\ell)v,v\\bigr) \\le \\delta a(v,v),\n    \\qquad \\forall v \\in V_\\ell,\n  \\end{gather}\n  where\n  \\begin{gather}\n    \\label{eq:mg:12}\n    \\delta = \\frac{\\alpha}{\\alpha+2m}.\n  \\end{gather}\n  In particular, the contraction number of the multigrid method is\n  bounded by a number less than 1, independent of the level.\n\\end{Theorem}\n\n\\begin{proof}\n  \\footnote{This version of the proof is taken\n    from~\\cite{ArnoldFalkWinther97Hdiv}. It can also be found\n    in~\\cite{BraessHackbusch83,Bramble93}.}\n  First, abbreviate $K_{\\ell} = I-R_{\\ell}^{-1} A_\\ell$, the error\n  propagation operator of a smoothing step. Now we will prove the\n  theorem by induction over $\\ell$. First, since $B_0 = A_0$, it holds\n  on level zero. For higher levels, we derive from~\\eqref{eq:mg:8} the\n  relation\n  \\begin{gather}\n    \\label{eq:mg:13}\n    E_\\ell = I-B_\\ell^{-1} A_\\ell = K_\\ell^m\\Bigl(\n    (I-P_{\\ell-1}) + (I-B_{\\ell-1}^{-1} A_{\\ell-1}) P_{\\ell-1}\n    \\Bigr) K_\\ell^m.\n  \\end{gather}\n  Non-negativity follows readily by the induction argument and\n  the same properties of the smoother and the Ritz-projection. For the\n  upper bound, let $w = K_\\ell^m v$ to obtain by the induction\n  hypothesis\n  \\begin{multline}\n    \\label{eq:mg:14}\n    a(E_\\ell v,v) \\le a\\bigl((I-P_{\\ell-1}) w,w\\bigr) + \\delta\n    a(P_{\\ell-1}w,w)\n    \\\\\n    = (1-\\delta) a\\bigl((I-P_{\\ell-1}) w,w\\bigr)\n   + \\delta a(w,w).\n  \\end{multline}\n  Now we use the smoothing hypothesis anf the\n  Bunyakovsky-Cauchy-Schwarz inequality for the bilinear form $r(.,.)$\n  associated with the smoothing operator $R_\\ell$ to obtain\n  \\begin{align*}\n    a\\bigl((I-P_{\\ell-1}) w,w\\bigr)\n    &= \\scal({(I-P_{\\ell-1}) w}, A_\\ell w) \\\\\n    &= \\scal(R_\\ell {(I-P_{\\ell-1})} w, R_\\ell^{-1} A_\\ell w)\n    \\\\\n    &= r\\bigl((I-P_{\\ell-1}) w, R_\\ell^{-1} A_\\ell w\\bigr) \\\\\n    &\\le \\sqrt{r\\bigl((I-P_{\\ell-1}) w,(I-P_{\\ell-1}) w\\bigr)}\n    \\sqrt{r\\bigl(R_\\ell^{-1} A_\\ell w, R_\\ell^{-1} A_\\ell w\\bigr)}\n    \\\\\n    &\\le \\sqrt{\\alpha a\\bigl((I-P_{\\ell-1}) w,(I-P_{\\ell-1}) w\\bigr)}\n    \\sqrt{a\\bigl(R_\\ell^{-1} A_\\ell w, w\\bigr)}\n  \\end{align*}\n  Using the projection property of $I-P_{\\ell-1}$, we obtain\n  \\begin{gather}\n    \\label{eq:mg:15}\n    a\\bigl((I-P_{\\ell-1}) w,w\\bigr) \\le \\alpha a\\bigl(R_\\ell^{-1} A_\\ell\n    w, w\\bigr)\n    = \\alpha a\\bigl((I-K_\\ell) K_\\ell^{2m} v,v\\bigr).\n  \\end{gather}\n  \n  The smoothing assumption also guarantees that the spectrum of\n  $K_\\ell$ is contained in the interval $[0,1]$. Therefore,\n  \\begin{gather}\n    \\label{eq:mg:16}\n    a\\bigl((I-K_\\ell) K_\\ell^{2m} v,v\\bigr)\n    \\le a\\bigl((I-K_\\ell) K_\\ell^{i} v,v\\bigr),\n    \\qquad i=0,\\dots,2m,\n  \\end{gather}\n  yielding by deflating the telescoping sum\n  \\begin{gather}\n    \\label{eq:mg:17}\n    a\\bigl((I-K_\\ell) K_\\ell^{2m} v,v\\bigr)\n    \\le \\frac1{2m} \\sum_{i=0}^{2m-1}\n    a\\bigl((I-K_\\ell) K_\\ell^{i} v,v\\bigr)\n    = \\frac1{2m} a\\bigl((I-K_\\ell^{2m}) v,v\\bigr)\n  \\end{gather}\n  Combining~\\eqref{eq:mg:14}, \\eqref{eq:mg:15}, and~\\eqref{eq:mg:17},\n  we obtain\n  \\begin{gather}\n    \\begin{split}\n      a(E_\\ell v,v) &\\le (1-\\delta)\\frac\\alpha{2m}\n      a\\bigl((I-K_\\ell^{2m}) v,v\\bigr)\n      + \\delta a(K_\\ell^m v,K_\\ell^m v)\n      \\\\\n      &= (1-\\delta)\\frac\\alpha{2m} a(v,v)\n      + \\left(\\delta - (1-\\delta)\\frac\\alpha{2m}\\right)\n      a(K_\\ell^m v,K_\\ell^m v).\n    \\end{split}\n  \\end{gather}\n  Finally, we enter $\\delta=\\alpha/(\\alpha+2m)$ to obtain\n  \\begin{gather*}\n    \\delta - (1-\\delta)\\frac\\alpha{2m} = 0,\n  \\end{gather*}\n  and thus\n  \\begin{gather}\n    \\label{eq:mg:18}\n    a(E_\\ell v,v) \\le \\left(1-\\frac\\alpha{\\alpha+2m}\\right)\\frac\\alpha{2m}\n    a(v,v) = \\frac\\alpha{\\alpha+2m}a(v,v). \n  \\end{gather}\n\\end{proof}\n\n\\begin{Lemma}{mg-additive}\n  Let $R_\\ell$ be the scaled additive Schwarz method\n  \\begin{gather}\n    \\label{eq:mg:19}\n    R_a^{-1} = \\omega \\sum_{j=1}^J P_j A^{-1},\n  \\end{gather}\n  where the subspaces $V_j$ are defined by overlapping subdomains\n  $\\Omega_j$ as in~\\eqref{eq:schwarz:9}. Not that we do not include\n  the coarse space here. Then, for $\\omega$ sufficiently small, this\n  smoother fulfills Assumption~\\ref{assumption:mg:1}.\n\\end{Lemma}\n\n\\begin{proof}\n  The positive definiteness and symmetry of the smoother have been\n  proven in an abstract way in Lemma~\\ref{lemma:schwarz:3}. In order\n  to prove estimate~\\eqref{eq:mg:10}, we observe that by\n  Lemma~\\ref{lemma:schwarz:5} and Lemma~\\ref{lemma:schwarz:6}\n  \\begin{gather*}\n    r(v,v) = \\omega \\min_{v=\\sum v_j} a(v_j, v_j) \\gtrsim \\omega a(v,v),\n  \\end{gather*}\n  where the implicit constant depends on the number of overlaps in\n  Definition~\\ref{definition:schwarz:finite-covering}. Thus, we can\n  choose $\\omega$ independent of $\\ell$ such that\n  \\begin{gather*}\n    r(v,v) \\ge a(v,v) \\qquad \\forall v\\in V_\\ell.\n  \\end{gather*}\n  Accordingly, $R_\\ell - A_\\ell$ is positive definite, and since\n  $R_\\ell^{-1}$ is as well, so is $I-R_\\ell^{-1} A_\\ell$.\n  It remains to prove~\\eqref{eq:mg:20}, but this is exactly the second\n  half of the proof of Lemma~\\ref{lemma:schwarz:stable-decomposition},\n  if we replace the Clément interpolant into the coarse space by the\n  Ritz projection.\n\\end{proof}\n\n%\\section{The W-cycle and two-grid convergence}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "a2fe3865afc3bc115f8388c13efb4ccfd9fc6569", "size": 18815, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "iteration/mg.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iteration/mg.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "iteration/mg.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.8622881356, "max_line_length": 86, "alphanum_fraction": 0.6365134201, "num_tokens": 6913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8723473647220787, "lm_q1q2_score": 0.6635515923371618}}
{"text": "%begin-include\n\n\\section{Predicates}\n\n\\begin{para}\nUntil now, we have been concerned with propositions --- statements that were either true or false --- and how we could manipulate them with using logical connectives.\nWe will now take one step further and take into consideration the particular objects which we make statements about.\nWelcome to the world of predicate logic.\n\\end{para}\n\n\\begin{para}[Predicates]\nJust as propositional logic was all about propositions, predicate logic is all about \\emph{predicates}.\nAn $n$-ary predicate $P(x_1,\\ldots,x_n)$, where $n$ is zero or a natural number, is a statement that depends on $n$ variables $x_1,\\ldots,x_n$, known as \\emph{arguments}, that is either true or false depending on the values that those variables take.\nThe set of values the variables are allowed to take is called the \\emph{domain of discourse} (or \\emph{domain}, for short).\nOf course, nullary predicates --- which are mere propositions --- need not be followed by parentheses since they do not take any arguments.\n\nFor example, if we were working with the set of all animals as domain, we could define a unary predicate $P(x)$ as ``$x$ can fly'' in such a way that $P(\\tx{cow})$ would be false but $P(\\tx{bird})$ would be true.\n\nNotice how the proposition that arises after any assignment of values to the arguments of a predicate is written substituting the different variable symbols by the values they take, just as we did in $P(\\tx{cow})$ for $P(x)$.\n\n\n\\end{para}\n\n\\begin{para}\nPredicates, just like propositions, can be combined with the connectives from propositional logic in order to form new predicates.\nNonetheless, being able to work directly with the objects we are ``saying things'' about opens up a new world of possibilities.\nOne of them is the ability to incorporate functions and constants into our predicates, but the most notable of all is the use of \\emph{quantifiers}.\n\nAs their name implies, quantifiers allow us to create new predicates stating the quantity of elements in the domain that verify a certain predicate. The two most fundamental are the \\emph{universal} quantifier and the \\emph{existential} quantifier.\nThe universal quantifier is used to state that a certain predicate $P(x_1,\\ldots,x_n)$ is true for every value taken by a variable $x_i$ (with $i\\in\\{1,\\ldots,n\\}$) in the domain. This is written as $(\\forall x_i)P(x_1,\\ldots,x_n)$ and is read as ``for all $x_i$, $P(x_1,\\ldots,x_n)$.''\nOn the other hand, we use the existential quantifier to state that a certain property\\footnote{``Property'' can be used to mean ``predicate.''} $P(x_1,\\ldots,x_n)$ is verified by, at least, one assignment to $x_i$ of an element in the domain. We write this as $(\\exists x_i)P(x_1,\\ldots,x_n)$ and read it as ``there exists an $x_i$ such that $P(x_1,\\ldots,x_n)$.''\nThe predicate $P$ over which we are quantifying is said to be the \\emph{scope} of the quantifier.\n\nA variable $x$ appearing in the scope of a quantifier $(\\forall x)$ or $(\\exists x)$ is said to be a \\emph{bound} variable. Variables that are not bound are called \\emph{free} variables. For example, if we let $P(x)$ and $Q(x)$ be predicates, in the predicate $P(x) \\land (\\forall x)Q(x)$, the first occurrence of $x$ is free but the second is bound.\nNevertheless, it should be taken into account that it is a pretty poor notational choice to use the same symbol to represent a free and a bound variable in the same predicate. This last predicate could have been better written as $Q(y) \\land (\\forall x)Q(x)$, but, from a purely formal point of view, there is nothing wrong with the original formulation.\n\\end{para}\n\n\\begin{para}[Order matters]\nWe are now ready to explore our first application of predicate logic; isn't that exciting!?\nAnd that application goes far beyond any mathematics that you will ever study: it is \\href{https://www.youtube.com/watch?v=-mLpe7KUg9U}{love}.\n\nYesterday, I was scrolling through my social media feed and I found this statement: ``No matter who you are, there exists someone who will love you''.\nJust when I was going to click the ``don't show me posts like this in the future'' button, I had a brilliant idea: that was a perfect sentence waiting for us --- you, my dear reader, and me --- to analyse. So let us get to it!\n\nIt should be clear that, if we take the set of all human beings as our domain and let $\\heartsuit(x,y)$ denote the predicate ``$y$ loves $x$'', the statement ``no matter who you are, love has already found someone for you'' can be written as $(\\forall x)(\\exists y) \\heartsuit(x,y)$.\nNow, I have a simple question: what would happen if you changed the order of the quantifiers and wrote $(\\exists y)(\\forall x)\\heartsuit(x,y)$?\nWhat does this sentence mean?\nIt means that there exists an individual who we all happen to be in love with!\nThe first sentence read ``for every person $x$, there exists a person $y$ who will love them'', but now it reads ``there exists a person $x$ who is loved by every person $y$''.\nDo you have the slightest idea of the mess you have made by swapping two quantifiers? You have taken a cheesy sentence and transformed its meaning to postulate the existence of a love monster!\n\nThe moral of the story is simple: do not swap quantifiers.\nNevertheless, if the same quantification is being used on two different variables consecutively, such as in $(\\exists x)(\\exists y)\\heartsuit(x,y)$, there is obviously no harm in swapping the order of quantifiers; in fact, that last sentence would be often written as $(\\exists x,y)\\heartsuit(x,y)$.\n\nHey, I know you might be angry at me for having created hype with applications and all that stuff and having only given you a cheesy sentence. What can I say? I needed your attention! I hope you will forgive me.\n\\end{para}\n\n\n\\begin{para}[Notation]\n\\label{notaquan}\nThere is a little bit of freedom in the way that quantifiers can be written and each alternative has its own advantages. The following are just some examples of the notation that one can find in the literature:\n\\[ \\forall x, \\exists y, P(x,y),\\qquad (\\forall x)(\\exists y) : P(x,y),\\qquad \\forall x : \\exists y : P(x,y).\\]\n\nI see myself as a liberal person when it comes to notation, but there is something I beg you to do: do not EVER write quantifiers after their scope. Every time you write $P(x),\\forall x$ a cute kitten cries immersed in sadness, so, please do not do that.\nThis is not a matter of taste; it is a matter of readability. When you are about to read an expression, what variables are being quantified is the first thing you should know, not the last!\n\nFurthermore, as we have just seen, the order in which quantifiers are set is very, very important; thus, if you write them at the end\\ldots what order are they in? Should they be read from left to right or from right to left? I mean, it is just inelegant and clumsy. Do not do that, please.\n\nIf you really want to do things right, you should extend this idea to your writing.\nI know; saying, for instance, ``$P(x)$ is true for all $x$'' sounds natural and harmless, but as the number of quantifiers increases --- and, believe me, it will increase and not just in logic, but in ordinary mathematics --- you better have those quantifiers right at the start.\nAs a rule of thumb, I would only put a quantifier at the end of a predicate in written text if it is a single universal quantifier, and I would never ever write a quantifier at the end in a symbolic expression.\n\n\nNow that we are dealing with notation, let me draw your attention to an important issue.\nIn \\ref{hierarchy}, we said that, in propositional logic, there was no harm in getting rid of the parentheses that surround a full proposition, so there was no need to write $(p \\land q)$ and we could just write $p\\land q$.\nIn predicate logic, however, we need to be somewhat careful with this idea.\nIf, for instance, I wrote $(\\forall x) P(x) \\land Q(x)$, I would not mean the same as if I had written $(\\forall x)(P(x) \\land Q(x))$.\nIn the former case, the scope of the quantifier is $P(x)$, whereas in the latter it is $P(x)\\land Q(x)$.\n\nIn order to save ourselves some parentheses and make everything a little bit cleaner, we will use the following convention.\nIf a sequence of quantifiers is followed by a dot, it will mean that its scope is the remainder of the predicate unless an opening parenthesis is present before the quantifiers; if this happens, the scope will end at the point where the matching closing parenthesis is located.\nThus, in $(\\forall x)(\\exists y)\\qsep P(x)\\land Q(y)$, the scope of the first quantifier is $(\\exists y)(P(x) \\land Q(y)$ and that of the second is $P(x) \\land Q(y)$.\nOn the other hand, in $( (\\forall x)\\qsep P(x) ) \\land Q(x)$, the scope of the quantifier is $P(x)$.\n\\end{para}\n\n\n\\begin{para}[Negating predicates]\nIf I told you that every single human loves mathematics, what would you have to do to prove me wrong?\nYou would simply need to show the existence of a person who does not like mathematics.\nTherefore, the negation of the sentence ``for all $x$, $P(x)$ holds'' is ``there exists an $x$ such that $P(x)$ does not hold.''\nIn other words, $\\lnot (\\forall x) P(x)$ is the same as $(\\exists x)(\\lnot P(x))$.\n\nNow, let us just say that I postulate the existence of a person who has the superpower of flying.\nIf you wanted to show that my statement is false, you would have to prove that no person has the superpower of flying or, equivalently, that ``for every person $x$, $x$ cannot fly''.\nWhat is the moral of the story? That $\\lnot(\\exists x)P(x)$ equivalent to $(\\forall x)(\\lnot P(x))$.\n\nPutting together all that we have learnt: how would you write the predicate $\\lnot(\\forall x)(\\exists y)P(x,y)$ without having a negation connective before any quantifier?\nTake a sheet of paper and write down the result.\n\n[Spoiler alert]\nIf you have understood this part, you should have reasoned as follows: $\\lnot(\\forall x)(\\exists y) P(x,y)$ is the same as $(\\exists x)(\\lnot (\\exists y) P(x,y))$, which is equivalent to $(\\exists x)(\\forall y) \\lnot P(x,y)$. If you got this right, congrats! You are on the right track.\nIf you did not, do not worry: make yourself a good cup of tea, go through this material again and give it some thinking.\n\nAs you can see, when negating an expression involving the existential and universal quantifiers, the only thing we need to do is ``swap them and negate what is inside them''.\nThat is a pretty easy rule, but, as always happens with this kind of shortcuts, you should only apply it if you really know what is going on underneath the hood.\n\\end{para}\n\n\n\\begin{para}[Defining quantifiers]\nThere is something kind of significant in our analysis of the negation of predicates. What we have shown --- probably without your noticing --- is that one of our quantifiers is redundant. The predicate $(\\exists x) P(x)$ is equivalent to $\\lnot (\\forall x)(\\lnot P(x))$, so, in a way, there was no need to introduce the existential quantifier once we had the universal one. Conversely, $(\\forall x) P(x)$ is equivalent to $\\lnot(\\exists x)(\\lnot P(x))$, hence the existential quantifier could also serve us as our only quantifier.\n\nDespite the redundancy, we introduced both of them for an obvious reason:\nfor us humans, it is more natural to think ``every $x$ verifies $P(x)$'' than ``there does not exits an $x$ not verifying $P(x)$''.\n\\end{para}\n\n\\begin{para}[Pseudo-quantifiers]\n\\label{pseudoquan}\nWe will now introduce some ``pseudo quantifiers''.\nI have given them this name --- which is, by the way, not standard whatsoever --- because they are just constructions that help us quantify over things without being proper quantifiers.\nInstead, they are mere logical artefacts that are limited to a certain kind of theories.\n\nSome theories (in fact, most theories) define a predicate $E$ that is meant to represent equality. In these theories, we can define a predicate $(\\exists! x)P(x)$ meaning ``there exists a unique $x$ verifying $P(x)$''. The equivalent real predicate behind $(\\exists! x)P(x)$ would be\n\\[(\\exists x)(\\forall y) (P(x) \\land (P(y)\\limplies E(x,y))),\\]\nor, in English, ``there exists an $x$ verifying $P(x)$ and such that, if any $y$ verifies $P(y)$, then $y$ is equal to $x$''.\n\nOn some occasions, one may wish to quantify only over the set of elements in the domain that verify a certain predicate $P$.\nThis is very easy to do. If we wanted to restrict the quantification of $(\\forall x)Q(x)$ or $(\\exists x)Q(x)$ only to the elements $x$ verifying $P(x)$, we would just need\n\\[ (\\forall x)(P(x)\\limplies Q(x)) \\quad \\tx{and} \\quad  (\\exists x)(P(x) \\land Q(x))\\]\nrespectively.\nYou see, saying ``for all $x$ verifying $P(x)$, $Q(x)$ is true'' is the same as saying ``for all $x$, if $x$ verifies $P(x)$, then $Q(x)$ is true'', and analogously for the existential quantifier.\n\nMany theories include binary predicates $P(x,y)$ that can be written as $xPy$ --- for instance, the inclusion predicate $\\in$ that we studied in our elementary treatment of set theory, --- and, given a fixed $y$, one may wish to quantify over all the elements $x$ verifying $xPy$.\nOf course, one could write $(\\forall x)(xPy\\limplies Q(x))$ or $(\\exists x)(xPy\\land Q(x))$, but, instead of wasting time and ink with such lengthy expressions, it is common to simply use $(\\forall x P y)Q(x)$ and $(\\exists x P y) Q(x)$.\nThus, if we wanted to postulate the existence of an element $X$ inside a set $Y$ verifying a property $P(x)$, we would simply have to write $(\\exists X \\in Y)P(X)$. \nIt is important to keep in mind that this is just shorthand notation, and we should always understand what is really going on.\n\nJust to finish with this, I have an innocent question for you: let us assume that we are in the context of set theory and, given a set $X$ and a predicate $P(x)$, we formulate the sentence $(\\exists! x \\in X) P(x)$.\nIs this expression well-formed and unambiguous? Take your time to think about it.\n\n[Spoiler alert] Turns out that this expression is ambiguous. What do you mean: that there exists an element $x\\in X$ verifying $P(x)$ that is unique among all the elements, or unique among all the elements in $X$? As far as I know, there is no widespread convention on which of these two possible interpretations is correct, so it is better not to use this construction to avoid ambiguity.\nIf you wanted to say that it is unique among all the elements of $X$, you could write $(\\exists! x)(x\\in X \\land P(x))$. If, on the other hand, you meant that it is unique amongst all the elements, you could write $(\\exists x\\in X)(P(x)\\land (\\forall y)(P(y)\\limplies y =x))$.\n\\end{para}\n\n\\begin{para}[Higher-order logic]\nPredicate logic is also known as \\emph{first-order logic}. Higher-order logic is an extension of first-order logic that not only allows quantification over variables, but also over predicates about variables, over predicates about predicates about variables, and so on.\n\nFor example, the statement ``for every property $P$, there exists an element $x$ such that $P(x)$ is true'' would be a statement in second-order logic. \n\\end{para}\n\n\\begin{para}[Mathematical induction]\nAnd now, let us close this chapter with a fundamental tool that we will be using extensively from now on, the principle of mathematical induction.\nWhat this principle states is the following: if a subset $A$ of the natural numbers contains $1$ and, for every $n \\in A$, $n+1 \\in A$, then $A$ is the set of natural numbers.\nThis is kind of trivial when you think about it.\nWe already know that $A \\subseteq \\mathbb{N}$ by hypothesis, so, in order to prove that $A = \\mathbb{N}$, we just need to show that $\\mathbb{N} \\subseteq A$.\nThus, let $n\\in\\mathbb{N}$ and let us prove that $n\\in A$.\nWe know, by hypothesis that $1 \\in A$ and --- since, for every $n\\in A$, $n+1\\in A$, --- then $1 + 1 \\in A$ and, therefore, $1 + 1 + 1 \\in A$. If we apply this reasoning $n$ times, we are led to\n\\[ n = 1 + \\overset{n}{\\cdots} + 1 \\in A.\\]\n\nAnd how does this relate to predicates?\nWell, let us say that we want to show that a predicate $P(n)$ is true for all natural numbers $n$.\nLet $A$ be the set of natural numbers $m$ such that $P(m)$ is true.\nIf we show that $1 \\in A$ and that, given any $m\\in A$, $m+1 \\in A$, we will have shown that $A = \\mathbb{N}$.\nIn other words, if we show that $P(1)$ is true and that, assuming $P(n)$ to be true, $P(n+1)$ is true, then we will know that the predicate is true for all natural numbers.\n\nThis principle can be extended to what is known as \\emph{strong induction} (we will refer to it as induction too).\nIf, given a subset $A\\subseteq \\mathbb{N}$, we know that $1\\in A$ and that, assuming every natural number $i$ such that $0\\leq i \\leq n$ to belong to $A$, we have $n+1 \\in A$, then $A = \\mathbb{N}$.\nThe reasoning that justifies this is essentially the same as that for normal induction.\nOf course, strong induction can also be applied to show that a certain property holds for every natural number.\n\\end{para}\n", "meta": {"hexsha": "c6d15e92d62a7b5ed9b7dfd6233f3556025943de", "size": 16952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch0/sec3.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": "ch0/sec3.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": "ch0/sec3.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": 99.7176470588, "max_line_length": 531, "alphanum_fraction": 0.7373761208, "num_tokens": 4399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6635515901283169}}
{"text": "\\section{Integration}\r\n\\subsection{The Riemann Integral}\r\nOur goal is the following: for a ``sufficiently nice'' function $f:[a,b]\\to\\mathbb R$ we want to define its integral\r\n$$\\int_a^bf(x)\\,\\mathrm dx$$\r\nWe would like to think of this as the area under the graph of $y=f(x)$, which motivates the Riemann integral.\r\n\\begin{definition}\r\n    We say $f:[a,b]\\in\\mathbb R$ is bounded if $\\exists M\\in\\mathbb R,|f(x)|\\le M$ for all $x\\in [a,b]$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A dissection of the interval $[a,b]$ is a finite subset $D\\subset [a,b]$ such that $a,b\\in D$.\r\n    If $D$ is a dissection, we can write $D=\\{a_0,\\ldots,a_n\\}$ where $a=a_0<a_1<\\cdots<a_n=b$.\r\n\\end{definition}\r\nNote that if $D,D'$ are both dissections, so is $D\\cup D'$.\r\n\\begin{definition}\r\n    If $f:[a,b]\\to\\mathbb R$ is bounded and a dissection $D$ consists of $a=a_0<a_1<\\cdots<a_n=b$, then we define the upper and lower Riemann sums wrt $D$ by\r\n    $$U(f,D)=\\sum_{i=1}^n(a_i-a_{i-1})\\sup_{a_{i-1}<x<a_i}f(x),L(f,D)=\\sum_{i=1}^n(a_i-a_{i-1})\\inf_{a_{i-1}<x<a_i}f(x)$$\r\n    respectively.\r\n    They exists as $f$ is bounded.\r\n\\end{definition}\r\nSince $f$ is bounded, $U,L$ are bounded over all dissections $D$.\r\n\\begin{lemma}\r\n    If $D\\subset D'$ are dissections of $[a,b]$, then $U(f,D)\\ge U(f,D')$ and $L(f,D)\\le L(f,D')$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    If $D_1,D_2$ are dissections of $[a,b]$, then $U(f,D_1)\\ge L(f,D_2)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nConsider the nonempty sets\r\n$$U=\\{U(f,D):D\\text{ dissects }[a,b]\\},L=\\{L(f,D):D\\text{ dissects }[a,b]\\}$$\r\nIt then follows by the preceding lemma that $U$ is bounded below and $L$ is bounded above, so\r\n\\begin{definition}\r\n    We define\r\n    $$U(f)=\\inf U=\\inf_{D\\text{ dissects }[a,b]}U(f,D),L(f)=\\sup L=\\sup_{D\\text{ dissects }[a,b]}L(f,D)$$\r\n    as the upper and lowe Riemann sums of $f$ over $[a,b]$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    $U(f)\\ge L(f)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Follows from definition.\r\n\\end{proof}\r\nSo we will want to define\r\n\\begin{definition}\r\n    If $L(f)=U(f)$, then we say $f$ is (Riemann) integrable on $[a,b]$ and write\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=L(f)=U(f)$$\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Consider $f(x)=c$ for a constant $c$ for all $x\\in [a,b]$, then consider $D=\\{a,b\\}$, then $U(f,D)=c(b-a)=L(f,D)$, hence $U(f)=c(b-a)=L(f)$, therefore $f$ is Riemann integrable and\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=c(b-a)$$\r\n    2. Take $f:[a,b]\\to\\mathbb R$ by $f(x)=0$ if $x\\in\\mathbb Q$ and $f(x)=1$ if $x\\in\\mathbb R\\setminus\\mathbb Q$.\r\n    Note that if $a_{i-1}<a_i$, then $[a_{i-1},a_i]$ contains both rational and irrational numbers, so it follows that $U(f,D)=b-a$ and $L(f,D)=0$ for any dissection $D$ of $[a,b]$, therefore $U(f)=b-a\\neq 0=L(f)$, hence $f$ is not Riemann integrable.\r\n\\end{example}\r\n\\subsection{Properties of the Integral}\r\n\\begin{proposition}\r\n    $f:[a,b]\\to\\mathbb R$ is integrable on $[a,b]$ and\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=I$$\r\n    iff for every $\\epsilon>0$, there is a dissection $D$ of $[a,b]$ with $U(f,D)< I+\\epsilon$ and $L(f,D)>I-\\epsilon$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    $f:[a,b]\\to\\mathbb R$ is integrable on $[a,b]$ iff for any $\\epsilon>0$, there is a dissection $D$ of $[a,b]$ such that $U(f,D)-L(f,D)<\\epsilon$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider $\\inf_D U(f,D)-L(f,D)$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    If $D=\\{a=a_0<a_1<\\ldots<a_n=b\\}$ is a dissection, then the mesh of $D$ is the difference $m(D)=\\max\\{a_i-a_{i-1}\\}$.\r\n\\end{definition}\r\nObserve that if $\\epsilon>0$, then one can find dissection with mesh less than $\\epsilon$.\r\n\\begin{theorem}\r\n    If $f:[a,b]\\to\\mathbb R$ is increasing, then $f$ is integrable.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Since $f$ is increasing, $f(a_i)\\ge f(x)$ whenever $x\\le a_i$.\r\n    So\r\n    $$\\sup_{a_{i-1}<x<a_i}f(x)\\le f(a_i),\\inf_{a_{i-1}<x<a_i}f(x)\\ge f(a_{i-1})$$\r\n    Hence\r\n    $$U(f,D)=\\sum_{i=1}^n(a_i-a_{i-1})\\sup_{a_{i-1}<x<a_i}f(x)\\le\\sum_{i=1}^n(a_i-a_{i-1})f(a_i)$$\r\n    and\r\n    $$L(f,D)=\\sum_{i=1}^n(a_i-a_{i-1})\\inf_{a_{i-1}<x<a_i}f(x)\\ge\\sum_{i=1}^n(a_i-a_{i-1})f(a_{i-1})$$\r\n    So by substracting\r\n    $$U(f,D)-L(f,D)\\le \\sum_{i=1}^n(a_i-a_{i-1})(f(a_i)-f(a_{i-1}))\\le m(D)(f(b)-f(a))<\\epsilon$$\r\n    If $f(b)=f(a)$ then $f$ is constant and we know that it is integrable.\r\n    Otherwise we take $D$ with $m(D)<\\epsilon/(f(b)-f(a))$, then by the preceding lemma, $f$ is integrable on $[a,b]$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Suppose $f,g:[a,b]\\in\\mathbb R$ are integrable, then\\\\\r\n    1. If $\\lambda\\in\\mathbb R$, then $f+\\lambda g$ is integrable and\r\n    $$\\int_a^bf(x)+\\lambda g(x)\\,\\mathrm dx=\\int_a^bf(x)\\,\\mathrm dx+\\lambda\\int_a^bg(x)\\,\\mathrm dx$$\r\n    2. For any $c\\in [a,b]$, $f|_{[a,c]},f|_{[c,b]}$ are integrable and\r\n    $$\\int_a^cf(x)\\,\\mathrm dx+\\int_c^bf(x)\\,\\mathrm dx=\\int_a^bf(x)\\,\\mathrm dx$$\r\n    3. If $f\\ge g$ on $[a,b]$, then\r\n    $$\\int_a^bf(x)\\,\\mathrm dx\\ge\\int_a^bg(x)\\,\\mathrm dx$$\r\n    4. $|f|$ is integrable and\r\n    $$\\left|\\int_a^bf(x)\\,\\mathrm dx\\right|\\le\\int_a^b|f(x)|\\,\\mathrm dx$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial but need patience.\r\n\\end{proof}\r\n\\subsection{Fundamental Theorem of Calculus}\r\nRecall that continuous function on closed interval is bounded.\r\n\\begin{theorem}\\label{cont_int}\r\n    If $f:[a,b]\\to\\mathbb R$ is continuous, then $f$ is integrable.\r\n\\end{theorem}\r\n\\begin{lemma}\r\n    Suppose $U(f,D)-L(f,D)>c>0$, then there is $a_i\\in D$ such that $\\exists x,y\\in (a_i,a_{i+1})$ with $f(x)-f(y)\\ge c/(b-a)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Basically just pigeonhole principle.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{cont_int}]\r\n    If $f$ is not integrable, then there is some $\\epsilon>0$ such that $U(f,D)-L(f,D)>\\epsilon$ for all dissections $D$ of $[a,b]$.\r\n    Let $0<\\alpha<\\epsilon/(b-a)$.\r\n    By the preceding lemma, if $D$ is a dissection of $[a,b]$, then there is some $a_i\\in D$ such that $\\exists x,y\\in (a_i,a_{i+1}),f(x)-f(y)\\ge\\alpha$\r\n    Consider the dissections $D_n$ with mesh $m(D_n)<1/n$, then we can find $a_i^{(n)}\\in D_n$ and $x_n,y_n\\in (a_i^{(n)},a_{i+1}^{(n)}),f(x_n)-f(y_n)\\ge\\alpha$.\r\n    Since $m(D_n)<1/n$, we know that $|x_n-y_n|<1/n$, so $x_n-y_n\\to 0$.\r\n    Now by Bolzano-Weierstrass, we can find a converging subsequence $x_{n_k}\\to x$ of $x_n$.\r\n    Also $x\\in [a,b]$ since $[a,b]$ is closed.\r\n    Note also that since $x_n-y_n\\to 0$, we have $y_{n_k}\\to x$.\r\n    But $f$ is continuous, so $0<\\alpha\\le f(x_{n_k})-f(y_{n_k})\\to 0$, contradiction.\r\n\\end{proof}\r\n\\begin{theorem}[Fundamental Theorem of Calculus, Version 1]\r\n    Suppose $f:[a,b]\\to\\mathbb R$ is continuous, then define\r\n    $$G(x)=\\int_a^xf(t)\\,\\mathrm dt$$\r\n    for $x\\in [a,b]$.\r\n    Then $G$ is differentiable and $G^\\prime=f$.\r\n\\end{theorem}\r\nNote that given $x\\in [a,b]$, since $f$ is continuous in $[a,b]$, then it is continuous and hence integrable in $[a,x]$, so $G(x)$ is always well-defined.\r\n\\begin{proof}\r\n    We need to show that, as $h\\to 0$,\r\n    $$\\frac{G(x+h)-G(x)}{h}\\to f(x)$$\r\n    for fixed $x\\in[a,b]$.\r\n    Assume for the moment that $h>0$, then\r\n    $$G(x+h)-G(x)=\\int_x^{x+h}f(t)\\,\\mathrm dt$$\r\n    Given $\\epsilon>0$, we can find $\\delta>0$ such that $|f(t)-f(x)|<\\epsilon$ whenever $|t-x|<\\delta$.\r\n    So whenever $0<h<\\delta$, we have $f(x)-\\epsilon<f(t)<f(x)+\\epsilon$ for $t\\in [x,x+h]$, so\r\n    $$f(x)h-\\epsilon h=\\int_x^{x+h}f(x)-\\epsilon\\,\\mathrm dt\\le\\int_{x}^{x+h}f(t)\\,\\mathrm dt\\le\\int_x^{x+h}f(x)-\\epsilon\\,\\mathrm dt=f(x)h+\\epsilon h$$\r\n    hence\r\n    $$\\left|\\frac{G(x+h)-G(x)}{h}-f(x)\\right|\\le\\epsilon$$\r\n    for $0<h<\\delta$, hence\r\n    $$\\lim_{h\\to 0^+}\\frac{G(x+h)-G(x)}{h}=f(x)$$\r\n    Using exactly the same way, we also have\r\n    $$\\lim_{h\\to 0^-}\\frac{G(x+h)-G(x)}{h}=f(x)$$\r\n    Combining them gives the result.\r\n\\end{proof}\r\n\\begin{definition}\r\n    If $F,f:[a,b]\\to\\mathbb R$ with $F^\\prime=f$, we say $F$ is an antiderivative of $f$.\r\n\\end{definition}\r\nSo the theorem says every continuous function on closed interval has an antiderivative.\r\n\\begin{theorem}[Fundamental Theorem of Calculus, Version 2]\r\n    If $f:[a,b]\\to\\mathbb R$ is continuous and $F:[a,b]\\to\\mathbb R$ is differentiable with $F^\\prime=f$, then\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=F(b)-F(a)$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let\r\n    $$G(x)=\\int_a^xf(t)\\,\\mathrm dt$$\r\n    Then $G$ is differentiable and $G^\\prime=f=F^\\prime$, so $(G-F)^\\prime=0$, hence $G-F$ is constant hence and equals $G(a)-F(a)=-F(a)$.\r\n    Hence\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=G(b)=F(b)+G(b)-F(b)=F(b)-F(a)$$\r\n    Which is what we want.\r\n\\end{proof}\r\nNote that we have used here many theorems about the real numbers, like the mean value theorem.\r\n\\begin{corollary}\r\n    Suppose $f:[a,b]\\to\\mathbb R$ is continuous and $g:[c,d]\\to\\mathbb R$ is $C^1$, and $g(c)=a, g(d)=b$, then\r\n    $$\\int_a^bf(t)\\,\\mathrm dt=\\int_c^df(g(s))g^\\prime(s)\\,\\mathrm ds$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Chain rule and FTC.\r\n\\end{proof}\r\n\\begin{corollary}[Integration by Part]\r\n    Suppose $f,g:[a,b]\\to\\mathbb R$ are both $C^1$, then\r\n    $$\\int_a^bg^\\prime(t)h(t)\\,\\mathrm dt=g(b)h(b)-g(a)h(a)-\\int_a^bg(t)h^\\prime(t)\\,\\mathrm dt$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Product rule and FTC.\r\n\\end{proof}\r\nRecall that if $f:[a,b]\\to\\mathbb R$ is $C^k$, the $k^{th}$ Taylor polynomial centered at $a$ is\r\n$$P_k(x)=\\sum_{i=0}^k\\frac{f^{(i)}(a)}{i!}(x-a)^i$$\r\n\\begin{theorem}[Integral Form of Taylor's Theorem]\r\n    If $f:[a,b]\\to\\mathbb R$ is $C^k$ and $x\\in[a,b]$, then $R_k(x)=f(x)-P_k(x)$ has\r\n    $$R_k(x)=\\int_a^x\\frac{(x-t)^{k-1}}{(k-1)!}f^{(k)}(t)\\,\\mathrm dt$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Induction by using integration by part.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $f:[a,b]\\to\\mathbb R$ is $C_k$, then there is a constant $M\\in\\mathbb R$ such that $|f(x)-P_{k-1}(x)|\\le M|x-a|^k$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Since $f$ is $C^k$, $|f^{(k)}|$ is bounded.\r\n    The rest follows instantly.\r\n\\end{proof}\r\nIf $x>0,s\\in\\mathbb R$, we defined $x^s=\\exp(s\\log x)$, so $\\mathrm dx^s/\\mathrm dx=sx^{s-1}$.\r\nNow consider $f(x)=(1+x)^s$.\r\nIt has Taylor polynomials (centered at $0$)\r\n$$P_k(x)=\\sum_{i=0}^k\\binom{s}{i}x^i,\\binom{s}{i}=\\frac{1}{i!}\\prod_{j=0}^{i-1}(s-j)$$\r\nWe write $P(x)$ to be the formal sum when $k\\to\\infty$.\r\nBy the ratio test, $P$ converges whenever $|x|<1$.\r\n\\begin{theorem}[Newton's Binomial Theorem]\\label{gen_bin}\r\n    For $x\\in (-1,1)$, $P(x)$ converges to $(1+x)^s$.\r\n\\end{theorem}\r\n\\begin{lemma}\r\n    $$k\\binom{s}{k}=s\\binom{s-1}{k-1},\\binom{s}{k-1}+\\binom{s}{k}=\\binom{s+1}{k}$$ \r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{gen_bin}]\r\n    By termwise differentiation,\r\n    $$(1+x)P^\\prime(x)=(1+x)\\sum_{i=0}^\\infty i\\binom{s}{i}x^{i-1}=sP(x)$$\r\n    by the preceding lemma.\r\n    So consider $h(x)=(1+x)^{-s}P(x)$, so $h^\\prime(x)=0$ by the differential equation we obtained above, hence $h$ is constant in $(-1,1)$, hence $h\\equiv h(0)=1$.\r\n    Therefore $P(x)=(1+x)^s$ for each $x\\in (-1,1)$.\r\n\\end{proof}\r\n\\subsection{Improper Integral}\r\nOur definition of integral\r\n$$\\int_a^bf(x)\\,\\mathrm dx$$\r\nrequires $a,b<\\infty$ and $f$ is defined and bounded in $[a,b]$.\r\nBut we'd also like to think about things like\r\n$$\\int_1^\\infty\\frac{\\mathrm dx}{x^2+1},\\int_0^1\\frac{\\mathrm dx}{\\sqrt{x}}$$\r\nwhich are not defined in our previous definition of integral.\r\nSuppose $f:[a,b)\\to\\mathbb R$ is continuous and $b\\in\\mathbb R\\cup\\{\\infty\\}$.\r\nThen if $x\\in [a,b)$, then\r\n$$\\int_a^xf(t)\\,\\mathrm dt$$\r\nis well-defined since $f$ is continuous on $[a,x]$.\r\n\\begin{definition}\r\n    If $f:[a,b)\\to\\mathbb R$ is continuous and\r\n    $$\\lim_{x\\to b^-}\\int_a^xf(t)\\,\\mathrm dt$$\r\n    exists and equals to some $c\\in\\mathbb R$, we define\r\n    $$\\int_a^bf(t)\\,\\mathrm dt=c$$\r\n    and say that this integral converges.\r\n    If this limit does not exist, we say the integral diverges.\\\\\r\n    Similarly, if $f:(a,b]\\to\\mathbb R$ is continuous and\r\n    $$\\lim_{x\\to a^+}\\int_x^bf(t)\\,\\mathrm dt$$\r\n    exists and equals to $c$, then we define\r\n    $$\\int_a^bf(t)\\,\\mathrm dt=c$$\r\n    And say that this integral converges.\r\n    Otherwise we say this integral diverges.\r\n\\end{definition}\r\nNote that by FTC this definition (whenever the integral converges) does coincide with our original definition of integrals.\r\n\\begin{example}\r\n    Consider the integral\r\n    $$\\int_1^\\infty t^{-s}\\,\\mathrm dt$$\r\n    Then for $s>1$, then integral converges and equals $1/(s-1)$, and it diverges for $s\\le 1$.\r\n    Similarly\r\n    $$\\int_0^1 t^{-s}\\,\\mathrm dt$$\r\n    converges iff $s<1$.\r\n\\end{example}\r\nMore generally,\r\n\\begin{definition}\r\n    If $f:(a,b)\\to\\mathbb R$ is continuous, then choose $c\\in (a,b)$, then if\r\n    $$\\int_a^cf(t)\\,\\mathrm dt,\\int_c^bf(t)\\,\\mathrm dt$$\r\n    both converge, then we say the integral of $f(t)$ over $(a,b)$ converges and\r\n    $$\\int_a^bf(t)\\,\\mathrm dt=\\int_a^cf(t)\\,\\mathrm dt+\\int_c^bf(t)\\,\\mathrm dt$$\r\n\\end{definition}\r\nNote that this definition (both the convergence and the value of the integral) does not depend on the choice of $c$.\r\n\\begin{example}\r\n    We have\r\n    $$\\int_{-\\infty}^\\infty\\frac{\\mathrm dx}{1+x^2}=\\int_{-\\infty}^0\\frac{\\mathrm dx}{1+x^2}+\\int_{0}^\\infty\\frac{\\mathrm dx}{1+x^2}=\\pi$$\r\n    But\r\n    $$\\int_{-\\infty}^\\infty t\\,\\mathrm dt$$\r\n    does not converge since\r\n    $$\\int_0^\\infty f(t)\\,\\mathrm dt$$\r\n    does not converge.\r\n    $$\\int_0^\\infty t^{-s}\\,\\mathrm dt=\\int_0^1 t^{-s}\\,\\mathrm dt+\\int_1^\\infty t^{-s}\\,\\mathrm ds$$\r\n    never converges for any value of $s$.\r\n\\end{example}\r\n\\begin{proposition}[The Integral Test]\r\n    Suppose $f:[1,\\infty)\\to[0,\\infty)$ is continuous and decreasing, then\r\n    $$\\sum_{n=1}^\\infty f(n)$$\r\n    converges iff\r\n    $$\\int_1^\\infty f(t)\\,\\mathrm dt$$\r\n    converges.\r\n\\end{proposition}\r\n\\begin{example}\r\n    $\\sum_nn^{-s}$ converges iff $s>1$ due to our discussion on the integral of $t^{-s}$ over $[1,\\infty)$.\r\n\\end{example}\r\n\\begin{proof}\r\n    Since $f(x)\\ge 0$,\r\n    $$F(x)=\\int_1^x f(t)\\,\\mathrm dt$$\r\n    is increasing.\r\n    Let $A=F([1,\\infty))$, then if $A$ is bounded above iff the integral converges.\r\n    Similarly since $F(n)\\ge 0$, the sequence $s_n$ of partial sums is increasing, so the series converges iff $B=\\{s_n\\}$ is bounded above.\r\n    Now let $D_n=\\{1,2,\\ldots,n\\}$ be a dissection of $[1,n]$, then\r\n    $$s_n-f(1)=L(f,D_n)\\le F(n)\\le U(f,D_n)=s_n-f(n)\\le s_n-c$$\r\n    where $c=\\inf_x f(x)$ (exists as $f$ is bounded below by $0$) since $f$ is decreasing.\r\n    This implies the claim.\r\n\\end{proof}\r\n\\begin{remark}\r\n    As we see in the proposition, improper integrals behave like series in a certain sense.\r\n    We also have a comparison test for improper integrals.\r\n    If $f,g:[a,b)\\to\\mathbb R$ satisfies $|g|\\le f$ and\r\n    $$\\int_a^bf(t)\\,\\mathrm dt$$\r\n    converges, then\r\n    $$\\int_a^bg(t)\\,\\mathrm dt$$\r\n    converges.\r\n\\end{remark}\r\nUsing improper integrals, we can define certain interesting functions.\r\n\\begin{definition}\r\n    The gamma function $\\Gamma:(0,\\infty)\\to\\mathbb R$ is defined by\r\n    $$\\Gamma(s)=\\int_0^\\infty x^{s-1}e^{-x}\\,\\mathrm dx$$\r\n\\end{definition}\r\nNote that the integral always converges by whatever triviality, so this function is always well-defined.\r\nNote also that by integration by part we know that for $s>1$, we have $\\Gamma(s+1)=s\\Gamma(s)$, hence $\\Gamma(n+1)=n!$ for $n\\in\\mathbb Z_{\\ge 1}$.\\\\\r\nOne of the motivation of defining this gamma function is because of the following (here many informal arguments are used):\r\nNow consider an $n$-dimensional sphere $S^{n-1}=\\{v\\in\\mathbb R^n:|v|=1\\}$.\r\nLet $V(S^{n-1})$ be the volume (or area, etc.) of $S^{n-1}$, so for example $V(S_1)=2\\pi$.\r\nObserve that\r\n$$\\int_{\\mathbb R^n}f(|v|)\\,\\mathrm dv=\\int_0^\\infty V(S^{n-1})r^{n-1}f(r)\\,\\mathrm dr$$\r\nNow consider $f(r)=e^{-r^2}$ and let $c_n$ be the integral as above, then\r\n$$c_n=\\prod_{i=1}^n\\int_\\mathbb Re^{-x^2}\\,\\mathrm dx=(c_1)^n$$\r\nBut on the other hand $c_n$ equals to\r\n$$\\int_0^\\infty V(S^{n-1})r^{n-1}e^{-r^2}\\,\\mathrm dr=\\frac{V(S^{n-1})}{2}\\Gamma\\left( \\frac{n}{2} \\right)$$\r\nSo\r\n$$V(S^{n-1})=\\frac{2c_1^n}{\\Gamma(n/2)}$$\r\nWe know that $c_1=\\sqrt{\\pi}$ since we know $V(S_1)=2\\pi$, and this gives the formula.", "meta": {"hexsha": "13f507fdd44542d1f23a61a13d6b2467e22a13cc", "size": 16239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/int.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": "6/int.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": "6/int.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.2755417957, "max_line_length": 252, "alphanum_fraction": 0.6153704046, "num_tokens": 6092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355188, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.6635258893450866}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\n\\usepackage{polyglossia}\n\\setdefaultlanguage{english}\n\n\\usepackage{fontspec}\n\\setmainfont{Gentium Basic}\n\n%\\linespread{1.3}\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{5pt}\n\n\\usepackage{amssymb}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{mathabx}\n\\usepackage{eulervm}\n\n% theorem, definition, remark\n\\theoremstyle{plain}\n\\newtheorem{mytheo} {Theorem}\n\n\\begin{document}\n\n\\title{Cycle detection problem}\n\\author{}\n\\date{}\n\\maketitle\n\n\\section{The problem}\n\nLet function $ f $ maps finite set $ S $ to itself: \n\\begin{equation}\nf: S \\to S\n\\end{equation}\n\nChoose initial value $ a \\in S $ and build a sequence by applying $ f $ iteratively:\n\\begin{gather}\nx_0 = a \\\\\nx_{i+1} = f(x_i), \\quad i = 0, 1, \\ldots\n\\end{gather}\n\nSince $ S $ is finite the sequence gets back to the older value:\n\\begin{equation}\nx_{\\nu} = x_{\\mu} \\quad (\\nu > \\mu)\n\\end{equation}\nand then cyclically repeats values $ x_{\\mu}, \\ldots, x_{\\nu-1} $.\n\nMathematical details are presented below. The problem in question is to find loop parameters: cycle start index $ \\mu $ and its length $ \\lambda $.\n\n\\section{Mathematical analysis}\n\nLet $ \\nu $ be \\emph{the largest} index such that values\n\n\\begin{equation}\nx_0, x_1, \\ldots, x_{\\nu-1}\n\\end{equation}\nare all different. This means the value $ x_{\\nu} $ already appeared in the sequence before, at some index $ \\mu < \\nu $:\n\n\\begin{equation}\nx_{\\nu} = x_{\\mu}\n\\end{equation}\n\nLet\n\\begin{equation}\n\\lambda = \\nu - \\mu\n\\end{equation}\n\nBy applying function $ f $ to both sides of equation\n\\begin{gather}\nx_{\\mu + \\lambda} = x_{\\mu}\n\\end{gather}\n\nwe have\n\\begin{gather}\nx_{\\mu + \\lambda + 1} = x_{\\mu + 1}\n\\end{gather}\n\nApply function $ f $ again:\n\\begin{gather}\nx_{\\mu + \\lambda + 2} = x_{\\mu + 2}\n\\end{gather}\n\nBy induction we conclude\n\\begin{equation}\\label{eq:period}\nx_{i + \\lambda} = x_{i}\n\\end{equation}\nfor any index $ i \\geq \\mu $.\n\nFor future reference let us prove the following statement:\n\n\\begin{mytheo}\nGiven two indices $ i < j $ we have: $ x_i = x_j $ if and only if\n\n\\begin{equation}\ni \\geq \\mu\n\\end{equation}\nand\n\\begin{equation}\n\\lambda \\, | \\, j - i\n\\end{equation}\n\n\\end{mytheo}\n\n\n\\section{Floyd's hare and tortoise algorithm}\n\n\\section{Brent's algorithm}\n\n\\end{document}\n", "meta": {"hexsha": "a13598eb2543d9fd8749f93656411c749f4f2d96", "size": 2280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/main/java/com/cycle/cycle-detection.tex", "max_stars_repo_name": "arkadius2006/algorithms", "max_stars_repo_head_hexsha": "4bf8a495227f4795a46c03832e764f7f3a6d0066", "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/main/java/com/cycle/cycle-detection.tex", "max_issues_repo_name": "arkadius2006/algorithms", "max_issues_repo_head_hexsha": "4bf8a495227f4795a46c03832e764f7f3a6d0066", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-07-21T16:09:05.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-22T04:25:50.000Z", "max_forks_repo_path": "src/main/java/com/cycle/cycle-detection.tex", "max_forks_repo_name": "arkadius2006/math-data", "max_forks_repo_head_hexsha": "4bf8a495227f4795a46c03832e764f7f3a6d0066", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3571428571, "max_line_length": 147, "alphanum_fraction": 0.6956140351, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.6635258817092214}}
{"text": "\\chapter{Rings and ideals}\n\\section{Some motivational metaphors about rings vs groups}\nIn this chapter we'll introduce the notion of\na \\textbf{commutative ring} $R$.\nIt is a larger structure than a group:\nit will have two operations addition and multiplication,\nrather than just one.\nWe will then immediately define a \\textbf{ring homomorphism}\n$R \\to S$ between pairs of rings.\n\nThis time, instead of having normal subgroups $H \\normalin G$,\nrings will instead have subsets $I \\subseteq R$ called \\textbf{ideals},\nwhich are not themselves rings but satisfy some niceness conditions.\nWe will then show how you to define $R/I$,\nin analogy to $G/H$ as before.\nFinally, like with groups, we will talk a bit about how to generate ideals.\n\nHere is a possibly helpful table of analogies to help you keep track:\n\\begin{center}\n\t\\begin{tabular}[h]{lcc}\n\t\t& Group & Ring \\\\\n\t\t\\hline\n\t\tNotation & $G$ & $R$ \\\\\n\t\tOperations & $\\cdot$ & $+$, $\\times$ \\\\\n\t\tCommutativity & only if abelian & for us, always \\\\\n\t\tSub-structure & subgroup & (not discussed) \\\\\n\t\tHomomorphism & grp hom.\\ $G \\to H$ & ring hom.\\ $R \\to S$ \\\\\n\t\tKernel & normal subgroup & ideal \\\\\n\t\tQuotient & $G/H$ & $R/I$ \\\\\n\t\\end{tabular}\n\\end{center}\n\n\\section{(Optional) Pedagogical notes on motivation}\nI wrote most of these examples with a number theoretic eye in mind;\nthus if you liked elementary number theory,\na lot of your intuition will carry over.\nBasically, we'll try to generalize properties of the ring $\\ZZ$ to\nany abelian structure in which we can also multiply.\nThat's why, for example, you can talk about\n``irreducible polynomials in $\\QQ[x]$'' in the same\nway you can talk about ``primes in $\\ZZ$'',\nor about ``factoring polynomials modulo $p$''\nin the same way we can talk ``unique factorization in $\\ZZ$''.\nEven if you only care about $\\ZZ$\n(say, you're a number theorist), this has a lot of value:\nI assure you that trying to solve $x^n+y^n = z^n$ (for $n > 2$)\nrequires going into a ring other than $\\ZZ$!\n\nThus for all the sections that follow, keep $\\ZZ$ in mind as your prototype.\n\nI mention this here because\ncommutative algebra is \\emph{also} closely tied to algebraic geometry.\nLots of the ideas in commutative algebra have nice\n``geometric'' interpretations that motivate the definitions,\nand these connections are explored in the corresponding part later.\nSo, I want to admit outright that this is not\nthe only good way (perhaps not even the most natural one)\nof motivating what is to follow.\n\n\\section{Definition and examples of rings}\n\\prototype{$\\ZZ$ all the way! Also $R[x]$ and various fields (next section).}\n\nWell, I guess I'll define a ring\\footnote{Or,\n\taccording to some authors, a ``ring with identity'';\n\tsome authors don't require rings to have multiplicative identity.\n\tFor us, ``ring'' always means ``ring with $1$''.}.\n\n\\begin{definition}\n\tA \\vocab{ring} is a triple $(R, +, \\times)$,\n\tthe two operations usually called addition and multiplication, such that\n\t\\begin{enumerate}[(i)]\n\t\t\\ii $(R,+)$ is an abelian group, with identity $0_R$, or just $0$.\n\t\t\\ii $\\times$ is an associative, binary operation on $R$ with some\n\t\tidentity, written $1_R$ or just $1$.\n\t\t\\ii Multiplication distributes over addition.\n\t\\end{enumerate}\n\tThe ring $R$ is \\vocab{commutative} if $\\times$ is commutative.\n\\end{definition}\n\\begin{abuse}\n\tAs usual, we will abbreviate $(R, +, \\times)$ to $R$.\n\\end{abuse}\n\\begin{abuse}\n\tFor simplicity, assume all rings are commutative\n\tfor the rest of this chapter.\n\tWe'll run into some noncommutative rings eventually,\n\tbut for such rings we won't need the full theory of this chapter anyways.\n\\end{abuse}\n\nThese definitions are just here for completeness.\nThe examples are much more important.\n\\begin{example}[Typical rings]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The sets $\\ZZ$, $\\QQ$, $\\RR$ and $\\CC$ are all rings\n\t\twith the usual addition and multiplication.\n\t\t\\ii The integers modulo $n$ are also a ring\n\t\twith the usual addition and multiplication.\n\t\tWe also denote it by $\\Zc n$.\n\t\\end{enumerate}\n\\end{example}\n\nHere is also a trivial example.\n\\begin{definition}\n\tThe \\vocab{zero ring} is the ring $R$ with a single element.\n\tWe denote the zero ring by $0$.\n\tA ring is \\vocab{nontrivial} if it is not the zero ring.\n\\end{definition}\n\\begin{exercise}\n\t[Comedic]\n\tShow that a ring is nontrivial if and only if $0_R \\ne 1_R$.\n\\end{exercise}\n\nSince I've defined this structure, I may as well state the obligatory facts about it.\n\\begin{fact}\n\tFor any ring $R$ and $r \\in R$, $r \\cdot 0_R = 0_R$.\n\tMoreover, $r \\cdot (-1_R) = -r$.\n\\end{fact}\n\nHere are some more examples of rings.\n\\begin{example}\n\t[Product ring]\n\t\\label{ex:product_ring}\n\tGiven two rings $R$ and $S$ the \\vocab{product ring},\n\tdenoted $R \\times S$, is defined as ordered pairs $(r,s)$\n\twith both operations done component-wise.\n\tFor example, the Chinese remainder theorem says\n\tthat \\[ \\Zc{15} \\cong \\Zc3 \\times \\Zc5 \\]\n\twith the isomorphism $n \\bmod{15} \\mapsto (n \\bmod 3, n \\bmod 5)$.\n\\end{example}\n\\begin{remark}\n\tEquivalently, we can define $R \\times S$ as the abelian group $R \\oplus S$,\n\tand endow it with the multiplication where $r \\cdot s = 0$\n\tfor $r \\in R$, $s \\in S$.\n\\end{remark}\n\\begin{ques}\n\tWhich $(r,s)$ is the identity element of the product ring $R \\times S$?\n\\end{ques}\n\n\\begin{example}[Polynomial ring]\n\tGiven any ring $R$,\n\tthe \\vocab{polynomial ring} $R[x]$ is defined as the set of polynomials\n\twith coefficients in $R$:\n\t\\[ R[x] = \\left\\{ a_n x^n+a_{n-1}x^{n-1}+\\dots+a_0\n\t\t\\mid a_0, \\dots, a_n \\in R \\right\\}. \\]\n\tThis is pronounced ``$R$ adjoin $x$''.\n\tAddition and multiplication are done exactly in the way you would expect.\n\\end{example}\n\\begin{remark}\n\t[Digression on division]\n\tHappily, polynomial division also does what we expect:\n\tif $p \\in R[x]$ is a polynomial, and $p(a) = 0$,\n\tthen $(x-a)q(x) = p(x)$ for some polynomial $q$.\n\tProof: do polynomial long division.\n\n\tWith that, note the caveat that\n\t\\[ x^2-1 \\equiv (x-1)(x+1) \\pmod 8 \\]\n\thas \\emph{four} roots $1$, $3$, $5$, $7$ in $\\Zc8$.\n\n\tThe problem is that $2 \\cdot 4 = 0$ even though $2$ and $4$ are not zero;\n\twe call $2$ and $4$ \\emph{zero divisors} for that reason.\n\tIn an \\emph{integral domain} (a ring without zero divisors),\n\tthis pathology goes away,\n\tand just about everything you know about polynomials carries over.\n\t(I'll say this all again next section.)\n\\end{remark}\n\\begin{example}\n\t[Multi-variable polynomial ring]\n\tWe can consider polynomials in $n$ variables with coefficients in $R$,\n\tdenoted $R[x_1, \\dots, x_n]$.\n\t(We can even adjoin infinitely many $x$'s if we like!)\n\\end{example}\n\n\\begin{example}\n\t[Gaussian integers are a ring]\n\tThe \\vocab{Gaussian integers} are the set of complex numbers\n\twith integer real and imaginary parts, that is\n\t\\[ \\ZZ[i] = \\left\\{ a+bi \\mid a,b \\in \\ZZ \\right\\}. \\]\n\\end{example}\n\\begin{abuse}\n\t[Liberal use of adjoinment]\n\tCareful readers will detect some abuse in notation here.\n\t$\\ZZ[i]$ should officially be\n\t``integer-coefficient polynomials in a variable $i$''.\n\tHowever, it is understood from context that $i^2=-1$;\n\tand a polynomial in $i = \\sqrt{-1}$ ``is'' a Gaussian integer.\n\\end{abuse}\n\\begin{example}\n\t[Cube root of $2$]\n\tAs another example (using the same abuse of notation):\n\t\\[ \\ZZ[\\sqrt[3]{2}] = \\left\\{ a + b\\sqrt[3]{2} + c\\sqrt[3]4\n\t\t\\mid a,b,c \\in \\ZZ \\right\\}. \\]\n\\end{example}\n\n\\section{Fields}\n\\prototype{$\\QQ$ is a field, but $\\ZZ$ is not.}\n\nAlthough we won't need to know what a field is until next chapter,\nthey're so convenient for examples I will go ahead and introduce them now.\n\nAs you might already know, if the multiplication is invertible,\nthen we call the ring a field.\nTo be explicit, let me write the relevant definitions.\n\n\\begin{definition}\n\t\\label{def:unit}\n\tA \\vocab{unit} of a ring $R$\n\tis an element $u \\in R$ which is invertible:\n\tfor some $x \\in R$ we have $ux = 1_R$.\n\\end{definition}\n\n\\begin{example}\n\t[Examples of units]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\\ii The units of $\\ZZ$ are $\\pm 1$,\n\tbecause these are the only things which ``divide $1$''\n\t(which is the reason for the name ``unit'').\n\t\\ii On the other hand, in $\\QQ$ everything is a unit (except $0$).\n\tFor example, $\\frac 35$ is a unit since\n\t$\\frac 35 \\cdot \\frac 53 = 1$.\n\t\\ii The Gaussian integers $\\ZZ[i]$ have four units:\n\t$\\pm 1$ and $\\pm i$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}\n\tA nontrivial (commutative) ring is a \\vocab{field}\n\twhen all its nonzero elements are units.\n\\end{definition}\n\nColloquially, we say that\n\\begin{moral}\n\tA field is a structure where you can add, subtract, multiply, and divide.\n\\end{moral}\nDepending on context, they are often denoted\neither $k$, $K$, $F$.\n\n\\begin{example}\n\t[First examples of fields]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\QQ$, $\\RR$, $\\CC$ are fields,\n\t\tsince the notion $\\frac 1c$ makes sense in them.\n\t\t\\ii If $p$ is a prime, then $\\Zc p$ is a field,\n\t\twhich we denote will usually denote by $\\FF_p$.\n\t\\end{enumerate}\n\tThe trivial ring $0$ is \\emph{not} considered a field,\n\tsince we require fields to be nontrivial.\n\\end{example}\n\n%\\begin{remark}\n%\tYou might say at this point that ``fields are nicer than rings'',\n%\tbut as you'll see in this chapter, the conditions for\n%\tbeing a field are somehow ``too strong''.\n%\tTo give an example of what I mean:\n%\tif you try to think about the concept of ``divisibility''\n%\tin $\\ZZ$, you've stepped into the vast and bizarre realm of\n%\tnumber theory.  Try to do the same thing in $\\QQ$ and you get nothing:\n%\tany nonzero $a$ ``divides'' any nonzero $b$\n%\tbecause $b = a \\cdot \\frac ba$.\n%\n%\tI know at least one person who instead\n%\tthinks of this as an argument for why people\n%\tshouldn't care about number theory\n%\t(studying chaos rather than order).\n%\\end{remark}\n\n\\section{Homomorphisms}\n\\prototype{$\\ZZ \\to \\Zc5$ by modding out by $5$.}\nThis section is going to go briskly --\nit's the obvious generalization of all the stuff\nwe did with quotient groups.\\footnote{I once found an\n\tabstract algebra textbook which teaches rings before groups.\n\tAt the time I didn't understand why,\n\tbut now I think I get it -- modding out by things in\n\tcommutative rings is far more natural, and you can start talking\n\tabout all the various flavors of rings and fields.\n\tYou also have (in my opinion) more vivid first examples\n\tfor rings than for groups.\n\tI actually sympathize a lot with this approach --- maybe I'll convert\n\tNapkin to follow it one day.}\n\nFirst, we define a homomorphism and isomorphism.\n\\begin{definition}\n\tLet $R = (R, +_R, \\times_R)$ and $S = (S, +_S, \\times_S)$ be rings.\n\tA \\vocab{ring homomorphism} is a map $\\phi : R \\to S$\n\tsuch that \n\t\\begin{enumerate}[(i)]\n\t\t\\ii $\\phi(x +_R y) = \\phi(x) +_S \\phi(y)$ for each $x,y \\in R$.\n\t\t\\ii $\\phi(x \\times_R y) = \\phi(x) \\times_S \\phi(y)$ for each $x,y \\in R$.\n\t\t\\ii $\\phi(1_R) = 1_S$.\n\t\\end{enumerate}\n\tIf $\\phi$ is a bijection then $\\phi$ is an \\vocab{isomorphism}\n\tand we say that rings $R$ and $S$ are \\vocab{isomorphic}.\n\\end{definition}\nJust what you would expect.\nThe only surprise is that we also demand $\\phi(1_R)$ to go to $1_S$.\nThis condition is not extraneous:\nconsider the map $\\ZZ \\to \\ZZ$ called ``multiply by zero''.\n\\begin{example}\n\t[Examples of homomorphisms]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The identity map, as always.\n\t\t\\ii The map $\\ZZ \\to \\Zc5$ modding out by $5$.\n\t\t\\ii The map $\\RR[x] \\to \\RR$ by $p(x) \\mapsto p(0)$\n\t\tby taking the constant term.\n\t\t\\ii For any ring $R$, there is a trivial ring homomorphism $R \\to 0$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Non-examples of homomorphisms]\n\tBecause we require $1_R$ to $1_S$, some maps that you\n\tmight have thought were homomorphisms will fail.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The map $\\ZZ \\to \\ZZ$ by $x \\mapsto 2x$\n\t\tis not a ring homomomorphism.\n\t\tAside from the fact it sends $1$ to $2$,\n\t\tit also does not preserve multiplication.\n\n\t\t\\ii If $S$ is a nontrivial ring,\n\t\tthe map $R \\to S$ by $x \\mapsto 0$ is not\n\t\ta ring homomorphism, even though it preserves multiplication.\n\n\t\t\\ii There is no ring homomorphism $\\Zc{2016} \\to \\ZZ$ at all.\n\t\\end{enumerate}\n\tIn particular, whereas for groups $G$ and $H$\n\tthere was always a trivial group homomorphism sending\n\teverything in $G$ to $1_H$, this is not the case for rings.\n\\end{example}\n\n\\section{Ideals}\n\\prototype{The multiples of $5$ are an ideal of $\\ZZ$.}\nNow, just like we were able to mod out by groups,\nwe'd also like to define quotient rings.\nSo once again,\n\\begin{definition}\n\tThe \\vocab{kernel} of a ring homomorphism $\\phi \\colon R \\to S$,\n\tdenoted $\\ker \\phi$, is the set of $r \\in R$ such that $\\phi(r) = 0$.\n\\end{definition}\n\nIn group theory, we were able to characterize the ``normal'' subgroups by a few\nobviously necessary conditions (namely, $gHg\\inv = H$).\nWe can do the same thing for rings, and it's in fact easier because our operations are commutative.\n\nFirst, note two obvious facts:\n\\begin{itemize}\n\t\\ii If $\\phi(x) = \\phi(y) = 0$, then $\\phi(x+y) = 0$ as well.\n\tSo $\\ker \\phi$ should be closed under addition.\n\t\\ii If $\\phi(x) = 0$, then for any $r \\in R$ we have\n\t$\\phi(rx) = \\phi(r)\\phi(x) = 0$ too.\n\tSo for $x \\in \\ker \\phi$ and \\emph{any} $r \\in R$,\n\twe have $rx \\in \\ker\\phi$.\n\\end{itemize}\n\nA (nonempty) subset $I \\subseteq R$ is called\nan ideal if it satisfies these properties.\nThat is,\n\\begin{definition}\n\tA nonempty subset $I \\subseteq R$ is an \\vocab{ideal}\n\tif it is closed under addition, and for each $x \\in I$,\n\t$rx \\in I$ for all $r \\in R$.\n\tIt is \\vocab{proper} if $I \\neq R$.\n\\end{definition}\n\nNote that in the second condition, $r$ need not be in $I$!\nSo this is stronger than merely saying $I$ is closed under multiplication.\n\\begin{remark}\n\tIf $R$ is not commutative, we also need the condition $xr \\in I$.\n\tThat is, the ideal is \\emph{two-sided}: it absorbs multiplication\n\tfrom both the left and the right.\n\tBut since rings in Napkin are commutative\n\twe needn't worry with this distinction.\n\\end{remark}\n\n\\begin{example}\n\t[Prototypical example of an ideal]\n\tConsider the set $I = 5\\ZZ = \\{\\dots,-10,-5,0,5,10,\\dots\\}$ as an ideal in $\\ZZ$.\n\tWe indeed see $I$ is the kernel of the ``take mod $5$'' homomorphism:\n\t\\[ \\ZZ \\surjto \\ZZ/5\\ZZ. \\]\n\tIt's clearly closed under addition,\n\tbut it absorbs multiplication from \\emph{all} elements of $\\ZZ$:\n\tgiven $15 \\in I$, $999 \\in \\ZZ$, we get $15 \\cdot 999 \\in I$.\n\\end{example}\n\n\\begin{exercise}\n\t[Mandatory: fields have two ideals]\n\tIf $K$ is a field, show that $K$ has exactly two ideals.\n\tWhat are they?\n\t\\label{exer:field_ideal}\n\\end{exercise}\n\nNow we claim that these conditions are sufficient.\nMore explicitly,\n\\begin{theorem}\n\t[Ring analog of normal subgroups]\n\tLet $R$ be a ring and $I \\subsetneq R$.\n\tThen $I$ is the kernel of some homomorphism if and only if it's an ideal.\n\\end{theorem}\n\\begin{proof}\n\tIt's quite similar to the proof for the normal subgroup thing,\n\tand you might try it yourself as an exercise.\n\t\n\tObviously the conditions are necessary.\n\tTo see they're sufficient, we \\emph{define} a ring by ``cosets''\n\t\\[ S = \\left\\{ r + I \\mid r \\in R \\right\\}. \\]\n\tThese are the equivalence where we say $r_1 \\sim r_2$ if $r_1 - r_2 \\in I$\n\t(think of this as taking ``mod $I$'').\n\tTo see that these form a ring, we have to check that the addition\n\tand multiplication we put on them is well-defined.\n\tSpecifically, we want to check that if $r_1 \\sim s_1$ and $r_2 \\sim s_2$,\n\tthen $r_1 + r_2 \\sim s_1 + s_2$ and $r_1r_2 \\sim s_1s_2$.\n\tWe actually already did the first part\n\t-- just think of $R$ and $S$ as abelian\n\tgroups, forgetting for the moment that we can multiply.\n\tThe multiplication is more interesting.\n\t\\begin{exercise}\n\t\t[Recommended]\n\t\tShow that if $r_1 \\sim s_1$ and $r_2 \\sim s_2$, then $r_1r_2 \\sim s_1s_2$.\n\t\tYou will need to use the fact that $I$ absorbs multiplication\n\t\tfrom \\emph{any} elements of $R$, not just those in $I$.\n\t\\end{exercise}\n\tAnyways, since this addition and multiplication is well-defined there\n\tis now a surjective homomorphism $R \\to S$ with kernel exactly $I$.\n\\end{proof}\n\n\\begin{definition}\n\tGiven an ideal $I$, we define as above the \\vocab{quotient ring}\n\t\\[ R/I \\defeq \\left\\{ r+I \\mid r \\in R \\right\\}. \\]\n\tIt's the ring of these equivalence classes.\n\tThis ring is pronounced ``$R$ mod $I$''.\n\\end{definition}\n\\begin{example}[$\\ZZ/5\\ZZ$]\n\tThe integers modulo $5$ formed by ``modding out additively by $5$''\n\tare the $\\Zc 5$ we have already met.\n\\end{example}\nBut here's an important point:\njust as we don't actually think of $\\ZZ/5\\ZZ$ as consisting of\n$k + 5\\ZZ$ for $k=0,\\dots,4$,\nwe also don't really want to think about $R/I$ as elements $r+I$.\nThe better way to think about it is\n\\begin{moral}\n\t$R/I$ is the result when we declare that elements of $I$ are all zero;\n\tthat is, we ``mod out by elements of $I$''.\n\\end{moral}\nFor example, modding out by $5\\ZZ$ means that we consider\nall elements in $\\ZZ$ divisible by $5$ to be zero.\nThis gives you the usual modular arithmetic!\n\n\\begin{exercise}\n\tEarlier, we wrote $\\ZZ[i]$ for the Gaussian integers,\n\twhich was a slight abuse of notation.\n\tConvince yourself that this ring\n\tcould instead be written as $\\ZZ[x] / (x^2+1)$,\n\tif we wanted to be perfectly formal.\n\t(We will stick with $\\ZZ[i]$ though --- it's more natural.)\n\n\tFigure out the analogous formalization of $\\ZZ[\\sqrt[3]{2}]$.\n\\end{exercise}\n\n\\section{Generating ideals}\n\\prototype{In $\\ZZ$, the ideals are all of the form $(n)$.}\n\nLet's give you some practice with ideals.\n\nAn important piece of intuition is that once an ideal\ncontains a unit, it contains $1$, and\nthus must contain the entire ring.\nThat's why the notion of ``proper ideal''\nis useful language.\nTo expand on that:\n\\begin{proposition}\n\t[Proper ideal $\\iff$ no units]\n\tLet $R$ be a ring and $I \\subseteq R$ an ideal.\n\tThen $I$ is proper (i.e.\\ $I \\ne R$)\n\tif and only if it contains no units of $R$.\n\\end{proposition}\n\\begin{proof}\n\tSuppose $I$ contains a unit $u$, i.e.\\ an element $u$\n\twith an inverse $u\\inv$.\n\tThen it contains $u \\cdot u\\inv = 1$, and thus $I = R$.\n\tConversely, if $I$ contains no units, it is obviously proper.\n\\end{proof}\nAs a consequence, if $K$ is a field,\nthen its only ideals are $(0)$ and $K$\n(this was \\Cref{exer:field_ideal}).\nSo for our practice purposes, we'll be working with rings that aren't fields.\n\nFirst practice: $\\ZZ$.\n\\begin{exercise}\n\tShow that the only ideals of $\\ZZ$ are precisely those\n\tsets of the form $n\\ZZ$, where $n$ is a nonnegative integer.\n\\end{exercise}\n\nThus, while ideals of fields are not terribly interesting,\nideals of $\\ZZ$ look eerily like elements of $\\ZZ$.\nLet's make this more precise.\n\\begin{definition}\n\tLet $R$ be a ring.\n\tThe \\vocab{ideal generated} by a set of elements $x_1, \\dots, x_n \\in R$\n\tis denoted by $I = (x_1, x_2, \\dots, x_n)$\n\tand given by\n\t\\[ I = \\left\\{ r_1 x_1 + \\dots + r_n x_n \\mid r_i \\in R \\right\\}.  \\]\n\tOne can think of this as ``the smallest ideal containing all the $x_i$''.\n\\end{definition}\n\nThe analogy of putting the $\\{x_i\\}$ in a sealed box and shaking vigorously\nkind of works here too.\n\\begin{remark}\n\t[Linear algebra digression]\n\tIf you know linear algebra,\n\tyou can summarize this as: an ideal is an $R$-module.\n\tThe ideal $(x_1, \\dots, x_n)$ is the submodule spanned by $x_1, \\dots, x_n$.\n\\end{remark}\n\nIn particular, if $I = (x)$ then $I$ consists of exactly the\n``multiples of $x$'', i.e.\\ numbers of the form $rx$ for $r \\in R$.\n\\begin{remark}\n\tWe can also apply this definition to infinite generating sets,\n\tas long as only finitely many of the $r_i$ are not zero\n\t(since infinite sums don't make sense in general).\n\\end{remark}\n\n\\begin{example}[Examples of generated ideals]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii As $(n) = n\\ZZ$ for all $ \\in \\ZZ$,\n\t\tevery ideal in $\\ZZ$ is of the form $(n)$.\n\t\t\\ii In $\\ZZ[i]$, we have\n\t\t$(5) = \\left\\{ 5a + 5b i \\mid a,b \\in \\ZZ \\right\\}$.\n\t\t\\ii In $\\ZZ[x]$, the ideal $(x)$ consists of polynomials\n\t\twith zero constant terms.\n\t\t\\ii In $\\ZZ[x,y]$, the ideal $(x,y)$ again consists\n\t\tof polynomials with zero constant terms.\n\t\t\\ii In $\\ZZ[x]$, the ideal $(x,5)$ consists of polynomials\n\t\twhose constant term is divisible by $5$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{ques}\n\tPlease check that the set\n\t$I = \\left\\{ r_1 x_1 + \\dots + r_n x_n \\mid r_i \\in R \\right\\}$\n\tis indeed always an ideal (closed under addition,\n\tand absorbs multiplication).\n\\end{ques}\nNow suppose $I = (x_1, \\dots, x_n)$.\nWhat does $R/I$ look like?\nAccording to what I said at the end of the last section,\nit's what happens when we ``mod out'' by each of the elements $x_i$.\nFor example\\dots\n\\begin{example}\n\t[Modding out by generated ideals]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $R = \\ZZ$ and $I = (5)$. Then $R/I$ is literally\n\t\t$\\ZZ/5\\ZZ$, or the ``integers modulo $5$'':\n\t\tit is the result of declaring $5 = 0$.\n\t\t\\ii Let $R = \\ZZ[x]$ and $I = (x)$.\n\t\tThen $R/I$ means we send $x$ to zero; hence $R/I \\cong \\ZZ$\n\t\tas given any polynomial $p(x) \\in R$,\n\t\twe simply get its constant term.\n\t\t\\ii Let $R = \\ZZ[x]$ again and now let $I = (x-3)$.\n\t\tThen $R/I$ should be thought of as the quotient when $x-3 \\equiv 0$,\n\t\tthat is, $x \\equiv 3$.\n\t\tSo given a polynomial $p(x)$ its image after\n\t\twe mod out should be thought of as $p(3)$.\n\t\tAgain $R/I \\cong \\ZZ$, but in a different way.\n\t\t\\ii Finally, let $I = (x-3,5)$.\n\t\tThen $R/I$ not only sends $x$ to three, but also $5$ to zero.\n\t\tSo given $p \\in R$, we get $p(3) \\pmod 5$.\n\t\tThen $R/I \\cong \\ZZ/5\\ZZ$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{remark}\n\t[Mod notation]\n\tBy the way, given an ideal $I$ of a ring $R$, it's totally legit to write\n\t\\[ x \\equiv y \\pmod I \\]\n\tto mean that $x-y \\in I$.\n\tEverything you learned about modular arithmetic carries over.\n\\end{remark}\n\n\\section{Principal ideal domains}\n\\prototype{$\\ZZ$ is a PID, $\\ZZ[x]$ is not.\n$\\CC[x]$ is a PID, $\\CC[x,y]$ is not.}\n\nWhat happens if we put multiple generators in an ideal,\nlike $(10,15) \\subseteq \\ZZ$?\nWell, we have by definition that $(10,15)$ is given as a set by\n\\[ (10,15) \\defeq \\left\\{ 10x + 15y \\mid x,y \\in \\ZZ \\right\\}.  \\]\nIf you're good at number theory you'll instantly\nrecognize that this as $5\\ZZ = (5)$.\nSurprise! In $\\ZZ$, the ideal $(a,b)$ is exactly $\\gcd(a,b) \\ZZ$.\nAnd that's exactly the reason you often see the GCD of two numbers denoted $(a,b)$.\n\nWe call such an ideal (one generated by a single element) a \\vocab{principal ideal}.\nSo, in $\\ZZ$, every ideal is principal.\nBut the same is not true in more general rings.\n\\begin{example}\n\t[A non-principal ideal]\n\tIn $\\ZZ[x]$, $I = (x,2015)$ is \\emph{not} a principal ideal.\n\n\tFor if $I = (f)$ for some polynomial $f \\in I$\n\tthen $f$ divides $x$ and $2015$.\n\tThis can only occur if $f = \\pm 1$,\n\tbut then $I$ contains $\\pm1$, which it does not.\n\\end{example}\nA ring with the property that all its ideals\nare principal is called a \\vocab{principal ideal ring}.\nWe like this property because they effectively\nlet us take the ``greatest common factor''\nin a similar way as the GCD in $\\ZZ$.\n\nIn practice, we actually usually care about\nso-called \\textbf{principal ideal domains (PID's)}.\nBut we haven't defined what a domain is yet.\nNonetheless, all the examples below are actually PID's,\nso we will go ahead and use this word for now,\nand tell you what the additional condition is in the next chapter.\n\n\\begin{example}\n\t[Examples of PID's]\n\tTo reiterate, for now you should just verify\n\tthat these are principal ideal rings,\n\teven though we are using the word PID.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii As we saw, $\\ZZ$ is a PID.\n\n\t\t\\ii As we also saw, $\\ZZ[x]$ is not a PID,\n\t\tsince $I = (x,2015)$ for example is not principal.\n\n\t\t\\ii It turns out that for a field $k$\n\t\tthe ring $k[x]$ is always a PID.\n\t\tFor example, $\\QQ[x]$, $\\RR[x]$, $\\CC[x]$ are PID's.\n\n\t\tIf you want to try and prove this,\n\t\tfirst prove an analog of Bezout's lemma,\n\t\twhich implies the result.\n\n\t\t\\ii $\\CC[x,y]$ is not a PID, because $(x,y)$\n\t\tis not principal.\n\t\\end{enumerate}\n\\end{example}\n\n\\section{Noetherian rings}\n\\prototype{$\\ZZ[x_1, x_2, \\dots]$ is not Noetherian,\n\tbut most reasonable rings are.\n\tIn particular polynomial rings are.\n\t(Equivalently, only weirdos care about non-Noetherian rings).}\n\nIf it's too much to ask that an ideal is generated by \\emph{one} element,\nperhaps we can at least ask that our ideals\nare generated by \\emph{finitely many} elements.\nUnfortunately, in certain weird rings this is also not the case.\n\\begin{example}\n\t[Non-Noetherian ring]\n\tConsider the ring $R = \\ZZ[x_1, x_2, x_3, \\dots]$\n\twhich has \\emph{infinitely} many free variables.\n\tThen the ideal $I = (x_1, x_2, \\dots) \\subseteq R$\n\tcannot be written with a finite generating set.\n\\end{example}\nNonetheless, most ``sane'' rings we work in\n\\emph{do} have the property that their ideals are finitely generated.\nWe now name such rings and give two equivalent definitions:\n\\begin{proposition}[The equvialent definitions of a Noetherian ring]\n\tFor a ring $R$, the following are equivalent:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Every ideal $I$ of $R$ is finitely generated\n\t\t(i.e.\\ can be written with a finite generating set).\n\t\t\\ii There does \\emph{not} exist an\n\t\tinfinite ascending chain of ideals\n\t\t\\[ I_1 \\subsetneq I_2 \\subsetneq I_3 \\subsetneq \\dots. \\]\n\t\tThe absence of such chains is often\n\t\tcalled the \\vocab{ascending chain condition}.\n\t\\end{enumerate}\n\tSuch rings are called \\vocab{Noetherian}.\n\\end{proposition}\n\n\\begin{example}\n\t[Non-Noetherian ring breaks ACC]\n\tIn the ring $R = \\ZZ[x_1, x_2, x_3, \\dots]$ we have\n\tan infinite ascending chain\n\t\\[ (x_1) \\subsetneq (x_1, x_2) \\subsetneq (x_1,x_2,x_3) \\subsetneq \\dots. \\]\n\\end{example}\nFrom the example, you can kind of see why the proposition is true:\nfrom an infinitely generated ideal you can extract an ascending chain\nby throwing elements in one at a time.\nI'll leave the proof to you if you want to\ndo it.\\footnote{On the other hand, every undergraduate\n\tclass in this topic I've seen makes you do it as homework.\n\tAdmittedly I haven't gone to that many such classes.}\n\n\\begin{ques}\n\tWhy are fields Noetherian?\n\tWhy are PID's (such as $\\ZZ$) Noetherian?\n\\end{ques}\n\nThis leaves the question:\nis our prototypical non-example of a PID,\n$\\ZZ[x]$, a Noetherian ring?\nThe answer is a glorious yes,\naccording to the celebrated Hilbert basis theorem.\n\\begin{theorem}[Hilbert basis theorem]\n\tGiven a Noetherian ring $R$,\n\tthe ring $R[x]$ is also Noetherian.\n\tThus by induction, $R[x_1, x_2, \\dots, x_n]$ is Noetherian\n\tfor any integer $n$.\n\t\\label{thm:hilbert_basis}\n\\end{theorem}\nThe proof of this theorem is really olympiad flavored,\nso I couldn't possibly spoil it -- I've\nleft it as a problem at the end of this chapter.\n\nNoetherian rings really shine in algebraic geometry,\nand it's a bit hard for me to motivate them right now,\nother than to say\n``most rings you'll encounter are Noetherian''.\nPlease bear with me!\n\n\\section{\\problemhead}\n\n\\begin{problem}\n\tThe ring $R = \\RR[x] / (x^2+1)$ is one that you've seen before.\n\tWhat is its name?\n\t\\begin{hint}\n\t\t$R = \\RR[i]$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThis is just $\\RR[i] = \\CC$.\n\t\tThe isomorphism is given by $x \\mapsto i$,\n\t\twhich has kernel $(x^2+1)$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tShow that $\\CC[x] / (x^2-x) \\cong \\CC \\times \\CC$.\n\t\\begin{hint}\n\t\tThe isomorphism is given by $x \\mapsto (1,0)$\n\t\tand $1-x \\mapsto (0,1)$.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tIn the ring $\\ZZ$, let $I = (2016)$ and $J = (30)$.\n\tShow that $I \\cap J$ is an ideal of $\\ZZ$ and compute its elements.\n\\end{problem}\n\n\\begin{sproblem}\n\t\\label{prob:inclusion_preserving}\n\tLet $R$ be a ring and $I$ an ideal.\n\tFind an inclusion-preserving bijection between\n\t\\begin{itemize}\n\t\t\\ii ideals of $R/I$, and\n\t\t\\ii ideals of $R$ which contain $I$.\n\t\\end{itemize}\n\\end{sproblem}\n\n\\begin{problem}\n\tLet $R$ be a ring.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Prove that there is exactly one ring homomorphism $\\ZZ \\to R$.\n\t\t\\ii Prove that the number of ring homomorphisms\n\t\t$\\ZZ[x] \\to R$ is equal to the number of elements of $R$.\n\t\\end{enumerate}\n\t\\begin{hint}\n\t\tFor (b) homomorphism is uniquely determined by the choice of $\\psi(x) \\in R$\n\t\\end{hint}\n\\end{problem}\n\n%\\begin{problem}\n%\t[$\\phi(1_R) = 1_S$ is really necessary]\n%\tFind two rings $R$ and $S$ and a \\emph{nonzero} function\n%\t$f \\colon R \\to S$ such that\n%\t\\begin{itemize}\n%\t\t\\ii $f(x+y) = f(x) + f(y)$ for $x,y \\in R$,\n%\t\t\\ii $f(xy) = f(x) f(y)$ for $x,y \\in R$,\n%\t\t\\ii $f(1_R) \\ne 1_S$ (i.e.\\ $f$ is not a ring homomorphism).\n%\t\\end{itemize}\n%\t\\begin{hint}\n%\t\tTake $S = R \\times R$ with $R$ nonzero.\n%\t\\end{hint}\n%\t\\begin{sol}\n%\t\tThe map $R \\to R \\times R$ by $x \\mapsto (x,0)$ will always work,\n%\t\twith $R$ nonzero.\n%\t\\end{sol}\n%\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tProve the Hilbert basis theorem, \\Cref{thm:hilbert_basis}.\n\\end{problem}\n\n\\begin{problem}\n\t[USA Team Selection Test 2016]\n\tLet $\\FF_p$ denote the integers modulo a fixed prime number $p$.\n\tDefine $\\Psi \\colon \\FF_p[x] \\to \\FF_p[x]$ by\n\t\\[ \\Psi\\left( \\sum_{i=0}^n a_i x^i \\right) = \\sum_{i=0}^n a_i x^{p^i}. \\]\n\tLet $S$ denote the image of $\\Psi$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Show that $S$ is a ring with addition\n\t\tgiven by polynomial addition,\n\t\tand multiplication given by \\emph{function composition}.\n\t\t\\ii Prove that $\\Psi \\colon \\FF_p[x] \\to S$\n\t\tis then a ring isomorphism.\n\t\\end{enumerate}\n\\end{problem}\n\n\\begin{problem} % from Brian Chen\n\t\\yod\n\tLet $A \\subseteq B \\subseteq C$ be rings.\n\tSuppose $C$ is a finitely generated $A$-module.\n\tDoes it follow that $B$ is a finitely generated $A$-module?\n\t% Assume $A$ is Noetherian. Show that $B$ is finitely generated as an $A$-module.\n\t% Find a counterexample where $A$ is not Noetherian.\n\t\\begin{hint}\n\t\tI think the result is true if you add the assumption $A$ is Noetherian,\n\t\tso look for trouble by picking $A$ not Noetherian.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tNope! Pick\n\t\t\\begin{align*}\n\t\t\tA &= \\ZZ[x_1, x_2, \\dots] \\\\\n\t\t\tB &= \\ZZ[x_1, x_2, \\dots, \\eps x_1, \\eps x_2, \\dots] \\\\\n\t\t\tC &= \\ZZ[x_1, x_2, \\dots, \\eps].\n\t\t\\end{align*}\n\t\twhere $\\eps \\neq 0$ but $\\eps^2 = 0$.\n\t\tI think the result is true if you add the assumption $A$ is Noetherian.\n\t\\end{sol}\n\\end{problem}\n\n\n", "meta": {"hexsha": "69fb89d389d21c2ca86c187f52822817dbff556c", "size": 30008, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/H113/ideals.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/ideals.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/ideals.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.1542168675, "max_line_length": 99, "alphanum_fraction": 0.6927152759, "num_tokens": 9575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.6635258733839368}}
{"text": "\\section{Model Description}\nThis module is a simulation environment module which simulates the analog voltage interface of a RW cluster.  The input is an array of voltages $V_{i}$.  The Reaction Wheel (RW) motor torque $u_{s_{i}}$ is evaluated using a linear mapping\n\\begin{equation}\nu_{s_{i}} = V_{i} \\gamma_{i} SF_{i} + b_{i}\n\\end{equation}\nwhere $\\gamma$ is constant value gain. SF is the scale factor error (i.e. a constant 1\\% gain error SF = 1.01). $b$ is the bias term (i.e. a constant 1 Nm error on torque b = 1.)  The output of the module is an array of RW motor torques.  The deadband and saturation behavior of the RW speed is modeled inside the RW dynamics model.  ", "meta": {"hexsha": "322c888b3ebcb7ac8b76076dab3c2500d2968058", "size": 677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/deviceInterface/rwVoltageInterface/_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/deviceInterface/rwVoltageInterface/_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/deviceInterface/rwVoltageInterface/_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": 112.8333333333, "max_line_length": 334, "alphanum_fraction": 0.7341211226, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6634579473334253}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 1}\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 a vacuum boundaries at $x=a$ and $x=0$. \nAt $x=0$ there is also a uniformly distributed source plane with strength $s''$ [neutrons per area]. \nFind the flux in this geometry. \n(You may use the substitution $L = \\sqrt{\\frac{D}{\\Sigma_a}}$.)\n\n", "meta": {"hexsha": "f679dbcb58226c710cce36e80ec20ddd6fe6e29a", "size": 522, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc10/disc10_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/disc10/disc10_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/disc10/disc10_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": 52.2, "max_line_length": 119, "alphanum_fraction": 0.6436781609, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.66345794182468}}
{"text": "% -*- compile-command: \"stack exec --package diagrams-lib --package diagrams-pgf --package diagrams-contrib --package diagrams-builder --package palette -- pdflatex --enable-write18 groups.tex\" -*-\n\\documentclass{article}\n\n\\usepackage{hyperref}\n\\usepackage{url}\n\\usepackage{amsmath}\n\n\\usepackage[outputdir=diagrams, extension=pgf, backend=pgf, input]{diagrams-latex}\n\\usepackage{pgf}\n\n\\usepackage{graphicx}\n\\graphicspath{{images/}}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\title{Operation tables}\n\\author{Brent Yorgey, \\href{http://www.mathlesstraveled.com}{\\texttt{mathlesstraveled.com}} \\\\ \\raisebox{-0.4em}{\\includegraphics[width=44px]{../CC-BY.png}} \\href{http://creativecommons.org/licenses/by/4.0/}{\\texttt{creativecommons.org/licenses/by/4.0/}}}\n\n\\begin{document}\n\n\\maketitle\n\n\\fontsize{16}{20}\\selectfont\n\nIn this activity you're going to fill out some \\emph{operation\n  tables}.  Each table will have some items listed across the top and\nside.  For a given operation, your job is to fill each square with the\nresult of that operation on the items in the corresponding row and\ncolumn.  For example, if we list $2$, $3$, and $5$ along the side and\ntop, and the operation is addition, then the operation table would\nlook like this:\n\n\\begin{center}\n\\begin{tabular}{l|lll}\n$+$ & 2 & 3 & 5  \\\\ \\hline\n2   & 4 & 5 & 7  \\\\\n3   & 5 & 6 & 8  \\\\\n5   & 7 & 8 & 10\n\\end{tabular}\n\\end{center}\n\n\\section*{XOR}\n\nFill in each spot in the table with the XOR of the two Boolean values.\n\n\\begin{center}\n\\begin{tabular}{l|ll}\n$\\oplus$ & F & T \\\\ \\hline\nF        &   &   \\\\\nT        &   &\n\\end{tabular}\n\\end{center}\n\n\\section*{Addition}\n\nFill in the table using addition.\n\n\\begin{center}\n\\begin{tabular}{l|lll}\n$+$ & 0 & 1 & 2 \\\\ \\hline\n0        &   &   &   \\\\\n1        &   &   &   \\\\\n2        &   &   &\n\\end{tabular}\n\\end{center}\n\n\\section*{Addition modulo 3}\n\nFill in the table using \\emph{addition modulo $3$}.  That is, imagine\nthat the number line ``wraps around'' back to $0$ when it gets to\n$3$.  If you get an answer bigger than $3$, subtract $3$ from it until\nyou are back down under $3$.  For example, $2 +_3 2 = 1$ since $2 + 2\n= 4$ and $4 - 3 = 1$.\n\n\\begin{center}\n\\begin{tabular}{l|lll}\n$+_3$ & 0 & 1 & 2 \\\\ \\hline\n0        &   &   &   \\\\\n1        &   &   &   \\\\\n2        &   &   &\n\\end{tabular}\n\\end{center}\n\n\\section*{Addition modulo 5}\n\n\\begin{center}\n\\begin{tabular}{l|lllll}\n$+_5$ & 0 & 1 & 2 & 3 & 4 \\\\ \\hline\n0        &   &   &   &   &   \\\\\n1        &   &   &   &   &   \\\\\n2        &   &   &   &   &   \\\\\n3        &   &   &   &   &   \\\\\n4        &   &   &   &   &  \n\\end{tabular}\n\\end{center}\n\n\\section*{Max}\n\nFill in the table using the $\\max$ operation, which returns the\nlargest of its two inputs.\n\n\\begin{center}\n\\begin{tabular}{l|lll}\n$\\max$ & 0 & 1 & 2 \\\\ \\hline\n0      &   &   &   \\\\\n1      &   &   &   \\\\\n2      &   &   &  \n\\end{tabular}\n\\end{center}\n\n\\newpage\n\n\\section*{Multiplication modulo 5}\n\nMultiplication modulo $5$ works just like addition modulo $5$, but\nwith multiplication: to compute $a \\times_5 b$, first multiply $a$ and\n$b$, then keep subtracting $5$ until you get something smaller than\n$5$.  For example, $3 \\times_5 4 = 2$ since $3 \\times 4 = 12$ and $12\n- 5 - 5 = 2$.\n\n\\begin{center}\n\\begin{tabular}{l|llll}\n$\\times_5$ & 1 & 2 & 3 & 4 \\\\ \\hline\n1          &   &   &   &   \\\\\n2          &   &   &   &   \\\\\n3          &   &   &   &   \\\\\n4          &   &   &   &\n\\end{tabular}\n\\end{center}\n\n\\newpage\n\nCut out the square on this page.  Ideally, you will also be able to\nsee the letter F through the back of the paper.  If you can't see it\nvery well you are welcome to draw in a backwards F on the back that\nmatches up with the F on the front. \\vspace{1in}\n\n\\begin{center}\n\\begin{diagram}[width=300]\ndia = text \"F\" # fontSizeL 0.25 <> square 1\n\\end{diagram}\n\\end{center}\n\n\\newpage\n\n\\newcommand{\\elt}[1]{\\raisebox{-0.25em}{\\includegraphics[height=1.2em]{#1.png}}}\n\nLet's list all the different things we can do to the square so that it\nends up still being a square in the same orientation (that is, we want\nto list all the \\emph{symmetries} of the square).  Each icon on the\nnext page represents an operation we can do to the square.  For\nexample, the \\elt{dot} in the first row means to do nothing; the \\elt{r1} in\nthe second row means to rotate the square by 1/4 turn, and so on.  On\nthe right of the colon is a graphical depiction of the operation.  If\nyou start your square with the letter F facing you and perform the\noperation, it should end up looking like the square at the end.  For\nexample, the row for \\elt{r1} looks like \\elt{r1row}, meaning that if\nyou start with \\elt{f} and perform the \\elt{r1} operation, the square\nends up looking like \\elt{r1f}.  You should physically do all the\noperations with your square to make sure you understand how they work!\n\n\\begin{center}\n  \\includegraphics[width=3in]{d4.png}\n\\end{center}\n\n\\newpage\n\nWe can also \\emph{combine} two operations on the square by doing first\none and then the other.  In the end this will have the same effect as\nif we had done a single operation.  For example, flipping the square\nvertically and then flipping it vertically again will put it back the\nway it started, so\n\n\\begin{center}\n  \\includegraphics[height=0.5in]{vv.png}\n\\end{center}\n\nAs another example,\n\n\\begin{center}\n  \\includegraphics[height=0.5in]{dh.png}\n\\end{center}\n\n(Try this with your physical square and make sure you understand it!)\n\n\\newpage\n\nFill in the table below, using the combining operation explained on\nthe previous page.\n\n\\begin{center}\n  \\includegraphics[width=5in]{table.png}\n\\end{center}\n\nWhat patterns do you notice?\n\n\\end{document}\n", "meta": {"hexsha": "1670ca57f82be83c976d1b580bcfdc57a40f2c7b", "size": 5644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/groups.tex", "max_stars_repo_name": "byorgey/coronavirus-math-worksheets", "max_stars_repo_head_hexsha": "b222c019641b36265662164a465c1e2acd781460", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-23T08:07:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-23T09:02:57.000Z", "max_issues_repo_path": "groups/groups.tex", "max_issues_repo_name": "byorgey/coronavirus-math-worksheets", "max_issues_repo_head_hexsha": "b222c019641b36265662164a465c1e2acd781460", "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": "groups/groups.tex", "max_forks_repo_name": "byorgey/coronavirus-math-worksheets", "max_forks_repo_head_hexsha": "b222c019641b36265662164a465c1e2acd781460", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5050505051, "max_line_length": 255, "alphanum_fraction": 0.6472360028, "num_tokens": 1810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8856314858927012, "lm_q1q2_score": 0.6634152216140187}}
{"text": "\\subsection{Subdifferentials}\\label{subsec:subdifferentials}\n\nLet \\( X \\) be a Hausdorff \\hyperref[def:topological_vector_space]{topological vector space}, let \\( D \\subseteq X \\) be an open set and \\( f: D \\to \\BbbR \\) be any function.\n\n\\begin{definition}\\label{def:subdifferentials}\n  We fix a point \\( x \\in D \\). We define different types of \\term{subgradients} and \\term{subdifferentials}. Subgradients are linear functionals \\( x^* \\in X^* \\) that approximate \\( f \\) at the point \\( x \\) in a certain way, and a subdifferential is the set of all subgradients of a given type.\n\n  \\begin{thmenum}\n    \\thmitem{def:subdifferentials/convex}\\mcite[59]{Clarke2013}We say that \\( x^* \\in X^* \\) is a \\term{subgradient of \\( f \\) at \\( x \\)} if for every \\( y \\in D \\) we have\n    \\begin{equation*}\n      f(y) - f(x) \\geq \\inprod {x^*} {y - x}.\n    \\end{equation*}\n\n    The \\term{subdifferential of \\( f \\) at \\( x \\)} is denoted by \\( \\partial f(x) \\) and is also sometimes called the \\term{convex subdifferential} because of \\fullref{thm:convex_iff_subdifferential_nonempty}.\n\n    \\thmitem{def:subdifferentials/clarke}\\mcite[def. 10.3]{Clarke2013}We say that \\( x^* \\in X^* \\) is a \\term{Clarke (generalized) subgradient of \\( f \\) at \\( x \\)} if for every direction \\( h \\in X \\) we have\n    \\begin{equation*}\n      f^\\circ(x)(h) \\geq \\inprod {x^*} h,\n    \\end{equation*}\n    where \\( f^\\circ(x)(h) \\) is the generalized Clarke \\hyperref[def:nonsmooth_derivatives/clarke]{derivative}.\n\n    The \\term{subdifferential of \\( f \\) at \\( x \\)} is denoted by \\( \\partial_C f(x) \\). Confusingly, the Clarke subdifferential is called the \\enquote{generalized gradient} by Clarke himself with no special name for the Clarke subgradients.\n\n    See \\fullref{subsec:clarke_gradients} for properties of these subgradients.\n\n    \\thmitem{def:subdifferentials/proximal}\\mcite[227]{Clarke2013}We say that \\( x^* \\in X^* \\) is a \\term{proximal subgradient of \\( f \\) at \\( x \\)} if there exist \\( \\sigma > 0 \\) and a neighborhood \\( V \\subseteq X \\) of \\( x \\) such that for every \\( y \\in D \\cap V \\) we have\n    \\begin{equation*}\n      f(y) - f(x) + \\sigma \\norm{y - x}^2 \\geq \\inprod {x^*} {y - x}.\n    \\end{equation*}\n\n    The \\term{proximal subdifferential of \\( f \\) at \\( x \\)} is denoted by \\( \\partial_P f(x) \\).\n\n    \\thmitem{def:subdifferentials/limiting}\\mcite[def. 11.10]{Clarke2013}Suppose the following are satisfied:\n    \\begin{enumerate}\n      \\item \\( \\{ x_n \\}_n \\subseteq D \\) is a sequence of points converging to \\( x \\)\n      \\item \\( f(x_n) \\to f(x) \\) (redundant if \\( f \\) is continuous)\n      \\item \\( x_n^* \\) is a proximal subgradient for \\( f \\) at \\( x_n \\) for every \\( n \\in \\BbbZ_{>0} \\).\n    \\end{enumerate}\n\n    If the limit \\( x^* \\coloneqq \\lim_n x_n^* \\) exists and is a continuous linear functional, we call \\( x^* \\) a \\term{limiting subgradient of \\( f \\) at \\( x \\)}.\n\n    The \\term{limiting subdifferential of \\( f \\) at \\( x \\)} is denoted by \\( \\partial_P f(x) \\).\n  \\end{thmenum}\n\\end{definition}\n", "meta": {"hexsha": "a5bd03fb0a9b1edcd48a6fdfdbcdcf6495acb5f8", "size": 3029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/subdifferentials.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/subdifferentials.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/subdifferentials.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.3111111111, "max_line_length": 297, "alphanum_fraction": 0.6464179597, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7490872243177519, "lm_q1q2_score": 0.6634152202296897}}
{"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 2 for Pattern Recognition}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 1}\n{\n    \\subsection*{(1)}\n    {\n        The error function is minimized when optimized: \n        $$\\frac{\\partial}{\\partial w_0} E(w, w_0) = \\sum_{i=1}^{n} {(w^T x_i + w_0 - t_i)} $$\n        $$= n w^T m + nw_0 + n_1 \\frac{n}{n_1} + n_2 \\frac{-n}{n_2} = n ( w^T m + w_0 ) = 0,$$\n        which yields $$w_0 = -w^T m$$.\n    }\n\n    \\subsection*{(2)}\n    {\n        Denote the observation matrix and the response matrix as \n        $$x = [x_1-m, x_2-m, \\cdots, x_n-m]$$ and $$t = [t_1, t_2, \\cdots, t_n].$$\n        Plug in the optimal $w_0 = -w^T m$, and the error function can thus be expressed as \n        $$E(w) = \\frac{1}{2} (w^T x - t)(w^T x - t)^T.$$\n\n        By matrix calculus\\footnote{See https://en.wikipedia.org/wiki/Matrix\\_calculus}, we have\n        $$\\frac{\\partial}{\\partial w} E(w) = -x (t^T - x^T w) = 0,$$\n        that is, $$x x^T w = x t^T.$$\n\n        Note that $$x t^T = \\left[ \\sum_{i=1}^{n} {(x_i t_i)} \\right] - m \\cdot \\sum_{i=1}^{n} {x_i} $$\n        $$= \\left[ \\left(n_1 \\frac{n}{n_1} m_1 + n_2 \\frac{-n}{n_2} m_2 \\right) \\right] - m \\cdot \\left( n_1 \\frac{n}{n_1} + n_2 \\frac{-n}{n_2} \\right) = n (m_1 - m_2),$$ and \n        $$m = \\frac{n_1}{n}m_1 + \\frac{n_2}{n}m_2 = m_1 - \\frac{n_2}{n}(m_1-m_2) = m_2 + \\frac{n_1}{n}(m_1-m_2),$$ we have\n        $$x x^T = \\sum_{i\\in C_1}{(x_i - m_1 + \\frac{n_2}{n}(m_1-m_2))(x_i - m_1 + \\frac{n_2}{n}(m_1-m_2))^T} $$$$+ \\sum_{i\\in C_2}{(x_i - m_2 - \\frac{n_1}{n}(m_1-m_2))(x_i - m_2 - \\frac{n_1}{n}(m_1-m_2))^T}$$\n        $$= \\sum_{i\\in C_1}{(x_i - m_1)(x_i - m_1)^T} + \\sum_{i\\in C_2}{(x_i - m_2)(x_i - m_2)^T} + \\frac{n_1 n_2}{n^2} \\sum_{i=1}^{n} {(m_1 - m_2)(m_1 - m_2)^T}$$\n        $$= S_w + \\frac{n_1 n_2}{n} S_B.$$\n\n        Therefore, we proved that $$\\left( S_w + \\frac{n_1 n_2}{n} S_B \\right) w = n (m_1 - m2)$$ when $w$ is optimal.\n\n    }\n\n    \\subsection*{(3)}\n    {\n        Note that $$S_B w = (m_1 - m_2) (m_1 - m_2)^T w = (m_1 - m_2) \\cdot \\left[ (m_1 - m_2)^T w \\right],$$ and that $(m_1 - m_2)^T w$ is a scalar. Therefore, the vector $S_B w$ is proportional to $m_1-m_2$, which means $$w \\propto S_w^{-1} (m_1 - m_2).$$\n    }\n}\n\n\\section*{Question 2}\n{\n    \\subsection*{Data Visualization}\n    {\n        Since the dimension of original data is high, we apply PCA (Principal Component Analysis) and extract the first two principal compenents for a scatter plot. \n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{pca.png}\n            \\caption{Scatter plot}\n        \\end{figure}\n\n        The data seems linearly separable, although there are a few outliers.\n    }\n\n    \\subsection*{Logistic Regression}\n    {\n        I implement the algorithm on my own, using a loss function based on cross entropy\n        $$L(\\theta) = - \\sum_{i} {\\left[ y_i \\log{(h_\\theta (x_i))} + (1 - y_i) \\log{(1 - h_\\theta (x_i))}\\right]},$$\n        where $$h_\\theta (x_i) = \\frac{1}{1 + \\exp{(- \\theta^T x_i)}}.$$\n\n        Gradient descent is employed to solve the optimal parameter $\\theta$. A column of ones is attached to the data matrix, in order not to write the intercept in the expression.\n\n        The error rate is $3.33\\%$ on the validation set.\n\n    }\n\n    \\subsection*{Fisher's Discriminant}\n    {\n        I implement the algorithm on my own, using the formula in Question 1.\n\n        The error rate is $1.43\\%$ on the validation set.\n\n    }\n\n    \\subsection*{Discussion}\n    {\n        Why does the Fisher's method have better performance than logistic regression? \n\n        Their main difference is their loss functions. Logistic regression uses the cross entropy, while the Fisher's method adopts the ordinary quadratic loss, or the sum of squared errors (SSE). With outliers in consideration, the cross entropy tends to punish more on outliers, compared to the SSE loss function, and therefore, is more likely to result in over fitting.\n\n        Another reason is that the Fisher's method considers the variance of two categories. It can predict the data distribution well if the positive samples have a variance different from that of the negative samples.\n\n    }\n}\n\n\\section*{Source Code}\n{\n    Please download the souece code from http://39.106.23.58/files/PR2\\_2015011506.7z\n}\n\n\\clearpage\n\\end{document}\n    ", "meta": {"hexsha": "fe4714a07fc0d401125ecc511cc2ae521bc57fc5", "size": 4811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2/Homework2.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": "HW2/Homework2.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": "HW2/Homework2.tex", "max_forks_repo_name": "kingium/PatternRecognitionForUndergrads", "max_forks_repo_head_hexsha": "5cd08f3a260fae4a7edaf71599433e93484863b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8347826087, "max_line_length": 372, "alphanum_fraction": 0.6175431303, "num_tokens": 1690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8856314723088732, "lm_q1q2_score": 0.6634152114385468}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\title{Method of Moments for Mixture of Gaussians}\n\\author{Yao Zhu\\thanks{yzhu221@bloomberg.net}\\\\ Derivatives Pricing, Bloomberg LP}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\section{Mixture of Spherical Gaussians with the same variance parameter $\\sigma^2$}\nFor clarity of presenting the idea of method of moments, we consider the mixture of spherical Gaussians with the same covariance. Under this setting, a random variable $X\\in R^{d}$ is generated as follows:\n\\begin{align}\np(Z=i) &= w_i\n\\label{eq-mog-gen}\n\\\\\n\\nonumber\nX|Z=i &\\sim \\mathcal{N}(\\mu_i,\\sigma^2 I_{d})\n\\end{align}\nfor $i=1,\\ldots,k$, where $k$ is a known number and $k\\leq d$, $I_d$ is the $d\\times d$ identity matrix, and $\\sigma^2$ is the variance parameter common to all $k$ components. We further assume the following non-degeneracy condition:\n\\par\n\\textbf{Non-degeneracy Condition}: $\\mu_i,i=1,\\ldots,k$ are linearly independent, and $w_i>0$ for all $i=1,\\ldots,k$.\n\\par\nWe target to recover the parameters $\\{w_i,\\mu_i\\}_{i=1}^k$ and $\\sigma^2$ from a sample of data points $\\{x_n\\}_{n=1}^N$ generated according to \\eqref{eq-mog-gen}.\n\\section{Raw Moments}\n\\subsection{Tensor product}\nIn order to work with moments (especially moments of order higher than $2$), we need to the notion of \\textit{tensor product}, denoted by $\\otimes$. Let $X_1,X_2,X_3\\in R^{d}$, we define $X_1\\otimes X_2\\otimes X_3$ such that\n\\begin{align}\n\\left(X_1\\otimes X_2\\otimes X_3\\right)_{jlm} &= (X_1)_{j}(X_2)_{l}(X_3)_{m}\n\\end{align}\nfor $j,l,m=1,\\ldots, d$. In a similar style, we define $X_1\\otimes X_2=X_1 X_2^{T}$.\n\\subsection{Moments of Mixture of Gaussians}\nGiven \\eqref{eq-mog-gen}, when $Z=i$ we can write and\n\\begin{align}\nX&=\\mu_i + Y \\\\\n\\nonumber\nY&\\sim \\mathcal{N}(0,\\sigma^2 I_{d})\n\\end{align}\nWe can compute the following raw moments up to order $3$\n\\begin{align}\n\\mathbb{E}[X]&=\\sum_{i=1}^k w_i \\mu_i\n\\end{align}\nWe will denote $M_1 = \\mathbb{E}[X]$ in the following.\n\\begin{align}\n\\mathbb{E}[X\\otimes X]&=\\sum_{i=1}^k w_i \\mathbb{E}[X\\otimes X|Z=i]\\\\\n&= \\sum_{i=1}^k w_i \\mathbb{E}[(\\mu_i + Y)\\otimes (\\mu_i + Y)]\\\\\n&=\\sum_{i=1}^k w_i \\mu_i\\otimes \\mu_i +  \\sigma^2 I_d\n\\end{align}\nNote we have used the fact that $\\mathbb{E}[Y]=0$, and $\\mathbb{E}[Y\\otimes Y]=\\sigma^2 I_d$. Plus the fact that $\\mathbb{E}[Y\\otimes Y\\otimes Y]=0$, we compute the $3$rd order moment\n\\begin{align}\n\\mathbb{E}[X\\otimes X \\otimes X]&=\\sum_{i=1}^k w_i \\mathbb{E}[X\\otimes X\\otimes X|Z=i]\\\\\n&= \\sum_{i=1}^k w_i \\mathbb{E}[(\\mu_i + Y)\\otimes (\\mu_i + Y)\\otimes (\\mu_i + Y)]\\\\\n&=\\sum_{i=1}^k w_i \\mu_i\\otimes \\mu_i\\otimes \\mu_i + \\\\\n\\nonumber\n& \\sum_{i=1}^k w_i\\left( \\mathbb{E}[\\mu_i\\otimes Y\\otimes Y] + \\mathbb{E}[ Y\\otimes\\mu_i\\otimes Y] + \\mathbb{E}[Y\\otimes Y\\otimes\\mu_i]\\right) \n\\end{align}\nNow let's take a closer look at the term\n\\begin{align*}\n\\sum_{i=1}^k w_i  \\mathbb{E}[ Y\\otimes\\mu_i\\otimes Y] &= \\mathbb{E}[ Y\\otimes(\\sum_{i=1}^k w_i\\mu_i)\\otimes Y]\\\\\n&= \\mathbb{E}[ Y\\otimes M_1\\otimes Y]\n\\end{align*}\nIn order to further simplify it, we look at a particular cell\n\\begin{align*}\n\\mathbb{E}[ (Y\\otimes M_1\\otimes Y)_{jlm}] &= (M_1)_l \\mathbb{E}[ Y_j Y_m]\\\\\n&= (M_1)_l \\sigma^2 \\delta_{jm}\n\\end{align*}\nwhere $\\delta_{jm}$ is the Kronecker delta. Thus, in tensor form we have\n\\begin{align}\n\\mathbb{E}[ Y\\otimes M_1\\otimes Y] &= \\sigma^2\\sum_{j=1}^d e_j \\otimes M_1 \\otimes e_j\n\\end{align}\nwhere $\\{e_1,\\ldots,e_d\\}$ is the canonical basis of $d$ dimension. Similarly we have\n\\begin{align}\n\\mathbb{E}[ M_1 \\otimes Y\\otimes Y] &= \\sigma^2\\sum_{j=1}^d  M_1 \\otimes e_j \\otimes e_j\\\\\n\\mathbb{E}[Y\\otimes Y\\otimes M_1] &= \\sigma^2\\sum_{j=1}^d   e_j \\otimes e_j \\otimes M_1\n\\end{align}\nThus, in summary we have\n\\begin{align}\n\\mathbb{E}[X\\otimes X \\otimes X]&=\\sum_{i=1}^k w_i \\mu_i\\otimes \\mu_i\\otimes \\mu_i +\\\\\n\\nonumber\n&\\sigma^2\\sum_{j=1}^d  (M_1 \\otimes e_j \\otimes e_j + e_j \\otimes M_1 \\otimes e_j + e_j \\otimes e_j \\otimes M_1)\n\\end{align}\n\\section{Parameter identification from the moments}\nFrom the data sample $\\{x_n\\}_{n=1}^N$, we can compute the empirical moments $\\widetilde{\\mathbb{E}}[X]$, $\\widetilde{\\mathbb{E}}[X\\otimes X]$, and $\\widetilde{\\mathbb{E}}[X\\otimes X \\otimes X]$ as estimates of the theoretical moments. For this reason, we say $\\mathbb{E}[X]$, $\\mathbb{E}[X\\otimes X]$, and $\\mathbb{E}[X\\otimes X \\otimes X]$ are observable. We want to come up with a recipe to identify the parameters $\\{w_i,\\mu_i\\}_{i=1}^k$ and $\\sigma^2$ from these observable moments.\n\\subsection{Identify $\\sigma^2$}\nLet's compute the covariance matrix of $X$\n\\begin{align}\ncov(X)&=\\mathbb{E}[(X-M_1)\\otimes (X-M_1)]\\\\\n&=\\sum_{i=1}^k w_i \\mathbb{E}[(X-M_1)\\otimes (X-M_1)|Z=i]\\\\\n&=\\sum_{i=1}^k w_i \\mathbb{E}[(\\mu_i-M_1+Y)\\otimes (\\mu_i-M_1+Y)]\\\\\n&=\\sum_{i=1}^k w_i (\\mu_i-M_1)\\otimes (\\mu_i-M_1) + \\sigma^2 I_d\n\\label{eq-cov-X}\n\\end{align}\nNote that because $\\sum_{i=1}^k w_i (\\mu_i-M_1)=0$, the $k$ vectors $(\\mu_i-M_1)$ for $i=1,\\ldots,k$ are linearly dependent. Thus, from \\eqref{eq-cov-X} we know $\\sigma^2=\\lambda_{\\min}(cov(X))$, i.e., $\\sigma^2$ is the smallest eigenvalue of $cov(X)$. Note because $cov(X)=\\mathbb{E}[X\\otimes X]-M_1\\otimes M_1$, $cov(X)$ is also observable.\n\\subsection{Identify $\\{w_i,\\mu_i\\}_{i=1}^k$}\nWe define the following two purified moments\n\\begin{align}\nM_2&=\\mathbb{E}[X\\otimes X] - \\sigma^2 I_d\n\\label{eq-M2-obs}\n\\\\\n&=\\sum_{i=1}^k w_i \\mu_i\\otimes \\mu_i\n\\label{eq-M2-tensor-decomp}\n\\end{align}\n\\begin{align}\nM_3&=\\mathbb{E}[X\\otimes X\\otimes X] - \\sigma^2\\sum_{j=1}^d  (M_1 \\otimes e_j \\otimes e_j + e_j \\otimes M_1 \\otimes e_j + e_j \\otimes e_j \\otimes M_1)\n\\label{eq-M3-obs}\n\\\\\n&=\\sum_{i=1}^k w_i \\mu_i\\otimes \\mu_i \\otimes \\mu_i\n\\label{eq-M3-tensor-decomp}\n\\end{align}\nOnce we have identified $\\sigma^2$, $M_2$ is observable thanks to equation \\eqref{eq-M2-obs}, and $M_3$ is observable thanks to equation \\eqref{eq-M3-obs}. In the \\textbf{Non-degeneracy Condition}, we only assume $\\mu_i,i=1,\\ldots,k$ to be linearly independent, which is not strong enough for us to extract $\\mu_i$ directly through the tensor decomposition in equation \\eqref{eq-M3-tensor-decomp}. We want to cook up another tensor that admits an \\textit{orthogonal tensor decomposition}, on which we can apply the \\textit{tensor power method}. From \\eqref{eq-M2-tensor-decomp}, we see that $M_2$ is a symmetric positive semidefinite matrix with rank $k$. Thus, it admits a thin eigendecomposition\n\\begin{align}\nM_2 &= U\\Lambda U^{T}\n\\label{eq-M2-thin-eigendecomp}\n\\end{align}\nwhere $U=(u_1,\\ldots,u_k)\\in R^{d\\times k}$, and $\\Lambda=diag(\\lambda_1,\\ldots,\\lambda_k)$ is a diagonal matrix with $\\lambda_i>0$ for $i=1,\\ldots, k$.\nNow let's define whitening matrix\n\\begin{align}\nB&=U\\Lambda^{-1/2}\n\\label{eq-whiten-matrix}\n\\end{align}\nand the following whitened vectors\n\\begin{align}\n\\widehat{\\mu_i}&=\\sqrt{w_i}B^{T}\\mu_i\n\\label{eq-whiten-vector}\n\\end{align}\nAlso note that because $\\mu_i\\in span(U)$, and $w_i>0$, we recover $\\mu_i$ by\n\\begin{align}\n\\mu_i&=\\frac{1}{\\sqrt{w_i}}(B^{T})^{\\dagger}\\widehat{\\mu_i}\n\\label{eq-whiten-vector-recover}\n\\end{align}\nwhere $B^{T})^{\\dagger}$ is the Moore-Penrose pseudoinverse on the right of $B^{T}$ such that $B^{T}(B^{T})^{\\dagger}=I_k$. From the definition of \\eqref{eq-whiten-matrix}, we have\n\\begin{align}\nI_k&=B^{T}M_2 B=M_2(B,B)\\\\\n&=\\sum_{i=1}^k w_i (B^{T}\\mu_i)\\otimes (B^{T}\\mu_i)\\\\\n&=\\sum_{i=1}^k (\\sqrt{w_i}B^{T}\\mu_i)\\otimes (\\sqrt{w_i}B^{T}\\mu_i)\\\\\n&=\\sum_{i=1}^k \\widehat{\\mu_i}\\otimes \\widehat{\\mu_i}\n\\end{align}\nThus, the vectors $\\widehat{\\mu_i},i=1,\\ldots,k$ are orthogonal. Now we apply the whitening to $M_3$ as follows:\n\\begin{align}\nM_3(B,B,B)&=\\sum_{i=1}^k w_i (B^{T}\\mu_i)\\otimes (B^{T}\\mu_i)\\\\\n&=\\sum_{i=1}^k \\frac{1}{\\sqrt{w_i}} \\widehat{\\mu_i}\\otimes \\widehat{\\mu_i}\\otimes \\widehat{\\mu_i}\n\\label{eq-M3-whiten-orth-tensor-decomp}\n\\end{align}\nThus, the whitened tensor $M_3(B,B,B)$ admits an orthogonal decomposition \\eqref{eq-M3-whiten-orth-tensor-decomp}, which is the merit we need in order to apply the tensor power method for identifying $\\widehat{\\mu_i}$, for $i=1,\\ldots,k$. We denote $M_3(B,B,B)=\\widehat{M_3}$. The tensor power method is given by the following iteration\n\\begin{align}\n\\theta_{t+1} & \\leftarrow \\frac{\\widehat{M_3}(:,\\theta_{t}, \\theta_{t})}{\\|\\widehat{M_3}(:,\\theta_{t}, \\theta_{t})\\|}\n\\label{eq-tensor-power-iter}\n\\end{align}\nstarting from an initial random vector $\\theta_0$ on the unit sphere $\\mathcal{S}^{k}$. It can be proved that $\\theta_t$ will converge to a certain eigenvector $\\widehat{\\mu_i}$ of $\\widehat{M_3}$. Once we have an estimate of $\\widehat{\\mu_i}$, we can identify $w_i$ by\n\\begin{align}\n\\frac{1}{\\sqrt{w_i}}&=\\widehat{M_3}(\\widehat{\\mu_i},\\widehat{\\mu_i},\\widehat{\\mu_i})\n\\label{eq-wi-estimate}\n\\end{align}\nNow we want to find another $\\widehat{\\mu_j}$ different from $\\widehat{\\mu_i}$. For this purpose, we need to \\textit{deflate} $\\widehat{\\mu_i}$ from $\\widehat{M_3}$. Let $\\mathcal{I}$ be the index set such that $i\\in \\mathcal{I}$ if and only if $(\\widehat{\\mu_i}, w_i)$ have been identified. The deflation is defined by\n\\begin{align}\n\\widehat{M_3} &\\leftarrow \\widehat{M_3} - \\sum_{i\\in \\mathcal{I}}\\frac{1}{\\sqrt{w_i}} \\widehat{\\mu_i}\\otimes \\widehat{\\mu_i} \\otimes \\widehat{\\mu_i}\n\\label{eq-deflation}\n\\end{align}\nPlease see~\\cite{AnandkumarG2014} for the details of orthogonal tensor decomposition and the tensor power method.\n\\subsection{Recipe}\nIn summary, our recipe using the method of moments are as follows:\n\\begin{enumerate}\n\\item Compute the empirical moments explicitly $\\widetilde{M_1}=\\widetilde{\\mathbb{E}}[X]$ and $\\widetilde{\\mathbb{E}}[X\\otimes X]$.\n\\item Identify $\\sigma^2$ by extracting the smallest eigenvalue of $\\widetilde{\\mathbb{E}}[X\\otimes X]-\\widetilde{M_1}\\otimes \\widetilde{M_1}$.\n\\item Form $M_2$ explicitly by \\eqref{eq-M2-obs}, and do the thin eigendecomposition \\eqref{eq-M2-thin-eigendecomp} to extract the whitening matrix $B$ in \\eqref{eq-whiten-matrix}.\n\\item Start with $\\mathcal{I}=\\emptyset$. For $i=1,\\ldots,k$, do the tensor power iteration \\eqref{eq-tensor-power-iter} using the deflated version \\eqref{eq-deflation} until converge (or maximum number of iterations met). We can estimate $w_i$ by \\eqref{eq-wi-estimate}. Let $\\mathcal{I}=\\mathcal{I}\\cup {i}$. \n\\par\nNote because in the tensor power iteration, only the action $\\widehat{M_3}(:,\\theta_{t}, \\theta_{t})$ is needed, we don't need to explicitly form $\\widehat{M_3}$. Instead, from \\eqref{eq-M3-obs}, we have\n\\begin{align}\n\\widehat{M_3}(:,\\theta_{t}, \\theta_{t}) &= \\mathbb{E}[B^{T}X (\\theta_t^{T}B^{T}X)^2] -\\\\\n\\nonumber\n& \\sigma^2\\sum_{j=1}^d  \\left(B^{T}M_1 (\\theta_t^{T}B^{T}e_j)^2  +  2 B^{T}e_j (\\theta_t^{T}B^{T}e_j)(\\theta_t^{T}B^{T}M_1) \\right)\n\\end{align}\n\\item Recover $\\mu_i$ from $\\widehat{\\mu_i}$ by \\eqref{eq-whiten-vector-recover}.\n\\end{enumerate}\n\\section{More general Gaussians}\n\\subsection{Differing $\\sigma_i^2$ for $i=1,\\ldots,k$}\nThe method presented above can be straightforwardly extended to the case where each mixture component has as different variance parameter $\\sigma_i^2$, with some tweaks to the form of the observed moments $M_2$ and $M_3$. Please see~\\cite{HsuK2013} for the details.\n\\subsection{General covariance matrices $\\Sigma_i$}\nIntuitively, when we have general covariance matrices $\\Sigma_i$ for $i=1,\\ldots,k$, we have many more parameters to estimate (each $\\Sigma_i$ have $\\frac{d(d+1)}{2}$ entries) than the case of spherical Gaussians. It turns out we need the $4$th and $6$th order moments in order to approximately recover $\\Sigma_i$ (with the assumption that $d=O(k^2)$). The algorithm is much more complicated and non-trivial to implement, please see~\\cite{GeHK2015} for the details.\n\n\\begin{thebibliography}{6}\n\n\\bibitem{AnandkumarG2014}A. Anandkumar and R. Ge and D. Hsu and S. M. Kakade and M. Telgarsky, Tensor decompositions for learning latent variable models. \\textit{Journal of Machine Learning Research}, Vol. 15, Issue 1, pp. 2773-2832, January 2014.\n\n\\bibitem{HsuK2013} D. Hsu and S. M. Kakade, Learning mixtures of spherical Gaussians: moment methods and spectral decompositions, \\textit{Proceedings of the fourth Innovations in Theoretical Computer Science}, pp. 11-20, January, 2013.\n\n\\bibitem{GeHK2015} R. Ge and Q. Huang and S. M. Kakade, Learning mixtures of Gaussians in high dimensions, \\textit{Proceedings of the forty-seventh annual ACM symposium on Theory of computing}, pp. 761-770, June, 2015.\n\n\\end{thebibliography}\n\\end{document}\n\n\\end{document}", "meta": {"hexsha": "68b082adf6f5e59490500348b99a29a7023e778b", "size": 12482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notebooks/gmm/mom/mom_gmm.tex", "max_stars_repo_name": "LBJ-Wade/mlcourse", "max_stars_repo_head_hexsha": "f5af0db001bf5e2fb153d381c10b35d34a491ebf", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 484, "max_stars_repo_stars_event_min_datetime": "2016-01-29T18:44:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T21:31:34.000Z", "max_issues_repo_path": "Notebooks/gmm/mom/mom_gmm.tex", "max_issues_repo_name": "LBJ-Wade/mlcourse", "max_issues_repo_head_hexsha": "f5af0db001bf5e2fb153d381c10b35d34a491ebf", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 76, "max_issues_repo_issues_event_min_datetime": "2016-12-25T19:14:21.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-20T19:52:59.000Z", "max_forks_repo_path": "Notebooks/gmm/mom/mom_gmm.tex", "max_forks_repo_name": "LBJ-Wade/mlcourse", "max_forks_repo_head_hexsha": "f5af0db001bf5e2fb153d381c10b35d34a491ebf", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 248, "max_forks_repo_forks_event_min_datetime": "2016-01-31T04:11:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T00:45:41.000Z", "avg_line_length": 64.3402061856, "max_line_length": 697, "alphanum_fraction": 0.7034129146, "num_tokens": 4678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6634074005745894}}
{"text": "%!TEX root = dsp_2nd_program_hw.tex\n\n\\subsection{Realization of DTMF using FFT --- dif\\_fft.h}\nThis part is explained in the previous report. \nThe code is shown in section~\\ref{code:fft}\n\nSee https://github.com/lzhbrian/Fast-Fourier-Transform for more information. \n\n\\subsection{Realization of DTMF using Goertzel --- goertzel.h}\nGoertzel algorithm is a method by which we can only calculate the amplitude of certain frequency.\nBy the following functions, We can obtain the $X[k]$ we want:\n\\begin{equation}\\label{equation:iter}\nv_{k}[n] = x[n] + 2cos(\\omega_{k})v_{k}[n-1]-v_{k}[n-2]\n\\end{equation}\n\\begin{equation}\\label{equation:xk_calc}\nX[k] = v_{k}[N-1] - W^{k}_{N}v_{k}[N-2]\n\\end{equation}\nwhere \n$$\\omega_{k} = 2\\pi k/N, W_{N}=e^{2\\pi /N}, v_{k}[-2]=v_{k}[-1]=0, v_{k}[0]=x[0]$$\n\nIn this DTMF detection, we want to acquire the amplitude of \n$$697Hz, 770Hz, 852Hz, 941Hz, 1209Hz, 1336Hz, 1477Hz, 1633Hz$$\nNote that we get the $k$ for each frequency by the following equation:\n\\begin{equation}\nk = ( N * f ) / SamplingRate;\n\\end{equation}\nwhere $N$ is the length of the sequence, and f is the targeted frequency.\n\nSo we first iteratively calculate the value of $v_{k}[N-1]$ and $v_{k}[N-2]$ using equation~(\\ref{equation:iter}), then we use them to get the value of X[k] by equation~(\\ref{equation:xk_calc}).\nIn the real practice, we further return the amplitude of X[k] by calculating their sum of squares.\n\nThe code is shown in section~\\ref{code:goertzel}", "meta": {"hexsha": "c84b4fbe10ddae51c333d52ce8eab273aa479514", "size": 1461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/algorithm.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/algorithm.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/algorithm.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": 45.65625, "max_line_length": 194, "alphanum_fraction": 0.7145790554, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.6634073998827191}}
{"text": "%SourceDoc ../YourName-Dissertation.tex\n% \\vspace*{-80mm}\n\\chapter{Background} \\label{chapter1:Background}\n\n\\section{\\sloppy Gaussian Processes}\n\nConsider a \\emph{spatial stochastic process}~\\cite{gelfand2010handbook} $\\{Y(\\bm{s}): \\bm{s} \\in \\mathcal{D} \\subseteq \\mathbb{R}^d\\}$ that varies over some continuous spatial domain $\\mathcal{D}$. We will focus on the most common case for spatial statistics, where the dimension is $d = 2$, although the methods presented here are valid for any $d$.  For a finite collection of spatial locations $\\{\\bm{s}_1, \\dots, \\bm{s}_n\\} \\subset \\mathcal{D}$, $\\bm{Y} = (Y(\\bm{s}_1), \\dots, Y(\\bm{s}_n))^T$ is a random vector where each element is associated with one location. The multivariate distribution of $\\bm{Y}$ contains information about the spatial dependencies between all $n$ locations.\n\nThe distribution of the process $\\{Y(\\bm{s})\\}$ may be described through its finite-dimensional joint distributions\n\\begin{equation} \\label{eq:joint}\nF(y_1, \\dots, y_n; \\bm{s}_1, \\dots, \\bm{s}_n) = P(Y(\\bm{s}_1) \\leq y_1, \\dots, Y(\\bm{s}_n) \\leq y_n)\n\\end{equation}\nfor every value of $n$ and every set of $n$ spatial locations in $\\mathcal{D}$. A \\emph{Gaussian process} is a special case in which every distribution in \\eqref{eq:joint} is multivariate normal~\\cite{gelfand2010handbook}. As a result, the distributions are all completely characterized by their means and covariance matrices, which makes Gaussian processes much easier to work with than non-Gaussian spatial stochastic processes.\n\n% section gaussian_processes (end)\n\n\\section{Stationarity and Isotropy} % (fold)\n\\label{sec:stationarity_and_isotropy}\n\nThroughout this work we will be making two key assumptions:  \\emph{stationarity} and \\emph{isotropy}. A stationary Gaussian process is one that does not vary with spatial shifts. That is, for any lag vector $\\bm{h} \\in \\mathbb{R}^d$,\n\\[\nE[Y(\\bm{s})] = E[Y(\\bm{s} + \\bm{h})] = \\bm{\\mu}\n\\]\nand\n\\[\n\\textrm{Cov}(Y(\\bm{s}), Y(\\bm{s} + \\bm{h})) = \\textrm{Cov}(Y(\\bm{0}), Y(\\bm{h})) = C(\\bm{h}).\n\\]\nHere $C(\\bm{h})$ is called the \\emph{covariance function}.\n\nFor isotropic Gaussian processes, the covariance function depends on $\\bm{h}$ only through its magnitude $||\\bm{h}||$. In this setting, we can express the covariance function simply as $C: [0, \\infty) \\to \\mathbb{R}$. If we assume without loss of generality that the process is standardized, we can further stipulate that $C(0) = 1$ and $E[Y(\\bm{s})] = 0$ for all $\\bm{s} \\in \\mathcal{D}$.\n\n% Define $\\mathcal{C}_d$ as the set of all continuous isotropic covariance functions in $d$ dimensions. Further define $\\mathcal{C}_\\infty = \\bigcap_{d=1}^\\infty \\mathcal{C}_d$ as the set of all functions that are valid isotropic covariance functions in \\emph{all} dimensions. It can be shown~\\cite{Stein1999}~\\cite{schoenberg1938metric} that\n% \\[\n% \t\\mathcal{C}_1 \\supseteq \\mathcal{C}_2 \\supseteq \\cdots \\supseteq \\mathcal{C}_\\infty\n% \\]\n% and that a function $C(h)$ is in $\\mathcal{C}_\\infty$ if and only if it can be written in the form\n% \\[\n% \tC(h) = \\int_0^\\infty \\exp(-h^2u^2) \\; dG(u)\n% \\]\n% for some $G$ bounded and non-decreasing on $[0, \\infty)$~\\cite{Stein1999}.\n\n% section stationarity_and_isotropy (end)\n\n\\section{Covariance Function Estimation} % (fold)\n\\label{sec:covariance_function_estimation}\n\nBecause Gaussian processes are completely characterized by their mean and covariance functions, estimating $C$ given a collection of observations $\\{y_1, \\dots, y_n\\}$ is a topic of great interest~\\cite{ver1993multivariable}~\\cite{banerjee2014hierarchical}. The problem of estimating $C$ differs from the general problem function estimation because only a restricted class of functions will produce a valid Gaussian process. In particular, $C$ must belong to the class of \\emph{positive definite functions}, which is defined as the set of all functions $C$ such that\n\\[\n  \\sum_{i=1}^n \\sum_{j=1}^n a_i a_j C(\\bm{s_i}\\bm{s}_j) > 0\n\\]\nfor any $n$, any $\\{\\bm{s}_1, \\dots, \\bm{s}_n\\} \\in \\mathcal{D}$, and any $a_1, \\ldots, a_n \\in \\mathbb{R}$. This condition guarantees that the joint distribution of any finite collection of observations $\\{Y(\\bm{s}_1), \\ldots, Y(\\bm{s}_n)\\}$ has a positive definite covariance matrix. This turns out to be a strong restriction, and it is very difficult in general to directly estimate $C$ in such a way that forces positive definiteness.\n\nThe classical approach to overcoming this difficulty is to select a parametric family of covariance functions that is known to be positive definite for a given range of the parameters, and to estimate the parameters using moment- or likelihood-based methods\\cite{gelfand2010handbook}. A popular choice of parametric families is the \\emph{Mat\\'{e}rn} class of functions~\\cite{handcock1994approach}, which take the form\n\\begin{equation} \\label{eq:matern}\nC(h) = \\frac{\\sigma^2}{2^{\\nu - 1}\\Gamma(\\nu)} \\left( \\frac{2\\nu^{1/2}h}{\\rho} \\right)^{\\nu} \\mathcal{K}_{\\nu} \\left( \\frac{2\\nu^{1/2}h}{\\rho} \\right), \\qquad \\sigma^2, \\nu, \\rho > 0,\n\\end{equation}\nwhere $\\mathcal{K}_\\nu$ is a modified Bessel function of the third kind. This is a three-parameter family, with $\\sigma$ controlling the marginal variance, $\\rho$ controlling the range of correlation, and $\\nu$ controlling the smoothness of the sample paths. All functions in this class are positive definite for observations in any dimension~\\cite{Stein1999}. Some examples of Mat\\'ern covariance functions are shown in Figure~\\ref{fig:matern_examples}.\n\n\n\\begin{figure}[!htb]\n\t\\centering\n\t\\includegraphics[width=0.95\\textwidth]{matern_examples.pdf}\n\t\\caption{\\small The Mat\\'ern isotropic covariance function \\eqref{eq:matern} for various choices of $\\nu$ and $\\rho$, each with $\\sigma^2 = 1$.}\n\t\\label{fig:matern_examples}\n\\end{figure}\n\n\nAnother positive definite family, which we will use in examples below, is the \\emph{exponentially damped cosine} class, \n\\begin{equation} \\label{eq:dampedcos}\n\tC(h) = \\sigma^2 \\exp \\left( -\\tau \\frac{h}{\\lambda} \\right) \\cos \\left( \\frac{h}{\\lambda} \\right), \\qquad \\tau \\geq \\frac{1}{\\tan \\frac{\\pi}{2d}}, \\quad \\sigma^2,\\lambda > 0.\n\\end{equation}\nUnlike the Mat\\'ern class, the damped cosine class allows for negative correlations at certain distances. This non-monotonic behavior is known in geostatistical applications as a \\emph{hole effect}~\\cite{Ye2015}, and is shown in Figure~\\ref{fig:dampedcos_examples}. The restriction on $\\tau$ that depends on $d$ is necessary for functions of this form to be positive definite. %Note, however, that $\\tan(\\pi/2d) \\to 0$ as $d \\to \\infty$, so this set of functions is not a member of $\\mathcal{C}_\\infty$. \nThe damped cosine family is not nearly as commonly used as the Mat\\'ern family, but it is useful in some applications because allows for stochastically periodic behavior as well as negative correlations, which a Mat\\'ern family cannot capture. However, it does not share the attractive feature of the Mat\\'ern family that the smoothness of the process (i.e. the degree of differentiability) is controlled by a parameter that can be estimated from the data. The smoothness is closely related to the local behavior of the process, which crucial to obtaining good performance when interpolating the process at unobserved locations~\\cite{Stein1999}.\n\n\\begin{figure}[!htb]\n\t\\centering\n\t\\includegraphics[width=0.95\\textwidth]{dampedcos_examples.eps}\n\t\\caption{\\small The damped cosine isotropic covariance function \\eqref{eq:dampedcos} for $\\tau = 1$, $\\lambda = 1$, and $\\sigma^2=1$. Notice that $C(h) < 0$ for certain values of $h$.}\n\t\\label{fig:dampedcos_examples}\n\\end{figure}\n\nThe strategy of fitting the data to a parametric family of covariance functions can produce a good estimate if the true covariance structure is close to the structure assumed by the choice of parametric family. However, there is no guarantee that this will be the case. For instance, if the true covariance contains a hole effect, there is no way for a Mat\\'ern model to capture it since $C(h) > 0$ for all $h$. More preferable would be a flexible method that allows the spatial dependence in the data itself, rather than the choice of parametric family, to determine the shape of $C$.\n\n% subsection estimating_the_covariance_function (end)\n\n\\section{The Spectral Domain and Bochner's Theorem} % (fold)\n\\label{sec:bochner_s_theorem}\n\nThe method proposed in this work takes advantage of the result from Bochner~\\cite{bochner1955harmonic} which says that a real-valued continuous function $C$ is positive definite if and only if it is the Fourier transform of a symmetric, non-negative, finite measure $F$ on $\\mathbb{R}^d$. That is, $C$ is positive definite if and only if\n\\begin{equation} \\label{eq:bochner}\nC(\\bm{h}) = \\int_{\\mathbb{R}^d} \\exp(i \\bm{h}^T \\bm{\\omega}) \\; dF(\\bm{\\omega}),\n\\end{equation}\nIn most circumstances, the measure $F$ has a Lebesgue density, $f(\\bm{\\omega})$, which is referred to as the \\emph{spectral density}~\\cite{gelfand2010handbook}.  Furthermore, because we are assuming that the Gaussian process described by $C$ is isotropic, $C$ is a function of a scalar $h$, so that\n\\begin{equation} \\label{eq:bochner2}\nC(h) = \\int_{\\mathbb{R}} \\cos(h\\omega) \\; f(\\omega) \\; d\\omega.\n\\end{equation}\nStein~\\cite{Stein1999} argues that for Gaussian process covariance functions to be realistic models for spatial phenomena, spectral densities $f(\\omega)$ must be heavy tailed.\n\nThe relationship between the covariance function and the spectral density given in \\eqref{eq:bochner2} suggests us an alternative way to estimate the covariance function $C(h)$. If we can estimate the the symmetric spectral density $f(\\omega)$, then we are assured that the corresponding covariance function $C(h)$ is positive definite.  Flexibly modeling $C(h)$ directly is difficult because of the restriction of positive definiteness, but flexibly modeling $f(\\omega) $ is easy because it can be any symmetric density.\n\nThere have been previous approaches for non- and semi-parametric methods that estimate $C(h)$ using the spectral domain. Most closely related to our approach is that of Im, Stein, and Zhu~\\cite{IM2007}, who estimate the spectral density using a combination of cubic B-splines with an explicitly specified algebraically decaying tail.   Constraints are placed on the spline coefficients to ensure that the spectral density is non-negative, thereby resulting in a covariance function is positive definite.  Im, Stein, and Zhu use the fact that when under isotropy, \\eqref{eq:bochner} can be written as an integral over only one dimension,\n\\[\n\tC(h) = 2^{(d-2)/2}\\Gamma(d/2) \\int_0^\\infty (hu)^{-(d-2)/2} J_{(d-2)/2}(hu) \\; dG(u),\n\\]\nwhere $J_\\nu(\\cdot)$ is the Bessel function of the first kind of order $\\nu$. The spline-based spectral density is transformed into a covariance function using numerical integration, which is then used to construct the likelihood of the spline coefficients given the data.  This likelihood is be maximized over the constrained set of spline coefficients to produce $d\\hat{G}(u)$, and hence $\\hat{C}(h)$.  Our method follows this same concept, with some notable differences outlined in Chapter~\\ref{chapter2:Procedure}.\n\nAnother, earlier method was put forth by Hall, Fisher and Hoffmann~\\cite{Hall1994}. They proposed a multistep process which begins with a kernel estimate of the covariogram. Because the kernel estimate is not necessarily positive definite, they numerically compute its Fourier transform, set all frequencies beyond the first negative value to zero, and then numerically Fourier transform it back to the spatial domain. In the simulation study in Chapter~\\ref{chapter3:Simulation-Study}, we compare our method to the one from Hall et al., as well as to the Mat\\'ern model fit by maximum likelihood.\n\nIn Chapter~\\ref{chapter4:Data-Application}, we apply our method to data from a paper by Singh et al. \\cite{Singh2014}, where we model the thickness of a thin film semiconductor in a photovoltaic cell as a Gaussian process. The results are discussed in Chapter~\\ref{chapter5:Conclusions}, as well as possibilities for improvements and future directions for this work.\n\n% section bochner_s_theorem (end)\n", "meta": {"hexsha": "c76061421f119af0b7e6e448edad087dcc753d38", "size": 12177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Chapter-1/Chapter-1.tex", "max_stars_repo_name": "ensley/thesis", "max_stars_repo_head_hexsha": "fc8af97cdb1ed43e6a996a9eed5f1f195199669c", "max_stars_repo_licenses": ["MIT"], "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/Chapter-1/Chapter-1.tex", "max_issues_repo_name": "ensley/thesis", "max_issues_repo_head_hexsha": "fc8af97cdb1ed43e6a996a9eed5f1f195199669c", "max_issues_repo_licenses": ["MIT"], "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/Chapter-1/Chapter-1.tex", "max_forks_repo_name": "ensley/thesis", "max_forks_repo_head_hexsha": "fc8af97cdb1ed43e6a996a9eed5f1f195199669c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 108.7232142857, "max_line_length": 688, "alphanum_fraction": 0.7519914593, "num_tokens": 3389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8311430478583169, "lm_q1q2_score": 0.6634073912107178}}
{"text": "\\section{Language models}\n\n\\paragraph{Language model}\nA language model is the probability distribution\nof a sequence of words, it can be used for all sort \nof applications.\n$$p(w_1, w_2, \\dots, w_n)$$\n\n\\paragraph{Examples}\nThis probability could be used to predict the next word \ngiven a sequence\n$$p(w_n | w_1, w_2, \\dots, w_{n-1})$$\nAnother usage is to predict a feature given the sequence, \nfor instance find the author from the text \n$$p(\\mathit{author} | w_1, w_2, \\dots, w_n)$$\n\n\\paragraph{Bases and evaluation}\nThe goal of language modeling is to build a computational model of the \nlanguage of an entity $X$, that can be any entity in a domain.\n\nLanguage models are entirely \\emph{data-driven}. In other terms, \nwe need to train models on the right data. One of the disadvantages of \nthis fact is that instead of modeling the language of $X$, we are modelling\nthe language of the \\emph{documents about X}.\n\n\\subsection{N-grams models}\nThe easier way to estimate a sequence probability is to count \nfrequencies, but that could be unfeasible. We discussed a similar approach \nin Section \\vref{problangmodel} in \\emph{Computing a sentence probability}.\n\n\\paragraph{Unigram models}\nA first approach is to use word frequencies, \nthe idea is to find the relative frequency of a word, by simply counting \nit in the corpus and use it to estimate\nthe probability of a sequence.\n$$p(w_n, w_{n-1}\\dots, w_1) = p(w_n)p(w_{n-1})\\dots p(w_1)$$\nNote that this approach does not take into consideration the sequence in \nany way, this is a \\emph{Unigram model} .\n\nThese models might be useful to compare two documents, where we \nneed to compare the probability of seeing a given word, \nor to find how much relevant is a given word for a document. \nWe can do that by comparing the word probability in all the dataset and in the\nsingle document.\n\n\\paragraph{Pointwise Mutual Information}\n$$\\mathit{pmi}(a,b) = \\log\\frac{p(a,b)}{p(a)p(b)} = \\log \\frac{p(a | b)}{p(a)} = \\log\\frac{p(b|a)}{p(b)}$$\nWe can set the two variables to the event of extracting the document $C$ from \nthe corpus and the probability $w$ of extracting a given word. \n$$\\mathit{pmi}(w, C) = \\log\\frac{p(w, C)}{p(w)p(C)}$$\nBy computing the \\emph{pmi} for the same word and two different documents, \nwe can compare the difference of relevance of a word for the two \ndocuments.\n\n\\paragraph{Chain rule}\nWe now want to consider the sequence instead of taking words independently \nas in the unigram model.\n$$p(w_k | w_1, \\dots, w_{k-1}) = \n\\frac{\\mathit{count}(w_1, \\dots, w_{k-1}, w_k)}{\\sum_w \\mathit{count}(w_1, \\dots, w_{k-1}, w)}$$ \nBasically to compute the probability of finding a given word \nafter a sequence, we count how many times we observe the sequence with\nthat word, over the count of all other words after the sequence.\n\nIn practice, we can reduce a long sequence to a shorter one, for instance\nof two or three words, to potentially have enough data to estimate the probability.\n\n\\subsection{Evaluation}\n\nThere are basically two ways of evaluating a language model:\n\\begin{itemize}\n    \\item \\emph{Extrinsic evaluation} : embed the system in a real applications\n    and measure improvement\n    \\item \\emph{intrinsic evaluation} : define a metric and evaluate the \n    model independent from any application, this requires a training set and \n    a testing set, where the second must be different but consistent \n    with the language learned by the model\n\\end{itemize}\n\n\n\\paragraph{Perplexity}\nIn the case of intrinsic evaluation, the main idea\n is to check if the model fits the test data. \nThis measure is called perplexity.\n$$\\mathit{pp}(T) = p(w_1, \\dots, w_n)^{-\\frac{1}{n}}$$\nFor a two-gram model the measure becomes:\n$$\\mathit{pp}(T)= \\sqrt[n]{\\prod_{i=1}^n \\frac{1}{p(w_i\\;|\\;w_{i-1})}}$$\n\n\\paragraph{Generalization and zero probabilities}\nLanguage models have an issue when a word is present in the test set \nbut not in the training set, this becomes unknown with no null probability.\n\nTo fix this we apply smoothing, for instance \\emph{Laplace smoothing}, i.e. \nadding one to each word count, or a parameter k.\n\n\\paragraph{Backoff and interpolation}\nAnother way to deal with null probabilities \nis to apply \\emph{backoff and interpolation}. Basically to estimate \na $n$-gram frequency, if we do not have enough evidence, we use the $(n-1)$-gram \nfrequency, until we have just a unigram.\nAn example can be:\n$$p(\\mathit{New\\;York\\;City}) = p(\\mathit{City}\\;|\\;\\mathit{York})\\;p(\\mathit{York}\\;|\\;\\mathit{New}) $$\n\n\\emph{Interpolation} means computing a weighted sum over an $n$-gram levels, \nthis way, even if we only observe the last word of a $n$-gram, we do not \nhave zero probability.\n\n\\subsection{Word-Context models}\nThe problem of data sparsity is mitigated by the n-gram models, but not \nsolved completely.\n\n\\paragraph{Skip-gram model}\nThe main of the model is to fix the cases where two sentences\nare really similar, i.e. they give the same information, but they do \nnot have any common n-gram.\n\nWe introduce the concept of \\emph{word context}, \nbasically we take a n-gram by skipping at most $k$ words, \nthis leads to skip noisy terms.\nBy doing so, we could potentially match two sentences \nthat differs for a few words but that do not share commons \ngrams.\n\n\\paragraph{Continuous Bag of Words}\nThe idea of this model is to take the context of a word, \nfor instance a collection of 2-grams, and predict a word.\n\n\\paragraph{Word context matrix}\nWe can think of a word context matrix, where we \nstore information about appearance of a word $w$ \nwithin $t$ other words.\n\nTaking into account the word order depends on the focus of\nthe model, in language the order is important, in semantics\nit is less relevant.\n\nThe context matrix stores in $c_{i, j}$ for each word $w_i$\nhow many times the word $w_j$ occurs in its context. \nIf we consider the row of that matrix as a vector, two words \nare close in that space if they have a similar context.\n\nAfter computing the matrix, we can factorize it with singular value \ndecomposition to obtain a more compact representation.\nA problem is that such a factorization has many zero terms, to \nfix it we can \\emph{weighted matrix factorization}.\n\n\\subsection{Word embeddings}\n\n\\paragraph{Words as vectors}\nRepresenting words as vectors, as we did with models previously, \nis a very efficient way to compute words similarity and \nrepresent documents as regions in the vector space.\nAn example of word as vectors can be found in the context matrix.\n\nThe goal is to obtain \\emph{dense word vectors}, so with small dimensionality \nand with the absence of sparsity.\n\n\\paragraph{Distributional hypothesis}\nIn a real world scenario a word has a meaning, which is related \nto the object, or the concept it represent, in our case there is \nno such thing, so we must find a way to deal with this.\n\nWe can assume that words that appear in the same \ncontext have the same meaning.\n\n\\subsubsection{Neural network models}\n\nA first example of using a neural network is \nto take as input an $n$-gram of a word $w$ and\nas output the probability distribution over the next word.\n\nWe saw this concept in the previous section when talking about \n\\emph{Continuous Bag of Words}.\n\nBasically what the network is doing is to compute \nthis function\n$$f(w_t, \\dots, w_{t-n+1}) = P(w_t \\; | \\; w_1, \\dots, w_{t-1})$$\n\n\\paragraph{Decomposition}\nThe idea used by the model is to decompose the function in \ntwo parts:\n\\begin{itemize}\n    \\item A mapping from any word $w_i \\in V$ to a vector $w_i \\in \\mathbb{R}^m$ dimensions,\n    this creates a matrix $W \\in \\mathbb{R}^{V \\times m}$, where $V$ is the number of words\n    \\item A probability function over words, that takes in input \n    a sequence of vectors of $d$ dimensions, obtained via the previous\n    mapping, and produces a vector $g$ in the original $V$ space.\n\\end{itemize}\n\n\\paragraph{Why is this relevant for word embeddings?}\nThe mapping to a $d$ dimensional space could be the word \nembedding we want to obtain, we are not interested \nin the network output.\n\nWe are assuming that the embedding made by the network \ncorrespond to the real meaning of the word, as such a \nmapping is obtained minimizing the objective function. \n\nIn other words, if the network is able to perform well, that should \nbe a good embedding.\n\n\\paragraph{Word2vec}\nThe idea is to train the neural network with positive couples of \nwords and negative ones, with the hope the network will learn \nto output good words sequences.\n\nThe structure of the network in this implementation \nhas an input and output layer of dimensions $V \\times V$, \nand a middle layer of $V \\times m$, initialized with random values.\n\nAfter training we discard the output layer and keep the \nmiddle one, as discussed in the previous section.\nThe main principle is that similar vectors in the hidden \nlayer corresponds to words with similar context. \n\nThis is due to the fact that two words with the same context\nshould have similar consequent predictions, thus, the weights in \nthe middle layer for this two words must be close, as the \nprediction made by the network must be more o less the same for \nthe twos.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{images/nn-words.png}\n    \\caption{Word2vec implementation of Neural Network embedding}\n\\end{figure}\n\n\\subsubsection{Using embeddings}\n\n\\paragraph{Adding information}\nWe can use the word embeddings obtained in some way to improve \nretrieval, for instance by applying query expansion.\n\n\\paragraph{Similarity}\nWe can also compute similarity among group of words, \nas we have a vector space where for instance cosine similarity is \napplicable.", "meta": {"hexsha": "82d44d595df96abaa22fd4df9dca4aa18aef5814", "size": 9633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-courses/information-retrieval/chapters/language_model.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/language_model.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/language_model.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": 40.8177966102, "max_line_length": 106, "alphanum_fraction": 0.754905014, "num_tokens": 2476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.6634073885641038}}
{"text": "\n\\section{Conclusion}\n\nThis article illustrated the verification method equational reasoning by example. We proved that the monoid law known as left identity holds for a given function definition. \n\nThe type class laws provide a specification for the verification process. In addition, we can rely on properties of existing type class instances to prove further properties.\n\nType classes allow us to generalize definitions. A proof for the generalization is valid for all specializations. Hence, the proof is reusable.\n\nThe examination of the topic improved my comprehension for the advantages of a purely functional language. The reason why verification in a purely functional language like Haskell is easier then in imperative language is because functions are just equalities. We can reason about Haskell code in the same way we reason about mathematical equations. The definitions are stateless. This fact does not apply to mainstream languages. A function definition of an imperative language is allowed to change the context. These definitions are stateful.\n\nPersonally, I found the process of proving the left identity law for the given definition tedious and difficult. The proof requires creativity and a strong mathematical background. The verification process would be too cumbersome and expensive to apply it to every piece of software. Although equational reasoning  is not suitable for software with a short life cycle, I think it is important to know the difference between testing and verification by proof.\n", "meta": {"hexsha": "83f5ffcb09920702bd1bf3ea5121afd1dfd4fa1b", "size": 1524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "conclusion.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": "conclusion.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": "conclusion.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": 117.2307692308, "max_line_length": 543, "alphanum_fraction": 0.8267716535, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6634073872206521}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%% Shortest Paths %%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Shortest Paths}\n\n\\begin{frame}\n  \\frametitle{Shortest paths}\n\n  \\textcolor{purple}{Different editions of shortest paths problems:}\n  \\begin{enumerate}\n    \\item shortest(longest) path in DAG  \\\\\n      \\emph{\\textcolor{blue}{Dynamic Programming}}\n    \\item single-source shortest paths\n      \\begin{itemize}\n        \\item No negative edges. \\\\\n          \\emph{\\textcolor{blue}{Dijkstra algorithm.}}\n        \\item With negative edges (No negative cycle). \\\\\n          \\emph{\\textcolor{gray}{Bellman-Ford algorithm.}}\n      \\end{itemize}\n    \\item all pairs shortest paths \\\\\n      \\emph{\\textcolor{blue}{Floyd-Warshall algorithm.}}\n  \\end{enumerate}\n\n\\end{frame}\n\n%\\begin{frame}\n%  \\frametitle{Shortest paths}\n%\n%  \\textcolor{purple}{To better understand these problems and algorithms:}\n%  \\vspace{0.40cm}\n%\n%  \\begin{enumerate}\n%    \\setlength{\\itemsep}{0.30cm}\n%    \\item Why the algorithm works for this problem ?\n%    \\item Does the algorithm also work for another problem ?\n%  \\end{enumerate}\n%\n%\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Shortest paths}\n\n  \\textcolor{purple}{DAG can be topologically sorted, so \\emph{DP} works.}\n\n  \\begin{figure}\n    \\begin{center}\n      \\includegraphics[scale=0.30]{figure/bfs_dfs/daglinear}\n      \\caption{{\\scriptsize A dag and its topological sorting.}}\n      \\label{fig:daglinear}\n    \\end{center}\n  \\end{figure}\n\n  \\[\n    dist(D) = \\min \\lbrace dist(B)+1, dist(C)+3 \\rbrace.\n  \\]\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Shortest paths}\n\n  \\textcolor{purple}{Shortest path without negative edges : \\emph{Dijkstra algorithm}}\n\n  \\begin{figure}\n    \\begin{center}\n      \\includegraphics[scale=0.40]{figure/bfs_dfs/dijkstra}\n      \\caption{{\\scriptsize Property of shortest paths.}}\n      \\label{fig:dijkstra}\n    \\end{center}\n  \\end{figure}\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Priority queue implementations}\n\n  \\textcolor{purple}{Complexity of Dijkstra algorithm:}\n  \\begin{enumerate}\n    \\item makequeue, $\\lvert V \\rvert \\cdot insert$\n    \\item $\\lvert V \\rvert \\cdot deletemin$\n    \\item $\\lvert E \\rvert \\cdot descreaseKey$\n  \\end{enumerate}\n\n  \\pause\n  \\vspace{0.50cm}\n\n  \\textcolor{purple}{Different implementations of priority queue:}\n\n  {\\scriptsize\n\n    \\begin{tabular}{|c||c|c|c|}\n      \\hline\n      Implementation     & deletemin        & insert, decreaseKey       & total                 \\\\ \\hline \\hline\n      Array              & $O(V)$           & $O(1)$                    & $O(V^2)$              \\\\ \\hline\n      Binary heap        & $O(\\log{V})$     & $O(\\log{V})$              & $O((V+E) \\log {V})$   \\\\ \\hline\n      Fibonacci heap     & $O(\\log{V})$     & $O(1)$                    & O$(V \\log {V} + E)$   \\\\\n      \\hline\n    \\end{tabular}\n  }\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Shortest path with negative edges: \\emph{Bellman-Ford algorithm}}\n\n  \\begin{figure}\n    \\begin{center}\n      \\includegraphics[scale=0.40]{figure/bfs_dfs/dijkstranegative}\n      \\caption{{\\scriptsize Dijkstra algorithm fails if there are negative edges ([\\textcolor{blue}{$P_{418}$ 8.14}]).}}\n      \\label{fig:dijkstranegative}\n    \\end{center}\n  \\end{figure}\n\n\\end{frame}\n\n\n\n\\begin{frame}\n  \\frametitle{All pairs of shortest paths: \\emph{Floyd-Warshall algorithm}}\n\n  \\begin{figure}\n    \\begin{center}\n      \\includegraphics[scale=0.40]{figure/bfs_dfs/warshall}\n      \\label{fig:warshall}\n    \\end{center}\n  \\end{figure}\n\n  \\pause\n  \\vspace{0.40cm}\n  \\textcolor{red}{Assumption: No negative cycles.}\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{All pairs of shortest paths: \\emph{Floyd-Warshall algorithm}}\n\n  \\begin{itemize}\n    \\item Routing table for all-pair shortest path ([\\textcolor{blue}{$P_{448}$ 9.10}]).\n    \\item Length of shortest cycle in digraph ([\\textcolor{blue}{$P_{448}$ 9.12}]).\n  \\end{itemize}\n\n\\end{frame}\n\n\n\n\\begin{frame}\n  \\frametitle{All pairs of shortest paths: \\emph{Floyd-Warshall algorithm}}\n\n  \\begin{itemize}\n    \\item Routing table for all-pair shortest path ([\\textcolor{blue}{$P_{448}$ 9.10}]).\n    \\vspace{0.50cm}\n\n      \\begin{figure}\n        \\begin{center}\n          \\includegraphics[scale=0.35]{figure/shortest_paths/route0}\n          \\caption{{\\scriptsize Construction of routing table.}}\n          \\label{fig:route0}\n        \\end{center}\n      \\end{figure}\n    \\end{itemize}\n\n\\end{frame}\n\n\n\n\\begin{frame}\n  \\frametitle{All pairs of shortest paths: \\emph{Floyd-Warshall algorithm}}\n\n  \\begin{itemize}\n    \\item Length of shortest cycle in digraph ([\\textcolor{blue}{$P_{448}$ 9.12}]).\n    \\[\n      path \\lbrack i \\rbrack \\lbrack i \\rbrack\n    \\]\n    \\[\n      path \\lbrack i \\rbrack \\lbrack i \\rbrack < 0 ?\n    \\]\n    \\textcolor{red}{Fail for undirected graph:}\n    \\[\n      \\lbrace v, w \\rbrace \\to (v,w,v).\n    \\]\n  \\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\begin{figure}\n    \\begin{center}\n      \\includegraphics[scale=0.60]{figure/thank}\n      \\label{fig:thank}\n    \\end{center}\n  \\end{figure}\n\\end{frame} ", "meta": {"hexsha": "cdfa55345e073a5eac2b37f22bd8b9a1ba9a13b6", "size": 4986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2011/algorithm-tutorial-bfs-dfs-mst-sssp-dp-20111218/shortest_paths.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-2011/algorithm-tutorial-bfs-dfs-mst-sssp-dp-20111218/shortest_paths.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-2011/algorithm-tutorial-bfs-dfs-mst-sssp-dp-20111218/shortest_paths.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.3096446701, "max_line_length": 120, "alphanum_fraction": 0.6221419976, "num_tokens": 1553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6634073838821676}}
{"text": "\nThe \\eslmod{stats} module is the foundation of a set of statistics\nmodules. It contains special functions like $\\Gamma(x)$ and $\\Psi(x)$,\nand elementary statistics routines such as linear regression fitting\nand $\\chi^2$ testing. Table~\\ref{tbl:stats_api} lists the functions in\nthe \\eslmod{stats} API.\n\n\\begin{table}[hbp]\n\\begin{center}\n{\\small\n\\begin{tabular}{|ll|}\\hline\n\\hyperlink{func:esl_stats_DMean()}{\\ccode{esl\\_stats\\_\\{D,F,I\\}Mean()}} & Calculates mean and $\\sigma^2$ for samples $x_i$.\\\\\n\\hyperlink{func:esl_stats_LogGamma()}{\\ccode{esl\\_stats\\_LogGamma()}} & Calculates $\\log \\Gamma(x)$.\\\\\n\\hyperlink{func:esl_stats_Psi()}{\\ccode{esl\\_stats\\_Psi()}} & Calculates $\\Psi(x)$ (the digamma function).\\\\\n\\hyperlink{func:esl_stats_IncompleteGamma()}{\\ccode{esl\\_stats\\_IncompleteGamma()}} & Calculates the incomplete Gamma function.\n\\\\\n\\hyperlink{func:esl_stats_ChiSquaredTest()}{\\ccode{esl\\_stats\\_ChiSquaredTest()}} & Calculates a $\\chi^2$ P-value.\\\\\n\\hyperlink{func:esl_stats_LinearRegression()}{\\ccode{esl\\_stats\\_LinearRegression()}} & Fit data to a straight line.\\\\\n\\hline\n\\end{tabular}\n}\n\\end{center}\n\\caption{The \\eslmod{stats} API.}\n\\label{tbl:stats_api}\n\\end{table}\n\n\\subsection{An example of using the stats API}\n\n\nFigure~\\ref{fig:stats_example} shows an example of using one of the\nroutines in the \\eslmod{stats} module, linear regression fitting. It\ngenerates a set of $n$ points dispersed around a line, $y_i = a + bx +\nN(\\sigma)$ with Gaussian noise $N(\\sigma)$, then fits the data to a\nline to obtain estimates $\\hat{a}$ and $\\hat{b}$.\n\n\\begin{figure}\n\\input{cexcerpts/stats_example}\n\\caption{An example of using the \\eslmod{stats} module.}\n\\label{fig:stats_example}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "b027d992e244cb6da66f66eeaad221f1e0ec2f65", "size": 1706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hmmer-3.3/easel/esl_stats.tex", "max_stars_repo_name": "WooMichael/Project_Mendel", "max_stars_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hmmer-3.3/easel/esl_stats.tex", "max_issues_repo_name": "WooMichael/Project_Mendel", "max_issues_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hmmer-3.3/easel/esl_stats.tex", "max_forks_repo_name": "WooMichael/Project_Mendel", "max_forks_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7727272727, "max_line_length": 127, "alphanum_fraction": 0.7362250879, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757313, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6634073818871348}}
{"text": "\\chapter[Markov Chains]{Markov Chains}\\label{chp:markov_chains}\n\n% Introduction\n\\chapterinitial{M}{any} real world situations have some level of\nunpredictability through randomness: the flip of a coin, the number of orders of\ncoffee in a shop, the winning numbers of the lottery. However, mathematics can\nin fact let us make predictions about what can be expected to happen. One tool\nused to understand randomness is Markov chains, an area of mathematics sitting\nat the intersection of probability and linear algebra.\n\n\\section{Problem}\\label{sec:markov_chains_problem}\n\nConsider a barber shop. The shop owners have noticed that customers will not\nwait if there is no room in their waiting room and will choose to take their\nbusiness elsewhere. The barber shop would like to make an investment so as to\navoid this situation. They know the following information:\n\n\\begin{itemize}\n    \\item They currently have 2 barber chairs (and 2 barbers);\n    \\item they have waiting room for 4 people;\n    \\item they usually have 10 customers arrive per hour;\n    \\item each barber takes about 15 minutes to serve a customer so they can\n        serve 4 customers an hour.\n\\end{itemize}\n\nThis is represented diagrammatically in Figure~\\ref{fig:barber-shop}.\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n    \\includestandalone[width=.75\\textwidth]{./assets/barber-shop/main}\n    \\end{center}\n    \\caption{Diagrammatic representation of the barber shop as a queuing system.}\n    \\label{fig:barber-shop}\n\\end{figure}\n\n\nThey are planning on\nreconfiguring space to either have 2 extra waiting chairs or\nanother barber's chair and barber.\n\nThe mathematical tool used here to model this situation is a Markov\nchain\\index{Markov chain}.\n\n\\section{Theory}\\label{sec:markov_chains_theory}\n\nA Markov chain is a model of a sequence of random events\\index{random events}\nthat is defined by a collection of \\textbf{states} and rules that define how to\nmove between these states.\n\nFor example, in the barber shop a single number is sufficient to describe the\nstatus of the shop: the number of customers present.\nIf that number is 1 this implies that 1 customer is\ncurrently having their hair cut. If that number is 5 this implies that 2\ncustomers are being served and 3 are waiting. The entire set of values that this\nvalue can take is a finite set of integers from 0 to 6, this set, in general, is\ncalled the \\textit{state space}.\nIf the system is full (all barbers and waiting room occupied) then the Markov\nchain is in state 6 and if there is no one at the\nshop then it is in state 0. This is denoted mathematically as:\n\n\\begin{equation}\n    S = \\{0, 1, 2, 3, 4, 5, 6\\}\n    \\label{eqn:barber_shop_state_space}\n\\end{equation}\n\nThe state increases when people arrive and this happens at a rate of change of\n10 per unit time. The state decrease when people are served and this happens at\na rate of 4 per active server per unit time. In both cases it is assumed that no\n2 events can occur at the same time.\n\nIn general, the rules that govern how to move between these states can be\ndefined in 2 ways:\n\n\\begin{itemize}\n    \\item Using probabilities\\index{probability} of changing state (or not) in a\n          well defined time interval. This is called a discrete time Markov\n          chain\\index{discrete time Markov chain}.\n    \\item Using rates of change\\index{rate of change} from one state to another.\n          This is called a continuous time Markov chain\\index{continuous time Markov chain}.\n\\end{itemize}\n\nThe barber shop will be considered as a continuous time Markov chain as shown\nin Figure~\\ref{fig:barber-shop-continuous-markov-process}\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n    \\includestandalone[width=.6\\textwidth]{./assets/barber-shop-continuous-markov-process/main}\n    \\end{center}\n    \\caption{Diagrammatic representation of the state space and the transition\n    rates}\n    \\label{fig:barber-shop-continuous-markov-process}\n\\end{figure}\n\nNote that a Markov chain assumes the rates follow an exponential\ndistribution\\index{exponential distribution}.\nOne interesting property of this distribution is that it is considered\nmemoryless which means the probability of a customer finishing service\nwithin the next 5 minutes does not change if they have been\nhaving their hair cut for 3 minutes already.\n\nThese states and rates can be represented mathematically using a transition\nmatrix\\index{transition matrix}\\index{matrix} \\(Q\\) where \\(Q_{ij}\\) represents the rate\nof going from state \\(i\\) to\nstate \\(j\\). In this case:\n\n\\begin{equation}\nQ =\n\\begin{pmatrix}\n-10 &  10 &   0 &   0 &   0 &   0 &   0\\\\\n  4 & -14 &  10 &   0 &   0 &   0 &   0\\\\\n  0 &   8 & -18 &  10 &   0 &   0 &   0\\\\\n  0 &   0 &   8 & -18 &  10 &   0 &   0\\\\\n  0 &   0 &   0 &   8 & -18 &  10 &   0\\\\\n  0 &   0 &   0 &   0 &   8 & -18 &  10\\\\\n  0 &   0 &   0 &   0 &   0 &   8 &  -8\\\\\n \\end{pmatrix}\n \\label{eqn:barber_shop_transition_matrix}\n\\end{equation}\n\nYou will see that \\(Q_{ii}\\) are negative and ensure the rows of \\(Q\\) sum to 0.\nThis gives the total rate of change leaving state \\(i\\).\n\nThe matrix \\(Q\\) can be used to understand the probability of being in a given\nstate after \\(t\\) time unis. This can be represented mathematically using a\nmatrix \\(P_{t}\\) where \\((P_{t})_{ij}\\) is the probability of being in state \\(j\\)\nafter \\(t\\) time units having started in state \\(i\\). Using a mathematical tool\ncalled the matrix exponential\\footnote{Chapter 9 of~\\cite{van1996matrix}\ngives a description of how to compute the matrix\nexponential\\index{matrix exponential} numerically and~\\cite{moler1978nineteen,\nmoler2003nineteen} give a review of 19 algorithms that can be used.} the value\nof \\(P_{t}\\) can be calculated numerically.\n\n\\begin{equation}\n    P_t = e^{Qt}\n    \\label{eqn:continuous_time_markov_process_matrix_exponential}\n\\end{equation}\n\nWhat is also useful is understanding the long run behaviour of the\nsystem. This allows us to answer questions such as ``what state is the system most\nlikely to be in on average?'' or ``what is the probability of being in the last\nstate on average?''.\n\nThis long run probability distribution\\index{long run probability distribution}\nover the states can be represented using a vector\\index{vector} \\(\\pi\\) where\n\\(\\pi_i\\) represents the probability of being in state \\(i\\). This vector is in\nfact the solution to the following matrix equation\\index{matrix equation}:\n\n\\begin{equation}\n    \\pi Q = 0\n    \\label{eqn:continuous_time_markov_process_steady_state}\n\\end{equation}\n\nwith the following constraint:\n\n\\begin{equation}\n    \\sum_{i=1}^{n}\\pi_i = 1\n\\end{equation}\n\nIn the upcoming sections all of the above concepts will be demonstrated and used\nto understand what is the best course of action for the barber shop.\n\n\\section{Solving with Python}\\label{sec:markov_chains_solving-with-python}\n\nThe first step is to write a function to obtain the transition\nrates between 2 given states:\n\n\n\\begin{pyin}\ndef get_transition_rate(\n    in_state,\n    out_state,\n    waiting_room=4,\n    num_barbers=2,\n):\n    \"\"\"Return the transition rate for 2 given states.\n\n    Args:\n        in_state: an integer\n        out_state: an integer\n        waiting_room: an integer (default: 4)\n        num_barbers:  an integer (default: 2)\n\n    Returns:\n        A real.\n    \"\"\"\n    arrival_rate = 10\n    service_rate = 4\n    capacity = waiting_room + num_barbers\n    delta = out_state - in_state\n\n    if delta == 1:\n        return arrival_rate\n\n    if delta == -1:\n        return min(in_state, num_barbers) * service_rate\n\n    return 0\n\\end{pyin}\n\nNext, a function that creates an entire transition rate matrix \\(Q\\) for a given\nproblem is written. The Numpy\\index{Numpy}~\\cite{harris2020array} library will\nbe used to handle all the linear algebra\\index{linear algebra} and the\nItertools\\index{Itertools} library for some iterations:\n\n\\begin{pyin}\nimport itertools\nimport numpy as np\n\n\ndef get_transition_rate_matrix(waiting_room=4, num_barbers=2):\n    \"\"\"Return the transition matrix Q.\n\n    Args:\n        waiting_room: an integer (default: 4)\n        num_barbers: an integer (default: 2)\n\n    Returns:\n        A matrix.\n    \"\"\"\n    capacity = waiting_room + num_barbers\n    state_pairs = itertools.product(range(capacity + 1), repeat=2)\n    flat_transition_rates = [\n        get_transition_rate(\n            in_state=in_state,\n            out_state=out_state,\n            waiting_room=waiting_room,\n            num_barbers=num_barbers,\n        )\n        for in_state, out_state in state_pairs\n    ]\n    transition_rates = np.reshape(\n        flat_transition_rates, (capacity + 1, capacity + 1)\n    )\n    np.fill_diagonal(\n        transition_rates, -transition_rates.sum(axis=1)\n    )\n\n    return transition_rates\n\\end{pyin}\n\nUsing this the matrix \\(Q\\) for the default system can be obtained:\n\n\\begin{pyin}\nQ = get_transition_rate_matrix()\nprint(Q)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n[[-10  10   0   0   0   0   0]\n [  4 -14  10   0   0   0   0]\n [  0   8 -18  10   0   0   0]\n [  0   0   8 -18  10   0   0]\n [  0   0   0   8 -18  10   0]\n [  0   0   0   0   8 -18  10]\n [  0   0   0   0   0   8  -8]]\n\\end{pyout}\n\nHere, the matrix exponential will be used as\ndiscussed above, using the SciPy\\index{SciPy}~\\cite{2020SciPy-NMeth}\nlibrary. To see what would happen after 0.5 time units:\n\n\\begin{pyin}\nimport scipy.linalg\n\nprint(scipy.linalg.expm(Q * 0.5).round(5))\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n[[0.10492 0.21254 0.20377 0.17142 0.13021 0.09564 0.0815 ]\n [0.08501 0.18292 0.18666 0.1708  0.14377 0.1189  0.11194]\n [0.06521 0.14933 0.16338 0.16478 0.15633 0.14751 0.15346]\n [0.04388 0.10931 0.13183 0.15181 0.16777 0.18398 0.21142]\n [0.02667 0.07361 0.10005 0.13422 0.17393 0.2189  0.27262]\n [0.01567 0.0487  0.07552 0.11775 0.17512 0.24484 0.32239]\n [0.01068 0.03668 0.06286 0.10824 0.17448 0.25791 0.34914]]\n\\end{pyout}\n\nTo see what would happen after 500 time units:\n\n\\begin{pyin}\nprint(scipy.linalg.expm(Q * 500).round(5))\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n[[0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n [0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n [0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n [0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n [0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n [0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n [0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]]\n\\end{pyout}\n\nAfter 500 time units, the probability of ending up in each state (column) is\nthe same regardless of the state the system began in (row).\n\nThe analysis can in fact be stopped here\nhowever the choice of 500 time units was arbitrary and might not be the correct\namount for all possible scenarios, as such the\nunderlying equation~\\ref{eqn:continuous_time_markov_process_steady_state}\ncan be solved directly in order to get a solution where\nequilibrium\\index{equilibrium} is guaranteed.\n\nThe underlying linear system will be solved using a numerically efficient\nalgorithm called least squares optimisation\\index{least squares optimisation}\n(available from the Numpy library):\n\n\\begin{pyin}\ndef get_steady_state_vector(Q):\n    \"\"\"Return the steady state vector of any given continuous time\n    transition rate matrix.\n\n    Args:\n       Q: a transition rate matrix\n\n    Returns:\n        A vector\n    \"\"\"\n    state_space_size, _ = Q.shape\n    A = np.vstack((Q.T, np.ones(state_space_size)))\n    b = np.append(np.zeros(state_space_size), 1)\n    x, _, _, _ = np.linalg.lstsq(A, b, rcond=None)\n    return x\n\\end{pyin}\n\nThe steady state vector for the default system is given by:\n\n\\begin{pyin}\nprint(get_steady_state_vector(Q).round(5))\n\\end{pyin}\n\ngiving:\n\n\\begin{pyout}\n[0.03431 0.08577 0.10722 0.13402 0.16752 0.2094  0.26176]\n\\end{pyout}\n\nThis shows that the shop is expected to be empty approximately 3.4\\% of the time\nand full 26.2\\% of the time.\n\nThe final function written is one that uses all of\nthe above to return the probability of the shop being full.\n\n\\begin{pyin}\ndef get_probability_of_full_shop(waiting_room=4, num_barbers=2):\n    \"\"\"Return the probability of the barber shop being full.\n\n    Args:\n        waiting_room: an integer (default: 4)\n        num_barbers: an integer (default: 2)\n\n    Returns:\n        A real.\n    \"\"\"\n    Q = get_transition_rate_matrix(\n        waiting_room=waiting_room,\n        num_barbers=num_barbers,\n    )\n    pi = get_steady_state_vector(Q)\n    return pi[-1]\n\\end{pyin}\n\nThis can now confirm the previous calculated probability of the shop\nbeing full:\n\n\\begin{pyin}\nprint(round(get_probability_of_full_shop(), 6))\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n0.261756\n\\end{pyout}\n\nNow that the models have been defined, they will be used to compare the 2\npossible scenarios.\n\nHaving 2 extra space in the waiting room corresponds to:\n\n\\begin{pyin}\nprint(round(get_probability_of_full_shop(waiting_room=6), 6))\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n0.23557\n\\end{pyout}\n\nThis is a slight improvement however, increasing the number of barbers has a\nsubstantial effect:\n\n\\begin{pyin}\nprint(round(get_probability_of_full_shop(num_barbers=3), 6))\n\\end{pyin}\n\n\\begin{pyout}\n0.078636\n\\end{pyout}\n\nTherefore, it would be better to increase the number of barbers by 1\nthan to increase the waiting room capacity by 2.\n\n\\section{Solving with R}\\label{sec:markov_chains_solving-with-R}\n\nThe first step taken is to write a function to obtain the transition rates\nbetween 2 given states:\n\n\\begin{Rin}\n#' Return the transition rate for 2 given states.\n#'\n#' @param in_state an integer\n#' @param out_state an integer\n#' @param waiting_room an integer (default: 4)\n#' @param num_barbers an integer  (default: 2)\n#'\n#' @return A real\nget_transition_rate <- function(in_state,\n                                out_state,\n                                waiting_room = 4,\n                                num_barbers = 2) {\n  arrival_rate <- 10\n  service_rate <- 4\n  capacity <- waiting_room + num_barbers\n  delta <- out_state - in_state\n\n  if (delta == 1) {\n    return(arrival_rate)\n  }\n  if (delta == -1) {\n    return(min(in_state, num_barbers) * service_rate)\n  }\n  return(0)\n}\n\\end{Rin}\n\nThis actual function will not be used but instead a vectorized\nversion\\footnote{\nA vectorized\\index{vectorized} calculation refers to the manner in which an\ninstruction is given to a computer. When vectorized: a single instruction with\nmultiple data are given at the same time\nwhich corresponds to ``Single instruction, multiple data'' (SIMD) as defined in\nFlynn's taxonomy~\\cite{flynn1966very}. This is a type of parallelisation\nthat can be done at the central processing unit level of the computer. }\nof this makes calculations more efficient:\n\n\\begin{Rin}\nvectorized_get_transition_rate <- Vectorize(\n  get_transition_rate,\n  vectorize.args = c(\"in_state\", \"out_state\")\n)\n\\end{Rin}\n\nThis function can now take a vector of inputs for the \\mintinline{R}{in_state}\nand \\mintinline{R}{out_state} variables which will allow us to simplify the\nfollowing code that creates the matrices:\n\n\\begin{Rin}\n#' Return the transition rate matrix Q\n#'\n#' @param waiting_room an integer (default: 4)\n#' @param num_barbers an integer (default: 2)\n#'\n#' @return A matrix\nget_transition_rate_matrix <- function(waiting_room = 4,\n                                       num_barbers = 2){\n  max_state <- waiting_room + num_barbers\n\n  Q <- outer(\n    0:max_state,\n    0:max_state,\n    vectorized_get_transition_rate,\n    waiting_room = waiting_room,\n    num_barbers = num_barbers\n  )\n  row_sums <- rowSums(Q)\n  diag(Q) <- -row_sums\n  Q\n}\n\\end{Rin}\n\nUsing this the matrix \\(Q\\) for the default system can be used:\n\n\\begin{Rin}\nQ <- get_transition_rate_matrix()\nprint(Q)\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n     [,1] [,2] [,3] [,4] [,5] [,6] [,7]\n[1,]  -10   10    0    0    0    0    0\n[2,]    4  -14   10    0    0    0    0\n[3,]    0    8  -18   10    0    0    0\n[4,]    0    0    8  -18   10    0    0\n[5,]    0    0    0    8  -18   10    0\n[6,]    0    0    0    0    8  -18   10\n[7,]    0    0    0    0    0    8   -8\n\\end{Rout}\n\nOne immediate thing that can be done with this matrix is to take the\nmatrix exponential discussed above. To do this, an R library called\nexpm\\index{expm}~\\cite{goulet2021expm} will be used.\nTo be able to make use of the nice \\mintinline{R}{%>%} ``pipe'' operator the\nmagrittr\\index{magrittr}~\\cite{bache2020magrittr} library will be loaded. Now to\nsee what would happen after 0.5 time units:\n\n\\begin{Rin}\nlibrary(expm, warn.conflicts = FALSE, quietly = TRUE)\nlibrary(magrittr, warn.conflicts = FALSE, quietly = TRUE)\n\nprint( (Q * 0.5) %>% expm() %>% round(5))\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n        [,1]    [,2]    [,3]    [,4]    [,5]    [,6]    [,7]\n[1,] 0.10492 0.21254 0.20377 0.17142 0.13021 0.09564 0.08150\n[2,] 0.08501 0.18292 0.18666 0.17080 0.14377 0.11890 0.11194\n[3,] 0.06521 0.14933 0.16338 0.16478 0.15633 0.14751 0.15346\n[4,] 0.04388 0.10931 0.13183 0.15181 0.16777 0.18398 0.21142\n[5,] 0.02667 0.07361 0.10005 0.13422 0.17393 0.21890 0.27262\n[6,] 0.01567 0.04870 0.07552 0.11775 0.17512 0.24484 0.32239\n[7,] 0.01068 0.03668 0.06286 0.10824 0.17448 0.25791 0.34914\n\\end{Rout}\n\nAfter 500 time units:\n\n\\begin{Rin}\nprint( (Q * 500) %>% expm() %>% round(5))\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n        [,1]    [,2]    [,3]    [,4]    [,5]   [,6]    [,7]\n[1,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n[2,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n[3,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n[4,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n[5,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n[6,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n[7,] 0.03431 0.08577 0.10722 0.13402 0.16752 0.2094 0.26176\n\\end{Rout}\n\nAfter 500 time units, the probability of ending up in each state (columns) is\nthe same regardless of the state the system began in (row).\n\nThe analysis can in fact be stopped here\nhowever the choice of 500 time units was arbitrary and might not be the correct\namount for all possible scenarios, as such the\nunderlying equation~\\ref{eqn:continuous_time_markov_process_steady_state}\nneeds to be solved directly.\n\nTo be able to do this, the versatile pracma\\index{pracma}~\\cite{borchers2021pracma}\npackage will be used which includes a number of numerical analysis functions for\nefficient computations.\n\n\\begin{Rin}\nlibrary(pracma, warn.conflicts = FALSE, quietly = TRUE)\n\n#' Return the steady state vector of any given continuous time\n#' transition rate matrix\n#'\n#' @param Q a transition rate matrix\n#'\n#' @return A vector\nget_steady_state_vector <- function(Q){\n  state_space_size <- dim(Q)[1]\n  A <- rbind(t(Q), 1)\n  b <- c(integer(state_space_size), 1)\n  mldivide(A, b)\n}\n\\end{Rin}\n\nThis is making use of pracma's \\mintinline{R}{mldivide} function\nwhich chooses the best numerical algorithm to find the solution to a given\nmatrix equation \\(Ax=b\\).\n\nThe steady state vector for the default system is now given by:\n\n\\begin{Rin}\nprint(get_steady_state_vector(Q))\n\\end{Rin}\n\ngiving:\n\n\\begin{Rout}\n           [,1]\n[1,] 0.03430888\n[2,] 0.08577220\n[3,] 0.10721525\n[4,] 0.13401906\n[5,] 0.16752383\n[6,] 0.20940479\n[7,] 0.26175598\n\\end{Rout}\n\nThe shop is expected to be empty approximately 3.4\\% of the time\nand full 26.2\\% of the time.\n\nThe final piece of this puzzle is to create a single function that uses all of\nthe above to return the probability of the shop being full.\n\n\\begin{Rin}\n#' Return the probability of the barber shop being full\n#'\n#' @param waiting_room (default: 4)\n#' @param num_barbers (default: 2)\n#'\n#' @return A real\nget_probability_of_full_shop <- function(waiting_room = 4,\n                                         num_barbers = 2){\n  arrival_rate <- 10\n  service_rate <- 4\n  pi <- get_transition_rate_matrix(\n    waiting_room = waiting_room,\n    num_barbers = num_barbers\n    ) %>%\n    get_steady_state_vector()\n\n  capacity <- waiting_room + num_barbers\n  pi[capacity + 1]\n}\n\\end{Rin}\n\nThis confirms the previous calculated probability of the shop\nbeing full:\n\n\\begin{Rin}\nprint(get_probability_of_full_shop())\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n[1] 0.261756\n\\end{Rout}\n\nNow that the models have been defined, they will be used to compare the 2\npossible scenarios.\n\nAdding 2 extra spaces in the waiting rooms corresponds to:\n\n\\begin{Rin}\nprint(get_probability_of_full_shop(waiting_room = 6))\n\\end{Rin}\n\nwhich decreases the probability of a full shop to:\n\n\\begin{Rout}\n[1] 0.2355699\n\\end{Rout}\n\nbut adding another barber and chair:\n\n\\begin{Rin}\nprint(get_probability_of_full_shop(num_barbers = 3))\n\\end{Rin}\n\ngives:\n\n\\begin{Rout}\n[1] 0.0786359\n\\end{Rout}\n\nTherefore, it would be better to increase the number of barbers by 1\nthan to increase the waiting room capacity by 2.\n\n\n\\section{Wider context}\\label{sec:markov_chains_wider_context}\n\nThe overview of Markov chains given here has mainly concentrated on calculation\nof steady state\\index{steady state} probabilities. There are in fact many more\ntheoretic and applied aspects of Markov chain models. Some examples of this\ninclude the calculation of sojourn times\\index{sojourn time} which is how long a\nsystem spends in a given state as well as considering models with\nabsorption\\index{absorption}: where the system arrives at a state that it no\nlonger leaves. For a good overview of these the following textbook is\nrecommended:~\\cite{stewart2009probability}.\n\nIn~\\cite{tan1997markov, stewart1996monopoly}, Markov chains are used to model\nboard games\\index{board games}. In~\\cite{tan1997markov} a model of the battles\nthat take place on a Risk board is used to understand the probabilities of\ninvasion of territories based on troop numbers. This is done using an\nabsorbing Markov chain. In~\\cite{stewart1996monopoly} a standard model is used\nto identify the properties that are most likely to be landed on in Monopoly.\nThis is done through calculation of steady state probabilities. These are both\nexamples of discrete time Markov chains.\n\nA common application of Markov chains is in queueing\\index{queueing} systems and\nspecifically queueing systems applied to healthcare\\index{healthcare}.\nIn~\\cite{griffiths2013modelling} a model of a neurological rehabilitation unit\nis built and used to help better staff the unit.  This is accomplished using the\nsteady state probabilities and calculating various performance measures. This is\nan application of a continuous time Markov chain.\n\nAn extension of Markov chains are Markov decision\nprocesses\\index{Markov decision process}. This is a particular mathematical\nmodel that identifies the optimal decision made within a Markov chain.\nInstead of building multiple Markov models for different decisions, in Markov\ndecision processes decisions can be made at each state of the underlying chain.\nA policy can be identified giving the optimal decision at each state.\nIn~\\cite{white1993survey} a literature review is given showing a wide\nranging application of these decision processes from agriculture to motor\ninsurance claims as well as sports.\n", "meta": {"hexsha": "9c0a81db1d0b286e284a874323beffe8a6dde7b8", "size": 22986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/chapters/02/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/02/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/02/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": 32.1033519553, "max_line_length": 95, "alphanum_fraction": 0.7185678239, "num_tokens": 7052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.6634073798921019}}
{"text": "\n\\subsection{The value function}\n\n\\subsubsection{State payoffs}\n\nAn agent gets a payoff which depends on the current state. We now have:\n\n\\begin{itemize}\n\\item \\(S\\) - the state space\n\\item \\(s_1\\) - the initial state\n\\item \\(P\\) - the transition model\n\\item \\(R\\) - the reward distribution\n\\end{itemize}\n\n\\subsubsection{Discounting}\n\nWe maximise the reward function using discounting.\n\n\\(E[\\sum_{t=1}^\\infty \\gamma^{t-1}r_t|s_1]\\)\n\n", "meta": {"hexsha": "4b9da86e0a70306ccedca26c4585df9175f6b5a7", "size": 433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/MDP/01-02-value.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/ai/MDP/01-02-value.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/ai/MDP/01-02-value.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.619047619, "max_line_length": 71, "alphanum_fraction": 0.7159353349, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6633822903869147}}
{"text": "\n%*******************************************************************************\n%***********************************    Background   *****************************\n%*******************************************************************************\n%!TEX root = 0.main.tex\n\n\\setcounter{page}{1}\n\n\n\n%********************************** %First Section  **************************************\n\\section {Introduction and general background} \n\n\\subsection{Introduction}\n\nNeural Networks (NNs) are popular algorithms for regression and classification tasks. Taking as example classification tasks of mapping the image $I$ into its correct label $C_I$, neural networks perform multiple combinations of linear and non-linear transformations of the image $I$ to assign it a label in $\\mathcal C$.  The first \\textit{layer} of a neural network transforms the input image $I$ in a vector $\\mathbf f_1$ through a function $\\phi_1$. $\\mathbf f_1$ is used as input of the following layer that transforms it in a second vector $\\mathbf f_2$ through a second function $\\phi_2$, and so on, until the original image $I$ is mapped into a label $C_I$ by the last, $n$-th layer of the neural network:\n$$C_I = \\phi_n \\circ \\phi_{n-1}\\circ ... \\phi_2\\circ\\phi_1 (I)$$\n Given a large \\textit{training set} of labeled images, a neural network is capable of learning the optimal transformations $\\phi_i$ that let it map the input image to its correct label. Since the functions $\\phi_i$ have many degrees of freedom - even millions - a neural network is able to learn very complex transformations. This characteristic makes NNs the optimal tool for complex tasks such as image classification, image segmentation, speech recognition and natural language processing.\\\\\n\nConvolutional Neural Networks (CNNs) are a specific class of neural networks whose layer structure has been specifically designed for image recognition and segmentation. For this purpose, they don't have all the degrees of freedom of a normal, \\textit{fully connected} neural network described above: each layer of a CNN has been constrained to only learn transformations of the input that are \\textit{invariant} to translation of the input. This means that if used in an image classification task, a translation of the input image will not result in a change of class. The function $\\phi_i$ of a CNN are \\textit{convolutions} with some kernel that was learned during the training phase. Thanks to their design, training of CNNs is faster - thanks to the smaller number of parameters to be learned compared to a fully connected NN -, it is easier -since there's no need of artificially \\textit{augmenting} the dataset with translated copies of the same image -, and leads to very accurate results.\\\\\n\nSpherical convolutional neural networks (SCNNs) are NNs that have been specifically designed to deal with spherical data, whose layer design makes them \\textit{equivariant to rotations of the input}.  Examples of tasks where data is naturally represented on a sphere are (i) climate science, where data is sampled on the surface of the Earth, (ii) cosmology, where observations are naturally projected on a sphere centered around the observer (see Figure \\ref{fig:cosmicradiation}), and (iii) virtual reality, where the images are represented on a sphere centered around the player. Being able to come up with designs that are equivariant to rotations brings with it all the advantages that traditional CNNs have brought for traditional (euclidean) image classification tasks: training is faster, easier and results are very accurate. The transformations $\\phi_i$ that each layer of a SCNN performs is a \\textit{spherical convolution} of the input vector with a kernel learned during the training phase. \n\n\\begin{figure}\n\t\\centering\n\t\\caption{\\label{fig:cosmicradiation} Cosmic microwave background map, the oldest electromagnetic radiation in the universe. Source: Wikipedia}\n\t\\includegraphics[width=0.4\\textwidth]{figs/literaturereview/WMAP.png}\n\\end{figure}\nOne of the main issues with traditional SCNNs is the computational complexity of computing at each layer the Spherical Harmonic Transform (SHT) of the data to perform the convolution in the spectral domain. Perraudin et al. \\cite{DeepSphere} proposed a Graph Convolutional Neural Network (GCNN) that is almost equivariant to rotations, replacing the SHT with a more efficient Graph Convolution.\n\nIn this Chapter we start by presenting fundamental concepts of spectral theory on the sphere and we present classical ways of building rotation equivariant neural networks through the use of the SHT.  We present then some basics of Graph Spectral Theory useful to introduce the work of Perraudin et al. DeepSphere \\cite{DeepSphere}. We present then a well suited way to build a graph to approximate the Laplace-Beltrami operator on a manifold, the Heat Kernel Graph Laplacian (HKGL) together with some convergence results. In Chapter 2 we study the spectral properties of the graph Laplacian matrix $\\mathbf L$ used by Perraudin et al. and we show a way to build a graph $G'$ such that the corresponding graph Laplacian matrix $\\mathbf L'$ shows better spectral properties. In Chapter 3 we investigate other different methods of building the matrix $\\mathbf L$ better suited to non uniform sampling measures. In particular, we study the Finite Element Method approximation of the Laplace-Beltrami operator on the sphere. We compare the FEM and the graph Laplacian on different samplings of the sphere. We finish by discussing the general problem of how to incorporate geometrical informations about the sphere in the graph, a purely topological object.\n\n\\subsection{Fourier Transforms and Convolutions on the 2-Sphere}\n[Review of \\textit{Computing Fourier Transforms and Convolutions on the 2-Sphere}]\nIf we find a basis of minimal subspaces invariant (a vector space of functions on the sphere is invariant if all of the operators $\\Lambda(g), g\\in SO(3)$ take each function in the space back into the space) under all the rotations of $SO(3)$, then we simplify a lot the analysis of rotation-invariant operators.\n\\paragraph{Things to keep in mind from section 2, \"Preliminaries\"}\n\\begin{enumerate}\n\t\\item any rotation $g\\in SO(3)$ can be written in the well-known Euler angle decomposition: $g = u(\\phi)a(\\theta)u(\\psi)$ determined uniquely for almost all $g$. Remember that any point on the sphere\n\t\\item $\\omega(\\theta, \\phi) = \\left(\\cos\\phi\\sin\\theta, \\sin\\phi\\sin\\theta, \\cos\\theta\\right)$. In fact, the 2-sphere is a quotient of the rotation group $SO(3)$ and inherits its natural coordinate system from that of the group.\n\t\\item $\\Lambda(g)f(\\omega) = f(g^{-1}\\omega)$\n\t\\item invariant volume measure on $SO(3)$ is $dg=\\sin\\theta\\ d\\theta\\ d\\phi\\ d\\psi$, invariant volume measure on the sphere is $d\\omega = \\sin\\theta\\ d\\theta\\ d\\phi$\n\t\\item The invariant subspace of degree $l$ harmonic polynomials restricted to the sphere is called the space of \\textit{spherical harmonics of degree l}. Spherical harmonics of different degree are orthogonal to one another\n\t\\item In coordinates, \n\t$$Y_l^m(\\theta, \\phi) =(-1)^m\\sqrt{\\frac{(2l+1)(l-m)!}{4\\pi(l+m)!}}P_l^m(\\cos\\theta)e^{im\\phi}$$\n\twhere $P_l^m$ are Legendre functions.\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{../codes/03.FEM_laplacian/HEALPix/img/linear_FEM_8_eigenvectors.png}\t\n\t\t\\label{fig:spherical harmonics}\n\t\t\\caption{The first 16 spherical harmonics}\n\t\\end{figure}\n\t\n\t\\item Of all the possible basis for $L^2(S^2)$ the spherical harmonics uniquely exploit the symmetries of the sphere. Under a rotation $g$, each spherical harmonic of degree $l$ is transformed into a linear combination of only those spherical harmonics of same degree $l$.\n\tThus the effect of a rotation on a function expressed in the basis of the spherical harmonics is a multiplication by a semi-infinite block-diagonal matrix with the $(2l+1)\\times(2l+1)$ blocks for each $l \\geq 0$ given by $$D^{(l)}(g) = \\left(D^{(l)}_{m,n}\\right) (g) =  \\left(D^{(l)}_{m,n}\\right)(u(\\phi)a(\\theta)u(\\psi)) = e^{-im\\psi}d^{(l)}_{m,n}(\\cos \\theta) e^{-in\\phi}$$\n\tThe effect of all of this is to block-diagonalize rotationally invariant operators; namely, convolution operators obtained as weighted averages of the rotation operators by functions or kernels. For example the Laplace-Beltrami operator, that acts diagonally on the spherical harmonic basis.\n\t\\item \\begin{definition}{[\\textit{Left Convolution}]}\\\\\n\t\t$k\\star f(\\omega) = \\left(\\int_{g\\in SO(3)}dg\\ k(g\\eta)\\Lambda(g)\\right)f(\\omega) = \\int_{g\\in SO(3)}k(g\\eta)f(g^{-1}\\omega)dg$\n\t\twhere $\\eta$ is the north pole. \n\t\\end{definition}\n\tSince the convolution is a linear combination of rotation operators $\\Lambda(g)$, it follows that also the convolution must be block diagonalized. Indeed,\n\t$$\\hat {(f \\star h)}(l,m) = 2\\pi \\sqrt{\\frac{4\\pi}{2l+1}}\\hat f(l,m) \\hat h(l,0) $$\n\n\\end{enumerate}\n\n\\subsection{Spherical Convolutional Neural Networks}\n[Review of \\textit{Spherical CNNs}]\n\\subsection{Graph Spectral Theory} \\label{sec:Chapter1: Spectral Graph Theory}\n[Review of \\textit{The emerging field of Graph Signal Processing}]\n\\subsection{Deep Sphere V1.0}\n[Review of \\textit{Deep Sphere}]\n\\subsection{Belkin's trinity}\n[Review of \\textit{the Belkin's trinity}]\n\n\\subsubsection{Towards a theoretical foundation of Laplacian-based manifold methods}\nIn this paper they present two results: a pointwise probabilistic convergence of \\textbf{the extension of the graph Laplacian} \n\\begin{definition}{Graph Laplacian}\n\t$$ \\left(\\mathbf L_n^t\\right)_{ij}=\\begin{cases}\n\t-w_{ij}, & i\\neq j\\\\\n\t\\sum_{k}w_{ik}, & i=j\n\t\\end{cases}$$\n\\end{definition}\n\\begin{definition}{Point cloud Laplace operator}\n\t$$L_n^t:\\quad(L_n^tf)(y) = \\frac{1}{n}f(y)\\sum_i e^{-\\frac{||x_i-y||^2}{4t}}-\\frac{1}{n}\\sum_ie^{-\\frac{||x_i-y||^2}{4t}}f(x_i)$$\n\\end{definition}\n\\begin{definition}{Functional approximation to the Laplace-Beltrami operator} \\label{eq:L^t}\n\t$$L^tf(p) :=  \\frac{1}{ (4\\pi t)^{\\frac{k+2}{2}}} \\int_\\mathcal Me^{-\\frac{||p-x||^2}{4t}}\\left(f(x)-f(p)\\right)d\\mu(x)$$\n\\end{definition}\n\n\\begin{theorem}{Pointwise convergence}\n\t$$\\forall f \\in C^\\infty(\\mathcal M)\\quad  C\\frac{(4\\pi t_n)^{-\\frac{k+2}{2}}}{n} L_n^t f(\\bf x) \\xrightarrow{n\\to\\infty}\\triangle_\\mathcal M f(\\bf x)$$\n\\end{theorem}\n\n\nand a uniform (pointwise convergence of the operator) one\n\\begin{theorem}{uniform convergence}\n\t$$\\sup_{x\\in\\mathcal M, f\\in \\mathcal F_C}\\left| C\\frac{(4\\pi t_n)^{-\\frac{k+2}{2}}}{n} L_n^t f(\\bf x) - \\triangle_\\mathcal M f(\\bf x) \\right|\\xrightarrow{n\\to\\infty}0\n\t, \\quad \\mathcal F_C = \\left\\{f\\in C^\\infty(\\mathcal M), f^{(i)}(x)\\leq M, i=1,2,3\\right\\}$$\n\\end{theorem}\n\n\nhere nothing is said about convergence of the spectra, plus there's nothing written about the relationship between $\\mathbf{Eig} L_n^t$ (the eigenfunctions and eigenvalues of the extension of the graph Laplacian) and $\\mathbf {Eig} \\mathbf {L}_n^t$ (the eigenvectors and eigenvalues of the matrix Laplacian).\n\nTheorem 1 is proven by simple analysis arguments and by Hoeffding's formula (probability). \nFirst, by the simple law of large numbers, we have that for a fixed $t>0$, a fixed function $f$ and a fixed point $p\\in\\mathcal M$\n\\begin{equation}\\label{eq:pointwise convergence of laplacian discrete approximation}\n\t\\lim_{n\\to\\infty}\\frac{1}{tn}\\frac{1}{ (4\\pi t)^{\\frac{k}{2}}}L_n^tf(p)= L^tf(p)\n\\end{equation}\n\n\n\n\nTo prove the convergence of $L^t$ to $\\triangle_\\mathcal M$, then we need three steps, that we can recycle completely. They use the fact that thanks to the exponential map the heat kernel centered on $p$ on any manifold can be approximated by a Gaussian in the ambient Euclidean space in a small neighborhood of $p$, and the relationship between Euclidean distances and geodesic distances.\n\nTheorem 2 is proven with arguments of Functional Analysis: Ascoli-Arzelà, compact convergence in Sobolev spaces, etc.etc...\n\n\\subsubsection{Consistency of Spectral Clustering}\n$$ \\mathbf{Eig} \\mathbf{L}^t_n \\xrightarrow[a.s.]{n\\to\\infty} \\mathbf{Eig} L^t $$\nIt aims at proving the convergence of eigenvalues and eigenvectors of random graph Laplacian matrices for growing sample size. They present two results: one for the normalized Laplacian and one for the unnormalized Laplacian. Since the matrix eigenvectors grow in dimension as the sample size increases, standard convergence arguments can not be applied. However, they show that there exists a function $f\\in C(\\mathcal M)$ such that the difference between the eigenvector $v_n$ and the restriction of $f$ to the sample converges to $0$\n\n$$||v_n-\\rho_nf||\\rightarrow 0$$\n\nTo do so they see the eigenvector $v_n$ as the restriction to the sample of a continuous eigenfunction $f_n$ of some continuous operator $U'_n$ that acts on the space $C(\\mathcal M)$. Then they use the fact that \n\n$$||v_n-\\rho_nf||_\\infty = ||\\rho_nf_n-\\rho_nf||_\\infty\\leq ||f_n-f||_\\infty$$\n\n\nSo, it will just be necessary to show that  $$||f_n-f||_\\infty\\rightarrow 0$$\n\\textbf{compact convergence} of both matrices towards $L^t$ (where $\\mathcal M$ is a compact metric space) in the Banach space of the continuous functions $(C, ||\\cdot||_\\infty)$. \n\nCompact convergence ensures convergence of spectral properties in the following sense: for isolated eigenvalues of the limit operator $\\triangle_\\mathcal M$ with finite multiplicity we have convergence of eigenvalues and eigenspaces but not convergence of eigenfunctions. for isolated simple eigenvalues of the limit operator we have also convergence of the eigenfunctions!\n\nThe proof consists in three steps:\n\\paragraph{Step 1} Construct a bounded operator $U'_n$ on the Banach space $(C(\\mathcal M), ||\\cdot||_\\infty)$ such that restricted on the sampled values behaves like $\\mathbf{L}'_n$. Then, construct an operator $U'$ such that for the law of large numbers for a fixed $f$ and for a fixed $x$, $U'_nf(x) \\xrightarrow U'f(x) $\n\\paragraph{Step 2} Here they establishes the connection between the spectra of $L'_n$ and $U'_n$. In particular, they prove a one-to-one correspondence between the eigenfunctions and eigenvalues of $U'_n$ and the eigenvectors and eigenvalues of $L'_n$, provided that satisfy $\\lambda\\notin \\{1\\}=\\sigma_{ess}(U'_n)= \\sigma_{ess}(U')$.\n\\paragraph{Step 3} Here we prove compact convergence:\n\n$$U'_n \\xrightarrow[n\\to\\infty]{c,\\ a.s.}U'$$\n\nAt the light of compact convergence and on the analysis of the essential spectrum of $U'_n, U'$ and the one-to-one correspondence of the spectra done in step 2, given Proposition 6 \\textit{Perturbation results for compact convergence} we get to the following result\n\n\\begin{theorem}\n\tLet $\\lambda\\neq 1 $ be an eigenvalue of $U'$ and $M\\subset \\mathbb C$ an open neighborhood of $\\lambda$ such that $\\sigma(U')\\cap M=\\{\\lambda\\}$. Then:\n\t\\begin{enumerate}\n\t\t\\item Convergence of eigenvalues: The eigenvalues in$\\sigma(L'_n)\\cap M$ converge to $\\lambda$ in the sense that every sequence $(\\lambda_n)_{n\\in\\mathbb N}$ with $\\lambda_n\\in\\sigma(L'_n)\\cap M$ satisfies $\\lambda_n\\rightarrow \\lambda$ almost surely.\n\t\t\\item Convergence of spectral projections: There exists some $N\\in\\mathbb N$ such that for $n>N$, the sets $\\sigma(U'_n)\\cap M$ are isolated in $\\sigma(U'_n)$. For $n>N$, let $Pr'_n$ be the spectral projection of $U'_n$ corresponding to $\\sigma(U'_n)\\cap M$, and $Pr$ the spectral projection of $U$ for $\\lambda$. Then $Pr'_n\\xrightarrow p Pr a.s.$\n\t\t\\item Convergence of eigenvectors: if $\\lambda$ is a single eigenvalue, then the eigenvectors of $L'_n$ converge a.s. up to a change of sign: if $v_n$ is the eigenvector\n\t\tof $L'_n$ with eigenvalue $\\lambda_n$, $v_{n,i}$ its i-th coordinate, and $f$ the eigenfunction of eigenvalue $\\lambda$, then there exists a sequence $(a_n)_{n\\in\\mathbb N}$ with $a_i \\in \\{+1,-1\\}$ such that $\\sup_{i=1,...,n} |a_nv_{n,i} - f(X_i)| \\rightarrow 0$ a.s. In particular, for all $b \\in\\mathbb R$, the sets $\\{a_nf_n > b\\}$ and $\\{f > b\\}$ converge, that is, their symmetric difference satisfies $P(\\{f > b\\}\\triangle\\{a_nf_n > b\\}) \\rightarrow 0$.\n\t\\end{enumerate}\n\\end{theorem}\n\nA similar theorem is stated also for non-normalized Laplacian matrix, although the arguments stay the same.\n\\subsubsection{Convergence of Laplacian Eigenmaps}\nHere all the pieces are put together. \n\n$$ \\mathbf{Eig} \\mathbf{ L}^t_n \\xrightarrow[a.s.]{n\\to\\infty} \\mathbf{Eig} L^t \\xrightarrow{t\\to0} \\mathbf{Eig} \\triangle_\\mathcal M $$\n\n\\begin{theorem}\n\tLet $\\lambda_{n,i}^t$ be the ith eigenvalue of $\\hat L_n^t$ and $e^t_{n,i}$ be the corresponding eigenfunction (which for each fixed i will be shown to exist for t sufficiently small). Let $\\lambda_{i}$ be the ith eigenvalue of $\\triangle_\\mathcal M$ and $e_{i}$ be the corresponding eigenfunction. Then there exists a sequence $t_n\\rightarrow 0$ such that\n\t\n\t$$\\lim_{n\\rightarrow\\infty} \\lambda_{n,i}^{t_n}=\\lambda_i$$\n\t$$\\lim_{n\\rightarrow\\infty}||e_{n,i}^{t_n}(x) - e_i(x)||_2 = 0$$\n\t\n\twhere the limits are in probability.\n\t\n\\end{theorem}\n\n\\paragraph{Step 1: Spectral convergence of the empirical approximation $\\mathbf{ L}_n^t$ to $L^t$}\nRecycle the work of \\textbf{Consistency of Spectral Clustering} with the analysis of the essential spectrum of the limit operator $\\sigma_{ess}(L^t)$.\n\\paragraph{Step 2: Spectral convergence of the functional approximation $L^t$ to $\\triangle$}\nReally hard. Uniform operator convergence does not hold, however spectral convergence is still assured in theorem 4.1 of the paper. This part, although really hard, will stay the same!\nsub", "meta": {"hexsha": "bcd69c8e25989bf9409f525fbd7127776424e703", "size": 17489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDF/1_with_notes.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/1_with_notes.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/1_with_notes.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": 102.2748538012, "max_line_length": 1252, "alphanum_fraction": 0.7394362171, "num_tokens": 4780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6633822811477856}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Timeunit To Number of Seconds}\n\nThe operation $toSeconds$ will return the number of seconds corresponding to the input $Timeunit$\n\\begin{zed}\n  Timeunit ::= second ~| ~ minute ~| ~hour ~| ~day ~| ~week ~| ~month ~| ~year\n\\end{zed}\nsuch that the following schema defines $toSeconds$\n\\begin{schema}{ToSeconds[Timeunit]}\n  t? : Timeunit \\\\\n  toSeconds~\\_ : Timeunit \\pfun \\nat\n  \\where\n  toSeconds(t?) = 1 \\iff t? = second \\\\\n  toSeconds(t?) = 60 \\iff t? = minute \\\\\n  toSeconds(t?) = 3600 \\iff t? = hour \\\\\n  toSeconds(t?) = 86400 \\iff t? = day \\\\\n  toSeconds(t?) = 604800 \\iff t? = week \\\\\n  toSeconds(t?) = 2629743 \\iff t? = month \\\\\n  toSeconds(t?) = 31556926 \\iff t? = year\n\\end{schema}\n\\end{document}\n", "meta": {"hexsha": "acae264dfe04ce18b67572739055c7b04f0c38b8", "size": 777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/util/timeUnitToNumberOfSeconds.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/timeUnitToNumberOfSeconds.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/timeUnitToNumberOfSeconds.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": 33.7826086957, "max_line_length": 97, "alphanum_fraction": 0.6499356499, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6633351520473598}}
{"text": "\\providecommand{\\main}{../..}\n\\documentclass[\\main/thesis.tex]{subfiles}\n\\begin{document}\n\n\\section{Continuous Systems}\\label{continuous}\n\nWe say a numeral system is \\textit{continuous} if there are no gaps in the number\nline and we can always find a successor after each numeral.\nIn other words, a system is continuous if every numeral is \\textit{incrementable}.\n\n\\begin{lstlisting}\nContinuous : ∀ b d o → Set\nContinuous b d o = (xs : Numeral b d o) → Incrementable xs\n\\end{lstlisting}\n\nBounded systems are deemed to be incontinuous because there are no successor\nafter the maximum numeral.\n\n\\begin{lstlisting}\nBounded⇒¬Continuous : ∀ {b d o}\n    → Bounded b d o\n    → ¬ (Continuous b d o)\nBounded⇒¬Continuous (xs , max) claim\n    = contradiction (claim xs) (Maximum⇒¬Incrementable xs max)\n\\end{lstlisting}\n\nSince systems of \\lstinline|NullBase| and \\lstinline|AllZeros| are all bounded,\nthey cannot be continuous. We will only be concerning ourselves with systems of\n\\lstinline|Proper| in the rest of the section.\n\nSuppose we want to determine if a system of \\lstinline|Proper| is continuous,\nwe can examine \\textit{every} numeral of that system with the view function\n\\lstinline|nextView|.\nIf \\textit{all} numerals are sorted as \\lstinline|Interval| and\n\\lstinline|UngappedEndpoint|, then the system is continuous;\nif \\textit{any} numeral is sorted as \\lstinline|GappedEndpoint|,\nthen the system must not be continuous.\n\nBut it is impossible to go through every numeral because we know that systems\nof \\lstinline|Proper| are non-exhaustive.\nTherefore we need another way of deciding the continuity of a system.\n\n\\subsection{Look no further than the Gaps}\n\nIn the section~\\ref{next}, we have propositions for describing gaps.\n\n\\begin{lstlisting}\nGapped#0 : ∀ b d o → Set\nGapped#0 b d o = suc d < carry o * suc b\n\nGapped#N : ∀ b d o\n    → (xs : Numeral (suc b) (suc d) o)\n    → (proper : 2 ≤ suc (d + o))\n    → Set\nGapped#N b d o xs proper\n    = suc d < (⟦ next-numeral-Proper xs proper ⟧ ∸ ⟦ xs ⟧) * suc b\n\nGapped : ∀ {b d o}\n    → (xs : Numeral (suc b) (suc d) o)\n    → (proper : 2 ≤ suc (d + o))\n    → Set\nGapped {b} {d} {o} (x ∙)    proper = Gapped#0 b d o\nGapped {b} {d} {o} (x ∷ xs) proper = Gapped#N b d o xs proper\n\\end{lstlisting}\n\n\\lstinline|Gapped#0| describes the first gap of a system, whereas\n\\lstinline|Gapped#N| covers the rest.\nCompared to \\lstinline|Gapped#N|, the definition of \\lstinline|Gapped#0| is much\nless demanding because it only depends on the three indices, making it really\neasy to be determined.\n\n\\subsection{When the First Gap is Open}\n\nLet's start with the easier case, we can know for sure that when the first gap\n\\lstinline|Gapped#0| is open, the system must not be continuous.\n\n\\begin{center}\n    \\begin{adjustbox}{max width=\\textwidth}\n        \\begin{tikzpicture}\n            % the frame\n            \\path[clip] (0, -2) rectangle (16, 2);\n            % the spine\n            \\draw[ultra thick] (0,0) -- (16,0);\n            % the body\n\n            \\foreach \\i in {1,...,7} {\n                \\draw[ultra thick, fill=white] ({\\i+0.05}, -0.2) rectangle ({\\i+0.95}, +0.2);\n            };\n            \\draw[ultra thick, fill=black] (8.05, -0.2) rectangle (8.95, +0.2);\n\n            \\foreach \\i in {12,...,16} {\n                \\draw[ultra thick, fill=white] ({\\i+0.05}, -0.2) rectangle ({\\i+0.95}, +0.2);\n            };\n            \\draw[->, ultra thick] (8.5,1) -- (8.5,0.5)\n                node at (8.5, 1.3) {the first endpoint};\n\n            % gap\n            \\draw[ultra thick, loosely dotted] (9, -0.2) -- (9,-1);\n            \\draw[ultra thick, loosely dotted] (12,-0.2) -- (12,-1);\n            \\draw[ultra thick, decoration={brace,mirror},decorate]\n                (9, -1) -- (12,-1);\n            \\node at (10.5, -1.3) {the first gap};\n        \\end{tikzpicture}\n    \\end{adjustbox}\n\\end{center}\n\nWe construct the first endpoint with the greatest digit.\n\n\\begin{lstlisting}\nfirst-endpoint : ∀ b d o → Numeral (suc b) (suc d) o\nfirst-endpoint b d o = greatest-digit d ∙\n\\end{lstlisting}\n\nThe first endpoint is proven to be not incrementable.\n\n\\begin{lstlisting}\nfirst-endpoint-¬Incrementable : ∀ {b d o}\n    → (proper : 2 ≤ suc (d + o))\n    → (gapped : Gapped#0 b d o)\n    → ¬ (Incrementable (first-endpoint b d o))\nfirst-endpoint-¬Incrementable {b} {d} {o} proper gapped\n    with nextView (first-endpoint b d o) proper\nfirst-endpoint-¬Incrementable proper gapped\n    | Interval b d o ¬greatest\n    = contradiction (greatest-digit-is-the-Greatest d) ¬greatest\nfirst-endpoint-¬Incrementable proper gapped\n    | GappedEndpoint b d o greatest _\n    = GappedEndpoint⇒¬Incrementable\n        (first-endpoint b d o) greatest proper gapped\nfirst-endpoint-¬Incrementable proper gapped\n    | UngappedEndpoint b d o greatest ¬gapped\n    = contradiction gapped ¬gapped\n\\end{lstlisting}\n\nThe first endpoint can then be used as an counter example of the continuity of\nthe system.\n\n\\begin{lstlisting}\nGapped#0⇒¬Continuous : ∀ {b d o}\n    → (proper : 2 ≤ suc (d + o))\n    → (gapped : Gapped#0 b d o)\n    → ¬ (Continuous (suc b) (suc d) o)\nGapped#0⇒¬Continuous {b} {d} {o} proper gapped cont\n    = contradiction\n        (cont (first-endpoint b d o))\n        (first-endpoint-¬Incrementable proper gapped)\n\\end{lstlisting}\n\nNow we can see if a system is incontiuous just by checking the first gap.\n\n\\begin{lstlisting}\nContinuous-Proper : ∀ b d o\n    → (proper : 2 ≤ suc (d + o))\n    → Dec (Continuous (suc b) (suc d) o)\nContinuous-Proper b d o proper with Gapped#0? b d o\nContinuous-Proper b d o proper | yes gapped#0\n    = no (Gapped#0⇒¬Continuous proper gapped#0)\nContinuous-Proper b d o proper | no ¬gapped#0\n    = ?\n\\end{lstlisting}\n\nHowever, when the first gap is closed, it is uncertain whether the given system\nwill be continuous.\n\n\\subsection{When the First Gap is Closed}\n\nIf we can prove that \\lstinline|Gapped#N| \\textbf{implies} \\lstinline|Gapped#0|,\nthen by contraposition, we can know that all gap of a system are closed if the\nfirst gap is also closed.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\nGapped#N⇒Gapped#0 : ∀ {b d o}\n    → (xs : Numeral (suc b) (suc d) o)\n    → (proper : 2 ≤ suc (d + o))\n    → Gapped#N b d o xs proper\n    → Gapped#0 b d o\nGapped#N⇒Gapped#0 xs proper gapped#N with nextView xs proper\nGapped#N⇒Gapped#0 xs proper gapped#N | Interval b d o ¬greatest =\n    start\n        suc (suc d)\n    ≤⟨ gapped#N ⟩\n        (⟦ next-numeral-Proper-Interval xs ¬greatest proper ⟧ ∸ ⟦ xs ⟧) * suc b\n    ≤⟨ *n-mono (suc b) (...next-numeral-Proper-Interval-lemma xs ¬greatest...) ⟩\n        (suc zero ⊔ o) * suc b\n    □)\nGapped#N⇒Gapped#0 (x ∙)    proper _ | GappedEndpoint b d o greatest gapped#0\n    = gapped#0\nGapped#N⇒Gapped#0 (x ∷ xs) proper _ | GappedEndpoint b d o greatest gapped#N\n    = Gapped#N⇒Gapped#0 xs proper gapped#N\nGapped#N⇒Gapped#0 xs proper gapped#N | UngappedEndpoint b d o greatest ¬gapped =\n    start\n        suc (suc d)\n    ≤⟨ gapped#N ⟩\n        (⟦ next-numeral-Proper-UngappedEndpoint xs greatest proper ¬gapped ⟧\n            ∸ ⟦ xs ⟧) * suc b\n    ≤⟨ *n-mono (suc b) (... next-numeral-Proper-UngappedEndpoint-lemma ...) ⟩\n        (suc zero ⊔ o) * suc b\n    □)\n\\end{lstlisting}\n\nWe can prove that, if the first gap is closed, then so do the rest of the gaps,\nby contraposition.\n\n\\begin{lstlisting}\n¬Gapped#0⇒¬Gapped : ∀ {b d o}\n    → (xs : Numeral (suc b) (suc d) o)\n    → (proper : 2 ≤ suc (d + o))\n    → ¬ (Gapped#0 b d o)\n    → ¬ (Gapped xs proper)\n¬Gapped#0⇒¬Gapped (x ∙)    proper ¬Gapped#0 = ¬Gapped#0\n¬Gapped#0⇒¬Gapped (x ∷ xs) proper ¬Gapped#0 = contraposition\n    (Gapped#N⇒Gapped#0 xs proper)\n    ¬Gapped#0\n\\end{lstlisting}\n\nWe can conclude that, if all gaps are closed,\nthen all numerals should be incrementable, therefore the system is continuous.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\n¬Gapped#0⇒Continuous : ∀ {b d o}\n    → (proper : 2 ≤ suc (d + o))\n    → (¬gapped : ¬ (Gapped#0 b d o))\n    → Continuous (suc b) (suc d) o\n¬Gapped#0⇒Continuous proper ¬gapped#0 xs with Incrementable? xs\n¬Gapped#0⇒Continuous proper ¬gapped#0 xs | yes incr = incr\n¬Gapped#0⇒Continuous proper ¬gapped#0 xs | no ¬incr = contradiction\n    (¬Gapped⇒Incrementable xs proper (¬Gapped#0⇒¬Gapped xs proper ¬gapped#0))\n    ¬incr\n\\end{lstlisting}\n\n\\subsection{Determining Continuity}\n\nFinally, we can decide if a system is continuous.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\nContinuous-Proper : ∀ b d o\n    → (proper : 2 ≤ suc (d + o))\n    → Dec (Continuous (suc b) (suc d) o)\nContinuous-Proper b d o proper with Gapped#0? b d o\nContinuous-Proper b d o proper | yes gapped#0\n    = no (Gapped#0⇒¬Continuous proper gapped#0)\nContinuous-Proper b d o proper | no ¬gapped#0\n    = yes (¬Gapped#0⇒Continuous proper ¬gapped#0)\n\nContinuous? : ∀ b d o → Dec (Continuous b d o)\nContinuous? b d o with numView b d o\nContinuous? _ _ _ | NullBase d o = no (Bounded⇒¬Continuous (Bounded-NullBase d o))\nContinuous? _ _ _ | NoDigits b o = yes (λ xs → NoDigits-explode xs)\nContinuous? _ _ _ | AllZeros b = no (Bounded⇒¬Continuous (Bounded-AllZeros b))\nContinuous? _ _ _ | Proper b d o proper = Continuous-Proper b d o proper\n\\end{lstlisting}\n\n\\subsection{Successor Function}\n\nSince the proof of \\lstinline|Continuous| is essentially a successor function,\nwe can use it to increment a numeral.\n\n\\begin{lstlisting}\n1+ : ∀ {b d o}\n    → {cont : True (Continuous? b d o)}\n    → (xs : Numeral b d o)\n    → Numeral b d o\n1+ {cont = cont} xs = proj₁ (toWitness cont xs)\n\\end{lstlisting}\n\nA numeral taking these two routes should result in the same {{\\lstinline|ℕ|}}.\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|Numeral b d o|} & {\\lstinline|Numeral b d o|} \\\\\n                {\\lstinline|ℕ|} & {\\lstinline|ℕ|} \\\\\n            };\n      \\path[-stealth]\n            (m-1-1)\n                edge node [left] {{\\lstinline|⟦_⟧|}} (m-2-1)\n                edge node [above] {{\\lstinline|+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|⟦_⟧|}} (m-2-2);\n    \\end{tikzpicture}\n\\end{center}\n\nThe proof also comes for free from \\lstinline|Continuous| as part of its\ndefinition.\n\n\\begin{lstlisting}\n1+-toℕ : ∀ {b d o}\n    → {cont : True (Continuous? b d o)}\n    → (xs : Numeral b d o)\n    → ⟦ 1+ {cont = cont} xs ⟧ ≡ suc ⟦ xs ⟧\n1+-toℕ {cont = cont} xs = proj₂ (toWitness cont xs)\n\\end{lstlisting}\n\n% \\subsection{Observations}\n%\n% \\lstinline|Numeral 4 3 0| is a quaternary (base-4) system with only 3 digits:\n% $0, 1, 2$.\n% Suppose we plot all values of numerals of \\lstinline|Numeral 4 3 0| onto a number\n% line, it would have a series of gaps that are ever widening as shown in the figure below.\n%\n% \\begin{center}\n%     \\begin{adjustbox}{max width=\\textwidth}\n%         \\begin{tikzpicture}[spy using outlines]\n%\n%             \\foreach \\j in {0,...,2} {\n%                 \\foreach \\i in {0,...,2} {\n%                     \\draw[fill=black] ({\\j*4 + \\i}, 0.5) rectangle ({\\j*4 + \\i + 0.75}, 0.75);\n%                 };\n%             };\n%\n%             \\draw[ultra thick] (0, 0) -- (16, 0);\n%\n%             % ticks\n%             \\foreach \\i in {0, ..., 64} {\n%                 \\draw[thick] ({\\i*0.25},0) -- ({\\i*0.25},-0.2);\n%             };\n%             \\foreach \\i in {0, ..., 16} {\n%                 \\pgfmathsetmacro{\\j}{int(\\i * 4)}\n%                 \\draw[thick] (\\i,0) -- (\\i,-0.3)\n%                     node[below, scale=0.8] {\\j};\n%             };\n%\n%             % spies\n%             \\spy[rectangle,lens={scale=8}, size=5cm, connect spies]\n%                 on (0.875,0.75) in node [left] at (5.25,5);\n%             \\spy[rectangle,lens={scale=2}, size=5cm, connect spies]\n%                 on (3.375,0.75) in node [left] at (10.5,5);\n%\n%             % gaps\n%             \\draw[ultra thick, loosely dotted] (1.75,5) -- (1.75,6);\n%             \\draw[ultra thick, loosely dotted] (3.75,5) -- (3.75,6);\n%             \\draw[ultra thick, decoration={brace,mirror},decorate]\n%                 (3.75, 6) -- (1.75, 6);\n%             \\node at (2.75, 6.5) {$1$};\n%             \\draw[ultra thick, loosely dotted] (6.75,5) -- (6.75,6);\n%             \\draw[ultra thick, loosely dotted] (9.25,5) -- (9.25,6);\n%             \\draw[ultra thick, decoration={brace,mirror},decorate]\n%                 (9.25, 6) -- (6.75,6);\n%             \\node at (8, 6.5) {$5$};\n%             \\draw[ultra thick, loosely dotted] (10.75, 0.5) -- (10.75,6);\n%             \\draw[ultra thick, loosely dotted] (16,0.5) -- (16,6);\n%             \\draw[ultra thick, decoration={brace,mirror},decorate]\n%                 (16, 6) -- (10.75,6);\n%             \\node at (13.375, 6.5) {$21$};\n%\n%         \\end{tikzpicture}\n%     \\end{adjustbox}\n% \\end{center}\n%\n% \\subsection{The Relation between Gaps}\n%\n% In the section~\\ref{next}, we have propositions for describing these gaps.\n%\n% \\begin{lstlisting}\n% Gapped#0 : ∀ b d o → Set\n% Gapped#0 b d o = suc d < carry o * suc b\n%\n% Gapped#N : ∀ b d o\n%     → (xs : Numeral (suc b) (suc d) o)\n%     → (proper : 2 ≤ suc (d + o))\n%     → Set\n% Gapped#N b d o xs proper\n%     = suc d < (⟦ next-numeral-Proper xs proper ⟧ ∸ ⟦ xs ⟧) * suc b\n%\n% Gapped : ∀ {b d o}\n%     → (xs : Numeral (suc b) (suc d) o)\n%     → (proper : 2 ≤ suc (d + o))\n%     → Set\n% Gapped {b} {d} {o} (x ∙)    proper = Gapped#0 b d o\n% Gapped {b} {d} {o} (x ∷ xs) proper = Gapped#N b d o xs proper\n% \\end{lstlisting}\n%\n% \\lstinline|Gapped#0| only describes the first gap of a system, whereas the rest\n% of the gaps are covered by \\lstinline|Gapped#N|.\n% Compared to \\lstinline|Gapped#N|, the definition of \\lstinline|Gapped#0| is much\n% less demanding because it only depends on the three indices, making it really\n% easy to be determined.\n\n\n\\end{document}\n", "meta": {"hexsha": "a514b710bcb443fe16b2c09156b778019b668f6a", "size": 13818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/tex/constructions/continuous.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/continuous.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/continuous.tex", "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "avg_line_length": 35.984375, "max_line_length": 96, "alphanum_fraction": 0.6100738168, "num_tokens": 4670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6633351473716875}}
{"text": "% Created 2021-09-09 Thu 13:21\n% Intended LaTeX compiler: pdflatex\n\\documentclass[presentation]{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{awesomebox}\n\\usepackage{booktabs}\n\\usepackage{placeins}\n\\usepackage{siunitx}\n\\usepackage{minted}\n\\usetheme[progressbar=frametitle,block=fill]{metropolis}\n\\usetheme{default}\n\\author{\\emph{Tejaswin Parthasarathy}, Mattia Gazzola}\n\\date{\\today}\n\\title{Scientific computing in Python}\n\\subtitle{ME447: Comp. Design \\& Dyn. of Soft Syst}\n\\hypersetup{\n pdfauthor={\\emph{Tejaswin Parthasarathy}, Mattia Gazzola},\n pdftitle={Scientific computing in Python},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 28.0.50 (Org mode 9.3.6)},\n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{\\texttt{numpy}}\n\\label{sec:orga56d279}\n\\begin{frame}[label={sec:org30f73da},fragile]{\\texttt{numpy} package \\footnote{\\href{https://www.numpy.org/}{numpy}}}\n \\begin{itemize}\n\\item High-performance vector, matrix and higher-dimensional data structures for\n\\texttt{Python}\n\\item Shares a lot of similarity and differences (syntactically and semantically)\nwith \\texttt{MATLAB} \\footnote{\\href{https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html}{numpy for Matlab users}}\n\\item Vectors, matrices and higher-dimensional data sets are \\emph{(nd) arrays} in \\texttt{numpy}\n(there is also the \\texttt{matrix} class, but it is being phased out)\n\\item Standard import---\\texttt{import numpy as np}\n\\end{itemize}\n\\end{frame}\n\\begin{frame}[label={sec:org02caaad},fragile]{Simple array creation in \\texttt{numpy}}\n \\note{:B\\_note:\n\\begin{itemize}\n\\item Show the documentaion and how to browse it\n\\item Show as a demonstration\\ldots{}\n\\end{itemize}}\n\\begin{itemize}\n\\item \\texttt{v = np.array([1,2,3,4])} creates a vector (argument : list)\n\\item \\texttt{M = np.array([[1, 2], [3, 4]])} creates a matrix (argument : nested list)\n\\item \\texttt{type(v), type(M)} both return \\texttt{numpy.ndarray}\n\\item The difference lies in the \\alert{shape} seen using \\texttt{v.shape/M.shape}\\ldots{}\n\\item Alternatively use function \\texttt{np.shape(v)}\n\\item Arrays can also have different data types, seen using \\texttt{v.dtype}\n\\begin{itemize}\n\\item \\texttt{npint32}, \\texttt{np.float32}, \\texttt{np.float64} (default)\\ldots{}\n\\end{itemize}\n\\item \\texttt{M = np.array([[1, 2], [3, 4]], dtype=int)}\n\\end{itemize}\n\\end{frame}\n\\begin{frame}[label={sec:org06896aa},fragile]{Array generating functions}\n \\note{:B\\_note:\n\\begin{itemize}\n\\item Show as a demonstration\\ldots{}\n\\end{itemize}}\n\\begin{itemize}\n\\item \\texttt{v = np.arange(0,11,2)} gives ranges similar to \\texttt{Python's range}\n\\item \\texttt{v = np.arange(0, 11, 0.1)} is also valid! (gives step of 0.1)\n\\item \\texttt{v = np.linspace(0, 1, 3)} creates a linearly spaced vector [0, 0.5, 1.]\n\\item Also have \\texttt{logspace, geomspace} for other progressions\n\\item Multidimensional array creation using \\texttt{meshgrid, ndgrid} and others\n\\item Other useful ones are \\texttt{ones} (which generates matrix with all 1), \\texttt{zeros}\n(similar) and \\texttt{eye} (identity matrix)\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgc25f801},fragile]{Random numbers}\n \\note{:B\\_note:\n\\begin{itemize}\n\\item Show as a demonstration\n\\item np.random.rand(5,5)\\ldots{}same syntax for randn too..\n\\item np.random.randint(1,5,size=(2,4))\n\\end{itemize}}\n\\begin{itemize}\n\\item We'll work extensively with random numbers, so let's see what \\texttt{numpy} has\nto offer\n\\item \\texttt{np.random.rand(<shape>)} gives random floats from uniform dist. in [0, 1)\n\\item \\texttt{np.random.randn(<shape>)} gives random floats from univariate normal\ndist. with \\(\\mu = 0\\) and \\(\\sigma = 1\\)\n\\item \\texttt{np.random.randint(low, high, size)} gives random ints from discrete uniform dist.\nin \\texttt{[low, high)}\n\\end{itemize}\n\\end{frame}\n\\begin{frame}[label={sec:org5da2caf},fragile]{Indexing}\n \\note{:B\\_note:\n\\begin{itemize}\n\\item Show as a demonstration of all\n\\item A = np.random.randn(5,5); A[2:3,:] is slicing\n\\item Fancy indexing: idx\\_rows = [1,5]; idx\\_cols = [1,2,4]; A[idx\\_rows, idx\\_cols]\n\\item mask\\_row = [True, False, False, False, True]; A[mask\\_row]. Compare with\nA[idx\\_rows, :] above\n\\end{itemize}}\n\\begin{itemize}\n\\item Slicing works for \\texttt{numpy} arrays too, across any dimension!\n\\item Fancy indexing\n\\begin{itemize}\n\\item Extends slicing to be more useful + practical\n\\end{itemize}\n\\item Masking\n\\begin{itemize}\n\\item Bools to \\emph{mask} what is not necessary\n\\item Useful with conditional functions (e.g. \\texttt{x < 5})\n\\end{itemize}\n\\item Reshaping using \\texttt{np.reshape} changes index access\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}[label={sec:org3b90a47},fragile]{Linear Algebra}\n \\note{:B\\_note:\n\\begin{itemize}\n\\item In the demo construct structure A with 1:25 using \\texttt{A =\n      np.linspace(1.0,25.0,25)} and then do \\texttt{A = A.reshape(5,5)}\n\\item Use \\texttt{np.arange} for constructing \\texttt{v=np.arange(0, 5)}\n\\item Show that \\texttt{A*v} does element wise onlt\n\\end{itemize}}\n\n\\begin{itemize}\n\\item Scalar operations on an array \\texttt{A}\n\\begin{itemize}\n\\item \\texttt{A + 2}, \\texttt{A * 2} , \\texttt{A ** 2} \\ldots{}\n\\end{itemize}\n\\item Element wise operations on an array \\texttt{A}\n\\begin{itemize}\n\\item \\texttt{A * A}, \\texttt{A / A} \\ldots{}\n\\item What do you get when you do \\texttt{A*v}? \\alert{DEMO}\n\\end{itemize}\n\\item Matrix algebra on an array \\texttt{A}\n\\begin{itemize}\n\\item \\texttt{np.dot(A, v)} or \\texttt{A.dot(v)} or simply \\texttt{A@v}\n\\item Shape needs to be compliant! \\texttt{numpy} also has broadcasts that is useful,\nbut is confusing and so is not covered here \\ldots{}\n\\end{itemize}\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgebf8dcf},fragile]{Practice}\n \\begin{block}{Please attempt}\n\\begin{itemize}\n\\item \\texttt{12\\_numpy\\_library.ipynb}\n\\item For a more extensive tutorial: \\url{https://github.com/donnemartin/data-science-ipython-notebooks\\#numpy}\n\\end{itemize}\n\\end{block}\n\\end{frame}\n\\note{:B\\_note:\n\\begin{itemize}\n\\item Access to \\url{https://github.com/donnemartin/data-science-ipython-notebooks}\nespecially the numpy section\n\\end{itemize}}\n\n\\section{Genetic algorithm using \\texttt{numpy}}\n\\label{sec:org9f358bb}\n\\begin{frame}[label={sec:orgec5522e}]{Schematic}\n\\footnotesize\n\\begin{figure}[htbp]\n\\centering\n\\includegraphics[width=1.0\\textwidth]{images/ga_schematic.png}\n\\caption{Schematic of an evolutionary search algorithm}\n\\end{figure}\n\\end{frame}\n\\begin{frame}[label={sec:org71af0f5}]{Let's use GA to solve\\ldots{}}\n\\begin{block}{Problem statement}\nMaximize the function \\(f(\\mathbf{x}) = \\sum_{i=1}^{6} w_i x_i\\) for a given\nset of weights \\(w_i\\), with the constraints that \\(x_i \\; \\in \\; [-4,4] \\;\n   \\forall \\; i\\).\n\n\\(\\therefore\\) Domain \\(\\mathbb{D}\\) of the search is \\(\\mathbb{D}:= [-4,4]^6\\).\n\nOptimization problem: \\(\\left(\\mathbb{D}, \\mathbb{R} , \\mathbf{f}, \\geq \\right)\\).\n\\end{block}\n\\end{frame}\n\\begin{frame}[label={sec:org9f1ea4f},fragile]{Representation?}\n \\begin{block}{Bitvector? Float vector?}\nPick a representation for \\(\\mathbf{x}\\)\n\\end{block}\nIn any case, \\texttt{np.array} seems useful. You can make a bitvector using\n\\texttt{np.array(..., dtype=bool)}\n\\end{frame}\n\\begin{frame}[label={sec:orgfdc435f},fragile]{GA parameters}\n \\begin{block}{Decisions}\n\\begin{itemize}\n\\item How long are you going to run your campaign? (Number of generations)\n\\item How many solutions will you consider in one step? (Population size)\n\\begin{itemize}\n\\item If so, whats your degree of freedom? (How many numbers should you change)\n\\end{itemize}\n\\end{itemize}\n\\end{block}\nAll these are just floating point numbers\n\n\\begin{block}{Initialization}\n\\begin{itemize}\n\\item How will you initialize your population?\n\\end{itemize}\n\\end{block}\n\nConsider the \\texttt{np.random} module\\ldots{}\n\\end{frame}\n\n\\begin{frame}[label={sec:org209e4d2}]{Fitness assignment}\n\\begin{block}{What's your fitness?}\n\\begin{itemize}\n\\item Feed in objective function directly?\n\\item Competitive fitness between members?\n\\end{itemize}\n\\end{block}\nUse matrix-vector products and/or slicing to determine fitness\n\\end{frame}\n\\begin{frame}[label={sec:org4cfb15a},fragile]{Selection (for variation)}\n \\begin{block}{Stochastic / Deterministic}\n\\begin{itemize}\n\\item How many parents do you want to select? Or do you want to leave it up to\nthe algorithm?\n\\item Deterministic / Stochastic?\n\\begin{itemize}\n\\item Remember that stochastic selection is usally used for variation, but\nwe do not need to do it necessarily\\ldots{}\n\\end{itemize}\n\\item Competitive fitness between members?\n\\begin{itemize}\n\\item It's definitely a good exercise to learn \\texttt{numpy}\n\\end{itemize}\n\\end{itemize}\n\\end{block}\n\\texttt{np.argsort/np.sort} is very useful to sort/rank stuff, indexing magic\nneeded. The brave souls doing SUS may also need \\texttt{searchsorted, cumsum, sum}\nand so on (familiarize yourself with the \\texttt{numpy} documentation)\n\\end{frame}\n\\begin{frame}[label={sec:org53f9b5f},fragile]{Variation}\n \\begin{block}{Recombination}\n\\begin{itemize}\n\\item What will be your \\(p_c\\), the rate of recombination?\n\\item Is there a limit on the number of offspring you generate?\n\\item How to achieve crossover for your representation?\n\\item Uniform crossover? N-point crossover? \\ldots{}\n\\item In which gene do you want to effect crossover?\n\\end{itemize}\n\\end{block}\nExtensively use slicing and index magic. You may use any algorithm (say\nusing the \\texttt{\\%} operator) to select parents.\n\\end{frame}\n\\begin{frame}[label={sec:org4f36e15},fragile]{Variation}\n \\begin{block}{Mutation}\n\\begin{itemize}\n\\item What will be your \\(p_m\\), the rate of mutation?\n\\item How do you want to achieve mutation? Flip bits? Number exchange? Random numbers?\n\\item Do you want to mutate the entire vector? Or only one gene?\n\\end{itemize}\n\\end{block}\n\\texttt{np.random} once again. You can also use other \\texttt{np} tools\n\\end{frame}\n\\begin{frame}[label={sec:orge82c7b6}]{Selection (environmental)}\n\\begin{block}{Constraints / Deterministic schemes}\n\\begin{itemize}\n\\item What about constraints of \\(-4 \\leq x_i \\leq 4\\)?\n\\item How do you select individuals (chromosomes) from the population to\npropogate to the next generation? Objective function alone?\n\\item If so what scheme do you want to use? \\(\\left( \\mu, \\lambda \\right)\\),\n\\(\\left( \\mu + \\lambda \\right)\\),\\ldots{}?\n\\end{itemize}\n\\end{block}\nAll the tools seen above apply to this case too\\ldots{}\n\\end{frame}\n\\begin{frame}[label={sec:orge229e9c}]{Putting it all together}\n\\begin{block}{Convergence, performance, diagnostics}\n\\begin{itemize}\n\\item Now that we have all the \\emph{modules}, how do they perform when you put\nthem together?\n\\item How do we track performance as generations progress?\n\\item Can you think of some diagnostics that may well-characterize the scheme\nthat you have just developed?\n\\end{itemize}\n\\end{block}\n\\end{frame}\n\\begin{frame}[label={sec:org1bf18c1}]{Practice}\n\\begin{block}{Exploration}\n\\begin{itemize}\n\\item Explore representations, parameters and all other design choices that you\nmade\n\\item You will essentially be doing a scaled up version of this exercise for\nyour project 1\n\\end{itemize}\n\\end{block}\n\\end{frame}\n\\end{document}\n", "meta": {"hexsha": "41c735a51332fd23ccf830270860db02b01c1ae3", "size": 11401, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/02_scicomp/02_scicomp.tex", "max_stars_repo_name": "tp5uiuc/soft_systems_course", "max_stars_repo_head_hexsha": "c9585c8fdc7fbc2fd539b4a1ed5e3b43a889a1ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-12T21:54:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T09:31:40.000Z", "max_issues_repo_path": "lectures/02_scicomp/02_scicomp.tex", "max_issues_repo_name": "tp5uiuc/soft_systems_course", "max_issues_repo_head_hexsha": "c9585c8fdc7fbc2fd539b4a1ed5e3b43a889a1ce", "max_issues_repo_licenses": ["MIT"], "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/02_scicomp/02_scicomp.tex", "max_forks_repo_name": "tp5uiuc/soft_systems_course", "max_forks_repo_head_hexsha": "c9585c8fdc7fbc2fd539b4a1ed5e3b43a889a1ce", "max_forks_repo_licenses": ["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.3803278689, "max_line_length": 128, "alphanum_fraction": 0.7421278835, "num_tokens": 3577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174789, "lm_q2_score": 0.8688267677469951, "lm_q1q2_score": 0.6633351398675315}}
{"text": "\\chapter{Natural Deduction For Propositional Logic}\n\\label{chapter:propositional-deduction}\n\\marginurl{%\n  Natural Deduction:\\\\\\noindent\n  Introduction to Mathematical Logic \\#3\n}{youtu.be/PfVafyptFtM}\n\nThere are two issues with thr method discussed in\n\\Cref{chapter:propositional-truth}: first to check a semantic implication \nwe need to consider \\textbf{all} possible values of the variables, secondly this\nmethod does not look like the proofs we use in mathematics.\n\nIn this chapter we introduce the way to check semantic implications that looks \nmore similar to real-life proofs.\nLet us illustrate this using the following example. Imagine that we know that\n$\\lnot q$, $p \\limplies q$. Using the contraposition argument and modus ponens\nwe may derive $\\lnot p$. Indeed, by contraposition we may conclude that \n$\\lnot q \\limplies \\lnot p$ and modus ponens implies that $\\lnot p$ is true\nsince $\\lnot q$ is true.\n\nIn other words, we can combine several tautologies to prove another tautology.\nApparently it is enough to fix some small number of tautologies to derive all\nother tautologies, we call these tautologies ``rules''. There are several ways\nto write such proofs, we are going to use Fitch notation for natural deduction.\nIn this notation any proof is written in several rows, each row in a Fitch-style\nproof is either:\n\\begin{itemize}\n  \\item an assumption or subproof assumption.\n  \\item a sentence justified by the citation of\n    \\begin{enumerate*}[label=(\\roman*)]\n      \\item a rule of inference and\n      \\item the prior line or lines of the proof that license that rule.\n    \\end{enumerate*}\n\\end{itemize}\nWe say that there is a natural deduction derivation of $\\phi$ from $\\psi_1$,\n\\dots, $\\psi_k$. If there is a Fitch-style proof starting with the assumptions\n$\\psi_1$, \\dots, $\\psi_k$, and finishes with the formula $\\phi$.\nUsing this scheme we may write the argument we just mentioned as follows.\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {\\lnot q}\n    \\hypo {2} {p \\limplies q}\n    \\have {3} {\\lnot q \\limplies \\lnot p} \\by{contraposition}{2}\n    \\have {4} {\\lnot p} \\by{modus ponens}{1, 3}\n  \\end{nd}\n$\n\n\\noindent In the rest of the section we are going to list all the rules we use.\n\n\\paragraph{Conjunctions.}\nIn order to introduce a conjunction we can use the following rule.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {A}\n    \\have [n] {3} {B}\n    \\have [~] {5} {A \\land B} \\ai{1, 3}\n  \\end{nd}\n\\]\nThis rule corresponds to the tautology $(A \\land B) \\limplies (A \\land B)$.\n\nIn order to eliminate conjunctions we can use the following two rules.\n\\begin{center}\n  \\begin{tabular}{c c}\n    $\\begin{nd}\n      \\have [m] {1} {A \\land B}\n      \\have [~] {3} {A} \\ae{1}\n    \\end{nd}$\n    &\n    $\\begin{nd}\n      \\have [m] {1} {A \\land B}\n      \\have [~] {3} {B} \\ae{1}\n    \\end{nd}$\n  \\end{tabular}\n\\end{center}\nThese rules correspond to the tautologies $(A \\land B) \\limplies A$ and\n$(A \\land B) \\limplies B$.\n\n\\paragraph{Disjuctions.}\nIn order to introduce a disjunction we can use the following two rules.\n\\begin{center}\n  \\begin{tabular}{c c}\n    $\\begin{nd}\n      \\have [m] {1} {A}\n      \\have [~] {3} {A \\lor B} \\oi{1}\n    \\end{nd}$\n    &\n    $\\begin{nd}\n      \\have [m] {1} {A}\n      \\have [~] {3} {B \\lor A} \\oi{1}\n    \\end{nd}$\n  \\end{tabular}\n\\end{center}\nThese rules correspond to the tautologies $A \\limplies (A \\lor B)$ and\n$A \\limplies (B \\lor A)$.\n\nIn order to eliminate a disjunction we can use the following rule.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {A \\lor B}\n    \\open\n      \\hypo [i] {3} {A}\n      \\have[j] {5} {C}\n    \\close\n    \\open\n      \\hypo [k] {6} {B}\n      \\have[l] {8} {C}\n    \\close\n    \\have[~] {9} {C} \\oe{1, 3-5, 6-8}\n  \\end{nd}\n\\]\nThis rule corresponds to the tautology\n$\\bigl( (A \\lor B) \\land (A \\limplies C) \\land (B \\limplies C) \\bigr)\n\\limplies C$.\n\n\\paragraph{Implications.}\nIn order to introduce an implication we can use the following two rules.\n\\[\n  \\begin{nd}\n    \\open\n      \\hypo [i] {3} {A}\n      \\have[j] {5} {B}\n    \\close\n    \\have[~] {9} {A \\limplies B} \\ii{3-5}\n  \\end{nd}\n\\]\nThis rule corresponds to the tautology\n$(A \\limplies B) \\limplies (A \\limplies B)$.\n\nIn order to eliminate an implication we can use the following rule.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {A \\limplies B}\n    \\have [n] {2} {A}\n    \\have[~] {9} {B} \\ie{1, 2}\n  \\end{nd}\n\\]\nThis rule corresponds to the tautology\n$\\bigl( (A \\limplies B) \\land A \\bigr)\n\\limplies B$.\n\n\\paragraph{Negations.}\nIn order to introduce a negation we can use the following two rules ($\\perp$ is\na special symbol representing a false statement).\n\\[\n  \\begin{nd}\n    \\open\n      \\hypo [i] {3} {A}\n      \\have[j] {5} {\\perp}\n    \\close\n    \\have[~] {9} {\\lnot A} \\ni{3-5}\n  \\end{nd}\n\\]\nThis rule corresponds to the tautology\n$\\bigl( A \\limplies \\perp \\bigr)\n\\limplies \\lnot A$.\n\nIn order to eliminate a negation we can use the following rule.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {A}\n    \\have [n] {2} {\\lnot A}\n    \\have[~] {9} {\\perp} \\ne{1, 2}\n  \\end{nd}\n\\]\nThis rule corresponds to the tautology\n$\\bigl( A \\land \\lnot A \\bigr)\n\\limplies \\perp$.\n\n\\paragraph{Truths and falsities.}\nAdditionally, we have the following two rules.\n\\begin{center}\n  \\begin{tabular}{c c}\n    $\\begin{nd}\n      \\have [m] {1} {\\perp}\n      \\have [~] {3} {A} \\be{1}\n    \\end{nd}$\n    &\n    $\\begin{nd}\n      \\open\n        \\hypo [i] {3} {\\lnot A}\n        \\have[j] {5} {\\perp}\n      \\close\n      \\have[~] {9} {A} \\by{IP}{3, 5}\n    \\end{nd}$\n  \\end{tabular}\n\\end{center}\n\n\\marginurl{%\n  An online tool to check natural deduction proofs\n}{proofs.openlogicproject.org/}\n\n\\begin{exercise}\n  Check that all the tautologies we mentioned are indeed tautologies.\n\\end{exercise}\n\n\\section{Examples of Derivations}\nIn this section we give several derivations using the rules we just introduced.\n\nFirst, we prove that if we know that $A \\limplies \\lnot A$ we can derive that\n$\\lnot A$.\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {A \\limplies \\lnot A}\n    \\open\n      \\hypo {2} {A}\n      \\have {3} {\\lnot A} \\ie{1, 2}\n      \\have {4} {\\perp} \\ne{2, 3}\n    \\close\n    \\have {5} {\\lnot A} \\ni{2-4}\n  \\end{nd}\n$\n\nAnother statement we are going to prove is that if\n$A \\limplies (A \\land \\lnot A)$ is true, then $\\lnot A$ is also true.\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {A \\limplies (A \\land \\lnot A)}\n    \\open\n      \\hypo {2} {A}\n      \\have {3} {A \\land \\lnot A} \\ie{1, 2}\n      \\have {4} {\\lnot A} \\ae{3}\n      \\have {5} {\\perp} \\ne{2, 4}\n    \\close\n    \\have {6} {\\lnot A} \\ni{2-5}\n  \\end{nd}\n$\n\nA bit more complicated is the proof of the law of excluded middle:\n$A \\lor \\lnot A$.\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {}\n    \\open\n      \\hypo {2} {\\lnot (A \\lor \\lnot A)}\n      \\open\n        \\hypo {3} {A}\n        \\have {4} {A \\lor \\lnot A} \\oi{3}\n        \\have {5} {\\perp} \\ne{2, 4}\n      \\close\n      \\have {6} {\\lnot A} \\ni{3-5}\n      \\have {7} {A \\lor \\lnot A} \\oi{6}\n      \\have {8} {\\perp} \\ne{2, 8}\n    \\close\n    \\have {9} {A \\lor \\lnot A} \\by{IP}{2-8}\n  \\end{nd}\n$\n\n\\section{Soundness and Completeness}\n\\marginurl{%\n  Soundness and Completeness:\\\\\\noindent\n  Introduction to Mathematical Logic \\#4\n}{youtu.be/9Utsppn-M_I}\nThe most important properties of the natural deduction are the following two\ntheorems.\n\n\\begin{theorem}[completeness of natural deductions]\n  Let $\\phi$ be a propositional formula. If $\\phi$ is a tautology, then\n  there is a proof of $\\phi$. Moreover if $\\Sigma$ is a finite set of\n  propositional formulas and $\\Sigma \\models \\phi$, then there is a\n  derivation of $\\phi$ from $\\Sigma$.\n\\end{theorem}\n\n\\begin{theorem}[soundness of natural deductions]\n  Let $\\phi$ be a propositional formula. If there is a proof of $\\phi$, then\n  $\\phi$ is a tautology. Moreover if $\\Sigma$ is a finite set of\n  propositional formulas and there is a derivation of $\\phi$ from $\\Sigma$,\n  then $\\Sigma \\models \\phi$.\n\\end{theorem}\n\n\nProofs of these two theorems are not that difficult but very technical. So\nwe will leave these theorems without proofs and just give some ideas behid \ntheir proofs.\n\n\\paragraph{Completeness of natural deductions.}\nThe proof of this statement exploits the following idea: if a propositional formula\nis a tautology, then we can verify this statement using the truth table. So\nthe proof may simply brute-force all the values of the variables of a formula\nand check that the formula is indeed true.\n\nFor example, consider a tautology $(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)$.\nThe proof of this tautology is as follows.\nFirst we derive $A \\lor \\lnot A$ and $B \\lor \\lnot B$, and we use these two\nformulas to consider cases using the elimination of disjunction.\n\n\\noindent$\n\\begin{nd}\n  \\hypo {1} {}\n  \\have {2} {A \\lor \\lnot A} \\by{the law of excluded middle}{}\n  \\have {3} {B \\lor \\lnot B} \\by{the law of excluded middle}{}\n\\end{nd}\n$\n\n\n\\noindent After that, we consider the case when $A$ and $B$ are both true. Note\nthat the assumption of the implication is false in this case. Thus, we just need\nto assume $\\lnot A \\land \\lnot B$, derive the contradiction, and derive\n$\\lnot (A \\lor B)$.\n\n\\noindent$\n\\begin{ndresume}\n  \\open\n    \\hypo {4} {A}\n    \\open\n      \\hypo {5} {B}\n      \\open\n        \\hypo {6} {\\lnot A \\land \\lnot B}\n        \\have {7} {\\lnot A} \\ae{6}\n        \\have {8} {\\perp} \\ne{4, 7}\n        \\have {9} {\\lnot (A \\lor B)} \\be{8}\n      \\close\n      \\have {10} {(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)} \\ii{6-9}\n    \\close\n\\end{ndresume}\n$\n\n\n\\noindent After that, we consider the case when $A$ is true but and $B$ is\nfalse. In this case, the assumption of the implication is also false; thus, the\nproof is the same as in the previous case.\n\n\\noindent$\n\\begin{ndresume}\n    \\open\n      \\hypo {11} {\\lnot B}\n      \\open\n        \\hypo {12} {\\lnot A \\land \\lnot B}\n        \\have {13} {\\lnot A} \\ae{12}\n        \\have {14} {\\perp} \\ne{4, 13}\n        \\have {15} {\\lnot (A \\lor B)} \\be{14}\n      \\close\n      \\have {16} {(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)} \\ii{6-9}\n    \\close\n    \\have {17} {(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)} \\oe{2, 5-10, 11-16}\n  \\close\n\\end{ndresume}\n$\n\n\\noindent The third case is when $A$ is false and $B$ is\ntrue. In this case the assumption of the implication is false again, thus the\nproof is the same as in the previous two cases.\n\n\\noindent$\n\\begin{ndresume}\n  \\open\n    \\hypo {18} {\\lnot A}\n    \\open\n      \\hypo {19} {B}\n      \\open\n        \\hypo {20} {\\lnot A \\land \\lnot B}\n        \\have {21} {\\lnot B} \\ae{20}\n        \\have {22} {\\perp} \\ne{19, 22}\n        \\have {23} {\\lnot (A \\lor B)} \\be{22}\n      \\close\n      \\have {24} {(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)} \\ii{20-23}\n    \\close\n\\end{ndresume}\n$\n\n\\noindent Finally, we consider the case when $A$ and $B$ are false. In this\ncase the assumption of the implication is true, and since the formula is a\ntautology and $\\lnot A \\land \\lnot B$ is true, we know that $\\lnot (A \\lor B)$\nis also true. Assume that $A \\lor B$ is true and note that this is impossible.\nThus using introduction of the negation we can prove the statement.\n\n\\noindent$\n\\begin{ndresume}\n    \\open\n      \\hypo {25} {\\lnot B}\n      \\open\n        \\hypo {26} {\\lnot A \\land \\lnot B}\n        \\open\n          \\hypo {27} {A \\lor B}\n          \\open\n            \\hypo {28} {A}\n            \\have {29} {\\perp} \\ne{18, 28}\n          \\close\n          \\open\n            \\hypo {30} {B}\n            \\have {31} {\\perp} \\ne{25, 30}\n          \\close\n          \\have {32} {\\perp} \\oe{27, 28-29, 30-31}\n        \\close\n        \\have {33} {\\lnot (A \\lor B)} \\ne{26-32}\n      \\close\n      \\have {39} {(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)} \\ii{26-33}\n    \\close\n    \\have {40} {(\\lnot A \\land \\lnot B) \\limplies \\lnot (A \\lor B)} \\oe{1, 3-17, 18-39}\n  \\close\n\\end{ndresume}\n$\n\n\\paragraph{Soundness of natural deductions.}\nThe idea behind the proof of the soundness is also simple. We just explain that\nevery line of the proof represent a tautology, including the last one. We\nillustrate this on the exaple of the proof of $A \\lor \\lnot A$. Recall that the\nproof of this tautology is the following.\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {}\n    \\open\n      \\hypo {2} {\\lnot (A \\lor \\lnot A)}\n      \\open\n        \\hypo {3} {A}\n        \\have {4} {A \\lor \\lnot A}\n        \\have {5} {\\perp}\n      \\close\n      \\have {6} {\\lnot A}\n      \\have {7} {A \\lor \\lnot A}\n      \\have {8} {\\perp}\n    \\close\n    \\have {9} {A \\lor \\lnot A}\n  \\end{nd}\n$\n\n\\begin{enumerate}\n  \\item The second line is just an assumption, so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies \\lnot (A \\lor \\lnot A)$.\n  \\item Line~3 is also an assumption so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies (A \\limplies A)$.\n  \\item Line~4 is a formula $A \\lor \\lnot A$ which we derived under assumptions\n    $\\lnot (A \\lor \\lnot A)$ and $A$, so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies (A \\limplies (A \\lor \\lnot A))$ (it is a\n    tautology since we replaced $A$ by $A \\lor \\lnot A$ in the conclusion of\n    the formula corresponding to Line~3).\n  \\item Line~5 is the formula $\\perp$ which we derived under assumptions\n    $\\lnot (A \\lor \\lnot A)$ and $A$, so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies (A \\limplies \\perp)$ (it is a\n    tautology since on Line~4 we explained that $\\lnot (A \\lor \\lnot A)\n    \\limplies (A \\limplies (A \\lor \\lnot A))$).\n  \\item Line~6 is a formula $\\lnot A$ which we derived under assumptions\n    $\\lnot (A \\lor \\lnot A)$, so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies \\lnot A$ (it is a\n    tautology since on Line~5 we explained that $A \\limplies \\perp$ under the\n    assumption $\\lnot (A \\lor \\lnot A)$).\n  \\item Line~7 is a formula $A \\lor \\lnot A$ which we derived under assumptions\n    $\\lnot (A \\lor \\lnot A)$, so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies (A \\lor \\lnot A)$ (it is a\n    tautology since on Line~6 we explained that $A$ under the\n    assumption $\\lnot (A \\lor \\lnot A)$).\n  \\item Line~8 is a formula $\\perp$ which we derived under assumptions\n    $\\lnot (A \\lor \\lnot A)$, so the corresponding tautology is\n    $\\lnot (A \\lor \\lnot A) \\limplies \\perp$ (it is a\n    tautology since on Line~6 we explained that $A \\lor \\lnot A$ under the\n    assumption $\\lnot (A \\lor \\lnot A)$).\n  \\item Finally, Line~9 is a formula $A \\lor \\lnot A$ (it is a tautology since\n    we proved that $\\lnot (A \\lor \\lnot A) \\limplies \\perp$ is a tautology)\n\\end{enumerate}\n\n\n\n\\begin{chapterendexercises}\n  \\exercise  Write a natural deduction derivation of $A \\lor C$ from\n    hypothesis $(A \\land B) \\lor C$.\n  \\exercise Write a natural deduction derivation of $B \\lor C$ from\n    hypothesis $A \\limplies B$ and $\\lnot A \\limplies C$.\n  \\exercise Write a natural deduction derivation of\n    $(W \\lor Y) \\limplies (X \\lor Z)$ from\n    hypotheses $W \\limplies X$ and $Y \\limplies Z$.\n  \\exercise Let us formulate the pigeonhole principle using propositional\n    formulas. Let\n    $V = \\set{x_{1, 1}, \\dots, x_{n + 1, 1}, x_{1, 2} \\dots, x_{n + 1, n}}$\n    (informally $x_{i, j}$ is true iff the $i$th pigeon is in the $j$th hole).\n    Consider the following propositional formulas on the variables from\n    $V$.\n    \\begin{itemize}\n      \\item $L_i$ ($i \\in [n + 1]$) is equal to $\\bigvee_{j = 1}^n x_{i, j}$.\n        (Informally this formula says that the $i$th pigeon is in a hole.)\n      \\item $R_j$ ($j \\in [n]$) is equal to\n        $\\biglor_{i_1 = 1}^{n + 1} \\biglor_{i_2 = i_1 + 1}^{n + 1}\n        (x_{i_1, j} \\land x_{i_2, j})$.\n        (Informally this formula says that there are two pigeons in the $j$th\n        hole.)\n      \\end{itemize}\n\n      Show that there is a natural deduction derivation of\n      $\\left(\n          \\bigland_{i = 1}^{n + 1} L_i\n        \\right)\n        \\limplies\n        \\left(\n          \\biglor_{i = 1}^{n} R_i\n        \\right)$.\n    \\exercise In this exercise we think about clauses as sets of literals so\n      the order of disjunctions and repetitions of literals are not important.\n      We say that a clause $C$ can be obtained from clauses $A$ and $B$\n      using the \\emph{resolution} rule if $C = A^\\prime \\lor B^\\prime$,\n      $A = x \\lor A^\\prime$, and $B = \\lnot x \\lor B^\\prime$, for some variable\n      $x$.\n\n      We say that a clause $C$ can be derived from clauses $A_1$, \\dots, $A_m$\n      using resolutions\n      if there is a sequence of clauses $D_1$, \\dots, $D_\\ell = C$ such that\n      each $D_i$\n      \\begin{itemize}\n        \\item is either obtained from clauses $D_j$ and $D_k$ for $j, k < i$ using the\n          \\emph{resolution} rule, or\n        \\item is equal to $A_j$ for some $j \\in [m]$, or\n        \\item is equal to $D_j \\lor E$ for some $j < i$ and a clause $E$.\n      \\end{itemize}\n\n      Show that if an empty clause $\\perp$ can be derived from clauses $A_1$,\n      \\dots, $A_m$ using the resolution rule, then $A_1$, \\dots, $A_m$\n      semantically imply $\\perp$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "0ea3abbd073468d376c784ca23436c8fe97d9136", "size": 16933, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_7/chapter_32_natural_deduction.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_7/chapter_32_natural_deduction.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_7/chapter_32_natural_deduction.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": 33.1369863014, "max_line_length": 87, "alphanum_fraction": 0.6223941416, "num_tokens": 5822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837581726991, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.6633351310268227}}
{"text": "\\subsection{Baire spaces}\\label{subsec:baire_spaces}\n\n\\begin{remark}\\label{rem:baire_categories}\n  René-Louis Baire introduced the concept of \\term{Baire categories} in 1899, almost 50 years before Samuel Eilenberg and Saunders MacLane introduced \\term{categories} in \\cite{EilenbergMacLane1945} (see \\fullref{sec:category_theory} for the latter).\n\n  Unfortunately, topology utilizes both concepts, so the word \\enquote{category} should be used with caution. To circumvent this, we use alternative terminology for Baire categories.\n\\end{remark}\n\n\\begin{definition}\\label{def:meager_set}\\mcite[def. 2.1]{Rudin1991Functional}\n  Any countable union of \\hyperref[def:topologically_dense_set/nowhere_dense]{nowhere dense sets} is called \\term{meager} or a \\term{first category set} (see \\fullref{rem:baire_categories} for terminology). If a set is not meager, we call it \\term{nonmeager} or a \\term{second category set}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:meager_set}\\mcite[43]{Rudin1991Functional}\n  \\hyperref[def:meager_set]{Meager sets} have the following basic properties (compare to \\fullref{thm:def:nowhere_dense}):\n  \\begin{thmenum}\n    \\thmitem{thm:def:meager_set/union} A countable union of meager sets is meager.\n    \\thmitem{thm:def:meager_set/subset} A subset of a meager set is meager.\n    \\thmitem{thm:def:meager_set/homeomorphism} The \\hyperref[def:homeomorphism]{homeomorphic} image of a set \\( A \\) is meager if and only if \\( A \\) itself is meager.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:meager_set/union} Follows from \\fullref{thm:countably_infinite_union_of_countably_infinite_sets}.\n  \\SubProofOf{thm:def:meager_set/subset} Fix a meager set \\( A \\) and let \\( B \\subseteq A \\). Then \\( A = \\bigcup_{k=1}^\\infty A_k \\) for some nowhere dense sets \\( A_1, A_2, \\ldots \\). By \\fullref{thm:def:nowhere_dense/subset}, the sets \\( A_1 \\cap B, A_2 \\cap B, \\ldots \\) are also nowhere dense. But\n  \\begin{equation*}\n    B\n    =\n    A \\cap B\n    =\n    \\left(\\bigcup_{k=1}^\\infty A_k \\right) \\cap B\n    \\reloset {\\ref{thm:boolean_algebra_of_subsets}} =\n    \\bigcup_{k=1}^\\infty (A_k \\cap B).\n  \\end{equation*}\n\n  Therefore, \\( B \\) is also nowhere dense.\n\n  \\SubProofOf{thm:def:meager_set/homeomorphism}\n  \\hfill\n  \\NecessitySubProof If \\( A \\) is meager, any homeomorphic image of \\( A \\) is meager by \\fullref{thm:def:function_image/union} and \\fullref{thm:def:nowhere_dense/homeomorphism}.\n  \\SufficiencySubProof If \\( f: X \\to Y \\) is a homeomorphism and \\( f(A) \\) is meager for some \\( A \\subseteq X \\), then \\( A \\) is the homeomorphic image of the meager set \\( f(A) \\) under \\( f^{-1} \\) and is thus meager.\n\\end{proof}\n\n\\begin{definition}\\label{def:baire_space}\n  A topological space is called a \\term{Baire space} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:baire_space/meager} Every nonempty open set is nonmeager.\n    \\thmitem{def:baire_space/dense} A countable intersection of dense sets is dense.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\EquivalenceSubProof{def:baire_space/meager}{def:baire_space/dense} Follows from \\fullref{thm:def:nowhere_dense/complement_dense} and \\fullref{thm:de_morgans_laws}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:open_subspace_of_baire_space_is_baire}\n  Every open subspace of a \\hyperref[def:baire_space]{Baire space} is a Baire space.\n\\end{proposition}\n\\begin{proof}\n  Let \\( (X, \\mscrT) \\) be a Baire space and let \\( (X', \\mscrT_{X'}) \\) be an open \\hyperref[def:topological_subspace]{subspace} with the canonical embedding \\( \\iota: X' \\to X \\). The proposition holds vacuously if \\( X' = \\varnothing \\), so we assume that \\( X' \\neq \\varnothing \\).\n\n  Note that \\( \\iota \\) is continuous by definition, however it is also an open map because if \\( U \\in T_{X'} \\), then \\( \\iota(U) = U \\cap X' \\) is open in \\( X \\) as the intersection of two open sets. Therefore, it is a homeomorphic embedding and by \\fullref{thm:def:meager_set/homeomorphism}, \\( U \\) is meager if and only if \\( \\iota(U) \\) is meager. Since \\( X \\) is a Baire space, \\( \\iota(U) \\) is not meager and hence \\( U \\) is also not meager.\n\n  We showed that every nonempty open set \\( U \\in T_{X'} \\) is nonmeager, therefore \\( X' \\) is a Baire space.\n\\end{proof}\n\n\\begin{theorem}[Baire category theorem]\\label{thm:baire_category_theorem}\\mcite{Rudin1991Functional}\n  \\begin{thmenum}\n    \\thmitem{thm:baire_category_theorem/metric} \\hyperref[def:complete_metric_space]{Complete metric spaces} are \\hyperref[def:baire_space]{Baire spaces}.\n    \\thmitem{thm:baire_category_theorem/compact} \\hyperref[def:locally_compact_space]{Locally compact} \\hyperref[def:separation_axioms/T2]{Hausdorff} spaces are Baire spaces.\n  \\end{thmenum}\n\\end{theorem}\n", "meta": {"hexsha": "19dda1a0fa16b37b8fccba8930f10cd6123d8bca", "size": 4767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/baire_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/baire_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/baire_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": 68.1, "max_line_length": 454, "alphanum_fraction": 0.7333752884, "num_tokens": 1548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.78793120560257, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.663300694019317}}
{"text": "\\subsection{2018 Free-Response Answers}\r\n\\begin{enumerate}\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item $r(t)$ tells us the rate at which people enter the line.\r\n\t\t\tBy integrating $r(t)$ over the given interval, we can find the total number of people who entered the line.\r\n\t\t\tUsing a calculator,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{0}^{300}{r(t)\\d{t}} = \\int_{0}^{300}{44\\left(\\frac{t}{100}\\right)^3\\left(1-\\frac{t}{300}\\right)^7\\d{t}} = 270 \\text{ people}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item We know that at $t=0$, there are already 20 people in line.\r\n\t\t\tCombining this fact with our answer from part (a), we know that $270+20=290$ people entered the line in the time interval.\r\n\t\t\tWe also know that people leave the line at a constant rate of 0.7 people per second.\r\n\t\t\tIntegrating this rate over the time interval will give us the number of people who left the line.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{0}^{300}{0.7\\d{t}} = 210 \\text{ people}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, there are $290-210=80$ people in line at $t=30$.\r\n\t\t\\item We know from our answer in (b) that there are 80 people in line at $t=300$.\r\n\t\t\tWe see from $r(t)$ that no more people are entering the line when $t>300$.\r\n\t\t\tSo, the only thing that contributes to changing the number of people in line is people constantly leaving at a rate of 0.7 people per second.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t300\\text{s} + \\frac{80 \\text{ people}}{0.7\\text{ people/s}} \\approx 414.286\\text{s}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Combining the fact that there are initially 20 people in line, the inflow rate is given by $r(t)$ and the outflow rate is 0.7, we can get that the number of people in line at time $x$ is modeled by\r\n\t\t\\begin{equation*}\r\n\t\t\t20 + \\int_{0}^{x}{\\left(r(t)-0.7\\right)\\d{t}}.\r\n\t\t\\end{equation*}\r\n\t\tFinding when the derivative is 0,\r\n\t\t\\begin{equation*}\r\n\t\t\tr(t) - 0.7 = 0 \\implies t = 33.013 \\text{ or } 166.575.\r\n\t\t\\end{equation*}\r\n\t\tFinding the number of people in line at these times and the endpoints 0 and 300,\r\n\t\t\\begin{align*}\r\n\t\t\t\\text{people}_{0} &= 20 \\\\\r\n\t\t\t\\text{people}_{33.013} &= 3.803 \\\\\r\n\t\t\t\\text{people}_{166.575} &= 158.070 \\\\\r\n\t\t\t\\text{people}_{300} &= 80,\r\n\t\t\\end{align*}\r\n\t\twe see that the fewest number of people occurs when $t\\approx 33.013\\text{s}$.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Using a calculator, we see that $p^\\prime(25) = -1.17906$.\r\n\t\t\tIn the context of the problem, this value means that at a depth of 25 meters, the density of plankton is decreasing at a rate of 1.17906 million plankton per cubic meter per meter.\r\n\t\t\\item The vertical density of the plankton in the column is given by $p(h)*3\\text{m}^2$.\r\n\t\t\tIntegrating this density function for $0 \\leq h \\leq 30\\text{m}$, we'll get the total number of plankton on the column.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{0}^{30}{3p(h)\\d{h}} \\approx 1675.414.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, there are 1675.414 million plankton in the column from 0 to 30 meters depth.\r\n\t\t\\item The total number of plankton in the entire vertical column with cross section area $A\\text{m}^2$ is given by\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tP = \\int_{0}^{\\infty}{A\\text{density}(h)\\d{h}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tWe can break this integral up, and we can use $A=3\\text{m}^2$ for our particular column.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tP = 3\\int_{0}^{30}{p(h)\\d{h}} + 3\\int_{30}^{\\infty}{f(h)\\d{h}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince $u(h) \\geq f(h)$ for $h \\geq 30$, we can write the following inequality, the right side of which we can numerically evaluate:\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tP &\\leq 3\\int_{0}^{30}{p(h)\\d{h}} + 3\\int_{0}^{\\infty}{u(h)\\d{h}} \\\\\r\n\t\t\t\t&\\leq 1675.414 + 3(105) \\\\\r\n\t\t\t\t&\\leq 1990.414.\r\n\t\t\t\\end{align*}\r\n\t\t\tSo, we see that the number of plankton in the entire vertical column is at most 1990.414 million, which is strictly less than 2000 million.\r\n\t\t\\item Since the position of the boat is parametric, we can use the parametric arc length formula to find the total distance traveled for $0 \\leq t \\leq 1\\text{hr}$.\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tD &= \\int_{0}^{1}{\\sqrt{(x^\\prime(t))^2+(y^\\prime(t))^2}\\d{t}} \\\\\r\n\t\t\t\t&= \\int_{0}^{1}{\\sqrt{\\left(662\\sin{(5t)}\\right)^2 + \\left(880\\cos{(6t)}\\right)^2}\\d{t}} \\\\\r\n\t\t\t\t&\\approx 757.456.\r\n\t\t\t\\end{align*}\r\n\t\t\tSo, for $0 \\leq t \\leq 1\\text{hr}$, the boat travels a distance of 757.456 meters.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Trying to treat this like an initial value problem would be too tedious with all the piecewise parts of $g$.\r\n\t\t\tPlus, it would be doing more than the question asked because it only wants the value of $f$ at a particular point, not an expression for $f$.\r\n\t\t\tInstead, we can use the fact that $g$ is the derivative of $f$ and apply the Fundamental Theorem of Calculus.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{-5}^{1}{g(x)\\d{x}} = f(1) - f(-5) = 3 - f(-5).\r\n\t\t\t\\end{equation*}\r\n\t\t\tEvaluating the integral geometrically,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{-5}^{1}{g(x)\\d{x}} = -(9+\\frac{3}{2}) + 1 = \\frac{-19}{2}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSolving for $f(-5)$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\frac{-19}{2} = 3 - f(-5) \\implies f(-5) = \\frac{25}{2}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Evaluating the integral,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\int_{1}^{6}{g(x)\\d{x}} &= \\int_{1}^{3}{2\\d{x}} + \\int_{3}^{6}{2(x-4)^2\\d{x}} \\\\\r\n\t\t\t\t&= 2x\\biggr\\rvert_{1}^{3} + \\frac{2}{3}(x-4)^3\\biggr\\rvert_{3}^{6} \\\\\r\n\t\t\t\t&= 4 + \\frac{18}{3} \\\\\r\n\t\t\t\t&= 10.\r\n\t\t\t\\end{align*}\r\n\t\t\\item $f$ is increasing when its first derivative is positive and concave up when its second derivative is positive.\r\n\t\t\tSince $g$ is the derivative of $f$, we can also say that $f$ is increasing when $g$ is positive and concave up when $g$ is increasing.\r\n\t\t\t$g$ is positive on $(0,4) \\cup (4,6]$.\r\n\t\t\t$g$ is increasing on $(-2,-1) \\cup (0,1) \\cup (4,6)$.\r\n\t\t\tTaking the intersection of these intervals, we see that $f$ is increasing and concave up on $(0,1) \\cup (4,6)$.\r\n\t\t\\item $f$ has an inflection point when its second derivative is equal to 0, changing sign.\r\n\t\t\tSince $g$ is the derivative of $f$, we can also say that $f$ has an inflection point when the derivative of $g$ is equal to 0, changing sign.\r\n\t\t\tAlthough we see by looking at the graph that the derivative of $g$ is 0 over several intervals, it does not change sign.\r\n\t\t\tThe only place the derivative is 0 and changes sign is at $x=4$.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item We can approximate $H^\\prime(6)$ as the average rate of change between $t=5$ and $t=7$.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tH^\\prime(6) \\approx \\frac{H(7)-H(5)}{7-5} = \\frac{11-6}{7-5} = \\frac{5}{2}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tIn the context of this problem $H^\\prime(6) \\approx = \\frac{5}{2}$ means that at 6 years, the tree is growing at a rate of 5/2 meters per year.\r\n\t\t\\item Looking at the average rate of change between $t=3$ and $t=5$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\bar{H^\\prime}_{3,5} = \\frac{H(5)-H(3)}{5-3} = \\frac{6-2}{5-3} = 2.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince $H$ is differentiable, it is also continuous.\r\n\t\t\tSo, by the mean value theorem, there is at least one point $3 \\leq c \\leq 5$ (which is a sub-interval of $2 \\leq t \\leq 10$) such that $H^\\prime(c) = 2$. \r\n\t\t\\item We know that the average value of a continous function $f$ over some interval $[a,b]$ is\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\bar{f}_{a,b} = \\frac{1}{b-a}\\int_{a}^{b}{f(x)\\d{x}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, over our interval of $[2,10]$, we need to approximate this integral using trapezoids.\r\n\t\t\tBecause the sub-interval widths given by the table are not equally-sized, we can't apply the shortcut trapezoidal rule.\r\n\t\t\tHowever, we can still approximate the area using trapezoids.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\frac{1}{10-2}\\int_{2}^{10}{H(x)\\d{x}} \\approx \\frac{1}{8}\\left(\\frac{1.5+2}{2}1+\\frac{2+6}{2}2+\\frac{6+11}{2}2+\\frac{11+15}{2}3\\right) = \\frac{1}{8}(65.75) = 8.21875.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, the average height of the tree between 2 and 10 years is approximately 8.21875 meters.\r\n\t\t\\item Finding the diameter of the base of the tree when it is 50 meters tall according to $G$.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t50 = \\frac{100x}{1+x} \\implies x = 1.\r\n\t\t\t\\end{equation*}\r\n\t\t\tDifferentiating $G$, remembering the chain rule,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tG^\\prime(x) = \\frac{100(1+x)\\dd{x}{t} - 100x\\dd{x}{t}}{(1+x)^2}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tPlugging in $x=1$ and $\\dd{x}{t}=0.03$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tG^\\prime(1) = \\frac{100(1+1)(0.03) - 100(1)(0.03)}{(1+1)^2} = \\frac{6-3}{4} = \\frac{3}{4}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, according to $G$, the tree is growing at 3/4 meters per year when it is 50 meters tall.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item We know the formula for the area between two polar curves is\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA = \\frac{1}{2}\\int_{\\alpha}^{\\beta}{\\left(f^2(\\theta)-g^2(\\theta)\\right)\\d{\\theta}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince we want the area inside the circle and outside the lima\\c{c}on for $\\pi/3 \\leq \\theta \\leq 5\\pi/3$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA = \\frac{1}{2}\\int_{\\pi/3}^{5\\pi/3}{\\left((4)^2-(3+2\\cos{\\theta})^2\\right)\\d{\\theta}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Remembering that $x=r\\cos{\\theta}$ and $y=r\\sin{\\theta}$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tx = (3+2\\cos{\\theta})\\cos{\\theta} \\text{, } y = (3+2\\cos{\\theta})\\sin{\\theta}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tDifferentiating $x$ and $y$ with respect to $\\theta$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{x}{\\theta}=-(3+2\\cos{\\theta})\\sin{\\theta} + \\cos{\\theta}(-2\\sin{\\theta}) \\text{, } \\dd{y}{\\theta} = (3+2\\cos{\\theta})\\cos{\\theta} + \\sin{\\theta}(-2\\sin{\\theta}).\r\n\t\t\t\\end{equation*}\r\n\t\t\tDividing one by the other,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{y}{x} = \\frac{\\dd{y}{\\theta}}{\\dd{x}{\\theta}} = \\frac{(3+2\\cos{\\theta})\\cos{\\theta} + \\sin{\\theta}(-2\\sin{\\theta})}{-(3+2\\cos{\\theta})\\sin{\\theta} + \\cos{\\theta}(-2\\sin{\\theta})}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tAt $\\theta=\\pi/2$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{y}{x}_{\\theta=\\pi/2} = \\frac{(3+2\\cdot 0)\\cdot 0 + 1(-2\\cdot 1)}{-(3+2\\cdot 0)1 + 0(-2\\cdot 1)} = \\frac{-2}{-3} = \\frac{2}{3}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item $r$ is a function of $\\theta$, and we're being told that $\\theta$ behaves as a function of $t$, due to how the particle moves.\r\n\t\t\tSo, we can apply the chain rule:\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\dd{r}{t} &= \\dd{r}{\\theta}\\cdot\\dd{\\theta}{t} \\\\\r\n\t\t\t\t&= -2\\sin{\\theta}\\dd{\\theta}{t}.\r\n\t\t\t\\end{align*}\r\n\t\t\tSolving for $\\dd{\\theta}{t}$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{\\theta}{t} = \\dd{r}{t}\\frac{1}{-2\\sin{\\theta}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tMoving away from the origin at some rate tell us how $r$ changes.\r\n\t\t\tPlugging in $\\dd{r}{t}=3$ and $\\theta=\\pi/3$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{\\theta}{t} = 3\\frac{1}{-2\\sin{\\left(\\pi/3\\right)}} = \\frac{3}{-\\sqrt{3}} = -\\sqrt{3}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, $\\theta$ is changing at a rate of $-\\sqrt{3}$ radians per second.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Starting with the given Maclaurin series,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\ln{(1+u)} = u - \\frac{u^2}{2} + \\frac{u^3}{3} - \\frac{u^4}{4} + \\ldots + (-1)^{n+1}\\frac{u^n}{n} + \\ldots .\r\n\t\t\t\\end{equation*}\r\n\t\t\tSubstituting $u=x/3$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\ln{\\left(1+\\frac{x}{3}\\right)} = \\frac{x}{3} - \\frac{(\\frac{x}{3})^4}{2} + \\frac{(\\frac{x}{3})^4}{3} - \\frac{(\\frac{x}{3})^4}{4} + \\ldots + (-1)^{n+1}\\frac{(\\frac{x}{3})^n}{n} + \\ldots .\r\n\t\t\t\\end{equation*}\r\n\t\t\tMultiplying by $x$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tx\\ln{\\left(1+\\frac{x}{3}\\right)} = x\\frac{x}{3} - x\\frac{(\\frac{x}{3})^4}{2} + x\\frac{(\\frac{x}{3})^4}{3} - x\\frac{(\\frac{x}{3})^4}{4} + \\ldots + (-1)^{n+1}x\\frac{(\\frac{x}{3})^n}{n} + \\ldots .\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Applying the ratio test on the absolute terms,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\lim_{n\\to\\infty}{\\frac{x\\frac{(\\frac{x}{3})^{n+1}}{n+1}}{x\\frac{(\\frac{x}{3})^n}{n}}} = \\lim_{n\\to\\infty}{\\frac{n\\frac{x}{3}}{n+1}} = \\frac{x}{3}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tThe ratio test tells us the series converges when the limit is less than 1, so we can safely say that $\\abs{x} < 3$, and we still need to test the endpoints.\r\n\t\t\tWhen $x=-3$ the series becomes\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\sum_{n=1}^{\\infty}{(-1)^{n+1}(-3)\\frac{\\left(\\frac{-3}{3}\\right)^n}{n}} = \\sum_{n=1}^{\\infty}{\\frac{3}{n}}\r\n\t\t\t\\end{equation*}\r\n\t\t\twhich diverges by the P-Test.\r\n\t\t\tWhen $x=3$, the series becomes\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\sum_{n=1}^{\\infty}{(-1)^{n+1}3\\frac{\\left(\\frac{3}{3}\\right)^{n}}{n}} = \\sum_{n=1}^{\\infty}{(-1)^{n+1}\\frac{3}{n}}\r\n\t\t\t\\end{equation*}\r\n\t\t\twhich converges by the Alternating Series Test.\r\n\t\t\tSo, the interval of convergence is $-3 < x \\leq 3$.\r\n\t\t\\item The Alternating Series Estimation Theorem tells us that the error from an alternating series is at most the value of the first term not included, and the error is the same sign as the first not included term.\r\n\t\t\tFor $P_4(x)$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\abs{P_4(2)-f(2)} \\leq \\abs{(-1)^5 2\\frac{\\left(\\frac{2}{3}\\right)^4}{4}} = \\frac{8}{81}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, our upper bound on the error is $8/81$.\r\n\t\\end{enumerate}\r\n\t\r\n\\end{enumerate}", "meta": {"hexsha": "e9319697332beb8c5f881991c6f2af701cb66774", "size": 12847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/additional_materials/2018_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/2018_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/2018_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": 56.8451327434, "max_line_length": 217, "alphanum_fraction": 0.6160193041, "num_tokens": 4904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.6633006840716195}}
{"text": "\\section{Basic techniques and properties}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Evaluate the determinant of a square matrix using either\n    Laplace Expansion or row operations.\n  \\item Demonstrate the effects that row operations have on\n    determinants.\n  \\item Verify the following:\n    \\begin{enumerate}\n    \\item The determinant of a product of matrices is the product of the\n      determinants.\n    \\item The determinant of a matrix is equal to the determinant of its\n      transpose.\n    \\end{enumerate}\n  \\end{enumerate}\n\\end{outcome}\n", "meta": {"hexsha": "3f001c9327cc638f209c0c11db36dec1f414e4e6", "size": 550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/determinantsBasicTechniquesProperties.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/determinantsBasicTechniquesProperties.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/determinantsBasicTechniquesProperties.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.5555555556, "max_line_length": 72, "alphanum_fraction": 0.7363636364, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6633006783507591}}
{"text": "\\subsection{Solving}\n\n\\begin{frame}\n  \\frametitle{The Tableau}\n\n  \\scriptsize\n\n  The equations $A\\vec{x} = \\vec{0}$ are kept in a {\\bf tableau}, the most \n  important structure of the Simplex\n  \\vfill\n  The variables are {\\bf partitioned} into the set of {\\bf non-basic} \\nonbas\n  and {\\bf basic} \\bas  variables \n  \\vfill\n  E.g., \\bas = $\\{ x_1, x_3, x_4 \\}$, \\nonbas = $\\{ x_2, x_5, x_6 \\}$\n  $$\n  \\begin{array}{rcl}\n    x_1 & = & 4 x_2 + x_5 \\\\\n    x_3 & = & 5 x_2 + 3 x_6 \\\\\n    x_4 & = & x_5 - x_6\n  \\end{array}\n  $$\n  \\vfill\n  non-basic variables can be considered as {\\bf independent}, while basic variables\n  assume values forced by the non-basic ones. E.g., in the row\n  $$\n    x_1 = 4 x_2 + x_5 \n  $$\n  suppose that $x_2 = 2, x_5 = 1$, then we set $x_1 = 9$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Solving}\n\n  \\scriptsize\n\n  The \\tsolver stores \n  \\begin{itemize}\n    \\item the Tableau (does not grow/shrink)\n    \\item the active bounds on variables (initially none)\n    \\item the current model $\\mu$ (initially all $0$, but could be chosen differently)\n  \\end{itemize}\n\n  \\vfill\n\n  \\begin{columns}\n\n  \\begin{column}{.4\\textwidth}\n  \\begin{center}\n  Tableau\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n    x_1 & = & a_{11} x_{m+1} \\ldots + a_{1n} x_n  \\\\ \n    x_2 & = & a_{21} x_{m+1} \\ldots + a_{2n} x_n  \\\\ \n    & \\ldots \\\\                             \n    x_i & = & a_{i1} x_{m+1} \\ldots + a_{in} x_n  \\\\ \n    & \\ldots \\\\                             \n    x_m & = & a_{m1} x_{m+1} \\ldots + a_{mn} x_n \\\\\n    \\\\\n    \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $lb$~~~~~~~Bounds~~~~~~~$ub$\n  \\end{center}\n  $$\n  \\begin{array}{rcccl}\n    - \\infty & \\leq & x_1 & \\leq & \\infty \\\\\n    - \\infty & \\leq & x_2 & \\leq & \\infty \\\\\n    & & \\ldots & & \\\\\n    - \\infty & \\leq & x_i & \\leq & \\infty \\\\\n    & & \\ldots & & \\\\\n    - \\infty & \\leq & x_m & \\leq & \\infty \\\\\n    & & \\ldots & & \\\\\n    - \\infty & \\leq & x_n & \\leq & \\infty \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $\\mu$\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n  x_1 & \\mapsto & 0 \\\\\n  x_2 & \\mapsto & 0 \\\\\n  & \\ldots \\\\\n  x_i & \\mapsto & 0 \\\\\n  & \\ldots \\\\\n  x_m & \\mapsto & 0 \\\\\n  & \\ldots \\\\\n  x_n & \\mapsto & 0 \n  \\end{array}\n  $$\n  \\end{column}\n\n  \\end{columns}\n\n  \\vfill\n\n  The \\tsolver is in a consistent state if the model $(i)$ respects the tableau \n  and $(ii)$ satisfies the bounds (for all $x$, $lb(x) \\leq \\mu(x) \\leq ub(x)$)\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Asserting a bound on a non-basic variable}\n\n  \\scriptsize\n\n  Asserting a bound $x \\leq c$ (resp. $x \\geq c$), $x \\in \\nonbas$ may result in \\pause\n  \\begin{itemize}\n    \\item unsatisfiability, if $c < lb(x)$ (resp. $c > ub(x)$) \\pause\n    \\item nothing, if $c > ub(x)$ (resp. $c < lb(x)$) \\pause\n    \\item bound tightening, model not affected if $\\mu(x) \\leq c$ (resp. $\\mu(x) \\geq c$) \\pause\n    \\item bound tightening, model affected if $\\mu(x) > c$ (resp. $\\mu(x) < c$) \\pause\n  \\end{itemize}\n  \\vfill\n  The last case is ``problematic'' because we need to \n  \\begin{enumerate}[$(i)$]\n    \\item adjust $\\mu(x)$: $\\mu(x)$ is set to $c$ \n    \\item adjust the values of basic variables\n  \\end{enumerate}\n  We assume we have a function $Update(x,c)$ that implements $(i)-(ii)$\n  \\vfill \\pause\n  \\begin{columns}\n\n  \\begin{column}{.4\\textwidth}\n  \\begin{center}\n  Tableau\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n    x_1 & = & - x_3 + x_4  \\\\ \n    x_2 & = &   x_3 + x_4  \\\\ \n    \\\\\n    \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $lb$~~~~~~~Bounds~~~~~~~$ub$\n  \\end{center}\n  $$\n  \\begin{array}{rcccl}\n    - \\infty & \\leq & x_1 & \\leq & \\infty \\\\\n    - \\infty & \\leq & x_2 & \\leq & \\infty \\\\\n    \\only<1-9|handout:0>{-\\infty}\\only<10->{-8} & \\leq & x_3 & \\leq & \\only<1-7|handout:0>{\\infty}\\only<8->{-4} \\\\\n    - \\infty & \\leq & x_4 & \\leq & \\infty \n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $\\mu$\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n  x_1 & \\mapsto & \\only<1-8|handout:0>{0}\\only<9->{4} \\\\\n  x_2 & \\mapsto & \\only<1-8|handout:0>{0}\\only<9->{-4} \\\\\n  x_3 & \\mapsto & \\only<1-8|handout:0>{\\coloneat{0}{8}}\\only<9->{-4} \\\\\n  x_4 & \\mapsto & 0 \n  \\end{array}\n  $$\n  \\end{column}\n\n  \\end{columns}\n  \\vfill\n  \\tsolver stack: \\\\\n  \\onslide<8->{$x_3 \\leq -4$\\ \\ \\ \\ (tighten $ub(x_3)$, affects other values)\\\\}\n  \\onslide<10->{$x_3 \\geq -8$\\ \\ \\ \\ (tighten $lb(x_3)$, does not affect other values)\\\\}\n  \\onslide<11->{$x_3 \\leq 0$\\ \\ \\ \\ \\ \\  (does not tighten $ub(x_3)$)\\\\}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Asserting a bound on a basic variable}\n\n  \\scriptsize\n\n  Asserting a bound $x \\leq c$ (resp. $x \\geq c$), $x \\in \\bas$ may result in\n  the same $4$ cases as before\n  \\begin{itemize}\n    \\item unsatisfiability, if $c < lb(x)$ (resp. $c > ub(x)$) \n    \\item nothing, if $c > ub(x)$ (resp. $c < lb(x)$) \n    \\item bound tightening, model not affected if $\\mu(x) \\leq c$ (resp. $\\mu(x) \\geq c$)\n    \\item bound tightening, model affected if $\\mu(x) > c$ (resp. $\\mu(x) < c$) \n  \\end{itemize}\n  \\vfill\n  however, since a basic variable is {\\bf dependent} from non-basic variables in the\n  tableau, we cannot use function $Update$ directly. Before we need to \n  turn $x$ into a non-basic variables.\n  \\pause \n  \\vfill\n  So if $\\mu(x) > c$ or $\\mu(x) < c$ we have to\n  \\begin{enumerate}[$(i)$]\n    \\item {\\bf turn $x$ into non-basic} (another non-basic variable will become basic instead)\n    \\item adjust $\\mu(x)$: $\\mu(x)$ is set to $c$ \n    \\item adjust the values of basic variables\n  \\end{enumerate}\n  \\vfill\n  Step $(i)$ is performed by a function $Pivot(x,y)$ (see next slide). Therefore asserting\n  a bound on a basic variable $x$ consists in executing $Pivot(x,y)$ and then $Update(x,c)$\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Pivoting}\n\n  \\scriptsize\n\n  $Pivot(x,y)$ is the operation of swapping a basic variable $x$ with a non-basic variable $y$ \n  (how to choose $y$ ? See next slide)\n  \\vfill\n  It consists of the following steps:\n  \\begin{enumerate}\n    \\item Take the row $x = a y + R$ in the tableau ($R = \\mbox{rest of the polynome}$)\n    \\item Rewrite it as $y = \\frac{x - R}{a}$\n    \\item Substitute $y$ with $\\frac{x - R}{a}$ in all the other rows of the tableau (and simplify)\n  \\end{enumerate}\n  \\vfill\\pause\n  Example for $Pivot(x_1,x_3)$\n  \\vfill\n  \\ra{1.5}\n  \\begin{columns}\n\n    \\begin{column}{.33\\textwidth}\n      \\begin{center}\n      Step 1 \n      \\end{center}\n      $$\n      \\begin{array}{rcl}\n\t\\colone{x_1} & \\colone{=} & \\colone{3 x_2 + 4 x_3 - 5 x_4} \\\\\n\tx_5 & = & - x_2 - x_3 \\\\\n\tx_6 & = & 10 x_2 + 5 x_4\t\n      \\end{array}\n      $$\n    \\end{column}\n\n    \\begin{column}{.33\\textwidth}\n      \\begin{center}\n      Step 2 \n      \\end{center}\n      $$\n      \\begin{array}{rcl}\n\t\\colone{x_3} & \\colone{=} & \\colone{-\\frac{3}{4} x_2 + \\frac{1}{4} x_1 + \\frac{5}{4} x_4} \\\\\n\tx_5 & = & - x_2 - x_3 \\\\\n\tx_6 & = & 10 x_2 + 5 x_4\t\n      \\end{array}\n      $$\n    \\end{column}\n\n    \\begin{column}{.33\\textwidth}\n      \\begin{center}\n      Step 3 \n      \\end{center}\n      $$\n      \\begin{array}{rcl}\n\tx_3 & = & -\\frac{3}{4} x_2 + \\frac{1}{4} x_1 + \\frac{5}{4} x_4 \\\\\n\t\\colone{x_5} & \\colone{=} & \\colone{- \\frac{1}{4} x_2 -\\frac{1}{4} x_1 - \\frac{5}{4} x_4} \\\\\n\tx_6 & = & 10 x_2 + 5 x_4\t\n      \\end{array}\n      $$\n    \\end{column}\n\n  \\end{columns}\n  \\vfill\\pause\n  we moved from $\\bas = \\{ x_1, x_5, x_6 \\}$ to $\\bas = \\{ x_3, x_5, x_6 \\}$ \n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Choosing Pivoting Variable}\n\n  \\scriptsize\n\n  Consider the following situation \n  \\vfill\n  \\begin{columns}\n\n  \\begin{column}{.4\\textwidth}\n  \\begin{center}\n  Tableau\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n    & \\ldots \\\\                             \n    x_1 & = & 3 x_2 - 4 x_3 + 2 x_4 - x_5 \\\\ \n    & \\ldots \\\\                             \n    \\\\\n    \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $lb$~~~~~~~Bounds~~~~~~~$ub$\n  \\end{center}\n  $$\n  \\begin{array}{rcccl}\n     -4 & \\leq & x_1 & \\leq & 10 \\\\\n      1 & \\leq & x_2 & \\leq & 3 \\\\\n     -4 & \\leq & x_3 & \\leq & -1 \\\\\n      1 & \\leq & x_4 & \\leq & 2 \\\\\n     -1 & \\leq & x_5 & \\leq & 10 \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $\\mu$\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n  x_1 & \\mapsto & \\colone{12} \\\\\n  x_2 & \\mapsto & 1 \\\\\n  x_3 & \\mapsto & -1 \\\\\n  x_4 & \\mapsto & 2 \\\\\n  x_5 & \\mapsto & -1 \n  \\end{array}\n  $$\n  \\end{column}\n\n  \\end{columns}\n  \\vfill\n  which among $\\nonbas = \\{ x_2, x_3, x_4 \\}$ do I choose for pivoting ? Clearly, the value of $\\mu(x_1)$\n  is too high, I have to decrease it by playing with the values of \\nonbas: \\pause\n  \\begin{itemize}\n    \\item $  3 x_2$ cannot decrease, as $\\mu(x_2) = lb(x_2)$ and cannot be moved down \\pause\n    \\item $- 4 x_3$ cannot decrease, as $\\mu(x_3) = ub(x_3)$ and cannot be moved up \\pause\n    \\item $  2 x_4$ can decrease, as  $\\mu(x_4) = ub(x_4)$, and can be moved down \\pause\n    \\item $-   x_5$ can decrease, as  $\\mu(x_5) = lb(x_5)$, and can be moved up\n  \\end{itemize}\n  \\vfill\\pause\n  both $x_4$ and $x_5$ are therefore good candidates for pivoting. To avoid loops, \n  choose variable with smallest subscript (Bland's Rule). This rule is not necessarily\n  efficient, though\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Detect Unsatisfiability}\n\n  \\scriptsize\n\n  There might be cases in which {\\bf no suitable variable for pivoting can be found}.\n  This indicates unsatisfiability. \\pause\n  Consider the following where we have just asserted $x_1 \\leq 9$\n  \\vfill\n  \\begin{columns}\n\n  \\begin{column}{.4\\textwidth}\n  \\begin{center}\n  Tableau\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n    & \\ldots \\\\                             \n    x_1 & = & 3 x_2 - 4 x_3 + 2 x_4 - x_5 \\\\ \n    & \\ldots \\\\                             \n    \\\\\n    \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $lb$~~~~~~~Bounds~~~~~~~$ub$\n  \\end{center}\n  $$\n  \\begin{array}{rcccl}\n     -4 & \\leq & x_1 & \\leq & 9 \\\\\n      1 & \\leq & x_2 & \\leq & 3 \\\\\n     -4 & \\leq & x_3 & \\leq & -1 \\\\\n      2 & \\leq & x_4 & \\leq & 2 \\\\\n     -1 & \\leq & x_5 & \\leq & -1 \\\\\n  \\end{array}\n  $$\n  \\end{column}\n\n  \\begin{column}{.3\\textwidth}\n  \\begin{center}\n  $\\mu$\n  \\end{center}\n  $$\n  \\begin{array}{rcl}\n  x_1 & \\mapsto & \\colone{12} \\\\\n  x_2 & \\mapsto & 1 \\\\\n  x_3 & \\mapsto & -1 \\\\\n  x_4 & \\mapsto & 2 \\\\\n  x_5 & \\mapsto & -1 \n  \\end{array}\n  $$\n  \\end{column}\n\n  \\end{columns}\n  \\vfill\n  no variable among $\\nonbas = \\{ x_2, x_3, x_4 \\}$ can be chosen for pivoting. This is because (due to tableau)\n  $$x_2 \\geq 3\\ \\swedge\\ x_3 \\leq -1\\ \\swedge\\ x_4 \\geq 4\\ \\swedge\\ x_5 \\leq -1\\ \\ \\Rightarrow\\ \\ x_1 \\geq 12\\ \\ \\Rightarrow\\ \\ \\neg (x_1 \\leq 9)$$\n  \\vfill\n  Therefore\n  $$\\{ x_2 \\geq 3,\\ x_3 \\leq -1,\\ x_4 \\geq 4,\\ x_5 \\leq -1,\\ \\neg( x_1 \\leq 9 ) \\}$$\n  is a \\tconflict (modulo the tableau)\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Solving}\n\n  \\scriptsize\n\n  \\begin{tabbing}\n  asv \\= a \\= a \\= a \\= as \\= asdfasdfasdfasdfasdfasdfasdfasdf \\= \\kill\n  1  \\> while( $true$ ) \\\\\n     \\> \\\\\n  2  \\> \\> pick first $x_i \\in \\bas$ such that $\\mu(x_i) < lb(x_i)$ or $\\mu(x_i) > ub(x_i)$ \\\\\n  3  \\> \\> if ( there is no such $x_i$ ) return $sat$ \\\\\n     \\> \\\\\n  4  \\> \\> $x_j = ChoosePivot( x_i )$ \\\\\n  5  \\> \\> if ( $x_j$ == $undef$ ) return $unsat$ \\\\ \n  6  \\> \\> $Pivot(x_i,x_j)$ \\\\\n     \\> \\\\\n  7  \\> \\> if ( $\\mu(x_i) < lb(x_i)$ ) \\\\\n  8  \\> \\> \\> $Update( x_i, lb(x_i) )$ \\\\\n     \\> \\\\\n  9  \\> \\> if ( $\\mu(x_i) > ub(x_i)$ ) \\\\\n  10 \\> \\> \\> $Update( x_i, ub(x_i) )$ \\\\\n     \\> \\\\\n  11 \\> end\n  \\end{tabbing}\n\n  $x_j = ChoosePivot( x_i )$: returns variable to use for pivoting with $x_i$, or $undef$ if conflict\\\\\n  pick first $x_i$ \\ldots: it's again Bland's rule\n\n\\end{frame}\n", "meta": {"hexsha": "d012ca5210753b0ca327689ddbfc196d5300f452", "size": 11809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture6/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": "lecture6/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": "lecture6/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": 26.4775784753, "max_line_length": 147, "alphanum_fraction": 0.5479718858, "num_tokens": 4751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.6630414708289317}}
{"text": "\\section{Implementation: \\toolname}\nHere we give some more examples on how we can use \\toolname.\nWe start by proving termination on mutual recursive functions, \nusing lexicographical ordering. \n%\nThen we describe how we proved functional correctness on \ntwo commonly used functions, namely \\texttt{ByteString}\nand \\texttt{Text}.\n\n\\subsection{Proving Termination}\n\n   Next, consider the 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   %\n   There exists no integer termination metric that decreases at each recursive call.\n   %\n   However @ack@ terminates because at each call \\emph{either}\n   @m@ decreases \\emph{or} @m@ remains the same and @n@ decreases. \n   %\n   In other words, the pair @(m,n)@ strictly decreases according to\n   \\emph{lexicographic} ordering. \n   %\n   To capture this requirement we extend termination metric\n   from an integer to a list of integers\n   and at each recursive call we check that this list is\n   lexicographically decreasing.\n   %\n   In the case of\n   @ack@ this list will simply be the parameters @m@\n   and @n@:\n   %\n   \\begin{code}\n     ack :: m:Nat -> n:Nat -> Nat / [m,n]\n   \\end{code}\n   %\n   Thus, \\toolname uses lexicographic ordering on \n   a list of natural numbers to prove termination.\n   %\n   Termination metrics could be generalized to \n   any \\emph{well-found} metric.\n   \n   \\spara{Mutual Recursion}\n   %\n   Equipped with termination metrics\n   \\toolname instantiates a powerful\n   termination checker that like~\\citep{XiTerminationLICS01}\n   proves termination even for mutual recursive functions.\n   %\n   Consider the mutual recursive functions @isEven@ and @isOdd@\n   \\begin{code}\n   {-@ isEven :: n:Nat -> Bool / [n, 0] @-}\n   {-@ isOdd  :: n:Nat -> Bool / [n, 1] @-}\n   \n   isEven 0 = True\n   isEven n = isOdd $ n-1\n   \n   isOdd n  = not $ isEven n \n   \\end{code}\n   Each call terminates as either @isEven@\n   calls @isOdd@ with a decreasing argument, \n   or the argument remains the same, and @isOdd@\n   calls @isEven@ that should then decrease the argument.\n   % \n   We capture this reasoning using two lexicographic pairs:\n   each function has its own metric, \n   and when @isEven@ calls @isOdd@\n   the metric of the caller $(n, 0)$\n   should be greater that callee's metric\n   $(n-1, 1)$.\n   %\n   Similarly, at @isEven@'s call-site \n   \\toolname verifies that\t\n   $(n, 1) > (n, 0)$.\n   %\n   For example, the call @isEven m@\n   will fire the decreasing metric sequence\n   $(m, 0) > (m-1, 1) > (m-1, 0) > (m-2, 1) > \\dots$\n   that ultimate terminates for \\textit{any}\n   natural number $m$.\n\n\n\\subsection{Bytestring}\\label{sec:bytestring}\n\\input{bytestring}\n\n\\subsection{Text}\\label{sec:text}\n\\input{text}\n", "meta": {"hexsha": "23d1330a7a41a5f70b9f630e2888f179b94f208f", "size": 2794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/refinedhaskell/extendedhaskell.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/refinedhaskell/extendedhaskell.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/refinedhaskell/extendedhaskell.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": 30.0430107527, "max_line_length": 84, "alphanum_fraction": 0.6639226915, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.663015716986762}}
{"text": "%\n% 386\n%\n\\chapter{The Equations of Mathematical Physics}\n\n\\Section{18}{1}{The differential equations of mathematical physics.}\n\nThe functions which have been introduced in the preceding chapters are\nof importance in the applications of mathematics to physical\ninvestigations. Such applications are outside the province of this\nbook; but most of them depend essentially on the fact that, by means\nof these functions, it is possible to construct solutions of certain\npartial differential equations, of which the following are among the\nmost important :\n\n(I) Laplace s equation\n\ndx- dy' dz which was originally introduced in a memoir* on Saturn's\nrings.\n\nIf x, y, z) be the rectangular coordinates of any point in space, this\nequation is satisfied by the following functions which occur in\nvarious branches of mathematical physics :\n\n(i) The gravitational potential in regions not occupied by\nattractii:ig matter.\n\n(ii) The electrostatic potential in a uniform dielectric, in the\ntheory of electro- statics.\n\n(iii) The magnetic potential in free aether, in the theory of\nmagnetostatics.\n\n(iv) The electric potential, in the theory of the steady flow of\nelectric currents in solid conductoi's.\n\n(v) The temperature, in the theory of thermal equilibrium in solids.\n\n(vi) The velocity potential at points of a homogeneous liquid moving\nirrotationally, in hydrodynamical problems,\n\nNotwithstanding the physical diflferences of these theories, the\nmathematical investi- gations are much the same for all of them :\nthus, the problem of thermal equilibrium in a solid when the points of\nits surface are maintained at given temperatures is mathe- matically\niden.tical with the problem of determining the electric intensity in a\nregion when the points of its boundary are maintained at given\npotentials.\n\n(II) The equation of ivave motions\n\ndx dy' dz C' dt- This equation is of general occurrence in\ninvestigations of undidatory disturbances propagated with velocity c\nindependent of the wave length; for example, in the theory of\nelectric waves and the electro-magnetic theory of light, it is the\nequation satisfied by each component of the electric or magnetic\nvector; in the theory of elastic vibrations, it is the equati<Mi\nsatisfied by each component of the displacement; and in the theory of\nsound, it is the equation satisfied by the velocity potential in a\nperfect gas.\n\n* Mem. de FAcad. des Sciences, 1787 (published 1789), p. 252.\n\n%\n% 387\n%\n\n(III) The equation of conduction of heat\n\ndfV dfV dfV\\ ldV dec- dy dz- k dt\n\nThis is the equation satisfied by the temperature at a point of a\nhomogeneous isotropic body; the constant k is proportional to the\nheat conductivity of the body and inversely proportional to its\nspecific heat and density.\n\n(IV) A particular case of the preceding equation (II), when the\nvariable z is absent, is\n\ndx- dy- c- dt'\n\nThis is the equation satisfied by the displacement in the theory of\ntransverse vibrations of a membrane; the equation also occurs in the\ntheory of wave motion in two dimensions.\n\n(V) The equation of telegraphy\n\nThis is the equation satisfied by the potential in a telegraph cable\nwhen the inductance X, the capacity K, and the resistance It per unit\nlength are taken into account.\n\nIt would not be possible, within the limits of this chapter, to\nattempt an exhaustive account of the theories of these and the other\ndifferential equations of mathematical physics; but, by considering\nselected 'typical cases, we shall expound some of the principal\nmethods employed, with special reference to the uses of the\ntranscendental functions.\n\n\\Section{18}{2}{Boundary conditions.}\n\nA problem which arises very frequently is the determination, for one\nof the equations of \\hardsectionref{18}{1}, of a solution which is subject to certain\nboundary con- ditions; thus we may desire to find the temperature at\nany point inside a homogeneous isotropic conducting solid in thermal\nequilibrium when the points of its outer surface are maintained at\ngiven temperatures. This amounts to finding a solution of Laplace's\nequation at points inside a given surface, when the value of the\nsolution at points on the surface is given.\n\nA more complicated problem of a similar nature occurs in discussing\nsmall oscillations of a liquid in a basin, the liquid being exposed to\nthe atmosphere; in this problem we are given, effectively, the\nvelocity potential at points of the free surface and the normal\nderivate of the velocity potential where the liquid is in contact with\nthe basin.\n\nThe nature of the boundary conditions, necessary to determine a\nsolution uniquely, varies very much with the form of differential\nequation considered, even in the case of equations which, at first\nsight, seem very much alike. Thus a solution of the equation\n\ndx- dy'\n\n25-2\n\n%\n% 388\n%\n\n(which occurs in the problem of thermal equilibrium in a conducting\ncylinder) is uniquely determined at points inside a closed curve in\nthe x7/-ip\\ a,ne by a knowledge of the value of V at points on the\ncurve; but in the case of the equation\n\nda; c- dt-\n\n(which effectively only differs from the former in a change of sign),\noccurring\n\nin connexion with transverse vibrations of a stretched string, where V\n\ndenotes the displacement at time t at distance x from the end of the\n\nstring, it is physically evident that a solution is determined\nuniquely only if\n\ndV both V and - are given for all values of x such that x l, when =\n\n(where I denotes the length of the string).\n\nPhysical intuitions will usually indicate the nature of the boundary\nconditions which are necessary to determine a solution of a\ndifferential equation uniquely; but the existence theorems which are\nnecessary from the point of view of the pure mathematician are usually\nvery tedious and difficult*.\n\n\\Section{18}{3}{A general solution of Laplace's equation.}\n\nIt is possible to construct a general solution of Laplace's equation\nin the form of a definite integral. This solution can be employed to\nsolve various problems involving boundary conditions.\n\nLet V x, y, z) be a solution of Laplace's equation which can be\nexpanded into a power series in three variables valid for points of x,\ny, z) sufficiently near a given point Xf, yo, z ). Accordingly we\nwrite\n\nx = Xq + X, y=zy + Y, z = Zo+ Z;\n\nand we assume the expansion\n\nV = c(o + a X + biY + CiZ + a.. X- + b. Y- + c Z\n\n+ 2cLYZ+2e,ZX + 2f,XY+...,\n\nit being supposed that this series is absolutely convergent whenever\n\n\\ X'f+\\ Yr + \\ Z' a,\n\nwhere a is some positive constant :]:. If this expansion exists, V is\nsaid to be analytic at (xo, yo, S'o). It can be proved by the methods\nof §§ 3*7, 4'7\n\n* See e.g. Forsyth, Theory of Functions (1918), §§ 216-220, where an\napparently simple problem is discussed.\n\nt Whittaker, Math. Ann. lvii. (1902), p. 333.\n\n* The functions of applied mathematics satisfy this condition.\n\n%\n% 389\n%\n\nthat the series converges uniformly throughout the domain indicated\nand may be differentiated term-by-term with regard to X, Y or Z any\nnumber of times at points inside the domain.\n\nIf we substitute the expansion in Laplace's equation, which may be\nwritten\n\nd'V a F d V dX-' dY-' dZ-' '\n\nand equate to zero (§ 373) the coefficients of the various powers of\nX, Y and Z, we get an infinite set of linear relations between the\ncoefficients, of which\n\na.2 4- 62 -I- c. = may be taken as typical.\n\nThere are n(n - l) of these relations* between the n + 2) n + l)\ncoefficients of the terms of degree n in the expansion of V, so that\nthere are only (n+2)(n + 1) - n (n - 1) = 2n -f 1 independent\ncoefficients in the terms of degree n in V. Hence the terms of degree\nn in V must be a linear combination of 2n+l linearly independent\nparticular solutions of Laplace's equation, these solutions being each\nof degree n in X, Y and Z.\n\nTo find a set of such solutions, consider (Z + iX cos u 4- iFsin m)\";\nit is a solution of Laplace's equation which may be expanded in a\nseries of sines and cosines of multiples of u, thus :\n\nn n\n\n2 gm X, Y, Z) COS mu+ 2 h,, (X, Y, Z) sin. mu,\n\nm = 111 = 1\n\nthe functions g iX, Y, Z) and h X, Y, Z) being independent of u. The\nhighest power of Z in gm X, Y, Z) and A,, (X, F, Z) is Z\"'\" and the\nformer function is an even function of Y, the latter an odd function;\nhence the functions are linearly independent. They therefore form a\nset of 2?i -f- 1 functions of the type sought.\n\nNow by Fourier's rulef \\hardsectionref{9}{1}'2)\n\nTrgm X, Y, Z)= j Z + iX cos u + i Fsin u)\" cos mudu,\n\nirhyn X, Y, Z)= \\ Z + iX cos u -H iFsin uY sin mudu,\n\nJ -77\n\n* If a,s,j (where r + s + t = n) be the coefficient of A''T Z' in V,\nand if the terms of degree . d-V d V dW, . .,\n\n\" ~ WV \"*\" Wr- \"*\" dZ arranged primarily in powers of X and\nsecondarily in powers of F,\n\nthe coefficient fl .s.t <loes not occur in any term after Z'- -r Z<\n(or ZT*- if r = or 1), and hence the relations are all linearly\nindependent.\n\nt 27r must be written for tt in the coefficient of g X, Y, Z).\n\n%\n% 390\n%\n\nand so any linear combination of the 2/; + 1 solutions can be written\nin the form\n\n/:\n\n Z + iX COS i( + iY sin i()' fn u) du,\n\nwhere / (w) is a rational function of e*\".\n\nNow it is readily verified that, if the terms of degree n in the\nexpression assumed for V be written in this form, the series of terms\nunder the integral sign converges uniformly if \\ X\\ \\ + \\ Y Jr\\ Z be\nsufficiently small, and so \\hardsectionref{4}{7}) w e may write\n\nV =\\ Z+iX cos u + iY sin ?()\"/ (w) du.\n\n -TT n-i)\n\nBut any expression of this form may be written\n\nF = / F Z - iX cos u + i Y sin u, u) du,\n\nJ -n\n\nwhere i is a function such that differentiations with regard to X, Y\nor Z under the sign of integration are permissible. And, conversely,\nif F be any function of this type, V is a solution of Laplace's\nequation.\n\nThis result may be written\n\nJ -TT\n\non absorbing the terms - 2,1 - * o cos m - I'yo sin m into the second\nvariable; and, if differentiations under the sign of integi-ation are\npermissible, this gives a general solution of Laplace's equation;\nthat is to say, every solution of Laplace's equation which is analytic\nthroughout the interior of some sphere is expressible by an integral\nof the form given.\n\nThis result is the three-dimensional analogue of the theorem that\n\nV=f x- iy)+g x-ii/) is the general solution of\n\nox oy-\n\n[NoTE. A distinction has to be drawn between the primitive of an\nordinary diflFerential equation and general integrals of a i)artial\ndifferential equation of order higher than the first*.\n\nTwo apparently distinct primitives are always directly transformable\ninto one another\n\nby means of suitable relations between the constants; thus in the case\nof;T\"f +y = 0, we\n\ncan obtain the primitive Csin x + t) from A cos .r + 5 sin .r by\ndefining C and e by the equations Csin e = A, C'cos f = B. On the\nother hand, every solution of Laplace's equation is expressible in\neach of the forms\n\n/:\n\nf x cos < +// sin + iz, t) dt, I g (y cos ?< + sin u + ix, ) du;\n\nr ' ' - TT\n\n* For a discussion of general integrals of such equations, see\nForsyth, Theory of Differential Equations, vi. (1906), Ch. xii.\n\n%\n% 391\n%\n\nbut if these are known to be the same solution, there appears to be no\ngeneral analytical relation, connecting the functions / and g, which\nwill directly transform one form of the solution into the other.]\n\nExample 1. Shew that the potential of a particle of unit mass at (a,\nb, c) is 1 [ \" du\n\n2tt J -TT z - c) + i x - a) cos u + i y - b) sin u at all points for\nwhich z> c.\n\nExample 2. Shew that a general solution of Laplace's equation of zero\ndegree in X, y, z is\n\n/ log (.rcos <+j/sin il + jj) (<)(:/i, if I g t)dt = Q.\n\nExpress the solutions - -; and log-; - \\ in this form, where r- = x'\n+y' - z .\n\nExample 3. Shew that, in the case of the equation\n\np + g; = x+y\n\n( where jo =, q = ), integrals of Charpit's subsidiary equations (see\nForsyth, Differential\n\nEquations, Chap, ix.) are\n\n(i) p --x=y-q - = a,\n\n(ii) p = q + a?.\n\nDeduce that the corresponding general integrals are derived from\n\n(i) z =, :c + af+l y-af+F a)\\ Q = x + af- y-af + F' a) j'\n\n(ii) Az = \\ (. +y)3 + 2a2 x-y)-a x -y)- + G a)\\ = Aa x-y)-Aa x->ry)-'\n+ G' [a) j'\n\nand thence obtain a diflferential equation determining the function O\n(a) in terms of the function E a) when the two general integrals are\nthe same.\n\n\\Subsection{18}{3}{1}{Solutions of Laplace s equation involving Leg endive functions.}\nIf an expansion for V, of the form assumed in \\hardsectionref{18}{3}, exists when\n\nXq = y Zq ), we have seen that we can express F as a series of\nexpressions of the type\n\nI (z + ix cos u + iy sin u)\"' cos mudu, (z + ix cos u + iy sin uy sin\ninudu,\n\nJ -TT J -TT\n\nwhere n and m are integers such that m n.\n\nWe shall now examine these expressions more closely. If we take polar\ncoordinates, defined by the equations\n\nx= r sin 6 cos (f), y = r sin 6 sin (/>, z = r cos 6,\n\n%\n% 392\n%\n\nwe have\n\nI z + ix cos u + iy sin w)\" cos mu du\n\nJ - ]T\n\n= ?\" I cos + i sin 6 cos ( - )j\" cos mudu\n\nrn-<t> = ?'\" (cos + i sin cos yjr]\" cos 7?l (</) + ylr) rf-v/r\n\nZ - TT - I\n\n= ?'\" cos + I sin cos -v \" cos m (p + fr) dy\\ r\n\nJ -It\n\n= ?\" COS m(f> cos d + i sin cos i \" cos m'yjrd'yjr,\n\nJ -TT\n\nsince the integrand is a periodic function of - and\n\n(cos + z sin 6 cos i/r)\" sin ii/r\n\nis an odd function of yjr. Therefore \\hardsubsectionref{15}{6}{1}), with Ferrers'\ndefinition of the associated Legendre function,\n\nrir 27ri\"' . n !\n\n1 (z + ix cos u + iy sin )\" cos ??m c?ii = 7 -;' r Pn' (cos ) cos md).\n\nj - c / (-. j + m) !\n\nSimilarly\n\n/:\n\n( + iv cos i/ + 1?/ sin k)\" sin ?/it<c?w = 7 -! r Fn ' (cos ) sin md>.\n\n'(71 + m) I\n\nThei efore 7'' P,i\" (cos 6) cos 7?i aiic? r ''Pn' (cos ) sin 7/i</>\nare polynomials in X, y, z and are particular solutions of Laplace's\nequation. Further, by \\hardsectionref{18}{3}, every solution of Laplace's equation,\nwhich is analytic near the origin, can be expr essed in the form\n\nF = i r' \\ AnFn (cos (9) + I (yl \" ' cos m< + Bn ''' sin m ) P \" (cos\n6)1 .\n\nAny expression of the form\n\nAnPn (cos ) + i ( n<\"\" cos ? </) + 5 <' sin m(f>) P,r (cos ),\n\nm = \\\n\nwhere w is a positive integer, is called a surface harmonic of degree\n7i; a surface harmonic of degi-ee n multiplied by ?'\" is called a\nsolid harmonic (or a spherical Jiarmonic) of degree n.\n\nThe curves on a unit sphere (with centre at the origin) on which P\n(cos 6) vanishes are n parallels of latitude which divide the surface\nof the sphere into zones, and so P (cos d)\n\nis called (see S 15*1) a zonal harmonic; and the curves on which .\nmtb . Pn\" (cos 6) vanishes\n\nare n-7n parallels of latitude and 2m meridians, which divide the\nsurface of the sphere into quadrangles wh(> e angles are right angles,\nand so these functions are called tesseral harmonics.\n\n%\n% 393\n%\n\nA solid harmonic of degree n is .evidently a homogeneous polynomial of\ndegree n in X, y, z and it satisfies Laplace's equation.\n\nIt is evident that, if a change of rectangular coordinates* is made\nl;)y rotating the axes about the origin, a solid harmonic (or a\nsurface harmonic) of degree n transforms into a solid harmonic (or a\nsuz'face harmonic) of degree n in the new coordinates.\n\nSpherical harmonics were investigated with the aid of Cartesian\ncoordinates by W. Thomson in 1862, see Phil. Trans. (1863), pp.\n573-582, and Thomson and Tait, Treatise on Natural Philosophy i.\n(1879), jip. 171-218; they were also investigated independently in\nthe same manner at about the same time by Clebsch, Journal fur Math.\nLXi. (1863), pp. 195-262.\n\nExample. If coordinates r,, are defined by the equations\n\n1 1\n\na; = rcos, ?/ = (/'- 1)- sin cos 0, 3 = (/'2- 1)- sin sin(,\n\nshew that P,/\" (r) P '\" (cos 6) cos wi0 satisfies Laplace's equation.\n\n\\Section{18}{4}{The solution of Laplace's equation which satisfies\n  assigned boundary conditions at the surface of a sphere.}\n\nWe have seen \\hardsubsectionref{18}{3}{1}) that any solution of Laplace's equation which\nis analytic near the origin can be expanded in the form\n\nw = (\n\n+ i ( <\" ' cos m(f) + 5 \" ' sin m(f>) P,,\"* (cos 6) \\\n\nm = l J\n\nand, from \\hardsectionref{3}{7}, it is evident that if it converges for a given value\nof r, say a, for all values of 6 and (f) such that O tt, - tt tt, it\nconverges absolutely and uniformly when r < a.\n\nTo determine the constants, we must know the boundary conditions which\nV must satisfy. A boundary condition of frequent occurrence is that F\nis a given bounded integrable function of 6 and (f), say f(0, (f>), on\nthe surface of a given sphere, which we take to have radius a, and V\nis analytic at points inside this sphere.\n\nWe then have to determine the coefficients An, -4 <'\"', 5,i\"\"* from\nthe equation\n\nf d,( )= S a'M Pn (cos )+ 2 ( ' ' cos ?n</) + £ \" ' sin m</))P,;' (cos\n6')\n\nrt = i m = l J\n\nAssuming that this series converges uniformly f throughout the domain\n\nmultiplying by\n\nP ' (cos ) °%i<i, sm\n\n* Laplace's operator -, +;r-, +; -5 is invariant for changes of\nrectangular axes. ox dij- oz-\n\nt This is usually the case in physical problems.\n\n%\n% 394\n%\n\nintegrating term-by-term \\hardsectionref{4}{7}) and using the results of §§ 15'14,\n1551 on the integral properties of Legendre functions, we find that\n\nfid', 4>') P,r (cos 6') cos m<f>' sin e'dd'dcf ' = 7ra - . ) \" ',\n\nCn fir 9 (yx -1- 171, \" t\n\nA 6*', 6') P ' (cos d') sin wt<i)' sin O'dO'd ' = -jra\" =- . ) (; 5\n<' ',\n\nf f V( '' <l>') Pn (cos ') sin e'dB'dcf)' = lira\" 5-?-. . Therefore,\nwhen r < a, F(r, e,4>)=l ? f-)\" f f7( ', f )]p,(cos )P (cos ')\n\n+ 2 i (!i:i; p m (cos 6) Pn' (cos ') COS m (6 - d)') sin O'dO'd )'.\n\nThe series which is here integrated term-by-term converges uniformly\nwhen r <a, since the expression under the integral sign is a bounded\nfunction of 6, 0', (f), (f>', and so \\hardsectionref{4}{7} )\n\n47rF(r, 6*, 0) = T 1 /(0', cf>') I (2n -h 1) f-VlPn (cos ) P (cos )\n\n+ 2 i y' - Pn'\"\" (cos d)Pn''' (cos d') cos 7n(4>-(f>')\\ sin\ne'de'd(f>'. m=i(n + m)l J\n\nNow suppose that we take the line (6, (f>) as a new polar axis and let\n( 1'. 1') be the new coordinates of the line whose old coordinates\nwere (6', < '); we consequently have to replace Pn (cos 6) by 1 and\nP, ! (cos 6) by zero; and so we get\n\n47rF(r, e, (f>)=r t f(0', </)') t (2n + l)(-Y\nPn(cos0,')sme,'de,'d<f>,'\n\nJ -TT J W=0 \\ \\ V\n\n= r rf(0''<f>') i (2n+l)(-Y Pn(cose,')sme'dO'd(f>'.\n\nIf, in this formula, we make use of the result of example 23 of\nChapter xv (p. 332), we get\n\n ' 'J-nJo \\ r'-2arcos6,'+a-) and so\n\n47r F(r, e, </))\n\n, r f\" f(0', <i>') sin e'dd'dd)'\n\n= a(a- - r')\\ I - - -n-\n\nJ -nJ [r- - 2ar cos 6 cos ' -f sin 6 sin ' cos (( - </>) + a\"]\n\nIn this compact formula the Legendre functions have ceased to appear\nexplicitly.\n\n%\n% 395\n%\n\nThe last formula can be obtained by the theory of Green's functions.\nFor properties of such functions the reader is refei'red to Thomson\nand Tait, Natural Philosophy., §§ 499-519.\n\n[Note. From the integrals for V (r, 6, cf)) involving Legendre\nfunctions of cos j' and of cos, cos ' respectively, we can obtain a\nnew proof of the addition theorem for the Legendre polynomial.\n\nFor let\n\nXn \\&', (t>') =Pn (COS d ) - |P (cos 6) P (cOS 6')\n\n+ 2 2 - -f; P - (COS 6) P,;\" (cos 6') cos ra (0 - < '), and we get,\non comparing the two formulae for V r, 6, (f)),\n\n0= r f'/iff, < ') 2 (2 +i) (-Xxn (d\\ 4>') siD e'd\\&d,'.\n\nJ -TT J n=0 \\ /\n\nIf we take/( ', 0') to be a surface harmonic of degree n, the term\ninvolving r\" is the only one which occurs in the integrated series;\nand in particular, if we take/( ', 4>') = Xn i 'i 0')> we get\n\n' Xni6',fp') 'id'de'd(t)' = 0.\n\n-n J\n\nSince the integrand is continuous and is not negative it must be zero\n; and so Xn ff, (f)') = 0; that is to say we have proved the formula\n\nPn (cos i') = Pn (cos 6) Pn (COS 6') + 2 2 ) '- . Pn'\" (COS 6) Pn\"\"\n(COS 6') COS 711 (j>- (f)'),\n\nm-1 n + M) ! wherein it is obvious that\n\ncos ]' = cos 6 cos 6' + sin 6 sin 0' cos (0 - < '), from geometrical\nconsiderations.\n\nWe have thus obtained a physical proof of a theorem proved elsewhere*\n(§ I5\"7) by purely analytical reasoning.]\n\nExample 1. Find the solution of Laplace's equation analytic inside the\nsphere /=1 which has the value sin 36 cos < at the surface of the\nsphere.\n\n[ s r Pgi (cos 6) cos (f) - irPji (cos 0) cos 0.]\n\nExample 2. Let fii r, 6, (f)) be equal to a homogeneous polynomial of\ndegree n in, y, z. Shew that\n\nl\" I fnla, G, (f)) Pn cos 6 con d' + siudamd' cos (f) -4>') a' sin 6\nd0dcf> J - J o'\n\n-; /.( . '< )-\n\n[Take the direction (6', < ') as a new polar axis.]\n\n\\Section{18}{5}{Solutions of Laplace's equation which involve Bessel\n  coefficients.}\nA particular case of the result of \\hardsectionref{18}{3} is that\n\nQk(z+ixcosu+iysmu, gQg f)iuclu\n\nis a solution of Laplace's equation, k being any constant and m being\nany\n\ninteger.\n\n* The absence of the factor ( - )'\" which occurs in \\hardsectionref{1}{5}-7 is due to\nthe fact that the functions now employed are Ferrers' associated\nfunctions.\n\n%\n% 396\n%\n\nTaking cylindrical-polar coordinates p, (f), z) defined by the\nequations . = p cos, y = p sin 4>, the above solution becomes\n\n kz I gikpcos iu-4>) cos ( dii = gkz i gikpcos V g g . (v + (f)) . clv\n\nJ -IT J - JT\n\n= 2e* I 6**'\" ° \" cos ?HV cos m<pdv\n\nJo\n\n= 2e* cos (mcj)) j e'*'\" ° \" cos mvdv,\n\nJo and so, using \\hardsectionref{17}{1} example 3, we see that 'Itti ' e'' cos (m(f))\n. Jm(f 'p) is a solution of Laplace's equation analytic near the\norigin.\n\nSimilarly, from the expression\n\nT\n\nwhere m is an integer, ive deduce that 27rz'\" e* sin (??i</)) . (kp)\nis a solution of Laplace's equation.\n\n18 \"SI. The periods of vibration of a uniform membrane*.\n\nThe equation satisfied by the displacement V at time t of a point x,\ny) of a uniform plane membrane vibrating harmonically is\n\n'dx cy- c- Ct- '\n\nwhere c is a constant depending on the tension and density of the\nmembrane. The equation can be reduced to Laplace's equation by the\nchange of variable given by z = cti. It follows, from \\hardsectionref{18}{5}, that\nexpressions of the form\n\n'sm sin satisfy the equation of motion of the membrane.\n\nTake as a particular case a drum, that is to say a membrane with a\nfixed circular boundary of radius R.\n\nThen one possible type of vibration is given by the equation\n\nr=t kp) cos m<\\ i cos ckt, provided that F=0 when p = R; so that we\nhave to choose k to satisfy the equation\n\nJ, kR)=0. This equation to determine / has an infinite number of real\nroots \\hardsectionref{17}{3} example 3), 1, 2j 3j  S3,y. A possible type of\nvibration is then given by\n\nr=/, (f-'rp) cosmcf) cos ckrt r= 1, 2, 3,,..).\n\nThis is a periodic motion with period 1iTJ ckj.); and so the\ncalculation of the periods depends essentially on calculating the\nzeros of Bessel coefficients (see 17'9).\n\n Euler, Novi Covim. Acad. Petrop. x. (1764) [published 1766], pp.\n243-260; Poisson, Mem. de I'Academie, viii. (1829), pp. 357-570;\nBourget, Ann. de I'Ecole nvrm.sup. iii. (1866), pp. 55-95. For a\ndetailed discussion of vibrations of membranes, see also Rayleigh,\nTheory of Sound, Chapter ix.\n\n%\n% 397\n%\n\nExample. The equation of motion of air in a circular cylinder\nvibrating per- pendicularly to the axis OZ of the cylinder is\n\ndx dy' c' dt- ' V denoting the velocity potential. If the cylinder\nhave radius R, the boundary condition\n\ndV is that n- =0 when p = R. Shew that the determination of the free\nperiods depends on\n\nfinding the zeros of J,,/ (C) == 0-\n\n\\Section{18}{6}{A general solution of the equation of wave motions.}\nIt may be\nshewn* by the methods of \\hardsectionref{18}{3} that a general solution of the equation\nof wave motions\n\ndx dy'' dz- c- di?\n\nIS\n\nF = I I f(x sin u cos v + y sin u sin v + z cos n + ct, u, v) dudv,\n\nwhere /is a function (of three variables) of the type considered in §\n18\"3.\n\nRegarding an integral as a limit of a sum, we see that a physical\ninterpretation of this equation is that the velocity potential V is\nproduced by a number of plane waves, the disturbance represented by\nthe element\n\nf(x sin u cos v + y sin u sin v + z cos u + ct, u, v) 8u Bv being\npropagated in the direction (sin u cos v, sin u sin v, cos u) with\nvelocity c. The solution therefore represents an aggregate of plane\nwaves travelling in all directions with velocity c.\n\n\\Subsection{18}{6}{1}{Solutions of the equation of wave motions which involve Bessel functions.}\n\nWe shall now obtain a class of particular solutions of the equation of\nwave motions, useful for the solution of certain special problems.\n\nIn physical investigations, it is desirable to have the time occurring\nby means of a factor sin ckt or cos ckt, where k is constant. This\nsuggests that we should consider solutions of the type\n\n/tt rn\n\ny =, \\ I giA;(a;sinttcost;+2/sinMsiuv+2cosM+cti f (u i)\\ dudv\n\nJ -TT J\n\nPhysically this means that we consider motions in which all the\nelementary waves have the same period.\n\nNow let the polar coordinates of (x, y, z) be (r, 6, (f>) and let (o),\nyjr) be the polar coordinates of the direction (u, v) referred to new\naxes such that the polar axis is the direction (ff, (f)), and the\nplane -v/r = passes through OZ; so that\n\ncos CO = cos 6 cos u + sin d sin u cos ((f) - v),\n\nsin II sin ((f) - v) = sin w sin yjr.\n\n* See the paper previously cited, Math. Ann. lvii. (1902), pp.\n342-345, or Messenger of Mathe- matics, XXXVI. (1907), pp. 98-106.\n\n%\n% 398\n%\n\nAlso, take the arbitrary function /(w, y) to be;S,j (w, y) sin i\nwhere Sn denotes a surface harmonic in u, v of degree ?i; so that we\nmay write\n\nSn(u, V) = Sn 0, 4>] CO, yjr),\n\nwhere \\hardsubsectionref{18}{3}{1}) Sn is a surface harmonic in co, -sjr of degree n. We\nthus get\n\nV = e ' ' f r I ' e''\"\"°\"\" Sn 6, < \\ w, y\\ r) sin a> dw df.\n\nNow we may write (§ 18 \"SI)\n\nSn (d, (i>; 0,y r) = An e,(f>). Pn (COS Oj)\n\n+ S \"'\" (0, <f>) cos myfr + Bn'\"' 0, (f)) sin myfr] P \"' (cos co),\n\nm = l\n\nwhere An 6, </>), n'\"'* 6, <p) and 5 \"\"' 6, 0) are independent of yjr\nand co. Performing the integration with respect to -yjr, we get\n\nF= 27re'' ' An 0, 4>) f\"e '*\"° \"P (cos to) sin codco\n\nJo\n\n= 27re' '- A n 0,(ii)j e''\"-' P,, (/i) djM\n\n= 27r. - '* An (, ( ) J' e'* ' - (f. - l)n d,\n\nby Rodrigues' formula (§ loll); on integrating by parts ti times and\nusing Hankel's integral (§ 17 '3 corollary), we obtain the equation\n\n = o;r '\"\" n 0, 4>) ikrY I e'>\"- (1 - /x )\" c yu\n\nZi  'It \\ J 1\n\n= (27r) iV'* ' kr) - -J + (kr) An (6, c >), and so F is a constant\nmultiple of e' ' h-' Jj \\ \\ i(kr) An(0, (f>).\n\nNow the equation of wave motions is unaffected if we multiply x, y, z\nand t by the same constant factor, i.e. if we multiply r and t by the\nsame constant factor leaving Q and unaltered; so that An B, <f)) may\nbe taken to be independent of the arbitrary constant k which\nmultiplies r and t.\n\nHence lim e**-''' r ~ H' ~ \" ~ /, i (kr) An 0, 9) is a solution of\nthe equation\n\nA:-*0\n\nof wave motions; and therefore r' An(0, <f>) is a solution\n(independent of t) of the equation of wave motions, and is\nconsequently a solution of Laplace's equation; it is, accordingly,\npermissible to take An (0, <f>) to be any surface harmonic of degree n\n; and so we obtain the result that\n\nr - Jn+r ih-) Pn''' (cos 0) md> ckt 2 sm sm\n\nis a particular solution of the equation of wave motions.\n\n%\n% 399\n%\n\n\\Subsubsection{18}{6}{1}{1}{Application of \\hardsubsectionref{18}{6}{1}\n  to a physical problem.}\n\nThe solution just obtained for the equation of wave motions may be\nused in the following manner to determine the periods of free\nvibration of air contained in a rigid sphere.\n\nThe velocity potential T' satisfies the equation of wave motions and\nthe boundary\n\ndV condition is that - =- =0 when ? =, where a is the radius of the\nsphere. Hence\n\nor\n\n~\\ -,,i.r,, /iv COS, COS,\n\nY-r *J,.(/-/),™ cos<9) . wd) . ckt \"+- \" sm sin\n\ngives a possible motion if Z* is so chosen that\n\nThis equation determines k; on using \\hardsubsectionref{17}{2}{4}, we see that it may be\nwritten in the form\n\ntan ka = ka)\n\nwhere f (ka) is a rational function of ka.\n\nIn particular the radial vibrations, in which V is independent of 6\nand <, are given by taking n = 0; then the equation to determine k\nbecomes simply\n\ntan ka = ka; and the pitches of the fundamental radial vibrations\ncorrespond to the roots of this equation.\n\nREFERENCES.\n\nJ. Fourier, La theorie analytique de la Chaleur. (Translated by A.\nFreeman.)\n\nW. Thomson and P. G. Tait, Natural Philosophy. (1879.)\n\nLord Rayleigh, Theory of Sound. (London, 1894-1896.)\n\nF. PoCKELS, Uber die partielle Diferentialgleichung /\\ u + khi. = 0.\n(Leipzig, 1891.)\n\nH. BuRKHARDT, Eiitivickelungen nach oscillirenden Funktionen.\n(Leipzig, 1908.)\n\nH. Bateman, Electrical and Optical Wave-motion. (1915.)\n\nE. T. Whittaker, History of the Theories of Aether and Electricity.\n(Dublin, 1910.)\n\nA. E. H. Love, Proc. London Math. Soc. xxx. (1899), pp. 308-321.\n\nH. Bateman, Proc. London Math. Soc. (2), i. (1904), pp. 451-458.\n\nL. N. G. FiLON, Philosophical Magazine (6), vi. (1903), pp. 193-213.\n\nH. Bateman, Proc. London Math. Soc. (2), vii. (1909), pp. 70-89.\n\nMiscellaneous Examples.\n\n1. If V be a solution of Laplace's equation which is symmetrical with\nrespect to OZ, and if y=f z) on OZ, shew that if f \\ be a function\nwhich is analytic in a domain of values (which contains the origin) of\nthe complex variable f, then\n\n'=i r - + i(.r2+j/2)5cos0 rf( /\n\nat any point of a certain three-dimensional region.\n\nDeduce that the potential of a uniform circular ring of radius c and\nof mass M lying in the plane XO T with its centre at the origin is\n\n  r [ + + ( ' + '/) cos (/) 2] - I d<t>.\n\n7!\" y\n\n%\n% 400\n%\n\n2. If r be a solution of Laplace's equation, which is of the form\ne\"\"*jP(p, 2), where\n\n(p, (f>, z) are cylindrical coordinates, and if this solution is\napproximately equal to\n\np\"'e\"\"*/(i) near the axis of z, where /(f) is of the character\ndescribed in example 1, shew that\n\n = r ( i+ 1 ) r (*) / ' \" '''' ' '\"\"\" ' - \\addexamplecitation{DougaU.}\n\n3. If ? be determined as a function of .r, y and z by means of the\nequation\n\nA.v+By + Cz=\\, where A, B, C are functions of ?< such that\n\nshew that (subject to certain general conditions) any function of is a\nsolution of\n\nLaplace's equation.\n\n(Forsyth, Messenger, xxvii. (1898), pp. 99-118.)\n\n4. A, B are two points outside a sphere whose centre is C. A layer of\nattracting matter on the surface of the sphere is such that its\nsurface density (Tp at P is given by the formula\n\napCc AP.BP)-\\\n\nShew that the total quantity of matter is unaffected by varying A and\nB so long as\n\nCA . CB and ACB are unaltered; and prove that this result is\nequivalent to the theorem\n\nthat the surface integral of two harmonics of different degrees taken\nover the sphere\n\nIS zero.\n\n(Sylvester, Phil. Mag. (5), il. (1876), pp. 291-307.)\n\n5. Let V (.r, y, z) be the potential function defined analytically as\ndue to particles of masses X + iy., X - z/x at the points (a + ia', b\n+ ib', c + ic') and (a - ia', b - ib', c - ic') respectively. Shew\nthat V x, y, z) is infinite at all points of a certain real circle,\nand if the point (.r, y, z) describes a circuit intertwined once with\nthis circle the initial and final values of V x,y, z) are numerically\nequal, but opposite in sign.\n\n(Appell, Math. Ann. xxx. (1887), pp. 155-156.)\n\n6. Find the solution of Laplace's equation analytic in the region for\nwhich a<r<iA, it being given that on the spheres /=a and r = A the\nsolution reduces to\n\n2 c P (cos(9), 2 C;P (cos<9), respectively.\n\n7. Let 0' have coordinates (0, 0, c), and let\n\nPdz=6, P0'Z=6', PO = r, PO' = r'. Shew that\n\nP cos6') \\ P cosd ) . .s cPn i(cos ) jn + 1) Qi + 2) c'' P + cos d) (\nY\" f I (n I 1) - 1 ( \" ) 1 n + l) n + 2) r 'P, oo,d) 1\n\n\"~ / Un + l V\" / pn + 2 ' 2! C\"\" T...|,\n\naccording as r>c or r<c.\n\nObtain a similar expansion for /\"P ' (cos ). \\addexamplecitation{Trinity, 1893.}\n\n8. At a point (r, 6, (p) outside a uniform oblate spheroid whose\nsemi-axes are a, b and whose density is p, shew that the potential is\n\n)a-b\n\n;\\ \\ \\ m Pj (cos 0) m P (cos 6)\n\n-...].\n\n3/- 3.5 r b.l r°\n\nwhere ni - a--b- and ?>? .. Obtain the i otential at points for which\nr<m.\n\n\\addexamplecitation{St John's, 1899.}\n\n%\n% 401\n%\n\n9. Shew that\n\neirco,e=( )i I in [271 + 1) r-lP cos 6) J +i(r).\n\nn =\n\n\\addexamplecitation{Bauer, Journal fiir Math, lvi.}\n\n10*. Shew that if x ±iy = h cosh (| + irj), the equation of\ntwo-dimensional wave motions in the coordinates and ? is\n\na|7 + 5 = ( h- 1 - cos2 rj) - . \\addexamplecitation{Lame.}\n\nIL Let X - c + r cos 6) cos (p, y = c + r cos 6) sin cp, 2 = /-sin;\n\nshew that the surfaces for which /, d, (f) respectively are constant\nform an orthogonal .system; and shew that Laplace's equation in the\ncoordinates /, \\&, is\n\n- - r(c + '/-cos ) +-; (c + ?-cos(9)-; [+- 7., =0.\n\nvr \\ a- j r 06 \\ j- ' cd \\ c + rcosdd(f>-\n\n(W. D. Xiven, J/essenger, x.)\n\n12. Let P have Cartesian coordinates x, ? z) and polar coordinates\n(;, 6, (f)). Let the plane POZ meet the circle x' + t/' = k-, s = in\nthe points a, y; and let\n\naPy = (o, log (Pa/Py) = a. Shew that Laplace's equation in the\ncoordinates o-, a>, (p is\n\n8 f sinho- bV] d j sinho- \\ 871 1 -0-\n\nda- [cosh o- - cos a da j ca (cosh a - cos o) 8w j sinh o- (cosh cr -\ncos w) 8( 2 ' and shew that a solution is\n\nV= (cosh o\" - cos 0)) cos /iQ) cos ??i0 P (cosh o-).\n\n(Hicks, Phil. Trans. CLXXii. p. 617 et seq.)\n\n13. Shew that\n\n00 -hn i r-j- r\n\n R + p -2Rpcoscl) + c-)-h= 2 I dk I e-\"\" J, I- p)e' ' ''°\"' cos\nrauclu,\n\nm=0 y J -T\n\nand deduce an expression for the potential of a particle in terms of\nBessel functions.\n\n14. Shew that if a, b, c are constants and X, /x, v are confocal\ncoordinates, defined as the roots of the equation in e\n\na2 + e' 6- + e' 6-2 + 6 ' then Laplace's equation may be written\n\nAx(M-) xf + M(-X)| A/J +A.(X-M) A. ]=0,\n\nwhere A;, = V (aHX) (i' + X) (c- + X) .\n\n\\addexamplecitation{Lame.}\n\n* Examples 10, 11, 12 and 14 are most easily proved by using Lame's\nresult (Journal de VEcole Polyt. xiv. cahier 23 (1834), pp. 191-288)\nthat if (X, /ul, v) be orthogonal coordinates for which the\nline-element is given by the formula dx)'' + (8yf + 5zy =(H d\\ y +\n(H2diM)'- + H 5v)', Laplace's equation in these coordinates is\n\nd fH.H cV\\ 8 / H. H, dV\\ 8 / H,H., dV\\ \\\n\n'Hi-\n\nd\\ V Hi a,\\ J dfjL\\ H., d/jiJ di'\\ Hs dv A simple method (due to W.\nThomson, Camh. Math. Journal, iv. (1845), pp. 83-42) of proving this\nresult, by means of arguments of a physical character, is reproduced\nby Lamb, Hydro- dynamics (1916), § 111. Analytical proofs, based on\nLame's proof, are given by Bertrand, Traite de Calcul Differentielle\n(1864), pp. 181-187, and Goursat, Coiirs d'Analyse, i. (1910), pp.\n155-159, the last proof being appreciably the simplest. Another proof\nis given by Heine, Theorie der Kugelfunctionen, i. (1878), pp.\n303-306.\n\nW. M. A. 26\n\n%\n% 402\n%\n\n15. Shew that a general solution of the equation of wave motions is\n\nr= F .v coH 6 + iiin \\$ + iz, >/ + iz siu 6 + ct cos B, B)dd.\n\nJ -IT\n\n(Bateman, Proc. London Math. Soc. (2) l. (1904), p. 457.)\n\n16. If r=/(.r, y, z, t) be a solution of\n\nd ct cx' cy' dz- ' prove that another solution of the equation is\n\n17. Shew that a general solution of the equation of wave motions, when\nthe motion is independent of <, is\n\n/ / (2 + ip cos e, ct + p sin 6) dO\n\nf' /\"\", / a - z + ct cos d\\,,,.,\n\n+ arc suih - r- ) F (a, 6) dBda,\n\nJ (1 .' -TT \\ p sin / ' '\n\nwhere p, (f>, z are cylindrical coordinates and a, h are arbitrary\nconstants.\n\n(Bateman, Proc. London Math. Soc. (2) i. (1904), p. 458.)\n\n\"18. If r=/(.r, y, z) is a solution of Laplace's equation, shew that\n\nY 1 / r -a r +gg az \\\n\n~( \\, )i-' V2(.'--i ' i x-iyy x-iy)\n\nis another solution.\n\n(Bateman, Proc. London Math. Soc. (2) vii. (1909), p. 77.)\n\n19. If U=f x, y, z, t) is a solution of the equation of wave motions,\nshew that another solution is\n\nrj 1 .( X y \\ r2-l rHl \\\n\nz-ct-'Xz-ct'' z-ct\" z-cty 2c z-ct))'\n\n(Bateman, Proc. London Math. Soc. (2) vii. (1909), p. 77.)\n\n20. If l=x-iy, m = z + hv, n = . : - + y' + z - + iv%\n\n\\ = j:+iy, fji = z-uv, p= - \\, so that l\\ + 7nfi + nv=0,\n\nshew that any homogeneous solution, of degree zero, of\n\ncHT cH[ dH/ c U Q dx' dy cz dw\n\nsatisfies +Z£+ =0-\n\ndldX dmdfi dndv '\n\nand obtain a solution of this equation in the form\n\nj', b, c \\\n\nU', ', y' )\n\nwhere = ( -c) (f-a),. ? /Li = (c-a) (f-6), np = (a- b) ((-c).\n\n(Bateman, Proc. London Math. Soc. (2) vii. (1909), pp. 78-82.)\n\n%\n% 403\n%\n\n21*. If (r, 6, (f)) are spheroidal coordinates, defined by the\nequations\n\njr = c (r + iy sin cos<, y=c (r2-|-l) sin sin(, z=crcosd,\n\nwhere x, y, z are rectangular coordinates and c is a constant, shew\nthat, when n and m are integers,\n\n('\" /. cos + y sin -f i2\\ cos, (n - in)\\ \\,., cos\n\nPn\\ -] mtdt = 27ry- - P,r tr)Pn'\" cos 6) . md).\n\nj -n- \\ c /Sin n+m)l \" sin\n\n(Blades, Proc. Edinburgh Math. Soc. xxxiii.) 22. With the notation of\nexample 21, shew that, if 2 =t= 0,\n\n/ /cPcos + y sin +i'2\\ cos,, (n - m)l, . s -r, / cos Qn - - ) intdt\n= 277 )--- -fj § ' ir) P ' cos e) . m4>. -r \\ c J Sin (n+m) i \" -' \" '\nsin\n\n(Jeffery, Proc. Edinburgh Math. Soc. xxxiil.)\n\n* The functions introduced in examples 21 and 22 are known as internal\nand external spheroidal harmonics respectively.\n\n26-2\n", "meta": {"hexsha": "b7c57fcc5a37fec35f91277ff10718b69000e818", "size": 36861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch18.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-ch18.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-ch18.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": 29.822815534, "max_line_length": 96, "alphanum_fraction": 0.6840020618, "num_tokens": 11748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6630157089974849}}
{"text": "\\section{Momentum Equilibrium and Elbow Angle Optimization}\n\\label{sec:72methodology}\n\n\\minitoc[-7mm]{70mm}{4}\n\n\\noindent\nIn this section, we give an overview of the methodology of our approach.\nWe continue following the presentation of \\cite{Valentin18Gradient}.\n\n\n\n\\subsection{From Muscle Forces to Equilibrium Angles}\n\\label{sec:721equilibrium}\n\n\\paragraph{Model inputs and outputs}\n\nIn the following, we regard simulations of the\nhuman upper limb model described in \\cref{sec:71model} as a black box,\nwhich receives as its input\nthe elbow angle $\\elbang \\in \\clint{\\ang{10}, \\ang{150}}$\nand the activation parameters\n$(\\actT, \\actB) \\in \\clint{\\*0, \\*1} = \\clint{0, 1}^2$\nof triceps and biceps.%\n\\footnote{%\n  Here and in the following, the subscripts T, B, and L stand for\n  triceps, biceps, and load, respectively.%\n}\nThe outputs of the black box simulation are the forces\n$\\forceT(\\elbang, \\actT)$ and $\\forceB(\\elbang, \\actB)$\nthat triceps and biceps exert.\nThese forces depend on the elbow angle as well as on the respective\nactivation parameter.\nGravitational forces due to the masses of bones or muscles\nare neglected in this context.\nHowever, we allow the specification of an external load $\\forceL$,\nwhich is applied to the end of the forearm.\nThis load may be the weight force of some object\nthat the arm is supposed to keep in position.\n\n\\paragraph{Moments and lever arms}\n\nEach force exerts a \\term{moment} (or \\term{torque}) on the elbow joint.\nThe moments are the products of the forces $\\forceX$\nwith the respective lever arms $\\armX$\n($X \\in \\{\\mathrm{T}, \\mathrm{B}, \\mathrm{L}\\}$).\nThe lever arms are approximated as in\n\\multicite{Roehrle16Two,Valentin18Gradient} by using\nthe tendon-displacement method of \\cite{An84Determination}:\n\\begin{subequations}\n  \\begin{align}\n    \\armT(\\elbang)\n    &\\ceq (-0.0009399 \\{\\elbang\\}^2 + 0.1126 \\{\\elbang\\} + 22.21)\\;\n    \\si{\\milli\\meter},\\\\\n    \\armB(\\elbang)\n    &\\ceq (-0.001482 \\{\\elbang\\}^2 + 0.1776 \\{\\elbang\\} + 35.02)\\;\n    \\si{\\milli\\meter},\\\\\n    \\armL(\\elbang)\n    &\\ceq \\sin(\\elbang) \\cdot \\SI{282.5}{\\milli\\meter},\n  \\end{align}\n\\end{subequations}\nwhere $\\{\\elbang\\}$ denotes the dimensionless value of $\\elbang$\nin degrees.\nThe lever arms are non-negative and the forces are signed, i.e.,\npositive forces pull the forearm downwards and\nnegative forces pull it upwards.\nIn general, $\\forceT, \\forceL \\ge \\SI{0}{\\newton}$ and\n$\\forceB \\le \\SI{0}{\\newton}$.\n\n\\paragraph{Total moment and equilibrium elbow angle}\n\nThe \\term{total moment} of the system is given by the function\n\\begin{subequations}\n  \\label{eq:totalMoment}\n  \\begin{gather}\n    \\moment_{\\forceL,\\actT,\\actB}\\colon\n    \\clint{\\ang{10}, \\ang{150}} \\to \\real,\\\\\n    \\moment_{\\forceL,\\actT,\\actB}(\\elbang)\n    \\ceq \\forceT(\\elbang, \\actT) \\armT(\\elbang) +\n    \\forceB(\\elbang, \\actB) \\armB(\\elbang) +\n    \\forceL \\armL(\\elbang),\n  \\end{gather}\n\\end{subequations}\ncf.\\ \\cite{Valentin18Gradient}.\nThe system is in \\term{equilibrium}\nif the total moment vanishes, i.e.,\n$\\moment_{\\forceL,\\actT,\\actB}(\\elbang) = \\SI{0}{\\newton\\meter}$.\nWe call the corresponding angle $\\elbang$ the\n\\term{equilibrium elbow angle}\nfor the load $\\forceL$ and the activation parameters $\\actT, \\actB$.\nTo find this angle for a given load $\\forceL$ and activation parameters\n$\\actT$ and $\\actB$, we first note that\n$\\moment_{\\forceL,\\actT,\\actB}$ may have zero, exactly one,\nor multiple zeros in $\\clint{\\ang{10}, \\ang{150}}$.\nHence, the inverse function evaluated at $\\SI{0}{\\newton\\meter}$\nis partially defined depending on the load and the activation parameters:\n\\begin{equation}\n  \\label{eq:equilibriumAngle}\n  \\equielbang{\\forceL}\\colon \\actdomain{\\forceL} \\!\\to\n  \\clint{\\ang{10}, \\ang{150}},\\quad\n  \\actdomain{\\forceL} \\subset \\clint{\\*0, \\*1},\\quad\n  \\equielbang{\\forceL}(\\actT,\\actB)\n  \\ceq (\\moment_{\\forceL,\\actT,\\actB})^{-1}(\\SI{0}{\\newton\\meter}),\n\\end{equation}\nwhich is well-defined whenever $\\moment_{\\forceL,\\actT,\\actB}$\nhas a unique root.\nWe approximate $\\equielbang{\\forceL}(\\actT,\\actB)$ with the Newton method\n\\multicite{Roehrle16Two,Valentin18Gradient}:\n\\begin{equation}\n  \\label{eq:newtonAngle}\n  \\elbang^{(j+1)}\n  \\ceq \\elbang^{(j)} -\n  \\frac{\n    \\moment_{\\forceL,\\actT,\\actB}(\\elbang^{(j)})\n  }{\n    \\partialderiv{\\partialdiff{} \\elbang}{\\moment_{\\forceL,\\actT,\\actB}}\n    (\\elbang^{(j)})\n  },\\quad\n  j \\in \\nat,\n\\end{equation}\nwith an initial value\n$\\elbang^{(0)} \\in \\clint{\\ang{10}, \\ang{150}}$\nand the stopping criterion of\n$\\abs{\\moment_{\\forceL,\\actT,\\actB}(\\elbang^{(j)})} <\n\\SI{e-9}{\\newton\\meter}$.\nWe repeat the Newton method for the initial values\n$\\elbang^{(0)} = \\ang{80}, \\ang{40}, \\ang{120}$\nand use the first converged result\n(i.e., we check if $\\elbang^{(0)} = \\ang{80}$ converges;\nif not, we proceed with $\\elbang^{(0)} = \\ang{40}$, and so on).\nIf all three initial values do not converge,\nwe conclude that $(\\actT, \\actB) \\notin \\actdomain{\\forceL}$.\n\n\n\n\\subsection{Optimization Problems}\n\\label{sec:722optimization}\n\n\\paragraph{General problem}\n\nThe general problem in our setting is as follows:\nFor a given external load $\\forceL$ and a target elbow angle $\\tarelbang$,\nfind activation parameters $(\\actT, \\actB) \\in \\clint{\\*0, \\*1}$\nsuch that the target elbow angle is attained in the equilibrium,\ni.e., $\\equielbang{\\forceL}(\\actT,\\actB) = \\tarelbang$.\nExample applications of such a scenario are medicine and robotics,\nwhen a specific movement should be carried out.\n\n\\paragraph{List of optimization problems}\n\nAs discussed in \\cref{sec:711models},\nmusculoskeletal systems with an antagonistic muscle pair\nsuch as our human upper limb model are usually overdetermined.\nThis means that there are multiple solutions to this general problem.\nAs a remedy, one may solve one of the following two\noptimization problems \\cite{Valentin18Gradient}:\n\n\\begin{enumerate}[label=O\\arabic*.,ref=O\\arabic*,leftmargin=2.7em]\n  \\item\n  \\label{item:biomech2MinSum}\n  For a given external load $\\forceL$ and a target angle\n  $\\tarelbang \\in \\clint{\\ang{10}, \\ang{150}}$,\n  find the activation parameters $(\\actT, \\actB) \\in \\clint{\\*0, \\*1}$\n  such that $\\actT + \\actB$ is minimized under the constraint\n  $\\equielbang{\\forceL}(\\actT, \\actB) = \\tarelbang$.\n  \n  \\item\n  \\label{item:biomech2MinDist}\n  For a given external load $\\forceL(t_2)$ for a time $t_2 > t_1$,\n  a target angle $\\tarelbang(t_2) \\in \\clint{\\ang{10}, \\ang{150}}$,\n  and initial activation parameters\n  $(\\actT(t_1), \\actB(t_1)) \\in \\clint{\\*0, \\*1}$,\n  find new activation parameters\n  $(\\actT(t_2), \\actB(t_2)) \\in \\clint{\\*0, \\*1}$ such that\n  $(\\actT(t_2) - \\actT(t_1))^2 + (\\actB(t_2) - \\actB(t_1))^2$\n  is minimized under the constraint\n  $\\equielbang{\\forceL(t_2)}(\\actT(t_2), \\actB(t_2)) = \\tarelbang(t_2)$.\n\\end{enumerate}\n\n\\noindent\nThe motivation of both problems is that the human body tries to\nachieve a given movement with minimal energy effort.\n\n\\paragraph{Motivation of problem \\ref{item:biomech2MinSum}}\n\nFor the first problem \\ref{item:biomech2MinSum},\nthis effort is quantified by $\\actT + \\actB$,\ni.e., the energy effort for each muscle is assumed to be proportional\nto its activation parameter.\n\n\\paragraph{Motivation of problem \\ref{item:biomech2MinDist}}\n\nThe second problem \\ref{item:biomech2MinDist} is motivated as follows:\nBefore time $t = t_1$, the musculoskeletal system is in equilibrium for\nthe external load $\\forceL(t_1)$,\nactivation parameters $\\actT(t_1), \\actB(t_1)$, and elbow angle\n$\\tarelbang(t_1) \\ceq \\equielbang{\\forceL(t_1)}(\\actT(t_1), \\actB(t_1))$, i.e.,\n$\\moment_{\\forceL(t_1),\\actT(t_1),\\actB(t_1)}(\\tarelbang(t_1))\n= \\SI{0}{\\newton\\meter}$.\nDirectly after $t = t_1$,\nthe external force and/or the target angle is suddenly changed\nto $\\forceL(t_2)$ and $\\tarelbang(t_2)$, respectively.\nConsequently, triceps and biceps adapt their activation parameters\nsuch that the musculoskeletal system returns to equilibrium\nat some time $t = t_2 > t_1$.\nHence, we have to determine the new activation parameters\n$\\actT(t_2), \\actB(t_2)$ such that\n$\\moment_{\\forceL(t_2),\\actT(t_2),\\actB(t_2)}(\\tarelbang(t_2))\n= \\SI{0}{\\newton\\meter}$.\nAgain, these parameters\n$\\actT(t_2)$ and $\\actB(t_2)$ are not uniquely determined.\nTherefore, we want to find the pair of activation parameters\nthat is closest (in terms of the Euclidean norm) to the initial\nactivation parameters $\\actT(t_1), \\actB(t_1)$.\n\n\\paragraph{Optimization method}\n\nProblems \\ref{item:biomech2MinSum} and \\ref{item:biomech2MinDist}\nare both constrained optimization problems.\nFor their solution, we employ the augmented Lagrangian method as\ndescribed in \\cref{sec:513gradientBasedConstrained}\nusing an adaptive gradient descent algorithm\nfor the gradient-based optimization of the penalized objective function\n(see \\cref{sec:512gradientBasedUnconstrained}).\n\n\n\n\\subsection{B-Spline Surrogates on Sparse Grids}\n\\label{sec:723surrogates}\n\n\\paragraph{Complexity}\n\nTo solve optimization problems\n\\ref{item:biomech2MinSum} and \\ref{item:biomech2MinDist},\nthe optimization method needs to evaluate the objective\nand constraint functions multiple times during the algorithm.\nThis requires the evaluation of $\\equielbang{\\forceL}$,\nwhich in turn has to be approximated with the Newton method.\nAs we see in \\cref{eq:newtonAngle},\neach iteration of the Newton method needs not only the values of the\nmuscle forces $\\forceT$ and $\\forceB$, but also their\npartial derivatives with respect to $\\elbang$.\nThese partial derivatives have to be approximated with finite differences.\n\nUnfortunately, simulations of continuum-mechanical models are\ncomputationally expensive.\nOne evaluation of the muscle force pair $\\forceT, \\forceB$\nrequires the solution of a solid mechanics model\nwith a complex constitutive law, pre-stretch, and contact between\nbone and muscles \\cite{Valentin18Gradient}.\nOn average, a single evaluation of $\\forceT$ and $\\forceB$ takes\nabout half an hour on current desktop computers.\n%\nIf we assume that we need four Newton iterations on average,\nthen a single iteration of the optimization algorithm to solve\nproblems \\ref{item:biomech2MinSum} and \\ref{item:biomech2MinDist}\nwill take four hours to complete\n(assuming one evaluation of objective and constraint functions\nper optimizer iteration and\ntwo evaluations of the muscle force pair\nper Newton iteration to approximate the missing derivative).\nConsequently, the whole optimization process takes\ntwo weeks to complete, if the optimizer converges after 100 iterations.\n\n\\paragraph{Sparse grid surrogates}\n\nA popular way to reduce complexity is to employ surrogates.\nIn this case, the idea is to replace the muscle force functions\n$\\forceT, \\forceB$ with surrogates $\\forceTintp, \\forceBintp$\n\\cite{Valentin18Gradient}, e.g., by interpolation.\nWe then automatically obtain a surrogate\n\\begin{subequations}\n  \\label{eq:totalMomentSurrogate}\n  \\begin{gather}\n    \\momentintp_{\\forceL,\\actT,\\actB}\\colon\n    \\clint{\\ang{10}, \\ang{150}} \\to \\real,\\\\\n    \\momentintp_{\\forceL,\\actT,\\actB}(\\elbang)\n    \\ceq \\forceTintp(\\elbang, \\actT) \\armT(\\elbang) +\n    \\forceBintp(\\elbang, \\actB) \\armB(\\elbang) +\n    \\forceL \\armL(\\elbang),\n  \\end{gather}\n\\end{subequations}\nfor the total moment (cf.\\ \\cref{eq:totalMoment}) and,\nconsequently, a surrogate\n\\begin{equation}\n  \\label{eq:equilibriumAngleSurrogate}\n  \\equielbangintp{\\forceL}\\colon \\actdomainintp{\\forceL} \\!\\to\n  \\clint{\\ang{10}, \\ang{150}},\\quad\n  \\actdomainintp{\\forceL} \\subset \\clint{\\*0, \\*1},\\quad\n  \\equielbangintp{\\forceL}(\\actT,\\actB)\n  \\ceq (\\momentintp_{\\forceL,\\actT,\\actB})^{-1}(\\SI{0}{\\newton\\meter}),\n\\end{equation}\nfor the equilibrium elbow angle function (cf.\\ \\cref{eq:equilibriumAngle}).\nSince the surrogates are much cheaper to evaluate,\nthe computation time is decreased by up to seven orders of magnitude,\nas experiments show.\n\nThe approach in \\cite{Valentin18Gradient} and in this thesis is\nto determine surrogates\n$\\forceXintp\\colon \\clint{\\*0, \\*1} \\to \\real$\n($X \\in \\{\\mathrm{T}, \\mathrm{B}\\}$) by sparse grid interpolation.\nCompared to surrogate construction techniques based on full grids,\nsparse grids help to reduce the number of samples that\nare necessary to build ``reasonably'' accurate surrogates,\nespecially if the number of dimensions is moderately large\n($d \\ge 4$, \\term{curse of dimensionality}).\n\nThe present model only has $d = 2$ dimensions ($\\actT$ and $\\actB$),\nsince the model contains only two muscles.\nHowever, as we will see,\nalready for this low-dimensional problem,\nsparse grids outperform conventional full grid interpolation.\nThe results have to be seen as a proof of concept.\nOne will be able to handle higher dimensionalities\n(i.e., models with a larger number of muscles) similarly with little\nor even no adjustments at all.\nThe low dimensionality of the model in this thesis\nenables us to compute and compare against reference solutions,\nwhich would not be possible in a higher-dimensional setting.\n\n\n\n\\paragraph{Benefiting from B-splines}\n\nAs in \\cite{Valentin18Gradient},\nwe use higher-order hierarchical B-splines as basis functions\nfor the sparse grid surrogates.\nThis has three advantages when compared with conventional\nsparse grid bases such as piecewise linear functions:\n%\nFirst, the partial derivative\n$\\partialderiv{\\partialdiff{} \\elbang}{\\momentintp}$ needed\nfor the Newton method in \\cref{eq:newtonAngle} is continuous and\nexplicitly known.\nThere is no need to approximate the derivative with\nfinite differences, reducing both error and computation time.\n%\nSecond, we can use gradient-based optimization methods\nfor the solution of the optimization problems \\ref{item:biomech2MinSum} and\n\\ref{item:biomech2MinDist},\nwhich involve the equilibrium elbow angle function\n$\\equielbangintp{\\forceL}\\colon \\clint{\\*0, \\*1} \\to \\real$.\nWith the implicit function theorem \\cite{Kudryavtsev95Implicit},\nwe obtain for the derivative of $\\equielbangintp{\\forceL}$\n\\begin{equation}\n  \\gradient{\\actT,\\actB}{\\equielbangintp{\\forceL}}\n  = -\\,(\\gradient{\\actT,\\actB}{\\momentintp}) \\cdot\n  (\\gradient{\\elbang}{\\momentintp})^{-1}\n  = -\\,\\frac{\n    \\gradient{\\actT,\\actB}{\\momentintp}\n  }{\n    \\partialderiv{\\partialdiff{} \\elbang}{\\momentintp}\n  },\n\\end{equation}\nwhere $\\gradient{\\actT,\\actB}{}$ is the transposed Jacobian\nwith respect to $\\actT$ and $\\actB$.%\n\\footnote{%\n  For example, the first column is the gradient with respect to $\\actT$\n  and the second column is the gradient with respect to $\\actB$.%\n}\nFor B-splines,\nboth the transposed Jacobian $\\gradient{\\actT,\\actB}{\\momentintp}$ and\nthe partial derivative $\\partialderiv{\\partialdiff{} \\elbang}{\\momentintp}$\nare continuous, explicitly known, and can be evaluated fast.\n%\nThird and finally,\nthe usage of higher-order B-splines as basis functions\nincreases the order of convergence of interpolation errors\nas shown for test functions in \\cref{sec:541interpolation}.\nThus, fewer interpolation points are necessary to construct a surrogate\nwith the same error as for piecewise linear functions.\n", "meta": {"hexsha": "1d98bb24153bc3a96ad2e534b501263759b207c3", "size": 14925, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/72methodology.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/72methodology.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/72methodology.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": 40.2291105121, "max_line_length": 79, "alphanum_fraction": 0.7408375209, "num_tokens": 4463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6630157063343923}}
{"text": "%!TEX root = maths.tex\n\\newcommand{\\adj}{\\text{adj}\\,}\n\\newcommand{\\identitymatrix}{\\begin{bmatrix*}[c]1&0&0\\\\0&1&0\\\\0&0&1\\end{bmatrix*}}\n\\begin{document}\n\\chapter{Matrices II}\n\\section{Determinant of a 3x3 Matrix}\nThe determinant of a 3x3 matrix is calculated by extracting a row of 2x2 determinants from the given 3x3 matrix. These 2x2 determinants are referred to as minors.\n\n\\begin{example}\n\tFind the determinant of the matrix $\\mathbf A = \\left(\\begin{smallmatrix*}[r]\n\t2 &-1 &4\\\\\n\t3 &0 &-3\\\\\n\t4 &5 &6\n\t\\end{smallmatrix*}\\right)$\n\\end{example}\n\\section{[Parentheses about vector product]}\nConsider the vectors $\\mathbf{a} = x_1\\mathbf{i} + y_1\\mathbf{j} + z_1\\mathbf{k}$ and b $\\mathbf{b} = x_2\\mathbf{i} + y_2\\mathbf{j} + z_2\\mathbf{k}$.\\\\\n\nSince vector product is distributive across addition:\\\\\n\n\\begin{align*}\n\t\\mathbf{a} \\times \\mathbf{b} & = \\left(  x_1\\mathbf{i} + y_1\\mathbf{j} + z_1\\mathbf{k} \\right) \\times \\left( x_2\\mathbf{i} + y_2\\mathbf{j} + z_2\\mathbf{k} \\right)\\\\\n\t&+\\cancel{x_1x_2(\\mathbf i \\times \\mathbf i)} + x_1y_2(\\mathbf i \\times \\mathbf j) + x_1z_2(\\mathbf i \\times \\mathbf k)\\\\\n\t&+ y_1x_2(\\mathbf j \\times \\mathbf i) + \\cancel{y_1y_2(\\mathbf j \\times \\mathbf j)} + y_1z_2(\\mathbf j \\times \\mathbf k)\\\\\n\t&+z_1x_2(\\mathbf k \\times \\mathbf i) + z_1y_2(\\mathbf k \\times \\mathbf j) + \\cancel{z_1z_2(\\mathbf k \\times \\mathbf k)}\\\\\n\t&=x_1y_2\\mathbf k - x_1z_2\\mathbf j - y_1x_2 \\mathbf k + y_1z_2\\mathbf i +z_1x_2\\mathbf j -z_1y_2\\mathbf i\\\\\n\t&=(y_1z_2-z_1y_2)\\mathbf i - (x_1z_2 - z_1 x_2)\\mathbf j + (x_1y_2-y_1x_2)\\mathbf k\n\\end{align*}\n\n\\section{Some properties of determinant}\nThe value of the determinant is unaltered if all the rows and columns of a given matrix are interchanged. If the above happens, the resulting determinant will be of opposite sign.\\\\\n If one row/column of a determinant $D$ is multiplied by $\\lambda$, the resulting determinant is equal to $\\lambda D$\n\n\\section{The Inverse of a 3x3 matrix}\n\n\n\\subsection{Matrix of cofactors}\nConsider the matrix $\\mathbf A = \\begin{bmatrix}a&b&c\\\\d&e&f\\\\g&h&i\\end{bmatrix}$\\\\\n\n\\noindent For each element of any given matrix $\\mathbf A$:\n\t\\begin{itemize}\n\\item{Ignore the values of the current row and column.}\n\\item{Calculate the determinant of the remaining values.}\n\\item{Apply alternating signs starting from $+$.}\n\\item{Input this determinant into a new matrix}\n\t\\end{itemize}1\nThe result would be the below matrix referred to as \\emph{the matrix of co-factors}.\n\n\\[\n\\mathbf C=\n\\begin{bmatrix*}[r]\n\t\\begin{vmatrix}e&f\\\\h&i\\end{vmatrix}&&-\\begin{vmatrix}d&g\\\\f&i\\end{vmatrix}&&\\begin{vmatrix}d&e\\\\g&h\\end{vmatrix}\\phantom{-}\\\\\\\\\n\t-\\begin{vmatrix}e&f\\\\h&i\\end{vmatrix}&&\\begin{vmatrix}d&g\\\\f&i\\end{vmatrix}&&-\\begin{vmatrix}d&e\\\\g&h\\end{vmatrix}\\phantom{-}\\\\\\\\\n\t\\begin{vmatrix}e&f\\\\h&i\\end{vmatrix}&&-\\begin{vmatrix}d&g\\\\f&i\\end{vmatrix}&&\\begin{vmatrix}d&e\\\\g&h\\end{vmatrix}\\phantom{-}\n\\end{bmatrix*}\n\\]\n\\subsection{Adjugate matrix}\nThe next step of finding the inverse matrix of $\\mathbf A$ is finding the \\emph{adjugate} matrix of $\\mathbf A$. This is done by obtaining the \\emph{transpose} of the matrix of cofactors, in our case, $\\mathbf C$.\n\\[\n\\adj A =\n\\begin{bmatrix*}[r]\n\\begin{vmatrix}e&f\\\\h&i\\end{vmatrix}&&-\\begin{vmatrix}e&f\\\\h&i\\end{vmatrix}&&\\begin{vmatrix}e&f\\\\h&i\\end{vmatrix}\\phantom{-}\\\\\\\\\n-\\begin{vmatrix}d&g\\\\f&i\\end{vmatrix}&&\\begin{vmatrix}d&g\\\\f&i\\end{vmatrix}&&-\\begin{vmatrix}d&g\\\\f&i\\end{vmatrix}\\phantom{-}\\\\\\\\\n\\begin{vmatrix}d&e\\\\g&h\\end{vmatrix}&&-\\begin{vmatrix}d&e\\\\g&h\\end{vmatrix}&&\\begin{vmatrix}d&e\\\\g&h\\end{vmatrix}\\phantom{-}\n\\end{bmatrix*}\n\\]\n\\subsection{Inverse matrix}\nLet the inverse of a matrix $A$ be $A^{-1}$. It is defined as a matrix of the same size of $A$ such that \\[AA^{-1} = A^{-1}A = I\\]\nThis same matrix $A^{-1}$ is defined more particularly as \\[A^{-1} = \\frac{1}{\\det A}\\quad\\text{adj }A\\]\n\\begin{example}\n\tFind the inverse of the matrix $A = \\begin{pmatrix*}\n\t\t\t\t\t\t\t\t\t\t2&3&1\\\\\n\t\t\t\t\t\t\t\t\t\t1&1&1\\\\\n\t\t\t\t\t\t\t\t\t\t5&-1&0\n\t\t\t\t\t\t\t\t\t\t\\end{pmatrix*}$\n\t\\end{example}\n\\begin{example}\nSolve using the inverse matrix method the system of equations:\\\\\n$x+y+z=7$\\\\\n$x-y+2z=9$\\\\\n$2x+y-z=1$\n\\end{example}\n\\newpage\n\\section{Transformation Matrices in 3D}\n\\subsection{Reflection along the xy plane}\n\n\\begin{center}\n\\begin{tikzpicture}[x=0.5cm,y=0.5cm,z=0.3cm,>=stealth]\n% The axes\n\\draw[->] (xyz cs:x=-5) -- (xyz cs:x=5) node[above] {$x$};\n\\draw[->] (xyz cs:y=-5) -- (xyz cs:y=5) node[right] {$y$};\n\\draw[->] (xyz cs:z=-5) -- (xyz cs:z=5) node[above] {$z$};\n\n\n\\foreach \\coo in {-4,-3,...,4}\n{\n\t\\draw (\\coo,-1.5pt) -- (\\coo,1.5pt);\n\t\\draw (-1.5pt,\\coo) -- (1.5pt,\\coo);\n\t\\draw (xyz cs:y=-0.15pt,z=\\coo) -- (xyz cs:y=0.15pt,z=\\coo);\n}\n%\\draw (xyz cs:y=3,z=2);\n\\end{tikzpicture}\n\\end{center}\n\n\n\\begin{align*}\n\\begin{bmatrix*}[c]1&0&0\\\\0&1&0\\\\0&0&1\\end{bmatrix*} \\rightarrow \\begin{bmatrix*}[c]1&0&0\\\\0&1&0\\\\0&0&-1\\end{bmatrix*}\n\\end{align*}\n\n\\subsection{Rotation along the y-axis}\n\n\\begin{align*}\n\\begin{bmatrix*}[c]1&0&0\\\\0&1&0\\\\0&0&1\\end{bmatrix*} \\rightarrow \\begin{bmatrix*}[c]\\cos\\theta&0&-\\sin\\theta\\\\0&1&0\\\\\\sin\\theta&0&\\cos\\theta\\end{bmatrix*}\n\\end{align*}\n\\subsection{Rotation along the z-axis}\n\n\\begin{align*}\n\\begin{bmatrix*}[c]1&0&0\\\\0&1&0\\\\0&0&1\\end{bmatrix*} \\rightarrow \\begin{bmatrix*}[c]\\cos\\theta&-\\sin\\theta&0\\\\\\sin\\theta&\\cos\\theta&0\\\\0&0&1\\end{bmatrix*}\n\\end{align*}\n\\subsection{Rotation along the z-axis}\n\n\\begin{align*}\n\\begin{bmatrix*}[c]1&0&0\\\\0&1&0\\\\0&0&1\\end{bmatrix*} \\rightarrow \\begin{bmatrix*}[c]1&0&0\\\\0&\\cos\\theta&-\\sin\\theta\\\\0&\\sin\\theta&\\cos\\theta\\end{bmatrix*}\n\\end{align*}\n\\subsection{Enlargement}\nWhen we enlarge (or conversely, reduce) by scale factor $n$, the unit base vector is multiplied by $n$.\\\\\nThus the matrix representing an enlargement by scale factor n is given by:\n\\begin{align*}\nn\\identitymatrix = \\begin{bmatrix*}[c]n&0&0\\\\0&n&0\\\\0&0&n\\end{bmatrix*}\n\\end{align*}\n\\section{Geometric Interpretation of the Determinant}\nConsider an object with volume $V$ transformed by the matrix $\\mathbf A$ with determinant $|\\mathbf A|$. \nThe volume of the image is given by $|\\mathbf A|V$. Thus, the determinant of the transformation matrix denotes the number of times by which th volume of the object increases or decreases.\n\\begin{example}\n\tDescribe the effect on volume in $3$D space of the transformation given by $\\mathbf{A} = \\begin{bmatrix*}[r]1&2&3\\\\5&0&-1\\\\2&4&-3\\end{bmatrix*}$\n\\end{example}\n\n\\begin{example}\n\tFind the images of $P(4,5,1)$, $Q(3,-1,-2)$, $R(6,-2,0)$ under the transformation given by \\\\$\\mathbf A = \\left(\\begin{smallmatrix*}[r]4&3&2\\\\-1&5&0\\\\6&2&-3\\end{smallmatrix*}\\right)$\n\\end{example}\n\\begin{example}\n\tFind the equation of the line which is the image of the line $\\mathbf r = 3\\mathbf i +\\mathbf j +\\mathbf k + \\lambda(2\\mathbf i + \\mathbf j - 5\\mathbf k)$ under the transformation given by $\\mathbf A =\\begin{bmatrix}2&3&1\\\\-1&2&4\\\\0&6&1\\end{bmatrix}$\n\\end{example}\nFind two points on the line.\nFind images of points.\nFind equation of the image line\n\n\\begin{example}\n\tFind the image of the plane $x+2y-7z=2$ under the transformation defined by $\\mathbf A = \\begin{smallmatrix}-1&2&1\\\\-3&1&4\\\\0&1&2\\end{smallmatrix}$\n\\end{example}\n\\end{document}\n\n", "meta": {"hexsha": "ccc8d186e62c2d76f46fc1fef342d98a1477640f", "size": 7138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/matrices2.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/matrices2.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/matrices2.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": 46.6535947712, "max_line_length": 251, "alphanum_fraction": 0.6808629868, "num_tokens": 2831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825006, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6629714940916677}}
{"text": "\\newcommand\\WWtil{{\\tilde{\\mathbf{W}}}}\n\\newcommand\\hh{{\\boldsymbol{\\mathit{h}}}}\n\n\\chapter{Random Walks}\n\n\\sloppy\n\nToday, we talk about random walks on graphs and how the spectrum of the Laplacian guides convergence of random walks. We start by giving the definition of a random walk on a weighted graph $G=(V,E,w)$.\n\n\\section{A Primer on Random Walks}\n\n\\paragraph{Random Walk Basics.} We call a random sequence of vertices $v_0, v_1, \\dots$ a \\emph{random walk} on $G$, if $v_0$ is a vertex in $G$ chosen according to some probability distribution $\\pp_0 \\in \\mathbb{R}^V$; and for any $t \\geq 0$, we have \n\\[\n\\mathbb{P}[v_{t+1} = v \\; | v_t = u] = \\begin{cases}\n    w(u,v)/\\dd(u) & \\text{if } \\{u,v\\} \\in E,\\\\\n    0 & \\text{otherwise}.\n\\end{cases}\n\\]\n\n\\begin{figure}[!ht]\n    \\centering\\label{fig:randomWalkSimple}\n    \\includegraphics[scale=0.4]{fig/lec_RandomWalks_fig1.png}\n    \\caption{A (possibly random) walk where the red edges indicate the edges that the particle moves along. Here the walk visits the vertices $v_0 = 1, v_1 = 2, v_2 = 3, v_3 = 2, v_4 = 3, v_5 = 4$.}\n    \\label{fig:my_label}\n\\end{figure}\n\nTo gain some intuition for the definition,  assume first that the graph $G$ is undirected. Consider a {\\color{red}particle} that is placed at a random vertex $v_0$ initially. Then at each step the particle is moved to a neighbor of the current vertex it is resting at, where the neighbor is chosen uniformly at random. \n\nIf the graph is weighted, then instead of choosing a neighbor $v_{t+1}$ of a vertex $v_t$ at each step uniformly at random, one chooses a neighbor $v$ of $v_t$ with probability $w(v,v_t)$ divided by the degree $\\dd(v_t)$.\n\n\\paragraph{The Random Walk Matrix.} We now define the random walk matrix $\\WW$ by\n\\[\n    \\WW = \\AA \\DD^{-1}\n\\]\nand observe that for all vertices $u,v \\in V$ (and any $t$), we have that \n\\[\n\\WW_{vu} = \\begin{cases}\n    w(u,v)/\\dd(u) & \\text{if } \\{u,v\\} \\in E,\\\\\n    0 & \\text{otherwise}.\n\\end{cases}\n\\]\nThus, $\\WW_{vu} = \\mathbb{P}[v_{t+1} = v \\; | v_t = u]$ (for any $t$). \n\nTherefore, $W \\vecone_u$ is the distribution over the vertices that the random walk visits them at the next time step, given that it currently is at $u$. More generally, we can now compute the distribution $\\pp_1$ over the vertices that they are visited at time $1$ by $\\WW \\pp_0$, the distribution $\\pp_2$ by $\\WW \\pp_1 = \\WW ( \\WW \\pp_0)$ and so on. Another way of writing this is $\\pp_t = \\WW^t \\pp_{0}$.\n\n\\section{Convergence Results for Random Walks}\n\nIn this first part of the chapter, we are interested mostly in convergence of random walks that is the two questions:\n\\begin{itemize}\n\t\\item How does a random walk behave after a large number of steps are taken? \n\t\\item How many steps does it take asymptotically until the random walk behaves as if an infinite number of steps were taken?\n\\end{itemize}\n\nTo start shedding some light on these questions, we introduce stationary distributions.\n\n\\paragraph{Stationary Distribution.} We call a distribution $\\ppi \\in \\mathbb{R}^V$, a \\emph{stationary distribution} if $\\WW\\ppi = \\ppi$. That is $\\ppi$ is an eigenvector of $\\WW$ associated with eigenvalue $1$. It turns out such a stationary distribution always exists.\n\n\\begin{lemma}\\label{lma:thereExistsStationaryDistr}\nEvery graph $G$ has a stationary distribution.\n\\end{lemma}\n\\begin{proof}\nLet $\\ppi = \\frac{\\dd}{\\vecone^\\trp\\dd}$. Clearly, we have that $\\|\\ppi\\|_1 = \\sum_{v \\in V} \\dd(v)/\\vecone^\\trp\\dd = \\frac{1}{\\vecone^\\trp\\dd} \\sum_{v \\in V} \\dd(v) = 1$, so $\\ppi$ is indeed a distribution. Further note that\n\\[\n\\WW \\ppi = \\AA \\DD^{-1} \\cdot  \\frac{\\dd}{\\vecone^\\trp\\dd} = \\frac{\\AA \\vecone}{\\vecone^\\trp \\dd} = \\frac{\\dd}{\\vecone^\\trp \\dd} = \\ppi.\n\\]\n\\end{proof}\n\nFor many graphs one can show that for $t \\to \\infty$, we have that $\\pp_t \\to \\ppi$, i.e. that independent of the starting distribution $\\pp_0$, the random walk always converges to distribution $\\ppi$. \n\nUnfortunately, this is not true for all graphs: take the graph of two vertices connected by a single edge with $\\pp_0$ being $1$ at one vertex and $0$ at the other. \n\n\\subsection{Making Random Walks Lazy}\n\n\\paragraph{Lazy Random Walks.} Luckily, we can overcome this issue by using a \\emph{lazy random walk}. A lazy random walk behaves just like a random walk, however, at each time step, with probability $\\frac{1}{2}$ instead of transitioning to a neighbor, it simply stays put. We give the lazy random walk matrix by\n\\[\n \\WWtil = \\frac{1}{2}\\II + \\frac{1}{2} \\WW = \\frac{1}{2}\\left(\\II + \\AA \\DD^{-1}\\right).\n\\]\nIt is not hard to see that the stationary distribution $\\ppi$ for $\\WW$, is also a stationary distribution for $\\WWtil$.\n\n\\begin{figure}[!ht]\n    \\centering\\label{fig:randomLazyWalkSimple}\n    \\includegraphics[scale=0.2]{fig/lec_RandomWalks_fig2.jpg}\n    \\caption{A lazy random walk where the red edges indicate the edges that the particle moves along. Here the lazy walk visits the vertices $v_0 = 1, v_1 = 2, v_2 = 2, v_3 = 3, v_4 = 3, v_5 = 2$.}\n    \\label{fig:my_label}\n\\end{figure}\n\n\\paragraph{Lazy Random Walks and the Normalized Laplacian.} Recall that we defined $\\NN = \\DD^{-1/2}\\LL \\DD^{-1/2} = \\II - \\DD^{-1/2}\\AA \\DD^{-1/2} \\iff \\DD^{-1/2}\\AA \\DD^{-1/2} = \\II - \\NN$. We can therefore derive\n\\begin{align*}\n    \\WWtil &= \\frac{1}{2}\\II + \\frac{1}{2} \\AA \\DD^{-1}\\\\\n    &= \\frac{1}{2}\\II + \\frac{1}{2} \\DD^{1/2}\\DD^{-1/2} \\AA \\DD^{-1/2}\\DD^{-1/2}\\\\\n     &= \\frac{1}{2}\\II + \\frac{1}{2} \\DD^{1/2}(\\II - \\NN) \\DD^{-1/2}\\\\\n    &= \\frac{1}{2}\\II + \\frac{1}{2} \\DD^{1/2}\\II \\DD^{-1/2} - \\frac{1}{2} \\DD^{1/2}\\NN \\DD^{-1/2}\\\\\n    &= \\II - \\frac{1}{2} \\DD^{1/2}\\NN \\DD^{-1/2}\n\\end{align*}\n\nWe will now start to reason about the eigenvalues and eigenvectors of $\\WWtil$ in terms of the normalized laplacian $\\NN$ that we are already familiar with.\n\nFor the rest of the lecture, we let $\\nu_1 \\leq \\nu_2 \\leq \\dots \\leq \\nu_n$ be the eigenvalues of $\\NN$ associated with the orthogonal eigenvectors $\\ppsi_1, \\ppsi_2, \\dots, \\ppsi_n$ where we know that such eigenvectors exist by the Spectral Theorem. We note in particular that from the last lecture, we have that $\\ppsi_1 = \\frac{\\dd^{1/2}}{(\\vecone^{\\trp} \\dd)^{1/2}}$ (see Equation \\ref{eq:plugInNormalizedVector} where we added a normalization such that $\\ppsi_1^{\\trp} \\ppsi_1 = 1$).\n\n\\begin{lemma}\\label{lma:correspondenceEigenvectorWalkMatrix}\nFor the $i^{th}$ eigenvalue $\\nu_i$ of $\\NN$ associated with eigenvector $\\bm{\\psi}_i$, we have that $\\WWtil$ has an eigenvalue of $(1 - \\frac{1}{2}\\nu_i)$ associated with eigenvector $\\DD^{1/2} \\ppsi_i$.\n\\end{lemma}\n\\begin{proof}\nThe proof is by straight-forward calculations\n\\begin{align*}\n    \\WWtil \\DD^{1/2} \\bm{\\psi}_i &= (\\II - \\frac{1}{2} \\DD^{1/2}\\NN \\DD^{-1/2})\\DD^{1/2} \\bm{\\psi}_i \\\\ &= \\DD^{1/2} \\bm{\\psi}_i - \\frac{1}{2} \\DD^{1/2}\\NN \\bm{\\psi}_i \\\\\n    &=\\DD^{1/2} \\bm{\\psi}_i - \\frac{1}{2} \\DD^{1/2}\\bm{\\psi}_i \\nu_i = \\DD^{1/2} \\bm{\\psi}_i (1 - \\frac{1}{2}\\nu_i).\n\\end{align*}\n\\end{proof}\n\n\\begin{corollary}\nEvery eigenvalue of $\\WWtil$ is in $[0,1]$.\n\\end{corollary}\n\\begin{proof}\nRecall that $\\LL \\pleq 2\\DD$ which implies that $\\NN \\pleq 2 \\II$. But this implies that every eigenvalue of $\\NN$ is in $[0,2]$. Thus, using Lemma \\ref{lma:correspondenceEigenvectorWalkMatrix}, the corollary follows.\n\\end{proof}\n\n\\subsection{Convergence of Lazy Random Walks}\n\nWe have now done enough work to obtain an interesting result. We can derive an alternative characterization of $\\pp_t$ by expanding $\\pp_0$ along an orthogonal eigenvectors basis and then we can repeatedly apply $\\WWtil$ by taking powers of the eigenvalues. \n\nUnfortunately, $\\WWtil$ is not symmetric so its eigenvectors are not necessarily orthogonal. Instead, we use a simple trick that allows to expand along the eigenvectors of $\\NN$\n\\begin{align}\\label{eq:definitionOfAlphaForWalks}\n     \\forall i, \\ppsi_i^{\\trp} \\DD^{-1/2} \\pp_0 = \\alpha_i \\iff \\DD^{-1/2} \\pp_0 = \\sum_{i=1}^n \\alpha_i \\ppsi_i \\iff  \\pp_0 = \\sum_{i=1}^n \\alpha_i \\DD^{1/2} \\ppsi_i.\n\\end{align}\nThe above equivalences are best understood if you start from the middle. To get to the left side, you need to observe that multiplying both sides by $\\ppsi_i^{\\trp}$ cancels all terms $\\ppsi_j$ with $j \\neq i$ in the sum by orthogonality. To get the right hand side expression, one can simply left-multiply by $\\DD^{1/2}$. Technically, we have to show that $\\DD^{-1/2}\\pp_0$ lives in the eigenspace of $\\NN$ but we leave this as an exercise.\n\nThis allows us to express a right multiplication by $\\WWtil$ as\n\\[\n    \\pp_1 = \\WWtil \\pp_0 = \\sum_{i=1}^n \\alpha_i \\WWtil \\DD^{1/2} \\ppsi_i = \\sum_{i=1}^n \\alpha_i \\left(1-\\frac{\\nu_i}{2}\\right) \\DD^{1/2} \\ppsi_i.\n\\]\nAnd as promised, if we apply $\\WWtil$, the lazy random walk operator, $t$ times, we now obtain\n\\begin{align}\\label{eq:distributionRandomWalkTSteps}\n    \\pp_t = \\sum_{i=1}^n \\alpha_i \\left(1-\\frac{\\nu_i}{2}\\right)^t \\DD^{1/2} \\ppsi_i = \\alpha_1 \\DD^{1/2} \\ppsi_1 + \\sum_{i=2}^n \\alpha_i \\left(1-\\frac{\\nu_i}{2}\\right)^t \\DD^{1/2} \\ppsi_i.\n\\end{align}\nwhere we use in the last equality that $\\nu_1 = 0$. Using this simple characterization, we immediately get that $\\pp_t \\to \\ppi$ if $\\nu_i > 0$ for all $i \\geq 2$ (which is exactly when the graph is connected as you will prove in an exercise). To see this, observe that as $t$ grows sum vanishes. We have that\n\\[\n    \\lim_{t \\to \\infty} \\pp_t = \\alpha_1 \\DD^{1/2} \\ppsi_1 = \\ppi.\n\\]\nwhere we used in the equality that $\\DD^{1/2} \\ppsi_1 = \\frac{\\dd }{(\\vecone^{\\trp} \\dd)^{1/2}}$ and the value of $\\alpha_1$ (from \\ref{eq:definitionOfAlphaForWalks}).\n\n\\begin{theorem}\nFor any connected graph $G$, we have that the lazy random walk converges to the stationary distribution of $G$.\n\\end{theorem}\n\n\\subsection{The Rate of Convergence}\n\nLet us now come to the main result that we want to prove this lecture. \n\n\\begin{theorem}\nFor any $\\pp_0$, at any time step $t$, we have for $\\pp_t = \\WWtil^t \\pp_0$ that\n\\[\n\\| \\pp_t - \\ppi \\|_{\\infty}  \\leq e^{-\\nu_2 \\cdot t/2} \\sqrt{n} \n\\]\n\\end{theorem}\n\nInstead of proving the theorem above, we prove the lemma below which gives point-wise convergence. This makes it more convenient to derive a proof and it is not hard to deduce the theorem above as a corollary.\n\n\\begin{lemma}\nFor all $a,b \\in V$, and any time step $t$, we have for $\\pp_0 = \\vecone_a$ and $\\pp_t = \\WWtil^t \\pp_0$ that\n\\[\n  |\\pp_t(b) - \\ppi(b)| \\leq e^{-\\nu_2 \\cdot t/2} \\sqrt{\\dd_b/\\dd_a} \n\\]\n\\end{lemma}\n\nFrom Equation \\ref{eq:distributionRandomWalkTSteps}, we obtain that\n\\begin{align}\\label{eq:piecewiseDistribution}\n    \\pp_t(b) - \\ppi(b) &= \\vecone_b^\\trp(\\pp_t - \\ppi) = \\vecone_b^\\trp\\left( \\sum_{i=2}^n \\alpha_i \\left(1-\\frac{\\nu_i}{2}\\right)^t \\DD^{1/2} \\ppsi_i \\right)\n    \\\\ & =   \\sum_{i=2}^n \\alpha_i \\left(1-\\frac{\\nu_i}{2}\\right)^t \\vecone_b^\\trp\\DD^{1/2} \\ppsi_i\n    \\leq \\left(1-\\frac{\\nu_2}{2}\\right)^t \\cdot \\sum_{i=2}^n \\alpha_i  \\vecone_b^\\trp\\DD^{1/2} \\ppsi_i\n\\end{align}\nTaking the absolute value on both sides, we obtain that\n\\begin{align*}\\small\n|\\pp_t(b) - \\ppi(b)|\n&\\leq \\left(1-\\frac{\\nu_2}{2}\\right)^t\\sum_{i=2}^n \\left|\\alpha_i  \\vecone_b^\\trp\\DD^{1/2} \\ppsi_i \\right|\\leq \\left(1-\\frac{\\nu_2}{2}\\right)^t \\sqrt{\\left( \\sum_{i=2}^n \\alpha_i^2 \\right) \\left( \\sum_{i=2}^n \\left(\\vecone_b^\\trp\\DD^{1/2} \\ppsi_i \\right)^2 \\right)}\n\\end{align*}\nwhere we use Cauchy-Schwarz in the last inequality, i.e. $|\\langle \\uu, \\vv \\rangle|^2 \\leq \\langle \\uu, \\uu \\rangle \\cdot \\langle \\vv, \\vv \\rangle$. Let us finally bound the two sums:\n\\begin{itemize}\n    \\item By \\ref{eq:definitionOfAlphaForWalks}, $\\sum_{i=2}^n \\alpha_i^2 = \\sum_{i=2}^n \\left(\\ppsi^\\trp_i \\DD^{-1/2}\\pp_0 \\right)^2 \\leq \\|\\DD^{-1/2}\\pp_0\\|_2^2 =  \\|\\DD^{-1/2}\\vecone_a\\|_2^2 = 1/\\dd_a$.\n    \\item Finally, we show that $\\sum_{i=2}^n \\left(\\vecone_b^\\trp\\DD^{1/2} \\ppsi_i \\right)^2 \\leq \\sum_{i=1}^n \\left(\\vecone_b^\\trp\\DD^{1/2} \\ppsi_i \\right)^2 = \\|\\DD^{1/2}\\vecone_b\\|_2^2 = \\dd_b$ (we only show the first equality, the other inequalities are straight-forward). We first expand the vector $\\DD^{1/2}\\vecone_b$ along the eigenvectors using some values $\\beta_i$ defined\n    \\[\n        \\DD^{1/2}\\vecone_b = \\sum_{i=1}^n \\beta_i \\ppsi_i \\iff  \\ppsi_i^\\trp \\DD^{1/2}\\vecone_b = \\beta_i \\iff  \\vecone_b^\\trp \\DD^{1/2}\\ppsi_i= \\beta_i  \n    \\]\n    We used orthogonality to get the first equivalence, and then just take the transpose to get the second. We can now write\n    \\[\n    \\|\\DD^{1/2}\\vecone_b\\|_2^2 = (\\DD^{1/2}\\vecone_b)^{\\trp} (\\DD^{1/2}\\vecone_b) = \\left(\\sum_{i=1}^n \\beta_i \\ppsi_i^\\trp\\right) \\left(\\sum_{i=1}^n \\beta_i \\ppsi_i\\right) = \\sum_{i=2}^n \\beta_i^2\n    \\]\n    where we again used orthogonality of $\\ppsi_i$. The equality then follows by definition of $\\beta_i$.\n\\end{itemize}\n\nPutting everything together (and using $1+x \\leq e^x, \\forall x \\in \\mathbb{R}$), we obtain \n\\[  \n    |\\pp_t(b) - \\ppi(b)| \\leq \\left(1-\\frac{\\nu_2}{2}\\right)^t \\sqrt{\\dd_b/\\dd_a} \\leq e^{-\\nu_2 \\cdot t/2} \\sqrt{\\dd_b/\\dd_a} \n\\]\n\n\\section{Properties of Random Walks}\n\nWe now shift our focus away from convergence of random walks and consider some interesting properties of random walks. Here, we are no longer interested in lazy random walks, although all proofs can be straight-forwardly adapted. While in the previous section, we relied on computing the second eigenvalue of the Normalized Laplacian efficiently, here, we will discover that solving Laplacian systems, that is finding an $\\xx$ such that $\\LL\\xx = \\bb$ can solve a host of problems in random walks.\n\n\\subsection{Hitting Times}\n\nOne of the most natural questions one can ask about a random walk starting in a vertex $a$ (i.e. $\\pp_0 = \\vecone_a$) is how many steps it takes to get to a special vertex $s$. This quantity is called the \\emph{hitting time} from $a$ to $s$ and we denote it by $H_{a,s} = \\inf \\{ t \\;|\\; \\vv_t = s \\}$. For the rest of this section, we are concerned with computing the expected hitting time, i.e. $\\mathbb{E}[H_{a,s}]$.\n\nIt turns out, that it is more convenient to compute \\emph{all} expected hitting times $H_{a,s}$ for vertices $a \\in V$ to a fixed $s$. We denote by $\\hh \\in \\mathbf{R}^V$, the vector with $\\hh_a = \\mathbb{E}[H_{a,s}]$. We now show that we can compute $\\hh$ by solving a Laplacian system $\\LL \\hh = \\bb$. We will see later in the course that such systems (spoiler alert!) can be solved in time $\\tilde{O}(m)$, so this will imply a near-linear time algorithm to compute the hitting times.\n\n\\paragraph{Hitting Time and the Random Walk Matrix.} Let us first observe that if $s = a$, then the answer becomes trivially $0$, i.e. $\\hh_s = 0$. \n\nWe compute the rest of the vector by writing down a system of equations that recursively characterizes $\\hh$. Observe therefore first that for any $a \\neq s$, we have that the random walks starting at $a$ will next visit a neighbor $b$ of $a$. If the selected neighbor $b = s$, the random walks stops; otherwise, the random walks needs in expectation $\\mathbb{E}[H_{b,s}]$ time to move to $s$. \n\nWe can express this algebraically by\n\\[\n\\hh_a = 1 + \\sum_{a \\sim b} \\mathbb{P}[v_{t+1} = b \\;| v_t = a]  \\cdot \\hh_b = 1 + \\sum_{a \\sim b} \\frac{w(a,b)}{\\dd(a)}  \\cdot \\hh_b =  1 + (\\WW\\vecone_a)^{\\trp} \\hh = 1 + \\vecone_a^{\\trp} \\WW^{\\trp} \\hh.\n\\]\nUsing that $\\hh_a = \\vecone_a^{\\trp} \\hh =  \\vecone_a^{\\trp} \\II \\hh$, we can rewrite this as \n\\[\n1 = \\vecone_a^\\trp (\\II - \\WW^\\trp) \\hh.\n\\]\nThis gives a system of (linear) equations, that can be neatly summarized by \n\\[\n\\vecone - \\alpha \\cdot \\vecone_s = (\\II - \\WW^\\trp) \\hh\n\\]\nwhere we have an extra degree of freedom in choosing $\\alpha$ in formulating a constraint $1 - \\alpha = \\vecone_s^\\trp (\\II -\\WW^\\trp) \\hh$. This extra degree of freedom stems from the fact that $n-1$ equations suffice for us to enforce that the returned vector $\\xx$ to the system  from the system are indeed the hitting times (possibly shifted by the value assigned to coordinate $t$).\n\n\\paragraph{Finding Hitting Times via Laplacian System Solve.} Since we assume $G$ connected, we have that multiplying with $\\DD = \\DD^\\trp$ preserves equality. Further since $\\WW = \\AA \\DD^{-1}$, we obtain\n\\[\n\\dd - \\alpha \\cdot \\dd(s) \\cdot \\vecone_s = (\\DD - \\AA) \\hh.\n\\]\nDefining $\\bb = \\dd - \\alpha \\cdot \\dd(s) \\cdot \\vecone_s$, and observing $\\LL = \\DD - \\AA$, we have $\\LL\\hh = \\bb$. \n\nFinally, we observe that we only have a solution to the above system if and only if $\\bb \\in \\ker(\\LL)^\\perp =  \\Span(\\vecone)^\\perp$. We thus have to set $\\alpha$ such that \n\\[\n\\vecone^{\\trp}(\\dd - \\alpha \\cdot \\dd(s) \\cdot \\vecone_s) = \\|\\dd\\|_1 - \\alpha \\cdot \\dd(s) \\iff \\alpha =  \\|\\dd\\|_1 /\\dd(s).\n\\]\nWe have now formalized $\\LL$ and $\\bb$ completely. A last detail that we should not forget about is that any solution $\\xx$ to such system $\\LL \\xx = \\bb$ is not necessarily equal $\\hh$ but has the property that it is shifted from $\\hh$ by the all-ones vector. Since we require $\\hh_s = 0$, we can reconstruct $\\hh$ from $\\xx$ straight-forwardly by subtracting $\\xx_s \\vecone$.\n\n\\begin{theorem}\n\tGiven a connected graph $G$, a special vertex $s \\in V$. Then, we can formalize a Laplacian system $\\LL \\xx = \\bb$ (where $\\LL$ is the Laplacian of $G$) such that the expected hitting times to $s$ are given by $\\hh = \\xx - \\xx_s \\vecone$. We can reconstruct $\\hh$ from $\\xx$ in time $O(n)$.\n\\end{theorem}\n\n\\paragraph{Hitting Times and Electrical Networks.} Seeing that hitting times can be computed by formulating a Laplacian system $\\LL \\xx = \\bb$. You might remember that in the first lecture, we argued that a system $\\LL \\xx = \\bb$ also solves the problem of routing a demand $\\bb$ via an electrical flow with voltages $\\xx$. \n\nIndeed, we can interpret computing expected hitting times $\\hh$ to a special vertex $s$ as the problem of computing the electrical voltages $\\xx$ where we insert (or more technically correct apply) $\\dd(a)$ units of current at every vertex $a \\neq s$ and where we remove $\\vecone^\\trp\\dd - \\dd(s)$ units of current at the vertex $s$. Then, we can express expected hitting time to some vertex $a$ as the voltage difference to $s$: $\\mathbb{E}[H_{a,s}] = \\hh_a = \\xx_a - \\xx_s$.\n\n\\subsection{Commute Time}\n\nA topic very related to hitting times are \\emph{commute times}. That is for two vertices $a,b$, the commute time is the time in a random walk starting in $a$ to visit $b$ and then to return to $a$ again. Thus, it can be defined $C_{a,b} = H_{a,b} + H_{b,a}$.\n\n\\paragraph{Commute Times via Electric Flows.} Recall that expected hitting times have an electric flow interpretation. \n\nNow, let us denote by $\\xx$ a solution to the Laplacian system $\\LL \\xx = \\bb_b$ where the demand is $\\bb_b = \\dd - \\dd^\\trp \\vecone \\cdot \\vecone_b \\in \\ker(\\vecone)^\\perp$. Recall that we have $\\mathbb{E}[H_{z,b}] = \\xx_z - \\xx_b$ for all $z$. \n\nSimilarly, we can compute voltages $\\yy$ to the Laplacian system $\\LL \\yy = \\bb_a$ where $\\bb_a = \\dd - \\dd^\\trp \\vecone \\cdot \\vecone_a \\in \\ker(\\vecone)^\\perp$. Again, $\\mathbb{E}[H_{z,a}] = \\yy_z - \\yy_a$ for all $z$. Note that, if we revert the flow by negating $\\yy$, then we can still compute the hitting time by taking $\\mathbb{E}[H_{z,a}] = -(-\\yy_z - (-\\yy_a)) = -(\\yy_a-\\yy_z)$.\n\nThus, inducing voltages $\\xx - \\yy$ on the graph $G$, we now have by linearity that $\\mathbb{E}[C_{a,b}] = \\mathbb{E}[H_{a,b}+H_{b,a}] = |\\xx_a - \\xx_b| + |\\yy_a-\\yy_b|$. But these voltages are also induced by $\\LL (\\xx - \\yy) = \\bb_b - \\bb_a = \\dd^\\trp \\vecone (\\vecone_a - \\vecone_b)$ (again by linearity). That is the flow that routes $\\|\\dd\\|_1$ units of flow from $b$ to $a$.  \n\n\\begin{theorem}\n\tGiven a graph $G=(V,E)$, for any two fixed vertices $a,b \\in V$, the expected commute time $C_{a,b}$ is given by the voltage difference between $a$ and $b$ for any solution $\\zz$ to the Laplacian system $\\LL \\zz = \\|\\dd\\|_1 \\cdot (\\vecone_b - \\vecone_a)$.\n\\end{theorem}\n\nWe note that the voltage difference between $a$ and $b$ in an electrical flow routing demand $\\vecone_b - \\vecone_a$ is also called the \\emph{effective resistance} $\\er(a,b)$. This quantity will play a crucial role in the next roles. In the next lecture, we introduce $\\er(a,b)$ slightly differently as the energy required by the electrical flow that routes $\\vecone_b - \\vecone_a$, however, it is not hard to show that these two definitions are equivalent.\n\nOur theorem can now be restated as saying that the expected commute time $\\mathbb{E}[C_{a,b}] = \\|\\dd\\|_1 \\cdot \\er(a,b)$. This is a classic result.", "meta": {"hexsha": "fe72e5d9d43606ec3ada2370211e379bca67efd9", "size": 20391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture_RandomWalks.tex", "max_stars_repo_name": "rjkyng/agao21_script", "max_stars_repo_head_hexsha": "772f8c17b0802ec43d45e1480f7193dd0eceadb7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-15T09:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T05:39:09.000Z", "max_issues_repo_path": "agao21_script/lecture_RandomWalks.tex", "max_issues_repo_name": "rjkyng/agao21_script", "max_issues_repo_head_hexsha": "772f8c17b0802ec43d45e1480f7193dd0eceadb7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "agao21_script/lecture_RandomWalks.tex", "max_forks_repo_name": "rjkyng/agao21_script", "max_forks_repo_head_hexsha": "772f8c17b0802ec43d45e1480f7193dd0eceadb7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-11T12:35:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T06:04:51.000Z", "avg_line_length": 77.8282442748, "max_line_length": 497, "alphanum_fraction": 0.6803491737, "num_tokens": 6902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6629714794692617}}
{"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\\subsection{Quadratic Integer Rings}\n\\label{sub:quadratic_integer_rings}\n\nLet \\(D\\) be a rational number that is not a perfect square in \\(\\Q\\) and define\n\\begin{align*}\n\t\\Q(\\sqrt{D} ) = \\left\\{a+b\\sqrt{D}  \\mid a,b \\in \\Q \\right\\} \n\\end{align*}\nas a subset of \\(\\C\\). One can check that the set is closed under subtraction and under the multiplication defined by\n\\begin{align*}\n\t(a+b\\sqrt{D})(c+d\\sqrt{D} ) = (ac+bdD) + (ad+bc)\\sqrt{D} \n\\end{align*}\nshows that it is closed under multiplication. Hence \\(\\Q(\\sqrt{D} ) \\leq \\C\\) as a subring (and of \\(\\R\\) if \\(D>0\\)) and hence is commutative with identity.\\\\\n\nThe assumption that \\(D\\) is not a square allows us to write every element of \\(\\Q(\\sqrt{D} )\\) uniquely in the form \\(a+b\\sqrt{D} \\). Furthermore, if \\(a,b\\) are not both zero, then \\(a^2-Db^2\\neq 0\\), and because\n\\begin{align*}\n\t(a+b\\sqrt{D} )(a-b\\sqrt{D} ) = a^2-Db^2\n\\end{align*}\nthen if \\(a+b\\sqrt{D} \\neq 0\\) we have\n\\begin{align*}\n\t(a+b\\sqrt{D} )^{-1} = \\dfrac{a-b\\sqrt{D} }{a^2-Db^2}.\n\\end{align*}\nThis shows that every nonzero element in the commutative ring is a unit and hence \\(\\Q(\\sqrt{D} )\\) is a field called a \\textbf{quadratic field}.\\\\\n\nThe rational number \\(D\\) can be written by \\(D = q^2D'\\) for some rational number \\(q\\) and a unique integer \\(D'\\), where \\(z^2\\not\\mid D'\\) for all \\(z \\in \\Z_+\\) greater than \\(1\\). We call \\(D'\\) the \\textbf{squarefree part} of \\(D\\). Because \\(\\sqrt{D} =q\\sqrt{D'} \\) it holds that \\(\\Q(\\sqrt{D} )=\\Q(\\sqrt{D'} )\\), and hence we can use squarefree integers instead in the definition of the quadratic field.\\\\\n\nLet \\(D\\) be a squarefree integer. One can check that\n\\begin{align*}\n\t\\Z[\\sqrt{D} ] = \\left\\{a + b\\sqrt{D}  \\mid a,b \\in \\Z \\right\\} \n\\end{align*}\nforms a subring of the quadratic field \\(\\Q(\\sqrt{D} )\\). In the case where \\(D \\equiv 1 \\pmod{4}\\), then we can form a slightly larger subring by\n\\begin{align*}\n\t\\Z\\left[ \\frac{1+\\sqrt{D}}{2} \\right] = \\left\\{ a + b \\frac{1+\\sqrt{D} }{2} \\mid a,b \\in \\Z \\right\\} .\n\\end{align*}\nNow define\n\\begin{align*}\n\t\\mathcal{O} = \\mathcal{O}_{\\Q(\\sqrt{D} )} = \\Z[\\omega ] = \\left\\{a + b \\omega  \\mid a,b \\in \\Z \\right\\} \\\\\n\t\\omega = \\begin{cases}\n\t\t\\sqrt{D}  & D \\equiv 2, 3 \\pmod{4}\\\\\n\t\t\\frac{1+\\sqrt{D} }{2} & D \\equiv 1 \\pmod{4}\n\t\\end{cases}.\n\\end{align*}\nWe call \\(\\mathcal{O}\\) the \\textbf{ring of integers} in the quadratic field \\(\\Q(\\sqrt{D} )\\)-- despite the fact that elements are not actually integers. This terminology arises because the properties of \\(\\mathcal{O}\\) are similar to those of \\(\\Z\\leq \\Q\\) as subrings. In fact, we will later see that it is the \\textit{integral closure} of \\(\\Z\\) in \\(\\Q(\\sqrt{D} )\\).\\\\\n\nIn the special case where \\(D = -1\\), we obtain the ring \\(\\Z[i]\\) of \\textbf{Gaussian integers}. We will cover the Gaussian integers later, as they have important ties to number theory.\n\n\\begin{defn}[Field Norm]\n\tDefine the \\textbf{field norm} \\(N:\\Q(\\sqrt{D} ) \\to \\Q\\) by\n\t\\begin{align*}\n\t\tN(a+b\\sqrt{D} ) = (a+b\\sqrt{D} )(a-b\\sqrt{D} ) = a^2 - Db^2 \\in \\Q\n\t\\end{align*}\n\tThis norm gives a notion of size in the field. For example, when \\(D=-1\\), the norm of \\(a+bi\\) is \\(a^2+b^2\\).\n\\end{defn}\nOne can check that \\(N\\) is \\textbf{multiplicative}-- that is, \\(N(\\alpha \\beta ) = N(\\alpha )N(\\beta )\\). We can also see that on the subring \\(\\mathcal{O}\\) the field norm is given by\n\\begin{align*}\n\tN(a+b\\omega ) = (a+b\\omega )(a+b \\overline{\\omega }) = \\begin{cases}\n\t\ta^2-Db^2 & D \\equiv 2,3 \\pmod{4}\\\\\n\t\ta^2+ab + \\frac{1-D}{4}b^2 & D \\equiv 1 \\pmod{4}\n\t\\end{cases}\\\\\n\t\\overline{\\omega } = \\begin{cases}\n\t\t-\\sqrt{D} & D \\equiv 2,3 \\pmod{4}\\\\\n\t\t\\frac{1-\\sqrt{D} }{2} & D \\equiv 1 \\pmod{4}\n\t\\end{cases}\n\\end{align*}\nAnd hence \\(N(\\alpha )\\) is in fact an integer for every \\(\\alpha  \\in \\mathcal{O}\\). This in fact characterizes the units of \\(\\mathcal{O}\\)-- if \\(\\alpha \\in \\mathcal{O}\\) has field norm \\(N(\\alpha ) = \\pm 1\\), then\n\\begin{align*}\n\t(a + b\\omega )^{-1} = \\pm (a + b \\overline{\\omega })\n\\end{align*}\nand hence \\(\\alpha \\) is a unit. The multiplicative property directly tells us that the converse holds, and hence \\(\\alpha \\in \\mathcal{O}\\) is a unit if and only if \\(N(\\alpha ) = \\pm 1\\).\\\\\n\nIn number theory, finding solutions to the equation \\(x^2-Dy^2 = \\pm 1\\) is equivalent to the determination of units in \\(\\mathcal{O}\\).\n\n\\begin{hw}\n\tShow that if \\(D>0\\) then the group of units \\(\\mathcal{O}^{\\times }\\) is always infinite. Find a class of units in \\(\\mathcal{O} = \\Z[\\sqrt{2} ]\\) that exemplifies this.\\\\\n\n\tShow that \\(\\mathcal{O}_{\\Q(\\sqrt{-3} )}\\) has only a finite number of elements, and list them. Are there other values of \\(D\\) with more units than \\(\\left\\{ \\pm 1 \\right\\} \\)?\n\\end{hw}\n\n\\subsection{Polynomial Rings}\n\\label{sub:polynomial_rings}\n\n\\begin{defn}[Polynomial Ring]\n\tLet \\(R\\) be a commutative ring. We define a \\textbf{polynomial} in \\(x\\) to be the formal sum\n\t\\begin{align*}\n\t\ta_n x^{n} + a_{n-1}x^{n-1} + \\ldots + a_1 x + a_0\n\t\\end{align*}\n\twhere \\(n\\geq 0\\) and \\(a_i \\in R\\). If \\(a_n \\neq 0\\), then the polynomial is of \\textbf{degree \\(n\\)}, and \\(a_nx^{n}\\) is te \\textbf{leading term} (\\(a_n\\) is the \\textbf{leading coefficient}). Furthermore, we say the polnyomial is \\textbf{monic} if \\(a_n=1\\).\\\\\n\n\tThe set of all such polynomials is called the \\textbf{ring of polynomials in \\(\\R\\)} and will be denoted \\(R[x]\\). We define addition and multiplication by the standard version from algebra:\n\t\\begin{align*}\n\t\t(a_nx^{n} + \\ldots + a_1x + a_0) + (b_nx^{n} + \\ldots + b_1x + b_0) = (a_n+b_n)x^{n} + \\ldots + (a_1+b_1)x + (a_0 + b_0)\\\\\n\t\t(a_0+a_1x + a_2x^2+\\ldots) \\times (b_0 + b_1x + b_2x^2 + \\ldots) = a_0b_0 + (a_0b_1 + a_1b_0)x + (a_0b_2 + a_1b_1 + a_2b_0)x^2 + \\ldots\n\t\\end{align*}\n\tThat is, the coefficient in the product of \\(x^{k}\\) is \\(\\sum_{i=0}^{k} a_i b_{k-i}\\).\n\\end{defn}\nWe can see that \\(R\\leq R[x]\\) as the \\textbf{constant polynomials}. Notice further that \\(R[x]\\) is also a commutative ring.\n\n\\begin{prop}\n\tLet \\(R\\) be an integral domain and let \\(p(x),q(x) \\in R[x]\\) be nonzero polynomials. Then the degree of \\(p(x)q(x) = \\textrm{deg}p(x) + \\textrm{deg}q(x)\\).\\\\\n\n\tThe units of \\(R[x]\\) are exactly the same units of \\(R\\), and \\(R[x]\\) is an integral domain.\n\\end{prop}\nIf \\(R\\) has zero divisors, then \\(R[x]\\) does as well. We can also see that \\(S\\leq R \\implies S[x] \\leq R[x]\\).\n\n\\begin{exmp}\n\tConsider the polynomial ring \\((\\Z_3[x]\\). This ring consists of nonnegative powers of \\(x\\) with coefficients in \\(\\left\\{ 0,1,2 \\right\\} \\) with calculations being done in modulus \\(3\\). For example, let\n\t\\begin{align*}\n\t\tp(x) = x^2+2x+1 \\quad q(x) = x^3+x +2.\n\t\\end{align*}\n\tThen\n\t\\begin{align*}\n\t\tp(x) + q(x) = x^3+x^2\\\\\n\t\tp(x)q(x) = x^{5}+2x^{4}+2x^3+x^2+2x+2\n\t\\end{align*}\n\tPolynomials behave very differently even under simple modulus structures.\n\\end{exmp}\nWe will see more of polynomial rings after building more theory.\n\n\\subsection{Matrix Rings}\n\\label{sub:matrix_rings}\n\n\\begin{defn}[Matrix Rings]\n\tLet \\(R\\) be a ring and \\(n\\in \\Z_+\\). We define \\(M_n(R)\\) to be the set of all \\(n\\times n\\) matrices with entries in \\(R\\). The element \\(A \\in M_n(R)\\) is an \\(n\\times n\\) square array of elements of \\(R\\) whose entry in row \\(i\\) and column \\(j\\) is \\(A_{ij} \\in R\\). We see that this set of matices becomes a ring under the usual matrix addition and multiplication, called the \\textbf{matrix ring of rank \\(n\\)}.\n\\end{defn}\nNotice that if \\(n\\geq 2\\), then \\(M_n(R)\\) is not commutative, regardless of the commutativity of \\(R\\). Furthermore, it will also have zero divisors.\\\\\n\nWe say \\(A \\in M_n(R)\\) is a \\textbf{scalar matrix} if \\(a_{ii}=a\\) for all \\(i \\in \\left\\{ 1,\\ldots,n \\right\\} \\), and \\(a_{ij}=0\\) if \\(i\\neq j\\). This forms a subgring of \\(M_n(R)\\), and is in fact isomorphic to \\(R\\). If \\(R\\) is commutative, the scalar matrices commute with all elements of \\(M_n(R)\\).\\\\\n\nNote that the units of \\(M_n(R)\\) are the invertible \\(n\\times n\\) matrices-- this forms a subgroup called the \\textbf{general linear group of degree \\(n\\) over \\(R\\)} (written by \\(GL_n(R)\\)).\\\\\n\nSimilar to polynomial rings, if \\(S\\leq R\\), then \\(M_n(S) \\leq M_n(R)\\). Another subring is the set of upper triangular matrices.\n\n\\subsection{Group Rings}\n\\label{sub:group_rings}\n\n\\begin{defn}[Group Rings]\nLet \\(R\\) be a commutative ring and \\(G \\) a finite group. The \\textbf{group ring \\(RG\\) of \\(G\\)} is the set of all sums\n\\begin{align*}\n\tRG = \\left\\{ a_1g_1 + a_2g_2 + \\ldots + a_ng_n \\mid a_i\\in R, g_i \\in G\\right\\} \n\\end{align*}\nWe define addition and multiplication by\n\\begin{align*}\n\t(a_1g_1+ a_2g_2 + \\ldots + a_ng_n) + (b_1g_1 + b_2g_2 + \\ldots + b_ng_n) = (a_1+b_1)g_1 + (a_2+b_2)g_2 + \\ldots + (a_n+b_n)g_n\\\\\n\t\t(a_1g_1+ \\ldots + a_ng_n)(b_1g_1 + \\ldots + b_ng_n) = \\sum_{g_ig_j = g_k} (a_ib_j)g_k \n\\end{align*}\nwhere the multiplication is the natural construction derived from defining \\((ag_i)(bg_j) = (ab)(g_ig_j)\\).\n\\end{defn}\n\\(RG\\) is commutative if and only if \\(G\\) is commutative. We can see \\(R \\leq RG\\) by the \"constant\" sums of \\(a_ie_G\\). In fact, \\(G\\leq RG\\) as well by taking \\(a_i = e_R\\), and because elements of \\(G\\) has inverses, \\(G\\) is a subgroup of the group of units of \\(RG\\).\\\\\n\nIf \\(\\left| G \\right| >1\\) then \\(RG\\) has zero divisors, given by\n\\begin{align*}\n\t(1-g)(1+g+\\ldots+g^{m-1}) = 1-g^{m} = 1-1 = 0\n\\end{align*}\nwhere \\(g\\) is an element with order \\(m>1\\).\\\\\n\nIf \\(S\\) is a subring of \\(R\\) then \\(SG \\leq RG\\). Similarly, if \\(H\\leq G\\), then \\(RH \\leq RG\\).\n\n\\begin{exmp}[\\(\\Z D_8\\)]\n\tLet \\(G = D_8\\) be the dihedral group of order \\(8\\) and \\(R = \\Z\\). Some example of elements in \\(\\Z D_8\\) could be \\(\\alpha  = r + r^2 - 2s\\) and \\(\\beta = -3r^2 + rs\\), and one can see that\n\t\\begin{align*}\n\t\t\\alpha + \\beta = r - 2r^2 -2s +rs\\\\\n\t\t\\alpha \\beta = (r+r^2-2s)(-3r^2+rs) = r(-3r^2+rs) + r^2(-3r^2+rs) - 2s(-3r^2+rs) = -3 - 5r^3 + 7r^2s + r^3s\n\t\\end{align*}\n\\end{exmp}\n\n\\begin{exmp}[\\(\\R Q_8\\)]\n\tAn interesting example is the group ring \\(\\R Q_8\\). This ring is distinct from the Hamilton quaternions \\(\\mathbb{H}\\) even though \\(Q_8 \\subset \\mathbb{H}\\). The unique element of order \\(2\\) in \\(Q_8\\) is NOT the additive inverse of \\(1 \\) in \\(\\R Q_8\\), even though it is in \\(\\mathbb{H}\\). It also contains zero divisors and hence is not a division ring.\\\\\n\n\tHowever, if one takes the quotient \\(\\R Q_8 / \\left( 1 + (-1), i + (-i), j + (-j), k + (-k) \\right) \\), then it is isomorphic to \\(\\mathbb{H}\\).\n\\end{exmp}\nIn other words, we only apply the group operation between elements of the group ring when multiplying two elements. The group elements hence serve as sort of a basis, that interacts multiplicatively via the group action.\n\n\\subsection{Rings of Fractions}\n\\label{sub:rings_of_fractions}\n\nLet \\(R\\) be a commutative ring. Recall that if we have a non-zero non-zero divisor element \\(a \\in R\\), then \\(ab = ac \\implies b = c\\). This property is similar to division even if \\(a\\) is not a unit. Our goal will be to define a larger ring \\(Q\\geq R\\) so that elements like \\(a\\) are units. This becomes particularly useful when \\(R\\) is an integral domain, as then \\(Q\\) becomes a field known as the \\textbf{field of fractions} or \\textbf{quotient field}.\n\n\\begin{thm}\n\tLet \\(R\\) be a commutative ring and \\(D\\subset R\\) a subset without \\(0\\), zero divisors, and is closed under multiplication. Then there is a commutative ring \\(Q\\) such that \\(R\\leq Q\\) and for all \\(d \\in D\\), \\(d \\in Q\\) is a unit.\\\\\n\n\tFurthermore, every element of \\(Q\\) is of the form \\(rd^{-1}\\) for some \\(r \\in R\\) and \\(d \\in D\\). If \\(D = R - \\left\\{ 0 \\right\\} \\), then \\(Q\\) is a field.\\\\\n\n\tThe ring \\(Q\\) is the smallest ring containing \\(R\\) in which all elements of \\(D\\) become units. That is, let \\(S\\) be a commutative ring and \\(\\varphi :R\\to S\\) be an injective ring homomorphism such that \\(\\varphi (d)\\) is a unit in \\(S\\) for every \\(d \\in D\\). Then there is an injective homomorphism \\(\\Phi :Q\\to S\\) such that \\(\\Phi\\mid_R = \\varphi \\). In other words, any other ring that makes \\(D\\) into units must contain an isomorphic copy of \\(Q\\).\\\\\n\n\tWe call the ring \\(Q\\) the \\textbf{ring of fractions of \\(D\\)} and denote it by \\(D^{-1}R\\). If \\(R\\) is integral, then \\(Q\\) is the \\textbf{field of fractions} of \\(R\\).\n\\end{thm}\nWhat does this actually look like? Caution must be exercised, as when dealing with fractions we are dealing with equivalence classes. Hence we will define an equivalence class on \\((r,d)\\) with \\(r \\in R\\) and \\(d \\in D\\) by\n\\begin{align*}\n\t\\dfrac{r}{d} = \\left\\{(a,b) \\mid a \\in R,\\, b \\in D,\\, rb = ad \\right\\} \n\\end{align*}\nThen \\(Q\\) is the set of equivalence classes \\(\\dfrac{r}{d}\\). Then we define addition and multiplication by\n\\begin{align*}\n\t\\dfrac{a}{b}+ \\dfrac{c}{d}= \\dfrac{ad+bc}{bd} \\quad \\dfrac{a}{b} \\times \\dfrac{c}{d} = \\dfrac{ac}{bd}.\n\\end{align*}\nWe leave it as an exercise to verify that this indeed gives \\(Q\\) the structure of a commutative ring. We embed \\(R\\) into \\(Q\\) by defining\n\\begin{align*}\n\t\\iota : R\\to Q \\quad \\iota:r\\mapsto \\dfrac{rd}{d}\n\\end{align*}\nfor any \\(d \\in D\\). This is obviously in the equivalence class of \\(\\dfrac{re}{e}\\), so the choice of \\(d\\) does not matter. This is a ring homomorphism and is in fact injective because \\(d\\) is not a zero divisor, and so this tells us that \\(\\iota(R)\\leq Q\\) is isomorphic to \\(R\\).\\\\\n\nWe can also see that \\(d \\in D\\) has a multiplicative inverse in \\(Q\\) as desired. That is,\n\\begin{align*}\n\t\\left( \\dfrac{de}{e} \\right)^{-1} = \\dfrac{e}{de}\n\\end{align*}\nand one can see that every element of \\(Q\\) can be written by \\(r \\cdot d^{-1}\\) for some \\(r \\in R\\) and \\(d \\in D\\).\n\n\\begin{rmrk}\n\tRecall that if \\(A\\subset F\\) is a subset of a field, then the intersection of all the subfields of \\(F\\) containing \\(A\\) is a subfield of \\(F\\) called the \\textbf{subfield generated by \\(A\\)}.\\\\\n\n\tThis subfield is the smallest subfield of \\(F\\) containing \\(A\\).\n\\end{rmrk}\n\n\\begin{cor}\n\tLet \\(R\\) be an integra domain and \\(Q\\) be the field of fractions of \\(R\\). If a field \\(F\\) contains a subring \\(R'\\) isomorphic to \\(R\\) then the subfield of \\(F\\) generated by \\(R'\\) is isomorphic to \\(Q\\).\n\\end{cor}\n% \\printindex\n\\end{document}\n", "meta": {"hexsha": "707b26d9e7d91bff424c6abd905ae87610b77448", "size": 14614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ring Theory/Notes/source/RingExamples.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/RingExamples.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/RingExamples.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": 61.1464435146, "max_line_length": 462, "alphanum_fraction": 0.6457506501, "num_tokens": 5290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.6629280923621901}}
{"text": "%description: Math 290 HW Template\n\n%%%%% Beginning of preamble %%%%%\n\n\\documentclass[12pt]{article}  %What kind of document (article) and what size\n\n%Packages to load which give you useful commands\n\\usepackage{subfig}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{amssymb, amsmath, amsthm}\n\n%Sets the margins\n\n\\textwidth = 6.5 in\n\\textheight = 9 in\n\\oddsidemargin = 0.0 in\n\\evensidemargin = 0.0 in\n\\topmargin = 0.0 in\n\\headheight = 0.0 in\n\\headsep = 0.0 in\n\\parskip = 0.2in\n\\parindent = 0.0in\n\n%defines a few theorem-type environments\n% \\newtheorem{theorem}{Theorem}\n% \\newtheorem{corollary}[theorem]{Corollary}\n% \\newtheorem{definition}{Definition}\n\n\\newtheorem{definition}{Definition}\n\\newtheorem{fact}{Fact}\n\\newtheorem{remark}{Remark}\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{proposition}{Proposition}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{corollary}{Corollary}\n\n\\renewcommand{\\labelenumi}{\\arabic{enumi}.}\n\\renewcommand{\\labelenumii}{\\arabic{enumi}.\\arabic{enumii}.}\n\\renewcommand{\\labelenumiii}{\\arabic{enumi}.\\arabic{enumii}.\\arabic{enumiii}.}\n\\renewcommand{\\labelenumiv}{\\arabic{enumi}.\\arabic{enumii}.\\arabic{enumiii}.\\arabic{enumiv}.}\n\\newlength{\\alginputwidth}\n\\newlength{\\algboxwidth}\n\\newcommand{\\alginput}[1]{\\makebox[1.5cm][l]{ {\\sc Input:}} \\parbox[t]{\\alginputwidth}{{\\it #1}}}\n\\newcommand{\\algoutput}[1]{\\makebox[1.5cm][l]{ {\\sc Output:}} \\parbox[t]{\\alginputwidth}{{\\it #1}}}\n\\newcommand{\\algtitle}[1]{\\underline{Algorithm \\ {\\bf #1}} \\vspace*{1mm}\\\\}\n\n%%%%% End of preamble %%%%%\n\n\n\n\n\n\n\n\\begin{document}\n\n\\title{AI for Risk Game}\n\n\\author{\n{Wah Loon Keng}\\thanks{\nLafayette College,\nEaston, PA 18042, USA.\nkengw{\\tt @}lafayette.edu.}\n\\qquad\n{Benjamin H. Draves}\\thanks{\nLafayette College,\nEaston, PA 18042, USA.\ndravesb{\\tt @}lafayette.edu.}\n      % \\affaddr{Department of Computer Science}\\\\\n%       \\affaddr{Lafayette College}\\\\\n%       \\affaddr{Easton, PA 18042, USA}\\\\\n%       \\email{gexia@cs.lafayette.edu}\n}\n% \\date{}\n\\maketitle\n\n\\begin{abstract}\nWe implement an AI to play the board game $\\emph{Risk}$. The game is formalized as an optimization problem in graph theory, where countries are represented as nodes in an undirected graph, and decisions are considered based on the graph properties. We introduce solution algorithms, with variable parametrizations, which are then implement as AIs with different personalities in {\\tt JavaScript}. We set up games among AIs to measure their performances, and discover unusual game strategies.\n\\end{abstract}\n\n\n\n\n\n\n\n\n\n\n\\section{Introduction} \\label{intro}\n\nThe board game $\\emph{World Domination RISK \\circledR}$ is a game of military strategy, where players of different factions try to conquer all 42 countries on the map, by deploying armies to attack and defend. We use the classic $\\emph{Hasbro}$ version of the game; the rules are well known and can easily be found online, but they will be included as we walk through our algorithms.\n\nIn this paper, we first set up our formalization of the game as a graph optimization problem. Next we introduce graph algorithms to carry out each of the game moves, and explain our reasoning behind them. Then, we combine these to implement an AI, with variable personalities based on the parametrization of its internal algorithms. The different AIs then play multiple games against one another, with their results recorded. Finally, we analyze their performances, and find several unusual, interesting strategies discovered by the AIs that are never observed from human players.\n\nThis entire project is public on GitHub: \\url{https://github.com/kengz/Risk-game}.\n\n\n\n\\section{Formalization} \\label{formalization}\n\nThe game is inherently dependent on the board, which is a world map of 42 countries, interconnected in specific ways. Decisions to attack or defend are based on the distribution of the armies, the surroundings of a location, and connectivity of countries. These motivate our formalizing the game board and algorithms based on an undirected graph. From now we shall refer to the graph representation as $\\emph{map}$:\n\n\\begin{definition} \\label{map}\nA $\\textbf{map}$ is a connected, undirected planar graph, with 42 nodes, each representing a country. The nodes are named with indices $0-41$, and are connected the same way as are countries on the game board by undirected edge of weight 1.\n\\end{definition}\n\nWe assign data fields to each node, namely its country name, the continent it is in, its player owner, the number of armies of the owner in it, its worth and pressure as determined by some metric described below.\n\n\n\\begin{definition} \\label{region}\nA $\\textbf{region}$ is a connected subgraph consisting of nodes all owned by the same player. Each player can own many regions, which together partition the map.\n\\end{definition}\n\n\\begin{definition} \\label{border}\nA $\\textbf{border}$ node of an AI is its node that is adjacent to at least an enemy node.\n\\end{definition}\n\n\\begin{definition} \\label{attackable}\nA $\\textbf{attackable}$ node for an AI an enemy node adjacent to its border.\n\\end{definition}\n\n\\begin{definition} \\label{shape}\nThe $\\textbf{shape}$ of a region is the measure of its shape/roundess. To compute the shape, find the maximum and minimum distances between the border nodes in the region, and shape=(max-min)/max. If a region is round, shape = 0; if it is a line, shape = 1.\n\\end{definition}\n\n\\begin{definition} \\label{radius}\n$\\textbf{Radius}$ is the measure of shortest distance from an origin node. We identify the neighbors of node $\\mathcal{O}$ at radius k to be the nodes whose shortest distance from $\\mathcal{O}$ is k.\n\\end{definition}\n\n\nFurthermore, we define the fields that will be useful in our algorithms:\n\n\\begin{definition} \\label{worth}\nThe $\\textbf{worth}$ of a node is the measure of its importance to an AI, as calculated by its internal metric algorithm, and is used by the AI to prioritize its decisions: which node should it defend/attack first.\n\\end{definition}\n\n\\begin{definition} \\label{pressure}\nThe $\\textbf{pressure}$ of a node as perceived by an AI is the measure of the average army distribution around the node, up to 5 unit radii away. It is calculated by the AI's internal metric and used to prioritize decisions.\n\\end{definition}\n\nNote that the worth and pressure of a node are not the same when calculated by opposing AIs due to different perceptions, metric and AI personalities. Each AI will be calculating these values for all 42 nodes at each turn.\n\nFinally, we introduce a data structure as the raw representation of overall army distribution on the map for various calculations:\n\n\\begin{definition} \\label{RMAM}\nThe $\\textbf{Radius Matrix (RM)}$ from an origin node $\\mathcal{O}$ is the matrix that better represents the connectivity of neighbor nodes of the origin within some radius. It is enumerated by the Radius Matrix Algorithm below, and each entry is the name of some node.\n\nIts corresponding $\\textbf{Army Matrix (AM)}$ is a different representation of the RM, with each entry now being $z \\in \\mathbb{Z}$, where $|z|$ is the number of armies at the node, and $z$ is positive if the node is owned by the calculating AI, and negative otherwise.\n\\end{definition}\n\n\n\n\n\n\n\n\\section{Algorithms}\n\nWe now enumerate the algorithms for each step of the game, which will collectively form the final algorithm used by the AI to play the game.\n\n\n\\subsection{The Matrix Algorithms}\n\n\\algtitle{Radius Matrix (RM) for an origin node $\\mathcal{O}$}\nStarting from an origin node $\\mathcal{O}$, initialize an empty matrix for its RM,\n\\begin{enumerate}\n\t\\item Add the index of each adjacent node (at radius 1) of $\\mathcal{O}$ to a new row in RM.\n\t\\item Repeat for $i \\in \\{2,3,...,n\\}$, where $n$ is the maximum radius covered:\n\t\n\tFor each entry $p$ at column $i$, get all $n_p$ of its adjacent nodes at radius $i+1$ from $\\mathcal{O}$. \n\n\t\\item Duplicate the row of entry $p$ while appending to it each of the $n_p$ adjacent nodes at column $i+1$. If $n_p=0$, append $``empty\"$ instead. The process is akin to a Cartesian product.\n\n\t\\item Return the RM for $\\mathcal{O}$.\n\\end{enumerate}\n\nNote that the column number will coincide with the radius from $\\mathcal{O}$. The RM with $n$ columns is a representation of the connectivity from the origin up to radius $n$, where each row is the shortest path from the origin to a point at radius $n$, and there may exist many such paths.\n\n\\algtitle{Army Matrix (AM) for an origin node $\\mathcal{O}$}\nWe can convert an RM into AM, a representation using the number of armies,\n\\begin{enumerate}\n\t\\item Find the RM for node $\\mathcal{O}$ using the RM algorithm.\n\t\\item For each entry $p$ in RM, if node $p$ has the same owner as $\\mathcal{O}$, replace the entry with the number of army at $p$; else, replace with the negative of the number of army at $p$. If an entry $p$ is $``empty\"$, append 0 instead.\n\t\\item return the AM for $\\mathcal{O}$.\n\\end{enumerate}\n\n\nThis transforms an RM into its alternate form AM, which gives a representation of the army distribution and connectivity around the origin node $\\mathcal{O}$. This matrix can be used for calculating the $\\textbf{pressure}$ from definition \\ref{pressure}. For our project we calculate the matrices up to radius 5, which we think is sufficient given that per game turn a player can only move adjacently among nodes.\n\n\n\n\n\n\\subsection{The Pressure Algorithm}\n\nThe pressure of each node from an AI's point of view is the average number of army surrounding the node. More positive pressure indicates the node is a better stronghold of the AI; more negative pressure indicates is surrounded by more enemies.\n\nThe calculation of pressure depends on the AI's perception of threat, which can be represented using a metric that varies based on its personality.\n\n\\begin{definition}\nThe $\\textbf{threat perception}$ of an AI is the way it sees the threat of army distribution up to some radius away poses on an origin node. E.g. 10 enemy armies further away poses less threat than 5 enemy armies nearby. The $\\textbf{threat perception}$ is quantified by defining a metric: a normalized vector or length = max radius of AM, where the individual value of the vector is the weight multiplied to the army number at that radius. The procedure is describe below.\n\\end{definition}\n\n\\algtitle{The Metric Algorithm}\nTo enumerate the metric for an AI's threat perception, with scope radius = 5,\n\\begin{enumerate}\n\t\\item Choose a weight function, for example, constant, Gaussian,\n\t\\item Evaluate function values for with the input distance vector $\\{1,2,3,4,5\\}$\n\t\\item Renormalize the output vector and return it as the metric vector.\n\\end{enumerate}\n\nThis metric vector $\\mathbf{w}$ is then dotted with a row $\\mathbf{r}$ in the AM, which is a list of number of armies at incremental distance away from an origin node $\\mathcal{O}$, and the partial pressure $\\emph{PP}$ for it is:\n$$\\emph{PP}(\\mathbf{r}) = \\mathbf{w} \\cdot \\mathbf{r}$$\n\n\n\\algtitle{The Pressure Algorithm}\nThe AI calculates the pressure for each node using its personality trait $\\textbf{threat-perception}$, or the metric vector $\\mathbf{w}$:\n\\begin{enumerate}\n\t\\item Update the data fields of the map and call the AM algorithm to compute the AMs for all 42 nodes.\n\t\\item For each node $\\mathcal{O}$, compute the dot product between $\\mathbf{w}$ and each row of the node's AM; the result is a column vector $\\mathbf{c}$.\n\t\\item The first column of the original RM is a repeated list of $m$ adjacent nodes of $\\mathcal{O}$, suppose each node $i$ repeats $q_i$ times in the column, so in total the column has length $q_1 + q_2 + \\cdots + q_m$. Renormalize this sequence into $nq_1 + nq_2 + \\cdots + nq_m$ For each batch $q_i$ of the column vector $\\mathbf{c}$ from above, take its mean, then multiply by the renormalized weight $nq_i$. Then sum all $m$ of the results, call this scalar $s(\\mathcal{O})$.\n\t\\item Now that the column $\\mathbf{c}$ has been reduced to a scalar representing the average army distribution around the origin $\\mathcal{O}$, account for the number of armies (sign-sensitive, negative for enemy) here $a(\\mathcal{O})$ by adding the scalar, and return the pressure of node $\\mathcal{O}$, $P(\\mathcal{O}) = s(\\mathcal{O}) + a(\\mathcal{O})$.\n\\end{enumerate}\n\n\nThus at each turn, the AI updates the data fields and calculates the pressure, i.e. the average number of surrounding armies, for each node, using its threat perception metric.\n\n\n\n\n\\subsection{The Worth Algorithm}\n\n\\algtitle{The Worth Algorithm}\nAt each turn, the AI evaluates the worth of each node to prioritize its attacks and defenses. Suppose it considers $m$ factors, each of which assumes a real positive value, with more positive being more worthy. To compute the final worth scalar, simply order the $m$ factors from the most vital, and dot it with a factor vector $\\{10^{m-1}, ..., 100, 10, 1\\}$.\n\nFor our AI, we consider the following factors (ordered from the most important). For each node $\\mathcal{O}$ calculate and append to the list of factors:\n\n\\begin{enumerate}\n\t\\item continent-fraction = $\\frac{\\text{(number of nodes with the same owner in the same continent $\\mathcal{O}$)}}{\\text{(total number of nodes in the continent)}}$\n\t\\item If $\\mathcal{O}$ is own node, the region-index: Enumerate for each player its nodes, and group them by regions, then order them from the biggest to the smallest regions. The region-index of $\\mathcal{O}$ is its index in this list. Or if $\\mathcal{O}$ is enemy, the attackable index: of the region list enumerated above, extract the sublist with nodes that are attackable, i.e. is an enemy adjacent to one of your nodes. The attackable index of $\\mathcal{O}$ is its index in this sublist; -1 otherwise.\n\t\\item shape: find the region $\\mathcal{O}$ is in and compute the shape as in definition \\ref{shape}.\n\t\\item degree: the degree of $\\mathcal{O}$, i.e. the number of adjacent nodes it has.\n\t\\item pressure: as calculated from the pressure algorithm.\n\t\\item Finally, return the dot product between this factor list and $\\{10^{4}, 1000, 100, 10, 1\\}$.\n\\end{enumerate}\n\n\nAfter obtaining an ordered list of worth nodes, we can partition it while preserving the order into lists of border nodes and attackable nodes, and reorder them based on strategies. Furthermore, the AI makes it context-sensitive by remembering the pressures from the past turn, and reorder the list based on pressure-drop between turns.\n\n\n\nTo justify our factors above, conquering a whole continent gives a player extra armies per turn while strengthening the region. Furthermore, a larger region is harder to attack than a smaller region, thus we place more importance on the nodes there. \n\nThe shape of a region is vital for defense and army mobility during fortification. This is the classic problem of minimizing the surface/volume ratio, or in this lower dimensional case, the perimeter/surface ratio. Intuitively, a thin region is vulnerable, and has bad army mobility. A thick, concentric shape is stronger. The average distance between nodes is also shorter and thus aids mobility. Moreover, a node with higher degree improves mobility since it can reach many other nodes.\n\nThe pressure measures the ease of attacking or defending a node; the less negative a node is, the less enemy presence it has. It is wise to not attack the enemy's stronghold, but to seek its weak point of entry, which can be detected from a less-negative pressure.\n\n\n\\subsection{The Priority Algorithm}\nAt each game turn, the AI updates the priority nodes to attack/defend. The list of priority nodes depends on the AI's personality trait $\\textbf{priority}$, whether it is agressive (attack-then-defend) or defensive (defend-then-attack).\n\n\\algtitle{The Priority Algorithm}\n\\begin{enumerate}\n\t\\item Update the data fields for the AI.\n\t\\item Call the pressure algorithm on the map.\n\t\\item Call the worth algorithm on the map.\n\t\\item Repartition the worth nodes and reorder by attackables/borders first based on the AI's personality, whether agressive or defensive. Furthermore, for the attackable, choose the best origin of attack by the highest pressure.\n\\end{enumerate}\n\n\n\n\n\n\n\n\\subsection{The Placement Algorithm}\nThis describes how the AI places the armies into the its priority nodes based on its personality trait $\\textbf{placement}$.\n\n\\algtitle{The Placement Algorithm}\n\\begin{enumerate}\n\t\\item If the trait is $\\textbf{cautious}$, place armies along its  priority nodes (if is enemy, use the best origin of attack) until all pressures are $>0$, then with the extra armies, place 4 each down the same list; repeat until none left.\n\t\\item If the trait is $\\textbf{tactical}$, place armies down the list until node pressure is $>4$, then with extra, place 4 each down the list; repeat until none left.\n\\end{enumerate}\n\n\n\n\n\n\n\n\\subsection{The Attack Algorithm}\nThe AI decides to launch attacks from the best attack origin (calculate with in priority list) based on its personality trait $\\textbf{attack}$.\n\n\\algtitle{The Attack Algorithm}\nFor all attackables down the priority list,\n\\begin{enumerate}\n\t\\item If the trait is $\\textbf{rusher}$, the AI harassess constantly, i.e. while the best attack origin has 2 more armies than the enemy target, keep attacking before moving to next target.\n\t\\item If the trait is $\\textbf{carry}$, same as above, but the difference threshold is 4 (higher). Furthermore, the AI will accumulate the cards to reserve more armies for late game.\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\\subsection{The Fortifying Algorithm}\nAll AIs use the same fortifying algorithm.\n\n\\algtitle{The Fortifying Algorithm}\n\n\\begin{enumerate}\n\t\\item Find the border node $\\mathcal{O}$ with the lowest pressure, and find a non-border ally node with higher pressure, transfer all but 1 troop to the border node if possible. This is to always push the unused central forces out to the borders where armies are mostly needed.\n\t\\item If no fortification done above, find a border node with the highest pressure, and transfer any neighboring armies (all but 1) to it. This is for the accumulation of armies during late game by making strong node even stronger.\n\\end{enumerate}\n\n\nThis algorithm aims to create a center-weak border-strong army distribution within a region with, that is to utilize the maximum number of armies by putting them to the border nodes. Such distribution is efficient for both offense and defense. The second part of the algorithm kicks in when there is less border nodes during the late game, when one player controls a larger region. This will accumulate all armies toward a border node to overwhelm the enemy, hopefully ending the game quicker.\n\n\n\n\n\n\n\n\\section{AI Algorithms and Personalities}\n\nWe now put everything together to form the AI, which has four personality traits parametrized in its algorithms: \n\n\\begin{enumerate}\n\t\\item The $\\textbf{threat perception}$ trait /metric in the Pressure Algorithm; function variations: \\{Constant, Survival\\}.\n\t\\item The $\\textbf{priority}$ trait in the Priority Algorithm; variations: \\{agressive, defensive\\}.\n\t\\item The $\\textbf{placement}$ trait in the Placement Algorithm; variations: \\{cautious, tactical\\}.\n\t\\item The $\\textbf{attack}$ trait in the Attack Algorithm; variations: \\{rusher, carry\\}.\n\\end{enumerate}\n\nThus there are $2^4 = 16$ AI personalities, and more if we allow richer variations.\n\n\nCorresponding to the game moves per turn:\n\\begin{enumerate}\n\\item Getting and placing new armies;\n\\item Attacking, if you choose to, by rolling the dice; \n\\item Fortifying your position (moving troops between an adjacent pair of your nodes),\n\\end{enumerate}\n\nthe AI has these primary methods:\n\\begin{enumerate}\n\\item Update: Call the Priority and Worth algorithms.\n\\item Get-and-Place-Armies: Call the Placement Algorithm.\n\\item Attack: Call the Attack Algorithm as many times as wanted.\n\\item Fortify: Call the Fortify Algorithm.\n\\end{enumerate}\n\n\n\nA game can have as many participating AIs as permitted by the rules. During the initial game setup, countries are randomly assigned to the AIs. Then, the AIs take turn to call their Update and Get-and-Place-Armies methods to complete the setup. Then the game begins and the AIs take turn to call all their primary methods in sequence, until the game terminates, or ties at the maximum number of rounds.\n\nAs opposed to physical game, the virtual game has no limit on the number of army pieces $-$ it just keeps creating more as needed; nor it has the limit on the cards $-$ it keeps reshuffling a new deck once an old one runs out.\n\n\nNext we present the results from our implementation.\n\n\\section{Implementation Results}\n\n\\subsection{Formalization of Problem}\nOur initial approach to the problem is one that focuses on the gross number of countries and armies an AI possesses throughout the game. As the game progresses, we monitor how the AI’s interact in their attempt to win both armies and territories based on their personalities. From this, conclusions were drawn regarding personality types, player order effect, as well as game starting conditions. \n\n\n\\subsection{Algorithms and Decisions}\n\n\\subsubsection{Initial Concerns}\nAn initial issue was normalization of the time axis across several games. While games were initially capped at 100 rounds, where the game was declared a draw, the games that did not end in a draw had variable game length. The majority of the data analysis done in this project was done where there was a definitive winner. From this, the time axis was normalized by considering games in terms of percentage of game length. To the AI the length of the game is unknown during gameplay. However, the analysis can show where pivotal points occur across the game. While initially, players will be unable to use this information an understanding of both territorial and army control will influence their decisions.\n\n\n\\subsubsection{The Difference Plots}\nIn this analysis, the percentage of both armies and countries in total will be compared to the percentage of the game in where these points occur. These points for players \\emph{p1, p2} will be found using the following \n$$\\emph{diff\\_army} = \\frac{\\emph{p1\\_army - p2\\_army}}{\\emph{p1\\_army - p2\\_army}}$$\n$$\\emph{diff\\_country} = \\frac{\\emph{p1\\_country - p2\\_country}}{\\emph{p1\\_country - p2\\_country}}$$\n\nThis data is stored in a matrix that holds both army numbers and round numbers. In this matrix, data from games resulting in draws is discounted. The equation will hold for any winner. From this we expect a divergent trend from zero as the game proceeds to an end. From this matrix the difference in both armies and countries are calculated and plotted in R. From this, R will produce a trend line. This trend line will provide information for both the initial game play configuration and the development of the game. \n\n\n\\subsubsection{The Fun Function}\nIn this analysis a fun function was built to hold and later display some basic analysis of the games played. The fun function includes, total wins of both AI’s, probability of winning, odds of winning, the average total armies, the average total armies during a win, the maximum number of armies needed to win , the minimum number of armies needed to win, average turns, and average turns without ties. When a game play data set is passed from the JSON through the rjson package, the function returns this summary of game play. \n\nImbedded in this function is the survival plot of two AI’s. The survival package in R allows from the plotting of the survival of both armies over the course of the game. As before, the data is filtered to view only games that have a definitive winner. These graphs show the deterioration of the two AI’s over the course of the game. From this, conclusions regarding how the game develops can be made. \n\n\n\n\\subsection{Results, Performance, and Analysis }\nWe immediately see several trends given by the fun function. A clear player order effect was found between nearly every AI. While some AI’s were simply more powerful and able to win regardless of characteristics, in nearly every case we see that more wins are generated from the AI if they play first compared to when they play second. For some more closely related AI’s, the odds of winning changes in its favor given the player order effect. From this we can conclude that for certain comparable AI’s, player order may greatly affect the outcome of the game. \n\nFurthermore, in every case, the trend line from the total army plot simply shifted its intercept value but held consistent slope. This intercept can be credited to first round play. After the first round (when the first point is calculated) the army advantage can be a one player advantage. This first round however rarely changes the results of the game. Consider figure 1. \n\n\\begin{center}\n\\includegraphics[scale=0.6]{images/Figure_1.jpg}\\\\\n{\\footnotesize Figure 1.}\n\\end{center}\n\nHere the green and red dots represent AI0’s and AI4’s percent total armies respectively over time. Again, the dots only represent games in which a definitive winner was found. Here we see that AI0 has a clear advantage but when the player order is changed, AI4 wins more games. Notice, however, while the trend line shifts down, that the slope stays constant. This implies that while the game is certainly affected by player order, on average, the game develops the same regardless of player order. \n\nFor the same AI match, the fun function provides two survival charts. Now consider figure 2. \n\n\n\\begin{center}\n\\includegraphics[scale=0.6]{images/Figure_2.jpg}\\\\\n{\\footnotesize Figure 2.}\n\\end{center}\n\nIn the first plot we see that player two holds several armies until near round 50. Suddenly over the next two rounds however, we see an incredible drop off. AI0 has mostly defensive characteristics. From this it appears that AI0 condenses its portion of the graph and builds armies. Somewhere near halfway through the game, it branches out and gains several territories in a very small period of time. When the order of the game is reversed we see a much more even trend. Both AI’s seem to lose armies at a consistent rate. This effect could be accredited to player order effect or the characteristics of the players in regards to their section of the sub graph. \n\n\nWhile these trends, in general, hold true, one AI in particular defied the general trends. We will call this AI, AI3. AI3, in general, tended to produce more wins when playing in the second player position. This trend was tested more rigorously against 15 new AI’s. From this data, the fun function produced the win records for both AI3 and the other AI’s for both player order. The difference between wins was then calculated. That is $\\Delta \\emph{win} = \\emph{AI3\\_wins} - \\emph{AIOpponent\\_wins}$. This figure was calculated for both player orders. This data is represented in figure 3.\n\n\n\n\\begin{center}\n\\includegraphics[scale=0.6]{images/Figure_3.jpg}\\\\\n{\\footnotesize Figure 3.}\n\\end{center}\n\n\nAs in figure 3, on average AI3 wins 3.625 games while playing second in comparison to playing first where the AI won only 0.5 games on average. This in turn would seem to offer a solution to the player order effect, mentioned above. By simply playing the AI3 characteristics (“Survival”, “Defensive”, “Cautious”, “Carry”), on average the advantage would go to the second player, thus making player order obsolete. \n\n\nAnother nuanced observation shows that this conclusion may not be entirely true. Under further observation, another AI which we will call AI4 (“Survival”, “Aggressive”, “Tactical”, “Rusher”) seemed to be superior to AI3 in both player orders. A more rigorous study of these two AI’s revealed that the assumption was correct. The fun function showed that on average, AI4 wins more often than AI3. Consider figure 4 and figure 5. \n\n\n\n\\begin{center}\n\\includegraphics[scale=0.6]{images/Figure_4.jpg}\\\\\n{\\footnotesize Figure 4.}\\\\\n\\includegraphics[scale=0.6]{images/Figure_5.jpg}\\\\\n{\\footnotesize Figure 5.}\n\\end{center}\n\nNotice that these two figures show very low correlation when player order changes. When AI3 goes first, it grosses more wins than AI4. When AI3 goes second, however, AI4 wins the majority of the games. While by a narrow margin, when AI4 goes first, AI4 wins 56 more games than AI3 in a 500 game trial. Thus if AI3 plays second they will on average lose to AI4. \n\n\n\\subsection{AI behaviors and Surprises}\nIn this project several AI’s were posed against each other in a game of Risk. Initially, it was predicted that a large player order effect would affect the game. This hypothesis held true for the majority of AI’s that were tested in this experiment. AI3 however, proved that by using the correct strategy, a player would actually hold an advantage by going second in the game. From this however, AI4 proved that their still exist AI’s that can beat AI3 while being the first player to move. \n\nFrom this project, we advise future Risk players to abstain from declaring their player strategy until the player order is determined. From this, we advise that second players play a cautious, defensive game, while first players play with aggressive tendencies. A consistent analysis of strategy will reveal the best strategy for either player to take throughout the duration of the game. \n\n\n\n\\section{Conclusion}\nWe have reformalized the board game \\emph{Risk} as a graph optimization, and implemented an AI to solve the problem, i.e. to play the game. Several decision algorithms were devised based on graph properties, and they in turn form the personalities of the AI. Our study of 4 binary traits, or a total of 16 personality variations of the AI, is merely the beginning. We have discovered some interesting AI behaviours and performance at a level beyond any human players. One can potentially investigate even more variations of the traits.\n\nFor future studies, an analysis of subgraphs would provide deep insight into the value of individual territories. The AI’s are built in such a way that the priority function is based off of current demographic of troops and shape of their graph. Evaluating the graph as a whole would provide insight to the value of different subgraphs that would proactively affect the priority function. This conditional thinking is much more like the ideas of a human player and thus could inform future strategies. \n\nFurthermore, game shifts could be analyzed using the fun function and the aforementioned subgraph analysis. This would allow for defensive players an understanding of which territories that are worth defending and worth conceding. This shift parameter would allow for insight to game length, army distribution, and other key factors.  \n\n\n\n\n\n\\section{Citations}\n\nHasbro, \\emph{Risk, The World Conquest Game \\circledR, Rules ©1959, 1963, 1975, 1980, 1990, 1993}, Parker Brothers, Division of Tonka Corporation, Beverly, MA 01915, U.S.A.\n\n\n\n\n\\end{document} \n\n", "meta": {"hexsha": "3850e165d735a9ac00ab944999d4afbc160ecf10", "size": 30836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/Risk-game-paper.tex", "max_stars_repo_name": "kengz/Risk-game", "max_stars_repo_head_hexsha": "7686716a017eb55fe596572924e11ad27346375a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-06-27T23:55:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-03T08:15:03.000Z", "max_issues_repo_path": "paper/Risk-game-paper.tex", "max_issues_repo_name": "kengz/Risk-game", "max_issues_repo_head_hexsha": "7686716a017eb55fe596572924e11ad27346375a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-11-30T00:56:42.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-05T14:02:04.000Z", "max_forks_repo_path": "paper/Risk-game-paper.tex", "max_forks_repo_name": "kengz/Risk-game", "max_forks_repo_head_hexsha": "7686716a017eb55fe596572924e11ad27346375a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-11-26T06:34:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T10:28:01.000Z", "avg_line_length": 65.4692144374, "max_line_length": 708, "alphanum_fraction": 0.7725061616, "num_tokens": 7362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6629280790016596}}
{"text": "\\documentclass{article}\n\\usepackage[T1]{fontenc}\n\\usepackage[utf8]{inputenc}\n\\usepackage{unicode,math}\n\\usepackage[margin=30mm]{geometry}\n\\newenvironment{eqsplit}{\\equation\\aligned}{\\endaligned\\endequation}\n\n\n\\begin{document}\n\\title{Useful geometric computatoins}\n\n\n\\section{Uniform approximation of a parabolic arc by a polygonal chain}%««1\n\\begin{prop}\\label{prop:points}\nLet~$𝒫$ be the parabola with equation $y = f(x) = a/2 + x²/2a$.\nLet~$H$ be the hypergeometric function\n$H(u) = {}_2F_1(1/4,1/2;\\;3/2\\;-u^2)$.\n\nChoose real numbers~$s_1$, $s_2$ and an integer~$n ≥ 1$\nand define, for~$i = 0, …, n$,\n$x_i = a H^{-1}((1-i/n) s_1 + (i/n) s_2)$.\n\nThen, for $n$ large enough,\nthe polygonal line with vertices~$A_i = (x_i, f(x_i))$\nlies within a Minkowski distance~$δ = \\frac{a}{8n^2}\n(s_2-s_1)^2+O(n^{-4})$ of the parabola~$𝒫$.\n\\end{prop}\n\n\\begin{proof}\nIt is enough to prove this for an individual segment of the polygonal line,\nfor example the segment $(A_0, A_1)$.\nFor~$x_0 ≤ x ≤ x_1$, the distance between a point~$(x, f(x)) ∈ 𝒫$\nand the segment~$(A_0, A_1)$ is given by the function\n% \tthe maximum on the interval~$[x_0,x_1]$ of the function\n\\begin{equation}\\begin{split}\ng(x)\n%  &= \\frac{(x_0+x_1)/(2a) x - f(x) + x_0 x_1/(2a) + a/2}{√{1+(x_0+x_1/2a)^2}}\\\\\n &= \\frac{(x_0+x_1) x - 2a f(x) + x_0 x_1 + a^2}{√{(2a)^2+(x_0+x_1)^2}}\\\\\n%  &= \\frac{(x_0+x_1) x - a^2 - x^2 + x_0 x_1 + a^2}{√{(2a)^2+(x_0+x_1)^2}}\\\\\n &= \\frac{(x-x_0)(x_1-x)}{√{(2a)^2+(x_0+x_1)^2}}.\\\\\n\\end{split}\\end{equation}\nThe maximum value~$δ_0$ of~$g$ on the interval~$[x_0,x_1]$\nis reached for~$x = (x_0+x_1)/2$\nand amounts to $δ_0 = \\frac{(x_1-x_0)^2}{4√{(2a)^2+(x_0+x_1)^2}}$.\n\nLet~$G = H^{-1}$ and~$x(t) = a G((1-t) s_1 + t s_2)$.\nThen for all~$i = 0,…, n$, $x_i = x(i/n)$\nand $x_{i+1} - x_i = x'(i/n)/n + O(1/n^2)$.\nTherefore\n\\begin{equation}\nδ_i = \\frac{x'(i/n)^2}{8n^2 √{a^2 + x_i^2}} + O(1/n^4).\n\\end{equation}\n\nSince $H'(u)^4 = 1/(1+u^2)$,\nthe inverse~$G$ of~$H$ satisfies the differential equation\n$(G')^4 = 1 + G^2$,\nand hence $x'(t)^2 = a (s_2 - s_1)^2 √{a^2 + x(t)^2}$.\nAccordingly, one finds\n\\begin{equation}\nδ_i = \\frac{a}{8n^2} (s_2-s_1)^2 + O(1/n^4).\n\\end{equation}\nSince this is true for all~$i = 0,…,n-1$, the proposition follows.\n\\end{proof}\n\n\n\\begin{prop}\\label{prop:approx}\nThe following algorithm approximates the parabola~$𝒫$\non the interval~$[X_1,X_2]$ within a distance~$≤ δ + O(δ^2)$.\n\\begin{enumerate}\n\\item For~$i = 1,2$, define $s_i = H(X_i/a)$.\n\\item Let~$n ≥ \\abs{s_2-s_1} √{a/(8δ)}$.\n\\item Define the points~$(x_i=a H^{-1}(s_1 + \\frac{i}{n}(s_2-s_1), f(x_i))$\nas in Prop.~\\ref{prop:points}.\n\\end{enumerate}\n\\end{prop}\n\n\n% \\section{Arc length of an Archimedean spiral (wrapped line segment)}%««1\n% \n% Let~$F$ be the transformation on~$ℝ^2$ defined by\n% $F(x,y) = (x \\cos(y/x), x \\sin(y/x)$.\n% \n% \\begin{prop}\n% Let~$S = (p_0, p_1)$ be a line segment, with $p_i = (x_i, y_i)$,\n% such that $0 < x_0 < x_1$.\n% Let~$a = x_0 - x_1$, $D = x_0 y_1 - y_0 x_1$,\n% and $z_i = D+√{a^2 x_i^2 + D^2}$.\n% Then the arc length of the image curve~$F(S)$ is\n% \\[ \\begin{cases}\n%   \\frac{D}{a} \\log \\frac{x_1 z_0}{x_0 z_1}\n% \t+ a \\pa{\\frac{x_1^2}{z_1}-\\frac{x_0^2}{z_0}}&\n% \t\\text{if $x_0 ≠ x_1$;}\\\\\n% \tx_0 \\abs{y_0 - y_1} &\\text{if $x_0 = x_1$.}\\end{cases}\n% \\]\n% \\end{prop}\n% \\begin{proof}\n% The segment is parametrized as $p(t) = (1-t) p_0 + p_1\n%  = (t (x_1-x_0) + x_0, t (y_1 - y_0) + y_0).\n%  = (a t +  b, c t + d)$\n% with $a = (x_1-x_0)$, $b = x_0$, $c = (y_1 - y_0)$, $d = y_0$.\n% In complex notation, one finds\n% $F(p(t)) = (a t + b) \\exp(i \\frac{ct+d}{at+b})$ and hence\n% \\begin{eqsplit} F(p(t))'\n% &= a e^{i…} + (a t + b) i \\frac{bc-ad}{(at+b)^2} e^{i…} \\\\\n% &= \\pa{a + i \\frac{bc - ad}{at + b}} \\exp\\pa{i \\frac{ct+d}{at+b}};\\\\\n% \\abs{F'(p(t))}\n% &= √{a^2 + \\frac{(ad-bc)^2}{(at+b)^2}}.\n% \\end{eqsplit}\n% The arc length is therefore\n% \\begin{eqsplit}\n% &= ∫_0^1 \\abs{F'(p(t))} dt\n% &= ∫_0^1 √{a^2 + \\frac{(ad-bc)^2}{(at+b)^2}} dt\\\\\n% &= ∫_0^1 √{a^2(at+b)^2 + (ad-bc)^2} \\;\\frac{dt}{at+b} \\\\\n% % &= a ∫_0^1 √{(at+b)^2 + (d-bc/a)^2} \\;\\frac{dt}{at+b} \\\\\n% \\end{eqsplit}\n% Define $s = (at+b)/(D+√{a^2(at+b)^2+D^2})$,\n% so that $t = -b/a+2sD/(a^2(1-s^2))$,\n% $√{(at+b)^2+D^2/a^2} = D\\frac{1+s^2}{1-s^2}$,\n% and $dt = 2D/a^2 \\frac{1+s^2}{(1-s^2)^2} ds$.\n% Then\n% \\begin{eqsplit}\n% G(t) = ∫ \\abs{F'(p(t))} dt\n% &= \\frac{D}{a} ∫ \\pa{\\frac{1+s^2}{1-s^2}}^2 \\frac{ds}{s}\\\\\n% &= \\frac{D}{a} ∫ \\pa{\\frac 1s +\\frac{1}{(s-1)^2} - \\frac{1}{(s+1)^2}} ds\\\\\n% &= \\frac{D}{a} \\pa{\\log s + \\frac{2}{1-s^2}}\\\\\n% &= \\frac{D}{a} \\pa{\\log \\frac{at+b}{D+√{a^2(at+b)^2+D^2}}\n%  + 2 \\frac{(D+√{a^2(at+b)^2+D^2})^2}{(D+√{a^2(at+b)^2+D^2})^2-(at+b)^2}}\\\\\n% &= \\frac{D}{a} \\pa{\\log \\frac{at+b}{D+√{…}}\n%  + 2 + \\frac{a^2}{D}\\frac{(at+b)^2}{D+√{…}}}\\\\\n% &= \\frac{D}{a} \\log \\frac{at+b}{D+√{a^2(at+b)^2+D^2}} + \\frac{2D}{a}\n%  + a \\frac{(at+b)^2}{D+√{a^2(at+b)^2+D^2}}\n% \\end{eqsplit}\n% The primitive~$G-2D/a$ takes the following values:\n% \\begin{eqsplit}\n% G(0)\n% &= \\frac{D}{a} \\log \\frac{x_0}{D+√{a^2 x_0^2 + D^2}}\n%  + \\frac{a x_0^2}{D+√{a^2 x_0^2+D^2}}\\\\\n% G(1)\n% &= \\frac{D}{a} \\log \\frac{x_1}{D+√{a^2 x_1^2+D^2}}\n%  + \\frac{a x_1^2}{D+√{a^2 x_1^2+D^2}}\\\\\n% \\end{eqsplit}\n% This concludes the case where~$a ≠ 0$. The other case is trivial.\n% \\end{proof}\n% % »»1\n% \\section{Arc length of wrapped segment (correct)}%««1\n% Let~$F(x,y,z) = ((x+r) \\cos(y/r), (x+r) \\sin(y/r), z)$.\n% \\begin{prop}\n% Let~$S = (p_0, p_1)$ be a line segment, with $p_i = (x_i, y_i, z_i)$.\n% Define~$a = x_0 - x_1$ and~$c = z_0 - z_1$,\n% and $λ_i = √{b^2 x_i^2/r^2 + a^2 + c^2}$.\n% If $a ≠ 0$ and $b ≠ 0$ then the arc length of the image curve~$F(S)$ is\n% \\[\n%   \\frac{1}{2a}(λ_1 x_1 - λ_0 x_0)\n% + \\frac{a^2 b^2+c^2 r^2}{2a b r} \\log \\frac{b x_1 + r λ_1}{b x_0 + r λ_0}.\n% \\]\n% If $a = 0$ or~$b = 0$ then this arc length is $√{a^2 + b^2 x_0^2/r^2 + c^2}$.\n% \\end{prop}\n% The segment is parametrized as\n% $p(t) = (1-t) p_0 + p_1\n%  = (t(x_1-x_0) + x_0, t (y_1 - y_0) + y_0, t (z_1 - z_0) + z_0)\n%  = (a t + x_0, b t + y_0, c t + z_0)$.\n% \\begin{eqsplit}\n% F(p(t))\n% &= ((a t+x_0+r) \\cos \\frac{b t+y_0}{r}, (at+x_0+r)\\sin\\frac{bt+y_0}{r},\n% ct+z_0) \\\\\n% F(p(t))'\n% &= (a \\cos φ(t) - x(t)b/r \\sin φ(t) , a \\sin φ(t) + x(t)b/r \\cos φ(t), c) \\\\\n% \\norm{F(p(t))'}\n% &= √{a^2 + (at+x_0)^2 b^2/r^2 + c^2}\n% \\end{eqsplit}\n% Using $∫ √{(α t+β)^2+γ^2} d t = \\frac{α t+β}{2 α} √{…}\n%   + \\frac{γ^2}{2 α} \\log(α t+β+√{…})$\n% with $α = ab/r$, $β=x_0 b/r$, $γ^2 = a^2+c^2$:\n% \\begin{eqsplit}\n% ∫ \\norm{F(p(t))'} dt\n% &= \\frac{(b/r)(a t+x_0)}{2ab/r} √{…}\n%   + \\frac{a^2 b^2/r^2+c^2}{2ab/r} \\log((b/r)(at+x_0)+√{(at+b)^2+a^2+c^2})\\\\\n% &= \\frac{x(t)}{2a} √{b^2 x(t)^2/r^2+a^2+c^2}\n%   + \\frac{a^2 b^2+c^2 r^2}{2a b r} \\log(b x(t)/r+√{b^2 x(t)^2/r^2+a^2+c^2})\\\\\n% \\end{eqsplit}\n% % Define $q = √{a^2+e^2}$ and~$s = (at+b)/(q+√{q^2+(at+b)^2})$; then\n% % $t = -b/a+2sq/a(1-s^2)$, $√{q^2+(at+b)^2} = q(1+s^2)/(1-s^2)$,\n% % and $dt = 2q/a (1+s^2)/(1-s^2)^2$.\n% % Thus the arc length~$L$ is\n% % \\begin{eqsplit}\n% % ∫_0^1 |F(p(t))'|\\;dt\n% % &= ∫_0^1 √{q^2+(at+b)^2}\\; dt \\\\\n% % &= \\frac{2 q^2}{a} ∫ \\frac{(1+s^2)^2}{(1-s^2)^3}\\;ds \\\\\n% % &= \\frac{2 q^2}{a} ∫\n% % \\pa{\\frac{1/4}{s+1}-\\frac{1/4}{s-1}+\\frac{s^4+6s^2+1}{2(1-s^2)^3}}\\; ds\\\\\n% % &= \\frac{2 q^2}{a} \\pa{ \\frac 14 \\log \\frac{s+1}{s-1}\n% %   + \\frac 12 \\frac{s(s^2+1)}{(1-s^2)^2}}\\\\\n% % &= \\frac{2 q^2}{a} \\pa{\\frac 14 \\log \\frac{q+b+u}{q-b+u}\n% %  + \\frac 12 \n% % \\end{eqsplit}\n% \n% % »»1\n\\section{Sagitta of wrapped segment}%««1\nLet~$F(x,y,z) = ((x+r) \\cos(y/r), (x+r) \\sin(y/r))$.\n\\begin{prop}\nLet~$S = (p_0, p_1)$ be a line segment, with $p_i = (x_i, y_i)$.\n% Define~$a = x_0 - x_1$ and~$c = z_0 - z_1$,\n% and $λ_i = √{b^2 x_i^2/r^2 + a^2 + c^2}$.\nThe \\emph{sagitta} of~$F(S)$ is the Minkowski distance\nbetween the image curve $F(S)$ and the straight segment $(F(p_0),F(p_1))$.\n\n\\end{prop}\nDistance in polar coordinates $(r e^{iθ})$:\n\\begin{eqsplit}\n\\norm{r_0 e^{iθ_0} - r_1 e^{iθ_1}}^2\n&= \\norm{r_0 e^{iθ_0}}^2 + \\norm{r_1 e^{i θ_1}}^2\n  - 2 (r_0 e^{iθ_0})⋅(r_1 e^{i θ_1}) \\\\\n&= r_0^2 + r_1^2 - 2 r_0 r_1 \\cos(θ_0 - θ_1).\n\\end{eqsplit}\nLet~$Σ = (F(p_0), F(p_1))$,\nthen $ℓ(Σ)^2 = (x_0+r)^2 + (x_1+r)^2 - 2 (x_0+r)(x_1+r) \\cos((y_0-y_1)/r)$.\n\nThe segment $(p_0, p_1)$ is parametrized as\n$p(t) = (1-t) p_0 + p_1\n = (t(x_1-x_0) + x_0, t (y_1 - y_0) + y_0)\n = (a t + x_0, b t + y_0)$,\nso that\n$F(p(t)) = (ξ(t), η(t)) = ((r+x(t)) \\cos(y(t)/r), (r+x(t)) \\sin(y(t)/r))$.\nThe squared distance of a point $F(p(t))$ to the\nsegment~$Σ=(F(p_0),F(p_1))$\nis\n\\begin{eqsplit}\nδ(t)^2\n&= \\frac{1}{\\norm{Σ}^2} \\chev{F(p(t))-F(p_0),F(p_1)-F(p_0)}^2\\\\\n&= \\frac{(x(t)-x_0)(y_1 -y_0) - (y(t) - y_0)(x_1 - x_0)}{\\norm{Σ}^2}\\\\\n\\end{eqsplit}\n\n\\end{document}\n% vim: fdm=marker fmr=««,»»:\n", "meta": {"hexsha": "2de83cba4521d25422d71b95a4fbb4b5a182bc94", "size": 8645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geometry.tex", "max_stars_repo_name": "plut/ConstructiveGeometry.jl", "max_stars_repo_head_hexsha": "0f384d6307513ec83ee030161d22937d3b65294b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2021-02-23T07:51:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T22:37:19.000Z", "max_issues_repo_path": "geometry.tex", "max_issues_repo_name": "plut/ConstructiveGeometry.jl", "max_issues_repo_head_hexsha": "0f384d6307513ec83ee030161d22937d3b65294b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-03-02T22:22:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T06:27:57.000Z", "max_forks_repo_path": "geometry.tex", "max_forks_repo_name": "plut/ConstructiveGeometry.jl", "max_forks_repo_head_hexsha": "0f384d6307513ec83ee030161d22937d3b65294b", "max_forks_repo_licenses": ["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.7872340426, "max_line_length": 80, "alphanum_fraction": 0.5260844419, "num_tokens": 4568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6629280777593308}}
{"text": "%!TEX root = morusAC.tex\n\n\\section{Symmetric Linear Combinations and \\MiniMORUS}\n\\label{sec/introminimorus}\n\nTo simplify the description of the attack, we assume all plaintext blocks are zero. This assumption will be removed in \\Cref{subsec:variable}, where we will show that plaintext bits only contribute linearly to the trail. Recall that the inner state of the cipher consists of five $4w$-bit registers $S_0,\\dots,S_4$, each containing four $w$-bit words.\n\n\\subsection{Symmetric Linear Combinations}\n\nWe begin with a few observations about the \\StateUpdate{} function. Besides XOR and AND operations, the \\StateUpdate{} function uses two types of bit rotations:\n\\begin{enumerate}\n\\item \\emph{word-wise} rotations perform a circular shift on each word within a register;\n\\item \\emph{register-wise} rotations perform a circular shift on a whole register.\n\\end{enumerate}\nThe second type of rotation always shifts registers by a multiple of the word size $w$. This amounts to a (circular) permutation of the words within the register: for example, if a register contains the words $(A, B, C, D)$, and a register-wise rotation by $w$ bits to the left is performed, then the register now contains the words $(B, C, D, A)$.\n\nTo build our linear trail, we start with a linear combinations of bits within a single register.\n\\begin{definition}\nRecall that $w$ denotes the word size in bits, and $4w$ is the size of a register. A linear combination of the form:\n\\[\nS^t_{i,j(0)} \\oplus S^t_{i,j(1)} \\oplus \\dots \\oplus S^t_{i,j(k)}\n\\]\nis said to be \\emph{symmetric} iff the set of bits $S^t_{i,j(0)}, \\dots, S^t_{i,j(k)}$ is left invariant by a circular shift by $w$ bits; that is, iff:\n\\[\n\\{j(i) : i\\leq k\\} = \\{j(i) + w \\text{\\rm{} mod } 4w : i\\leq k\\}.\n\\]\n\\end{definition}\n\\emph{Example.} The following linear combination is symmetric for \\MORUS[640], i.e. $w = 32$:\n\\begin{equation}\nS^t_{0,0} \\oplus S^t_{0,32} \\oplus S^t_{0,64} \\oplus S^t_{0,96}.\n\\label{eq:symmetric}\n\\end{equation}\n\nThis definition naturally extends to a linear combination across multiple registers, and also across ciphertext blocks.\nThe value of such a linear combination is unaffected by register-wise rotations, since those rotations always shift registers by a multiple of the word size.\nOn the other hand, since word-wise rotations always shift all four words within a register by the same amount, word-wise rotations preserve the symmetry property. Moreover, the XOR of two symmetric linear combinations is also symmetric.%; and the same holds for the AND operation (if we extend the symmetric property to non-linear combinations in the natural way).\n\nThis naturally leads to the idea of building a linear trail using only symmetric linear combinations, which is what we are going to do. As a result, the effect of register-wise rotations can be ignored. Moreover, since all linear combinations we consider are going to be symmetric, they can be described by truncating the linear combination to the first word of a register. Indeed, an equivalent way of saying a linear combination is symmetric, is that it involves the same bits in each word within a register. For example, in the case of (\\ref{eq:symmetric}) above, the four bits involved are the first bit of each of the four words.\n\n\\subsection{\\MiniMORUS}\n\nIn fact, we can go further and consider a reduced version of \\MORUS where each register contains a single word instead of four. The \\StateUpdate{} function is unchanged, except for the fact that register-wise rotations are removed: see \\Cref{fig:minimorus}. We call these reduced versions \\MiniMORUS[640] and \\MiniMORUS[1280], for \\MORUS[640] and \\MORUS[1280] respectively. Since registers in \\MiniMORUS contain a single word, word-wise and register-wise rotations are the same operation; for simplicity we write $\\lll$ for word-wise rotations.\n\nSince the trail we are building is relatively complex, we will first describe it on \\MiniMORUS. We will then extend it to the full \\MORUS via the previous symmetry.\n\n\\begin{figure}[h]\n  \\substatesfalse\n  % \\substatesfalse to label state words and/or masks\n  \\centering\n  \\tikzsetnextfilename{minimorus_plain}\n  \\begin{tikzpicture}[xscale=1.0,yscale=1.5]%{{{\n    \\printstate\n  \\end{tikzpicture}%}}}\n  \\caption{\\MiniMORUS state update function.}\n  \\label{fig:minimorus}\n\\end{figure}\n", "meta": {"hexsha": "6a3e1fdf1dc87907176c8b50608d38fe3d779264", "size": 4315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "morusAC_03_MiniMorus.tex", "max_stars_repo_name": "ildyria/MiniMorus", "max_stars_repo_head_hexsha": "168b27e059a46714bfe86af0cead20b4f6a51fcb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "morusAC_03_MiniMorus.tex", "max_issues_repo_name": "ildyria/MiniMorus", "max_issues_repo_head_hexsha": "168b27e059a46714bfe86af0cead20b4f6a51fcb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "morusAC_03_MiniMorus.tex", "max_forks_repo_name": "ildyria/MiniMorus", "max_forks_repo_head_hexsha": "168b27e059a46714bfe86af0cead20b4f6a51fcb", "max_forks_repo_licenses": ["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.701754386, "max_line_length": 634, "alphanum_fraction": 0.7631517961, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951104066295, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.662718075811819}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\title{Numerical simulation of PWL models of gene regulatory networks}\n\\author{V. Acary}\n\\begin{document}\n\\maketitle\n\\subsection*{Standard form}\n\n\\begin{equation}\n  \\label{eq:std}\n  \\left\\{\\begin{array}{l}\n      M \\dot x  = f(x,t) +  r(t) \\\\\n      r(t) = g(x,t,\\lambda) \\text{ (input) }  \\\\\n      y(t) = h(x,t,\\lambda) \\text{ (output) } \\\\\n   \\end{array}\\right.\n\\end{equation}\n\nwith one of the following nonsmooth law\n\\begin{enumerate}\n\\item Sign function\n  \\begin{equation}\n    \\label{eq:sign}\n    \\lambda \\in \\mbox{Sign} (-y) \\Longleftrightarrow  - y  \\in N_{[-1,1]}(\\lambda)\n  \\end{equation}\n\\item Step function\n  \\begin{equation}\n    \\label{eq:step}\n    \\lambda \\in \\mbox{Step} (-y) \\Longleftrightarrow  - y  \\in N_{[0,1]}(\\lambda)\n  \\end{equation}\n\\end{enumerate}\n\nWe have \n\\begin{equation}\n  \\label{eq:signstep}\n  \\begin{array}{l}\n  s^+(x,\\theta) = \\mbox{Step}(x-\\theta) = \\frac 1 2 (1+ \\mbox{Sign}(x-\\theta))\\\\ \\\\\n  s^-(x,\\theta) = 1 - \\mbox{Step}(x-\\theta) = \\frac 1 2 (1- \\mbox{Sign}(x-\\theta))\n\\end{array}\n\\end{equation}\n\\subsection*{First 2D example}\n\\begin{equation*}\n\\left\\{\\begin{array}{l} \\dot{x}_{a} = - \\gamma_{a}\\, x_{a}+ \\kappa_{a} \\, s^{+}(x_{b},\\theta_{b}^1)\\, s^{-}(x_{a},\\theta_{a}^2) \\\\\n\\dot{x}_{b} = - \\gamma_{b}\\, x_{b} + \\kappa_{b} \\,  s^{+}(x_{a},\\theta_{a}^1)\\,s^{-}(x_{b},\\theta_{b}^2) \\end{array}\\right. .\n\\end{equation*}\n\n\nThe parameters are: $\\theta_a^1=\\theta_b^1=4, \\theta_a^2=\\theta_b^2=8, k_a=k_b=40, \\gamma_a=4.5$ and $\\gamma_b=1.5$.\n\nThe vector fields $f$ and $h$ can be identified as\n\n\n\\begin{equation}\n  \\label{eq:f1}\n  f(x,t) = \\left[\n    \\begin{array}{l}\n      - \\gamma_a x_a \\\\\n      - \\gamma_b x_b \\\\\n    \\end{array}\n  \\right]=\\left[\n    \\begin{array}{l}\n      - 4.5 x_a \\\\\n      - 1.5 x_b \\\\\n    \\end{array}\n  \\right]\n\\end{equation}\n\n\\begin{equation}\n  \\label{eq:h1}\n  h(x,t,\\lambda) = -  \\left[\n    \\begin{array}{l}\n       x_a - \\theta_a^1 \\\\      \n       x_b - \\theta_b^1 \\\\\n       x_a - \\theta_a^2 \\\\      \n       x_b - \\theta_b^2 \\\\\n    \\end{array}\n  \\right]=\\left[\n    \\begin{array}{l}\n      4- x_a \\\\      \n      4- x_b \\\\\n      8- x_a \\\\      \n      8- x_b \\\\\n    \\end{array}\n  \\right]\n\\end{equation}\n\n\n\\subsubsection*{With the sign function}\n\\begin{equation}\n  \\label{eq:g1sign}\n  \\begin{array}{lcl}\n  g(x,t,\\lambda) &=&\\displaystyle\\frac 1 4  \\left[\n    \\begin{array}{l}\n      \\kappa_a      (1- \\mbox{sign}( x_a - \\theta_a^2))((1+ \\mbox{sign}( x_b - \\theta_b^1)))\\\\\n      \\kappa_b      (1+ \\mbox{sign}( x_a - \\theta_a^1))((1- \\mbox{sign}( x_b - \\theta_b^2)))\n    \\end{array}\n  \\right]\\\\ \\\\\n  &=& 10   \\left[\n    \\begin{array}{l}\n          (1-\\lambda_3)(1+\\lambda_2)\\\\\n          (1+\\lambda_1)(1-\\lambda_4)\n    \\end{array}\n  \\right] \n\\end{array}\n\\end{equation}\n\n\\subsubsection*{With the Step function}\n\\begin{equation}\n  \\label{eq:g1step}\n  \\begin{array}{lcl}\n  g(x,t,\\lambda) &=&  \\left[\n    \\begin{array}{l}\n      \\kappa_a      (1- \\mbox{step}( x_a - \\theta_a^2))( \\mbox{step}( x_b - \\theta_b^1)))\\\\\n      \\kappa_b      (\\mbox{step}( x_a - \\theta_a^1))((1- \\mbox{step}( x_b - \\theta_b^2)))\n    \\end{array}\n  \\right]\\\\ \\\\\n  &=& 40   \\left[\n    \\begin{array}{l}\n          \\lambda_2 (1-\\lambda_3)\\\\\n          \\lambda_1 (1-\\lambda_4)\n    \\end{array}\n  \\right] \n\\end{array}\n\\end{equation}\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "f7ea3b32ba1034dc1e6feedd7813d88c49cf7a76", "size": 3367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/Biology/StepSystem/notes.tex", "max_stars_repo_name": "siconos/siconos-deb", "max_stars_repo_head_hexsha": "2739a23f23d797dbfecec79d409e914e13c45c67", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-01-12T23:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-20T17:03:58.000Z", "max_issues_repo_path": "examples/Biology/StepSystem/notes.tex", "max_issues_repo_name": "siconos/siconos-deb", "max_issues_repo_head_hexsha": "2739a23f23d797dbfecec79d409e914e13c45c67", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-14T13:44:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-17T13:57:27.000Z", "max_forks_repo_path": "examples/Biology/StepSystem/notes.tex", "max_forks_repo_name": "siconos/siconos-deb", "max_forks_repo_head_hexsha": "2739a23f23d797dbfecec79d409e914e13c45c67", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-22T13:30:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-06T10:19:57.000Z", "avg_line_length": 25.7022900763, "max_line_length": 130, "alphanum_fraction": 0.555984556, "num_tokens": 1354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6627180677194671}}
{"text": "\\chapter{Heuristic Strategies}\n\n\\section{Overview}\n\n[motivation]\n\nHeuristic strategies are interesting to study because they tend to uncover some interesting links between an optimal strategy and the immediate step. Good heuristics have an intuitive rationale as why the heuristic is constructed that way.\n\nIn this sense, the objective of a heuristic may not only be to yield an optimal solution quickly. [See e.g. neuwirth].\n\nIt is fair to expect that a tailored-heuristic to one configuration of the rules may not perform well in another configuration. This is the defect of tailored heuristics. (Show some examples)\n\nSee \\cite{pepperdine10} for a list of heuristic functions.\n\n[tie-breaker policy]\n\nAll known heuristic strategies work on the partition of the remaining secrets by a candidate guess. Notations: Let $S$ be the set of remaining possibilities. Let $\\tilde{S}$ be the set of remaining possibilities after the guess, which is a random variable depending on the guess and the secret. Let $n = \\#\\{S\\}$ be the number of remaining possibilities, and let $\\tilde{n} = \\#\\{\\tilde{S}\\}$ be the number of remaining possibilities after a guess. Let a guess partition the remaining possibilities into $r$ cells $V_1, \\ldots, V_r$, where the number of secrets in cell $i$ is $n_i = \\#\\{V_i\\}$. Let $x$ be the unknown secret.\n\n\n\n\\section{The Min-Max heuristic}\n\nKnuth \\cite{knuth76} published the first systematic paper on Mastermind, where he introduced a heuristic strategy aiming at minimizing the worst-case number of remaining possibilities.\n\nThe same heuristic function first appeared in \\cite{aleph71} for the Bulls and cows game, but was not elaborated.\n\nRationale: fewer remaining possibilities is better. We want to play safe and reduce the worst-case number of remaining possibilities. \n\nNote that this strategy does not need an assumption on the distribution of the secret. [see neu] (This, e.g. is suitable in mastermind with lie (or dynamic mastermind.))\n\nNote: If two guesses yield the same worst-case partition, the second-to-worst partition size is compared, etc.\n\n\\section{The Min-Average heuristic}\n\nRationale: fewer remaining possibilities is better. We want to minimize the expected partition size (number of remaining possibilities).\n\nThe objective function to minimize is\n\\[\nE[\\tilde{n}] = \\sum_{i=1}^r P(x \\in V_i) \\# \\{ V_i \\}\n\\]\nNow we assume each remaining possibility is equally likely to be the secret. Then the above is transformed to\n\\[\nE[\\tilde{n}] = \\sum_{i=1}^r \\frac{n_i}{n} n_i = \\frac{1}{n}  \\sum_{i=1}^r n_i^2 .\n\\]\nMinimizing this expectation is equivalent to minimizing the heuristic function\n\\[\nh(P) = \\sum_{i=1}^r n_i^2 .\n\\]\n\n\n[Gini Index]\n\nA correction for perfect match is useful. If the guess is among the remaining possibilities, then one of the responses is the perfect match, which accounts for a partition of size 1. However, we don't need to make any further guesses in this case. So this partition should be excluded when calculating the expected \\emph{remaining} count. This can be corrected by applying the following correction term:\n\\[\n-1 .\n\\]\n\n\\section{The Max-Entropy heuristic}\n\nRationale: we want a guess to provide as much information as possible as to determine what is the secret.\n\nThe entropy heuristic was first introduced by Neuwirth \\cite{neuwirth81} for Mastermind and by Larmouth \\cite{aleph71} for Bulls and cows. It is a theoretically advanced heuristic that scores a guess by the ``amount of information'' brought by its partitioning of the potential secret set. To be precise, this heuristic aims to maximize the \\emph{entropy} of the partition, defined as\n\\[\nH = -\\sum_i \\frac{n_i}{n} \\log \\frac{n_i}{n} .\n\\]\nThe base of the logarithm is not specified but it does not impact the choice. \n\nRearranging terms, it can be written as\n\\begin{align}\nH \n&= - \\frac{1}{n} \\left[ \\sum_i n_i (\\log n_i - \\log n ) \\right] \\notag \\\\\n&= - \\frac{1}{n} \\left( \\sum_i n_i \\log n_i \\right) + \\log n . \\notag\n\\end{align}\nWhen $n$ is fixed, maximizing $H$ is equivalent to minimizing the heuristic function\n\\[\nh(P) = \\sum_i n_i \\log n_i .\n\\]\nIf we loosely interpret $\\log n_i$ as an estimate of the number of further guesses needed for a partition of size $n_i$, then we can interpret the heuristic function (when divided by $n$) as an estimate of the expected number of further guesses needed. \n\n[Note: floating point precision?]\n\nHeeffer \\cite{heeffer07} tested various heuristic algorithms on the Mastermind game with 5 pegs and 8 colors, and found the entropy heuristic to perform the best.\n\nSee \\href{http://en.wikipedia.org/wiki/Entropy\\_(information\\_theory)\\#Further\\_properties}{Wikipedia}.\n\nEach feedback from a guess can be thought of as a \"alphabet\"\nFor p4c10n, there are 14 alphabets, but some letters are more likely to follow certain letters than others. However, such likelyhood depends on the guess chosen.\n\nFor example, if a guess partitions the possibility set into discrete partition, then all letters in that alphabet \n\nIf alphabet is equally likely, then the entropy is maximized.\n\n\n***************\n\nWhy entropy heuristic doesn't yield best (worst step) and (average step)?\n\nThe apparent underperformance of the entropy heuristic could be explained by noting the fact that there is a distinction between \\emph{determining} the secret and \\emph{revealing} the secret. Suppose we are left with 2 possibilities: 5678 and 7890. We can \\emph{determine} the secret with one guess (e.g. 5678). However, to actually \\emph{reveal} the secret, we need to make an extra guess (7890) if 5689 returns \\fb{0}{2}. In total we need maximum 2 guesses and average 1.5 guesses.\n\nHowever, from a information theory's perspective, the extra guess is totally redundant in that there is no uncertainty of the outcome: we know for sure that we will get \\fb{4}{0} when we guess \\cw{7890}. In fact, when we guess 5678, the entropy of the resulting partition \\{(5678:4A0B),(7890:0A2B)\\} is zero (ignoring the constant denominator), which means uncertainty removed.\n\nThe extra step to reveal the secret is necessary in the traditional human game because otherwise it's difficult to judge that the code breaker wins. On the other hand, the human game rules could be slightly modified to remove the need for the extra guess. Instead of required to \\emph{reveal} the guess with a 4A0B feedback, the codebreaker is required to \\emph{assert} the guess after a number of rounds. If the assertion is correct, he wins; if the assertion is wrong, he loses. The number of guesses one needs before making an assertion is equal to the number of steps one needs to determine the secret, and this number is consistent with an information-theory perspective.\n\nTo cope with subtle discrepancy of determining and revealing the secret, the entropy heuristic could be amended to distinguish the difference, though in this case the theory is not that sound. See [taiwan wang you] For example, Larmouth \\cite{aleph71} used the following entropy heuristic \\emph{with correction}:\n\\[\nh'(P) = \\sum_i n_i \\log n_i - (2 \\log 2) \\delta(\\fb{4}{0})  .\n\\]\nThe correction term applies when the partition contains \\fb{4}{0}. However, how the coefficient $(2 \\log 2)$ is derived is unclear.\n\nAnother issue with the entropy heuristic is that when computing the entropy, it only depends on the probablity of each partition (i.e. the size of each partition). This is because in entropy theory, it assumes that we know absolutely nothing about the underlying random variable (the secret), except which partition it resides in. Under this assumption, two partitions with the same size gives the same amount of information; for example, if partition A and partiton B both contain 3 possibilities, then if either case turns out to contain the secret, then we are equipped with the knowledge that we have 3 possibilities left, without any more knowledge.\n\nHowever, in the scenario of Mastermind, the situation is different, because we have extra knowledge about the codewords apart from the size. Consider two partitions of the same size:\n\nA = (1234, 1235, 1236), and\n\nB = (1234, 1235, 2135)\n\nThough both partitions contain the same number of elements, their information content is different; partition A has more uncertainty (in Mastermind sense) than partition B. This is because it requires at least 2 steps to determine the secret in A (this can be verified by an exhaustive search). However, partition B can be determined with one guess (for example, any one of the three secrets). Thus, with the extra knowledge not present in a vanilla entropy theory, partition A has more uncertainty.\n\nThus the assumptions of applying the entropy theory do not exactly hold. Consequenty, the strategy produced by entropy theory may not be as good as it apparently suggests. This may also mean that the logarithm base in computing the entropy may need to be adapted to the actual structure of the partition. However, if we continue this step recursively, then it is essentially an exhaustive strategy, in which case we don't need the heuristic any more.\n\n\n\n\\section{The Max-Parts Heuristic}\n\nRationale is problematic. Subject to choice of equal heuristic element. (We can perform a randomized test to permute the codeword list.)\n\nThe \\maxpar{} heuristic was introduced by Kooi \\cite{kooi05} who applied it to the Mastermind game and outperformed all other heuristic strategies. It proved to work well for a Mastermind game with 4 pegs and 6 colors, but didn't work well for one with 5 pegs and 8 colors.\n\nThe formula is\n\\[\nh(P) = r ,\n\\]\nwhere $r$ is the number of n(on-empty) partitions.\n\n%\\subsection{The Min-Steps Heuristic}\n\nFor Bulls and cows, the \\maxpar{} strategy might have been tested in as early as 1969 by Ken Thompson \\cite{ritchie01}. However, it is apparent that this strategy doesn't perform as well as the other heuristic strategies. See appendix [???] for an table.\n\n\\section{Other heuristics}\n\n%http://mercury.webster.edu/aleshunas/Support\\%20Materials/Analysis/Dowelll\\%20-\\%20Mastermind%20v2-0.doc\n\n%Defeating Mastermind\n%By Justin Dowell\n\n%- WideDev\n%- LongRect both hybrid strats\n\nThese are not good. Because we need a \"rationale\" for the heuristic. \n\nA few more heuristics have been tested by various authors. They are listed below for completeness. However, the rationale for each of the heuristics is not clear, so their performance may be expected to vary widely with the configuration of the rules.\n\n[Move this to appendix]\n\nFor a large class of heuristics, the heuristic function is computed as the expectation of some function, $f$ of the partition size, optionally minus a correction term, $\\lambda$ if the guess is in the possibilities. That is,\n\\[\nh(P) = \\frac{1}{n} \\left[\\sum_i n_i f(n_i) - \\tau(\\lambda) \\right].\n\\]\n\nThe following list of functions appear in \\cite{pepperdine10}:\n\\begin{center}\n\\begin{tabular}{c l l}\n\\hline\nName & $f$ & $\\lambda$ \\\\\n\\hline\nModified entropy & $\\log (1+n_i)$ & 0 \\\\\nLandy's function & $L(n_i)$ where $L(n)$ is the solution of $x^x = n$ & 0 \\\\\nExponential asymptote & $1-e^{-n_i}$ & $(1-e^{-1})$ \\\\\nsquare root & $\\sqrt{n_i}$ & 1 \\\\\nLogarithmic integral & $\\text{li}(1+n_i)$ & $2 \\cdot \\text{li}(3)$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nMore examples can be found in his document.\n\nIn addition, some hybrid strategies are used.\n\n\\section{Comparison of heuristics}\n\nWhen several candidate guesses yield the same heuristic value, a choice must be made as to pick which one as the guess. Standard way is to choose the ``first'' candidate as it appears in the list, or the lexicographically minima. However, some evidence (where??) shows that the performance of a heuristic does depend on which choice is made. This is not ideal.\n\n\\section{Building a strategy tree}\n\n\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": "93bc37b719e96340c69f4785f563c0e686f3f072", "size": 11824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/heuristic.tex", "max_stars_repo_name": "bijaykoirala/mastermind-strategy", "max_stars_repo_head_hexsha": "22763672c413c6a73e2c036a9f522b65a0025b68", "max_stars_repo_licenses": ["MIT"], "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/heuristic.tex", "max_issues_repo_name": "bijaykoirala/mastermind-strategy", "max_issues_repo_head_hexsha": "22763672c413c6a73e2c036a9f522b65a0025b68", "max_issues_repo_licenses": ["MIT"], "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/heuristic.tex", "max_forks_repo_name": "bijaykoirala/mastermind-strategy", "max_forks_repo_head_hexsha": "22763672c413c6a73e2c036a9f522b65a0025b68", "max_forks_repo_licenses": ["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.5741626794, "max_line_length": 676, "alphanum_fraction": 0.7583728011, "num_tokens": 2896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.6627180538415393}}
{"text": "\\documentclass[twoside]{article}\n\n\\usepackage{mystyle}\n\\usepackage{tikz}\n\n\\newcommand{\\I}{\\mathcal{I}}\n\n\\title{Introduction to Matroids}\n\\author{Travis Westura}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\\thispagestyle{empty}\n\n\\section{Introduction}\n\nIn this course we've seen several examples of algorithms that are ``greedy.''\nA greedy algorithm is an algorithm that makes a ``locally best'' decision.\nFor example, in Dijkstra's algorithm we use a priority queue to keep track of nodes on the friontier and pop them off using the priority of shortest path distance.\nAnd in Kruskal's algorithm for finding minimum weight spanning trees, at each step we select the minimum weight edge that does not form a cycle.\n\nWe can generalize the idea of ``locally make a best decision'' by using matroids.\nThe word \\emph{matroid} should make you think of the word \\emph{matrix}, which you use in linear algebra and multivariable or vector calculus.\nWe'll begin by reviewing the concepts of linear independence, then we'll discuss analogous concepts in graph theory.\nThen we will relate these concepts by generalizing them and giving the definition of a matroid.\nAnd finally we will use matroids to give a proof of the correctness of Kruskal's algorithm.\n\n\\section{Independence in Linear Algebra}\n\nAs you take Linear Algebra and Multivariable Calculus you will gain lots of experience working with vectors and matrices.\nIn these notes we'll denote vectors using boldface letters at the end of the alphabet, such as $\\bv{u}$ and $\\bv{v}$, and matrices using capital letters at the beginning of the alphabet, such as $A$ and $B$.\nWe'll denote by $\\bv{0}$ the vector of all $0$'s, and we'll also write vectors as columns and matrices as rectangles containing numbers:\n\\begin{equation*}\n  \\bv{u} = \\mat{3\\\\-1\\\\3}, \\quad \\bv{v} = \\mat{v_1\\\\v_2\\\\v_3}, \\quad \\bv{0} = \\mat{0\\\\0\\\\0}, \\quad A = \\mat{1 & 2 & 5\\\\-2 & 3 & 0}, \\quad B = \\mat{b_{1,1} & b_{1, 2} & b_{1, 3}\\\\b_{2, 1} & b_{2, 2} & b_{2, 3}}.\n\\end{equation*}\nWe say that vectors are elements of a set called a Vector Space, and we also have the ability to add vectors and to multiply them by scalars.\nIn multivariable calculus the most common example of vector spaces are $\\R^2$ and $\\R^3$, where vectors consist of tuples of $2$ and $3$ numbers, respectively.\nWe can add vectors and multiply them by scalars as follows:\n\\begin{equation*}\n  \\mat{u_1\\\\u_2} + \\mat{v_2\\\\v_2} = \\mat{u_1 + v_1\\\\v_2 + v_2}, \\quad a\\mat{u_1\\\\u_2} = \\mat{a u_1\\\\ a u_2}.\n\\end{equation*}\nA linear combination of vectors is a sum of scalar multiples of vectors.\nFor example\n\\begin{equation*}\n  2\\mat{2\\\\-1} + 3\\mat{-3\\\\4} = \\mat{-5\\\\10}.\n\\end{equation*}\nWe could say that the $3$rd vector depends on the first two vectors, since it is a linear combination of them.\n\nA set of vectors\\footnote{\n  We can also treat the columns of matrices as vectors and define a notion of linear independence on them, although we should be careful that a column may be repeated, whereas a vector in a set is not repeated.\n}\n$\\{\\bv{v}_1, \\bv{v}_2, \\ldots, \\bv{v}_n\\}$ is \\emph{linearly independent} if the only scalars ${a_1, a_2, \\ldots, a_n}$ that satisfy\n\\begin{equation*}\n  a_1\\bv{v}_1 + a_2\\bv{v}_2 + \\cdots + a_n\\bv{v}_n = \\bv{0}\n\\end{equation*}\nare ${a_1 = a_2 = \\cdots = a_n = 0}$.This means there is no way to write one of the vectors as a combination of the others, unless we make all the coefficients~$0$.\nThat is, none of the vectors in the set depend on the others.\nFor example, the standard basis vectors in $\\R^3$ are linearly independent,\n\\begin{equation*}\n  \\left\\{\\mat{1\\\\0\\\\0}, \\mat{0\\\\1\\\\0}, \\mat{0\\\\0\\\\1}\\right\\},\n\\end{equation*}\nas none of them can be written as a linear combination of the others.\nThe following set of vectors is linearly dependent:\n\\begin{equation*}\n  \\left\\{\\mat{1\\\\2}, \\mat{3\\\\2}, \\mat{5\\\\6}\\right\\}, \\quad 2\\mat{1\\\\2} + \\mat{3\\\\2} = \\mat{2 + 3\\\\4 + 2} = \\mat{5\\\\6}.\n\\end{equation*}\n\nThere is a limit to the number of vectors that we can add to a set while maintaining independence.\nFor example, in~$\\R^3$, and set of $4$~vectors is linearly dependent.\nAn independent set to which we can't add any more vectors is called a \\emph{maximal} independent set, with the word maximal meaning we have included as many vectors as possible.\\footnote{\n  A maximal linearly independent set of vectors is called a \\emph{basis}.\n}\n\nFurther, if we have an independent set of vectors, we can remove vectors and still have an independent set.\nFor example, the subset of standard basis vectors,\n\\begin{equation*}\n  \\left\\{\\mat{1\\\\0\\\\0}, \\mat{0\\\\1\\\\0}\\right\\},\n\\end{equation*}\nis still independent in~$\\R^3$.\n\n\\section{Independence in Graphs}\n\nNow let's discuss independence in graphs.\nRecall that a graph~${G = (V, E)}$ consists of a set~$V$ of vertices and a set~$E$ of edges.\nWe will consider only undirected graphs for now.\n\nRecall that a \\emph{tree} is a connected graph that does not have any cycles.\nA \\emph{forest} is a graph in which each connected component is a tree.\nThat is, a forest is essentially a collection of trees grouped together.\nA \\emph{spanning tree} of an undirected\\footnote{ There is also a notion of spanning tree in an undirected graph, called an \\emph{arborescence}.} graph~$G$ is a subgraph that is a tree and that includes all of the vertices of~$G$.\nThe ``span'' part of a spanning tree refers to the tree containing all of the vertices.\nIn the following diagram, from left to right we have: a tree that does not span the graph, a cycle, two spanning trees, and a forest consisting of two trees.\n\\begin{center}\n  \\begin{tikzpicture}[every node/.style={circle,thick,draw}]\n    \\node (A) at (0, 0) {A};\n    \\node (B) at (1.5, 0) {B};\n    \\node (C) at (0, -1.5) {C};\n    \\node (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] (B);\n    \\path[-] (A) edge[draw=black,very thick] (C);\n    \\path[-] (B) edge[draw=gray,thin] (D);\n    \\path[-] (C) edge[draw=black,very thick] (D);\n    \\path[-] (A) edge[draw=gray,thin] (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}[every node/.style={circle,thick,draw}]\n    \\node (A) at (0, 0) {A};\n    \\node (B) at (1.5, 0) {B};\n    \\node (C) at (0, -1.5) {C};\n    \\node (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] (B);\n    \\path[-] (A) edge[draw=black,very thick] (C);\n    \\path[-] (B) edge[draw=gray,thin] (D);\n    \\path[-] (C) edge[draw=black,very thick] (D);\n    \\path[-] (A) edge[draw=black,very thick] (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}[every node/.style={circle,thick,draw}]\n    \\node (A) at (0, 0) {A};\n    \\node (B) at (1.5, 0) {B};\n    \\node (C) at (0, -1.5) {C};\n    \\node (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] (B);\n    \\path[-] (A) edge[draw=black,very thick] (C);\n    \\path[-] (B) edge[draw=black,very thick] (D);\n    \\path[-] (C) edge[draw=black,very thick] (D);\n    \\path[-] (A) edge[draw=gray,thin] (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}[every node/.style={circle,thick,draw}]\n    \\node (A) at (0, 0) {A};\n    \\node (B) at (1.5, 0) {B};\n    \\node (C) at (0, -1.5) {C};\n    \\node (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] (B);\n    \\path[-] (A) edge[draw=black,very thick] (C);\n    \\path[-] (B) edge[draw=black,very thick] (D);\n    \\path[-] (C) edge[draw=gray,thin] (D);\n    \\path[-] (A) edge[draw=black,very thick] (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}[every node/.style={circle,thick,draw}]\n    \\node (A) at (0, 0) {A};\n    \\node (B) at (1.5, 0) {B};\n    \\node (C) at (0, -1.5) {C};\n    \\node (D) at (1.5, -1.5) {D};\n    \\node (E) at (3, 0) {E};\n    \\node (F) at (3, -1.5) {F};\n\n    \\path[-] (A) edge[draw=gray,thin] (B);\n    \\path[-] (A) edge[draw=black,very thick] (C);\n    \\path[-] (B) edge[draw=gray,thin] (D);\n    \\path[-] (C) edge[draw=gray,thin] (D);\n    \\path[-] (A) edge[draw=black,very thick] (D);\n    \\path[-] (B) edge[draw=black,very thick] (E);\n    \\path[-] (E) edge[draw=black,very thick] (F);\n    \\path[-] (D) edge[draw=gray,thin] (F);\n  \\end{tikzpicture}\n\\end{center}\nThe independent sets of a graph are the forests, that is, the subgraphs that do not include cycles.\nThe dependent sets are the subgraphs that include cycles.\nTo see the analogy to linear algebra, here note that if we have a forest that is not a spanning tree, then there is still an edge we can add to it to obtain a larger subggraph without creating a cycle.\nA spanning tree gives us a notion of maximal independent set, meaning that we have included as many edges as we possibly can.\n\nAnd given a forest, removing edges does not create a cycle.\nThus we have the same property that removing elements from an independent set preserves independence.\n\n\\section{Definition of Matroids}\n\nNow that we have some intuition about the concept of ``independence,'' let's give a definition of matroids.\\footnote{\n  We could define matroids in many ways.\n  Matroids are referred to as \\emph{cryptomorphic}, which means they have many equivalent but ostensibly unrelated definitions.}\nMany mathematical definitions involve placing a set inside of parentheses with other sets or functions that further describe that set.\nFor example, a graph is given by two sets ${G = (V, E)}$.\nA vector space is given by ${(V, k, +, \\cdot)}$, where $V$ is a set of vectors, $k$ is a field of scalars, $+$ is an addition of vectors, and $\\cdot$ is a multiplication between a scalar and a vector.\nA familiar example is ${(\\R^3, \\R, +, \\cdot)}$.\nIf you have taken CS~$2800$ or other more advanced courses, you will have seen groups, where are often described by writing ${(G, +)}$, where $G$ is a set and $+$ is a binary operation on that set.\nMatroids have a similar definition, where we have a set that we write in parentheses together with some other information describing that set.\nIn this definition the additional information is a collection of subsets.\n\n\\begin{defn}[Matroid]\n  A \\emph{matroid}~$M$ is a pair~$(E, \\I)$ consisting of a finite set~$E$ and a collection~$\\I$ of subsets of~$E$, called the \\emph{independent sets}, satisfying the following properties:\n  \\begin{enumerate}\n    \\item The collection is nonempty.\n      That is, ${\\I \\ne \\varnothing}$.\n    \\item All subsets of an independent set are independent.\n      That is, if ${A \\in \\I}$ and ${B \\subseteq A}$, then ${B \\in \\I}$.\n    \\item If $A$ and $B$ are independent sets and $A$ is larger than $B$, then we can take an element that is in $A$ but not in $B$ and add it to $B$ to construct an independent set.\n    That is, if ${A, B \\in \\I}$ with ${|A| > |B|}$, then there exists ${x \\in A \\setminus B}$ such that ${B \\cup \\{x\\} \\in \\I}$.\n    This property is knows as the \\emph{independent set exchange property}---we can ``exchange'' an element from one set to another.\n  \\end{enumerate}\n  A subset of~$E$ that is not independent is called \\emph{dependent}.\n\\end{defn}\n\nLet's see how this definition fits in with our first two examples.\nRecalling that a vector space has a set of vectors~$V$, we form a matroid~$(V, \\I)$, where $\\I$ is the collection of independent sets of vectors of~$V$.\nRecall what we noted previously: given a set of independent vectors, removing vectors still results in an independent set.\nAnd if there are two independent sets of vectors ${A = \\{\\bv{a}_1, \\ldots, \\bv{a}_n\\}}$ and ${B = \\{\\bv{b}_1, \\ldots, \\bv{b}_m\\}}$ with ${m < n}$, then clearly $B$ is not a maximal independent set, so we can add more vectors to it while maintaining independence.\\footnote{\n  Being formal about explicitly satisfying the thrid property requires slightly more linear algebra than I want to use right now, so I'll leave this verification as an exercise for those interested.\n}\n\nNext, given an undirected graph ${G = (V, E)}$, we form a matroid~$(E, \\I)$ with the ground set given by the graph's edges and the independent sets given by the graph's forests.\nLet's verify each part of the definition.\n\\begin{enumerate}\n  \\item The empty collection of edges forms a forest vacuously.\n  \\item If a graph does not form a cycle, then removing edges cannot yield a cycle.\n  \\item Consider two forests $A$ and $B$ where $A$ has more edges than $B$.\n    Then there is some edge ${e \\in A}$ such that ${B \\cup \\{e\\}}$ does not have a cycle.\n    The number of connected components in a graph ${(V, F)}$ is given by ${|V| - |F|}$.\n    Note that individual vertices form their own component.\n    If $A$ and $B$ are two forests with ${|A| > |B|}$, then there are more connected components in ${(V, B)}$ than in ${(V, A)}$.\n    There there is some edge~$e$ in~$A$ that connects two of the components in~$B$.\n    Thus ${B \\cup \\{e\\}}$ forms a forest with one more edge than~$B$.\n\\end{enumerate}\n\n\\section{Kruskal's Algorithm and Matroid Optimization}\n\nGiven a weighted undirected graph, we construct a spanning tree by beginning by starting with the empty set and repeatedly adding the minimum weight edge that does not form a cycle.\nThat is, at each step, add the minimum weight edge that still produces an independent set.\nThe algorithm terminates when we have a spanning tree, or in the language of matroids, when we have a maximal independent set.\n\nIn the following example we start with the empty set of edges.\nThe minimum weight edge is between~$A$ and~$C$, the we first choose that edge.\nNext we select the edge between~$A$ and~$D$.\nWe then can't select the edge between~$C$ and~$D$, as that edge would form a cycle.\nThus we select the edge between~$B$ and~$D$.\nAt this point there are no other edges we can add without creating a cycle, so we have a spanning tree and terminate out algorithm here.\n\\begin{center}\n  \\begin{tikzpicture}\n    \\node[shape=circle,draw=black,thick] (A) at (0, 0) {A};\n    \\node[shape=circle,draw=black,thick] (B) at (1.5, 0) {B};\n    \\node[shape=circle,draw=black,thick] (C) at (0, -1.5) {C};\n    \\node[shape=circle,draw=black,thick] (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] node[above] {5} (B);\n    \\path[-] (A) edge[draw=gray,thin] node[left] {1} (C);\n    \\path[-] (B) edge[draw=gray,thin] node[right] {4} (D);\n    \\path[-] (C) edge[draw=gray,thin] node[below] {3} (D);\n    \\path[-] (A) edge[draw=gray,thin] node[above right] {2} (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}\n    \\node[shape=circle,draw=black,thick] (A) at (0, 0) {A};\n    \\node[shape=circle,draw=black,thick] (B) at (1.5, 0) {B};\n    \\node[shape=circle,draw=black,thick] (C) at (0, -1.5) {C};\n    \\node[shape=circle,draw=black,thick] (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] node[above] {5} (B);\n    \\path[-] (A) edge[draw=black,very thick] node[left] {1} (C);\n    \\path[-] (B) edge[draw=gray,thin] node[right] {4} (D);\n    \\path[-] (C) edge[draw=gray,thin] node[below] {3} (D);\n    \\path[-] (A) edge[draw=gray,thin] node[above right] {2} (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}\n    \\node[shape=circle,draw=black,thick] (A) at (0, 0) {A};\n    \\node[shape=circle,draw=black,thick] (B) at (1.5, 0) {B};\n    \\node[shape=circle,draw=black,thick] (C) at (0, -1.5) {C};\n    \\node[shape=circle,draw=black,thick] (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] node[above] {5} (B);\n    \\path[-] (A) edge[draw=black,very thick] node[left] {1} (C);\n    \\path[-] (B) edge[draw=gray,thin] node[right] {4} (D);\n    \\path[-] (C) edge[draw=gray,thin] node[below] {3} (D);\n    \\path[-] (A) edge[draw=black,very thick] node[above right] {2} (D);\n  \\end{tikzpicture}\n  \\quad\n  \\begin{tikzpicture}\n    \\node[shape=circle,draw=black,thick] (A) at (0, 0) {A};\n    \\node[shape=circle,draw=black,thick] (B) at (1.5, 0) {B};\n    \\node[shape=circle,draw=black,thick] (C) at (0, -1.5) {C};\n    \\node[shape=circle,draw=black,thick] (D) at (1.5, -1.5) {D};\n\n    \\path[-] (A) edge[draw=gray,thin] node[above] {5} (B);\n    \\path[-] (A) edge[draw=black,very thick] node[left] {1} (C);\n    \\path[-] (B) edge[draw=black,very thick] node[right] {4} (D);\n    \\path[-] (C) edge[draw=gray,thin] node[below] {3} (D);\n    \\path[-] (A) edge[draw=black,very thick] node[above right] {2} (D);\n  \\end{tikzpicture}\n\\end{center}\n\nWe are interested in proving the correctness of this abstract algorithm.\nFor now we don't consider the implementation details.\\footnote{\n  For the details of an efficient implementation, look up the Union-Find data structure.\n}\nKruskal's spanning tree algorithm is actually a case of the more general greedy algorithm that is used for weighted matroids.\nA \\emph{weighted matroid} is a matroid in which every element of the ground set has a nonnegative weight.\nThat is, a weighted matroid~${(E, \\I)}$ has a weight~${w_e \\ge 0}$ for each edge~${e \\in E}$.\nFinding a minimum weight spanning tree then becomes the problem of finding a minmum weight maximal independent set.\\footnote{\n  To use more terminalogy from linear algebra, a maximal independent set is called a \\emph{base}.\n  All maximal independent sets contain the same number of elements, and this number is called the \\emph{rank} of the matroid.\n}\n\nIn this general case the greedy algorithm works the same way.\nBegin with the empty set.\nRepeated select the minimum weight element of~$E$ that maintains independence.\nTerminate when the only remaining elements of~$E$ would form a dependent set if added.\n\n\\begin{thm}[]\n  Let ${(E, \\I)}$ be a matroid with weights ${w_e \\ge 0}$ for each~${e \\in E}$.\n  Then the greedy algorithm produces a maximal independent set of minimum weight.\n\\end{thm}\n\\begin{proof}\n  Suppose that the greedy algorithm selects elements ${[e_1, e_2, \\ldots , e_r]}$, in that order.\n  These elements form an independent set, and their weights are in ascending order: ${w_{e_1} \\le w_{e_2} \\le \\cdots \\le w_{e_r}}$.\n  To see this set is of minimum weight, suppose there is another maximal independent set consisting of ${[x_1, \\ldots, x_r]}$ of lower weight.\n  Then for some $i$ we must have ${w_{x_i} \\le w_{e_i}}$.\n  Use the least such $i$, which we note must be greater than~$1$, since the greedy algorithm picks the min cost edge at the first step.\n  Now consider ${B = \\{e_1, \\ldots, e_{i-1}\\}}$ and ${A = \\{x_1, \\ldots, x_i\\}}$.\n  Since ${|A| > |B|}$ and both sets are independent, we use the exchange property.\n  There is some $j$ such that ${x_j \\in A \\setminus B}$ and ${B \\cup \\{x_j\\}}$ is independent.\n  But since ${w_{x_j} \\le w_{x_i} < w_{e_i}}}$, we have a contradiction, as the greedy algorithm would have picked $x_j$ before $e_i$.\n\\end{proof}\n\nThere is also a converse to the previous result: if an independence system ${(E, \\I)}$ is not a matroid, then the greedy algorithm fails for some choice of integer weights.\nYou'll learn more about Greedy Algorithms if you take the undergraduate algorithms course CS~$4820$, and you'll learn more about matroids if you take the graduate algorithms course CS~$6820$ or the combinatorics course sequence~Math~$4410$ and~$4420$.\n\n\\end{document}\n", "meta": {"hexsha": "dec7b658b773aebb3b40e7340cff0d5ad07fd5bf", "size": 18809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matroid-introduction.tex", "max_stars_repo_name": "twestura/MatroidIntroduction", "max_stars_repo_head_hexsha": "7d93a5ab90be4df0d5e5e3d819c1e8d1d59b347f", "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": "matroid-introduction.tex", "max_issues_repo_name": "twestura/MatroidIntroduction", "max_issues_repo_head_hexsha": "7d93a5ab90be4df0d5e5e3d819c1e8d1d59b347f", "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": "matroid-introduction.tex", "max_forks_repo_name": "twestura/MatroidIntroduction", "max_forks_repo_head_hexsha": "7d93a5ab90be4df0d5e5e3d819c1e8d1d59b347f", "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.0524691358, "max_line_length": 272, "alphanum_fraction": 0.6818544314, "num_tokens": 6066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6626758506826335}}
{"text": "\n\\subsection{Asymmetric encryption}\n\nHere we use different keys to encrypt and decrypt the file.\n\nConsider two users who wish to send a message securely.\n\nOne option would be to use symmetric encrpytion. They would have to meet and share this key securely, however, as transferring it over an insecure network would mean it could be copied.\n\nWith public key encryption each user has a public and a private key. The private key is kept secure locally, while the public key can be broadcasted.\n\nIn order to encrypt the file, the recipient's public key is used, while both the private and public key are needed to decrypt the file.\n\nAs a result anyone can encrypt a file to send to the user, but only the user can read what is sent.\n\nPublic-key encryption can be used to facilitate symmetric encryption. If only one party has a public key then the other user can send a symmetric key securely using the public key.\n\nUsing this, asymmetric encrpyiton is only used at the start.\n\nThis is how HTTPS operates, where the website has a public key, but the client does not.\n\nEach user still needs to trust that the public key is accurate. This could be done by hosting the public key on a secure location.\n\nRSA is an algorithm used for public-key encrpytion, including for HTTPS handshakes and PGP.\n\n", "meta": {"hexsha": "4ee75629a4e26a808bcdb7840d377eb048843111", "size": 1290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/encryptionAsymmetric/01-07-asymmetric.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/encryptionAsymmetric/01-07-asymmetric.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/encryptionAsymmetric/01-07-asymmetric.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.6153846154, "max_line_length": 185, "alphanum_fraction": 0.7906976744, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6626758415600705}}
{"text": "\n\n\\begin{lem}\n% \\emph{\t\nIf $A$ and $B$ are the adjacency matrices of simple graphs that are isomorphic to one another, then the minimum of rQAP is equal to the minimum of QAP.\n\\end{lem}\n\n\\begin{proof}\nBecause any feasible solution to GM is also a feasible solution to rQAP, we must only show that the optimal objective function value to rQAP can be no better than the optimal objective function value of QAP.  Let $A=PBP\\T$, so that $\\langle A, PBP\\T\\rangle=2m$, where $m$ is the number of edges in $A$.  If rQAP could achieve a lower objective value, then it must be that there exists a $D \\in \\mc{D}$ such that $\\langle A, DBD\\T\\rangle > \\langle A, PBP\\T\\rangle = 2m$ (remember that we are minimizing the negative Euclidean inner product). For that to be the case, it must be that $(DBD\\T)_{uv} \\geq 1$ for some $(u,v)$.  That this is not so may be seen by the submultiplicativity of the norm induced by the $\\ell_{\\infty}$ norm:\n$\\norm{Dx}_\\infty \\leq \\norm{D}_{\\infty,\\infty} \\norm{x}_\\infty$.  Applying this twice (once for each doubly stochastic matrix multiplication) yields our result.\n% Consider $d_i=\\langle D, \\text{col}_i(BD\\T) \\rangle$, where $\\text{col}_i(\\cdot)$ indicates the $i^{th}$ column of the matrix.  $d_i \\leq 1$ for all $i \\in [n]$, therefore, our result holds.\n\\end{proof}\n\n\n\\paragraph{Linear Assignment Problems} % (fold)\n% \\label{ssub:linear_assignment_problems}\n\n% subsubsection linear_assignment_problems (end)\n\nThe standard way of writing a Linear Assignment Problem (LAP) is\n\\begin{equation*}\n% \\text{(LAP)} \\qquad  \n\\begin{array}{cl}\n\t\t\t\\text{minimize}   & \\sum_{u,v \\in [n]} a_{u \\pi(v)} b_{uv} \\\\\n\t\t\t\\text{subject to}  &P \\in \\mc{P}.   \n\\end{array} %\\label{eq:LAP}\n\\end{equation*}\nThe LAP objective function, like the QAP objective function, enjoys a number of equivalent formulations, including\n% , similar to the QAP objective function (cf Eq. \\eqref{eq:equiv})\n% \\begin{multline} \\label{eq:equiv}\n% (a_{uv}-b_{\\pi(u)\\pi(v)})^2 = \\norm{A - PBP\\T}_F^2 \\\\ = tr \\{ (A - PBP\\T)\\T (A - PBP\\T)\\}.\n% \\end{multline}\n% \n% \n% which can be written equivalently in a number of ways using the notion of permutation matrix introduced in the main text, including\n\\begin{equation}\n\\text{(LAP)} \\qquad  \n\\begin{array}{cl}\n\t\t\t\\text{minimize}   & \\langle P, AB\\T \\rangle \\\\\n\t\t\t\\text{subject to}  &P \\in \\mc{P}.   \n\\end{array}\\label{eq:LAP}\n\\end{equation}\n% \n% \\begin{subequations} \\label{eq:LAP2}\n% \\begin{align}\n% \t&\\argmin_{\\PmcP} \\norm{PA - B}_F =\\\\\n% \t&\\argmin_{\\PmcP} \\, tr(PA-B)\\T (PA-B)=\\\\ \n% \t% &\\argmin_{\\PmcP} tr (A\\T P\\T PA) - tr(2PAB\\T) + tr(B\\T B)=\\\\ \n% \t&\\argmin_{\\PmcP}  -tr (P AB\\T) = \\argmin_{\\PmcP}  -\\langle P\\T, AB\\T \\rangle = \\label{eq:2c} \\\\\n% \t% &\\argmin_{\\PmcP}  -\\sum_{u,v \\in [n]} p_{ij} a_{ij} b_{ji}\n% \t% =\\\\% &\\argmin_{\\PmcP}  - \\text{vec}(P)\\T \\text{vec}(AB\\T).=\\\\\n% \t&\\argmin_{\\PmcP}  -\\langle P, AB\\T \\rangle, \\label{eq:dotLAP}\n% \\end{align}\n% \\end{subequations}\n% where $\\langle \\cdot,\\cdot \\rangle$ %the equality on the second to last line defines is the usual Euclidean inner product, i.e., $\\langle X,Y\\rangle \\defn tr(X\\T Y)= \\sum_{ij} x_{ij} y_{ij}$.\n% While the objective function and the first two constraints of LAP are linear, t\nThe binary constraints of LAP---like those of QAP---make solving even this problem computationally tricky.  Nonetheless, in the last several decades, there has been much progress in accelerating algorithms for solving LAPs, starting with exponential time, all the way down to $\\mc{O}(n^3)$ for general LAPs, and even faster for certain special cases (e.g., sparse matrices) \\cite{Jonker1987, Burkard2009}.\n\n% That Eq.~\\eqref{eq:dir} is a LAP is evident by considering Eq.~\\eqref{eq:dotLAP}.  \nTo see that Eq.~\\eqref{eq:dir} is identical to Eq.~\\eqref{eq:LAP}, \nsimply let $A=\\nabla_P^{(i)}$ and $B=I$ (the $n\\times n$ identity matrix).\n\n\n% The last form indicates that LAP is a linear programming problem (hence the name).  Yet, the constraints, $\\mc{P}$, make it a bit trickier.  The feasible region $\\mc{P}$ can be written as a set of three constraints: two linear equality constraint sets and a binary constraint.  The LAP objection function with constraints can explicitly be written:\n% \\begin{align}\n% \t\t&\\text{minimize}_P  &&\\sum_{u \\in \\mc{V}} -p_{ij} a_{ij} b_{ji} \\nonumber \\\\\n% \t\t&\\text{subject to } && \\sum_{u \\in \\mc{V}} p_{ij} = 1 \\, \\forall u \\in \\mc{V} \\nonumber \\\\\n% \t\t& && \\sum_{v \\in \\mc{V}} p_{ij} = 1 \\, \\forall v \\in \\mc{V}, \\nonumber \\\\\n% \t\t& &&p_{ij} \\in \\{0,1\\} \\, \\forall u,v. \\label{eq:rLAP}\t\n% \\end{align}\n% Perhaps because LAP comes up in a wide variety of contexts, a large number of algorithms have been developed to solve LAP \\cite{Burkard2009}.  These algorithms have become increasing efficient.  \n% One of the most popular algorithms, the so-called ``Hungarian algorithm'' has time complexity $\\mc{O}(n^3)$ \\cite{Jonker1987}.  Under certain conditions (for example, when $AB\\T$ is sparse), faster implementations are also available.  As will be seen below, LAP is a key subroutine to our inexact QAP solution.  \n\nTo solve a LAP, consider a continuous relaxation of LAP, specifically, relaxing the permutation matrix constraint to a doubly stochastic matrix constraint:\n% A matrix $P$ is doubly stochastic precisely when $P$ satisfies the following three conditions: \n% \\begin{enumerate}\n% \\item\t$P\\mb{1} = \\mb{1}$,\n% \\item\t$P\\T \\mb{1}=\\mb{1}$, %\\\\\n% \\item \t$P \\in  \\Real_+^{n \\times n}$,\n% \\end{enumerate}\n% where the third constraint relaxes the binary constraints of the permutation matrices with a non-negativity constraint.  \n% Let $\\mc{D}$ be the set of doubly stochastic matrices.\n% With this, we now state a relaxed LAP problem:\n\\begin{equation}\n\\text{(rLAP)} \\qquad  \n\\begin{array}{cl}\n\t\t\t\\text{minimize}   & \\langle P, AB\\T \\rangle \\\\\n\t\t\t\\text{subject to}  &P \\in \\mc{D}.   \n\\end{array}\\label{eq:LAP}\n\\end{equation}\n% \\begin{subequations} \\label{eq:rLAP}\n% \\begin{align}\n% \t\t\\text{(rLAP) } \\quad &\\underset{P}{\\text{minimize}}  &&-\\langle P, AB\\T \\rangle \\\\\n% \t\t&\\text{subject to } && P \\in \\mc{D}.\n% \t\t% && \\sum_{u \\in \\mc{V}} p_{ij} = 1 \\, \\forall u \\in \\mc{V} \\nonumber \\\\\n% \t\t% \t\t& && \\sum_{v \\in \\mc{V}} p_{ij} = 1 \\, \\forall v \\in \\mc{V}, \\nonumber \\\\\n% \t\t% \t\t& &&p_{ij} \\geq 0 \\, \\forall u,v, \\label{eq:ALAP}\t\n% \\end{align}\n% \\end{subequations}\nAs it turns out, the minima of LAP and rLAP are equal to one anther \\cite{Burkard2009}.\n% solving rLAP is equivalent to solving LAP.\n% \\begin{prop}\n% \tLAP and rLAP are equivalent, meaning that they have the same optimal objective function value.\n% \\end{prop}\n% \\begin{proof}\n% \tAlthough this proposition is typically proven by invoking total unimodularity, we present a  proof here that we find simpler.\tLet $P^L$ be a solution to LAP and let $P^r = \\sum_{i\\in[k]} \\alpha_i P_i$ be a solution to rLAP for some positive integer $k$, permutation matrices $\\{P_i\\}_{i \\in [k]}$, and positive real numbers $\\{\\alpha_i\\}_{i \\in[k]}$ such that $\\sum_{i \\in [k]} \\alpha_i=1$.  Note that it must be the case that\n% \\begin{align}\n% \t\\langle P^L, AB\\T \\rangle \\geq \\langle P^r, AB\\T \\rangle,\n% \\end{align}\n% because $P^L$ is also a solution for rLAP. Expanding $P^r$, we have\n% \\begin{align}\n% \t\\langle P^r, AB\\T \\rangle = \\langle \\sum_i \\alpha_i P_i, AB\\T \\rangle = \\sum_i \\alpha_i \\langle  P_i, AB\\T \\rangle.\n% \\end{align}\n% But we know that \n% \\begin{align}\n% \t\\langle P^L, AB\\T \\rangle \\leq \\langle P, AB\\T \\rangle\n% \\end{align}\n% for any $P \\in \\mc{P}$ because $P^L$ solves LAP, so  \n% \t% \n% \t% \n% \t% \\begin{multline}\n% \t% \\langle P^L,AB\\T \\rangle = \\langle  \\sum_{i\\in[k]} \\alpha_i P_i^L, AB\\T \\rangle=  \\sum_{i\\in[k]} \\alpha_i \\langle  P_i^L, AB\\T \\rangle\t \\\\\n% \t% \\leq \\sum_{i\\in[k]} \\alpha_i \\langle P^r, AB\\T  \\rangle = \\langle P^r, AB\\T \\rangle \\leq \\langle P^L, AB\\T \\rangle,\n% \t% \\end{multline}\n% \t% % then we have a contradiction, \n% \t% because $P^r$ is feasible in rLAP.\n% \t\\end{proof}\nThis relaxation motivates our approach to approximating QAP.\n\n\n\n\\begin{algorithm}\n\t\\caption{\\FAQ~ for finding a local optimum of rQAP} \\label{alg:1}\n\\begin{algorithmic}[1]\n\t\\REQUIRE graphs $A$ and $B$ as well as stopping criteria\n\t\\ENSURE $\\wh{P}$, an estimated permutation matrix\n\t\\STATE Choose an initialization, $P^{(0)}=\\mb{1}\\mb{1}\\T/n$ \\label{step:init} %\\COMMENT{although points in $\\mc{D}$ would also be feasible}\n\t\\WHILE{stopping criteria not met} \n\t\\STATE Compute the gradient of $f$ at the current point via Eq.~\\eqref{eq:grad}\t\n\t\\STATE Compute the direction $Q^{(i)}$ by solving Eq.~\\eqref{eq:dir} via the Hungarian algorithm\n\t\\STATE Compute the step size $\\alpha^{(i)}$ by solving Eq.~\\eqref{eq:step}\n\t\\STATE Update $P^{(i)}$ according to Eq.~\\eqref{eq:update}  %$P^{(i+1)} \\leftarrow P^{(i)} + \\alpha^{(i)} Q^{(i)}$\n\t\\ENDWHILE\n\t\\STATE Obtain $\\wh{P}$ by solving Eq.~\\eqref{eq:proj} via the Hungarian algorithm.\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\begin{table}[h!]\n\\caption{Comparison of \\FAQ~ with optimal objective function value and previous state-of-the-art for directed graphs.  The best (lowest) value is in \\textbf{bold}. Asterisks indicate achievement of the global minimum.  The number of vertices for each problem is the number in its name (second column).}\n\\begin{center}\n\\begin{tabular}{|r|r|r||l|l|l|l|l|}\n\t\\hline \n\t          \\# &  Problem &      Optimal & \\FAQ~ & \\Epath~& \\Grad~ \\\\\n\t\\hline \n\t           1 &  lipa20a &     3683 & \\textbf{3791} &     3885 &     3909 \\\\ \n\t           2 &  lipa20b &    27076 & \\textbf{27076}$^*$ &    32081 &    \\textbf{27076}$^*$ \\\\ \n\t           3 &  lipa30a &    13178 & \\textbf{13571} \t&    13577 &    13668 \\\\ \n\t           4 &  lipa30b &   151426 & \\textbf{151426}$^*$ & \\textbf{151426}$^*$ &   \\textbf{151426}$^*$ \\\\ \n\t           5 &  lipa40a &    31538 & \\textbf{32109} \t&    32247 &    32590 \\\\ \n\t           6 &  lipa40b &   476581 & \\textbf{476581}$^*$ &   \\textbf{476581}$^*$ &   \\textbf{476581}$^*$ \\\\ \n\t           7 &  lipa50a &    62093 & \\textbf{62962} &    63339 &    63730 \\\\ \n\t           8 &  lipa50b &  1210244 & \\textbf{1210244}$^*$ &  \\textbf{1210244}$^*$ &  \\textbf{1210244}$^*$ \\\\ \n\t           9 &  lipa60a &   107218 & \\textbf{108488} &   109168 &   109809 \\\\ \n\t          10 &  lipa60b &  2520135 & \\textbf{2520135}$^*$ &  \\textbf{2520135}$^*$ &  \\textbf{2520135}$^*$ \\\\ \n\t          11 &  lipa70a &   169755 & \\textbf{171820} &   172200 &   173172 \\\\ \n\t          12 &  lipa70b &  4603200 & \\textbf{4603200}$^*$ &  \\textbf{4603200}$^*$ &  \\textbf{4603200}$^*$ \\\\ \n\t          13 &  lipa80a &   253195 & \\textbf{256073} &   256601 &   258218 \\\\ \n\t          14 &  lipa80b &  7763962 & \\textbf{7763962}$^*$ &  \\textbf{7763962}$^*$ &  \\textbf{7763962}$^*$ \\\\ \n\t          15 &  lipa90a &   360630 & \\textbf{363937} &   365233 &   366743 \\\\ \n\t          16 &  lipa90b & 12490441 & \\textbf{12490441}$^*$ & \\textbf{12490441}$^*$ & \\textbf{12490441}$^*$ \\\\ \n\t\\hline\n\t\\end{tabular}\n\\end{center}\n\\label{tab:directed}\n\\end{table}%\n\n\n\n\n\n\\begin{table}[h!]\n\\caption{Comparison of \\FAQ~ with optimal objective function value and the best result  on the undirected benchmarks.  Note that \\FAQ~ restarted 100 times finds the optimal objective function value in 3 of 16 benchmarks, and that \\FAQ~ restarted 3 times finds a minimum better than the previous state-of-the-art on all 16 particularly difficult benchmarks.}\n\\begin{center}\n\\begin{tabular}{|r|r|r||l|l|l|l|l|}\n\\hline\n\\# & Problem  &   Optimal    & \\FAQ$_{100}$ & \\FAQ$_{3}$ & previous min \\\\\n\\hline\n1&    chr12c &   11156 &    \\textbf{12176} &   13072 & 13072 \\\\\n2&    chr15a &    9896 &    \\textbf{9896}$^*$ &   17272 &  19086 \\\\\n3&    chr15c &    9504 &    \\textbf{10960} &   14274 &  16206 \\\\\n4&   chr20b &    2298 &     \\textbf{2786} &    3068 &    3068 \\\\\n5&    chr22b &    6194 &    \\textbf{7218} &    7876 &   8482 \\\\\n6&    esc16b & \t292 & \t\t\\textbf{292}$^*$ & 294 &    296 \\\\\n7& \t   rou12 &  235528 &  \\textbf{235528}$^*$ &  238134 &    253684 \\\\\n8& \t   rou15 &  354210 &  \\textbf{356654} &  371458 &    371458 \\\\\n9&      rou20 &  725522 &  \\textbf{730614} &  743884 &    743884 \\\\\n10&    tai10a &  135028 &  \\textbf{135828} &  148970 &    152534 \\\\\n11&    tai15a &  388214 &  \\textbf{391522} &  397376 &    397376 \\\\\n12&    tai17a &  491812 &  \\textbf{496598} &  511574 &    529134 \\\\\n13&    tai20a &  703482 &  \\textbf{711840} &  721540 &    734276 \\\\\n14&    tai30a & 1818146 & \\textbf{1844636} & 1890738 &  1894640 \\\\\n15&    tai35a & 2422002 & \\textbf{2454292} & 2460940 &  2460940 \\\\\n16&    tai40a & 3139370 & \\textbf{3187738} & 3194826 &  3227612 \\\\\n    \\hline\n\\end{tabular}\n\\end{center}\n\\label{tab:restarts}\n\\end{table}%", "meta": {"hexsha": "a672e20e117961535e11d7ff890f90b51f1af7eb", "size": 12529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Drafts/nips/FAQ-nips-supp.tex", "max_stars_repo_name": "rwolst/FastApproximateQAP", "max_stars_repo_head_hexsha": "08854a8edfe8881003b11fe4433dec8f0c8217ed", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-08-27T14:10:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-08T21:38:55.000Z", "max_issues_repo_path": "Drafts/nips/FAQ-nips-supp.tex", "max_issues_repo_name": "rwolst/FastApproximateQAP", "max_issues_repo_head_hexsha": "08854a8edfe8881003b11fe4433dec8f0c8217ed", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-02-20T01:53:58.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-24T11:14:00.000Z", "max_forks_repo_path": "Drafts/nips/FAQ-nips-supp.tex", "max_forks_repo_name": "rwolst/FastApproximateQAP", "max_forks_repo_head_hexsha": "08854a8edfe8881003b11fe4433dec8f0c8217ed", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2016-08-23T11:44:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-06T01:41:25.000Z", "avg_line_length": 59.6619047619, "max_line_length": 730, "alphanum_fraction": 0.6399553037, "num_tokens": 4600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6626758397355579}}
{"text": "% !TEX root = scombinatorics.tex\n\\documentclass[scombinatorics.tex]{subfiles}\n\\begin{document}\n\\chapter{Vapnik-Chervonenkis theory}\n\\label{sauer}\n\n\n\n\\def\\medrel#1{\\parbox[t]{5ex}{$\\displaystyle\\hfil #1$}}\n\\def\\ceq#1#2#3{\\parbox[t]{20ex}{$\\displaystyle #1$}\\medrel{#2}{$\\displaystyle #3$}}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The Vapnik-Chervonenkis dimension}\\label{VCdim}\n\nIf all subsets of $A\\subseteq\\U$ are definable, that is $\\P A=\\phi(A,b)_{b\\in\\V}$ we say that $A$ is \\emph{shattered\\/} by $\\phi(x\\,;z)$.\n%Paraphrase the the definition,  $A$ is shattered by $\\phi$ if fr every $C\\subseteq A$ there is a $b_C\\in\\V$ such that $C=\\phi(A,b_C)$.\nThe following is called the \\emph{shatter function\\/}\n\n%\\ceq{\\hfill\\emph{$\\pi_\\phi(n)$}}{=}{\\max\\Big\\{|\\phi(A,b)_{b\\in\\V}|\\ \\ :\\ \\ A\\subseteq\\U,\\ |A|=n\\Big\\}.}\n\n\\ceq{\\hfill\\emph{$\\pi_\\phi(n)$}}{=}{\\max\\bigg\\{|\\phi(A,b)_{b\\in\\V}|\\ \\ :\\ \\ A\\in {\\U\\choose n}\\bigg\\}}\n\nSo, $\\pi_\\phi(n)$ gives the maximal number of definable subsets that a set of cardinality $n$ can have.\nTrivially, $\\pi_\\phi(n)\\le2^n$ for all $n$.\nMoreover, if $\\pi_\\phi(n)=2^n$ for some $n$, then $\\pi_\\phi(k)=2^k$ for every $k\\le n$.\n\nThe \\emph{Vapnik-Chervonenkis dimension\\/} of $\\phi(\\U\\,;b)_{b\\in\\V}$, or of $\\phi(x\\,;z)$, abbreviated by \\emph{\\vc-dimension}, is the maximal cardinality of a finite set $A\\subseteq\\U$ that is shattered by $\\phi(x\\,;z)$.\nEquivalently, it is the maximal $k$ such that $\\pi_\\phi(k)=2^k$.\nIf such a maximum does not exist,\nwe say that the \\vc-dimension is infinite or that $\\phi(x\\,;z)$ has \\emph{\\ip\\/} (the independence property).\nOtherwise, we say that $\\phi(x\\,;z)$ has \\emph{\\nip\\/} (not the independence property).\nWe may also say: \\textit{is\\/} \\ip, or \\textit{is\\/} \\nip.\n\nAs $\\U$ and $\\V$ are usually clear from the context, we may say \\vc-dimension of $\\phi(x\\,;z)$ for the \\vc-dimension of $\\phi(\\U\\,;b)_{b\\in\\V}$.\n\n\\begin{example}\n  If $\\phi(x\\,;z)$ is either $\\top$ or $\\bot$, then it shatters only the empty set, therefore it has \\vc-dimension $0$.\\QED\n\\end{example}\n\n\\begin{example}\n  If $\\phi(x\\,;z)$ has ladder dimension $n$ then it has \\vc-dimension at most $n$. Hence stable formulas are \\nip.\\QED\n\\end{example}\n \n\\begin{example}\n  If $\\phi(\\U\\,;b)_{b\\in\\V}$ is a non trivial chain of sets, then its \\vc-dimension is $1$.\\QED\n\\end{example}\n \n\\begin{example} \n  Let $\\U=\\RR$ and $\\V=\\RR^2$.\n  Let $\\phi(x\\,;z_1,z_2)$ be the formula $z_1<x<z_2$.\n  Then its \\vc-dimension $2$.\\QED\n\\end{example}\n \n\\begin{example} \n  Let $\\U=\\V=\\RR^2$.\n  Let $\\phi(x_1,x_2\\,;z_1,z_2)$ be the formula $x_2<z_1\\cdot x_1 + z_2$.\n  Then its  \\vc-dimension $3$ (by Radon's Theorem).\\QED\n\\end{example}\n \n\\begin{example}\\label{ex_vcdim_opt}\n  If $\\phi(\\U\\,;b)_{b\\in\\V}$ is the set of all subsets of $\\U$ of cardinality $\\le k$.\n  Then its \\vc-dimension is $k$ and\n  \n  \\ceq{\\hfill\\pi_\\phi(n)}{=}{\\sum^k_{i=0} \\binom{n}{i}.}\n  \n  Incidentally, we note that this is also the shatter function of the collection of all subsets of $\\U$ of cardinality exactly $k$.\n  In fact we always assume $\\U$ is infinite (or at least very large, in this case, size $\\ge2k$ suffices).\\QED\n\\end{example}\n\nThe \\vc-dimension of $\\phi(x\\,;z)^{\\rm op}$ is called the \\emph{dual \\vc-dimension\\/} or \\emph{\\vc-codimension\\/} of $\\phi(x\\,;z)$.\n\n\\begin{proposition}\\label{prop_bound_VCcodim}\n  If $\\phi(x\\,;z)$ has \\vc-dimension $k$, then its \\vc-codimension is $\\le2^{k+1}-1$.\n\\end{proposition}\n  \n\\begin{proof}\n  Suppose that the \\vc-dimension of $\\phi(x\\,;z)^{\\rm op}$ is $\\ge 2^{k+1}$.\n  We prove that the \\vc-dimension of $\\phi(x\\,;z)$ is at least $k+1$.\n  Let $B=\\big\\{b_I\\,:\\,I\\subseteq [k+1)\\big\\}$ be a set of cardinality $2^{k+1}$ shattered by $\\phi(x\\,;z)^{\\rm op}$. \n  That is, for every $\\J\\subseteq \\P[k+1)$ there is $a_\\J$ such that\n  \n  \\ceq{\\hfill\\phi(a_\\J, b_I)}{\\IFF}{I\\in\\J}\\hfill for all $I\\subseteq [k+1)$\n  \n  Let $a_i=a_{\\{I\\; :\\ i\\,\\in\\, I\\}}$. Then from the equivalence above we obtain\n  \n  \\ceq{\\hfill\\phi(a_i, b_I)}{\\IFF}{i\\in I}\n  \n  That is, $\\phi(x\\,;z)$ shatters $A=\\big\\{a_i\\,:\\, i\\in [k+1)\\big\\}$.\n\\end{proof}\n\nWe prove that the bound in the proposition above is optimal.\n\n\\begin{proposition}\n  For every $k$, there is a formula $\\phi(x\\,;z)$ that has \\vc-dimension $k$ and \\vc-codimension $2^{k+1}-1$.\n\\end{proposition}\n\\begin{proof}\n  Let $k$ be given.\n  We claim that there is a formula $\\phi(x\\,;z)$ with \\vc-dimension $2^{k+1}-1$ and \\vc-codimension $k$.\n  As the dual of the dual is the primal, this claim is equivalent to the proposition.\n  Let $\\U$ an infinite set, let $\\V=\\P(\\U)$.\n  Fix an equivalence relation on $\\U$ with $2^{k+1}-1$ many classes.\n  We say that $b\\in\\V$ is compatible if it is union of equivalence classes.\n  Define\n  \n  \\ceq{\\hfill\\phi(x\\,;z)}{=}{x\\in z \\ \\wedge\\ z\\textrm{ is compatible}}%\\A x_1,x_2\\big[x_1\\sim x_2\\imp [x_1\\in z\\iff x_2\\in z]\\big]}\n  \n  (Recall that in the preliminaries to this notes, we have agreed that $\\U$ and $\\V$ are some fixed infinite sets. Without this constraint we could have taken as $\\U$ a set of cardinality $2^{k+1}-1$; defined $\\phi(x\\,;z)=x\\in z$; and forgot the equivalence relation altogether.)\n\n  Clearly, $\\phi(x\\,;z)$ has \\vc-dimension $2^{k+1}-1$.\n  Note that the dimension of $\\phi(x\\,;z)^{\\rm op}$ is at least $k$.\n  Otherwise $\\phi(x\\,;z)$ would have dimension $\\le2^k-1$ by Proposition~\\ref{prop_bound_VCcodim}.\n  \n  So, it suffices to prove that the dimension of $\\phi(x\\,;z)^{\\rm op}$ is exactly $k$.\n  Assume for a contradiction that some $B=\\big\\{b_i\\ :\\ i\\in[k+1)\\big\\}\\subseteq\\V$ is shattered by $\\phi(x\\,;z)^{\\rm op}$.\n  Then there is some set $A=\\big\\{a_I:I\\subseteq[k+1)\\big\\}\\subseteq\\U$ such that\n  \n  \\ceq{\\hfill\\phi(a_I, b_i)}{\\IFF}{i\\in I}\n\n  The $b_i\\in B$ are necessarily compatible sets, therefore any two distinct $a_I\\in A$ are non equivalent.\n  But this is impossible by cardinality reasons.\n\\end{proof}\n\n\\begin{exercise}\n  Let $\\phi(x\\,;z)$ have \\vc-dimension $k$.\n  Assume that there is no $A\\subseteq\\U$ of cardinality $\\le k+1$ such that $\\phi(a\\,;\\V)_{a\\in A}$ covers $\\V$.\n  Prove that $\\phi(x\\,;z)$ has \\vc-codimension $\\le2^{k+1}-2$.\n  Prove that the bound is optimal.\n  Hint: let $\\U$ be an infinite set, $\\V = \\P(\\U)$, and consider an equivalence relation $\\sim$ s.t. $\\U / {\\sim} = C \\cup \\{c_0, \\dots, c_k\\}$ with $|C| = 2^{k+1}-2$ and take the same formula used in the previous Proposition, but with $b \\in \\V$ compatible if it is the union of equivalence classes that belongs to $C$ or if it coincides with $c_i$ for some $i \\in \\{0,\\dots, k\\}$.\n  Prove that $\\phi(x\\,;z)$ has \\vc-codimension $k$.\\QED\n\\end{exercise}\n\n\n% \\begin{exercise}\n%   Let $A\\subseteq\\U$ have finite cardinality $n$.\n%   Let $\\phi(x\\,;z)$ have \\vc-dimension $k$.\n%   Define an equivalence relation on $\\V$ as follows.\n  \n%   \\ceq{\\hfill b\\sim_Ab'}\n%   {\\IFF}\n%   {}\n\n% \\end{exercise}\n\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The Sauer-Shelah lemma}\\label{sauer}\n\n\\def\\ceq#1#2#3{\\parbox[t]{15ex}{$\\displaystyle #1$}\\medrel{#2}{$\\displaystyle #3$}}\n\nAccording to Gil Kalai in~\\cite{kalai}, Sauer-Shelah's Lemma can been described as an \\textit{eigentheorem\\/} because it is important in many different areas of mathematic (model theory, learning theory, probability theory, ergodic theory, Banach spaces, to name a few).\nNo wonder it has been discovered and rediscovered may times.\n\nIt has been proved independently by Shelah~\\cite{shelah72}, Sauer~\\cite{sauer}, and Vapnik-Cher\\-vo\\-nen\\-kis~\\cite{VC} around 1970 (Shelah gives credit to Micha Perles).\nSaharon Shelah was working in model theory while Norbert Sauer, Vladimir Vapnik and Alexey Chervonenkis were in statistical learning theory.\n\n\\begin{void_thm}[Sauer-Shelah Lemma]\\label{lem_sauer}\nIf $\\phi(x\\,;z)$ has \\vc-dimension $k$ then for every $n\\ge k$\n\n\\ceq{\\hfill\\pi_\\phi(n)}{\\le}{\\bigsum^{k}_{i=0} \\binom{n}{i}.}\n\\end{void_thm}\n\nThe set system presented in Example~\\ref{ex_vcdim_opt} shows that the bound is optimal.\n\nAn alternative proof of the Sauer-Shelah Lemma derives it as corollary of a lemma by Alain Pajor~\\cite{pajor}.\n\n\\begin{void_thm}[Pajor's Lemma]\\label{lem_pajor}\n  Let $A\\subseteq\\U$ be finite.\n  \n  \\ceq{\\hfill|\\phi(A,b)_{b\\in\\V}|}{\\le}{\\Big|\\{C\\subseteq A\\; :\\; C \\textrm{\\ is\\ shattered\\ by\\ }\\phi(x\\,;z)\\}\\Big|}.\n\\end{void_thm}\n\n\\begin{proof}\n  If $A$ is empty then $|\\phi(A,b)_{b\\in\\V}|=1$ and $\\0$ is the only subset of $A$ that $\\phi$ shatters, so the inequality holds trivially.\n  Otherwise, pick an $a\\in A$ and assume the lemma holds for $A'=A\\sm\\{a\\}$.\n  Define \n\n  \\ceq{\\hfill\\psi(x\\,;y)}{=}{\\phi(x\\,;y)\\ \\wedge\\neg \\phi(a\\,;y)\\ \\wedge\\ \\E y'\\, \\Big[ \\phi(a\\,;y')\\ \\wedge\\ \\phi(A'\\,;y')=\\phi(A'\\,;y)\\Big].}\n\n  Notice that\n  \n  \\ceq{\\hfill\\big|\\phi(A,b)_{b\\in\\V}\\big|}{=}{\\bigg|\\phi(A',b)_{b\\in\\V}\\quad \\cup\\quad \\Big\\{\\{a\\}\\cup\\psi(A',b)\\ :\\ b\\in\\V\\Big\\}\\bigg|.}\n  \n  as the two sets in the r.h.s.\\@ are disjoint\n\n  \\ceq{\\hfill\\big|\\phi(A,b)_{b\\in\\V}\\big|}{=}{\\big|\\phi(A',b)_{b\\in\\V}\\big|\\ +\\ \\big|\\psi(A',b)_{b\\in\\V}\\big|.}\n\n  By induction hypothesis, \n\n  \\ceq{\\hfill\\big|\\phi(A',b)_{b\\in\\V}\\big|}{\\le}{\\Big|\\{C\\subseteq A'\\; :\\; C \\textrm{\\ is\\ shattered\\ by\\ }\\phi(x\\,;z)\\}\\Big|}\\hfill(1)\n  \n  and\n\n  \\ceq{\\hfill\\big|\\psi(A',b)_{b\\in\\V}\\big|}{\\le}{\\Big|\\{C\\subseteq A'\\; :\\; C \\textrm{\\ is\\ shattered\\ by\\ }\\psi(x\\,;z)\\}\\Big|}\n\n  \\ceq{}{=}{\\Big|\\{C\\subseteq A'\\; :\\; C\\cup\\{a\\} \\textrm{\\ is\\ shattered\\ by\\ }\\phi(x\\,;z)\\}\\Big|.}\\hfill(2)\n\n  In fact, $C\\subseteq A'$ is shattered by $\\psi(x\\,;y)$ if an only if $C\\cup\\{a\\}$ it is shattered by $\\phi(x\\,;y)$.\n  Clearly, \n\n  \\ceq{\\hfill(1)+(2)}{=}{\\Big|\\{C\\subseteq A\\; :\\; C \\textrm{\\ is\\ shattered\\ by\\ }\\phi(x\\,;z)\\}\\Big|,}\n\n  so the lemma follows.\n\\end{proof}\n  \n\\begin{proof}[Proof of the Sauer-Shelah Lemma]\n  Given $\\phi(x\\,;z)$ and $n\\ge k$ as in the lemma\n\n  \\ceq{\\hfill\\pi_\\phi(n)}{=}{\\max_{|A|=n}\\big|\\phi(A,b)_{b\\in\\V}\\big|}\\smallskip\n\n  \\ceq{\\hfill\\pi_\\phi(n)}{\\le}{\\max_{|A|=n}\\big|\\{C\\subseteq A\\; :\\; C\\textrm{\\ shattered\\ by\\ }\\phi(x\\,;z)\\}\\big|}\\hfill by  Pajor's Lemma\\smallskip\n  \n  \\ceq{}{\\le}{\\sum^k_{i=0}{n\\choose i}}\\hfill because $\\phi(x\\,;z)$ has \\vc-dimension $k$\n\\end{proof}\n\nWe write $f(n)=O(g(n))$ if there is a constant $C$ such that $|f(n)|\\le C g(n)$ holds for all (sufficiently large) $n$.\n\nThe \\emph{\\vc-density\\/} of $\\phi(x\\,;z)$ is the infimum over all real number $r$ such that $\\pi_\\phi(n)= O(n^r)$.\nIt is infinite if no such $r$ exist.\nThe  \\emph{dual \\vc-density\\/} is defined accordingly.\n\nBy the Sauer-Shelah lemma the \\vc-density is at most as large as the \\vc-dimension.\nIt could be smaller, however it is usually rather difficult to compute.\n\nWe conclude this section with a couple of inequalities that is useful to have at hand.\n\n\\ceq{\\hfill\\sum^k_{i=0}{n\\choose i}}\n{=}\n{\\sum^k_{i=0}\\frac{n!}{i!\\,(n-i)!}}\n\n\\ceq{}\n{\\le}\n{\\sum^k_{i=0}\\frac{n^i}{i!}}\n\n\\ceq{}\n{\\le}\n{\\sum^k_{i=0}\\frac{n^i\\,k!}{i!(k-i)!}}\n\n\\ceq{}\n{=}\n{\\sum^k_{i=0}n^i{k\\choose i}}\n\n\\ceq{}\n{=}\n{(n+1)^k}\n\\hfill by the binomial theorem.\\smallskip\n\nThere is a second bound, which is better when $k\\ge 3$ and holds for $n>k$\n\n\\ceq{\\hfill\\sum^k_{i=0}{n\\choose i}}\n{\\le}\n{\\Big(\\frac{n}{k}\\Big)^{\\!k}\\sum^k_{i=0}\\Big(\\frac{k}{n}\\Big)^{\\!i}{n\\choose i}}\n\\hfill because $\\dfrac{k}{n}<1$\n\n\\ceq{}\n{\\le}\n{\\Big(\\frac{n}{k}\\Big)^{\\!k}\\sum^n_{i=0}\\Big(\\frac{k}{n}\\Big)^{\\!i}{n\\choose i}}\n\n\\ceq{}\n{=}\n{\\Big(\\frac{n}{k}\\Big)^{\\!k}\\Big(1+\\frac{k}{n}\\Big)^n}\n\\hfill by the binomial theorem\n\n\\ceq{}\n{\\le}\n{\\Big(\\frac{n\\,e}{k}\\Big)^{\\!k}}\n\\hfill where $e$ is the base of the natural logarithm.\n\n\\end{document}\n", "meta": {"hexsha": "dc7240c8aa2978e54f62c59d8d4daa1e3850418f", "size": 11657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sauer.tex", "max_stars_repo_name": "domenicozambella/scombinatorics", "max_stars_repo_head_hexsha": "d0a03c1472a4b345d713e082ebdd0d1361068b88", "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": "sauer.tex", "max_issues_repo_name": "domenicozambella/scombinatorics", "max_issues_repo_head_hexsha": "d0a03c1472a4b345d713e082ebdd0d1361068b88", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-27T12:37:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-27T12:37:11.000Z", "max_forks_repo_path": "sauer.tex", "max_forks_repo_name": "domenicozambella/scombinatorics", "max_forks_repo_head_hexsha": "d0a03c1472a4b345d713e082ebdd0d1361068b88", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-19T08:23:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-19T08:23:27.000Z", "avg_line_length": 41.9316546763, "max_line_length": 382, "alphanum_fraction": 0.6230591061, "num_tokens": 4416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6626269548096967}}
{"text": "\\pagebreak\n\\null\n\\newpage\n\\section{Discrete Laplacians}\\label{sec:Chapter3: other discrete laplacians}\nIn this Chapter we describe different methods to approximate the Laplace-Beltrami operator on manifolds, with particular attention to what we will call the Heat Kernel Graph Laplacian.\n\nLet $f$ be a sufficiently smooth function on a compact, closed infinitely differentiable manifold $\\mathcal M$. The Laplacian eigenvalue problem on $\\mathcal M$ is defined as \n\\begin{equation}\\label{eq:continous eigenvalue problem}\n\\triangle_{\\mathcal M}\\psi = -\\lambda \\psi\n\\end{equation}\nBeing the Laplace-Beltrami operator self-adjoint and semi-positive definite, there exists a basis $\\mathcal B=\\{\\psi_i\\}_i$of the space $L^2(\\mathcal M)$ such that $\\triangle_\\mathcal M \\psi_i = -\\lambda_i\\psi_i,\\ \\lambda_0\\leq\\lambda_1\\leq...,\\lambda_i\\leq\\lambda_{i+1}...\\leq+\\infty$. See \\cite{rosenberg_1997} for an introduction to the Laplace-Beltrami operator on manifolds.\n\nThere's been a lot of work in trying to calculate solutions to equation (\\ref{eq:continous eigenvalue problem}), leading to different ways to approximate the Laplace-Beltrami operator through what we call a \\textit{discrete Laplacian}. By discrete Laplacian we mean an operator $L$ that, once evaluated on a signal $f$ and on a vertex $x_i$ can be written as a matrix $\\mathbf L$ in the following way:\n\n\\begin{equation}\\label{eq:discrete laplacian}\n\\mathbf L f\\left(\\mathbf{x}_{i}\\right)=\\frac{1}{d_{i}} \\sum_{j} w_{i j}\\left(f\\left(\\mathbf{x}_{i}\\right)-f\\left(\\mathbf{x}_{j}\\right)\\right)\n\\end{equation}\n\nNote that with unit \\textit{masses} $d_i=1$ we recover the same definition of Graph Laplacian. We need now to introduce some basic concepts of Differential Geometry, especially the definition of mean curvature of a manifold and its link with the Laplace-Beltrami operator.\n\\subsection{Notions of Differential Geometry}\n\n For this short introduction to basic concepts of Differential Geometry, set the manifold $\\mathcal M$ to be a differentiable, two dimensional surface embedded in $\\mathbb R^3$. \n \\begin{figure}[h]\n \t\\centering\n \t\\includegraphics[width=0.7\\textwidth]{figs/Chapter3/curvature.png}\n \t\\caption{\\label{fig:curvature}Curvature normal of a manifold}\n \\end{figure} \nThe \\textit{curvature} of a curve on a plane is defined as the inverse of the radius $R$ of the tangent circle. For each point on the manifold $\\mathcal M$, define its tangent plane $H$, orthogonal to the normal vector $\\mathbf n$. For every unit vector $\\mathbf e_\\theta$ lying on the tangent plane $H$, where $\\theta$ is an angle that measures the direction on the tangent plane of $\\mathbf e_\\theta$, the \\textit{normal curvature} $\\kappa(\\theta)$ is defined as the curvature of the curve that is the intersection of the manifold $\\mathcal M$ and the plane containing both $\\mathbf n$ and $\\mathbf e_\\theta$. The \\textit{mean curvature} $\\overline \\kappa $ is defined as the average on $\\theta$ of the normal curvatures:\n \n \\begin{equation}\\label{eq:mean curvature}\n \t\\overline \\kappa=\\frac{1}{2 \\pi} \\int_{0}^{2 \\pi} \\kappa(\\theta) d \\theta\n \\end{equation}\n\nIt can be proved that the Laplace-Beltrami operator applied on the identity function $\\mathbf x \\rightarrow \\mathbf x, \\ \\forall \\mathbf x\\in \\mathcal M$ is directly linked to the \\textit{mean curvature normal} $\\overline{\\kappa}\\mathbf n$ by the following formula:\n\\begin{equation}\\label{eq:laplacian and curvature}\n\t\\triangle_\\mathcal M \\mathbf x  = -2\\overline{\\kappa}\\mathbf n\n\\end{equation}\nThis equation provides us a way to approximate the Laplace-Beltrami operator through the approximation of the mean curvature normal. This fact is exploited by methods presented in the next section.\n\n\\subsection{Discrete Laplacians from Differential Geometry}\n\\begin{figure}[h]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\textwidth]{figs/Chapter3/MyDesbrun.png}\n\t\t\\includegraphics[width=0.45\\textwidth]{figs/Chapter3/Voronoi}\n\t\\end{center}\n\t\\caption{\\label{fig:Desbrun}One term of curvature normal formula and one Voronoi cell constructed around the node $x_i$}\n\\end{figure} \nDesbrun et al. \\cite{Desbrun1999} construct a triangulation $\\mathcal T_h$ with the vertices in the sampling $x_0, x_1, ..., x_{n-1}$ approximating the manifold $\\mathcal M$, and then use the following discrete expression for the \\textit{discrete normal curvature} $\\overline{\\kappa_h} \\mathbf{n}$ of the manifold $\\mathcal M$:\n\\begin{equation}\\label{eq:curvature normal}\n\t-\\overline{\\kappa_h} =\\frac{1}{4 A_i} \\sum_{j \\in N_{1}(i)}\\left(\\cot \\alpha_{ij}+\\cot \\beta_{ij}\\right)\\left(x_{j}-x_{i}\\right)\n\\end{equation}\nwhere $A_i$ is the area of all the triangles of the mesh sharing the node $x_i$; $N_1(i)$ is the first ring of neighbors of the $i$th node; $\\alpha_{i j},\\ \\beta_{i j}$ are the angles of the triangles of the mesh that lie on the opposite side to the edge $(i,j)$ with respect to the node $x_i$ (Figure \\ref{fig:Desbrun}). Observe that for a flat surface the discrete curvature is equal to zero $\\overline{\\kappa_h}=0$. This is a geometric approach that relies on the intrinsic properties of the triangulation $\\mathcal T_h$ and is based on the geometric meaning of the curvature normal $\\overline{\\kappa}$. Using equations (\\ref{eq:curvature normal}) and (\\ref{eq:laplacian and curvature}) it can be shown \\cite{REUTER2009381} that this approach leads to a discrete Laplacian with masses\n$$\nd_i=\\frac{A_i}{3}\n$$\nwhere $A_i$ is the area of all the triangles of the mesh with a vertex in $x_i$, and weights\n$$\nw_{i j}=\\frac{\\cot \\left(\\alpha_{i j}\\right)+\\cot \\left(\\beta_{i j}\\right)}{2}\n$$\n\n\\subsection{Linear Finite Element Method Laplacian}\nThe eigenvalue problem (\\ref{eq:continous eigenvalue problem}) can be rewritten in the equivalent weak form\n\\begin{equation}\\label{eq:weak}\n\t\\langle \\nabla f, \\nabla v\\rangle_{L^2(\\mathbb S^2)} = \\lambda \\langle  f, v\\rangle_{L^2(\\mathbb S^2)} \\quad \\forall v \\in L^2(\\mathbb S^2)\n\\end{equation}\nThe Finite Element Method (FEM) is a numerical algorithm that allows to calculate a discrete approximation of the solution $f$ through a functional discretization of the weak eigenvalue problem (\\ref{eq:weak}). We will discuss this method deeper in section \\ref{sec:Chapter3: Using the Finite Element Method to approximate the Laplace-Beltrami operator on a manifold}. By projecting equation (\\ref{eq:weak}) on a finite dimensional functional subspace of $L^2(\\mathbb S^2)$ spanned by $n$ basis functions $\\phi_i$, by writing $n$ times the equation (\\ref{eq:weak eigenvalue problem}), setting each time the \\textit{test} function $v$ equal to the $i$th basis function $\\phi_i$ we obtain the generalized algebraic eigenvalue problem\n$$\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$$\nthat can be solved through usual algebraic solvers. \n\n\\paragraph{FEM Laplacian as a Differential Geometry Laplacian.} Levy \\cite{levy} showed that by using the \\textit{lumped} mass matrix $\\mathbf D_{ii} = \\sum_j \\mathbf B_{ij}$ the FEM Laplacian \n$$\n\\mathbf D^{-1}\\mathbf A\n$$\nis the same Laplacian of Desbrun et al. \\cite{Desbrun1999} introduced in the previous section. Meyer et al. \\cite{Meyer02discretedifferential-geometry} proposed another discrete Laplacian by modifying the masses of Desbrun et al. setting them to \n$$\nd_i=a_{V}(i),\n$$\nwhere \\(a_{V}(i)\\) is the area of the polygon obtained by joining the circumcenters of the triangles surrounding node $i$ (i.e. the Voronoi cell, figure \\ref{fig:Desbrun}).\n\n\\subsection{Graph Laplacian for manifolds}\\label{sec:Chapter1:theoretical foundations}\nBelkin et al. \\cite{NIPS2006_2989} prove convergence of eigenvectors of the \\textit{Heat Kernel Graph Laplacian} $\\mathbf L_n^t$ (HKGL) of a data point cloud to the eigenfunctions of the Laplace Beltrami operator $\\Delta_\\mathcal M$ on the manifold $\\mathcal M$, when the data is sampled from a uniform distribution on $\\mathcal M$.\nFor this result to hold, they suppose the manifold $\\mathcal M$ to be compact, infinitely differentiable and without boundary. We just point out that being $\\mathcal M$ compact, $\\Delta_\\mathcal M$ has a discrete spectrum. The graph they use to approximate the manifold is constructed as follows: given a sampling $ \\mathcal P = \\{x_i\\in\\mathcal M\\}_{i=0}^{n-1}$ on a $k$-dimensional manifold $\\mathcal M\\subset \\mathbb R^N$ they construct the full graph defined by the weights \n$$\nw_{ij}=\\exp\\left({-\\frac{||x_i-x_j||^2}{4t}}\\right)\n$$\nwhere $\\norm\\cdot$ is the Euclidean norm in the ambient space $\\mathbb R^N$ and whose Laplacian matrix \n$$\n\\mathbf L_n^t\n$$ we call \\textit{Heat Kernel Graph Laplacian}.\n\nObserve that given a function $f: \\mathcal P \\rightarrow \\mathbb R$ defined on the sampling $ \\mathcal P$ and defined the vector $\\mathbf f\\in\\mathbb R^n$ such that $\\mathbf f_i = f(x_i)$, the Heat Kernel Graph Laplacian matrix acts on $\\mathbf f$ in the following way:\n\\begin{equation}\\label{eq:HKGL}\n(\\mathbf L_n^t \\mathbf f)_i:=  \\sum_{j=0}^{n-1} e^{-\\frac{||x_i-x_j||^2}{4t}}\\left(f(x_i)-f(x_j)\\right)\n\\end{equation}\nThis graph construction is motivated by the fact that the HKGL is nothing else than the natural discretization of the continuous \\textit{functional approximation to the Laplace-Beltrami operator} $L^t:  L^{2}(\\mathcal{M}) \\rightarrow L^{2}(\\mathcal{M})$ whose eigenvectors and eigenvalues are proven to converge to the ones of $\\Delta_\\mathcal M$.\n\\vspace{0.5cm}\n\\begin{definition}{}(\\cite[Belkin et al.]{Belkin:2005:TTF:2138147.2138189}Functional approximation to the Laplace-Beltrami operator)\\\\ \\label{eq: my L^t} Let $\\mu$ be the uniform probability measure on the manifold $\\mathcal M$, where $\\text{vol}(\\mathcal M)$ is the volume of $\\mathcal M$. We define the functional approximation to the Laplace-Beltrami operator to be the operator $L^t: L^{2}(\\mathcal{M}) \\rightarrow L^{2}(\\mathcal{M})$ such that\n\t\\label{def:Functional approximation to the Laplace-Beltrami operator}\n\t$$ L^tf(y) = \\int_{\\mathcal M}e^{-\\frac{||y-x||^2}{4t}}\\left(f(y)-f(x)\\right)d\\mu(x)$$\n\\end{definition}\nWe end this Chapter by stating the theorem of spectral convergence of the HKGL to the Laplace-Beltrami operator $\\Delta_\\mathcal M$, that makes it a really good candidate to construct rotation invariant graphs.\n\\vspace{0.5cm}\n\\begin{snugshade*}\n\t\\begin{theorem}(Belkin et al., \\cite{NIPS2006_2989})\\label{theo:spectral convergence}\n\t\tLet \\(\\lambda_{n, i}^{t}\\) be the $i$th eigenvalue of \n\t\t$$\n\t\t\\frac{(4\\pi t)^{-(k+2)/2}}{n}\\mathbf L^t_n\n\t\t$$\n\t\tand \\(\\mathbf v_{n, i}^{t}\\) be the corresponding eigenvector. Let \\(\\lambda_{i}\\) and \\(v_{i}\\) be the corresponding eigenvalue and eigenfunction of \\(\\Delta\\) respectively. Then there exists a sequence \\(t_{n} \\rightarrow 0,\\) such that\n\t\t\\begin{equation}\n\t\t\\begin{array}{c}{\\lim _{n \\rightarrow \\infty} \\lambda_{n, i}^{t_{n}}=\\lambda_{i}} \\\\ \n\t\t{\\lim _{n \\rightarrow \\infty}\\left\\|\\mathbf v_{n, i}^{t_{n}}-v_{i}(\\mathbf x)\\right\\|_{2}=0}\\end{array}\n\t\t\\end{equation}\n\t\twhere the limits are in probability.\n\t\\end{theorem}\n\\end{snugshade*}\n\n\n\n", "meta": {"hexsha": "2d3ecf8a8e366a4b34874e25dc710710dd895cdf", "size": 11368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDF/1.2.DiscreteLaplacians.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/1.2.DiscreteLaplacians.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/1.2.DiscreteLaplacians.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": 88.1240310078, "max_line_length": 787, "alphanum_fraction": 0.7419950739, "num_tokens": 3474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257653, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6626268785086444}}
{"text": "\\documentclass{scrartcl}\n\n\\input{../../shared.tex}\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{lemma}{Lemma}[section]\n\\usepackage{enumerate}\n\n\\begin{document}\n\n\n\\section*{Problem set: Gradient descent}%\n\n\n\\paragraph{Exercise (i)} (7P) Enter the missing code snippets in the jupyter notebook. Partial credit will be awarded.\n\n\n\\begin{definition}\n  For a matrix $Q \\in \\R^{m \\times d}$ its \\textbf{operator norm} is defined as\n  \\begin{equation}\n    \\Vert Q \\Vert_{op} := \\sup_{x \\in \\R^d: \\Vert x \\Vert \\le 1} \\Vert Q x \\Vert,\n  \\end{equation}\n  but for convenience we will mostly write $\\Vert Q \\Vert$ (so no subscript) but mean the operator norm.\n\\end{definition}\n\n\\begin{lemma}%\n  The operator norm of a matrix $Q$ fulfills\n  \\begin{equation}\n    \\Vert Qx \\Vert \\le \\Vert Q \\Vert_{op} \\Vert x \\Vert.\n  \\end{equation}\n  In particular, every linear map (given by a matrix $Q$) is Lipschitz continuous with Lipschitz constant $\\Vert Q \\Vert$.\n\\end{lemma}\n\n\n\\paragraph{Exercise (ii)} (2P) Prove that the quadratic function\n\\begin{equation}\n  f(x) = \\frac{1}{2} x^T Q x +b^T x + c\n\\end{equation}\nis \\textbf{smooth} with parameter $\\Vert Q \\Vert$. Note that without loss of generality $Q$ can be assumed to symmetric, however, this should not change anything.\n\n\n\\paragraph{Exercise (iii)} (1P) Suppose that we have observations $(x_i, y_i)$ which are \\textbf{centered}, meaning that $\\sum_{i=1}^{n}x_i = 0 = \\sum_{i=1}^{n}y_i$. Let $(b^*, w^*)$ be the global minimum of the least squares objective\n\\begin{equation}\n  f(b, w) = \\sum_{i=1}^{n} {(b + w^T x_i - y_i)}^2.\n\\end{equation}\nProve that $b^*=0$.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "7737fd9447041e415a77e083fd2a28b6cbea90fd", "size": 1655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/02_gradient_descent/exercises-GD.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/02_gradient_descent/exercises-GD.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/02_gradient_descent/exercises-GD.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": 32.4509803922, "max_line_length": 235, "alphanum_fraction": 0.6918429003, "num_tokens": 535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6626268726845189}}
{"text": "\n\\chapter{Example: a Simple Parity Checker}\\label{parity}\n\nThis chapter consists of a worked example: the specification and\nverification of a simple sequential parity checker.  The intention is\nto accomplish two things:\n\n\\begin{myenumerate}\n\\item To present a complete piece of work with \\HOL.\n\\item To give a flavour of what it is like to use the \\HOL\\ system for\n  a tricky proof.\n\\end{myenumerate}\n\nConcerning (ii), note that although the theorems proved are, in fact,\nrather simple, the way they are proved illustrates the kind of\nintricate `proof engineering' that is typical.  The proofs could be\ndone more elegantly, but presenting them that way would defeat the\npurpose of illustrating various features of \\HOL. It is hoped that the\nsmall example here will give the reader a feel for what it is like to\ndo a big one.\n\nReaders who are not interested in hardware verification should be able\nto learn something about the \\HOL{} system even if they do not wish to\npenetrate the details of the parity-checking example used here.  The\nspecification and verification of a slightly more complex parity\nchecker is set as an exercise (a solution is provided).\n\n\\section{Introduction}\n\nThe sessions of this example comprise the specification and\nverification of a device that computes the parity of a sequence of\nbits.  More specifically, a detailed verification is given of a device\nwith an input {\\small\\verb|in|}, an output {\\small\\verb|out|} and the\nspecification that the $n$th output on {\\small\\verb|out|} is\n{\\small\\verb|T|} if and only if there have been an even number of\n{\\small\\verb|T|}'s input on {\\small\\verb|in|}. A theory named\n{\\small\\verb|PARITY|} is constructed; this contains the specification\nand verification of the device. All the \\ML{} input in the boxes below\ncan be found in the file {\\small\\verb|examples/parity/PARITY.sml|}. It\nis suggested that the reader interactively input this to get a `hands\non' feel for the example. The goal of the case study is to illustrate\ndetailed `proof hacking' on a small and fairly simple example.\n\n\\section{Specification}\n\\label{example}\nThe first step is to start up the \\HOL{} system.  We again use\n\\texttt{<holdir>/bin/hol}.  The \\ML{} prompt is {\\small\\verb|-|}, so\nlines beginning with {\\small\\verb|-|} are typed by the user and other\nlines are the system's response.\n\nTo specify the device, a primitive recursive function\n{\\small\\verb|PARITY|} is defined so that for $n>0$, {\\small\\tt PARITY}\n$n f$ is true if the number of {\\small\\verb|T|}'s in the sequence\n$f${\\small\\tt (}$1${\\small\\tt)}, $\\ldots$ , $f${\\small\\tt\n  (}$n${\\small\\tt)} is even.\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n\\begin{verbatim}\n- val PARITY_def = Define`\n    (PARITY 0 f = T) /\\\n    (PARITY(SUC n) f = if f(SUC n) then ~(PARITY n f) else PARITY n f)`;\nDefinition has been stored under \"PARITY_def\".\n> val PARITY_def =\n    |- (!f. PARITY 0 f = T) /\\\n       !n f. PARITY (SUC n) f =\n             (if f (SUC n) then ~PARITY n f else PARITY n f)\n    : thm\n\\end{verbatim}\n\\end{session}\n\n\\noindent\n\nThe effect of our call to {\\small\\verb|Define|} is to store the\ndefinition of {\\small\\verb|PARITY|} on the current theory with name\n{\\small\\verb|PARITY_def|} and to bind the defining theorem to the \\ML\\\nvariable with the same name.  Notice that there are two name spaces\nbeing written into: the names of constants in theories and the names\nof variables in \\ML.  The user is generally free to manage these names\nhowever he or she wishes (subject to the various lexical\nrequirements), but a common convention is (as here) to give the\ndefinition of a constant {\\small\\tt CON} the name\n{\\small\\verb|CON_def|} in the theory and also in \\ML.  Another\ncommonly-used convention is to use just {\\small\\verb|CON|} for the\ntheory and \\ML{} name of the definition of a constant\n{\\small\\verb|CON|}.  Unfortunately, the \\HOL{} system does not use a\nuniform convention, but users are recommended to adopt one.  In this\ncase \\ml{Define} has made one of the choices for us, but there are\nother scenarios where we have to choose the name used in the theory\nfile.\n\nThe specification of the parity checking device can now be given as:\n\n{\\small\\begin{verbatim}\n   !t. out t = PARITY t inp\n\\end{verbatim}}\n\n\\noindent\nIt is {\\it intuitively\\/} clear that this specification will be\nsatisfied if the signal\\footnote{Signals are modelled as functions\n  from numbers, representing times, to booleans.}  functions\n{\\small\\verb|inp|} and {\\small\\verb|out|} satisfy\\footnote{We'd like\n  to use \\ml{in} as one of our variable names, but this is a reserved\n  word for \\ml{let}-expressions.}:\n\n{\\small\\begin{verbatim}\n   out(0) = T\n\\end{verbatim}}\n\n\\noindent and\n\n{\\small\\begin{verbatim}\n   !t. out(t+1)  =  (if inp(t+1) then ~(out t) else out t)\n\\end{verbatim}}\n\n\\noindent This can be verified formally in \\HOL{} by proving the\nfollowing lemma:\n\n{\\small\\begin{verbatim}\n   !inp out.\n    (out 0 = T) /\\ (!t. out(SUC t) = (if inp(SUC t) then ~(out t) else out t))\n    ==>\n    (!t. out t = PARITY t inp)\n\\end{verbatim}}\n\n\\noindent The proof of this is done by Mathematical Induction and, although\ntrivial, is a good illustration of how such proofs are done.  The\nlemma is proved interactively using \\HOL's subgoal package.  The proof\nis started by putting the goal to be proved on a goal stack using the\nfunction {\\small\\verb|g|} which takes a goal as argument.\n\n\\begin{session}\n\\begin{verbatim}\n- g `!inp out.\n        (out 0 = T) /\\\n        (!t. out(SUC t) = (if inp(SUC t) then ~(out t) else out t)) ==>\n        (!t. out t = PARITY t inp)`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !inp out.\n           (out 0 = T) /\\\n           (!t. out (SUC t) = (if inp (SUC t) then ~out t else out t)) ==>\n           !t. out t = PARITY t inp\n\\end{verbatim}\n\\end{session}\n\n\\noindent The subgoal package prints out the goal on the top of the goal stack.\nThe top goal is expanded by stripping off the universal quantifier\n(with {\\small\\verb|GEN_TAC|}) and then making the two conjuncts of the\nantecedent of the implication into assumptions of the goal (with\n{\\small\\verb|STRIP_TAC|}).  The \\ML{} function {\\small\\verb|expand|}\ntakes a tactic and applies it to the top goal; the resulting subgoals\nare pushed on to the goal stack.  The message `{\\small\\verb|OK..|}' is\nprinted out just before the tactic is applied.  The resulting subgoal\nis then printed.\n\n\n\\begin{session}\n\\begin{verbatim}\n- expand(REPEAT GEN_TAC THEN STRIP_TAC);\nOK..\n1 subgoal:\n> val it =\n    !t. out t = PARITY t inp\n    ------------------------------------\n      0.  out 0 = T\n      1.  !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n\\end{verbatim}\n\\end{session}\n\n\\noindent Next induction on {\\small\\verb|t|} is done\nusing {\\small\\verb|Induct|}, which does\ninduction on the outermost universally quantified variable.\n\n\\begin{session}\n\\begin{verbatim}\n- expand Induct;\nOK..\n2 subgoals:\n> val it =\n    out (SUC t) = PARITY (SUC t) inp\n    ------------------------------------\n      0.  out 0 = T\n      1.  !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n      2.  out t = PARITY t inp\n\n    out 0 = PARITY 0 inp\n    ------------------------------------\n      0.  out 0 = T\n      1.  !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n\\end{verbatim}\n\\end{session}\n\n\\noindent The assumptions of the two subgoals\nare shown numbered underneath the horizontal lines of hyphens. The\nlast goal printed is the one on the top of the stack, which is the\nbasis case. This is solved by rewriting with its assumptions and the\ndefinition of {\\small\\verb|PARITY|}.\n\n\n\\begin{session}\n\\begin{verbatim}\n- expand(ASM_REWRITE_TAC[PARITY_def]);\nOK..\n\nGoal proved.\n [.] |- out 0 = PARITY 0 inp\n\nRemaining subgoals:\n> val it =\n    out (SUC t) = PARITY (SUC t) inp\n    ------------------------------------\n      0.  out 0 = T\n      1.  !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n      2.  out t = PARITY t inp\n\\end{verbatim}\n\\end{session}\n\nThe top goal is proved, so the system pops it from the goal stack (and\nputs the proved theorem on a stack of theorems). The new top goal is\nthe step case of the induction. This goal is also solved by rewriting.\n\n\\begin{session}\n\\begin{verbatim}\n- expand(ASM_REWRITE_TAC[PARITY_def]);\nOK..\n\nGoal proved.\n [..] |- out (SUC t) = PARITY (SUC t) inp\n\nGoal proved.\n [..] |- !t. out t = PARITY t inp\n> val it =\n    Initial goal proved.\n    |- !inp out.\n         (out 0 = T) /\\\n         (!t. out (SUC t) = (if inp (SUC t) then ~out t else out t)) ==>\n         !t. out t = PARITY t inp\n\\end{verbatim}\n\\end{session}\n\n\\noindent The goal is proved, \\ie\\ the empty list of subgoals is produced.\nThe system now applies the justification functions produced by the\ntactics to the lists of theorems achieving the subgoals (starting with\nthe empty list).  These theorems are printed out in the order in which\nthey are generated (note that assumptions of theorems are printed as\ndots).\n\nThe \\ML{} function\n\n{\\small\\begin{verbatim}\n   top_thm : unit -> thm\n\\end{verbatim}}\n\n\\noindent\nreturns the theorem just proved (\\ie\\ on the top of the theorem stack)\nin the current theory, and we bind this to the \\ML{} name\n\\ml{UNIQUENESS\\_LEMMA}.\n\n\\begin{session}\n\\begin{verbatim}\n- val UNIQUENESS_LEMMA = top_thm();\n> val UNIQUENESS_LEMMA =\n    |- !inp out.\n         (out 0 = T) /\\\n         (!t. out (SUC t) = (if inp (SUC t) then ~out t else out t)) ==>\n         !t. out t = PARITY t inp\n    : thm\n\\end{verbatim}\n\\end{session}\n\n\\section{Implementation}\n\\label{implementation}\n\nThe lemma just proved suggests that the parity checker can be\nimplemented by holding the parity value in a register and then\ncomplementing the contents of the register whenever {\\small\\verb|T|}\nis input. To make the implementation more interesting, it will be\nassumed that registers `power up' storing {\\small\\verb|F|}. Thus the\noutput at time {\\small\\verb|0|} cannot be taken directly from a\nregister, because the output of the parity checker at time\n{\\small\\verb|0|} is specified to be {\\small\\verb|T|}. Another tricky\nthing to notice is that if {\\small\\verb|t>0|}, then the output of the\nparity checker at time {\\small\\verb|t|} is a function of the input at\ntime {\\small\\verb|t|}. Thus there must be a combinational path from\nthe input to the output.\n\nThe schematic diagram below shows the design of\na device that is intended to implement this specification.\n(The leftmost input to \\ml{MUX} is the selector.)\nThis works by storing the parity of the sequence input so far in the\nlower of the two registers.  Each time {\\small\\verb|T|} is input at\n{\\small\\verb|in|}, this stored value is complemented. Registers are assumed to\n`power up' in a state in which they are storing {\\small\\verb|F|}.  The second\nregister (connected to {\\small\\verb|ONE|}) initially outputs\n {\\small\\verb|F|} and\nthen outputs {\\small\\verb|T|} forever.  Its role is just to ensure that the\ndevice\nworks during the first cycle by connecting the output {\\small\\verb|out|} to the\ndevice {\\small\\verb|ONE|} via the lower multiplexer.  For all subsequent cycles\n{\\small\\verb|out|} is connected to {\\small\\verb|l3|} and so either carries the\nstored parity value (if the current input is {\\small\\verb|F|}) or the\ncomplement of this value (if the current input is {\\small\\verb|T|}).\n\n\\begin{center}\n%BEGIN IMAGE\n\\setlength{\\unitlength}{5mm}\n\\begin{picture}(14,30)(0,0.5)\n\\put(8,20){\\framebox(2,2){\\small{\\tt NOT}}}\n\\put(6,16){\\framebox(6,2){\\small{\\tt MUX}}}\n\\put(2,16){\\framebox(2,2){\\small{\\tt ONE}}}\n\\put(2,12){\\framebox(2,2){\\small{\\tt REG}}}\n\\put(6,8){\\framebox(6,2){\\small{\\tt MUX}}}\n\\put(8,4){\\framebox(2,2){\\small{\\tt REG}}}\n\n\\puthrule(9,24){4}\n\\puthrule(3,15){8}\n\\puthrule(3,11){4}\n\\puthrule(7,7){2}\n\\puthrule(9,3){4}\n\n\\putvrule(3,11){1}\n\\putvrule(3,14){2}\n\\putvrule(7,2){5}\n\\putvrule(7,10){1}\n\\putvrule(7,18){8}\n\\putvrule(9,3){1}\n\\putvrule(9,6){2}\n\\putvrule(9,10){6}\n\\putvrule(9,18){2}\n\\putvrule(9,22){2}\n\\putvrule(11,10){5}\n\\putvrule(11,18){6}\n\\putvrule(13,3){21}\n\n\\put(6,26){\\makebox(2,2){\\small{\\tt in}}}\n\\put(6,0){\\makebox(2,2){\\small{\\tt out}}}\n\\put(9,18){\\makebox(1.8,2){\\small{\\tt l1}}}\n\\put(13,18){\\makebox(1.8,2){\\small{\\tt l2}}}\n\\put(9,12){\\makebox(1.8,2){\\small{\\tt l3}}}\n\\put(11,12){\\makebox(1.8,2){\\small{\\tt l4}}}\n\\put(4,11){\\makebox(3,1){\\small{\\tt l5}}}\n\n\\put(10,23){\\makebox(2,2){$\\bullet$}}\n\\put(8,6){\\makebox(2,2){$\\bullet$}}\n\\put(2,14){\\makebox(2,2){$\\bullet$}}\n\n\\end{picture}\n\\setlength{\\unitlength}{1mm}\n%END IMAGE\n%HEVEA \\imageflush\n\\end{center}\n\nThe devices making up this schematic will be modelled with predicates\n\\cite{Why-HOL-paper}. For example, the predicate {\\small\\verb|ONE|} is true\nof a signal {\\small\\verb|out|} if for all times {\\small\\verb|t|} the value of\n{\\small\\verb|out|} is {\\small\\verb|T|}.\n\n\\begin{session}\n\\begin{verbatim}\n- val ONE_def = Define `ONE(out:num->bool) = !t. out t = T`;\nDefinition stored under \"ONE_def\".\n> val ONE_def = |- !out. ONE out = !t. out t = T : thm\n\\end{verbatim}\n\\end{session}\n\n\\noindent Note that, as discussed above, `{\\small\\verb|ONE_def|}'  is used both\nas an \\ML{} variable and as the name of the definition in the theory.\nNote also how `{\\small\\verb|:num->bool|}' has been added to resolve\ntype ambiguities; without this (or some other type information) the\ntypechecker would not be able to infer that {\\small\\tt t} is to have\ntype {\\small\\tt num}.\n\nThe binary predicate {\\small\\verb|NOT|} is true of a pair of signals\n{\\small\\verb|(inp,out)|} if the value of {\\small\\verb|out|} is always\nthe negation of the value of {\\small\\verb|inp|}. Inverters are thus\nmodelled as having no delay. This is appropriate for a\nregister-transfer level model, but not at a lower level.\n\n\\begin{session}\n\\begin{verbatim}\n- val NOT_def = Define`NOT(inp, out:num->bool) = !t. out t = ~(inp t)`;\nDefinition stored under \"NOT_def\".\n> val NOT_def = |- !inp out. NOT (inp,out) = !t. out t = ~inp t : Thm.thm\n\\end{verbatim}\n\\end{session}\n\n\\noindent The final combinational device needed is a multiplexer.\nThis is a `hardware conditional'; the input\n{\\small\\verb|sw|} selects which of the other\ntwo inputs are to be connected to the output {\\small\\verb|out|}.\n\n\\begin{session}\n\\begin{verbatim}\n- val MUX_def = Define`\n    MUX(sw,in1,in2,out:num->bool) =\n      !t. out t = if sw t then in1 t else in2 t`;\nDefinition stored under \"MUX_def\".\n> val MUX_def =\n    |- !sw in1 in2 out.\n         MUX (sw,in1,in2,out) = !t. out t = (if sw t then in1 t else in2 t)\n    : thm\n\\end{verbatim}\n\\end{session}\n\nThe remaining devices in the schematic are registers.  These are\nunit-delay elements; the values output at time {\\small\\verb|t+1|} are\nthe values input at the preceding time {\\small\\verb|t|}, except at\ntime {\\small\\verb|0|} when the register outputs\n{\\small\\verb|F|}.\\footnote{Time {\\tt {\\small 0}} represents when the\n  device is switched on.}\n\n\\begin{session}\n\\begin{verbatim}\n- val REG_def =\n    Define `REG(inp,out:num->bool) =\n              !t. out t = if (t=0) then F else inp(t-1)`;\nDefinition stored under \"REG_def\".\n> val REG_def =\n    |- !inp out. REG (inp,out) = !t. out t =\n                 (if t = 0 then F else inp (t - 1))\n    : thm\n\\end{verbatim}\n\\end{session}\n\nThe schematic diagram above can be represented as a predicate by\nconjoining the relations holding between the various\nsignals and then existentially quantifying the internal lines.\nThis technique is explained elsewhere\n(\\eg\\ see \\cite{Camilleri-et-al,Why-HOL-paper}).\n\n\\begin{session}\n\\begin{verbatim}\n- val PARITY_IMP_def = Define\n   `PARITY_IMP(inp,out) =\n      ?l1 l2 l3 l4 l5.\n        NOT(l2,l1) /\\ MUX(inp,l1,l2,l3) /\\ REG(out,l2) /\\\n        ONE l4     /\\ REG(l4,l5)        /\\ MUX(l5,l3,l4,out)`;\nDefinition stored under \"PARITY_IMP_def\".\n> val PARITY_IMP_def =\n    |- !inp out.\n         PARITY_IMP (inp,out) =\n         ?l1 l2 l3 l4 l5.\n           NOT (l2,l1) /\\ MUX (inp,l1,l2,l3) /\\ REG (out,l2) /\\ ONE l4 /\\\n           REG (l4,l5) /\\ MUX (l5,l3,l4,out)\n    : thm\n\\end{verbatim}\n\\end{session}\\label{parity-imp}\n\n\\section{Verification}\n\nThe following theorem will eventually be proved:\n{\\small\\begin{verbatim}\n   |- !inp out. PARITY_IMP(inp,out) ==> (!t. out t = PARITY t inp)\n\\end{verbatim}}\nThis states that {\\it if\\/} {\\small\\verb|inp|} and {\\small\\verb|out|}\nare related as in the schematic\ndiagram (\\ie\\ as in the definition of {\\small\\verb|PARITY_IMP|}),\n{\\it then\\/} the\npair of signals {\\small\\verb|(inp,out)|} satisfies the specification.\n\nFirst, the following lemma is proved; the correctness of the parity\nchecker follows from this and {\\small\\verb|UNIQUENESS_LEMMA|} by the\ntransitivity of {\\small{\\tt\\verb+==>+}}.\n\n\\begin{session}\n\\begin{verbatim}\n- g `!inp out.\n        PARITY_IMP(inp,out) ==>\n        (out 0 = T) /\\\n        !t. out(SUC t) = if inp(SUC t) then ~(out t) else out t`;\n> val it =\n    Proof manager status: 2 proofs.\n    2. Completed: ...\n    1. Incomplete:\n         Initial goal:\n         !inp out.\n           PARITY_IMP (inp,out) ==>\n           (out 0 = T) /\\\n           !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n\\end{verbatim}\n\\end{session}\n\nThe first step in proving this goal is to rewrite with definitions\nfollowed by a decomposition of the resulting goal using\n{\\small\\verb|STRIP_TAC|}. The rewriting tactic\n{\\small\\verb|PURE_REWRITE_TAC|} is used; this does no built-in\nsimplifications, only the ones explicitly given in the list of\ntheorems supplied as an argument.  One of the built-in simplifications\nused by {\\small\\verb|REWRITE_TAC|} is {\\small\\tt |-~(x~=~T)~=~x}.\n{\\small\\verb|PURE_REWRITE_TAC|} is used to prevent rewriting with this\nbeing done.\n\\begin{session}\n\\begin{verbatim}\n- expand(PURE_REWRITE_TAC\n           [PARITY_IMP_def, ONE_def, NOT_def, MUX_def, REG_def] THEN\n         REPEAT STRIP_TAC);\nOK..\n2 subgoals:\n> val it =\n    out (SUC t) = (if inp (SUC t) then ~out t else out t)\n    ------------------------------------\n      0.  !t. l1 t = ~l2 t\n      1.  !t. l3 t = (if inp t then l1 t else l2 t)\n      2.  !t. l2 t = (if t = 0 then F else out (t - 1))\n      3.  !t. l4 t = T\n      4.  !t. l5 t = (if t = 0 then F else l4 (t - 1))\n      5.  !t. out t = (if l5 t then l3 t else l4 t)\n\n    out 0 = T\n    ------------------------------------\n      0.  !t. l1 t = ~l2 t\n      1.  !t. l3 t = (if inp t then l1 t else l2 t)\n      2.  !t. l2 t = (if t = 0 then F else out (t - 1))\n      3.  !t. l4 t = T\n      4.  !t. l5 t = (if t = 0 then F else l4 (t - 1))\n      5.  !t. out t = (if l5 t then l3 t else l4 t)\n\\end{verbatim}\n\\end{session}\n\nThe top goal is the one printed last; its conclusion is\n{\\small\\verb|out 0 = T|} and its assumptions are equations relating\nthe values on the lines in the circuit.  The natural next step would\nbe to expand the top goal by rewriting with the assumptions.  However,\nif this were done the system would go into an infinite loop because\nthe equations for {\\small\\verb|out|}, {\\small\\verb|l2|} and\n{\\small\\verb|l3|} are mutually recursive.  Instead we use the\nfirst-order reasoner {\\small\\verb|PROVE_TAC|} to do the work:\n\n\\begin{session}\n\\begin{verbatim}\n- expand(PROVE_TAC []);\nOK..\nMeson search level: .....\n\nGoal proved.\n [......] |- out 0 = T\n\nRemaining subgoals:\n> val it =\n    out (SUC t) = (if inp (SUC t) then ~out t else out t)\n    ------------------------------------\n      0.  !t. l1 t = ~l2 t\n      1.  !t. l3 t = (if inp t then l1 t else l2 t)\n      2.  !t. l2 t = (if t = 0 then F else out (t - 1))\n      3.  !t. l4 t = T\n      4.  !t. l5 t = (if t = 0 then F else l4 (t - 1))\n      5.  !t. out t = (if l5 t then l3 t else l4 t)\n\\end{verbatim}\n\\end{session}\nThe first of the two subgoals is proved.  Inspecting the remaining\ngoal it can be seen that it will be solved if its left hand side,\n{\\small\\verb|out(SUC t)|}, is expanded using the assumption:\n\n{\\small\\begin{verbatim}\n   !t. out t = if l5 t then l3 t else l4 t\n\\end{verbatim}}\n\n    However, if this assumption is used for rewriting, then all the\n    subterms of the form {\\small\\verb|out t|} will also be expanded.\n    To prevent this, we really want to rewrite with a formula that is\n    specifically about {\\small\\verb|out (SUC t)|}.  We want to somehow\n    pull the assumption that we do have out of the list and rewrite\n    with a specialised version of it.  We can do just this using\n    {\\small\\verb|PAT_ASSUM|}.  This tactic is of type \\ml{term -> thm\n      -> tactic}.  It selects an assumption that is of the form given\n    by its term argument, and passes it to the second argument, a\n    function which expects a theorem and returns a tactic.  Here it is\n    in action:\n\n\\begin{session}\n\\begin{verbatim}\n- e (PAT_ASSUM ``!t. out t = X t``\n       (fn th => REWRITE_TAC [SPEC ``SUC t`` th]));\n<<HOL message: inventing new type variable names: 'a, 'b.>>\nOK..\n1 subgoal:\n> val it =\n    (if l5 (SUC t) then l3 (SUC t) else l4 (SUC t)) =\n    (if inp (SUC t) then ~out t else out t)\n    ------------------------------------\n      0.  !t. l1 t = ~l2 t\n      1.  !t. l3 t = (if inp t then l1 t else l2 t)\n      2.  !t. l2 t = (if t = 0 then F else out (t - 1))\n      3.  !t. l4 t = T\n      4.  !t. l5 t = (if t = 0 then F else l4 (t - 1))\n\\end{verbatim}\n\\end{session}\nThe pattern used here exploited something called \\emph{higher order\n  matching}. The actual assumption that was taken off the assumption\nstack did not have a RHS that looked like the application of a\nfunction (\\ml{X} in the pattern) to the \\ml{t} parameter, but the RHS\ncould nonetheless be seen as equal to the application of \\emph{some}\nfunction to the \\ml{t} parameter.  In fact, the value that matched\n\\ml{X} was {\\small\\verb|``\\x. if l5 x then l3 x else l4 x``|}.\n\nInspecting the goal above, it can be seen that the next step is to\nunwind the equations for the remaining lines of the circuit.  We do\nthis using the \\ml{arith\\_ss} simpset that comes with \\ml{bossLib} to\nhelp with the arithmetic embodied by the subtractions and \\ml{SUC}\nterms.\n\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\nOK..\n\nGoal proved.\n [.....]\n|- (if l5 (SUC t) then l3 (SUC t) else l4 (SUC t)) =\n   (if inp (SUC t) then ~out t else out t)\n\nGoal proved.\n [......] |- out (SUC t) = (if inp (SUC t) then ~out t else out t)\n> val it =\n    Initial goal proved.\n    |- !inp out.\n         PARITY_IMP (inp,out) ==>\n         (out 0 = T) /\\\n         !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n\\end{verbatim}\n\\end{session}\n\n\\noindent The theorem just proved is named\n{\\small\\verb|PARITY_LEMMA|} and saved in the current theory.\n\n\\begin{session}\n\\begin{verbatim}\n- val PARITY_LEMMA = top_thm ();\n> val PARITY_LEMMA =\n    |- !inp out.\n         PARITY_IMP (inp,out) ==>\n         (out 0 = T) /\\\n         !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n\\end{verbatim}\n\\end{session}\n\n{\\small\\verb|PARITY_LEMMA|} could have been proved in one step with a\nsingle compound tactic.  Our initial goal can be expanded with a\nsingle tactic corresponding to the sequence of tactics that were used\ninteractively:\n\n\\begin{session}\n\\begin{verbatim}\n- restart()\n> ...\n- e (PURE_REWRITE_TAC [PARITY_IMP_def, ONE_def, NOT_def,\n                       MUX_def, REG_def] THEN\n     REPEAT STRIP_TAC THENL [\n       PROVE_TAC [],\n       PAT_ASSUM ``!t. out t = X t``\n                 (fn th => REWRITE_TAC [SPEC ``SUC t`` th]) THEN\n       RW_TAC arith_ss []\n     ]);\n<<HOL message: inventing new type variable names: 'a, 'b.>>\nOK..\nMeson search level: .....\n> val it =\n    Initial goal proved.\n    |- !inp out.\n         PARITY_IMP (inp,out) ==>\n         (out 0 = T) /\\\n         !t. out (SUC t) = (if inp (SUC t) then ~out t else out t)\n\\end{verbatim}\n\\end{session}\n\nArmed with {\\small\\verb|PARITY_LEMMA|}, the final theorem is easily\nproved.  This will be done in one step using the \\ML{} function\n{\\small\\verb|prove|}.\n\n\\begin{session}\n\\begin{verbatim}\n- val PARITY_CORRECT = prove(\n    ``!inp out. PARITY_IMP(inp,out) ==> (!t. out t = PARITY t inp)``,\n    REPEAT STRIP_TAC THEN MATCH_MP_TAC UNIQUENESS_LEMMA THEN\n    MATCH_MP_TAC PARITY_LEMMA THEN ASM_REWRITE_TAC []);\n> val PARITY_CORRECT =\n    |- !inp out. PARITY_IMP (inp,out) ==> !t. out t = PARITY t inp\n\\end{verbatim}\n\\end{session}\n\n\\noindent This completes the proof of the\nparity checking device.\n\n\\section{Exercises}\n\\label{exercises}\n\nTwo exercises are given in this section: Exercise~1 is\nstraightforward, but Exercise~2 is quite tricky and might take a\nbeginner several days to solve.\n\n\\subsection{Exercise 1}\n\nUsing {\\it only\\/} the devices {\\small\\verb|ONE|}, {\\small\\verb|NOT|},\n{\\small\\verb|MUX|} and {\\small\\verb|REG|} defined in\nSection~\\ref{implementation}, design and verify a register\n{\\small\\verb|RESET_REG|} with an input {\\small\\verb|in|}, reset line\n{\\small\\verb|reset|}, output {\\small\\verb|out|} and behaviour\nspecified as follows.\n\\begin{itemize}\n\\item If {\\small\\verb|reset|} is {\\small\\verb|T|} at time\n  {\\small\\verb|t|}, then the value at {\\small\\verb|out|} at time\n  {\\small\\verb|t|} is also {\\small\\verb|T|}.\n\\item If {\\small\\verb|reset|} is {\\small\\verb|T|} at time\n  {\\small\\verb|t|} or {\\small\\verb|t+1|}, then the value output at\n  {\\small\\verb|out|} at time {\\small\\verb|t+1|} is {\\small\\verb|T|},\n  otherwise it is equal to the value input at time {\\small\\verb|t|} on\n  {\\small\\verb|inp|}.\n\\end{itemize}\nThis is formalized in \\HOL{} by the definition:\n\n{\\small\\begin{verbatim}\n   RESET_REG(reset,inp,out) =\n    (!t. reset t ==> (out t = T)) /\\\n    (!t. out(t+1) = ((reset t  \\/ reset(t+1)) => T | inp t))\n\\end{verbatim}}\n\n\\noindent Note that this specification is only partial; it doesn't specify the\noutput at time {\\small\\verb|0|} in the case that there is no reset.\n\nThe solution to the exercise should be a definition of a predicate\n{\\small\\verb|RESET_REG_IMP|} as an existential quantification of a\nconjunction of applications of {\\small\\verb|ONE|}, {\\small\\verb|NOT|},\n{\\small\\verb|MUX|} and {\\small\\verb|REG|} to suitable line\nnames,\\footnote{i.e.  a definition of the same form as that of\n  {\\small\\tt PARITY\\_IMP}\n%BEGIN LATEX\non page~\\pageref{parity-imp}.\n%END LATEX\n%HEVEA in section~\\ref{parity-imp}\n} together with a proof of:\n\n{\\small\\begin{verbatim}\n   RESET_REG_IMP(reset,inp,out) ==> RESET_REG(reset,inp,out)\n\\end{verbatim}}\n\n\n\\subsection{Exercise 2}\n\n\\begin{enumerate}\n\\item Formally specify a resetable parity checker that has two boolean\n  inputs {\\small\\tt reset} and {\\small\\tt inp}, and one boolean output\n  {\\small\\tt out} with the following behaviour:\n  \\begin{quote}\n    The value at {\\small\\tt out} is {\\small\\tt T} if and only if there\n    have been an even number of {\\small\\tt T}s input at {\\small\\tt inp}\n    since the last time that {\\small\\tt T} was input at {\\small\\tt\n      reset}.\n  \\end{quote}\n\\item Design an implementation of this specification built using {\\it\n    only\\/} the devices {\\small\\verb|ONE|}, {\\small\\verb|NOT|},\n  {\\small\\verb|MUX|} and {\\small\\verb|REG|} defined in\n  Section~\\ref{implementation}.\n\\item Verify the correctness of your implementation in \\HOL.\n\\end{enumerate}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"tutorial\"\n%%% End:\n", "meta": {"hexsha": "aecb3f9b274cdfae95c6b1265dcf472c9cc3bd4c", "size": 26947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Tutorial/parity.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/parity.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/parity.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": 35.3171690695, "max_line_length": 79, "alphanum_fraction": 0.6678665529, "num_tokens": 8453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.662626871023388}}
{"text": "\\section{Overview}\n\\label{sec:refinementreflection:overview}\n\\label{sec:examples}\n\nWe begin with an overview of refinement reflection and\nhow it allows us to write proofs \\emph{of} and \\emph{by}\nHaskell functions.\n\n\\subsection{Refinement Types}\n\nFirst, we recall some preliminaries about refinement types\nand how they enable shallow specification and verification.\n\n\\mypara{Refinement types} are the source program's (here\nHaskell's) types decorated with logical predicates drawn\nfrom a(n SMT decidable) logic~\\citep{ConstableS87,Rushby98}.\n%\nFor example, we can define the @Nat@ type by refining\nHaskell's @Int@ type with a predicate @0 <= v@:\n%\n\\begin{code}\n  type Nat = { v:Int | 0 <= v }\n\\end{code}\n%\nHere, @v@ names the value described by the type:\nthe above can be read as the\n``set of @Int@ values @v@ that are not less than 0\".\nThe refinement is drawn from the logic of quantifier\nfree linear arithmetic and uninterpreted functions\n(QF-UFLIA~\\cite{SMTLIB2}).\n\n\\mypara{Specification \\& Verification}\n%\nWe can use refinements to define and type the\ntextbook Fibonacci function as:\n%\n\\begin{code}\n  fib :: Nat -> Nat\n  fib 0 = 0\n  fib 1 = 1\n  fib n = fib (n-1) + fib (n-2)\n\\end{code}\n%\nHere, the input type's refinement specifies a\n\\emph{pre-condition} that the parameters must\nbe @Nat@, which is needed to ensure termination,\nand the output types's refinement specifies a\n\\emph{post-condition} that the result is also a @Nat@.\n%\nRefinement type checking lets us specify\nand (automatically) verify the shallow property\nthat if @fib@ is invoked with a non-negative\n@Int@, then it terminates and yields\na non-negative @Int@.\n\n\\mypara{Propositions}\n%\nWe can use refinements to define a data type\nrepresenting propositions simply as an alias\nfor unit, a data type that carries no useful\nruntime information:\n%\n\\begin{mcode}\n  type $\\typp$ = ()\n\\end{mcode}\n%\nwhich can be \\emph{refined} with\npropositions about the code.\n%\nFor example, the following states the proposition\n$2 + 2$ equals $4$.\n%\n\\begin{mcode}\n  type Plus_2_2_eq_4 = { v: $\\typp$ | 2 + 2 = 4 }\n\\end{mcode}\n%\nFor clarity, we abbreviate the above type by omitting\nthe irrelevant basic type $\\typp$ and variable @v@:\n%\n\\begin{mcode}\n  type Plus_2_2_eq_4 = { 2 + 2 = 4 }\n\\end{mcode}\n%\nFunction types encode universally quantified propositions:\n%\n\\begin{mcode}\n  type Plus_com = x:Int -> y:Int -> { x + y = y + x }\n\\end{mcode}\n%\nThe parameters @x@ and @y@ refer to input\nvalues. Any inhabitant of the above type is a\nproof that @Int@ addition is commutative.\n\n\\mypara{Proofs}\n%\nWe \\emph{prove} the above theorems by providing inhabitants to type specifications\nin forms of Haskell programs. To ease this task \\toolname\nprovides primitives to construct proof terms by\n``casting'' expressions to \\typp.\n%\n\\begin{mcode}\n  data QED = QED\n\n  (**) :: a -> QED -> $\\typp$\n  _ ** _  = ()\n\\end{mcode}\n%\nTo resemble mathematical proofs, we make this casting post-fix.\nThus, we write @e ** QED@ to cast @e@ to a value of \\typp.\n%\nFor example, we can prove the above propositions by writing\n%\n\\begin{code}\n  pf_plus_2_2 :: Plus_2_2_eq_4\n  pf_plus_2_2 = trivial ** QED\n\n  pf_plus_comm :: Plus_comm\n  pf_plus_comm = \\x y -> trivial ** QED\n\n  trivial = ()\n\\end{code}\n%\nVia standard refinement type checking, the above code yields\nthe respective verification conditions (VCs),\n%\n\\begin{align*}\n                      2 + 2 & = 4 \\\\\n  \\forall \\ x,\\ y\\ .\\ x + y & = y + x\n\\end{align*}\n%\nwhich are easily proved valid by the SMT solver, allowing us\nto prove the respective propositions.\n\n\\mypara{A Note on Bottom:} Readers familiar with Haskell's\nsemantics may be feeling anxious about whether the\ndreaded ``bottom\", which inhabits all types, makes our\nproofs suspect.\n%\nFortunately, as described in \\cite{Vazou14}, \\toolname\nensures that all terms with non-trivial refinements\nprovably evaluate to (non-bottom) values, thereby making\nour proofs sound.\n\n\\subsection{Refinement Reflection}\n\nSuppose we wish to prove properties about the @fib@\nfunction, \\eg @fib 2@ equals @1@.\n%\n\\begin{code}\n  type fib2_eq_1 = { fib 2 = 1 }\n\\end{code}\n%\n%% \\NV{By Standard refinement type checking, you mean liquid types, not FStar}\nStandard refinement type checking runs into two problems.\n%\nFirst, for decidability and soundness, arbitrary user-defined\nfunctions do not belong the refinement logic, \\ie we cannot\n\\emph{refer} to @fib@ in a refinement.\n%\nSecond, the only information that a refinement type checker\nhas about the behavior of @fib@ is its shallow type\nspecification @Nat -> Nat@ which is far too weak to verify\n@fib2_eq_1@.\n%\nTo address both problems, we use the following annotation,\nwhich sets in motion the three steps of refinement reflection:\n%\n\\begin{code}\n  reflect fib\n\\end{code}\n\n\\mypara{Step 1: Definition}\n%\nThe annotation tells \\toolname to declare an\n\\emph{uninterpreted function} @fib :: Int -> Int@\nin the refinement logic.\n%\nBy uninterpreted, we mean that the logical @fib@\nis \\emph{not} connected to the program function\n@fib@; in the logic, @fib@\nonly satisfies the \\emph{congruence axiom}\n%\n$$\\forall n, m.\\ n = m\\ \\Rightarrow\\ \\fib{n} = \\fib{m}$$\n%\nOn its own, the uninterpreted function is not\nterribly useful, as it does not let us prove\n% It lets us prove theorems like\n% $$\\forall m,\\ n.\\ m = n \\Rightarrow \\fib{m} = \\fib{n}$$\n%\n%% \\begin{code}\n  %% fib_cong :: n:Nat -> m:Nat -> {m=n => fib m = fib n}\n  %% fib_cong = trivial ** QED\n%% \\end{code}\n%% %\n%but not\n@fib2_eq_1@ which requires reasoning about the\n\\emph{definition} of @fib@.\n\n\\mypara{Step 2: Reflection}\n%\nIn the next key step, \\toolname reflects the\ndefinition into the refinement type of @fib@\nby automatically strengthening the user defined\ntype for @fib@ to:\n%\n\\begin{code}\n  fib :: n:Nat -> { v:Nat | fibP v n }\n\\end{code}\n%\nwhere @fibP@ is an alias for a refinement\n\\emph{automatically derived} from the\nfunction's definition:\n%\n\\begin{mcode}\n  fibP v n = v = if n = 0 then 0 else\n                 if n = 1 then 1 else\n                 fib(n-1) + fib(n-2)\n\\end{mcode}\n\n\\mypara{Step 3: Application}\n%\nWith the reflected refinement type,\neach application of @fib@ in the code\nautomatically unfolds the @fib@ definition\n\\textit{once} in the logic.\n%\nWe prove @fib2_eq_1@ by:\n%\n\\begin{code}\n  pf_fib2 :: { fib 2 = 1 }\n  pf_fib2 = let t0 = #fib# 0 \n                t1 = #fib# 1\n                t2 = #fib# 2 \n            in  ()\n\\end{code}\n%\nWe write @#f#@ to denote places where the\nunfolding of @f@'s definition is important.\n%\nVia refinement typing, the above proof yields the\nfollowing verification condition that is\ndischarged by the SMT solver, even though @fib@\nis uninterpreted:\n%\n\\begin{align*}\n   (\\fibdef\\ (\\fib\\ 0)\\ 0) \\ \\wedge\\ (\\fibdef\\ (\\fib\\ 1)\\ 1) \\ \\wedge\\ \n   (\\fibdef\\ (\\fib\\ 2)\\ 2) \\  \\Rightarrow\\ (\\fib{2} = 1)\n\\end{align*}\n%\nNote that the verification of @pf_fib2@ relies\nmerely on the fact that @fib@ was applied\nto (\\ie unfolded at) @0@, @1@ and @2@.\n%\nThe SMT solver automatically \\emph{combines}\nthe facts, once they are in the antecedent.\nThe following is also verified:\n%\n\\begin{code}\n  pf_fib2' :: { fib 2 = 1 }\n  pf_fib2' = [ #fib# 0, #fib# 1, #fib# 2 ] ** QED\n\\end{code}\n%\n%\nThus, unlike classical dependent typing, refinement\nreflection \\emph{does not} perform any type-level\ncomputation.\n\n\\mypara{Reflection vs. Axiomatization}\n%\nAn alternative \\emph{axiomatic} approach,\nused by Dafny~\\citep{dafny} and\n\\fstar~\\citep{fstar},\nis to encode @fib@ using a universally\nquantified SMT formula (or axiom):\n$$\\forall n.\\ \\fibdef\\ (\\fib\\ n)\\ n$$\n%\nAxiomatization offers greater automation than\nreflection. Unlike \\toolname, Dafny\n%and \\fstar\nwill verify the following by\n\\emph{automatically instantiating} the above\naxiom at @2@, @1@ and @0@:\n%\n\\begin{code}\n  axPf_fib2 :: { fib 2 = 1 }\n  axPf_fib2 = trivial ** QED\n\\end{code}\n\nThe automation offered by axioms is a bit of a\ndevil's bargain, as axioms render checking of\nthe VCs \\emph{undecidable}.\n%\nIn practice, automatic axiom instantation can\neasily lead to infinite ``matching loops''.\n%\nFor example, the existence of a term \\fib{n} in a VC\ncan trigger the above axiom, which may then produce\nthe terms \\fib{(n-1)} and \\fib{(n-2)}, which may then\nrecursively give rise to further instantiations\n\\emph{ad infinitum}.\n%\nTo prevent matching loops an expert must carefully\ncraft ``triggers'' and provide a ``fuel''\nparameter~\\citep{Amin2014ComputingWA} that can be\nused to restrict the numbers of the SMT unfoldings,\nwhich ensure termination, but can cause the axiom\nto not be instantiated at the right places.\n%\nIn short, per the authors of Dafny, the\nundecidability of the VC checking and its\nattendant heuristics makes verification\nunpredictable~\\citep{Leino16}.\n\n\\subsection{Structuring Proofs}\n\nIn contrast to the axiomatic approach,\nwith refinement reflection, the VCs are\ndeliberately designed to always fall in\nan SMT-decidable logic, as function symbols\nare uninterpreted.\n%\nIt is up to the programmer to unfold the\ndefinitions at the appropriate places,\nwhich we have found, with careful design\nof proof combinators, to be quite\na natural and pleasant experience.\n%\nTo this end, we have developed a library\nof proof combinators that permits reasoning\nabout equalities and linear arithmetic,\ninspired by Agda~\\citep{agdaequational}.\n\n\\mypara{``Equation'' Combinators}\n%\nWe equip \\toolname with a family of\nequation combinators @op.@ for each\nlogical operator @op@ in\n$\\{=, \\not =, \\leq, <, \\geq, > \\}$,\nthe operators in the theory QF-UFLIA.\n%\nThe refinement type of @op.@  \\emph{requires}\nthat $x \\odot y$ holds and then \\emph{ensures}\nthat the returned value is equal to @x@.\n%\nFor example, we define @=.@ as:\n%\n\\begin{code}\n  (=.) :: x:a -> y:{a| x=y} -> {v:a| v=x}\n  x =. _ = x\n\\end{code}\n%\nand use it to write the following ``equational\" proof:\n%\n\\begin{code}\n  eqPf_fib2 :: { fib 2 = 1 }\n  eqPf_fib2 =  #fib# 2\n            =. #fib# 1 + #fib# 0\n            =. 1\n            ** QED\n\\end{code} %$\n\n\\mypara{``Because'' Combinators}\n%\nOften, we need to compose ``lemmata'' into larger\ntheorems. For example, to prove @fib 3 = 2@ we\nmay wish to reuse @eqPf_fib2@ as a lemma.\n%\nTo this end, \\toolname has a ``because'' combinator:\n%\n\\begin{mcode}\n  ($\\because$) :: ($\\typp$ -> a) -> $\\typp$ -> a\n  f $\\because$ y = f y\n\\end{mcode}\n%\nThe operator is simply an alias for function\napplication that lets us write\n%\n@ x op. y $\\because$ p@ (instead of @(op.) x y p@)\nwhere @(op.)@ is extended to accept an \\textit{optional} third proof\nargument via Haskell's typeclass mechanisms.\n%\nWe use the because combinator to\nprove that @fib 3 = 2@ with a Haskell function:\n%\n\\begin{mcode}\n  eqPf_fib3 :: { fib 3 = 2 }\n  eqPf_fib3 =  #fib# 3\n            =. fib 2 + #fib# 1\n            =. 2              $\\because$ eqPf_fib2\n            ** QED\n\\end{mcode}\n\n\\mypara{Arithmetic and Ordering}\n%\nSMT based refinements let us go well beyond just equational\nreasoning. Next, lets see how we can use arithmetic and\nordering to prove that @fib@ is (locally) increasing,\n%\n\\ie for all $n$, $\\fib{n} \\leq \\fib{(n+1)}$\n%\n\\begin{mcode}\n  fibUp :: n:Nat -> { fib n <= fib (n+1) }\n  fibUp n\n    | n == 0\n    =  #fib# 0 <. #fib# 1\n    ** QED\n\n    | n == 1\n    =  fib 1 <=. fib 1 + fib 0 <=. #fib# 2\n    ** QED\n\n    | otherwise\n    =  #fib# n\n    =. fib (n-1) + fib (n-2)\n    <=. fib n     + fib (n-2) $\\because$ fibUp (n-1)\n    <=. fib n     + fib (n-1) $\\because$ fibUp (n-2)\n    <=. #fib# (n+1)\n    ** QED\n\\end{mcode} %$\n\n\\mypara{Case Splitting and Induction}\n%\nThe proof @fibUp@ works by induction on @n@.\n%\nIn the \\emph{base} cases @0@ and @1@, we simply assert\nthe relevant inequalities. These are verified as the\nreflected refinement unfolds the definition of\n@fib@ at those inputs.\n%\nThe derived VCs are (automatically) proved\nas the SMT solver concludes $0 < 1$ and $1 + 0 \\leq 1$\nrespectively.\n%\nIn the \\emph{inductive} case, @fib n@ is unfolded\nto  @fib (n-1) + fib (n-2)@, which, because of the\ninduction hypothesis (applied by invoking @fibUp@\nat @n-1@ and @n-2@) and the SMT solver's arithmetic\nreasoning, completes the proof.\n\n\\mypara{Higher Order Theorems}\n%\nRefinements smoothly accomodate higher-order reasoning.\n%\nFor example, lets prove that every locally increasing\nfunction is monotonic, \\ie\nif @f z <= f (z+1)@ for all @z@,\nthen @f x <= f y@ for all @x < y@.\n%\n\\begin{mcode}\n  fMono :: f:(Nat -> Int)\n        -> fUp:(z:Nat -> {f z <= f (z+1)})\n        -> x:Nat\n        -> y:{x < y}\n        -> {f x <= f y} / [y]\n  fMono f inc x y\n    | x + 1 == y\n    =  f x <=. f (x+1) $\\because$ fUp x\n           <=. f y\n           ** QED\n\n    | x + 1 < y\n    =  f x <=. f (y-1) $\\because$ fMono f fUp x (y-1)\n           <=. f y     $\\because$ fUp (y-1)\n           ** QED\n\\end{mcode}\n%\nWe prove the theorem by induction\non @y@, which is specified by the\nannotation @/ [y]@ which states\nthat @y@ is a well-founded\ntermination metric that decreases\nat each recursive call~\\citep{Vazou14}.\n%\n% All reflected functions are proved terminating.\n% When the annotation metric is not explicit Liquid Haskell\n% successfully uses heuristics to automatically prove termination. \n%\nIf @x+1 == y@, then we use @fUp x@.\n%\nOtherwise, @x+1 < y@, and we use\nthe induction hypothesis \\ie apply\n@fMono@ at @y-1@, after which\ntransitivity of the less-than\nordering finishes the proof.\n%\nWe can use the general @fMono@\ntheorem to prove that @fib@\nincreases monotonically:\n%\n\\begin{code}\n  fibMono :: n:Nat -> m:{n<m} -> {fib n <= fib m}\n  fibMono = fMono fib fibUp\n\\end{code}\n\n\n\\subsection{Case Study: Deterministic Parallelism}\n\\label{sec:detpar}\n\n%% The natural integration of deep verification with a language like Haskell makes\n%% it possible to engage in lightweight, incremental verification of program\n%% properties.\n\nOne benefit of an in-language prover is that it lowers the barrier to {\\em\n  small} verification efforts that touch only a fraction of the program, and yet\nensure critical invariants that Haskell's type system cannot.  Here we consider\nparallel programming, which is commonly considered error prone and entails\nproof obligations on the user that typically go unchecked.\n\nThe situation is especially precarious with parallel programming frameworks that\nclaim to be {\\em determinstic} and thus usable within purely functional\nprograms.  These include Deterministic Parallel Java (DPJ \\cite{DPJ}), Concurrent\nRevisions for .NET~\\cite{concurrent-revisions-oopsla}, and Haskell's\nLVish~\\cite{kuper2014freeze}, Accelerate~\\cite{accelerate-icfp13}, and\nREPA~\\cite{repa-icfp10}.\n%\nAccelerate's parallel fold function, for instance, claims to be\ndeterministic---and its purely functional type means the Haskell optimizer will\n{\\em assume} its referential transparency---but its determinism depends on an\nassociativity guarantee which must be assured {\\em by the programmer} rather than the\ntype system.\n%\nThus simply folding the minus function, @fold (-) 0 arr@, is sufficient to\nviolate determinism and Haskell's pure semantics.\n\n\nLikewise, DPJ goes to pains to develop a new type system for parallel\nprogramming, but then provides a ``commutes'' annotation for methods updating\nshared state, compromising the {\\em guarantee} and going back to trusting the\nuser. LVish has the same Achilles heel. Consider set insertion:\n\n\\begin{code}\n  insert :: Ord a => a -> Set s a -> Par s ()\n\\end{code}\n\nHere @insert@ returns an (effectful) @Par@ computation, which can be run within a\npure function to produce a pure result.  At first glance it would seem that\ntrusting the implementation of the concurrent set is sufficient to assure a\ndeterministic outcome.  Yet the interface has an @Ord@ constraint. This\n polymorphic function works with user-defined data types, and thus\nuser-defined orderings.  What if the user fails to implement a total order?\nThen, even a correct implementation of, e.g. a concurrent\nskiplist~\\cite{concurrent-skiplist}, can reveal\ndifferent insertion orders due to concurrency.\n\n%% verifiedInsert :: HasPut e => VerifiedOrd a\n%%                => a -> ISet s a -> Par e s ()\n\n% \\mypara{LVish}\n%% We demonstrate the use of \\toolname{} to ensure guarantees of\n%% deterministic parallel programming. We choose this case study, because, to the\n%% best of our knowledge, there exists no practical deterministic parallel\n%% programming system, including user-defined parallel folds, which does not have\n%% {\\em soundness holes}---due to trusted assumptions of user code.\n\n%% {\\em LVish}\\cite{kuper2014freeze} is a programming library for Haskell, which\n%% exposes effectful parallel programming against lattice-variables (LVars) whose\n%% states change monotonically during parallel regions of program execution. LVish\n%% programs operate on Haskell data types, and LVish requires the operations on\n%% these datatypes to satisfy some first order laws, which cannot be expressed in\n%% Haskell. However, we can leverage \\toolname to verify these properties for\n%% arbitrary user-defined datatypes.\n\n%% LVish provides two implementations of concurrent sets, @PureSet@ and @SLSet@,\n%% where the underlying data structure is a size-balanced binary tree and\n%% concurrent skiplist respectively. The @insert@ operation on a set requires a\n%% total ordering on the elements, we can express that in the type signature by\n%% \\new{The implementation doesn't change, in fact, the}\n%% @VerifiedOrd@ \\new{methods do not even need to exist at runtime. A sufficiently\n%%   smart compiler could optimize away these proof obligations during code\n%%   generation.}\n% \\RN{Let's save the issue of runtime impact for the eval.}\n\nIn summary, parallel programs naturally need to communicate, but the mechanisms\nof that communication---such as folds or inserts into a shared\nstructure---typically carry additional proof obligations.  This in turn makes\nparallelism a liability.  But we can remove the risk with verification.\n\n% But what if we could use verification to remove the risk?\n\n% through contributions to shared structures (otherwise they are really separate\n% programs)\n\n\n\\mypara{Verified typeclasses}\n%\nOur solution is simply to change the @Ord@ constraint above to\n@VerifiedOrd@.\n\\begin{mcode}\n  insert :: VerifiedOrd a => a -> Set s a -> Par s ()\n\\end{mcode}\n%\nThis constraint changes the interface but not the implementation of @insert@.\n%\n% \\NV{Why does insert now requires Verified Ord? Is it using the extra methods\n% in the implementation?}\n%% \\note{VerifiedSemigroup story + lifting + isomorphism (\"bootstrapping\n%%   instances\") + detpar propaganda}\n%\n%% It is an informal requirement when using\n%% typeclasses in GHC that some typeclass laws be satisfied. For example, the @Ord@\n%% typeclass in GHC requires that the $\\leq$ operation be a total order. Using\n%% \\toolname, we can extend it to include the required properties of a total order,\n%% which we call a @VerifiedOrd@.\nThe additional methods of the verified type class don't add operational\ncapabilities, but rather impose additional proof obligations:\n\n\\begin{code}\n  class Ord a => VerifiedOrd a where\n   antisym :: x:a -> y:a -> { x <= y && y <= x => x = y }\n   trans   :: x:a -> y:a -> z:a -> { x <= y && y <= z => x <= z }\n   total   :: x:a -> y:a -> { x <= y || y <= x }\n\\end{code}\n\n% ---------------------------------------------------------------\n% \\mypara{Verified Monoids}\n\nSimilarly, we can extend\nthe @Monoid@ typeclass to a @VerifiedMonoid@, with refinements\nexpressing @Monoid@ laws.\n%\n\\begin{code}\n  class Monoid a => VerifiedMonoid a where\n   lident :: x:a -> { mempty <> x = x }\n   rident :: x:a -> { x <> mempty = x }\n   assoc  :: x:a -> y:a -> z:a -> { x <> (y <> z) = (x <> y) <> z }\n\\end{code}\nThe @VerifiedMonoid@ typeclass constraint requires the binary operation\nto be associative, thus can be safely used to fold on\nan unknown number of processors.\n%% A parallel fold requires the underlying binary operation to be associative and\n%% have a well-behaved identity element, or a @Monoid@.\n\n\n%% We can then extend the @ParFoldable@ typeclass to a @VerifiedParFoldable@ which\n%% enforces a @VerifiedMonoid@ constraint.\n\n%% \\NV{Not sure if the below code adds any information: too difficult to follow,\n%%   especially for non Haskell people} \\NV{I suggest to say similarly to Verified\n%%   Ord and add a link to appendix}\n%%\\RN{I concur with Niki -- we often whitewash away details of the library for\n%%  presentation purposes.  E.g. we are not going to explain effect signatures in\n%%  this paper.}\n\n%% \\begin{code}\n%% class ParFoldable c\n%%    => VerifiedParFoldable c where\n%%   verifiedPmapFold :: forall m e s a .\n%%   ( ParFuture m, HasGet e\n%%   , HasPut e, FutContents m a,\n%%   , VerifiedMonoid a )\n%%   => (ElemOf c -> m e s a) -- compute one\n%%                            -- result\n%%   -> c                     -- element generator\n%%                            -- to consume\n%%   -> m e s a\n%% \\end{code}\n\n\n%%  -------------------------------------------------------------------------\n\n\\mypara{Verified instances for primitive types}\n@VerifiedOrd@ instances for primitive types like @Int@, @Double@ are trivial to\nwrite; they just appeal to the SMT solver's built-in theories.\n%\nFor example, the following is a valid totality proof on @Int@.\n\\begin{code}\n  totInt :: x:Int -> y:Int -> {x <= y || y <= x}\n  totInt _ _ = trivial ** QED\n\\end{code}\n\n\\mypara{Verified instances for algebraic datatypes}\n%\nTo prove the class laws for user defined algebraic datatypes,\nrefinement reflection allows for structurally inductive proof terms.\n%\nFor example, we can inductively define Peano numerals\n%\n\\begin{code}\n  data Peano = Z | S Peano\n\\end{code}\n%\nWe can compare two @Peano@ numbers via\n\\begin{code}\n  reflect leq :: Peano -> Peano -> Bool\n  leq Z _         = True\n  leq (S n) Z     = False\n  leq (S n) (S m) = leq n m\n\\end{code}\n%\nIn \\S~\\ref{sec:refinementreflection:theory} we will describe\nexactly how the reflection mechanism (illustrated\nvia @fibP@) is extended to account for ADTs like @Peano@.\n%\n\\toolname automatically checks\nthat @leq@ is total~\\citep{Vazou14}, which\nlets us safely @reflect@ it into the logic.\n\nNext, we prove that @leq@ is total on @Peano@ numbers\n%\n\\begin{mcode}\n  totalPeano :: n:Peano -> m:Peano -> {leq n m || leq m n} / [toInt n + toInt m]\n  totalPeano Z m = leq Z m ** QED\n  totalPeano n Z = leq Z n ** QED\n  totalPeano (S n) (S m)\n   =  leq (S n) (S m) || leq (S m) (S n)\n   =. leq n m || leq m n\n   =. True $\\because$ totalPeano m n\n   ** QED\n\\end{mcode}\nThe proof goes by induction, splitting cases on\nwhether the number is zero or non-zero. Consequently,\nwe pattern match on the parameters @n@ and @m@, and furnish\nseparate proofs for each case.\n%\nIn the ``zero\" cases, we simply unfold the definition\nof @leq@.\n%\nIn the ``successor\" case, after unfolding we (literally)\napply the induction hypothesis by using the because operator.\n%\nThe termination hint @[toInt n + toInt m]@,\nwhere @toInt@ maps @Peano@ numbers to integers,\nis used to verify well-formedness of the @totalPeano@\nproof term.\n%\n\\toolname's termination and totality checker\nuse the hint to\nverify that we are in fact doing induction\nproperly~(\\S~\\ref{sec:types-reflection}).\n\nSimilarly to @totalPeano@, we can define the rest of the @VerifiedOrd@\nproof methods and use them to create the verified instance.\n%\n\\begin{code}\n  instance Ord Peano where\n    (<=) = leq\n\n  instance VerifiedOrd Peano where\n    total = totalPeano\n\\end{code}\n%\nProving all the four @VerifiedOrd@ laws\nis a burden on the programmer.\n%becomes a burden as the datatype grows more complicated.\n%\nSince @Peano@ is isomorphic to @Nat@s,\nnext we present how\nto reduce the @Peano@ proofs into the\nSMT automated integer proofs.\n\n\\mypara{Isomorphisms}\n%\nIn order to reuse proofs for a custom datatype,\nwe provide a way to translate verified instances between isomorphic types~\\cite{barthe2001type}.\n%% If our datatype is isomorphic to a nesting of binary sums and products, we\n%% should be able to reusing existing proofs.\n%% To verify operations on custom data types efficiently, we\n%% need to be able lift verified instances on one type to another.\n%\nWe design a typeclass @Iso@ which witnesses the fact that\ntwo types are isomorphic.\n%, with respect to the built-in equality in \\toolname{}\n%which is a congruence.\n\n\\begin{mcode}\n  class Iso a b where\n    to      :: a -> b\n    from    :: b -> a\n    to$\\circ$from :: x:a -> {to (from x) = x}\n    from$\\circ$to :: x:a -> {from (to x) = x}\n\\end{mcode}\n%\nFor two isomorphic types @a@ and @b@\nwe compare instances of @b@ using @a@'s\ncomparison method.\n%\n\\begin{mcode}\n  instance (Ord a, Iso a b) => Ord b where\n    x <= y = from x <= from y\n\\end{mcode}\n%\nThen, we prove that @VerifiedOrd@ laws are closed under isomorphisms.\n%\nFor example, we prove totality of comparison on @b@s\nusing the @VerifiedOrd@ totality on @a@s\n\n\\begin{mcode}\n  isoTotal :: (VerifiedOrd a, Iso a b) => x:b -> y:b -> {x <= y || y <= x}\n  isoTotal x y\n   =  x <= y || y <= x\n   =. (from x) <= (from y) || (from y) <= (from x)\n      $\\because$ total (from x) (from y)\n   ** QED\n\\end{mcode}\n%\nWe use @isoTotal@ to create a verified instance on @b@s.\n\\begin{mcode}\n  instance (VerifiedOrd a, Iso a b) => VerifiedOrd b where\n    total   = isoTotal\n\\end{mcode}\n%\nWith the above technique,\nand using Haskell's instances,\ngetting a @VerifiedOrd@ instance for @Peano@\nreduces to definition of an @Iso Nat Peano@.\n%\\VC{Iso (Either () Peano) Peano}\n\n\\mypara{Proof Composition via Products}\nFinally, we present a mechanism to automatically\nreduce proofs on product types to proofs of the product components.\n%\nFor example, lexicographic ordering preserves the ordering laws.\n%\nFirst, we use class instances to define lexicographic ordering.\n%\n\\begin{mcode}\n  instance (VerifiedOrd a, VerifiedOrd b) => Ord (a, b) where\n    (x1, y1) <= (x2, y2) = if x1 == x2 then y1 <= y2 else x1 <= x2\n\\end{mcode}\n%\nThen, we prove that lexicographic ordering\npreserves the ordering laws.\n%\nFor example, it preserves totality.\n%\n\\begin{mcode}\n  prodTotal :: (VerifiedOrd a, VerifiedOrd b)\n            => p:(a, b) -> q:(a, b) -> {p <= q || q <= p}\n  prodTotal p@(x1, y1) q@(x2, y2)\n   =  p <= q || q <= p\n   =. if x1 == x2 then (y1 <= y2 || y2 <= y1) else True \n      $\\because$ total x1 x2\n   =. if x1 == x2 then True                   else True \n      $\\because$ total y1 y2\n   ** QED\n\\end{mcode}\n%\nFinally, using the @prodTotal@ proof method,\nwe conclude that each instance defined via the lexicographic\nordering is indeed a verified instance.\n%\n\\begin{mcode}\n  instance (VerifiedOrd a, VerifiedOrd b) => VerifiedOrd (a, b) where\n    total   = prodTotal\n\\end{mcode}\n%\nFor example the type @(Peano, Peano)@ is derived to be a @VerifiedOrd@ instance.\n\nIn short, we can decompose an algebraic datatype into an isomorphic type using sums and\nproducts to generate verified instances for arbitrary Haskell\ndatatypes. This could be combined with the Glasgow Haskell Compiler's (GHC) support\nfor generics~\\cite{ghc-generics} to automate the derivation of verified instances\nfor user datatypes.\nIn \\S\\ref{sec:eval-parallelism}, we use these ideas to develop fully safe\ninterfaces to LVish modules, as well as verifying programming patterns from DPJ.\n", "meta": {"hexsha": "b948cc5596a17d19698d58aa0f8ae7b681e39fc0", "size": 27075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/refinementreflection/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/refinementreflection/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/refinementreflection/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": 31.6296728972, "max_line_length": 96, "alphanum_fraction": 0.6970267775, "num_tokens": 7824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.6626268693622567}}
{"text": "\\chapter{Interlude: Cauchy's functional equation and Zorn's lemma}\n\\label{ch:zorn}\n\\emph{This is an informal chapter on Zorn's lemma,\nwhich will give an overview of what's going to come in the last parts of the Napkin.\nIt can be omitted without loss of continuity.}\n\n\\medskip\n\nIn the world of olympiad math, there's a famous functional equation that goes as follows: \n\\[ f : \\RR \\to \\RR \\qquad f(x+y) = f(x) + f(y). \\]\nEveryone knows what its solutions are!\nThere's an obvious family of solutions $f(x) = cx$.\nThen there's also this family of\\dots\\ uh\\dots\\ noncontinuous solutions (mumble grumble) pathological \n(mumble mumble) Axiom of Choice (grumble).\n\nThere's also this thing called Zorn's lemma. It sounds terrifying,\nbecause it's equivalent to the Axiom of Choice, which is also terrifying because why not.\n\nIn this post I will try to de-terrify these things,\nbecause they're really as terrifying as they sound.\n\n\\section{Let's construct a monster}\nLet us just see if we can try and construct a ``bad'' $f$ and see what happens.\n\nBy scaling, let's assume WLOG that $f(1) = 1$.\nThus $f(n) = n$ for every integer $n$, and you can easily show from here that\n\\[ f\\left( \\frac mn \\right) = \\frac mn. \\]\nSo $f$ is determined for all rationals. And then you get stuck.\n\nNone of this is useful for determining, say, $f(\\sqrt 2)$.\nYou could add and subtract rational numbers all day\nand, say, $\\sqrt 2$ isn't going to show up at all.\n\nWell, we're trying to set things on fire anyways, so let's set\n\\[ f(\\sqrt 2) = 2015 \\]\nbecause why not?\nBy the same induction, we get $f(n\\sqrt2) = 2015n$, and then that\n\\[ f\\left( a + b \\sqrt 2 \\right) = a + 2015b. \\]\nHere $a$ and $b$ are rationals.\nWell, so far so good -- as written, this is a perfectly good solution,\nother than the fact that we've only defined $f$ on a tiny portion of the real numbers.\n\nWell, we can do this all day:\n\\[ f\\left( a + b \\sqrt 2 + c \\sqrt 3 + d \\pi \\right) = a + 2015b + 1337c - 999d. \\]\nPerfectly consistent.\n\nYou can kind of see how we should keep going now.\nJust keep throwing in new real numbers which are ``independent''\nto the previous few, assigning them to whatever junk we want.\nIt feels like it \\emph{should} be workable. . .\n\nIn a moment I'll explain what ``independent'' means (though you\nmight be able to guess already), but at the moment there's a bigger issue:\nno matter how many numbers we throw, it seems like we'll never finish.\nLet's address the second issue first.\n\n\\section{Review of finite induction}\nWhen you do induction, you get to count off $1$, $2$, $3$, \\dots and so on.\nSo for example, suppose we had a ``problem'' such as:\n\\begin{quote}\n\tProve that the intersection of $n$ open intervals is either $\\varnothing$\n\tor an open interval.\n\\end{quote}\nYou can do this by induction easily: it's true for $n = 2$, and\nfor the larger cases it's similarly easy.\n\nBut you can't conclude from this that \\emph{infinitely} many open intervals intersect\nat some open interval. Indeed, this is false: consider the intervals\n\\[\n\t\\left( -1, 1 \\right), \\quad\n\t\\left( -\\frac12, \\frac12 \\right), \\quad\n\t\\left( -\\frac13, \\frac13 \\right), \\quad\n\t\\left( -\\frac14, \\frac14 \\right), \\quad\n\t\\dots\n\\]\nThis \\emph{infinite} set of intervals intersects at a single point $\\{0\\}$!\n\nThe moral of the story is that induction doesn't let us reach infinity.\nToo bad, because we'd have loved to use induction to help us construct a monster.\nThat's what we're doing, after all -- adding things in one by one.\n\n\\section{Transfinite induction}\nWell, it turns out we can, but we need a new notion of number,\nthe so-called \\emph{ordinal number}.\nI define these in their full glory in the first two sections of \\Cref{ch:ordinal}\n(and curious readers are even invited to jump ahead to those two sections),\nbut for this chapter I won't need that full definition yet.\n\nHere's what I want to say: after all the natural numbers\n\\[ 0, \\; 1, \\; \\dots, \\]\nI'll put a \\emph{new number} called $\\omega$,\nthe first ordinal greater than all the natural numbers.\nAfter that there's more numbers called\n\\[\\omega+1, \\; \\omega+2, \\; \\dots \\]\nand eventually a number called $2\\omega$.\n\nThe list goes on:\n\\[\n\\begin{aligned}\n\t0, & 1, 2, 3, \\dots, \\omega \\\\\n\t& \\omega+1, \\omega+2, \\dots, \\omega+\\omega \\\\\n\t& 2\\omega+1, 2\\omega+2, \\dots, 3\\omega \\\\\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\\dots, \\omega^{\\omega^{\\omega^{\\dots}}} \\\\\n\\end{aligned}\n\\]\nPictorially, it kind of looks like this:\n\\begin{center}\n\t\\includegraphics[scale=0.70]{media/500px-Omega-exp-omega-labeled.png}\n\t\\\\ \\scriptsize Image from \\cite{img:omega500}\n\\end{center}\n(Note that the diagram only shows an initial segment;\nthere are still larger ordinals like $\\omega^{\\omega^{\\omega}}+1000$ and so on).\n\nAnyways, in the same way that natural numbers ``dominate'' all finite sets,\nthe ordinals dominate \\emph{all the sets}, in the following sense.\nEssentially, assuming the Axiom of Choice,\nit follows that for every set $S$ there's some ordinal $\\alpha$\nwhich is larger than $S$ (in a sense I won't make precise until later chapters).\n\nBut it turns out (and you can intuitively see) that as large as the ordinals grow,\nthere is no \\emph{infinite descending chain}.\nMeaning: if I start at an ordinal (like $2 \\omega + 4$) and jump down, I can only\ntake finitely many jumps before I hit $0$.\n(To see this, try writing down a chain starting at $2 \\omega + 4$ yourself.)\nHence, 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(\\beta)$ is true.\n\\end{theorem}\nSimilarly, you're allowed to do recursion to define $x_\\beta$ if you know the\nvalue of $x_\\alpha$ for all $\\alpha < \\beta$.\n\nThe difference from normal induction or recursion is that we'll often\nonly do things like ``define $x_{n+1} = \\dots$''.\nBut this is not enough to define $x_\\alpha$ for all $\\alpha$.\nTo see this, try using our normal induction and see how far we can climb up the ladder.\n\nAnswer: you can't get $\\omega$!\nIt's not of the form $n+1$ for any of our natural numbers $n$ -- our finite induction only lets us\nget up to the ordinals less than $\\omega$.\nSimilarly, the simple $+1$ doesn't let us hit the ordinal $2\\omega$,\neven if we already have $\\omega+n$ for all $n$.\nSuch ordinals are called \\vocab{limit ordinals}.\nThe ordinal that \\emph{are} of the form $\\alpha+1$ are called \\vocab{successor ordinals}.\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) Show that $P(\\lambda)$ holds given $P(\\alpha)$ for all $\\alpha < \\lambda$,\n\twhere $\\lambda$ is a limit ordinal.\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 far above the barrier $\\omega$.\n\n\\section{Wrapping up functional equations}\nLet's return to solving our problem.\n\nLet $S_n$ denote the set of ``base'' numbers we have at the $n$th step.\nIn our example, we might have\n\\[\n\tS_1 = \\left\\{ 1 \\right\\}, \\quad\n\tS_2 = \\left\\{ 1, \\sqrt 2 \\right\\}, \\quad\n\tS_3 = \\left\\{ 1, \\sqrt 2, \\sqrt 3 \\right\\}, \\quad\n\tS_4 = \\left\\{ 1, \\sqrt 2, \\sqrt 3, \\pi \\right\\}, \\quad\n\t\\dots\n\\]\nand we'd like to keep building up $S_i$ until we can express all real numbers.\nFor completeness, let me declare $S_0 = \\varnothing$.\n\nFirst, I need to be more precise about ``independent''.\nIntuitively, this construction is working because\n\\[ a + b \\sqrt 2 + c \\sqrt 3 + d \\pi \\]\nis never going to equal zero for rational numbers $a$, $b$, $c$, $d$ (other than all zeros).\nIn general, a set $X$ of numbers is ``independent'' if the combination\n\\[ c_1 x_1 + c_2 x_2 + \\dots + c_m x_m = 0 \\]\nnever occurs for rational numbers $\\QQ$ unless $c_1 = c_2 = \\dots = c_m = 0$.\nHere $x_i \\in X$ are distinct. Note that even if $X$ is infinite,\nI can only take finite sums!\n(This notion has a name: we want $X$ to be \\textbf{linearly independent} over $\\QQ$;\nsee the chapter on vector spaces for more on this!)\n\nWhen do we stop?\nWe'd like to stop when we have a set $S_{\\text{something}}$ that's so big,\nevery real number can be written in terms of the independent numbers.\n(This notion also has a name: it's called a $\\QQ$-basis.)\nLet's call such a set \\textbf{spanning};\nwe stop once we hit a spanning set.\n\nThe idea that we can induct still seems okay:\nsuppose $S_\\alpha$ isn't spanning.\nThen there's some number that is independent of $S_\\alpha$, say $\\sqrt{2015}\\pi$ or something.\nThen we just add it to get $S_{\\alpha+1}$.\nAnd we keep going.\n\nUnfortunately, as I said before it's not enough to be able to go from $S_\\alpha$ to $S_{\\alpha+1}$\n(successor case); we need to handle the limit case as well.\nBut it turns out there's a trick we can do.\nSuppose we've constructed \\emph{all} the sets $S_0$, $S_1$, $S_2$, \\dots, one for each positive integer $n$,\nand none of them are spanning.\nThe next thing I want to construct is $S_\\omega$; somehow I have to ``jump''.\nTo do this, I now take the infinite union\n\\[ S_\\omega \\overset{\\text{def}}{=} S_0 \\cup S_1 \\cup S_2 \\cup \\dots. \\]\nThe elements of this set are also independent (why?).\n\nTa-da!\nWith the simple trick of ``union all the existing sets'',\nwe've just jumped the hurdle to the first limit ordinal $\\omega$.\nThen we can construct $S_{\\omega+1}$, $S_{\\omega+2}$, \\dots, once again --\njust keep throwing in elements.\nThen when we need to jump the next hurdle to $S_{2 \\omega}$,\nwe just do the same trick of ``union-ing'' all the previous sets.\n\nSo we can formalize the process as follows:\n\\begin{enumerate}\n\t\\ii Let $S_0 = \\varnothing$.\n\t\\ii For a successor stage $S_{\\alpha+1}$, add any element to $S_\\alpha$ to obtain $S_{\\alpha+1}$.\n\t\\ii For a limit stage $S_{\\lambda}$, take the union $\\bigcup_{\\gamma < \\lambda} S_\\gamma$.\n\\end{enumerate}\nHow do we know that we'll stop eventually?\nWell, the thing is that this process consumes a lot of real numbers.\nIn particular, the ordinals get larger than the size of $\\RR$ (assuming Choice).\nHence if we don't stop we will quite literally reach a point where we have used up every single real number.\nClearly that's impossible, because by then the elements can't possibly be independent!\n\nSo by transfinite recursion, we eventually hit some $S_\\gamma$ which is spanning:\nthe elements are all independent, but every real number can be expressed using it.\nDone!\n\n\\section{Zorn's lemma}\nNow I can tell you what Zorn's lemma is:\nit lets us do the same thing in any poset.\n\nWe can think of the above example as follows:\nconsider all sets of independent elements.\nThese form a partially ordered set by inclusion, and what we did\nwas quite literally climb up a chain\n\\[ S_0 \\subsetneq S_1 \\subsetneq S_2 \\subsetneq \\dots. \\]\nIt's not quite climbing since we weren't just going one step at a time:\nwe had to do ``jumps'' to get up to $S_\\omega$ and resume climbing.\nBut the main idea is to climb up a poset until we're at the very top;\nin the previous case, when we reached the spanning set.\n\nThe same thing works verbatim with any \\href{http://en.wikipedia.org/wiki/Partially_ordered_set}{partially ordered set}\n$\\mathcal P$.\nLet's define some terminology.\nA \\vocab{local maximum} of the entire poset $\\mathcal P$ is an element\nwhich has no other elements strictly greater than it.\n(Most authors refer to this as ``maximal element'', but I think\n``local maximum'' is a more accurate term.)\n\nNow a \\vocab{chain of length $\\gamma$} is a set of elements $p_\\alpha$ for every $\\alpha < \\gamma$\nsuch that $p_0 < p_1 < p_2 < \\dots$.\n(Observe that a chain has a last element if and only if $\\gamma$ is a successor ordinal, like $\\omega+3$.)\nAn \\vocab{upper bound} to a chain is an element $\\tilde p$ which is greater than or equal\nto all elements of the chain;\nIn particular, if $\\gamma$ is a successor ordinal, then just taking the last element of the chain works.\n\nIn this language, Zorn's lemma states that\n\\begin{theorem}\n\t[Zorn's lemma]\n\tLet $\\mathcal P$ be a nonempty partially ordered set.\n\tIf every chain has an upper bound,\n\tthen $\\mathcal P$ has a local maximum.\n\\end{theorem}\n\nChains with length equal to a successor ordinal always have upper bounds,\nbut this is not true in the limit case.\nSo the hypothesis of Zorn's lemma is exactly what\nlets us ``jump'' up to define $p_\\omega$ and other limit ordinals.\nAnd the proof of Zorn's lemma is straightforward: keep climbing up the poset at successor stages,\nusing Zorn's condition to jump up at limit stages, and thus building a really long chain.\nBut we have to eventually stop, or we literally run out of elements of $\\mathcal P$.\nAnd the only possible stopping point is a local maximum.\n\nIf we want to phrase our previous solution in terms of Zorn's lemma, we'd say:\n\\begin{proof}\n\tLook at the poset whose elements are sets of independent real numbers.\n\tEvery chain $S_0 \\subsetneq S_1 \\subsetneq \\dots$ has an upper bound $\\bigcup S_\\alpha$\n\t(which you have to check is actually an element of the poset).\n\tThus by Zorn, there is a local maximum $S$.\n\tThen $S$ must be spanning, because otherwise we could add an element to it.\n\\end{proof}\nSo really, Zorn's lemma is encoding all of the work of climbing that I argued earlier.\nIt's a neat little package that captures all the boilerplate, and tells\nyou exactly what you need to check.\n\n\\begin{center}\n\t\\includegraphics[scale=0.5]{media/zornaholic.png}\n\t\\\\ \\scriptsize Image from \\cite{img:zornaholic}\n\\end{center}\n\nOne last thing you might ask:\nwhere is the Axiom of Choice used?\nWell, the idea is that for any chain there could be lots of $\\tilde p$'s,\nand you need to pick one of them.\nSince you are making arbitrary choices infinitely many times, you need the Axiom of Choice.\n(Actually, you also need choice to talk about cardinalities as in theorem 1.)\nBut really, it's nothing special.\n\n\\section{\\problemhead}\n\\begin{problem}\n\t[Tukey's lemma]\n\tLet $\\mathcal F$ be a nonempty family of sets.\n\tAssume that for any set $A$,\n\tthe set $A$ is in $\\mathcal F$\n\tif and only if all its finite subsets are in $\\mathcal F$.\n\tProve that there exists $Y \\in \\mathcal F$\n\tsuch that $X \\subseteq Y$ for every $X \\in \\mathcal F$.\n\\end{problem}\n", "meta": {"hexsha": "e43f8d344f1d6ca6416fa1ac8331bbea8398351e", "size": 14749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/set-theory/zorn-lemma.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/zorn-lemma.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/zorn-lemma.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": 45.1039755352, "max_line_length": 119, "alphanum_fraction": 0.7221506543, "num_tokens": 4244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6626268620171221}}
{"text": "\\chapter{Universal Functions}\nIt is known that we may write a program that gets another program as an argument\nand run it. (Such programs are known as interpreters.) To use this observation\nwe give the following definition and theorem.\n\\begin{definition}\n  We say that a function $U$ is a \\emph{universal function} (for the set of\n  univariate computable functions) iff for each $n \\in \\N$,\n  \\[\n    U_n : x \\mapsto U(n, x)\n  \\]\n  (we say that $U_n$ is a section of $U$)\n  is computable and any univariate computable function is among $U_n$'s.\n\\end{definition}\n\n\\begin{theorem}\n\\label{theorem:universal-function-computable}\n  There is a computable universal function $U$.\n\\end{theorem}\n\n\\begin{exercise}\n  Assume that every section of a function $U$ is computable.\n  Is it necessarily true that $U$ is computable?\n\\end{exercise}\n\nSimilarly to the notion of universal function we may define the notion\nof universal sets.\n\\begin{definition}\n  Let $F \\subseteq 2^\\N$. We say that $W \\subseteq \\N^2$ is universal for $F$\n  if $W_n = \\set[(n, x) \\in F]{x \\in \\N}$ is an element of $F$ for all\n  $n \\in \\N$ and any set $S \\in F$ is among $W_n$'s.\n\\end{definition}\n\n\\begin{theorem}\n\\label{theorem:universal-set-enumerable}\n  There is an enumerable set $W$ such that it is universal for the set of\n  all enumerable subsets of $\\N$.\n\\end{theorem}\n\n\\section{Enumerable but Not Decidable Set}\n\\begin{theorem}\n\\label{theorem:enumerable-not-decidable}\n  There is a set $S \\subseteq \\N$ such that $S$ is enumerable but it is not\n  decidable.\n\\end{theorem}\n\\begin{proof}\n  Let $U$ be be a universal computable function, it exists by\n  \\Cref{theorem:universal-function-computable}.\n  To prove the statement we are going to use the diagonalization method.\n  Let us consider $S = \\set[U(n, n) = 0]{n \\in \\N}$.\n\n  It is easy to see that $S$ is enumerable. Assume for the sake of\n  contradiction that $S$ is decidable. Let $\\Algorithm{A}$ be the algorithm\n  deciding $S$. There is $n \\in \\N$ such that $\\Algorithm{A}$ computes $U_n$\n  since $U$ is universal. Let us now consider two following cases.\n  \\begin{enumerate}\n    \\item Assume that $n \\in S$. In this case $\\Algorithm{A}(n) = 1$ since\n      $\\Algorithm{A}$ decides $S$. However, $U_n(n) \\neq 1$ by the definition of\n      $S$. These two equalities together leads us to a contradiction since\n      $\\Algorithm{A}$ computes $U_n$.\n    \\item Assume that $n \\notin S$. In this case $\\Algorithm{A}(n) = 0$ since\n      $\\Algorithm{A}$ decides $S$. However, $U_n(n) = 1$ by the definition of\n      $S$. These two equalities together leads us to a contradiction since\n      $\\Algorithm{A}$ computes $U_n$.\n  \\end{enumerate}\n\\end{proof}\n\nUsing the proof of this result we can prove the following surprising\nobservation.\n\\begin{theorem}\n\\label{theorem:halting}\n  Let $U$ be a universal function.\n  Let $\\Halting : \\N^2 \\to \\set{0, 1}$ be the function such that\n  $\\Halting(n, x) = 1$ iff $U_n(x)$ is defined. Then $\\Halting$ is not\n  computable.\n\\end{theorem}\nInformally, this theorem says that it is impossible to check whether a given\nalgorithm terminates or not on some input.\n\n\n\\section{Diagonalization Method}\nThis section will give several other applications of the diagonalization method.\n\nIn the previous section we constructed a computable universal function for\nthe set of computable functions of one variable. Now we can prove that\nit is impossible for total functions.\n\\begin{theorem}\n    There is no computable universal total function for\n    the set of computable total functions of one variable.\n\\end{theorem}\n\\begin{proof}\n  Assume that such a function $U$ exists. Let us consider the total computable\n  function $d : \\N \\to \\N$ such that $d(n) = U(n, n) + 1$. Since $U$ is a\n  computable universal total function for the set of computable total functions\n  of one variable, there is $m \\in \\N$ such that $d(n) = U(m, n)$ for any\n  $n \\in \\N$. Note that this implies that $U(m, m) = d(m) = U(m, m) + 1$,\n  which is a contradiction.\n\\end{proof}\nNote that the crucial point in this argument is that $U(m, m)$ is different\nfrom $U(m, m) + 1$; however, if the functions are not total it is possible\nthat $U(m, m)$ is simply not defined. However, a part of the argument can be\nused, nonetheless.\n\\begin{theorem}\n\\label{theorem:intersecting-function}\n    There is a computable function $f : \\N \\to \\N$ such that\n    no computable function $g : \\N \\to \\N$ can differ from $f$\n    everywhere; i.e., for any computable function $g : \\N \\to \\N$\n    there is $n \\in \\N$ such that $f(n) = g(n)$.\n    (The last equality says that the values are either equal or\n    both values are not defined for $n$.)\n\\end{theorem}\n\\begin{proof}\n  Let $U$ be a universal function for computable functions, and\n  let $d : \\N \\to \\N$ be a partial function such that $d(n) = U(n, n)$.\n  It is clear that $d$ satisfies the statement of the theorem. Indeed,\n  any computable function $f$ is equal to $U_n$  for some $n$. Hence,\n  $d(n) = U(n, n) = f(n)$.\n\\end{proof}\n\n\\begin{theorem}\n    There is a computable function that does not admit a total computable\n    extension.\n\\end{theorem}\n\\begin{proof}\n  Let $d$ be the function from the previous theorem. Let us consider the\n  partial function $e : \\N \\to \\N$ such that $e(n) = d(n) + 1$.\n  We wish to prove that $e$ does not have a total extension. Let us assume\n  the opposite, let $e'$ be a computable total extension of $e$. Then $e'$\n  differs from $d$ everywhere, therefore $e'$ is not computable.\n\\end{proof}\n\nNote that the last theorem gives another proof of\n\\Cref{theorem:enumerable-not-decidable}. Indeed, let $f$ be the function\nwithout total computable extension. Let $S = \\Im{f}$.\nBy \\Cref{theorem:enumerable-via-computable-funcitons},\n$S$ is enumerable. Assume for the sake of contradiction, that $S$ is decidable.\nThen the total function $g : \\N \\to \\N$ such that\n\\[\n    g(x) =\n    \\begin{cases}\n        f(x) & \\text{if } x \\in S \\\\\n        0 & \\text{if } x \\notin S\n    \\end{cases}\n\\]\nis computable. Moreover, $g$ is an extension of $f$ which leads to a\ncontradiction.\n\n\\begin{chapterendexercises}\n    \\exercise Let $U \\subseteq \\N^2$ be any enumerable set of pairs of\n        natural numbers that is universal for the set of all\n        enumerable sets of natural numbers.\n        Prove that its ``diagonal section''\n        $K = \\set[(x, x) \\in U]{x}$ is an enumerable undecidable set.\n    \\exercise Let $S \\subseteq \\N$ be decidable and let\n        \\[\n            D =\n            \\set[\n                p \\text{ is prime and }\n                p \\text{ divides some } n \\in S\n            ]{p \\in \\N}.\n        \\]\n        Is the set $D$ always decidable?\n    \\exercise Show that there exist countably many disjoint\n        enumerable sets such that any two of them are inseparable\n        (cannot be separated by a decidable set).\n\\end{chapterendexercises}\n", "meta": {"hexsha": "10b5fcc8048699f7056394d533f69bf34a08fadc", "size": 6835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_9/chapter_36_universal_functions.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_9/chapter_36_universal_functions.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_9/chapter_36_universal_functions.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.1746987952, "max_line_length": 80, "alphanum_fraction": 0.6866130212, "num_tokens": 1984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6626268582744937}}
{"text": "\\documentclass[%\n %twocolumn,\n %preprint,\n onecolumn,\n amsmath, amssymb, aps, pra, 10pt\n]{revtex4-2}\n\\usepackage{amsmath}\n\\usepackage{appendix}\n\\usepackage[colorlinks,citecolor=blue,urlcolor=black,bookmarks=false,hypertexnames=true]{hyperref} \n\\begin{document}\n\\title{Unifying Variable Order Fractional Derivatives}% Force line breaks with \\\n\\author{Luke A. Siemens}\n\\email{luke.siemens@lsiemens.com}\n\\noaffiliation\n\\date{\\today}\n\\maketitle\n\nI have found a generalized definition of variable order fractional derivatives. I will show that this definition applies to any variable order fractional derivative provided it maps analytic functions to analytic functions and that they are analytic with respect to the order of differentiation. I will make the simplifying assumptions that the functions are analytic, that the domain of the functions is either $\\mathbb{C}$ or $\\mathbb{C} \\times \\mathbb{C}$, that they are analytic in the neighborhood of the origin and that they are analytic almost everywhere (in a measure theory sense). Denote the set of all analytic functions on the domain $\\mathbb{C} \\times \\mathbb{C}$ as $\\mathcal{O}(\\mathbb{C}^2)$. Let us define a function space $\\mathbb{S}$ as the set,\n\\begin{equation}\n\\mathbb{S} = \\left\\lbrace f(x, a) \\in \\mathcal{O}(\\mathbb{C}^2) \\middle| \\partial_x f(x, a) = f(x, a - 1) \\right\\rbrace\n\\label{differentiable_set}\n\\end{equation}\nand define the fractional integral operator $J^{\\alpha}$ acting on elements of the set $\\mathbb{S}$ as,\n\\begin{equation}\nJ^{\\alpha} f(x, a) = T_{a}^{\\alpha} f(x, a) = f(x, a + \\alpha)\n\\label{fractional_derivative}\n\\end{equation}\nwhere $T_{a}^{\\alpha}$ is an operator shifting the variable $a$ by the amount $\\alpha$. Note that if $f(x, a) \\in \\mathbb{S}$ then $J^{\\alpha} f(x, a) \\in \\mathbb{S}$. I will now show that this operator, when acting on functions in the function space $\\mathbb{S}$, satisfies the necessary properties to be considered a variable order fractional derivative, and it is equivalent to any sufficiently analytic variable order fractional derivative on some subspace of $\\mathbb{S}$.\nI will use the criterion, $\\,^3P$, given in your paper, \\textit{What is a fractional derivative} \\cite{ORTIGUEIRA20154}, to determine if the operator \\eqref{fractional_derivative} is a fractional derivative when acting on functions in the set \\eqref{differentiable_set}. In the following arguments let us assume that $f(x, a), g(x, a) \\in \\mathbb{S}$ and $C_1, C_2, \\alpha, \\beta \\in \\mathbb{C}$.\n\n\\subsection*{$\\,^3P1$ : Linearity}\nSince the shift operator $T_{a}^{\\alpha}$ is a linear operator, then the operator $J^{\\alpha}$ is also a linear operator.\n\n\\subsection*{$\\,^3P2$ : Identity}\nUsing the definition of $J^{\\alpha}$ for $\\alpha=0$ acting on $f(x, a)$ results in, $J^{0}f(x, a) = T_{a}^{0}f(x, a) = f(x, a)$. So the property $\\,^3P2$ is satisfied.\n\n\\subsection*{$\\,^3P3$ : Backwards compatibility}\nTaking the fractional integral, $J^{\\alpha} f(x, a)$, for $\\alpha \\in\\ \\mathbb{Z}$. In the case where $\\alpha$ is a negative integer we can apply $\\partial_x f(x, a) = f(x, a - 1)$ repeatedly, let $\\alpha = -k$ with $k \\in \\mathbb{Z}^+$,\n$$J^{-k} f(x, a) = T_{a}^{-k} f(x, a)=T_{a}^{-k + 1}T_{a}^{-1} f(x, a) = T_{a}^{-k + 1}f(x, a - 1) = T_{a}^{-k + 1}\\partial_x f(x, a)$$\nSince $\\partial_x f(x, a) \\in \\mathbb{S}$ we can repeat this argument, resulting in\n$$J^{-k} f(x, a) = \\partial_{x}^{k} f(x, a)$$\nFor the positive case first let us try $k=1$. In this case $J^{1} f(x, a) = f(x, a + 1)$, so $\\partial_x f(x, a + 1) = f(x, a)$ leading to the solution $J^{1} f(x, a) = \\int_{x_0}^{x} f(t, a)dt + f(x_0, a + 1)$. Provided that $f(x, a)$ is an entire function for all $a$, then applying this repeatedly produces\n$$J^{k} f(x, a) = \\frac{1}{\\Gamma(k)}\\int_{x_0}^{x} (x - t)^{k - 1}f(t, a)dt + \\sum_{i = 0}^{k - 1}f(x_0, a + k - i)\\frac{(x - x_0)^i}{i!}$$\nSo if $\\alpha \\in \\mathbb{Z}$, then $J^{\\alpha}$ represents either repeated integration or differentiation.\n\n\\subsection*{$\\,^3P4$ : Index law}\nApplying the fractional integral twice and simplifying yields\n$$J^{\\beta}J^{\\alpha} f(x, a) = T{a}^{\\beta}T_{a}^{\\alpha} f(x, a) = T_{a}^{\\beta} f(x, a + \\alpha) = f(x, a + \\alpha + \\beta) = J^{\\beta + \\alpha} f(x, a)$$\nSo the index law is satisfied.\n\n\\section*{Implications of $\\,^3P1 - \\,^3P4$ for $J^{\\alpha}$}\nThe criterion $\\,^3P1 - \\,^3P4$ are satisfied, but before addressing criterion $\\,^3P5$ I show that any sufficiently analytic variable order fractional derivative is equivalent to the operator \\eqref{fractional_derivative} acting on some subspace of the set $\\mathbb{S}$. Note I will use the fractional integral derived from the variable order fractional derivative. Now let $J'^{\\alpha}$ be an arbitrary variable order fractional derivative that satisfies $\\,^3P1 - \\,^3P4$, and that there exists a set $\\mathbb{S}''$ of analytic functions on which the operator $J'^{\\alpha}$ satisfies $\\,^3P1 - \\,^3P4$ and where $\\forall F(x) \\in \\mathbb{S}'', J'^{\\alpha}F(x) \\in \\mathcal{O}(\\mathbb{C}^2)$. The action of $J'^{\\alpha}$ acting on $F(x) \\in \\mathbb{S}''$ can be expressed as $f(x, a) = J'^{\\alpha} F(x)$. Using this let\n$$\\mathbb{S}' = \\left\\lbrace f(x, a) \\in \\mathcal{O}(\\mathbb{C}^2) \\middle| \\exists F(x) \\in \\mathbb{S}'', f(x, a) = J'^{\\alpha} F(x) \\right\\rbrace$$\nGiven $f(x, a) \\in \\mathbb{S}'$ then $J'^{-1}f(x, a) = \\partial_x f(x, a)$ by $\\,^3P3$ and $J'^{-1} f(x, a) = J'^{-1}J'^{\\alpha} F(x) = J'^{\\alpha - 1} F(x) = f(x, \\alpha - 1)$ by $\\,^3P4$, so\n$$\\forall f(x, a) \\in \\mathbb{S}', \\partial_x f(x, a) = f(x, a - 1) \\therefore \\mathbb{S}' \\subseteq \\mathbb{S}$$\nGiven $f(x, a) \\in \\mathbb{S}'$ then taking a fractional integral and using $\\,^3P4$ results in $J'^{\\alpha} f(x, a) = J'^{\\alpha}J'^{a} F(x) = J'^{\\alpha + a} F(x) = f(x, a + \\alpha) = T_{a}^{\\alpha} f(x, a)$, so\n$$J'^{\\alpha} f(x,a) = T_{a}^{\\alpha} f(x, a) = J^{\\alpha} f(x, a)$$\nWe have shown that $\\mathbb{S}' \\subseteq \\mathbb{S}$ and that $\\forall f(x, a) \\in \\mathbb{S}', J'^{\\alpha} f(x, a) = J^{\\alpha} f(x, a)$. So every variable order fractional derivative which is sufficiently analytic is equivalent to $J^{\\alpha}$ acting on some subspace of $\\mathbb{S}$. The fractional integral defined in \\eqref{fractional_derivative} when acting on functions in the space \\eqref{differentiable_set} provides a general description of all sufficiently analytic variable order fractional derivatives subject to $\\,^3P1 - \\,^3P4$.\n\nUp until this point I have used the equation $\\partial_x f(x, a) = f(x, a - 1)$ to determine if a function is in the set $\\mathbb{S}$ but have not considered whether or not this equation holds on the entire domain of $f(x, a)$ or only on some subset. Given $f(x, a) \\in \\mathcal{O}(\\mathbb{C}^2)$ we can define $g(x, a) = \\partial_x f(x, a) - f(x, a - 1)$. Note that if $f(x, a) \\in \\mathcal{O}(\\mathbb{C}^2)$ then $g(x, a) \\in \\mathcal{O}(\\mathbb{C}^2)$ and that at every point in the domain $\\partial_x f(x, a) = f(x, a - 1) \\iff g(x, a) = 0$. Since $g(x, a)$ is a complex analytic function it can be analytically continued and its continuation is either zero everywhere, or it is zero almost nowhere on the domain of the analytic continuation. Therefore $\\partial_x f(x, a) = f(x, a - 1)$ must either be satisfied on the entire domain of $f(x, a)$, or satisfied almost nowhere since $f(x, a)$ is complex analytic.\n\n\\subsection*{$\\,^3P5$ : Generalized Leibniz rule}\nSo far I have not found a consistent way to define multiplication in general. If $f(x, a), g(x, a) \\in \\mathbb{S}$ and $h(x, a) = f(x, a) \\cdot g(x, a)$ then $\\partial_x h(x, a) = f(x, a - 1) \\cdot g(x, a) + f(x, a) \\cdot g(x, a - 1) \\neq h(x, a - 1)$, unless either $f(x, a)$ or $g(x, a)$ is a constant function. So if multiplication by non-constant functions is possible then the product operator needs to be modified, and due to $\\,^3P3$ it needs to be compatible with the General Leibniz rule. In the simpler case of multiplication by an analytic function of one variable $g(x) \\in \\mathcal{O}(\\mathbb{C})$, then a solution is to use a modification of the equation given in $\\,^3P5$. Given the functions $f(x, a) \\in \\mathbb{S}$ and $g(x) \\in \\mathcal{O}(\\mathbb{C})$ define multiplication, denoted by the symbol $*$, as\n\\begin{equation}\nf(x, a) * g(x) = (f * g)(x, a) = \\sum_{k=0}^{\\infty} \\binom{-a}{k}f(x, a + k) \\cdot \\frac{d^k}{dx^k} g(x)\n\\label{multiplication}\n\\end{equation}\nTaking the partial derivative of $(f * g)(x, a)$ with respect to $x$, then\n$$\\partial_x (f * g)(x, a) = \\sum_{k=0}^{\\infty} \\binom{-a}{k}f(x, a + k - 1) \\cdot \\frac{d^k}{dx^k} g(x) + \\binom{-a}{k}f(x, a + k) \\cdot \\frac{d^{k + 1}}{dx^{k + 1}} g(x)$$\nUsing $k = k' - 1$ in the second term and $k = k'$ in the first, and since $\\binom{-a}{k-1}$ is zero if $k=0$, we can rearrange to find\n$$\\partial_x (f * g)(x, a) = \\sum_{k'=0}^{\\infty} \\left( \\binom{-a}{k'} + \\binom{-a}{k' - 1} \\right)f(x, (a - 1) + k') \\cdot \\frac{d^{k'}}{dx^{k'}} g(x)$$\nNow using the fact that $\\binom{-a}{k} + \\binom{-a}{k - 1} = \\binom{-a + 1}{k}$ and the definition of $(f * g)(x, a)$, then \n$$\\partial_x (f * g)(x, a) = \\sum_{k'=0}^{\\infty} \\binom{-(a - 1)}{k'}f(x, (a - 1) + k') \\cdot \\frac{d^{k'}}{dx^{k'}} g(x) = (f * g)(x, a - 1)$$\nSo if $f(x, a) \\in \\mathbb{S}$ and $g(x) \\in \\mathcal{O}(\\mathbb{C})$, then $(f * g)(x, a) \\in \\mathbb{S}$, if it exists, and clearly $(f * g)(x, a)$ satisfies $\\,^3P5$. Currently I am working on finding an operator that naturally generalizes multiplication that works when both functions are in the set $\\mathbb{S}$.\n\n\\section*{PDE representation}\nWe can construct an alternative for $\\partial_x f(x, a) = f(x, a - 1)$ by using the definition of the shift operator $T_{x}^{t} = e^{t \\partial_x}$. Expanding the exponential function in this definition $T_{x}^t = \\sum_{k=0}^{\\infty} \\frac{t^k}{k!} \\partial_{x}^{k}$, allows us to express $\\partial_x f(x, a) = f(x, a - 1)$ as the PDE $\\partial_x f(x, a) - \\sum_{k=0}^{\\infty} \\frac{(-1)^k}{k!}\\partial_{a}^{k} f(x, a) = 0$. So we can solve for elements of $\\mathbb{S}$ by solving the system of PDEs\n\\begin{align*}\n&\\partial_x f(x, a) - \\sum_{k=0}^{\\infty} \\frac{(-1)^k}{k!} \\partial_{a}^{k} f(x, a) = 0 \\\\\n&\\partial_{\\bar{x}} f(x, a) = 0 \\\\\n&\\partial_{\\bar{a}} f(x, a) = 0\n\\end{align*}\nwhere the last two PDEs ensure that $f(x, a)$ is complex analytic.\n\n\\section*{Series solution}\nGiven $f(x, a) \\in \\mathcal{O}(\\mathbb{C}^2)$ it can be described by the power series\n$$f(x, a) = \\sum_{j=0}^{\\infty} \\sum_{k=0}^{\\infty} C_{j, k} \\frac{x^j}{j!} \\frac{a^k}{k!}$$\nWe can rearrange the series to the form $f(x, a) = \\sum_{j=0}^{\\infty} \\frac{x^j}{j!} \\sum_{k=0}^{\\infty} C_{j, k} \\frac{a^k}{k!}$. Then define $g_n(a) = \\sum_{k=0}^{\\infty} C_{n, k} \\frac{a^k}{k!}$, so that $f(x, a) = \\sum_{j=0}^{\\infty} \\frac{x^j}{j!} g_j(a)$, if $g_n(a)$ converges for all $n \\in \\mathbb{Z}^+$. If $f(x, a) \\in \\mathbb{S}$, then applying the equation $\\partial_x f(x, a) = f(x, a - 1)$ to the power series representation produces,\n$$\\partial_x f(x, a) = \\sum_{j=0}^{\\infty} \\sum_{k=0}^{\\infty} C_{j + 1, k} \\frac{x^j}{j!} \\frac{a^k}{k!} = \\sum_{j=0}^{\\infty} \\sum_{k=0}^{\\infty} C_{j, k} \\frac{x^j}{j!} \\frac{(a - 1)^k}{k!}$$\nTaking the $n$th partial derivative of $x$ on both sides and letting $x=0$ yields,\n$$\\sum_{k=0}^{\\infty} C_{n + 1, k} \\frac{a^k}{k!} = \\sum_{k=0}^{\\infty} C_{n, k} \\frac{(a -1)^k}{k!}$$\nUsing the definition of $g_n(a)$ results in,\n$$g_{n+1}(a) = g_{n}(a - 1)$$\nApplying this equation repeatedly yields the equation,\n$$g_{n}(a) = g_{0}(a - n)$$\nSo if $f(x, a) \\in \\mathbb{S}$, then\n$$f(x, a) = \\sum_{j=0}^{\\infty} \\frac{x^j}{j!} g_{j}(a) = \\sum_{j=0}^{\\infty} \\frac{x^j}{j!} g_{0}(a - j)$$\nThus for any $g(a) \\in \\mathcal{O}(\\mathbb{C})$, if the series $f(x, a) = \\sum_{j=0}^{\\infty} \\frac{x^j}{j!} g(a - j)$ converges, then $f(x, a) \\in \\mathbb{S}$. Note that $g_{0}(a) = f(0, a)$. So if $f(x, a) \\in \\mathbb{S}$, then \n\\begin{equation}\nf(x, a) = \\sum_{j=0}^{\\infty} \\frac{x^j}{j!} f(0, a - j)\n\\label{series_solution}\n\\end{equation}\nand if $f(x, a)$ is an entire function, then the series solution converges for all finite $x$ and $a$. Currently I am looking into using this idea to construct an alternative representation of the fractional calculus I have described in this document, as it looks like it might be a more natural description.\n\n\\bibliographystyle{plain}\n\\bibliography{scv_fractional_calculus.bib}\n\\end{document}\n", "meta": {"hexsha": "550788672c39ebe43cb7be12ed81c1d6b0c64857", "size": 12371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/fractional_calculus/scv_fractional_calculus/scv_fractional_calculus.tex", "max_stars_repo_name": "lsiemens/lsiemens.github.io", "max_stars_repo_head_hexsha": "d93bf32c8e849b6514aea0f8eb582c42543a53d6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-16T18:16:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-16T18:16:07.000Z", "max_issues_repo_path": "theory/fractional_calculus/scv_fractional_calculus/scv_fractional_calculus.tex", "max_issues_repo_name": "lsiemens/lsiemens.github.io", "max_issues_repo_head_hexsha": "d93bf32c8e849b6514aea0f8eb582c42543a53d6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-03-08T23:16:36.000Z", "max_issues_repo_issues_event_max_datetime": "2015-12-29T02:17:16.000Z", "max_forks_repo_path": "theory/fractional_calculus/scv_fractional_calculus/scv_fractional_calculus.tex", "max_forks_repo_name": "lsiemens/lsiemens.github.io", "max_forks_repo_head_hexsha": "d93bf32c8e849b6514aea0f8eb582c42543a53d6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-16T18:16:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-16T18:16:10.000Z", "avg_line_length": 114.5462962963, "max_line_length": 916, "alphanum_fraction": 0.6448953197, "num_tokens": 4608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6625920085289642}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\n\n\\begin{document}\n\n\\subsection{Motivation}\n\n%Each report must be created in a separate subfolder. Take the \"example\" folder as an example of a report (please do not change).\n%\n%Here it is required to describe the problematic of the problem. Basic premises and results. It is important to indicate a list of references on this topic~\\cite{AuthorYear}. All refernces put to the main.bib file.\n%\n%After writing your report, include the report to main.tex similar to the sample report.\n\n%All changes are made through GitHub\\footnote{\\url{https://github.com/Intelligent-Systems-Phystech/GeometricDeepLearning}}.\n\nThe work investigates the problem of time series forecasting. The goal is to get a continuous forecast given discrete data points.\n\n\\subsection{Problem statement}\n\nGiven a time series $\\mathbf{X} = (t_i, a_i)^{\\ell}_{i=1}, ~t_1 \\leq \\ldots \\leq t_\\ell$. The number $a_i$ is the accelerometer reading. Given also unobservable velocities $v_i \\in \\mathbb{R}^1$ at each timestamp $t_i$. The current velocity $v_i$ can be computed through the previous one as follows: $v_i = f(v_{i-1},a_{i}, \\boldsymbol\\theta_\\text{rnn})$. It is assumed that at each interval $[t_{i-1}, t_i]$ the pendulum equation is fulfilled:\n\\[\n\\begin{cases}\n\\frac{d}{dt}a(t) = v(t),\\\\\n\\frac{d}{dt}v(t) = -\\theta\\sin a(t), \\quad \\theta > 0,\\\\\na(t_{i-1}) = a_{i-1} + \\xi_{i-1}, ~v(t_{i-1}) = v_{i-1}.\n\\end{cases} \\quad 2 \\leq i \\leq \\ell\n\\]\nLet $\\boldsymbol\\theta = [\\theta, \\boldsymbol\\theta_\\text{rnn}]$. Given a loss function $\\mathcal{L}(\\boldsymbol{\\theta}) = \\sum_{i=2}^\\ell\\xi_i^2(\\boldsymbol\\theta)$. Optimal parameters $\\boldsymbol\\theta$ are solution of the following optimization problem:\n\\[\n\\boldsymbol{\\theta}^* = \\arg\\min_{\\boldsymbol{\\theta}}\\mathcal{L}(\\boldsymbol{\\theta}).\n\\]\n\n\\subsection{Problem solution}\nConsider basic algorithm ODE-RNN \\cite{NEURIPS2019_42a6845a}:\n\\begin{algorithm}[H]\n\\begin{algorithmic}\n\\caption{ODE-RNN}\n\\REQUIRE Data points $\\{(x_i, t_i)\\}_{i=1}^N$.\n\\STATE Initialize $\\mathbf{h}_0$.\n\\FOR{$i = 1, \\ldots, N$}\n\\STATE $\\mathbf{h}_i' = \\mathrm{ODESolve}(f_\\theta, \\mathbf{h}_{i-1}, (t_{i-1}, t_i))$.\n\\STATE $\\mathbf{h}_i = \\mathrm{RNNCell}(\\mathbf{h}_i', x_i)$.\n\\ENDFOR\n\\STATE For each $i$ compute outputs $o_i = \\mathrm{OutputNN}(\\mathbf{h}_i)$.\n\\RETURN $\\{o_i\\}_{i=1}^N$\n\\end{algorithmic}\n\\end{algorithm}\n\nWe introduce a modification of ODE-RNN. The difference is that we map hidden state to the space (from $\\mathbb{R}^\\text{hidden}$) of the ODE solution ($\\mathbb{R}^2$) and back.\n\\begin{algorithm}[H]\n\\begin{algorithmic}\n\\caption{ODE-RNN with modifications}\n\\REQUIRE Data points $\\{(x_i, t_i)\\}_{i=1}^N$.\n\\STATE Initialize $\\mathbf{h}_0$.\n\\FOR{$i = 1, \\ldots, N$}\n\\STATE $\\mathbf{h}_i' = \\mathrm{ODESolve}(f_\\theta, \\textcolor{red}{\\mathrm{To2d}}(\\mathbf{h}_{i-1}), (t_{i-1}, t_i))$.\n\\STATE $\\mathbf{h}_i = \\mathrm{RNNCell}(\\textcolor{red}{\\mathrm{ToHidden}}(\\mathbf{h}_i'), x_i)$.\n\\ENDFOR\n\\STATE For each $i$ compute outputs $o_i = \\mathrm{OutputNN}(\\mathbf{h}_i)$.\n\\RETURN $\\{o_i\\}_{i=1}^N$\n\\end{algorithmic}\n\\end{algorithm}\n\nWe compute gradients of the loss function $\\mathcal{L}(\\boldsymbol{\\theta})$ w.r.t. $\\boldsymbol\\theta$ using backpropagation. Then we perform optimizing step. After some iterations we get a solution. \n\n\\subsection{Code analysis}\n\nThe computational experiment can be found on GitHub repository\\footnote{https://github.com/Konstantin-Iakovlev/MathMethodsOfForecasting}.\n\n\\subsection{Computational experiment}\n\nThe goal of the computational experiment is to compare the prediction quality of the proposed method with other methods. The data was taken from WISDM dataset \\cite{kwapisz2011activity}. We considered an accelerometer measurements. The number of train timestamps is 60. The number of validation timestamps is 20. Hidden size of LSTM is 20. Output network, networks that map to hidden space and back are one layer dense networks.\n\nFirst, we ran ODE-RNN with modifications with $f_\\theta$ as a right hand side of a pendulum equation. We used Adam with learning rate $5\\cdot 10^{-3}$ for optimization. We ran 500 epochs of optimization. Validation loss is 0.6090.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/pendulum.png}\n\\caption{Forecast of ODE-RNN with modifications, pendulum equation.}\n\\end{figure}\n\nAfter that we ran ODE-RNN with modifications with $f_\\theta$ as a two fully connected layers with Tanh activation with hidden size 2. We also ran 500 epochs with Adam optimizer. The validation loss is 1.3758.\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/dense.png}\n\\caption{Forecast of ODE-RNN with modifications,  dense network.}\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/pendulum_train.png}\n\\caption{Train loss, pendulum equation.}\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/dense_train.png}\n\\caption{Train loss, dense network.}\n\\end{figure}\n\nDuring our experiments, we noticed that the learning process of the network in the case of a pendulum is more stable and reach better minimum. It seems to be that the using of the pendulum equation's right hand side as a dynamic of an ODE is a powerful regularizer.\n%\\begin{table}\n%\\caption{Dependence of $Q^2$ on $R$ on validation dataset}\n%\\label{table}\n%\\begin{tabular}{c|c|c|c|c|c|c|c|}\n%Method & $R= 1$ & $R= 4$ & $R = 10$ & $R = 13$ & $R = 16$ & $R = 19$\\\\ \\hline\n%HOPLS  &0.41 $\\pm$ 0.12 & 0.51 $\\pm$ 0.19&  0.41 $\\pm$ 0.12& 0.04 $\\pm$ 0.47 & -0.22 $\\pm$ 0.68&  -0.32 $\\pm$ 0.68 \\\\\n%N-PLS & 0.42 $\\pm$ 0.15 & 0.45 $\\pm$ 0.11 & 0.35 $\\pm$ 0.18 & 0.35 $\\pm$ 0.19 & 0.33 $\\pm$ 0.20 & 0.30 $\\pm$ 0.20    \n%\\end{tabular}\n%\\end{table}\n\n\n\n\\end{document}", "meta": {"hexsha": "25987516ea6347de2ad3388d968cf595752a04a3", "size": 5757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Task_2/report/sections/example/main.tex", "max_stars_repo_name": "Konstantin-Iakovlev/MathMethodsOfForecasting", "max_stars_repo_head_hexsha": "44fa014fd18aaae5330105de35a41ef90962ee70", "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": "Task_2/report/sections/example/main.tex", "max_issues_repo_name": "Konstantin-Iakovlev/MathMethodsOfForecasting", "max_issues_repo_head_hexsha": "44fa014fd18aaae5330105de35a41ef90962ee70", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task_2/report/sections/example/main.tex", "max_forks_repo_name": "Konstantin-Iakovlev/MathMethodsOfForecasting", "max_forks_repo_head_hexsha": "44fa014fd18aaae5330105de35a41ef90962ee70", "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": 48.7881355932, "max_line_length": 444, "alphanum_fraction": 0.7182560361, "num_tokens": 1886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6625289432714236}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\\usepackage{color}\n\\usepackage{graphicx}\n\n\\pagestyle{myheadings}\n\\markboth{Magic}{Magic}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Do you believe in magic?\n\\end{center}\n\nMagic squares have fascinated humanity for centuries. In our\nterminology, a magic square is an $n\\times n$ matrix whose entries are\nthe integers from 1 to $n^2$, arranged so that the sum of every row,\nevery column, and the two long diagonals is the magic number\n$n(n^2+1)/2$. \n\nA famous example is Durer's magic square,\n\\[\n\\begin{bmatrix}\n  16 & 3 & 2 & 13 \\\\ 5 & 10 & 11 & 8 \\\\ 9 & 6 & 7 & 12 \\\\ 4 & 15 & 14 & 1\n\\end{bmatrix}\n\\]\nOne of the coolest facts about this magic square is that it contains the numbers 15 and 14 next to each other, and in 1514 he made an engraving about it:\n\\begin{center}\n  \\includegraphics[height=2in]{durer}\n\\end{center}\nIt has a couple more tricks up its sleeve as well.\n\nWe can check the magic square properties with a little linear algebra. First consider the inner product \n\\begin{equation}\n\t\\label{ones}\n\\begin{bmatrix}\na & b & c & d \n\\end{bmatrix} \\begin{bmatrix}\n1 \\\\ 1 \\\\ 1 \\\\ 1\n\\end{bmatrix}\n= a + b + c + d,\n\\end{equation}\nallowing us to sum the entries of a vector. We can do something similar with the square matrix $M$, summing all the rows simultaneously:\n\\begin{equation}\n\t\\label{Mones}\n\tM \\begin{bmatrix}\n\t\t1 \\\\ 1 \\\\ 1 \\\\ 1\n\t\\end{bmatrix}\n\t= 1 \\bm{m}_1 + 1 \\bm{m}_2 + 1 \\bm{m}_3 + 1 \\bm{m}_4.\n\\end{equation}\nThe result is a column vector, each entry of which is the sum of elements in its row. To sum columns instead, we can first transpose $M$ so that the columns become rows. Finally, note that if $\\mA$ is $n\\times n$ and $\\bfx$ is a column vector of $n$ ones, then we can do two multiplications and get\n\\begin{equation}\n\t\\label{sumall}\n\t\\bfx^T \\mA \\bfx = \\bfx^T ( \\bfa_1 + \\cdots + \\bfa_n) = \\sum_{i=1}^n \\sum_{j=1}^n A_{ij}.\n\\end{equation}\n\n\n\\subsection*{Preparation}\n\nRead section 2.2, and the online help for the \\texttt{diag} command.\n\n\\subsection*{Goals}\n\nYou will use MATLAB commands to manipulate Durer's magic square and check its special properties. While you could do all the operations by summing in loops, we'll use linear algebra techniques that make vectors and matrices the central focus.\n\n\\subsection*{Required submission elements}\n\nDownload the template script and complete it to do the following. You should use the techniques described in the introduction. \n\n\\begin{enumerate}\n\\item Let \\texttt{M} be Durer's magic square as given above. \n\\item Use the matrix-vector multiplication in~\\eqref{Mones} to compute the row sums of $M$.  \n\\item Use a transpose and~\\eqref{Mones} to compute the column sums of $M$. \n\\item There are four $2\\times 2$ submatrices made by drawing lines\n  horizontally and vertically through the center of the matrix. Using the identity~\\eqref{sumall}, verify that the sum of the elements of each of these submatrices is also the magic number.\n\\item There is another $2\\times 2$ submatrix made by the four interior elements. Verify that the sum of these elements is---wait for it---the magic number. \n\\item Find the sum of the main diagonal of \\texttt{M} using \\texttt{diag} and~\\eqref{ones}. Then do the same for the sum on the ``antidiagonal.'' (Hint: How can you rearrange $M$ so that the antidiagonal becomes the diagonal?)\n\\end{enumerate}\n\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "26f17985d34ca695f062e437a005963ac0ad7cb3", "size": 3503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter02/Magic/Magic.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/Magic/Magic.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/Magic/Magic.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": 38.4945054945, "max_line_length": 298, "alphanum_fraction": 0.7259491864, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6625289309415182}}
{"text": "\n\\section{Monte Carlo Methods}\nMonte Carlo methods learn state and action values by sampling and averaging returns (i.e. not from dynamics like DP). These methods learn from experience (real or simulated) and require no prior knowledge of the environments dynamics.\\\\\n\nMonte Carlo methods thus require well defined returns, so we will consider them only for episodic tasks. Only on completion of an episode do values and policies change.\\\\\n\nWe still use the generalised policy iteration framework, but we adapt it so that we learn the value function from experience rather than compute it \\emph{a priori}.\n\n\n\\subsection{Monte Carlo Prediction}\nThe idea is to average the returns following each state to get an estimate of the state value\n\\[\n    v_\\pi(s) = \\Epi{} [G_{t+1} | S_t =s].\n\\]\nGiven enough observations, the sample average converges to the true state value under the policy $\\pi$.\\\\\n\nGiven a policy $\\pi$ and a set of episodes, here are two ways in which we might estimate state values\n\\begin{itemize}\n    \\item \\emph{First Visit MC} average returns from first visit to state $s$ in order to estimate $v_\\pi(s)$\n    \\item \\emph{Every Visit MC} average returns following every visit to state $s$.\n\\end{itemize}\n\nFirst visit MC generates iid estimates of $v_\\pi(s)$ with finite variance, so the sequence of estimates converges to the expected value by the law of large numbers as visits to $s$ tend to $\\infty$. Every visit MC does not generate independent estimates, but still converges.\\\\\n\nAn algorithm for first visit MS (what we will focus on) is below. Every visit is the same, just without the check for $S_k$ occurring earlier in the episode.\\\\\n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/first_visit_mc_algo.png} \\\\ \n\nMonte Carlo methods are often used even when the dynamics of the environment are knowable, e.g. in Blackjack. It is often much easier to create sample games than it is to calculate environment dynamics directly.\\\\\n\nMC estimates for different states are independent (unlike bootstrapping in DP). This means that we can use MC to calculate the value function for a subset of the states, rather than the whole state space as with DP. Along with the ability to learn from experience and simulation, this is the another advantage that MC has over DP.\n\n\\subsection{Monte Carlo Estimation of Action Values}\nIf we don't have a model for the environment, then it is more useful to estimate action-values. With a model we can use state values to find a policy by searching possible actions, as with DP (value iteration, etc.). We can't do this without knowledge of the dynamics, so one of the primary goals of MC is to estimate $q_*$. We start with policy evaluation for action-values.\n\n\\subsubsection*{Policy Evaluation for Action-Values}\nThe policy evaluation problem for action-values is to estimate $q_\\pi(s, a)$ for some $\\pi$. This is essentially the same as for state values, only we now talk about state-action pairs being visited, i.e. taking action $a$ in state $s$, rather than just states being visited.\\\\\n\nIf $\\pi$ is deterministic, then we will only estimate the values of actions that $\\pi$ dictates. We therefore need to incorporate some exploration in order to have useful action-values (since, after all, we want to use them to make informed decisions).\\\\\n\nOne consideration is to make $\\pi$ stochastic, e.g. $\\varepsilon$-soft. Another is the assumption of \\emph{exploring starts}, which specifies that ever state-action pair has non-zero probability of being selected as the starting state. Of course, this is not always posible in practice.\\\\\n\nFor now we assume exploring start. Later we will come back to the issue of \\emph{maintaining exploration}\n\n\\subsection{Monte Carlo Control}\nWe make use of the GPI framework for action-values. Policy evaluation is done as described. Policy improvement is done by making the policy greedy with respect to the action-value function, so no model is needed for this step\n\\[\n    \\pi(s) \\doteq \\argmax_a q(s, a).\n\\]\n\nWe generate a sequence of policies $\\pi_k$ each greedy with respect to $q_{\\pi_{k-1}}(s, a)$. The policy improvement theorem applies: for all $s \\in \\mathcal{S}$\n\\begin{align*}\n    q_{\\pi_k}(s, a=\\pi_{k+1}(s)) &= q_{\\pi_k}(s, \\argmax_a q_\\pi(s, a)) \\\\\n                    &= \\max_a q_{\\pi_k}(s, a) \\\\\n                    &\\geq q_{\\pi_k}(s, \\pi_k(s))\\\\\n                    &= v_{\\pi_k}(s)\n\\end{align*}\n\nSo $\\pi_{k+1}$ uniformly better than $\\pi_k$ or it is optimal. \\\\\n\nThe above procedure's convergence depends on assumptions of exploring starts and infinitely many episodes. We will relax the first later, but we will address the second now.\\\\\n\nTwo approaches to avoid infinitely many episodes:\n\\begin{enumerate}\n    \\item Stop the algorithm once the $q_{\\pi_k}$ stop moving within a certain error. (In practice this is only useful on the smallest problems.)\n    \\item Stop policy evaluation after a certain number of episodes, moving the action value towards $q_{\\pi_k}$, then go to policy improvement.\n\\end{enumerate}\n\nFor MC policy evaluation, it is natural to alternate policy evaluation and improvement on a episode by episode basis. We give such an algorithm below (with the assumption of exploring starts).\\\\\n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/mc_policy_iteration_exploring_starts.png}\\\\\n\nIt is easy to see that optimal policies are a fixed point of this algorithm. Whether this algorithm converges in general is still, however, an open question.\n\n\\subsection{Monte Carlo Control without Exploring Starts}\n\\subsubsection*{On Policy vs. Off Policy}\nOn-policy methods evaluate or improve the policy that is used to make decisions, whereas off-policy methods evaluate or improve one that is different than the one used to generate the data.\n\n\\subsubsection*{On-Policy Techniques without Exploring Starts}\nWe consider $\\varepsilon$-greedy policies that put probability $1 - \\varepsilon + \\frac{\\varepsilon}{|\\mathcal{A}(s)|}$ on the maximal action and $\\frac{\\varepsilon}{|\\mathcal{A}(s)|}$ on each of the others. These are examples of $\\varepsilon$-soft policies in which $\\pi(a|s) \\geq \\frac{\\varepsilon}{|\\mathcal{A}(s)|}$.\\\\\n\nWe use this idea in the GPI framework:\\\\\n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/on_policy_mc_algo.png}\\\\\n\nWe now show that an $\\varepsilon$-greedy policy with respect to $q_\\pi$, $\\pi'$, is an improvement over any $\\varepsilon$-soft policy $\\pi$. For any $s \\in \\mathcal{S}$\n\\begin{align}\n    q_\\pi(s, \\pi'(s)) &= \\sum_a \\pi'(a|s) q_\\pi(s, a) \\\\ \n                      &= \\frac{\\varepsilon}{|\\mathcal{A}(s)|} \\sum_a q_\\pi(s, a) + (1 - \\varepsilon)\\max_a q_\\pi(s, a) \\\\\n                      &\\geq \\frac{\\varepsilon}{|\\mathcal{A}(s)|} \\sum_a q_\\pi(s, a) + (1 - \\varepsilon)\\sum_a\\frac{\\pi(a|s) - \\frac{\\varepsilon}{|\\mathcal{A}(s)|}}{1 - \\varepsilon} q_\\pi(s, a) \\\\\n                      &= \\sum_a \\pi(a|s) q_\\pi(s, a)\\\\\n                      &= v_\\pi(s)\n\\end{align}\n(where line 3 follows because a weighted average with weights $w_i \\geq 0$ and $\\sum_i w_i = 1$ is $\\leq$ the max term).\\\\\n\nThis satisfies the condition of the policy improvement theorem so we now know that $\\pi' \\geq \\pi$.\\\\\n\nPreviously, with deterministic greedy policies, we would get automatically that fixed points of policy iteration are optimal policies since\n\\[\n    v_*(s) \\doteq \\max_\\pi v_\\pi(s) \\quad \\forall s \\in \\mathcal{S}.\n\\]\nNow our policies are not deterministically greedy, our value updates do not take this form. We note, however, that we can consider an equivalent problem where we change the environment to select state and reward transitions at random with probability $\\varepsilon$ and do what our agent asks with probability $1 - \\varepsilon$. We have moved the stochasticity of the policy into the environment, creating an equivalent problem. The optimal value function in the new problem satisfies its Bellman equation\n\\begin{align}\n    \\tilde{v}_\\pi(s) &= (1 - \\varepsilon) \\max_a \\tilde{q}_\\pi(s, a) + \\frac{\\varepsilon}{|\\mathcal{A}(s)|}\\sum_a \\tilde{q}_\\pi(s, a) \\\\ \n                     &= (1 - \\varepsilon) \\max_a \\sum_{s', r} p(s', r|s, a)[r + \\gamma \\tilde{v}_\\pi(s')] + \\frac{\\varepsilon}{|\\mathcal{A}(s)|} \\sum_a \\sum_{s', r} p(s', r|s, a)[r + \\gamma \\tilde{v}_\\pi(s')].\n\\end{align}\nWe also know that at fixed points of our algorithm\n\\begin{align}\n    v_\\pi(s) &= (1 - \\varepsilon) \\max_a q_\\pi(s, a) + \\frac{\\varepsilon}{|\\mathcal{A}(s)|}\\sum_a q_\\pi(s, a) \\\\ \n                     &= (1 - \\varepsilon) \\max_a \\sum_{s', r} p(s', r|s, a)[r + \\gamma v_\\pi(s')] + \\frac{\\varepsilon}{|\\mathcal{A}(s)|} \\sum_a \\sum_{s', r} p(s', r|s, a)[r + \\gamma v_\\pi(s')].\n\\end{align}\nThis is the same equation as above, so by uniqueness of solutions to the Bellman equation we have that $v_\\pi = \\tilde{v}_\\pi$ and so $\\pi$ is optimal.\n\n\\subsection{Off-Policy Prediction via Importance Sampling}\nOff-policy learning uses information gained by sampling the \\emph{behaviour policy} $b$ to learn the \\emph{target policy} $\\pi$. The behaviour policy explores the environment for us during training and we update the target policy accordingly.\\\\\n\nIn this section we consider the prediction problem: estimating $v_\\pi$ or $q_\\pi$ for a fixed and known $\\pi$ using returns from $b$. In order to do this we need the assumption of coverage:\n\\begin{equation}\n    \\pi(a|s) \\geq 0 \\implies b(a|s) \\geq 0.\n\\end{equation}\nThis implies that $b$ must be stochastic wherever it is not identical to $\\pi$. The target policy $\\pi$ may itself be deterministic, e.g. greedy with respect to action-value estimates.\n\n\\subsubsection*{Importance Sampling}\nWe use \\emph{importance sampling} to evaluate expected returns from $\\pi$ given returns from $b$.\\\\\n\nDefine the importance sampling ratio as the relative probability of a certain trajectory from $S_t$\n\\begin{align}\n    \\rho_{t:T-1} &= \\frac{\\P{}(A_t, S_{t+1}, A_{t+1}, \\dots)| S_t, A_{t:T-1} \\sim \\pi}{\\P{}(A_t, S_{t+1}, A_{t+1}, \\dots)| S_t, A_{t:T-1} \\sim b} \\\\\n                 &= \\frac{\\prod_{k=t}^{T-1}\\pi(A_k|S_k)\\P{}(S_{k+1}|S_k, A_k)}{\\prod_{k=t}^{T-1}b(A_k|S_k)\\P{}(S_{k+1}|S_k, A_k)}\\\\\n                 &=\\prod_{k=t}^{T-1}\\frac{\\pi(A_k|S_k)}{b(A_k|S_k)}\n\\end{align}\nwhere the state transition dynamics $\\P{}$ cancel out.\\\\\n\nIf we have returns $G_t$ from evaluating policy $b$, so $v_b(s) = \\E[G_t|S_t=s]$, then we can calculate\n\\[\n    v_\\pi(s) = \\E[\\rho_{t:T-1}G_t|S_t=s]\n\\]\n\n\\subsubsection*{Estimation}\nIntroduce new notation:\n\\begin{itemize}\n    \\item Label all time steps in a single scheme. So maybe episode 1 is $t=1, \\dots, 100$ and episode 2 is $t = 101, \\dots, 200$, etc.\n    \\item Denote the set times of first/every visit to $s$ by $\\mathcal{T}(s)$ (spanning episodes).\n    \\item Let $T(t)$ be the first termination after $t$\n    \\item Let $G_t$ be the returns from $t$ to $T(t)$\n\\end{itemize}\n\nWe can now give two methods of values for $\\pi$ from returns from $b$:\\\\\n{\\bfseries{Ordinary Importance Sampling}}\n\\begin{equation}\n    V(s) \\doteq \\frac{\\sum_{t\\in \\mathcal{T}(s)} \\rho_{t:T-1}G_t}{|\\mathcal{T}(s)|}\n\\end{equation}\n{\\bfseries{Weighted Importance Sampling}}\n\\begin{equation}\n    V(s) \\doteq \\frac{\\sum_{t\\in \\mathcal{T}(s)} \\rho_{t:T-1}G_t}{\\sum_{t\\in \\mathcal{T}(s)} \\rho_{t:T-1}}\n\\end{equation}\nor 0 if the denominator is 0.\\\\\n\nWeighted importance sampling is biased (e.g. it's expectation is $v_b(s)$ after 1 episode) but has bounded variance. The ordinary importance sampling ratio is unbiased, but has possibly infinite variance, because the variance of the importance sampling ratios themselves is unbounded.\\\\\n\nAssuming bounded returns, the variance of the weighted importance sampling estimator converges to 0 even if the variance of the importance sampling ratios is infinite. In practice, this estimator usually has dramatically lower variance and is strongly preferred.\n\n\\subsection{Incremental Implementation}\nWe look for incremental calculations of the averages that make up the estimates, as in Chapter 2.\\\\\n\nFor on-policy methods the incremental averaging is the same as in Chapter 2. For off-policy methods, but with ordinary importance sampling, we only need to multiply the returns by the importance sampling ratio and then we can average as before.\\\\\n\nWe will now consider weighted importance sampling. We have a sequence of returns $G_i$, all starting in the same state $s$ and each with a random weight $W_i$ (e.g. $W_i = \\rho_{i:T(i)-1}$). We want to iteratively calculate (for $n \\geq 2$)\n\\[\n    V_n = \\frac{\\sum_{k=1}^{n-1}W_kG_k}{\\sum_{k=1}^{n-1}W_k}.\n\\]\nWe can do this with the following update rules\n\\begin{align}\n    V_{n+1} &= V_n + \\frac{W_n}{C_n}[G_n - V_n]\\\\\n    C_{n+1} &= C_n + W_{n+1}\n\\end{align}\nwhere $C_0 = 0$ and $V_1$ is arbitrary (notice that it cancels out as $V_2 = G_1$).\\\\\n\nBelow is an algorithm for off-policy weighted importance sampling (set $b=\\pi$ for on policy). The estimator $Q$ converges to $q_\\pi$ for all encountered state-action pairs.\\\\\n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/off_policy_mc_prediction_algo.png}\\\\\n\n\n\\subsection{Off-Policy Monte Carlo Control}\nBelow is an algorithm for estimating $\\pi_*$ and $q_*$ in the GPI framework. The target policy $\\pi$ is the greedy policy with respect to $Q$, which is an estimate of $q_\\pi$. This algorithm converges to $q_\\pi$ as long as an infinite number of returns are observed for each state-action pair. This can be achieved by making $b$ $\\varepsilon$-soft. The policy $\\pi$ converges to $\\pi_*$ at all encountered states even if $b$ changes (to another $\\varepsilon$-soft policy) between or within episodes.\\\\\n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/off_policy_mc_control_algo.png}\\\\\n\nNotice that this policy only learns from episodes in which $b$ selects only greedy actions after some timestep. This can greatly slow learning.\n\n\\subsection{*Discounting Aware Importance Sampling}\nWe present a method of importance sampling that recognises the return as a discounted sum of rewards. This can help in estimation, since if an episode is of length 100 and $\\gamma = 0$ then the final 99 terms of the importance sampling ration contribute nothing to the expected value of our estimator (they have expected value of 1) but can greatly increase its variance. We therefore construct a method of importance sampling that takes into account discounting.\\\\\n\nIntroduce the \\emph{flat partial returns}\n\\[\n    \\bar{G}_{t:h} \\doteq \\sum_{i=t+1}^h R_{i} \\quad 0 \\leq t \\leq h \\leq T\n\\]\nthen it can be shown (by rearranging) that\n\\begin{align}\n    G_t &\\doteq \\gamma^{i-t}R_{i+1}\\\\\n        &= (1 - \\gamma)\\sum_{h=t+1}^{T-1}\\gamma^{h-t-1}\\bar{G}_{t:h} + \\gamma^{T-t-1}\\bar{G}_{t:T}.\n\\end{align}\nNow we can scale each flat partial return by a truncated importance sampling ratio (hence reducing variance).\\\\\n\n{\\bfseries{Ordinary Importance Sampling Ratio}}\n\\begin{equation}\n    V(s) \\doteq \\frac{\\sum_{t\\in \\mathcal{T}(s)} \\left[ (1 - \\gamma) \\sum_{h=t+1}^{T(t-1)} \\gamma^{h - t - 1}\\rho_{t:h-1}\\bar{G}_{t:h} + \\gamma^{T(t) - t - 1}\\rho_{t:T(t) - 1} \\bar{G}_{t:T(t)} \\right]}{|\\mathcal{T}(s)|}\n\\end{equation}\n\n{\\bfseries{Weighted Importance Sampling Ratio}}\n\\begin{equation}\n    V(s) \\doteq \\frac{\\sum_{t\\in \\mathcal{T}(s)} \\left[ (1 - \\gamma) \\sum_{h=t+1}^{T(t-1)} \\gamma^{h - t - 1}\\rho_{t:h-1}\\bar{G}_{t:h} + \\gamma^{T(t) - t - 1}\\rho_{t:T(t) - 1} \\bar{G}_{t:T(t)} \\right]}{\\sum_{t\\in \\mathcal{T}(s)} \\left[ (1 - \\gamma) \\sum_{h=t+1}^{T(t-1)} \\gamma^{h - t - 1}\\rho_{t:h-1} + \\gamma^{T(t) - t - 1}\\rho_{t:T(t) - 1} \\right]}\n\\end{equation}\n\n\\subsection{*Per-Decision Importance Sampling}\nThere is another way in which we may be able to reduce variance in off-policy importance sapling, even in the absence of discounting ($\\gamma = 1$). Notice that the off-policy estimators are made up of terms like\n\\[\n    \\rho_{t:T-1}G_t = \\rho_{t:T-1} (R_{t+1} + \\gamma R_{t+2} + \\dots+ \\gamma^{T-t-1}R_{T})\n\\]\nand that each of these terms is of the form\n\\[\n    \\rho_{t:T-1}R_{t+1} = \\frac{\\pi(A_t|S_t)}{b(A_t|S_t)}\\dots\\frac{\\pi(A_{T-1}|S_{T-1})}{b(A_{T-1}|S_{T-1})}R_{t+1}.\n\\]\nNow notice that only the first and last terms here are correlated, while all the others have expected value 1 (taken with respect to $b$). Clearly this is also the case at each $t$. This means that\n\\[\n    \\E{}[\\rho_{t:T-1}R_{t+k}] = \\E{}[\\rho_{t:t+k-1}R_{t+k}]\n\\]\ntherefore\n\\[\n    \\E{}[\\rho{t:T-1}G_t] = \\E{}[\\tilde{G}_t]\n\\]\nwhere\n\\[\n    \\tilde{G}_t \\doteq \\sum_{i=t}^{T-1}\\gamma^{i-t}\\rho_{t:i}R_{i+1}.\n\\]\nNow we can write the ordinary importance sampling estimator as\n\\[\n    V(s) \\doteq \\frac{\\sum_{t\\in\\mathcal{T}(s)} \\tilde{G}_t}{|\\mathcal{T}(s)|}\n\\]\npossibly reducing variance in the estimator. \\\\\n\nThe weighted importance sampling estimators of this form that have so far been found have been shown to not be consistent (in the statistical sense). We don't know if a consistent weighted average form of this exists.\n", "meta": {"hexsha": "ccda3b2915b7ae1e5ead40f3cad93c4e306df2d1", "size": 16896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter5/chapter5_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/chapter5/chapter5_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/chapter5/chapter5_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": 69.5308641975, "max_line_length": 504, "alphanum_fraction": 0.708688447, "num_tokens": 4937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6625289233621308}}
{"text": "\\appendix\n\\appendixpage\n\\section{Terms That Need More Explanation Then A Footnote}\n\\subsection{Potential} \\label{sec:potential}\nPotential is the energy change that occurs when the position of an object changes \\cite{potential}. There are many potentials, like electric potential, gravitational potential and elastic \npotential. Let me explain the concept with an example. Say you are walking on a set of stairs in the upwards direction. As your muscles move to bring you one step upwards, energy that is used\nby your muscles is converted into gravitational potential. Now imagine you turn around and go downwards instead. Notice how that is easier? That is due to the gravitational potential being \nconverted back into energy so your muscles have to deliver less energy to get you down. The potential is usually tied to a force, like the gravitational force.\n\n\\subsection{Asymptotic Runtime} \\label{sec:runtime}\nAsymptotic runtime is what we use in computer science to indicate how fast an algorithm works. We do it this way because concrete time indications (seconds, minutes, hours) are very machine \ndependent. It matters a lot if your CPU, RAM and GPU are fast or not for the runtime. Therefore, we needed something to compare algorithms by which is machine independent. That is what asymptotic\nruntime is. We have 3 notations for asymptotic runtime, $\\Omega$ which is the lower bound of the runtime: not faster than; $O$ which is the upperbound of the runtime: not slower than; and we \nhave $\\Theta$ which is the tight bound: not slower but also not faster than. After these 3 notations we usually denote the runtime in algebraic letters which stand for the input size. $O(n)$ for \ninstance means that for an input of size $n$ the algorithm will not run slower than $n$ operations. Whereas $\\Omega(n^3)$ means that the algorithm needs for an input of size $n$ at least $n^3$ \noperations. Now this is not an exact match, as there are constants and other terms in the real runtime, but for asymptotic runtime we look at the most dominant factor, as that outgrows all the \nother factors if the input size increases. You can compare this by plotting the functions $y = x$ and $z = x^2$ on a graphical calculator. No matter which constant $a$ you put in front of the $x$,\n$z = x^2$ will at some point (note we don't specify when or where) be larger than $y = ax$. What you need to remember for all this is that polynomials are faster than exponentials ($n^2 < 2^n$)\nand logarithms are faster than polynomials ($\\log(n) < n$). $n!$ is very slow, $\\log(n)$ is very fast.\n\n\\subsection{Complex Numbers} \\label{sec:complex}\nAs you all know in the real numbers ($\\mathbb{R}$) negative roots are not allowed as they do not exist. But what would happen if we would allow them to exist? Then we move into the area of \ncomplex numbers. A complex number consists out of two parts, a real part and an imaginary part in the form $a + bi$ where $i = \\sqrt{-1}$. Complex numbers have all kinds of properties, but what \nwe need them for are rotations. This is captured in Euler's formula $e^{it} = \\cos(x) + i\\sin(x)$ \\cite{eulerFormula}. Which means that for time $t$ we rotate around the origin (of the complex \nplane) forming a circle with radius one (the unit circle). Now if you would set $t = \\pi$ then the result is $0$. What this means is that we have come full circle (hah) when $t = 2\\pi$.", "meta": {"hexsha": "19f45d50e27497ebe74c318ab147abf715c6e646", "size": 3383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/appendices/TTNMETAF.tex", "max_stars_repo_name": "RolfHut/claude", "max_stars_repo_head_hexsha": "56ecbc1807e2c74e9edfdfcafce539e5ebc0cd33", "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/appendices/TTNMETAF.tex", "max_issues_repo_name": "RolfHut/claude", "max_issues_repo_head_hexsha": "56ecbc1807e2c74e9edfdfcafce539e5ebc0cd33", "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/appendices/TTNMETAF.tex", "max_forks_repo_name": "RolfHut/claude", "max_forks_repo_head_hexsha": "56ecbc1807e2c74e9edfdfcafce539e5ebc0cd33", "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": 135.32, "max_line_length": 196, "alphanum_fraction": 0.7652970736, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.6625289228951192}}
{"text": "\\section{The Argument Principle, Local Degree and Rouch\\'e's Theorem}\r\n\\begin{definition}\r\n    Let $D$ be a domain, we say a closed curve $\\gamma:[0,1]\\to\\mathbb C$ bounds $D$ if $I(\\gamma;w)=1$ for any $w\\in D$ and $I(\\gamma;w)=0$ for any $w\\notin D\\cup\\gamma([0,1])$.\r\n\\end{definition}\r\nNote that the orientation matters here.\r\n$D$ is indeed bounded since $\\gamma([0,1])$ is contained in $D_R(0)$ for a large enough $R$, but $I(\\gamma;w)=0$ for any $w\\notin D_R(0)$, so $D\\subset D_R(0)$, hence is bounded.\r\n\\begin{theorem}[The Argument Principle]\r\n    Let $\\gamma$ be a closed curve bounding a domain $D$ and suppose that $f$ is meromorphic in some open set $U\\subset \\bar{D}\\cup\\gamma([0,1])$ such that $f$ has no pole or zero on $\\gamma([0,1])$.\r\n    If $f$ has precisely $N$ zeros and $P$ poles in $D$ (both counting with multiplicity), then\r\n    $$N-P=\\frac{1}{2\\pi i}\\int_\\gamma\\frac{f^\\prime(z)}{f(z)}\\,\\mathrm dz=I(\\Gamma;0)$$\r\n    where $\\Gamma=f\\circ\\gamma$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $N$,$P$ are finite since $D$ is bounded and zeros and poles are isolated points.\r\n    Also note that $0\\notin\\Gamma([0,1])$ since $f\\circ\\gamma$ is never $0$.\r\n    So\r\n    $$I(\\Gamma,0)=\\frac{1}{2\\pi i}\\int_\\Gamma\\frac{1}{z}\\,\\mathrm dz=\\frac{1}{2\\pi i}\\int_0^1\\frac{1}{f(\\gamma(t))}f^\\prime(\\gamma(t))\\gamma^\\prime(t)\\,\\mathrm dt=\\frac{1}{2\\pi i}\\int_\\gamma\\frac{f^\\prime(z)}{f(z)}\\,\\mathrm dz$$\r\n    which is the second equality.\\\\\r\n    As for the other part, note that if $a$ is neither a pole or a zero at $f$, then $f^\\prime/f$ is holomorphic at $a$.\r\n    Also, if $a$ is a zero (or a pole) of order $k$ at $z=a$, then $f^\\prime/f$ has a simple pole at $z=a$ with $\\operatorname{Res}_{f^\\prime/f}(a)=k$ (or $-k$ respectively).\r\n    Now $I(\\gamma,w)=0$ for any $w\\in D$ by hypothesis, so applying the residue theorem to $f^\\prime/f$ shall give the result.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $f:D_R(a)\\to\\mathbb C$ be holomorphic and nonconstant, then the local degree of $f$ at $a$, denoted $\\deg_f(a)$, is the order of zero of $f(z)-f(a)$ at $0$.\r\n\\end{definition}\r\nNote that the local degree has to be positive.\r\n\\begin{theorem}[Local Degree Theorem]\r\n    Consider $f:D_R(a)\\to\\mathbb C$ nonconstant and holomorphic.\r\n    Suppose $\\deg_f(a)=d>0$, then for every sufficiently small $r>0$, there is $\\epsilon>0$ such that for any $w$ with $0<|w-f(a)|<\\epsilon$, the equation $f(z)=w$ has precisely $d$ roots in $D(a,r)\\setminus\\{a\\}$ that are all distinct.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Since $f$ is nonconstant, by the principle of isolated zeros, we can choose $r>0$ such that $f(z)-f(a)\\neq 0$ and $f^\\prime(z)\\neq 0$ for any $z\\in B_r(a)\\setminus\\{a\\}$.\r\n    Now take $\\gamma(t)=a+re^{it}$ for $t\\in [0,2\\pi]$, then $f(\\gamma(t))\\neq f(a)$ for any $t$, so $\\Gamma=f\\circ\\gamma$ misses $f(a)$, so we can choose $\\epsilon$ such that $\\Gamma$ never enters $D_\\epsilon(f(a))$.\r\n    Then for $w\\in D_\\epsilon(f(a))\\setminus\\{f(a)\\}$, by the argument principle, the number of zeros counting multiplicity of $f(z)-w$ in $D_r(a)$ is $I(\\Gamma;w)=I(\\Gamma;f(a))=d$.\r\n    These zeros must all be in $D_r(a)\\setminus\\{a\\}$ and none of them has multiplicity more than one as $f^\\prime(a)\\neq 0$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    A nonconstant holomorphic function on a domain is an open map.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\n\\begin{theorem}[Rouch\\'e's Theorem]\r\n    Let $\\gamma:[0,1]\\to\\mathbb C$ be a curve that bounds a domain $D$ and $f,g$ holomorphic on a open set $U$ containing $\\bar D\\cup\\gamma([0,1])$.\r\n    If $|f|>|g|$, then $f,f+g$ have the same number of zeros on $D$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $|f|>|g|$ hence $f,f+g$ are nowhere zero on $\\gamma$, so we apply the argument principle on $h=(f+g)/f=1+g/f$.\r\n    We have $I(h\\circ\\gamma;0)=0$, so $h$ has $N=P$, so $f+g,f$ has the same number of zeros.\r\n\\end{proof}", "meta": {"hexsha": "acffae1eacfa5efb101c13a0802ec85badd91dec", "size": 3888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/misc.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": "5/misc.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": "5/misc.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": 77.76, "max_line_length": 237, "alphanum_fraction": 0.6445473251, "num_tokens": 1365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.6624203883846813}}
{"text": "\\section{Foundation of Quantum Mechanics}\r\n\\subsection{Quantum Mechanics of a Particle}\r\nIn classical dynamics, a particle is characterised by its position $\\underline{x}$ and momentum $\\underline{p}$.\r\nWe formulate classical laws in this framework.\r\nE.g. in Newton's Second Law, we have $F(\\underline{x})=m\\underline{\\ddot{x}}$.\r\nA simple consequence of this is that the position and momentum of a particle at $t=0$ determines its motion under physical laws formulated in this way.\\\\\r\nBut in Quantum Mechanics, things are different.\r\n\\begin{postulate}[State and Wavefunction]\r\n    A particle in space is described by its state $\\psi:\\mathbb R^3\\times\\mathbb R\\to\\mathbb C$ such that\r\n    $$\\int_{\\mathbb R^3}|\\psi(\\underline{x},t)|^2\\,\\mathrm dV=N\\in\\mathbb R_+$$\r\n    The probability amplitude of finding a particle at a place $\\underline{x}$ and a given time $t$ is given by the state as a wavefunction $\\psi(\\underline{x},t)$.\r\n\\end{postulate}\r\nThere are subtle differences when we talk about state and when we talk about a wavefunction.\r\nBut we don't care.\r\n\\begin{postulate}[Born's Rule]\r\n    $|\\bar\\psi(\\underline{x},t)|^2\\,\\mathrm dV$ is the probability of finding the particle in $\\mathrm dV$.\r\n    Here, $\\bar\\psi$ is the normalised wavefunction $\\bar\\psi=\\psi/\\sqrt{N}$.\r\n\\end{postulate}\r\n\\begin{postulate}[Time-Dependent Schr\\\"odinger's Equation (TDSE)]\r\n    For a particle of mass $m$ in potential $U(\\underline{x})$, in the time evolution of $\\psi$ we have\r\n    $$i\\hbar\\frac{\\partial\\psi}{\\partial t}=-\\frac{\\hbar^2}{2m}\\nabla^2\\psi+U\\psi$$\r\n\\end{postulate}\r\nObserve that the equation is first order in $t$ and second order in $\\underline{x}$.\r\nIt is also linear, so it still holds if we replace $\\psi$ by a scalar multiple of it, for example $\\bar\\psi$.\r\nHeuristically, one can derive this equation (in dimension one) in the following way:\\\\\r\nConsider the particle as a de Broglie wave with wavefunction $e^{i(kx-\\omega t)}$.\r\nSo for a free particle with $U(x)=0$, we have $E=p^2/2m$, therefore the wavefunction is\r\n$$\\exp(i(kx-\\omega t))=\\exp\\left( \\frac{1}{\\hbar}(px-Et) \\right)=\\exp\\left( \\frac{1}{\\hbar}\\left(px-\\frac{p^2}{2m}t\\right) \\right)$$\r\nwhich can be verified a solution to the equation.\r\nBut this is just heuristic, the de Broglie wave is not even normalisable.\r\nWe will (hopefully) see the actual stuff later.\\\\\r\nOne thing that can easily go wrong with these postulate is that we do not know if the normalised wavefunction will continue to be normalised as time goes, so we need some work on that.\r\nIt suffices show that TDSE guarantees that $N$ does not depend on $t$.\r\n\\begin{proposition}\r\n    $N$ does not depend on $t$ assuming TDSE.\r\n\\end{proposition}\r\nThe proof involves the use of some techniques that need some analytical justification.\r\nBut this is an applied course, so nobody cares.\r\n\\begin{proof}\r\n    Just differentiate\r\n    \\begin{align*}\r\n        \\frac{\\mathrm dN}{\\mathrm dt}&=\\frac{\\mathrm d}{\\mathrm dt}\\int_{\\mathbb R^3}|\\psi(\\underline{x},t)|^2\\,\\mathrm dV\\\\\r\n        &=\\int_{\\mathbb R^3}\\frac{\\partial}{\\partial t}\\left( \\psi^*(\\underline{x},t)\\psi(\\underline{x},t) \\right)\\,\\mathrm dV\\\\\r\n        &=\\int_{\\mathbb R^3}\\psi^*\\frac{\\partial\\psi}{\\partial t}+\\psi\\frac{\\partial \\psi^*}{\\partial t}\\,\\mathrm dV\\\\\r\n        &=\\int_{\\mathbb R^3}\\psi^*\\left( \\frac{i\\hbar}{2m}\\nabla^2\\psi+\\frac{i}{\\hbar}U\\psi\\right)+\\psi\\left( -\\frac{i\\hbar}{2m}\\nabla^2\\psi^*-\\frac{i}{\\hbar}U\\psi^* \\right)\\,\\mathrm dV\\\\\r\n        &=\\frac{i\\hbar}{2m}\\int_{\\mathbb R^3}\\psi^*\\nabla^2\\psi-\\psi\\nabla^2\\psi^*\\,\\mathrm dV\\\\\r\n        &=\\frac{i\\hbar}{2m}\\int_{\\mathbb R^3}\\nabla\\cdot( \\psi^*\\nabla\\psi-\\psi\\nabla\\psi^*)\\,\\mathrm dV\\\\\r\n        &=\\frac{i\\hbar}{2m}\\int_{\\partial V}(\\psi^*\\nabla\\psi-\\psi\\nabla\\psi^*)\\cdot\\mathrm d\\underline{S}\\\\\r\n        &=0\r\n    \\end{align*}\r\n    by our boundary condition.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Assume that $\\psi$ is normalised.\r\n    Write $\\rho(\\underline{x},t)=|\\psi(\\underline{x},t)|^2$ as the probability density and\r\n    $$\\underline{J}=-\\frac{i\\hbar}{2m}(\\psi^*\\nabla\\psi-\\psi\\nabla\\psi^*)$$\r\n    the probability current.\r\n    Then we have the conservation law\r\n    $$\\frac{\\partial\\rho}{\\partial t}+\\nabla\\cdot\\underline{J}=0$$\r\n    by the calculation involved in the above proof.\r\n\\end{remark}\r\n\\subsection{Principle of Superpositions}\r\nAs TDSE is linear in $t$, for states $\\phi_1,\\phi_2$ satisfying it, $a_1\\phi_1+a_2\\phi_2$ also satisfies TDSE for any $a_1,a_2\\in\\mathbb C$.\r\nObviously, we want to show that this superposition is either $0$ or also normalisable.\r\n\\begin{proposition}\r\n    If $\\phi_1,\\phi_2$ are normalisable, so is $a_1\\phi_1+a_2\\phi_2$ for any $a_1,a_2\\in\\mathbb C$ given that it is nonzero.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Quite obvious.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    The set of all states, together with the zero function, is a vector space.\r\n\\end{corollary}\r\nThis vector space is often denoted by $\\mathcal H$.\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nWe can equip a complex inner product\r\n$$(\\psi,\\phi)=\\int_{\\mathbb R^3}\\psi^*\\phi\\,\\mathrm dV$$\r\non this space.\r\nIf we also know that it is complete with respect to that inner product, then $\\mathcal H$ is a (complex) Hilbert space.\r\n\\subsection{Expectation Values and Operators}\r\nFor a (one dimensional) particle in state $\\psi$, the average value of its position $x$ is then\r\n$$\\langle x\\rangle=\\int_{\\mathbb R}x\\rho(x,t)\\,\\mathrm dx=\\int_{\\mathbb R}x|\\bar\\psi(x,t)|^2\\,\\mathrm dx$$\r\nwhich can be interpreted as the average of repeated measurement on an ensemble of identically prepared systems.\r\nClassically $p=m\\dot{x}$ is the momentum.\r\nIn quantum mechanics, we define the average momentum to be\r\n$$\\langle p\\rangle=m\\frac{\\mathrm d\\langle x\\rangle}{\\mathrm dt}=m\\frac{\\mathrm d}{\\mathrm dt}\\int_{\\mathbb R}x|\\bar\\psi(x,t)|^2\\,\\mathrm dx$$\r\nWe can calculate it and using the conservation rule we found earlier and assuming the boundary condition that $\\psi$ decays fast enough as $x\\to\\pm\\infty$,\r\n\\begin{align*}\r\n    \\langle p\\rangle&=m\\frac{\\mathrm d}{\\mathrm dt}\\int_{\\mathbb R}x|\\bar\\psi(x,t)|^2\\,\\mathrm dx\\\\\r\n    &=m\\int_{\\mathbb R}x\\frac{\\partial(\\bar\\psi^*\\bar\\psi)}{\\partial t}\\,\\mathrm dx\\\\\r\n    &=\\frac{i\\hbar}{2}\\int_{\\mathbb R}x\\frac{\\partial}{\\partial x}\\left( \\bar\\psi^*\\frac{\\partial\\bar\\psi}{\\partial x}-\\bar\\psi\\frac{\\partial\\bar\\psi^*}{\\partial x} \\right)\\,\\mathrm dx\\\\\r\n    &=\\frac{i\\hbar}{2}\\left[x\\bar\\psi^*\\frac{\\partial\\bar\\psi}{\\partial x}-x\\bar\\psi\\frac{\\partial\\bar\\psi^*}{\\partial x}\\right]_{-\\infty}^\\infty-\\frac{i\\hbar}{2}\\int_{\\mathbb R}\\left( \\bar\\psi^*\\frac{\\partial\\bar\\psi}{\\partial x}-\\bar\\psi\\frac{\\partial\\bar\\psi^*}{\\partial x} \\right)\\,\\mathrm dx\\\\\r\n    &=-\\frac{i\\hbar}{2}\\int_{\\mathbb R}\\left( \\bar\\psi^*\\frac{\\partial\\bar\\psi}{\\partial x}-\\bar\\psi\\frac{\\partial\\bar\\psi^*}{\\partial x} \\right)\\,\\mathrm dx\\\\\r\n    &=-i\\hbar\\int_{\\mathbb R}\\bar\\psi^\\ast\\frac{\\partial\\bar\\psi}{\\partial x}\\,\\mathrm dx\r\n\\end{align*}\r\nBy a bad notation one can write\r\n$$\\langle p\\rangle=\\int_{\\mathbb R}\\psi^*\\left( -i\\hbar\\frac{\\partial}{\\partial x} \\right)\\psi\\,\\mathrm dx$$\r\nTo make it even worse we can consider the functional $\\hat{x}$ and $\\hat{p}$ defined by $\\hat{x}=x$ and $\\hat{p}=-i\\hbar\\partial/\\partial x$, which allows us to effectively confuse everybody by writing\r\n$$\\langle x\\rangle=\\int_{\\mathbb R}\\psi^*\\hat{x}\\psi\\,\\mathrm dx,\\langle p\\rangle=\\int_{\\mathbb R}\\psi^*\\hat{p}\\psi\\,\\mathrm dx$$\r\nIn general dimensions, we can use the same idea with $\\hat{\\underline{x}}=\\underline{x}$ and $\\hat{\\underline{p}}=-i\\hbar\\nabla$.\r\nThis is where we desperately try to justify these notations by considering them as (linear) operators in the Hilbert space $\\mathcal H$, which works mathematically.\r\n\\footnote{However, the notation shall haunt you for a considerable proportion of your relationship with quantum mechanics.}\r\nThe kinetic energy operator is then\r\n$$\\hat{T}=\\frac{\\hat{p}^2}{2m}=-\\frac{\\hbar^2}{2m}\\nabla^2$$\r\nIn fact, for any physical quantity $Q(x,p)$ , we are just gonna write $\\hat{Q}=Q(\\hat{x},\\hat{p})$ and we can get\r\n$$\\langle Q(x,p)\\rangle=\\int_{\\mathbb R}\\psi^*\\hat{Q}\\psi\\,\\mathrm dx=\\int_{\\mathbb R}\\psi^*Q\\left( x,-i\\hbar\\frac{\\partial}{\\partial x} \\right)\\psi\\,\\mathrm dt$$\r\nAlso, one can check by direct calculation that\r\n$$\\frac{\\mathrm d\\langle p\\rangle}{\\mathrm dt}=\\int_{\\mathbb R}\\psi^*\\left( -\\frac{\\partial U}{\\partial x} \\right)\\psi\\,\\mathrm dx=\\langle -U_x\\rangle$$\r\nby using TDSE.\r\nThe Hamiltonian operator is $\\hat{H}=\\hat{T}+\\hat{U}$, so\r\n$$(\\hat{H}\\psi)(\\underline{x},t)=-\\frac{\\hbar^2}{2m}\\nabla^2\\psi+U\\psi$$\r\n\\subsection{Time-Independent Schr\\\"odinger Equation}\r\nNote that we can rewrite the Schr\\\"odinger equation in the form\r\n$$i\\hbar\\frac{\\partial\\psi}{\\partial t}=\\hat{H}\\psi$$\r\nSO if we seperate the variables $\\psi(\\underline{x},t)=X(\\underline{x})T(t)$, then by some rearrangement\r\n$$i\\hbar T^{-1}T^\\prime=(\\hat{H}X)/X$$\r\nThe left hand side depends only on $t$ while the right hand side on $\\underline{x}$, requiring them to be equal is just saying they are actually constants.\r\nDenote this constant by $E$, then we get\r\n$$\\begin{cases}\r\n    i\\hbar T^{-1}T^\\prime=E\\\\\r\n    \\hat{H}X=EX\r\n\\end{cases}$$\r\nThe first equation is easy to solve and gives $T(t)=e^{-iEt/\\hbar}$.\r\nThe second equation is called the Time-Independent Schr\\\"odinger Equation (TISE).\r\nIts solution $X$ is then interpreted as a physical state with energy $E$.\r\nNote that $E$ must be real by our expression of $T$ and the condition that $T$ does not explode as $t\\to\\pm\\infty$.\r\nAlso, TISE is essentially the eigenvalue problem of $\\hat{H}$ which makes sense as it is a linear operator on the vector space of states and $0$.\r\nSo we have obtained the set of solutions $\\psi=Xe^{-iEt/\\hbar}$ where $X$ is an eigenfunction of $\\hat{H}$ with eigenvalue $E$.\r\nThis set of solutions is called the stationary states.\r\n\\subsection{Stationary States}\r\nFor a stationary state, assuming $\\psi$ is normalised, then\r\n$$\\rho(\\underline{x},t)=|\\psi(\\underline{x},t)|^2=|X(\\underline{x})|^2|e^{-iEt/\\hbar}|^2=|X(\\underline{x})|^2$$\r\nSo the stationary states are some particular solutions of TDSE whose induced probability distributions in space do not depend on time.\r\nOf course, superpositions of this family of stationary states is also an allowed state (or zero).\r\nWhat's more, if $\\psi_1=X_1e^{-iE_1t/\\hbar},\\psi_2=X_2e^{-iE_2t/\\hbar}$ are stationary states and $\\psi=a_1\\psi_1+a_2\\psi_2$ is a superposition, then (assuming $a_i$ and $X_i$ are real),\r\n\\begin{align*}\r\n    |\\psi|^2&=(a_1^*X_1^*e^{iE_1t/\\hbar}+a_2^*X_2^*e^{iE_2t/\\hbar})(a_1X_1e^{-iE_1t/\\hbar}+a_2X_2e^{-iE_2t/\\hbar})\\\\\r\n    &=|a_1|^2|X_1|^2+|a_2|^2|X_2|^2+a_1a_2X_1X_2(e^{i(E_1-E_2)t/\\hbar}+e^{i(E_2-E_1)t/\\hbar})\\\\\r\n    &=|a_1|^2|X_1|^2+|a_2|^2|X_2|^2+2a_1a_2X_1X_2\\cos\\left( \\frac{(E_1-E_2)t}{\\hbar} \\right)\r\n\\end{align*}\r\nSo $\\psi$ is not a stationary state if $E_1\\neq E_2$ as $|\\psi|^2$ depends on time.\r\nIn fact, the stationary state is a basis of the vector space of states (and zero), that is each state $\\psi$ can be expressed in the form\r\n$$\\psi(\\underline{x},t)=\\sum_{n=1}^Na_nX_n(x)e^{-iE_nt/\\hbar}$$\r\nwhere $X_n,E_n$ are stuff you expect them to be.\r\nWe then interpret $|a_n|^2$ to be the probability for the energy to be $E_n$.\r\n\\begin{remark}\r\n    If we have a discrete and normalisable basis $X_n$ of the Hamiltonian $\\hat{H}$.\r\n    Then we might write something of the form\r\n    $$\\psi=\\sum_{n=1}^\\infty a_nX_ne^{-iE_nt/\\hbar}$$\r\n    which is a solution to TDSE if we can show that it converges nice enough.\r\n    But this will require\r\n    $$\\lim_{R\\to\\infty}\\int_{|\\underline{x}|>R}|X_n|^2\\,\\mathrm dx=0$$\r\n    So the particle cannot be too far from the origin.\r\n    We call this a bounded state.\\\\\r\n    How about a continuous basis (i.e. the basis is indexed by $(X_\\alpha)_{\\alpha\\in I}$ where $I$ is an interval)?\r\n    Then we might write\r\n    $$\\psi=\\int_{\\alpha\\in I}A(\\alpha)X_\\alpha(\\underline{x})e^{-iE_\\alpha t/\\hbar}\\,\\mathrm d\\alpha$$\r\n    So we interpret $|A(\\alpha)|^2\\,\\mathrm d\\alpha$ as the probability for the state to have energy $E_\\alpha$.\r\n    But the same limit condition does not have to hold, since even if the state themselves are not normalisable, we can choose an $A$ that decays fast enough to make the eventual superposition normalisable.\r\n    This is called a scattering state.\r\n\\end{remark}", "meta": {"hexsha": "68f9e024358824a3ea91683d980dfbbbbfe66d47", "size": 12314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/fund.tex", "max_stars_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_stars_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/fund.tex", "max_issues_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_issues_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/fund.tex", "max_forks_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_forks_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.5460122699, "max_line_length": 299, "alphanum_fraction": 0.6887282768, "num_tokens": 4059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.662420382336127}}
{"text": "\\section{Summary}\n\\label{sec:summary}\n\n\\begin{frame}{Multigroup Neutron Diffusion Equation}\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    \\vspace{-2\\baselineskip}\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) & \n        \\parbox[t]{\\columnwidth}{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 & \n        \\parbox[t]{\\columnwidth}{fundamental eigenvalue, \\\\\n        effective neutron multiplication factor,} \\\\\n      \\nu \\Sigma_{f,g}(\\vr) & \n        \\parbox[t]{\\columnwidth}{number of fission neutrons times macroscopic\n        fission \\\\\n        cross section in energy group $g$ \\units{$\\frac{1}{\\text{cm}}$},} \\\\\n      \\Sigma_{s,g' \\rightarrow g} (\\vr) & \n        \\parbox[t]{\\columnwidth}{macroscopic scatter cross section from\n        energy group $g'$ to \\\\\n        energy group $g$ \\units{$\\frac{1}{\\text{cm}}$},} \\\\\n      G & total number of energy groups.\n    \\end{conditions}\n\\end{frame}\n\n\\begin{frame}{\\glsentryshort{nem} Equations}\n  Transverse integrated multigroup neutron diffusion equation. \\\\\n  Note: node indices $i,j,k$ have been omitted.\n  \\begin{align}\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    \\label{eq:current_approximation}\n    \\current_{g,u}(u) &= - \\overline{D_g} \\, \\frac{d \\phi_{g,u}(u)}{du}\n  \\end{align}\n  \\vspace{-\\baselineskip}\n  \\begin{conditions}\n    u          & coordinate direction (i.e. $u = x,y,z$), \\\\\n    \\overline{\\Sigma_{r,g}} & average value of $\\Sigma_{r,g}(\\vr)$ in node $i,j,k$, \\\\\n    \\overline{D_g} & average value of diffusion coefficient in node $i,j,k$, \\\\\n    Q_{g,u}(u) & transverse integrated neutron source, \\\\\n    L_{g,u}(u) & transverse leakage.\n  \\end{conditions}\n\\end{frame}\n\n\\begin{frame}{\\glsentryshort{nem} Projections}\n  Basis functions are typically polynomials.\\\\\n  \\citeauthor{qe2paper} select Legendre polynomials.\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  \\vspace{-\\baselineskip}\n  \\begin{conditions}\n    a_{g,u,n} & expansion coefficient of $\\phi_{g,u}(u)$, \\\\\n    q_{g,u,n} & expansion coefficient of $Q_{g,u}(u)$, \\\\\n    l_{g,u,n} & expansion coefficient of $L_{g,u}(u)$, \\\\\n    f_{u,n}(u) & $n^{th}$ Legendre polynomial.\n  \\end{conditions}\n\\end{frame}\n\n\\begin{frame}{Local Elimination}\n  \\begin{itemize}\n    \\item Odd and even coefficients can be solved separately \\cite{gehinThesis}.\n    \\item \\citeauthor{qe2paper} show $a_{g,u,1}$ and $a_{g,u,3}$ can be written\n      in terms of each other.\n    \\item $a_{g,u,1-3}$ and $a_{g,u,2-4}$ are introduced.\n    \\item Solution vector, $\\Phi_g$ is length $10 \\times N \\times G$.\n  \\end{itemize}\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\\end{frame}\n\n\\begin{frame}{\\glsentryshort{jfnk} Theory}\n  The $m^{th}$ Newton step.\n  \\begin{equation}\n    \\label{eq:newton_step}\n    \\jacobian (\\vx^m) \\cdot \\step^m = - \\residual(\\vx^m)\n  \\end{equation}\n  The step proceeds.\n  \\begin{equation}\n    \\vx^{m+1} = \\vx^{m} + \\step^{m}\n  \\end{equation}\n\\end{frame}\n\n\\begin{frame}{Inexact Newton Condition}\n  The Newton step is solved with a Krylov solver. \\\\\n  \\glsentryshort{gmres} and \\glsentryshort{bicgstab} are both investigated.\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  The Krylov solver does not require an explicit Jacobian, only the\n  Jacobian-vector product which can be approximated with finite differences.\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  Typically, $\\epsilon = \\sqrt{\\epsilon_{mach}} \\approx 10^{-8}$.\n\\end{frame}\n\n\\begin{frame}{Choice of Physics-Based Preconditioner}\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  \\begin{itemize}\n    \\item Preconditioner should approximate the Jacobian inverse\n      \\cite{textbookkelley}.\n    \\item \\citeauthor{gill_azmy} investigate several choices of preconditioner\n      and conclude that preconditioning with $\\approx 5$~\\glspl{pi} is ideal.\n    \\item \\citeauthor{jfnk_wielandt} present similar results.\n    \\item \\citeauthor{qe2paper} develop a preconditioner based on available\n      data.\n    \\item Solved using \\gls{tdma} and then \\gls{adi} method.\n    \\item No preconditioner comparison provided.\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Convergence Rates of \\glsentryshort{jfnk} and \\glsentryshort{pi}\n  Methods}\n  \\begin{itemize}\n    \\item \\gls{pi}.\n    \\begin{itemize}\n      \\item Converges linearly at a rate determined by the dominance ratio\n        \\cite{nakamura}.\n      \\begin{equation}\n        d = \\frac{\\lambda_1}{\\lambda_0}\n      \\end{equation}\n      \\item Typically, $d > 0.95$ is common and the \\gls{ws} is used (to be \n        discussed) \\cite{gehinThesis}.\n      \\begin{equation}\n        d' = \\frac{\\frac{1}{\\lambda_0} - \\frac{1}{\\lambda'}}\n          {\\frac{1}{\\lambda_1} - \\frac{1}{\\lambda'}}\n      \\end{equation}\n      % if \\lambda_0 = 1.0, \\lambda_1 = 0.95, \\lambda' = \\lambda_0 + 0.03\n      % d = 0.95, d' = 0.35625\n    \\end{itemize}\n    \\item \\gls{jfnk}.\n    \\begin{itemize}\n      \\item Convergence rate determined by Jacobian properties (e.g. Lipschitz\n        constant) \\cite{textbookkelley}.\n      \\item Not affected by dominance ratio \\cite{gill_azmy}.\n      \\item Will not be affected by \\gls{ws} despite claim of\n        \\citeauthor{qe2paper}.\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "cd797030f12636b36e21cba2206317d12da3cfcc", "size": 7077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/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": "presentation/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": "presentation/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": 38.2540540541, "max_line_length": 86, "alphanum_fraction": 0.6118411756, "num_tokens": 2434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6624203726608778}}
{"text": "\n\\subsection{Bitshifts}\n\nWe can have other operations where bits do interact. An important operator is the bit shift. This takes a series of bits and shifts them to the right or left by one place. This pushes one bit off the end. \n\nThe new bit can take a \\(0\\) or \\(1\\).\n\nLogic gates are not needed for bit shifts. Instead wiring of inputs to outputs achieves the same effect.\n\n", "meta": {"hexsha": "410dc9c0089c65a1b3e2a3ee3b4fabf4a0425d42", "size": 378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/logic/03-02-bitshifts.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/logic/03-02-bitshifts.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/logic/03-02-bitshifts.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": 37.8, "max_line_length": 205, "alphanum_fraction": 0.7566137566, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6623820449377725}}
{"text": "\\chapter{Engel Expansions}\n\\label{ch:maximizing_target_node}\n\n\\section{Engel expansions maximize the node $v_{n+1}$}\nA sequence $v_{n+1},v_n,\\ldots,v_2,v_1$ describing a path in $H_{C,3}$ from $v_{n+1}$ down to $v_1$ allows at most one division by $2$ between two successive nodes. Dividing only once between two successive nodes, maximizes the $v_{n+1}$, but it is not obvious that this maximizes the product contained in condition~\\ref{eq:condition_max}. Such a sequence forms the following ascending continued fraction (cf. also \\cite[p.~11]{Ref_Laarhoven}):\n\n\\begin{equation}\n\\label{eq:asc_continued_fraction}\nv_{n+1}=\\cfrac{3\\cfrac{3\\cfrac{3\\cfrac{3v_1+1}{2}+1}{2}+1}{2}+1}{2}\\dotsb\n=\\frac{3^nv_1+\\sum_{i=0}^{n-1}3^i2^{n-1-i}}{2^n}\n=\\frac{3^n(v_1+1)-2^n}{2^n}\n\\end{equation}\n\n\\par\\medskip\nThe sum of the products of the powers of three and two, contained within the above term, can be simplified to the difference $3^n-2^n$ by converting the sum expression into the form $(x-1)(1+x+x^2+\\cdots+x^{n-2}+x^{n-1})=x^n-1$ as follows:\n\\[\n\\frac{2^n}{2^n}(3-2)\\sum_{i=0}^{n-1}3^i2^{n-1-i}\n=\\frac{2^n}{\\cancel{2^{n-1}}}\\cdot\\frac{3-2}{2}\\sum_{i=0}^{n-1}3^i2^{\\cancel{n-1}-i}\n=2^n\\left(\\frac{3}{2}-1\\right)\\sum_{i=0}^{n-1}\\left(\\frac{3}{2}\\right)^i\n=2^n\\left(\\left(\\frac{3}{2}\\right)^n-1\\right)\n\\]\n\n\\begin{example}\n\tA concrete example for such a sequence is $v_1=31$, $v_2=47$, $v_3=71$, $v_4=107$, $v_5=161$. And, to follow that example, we can calculate the label of the vertex $v_5$ in a straightforward way:\n\t\\[\n\tv_5=v_{n+1}=\\frac{3^4(31+1)-2^4}{2^4}=161\n\t\\]\n\tBy choosing a vertex $v_1=2^{n+1}-1$, we are able to infinitely generate sequences which each form an ascending continued fraction. As per equation~\\ref{eq:asc_continued_fraction} the last member in this sequence is the odd labeled vertex $v_{n+1}=3^n\\cdot2-1$.\n\\end{example}\n\n\\begin{remark}\n\tAscending variants of a continued fraction, such as used in equation~\\ref{eq:asc_continued_fraction}, shall not be confused with continued fractions as treated for example in \\cite{Ref_Moore}, \\cite{Ref_Hensley}, \\cite{Ref_Borwe_etal}. These ascending continued fractions correspond to the so-called \"Engel Expansions\" \\cite{Ref_Kraaikamp_Wu}.\n\\end{remark}\n\n\\par\\noindent\nAs illustrated below, we can formulate the ascending continued fractions in a generalized fashion, whereas the analogy to \\ref{eq:asc_continued_fraction} is given by $b_1=b_2=b_3=b_4=2$ and $a_1=3^0$, $a_2=3^1$, $a_3=3^2$ and $a_4=3^3+3^4v_1$:\n\\[\n\\cfrac{a_1+\\cfrac{a_2+\\cfrac{a_3+\\cfrac{a_4}{b_4}}{b_3}}{b_2}}{b_1}\\dotsb=\\frac{a_1}{b_1}+\\frac{a_2}{b_1b_2}+\\frac{a_3}{b_1b_2b_3}+\\frac{a_4}{b_1b_2b_3b_4}+\\cdots\n\\]\n\n\\par\\medskip\nThe generalized form of equation~\\ref{eq:asc_continued_fraction} may be used to compute any of the above-named ascending continued fraction that has $a_i=k^{i-1}$, $b_i=b$ for $i\\in\\mathbb{N}$ and $a_n=k^{n-1}+k^nv_1$:\n\n\\par\\medskip\n\\begin{equation}\n\\label{eq:generalized_asc_continued_fraction}\nv_{n+1}=\\frac{k^n(kv_1-bv_1+1)-b^n}{b^n(k-b)}\n\\end{equation}\n\n\\section{Include more divisions by two into an Engel expansion}\n\\label{sec:include_divisions_engel_expansion}\nIn order to calculate the largest possible $v_{n+1}$, we have thus far considered Engel expansions which contain only $n$ division by two within a Collatz sequence of $n+1$ members. In the following, we include $m$ additional divisions by two and thus a total of $m+n$ divisions. Now we examine two corner cases:\n\\begin{itemize}\n\t\\item the one where we do the additional $m$ divisions by $2$ at the end and\n\t\\item the one where we do these additional divisions at the very beginning.\n\\end{itemize}\n\n\\par\\noindent\n\\textbf{The first case} is our starting point to examine how swapping a division by two affects the node $v_{n+1}$. For this, let us compare the Engel expansion where we divide by $2^m$ afterwards with one where we divide by $2$ in the penultimate step and by $2^{m-1}$ in last step. One can immediately recognize the following inequality with a mere look:\n\\[\n\\cfrac{1+\\cfrac{3+\\cfrac{3^2+\\cfrac{3^3+3^4v_1}{2}}{2}}{2}}{2\\cdot2^m}\n<\n\\cfrac{1+\\cfrac{3+\\cfrac{3^2+\\cfrac{3^3+3^4v_1}{2}}{2}}{2\\cdot\\textcolor{red}{\\mathbf{2}}}}{2\\cdot2^{m-1}}\n\\]\n\nTo put it simply, in the expansion on the right side of the above-shown inequality we perform one division by two a little bit earlier as we do it in the expansion on the left side of the expansion. Almost all summands of both expansions cancel out each other:\n\n\\[\n\\frac{1}{2\\cdot2^m}+\\cancel{\\frac{3}{2^2\\cdot2^m}+\\frac{3^2}{2^3\\cdot2^m}+\\frac{3^3+3^4v_1}{2^4\\cdot2^m}}\n<\n\\frac{1}{2\\cdot2^{m-1}}+\\cancel{\\frac{3}{2^2\\cdot\\textcolor{red}{\\mathbf{2}}\\cdot2^{m-1}}+\\frac{3^2}{2^3\\cdot\\textcolor{red}{\\mathbf{2}}\\cdot2^{m-1}}\\frac{3^3+3^4v_1}{2^4\\cdot\\textcolor{red}{\\mathbf{2}}\\cdot2^{m-1}}}\n\\]\n\n\\par\\bigskip\\noindent\n\\textbf{The second case} deals with Engel expansions where we perform that additional $m$ divisions by two as early as possible. The resulting value decreases, when we make a division by two later:\n\\[\n\\cfrac{1+\\cfrac{3+\\cfrac{3^2+\\cfrac{3^3+3^4v_1}{2\\cdot2^{m-1}}}{2\\cdot\\textcolor{red}{\\mathbf{2}}}}{2}}{2}\n<\n\\cfrac{1+\\cfrac{3+\\cfrac{3^2+\\cfrac{3^3+3^4v_1}{2\\cdot2^m}}{2}}{2}}{2}\n\\]\n\nAlso here almost all summands of both Engel expansions cancel each other out:\n\n\\[\n\\cancel{\\frac{1}{2}+\\frac{3}{2^2}}+\\frac{3^2}{2^3\\cdot\\textcolor{red}{\\mathbf{2}}}+\\cancel{\\frac{3^3+3^4v_1}{2^4\\cdot\\textcolor{red}{\\mathbf{2}}\\cdot2^{m-1}}}\n<\n\\cancel{\\frac{1}{2}+\\frac{3}{2^2}}+\\frac{3^2}{2^3}+\\cancel{\\frac{3^3+3^4v_1}{2^4\\cdot2^m}}\n\\]\n\n\\par\\medskip\nWhile the first case minimizes the value of the node $v_{n+1}$, the second case maximizes it. The difference between the maximum and the minimum is given by the following equation:\n\n\\begin{flalign*}\n\t&\\frac{3^{n-1}\\left(\\frac{3v_1+1}{2\\cdot2^m}+1\\right)-2^{n-1}}{2^{n-1}}-\\frac{3^n\\left(v_1+1\\right)-2^n}{2^{n+m}}\\\\\n\t=&\\frac{3^{n-1}\\cdot\\left(3v_1+1+2^{m+1}\\right)-2^{n-1}\\cdot2^{m+1}-3^n\\left(v_1+1\\right)+2^n}{2^{m+1}\\cdot2^{n-1}}\\\\\n\t=&\\frac{3^{n-1}+3^{n-1}\\cdot2^{m+1}-2^{n+m}-3^n+2^n}{2^{n+m}}=\\frac{3^{n-1}-3\\cdot3^{n-1}+3^{n-1}\\cdot2^{m+1}-2^{n+m}+2^n}{2^{n+m}}\\\\\n\t=&\\frac{-2\\cdot3^{n-1}+3^{n-1}\\cdot2^{m+1}-2^{n+m}+2^n}{2^{n+m}}=\\frac{\\left(2\\cdot3^{n-1}-2^n\\right)\\left(2^m-1\\right)}{2^n\\cdot2^m}\\\\\n\t=&\\left(\\frac{3^{n-1}}{2^{n-1}}-1\\right)\\left(1-\\frac{1}{2^m}\\right)\n\\end{flalign*}\n\nThis has the consequence that for a given sequence consisting of $n+1$ members, between which a total of $n+m$ divisions have taken place, the permutation of these divisions has a very limited effect on the node $v_{n+1}$ as described by theorem~\\ref{theo:permutation}.\n\n\\par\\medskip\n\\begin{theorem}\n\t\\label{theo:permutation}\n\tLet $v_{n+1},v_n,\\ldots,v_2,v_1$ be a sequence in which a total of $n+m$ divisions took place (a path in which a total of $n+m$ edges has been contracted). No matter how these divisions are permuted, i.e. performed sooner or later, the node $v_{n+1}$ can differ at most by the following product:\n\t\\[\n\t\\left(\\frac{3^{n-1}}{2^{n-1}}-1\\right)\\left(1-\\frac{1}{2^m}\\right)\n\t\\]\n\\end{theorem}\n\n\\section{The product in the condition for alpha's upper limit}\nLet us take a closer look at the product contained in condition~\\ref{eq:condition_max} for the case $k=3$ and use the ascending continued fractions for examining this product. The exciting question is, does this product have a limit value even in the case where we only contract a single edge between successive nodes? Setting the according sequence, which maximizes $v_{n+1}$, into the product expressed by condition~\\ref{eq:condition_max}, we obtain a product that is limited, or to be more specific, which in the worst case $v_1=1$ converges (for $n$ to infinity) towards $2$:\n\\begin{equation}\n\\label{eq:product_simplification_k3}\n\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_{i}}\\right)\n=\\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\\end{equation}\n\nThe above-illustrated last forming step, simplifies this product significantly into an expression waiving a product formulation. A detailed breakdown including all intermediate steps of this simplification is shown in the appendix~\\ref{appx:product_simplification_k3}. The correctness of this simplification can be proven inductively too, which we detail in appendix~\\ref{appx:proof_product_simplification_k3}. The most important and the most interesting aspect of this result is, that the above simplified term cannot exceed the value $2$, whatever you choose to insert into $n$ or into $v_1$:\n\\[\n\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^{n+1}+1<2\n\\]\n\nAs demonstrated above, since the product cannot exceed the value $2$, the logarithmic product expression in the condition~\\ref{eq:condition_max} cannot exceed the value one and this condition becomes a consistently true statement:\n\\[\nn\\log_23-\\lfloor n\\log_23\\rfloor<2-1\n\\]\n\nThus, for $k=3$ the condition~\\ref{eq:condition_max} for alphas's upper limit is met for all sequences that maximize $v_{n+1}$.\n\n\\section{Include additional divisions into the product}\nHow does the product, contained in condition~\\ref{eq:condition_max} look if we include the additional $m$ divisions into the Engel expansion as per section~\\ref{sec:include_divisions_engel_expansion}? To answer this question, we consider the sequence $v_{n+1},v_n,v_{n-1},\\ldots,v_2,v_1$ and we set $v_2=\\frac{3v_1+1}{2\\cdot2^{m}}$. Then reusing the continued fraction given by equation~\\ref{eq:asc_continued_fraction}, we obtain:\n\n{\\setlength{\\jot}{1.2em}\n\\begin{flalign}\n\\label{eq:asc_continued_fraction_m}\nv_{n+1}&=\\cfrac{3\\cfrac{3\\cfrac{3\\cfrac{3v_1+1}{2\\cdot2^m}+1}{2}+1}{2}+1}{2}\\dotsb\n=\\cfrac{3\\cfrac{3\\cfrac{3v_2+1}{2}+1}{2}+1}{2}\\dotsb\n=\\frac{3^{n-1}(v_2+1)-2^{n-1}}{2^{n-1}}\\\\\n\\notag\n&=\\frac{3^{n-1}(\\frac{3v_1+1}{2\\cdot2^{m}}+1)-2^{n-1}}{2^{n-1}}=\\frac{3^nv_1+3^{n-1}+3^{n-1}2^{m+1}}{2^{m+n}}-1\n\\end{flalign}}\n\n\\par\\noindent\nThe product will be calculated by using equation~\\ref{eq:product_simplification_k3}:\n\\begin{flalign}\n\\label{eq:product_k3_m}\n\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_{i}}\\right)&=\\left(1+\\frac{1}{3v_1}\\right)\\cdot\\prod_{i=2}^{n}\\left(1+\\frac{1}{3v_{i}}\\right)\\\\\n\\notag\n&=\\left(1+\\frac{1}{3v_1}\\right)\\cdot\\prod_{i=1}^{n-1}\\left(1+\\frac{1}{3v_{i+1}}\\right)=\\left(1+\\frac{1}{3v_1}\\right)\\cdot\\left(\\frac{1}{v_2}-\\frac{1}{v_2}\\left(\\frac{2}{3}\\right)^{n-1}+1\\right)\n\\end{flalign}\n\n\\par\\noindent\nFinally substituting $v_2=\\frac{3v_1+1}{2\\cdot2^{m}}$ into equation~\\ref{eq:product_k3_m} leads to the simplified formula of the product:\n\\begin{equation}\n\\label{eq:product_simplification_k3_m}\n\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_{i}}\\right)=\\left(1+\\frac{1}{3v_1}\\right)\\cdot\\frac{1-\\left(\\frac{2}{3}\\right)^{n-1}+v_2}{v_2}=\\frac{1+2^{m+1}}{3v_1}-\\frac{2^m}{v_1}\\left(\\frac{2}{3}\\right)^n+1\n\\end{equation}\n\n\\begin{example}\n\tAn example provides the sequence $v_1=661$, $v_2=31$, $v_3=47$, $v_4=71$, $v_5=107$. When we input $v_1=661$ with $m=5$ and $n=4$ into equation~\\ref{eq:asc_continued_fraction_m} we retrieve the label of the vertex $v_5$:\n\t\\[\n\tv_5=v_{n+1}=\\frac{3^4\\cdot661+3^3+3^3\\cdot2^6}{2^9}-1=107\n\t\\]\n\tIn this sequence five $(m=5)$ additional divisions by two took place in the first step using $v_1$:\n\t\\[\n\t\\frac{3\\cdot661-1}{2\\cdot2^5}=v_2=31\n\t\\]\n\tLet us now verify the formula for the product by taking this particular example. To this end, we input $v_1=661$ together with $m=5$ and $n=4$ into equation~\\ref{eq:product_simplification_k3_m}:\n\t\\[\n\t\\left(1+\\frac{1}{3\\cdot661}\\right)\\left(1+\\frac{1}{3\\cdot31}\\right)\\left(1+\\frac{1}{3\\cdot47}\\right)\\left(1+\\frac{1}{3\\cdot71}\\right)=\\frac{1+2^{6}}{3\\cdot661}-\\frac{2^5}{661}\\left(\\frac{2}{3}\\right)^4+1=1.023215853\n\t\\]\n\\end{example}\n\n\\section{Condition for a limited growth of the Engel expansion}\n\\label{sec:condition_limited_growth}\nLet us look now into the question of what condition must be met to prevent a greater growth than a decline in Collatz sequences. Specifically, we consider an Engel expansion comprising $n+1$ sequence members that include $m$ additional divisions by two at the beginning. The last member $v_{n+1}$ in such a sequence can be calculated by formula~\\ref{eq:asc_continued_fraction_m}. In order to restrict the growth of this sequence, we require that the last member has to be smaller than the first one. For this we define the condition $v_{n+1}<v_1$:\n\n\\[\n\\frac{3^nv_1+3^{n-1}+3^{n-1}2^{m+1}}{2^{m+n}}-1<v_1\n\\]\n\nBy transforming this inequality, which is thoroughly described in the appendix~\\ref{appx:condition_limited_growth} step by step, we obtain the condition:\n\n\\begin{equation}\n\\label{eq:condition_limited_growth}\n\t\\frac{3^{n-1}\\left(2^{m+1}-2\\right)}{2^{m+n}-3^n}-1<v_1\n\\end{equation}\n\n\\section{Engel expansions maximize the product}\nThe question which sequence maximizes the target node $v_{n+1}$ ties into the question which sequence maximizes the product in the condition for cycle-alpha's upper limit given by equation~\\ref{eq:condition_max}. The product formula that do not depend from all vertices $v_1,v_2,\\ldots v_n$ has been evolved in appendix~\\ref{appx:product_formula_depending_v1}. This formula depends only from $2^\\alpha$, from the starting node $v_1$ and the target node $v_{n+1}$:\n\n\\[\n\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_i}\\right)=\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}v_{n+1}}{k^nv_1}\n\\]\n\nIn order to maximize this product, one needs to maximize the target node $v_{n+1}$, which is exactly what the Engel expansion does. Hence, for a given $v_1$, the Engel expansion is the worst case sequence maximizing the product in the condition for cycle-alpha's upper limit.\n", "meta": {"hexsha": "0939cce0a725d0b3fe8917eb959d7434536b9ad7", "size": 13616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v5.0/chapter/04_maximizing_target_node.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v6.0/chapter/04_maximizing_target_node.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v6.0/chapter/04_maximizing_target_node.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.7412935323, "max_line_length": 594, "alphanum_fraction": 0.7128378378, "num_tokens": 5067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6623820436729972}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n %\\subsection{Circuits in a graph}\n \\begin{thm}\n Let $E$ be the edge set of a graph $G$ and let $\\mathcal{C}$ be the edge sets of cycles in $G$.\\\\\n \\noindent Then $\\mathcal{C}$ is the set of circuits of a matroid.\n \\end{thm}\n\n\\begin{proof}\nLet $A, B \\in \\mathcal{C}, A \\neq B $ and let $e \\in A \\cap B .$\n\n\\vspace{1mm}\n\n\\noindent We must now construct a minimal cycle of $G$ whose edge set is contained in $(A \\cup B) \\setminus \\{e\\}.$\\\\\n\\noindent For $ i = 1,2,3,...... $ let $P_1$ be a path whose edge set is $ A \\setminus \\{e\\}.$\\\\\n\\noindent $ A \\setminus \\{e\\} \\in \\mathcal{I} $ therefore $P_1$ is not a cycle of $G$. This path will traverse from the edge $a_j$ to $a_u$ where $u,j$ were the vertices connecting the edge e to $(A \\cup B) \\setminus \\{e\\}$ to make $A \\cup B$.\\\\\n\\noindent Now perform the same procedure for a path $P_2$ whose edge set is $B \\setminus \\{e\\}.$\\\\\n\\noindent $P_1$ and $P_2$ should meet at the junctions $u,v$,  where $e$ was removed to make $ (A \\cup B) \\setminus \\{e\\}.$\\\\\n\\noindent Therefore $P_1 \\cup P_2$ should be a cycle of $G$.\\\\\n\\noindent $\\implies$ (C3) holds.\\\\\n\\noindent $\\implies \\mathcal{C}$ is the set of circuits in $G$.\\\\\n\\end{proof}\n\\end{document}", "meta": {"hexsha": "3648058acab088ffd9d5f91c146dd01e33e378f7", "size": 1251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/char12.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/char12.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/char12.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": 54.3913043478, "max_line_length": 245, "alphanum_fraction": 0.6506794564, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6623820328159161}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Let $z = 3 + 3i$ be a complex number written in standard form. Convert $z$ to polar form, and write it in the form $z = re^{i\\theta}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $z = 2i$ be a complex number written in standard form. Convert $z$ to polar form, and write it in the form $z = re^{i\\theta}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $z = 4e^{\\frac{2\\pi}{3}i}$ be a complex number written in polar form. Convert $z$ to standard form, and write it in the form $z = a+bi$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $z = -1e^{\\frac{\\pi}{6}i}$ be a complex number written in polar form. Convert $z$ to standard form, and write it in the form $z = a+bi$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} If $z$ and $w$ are two complex numbers and the polar form of $z$\ninvolves the angle $\\theta $ while the polar form of $w$ involves the angle\n$\\phi$, show that in the polar form for $zw$ the angle involved is $\\theta\n+\\phi$.\n\\begin{sol}\n You have $z=\\abs{z}(\\cos\n\\theta +i\\sin \\theta) $ and $w=\\abs{w}(\\cos\n\\phi +i\\sin \\phi)$. Then when you multiply these, you get\n\\begin{eqnarray*}\n&&\\abs{z}\\abs{w}(\\cos \\theta +i\\sin\n\\theta) (\\cos \\phi +i\\sin \\phi) \\\\\n&=&\\abs{z}\\abs{w}(\\cos \\theta \\cos\n\\phi -\\sin \\theta \\sin \\phi +i(\\cos \\theta \\sin \\phi +\\cos \\phi \\sin\n\\theta)) \\\\\n&=&\\abs{z}\\abs{w}(\\cos (\\theta\n+\\phi) +i\\sin (\\theta +\\phi))\n\\end{eqnarray*}\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "41965b7bf08d95f9b69cc692a942f3d4b26e8fb9", "size": 1427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/ComplexNumbers-PolarForm.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/ComplexNumbers-PolarForm.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/ComplexNumbers-PolarForm.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.1860465116, "max_line_length": 151, "alphanum_fraction": 0.6377014716, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145405, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.662382030407191}}
{"text": "\\section{Appendix}\n\n% ===\n\\emph{Complete the square:}\nIf $p(\\bm x) \\propto \\exp(-\\frac12 \\bm x\\!^\\top \\!\\bm{{\\color{OrangeRed} A}x} + \\bm x\\!^\\top \\begingroup \\color{OrangeRed} \\bm b \\endgroup)$,\nthen $p(\\bm x) = \\Gauss{\\bm x \\mid \\bm A^{-1} \\bm b, \\bm A^{-1}}$\n\n% ===\n\\emph{Constrained optimisation:}\n\\\\\n\\textit{primal}: \\enspace $\\min_{\\bm x} f(\\bm x)$ \\enspace s.t. \\enspace $g_i(\\bm x) = 0$; \\enspace $h_j(\\bm x) \\leq 0$\n\\\\\n\\textbf{Lagrangian:} \\enspace with each $\\alpha_j \\geq 0$\\\\\n\\enspace $\\mathcal L(\\bm x,\\lambda,\\alpha) = f(\\bm x) + \\sum_i \\lambda_i g_i(\\bm x) + \\sum_j \\alpha_j h_j(\\bm x)$\n\\\\\nSolve: \\: $\\pderiv{\\mathcal L}{\\bm x} = 0$; \\: $g_i(\\bm x) = 0$; \\: $\\alpha_j \\geq 0$; \\: $h_j(\\bm x) \\leq 0$\n\\\\\nIf \\textbf{Slater's cond.} holds, $\\exists \\bm x : g_i(\\bm x) = 0, h_j(\\bm x) {\\color{red}\\,<\\,} 0$, then we can solve the \\textit{dual} instead:\\\\\n\\enskip $\\max_{\\bm \\lambda, \\bm \\alpha} \\brace{ \\min_{\\bm x} \\mathcal L(\\bm x, \\bm \\lambda, \\bm \\alpha) }$ \\: s.t. \\: $\\alpha_j \\geq 0$\\\\\nSolve: \\: $\\pderiv{\\mathcal L}{\\bm x} = 0$; \\: $\\pderiv{\\mathcal L}{\\bm \\lambda} = 0$; \\: $\\alpha_j h_j(\\bm x) {\\color{red}\\,=\\,} 0$; \\: $\\alpha_j \\geq 0$\n\n\\iffalse\n    \\emph{Lagrange Multipliers: \\color{red} OLD VERSION}\n    \\\\\n    Problem $\\mathcal P : \\begin{cases}\n        \\min f(\\bm x),      & \\bm x\\in\\mathbb R^d \\\\\n        \\text{s.t. } g_i(\\bm x)=0,      & i\\leq m \\\\\n        \\phantom{\\text{s.t. }} h_j(\\bm x) \\leq 0,       & j\\leq n\n    \\end{cases}$\n    \\\\\n    Lagrangian: $\\mathcal L(\\bm x,\\lambda,\\alpha) = f(\\bm x) + \\sum_{i\\leq m} \\lambda_i g_i(\\bm x) + \\sum_{j\\leq n} \\alpha_j h_j(\\bm x)$ with each $\\alpha_j \\geq 0$.\n    \\\\\n    Solution must satisfy\n    $\\pderiv{\\mathcal L}{\\bm x} = 0$ and $\\pderiv{\\mathcal L}{\\lambda} = 0$,\n    $\\alpha_j h_j(\\bm x) = 0$, and\n    $\\alpha_j \\geq 0, \\forall j\\leq n$.\n\\fi\n\n\\iffalse\n    \\emph{Euler-Lagrange:}\n    Find extrema of functional $\\mathcal F[f] = \\int G(x, f(x), f’(x)) \\diff x$,\n    thus $\\pderiv{\\mathcal F}{f} \\overset!= 0$.\n    \\\\\n    If $G$ is twice diff'able, then\n    \\\\\n    $\\pderiv{\\mathcal F}{f} = \\pderiv{G}{f(x)} - \\deriv{}{x} \\paren*{ \\pderiv{G}{f'(x)} } \\overset{(\\ast)}= \\pderiv{G}{f(x)}$.\n    \\\\\n    $(\\ast)$ : when $G$ does not depend on $f'$.\n\\fi\n\n\n% ===\n\\emph{Metrics:}\n$\\mathit{acc} = \\frac{\\mathrm{TP} + \\mathrm{TN}}{n}$\n$\\mathit{prec} = \\frac{\\mathrm{TP}}{\\mathrm{TP} + \\mathrm{FP}}$\n$\\mathit{FPR} = \\frac{\\mathrm{FP}}{\\mathrm{FP} + \\mathrm{TN}}$\n$\\mathit{Recall/TPR} = \\frac{\\mathrm{TP}}{\\mathrm{TP} + \\mathrm{FN}}$\n$\\mathit{balanced\\:acc} = \\frac1n \\sum_i \\mathit{TPR}_i$\n$\\mathit{F1\\!-\\!score} = \\frac{2 \\mathrm{TP}}{2 \\mathrm{TP} + \\mathrm{FP} + \\mathrm{FN}}$\n$\\mathit{ROC} = \\mathit{FPR} / \\mathit{TPR}$\n\n\n% ===\n\\emph{Conditional Gaussians:}\\\\\n$P_{X,Y} = \\begin{bmatrix} \\bm X \\\\ \\bm Y \\end{bmatrix} \\sim\n\\Gauss*[~]{\n    \\begin{bmatrix} \\bm\\mu_X \\\\ \\bm\\mu_Y \\end{bmatrix} ,\n    \\begin{bmatrix} \\bm\\Sigma_{XX} & \\bm\\Sigma_{XY} \\\\ \\bm\\Sigma_{YX} & \\bm\\Sigma_{YY} \\end{bmatrix}\n}$,\\enspace $\\bm\\Sigma_{ij}$ p.s.d.\n\n\\iffalse\n    $\\implies X\\vert Y \\sim \\Gauss{\\tilde{\\bm\\mu}, \\tilde{\\bm\\Sigma}}$,\\enskip where\n    $\\tilde{\\bm\\mu} = \\bm\\mu_X + \\bm\\Sigma_{XY} \\bm\\Sigma_{YY}^{-1} (Y - \\bm\\mu_Y)$,\\enskip\n    $\\tilde{\\bm\\Sigma} = \\bm\\Sigma_{XX} - \\bm\\Sigma_{XY} \\bm\\Sigma_{YY}^{-1} \\bm\\Sigma_{YX})$\n\\fi\n\n$\\implies Y\\vert X \\sim \\Gauss{\\tilde{\\bm\\mu}, \\tilde{\\bm\\Sigma}}$,\\enskip where\n$\\tilde{\\bm\\mu} = \\bm\\mu_Y + \\bm\\Sigma_{YX} \\bm\\Sigma_{XX}^{-1} (X - \\bm\\mu_X)$,\\enskip\n$\\tilde{\\bm\\Sigma} = \\bm\\Sigma_{YY} - \\bm\\Sigma_{YX} \\bm\\Sigma_{XX}^{-1} \\bm\\Sigma_{XY})$\n\n% ===\n", "meta": {"hexsha": "7c84cc25dc2ba31ed40f7eb0f655986d9919fd8b", "size": 3552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/99_appendix.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/AML20/sections/99_appendix.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/AML20/sections/99_appendix.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3170731707, "max_line_length": 165, "alphanum_fraction": 0.5596846847, "num_tokens": 1574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8056321913146128, "lm_q1q2_score": 0.6623820273873755}}
{"text": "%           Copyright Matthew Pulver 2018 - 2019.\n% Distributed under the Boost Software License, Version 1.0.\n%     (See accompanying file LICENSE_1_0.txt or copy at\n%           https://www.boost.org/LICENSE_1_0.txt)\n\n\\documentclass{article}\n\\usepackage{amsmath} %\\usepackage{mathtools}\n\\usepackage{amssymb} %\\mathbb\n\\usepackage{array} % m{} column in tabular\n\\usepackage{csquotes} % displayquote\n\\usepackage{fancyhdr}\n\\usepackage{fancyvrb}\n\\usepackage[margin=0.75in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n%\\usepackage{listings}\n\\usepackage{multirow}\n\\usepackage[super]{nth}\n\\usepackage{wrapfig}\n\\usepackage{xcolor}\n\n\\hypersetup{%\n  colorlinks=false,% hyperlinks will be black\n  linkbordercolor=blue,% hyperlink borders will be red\n  urlbordercolor=blue,%\n  pdfborderstyle={/S/U/W 1}% border style will be underline of width 1pt\n}\n\n\\pagestyle{fancyplain}\n\\fancyhf{}\n\\renewcommand{\\headrulewidth}{0pt}\n\\cfoot[]{\\thepage\\\\\n\\scriptsize\\color{gray} Copyright \\textcopyright\\/ Matthew Pulver 2018--2019.\nDistributed under the Boost Software License, Version 1.0.\\\\\n(See accompanying file LICENSE\\_1\\_0.txt or copy at\n\\url{https://www.boost.org/LICENSE\\_1\\_0.txt})}\n\n\\DeclareMathOperator{\\sinc}{sinc}\n\n\\begin{document}\n\n\\title{Autodiff\\\\\n\\large Automatic Differentiation C++ Library}\n\\author{Matthew Pulver}\n\\maketitle\n\n%\\date{}\n\n%\\begin{abstract}\n%\\end{abstract}\n\n\\tableofcontents\n\n%\\section{Synopsis}\n%\\begingroup\n%\\fontsize{10pt}{10pt}\\selectfont\n%\\begin{verbatim}\n% example/synopsis.cpp\n%\\end{verbatim}\n%\\endgroup\n\n\\newpage\n\n\\section{Description}\n\nAutodiff is a header-only C++ library that facilitates the\n\\href{https://en.wikipedia.org/wiki/Automatic_differentiation}{automatic differentiation} (forward mode) of\nmathematical functions of single and multiple variables.\n\nThis implementation is based upon the \\href{https://en.wikipedia.org/wiki/Taylor_series}{Taylor series} expansion of\nan analytic function $f$ at the point $x_0$:\n\n\\begin{align*}\nf(x_0+\\varepsilon) &= f(x_0) + f'(x_0)\\varepsilon + \\frac{f''(x_0)}{2!}\\varepsilon^2 + \\frac{f'''(x_0)}{3!}\\varepsilon^3 + \\cdots \\\\\n  &= \\sum_{n=0}^N\\frac{f^{(n)}(x_0)}{n!}\\varepsilon^n + O\\left(\\varepsilon^{N+1}\\right).\n\\end{align*}\nThe essential idea of autodiff is the substitution of numbers with polynomials in the evaluation of $f(x_0)$. By\nsubstituting the number $x_0$ with the first-order polynomial $x_0+\\varepsilon$, and using the same algorithm\nto compute $f(x_0+\\varepsilon)$, the resulting polynomial in $\\varepsilon$ contains the function's derivatives\n$f'(x_0)$, $f''(x_0)$, $f'''(x_0)$, ...  within the coefficients. Each coefficient is equal to the derivative of\nits respective order, divided by the factorial of the order.\n\nIn greater detail, assume one is interested in calculating the first $N$ derivatives of $f$ at $x_0$. Without loss\nof precision to the calculation of the derivatives, all terms $O\\left(\\varepsilon^{N+1}\\right)$ that include powers\nof $\\varepsilon$ greater than $N$ can be discarded. (This is due to the fact that each term in a polynomial depends\nonly upon equal and lower-order terms under arithmetic operations.) Under these truncation rules, $f$ provides a\npolynomial-to-polynomial transformation:\n\n\\[\nf \\qquad : \\qquad x_0+\\varepsilon \\qquad \\mapsto \\qquad\n    \\sum_{n=0}^Ny_n\\varepsilon^n=\\sum_{n=0}^N\\frac{f^{(n)}(x_0)}{n!}\\varepsilon^n.\n\\]\nC++'s ability to overload operators and functions allows for the creation of a class {\\tt fvar}\n(\\underline{f}orward-mode autodiff \\underline{var}iable) that represents polynomials in $\\varepsilon$. Thus\nthe same algorithm $f$ that calculates the numeric value of $y_0=f(x_0)$, when\nwritten to accept and return variables of a generic (template) type, is also used to calculate the polynomial\n$\\sum_{n=0}^Ny_n\\varepsilon^n=f(x_0+\\varepsilon)$. The derivatives $f^{(n)}(x_0)$ are then found from the\nproduct of the respective factorial $n!$ and coefficient $y_n$:\n\n\\[ \\frac{d^nf}{dx^n}(x_0)=n!y_n. \\]\n\n\\section{Examples}\n\n\\subsection{Example 1: Single-variable derivatives}\n\n\\subsubsection{Calculate derivatives of $f(x)=x^4$ at $x=2$.}\n\nIn this example, {\\tt make\\_fvar<double, Order>(2.0)} instantiates the polynomial $2+\\varepsilon$. The {\\tt Order=5}\nmeans that enough space is allocated (on the stack) to hold a polynomial of up to degree 5 during the proceeding\ncomputation.\n\nInternally, this is modeled by a {\\tt std::array<double,6>} whose elements {\\tt \\{2, 1, 0, 0, 0, 0\\}} correspond\nto the 6 coefficients of the polynomial upon initialization. Its fourth power, at the end of the computation, is\na polynomial with coefficients {\\tt y = \\{16, 32, 24, 8, 1, 0\\}}.  The derivatives are obtained using the formula\n$f^{(n)}(2)=n!*{\\tt y[n]}$.\n\n\\begin{verbatim}\n#include <boost/math/differentiation/autodiff.hpp>\n#include <iostream>\n\ntemplate <typename T>\nT fourth_power(T const& x) {\n  T x4 = x * x;  // retval in operator*() uses x4's memory via NRVO.\n  x4 *= x4;      // No copies of x4 are made within operator*=() even when squaring.\n  return x4;     // x4 uses y's memory in main() via NRVO.\n}\n\nint main() {\n  using namespace boost::math::differentiation;\n\n  constexpr unsigned Order = 5;                  // Highest order derivative to be calculated.\n  auto const x = make_fvar<double, Order>(2.0);  // Find derivatives at x=2.\n  auto const y = fourth_power(x);\n  for (unsigned i = 0; i <= Order; ++i)\n    std::cout << \"y.derivative(\" << i << \") = \" << y.derivative(i) << std::endl;\n  return 0;\n}\n/*\nOutput:\ny.derivative(0) = 16\ny.derivative(1) = 32\ny.derivative(2) = 48\ny.derivative(3) = 48\ny.derivative(4) = 24\ny.derivative(5) = 0\n*/\n\\end{verbatim}\nThe above calculates\n\n\\begin{alignat*}{3}\n{\\tt y.derivative(0)} &=& f(2) =&& \\left.x^4\\right|_{x=2} &= 16\\\\\n{\\tt y.derivative(1)} &=& f'(2) =&& \\left.4\\cdot x^3\\right|_{x=2} &= 32\\\\\n{\\tt y.derivative(2)} &=& f''(2) =&& \\left.4\\cdot 3\\cdot x^2\\right|_{x=2} &= 48\\\\\n{\\tt y.derivative(3)} &=& f'''(2) =&& \\left.4\\cdot 3\\cdot2\\cdot x\\right|_{x=2} &= 48\\\\\n{\\tt y.derivative(4)} &=& f^{(4)}(2) =&& 4\\cdot 3\\cdot2\\cdot1 &= 24\\\\\n{\\tt y.derivative(5)} &=& f^{(5)}(2) =&& 0 &\n\\end{alignat*}\n\n\\subsection{Example 2: Multi-variable mixed partial derivatives with multi-precision data type}\\label{multivar}\n\\subsubsection{Calculate $\\frac{\\partial^{12}f}{\\partial w^{3}\\partial x^{2}\\partial y^{4}\\partial z^{3}}(11,12,13,14)$\nwith a precision of about 50 decimal digits,\\\\\nwhere $f(w,x,y,z)=\\exp\\left(w\\sin\\left(\\frac{x\\log(y)}{z}\\right)+\\sqrt{\\frac{wz}{xy}}\\right)+\\frac{w^2}{\\tan(z)}$.}\n\nIn this example, {\\tt make\\_ftuple<float50, Nw, Nx, Ny, Nz>(11, 12, 13, 14)} returns a {\\tt std::tuple} of 4\nindependent {\\tt fvar} variables, with values of 11, 12, 13, and 14, for which the maximum order derivative to\nbe calculated for each are 3, 2, 4, 3, respectively. The order of the variables is important, as it is the same\norder used when calling {\\tt v.derivative(Nw, Nx, Ny, Nz)} in the example below.\n\n\\begin{verbatim}\n#include <boost/math/differentiation/autodiff.hpp>\n#include <boost/multiprecision/cpp_bin_float.hpp>\n#include <iostream>\n\nusing namespace boost::math::differentiation;\n\ntemplate <typename W, typename X, typename Y, typename Z>\npromote<W, X, Y, Z> f(const W& w, const X& x, const Y& y, const Z& z) {\n  using namespace std;\n  return exp(w * sin(x * log(y) / z) + sqrt(w * z / (x * y))) + w * w / tan(z);\n}\n\nint main() {\n  using float50 = boost::multiprecision::cpp_bin_float_50;\n\n  constexpr unsigned Nw = 3;  // Max order of derivative to calculate for w\n  constexpr unsigned Nx = 2;  // Max order of derivative to calculate for x\n  constexpr unsigned Ny = 4;  // Max order of derivative to calculate for y\n  constexpr unsigned Nz = 3;  // Max order of derivative to calculate for z\n  // Declare 4 independent variables together into a std::tuple.\n  auto const variables = make_ftuple<float50, Nw, Nx, Ny, Nz>(11, 12, 13, 14);\n  auto const& w = std::get<0>(variables);  // Up to Nw derivatives at w=11\n  auto const& x = std::get<1>(variables);  // Up to Nx derivatives at x=12\n  auto const& y = std::get<2>(variables);  // Up to Ny derivatives at y=13\n  auto const& z = std::get<3>(variables);  // Up to Nz derivatives at z=14\n  auto const v = f(w, x, y, z);\n  // Calculated from Mathematica symbolic differentiation.\n  float50 const answer(\"1976.319600747797717779881875290418720908121189218755\");\n  std::cout << std::setprecision(std::numeric_limits<float50>::digits10)\n            << \"mathematica   : \" << answer << '\\n'\n            << \"autodiff      : \" << v.derivative(Nw, Nx, Ny, Nz) << '\\n'\n            << std::setprecision(3)\n            << \"relative error: \" << (v.derivative(Nw, Nx, Ny, Nz) / answer - 1) << '\\n';\n  return 0;\n}\n/*\nOutput:\nmathematica   : 1976.3196007477977177798818752904187209081211892188\nautodiff      : 1976.3196007477977177798818752904187209081211892188\nrelative error: 2.67e-50\n*/\n\\end{verbatim}\n\n\\subsection{Example 3: Black-Scholes Option Pricing with Greeks Automatically Calculated}\n\\subsubsection{Calculate greeks directly from the Black-Scholes pricing function.}\n\nBelow is the standard Black-Scholes pricing function written as a function template, where the price, volatility\n(sigma), time to expiration (tau) and interest rate are template parameters. This means that any Greek based on\nthese 4 variables can be calculated using autodiff. The below example calculates delta and gamma where the variable\nof differentiation is only the price. For examples of more exotic greeks, see {\\tt example/black\\_scholes.cpp}.\n\n\\begin{verbatim}\n#include <boost/math/differentiation/autodiff.hpp>\n#include <iostream>\n\nusing namespace boost::math::constants;\nusing namespace boost::math::differentiation;\n\n// Equations and function/variable names are from\n// https://en.wikipedia.org/wiki/Greeks_(finance)#Formulas_for_European_option_Greeks\n\n// Standard normal cumulative distribution function\ntemplate <typename X>\nX Phi(X const& x) {\n  return 0.5 * erfc(-one_div_root_two<X>() * x);\n}\n\nenum class CP { call, put };\n\n// Assume zero annual dividend yield (q=0).\ntemplate <typename Price, typename Sigma, typename Tau, typename Rate>\npromote<Price, Sigma, Tau, Rate> black_scholes_option_price(CP cp,\n                                                            double K,\n                                                            Price const& S,\n                                                            Sigma const& sigma,\n                                                            Tau const& tau,\n                                                            Rate const& r) {\n  using namespace std;\n  auto const d1 = (log(S / K) + (r + sigma * sigma / 2) * tau) / (sigma * sqrt(tau));\n  auto const d2 = (log(S / K) + (r - sigma * sigma / 2) * tau) / (sigma * sqrt(tau));\n  switch (cp) {\n    case CP::call:\n      return S * Phi(d1) - exp(-r * tau) * K * Phi(d2);\n    case CP::put:\n      return exp(-r * tau) * K * Phi(-d2) - S * Phi(-d1);\n  }\n}\n\nint main() {\n  double const K = 100.0;                    // Strike price.\n  auto const S = make_fvar<double, 2>(105);  // Stock price.\n  double const sigma = 5;                    // Volatility.\n  double const tau = 30.0 / 365;             // Time to expiration in years. (30 days).\n  double const r = 1.25 / 100;               // Interest rate.\n  auto const call_price = black_scholes_option_price(CP::call, K, S, sigma, tau, r);\n  auto const put_price = black_scholes_option_price(CP::put, K, S, sigma, tau, r);\n\n  std::cout << \"black-scholes call price = \" << call_price.derivative(0) << '\\n'\n            << \"black-scholes put  price = \" << put_price.derivative(0) << '\\n'\n            << \"call delta = \" << call_price.derivative(1) << '\\n'\n            << \"put  delta = \" << put_price.derivative(1) << '\\n'\n            << \"call gamma = \" << call_price.derivative(2) << '\\n'\n            << \"put  gamma = \" << put_price.derivative(2) << '\\n';\n  return 0;\n}\n/*\nOutput:\nblack-scholes call price = 56.5136\nblack-scholes put  price = 51.4109\ncall delta = 0.773818\nput  delta = -0.226182\ncall gamma = 0.00199852\nput  gamma = 0.00199852\n*/\n\\end{verbatim}\n\n\\section{Advantages of Automatic Differentiation}\nThe above examples illustrate some of the advantages of using autodiff:\n\\begin{itemize}\n\\item Elimination of code redundancy. The existence of $N$ separate functions to calculate derivatives is a form\n  of code redundancy, with all the liabilities that come with it:\n  \\begin{itemize}\n    \\item Changes to one function require $N$ additional changes to other functions. In the \\nth{3} example above,\n        consider how much larger and inter-dependent the above code base would be if a separate function were\n        written for \\href{https://en.wikipedia.org/wiki/Greeks\\_(finance)#Formulas\\_for\\_European\\_option\\_Greeks}\n        {each Greek} value.\n    \\item Dependencies upon a derivative function for a different purpose will break when changes are made to\n        the original function. What doesn't need to exist cannot break.\n    \\item Code bloat, reducing conceptual integrity. Control over the evolution of code is easier/safer when\n        the code base is smaller and able to be intuitively grasped.\n  \\end{itemize}\n\\item Accuracy of derivatives over finite difference methods. Single-iteration finite difference methods always\n   include a $\\Delta x$ free variable that must be carefully chosen for each application. If $\\Delta x$ is too\n   small, then numerical errors become large. If $\\Delta x$ is too large, then mathematical errors become large.\n   With autodiff, there are no free variables to set and the accuracy of the answer is generally superior to finite\n   difference methods even with the best choice of $\\Delta x$.\n\\end{itemize}\n\n\\section{Mathematics}\n\nIn order for the usage of the autodiff library to make sense, a basic understanding of the mathematics will help.\n\n\\subsection{Truncated Taylor Series}\n\nBasic calculus courses teach that a real \\href{https://en.wikipedia.org/wiki/Analytic_function}{analytic function}\n$f : D\\rightarrow\\mathbb{R}$ is one which can be expressed as a Taylor series at a point\n$x_0\\in D\\subseteq\\mathbb{R}$:\n\n\\[\nf(x) = f(x_0) + f'(x_0)(x-x_0) + \\frac{f''(x_0)}{2!}(x-x_0)^2 + \\frac{f'''(x_0)}{3!}(x-x_0)^3 + \\cdots\n\\]\nOne way of thinking about this form is that given the value of an analytic function $f(x_0)$ and its derivatives\n$f'(x_0), f''(x_0), f'''(x_0), ...$ evaluated at a point $x_0$, then the value of the function\n$f(x)$ can be obtained at any other point $x\\in D$ using the above formula.\n\nLet us make the substitution $x=x_0+\\varepsilon$ and rewrite the above equation to get:\n\n\\[\nf(x_0+\\varepsilon) = f(x_0) + f'(x_0)\\varepsilon + \\frac{f''(x_0)}{2!}\\varepsilon^2 + \\frac{f'''(x_0)}{3!}\\varepsilon^3 + \\cdots\n\\]\nNow consider $\\varepsilon$ as {\\it an abstract algebraic entity that never acquires a numeric value}, much like\none does in basic algebra with variables like $x$ or $y$. For example, we can still manipulate entities\nlike $xy$ and $(1+2x+3x^2)$ without having to assign specific numbers to them.\n\nUsing this formula, autodiff goes in the other direction. Given a general formula/algorithm for calculating\n$f(x_0+\\varepsilon)$, the derivatives are obtained from the coefficients of the powers of $\\varepsilon$\nin the resulting computation. The general coefficient for $\\varepsilon^n$ is\n\n\\[\\frac{f^{(n)}(x_0)}{n!}.\\]\nThus to obtain $f^{(n)}(x_0)$, the coefficient of $\\varepsilon^n$ is multiplied by $n!$.\n\n\\subsubsection{Example}\n\nApply the above technique to calculate the derivatives of $f(x)=x^4$ at $x_0=2$.\n\nThe first step is to evaluate $f(x_0+\\varepsilon)$ and simply go through the calculation/algorithm, treating\n$\\varepsilon$ as an abstract algebraic entity:\n\n\\begin{align*}\nf(x_0+\\varepsilon) &= f(2+\\varepsilon) \\\\\n &= (2+\\varepsilon)^4 \\\\\n &= \\left(4+4\\varepsilon+\\varepsilon^2\\right)^2 \\\\\n &= 16+32\\varepsilon+24\\varepsilon^2+8\\varepsilon^3+\\varepsilon^4.\n\\end{align*}\nEquating the powers of $\\varepsilon$ from this result with the above $\\varepsilon$-taylor expansion\nyields the following equalities:\n\n\\[\nf(2) = 16, \\qquad\nf'(2) = 32, \\qquad\n\\frac{f''(2)}{2!} = 24, \\qquad\n\\frac{f'''(2)}{3!} = 8, \\qquad\n\\frac{f^{(4)}(2)}{4!} = 1, \\qquad\n\\frac{f^{(5)}(2)}{5!} = 0.\n\\]\nMultiplying both sides by the respective factorials gives\n\n\\[\nf(2) = 16, \\qquad\nf'(2) = 32, \\qquad\nf''(2) = 48, \\qquad\nf'''(2) = 48, \\qquad\nf^{(4)}(2) = 24, \\qquad\nf^{(5)}(2) = 0.\n\\]\nThese values can be directly confirmed by the \\href{https://en.wikipedia.org/wiki/Power_rule}{power rule}\napplied to $f(x)=x^4$.\n\n\\subsection{Arithmetic}\n\nWhat was essentially done above was to take a formula/algorithm for calculating $f(x_0)$ from a number $x_0$,\nand instead apply the same formula/algorithm to a polynomial $x_0+\\varepsilon$. Intermediate steps operate on\nvalues of the form\n\n\\[\n{\\bf x} = x_0 + x_1\\varepsilon + x_2\\varepsilon^2 +\\cdots+ x_N\\varepsilon^N\n\\]\nand the final return value is of this polynomial form as well. In other words, the normal arithmetic operators\n$+,-,\\times,\\div$ applied to numbers $x$ are instead applied to polynomials $\\bf x$. Through the overloading of C++\noperators and functions, floating point data types are replaced with data types that represent these polynomials. More\nspecifically, C++ types such as {\\tt double} are replaced with {\\tt std::array<double,N+1>}, which hold the above\n$N+1$ coefficients $x_i$, and are wrapped in a {\\tt class} that overloads all of the arithmetic operators.\n\nThe logic of these arithmetic operators simply mirror that which is applied to polynomials. We'll look at\neach of the 4 arithmetic operators in detail.\n\n\\subsubsection{Addition}\n\nThe addition of polynomials $\\bf x$ and $\\bf y$ is done component-wise:\n\n\\begin{align*}\n{\\bf z} &= {\\bf x} + {\\bf y} \\\\\n &= \\left(\\sum_{i=0}^Nx_i\\varepsilon^i\\right) + \\left(\\sum_{i=0}^Ny_i\\varepsilon^i\\right) \\\\\n &= \\sum_{i=0}^N(x_i+y_i)\\varepsilon^i \\\\\nz_i &= x_i + y_i \\qquad \\text{for}\\; i\\in\\{0,1,2,...,N\\}.\n\\end{align*}\n\n\\subsubsection{Subtraction}\n\nSubtraction follows the same form as addition:\n\n\\begin{align*}\n{\\bf z} &= {\\bf x} - {\\bf y} \\\\\n &= \\left(\\sum_{i=0}^Nx_i\\varepsilon^i\\right) - \\left(\\sum_{i=0}^Ny_i\\varepsilon^i\\right) \\\\\n &= \\sum_{i=0}^N(x_i-y_i)\\varepsilon^i \\\\\nz_i &= x_i - y_i \\qquad \\text{for}\\; i\\in\\{0,1,2,...,N\\}.\n\\end{align*}\n\n\\subsubsection{Multiplication}\n\nMultiplication produces higher-order terms:\n\n\\begin{align*}\n{\\bf z} &= {\\bf x} \\times {\\bf y} \\\\\n &= \\left(\\sum_{i=0}^Nx_i\\varepsilon^i\\right) \\left(\\sum_{i=0}^Ny_i\\varepsilon^i\\right) \\\\\n &= x_0y_0 + (x_0y_1+x_1y_0)\\varepsilon + (x_0y_2+x_1y_1+x_2y_0)\\varepsilon^2 + \\cdots +\n    \\left(\\sum_{j=0}^Nx_jy_{N-j}\\right)\\varepsilon^N + O\\left(\\varepsilon^{N+1}\\right) \\\\\n &= \\sum_{i=0}^N\\sum_{j=0}^ix_jy_{i-j}\\varepsilon^i + O\\left(\\varepsilon^{N+1}\\right) \\\\\nz_i &= \\sum_{j=0}^ix_jy_{i-j} \\qquad \\text{for}\\; i\\in\\{0,1,2,...,N\\}.\n\\end{align*}\nIn the case of multiplication, terms involving powers of $\\varepsilon$ greater than $N$, collectively denoted\nby $O\\left(\\varepsilon^{N+1}\\right)$, are simply discarded. Fortunately, the values of $z_i$ for $i\\le N$ do not\ndepend on any of these discarded terms, so there is no loss of precision in the final answer. The only information\nthat is lost are the values of higher order derivatives, which we are not interested in anyway. If we were, then\nwe would have simply chosen a larger value of $N$ to begin with.\n\n\\subsubsection{Division}\n\nDivision is not directly calculated as are the others. Instead, to find the components of\n${\\bf z}={\\bf x}\\div{\\bf y}$ we require that ${\\bf x}={\\bf y}\\times{\\bf z}$. This yields\na recursive formula for the components $z_i$:\n\n\\begin{align*}\nx_i &= \\sum_{j=0}^iy_jz_{i-j} \\\\\n &= y_0z_i + \\sum_{j=1}^iy_jz_{i-j} \\\\\nz_i &= \\frac{1}{y_0}\\left(x_i - \\sum_{j=1}^iy_jz_{i-j}\\right) \\qquad \\text{for}\\; i\\in\\{0,1,2,...,N\\}.\n\\end{align*}\nIn the case of division, the values for $z_i$ must be calculated sequentially, since $z_i$\ndepends on the previously calculated values $z_0, z_1, ..., z_{i-1}$.\n\n\\subsection{General Functions}\n\nCalling standard mathematical functions such as {\\tt log()}, {\\tt cos()}, etc. should return accurate higher\norder derivatives. For example, {\\tt exp(x)} may be written internally as a specific \\nth{14}-degree polynomial to\napproximate $e^x$ when $0<x<1$. This would mean that the \\nth{15} derivative, and all higher order derivatives, would\nbe 0, however we know that $\\frac{d^{15}}{dx^{15}}e^x=e^x$.  How should such functions whose derivatives are known\nbe written to provide accurate higher order derivatives? The answer again comes back to the function's Taylor series.\n\nTo simplify notation, for a given polynomial ${\\bf x} = x_0 + x_1\\varepsilon + x_2\\varepsilon^2 +\\cdots+\nx_N\\varepsilon^N$ define\n\n\\[\n{\\bf x}_\\varepsilon = x_1\\varepsilon + x_2\\varepsilon^2 +\\cdots+ x_N\\varepsilon^N = \\sum_{i=1}^Nx_i\\varepsilon^i.\n\\]\nThis allows for a concise expression of a general function $f$ of $\\bf x$:\n\n\\begin{align*}\nf({\\bf x}) &= f(x_0 + {\\bf x}_\\varepsilon) \\\\\n & = f(x_0) + f'(x_0){\\bf x}_\\varepsilon + \\frac{f''(x_0)}{2!}{\\bf x}_\\varepsilon^2 + \\frac{f'''(x_0)}{3!}{\\bf x}_\\varepsilon^3 + \\cdots + \\frac{f^{(N)}(x_0)}{N!}{\\bf x}_\\varepsilon^N + O\\left(\\varepsilon^{N+1}\\right) \\\\\n & = \\sum_{i=0}^N\\frac{f^{(i)}(x_0)}{i!}{\\bf x}_\\varepsilon^i + O\\left(\\varepsilon^{N+1}\\right)\n\\end{align*}\nwhere $\\varepsilon$ has been substituted with ${\\bf x}_\\varepsilon$ in the $\\varepsilon$-taylor series\nfor $f(x)$. This form gives a recipe for calculating $f({\\bf x})$ in general from regular numeric calculations\n$f(x_0)$, $f'(x_0)$, $f''(x_0)$, ... and successive powers of the epsilon terms ${\\bf x}_\\varepsilon$.\n\nFor an application in which we are interested in up to $N$ derivatives in $x$ the data structure to hold\nthis information is an $(N+1)$-element array {\\tt v} whose general element is\n\n\\[ {\\tt v[i]} = \\frac{f^{(i)}(x_0)}{i!} \\qquad \\text{for}\\; i\\in\\{0,1,2,...,N\\}. \\]\n\n\\subsection{Multiple Variables}\n\nIn C++, the generalization to mixed partial derivatives with multiple independent variables is conveniently achieved\nwith recursion. To begin to see the recursive pattern, consider a two-variable function $f(x,y)$. Since $x$\nand $y$ are independent, they require their own independent epsilons $\\varepsilon_x$ and $\\varepsilon_y$,\nrespectively.\n\nExpand $f(x,y)$ for $x=x_0+\\varepsilon_x$:\n\\begin{align*}\nf(x_0+\\varepsilon_x,y) &= f(x_0,y)\n+ \\frac{\\partial f}{\\partial x}(x_0,y)\\varepsilon_x\n+ \\frac{1}{2!}\\frac{\\partial^2 f}{\\partial x^2}(x_0,y)\\varepsilon_x^2\n+ \\frac{1}{3!}\\frac{\\partial^3 f}{\\partial x^3}(x_0,y)\\varepsilon_x^3\n+ \\cdots\n+ \\frac{1}{M!}\\frac{\\partial^M f}{\\partial x^M}(x_0,y)\\varepsilon_x^M\n+ O\\left(\\varepsilon_x^{M+1}\\right) \\\\\n&= \\sum_{i=0}^M\\frac{1}{i!}\\frac{\\partial^i f}{\\partial x^i}(x_0,y)\\varepsilon_x^i + O\\left(\\varepsilon_x^{M+1}\\right).\n\\end{align*}\nNext, expand $f(x_0+\\varepsilon_x,y)$ for $y=y_0+\\varepsilon_y$:\n\n\\begin{align*}\nf(x_0+\\varepsilon_x,y_0+\\varepsilon_y) &= \\sum_{j=0}^N\\frac{1}{j!}\\frac{\\partial^j}{\\partial y^j}\n    \\left(\\sum_{i=0}^M\\varepsilon_x^i\\frac{1}{i!}\\frac{\\partial^if}{\\partial x^i}\\right)(x_0,y_0)\\varepsilon_y^j\n    + O\\left(\\varepsilon_x^{M+1}\\right) + O\\left(\\varepsilon_y^{N+1}\\right) \\\\\n&= \\sum_{i=0}^M\\sum_{j=0}^N\\frac{1}{i!j!}\\frac{\\partial^{i+j}f}{\\partial x^i\\partial y^j}(x_0,y_0)\n   \\varepsilon_x^i\\varepsilon_y^j + O\\left(\\varepsilon_x^{M+1}\\right) + O\\left(\\varepsilon_y^{N+1}\\right).\n\\end{align*}\n\nSimilar to the single-variable case, for an application in which we are interested in up to $M$ derivatives in\n$x$ and $N$ derivatives in $y$, the data structure to hold this information is an $(M+1)\\times(N+1)$\narray {\\tt v} whose element at $(i,j)$ is\n\n\\[\n{\\tt v[i][j]} = \\frac{1}{i!j!}\\frac{\\partial^{i+j}f}{\\partial x^i\\partial y^j}(x_0,y_0)\n    \\qquad \\text{for}\\; (i,j)\\in\\{0,1,2,...,M\\}\\times\\{0,1,2,...,N\\}.\n\\]\nThe generalization to additional independent variables follows the same pattern.\n\n\\subsubsection{Declaring Multiple Variables}\n\nInternally, independent variables are represented by vectors within orthogonal vector spaces. Because of this,\none must be careful when declaring more than one independent variable so that they do not end up in\nparallel vector spaces. This can easily be achieved by following one rule:\n\\begin{itemize}\n\\item When declaring more than one independent variable, call {\\tt make\\_ftuple<>()} once and only once.\n\\end{itemize}\nThe tuple of values returned are independent. Though it is possible to achieve the same result with multiple calls\nto {\\tt make\\_fvar}, this is an easier and less error-prone method. See Section~\\ref{multivar} for example usage.\n\n%\\section{Usage}\n%\n%\\subsection{Single Variable}\n%\n%To calculate derivatives of a single variable $x$, at a particular value $x_0$, the following must be\n%specified at compile-time:\n%\n%\\begin{enumerate}\n%\\item The numeric data type {\\tt T} of $x_0$. Examples: {\\tt double},\n%    {\\tt boost::multiprecision::cpp\\_bin\\_float\\_50}, etc.\n%\\item The maximum derivative order $M$ that is to be calculated with respect to $x$.\n%\\end{enumerate}\n%Note that both of these requirements are entirely analogous to declaring and using a {\\tt std::array<T,N>}. {\\tt T}\n%and {\\tt N} must be set as compile-time, but which elements in the array are accessed can be determined at run-time,\n%just as the choice of what derivatives to query in autodiff can be made during run-time.\n%\n%To declare and initialize $x$:\n%\n%\\begin{verbatim}\n%    using namespace boost::math::differentiation;\n%    autodiff_fvar<T,M> x = make_fvar<T,M>(x0);\n%\\end{verbatim}\n%where {\\tt x0} is a run-time value of type {\\tt T}. Assuming {\\tt 0 < M}, this represents the polynomial $x_0 +\n%\\varepsilon$. Internally, the member variable of type {\\tt std::array<T,M>} is {\\tt v = \\{ x0, 1, 0, 0, ... \\}},\n%consistent with the above mathematical treatise.\n%\n%To find the derivatives $f^{(n)}(x_0)$ for $0\\le n\\le M$ of a function\n%$f : \\mathbb{R}\\rightarrow\\mathbb{R}$, the function can be represented as a template\n%\n%\\begin{verbatim}\n%    template<typename T>\n%    T f(T x);\n%\\end{verbatim}\n%Using a generic type {\\tt T} allows for {\\tt x} to be of a regular type such as {\\tt double}, but also allows for\\\\\n%{\\tt boost::math::differentiation::autodiff\\_fvar<>} types.\n%\n%Internal calls to mathematical functions must allow for\n%\\href{https://en.cppreference.com/w/cpp/language/adl}{argument-dependent lookup} (ADL). Many standard library functions\n%are overloaded in the {\\tt boost::math::differentiation} namespace. For example, instead of calling {\\tt std::cos(x)}\n%from within {\\tt f}, include the line {\\tt using std::cos;} and call {\\tt cos(x)} without a namespace prefix.\n%\n%Calling $f$ and retrieving the calculated value and derivatives:\n%\n%\\begin{verbatim}\n%    using namespace boost::math::differentiation;\n%    autodiff_fvar<T,M> x = make_fvar<T,M>(x0);\n%    autodiff_fvar<T,M> y = f(x);\n%    for (int n=0 ; n<=M ; ++n)\n%        std::cout << \"y.derivative(\"<<n<<\") == \" << y.derivative(n) << std::endl;\n%\\end{verbatim}\n%{\\tt y.derivative(0)} returns the undifferentiated value $f(x_0)$, and {\\tt y.derivative(n)} returns $f^{(n)}(x_0)$.\n%Casting {\\tt y} to type {\\tt T} also gives the undifferentiated value. In other words, the following 3 values\n%are equal:\n%\n%\\begin{enumerate}\n%\\item {\\tt f(x0)}\n%\\item {\\tt y.derivative(0)}\n%\\item {\\tt static\\_cast<T>(y)}\n%\\end{enumerate}\n%\n%\\subsection{Multiple Variables}\n%\n%Independent variables are represented in autodiff as independent dimensions within a multi-dimensional array.\n%This is perhaps best illustrated with examples. The {\\tt namespace boost::math::differentiation} is assumed.\n%\n%The following instantiates a variable of $x=13$ with up to 3 orders of derivatives:\n%\n%\\begin{verbatim}\n%    autodiff_fvar<double,3> x = make_fvar<double,3>(13);\n%\\end{verbatim}\n%This instantiates {\\bf an independent} value of $y=14$ with up to 4 orders of derivatives:\n%\n%\\begin{verbatim}\n%    autodiff_fvar<double,0,4> y = make_fvar<double,0,4>(14);\n%\\end{verbatim}\n%Combining them together {\\bf promotes} their data type automatically to the smallest multidimensional array that\n%accommodates both.\n%\n%\\begin{verbatim}\n%    // z is promoted to autodiff_fvar<double,3,4>\n%    auto z = 10*x*x + 50*x*y + 100*y*y;\n%\\end{verbatim}\n%The object {\\tt z} holds a 2-dimensional array, thus {\\tt derivative(...)} is a 2-parameter method:\n%\n%\\[\n%{\\tt z.derivative(i,j)} = \\frac{\\partial^{i+j}f}{\\partial x^i\\partial y^j}(13,14)\n%    \\qquad \\text{for}\\; (i,j)\\in\\{0,1,2,3\\}\\times\\{0,1,2,3,4\\}.\n%\\]\n%A few values of the result can be confirmed through inspection:\n%\n%\\begin{verbatim}\n%    z.derivative(2,0) == 20\n%    z.derivative(1,1) == 50\n%    z.derivative(0,2) == 200\n%\\end{verbatim}\n%Note how the position of the parameters in {\\tt derivative(...)} match how {\\tt x} and {\\tt y} were declared.\n%This will be clarified next.\n%\n%\\subsubsection{Two Rules of Variable Initialization}\n%\n%In general, there are two rules to keep in mind when dealing with multiple variables:\n%\n%\\begin{enumerate}\n%\\item Independent variables correspond to parameter position, in both the initialization {\\tt make\\_fvar<T,...>}\n%    and calls to {\\tt derivative(...)}.\n%\\item The last template position in {\\tt make\\_fvar<T,...>} determines which variable a derivative will be\n%   taken with respect to.\n%\\end{enumerate}\n%Both rules are illustrated with an example in which there are 3 independent variables $x,y,z$ and 1 dependent\n%variable $w=f(x,y,z)$, though the following code readily generalizes to any number of independent variables, limited\n%only by the C++ compiler/memory/platform. The maximum derivative order of each variable is {\\tt Nx}, {\\tt Ny}, and\n%{\\tt Nz}, respectively. Then the type for {\\tt w} is {\\tt boost::math::differentiation::autodiff\\_fvar<T,Nx,Ny,Nz>}\n%and all possible mixed partial derivatives are available via\n%\n%\\[\n%{\\tt w.derivative(nx,ny,nz)} =\n%    \\frac{\\partial^{n_x+n_y+n_z}f}{\\partial x^{n_x}\\partial y^{n_y}\\partial z^{n_z} }(x_0,y_0,z_0)\n%\\]\n%for $(n_x,n_y,n_z)\\in\\{0,1,2,...,N_x\\}\\times\\{0,1,2,...,N_y\\}\\times\\{0,1,2,...,N_z\\}$ where $x_0, y_0, z_0$ are\n%the numerical values at which the function $f$ and its derivatives are evaluated.\n%\n%In code:\n%\\begin{verbatim}\n%    using namespace boost::math::differentiation;\n%\n%    using var = autodiff_fvar<double,Nx,Ny,Nz>; // Nx, Ny, Nz are constexpr size_t.\n%\n%    var x = make_fvar<double,Nx>(x0);       // x0 is of type double\n%    var y = make_fvar<double,Nx,Ny>(y0);    // y0 is of type double\n%    var z = make_fvar<double,Nx,Ny,Nz>(z0); // z0 is of type double\n%\n%    var w = f(x,y,z);\n%\n%    for (size_t nx=0 ; nx<=Nx ; ++nx)\n%        for (size_t ny=0 ; ny<=Ny ; ++ny)\n%            for (size_t nz=0 ; nz<=Nz ; ++nz)\n%                std::cout << \"w.derivative(\"<<nx<<','<<ny<<','<<nz<<\") == \"\n%                    << w.derivative(nx,ny,nz) << std::endl;\n%\\end{verbatim}\n%Note how {\\tt x}, {\\tt y}, and {\\tt z} are initialized: the last template parameter determines which variable\n%$x, y,$ or $z$ a derivative is taken with respect to. In terms of the $\\varepsilon$-polynomials\n%above, this determines whether to add $\\varepsilon_x, \\varepsilon_y,$ or $\\varepsilon_z$ to\n%$x_0, y_0,$ or $z_0$, respectively.\n%\n%In contrast, the following initialization of {\\tt x} would be INCORRECT:\n%\n%\\begin{verbatim}\n%    var x = make_fvar<T,Nx,0>(x0); // WRONG\n%\\end{verbatim}\n%Mathematically, this represents $x_0+\\varepsilon_y$, since the last template parameter corresponds to the\n%$y$ variable, and thus the resulting value will be invalid.\n%\n%\\subsubsection{Type Promotion}\n%\n%The previous example can be optimized to save some unnecessary computation, by declaring smaller arrays,\n%and relying on autodiff's automatic type-promotion:\n%\n%\\begin{verbatim}\n%    using namespace boost::math::differentiation;\n%\n%    autodiff_fvar<double,Nx> x = make_fvar<double,Nx>(x0);\n%    autodiff_fvar<double,0,Ny> y = make_fvar<double,0,Ny>(y0);\n%    autodiff_fvar<double,0,0,Nz> z = make_fvar<double,0,0,Nz>(z0);\n%\n%    autodiff_fvar<double,Nx,Ny,Nz> w = f(x,y,z);\n%\n%    for (size_t nx=0 ; nx<=Nx ; ++nx)\n%        for (size_t ny=0 ; ny<=Ny ; ++ny)\n%            for (size_t nz=0 ; nz<=Nz ; ++nz)\n%                std::cout << \"w.derivative(\"<<nx<<','<<ny<<','<<nz<<\") == \"\n%                    << w.derivative(nx,ny,nz) << std::endl;\n%\\end{verbatim}\n%For example, if one of the first steps in the computation of $f$ was {\\tt z*z}, then a significantly less number of\n%multiplications and additions may occur if {\\tt z} is declared as {\\tt autodiff\\_fvar<double,0,0,Nz>} as opposed to \\\\\n%{\\tt autodiff\\_fvar<double,Nx,Ny,Nz>}. There is no loss of precision with the former, since the extra dimensions\n%represent 0 values. Once {\\tt z} is combined with {\\tt x} and {\\tt y} during the computation, the types will be\n%promoted as necessary.  This is the recommended way to initialize variables in autodiff.\n\n\\section{Writing Functions for Autodiff Compatibility}\\label{compatibility}\n\nIn this section, a general procedure is given for writing new, and transforming existing, C++ mathematical\nfunctions for compatibility with autodiff.\n\nThere are 3 categories of functions that require different strategies:\n\\begin{enumerate}\n\\item Piecewise-rational functions. These are simply piecewise quotients of polynomials. All that is needed is to\n    turn the function parameters and return value into generic (template) types. This will then allow the function\n    to accept and return autodiff's {\\tt fvar} types, thereby using autodiff's overloaded arithmetic operators\n    which calculate the derivatives automatically.\n\\item Functions that call existing autodiff functions. This is the same as the previous, but may also include\n    calls to functions that are in the autodiff library. Examples: {\\tt exp()}, {\\tt log()}, {\\tt tgamma()}, etc.\n\\item New functions for which the derivatives can be calculated. This is the most general technique, as it\n    allows for the development of a function which do not fall into the previous two categories.\n\\end{enumerate}\nFunctions written in any of these ways may then be added to the autodiff library.\n\n\\subsection{Piecewise-Rational Functions}\n\\[\nf(x) = \\frac{1}{1+x^2}\n\\]\nBy simply writing this as a template function, autodiff can calculate derivatives for it:\n\\begin{Verbatim}[xleftmargin=2em]\n#include <boost/math/differentiation/autodiff.hpp>\n#include <iostream>\n\ntemplate <typename T>\nT rational(T const& x) {\n  return 1 / (1 + x * x);\n}\n\nint main() {\n  using namespace boost::math::differentiation;\n  auto const x = make_fvar<double, 10>(0);\n  auto const y = rational(x);\n  std::cout << std::setprecision(std::numeric_limits<double>::digits10)\n            << \"y.derivative(10) = \" << y.derivative(10) << std::endl;\n  return 0;\n}\n/*\nOutput:\ny.derivative(10) = -3628800\n*/\n\\end{Verbatim}\nAs simple as $f(x)$ may seem, the derivatives can get increasingly complex as derivatives are taken.\nFor example, the \\nth{10} derivative has the form\n\\[\nf^{(10)}(x) = -3628800\\frac{1 - 55x^2 + 330x^4 - 462x^6 + 165x^8 - 11x^{10}}{(1 + x^2)^{11}}.\n\\]\nDerivatives of $f(x)$ are useful, and in fact used, in calculating higher order derivatives for $\\arctan(x)$\nfor instance, since\n\\[\n\\arctan^{(n)}(x) = \\left(\\frac{d}{dx}\\right)^{n-1} \\frac{1}{1+x^2}\\qquad\\text{for}\\quad 1\\le n.\n\\]\n\n\\subsection{Functions That Call Existing Autodiff Functions}\n\nMany of the standard library math function are overloaded in autodiff. It is recommended to use\n\\href{https://en.cppreference.com/w/cpp/language/adl}{argument-dependent lookup} (ADL) in order for functions to\nbe written in a way that is general enough to accommodate standard types ({\\tt double}) as well as autodiff types\n({\\tt fvar}).\n\\\\\nExample:\n\\begin{Verbatim}[xleftmargin=2em]\n#include <boost/math/constants/constants.hpp>\n#include <cmath>\n\nusing namespace boost::math::constants;\n\n// Standard normal cumulative distribution function\ntemplate <typename T>\nT Phi(T const& x)\n{\n  return 0.5 * std::erfc(-one_div_root_two<T>() * x);\n}\n\\end{Verbatim}\nThough {\\tt Phi(x)} is general enough to handle the various fundamental floating point types, this will\nnot work if {\\tt x} is an autodiff {\\tt fvar} variable, since {\\tt std::erfc} does not include a specialization\nfor {\\tt fvar}. The recommended solution is to remove the namespace prefix {\\tt std::} from {\\tt erfc}:\n\\begin{Verbatim}[xleftmargin=2em]\n#include <boost/math/constants/constants.hpp>\n#include <boost/math/differentiation/autodiff.hpp>\n#include <cmath>\n\nusing namespace boost::math::constants;\n\n// Standard normal cumulative distribution function\ntemplate <typename T>\nT Phi(T const& x)\n{\n  using std::erfc;\n  return 0.5 * erfc(-one_div_root_two<T>() * x);\n}\n\\end{Verbatim}\nIn this form, when {\\tt x} is of type {\\tt fvar}, the C++ compiler will search for and find a function {\\tt erfc}\nwithin the same namespace as {\\tt fvar}, which is in the autodiff library, via ADL. Because of the using-declaration,\nit will also call {\\tt std::erfc} when {\\tt x} is a fundamental type such as {\\tt double}.\n\n\\subsection{New Functions For Which The Derivatives Can Be Calculated}\\label{new_functions}\n\nMathematical functions which do not fall into the previous two categories can be constructed using autodiff helper\nfunctions. This requires a separate function for calculating the derivatives. In case you are asking yourself what\ngood is an autodiff library if one needs to supply the derivatives, the answer is that the new function will fit\nin with the rest of the autodiff library, thereby allowing for the creation of additional functions via all of\nthe arithmetic operators, plus function composition, which was not readily available without the library.\n\nThe example given here is for {\\tt cos}:\n\\begin{Verbatim}[xleftmargin=2em]\ntemplate <typename RealType, size_t Order>\nfvar<RealType, Order> cos(fvar<RealType, Order> const& cr) {\n  using std::cos;\n  using std::sin;\n  using root_type = typename fvar<RealType, Order>::root_type;\n  constexpr size_t order = fvar<RealType, Order>::order_sum;\n  root_type const d0 = cos(static_cast<root_type>(cr));\n  if constexpr (order == 0)\n    return fvar<RealType, Order>(d0);\n  else {\n    root_type const d1 = -sin(static_cast<root_type>(cr));\n    root_type const derivatives[4]{d0, d1, -d0, -d1};\n    return cr.apply_derivatives(order,\n                                [&derivatives](size_t i) { return derivatives[i & 3]; });\n  }\n}\n\\end{Verbatim}\nThis uses the helper function {\\tt fvar::apply\\_derivatives} which takes two parameters:\n\\begin{enumerate}\n\\item The highest order derivative to be calculated.\n\\item A function that maps derivative order to derivative value.\n\\end{enumerate}\nThe highest order derivative necessary to be calculated is generally equal to {\\tt fvar::order\\_sum}.  In the case\nof {\\tt sin} and {\\tt cos}, the derivatives are cyclical with period 4. Thus it is sufficient to store only these\n4 values into an array, and take the derivative order modulo 4 as the index into this array.\n\nA second helper function, not shown here, is {\\tt apply\\_coefficients}. This is used the same as\n{\\tt apply\\_derivatives} except that the supplied function calculates coefficients instead of derivatives.\nThe relationship between a coefficient $C_n$ and derivative $D_n$ for derivative order $n$ is\n\\[\nC_n = \\frac{D_n}{n!}.\n\\]\nInternally, {\\tt fvar} holds coefficients rather than derivatives, so in case the coefficient values are more readily\navailable than the derivatives, it can save some unnecessary computation to use {\\tt apply\\_coefficients}.\nSee the definition of {\\tt atan} for an example.\n\nBoth of these helper functions use Horner's method when calculating the resulting polynomial {\\tt fvar}. This works\nwell when the derivatives are finite, but in cases where derivatives are infinite, this can quickly result in NaN\nvalues as the computation progresses. In these cases, one can call non-Horner versions of both function which\nbetter ``isolate'' infinite values so that they are less likely to evolve into NaN values.\n\nThe four helper functions available for constructing new autodiff functions from known coefficients/derivatives are:\n\\begin{enumerate}\n\\item {\\tt fvar::apply\\_coefficients}\n\\item {\\tt fvar::apply\\_coefficients\\_nonhorner}\n\\item {\\tt fvar::apply\\_derivatives}\n\\item {\\tt fvar::apply\\_derivatives\\_nonhorner}\n\\end{enumerate}\n\n\\section{Function Writing Guidelines}\n\nAt a high level there is one fairly simple principle, loosely and intuitively speaking, to writing functions for\nwhich autodiff can effectively calculate derivatives: \\\\\n\n{\\bf Autodiff Function Principle (AFP)}\n\\begin{displayquote}\nA function whose branches in logic correspond to piecewise analytic calculations over non-singleton intervals,\nwith smooth transitions between the intervals, and is free of indeterminate forms in the calculated value and\nhigher order derivatives, will work fine with autodiff.\n\\end{displayquote}\nStating this with greater mathematical rigor can be done. However what seems to be more practical, in this\ncase, is to give examples and categories of examples of what works, what doesn't, and how to remedy some of the\ncommon problems that may be encountered. That is the approach taken here.\n\n\\subsection{Example 1: $f(x)=\\max(0,x)$}\n\nOne potential implementation of $f(x)=\\max(0,x)$ is:\n\n\\begin{verbatim}\n    template<typename T>\n    T f(const T& x)\n    {\n        return 0 < x ? x : 0;\n    }\n\\end{verbatim}\nThough this is consistent with Section~\\ref{compatibility}, there are two problems with it:\n\n\\begin{enumerate}\n\\item {\\tt f(nan) = 0}. This problem is independent of autodiff, but is worth addressing anyway. If there is\n    an indeterminate form that arises within a calculation and is input into $f$, then it gets ``covered up'' by\n    this implementation leading to an unknowingly incorrect result. Better for functions in general to propagate\n    NaN values, so that the user knows something went wrong and doesn't rely on an incorrect result, and likewise\n    the developer can track down where the NaN originated from and remedy it.\n\\item $f'(0) = 0$ when autodiff is applied. This is because {\\tt f} returns 0 as a constant when {\\tt x==0}, wiping\n    out any of the derivatives (or sensitivities) that {\\tt x} was holding as an autodiff variable. Instead, let us\n    apply the AFP and identify the two intervals over which $f$ is defined: $(-\\infty,0]\\cup(0,\\infty)$.\n    Though the function itself is not analytic at $x=0$, we can attempt somewhat to smooth out this transition\n    point by averaging the calculation of $f(x)$ at $x=0$ from each interval. If $x<0$ then the result is simply\n    0, and if $0<x$ then the result is $x$. The average is $\\frac{1}{2}(0 + x)$ which will allow autodiff to\n    calculate $f'(0)=\\frac{1}{2}$. This is a more reasonable answer.\n\\end{enumerate}\nA better implementation that resolves both issues is:\n\\begin{verbatim}\n    template<typename T>\n    T f(const T& x)\n    {\n        if (x < 0)\n            return 0;\n        else if (x == 0)\n            return 0.5*x;\n        else\n            return x;\n    }\n\\end{verbatim}\n\n\\subsection{Example 2: $f(x)=\\sinc(x)$}\n\nThe definition of $\\sinc:\\mathbb{R}\\rightarrow\\mathbb{R}$ is\n\n\\[\n\\sinc(x) = \\begin{cases}\n    1 &\\text{if}\\; x = 0 \\\\\n    \\frac{\\sin(x)}{x} &\\text{otherwise.}\\end{cases}\n\\]\nA potential implementation is:\n\n\\begin{verbatim}\n    template<typename T>\n    T sinc(const T& x)\n    {\n        using std::sin;\n        return x == 0 ? 1 : sin(x) / x;\n    }\n\\end{verbatim}\nThough this is again consistent with Section~\\ref{compatibility}, and returns correct non-derivative values,\nit returns a constant when {\\tt x==0} thereby losing all derivative information contained in {\\tt x} and\ncontributions from $\\sinc$. For example, $\\sinc''(0)=-\\frac{1}{3}$, however {\\tt y.derivative(2) == 0} when\n{\\tt y = sinc(make\\_fvar<double,2>(0))} using the above incorrect implementation. Applying the AFP, the intervals\nupon which separate branches of logic are applied are $(-\\infty,0)\\cup[0,0]\\cup(0,\\infty)$. The violation occurs\ndue to the singleton interval $[0,0]$, even though a constant function of 1 is technically analytic. The remedy\nis to define a custom $\\sinc$ overload and add it to the autodiff library. This has been done. Mathematically, it\nis well-defined and free of indeterminate forms, as is the \\nth{3} expression in the equalities\n\\[\n\\frac{1}{x}\\sin(x) = \\frac{1}{x}\\sum_{n=0}^\\infty\\frac{(-1)^n}{(2n+1)!}x^{2n+1}\n    = \\sum_{n=0}^\\infty\\frac{(-1)^n}{(2n+1)!}x^{2n}.\n\\]\nThe autodiff library contains helper functions to help write function overloads when the derivatives of a function\nare known. This is an advanced feature and documentation for this may be added at a later time.\n\nFor now, it is worth understanding the ways in which indeterminate forms can occur within a mathematical calculation,\nand avoid them when possible by rewriting the function. Table~\\ref{3nans} compares 3 types of indeterminate\nforms. Assume the product {\\tt a*b} is a positive finite value.\n\n\\begin{table}[h]\n\\centering\\begin{tabular}{m{7em}||c|c|c}\n & $\\displaystyle f(x)=\\left(\\frac{a}{x}\\right)\\times(bx^2)$\n & $\\displaystyle g(x)=\\left(\\frac{a}{x}\\right)\\times(bx)$\n & $\\displaystyle h(x)=\\left(\\frac{a}{x^2}\\right)\\times(bx)$ \\\\[0.618em]\n\\hline\\hline\nMathematical\\newline Limit\n & $\\displaystyle\\lim_{x\\rightarrow0}f(x) = 0$\n & $\\displaystyle\\lim_{x\\rightarrow0}g(x) = ab$\n & $\\displaystyle\\lim_{x\\rightarrow0}h(x) = \\infty$ \\\\\n\\hline\nFloating Point\\newline Arithmetic\n & {\\tt f(0) = inf*0 = nan} & {\\tt g(0) = inf*0 = nan} & {\\tt h(0) = inf*0 = nan}\n\\end{tabular}\n\\caption{Automatic differentiation does not compute limits.\nIndeterminate forms must be simplified manually. (These cases are not meant to be exhaustive.)}\\label{3nans}\n\\end{table}\n\nIndeterminate forms result in NaN values within a calculation. Mathematically, if they occur at locally isolated\npoints, then we generally prefer the mathematical limit as the result, even if it is infinite. As demonstrated in\nTable~\\ref{3nans}, depending upon the nature of the indeterminate form, the mathematical limit can be 0 (no matter\nthe values of $a$ or $b$), or $ab$, or $\\infty$, but these 3 cases cannot be distinguished by the floating point\nresult of nan. Floating point arithmetic does not perform limits (directly), and neither does the autodiff library.\nThus it is up to the diligence of the developer to keep a watchful eye over where indeterminate forms can arise.\n\n\\subsection{Example 3: $f(x)=\\sqrt x$ and $f'(0)=\\infty$}\n\nWhen working with functions that have infinite higher order derivatives, this can very quickly result in nans in\nhigher order derivatives as the computation progresses, as {\\tt inf-inf}, {\\tt inf/inf}, and {\\tt 0*inf} result\nin {\\tt nan}. See Table~\\ref{sqrtnan} for an example.\n\n\\begin{table}[h]\n\\centering\\begin{tabular}{c||c|c|c|c}\n$f(x)$ & $f(0)$ & $f'(0)$ & $f''(0)$ & $f'''(0)$ \\\\\n\\hline\\hline\n{\\tt sqrt(x)} & {\\tt 0} & {\\tt inf} & {\\tt -inf} & {\\tt inf} \\\\\n\\hline\n{\\tt sqr(sqrt(x)+1)} & {\\tt 1} & {\\tt inf} & {\\tt nan} & {\\tt nan} \\\\\n\\hline\n{\\tt x+2*sqrt(x)+1} & {\\tt 1} & {\\tt inf} & {\\tt -inf}& {\\tt inf}\n\\end{tabular}\n\\caption{Indeterminate forms in higher order derivatives. {\\tt sqr(x) == x*x}.}\\label{sqrtnan}\n\\end{table}\n\nCalling the autodiff-overloaded implementation of $f(x)=\\sqrt x$ at the value {\\tt x==0} results in the\n\\nth{1} row (after the header row) of Table~\\ref{sqrtnan}, as is mathematically correct. The \\nth{2} row shows\n$f(x)=(\\sqrt{x}+1)^2$ resulting in {\\tt nan} values for $f''(0)$ and all higher order derivatives. This is due to\nthe internal arithmetic in which {\\tt inf} is added to {\\tt -inf} during the squaring, resulting in a {\\tt nan}\nvalue for $f''(0)$ and all higher orders. This is typical of {\\tt inf} values in autodiff. Where they show up,\nthey are correct, however they can quickly introduce {\\tt nan} values into the computation upon the addition of\noppositely signed {\\tt inf} values, division by {\\tt inf}, or multiplication by {\\tt 0}. It is worth noting that\nthe infection of {\\tt nan} only spreads upward in the order of derivatives, since lower orders do not depend upon\nhigher orders (which is also why dropping higher order terms in an autodiff computation does not result in any\nloss of precision for lower order terms.)\n\nThe resolution in this case is to manually perform the squaring in the computation, replacing the \\nth{2} row\nwith the \\nth{3}: $f(x)=x+2\\sqrt{x}+1$. Though mathematically equivalent, it allows autodiff to avoid {\\tt nan}\nvalues since $\\sqrt x$ is more ``isolated'' in the computation. That is, the {\\tt inf} values that unavoidably\nshow up in the derivatives of {\\tt sqrt(x)} for {\\tt x==0} do not have the chance to interact with other {\\tt inf}\nvalues as with the squaring.\n\n\\subsection{Summary}\n\nThe AFP gives a high-level unified guiding principle for writing C++ template functions that autodiff can\neffectively evaluate derivatives for.\n\nExamples have been given to illustrate some common items to avoid doing:\n\n\\begin{enumerate}\n\\item It is not enough for functions to be piecewise continuous. On boundary points between intervals, consider\n    returning the average expression of both intervals, rather than just one of them. Example: $\\max(0,x)$ at $x=0$.\n    In cases where the limits from both sides must match, and they do not, then {\\tt nan} may be a more appropriate\n    value depending on the application.\n\\item Avoid returning individual constant values (e.g. $\\sinc(0)=1$.) Values must be computed uniformly along\n    with other values in its local interval. If that is not possible, then the function must be overloaded to\n    compute the derivatives precisely using the helper functions from Section~\\ref{new_functions}.\n\\item Avoid intermediate indeterminate values in both the value ($\\sinc(x)$ at $x=0$) and derivatives\n    ($(\\sqrt{x}+1)^2$ at $x=0$). Try to isolate expressions that may contain infinite values/derivatives so\n    that they do not introduce NaN values into the computation.\n\\end{enumerate}\n\n\\section{Acknowledgments}\n\n\\begin{itemize}\n\\item Kedar Bhat --- C++11 compatibility, Boost Special Functions compatibility testing, codecov integration,\n    and feedback.\n\\item Nick Thompson --- Initial feedback and help with Boost integration.\n\\item John Maddock --- Initial feedback and help with Boost integration.\n\\end{itemize}\n\n\\begin{thebibliography}{1}\n\\bibitem{ad} \\url{https://en.wikipedia.org/wiki/Automatic\\_differentiation}\n\\bibitem{ed} Andreas Griewank, Andrea Walther. \\textit{Evaluating Derivatives}. SIAM, 2nd ed. 2008.\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "e71876a81db724c20b2afa6238849e02a772f3d8", "size": 50516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thirdparty/boost_1_71_0/libs/math/doc/differentiation/autodiff.tex", "max_stars_repo_name": "anonymouscode1/djxperf", "max_stars_repo_head_hexsha": "b6073a761753aa7a6247f2618977ca3a2633e78a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 233, "max_stars_repo_stars_event_min_datetime": "2015-01-12T19:26:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T09:21:47.000Z", "max_issues_repo_path": "thirdparty/boost_1_71_0/libs/math/doc/differentiation/autodiff.tex", "max_issues_repo_name": "anonymouscode1/djxperf", "max_issues_repo_head_hexsha": "b6073a761753aa7a6247f2618977ca3a2633e78a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 626, "max_issues_repo_issues_event_min_datetime": "2015-02-05T18:12:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-20T13:19:18.000Z", "max_forks_repo_path": "Libs/boost_1_76_0/libs/math/doc/differentiation/autodiff.tex", "max_forks_repo_name": "Antd23rus/S2DE", "max_forks_repo_head_hexsha": "47cc7151c2934cd8f0399a9856c1e54894571553", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 243, "max_forks_repo_forks_event_min_datetime": "2015-01-17T17:46:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T12:56:26.000Z", "avg_line_length": 47.882464455, "max_line_length": 220, "alphanum_fraction": 0.703381107, "num_tokens": 14969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.6623820237138746}}
{"text": "\\subsection{Riemann integration}\\label{subsec:riemann_integration}\n\n\\begin{definition}\\label{def:riemann_partition}\\mcite[def. 1]{Gordon1991}\n  The concept of a partition of a nonempty \\hyperref[def:set_of_real_numbers]{real} \\hyperref[def:partially_ordered_set_interval/closed]{closed interval} \\( [a, b] \\) is the base for defining Riemann-style integrals.\n\n  \\begin{thmenum}\n    \\thmitem{def:riemann_partition/partition} A \\term{Riemann partition} of \\( [a, b] \\) is a set\n    \\begin{equation*}\n      \\Delta \\coloneqq \\{ x_0, \\ldots, x_n \\} \\subseteq [a, b]\n    \\end{equation*}\n    that satisfies\n    \\begin{equation*}\n      a = x_0 < x_1 < \\ldots < x_n = b.\n    \\end{equation*}\n\n    For brevity, we write\n    \\begin{equation}\\label{eq:def:riemann_partition/partition}\n      \\Delta: a = x_0 < x_1 < \\ldots < x_n = b.\n    \\end{equation}\n\n    We denote the set of all partitions of \\( [a, b] \\) by \\( \\op{part}([a, b]) \\).\n\n    \\thmitem{def:riemann_partition/refinement} The partition\n    \\begin{equation*}\n      \\Gamma: a = y_0 < y_1 < \\ldots < y_m = b\n    \\end{equation*}\n    is called a \\term{refinement} of the partition \\eqref{eq:def:riemann_partition/partition} if we have the \\hyperref[def:subset]{set inclusion}\n    \\begin{equation}\\label{eq:def:riemann_partition/refinement/inclusion}\n      \\{ x_0, x_1, \\ldots, x_n \\} \\subseteq \\{ y_0, y_1, \\ldots, y_m \\}.\n    \\end{equation}\n\n    In this case, we \\enquote{split} \\( \\Gamma \\) into chains such that, for each \\( k = 1, 2, \\ldots, n \\),\n    \\begin{equation}\\label{def:riemann_partition/refinement/splitting}\n      y_{k,j} \\coloneqq \\begin{cases}\n        x_{k-1},                                                                          &j = 0, \\\\\n        x_k,                                                                              &j = p_k, \\\\\n        j\\text{-th point of } \\{ y_0, \\ldots, y_m \\} \\cap [x_{k-1}, x_k], &0 < j < p_k.\n      \\end{cases}\n    \\end{equation}\n\n    \\thmitem{def:riemann_partition/diameter} Finally, the \\term{diameter} of the partition \\eqref{eq:def:riemann_partition/partition} is defined as\n    \\begin{equation}\\label{eq:def:riemann_partition/diameter}\n      \\diam(\\Delta) \\coloneqq \\max_{1 \\leq k \\leq n} (x_k - x_{k-1}).\n    \\end{equation}\n\n    \\thmitem{def:riemann_partition/order} We can make the set \\( \\op{part}([a, b]) \\) of all \\hyperref[def:riemann_partition/partition]{Riemann partitions} of \\( [a, b] \\) into a \\hyperref[def:directed_set]{directed set} using two common approaches:\n    \\begin{thmenum}\n      \\thmitem{def:riemann_partition/order/refinement} Put \\( \\Delta \\preceq_R \\Gamma \\) if and only if \\( \\Gamma \\) is a \\hyperref[def:riemann_partition/refinement]{refinement} of \\( \\Delta \\). This actually makes \\( (\\op{part}([a, b]), \\preceq_R) \\) a \\hyperref[def:partially_ordered_set]{partially ordered set}.\n      \\thmitem{def:riemann_partition/order/diameter} Put \\( \\Delta \\preceq_D \\Gamma \\) if and only if \\( \\diam(\\Gamma) \\leq \\diam(\\Delta) \\).\n    \\end{thmenum}\n\n    \\thmitem{def:riemann_partition/tagged} A \\term{tagged partition} of \\( [a, b] \\) is a partition \\eqref{eq:def:riemann_partition/partition} of \\( [a, b] \\) along with a choice of a \\term{tag} \\( \\xi_k \\) for each closed interval \\( [x_{k-1}, x_k], k = 1, \\ldots, n \\). By putting \\( \\Xi \\coloneqq \\{ \\xi_k \\}_{k=1}^n \\), we can define a tagged partition as the tuple \\( (\\Delta, \\Xi) \\). For brevity, we write\n    \\begin{alignedeq}\\label{eq:def:riemann_partition/tagged}\n      &\\Delta: a = x_0 < x_1 < \\ldots < x_n = b \\\\\n      &\\Xi: \\xi_k \\in [x_{k-1}, x_k], k = 1, \\ldots, n.\n    \\end{alignedeq}\n\n    We denote the set of all tagged partitions of \\( [a, b] \\) by \\( \\op{tpart}([a, b]) \\). We introduce an order on \\( \\op{tpart}([a, b]) \\) by putting\n    \\begin{equation*}\n      (\\Delta, \\Xi) \\preceq_R (\\Gamma, \\Eta) \\T{if and only if} \\Delta \\preceq_R \\Eta\n    \\end{equation*}\n    and analogously for \\( \\preceq_D \\). Note that \\( \\preceq_R \\) is not a partial order in \\( \\op{tpart}([a, b]) \\) unlike in \\( \\op{part}([a, b]) \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:set_and_riemann_partitions}\n  Note that \\eqref{eq:def:riemann_partition/partition} is not a partition in the sense of \\fullref{def:set_partition}, however the set of intervals\n  \\begin{equation*}\n    \\Big\\{ [x_0, x_1), [x_1, x_2), \\ldots, [x_{n-2}, x_{n-1}), [x_{n-1}, x_n] \\Big\\}\n  \\end{equation*}\n  is a set-theoretic partition of \\( [a, b] \\). Conversely, every finite set-theoretic partition of \\( [a, b] \\) gives rise to a Riemann partition in the sense of \\fullref{def:riemann_partition/partition}.\n\\end{remark}\n\n\\begin{definition}\\label{def:riemann_integral}\\mcite[def. 2]{Gordon1991}\n  Let \\( \\mscrX \\) be a real \\hyperref[def:separation_axioms/T2]{Hausdorff} \\hyperref[def:topological_vector_space]{topological vector space}. Fix a \\hyperref[def:function]{function} \\( f: [a, b] \\to X \\).\n\n  The \\term{Riemann sum} of \\( f \\) corresponding to the \\hyperref[def:riemann_partition/tagged]{tagged partition} \\eqref{eq:def:riemann_partition/tagged} is defined as\n  \\begin{equation*}\n    S(f, \\Delta, \\Xi) \\coloneqq \\sum_{k=1}^n f(\\xi_k) (x_k - x_{k-1}).\n  \\end{equation*}\n\n  Consider the net\n  \\begin{equation}\\label{eq:def:riemann_integral/net}\n    \\{ S(f, \\Delta, \\Xi) \\}_{(\\Delta, \\Xi) \\in \\op{tpart}([a, b])}\n  \\end{equation}\n\n  Both orders \\fullref{def:riemann_partition/order/refinement} and \\fullref{def:riemann_partition/order/diameter} on \\( \\op{tpart}([a, b]) \\) provide equivalent convergence for Riemann sums. If the limit exists, \\( f \\) is said to be \\term{Riemann integrable} in \\( [a, b] \\). We call the limit the \\term{Riemann integral} of \\( f \\) and denote it by\n  \\begin{equation}\\label{eq:def:riemann_integral}\n    \\int_a^b f(x) dx.\n  \\end{equation}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:riemann_partition/order/refinement}{def:riemann_partition/order/diameter} Let \\( I \\) be the limit \\eqref{eq:def:riemann_integral} with respect to \\( \\preceq_R \\). Fix a neighborhood \\( U \\) of \\( 0 \\). Since \\eqref{eq:def:riemann_integral/net} is eventually in \\( I + U \\), there exists a tagged partition\n  \\begin{alignedeq}\\label{eq:def:riemann_integral/tagged_zero}\n    &\\Delta_0: a = x_0^{(0)} < x_1^{(0)} < \\ldots < x_n^{(0)} = b \\\\\n    &\\Xi_0: \\xi_k^{(0)} \\in [x_{k-1}^{(0)}, x_k^{(0)}], k = 1, \\ldots, n_0.\n  \\end{alignedeq}\n  such that \\( S(f, \\Gamma, \\Eta) \\in I + U \\) if \\( \\Gamma \\) is a refinement of \\( \\Delta_0 \\).\n\n  Note that \\( f \\) is \\hyperref[def:bounded_function/bounded]{bounded}. Indeed, if it is unbounded on \\( [a, b] \\), then there exists a refinement \\( (\\Gamma, \\Eta) \\) of \\( (\\Delta_0, \\Xi_0) \\) such that\n  \\begin{equation*}\n    S(f, \\Gamma, \\Eta) - I \\not\\in U.\n  \\end{equation*}\n\n  But this contradicts our choice of \\( \\Delta_0 \\). Therefore, \\( f \\) is bounded and there exists a bounded neighborhood \\( V_0 \\) of \\( 0 \\) such that \\( f([a, b]) \\subseteq V_0 \\) and hence \\( f(x) - f(y) \\in V \\coloneqq V_0 - V_0 \\) for all \\( x, y \\in [a, b] \\).\n\n  Let  \\( v > 0 \\) be such that \\( V \\subseteq vU \\).\n\n  Let \\( (\\Delta, \\Xi) \\) be a tagged partition such that \\( \\diam(\\Delta) \\leq \\diam(\\Delta_0) \\).\n\n  We introduce another partition \\( \\Gamma \\coloneqq \\Delta \\cup \\Delta_0 \\). Since \\( \\Gamma \\) is a refinement of \\( \\Delta_0 \\), we can use a splitting similar to \\eqref{def:riemann_partition/refinement/splitting} such that\n  \\begin{equation}\\label{def:riemann_partition/subdiameter_splitting}\n    S(f, \\Delta_0, \\Xi_0) = \\sum_{k=1}^{n_0} \\sum_{j=1}^{p_k} f(\\xi^{(0)}_k) (y_{k,j} - y_{k,j-1}).\n  \\end{equation}\n\n  Denote by \\( \\xi_{k,j} \\) the largest tag in \\( \\Xi \\) such that \\( \\xi_{k,j} \\leq y_{k,j} \\). Thus,\n  \\begin{equation*}\n    S(f, \\Delta, \\Xi) = \\sum_{k=1}^{n_0} \\sum_{j=1}^{p_k} f(\\xi_{k,j}) (y_{k,j} - y_{k,j-1}).\n  \\end{equation*}\n\n  For every \\( k = 1, \\ldots, n \\) and every \\( j = 0, \\ldots, p_k \\), choose an arbitrary tag\n  \\begin{equation*}\n    \\Eta: \\eta_{k,j} \\in [y_{k,j-1}, y_{k,j}].\n  \\end{equation*}\n\n  Then we have\n  \\begin{balign*}\n    S(f, \\Delta, \\Xi) - I\n    &=\n    S(f, \\Delta, \\Xi) - S(f, \\Gamma, \\Eta) + \\underbrace{S(f, \\Gamma, \\Eta) - I}_{\\in U}\n    \\in \\\\ &\\in\n    \\sum_{k=1}^{n_0} \\sum_{j=1}^{p_k} [ \\underbrace{f(\\xi_{k,j}) - f(\\eta_{k,j})}_{\\in V} ] (y_{k,j} - y_{k,j-1}) + U\n    \\subseteq \\\\ &\\subseteq\n    V \\cdot \\sum_{k=1}^{n_0} \\underbrace{\\sum_{j=1}^{p_k} (y_{k,j} - y_{k,j-1})}_{x_k - x_{k-1}} + U\n    \\subseteq \\\\ &\\subseteq\n    \\diam(\\Delta) \\cdot n_0 \\cdot V + U\n    \\subseteq \\\\ &\\subseteq\n    (\\diam(\\Delta) \\cdot n_0 \\cdot v + 1) U.\n  \\end{balign*}\n\n  Let \\( (\\Delta_1, \\Xi_1) \\) be a tagged partition of \\( [a, b] \\) such that \\( \\diam(\\Delta_1) \\leq \\min \\left\\{ \\diam(\\Delta_0), \\frac 1 {v n_0} \\right\\} \\). It follows that\n  \\begin{equation}\\label{eq:def:riemann_integral/subdiameter_in_neighborhood}\n    S(f, \\Delta_1, \\Xi_1) - I \\subseteq 2U.\n  \\end{equation}\n\n  Until now, \\( U \\) was fixed. Given any neighborhood \\( W \\) of \\( 0 \\), we need to choose a neighborhood \\( U \\) of \\( 0 \\) and a corresponding partition \\( \\Delta_1 \\) such that \\eqref{eq:def:riemann_integral/subdiameter_in_neighborhood} holds. Then, whenever \\( \\diam(\\Delta) \\leq \\diam(\\Delta_1) \\), we have\n  \\begin{equation*}\n    S(f, \\Delta, \\Xi) - I \\subseteq 2U \\subseteq W.\n  \\end{equation*}\n\n  This finishes the proof.\n\n  \\ImplicationSubProof{def:riemann_partition/order/diameter}{def:riemann_partition/order/refinement} Note that if \\( \\Gamma \\) is a refinement of \\( \\Delta \\), clearly \\( \\diam(\\Gamma) \\leq \\diam(\\Delta) \\). Therefore, if the net \\eqref{eq:def:riemann_integral/net} with respect to \\( \\preceq_D \\) is eventually in some open set \\( U \\), the corresponding net with respect to \\( \\preceq_R \\) is also eventually in \\( U \\). This finishes the proof.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:riemann_integrable_implies_bounded}\n  A Riemann-integrable function is bounded.\n\\end{corollary}\n\\begin{proof}\n  Proven in \\fullref{def:riemann_integral}.\n\\end{proof}\n\n\\begin{definition}\\label{def:darboux_integrability}\\mcite[def. 17]{Gordon1991}\n  Let \\( (\\mscrX, \\rho) \\) be a \\hyperref[def:frechet_space]{Frechet space}. Fix a function \\( f: [a, b] \\to X \\). Similarly to \\fullref{def:riemann_integral}, choose any of the orderings \\fullref{def:riemann_partition/order/refinement} and \\fullref{def:riemann_partition/order/diameter} on the set of all untagged \\hyperref[def:riemann_partition/partition]{Riemann partitions} \\( \\op{part}([a, b]) \\).\n\n  For each partition \\eqref{eq:def:riemann_partition/partition}, we define its \\term{oscillation} via the \\hyperref[def:function_oscillation]{function oscillation} of \\( f \\)\n  \\begin{equation}\\label{eq:def:darboux_integrability/oscillation}\n    \\omega(f, \\Delta) \\coloneqq \\sum_{k=1}^n \\omega(f, [x_{k-1}, x_k]) (x_k - x_{k-1}).\n  \\end{equation}\n\n  Consider the net\n  \\begin{equation}\\label{eq:def:darboux_integrability/net}\n    \\{ \\omega(f, \\Delta) \\}_{\\Delta \\in \\op{part}([a, b])}\n  \\end{equation}\n\n  If this net converges to zero, we say that \\( f \\) is \\term{Darboux integrable}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:darboux_integrable_implies_riemann_integrable}\n  In a \\hyperref[def:banach_space]{Banach space}, \\hyperref[def:darboux_integrability]{Darboux integrability} implies \\hyperref[def:riemann_integral]{Riemann integrability}.\n\\end{proposition}\n\\begin{proof}\n  We will show that the net \\eqref{eq:def:riemann_integral/net} is fundamental. Fix \\( \\varepsilon > 0 \\). Since \\( f \\) is Darboux integrable, there exists an untagged partition \\( \\Delta_0 \\) such that, if \\( \\Delta \\) is a refinement of \\( \\Delta_0 \\), we have\n  \\begin{equation*}\n    \\omega(f, \\Delta) < \\varepsilon.\n  \\end{equation*}\n\n  Let \\( \\Delta \\) be a refinement of \\( \\Delta_0 \\) and \\( \\Gamma \\) be a refinement of \\( \\Delta \\). Assume that the points of \\( \\Gamma \\) are split as in \\eqref{def:riemann_partition/refinement/splitting}. Choose arbitrary tags \\( \\Xi = \\{ \\xi_k \\}_{k=1}^n \\) for \\( \\Delta \\) and \\( \\Eta = \\{ \\eta_{k,j} \\}_{k=1,j=1}^{n,p_k} \\) for \\( \\Gamma \\). For the corresponding Riemann sums, we have\n  \\begin{balign*}\n    &\\phantom{{}={}}\n    \\norm{S(f, \\Delta, \\Xi) - S(f, \\Gamma, \\Eta)}\n    = \\\\ &=\n    \\norm{\\sum_{k=1}^n f(\\xi_k) (x_k - x_{k-1}) - \\sum_{k=1}^n \\sum_{j=1}^{p_k} f(\\eta_{k,j}) (y_{k,j} - y_{k,j-1}) }\n    \\leq \\\\ &\\leq\n    \\sum_{k=1}^n \\sum_{j=1}^{p_k} \\norm{f(\\xi_k) - f(\\eta_{k,j})} (y_{k,j} - y_{k,j-1})\n    \\leq \\\\ &\\leq\n    \\sum_{k=1}^n \\sum_{j=1}^{p_k} (y_{k,j} - y_{k,j-1}) \\sup \\{ \\norm{f(\\xi) - f(\\eta)} \\colon \\xi, \\eta \\in [y_{k,j-1}, y_{k,j}] \\}\n    \\leq \\\\ &\\leq\n    \\sum_{k=1}^n \\sup \\{ f(\\xi) - f(\\eta) \\colon \\xi, \\eta \\in [x_{k-1}, x_k] \\} \\underbrace{\\sum_{j=1}^{p_k} (y_{k,j} - y_{k,j-1})}_{x_{k-1} - x_k}\n    = \\\\ &=\n    \\omega(f, \\Delta)\n    <\n    \\varepsilon.\n  \\end{balign*}\n\n  Therefore, the net \\eqref{eq:def:riemann_integral/net} is fundamental and, since \\( \\mscrX \\) is complete, the net converges to a limit.\n\\end{proof}\n\n\\begin{definition}\\label{def:darboux_integral}\n  Fix a real-valued function \\( f: [a, b] \\to \\BbbR \\). The \\term{upper Darboux sum} corresponding to the partition \\eqref{eq:def:riemann_partition/partition} is defined as\n  \\begin{equation*}\n    \\overline{S}(f, \\Delta) \\coloneqq \\sum_{k=1}^n (x_{k-1} - x_k) \\sup_{\\xi \\in [x_{k-1}, x_k]} f(\\xi).\n  \\end{equation*}\n\n  The \\term{lower Darboux sum} is defined as\n  \\begin{equation*}\n    \\underline{S}(f, \\Delta) \\coloneqq \\sum_{k=1}^n (x_{k-1} - x_k) \\inf_{\\xi \\in [x_{k-1}, x_k]} f(\\xi).\n  \\end{equation*}\n\n  If the nets\n  \\begin{align}\\label{eq:def:darboux_integral/nets}\n    \\{ \\overline{S}(f, \\Delta) \\}_{\\Delta \\in \\op{part}([a, b])}\n    &&\n    \\{ \\underline{S}(f, \\Delta) \\}_{\\Delta \\in \\op{part}([a, b])}\n  \\end{align}\n  have a common limit, we call this limit the \\term{Darboux integral} of \\( f \\) and, analogously to \\fullref{def:riemann_integral}, we denote it by\n  \\begin{equation*}\n    \\int_a^b f(x) dx.\n  \\end{equation*}\n\n  This notation is justified by \\fullref{thm:darboux_integral_iff_riemann_integral}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:darboux_integrable_iff_has_darboux_integral}\n  A real-valued function \\( f: [a, b] \\to \\BbbR \\) is \\hyperref[def:darboux_integrability]{Darboux integrable} if and only if it has a \\hyperref[def:darboux_integral]{Darboux integral}.\n\\end{proposition}\n\\begin{proof}\n  Note that, given the partition \\eqref{eq:def:riemann_partition/partition}, we have\n  \\begin{align*}\n    \\overline{S}(f, \\Delta) - \\underline{S}(f, \\Delta)\n    &=\n    \\sum_{k=1}^n (x_k - x_{k-1}) \\left[ \\sup_{\\xi \\in [x_{k-1}, x_k]} f(\\xi) - \\inf_{\\eta \\in [x_{k-1}, x_k]} f(\\eta) \\right]\n    = \\\\ &=\n    \\sum_{k=1}^n (x_k - x_{k-1}) \\left[ \\sup_{\\xi \\in [x_{k-1}, x_k]} f(\\xi) + \\sup_{\\eta \\in [x_{k-1}, x_k]} -f(\\eta) \\right]\n    = \\\\ &=\n    \\sum_{k=1}^n (x_k - x_{k-1}) \\sup \\{ f(\\xi) - f(\\eta) \\colon \\xi, \\eta \\in [x_{k-1}, x_k] \\}\n    = \\\\ &=\n    \\sum_{k=1}^n (x_k - x_{k-1}) \\sup \\{ \\abs{f(\\xi) - f(\\eta)} \\colon \\xi, \\eta \\in [x_{k-1}, x_k] \\}\n    = \\\\ &=\n    \\omega(f, \\Delta).\n  \\end{align*}\n\n  Therefore, the nets \\eqref{eq:def:darboux_integral/nets} converge to a common limit if and only if \\( \\omega(f, \\Delta) \\xrightarrow[\\Delta]{} 0 \\). This finishes the proof.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:darboux_integral_iff_riemann_integral}\n  A real-valued function \\( f: [a, b] \\to \\BbbR \\) has a \\hyperref[def:darboux_integral]{Darboux integral} if and only if it has a \\hyperref[def:riemann_integral]{Riemann integral}. Furthermore, the two integrals are equal.\n\\end{proposition}\n\\begin{proof}\n  Fix \\( \\varepsilon > 0 \\).\n\n  \\ImplicationSubProof{def:darboux_integral}{def:riemann_integral} Denote by \\( I_D \\) the Darboux integral of \\( f \\). Then there exists a partition \\( \\Delta_0 \\) of \\( [a, b] \\) such that for any refinement \\eqref{eq:def:riemann_partition/partition} of \\( \\Delta_0 \\) we have\n  \\begin{equation*}\n    \\overline{S}(f, \\Delta) - \\underline{S}(f, \\Delta) < \\frac \\varepsilon 2.\n  \\end{equation*}\n\n  In particular, \\( I_D - \\underline{S}(f, \\Delta) < \\tfrac \\varepsilon 2 \\).\n\n  Let \\( \\Xi \\coloneqq \\{ \\xi_k \\}_{k=1}^n \\) be tags for \\( \\Delta \\). Then\n  \\begin{align*}\n    \\abs{S(f, \\Delta, \\Xi) - I_D}\n    &\\leq\n    \\abs{S(f, \\Delta, \\Xi) - \\underline{S}(f, \\Delta)} - \\abs{\\underline{S}(f, \\Delta) - I}\n    \\leq \\\\ &\\leq\n    \\abs{\\overline{S}(f, \\Delta) - \\underline{S}(f, \\Delta)} - \\abs{\\underline{S}(f, \\Delta) - I}\n    < \\\\ &<\n    \\frac \\varepsilon 2 + \\frac \\varepsilon 2\n    = \\\\ &=\n    \\varepsilon.\n  \\end{align*}\n\n  Therefore, \\( I_D \\) is also a Riemann integral for \\( f \\).\n\n  \\ImplicationSubProof{def:riemann_integral}{def:darboux_integral} Denote by \\( I_R \\) the Riemann integral of \\( f \\). Then there exists a partition \\eqref{eq:def:riemann_integral/tagged_zero} such that for any partition \\eqref{eq:def:riemann_partition/tagged} with \\( \\diam(\\Delta) \\leq \\diam(\\Delta_0) \\), we have\n  \\begin{equation*}\n    \\abs{S(f, \\Delta, \\Xi) - I_R} < \\frac \\varepsilon 2.\n  \\end{equation*}\n\n  Since \\eqref{thm:riemann_integrable_implies_bounded} is bounded, there exists a constant \\( M > 0 \\) such that \\( \\abs{f(\\xi) - f(\\eta)} < M \\) for any \\( \\xi, \\eta \\in [a, b] \\).\n\n  Using an analogous to \\eqref{def:riemann_partition/subdiameter_splitting} splitting for the refinement \\( \\Gamma \\coloneqq \\Delta \\cup \\Delta_0 \\) of \\( \\Delta_0 \\), we obtain\n  \\begin{align*}\n    \\overline{S}(f, \\Gamma) - S(f, \\Gamma, \\Eta)\n    &=\n    \\sum_{k=1}^{n_0} \\sum_{k=1}^{p_k} [ \\sup_{\\xi \\in [y_{k,j-1}, y_{k,j}]} f(\\eta) - f(\\eta_{k,j}) ] (y_{k,j} - y_{k,j-1})\n    \\leq \\\\ &\\leq\n    M \\sum_{k=1}^{n_0} \\sum_{k=1}^{p_k} (y_{k,j} - y_{k,j-1})\n    \\leq \\\\ &\\leq\n    M \\cdot n_0 \\cdot \\diam(\\Gamma).\n  \\end{align*}\n\n  By choosing a tagged partition \\( (\\Delta_1, \\Xi_1) \\) with \\( \\diam(\\Delta_1) < \\min \\left\\{ \\diam(\\Delta_0), \\frac \\varepsilon {2 M n_0} \\right\\} \\), we obtain\n  \\begin{equation*}\n    \\overline{S}(f, \\Delta_1) - S(f, \\Delta_1, \\Xi) < \\frac \\varepsilon 2.\n  \\end{equation*}\n\n  Therefore, whenever \\( \\diam(\\Delta) \\leq \\diam(\\Delta_1) \\),\n  \\begin{equation*}\n    \\overline{S}(f, \\Delta) - I_R\n    =\n    \\overline{S}(f, \\Delta) - S(f, \\Delta, \\Xi) + S(f, \\Delta, \\Xi) - I_R\n    <\n    \\frac \\varepsilon 2 + \\frac \\varepsilon 2\n    =\n    \\varepsilon.\n  \\end{equation*}\n\n  Thus, the net \\( \\{ \\overline{S}(f, \\Delta) \\}_{\\Delta \\in \\op{part}([a, b])} \\) of upper Darboux sums converges to \\( I \\). We can analogously show that the lower Darboux sums also converge to \\( I_R \\). Hence, \\( I_R \\) is the Darboux integral of \\( f \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:countinuous_functions_integrable}\n  In a \\hyperref[def:frechet_space]{Frechet space} \\( (\\mscrX, \\rho) \\), \\hyperref[def:global_continuity]{continuous functions} \\( f: [a, b] \\to X \\) are \\hyperref[def:darboux_integrability]{Darboux integrable}.\n\\end{proposition}\n\\begin{proof}\n  Fix \\( \\delta > 0 \\). Let \\eqref{eq:def:riemann_partition/partition} be a partition of \\( [a, b] \\) such that \\( \\diam(\\Delta) < \\delta \\). We have\n  \\begin{equation*}\n    \\omega(f, \\Delta)\n    =\n    \\sum_{k=1}^n \\omega(f, [x_{k-1}, x_k]) (x_k - x_{k-1})\n    \\leq\n    \\sum_{k=1}^n \\omega(f, \\diam(\\Delta)) \\diam(\\Delta)\n    <\n    n \\omega(f, \\delta) \\delta.\n  \\end{equation*}\n\n  Now fix \\( \\varepsilon > 0 \\). A continuous function on a compact interval is \\hyperref[def:uniform_continuity]{uniformly continuous}. By \\fullref{thm:def:function_oscillation/properties/continuity_condition}, there exists \\( \\delta_0 > 0 \\) such that \\( \\omega(f, \\delta_0) < \\varepsilon \\). It is then enough to choose\n  \\begin{equation*}\n    \\delta \\coloneqq \\frac {\\delta_0} {n \\varepsilon}\n  \\end{equation*}\n  to obtain\n  \\begin{equation*}\n    \\omega(f, \\Delta)\n    <\n    n \\delta \\omega(f, \\delta)\n    =\n    \\delta_0 \\frac {\\omega(f, \\delta)} {\\varepsilon}\n    \\reloset {\\ref{thm:def:function_oscillation/properties/monotone}} \\leq\n    \\delta_0 \\frac {\\omega(f, \\delta_0)} {\\varepsilon}\n    <\n    \\varepsilon.\n  \\end{equation*}\n\n  Therefore, the same inequality holds for all partitions with diameters smaller than \\( \\delta \\), which implies that \\( f \\) is Darboux integrable.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:componentwise_integration}\n  Let \\( f: [a, b] \\to \\BbbR^n \\) be a function and let \\( f_k, k = 1, \\ldots, n \\) be its components. We have that \\( f \\) is integrable if and only if \\( f_k \\) is integrable for \\( k = 1, \\ldots, n \\). Furthermore,\n  \\begin{equation}\\label{eq:thm:componentwise_integration}\n    \\bigintss_a^b \\begin{pmatrix} f_1(x) \\\\ \\vdots \\\\ f_n(x) \\end{pmatrix} dx\n    =\n    \\begin{pmatrix} {\\displaystyle \\int_a^b f_1(x)} dx \\\\ \\vdots \\\\ {\\displaystyle \\int_a^b f_n(x) dx} \\end{pmatrix}.\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( f \\) be integrable and let \\( I = (I_1, \\ldots, I_n)^T \\) be the value of the integral. Fix \\( \\varepsilon > 0 \\) and let \\( (\\Delta, \\Xi) \\) be a tagged partition such that\n  \\begin{equation*}\n    \\norm{I - S(f, \\Delta, \\Xi)} < \\varepsilon.\n  \\end{equation*}\n\n  Then for any \\( k = 1, \\ldots, n \\) we have\n  \\begin{equation*}\n    \\norm{I - S(f, \\Delta, \\Xi)}^2\n    =\n    \\sum_{m=1}^n \\abs{I_m - S(f_m, \\Delta, \\Xi)}^2\n    \\geq\n    \\abs{I_k - S(f_k, \\Delta, \\Xi)}^2,\n  \\end{equation*}\n  hence\n  \\begin{equation*}\n    \\abs{I_k - S(f_k, \\Delta, \\Xi)} < \\varepsilon.\n  \\end{equation*}\n\n  Therefore, \\( f_k \\) is integrable and\n  \\begin{equation*}\n    \\int_a^b f_k(x) dx = I_k.\n  \\end{equation*}\n\n  \\NecessitySubProof Let \\( f_k \\) be integrable for \\( k = 1, \\ldots, n \\) with value \\( I_k \\). Put \\( I \\coloneqq (I_1, \\ldots, I_n)^T \\). Fix \\( \\delta > 0 \\) and let \\( (\\Delta_k, \\Xi_k) \\) be a parition such that\n  \\begin{equation*}\n    \\abs{I_k - S(f_k, \\Delta_k, \\Xi_k)} < \\delta\n  \\end{equation*}\n\n  Let \\( \\Gamma \\coloneqq \\bigcup_{k=1}^n \\Delta_k \\) and let \\( \\Eta \\) be tags for \\( \\Gamma \\). Since \\( \\diam(\\Gamma) \\leq \\diam(\\Delta_k) \\) and since \\( f_k \\) is integrable, we have\n  \\begin{equation*}\n    \\abs{I_k - S(f_k, \\Gamma, \\Eta)} < \\delta \\quad\\forall k = 1, \\ldots, n.\n  \\end{equation*}\n\n  We have\n  \\begin{equation*}\n    \\norm{I - S(f, \\Gamma, \\Eta)}\n    =\n    \\sqrt{\\sum_{m=1}^n \\abs{I_m - S(f_m, \\Gamma, \\Eta)}^2}\n    <\n    \\delta \\sqrt{n}.\n  \\end{equation*}\n\n  Therefore, given \\( \\varepsilon > 0 \\), it is enough to choose \\( \\delta \\coloneqq \\frac {\\varepsilon} {\\sqrt n} \\) to obtain a tagged partition \\( (\\Gamma_0, \\Eta_0) \\), so that for \\( (\\Gamma, \\Eta) \\) with \\( \\diam(\\Gamma) < \\diam(\\Gamma_0) \\) we have\n  \\begin{equation*}\n    \\norm{I - S(f, \\Gamma, \\Eta)} < \\varepsilon.\n  \\end{equation*}\n\n  This proves integrability of \\( f \\) and \\eqref{eq:thm:componentwise_integration}.\n\\end{proof}\n", "meta": {"hexsha": "3699721123b0bb41028ee359158e2ea057ddde0b", "size": 22643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/riemann_integration.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/riemann_integration.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/riemann_integration.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": 54.693236715, "max_line_length": 447, "alphanum_fraction": 0.6288036038, "num_tokens": 8475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.6623708171867368}}
{"text": "\\title{KL(p||q) Minimization}\n\n\\subsection{$\\text{KL}(p\\|q)$ Minimization}\n\nOne form of variational inference minimizes the Kullback-Leibler divergence\n\\textbf{from} $p(\\mathbf{z} \\mid \\mathbf{x})$ \\textbf{to} $q(\\mathbf{z}\\;;\\;\\lambda)$,\n\\begin{align*}\n  \\lambda^*\n  &=\n  \\arg\\min_\\lambda \\text{KL}(\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  \\;\\|\\;\n  q(\\mathbf{z}\\;;\\;\\lambda)\n  )\\\\\n  &=\n  \\arg\\min_\\lambda\\;\n  \\mathbb{E}_{p(\\mathbf{z} \\mid \\mathbf{x})}\n  \\big[\n  \\log p(\\mathbf{z} \\mid \\mathbf{x})\n  -\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big].\n\\end{align*}\nThe KL divergence is a non-symmetric, information theoretic measure of\nsimilarity between two probability distributions.\n\n\\subsubsection{Minimizing an intractable objective function}\n\nThe $\\text{KL}(p\\|q)$ objective we seek to minimize is intractable; it directly\ninvolves the posterior $p(\\mathbf{z} \\mid \\mathbf{x})$. Ignoring this for the moment, consider its\ngradient\n\\begin{align*}\n  \\nabla_\\lambda\\;\n  \\text{KL}(\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  \\;\\|\\;\n  q(\\mathbf{z}\\;;\\;\\lambda)\n  )\n  &=\n  -\n  \\mathbb{E}_{p(\\mathbf{z} \\mid \\mathbf{x})}\n  \\big[\n  \\nabla_\\lambda\\;\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big].\n\\end{align*}\nBoth $\\text{KL}(p\\|q)$ and its gradient are intractable\nbecause of the posterior expectation.\nWe can use importance sampling to both\nestimate the objective and calculate stochastic gradients\n\\citep{oh1992adaptive}.\n\n\\subsubsection{Adaptive Importance sampling}\n\nFirst rewrite the expectation to be with respect to the variational\ndistribution,\n\\begin{align*}\n  -\n  \\mathbb{E}_{p(\\mathbf{z} \\mid \\mathbf{x})}\n  \\big[\n  \\nabla_\\lambda\\;\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big]\n  &=\n  -\n  \\mathbb{E}_{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\Bigg[\n  \\frac{p(\\mathbf{z} \\mid \\mathbf{x})}{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\nabla_\\lambda\\;\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\Bigg].\n\\end{align*}\n\nWe then use importance sampling to obtain a noisy estimate of this gradient.\nThe basic procedure follows these steps:\n\\begin{enumerate}\n  \\item draw $S$ samples $\\{\\mathbf{z}_s\\}_1^S \\sim q(\\mathbf{z}\\;;\\;\\lambda)$,\n  \\item evaluate $\\nabla_\\lambda\\; \\log q(\\mathbf{z}_s\\;;\\;\\lambda)$,\n  \\item compute the normalized importance weights\n  \\begin{align*}\n    w_s\n    &=\n    \\frac{p(\\mathbf{z}_s \\mid \\mathbf{x})}{q(\\mathbf{z}_s\\;;\\;\\lambda)}\n    \\Bigg/\n    \\sum_{s=1}^{S}\n    \\frac{p(\\mathbf{z}_s \\mid \\mathbf{x})}{q(\\mathbf{z}_s\\;;\\;\\lambda)}\n  \\end{align*}\n  \\item compute the weighted mean.\n\\end{enumerate}\nThe key insight is that we can use the joint $p(\\mathbf{x},\\mathbf{z})$ instead of the posterior\nwhen estimating the normalized importance weights\n\\begin{align*}\n  w_s\n  &=\n  \\frac{p(\\mathbf{z}_s \\mid \\mathbf{x})}{q(\\mathbf{z}_s\\;;\\;\\lambda)}\n  \\Bigg/\n  \\sum_{s=1}^{S}\n  \\frac{p(\\mathbf{z}_s \\mid \\mathbf{x})}{q(\\mathbf{z}_s\\;;\\;\\lambda)} \\\\\n  &=\n  \\frac{p(\\mathbf{x}, \\mathbf{z}_s)}{q(\\mathbf{z}_s\\;;\\;\\lambda)}\n  \\Bigg/\n  \\sum_{s=1}^{S}\n  \\frac{p(\\mathbf{x}, \\mathbf{z}_s)}{q(\\mathbf{z}_s\\;;\\;\\lambda)}.\n\\end{align*}\nThis follows from Bayes' rule\n\\begin{align*}\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  &=\n  p(\\mathbf{x}, \\mathbf{z}) / p(\\mathbf{x})\\\\\n  &=\n  p(\\mathbf{x}, \\mathbf{z}) / \\text{a constant function of }\\mathbf{z}.\n\\end{align*}\n\nImportance sampling thus gives the following biased yet consistent gradient\nestimate\n\\begin{align*}\n\\nabla_\\lambda\\;\n  \\text{KL}(\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  \\;\\|\\;\n  q(\\mathbf{z}\\;;\\;\\lambda)\n  )\n  &=\n  -\n  \\frac{1}{S}\n  \\sum_{s=1}^S\n  w_s\n  \\nabla_\\lambda\\; \\log q(\\mathbf{z}_s\\;;\\;\\lambda).\n\\end{align*}\nThe objective $\\text{KL}(p\\|q)$ can be calculated in a similar fashion.\nThe only new ingredient for its gradient is the score function\n$\\nabla_\\lambda \\log q(\\mathbf{z}\\;;\\;\\lambda)$.  Edward uses automatic\ndifferentiation, specifically with TensorFlow's computational graphs,\nmaking this gradient computation both simple and efficient to\ndistribute.\n\nAdaptive importance sampling follows this gradient to a local optimum using\nstochastic optimization. It is adaptive because the variational distribution\n$q(\\mathbf{z}\\;;\\;\\lambda)$ iteratively gets closer to the posterior $p(\\mathbf{z} \\mid \\mathbf{x})$.\n\nFor more details, see the \\href{/api/}{API} as well as its\nimplementation in Edward's code base.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "f3e7525fedb5ea94652801b53716ae20688337fe", "size": 4266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/klpq.tex", "max_stars_repo_name": "NunoEdgarGFlowHub/edward", "max_stars_repo_head_hexsha": "298fb539261c71e34d5e7aa5a37ed8a029df0820", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-11T03:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-11T03:33:36.000Z", "max_issues_repo_path": "docs/tex/tutorials/klpq.tex", "max_issues_repo_name": "NunoEdgarGFlowHub/edward", "max_issues_repo_head_hexsha": "298fb539261c71e34d5e7aa5a37ed8a029df0820", "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/klpq.tex", "max_forks_repo_name": "NunoEdgarGFlowHub/edward", "max_forks_repo_head_hexsha": "298fb539261c71e34d5e7aa5a37ed8a029df0820", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-13T06:58:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-13T06:58:00.000Z", "avg_line_length": 29.4206896552, "max_line_length": 101, "alphanum_fraction": 0.6586966714, "num_tokens": 1517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6623704705109951}}
{"text": "\n\\subsection{The AK model}\n\n\\subsubsection{Recap of growth models}\n\nAs with the Harrod-Domar model we have output as a function of capital:\n\n\\(Y=f(K)\\)\n\nCapital dynamics:\n\n\\(\\dot K=I-\\delta K\\)\n\n\\(I=S=sY\\)\n\nThis gives us:\n\n\\(\\dot K = sY-\\delta K\\)\n\n\\subsubsection{Recap of the Harrod-Domar and Solow-Swan models}\n\nIn the Solow-Swan model the production function was:\n\n\\(Y=K^\\alpha (AL)^{1-\\alpha }\\)\n\nIn the Harrod-Domar model the production function was:\n\n\\(Y=cK\\)\n\nIn the Solow-Swan model we also added population and technology growth\n\n\\subsubsection{The AK model}\n\nIn the AK model the production function is:\n\n\\(Y=AK\\)\n\nWe keep population growth from the Solow-Swan model.\n\n\\subsubsection{Per-capita income}\n\n\\(\\dot K = sAK-\\delta K\\)\n\n\\(\\dot K = (sA-\\delta )K\\)\n\n\\(k=\\dfrac{K}{L}\\)\n\n\\(\\dot k =\\dfrac{\\dot K}{L}-\\dot L\\dfrac{K}{L^2}\\)\n\n\\(\\dot k =\\dfrac{(sA-\\delta )K}{L}-\\dot L\\dfrac{K}{L^2}\\)\n\n\\(\\dot k =(sA-\\delta )k-k\\dfrac{\\dot L}{L}\\)\n\n\\(\\dot k =(sA-\\delta -n)k\\)\n\n\\(\\dfrac{\\dot k}{k} =sA-\\delta -n\\)\n\n", "meta": {"hexsha": "b52dfaf163a7ad85e691dd79aaf474760c2624a6", "size": 1011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/neoClassical/04-01-AK.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/neoClassical/04-01-AK.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/neoClassical/04-01-AK.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.4310344828, "max_line_length": 71, "alphanum_fraction": 0.649851632, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6623704632625919}}
{"text": "\\section{An alternative approach}\n\nTo complete our analysis, we thought to seek alternative models to compare with the ones described above. Our idea was to consider different approaches to see if they lead to same results. After some research we found a new process, discussed in \\cite{7520324}, that proposed a linear proceedings to determine the error. \\\\\n% During the analysis discussed above, we encountered some problems: few of them were caused by misunderstandings of parts of the model itself, some others by calculation or implementation errors. All these errors prevented us to reach meaningful result during the test phase. Thus, we decided to look for alternative solutions in order to place them side by side with our model and, if possible, to correct it and compare final results. After some research we found a new process, discussed in \\cite{7520324}, and proposed to fully understand the propagation error in laser triangulation-based systems. \\\\\n\nThis new model is based on \\cite{576335}, that proposed a way to propagate approximately additive random perturbations through vision algorithms in which the appropriate random perturbation model for the estimated quantity (produced by the vision step) is also an additive random perturbation. We have considered this aspect very interesting because if we are able to find a linear description $f(\\nu, \\theta)$ of our problem, we can theoretically evaluate the error propagation over the experimental parameters $\\hat{\\theta}$ when they are not derived by an experimental observation of the noise $\\nu$, but through a minimization such as:\n  \\begin{equation*}\n    \\hat{\\theta} = argmin_{\\theta} \\, f(\\nu, \\theta)\n  \\end{equation*}\nIn this case, the propagation error we are interested in, is given by the covariance matrix $\\Sigma_{\\hat{\\theta}}$ of each parameter involved by the system. A general for of this matrix is given by:\n  \\begin{equation*}\n    \\Sigma_{\\hat{\\theta}} =\n      \\left( \\frac{\\partial g}{\\partial \\theta} \\right)^{-1}\n      \\frac{\\partial g}{\\partial \\nu}^T\n      \\Sigma_\\nu\n      \\frac{\\partial g}{\\partial \\nu}\n      \\left(\\left( \\frac{\\partial g}{\\partial \\theta} \\right)^{-1}\\right)^T\n  \\end{equation*}\nwhere $\\Sigma_\\nu$ is the covariance matrix of the observed noise. To make a complete and robust description of the problem, we have to build this last matrix properly.\n\nFrom a geometrical point of view, a 3D point in the world reference system must satisfy both the camera perspective projection model (Equation \\ref{eq:perspective_projection}) as well as the laser plane equation $x^T\\boldsymbol{n} = d$, where $\\boldsymbol{n}$ is the plane normal vector, and $d = 0$ accordingly with the coplanar version of Tsai \\cite{TsaiTvLenses}. This allows to build a system of equation, described by: \n  \\begin{equation}\n    \\begin{bmatrix}\n      \\boldsymbol{r}^T - \\boldsymbol{v}^T \\frac{(x_p - c_x)}{f_x} \\\\\n      \\boldsymbol{u}^T - \\boldsymbol{v}^T \\frac{(y_p - c_y)}{f_y} \\\\\n      \\boldsymbol{n}^T\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      x_w \\\\ y_w \\\\ z_w\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n      \\frac{(x_p - c_x)}{f_x} t_3 - t_1 \\\\\n      \\frac{(y_p - c_y)}{f_y} t_2 - t_1 \\\\\n      d\n    \\end{bmatrix}\n    \\label{eq:app2-model}\n  \\end{equation}\nThe vectors $\\boldsymbol{r}$, $\\boldsymbol{u}$ and $\\boldsymbol{v}$ are the row vectors of the rotation matrix $R^T = \\begin{bmatrix} \\boldsymbol{r} & \\boldsymbol{u} & \\boldsymbol{v} \\end{bmatrix}$, while $t_i$ is the element of the translation vector $T^T = \\begin{bmatrix} t_1 & t_2 & t_3 \\end{bmatrix}$. We can rewrite the system of equation as:\n  \\begin{equation*}\n    A\\boldsymbol{x} = \\boldsymbol{b}\n  \\end{equation*}\nand we obtain a linear equation that can be used to determine $\\hat{\\theta}$. Furthermore, if we perturb this last equation, we obtain something like:\n  \\begin{equation*}\n    (\\boldsymbol{x} + \\delta \\boldsymbol{x}) = (A + \\delta A)^{-1}(\\boldsymbol{b} + \\delta \\boldsymbol{b})\n  \\end{equation*}\nAt this point it is simple to identify all the parameters from Equation \\ref{eq:app2-model} that are included in $\\Sigma_{\\nu}$. \\\\\n\nTo simplify the determination of significant factor, the authors suggest to group the parameters of interest in a few set:\n  \\begin{enumerate}\n    \\item \\textit{Camera Intrinsic Calibration Uncertainty} \\\\\n    We have already discussed extensively in the Section \\ref{sec:calib-model} the issues that arise when we try to consider the propagation error in the calibration phase. The same conclusions are still valid in this case.\n    \n  \\item \\textit{Positioning Uncertainty} \\\\\n  In this set are grouped both the position of the camera as well as the one of the laser. Concerning the position of the camera, we can consider its position deviations as negligible. From our point of view, if we move camera with respect of its ideal position, we will see some changes about its \\acs{DOF} or resolution, that can be fixed by correcting lens focus, but not a substantial degradation of the ability to correctly detect the sub-pixel position of the laser spot.  \\\\\n  About the laser, instead, we are strongly interested in determining as precisely as possible its pitch and roll rotations. If on the one hand laser rotations could be manufacture errors, on the other many system like \\acs{WPMS}s acquire the laser when the target is not perpendicular to the laser itself. Thus, it is of primary importance to be able to determine the right laser orientation. In \\cite{7520324} the authors proposed to use the rotation matrix \\ref{eq:second-app-laser-rot} to determine the error in laser positioning.\n  \\begin{equation}\n      \\begin{bmatrix}\n          \\sin(e_\\theta)\\cos(e_\\phi) \\\\ \\sin(e_\\theta)\\sin(e_\\phi) \\\\ \\cos(e_\\theta)\n      \\end{bmatrix}\n      \\label{eq:second-app-laser-rot}\n   \\end{equation}\n    \n    \\item \\textit{Laser detection} \\\\\n    Following the idea as the one used in our model, it is natural to underline that errors of interest are the ones made by determining the position of the spot laser at sub-pixel accuracy, i.e. $\\sigma_{x}$ and $\\sigma_{y}$ (with $x$ and $y$ taken accordingly to the laser reference system), and $Cov_{xy}$ for the spot, under the hypothesis that the two coordinates are i.i.d. random variables. \\\\\n    However, accordingly with \\cite{7520324}, this seems not to be correct. In fact the authors suggest to perform some test on a known system, and to use the variations of the spot position between couples of acquisitions to make a statistics on the committed errors.\n    \n    \\item \\textit{Lens distortions and the point discretization} \\\\\n    As we done in the previous model, also in this case we considered the contributions due by lens distortions and the point discretization on the 2D sensor plane. To do that, we consider the same analysis done in the Sections \\ref{sec:model-lens-distortion} and \\ref{sec:laser-peaks}.\n  \\end{enumerate}\n\nOnce all the parameters of interest have been defined, we tried to build the covariance matrix $\\Sigma_\\nu$: removing all the parameters that we considered negligible, we obtained a $6\\times6$ matrix. We notice that many dependency relationships were not trivial to determine, sometimes because we couldn't understand what type of relations existed between the couple of parameters. Furthermore, the conclusion reached talking about laser detection (point 3 of the list above) does not convince us. Our goal is to develop a mathematical model that can be used without any information on the performance of a possible real system: the necessity to make an error statistic using real data is out of our requirements. \\\\\nAll these difficulties in creating the matrix $\\Sigma_\\nu$, and the bad results obtained using this second model, discouraged us to continue along this way.\n", "meta": {"hexsha": "e4aa703de45666524a462e11fb8d4217a419b0fc", "size": 7770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch4-Model/8_second-app.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/8_second-app.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/8_second-app.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": 105.0, "max_line_length": 717, "alphanum_fraction": 0.7464607465, "num_tokens": 1927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6622228064095039}}
{"text": "\\chapter{Weights and forces}\n\nPretend that the concept of \\emph{mass} has not been invented.\n\n\\emph{Weight} is what a weight balance measures.\n\nA weight balance has two arms.\n\nPut a weight on an end of a weight balance.\nPush the other end with your hand until the balance comes to rest.\nWhen they reach equilibrium,\nboth of them exerts the same amount of \\emph{force}.\n\n\\section{Law of the lever}\n\n% https://en.wikipedia.org/wiki/Virtual_work#Law_of_the_lever\n% https://en.wikipedia.org/wiki/Lever\n\n\\index{definitions!lever}%\n\\index{lever!definition}%\n\\index{simple machine!lever|see{lever}}%\nA \\emph{lever} has a fulcrum and two ends.\n\nLet \\(r_1\\) be the distance between the first end to the fulcrum.\n\nLet \\(r_2\\) be the distance between the second end to the fulcrum.\n\nLet \\(F_1\\) be the weight placed at the first end.\n\nLet \\(F_2\\) be the weight placed at the second end.\n\n\\index{Archimedes!law of the lever}%\n\\index{laws named after people!Archimedes's law of the lever}%\n\\index{laws!lever}%\n\\index{lever!law of the lever}%\n\\index{statics!Archimedes's law of the lever}%\n\\emph{Law of the lever}:\nSuch lever at equilibrium satisfies \\(F_1 \\cdot r_1 = F_2 \\cdot r_2\\).\n\nWe take this law as evident.\nDoubt can be removed by a simple experiment.\n\nThus, a weight balance is a lever whose arms have equal length.\n", "meta": {"hexsha": "d11257ac9d574c8f750a0e680bf57faff6ab027f", "size": 1312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/force.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/force.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/force.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": 29.8181818182, "max_line_length": 70, "alphanum_fraction": 0.75, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6622228005410099}}
{"text": "\\subsection{Great-circle distance}\nThe shortest distance between two points $A$ and $B$ on a sphere $(O,r)$ is given by travelling along plane $OAB$. It is called the \\emph{great-circle distance} because it follows the circumference of one of the big circles of radius $r$ that split the sphere in two.\n\n\\centerFig{sph-4}\n\nSo computing the distance between $A$ and $B$ amounts to finding the length of the circle arc joining them. This arc is subtended by angle $\\theta$, the angle between $\\vv{OA}$ and $\\vv{OB}$, so its length is simply $r\\theta$.\n\\begin{lstlisting}\ndouble greatCircleDist(p3 o, double r, p3 a, p3 b) {\n    return r * angle(a-o, b-o);\n}\n\\end{lstlisting}\n\nThis code also works if $A$ and $B$ are not actually on the sphere, in which case it will give the distance between their projections on the sphere:\n\n\\centerFig{sph-5}\n\nNote that in most 2D projections this great-circle path is not a straight line, and it tends to bend northward in the Northern Hemisphere, and southward in the Southern Hemisphere. This is why, for example, flights going from London to Los Angeles fly over Greenland, although it is much further North than both cities.\n\n\\centerFig{sph-6}\n\n\\subsection{Spherical segment intersection}\nFor points $A$ and $B$ on a sphere, we define spherical segment $[AB]$ as the path drawn by the great-circle distance between $A$ and $B$ on the sphere. This is not well-defined if $A$ and $B$ are directly opposite each other on the sphere, because there would be many possible shortest paths.\n\nFrom simplicity, we assume that the sphere is centered at the origin. \nWe will call a segment $[AB]$ \\emph{valid} if $A$ and $B$ are not opposite each other on the sphere, or in other words, if their directions as vectors are not directly opposite each other. Note that this definition accepts segments where $A=B$.\n\\begin{lstlisting}\nbool validSegment(p3 a, p3 b) {\n    return a*b != zero || (a|b) > 0;\n}\n\\end{lstlisting}\n\nGiven two spherical segments $[AB]$ and $[CD]$, we would like to figure out if they intersect, and what their intersection is. This is part of a more general problem: given two segments $[AB]$ and $[CD]$ in space, if we view them from an observation point $O$, does one of them hide part of the other, that is, is there a ray from $O$ that touches them both?\n\n\\begin{center}\n    \\begin{tabu} to .9\\linewidth {X[c]X[c]}\n        \\includeFig{sph-7} & \\includeFig{sph-8} \\\\\n        common point on sphere & common ray from $O$ \\\\\n    \\end{tabu}\n\\end{center}\n\nWe will solve the general problem, and make sure that our answer is always exact when points $A,B,C,D$ are integer points. To do this, we will separate cases just like we did for 2D segment intersection in section~\\ref{ss:seg-seg-inter}:\n\\begin{enumerate}\n\\item Segments $[AB]$ and $[CD]$ intersect \\term{properly}, that is, their intersection is one single point which is not an endpoint of either segment. For the general problem this means that there is a single ray from $O$ that touches both $[AB]$ and $[CD]$, and it doesn't touch any of $A,B,C,D$.\n\\item In all other cases, the intersection, if it exists, is determined by the endpoints. If it is a single point, it must be one of $A,B,C,D$, and if it is a whole segment, it will necessarily start and end with points in $A,B,C,D$.\n\\end{enumerate}\n\nFor the rest of explanation, we will consider the case of spherical segment intersection, because it's easier to visualize, but it should be easy to verify that this also applise to the general problem.\n\n\\subsubsection{Proper intersection}\nLet's deal with the first case: there is a single proper intersection point $I$. For this to be the case, $A$ and $B$ must be on either side of plane $OCD$, and $C$ and $D$ must be on either side of plane $OAB$. Put another way, $A$ and $B$ must be on either side of the great circle containing $C$ and $D$, and vice versa.\n\n\\centerFig{sph-9}\n\nWe can check this with mixed product. We have to verify that\n\\begin{itemize}\n\\item $o_A = (C \\times D) \\cdot A$ and $o_B = (C \\times D) \\cdot B$ have opposite signs;\n\\item $o_C = (A \\times B) \\cdot C$ and $o_D = (A \\times B) \\cdot D$ have opposite signs.\n\\end{itemize}\n\nHowever, this time it's not enough. Sometimes, even though the conditions above are verified, there is no intersection, because the segments are on opposite sides of the sphere:\n\n\\begin{center}\n    \\includeFig{sph-10}\n    \n    $C$ and $D$ are on the other side of the sphere\n\\end{center}\n\nTo eliminate this kind of case, we also have to check that $o_A$ and $o_C$ have opposite signs (this is clearly not the case here).\n\n\\exo{Consider a few more examples and verify that these criteria correctly detect proper intersections in all cases.}\n\nThe intersection point $I$ must be in the intersection of planes $OAB$ and $OCD$.\nSo direction $\\vv{OI}$ must be perpendicular to their normals $A \\times B$ and $C \\times D$, that is, parallel to $(A \\times B) \\times (C \\times D)$.\nMultiplying this by the sign of $o_D$ gives the correct direction.\n\nThis is implemented by the code below. Note that the result, \\lstinline|out|, only gives the direction of the intersection. If we want to find the intersection on the sphere, we need to scale it to have length $r$.\n\\begin{lstlisting}\nbool properInter(p3 a, p3 b, p3 c, p3 d, p3 &out) {\n    p3 ab = a*b, cd = c*d; // normals of planes OAB and OCD\n    int oa = sgn(cd|a),\n        ob = sgn(cd|b),\n        oc = sgn(ab|c),\n        od = sgn(ab|d);\n    out = ab*cd*od; // four multiplications => careful with overflow!\n    return (oa != ob && oc != od && oa != oc);\n}\n\\end{lstlisting}\n\n\\subsubsection{Improper intersections}\nTo deal with the second case, we will do as for 2D segments and test for every point among $A,B,C,D$ if it is on the other segment. If it is, we add it to a set $S$. $S$ will contain 0, 1, or 2 distinct points, describing an empty intersection, a single intersection point or an intersection segment.\n\n\\centerFig{sph-11}\n\nTo check whether a point $P$ is on spherical segment $[AB]$, we need to check that $P$ is on plane $OAB$, but also that $P$ is is ``between`` rays $[OA)$ and $[OB)$ on that plane.\n\nLet $\\vv{n} = A \\times B$, a normal of plane $OAB$. Checking that $P$ is on plane $OAB$ is easy: $\\vv{n}\\cdot P$ should be 0. If $P$ is indeed on plane $OAB$, then we can check if it is to the ``right'' of $[OA)$ by looking at cross product $A \\times P$. It should be perpendicular to plane $OAB$. If it is in the same direction as $\\vv{n}$, then $P$ is to the right of $OA$, and if it is in the opposite direction, then $P$ is to the left of $OA$. So we need to check $\\vv{n} \\cdot (A \\times P) \\geq 0$.\nSimilarly, to check that $P$ is to the left of $OB$, we should check $\\vv{n} \\dot (B \\times X) \\leq 0$.\n\n\\centerFig{sph-12}\n\nThere remains only one special case: if $A$ and $B$ are the same point on the sphere, then $\\vv{n}=\\vv{0}$, and then we should just check that $P$ is also that same point.\n\nWe arrive at the following implementation. To handle the general problem, instead of directly checking for equality between $P$ and $A$ or $B$, we check that they are in the same direction with the cross product.\n\\begin{lstlisting}\nbool onSphSegment(p3 a, p3 b, p3 p) {\n    p3 n = a*b;\n    if (n == zero)\n        return a*p == zero && (a|p) > 0;\n    return (n|p) == 0 && (n|a*p) >= 0 && (n|b*p) <= 0;\n}\n\\end{lstlisting}\n\nNow we just have to put all of this together in one function. First we check for a proper intersection, then if there is none we check segment by segment and add the points to set $S$. Since (as mentioned) we can't check for equality directly, we use a custom set structure that checks if the cross product is zero for every point already in the set.\n\\begin{lstlisting}\nstruct directionSet : vector<p3> {\n    using vector::vector; // import constructors\n    void insert(p3 p) {\n        for (p3 q : *this) if (p*q == zero) return;\n        push_back(p);\n    }\n};\ndirectionSet intersSph(p3 a, p3 b, p3 c, p3 d) {\n    assert(validSegment(a, b) && validSegment(c, d));\n    p3 out;\n    if (properInter(a, b, c, d, out)) return {out};\n    directionSet s;\n    if (onSphSegment(c, d, a)) s.insert(a);\n    if (onSphSegment(c, d, b)) s.insert(b);\n    if (onSphSegment(a, b, c)) s.insert(c);\n    if (onSphSegment(a, b, d)) s.insert(d);\n    return s;\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "2e1e98c283f9337f66c23734e04caa4b438f9b40", "size": 8304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/3d/sph/sph-segs.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/sph/sph-segs.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/sph/sph-segs.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.9701492537, "max_line_length": 504, "alphanum_fraction": 0.703155106, "num_tokens": 2344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6622228005410098}}
{"text": "\\chapter{Random}\nA game will rarely stay interesting when it is completely predictable. To avoid predictability, developers use random values provided by the \\eeClass{Random} class.\n\n\\section{Whole Numbers}\nThe function \\eeFunc{Random()} returns a random number between 0 and 4.294.967.295. Check this yourself with the next example:\n\n\\begin{code}\nuint number = 0;\n\nbool Update() {\n  if(Kb.bp(KB_SPACE)) number = Random();\n\treturn true;\n}\n\nvoid Draw() {\n\tD.clear(BLACK);\n\tD.text(0, 0, S + number);\n}\n\\end{code}\n\nYou will rarely need a number this big. Which is why you can use the \\eeClass{Random()} function with one or more arguments. When used with one argument, the function will return a number in the range 0 to the argument minus one. In other words, \\eeClass{Random(5)}  will return one of the values 0, 1, 2, 3 or 4. Count them, that's 5 different values. A common beginners mistake is to expect the number five as a result. That will never, ever happen!\n\nIt is also possible to pass two arguments. \\eeClass{Random(-2, 4)} returns one of these values: -2, -1, 0, 1, 2, 3 or 4. The important thing to remember that with this version, the arguments are inclusive.\n\n\\begin{exercise}\nCreate the basics of a lottery application. Show a new number from 1 to 42 (inclusive) on the screen every time you press the space bar. \n\\end{exercise}\n\n\\begin{note}\nHow to get a random color? The RGB values which make up a color have a value between 0 and 255. To randomize a color, try this:\n\n\\begin{code}\nColor myColor;\nmyColor.set(Random(256), Random(256), Random(256));\n\\end{code}\n\\end{note}\n\n\\section{Random Float}\nSo far we've discussed random whole numbers. But you will often need floating point values. These are provided by the function \\eeFunc{RandomF()}. This function will return a value between 0 and 1 by default, but it will also accept arguments. \\eeFunc{RandomF(3)} will return a value between 0 and 3. \\eeFunc{RandomF(-1.3, 2.5)} returns one between -1.3 and 2.5.\n\nThese functions are often used to show an object on a random position. Like so:\n\n\\begin{code}\nCircle c;\n\nc.pos.x = RandomF(-D.w(), D.w());\nc.pos.y = RandomF(-D.h(), D.h());\n\\end{code}\n\nIn the example above, we won't even pass actual numbers to the function \\eeFunc{RandomF()}. Instead, we let our application decide. The width and height of the screen are not the same on every device. By asking the engine about it, we will always end up with the correct values.\n\n\\begin{exercise}\nCreate an application which shows a circle on the screen. Every time the space bar is pressed, you change the circle's position.\n\\end{exercise}\n\\begin{exercise}\nCreate an application with a small rectangle on the screen. Assign a new position every second. \n\\end{exercise}\n\\begin{exercise}\nStarting from the previous exercise, add an int `score' equal to zero. Draw this score somewhere on the screen. When the left mouse button is pressed, check if the mouse pointer is on top of the rectangle. If it is, increase the score by one.\n\\end{exercise}\n\\begin{exercise}\n\\textit{(A bit harder)} With every score increase, the position of the rectangle should change a bit faster.\n\\end{exercise}\n\n\n\n", "meta": {"hexsha": "fd42f49c4825ca014600661c1a0a11288f5f1097", "size": 3149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course/en/basics/random.tex", "max_stars_repo_name": "yvanvds/EsenthelCourse", "max_stars_repo_head_hexsha": "2522fd91dfba1f93fd623eb0b50e55d560d6c803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "course/en/basics/random.tex", "max_issues_repo_name": "yvanvds/EsenthelCourse", "max_issues_repo_head_hexsha": "2522fd91dfba1f93fd623eb0b50e55d560d6c803", "max_issues_repo_licenses": ["MIT"], "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/en/basics/random.tex", "max_forks_repo_name": "yvanvds/EsenthelCourse", "max_forks_repo_head_hexsha": "2522fd91dfba1f93fd623eb0b50e55d560d6c803", "max_forks_repo_licenses": ["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.0, "max_line_length": 451, "alphanum_fraction": 0.7484915846, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6622225100294026}}
{"text": "\\begin{intro}\n  The following results can be found in any book on linear\n  algeba. Thus, we will just keep the arguments short. There will be a\n  focus on normal matrices justified by results on conditioning of\n  eigenvalue problems later on.\n\n  Thus, spectral theory based on module theory will not be needed in\n  this class. The spectral theorem for normal matrices on the other\n  hand is fairly simple and can be proved without too much overhead.\n\\end{intro}\n\n\\begin{Definition}{eigenvalue}\n  An \\define{eigenvalue} of a matrix $\\mata\\in \\C^{n\\times n}$ is a\n  complex number $\\lambda$ such that the matrix\n  \\begin{gather}\n   \\mata-\\lambda\\id \n  \\end{gather}\n  is singular.\n\n  The set of all eigenvalues of $\\mata$ is called the\n  \\define{spectrum} $\\sigma(\\mata)$.\n\n  The \\define{eigenspace} for $\\lambda$ is the kernel of\n  $A-\\lambda\\id$, that is, the set\n\\begin{gather}\n    \\esp{\\lambda} = \\bigl\\{\n    \\vv \\in \\C^n \\;\\big\\vert\\;\n    \\mata\\vv = \\lambda\\vv \\bigr\\}.\n\\end{gather}\nThe \\define{geometric multiplicity} of $\\lambda$ is the dimension of\n$\\esp{\\lambda}$.\n\n\nAn \\define{eigenvector} for $\\lambda$ is a (normed) vector in\n$\\esp\\lambda$. We refer to an eigenvector $\\lambda$ and a\ncorresponding eigenvector $\\vv$ as \\define{eigenpair}.\n\\end{Definition}\n\n\\begin{Definition}{eigenvalue-algebraic}\n  An \\define{eigenvalue} of a matrix $\\mata\\in \\C^{n\\times n}$ is a root of the characteristic polynomial $\\chi(\\lambda) = \\det(\\mata-\\lambda\\id)$.\n  \n  The \\define{algebraic multiplicity} of an eigenvalue is the multiplicity of the corresponding root of the characteristic polynomial.\n\\end{Definition}\n\n\\begin{Lemma}{eigenvalue-equivalent}\n  The two definitions of an eigenvalue are consistent.\n\\end{Lemma}\n\n\\begin{Theorem}{eigenvalue-count}\n  Every matrix in $\\C^{n\\times n}$ has at most $n$ eigenvalues. The algebraic multiplicities of all eigenvalues add up to $n$.\n\\end{Theorem}\n\n\\begin{proof}\n  The ``at most'' follows from the fact that a polynomial contains\n  linear factors $x-\\lambda_i$ for each of its roots\n  $\\lambda_i$. Thus, if the characteristic polynomial has $k$ roots it\n  has at least degree $k$. On the other hand, the characteristic\n  polynomial has degree $n$, such that $k\\le n$.\n\n  The second statement is due to the fact that every polynomial over\n  $\\C$ is a product of linear factors.\n\\end{proof}\n\n\\begin{remark}\n  The last theorem is not true in $\\R$, as it is not algebraically\n  closed. Thus, even a real matrix may have complex eigenvalues and\n  eigenvectors. Therefore, all results in this chapter will be on\n  complex matrices, but some simplifications for real matrices will be\n  pointed out.\n\\end{remark}\n\n\\begin{Definition}{eigenvalue-simple}\n  An eigenvalue is \\define{simple}, if its algebraic and geometric multiplicity are one. It is \\define{semi-simple}, if its algebraic and geometric multiplicities are equal.\n\\end{Definition}\n\n\\begin{remark}\n  It is possible to refine the concept of eigenvalues and eigenvectors by distinguishing between right eigenvalues and vectors solving\n  \\begin{gather}\n      \\mata \\vv = \\lambda \\vv,\n  \\end{gather}\n  and left eigenvalues and vectors solving\n  \\begin{gather}\n    \\vu \\mata = \\lambda \\vu,\n  \\end{gather}\n  where $\\vu$ is now a row vector. By taking the transpose of this equation\\footnote{Here, we refer to the real transpose obtained by simply exchanging indices, not the complex conjugate transpose.},\n  \\begin{gather}\n    \\label{eq:evp:1}\n    \\mata^T \\vu^T = \\lambda \\vu^T,\n  \\end{gather}\n  we see that $\\vu$ is a left eigenvector of $\\mata$ if and only if\n  $\\vu^T$ is a right eigenvector of $\\mata^T$.\n\\end{remark}\n\n\\begin{Lemma}{eigenvalues-conjugate}\n  Every eigenvalue $\\lambda$ of $\\mata\\in\\C^{n\\times n}$ is also an eigenvalue of $\\mata^T$.\n\\end{Lemma}\n\n\\begin{proof}\n  The determinant does not change when the matrix is transposed, therefore\n  \\begin{gather}\n    \\chi(\\mata^T)\n    = \\det(\\mata^T-\\lambda \\id)\n    = \\det(\\mata-\\lambda \\id)\n    = \\chi(\\mata).\n  \\end{gather}\n  Thus, the eigenvalues of $\\mata$ and of $\\mata^T$ coincide.\n\\end{proof}\n\n\\subsection{Normal and Hermitian matrices}\n\n\\begin{Definition}{normal-Hermitian}\n  A matrix $\\mata\\in\\C^{n\\times n}$ is called \\define{normal} if there holds\n  \\begin{gather}\n      A^*A = AA^*.\n  \\end{gather}\n  It is called \\define{Hermitian} or \\define{complex symmetric}, if there holds\n  \\begin{gather}\n      A=A^*.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{Hermitian-eigenvalues-real}\n  All eigenvalues of a Hermitian matrix are real.\n\\end{Lemma}\n\n\\begin{Theorem*}{Hermitian-diagonalizable}{Spectral theorem for Hermitian matrices}\n  A Hermitian matrix $\\mata\\in\\C^{n\\times n}$ is diagonalizable with\n  an orthogonal basis of eigenvectors and real eigenvalues. That is,\n  there is a real, diagonal matrix $\\matlambda$ and a unitary matrix\n  $\\matq$ such that\n  \\begin{gather}\n    \\mata = \\matq^T \\matlambda\\matq.\n  \\end{gather}\n\\end{Theorem*}\n\n%\\begin{proof}\n%\\end{proof}\n\n\\begin{Corollary}{symmetric-diagonalizable}\n  A symmetric matrix $\\mata\\in\\R^{n\\times n}$ is diagonalizable with\n  an orthogonal basis of eigenvectors and real eigenvalues.\n\\end{Corollary}\n\n\\begin{Theorem*}{normal-diagonalizable}{Spectral theorem for normal matrices}\n  A matrix $\\mata\\in\\C^{n\\times n}$ is normal if and only if it is diagonalizable by a unitary matrix.\n  \n  It is normal if and only if there exists an orthonormal basis of eigenvectors.\n\\end{Theorem*}\n\n\\begin{proof}\n  \n\\end{proof}\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "110c906fc73886eba7b36f4cc542c7728f0383f2", "size": 5505, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nla/def-evp.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nla/def-evp.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "nla/def-evp.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 34.40625, "max_line_length": 199, "alphanum_fraction": 0.7198910082, "num_tokens": 1616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8705972768020107, "lm_q1q2_score": 0.6622203868185194}}
{"text": "\\lab{Mayavi}{Mayavi}\n\n\\section*{3-D Plotting with Mayavi} % =========================================\n\nAlthough Matplotlib is capable of creating 3-D plots, Mayavi\\footnote{If Mayavi is not installed on your machine, run \\li{conda install mayavi} from the command line. See Appendix \\ref{updateinstall} for more info.} does it much faster and with better visuals.\nHere we introduce methods for plotting space curves, scatter plots, and surfaces in 3-D.\nThe \\li{mlab} submodule within the \\li{mayavi} package contains the functions for creating these plots.\n% We will use Mayavi for all 3-D plots in these labs. % O RLY?\n\n\\begin{warn}\nMayavi must be imported before Matplotlib.\n\\begin{lstlisting}\nfrom mayavi import mlab\nfrom matplotlib import pyplot as plt\n\\end{lstlisting}\n\\end{warn}\n\n\\begin{comment}\n\\begin{info} % Installation note. Make into a footnote?\nIf you do not have the \\li{Mayavi} package installed on your system, you may download it by running the following commands from the command line:\n\\begin{lstlisting}\n$ conda install conda               # Download the most recent installer.\n$ conda install anaconda            # Update all packages.\n$ conda install mayavi              # Installs mayavi.\n\\end{lstlisting}\n\n% For more information regarding installing Python packages, see Appendix \\ref{updateinstall}.\n\\end{info}\n\n\\begin{table} % Mayavi plotting functions. Probably should put this back in.\n\\begin{center}\n\\begin{tabular}\n{|c|l|}\n\\hline\nFunction & Description \\\\\n\\hline\n\\li{barchart} & Produces 3D histogram-like plots\\\\\n\\li{contour3d} & Plots level surfaces of functions of three variables\\\\\n\\li{flow} & Creates a trajectory of particles following the flow of a vector field\\\\\n\\li{imshow} & Use a colormap to view a 2D array as an image\\\\\n\\li{mesh} & Plot a surface using \\li{(x,y,z)} coordinates supplied as three 2D arrays\\\\\n\\li{plot3d} & Draws lines between points\\\\\n\\li{points3d} & Plots glyphs (like points) at the coordinates supplied\\\\\n\\li{quiver3d} & Generate 3D vector fields\\\\\n\\li{surf} & Plot a surface with a 2D array as elevation data\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Some plotting functions in \\li{mlab}.}\n\\label{table:mlab_functions}\n\\end{table}\n\\end{comment}\n\n\\subsection*{Lines} % ---------------------------------------------------------\n\nThe function \\li{mlab.plot3d()} is the 3-D Mayavi equivalent for Matplotlib's \\li{plt.plot()}.\nBecause the plot is 3-D, we must provide $x$, $y$, and $z$ coordinates, each contained in 1-D arrays of the same length.\nThe points \\li{(x[i], y[i], z[i])} are graphed in $\\mathbb{R}^3$ and connected with straight lines.\n\nConsider the following curve, parametrized by time:\n\\begin{align*}\nx(t) &= \\cos(t)(1+\\cos(6t))\\\\\ny(t) &= \\sin(t)(1+\\sin(6t)\\\\\nz(t) &= \\sin\\left(\\frac{6}{11}t\\right)\n\\end{align*}\nThe following code plots the curve over the time domain $t \\in [0,2\\pi]$.\nThe resulting plot is shown in Figure \\ref{fig:plot3d}.\n\n\\begin{lstlisting}\n>>> from mayavi import mlab\n\n# Calculate the coordinates of a curve parametrized by time.\n>>> t = np.linspace(0, 2*np.pi, 100)\n>>> x = np.cos(t) * (1 + np.cos(t*6))\n>>> y = np.sin(t) * (1 + np.cos(t*6))\n>>> z = np.sin(t*6/11.)\n\n# Plot and show the figure.\n>>> mlab.plot3d(x, y, z)\n>>> mlab.show()\n\\end{lstlisting}\n\n\\begin{figure} % Mayavi line and point plots.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{plot3d.png}\n    \\caption{A 3-D curve generated by \\li{mlab.plot3d()}.}\n    \\label{fig:plot3d}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{points3d.png}\n    \\caption{A 3-D scatter plot generated by \\li{mlab.points3d()}.}\n    \\label{fig:points3d}\n\\end{subfigure}\n\\end{figure}\n\n\\subsection*{Points} % --------------------------------------------------------\n\nThe function \\li{mlab.points3d()} is the 3-D Mayavi equivalent for Matplotlib's \\li{plt.scatter()}.\nEach point is plotted, but not connected with lines.\nIn the code below, the optional input array \\li{s} defines a scalar for each point that modifies the color and size of the point.\nThe output is in Figure \\ref{fig:points3d}.\n\n\\begin{lstlisting}\n>>> t = np.linspace(0, 4*np.pi, 30)\n>>> x = np.sin(2*t)\n>>> y = np.cos(t)\n>>> z = np.cos(2*t)\n>>> s = 2 + np.sin(t)\n\n# Adjust the keyword argument 'scale_factor' so all points are visible.\n>>> mlab.points3d(x, y, z, s, scale_factor=.15)\n>>> mlab.show()\n\\end{lstlisting}\n\n\\subsection*{Surfaces} % ------------------------------------------------------\n\nThe function \\li{mlab.surf()} renders a 3-D surface.\nBecause the surface is over a 2-D domain, we create a coordinate grid with \\li{np.mgrid()} (similar to \\li{np.meshgrid()}).\nThis function uses the slicing syntax \\li{[start:stop:step]}, similar to \\li{range()} and \\li{np.arange()}, but is accessed with brackets instead of parentheses.\n\nThe following code produces the hyperbolic paraboloid $f(x,y) = \\frac{x^2}{4} - \\frac{y^2}{4}$ over the domain $[-4,4]\\times[-4,4]$.\nThe result is displayed in Figure \\ref{fig:surf_example}.\n\n\\begin{lstlisting}\n>>> X, Y = np.mgrid[-4:4:.025, -4:4:.025]\n>>> Z = (X**2)/4. - (Y**2)/4.\n>>> mlab.surf(X, Y, Z, colormap='RdYlGn')\n>>> mlab.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{mesh_example.png}\n\\caption{Sample output of \\li{mlab.surf()}.}\n\\label{fig:surf_example}\n\\end{figure}\n\nLike Matplotlib, Mayavi supports various color schemes, either as a solid color or with a varying colormap.\nFor example, the plot in Figure \\ref{fig:surf_example} uses the colormap \\li{'RdYlGn'}.\nFor a list of all colormaps in Mayavi, see \\url{http://docs.enthought.com/mayavi/mayavi/mlab_changing_object_looks.html}.\n\n% TODO: More exercises with Mayavi!!! Don't have to be too hard either...\n\\begin{problem}\nPlot the function $z = \\frac{1}{10}\\sin(10(x^2+y^2))$ on $[-1,1] \\times [-1,1]$ using Mayavi.\n\\end{problem}\n", "meta": {"hexsha": "fad9ed9ec39b0d2dd847dce780802398cf40fab7", "size": 5929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Introduction/PlottingIntro/mayavi_/Mayavi.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": "Introduction/PlottingIntro/mayavi_/Mayavi.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": "Introduction/PlottingIntro/mayavi_/Mayavi.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.7919463087, "max_line_length": 260, "alphanum_fraction": 0.6837578006, "num_tokens": 1758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.6622203697095006}}
{"text": "\\section{Introduction}\n\nThe key to convolutional neural networks (CNNs) lies in the way they employ convolution as a local and shift-invariant operation on Euclidean spaces, e.g.\\ $\\RR$ for audio or $\\RR^2$ for images.\nRecently, the concept of CNNs has been extended to more general spaces to exploit different structures that may underlie the data:\nThis includes spherical convolutions for rotationally invariant data~\\cite{cohen2018sphericalcnn,esteves2018sphericalcnn,defferrard2020deepsphere}, more general convolutions on homogeneous spaces~\\cite{cohen2016groupnn,kondor2018groupnn,worrall2017harmonicnn}, or convolutions on graphs~\\cite{bruna2014graphnn,defferrard2016convolutional}.\n\nGraph neural networks (GNNs) have proven to be an effective tool that can take into account irregular graphs to better learn interactions in the data~\\cite{bronstein2017geometric,wu2020survey}.\nAlthough graphs are useful in describing complex systems of irregular relations in a variety of settings, they are intrinsically limited to modeling pairwise relationships. The advance of topological methods in machine learning~\\cite{Gabrielsson2020topological, Hofer2019LearningRO, rieck2018neural}, and the earlier establishment of \\emph{topological data analysis (TDA)}~\\cite{carlsson2008,chazal2017,edelsbrunner2010computational,ghrist2008barcodes} as a field in its own right, have confirmed the usefulness of viewing data as topological spaces in general, or in particular as simplicial complexes. The latter can be thought of as a higher-dimensional analog of graphs~\\cite{moore2012,patania2017}. We here take the view that structure is encoded in \\emph{simplicial complexes}, and that these represent $n$-fold interactions. In this setting, we present \\emph{simplicial neural networks (SNNs)}, a neural network framework that take into account locality of data living over a simplicial complex in the same way a GNN does for graphs or a conventional CNN does for grids.\n\nHigher-order relational learning methods, of which hypergraph neural networks~\\cite{feng2018hypergraphs} and motif-based GNNs~\\cite{monti2018motif} are examples, have already proven useful in some applications, e.g.\\ protein interactions~\\cite{ze2020graph}. However the mathematical theory underneath the notion of convolution in these approaches does not have clear connections with the global topological structure of the space in question. This leads us to believe that our method, motivated by Hodge--de Rham theory, is far better suited for situations where topological structure is relevant, such as perhaps in the processing of data that exists naturally as vector fields or data that is sensitive to the space's global structure.\n", "meta": {"hexsha": "dbda21aa7c1937565e8330f38d561c88d8e98124", "size": 2702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "introduction.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": "introduction.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": "introduction.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": 245.6363636364, "max_line_length": 1077, "alphanum_fraction": 0.8293856403, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6621862073292932}}
{"text": "\\chapter{Bernoulli-Euler Beam equation}\\label{Bernoulli-Euler Beam equation}\n\n\nAssumptions used to derive the Bernoulli-Euler beam equation are (Complete derivation in \\cite{craig2006fundamentals}):\n\\begin{enumerate}\n\t\\item Beam is bending in a plane, in this case in the y-direction, where the x-direction is along the length of the beam.\n\t\\item The  neutral axis undergoes no deformation in the longitudinal direction.\n\t\\item Cross sections remain plane and perpendicular to the nuetral axis.\n\t\\item The material is linear-elastic.\n\t\\item Stresses in the y and z direction are negligible compared to those in the x direction.\n\t\\item Rotary inertial effects are not considered.\n\t\\item Mass density is constant at each cross section, so that each mass center is coincident with the centroid of that section.\n\\end{enumerate}\nUsing kinematics and assumptions 2 \\& 3, the strain in the x direction may be related to the curvature of the beam, $\\mu(x,t)$, and the distance from the neutral axis by\n\\begin{equation} \\label{eq:curvature}\n\\epsilon=-\\dfrac{y}{\\mu}\n\\end{equation}\nthen, with assumption 4 \\& 7 the relation from curvature to moment is\n\\begin{equation} \\label{eq:curv_moment}\nM(x,t)=\\dfrac{EI}{\\mu}\n\\end{equation}\n\\begin{figure}\n\t\\centering\n\t\\def\\svgwidth{300pt}\n\t\\import{figures/}{BeamFBD.pdf_tex}\n\t\\caption{Free body diagram of a beam section in planar bending.}\n\t\\label{fig:BeamFBD}\n\\end{figure}\nwhere $ E $, Young's modulus, and $ I $, area moment of inertia are constant in cross sections. By using Newton's laws and the free body diagram of a single beam element, see Figure \\ref{fig:BeamFBD}, the equations of motion are summarized as:\n\\begin{equation} \\label{eq:Newton}\n\\sum{F_y}=\\Delta m \\ddot{v} \\quad \\textrm{\\&} \\quad \\sum{M_G}=0\n\\end{equation}\nMoment equation is represented as moments summarized at the center of mass, $ G $. The right hand side of moment equation of EOM \\eqref{eq:Newton} is know to be null due to assumption 6. Applying Newton's equations \\eqref{eq:Newton} to the FBD of Figure \\ref{fig:BeamFBD} results in the force equation\n\\begin{equation} \\label{eq:force_EOM}\nF(x,t)-F(x+\\Delta x,t)=\\rho A\\Delta x \\frac{\\partial^2 v}{\\partial t^2}\n\\end{equation}\nand moment equation\n\\begin{equation} \\label{eq:moment_EOM}\n-M(x,t) + M(x+\\Delta x,t) + F(x,t)\\left( \\frac{-\\Delta x}{2}\\right)  + \\left[-F(x+\\Delta x,t)\\right] \\left(\\frac{\\Delta x}{2}\\right) = 0\n\\end{equation}\nTaking the limit of equations \\eqref{eq:force_EOM} \\& \\eqref{eq:moment_EOM} as $ \\Delta x \\rightarrow 0 $ results in equations \\eqref{eq:force_EOM_partial} \\& \\eqref{eq:moment_EOM_partial} respectively.\n\\begin{equation} \\label{eq:force_EOM_partial}\n\\frac{\\partial F}{\\partial x}=-\\rho A \\frac{\\partial^2 v}{\\partial t^2}\n\\end{equation} \n\\begin{equation} \\label{eq:moment_EOM_partial}\n\\frac{\\partial M}{\\partial x} - F=0\n\\end{equation}\nAssuming the beam slope, $ \\frac{\\partial v}{\\partial x} $, remains relatively small, then linearized curvature of the beam is inversely related to $ \\frac{\\partial^2 v}{\\partial x^2} $. Substituting this linearized curvature in \\eqref{eq:curv_moment} produces\n\\begin{equation} \\label{eq:moment_curvature_partial}\nM(x,t)=EI\\frac{\\partial^2 v}{\\partial x^2}\n\\end{equation}\nUsing linearized moment equation \\eqref{eq:moment_curvature_partial}, combined with \\eqref{eq:force_EOM_partial} \\&  \\eqref{eq:moment_EOM_partial} lends the Euler beam equation\n\\begin{equation} \\label{eq:euler_beam_equation}\n\\frac{\\partial^2}{\\partial x^2} \\left(EI\\frac{\\partial^2 v}{\\partial x^2}\\right) = -\\rho A\\frac{\\partial^2 v}{\\partial t^2}\n\\end{equation}\nThis is the governing differential equation for transverse motion of a slender beam. This equation is not suitable for an application involving lengths that are not much greater than the width of the beam \\cite{genta2007dynamics}.", "meta": {"hexsha": "b46c1d9e7728606620a7d7f86ffb7d13e48e18a5", "size": 3802, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/Bernoulli-Euler.tex", "max_stars_repo_name": "cameron1320/Cameron", "max_stars_repo_head_hexsha": "276144ab299ab00f102f3f3cc0869261a13e0059", "max_stars_repo_licenses": ["MIT"], "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/Bernoulli-Euler.tex", "max_issues_repo_name": "cameron1320/Cameron", "max_issues_repo_head_hexsha": "276144ab299ab00f102f3f3cc0869261a13e0059", "max_issues_repo_licenses": ["MIT"], "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/Bernoulli-Euler.tex", "max_forks_repo_name": "cameron1320/Cameron", "max_forks_repo_head_hexsha": "276144ab299ab00f102f3f3cc0869261a13e0059", "max_forks_repo_licenses": ["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.8928571429, "max_line_length": 301, "alphanum_fraction": 0.7535507628, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.662163989147289}}
{"text": "\\documentclass{article}\n\n\\usepackage{style/conference}\n\\usepackage{opensans}\n\\usepackage{graphicx}\n\\usepackage{biblatex}\n\\usepackage{fontawesome}\n\\usepackage[hidelinks]{hyperref}\n\n\\addbibresource{references.bib}\n\\input{style/math_commands.tex}\n\n\\title{Winged Horses with a Deep Convolutional Generative Adversarial Network}\n\n\\begin{document}\n\\maketitle\n\\begin{abstract}\n    This paper proposes using a deep convolutional generative adversarial network (DCGAN) to generate images that look like a Pegasus. We give an overview of the underpinning mathematical theory behind GANs, display the architecture that was applied for the task, suited for use with the CIFAR-10 dataset, and describe and explain our pre-processing and implementation steps. The best result obtained is shown, a Pegasus with a dark body colour, alongside the unique batch, and limitations of the approach as well as improvements unaccomplished due to time constraints are discussed.\n\\end{abstract}\n\n\\section{Methodology}\n\\subsection{Underpinning mathematical theory}\nThe method is to train a deep convolutional generative adversarial network (DCGAN) \\cite{article}, by having two networks, $D$ and $G$, play the following two-player minimax game with value function $V(D, G)$: \n\\begin{equation}\n    \\underset{G}{\\text{min}} \\ \\underset{D}{\\text{max}} \\ V(D,G) = \\mathbb{E}_{x\\sim p_{data}(x)}\\big[logD(x)\\big] + \\mathbb{E}_{z\\sim p_{z}(z)}\\big[log(1-D(G(z)))\\big].\n\\end{equation}\nThe discriminator network, $D$, discriminates between real and fake images. $D$ takes as input an image, $x$, and outputs the scalar probability, $D(x)$, that $x$ came from training data (real) rather than the generator (fake). \n\nThe generator network, $G$, generates fake images. $G$ takes as input a latent space vector, $z$, sampled from a standard normal distribution, $p_z$, and outputs the mapped vector, $D(z)$, in data space (e.g. a space of dimension $3 \\times 32 \\times 32$, which corresponds to the number of channels, height, and width of an image). \n\nGANs proceed by simultaneously training both $G$ and $D$. We train $D$ to maximise $logD(x)$, the probability of $D$ assigning the correct label to both real and fake images. At the same time, we train $G$ to minimise $log(1-D(G(z)))$, the probability of $D$ assigning the correct label to a fake image. Alternatively, we can train $G$ to maximise $logD(G(z))$, the probability of $D$ assigning the incorrect label to a fake image (i.e. making a mistake), which results in the same dynamics of $G$ and $D$. We decide to train $G$ with the latter objective function, since it is supposed to provide much stronger gradients early in learning \\cite{NIPS2014_5ca3e9b1}.\n\nThere exists a unique solution (global optimum) to the minimax game. This is achieved when $G$'s estimate of the training data distribution, $p_g$, matches exactly the true training data distribution, $p_{data}$. When $p_g = p_{data}$, the fake images $G$ generates (by sampling from $p_g$) are indistinguishable from the real images (sampled from $p_{data}$), so $D(x)$ equals $\\frac{1}{2}$ for all $x$, since the discriminator can do no better than guess whether $x$ is real or fake.\n\n\\subsection{Architecture}\nAn architectural diagram of the method is included in Figure \\ref{fig:architecture}. More detailed architectural diagrams of the generator and discriminator networks are also included, in Figure \\ref{fig:generator} and Figure \\ref{fig:discriminator} respectively. Figures \\ref{fig:generator} and \\ref{fig:discriminator} were made using the online tool `\\textit{NN-SVG}' \\footnote{https://github.com/alexlenail/NN-SVG}.\n\n\\begin{figure}[h]\n    \\begin{center}\n        \\includegraphics[width=0.75\\textwidth]{figures/architecture.pdf}\n    \\end{center}\n    \\caption{Method architectural diagram. Both generator and discriminator networks process data with a batch size of 64. The image data used to train the discriminator is a manually identified subset of the CIFAR-10 dataset. The motivation and method for doing this is explained in Section \\ref{implementation}.}\n    \\label{fig:architecture}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\begin{center}\n        \\includegraphics[width=0.75\\textwidth]{figures/generator.png}\n    \\end{center}\n    \\caption{Generator architectural diagram. Transformations happen from left to right.}\n    \\label{fig:generator}\n\\end{figure}\n\nThe generator architecture consists of four layers. The first layer takes as input a $100 \\times 1 \\times 1$ vector of noise (random numbers) sampled from the standard normal distribution, and consists of a convolutional transpose layer, with a $4 \\times 4$ kernel, stride 1, and 0 padding, paired with a batch normalisation layer and ReLU activation function. The second and third layers are like the first, except with stride 2 and 1 padding. The fourth and final layer consists of a convolutional transpose layer, with a $4 \\times 4$ kernel, stride 2, and 1 padding, with $tanh$ activation function, and outputs a $3 \\times 32 \\times 32$ image.  \n\n\\begin{figure}[h]\n    \\begin{center}\n        \\includegraphics[width=0.75\\textwidth]{figures/discriminator.png}\n    \\end{center}\n    \\caption{Discriminator architectural diagram. Transformations happen from right to left.}\n    \\label{fig:discriminator}\n\\end{figure}\n\nThe discriminator architecture also consists of four layers. The first layer takes as input a $3 \\times 32 \\times 32$ image, and consists of a convolutional transpose layer, with a $4 \\times 4$ kernel, stride 2, and 1 padding, with Leaky ReLU activation function. The second and third layers are like the first, each paired with an additional batch normalisation layer. The fourth and final layer consists of a convolutional transpose layer, with a $4 \\times 4$ kernel, stride 1, and 0 padding, with Sigmoid activation function, and outputs a probability. \n\n\\subsection{Implementation} \\label{implementation}\nOur goal was to create unique and diverse images of winged horses that all looked like a Pegasus. We chose to use the CIFAR-10 dataset to train our DCGAN model.\n\nIn order to create an image that looked like a Pegasus, we had to combine a horse's body with a bird's wings. The first step would be to identify good examples of images that exhibited these features clearly. Therefore, we manually identified birds and horses using the annotated class labels available for the CIFAR-10 images. However, upon inspecting the subset, it was noted that the required features were not often displayed clearly: not all horse images showed the horse's body --- instead, showing just the head --- and not all bird images showed birds with their wings outstretched --- instead, showing their beak or neck. (See Appendix \\ref{appendix:A}.)\n\nTo get around this issue, we trained a convolutional neural network classifier by Chris Willcocks\\footnote{https://colab.research.google.com/gist/cwkx/3a6eba039aa9f68d0b9d37a02216d385/convnet.ipynb} for 20 epochs, and used it to choose our model training data. By selecting only horse images that the classifier predicted correctly and with over 80\\% confidence, it was almost guaranteed that the resulting horse images would be of the horse's entire body. Similarly, by selecting only bird images that the classifier misclassified as airplanes with over 80\\% confidence, the resulting bird images would be of birds in mid-flight with outstretched wings. (See Appendix \\ref{appendix:B}.) \n\nFrom this, we made 10 batches of bird images and 10 batches of horse images, with a batch size of 64. Using a weighted random sampler, we trained the DCGAN on this data, and varied the number of epochs the model trained for (from 100 to 1000), as well as the probability of the discriminator training on horse data versus bird data (from odds of 1:1 to 1:20). Our best results were when the odds of the discriminator being given a batch of horses versus a batch of birds to train on was 1:5.\n\n\\section{Results}\nThe generated images are low resolution, but they are not blurry since there are clear-defined edges which outline the objects in them. The objects have realistic shapes because one can easily identify the body of a horse and distinguish between its features, including the torso, head, legs, and, in some cases, tail. The objects in them also have some texture, in particular where the shading highlights the mane and musculature. Although there is some noise, the generated images look real enough to classify as horse-like. \n\nThe images are not that different to their nearest neighbours in the dataset, indicating that the network has learned well the data distribution of horse images. Although the objects in the generated images all hold the same side-view pose, there is diversity between the samples within the batch of 64 provided, in the orientation of pose (left-facing and right-facing), colour (various shades of brown, black, and white), as well as stance (standing and moving). Unfortunately, few clearly identifiable winged horses were made --- the closest were horses with humps instead of wings. There is definitely mode collapse, since we observed the generator rotate through outputting horse-like objects against a green, grassy backdrop and outputting bird-like objects against a blue, cloudless backdrop. (See Appendix \\ref{appendix:C}.) \n\nThe best batch of images looks like this:\n\\begin{center}\n    \\includegraphics[width=0.5\\textwidth]{figures/best-batch.png}\n\\end{center}\n\nFrom this batch, the most Pegasus-like image is:\n\\begin{center}\n    \\includegraphics[width=0.075\\textwidth]{figures/best-pegasus.png}\n\\end{center}\n\n\\section{Limitations}\nIt's very difficult to see anything that looks like a Pegasus. This was anticipated since GANs are notoriously difficult to train due to lacking convergence, having diminishing gradients, and being susceptible to mode collapse. We demonstrate this by plotting the running average of generator and discriminator loss over the previous 100 iterations during a training run, shown below:\n\\begin{center}\n    \\includegraphics[width=0.6\\textwidth]{figures/avgloss.png}\n\\end{center}\n\nIn the future, mode collapse in the GAN could be reduced by lowering the Lipschitz constant for the discriminator function, as was achieve by Wasserstein GANs \\cite{arjovsky2017wasserstein} or by spectral normalisation \\cite{DBLP:journals/corr/abs-1802-05957}, which normalises the weights for each layer using the spectral norm $\\sigma(\\mathbf{W}$). Furthermore the diversity and quantity of training data could have been improved by incorporating data from the STL-10 dataset. Training with STL-10 at the full 96x96 pixels would also have improved issues regarding resolution and realism. Regrettably, these steps could not be accomplished due to the time constraints.\n\n\\section*{Bonuses}\nThis submission has a total bonus of -8 marks (a penalty), as it used an adversarial training method, is trained only on CIFAR-10, and the Pegasus has a dark body colour.\n\n\\appendix\n\\section{Images with the `horse' and `bird' labels} \\label{appendix:A}\n\\begin{center}\n    \\includegraphics[width=0.5\\textwidth]{figures/birds.png}\n\\end{center}\n\\begin{center}\n    \\includegraphics[width=0.5\\textwidth]{figures/horses.png}\n\\end{center}\n\n\\section{Images filtered by the classifier} \\label{appendix:B}\n\\begin{center}\n    \\includegraphics[width=1\\textwidth]{figures/c-birds.png}\n\\end{center}\n\\begin{center}\n    \\includegraphics[width=1\\textwidth]{figures/c-horses.png}\n\\end{center}\n\n\\section{Demonstrating mode collapse} \\label{appendix:C}\n\\begin{center}\n    \\includegraphics[width=0.5\\textwidth]{figures/best-batch-0.png}\n\\end{center}\n\\begin{center}\n    \\includegraphics[width=0.5\\textwidth]{figures/best-batch-2.png}\n\\end{center}\n\n% you can have an unlimited number of references (they can go on the 5th page and span many additional pages without any penalty)\n\\printbibliography\n\\end{document}", "meta": {"hexsha": "e55816d664f4b1dc92de017063686560692c2906", "size": 11836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Scientific Paper/pegasus-paper.tex", "max_stars_repo_name": "matthew-chapman/deep-learning", "max_stars_repo_head_hexsha": "f17c04de40b17581bb4179181669c8ae71497e81", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Scientific Paper/pegasus-paper.tex", "max_issues_repo_name": "matthew-chapman/deep-learning", "max_issues_repo_head_hexsha": "f17c04de40b17581bb4179181669c8ae71497e81", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Scientific Paper/pegasus-paper.tex", "max_forks_repo_name": "matthew-chapman/deep-learning", "max_forks_repo_head_hexsha": "f17c04de40b17581bb4179181669c8ae71497e81", "max_forks_repo_licenses": ["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.46875, "max_line_length": 833, "alphanum_fraction": 0.7784724569, "num_tokens": 2903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.6621639735418382}}
{"text": "\\documentclass{article}\n\\usepackage{amssymb}\n\\begin{document}\n\\section{Filters}\nSource: Daniel Ch. von Grueningen, \"Digitale Signalverarbeitung\", Carl Hanser Verlag 2014, page 251.\\\\\n\nApparently, the filter coefficients can be calculted like so\n\\begin{eqnarray*}\nh_{lowpass}[n]&=& \\frac{\\Omega_u}{\\pi}sinc \\left(\\frac{n\\Omega_u}{pi}\\right)\\\\\nh_{highpass}[n]&=&-\\frac{\\Omega_l}{\\pi}sinc \\left(\\frac{n\\Omega_l}{pi}\\right) \\\\\nh_{bandpass}[n]&=& \\frac{\\Omega_u}{\\pi}sinc \\left(\\frac{n\\Omega_u}{pi}\\right)-\\frac{\\Omega_l}{\\pi}sinc \\left(\\frac{n\\Omega_l}{\\pi}\\right){pi}\\\\\nh_{bandstop}[n]&=& \\frac{\\Omega_l}{\\pi}sinc \\left(\\frac{n\\Omega_l}{pi}\\right)-\\frac{\\Omega_u}{\\pi}sinc \\left(\\frac{n\\Omega_u}{\\pi}\\right){pi}\\\\\n\\end{eqnarray*}\nWith\n\\begin{eqnarray*}\nh_{lowpass}[0]&=&\\frac{\\Omega_u}{\\pi}\\\\\nh_{highpass}[0]&=&1-\\frac{\\Omega_u}{\\pi}\\\\\nh_{bandpass}[0]&=&\\frac{\\Omega_u-\\Omega_l}{\\pi}\\\\\nh_{bandstop}[0]&=&1-\\frac{\\Omega_u-\\Omega_l}{\\pi}\\\\\n\\end{eqnarray*}\n\\section{Windows}\n\\begin{tabular}{l|c}\nHamming&$w_{Hamm}[n]=\\left\\{\\begin{array}{l@{:}l}c\\cdot\\left( 0.54+0.46\\cos\\left(\\frac{2\\pi n}{N+1}\\right)\\right)&|n|\\leqslant N/2\\\\0&otherwise\\\\\\end{array}\\right.$\\\\\\hline  %% }\n\\end{tabular}\n\\end{document}\n\n", "meta": {"hexsha": "fdd7d69a239b9c7053db481e6cc72c5babef78c5", "size": 1199, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "experimental_code/filter/filter.tex", "max_stars_repo_name": "dettus/dettusSDR", "max_stars_repo_head_hexsha": "066a96ab7becdd612bab04e33ea0840234a8a6a8", "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": "experimental_code/filter/filter.tex", "max_issues_repo_name": "dettus/dettusSDR", "max_issues_repo_head_hexsha": "066a96ab7becdd612bab04e33ea0840234a8a6a8", "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": "experimental_code/filter/filter.tex", "max_forks_repo_name": "dettus/dettusSDR", "max_forks_repo_head_hexsha": "066a96ab7becdd612bab04e33ea0840234a8a6a8", "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.4074074074, "max_line_length": 178, "alphanum_fraction": 0.6713928274, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6621639699208189}}
{"text": "\\section{Matrix Element Analysis Technique} \n\n\\subsection{Introduction}\n\\label{me_intro}\nThe matrix element analysis uses leading order matrix elements to separate single top quark events from W+jets and $\\ttbar$ background events. The matrix element analysis calculates a probability for an event to be a signal top event, either s-channel or t-channel, and a probability for one of several W+jets backgrounds. This probability is defined in equation ~\\ref{prob}.\n\n\\begin{equation}\n\\label{prob}\nP(\\vec{x}) = \\frac{1}{\\sigma} \\sum_{i,j} \\int f_{i}(x_{1}, Q^{2})dx_{1}\n\\times \nf_{j}(x_{2}, Q^{2})dx_{2} \\times \\pderiv{\\sigma_{hs,ij}(\\vec{y})}{\\vec{y}} \\times W(\\vec{x},\\vec{y})d\\vec{y}\n\\end{equation}\n\nwhere $f(x_{i},Q^{2})$ is the parton distribution function for parton i,  $\\pderiv{\\sigma_{hs,ij}(\\vec{y})}{\\vec{y}}$ is the differential cross section for the hard scatter interaction, and $W(\\vec{x},\\vec{y})$ is the probability that final state $\\vec{y}$ is reconstructed as $\\vec{x}$ in the detector, and finally, $\\sigma$ is an overall normalization constant defined as the integral of the differential cross section over the entire detector phase space, $d\\vec{x}$ as shown in equation ~\\ref{prob2}.\n\\begin{equation}\n\\label{prob2}\n\\sigma = \\sum_{i,j} \\int f_{i}(x_{1}, Q^{2})dx_{1}\n\\times \nf_{j}(x_{2}, Q^{2})dx_{2} \\times \\pderiv{\\sigma_{hs,ij}(\\vec{y})}{\\vec{y}} \\times W(\\vec{x},\\vec{y})d\\vec{y}d\\vec{x}\n\\end{equation}\n\nThis analysis uses CTEQ 6.1 LO parton distribution functions accessed via\nLHAPDF C++ wrapper~\\footnote{http://hepforge.cedar.ac.uk/lhapdf/}. The matrix elements are calculated using the MadGraph leading order\nmatrix element generator.\n\n\\subsection{Jet-Parton Assignment}\nThe event probabilities calculated in section ~\\ref{me_intro} assume a particle assignment of a jet to a parton in the final state. In practice, this assignment is not known and we must sum over all possible assignments to ensure the correct one is chosen.\nFor two jet events, the event probability is then re-written as a sum over assignment possibilities as shown in equation ~\\ref{assign}\n\n\\begin{eqnarray}\n\\label{assign}\n\\nonumber\nP(\\ell, \\nu, \\vec{\\rm{jets}}) = \\alpha_{1 \\rightarrow 1;2 \\rightarrow 2} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{1}, j_{2} \\rightarrow p_{2}) + \\\\\n\\alpha_{1 \\rightarrow 2; 2 \\rightarrow 1} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{2}, j_{2} \\rightarrow p_{1})\n\\end{eqnarray}\n\nwhere the coefficients, $\\alpha$, are free parameters that depend on the jet-parton assignment probability. Determination of these parameters is described in appendix ~\\ref{jpassign}. For three jet events, the event probability is defined as\n\n\\begin{eqnarray}\n\\label{assign}\n\\nonumber\nP(\\ell, \\nu, \\vec{\\rm{jets}}) = \n\\alpha_{1 \\rightarrow 1;2 \\rightarrow 2; 3 \\rightarrow 3} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{1}, j_{2} \\rightarrow p_{2}, j_{3} \\rightarrow p_{3}) + \\\\\n\\nonumber\n\\alpha_{1 \\rightarrow 1;2 \\rightarrow 3; 3 \\rightarrow 2} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{1}, j_{2} \\rightarrow p_{3}, j_{3} \\rightarrow p_{2}) + \\\\\n\\nonumber\n\\alpha_{1 \\rightarrow 2;2 \\rightarrow 1; 3 \\rightarrow 3} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{2}, j_{2} \\rightarrow p_{1}, j_{3} \\rightarrow p_{3}) + \\\\\n\\nonumber\n\\alpha_{1 \\rightarrow 2;2 \\rightarrow 3; 3 \\rightarrow 1} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{2}, j_{2} \\rightarrow p_{3}, j_{3} \\rightarrow p_{1}) + \\\\\n\\nonumber\n\\alpha_{1 \\rightarrow 3;2 \\rightarrow 2; 3 \\rightarrow 1} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{3}, j_{2} \\rightarrow p_{2}, j_{3} \\rightarrow p_{1}) + \\\\\n\\alpha_{1 \\rightarrow 3;2 \\rightarrow 1; 3 \\rightarrow 2} \\times P(\\ell, \\nu, \\rm{j}_{1} \\rightarrow p_{3}, j_{2} \\rightarrow p_{1}, j_{3} \\rightarrow p_{2})\n\\end{eqnarray}\n\n\\subsection{Matrix Element Analysis Output}\nThe matrix element analysis is named so because the differential cross section for the hard scatter interaction is proportional to the leading order matrix element as shown in equation ~\\ref{me}\n\n\\begin{equation}\n\\label{me}\nd\\sigma_{hs} = \\frac{(2\\pi)^4}{4} \\frac{{|\\cal M|}^{2}}{\\sqrt{(q_{1}q_{2})^2 - m_{1}^2\nm_{2}^2}} d\\Phi_{n}(y)\n\\end{equation}\n\nFor this analysis, we consider four probabilities for two jet events and and three probabilities for three jet events. For two jet events events, we calculate the probability for s-channel single top ($u\\bar{d}$ $\\rightarrow$ $t\\bar{b}$), t-channel single top ($ub$ $\\rightarrow$ $td$), Wbb production ($u\\bar{d}$ $\\rightarrow$ $Wb\\bar{b}$), and Wcg production ($sg$ $\\rightarrow$ $W\\bar{c}g$). The leading order diagrams for these channels are shown in figure ~\\ref{2jets}.\n\n\\vspace{0.1in}\n\\begin{figure}[!h!tbp]\n\\begin{center}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/tb.eps}\n}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/tq.eps}\n}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/wbb.eps}\n}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/wcg.eps}\n}\n\\end{center}\n\\vspace{-0.1in}\n\\caption[2jets]{The leading order matrix elements used for event probability calculation for events with two jets. (a) $u\\bar{d}$ $\\rightarrow$ $t\\bar{b}$, (b) $ub$ $\\rightarrow$ $td$, (c) $u\\bar{d}$ $\\rightarrow$ $Wb\\bar{b}$, (d) $sg$ $\\rightarrow$ $W\\bar{c}g$}\n\\label{2jets}\n\\end{figure}\n\nFor events with three jets, we use three matrix elements, s-channel with gluon radiation ($u\\bar{d}$ $\\rightarrow$ $t\\bar{b}g$), t-channel with associated b quark ($ug$ $\\rightarrow$ $t\\bar{b}d$), and Wbbg ($u\\bar{d}$ $\\rightarrow$ $Wb\\bar{b}g$). The leading order Feynman diagrams are shown in figure ~\\ref{3jets}.\n\n\\vspace{0.1in}\n\\begin{figure}[!h!tbp]\n\\begin{center}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/tbg.eps}\n}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/tqb.eps}\n}\n\\subfigure[]{\n\t\\includegraphics[width=0.22\\textwidth]{figures/wbbg.eps}\n}\n\\end{center}\n\\vspace{-0.1in}\n\\caption[3jets]{The leading order matrix elements used for event probability calculation for events with two jets.  (a) $u\\bar{d}$ $\\rightarrow$ $t\\bar{b}g$, (b) $ug$ $\\rightarrow$ $t\\bar{b}d$, (c) $u\\bar{d}$ $\\rightarrow$ $Wb\\bar{b}g$}\n\\label{3jets}\n\\end{figure}\n\nAfter calculating event probabilities we combine them into a discriminant output variable, D, defined in equation ~\\ref{disc}\n\n\\begin{equation}\n\\label{disc}\nD(\\vec{x}) = \\frac{P_{\\rm{signal}}(\\vec{x})}{P_{\\rm{signal}}(\\vec{x}) + P_{\\rm{background}}(\\vec{x})}\n\\end{equation}\n\nwhere $c_{wbb}$ and $c_{wcg}$ are, in principle, the relative background fractions for each background in the data; however, these background fractions are optimizable for the analysis. \n\nFor events with two jets the discriminant for either s-channel or t-channel as signal is defined as\n\n\\begin{equation}\nD(\\vec{x})_{\\rm{s|t}} = \\frac{P_{\\rm{s|t}}(\\vec{x})}{P_{\\rm{st}}(\\vec{x}) + c_{wbb}P_{\\rm{wbb}}(\\vec{x}) + c_{wcg}P_{\\rm{wcg}}(\\vec{x})}\n\\end{equation}\n\nand events with three jets the discriminant for s-channel and t-channel is defined as\n\n\\begin{equation}\nD(\\vec{x})_{\\rm{s|t}} = \\frac{P_{\\rm{s|t}}(\\vec{x})}{P_{\\rm{st}}(\\vec{x}) + P_{\\rm{wbbg}}(\\vec{x})}\n\\end{equation}\n\n\n\n\n", "meta": {"hexsha": "6027acb029d4e5dc3bfbd0f95541a90586d6c0f5", "size": 7142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "STnote/MatrixElement.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": "STnote/MatrixElement.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": "STnote/MatrixElement.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": 54.5190839695, "max_line_length": 504, "alphanum_fraction": 0.7016241949, "num_tokens": 2363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932333, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6621175836665187}}
{"text": "\\section{The long exact sequence of homotopy groups}\n\\sectionmark{The long exact sequence}\n\n\\subsection{The long exact sequence}\n\n\\begin{defn}\nA fiber sequence $F\\hookrightarrow E \\twoheadrightarrow B$ consists of:\n\\begin{enumerate}\n\\item Pointed types $F$, $E$, and $B$, with base points $x_0$, $y_0$, and $b_0$ respectively, \n\\item Base point preserving maps $i:F\\to_\\ast E$ and $p:E\\to_\\ast B$, with $\\alpha:i(x_0)=y_0$ and $\\beta:p(y_0)=b_0$,\n\\item A pointed homotopy $H:\\mathsf{const}_{b_0}\\htpy_\\ast p\\circ_\\ast i$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nF \\arrow[r,\"i\"] \\arrow[d] & E \\arrow[d,\"p\"] \\\\\n\\unit \\arrow[r,swap,\"\\mathsf{const}_{b_0}\"] & B,\n\\end{tikzcd}\n\\end{equation*}\ncommutes and is a pullback square.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{lem}\nAny fiber sequence $F\\hookrightarrow E\\twoheadrightarrow B$ induces a sequence of pointed maps\n\\begin{equation*}\n\\begin{tikzcd}\n\\loopspace{F} \\arrow[r,\"\\loopspace{i}\"] & \\loopspace{E} \\arrow[r,\"\\loopspace{p}\"] & \\loopspace{B} \\arrow[r,\"\\partial\"] & F \\arrow[r,\"i\"] & E \\arrow[r,\"p\"] & B,\n\\end{tikzcd}\n\\end{equation*}\nin which every two consecutive maps form a fiber sequence.\n\\end{lem}\n\n\\begin{proof}\nBy taking pullback squares repeatedly, we obtain the diagram\n\\begin{equation*}\n\\begin{gathered}[b]\n\\begin{tikzcd}[column sep=large]\n\\loopspace{F} \\arrow[d,swap,\"\\loopspace{i}\"] \\arrow[r] & \\unit \\arrow[d,\"\\mathsf{const}_{\\refl{b_0}}\"] \\\\\n\\loopspace{E} \\arrow[r,\"\\loopspace{p}\"] \\arrow[d] & \\loopspace{B} \\arrow[r] \\arrow[d,swap,\"\\partial\"] & \\unit \\arrow[d,\"\\mathsf{const}_{y_0}\"] \\\\\n\\unit \\arrow[r,swap,\"\\mathsf{const}_{x_0}\"] & F \\arrow[r,\"i\"] \\arrow[d] & E \\arrow[d,\"p\"] \\\\\n& \\unit \\arrow[r,swap,\"\\mathsf{const}_{b_0}\"] & B.\n\\end{tikzcd}\\\\[-\\dp\\strutbox]\n\\end{gathered}\\qedhere\n\\end{equation*}\n\\end{proof}\n\n\\begin{defn}\nWe say that a consecutive pair of pointed maps between pointed sets\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"f\"] & B \\arrow[r,\"g\"] & C\n\\end{tikzcd}\n\\end{equation*}\nis \\define{exact} at $B$ if we have\n\\begin{equation*}\n\\Big(\\exis{a:A}f(a)=b\\Big)\\leftrightarrow (g(b)=c)\n\\end{equation*}\nfor any $b:B$. \n\\end{defn}\n\n\\begin{rmk}\nIf a pair of consecutive pointed maps between pointed sets\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"f\"] & B \\arrow[r,\"g\"] & C\n\\end{tikzcd}\n\\end{equation*}\nis exact at $B$, it directly that $\\im(f)=\\fib{g}{c}$. Indeed, such a pair of pointed maps is exact at $B$ if and only if there is an equivalence $e:\\im(f)\\eqvsym \\fib{g}{c}$ such that the triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\n\\im(f) \\arrow[dr] \\arrow[rr,\"e\"] & & \\fib{g}{c} \\arrow[dl] \\\\\n& B\n\\end{tikzcd}\n\\end{equation*}\ncommutes. In other words, $\\im(f)$ and $\\fib{g}{c}$ are equal \\emph{as subsets of $B$}.\n\\end{rmk}\n\n\\begin{lem}\nSuppose $F\\hookrightarrow E \\twoheadrightarrow B$ is a fiber sequence. Then the sequence\n\\begin{equation*}\n\\begin{tikzcd}\n\\trunc{0}{F} \\arrow[r,\"\\trunc{0}{i}\"] & \\trunc{0}{E} \\arrow[r,\"\\trunc{0}{p}\"] & \\trunc{0}{B}\n\\end{tikzcd}\n\\end{equation*}\nis exact at $\\trunc{0}{E}$. \n\\end{lem}\n\n\\begin{proof}\nTo show that the image $\\im\\trunc{0}{i}$ is the fiber $\\fib{\\trunc{0}{p}}{\\tproj{0}{b_0}}$, it suffices to construct a fiberwise equivalence\n\\begin{equation*}\n\\prd{x:\\trunc{0}{E}} \\trunc{-1}{\\fib{\\trunc{0}{i}}{x}} \\eqvsym \\trunc{0}{p}(x)=\\tproj{0}{b_0}.\n\\end{equation*}\nBy the universal property of $0$-truncation it suffices to show that\n\\begin{equation*}\n\\prd{x:E} \\trunc{-1}{\\fib{\\trunc{0}{i}}{\\tproj{0}{x}}} \\eqvsym \\trunc{0}{p}(\\tproj{0}{x})=\\tproj{0}{b_0}.\n\\end{equation*}\nFirst we note that \n\\begin{align*}\n\\trunc{0}{p}(\\tproj{0}{x})=\\tproj{0}{b_0} & \\eqvsym \\tproj{0}{p(x)} = \\tproj{0}{b_0} \\\\\n& \\eqvsym \\trunc{-1}{p(x)=b_0}.\n\\end{align*}\nNext, we note that\n\\begin{align*}\n\\fib{\\trunc{0}{i}}{\\tproj{0}{x}} & \\eqvsym \\sm{y:\\trunc{0}{F}}\\trunc{0}{i}(y)=\\tproj{0}{x} \\\\\n& \\eqvsym \\trunc{0}{\\sm{y:F}\\trunc{0}{i}(\\tproj{0}{y})=\\tproj{0}{x}} \\\\\n& \\eqvsym \\trunc{0}{\\sm{y:F}\\tproj{0}{i(y)}=\\tproj{0}{x}} \\\\\n& \\eqvsym \\trunc{0}{\\sm{y:F}\\trunc{-1}{i(y)=x}}.\n\\end{align*}\nTherefore it follows that\n\\begin{align*}\n\\trunc{-1}{\\fib{\\trunc{0}{i}}{\\tproj{0}{x}}} & \\eqvsym \\trunc{-1}{\\sm{y:F}\\trunc{-1}{i(y)=x}} \\\\\n& \\eqvsym \\trunc{-1}{\\sm{y:F}i(y)=x} \\\\\n\\end{align*}\nNow it suffices to show that $\\eqv{\\big(\\sm{y:F}i(y)=x\\big)}{p(x)=b_0}$. This follows by the pasting lemma of pullbacks\n\\begin{equation*}\n\\begin{tikzcd}\n(p(x)=b_0) \\arrow[r] \\arrow[d] & \\unit \\arrow[d] \\\\\nF \\arrow[r] \\arrow[d] & E \\arrow[d] \\\\\n\\unit \\arrow[r] & B\n\\end{tikzcd}\n\\end{equation*}\n\\end{proof}\n\n\\begin{thm}\nAny fiber sequence $F\\hookrightarrow E\\twoheadrightarrow B$ induces a long exact sequence on homotopy groups\n\\begin{equation*}\n\\begin{tikzcd}\n& & \\cdots \\arrow[out=355,in=175,dll] \\\\\n\\pi_n(F) \\arrow[r,\"\\pi_n(i)\"] & \\pi_n(E) \\arrow[r,\"\\pi_n(p)\"] & \\pi_n(B) \\arrow[out=355,in=175,dll,densely dotted] \\\\\n\\pi_1(F) \\arrow[r,\"\\pi_1(i)\"] & \\pi_1(E) \\arrow[r,\"\\pi_1(p)\"] & \\pi_1(B) \\arrow[out=355,in=175,dll] \\\\\n\\pi_0(F) \\arrow[r,\"\\pi_0(i)\"] & \\pi_0(E) \\arrow[r,\"\\pi_0(p)\"] & \\pi_0(B)\n\\end{tikzcd}\n\\end{equation*}\n\\end{thm}\n\n\\subsection{The Hopf fibration}\nOur goal in this section is to construct the Hopf fibration, i.e.~a fiber sequence\n\\begin{equation*}\n\\sphere{1}\\hookrightarrow\\sphere{3}\\twoheadrightarrow\\sphere{2}.\n\\end{equation*}\nThis fiber sequence involves the complex multiplication of the unit sphere in the complex number, which is a circle. Viewing the circle as a subspace of the complex numbers, we write $1$ for the base point of the circle.\n\n\\begin{defn}\nWe define the \\define{complex multiplication} operation\n\\begin{equation*}\n\\mu_{\\mathbb{C}}:\\sphere{1}\\to(\\sphere{1}\\to\\sphere{1}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nBy the universal property of the circle, it is equivalent to define\n\\begin{align*}\n\\mu_{\\mathbb{C}}(1) & : \\sphere{1}\\to\\sphere{1} \\\\\n\\ap{\\mu_{\\mathbb{C}}}{\\lloop} & : \\mu_{\\mathbb{C}}(1)=\\mu_{\\mathbb{C}}(1). \n\\end{align*}\nThe function $\\mu_{\\mathbb{C}}(1)$ is multiplication by $1$, which is the identity function. The type of $\\ap{\\mu_{\\mathbb{C}}}{\\lloop}$ is equivalent to the type of homotopies\n\\begin{equation*}\n\\idfunc[\\sphere{1}] \\htpy \\idfunc[\\sphere{1}]. \n\\end{equation*}\nWe construct this homotopy by induction on $\\sphere{1}$. Therefore it suffices to construct\n\\begin{align*}\np & : 1=1 \\\\\nq & : \\mathsf{tr}_{L}(\\lloop,p)=p\n\\end{align*}\n\\end{constr}\n\n\\begin{lem}\nThe complex multiplication operation $\\mu_{\\mathbb{C}}$ on the circle satisfies the unit laws\n\\begin{align*}\n\\mathsf{left\\usc{}unit}_{\\mathbb{C}}(x) & : \\mu_{\\mathbb{C}}(1,x) = x \\\\\n\\mathsf{right\\usc{}unit}_{\\mathbb{C}}(x) & : \\mu_{\\mathbb{C}}(x,1) = x \\\\\n\\mathsf{coh\\usc{}unit}_{\\mathbb{C}} & : \\mathsf{left\\usc{}unit}_{\\mathbb{C}}(1)=\\mathsf{right\\usc{}unit}_{\\mathbb{C}}(1),\n\\end{align*}\nand the functions $\\mu_{\\mathbb{C}}(x,\\blank)$ and $\\mu_{\\mathbb{C}}(\\blank,y)$ are equivalences for each $x:\\sphere{1}$ and $y:\\sphere{1}$, respectively.\n\\end{lem}\n\n\\begin{lem}\nBoth commuting squares in the diagram\n\\begin{equation*}\n\\begin{tikzcd}\n\\sphere{1} \\arrow[d] & \\sphere{1}\\times\\sphere{1} \\arrow[d,swap,\"\\mu_{\\mathbb{C}}\"] \\arrow[l,swap,\"\\proj 1\"] \\arrow[r,\"\\proj 2\"] & \\sphere{1} \\arrow[d] \\\\\n\\unit & \\sphere{1} \\arrow[l] \\arrow[r] & \\unit\n\\end{tikzcd}\n\\end{equation*}\nare pullback squares.\n\\end{lem}\n\n\\begin{cor}\nThere is a fiber sequence\n\\begin{equation*}\n\\sphere{1}\\hookrightarrow \\join{\\sphere{1}}{\\sphere{1}} \\twoheadrightarrow \\sphere{2}.\n\\end{equation*}\n\\end{cor}\n\n\\begin{lem}\nThe join operation is associative\n\\end{lem}\n\n\\begin{proof}\n\\begin{equation*}\n\\begin{tikzcd}\nA & A\\times C \\arrow[l] \\arrow[r] & A\\times C \\\\\nA\\times B \\arrow[u] \\arrow[d] & A\\times B \\times C \\arrow[r] \\arrow[d] \\arrow[l] \\arrow[u] & A\\times C \\arrow[u] \\arrow[d] \\\\\nB & B\\times C \\arrow[l] \\arrow[r] & C\n\\end{tikzcd}\n\\end{equation*}\n\\end{proof}\n\n\\begin{cor}\nThere is an equivalence $\\eqv{\\join{\\sphere{1}}{\\sphere{1}}}{\\sphere{3}}$.\n\\end{cor}\n\n\\begin{thm}\nThere is a fiber sequence $\\sphere{1}\\hookrightarrow\\sphere{3}\\twoheadrightarrow\\sphere{2}$. \n\\end{thm}\n\n\\begin{lem}\nSuppose $f:G\\to H$ is a group homomorphism, such that the sequence\n\\begin{equation*}\n\\begin{tikzcd}\n0 \\arrow[r] & G \\arrow[r,\"f\"] & H \\arrow[r] & 0\n\\end{tikzcd}\n\\end{equation*}\nis exact at $G$ and $H$, where we write $0$ for the trivial group consisting of just the unit element. Then $f$ is a group isomorphism.\n\\end{lem}\n\n\\begin{cor}\nWe have $\\pi_2(\\sphere{2})=\\Z$, and for $k>2$ we have $\\pi_k(\\sphere{2})=\\pi_k(\\sphere{3})$.\n\\end{cor}\n\n\n\\begin{exercises}\n\\item Give the $0$-sphere $\\sphere{0}$ the structure of an H-space.\n\\item For any pointed type $A$, give $\\loopspace{A}$ the structure of an H-space.\n\\item Show that the type of (small) fiber sequences is equivalent to the type of quadruples $(B,P,b_0,x_0)$, consisting of\n\\begin{align*}\nB & : \\UU \\\\\nP & : B \\to \\UU \\\\\nb_0 & : B \\\\\nx_0 & : P(b_0).\n\\end{align*}\n\\end{exercises}\n", "meta": {"hexsha": "75e2b389dbc8b2d9e511d6db0cbae7b7ba139fcf", "size": 8836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/les.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/les.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/les.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": 36.5123966942, "max_line_length": 220, "alphanum_fraction": 0.6599139882, "num_tokens": 3451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7718434873426303, "lm_q1q2_score": 0.6620627310995979}}
{"text": "%---------------------------Edge Ratio-----------------------------\n\\section{Edge Ratio}\n\nThe edge ratio of a quadrilateral is the ratio of its longest and shortest edge lengths:\n\\[\n  q = \\frac{L_{\\max}}{L_{\\min}}.\n\\]\n\n\\quadmetrictable{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$}%                                      Square\n{\\cite{pebay:04}}%                          Citation\n{v\\_quad\\_edge\\_ratio}%                     Verdict function name\n\n", "meta": {"hexsha": "7e8f8697b7341327fdd45ef3bcc9cbde59e60a77", "size": 647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadEdgeRatio.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/QuadEdgeRatio.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/QuadEdgeRatio.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": 35.9444444444, "max_line_length": 88, "alphanum_fraction": 0.4049459042, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6620627243758415}}
{"text": "\\documentclass[12pt]{article} \\usepackage{amsmath,amssymb,amsthm}\n\\usepackage[margin=1in]{geometry} \\title{A Naive Bayes Primer / Naive Bayes for\n  Text Categorization} \\date{November 14, 2016} \\author{Nelson Liu\\\\\n  nfliu@uw.edu \\and Jonathan Lee\\\\ jlee27@uw.edu}\n\\newtheorem{theorem}{Theorem}[section] \\newtheorem*{remark}{Remark}\n\n\\begin{document}\n\\maketitle\n\\section{Motivating Problem}\nConsider the following (hypothetical) problem: \n\\newline \n\n\\textit{In our dataset, Hillary Clinton has tweeted 4190 times and Donald Trump\n  has tweeted 4246 times. 30\\% of Clinton tweets contain the word \"climate\",\n  while only 15\\% of Trump tweets contain the word \"climate\". What is the\n  probability that a tweet is written by Trump or Clinton, given that it\n  contains the word \"climate\"?} \n\\newline\n\n% Let $S$ be the event that a given email is spam, and let $V$ be the event that the email contains the word \"viagra\". We would like to know $\\mathbb{P}(S|V)$, the probability that an email is spam given that it contains \"viagra\". A straightforward application of Bayes' theorem tells us that\n\nWe like to assume that our dataset is fairly accurate sample of the population,\nso we'll say that the numbers of tweets we have for each person is an accurate\nrepresentation of their tweeting frequency. Let $H$ be the event that a tweet is\nwritten by Hillary Clinton, $T$ be the event that a tweet is written by Donald\nTrump. Thus, we can estimate the probability that an arbitrary tweet is written\nby Clinton or by Trump from our dataset.\n\n$$\\mathbb{P}(H) = \\frac{\\text{\\# Hillary tweets}}{\\text{\\# total tweets}} =\n\\frac{4190}{4190+4246} \\approx 0.497$$\n$$\\mathbb{P}(T) = \\frac{\\text{\\# Trump tweets}}{\\text{\\# total tweets}} =\n\\frac{4246}{4190+4246} \\approx 0.503$$\n\nLet $C$ be the event that the tweet contains the word \"climate\". We want to\ncalculate $\\mathbb{P}(H|C)$, the probability that a tweet is written by Clinton\ngiven that we know that it contains the word \"climate\". We can calculate this\nprobability (called the posterior probability) by applying Bayes' Theorem\n(presented in the next section, so don't worry if you don't know what this is).\n\n\\begin{equation}\n\\begin{split}\n  \\mathbb{P}(H|C) &= \\frac{\\mathbb{P}(C|H)\\mathbb{P}(H)}{\\mathbb{P}(C|H)\\mathbb{P}(H) + \\mathbb{P}(C|T)\\mathbb{P}(T)}\\\\\n  &= \\frac{0.3 \\times 0.497}{0.3 \\times 0.497 + 0.15 \\times 0.503}\\\\\n  &\\approx 0.66\n\\end{split}\n\\end{equation}\n\nIt's pretty simple to calculate this probability when we're only examining one\nword. We would like to extend this sort of thinking to classify entire tweets as\neither being written by Hillary Clinton or Donald Trump by examining every word\nin the tweet. This is where naive bayes classifiers come in.\n\n\\section{Derivation of Bayes' Theorem}\nThis section seeks to give the reader a theoretical understanding of Bayes'\nTheorem. It's difficult to understand how Bayes' theorem works without knowing\nwhat conditional probability is, so we'll begin by giving a recap on that.\n\n\\subsection{Conditional Probability: A Recap}\nGiven two events $A$ and $B$, the probability of $A$ happening given that we\nknow that $B$ happens (denoted $\\mathbb{P}(A|B)$) is defined by:\n\n$$\\mathbb{P}(A|B) = \\frac{\\mathbb{P}(AB)}{\\mathbb{P}(B)}$$\n$\\mathbb{P}(A|B)$ is read ``the probability of $A$ given $B$''. This equation\nmakes intuitive sense; since you are trying to calculate the probability that\n$A$ happens and you know that $B$ has happened, you put the probability that $B$\nhappens in the denominator (this is your ``sample space'') and the probability\nthat $A$ and $B$ happen in the numerator. Dividing these thus yields the\nprobability that $A$ occurs given that $B$ occurs.\n\n\\begin{remark}\nNotation may shift occasionally; note that $\\mathbb{P}(AB) = \\mathbb{P}(A,B)$\n\\end{remark}\n\n\\subsection{Derivation}\nBefore we can derive Bayes' theorem, we need a preliminary result, the law of\ntotal probability. We present it without proof for the sake of brevity, the the\nproof can be found online quite easily.\n\\begin{theorem}[Law of Total Probability]\n  Let $A_1, \\dots, A_n$ represent events that span the entire sample space (that\n  is, the possible outcome events are $A_1, \\dots, A_n$). For any event B, \n  $$\\mathbb{P}(B) = \\sum \\limits_{i=1}^{k} \\mathbb{P}(B|A_i)\\mathbb{P}(A_i)$$\n\\end{theorem}\n\nIn our derivation of Bayes' Theorem, let's continue considering the events\n$A_1, \\dots, A_n$ where $\\mathbb{P}(A_i) > 0$ for each $i$. With the formula for\nconditional probability, we rearrange the terms a bit and see that:\n$$\\mathbb{P}(A_i B) = \\mathbb{P}(B) \\times \\mathbb{P}(A_i|B)$$\nThis signifies that the probability of $A_i$ and $B$ occurring is the\nprobability of $B$ occurring multiplied by the probability of $A_i$ occurring\ngiven that $B$ occurs.\n\nWe can similarly rearrange this the other way around:\n$$\\mathbb{P}(A_iB) = \\mathbb{P}(A_i) \\times \\mathbb{P}(B|A_i)$$\nThis signifies that the probability of $A_i$ and $B$ occurring is the\nprobability of $A_i$ occurring multiplied by the probability of $B$ occurring\ngiven that $A_i$ occurs, which is also a reasonable thing to say.\n\nBecause the two equations above equal $\\mathbb{P}(A_iB)$, it follows that:\n$$\\mathbb{P}(B) \\times \\mathbb{P}(A_i|B) = \\mathbb{P}(A_i) \\times \\mathbb{P}(B|A_i)$$\n\nNow, by dividing $\\mathbb{P}(B)$ on both sides, we get the ``simple\nformulation'' of Bayes' Theorem:\n$$\\mathbb{P}(A_i|B) = \\frac{\\mathbb{P}(A_i) \\times \\mathbb{P}(B|A_i)}{\\mathbb{P}(B)}$$\nThe simple formulation shows us that the probability of $A$ given $B$ is equal\nto the probability of $A$ happening multiplied by the probability of $B$ given\n$A$, all divided by the probability of $B$. In reality however, the probability\nof $B$ is calculated by applying the aforementioned law of total probability.\nThus, we can apply the law of total probability to the ``simple formulation'' to\nyield the formulation of Bayes' Theorem that is commonly found in literature\n(simply ``Bayes' Theorem'' from here on out).\n\\begin{theorem}[Bayes' Theorem]\n  Let $A_1, \\dots, A_k$ represent the events that span the entire sample space\n  such that $\\mathbb{P}(A_i) > 0$ for each i. If $\\mathbb{P}(B) > 0$ then, for\n  each $i = 1, \\dots, k$,\n  $$\\mathbb{P}(A_i|B) = \\frac{\\mathbb{P}(A_i) \\times \\mathbb{P}(B|A_i)}{\\sum \\limits_{i=1}^{k} \\mathbb{P}(B|A_i)\\mathbb{P}(A_i)}$$\n\\end{theorem}\n\n\\begin{remark}\nWe call $\\mathbb{P}(A_i)$ the \\textbf{prior probability of $A$} and\n$\\mathbb{P}(A_i|B)$ the \\textbf{posterior probability of $A$}.\n\\end{remark}\n\\section{Theory behind Naive Bayes Classifiers}\nLet's represent a tweet as the set of distinct words $(x_1, \\dots, x_n)$\ncontained in the text. We are interested in computing\n\n$$\\mathbb{P}(H|x_1, \\dots, x_n)$$\nwhere $H$ is the event that the tweet is written by Hillary, and $T$ is the\nevent that the tweet is written by Trump. Note that the probability of $T$ is\nequivalent to $H^c$, or the probability that the tweet is not written by Hillary\n(since we're only deciding between two classes, a task called binary\nclassification). By Bayes' theorem, this is equivalent to\n\\begin{equation}\n\\begin{split}\n  \\mathbb{P}(H|x_1, \\dots, x_n) &= \\frac{\\mathbb{P}(H) \\times\n                                  \\mathbb{P}(x_1, \\dots, x_n|H)}{\\mathbb{P}(x_1, \\dots, x_n)}\\\\\n                                &= \\frac{\\mathbb{P}(H)\\mathbb{P}(x_1, \\dots, x_n|H)}{\\mathbb{P}(x_1, \\dots,\n                                  x_n)}\\\\ \n                                &= \\frac{\\mathbb{P}(H)\\mathbb{P}(x_1, \\dots, x_n|H)}{\\mathbb{P}(x_1,\n                                  \\dots, x_n|H)\\mathbb{P}(H)+\\mathbb{P}(x_1, \\dots, x_n|T)\\mathbb{P}(T)}\n\\end{split}\n\\end{equation}\nIgnoring the denominator for a minute, by definition of conditional probability,\n$$\\mathbb{P}(H)\\mathbb{P}(x_1, \\dots, x_n|H) = \\mathbb{P}(x_1, \\dots, x_n, H)$$\n\nTo simplify this equation, we need the chain rule of probability. As a brief\nrecap, the chain rule is a rearrangement of the generalization of conditional\nprobability formula to $n$ terms, and not just $2$. We can get the ``product\nrule'' by rearranging the formula for conditional probability:\n$$\\mathbb{P}(A,B) = \\mathbb{P}(A|B) \\mathbb{P}(B)$$\n\nExtending this for three variables, we can see that:\n$$\\mathbb{P}(A,B,C) = \\mathbb{P}(A|B,C) \\mathbb{P}(B,C) = \\mathbb{P}(A|B,C)\n\\mathbb{P}(B|C) \\mathbb{P}(C)$$\n\nApplying this to $n$ variables leads to the chain rule.\n\\begin{theorem}[The Chain Rule of Probability]\n$$\\mathbb{P}(A_1, A_2, \\dots, A_n) = \\mathbb{P}(A_1| A_2, \\dots,\nA_n)\\mathbb{P}(A_2| A_3, \\dots, A_n) \\dots \\mathbb{P}(A_{n-1}|A_n) \\mathbb{P}(A_n)$$\n\\end{theorem}\n\nApplying the chain rule to decompose the probability equation we had above,\n\\begin{equation}\n\\begin{split}\n  \\mathbb{P}(x_1, \\dots, x_n, H) & = \\mathbb{P}(x_1 | x_2, \\dots, x_n, H) \\mathbb{P}(x_2, \\dots, x_n, H) \\\\\n                                 & = \\mathbb{P}(x_1 | x_2, \\dots, x_n, H) \\mathbb{P}(x_2 | x_3, \\dots, x_n, H) \\mathbb{P}(x_3, \\dots, x_n, H) \\\\\n                                 & = \\dots \\\\\n                                 & = \\mathbb{P}(x_1 | x_2, \\dots, x_n, H) \\mathbb{P}(x_2 | x_3, \\dots, x_n, H) \\dots   \\mathbb{P}(x_{n-1} | x_n, H) \\mathbb{P}(x_n | H) \\mathbb{P}(H) \\\\\n\\end{split}\n\\end{equation}\nThis is a correct formula, but it's not a particularly useful one for us! The\nproblem is that terms like $\\mathbb{P}(x_1 | x_2, \\dots, x_n, H)$ have so many\nconditions, that it's generally not possible to accurately calculate their\nprobability. \\newline\n\nThink about what that term is really trying to calculate, though: what's the\nprobability that the word $x_1$ occurs in a Hillary tweet, given that\n($x_2, \\dots x_n$) also occur? Unless there is another Hillary tweet with all of\nthose words ($x_2, \\dots x_n$) in it that you've already looked at (which is\nunlikely unless you have absurd amounts of data), there's no way to know that\nprobability already. We need to simplify the problem! \\newline\n\nNaive Bayes \"fixes\" this by making the assumption that the words in an tweet\n(and more generally, features in data) are \\textbf{conditionally independent of\n  each other, given that we know whether or not the tweet was written by\n  Hillary}. In other words, it assumes that knowing that an tweet has the word\n\"climate\" in it, doesn't tell us anything about whether it has the word \"change\"\nin it, \\textbf{if we already factor in whether the tweet was written by Hillary\n  or not}. This is why it's called Naive Bayes: it naively assumes independence\nwhere it might not actually (and likely doesn't!) exist. \\newline\n\nThis assumption, of course, is \\textbf{not true} in reality: words often appear\ntogether, and English is not just a random walk through the dictionary. But it's\na useful simplification of the problem that can lead to practical results.\n\\newline\n\nLet's rewrite those chain rule probabilities using the conditional independence\nassumptions.\n\\begin{equation}\n\\begin{split}\n  \\mathbb{P}(x_1, \\dots, x_n, H) & = \\mathbb{P}(x_1 |  H) \\mathbb{P}(x_2 | x_3, \\dots, x_n, H) \\dots   \\mathbb{P}(x_{n-1} | x_n, H) \\mathbb{P}(x_n | H) \\mathbb{P}(H) \\\\\n                                 & \\approx \\mathbb{P}(x_1 | H) \\mathbb{P}(x_2 | H) \\dots   \\mathbb{P}(x_{n-1} | H) \\mathbb{P}(x_n | H) \\mathbb{P}(H) \\\\\n                                 & = \\mathbb{P}(H)\\prod_{i=1}^n \\mathbb{P}(x_i | H)\n\\end{split}\n\\end{equation}\n\nBy a similar argument,\n\n$$\\mathbb{P}(x_1, \\dots, x_n, T) \\approx \\mathbb{P}(T)\\prod_{i=1}^n \\mathbb{P}(x_i | T)$$\nPutting it all together,\n$$\\mathbb{P}(H|x_1, \\dots, x_n) \\approx \\frac{\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H)}{\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H) + \\mathbb{P}(T)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | T)}$$\n\nThus, we can calculate the probability of a tweet being authored by Hillary if\nwe know the underlying probability of tweet being a Hillary-tweet, and the\nprobabilities of seeing a particular word in either a Hillary or Trump tweet!\n\n\\section{How Trump-ish is a word?}\nWe have a way to compute the probability of an tweet being from Hillary Clinton\nor Donald Trump using relatively simple terms, but it's not yet clear how to\ncompute those conditional probabilities. This classifier works by taking a large\nnumber of tweets that have already been hand-labelled as \\textit{Hillary} or\n\\textit{Trump} and uses that data to compute word-Trump (or word-Hillary)\nprobabilities, by counting the frequency of each word. \\newline\n\nImagine we're given a labelled training set of $2000$ Hillary tweets and $3000$\nTrump tweets (so $\\mathbb{P}(H) = 0.4$, and $\\mathbb{P}(T) = 0.6$). We'd like to\ncalculate $\\mathbb{P}(\"woman\"|H)$ and $\\mathbb{P}(\"woman\"|T)$. The easiest thing\nto do would be to count how many Hillary tweets have ``woman'' and divide that by\nthe total number of Hillary tweets (and do the same thing for Trump). So, if\nthere were 216 Hillary tweets with ``woman'' and 12 Trump tweets with ``woman'',\nwe'd say\n$$\\mathbb{P}(\"woman\"|H) = \\frac{216}{2000} \\approx 11\\%$$\n$$\\mathbb{P}(\"woman\"|T) = \\frac{12}{3000} \\approx 0.4\\%$$\n\n\\section{Important Practical / Engineering Considerations}\nWhile the theory is all dandy and fine, there are some problems that we may run\ninto when actually implementing the classifier. We detail a few of them below,\nand how they are solved.\n\\subsection{Smoothing}\nOur theoretical framework and formulation of the solution has the right idea,\nbut there's a small problem that we have yet to address: what if there's a word\n(say, \"Pokemon\") that we've only ever seen before in Trump tweets, and not\nHillary tweets? In that case, $\\mathbb{P}(\"Pokemon\"|H) = 0$, and the entire\nHillary probability will go to zero, because we're multiplying all of the word\nprobabilities together and we've never seen \"Pokemon\" in a Hillary tweet before.\nThus, any tweet that we get that has ``Pokemon'' in it would be classified as a\nTrump tweet for sure! We would like to be robust to words we haven't seen\nbefore, or at least words we've only seen in one setting. \\newline\n\nThe solution is to never let any word probabilities be zero, by smoothing them\nupwards. \\textbf{Instead of starting each word count at 0, start it at 1}. This\nway none of the counts will ever have a numerator of 0. This overestimates the\nword probability, so we need to \\textbf{add 2 to the denominator}. (We add 2\nbecause we're implicitly keeping track of 2 things: the number of tweets that\ncontain that word, and the number that don't. The sum of those two things should\nbe in the denominator, and the 2 accounts for starting both the counters at 1.)\nEssentially, you're hallucinating that you've seen the novel word at least once\nin your train set. \\newline\n\nThe smoothed word probabilities for the previous example are now\n$$\\mathbb{P}(\"woman\"|S) = \\frac{217}{2002} \\approx 11\\%$$\n$$\\mathbb{P}(\"woman\"|H) = \\frac{13}{3002} \\approx 0.43\\%$$\nAnd our estimate for \"Pokemon\" in Hillary tweets would now be $\\frac{1}{2002}$,\ninstead of $0$. \\newline\n\nThis technique is called \\textbf{Laplacian smoothing} and was used in the 18th\ncentury to estimate the probability that the sun will rise tomorrow!\n\n\\subsection{The Naive Bayes Classification algorithm}\n\\begin{enumerate}\n  \\item Iterate over the labelled Hillary tweets, and for each word $w$ seen,\n  count how many of the Hillary tweets contain $w$. Compute\n  $\\mathbb{P}(w | H) = \\frac{|\\text{\\# Hillary tweets containing w}| +\n    1}{|\\text{\\# Hillary Tweets}| + 2}$.\n\\item Compute $\\mathbb{P}(w | T)$ the same way for Trump tweets.\n\\item Compute $\\mathbb{P}(H) = \\frac{|\\text{\\# Hillary tweets}|}{|\\text{\\#\n    Hillary tweets}| + |\\text{\\# Trump tweets}|}$\n\\item $\\mathbb{P}(T) = \\frac{|\\text{\\# Trump tweets}|}{|\\text{\\# Hillary\n    tweets}| + |\\text{\\# Trump tweets}|}$\n\\item Iterate over the unlabelled test tweets:\n\\begin{enumerate}\n  \\item Create a set $(x_1, \\dots, x_n)$ of the distinct words in the tweet.\n  Ignore the words that you haven't seen in the labelled training data.\n\\item Compute\n$$\\mathbb{P}(H|x_1, \\dots, x_n) \\approx \\frac{\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H)}{\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H) + \\mathbb{P}(T)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | T)}$$\n\\item If $\\mathbb{P}(H|x_1, \\dots, x_n) > 0.5$, output \"Hillary\", else output\n\"Trump\"\n\\end{enumerate}\n\\end{enumerate}\n\\subsection{Avoiding floating point underflow}\nMultiplying a bunch of small probabilities together will probably result in\nfloating point underflow, where the numbers will become too small to represent\nand will go to $0$. Instead of calculating\n$$\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H)$$\n(which may underflow), consider computing the logarithm of this,\n$$\\log\\Big({\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H)}\\Big)$$\nwhich can be written equivalently as\n$$\\log(\\mathbb{P}(H))+\\sum\\limits_{i=1}^n \\log(\\mathbb{P}(x_i | H))$$\nWhich will certainly not underflow. Then, realize that if\n$$\\log(\\mathbb{P}(H))+\\sum\\limits_{i=1}^n \\log(\\mathbb{P}(x_i | H)) > \\log(\\mathbb{P}(T))+\\sum\\limits_{i=1}^n \\log(\\mathbb{P}(x_i | T))$$\nthen, because in general $\\log(x) > \\log(y)$ means $x > y$,\n$$\\mathbb{P}(H)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | H) > \\mathbb{P}(T)\\prod\\limits_{i=1}^n \\mathbb{P}(x_i | T)$$\nand therefore\n$$\\mathbb{P}(H|x_1, \\dots, x_n) > 0.5$$\nand thus the tweet should be classified as ``Hillary'' (or as ``Trump'', if the\nsum of the logarithms for ``Trump'' was greater).\n\\end{document}\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "60468b7039ff2cf929663bc2b4d1bd898f3646ef", "size": 17414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-2017.Meetings/05.DIY_naive_bayes/naive_bayes_primer/naive_bayes_primer.tex", "max_stars_repo_name": "NViday/machine_learning_workshop_Winter17", "max_stars_repo_head_hexsha": "834c4abee998b3143cd562ecd240c8054d29ffc6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-07T09:18:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T09:49:35.000Z", "max_issues_repo_path": "2016-2017.Meetings/05.DIY_naive_bayes/naive_bayes_primer/naive_bayes_primer.tex", "max_issues_repo_name": "NViday/machine_learning_workshop_Winter17", "max_issues_repo_head_hexsha": "834c4abee998b3143cd562ecd240c8054d29ffc6", "max_issues_repo_licenses": ["MIT"], "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-2017.Meetings/05.DIY_naive_bayes/naive_bayes_primer/naive_bayes_primer.tex", "max_forks_repo_name": "NViday/machine_learning_workshop_Winter17", "max_forks_repo_head_hexsha": "834c4abee998b3143cd562ecd240c8054d29ffc6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-03-27T11:06:24.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-27T11:06:24.000Z", "avg_line_length": 55.9935691318, "max_line_length": 292, "alphanum_fraction": 0.7008728609, "num_tokens": 5487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.6619779499596402}}
{"text": "\n\\subsection{Cointegration}\n\nIf we have multiple variables, we can explore the order of integration of linear combinations.\n\nIf two series have time trends, a linear combination of them could remove this.\n\n", "meta": {"hexsha": "f8d6e6139cc40c9dbde47e54f5e3f6c33b75d3eb", "size": 206, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticMulti/01-01-cointegration.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/stochasticMulti/01-01-cointegration.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/stochasticMulti/01-01-cointegration.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.75, "max_line_length": 94, "alphanum_fraction": 0.8009708738, "num_tokens": 41, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045877523146, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6619779377177746}}
{"text": "\\section{Lagrange Multipliers}\\label{sec:LagrangeMultipliers}\n\nMany applied max/min problems take the following form:\nwe want to find an extreme value of a function, like $V=xyz$, subject\nto a constraint, like $\\ds1=\\sqrt{x^2+y^2+z^2}$. Often this can be\ndone, as we have, by explicitly combining the equations and then\nfinding critical points. There is another approach that is often\nconvenient, the method of \\dfont{Lagrange multipliers}\\index{Lagrange multipliers}.\n\nIt is somewhat easier to understand two variable problems, so we begin\nwith one as an example. Suppose the perimeter of a rectangle is to be\n100 units. Find the rectangle with largest area. This is a fairly\nstraightforward problem from single variable calculus. We write down\nthe two equations: $A=xy$, $P=100=2x+2y$, solve the second of these\nfor $y$ (or $x$), substitute into the first, and end up with a\none-variable maximization problem. Let's now think of it differently:\nthe equation $A=xy$ defines a surface, and the equation $100=2x+2y$\ndefines a curve (a line, in this case) in the $x$-$y$ plane. If we\ngraph both of these in the three-dimensional coordinate system, we can\nphrase the problem like this: what is the highest point on the surface\nabove the line? The solution we already understand effectively\nproduces the equation of the cross-section of the surface above the\nline and then treats it as a single variable problem. Instead, imagine\nthat we draw the level curves (the contour lines) for the surface in\nthe $x$-$y$ plane, along with the line.\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/lagrange.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{Constraint line with contour plot of the surface $xy$.}\n\\label{fig:lagrange}\n\\end{figure}\n\nImagine that the line represents a hiking trail and the contour lines\nare, as on a topographic map, the lines of constant altitude. How\ncould you estimate, based on the graph, the high (or low) points on\nthe path? As the path crosses contour lines, you know the path must be\nincreasing or decreasing in elevation. At some point you will see the\npath just touch a contour line (tangent to it), and then begin to\ncross contours in the opposite order---that point of tangency must be\na maximum or minimum point. If we can identify all such points, we can\nthen check them to see which gives the maximum and which the minimum\nvalue. As usual, we also need to check boundary points; in this\nproblem, we know that $x$ and $y$ are positive, so we are interested\nin just the portion of the line in the first quadrant, as shown. The\nendpoints of the path, the two points on the axes, are not points of\ntangency, but they are the two places that the function $xy$ is a\nminimum in the first quadrant.\n\nHow can we actually make use of this? At the points of tangency that\nwe seek, the constraint curve (in this case the line) and the level\ncurve have the same slope---their tangent lines are parallel. This also\nmeans that the constraint curve is perpendicular to the gradient\nvector of the function; going a bit further, if we can express the\nconstraint curve itself as a level curve, then we seek the points at\nwhich the two level curves have parallel gradients.\nThe curve $100=2x+2y$ can be thought of as a level curve of the\nfunction $2x+2y$; Figure~\\ref{fig:lagrange two} shows both sets of\nlevel curves on a single graph. We are interested in those points\nwhere two level curves are tangent---but there are many such points,\nin fact an infinite number, as we've only shown a few of the level\ncurves. All along the line $y=x$ are points at which two level curves\nare tangent. While this might seem to be a show-stopper, it is\nnot. \n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/lagrange2.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{Contour plots for $2x+2y$ and $xy$.}\n\\label{fig:lagrange two}\n\\end{figure}\n\nThe gradient of $2x+2y$ is $\\langle 2,2\\rangle$, and the gradient of\n$xy$ is $\\langle y,x\\rangle$. They are parallel when\n$\\langle 2,2\\rangle=\\lambda\\langle y,x\\rangle$, that is, when\n$2=\\lambda y$ and $2=\\lambda x$. We have two equations in three\nunknowns, which typically results in many solutions (as we\nexpected). A third equation will reduce the number of solutions; the\nthird equation is the original constraint, $100=2x+2y$. So we have the\nfollowing system to solve:\n$$2=\\lambda y \\qquad 2=\\lambda x\\qquad 100=2x+2y.$$\nIn the first two equations, $\\lambda$ can't be 0, so we may divide by\nit to get $x=y=2/\\lambda$. Substituting into the third equation we get \n\\begin{align*}\n2{2\\over \\lambda}+2{2\\over \\lambda}&=100\t\\\\\n{8\\over100}&=\\lambda\t\\\\\n\\end{align*}\nso $x=y=25$. Note that we are not really interested in the value of\n$\\lambda$---it is a clever tool, the Lagrange multiplier, introduced\nto solve the problem. In many cases, as here, it is easier to find\n$\\lambda$ than to find everything else without using $\\lambda$.\n\nThe same method works for functions of three variables, except of\ncourse everything is one dimension higher: the function to be\noptimized is a function of three variables and the constraint represents\na surface---for example, the function may represent temperature, and\nwe may be interested in the maximum temperature on some surface, like\na sphere.\nThe points we seek are those at which the constraint\nsurface is tangent to a level surface of the function. Once again, we\nconsider the constraint surface to be a level surface of some\nfunction, and we look for points at which the two gradients are\nparallel, giving us three equations in four unknowns. The constraint\nprovides a fourth equation.\n\n\\begin{example}{Optimization with Constraints}{}\nMaximize the function $xyz$ given the constraint $\\ds\n1=\\sqrt{x^2+y^2+z^2}$.\n\\end{example}\n\\begin{solution}\n%Recall Example~\\ref{exa:box diagonal}: the diagonal of a box is 1, we seek to maximize the volume.\nThe constraint is $\\ds\n1=\\sqrt{x^2+y^2+z^2}$, which is the same as\n$1=x^2+y^2+z^2$. The function to maximize is $xyz$. The two gradient\nvectors are $\\langle 2x,2y,2z\\rangle$ and $\\langle yz,xz,xy\\rangle$,\nso the equations to be solved are\n\\begin{align*}\nyz&=2x\\lambda\t\\\\\nxz&=2y\\lambda\t\\\\\nxy&=2z\\lambda\t\\\\\n1&=x^2+y^2+z^2\t\\\\\n\\end{align*}\nIf $\\lambda=0$ then at least two of $x$, $y$, $z$ must be 0, giving a\nvolume of 0, which will not be the maximum. If we multiply the first\ntwo equations by $x$ and $y$ respectively, we get\n\\begin{align*}\nxyz&=2x^2\\lambda\t\\\\\nxyz&=2y^2\\lambda\t\\\\\n\\end{align*}\nso $2x^2\\lambda=2y^2\\lambda$ or $x^2=y^2$; in the same way we can show\n$x^2=z^2$. Hence the fourth equation becomes\n$1=x^2+x^2+x^2$ or $x=1/\\sqrt3$, and so $x=y=z=1/\\sqrt3$ gives the\nmaximum volume. This is of course the same answer we obtained\npreviously.\n\\end{solution}\n\nAnother possibility is that we have a function of three variables, and\nwe want to find a maximum or minimum value not on a surface but on a\ncurve; often the curve is the intersection of two surfaces, so that we\nreally have two constraint equations, say $g(x,y,z)=c_1$ and\n$h(x,y,z)=c_2$. It turns out that at points on the intersection of the\nsurfaces where $f$ has a maximum or minimum value,\n$$\\nabla f=\\lambda\\nabla g+\\mu \\nabla h.$$\nAs before, this gives us three equations, one for each component of\nthe vectors, but now in five unknowns, $x$, $y$, $z$, $\\lambda$, and\n$\\mu$. Since there are two constraint functions, we have a total of\nfive equations in five unknowns, and so can usually find the solutions\nwe need.\n\n\\begin{example}{Intersection of a Plane with a Cylinder}{}\nThe plane $x+y-z=1$ intersects the cylinder $x^2+y^2=1$ in an\nellipse. Find the points on the ellipse closest to and farthest from\nthe origin.\n\\end{example}\n\\begin{solution}\nWe want the extreme values of $f=\\sqrt{x^2+y^2+z^2}$ subject to the\nconstraints  $g=x^2+y^2=1$ and $h=x+y-z=1$. To simplify the algebra,\nwe may use instead $f=x^2+y^2+z^2$, since this has a maximum or\nminimum value at exactly the points at which $\\sqrt{x^2+y^2+z^2}$ does.\nThe gradients are\n$$\\nabla f =\\langle 2x,2y,2z\\rangle\\qquad\n\\nabla g = \\langle 2x,2y,0\\rangle\\qquad\n\\nabla h = \\langle 1,1,-1\\rangle,$$\nso the equations we need to solve are\n\\begin{align*}\n2x&=\\lambda 2x+\\mu\t\\\\\n2y&=\\lambda 2y+\\mu\t\\\\\n2z&=0-\\mu\t\\\\\n1&=x^2+y^2\t\\\\\n1&=x+y-z.\t\\\\\n\\end{align*}\nSubtracting the first two we get\n$2y-2x=\\lambda(2y-2x)$, so either $\\lambda=1$ or $x=y$. If $\\lambda=1$\nthen $\\mu=0$, so $z=0$ and the last two equations are\n$$1=x^2+y^2\\qquad\\hbox{and}\\qquad 1=x+y.$$\nSolving these gives $x=1$, $y=0$, or $x=0$, $y=1$, so the points of\ninterest are $(1,0,0)$ and $(0,1,0)$, which are both distance 1 from\nthe origin. If $x=y$, the fourth equation is $2x^2=1$, giving \n$x=y=\\pm1/\\sqrt2$, and from the fifth equation we get\n$z=-1\\pm\\sqrt2$. The distance from the origin to \n$(1/\\sqrt2,1/\\sqrt2,-1+\\sqrt2)$ is $\\sqrt{4-2\\sqrt2}\\approx 1.08$ and\nthe distance from the origin to \n$(-1/\\sqrt2,-1/\\sqrt2,-1-\\sqrt2)$ is $\\sqrt{4+2\\sqrt2}\\approx 2.6$.\nThus, the points $(1,0,0)$ and $(0,1,0)$ are closest to the origin and \n$(-1/\\sqrt2,-1/\\sqrt2,-1-\\sqrt2)$ is farthest from the origin.\n%The Java \n%\\expandafter\\url\\expandafter{\\liveurl lagrange_two_constraints.html}%\n%applet \\endurl shows the cylinder, the plane, the four points of\n%interest, and the origin.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:LagrangeMultipliers}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nA six-sided rectangular box is to hold $1/2$ cubic meter;\nwhat shape should the box be to minimize surface area?\n\\begin{sol}\na cube, $\\root 3 \\of {1/2}\\times\\root 3 \\of {1/2}\\times\\root 3 \\of {1/2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe post office will accept packages whose combined length\nand girth are at most 130 inches (girth is the maximum distance around\nthe package perpendicular to the length). What is the largest volume\nthat can be sent in a rectangular box?\n\\begin{sol}\n$65/3\\cdot 65/3\\cdot 130/3=2\\cdot 65^3/27$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe bottom of a rectangular box costs twice as much per unit\narea as the sides and top. Find the shape for a given volume that will\nminimize cost.\n\\begin{sol}\nIt has a square base, and is one and one half times as tall as wide.\nIf the volume is $V$ the dimensions are $\\root 3 \\of {2V/3}\\times\n\\root 3 \\of {2V/3}\\times \\root 3\\of {9V/4}$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUsing Lagrange multipliers, find the shortest\ndistance from the point $(x_0,y_0,z_0)$ to the plane $ax+by+cz=d$.\n\\begin{sol}\n$|ax_0+by_0+cz_0-d|/\\sqrt{a^2+b^2+c^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all points on the surface $xy-z^2+1=0$ that are closest\nto the origin.\n\\begin{sol}\n$(0,0,1)$, $(0,0,-1)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe material for the bottom of an aquarium costs half as\nmuch as the high strength glass for the four sides. Find the shape of\nthe cheapest aquarium that holds a given volume $V$.\n\\begin{sol}\n$\\root 3\\of{4V}\\times\\root 3\\of{4V}\\times\\root 3\\of{V/16}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe plane $x-y+z=2$ intersects the cylinder $x^2+y^2=4$ in an\nellipse. Find the points on the ellipse closest to and farthest from\nthe origin.\n\\begin{sol}\nFarthest: $(-\\sqrt2,\\sqrt2,2+2\\sqrt2)$; closest:\n$(2,0,0)$, $(0,-2,0)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind three positive numbers whose sum is 48 and whose\nproduct is as large as possible.\n\\begin{sol}\n$x=y=z=16$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all points on the plane $x+y+z = 5$ in the first octant at\nwhich $\\ds f(x,y,z) = xy^2z^2$ has a maximum value.\n\\begin{sol}\n$(1,2,2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the points on the surface $x^2 -yz = 5$ that are closest to the\norigin.\n\\begin{sol}\n$\\ds (\\sqrt{5},0,0)$, $\\ds (-\\sqrt{5},0,0)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA manufacturer makes two models of an item, standard and deluxe.  It\ncosts \\$40 to manufacture the standard model and \\$60 for the deluxe.  A\nmarket research firm estimates that if the standard model is priced at $x$\ndollars and the deluxe at $y$ dollars, then the manufacturer will sell\n$500(y-x)$ of the standard items and $45,000+500(x-2y)$ of the deluxe each\nyear.  How should the items be priced to maximize profit?\n\\begin{sol}\nstandard \\$65, deluxe \\$75\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA length of sheet metal is to be made into a\nwater trough by bending up two sides as shown in\nFigure~\\ref{fig:trough two}.  Find $x$ and $\\phi$ so that the\ntrapezoid--shaped cross section has maximum area, when\nthe width of the metal sheet is 27 inches (that is, $2x+y=27$).\n\\begin{sol}\n$x=9$, $\\phi=\\pi/3$\n\\end{sol}\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <1truecm,1truecm>\n\\setplotarea x from 0 to 5, y from -0.5 to 1\n\\plot 0 1 1 0 4 0 5 1 /\n\\put {$x$} [bl] <2pt,2pt> at 0.5 0.5\n\\put {$x$} [br] <-2pt,2pt> at 4.5 0.5\n\\put {$y$} [t] <0pt,-3pt> at 2.5 0\n\\put {$\\phi$} at 4.7 0.35\n\\put {$\\phi$} at 0.3 0.35\n\\circulararc 45 degrees from 4.5 0 center at 4 0\n\\circulararc -45 degrees from 0.5 0 center at 1 0\n\\setdashes\n\\putrule from 4 0 to 5.3 0\n\\putrule from -0.3 0 to 1 0\n\\endpicture}}\n%\\endtexonly\n\\caption{Cross-section of a trough.}\n\\label{fig:trough two}\n\\end{figure}\n\\end{ex}\n\n\\begin{ex}\nFind the maximum and minimum values of $f(x,y,z)=6x+3y+2z$ subject\nto the constraint $\\ds g(x,y,z) = 4x^2+2y^2 + z^2 - 70 = 0$.\n\\begin{sol}\n$35$, $-35$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the maximum and minimum values of $f(x,y)=e^{xy}$ subject\nto the constraint $g(x,y) = x^3+y^3 - 16 = 0$.  \n\\begin{sol}\nmaximum $e^4$, no minimum\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the maximum and minimum values of $\\ds f(x,y) = xy +\n\\sqrt{9-x^2-y^2}$ when $\\ds x^2+y^2 \\leq 9$.\n\\begin{sol}\n$5$, $-9/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind three real numbers whose sum is 9 and the sum of whose squares\nis a small as possible.  \n\\begin{sol}\n$3$, $3$, $3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the dimensions of the closed rectangular box with maximum volume\nthat can be inscribed in the unit sphere.\n\\begin{sol}\na cube of side length $\\ds 2/\\sqrt{3}$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "5152633654d17ca3d5322e7dfa17d1c0d69e4fdf", "size": 14340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-8-lagrange-multipliers.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-8-lagrange-multipliers.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-8-lagrange-multipliers.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.5816326531, "max_line_length": 99, "alphanum_fraction": 0.7207112971, "num_tokens": 4654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.867035758084294, "lm_q1q2_score": 0.6619677237183458}}
{"text": "\\subsection{Categories}\\label{subsec:categories}\n\n\\begin{definition}\\label{def:category}\\mcite[def. 1.1.1]{Leinster2016Basic}\n  A \\term{category} is a \\hyperref[def:quiver]{quiver} \\( \\cat{C} \\) equipped with a \\hyperref[def:partial_function]{partial operation} \\( \\bincirc \\) on the arrows of \\( \\cat{C} \\) and another operation \\( \\id \\) that selects a distinguished arrow for each vertex.\n\n  In tradition regarding \\hyperref[def:concrete_category]{forgetful functors}, we denote the underlying quiver of \\( \\cat{C} \\) by \\( U(\\cat{C}) \\).\n\n  \\begin{thmenum}[series=def:category]\n    \\thmitem{def:category/objects} We call the vertices of the quiver \\term{objects} and denote the set of all objects by \\( \\obj(\\cat{C}) \\). We will often write \\( A \\in \\cat{C} \\) as a shorthand for \\( A \\in \\obj(\\cat{C}) \\).\n\n    \\thmitem{def:category/morphisms} We call the arrows of the quiver \\term{morphisms} or sometimes \\term{maps}. If \\( f \\) is a morphism, we call its head its \\term{domain} \\( \\dom(f) \\) and its tail its \\term{codomain} \\( \\co\\dom(f) \\). We denote a morphism from \\( A \\) to \\( B \\) by \\( f: A \\to B \\) or \\( A \\reloset f \\to B \\).\n\n    We call the set \\( \\cat{C}(A, B) \\) of all morphisms from \\( A \\) to \\( B \\) a \\term{morphism set} or \\term{\\( \\hom \\)-set}. We use the shorthand \\( \\cat{C}(A) \\) for \\( \\cat{C}(A, A) \\). Another established notation is \\( \\op{hom}(A, B) \\) instead of \\( \\cat{C}(A, B) \\).\n\n    Both of these notations highlight that \\( \\cat{C}(A, B) \\), when parameterized by \\( A \\) and \\( B \\), is a \\hyperref[def:functor]{functor}, as discussed in \\fullref{def:hom_functor}.\n\n    \\thmitem{def:category/composition} We require the \\term{composition} \\( \\bincirc \\) of the arrows \\( f \\) and \\( g \\) to be defined only if \\( \\co\\dom(f) = \\dom(g) \\). In this case, we require \\( g \\bincirc f \\) to be a morphism from \\( \\dom(f) \\) to \\( \\co\\dom(g) \\).\n\n    Note how the order of \\( f \\) and \\( g \\) may seem confusing: we write the composition of \\( f: A \\to B \\) and \\( g: B \\to C \\) as \\( g \\bincirc f: A \\to C \\). This is set up so that it matches \\hyperref[def:multi_valued_function/composition]{function composition}. The order may seem different compared to multiplication in \\hyperref[def:group]{groups}, for example, however \\fullref{def:monoid_delooping} shows that this is actually a generalization of multiplication.\n\n    This order of composition is used in \\cite[7]{MacLane1994}, \\cite[def. 1.1.1]{Leinster2016Basic} and \\cite[def. I.3.1]{Aluffi2009}.\n\n    \\thmitem{def:category/identity} We denote the \\term{identity morphism} of an object \\( A \\) by \\( \\id_A \\).\n  \\end{thmenum}\n\n  The definition of a category additionally requires the following conditions to hold:\n  \\begin{thmenum}[resume=def:category]\n    \\thmitem[def:category/C1]{C1} For any morphism \\( f: A \\to B \\), the identities \\( \\id_A \\) and \\( \\id_B \\) must satisfy\n    \\begin{equation}\\label{eq:def:category/C1}\\tag{\\logic{C1}}\n      f \\bincirc \\id_A = \\id_B \\bincirc f = f.\n    \\end{equation}\n\n    \\thmitem[def:category/C2]{C2} Composition must be associative. That is, for each triple of morphism \\( f: A \\to B \\), \\( g: B \\to C \\) and \\( h: C \\to D \\), the following must hold:\n    \\begin{equation}\\label{eq:def:category/C2}\\tag{\\logic{C2}}\n      (h \\bincirc g) \\bincirc f = h \\bincirc (g \\bincirc f).\n    \\end{equation}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:category}\n  Examples of categories include:\n\n  \\begin{itemize}\n    \\item The category \\( \\cat{Set} \\) of \\hyperref[def:large_and_small_sets]{small} \\hyperref[def:set]{sets} and \\hyperref[def:function]{functions} defined in \\fullref{def:category_of_small_sets}.\n\n    \\item The category \\( \\cat{Cat} \\) of small categories defined in \\fullref{def:category_of_small_categories}.\n\n    \\item All the \\hyperref[def:category_of_small_first_order_models]{categories of small first-order models} listed in \\fullref{ex:def:category_of_small_first_order_models}\n\n    \\item The category \\( \\cat{Top} \\) of small \\hyperref[def:topological_space]{topological spaces} and \\hyperref[def:global_continuity]{continuous functions} defined in \\fullref{def:category_of_small_topological_spaces}.\n\n    \\item For every topological space, the fundamental groupoid defined in \\fullref{def:fundamental_groupoid}.\n\n    \\item The category \\( \\cat{Quiv} \\) of small \\hyperref[def:quiver]{quivers} defined in \\fullref{def:category_of_small_quivers}.\n\n    \\item For every quiver, the free category defined in \\fullref{def:quiver_free_category}.\n\n    \\item For every \\hyperref[def:preordered_set]{preordered set}, the induced category defined in \\fullref{thm:order_category_isomorphism}.\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}\\label{def:category_size}\n  As can be seen from \\fullref{ex:def:category}, some of the categories we are working with, like \\( \\cat{Set} \\), contain as objects all \\hyperref[def:large_and_small_sets]{small sets}. As mentioned in \\fullref{def:large_and_small_sets}, the concept of a small set is defined relative to the smallest Grothendieck universe that suits our needs.\n\n  \\Fullref{thm:russels_paradox} demonstrates that the set of all sets easily leads to a paradox, which is the reason we restrict our attention only to sets within some Grothendieck universe. This universe is implicit by default, however we will occasionally need to make it explicit.\n\n  We will say that the category \\( \\cat{C} \\) is \\term{locally \\( \\mscrU \\)-small} if the morphism set \\( \\cat{C}(A, B) \\) is \\( \\mscrU \\)-small for every pair of objects \\( A \\) and \\( B \\). If, in addition, the set \\( \\obj(\\cat{C}) \\) of objects is also \\( \\mscrU \\)-small, we will say that the category \\( \\cat{C} \\) is \\term{\\( \\mscrU \\)-small}. If a category is not \\( \\mscrU \\)-small, we say that it is \\term{\\( \\mscrU \\)-large}.\n\n  In particular, \\term{finite} and \\term{locally finite} categories are ones who are \\( V_\\omega \\)-small and \\( V_\\omega \\)-locally small for the universe of hereditary finite sets \\hyperref[def:universe_of_hereditary_finite_sets]{\\( V_\\omega \\)}. This notion of local finiteness is unrelated to local finiteness of graphs defined in \\fullref{def:hypergraph/degree}.\n\n  Universes are crucial to be able to do a lot of categorical constructions within set theory, most importantly \\( \\mscrU \\)-large \\hyperref[def:functor_category]{functor categories} but also \\hyperref[def:product_category]{product categories} and, as discussed in \\fullref{rem:functor_size}, even the \\hyperref[def:functor]{functors} themselves.\n\n  Note that, even if a category is \\( \\mscrU \\)-small, the category itself as the tuple \\( (Q, \\bincirc, \\id) \\) from \\fullref{def:category} may not be a \\( \\mscrU \\)-small set.\n\n  Also note that, in a locally small category, it is possible for the set of all morphisms to be \\( \\mscrU \\)-large. This is impossible for small categories due to \\ref{def:grothendieck_universe/union}.\n\n  We sometimes skip the prefix \\enquote{\\( \\mscrU \\)-} if it is unimportant, and simply speak of \\enquote{large categories} or \\enquote{locally small categories}.\n\\end{definition}\n\n\\begin{definition}\\label{def:category_of_small_sets}\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:set]{sets} by \\( \\ucat{Set} \\) or, if the universe is clear from the context, simply by \\( \\cat{Set} \\). 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{Set}) \\) is the set of all \\( \\mscrU \\)-small sets, i.e. all members of \\( \\mscrU \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{Set}(A, B) \\) from \\( A \\) to \\( B \\) is the set \\hyperref[def:function/set_of_functions]{\\( \\fun(A, B) \\)} of all total single-valued functions from \\( A \\) to \\( B \\).\n\n    \\item The \\hyperref[def:category/composition]{composition of morphisms} is the usual \\hyperref[def:multi_valued_function/composition]{function composition}.\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the set \\( A \\) is the \\hyperref[def:multi_valued_function/identity]{identity function}\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\id_A: A \\to A \\\\\n        &\\id_A(x) \\coloneqq A.\n      \\end{aligned}\n    \\end{equation*}\n  \\end{itemize}\n\\end{definition}\n\\begin{defproof}\n  To see that \\( \\ucat{Set} \\) 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 sets \\( A, B \\in \\mscrU \\) and every function \\( f: A \\to B \\), for all \\( x \\in A \\) we have\n  \\begin{equation*}\n    [\\id_B \\bincirc f](x)\n    =\n    \\id_B(f(x))\n    =\n    f(x)\n    =\n    f(\\id_A(x))\n    =\n    [f \\bincirc \\id_A](x).\n  \\end{equation*}\n\n  Therefore, \\( \\id_A \\) and \\( \\id_B \\) satisfy \\eqref{eq:def:category/C1}.\n\n  \\SubProofOf{def:category/C2} Associativity of function composition is proved in \\fullref{thm:def:multivalued_function/associative}.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:category_of_small_sets_properites}\n  We collect here important properties of the category \\hyperref[def:category_of_small_sets]{\\( \\ucat{Set} \\)} of \\( \\mscrU \\)-small sets. Most of them require forward references.\n\n  \\begin{thmenum}\n    \\thmitem{thm:category_of_small_sets_properites/large} It is a \\( \\mscrU \\)-large category in the sense of \\fullref{def:category_size} because \\( \\mscrU \\) itself is the set of objects and, defined as a \\hyperref[def:quiver]{quiver} with additional operations, the category is a \\( \\mscrU \\)-large set in the sense of \\fullref{def:large_and_small_sets}.\n\n    \\thmitem{thm:category_of_small_sets_properites/locally_small} It is a \\hyperref[def:category_size]{\\( \\mscrU \\)-locally small category} because \\( \\mscrU \\) is a model of \\hyperref[def:zfc]{\\( \\logic{ZFC} \\)} and \\fullref{thm:zfc_existence_theorems/set_of_functions} holds.\n\n    \\thmitem{thm:category_of_small_sets_properites/morphism_invertibility} All \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphisms} and \\hyperref[def:multi_valued_function/empty]{nonempty} \\hyperref[def:morphism_invertibility/left_cancellative]{monomorphisms} \\hyperref[def:morphism_invertibility/left_invertible]{split} and are precisely the \\hyperref[def:function_invertibility/surjective]{surjective} and nonempty \\hyperref[def:function_invertibility/injective]{injective functions}, respectively.\n\n    This is stated in \\fullref{thm:function_invertibility_categorical}. See also \\fullref{thm:epimorphisms_split_in_set}.\n\n    \\thmitem{thm:category_of_small_sets_properites/universal_objects} The empty set \\( \\varnothing \\) is an \\hyperref[def:universal_objects/initial]{initial object} and the singleton set \\( \\set{ A } \\) is a \\hyperref[def:universal_objects/terminal]{terminal object} for every \\( A \\in \\ucat{Set} \\). No \\hyperref[def:universal_objects/zero]{zero objects} exist in \\( \\ucat{Set} \\) by \\fullref{thm:def:universal_objects/no_zero}.\n\n    This is discussed in \\fullref{ex:def:universal_objects}.\n\n    \\thmitem{thm:category_of_small_sets_properites/discrete_category} The \\hyperref[def:discrete_category]{discrete category} functor \\( D: \\ucat{Set} \\to \\ucat{Cat} \\) is left adjoint to the forgetful functor \\( U: \\ucat{Cat} \\to \\ucat{Set} \\)\n\n    This is discussed in \\fullref{ex:def:category_adjunction/set_cat}.\n\n    \\thmitem{thm:category_of_small_sets_properites/limits} The \\hyperref[def:discrete_category_limits]{products} and \\hyperref[def:discrete_category_limits]{coproducts} are the \\hyperref[def:cartesian_product/product]{Cartesian products} and the \\hyperref[def:disjoint_union]{disjoint unions}, respectively.\n\n    This is stated in \\fullref{thm:discrete_category_limits_in_set}.\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{definition}\\label{def:opposite_category}\\mcite[def. 1.1.9]{Leinster2016Basic}\n  The \\term{opposite} category of \\( \\cat{C} \\) is obtained by \\enquote{reversing} all arrows. This reversing is merely a relabeling of the domain and codomain --- the underlying morphisms are the same. This concept is quite powerful because it allows performing constructions and proofs by duality --- see \\fullref{thm:categorical_principle_of_duality}.\n\n  Formally, the category \\( \\cat{C}^{\\opcat} \\) is defined as follows:\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(\\cat{C}^{\\opcat}) \\) is the set of objects \\( \\obj(\\cat{C}) \\) of \\( \\cat{C}^{\\opcat} \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{C}(A, B) \\) is the set \\( \\cat{C}(B, A) \\). Thus, any morphism \\( f^{\\opcat}: A \\to B \\) in the opposite category \\( \\cat{C}^{\\opcat} \\) is a morphism \\( f: B \\to A \\) in \\( \\cat{C}^{\\opcat} \\).\n\n    The superscript here is used solely to distinguish between \\( f \\) being regarded as a morphism of \\( \\cat{C} \\) and of \\( \\cat{C}^{\\opcat} \\) --- the morphisms in \\( \\cat{C} \\) are exactly those of \\( \\cat{C}^{\\opcat} \\), simply relabeled.\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms}\n    \\begin{align*}\n      f^{\\opcat} &\\in \\cat{C}^{\\opcat}(A, B) = \\cat{C}(B, A) \\\\\n      g^{\\opcat} &\\in \\cat{C}^{\\opcat}(B, C) = \\cat{C}(C, B)\n    \\end{align*}\n    is the morphism\n    \\begin{equation*}\n      \\underbrace{g^{\\opcat} \\bincirc f^{\\opcat}}_{\\cat{C}^{\\opcat}(A, C)} \\coloneqq \\underbrace{f \\bincirc g}_{\\cat{C}(C, A)}.\n    \\end{equation*}\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the object \\( A \\in \\cat{C} \\) is again \\( \\id_A \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{remark}\\label{rem:double_opposite_category}\n  The double-opposite of a category or morphism is obviously the original. This is made precise with the oppositization functor defined in \\fullref{def:opposite_functor}.\n\\end{remark}\n\n\\begin{example}\\label{ex:def:opposite_category}\n  A morphism \\( f^{\\opcat}: A \\to B \\) in the category \\( \\cat{Set}^{\\opcat} \\) is a function from the set \\( B \\) to the set \\( A \\). We cannot apply \\( f \\) to a point in \\( B \\) unless \\( B \\subseteq A \\). Thus, we cannot regard, in general, the morphism \\( f^{\\opcat} \\) as a function, although only the \\hyperref[def:multi_valued_function]{signature} of \\( f \\) is different from that of \\( f^{\\opcat} \\) --- their \\hyperref[def:multi_valued_function/graph]{graphs} are the same.\n\\end{example}\n\n\\begin{proposition}\\label{thm:categorical_principle_of_duality}\n  We can extend the principle of duality for preordered sets discussed in \\fullref{def:preordered_set/duality} to categories. Since we have defined categories in \\hyperref[def:axiom_of_universes]{\\logic{ZFC+U}} rather than as a first-order theory, we will state this principle informally:\n  \\begin{displayquote}\n    If a statement holds for every category, its dual statement obtained by \\enquote{reversing} all morphisms as in \\fullref{def:opposite_category}, also holds for every category.\n  \\end{displayquote}\n\n  See \\fullref{thm:def:morphism_invertibility/split_epimorphism} for how this principle can be utilized easily.\n\n  We list here results that heavily utilize this principle. Note that it is now always obvious what exactly needs to reversed in order for this principle to hold. For example, as discussed in \\fullref{def:opposite_functor}, for opposite functors we have\n  \\begin{equation*}\n    [F \\bincirc G]^{\\opcat} = F^{\\opcat} \\bincirc G^{\\opcat},\n  \\end{equation*}\n  which is somewhat unexpected.\n\n  \\begin{thmenum}\n    \\thmitem{thm:categorical_principle_of_duality/morphism_invertibility} \\Fullref{thm:morphism_invertibility_duality}: A morphism \\( f: A \\to B \\) in \\( \\cat{C} \\) is a \\hyperref[def:morphism_invertibility/left_invertible]{(split)} \\hyperref[def:morphism_invertibility/left_cancellative]{monomorphism} if and only if \\( f^{\\opcat}: B \\to A \\) in the opposite category \\( \\cat{C}^{\\opcat} \\) is a \\hyperref[def:morphism_invertibility/right_invertible]{(split)} \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphism}.\n\n    In particular, \\( f \\) is an \\hyperref[def:morphism_invertibility/isomorphism]{isomorphism} in \\( \\cat{C} \\) if and only if \\( f^{\\opcat} \\) is an isomorphism in \\( \\cat{C}^{\\opcat} \\).\n\n    \\thmitem{thm:categorical_principle_of_duality/universal_objects} \\Fullref{thm:universal_object_duality}: An object is \\hyperref[def:universal_objects/initial]{initial} if and only if it is a \\hyperref[def:universal_objects/terminal]{terminal object} the \\hyperref[def:opposite_category]{opposite category}.\n\n    \\thmitem{thm:categorical_principle_of_duality/functor_categories} \\Fullref{thm:opposite_of_functor_category}: For the \\hyperref[def:opposite_category]{opposite} 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    \\thmitem{thm:categorical_principle_of_duality/equivalences} \\Fullref{thm:opposite_of_category_equivalence}: The \\hyperref[def:opposite_category]{duals} of \\hyperref[def:category_equivalence]{equivalent categories} are equivalent.\n\n    \\thmitem{thm:categorical_principle_of_duality/adjunctions} \\Fullref{thm:category_adjunction_duality}: The functor \\( F \\) is \\hyperref[def:category_adjunction]{left adjoint} to \\( G \\) if and only if the \\hyperref[def:opposite_functor]{dual functor} \\( F^{\\opcat} \\) is right adjoint to \\( G^{\\opcat} \\).\n\n    \\thmitem{thm:categorical_principle_of_duality/limits} \\Fullref{thm:categorical_limit_duality}: 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 \\( \\cat{C}^{\\opcat} \\).\n\n    Even more, for every \\hyperref[def:category_of_cones/limit]{limit} \\( (L, \\pi) \\) of \\( D \\) in \\( \\cat{C} \\), \\( (L, \\pi^{\\opcat}) \\) is a \\hyperref[def:category_of_cones/colimit]{colimit} of \\( D^{\\opcat} \\) in \\( \\cat{C}^{\\opcat} \\).\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{definition}\\label{def:morphism_invertibility}\n  In connection with \\fullref{def:function_invertibility} and \\fullref{def:first_order_homomorphism_invertibility}, we introduce the following terminology:\n  \\begin{thmenum}\n    \\thmitem{def:morphism_invertibility/left_cancellative} The morphism \\( g: B \\to C \\) is \\term{left-cancellative} if, for any pair of morphisms \\( f_1, f_2: A \\to B \\), the equality \\( g \\bincirc f_1 = g \\bincirc f_2 \\) implies \\( f_1 = f_2 \\).\n\n    Left-cancellative morphisms are also called \\term{monic morphisms} or \\term{monomorphisms}.\n\n    \\thmitem{def:morphism_invertibility/left_invertible} The morphism \\( f: A \\to B \\) is \\term{left-invertible} if there exists a morphism \\( g: B \\to A \\) such that \\( g \\bincirc f = \\id_A \\). We call \\( g \\) a \\term{left inverse} of \\( f \\).\n\n    Using forward references to \\fullref{def:categorical_diagram}, we can restate this condition by saying that the following diagram commutes:\n    \\begin{equation}\\label{eq:def:morphism_invertibility/left_invertible}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__morphism_invertibility.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    Left-invertible morphisms are sometimes called \\term{split monomorphisms} because they \\enquote{split} the identity \\( \\id_A \\) into a composition of \\( f \\) and \\( g \\).\n\n    \\thmitem{def:morphism_invertibility/right_cancellative} \\hyperref[thm:categorical_principle_of_duality]{Dually}, the morphism \\( f: A \\to B \\) is \\term{right-cancellative} if, for any pair of morphisms \\( g_1, g_2: B \\to C \\), the equality \\( g_1 \\bincirc f = g_2 \\bincirc f \\) implies \\( g_1 = g_2 \\).\n\n    Right-cancellative morphisms are also called \\term{epic morphisms} or \\term{epimorphisms}.\n\n    \\thmitem{def:morphism_invertibility/right_invertible} The morphism \\( g: B \\to A \\) is \\term{right-invertible} if there exists a morphism \\( f: A \\to B \\) such that \\( f \\bincirc g = \\id_B \\). We call \\( g \\) a \\term{right inverse} of \\( f \\).\n\n    Using forward references to \\fullref{def:categorical_diagram}, we can restate this condition by saying that the following diagram commutes:\n    \\begin{equation}\\label{eq:def:morphism_invertibility/right_invertible}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/def__morphism_invertibility.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    Right-invertible morphisms are sometimes called \\term{split epimorphisms} because they \\enquote{split} the identity \\( \\id_B \\) into a composition of \\( g \\) and \\( f \\).\n\n    \\thmitem{def:morphism_invertibility/isomorphism} The morphism \\( f: A \\to B \\) is \\term{fully invertible} it is both left-invertible and right-invertible. By \\fullref{thm:def:morphism_invertibility/left_and_right}, in this case, there exists a unique morphism \\( f^{-1}: B \\to A \\) that is a \\term{two-sided inverse}, i.e. it is both a left inverse and a right inverse.\n\n    A fully invertible morphism is usually called an \\term{isomorphism}. If there exists an isomorphism between \\( A \\) and \\( B \\), we say that they are \\term{isomorphic} and write \\( A \\cong B \\).\n\n    \\thmitem{def:morphism_invertibility/endomorphism} A morphism \\( f: A \\to A \\) from an object to itself is called an \\term{endomorphism}.\n\n    \\thmitem{def:morphism_invertibility/automorphism} A morphism that is both an endomorphism and an isomorphism is called an \\term{automorphism}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:morphism_invertibility}\n  \\Fullref{thm:function_invertibility_categorical} characterizes the cancellative and invertible morphisms defined in \\fullref{def:morphism_invertibility} for \\hyperref[def:category_of_small_sets]{\\( \\cat{Set} \\)} in terms of \\hyperref[def:function_invertibility/injective]{injectivity} and \\hyperref[def:function_invertibility/injective]{surjectivity}.\n\n  A very simple example of a monomorphism which does not split is the empty function with nonempty domain. These are discussed in \\fullref{thm:function_invertibility_categorical/empty}.\n\n  \\Fullref{thm:surjective_functions_are_right_invertible} is important enough to have a categorical interpretation via \\fullref{thm:epimorphisms_split_in_set}, where its relation to the \\hyperref[def:zfc/choice]{axiom of choice} is also discussed.\n\\end{example}\n\n\\begin{proposition}\\label{thm:morphism_invertibility_duality}\n  A morphism \\( f: A \\to B \\) in \\( \\cat{C} \\) is a \\hyperref[def:morphism_invertibility/left_invertible]{(split)} \\hyperref[def:morphism_invertibility/left_cancellative]{monomorphism} if and only if \\( f^{\\opcat}: B \\to A \\) in the opposite category \\( \\cat{C}^{\\opcat} \\) is a \\hyperref[def:morphism_invertibility/right_invertible]{(split)} \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphism}.\n\n  In particular, \\( f \\) is an \\hyperref[def:morphism_invertibility/isomorphism]{isomorphism} in \\( \\cat{C} \\) if and only if \\( f^{\\opcat} \\) is an isomorphism 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  Trivial.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:morphism_invertibility}\n  Morphisms have the following basic properties regarding their \\hyperref[def:morphism_invertibility]{invertibility} (compare to \\fullref{thm:function_composition_invertibility}):\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:morphism_invertibility/split_monomorphism} Any \\hyperref[def:morphism_invertibility/left_invertible]{left-invertible morphism} is \\hyperref[def:morphism_invertibility/left_cancellative]{left-cancellative}.\n\n    In more categorical terms, every split monomorphism is a monomorphism.\n\n    \\thmitem{thm:def:morphism_invertibility/split_epimorphism} Any \\hyperref[def:morphism_invertibility/right_invertible]{right-invertible morphism} is \\hyperref[def:morphism_invertibility/right_cancellative]{right-cancellative}.\n\n    In more categorical terms, every split epimorphism is an epimorphism.\n\n    \\thmitem{thm:def:morphism_invertibility/at_most_one_inverse}\\mcite[exer. 1.1.13]{Leinster2016Basic} Any morphism has at most one two-sided inverse.\n\n    \\thmitem{thm:def:morphism_invertibility/left_and_right} If a morphism is both left-invertible and right-invertible, the two inverses are equal, and the morphism is fully invertible.\n\n    \\thmitem{thm:def:morphism_invertibility/inverse_interchanges} The morphism \\( f: A \\to B \\) is a right inverse of \\( g: B \\to A \\) if and only if \\( g \\) is a left inverse of \\( f \\).\n\n    \\thmitem{thm:def:morphism_invertibility/monomorphism_and_split_epimorphism} If a morphism left-cancellative and right-invertible, it is an isomorphism.\n\n    \\thmitem{thm:def:morphism_invertibility/split_monomorphism_and_epimorphism} If a morphism left-invertible and right-cancellative, it is an isomorphism.\n\n    \\thmitem{thm:def:morphism_invertibility/cancellative_composition} The composition of two monomorphisms (resp. epimorphisms) is again a monomorphism (resp. epimorphism).\n\n    \\thmitem{thm:def:morphism_invertibility/invertible_composition} The composition of two split monomorphisms (resp. epimorphisms) is again a split monomorphism (resp. epimorphism).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:morphism_invertibility/split_monomorphism} Suppose that \\( g: B \\to C \\) is left-invertible with inverse \\( h: C \\to B \\). Suppose that \\( f_1, f_2: A \\to B \\) are morphisms such that\n  \\begin{equation*}\n    g \\bincirc f_1 = g \\bincirc f_2.\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    f_1\n    \\reloset {\\eqref{eq:def:category/C1}} =\n    \\id_B \\bincirc f_1\n    =\n    (h \\bincirc g) \\bincirc f_1\n    \\reloset {\\eqref{eq:def:category/C2}} =\n    h \\bincirc (g \\bincirc f_1)\n    =\n    h \\bincirc (g \\bincirc f_2)\n    =\n    \\cdots\n    =\n    f_2.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:morphism_invertibility/split_epimorphism} This is an exemplar proof using duality. By \\fullref{thm:morphism_invertibility_duality}, every split epimorphism \\( f: A \\to B \\) in \\( \\cat{C} \\) is a split monomorphism in \\( \\cat{C}^{\\opcat} \\). By \\fullref{thm:def:morphism_invertibility/split_monomorphism}, \\( f^{\\opcat} \\) is a monomorphism. Then gain by \\fullref{thm:morphism_invertibility_duality}, \\( f \\) is an epimorphism.\n\n  \\SubProofOf{thm:def:morphism_invertibility/at_most_one_inverse} If \\( f: A \\to B \\) has no inverse, it vacuously has at most one inverse.\n\n  Now assume that \\( f: A \\to B \\) has two inverses \\( g_1: B \\to A \\) and \\( g_2: B \\to A \\):\n  \\begin{align*}\n    g_1 \\bincirc f = \\id_A &&& f \\bincirc g_1 = \\id_B, \\\\\n    g_2 \\bincirc f = \\id_A &&& f \\bincirc g_2 = \\id_B.\n  \\end{align*}\n\n  Then\n  \\begin{equation*}\n    g_1\n    \\reloset {\\eqref{eq:def:category/C1}} =\n    g_1 \\bincirc \\id_B\n    =\n    g_1 \\bincirc (f \\bincirc g_2)\n    \\reloset {\\eqref{eq:def:category/C2}} =\n    (g_1 \\bincirc f) \\bincirc g_2\n    =\n    \\id_A \\bincirc g_2\n    \\reloset {\\eqref{eq:def:category/C1}} =\n    g_2.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:morphism_invertibility/left_and_right} Suppose that \\( f: A \\to B \\) has a left-inverse \\( l: B \\to A \\) and a right-inverse \\( r: B \\to A \\). Then\n\n  \\SubProofOf{thm:def:morphism_invertibility/inverse_interchanges} Trivial.\n\n  \\SubProofOf{thm:def:morphism_invertibility/monomorphism_and_split_epimorphism} Let \\( g: B \\to A \\) be left-cancellative and right-invertible. Let \\( f: A \\to B \\) be a right inverse of \\( g \\). Then\n  \\begin{equation*}\n    f\n    =\n    \\reloset {\\eqref{eq:def:category/C1}} =\n    f \\bincirc \\id_A\n    =\n    f \\bincirc (g \\bincirc f)\n    =\n    (f \\bincirc g) \\bincirc f.\n  \\end{equation*}\n\n  Because \\( g \\) is a left inverse of \\( f \\), from \\fullref{thm:def:morphism_invertibility/split_monomorphism} it follows that \\( f \\) is left-cancellative. Since we have\n  \\begin{equation*}\n    \\id_B \\bincirc f\n    =\n    (f \\bincirc g) \\bincirc f,\n  \\end{equation*}\n  it follows that \\( f \\bincirc g = \\id_B \\).\n\n  Therefore, \\( f \\) is a left inverse of \\( g \\) and hence an isomorphism.\n\n  \\SubProofOf{thm:def:morphism_invertibility/split_monomorphism_and_epimorphism} The proof is analogous to \\fullref{thm:def:morphism_invertibility/monomorphism_and_split_epimorphism}.\n\n  \\SubProofOf{thm:def:morphism_invertibility/cancellative_composition} Let \\( g: B \\to C \\) and \\( h: C \\to D \\) be monomorphisms (left-cancellative).\n\n  Let \\( f_1, f_2: A \\to B \\) be two arbitrary morphisms with codomain \\( B \\). Suppose that\n  \\begin{equation*}\n    (h \\bincirc g) \\bincirc f_1 = (h \\bincirc g) \\bincirc f_2.\n  \\end{equation*}\n\n  Then, by \\ref{def:category/C2},\n  \\begin{equation*}\n    h \\bincirc (g \\bincirc f_1) = h \\bincirc (g \\bincirc f_2).\n  \\end{equation*}\n\n  Since \\( h \\) is left-cancellative, it follows that\n  \\begin{equation*}\n    g \\bincirc f_1 = g \\bincirc f_2.\n  \\end{equation*}\n\n  Since \\( g \\) is also left-cancellative, \\( f_1 = f_2 \\).\n\n  Therefore, \\( h \\bincirc g \\) is a monomorphism.\n\n  The proof for composition of epimorphisms is identical.\n\n  \\SubProofOf{thm:def:morphism_invertibility/invertible_composition} Let \\( f: A \\to B \\) and \\( g: B \\to C \\) be split monomorphisms (left-invertible).\n\n  Then there exist left inverses \\( l_f: B \\to A \\) and \\( l_g: C \\to B \\) of \\( f \\) and \\( g \\), respectively. We have\n  \\begin{equation*}\n    (l_f \\bincirc l_g) \\bincirc (g \\bincirc f)\n    \\reloset {\\eqref{eq:def:category/C2}} =\n    l_f \\bincirc (l_g \\bincirc g) \\bincirc f\n    =\n    l_f \\bincirc \\id_B \\bincirc f\n    \\reloset {\\eqref{eq:def:category/C1}} =\n    l_f \\bincirc f\n    =\n    \\id_A.\n  \\end{equation*}\n\n  Therefore, \\( g \\bincirc f \\) is also left-invertible.\n\n  The proof for composition of split epimorphisms is identical.\n\\end{proof}\n\n\\begin{theorem}[Epimorphisms split in Set]\\label{thm:epimorphisms_split_in_set}\n  Every \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphism} in \\hyperref[def:category_of_small_sets]{\\( \\cat{Set} \\)} splits. That is, all epimorphisms in \\( \\cat{Set} \\) are \\hyperref[def:morphism_invertibility/right_invertible]{split epimorphisms}.\n\n  Assuming the existence of the \\hyperref[def:grothendieck_universe]{Grothendieck universe} containing \\( \\cat{Set} \\), 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/epimorphisms}.\n\n  Since not every epimorphism splits in a general category, this theorem is sometimes considered to be a categorical statement of the axiom of choice, which holds in some categories but not in others.\n\\end{theorem}\n\\begin{proof}\n  By \\fullref{thm:function_invertibility_categorical/right_cancellative}, a function is an epimorphism if and only if it is surjective. Thus, the theorem is equivalent to \\fullref{thm:surjective_functions_are_right_invertible}.\n\\end{proof}\n\n\\begin{definition}\\label{def:universal_objects}\\mcite[def. 2.1.7]{Leinster2016Basic}\n  Fix a category \\( \\cat{C} \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:universal_objects/initial} We call the object \\( I \\in \\cat{C} \\) an \\term{initial object} if for any other object \\( A \\in \\cat{C} \\) there exists a unique morphism \\( f: I \\to A \\),\n\n    \\thmitem{def:universal_objects/terminal} \\hyperref[thm:categorical_principle_of_duality]{Dually}, we call the object \\( T \\in \\cat{C} \\) a \\term{terminal object} or \\term{final object} if for any other object \\( A \\in \\cat{C} \\) there exists a unique morphism \\( f: A \\to T \\).\n\n    The initial and terminal objects are collectively called \\term{universal objects}.\n\n    \\thmitem{def:universal_objects/zero}\\mcite{nLab:pointed_category} If \\( Z \\) is both an initial and a terminal object, we say that \\( Z \\) is a \\term{zero object}. A category with a zero object is called a \\term{pointed category}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:universal_objects}\n  \\begin{thmenum}\n    \\thmitem{ex:def:universal_objects/set} In the category \\hyperref[def:category_of_small_sets]{\\( \\cat{Set} \\)} of small sets, for any set \\( A \\) there is a unique \\hyperref[def:multi_valued_function/empty]{empty function} from \\( \\varnothing \\) to \\( A \\). Therefore, \\( \\varnothing \\) is an \\hyperref[def:universal_objects/initial]{initial object} in \\( \\cat{Set} \\).\n\n    For any set \\( A \\), there is a unique function that contracts any set \\( B \\) to \\( \\set{ A } \\). Therefore, every singleton set is a \\hyperref[def:universal_objects/terminal]{final object} in \\( \\cat{Set} \\).\n\n    We often denote the initial and terminal objects in \\( \\cat{Set} \\) by \\( 0 \\) and \\( 1 \\) respectively, which corresponds to their definition as \\hyperref[def:ordinal]{ordinals}.\n\n    By \\fullref{thm:def:universal_objects/no_zero}, \\( \\cat{Set} \\) has no zero object.\n\n    \\thmitem{ex:def:universal_objects/grp} In the category \\hyperref[def:group/category]{\\( \\cat{Grp} \\)} of small groups, the \\hyperref[def:group/trivial]{trivial group} is a \\hyperref[def:universal_objects/zero]{zero object}. This holds more generally for pointed sets rather than groups.\n\n    Indeed, it can be embedded into any other group and any group can be contracted into the corresponding trivial group. Furthermore, all trivial groups are isomorphic.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:universal_object_duality}\n  An object is \\hyperref[def:universal_objects/initial]{initial} if and only if it is a \\hyperref[def:universal_objects/terminal]{terminal object} the opposite category.\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:def:universal_objects}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{thm:def:universal_objects/initial} An \\hyperref[def:universal_objects/initial]{initial object} is unique up to an isomorphism.\n    \\thmitem{thm:def:universal_objects/terminal} \\hyperref[thm:categorical_principle_of_duality]{Dually}, a \\hyperref[def:universal_objects/initial]{terminal object} is also unique up to an isomorphism.\n    \\thmitem{thm:def:universal_objects/zero} If a category has an initial and a terminal object and if they are isomorphic, then both are zero objects.\n\n    In particular, a zero object is unique up to an isomorphism.\n\n    \\thmitem{thm:def:universal_objects/no_zero} If an initial and a terminal object exists and are not isomorphic, then there exist no zero objects.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:universal_objects/initial} Suppose that \\( A \\) and \\( B \\) are both initial objects in \\( \\cat{C} \\). Then there exist morphisms \\( f: A \\to B \\) and \\( g: B \\to A \\). Their composition \\( g \\bincirc f \\) is an \\hyperref[def:morphism_invertibility/endomorphism]{endomorphism} on \\( A \\).\n\n  But there exists a unique \\hyperref[def:morphism_invertibility/endomorphism]{endomorphism} on \\( A \\), which must be the identity \\( \\id_A \\). Thus, \\( g \\bincirc f = \\id_A \\) and \\( g \\) is a left inverse of \\( f \\).\n\n  We can analogously show that \\( g \\) is a right inverse of \\( f \\). Therefore, \\( f \\) is fully invertible, and \\( A \\) and \\( B \\) are isomorphic.\n\n  \\SubProofOf{thm:def:universal_objects/terminal} If \\( T' \\) and \\( T^\\dprime \\) are terminal objects in \\( \\cat{C} \\), by \\fullref{thm:universal_object_duality}, they are initial objects in \\( \\cat{C}^{\\opcat} \\). By \\fullref{thm:def:universal_objects/initial}, they are isomorphic in \\( \\cat{C}^{\\opcat} \\) and by \\fullref{thm:morphism_invertibility_duality}, they are isomorphic in \\( \\cat{C} \\).\n\n  \\SubProofOf{thm:def:universal_objects/zero} Suppose that \\( A \\) is an initial object and that \\( B \\) is a final object in \\( \\cat{C} \\). Let \\( f: A \\to B \\) be an isomorphism between them.\n\n  Let \\( C \\in \\cat{C} \\) be any other object and let \\( g: C \\to B \\) be the unique morphism to \\( B \\). Then \\( f^{-1} \\bincirc g: C \\to A \\) is a morphism from \\( C \\) to \\( A \\). The inverse \\( f^{-1}: B \\to A \\) is unique by \\fullref{thm:def:morphism_invertibility/at_most_one_inverse}, therefore its composition with \\( g: C \\to B \\) is also unique. Hence, any object has a unique morphism to \\( A \\). This makes \\( A \\) a terminal object and thus a zero object.\n\n  We can analogously show that \\( B \\) is a zero object.\n\n  \\SubProofOf{thm:def:universal_objects/no_zero} By \\fullref{thm:def:universal_objects/zero}, all zero objects are isomorphic. By \\fullref{thm:def:universal_objects/initial}, all initial objects are isomorphic and analogously for terminal objects. Hence, if a zero object exists, all initial objects are isomorphic to all terminal objects.\n\n  If some initial object is not isomorphic to some terminal object, then by contraposition it follows that no zero object exists.\n\\end{proof}\n", "meta": {"hexsha": "657942ef259226ad8d79779f51ebc6b63d4ca8a2", "size": 36962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/categories.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/categories.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/categories.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.04743083, "max_line_length": 531, "alphanum_fraction": 0.7201450138, "num_tokens": 11513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.6619415342855767}}
{"text": "\\section{Orbits}\r\nThe study of orbits it is motivated by the motion of heavenly bodies under the infludence of the gravitational force due to e.g. a star.\r\nOf course, we want to study a conservative field $-\\nabla V$ where $V$ is a potential of a central force (so it only depends on $r=|\\underline{r}|$), that is\r\n$$m\\underline{\\ddot{r}}=-\\nabla V(r)$$\r\nWe shall study the case when the central body is much more massive than the orbiting body, so that the central body can be regarded as fixed.\\\\\r\nRecall that $\\underline{L}=m\\underline{r}\\times\\underline{\\dot{r}}$, and in the case for a central force $\\underline{\\dot{L}}=0$, so $\\underline{L}$ is constant.\r\nAlso we always have $\\underline{L}\\cdot\\underline{r}=0$, so we can regard the motion as if it is in a plane.\r\n\\subsection{Polar Coordinates in a Plane}\r\nIn an orbit problem, we of course want to use polar coordinate to simplify calculation.\r\nSince we can regard the problem as two-dimensional, we can use the plane polar coordinates $x=r\\cos\\theta,y=r\\sin\\theta$, so we define the unit vectors\r\n$$\\underline{e_r}=(\\cos\\theta,\\sin\\theta)^\\top,\\underline{e_\\theta}=(-\\sin\\theta,\\cos\\theta)^\\top$$\r\nSo we can use $\\underline{e_r},\\underline{e_\\theta}$ as two basis vectors, but note that they are dependent of the position.\r\nNote that $\\underline{e_r}$ is always in the direction of the position and $\\underline{e_\\theta}$ the direction of rotation.\r\nAlso note that $\\mathrm d\\underline{e_r}/\\mathrm d\\theta=\\underline{e_\\theta},\\mathrm d\\underline{e_\\theta}/\\mathrm d\\theta=-\\underline{e_r}$, so\r\n$$\\frac{\\mathrm d\\underline{e_r}}{\\mathrm dt}=\\underline{e_\\theta}\\dot{\\theta},\\frac{\\mathrm d\\underline{e_\\theta}}{\\mathrm dt}=-\\underline{e_r}\\dot{\\theta}$$\r\nNow we turn to consider the implications for the velocity of the particle given some acceleration.\r\nWrite $\\underline{r}=r\\underline{e_r}$.\r\nConsider this as a function of time, then $\\underline{v}=\\underline{\\dot{r}}=\\dot{r}\\underline{e_r}+r\\underline{e_\\theta}\\dot{\\theta}$.\r\n$\\dot{r}$ is the radial component of the velocity while $\\dot{\\theta}$ is the angular component of it.\r\nSo $\\dot{\\theta}$ has dimension $T^{-1}$.\\\\\r\nAs for accelerations, we have\r\n$$\\underline{\\ddot{r}}=\\underline{\\dot{v}}=\\ddot{r}\\underline{e_r}+\\dot{r}\\underline{e_\\theta}\\dot{\\theta}+(\\dot{r}\\dot{\\theta}+r\\ddot{\\theta})\\underline{e_\\theta}-r\\dot{\\theta}\\underline{e_r}\\dot{\\theta}=(\\ddot{r}-r\\dot{\\theta}^2)\\underline{e_r}+(2\\dot{r}\\dot{\\theta}+r\\ddot{\\theta})\\underline{e_\\theta}$$\r\n\\begin{example}\r\n    Consider the circular motion with a constant angular velocity, then $r=a,\\dot{\\theta}=\\omega$, so $\\dot{r}=\\ddot{\\theta}=0$, hence\r\n    $$\\underline{\\ddot{r}}=(\\ddot{r}-r\\dot{\\theta}^2)\\underline{e_r}+(2\\dot{r}\\dot{\\theta}+r\\ddot{\\theta})\\underline{e_\\theta}=-a\\omega^2\\underline{e_r}=-\\omega^2\\underline{r}$$\r\n    which is the familiar centripetal acceleration.\r\n    Newton's Second Law requires a force to be applied to cause this acceleration, which is called the centripetal force, which is in the direction of $-\\underline{e_r}$.\r\n    For the special case that it is actually a mass on a string, then when the string broke, the mass will move in a straight line that is tangential to the point where the string broke.\r\n\\end{example}\r\n\\subsection{Motion in a Constant Force Field}\r\nWe know\r\n$$m\\underline{\\ddot{r}}=\\underline{F}=-\\nabla V(r)=-\\frac{\\mathrm dV}{\\mathrm dr}\\underline{e_r}$$\r\nfor a force field that is symmetric wrt the origin.\r\nNote that\r\n$$-\\frac{\\mathrm dV}{\\mathrm dr}\\underline{e_r}=\\underline{F}=m(\\ddot{r}-r\\dot{\\theta}^2)\\underline{e_r}+m(2\\dot{r}\\dot{\\theta}+r\\ddot{\\theta})\\underline{e_\\theta}$$\r\nBy looking at the $\\underline{e_\\theta}$ component, we have $2\\dot{r}\\dot{\\theta}+r\\ddot{\\theta}=0$, so\r\n$$\\frac{1}{r}\\frac{\\mathrm d}{\\mathrm dt}(mr^2\\dot{\\theta})=0$$\r\nHence the quantity $mr^2\\dot{\\theta}$ is constant, but $\\underline{L}=\\underline{r}\\times (m\\underline{\\dot{r}})=mr^2\\dot{\\theta}\\underline{e_z}$.\r\nWhere $\\underline{e_z}$ is the normal to the plane of motion.\r\nHence the angular momentum is constant in magnitude.\r\nWe write $h=|\\underline{L}|/m=r^2\\dot{\\theta}$.\\\\\r\nGoing to the radial part $\\mathrm dV/\\mathrm dr=-m(\\ddot{r}-h^2/r^3)$, rearranging gives\r\n$$m\\ddot{r}=-\\frac{\\mathrm dV}{\\mathrm dr}+\\frac{mh^2}{r^3}=-\\frac{\\mathrm dV_{\\rm eff}}{\\mathrm dr},V_{\\rm eff}=V+\\frac{mh^2}{2r^2}$$\r\nSo the motion of the particle is as if we are considering one dimensional motion under the influence of a modified potential $V_{\\rm eff}$.\\\\\r\nThe energy of the particle is then\r\n$$E=T+V=\\frac{1}{2}m|\\underline{\\dot{r}}|^2+V(r)=\\frac{1}{2}m\\dot{r}^2+V_{\\rm eff}(r)$$\r\n\\begin{example}\r\n    For gravity, we have\r\n    $$V(r)=-\\frac{GMm}{r},V_{\\rm eff}(r)=-\\frac{GMm}{r}+\\frac{mh^2}{2r^2}$$\r\n    So $V_{\\rm eff}$ is minimum at $r=h^2/GM$ and minimum energy is\r\n    $$E_{\\rm min}=-m(GM)^2/(2h^2)$$\r\n    At the minimum (which is a stable equilibrium), both $r,\\dot\\theta$ are constants.\\\\\r\n    At any $E_{\\rm min}<E<0$, the particle oscillates.\r\n    Let $r_0$ be the point where $V_{\\rm eff}=0$, then $r_0<r_{\\rm min}\\le r\\le r_{\\rm max}$.\r\n    So it gives a bounded non-circular orbit with $\\dot\\theta$ varying when $r$ varies.\r\n    $r_{\\rm min}$ is called the periapsis and $r_{\\rm max}$ is called apoapsis.\\\\\r\n    For $E>0$, the particle can move from a long distance and escape, which is an unbounded orbit.\r\n\\end{example}\r\n\\subsection{Stability of Circular Orbits}\r\nConsider the potential $V(r)$, we want to investigate whether a circular orbit exists and whether it is stable.\\\\\r\nAssume that the angular momentum $h$ is given and is nonzero.\r\nFor circular orbit $r(t)=r_\\star$ is a constant, then\r\n$$\\ddot{r}=0\\implies V_{\\rm eff}^\\prime(r_\\star)=0$$\r\nwhich is the condition for circular orbit.\r\nNote that if $V_{\\rm eff}^{\\prime\\prime}(r_\\star)>0$, then it is a minimum, so $r_\\star$ is a stable fixed point.\r\nSo if we express it as $V(r)$, we get\r\n$$0=V_{\\rm eff}^\\prime(r_\\star)=V^\\prime(r_\\star)-\\frac{mh^2}{r_\\star^3}=0\\implies V^\\prime(r_\\star)=\\frac{mh^2}{r_\\star^3}$$\r\nAnd it is stable if\r\n$$0<V_{\\rm eff}^\\prime(r_\\star)=V^{\\prime\\prime}(r_\\star)+\\frac{3mh^2}{r_\\star^4}=V^{\\prime\\prime}(r_\\star)+\\frac{3V^\\prime(r_\\star)}{r_\\star}$$\r\nSo in terms of $F(r)$, we have\r\n$$F^{\\prime}(r_\\star)+\\frac{3F(r_\\star)}{r_\\star}<0$$\r\n\\begin{example}\r\n    If we take $V(r)=-km/rp$ for $k,p>0$ for a circular orbit with radius $r_\\star$, we can solve the above equation to get $r_\\star=(pk/h^2)^{1/(p-2)}$.\r\n    So unless $p=2$, there exists a circular orbit.\\\\\r\n    As for stability, we have\r\n    $$V^{\\prime\\prime}(r_\\star)+\\frac{3V^\\prime(r_\\star)}{r_\\star}=\\frac{p(2-p)k}{r_\\star^{p+2}}>0$$\r\n    which is positive iff $p<2$.\r\n\\end{example}\r\n\\subsection{The Orbit Equation}\r\nThe shape of the orbit is obviously governed by the joint variation of $r$ and $\\theta$ (both as functions of $t$).\r\nIn principle, the energy equation can be helpful to determine $r(t)$, i.e.\r\n$$E=\\frac{1}{2}m\\dot{r}^2+V_{\\rm eff}(r)\\implies t=\\pm\\sqrt{\\frac{m}{2}}\\int\\frac{\\mathrm dr}{\\sqrt{E-V_{\\rm eff}(r)}}$$\r\nGiven $r(t)$, since we already know the conservation of angular momentum $r^2\\dot\\theta=h$, we can then deduce $\\theta(t)$.\r\nBut this might not always yield an analytic solution.\\\\\r\nAn interesting approach if one is only interested in the trajectory is to use $\\theta$ as the dependent variable.\r\nWe can write\r\n$$\\frac{\\mathrm d}{\\mathrm dt}=\\dot\\theta\\frac{\\mathrm d}{\\mathrm d\\theta}=\\frac{h}{r^2}\\frac{\\mathrm d}{\\mathrm d\\theta}$$\r\nSo plugging in Newton's Second Law,\r\n$$m\\frac{h}{r^2}\\frac{\\mathrm d}{\\mathrm d\\theta}\\left( \\frac{h}{r^2}\\frac{\\mathrm dr}{\\mathrm d\\theta} \\right)-\\frac{mh^2}{r^3}=F(r)$$\r\nwhich then becomes, by substituting $u=1/r$,\r\n$$\\frac{\\mathrm d^2u}{\\mathrm d\\theta^2}+u=-\\frac{1}{mh^2u^2}F\\left(\\frac{1}{u}\\right)$$\r\nThis is called the orbit equation.\r\nWe can then solve for $u$ as a function of $\\theta$, and then $\\dot\\theta=hu^2$ can help us to deduce the time evolution.\r\n\\subsection{The Kepler Problem}\r\nWe want to solve the case for gravitational central force given by\r\n$$F(r)=-\\frac{mk}{r^2}$$\r\nSo the orbit equation becomes\r\n$$\\frac{\\mathrm d^2u}{\\mathrm d\\theta^2}+u=\\frac{k}{h^2}$$\r\nWhich is linear in $u$.\r\nWe know how to solve this.\r\nIndeed, the general solution is given by\r\n$$u=\\frac{k}{h^2}+A\\cos(\\theta-\\theta_0)$$\r\nWLOG we assume $A\\ge 0$.\\\\\r\nIf $A=0$, then $u$ is constant hence we obtain a circular orbit.\r\nIf $A>0$, $u$ obtains its maximum (hence $r$ obtains its minimum) at $\\theta=\\theta_0$.\r\nWe may choose $\\theta_0=0$, then\r\n$$r=\\frac{1}{u}=\\frac{\\ell}{1+e\\cos\\theta},\\ell=\\frac{h^2}{k},e=\\frac{Ah^2}{k}$$\r\nWhich is the polar coordinate form of a conic section with focus at the origin.\r\n$e$ is called the eccentricities, which determines the shape of the trajectory.\r\nBy rearranging we obtain (since $r=\\ell-ex$ and $r\\cos\\theta=y$)\r\n$$(1-e^2)x^2+2elx+y^2=\\ell^2$$\r\nTherefore if $e\\in[0,1)$, it is an ellipse that is bounded by\r\n$$\\frac{\\ell}{1+e}\\le r\\le\\frac{\\ell}{1-e}$$\r\nOr analytically we can rewrite the equation as\r\n$$\\frac{(x+ea)^2}{a^2}+\\frac{y^2}{b^2}=1,a=\\frac{\\ell}{1-e^2},b=\\frac{\\ell}{\\sqrt{1-e^2}}\\le a$$\r\n$a,b$ represents the semimajor and semiminor axes respectively.\r\nIn particular, for $e=0$, the path is a circle with center being the central mass.\\\\\r\nFor $e>1$, the equation gives a hyperbola, so $r\\to\\infty$ when $\\theta\\to\\pm\\alpha$ where $\\alpha=\\cos^{-1}(-1/e)\\in (\\pi/2,\\pi)$.\r\nWe can also transform the equation ot the standard equation for hyperbola\r\n$$\\frac{(x-ea)^2}{a^2}-\\frac{y^2}{b^2}=1$$\r\nwith $a=\\ell/(e^2-1),b=\\ell/\\sqrt{e^2-1}$.\r\nThis case represents incoming body with large velocity which is deflected by gravitational force.\r\nBy simple calculations the asymptotes are $y=\\mp b(x-ea)/a$, so $bx\\pm ay=eba$.\r\nAnd the normal vectors are $\\underline{n}=(b,\\pm a)/\\sqrt{a^2+b^2}$.\\\\\r\nNow consider the perpendicular distance between incoming mass and orgin, we have\r\n$$\\underline{r}\\cdot\\underline{n}=(x,y)\\cdot\\left( \\frac{b}{\\sqrt{a^2+b^2}},\\pm\\frac{a}{\\sqrt{a^2+b^2}} \\right)=\\frac{eba}{\\sqrt{a^2+b^2}}=b$$\r\nThis is sometimes called the impact parameter.\\\\\r\nThe marginal case that $e=1$ yields a parabola with equation\r\n$$r=\\frac{\\ell}{1+\\cos\\theta}$$\r\nwhere $r\\to \\infty$ as $\\theta\\to\\pm\\pi$.\r\nIn Cartesians this reduces to $y=2\\ell(\\ell-x)$.\\\\\r\nOn the other hand, we might want to analyze the linkge between the energy and the eccentricity of the trajectory.\r\nRecall that\r\n\\begin{align*}\r\n    E&=\\frac{1}{2}m(\\dot{r}^2+r^2\\dot{\\theta}^2)-\\frac{mk}{r}\\\\\r\n    &=\\frac{1}{2}mh^2\\left( \\left( \\frac{\\mathrm du}{\\mathrm d\\theta} \\right)^2+u^2 \\right)-mku\\\\\r\n    &=\\frac{mk}{2\\ell}(e^2-1)\r\n\\end{align*}\r\nHence bounded orbits have $e<1,E<0$ and unbounded ones have $e>1,E>0$.\r\nThe marginal case is then $e=E=0$.\r\n\\begin{law}[Kepler's Laws of Planetary Motion]\r\n    1. Orbit of planet is ellipe with the Sun at focus.\\\\\r\n    2. Line between the planet and the sun sweeps cut equal area in equal time.\\\\\r\n    3. Square of period $P$ is proportional to cube of semimajor axis.\r\n\\end{law}\r\n1 is consistent with the solutrion to the orbit equation that we have obtained earlier, and $2$ follows from the conservation of angular momentum (since the rate of change of area is approximately $r^2\\dot\\theta/2=h/2$).\r\nHence the area of the ellipse is $A=hP/2$ where $P$ is the period.\r\nTherefore $\\pi ab=hP/2$, rearranging gives the third statement.\r\n\\subsection{Rutherford Scattering}\r\nConsider the motion in a repulsive force under inverse square law:\r\n$$V(r)=\\frac{mk}{r},F(r)=\\frac{mk}{r^2}$$\r\nThen the orbit equation solves to give\r\n$$\\frac{1}{r}=u=-\\frac{k}{h^2}+A\\cos(\\theta-\\theta_0)$$\r\nWLOG $\\theta_0=0,A\\ge 0$.\r\nSo\r\n$$r=\\frac{\\ell}{e\\cos\\theta-1},\\ell=\\frac{h^2}{k},e=\\frac{Ah^2}{k}$$\r\nIf there is sometime where $r>0$, then we necessarily have $e>1$, therefore the trajectory is a hyperbola.\r\nAs previously known, $r\\to\\infty$ as $\\theta\\to\\pm\\alpha$ where $\\alpha=\\cos^{-1}(1/e)\\in(0,\\pi/2)$ and in Cartesian,\r\n$$\\frac{(x-ea)^2}{a^2}-\\frac{y^2}{b^2}=1,a=\\frac{\\ell}{e^2-1},b=\\frac{\\ell}{\\sqrt{e^2-1}}$$\r\nSuppose the speed of the particle from far away be $v$, that is\r\nWith $x$-axis parallel to the incoming asymptote, as $t\\to-\\infty$\r\n$$\\underline{r}(t)\\to (x(t),b,0),\\underline{\\dot{r}}(t)\\to(-v,0,0)$$\r\nThen $\\underline{r}\\times\\underline{\\dot{r}}\\to(0,0,bv)$\r\nTherefore the angular momentum per unit mass is $bv$, so\r\n$$b=\\frac{h^2}{k}\\frac{k}{bv^2}=\\frac{h^2}{k}\\tan\\frac{\\beta}{2}=\\frac{b^2v^2}{k}\\tan\\frac{\\beta}{2},\\beta=2\\tan^{-1}\\left( \\frac{k}{bv^2} \\right)$$\r\nRutherfold (1911) fired $\\alpha$ particles at gold leaf to obtain experimental results of the scattering.\r\nBut Scattering angles greater than $\\pi/2$ is observed in the experiment, from which he concluded that the positive charge must be highly concentrated.", "meta": {"hexsha": "6c9f9a01d73aed600c97e646b532bb7c42eb10f7", "size": 12753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/orbits.tex", "max_stars_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_stars_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/orbits.tex", "max_issues_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_issues_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/orbits.tex", "max_forks_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_forks_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.3652694611, "max_line_length": 307, "alphanum_fraction": 0.6827413158, "num_tokens": 4343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6619415264219216}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb,amsthm,fullpage,enumerate,hyperref,graphicx}\n\\usepackage[color]{changebar}\n\\cbcolor{blue}\n\\theoremstyle{definition}\n\\newtheorem{defi}{Definition}\n\\newtheorem{theo}{Theorem}\n\\newtheorem{prop}{Proposition}\n\\newtheorem{claim}{Claim}\n\\begin{document}\n\\section{Starting point}\nWe take a lattice\n\\[L=\\mathbb{Z}\\omega_1+\\mathbb{Z}\\omega_2,\\]\nfor some $\\omega_1,\\omega_2\\in\\mathbb{C}$ not on the same line. Then $\\mathbb{C}/L$ is topologically a torus.\n\nSince we're going to do differential geometry, we want to find an explicit map. We recall that the origin-centered torus is given parametrically as\n\\begin{align*}\n  x(\\theta,\\phi)&=(R+r\\cos(\\theta))\\cos(\\phi)\\\\\n  y(\\theta,\\phi)&=(R+r\\cos(\\theta))\\sin(\\phi)\\\\\n  z(\\theta,\\phi)&=r\\sin(\\theta),\n\\end{align*}\nwhere $0\\leq\\theta,\\phi\\leq 2\\pi$ and $R$ is the distance from the center of the tube to the center of the torus, and $r$ is the radius of the tube. We denote this torus by $\\mathbb{T}^2(R,r)$. If you plot $\\mathbb{T}^2(R,r)$ you'll notice that $\\theta$ specifies angle in relation to the center of the tube, and $\\phi$ specifies angle in relation to the center of the torus. As in the below picture:\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{theta_phi.png}\n\\end{figure}\n\nTo figure out the map from $\\mathbb{C}/L$ to $\\mathbb{T}^2(R,r)$ we essentially just have to figure out how to map a point on the ``parallellogram with sides identified'' to a point on $\\mathbb{T}^2(R,r)$ for some appropriate $R$ and $r$.\n\nThere are several ways of doing this, and here's but one. Let $F:\\mathbb{C}\\to\\mathbb{T}^2(1,1)$ be given by\n\\[F(\\alpha\\omega_1+\\beta\\omega_2)=(x,y,z)(\\alpha\\cdot2\\pi,\\beta\\cdot2\\pi).\\]\nSince $\\omega_1$ and $\\omega_2$ are linearly independent, this is well-defined, and since $\\cos$ and $\\sin$ are $2\\pi$-periodic, $F$ descends to a function $\\tilde{F}:\\mathbb{C}/L\\to\\mathbb{T}^2(R,r)$. It is clear that viewed as function from $\\mathbb{R}^2$ to $\\mathbb{R}^3$, $F$ is a diffeomorphism.\n\nBy the way, I'm making the gentle assumption that $\\omega_1$ and $\\omega_2$ are both in the first quadrant.\n\nExcellent, so let's now bring in some definitions from Spivak so that we can make sense of $\\mathrm{d}z$ -- the translation invariant one-form.\n\\section{Definitions from Spivak}\nWe begin with a $k$-dimensional manifold.\n\\begin{defi}\n  A subset $M\\subseteq\\mathbb{R}^n$ is called a $k$-dimensional manifold if for\n  every $x\\in M$ it holds that\n  \\begin{quotation}\n    there exists an open set $U\\ni x$ and an open set $V\\subseteq\\mathbb{R}^n$ and\n    a diffeomorphism $h:U\\to V$ such that\n    \\[h(U\\cap M)=V\\cap(\\mathbb{R}^k\\times\\{\\mathbf{0}\\}).\\]\n  \\end{quotation}\n\\end{defi}\nTo see that $\\mathbb{T}^2(R,r)$ is a $2$-manifold, we have to think a little bit. Take $v\\in M$ arbitrary, say with $v=(x(\\theta',\\phi'),y(\\theta',\\phi),z(\\theta',\\phi'))$ with $0\\leq\\theta',\\phi<2\\pi$. Let $0\\leq\\epsilon<\\pi/4$ be arbitrary and put\n\\[P=\\{(x(\\theta'+2\\pi\\delta_{\\theta',0}+s,\\phi'+t),y(\\theta'+2\\pi\\delta_{\\theta',0}+s,\\phi'+t),z(\\theta'+2\\pi\\delta_{\\theta',0}+s,\\phi'+t)):-\\epsilon<s,t<\\epsilon\\}.\\]\nHere $P$ stands for ``patch''. Let\n\\[w=(x(\\pi/2,\\phi'),y(\\pi/2,\\phi'),z(\\pi/2,\\phi')),\\]\nand let\n\\[U=\\{p+rw:p\\in P,-1/2<r<1/2\\}.\\]\nHence $U\\cap M=P$. I take as geometrically clear that $U$ is indeed an open set. Let now\n\\[V=\\{(s,t,u):-\\epsilon<s,t<\\epsilon,-1/2<u<1/2\\},\\]\nand define $h:U\\to V$ by\n\\[h(x(\\theta'+2\\pi\\delta_{\\theta',0}+s,\\phi'+t)+rw_1,y(\\theta'+2\\pi\\delta_{\\theta',0}+s,\\phi'+t)+rw_2,z(\\theta'+2\\pi\\delta_{\\theta',0}+s,\\phi'+t)+rw_3)=(s,t,r).\\]\nSince any point in in $U$ is determined uniquely by the parameters $s$, $t$, and $r$, we have that $h$ is well-defined, and some first year calculus shows that it's smooth.\n\nWe see that\n\\[h(U\\cap M)=h(P)=\\{(s,t,0):-\\epsilon<s,t<\\epsilon\\}=V\\cap\\mathbb{R}^2\\times\\{0\\},\\]\nand so we conclude that $\\mathbb{T}^2(R,r)$ indeed is a $2$-manifold.\n\nI will take the view that $\\mathbb{C}/L$ is simply identified with $\\mathbb{T}^2(1,1)$ through $\\tilde{F}$. This is because Spivak doesn't include an ambient space. {\\tt Frankly, when giving the talk I will probably just use Lee's ``Smooth Manifolds'' instead or better yet Wells' ``Differential Analysis on Complex Manifolds'' because it's a bit difficult to translate notions all the time. On the other hand, Wells' and Lee kind of go off the deep end into some algebraic geometry. So there's that.}\n\nBefore continuing to {\\it forms}, let's talk about coordinate systems. Spivak gives the following theorem.\n\\begin{theo}\n  A subset $M$ of $\\mathbb{R}^n$ is a $k$-dimensional manifold iff for every $x\\in M$ the following condition is satisfied:\n  \\begin{quotation}\n    There is an open set $U\\ni x$ and an open set $W\\subseteq\\mathbb{R}^k$ and an injective smooth function $f:W\\to\\mathbb{R}^n$ such that\n    \\begin{enumerate}\n      \\item $f(W)=M\\cap U$,\n      \\item $f'(y)$ has rank $k$ for every $y\\in W$,\n      \\item $f^{-1}:f(W)\\to W$ is continuous.\n    \\end{enumerate}\n  \\end{quotation}\n  Such a function $f$ is called a coordinate system around $x$.\n\\end{theo}\nI'm pretty sure that in modern terminology -- this corresponds to having an atlas.\n\\section{Forms}\nBefore we treat forms on manifolds, we need to recall what forms are in Euclidean space. For this, we need the concept of tensors, alternating tensors, and the wedge product. From Spivak's point of view, this isn't too bad. {\\tt Although he seems to consciously skip the concept of vector and tangent bundles, which makes it a bit harder to define things.}\n\nLet's start with tensors.\n\\begin{defi}[Tensor]\n  Let $V$ be an $\\mathbb{R}$-vector space, and let $k$ be a positive integer. Then a $k$-tensor on $V$ is a multilinear function $T:V^k\\to\\mathbb{R}$. The set of all $k$-tensors on $V$ is denoted by $\\mathcal{T}^k(V)$. It forms a vector space given\n  \\[(S+T)(v)=S(v)+T(v),\\]\n  and\n  \\[(rS)(v)=rS(v),\\]\n  for $S,T\\in\\mathcal{T}^k(V)$ and $r\\in\\mathbb{R}$ and $v\\in V$.\n\\end{defi}\nIn other words, $\\mathcal{T}^k(V)=(V^k)^\\vee$. If $T\\in\\mathcal{T}^k(V)$ it's called {\\it alternating} if\n\\[T(v_1,\\dots,v_i,\\dots,v_j,\\dots,v_k)=-T(v_1,\\dots,v_j,\\dots,v_i,\\dots,v_k),\\]\nfor any $i<j$. The space of all alternating $k$-tensors on $V$ is denoted by $\\Lambda^k(V)$.\n\nIn this setting, the tensor product $\\otimes$ is defined as follows.\n\\begin{defi}\n  Let $V$ be an $\\mathbb{R}$-vector space. Let $S\\in\\mathcal{T}^k(V)$ and $T\\in\\mathcal{T}^l(V)$. Then we define\n  \\[(S\\otimes T)(v_1,\\dots,v_k,v_{k+1},\\dots,v_{k+l})=S(v_1,\\dots,v_k)T(v_{k+1},\\dots,v_{k+l}),\\]\n  and notice $S\\otimes T\\in\\mathcal{T}^{k+l}(V)$.\n\\end{defi}\nWe can construct alternating tensors from tensors using the $\\mathrm{Alt}$-map, defined as follows. Let $T\\in\\mathcal{T}^k(V)$, then put\n\\[\\mathrm{Alt}(T)(v)=\\frac{1}{k!}\\sum_{\\sigma\\in S_k}\\mathrm{sgn}(\\sigma)T(\\sigma.v),\\]\nwhere $\\sigma$ acts by permutating the canonical basis. Clearly $\\mathrm{Alt}$ is a generalization of the determinant.\n\nIt's a fact that if $T\\in\\mathcal{T}^k(V)$ then $\\mathrm{Alt}(T)\\in\\Lambda^k(V)$ and $\\mathrm{Alt}(\\mathrm{Alt}(T))=T$, and if $\\omega\\in\\Lambda^k(V)$, then $\\mathrm{Alt}(\\omega)=\\omega$.\n\nWe can form products also on the space of alternating tensors.\n\\begin{defi}[Wedge product]\n  Let $\\omega\\in\\Lambda^k(V)$ and $\\eta\\in\\Lambda^l(V)$ for some $\\mathbb{R}$-vector space. Then we define\n  \\[\\omega\\land\\eta=\\frac{(k+l)!}{k!l!}\\mathrm{Alt}(\\omega\\otimes\\eta).\\]\n  It holds that $\\omega\\land\\eta\\in\\Lambda^{k+l}(V)$.\n\\end{defi}\nWe can use the wedge product to get a basis for $\\Lambda^k(V)$.\n\\begin{prop}\n  Let $\\{e_i\\}_{i=1}^n$ be a basis for $V$. Then\n  \\[e_{i_1}^\\vee\\land\\dots\\land e_{i_k}^\\vee,\\]\n  where $1\\leq i_1<i_2<\\dots<i_k\\leq n$, forms a basis for $\\Lambda^k(V)$.\n\\end{prop}\n\nNow we're really close to defining forms. First we need the concept of a tangent space.\n\\begin{defi}[Tangent space]\n  Let $n$ be a positive integer and let $p\\in\\mathbb{R}^n$. Then we define\n  \\[\\mathbb{R}^n_p=\\{(p,v):v\\in\\mathbb{R}^n\\},\\]\n  and $(p,v)+(p,w)=(p,v+w)$ and $a(p,v)=(p,av)$. This turns $\\mathbb{R}^n_p$ into a vector space, which we call the tangent space at $p$.\n\n  We usually write $v_p$ for $(p,v)$.\n\\end{defi}\nWe will probably need the notion of vector fields, so I'll define that too.\n\\begin{defi}[Vector field]\n  A vector field is a function\n  \\[F:\\mathbb{R}^n\\to\\bigsqcup_{p\\in\\mathbb{R}^n}\\mathbb{R}^n_p,\\]\n  such that $F(p)\\in\\mathbb{R}^n_p$ for every $p\\in\\mathbb{R}^n$.\n\\end{defi}\nNotice that $(e_i)_p$ is a basis for $\\mathbb{R}^n_p$, and thus we have\n\\[F(p)=\\sum_{i=1}^nF^i(p)(e_i)_p,\\]\nfor some component functions $F^i$. We call $F$ continuous or smooth if the $F^i$ are continuous or smooth; respectively.\n\nAnd here we go, now we can define a differential form.\n\\begin{defi}[Differential form]\n  A differential $k$-form on $\\mathbb{R}^n$ is a function $\\omega:\\mathbb{R}^n\\to\\bigsqcup_{p\\in\\mathbb{R}^n}\\Lambda^k(\\mathbb{R}^n_p)$ with $\\omega(p)\\in\\Lambda^k(\\mathbb{R}^n_p)$.\n\\end{defi}\nSince we know a basis for $\\Lambda^k(V)$, we see that any $k$-form $\\omega$ can be written as\n\\[\\omega(p)=\\sum_{1\\leq i_1<\\dots<i_k\\leq n}\\omega_{i_1,\\dots,i_k}(p)\\phi_{i_1}(p)\\land\\dots\\land\\phi_{i_k}(p),\\]\nfor some coefficients $\\omega_{i_1,\\dots,i_k}(p)\\in\\mathbb{R}$, and $\\phi_i=(e_i)_p^\\vee$.\n\nIf the coefficient functions $p\\mapsto\\omega_{i_1,\\dots,i_k}(p)$ are continuous or smooth, then we call the $k$-form $\\omega$ continuous, or smooth; respectively.\n\nSuppose now that $f:\\mathbb{R}^n\\to\\mathbb{R}$ is smooth.\n\\begin{claim}\n  Then $Df(p)\\in\\Lambda^1(\\mathbb{R}^n)$.\n\\end{claim}\n\\begin{proof}\n  By definition $Df(p)=\\lambda:\\mathbb{R}^n\\to\\mathbb{R}$ is the unique linear transformation satisfying\n  \\[\\lim_{h\\to 0}|f(p+h)-f(h)-\\lambda(h)|/|h|=0.\\]\n  So $\\lambda$, because it's linear, is a $1$-tensor. But then it's alternating (vacuously).\n\\end{proof}\nUsing this, we can define $df$, for $f:\\mathbb{R}^n\\to\\mathbb{R}$ smooth.\n\\begin{defi}\n  Let $f:\\mathbb{R}^n\\to\\mathbb{R}$ be smooth. Then we define $df:\\mathbb{R}^n\\to\\bigsqcup_{p\\in\\mathbb{R}^n}\\Lambda^1(\\mathbb{R}^n_p)$ by\n  \\[df(p)(v_p)=Df(p)(v).\\]\n\\end{defi}\nLet in particular $\\pi^i:\\mathbb{R}^n\\to\\mathbb{R}$ be defined by $\\pi^i(x)=x^i$. Notice now that\n\\[d\\pi^i(p)(v_p)=D\\pi^i(p)(v)=e_i^Tv=v^i,\\]\nSo $d\\pi^i(p)((e_j)_p)=[i=j]$, so $d\\pi^i(p)=(e_i)_p^\\vee$. Usually we write $x^i$ for $\\pi^i$, and thus any differential $k$-form can be written as\n\\[\\omega(p)=\\sum_{1\\leq i_1<\\dots<i_k\\leq n}\\omega_{i_1,\\dots,i_k}(p)dx^{i_1}\\land\\dots\\land dx^{i_k}.\\]\nWhen defining differential forms on manifolds, we want to induce smooth functions $\\mathbb{R}^n\\to\\mathbb{R}^m$ to linear transformations $\\mathbb{R}^n_p\\to\\mathbb{R}^n_{f(p)}$. This is how we do it.\n\\begin{defi}\n  Let $f:\\mathbb{R}^n\\to\\mathbb{R}^m$ be a smooth. Then we define $f_\\ast:\\mathbb{R}^n_p\\to\\mathbb{R}^m_{f(p)}$ by\n  \\[f_\\ast(v_p)=(Df(p)(v))_{f(p)}.\\]\n\\end{defi}\n\\begin{claim}\n  It makes sense.\n\\end{claim}\n\\begin{proof}\n  We have that $Df(p)$ is a linear transformation $\\mathbb{R}^n\\to\\mathbb{R}^m$, so $Df(p)(v)\\in\\mathbb{R}^m$ and thus $(Df(p)(v))_{f(p)}$. Linearity should be fine.\n\\end{proof}\nFrom $f_\\ast$ we can induce further, to get a transformation\n\\[f^\\ast:\\Lambda^k(\\mathbb{R}^m_{f(p)})\\to\\Lambda^k(\\mathbb{R}^n_p),\\]\nin the usual way -- that is:\n\\[f^\\ast(\\omega)=\\omega\\circ f_\\ast.\\]\n\\begin{claim}\n  This also makes sense.\n\\end{claim}\n\\begin{proof}\n  Take $v_p\\in\\mathbb{R}^n_p$, then $f_\\ast(v_p)\\in\\mathbb{R}^m_{f(p)}$, so is in the domain of $\\omega$. Cool, we're fine.\n\\end{proof}\nThat's all we need for forms. So let's go to {\\Huge\\tt manifold town!}\n\\section{Forms on manifolds}\nLet $M$ be a $k$-dimensional in $\\mathbb{R}^n$ and let $f:W\\to\\mathbb{R}^n$ be a coordinate system around $x=f(a)$.\n\\begin{claim}\n  It holds that $f_\\ast:\\mathbb{R}^k_a\\to\\mathbb{R}^n_x$ is injective, and $f_\\ast(\\mathbb{R}^k_a)$ is $k$-dimensional subspace of $\\mathbb{R}^n_x$.\n\\end{claim}\n\\begin{proof}\n  We have that $f_\\ast(v_a)=(Df(a)(v))_x$. Since $f'(a)$ has rank $k$, the linear transformation $Df(a):W\\to\\mathbb{R}^k$ is an isomorphism. Therefore, $(Df(a)(v))_x=0$ implies $Df(a)(v)=0$ implies $v=0$ implies $v_a=0$. So also $f_\\ast$ is injective.\n\n  It's not surjective, but at least $f_\\ast(\\mathbb{R}^k_a)$ is an isomorphic copy of $\\mathbb{R}^k_a$, so it is of dimension $k$.\n\\end{proof}\nLet $g:V\\to\\mathbb{R}^n$ be any other coordinate system around $x=g(b)$. {\\tt We assume, I think WLOG, that the $U\\ni x$ is the same for both.}\n\\begin{claim}\n  Its range is the same.\n\\end{claim}\n\\begin{proof}\n  \\cbstart\n  Let's first prove that $g_\\ast=f_\\ast\\circ(f^{-1}\\circ g)_\\ast$. This follows basically by the chain rule. Note that\n  \\[f^{-1}(g(b))=f^{-1}(x)=a,\\]\n  and therefore\n  \\[Df(a)D(f^{-1}\\circ g)(b)=Df(f^{-1}(g(b)))D(f^{-1}\\circ g)(b)=D(f\\circ(f^{-1}\\circ g))(b)=Dg(b).\\]\n  This means that\n  \\[f_\\ast(f^{-1}\\circ g)_\\ast(v_b)=f_\\ast((D(f^{-1}\\circ g)(b)v)_a)=(Df(a)(D(f^{-1}\\circ g)(b)v))_x=(Dg(b)v)_x=g_\\ast(v_b).\\]\n  Let's now take a peek at\n  \\[(f^{-1}\\circ g)_\\ast(\\mathbb{R}^k_b).\\]\n  We have that\n  \\[(f^{-1}\\circ g)_\\ast(\\mathbb{R}^k_b)=\\{(Df^{-1}g(b)\\circ Dg(b)v)_a:v\\in\\mathbb{R}^k\\}.\\]\n  Since $Dg(b)$ has rank $k$, we have that $Dg(b)v$ spans a $k$-dimensional subspace of $\\mathbb{R}^n$. Since $Df(a)$ has rank $k$, it should be the case that $Df^{-1}(g(b))$ (which exists because reasons) also has rank $k$, and thus $Df^{-1}(g(b))Dg(b)v$ should be $k$-dimensional, and thus $\\mathbb{R}^k$ itself.\n  \\cbend\n\n  {\\tt BTW:} The correct way is to say that $(g^{-1}\\circ f)_\\ast$ is an inverse to $(f^{-1}\\circ g)_\\ast$. No smoothness needed!\n\\end{proof}\n{\\tt Fishy argument. I need to fix this.}\n\nThe best way to fix this is to just use Lee. But, I'll let it slide for now. Let's just assume that it works. {\\tt Damn it!}\n\n{\\tt Found a fix in ``Comprehensive Introduction'' volume 1. Yes!}\n\nIf $f:W\\to\\mathbb{R}^n$ is a coordinate system. We write\n\\[M_x=f_\\ast(\\mathbb{R}^k_a),\\]\nand call this the tangent space of $M$ at $x$. We can now define a differential $p$-form.\n\\begin{defi}[Form on a manifold]\n  Let $\\omega:M\\to\\bigsqcup_{x\\in M}\\Lambda^p(M_x)$ satisfy $\\omega(x)\\in\\Lambda^p(M_x)$ for every $x\\in M$. Then we call $\\omega$ a $p$-form on $M$.\n\n  If $f:W\\to\\mathbb{R}^n$ is a coordinate system, then $f^\\ast\\omega$ is a $p$-form on $W$, and we say that $\\omega$ is smooth if $f^\\ast\\omega$ is.\n\\end{defi}\nNext Spivak claims we can write $\\omega$ as\n\\[\\omega=\\sum_{1\\leq i_1<\\dots<i_p\\leq n}\\omega_{i_1,\\dots,i_p}dx^{i_1}\\land\\dots\\land dx^{i_p},\\]\nand this means we need to make sense of\n\\[dx^{i_j}(p),\\]\nfor $p\\in M$. Can we? Previously we defined it as\n\\[d\\pi^i(v)(w\\in M_x)=D\\pi^i(v)(w),\\]\nbut we probably need to use coordinate systems now.\n\nAnd yes we do, but recall that $M_x=f_\\ast(\\mathbb{R}^k_a)$ actually sits inside $\\mathbb{R}^n_x$, so we in fact use the same $d\\pi^i$ as before.\n\nBut, when we want to carry over $dz$ to $\\mathbb{T}^2$ we get a problem. It's the case that\n\\[f_\\ast(\\mathbb{R}^2_a)\\subset\\mathbb{R}^3_x,\\]\nso we can impossible make sense of $(dx,dy)$, because $dx$ and $dy$ only make sense in $\\mathbb{R}^2_x$. Here's where our grand plan stops making sense.\n\\end{document}\n", "meta": {"hexsha": "feca4fcf0ae781b360e9d9393ded1cea32b22924", "size": 15152, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk1/manuscript.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/manuscript.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/manuscript.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": 61.0967741935, "max_line_length": 501, "alphanum_fraction": 0.6677666315, "num_tokens": 5713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.6619415102686059}}
{"text": "Machine learning (ML) is the study of algorithms and mathematical models with a feature of progressively improve a performance on a specific task. Machine learning is a subfield of Artificial Intelligence (AI). The main difference between Artificial Intelligence and Machine learning is that machine learning performance results primary depends on the data set and it makes data driven decisions while Artificial Intelligence involves agents at the top. Another subfield of machine learning is Deep Learning that uses a cascade of multiple layers of nonlinear processing units for feature extraction and transformation. Hierarchy representation of Artificial Intelligence, Machine Learning and Deep Learning could be seen in the \\ref{fig:ml_hierarchy} figure.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Pictures/ml_hierarchy.png}\n\\caption{\\label{fig:ml_hierarchy}{}Hierarchy representation of AI, ML and Deep Learning}\n\\captionsetup{font={footnotesize,bf,it}}\n\\caption*{Source: https://www.codesofinterest.com/2016/11/difference-artificial-intelligence-machine-learning-deep-learning.html}\n\\end{figure}\n\n\nMachine learning models is divided into two types:\n\n\\begin{enumerate}\n    \\item \\textbf{Supervised learning} - is the machine learning task of learning a function that maps an input to an output based on example input-output pairs.\n    \\item \\textbf{Unsupervised learning} - is the machine learning tasks that learns from test data that has not been labeled, classified or categorized.\n\\end{enumerate}\n\n\n\n\n\\subsection{Supervised Learning}\n\nSupervised Machine learning models are all about finding appropriate representations for their input data and it requires 3 things:\n\\begin{enumerate}\n    \\item \\textbf{Input data}. A good data set is the key of creating good Machine Learning model. The input data depends on the problem which the developer want to solve - if the task is speech recognition, then the input data could be sound files converted to the form that computer could proceed, for example: binary. If the task is image tagging, then the data could be a pictures where each pixel is converted to the RGB (red-green-blue) format or HSV (hue-saturation-value) format. The input data depends on the problem and the final goal of the problem. \n    \\item \\textbf{Output data}. Output data in other words could be called as results of the input data. Supervised machine learning models should know the results of each data input entry point in order to find out a pattern which helps to predict a results. \n    \\item \\textbf{Validation}. Validation is a way to measure whether the algorithm is doing a good job to determine the distance between the algorithm's current output and its expected output. The validation for supervised machine learning models is split into 2 parts: training data and testing data. Training data is input data and output data which is used for machine learning model training and it from where model learns the patterns of the data which produce certain output. The testing data is used after the machine learning training and from this data the model is evaluated of how successfully it predicted the output results from the input data.\n\\end{enumerate}\n\n\nSupervised learning is grouped into two types:\n\n\\begin{enumerate}\n    \\item \\textbf{Classification} A classification type is when the output variable is representing a category\n    \\item \\textbf{Regression} A regression type is when the output variable is representing a real value\n\\end{enumerate}\n\n\\subsubsection{Classification}\n\nClassification is the process of predicting the class of given data points. Classes are usually named as a term of \\textbf{Labels}. Classification main goal is from given input data points predict an output which would mark a label. Classification predictive modeling: approximating a mapping function (f) from input variables (X) to discrete output variable (y). \n\n\nClassification Machine Learning algorithms:\n\n\\begin{enumerate}\n    \\item \\textbf{Linear Classifiers} is the statistical classification group of identifying classes of the object's characteristics. A linear classifier methods makes a classification decisions based on the values of a linear combinations of the characteristics. In this paper two linear classifiers would be described: \\textit{Logistic Regression} and \\textit{Naive Bayes Classifier}\n    \\begin{enumerate}\n        \\item \\textbf{Logistic Regression}\n        \\label{sssec:logistic_regression}\n        Logistic Regression is a statistical method for analysing a data set in which there are one or more independent variables that determine an measured(outcome) with a dichotomous variable. It predicts the probability of an outcome that have two values. \n        \n        The main goal of logistic regression is to find the best fitting model to describe relationship between the dichotomous characteristics of interest and a set of independent variables. \n        \n        Logistic regression generates a logistic curve (yellow color) (the Linear and logistic model representation figure \\ref{fig:logistic_regression}) which y-axis is limited to values between 0 and 1; [0, 1].\n        \n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width=0.8\\textwidth]{Pictures/logistic_regression.png}\n            \\caption{\\label{fig:logistic_regression}{} Linear model and Logistic model representation \\cite{16}}\n        \\end{figure}\n        \n        \\textbf{Logistic model} mathematical representation: $p = \\frac{1}{1 + e^-(b_{0} + b_{1}x)}$\n        \n        \\textbf{Linear model} mathematical representation: $y = b_{0} + b_{1}x$\n        \n        \\textbf{Logistic regression} could be expressed in the formula:\n        \n        \\begin{equation}\n             \\frac{p}{1 - p} = \\exp{b_{0} + b_{1}x}\n        \\end{equation}\n        \\begin{description}\n            \\item[$p$] Logistic Model \n            \\item[$b_{0}$] Logistic regression constant\n            \\item[$b_{1}$] The slope that defines the steepness of the curve\n        \\end{description}\n        \n        \\item \\textbf{Naive Bayes Classifier}. \n        \n        Naive Bayes classifier assumes that the presence of a particular feature in a class is unrelated to the presence of any other feature. Bayes theorem could be expressed in the mathematical equation:\n        \n        \\begin{equation}\n                P(A|B) = \\frac{P(B|A)P(A)}{P(B)}\n        \\end{equation}\n        \\begin{description}\n            \\item[$A$ and $B$] are events \n            \\item[$P(B)$] $\\ne 0$\n            \\item[$P(A | B)$] is a conditional probability: the likelihood of event $A$ occurring given that $B$ is true.\n            \\item[$P(B | A$] is also a conditional probability: the likelihood of event $B$ occurring given that $A$ is true.\n            \\item[$P(A)$ and $P(B)$] are the probabilities of observing $A$ and $B$ independently of each other; this is known as the marginal probability\n        \\end{description}\n        \n        Naive Bayes \\cite{BIB4} is effective in many practical applications including text classification, performance management and medical diagnosis. The effectiveness of Naive Bayes classifier comes from it is presence of feature dependencies: optimality in terms of zero-one loss (classification error) is not necessarily related to the quality of the fit to a probability distribution. \n        \n    \\end{enumerate}\n    \\item \\textbf{Support Vector Machines(SVM)} \n    \n    Support vector machine(SVM) is a discriminative classifier defined by a separating hyperplane. Hyperplane is a line dividing a plane i two parts where in two parts. SVM algorithm main objective is to find a optimal hyperplane in an N-dimensional (N - is the number of features) space that distinctly classifies the data points. \n    \n    When using Support Vector Machine it should be considered these parameters:\n    \n    \\begin{itemize}\n        \\item Input. Set of training pair samples. Call the input sample features $x_{1}, x_{2}...x_{n}$ and the output result y\n        \\item Output. Set of weights $w$. One for each feature, whose linear combination predicts the value of y\n    \\end{itemize}\n    \n    \n    \n    SVM usage in the real world applications:\n    \n    \\begin{itemize}\n        \\item Text and Hypertext categorization. SVM method could significantly reduce the need for labeled training instances in both the standard inductive and transductive settings.\n        \\item Classification of images. SVM achieve higher search accuracy than traditional query refinement schemes\n        \\item Biological and other sciences. SVM performed good results in classification of proteins schemes or classifying permutation tests.\n    \\end{itemize}\n    \n    \n    \\item \\textbf{Decision Trees}\n    \n    Decision tree are flowchart-like structures that classifies input data points or predict output values given inputs.\n    A decision tree is a decision-making device which assigns a probability to each of the possible choices based on the context of the decision: $P(f|h)$, where $f$ is an element of the set of choices and $h$ is the context of the decision. Probability $P(f|h)$ is determined by asking the sequence of questions $q_{1}, q_{2},...,q_{n}$ about the context, where the $ith$ question asked is uniquely determined by the answers to the $i - 1$ previous questions \\cite{BIB5}.\n    \n    \n    Decision tree builds classification or regression models in the form of a tree data structure. The data sets is break into smaller subsets. Decisions are represented as nodes and leaf nodes in the tree. \n    \n    A decision tree consist of three types of nodes:\n    \n    \\begin{enumerate}\n        \\item Decision nodes - represented by squares\n        \\item Chance nodes - represented by circles\n        \\item End nodes - represented by triangles\n    \\end{enumerate}\n    \n    Advantages of Decision trees classification:\n    \n    \\begin{itemize}\n        \\item Easy to understand and interpret because of the tree structure.\n        \\item The results could be achieved even with the little data. \n        \\item Could determine best, worst and expected values for different scenarios\n    \\end{itemize}\n    \n    Disadvantages of Decision trees classification:\n    \n    \\begin{itemize}\n        \\item It could be unstable. Small changes could imply large changes in the structure of the decision tree\n        \\item They are often relatively inaccurate comparing with others classification algorithms\n        \\item Information gain in decision trees is biased in favor of those attributes with more levels\n    \\end{itemize}\n\\end{enumerate}\n\n\\subsubsection{Regression}\n\nAnother type of Machine learning is called Regression. Regression algorithms tries predict a value for an input based on previous information. The main difference of classification type and regression type is that regression main goal is to estimate a value while classification type main goal is to estimate a class of an observation. \n\nRegression models have the following parameters and variables:\n\n\\begin{itemize}\n    \\item \\textbf{The unknown parameters}, denotes as $\\beta$, which may represent a scalar or a vector\n    \\item \\textbf{The dependent variable, Y}. This is a main factor that has to be understood and predicted.\n    \\item \\textbf{The independent variables, X}. This is a factor which have an impact on dependent variable\n\\end{itemize}\nA regression model relates Y to a function of X and $\\beta$: $Y \\approx f(X, \\beta)$\n\n\nRegression Machine Learning algorithms:\n\\begin{enumerate}\n    \\item \\textbf{Linear Regression}\n    \n    Linear regression \\cite{BIB6} is a technique that analyze the relationships between variables and how they contribute and related to producing a particular outcome. Linear regression establishes a relationship between \\textbf{dependent variable (Y)} and \\textbf{independent variables (X)} using straight line also known as regression line. \n    \n    Linear regression is represented in the formula:\n    \n    \\begin{equation}\n     Y = a + b\\times X + e\n    \\end{equation}\n    \\begin{description}\n        \\item[Y] Dependent variable \n        \\item[X] Independent variables\n        \\item[a] Intercept\n        \\item[b] Slope\n        \\item[e] Error term\n    \\end{description}\n    This equation represents of how Linear Regression method predicts value of target variable on given predictor variables.\n    \n    Example of the linear regression scatter plot could be seen in the figure \\ref{fig:linear_regression}. The black line consists of the predictions, the points are the data and the vertical lines between the points and  the black line represent errors of prediction.\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=0.55\\textwidth]{Pictures/linear_regression.png}\n        \\caption{\\label{fig:linear_regression}{}Scatter plot of the linear regression method \\cite{BIB17}}\n    \\end{figure}\n    \n    \n    Logistic regression \\tectbg{properties}:\n    \n    \\begin{itemize}\n        \\item Linear regression method requires linear relationship between independent variable (Y) and dependent variables X\n        \\item Linear regression results could be drastically dependent on Outliers. Outliers are the Data points that diverge in a big way from the overall pattern. \n        \\item Multicollinearity could increase the variance of the coefficient estimates and make the estimates sensitive to minor changes in the model. Multicollinearity is a statistical process in which predictor variables are correlated.\n    \\end{itemize}\n    \n    \\textbf{Advantages} of using logistic regression model:\n    \n    \\begin{itemize}\n        \\item Space complexity of the logistic regression model is low because it needs only to save the weights at the end of training\n        \\item Good interpretability, simple to understand\n        \\item Feature importance is generated at the time model building. Dimensionality reduction could be achieved by handling feature selection and by using hyperparameters \n    \\end{itemize}\n    \n    \\textbf{Disadvantages} of using logistic regression model:\n    \n    \\begin{itemize}\n        \\item Multicollinearity should be avoided\n        \\item Prone to outliers\n        \\item Linear regression assumes that the data is independent\n    \\end{itemize}\n    \n    \\item \\textbf{Polynomial Regression}\n    \n    Polynomial Regression method is the relationship between the \\textbf{independent variables X } and the \\textbf{dependent variable Y} which is modelled as an $nth$ degree polynomial. This method is good for handling non-linearly separable data. This method fits a nonlinear relationship between the value of x and the corresponding conditional mean of Y, denoted as $E(Y|X)$. \n    \n    $nth$ degree polynomial regression method could be described in the mathematical formula:\n    \\begin{equation}\n     Y = \\beta_{0} + \\beta_{1}x + \\beta_{2}x^2 + \\beta_{3}x^3 + ... + \\beta_{n}x^n + e\n    \\end{equation}\n    \\begin{description}\n        \\item[Y] Dependent variable \n        \\item[x] Independent variables\n        \\item[$\\beta$] Unknown parameters\n        \\item[e] Error term\n    \\end{description}\n    \n    Polynomial regression properties:\n    \\begin{itemize}\n        \\item Otherwise than linear regression, polynomial regression method could model non-linearly seperable data\n        \\item Full control over the modelling of feature variables\n        \\item Prone to over fitting if exponents are not selected according to model design.\n    \\end{itemize}\n    \n    Polynomial regression have few problems that should be taken to consideration before using this algorithm:\n    \\begin{enumerate}\n        \\item When the X values are large, the model could be leaded to the math overflow which could make results inaccurate.\n        \\item The parameters of the model are intertwined so that lead=s of having covariance and dependency cases between the X values.\n    \\end{enumerate}\n    \n    \\item \\textbf{Ridge Regression}\n    \n    Ridge regression is a remedial measure taken to alleviate multicollinearity amongst regression predictor variables in a model. By adding a degree of bias to the regression estimates, ridge regression reduces the standart errors rate. \n    \n    Ridge regression model formula:\n    \\begin{equation}\n     Y = X\\beta + e\n    \\end{equation}\n    \\begin{description}\n        \\item[Y] Dependent variable \n        \\item[X] Independent variables\n        \\item[$\\beta$] Regression coefficients to be estimated\n        \\item[e] Error term\n    \\end{description}\n    \n    \n    The presence of multicollinearity could be detected in a few ways:\n    \\begin{itemize}\n        \\item A regression coefficient is not significant even though variables should be correlated with dependent variable Y\n        \\item The regression coefficients changes dramatically if X independent variables are added or deleted\n        \\item X independent variables have high pairwise correlations\n    \\end{itemize}\n    \n    Features of ridge regression model:\n    \\begin{itemize}\n        \\item The assumption is the same as least squared regression\n        \\item The value of coefficients does not reach zero\n    \\end{itemize}\n    \n    \n    \\item \\textbf{Lasso Regression}\n    \n    Lasso regression \\cite{BIB7} method performs both variable selection and regularization in order to enhance the prediction. Lasso regression and ridge regression are similar methods but lasso regression is using an absolute value bias while ridge regression method is using squared value bias.\n    \n    The goal of lasso method is to obtain the subset of predictors that minimizes prediction error for a quantitative response variable. This is done by shrinking variables towards zero.\n    \n    The lasso estimate is defined by formula:\n    \n    $\\beta^{\\mathit{lasso}} = argmin \\sum_{i=1}^N(y_{i} - \\beta{0} - \\sum_{j=1}^P x_{ij}\\beta_{j})^2$ subject to $\\sum_{j=1}^P |\\beta_{j}| <= t$ \n    \n    Lasso regression translates each coefficient by a constant factor $\\lambda$, truncating at zero. This process is called \"soft thresholding,\" and is used in the context of wavelet-based smoothing.\n    \n    Lasso regression is often an effective technique for shrinkage and feature selection.\n    \n\\end{enumerate}\n\n\n\\subsection{Unsupervised Learning}\n\nUnsupervised machine learning clusters only need to have an input data which would be used for detecting a patterns of the data.  \n\n\\subsubsection{Clustering}\n\nClustering is a task of grouping a set of objects by their data property patterns. Clustering methods are used for identifying similar groups to entities of that group than those of the other groups. Clustering methods are diverse by their types:\n\\begin{enumerate}\n    \\item \\textbf{Centroid-based}\n    \n    Clustering model which is related to the notion of similarity is derived by the closeness of a data point to the centroid of the clusters. Using algorithms with this type it is important to know the number of clusters before grouping data.\n    \n    \\item \\textbf{Distributed-based}\n    \n    Clustering model which is based on the notion of how probable is it that all data points in the cluster belong to the same distribution. Distributed-based models tends more suffer from overfitting. \n    \n    \\item \\textbf{Connectivity-based}\n    \n    Clustering model which is based on the notion that the data points closer in data space exhibit more similarity to each other than the data points lying farther away. This model could be diverse into two approaches:\n    \\begin{enumerate}\n        \\item Classifying all data points into separate clusters and then aggregating them as the distance decrease.\n        \\item All data points are classified as a single cluster and then partitioned as the distance increases.\n    \\end{enumerate}\n    Models are very easy to interpret but lacks scalability for handling big data sets\n    \n    \\item \\textbf{Density-based}\n    \n    Clustering model which is search the data space for areas of varied density of data points in the data space. It isolates various different density regions and assign the data points within these regions in the same cluster.\n    \n\\end{enumerate}\n\n\n\\begin{enumerate} \n\n    \\item \\textbf{K-Means Clustering}\n    \n    K-mean is a centroid model based clustering algorithm which the main goal is to partition the inputs into sets $S1,...,S_{k}$ in a way that minimizes the total sum of squared distances from each point to the mean of its assigned cluster. $k$ representing the number of clusters. \n    \n    K-means \\cite{BIB8} clustering abstract algorithm:\n    \n    \\begin{enumerate}\n        \\item Decide on a value for K, the number of clusters\n        \\item Initialize the K cluster centers \n        \\item Decide the class memberships of the N objects by assigning them to the nearest cluster center\n        \\item Re-estimate the K cluster centers, by assuming the memberships found above are correct\n        \\item Repeat c and d until none of the N objects changed membership in the last iteration\n    \\end{enumerate}\n    \n    \\textbf{Advantages} of K-mean clustering :\n    \\begin{itemize}\n        \\item K-mean clustering is fast. Computing the distances between points and group centers requires few computations. The linear complexity of the algorithm is \\textbf{O(n)}\n        \\item An instance could move to another cluster when the centroids are recomputed\n        \\item Converges to local minimum of within-cluster squared error\n    \\end{itemize}\n    \n    \n    \\textbf{Disadvantages} of K-mean clustering:\n    \\begin{itemize}\n        \\item The exact number of clustering groups/classes should be known before using k-means clustering algorithm \n        \\item K-means starts with a random choice of cluster centers and it could perform different results for each algorithm run\n        \\item The order of the data has an impact to the final results\n        \\item Sensitive to outliers\n        \\item Detects spherical clusters only\n    \\end{itemize}\n    \n    \n    \\item \\textbf{Mean-Shift Clustering}\n    \n    Mean-shift \\cite{BIB9} clustering algorithm is a non parametric clustering technique which does not require prior knowledge of the number of clusters and does not constrain the shape of the clusters. \n    \n    \n    \\begin{equation}\n        K(x) = \n        \\left \\{\n          \\begin{tabular}{ccc}\n          1 if ||x|| <= \\lambda \\\\\n          0 if ||x|| > \\lambda \n          \\end{tabular}\n        \\right \\}\n    \\end{equation}\n    \\begin{description}\n         Let data be a finite set $S$ embedded in the n-dimensional Euclidean space, $X$. Let $K$ be a flat kernel that is the characteristic function of the $\\lambda$-ball in $X$\n    \\end{description}\n    The sample mean at x \\in X is:\n    \n    \\begin{equation}\n        m(x) = \\frac{\\Sigma_{s \\in S} K(s-x)s}{\\Sigma_{s \\in S} K(s-x)}\n    \\end{equation}\n    \n    The difference $m(x) - x$ is called \\textit{mean shift}. In each iteration of the algorithm, $s \\Leftarrow m(s)$ is performed for all $s \\in S$ simultaneously. The mean shift vector always points toward the direction of the maximum increase in the density.\n    \n    Mean-shift clustering abstract algorithm:\n    \\begin{enumerate}\n        \\item Circular sliding window centered at a randomly selected point $C$ and having radius $r$ as the kernel. \n        \\item At every iteration the sliding window is shifted towards regions of higher density by shifting the center points to the mean of the points withing the window while there is direction at which a shift can accommodate more points inside the kernel\n        \\item  This process of steps (a) and (b) is done with many sliding windows until all points lie within a window.\n    \\end{enumerate}\n    \n    \n    \\textbf{Advantages} of Mean-Shift clustering:\n    \\begin{itemize}\n        \\item Model free - does not assume any prior shape on data clusters\n        \\item It requires single parameter of window size $h$\n        \\item Robust to outliers\n    \\end{itemize}\n    \n    \\textbf{Disadvantages} of Mean-Shift clustering:\n    \\begin{itemize}\n        \\item Results depends on window size\n        \\item Window size selection is not trivial\n        \\item Computationally expensive\n        \\item Does not scale well with dimension of feature space\n    \\end{itemize}\n    \n    \\item \\textbf{Density-Based Spatial Clustering of Applications with Noise (DBSCAN)}\n    \n    Density-Based Spatial Clustering of Applications with Noise (DBSCAN) is a density based clustering algorithm. Given a set of points in some space, it groups together points that are closely packed together, marking as outliers points that lie alone in low-density regions. Overall average complexity of DBSCAN clusetering algorithm is \\textbf{O(log n)}.\n    \n    DBSCAN abstract algorithm:\n    \\begin{enumerate}\n        \\item Find the points in the $\\epsilon$ neighborhood of every point, and identify the core points with more than $minPts$ neighbors\n        \\item Find the connected components of core points on the neighbor graph, ignoring all non-core points\n        \\item Assign each non-core point to a nearby cluster if the cluster is an $\\epsilon$ neighbor, otherwise assign it to noise\n    \\end{enumerate}\n    \n    \n    \\textbf{Parameters}  of DBSCAN clustering algorithm:\n    \\begin{itemize}\n        \\item $MinPoints$: The minimum number of points to form a dense region \n        \\item $\\epsilon$: The minimum distance between two points. The points are considered neighbors if the distance between two points is lower or equal to $\\epsilon$ value\n    \\end{itemize}\n    \n    \n    \\textbf{Advantages} of DBSCAN clustering algorithm:\n    \\begin{itemize}\n        \\item DBSCAN does not require one to specify the number of clusters in the data\n        \\item DBSCAN can find arbitrarily shaped clusters\n        \\item DBSCAN has a notion of noise, and is robust to outliers\n        \\item DBSCAN requires just two parameters and is mostly insensitive to the ordering of the points in the database\n        \\item DBSCAN is designed for use with databases that can accelerate region queries, e.g. using an R* tree\n    \\end{itemize}\n    \n    \n    \\textbf{Disadvantages} of DBSCAN clustering algorithm:\n    \\begin{itemize}\n        \\item DBSCAN is not entirely deterministic: border points that are reachable from more than one cluster can be part of either cluster, depending on the order the data are processed\n        \\item The results of DBSCAN model depends on the distance measure\n        \\item DBSCAN cannot cluster data sets well with large differences in densities\n        \\item Choosing a meaningfull distance treshhold $\\epilepson$ could be difficult if the data is not proper for this algorithm\n    \\end{itemize}\n    \n    \n    \n    \\item \\textbf{Expectation–Maximization (EM) Clustering}\n    \n    The Expectation–Maximization clustering algorithm is an iterative method to find maximum likelihood or maximum a posteriori (MAP) which computes probabilities of cluster memberships based on one or more probability distributions. The goal of the EM clustering algorithm is to maximize the overall probability or likelihood of the data.\n    \n    \n    The EM algorithm seeks to find the MLE of the marginal likelihood by iteratively applying these two steps:\n    \\begin{enumerate}\n        \\item Expectation step (E step): Define $\\Theta(\\theta|\\theta^{(t)})$ as the expected value of the log likelihood function of $theta$, with respect to the current conditional distribution of $Z$  given $X$  and the current estimates of the parameters $\\theta^{(t)$:\n        \\begin{equation}\n            \\Theta(\\theta|\\theta^{(t)}) = E_{Z|X_{1}\\theta^{(t)}}[\\log L(\\Theta;X;Z)]\n        \\end{equation}\n        \\item Maximization step (M step): Find the parameters that maximize this quantity:\n        \\begin{equation}\n            \\theta^{(t+1)} = arg max_\\theta \\Theta(\\theta|\\theta^{(t)}\n        \\end{equation}\n    \\end{enumerate}\n    \n    \\begin{description}\n        \\item [X] Observed data\n        \\item [Z] a set of unobserved latent data or missing values $Z$ \n        \\item [$\\theta$] a vector of unknown parameters\n        \\item [$L(\\theta,X, Z)$] likelihood function\n    \\end{description}\n    \n    \n    Expectation–Maximization abstract algorithm:\n    \\begin{enumerate}\n        \\item Initialize the parameters $\\theta$ to some random values\n        \\item Compute the probability of each possible value of $Z$, given $\\theta$\n        \\item Use the just-computed values of $Z$  to compute a better estimate for the parameters $\\theta$\n        \\item Iterate steps (b) and (c) until convergence\n    \\end{enumerate}\n    \n    \n    \\textbf{Advantages} of Expectation–Maximization clustering algorithm:\n    \\begin{itemize}\n        \\item Likelihood is guaranteed to increase for each iteration\n        \\item Is a derivative-free optimizer\n        \\item Is fast if analytical expressions for the M-step are available\n        \\item Parameter constraints are often dealt with implicitly\n    \\end{itemize}\n    \n    \n    \n    \\textbf{Disadvantages} of Expectation–Maximization clustering algorithm:\n    \\begin{itemize}\n        \\item Requires both forward and backward probabilities\n        \\item Significant implementational effort required compared to numerical optimization\n        \\item I Convergence may be slow if analytical expressions for the M-step are not available since numerical optimization must be applied\n        \\item Hessian must be calculated manually\n    \\end{itemize}\n    \n    \n    \n    \\item \\textbf{Hierarchical Clustering}\n    \n   Hierarchical clustering \\cite{BIB10} is a method of cluster analysis which seeks to build a hierarchy of clusters. Hierarchical clustering algorithm run once and create a dendrogram which is a tree structure containing a k-block set partition for each value of k between 1 and n, where n is the number of data points to cluster allowing the user to choose a particular clustering. \n   \n   \n   Hierarchical clustering consist of two types:\n   \\begin{enumerate}\n       \\item \\textbf{Agglomerative}:  This is a \"bottom-up\" approach: each observation starts in its own cluster, and pairs of clusters are merged as one moves up the hierarchy. Bottom-up algorithms treat each data point as a single cluster at the outset and then successively merge  pairs of clusters until all clusters have been merged into a single cluster that contains all data points. The time complexity of this method is $O(n^3)$.\n       \\item \\textbf{Divisive}: This is a \"top-down\" approach: all observations start in one cluster, and splits are performed recursively as one moves down the hierarchy. Divisive clustering complexity is $O(2^n)$. \n   \\end{enumerate}\n    \n    \n    Agglomerative Hierarchical clustering abstract algorithm \\cite{BIB11}:\n    \\begin{enumerate}\n        \\item Compute the similarity between all the pairs of clusters\n        \\item Combine the foremost similar two clusters\n        \\item Update the similarity matrix to replicate the pairwise similarity between the new cluster and the original clusters\n        \\item Repeat steps b and c until only a single cluster remains\n    \\end{enumerate}\n    \n    \n    \\textbf{Advantages} of Hierarchical clustering algorithms:\n    \\begin{itemize}\n        \\item Hierarchical clustering does not require us to specify the number of clusters\n        \\item Algorithm is not sensitive to the choice of distance metric\n    \\end{itemize}\n    \n    \n    \\textbf{Disadvantages} of Hierarchical clustering algorithms:\n    \\begin{itemize}\n        \\item Sensitivity to noise and outliers\n        \\item Breaking large clusters\n        \\item Difficulty handling different sized clusters and convex shapes\n    \\end{itemize}\n    \n\\end{enumerate}\n\n\n\\subsubsection{Dimensionality reduction}\n\nDimensionality reduction \\cite{BIB13} is the transformation of high-dimensional data into a meaningful representation of reduced imensionality.Ideally, the reduced representation should have a dimensionality that corresponds to the intrinsic dimensionality of the data. The intrinsic dimensionality of data is the minimum number of parameters needed to account for the observed properties of the data.\n\n\nThe problem of dimeansionality reduction could be defined as follows: Data set is represented in a $n$ x $D$ matrix $X$ consisting of $n$ datavectors $x_{i} (i \\in {1, 2, ..., n})$ ) with dimensionality $D$. The data set has intrinsic dimensionality $d (where d < D)$, in mathematical terms, intrinsic dimensionality means that the points in data set $X$ are\nlying on or near a manifold with dimensionality $d$ that is embedded in the D-dimensional space. \nDimensionality reduction techniques transform dataset $X$ with dimensionality $D$ into a new data set $Y$ with dimensionality $d$, while retaining the geometry of the data as much as possible. High-dimensional data point is denoted by $x_{i}$ , where $x_{i}$ is the $i$th row of the D-dimensional data matrix $X$. The low-dimensional counterpart of $x_{i}$ is denoted by $y_{i}$ , where $y_{i}$ is the $i$th row of the d-dimensional data matrix $Y$. The data set $X$ is assumed as a zero-mean.\n\n\nThere are two components of dimensionality reduction:\n\\begin{enumerate}\n    \\item \\textbf{Feature selection}. The subset of the original set of variables are found to get a smaller subset which could be used to model the problem. This component is divided into three separate parts:\n    \\begin{enumerate}\n        \\item \\textit{Filter}. Filter out features with small potential to predict outputs. Filter operation could be expressed in mathematical representation:\n        \\begin{enumerate}\n            \\item Let $\\Phi$ be a current set of features\n            \\item Removing feature $\\phi_}k}(x)$ is possible only when:\n            \\begin{equation}\n                \\Tilde{P}(y|\\Phi|\\phi_{k}) \\approx \\Tilde{P}(y|\\Phi)\n            \\end{equation}\n            For all values of $\\phi_{k}, y$\n        \\end{enumerate}\n       \n        \\item \\textit{Wrapper}. Select features that directly optimize the accuracy of the classifier\n        \\item \\textit{Embedded}. Features are selected to add or be removed while building the model based on the prediction errors\n    \\end{enumerate}\n    \\item \\textbf{Feature extraction}. Reduces the data in a high dimensional space to a lower dimension space\n\\end{enumerate}\n\n\n\\textbf{Advantages} of Dimensionality Reduction:\n\\begin{itemize}\n    \\item Improves performance in data compression\n    \\item Reduces computation time\n    \\item Removes redundant features\n    \\item Hence reduced storage space\n\\end{itemize}\n\n\n\\textbf{Disadvantages} of Dimensionality Reduction:\n\\begin{itemize}\n    \\item It may lead to some amount of data loss.\n\\end{itemize}\n\n\n\\begin{enumerate}\n    \\item \\textbf{Principal Component Analysis (PCA)}\n    \n    Principal component analysis (PCA) is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables into a set of values of linearly uncorrelated variables called principal components. PCA is a linear transformation of $d$ dimensional input $x$ to $M$ dimensional feature vector $z$ such that under which the retained variance is maximal. It is also considered as the linear projection for which the sum of squares reconstruction cost is minimized. \n    \n    \n    \\textbf{Goals} of Principal Component Analysis (PCA):\n    \\begin{itemize}\n        \\item Simplification\n        \\item Data reduction\n        \\item Outlier Detection\n        \\item Variable selection\n        \\item Classification\n        \\item Prediction\n        \\item Unmixing\n    \\end{itemize}\n    \n    \n    Many of the goals of PCA are concerned with finding relationships between objects. PCA estimates the correlation structure of the variables. The importance of a variable in a PC model is indicated by the size of its residual variance. \n\n    \n    PCA \\cite{BIB14} in matrix form is the least squares model:\n    \\begin{equation}\n        X = 1\\Tilde{x} + TP' + E\n    \\end{equation}\n    \\begin{description}\n        \\item [$\\Tilde{x}$] Mean vector which is included in the model formulation\n        \\item [P'] Projection matrix. It is also called loading vector\n        \\item [T] Object coordinates in the plane. It is also called scoring vectors\n        \\item [X] The projection\n        \\item [E] The deviations between projections and the original coordinates are termed the residuals.\n    \\end{description}\n    \n    \n    \\item \\textbf{Linear Discriminant Analysis (LDA)}\n    \n    Linear Discriminant Analysis (LDA) \\cite{BIB15} is a method to find a linear combination of features that characterizes or separates two or more classes of objects or events. \n    \n    Given a data matrix $A \\in \\R^{N×n}$, classical LDA aims to find a transformation $G \\in \\R^{N×t}$ that maps each column $a_{i}$ of $A$, for $1 ≤ i ≤ n$, in the N-dimensional space to a vector $b_{i}$ in the $\\iota$-dimensional space. That is $G$ : $a_{i} \\in \\R \\Leftarrow b_{i} = G^T a_{i} \\in \\R^{\\iota} (\\iota < N)$. Equivalently, classical LDA aims to find a vector space $G$ spanned by {g$_{i}}^{\\iotai}_{i=1}$}, where $G = [g_{1},..., g_{\\iota}]$, such that each $a_{i}$ is projected onto $G$ by $(g^{T}_{1} · a_{i},..., g^{T} · a_{i})T \\in \\R^{\\iota}$.\n    \n    \n    Assume that the original data in $A$ is partitioned into $k$ classes as $A = {\\Pi_{1}, ... , \\Pi_{k}}$, where $\\Pi_{i}$ contains $n_{i}$ data points from the $i$th class, and $\\sum\\limits{i=1}^{k} n_{i} = n$. Classical LDA aims to find the optimal transformation $G$ such that the class structure of the original high-dimensional space is preserved in the low-dimensional space. In general, if each class is tightly grouped, but well separated from the other classes, the quality of the cluster is considered to be high. In discriminant analysis, two scatter matrices, called within-class ($S_{w}$) and between-class ($S_{b}$) matrices, are defined to quantify the quality of the cluster, as follows [4]: $S_{w} = \\sum\\limits{i=1}^{k} \\sum\\limits{x \\in \\Pi_{i}} (x − m_{i})(x − m_{i})T$, and $S_{b} = \\sum\\limits{i=1}^{k} n_{i}(m_{i} − m)(m_{i} − m)T$, where $m_{i} = \\frac{1}{n_{i}} \\sum\\limits{x \\in \\Pi_{i}} x$ is the mean of the $i$th class, and $m = \\frac{1}{n}\\sum\\limits{i=1}^{k} \\sum\\limits{x \\in \\Pi|{i}} x$ is the global mean. \n    \n    Notation:\n    \\begin{description}\n        \\item [$n$] number of instances in the data set\n        \\item [$k$] number of classes in the data set\n        \\item [$A_{i}$] $i$th instance in matrix representation\n        \\item [$a_{i}$] $i$th instance in vectors representation\n        \\item [$r$] r number of rows in $A_{i}$\n        \\item [$c$] number of columns in $A_{i}$\n        \\item [$N$] dimension of $a_{i} (N = r ∗ c)$\n        \\item [$\\Pi$] $j$th class in the data set\n        \\item [$L$] transformation matrix (left) by Two-Dimensional Linear Discriminant Analysis\n        \\item [$R$] transformation matrix (right) by Two-Dimensional Linear Discriminant Analysis\n        \\item [$I$] number of iterations in Two-Dimensional Linear Discriminant Analysis\n        \\item [$B_{i}$] reduced representation of $A_{i}$ by Two-Dimensional Linear Discriminant Analysis\n        \\item [$\\iota_{1}$] number of rows in $B_{i}$\n        \\item [$\\iota_{2}$] number of columns in $B_{i}$\n    \\end{description}\n    \n    \n    The goal of Linear Discriminant Analysis (LDA) is to project a data set onto a lower-dimensional space with good class-separability in order avoid overfitting and also reduce computational costs.\n    \n    \n    \\textbf{Pseudo algorithm} for using LDA approach:\n    \\begin{enumerate}\n        \\item Compute the $d$-dimensional mean vectors for the different classes from the data set\n        \\item Compute the scatter matrices\n        \\item Compute the eigenvectors ($e_{1},e_{2},...,e{d}$) and corresponding eigenvalues ($\\lambda_{1},\\lambda_{2},...,\\lambda_{d}$) for the scatter matrices\n        \\item Sort the eigenvectors by decreasing eigenvalues and choose $k$ eigenvectors with the largest eigenvalues to form a $d$×$k$ dimensional matrix $W$\n        \\item Use $d$×$k$ eigenvector matrix to transform the samples onto the new subspace. This can be summarized by the matrix multiplication: $Y$=$X$×$W$, where \n        \\begin{description}\n            \\item [X] is a $n$×$d$-dimensional matrix representing the $n$ samples\n            \\item [Y] are the transformed $n$×$k$-dimensional samples in the new subspace\n        \\end{description}\n    \\end{enumerate}\n    \n\\end{enumerate}\n\n\n\\subsubsection{Association analysis}\n\nAssociation analysis is a method which is useful for discovering relationships hidden in large data sets. The uncovered relationships can be represented in the form of sets of items present in many transactions, which are known as \\textbf{association rules} that represents relationships between two item sets. Association rule mining finds all rules in the database that satisfy some minimum support and minimum confidence constraints.\n\nOne of the real life examples in where association rules could be used is two items expression:\n\n\\textbf{Olives} \\rightarrow \\textbf{Wine}\n\nThe rule suggest a relationship between olives usage with wine because olives is well know a good pair with wine. \n\nAn \\textbf{association rule} \\cite{BIB12} is an implication expression of the form $X \\rightarrow Y$ , where $X$ and $Y$ are disjoint item sets, i.e., $X ∩ Y = ∅$. The strength of an association rule can be measured in terms of its support and confidence. Support determines how often a rule is applicable to a given data set, while confidence determines how frequently items in $Y$ appear in transactions that contain $X$. These metrics has an formal definitions:\n\n\\begin{equation}\n    Support, s(x \\rightarrow Y) = \\frac{\\delta(X \\cup Y)}{N}\n\\end{equation}\n\\begin{equation}\n    Confidence, c(x \\rightarrow Y) = \\frac{\\delta(X \\cup Y)}{\\delta(X)}\n\\end{equation}\n\n\\subsection{Machine Learning models evaluation}\nMachine Learning models performance could be evaluated of how well they are classifying websites categories. Evaluation scores is a first level indicator which lets to know of Machine Learning capabilities of predicting categories according to the primary training features data sets.\n\nMachine Learning models could predict website categories when training features set are fitted into model. After that model is fed with training features set and it outputs prediction set of predicted categories of websites. These predicted categories are compared with training labels set. Models predictions set and training labels set allows to generate evaluation scores and analysis of how well model is trained to predict categories of websites. \n\nCalculating models predictions scores, there are 4 special terms which appears in the formulas:\n\\begin{itemize}\n    \\item \\textbf{True Positives (TP)} - is an outcome where the model correctly predicts the positive class. Example of true positive condition: \\textit{Person with disease was diagnosed a disease}.\n    \\item \\textbf{True Negatives (TN)} - is a true negative is an outcome where the model correctly predicts the negative class. Example of true negative condition: \\textit{Person with no disease was not diagnosed a disease}.\n    \\item \\textbf{False Positives (FP)} - is a result that indicates a given condition exists, when it does not. A false positive error is a type I error where the test is checking a single condition, and wrongly gives an affirmative decision.  Example of false positive condition:: \\textit{Healthy person was diagnosed with a specific disease}. \n    \\item \\textbf{False Negatives (FN)} - is a test result that indicates that a condition does not hold, while in fact it does. A false negative error is a type II error occurring in a test where a single condition is checked for and the result of the test is erroneously that the condition is absent.  Example of false negative condition:: \\texit{Person with disease was diagnosed with no disease}.\n\\end{itemize}\n\nThere are several methods to evaluate machine learning models :\n\\begin{enumerate}\n    \n    \\item \\textbf{Accuracy score}\n    \n    Classification accuracy is the number of correct predictions made as a ratio of all predictions made.\n    \n    The accuracy score is calculated by formula:\n    \\begin{equation}\n        Accuracy = \\frac{TP + TN}{TP + TN + FP + FN}\n    \\end{equation}\n    \n    \\item \\textbf{Recall score}\n    \n    Recall score is the number of true positives divided by the number of true positives plus the number of false negatives.\n    \n    The recall score is calculated by formula:\n    \\begin{equation}\n        Recall = \\frac{TP}{TP + FN}\n    \\end{equation}\n    \n    \\item \\textbf{Precision score}\n    \n    Precision evaluation method determines of how precise/accurate machine learning model of how many positives predictions have been predicted of total predictions. Precision score is calculated by formula:\n    \\begin{equation}\n        Precision = \\frac{TP}{\\mathit{TP} + \\mathit{FP}}\n    \\end{equation}\n    \n    Precision is a good measure to determine, when the costs of False Positive is high. \n    \n    \n    \\item \\textbf{F1 score}\n    \n    F1 score is the harmonic mean of precision and recall taking both metrics into account. F1 score is calculated by formula:\n    \\begin{equation}\n        F1 = 2 * \\frac{Precision * Recall}{Precision + Recall}\n    \\end{equation}    \n    \\item \\textbf{Confusion Matrix}\n    \n    A confusion matrix is a technique for summarizing the performance of a classification algorithm. Confusion matrix is a method to better understand the performance of classification models. It is a summary of of prediction results on a classification models: The number of correct and incorrect predictions are summarized with count values and broken down by each class. This is the key to the confusion matrix.\n    \n    \n\n\\end{enumerate}\n", "meta": {"hexsha": "bce444a46cf64782bda1e9492391a72267620f7a", "size": 45739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/Main/ML.tex", "max_stars_repo_name": "lzomedia/URL-categorization-using-machine-learning", "max_stars_repo_head_hexsha": "db204571a2e86643581d46c2cc7bfc9d78827e53", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 47, "max_stars_repo_stars_event_min_datetime": "2018-01-29T23:24:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-04T20:18:12.000Z", "max_issues_repo_path": "Documentation/Main/ML.tex", "max_issues_repo_name": "lzomedia/URL-categorization-using-machine-learning", "max_issues_repo_head_hexsha": "db204571a2e86643581d46c2cc7bfc9d78827e53", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-06-25T11:44:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-05T20:11:33.000Z", "max_forks_repo_path": "Documentation/Main/ML.tex", "max_forks_repo_name": "lzomedia/URL-categorization-using-machine-learning", "max_forks_repo_head_hexsha": "db204571a2e86643581d46c2cc7bfc9d78827e53", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-05T16:42:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T23:27:09.000Z", "avg_line_length": 61.8094594595, "max_line_length": 1041, "alphanum_fraction": 0.7254421828, "num_tokens": 10349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6619317244352025}}
{"text": "\\subsection{Gradient Properties}\r\n\\noindent\r\nLet $f$ and $g$ be functions of multiple variables, let $\\vec{r}$ be a VVF, and let $c \\in \\mathbb{R}$.\r\n\\begin{enumerate}\r\n\t\\item $\\nabla(f \\pm g) = \\nabla f \\pm \\nabla g$\r\n\t\\item $\\nabla(cf) = c\\nabla f$\r\n\t\\item $\\nabla(fg) = f\\nabla g + g\\nabla f$\r\n\t\\item $\\nabla(f\\circ\\vec{r}(t)) = \\nabla f \\cdot \\vec{r}(t)$\r\n\\end{enumerate}", "meta": {"hexsha": "56202a671f00cb0b8fb103e9b3baa542fbe2e679", "size": 375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/gradientProperties.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/gradientProperties.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/gradientProperties.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": 41.6666666667, "max_line_length": 104, "alphanum_fraction": 0.6213333333, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6616526017630501}}
{"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{Cerebellum: Mathematical Preliminaries} \\author{Eric Purdy}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Probability Space}\n\nA finite probability space\\footnote{It is slightly more complicated to\n  define an infinite probability space, so we will assume that our\n  probability spaces are finite.} is a finite set $\\Omega$ together\nwith a function $P$ from $\\Omega$ to the real numbers $\\RR$, such that\n\\begin{itemize}\n\\item For all $\\omega \\in \\Omega$, $0 \\le P[\\omega] \\le 1$\n\\item $\\sum_{\\omega\\in \\Omega} P[\\omega] = 1$\n\\end{itemize}\n\nThe elements $\\omega$ of $\\Omega$ are called {\\em elementary events}.\nAn {\\em event} is a subset $S$ of $\\Omega$, and its probability is the\nsum of the probabilities of the elementary events that make it up:\n$$P[A] = \\sum_{\\omega \\in A} P[\\omega].$$ We say that the event $A$\nhappens if we pick a sample $\\omega$ from $\\Omega$ and $\\omega \\in A$,\nand that it does not happen if $\\omega \\notin A$.\n\nFor us, $\\Omega$ will generally be the space of all possible\nactivities of neurons in the brain at a single instant in time. One of\nthe most common events that we will be interested in is the event that\na particular neuron $s$ fires; there are many possible states of the\nbrain that include $s$ firing (for example, every single neuron in the\nbrain firing, or $s$ alone firing and no other neuron in the brain\nfiring), and these are the elementary events that make up the event\n``$s$ fires''.\n\n\\section{Random Variables}\n\nA random variable is a function $X$ from a finite probability space\n$\\Omega$ to some set. For our purposes, the set will always be $\\RR$,\nthe real numbers.\n\nFor a random variable $X$, and a real number $a \\in \\RR$, the event\nthat $X=a$ is just the subset of those $\\omega$ in $\\Omega$ such that\n$X(\\omega) = a$. The probability of this event is written as $P[X=a]$.\nIf we write just $P[X]$, this should be understood as a function that\nmaps values of $X$ to probabilities, i.e., $P[X](a) = P[X = a]$.\n\nIf $X$ and $Y$ are random variables, then so are $aX$, $X+Y$, $X-Y$,\n$X\\cdot Y$, and $\\frac{X}{Y}$. These are the functions \n\\begin{align*}\n(aX)(\\omega) &= a \\cdot X(\\omega)\\\\\n(X+Y)(\\omega) &= X(\\omega) + Y(\\omega)\\\\\n(X-Y)(\\omega) &= X(\\omega) - Y(\\omega)\\\\\n(X\\cdot Y)(\\omega) &= X(\\omega) \\cdot Y(\\omega)\\\\\n\\left(\\frac{X}{Y}\\right)(\\omega) &= \\frac{X(\\omega)}{Y(\\omega)},\\\\\n\\end{align*}\nrespectively. In this way, we can build up more complicated random\nvariables from simpler ones.\n\nThe {\\em expected value} or {\\em average value} of a random variable\n$X$ is defined to be\n$$E[X] = \\sum_{\\omega \\in \\Omega} P[\\omega] X(\\omega).$$\n\n\\section{Conditional Probabilities}\n\nWe will be working with conditional probabilities. The {\\em\n  conditional probability of A given B}, written $P(A|B)$, is the\nprobability that event $A$ happens given that we already know that $B$\nhas happened. It is defined as the probability that both $A$ and $B$\nhappen (written $A\\cap B$) divided by the probability that $B$\nhappens.\n$$P[A|B] = \\frac{P[A \\cap B]}{P[B]}$$\n\nTwo events $A$ and $B$ are said to be independent if $P[A|B] = P[A]$.\n\nIf $X$ and $Y$ are random variables, then the events we are interested\nin are the event that they take on a particular value. A conditional\nprobability $P[X|Y]$, where $X$ and $Y$ are random variables, should\nbe understood as a function that maps values of $X$ and $Y$ to\nprobabilities, i.e., $P[X|Y](\\alpha, \\beta) = P[X=\\alpha | Y=\\beta]$.\n\nIt is always the case that, for every $\\beta$, $\\sum_\\alpha\nP[X=\\alpha|Y=\\beta] = 1$, where the sum is taken over all possible\nvalues of $A$.\n\nTwo random variables $X$ and $Y$ are said to be independent if the\nevents $X=a$ and $Y=b$ are independent for every $a$ and $b$.\n\n\\section{Covariance}\n\nThe {\\em covariance} between two random variables is defined as \n$$Cov[X,Y] = E[XY] - E[X]E[Y].$$\nThe covariance is higher if $X$ and $Y$ tend to be large at the same\ntime and small at the same time. If it is zero, $X$ and $Y$ are said\nto be ``uncorrelated''. Two independent random variables are always\nuncorrelated, but two uncorrelated random variables need not be\nindependent.\n\n\\section{Partial Derivatives}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{contour3d_demo3.png}\n\\caption{A function of two variables. The partial derivative is the\n  derivative of the curves shown on the left and right walls.}\n\\label{fig-partial}\n\\end{figure}\n\nThe partial derivative of a function $f(x_1, \\dots, x_n)$, denoted by\n$\\frac{\\partial f(x_1, \\dots, x_n)}{\\partial x_i}$, is the derivative of\nthe function\n$$g(x) = f(a_1, \\dots, a_{i-1}, x, a_{i+1}, \\dots, a_n),$$\nwhere the $a_j$ are constants. Some functions $g$ are shown for\ndifferent values of the $a_j$ in Figure \\ref{fig-partial}, for a\nfunction of two variables $f(x_1, x_2)$.\n\n\\section{Stochastic Gradient Ascent/Descent}\n\nLet $f$ be a function of $n$ real variables $x_1, \\dots, x_n$. We want\nto find the values of $x_1, \\dots, x_n$ for which $f(x_1, \\dots, x_n)$\nis largest. For completely general $f$, this is impossible to do\nexcept by a brute force search over the entire space, which is\nimpossible, since there are infinitely many settings for each\n$x_i$. For functions $f$ which are continuous and which have\ncontinuous derivatives, it is still nontrivial, and often the best we\ncan do is to find a setting of the $x_i$ which is locally highest,\ni.e., such that there is no $x_1', \\dots, x_n'$ close to $x_1, \\dots,\nx_n$ such that $f(x_1', \\dots, x_n') > f(x_1, \\dots, x_n)$.\n\nWe can find local maxima of continously differentiable $f$ by\nrepeatedly taking small steps in the direction that makes the function\ngrow fastest:\n$$\\Delta x_i = \\eta \\cdot \\frac{\\partial f(x_1, \\dots, x_n)}{\\partial\n  x_i}.$$ \nThe notation $\\Delta x_i$ means that we replace $x_i$ by $x_i + \\Delta\nx_i$.  Here $\\frac{\\partial f}{\\partial x_i}$ is a partial derivative;\nit specifies how fast $f$ will grow if we take a small step in the\ndirection of increasing $x_i$. This procedure is called {\\em gradient\n  ascent}; if we are trying to minimize a function, we simply go in\nthe opposite direction:\n$$\\Delta x_i = -\\eta \\cdot \\frac{\\partial f(x_1, \\dots, x_n)}{\\partial\n  x_i}.$$ This is called {\\em gradient descent}.\n\nThe parameter $\\eta$, called the ``learning rate'', controls how fast\nwe move in the direction of the gradient. Lower rates result in more\naccurate gradient computations (since we are updating our direction\nmore frequently), but also result in gradient ascent taking\nlonger. Learning rates that are too high can result in oscillation\naround the desired solution, as the algorithm keeps overshooting the\nbest point. Learning rates are generally set empirically, by seeing\nwhat works best in a particular context.\n\nIt is often easier to find a random variable whose average value is\nthe gradient, and use that instead of the true gradient in our\nupdates. This is called {\\em stochastic} gradient ascent or descent,\ndepending on whether we are trying to maximize $f$ or minimize $f$.\nMore formally, if we have random variables $Y_i$ ($i=1, \\dots, n$)\nsuch that:\n$$\\frac{\\partial f(x_1, \\dots, x_n)}{\\partial x_i} = E[Y_i] = \\sum_a P[Y_i=a]\na,$$ and we have a source of random samples $y_i(1), \\dots, y_i(T)$\nof $Y_i$, then we can maximize $f$ via the update\n$$\\Delta x_i = \\eta \\cdot y_i(t).$$ \n\nIn general, the partial derivative of $f$ will change as the $x_i$\nchange, so we will need a new random variable $Y_i$ at each time\nstep. Fortunately, this is often possible. In general the approach\ntaken is to use a single sample from each random variable, then update\nthe $x_i$ according to the update rule above, then pick a new random\nvariable whose expected value is the new gradient.\n\nIt is important to note that there may be many different random\nvariables whose expectation is equal to the gradient. For instance, if\nwe have a random variable such that $E[X]$ is equal to a gradient of\ninterest, then the same is true of the random variable\n$$X + a\\frac{I[X \\ge 0]}{P[X \\ge 0]} - a \\frac{I[X<0]}{P[X < 0]},$$\nwhere $I[X \\ge 0]$ is one if $X \\ge 0$ and zero otherwise, and\n$I[X<0]$ is one if $X<0$ and zero otherwise. We therefore do not\nrequire that the neurological evidence exactly match the stochastic\ngradient descent equations we give.\n\nOne random variable that seems especially biologically plausible is\n$$T_{X, a} = E[X | X\\ge a] I[X \\ge a] + E[X | X < a] I[X < a],$$\nwhere\n$$E[X | X \\ge a] = \\sum_{\\omega: X(\\omega) \\ge a}X(\\omega)\n\\frac{P[\\omega]}{P[X \\ge a]},$$ \nand similarly for $E[X | X < a]$. The random variable $T_{X,a}$ has\nthe same expectation as $X$, but has the very simple form of a step\nfunction: it has one constant value when $X<a$ and another constant\nvalue when $X\\ge a$.\n\\end{document}\n", "meta": {"hexsha": "aa68c2277c73e3b9a95dce9edae9dc0aefdb4805", "size": 9238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "askesis/math.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/math.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/math.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": 45.5073891626, "max_line_length": 77, "alphanum_fraction": 0.7161723317, "num_tokens": 2724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.661652597533417}}
{"text": "\\section{Graph-based Clustering}\n\n% ===\n%\\textbf{Metric} relational data:\n%relations correspond to Euclidean distances.\n\n\\textbf{Non-metric relations:}\nmight assume negative values or violate the triangular inequality.\n\n% ===\n\\emph{Setting:}\\enspace\nobjects $\\bm o_i, \\bm o_j \\in \\mathcal O$;\\:\nrelations with weights $\\mathcal D \\coloneqq \\{ D_{ij} \\}$ on the edges $(i, j)$.\n\\\\\n\\begin{itemize}\n    \\item Cluster $\\alpha$:\\enskip\n        $\\mathcal G_\\alpha \\equiv \\brace{\\bm o\\in \\mathcal O : c(\\bm o) = \\alpha}$\n    \\item Inter-cluster edges:\\enskip\n        $\\mathcal E_{\\alpha\\beta} = \\brace{(i,j) \\in \\mathcal E : \\bm o_i \\in \\mathcal G_\\alpha \\land \\bm o_j \\in \\mathcal G_\\beta}$\n    \\item $\\mathrm{cut}(A,B) = \\sum_{i\\in A, j\\in B} W_{ij}$\\enskip\n        {\\small $\\to$ weight matrix $W$}\n    \\item $\\mathrm{assoc}(A,\\mathcal V) = \\sum_{i\\in A, j\\in \\mathcal V} W_{ij}$\n        \\enskip{\\small $\\to$ total connection strength from nodes in $A$ to all nodes in the graph}\n\\end{itemize}\n\n\\emph{Correlation clustering:}\\\\\n%Maximise agreement within cluster and disagr. between clusters.\nMinimise the sum of \\textit{pairwise} intracluster distances.\n\n\\begin{tabular}{@{} l @{} l @{}}\n    $R\\ap{cc} (c; \\mathcal D)$ &\n        $= - \\sum\\limits_{\\nu\\leq k} \\: \\sum\\limits_{(i,j) \\in \\mathcal E_{\\nu\\nu}} S_{ij} + \\sum\\limits_{\\nu\\leq k} \\: \\sum\\limits_{\\substack{\\mu\\leq k \\\\ \\color{red}\\mu\\neq\\nu}} \\: \\sum\\limits_{(i,j) \\in \\mathcal E_{\\nu\\mu}} S_{ij}$\n    \\\\ &\n        $= - \\textcolor{red}{2}\\sum\\limits_{\\nu\\leq k} \\: \\sum\\limits_{(i,j)\\in \\mathcal E_{\\nu\\nu}} S_{ij} + \\cancel{ \\sum\\limits_{(i,j)} S_{ij} }$\n    \\\\ &\n        \\quad $\\hookrightarrow$ intra-cluster\n        \\quad $\\hookrightarrow$ const\n    \\\\\n    \\multirow{2}{*}{\\small \\shortstack{up to \\\\ thresh. $u$}} &\n        $\\overset{\\ast}{=}- \\frac12 \\sum\\limits_{\\nu\\leq k} \\: \\sum\\limits_{(i,j) \\in \\mathcal E_{\\nu\\nu}} (\\abs{S_{ij} {-} u} + S_{ij} {-} u)$\n    \\\\ &\n        $\\phantom{=} + \\frac12 \\sum\\limits_{\\nu\\leq k} \\: \\sum\\limits_{\\substack{\\mu\\leq k \\\\ \\color{red}\\mu\\neq\\nu}} \\: \\sum\\limits_{(i,j) \\in \\mathcal E_{\\nu\\mu}} (\\abs{S_{ij} {+} u} - S_{ij} {-} u)$\n    \\\\ \\multicolumn{2}{@{\\quad}l}{\n        \\small $\\ast :$ altern. def. where $\\frac12 (\\abs{X} \\pm X) = \\max \\{ 0, \\pm X \\}$\n    }\n\\end{tabular}\n\n\\columnbreak\n\\emph{Graph partitioning:}\n\\quad $D_{ij} \\in \\mathbb R$\\\\\n\\begin{tabular}{@{} l @{} l @{}}\n    $R\\ap{gp} (c; \\mathcal D)$ &\n        $= \\mathit{const} - \\sum_{\\nu\\leq k} \\mathrm{cut} \\paren{ \\mathcal G_\\nu (\\mathcal D), \\mathcal V \\setminus \\mathcal G_\\nu (\\mathcal D) }$\n    \\\\ &\n        $= \\mathit{const} + \\sum_{\\nu\\leq k} \\mathrm{cut} \\paren{ \\mathcal G_\\nu (\\mathcal S), \\mathcal V \\setminus \\mathcal G_\\nu (\\mathcal S) }$\n\\end{tabular}\n\n\\emph{Bias in \\textit{\\rmfamily R(c;D)}:}\\enspace\nCost should scale prop. to \\#objects,\\\\\ni.e. $R(c;D) = \\mathcal O(n)$.\n\\qquad $\\ast: \\text{ use } D_{ij} = D(1 - \\delta_{ij})$\n\n\\textbf{Tipp:}\\enspace\n$\\frac{\\mathrm{cut}(\\mathcal G_\\alpha, \\mathcal V \\backslash \\mathcal G_\\alpha)}{\\mathrm{assoc}(\\mathcal G_\\alpha, \\mathcal V)}\n\\overset\\ast= \\frac{n\\cdot p_\\alpha \\cdot n(1-p_\\alpha) \\cdot D}{n\\cdot p_\\alpha \\cdot n \\cdot D} = 1 - p_\\alpha$\n\n% ===\n\\subsection{Pairwise Clustering}\n\n\\emph{Cost:}\\enspace\n$R\\ap{pc} (c; \\mathcal D)\n= \\sum\\limits_\\alpha \\sum\\limits_{(i,j) \\in \\mathcal E_{\\alpha\\alpha}} \\frac{D_{ij}}{\\abs{\\mathcal G_\\alpha}}\n\\color{gray}\n= \\sum\\limits_\\alpha \\sum\\limits_{(i,j) \\in \\mathcal E_{\\alpha\\alpha}} \\abs{\\mathcal G_\\alpha} \\frac{D_{ij}}{\\abs{\\mathcal E_{\\alpha\\alpha}}}$\n\n\\emph{Equivariance to \\textit{\\rmfamily k}-means:}\n{\\small\\color{gray}\\quad(if $\\color{gray} D_{ij} = \\norm{\\bm x_i - \\bm x_j}^2$)}\\\\\n$\\sum\\limits_{i\\leq n} \\norm{\\bm x_i - \\bm y_{c(i)}}^2 = \\sum\\limits_{i\\leq n} \\sum\\limits_{j\\leq n} \\sum\\limits_{\\alpha\\leq k} \\frac{\\mathbb I_{\\brace{c(i) = \\alpha}} \\mathbb I_{\\brace{c(j) = \\alpha}}}{\\abs{\\mathcal G_\\alpha}} D_{ij}$\n\n\n\\emph{Invariance properties:}\\\\\n\\begin{itemize}\n    \\item Symmetrisation:\n        \\enskip $R\\ap{pc} (c; \\mathcal D\\ap{s}) \\equiv R\\ap{pc} (c; \\mathcal D)$\n    \\item Off-diagonal shift:\n        \\enskip $R\\ap{pc} (c; \\tilde{\\mathcal D}) = R\\ap{pc} (c; \\mathcal D) - \\lambda\\ped{min}\\cdot n$\n\\end{itemize}\n\n\\emph{Theorem:}\\enspace\nIf $S\\ap{c}$ is p.s.d., then $D$ derives from squared Eucl. space.\n$\\implies$ Make $S$ \\textbf{p.s.d.}: \\enskip $\\tilde S \\coloneqq S - \\lambda\\ped{min} \\mathbb I$\n\n\\emph{Constant Shift Embedding:}\\\\\n\\begin{enumerate}\n    \\item \\textbf{Symmetrise} $D \\to D\\ap{s}$:\n        \\enskip $\\highlight*{D_{ij}\\ap{s}} \\coloneqq \\frac12 (D_{ij} + D_{ji})$\n    \\item \\textbf{Centralise} $D$, then $S$:\n        \\enskip $X\\ap{c} \\coloneqq Q X\\ap{s} Q^\\top$\\\\\n        $Q = \\mathbb I - \\frac1n \\bm e_n \\bm e_n^\\top$\n        \\qquad \\highlight*{$S\\ap{c} = -\\frac12 D\\ap{c}$}\\\\\n        $X\\ap{c}_{ij} = X_{ij} - \\frac1n \\sum_k X_{ik} - \\frac1n \\sum_k X_{kj} + \\frac{1}{n^2} \\sum_{k,\\ell} X_{k\\ell}$\\\\\n        $\\implies$ sum over column/rows = 0\n    \\item \\textbf{(Off-)Diagonal shift}:\n        \\enskip Find $\\lambda\\ped{min}$ of $S\\ap{c}$\\\\\n        $\\highlight*{\\tilde S} \\coloneqq S\\ap{c} - \\lambda\\ped{min} \\mathbb I$\n        \\qquad $\\tilde D \\coloneqq D - \\lambda\\ped{min} (\\bm 1 - \\mathbb I)$\\\\\n        $\\highlight*{\\tilde D_{ij}} = \\tilde S_{ii} + \\tilde S_{jj} - 2 \\tilde S_{ij} \\color{gray} = \\norm{\\bm x_i - \\bm x_j}^2$\n\\end{enumerate}\n\n\\emph{Reconstruction:}\\\\\n\\begin{enumerate}\n    \\item EVD:\n        \\enskip \\highlight*{$\\tilde S = \\bm V \\Lambda \\bm V^\\top$}\n        \\enskip via \\enskip $(\\tilde S - \\lambda \\mathbb I) \\bm v \\overset!= 0$\n        \\enskip $\\color{gray} (\\abs{\\bm v} = 1)$\\\\\n        where \\: $\\Lambda {=} \\mathrm{diag}(\\lambda_1 \\ldots \\lambda_n)$\n        \\: and \\: $\\bm V {=} [\\bm v_1 \\ldots \\bm v_n]$\n    \\item Find $p$ s.t. $\\lambda_1 \\geq \\ldots \\lambda_p > \\lambda_{p+1} = \\ldots = \\lambda_n = 0$\n    \\item $\\implies \\highlight*{\\bm X_p} = \\bm V_p (\\Lambda_p)^{1/2}$\n        \\enskip (each row is a vector)\n    \\item $\\implies \\bm X_t = \\bm V_t (\\Lambda_t)^{1/2}$\n        \\enskip (approx. \\& denoising)\n\\end{enumerate}\n\n\\columnbreak\n\\emph{Cluster membership of new data:}\\\\\n\\textit{Note:}\\enspace $S\\ap{new}$ is def. by\\enspace $D_{ij}\\ap{new} = S_{ii}\\ap{new} + \\tilde S_{jj} - 2 S_{ij}\\ap{new}$\n\\begin{enumerate}\n    \\item $\\begin{aligned}[t]\n        (S\\ap{new})\\ap{c} = -\\tfrac12 \\big[ &\n            D\\ap{new} (\\mathbb I_n - \\tfrac1n \\bm e_n \\bm e_n^\\top)\n        \\\\[-3pt] &\n            - \\tfrac1n \\bm e_m \\bm e_n^\\top + \\tilde D (\\mathbb I_n - \\tfrac1n \\bm e_n \\bm e_n^\\top) \\big]\n    \\end{aligned}$\n    \\item Project:\n        \\enspace $X_p\\ap{new} = (S\\ap{new})\\ap{c} \\bm V_p (\\Lambda_p)^{-1/2}$\n    \\item Assign:\n        \\enskip $\\hat c_i = \\arg\\min_c \\norm*{(x_p\\ap{new})_i - y_{c(i)}}$\n\\end{enumerate}\n\n% ===\n\\iffalse\n    \\subsection{Alternative Costs}\n    \\todo{}\n\\fi\n\n% ===\n", "meta": {"hexsha": "c7fef1fa5038bd5acb54e4bf314527f9d4c900d7", "size": 6823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/07_pairwise_clustering.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/SLT21/sections/07_pairwise_clustering.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SLT21/sections/07_pairwise_clustering.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.1013513514, "max_line_length": 235, "alphanum_fraction": 0.5875714495, "num_tokens": 2745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.661652597533417}}
{"text": "\\section*{Web Appendix C}\n\nAs mentioned in Section 2, any \\textit{p}-hacking model can be written on the form of a selection model. Observe that\n\\begin{eqnarray*}\n\\int_{[0,1]}\\phi_\\alpha^{\\star}(x_{i}\\mid\\theta_{i},\\sigma_{i}^2)d\\omega(\\alpha) & = & \\int_{[0,1]}\\phi(x_{i}\\mid\\theta_{i}, \\sigma_i^2)P(u_i\\in\\left[0,\\alpha\\right]\\mid\\theta_{i},\\sigma^2_{i})^{-1}d\\omega(\\alpha)\\\\\n & = & \\phi(x_{i}\\mid\\theta_{i}, \\sigma^2_i)\\int_{[0,u_i)}P(u_i\\in\\left[0,\\alpha\\right]\\mid\\theta_{i},\\sigma_{i}^2)^{-1}d\\omega(\\alpha).\n\\end{eqnarray*}\nwhere $\\phi_\\alpha^{\\star}$ is a Gaussian density truncated so that the \\textit{p}-value associated to $x_i$, $u_i$, lies in the interval $\\left[0,\\alpha\\right)$. This is a publication bias model if $$h(u_i)=\\int_{[0,u_i]}P(u_i\\in\\left[0,\\alpha\\right]\\mid\\theta_{i},\\sigma^2_{i})^{-1}d\\omega(\\alpha)$$ is bounded for each $u_i$ and $h(u_i)$ is independent of $\\theta_{i},\\sigma^2_{i}$. While $h(u_i)$ can be bounded, it is typically dependent of $\\theta_{i},\\sigma^2_{i}$, with the fixed effect model under complete selection for significance being a notable exception.\n\nOn the other hand, any selection model with \n$$\nI = \\int \\phi(x;\\theta_{i},\\sigma^2_{i})w(u_i)du_i<\\infty\n$$\ncan be written as a mixture model. For then there is a finite measure $d\\omega(\\alpha)$ satisfying \n\\[\nw(u_i)=\\int_{[0,u_i)}\\frac{1}{P(u_i\\in\\left[0,\\alpha\\right)\\mid\\theta_i,\\sigma^2_{i})}d\\omega(\\alpha)\n\\]\nJust take $d\\omega(\\alpha)=d w(\\alpha)P(u_i\\in\\left[0,\\alpha\\right)\\mid\\theta_{i},\\sigma^2_{i})$, where $d\\rho(\\alpha)$ is defined by $\\int_{0}^{u_i}d w(\\alpha)= w(u_i)$. The size of the measure is\n\\begin{eqnarray*}\n\\int_{0}^{1}d\\omega(\\alpha;\\theta_{i},\\sigma^2_{i}) & = & \\int_{0}^{1}P(u_i\\in\\left[0,\\alpha\\right)\\mid\\theta_{i},\\sigma^2_{i})d w(\\alpha)\\\\\n & = & \\int_{0}^{1}\\phi(u_i;\\theta_{i},\\sigma^2_{i})\\int_{0}^{u_i}d w(\\alpha)du_i\\\\\n & = & I\n\\end{eqnarray*}\nHence $I d\\omega'(\\alpha;\\theta_{i},\\sigma^2_{i})$ is a probability measure. This probability measure makes \n\\[\nI^{-1}\\phi(x_{i};\\theta_{i},\\sigma^2_{i})w(u_i)=\\int_{[0,1]}\\phi_\\alpha(x_{i};\\theta_{i},\\sigma^2_{i})d\\omega'(\\alpha)\n\\]\nas can be seen by the following computation,\n\\begin{eqnarray*}\nI^{-1}\\phi(x_{i};\\theta_{i},\\sigma^2_{i})w(u_i) & = & I^{-1}\\int_{[0,u_i)}\\frac{\\phi(x_{i};\\theta_{i},\\sigma^2_{i})}{P(u_i\\in\\left[0,\\alpha\\right)\\mid\\theta_{i},\\sigma^2_{i})}d\\omega(\\alpha)\\\\\n & = & I^{-1}\\int_{[0,1]}\\frac{\\phi(x_{i};\\theta,\\sigma^2_{i})1_{\\left[0,\\alpha\\right)}(u_i)}{P(u_i\\in\\left[0,\\alpha\\right)\\mid\\theta_{i},\\sigma^2_{i})}d\\omega(\\alpha)\\\\\n & = & I^{-1}\\int_{[0,1]}\\phi_\\alpha(x_{i};\\theta_{i},\\sigma^2_{i})d\\omega(\\alpha)\\\\\n & = & \\int_{[0,1]}\\phi_\\alpha(x;\\theta_{i},\\sigma^2_{i})d\\omega'(\\alpha)\n\\end{eqnarray*}\n\nProposition 1 shows the form of the one-sided normal step function selection probability publication bias model when it is written as a mixture model of the form (5). But most such mixture models are not true \\textit{p}-hacking models, as the mixing probabilities $\\pi_{i}^{\\star}$ depend on $\\theta$. There is no way for the \\textit{p}-hacker to know\n$\\theta$, so we cannot regard the publication bias model as a \\textit{p}-hacking model.\n\n\n\n", "meta": {"hexsha": "02d30901024ffffb576ebe80cafe26df4f09f89a", "size": 3165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WebAppendix_C_removedTooMuch.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_C_removedTooMuch.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_C_removedTooMuch.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": 77.1951219512, "max_line_length": 569, "alphanum_fraction": 0.6647709321, "num_tokens": 1227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6616525943731658}}
{"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\\renewcommand{\\a}{\\bm a}\n\\renewcommand{\\c}{\\bm c}\n\\newcommand{\\p}{\\bm p}\n\\newcommand{\\q}{\\bm q}\n\\newcommand{\\1}{\\bm 1}\n\\title{Homework 1}\n\\author{Xinyi Gu, Songchen Tan}\n\\date{\\today}\n\\begin{document}\n\\maketitle\n\\section{}\n\\subsection*{(a)}\n\nTo deal with the absolute value in the objective function, We let vector $\\a=\\{a_0,\\cdots,a_{T-1}\\}=\\p-\\q$, where $p_t=\\max(a_t,0)$ and $q_t=-\\min(a_t,0)$; it is easy to verify that $a_t=p_t-q_t$ and $|a_t|=p_t+q_t$. Furthermore we denote $m=\\max_{t\\in\\{0,\\cdots,T-1\\}}|a_t|$. Let $\\c=(c_0,\\cdots,c_{T-1})$ and $\\1=(1,\\cdots,1)$. The linear programming formulation is\n\nminimize $m$, subject to\n\n$$\n\\begin{cases}\n    m >= (p_t + q_t), \\quad 0\\le t\\le T-1\\\\\n    \\displaystyle\n    \\sum_{t=0}^{T-1}(p_t - q_t)=0\\\\\n    \\displaystyle\n    \\sum_{t=0}^{T-1}(T-t-1)(p_t - q_t)=d\\\\\n    -\\delta \\le (p_{t-1} - q_{t-1})-(p_t - q_t) \\le\\delta, \\quad 1\\le t\\le T-1\\\\\n    \\displaystyle\n    \\sum_{t=0}^{T-1}c_t(p_t+q_t)\\le f\n\\end{cases}\n$$\n\n\\subsection*{(b)}\n\nThe optimization gives $m\\approx 0.0213$, and the $a, x, v$ are shown below.\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[b]{0.3\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{a.png}\n        \\caption{$a$}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[b]{0.3\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{v.png}\n        \\caption{$v$}\n    \\end{subfigure}\n    \\hfill\n    \\begin{subfigure}[b]{0.3\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{x.png}\n        \\caption{$x$}\n    \\end{subfigure}\n       \\caption{$a, x, v$ during the motion}\n\\end{figure}\n\n\\section{}\n\n\\subsection*{(a)} \n\nWe have \n\n\\begin{align*}\n    \\min \\quad & c_1 x_1 + c_2 | x_2 -10| \\\\\n    \\text{subject to}\\quad & c_3 | x_1 + 2 | + c_4 | x_2 | \\le 5 \n\\end{align*}\n\nMoving the objective into the constraints and making constraints with absolute valunes linear, we get\n\n\\begin{align*}\n    \\min \\quad & t\\\\\n    \\text{subject to}\\quad  z_1  & \\geq  x_1 +2, \\\\\n    z_1  & \\geq -(x_1 + 2) \\\\\n    z_2  & \\geq  x_2 ,\\\\\n    z_2  & \\geq  -x_2\\\\\n    c_3 z_1 + c_4 z_2 & \\le 5, \\\\\n    z_3  & \\geq x_2 - 10 ,\\\\\n    z_3  & \\geq -(x_2 - 10)\\\\\n    c_1 x_1 + c_2 z_3 & \\le  t\n\\end{align*}\n\nTo formulate a linear programming problem, $c_1$ free, $c_2, c_3, c_4 \\geq 0 $.\n\n\\subsection*{(b)} \n\n\\begin{align*}\n    f(x) & = \\max{\\{-x+1, \\quad 0, \\quad 2x - 4\\}}\\\\\n    c^{'}x + f(d^{'}x) & = c^{'}x + \\max{\\{-(d^{'}x) + 1, \\quad 0, \\quad 2(d^{'}x) - 4\\}}\n\\end{align*}\n\nWrite max$\\{\\cdot\\}$ as z and 3 constraints:\n\n\\[ z \\geq - d^{'}x + 1, \\quad z \\geq 0, \\quad z \\geq 2d^{'}x - 4 \\]\n\nWe get\n\n\\begin{align*}\n    \\min \\quad & c^{'}x + z\\\\\n    \\text{subject to} \\quad z & \\geq - d^{'}x + 1,\\\\\n    z & \\geq 0,\\\\\n    z & \\geq 2d^{'}x - 4, \\\\\n    Ax & \\geq b\n\\end{align*}\n\n\n\\section{}\n\nWhen $m\\ge n$ this is trivial, so we consider $m < n$ only. For any $y\\in\\operatorname{ran}_+(A)$, consider the polyhedron\n\n$$\nC=\\left\\{x \\in \\mathbb{R}^{n} \\mid y=A x, x \\geq 0\\right\\}\n$$\n\nAssuming the rank of $A$ is $r\\le m<n$, we can always select $r$ linearly independent rows such that, by row operations, they can eliminate other rows (including the corresponding elements in $y$). Therefore it suffices to prove the case $r=m$.\n\nAccording to the corollary in class, every nonempty polyhedron in standard form has a BFS. $C$ is certainly nonempty since $y\\in\\textrm{ran}_+(A)$, so there exists a group of indices $B(1), \\cdots, B(m)$ such that the matrix $B=(A_{B(1)}, \\cdots, A_{B(m)})$ satisfies $B^{-1}y\\ge 0$. This group of indices are the indices of coefficients required by the problem.\n\n\n\\section{}\n\n\\subsection*{(a)} \n\nTrue.\n\n$n = m+1$ means that $P$ lives in an 1-D subspace, therefore every point in $P$ can be written as $x_0 + \\lambda d$. This subspace is either a segment or a ray, so it can't have more than 2 extreme points.\n\n\\subsection*{(b)}\nFalse.\n\nCounter example: \nminimize $x_1$, subject to $x_1=1$ and $x_1,x_2\\ge0$, optimal solution set is $\\{(x_1,x_2)|x_1=1,x_2\\geq0\\}$ which is unbounded.\n\n\\subsection*{(c)} \nFalse.\n\nCounter example: minimize $x_1+x_2$, subject to $x_1 +x_2= 1$, $x_1, x_2 \\geq 0$. At a optimal solution $(0.5, 0.5)$, 2 (more than 1) variables are positive.\n\n\\subsection*{(d)} \nTrue.\n\nConvex combination of any 2 (or more) solutions can be optimal.\n\n\\subsection*{(e)} \nFalse.\n\nSame example as (b).\n\n\\subsection*{(f)} \nFalse.\n\nCounter example: minimize $\\max\\{x_1-x_2,x_2-x_1\\}$ subject to $x_1+x_2=1,x_1,x_2\\ge0$. The optimal solution is $(0.5, 0.5)$.\n\n\\section{}\n\n\\subsection*{(a)}\n\nWe noticed that $\\bar c_2<0$, therefore $\\beta=0$ (or else it can be further optimized). We choose $(\\alpha,\\beta,\\gamma,\\delta,\\eta)=(0, 0, 0, 0, 0)$.\n\n\\subsection*{(b)}\n\nWe need $d_j>0,\\forall j\\in N$, so we choose $j=1$ and $\\alpha,\\gamma,\\delta <0$. We choose $(\\alpha,\\beta,\\gamma,\\delta,\\eta)=(-1, 0, -1, -1, 0)$.\n\n\\subsection*{(c)}\n\nWe choose $j=2$ to be optimized, so we require $\\beta>0$. We choose $(\\alpha,\\beta,\\gamma,\\delta,\\eta)=(0, 3, 0, 1, 0)$.\n\n\n\n\\section{}\n\n\\subsection*{(a)}\n\nStandard form:\n\n\\begin{align*}\n    \\min \\quad  -2x_1 - x_2 & \\\\\n    \\text{subject to} \\quad x_1 - x_2 + s_1 & = 2 \\\\\n    x_1 + x_2 + s_2 & = 6 \\\\\n    x_1, x_2, s_1, s_2 & \\geq 0\n\\end{align*}\n\n\\[\\begin{bmatrix}\n    1 & -1 & 1 & 0 \\\\\n    1 & 1 & 0 & 1\n\\end{bmatrix} \\begin{bmatrix}\n    x_1 & x_2 & s_1 & s_2\n\\end{bmatrix}^{T} = \\begin{bmatrix}\n    2 \\\\\n    6\n\\end{bmatrix}\n\\]\nWant ($x_1$, $x_2$) = (0, 0), pick $s_1$, $s_2$ as basis, \nB $ = \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} $, \nBFS: $x^T = B ^{-1} b = $ (0, 0, 2, 6).\n\n\\subsection*{(b)}\n\nFull tableau implementation:\n\nstart with BFS: x = (0, 0, 2, 6)'\nB = [\\boldsymbol{$A_3$}, \\boldsymbol{$A_4$}]\n\n\\begin{tabular}{l|l|l|l|l|l|}\n\\cline{2-6}\n&  & $x_1$ & $x_2$ & $s_1$ & $s_2$ \\\\ \\cline{2-6} \n& 0 & -2 & -1 & 0 & 0 \\\\ \\cline{2-6} \n $s_1$ = & 2 & 1 & -1 & 1 & 0 \\\\ \\cline{2-6} \n $s_2$ = & 6 & 1 & 1 & 0 & 1\\\\ \\cline{2-6} \n\\end{tabular}\n\\\\\n\n$x_1$ and $x_2$ have negative reduced costs, pick $x_1$ to enter basis\n\n\\begin{tabular}{l|l|l|l|l|l|}\n\\cline{2-6}\n&  & $x_1$ & $x_2$ & $s_1$ & $s_2$ \\\\ \\cline{2-6} \n& 1 & 0 & 1 & 0 & 2 \\\\ \\cline{2-6} \n $x_1$ = & 6 & 1 & 1 & 0 & 1 \\\\ \\cline{2-6} \n $s_1$ = & -4 & 0 & -2 & 1 & -1\\\\ \\cline{2-6} \n\\end{tabular}\n\\\\\n\n$s_1 < $  0 here, infeasible solution, pick $s_2$\n\n\\begin{tabular}{l|l|l|l|l|l|}\n\\cline{2-6}\n&  & $x_1$ & $x_2$ & $s_1$ & $s_2$ \\\\ \\cline{2-6} \n& -3 & 0 & -3 & 2 & 0 \\\\ \\cline{2-6} \n $x_1$ = & 2 & 1 & -1 & 1 & 0 \\\\ \\cline{2-6} \n $s_2$ = & 4 & 0 & 2 & -1 & 1\\\\ \\cline{2-6} \n\\end{tabular}\n\\\\\nThen we have reduced costs of $x_2$ to be negative, pick $x_2$ to enter basis,\n\n\\begin{tabular}{l|l|l|l|l|l|}\n\\cline{2-6}\n&  & $x_1$ & $x_2$ & $s_1$ & $s_2$ \\\\ \\cline{2-6} \n& 10 & 0 & 0 & 0.5 & 1.5 \\\\ \\cline{2-6} \n $x_1$ = & 4 & 1 & 0 & 0.5 & 0.5 \\\\ \\cline{2-6} \n $x_2$ = & 2 & 0 & -1 & -0.5 & 0.5\\\\ \\cline{2-6} \n\\end{tabular}\n\\\\\nAll the reduced costs in this tableau are nonnegative, representing an optimal solution at $x_1$ = 4 and $x_2$ = 2, $s_1$ = 0, $s_1$ = 0. In this solution, min $-2x_1 -x_2$ = $c^{'}_B x_B$ = -10\n\n\n\\end{document}\n\n\n\n\n\n\\\\", "meta": {"hexsha": "1e8f1ab00211481974ed95a379dd154ebc1da663", "size": 7253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/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": "1/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": "1/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": 28.0038610039, "max_line_length": 367, "alphanum_fraction": 0.5792086033, "num_tokens": 3146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.6616525891699394}}
{"text": "\\chapter{Categories of filters}\n\nIn~\\cite{filt-cat} two categories, whose objects are related with filters on sets, are defined and researched.\n\nAccordingly~\\cite{filt-cat} infinite product is defined just in the first (denoted $\\mathscr{F}$ there) of these two categories.\nSo we will for now consider the first category. (Usefulness of the second category for our research is questionable.)\n\nLet $f:A\\rightarrow B$ be a function, $\\mathcal{A}$ be a filter on~$A$.\n\n\\begin{prop}\n$\\setcond{Y\\in\\subsets B}{\\rsupfun{f^{-1}}Y\\in\\mathcal{A}}$ is a filter.\n\\end{prop}\n\n\\begin{proof}\nThat it is an upper set is obvious.\n\nLet $Y_0,Y_1\\in\\setcond{Y\\in\\subsets B}{\\rsupfun{f^{-1}}Y\\in\\mathcal{A}}$. Then\n$\\rsupfun{f^{-1}}Y_0\\in\\mathcal{A}$ and $\\rsupfun{f^{-1}}Y_1\\in\\mathcal{A}$.\nWe have\n\\[ \\rsupfun{f^{-1}}(Y_0\\cap Y_1) = \\rsupfun{f^{-1}}Y_0 \\cap \\rsupfun{f^{-1}}Y_1 \\in \\mathcal{A} \\]\nsince $f$ is monovalued.\nThus $Y_0 \\cap Y_1\\in\\setcond{Y\\in\\subsets B}{\\rsupfun{f^{-1}}Y\\in\\mathcal{A}}$.\n\\end{proof}\n\n\\begin{thm}\n\\fxwarning{Should be moved above in the book.}\n$\\setcond{Y\\in\\subsets B}{\\rsupfun{f^{-1}}Y\\in\\mathcal{A}}$ is equal to the filter generated\nby the filter base $\\rsupfun{\\rsupfun{f}}\\mathcal{A}$, for every filter~$\\mathcal{A}$.\n\\end{thm}\n\n\\begin{proof}\nDenote $\\mathcal{B} = \\setcond{Y\\in\\subsets B}{\\rsupfun{f^{-1}}Y\\in\\mathcal{A}}$,\n$\\mathcal{C} = \\rsupfun{\\rsupfun{f}}\\mathcal{A}$.\n\nLet $Y\\in\\mathcal{C}$. Then $Y=\\rsupfun{f}A$ where $A\\in\\mathcal{A}$.\nThen $\\rsupfun{f^{-1}}\\rsupfun{f}A\\supseteq A$ and so $\\rsupfun{f^{-1}}\\rsupfun{f}A\\in\\mathcal{A}$.\nThis proves $\\rsupfun{f}A\\in\\mathcal{B}$, that is $Y\\in\\mathcal{B}$.\n\nLet now $Y\\in\\mathcal{B}$. Then $\\rsupfun{f}\\rsupfun{f^{-1}}Y\\subseteq Y$. Since $\\rsupfun{f^{-1}}Y\\in\\mathcal{A}$,\nwe have that $Y$ is a supset of some set of the form $\\rsupfun{f}A$, so $Y\\in\\mathcal{C}$.\n\\end{proof}\n\n\\begin{cor}\n$\\up\\supfun{f}\\mathcal{A} = \\setcond{Y\\in\\subsets B}{\\rsupfun{f^{-1}}Y\\in\\up\\mathcal{A}}$.\n\\end{cor}\n\n\\begin{defn}\nThe \\emph{category of filtered sets} $\\mathbf{Filt}$ is the category defined as follows:\n\\begin{enumerate}\n\\item Objects are pairs $(A,\\mathcal{A})$ where $A$ is a (small) set and $\\mathcal{A}$ is a filter on~$A$.\n\\item Morphisms from $(A,\\mathcal{A})$ to $(B,\\mathcal{B})$ are functions $f:A\\rightarrow B$ such that\n$\\supfun{f}\\mathcal{A} \\sqsubseteq \\mathcal{B}$.\n\\item Identities are identity functions.\n\\end{enumerate}\n\\end{defn}\n\nTo verify that it is a category is straightforward.\n\nIt is the same category as $\\mathscr{F}$ in \\cite{filt-cat}, as follows from an above proposition.\n\nWe will prove that starred reloidal product is a categorical product in this category.\nFirst we will prove the special case that binary reloidal product is a categorical product in this category.\n\n\\begin{thm}\n  $\\times^{\\mathsf{RLD}}$ (together with projections $\\Pr_0$ and\n  $\\Pr_1$) is a categorical product in $\\mathbf{Filt}$.\n\\end{thm}\n\n\\begin{proof}\n  Let our objects be $\\mathcal{A}$, $\\mathcal{B}$.\n  \n  Denote $p$ the left projection from $\\Base (\\mathcal{A}) \\times\n  \\Base (\\mathcal{B})$ to $\\Base (\\mathcal{A})$.\n  \n  We need to check that $p$ is a $\\mathbf{Filt}$-morphism that is $p\n  (\\mathcal{A} \\times^{\\mathsf{RLD}} \\mathcal{B}) \\sqsubseteq\n  \\mathcal{A}$ what is obvious.\n  \n  Similarly for the right projection $q$.\n  \n  It remains to check the universal property: Let $\\mathcal{C}$ be a filter\n  and $f : \\mathcal{C} \\rightarrow \\mathcal{A}$, $g : \\mathcal{C} \\rightarrow\n  \\mathcal{B}$. We need to prove that there are a unique $u : \\mathcal{C}\n  \\rightarrow \\mathcal{A} \\times^{\\mathsf{RLD}} \\mathcal{B}$ such that\n  $f = p \\circ u$ and $g = q \\circ u$. Denote $h (z) = (f (z) , g (z))$.\n  \n  $h$ is the unique function $\\Base (\\mathcal{C}) \\rightarrow\n  \\Base (\\mathcal{A}) \\times \\Base (\\mathcal{B})$ such that $f = p\n  \\circ h$ and $g = q \\circ h$, so it remains to check that $h$ is a morphism\n  of $\\mathbf{Filt}$ that is $\\langle h \\rangle \\mathcal{C}\n  \\sqsubseteq \\mathcal{A} \\times^{\\mathsf{RLD}} \\mathcal{B}$, what\n  obviously follows from $\\supfun{f} \\mathcal{C} \\sqsubseteq\n  \\mathcal{A}$ and $\\supfun{g} \\mathcal{C} \\sqsubseteq \\mathcal{B}$.\n\\end{proof}\n\n\\begin{thm}\n  $\\prod^{\\mathsf{RLD} \\ast}$ together with projections $\\Pr_k$ is a\n  categorical product in $\\mathbf{Filt}$.\n\\end{thm}\n\n\\begin{proof}\n  Consider an indexed family $\\mathcal{A}$ of objects.\n  \n  Denote $p_k$ the $k$-th projection from $\\prod_{i \\in \\dom\n  \\mathcal{A}} \\Base (\\mathcal{A}_i)$.\n  \n  We need to check that $p_k$ s a $\\mathbf{Filt}$-morphism that is\n  $p_k \\left( \\prod^{\\mathsf{RLD} \\ast} \\mathcal{A} \\right) \\sqsubseteq\n  \\mathcal{A}_k$ what is obvious.\n  \n  It remains to check the universal property: Let $\\mathcal{C}$ be a filter\n  and $f_k : \\mathcal{C} \\rightarrow \\mathcal{A}_k$. We need to prove that\n  there are a unique $u : \\mathcal{C} \\rightarrow \\prod^{\\mathsf{RLD}\n  \\ast} \\mathcal{A}$ such that $f_k = p_k \\circ u$. Denote $h (z) = \\lambda i\n  \\in \\dom \\mathcal{A} : f_i z$.\n  \n  $h$ is the unique function $\\Base (\\mathcal{C}) \\rightarrow \\prod_{i\n  \\in \\dom \\mathcal{A}} \\Base (\\mathcal{A}_i)$ such that $f_k =\n  p_k \\circ h$, so it remains to check that $h$ is a morphism of\n  $\\mathbf{Filt}$ that is $\\langle h \\rangle \\mathcal{C} \\sqsubseteq\n  \\prod^{\\mathsf{RLD} \\ast} \\mathcal{A}$. It follows from\n  \\[ \\Pr^{\\mathsf{RLD}}_i \\langle h \\rangle \\mathcal{C} = \\bigsqcap\n     \\rsupfun{Pr_i} \\langle h \\rangle^{\\ast} \\up\n     \\mathcal{C} = \\bigsqcap \\langle \\Pr_i \\circ h \\rangle^{\\ast} \\up\n     \\mathcal{C} = \\bigsqcap \\langle f_i \\rangle^{\\ast} \\up \\mathcal{C}\n     = \\langle f_i \\rangle \\mathcal{C} \\sqsubseteq \\mathcal{A}_i . \\]\n\\end{proof}", "meta": {"hexsha": "dc0ae95136b79b19be80debbe253075c7b39016c", "size": 5647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-filt-cat.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-filt-cat.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-filt-cat.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": 44.4645669291, "max_line_length": 128, "alphanum_fraction": 0.6663715247, "num_tokens": 2146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6616480014170351}}
{"text": "\\section{Image segmentation}\nIdentify groups of pixels that belong together - goal: Delineate objects and background regions \\& group similar-looking pixels for efficientcy of further processing\n\nExamples of Groupin in vision\n\\begin{itemize}\n\t\\item similar appearance\n\t\\item symmetry\n\t\\item common fate (direction etc)\n\t\\item proximity\n\\end{itemize}\n\n\\subsection{Segmentation as clustering}\n\\subsubsection{Clustering}\nChicken and Egg problem  - either know the centers and allocate the points to it OR know the point membership and create center from them\n\nFeature space - depending on that choice we can group pixels in different ways\n\n\\begin{itemize}\n\t\\item pixel intensity\n\t\\item pixel color\n\t\\item pixel texture\n\t\\item pixel intensity + position (proximity)\n\\end{itemize}\n\n\\subsubsection{k-Means}\nIdea: randomly initialize the k cluster centers, and iterate between the two steps from clustering\n\nProperties: will always converge to some solution (which can be a local maximum)\n\nPro:\n\\begin{itemize}\n\t\\item simple, fast to compute\n\t\\item converges (to local maximum)\n\\end{itemize}\n\nCons:\n\\begin{itemize}\n\t\\item number of cluster has to be defined\n\t\\item sensitive to initial centers\n\t\\item sensitive to outliers\n\t\\item detects spherical clusters only\n\t\\item assuming means can be computed\n\\end{itemize}\n\\subsubsection{Mixture of Gaussians, EM}\nIdea: instead of treating the data as a bunch of points, assume that they are all generated by sampling a continous function - this function is called a \\textit{generative model}, defined by a vector of parameters $\\theta$\n\n\\includegraphics[width=\\columnwidth]{pictures/EM}\n\nE-Step: Compute probability that point $x$ is in blob b, given current guess of $\\theta$\n\n$$ P(b|x,\\mu_b, V_b) = \\frac{\\alpha_b P(x|\\mu_b, V_b)}{\\sum_{i=1}^{K}\\alpha_i P(x|\\mu_i, V_i)} $$\n\nM-Step: Compute overall probability that blob b is selected (N: data points)\\\\\n\nWeight:\n$$\\alpha_b^{new} = \\frac{1}{N} \\sum_{i=1}^{N} P(b|x_i, \\mu_b, V_b) $$\nMean of blob b:\n$$ \\mu_b^{new} = \\frac{\\sum_{i=1}^{N} x_i P(b|x_i, \\mu_b, V_b)}{\\sum_{i=1}^{N} P(b|x_i, \\mu_b, V_b)}$$\nCovariance of blob b:\n$$ V_b^{new} = \\frac{\\sum_{i=1}^{N} (x_i-\\mu_b^{new})(x_i-\\mu_b^{new})^T P(b|x_i, \\mu_b, V_b)}{\\sum_{i=1}^{N} x_i P(b|x_i, \\mu_b, V_b)} $$\n\nEM Application is useful for all sorts of problems \n\\begin{itemize}\n\t\\item Any clustering problem\n\t\\item Many model estimation problems\n\t\\item Missing data problems\n\t\\item Finding outliers\n\t\\item Segmentation problems\n\t\\begin{itemize}\n\t\t\\item based on color\n\t\t\\item based on motion\n\t\t\\item Foreground/background separation \n\\end{itemize}\t\n\\end{itemize}\nPro:\n\\begin{itemize}\n\t\\item Probabilistic interpretation\n\t\\item Soft assignments between data points and clusters\n\t\\item Generative model, can predict novel data points \n\t\\item Relatively compact storage ($O(Kd^2$)\n\\end{itemize}\nCons:\n\\begin{itemize}\n\t\\item Initialization – often a good idea to start from output of k-means\n\t\\item Local minima\n\t\\item Need to know number of components K – Solutions: model selection (AIC, BIC), Dirichlet process mixture\n\t\\item  Need to choose blob generative model (math form of a cluster?)\n\t\\item Numerical problems are often a nuisance\n\\end{itemize}\n\n\\subsubsection{Mean-Shift Algorithm}\nChoose features (color, gradients, texture, etc)\n\\begin{enumerate}\n\t\\item Initialize random seed center and window size $W$\n\t\\item Calculate center of gravity (the “mean”) of $W$: $ \\sum_{x \\in W} x H(x) $\n\t\\item Shift the search window to the mean\n\t\\item Repeat steps 2+3 until convergence for all centers\n\t\\item merge windows that end up near the same peak/center\n\\end{enumerate}\n\n\\includegraphics[width=\\columnwidth]{pictures/meanshift}\n\nPro:\n\\begin{itemize}\n\t\\item General, application-independent tool\n\t\\item Model-free, does not assume any prior shape (spherical, elliptical, etc.) on data clusters\n\t\\item Just a single parameter (window size h) – h has a physical meaning (unlike k-means) == scale of clustering\n\t\\item Finds variable number of modes given the same h \n\t\\item Robust to outliers\n\\end{itemize}\nCons:\n\\begin{itemize}\n\t\\item Output depends on window size h\n\t\\item Window size (bandwidth) selection is not trivial\n\t\\item Computationally rather expensive\n\t\\item Does not scale well with dimension of feature space\n\\end{itemize}\n\n\\subsection{Hough transform}\nsee chapter before\n\n\\subsection{Interactive Segmentation with GraphCuts}\nMarkov Random Fields\n\n\\includegraphics[width=\\columnwidth]{pictures/markovfields}\n\nField Joint Probability\n\n\\includegraphics[width=0.7\\columnwidth]{pictures/fieldjointprobability}\n\n\\includegraphics[width=\\columnwidth]{pictures/energyfunction}\nUnary potentials $\\Phi$\n\\begin{itemize}\n\t\\item Encode local information about the given pixel/patch\n\t\\item How likely is a pixel/patch to be in a certain state (e.g. foreground/background)\n\\end{itemize}\nPairwise potentials $\\Psi$\n\\begin{itemize}\n\t\\item Ecode neighborhood information\n\t\\item How different is a pixel/patch's label from that of its neighbor (e.g. here independent of image data, but later based on intensity/color/texture difference)\n\\end{itemize}\n\nGoal: minimum cost cut\n\n\\includegraphics[width=\\columnwidth]{pictures/s-t-min-cut}\n\nMaxflow Algorithm\n\\begin{enumerate}\n\t\\item Find path from source to sink with positive ! capacity\n\t\\item push maximum possible flow through this path (subtract it from all segments)\n\t\\item repeat until no path can be found\n\\end{enumerate}\n\nPro:\n\\begin{itemize}\n\t\\item Powerful technique, based on probabilistic model (MRF).\n\t\\item Applicable for a wide range of problems.\n\t\\item Very efficient algorithms available for vision problems.\n\t\\item Becoming a de-facto standard for many segmentation tasks.\n\\end{itemize}\nCons:\n\\begin{itemize}\n\t\\item Graph cuts can solve a limited (but useful) class of models\n\t\\item Submodular energy functions\n\t\\item Can capture only part of the expressiveness of MRFs\n\t\\item Only approximate algorithms available for multi-label case (except for special cases with particular topology and/or pairwise potentials)\n\\end{itemize}\n\n\\subsection{Learning-based approaches}\nExtract the same features used during training \\& Use the mapping learned before to label\n\n\\subsubsection{K-nearest neighbor}\nFor every point find the k nearest neighbors (labeled in the training set). The point is then defined through the lables of these neighbors (majority voting of these k neighbors)\n\nPro:\n\\begin{itemize}\n\t\\item Very simple to implement\n\t\\item Very simple to understand\n\t\\item efficient implementations possible for approx. NNs\n\t\\item distance definition is flexible\n\\end{itemize}\nCons:\n\\begin{itemize}\n\t\\item highly depends on the definitions and k\n\t\\item need to keep the entire data in memory for distance computations\n\t\\item for high dimensional problems might need many training samples for accuracy\n\t\\item other methods have better generalization ability\n\\end{itemize}\n\n\\subsubsection{Random forests}\nBinary decision trees - Random Forests are slow to train, but fast to apply during testing.\n\n\\includegraphics[width=\\columnwidth]{pictures/tree}\nTRaining: During training, samples are used for which the true class is known.\nHaving arrived at a node, one randomly generates a set of possible tests to carry out in order to split it up.\nAmong the possibilities one selects the test that maximally reduces the uncertainty. (biggest difference)\\\\\n\\\\\nTesting: Feed the current sample into every tree. See in which leaf node it ends -> (most probable) class. Combine the results, e.g. which class/label was found most often\n\nPro:\n\\begin{itemize}\n\t\\item Easy to implement\n\t\\item very efficient during testing\n\t\\item can easily use diverse features\n\t\\item can handle high dimensional spaces\n\\end{itemize}\nCons:\n\\begin{itemize}\n\t\\item Lots of parametric choices\n\t\\item needs large number of data\n\t\\item training can take time\n\\end{itemize}", "meta": {"hexsha": "10b134efed34ad799ca094ff19f9277d58bcd5bf", "size": 7824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/7_Image_Segmentation.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/7_Image_Segmentation.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/7_Image_Segmentation.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.9056603774, "max_line_length": 222, "alphanum_fraction": 0.7704498978, "num_tokens": 2039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6616480014170351}}
{"text": "% File:\t\tmakepass.tex\n% Author:\tSee Below\n% Date:\t        See Below\n%\n% The authors have placed this file in the public domain;\n% they make no warranty and accept no liability for this file.\n\n\\documentclass[12pt]{article}\n\\usepackage{times}\n\\begin{document}\n\\newcommand{\\problem}[1]{\\underline{\\Large \\bf #1}}\n\\renewcommand{\\section}[1]{\\bigskip\\underline{\\bf #1}\\\\}\n\\newcommand{\\header}[1]{\\underline{\\bf #1}}\n\\newcommand{\\file}[1]{{\\bf #1}}\n\\newcommand{\\blankpage}{\\newpage\\vspace*{3.5in}%\n    \\centerline{\\Large This Page is Intentionally Left Blank}}\n\\setlength{\\parindent}{0.0in}\n\\setlength{\\parskip}{1ex}\n\n\\problem{Make Passwords}\n\nIdeally a password would be a string of 10 (or more)\nrandomly chosen decimal digits.  But this tends to be hard\nto remember or type.\n\nYou are being asked to convert strings of decimal digits\ninto a more typeable and perhaps more memorable form using a 1-1 encoding.\nIn this encoding, groups of more than 3 digits are encoded\nas 3-letter word randomly chosen from a dictionary.\n\nSome examples are:\\hspace{0.2in}\n\\begin{tabular}[t]{r@{~~~~~{\\em is encoded as}~~~~~}l}\n161954595198532 & 88bem06fis \\\\\n174570539285673 & 5bid012loq \\\\\n417744241130258 & dav034zeq9 \\\\\n566373677809620 & sah9qub784 \\\\\n270281313141987 & 4dud456niz \\\\\n\\end{tabular}\n\nThe encoding algorithm uses a dictionary of all words\nof the form: \\\\\n\\hspace*{1in}$<consonant><vowel><consonant>$ \\\\\nsorted in\nlexical order, with {\\tt y} treated as a consonant.\nDictionary word $0$ is {\\tt \"bab\"} and word\n$21*5*21-1=2204$ is {\\tt \"zuz\"}.\n\nThen the encoding algorithm with input number $N$ is as follows:\n\\begin{enumerate}\n\\item Divide $N$ by 6 and use the remainder to select the\nencoding format thus:\n\\begin{tabular}{r@{~~~~~{\\em selects}~~~~~}l}\n0 & \\tt \"WWWDWWWDDD\" \\\\\n1 & \\tt \"WWWDDWWWDD\" \\\\\n2 & \\tt \"WWWDDDWWWD\" \\\\\n\\end{tabular}\n\\hspace{0.3in}\n\\begin{tabular}{r@{~~~~~{\\em selects}~~~~~}l}\n3 & \\tt \"DWWWDDDWWW\" \\\\\n4 & \\tt \"DDWWWDDWWW\" \\\\\n5 & \\tt \"DDDWWWDWWW\" \\\\\n\\end{tabular}\n\\item Process the format left to right.  If the next\ncharacter is {\\tt D}, divide $N$ by 10 and output the\nremainder.  If the next character is {\\tt W}, divide $N$\nby $21*5*21 = 2205$, use the remainder to look up\na word in the dictionary, output the word, and skip to\nafter the 3 {\\tt W}'s in the format.\n\\end{enumerate}\n\nFor example, $0+6*(0+2205*(1+10*(2204+2205*(2+10*(3+10*4)))))= 126315290430$\nis encoded as {\\tt bab1zuz234}.  Note you must use `{\\tt long}'\nintegers for C, C++, and JAVA, and that numbers input are treated\nmodule $6*(21*5*21)^2*10^4=291721500000$.\n\n\n\\section{Input}\nOne more lines each containing a non-negative integer\nwith at most 12 digits.  Input ends with an end of line.\n\n\n\\section{Output}\nFor each input line, output one line containing the\nencoded input integer.\n\n\\bigskip\n\n\\begin{center}\n\\begin{tabular}{ll}\n\\begin{minipage}[t]{2.5in}\n\\header{Sample Input}\n\\\\[1ex]\n\\file{00-000-makepass.sin:}\n\\begin{verbatim}\n0\n6\n13230\n132300\n291721500\n2917215000\n29172150000\n\\end{verbatim}\n\\file{00-001-makepass.sin:}\n\\begin{verbatim}\n0\n1\n2\n3\n4\n5\n\\end{verbatim}\n\\file{00-002-makepass.sin:}\n\\begin{verbatim}\n126315290430\n854595198532\n870539285673\n144241130258\n273677809620\n281313141987\n\\end{verbatim}\n\\end{minipage}\n&\n\\begin{minipage}[t]{2.5in}\n\\header{Sample Output}\n\\\\[1ex]\n\\file{00-000-makepass.sout:}\n\\begin{verbatim}\nbab0bab000\nbac0bab000\nbab1bab000\nbab0bac000\nbab0bab100\nbab0bab010\nbab0bab001\n\\end{verbatim}\n\\file{00-001-makepass.sout:}\n\\begin{verbatim}\nbab0bab000\nbab00bab00\nbab000bab0\n0bab000bab\n00bab00bab\n000bab0bab\n\\end{verbatim}\n\\file{00-002-makepass.sout:}\n\\begin{verbatim}\nbab1zuz234\n88pat25yiq\n5yuz930zok\nvac975yuf4\nlod3fan839\n4qol723zeh\n\\end{verbatim}\n\\end{minipage}\n\\end{tabular}\n\\end{center}\n\n\\bigskip\n\n\\begin{tabular}{ll}\nAuthor:\t      & Robert L.~Walton $<$walton@acm.org$>$ \\\\\nDate:         & Thu Oct  8 06:35:04 EDT 2020\n\\end{tabular}\n\nThe authors have placed this problem in the public domain;\nthey make no warranty and accept no liability for this problem.\n\n\\end{document}\n", "meta": {"hexsha": "515770ecb49566a62286098ed64cd705bbb97742", "size": 3993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/ed-crypto/makepass/+sources+/makepass.tex", "max_stars_repo_name": "RobertLWalton/epm_ed", "max_stars_repo_head_hexsha": "09e966364c5b9b2ab38bb78def1d680e231f889d", "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": "projects/ed-crypto/makepass/+sources+/makepass.tex", "max_issues_repo_name": "RobertLWalton/epm_ed", "max_issues_repo_head_hexsha": "09e966364c5b9b2ab38bb78def1d680e231f889d", "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": "projects/ed-crypto/makepass/+sources+/makepass.tex", "max_forks_repo_name": "RobertLWalton/epm_ed", "max_forks_repo_head_hexsha": "09e966364c5b9b2ab38bb78def1d680e231f889d", "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": 23.6272189349, "max_line_length": 76, "alphanum_fraction": 0.7237665915, "num_tokens": 1376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6616479963573922}}
{"text": "\\chapter{Factoring Polynomials}\n\nWe factor a polynomial into two or more polynomials of lower\ndegree. For example, let's say that you wanted to factor\n$5x^3 - 45x$. You would note that you can factor out $5x$ from every term. Thus,\n\\begin{equation*}\n5x^3 - 45x = (5x)(x^2 - 9)\n\\end{equation*}\nAnd then, you might notice that the second factor looks like the difference of squares, so\n\\begin{equation*}\n5x^3 - 45x = (5x)(x + 3)(x - 3)\n\\end{equation*}\nThat is as far as we can factorize this polynomial.\\index{factoring polynomials}\n\nWhy do we care? The factors make it easy to find the roots of the\npolynomial. This polynomial evaluates to zero if and only if at least\none of the factors is zero. Here we see that\n\\begin{itemize}\n\\item The factor $(5x)$ is zero when $x$ is zero.\n\\item The factor $(x + 3)$ is zero when $x$ is -3.\n\\item The factor$(x - 3)$ is zero when $x$ is 3.\n\\end{itemize}\nSo looking at the factorization, you can see\nthat $5x^3 - 45x$ is zero when $x$ is 0, -3, or 3. \n\nThis is a graph of that polynomial with its roots circled:\n\n\\includegraphics{factor4roots}\n\n\\section{How to factor polynomials}\n\nThe first step when you are trying to factor a polynomial is to find\nthe greatest common divisor for all the terms, and pull that out. In\nthis case, the greatest common divisor will also be a monomial: its\ndegree is the least of the degrees of the terms, its coefficient will\nbe the greatest common divisor of the coefficients of the terms.\n\nFor example, what can you pull out of this polynomial?\n\\begin{equation*}\n12x^100 + 30x^31 + 42x^17\n\\end{equation*}\nThe greatest common divisor of the coefficients (12, 30, and 42) is 6.  The least of the degrees of terms (100, 31, and 17) is 17.  So you can pull out $6x^17$:\n\\begin{equation*}\n12x^100 + 30x^31 + 42x^17 = (6x^17)(2x^83 + 5x^14 + 7)\n\\end{equation*}\n\n\\begin{Exercise}[title={Factoring out the GCD monomial}, label=gcdmonomial]\n  \n\\end{Exercise}\n\\begin{Answer}[ref=gcdmonomial]\n  \n\\end{Answer}\n\nSo, now you have the product of a monomial and a polynomial. If you\nare lucky, the polynomial part looks familiar, like the difference of\nsquares or a row from Pascal's triangle.\n\nOften you are trying factor a quadratic like $x^2 + 5x + 6$ in a pair\nof binomials. In this case, the result would be $(x + 3)(x + 2)$. Let's check that:\n\\begin{equation*}\n  (x + 3)(x + 2) = (x)(x) + (3)(x) + (2)(x) + (3)(2) = x^2 + 5x + 6\n\\end{equation*}\nNotice that 3 and 2 multiply to 6 and add to 5. If I were trying to\nfactor $x^2 + 5x + 6$, I would ask myself''What are two numbers that\nwhen multiplied equal 6 and when added equal 5?'' And I would might\nguess wrong a couple of times. For example, I might say to myself\n``Well, 6 times 1 is 6. Maybe those work. But 6 and 1 add 7. So those\ndon't work.''\n\nSolving these sorts of problems are like solving a Sudoku puzzle: you\ntry things and realize they are wrong, so you backtrack and try\nsomething else.\n\nThe numbers are sometimes negative. For example, $x^2 + 3x - 10$ factors into $(x + 5)(x - 2)$.\n\n\\begin{Exercise}[title={Factoring quadratics}, label=factorquadratics]\n  \n\\end{Exercise}\n\\begin{Answer}[ref=factorquadratics]\n  \n\\end{Answer}\n", "meta": {"hexsha": "260f7df7fd6af8d098df6492cad7f8fb495bcbcf", "size": 3153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/factoring-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/factoring-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/factoring-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": 38.4512195122, "max_line_length": 160, "alphanum_fraction": 0.7177291468, "num_tokens": 1006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004187, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.661638187844168}}
{"text": "\\chapter{Functional form for the prior}\\label{appendix:prior_function}\n\\paragraph{} \\cite{2006A&A...457..841I} devise a functional form for the prior $P(z, T | m_{0})$, by once more using Bayes' theorem to obtain: \n\n\\begin{equation}\nP(z, T | m_{0}) = P(T | m_{0}) P(z | T, m_{0}). \\label{eqn:prior}\n\\end{equation}\n\n$P(z|T, m_{0})$ is parameterised as:\n \n\\begin{equation}\nP(z|T,m_{0})  \\propto z^{\\alpha_{T}}\\exp{-\\left[ \\frac{z}{z_{oT}+k_{mT}(m_{0} -20)} \\right]},\\label{eqn:redshift_distr}\n\\end{equation}\n\n\\noindent where $\\alpha_{T}$, $z_{0T}$, $k_{mT}$ are free parameters and $T$ encapsulates the dependence on spectral type. The other part of Equation \\ref{eqn:prior}, $P(T|m_{0})$, gives the magnitude distribution of spectral types and is parameterised as\n\n\\begin{equation}\nP(T|m_{0}) = f_{T} e^{-k_{T}(m_{0}-20)},\\label{eqn:spectral_distr}\n\\end{equation}\n\nwhere $k_{T}$ is a free parameter  and $f_{T}$ is the fraction of each type at $m_{0} = 20 \\textrm{ mag AB}$. Following the formalism in \\cite{2000ApJ...536..571B}, \\cite{2006A&A...457..841I} calibrated the values for all four free parameters using a deep and representative $I$-selected spectroscopic sample from VVDS \\citep{2005A&A...439..845L} using data from a (different) $i'$ band for $m_{0}$. To quantify the dependence on spectral type, the sample was divided into four different spectral type groups (according to the four optimised CWW  templates [\\cite{1980ApJS...43..393C}, \\cite{2006A&A...457..841I}]). For each group,  $f_T$ and $k_T$ were determined by fitting Equation \\ref{eqn:spectral_distr} to the observed magnitude distribution. Likewise, the redshift distrubution of each spectral type group was fitted to {\\color{red} Equation \\ref{eqn:redshift_distr}} to obtain $\\alpha_{T}$, $z_{0,T}$ and $k_{mT}$. \n", "meta": {"hexsha": "1df29076a2818cb534ba6a48224b588c012be988", "size": 1789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix2/appendix2.tex", "max_stars_repo_name": "ASchooneveld/MScThesisDraft", "max_stars_repo_head_hexsha": "ee4de09799f9e95a91863bd403f2da8fa9f20961", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendix2/appendix2.tex", "max_issues_repo_name": "ASchooneveld/MScThesisDraft", "max_issues_repo_head_hexsha": "ee4de09799f9e95a91863bd403f2da8fa9f20961", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendix2/appendix2.tex", "max_forks_repo_name": "ASchooneveld/MScThesisDraft", "max_forks_repo_head_hexsha": "ee4de09799f9e95a91863bd403f2da8fa9f20961", "max_forks_repo_licenses": ["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.1904761905, "max_line_length": 924, "alphanum_fraction": 0.7093348239, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.661611508382877}}
{"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{tfrridb}\n\\section*{\\hspace*{-1.6cm} tfrridb}\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}\nReduced Interference Distribution with Bessel kernel.\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] = tfrridb(x)\n[tfr,t,f] = tfrridb(x,t)\n[tfr,t,f] = tfrridb(x,t,N)\n[tfr,t,f] = tfrridb(x,t,N,g)\n[tfr,t,f] = tfrridb(x,t,N,g,h)\n[tfr,t,f] = tfrridb(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        Reduced Interference Distribution with a kernel based on the Bessel\n        function of the first kind.  {\\ty tfrridb} computes either the\n        distribution of a discrete-time signal {\\ty x}, or the cross\n        representation between two signals. This distribution writes\n\\begin{eqnarray*}\nRIDB_x(t,\\nu)&=&\\int_{-\\infty}^{+\\infty} h(\\tau) R_x(t,\\tau)\\,\ne^{-j2\\pi\\nu\\tau}\\ d\\tau\\\\\n{\\rm with}\\quad\nR_x(t,\\tau)&=&\n\\int_{t-|\\tau|}^{t+|\\tau|}\\ \n\\dfrac{2\\ g(v)}{\\pi|\\tau|}\\ \\sqrt{1-\\left(\\frac{v-t}{\\tau}\\right)^2} \nx(v+\\frac{\\tau}{2})\\ x^*(v-\\frac{\\tau}{2})\\ dv.\n\\end{eqnarray*}\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-RIDB, or {\\ty [x1,x2]} if cross-RIDB ({\\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 g}     & time smoothing window, {\\ty G(0)} being forced to\n\t\t{\\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 output arguments, {\\ty tfrridb} 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(31,'rect'); h=window(63,'rect');  \n         tfrridb(sig,1:128,128,g,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] Z. Guo, L.G. Durand, H.C. Lee ``The Time-Frequency Distributions of\nNonstationary Signals Based on a Bessel Kernel'' IEEE Trans. on Signal\nProc., vol 42, pp. 1700-1707, july 1994.\n\\end{minipage}\n\n", "meta": {"hexsha": "9135bad38d9030de26ee353268fe3d0a0d2024ca", "size": 3118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrridb.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/tfrridb.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/tfrridb.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.8712871287, "max_line_length": 84, "alphanum_fraction": 0.5936497755, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6616115010811741}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\usepackage{microtype}\n\\usepackage{amsfonts}\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\n\\newcommand{\\dpar}[1]{\\left(#1\\right)}\n\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\theoremstyle{definition}\n\\newtheorem{ex}{Exercise}[section]\n\n\\title{Physics 1: Class 4}\n\\author{Max Jauregui}\n\n\\begin{document}\n\\maketitle\n\n\\section{Acceleration}\n\nLet us consider a particle that moves along a straight line and let us\nsuppose that we know the velocities of the particle at the instants\n$t_1$ and $t_2$. We define the \\emph{average acceleration} of the\nparticle bewteen $t_1$ and $t_2$ as\n$$\\overline{a}=\\frac{v(t_2)-v(t_1)}{t_2-t_1}\\,.$$\nIn addition, we define the \\emph{instantaneous acceleration} of the\nparticle at an instant $t$ by\n$$a(t)=\\lim_{\\Delta t\\to 0}\\frac{v(t+\\Delta t)-v(t)}{\\Delta t}=\\frac{dv}{dt}\\,.$$\nSince $v(t)=dx/dt$, it follows from the last equation that\n$$a(t)=\\frac{d}{dt}\\dpar{\\frac{dx}{dt}}=\\frac{d^2x}{dt^2}\\,,$$\nwhere the last term is called the second derivative of the function\n$x$ at the point $t$.\n\nSince $a(t)$ is the derivative of the velocity at the instant $t$, in\na $v$ vs $t$ graph, $a(t)$ will be given by the slope of the line that\nis tangent to the curve at the instant $t$. On the other hand, since\n$a(t)$ is the second derivative of the position at the instant $t$, in\nan $x$ vs $t$ graph, $a(t)$ will be given by the curvature of the\ncurve at the instant $t$. Basically, a curve has positive curvature at\na point if it has the form $\\smile$ and negative curvature if it has\nthe form $\\frown$. An inflection point of a curve is a point where the\ncurvature changes its sign. The curvature of the curve at this point\nis zero.\n\n\\begin{ex}\n  Let $x(t)=5t^3-10t+2$ be the position of a particle in meters, where\n  $t$ is measured in seconds. Find the acceleration of the particle at\n  the instant $1\\,\\mathrm{s}$. \\emph{Answer:}\n  $a(1)=30\\,\\mathrm{m/s^2}$.\n\\end{ex}\n\n\\begin{ex}\n  Considering the $x$ vs $t$ graph given in Fig.~\\ref{fig:xvst},\n  answer the following:\n  \\begin{enumerate}\n  \\item[(i)] What are the signs of the acceleration between the\n    instants $1\\,\\mathrm{s}$ and $2\\,\\mathrm{s}$?\n  \\item[(ii)] Is the acceleration negative in some instant between\n    $4\\,\\mathrm{s}$ and $6\\,\\mathrm{s}$?\n  \\item[(iii)] What is the sign of the acceleration when the velocity\n    of the particle attains its maximum value?\n  \\item[(iv)] Is there an instant where the acceleration is zero?\n  \\end{enumerate}\n  \\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth,keepaspectratio]{figures/xvst.pdf}\n    \\caption{$x$ vs $t$ graph.}\n    \\label{fig:xvst}\n  \\end{figure}\n\\end{ex}\n\n\\section{Constant acceleration}\n\nLet us consider a particle that moves in a straight line with constant\nacceleration $a_0$, i.e., $a(t)=a_0$ for all $t\\ge 0$. We will be\ninterested in obtaining the expression of the position of the particle\nat an arbitrary instant $t$.\n\nWe begin by observing that, since $a(t)$ is the derivative of the\nvelocity at the instant $t$, in an analogous way to the case when we\nobtained the position of a particle from the expression of its\nvelocity, we will have\n$$v(t)-v(t_0)=\\int_{t_0}^{t}a(t')\\,dt'=a_0(t-t_0)\\,.$$\nThen,\n\\begin{equation}\n  \\label{eq:1}\n  v(t)=v_0+a_0(t-t_0)\\,,\n\\end{equation}\nwhere $v_0=v(t_0)$.  Now, the displacement of the particle between two\ninstants $t_0$ and $t$ is given by\n$$x(t)-x(t_0)=\\int_{t_0}^{t}v(t')\\,dt'=v_0(t-t_0)+\\frac{a_0}{2}(t^2-t_0^2)-a_0t_0(t-t_0)\\,.$$\nHence,\n\\begin{equation}\n  \\label{eq:2}\n  x(t)=x_0+v_0(t-t_0)+\\frac{a_0}{2}(t-t_0)^2\\,,\n\\end{equation}\nwhere $x_0=x(t_0)$.\n\nFrom Eqs.~(\\ref{eq:1}) and~(\\ref{eq:2}) we can obtain other useful\nequations. For instance, it follows from Eq.~(\\ref{eq:1}) that\n$$t-t_0=\\frac{v(t)-v_0}{a_0}\\,.$$\nUsing this in Eq.~(\\ref{eq:2}), we can obtain that\n$$v^2(t)-v_0^2=2a_0[x(t)-x_0]\\,.$$\nMoreover, using the expression of $a_0$, obtained from\nEq.~(\\ref{eq:1}), we obtain\n$$x(t)-x_0=\\dpar{\\frac{v(t)+v_0}{2}}(t-t_0)\\,.$$\n\n\\end{document}\n", "meta": {"hexsha": "c683435777b21b562ee4df099cf2ef8c6fbf5cc8", "size": 4026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fisica1/aula4.tex", "max_stars_repo_name": "maxjaure/UEM-DFI", "max_stars_repo_head_hexsha": "fe1b3ba629ab475d92b6140f49cf397f0b6120fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-25T18:25:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-25T18:25:46.000Z", "max_issues_repo_path": "fisica1/aula4.tex", "max_issues_repo_name": "maxjaure/UEM-DFI", "max_issues_repo_head_hexsha": "fe1b3ba629ab475d92b6140f49cf397f0b6120fc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fisica1/aula4.tex", "max_forks_repo_name": "maxjaure/UEM-DFI", "max_forks_repo_head_hexsha": "fe1b3ba629ab475d92b6140f49cf397f0b6120fc", "max_forks_repo_licenses": ["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.2702702703, "max_line_length": 93, "alphanum_fraction": 0.6902632886, "num_tokens": 1408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.6616114981762843}}
{"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\\subgroup{2}{Ruitong Zhu and Qingan Zhao}\r\n\r\n\\paragraph{Model presentation}\r\nThis part is to simulate the vibrating string (i.e., 1D wave equation) and present its displacement with a time-varying image. The string held stationary at both ends and free to vibrate transversely subject only to the restoring forces due to tension in the string. $Figure 1$ shows coordinates and definies symbols for the transverse vibrating string. \r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{string.jpg}       \r\n\t\\caption{Vibrating String}\r\n\\end{figure}\r\n\r\nThe partial differential equation (PDE) of this problem is given as follow:\r\n\r\n\\begin{equation}\r\n\t\\frac{\\partial^2 h}{\\partial t^2}=a^2\\left(\\frac{\\partial^2 h}{\\partial x^2}\\right)\r\n\\end{equation}\r\n\r\nwhere $h$ is the wave function $h(x,t)$, representing the displacement of the string at position $x$ and time $t$; $a$ is the wave speed which equals to $\\sqrt{E/\\rho}$.\r\n\r\n\\paragraph{Implementation}\r\n\r\nThe simluation is based on Finite Difference Method (FDM). Using second-order central difference at time $t_n$ and position $x_i$, we can get the recurrence equation as follow:\r\n\r\n\\begin{equation}\r\n\\frac{u_{i}^{N+1}-2u_{i}^{N}+u_{i}^{N-1}}{\\Delta t^2} = a^2\\frac{u_{i+1}^{N}-2u_{i}^{N}+u_{i-1}^{N}}{\\Delta x^2}\r\n\\end{equation}\r\n\r\nAssume the wave speed $a = 1$; the length of the string $L$ is $2$; the maxium time for this simulation is $4$; stepsize $\\Delta x$ and $\\Delta t$ are both equal to $0.01$. The initial condition and the boundary condition are described as follows:\r\n\\begin{eqnarray}\r\nh(x,0)&=&sin(\\pi x)\\\\\r\n\\frac{\\partial h}{\\partial t}\\bigg |_{(x,0)}&=&0\\\\\r\nh(0,t)&=&h(2,t)=0\r\n\\end{eqnarray}\r\n\r\nHere we offer the implementation in Python:\r\n\r\n\\begin{python}\r\n\t## parameter\r\n\ta = 1  ## a coefficient of stiffness\r\n\tL = 2  ## The string is constrained at x=0 and x=L.\r\n\tT = 4  ## maxium time for this simulation.\r\n\tdx = 0.01  ## time step\r\n\tdt = 0.01  ## distance step\r\n\tN = int(L/dx);\r\n\tM = int(T/dt);\r\n\tr = (a*dt/dx)**2  ## a parameter\r\n\r\n\t## initial shape of the string\r\n\tdef initial(x):\r\n\ttmp = math.sin(math.pi*x)\r\n\treturn tmp\r\n\t\r\n\t## initial speed of the string\r\n\tdef speed(x):\r\n\ttmp = 0\r\n\treturn tmp\r\n\t\r\n\t## Define an array and a blank matrix for later use.\r\n\tx = [0]\r\n\th = np.zeros((M+1, N+1))\r\n\t\r\n\t## t=0, initial condition\r\n\tfor i in range(N):\r\n\tx.append(x[i] + dx)  ## x axis\r\n\th[0,i+1] = initial(x[i+1])  ## displacement of the string\r\n\t\r\n\t## t=dt, the first itertaion\r\n\tfor i in range(N-1):\r\n\th[1,i+1] = h[0,i+1] + r* (h[0,i] + h[0,i+2] - 2*h[0,i+1])/2 + dx*speed(x[i+1])\r\n\t## displacement of the string\r\n\t\r\n\t## t=n*dt where n>1\r\n\tfor j in range(1, M):\r\n\tfor i in range(N-1):\r\n\th[j+1,i+1] = (h[j,i+2]+h[j,i]-2*h[j,i+1])*r-h[j-1,i+1]+2*h[j,i+1]\r\n\t## displacement of the string\r\n\t\r\n\tt = [0]\r\n\tfor j in range(M):\r\n\tt.append(t[j] + dt)  ## t axis\r\n\t\r\n\t## Plot the 3D figure.\r\n\tfig = plt.figure()\r\n\tax = Axes3D(fig)\r\n\tX, T= np.meshgrid(x,t)\r\n\tax.plot_surface(X, T, h, cmap='rainbow')\r\n\tax.set_xlabel('X')\r\n\tax.set_ylabel('T')\r\n\tax.set_zlabel('h')\r\n\tplt.show()\r\n\t\r\n\t## Plot the shape of string at different time\r\n\tfor i in range(4):\r\n\tplt.xlabel(u'x',fontsize=14)\r\n\tplt.ylabel(u'h',fontsize=14)\r\n\tplt.show()\r\n\\end{python}\r\n\r\n\\paragraph{Results}\r\n\r\nThe dynamic change of the string is shown in $Figure 2$, ranging from $0\\sim 4$.\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{string3d.png}       \r\n\t\\caption{Time-varying Image of the string}\r\n\\end{figure}\r\n\r\nMore specifically, the shapes of the string at different times are shown below:\r\n\r\n\\begin{figure}[ht]\r\n\t\\centering\r\n\t\\begin{minipage}{8cm}\r\n\t\t\\includegraphics[width=7cm]{string0.png}   \r\n\t\t\\caption*{t=0}\r\n\t\t\\end{minipage}    \r\n\t\\begin{minipage}{8cm}\r\n\t\t\\includegraphics[width=7cm]{string0_5.png}   \r\n\t\t\\caption*{t=0.5}\r\n\t\\end{minipage}  \r\n\r\n    \\begin{minipage}{8cm}\r\n    \t\\includegraphics[width=7cm]{string1.png}   \r\n    \t\\caption*{t=1}\r\n        \\end{minipage}  \r\n    \\begin{minipage}{8cm}\r\n    \t\\includegraphics[width=7cm]{string1_5.png}  \r\n    \t\\caption*{t=1.5} \r\n    \\end{minipage}  \r\n\t\\caption{Shape of the string at time t}\r\n\\end{figure}\r\n\r\n\r\n\r\n\\paragraph{Interpretation}\r\n\r\nThe results are consistent with our expectation. The shape of the string depends on the initial and boundary conditions. In this case, the string is in the shape of a sine wave that changes periodically. \r\n\r\nThe initial and boundary conditions can be changed easily at the code by modifying the function $initial()$ and $speed()$. Readers can plot more complicated image with different initial displacement and speed function.\r\n\r\n\\paragraph{Conclusion}\r\nFinite Difference Method is a practical method to obtain the numerical solution of a Partial Differential Equation. We can learn that it is applicable for one dimentional problems like 1D wave equation and 1D heat equation. It's not difficult to understand but there are some places worth special attention while writing the code. For example, the first iteration needs to be distinguished from other iterations since $t_{N-1}$ is not defined. \r\n\r\n", "meta": {"hexsha": "45289836452251153c59095fe3f43fded328ea67", "size": 5462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "simulation-1Dstring.tex", "max_stars_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_stars_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-29T06:19:28.000Z", "max_issues_repo_path": "simulation-1Dstring.tex", "max_issues_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_issues_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "simulation-1Dstring.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": 36.1721854305, "max_line_length": 445, "alphanum_fraction": 0.6548883193, "num_tokens": 1606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6614266370382094}}
{"text": "\n\n\\chapter{Multiscale Methods on the Sphere}\n\\label{ch_mms}\n\n\\section{Wavelet Transform on the Sphere}\n\\label{sect_wts}\n\n\\subsection{Isotropic Undecimated Wavelet Transform on the Sphere (UWTS) }\n\\index{wavelet!undecimated wavelet transform}\r\n\nThere are clearly many different possible implementations of a wavelet transform on the sphere and their performances depend on the application. \r\nWe describe here an undecimated isotropic transform which is similar in many respects to the \\emph{ \\`a trous} algorithm, and is therefore a good \ncandidate for restoration applications. Its isotropy is a favorable property when analyzing a statistically isotropic Gaussian field such as the \nCMB, or data sets such as maps of galaxy clusters, which contain only isotropic features~\\cite{starck:book98}. Our isotropic transform is obtained \nusing a scaling function $\\phi_{l_c}(\\vartheta, \\varphi)$ with cut-off frequency $l_c$ and azimuthal symmetry, meaning that $\\phi_{l_c}$ does not \ndepend on the azimuth $\\varphi$. Hence the spherical harmonic coefficients $\\hat \\phi_{l_c} (l,m)$ of $\\phi_{l_c}$ vanish when $m \\ne 0$ so that :\r\n\\begin{eqnarray}\r\n\\phi_{l_c}(\\vartheta, \\varphi)= \\phi_{l_c}(\\vartheta) = \\sum_{l = 0}^{l = l_c} \\hat \\phi_{l_c} (l,0) Y_{l,0}(\\vartheta, \\varphi)\r\n\\end{eqnarray}\nwhere the $Y_{l,m}$ are the spherical harmonic basis functions. Then, convolving a map $f(\\vartheta, \\varphi)$ with $\\phi_{l_c}$ is greatly simplified \r\nand the spherical harmonic coefficients $\\hat c_{0}(l,m)$ of the resulting map $c_0(\\vartheta, \\varphi)$ are readily given by \\cite{bogdanova}:\r\n\\begin{eqnarray}\\label{eq:conv}\n \\hat c_{0}(l,m) = \\widehat{\\phi_{l_c} * f} (l,m) = \\sqrt{\\frac{4\\pi}{2l+1} } \\hat \\phi_{l_c} (l,0) \\hat f(l,m) \n\\end{eqnarray}\nwhere $*$ stands for convolution.\n\n\\subsubsection*{From one resolution to the next one}\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\r\n\\begin{eqnarray}\r\nc_0   & = &  \\phi_{ l_{c} }  * f    \\nonumber    \\\\\r\nc_1   & = &  \\phi_{2^{-1} l_{c} }   * f    \\nonumber\t   \\\\\r\n&\\ldots&\\nonumber\\\\ \r\nc_j    &=&   \\phi_{2^{-j}  l_{c}  }  * f  \\nonumber    \\\\\r\n\\end{eqnarray}\r\nwhere $\\phi_{2^{-j} l_{c} }$ is a rescaled version of $\\phi_{l_{c}}$ with cut-off frequency $2^{-j} l_{c}$. The above multi-resolution sequence \ncan actually be obtained recursively. Define a low pass filter $h_{j}$ for each scale $j$ by \r\n%\\begin{eqnarray}\r\n %\\hat h_{j}(l,m) = \\left\\{\r\n%  \\begin{array}{ll}\r\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}} \\\\\r\n%0 & \\mbox{otherwise } \\ \r\n % \\end{array}\r\n  %\\right.\r\n%\\end{eqnarray}\r\n\\begin{eqnarray}\r\n \\hat{H}_{j}(l,m) = \\sqrt{\\frac{4\\pi}{2l+1} }  \\hat h_{j}(l,m) = \\left\\{\r\n  \\begin{array}{ll}\r\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\\\\\r\n0 & \\mbox{otherwise } \\ \r\n  \\end{array}\r\n  \\right.\r\n\\end{eqnarray}\nIt is then easily shown that $c_{j+1}$ derives from $c_j$ by convolution with $h_j$:  $c_{j+1} = c_{j} * h_j$.\r\n\r\n\\subsubsection*{The wavelet coefficients}\n\nGiven an asymmetrical wavelet function $\\psi_{l_c}$, we can derive in the same way a high pass filter $g_j$ on each scale $j$:\r\n%\\begin{eqnarray}\r\n%\\hat{g}_{j}(l,m) = \\left\\{\r\n%  \\begin{array}{ll}\r\n%  \\frac{\\hat{\\psi}_{2l_{c}}}{\\hat{\\phi}_{l_{c}}} & \\mbox{if }  l  < l_{c} \\\\\r\n%1 & \\mbox{otherwise } \\ \r\n%  \\end{array}\r\n%  \\right.\r\n%\\end{eqnarray}\n\\begin{eqnarray}\r\n \\hat{G}_{j}(l,m) = \\sqrt{\\frac{4\\pi}{2l+1} }  \\hat{g}_{j}(l,m) = \\left\\{\r\n  \\begin{array}{ll}\r\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\\\\ \r\n1 &\\mbox{if }  l  \\ge \\frac{ l_{c}} {2^{j+1}} \\quad \\textrm{and}\\quad m = 0\\\\ \n0&  \\mbox{otherwise }\\\r\n  \\end{array}\r\n  \\right.\r\n\\end{eqnarray}\r\nUsing these, the wavelet coefficients $w_{j+1} $ at scale $j+1$ are obtained from the previous resolution by a simple convolution: $w_{j+1} = c_{j} * g_j$.\\\\\r\n\r\nJust as with the \\emph{\\`a trous} algorithm, the wavelet coefficients can be defined as the difference between two consecutive resolutions, \n$w_{j+1}(\\vartheta, \\varphi) = c_{j}(\\vartheta, \\varphi) - c_{j+1}(\\vartheta, \\varphi)$, which in fact corresponds to making the following \nspecific choice for the wavelet function $\\psi_{l_c}$:\r\n\\index{wavelet!\\`a trous}\r\n%\\begin{eqnarray}\r\n%\\hat \\psi(l,m) = \\hat \\phi_{l_c} (l,m)  - \\hat \\phi_{l_c/2}(l,m)\r\n%\\end{eqnarray}\n\\begin{eqnarray}\r\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)\r\n\\end{eqnarray}\r\nThe high pass filters $g_j$ defined above are, in this particular case, expressed as: \r\n%\\begin{eqnarray}\r\n%\\hat{g}_{j}(l,m) =  1 - \\hat{h}_j(l,m)  \r\n%\\end{eqnarray}\r\n\\begin{eqnarray}\r\n \\hat{G}_{j}(l,m) = \\sqrt{\\frac{4\\pi}{2l+1} } \\hat{g}_{j}(l,m) =  1 - \\sqrt{\\frac{4\\pi}{2l+1} } \\hat{h}_j(l,m)   =   1 - \\hat{H}_j(l,m) \r\n\\end{eqnarray}\r\nObviously, other wavelet functions could be used just as well.\r\n\r\n\n\\subsubsection*{Choice of the scaling function}\n\\index{scaling function}\rAny function with a cut-off frequency is a possible candidate. We retained here a B-spline function of order 3. It is quite similar to a \nGaussian function and converges rapidly to $0$:\r\n%\\begin{eqnarray}\r\n%\\hat \\phi_{l_c} (l,m) =\\frac{3}{2} B_{3\\ \\frac{l}{l_{c}}m}\r\n%\\end{eqnarray}\n\\begin{eqnarray}\r\n\\hat \\phi_{l_c} (l,m = 0) =\\frac{3}{2} B_{3}( \\frac{2 l}{l_{c} })  % \\quad \\textrm{where} \\quad   B_3(x) = \\frac{1}{12}({\\mid{x-2}\\mid}^3 - 4 {\\mid{x-1}\\mid}^3 + 6 {\\mid{x}\\mid}^3 - 4 {\\mid{x+1}\\mid}^3 + {\\mid{x+2}\\mid}^3)\r\n\\end{eqnarray}\r\nwhere $B(x) = \\frac{1}{12}({\\mid{x-2}\\mid}^3 - 4 {\\mid{x-1}\\mid}^3 + 6 {\\mid{x}\\mid}^3 - 4 {\\mid{x+1}\\mid}^3 + {\\mid{x+2}\\mid}^3)$.\r\n\n\\begin{figure*}[htb]\r\\centerline{\r\\hbox{\r% \\psfig{figure=ch1_diff_uv_phi_psi.ps,bbllx=0.5cm,bblly=13.5cm,bburx=20.5cm,bbury=27cm,height=5cm,width=14.5cm,clip=}\r\\psfig{figure=fig_sphere_filterbank.pdf,bbllx=2cm,bblly=21cm,bburx=20cm,bbury=26cm,height=7cm,width=14.5cm,clip=}\r}}\r\\caption{On the left, the scaling function $\\hat{\\phi}$ and, on the \rright, the wavelet function $\\hat{\\psi}$.}\r\\label{fig_diff_uv_phi_psi}\r\\end{figure*}\r\rIn Fig.~\\ref{fig_diff_uv_phi_psi} the chosen scaling function derived from a $B$-spline of degree 3, and its resulting wavelet function, are plotted in frequency space.\r\\index{B-spline}\r\n\n\n\\begin{center}\r\n\\begin{tabular}{|c|} \\hline\r\n\\begin{minipage}[b]{5.3in}\r\n\\vspace{0.1in}\r\n\r\n\\small{\r\n\\textsf{1. Compute the $B_3$-spline scaling function and derive $\\psi$, $h$ and $g$ numerically.}\r\n\r\n\\textsf{2. Compute the corresponding Spherical Harmonics of image $c_0$. We get ${\\hat c}_0$.}\r\n\r\n\\textsf{3. Set $j$ to $0$. Iterate:}\r\n\r\n\\hspace{0.3in} \\textsf{4. Multiply  $\\hat{c}_j$ by $\\widehat H_{j}$. We get the array $\\hat{c}_{j+1}$.}\r\n\r\n\\hspace{0.33in} \\textsf{Its inverse Spherical Harmonics Transform gives the image at scale $j+1$.}\r\n\r\n\\hspace{0.3in} \\textsf{5. Multiply $\\hat{c}_j$ by $\\widehat G_{j}$. We get the complex array\r\n$\\hat{w}_{j+1}$.}\r\n\r\n\\hspace{0.33in} \\textsf{ The inverse Spherical Harmonics transform of $\\hat{w}_{j+1}$ \r\ngives the wavelet coefficients $w_{j+1}$ at scale $j+1$.}\r\n\r\n\\hspace{0.3in} \\textsf{6. j=j+1 and if $j \\leq  J$, return to Step 4.}\r\n\r\n\\textsf{9. The set $\\{w_1, w_2, \\dots, w_{J}, c_{J}\\}$ describes the wavelet transform on the sphere of $c_0$.}}\r\n\n\\vspace{0.05in}\n\\end{minipage}\n\\\\\\hline\n\\end{tabular}\n\\\\ \\vspace{0.1in}\nThe numerical algorithm for the undecimated wavelet transform on the sphere.\n\\end{center}\n\\linespread{1.3}\n\\index{algorithm!undecimated wavelet transform}\r\n\nIf the wavelet is the difference between two resolutions, Step 5 in the above UWTS algorithm can be replaced by the following simple subtraction $w_{j+1} = c_{j} - c_{j+1}$.\n\n\\subsubsection*{Reconstruction}\n\\index{wavelet!undecimated wavelet reconstruction}\rWhen the wavelet is the difference between two resolutions, the reconstruction of an image from its wavelet coefficients ${\\cal W} = \\{w_1,\\dots, w_{J}, c_{J}\\}$ is straightforward: \r\n\\begin{eqnarray}\r\n c_{0}(\\theta, \\phi) = c_{J}(\\theta, \\phi) + \\sum_{j=1}^J  w_j(\\theta, \\phi)\r\n\\end{eqnarray}\r\nThis is the same reconstruction formula as in the \\emph{\\`a trous} algorithm: the simple sum of all scales reproduces the original data. \nActually, since the present decomposition is redundant, the procedure for reconstructing an image from its coefficients is not unique and \nin fact this can profitably be used to impose additional constraints on the synthesis functions (\\emph{e.g.} smoothness, positivity) used \nin the reconstruction. Here for instance, using the relations:\r\n\\begin{eqnarray}\r\n\\hat c_{j+1}(l,m) = \\widehat H_{j} (l,m)  \\hat c_{j} (l,m) \\nonumber \\\\\r\n\\hat w_{j+1}(l,m) = \\widehat G_{j} (l,m) \\hat c_{j} (l,m) \r\n\\end{eqnarray}\r\na least squares estimate of $c_j$ from $c_{j+1}$ and $w_{j+1}$ gives:\r\n\\begin{eqnarray}\r\n%c_{j}   = c_{j+1}  * {\\tilde h}_{2^{j}l_{c}}   + w_{j+1}  * {\\tilde g}_{2^{j}l_{c}}\r\n\\hat{c}_{j}   = \\hat{c}_{j+1}  {\\widehat {\\tilde H}}_{j}   + \\hat{w}_{j+1}  {\\widehat {\\tilde G}}_{j} \n\\end{eqnarray}\r\nwhere the conjugate filters $ {\\widehat {\\tilde H}}_j $ and $ {\\widehat {\\tilde G}}_j$ have the expression:\r\n\\begin{eqnarray}\r\n {\\widehat {\\tilde H}}_j =  \\sqrt{\\frac{4\\pi}{2l+1} } {\\hat {\\tilde h}}_j & = {\\widehat H}_{j}^* /\r\n(\\mid {\\widehat H}_{j}\\mid^2 + \\mid {\\widehat G}_j\\mid^2) \\label{eqnht} \\\\ \r\n {\\widehat {\\tilde G}}_j =  \\sqrt{\\frac{4\\pi}{2l+1} } {\\hat {\\tilde g}}_j & = {\\widehat G}_{j}^* /\r\n(\\mid {\\widehat H}_j \\mid^2 + \\mid {\\widehat G}_j \\mid^2)\r\n\\label{eqngt}\r\n\\end{eqnarray}\r\n%\\begin{eqnarray}\r\n%{\\hat {\\tilde h}} & = {\\hat h^* /\r\n%(\\mid \\hat h\\mid^2 + \\mid \\hat g\\mid^2}) \\label{eqnht} \\\\ \r\n%{\\hat {\\tilde g}} & = {\\hat g^* /\r\n%(\\mid \\hat h \\mid^2 + \\mid \\hat g \\mid^2})\r\n%\\label{eqngt}\r\n%\\end{eqnarray}\r\nand the reconstruction algorithm is:\r\n\\begin{center}\r\n\\begin{tabular}{|c|} \\hline\r\n\\begin{minipage}[b]{5.3in}\r\n\\vspace{0.1in}\r\n\r\n\\small{\r\n\\textsf{1. Compute the $B_3$-spline scaling function and derive $\\hat \\psi$, $\\hat h$, $\\hat g$, ${\\hat {\\tilde h}}$, ${\\hat {\\tilde g}}$ numerically.}\r\n\r\n\\textsf{2. Compute the corresponding Spherical Harmonics of the image at the low resolution $c_J$. We get ${\\hat c}_J$.}\r\n\r\n\\textsf{3. Set $j$ to $J-1$. Iterate:}\r\n\r\n\\hspace{0.3in} \\textsf{4. Compute the Spherical Harmonics transform of the wavelet coefficients $w_{j+1}$ at scale $j+1$. We get  $\\hat{w}_{j+1}$.}\r\n\r\n\\hspace{0.3in} \\textsf{5. Multiply  $\\hat{c}_{j+1}$ by ${\\widehat {\\tilde H}}_j $.}\r\n\r\n\\hspace{0.3in} \\textsf{6. Multiply $\\hat{w}_{j+1}$ by $ {\\widehat {\\tilde G}}_j $.}\r\n\r\n\\hspace{0.3in} \\textsf{7. Add the results of steps 6 and 7. We get $\\hat  c_j$.}\r\n\r\n\\hspace{0.3in} \\textsf{8. j=j-1 and if $j \\ge  0$, return to Step 4.}\r\n\r\n\\textsf{9. Compute The inverse Spherical Harmonic transform of $\\hat  c_0$}}\r\n\r\n\\vspace{0.05in}\n\\end{minipage}\n\\\\\\hline\n\\end{tabular}\n\\\\ \\vspace{0.1in}\n% The numerical algorithm for the inverse wavelet transform on the sphere.\n\\end{center}\n\\linespread{1.3}\n\\index{algorithm!undecimated wavelet reconstruction}\r\nThe synthesis low pass and high pass filters $\\hat{\\tilde h}$ and $\\hat{\\tilde g}$ are plotted in Fig.~\\ref{fig_diff_uv_ht_gt}. \n\n\\begin{figure*}[htb]\r\\centerline{\r\\hbox{\r% \\psfig{figure=ch1_diff_uv_ht_gt.pdf,bbllx=0.5cm,bblly=13.5cm,bburx=20.5cm,bbury=27cm,height=5cm,width=14.5cm,clip=}\r\\psfig{figure=fig_sphere_filterbank.pdf,bbllx=2cm,bblly=12.5cm,bburx=20cm,bbury=16.7cm,height=7cm,width=14.5cm,clip=}\r}}\r\\caption{On the left, the filter $\\hat{\\tilde{h}}$, and on the right the \rfilter $\\hat{\\tilde{g}}$.}\r\\label{fig_diff_uv_ht_gt}\r\\end{figure*}\r\r\n\n\\begin{figure*}\n\\vbox{\n\\centerline{\n\\hbox{\n % \\psfig{figure=fig_uwt_sphere.ps,bbllx=1cm,bblly=7cm,bburx=17cm,bbury=22cm,height=9cm,width=12cm,clip=}\n\\psfig{figure=fig_wmap_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20.5cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n\\psfig{figure=fig_wmap_scale1_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_wmap_scale2_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n\\psfig{figure=fig_wmap_scale3_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_wmap_scale4_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n\\psfig{figure=fig_wmap_scale5_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n}}\n}\n\\caption{{ WMAP Data and its wavelet transform on the Sphere using five resolution levels (4 wavelet scales and the coarse scale). \nThe sum of these five maps reproduces exactly the original data (top left). Top,original data and the first wavelet scale. Middle, \nthe second and third wavelet scales. Bottom, the fourth wavelet scale and the last smoothed array.}}\n\\label{Figure:UWTS}\n\\end{figure*}\n\n\n\\begin{figure}\n\\centerline{\n\\hbox{\n% \\centering\n% \\includegraphics[height=8truecm,width=6truecm]{fig_uwt_sphere.pdf}\n% \\includegraphics[height = 6 in]{fig_backwt_sphere.pdf}\n\\psfig{figure=fig_backwt_sphere.pdf,bbllx=0.5cm,bblly=6.5cm,bburx=20.5cm,bbury=21.5cm,height=7.5cm,width=10cm,clip=}\n}}\n\\caption{{ Backprojection of a wavelet coefficient at different scales. Each map is obtained by setting all wavelet coefficients \nto zero but one, and applying an inverse wavelet transform. Depending on the scale and the position of the non zero wavelet coefficient, \nthe reconstructed image presents an isotropic feature with a given size.}}\n\\label{Figure:back_wt}\n\\end{figure}\n\n{ Figure~\\ref{Figure:UWTS} shows the WMAP data (top left) and its undecimated wavelet decomposition on the sphere using \nfive resolution levels. Figures~\\ref{Figure:UWTS} top right, middle left, middle right and bottom left show respectively \nthe four wavelet scales. Figure~\\ref{Figure:UWTS} bottom right shows the last smoothed array. Figure~\\ref{Figure:back_wt} \nshows the backprojection of a wavelet coefficient at different scales and positions.}\n\n\\subsection{Isotropic Pyramidal Wavelet Transform on the Sphere (PWTS) }\n\\index{wavelet!pyramidal wavelet transform}\r\\index{wavelet!pyramidal wavelet reconstruction}\r\n\n\\begin{figure*}\n\\vbox{\n\\centerline{\n\\hbox{\n % \\psfig{figure=fig_pyrwt_sphere.ps,bbllx=1cm,bblly=7cm,bburx=17cm,bbury=22cm,height=9cm,width=12cm,clip=}\n\\psfig{figure=fig_wmap_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20.5cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n\\psfig{figure=fig_wmap_pscale1_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_wmap_pscale2_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n\\psfig{figure=fig_wmap_pscale3_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_wmap_pscale4_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n\\psfig{figure=fig_wmap_pscale5_bw.pdf,bbllx=0.5cm,bblly=9.5cm,bburx=20cm,bbury=20cm,width=8cm,height=4.5cm,clip=}\n}}\n}\n\\caption{{ WMAP Data (top left) and its pyramidal wavelet transform on the Sphere using five resolution levels (4 wavelet scales \nand the coarse scale). The original map can be reconstructed exactly from the pyramidal wavelet coefficients.Top, original data \nand the first wavelet scale. Middle, the second and third wavelet scales. Bottom, the fourth wavelet scale and the last smoothed \narray. The number of pixels is divided by four at each resolution level, which can be helpful when the data set are large.}}\n\\label{Figure:PWTS}\n\\end{figure*}\n\nIn the previous algorithm, no downsampling is performed and each scale of the wavelet decomposition has the same number of pixels as \nthe 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 applications such as PLANCK data restoration, we may prefer to introduce a decimation in the decomposition \nso as to reduce the required memory size and the computation time. This can be done easily by using a specific property of the chosen \nscaling function. Indeed, since we are considering here a scaling function with an initial cut-off $l_c$ in spherical harmonic multipole \nnumber $l$, and since the actual cut-off is reduced by a factor of two at each step, the number of significant spherical harmonic \ncoefficients is then reduced by a factor of four after each convolution with the low pass filter $h$. Therefore, we need less pixels \nin the direct space when we compute the inverse spherical harmonic transform. Using the Healpix pixelization scheme \\cite{healpix}, \nthis can be done easily by dividing by 2 the {\\it nside} parameter when calling to the inverse spherical harmonic transform routine.\n\n{ Figure~\\ref{Figure:PWTS} shows WMAP data (top left) and its pyramidal wavelet transform using five scales. As the scale number increases \n(i.e. the resolution decreases), the pixel size becomes larger. Figures~\\ref{Figure:PWTS} top right, middle left, middle right and bottom \nleft show respectively the four wavelet scales. Figure~\\ref{Figure:PWTS} bottom right shows the last smoothed array.}\n\n\n\\subsection{Mexican hat wavelet transform on the sphere}\n\\index{wavelet!mexican hat}\n\nThe 1D Euclidean mexican hat wavelet is defined as the second derivative of a Gaussian. Its isotropic extension in 2D is expressed as :\n\\begin{equation}\n\\psi(r) = \\frac{1}{\\sqrt{2 \\pi}} \\Big( 2 - \\Big( \\frac{r}{R} \\Big)^2 \\Big) e^{- \\frac{r^2}{2R^2}}\n\\end{equation}\nwhere $R$ is the scale factor and $r$ measures the distance to the center of the wavelet. This function has been used to implement \na \\emph{continuous} wavelet transform resulting in a powerful tool for data analysis purposes and especially for the detection of \nmostly isotropic features embedded in noise.\\\\\n\nUsing the inverse stereographic projection of the plane unto the sphere, it is possible to design an extension of the continuous \nMexican Hat wavelet transform to the sphere, as motivated and explained in \\cite{wave:antoine99,wave:tenerio99,wave:cayon01,wave:holschneider96}. \nThis leads to the following expression : \n\\begin{equation}\n\\psi_s (\\delta ) = \\frac{1}{\\sqrt{2 \\pi} N_R} \\Big( 1 +  \\Big( \\frac{\\delta}{2} \\Big)^2 \\Big)^2   \\Big( 2 - \\Big( \\frac{\\delta}{R} \\Big)^2 \\Big) e^{- \\frac{\\delta^2}{2R^2}}\n\\end{equation}\nwhere $R$ is the scale factor, $N_R$ is a normalization factor : \n\\begin{equation}\nN_R = R \\Big( 1 + \\frac{R^2}{2} + \\frac{R^4}{4} \\Big)^{\\frac{1}{2}}\n\\end{equation}\nand $\\delta$ is the distance to the tangency point in the tangent plane which is related to the polar angle $\\theta$ through the stereographic projection by :\n\\begin{equation}\n\\delta = 2 \\textrm{tan} \\frac{\\theta}{2}\n\\end{equation}  \nThe resulting wavelet function on the sphere is clearly zonal so that one can move to a spherical harmonics representation and resort \nto equation~\\ref{eq:conv} to compute the wavelet coefficients. This transform was used successfully for the detection of point sources \nin maps of the Cosmic Microwave Background and an application to the detection of non-gaussianity in  CMB is reported in \\cite{wave:vielva04}. \nHowever, although it is profitable for data analysis, this continuous transform lacks an inverse and hence is clearly not suitable for restoration purposes. \n\n\n\\section{Ridgelet and Curvelet Transform on the Sphere (CTS) }\n\\label{sect_cur}\n\\subsection{Introduction.}\n\nThe 2D curvelet transform, proposed in \\cite{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 \\cite{starck:sta01_3,starck:sta02_3}, the data first undergoes an Isotropic Undecimated Wavelet Transform (i.e. \\emph{\\`a trous} 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 \\cite{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 Starck et al\\cite*{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 \\cite{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)$. This method is best for the detection of anisotropic structures and smooth \ncurves 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 \\`a trous 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}$), thanks to the Healpix pixelization.\n\\item {\\it Ridgelet Analysis.} Each square is analyzed via the discrete ridgelet transform.\n\\end{itemize}\n\n\\subsubsection*{Partitioning using the Healpix representation.}\nThe Healpix representation is a curvilinear partition of the sphere into quadrilateral pixels of exactly equal area but with varying shape. The base \nresolution divides the sphere into 12 quadrilateral faces of equal area placed on three rings around the poles and equator. Each face is subsequently \ndivided into $nside^{2}$ pixels following a hierarchical quadrilateral tree structure. The geometry of the Healpix sampling grid makes it easy to \npartition a spherical map into blocks of a specified size $2^n$. We first extract the twelve base-resolution faces, and each face is then decomposed \ninto overlapping blocks as in the 2D digital curvelet transform. With this scheme however, there is no overlapping between blocks belonging to different \nbase-resolution faces. This may result in blocking effects for instance in denoising experiments \\emph{via} non linear filtering. A simple way around \nthis difficulty is to work with various rotations of the data with respect to the sampling grid. \n%The Healpix representation divides the sphere into 12 quadrilateral faces of equal area.  \r\n%Each face is subsequently divided into $nside^{2}$  pixels . Using this pixelization scheme, we can apply a partitioning \r\n%of the data on the sphere in the following way.\r\n%We extract first the twelve faces, and each face is then decomposed into\r\n%overlapping blocks. Because the blocks are not very large, we readily neglect the effect of curvature on each block.\r\n\n\\subsubsection*{Ridgelet transform}\n\\index{ridgelet transform}\n\\index{Radon transform}\nOnce the partitioning is performed, the standard 2D ridgelet transform described in \\cite{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} \\cite{cur:donoho_02}, can be used as well, as long as they offer an exact reconstruction.\n   \nFigure~\\ref{Figure:rid_sphere} shows the flowgraph of the ridgelet transform on the sphere and Figure~\\ref{Figure:back_rid} \nshows the backprojection of a ridgelet coefficient at different scales and orientations.\n\n\\begin{figure*}\n% \\centering\n%  \\includegraphics[height = 5 in]{fig_flowgraph_ridgelet_sphere.pdf}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_flowgraph_ridgelet_sphere.pdf,bbllx=1.5cm,bblly=9cm,bburx=18.5cm,bbury=19cm,height=8cm,width=13.6cm,clip=}\n}}\n\\caption{Flowgraph of the Ridgelet Transform on the Sphere.}\n\\label{Figure:rid_sphere}\n\\end{figure*}\n\n\\begin{figure*}\n% \\centering\n% \\includegraphics[height = 5 in]{fig_back_rid_sphere.pdf}\n\\centerline{\n\\hbox{\n% \\psfig{figure=fig_back_rid_sphere.ps,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=19.5cm,height=6cm,width=9.5cm,clip=}\n\\psfig{figure=fig_ridssr.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,height=6cm,width=9.5cm,clip=}\n}}\n\\caption{Backprojection of a ridgelet coefficient at different scales and orientations.\n{ Each map is obtained by setting all ridgelet coefficients to zero but one, and applying an inverse ridgelet transform. Depending on \nthe scale and the position of the non zero ridgelet coefficient, the reconstructed image presents a feature with a given width and a \ngiven orientation.}}\n\\label{Figure:back_rid}\n\\end{figure*}\n \n\n\\subsection{Algorithm}\nThe curvelet transform algorithm on the sphere is as follows:\n\\begin{enumerate}\n\\item apply the isotropic wavelet transform on the sphere with $J$ scales,\n\\item set the block size $B_1 = B_{min}$,\n\\item for $j = 1, \\ldots, J$ do,\n\\begin{itemize}\n\\item partition the subband $w_j$ with a block size $B_j$ and apply the digital ridgelet transform to each block,\n\\item if $j \\mbox{ modulo } 2 = 1$ then $B_{j+1} = 2 B_{j}$,\n\\item else $B_{j+1} = B_{j}$.\n\\end{itemize}\n\\end{enumerate}\nThe sidelength of the localizing windows is doubled {\\em at every other} dyadic subband, hence maintaining the fundamental property of\nthe curvelet transform which says that elements of length about $2^{-j/2}$ serve for the analysis and synthesis of the $j$-th subband\n$[2^j, 2^{j+1}]$. We used the default value $B_{min} = 16$ pixels in our implementation. Finally, Figure~\\ref{Figure:cur_sphere} gives \nan overview of the organization of the algorithm.\n\\begin{figure*}\n % \\includegraphics[height=8truecm,width=6truecm]{fig_uwt_sphere.pdf}\n% \\includegraphics[height = 7 in]{fig_flowgraph_curvelet_sphere.pdf}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_flowgraph_curvelet_sphere.pdf,bbllx=1cm,bblly=7cm,bburx=20cm,bbury=21cm,height=9cm,width=12cm,clip=}\n}}\n\\caption{Flowgraph of the Curvelet Transform on the Sphere.}\n\\label{Figure:cur_sphere}\n\\end{figure*}\n\\begin{figure*}\n% \\includegraphics[height=8truecm,width=6truecm]{fig_uwt_sphere.pdf}\n% \\includegraphics[height = 5 in]{fig_back_cur_sphere.pdf}\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_back_cur_sphere.pdf,bbllx=1cm,bblly=7cm,bburx=20cm,bbury=21cm,height=9cm,width=12cm,clip=}\n}}\n\\caption{Backprojection of a curvelet coefficient at different scales and orientations.\n{ Each map is obtained by setting all curvelet coefficients to zero but one, and applying an inverse curvelet transform. \nDepending on the scale and the position of the non zero curvelet coefficient, the reconstructed image presents a feature \nwith a given width, length and orientation.}}\n\\label{Figure:back_cur}\n\\end{figure*}\nFigure~\\ref{Figure:back_cur} shows the backprojection of  curvelet coefficients at different scales and orientations.\n\\index{algorithm!curvelet transform}\r\r\r\\subsection{Pyramidal Curvelet Transform on the Sphere (PCTS)}\r\\index{curvelet}\r\\index{curvelet!pyramidal transform}\r\rThe CTS is very redundant, which may be a problem for handling huge data sets such as the future PLANCK data. The redundancy \ncan be reduced by substituting, in the curvelet transform algorithm, the pyramidal wavelet transform to the undecimated wavelet \ntransform. The second step which consists in applying the ridgelet transform on the wavelet scale is unchanged. The pyramidal \ncurvelet transform algorithm is:\n\\begin{enumerate}\n\\item apply the pyramidal wavelet transform on the sphere with $J$ scales,\n\\item set the block size $B_1 = B_{min}$,\n\\item for $j = 1, \\ldots, J$ do,\n\\begin{itemize}\n\\item partition the subband $w_j$ with a block size $B_j$ and apply the digital ridgelet transform to each block,\n\\item if $j \\mbox{ modulo } 2 = 2$ then $B_{j+1} = B_{j} / 2$,\n\\item else $B_{j+1} = B_{j}$.\n\\end{itemize}\n\\end{enumerate}\nIn the next section, it is shown how the pyramidal curvelet transform can be used for image filtering.\n\n\n\n\n", "meta": {"hexsha": "85d3cf77d09757d7ba3146c123592806367a7901", "size": 28987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/archive_tex/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/archive_tex/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/archive_tex/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": 59.6440329218, "max_line_length": 618, "alphanum_fraction": 0.7290164557, "num_tokens": 9381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.661426635970085}}
{"text": "\\section{Recursion} % (fold)\n\\label{sec:recursion}\n\n% go slower, add more examples\n\n\\begin{frame}\\frametitle{Back to control flow}\n    \\framesubtitle{}\n\n    To execute repetitive code, we have relied on \\texttt{for} and \\texttt{while}\n    loops.\n    \\vfill\n    Furthermore, we used \\texttt{if} statements to handle conditional statements.\n    \\vfill\n    These statements are rather straightforward and easy to understand.\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Recursion}\n    \\framesubtitle{A new type of functions}\n\n    Recursive function solve problems by reducing them to smaller problems\n    of the same form.\n\n    \\vfill\n\n    This allows recursive functions to call themselves...\n\n    \\pause\\vfill\n\n    \\begin{itemize}\n        \\item New paradigm\n        \\item Powerful tool\n        \\item Divide-and-conquer\n        \\item Beautiful solutions\n    \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{First example}\n    \\framesubtitle{Add numbers}\n\n    Let's consider a trivial problem:\n\n    Suppose we want to add two positive numbers $a$ and $b$, but we can only add/subtract one.\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{First example}\n    \\framesubtitle{Add numbers}\n\n    Non-recursive solution:\n    \\codeblock{code/rec_nr_add.py}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{First example}\n    \\framesubtitle{Add numbers}\n\n    Recursive solution:\n\n    \\begin{itemize}\n        \\item Simple case: b = 0, return a\n        \\item Else, we can return 1 + add(a, b-1)\n    \\end{itemize}\n    \\pause\n    \\codeblock{code/rec_add.py}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Base case and recursive steps}\n    \\framesubtitle{Two parts of any recursive function}\n\n    Recursive functions consist of two parts:\n\n    \\begin{description}\n        \\item[base case] The base case is the trivial case that can be dealt with\n            easily.\n        \\item[recursive step] The recursive step brings us slightly closer to\n            the base case and calls the function itself again.\n    \\end{description}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Reversing a list}\n\n    How can we recursively reverse a list ([1, 2, 3] $\\to$ [3, 2, 1]).\n\n    \\begin{itemize}\n        \\item If list is empty or has one element, the reverse is itself\n        \\item Otherwise, reverse elements 2 to $n$, and append the first\n    \\end{itemize}\n\n    \\pause\n\n    \\codeblock{code/rec_reverse.py}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Palindromes}\n    \\framesubtitle{Another example}\n\n    A palindrome is a word that reads the same from both ways, such as\n    \\emph{radar} or \\emph{level}.\n    \\vfill\n    Let's write a function that checks whether a given word is a palindrome.\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{The recursive idea}\n    \\framesubtitle{}\n\n    Given a word, such as \\emph{level}, we check:\n    \\begin{itemize}\n        \\item whether the first and last character are the same\n        \\item whether the string with first and last character removed are the same\n    \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Base case}\n    \\framesubtitle{}\n\n    What's the base case in this case?\n\n    \\pause\n    \\begin{itemize}\n        \\item The empty string is a palindrome\n        \\item Any 1 letter string is a palindrome\n    \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Implementation}\n    \\framesubtitle{}\n\n    \\codeblock{code/rec_palindrome.py}\n\n    \\pause\n\n    What is an iterative solution?\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Numerical integration}\n    \\framesubtitle{}\n\n    Suppose we want to numerically integrate some function $f$:\n\n    \\[\n        A = \\int_a^b f(x) dx\n    \\]\n\n    \\pause\\vfill\n\n    Trapezoid rule:\n\n    \\begin{align*}\n        A &= \\int_a^b f(x) dx\\\\\n         &= \\int_a^{r_1} f(x) dx + \\int_{r_1}^{r_2} f(x) dx + \\ldots + \\int_{r_{n-1}}^{b} f(x) dx\\\\\n         &\\approx \\frac{h}{2}\\left((f(a) + f(r_1)) +  h(f(r_1) + f(r_2)) + \\ldots + (f(b) + f(r_{n-1}))\\right)\\\\\n         &= \\frac{h}{2} (f(a) + f(b)) \\quad+\\quad h (f(r_1) + f(r_2) +\\ldots+ f(r_{n-1}))\n    \\end{align*}\n\\end{frame}\n\n\\begin{frame}\\frametitle{Trapezoid rule}\n    \\framesubtitle{Implementation}\n\n    \\codeblock{code/rec_trapezoid.py}\n\n    Forget the math / code:\n    This function approximates the area under f between a and b using N points.\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Key point}\n\n    \\begin{itemize}\n        \\item If function is flat, then we don't need many points.\n        \\item If function is very wiggly, we need a lot of points.\n    \\end{itemize}\n\n    So:\n\n    \\begin{itemize}\n        \\item How many points do we need?\n        \\item What if function is flat in some areas, wiggly in others?\n    \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Adaptive integration}\n    \\framesubtitle{Recursive implementation}\n\n    Idea: Adaptively space points based on local curvature of function.\n\n    Areas where function is flat: few points, areas where function is wiggly: many points.\n\n    \\pause\n\n    \\codeblock{code/rec_adaptint.py}\n\n    Note: we do not need to use trapezoid rule.\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Pitfalls}\n    \\framesubtitle{}\n\n    Recursion can be very powerful, but there are some pitfalls:\n\n    \\begin{itemize}\n        \\item Have to ensure you always reach the base case.\n        \\item Each successive call of the algorithm must be solving a simpler problem\n        \\item The number of function calls shouldn't explode. (see exercises)\n        \\item An iterative algorithm is always faster due to overhead of function calls.\n         (However, the iterative solution might be much more complex)\n    \\end{itemize}\n\n\\end{frame}\n\n% section recursion (end)\n\n\n", "meta": {"hexsha": "229d316d38aabe92618153e7b8a0febf712cea26", "size": 5564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/tex/recursion.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": "lectures/tex/recursion.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": "lectures/tex/recursion.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": 24.8392857143, "max_line_length": 112, "alphanum_fraction": 0.6676851186, "num_tokens": 1565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6614266342824358}}
{"text": "\\section{Calculus with Parametric Equations}\\label{sec:Calculus with Parametric Equations}\nWe have already seen how to compute slopes of curves given by\nparametric equations---it is how we computed slopes in polar\ncoordinates.\n\n\\begin{example}{Slope of Cycloid}{cycloidslope}\n Find the slope of the cycloid $x=t-\\sin t$, $y=1-\\cos t$.\n\\end{example}\n\n\\begin{solution}\nWe compute $x'=1-\\cos t$, $y'=\\sin t$, so \n$${dy\\over dx} ={\\sin t\\over  1-\\cos t}.$$\nNote that when $t$ is an odd multiple of $\\pi$, like $\\pi$ or $3\\pi$,\nthis is $(0/2)=0$, so there is a horizontal tangent line, in agreement\nwith figure~\\ref{fig:cycloid}. At even multiples of $\\pi$, the\nfraction is $0/0$, which is undefined. The figure shows that\nthere is no tangent line at such points.\n\\end{solution}\n\nAreas can be a bit trickier with parametric equations, depending on\nthe curve and the area desired. We can potentially compute areas\nbetween the curve and the $x$-axis quite easily.\n\n\\begin{example}{Area Under Cycloid Arch}{areaundercycloidarch}\n Find the area under one arch of the cycloid\n$x=t-\\sin t$, $y=1-\\cos t$. \n\\end{example}\n\n\\begin{solution}\nWe would like to compute\n$$\\int_0^{2\\pi} y\\;dx,$$\nbut we do not know $y$ in terms of $x$. However, the parametric\nequations allow us to make a substitution: use $y=1-\\cos t$\nto replace $y$, and compute $dx=(1-\\cos t)\\;dt$. Then the integral\nbecomes \n$$\\int_0^{2\\pi} (1-\\cos t)(1-\\cos t)\\;dt=3\\pi.$$\n\nNote that we need to convert the original $x$ limits to $t$ limits\nusing $x=t-\\sin t$. When $x=0$, $t=\\sin t$, which happens only when\n$t=0$. Likewise, when $x=2\\pi$, $t-2\\pi=\\sin t$ and\n$t=2\\pi$. Alternately, because we understand how the cycloid is\nproduced, we can see directly that one arch is generated by \n$0\\le t\\le 2\\pi$. In general, of course, the $t$ limits will be\ndifferent than the $x$ limits.\n\\end{solution}\n\nThis technique will allow us to compute some quite interesting areas,\nas illustrated by the exercises.\n\nAs a final example, we see how to compute the length of a curve given\nby parametric equations. %Section~\\ref{sec:arc length} investigates\nThe arc length for functions given as $y$ in terms of $x$ is\nthe formula:\n$$\\int_a^b \\sqrt{1+\\left({dy\\over dx}\\right)^2}\\;dx.$$\nUsing some properties of derivatives, including the chain rule, we can\nconvert this to use parametric equations $x=f(t)$, $y=g(t)$:\n\\begin{eqnarray*}\n  \\ds\\int_a^b \\sqrt{1+\\left({dy\\over dx}\\right)^2}\\;dx&=\n  \\ds\\int_a^b \\sqrt{\\left({dx\\over dt}\\right)^2\n  +\\left({dx\\over dt}\\right)^2\\left({dy\\over dx}\\right)^2}\\;{dt\\over dx}\\;dx\\cr\n  \\\\\n  &=\\ds\\int_u^v \\sqrt{\\left({dx\\over dt}\\right)^2+\n    \\left({dy\\over dt}\\right)^2}\\;dt\\cr\n    \\\\\n  &=\\ds\\int_u^v \\sqrt{(f'(t))^2+(g'(t))^2}\\;dt.\\cr\n\\end{eqnarray*}\nHere $u$ and $v$ are the $t$ limits corresponding to the $x$ limits\n$a$ and $b$.\n\n\\begin{example}{Length of Cycloid Arch}{lengthofcycloidarch}\n Find the length of one arch of the cycloid.\n\\end{example}\n\n\\begin{solution}\nFrom $x=t-\\sin t$, $y=1-\\cos t$, we get the derivatives\n$f'=1-\\cos t$ and $g'=\\sin t$, so the length is \n$$\n  \\int_0^{2\\pi} \\sqrt{(1-\\cos t)^2+\\sin^2 t}\\;dt=\n  \\int_0^{2\\pi} \\sqrt{2-2\\cos t}\\;dt.\n$$\nNow we use the formula $\\ds \\sin^2(t/2)=(1-\\cos(t))/2$ or\n$\\ds 4\\sin^2(t/2)=2-2\\cos t$ to get\n$$\\int_0^{2\\pi} \\sqrt{4\\sin^2(t/2)}\\;dt.$$\nSince $0\\le t\\le2\\pi$, $\\sin(t/2)\\ge 0$, so we can rewrite this as\n$$\\int_0^{2\\pi} 2\\sin(t/2)\\;dt = 8.$$\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Calculus with Parametric Equations}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the curve of ~\\ref{exer:pseudo cycloid} in \nsection~\\ref{sec:Parametric Equations}. Find all values of\n$t$ for which the curve has a horizontal tangent line.\n\\begin{sol}\n There is a horizontal tangent at all multiples of $\\pi$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the curve of ~\\ref{exer:pseudo cycloid} in \nsection~\\ref{sec:Parametric Equations}. Find the area under\none arch of the curve.\n\\begin{sol}\n $9\\pi/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Consider the curve of  \\ref{exer:pseudo cycloid} in \nsection~\\ref{sec:Parametric Equations}. Set up an integral\nfor the length of one arch of the curve.\n\\begin{sol}\n $\\ds \\int_0^{2\\pi}{1\\over2} \\sqrt{5-4\\cos t}\\;dt$\n\\end{sol}\n\\end{ex}\n\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Consider the hypercycloid of \n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:hypercycloid} in \n%section~\\ref{sec:parametric equations}. Find all points at\n%which the curve has a horizontal tangent line.\n%\\begin{sol}\n% Four points:\\hfill\\break\n%$\\ds \\left({-3-3\\sqrt5\\over4},\n%\\pm\\sqrt{5-\\sqrt5\\over8}\\right)$,\\hfill\\break\n%$\\ds \\left({-3+3\\sqrt5\\over4},\n%\\pm\\sqrt{5+\\sqrt5\\over8}\\right)$ \n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Consider the hypercycloid of \n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:hypercycloid} in \n%section~\\ref{sec:parametric equations}. Find the area between the\n%large circle and\n%one arch of the curve.\n%\\begin{sol}\n% $11\\pi/3$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Consider the hypercycloid of\n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:hypercycloid} in section~\\ref{sec:parametric\n%  equations}. Find the length of one arch of the curve.  \n%\\begin{sol}\n% $32/3$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Consider the hypocycloid of \n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:hypocycloid} in \n%section~\\ref{sec:parametric equations}. Find the area inside the curve.\n%\\begin{sol}\n% $2\\pi$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Consider the hypocycloid of\n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:hypocycloid} in section~\\ref{sec:parametric\n%  equations}. Find the length of one arch of the curve.  \n%\\begin{sol}\n% $16/3$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Recall the involute of a circle from\n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:involute of a circle} in\n%section~\\ref{sec:parametric equations}. Find the point in the first\n%quadrant in figure~\\ref{fig:involute} \n%at which the tangent line is vertical.\n%\\begin{sol}\n% $(\\pi/2,1)$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Recall the involute of a circle from\n%%%%%%%%%%%\n%\\\\begin{ex}\n%~\\ref{exer:involute of a circle} in\n%section~\\ref{sec:parametric equations}. Instead of an infinite\n%string, suppose we have a string of length $\\pi$ attached to the unit\n%circle at $(-1,0)$, and initially laid around the top of the circle\n%with its end at $(1,0)$. If we grasp the end of the string and begin\n%to unwind it, we get a piece of the involute, until the string is\n%vertical. If we then keep the string taut and continue to rotate it\n%counter-clockwise, the end traces out a semi-circle with center at\n%$(-1,0)$, until the string is vertical again. Continuing, the end of\n%the string traces out the mirror image of the initial portion of the\n%curve; see figure~\\ref{fig:involute plus semicircle}. Find the area\n%of the region inside this curve and outside the unit circle.\n%\\begin{sol}\n% $\\ds 5\\pi^3/6$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Find the length of the curve from the previous %%%%%%%%%%\n%\\\\begin{ex}\n%,\n%shown in figure~\\ref{fig:involute plus semicircle}.\n%\\begin{sol}\n% $\\ds 2\\pi^2$\n%\\end{sol}\n%\\end{ex}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% Find the length of the spiral of Archimedes\n%(figure~\\ref{fig:area inside spiral}) for $0\\le\\theta\\le2\\pi$.\n%\\begin{sol}\n% $\\ds(2\\pi\\sqrt{4\\pi^2+1}+\\ln(2\\pi+\\sqrt{4\\pi^2+1}))/2$\n%\\end{sol}\n%\\end{ex}\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.005 0.000 1.022 0.003 1.048 0.010 1.084 0.024\n%1.128 0.047 1.178 0.079 1.234 0.124 1.292 0.183 1.350 0.255\n%1.407 0.342 1.459 0.445 1.504 0.563 1.540 0.695 1.563 0.841\n%1.571 1.000 1.562 1.170 1.533 1.348 1.484 1.534 1.411 1.723\n%1.314 1.913 1.191 2.102 1.043 2.285 0.868 2.459 0.668 2.621\n%0.443 2.767 0.194 2.894 -0.077 2.998 -0.369 3.076 -0.677 3.125\n%-1.000 3.142 /\n%\\plot -1.000 -3.142 -0.677 -3.125 -0.369 -3.076 -0.077 -2.998 0.194 -2.894\n%0.443 -2.767 0.668 -2.621 0.868 -2.459 1.043 -2.285 1.191 -2.102\n%1.314 -1.913 1.411 -1.723 1.484 -1.534 1.533 -1.348 1.562 -1.170\n%1.571 -1.000 1.563 -0.841 1.540 -0.695 1.504 -0.563 1.459 -0.445\n%1.407 -0.342 1.350 -0.255 1.292 -0.183 1.234 -0.124 1.178 -0.079\n%1.128 -0.047 1.084 -0.024 1.048 -0.010 1.022 -0.003 1.005 -0.000\n%1.000 0.000 /\n%\\circulararc 180 degrees from -1.000 3.142 center at -1 0\n%\\textBlack\n%\\setlinear\\setdashes <2pt>\n%\\plot -1 -3.142 -1 3.142 /\n%\\plot -1 0 -3.221 2.221 /\n%\\plot -0.42 0.91 1.4 1.74 /\n%\\endpicture}\n%\\label{fig:involute plus semicircle}\n%\\endfigure{A region formed by the end of a string.}\n%\n%\\end%%%%%%%%%%\n%\\\\begin{ex}\n%s\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "9ce99fbf967a5c87213b1a05a11c1563cd413a3b", "size": 8864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11-polar-coord-parametric-eq/11-5-calc-with-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-5-calc-with-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-5-calc-with-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": 30.7777777778, "max_line_length": 90, "alphanum_fraction": 0.6605370036, "num_tokens": 3309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.6614266270832382}}
{"text": "\\chapter{Central force motions}\nIt was Newton's fascination with planetary motion that led him to formulate his laws of motion and the law of universal gravitation. His success in explaining Kepler's empirical laws of planetary motion was an overwhelming argument in favor of the new mechanics and marked the beginning of modern mathematical physics. Planetary motion and the more general problem of motion under a central force continue to play an important role in most branches of physics and turn up in such topics as particle scattering, atomic structure, and space navigation.\n\\section{Central force}\nA central force  acting on a particle only depends upon magnitude of a distance from a fixed center. If $r$ is the instanteneous position vector of the particle relative to the fixed center. Then the central force is represented by the relation,\n\\begin{equation}\nF= f(r) \\hat{r}\n\\end{equation}\nWhere, $f(r)$ is a scalar function of distance, $r$  and $\\hat{r}=\\frac{\\vec{r}}{r}$. Then the torque acting on the particle is,\n\\begin{equation}\n\\tau =r\\times F\n\\end{equation}\nThis type of motion is particularly relevant when studying the orbital movement of planets and satellites. The laws which govern this motion were first postulated by Kepler and deduced from observation. In this lecture, we will see that these laws are a consequence of Newton's second law. An understanding of central force motion is necessary for the design of satellites and space vehicles.\n\\subsection{General Properties of Central Force Motion}\n\\begin{enumerate}\n\t\n\t\\item The central force $f(r) \\hat{{r}}$ is along ${r}$ and can exert no torque on the reduced mass $\\mu $ , therefore angular momentum about centre of force is conserved. This implies that central force motion is a planar motion. \n\t\\begin{align*}\n\t\\tau &=r\\times F\\\\\n\t&=r  \\hat{r} \\times f(r) \\hat{{r}}\\\\\n\t&=0 \\quad (\\text{Since,  } \\hat{r} \\times \\hat{r} =0)\n\t\\end{align*}\n\t\\item Central forces are conservative, therefore total energy of a particle moving under central force is conserved.\n\t\\item The magnitude of the angular momentum $|{L}| \\equiv l$, and the total energy $E $ , of central force motion is constant.\n\t\\item Areal velocity is constant, that is area swept by line joining the particle to the centre of force per unit time is constant.\n\t\\begin{equation}\n\t\\frac{\\Delta A}{\\Delta t}=\\text { constant }\n\t\\end{equation}\n\\end{enumerate}\n\\section{The two body central force problems}\n\\subsection{Reduction of two-body problems to one body problem}\nA two-body system can be effectively reduced to one-body system by introducing the concept of reduced mass. Suppose a system is composed of two masses $m_{1}$ and $m_{2}$, then for an inertial observer the relative motion of these masses may be expressed by a fictitious particle of reduced mass $\\mu$.\\\\\nLet the instantaneous position of masses $m_{1}$ and $m_{2}$ be represented by position vectors $r_{1}$ and $r_{2}$ relative to an arbitrary origin 0\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=5cm]{diagram-20220217(5)-20220217171814-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nLet us assume that no external force acts on the system and the internal force is simply due to mutual interaction of the particles, so the potential energy function is dependent only on internal forces, so the potential energy function may be assumed to be the function of vector between two particles $\\mathbf{r}_{2}-\\mathbf{r}_{1}$ or their relative velocity $\\left(\\dot{\\mathbf{r}}_{2}-\\dot{\\mathbf{r}}_{1}\\right) .$ This system has six degrees of freedom and hence requires six independent generalised coordinates. We choose these to be three components of radius vector $\\mathbf{R}$ of centre of mass and three components of difference vector $\\mathbf{r}=\\mathbf{r}_{2}-\\mathbf{r}_{1}$.\\\\\nThe Lagrangian of the system has the form $L=T(\\dot{\\mathbf{R}}, \\dot{\\mathbf{r}})-V(\\mathbf{r}, \\dot{\\mathbf{r}}, \\ldots)$\nThe kinetic energy of the system may be expressed as the sum of kinetic energy of the motion of centre of mass plus the kinetic energy of the motion about the centre of mass, i.e.,\n$$\nT=\\frac{1}{2}\\left(m_{1}+m_{2}\\right) \\dot{\\mathbf{R}}^{2}+\\left(\\frac{1}{2} m_{1} \\cdot{\\mathbf{r}}_{C_{1}}^{2}+\\frac{1}{2} m_{2} \\cdot{\\mathbf{r}}_{C_{2}}^{2}\\right)\n$$\nwhere $\\mathbf{r}_{C_{1}}$ and $\\mathbf{r}_{C_{2}}$ are the radii vectors of the two particles relative to centre of mass. $\\mathbf{r}_{C_{1}}$ and $\\mathbf{r}_{C_{2}}$ are related to $\\mathbf{r}$ by the equations\\\\\n$$\\left.\\begin{array}{l}\n\t\\mathbf{r}_{C_{1}}=-\\frac{m_{2}}{m_{1}+m_{2}} \\mathbf{r} \\\\\n\t\\mathbf{r}_{C_{2}}=\\frac{m_{1}}{m_{1}+m_{2}} \\mathbf{r}\n\\end{array}\\right\\}$$\nSubstituting these values, we get\n$$\nT=\\frac{1}{2}\\left(m_{1}+m_{2}\\right) \\dot{\\mathbf{R}}^{2}+\\frac{1}{2}\\left(\\frac{m_{1} m_{2}}{m_{1}+m_{2}}\\right) \\dot{\\mathbf{r}}^{2}\n$$\nso the Lagrangian of the system\n$$\nL=T-V=\\frac{1}{2}\\left(m_{1}+m_{2}\\right) \\dot{\\mathbf{R}}^{2}+\\frac{1}{2}\\left(\\frac{m_{1} m_{2}}{m_{1}+m_{2}}\\right) \\dot{\\mathbf{r}}^{2}-V(\\mathbf{r}, \\dot{\\mathbf{r}})\n$$\n$\\mathbf{R}$ does not occurs in Lagrangian, so three components of $\\mathbf{R}$ are cyclic, so centre of mass is either at rest or in uniform motion. No equation of motion for $\\mathbf{r}$, will contain terms containing $\\mathbf{R}$ or $\\dot{\\mathbf{R}}$, so assuming centre of mass at rest, me may drop the first term from the Lagrangian, i.e.,\n$$\nL=\\frac{1}{2}\\left(\\frac{m_{1} m_{2}}{m_{1}+m_{2}}\\right) \\dot{\\mathbf{r}}^{2}-V(\\mathbf{r}, \\dot{\\mathbf{r}}, \\ldots)\n$$\n$\\text { This is the Lagrangian of a single particle of a fictitious mass } \\mu=\\frac{m_{1} m_{2}}{m_{1}+m_{2}} \\text { placed at the }$ at the location of $m_2$ with the original potential function.Thus two body problem is equivalent to one body problem.\n\\subsection{The equation of motion and first integral}\nLet us consider only the central force, where the potential $V$ is the function of $r$ only, so that the force is always directed along $\\mathbf{r}$. Let a single particle move about a fixed centre of force which we assume to be the origin of co-ordinate system. Using polar co-ordinates $(r, \\theta)$, the kinetic energy of particle is given by\\\\\n$T=\\frac{1}{2} \\mu\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}\\right), \\mu$ being reduced mass.\\\\\nThe potential energy $V=V(r)$.\\\\\nThe Lagrangian of the system is given by\n\n\\begin{align}\n&L=T-V \\\\\n&=\\frac{1}{2} \\mu\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}\\right)-V(r) .\\\\\n\\intertext { Lagrange's equation for } \\theta \\text { is } &\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\frac{\\partial L}{\\partial \\theta}=0\n\\end{align}\n$\\therefore \\quad$ From (2.5)\n$$\n\\frac{\\partial L}{\\partial \\theta}=0 \\text { and } \\frac{\\partial L}{\\partial \\dot{\\theta}}=\\mu r^{2} \\dot{\\theta}\n$$\n$\\therefore \\quad$ From (2.6)\n$$\n\\frac{d}{d t}\\left(\\mu r^{2} \\dot{\\theta}\\right)=0\n$$\nIntegrating, we get\\\\\n\\begin{align}\n\\mu r^{2} \\dot{\\theta}= constant =J (say),\n\\end{align}\nwhere $J$ is first integral (constant of motion) and represents the magnitude of angular momentum.\\\\\nAs $\\mu$ is constant, equation (2.6) gives\\\\\n\\begin{align}\n\t&\\frac{d}{d t}\\left(r^{2} \\dot{\\theta}\\right)=0 \\notag\\\\\n\t&\\frac{d}{d t}\\left(\\frac{1}{2} r^{2} \\dot{\\theta}\\right)=0 \\notag\\\\\n\t&\\frac{1}{2} r^{2} \\dot{\\theta}=\\text { constant }\\label{eq6}\n\\end{align}\nThe term $\\frac{1}{2} r^{2} \\dot{\\theta}$ represents the areal velocity, i.e., the area swept out by the radius vector per unit time.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{diagram-20220217(4)-20220217171419-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nIf vector $\\mathbf{r}$ rotates by an angle $d \\theta$ in time $d t$, the area swept out by $r$ in time $d t$ is $\\frac{1}{2} r .(r d \\theta)=d A$ (say), so that\n$$\n\\frac{d A}{d t}=\\frac{1}{2} r^{2} \\frac{d \\theta}{d t}=\\frac{1}{2} r^{2} \\dot{\\theta}\n$$\nFrom equation (\\ref*{eq6});\n\\begin{align}\n\\frac{d A}{d t}=\\frac{1}{2} r^{2} \\dot{\\theta}=\\text { constant }\n\\end{align}\nEquation (2.4) gives \n\\begin{align*}\n\\frac{\\partial L}{\\partial \\dot{r}}=\\mu \\dot{r}\\\\\n\\frac{\\partial L}{\\partial r}=\\mu \\dot{\\theta}^{2}-\\frac{\\partial V}{\\partial r} \n\\end{align*}\nThe Lagrangian equation in terms of $r$ is given by\n\\begin{align}\n\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{r}}\\right)-\\frac{\\partial L}{\\partial r}=0 \\notag\\\\\n\\frac{d}{d t}(\\mu \\dot{r})-\\mu r \\dot{\\theta}^{2}+\\frac{\\partial V}{\\partial r}=0\\label{eq7}\n\\end{align}\nIf we represent the force along $\\mathbf{r}$ by $F(r)$, then we have\n$$\nF(r)=-\\frac{\\partial V}{\\partial r},\n$$\nso that equation \\ref{eq7} can be written as\n\\begin{align}\n\\mu \\ddot{r}-\\mu r \\dot{\\theta}^{2}=F(r) \\label{eq9}\n\\end{align}\nThis is the general equation of motion.\\\\\n But from equation (2.7),\n \\begin{align*}\n  \\dot{\\theta}=\\frac{J}{\\mu r^{2}}\\\\\n \\dot{\\theta}^{2}=\\frac{J^{2}}{\\mu^{2} r^{4}},\n \\end{align*}\nso that equation (\\ref{eq9}) gives\n\\begin{align}\n\\mu \\ddot{r}-\\frac{J^{2}}{\\mu r^{3}}=F(r) \\label{eq10}\n\\end{align}\nThis is second order differential equation in $r$ only\\\\\n Equation (\\ref{eq10}) gives\\\\\n$\n\\mu \\ddot{r}=\\frac{J^{2}}{\\mu r^{3}}+F(r),\n$\n\\begin{align}\n\t&\\mu \\ddot{r}=\\frac{j^{2}}{\\mu r^{3}}-\\frac{\\partial V}{\\partial r}=-\\frac{1}{2} \\frac{\\partial}{\\partial r}\\left(\\frac{J^{2}}{\\mu r^{2}}\\right)-\\frac{\\partial V}{\\partial r} \\notag \\\\\n\t&\\mu \\ddot{r}=-\\frac{\\partial}{\\partial r}\\left(\\frac{1}{2} \\frac{J^{2}}{\\mu r^{2}}+V\\right) \\label{eq11}\n\\end{align}\nMultiplying both sides of this equation by $\\dot{r}$, we get\n\\begin{align*}\n&\\mu \\dot{r} \\ddot{r}=-\\frac{\\partial}{\\partial r}\\left(\\frac{1}{2} \\cdot \\frac{J^{2}}{\\mu r^{2}}+V\\right) \\dot{r} \\\\\n&\\frac{d}{d t}\\left(\\frac{1}{2} \\mu \\dot{r}^{2}\\right)=-\\frac{d}{d t}\\left(\\frac{1}{2} \\frac{J^{2}}{\\mu r^{2}}+V\\right) \\\\\n&\\frac{d}{d t}\\left(\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{1}{2} \\frac{J^{2}}{\\mu r^{2}}+V\\right)=0 \\\\\n&\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{1}{2} \\frac{j^{2}}{\\mu r^{2}}+V=\\mathrm{constant}\n\\end{align*}\nBut\n\\begin{align*}\n&\\text { K.E. }=T=\\frac{1}{2} \\mu\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}\\right) \\\\\n&=\\frac{1}{2} \\mu\\left(\\dot{r}^{2}+\\frac{J^{2}}{\\mu^{2} r^{2}}\\right) \\\\\n&=\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{1}{2} \\frac{J^{2}}{\\mu r^{2}} \\\\\n&\\text { potential energy } =V\\\\\n&\\text { total energy } \\quad E\n=T+V=\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{1}{2} \\frac{j^{2}}{\\mu r^{2}}+V .\n\\end{align*}\nFrom these equations we get \n\\begin{align}\n\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{1}{2} \\mu^{2}+V=E=\\text { constant } \\label{eq12}\n\\end{align}\nie total energy of the system is constant ie the total energy E , constant of motion.This is the another first integral of motion .This equation (\\ref{eq10}) represents equation of motion while angular momentum and total energy are constant of motion.\\\\\nFrom equation (\\ref{eq12}) we have\n\\begin{align}\n\t&\\frac{1}{2} \\mu \\dot{r}^{2}=E-\\frac{J^{2}}{2 \\mu r^{2}}-V \\notag\\\\\n\t&\\dot{r}=\\sqrt{\\left[\\frac{2}{\\mu}\\left\\{E-\\frac{J^{2}}{2 \\mu r^{2}}-V\\right\\}\\right]} \\notag\\\\\n\t&\\frac{d r}{d t}=\\sqrt{\\left[\\frac{2}{\\mu}\\left(E-\\frac{J^{2}}{2 \\mu r^{2}}-V\\right)\\right]} \\notag\\\\\n\t&\\sqrt{\\left[\\frac{2}{\\mu}\\left(E-\\frac{j^{2}}{2 \\mu r^{2}}-V\\right)\\right]} \\label{eq15}\n\\end{align}\n$\\text { Let the initial value of } r \\text { be } r_{0} \\text {; then integrating equation (\\ref{eq15}), we get }$\n\\begin{align}\n\t&\\int_{r_{\\theta}}^{r} \\frac{d r}{\\sqrt{\\left\\{\\frac{2}{\\mu}\\left(E-V-\\frac{J^{2}}{2 \\mu r^{2}}\\right)\\right\\}}}=\\int_{\\theta}^{t} d t \\notag \\\\\n\t&\\left.t=\\int_{r_{\\theta}}^{r} \\frac{d r}{\\sqrt{\\left\\{\\frac{2}{\\mu}\\left(E-V-\\frac{J^{2}}{2 \\mu r^{2}}\\right)\\right.}}\\right\\} \\label{eq16}\n\\end{align}\nThis equation gives $t$ as a function of $r$. However, from this equation we can find $r$ as function of $t$ and the constants.\nFrom equation (2.7), we have\n$$\nd \\theta=\\frac{J}{\\mu r^{2}} d t\n$$\nIf initially $\\theta=\\theta_{\\theta}$, then integration of above equation yields\n\\begin{align}\n&\\int_{\\theta_{0}}^{\\theta} d \\theta=\\int_{0}^{t} \\frac{J}{\\mu r^{2}} d t \\notag \\\\\n&\\theta-\\theta_{0}=\\int_{0}^{t} \\frac{J}{\\mu r^{2}} d t \\notag \\\\\n&\\theta=\\int_{0}^{1} \\frac{J}{\\mu r^{2}} d t+\\theta_{0}\n\\end{align}\nThis equation gives $\\theta$ as a function of $t$.\\\\\nEquation(2.17 and 2.16) are the only integration to be solved .Therefore the problems have been reduced to quadratures with four constants $E,J,r_0,\\theta_0$\n\\subsection{The equivalent one-dimensional problem, and classification of orbits}\nAlthough we have solved the one dimensional problem formally ,practically speaking the integrals (1.16) and (1.17) are usually quite unmanageable and in specific case it is often more convenient to perform the integration in some other fashion.But before obtaining the solution for any specific force laws,let us see what can be learned about the motion in the general case using only the equation of motion and conservation theorems,without requiring explicit solutions.\n\\par The equation of motion in r,with $\\dot{\\theta}$ expressed in terms of l,quation     $m\\ddot{r}-\\frac{l^2}{mr^3}=f(r)$ involves only r and its derivatives.It is the same equation as would be obtained  for a fictitious one-dimensional problem in which a particle of mass $m$ is subject to a force\n$$f^{\\prime}=f+\\frac{l^{2}}{m r^{3}}$$\nThe significance of the additional term is clear if it is written as $m r \\dot{\\theta}^{2}=m v_{\\theta}^{2} / r$, which is the familiar centrifugal force. An equivalent statement can be obtained from the conservation theorem for energy. By Eq. $\\frac{1}{2}m\\dot{r}^2+\\frac{1}{2}\\frac{l^2}{mr^2}+V=constant$ the motion of the particle in $r$ is that of a one-dimensional problem with a fictitious potential energy:\\\\\n$$V^{\\prime}=V+\\frac{1}{2} \\frac{l^{2}}{m r^{2}}$$\nAs a check, note that\n$$\nf^{\\prime}=-\\frac{\\partial V^{\\prime}}{\\partial r}=f(r)+\\frac{l^{2}}{m r^{3}}\n$$\n The energy conservation theorem can thus also be written as\n$$\nE=V^{\\prime}+\\frac{1}{2} m \\dot{r}^{2}\n$$\nAs an illustration of this method of examining the motion, consider a plot of $V^{\\prime}$ against $r$ for the specific case of an attractive inverse-square law of force:\n$$\nf=-\\frac{k}{r^{2}} .\n$$\n(For positive $k$, the minus sign ensures that the force is toward the center of force.) The potential energy for this force is\n$$\nV=-\\frac{k}{r}\n$$\nand the corresponding fictitious potential is\n$$\nV^{\\prime}=-\\frac{k}{r}+\\frac{l^{2}}{2 m r^{2}}\n$$\nSuch a plot is shown in Figure the two dashed lines represent the separate components\n$$\n-\\frac{k}{r} \\quad \\text { and } \\quad \\frac{l^{2}}{2 m r^{2}}\n$$\nand the solid line is the sum $V^{\\prime}$.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=9cm,width=9cm]{diagram-20220219(10)}\n\t\\caption{The equivalent one dimensional potential for attractive inverse square law of force}\n\t\\label{}\n\\end{figure}\nLet us consider now the motion of a particle having the energy $E_{1}$, as shown in Figures. Clearly this particle can never come closer than $r_{1}$  Otherwise with $r<r_{1}, V^{\\prime}$ exceeds $E_{1}$ and by conservation of energy the kinetic energy would have to be negative, corresponding to an imaginary velocity! on the other hand, there is no upper limit to the possible value of $r$, so the orbit is not bounded. A particle will come in from infinity, strike the \"repulsive centrifugal barrier,\" be repelled, and travel back out to infinity. The distance between $E$ and $V^{\\prime}$ is $\\frac{1}{2} m \\dot{r}^{2}$, i.e., proportional to the square of the radial velocity, and becomes zero, naturally, at the turning point $r_{1}$. At the same time. the distance between $E$ and $V$ on the plot is the kinetic energy $\\frac{1}{2} m v^{2}$ at the given value of $r$. Hence, the distance between the $V$ and $V^{\\prime}$ curves is $\\frac{1}{2} m r^{2} \\theta^{2}$. These curves therefore supply the magnitude of the particle velocity and its components for any distance r,at the given energy and angular momentum .This information is sufficient to produce an approximate picture of the form of the orbit.\\\\\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=7cm,width=10cm]{diagram-20220219(11)}\n\t\\caption{Unbounded motion at positive energies for inverse square law of force}\n\t\\label{}\n\\end{figure}\n\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=7cm]{diagram-20220219(6)}\n\t\\caption{The orbit for $E_1$ corresponding to unbounded motion}\n\t\\label{}\n\\end{figure}\n\\end{minipage}\n\\par For the energy $E_{2}=0$, a roughly similar picture of the orbit behavior is obtained. But for any lower energy, such as $E_{3}$ indicated in fig (1.6) we have a different story. In addition to a lower bound $r_{1}$, there is also a max. imum value $r_{2}$ that cannot be exceeded by $r$ with positive kinetic energy. The motion is then \"bounded,\" and there are two turning points, $r_{1}$ and $r_{2}$, also known as apsidal distances. This does not necessarily mean that the orbits are closed. All that can be said is that they are bounded, contained between two circles of radius $r_{1}$ and $r_{2}$ with turning points always lying on the circles\\\\\n\\begin{minipage}{0.5\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=8cm,width=9cm]{diagram-20220219(8)}\n\t\t\\caption{The equivalent one dimensional potential for inverse square law of force illustrating bounded motion at negative energies.}\n\t\t\\label{}\n\t\\end{figure}\n\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=7cm]{diagram-20220219(7)}\n\t\\caption{The nature of the orbit for bounded motion}\n\t\\label{}\n\\end{figure}\n\\end{minipage}\n\\par If the energy is $E_{4}$ at the minimum of the fictitious potential as shown in Fig. (1.8), then the two bounds coincide. In such case, motion is possible at only one radius; $\\dot{r}=0$, and the orbit is a circle.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=7cm,width=7cm]{diagram-20220219(9)}\n\t\\caption{The equivalent one dimensional potential of inverse square law of force,illustrating the condition for circular orbits}\n\t\\label{}\n\\end{figure}\n\\subsection{Condition for circular orbit}\nRemembering that the effective \"force\" is the negative of the slope of the $V^{\\prime}$ curve, the requirement for circular orbits is simply that $f^{\\prime}$ be zero, or\n$$\nf(r)=-\\frac{l^{2}}{m r^{3}}=-m r \\dot{\\theta}^{2}\n$$\nwhich can be also derived by $\\left.\\frac{\\partial V_{\\text {effective }}}{\\partial r}\\right|_{r=r_{0}}=0$ and $\\dot{\\theta}=\\omega_{0}$ is identified as angular frequency circular orbit.\t\nwhere $$V_{e f f}=\\frac{J^{2}}{2 m r^{2}}-\\frac{k}{r^{n}}$$\nRadius $r=r_0$ of circular orbit is also identified as stable equilibrium point so $\\frac{\\partial^2V_{effective}}{\\partial r}|_{r=r_0}\\geq 0$\nSomehow particle of mass m changes its orbit without changing its angular momentum and orbit is bounded then new orbit is identified as elliptical orbit .The angular frequency in new elliptical orbit is \n$$\\omega=\\sqrt{\\frac{\\frac{\\partial^2 V_{effective}}{\\partial r}|_{r-r_0}}{m}}$$\n\\subsection{The differential equation for the orbit}\nUnder central force\n\\begin{align}\n\\text{We have }J=\\mu r^{2} \\dot{\\theta}= \\text{constant}\\\\\nand E=\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{J^{2}}{2 \\mu r^{2}}+V= \\text{constant}\\\\\n\\text{Differential equation in r is} \\notag\\\\\n\\mu \\ddot{r}-\\frac{J^{2}}{\\mu r^{3}}=F(r)\n\\end{align}\nFrom equation (2.18)\n\\begin{align}\n\t&J=\\mu r^{2} \\dot{\\theta}\\notag  \\\\\n\t&J=\\mu r^{2} \\frac{d \\theta}{d t}\\notag \\\\ \n\t&J d t=\\mu r^{2} d \\theta\n\\end{align}\nThe corresponding relation between the derivative relative to $t$ and $\\theta$ can be written as\n\\begin{align}\n\\frac{d}{d t}=\\frac{J}{\\mu r^{2}} \\frac{d}{d \\theta}\n\\end{align}\nsecond derivative w.r.t. t can be written as \\\\\n\\begin{equation}\n\\frac{d^{2}}{d t^{2}}=\\frac{J}{\\mu r^{2}} \\frac{d}{d \\theta}\\left[\\frac{J}{\\mu r^{2}} \\frac{d}{d \\theta}\\right]\n\\end{equation}\nfrom equation (2.20)\\\\\n\\begin{align}\n\t&\\mu \\frac{J}{\\mu r^{2}} \\frac{d}{d \\theta}\\left\\{\\frac{J}{\\mu r^{2}} \\frac{d r}{d \\theta}\\right\\}-\\frac{J^{2}}{\\mu r^{3}}=F(r) . \\notag \\\\\n\t&\\frac{J}{r^{2}} \\frac{d}{d \\theta}\\left\\{\\frac{J}{\\mu r^{2}} \\frac{d r}{d \\theta}\\right\\}-\\frac{J^{2}}{\\mu r^{3}}=F(r)\n\\end{align}\nTo simplify above equation we must remember that\n\\begin{equation}\n\\frac{1}{r^{2}} \\frac{d r}{d \\theta}=-\\frac{d(1 / r)}{d \\theta}\n\\end{equation}\n$\\text { Using }(2.25) \\text {, equation (2.24) gives }$\\\\\n\\begin{equation}\n\\frac{J^{2}}{\\mu r^{2}} \\frac{d}{d \\theta}\\left[-\\frac{d(1 / r)}{d \\theta}\\right]-\\frac{J^{2}}{\\mu r^{3}}=F(r)\n\\end{equation}\nSubstituting\n$$\nu=\\frac{1}{r}\n$$\nequation (2.26) gives \\\\\n\\begin{align}\n\t&-\\frac{J^{2} u^{2} d^{2} u}{\\mu} \\frac{J^{2}}{\\mu^{2}}-\\frac{J^{2}}{\\mu}=F\\left(\\frac{1}{u}\\right) \\notag \\\\\n\t&\\frac{J^{2} u^{2}}{\\mu}\\left[\\frac{d^{2} u}{d \\theta^{2}}+u\\right]=-F\\left(\\frac{1}{u}\\right)\n\\end{align}\nThis is the differential equation for the orbit if the force F is known.\n\\subsection{The kepler problem:Inverse square law of force}\nThe inverse square law is most important of all central force laws.It results in the deduction of Kepler's laws of planetary motion.\\\\\n\\textbf{The kepler's laws of planetary motion are:}\\\\\n(i) All planets move in elliptical orbits having the sun as one focus.\\\\\n(ii)The area swepts out by the radius vector of planet relative to the sun in equal times are equal.\\\\\n(iii)The square of the period of revolution of any planet about the sun is proportional to the cube of the semi major axis\\\\\n\\textbf{Deduction of Kepler's laws}\\\\\n\\textbf{Kepler's first law}\\\\\nUnder central force the constant of motion are angular momentum and energy\n\\begin{align}\nJ&=\\mu r^{2} \\dot{\\theta} \\\\\n E&=\\frac{1}{2} \\mu \\dot{r}^{2}+\\frac{J^{2}}{2 \\mu r^{2}}+V\n\\end{align}\nFrom equation (2.28 and 2.29)\\\\\n\\begin{align}\n\t&\\frac{d \\theta}{d t}=\\frac{J}{\\mu r^{2}} \\\\\n\t&\\frac{d r}{d t}=\\sqrt{\\frac{2}{\\mu}\\left(E-\\frac{J^{2}}{2 \\mu r^{2}}-V\\right)}\n\\end{align}\nDividing equation (2.31) by (2.30)\n\\begin{align}\n\t\\frac{dr}{d \\theta} &=\\frac{\\mu r^{2}}{J} \\times \\sqrt{\\left\\{\\frac{2}{\\mu}\\left(E-V-\\frac{j^{2}}{2 \\mu r^{2}}\\right)\\right\\}} \\\\\n\td \\theta &=\\frac{J d r}{\\mu r^{2} \\sqrt{\\left\\{\\frac{2}{\\mu}\\left(E-V-\\frac{J^{2}}{2 \\mu r^{2}}\\right)\\right\\}}}\n\\end{align}\nUnder inverse square law of force, we have\n\n\\begin{align*}\n&F(r)=-\\frac{k}{r^{2}} \\\\\n&F(r)=-\\frac{\\partial V}{\\partial r} \\\\\n&-\\frac{\\partial V}{\\partial r}=-\\frac{k}{r^{2}} \\Rightarrow d V=\\frac{k}{r^{2}} d r\n\\end{align*}\nIntegrating $\\quad V=\\int^{r} \\frac{k}{r^{2}} d r$\\\\\nor the potential energy $V=-\\frac{k}{r}$.\\\\\nSubstituting this value of $V$ in equation (2.33), we get\n$$\nd \\theta=\\frac{J d r}{\\sqrt[\\mu r^{2}]{\\left\\{\\frac{2}{\\mu}\\left(E+\\frac{k}{r}-\\frac{J^{2}}{2 \\mu r^{2}}\\right)\\right\\}}}\n$$\nIntegrating, we get\n$$\n\\theta=\\int \\frac{J d r}{\\mu r^{2} \\sqrt{\\left\\{\\frac{2}{\\mu}\\left(E+\\frac{k}{r}-\\frac{J^{2}}{2 \\mu r^{2}}\\right)\\right\\}}}+\\theta^{\\prime}\n$$\nwhere $\\theta^{\\prime}$ is constant of integration.\\\\\nSubstituting $r=1 / u$, we get\\\\\n\\begin{align}\n\\theta=-\\int \\frac{J d u}{\\mu \\sqrt{\\left\\{\\frac{2}{\\mu}\\left(E+k u-\\frac{J^{2} u^{2}}{2 \\mu}\\right)\\right\\}}}+\\theta^{\\prime} \\notag \\\\\n=\\theta^{\\prime}-\\int \\frac{d u}{\\sqrt{\\left(\\frac{2 \\mu E}{J^{2}}+\\frac{2 \\mu k u}{J^{2}}-u^{2}\\right)}} \\notag \\\\\n=\\theta^{\\prime}-\\int \\frac{d u}{\\sqrt{\\left[\\left(\\frac{2 \\mu E}{J^{2}}+\\frac{\\mu^{2} k^{2}}{J^{4}}\\right)-\\left(u-\\frac{\\mu k}{J^{2}}\\right)^{2}\\right]}} \\notag\\\\\n=\\theta^{\\prime}-\\cos ^{-1} \\frac{u-\\frac{\\mu k}{J^{2}}}{\\sqrt{\\left(\\frac{2 \\mu E}{J^{2}}+\\frac{\\mu^{2} k^{2}}{J^{4}}\\right)}}=\\theta^{\\prime}-\\cos ^{-1} \\frac{\\frac{u J^{2}}{\\mu k}-1}{\\sqrt{\\left(\\frac{2 E J^{2}}{\\mu k^{2}}+1\\right)}} \\notag\\\\\n\\frac{\\frac{u J^{2}}{\\mu k}-1}{\\sqrt{\\left(\\frac{2 E J^{2}}{\\mu k^{2}}+1\\right)}}=\\cos \\left(\\theta-\\theta^{\\prime}\\right)\\notag\\\\\n\\frac{u J^{2}}{\\mu k}-1=\\sqrt{\\left(\\frac{2 E J^{2}}{\\mu k^{2}}+1\\right)} \\cos \\left(\\theta-\\theta^{\\prime}\\right) \\notag \\\\\nu=\\frac{\\mu k}{J^{2}}\\left[1+\\sqrt{\\left(\\frac{2 E J^{2}}{\\mu k^{2}}+1\\right)} \\cos \\left(\\theta-\\theta^{\\prime}\\right)\\right]\n\\end{align}\nSubstituting\n\\begin{align}\nc &=\\frac{\\mu k}{J^{2}} \\\\\n\\varepsilon &=\\sqrt{\\left(1+\\frac{2 E J^{2}}{\\mu k^{2}}\\right)}\n\\end{align}\nEquation (2.34) gives\\\\\n\\begin{align}\n\tu &=c\\left[1+\\varepsilon \\cos \\left(\\theta-\\theta^{\\prime}\\right)\\right] \\notag \\\\\n\t\\frac{1}{r} &=c\\left[1+\\varepsilon \\cos \\left(\\theta-\\theta^{\\prime}\\right)\\right]\n\\end{align}\nwhich is the equation of the conic with $\\varepsilon$ as eccentricity and one focus as the origin. Thus the equation of the path of the two-body problem of reduced mass $\\mu$ is always a conic section, which is the generalisation of Kepler's first law.\\\\\nThe nature of the conic dependes on the value of eccentricity given by eqn. (2.36).\\\\\n If $\\in>1$, i.e., if $\\sqrt{\\left(\\frac{2 E J^{2}}{\\mu k^{2}}+1\\right)}>1$ or $E>0$, the conic is hyperbola.\\\\\n If $\\in=1$, i.e., if $\\sqrt{\\left(\\frac{2 E J^{2}}{\\mu k^{2}}+1\\right)}=1$ or $E=0$, the conic is a parabola.\\\\\n  If $\\in<1$, i.e., if $\\sqrt{\\left(\\frac{2 E^{2}}{\\mu k^{2}}+1\\right)}<1$ or $E<0$, the conic is an ellipse.\\\\\n   If $\\in=0$, i.e., if $\\sqrt{\\left(\\frac{2 E^{2}}{\\mu k^{2}}+1\\right)}=0$ or $E=-\\frac{\\mu k^{2}}{2 J^{2}}$, the conic is a circle.\\\\\n    In the case of elliptical orbits, when $\\theta-\\theta^{\\prime}=0, r=r_{1}=$ perihelion,\\\\\n    \\begin{figure}[H]\n    \t\\centering\n    \t\\includegraphics[height=4cm,width=7cm]{diagram-20220217(3)-20220217170838-crop}\n    \t\\caption{}\n    \t\\label{}\n    \\end{figure}\n    Then from equation (2.37) we have\\\\\n    $$r_{1}=\\frac{1}{c(1+\\varepsilon)}$$\n    When $\\theta-\\theta^{\\prime}=\\pi, r=r_{2}=$ aphelion, then eqn. (2.37) gives\n    $$\n    r_{2}=\\frac{1}{c(1-\\varepsilon)}\n    $$\n    The semi-major axis, which is one-half the sum of perihelion $r_{1}$ and aphelion $r_{2}$ is given by\n    $$a=\\frac{r_{1}+r_{2}}{2}=\\frac{1}{2}\\left[\\frac{1}{c(1+\\varepsilon)}+\\frac{1}{c(1-\\varepsilon)}\\right]$$\n    Substituting values of $c$ and $\\varepsilon$ , we get\n    \\begin{align}\n    &a=\\frac{1}{\\frac{\\mu k}{J^{2}}\\left\\{1-\\left(1+\\frac{2 E J^{2}}{\\mu k^{2}}\\right)\\right\\}}=-\\frac{k}{2 E} \\notag \\\\\n    &E=-\\frac{k}{2 a} .\n    \\end{align}\n  This shows that in the case of elliptical orbits the total energy depends solely on the major axis.\\\\\n  \\textbf{Deduction of II law}\\\\\n  $$J=\\mu r^{2} \\dot{\\theta}=\\text { constant }$$\n  This implies\n  $$\n  \\frac{d A}{d t}=\\frac{1}{2} r^{2} \\dot{\\theta}=\\text { constant }\n  $$\n  which represents the areal velocity, i.e., the area swept out by the radius vector per unit time is constant. This means that the areas swept out by the radius vector in equal times are equal which is Kepler's II law.\\\\\n  \\textbf{Deduction of kepler's III Law}\\\\\nIf $T$ is the periodic time of describing the complete orbit, the area of the orbit is given by\\\\\n\\begin{align}\nA &=\\int_{0}^{T} \\frac{d A}{d t} d t=\\int_{0}^{T} \\frac{1}{2} r^{2} \\ddot{\\theta} d t \\notag \\\\\n&=\\int_{0}^{T} \\frac{J}{2 \\mu} d t \\quad\\left(\\text { since } J=\\mu r^{2} \\dot{\\theta}\\right) \\notag \\\\\n&=\\frac{J T}{2 \\mu}\n\\end{align}\nBut area of the ellipse \n\\begin{equation}\n\\mathrm{A}=\\pi a b\n\\end{equation}\nwhere $a$ and $b$ are the semi-major and semi-minor axes of the ellipse respectively.\n$$\n\\begin{array}{ll}\n\\text { Also } & b=a \\sqrt{\\left(1-\\varepsilon^{2}\\right)}=a \\sqrt{\\left(1-1-\\frac{2 E J^{2}}{\\mu k^{2}}\\right)}=a \\sqrt{\\left(-\\frac{2 E J^{2}}{\\mu k^{2}}\\right)} \\\\\n\\text { But } & E=-\\frac{k}{2 a}\n\\end{array}\n$$\nTherefore\n\\begin{equation}\nb=a \\sqrt{\\left(\\frac{k J^{2}}{a \\mu k^{2}}\\right)}=a^{1 / 2} \\sqrt{\\left(\\frac{J^{2}}{\\mu k}\\right)}\n\\end{equation}\nSubstituting value of $b$ in equation (2.40) we get\n\\begin{equation}\nA=\\pi a^{3 / 2} \\sqrt{\\left(\\frac{J^{2}}{\\mu k}\\right)}\n\\end{equation}\nComparing equation (2.39 and 2.42)\\\\\n\\begin{align}\n\t&\\frac{J T}{2 \\mu}=\\pi a^{3 / 2} \\sqrt{\\left(\\frac{J^{2}}{\\mu k}\\right)} \\notag \\\\\n\t&\\frac{J^{2} T^{2}}{4 \\mu^{2}}=\\pi^{2} a^{3} \\frac{J^{2}}{\\mu k} \\notag \\\\\n\t&T^{2}=4 \\pi^{2} a^{3} \\frac{\\mu}{k} \\notag \\\\\n\t&T^{2} \\propto a^{3}\n\\end{align}\nie the square of the period of revolution of the planet around the sun is proportional to the cube of the semimajor axis, which is kepler's III law.\n\\section{Two body collisions}\nWhen discussing conservation of momentum, we considered examples in which two\nobjects collide and stick together, and either there are no external forces acting in some\ndirection (or the collision was nearly instantaneous) so the component of the momentum\nof the system along that direction is constant. We shall now study collisions between\nobjects in more detail. In particular we shall consider cases in which the objects do not\nstick together. The momentum along a certain direction may still be constant but the\nmechanical energy of the system may change. We will begin our analysis by considering\ntwo-particle collision. We introduce the concept of the relative velocity between two\nparticles and show that it is independent of the choice of reference frame. We then show\nthat the change in kinetic energy only depends on the change of the square of the relative\nvelocity and therefore is also independent of the choice of reference frame. We will then\nstudy one- and two-dimensional collisions with zero change in potential energy. In\nparticular we will characterize the types of collisions by the change in kinetic energy and analyze the possible outcomes of the collisions.\n\\subsection{Laboratary frame of reference}\n Let $\\overrightarrow{\\mathbf{R}}$ be the vector from the origin of frame $S$ to the origin of reference frame $S^{\\prime}$. Denote the position vector of the $j^{\\text {th }}$ particle with respect to the origin of reference frame $S$ by $\\overrightarrow{\\mathbf{r}}_{j}$ and similarly, denote the position vector of the $j^{\\text {th }}$ particle with respect to the origin of reference frame $S^{\\prime}$ by $\\overrightarrow{\\mathbf{r}}_{j}^{\\prime}$ .\\\\\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=3cm,width=5cm]{diagram-20220218-crop}\n \t\\caption{}\n \t\\label{}\n \\end{figure}\nThe position vectors are related by\n$$\n\\overrightarrow{\\mathbf{r}}_{j}=\\overrightarrow{\\mathbf{r}}_{j}^{\\prime}+\\overrightarrow{\\mathbf{R}}\n$$\nThe relative velocity (call this the boost velocity) between the two reference frames is given by\n$$\n\\overrightarrow{\\mathbf{V}}=\\frac{d \\overrightarrow{\\mathbf{R}}}{d t}\n$$\nAssume the boost velocity between the two reference frames is constant. Then, the relative acceleration between the two reference frames is zero,\n$$\n\\overrightarrow{\\mathbf{A}}=\\frac{d \\overrightarrow{\\mathbf{V}}}{d t}=\\overrightarrow{\\mathbf{0}}\n$$\nWhen the equation is satisfied, the reference frames $S$ and $S^{\\prime}$ are called relatively inertial reference frames.\\\\\nSuppose the $j^{\\text {th }}$ particle in Figure is moving; then observers in different reference frames will measure different velocities. Denote the velocity of $j^{\\text {th }}$ particle in frame $S$ by $\\overrightarrow{\\mathbf{v}}_{j}=d \\overrightarrow{\\mathbf{r}}_{j} / d t$, and the velocity of the same particle in frame $S^{\\prime}$ by $\\overrightarrow{\\mathbf{v}}_{j}^{\\prime}=d \\overrightarrow{\\mathbf{r}}_{j}^{\\prime} / d t$. Taking derivative, the velocities of the particles in two different reference frames are related according to\n$$\n\\overrightarrow{\\mathbf{v}}_{j}=\\overrightarrow{\\mathbf{v}}_{j}^{\\prime}+\\overrightarrow{\\mathbf{V}}\n$$\n\\subsection{ Center-of-mass Reference Frame}\nLet $\\overrightarrow{\\mathbf{r}}_{c m}$ be the vector from the origin of frame $S$ to the center-of-mass of the system of particles, a point that we will choose as the origin of reference frame $S_{c m}$, called the center-of-mass reference frame. Denote the position vector of the $j^{\\text {th }}$ particle with respect to origin of reference frame $S$ by $\\overrightarrow{\\mathbf{r}}_{j}$ and similarly, denote the position vector of the $j^{\\text {th }}$ particle with respect to origin of reference frame $S_{c m}$ by $\\overrightarrow{\\mathbf{r}}_{j}^{\\prime}$ \\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{diagram-20220218(1)-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nThe position vector of the $j^{\\text {th }}$ particle in the center-of-mass frame is then given by\n$$\n\\overrightarrow{\\mathbf{r}}_{j}^{\\prime}=\\overrightarrow{\\mathbf{r}}_{j}-\\overrightarrow{\\mathbf{r}}_{c m} .\n$$\nThe velocity of the $j^{\\text {th }}$ particle in the center-of-mass reference frame is then given by\n$$\n\\overrightarrow{\\mathbf{v}}_{j}^{\\prime}=\\overrightarrow{\\mathbf{v}}_{j}-\\overrightarrow{\\mathbf{v}}_{c m}\n$$\nThere are many collision problems in which the center-of-mass reference frame is the most convenient reference frame to analyze the collision.\\\\\nConsider a system consisting of two particles, which we shall refer to as particle 1 and particle $2 .$ We can determine the velocities of particles 1 and 2 in the center-of-mass,\nas\\\\\\\\\n$$\\overrightarrow{\\mathbf{v}}_{1}^{\\prime}=\\overrightarrow{\\mathbf{v}}_{1}-\\overrightarrow{\\mathbf{v}}_{c m}=\\overrightarrow{\\mathbf{v}}_{1}-\\frac{m_{1} \\overrightarrow{\\mathbf{v}}_{1}+m_{2} \\overrightarrow{\\mathbf{v}}_{2}}{m_{1}+m_{2}}=\\frac{m_{2}}{m_{1}+m_{2}}\\left(\\overrightarrow{\\mathbf{v}}_{1},-\\overrightarrow{\\mathbf{v}}_{2}\\right)=\\frac{\\mu}{m_{1}} \\overrightarrow{\\mathbf{v}}_{1,2}$$\nwhere $\\overrightarrow{\\mathbf{v}}_{12}=\\overrightarrow{\\mathbf{v}}_{1}-\\overrightarrow{\\mathbf{v}}_{2}$ is the relative velocity of particle 1 with respect to particle 2 . A similar result holds for particle 2 :\\\\\\\\\n$$\\overrightarrow{\\mathbf{v}}_{2}^{\\prime}=\\overrightarrow{\\mathbf{v}}_{2}-\\overrightarrow{\\mathbf{v}}_{c m}=\\overrightarrow{\\mathbf{v}}_{2}-\\frac{m_{1} \\overrightarrow{\\mathbf{v}}_{1}+m_{2} \\overrightarrow{\\mathbf{v}}_{2}}{m_{1}+m_{2}}=-\\frac{m_{1}}{m_{1}+m_{2}}\\left(\\overrightarrow{\\mathbf{v}}_{1}-\\overrightarrow{\\mathbf{v}}_{2}\\right)=-\\frac{\\mu}{m_{2}} \\overrightarrow{\\mathbf{v}}_{1,2}$$\nThe momentum of the system the center-of-mass reference frame is zero as we expect,\n$$\nm_{1} \\overrightarrow{\\mathbf{v}}_{1}^{\\prime}+m_{2} \\overrightarrow{\\mathbf{v}}_{2}^{\\prime}=\\mu \\overrightarrow{\\mathbf{v}}_{12}-\\mu \\overrightarrow{\\mathbf{v}}_{12}=\\overrightarrow{\\mathbf{0}}\n$$\n\\subsection{ Characterizing Collisions}\nIn a collision, the ratio of the magnitudes of the initial and final relative velocities is called the coefficient of restitution and denoted by the symbol $e$,\n$$\ne=\\frac{v_{B}}{v_{A}}\n$$\nIf the magnitude of the relative velocity does not change during a collision, $e=1$, then the change in kinetic energy is zero. Collisions in which there is no change in kinetic energy are called elastic collisions,\n$$\\Delta K=0, \\text{elastic collision }$$\nIf the magnitude of the final relative velocity is less than the magnitude of the initial relative velocity, $e<1$, then the change in kinetic energy is negative. Collisions in which the kinetic energy decreases are called inelastic collisions,\n$$\\Delta K<0, \\text{inelastic collision }$$\nIf the two objects stick together after the collision, then the relative final velocity is zero, $e=0 .$ Such collisions are called totally inelastic. The change in kinetic energy can be written as\\\\\n$$\\Delta K=-\\frac{1}{2} \\mu v_{A}^{2}=-\\frac{1}{2} \\frac{m_{1} m_{2}}{m_{1}+m_{2}} v_{A}^{2}, \\text { totally inelastic collision } .$$\nIf the magnitude of the final relative velocity is greater than the magnitude of the initial relative velocity, $e>1$, then the change in kinetic energy is positive. Collisions in which the kinetic energy increases are called superelastic collisions,\n$$\\Delta K>0, \\textbf{superelastic collision}$$\n\\subsection{ Two-dimensional Elastic Collision in Laboratory Reference Frame}\nConsider the elastic collision between two particles in which we neglect any external forces on the system consisting of the two particles. Particle 1 of mass $m_{1}$ is initially moving with velocity $\\overrightarrow{\\mathbf{v}}_{1, i}$ and collides elastically with a particle 2 of mass $m_{2}$ that is initially at rest. We shall refer to the reference frame in which one particle is at rest, 'the target', as the laboratory reference frame. After the collision particle 1 moves with velocity $\\overrightarrow{\\mathbf{v}}_{1, f}$ and particle 2 moves with velocity $\\overrightarrow{\\mathbf{v}}_{2, f}$, (Figure). The angles $\\theta_{1, f}$ and $\\theta_{2, f}$ that the particles make with the positive forward direction of particle 1 are called the laboratory scattering angles.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=8cm]{class20}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nGenerally the initial velocity $\\overrightarrow{\\mathbf{v}}_{1, i}$ of particle 1 is known and we would like to determine the final velocities $\\overrightarrow{\\mathbf{v}}_{1, f}$ and $\\overrightarrow{\\mathbf{v}}_{2, f}$, which requires finding the magnitudes and directions of each of these vectors, $v_{1, f}, v_{2, f}, \\theta_{1, f}$, and $\\theta_{2, f} .$ These quantities are related by the two equations describing the constancy of momentum, and the one equation describing constancy of the kinetic energy. Therefore there is one degree of freedom that we must specify in order to determine the outcome of the collision. In what follows we shall express our results for $v_{1, f}, v_{2, f}$, and $\\theta_{2, f}$ in terms of $v_{1, i}$ and $\\theta_{1, f}$.\\\\\nThe components of the total momentum $\\overrightarrow{\\mathbf{p}}_{i}^{\\mathrm{sys}}=m_{1} \\overrightarrow{\\mathbf{v}}_{1, i}+m_{2} \\overrightarrow{\\mathbf{v}}_{2, i}$ in the initial state are given by\n$$\n\\begin{aligned}\np_{x, i}^{\\mathrm{sys}} &=m_{1} v_{1, i} \\\\\np_{y, i}^{\\mathrm{sys}} &=0 .\n\\end{aligned}\n$$\nThe components of the momentum $\\overrightarrow{\\mathbf{p}}_{f}^{\\mathrm{sys}}=m_{1} \\overrightarrow{\\mathbf{v}}_{1, f}+m_{2} \\overrightarrow{\\mathbf{v}}_{2, f}$ in the final state are given by\n$$\n\\begin{aligned}\n&p_{x, f}^{\\mathrm{sys}}=m_{1} v_{1, f} \\cos \\theta_{1, f}+m_{2} v_{2, f} \\cos \\theta_{2, f} \\\\\n&p_{y, f}^{\\mathrm{sys}}=m_{1} v_{1, f} \\sin \\theta_{1, f}-m_{2} v_{2, f} \\sin \\theta_{2, f} .\n\\end{aligned}\n$$\nThere are no any external forces acting on the system, so each component of the total momentum remains constant during the collision,\n$$\n\\begin{aligned}\n&p_{x, i}^{\\text {sys }}=p_{x, f}^{\\text {sys }} \\\\\n&p_{y, i}^{\\text {sys }}=p_{y, f}^{\\text {sy }}\n\\end{aligned}\n$$\nsubstituting the values\\\\\n$$\\begin{gathered}\nm_{1} v_{1, i}=m_{1} v_{1, f} \\cos \\theta_{1, f}+m_{2} v_{2, f} \\cos \\theta_{2, f} \\\\\n0=m_{1} v_{1, f} \\sin \\theta_{1, f}-m_{2} v_{2, f} \\sin \\theta_{2, f}\n\\end{gathered}$$\nrewriting the expressions we will get \\\\\n\\begin{align}\nm_{2} v_{2, f} \\cos \\theta_{2, f}=m_{1}\\left(v_{1, i}-v_{1, f} \\cos \\theta_{1, f}\\right)\\\\\nm_{2} v_{2, f} \\sin \\theta_{2, f}=m_{1} v_{1, f} \\sin \\theta_{1, f}\n\\end{align}\nSquaring and adding and using the identity $\\text { the identity } \\cos ^{2} \\theta+\\sin ^{2} \\theta=1 \\text { yielding }$\n$$v_{2, f}^{2}=\\frac{m_{1}^{2}}{m_{2}^{2}}\\left(v_{1, i}^{2}-2 v_{1, i} v_{1, f} \\cos \\theta_{1, f}+v_{1, f}^{2}\\right)$$\nThe collision is elastic and therefore the system kinetic energy of is constant\n$$\nK_{i}^{\\text {sys }}=K_{f}^{\\text {sys }}\n$$\n$$\n\\frac{1}{2} m_{1} v_{1, i}^{2}=\\frac{1}{2} m_{1} v_{1, f}^{2}+\\frac{1}{2} m_{2} v_{2, f}^{2}\n$$\nsubstituting the value of $v_{2, f}^{2}$ in this equation\\\\\n$$\\frac{1}{2} m_{1} v_{1, i}^{2}=\\frac{1}{2} m_{1} v_{1, f}^{2}+\\frac{1}{2} \\frac{m_{1}^{2}}{m_{2}}\\left(v_{1, i}^{2}-2 v_{1, i} v_{1, f} \\cos \\theta_{1, f}+v_{1, f}^{2}\\right)$$\n$$0=\\left(1+\\frac{m_{1}}{m_{2}}\\right) v_{1, f}^{2}-\\frac{m_{1}}{m_{2}} 2 v_{1, i} v_{1, f} \\cos \\theta_{1, f}-\\left(1-\\frac{m_{1}}{m_{2}}\\right) v_{1, i}^{2}$$\nLet $\\alpha=m_{1} / m_{2}$ then Equation can be written as\n$$\n0=(1+\\alpha) v_{1, f}^{2}-2 \\alpha v_{1, i} v_{1, f} \\cos \\theta_{1, f}-(1-\\alpha) v_{1, i}^{2}\n$$\nThe solution to this quadratic equation is given by\n$$\nv_{1, f}=\\frac{\\alpha v_{1, i} \\cos \\theta_{1, f} \\pm\\left(\\alpha^{2} v_{1, i}^{2} \\cos ^{2} \\theta_{1, f}+(1-\\alpha) v_{1, i}^{2}\\right)^{1 / 2}}{(1+\\alpha)}\n$$\nDivide equation (2.44 and 2.25) yields\\\\\n$$\\begin{gathered}\n\\frac{v_{2, f} \\sin \\theta_{2, f}}{v_{2, f} \\cos \\theta_{2, f}}=\\frac{v_{1, f} \\sin \\theta_{1, f}}{v_{1, i}-v_{1, f} \\cos \\theta_{1, f}} \\\\\n\\tan \\theta_{2, f}=\\frac{v_{1, f} \\sin \\theta_{1, f}}{v_{1, i}-v_{1, f} \\cos \\theta_{1, f}} .\n\\end{gathered}$$\nThe relationship between the scattering angles is independent of the masses of the colliding particles. Thus the scattering angle for particle 2 is\n$$\\theta_{2, f}=\\tan ^{-1}\\left(\\frac{v_{1, f} \\sin \\theta_{1, f}}{v_{1, i}-v_{1, f} \\cos \\theta_{1, f}}\\right)$$\nFrom (2.45) final velocity of the particle 1\\\\\n$$v_{2, f}=\\frac{v_{1, f} \\sin \\theta_{1, f}}{\\alpha \\sin \\theta_{2, f}}$$\n\\begin{exercise}\n\tObject 1 with mass $m_{1}$ is initially moving with a speed $v_{1, i}=3.0 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}$ and collides elastically with object 2 that has the same mass, $m_{2}=m_{1}$, and is initially at rest. After the collision, object 1 moves with an unknown speed $v_{1, f}$ at an angle $\\theta_{1, f}$ with respect to its initial direction of motion and object 2 moves with an unknown speed $v_{2, f}$, at an unknown angle $\\theta_{2, f}$ (as shown in the Figure $15.10$ ). Find the final speeds of each of the objects and the angle $\\theta_{2, f}$.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=8cm]{diagram-20220218(2)}\n\t\\end{figure}\n\\end{exercise}\n\\begin{answer}\n Because the masses are equal, $\\alpha=1$. We are given that $v_{1, i}=3.0 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}$ and $\\theta_{1, f}=30^{\\circ}$. Hence  $0=(1+\\alpha) v_{1, f}^{2}-2 \\alpha v_{1, i} v_{1, f} \\cos \\theta_{1, f}-(1-\\alpha) v_{1, i}^{2}$ reduces  to\n$$ v_{1, f}=v_{1, i} \\cos \\theta_{1, f}=\\left(3.0 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}\\right) \\cos 30^{\\circ}=2.6 \\mathrm{~m} \\cdot \\mathrm{s}^{-1} $$\nsubstitute this value in \n$$\\tan \\theta_{2, f}=\\frac{v_{1, f} \\sin \\theta_{1, f}}{v_{1, i}-v_{1, f} \\cos \\theta_{1, f}}$$\n$$\\begin{aligned}\n\t\\theta_{2, f} &=\\tan ^{-1}\\left(\\frac{v_{1, f} \\sin \\theta_{1, f}}{v_{1, i}-v_{1, f} \\cos \\theta_{1, f}}\\right) \\\\\n\t\\theta_{2, f} &=\\tan ^{-1}\\left(\\frac{\\left(2.6 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}\\right) \\sin \\left(30^{\\circ}\\right)}{3.0 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}-\\left(2.6 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}\\right) \\cos \\left(30^{\\circ}\\right)}\\right) \\\\\n\t&=60^{\\circ} .\n\\end{aligned}$$\t\nThe above results for $v_{1, f}$ and $\\theta_{2, f}$ may be substituted into either of the expressions in $m_{2} v_{2, f} \\cos \\theta_{2, f}=m_{1}\\left(v_{1, i}-v_{1, f} \\cos \\theta_{1, f}\\right)$  to find $v_{2, f}=1.5 \\mathrm{~m} \\cdot \\mathrm{s}^{-1}$. \n\\end{answer}\n\\subsection{ Two-Dimensional Collision in Center-of-Mass Reference Frame}\nConsider a collision between particle 1 of mass $m_{1}$ and velocity $\\overrightarrow{\\mathbf{v}}_{1, i}$ and particle 2 of mass $m_{2}$ at rest in the laboratory frame. Particle 1 is scattered elastically through a scattering angle $\\Theta$ in the center-of-mass frame. The center-of-mass velocity is given by\\\\\n$$\\overrightarrow{\\mathbf{v}}_{c m}=\\frac{m_{1} \\overrightarrow{\\mathbf{v}}_{1, i}}{m_{1}+m_{2}}$$\nIn the center-of-mass frame, the momentum of the system of two particles is zero\n$$\n\\overrightarrow{\\mathbf{0}}=m_{1} \\overrightarrow{\\mathbf{v}}_{1, i}^{\\prime}+m_{2} \\overrightarrow{\\mathbf{v}}_{2, i}^{\\prime}=m_{1} \\overrightarrow{\\mathbf{v}}_{1, f}^{\\prime}+m_{2} \\overrightarrow{\\mathbf{v}}_{2, f}^{\\prime}\n$$\nTherefore\n$$\n\\begin{aligned}\n&\\overrightarrow{\\mathbf{v}}_{1, i}^{\\prime}=-\\frac{m_{2}}{m_{1}} \\overrightarrow{\\mathbf{v}}_{2, i}^{\\prime} \\\\\n&\\overrightarrow{\\mathbf{v}}_{1, f}^{\\prime}=-\\frac{m_{2}}{m_{1}} \\overrightarrow{\\mathbf{v}}_{2, f}^{\\prime}\n\\end{aligned}\n$$\nThe energy condition in the center-of-mass frame is\n$$\n\\frac{1}{2} m_{1} v_{1, i}^{\\prime 2}+\\frac{1}{2} m_{2} v_{2, i}^{\\prime 2}=\\frac{1}{2} m_{1} v_{1, f}^{\\prime 2}+\\frac{1}{2} m_{2} v_{2, f}^{\\prime 2} .\n$$\nsubstitute the value of velocities in this equation yields\\\\\n$$v_{1, i}^{\\prime}=v_{1, f}^{\\prime}$$\n(we are only considering magnitudes). Therefore\n$$\nv_{2, i}^{\\prime}=v_{2, f}^{\\prime} .\n$$\nBecause the magnitude of the velocity of a particle in the center-of-mass reference frame is proportional to the relative velocity of the two particles, imply that the magnitude of the relative velocity also does not change\\\\\n$$\\left|\\overrightarrow{\\mathbf{V}}_{1,2, i}^{\\prime}\\right|=\\left|\\overrightarrow{\\mathbf{V}}_{1,2, f}^{\\prime}\\right|$$\n Recall that the relative velocity is independent of the reference frame\\\\\n $$\\overrightarrow{\\mathbf{V}}_{1, i}-\\overrightarrow{\\mathbf{V}}_{2, i}=\\overrightarrow{\\mathbf{V}}_{1, i}^{\\prime}-\\overrightarrow{\\mathbf{V}}_{2, i}^{\\prime}$$\n In the laboratory reference frame $\\overrightarrow{\\mathbf{v}}_{2, i}=\\overrightarrow{\\mathbf{0}}$, hence the initial relative velocity is $\\overrightarrow{\\mathbf{v}}_{1,2, i}^{\\prime}=\\overrightarrow{\\mathbf{v}}_{1,2, i}=\\overrightarrow{\\mathbf{v}}_{1, i}$, and the velocities in the center-of-mass frame of the particles are then\n $$\\begin{gathered}\n \\overrightarrow{\\mathbf{v}}_{1, i}^{\\prime}=\\frac{\\mu}{m_{1}} \\overrightarrow{\\mathbf{v}}_{1, i} \\\\\n \\overrightarrow{\\mathbf{V}}_{2, i}^{\\prime}=-\\frac{\\mu}{m_{2}} \\overrightarrow{\\mathbf{v}}_{1, i}\n \\end{gathered}$$\n Therefore the magnitudes of the final velocities in the center-of-mass frame are\n $$\n \\begin{aligned}\n &v_{1, f}^{\\prime}=v_{1, i}^{\\prime}=\\frac{\\mu}{m_{1}} v_{1,2, i}^{\\prime}=\\frac{\\mu}{m_{1}} v_{1,2, i}=\\frac{\\mu}{m_{1}} v_{1, i} . \\\\\n &v_{2, f}^{\\prime}=v_{2, i}^{\\prime}=\\frac{\\mu}{m_{2}} v_{1,2, i}^{\\prime}=\\frac{\\mu}{m_{2}} v_{1,2, i}=\\frac{\\mu}{m_{2}} v_{1, i} .\n \\end{aligned}\n $$\n \\subsection{Relation between scattering angles in laboratory and centre of mass frame for particle undergoing elastic collision}\n Consider a particle of mass $m_1$ moving with velocity $\\vec{u_1}$ in the laboratory frame and let it collide with particles of mass $m_2$ at rest ,the collision being perfectly elastic .After collision the incident particle moves with a velocity $\\vec{v_1}$ making scattering angle $\\theta_{1}$ with the initial direction and the target particle of mass $m_2$ moves with a velocity $\\vec{v_2}$ making recoil angle $\\theta_{2}$ with the initial direction of motion of $m_1$.The initial path of $m_1$ is along the X- axis and the plane containing $u_1$ and $v_1$ is the X-Y plane as ahown in figure.\\\\\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=4cm,width=9cm]{collision}\n \t\\caption{}\n \t\\label{}\n \\end{figure}\n Let $\\vec{v_1^{\\prime}}$ and $\\vec{v_2^{\\prime}}$ be the final velocities of the particle $m_1$ and $m_2$ after collision in the center of mass frame making an angle $\\theta$ with the X-axis as shown in the figure.\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=4cm,width=9cm]{diagram-20220221(14)-crop}\n \t\\caption{}\n \t\\label{}\n \\end{figure}\n Then\\\\\n $$\\vec{v_1^{\\prime}}=\\vec{v_1}-\\vec{V}_{cm} \\hspace{1cm} \\vec{v_2^{\\prime}}=\\vec{v_2}-\\vec{V}_{cm}$$\nAs $$\\vec{u_2}=0 ,\\quad \\vec{V}_{cm}=\\frac{m_1u_1}{m_1+m_2}$$\nie $\\vec{V}_{cm}$ and $u_1$ have the same direction along X-axis.Therefore $\\vec{V}_{cm}$ has no component along the Y-axis .The y component of the velocity of the particle of mass $m_1$ is the same in both frames.\n\\begin{equation}\nv_1\\sin\\theta_1=v_1^{\\prime}\\sin\\theta\n\\end{equation}\nAs the center of mass has a velocity $\\vec{V}_{cm}$ along X-axis with respect to laboratory frame.\n\\begin{equation}\nv_1\\cos \\theta_{1}=v_1^{\\prime}\\cos\\theta +V_{cm}\n\\end{equation}\n Divide (1.46) by (1.47),we have \\\\\n $$\\tan\\theta_{1}=\\frac{v_1^{\\prime}\\sin\\theta}{v_1^{\\prime}\\cos\\theta +V_{cm}}=\\frac{\\sin\\theta}{\\cos \\theta +\\frac{V_{cm}}{v_1^{\\prime}}}$$\n But $$V_{\\prime}=\\frac{m_1}{m_1+m_2}u_1$$\n and $$v_1^{\\prime}=\\frac{m_2}{m_1+m_2}u_1$$\n Dividing we get $$\\frac{V_{cm}}{v_1^{\\prime}}=\\frac{m_1}{m_2}$$\n $$\\tan\\theta_1=\\frac{\\sin\\theta}{\\cos\\theta+\\frac{m_1}{m_2}}$$\n Special cases (i)\\textbf{when $m_1<<<<m_2$}\\\\\n in this case $m_1/m_2$ can be neglected and we have \n $$\\tan\\theta_{1}=\\frac{\\sin \\theta}{\\cos\\theta}=\\tan\\theta$$\n Thus if the incident particle is very light as compared to the target particle ,the angle of scattering for the incident particle in the laboratory and center of mass system are very nearly equal.\\\\\n Case (ii)\\textbf{when $m_1=m_2$}\\\\\n In this case $m_1/m_2$=1\\\\\n Hence $$\\tan\\theta_{1}=\\frac{\\sin\\theta}{1+\\cos \\theta}=\\tan(\\theta/2)$$\n $$\\theta_{1}=\\theta/2$$\n Thus if the incident and target particle are of equal masses ,the angle of scattering in the laboratory system is the half the angle of scattering in the CM system.\n \n \n \n \n \n \n \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 \tPractice set 1\n \t\\end{abox}\n \\begin{enumerate}\n \t\\item The acceleration due to gravity $(g)$ on the surface of Earth is approximately $2.6$ times that on the surface of Mars. Given that the radius of Mars is about one half the radius of Earth, the ratio of the escape velocity on Earth to that on Mars is approximately\n \t{\\exyear{NET JUNE 2011}}\n \\begin{tasks}(2)\n \t\\task[\\textbf{A.}] $1.1$\n \t\\task[\\textbf{B.}]$1.3$\n \t\\task[\\textbf{C.}]$2.3$\n \t\\task[\\textbf{D.}]$5.2$\n \\end{tasks}\n\t\\item Two particles of identical mass move in circular orbits under a central potential $V(r)=\\frac{1}{2} k r^{2}$. Let $l_{1}$ and $l_{2}$ be the angular momenta and $r_{1}, r_{2}$ be the radii of the orbits respectively. If $\\frac{l_{1}}{l_{2}}=2$, the value of $\\frac{r_{1}}{r_{2}}$ is:\n\t{\\exyear{NET DEC 2011}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sqrt{2}$\n\t\\task[\\textbf{B.}]$1 / \\sqrt{2}$\n\t\\task[\\textbf{C.}] 2\n\t\\task[\\textbf{D.}] $1 / 2$\n\\end{tasks}\n\n\t\\item A planet of mass $m$ moves in the inverse square central force field of the Sun of mass $M$. If the semi-major and semi-minor axes of the orbit are $a$ and $b$, respectively, the total energy of the planet is:\n\t{\\exyear{NET DEC 2011}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{G M m}{a+b}$\n\t\\task[\\textbf{B.}]$-G M m\\left(\\frac{1}{a}+\\frac{1}{b}\\right)$\n\t\\task[\\textbf{C.}]$-\\frac{G M m}{a}\\left(\\frac{1}{b}-\\frac{1}{a}\\right)$\n\t\\task[\\textbf{D.}]$-G M m\\left(\\frac{a-b}{(a+b)^{2}}\\right)$\n\\end{tasks}\n\t\\item A planet of mass $m$ moves in the gravitational field of the Sun (mass $M$ ). If the semimajor and semi-minor axes of the orbit are $a$ and $b$ respectively, the angular momentum of the planet is\n\t{\\exyear{NET DEC 2012}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\sqrt{2 G M m^{2}(a+b)}$\n\t\\task[\\textbf{B.}]$\\sqrt{2 G M m^{2}(a-b)}$\n\t\\task[\\textbf{C.}]$\\sqrt{\\frac{2 G M m^{2} a b}{a-b}}$\n\t\\task[\\textbf{D.}]$\\sqrt{\\frac{2 G M m^{2} a b}{a+b}}$\n\\end{tasks}\n\t\\item A planet of mass $m$ and an angular momentum $L$ moves in a circular orbit in a potential, $V(r)=-k / r$, where $k$ is a constant. If it is slightly perturbed radially, the angular frequency of radial oscillations is\n\t{\\exyear{NET JUNE 2013}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $m k^{2} / \\sqrt{2} L^{3}$\n\t\\task[\\textbf{B.}]$m k^{2} / L^{3}$\n\t\\task[\\textbf{C.}]$\\sqrt{2} m k^{2} / L^{3}$\n\t\\task[\\textbf{D.}]$\\sqrt{3} m k^{2} / L^{3}$\n\\end{tasks}\n\t\\item The radius of Earth is approximately $6400 \\mathrm{~km}$. The height $h$ at which the acceleration due to Earth's gravity differs from $g$ at the Earth's surface by approximately $1 \\%$ is\n\t{\\exyear{NET DEC 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $64 \\mathrm{~km}$\n\t\\task[\\textbf{B.}] $48 \\mathrm{~km}$\n\t\\task[\\textbf{C.}]$32 \\mathrm{~km}$\n\t\\task[\\textbf{D.}]$16 \\mathrm{~km}$\n\\end{tasks}\n\t\\item The probe Mangalyaan was sent recently to explore the planet Mars. The inter-planetary part of the trajectory is approximately a half-ellipse with the Earth (at the time of launch),Sun and Mars (at the time the probe reaches the destination) forming the major axis. Assuming that the orbits of Earth and Mars are approximately circular with radii $R_{E}$ and $R_{M}$, respectively, the velocity (with respect to the Sun) of the probe during its voyage when it is at a distance\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210926(22)-crop(1)}\n\t\\end{figure}\n\t$r\\left(R_{E}<<r<<R_{M}\\right) \\text { from the Sun, neglecting the effect of Earth and Mars, is }$\n\t{\\exyear{NET DEC 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sqrt{2 G M \\frac{\\left(R_{E}+R_{M}\\right)}{r\\left(R_{E}+R_{M}-r\\right)}}$\n\t\\task[\\textbf{B.}]$\\sqrt{2 G M \\frac{\\left(R_{E}+R_{M}-r\\right)}{r\\left(R_{E}+R_{M}\\right)}}$\n\t\\task[\\textbf{C.}]$\\sqrt{2 G M \\frac{R_{E}}{r R_{M}}}$\n\t\\task[\\textbf{D.}]$\\sqrt{\\frac{2 G M}{r}}$\n\\end{tasks}\n\t\\item After a perfectly elastic collision of two identical balls, one of which was initially at rest, the velocities of both the balls are non zero. The angle $\\theta$ between the final, velocities (in the lab frame) is\n\t{\\exyear{NET DEC 2016}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\theta=\\frac{\\pi}{2}$\n\t\\task[\\textbf{B.}]$\\theta=\\pi$\n\t\\task[\\textbf{C.}]$0<\\theta \\leq \\frac{\\pi}{2}$\n\t\\task[\\textbf{D.}] $\\frac{\\pi}{2}<\\theta \\leq \\pi$\n\\end{tasks}\n\t\\item Consider circular orbits in a central force potential $V(r)=-\\frac{k}{r^{n}}$, where $k>0$ and $0<n<2$. If the time period of a circular orbit of radius $R$ is $T_{1}$ and that of radius $2 R$ is $T_{2}$, then $\\frac{T_{2}}{T_{1}}$\n\t{\\exyear{NET DEC 2016}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2^{\\frac{n}{2}}$\n\t\\task[\\textbf{B.}]$2^{\\frac{2}{3} n}$\n\t\\task[\\textbf{C.}]$2^{\\frac{n}{2}+1}$\n\t\\task[\\textbf{D.}]$2^{n}$\n\\end{tasks}\n\t\\item A ball weighing $100 \\mathrm{gm}$, released from a height of $5 \\mathrm{~m}$, bounces perfectly elastically off a plate. The collision time between the ball and the plate is $0.5 \\mathrm{~s}$. The average force on the plate is approximately\n\t{\\exyear{NET JUNE 2017}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $3 N$\n\t\\task[\\textbf{B.}]$2 N$\n\t\\task[\\textbf{C.}]$5 N$\n\t\\task[\\textbf{D.}]$4 N$\n\\end{tasks}\n\n\t\\item Which of the following figures best describes the trajectory of a particle moving in a repulsive central potential $V(r)=\\frac{a}{r}(a>0$ is a constant)?\n\t{\\exyear{NET JUNE 2018}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210926(47)-crop}\n\t\\end{figure}\n\t\\task[\\textbf{B.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210926(48)-crop}\n\t\\end{figure}\n\t\\task[\\textbf{C.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210926(49)-crop}\n\t\\end{figure}\n\t\\task[\\textbf{D.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210926(50)-crop}\n\t\\end{figure}\n\\end{tasks}\n\t\\item A particle of mass $m$ moves in a central potential $V(r)=-\\frac{k}{r}$ in an elliptic orbit $r(\\theta)=\\frac{a\\left(1-e^{2}\\right)}{1+e \\cos \\theta}$, where $0 \\leq \\theta<2 \\pi$ and $a$ and $e$ denote the semi-major axis and eccentricity, respectively. If its total energy is $E=-\\frac{k}{2 a}$, the maximum kinetic energy is\n\t{\\exyear{NET JUNE 2018}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $E\\left(1-e^{2}\\right)$\n\t\\task[\\textbf{B.}]$E \\frac{(e+1)}{(e-1)}$\n\t\\task[\\textbf{C.}]$E /\\left(1-e^{2}\\right)$\n\t\\task[\\textbf{D.}]$E \\frac{(e-1)}{(e+1)}$\n\\end{tasks}\n\t\\item In the attractive Kepler problem described by the central potential $V(r)=\\frac{-k}{r}($ where $k$ is a positive constant), a particle of mass $m$ with a non-zero angular momentum can never reach the centre due to the centrifugal barrier. If we modify the potential to\n\t$$\n\tV(r)=-\\frac{k}{r}-\\frac{\\beta}{r^{3}}\n\t$$\n\tone finds that there is a critical value of the angular momentum $\\ell_{c}$ below which there is no centrifugal barrier. This value of $\\ell_{c}$ is\n\t{\\exyear{NET DEC 2018}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[12 \\mathrm{~km}^{2} \\beta\\right]^{1 / 2}$\n\t\\task[\\textbf{B.}]$\\left[12 \\mathrm{~km}^{2} \\beta\\right]^{-1 / 2}$\n\t\\task[\\textbf{C.}]$\\left[12 \\mathrm{~km}^{2} \\beta\\right]^{1 / 4}$\n\t\\task[\\textbf{D.}]$\\left[12 \\mathrm{~km}^{2} \\beta\\right]^{-1 / 4}$\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{c}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{a}&4&\\textbf{d}\\\\\\hline\n\t\t5&\\textbf{b}&6&\\textbf{c}\\\\\\hline\n\t\t7&\\textbf{b}&8&\\textbf{a}\\\\\\hline\n\t\t9&\\textbf{c}&10&\\textbf{d}\\\\\\hline\n\t\t11&\\textbf{c}&12&\\textbf{b}\\\\\\hline\n\t\t13&\\textbf{c}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\newpage\n\\begin{abox}\n\tPractice set 2\n\t\\end{abox}\n\\begin{enumerate}\n\t\\item In a central force field, the trajectory of a particle of mass $m$ and angular momentum $L$ in plane polar coordinates is given by,\\\\\n\t$$\\frac{1}{r}=\\frac{m}{l^{2}}(1+\\varepsilon \\cos \\theta)$$\n\twhere, $\\varepsilon$ is the eccentricity of the particle's motion. Which one of the following choice for $\\varepsilon$ gives rise to a parabolic trajectory?\n\t{\\exyear{GATE 2012}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\varepsilon=0$\n\t\\task[\\textbf{B.}]$\\varepsilon=1$\n\t\\task[\\textbf{C.}] $0<\\varepsilon<1$\n\t\\task[\\textbf{D.}] $\\varepsilon>1$\n\\end{tasks}\n\t\\item A particle of unit mass moves along the $x$-axis under the influence of a potential, $V(x)=x(x-2)^{2}$. The particle is found to be in stable equilibrium at the point $x=2$. The time period of oscillation of the particle is\n\t{\\exyear{GATE 2012}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\pi}{2}$\n\t\\task[\\textbf{B.}]$\\pi$\n\t\\task[\\textbf{C.}]$\\frac{3 \\pi}{2}$\n\t\\task[\\textbf{D.}] $2 \\pi$\n\\end{tasks}\n\t\\item $\\text { A particle of mass } m \\text { is in a potential given by }$\n\t$$V(r)=-\\frac{a}{r}+\\frac{a r_{0}^{2}}{3 r^{3}}$$\n\twhere $a$ and $r_{0}$ are positive constants. When disturbed slightly from its stable equilibrium position it undergoes a simple harmonic oscillation. The time period of oscillation is\n\t{\\exyear{GATE 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 \\pi \\sqrt{\\frac{m r_{0}^{3}}{2 a}}$\n\t\\task[\\textbf{B.}]$2 \\pi \\sqrt{\\frac{m r_{0}{ }^{3}}{a}}$\n\t\\task[\\textbf{C.}]$2 \\pi \\sqrt{\\frac{2 m r_{0}^{3}}{a}}$\n\t\\task[\\textbf{D.}]$4 \\pi \\sqrt{\\frac{m r_{0}^{3}}{a}}$\n\\end{tasks}\n\n\t\\item A planet of mass $m$ moves in a circular orbit of radius $r_{0}$ in the gravitational potential $V(r)=-\\frac{k}{r}$, where $k$ is a positive constant. The orbit angular momentum of the planet is\n\t{\\exyear{GATE 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 r_{0} \\mathrm{~km}$\n\t\\task[\\textbf{B.}]$\\sqrt{2 r_{0} \\mathrm{~km}}$\n\t\\task[\\textbf{C.}]$r_{0} k m$\n\t\\task[\\textbf{D.}]$\\sqrt{r_{0} k m}$\n\\end{tasks}\n\t\\item An interstellar object has speed $v$ at the point of its shortest distance $R$ from a star of much larger mass $M$. Given $v^{2}=2 G M / R$, the trajectory of the object is\n\t{\\exyear{GATE 2018}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] circle\n\t\\task[\\textbf{B.}]ellipse\n\t\\task[\\textbf{C.}]parabola\n\t\\task[\\textbf{D.}]hyperbola\n\\end{tasks}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b}&2&\\textbf{b}\\\\\\hline\n\t\t3&\\textbf{a}&4&\\textbf{d}\\\\\\hline\n\t\t5&\\textbf{c}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set 3\n\t\\end{abox}\n\\begin{enumerate}\n\t\t\\item  A particle 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\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\\begin{answer}\n\t\\begin{align*}\n\tr \\theta=\\beta,\\text{ therefore, }u&=\\frac{1}{r}=\\frac{\\theta}{\\beta} \\quad \\therefore \\frac{\\partial^{2} u}{\\partial \\theta^{2}}=0\\\\\n\t\\text{\tDifferential equation of orbit, }\\frac{\\partial^{2} u}{\\partial \\theta^{2}}+u&=\\frac{-m f(r)}{L^{2} u^{2}}\\\\\n\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\\end{align*}\n\\end{answer}\n\\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\\begin{answer}\n\t\\begin{align}\n\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\\text{ Taking $\\ln$ both sides we get, }n \\ln u&=\\ln \\left(\\frac{1}{a}\\right)+\\ln \\sec n \\theta\\notag\\\\\n\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\\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\\text{ Differential equation of orbit is }\\frac{\\partial^{2} u}{\\partial \\theta^{2}}+u&=\\frac{-m f(r)}{L^{2} u^{2}}\\notag\\\\\n\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\\therefore f(r)&=-\\frac{L^{2} u^{3}(1+n) \\sec ^{2} n \\theta}{m}\\notag\\\\\n\t\\text{from (\\ref{25}) }\\sec ^{2} n \\theta&=a^{2} u^{2 n}\\notag\\\\\n\t\\therefore f(r)&=\\frac{-L^{2}(n+1) a^{2} u^{2 n+3}}{m}\\notag\\\\\n\t\\therefore \\quad f(r)&=\\frac{-L^{2}(n+1) a^{2}}{m} \\cdot \\frac{1}{r^{2 n+3}}\\notag\\\\\n\t\\text{Or }\n\tf(r) \\propto \\frac{1}{r^{2 n+3}}&\n\t\\text{and the force is attractive in nature.}\\notag\n\t\\end{align}\n\\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\\begin{answer}\n\tPericentre distance is the minimum distance $(\\cos \\theta=\\max =1)$ and for parabolic orbit $e=1 .$\n\t\\begin{align*}\n\t\\text{Therefore, }r_{\\min }&=\\frac{l}{1+e \\cos \\theta}=\\frac{l}{2}=r_{p}\\\\\n\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\\end{align*}\n\\end{answer}\n\\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\\begin{answer}\n\t\\begin{align*}\n\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\\end{align*}\n\\end{answer}\n\\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\\begin{answer}\n\t\\begin{align*}\n\t\\text{\tOrbital speed of the planet is }&\\sqrt{\\frac{G M}{r}}\\\\\n\t\\text{New speed of the planet }&=2 \\sqrt{\\frac{G M}{r}}\\\\\n\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\\intertext{\tTotal energy of the planet becomes positive on doubling its speed therefore new orbit of the planet will be hyperbolic.}\n\t\\end{align*}\n\\end{answer}\n\\item  Two masses constrained to move in a horizontal plane collide. Given initially $m_{1}=$ $85 \\mathrm{gms}, m_{2}=200 \\mathrm{gms} ; u_{1}=6.48 \\mathrm{cms} / \\mathrm{sec}$ and $u_{2}=-6.78 \\mathrm{cms} / \\mathrm{sec}$, find the velocity of centre of mass.\n\\begin{answer}\n\\begin{align*}\n \\intertext{The velocity of centre of mass is given by}\n\\vec{V}_{\\mathrm{cm}}&=\\frac{m_{1} \\overrightarrow{u_{1}}+m_{2} \\overrightarrow{u_{2}}}{m_{1}+m_{2}}\\\\\n\\vec{V}_{\\mathrm{cm}}&=\\frac{85 \\times 6.48+200 \\times(-6.78)}{85+200}=2.82 \\mathrm{~cm} / \\mathrm{sec} \\text{in the direction of motion of $m_{2}$}\n\\end{align*}\t\n\\end{answer}\n\\item Two particles each of mass 2kg are moving with velocities $2\\vec{i}+4\\vec{j}$m/s and $5\\vec{i}+6\\vec{j}$m/s respectively.Find the kinetic energy of the system relative to the center of mass.\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { Given } m_{1}&=m_{2}=2 \\mathrm{~kg} . ; u_{1}=3 \\hat{i}+4 \\hat{j} ; \\quad u_{2}=5 \\hat{i}+6 \\hat{j}\\\\\n\t\\text{velocity of centre of mass}\\quad  \\vec{V}_{cm}&=\\frac{m_{1} \\overrightarrow{u_{1}}+m_{2} \\overrightarrow{u_{2}}}{m_{1}+m_{2}}=\\frac{2(3 \\hat{i}+4 \\hat{j})+2(5 \\hat{i}+6 \\hat{j})}{2+2}=4 \\hat{i}+5 \\hat{j}\\\\\n\t\\intertext{Velocity of $m_1$ in centre of mass frame}\n\t\\vec{u}_1^{\\prime}&=\\vec{u}_1-\\vec{V}_{cm}\\\\\n\t\\vec{u}_1^{\\prime}&=3\\hat{i}+4\\hat{j}-4\\hat{i}-5\\hat{j}=-\\hat{i}-\\hat{j}\\\\\n\t\\intertext{Velocity of $m_2$ in centre of mass frame}\n\t\\vec{u}_2^{\\prime}&=\\vec{u}_2-\\vec{V}_{cm}\\\\\n\t\\vec{u}_2^{\\prime}&=5\\hat{i}+6\\hat{j}-4\\hat{i}-5\\hat{j}\\\\\n\t\\intertext{Kinetic energy relative to centre of mass before collision}\n\t&=\\frac{1}{2}m_1u_1^{\\prime 2}+\\frac{1}{2}m_2u_2^{\\prime 2}\\\\\n\t&=\\frac{1}{2}m_1|\\sqrt{(-1)^2+(-1)^2}|^2+\\frac{1}{2}m_2|\\sqrt{(1)^2+(1)^2}|^2\\\\\n\t&=2+2=4 Joule\n\t\\end{align*}\n\\end{answer}\n\\item A particle of mass $m_{1}$ moving with a velocity $\\overrightarrow{u_{1}}$ is elastically scattered from another particle of mass $m_{2}$. After collision the two particles move in opposite directions with the same speed. Find the relation between the two masses.\n\\begin{answer}\n\tAns. Let $\\overrightarrow{v_{1}}$ and $\\overrightarrow{v_{2}}$ be the velocities of the two particles after collision, then\\\\ $\\overrightarrow{v_{1}}=-\\overrightarrow{v_{2}}$ \\\\\n\tThe particle of mass $m_{2}$ is at rest\\\\\n\t$\\therefore$ Linear momentum before collision $=m_{1} \\overrightarrow{u_{1}}$\\\\\n+\tLinear momentum after collision $=m_{1} \\overrightarrow{v_{1}}+m_{2} \\o\nverrightarrow{v_{2}}=m_{1} \\overrightarrow{v_{1}}-m_{2} \\overrightarrow{v_{1}}=\\left(m_{1}-m_{2}\\right) \\overrightarrow{v_{1}}$\\\\\n\tAccording to the law of conservation of linear momentum\n\t\\begin{align*}\n\tm_{1} \\overrightarrow{u_{1}} &=\\left(m_{1}-m_{2}\\right) \\overrightarrow{v_{1}} \\\\\n\t\\overrightarrow{v_{1}} &=\\frac{m_{1}}{m_{1}-m_{2}} \\overrightarrow{u_{1}}\n\t\\end{align*}\n\tConsidering magnitudes only $\\left|\\overrightarrow{v_{1}}\\right|=\\frac{m_{1}}{m_{1}-m_{2}}\\left|\\overrightarrow{u_{1}}\\right|$\\\\\n\t According to the law of conservation of energy\n\t\\begin{align*}\n\t\t&\\frac{1}{2} m_{1}\\left|\\overrightarrow{u_{1}}\\right|^{2}=\\frac{1}{2} m_{1}\\left|\\overrightarrow{v_{1}}\\right|^{2}+\\frac{1}{2} m_{2}\\left|\\overrightarrow{v_{1}}\\right|^{2} \\\\\n\t\t&=\\frac{1}{2}\\left(m_{1}+m_{2}\\right)\\left|\\overrightarrow{v_{1}}\\right|^{2}=\\frac{1}{2} \\frac{m_{1}+m_{2}}{\\left(m_{1}-m_{2}\\right)^{2}} m_{1}^{2}\\left|\\overrightarrow{u_{1}}\\right|^{2} \\\\\n\t\t&\\left(m_{1}-m_{2}\\right)^{2}=\\left(m_{1}+m_{2}\\right) m_{1} \\\\\n\t\t&m_{1}^{2}+m_{2}^{2}-2 m_{1} m_{2}=m_{1}^{2}+m_{1} m_{2} \\\\\n\t\t&m_{2}^{2}=3 m_{1} m_{2} \\quad \\text { or } \\quad m_{2}=3 m_{1}\n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "5eafb4af5f5c3fe77a061320eacf8e18a60bd237", "size": 67240, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/central force motions.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/central force motions.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/central force motions.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": 63.3741753063, "max_line_length": 1213, "alphanum_fraction": 0.667415229, "num_tokens": 24287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6614088475029135}}
{"text": "\\section{Preliminaries: decision diagrams and stabilizer states \\label{sec:preliminaries}}\n%\\todo[inline]{mention terminology `low' and `high' for 0-edge and 1-edge}\n\n%Here, we briefly introduce two methods to manipulate and succinctly represent quantum states: decision diagrams and stabilizer states.\n%For an introduction to quantum computation, see appendix~\\ref{sec:quantum-nutshell}.\n\nThe computational unit of quantum computers are quantum bits or qubits.\nA single-qubit state is a complex vector $(\\alpha_0, \\alpha_1)^{T} \\in \\mathbb{C}^2$ with norm 1, usually written in Dirac notation as $\\alpha_0 \\ket{0} + \\alpha_1 \\ket{1}$.\nTwo quantum states which differ only by a complex multiple are considered equal.\nThe joint state $\\ket{\\phi}$ of $n$ quantum bits can be written as \n\\begin{equation}\n    \\label{eq:quantum-state-expansion}\n    \\sum_{x_1, x_2, \\dots, x_n \\in \\set{0,1}} f(x_1, x_2, \\dots, x_n) \\ket{x_1}\\otimes\\ket{x_2}\\otimes \\dots \\otimes\\ket{x_n}\\vspace{-1em}\n\\end{equation}\nfor a function $f: \\{0, 1\\}^n \\rightarrow \\mathbb{C}$, where $\\otimes$ denotes the tensor product.\nAn example two-qubit state is $\\left( \\ket{0} \\otimes \\ket{0} + i \\ket{1} \\otimes \\ket{1}\\right) / \\sqrt{2} = \\frac{1}{\\sqrt{2}} (1,0,0,i)^T$.\nAlternatively to \\autoref{eq:quantum-state-expansion}, we can recursively describe an $n$-qubit quantum state $\\ket{\\phi}$ for $n>1$ as\n\\begin{equation}\n\\ket{\\phi} = \\alpha_0 \\ket{0} \\otimes \\ket{\\phi_0} + \\alpha_1 \\ket{1} \\otimes \\ket{\\phi_1}, \\text{where $\\ket{\\phi_0}, \\ket{\\phi_1}$ are $n$-1-qubit states and $\\alpha_0,\\alpha_1  \\in \\mathbb{C}$.}\n    \\label{eq:quantum-state-recursive}\n\\end{equation}\nAn Algebraic Decision Diagram (\\add) represents a function of the form $f\\colon \\{0, 1\\}^n \\rightarrow \\mathbb{C}$, and thus also a quantum state via \\autoref{eq:quantum-state-expansion}, see \\autoref{fig:qmdd-isoqmdd-exposition} for an example.\n%A succint representation of functions of the form $f\\colon \\{0, 1\\}^n \\rightarrow \\mathbb{C}$, and thus of quantum states via \\autoref{eq:quantum-state-expansion}, has been achieved by the use of Algebraic Decision Diagrams (\\adds), see \\autoref{fig:qmdd-isoqmdd-exposition} for an example.\nAn \\add is a rooted directed acyclic graph (DAG), which has a leaf node for each unique value in the image of $f$, i.e., in $\\{f(\\vec{x}) \\mid \\vec{x} \\in \\{0, 1\\}^n \\}$.\nEach path from the root to a leaf visits nodes representing the variables $x_1, x_2, x_3, x_4$; one variable at each level of the diagram.\nThe value $f(x_1, \\dots, x_n)$ is found by traversing such a path, following the \\concept{low edge} (dashed line)\n when $x_i=0$, and the  \\concept{high edge} (solid line) when $x_i=1$;\n so, e.g., $f(1,1,1,0) = -i$ in \\autoref{fig:qmdd-isoqmdd-exposition}.\nHence every node in an \\add, not only the root node, can be said to represent a function.\n\n%\\adds for functions $f$ on length-$n$ bitstrings can be defined recursively on $n$: in case $n=1$, then the \\add has a single node with two outgoing edge, labelled $0$ and $1$ and pointing to the leaf node holding the value $f(0)$ and $f(1)$ respectively.\n%If $f(0) = f(1)$, then the \\add only has a single leaf node and both edges point to that node.\n%If $n>1$, then and \\add for $f$ is constructed by first constructing \\adds for the two functions $f_0: (x_2, x_3, \\dots, x_n) \\mapsto f(0, x_2, x_3, \\dots, x_n)$ and $f_1: (x_2, x_3, \\dots, x_n) \\mapsto f(1, x_2, x_3, \\dots, x_n)$.\n%An \\add for $f_0$ is then made by adding a fresh node and a $0$-edge ($1$-edge) pointing to the root node of the \\add of $f_0$ (the \\add of $f_1$).\n%If the \\adds of $f_0$ and $f_1$ are identical, then remove one of them and make both edges point to the remaining one.\n%Thus, in an \\add, the value $f(x_1, \\dots, x_n)$ is found by traversing the path $x_1 \\rightarrow x_2 \\rightarrow \\dots \\rightarrow x_n$, e.g. $f(1,1,0) = -1/\\sqrt{2}$ in \\autoref{fig:add-qmdd-example}.\n%Although generally, functions $f: \\{0, 1\\}^n \\rightarrow \\mathbb{C}$ have exponentially many partial assignments, many functions encountered in practice have only a polynomial number of unique subfunctions, and therefore can be represented by polynomial-size \\add.\n\nA \\emph{partial assignment} $(x_1=a_1,\\ldots, x_k=a_k)$ to the variables induces a \\emph{subfunction} $f_a$, defined as $f_a(x_{k+1},\\ldots, x_n)\\defn f(a_1,\\ldots, a_k,x_{k+1},\\ldots, x_n)$.\nTwo \\add nodes representing the same subfunction can be \\emph{merged}, i.e., one node is deleted and its incident edges are rerouted to the other.\nWhen all eligible nodes have been merged, an \\add is \\emph{reduced}.\nThe nodes of a reduced \\add are in one-to-one correspondence with the unique \\emph{subfunctions} of $f$.\nAn \\add is a \\emph{canonical} representation: a given function has exactly one reduced \\add.\n\\adds can represent both states and matrices, and there are algorithms which multiply a matrix with a vector in \\add form.\nAn \\add can represent any quantum state, using exponentially many nodes in the worst case.\nA given quantum gate can be compiled into an \\add, thus allowing one to simulate any quantum circuit by repeatedly multiplying a gate's matrix with a state. %\\todo[inline]{@Lieuwe: David asks for ref here}\n%For example, the functions $(x_2, x_2, \\dots, x_n) \\mapsto f(0, x_2, x_3, \\dots, x_n)$ and $(x_4, x_5, \\dots, x_n) \\mapsto f(0, 1, 1, x_4, x_5, \\dots, x_n)$ are subfunctions of $f$.\n%At a node in an \\add corresponding to the $k$-th variable, the two outgoing arrows correspond to the partial assignments $x_k=0$ and $x_k=1$.\n\nThe Quantum Multi-valued Decision Diagram (\\qmdd) \\cite{miller2006qmdd} improves on the \\add representation by also merging two nodes when they represent functions $f,g$ that are related by $f=\\lambda\\cdot g$ for some $\\lambda\\in\\mathbb C^{\\ast}$.\n\\autoref{fig:qmdd-isoqmdd-exposition} gives an example.\nEach edge is labelled with a weight. % (the normalization constant $\\lambda$).%$^{\\ref{fn:norm}}$\nTo read a value of $f$, traverse the \\qmdd from the root to the leaf just as in an \\add, and multiply the weights of all edges on that path.\nLike \\adds, \\qmdds are a canonical representation and can be used to simulate any quantum circuit.\n\nThe single-qubit Pauli operators are\n$2\\times 2$ unitary matrices:\n\\begin{equation*}\n\\id[2] \\defn \\begin{pmatrix} 1 & 0\\\\ 0 & 1 \\end{pmatrix},\nX \\defn \\begin{pmatrix} 0 & 1\\\\ 1 & 0 \\end{pmatrix},\nY \\defn \\begin{pmatrix} 0 & -i\\\\ i & 0 \\end{pmatrix},\nZ \\defn \\begin{pmatrix} 1 & 0\\\\ 0 & -1 \\end{pmatrix}\n\\label{eq:pauli-matrices}\n\\end{equation*}\nwhere $i$ is the complex unit.\nAn $n$-qubit operator of the form $P_n\\otimes\\cdots\\otimes P_1$ is called a \\emph{Pauli string} if $P_j$ are single-qubit Pauli operators.\nThe $n$-qubit Pauli strings generate a nonabelian group $\\Pauli_n$ (under matrix multiplication), consisting of all operators of the form $\\lambda P_n\\otimes\\cdots\\otimes P_1$ with $\\lambda \\in \\{\\pm 1, \\pm i\\}$.\nNote that the high indices are on the left, in keeping with the custom that the least significant (qu)bit is the first qubit, and the leftmost operator $P_n$ acts on the most significant qubit. \nPauli operators $A, B$ either commute ($A\\cdot B = B\\cdot A$) or anticommute ($A \\cdot B = - B \\cdot A$).\n\nIn contrast to decision diagrams, the stabilizer formalism forms a subset of quantum computation that is efficiently simulatable.\nA stabilizer state on $n$ qubits can be prepared from the state $\\ket{0}^{\\otimes n}$ by repeatedly applying any of the following gates (generators of the Clifford set):\n\\begin{equation}\n    H \\defn \n        \\frac{1}{\\sqrt{2}}\n        \\begin{pmatrix} 1 & 1\\\\ 1 & -1 \\end{pmatrix}\n            ,\n        S\n        \\defn\n        \\begin{pmatrix} 1 & 0\\\\ 0 & i \\end{pmatrix},\n            \\textnormal{CNOT} \\defn \n        \\begin{pmatrix}\n            1 & 0 & 0 & 0\\\\\n            0 & 1 & 0 & 0\\\\\n            0 & 0 & 0 & 1\\\\\n            0 & 0 & 1 & 0\n        \\end{pmatrix}.\n        \\label{eq:clifford-generators}\n\\end{equation}\nThere exist $2^{\\Theta(n^2)}$ stabilizer states on $n$ qubits \\cite{aaronson2008improved}; examples are $\\ket{00}$ and $(\\ket{00} + \\ket{11}) / \\sqrt{2}$.\nA strict subset of stabilizer states is the set of graph states \\cite{hein2006entanglement}.\nThe relationship between graph states and stabilizer states has been extensively investigated in, e.g., \\cite{nest2004graphical,nest2005local}\n%\\todo{Move to S4.1?}\nFor an undirected graph $G=(V,E)$, the graph state $\\ket{G}$ is the following state on $n$ qubits, where $Z_{jk}$ denotes the controlled $Z$-gate between qubits $j$ and $k$.\n\\begin{equation}\n    \\frac{1}{\\sqrt{2}^n} \\prod_{(j, k) \\in E} Z_{jk} \\left(\\ket{0} + \\ket{1}\\right)^{\\otimes n}, \\text{ where e.g. }\n        Z_{1,2} = \n        \\begin{pmatrix}\n            1 & 0 & 0 & 0\\\\\n            0 & 1 & 0 & 0\\\\\n            0 & 0 & 1 & 0\\\\\n            0 & 0 & 0 & -1\n        \\end{pmatrix} \\text{ for } n=2.\n\t\\label{eq:graph-state-definition}\n\\end{equation}\n%Although not every stabilizer state is a graph state, any stabilizer state can be converted into one by local Cliffords (LC)~\\cite{nest2004graphical}.\n%Moreover, since LC-equivalence between two graphs is efficient~\\cite{nest2005local}, so is LC-equivalence between stabilizer states.\\todo{Tim: Vedran mentioned this and I added it here, but I am not so sure this is the right place to mention this... All Paulis are CLiffords so checking local-Pauli equivalence is easy for stabilizer states, but we consider arbitrary states...}\nAn $n$-qubit stabilizer state $\\ket{\\phi}$ is uniquely specified by the set $S$ of Pauli operators $A \\in \\Pauli_n$ for which $A\\ket{\\phi} = \\ket{\\phi}$.\nThis set $S$ is an abelian group of $2^n$ elements, succinctly represented by $n$ independent generators.\nSince each Pauli generator takes $\\mathcal{O}(n)$ space to represent, an $n$-qubit stabilizer is represented by $\\mathcal O(n^2)$ bits.\nUpdating the stabilizer generating set after application of one of the gates from eq.~\\eqref{eq:clifford-generators} or a single-qubit computational-basis measurement can be done in polynomial time \\cite{gottesman1998heisenberg}.\nAlso, we note that multiplying two $n$-qubit Pauli strings can be done in $O(n)$ time by using the property of the tensor product $\\otimes$ that $(a\\otimes b) \\cdot (c\\otimes d) = (a\\cdot c) \\otimes (b\\cdot d)$.\n\nStabilizer-rank based methods~\\cite{bravyi2016trading,bravyi2017improved,bravyi2019simulation, huang2019approximate,kocia2018stationary,kocia2020improved} extend this approach to families of Clifford circuits with arbitrary input states $\\ket{\\phi_n}$, enabling the simulation of universal quantum computation in general~\\cite{bravyi2005universal}.\nBy decomposing $\\ket{\\phi_n}$ as linear combination of $\\chi$ stabilizer states, the measurement outcome probabilities can be computed in time $\\oh(\\chi \\cdot \\textnormal{poly}(n))$, where the least $\\chi$ is referred to as the \\concept{stabilizer rank}.\nTherefore, stabilizer-rank based methods are efficient for a family of input states $\\ket{\\phi_n}$ with a stabilizer rank polynomially growing~in~$n$.\n\nIn this work we will also consider stabilizer groups of states which are not stabilizer states.\nIn general, we will refer to an abelian subgroup of $\\Pauli_n$, not containing $-\\id[2]^{\\otimes n}$, as an $n$-qubit \\emph{stabilizer subgroup}, which generally has $\\leq n$ generators.\nSuch objects are also studied in the context of simulating mixed states \\cite{audenaert2005entanglement} and quantum error correction~\\cite{gottesman1997stabilizer}.\nExamples of stabilizer subgroups are $\\{\\id[2]\\}$ for $\\ket{0} + e^{i\\pi/4}\\ket{1}$, $\\langle -Z\\rangle$ for $\\ket{1}$ and $\\langle X \\otimes X\\rangle$ for $(\\ket{00} + \\ket{11}) + 2(\\ket{01} + \\ket{10})$.\n\nAny $n$-qubit Pauli string can (modulo factor $\\in \\{\\pm 1, \\pm i\\}$) be written as $(X^{x_n} Z^{z_n}) \\otimes \\dots \\otimes (X^{x_1} Z^{z_1})$ for bits $x_j, z_j, 1 \\leq j \\leq n$.\nWe can therefore write an $n$-qubit Pauli string $P$ as length-$2n$ binary vector \n\\[\n    (\\underbrace{x_n, x_{n-1}, \\dots x_1}_{\\textnormal{X block}} | \\underbrace{z_n, z_{n-1}, \\dots, z_1}_{\\textnormal{Z block}})\n    ,\n\\] \nwhere we added the horizontal bar ($|$) only to guide the eye.\nWe will refer to such vectors as \\emph{check vectors}.\nFor example $X \\sim (1, 0)$ and $Z \\otimes Y \\sim (0, 1 | 1, 1)$ \\cite{aaronson2008improved}.\nA set of $k$ Pauli strings thus can be written as $2n\\times k$ binary matrix, often called \\emph{check matrix}, e.g.\n\\[\n    \\begin{pmatrix}\n        X &\\otimes& X &\\otimes& X\\\\\n        \\id[2] &\\otimes& Z &\\otimes& Y\n    \\end{pmatrix}\n    \\sim\n    \\begin{pmatrix}\n        1& 1& 1& |& 0& 0& 0\\\\\n        0& 0& 1& |& 0& 1& 1\n    \\end{pmatrix}\n    .\n\\]\nThis equivalence induces an ordering on Pauli strings following the lexicographic ordering on bit strings. %, defined as $\\vec{y} \\leq \\vec{z}$ if either $\\vec{y} = \\vec{z}$ or else if $\\vec{y}$ $\\vec{z}$ agree on the first $k$ elements but $\\vec{y}_{k+1} < \\vec{z}_{k+1}$, where $0<1$.\nFor example, $X<Y$ because $(1|0) < (1|1)$ and $Z\\otimes \\id[2] < Z \\otimes X$ because $(0 0 | 1 0) < (0 1 | 1 0)$.\nFurthermore, if $P, Q$ are Pauli strings corresponding to binary vectors $\\vec{x}^P, \\vec{z}^P$ and $\\vec{x}^Q, \\vec{z}^Q$, then \n\\[\nP \\cdot Q \\propto\n\\bigotimes_{j=1}^n\n\\left(X^{x^P_j} Z^{z^P_j}\\right) \\left(X^{x^Q_j} Z^{z^Q_j}\\right) \n=\n\\bigotimes_{j=1}^n\n\\left(X^{x^P_j \\oplus x^Q_j } Z^{z^P_j \\oplus z^Q_j} \\right)\n\\]\nand therefore the group of $n$-qubit Pauli strings with multiplication (disregarding factors) is group isomorphic to the vector space $\\{0, 1\\}^{2n}$ with bitwise addition (i.e., exclusive or; `xor').\nConsequently, many efficient algorithms for linear-algebra problems carry over to sets of Pauli strings.\nIn particular, if $G = \\{g_1, \\dots, g_k\\}$ are length$-2n$ binary vectors (/ $n$-qubit Pauli strings) with $k\\leq n$, then we can efficiently perform the following operations.\n\\begin{description}\n%    \\item[\\emph{Orthogonalization:}] convert $G$ to a (potentially smaller) independent set, using the Gram-Schmidt procedure, in $O(n^3)$ time.\n    \\item[\\emph{RREF:}] bring $G$ into a reduced-row echelon form (RREF) using Gauss-Jordan elimination (both standard linear algebra notions) where each row (in check matrix form) has strictly more leading zeroes than the row above.\n        The RREF is achievable by $O(k^2)$ row additions (/~multiplications modulo factor) and thus $O(k^2 \\cdot n)$ time (see \\cite{berg2020circuit} for a similar algorithm).\n        In the RREF, the first $1$ after the leading zeroes in a row is called a `pivot'.\n    \\item[\\emph{Independent Set}] convert $G$ to a (potentially smaller) independent set by performing the RREF procedure and discarding resulting all-zero rows.\n    \\item[\\emph{Membership:}] determining whether a given a vector (/~Pauli string) $h$ has a decomposition in elements of $G$.\n        This task can be reduced to independence by first getting $G^{\\textnormal{RREF}}$ by applying RREF, followed by adding $h$ to $G$ and performing the Independent-Set procedure. The result has $|G^{\\textnormal{RREF}}|$ rows if $h\\in \\langle G\\rangle$, and $|G^{\\textnormal{RREF}}| + 1$ rows otherwise.\n    \\item[\\emph{Intersection:}] determine all Pauli strings which, modulo a factor, are contained in both $G_A$ and $G_B$, where $G_A, G_B$ are generator sets for $n$-qubit stabilizer subgroups.\n        This can be achieved using the Zassenhaus algorithm \\cite{LUKS1997335} in time $O(n^3)$.\n    \\item[\\emph{Division remainder:}] given a vector $h$  (/~Pauli string $h$), determine \\mbox{$ h^{\\textnormal{rem}} := \\min_{g\\in \\langle G\\rangle} \\{ g  h\\}$} (minimum in the lexicographic ordering) where $\\oplus$ denotes bitwise XOR (/~factor-discarding multiplication).\n        We do so in the check matrix picture by bringing $G$ into RREF, and then making the check vector of $h$ contain as many zeroes as possible by adding rows from $G$:\n\t\\begin{algorithmic}[1]\n        \\For{column index $j=1$ to $2n$}\n        \\If{$h_j = 1$ and $G$ has a row $g_i$ with its pivot at position $j$}\n\t\t$h := h \\oplus g_i$\n        \\EndIf\n        \\EndFor\n\t\\end{algorithmic}\n        The resulting  $h$ is $h^{\\textnormal{rem}}$.\nThis algorithm's runtime is dominated by the RREF step; $O(n^3)$.\n        %\\todo{It is hard to follow. An example might help. Perhaps indeed explain where you need it?}\n%        \\todo[inline]{Tim: this algorithm is obvious but I have not been able to find a reference.... Need to move to elsewhere?}\n% AL: I like this overview. If it is trivial let's leave it here. People might still refer to it, and we avoid claiming trivial stuff.\n\\end{description}\n\nIn this work, we will consider the group of $n$-qubit Pauli operators $\\lambda P_n \\otimes \\dots P_n$ for arbitrary $\\lambda \\in \\mathbb{C}-\\{0\\}$, denoted as $\\paulilim_n$.\nSince each stabilizer $\\lambda P \\in \\paulilim_n$ has factor $\\lambda =\\pm 1$ (follows from\n$ (\\lambda P)\\ket{\\phi} = (\\lambda P)^2 \\ket{\\phi} =  \\lambda^2 \\id \\ket{\\phi}  =\\ket{\\phi}$, hence $\\lambda^2 = 1$), the stabilizer subgroups in $\\paulilim_n$ are the same as in $\\pauli_n$.\nAs extension of the check matrix form to $A \\in \\paulilim_n$, we write $A = r \\cdot e^{i\\theta} \\cdot P_n \\otimes ...\\otimes P_1$, for $r \\in \\mathbb{R}_{> 0}$ and $\\theta\\in [0, 2\\pi)$ and represent $A$ by a length-$(2n+2)$ vector where the last entries store $r$ and $\\theta$, e.g.:\n\\[\n    \\begin{pmatrix}\n        3X &\\otimes& X &\\otimes& X\\\\\n        -\\frac{1}{2} i\\id[2] &\\otimes& Z &\\otimes& Y\n    \\end{pmatrix}\n    \\sim\n    \\begin{pmatrix}\n        1& 1& 1& |& 0& 0& 0& |&3 & 0\\\\\n        0& 0& 1& |& 0& 1& 1& |&\\frac{1}{2} & \\frac{3\\pi}{2}\n    \\end{pmatrix}\n\\]\nwhere we used $3 = 3\\cdot e^{i\\cdot 0}$ and $-\\frac{1}{2}i = \\frac{1}{2} \\cdot e^{3\\pi i/2}$.\nThe ordering on real numbers induces a lexicographic ordering (from left to right) on such extended check vectors, for example $(1, 1, | 0, 0 | 3, \\frac{1}{2} ) < (1, 1 | 1, 0 | 2, 0)$.\nLet us stress that the factor encoding $(r, \\theta)$ is less significant than the Pauli string encoding $(x_n, \\dots, x_1 | z_n, \\dots, z_1)$.\nAs a consequence, we can greedily determine the minimum of two Pauli operators.\n%We state this remark separately because we will explicitly use it for proving correctness of our algorithms in~\\autoref{sec:choose-canonical-isomorphism-pauli}--\\ref{sec:pauli-isomorphism-detection}.\n\n%\\def\\rp{r}\n%\\def\\thetap{\\theta}\n%\\def\\rq{r'}\n%\\def\\thetaq{\\theta'}\n%\\begin{remark}\n%    \\label{remark:ordering}\n%    Checking which of two Pauli operators $\\rp e^{i\\thetap} P, \\rq e^{i\\thetaq} P' \\in \\paulilim_n$ is smaller can be performed in two greedy steps: first, declare $\\rp e^{i\\thetap} P <  \\rq e^{i\\thetaq} P'$ if $P < P'$.\n%    Otherwise (i.e., if $P = P'$), then proceed to comparing the factors and declare $\\rp e^{i\\thetap} P <  \\rq e^{i\\thetaq} P'$ if and only if $(\\rp, \\thetap) < (\\rq, \\thetaq)$.\n%\\end{remark}\n\nFinally, we emphasize that the algorithms above rely on row addition, which is a commutative operation.\n%are correct because Pauli operators with factor-ignoring multiplication are group isomorphic to binary vectors with xor.\nSince conventional (i.e., factor-respecting) multiplication of Pauli operators is not commutative, the algorithms above are not straightforwardly applicable to (nonabelian subgroups of) $\\paulilim_n$.\n(For abelian subgroups of $\\paulilim_n$, such as stabilizer subgroups \\cite{aaronson2008improved}, the algorithms still do work.)\nFortunately, since Pauli strings either commute or anti-commute, row addition may only yield an factors up to the $\\pm$ sign, not the resulting Pauli strings.\nThis feature, combined with the stipulated order assigning least significance to the factor,\nenables us to invoke the algorithms above as subroutine, with postpocessing to obtain the correct factor.\nWe will do so in~\\autoref{sec:choose-canonical-isomorphism-pauli}--\\ref{sec:pauli-isomorphism-detection}.\n%\n%\n%, which may yield incorrect output (for example, the intersection of $\\langle Z \\rangle$ and $\\langle -Z \\rangle$ is $\\{\\id[2]\\}$, while if we discard scalars, the Intersection algorithm above would also return $Z$ as element in the intersection).\n%However, because $\\paulilim_n$ with factor-respecting multiplication is a non-abelian group while row addition is, there is no commutative row addition operation that preserves factors in the Pauli picture.\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "1cf4c37498a54951a9901769ff54ffe1a4e0e6ae", "size": 20336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Src/CS/sections/preliminaries.tex", "max_stars_repo_name": "Katafotic/latex_parsing", "max_stars_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Src/CS/sections/preliminaries.tex", "max_issues_repo_name": "Katafotic/latex_parsing", "max_issues_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/CS/sections/preliminaries.tex", "max_forks_repo_name": "Katafotic/latex_parsing", "max_forks_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 85.4453781513, "max_line_length": 379, "alphanum_fraction": 0.700088513, "num_tokens": 6532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6614088355157681}}
{"text": "\\input{../tex/headerfile}\n\\input{../tex/mathdefs}\n\\setcounter{MaxMatrixCols}{20}\n\\usepackage{enumerate}\n\\usepackage{Sweave}\n\\begin{document}\n\\input{basic-matrix-math-concordance}\n\n\n\n\\chapter{Basic matrix math in R}\n\\label{chap:basicmat}\n\\chaptermark{Matrix math}\n\nThis chapter reviews the basic matrix math operations that you will need to understand the course material and how to do these operations in R.\n\n\\section{Creating matrices in R}\nCreate a $3 \\times 4$ matrix, meaning 3 row and 4 columns, that is all 1s:\n\\begin{Schunk}\n\\begin{Sinput}\n matrix(1, 3, 4)\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    1    1    1    1\n[2,]    1    1    1    1\n[3,]    1    1    1    1\n\\end{Soutput}\n\\end{Schunk}\nCreate a $3 \\times 4$ matrix filled in with the numbers 1 to 12 by column (default) and by row:\n\\begin{Schunk}\n\\begin{Sinput}\n matrix(1:12, 3, 4)\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    1    4    7   10\n[2,]    2    5    8   11\n[3,]    3    6    9   12\n\\end{Soutput}\n\\begin{Sinput}\n matrix(1:12, 3, 4, byrow=TRUE)\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    1    2    3    4\n[2,]    5    6    7    8\n[3,]    9   10   11   12\n\\end{Soutput}\n\\end{Schunk}\nCreate a matrix with one column:\n\\begin{Schunk}\n\\begin{Sinput}\n matrix(1:4, ncol=1)\n\\end{Sinput}\n\\begin{Soutput}\n     [,1]\n[1,]    1\n[2,]    2\n[3,]    3\n[4,]    4\n\\end{Soutput}\n\\end{Schunk}\nCreate a matrix with one row:\n\\begin{Schunk}\n\\begin{Sinput}\n matrix(1:4, nrow=1)\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    1    2    3    4\n\\end{Soutput}\n\\end{Schunk}\nCheck the dimensions of a matrix\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:6, 2,3)\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    3    5\n[2,]    2    4    6\n\\end{Soutput}\n\\begin{Sinput}\n dim(A)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2 3\n\\end{Soutput}\n\\end{Schunk}\nGet the number of rows in a matrix:\n\\begin{Schunk}\n\\begin{Sinput}\n dim(A)[1]\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2\n\\end{Soutput}\n\\begin{Sinput}\n nrow(A)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2\n\\end{Soutput}\n\\end{Schunk}\nCreate a 3D matrix (called array):\n\\begin{Schunk}\n\\begin{Sinput}\n A=array(1:6, dim=c(2,3,2))\n A\n\\end{Sinput}\n\\begin{Soutput}\n, , 1\n\n     [,1] [,2] [,3]\n[1,]    1    3    5\n[2,]    2    4    6\n\n, , 2\n\n     [,1] [,2] [,3]\n[1,]    1    3    5\n[2,]    2    4    6\n\\end{Soutput}\n\\begin{Sinput}\n dim(A)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2 3 2\n\\end{Soutput}\n\\end{Schunk}\nCheck if an object is a matrix.  A dataframe is not a matrix.  A vector is not a matrix.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:4, 1, 4)\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    1    2    3    4\n\\end{Soutput}\n\\begin{Sinput}\n class(A)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"matrix\"\n\\end{Soutput}\n\\begin{Sinput}\n B=data.frame(A)\n B\n\\end{Sinput}\n\\begin{Soutput}\n  X1 X2 X3 X4\n1  1  2  3  4\n\\end{Soutput}\n\\begin{Sinput}\n class(B)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"data.frame\"\n\\end{Soutput}\n\\begin{Sinput}\n C=1:4\n C\n\\end{Sinput}\n\\begin{Soutput}\n[1] 1 2 3 4\n\\end{Soutput}\n\\begin{Sinput}\n class(C)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"integer\"\n\\end{Soutput}\n\\end{Schunk}\n\n\\section{Matrix multiplication, addition and transpose}\nYou will need to be very solid in matrix multiplication for the course.  If you haven't done it in awhile, google `matrix multiplication youtube' and you find lots of 5min videos to remind you.\n\nIn R, you use the \\verb@%*%@ operation to do matrix multiplication.  When you do matrix multiplication, the columns of the matrix on the left must equal the rows of the matrix on the right.  The result is a matrix that has the number of rows of the matrix on the left and number of columns of the matrix on the right.\n$$(n \\times m)(m \\times p) = (n \\times p)$$\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:6, 2, 3) #2 rows, 3 columns\n B=matrix(1:6, 3, 2) #3 rows, 2 columns\n A%*%B #this works\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]   22   49\n[2,]   28   64\n\\end{Soutput}\n\\begin{Sinput}\n B%*%A #this works\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    9   19   29\n[2,]   12   26   40\n[3,]   15   33   51\n\\end{Soutput}\n\\begin{Sinput}\n try(B%*%B) #this doesn't\n\\end{Sinput}\n\\end{Schunk}\nTo add two matrices use \\verb@+@. The matrices have to have the same dimensions.\n\\begin{Schunk}\n\\begin{Sinput}\n A+A #works\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    2    6   10\n[2,]    4    8   12\n\\end{Soutput}\n\\begin{Sinput}\n A+t(B) #works\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    2    5    8\n[2,]    6    9   12\n\\end{Soutput}\n\\begin{Sinput}\n try(A+B) #does not work since A has 2 rows and B has 3\n\\end{Sinput}\n\\end{Schunk}\nThe transpose of a matrix is denoted $\\AA^\\top$ or $\\AA^\\prime$.  To transpose a matrix in R, you use \\verb@t()@.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:6, 2, 3) #2 rows, 3 columns\n t(A) #is the transpose of A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]    1    2\n[2,]    3    4\n[3,]    5    6\n\\end{Soutput}\n\\begin{Sinput}\n try(A%*%A) #this won't work\n A%*%t(A) #this will\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]   35   44\n[2,]   44   56\n\\end{Soutput}\n\\end{Schunk}\n\n\\section{Subsetting a matrix}\nTo subset a matrix, we use \\verb@[ ]@:\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:9, 3, 3) #3 rows, 3 columns\n #get the first and second rows of A\n #it's a 2x3 matrix\n A[1:2,]\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    4    7\n[2,]    2    5    8\n\\end{Soutput}\n\\begin{Sinput}\n #get the top 2 rows and left 2 columns\n A[1:2,1:2]\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]    1    4\n[2,]    2    5\n\\end{Soutput}\n\\begin{Sinput}\n #What does this do?\n A[c(1,3),c(1,3)]\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]    1    7\n[2,]    3    9\n\\end{Soutput}\n\\begin{Sinput}\n #This?\n A[c(1,2,1),c(2,3)]\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]    4    7\n[2,]    5    8\n[3,]    4    7\n\\end{Soutput}\n\\end{Schunk}\nIf you have used matlab, you know you can say something like \\verb@A[1,end]@ to denote the element of a matrix in row 1 and the last column.  R does not have `end'.  To do, the same in R you do something like:\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:9, 3, 3)\n A[1,ncol(A)]\n\\end{Sinput}\n\\begin{Soutput}\n[1] 7\n\\end{Soutput}\n\\begin{Sinput}\n #or\n A[1,dim(A)[2]]\n\\end{Sinput}\n\\begin{Soutput}\n[1] 7\n\\end{Soutput}\n\\end{Schunk}\n\n\\textbf{Warning R will create vectors from subsetting matrices!}\n\nOne of the really bad things that R does with matrices is create a vector if you happen to subset a matrix to create a matrix with 1 row or 1 column.  Look at this:\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:9, 3, 3)\n #take the first 2 rows\n B=A[1:2,]\n #everything is ok\n dim(B)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2 3\n\\end{Soutput}\n\\begin{Sinput}\n class(B)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"matrix\"\n\\end{Soutput}\n\\begin{Sinput}\n #take the first row\n B=A[1,]\n #oh no! It should be a 1x3 matrix but it is not.\n dim(B)\n\\end{Sinput}\n\\begin{Soutput}\nNULL\n\\end{Soutput}\n\\begin{Sinput}\n #It is not even a matrix any more\n class(B)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"integer\"\n\\end{Soutput}\n\\begin{Sinput}\n #and what happens if we take the transpose?\n #Oh no, it's a 1x3 matrix not a 3x1 (transpose of 1x3)\n t(B)\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    4    7\n\\end{Soutput}\n\\begin{Sinput}\n #A%*%B should fail because A is (3x3) and B is (1x3)\n A%*%B\n\\end{Sinput}\n\\begin{Soutput}\n     [,1]\n[1,]   66\n[2,]   78\n[3,]   90\n\\end{Soutput}\n\\begin{Sinput}\n #It works? That is horrible!\n\\end{Sinput}\n\\end{Schunk}\nThis will create hard to find bugs in your code because you will look at \\verb@B=A[1,]@ and everything looks fine.  Why is R saying it is not a matrix!  To stop R from doing this use \\verb@drop=FALSE@.\n\\begin{Schunk}\n\\begin{Sinput}\n B=A[1,,drop=FALSE]\n #Now it is a matrix as it should be\n dim(B)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 1 3\n\\end{Soutput}\n\\begin{Sinput}\n class(B)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"matrix\"\n\\end{Soutput}\n\\begin{Sinput}\n #this fails as it should (alerting you to a problem!)\n try(A%*%B)\n\\end{Sinput}\n\\end{Schunk}\n\n\\section{Replacing elements in a matrix}\nReplace 1 element.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1, 3, 3)\n A[1,1]=2\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    2    1    1\n[2,]    1    1    1\n[3,]    1    1    1\n\\end{Soutput}\n\\end{Schunk}\nReplace a row with all 1s or a string of values\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1, 3, 3)\n A[1,]=2\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    2    2    2\n[2,]    1    1    1\n[3,]    1    1    1\n\\end{Soutput}\n\\begin{Sinput}\n A[1,]=1:3\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    2    3\n[2,]    1    1    1\n[3,]    1    1    1\n\\end{Soutput}\n\\end{Schunk}\nReplace group of elements.  This often does not work as one expects so be sure look at your matrix after trying something like this.  Here I want to replace elements (1,3) and (3,1) with 2, but it didn't work as I wanted.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1, 3, 3)\n A[c(1,3),c(3,1)]=2\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    2    1    2\n[2,]    1    1    1\n[3,]    2    1    2\n\\end{Soutput}\n\\end{Schunk}\nHow do I replace elements (1,1) and (3,3) with 2 then?  It's tedious.  If you have a lot of elements to replace, you might want to use a for loop.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1, 3, 3)\n A[1,3]=2\n A[3,1]=2\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    1    2\n[2,]    1    1    1\n[3,]    2    1    1\n\\end{Soutput}\n\\end{Schunk}\n\n\\section{Diagonal matrices and identity matrices}\nA diagonal matrix is one that is square, meaning number of rows equals number of columns, and it has 0s on the off-diagonal and non-zeros on the diagonal.  In R, you form a diagonal matrix with the \\verb@diag()@ function:\n\\begin{Schunk}\n\\begin{Sinput}\n diag(1,3) #put 1 on diagonal of 3x3 matrix\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    0    0\n[2,]    0    1    0\n[3,]    0    0    1\n\\end{Soutput}\n\\begin{Sinput}\n diag(2, 3) #put 2 on diagonal of 3x3 matrix\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    2    0    0\n[2,]    0    2    0\n[3,]    0    0    2\n\\end{Soutput}\n\\begin{Sinput}\n diag(1:4) #put 1 to 4 on diagonal of 4x4 matrix\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    1    0    0    0\n[2,]    0    2    0    0\n[3,]    0    0    3    0\n[4,]    0    0    0    4\n\\end{Soutput}\n\\end{Schunk}\nThe \\verb@diag()@ function can also be used to replace elements on the diagonal of a matrix:\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(3, 3, 3)\n diag(A)=1\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    3    3\n[2,]    3    1    3\n[3,]    3    3    1\n\\end{Soutput}\n\\begin{Sinput}\n A=matrix(3, 3, 3)\n diag(A)=1:3\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    3    3\n[2,]    3    2    3\n[3,]    3    3    3\n\\end{Soutput}\n\\begin{Sinput}\n A=matrix(3, 3, 4)\n diag(A[1:3,2:4])=1\n A\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3] [,4]\n[1,]    3    1    3    3\n[2,]    3    3    1    3\n[3,]    3    3    3    1\n\\end{Soutput}\n\\end{Schunk}\nThe \\verb@diag@ function is also used to get the diagonal of a matrix.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:9, 3, 3)\n diag(A)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 1 5 9\n\\end{Soutput}\n\\end{Schunk}\nThe identity matrix is a special kind of diagonal matrix with 1s on the diagonal.  It is denoted $\\II$.  $\\II_3$ would mean a $3 \\times 3$ diagonal matrix.  A identity matrix has the property that $\\AA\\II=\\AA$ and $\\II\\AA=\\AA$ so it is like a 1.\n\\begin{Schunk}\n\\begin{Sinput}\n A=matrix(1:9, 3, 3)\n I=diag(3) #shortcut for 3x3 identity matrix\n A%*%I\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2] [,3]\n[1,]    1    4    7\n[2,]    2    5    8\n[3,]    3    6    9\n\\end{Soutput}\n\\end{Schunk}\n\n\\section{Taking the inverse of a square matrix}\nThe inverse of a matrix is denoted $\\AA^{-1}$.  You can think of the inverse of a matrix like $1/a$.  $1/a \\times a = 1$. $\\AA^{-1}\\AA = \\AA\\AA^{-1} = \\II$.  The inverse of a matrix does not always exist; for one it has to be square.  We'll be using inverses for variance-covariance matrices and by definition (of a variance-covariance matrix), the inverse of those exist.  In R, there are a couple way common ways to take the inverse of a variance-covariance matrix (or something with the same properties).  \\verb@solve@ is the most common probably:\n\\begin{Schunk}\n\\begin{Sinput}\n A=diag(3,3)+matrix(1,3,3)\n invA=solve(A)\n invA%*%A\n\\end{Sinput}\n\\begin{Soutput}\n             [,1]          [,2] [,3]\n[1,] 1.000000e+00 -6.938894e-18    0\n[2,] 2.081668e-17  1.000000e+00    0\n[3,] 0.000000e+00  0.000000e+00    1\n\\end{Soutput}\n\\begin{Sinput}\n A%*%invA\n\\end{Sinput}\n\\begin{Soutput}\n             [,1]          [,2] [,3]\n[1,] 1.000000e+00 -6.938894e-18    0\n[2,] 2.081668e-17  1.000000e+00    0\n[3,] 0.000000e+00  0.000000e+00    1\n\\end{Soutput}\n\\end{Schunk}\nAnother option is to use \\verb@chol2inv@ which uses a Cholesky decomposition\\footnote{The Cholesky decomposition is a handy way to keep your variance-covariance matrices valid when doing a parameter search.  Don't search over the raw variance-covariance matrix.  Search over a matrix where the lower triangle is 0, that is what a Cholesky decomposition looks like.  Let's call it \\texttt{B}. Your variance-covariance matrix is \\texttt{t(B)\\%*\\%B}.}:\n\\begin{Schunk}\n\\begin{Sinput}\n A=diag(3,3)+matrix(1,3,3)\n invA=chol2inv(chol(A))\n invA%*%A\n\\end{Sinput}\n\\begin{Soutput}\n              [,1]         [,2]          [,3]\n[1,]  1.000000e+00 6.938894e-17  0.000000e+00\n[2,]  2.081668e-17 1.000000e+00 -2.775558e-17\n[3,] -5.551115e-17 0.000000e+00  1.000000e+00\n\\end{Soutput}\n\\begin{Sinput}\n A%*%invA\n\\end{Sinput}\n\\begin{Soutput}\n             [,1]          [,2]          [,3]\n[1,] 1.000000e+00  2.081668e-17 -5.551115e-17\n[2,] 6.938894e-17  1.000000e+00  0.000000e+00\n[3,] 0.000000e+00 -2.775558e-17  1.000000e+00\n\\end{Soutput}\n\\end{Schunk}\nFor the purpose of this course, \\verb@solve@ is fine.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\clearpage\n\\renewcommand{\\rightmark}{}\n\\section*{Problems}\n\\addcontentsline{toc}{section}{Problems}\n\n\\begin{hwenumerate} \n\\item Build a $4 \\times 3$ matrix with the numbers 1 through 4 in each row.\n\\item Extract the elements in the 1st and 2nd rows and 1st and 2nd columns (you'll have a $2 \\times 2$ matrix). Show the R code that will do this.\n\\item Build a $4 \\times 3$ matrix with the numbers 1 through 12 by row (meaning the first row will have the numbers 1 through 4 in it).\n\\item Extract the 3rd row of the above.  Show R code to do this where you end up with a vector and how to do this where you end up with a $1 \\times 3$ matrix.\n\\item Build a $4 \\times 3$ matrix that is all 1s except a 2 in the (2,3) element (2nd row, 3rd column).\n\\item Take the transpose of the above.\n\\item Build a $4 \\times 4$ diagonal matrix with 1 through 4 on the diagonal.\n\\item Build a $5 \\times 5$ identity matrix.\n\\item Replace the diagonal in the above matrix with 2 (the number 2).\n\\item Build a matrix with 2 on the diagonal and 1s on the offdiagonals.\n\\item Take the inverse of the above.\n\\item Build a $3 \\times 3$ matrix with the first 9 letters of the alphabet.  First column should be ``a'', ``b'', ``c''.  \\verb@letters[1:9]@ gives you these letters.\n\\item Replace the diagonal of this matrix with the word ``cat''.\n\\item Build a $4 \\times 3$ matrix with all 1s. Multiply by a $3 \\times 4$ matrix with all 2s.\n\\item If $\\AA$ is a $4 \\times 3$ matrix, is $\\AA \\AA$ possible? Is $\\AA  \\AA^\\top$ possible?  Show how to write $\\AA\\AA^\\top$ in R.\n\\item In the equation, $\\AA \\BB = \\CC$, let $\\AA=\\left[ \\begin{smallmatrix}1&4&7\\\\2&5&8\\\\3&6&9\\end{smallmatrix}\\right]$.  Build a $\\BB$ matrix with only 1s and 0s such that the values on the diagonal of $\\CC$ are 1, 8, 6 (in that order).  Show your R code for $\\AA$, $\\BB$ and $\\AA \\BB$.\n\\item Same $\\AA$ matrix as above and same equation $\\AA \\BB = \\CC$.  Build a $3 \\times 3$ $\\BB$ matrix such that $\\CC=2\\AA$.  So $\\CC=\\left[ \\begin{smallmatrix}2&8&14\\\\ 4&10&16\\\\ 6&12&18\\end{smallmatrix}\\right]$. Hint, $\\BB$ is diagonal.\n\\item Same $\\AA$ and $\\AA \\BB=\\CC$ equation.  Build a $\\BB$ matrix to compute the row sums of $\\AA$.  So the first `row sum' would be $1+4+7$, the sum of all elements in row 1 of $\\AA$.  $\\CC$ will be $\\left[ \\begin{smallmatrix}12\\\\ 15\\\\ 18\\end{smallmatrix}\\right]$, the row sums of $\\AA$. Hint, $\\BB$ is a column matrix (1 column).\n\\item Same $\\AA$ matrix as above but now equation $\\BB \\AA  = \\CC$.  Build a $\\BB$ matrix to compute the column sums of $\\AA$.  So the first `column sum' would be $1+2+3$.  $\\CC$ will be a $1 \\times 3$ matrix.\n\\item Let $\\AA \\BB=\\CC$ equation but $\\AA=\\left[ \\begin{smallmatrix}2&1&1\\\\1&2&1\\\\1&1&2\\end{smallmatrix}\\right]$ (so A=\\verb@diag(3)+1@).  Build a $\\BB$ matrix such that $\\CC=\\left[ \\begin{smallmatrix}3\\\\ 3\\\\ 3\\end{smallmatrix}\\right]$. Hint, you need to use the inverse of $\\AA$.\n\n\\end{hwenumerate}\n\n\n\\bibliography{../tex/Fish507}\n\n\\end{document}\n", "meta": {"hexsha": "32725d925e729258f3c54155d74b1d56646d920c", "size": 16954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Week 0 basic matrix/basic-matrix-math.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/Week 0 basic matrix/basic-matrix-math.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/Week 0 basic matrix/basic-matrix-math.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": 26.5320813772, "max_line_length": 550, "alphanum_fraction": 0.619027958, "num_tokens": 6937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.661408831179094}}
{"text": "\\subsubsection{The Spectral Theorem}\n\nWith the introduction in previous section of the gramian matrix\n$\\trans{A}A$, it is time for the heavy machinery that will allow us to\nprove the SVD \\cref{thm:SVD}; we are talking of course, about\nthe Spectral Theorem. We will not only present the theorem, but also\ninclude one of the many possible proofs. The one we chose was published\nby Wilf in \\cite{wilf81}, and we did so because of its brevity and\nelegance. It actually makes an interesting connection between the\nLinear Algebra world where have been moving so far, and the  world of\nTopology; the link is created by using the properties of compact\nsets. But before defining what a compact set is, let us \nmotivate this interesting usage. \\\\\n\nA common problem that many people are familiar with, specially if they\ntook single-variable calculus courses at college; is that of finding the\nminima or maxima of a given function $f: \\R{} \\fromto \\R{}$. There is a\nmechanical part about how to calculate those critical points, but a\ncrucial part is to verify on the first place, if they actually\nexist. A common requirement is for the function $f$ to be continuous,\nbut further requirements are also needed on its domain. The reader may\nrecall the famous Extreme Value Theorem, which establishes what are those\nconditions on the domain for single-variable functions: \\\\\n\n\\begin{theorem}\n\\label{thm:xtrem}\nLet $f: \\R{} \\fromto \\R{}$ be a continuous function over the closed\n(and bounded interval) $[a,b]$, then $f$ reaches its maximum and its\nminimum over the same interval. \n\\end{theorem}\n\\hfill\n\nThe \\cref{thm:xtrem} tells us what the required condition is on\nthe domain of a continuous function $f$, in order to guarantee that its\ncritical points (minimum/maximum) actually exist. The\ncondition is simply to have a closed interval, which though not\nevident, has the following two properties: \\\\\n\n\\begin{enumerate}\n\\item Closed: It contains its limit points \\footnote{The intuitive\n  idea for limit points, is that a ``limit'' process can approximate\n  them by using points inside the set.} (like $0$ and $1$).\n\\item Bounded: There are real numbers which serve as lower and upper\n  bounds for all the elements of the interval \\footnote{In the case of a closed\n  interval in \\R{}, these bounds happen to be the limit points and are\n  inside the interval; but for more general spaces, that may not be\n  the case.}.\n\\end{enumerate}\n\\hfill\n\nA set which has these properties of being closed and bounded, is said\nto be compact. Being compact, is  a generalization of the closed intervals\non the real line. Why do we need such generalization? Well, simply\nbecause we may be interested in calculating minima and maxima for\nfunctions defined over more complex sets than \\R{}; for example,\nvector spaces or matrix spaces. Another important property of\ncompact sets, is that continuous functions preserve its\n``compactness''; that is, if $S$ is a compact set and $f$ a continuous\nfunction, then $\\func{f}(S)$ is also a compact set. \\\\\n\nArmed with this brief, but hopefully enough understanding of what\ncompact sets are; let us proceed with the proof.\nThe first required artifact is a function called \\func{Od}, which\nintuitively measures how close is an square matrix of $n \\times n$,\nfrom having a diagonal form:\n\n\\[\n\\func{Od}(A) = {\\sum\\sum}_{i \\ne i} A_{ij}^2\n\\]\n\\hfill\n\nThe next artifact we need is the set of all orthogonal matrices\n(denoted \\bigO{n} \\footnote{Not to be confused with the big-O\n  notation for algorithms complexity.}). Using product multiplication, this set has the\nalgebraic structure of a group (though we do not really need such\nproperty here). \\\\\n\nThe next tool is the following theorem, about Jacobi's method for\nfinding eigenvalues, which tells us that it is always possible to\nperform rigid transformations (change of basis), that take one\nnon-diagonal matrix into a new one that is closer to a diagonal form\n(per the metric defined by function $\\func{Od}$). \\\\\n\n\\begin{theorem}\n\\label{thm:jacobi}\nIf $A$ is a real non-diagonal matrix, $\\implies$ there is an orthogonal\nmatrix $J$ such that $\\func{Od}(\\trans{J} A J) < \\func{Od}(A)$. \n\\end{theorem}\n\\hfill\n\nAn informal proof is given in \\cite{wilf81}, and a more detailed\ndiscussion is found in \\cite{golub13}. This is the last tool we needed\nfor presenting the proof of the Spectral Theorem from \\cite{wilf81},\nwhich follows below: \\\\\n\n\\begin{theorem}\n\\label{thm:spec}\nIf $A$ is a symmetric real matrix, $\\implies$ there is a real orthogonal\nmatrix $Q$ such that $\\trans{Q}AQ$ is diagonal. \n\\end{theorem}\n\\hfill\n\n\\begin{proof}\nLet $f$ be the function that, given the fixed matrix $A$, maps every\northogonal matrix $P$ into the product $\\trans{P}AP$. This function is\ncontinuous over the compact set \\bigO{n}; hence, $\\func{f}(\\bigO{n})$ is also\ncompact. The set $\\func{f}(\\bigO{n})$ contains all the possible products of\nfixed matrix $A$ with orthogonal matrices, that may or may not give a diagonal\n as result. Then, we basically use brute force: search for the best\ncandidate in that set of options. And we do that, by using the metric\nwe define specifically for that purpose: the function\n$\\func{Od}$. Thus, we want to search for the product of the form\n$\\trans{P}AP$ (an element of $\\func{f}(\\bigO{n})$ which give us the\nminimum value of function $\\func{Od}$. Here is where the compactness\nproperty comes into play; if the domain $\\func{f}(\\bigO{n})$ was not compact, we could\nnot even talk about the minimum of the (continuous) function\n$\\func{Od}$. \\\\\n\nKnowing that, the existence of the minimum of function \\func{Od} in the\nset $\\func{f}(\\bigO{n})$ is granted, the next thing to realize is that\nsuch minimum must be zero. This is easily seen by using reduction to\nthe absurd: let us suppose that the minimum reached at matrix\n$D = \\trans{Q}AQ$, is not zero. That would mean the matrix $D$ is not\ndiagonal yet and then, by \\cref{thm:jacobi} we know that there\nmust exist another matrix $D^{*} = \\trans{Q}DQ$, such that\n$\\func{Od}(D^{*}) < \\func{Od}(D)$. But that contradicts the assumption\nthat the minimum was reached at $D$. Therefore, the minimum of\n\\func{Od} must be zero. \\\\\n\nIf the minimum of \\func{Od} is zero, it means that is reached on a\nmatrix which is diagonal (the square of all its\noff-diagonal\\footnote{The off-diagonal elements of a matrix, are those\nwhich do not lie on the diagonal.} elements is zero, which means they\nare all zero).  The existence of such diagonal matrix of the form\n$\\trans{Q}AQ$ proves the theorem. \\\\\n\\end{proof}\n\\hfill\n\nThere are a couple of useful corollaries that derive from the Spectral\nTheorem just proved: \\\\\n\n\\begin{itemize}\n\\item In the search of the minimum, there was an implicit iterative\n  process of applying multiplications, where the matrix at step $i+1$,\n  was obtained from the previous matrix at step $i$, in the following\n  way: $D_{i+1} = \\trans{J}D_iJ$ (the matrices $J$ are obtained by the\n  Jacobi's method of rotations \\footnote{This algorithmic perspective,\n  is actually the main inspiration of this proof, which is taken from\n  \\cite{wilf81}}). If we think in the series of \n  transformations done by this iteration, from the original matrix\n  $A$, we would realize that all we did was to apply rigid\n  transformations; therefore, the resulting entries in the diagonal\n  must be real (there is no way that applying a rotation to real\n  matrix, produces another matrix with complex entries). \\\\\n\n\\item The second observation is that the result $D = \\trans{Q}AQ$,\n  where $D$ is a diagonal matrix; implies that $AQ = QD$, which in\n  turn can be broken into individual equations of the form $A\\vec{q_i}\n  = d_i\\vec{q_i}$. This tells us that the columns of the orthogonal\n  matrix $Q$ are the eigenvectors of $A$, and that the diagonal of $D$\n  contains its eigenvalues. We started the other way around, but in\n  practice, the usual motivation for diagonalizing a symmetric matrix\n  (or for applying the Jacobi's method), is to actually find the\n  eigenvalues and eigenvectors. \n\\end{itemize}\n\\hfill\n\nThese two corollaries will be useful in the final proof to come, that\nof the SVD \\cref{thm:SVD}. \n", "meta": {"hexsha": "ab7ec8c6d5263a2804491fd6cac8e5081182619a", "size": 8127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-proof-spec-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-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-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": 47.8058823529, "max_line_length": 87, "alphanum_fraction": 0.753783684, "num_tokens": 2156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6614088266839143}}
{"text": "\\section{Planar Approximation}\nIt is time to deal with the pole situation. The north and south poles that is, not the lovely people over in Poland. We run into problems because the latitude longitude grid cells become to small \nnear the poles. Therefore, the magnitudes no longer fit into one cell and overflow into other cells which makes everything kind of funky. So we need to fix that, and we do that by a planar \napproximation. \n\n\\subsection{The Initial Theory}\nAs said earlier, the grid cells on the latitude longitude grid get closer together the closer you get to the poles which poses problems. To fix this, we will be using a planar approximation of \nthe poles. What this means is that we will map the 3D grid near the poles onto a 2D plane parallel to the poles, as if we put a giant flat plane in the exact center of the poles and draw lines\nfrom the grid directly upwards to the plane. For a visual representation, please consult the stream with timestamp 1:38:25 \\cite{polarPlane}, which includes some explanation. In the streamm we\nuse $r$ to indicate the radius of the planet (which we assume is a sphere), $\\theta$ for the longitude and $\\lambda$ for the latitude. So we have spherical coordinates, which we need to transform\ninto $x$ and $y$ coordinates on the plane. We also need the distance between the center point (the point where the plane touches the planet which is the center of the pole) and the projected \npoint on the plane from the grid (the location on the plane where a line from the gird upwards to the plane hits it). This distance is denoted by $a$ (Simon chose this one, not me). We then get \nthe following equations as shown in \\autoref{eq:polar distance}, \\autoref{eq:polar x} and \\autoref{eq:polar y}. \n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:polar distance}\n        a = r \\cos(\\theta)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar x}\n        x = a \\sin(\\lambda)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar y}\n        y = a \\cos(\\lambda)\n    \\end{equation}\n\\end{subequations}\n\nBut what if we know $x$ and $y$ and want to know $\\theta$ and $\\lambda$? Pythagoras' Theorem then comes into play \\cite{pythagoras}. We know that (due to Pythagoras) \\autoref{eq:pythagoras} must \nalways be true. Then if we substitue $a$ by $\\sqrt{x^2 + y^2}$ in \\autoref{eq:polar distance} we get \\autoref{eq:polar theta1}. Then we transform that equation such that we only have $\\theta$ on \none side and the rest on the other side (since we want to know $\\theta$) and we get \\autoref{eq:polar theta3}.\n\\begin{equation}\n    \\label{eq:pythagoras}\n    x^2 + y^2 = a^2\n\\end{equation}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:polar theta1}\n        \\sqrt{x^2 + y^2} = r\\cos(\\theta)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar theta2}\n        \\frac{\\sqrt{x^2 + y^2}}{r} = \\cos(\\theta)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar theta3}\n        \\arccos(\\frac{\\sqrt{x^2 + y^2}}{r}) = \\theta\n    \\end{equation}\n\\end{subequations}\n\nFor $\\lambda$ we need another trigonometric function which is the tangent ($\\tan$). The tangent is defined in \\autoref{eq:tan}. If we then take a look at \\autoref{eq:polar x} and \n\\autoref{eq:polar y}, we see that $\\lambda$ is present in both equations. So we need to use both to get $\\lambda$ \\footnote{Yes you could only use one but since we both know $x$ and $y$ it is a\nbit easier to use both than to only use one as you need to know $\\theta$ at that point as well which may or may not be the case.}. So let's combine \\autoref{eq:polar x} and \\autoref{eq:polar y}\nin \\autoref{eq:polar lambda1}, transform it such that we end up with only $\\lambda$ on one side and the rest on the other side and we end up with \\autoref{eq:polar lambda3}.\n\n\\begin{equation}\n    \\label{eq:tan}\n    \\tan(\\alpha) = \\frac{\\sin(\\alpha)}{\\cos(\\alpha)}\n\\end{equation}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:polar lambda1}\n        \\frac{x}{y} = \\frac{a\\sin(\\lambda)}{a\\cos(\\lambda)} = \\frac{\\sin(\\lambda)}{\\cos(\\lambda)}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar lambda2}\n        \\frac{x}{y} = \\tan(\\lambda)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar lambda3}\n        \\lambda = \\arctan(\\frac{x}{y})\n    \\end{equation}\n\\end{subequations}\n\n\\subsection{The Grid Code}\nTo start the planar approximation, we first need to create a grid. One for the north pole, and one for the south pole. Now since the project is made in Python, Simon uses a function to generate \na grid from two coordinate vectors (lists with a coordinate as elements). Since the documentation tries to not be language specific, I instead opt to use words instead of function calls. What \nthat comes down to is use your favourite language and import the libraries that do this for you, or start coding your own after finding out how to do that (your mileage may vary). To implement \nthe grid function in the exact same way as the numpy packages does, please refer to the following two references \\cite{meshgridDoc} \\cite{meshgridGFG}. Anyway, the code for the grid can be found \nin \\autoref{alg:polar grid south}. To convert $x, y$ coordinates into $lat, lon$ coordinates, we make use of \\autoref{eq:polar theta3} and \\autoref{eq:polar lambda3}. Keep in mind that the \nequations themselves assume that the angles are in radians, whereas the model uses the angles in degrees so they need to be converted. To convert from $lat, lon$ back into $x, y$ we need to \ncombine \\autoref{eq:polar distance}, \\autoref{eq:polar x} and \\autoref{eq:polar y}. $gridPad$ refers to how many cells for padding we add to the grid. We add padding so that the calculations \nlater on all go smoothly and don't require complex and specific code to deal with them. The more general an algorithm is, the better, as you can reuse it for other things while not adjusting\nthe algorithm for that particular problem. That way, it is easier and better to adjust the input then to alter the algorithm.\n\n\\begin{algorithm}[htb]\n    \\caption{Generating the grid for polar approximation of the south pole}\n    \\label{alg:polar grid south}\n    \\SetKwComment{Comment}{//}{}\n    $poleLowIndexS \\leftarrow $ find first index where $lat > poleLowerLatLimit$ \\;\n    $poleHighIndexS \\leftarrow $ find first index where $lat > poleHigherLatLimit$ \\;\n    $polarGridResolution \\leftarrow dx[poleLowIndexS] $ \\Comment*[l]{Will be reused for the north pole}\n    $gridSize \\leftarrow r \\cos(lat[poleLowIndexS + gridPad] \\frac{\\pi}{180})$ \\Comment*[l]{Will be reused for the north pole}\n    \\BlankLine\n\n    $gridXAxisS \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridYAxisS \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridXValuesS, gridYValuesS \\leftarrow $ generate the grid from the two axis vectors $gridXAxissS$ and $gridYAxissS$ \\;\n    $gridSideLength \\leftarrow gridXValuesS.length $ \\Comment*[l]{Is globally available\\dots}\n    \\BlankLine \n\n    $gridLatCoordsS \\leftarrow $ empty list \\;\n    $gridLonCoordsS \\leftarrow $ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $gridXValuesS.length$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $gridXValuesS[i].length$}{\n            $x \\leftarrow gridXValuesS[i, j]$ \\;\n            $y \\leftarrow gridYValuesS[i, j]$ \\;\n            $latPoint \\leftarrow -\\arccos(\\frac{\\sqrt{x^2 + y^2}}{r})\\frac{180}{\\pi}$ \\;\n            $lonPoint \\leftarrow 180 - \\arctan(\\frac{x}{y})\\frac{180}{\\pi}$ \\;\n            $gridLatCoordsS.append(latPoint)$ \\;\n            $gridLonCoordsS.append(lonPoint)$ \\;\n        }\n    }\n\n    \\BlankLine\n    $polarXCoordsS \\leftarrow$ empty list \\;\n    $polarYCoordsS \\leftarrow$ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndexS$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $nlon$}{\n            $polarXCoordsS.append(r \\cos(lat[i] \\frac{\\pi}{180}) \\sin(lon[j]\\frac{\\pi}{180}))$ \\;\n            $polarYCoordsS.append(-r \\cos(lat[i] \\frac{\\pi}{180}) \\cos(lon[j]\\frac{\\pi}{180}))$ \\;\n        }\n    }\n\\end{algorithm}\n\nTo make the process of generating the grid faster, we can vectorise the first for loop as shown in \\autoref{alg:polar grid south vectorised}. Here instead of going over each value one by one \n(and because Python is an interpreter based language, the interpreter cannot optimise it out as it does not know what is coming next) we treat everything as a vector or a scalar. By treating the \narrays as a vector, Python can efficiently (and most likely in parallel) perform the same calculations as it would do by using the classic for loop. We include the \\texttt{flatten()} method as \nit forces everything to be a one dimensional array (vector).\n\n\\begin{algorithm}[htb]\n    \\caption{Snippet for generating the grid for polar approximation of the south pole}\n    \\label{alg:polar grid south vectorised}\n    $gridLatCoordsS \\leftarrow (-\\arccos(\\frac{\\sqrt{gridXValuesS^2 + gridYValuesS^2}}{r})\\frac{180}{\\pi}).$\\texttt{flatten()} \\;\n    $gridLonCoordsS \\leftarrow (180 - \\arctan(\\frac{gridXValuesS}{gridYValuesS})\\frac{180}{\\pi}).$\\texttt{flatten()} \\;\n\\end{algorithm}\n\nWe need to do a similar thing for the north pole and insert a few changes to some of the equations to correct for different angles and similar things. The code can be found in \n\\autoref{alg:polar grid north}. Again, see the references at the south pole explanation on how to generate the grid itself.\n\n\\begin{algorithm}[htb]\n    \\caption{Generating the grid for polar approximation of the north pole}\n    \\label{alg:polar grid north}\n    \\SetKwComment{Comment}{//}{}\n    $poleLowIndexN \\leftarrow $ find last index where $lat < -poleLowerLatLimit$ \\;\n    $poleHighIndexN \\leftarrow $ find last index where $lat < -poleHigherLatLimit$ \\;\n    \\BlankLine\n\n    $gridXAxisN \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridYAxisN \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridXValuesN, gridYValuesN \\leftarrow $ generate the grid from the two axis vectors $gridXAxisN$ and $gridYAxisN$ \\;\n    \\BlankLine \n    \n    $gridLatCoordsN \\leftarrow $ empty list \\;\n    $gridLonCoordsN \\leftarrow $ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $gridXValuesN.length$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $gridXValuesN[i].length$}{\n            $x \\leftarrow gridXValuesN[i, j]$ \\;\n            $y \\leftarrow gridYValuesN[i, j]$ \\;\n            $latPoint \\leftarrow \\arccos(\\frac{\\sqrt{x^2 + y^2}}{r})\\frac{180}{\\pi}$ \\;\n            $lonPoint \\leftarrow 180 - \\arctan(\\frac{x}{y})\\frac{180}{\\pi}$ \\;\n            $gridLatCoordsN.append(latPoint)$ \\;\n            $gridLonCoordsN.append(lonPoint)$ \\;\n        }\n    }\n\n    \\BlankLine\n    $polarXCoordsN \\leftarrow$ empty list \\;\n    $polarYCoordsN \\leftarrow$ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndexN$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $nlon$}{\n            $polarXCoordsN.append(r \\cos(lat[i] \\frac{\\pi}{180}) \\sin(lon[j]\\frac{\\pi}{180}))$ \\;\n            $polarYCoordsN.append(-r \\cos(lat[i] \\frac{\\pi}{180}) \\cos(lon[j]\\frac{\\pi}{180}))$ \\;\n        }\n    }\n\\end{algorithm}\n\nAs was the case with the south pole, we can optimise the first for loop by vectorising it. A similar snippet to \\autoref{alg:polar grid south vectorised} is the result, though there are small \nchanges. These changes can be found in \\autoref{alg:polar grid north vectorised}.\n\n\\begin{algorithm}[htb]\n    \\caption{Snippet for generating the grid for polar approximation of the north pole}\n    \\label{alg:polar grid north vectorised}\n    $gridLatCoordsS \\leftarrow (\\arccos(\\frac{\\sqrt{gridXValuesN^2 + gridYValuesN^2}}{r})\\frac{180}{\\pi}).$\\texttt{flatten()} \\;\n    $gridLonCoordsS \\leftarrow (180 - \\arctan(\\frac{gridXValuesN}{gridYValuesN})\\frac{180}{\\pi}).$\\texttt{flatten()} \\;\n\\end{algorithm}\n\nIn both algorithms it is important to make a distinction between $gridLatCoords$ and $polarXCoords$ and their respective variants. $gridLatCoords$ are the latitudinal coordinates on the \n$lat, lon$ grid corresponding to the $x$ and $y$ coordinates on the polar grid. Whereas $polarXCoords$ are the $x$ coordinates on the polar grid corresponding to the latitude and longitude on \nthe $lat, lon$ grid. Those are different to the $gridXValues$ as they represent the values on the $x$ axis as integers which may or may not directly correspond to the $polarXCoords$. So we need \na way of mapping the $polarXCoords$ to $gridXValues$ and their respective values and vice versa. This is done in \\autoref{sec:polar switch}.\n\n\\subsection{Switching between grids} \\label{sec:polar switch}\nNow that we have defined the polar plane grid, we need code to convert the values from the $lat, lon$ grid to the polar plane grid and vice versa. Let's start with converting to the polar grid. \nWe need 2 versions of the algorithm for that. One that converts in 2 dimensions, and one that converts in 3 dimensions. The code for the 2 dimensional case is shown in \\autoref{alg:beam up 2d}.\nHere we use bivariate spline interpolation \\cite{bivariatespline} which is a different form of linear interpolation than discussed in \\autoref{sec:interpolation} though the same principle \napplies.\n\n\\begin{algorithm}[htb]\n    \\caption{Converting from $lat, lon$ grid to polar plane grid in 2 dimensions}\n    \\label{alg:beam up 2d}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Latitude coordinates $lat$, Longitude coordinates $lon$, Values of the $lat, lon$ grid $data$, Length of one axis of the polar grid? $gridSize$, Latitude coordinates on the polar grid \n        $gridLatCoords$, Longitude coordinates on the polar grid $gridLonCoords$}\n    \\Output{Double array representing the values of the $lat, lon$ grid on the polar grid}\n    \\SetKwComment{Comment}{//}{}\n    $f \\leftarrow $ \\texttt{BivariateSpline}($lat, lon, data$) \\Comment*[l]{Do the interpolation}\n    $polarPlane \\leftarrow f(gridLatCoords, gridLonCoords).$\\texttt{reshape}(($gridSize$, $gridSize$)) \\Comment*[l]{Check the values of the interpolation at the specified coordinates and force \n    them to align to the polar grid}\n    \\Return{$polarPlane$}\n\\end{algorithm}\n\nThe 3 dimensional algorithm is quite similar to the 2 dimensional algorithm, which can be found in \\autoref{alg:beam up 3d}\n\n\\begin{algorithm}[htb]\n    \\caption{Converting from $lat, lon$ grid to polar plane grid in 3 dimensions}\n    \\label{alg:beam up 3d}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Latitude coordinates $lat$, Longitude coordinates $lon$, Values of the $lat, lon$ grid $data$, Length of one axis of the polar grid? $gridSize$, Latitude coordinates on the polar grid \n        $gridLatCoords$, Longitude coordinates on the polar grid $gridLonCoords$}\n    \\Output{Triple array representing the values of the $lat, lon, layer$ grid on the polar grid}\n    \\SetKwComment{Comment}{//}{}\n    $polarPlane \\leftarrow $ 3 Dimensional array where the $1^{\\text{st}}$ and $2^{\\text{nd}}$ dimensions have length $gridSize$ and the $3^{\\text{rd}}$ dimension has length $data[0][0].length$ \\;\n    \\For{$k \\leftarrow 0$ \\KwTo $data[0][0].length$}{\n        $f \\leftarrow $ \\texttt{BivariateSpline}($lat, lon, data[:, :, k]$) \\Comment*[l]{Do the interpolation on this layer}\n        $polarPlane[:, :, k] \\leftarrow f(gridLatCoords, gridLonCoords).$\\texttt{reshape}(($gridSize$, $gridSize$)) \\Comment*[l]{Check the values of the interpolation at the specified \n        coordinates and force them to align to the polar grid}\n    }\n    \\Return{$polarPlane$}\n\\end{algorithm}\n\nHaving dealt with converting to the polar grid, we now also need to deal with converting from the polar grid. In contrast to converting to the polar griod, this is only done in 3 dimensions so \nwe do not need a 2 dimensional algorithm. How we convert from the polar grid can be found in \\autoref{alg:beam down}.\n\n\\begin{algorithm}[htb]\n    \\caption{Converting from the polar plane grid to the $lat, lon$ grid in 3 dimensions}\n    \\label{alg:beam down}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Longitude coordinates $lon$, Values of the $lat, lon$ grid $data$, Polar $x$ value indices $gridXValues$, Polar $y$ value indices $gridYValues$, Polar $x$ coordinates $polarXCoords$, \n        Polar $y$ coordinates $polarYCoords$}\n    \\Output{Triple array representing the values of the polar grid on the $lat, lon, layer$ grid}\n    \\SetKwComment{Comment}{//}{}\n    $resample \\leftarrow $3 Dimensional array where the $1^{\\text{st}}$ dimension has length $\\lfloor \\frac{polarXCoords}{lon.length} \\rfloor$, the $2^{\\text{nd}}$ dimension has length \n    $lon.length$ and the $3^{\\text{rd}}$ dimension has length $data[0][0].length$ \\;\n    \\For{$k \\leftarrow 0$ \\KwTo $data[0][0].length$}{\n        $f \\leftarrow $ \\texttt{BivariateSpline})($gridXValues, gridYValues, data[:, :, k]$) \\Comment*[l]{Do the interpolation on this layer}\n        $resample[:, :, k] \\leftarrow f(polarXCoords, polarYCoords).$\\texttt{reshape}(($\\lfloor \\frac{polarXCoords}{lon.length} \\rfloor, lon.length$)) \\Comment*[l]{Check the values of the \n        interpolation at the specified coordinates and force them to align to the polar grid}\n    }\n    \\Return{$resample$}\n\\end{algorithm}\n\n\\subsection{Creating the Other Required Vectors and Matrices (Planes)}\nSo now that we have the grids, we need some more vectors and matrices. We need the coriolis plane (the coriolis force on the polar plane) and the velocity vectors. We need these in order for the \nvelocity calculations to go correctly. We also need these at this level and not locally as both velocity and advection need the velocity vectors and it is easier to adjust the coriolis plane for \ndifferent planets on the highest level than when it is embedded into the calculation algorithms. How we create the plane and the velocity vectors is shown in \\autoref{alg:polar grid coriolis}.\n\n\\begin{algorithm}[htb]\n    \\caption{Generating the coriolis planes and the velocity vectors}\n    \\label{alg:polar grid coriolis}\n    $data \\leftarrow $ matrix with dimensions $nlat - poleLowIndexN + gridPad \\times nlon$ \\;\n    \\For{$i \\leftarrow poleLowIndexN - gridPad$ \\KwTo $nlat - 1$}{\n        $data[i - poleLowIndexN, :] \\leftarrow coriolis[i]$ \\;\n    }\n    $coriolisPlaneN \\leftarrow $ \\texttt{BeamMeUp2D}$(lat[(poleLowIndexN - gridPad):], lon, data, gridSideLength, gridLatCoordsN, gridLonCoordsN)$ \\;\n\n    $data \\leftarrow $ matrix with dimensions $poleLowIndexS + gridPad \\times nlon$ \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndexS + gridPad - 1$}{\n        $data[i, :] \\leftarrow coriolis[i]$ \\;\n    }\n    $coriolisPlaneS \\leftarrow $ \\texttt{BeamMeUp2D}$(lat[:(poleLowIndexS + gridPad)], lon, data, gridSideLength, gridLatCoordsS, gridLonCoordsS)$ \\;\n\\end{algorithm}\n\n\\subsection{Gradually Changing Grids}\nNow that we can convert between grids we also need a way to do so gradually. Otherwise we would move the hard border we had previously around the poles further down the $lat, lon$ grid. Instead \nwe have to do some interpolation between the two grids in order to ensure a smooth transition in the final output, so that there are no hard borders. This interpolation is done in \n\\autoref{alg:polar interpolation}, using the linear interpolation technique as discussed in \\autoref{sec:interpolation}.\n\n\\begin{algorithm}[htb]\n    \\caption{Gradually transition from the $lat, lon$ grid to the polar grid}\n    \\label{alg:polar interpolation}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Index when to start using the polar grid $poleLowIndex$, Index when to only use the polar grid $poleHighIndex$, Polar data $polarData$, $lat, lon$ data $sphericalData$}\n    \\Output{3 Dimensional array representing the values on the polar grid with the part that gradually transitions to the $lat, lon$ grid}\n    \\SetKwComment{Comment}{//}{}\n    $output \\leftarrow$ 3 Dimensional array with the exact same structure as $polarData$ \\;\n    $overlap \\leftarrow $ $|poleLowIndex - poleHighIndex|$ \\;\n    \n    \\BlankLine\n    \\uIf(\\Comment*[h]{Determine whether we are talking about the north or south pole}){$lat[poleLowIndex] < 0$}{\n        \\DontPrintSemicolon\n        \\Comment*[l]{South pole}\n        \\PrintSemicolon\n        \\For{$k \\leftarrow 0$ \\KwTo $output[0][0].length$}{\n            \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndex$}{\n                \\uIf{$i < poleHighIndex$}{\n                    $\\lambda \\leftarrow 0$ \\;\n                } \\uElse{\n                    $\\lambda \\leftarrow \\frac{i - poleHighIndex}{overlap}$ \\;\n                }\n                $output[i, :, k] \\leftarrow (1 - \\lambda) sphericalData[i, :, k] + \\lambda polarData[i, :, k]$ \\;\n            }\n        }\n    } \\uElse{\n        \\DontPrintSemicolon\n        \\Comment*[l]{North pole}\n        \\PrintSemicolon\n        \\For{$k \\leftarrow 0$ \\KwTo $output[0][0].length$}{\n            \\For{$i \\leftarrow 0$ \\KwTo $nlat - poleLowIndex$}{\n                \\uIf{$i + poleLowIndex + 1 > poleHighIndex$}{\n                    $\\lambda \\leftarrow 0$ \\;\n                } \\uElse{\n                    $\\lambda \\leftarrow \\frac{i}{overlap}$ \\;\n                }\n                $output[i, :, k] \\leftarrow (1 - \\lambda) sphericalData[i, :, k] + \\lambda polarData[i, :, k]$ \\;\n            }\n        }\n    }\n\n    \\BlankLine\n    \\Return{$output$}\n\\end{algorithm}\n\n\\subsection{Gradients on the Grid}\nWith our new found ability to convert to and from the polar grid, while also gradually transitioning, we now get to the part we are doing it all for. Calculations on the polar grid. In order for\nthat to work, we need some utility functions specifically for the polar grid first. We will need gradients in all 3 dimensions, those being the $x$ dimension, the $y$ dimension and the $p$ \ndimension (pressure). All of the gradients will be quite similar to \\autoref{alg:gradient x}, \\autoref{alg:gradient y} and \\autoref{alg:gradient z} though some small tweaks are required as we \nare not differentiating over a spehere but over a plane. These changes are reflected in \\autoref{alg:polar gradient x}, \\autoref{alg:polar gradient y} and \\autoref{alg:polar gradient p}.\n\n\\begin{algorithm}[htb]\n    \\caption{Gradient in the $x$ dimension on the polar grid}\n    \\label{alg:polar gradient x}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, first index $i$, second index $j$ and third index $k$, resolution of the polar grid $polarGridResolution$}\n    \\Output{Gradient in the $x$ dimension for the value of the grid point at the specified coordinates}\n    \\uIf{$i = 0$}{\n        $value \\leftarrow \\frac{data[i, j + 1, k] - data[i, j, k]}{polarGridResolution}$ \\;\n    } \\uElseIf{$j = gridSideLength - 1$}{\n        $value \\leftarrow \\frac{data[i, j, k] - data[i, j - 1, k]}{polarGridResolution}$ \\;\n    } \\uElse{\n        $vale \\leftarrow \\frac{data[i, j + 1, k] - data[i, j - 1, k]}{2 polarGridResolution}$ \\; \n    }\n    \\Return{$value$}\n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n    \\caption{Gradient in the $y$ dimension on the polar grid}\n    \\label{alg:polar gradient y}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, first index $i$, second index $j$ and third index $k$, resolution of the polar grid $polarGridResolution$}\n    \\Output{Gradient in the $y$ dimension for the value of the grid point at the specified coordinates}\n    \\uIf{$i = 0$}{\n        $value \\leftarrow \\frac{data[i + 1, j, k] - data[i, j, k]}{polarGridResolution}$ \\;\n    } \\uElseIf{$i = gridSideLength - 1$}{\n        $value \\leftarrow \\frac{data[i, j, k] - data[i - 1, j, k]}{polarGridResolution}$ \\;\n    } \\uElse{\n        $vale \\leftarrow \\frac{data[i + 1, j, k] - data[i - 1, j, k]}{2 polarGridResolution}$ \\; \n    }\n    \\Return{$value$}\n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n    \\caption{Gradient in the $p$ dimension on the polar grid}\n    \\label{alg:polar gradient p}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, first index $i$, second index $j$ and third index $k$, pressure levels $pressureLevels$}\n    \\Output{Gradient in the $p$ dimension for the value of the grid point at the specified coordinates}\n    \\uIf{$i = 0$}{\n        $value \\leftarrow \\frac{data[i, j, k + 1] - data[i, j, k]}{pressureLevels[k + 1] - pressureLevels[k]}$ \\;\n    } \\uElseIf{$k = nlevels - 1$}{\n        $value \\leftarrow \\frac{data[i, j, k] - data[i, j, k - 1]}{pressureLevels[k] - pressureLevels[k - 1]}$ \\;\n    } \\uElse{\n        $vale \\leftarrow \\frac{data[i, j, k + 1] - data[i, j, k - 1]}{pressureLevels[k + 1] - pressureLevels[k - 1]}$ \\; \n    }\n    \\Return{$value$}\n\\end{algorithm}\n\nNow that we have seen the normal versions, let us vectorise them for optimal performance. The vectorised versions do exactly the same, however instead of returning a single value (and the method\nneeding to be called for each and every element) we return a matrix of gradients. By using a matrix, we can apply the gradient to multiple elements at once and efficiently. The vectorised \nversions can be found in \\autoref{alg:polar gradient x vectorised}, \\autoref{alg:polar gradient y vectorised} and \\autoref{alg:polar gradient p vectorised} respectively.\n\n\\begin{algorithm}[htb]\n    \\caption{Gradient in the $x$ dimension on the polar grid}\n    \\label{alg:polar gradient x vectorised}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, resolution of the polar grid $polarGridResolution$}\n    \\Output{Triple array containing the gradients for each cell on the polar grid}\n    $shiftEast \\leftarrow $ shift all $x$ coordinates in $data$ one cell to the east (positive $x$) \\;\n    $shiftWest \\leftarrow $ shift all $x$ coordinates in $data$ one cell to the west (negative $x$) \\;\n    \\Return{$\\frac{shiftWest - shiftEast}{2 polarGridResolution}$}\n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n    \\caption{Gradient in the $y$ dimension on the polar grid}\n    \\label{alg:polar gradient y vectorised}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, resolution of the polar grid $polarGridResolution$}\n    \\Output{Triple array containing the gradients for each cell on the polar grid}\n    $shiftSouth \\leftarrow $ shift all $y$ coordinates in $data$ one cell to the south (negative $y$) \\;\n    $shiftNorth \\leftarrow $ shift all $y$ coordinates in $data$ one cell to the north (positive $y$) \\;\n    \\Return{$\\frac{shiftNorth - shiftSouth}{2 polarGridResolution}$}\n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n    \\caption{Gradient in the $p$ dimension on the polar grid}\n    \\label{alg:polar gradient p vectorised}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, pressure levels $pressureLevels$}\n    \\Output{Triple array containing the gradients for each cell on the polar grid}\n    $shiftUp\\leftarrow $ shift all $p$ coordinates in $data$ one cell upwards (positive $p$) \\;\n    $shiftDown \\leftarrow $ shift all $p$ coordinates in $data$ one cell downwards (negative $p$) \\;\n    $shiftPressureUp \\leftarrow$ shift the pressure in $pressureLevels$ up by one cell \\;\n    $shiftPressureDown \\leftarrow$ shift the pressure in $pressureLevels$ down by one cell \\;\n    \\Return{$\\frac{shiftDown - shiftUp}{shiftPressureDown - shiftPressureUp}$}\n\\end{algorithm}\n\n\\subsection{Calculating Velocities on the Polar Grid}\nWith all the utility functions out of the way, we now come to the physics of it. Let us start with the velocity calculations on the polar grid. These work very similarly to the ones on the lat, \nlon grid, though not exactly. For the explanation of the equations, please refer to \\autoref{sec:velocity}. The algorithm is given (in its non-vectorised form) in \n\\autoref{alg:polar velocity}. An important thing to note is that this algorithm does not calculate the new velocities, but rather what needs to be changed with regards to the velocities. \nThe \\texttt{gridXGradient} refers to \\autoref{alg:polar gradient x} and \\texttt{gridYGradient} refers to \\autoref{alg:polar gradient y}.\n\n\\begin{algorithm}[htb]\n    \\caption{Velocity calculations on the polar plane}\n    \\label{alg:polar velocity}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Polar plane $polarPlane$, Length of one axis of the grid $polarGridLength$, Coriolis force on the plane (with the same size and resolution as the $polarPlane$) $coriolisPlane$, \n            East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Resolution of the polar grid $polarGridResolution$}\n    \\Output{Additions to the east-west velocity vector on the polar plane $\\dot{x}_{add}$, Additions to the north-south velocity vector on the polar plane $\\dot{y}_{add}$}\n    \\For{$i \\leftarrow 0$ \\KwTo $polarGridLength$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $polarGridLength$}{\n            \\For{$k \\leftarrow 0$ \\KwTo $polarPlane[0, 0].length$}{\n                \\uIf{$k \\geq 17$}{\n                    $\\dot{x}_{add}[i, j, k] \\leftarrow - \\dot{x}[i, j, k] \\texttt{gridXGradient}(\\dot{x}, i, j, k) - \\dot{y}[i, j, k] \\texttt{gridYGradient}(\\dot{x}, i, j, k) +$ \n                    $coriolisPlane[i, j] \\dot{y}[i, j, k] - \\texttt{gridXGradient}(polarPlane, i, j, k) - \\dot{x}[i, j, k] \\cdot 10^{-5}$ \\;\n                    $\\dot{y}_{add}[i, j, k] \\leftarrow - \\dot{x}[i, j, k] \\texttt{gridXGradient}(\\dot{y}, i, j, k) - \\dot{y}[i, j, k] \\texttt{gridYGradient}(\\dot{y}, i, j, k) -$ \n                    $coriolisPlane[i, j] \\dot{x}[i, j, k] - \\texttt{gridXGradient}(polarPlane, i, j, k) - \\dot{y}[i, j, k] \\cdot 10^{-5}$ \\;\n                } \\uElse{\n                    $\\dot{x}_{add}[i, j, k] \\leftarrow - \\dot{x}[i, j, k] \\texttt{gridXGradient}(\\dot{x}, i, j, k) - \\dot{y}[i, j, k] \\texttt{gridYGradient}(\\dot{x}, i, j, k) -$\n                    $\\dot{x}[i, j, k] \\cdot 10^{-3}$ \\; \n                    $\\dot{y}_{add}[i, j, k] \\leftarrow - \\dot{x}[i, j, k] \\texttt{gridXGradient}(\\dot{y}, i, j, k) - \\dot{y}[i, j, k] \\texttt{gridYGradient}(\\dot{y}, i, j, k) -$\n                    $\\dot{y}[i, j, k] \\cdot 10^{-3}$ \\; \n                }\n                \n            }\n        }\n    }\n\n    \\Return{$\\dot{x}_{add}, \\dot{y}_{add}$}  \n\\end{algorithm}\n\nOne velocity calculation is still missing. That one being the vertical velocity, which is described in \\autoref{alg:polar velocity vert}.\n\n\\begin{algorithm}[htb]\n    \\caption{Vertical velocity calculations for the polar plane}\n    \\label{alg:polar velocity vert}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Pressure levels $pressureLevels$, Temperature on the polar plane \n            $temp$, Resolution of the polar grid $polarGridResolution$}\n    \\Output{Vertical velocity on the polar plane}\n    $output \\leftarrow$ array like $\\dot{x}$ \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $output.length$}{\n\t\t\\For{$j \\leftarrow 0$ \\KwTo $output[i].length$}{\n\t\t\t\\For{$k \\leftarrow 0$ \\KwTo $output[i, j].length$}{\n                $output[i,j,k] = - \\frac{(pressureLevels[k] - pressureLevels[k-1]) * pressureLevels[k] * g * (\\texttt{gridXGradient}(\\dot{x}, i, j, k) + \\texttt{gridYGradient}(\\dot{y}, i, j, k))}\n                    {287 * temp[i, j, k]}$ \\;\n            }\n        }\n    }\n    \\Return{$output$}\n\\end{algorithm}\n\nNow it is time to optimise (and thus vectorise)! The new versions of the algorithms can be found in \\autoref{alg:polar velocity vectorised} and \\autoref{alg:polar velocity vert vectorised}. \nHere, \\texttt{gridXGradient} refers to \\autoref{alg:polar gradient x vectorised} and \\texttt{gridYGradient} refers to \\autoref{alg:polar gradient y vectorised}.\n\n\\begin{algorithm}[htb]\n    \\caption{Velocity calculations on the polar plane}\n    \\label{alg:polar velocity vectorised}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Polar plane $polarPlane$, Length of one axis of the grid $polarGridLength$, Coriolis force on the plane (with the same size and resolution as the $polarPlane$) $coriolisPlane$, \n            East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Resolution of the polar grid $polarGridResolution$}\n    \\Output{Additions to the east-west velocity vector on the polar plane $\\dot{x}_{add}$, Additions to the north-south velocity vector on the polar plane $\\dot{y}_{add}$}\n    $\\dot{x}_{add} \\leftarrow - \\dot{x} \\texttt{gridXGradient}(\\dot{x}, polarGridResolution) - \\dot{y} \\texttt{gridYGradient}(\\dot{x}, polarGridResolution) + coriolisPlane[:, :, None] \\dot{y} -$ \n        $\\texttt{gridXGradient}(polarPlane, polarGridResolution) - \\dot{x} \\cdot 10^{-5}$ \\;\n    $\\dot{y}_{add} \\leftarrow - \\dot{x} \\texttt{gridXGradient}(\\dot{y}, polarGridResolution) - \\dot{y} \\texttt{gridYGradient}(\\dot{y}, polarGridResolution) - coriolisPlane[:, :, None] \\dot{x} -$ \n        $\\texttt{gridXGradient}(polarPlane, polarGridResolution) - \\dot{y} \\cdot 10^{-5}$ \\;\n\n    $\\dot{x}_{add}[:,:,17:] \\leftarrow - \\dot{x}[:,:,17:] \\texttt{gridXGradient}(\\dot{x}, polarGridResolution) - \\dot{y}[:,:,17:] \\texttt{gridYGradient}(\\dot{x}, polarGridResolution) - $ \n        $\\dot{x}[:,:,17:] \\cdot 10^{-3}$ \\; \n    $\\dot{y}_{add}[:,:,17:] \\leftarrow - \\dot{x}[:,:,17:] \\texttt{gridXGradient}(\\dot{y}, polarGridResolution) - \\dot{y}[:,:,17:] \\texttt{gridYGradient}(\\dot{y}, polarGridResolution) -$\n        $\\dot{y}[:,:,17:] \\cdot 10^{-3}$ \\; \n\n\n    \\Return{$\\dot{x}_{add}, \\dot{y}_{add}$}  \n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n    \\caption{Vertical velocity calculations for the polar plane}\n    \\label{alg:polar velocity vert vectorised}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Pressure levels $pressureLevels$, Temperature on the polar plane \n            $temp$, Resolution of the polar grid $polarGridResolution$}\n    \\Output{Vertical velocity on the polar plane}\n    $shiftUp \\leftarrow$ shift all cells in pressureLevels up by one cell (wrap around if needed) \\;\n    \\Return{$-\\frac{(pressureLevels - shiftUp) * pressureLevels * g * (\\texttt{gridXGradient}(\\dot{x}, polarGridResolution) + \\texttt{gridYGradient}(\\dot{y}, polarGridResolution))}{287 * temp}$}\n\\end{algorithm}\n\n\\subsection{Projecting the Velocities}\nNow that we have methods that can calculate the velocities on the polar plane and on the normal grid, we now need to combine methods to convert from the polar plane to the normal grid and vice \nversa. Due to the polar grid having different axes than the normal grid, we cannot simply project them down and be done with it. We actually need to correct for the differences in axes. After \nprojecting the polar plane velocity vectors down as is, we correct for the mismatch in axes by converting everything back to the lat, lon grid. As that grid uses spherical coordinates, we know \nthat each pointon that grid is uniquely identified by a combination of the $\\sin$ and $\\cos$ functions. This fact we use in realigning the velocity vectors. The whole process is shown in \n\\autoref{alg:project velocities north} and \\autoref{alg:project velocities south}. \\texttt{BeamMeDown} refers to \\autoref{alg:beam down}. Again, the north and south methods are quite similar. \nApart from a few different variable names the only real difference is reversing the reprojected vector values along the 2nd dimension for the north polar plane. This has to do with the \ndifference in axis alignment between the two polar planes. Now you might be wondering what $[\\texttt{None}, :, \\texttt{None}]$ means when appended to $lon$. It turns the $lon$ 1-dimensional \narray into a 3-dimensional array. It does this by creating small arrays that contain all a single element. So $lon[\\texttt{None}, :, \\texttt{None}]$ will become something like: \n$[[[x], [y], \\dots]]$ where $x$ and $y$ are elements of the original $lon$.\n\n\\begin{algorithm}[htb]\n    \\caption{Projecting velocities from the northern polar plane down to the normal grid}\n    \\label{alg:project velocities north}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Longitude coordinates $lon$, East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Lower limit of northern polar plane \n        $poleLowIndexN$, Polar $x$ value indices $gridXValues$, Polar $y$ value indices $gridYValues$, Polar $x$ coordinates $polarXCoords$, Polar $y$ coordinates $polarYCoords$}\n    \\Output{Reprojected east-west velocity vector on the lat, lon grid $u$, Reprojected north-south velocity vector on the lat, lon grid $v$}\n    $repX \\leftarrow $ \\texttt{BeamMeDown}$(lon, \\dot{x}, poleLowIndexN, gridXValues, gridYValues, polarXCoords, polarYCoords)$ \\;\n    $repY \\leftarrow $ \\texttt{BeamMeDown}$(lon, \\dot{y}, poleLowIndexN, gridXValues, gridYValues, polarXCoords, polarYCoords)$ \\;\n    $u \\leftarrow repX * \\sin(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180}) + repY * \\cos(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180})$ \\;\n    $v \\leftarrow repX * \\cos(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180}) - repY * \\sin(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180})$ \\;\n    $u \\leftarrow $ reverse all values of $u$ along the 2nd dimension \\;\n    $v \\leftarrow $ reverse all values of $v$ along the 2nd dimension \\;\n    \\Return{$u, v$}\n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n    \\caption{Projecting velocities from the southern polar plane down to the normal grid}\n    \\label{alg:project velocities south}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Longitude coordinates $lon$, East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Lower limit of southern polar plane \n        $poleLowIndexS$, Polar $x$ value indices $gridXValues$, Polar $y$ value indices $gridYValues$, Polar $x$ coordinates $polarXCoords$, Polar $y$ coordinates $polarYCoords$}\n    \\Output{Reprojected east-west velocity vector on the lat, lon grid $u$, Reprojected north-south velocity vector on the lat, lon grid $v$}\n    $repX \\leftarrow $ \\texttt{BeamMeDown}$(lon, \\dot{x}, poleLowIndexS, gridXValues, gridYValues, polarXCoords, polarYCoords)$ \\;\n    $repY \\leftarrow $ \\texttt{BeamMeDown}$(lon, \\dot{y}, poleLowIndexS, gridXValues, gridYValues, polarXCoords, polarYCoords)$ \\;\n    $u \\leftarrow repX * \\sin(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180}) + repY * \\cos(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180})$ \\;\n    $v \\leftarrow -repX * \\cos(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180}) + repY * \\sin(lon[\\texttt{None}, :, \\texttt{None}] * \\frac{\\pi}{180})$ \\;\n    \\Return{$u, v$}\n\\end{algorithm}\n\nThe previous algorithms show how to convert from the polar plane to the lat, lon grid. However we also need the other direction. That process is shown in \\autoref{alg:project velocities up}. We \nuse similar information to re-align the velocity vectors to the polar plane grid as we used to re-align the velocity vectors to the lat, lon grid. \\texttt{BeamMeUp} corresponds to the \n\\autoref{alg:beam up 3d}.\n\n\\begin{algorithm}[htb]\n    \\caption{Projecting velocities from the normal grid to the polar plane}\n    \\label{alg:project velocities up}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Latitude coordinates $lat$, Longitude coordinates $lon$, East-west velocity vector $u$, North-south velocity vector $v$, Size of the polar grid $gridSize$, Latitude coordinates \n        corresponding to the polar plane grid $gridLatCoords$, Longitude coordinates correpsonding to the polar plane grid $gridLonCoords$}\n    \\Output{East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar planes $\\dot{y}$}\n    \\SetKwComment{Comment}{//}{}\n    $gridU \\leftarrow $ \\texttt{BeamMeUp}$(lat, lon, u, gridSize, gridLatCoords, gridLonCoords)$ \\;\n    $gridV \\leftarrow $ \\texttt{BeamMeUp}$(lat, lon, v, gridSize, gridLatCoords, gridLonCoords)$ \\;\n\n    $nlevels \\leftarrow u[0, 0].length$ \\Comment*[r]{Does not replace the global, is only of effect here in this method}\n\n    $\\dot{x} \\leftarrow$ matrix with shape $gridSize \\times gridSize \\times nlevels$ \\;\n    $\\dot{y} \\leftarrow$ matrix with shape $gridSize \\times gridSize \\times nlevels$ \\;\n\n    $gridLonCoords \\leftarrow gridLonCoords.\\texttt{reshape}(gridSize, gridSize)$ \\;\n\n    \\uIf(//Check to see with which pole we are dealing){$lat[0] < 0$}{\n        \\For{$k \\leftarrow 0$ \\KwTo $nlevels - 1$}{\n            $\\dot{x}[:, :, k] \\leftarrow gridU[:, :, k] * \\sin(gridLonCoords * \\frac{\\pi}{180}) - gridV[:, :, k] * \\cos(gridLonCoords * \\frac{\\pi}{180})$ \\;\n            $\\dot{y}[:, :, k] \\leftarrow gridU[:, :, k] * \\cos(gridLonCoords * \\frac{\\pi}{180}) + gridV[:, :, k] * \\sin(gridLonCoords * \\frac{\\pi}{180})$ \\;\n        }\n    } \\uElse {\n        \\For{$k \\leftarrow 0$ \\KwTo $nlevels - 1$}{\n            $\\dot{x}[:, :, k] \\leftarrow -gridU[:, :, k] * \\sin(gridLonCoords * \\frac{\\pi}{180}) + gridV[:, :, k] * \\cos(gridLonCoords * \\frac{\\pi}{180})$ \\;\n            $\\dot{y}[:, :, k] \\leftarrow -gridU[:, :, k] * \\cos(gridLonCoords * \\frac{\\pi}{180}) - gridV[:, :, k] * \\sin(gridLonCoords * \\frac{\\pi}{180})$ \\;\n        }\n    }\n    \\Return{$\\dot{x}, \\dot{y}$}\n\\end{algorithm}\n\n\\subsection{Advection on the Polar Planes}\nLike we have done with the velocities, we also need to make a calculation for the advection on the polar planes themselves. We do this in \\autoref{alg:polar advection}. For more details about \nadvection itself, please refer to \\autoref{sec:adv}. The interesting bit of magic happens with the $\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|$ term. If $\\dot{y}[i, j, :]$ is negative, then this \nwhole term will be $0$ and hence will not be considered, whereas if it is positive it will be considered (that's also why we divide by $2 * polarGridResolution$, to correct for adding \n$\\dot{y}[i, j, :]$ twice). Doing it this way saves an if statement and allows everything to be calculated faster along the last dimension. We have also added specific assignments for $j = 0$ and \nfor $j = \\dot{x}[i].length$ as these indicate the boundaries of the $\\dot{x}$ vector and saves us 2 more if statements.\n\n\\begin{algorithm}[htb]\n    \\caption{Performing the advection calculations on the polar plane}\n    \\label{alg:polar advection}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Data matrix $data$, East-west velocity vector on the polar plane $\\dot{x}$, North-south velocity vector on the polar plane $\\dot{y}$, Resolution of the polar grid $polarGridResolution$}\n    \\Output{3-dimensional matrix with the advection data on the polar plane $adv$}\n    $adv \\leftarrow $ matrix with the same size as $data$ \\;\n    \\For{$i \\leftarrow 1$ \\KwTo $\\dot{x}.length - 1$}{\n        $j \\leftarrow 0$ \\;\n        $adv[i, j, :] \\leftarrow adv + \\frac{(\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|) * (data[i, j, :] - data[i - 1, j, :])}{2 * polarGridResolution} +$ \n        $\\frac{(\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|) * (data[i + 1, j, :] - data[i, j, :])}{2 * polarGridResolution}$ \\;\n        $adv[i, j, :] \\leftarrow adv + \\frac{(\\dot{x}[i, j, :] + |\\dot{x}[i, j, :]|) * (data[i, j + 1, :] - data[i, j, :])}{2 * polarGridResolution}$ \\;\n\n        \\For{$j \\leftarrow 1$ \\KwTo $\\dot{x}[i].length - 1$}{\n            $adv[i, j, :] \\leftarrow adv + \\frac{(\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|) * (data[i, j, :] - data[i - 1, j, :])}{2 * polarGridResolution} +$ \n            $\\frac{(\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|) * (data[i + 1, j, :] - data[i, j, :])}{2 * polarGridResolution}$ \\;\n            $adv[i, j, :] \\leftarrow adv + \\frac{(\\dot{x}[i, j, :] + |\\dot{x}[i, j, :]|) * (data[i, j, :] - data[i, j - 1, :])}{2 * polarGridResolution} + $\n            $\\frac{(\\dot{x}[i, j, :] + |\\dot{x}[i, j, :]|) * (data[i, j + 1, :] - data[i, j, :])}{2 * polarGridResolution}$ \\;\n        }\n\n        $j \\leftarrow \\dot{x}[i].length - 1$ \\;\n        $adv[i, j, :] \\leftarrow adv + \\frac{(\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|) * (data[i, j, :] - data[i - 1, j, :])}{2 * polarGridResolution} +$ \n        $\\frac{(\\dot{y}[i, j, :] + |\\dot{y}[i, j, :]|) * (data[i + 1, j, :] - data[i, j, :])}{2 * polarGridResolution}$ \\;\n        $adv[i, j, :] \\leftarrow adv + \\frac{(\\dot{x}[i, j, :] + |\\dot{x}[i, j, :]|) * (data[i, j, :] - data[i, j - 1, :])}{2 * polarGridResolution}$ \\;\n    }\n    \\Return{$adv$}\n\\end{algorithm}", "meta": {"hexsha": "a55363222027fba5437c985cb831d9f9098aa08a", "size": 44721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/topics/planar.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/planar.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/planar.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": 69.985915493, "max_line_length": 196, "alphanum_fraction": 0.6782048702, "num_tokens": 13198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.6613056983396476}}
{"text": "\\section{Canonical Quantization}\n\nClassical $Q$ configuration space.\n$q_i$, for $i=1,\\ldots,N$\n$p_i$, for $i=1,\\ldots,N$\nPoisson brackets\n$\\left\\{ q_i, p_i \\right\\}=1$\n\nQuantum $\\mathcal{H}$ on $Q$.\n$\\hat{q}_i$ and $\\hat{p}_i$.\nCommutator\n$\\left[ \\hat{q}_i, \\hat{p}_i \\right] = i\\hbar \\delta_{ij}$.\n\nHamiltonian is\n\\begin{align}\n    \\hat{H} = \\mathcal{H}\\left( \\hat{q}_i, \\hat{p}_i \\right)\n\\end{align}\n\n\\begin{example}[1D particle]\n    $\\hat{x}\\ket{x} = x\\ket{x}$\n    and\n    \\begin{align}\n        \\ket{\\psi} = \\int_{-\\infty}^{\\infty} dx\\,\n        \\psi(x)\\ket{x}\n    \\end{align}\n    and hte momentum is\n    \\begin{align}\n        \\hat{p}\\ket{x} := i\\hbar \\frac{d}{dx}\\ket{x}\n    \\end{align}\n    with\n    \\begin{align}\n        \\left[ \\hat{x}, \\hat{p} \\right] = i\\hbar\n    \\end{align}\n\\end{example}\n\\begin{proof}\n    For a basis state,\n    \\begin{align}\n        \\left[ \\hat{x}, \\hat{p} \\right]\n        &=\n        \\hat{x} i\\hbar \\frac{d}{dx}\\ket{x}\n        - \\hat{p}\\hat{x}\\ket{x}\\\\\n        &=\n        i\\hbar\n        \\frac{(x + dx)\\ket{x + dx} - x\\ket{x}}{dx}\n        - x i\\hbar \\frac{d}{dx}\\ket{x}\\\\\n        &=\n        i\\hbar\\left(\n            x \\frac{d}{dx} + \\frac{dx}{dx}\\ket{x}\n        \\right)\n        - i\\hbar x \\frac{d}{dx}\\kket{x}\\\\\n        &= i\\hbar \\ket{x}\n    \\end{align}\n    Then more generally\n    \\begin{align}\n        \\left[ \\hat{x}, \\hat{p} \\right] &=\n        \\int_{-\\infty}^{\\infty} dx \\left[ \\hat{x}, \\hat{p} \\right]\n        \\ket{x} \\braket{x}{\\psi}\\\\\n        &= i\\hbar\\ket{\\psi}\n    \\end{align}\n\\end{proof}\n\n\\begin{example}[Particle on a sphere]\n    The Lagrangian is\n    \\begin{align}\n        L &=\n        \\frac{m}{2} R^2\\left(\n            \\theta^2 + \\sin^2\\theta \\phi^2\n        \\right)\n    \\end{align}\n    and the conjugate momenta are\n    \\begin{align}\n        p_\\theta &=\n        \\frac{dL}{d\\theta}\n        = mR^2\\theta\\\\\n        p_\\phi &=\n        \\frac{dL}{d\\phi}\n        = mR^2 \\sin^2\\theta \\phi\n    \\end{align}\n    which gives the Hamiltonian\n    \\begin{align}\n        H &=\n        \\frac{m}{2} R^2\\left(\n            \\frac{p_\\theta^2}{(mR^2)^2}\n            + \\frac{p_\\phi^2}{(mR^2)^2\\sin^2\\theta}\n        \\right)\n    \\end{align}\n    Classically the Poisson bracket is\n    \\begin{align}\n        \\left\\{ \\theta, p_\\theta \\right\\} &=\n        \\left\\{ \\phi, p_\\phi \\right\\}\n        = 1\n    \\end{align}\n    which upon quantisation leads becomes commutation relations\n    \\begin{align}\n        \\left[ \\hat{\\theta}, \\hat{p}_\\theta \\right] =\n        \\left[ \\hat{\\phi}, \\hat{p}_\\phi \\right] =\n        i\\hbar\n    \\end{align}\n    We can then define the position operators acting on basis states with\n    \\begin{align}\n        \\hat{\\theta}\\ket{\\theta,\\phi} &= \n        \\theta\\ket{\\theta,\\phi}\\\\\n        \\hat{\\phi}\\ket{\\theta,\\phi} &= \n        \\phi\\ket{\\theta,\\phi}\n    \\end{align}\n    and the momentum operators\n    \\begin{align}\n        \\hat{p}_\\theta\\ket{\\theta,\\phi}\n        &=\n        i\\hbar \\frac{\\partial}{\\partial\\theta}\\ket{\\theta,\\phi}\\\\\n        \\hat{p}_\\phi\\ket{\\theta,\\phi}\n        &=\n        i\\hbar \\frac{\\partial}{\\partial\\phi}\\ket{\\theta,\\phi}\n    \\end{align}\n    A arbitrary state can be written as a superposition\n    \\begin{align}\n        \\ket{\\psi} &=\n        \\underbrace{\n            \\int_{0}^{2\\pi} d\\theta\\sin\\theta\n            \\int_0^{\\pi d\\phi}\n        }_{\\displaystyle\\int_{\\textrm{sphere}} d\\Omega}\n        \\psi(\\theta,\\phi) \\ket{\\theta,\\phi}\n    \\end{align}\n    However, the momentum operator does not act like how you think it does.\n    \\begin{align}\n        \\hat{p}_\\theta \\psi(x) &\\ne\n        -i\\hbar \\frac{\\partial}{\\partial\\theta} \\psi(\\theta,\\phi)\n    \\end{align}\n    If you plug the above into the Hamiltonian,\n    you don't get the Laplacian back, so it must be wrong.\n    The correct expression is\n    \\begin{align}\n        \\hat{p}_\\theta \\psi(x) &=\n        \\frac{-i\\hbar}{\\sqrt{\\sin\\theta}}\n        \\frac{\\partial}{\\partial\\theta}\\sqrt{\\sin\\theta}\n    \\end{align}\n    Then you find that\n    \\begin{align}\n        \\bra{\\psi}\\hat{p}\\ket{\\chi}\n        &=\n        \\int_{0}^{2\\pi} d\\theta \\sqrt{\\sin\\theta}\n        \\int_{0}^{\\pi}d\\phi\\,\n        \\psi^*(\\theta,\\phi)\\cdots\n    \\end{align}\n    Then you find that\n    the solutions are spherical harmonics $Y_{l,m}(\\theta,\\phi)$\n    which you can use as basis.\n\\end{example}\n\n\\section{Operator Ording Ambiguities}\nCanonical quantization is not a good algorithm for quantisation,\nbcecause there is ambigiuity in the ordering of the Hamiltonian.\nSuppose you have\n\\begin{align}\n    H &= \\frac{p^2}{2m}\n\\end{align}\nand you quantize it into\n\\begin{align}\n    \\hat{H} &= \\frac{\\hat{p}^2}{2m}\n\\end{align}\nHowever, another Hamiltonian you could have that is classically the same is\n\\begin{align}\n    H &=\n    \\frac{1}{x^{100}}\n    \\frac{p x^{100} p}{2m}\n\\end{align}\nwhich quantizes into\n\\begin{align}\n    \\hat{H} &= \\frac{1}{2m}\n    \\frac{1}{\\hat{x}^{100}}\n    \\hat{p} \\hat{x}^{100} \\hat{p}\n\\end{align}\nwhich is wildly different!\n", "meta": {"hexsha": "3236b23a0c8e6c19dae4892e10e547d6d551ba55", "size": 4907, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture13.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/lecture13.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/lecture13.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.2011494253, "max_line_length": 75, "alphanum_fraction": 0.547381292, "num_tokens": 1745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6612047248497077}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{bm}\n\\usepackage{natbib}\n\\usepackage{hyperref}\n\\usepackage{cleveref}\n\n% Turn off ChkTeX warning about \\( \\) instead of $ $\n% chktex-file 46\n\n\\begin{document}\n\n\\author{Jonas Lippuner}\n\\title{Ethon hydrodynamics notes}\n\n\\maketitle\n\nEthon is a free and open source software framework to test and develop hydrodynamics methods\nwith block-based  adaptive mesh refinement on various parallel computing architectures. It\nis available at \\url{https://github.com/lanl/Ethon} and described in detail in \\cite{lippuner:21}.\nThese notes are distributed together with the Ethon source code and they describe\nthe hydrodynamics physics currently implemented in Ethon.\n\nThroughout these notes, we will use index notation for vectors and derivatives. The vector $\\vec x$\nwill be denoted as $x^i$, where $i$ ranges from 1 to 3. Furthermore, we denote time and spacial\nderivatives as follows.\n\\begin{align}\n  \\frac{\\partial}{\\partial t} = \\partial_t\n  \\qquad \\text{and} \\qquad\n  \\frac{\\partial}{\\partial x_i} = \\partial_i.\n\\end{align}\nNote that we are in flat space-time, hence covariant and contravariant indices are the same.\nRepeated indices are summed over. For example, the gradient of a scalar and divergence of a vector\nfield are written as\n\\begin{align}\n  \\label{eq:examples}\n  \\nabla f = \\partial_i f\n  \\qquad \\text{and} \\qquad\n  \\nabla \\cdot \\vec u = \\partial_i u^i.\n\\end{align}\n\n\\section{Conserved and primitive variables}\n\nWe define the following \\textbf{primitive} variables:\n\\begin{itemize}\n  \\item Fluid density $\\rho$\n  \\item Fluid velocity $u^i$\n  \\item Fluid internal specific energy $e$\n  \\item Fluid stress tensor $P^{ij}$\n\\end{itemize}\nFor now we only consider isotropic stresses and so we write $P^{ij} = p\\delta^{ij}$, where $p$ is\nthe usual fluid pressure and $\\delta^{ij}$ is the Kronecker delta.\n\nThe \\textbf{conserved} variables are the ones that are actually evolved and they are:\n\\begin{itemize}\n  \\item Mass density $\\rho$\n  \\item Momentum density $\\mu^i = \\rho u^i$\n  \\item Total energy density $\\epsilon = \\rho e + \\frac{1}{2}\\rho u_i u^i$\n\\end{itemize}\nNote that the total energy density is the sum of the internal energy density and kinetic energy\ndensity.\n\n\\section{Compressible Euler equations}\n\nWe write the conservation equations for the conserved variables as follows.\n\\begin{align}\n  \\label{eq:mass_cons}\n  \\partial_t \\rho + \\partial_j(\\rho u^j)  & = 0 \\\\\n  \\label{eq:mom_cons}\n  \\partial_t \\mu^i + \\partial_j(\\rho u^i u^j + P^{ij}) & = \\rho g^i \\\\\n  \\label{eq:ener_cons}\n  \\partial_t \\epsilon + \\partial_j(\\epsilon u^j + u_i P^{ij}) & = \\rho u_i g^i,\n\\end{align}\nwhere $g^i$ is the external acceleration due to gravity. Note that we can write the above also in\nterms of the time derivatives of the primitive variables.\nThe mass conservation equation \\labelcref{eq:mass_cons} remains the same. The momentum conservation\nequation \\labelcref{eq:mom_cons} becomes\n\\begin{align}\n  \\label{eq:dtu}\n  & \\partial_t(\\rho u^i)\n  + \\partial_j(\\rho u^i u^j + P^{ij})\n  = \\rho g^i\n  \\nonumber \\\\\n  \\Leftrightarrow\\ \\\n  & u^i\\left(\\partial_t + \\partial_j(\\rho u^j)\\right)\n  + \\rho \\partial_t u^i\n  + \\rho u^j \\partial_j u^i\n  + \\partial^j p \\delta^{ij}\n  = \\rho g^i\n  \\nonumber \\\\\n  \\Leftrightarrow\\ \\\n  & \\partial_t u^i\n  + u^j \\partial_j u^i\n  + \\frac{\\partial^i p}{\\rho}\n  = g^i,\n\\end{align}\nwhere we used \\cref{eq:mass_cons}, $\\mu^i = \\rho u^i$, and $P^{ij} = p\\delta^{ij}$. Finally, for the\nenergy conservation equation \\labelcref{eq:ener_cons} we find\n\\begin{align}\n  & \\partial_t\\left(\\rho e + \\frac{1}{2}\\rho u_i u^i\\right)\n  + \\partial_j\\left(\\rho e u^j + \\frac{1}{2}\\rho u_i u^i u^j + u_i P^{ij}\\right)\n  = \\rho u_i g^i\n  \\nonumber \\\\\n  \\Leftrightarrow\\ \\\n  & e\\partial_t\\rho + \\rho \\partial_t e + \\frac{1}{2}u_i u^i\\partial_t \\rho + \\rho u_i\\partial_t u^i\n  \\nonumber \\\\\n  & {} + e\\partial_j(\\rho u^j) + \\rho u^j \\partial_j e + \\frac{1}{2}u_i u^i \\partial_j(\\rho u^j)\n    + \\rho u^j u_i\\partial_j u^i\n  \\nonumber \\\\\n  & {} + u_i \\partial^i p + p\\partial^i u_i\n  = \\rho u_i g^i\n  \\nonumber \\\\\n  \\Leftrightarrow\\ \\\n  & e\\left(\\partial_t \\rho + \\partial_j(\\rho u^j)\\right)\n  \\nonumber \\\\\n  & {} + \\frac{1}{2}u_i u^i\\left(\\partial_t \\rho + \\partial_j(\\rho u^j)\\right)\n  \\nonumber \\\\\n  & {} + \\rho u_i \\left(\\partial_t u^i + u^j\\partial_j u^i + \\frac{\\partial^i p}{\\rho} - g^i\\right)\n  \\nonumber \\\\\n  & {} + \\rho \\partial_t e + \\rho u^j \\partial_j e + p \\partial^i u_i = 0\n  \\nonumber \\\\\n  \\Leftrightarrow\\ \\\n  & \\partial_t e + u^i\\partial_i e + \\frac{p}{\\rho}\\partial^i u_i = 0,\n\\end{align}\nwhere we used \\cref{eq:mass_cons,eq:dtu}, $\\epsilon = \\rho e + \\frac{1}{2}\\rho u_i u^i$, and\n$P^{ij} = p\\delta^{ij}$.\n\nIf shocks are present, non-conservative methods do not converge to the correct solution, so one must\nuse conservative methods in those cases (which do converge to the correct solution, if they converge\nat all), see \\citet[][\\S 5.3]{toro}.\n\n\\newcommand{\\vc}[1]{\\mathrm{\\bf #1}}\n\nFor notational simplicity, we shall write the conservative form of the compressible Euler equations\n\\labelcref{eq:mass_cons,eq:mom_cons,eq:ener_cons} as follows\n\\begin{align}\n  \\label{eq:euler_vec}\n  \\partial_t \\vc{U} + \\partial_j \\vc{F}^j(\\vc U) = \\vc{S}(\\vc U),\n\\end{align}\nwhere the state vector $\\vc U$, the flux tensor $\\vc F^j(\\vc U)$, and the source term\n$\\vc S(\\vc U)$ are given by\n\\begin{align}\n  \\label{eq:system_vecs}\n  \\vc U =\n    \\begin{bmatrix}\n      \\rho  \\\\\n      \\mu^1 \\\\\n      \\mu^2 \\\\\n      \\mu^3 \\\\\n      \\epsilon\n    \\end{bmatrix}, \\qquad\n  \\vc F^j(\\vc U) =\n    \\begin{bmatrix}\n      \\rho u^j \\\\\n      \\rho u^1 u^j + P^{1j} \\\\\n      \\rho u^2 u^j + P^{2j} \\\\\n      \\rho u^3 u^j + P^{3j} \\\\\n      \\epsilon u^j + u_i P^{ij}\n    \\end{bmatrix}, \\qquad\n  \\vc S(\\vc U) =\n    \\begin{bmatrix}\n      0 \\\\\n      \\rho g^1 \\\\\n      \\rho g^2 \\\\\n      \\rho g^3 \\\\\n      \\rho u_i g^i\n    \\end{bmatrix}.\n\\end{align}\nNote that to evaluate $\\vc F^j(\\vc U)$ we need an additional Equation of State (EOS) that allows us\nto recover the primitive variables from the conservative ones, which are contained in $\\vc U$. Note\nthat all of the above quantities are functions of time and space.\n\n\n\\section{Finite-volume scheme}\n\nTo discretize the non-linear, partial-differential Euler equations \\labelcref{eq:mass_cons,%\neq:mom_cons,eq:ener_cons} we introduce a Cartesian mesh. For simplicity, we initially consider a\nuniform mesh with cells of size $\\Delta x^i$, where the sizes in the three dimensions can vary, in\nprinciple (in practice they are usually the same, though). Furthermore, we consider a cell-centered\nmethod where we have grid points at the centers of the cells and the cell-averaged quantities are\nstored at those grid points. Additionally, we initially restrict ourselves to the case without\nsource terms, i.e.\\ $\\vc S = \\vc 0$ and so we have the system\n\\begin{align}\n  \\label{eq:sys}\n  \\partial_t \\vc U + \\partial_j \\vc F^j(\\vc U) = \\vc 0.\n\\end{align}\n\n\\newcommand{\\dv}{\\,\\mathrm{d}V}\n\\newcommand{\\ds}{\\,\\mathrm{d}S}\n\\newcommand{\\dt}{\\,\\mathrm{d}t}\n\nNow consider a cell with index $\\alpha$ and volume\n\\begin{align}\n  V_\\alpha = \\Delta x^1 \\Delta x^2 \\Delta x^3.\n\\end{align}\nWe define the cell average of the state vector in cell $\\alpha$ as\n\\begin{align}\n  \\label{eq:cell-average}\n  \\bar{\\vc U}_\\alpha(t) = \\frac{1}{V_\\alpha} \\int_{V_\\alpha} \\vc U(x^i,t) \\dv.\n\\end{align}\nSince $\\partial_t \\vc U = -\\partial_j\\vc F^j(\\vc U)$, we have\n\\begin{align}\n  \\vc U(x^i,t_2) = \\vc U(x^i, t_1) - \\int_{t_1}^{t_2} \\partial_j \\vc F^j(\\vc U(x^i,t)) \\dt,\n\\end{align}\nand so\n\\begin{align}\n  \\label{eq:avg-update}\n  \\bar{\\vc U}_\\alpha(t_2) &= \\frac{1}{V_\\alpha}\\int_{V_\\alpha} \\left( \\vc U(x^i,t_1)\n    - \\int_{t_1}^{t^2} \\partial_j \\vc F^j(\\vc U(x^i, t))\\dt \\right)\\dv\n  \\nonumber \\\\\n  &= \\bar{\\vc U}_\\alpha(t_1) - \\frac{1}{V_\\alpha}\\int_{t_1}^{t_2}\\int_{\\partial V_\\alpha}\n    n_j \\vc F^j(\\vc U(x^i, t))\\ds\\dt,\n\\end{align}\nwhere we assumed that the flux $\\vc F$ is well behaved so that we can change the order of\nintegration, and\nwe used the divergence theorem to replace the volume integral of the divergence of $\\vc F$ with the\nsurface integral over the cell $\\alpha$, where $n_j$ is the normal vector of the cell surface. Note\nthat \\cref{eq:avg-update} is exact since we have made no approximations yet.\n\nThe surface integral in \\cref{eq:avg-update} has six components, namely the integral of the flux\nacross the six faces of the cell. For cell $\\alpha$ we define the following quantities\n\\begin{align}\n  \\label{eq:cell-def}\n  x_\\alpha^i &= \\text{cell center location}, \\nonumber \\\\\n  x_{\\alpha,L}^i &= \\text{coordinates of the lower cell faces, and} \\nonumber \\\\\n  x_{\\alpha,U}^i &= \\text{coordinates of the upper cell faces.}\n\\end{align}\nNote that\n\\begin{align}\n  x_{\\alpha,U}^i - x_{\\alpha,L}^i = \\Delta x^i \\qquad \\text{and} \\qquad\n  x_\\alpha^i = \\frac{x_{\\alpha,L}^i + x_{\\alpha,U}^i}{2}.\n\\end{align}\nWe can now write \\cref{eq:avg-update} as\n\\begin{align}\n  \\label{eq:finite-volume}\n  \\bar{\\vc U}_\\alpha(t_2) = \\bar{\\vc U}_\\alpha(t_1) + \\frac{\\Delta t}{\\Delta x^i}\n          \\left(\\bar{\\vc F}^i_{\\alpha,L} - \\bar{\\vc F}^i_{\\alpha,U}\\right),\n\\end{align}\nwhere $\\Delta t$ = $t_2 - t_1$, and $\\bar{\\vc F}^i_{\\alpha,L}$ and\n$\\bar{\\vc F}^i_{\\alpha,U}$ are the average fluxes through the lower and upper faces in the\n$i$-direction. Their exact form is\n\\begin{align}\n  \\label{eq:fluxes}\n  \\bar{\\vc F}^i_{\\alpha,L} = \\frac{\\Delta x^i}{\\Delta t V_\\alpha}\\int_{t_1}^{t_2}\n      \\int_{V_\\alpha} \\vc F^i(\\vc U(x^1, x^2, x^3, t)) \\delta(x^i - x^i_L) \\dv \\dt\n      \\quad \\text{(no sum over $i$)},\n\\end{align}\nwhere the Dirac-Delta function reduces the integral over the cell volume to an integral over the\nlower cell face in direction $i$ with coordinate $x^i_L$. The expression for\n$\\bar{\\vc F}^i_{\\alpha,U}$ is analogous, since we have already taken care of the sign of the\nnormal vector of the lower and upper faces in \\cref{eq:finite-volume}.\n\nObviously, we cannot evaluate \\cref{eq:fluxes} directly, because that would require knowledge of the\nsolution $\\vc U$ at all times and all points in space. One of the core ingredients of a finite\nvolume method is thus to prescribe some numeric approximations for $\\bar{\\vc F}^i_{\\alpha,L}$\nand $\\bar{\\vc F}^i_{\\alpha,U}$ that can be readily evaluated.\n\n\\subsection{Godunov scheme}\n\nThe Godunov scheme is one of the simplest finite volume schemes and it is first-order\naccurate. We compute the fluxes by solving the Riemann Problem between the two cells, i.e.\n\\begin{align}\n\\bar{\\vc{F}}^j_{\\alpha,L} = \\text{RP}(\\bar{\\vc U}_{\\alpha-1}, \\bar{\\vc U}_\\alpha), \\\\\n\\bar{\\vc{F}}^j_{\\alpha,U} = \\text{RP}(\\bar{\\vc U}_\\alpha, \\bar{\\vc U}_{\\alpha+1}),\n\\end{align}\nwhere $\\bar{\\vc U}_{\\alpha-1}$ and $\\bar{\\vc U}_{\\alpha+1}$ are the average states of the cells\nadjacent to cell $\\alpha$ in the lower and upper direction in dimension $j$, respectively,\nand we use RP to denote the solution to the Riemann Problem. We can use use these fluxes in\n\\cref{eq:finite-volume} to update the state in cell $\\alpha$.\n\n\n\\subsection{MUSCL-Hancock scheme}\n\nThe MUSCL-Hancock scheme is a popular finite volume scheme that is second-order accurate in time and\nspace. MUSCL stands for Monotone Upstream-centred Scheme for Conservation Laws. For example, FLASH\nuses MUSCL-Hancock for its dimensionally unsplit hydro solver. See\n\\cite[\\S13.4, \\S14.4, \\S16.5]{toro} for more details.\n\nThe central idea in the MUSCL-Hancock scheme is to replace the constant cell averages by a linearly\nvarying quantity within the cell. Considering only one dimension for a moment, we define the\nconserved quantity $\\vc U_\\alpha(x)$ in the cell $\\alpha$ as\n\\begin{align}\n  \\label{eq:ux}\n  \\vc U_\\alpha(x) = \\bar{\\vc U}_\\alpha + \\frac{x - x_\\alpha}{\\Delta x} \\vc\\Delta_\\alpha\n  \\qquad\\text{for } x\\in [x_{\\alpha,L}, x_{\\alpha,U}],\n\\end{align}\nwhere $\\vc\\Delta_\\alpha$ is a suitably chosen slope vector (of the five conserved quantities)\nof the solution inside the cell (see \\cref{sec:slope} for details on how to construct the slope\nvector).\nThe above is at a fixed time.\nWe now evaluate the above at the lower and upper boundaries\nto get the extrapolated boundary values of $\\vc U$:\n\\begin{align}\n  \\label{eq:extrapolated-boundary-values-1d}\n  \\vc U^L_\\alpha = \\vc U_\\alpha(x_{\\alpha,L}) =\n    \\bar{\\vc U}_\\alpha - \\frac{\\vc\\Delta_\\alpha}{2}\n  \\quad \\text{and} \\quad\n  \\vc U^U_\\alpha = \\vc U_\\alpha(x_{\\alpha,U}) =\n    \\bar{\\vc U}_\\alpha + \\frac{\\vc\\Delta_\\alpha}{2}.\n\\end{align}\nWe now evolve the boundary extrapolated conserved quantities for a half timestep $\\Delta t/2$\naccording to \\cref{eq:finite-volume} by evaluating $\\vc F$ for the boundary extrapolated values\n$\\vc U^L_\\alpha$ and $\\vc U^U_\\alpha$ and using these as the approximate fluxes. Hence\nwe get\n\\begin{align}\n  \\label{eq:half-time-step-1d}\n  \\hat{\\vc U}^L_\\alpha &= \\vc U^L_\\alpha + \\frac{\\Delta t}{2\\Delta x}\n      \\left[\\vc F(\\vc U^L_\\alpha) - \\vc F(\\vc U^U_\\alpha)\\right], \\nonumber \\\\\n  \\hat{\\vc U}^U_\\alpha &= \\vc U^U_\\alpha + \\frac{\\Delta t}{2\\Delta x}\n      \\left[\\vc F(\\vc U^L_\\alpha) - \\vc F(\\vc U^U_\\alpha)\\right],\n\\end{align}\nwhere all the right-hand side terms are evaluated at the current time $t_1$. Finally, to obtain the\nactual approximate fluxes at the cell boundaries, we solve the one-dimensional local Riemann problem\nat the cell boundaries using the evolved boundary extrapolated quantities. A thorough discussion of\nthe Riemann Problem is beyond the scope of these notes. Simply put, the solution to Riemann Problem\nroughly provides the flux across a discontinuity namely a cell face. For more details, see \\cite{toro}.\nThe Riemann Problem\nrequires left and right initial states $\\vc U_L$ and $\\vc U_R$ and produces a similarity solution\n$\\vc U(x/t)$, which we will denote by\n\\begin{align}\n  \\label{eq:RP-notation}\n  \\vc U(x/t) \\equiv \\text{RP}(\\vc U_L, \\vc U_R).\n\\end{align}\nAt the lower cell boundary of cell $\\alpha$, the left initial state for the Riemann problem is\n$\\hat{\\vc U}_{\\alpha-1}^U$ and the right initial state is $\\hat{\\vc U}_\\alpha^L$, where $\\alpha -1$\ndenotes the cell to the left of cell $\\alpha$ in the $x$-direction. The initial states for the\nRiemann Problem at the upper cell boundary of cell $\\alpha$ are analogous. Hence we have\n\\begin{align}\n  \\label{eq:RPs-1d}\n  \\vc U_\\alpha^L(x/t) &= \\text{RP}(\\hat{\\vc U}_{\\alpha-1}^U, \\hat{\\vc U}_\\alpha^L), \\nonumber \\\\\n  \\vc U_\\alpha^U(x/t) &= \\text{RP}(\\hat{\\vc U}_\\alpha^U, \\hat{\\vc U}_{\\alpha+1}^L),\n\\end{align}\nwhere $\\alpha+1$ is the cell to the right of cell $\\alpha$ in the $x$-direction. We now use the\nRiemann similarity solutions evaluated at $x/t = 0$ to get the final approximate fluxes for\n\\cref{eq:finite-volume}, thus we have\n\\begin{align}\n  \\label{eq:fluxes-1d}\n  \\bar{\\vc F}_{\\alpha,L} = \\vc F(\\vc U_\\alpha^L(0)) \\qquad \\text{and} \\qquad\n  \\bar{\\vc F}_{\\alpha,U} = \\vc F(\\vc U_\\alpha^U(0)).\n\\end{align}\nNote that in principle, we could solve the Generalized Riemann Problem where the left and right\nstates are not constant. We could use a linear form similar to \\cref{eq:ux} to describe the left and\nright states for the Riemann Problems at the boundaries. However, the Generalized Riemann Problem is\nexceedingly difficult and not typically employed \\cite[\\S13.4.1]{toro}.\n\nGeneralizing the above to three dimensions is straight forward. We still solve one-dimensional,\npiece-wise constant Riemann Problems at the cell boundaries (now there are six instead of two), but\nfor the time evolution in \\cref{eq:half-time-step-1d} we incorporate the fluxes from all six faces.\nWe now have a different slope vector (see \\cref{sec:slope}) in each dimension and we'll denote the\ncomponent in dimension $i$ by $\\vc \\Delta_\\alpha^i$. We have six boundary extrapolated values,\nnamely\n\\begin{align}\n  \\label{eq:boundary-values-3d}\n  \\vc U_\\alpha^{L,i} = \\bar{\\vc U}_\\alpha - \\frac{\\vc \\Delta_\\alpha^i}{2}\n  \\qquad \\text{and} \\qquad\n  \\vc U_\\alpha^{U,i} = \\bar{\\vc U}_\\alpha + \\frac{\\vc \\Delta_\\alpha^i}{2},\n\\end{align}\nwhich are evolved forward in time by $\\Delta t/2$ to yield\n\\begin{align}\n  \\label{eq:evolved-boundary-values-3d}\n  \\hat{\\vc U}_\\alpha^{[L|U],i} = \\vc U_\\alpha^{[L|U],i} + \\frac{\\Delta t}{2\\Delta x^j}\n      \\left[\\vc F^j(\\vc U_\\alpha^{L,j}) - \\vc F^j(\\vc U_\\alpha^{U,j})\\right].\n\\end{align}\nNow we solve the Riemann Problem at all six faces using one evolved boundary extrapolated value from\nthis cell and one from the adjacent cell, just like in \\cref{eq:RPs-1d}. This yields a similarity\nsolution at each face, which we plug into the flux function $\\vc F$ to get the approximate flux\n$\\bar{\\vc F}^i_{\\alpha,[L|U]}$\nthrough that face. The cell averaged conserved quantity $\\bar{\\vc U}_\\alpha$ is then updated\naccording to \\cref{eq:finite-volume}.\n\n\n\\subsection{Slope construction and limiter methods}\\label{sec:slope}\n\n\\newcommand{\\du}{\\vc\\Delta_\\alpha^\\text{up}}\n\\newcommand{\\dd}{\\vc\\Delta_\\alpha^\\text{down}}\n\\newcommand{\\dc}{\\vc\\Delta_\\alpha^\\text{cent}}\n\\newcommand{\\db}{\\bar{\\vc\\Delta}_\\alpha}\n\nWe will restrict ourselves again to one dimension in this section, since it drastically simplifies\nnotation. The components of the slope vector in the different dimensions are all determined\nindependently from each other, so generalizing this discussion to multiple dimension is trivial.\nWe use $\\alpha+1$ to denote the neighboring cell in the positive direction and $\\alpha-1$ the\nneighbor in the negative direction. We follow \\cite[\\S6]{leveque}. A general form of the slope is\n\\begin{align}\n  \\label{eq:slope_vector}\n  \\vc \\Delta_\\alpha =\n      \\frac{1}{2}(1+\\omega) \\left(\\bar{\\vc U}_{\\alpha} - \\bar{\\vc U}_{\\alpha-1}\\right)\n    + \\frac{1}{2}(1-\\omega) \\left(\\bar{\\vc U}_{\\alpha+1} - \\bar{\\vc U}_{\\alpha}\\right),\n\\end{align}\nwhere $\\omega$ is a free parameter in the interval $[-1,1]$. Three common choices for $\\omega$ are\n\\begin{align}\n  \\label{eq:example_slopes}\n  \\text{Upwind ($\\omega = 1$):} \\quad\n    & \\du = \\bar{\\vc U}_{\\alpha} - \\bar{\\vc U}_{\\alpha-1} &\n    & \\text{(Beam--Warming).}  \\\\\n  \\text{Centered ($\\omega = 0$):} \\quad\n    & \\dc = \\frac{\\bar{\\vc U}_{\\alpha+1} - \\bar{\\vc U}_{\\alpha-1}}{2} &\n    & \\text{(Fromm),}  \\\\\n  \\text{Downwind ($\\omega = -1$):} \\quad\n    & \\dd = \\bar{\\vc U}_{\\alpha+1} - \\bar{\\vc U}_{\\alpha} &\n    & \\text{(Lax--Wendroff),}\n\\end{align}\n\nUsing any of these slopes leads to a second-order method. Unfortunately, with the increased accuracy\nalso come spurious oscillations near discontinuities. To avoid these discontinuities, the slope\ncomputed above needs to be limited in a way that ensures that the total variation of the solution\ndoes not increase. The resulting scheme is said to be total variation diminishing (TVD). Let\n$\\db$ denote the limited slope and define the minmod and maxmod functions as\n\\begin{align}\n  \\label{eq:minmod-maxmod}\n  \\text{minmod}(a,b) = \\left\\{\n    \\begin{array}{ll}\n      0 & \\text{if } ab \\leq 0, \\\\\n      a & \\text{if } |a| \\leq |b| \\text{ and } ab > 0, \\\\\n      b & \\text{if } |b| \\leq |a| \\text{ and } ab > 0.\n    \\end{array}\\right. \\\\[6pt]\n    \\text{maxmod}(a,b) = \\left\\{\n    \\begin{array}{ll}\n      0 & \\text{if } ab \\leq 0, \\\\\n      a & \\text{if } |a| \\geq |b| \\text{ and } ab > 0, \\\\\n      b & \\text{if } |b| \\geq |a| \\text{ and } ab > 0.\n    \\end{array}\\right.\n\\end{align}\n\nSome popular limiters are the following.\n\\begin{align}\n  \\label{eq:slope-limiters}\n  \\text{minbee:}   \\quad & \\db = \\text{minmod}\\left(\\du, \\dd\\right) \\\\[6pt]\n  \\text{superbee:} \\quad & \\db = \\text{maxmod}\\big[\\text{minmod}\\left(\\du, 2\\dd\\right), \\nonumber \\\\\n      & \\hphantom{\\db = \\text{maxmod}\\big[} \\text{minmod}\\left(2\\du,\\dd\\right)\\big] \\\\[6pt]\n  \\text{MC:} \\quad       & \\db = \\left\\{ \\begin{array}{ll}\n    \\phantom{-}0 & \\text{if } \\du\\dd \\leq 0, \\\\\n    \\phantom{-}\\text{min}(2|\\du|, 2|\\dd|, |\\dc|) & \\text{if } \\dc > 0, \\\\\n    -\\text{min}(2|\\du|, 2|\\dd|, |\\dc|) & \\text{if } \\dc < 0.\n  \\end{array} \\right. \\\\[6pt]\n  \\text{van Leer:} \\quad & \\db = \\left\\{ \\begin{array}{ll}\n    0 & \\text{if } \\du\\dd \\leq 0, \\\\\n    \\dfrac{2\\du\\dd}{\\du+\\dd} & \\text{otherwise.}\n  \\end{array} \\right.\n\\end{align}\nNote that the minbee limiter is also called minmod limiter.\n\n\\section{$\\gamma$-Law Equation of State}\n\nLet $\\gamma$ be the adiabatic index (ratio constant-pressure heat capacity to constant-volume heat\ncapacity). The pressure is given by\n\\begin{align}\n  \\label{eq:gamma-Law}\n  P = (\\gamma-1)\\rho e,\n\\end{align}\nwhere $\\rho$ is the mass density and $e$ is the specific internal energy. We have $\\gamma = 5/3$ for\nmonoatomic ideal gases and $\\gamma = 7/5$ for diatomic ideal gases. From the ideal gas law we\nalso have\n\\begin{align}\n  \\label{eq:ideal-gas}\n  PV = Nk_BT \\Rightarrow P = \\frac{N}{V}k_BT = nk_BT = \\frac{\\rho}{m}k_BT,\n\\end{align}\nwhere $V$ is the volume, $N$ is the number of particles, $n = N/V$ is the number density, and $m$ is\nthe mass of a particle. Equating the above gives\n\\begin{align}\n  \\label{eq:gamma-law_e}\n  e = \\frac{1}{\\gamma-1}\\frac{k_BT}{m}.\n\\end{align}\nFor an isentropic (constant entropy, i.e.\\ adiabatic and reversible) process, one can derive\n\\begin{align}\n  \\label{eq:isentropic}\n  P = \\alpha \\rho^\\gamma,\n\\end{align}\nfor some constant $\\gamma$. The sound speed can now be computed as\n\\begin{align}\n  \\label{eq:sound-speed}\n  c_s^2 = \\left.\\frac{dP}{d\\rho}\\right|_S = \\gamma \\alpha \\rho^{\\gamma-1} = \\gamma\\frac{P}{\\rho} =\n  \\gamma(\\gamma-1)e.\n\\end{align}\n\n\\section*{Acknowledgements}\n\nThe development of Ethon was funded by the Laboratory Directed\nResearch and Development program of Los Alamos National Laboratory under\nproject number 20190519ECR. The development used LANL Institutional Computing\nProgram resources. LANL is operated by Triad National Security, LLC, for the\nNational Nuclear Security Administration of the U.S.DOE (Contract No.\\\n89233218CNA000001).\n\n\\bibliographystyle{apj}\n\\bibliography{notes.bib}\n\n\\end{document}\n", "meta": {"hexsha": "8853268741a8e042e9f90653e359979fbcbb526d", "size": 21758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/notes.tex", "max_stars_repo_name": "lanl/Ethon", "max_stars_repo_head_hexsha": "95ea508b51a59c83c154b7f80594b64d71fd0a55", "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/notes.tex", "max_issues_repo_name": "lanl/Ethon", "max_issues_repo_head_hexsha": "95ea508b51a59c83c154b7f80594b64d71fd0a55", "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": "lanl/Ethon", "max_forks_repo_head_hexsha": "95ea508b51a59c83c154b7f80594b64d71fd0a55", "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.4040816327, "max_line_length": 103, "alphanum_fraction": 0.6857247909, "num_tokens": 7239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6612047146097526}}
{"text": "\n\\subsection{Matching}\n\nMatching is similar to regression. We assume that effects are constant, and the effect of treatment on \\(y_{0i}\\) and \\(y_{1i}\\) are independent of treatment, once controlling for \\(X\\).\n\nAgain, this is biased if this is not the case.\n\nWe however do not have to assume a linear form for \\(X\\).\n\nWe assume: \\(E[y_{ji}|\\mathbf x_{i}, D_i]=E[y_{ji}|\\mathbf x_{i}]\\)\n\nFor each entity, find a near entity which had the opposite treatment.\n\n\n", "meta": {"hexsha": "e0d61397c053e633c9fe12d270e23033a3a45a8b", "size": 460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treatmentHomo/04-01-matching.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treatmentHomo/04-01-matching.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treatmentHomo/04-01-matching.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6666666667, "max_line_length": 186, "alphanum_fraction": 0.7130434783, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6612047125073679}}
{"text": "\\subsection{Additionstheoreme}\n\t$\\sin(a \\pm b)=\\sin(a) \\cdot \\cos(b) \\pm \\cos(a) \\cdot \\sin(b)$\\\\\n\t$\\cos(a \\pm b)=\\cos(a) \\cdot \\cos(b) \\mp \\sin(a) \\cdot \\sin(b)$\\\\\t\n\t$\\tan(a \\pm b)=\\dfrac{\\tan(a) \\pm \\tan(b)}{1 \\mp \\tan(a) \\cdot \\tan(b)}$", "meta": {"hexsha": "821ba38225daf81c0ae37f7f1cd4438e8a5cf1c7", "size": 239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "idiotenseite/trigo/subsections/Additionstheoreme.tex", "max_stars_repo_name": "HSR-Stud/ELT-3", "max_stars_repo_head_hexsha": "63028df9fbba7a34fac05f21cca6bfaf9608493a", "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": "idiotenseite/trigo/subsections/Additionstheoreme.tex", "max_issues_repo_name": "HSR-Stud/ELT-3", "max_issues_repo_head_hexsha": "63028df9fbba7a34fac05f21cca6bfaf9608493a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idiotenseite/trigo/subsections/Additionstheoreme.tex", "max_forks_repo_name": "HSR-Stud/ELT-3", "max_forks_repo_head_hexsha": "63028df9fbba7a34fac05f21cca6bfaf9608493a", "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.75, "max_line_length": 73, "alphanum_fraction": 0.5439330544, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542817548989, "lm_q2_score": 0.6893056167854461, "lm_q1q2_score": 0.6611504337774622}}
{"text": "\\chapter{Eigen-things}\nThis chapter will develop the theory of eigenvalues and eigenvectors,\nthe so-called ``Jordan canonical form''.\n(Later on we will use it to\ndefine the characteristic polynomial.)\n\n\\section{Why you should care}\nWe know that a square matrix $T$ is really just\na linear map from $V$ to $V$.\nWhat's the simplest type of linear map?\nIt would just be multiplication by some scalar $\\lambda$,\nwhich would have associated matrix (in any basis!)\n\\[\n\tT =\n\t\\begin{bmatrix}\n\t\t\\lambda & 0 & \\dots & 0 \\\\\n\t\t0 & \\lambda & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t0 & 0 & \\dots & \\lambda\n\t\\end{bmatrix}.\n\\]\nThat's perhaps \\emph{too} simple, though.\nIf we had a fixed basis $e_1, \\dots, e_n$\nthen another very ``simple'' operation\nwould just be scaling each basis element $e_i$ by $\\lambda_i$,\ni.e.\\ a \\vocab{diagonal matrix} of the form\n\\[\n\tT = \\begin{bmatrix}\n\t\t\\lambda_1 & 0 & \\dots & 0 \\\\\n\t\t0 & \\lambda_2 & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t0 & 0 & \\dots & \\lambda_n\n\t\\end{bmatrix}.\n\\]\nThese maps are more general.\nIndeed, you can, for example, compute $T^{100}$ in a heartbeat:\nthe map sends $e_1 \\to \\lambda_1^{100} e_1$.\n(Try doing that with an arbitrary $n \\times n$ matrix.)\n\nOf course, most linear maps are probably not that nice.\nOr are they?\n\\begin{example}\n\t[Getting lucky]\n\tLet $V$ be some two-dimensional vector space\n\twith $e_1$ and $e_2$ as basis elements.\n\tLet's consider a map $T \\colon V \\to V$\n\tby $e_1 \\mapsto 2e_1$ and $e_2 \\mapsto e_1+3e_2$,\n\twhich you can even write concretely as\n\t\\[ T = \\begin{bmatrix}\n\t\t2 & 1 \\\\\n\t\t0 & 3\n\t\\end{bmatrix} \\quad\\text{in basis $e_1$, $e_2$}. \\]\n\tThis doesn't look anywhere as nice until we realize we can rewrite it as\n\t\\begin{align*}\n\t\te_1 &\\mapsto 2e_1 \\\\\n\t\te_1+e_2 &\\mapsto 3(e_1+e_2).\n\t\\end{align*}\n\tSo suppose we change to the basis $e_1$ and $e_1 + e_2$.\n\tThus in the new basis,\n\t\\[ T = \\begin{bmatrix}\n\t\t2 & 0 \\\\\n\t\t0 & 3\n\t\\end{bmatrix} \\quad\\text{in basis $e_1$, $e_1+e_2$}. \\]\n\tSo our completely random-looking map,\n\tunder a suitable change of basis,\n\tlooks like the very nice maps we described before!\n\\end{example}\nIn this chapter, we will be \\emph{making} our luck,\nand we will see that our better understanding of matrices\ngives us the right way to think about this.\n\n\\section{Warning on assumptions}\nMost theorems in this chapter only work for\n\\begin{itemize}\n\t\\ii finite-dimensional vector spaces $V$,\n\t\\ii over a field $k$ which is \\emph{algebraically closed}.\n\\end{itemize}\nOn the other hand, the definitions work fine without\nthese assumptions.\n\n\\section{Eigenvectors and eigenvalues}\nLet $k$ be a field and $V$ a vector space over it.\nIn the above example, we saw that there were two very nice\nvectors, $e_1$ and $e_1+e_2$, for which $V$ did something very simple.\nNaturally, these vectors have a name.\n\\begin{definition}\n\tLet $T \\colon V \\to V$ and $v \\in V$ a \\emph{nonzero} vector.\n\tWe say that $v$ is an \\vocab{eigenvector} if $T(v) = \\lambda v$\n\tfor some $\\lambda \\in k$ (possibly zero, but remember $v \\neq 0$).\n\tThe value $\\lambda$ is called an \\vocab{eigenvalue} of $T$.\n\n\tWe will sometimes abbreviate\n\t``$v$ is an eigenvector with eigenvalue $\\lambda$''\n\tto just ``$v$ is a $\\lambda$-eigenvector''.\n\\end{definition}\nOf course, no mention to a basis anywhere.\n\n\\begin{example}\n\t[An example of an eigenvector and eigenvalue]\n\tConsider the example earlier with\n\t$T = \\begin{bmatrix} 2 & 1 \\\\ 0 & 3 \\end{bmatrix}$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Note that $e_1$ and $e_1 + e_2$ are\n\t\t$2$-eigenvectors and $3$-eigenvectors.\n\t\t\\ii Of course, $5e_1$ is also an $2$-eigenvector.\n\t\t\\ii And, $7e_1 + 7e_2$ is also a $3$-eigenvector.\n\t\\end{enumerate}\n\\end{example}\nSo you can quickly see the following observation.\n\\begin{ques}\n\tShow that the $\\lambda$-eigenvectors, together with $\\{0\\}$\n\tform a subspace.\n\\end{ques}\n\\begin{definition}\n\tFor any $\\lambda$, we define the $\\lambda$-\\vocab{eigenspace}\n\tas the set of $\\lambda$-eigenvectors together with $0$.\n\\end{definition}\nThis lets us state succinctly that\n``$2$ is an eigenvalue of $T$\nwith one-dimensional eigenspace spanned by $e_1$''.\n\nUnfortunately, it's not exactly true that eigenvalues always exist.\n\\begin{example}[Eigenvalues need not exist]\n\tLet $V = \\RR^2$ and let $T$ be the map\n\twhich rotates a vector by $90\\dg$\n\taround the origin.\n\tThen $T(v)$ is not a multiple of $v$ for any $v \\in V$,\n\tother than the trivial $v=0$.\n\\end{example}\n\nHowever, it is true if we replace $k$ with an\nalgebraically closed field\\footnote{A field is \\vocab{algebraically closed}\n\tif all its polynomials have roots,\n\tthe archetypal example being $\\CC$.}.\n\\begin{theorem}[Eigenvalues always exist over algebraically closed fields]\n\tSuppose $k$ is an \\emph{algebraically closed} field.\n\tLet $V$ be a finite dimensional $k$-vector space.\n\tThen if $T \\colon V \\to V$ is a linear map,\n\tthere exists an eigenvalue $\\lambda \\in k$.\n\\end{theorem}\n\\begin{proof}\n\t(From \\cite{ref:axler})\n\tThe idea behind this proof is to consider ``polynomials'' in $T$.\n\tFor example, $2T^2-4T+5$ would be shorthand for $2T(T(v)) - 4T(v) + 5v$.\n\tIn this way we can consider ``polynomials'' $P(T)$;\n\tthis lets us tie in the ``algebraically closed'' condition.\n\tThese polynomials behave nicely:\n\t\\begin{ques}\n\t\tShow that $P(T)+Q(T) = (P+Q)(T)$ and $P(T) \\circ Q(T) = (P \\cdot Q)(T)$.\n\t\\end{ques}\n\n\tLet $n = \\dim V < \\infty$ and fix any nonzero vector $v \\in V$,\n\tand consider vectors $v$, $T(v)$, \\dots, $T^n (v)$.\n\tThere are $n+1$ of them,\n\tso they can't be linearly independent for dimension reasons;\n\tthus there is a nonzero polynomial $P$ such that $P(T)$\n\tis zero when applied to $v$.\n\tWLOG suppose $P$ is a monic polynomial,\n\tand thus $P(z) = (z-r_1)\\dots(z-r_m)$ say.\n\tThen we get\n\t\\[ 0 = (T - r_1 \\id) \\circ (T - r_2 \\id) \\circ \\dots\n\t\t\\circ (T - r_m \\id)(v) \\]\n\t(where $\\id$ is the identity matrix).  This means at least one of\n\t$T - r_i \\id$ is not injective, i.e.\\ has a nontrivial kernel,\n\twhich is the same as an eigenvector.\n\\end{proof}\nSo in general we like to consider algebraically closed fields.\nThis is not a big loss:\nany real matrix can be interpreted as a complex matrix\nwhose entries just happen to be real, for example.\n\n\\section{The Jordan form}\nSo that you know exactly where I'm going,\nhere's the main theorem.\n\\begin{definition}\n\tA \\vocab{Jordan block} is an $n \\times n$ matrix of the following shape:\n\t\\[\n\t\t\\begin{bmatrix}\n\t\t\t\\lambda & 1 & 0 & 0 & \\dots & 0 & 0 \\\\\n\t\t\t0 & \\lambda & 1 & 0 & \\dots & 0 & 0 \\\\\n\t\t\t0 & 0 & \\lambda & 1 & \\dots & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 & \\lambda & \\dots & 0 & 0 \\\\\n\t\t\t\\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n\t\t\t0 & 0 & 0 & 0 & \\dots & \\lambda & 1 \\\\\n\t\t\t0 & 0 & 0 & 0 & \\dots & 0 & \\lambda\n\t\t\\end{bmatrix}.\n\t\\]\n\tIn other words, it has $\\lambda$ on the diagonal,\n\tand $1$ above it.\n\tWe allow $n = 1$,\n\tso $\\begin{bmatrix} \\lambda \\end{bmatrix}$ is a Jordan block.\n\\end{definition}\n\n\\begin{theorem}\n\t[Jordan canonical form]\n\tLet $T \\colon V \\to V$ be a linear map\n\tof finite-dimensional vector spaces\n\tover an algebraically closed field $k$.\n\tThen we can choose a basis of $V$\n\tsuch that the matrix $T$ is ``block-diagonal''\n\twith each block being a Jordan block.\n\n\tSuch a matrix is said to be in \\vocab{Jordan form}.\n\tThis form is unique up to rearranging the order of the blocks.\n\\end{theorem}\nAs an example, this means the matrix should look something like:\n\\[\n\t\\begin{bmatrix}\n\t\t\\lambda_1 & 1 \\\\\n\t\t0 & \\lambda_1 \\\\\n\t\t&& \\lambda_2 \\\\\n\t\t&&& \\lambda_3 & 1 & 0 \\\\\n\t\t&&& 0 & \\lambda_3 & 1 \\\\\n\t\t&&& 0 & 0 & \\lambda_3 \\\\\n\t\t&&&&&& \\ddots \\\\\n\t\t&&&&&&& \\lambda_m & 1 \\\\\n\t\t&&&&&&& 0 & \\lambda_m\n\t\\end{bmatrix}\n\\]\n\\begin{ques}\n\tCheck that diagonal matrices are the special case\n\twhen each block is $1 \\times 1$.\n\\end{ques}\n\nWhat does this mean?\nBasically, it means \\emph{our dream is almost true}.\nWhat happens is that $V$ can get broken down as a direct sum\n\\[ V = J_1 \\oplus J_2 \\oplus \\dots \\oplus J_m \\]\nand $T$ acts on each of these subspaces independently.\nThese subspaces correspond to the blocks in the matrix above.\nIn the simplest case, $\\dim J_i = 1$,\nso $J_i$ has a basis element $e$\nfor which $T(e) = \\lambda_i e$;\nin other words, we just have a simple eigenvalue.\nBut on occasion, the situation is not quite so simple,\nand we have a block of size greater than $1$;\nthis leads to $1$'s just above the diagonals.\n\nI'll explain later how to interpret the $1$'s,\nwhen I make up the word \\emph{descending staircase}.\nFor now, you should note that even if $\\dim J_i \\ge 2$,\nwe still have a basis element\nwhich is an eigenvector with eigenvalue $\\lambda_i$.\n\n\\begin{example}\n\t[A concrete example of Jordan form]\n\tLet $T : k^6 \\to k^6$ and suppose $T$ is given by the matrix\n\t\\[\n\t\tT = \\begin{bmatrix}\n\t\t\t5 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t0 & 2 & 1 & 0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 2 & 0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 & 7 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 & 0 & 3 & 0 \\\\\n\t\t\t0 & 0 & 0 & 0 & 0 & 3 \\\\\n\t\t\\end{bmatrix}.\n\t\\]\n\tReading the matrix, we can compute all the eigenvectors and eigenvalues:\n\tfor any constants $a, b \\in k$ we have\n\t\\begin{align*}\n\t\tT(a \\cdot e_1) &= 5a \\cdot e_1 \\\\\n\t\tT(a \\cdot e_2) &= 2a \\cdot e_2 \\\\\n\t\tT(a \\cdot e_4) &= 7a \\cdot e_4 \\\\\n\t\tT(a \\cdot e_5 + b \\cdot e_6) &= 3\\left[ a \\cdot e_5 + b \\cdot e_6 \\right].\n\t\\end{align*}\n\tThe element $e_3$ on the other hand,\n\tis not an eigenvector since $T(e_3) = e_2 + 2e_3$.\n\\end{example}\n\n%Here's the idea behind the proof.\n%We would like to be able to break down $V$ directly into components as above,\n%but some of the $\\lambda_i$'s from the different Jordan blocks could coincide,\n%and this turns out to give a technical difficulty for detecting them.\n%So instead, we're going to break down $V$ first into subspaces\n%based on the values of $\\lambda$'s;\n%these are called the \\emph{generalized eigenspaces}.\n%In other words, the generalized eigenspace of a given $\\lambda$\n%is just all the Jordan blocks which have eigenvalue $\\lambda$.\n%Only after that will we break the generalized eigenspace\n%into the individual Jordan blocks.\n%\n%The sections below record this proof in the other order:\n%the next part deals with breaking generalized\n%eigenspaces into Jordan blocks,\n%and the part after that is the one where we break down $V$ into\n%generalized eigenspaces.\n\n\\section{Nilpotent maps}\nBear with me for a moment.  First, define:\n\\begin{definition}\n\tA map $T: V \\to V$ is \\vocab{nilpotent} if $T^m$ is the zero map for some integer $m$.\n\t(Here $T^m$ means ``$T$ applied $m$ times''.)\n\\end{definition}\nWhat's an example of a nilpotent map?\n\\begin{example}\n\t[The ``descending staircase'']\n        Let $V = k^{\\oplus 3}$ have basis $e_1$, $e_2$, $e_3$.\n\tThen the map $T$ which sends\n\t\\[ e_3 \\mapsto e_2 \\mapsto e_1 \\mapsto 0 \\]\n\tis nilpotent, since $T(e_1) = T^2(e_2) = T^3(e_3) = 0$,\n\tand hence $T^3(v) = 0$ for all $v \\in V$.\n\\end{example}\nThe $3 \\times 3$ descending staircase has matrix representation\n\\[ T = \\begin{bmatrix}\n\t\t0 & 1 & 0 \\\\\n\t\t0 & 0 & 1 \\\\\n\t\t0 & 0 & 0\n\t\\end{bmatrix}. \\]\nYou'll notice this is a Jordan block.\n\\begin{exercise}\n\tShow that the descending staircase above\n\thas $0$ as its only eigenvalue.\n\\end{exercise}\n\nThat's a pretty nice example.\nAs another example, we can have multiple such staircases.\n\\begin{example}\n\t[Double staircase]\n\tLet $V = k^{\\oplus 5}$ have basis $e_1$, $e_2$, $e_3$, $e_4$, $e_5$.\n\tThen the map\n\t\\[ e_3 \\mapsto e_2 \\mapsto e_1 \\mapsto 0 \\text{ and }\n\t\te_5 \\mapsto e_4 \\mapsto 0 \\]\n\tis nilpotent.\n\\end{example}\nPicture, with some zeros omitted for emphasis:\n\\[ T = \\begin{bmatrix}\n\t\t0 & 1 & 0 &   &   \\\\\n\t\t0 & 0 & 1 &   &   \\\\\n\t\t0 & 0 & 0 &   &   \\\\\n\t\t  &   &   & 0 & 1 \\\\\n\t\t  &   &   & 0 & 0 \\\\\n\t\\end{bmatrix}\n\\]\nYou can see this isn't really that different\nfrom the previous example;\nit's just the same idea repeated multiple times.\nAnd in fact we now claim that \\emph{all}\nnilpotent maps have essentially that form.\n\\begin{theorem}\n\t[Nilpotent Jordan]\n\tLet $V$ be a finite-dimensional vector space\n\tover an algebraically closed field $k$.\n\tLet $T \\colon V \\to V$ be a nilpotent map.\n\tThen we can write $V = \\bigoplus_{i=1}^m V_i$\n\twhere each $V_i$ has a basis of the form\n\t$v_i$, $T(v_i)$, \\dots, $T^{\\dim V_i - 1}(v_i)$\n\tfor some $v_i \\in V_i$.\n\\end{theorem}\nHence:\n\\begin{moral}\n\tEvery nilpotent map can be viewed as independent staircases.\n\\end{moral}\nEach chain $v_i$, $T(v_i)$, $T(T(v_i))$, \\dots is just one staircase.\nThe proof is given later, but first let me point out where this is going.\n\nHere's the punch line.\nLet's take the double staircase again.\nExpressing it as a matrix gives, say\n\\[\n\tS = \\begin{bmatrix}\n\t\t0 & 1 & 0 &   &   \\\\\n\t\t0 & 0 & 1 &   &   \\\\\n\t\t0 & 0 & 0 &   &   \\\\\n\t\t  &   &   & 0 & 1 \\\\\n\t\t  &   &   & 0 & 0\n\t\\end{bmatrix}.\n\\]\nThen we can compute\n\\[\n\tS + \\lambda \\id = \\begin{bmatrix}\n\t\t\\lambda & 1 & 0 &   &   \\\\\n\t\t0 & \\lambda & 1 &   &   \\\\\n\t\t0 & 0 & \\lambda &   &   \\\\\n\t\t  &   &   & \\lambda & 1 \\\\\n\t\t  &   &   & 0 & \\lambda\n\t\\end{bmatrix}.\n\\]\nIt's a bunch of $\\lambda$ Jordan blocks!\nThis gives us a plan to proceed: we need to break $V$ into\na bunch of subspaces such that $T - \\lambda \\id$ is nilpotent over each subspace.\nThen Nilpotent Jordan will finish the job.\n\n\\section{Reducing to the nilpotent case}\n\\begin{definition}\n\tLet $T \\colon V \\to V$. A subspace $W \\subseteq V$\n\tis called $T$-\\vocab{invariant}\n\tif $T(w) \\in W$ for any $w \\in W$.\n\tIn this way, $T$ can be thought of as a map $W \\to W$.\n\\end{definition}\nIn this way, the Jordan form is a decomposition of $V$ into invariant subspaces.\n\nNow I'm going to be cheap, and define:\n\\begin{definition}\n\tA map $T \\colon V \\to V$ is called \\vocab{indecomposable}\n\tif it's impossible to write $V = W_1 \\oplus W_2$\n\twhere both $W_1$ and $W_2$ are nontrivial $T$-invariant spaces.\n\\end{definition}\nPicture of a \\emph{decomposable} map:\n\\[\n\t\\begin{bmatrix}\n\t\t\\multicolumn{2}{c|}{\\multirow{2}{*}{$W_1$}} & 0 & 0 & 0  \\\\\n\t\t\\multicolumn{2}{c|}{} & 0 & 0 & 0 \\\\ \\hline\n\t\t0 & 0 & \\multicolumn{3}{|c}{\\multirow{3}{*}{$W_2$}} \\\\\n\t\t0 & 0 & \\multicolumn{3}{|c}{} \\\\\n\t\t0 & 0 & \\multicolumn{3}{|c}{}\n\t\\end{bmatrix}\n\\]\nAs you might expect, we can break a space apart into ``indecomposable'' parts.\n\\begin{proposition}\n\t[Invariant subspace decomposition]\n\tLet $V$ be a finite-dimensional vector space.\n\tGiven any map $T \\colon V \\to V$, we can write\n\t\\[ V = V_1 \\oplus V_2 \\oplus \\dots \\oplus V_m \\]\n\twhere each $V_i$ is $T$-invariant,\n\tand for any $i$ the map $T \\colon V_i \\to V_i$ is indecomposable.\n\\end{proposition}\n\\begin{proof}\n\tSame as the proof that every integer is the product of primes.\n\tIf $V$ is not decomposable, we are done.\n\tOtherwise, by definition write $V = W_1 \\oplus W_2$\n\tand then repeat on each of $W_1$ and $W_2$.\n\\end{proof}\n\nIncredibly, with just that we're almost done!\nConsider a decomposition as above,\nso that $T \\colon V_1 \\to V_1$ is an indecomposable map.\nThen $T$ has an eigenvalue $\\lambda_1$, so let $S = T - \\lambda_1 \\id$; hence $\\ker S \\neq \\{0\\}$.\n\\begin{ques}\n\tShow that $V_1$ is also $S$-invariant, so we can consider $S : V_1 \\to V_1$.\n\\end{ques}\nBy \\Cref{prob:endomorphism_eventual_lemma}, we have\n\\[ V_1 = \\ker S^N \\oplus \\img S^N \\]\nfor some $N$.\nBut we assumed $T$ was indecomposable,\nso this can only happen if $\\img S^N = \\{0\\}$ and $\\ker S^N = V_1$\n(since $\\ker S^N$ contains our eigenvector).\nHence $S$ is nilpotent, so it's a collection of staircases.\nIn fact, since $T$ is indecomposable, there is only one staircase.\nHence $V_1$ is a Jordan block, as desired.\n\n\\section{(Optional) Proof of nilpotent Jordan}\nThe proof is just induction on $\\dim V$.\nAssume $\\dim V \\ge 1$, and let $W = T\\im(V)$ be the image of $V$.\nSince $T$ is nilpotent, we must have $W \\subsetneq V$.\nMoreover, if $W = \\{0\\}$ (i.e.\\ $T$ is the zero map) then we're already done.\nSo assume $\\{0\\} \\subsetneq W \\subsetneq V$.\n\nBy the inductive hypothesis, we can select a good basis of $W$:\n\\begin{align*}\n\t\\mathcal B' =\n\t\\Big\\{ & T(v_1), T(T(v_1)), T(T(T(v_1))), \\dots \\\\\n\t& T(v_2), T(T(v_2)), T(T(T(v_2))), \\dots \\\\\n\t& \\dots, \\\\\n\t& T(v_\\ell), T(T(v_\\ell)), T(T(T(v_\\ell))), \\dots \\Big\\}\n\\end{align*}\nfor some $T(v_i) \\in W$ (here we have taken advantage of the fact that each element of $W$ is itself of the form $T(v)$ for some $v$).\n\nAlso, note that there are exactly $\\ell$ elements of $\\mathcal B'$ which are in $\\ker T$\n(namely the last element of each of the $\\ell$ staircases).\nWe can thus complete it to a basis $v_{\\ell+1}, \\dots, v_m$ (where $m = \\dim \\ker T$).\n(In other words, the last element of each staircase plus the $m-\\ell$ new ones are a basis for $\\ker T$.)\n\nNow consider\n\\begin{align*}\n\t\\mathcal B =\n\t\\Big\\{ & v_1, T(v_1), T(T(v_1)), T(T(T(v_1))), \\dots \\\\\n\t& v_2, T(v_2), T(T(v_2)), T(T(T(v_2))), \\dots \\\\\n\t& \\dots, \\\\\n\t& v_\\ell, T(v_\\ell), T(T(v_\\ell)), T(T(T(v_\\ell))), \\dots \\\\\n\t& v_{\\ell+1}, v_{\\ell+2}, \\dots, v_m \\Big\\}.\n\\end{align*}\n\\begin{ques}\nCheck that there are exactly $\\ell + \\dim W + (\\dim \\ker T - \\ell) = \\dim V$ elements.\n\\end{ques}\n\\begin{exercise}\n\tShow that all the elements are linearly independent.\n\t(Assume for contradiction there is some linear dependence,\n\tthen take $T$ of both sides.)\n\\end{exercise}\nHence $\\mathcal B$ is a basis of the desired form.\n\n\\section{Algebraic and geometric multiplicity}\n\\prototype{The matrix $T$ below.}\nThis is some convenient notation:\nlet's consider the matrix in Jordan form\n\\[\n\tT =\n\t\\begin{bmatrix}\n\t\t7 & 1 \\\\\n\t\t0 & 7 \\\\\n\t\t& & 9 \\\\\n\t\t& & & 7 & 1 & 0 \\\\\n\t\t& & & 0 & 7 & 1 \\\\\n\t\t& & & 0 & 0 & 7\n\t\\end{bmatrix}.\n\\]\nWe focus on the eigenvalue $7$,\nwhich appears multiple times, so it is certainly ``repeated''.\nHowever, there a two different senses in which you could say it is repeated.\n\\begin{itemize}\n\t\\ii \\emph{Algebraic}: You could say it is repeated five times,\n\tbecause it appears five times on the diagonal.\n\t\\ii \\emph{Geometric}: You could say it really only appears two times:\n\tbecause there are only two eigen\\emph{vectors}\n\twith eigenvalue $7$, namely $e_1$ and $e_4$.\n\n\tIndeed, the vector $e_2$ for example has $T(e_2) = 7e_2 + e_1$,\n\tso it's not really an eigenvector!\n\tIf you apply $T - 7\\id$ to $e_2$ twice though,\n\tyou do get zero.\n\\end{itemize}\n\\begin{ques}\n\tIn this example,\n\thow many times do you need to apply $T - 7\\id$ to $e_6$ to get zero?\n\\end{ques}\nBoth these notions are valid,\nso we will name both.\nTo preserve generality,\nwe first state the ``intrinsic'' definition.\n\\begin{definition}\n\tLet $T \\colon V \\to V$ be a linear map and $\\lambda$ a scalar.\n\t\\begin{itemize}\n\t\t\\ii The \\vocab{geometric multiplicity}\n\t\tof $\\lambda$ is the dimension $\\dim V_\\lambda$\n\t\tof the $\\lambda$-eigenspace.\n\n\t\t\\ii Define the \\vocab{generalized eigenspace}\n\t\t$V^\\lambda$ to be the subspace of $v$\n\t\tfor which $(T-\\lambda \\id)^n(v) = 0$ for some $n \\ge 1$.\n\t\tThe \\vocab{algebraic multiplicity} of $\\lambda$ is the\n\t\tdimension $\\dim V^\\lambda$.\n\t\\end{itemize}\n\t(Silly edge case: we allow ``multiplicity zero''\n\tif $\\lambda$ is not an eigenvalue at all.)\n\\end{definition}\nHowever in practice you should just count the Jordan blocks.\n\\begin{example}\n\t[An example of eigenspaces via Jordan form]\n\tRetain the matrix $T$ mentioned earlier and let $\\lambda = 7$.\n\t\\begin{itemize}\n\t\t\\ii The eigenspace $V_\\lambda$ has basis $e_1$ and $e_4$,\n\t\tso the geometric multiplicity is $2$.\n\t\t\\ii The generalized eigenspace $V^\\lambda$ has basis $e_1$, $e_2$,\n\t\t$e_4$, $e_5$, $e_6$ so the algebraic multiplicity is $5$.\n\t\\end{itemize}\n\\end{example}\n\nTo be completely explicit, here is how you think of these in practice:\n\\begin{proposition}\n\t[Geometric and algebraic multiplicity vs Jordan blocks]\n\tAssume $T \\colon V \\to V$ is a linear map\n\tof finite-dimensional vector spaces,\n\twritten in Jordan form.\n\tLet $\\lambda$ be a scalar.\n\tThen\n\t\\begin{itemize}\n\t\t\\ii The geometric multiplicity of $\\lambda$ is the number\n\t\tof Jordan blocks with eigenvalue $\\lambda$;\n\t\tthe eigenspace has one basis element per Jordan block.\n\n\t\t\\ii The algebraic multiplicity of $\\lambda$ is the\n\t\tsum of the dimensions of the Jordan blocks\n\t\twith eigenvalue $\\lambda$;\n\t\tthe eigenspace is the direct sum of the subspaces\n\t\tcorresponding to those blocks.\n\t\\end{itemize}\n\\end{proposition}\n\n\\begin{ques}\n\tShow that the geometric multiplicity\n\tis always less than or equal to the algebraic multiplicity.\n\\end{ques}\n\nThis actually gives us a tentative definition:\n\\begin{itemize}\n\t\\ii The trace is the sum of the eigenvalues,\n\tcounted with algebraic multiplicity.\n\t\\ii The determinant is the product of the eigenvalues,\n\tcounted with algebraic multiplicity.\n\\end{itemize}\nThis definition is okay,\nbut it has the disadvantage of requiring the ground\nfield to be algebraically closed.\nIt is also not the definition that is easiest\nto work with computationally.\nThe next two chapters will give us a better definition.\n\n\\section\\problemhead\n\n\\begin{problem}\n\t[Sum of algebraic multiplicities]\n\tGiven a $2018$-dimensional complex vector space $V$\n\tand a map $T \\colon V \\to V$,\n\twhat is the sum of the algebraic multiplicities\n\tof all eigenvalues of $T$?\n\t\\begin{sol}\n\t\tIt's just $\\dim V = 2018$.\n\t\tAfter all, you are adding the dimensions of the Jordan blocks\\dots\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[The word ``diagonalizable'']\n\tA linear map $T \\colon V \\to V$ (where $\\dim V$ is finite)\n\tis said to be \\vocab{diagonalizable}\n\tif it has a basis $e_1$, \\dots, $e_n$\n\tsuch that each $e_i$ is an eigenvector.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Explain the name ``diagonalizable''.\n\t\t\\ii Suppose we are working over an algebraically closed field.\n\t\tThen show that that $T$ is diagonalizable if and only if\n\t\tfor any $\\lambda$, the geometric multiplicity of $\\lambda$\n\t\tequals the algebraic multiplicity of $\\lambda$.\n\t\\end{enumerate}\n\t\\begin{sol}\n\t\t(a): if you express $T$ as a matrix in such a basis,\n\t\tone gets a diagonal matrix.\n\t\t(b): this is just saying each Jordan block has dimension $1$,\n\t\twhich is what we wanted.\n\t\t(We are implicitly using uniqueness of Jordan form here.)\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Switcharoo]\n\tLet $V$ be the $\\CC$-vector space\n\twith basis $e_1$ and $e_2$.\n\tThe map $T \\colon V \\to V$ sends $T(e_1) = e_2$ and $T(e_2) = e_1$.\n\tDetermine the eigenspaces of $T$.\n\t\\begin{sol}\n\t\tThe $+1$ eigenspace is spanned by $e_1+e_2$.\n\t\tThe $-1$ eigenspace is spanned by $e_1-e_2$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Writing a polynomial backwards]\n\tDefine the complex vector space $V$\n\tof polynomials with degree at most $2$,\n\tsay $V = \\left\\{ ax^2 + bx + c \\mid a,b,c \\in \\CC \\right\\}$.\n\tDefine $T \\colon V \\to V$ by\n\t\\[ T(ax^2+bx+c) = cx^2+bx+a. \\]\n\tDetermine the eigenspaces of $T$.\n\t\\begin{sol}\n\t\tThe $+1$ eigenspace is spanned by $1+x^2$ and $x$.\n\t\tThe $-1$ eigenspace is spanned by $1-x^2$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Differentiation of polynomials]\n\tLet $V = \\RR[x]$ be the real vector space of all real polynomials.\n\tNote that $\\frac{d}{dx} \\colon V \\to V$ is a linear map\n\t(for example it sends $x^3$ to $3x^2$).\n\tWhich real numbers are eigenvalues of this map?\n\t\\begin{hint}\n\t\tOnly $0$ is.\n\t\tLook at degree.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tConstant functions differentiate to zero,\n\t\tand these are the only $0$-eigenvectors.\n\t\tThere can be no other eigenvectors,\n\t\tsince if $\\deg p > 0$ then $\\deg p' = \\deg p - 1$,\n\t\tso if $p'$ is a constant real multiple of $p$\n\t\twe must have $p' = 0$, ergo $p$ is constant.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Differentiation of functions]\n\tLet $V$ be the real vector space of all\n\tinfinitely differentiable functions $\\RR \\to \\RR$.\n\tNote that $\\frac{d}{dx} \\colon V \\to V$ is a linear map\n\t(for example it sends $\\cos x$ to $-\\sin x$).\n\tWhich real numbers are eigenvalues of this map?\n\t\\begin{hint}\n\t\tAll of them are!\n\t\\end{hint}\n\t\\begin{sol}\n\t\t$e^{cx}$ is an example of a $c$-eigenvector for every $c$.\n\t\tIf you know differential equations,\n\t\tthese generate all examples!\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "4fa53543b466f63605f336e771469c938da20795", "size": 23728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/linalg/eigenvalues.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/linalg/eigenvalues.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/linalg/eigenvalues.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.5889212828, "max_line_length": 134, "alphanum_fraction": 0.673128793, "num_tokens": 8112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.769080247656264, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.6611504059955398}}
{"text": "\\documentclass[]{article}\n\n%\\usepackage{showframe} % To render a frame marking the margins \n\n\\usepackage{tikz}\n\\usetikzlibrary{\n    angles,\n    arrows.meta,\n    automata, % to use \\node[state]\n    graphs,\n    intersections,\n    quotes,\n    positioning\n}\n\\usepackage{amsmath, amssymb} % for $\\therefore e_{l} * e_{r} \\implies e_{r}$\n\n% epigraph for quote at start of section\n\\usepackage{epigraph}\n\\setlength\\epigraphwidth{8cm}\n\\setlength\\epigraphrule{0pt}\n\\renewcommand{\\epigraphsize}{\\small\\itshape}\n\n% for hyperlinks and URL links\n\\usepackage{hyperref}\n\n\\title{\\LaTeX{} Experiments\\\\ Part III: PGF/TikZ}\n\n\\author{AeAeA}\n\n\\begin{document}\n\n\\maketitle\n\n\\vspace{20pt}\n\n\\begin{figure}[h] \\centering\n    \\begin{tikzpicture}\n        \\draw[gray, thick, ->] (-1,2) -- (2,-4);\n        \\draw[gray, thick] (-1,-1) -- (2,2);\n        \\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};\n    \\end{tikzpicture}\n\\end{figure}\n\n%==============================================================================\n\\section{TikZ ist {\\itshape kein} Zeichenprogramm}\n\n\\epigraph\n{Für meinen Vater, damit er noch viele schöne TEX-Graphiken erschaffen kann.}\n{--- \\textup{Till Tantau}, PGF Manual}\n\n\\begin{itemize}\n    \\item \\url{https://en.wikipedia.org/wiki/PGF/TikZ}\n    \\item \\url{https://www.ctan.org/pkg/pgf}\n    \\item \\url{https://github.com/pgf-tikz/pgf}\n    \\item \\href{http://cremeronline.com/LaTeX/minimaltikz.pdf}\n               {Minimal introduction to TikZ (unofficial)}\n    \\item  It comes with very good documentation; the version 3.1.5b of the \n           \\href{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}\n                {PGF Manual} has over 1,300 pages (!) \\ldots\n    \\item \\ldots and an extensive collection of examples: \\\\\n          \\url{http://www.texample.net/tikz/}\n    \\item \\url{https://en.wikibooks.org/wiki/LaTeX/PGF/TikZ}\n    \\item \\url{https://www.overleaf.com/learn/latex/TikZ_package}\n\\end{itemize}\n\n\n\n%--------------------------------------\n\\subsection{Basic elements: points, lines and paths}\n\n\\begin{tikzpicture}\n    \\draw (-2,0) -- (2,0);\n    \\filldraw [gray] (0,0) circle (2pt);\n    \\draw[very thick, <->] (-2,-2) .. controls (0,0) .. (2,-2);\n    \\draw (-2,2) .. controls (-1,0) and (1,0) .. (2,2); \n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Basic geometric shapes: Circles, ellipses and polygons}\n\n\\begin{tikzpicture}\n    \\filldraw[color=red!60, fill=red!7, very thick] (-1,0) circle (1.5);\n    \\fill[blue!10] (2.5,0) ellipse (1.5 and 0.5);\n    \\fill[blue]    (2.5,0) circle (2pt);\n    \\draw (2.5,0) ellipse [x radius=1.5, y radius=0.5];\n    \\draw[ultra thick, ->] (6.5,0) arc (0:270:1);\n\\end{tikzpicture}\n\n\\vspace{20pt}\n\n\\begin{tikzpicture}\n    \\draw[blue, very thick] (0,0) rectangle (3,2);\n    \\draw[orange, ultra thick] (4,0) -- (6,0) -- (5.7,2) -- cycle;\n\\end{tikzpicture}\n\nThe code for the little \"turned\" ellipse \n\\tikz \\draw[rotate=30] (0,0) ellipse [x radius=6pt,y radius=3pt]; is \\\\\n\\verb+\\tikz \\draw[rotate=30] (0,0) ellipse [x radius=6pt,y radius=3pt];+\n\n%--------------------------------------\n\\subsection{Elliptical arc}\n%  \\usetikzlibrary {arrows.meta}\n\\begin{tikzpicture}[>=Stealth]\n    \\draw[<->>,very thick] \n        (0,0) arc [start angle=0, end angle=315, x radius=1.75cm, y radius=1cm];\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Arrow tips}\n\n\\marginpar{\\texttt{Stealth}\\\\\n\\tikz [>=Stealth] \\draw[<<<<-,ultra thick] (0,0) -- (0.1pt,0);}\n\n\\epigraph\n{Karl wonders whether such a military name for the arrow type is really necessary. \nHe is not really mollified when his son tells him that Microsoft’s PowerPoint \nuses the same name. He decides to have his students discuss this at some point.}\n{--- \\textup{Till Tantau}, PGF Manual}\n\nThis is an example of \\texttt{Stealth} arrow tip \n\\tikz [>=Stealth]\n    \\draw[<<-,ultra thick] (1,0) -- (1.5cm,10pt) -- (2cm,0pt) -- (2.5cm,10pt);\nwhich is a “stealth-fighter-like”.\n\nAll arrow tips:\\\\\n%  \\usetikzlibrary {arrows.meta}\n\\begin{tikzpicture} [->,very thick]\n    \\draw[>=Arc Barb]      (0,0) -- (0,10pt);\n    \\draw[>=Bar]           (10pt,0) -- (10pt,10pt);\n    \\draw[>=Bracket]       (20pt,0) -- (20pt,10pt);\n    \\draw[>=Butt Cap]      (30pt,0) -- (30pt,10pt);\n    \\draw[>=Circle]        (40pt,0) -- (40pt,10pt);\n    \\draw[>=Diamond]       (50pt,0) -- (50pt,10pt);\n    \\draw[>=Ellipse]       (60pt,0) -- (60pt,10pt);\n    \\draw[>=Fast Round]    (70pt,0) -- (70pt,10pt);\n    \\draw[>=Fast Triangle] (80pt,0) -- (80pt,10pt);\n    \\draw[>=Hooks]         (90pt,0) -- (90pt,10pt);\n    \\draw[>=Implies]       (100pt,0) -- (100pt,10pt);\n    \\draw[>=Kite]          (110pt,0) -- (110pt,10pt);\n    \\draw[>=LaTeX]         (120pt,0) -- (120pt,10pt);\n    \\draw[>=Latex]         (130pt,0) -- (130pt,10pt);\n    \\draw[>=Parenthesis]   (140pt,0) -- (140pt,10pt);\n    \\draw[>=Rays]          (150pt,0) -- (150pt,10pt);\n    \\draw[>=Rectangle]     (160pt,0) -- (160pt,10pt);\n    \\draw[>=Round Cap]     (170pt,0) -- (170pt,10pt);\n    \\draw[>=Square]        (180pt,0) -- (180pt,10pt);\n    \\draw[>=Stealth]       (190pt,0) -- (190pt,10pt);\n    \\draw[>=Straight Barb] (200pt,0) -- (200pt,10pt);\n    \\draw[>=Tee Barb]      (210pt,0) -- (210pt,10pt);\n    \\draw[>=To]            (220pt,0) -- (220pt,10pt);\n    \\draw[>=Triangle]      (230pt,0) -- (230pt,10pt);\n    \\draw[>=Triangle Cap]  (240pt,0) -- (240pt,10pt);\n    \\draw[>=Turned Square] (250pt,0) -- (250pt,10pt);\n\\end{tikzpicture}\n\n\\marginpar{\\tikz \\draw[-To,red,ultra thick] (0,0) -- (0.1pt,0);}\n(Almost) zero-length arrow: \n\\tikz \\draw[-To,red,ultra thick] (0,0) -- (0.1pt,0);\n\n\\subsubsection{Arrow Tip Kind \\texttt{Implies}}\n\\marginpar{$\\therefore\\\\ e_{l} * e_{r} \\implies e_{r}$}\nThis arrow tip makes only sense in conjunction with the double option:\nattach it to a double line to get something \n( \\tikz \\draw[double equal sign distance, -Implies] (0,0) -- (15pt,0); ) \nthat looks like \n\\texttt{amsmath} \\TeX’s \\verb+\\implies+ arrow ( $\\implies$ ). \nA typical use of this arrow tip is:\\\\\n% \\usetikzlibrary {arrows.meta,graphs}\n\\tikz \\graph [\n    clockwise=3, math nodes, edges = {double equal sign distance, -Implies}\n] { \n    \"\\alpha\", \"\\beta\", \"\\gamma\";\n    \"\\alpha\" -> \"\\beta\" -> \"\\gamma\" -> \"\\alpha\"\n};\n\n\n%--------------------------------------\n\\subsection{Path}\n\n\\tikz \\draw[thick,rounded corners=8pt]\n    (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0);\n\n%--------------------------------------\n\\subsection{Curved path}\n\n\\begin{tikzpicture}[scale=2]\n    \\filldraw[gray] (0,0) circle [radius=2pt]\n                    (1,1) circle [radius=2pt] \n                    (2,1) circle [radius=2pt] \n                    (2,0) circle [radius=2pt];\n    \\draw[gray] (0,0) .. controls (1,1) and (2,1) .. (2,0);\n\n    \\filldraw[orange] (0.5,0.5) circle [radius=2pt]\n                      (2,0.5) circle [radius=2pt];                \n    \\draw[orange] (0,0) .. controls (0.5,0.5) and (2,0.5) .. (2,0);\n\n    \\filldraw[blue] (2,2) circle [radius=2pt];\n    \\draw[blue] (0,0) .. controls (2,2) .. (2,0);\n\n    \\filldraw[red] (3,2) circle [radius=2pt]\n                   (-1,2) circle [radius=2pt];                \n    \\draw[red] (0,0) .. controls (3,2) and (-1,2) .. (2,0);\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Grid}\n\\marginpar{\\tikz \\draw[step=2pt] (0,0) grid (10pt,10pt);}\nThe code \\verb+\\tikz \\draw[step=2pt] (0,0) grid (10pt,10pt);+ produces\n\\tikz \\draw[step=2pt] (0,0) grid (10pt,10pt);.\n\nHere is a bigger grid:\\\\\n\\tikz{ \n    \\fill[orange] (0,0) circle (2pt);\n    \\fill[red] (50pt,50pt) circle (2pt);\n    \\fill[blue] (100pt,100pt) circle (2pt);\n\n    \\draw[step=5pt,gray,very thin] (1pt,1pt) grid (99pt,99pt);\n\n    \\draw (50pt,0) -- (50pt,100pt); % vertical\n    \\draw (0,50pt) -- (100pt,50pt); % horizontal\n}\n\n%--------------------------------------\n\\subsection{Circle and curved path}\n\\marginpar{0.555}\n0.555 is the magic number.\\\\\n\\begin{tikzpicture} [\n    dark green/.style = {green!50!black}\n]\n    \\draw[step=.5cm,gray,very thin] (-5.4,-5.4) grid (5.4,5.4); \n\n    \\draw (-5.5,0) -- (5.5,0);\n    \\draw (0,-5.5) -- (0,5.5);\n\n    \\draw[gray,thick] (0,0) circle [radius=5cm];\n\n    % 2.777 = 5 * 0.555(5)\n\n    \\fill[blue] (-5,2.777) circle (1pt) (-2.777,5) circle (1pt);\n    \\draw[blue,->] (-5,0) .. controls (-5,2.777) and (-2.777,5) .. (0,5);\n\n    \\fill[orange] (3,5) circle (1pt) (5,3) circle (1pt);\n    \\draw[orange,->] (0,5) .. controls (3,5) and (5,3) .. (5,0);\n\n    \\fill[dark green] (5,-5) circle (1pt);\n    \\draw[dark green,->] (5,0) .. controls (5,-5) .. (0,-5);\n\n    \\fill[red] (-2,-5) circle (1pt) (-5,-2) circle (1pt);\n    \\draw[red,->] (0,-5) .. controls (-2,-5) and (-5,-2) .. (-5,0);\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Clipping a path}\nOriginal drawing on the left, clipped (and 1.4 scaled) drawing on the right:\\\\\n\\begin{tikzpicture}\n    \\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4); \n    \\draw (-1.5,0) -- (1.5,0);\n    \\draw (0,-1.5) -- (0,1.5);\n    \\draw[thick] (0,0) circle (1);\n    \\draw (0.3,0) arc [start angle=0, end angle=30, radius=0.3];\n\\end{tikzpicture}\n\\begin{tikzpicture}[scale=1.4]\n    \\path[draw,clip] (0.5,0.5) circle (1);\n    \\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4); \n    \\draw (-1.5,0) -- (1.5,0);\n    \\draw (0,-1.5) -- (0,1.5);\n    \\draw[thick] (0,0) circle (1);\n    \\draw (0.3,0) arc [start angle=0, end angle=30, radius=0.3];\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Parabola and Sine}\n\\marginpar{\n    \\tikz \\draw[x=1.57ex,y=1ex] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0) \n(0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1);\n}\nTwo parabolas \n\\tikz \\draw[x=2ex,y=2ex] (-1,0) rectangle (1,1) (-1,1) parabola (0,0) parabola (1,1);\nand a parabola with placed bend \n\\tikz \\draw[x=2ex,y=2ex] (-1,0) rectangle (1,1) (-1,1) parabola bend (0,0) (1,1);\n\nA parabola with the bend:\n\\tikz \\draw[x=1pt,y=1pt] (0,0) parabola bend (4,16) (6,12);\n\nA sine \\tikz \\draw[x=1ex,y=1ex] (0,0) sin (1.57,1); curve, \nand a longer span of sine and cosine: \n\\tikz \\draw[x=1.57ex,y=1ex] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0) \n                            (0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1);\n\n%--------------------------------------\n\\subsection{Closing the path}\nThe \\texttt{--cycle} causes the current path to be closed (actually the current part of \nthe current path) by smoothly joining the first and last point. To appreciate \nthe difference, consider the following example:\\\\\n\\begin{tikzpicture}[line width=5pt]\n    \\draw (0,0) -- (1,0) -- (1,1) -- (0,0);\n    \\draw (2,0) -- (3,0) -- (3,1) -- cycle; \n    \\useasboundingbox (0,1.5); % make bounding box higher\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Shading}\n\\marginpar{\\tikz \\shade[ball color=green] (.5,.5) circle (.5);}\nThe default shading is a smooth transition from gray at the top \nto white at the bottom:\\\\\n\\tikz \\shade (0,0) rectangle (2,1)  (3,0.5) circle (.5cm);\n\nTo specify different colors, you can use options:\\\\ \n\\begin{tikzpicture}[rounded corners,ultra thick]\n    \\shade[top color=yellow,bottom color=black] (0,0) rectangle +(2,1);\n    \\shade[left color=yellow,right color=black] (3,0) rectangle +(2,1);\n    \\shadedraw[inner color=yellow,outer color=black,draw=yellow] (6,0) rectangle +(2,1); \n    \\shade[ball color=green] (9,.5) circle (.5);\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Scoping}\n\\begin{tikzpicture}[ultra thick]\n    \\draw (0,0) -- (0,1);\n    \\begin{scope}[thin]\n        \\draw (1,0) -- (1,1);\n        \\draw (2,0) -- (2,1);\n    \\end{scope}\n    \\draw (3,0) -- (3,1);\n\\end{tikzpicture}\n\n\n\\newpage\n%==============================================================================\n\\section{A picture for Karl}\n\n%--------------------------------------\n\\subsection{Style}\n\\tikzset{help lines/.style=very thin}\n\\begin{tikzpicture}[\n    Karl's grid/.style ={help lines,color=#1!50},\n    Karl's grid/.default=blue\n]\n\n    \\draw[Karl's grid]     (0,0) grid (1.5,2);\n    \\draw[Karl's grid=red] (2,0) grid (3.5,2);\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Adding Text}\n\\begin{tikzpicture}\n    \\draw (0,0) rectangle (2,2);\n    \\draw (0.5,0.5) node [fill=yellow!80!black]\n                           {Text at \\verb!node 1!}\n         -- (1.5,1.5) node {Text at \\verb!node 2!};\n\\end{tikzpicture}\n\nIf the label directly after the \\verb+--+ and before the coordinate, \nthis places the label in the middle of the line, but the \\verb+pos=+ \noptions can be used to modify this. Also, options like \\verb+near start+ \nand \\verb+near end+ can be used to modify this position. You can also \nposition labels on curves and, by adding the \\verb+sloped+ option, \nhave them rotated such that they match the line’s slope. \nHere is an example:\\\\\n\\begin{tikzpicture}\n    \\draw (0,0) .. controls (6,1) and (9,1) ..\n      node[near start,sloped,above] {near start}\n      node {midway}\n      node[very near end,sloped,below] {very near end} (12,0);\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Diagrams with nodes}\n\n\\begin{tikzpicture}[\n    roundnode/.style   = {circle, draw=green!60!black, fill=green!5, very thick, \n                          minimum size=20pt},\n    squarednode/.style = {rectangle, draw=red!60, fill=red!5, very thick, \n                          minimum size=15pt},\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) .. \n              controls +(down:20pt) and +(right:20pt) \n              .. (lowercircle.east);\n\\end{tikzpicture}\n\n\\subsubsection{Extracting Insights From Data diagram}\n\\begin{tikzpicture}[\n    squarednode/.style = {rectangle, draw=orange!60!black, fill=orange!7, \n                          very thick, \n                          minimum size=20pt,\n                          rounded corners=2pt},\n    impliesarrow/.style = {double equal sign distance, -Implies}\n]\n  \n    \\node[squarednode] (DK) {Domain Knowledge};\n    \\node[squarednode] (SA) [below=of DK] {Schema \\& Algorithms};\n    \\node[squarednode] (SP) [right=of SA] {Production System}; \n    \\node[squarednode] (EA) [above=of SP] {Exploratory Analysis};\n\n    \\draw[impliesarrow] (DK.south) -- (SA.north);\n    \\draw[impliesarrow] (SA.east) -- (SP.west);\n    \\draw[impliesarrow] (SP.north) -- (EA.south);\n    \\draw[impliesarrow] (EA.west) -- (DK.east);\n    % \\draw[impliesarrow] (DA.north) .. controls +(up:30pt) and +(right:40pt) .. (DK.east);\n\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Specifying Coordinates}\nTo appreciate the difference between + and ++ consider the following example:\\\\\n\\verb|-- ++(1cm,0cm)  -- ++(0cm,1cm)  -- ++(-1cm,0cm) -- cycle|\\\\\n\\begin{tikzpicture}\n    \\def\\rectanglepath{-- ++(1cm,0cm)  -- ++(0cm,1cm)  -- ++(-1cm,0cm) -- cycle}\n    \\draw (0,0) \\rectanglepath;\n    \\draw (1.5,0) \\rectanglepath;\n\\end{tikzpicture}\n\nBy comparison, when using a single +, the coordinates are different:\\\\\n\\verb|-- +(1cm,0cm)  -- +(1cm,1cm)  -- +(0cm,1cm) -- cycle|\\\\\n\\begin{tikzpicture}\n    \\def\\rectanglepath{-- +(1cm,0cm)  -- +(1cm,1cm)  -- +(0cm,1cm) -- cycle}\n    \\draw (0,0) \\rectanglepath;\n    \\draw (1.5,0) \\rectanglepath;\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Transformations}\n\\tikz \\draw (0,0) -- (0,0.5) [xshift=20pt] (0,0) -- (0,0.5);\n\n\\marginpar{\n\\begin{tikzpicture}[even odd rule,rounded corners=2pt,x=10pt,y=10pt] \n    \\filldraw[fill=yellow!80!black]   (0,0) rectangle (1,1) \n                [shift={(0.5,0.5)}]   (0,0) rectangle (1,1)\n                        [rotate=30] (-1,-1) rectangle (2,2) \n                                      (0,0) circle (0.2) \n                  [shift={(-1,-1)}]   (0,0) circle (0.4);\n\\end{tikzpicture}\n}\n\nAnother way to display all options for arrow tips:\\\\\n\\begin{tikzpicture}\n    %  \\usetikzlibrary {arrows.meta}\n    \\def\\arrowup{[->,very thick] (0,0) -- (0,10pt)}\n\n    \\draw                                   [xshift=-40pt] \\arrowup;\n    \\draw[>=To,red]                         [xshift=-30pt] \\arrowup;\n    \\draw[>=Computer Modern Rightarrow,red] [xshift=-20pt] \\arrowup;\n    \\draw[>=Classical TikZ Rightarrow]      [xshift=-10pt] \\arrowup;\n    \\draw (0,5pt) circle (5pt); % circle to mark Arc Barb\n    \\draw[>=Arc Barb]                    \\arrowup;\n    \\draw[>=Bar]           [xshift=10pt] \\arrowup;\n    \\draw[>=Bracket]       [xshift=20pt] \\arrowup;\n    \\draw[>=Butt Cap]      [xshift=30pt] \\arrowup;\n    \\draw[>=Circle]        [xshift=40pt] \\arrowup;\n    \\draw[>=Diamond]       [xshift=50pt] \\arrowup;\n    \\draw[>=Ellipse]       [xshift=60pt] \\arrowup;\n    \\draw[>=Fast Round]    [xshift=70pt] \\arrowup;\n    \\draw[>=Fast Triangle] [xshift=80pt] \\arrowup;\n    \\draw[>=Hooks]         [xshift=90pt] \\arrowup;\n    \\draw[>=Implies]       [xshift=100pt] \\arrowup;\n    \\draw[>=Kite]          [xshift=110pt] \\arrowup;\n    \\draw[>=LaTeX]         [xshift=120pt] \\arrowup;\n    \\draw[>=Latex]         [xshift=130pt] \\arrowup;\n    \\draw[>=Parenthesis]   [xshift=140pt] \\arrowup;\n    \\draw[>=Rays]          [xshift=150pt] \\arrowup;\n    \\draw[>=Rectangle]     [xshift=160pt] \\arrowup;\n    \\draw[>=Round Cap]     [xshift=170pt] \\arrowup;\n    \\draw[>=Square]        [xshift=180pt] \\arrowup;\n    \\draw[>=Stealth]       [xshift=190pt] \\arrowup;\n    \\draw[>=Straight Barb] [xshift=200pt] \\arrowup;\n    \\draw[>=Tee Barb]      [xshift=210pt] \\arrowup;\n    \\draw[>=To]            [xshift=220pt] \\arrowup;\n    \\draw[>=Triangle]      [xshift=230pt] \\arrowup;\n    \\draw[>=Triangle Cap]  [xshift=240pt] \\arrowup;\n    \\draw[>=Turned Square] [xshift=250pt] \\arrowup;\n\\end{tikzpicture}\n\n\\newpage\n%--------------------------------------\n\\subsection{Repeating Things: For-Loops}\n\n\\foreach \\i/\\t in {\n    1/Arc Barb, 2/Bar, 3/Bracket, 4/Butt Cap, 5/Circle, \n    6/Diamond, 7/Ellipse, 8/Fast Round, 9/Fast Triangle, \n    10/Hooks, 11/Implies, 12/Kite, 13/LaTeX, 14/Latex, \n    15/Parenthesis, 16/Rays, 17/Rectangle, 18/Round Cap, \n    19/Square, 20/Stealth, 21/Straight Barb, 22/Tee Barb, \n    23/To, 24/Triangle, 25/Triangle Cap, 26/Turned Square} \n    {\\i. \\tikz [>=\\t] \\draw[->,ultra thick] (0,0) -- (15pt,0); \\t \\\\}\n\n\\foreach \\x in {1,2,3} {$x =\\x$, }\n\n\\tikz  \\foreach \\x in {-1,-0.5,...,1} \\draw[shift={(\\x,0)}] (0,-5pt) -- (0,5pt);\n\n\\tikz \\foreach \\x in {1,...,10} \\draw (\\x,0) circle (0.4);\n\n\\subsubsection{2D tables}\n\\begin{tikzpicture}\n    \\filldraw[fill=yellow!80!black] (6,1) circle (2pt);\n    \\foreach \\x in {1,2,...,5,7,8,...,12}\n        \\foreach \\y in {1,...,5}\n        {\n            \\draw (\\x,\\y) +(-.5,-.5) rectangle ++(.5,.5);\n            \\draw (\\x,\\y) node{\\x,\\y};\n        }\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Karl's picture}\n\\marginpar{\\begin{tikzpicture}\n    \\coordinate (A) at (2,0);\n    \\coordinate (B) at (0,0);\n    \\coordinate (C) at (30:2);\n    \\draw (A) -- (B) -- (C)\n        pic [draw=green!50!black, fill=green!20, angle radius=9mm, \"$\\alpha$\"] \n            {angle = A--B--C};\n\\end{tikzpicture}}\n\n\\begin{tikzpicture}\n    [scale=2.5,line cap=round,\n    % Styles\n    axes/.style=,\n    grid lines/.style={gray,very thin},\n    important line/.style={very thick},\n    information text/.style={rounded corners,fill=red!10,inner sep=1ex}]\n\n    % Colors\n    \\colorlet{anglecolor}{green!50!black}\n    \\colorlet{sincolor}{red}\n    \\colorlet{tancolor}{orange!80!black}\n    \\colorlet{coscolor}{blue}\n\n    % The graphic\n    \\draw[grid lines,step=.5] (-1.4,-1.4) grid (1.4,1.4);\n    \\draw (0,0) circle [radius=1cm];\n\n    \\begin{scope}[axes]\n        \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$} coordinate(x axis);\n        \\draw[->] (0,-1.5) -- (0,1.5) node[above] {$y$} coordinate(y axis);\n\n        \\foreach \\x/\\xtext in {-1, -.5/-\\frac{1}{2}, 1}\n            \\draw[xshift=\\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white] {$\\xtext$};\n        \\foreach \\y/\\ytext in {-1, -.5/-\\frac{1}{2}, .5/\\frac{1}{2}, 1}\n            \\draw[yshift=\\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white] {$\\ytext$};\n    \\end{scope}\n\n    \\filldraw[fill=green!20,draw=anglecolor] \n        (0,0) -- (3mm,0pt) arc [start angle=0, end angle=30, radius=3mm];\n    \\draw (15:2mm) node[anglecolor] {$\\alpha$};\n    \n    \\draw[important line,sincolor]\n        (30:1cm) -- node[left=1pt,fill=white] {$\\sin \\alpha$} (30:1cm |- x axis); \n\n    \\draw[important line,coscolor]\n    (30:1cm |- x axis) -- node[below=2pt,fill=white] {$\\cos \\alpha$} (0,0);\n\n    % to find tan(30) \"geometrically\", as an intersection of two lines:\n    \\path [name path=upward line] (1,0) -- (1,1);\n    \\path [name path=sloped line] (0,0) -- (30:1.5cm);\n    \\draw [name intersections={of=upward line and sloped line, by=t}]\n          [very thick,orange] (1,0) -- node [right=1pt,fill=white] \n          {$\\displaystyle \\tan \\alpha \\color{black}=\n          \\frac{{\\color{red}\\sin \\alpha}}{\\color{blue}\\cos \\alpha}$} (t);\n    \\draw (0,0) -- (t);\n    \n    % text area to the left:\n    \\draw[xshift=-1.55cm] \n        node[left,text width=3cm,information text] {\n            The {\\color{anglecolor} angle $\\alpha$} is $30^\\circ$ in the\n            example ($\\pi/6$ in radians). \n            The {\\color{sincolor}sine of\n            $\\alpha$}, which is the height of the red line, is\n            \\[ {\\color{sincolor} \\sin \\alpha} = 1/2. \\]\n            By the Theorem of Pythagoras ...\n        };\n\\end{tikzpicture}\n\n\n\\newpage\n%==============================================================================\n\\section{Nodes}\n\n\\begin{tikzpicture}\n    \\fill (0,0) circle (1pt);\n    \\path ( 0,2) node [shape=circle,draw] {}\n          ( 0,1) node [shape=circle,draw] {}\n          ( 0,0) node [shape=circle,draw] {}\n          ( 1,1) node [shape=rectangle,draw] {}\n          (-1,1) node [shape=rectangle,draw] {};\n  \\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Placing Nodes Using the At Syntax}\n\n\\begin{tikzpicture} [\n    place/.style      = {circle,draw=blue!50,fill=blue!20,thick},\n    transition/.style = {rectangle,draw=black!50,fill=black!20,thick}\n] \n    \\node at ( 0,2) [place] {};\n    \\node at ( 0,1) [place] {};\n    \\node at ( 0,0) [place] {};\n    \\node at ( 1,1) [transition] {};\n    \\node at (-1,1) [transition] {};\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Node size, name and style}\n\n\\begin{tikzpicture} [inner sep=2mm,\n    place/.style={circle,draw=blue!50,fill=blue!20,thick,\n                  inner sep=0pt,minimum size=6mm},\n    transition/.style={rectangle,draw=black!50,fill=black!20,thick,\n                  inner sep=0pt,minimum size=4mm}\n] \n    \\node[place]      (waiting 1)      at ( 0,2) {};\n    \\node[place]      (critical 1)     at ( 0,1) {};\n    \\node[place]      (semaphore)      at ( 0,0) {};\n    \\node[transition] (leave critical) at ( 1,1) {};\n    \\node[transition] (enter critical) at (-1,1) {};\n\\end{tikzpicture}\n\n%--------------------------------------\n\\subsection{Labels and pins}\n\n\\tikz [\n    every label/.style={draw,red,label distance=5mm},\n    pin distance=1.5cm\n] \\node [\n    circle,draw,\n    pin = right:X,\n    pin = above:Y,\n    pin = below left:Z,\n    label = center:*,\n    label = 60:$60^\\circ$,\n    label = 105:$105^\\circ$,\n    label = 175:$175^\\circ$,\n    label = -40:$-40^\\circ$,\n    label = -95:$-95^\\circ$,\n    label = -170:$-170^\\circ$\n] {my circle};\n\n\n%--------------------------------------\n\\subsection{Node with tabular text}\n\n\\tikz \\node [draw] {\n    \\begin{tabular}{cc}\n        upper left & upper right\\\\\n        lower left & lower right\n    \\end{tabular}\n};\n\n%--------------------------------------\n\\subsection{Gallery}\n\n\\begin{tikzpicture}\n    [scale=.8,auto=left,every node/.style={circle,fill=blue!20}] \n    \\node (a) at (-1,-2) {a};\n    \\node (b) at ( 1,-2) {b};\n    \\node (c) at ( 2,-1) {c};\n    \\node (d) at ( 2, 1) {d};\n    \\node (e) at ( 1, 2) {e};\n    \\node (f) at (-1, 2) {f};\n    \\node (g) at (-2, 1) {g};\n    \\node (h) at (-2,-1) {h};\n    \n    \\foreach \\from/\\to in {a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}\n        \\draw [->] (\\from) -- (\\to) node[midway,fill=red!20] {\\from--\\to}; \n\\end{tikzpicture}\n\n\\vspace{20pt}\n\n\\begin{tikzpicture}[auto]\n    \\draw[help lines,use as bounding box] (0,-.5) grid (4,5);\n    \\draw (0.5,0) .. controls (9,6) and (-5,6) .. (3.5,0)\n        node foreach \\pos in {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1}\n            [pos=\\pos,swap,fill=red!20] {\\pos}\n        node foreach \\pos in {0.025,0.2,0.4,0.6,0.8,0.975}\n            [pos=\\pos,fill=blue!20] {\\pos}; \n\\end{tikzpicture}\n\n\\vspace{20pt}\n\n% \\usetikzlibrary {automata}\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,auto]\n    \\draw[help lines] (0,0) grid (3,2);\n  \n    \\node[state] (q_0) {$q_0$}; \n    \\node[state] (q_1) [above right of=q_0] {$q_1$}; \n    \\node[state] (q_2) [below right of=q_0] {$q_2$}; \n    \\node[state] (q_3) [below right of=q_1] {$q_3$};\n    \n    \\path[->] (q_0) edge              node        {0} (q_1)\n                    edge              node [swap] {1} (q_2)\n              (q_1) edge              node        {1} (q_3)\n                    edge [loop above] node        {0} ()\n              (q_2) edge              node [swap] {0} (q_3)\n                    edge [loop below] node        {1} ();\n\\end{tikzpicture}\n\n\\end{document}", "meta": {"hexsha": "7fcf6379f84f6ddb38c383dbfce8e3d01f2a38fa", "size": 25472, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/latex-03-tikz.tex", "max_stars_repo_name": "whitechno/latex-ref", "max_stars_repo_head_hexsha": "9793846d5c51f1c22c2df926ffba670572169d72", "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/latex-03-tikz.tex", "max_issues_repo_name": "whitechno/latex-ref", "max_issues_repo_head_hexsha": "9793846d5c51f1c22c2df926ffba670572169d72", "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/latex-03-tikz.tex", "max_forks_repo_name": "whitechno/latex-ref", "max_forks_repo_head_hexsha": "9793846d5c51f1c22c2df926ffba670572169d72", "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.1304964539, "max_line_length": 91, "alphanum_fraction": 0.5475031407, "num_tokens": 9197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.6611504010432782}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Markov chain Monte Carlo}\n\\begin{frame}{MCMC: The best bad method you have ever seen}\nMarkov chain Monte Carlo (MCMC) methods are a broad class of stochastic algorithms to compute integrals.\n\nSuppose you are confronted with the following question: what is the ratio between the circumference of inscribed circle and its diameter?\nYou are \\textbf{not} allowed to use any Geometry.\n\\begin{figure}\n\\includegraphics[scale=0.85]{figures/pi_MC.png}\n\\end{figure}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{First, a warning}\n\\begin{quote}\n ``Monte Carlo is an extremely bad method; it should be used only when all alternative methods are worse.''\n\\end{quote}\nAlan Sokal (1955-) in \\textit{Monte Carlo Methods in Statistical Mechanics: Foundations and New Algorithms} (1996, pg. 1).\n\\begin{figure}\n\\includegraphics[scale=0.25]{figures/tiger.jpg}\n\\caption{MCMC is, in a way, like a captive tiger...}\n\\end{figure}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Also...}\n Repeat after me,\n \\begin{idea}[Bayesian MCMC is not a thing]\n \\begin{center}\n  {\\Huge There is no such thing as ``Bayesian'' MCMC.}\n \\end{center}  \n  \n  MCMC is a numerical method for computing integrals.\n  It does not care whether you are a Bayesian, frequentist, \\textit{flamenguista} or \\textit{corintiana}.\n \\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Computing integrals}\nTechnically, for a probability space $(X, \\mathcal{F}, P)$, for $f : X \\to \\mathbb{R}$, we want to compute\n$$\n\\mu_f = E_P[f] = \\int_{X} f\\,dP.  \n$$\nWhen $P$ is absolutely continuous with respect to the Lebesgue measure, we have \n$$\n\\mu_f= \\int_{X} f(x)p(x)\\,dx,\n$$\nas is usually written in introductory textbooks.\n\nA ``natural'' approach to obtain an estimator of  $\\mu_f$ is\n$$\n\\hat{\\mu}_{f, N}^{\\text{MC}} = \\frac{1}{N} \\sum_{n = 1}^{N} f(x_{n}),\n$$\nwith $x_1, \\ldots, x_N \\sim P$.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A central (limit) theorem}\nDefine\n$$\n\\text{MC-SE}_{N}[f]\n= \\sqrt{ \\frac{ \\text{Var}_{P}[f]}{N} }.\n$$\nThen\n$$\n\\lim_{N \\rightarrow \\infty}\n\\frac{ \\hat{\\mu}_{f,N}^{\\text{MC}} - \\mathbb{E}_{P}[f] }\n{ \\text{MC-SE}_{N}[f] }\n\\sim \\text{Normal}(0, 1),\n$$\n\\begin{idea}[MCMC-CLT needs to hold]\n A key insight is that MCMC only trustworthy when a central limit theorem holds.\n This means $f$ needs to be $2+\\epsilon$-integrable with respect to $P$.\n Look out for $\\text{MC-SE}$, too. \n It is important to quantify ``the probable error of the mean''\\footnote{A ``pun'' with William Gosset's (1876--1937) paper: Student. (1908). The probable error of a mean. Biometrika, 1-25.}, as it were.\n\\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Diagnostics}\n\\begin{idea}[Diagnose your MCMC!]\nPerhaps as important as learning how to run an MCMC is to learn to \\textbf{diagnose} it.\nThis means detecting failure to converge to $P$ and/or poor statistical performance.\n\\end{idea}\nWhen running $K$ chains,  the between sample variance can be written as\n\\begin{equation*}\n\\label{eq:Between}\n B = \\frac{N}{K-1} \\sum_{k = 1}^K \\left(\\bar{x}_k - \\bar{\\bar{x}}\\right)^2, \n\\end{equation*}\nwhere $\\bar{x}_k = N^{-1}\\sum_{n = 1}^N x_k^{(n)}$ and $\\bar{\\bar{x}} = K^{-1}\\sum_{k=1}^K\\bar{x}_k$.\nNow we can define the within variance as \n\\begin{equation*}\nW =  K^{-1}\\sum_{k = 1}^K s_k^2 \\: \\text{and} \\: s_k^2  = (N-1)^{-1} \\sum_{n = 1}^N \\left(x_k^{(n)} - \\bar{x}_k\\right)^2 \n\\end{equation*}\nFinally we can define the~\\textbf{potential scale reduction factor} (PSRF)~\\citep{Gelman1992}:\n\\begin{equation*}\n \\label{eq:PRSF}\n \\hat{R} = \\sqrt{\\frac{ (N-1)W +  B }{NW}}.\n\\end{equation*}\nAt convergence, $\\hat{R} < 1.1$, providing a univariate measure of convergence across chains (for a given parameter).\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{More diagnostics}\nOne of the things we are interested in is \\textit{statistical} performance, i.e., how precise the estimator $\\hat{\\mu}_{f,N}^{\\text{MC}}$ is.\nTo measure that, we can compute the \\textbf{effective sample size}:\n\\begin{equation*}\n \\text{ESS} = \\frac{N}{1 + 2\\sum_{t=1}^\\infty \\rho_t},\n\\end{equation*}\nwhere $\\rho_t$ is the \\textbf{autocorrelation} at lag $t$, $t=1, 2, \\ldots$.\nA good rule of thumb\\footnote{Assuming approximate normality. Calculation stolen from~\\url{https://www.biorxiv.org/content/10.1101/2021.05.04.442586v1.full.pdf}} is that if one wants to have a an standard error which is 1\\% of the width of the 95\\% interval of the true distribution is to have $\\text{ESS} \\geq 625$:\n\\begin{align*}\n \\frac{\\sigma}{\\sqrt{N}} &\\leq \\frac{\\sigma}{\\sqrt{\\text{ESS}}},\\\\\n 0.01 \\times 4 \\times \\sigma &\\leq \\frac{\\sigma}{\\sqrt{\\text{ESS}}},\\\\\n &\\implies\\\\\n \\text{ESS} &\\geq 625,\n\\end{align*}\nwhere $\\sigma = \\sqrt{\\text{Var}_{P}[f]}$.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Even more diagnostics}\n\\begin{figure}\n\\includegraphics[scale=0.25]{figures/traceplots.png}\n\\end{figure}\n\\begin{idea}[No one diagnostic is enough]\n Use multiple diagnostic metrics, always.\n Every MCMC diagnostic out there has blind spots; using multiple simultaneously increases the chances those blind spots are covered.\n\\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Scaling with dimension}\n\\begin{figure}\n\\includegraphics[scale=0.35]{figures/concentration_measure_volume.pdf}\n\\end{figure}\nTaken from~\\url{https://mc-stan.org/users/documentation/case-studies/curse-dims.html}.\n\\begin{idea}[The higher the dimension, the more structure you need]\n As dimension increases, things start to get pretty lonely pretty fast for a particle.\n The only way to counteract this ``thinning'' is to introduce more structure.\n This is the intuitive basis for the success of gradient-based methods such as MALA\\footnote{Metropolis-adjusted Langevin algorithm} and HMC\\footnote{Hamiltonian (or Hybrid) Monte Carlo.}.\n\\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Take home}\n\\begin{itemize}\n \\item MCMC allows us to make inferences about huge models in Science and Engineering;\n \\item MCMC is a terrible method, which nevertheless is our best shot at computing high-dimensional integrals;\n \\item One has to make sure a CLT holds;\n \\item One has to verify diagnostics to ensure no convergence/performance problems are present;\n \\item No one diagnostic is enough.\n\\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n  \\item[\\faBook] \\cite{Robert2007}, Ch. 6\\footnote{The Bayesian Choice by Christian Robert (2007, 2nd edition).}.\n  \\item[\\faBook] \\url{https://betanalpha.github.io/assets/case_studies/markov_chain_monte_carlo.html}\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "f22d194527ff19769d27e70a0f89508b09ae319e", "size": 6719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_extra.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_extra.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_extra.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": 43.9150326797, "max_line_length": 316, "alphanum_fraction": 0.673016818, "num_tokens": 2064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.8757869965109765, "lm_q1q2_score": 0.6611447193117854}}
{"text": "\\chapter{Numerical Algorithms} \\label{Ch:NumericalAlgorithms}\r\n\r\n\\section{Lagrange Interpolation}\r\n\r\nBelow we describe the algorithm used for lagrange interpolation.\r\nThis includes specifying how points  from the known data are chosen\r\nfor interpolation, and how interpolation is performed for multiple\r\nfunction values (i.e. position and velocity) at the desired\r\ninterpolation point.\r\n\r\nAssume we have $m$ functions to interpolate and that each function\r\nis known at $\\ell$ values of the independent variable $x$ (in\r\nephemeris interpolation this is time) as illustrated in\r\nTable~\\ref{Table:InterpolationData}. Given some point, say $x'$, we\r\ndesire the interpolated values of the functions, or $\\mathbf{f}'\r\n\\approx \\mathbf{P}(x')$ where $P$ is the Lagrange interpolating\r\npolynomial.\r\n\r\n%\r\n\\begin{table}[ht] \\centering\r\n\\caption{Example of Data for interpolation}\r\n \\begin{tabular}{ccccc}  \\hline \\hline\r\n         x & $\\mathbf{f}_1$ & $\\mathbf{f}_2$ & \\dots & $\\mathbf{f}_m$ \\\\ \\hline\r\n         $x_1$ & $f_1(x_1)$ &  $f_2(x_1)$ &  \\dots & $f_m(x_1)$\\\\\r\n         $x_2$ & $f_1(x_2)$ &  $f_2(x_2)$ &  \\dots &$f_m(x_2)$\\\\\r\n         $x_3$ & $f_1(x_3)$ &  $f_2(x_3)$ &  \\dots &$f_m(x_3)$\\\\\r\n         $x_4$ & $f_1(x_4)$ &  $f_2(x_4)$ &  \\dots &$f_m(x_4)$\\\\\r\n         \\vdots   & \\vdots &   \\vdots &  $\\ddots$ & \\vdots\\\\\r\n         $x_{\\ell-1}$ & $f_1(x_{\\ell-1})$ &  $f_2(x_{\\ell-1})$ & \\dots & $f_m(x_{\\ell-1})$\\\\\r\n         $x_{\\ell}$ & $f_1(x_\\ell)$ &  $f_2(x_\\ell)$ & \\dots & $f_m(x_\\ell)$\\\\\r\n         \\hline \\hline\r\n         \\label{Table:InterpolationData}\r\n \\end{tabular}\r\n \\end{table}\r\n %\r\n\r\nBefore proceeding we define the following variables:\r\n%\r\n\\begin{center}\r\n    \\begin{minipage}[t]{5.0 in}\r\n        \\begin{tabbing}[htbp!]\r\n            123456 \\= dummy line \\kill\r\n            $\\mathbf{x}$ \\> $m_x$ x 1 Known values of the independent variable (monotonically increasing or decreasing) \\\\\r\n            $x'$ \\>  Value of independent variable a the required interpolation point\\\\\r\n            $\\mathbf{f}_i$ \\> $m_x$ x $m_f$ Array of dependent variable values for the $i^{th}$ function\\\\\r\n            $\\mathbf{f}'$ \\> 1 x $m_f$ Array of interpolated function values at $x'$\\\\\r\n            $n$ \\> Order of interpolation \\\\\r\n            $m_x$  \\>  Number of points in $\\mathbf{x}$ and $\\mathbf{f}_i$ \\\\\r\n            $m_f$  \\>  Number of functions to be interpolated \\\\\r\n        \\end{tabbing}\r\n    \\end{minipage}\r\n\\end{center}\r\n\r\nFor interpolation to be feasible, several conditions must be\r\nsatisfied.  First, $x'$ must lie between the minimum and maximum\r\nvalue of $\\mathbf{x}$, or at the boundaries ( otherwise we would be\r\nextrapolating ):\r\n%\r\n\\begin{equation}\r\n     x' \\geq \\mbox{min}(\\mathbf{x})\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{equation}\r\n     x' \\leq \\mbox{max}(\\mathbf{x})\r\n\\end{equation}\r\n%\r\nSecond, there must be enough data points in points in $\\mathbf{x}$\r\nto support interpolation to the desired order.  If the requested\r\ninterpolation is of order $n$, then we require $n+1$ data points to\r\nperform the interpolation.  Hence the following criteria must be\r\nmet:\r\n%\r\n\\begin{equation}\r\n    m_x \\geq n + 1\r\n\\end{equation}\r\n%\r\n\r\nIf the requested interpolation is feasible, we must choose the\r\nsubset of $\\mathbf{x}$ to use for interpolating the data at $x'$.\r\nDefine $x(q)$ as the $q^{th}$ element of $\\mathbf{x}$. Given $x'$,\r\nwe choose $q$ to minimize the difference between $x'$ and the mean\r\nof $x(q)$ and $x(q + n)$, or:\r\n%\r\n\\begin{equation}\r\n    \\underset{q}{\\mbox{min }} \\left| \\frac{x(q+n) + x(q)}{2} - x'\\right|  \\hspace{.3 in} ( q \\in 1,2,3,... m_x)\r\n\\end{equation}\r\n%\r\nChoosing $q$ in this way places $x'$ as near to the center of the\r\ninterpolation interval as possible.\r\n\r\nThe standard formula for the Lagrange interpolating polynomial for a\r\nsingle function is\r\n%\r\n\\begin{equation}\r\n    P(x) =  \\sum_{k=1}^n P_j(x) \\label{Eq:LagrangeInterp}\r\n\\end{equation}\r\n%\r\nwhere $P_j(x)$ is given by\r\n%\r\n\\begin{equation}\r\n   P_j(x) = y_j\\prod_{k=1,k \\neq j}^n\\frac{x - x_j}{x_j - x_k} \\label{Eq:LagrangePj}\r\n\\end{equation}\r\n%\r\nLagrange interpolation is an efficient method when interpolating\r\nmultiple data sets available at the same independent variable\r\npoints.  This is due to the fact that the product term in\r\nEq.~(\\ref{Eq:LagrangePj}) is only a function of the values of the\r\nindependent variables and the desired interpolation point and not on\r\nthe function being interpolated.  As a result, we can evaluate the\r\nproduct term one time and use it for many functions (which is what\r\nis done when interpolating an ephemeris file).  The algorithm for\r\nimplementing Lagrangian interpolation for multiple functions is\r\nshown below.\r\n\r\n\\begin{center}\r\n\\begin{minipage}{6 in}\r\n\\begin{small}\r\n\\begin{algorithm}[H]\r\n\r\n    \\KwIn{$\\mathbf{x}, \\mathbf{f},x',q,n$}\r\n    %\r\n    \\KwOut{$\\mathbf{f}'$}\r\n    %\r\n    $\\mathbf{f}' = \\mathbf{0}_{(1 \\mbox{ x } m_f)}$\\;\r\n    %\r\n    \\For{ i = q to $q+n$}\r\n    {\r\n        $\\mathbf{prod} = f(i,:)$ \\% The $i^{th}$ row of $\\mathbf{f}$ \\;\r\n        \\For{ $j = q$ to $q+n$}\r\n        {\r\n            \\If{ $ i \\neq j$}\r\n            {\r\n            \\% The product in Eq.~(\\ref{Eq:LagrangePj})\\;\r\n                    $ \\mathbf{prod} = \\mathbf{prod} \\cdot \\displaystyle\\frac{x' - x(j)}{x(i) - x(j)}$\\;\r\n            }\r\n        }\r\n       \\% The summation in Eq.~(\\ref{Eq:LagrangeInterp})\\;\r\n       $ \\mathbf{f}'= \\mathbf{f}' + \\mathbf{prod}$\\;\r\n    }\r\n    \\hspace{.2 in}\r\n    %\r\n    \\label{alg:LagrangeInterpolation}\\caption{Algorithm for Lagrangian Interpolation}\r\n    %\r\n\\end{algorithm}\r\n\\end{small}\r\n\\end{minipage}\r\n\\end{center}\r\n\r\n\r\n\\section{Quadratic Polynomial Interpolation }\r\n\r\n\r\nWe are given three data points defined by a vector of independent\r\nvariables\r\n%\r\n\\begin{equation}\r\n     \\mathbf{x} = [\\hspace{.05 in} x_1 \\hspace{.05 in} x_2 \\hspace{.05 in}\r\n     x_3 \\hspace{.05\r\n     in}]^T\r\n\\end{equation}\r\n%\r\nand a vector of corresponding dependent variables\r\n%\r\n\\begin{equation}\r\n     \\mathbf{y} = [\\hspace{.05 in} y_1 \\hspace{.05 in} y_2 \\hspace{.05 in}\r\n     y_3  \\hspace{.05\r\n     in}]^T\r\n\\end{equation}\r\n%\r\nwe wish to find a quadratic polynomial that fits the data such that\r\n%\r\n\\begin{equation}\r\n   y = Ax^2 + Bx +C\r\n\\end{equation}\r\n%\r\nWe begin by forming the system of linear equations\r\n%\r\n\\begin{equation}\r\n    \\left(%\r\n    \\begin{array}{ccc}\r\n       x_1^2 & x_1 & 1 \\\\\r\n       x_2^2 & x_2 & 1 \\\\\r\n       x_3^2 & x_3 & 1 \\\\\r\n    \\end{array}%\r\n    \\right)\r\n    %\r\n     \\left(%\r\n    \\begin{array}{ccc}\r\n       A \\\\\r\n       B \\\\\r\n       C \\\\\r\n    \\end{array}%\r\n    \\right)\r\n    =\r\n     \\left(%\r\n    \\begin{array}{ccc}\r\n       y_1 \\\\\r\n       y_2 \\\\\r\n       y_3 \\\\\r\n    \\end{array}%\r\n    \\right)\r\n\\end{equation}\r\n%\r\nWe can solve for the coefficients using\r\n%\r\n\\begin{equation}\r\n    A = \\frac{\r\n    %  Numerator\r\n    \\left|%\r\n    \\begin{array}{ccc}\r\n       y_1 & x_1 & 1 \\\\\r\n       y_2 & x_2 & 1 \\\\\r\n       y_3 & x_3 & 1 \\\\\r\n    \\end{array}%\r\n    \\right|\r\n    }\r\n    %  Denominator\r\n    {    \\left|%\r\n    \\begin{array}{ccc}\r\n       x_1^2 & x_1 & 1 \\\\\r\n       x_2^2 & x_2 & 1 \\\\\r\n       x_3^2 & x_3 & 1 \\\\\r\n    \\end{array}%\r\n    \\right|}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    B = \\frac{\r\n    %  Numerator\r\n    \\left|%\r\n    \\begin{array}{ccc}\r\n     x_1^2 & y_1 & 1 \\\\\r\n     x_2^2 & y_2 & 1 \\\\\r\n     x_3^2 & y_3 & 1 \\\\\r\n    \\end{array}%\r\n    \\right|\r\n    }\r\n    %  Denominator\r\n    {    \\left|%\r\n    \\begin{array}{ccc}\r\n       x_1^2 & x_1 & 1 \\\\\r\n       x_2^2 & x_2 & 1 \\\\\r\n       x_3^2 & x_3 & 1 \\\\\r\n    \\end{array}%\r\n    \\right|}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    C = y_3 - A x_3^2 - B x_3\r\n\\end{equation}\r\n\r\n\\section{Cubic Spline (Not-a-Knot) Interpolation }\r\n\r\nWe are given five data points defined by a vector of independent\r\nvariables\r\n%\r\n\\begin{equation}\r\n     \\mathbf{x} = [\\hspace{.05 in} x_1 \\hspace{.05 in} x_2 \\hspace{.05 in}\r\n     x_3 \\hspace{.05 in} x_4 \\hspace{.05 in} x_5 \\hspace{.05\r\n     in}]^T\r\n\\end{equation}\r\n%\r\nand a vector of corresponding dependent variables\r\n%\r\n\\begin{equation}\r\n     \\mathbf{y} = [\\hspace{.05 in} y_1 \\hspace{.05 in} y_2 \\hspace{.05 in}\r\n     y_3 \\hspace{.05 in} y_4 \\hspace{.05 in} y_5 \\hspace{.05\r\n     in}]^T\r\n\\end{equation}\r\n%\r\nwe wish to find the four cubic polynomials, $i = 1,2,3,4$, such that\r\n%\r\n\\begin{equation}\r\n    p_i = a_i(x - x_i)^3 + b_i(x - x_i)^2 + c_i(x - x_i) + d_i\r\n\\end{equation}\r\n%\r\nwhere the values for $x_i$ are known from the inputs.\r\n\r\nTo calculate the coefficients $a_i$, $b_i$, $c_i$, and $d_i$ we\r\nstart by calculating the eight quantities\r\n%\r\n\\begin{eqnarray}\r\n     h_i      &=& x_{i+1} - x_i\\\\\r\n     \\Delta_i &=& \\displaystyle\\frac{y_{i+1} - y_i}{h_i}\r\n\\end{eqnarray}\r\n%\r\nNext we solve the following system of linear equations\r\n%\r\n\\begin{equation}\r\n     \\mathbf{A}\\mathbf{S} = \\mathbf{B}\r\n\\end{equation}\r\n%\r\nwhere the components of $\\mathbf{A}$ are given by\r\n%\r\n\\begin{eqnarray}\r\n     A_{11} &=& 2h_2 + h_1 \\\\\r\n     A_{12} &=& 2h_1 + h_2 \\\\\r\n     A_{13} &=& 0 \\\\\r\n     A_{21} &=& 0 \\\\\r\n     A_{22} &=& h_3 + 2h_4 \\\\\r\n     A_{23} &=& 2h_3 + h_4 \\\\\r\n     A_{31} &=& \\displaystyle\\frac{h_2^2}{h_1 + h_2} \\\\\r\n     A_{32} &=& \\displaystyle\\frac{h_1h_2}{( h_1 + h_2 )} + 2( h_2 + h_3 ) + \\displaystyle\\frac{h_3h_4}{( h_3 + h_4\r\n     )}\\\\\r\n     A_{33} &=& \\displaystyle\\frac{h_3^2}{h_3 + h_4}\r\n\\end{eqnarray}\r\n%\r\nthe components of $\\mathbf{B}$ are\r\n%\r\n\\begin{eqnarray}\r\n    B_{11} &=& 6( \\Delta_2 - \\Delta_1 )\\\\\r\n    B_{21} &=& 6( \\Delta_4 - \\Delta_3 )\\\\\r\n    B_{31} &=& 6( \\Delta_3 - \\Delta_2 )\r\n\\end{eqnarray}\r\n%\r\nand $\\mathbf{S} = [\\hspace{.05 in} S_1 \\hspace{.05 in} S_3\r\n\\hspace{.05 in} S_5 \\hspace{.05 in}]^T$. We can solve for the\r\ncomponents of $\\mathbf{S}$ using Cramer's Rule as follows\r\n%\r\n\\begin{equation}\r\n    S_1 = \\frac{\r\n    %  Numerator\r\n    \\left|%\r\n    \\begin{array}{ccc}\r\n       B_{11} & A_{12} & A_{13} \\\\\r\n       B_{21} & A_{22} & A_{23} \\\\\r\n       B_{31} & A_{32} & A_{33} \\\\\r\n    \\end{array}%\r\n    \\right|\r\n    }\r\n    %  Denominator\r\n    {\\mathbf{| \\mathbf{A}|}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    S_3 = \\frac{\r\n    %  Numerator\r\n    \\left|%\r\n    \\begin{array}{ccc}\r\n       A_{11} & B_{11} & A_{13} \\\\\r\n       A_{21} & B_{21} & A_{23} \\\\\r\n       A_{31} & B_{31} & A_{33} \\\\\r\n    \\end{array}%\r\n    \\right|\r\n    }\r\n    %  Denominator\r\n    {\\mathbf{| \\mathbf{A}|}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     S_5 = \\frac{B_{31} - A_{31} S_1 - A_{32} S_3}{A_{33}}\r\n\\end{equation}\r\n%\r\nNow we can calculate $S_2$ and $S_4$ using\r\n%\r\n\\begin{equation}\r\n     S_2 = \\frac{ h_2 S_1 + h_1 S_3  }{  h_1 + h_2 };\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     S_4 = \\frac{ h_4 S_3 + h_3 S_5  }{  h_3 + h_4 };\r\n\\end{equation}\r\n%\r\n\r\nFinally, the coefficients for the $i^{th}$ cubic polynomial are\r\ngiven by\r\n\\begin{eqnarray}\r\n   a_i &=&  \\frac{ S_{i+1} - S_i   }{ 6  h_i}\\\\\r\n   b_i &=&  \\frac{S_i}{2}\\\\\r\n   c_i &=&  \\frac{ y_{i+1} - y_i  }{ h_i } - \\frac{ 2 h_i S_i + h_i S_{i+1} }{  6\r\n   }\\\\\r\n   d_i &=&  y_i\r\n\\end{eqnarray}\r\n\r\n\r\n\\section{Root Location using Brent's Method}\r\n\r\nNOTE: The implementation used in GMAT's even locators follows the Algorithm\r\nin Numerical Recipes 3rd edition which slightlyl different than the algorithm presented below.\r\n\r\nBrent's\\cite{Brent:73} method is a root finding algorithm that takes\r\nadvantage of superlinear convergence properties of the secant method\r\nand inverse quadratic interpolation, and the robustness of the\r\nbisection method.  The algorithm is a modification of Dekker's\r\nmethod which combines the bisection method and the secant method\r\n\\cite{Dekker:69}.\r\n\r\nThe algorithm requires as inputs to real numbers that bound the\r\ndesired root.\r\n\r\n\\begin{tabbing}\r\n    12345678912345 \\= Reynolds number based on length $s$ \\kill\r\n    $f$         \\>  Function whose root is desired \\\\\r\n    $a$         \\>  Initial guess for independent variable ($a$ and $b$ must bound the desired root)\\\\\r\n    $b$         \\>  Initial guess for independent variable ($a$ and $b$ must bound the desired root) \\\\\r\n    $tol$     \\>  Convergence tolerance.\\\\\r\n    $N$       \\> Maximum number of iterations \\\\\r\n    $x_o$     \\>  Root value\\\\\r\n    $i$         \\> Number of iterations\\\\\r\n    $\\epsilon$ \\> Machine precision\\\\\r\n\\end{tabbing}\r\n\r\n\\begin{center}\r\n\\begin{minipage}{6 in}\r\n\\begin{small}\r\n\\begin{algorithm}[H]\r\n\r\n    \\KwIn{$f,a,b,tol,N,$}\r\n    %\r\n    \\KwOut{$x_o,i$}\r\n    %\r\n    $f_a = f(a)$; $f_b = f(b)$\\;\r\n    \\textbf{if} $f_a \\cdot f_b > 0$; error and return; \\textbf{end} \\;\r\n    $c = a;$ $f_c = f_a;$ $d = b - a;$ $e = d$\\;\r\n    \\If{ $|f_c| \\leq |f_b|$}\r\n    {\r\n     $a = b;$ $b = c;$ $c = a;$\r\n    $f_a = f_b;$ $f_b = f_c;$ $f_c = f_a;$\r\n    }\r\n    $t = 2\\epsilon | b | + tol$\\;\r\n    $m = 0.5(c - b)$ \\;\r\n    $i = 1$\\;\r\n    \\While{$ | m | >= t$ and $| f_b | >= t$ and $ i \\leq N$}\r\n        {\r\n        \\eIf{ $|e | \\leq t $ or $ |f_a| <  |fb|$}\r\n          {\r\n           $d = m$; $ e = m$\\;\r\n          }{\r\n           $s = f_b/f_a$\\;  % line 40\r\n           \\eIf {$ a = c $}\r\n              {\r\n              $p = 2.0 \\cdot m \\cdot s$\\;\r\n              $q = 1.0 - s$\\;\r\n               }\r\n              {\r\n                $q = f_a/f_c$; $r = f_b/f_c$\\;\r\n                $p = s(2.0 \\cdot m \\cdot q (q-r) - (b - a)(r - 1.0))$\\;\r\n                $q = (q - 1.0)(r - 1.0)(s - 1.0)$\\;\r\n                }\r\n          \\eIf{ $p >= 0.0$ }{ %line 60\r\n            $q = -q$\\;\r\n          }{\r\n            $p = -p$\\;  % line 70\r\n          }\r\n        $s = e$\\;  % line 80\r\n        $e = d$\\;\r\n        \\eIf {($2 \\cdot p < 3.0 \\cdot m \\cdot q- |t\\cdot q|) $ or $ ( p \\leq | 0.5 \\cdot s\\cdot q | )$}\r\n           {\r\n            $d = p/q$\\;\r\n         }{\r\n            $d = m$; $e = m$\\;\r\n         }\r\n       }\r\n       $a  = b$; $f_a = f_b$\\;\r\n       \\eIf { $|d| \\geq  t$ }{\r\n          $b = b + d$;\r\n        }\r\n        {\r\n        \\eIf {$ m \\geq 0.0$ }{\r\n           $ b = b + t$;\r\n        }{\r\n           $ b = b - t$;\r\n         }\r\n        }\r\n       $ f_b = f(b)$\\;\r\n        \\eIf { ( $f_b > 0.0$ and $f_c > 0$ ) or ( $f_b < 0.0$ and $f_c < 0$ )} {\r\n            $c = a;$ $f_c = fa;$ $d = b - a;$ $e = d$\\;\r\n            }\r\n         {\r\n               \\If{ $|f_c| \\leq |f_b|$}\r\n            {\r\n             $a = b;$ $b = c;$ $c = a;$\r\n            $f_a = f_b;$ $f_b = f_c;$ $f_c = f_a;$\r\n            }\r\n                 }\r\n        $t = 2\\epsilon |b| + tol$; % line 3\r\n        $m    = 0.5(c - b)$;\r\n        $ i = i + 1$;\r\n\r\n    }\r\n    $x_o = b$\\;\r\n    \\hspace{.2 in}\r\n    %\r\n    \\label{alg:BrentsMethod}\\caption{Brent's Method for Root Finding}\r\n    %\r\n\\end{algorithm}\r\n\\end{small}\r\n\\end{minipage}\r\n\\end{center}\r\n", "meta": {"hexsha": "44c91f1f5fb946d0e79a858bda5f1ddb4e764052", "size": 14434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/NumericalAlgorithms.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/NumericalAlgorithms.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/NumericalAlgorithms.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": 29.337398374, "max_line_length": 123, "alphanum_fraction": 0.5340861854, "num_tokens": 5211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6610965057828236}}
{"text": "\\documentclass[12pt]{article}\r\n\r\n\\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry} % see geometry.pdf on \r\n\\usepackage{graphicx}\r\n\\usepackage{amssymb,amsmath}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{listings}\r\n\\usepackage{color}\r\n\\geometry{letterpaper}\r\n\\linespread{1.1}% \\geometry{landscape} % rotated page geometry\r\n\r\n\\definecolor{codegreen}{rgb}{0,0.6,0}\r\n\\definecolor{codegray}{rgb}{0.5,0.5,0.5}\r\n\\definecolor{codepurple}{rgb}{0.58,0,0.82}\r\n\\definecolor{backcolour}{rgb}{0.95,0.95,0.92}\r\n\r\n\\lstdefinestyle{mystyle}{\r\n\tbackgroundcolor=\\color{backcolour},   \r\n\tcommentstyle=\\color{codegreen},\r\n\tkeywordstyle=\\color{magenta},\r\n\tnumberstyle=\\tiny\\color{codegray},\r\n\tstringstyle=\\color{codepurple},\r\n\tbasicstyle=\\footnotesize,\r\n\tbreakatwhitespace=false,         \r\n\tbreaklines=true,                 \r\n\tcaptionpos=b,                    \r\n\tkeepspaces=true,                 \r\n\tnumbers=left,                    \r\n\tnumbersep=5pt,                  \r\n\tshowspaces=false,                \r\n\tshowstringspaces=false,\r\n\tshowtabs=false,                  \r\n\ttabsize=2\r\n}\r\n\r\n\\lstset{style=mystyle}\r\n  \r\n\\title{IEOR 160 Course Project}\r\n\\date{20 Oct. 2017} \r\n\\author{Qingan Zhao \\\\ SID: 3033030808}\r\n\r\n\\begin{document}\r\n\r\n\\maketitle\r\n\\newcommand{\\ud}{\\mathrm d} %COMMENT: for infinitesimal dx = \\ud x and dy = \\ud y TODO: DO YOURSELF all replacement\r\n\\renewcommand\\theequation{\\arabic{equation}}\r\n\\renewcommand{\\figurename}{Fig.}\r\n\\renewcommand\\thesection{Problem \\arabic{section}}\r\n\\renewcommand\\thesubsection{\\alph{subsection} )}\r\n\r\n\\begin{large}\r\n\\noindent\\textbf{All plots and relevant code are generated in MATLAB.}\r\n\\end{large}\r\n\r\n\\section{}\r\n\r\nThis problem is solved using Gradient method with the backtracking line search ($\\alpha$ = 1 and $\\beta$ = 0.6).\\\\\r\n\r\n\\noindent Code:\r\n\r\n\\lstinputlisting[language=MATLAB]{P1.m}\r\n\r\n\\bigskip\\noindent The minimum value of the function is \\textbf{2.722814}, where $x$=\\textbf{(0.122218, -0.556434)}.\\\\\r\n\r\n\\noindent The plot of $f(x^{(k)})$ versus $k$ for $k=0,1,2,...,50$ is shown in Figure 1.\\\\\\\\\\\\\r\n\r\n\\begin{figure}[!htbp]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{figures/fig1.eps}      \r\n\t\\caption{$f(x^{(k)})$ versus $k$ for $k=0,1,2,...,50$ (Gradient method)}\r\n\\end{figure}\r\n\r\n\\noindent The trajectory of points $x^{(0)}$, $x^{(1)}$, ..., $x^{(50)}$ is shown in Figure 2.\r\n\r\n\\begin{figure}[!htbp]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{figures/fig2.eps}      \r\n\t\\caption{The trajectory of points $x^{(0)}$, $x^{(1)}$, ..., $x^{(50)}$ (Gradient method)}\r\n\\end{figure}\r\n\r\n\\section{}\r\n\r\nThis problem is solved using Newton's method with the backtracking line search ($\\alpha$ = 1 and $\\beta$ = 0.6).\\\\\r\n\r\n\\noindent Code:\r\n\r\n\\lstinputlisting[language=MATLAB]{P2.m}\r\n\r\n\\bigskip\\noindent The minimum value of the function is \\textbf{2.722814}, where $x$=\\textbf{(0.122219, -0.556434)}.\\\\\r\n\r\n\\noindent The plot of $f(x^{(k)})$ versus $k$ for $k=0,1,2,...,50$ is shown in Figure 3.\r\n\r\n\\begin{figure}[!htbp]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{figures/fig3.eps}      \r\n\t\\caption{$f(x^{(k)})$ versus $k$ for $k=0,1,2,...,50$ (Newton's method)}\r\n\\end{figure}\r\n\r\n\\noindent The trajectory of points $x^{(0)}$, $x^{(1)}$, ..., $x^{(50)}$ is shown in Figure 4.\r\n\r\n\\begin{figure}[!htbp]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{figures/fig4.eps}      \r\n\t\\caption{The trajectory of points $x^{(0)}$, $x^{(1)}$, ..., $x^{(50)}$ (Newton's method)}\r\n\\end{figure}\r\n\r\n\\section{}\r\n\r\nThis problem is solved using Newton's method with the backtracking line search ($\\alpha$ = 0.4 and $\\beta$ = 0.4).\\\\\r\n\r\n\\noindent The function in this problem is much more complex than the previous one. Hence, to speed up the code, let's first calculate the gradient and hessian by hand instead of using $gradient()$ and $hessian()$ functions in MATLAB. Assume the $log()$ in the problem is the logarithm to the base 10.\\\\\r\n\r\n\\noindent Another thing needs to mention is that the code is not efficient enough to run with 500 variables, so let's just run with 100 variables instead.\\\\\r\n\r\n\\noindent Code:\\\\\r\n\r\n\\noindent\\textbf{(1)} The $f$ function (the function in the problem)\r\n\r\n\\lstinputlisting[language=MATLAB]{f.m}\r\n\\ \\\\\r\n\r\n\\bigskip\\noindent\\textbf{(2)}  The gradient function\r\n\r\n\\lstinputlisting[language=MATLAB]{grad_fun.m}\r\n\r\n\\bigskip\\noindent\\textbf{(3)}  The hessian function\r\n\r\n\\lstinputlisting[language=MATLAB]{hess_fun.m}\r\n\r\n\\bigskip\\noindent\\textbf{(4)}  Main script\r\n\r\n\\lstinputlisting[language=MATLAB]{p3.m}\r\n\r\n\\bigskip\\noindent The minimum value of the function is \\textbf{-204.012227.}\\\\\\\\\\\\\r\n\r\n\\noindent The plot of $f(x^{(k)})$ versus $k$ for $k=0,1,2,...,300$ is shown in Figure 5.\r\n\r\n\\begin{figure}[!htbp]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{figures/fig5.eps}      \r\n\t\\caption{$f(x^{(k)})$ versus $k$ for $k=0,1,2,...,300$ (Newton's method)}\r\n\\end{figure}\r\n\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "d50c74d017aead07c1aae1a6d72e05eac773f723", "size": 4833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "solution.tex", "max_stars_repo_name": "QinganZhao/Nonlinear-and-Discrete-Optimization-Course-Project", "max_stars_repo_head_hexsha": "ac7a63bb88172879428a0dc3ca33265991987e76", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-08T02:54:10.000Z", "max_issues_repo_path": "solution.tex", "max_issues_repo_name": "QinganZhao/Nonlinear-and-Discrete-Optimization-Course-Project", "max_issues_repo_head_hexsha": "ac7a63bb88172879428a0dc3ca33265991987e76", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solution.tex", "max_forks_repo_name": "QinganZhao/Nonlinear-and-Discrete-Optimization-Course-Project", "max_forks_repo_head_hexsha": "ac7a63bb88172879428a0dc3ca33265991987e76", "max_forks_repo_licenses": ["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.102739726, "max_line_length": 303, "alphanum_fraction": 0.6602524312, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.6610929090725988}}
{"text": "\\section{Reversal}\n\\label{sec:reversal}\n\n%\\paragraph{Involution} -> Allows a page break because there is no\n% text after \\section.\n\n\\textbf{Involution}\\index{stack!reversal!involution}\\quad Sometimes a\nproof requires some lemma to be devised. Let us consider the\ndefinition of a function\n\\fun{rev\\(_0\\)/1}\\label{def:rev0}\\index{stack!reversal!definition}\\index{rev0@\\fun{rev\\(_0\\)/1}}\nreversing a stack:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n  \\fun{cat}(\\el,t)\\index{cat@\\fun{cat/2}}\n& \\xrightarrow{\\smash{\\alpha}} & t;\n& \\fun{rev}_0(\\el)\n& \\xrightarrow{\\smash{\\gamma}} & \\el;\\\\\n  \\fun{cat}(\\cons{x}{s},t)\n& \\xrightarrow{\\smash{\\beta}} & \\cons{x}{\\fun{cat}(s,t)}.\n& \\fun{rev}_0(\\cons{x}{s})\n& \\xrightarrow{\\smash{\\delta}} & \\fun{cat}(\\fun{rev}_0(s),[x]).\n\\end{array}\n\\end{equation*}\nAn evaluation is shown with abstract syntax trees in\n\\fig~\\ref{fig:rev0_321}.\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[bb=69 620 328 721]{rev0_321_0}\n\\includegraphics[bb=64 626 320 721]{rev0_321_1}\n\\includegraphics[bb=69 627 375 721]{rev0_321_2}\n\\includegraphics[bb=69 627 375 721]{rev0_321_3}\n\\caption{\\(\\fun{rev}_0([3,2,1]) \\twoheadrightarrow [1,2,3]\\)\n\\label{fig:rev0_321}\\index{stack!reversal!example}}\n\\end{figure}\nLet \\(\\pred{Inv}{s}\\)\\index{Inv@\\predName{Inv}|(} be the property\n\\(\\fun{rev}_0(\\fun{rev}_0(s)) \\equiv s\\), that is, the function\n\\fun{rev\\(_0\\)/1}\\index{rev0@\\fun{rev\\(_0\\)/1}} is an\n\\emph{involution}\\index{stack!reversal!involution}. In order to prove\n\\(\\forall s \\in S.\\pred{Inv}{s}\\), the induction principle on the\nstructure of~\\(s\\)\\index{induction!example|(} requires that we\nestablish\n\\begin{itemize*}\n\n  \\item the basis \\(\\pred{Inv}{\\el}\\);\n\n  \\item the inductive step \\(\\forall s \\in S.\\pred{Inv}{s}\n    \\Rightarrow \\forall x \\in T.\\pred{Inv}{\\cons{x}{s}}\\).\n\n\\end{itemize*}\nThe basis is quickly found: \\(\\fun{rev}_0(\\fun{rev}_0(\\el))\n\\xrightarrow{\\smash{\\gamma}} \\fun{rev}_0(\\el)\n\\xrightarrow{\\smash{\\gamma}} \\el\\). The induction hypothesis is\n\\(\\pred{Inv}{s}\\) and we want to establish\n\\(\\pred{Inv}{\\cons{x}{s}}\\)\\index{Inv@\\predName{Inv}|)}, for\nany~\\(x\\). If we commence head\\hyp{}on with\n\\(\\fun{rev}_0(\\fun{rev}_0(\\cons{x}{s})) \\xrightarrow{\\smash{\\delta}}\n\\fun{rev}_0(\\fun{cat}(\\fun{rev}_0(s),[x]))\\), we are stuck. But the\nterm to rewrite involves both \\fun{rev$_0$/1} and \\fun{cat/2}, hence\nspurring us to conceive a lemma where the stumbling pattern\n\\(\\fun{cat}(\\fun{rev}_0(\\dots),\\dots)\\) occurs and is equivalent to a\nsimpler term.\\par\\vskip\\baselineskip\n\nLet\n\\(\\pred{CatRev}{s,t}\\)\\index{CatRev@\\predName{CatRev}} \\label{CatRev}\ndenote \\(\\fun{cat}(\\fun{rev}_0(t),\\fun{rev}_0(s)) \\equiv\n\\fun{rev}_0(\\fun{cat}(s,t))\\)\\index{cat@\\fun{cat/2}}. In order to\nprove it by induction on the structure of~\\(s\\), we need, for\nall~\\(t\\),\n\\begin{itemize*}\n\n  \\item the basis \\(\\pred{CatRev}{\\el,t}\\);\n\n  \\item the inductive step \\(\\forall s,t \\in S.\\pred{CatRev}{s,t}\n    \\Rightarrow \\forall x \\in T.\\pred{CatRev}{\\cons{x}{s},t}\\).\n\n\\end{itemize*}\nThe former is almost within reach:\n\\begin{align*}\n  \\fun{rev}_0(\\fun{cat}(\\el,t))\n  & \\smashedrightarrow{\\alpha}\n  \\fun{rev}_0(t)\\\\\n  & \\leftrightsquigarrow \\fun{cat}(\\fun{rev}_0(t),\\el)\\\\\n  & \\smashedleftarrow{\\gamma}\n    \\fun{cat}(\\fun{rev}_0(t),\\fun{rev}_0(\\el)).\n\\end{align*}\nThe missing part is filled by showing that\n\\((\\leftrightsquigarrow)\\)~is actually~\\((\\equiv)\\).\\par\\vskip\\baselineskip\n\nLet \\(\\pred{CatNil}{s}\\)\\index{CatNil@\\predName{CatNil}|(} be the\nproperty \\(\\fun{cat}(s,\\el) \\equiv s\\)\\index{cat@\\fun{cat/2}}. In\norder to prove it by induction on the structure of~\\(s\\), we have to\nprove\n\\begin{itemize}\n\n  \\item the basis \\(\\pred{CatNil}{\\el}\\);\n\n  \\item the inductive step \\(\\forall s \\in S.\\pred{CatNil}{s}\n    \\Rightarrow \\forall x \\in T.\\pred{CatNil}{\\cons{x}{s}}\\).\n\n\\end{itemize}\nThe former is easy: \\(\\fun{cat}(\\el,\\el) \\xrightarrow{\\smash{\\alpha}}\n\\el\\)\\index{cat@\\fun{cat/2}}. The latter is not complicated either:\n\\(\\fun{cat}(\\cons{x}{s},\\el) \\xrightarrow{\\smash{\\beta}}\n\\cons{x}{\\fun{cat}(s,\\el)} \\equiv \\cons{x}{s}\\), where the equivalence\nis none other than the induction hypothesis\n\\(\\pred{CatNil}{s}\\)\\index{CatNil@\\predName{CatNil}|)}.\\hfill\\(\\Box\\)\n\n%% Note that we could have proved instead \\(\\fun{cat}(s,\\el)\n%% \\twoheadrightarrow s\\), for all values~\\(s\\). The difference is that\n%% \\(\\pred{CatNil}{s}\\) holds even if~\\(s\\) is not a value, as all we\n%% have to do is to replace \\(\\fun{cat}(\\cons{x}{s},\\el)\n%% \\xrightarrow{\\smash{\\beta}} \\cons{x}{\\fun{cat}(s,\\el)}\\) by the\n%% equivalence \\(\\fun{cat}(\\cons{x}{s},\\el) \\Rra{\\beta}\n%% \\cons{x}{\\fun{cat}(s,\\el)}\\). This principle will hold in all our\n%% proofs: we assume that variables denote values and, if not, we simply\n%% change \\((\\xrightarrow{\\smash{\\beta}})\\) into \\((\\Rra{\\beta})\\), for\n%% all rules~\\(\\beta\\) in the proof. Our assumption perhaps improves\n%% legibility.\\par\\vskip\\baselineskip\n\n\\par\\vskip\\baselineskip\n\n\\noindent Assuming\n\\(\\pred{CatRev}{s,t}\\)\\index{CatRev@\\predName{CatRev}}, we must\nestablish \\(\\forall x \\in T.\\pred{CatRev}{\\cons{x}{s},t}\\):\n\\index{cat@\\fun{cat/2}|(} \\index{rev0@\\fun{rev\\(_0\\)/1}|(}\n\\index{CatAssoc@\\predName{CatAssoc}}\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\;\\;}r@{}}\n  \\fun{cat}(\\fun{rev}_0(t),\\fun{rev}_0(\\cons{x}{s}))\n& \\xrightarrow{\\smash{\\delta}}\n& \\fun{cat}(\\fun{rev}_0(t),\\fun{cat}(\\fun{rev}_0(s),[x]))\\\\\n& \\equiv\n& \\fun{cat}(\\fun{cat}(\\fun{rev}_0(t),\\fun{rev}_0(s)),[x])\n& (\\predName{CatAssoc})\\\\\n& \\equiv\n& \\fun{cat}(\\fun{rev}_0(\\fun{cat}(s,t)),[x])\n& (\\pred{CatRev}{s,t})\\\\\n& \\xleftarrow{\\smash{\\delta}}\n& \\fun{rev}_0(\\cons{x}{\\fun{cat}(s,t)})\\\\\n& \\xleftarrow{\\smash{\\beta}}\n& \\fun{rev}_0(\\fun{cat}(\\cons{x}{s},t)).\n& \\multicolumn{1}{r@{}}{\\Box}\n\\end{array}\n\\end{equation*}\nLet us resume the proof of\n\\(\\pred{Inv}{\\cons{x}{s}}\\):\\index{Inv@\\predName{Inv}}\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\quad}r@{}}\n  \\fun{rev}_0(\\fun{rev}_0(\\cons{x}{s}))\n& \\xrightarrow{\\smash{\\delta}}\n& \\fun{rev}_0(\\fun{cat}(\\fun{rev}_0(s),[x]))\\\\\n& \\equiv\n& \\fun{cat}(\\fun{rev}_0([x]),\\fun{rev}_0(\\fun{rev}_0(s)))\n& (\\pred{CatRev}{\\fun{rev}_0(s),[x]})\\\\\n& \\equiv\n& \\fun{cat}(\\fun{rev}_0([x]),s)\n& (\\pred{Inv}{s})\\\\\n& \\xrightarrow{\\smash{\\delta}}\n& \\fun{cat}(\\fun{cat}(\\fun{rev}_0(\\el),[x]),s)\\\\\n& \\xrightarrow{\\smash{\\gamma}}\n& \\fun{cat}(\\fun{cat}(\\el,[x]),s)\\\\\n& \\xrightarrow{\\smash{\\alpha}}\n& \\fun{cat}([x],s)\\\\\n& \\xrightarrow{\\smash{\\beta}}\n& \\cons{x}{\\fun{cat}(\\el,s)}\\\\\n& \\xrightarrow{\\smash{\\alpha}} &\n\\cons{x}{s}.\n& \\hfill\\Box\n\\end{array}\n\\end{equation*}\n\\index{rev0@\\fun{rev\\(_0\\)/1}|)}\\index{cat@\\fun{cat/2}|)}\n\\index{CatRev@\\predName{CatRev}}\n\n\\paragraph{Equivalence}\n\nWe may have two definitions meant to describe the same function, which\ndiffer in complexity and/or efficiency. For instance,\n\\fun{rev\\(_0\\)/1}\\index{rev0@\\fun{rev\\(_0\\)/1}} was given an intuitive\ndefinition, as we can clearly see in rule~\\(\\delta\\) that the\nitem~\\(x\\), which is the top of the input, is intended to be located\nat the bottom of the output. Unfortunately, this definition is\ncomputationally inefficient, that is, it leads to a great deal of\nrewrites relatively to the size of the input.\n\nLet us assume that we also have an efficient definition for the stack\nreversal, named \\fun{rev/1}\\index{rev@\\fun{rev/1}}, which depends upon\nan auxiliary function\n\\fun{rcat/2}\\index{rcat@\\fun{rcat/2}|(}\\index{stack!reversal!$\\sim$\n  and catenation}\\index{stack!reversal!efficient $\\sim$}\n(\\emph{reverse and catenate}):\n\\begin{equation}\n  \\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n    \\fun{rev}(s) & \\smashedrightarrow{\\epsilon} & \\fun{rcat}(s,\\el).\\\\\n    \\fun{rcat}(\\el,t) & \\smashedrightarrow{\\zeta} & t;\\\\\n    \\fun{rcat}(\\cons{x}{s},t) & \\smashedrightarrow{\\eta} &\n    \\fun{rcat}(s,\\cons{x}{t}).\n  \\end{array}\n  \\label{def:rev}\n\\end{equation}\nAn additional parameter introduced by \\fun{rcat/2} accumulates partial\nresults, thus called an \\emph{accumulator}\\index{functional\n  language!accumulator}. We can see it at work in\n\\fig~\\vref{fig:rev_321}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{rev}([3,2,1])\n& \\xrightarrow{\\smash{\\epsilon}} & \\fun{rcat}([3,2,1],\\el)\\\\\n& \\xrightarrow{\\smash{\\eta}}     & \\fun{rcat}([2,1],[3])\\\\\n& \\xrightarrow{\\smash{\\eta}}     & \\fun{rcat}([1],[2,3])\\\\\n& \\xrightarrow{\\smash{\\eta}}     & \\fun{rcat}(\\el,[1,2,3])\\\\\n& \\xrightarrow{\\smash{\\zeta}}    & [1,2,3].\n\\end{array}}\n\\end{equation*}\n\\caption{\\(\\fun{rev}([3,2,1]) \\twoheadrightarrow [1,2,3]\\)\n\\label{fig:rev_321}\\index{stack!reversal!example}}\n\\end{figure}\n\\index{rcat@\\fun{rcat/2}|)}\n\nLet us prove\\label{EqRev} \\(\\pred{EqRev}{s} \\colon\n\\fun{rev}_0(s) \\equiv\n\\fun{rev}(s)\\)\\index{rev@\\fun{rev/1}|(}\\index{EqRev@\\predName{EqRev}|(}\nby\nstructural\\index{stack!reversal!equivalence}\\index{equivalence!proof\n  of $\\sim$} induction on~\\(s\\), namely,\n\\begin{itemize}\n\n  \\item the basis \\(\\pred{EqRev}{\\el}\\);\n\n  \\item the inductive step \\(\\forall s \\in S.\\pred{EqRev}{s}\n    \\Rightarrow \\forall x \\in T.\\pred{EqRev}{\\cons{x}{s}}\\).\n\n\\end{itemize}\nThe former is easy: \\(\\fun{rev}_0(\\el) \\xrightarrow{\\smash{\\gamma}}\n\\el \\xleftarrow{\\smash{\\zeta}} \\fun{rcat}(\\el,\\el)\n\\xleftarrow{\\smash{\\epsilon}}\n\\fun{rev}(\\el)\\)\\index{rev0@\\fun{rev\\(_0\\)/1}}.\n\nFor the latter, let us rewrite \\(\\fun{rev}_0(\\cons{x}{s})\\) and\n\\(\\fun{rev}(\\cons{x}{s})\\) so they converge:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{}}\n  \\fun{rev}_0(\\cons{x}{s})\n& \\xrightarrow{\\smash{\\delta}}\n& \\fun{cat}(\\fun{rev}_0(s),[x])\\\\\n& \\equiv\n& \\fun{cat}(\\fun{rev}(s),[x])\n& (\\pred{EqRev}{s})\\\\\n& \\leftrightsquigarrow\n& \\fun{rcat}(s,[x])\n& (\\text{to be determined})\\\\\n& \\xleftarrow{\\smash{\\eta}}\n& \\fun{rcat}(\\cons{x}{s},\\el)\\\\\n& \\xleftarrow{\\smash{\\epsilon}}\n& \\fun{rev}(\\cons{x}{s}).\n\\end{array}\n\\end{equation*}\nThe missing part is filled by showing \\((\\leftrightsquigarrow)\\) to\nbe~\\((\\equiv)\\) as follows.\\index{rev@\\fun{rev/1}|)}\n\n\\par\\vskip\\baselineskip\n\nLet\n\\(\\pred{RevCat}{s,t}\\)\\index{RevCat@\\predName{RevCat}}\\label{RevCat}\nbe the property \\(\\fun{rcat}(s,t) \\equiv\n\\fun{cat}(\\fun{rev}(s),t)\\).\\index{rcat@\\fun{rcat/2}}\\index{cat@\\fun{cat/2}|(}\\index{rev@\\fun{rev/1}}\nInduction on the structure of~\\(s\\) requires the proofs of\n\\begin{itemize}\n\n  \\item the basis \\(\\forall t \\in S.\\pred{RevCat}{\\el,t}\\);\n\n  \\item the general case \\(\\forall s,t \\in S.\\pred{RevCat}{s,t}\n    \\Rightarrow \\forall x \\in T.\\pred{RevCat}{\\cons{x}{s},t}\\).\n\n\\end{itemize}\nFirst, for the establishment of the basis, we have:\n\\begin{align*}\n  \\fun{rcat}(\\el,t)\n  & \\smashedrightarrow{\\zeta} t\\\\\n  & \\smashedleftarrow{\\alpha} \\fun{cat}(\\el,t)\\\\\n  & \\smashedleftarrow{\\zeta} \\fun{cat}(\\fun{rcat}(\\el,\\el),t)\\\\\n  & \\smashedleftarrow{\\epsilon} \\fun{cat}(\\fun{rev}(\\el),t).\n\\end{align*}\nNext, let us assume \\(\\pred{RevCat}{s,t}\\) and prove \\(\\forall x \\in\nT.\\pred{RevCat}{\\cons{x}{s},t}\\):\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{}r@{}}\n  \\fun{rcat}(\\cons{x}{s},t)\n& \\xrightarrow{\\smash{\\eta}}\n& \\fun{rcat}(s,\\cons{x}{t})\\\\\n& \\equiv\n& \\fun{cat}(\\fun{rev}(s),\\cons{x}{t})\n& (\\pred{RevCat}{s,\\cons{x}{t}})\\\\\n& \\xleftarrow{\\smash{\\alpha}}\n& \\fun{cat}(\\fun{rev}(s),\\cons{x}{\\fun{cat}(\\el,t)})\\\\\n& \\xleftarrow{\\smash{\\beta}}\n& \\fun{cat}(\\fun{rev}(s),\\fun{cat}([x],t))\\\\\n& \\equiv\n& \\fun{cat}(\\fun{cat}(\\fun{rev}(s),[x]),t)\n& (\\pred{CatAssoc}{\\fun{rev}(s),[x],t})\\\\\n& \\equiv\n& \\fun{cat}(\\fun{rcat}(s,[x]),t)\n& (\\pred{RevCat}{s,[x]})\\\\\n& \\xleftarrow{\\smash{\\eta}}\n& \\fun{cat}(\\fun{rcat}(\\cons{x}{s},\\el),t)\\\\\n& \\xleftarrow{\\smash{\\epsilon}}\n& \\fun{cat}(\\fun{rev}(\\cons{x}{s}),t).\n& \\multicolumn{1}{r@{}}{\\Box}\n\\end{array}\n\\end{equation*}\nFinally, we proved \\(\\forall s.\\pred{EqRev}{s}\\), that is,\n\\(\\fun{rev/1} =\n\\fun{rev\\(_0\\)/1}\\)\\index{EqRev@\\predName{EqRev}|)}\\index{rev@\\fun{rev/1}}\\index{rev0@\\fun{rev\\(_0\\)/1}}\\index{cat@\\fun{cat/2}|)}\\index{induction!example|)}.\\hfill\\(\\Box\\)\n\n\\paragraph{Cost}\n\\label{cost:rev0}\n\\index{stack!reversal!cost}\n\nThe definition of \\fun{rev\\(_0\\)/1}\\index{rev0@\\fun{rev\\(_0\\)/1}}\ndirectly leads to the recurrences\\index{rev0@$\\C{\\fun{rev}_0}{n}$}\n\\begin{equation*}\n\\C{\\fun{rev}_0}{0} = 1,\\qquad \\C{\\fun{rev}_0}{k+1} = 1 +\n\\C{\\fun{rev}_0}{k} + \\C{\\fun{cat}}{k} = \\C{\\fun{rev}_0}{k} + k + 2,\n\\end{equation*}\nbecause the length of \\(\\fun{rev}_0(s)\\) is~\\(k\\) if the length\nof~\\(s\\) is~\\(k\\), and we already know \\(\\C{\\fun{cat}}{k} = k +\n1\\)\\index{cat@$\\C{\\fun{cat}}{n}$} (page~\\pageref{cost:cat}). We have\n\\begin{equation*}\n\\sum_{k=0}^{n-1}(\\C{\\fun{rev}_0}{k+1} - \\C{\\fun{rev}_0}{k}) =\n\\C{\\fun{rev}_0}{n} - \\C{\\fun{rev}_0}{0} =\n\\sum_{k=0}^{n-1}(k+2) = 2n + \\sum_{k=0}^{n-1}{k}.\n\\end{equation*}\nThe remaining sum is a classic of algebra:\n\\begin{equation*}\n2 \\cdot \\sum_{k=0}^{n-1}{k} =\n\\sum_{k=0}^{n-1}{k} + \\sum_{k=0}^{n-1}{k} =\n\\sum_{k=0}^{n-1}{k} + \\sum_{k=0}^{n-1}(n-k-1) = n(n-1).\n\\end{equation*}\nConsequently,\n\\begin{equation}\n\\sum_{k=0}^{n-1}{k} = \\frac{n(n-1)}{2},\\label{eq:sum_k}\n\\end{equation}\nand we can finally conclude\n\\begin{equation*}\n\\C{\\fun{rev}_0}{n} = \\frac{1}{2}n^2 + \\frac{3}{2}n + 1 \\sim \\frac{1}{2}n^2.\n\\end{equation*}\nAnother way to reach the result is to induce an \\emph{evaluation\n  trace}\\index{functional language!evaluation!trace}. A trace is a\ncomposition of rewrite rules, noted using the mathematical convention\nfor multiplication. From \\fig~\\vref{fig:rev0_321}, we draw the trace\n\\(\\T{\\fun{rev}_0}{n}\\)\\index{trace_rev0@$\\T{\\fun{rev}_0}{n}$} of the\nevaluation of \\(\\fun{rev}_0(s)\\)\\index{rev0@\\fun{rev\\(_0\\)/1}}, where\n\\(n\\)~is the length of~\\(s\\):\n\\begin{equation*}\n\\T{\\fun{rev}_0}{n} :=\n\\delta^n\\gamma\\alpha(\\beta\\alpha)\\dots(\\beta^{n-1}\\alpha) =\n\\delta^n\\gamma \\prod_{k=0}^{n-1}{\\beta^k\\alpha}.\n\\end{equation*}\nIf we note\n\\(\\len{\\T{\\fun{rev}_0}{n}}\\)\\index{trace_rev0@$\\T{\\fun{rev}_0}{n}$}\nthe length of~\\(\\T{\\fun{rev}_0}{n}\\), that is, the number of rule\napplications it contains, we expect to have the equations \\(\\len{x} =\n1\\), for a rule~\\(x\\), and \\(\\len{x \\cdot y} = \\len{x} + \\len{y}\\),\nfor rules \\(x\\)~and~\\(y\\). By definition of the\ncost:\\index{rev0@$\\C{\\fun{rev}_0}{n}$}\n\\begin{align*}\n\\C{\\fun{rev}_0}{n}\n  &:= \\len{\\T{\\fun{rev}_0}{n}}\n    = \\left\\lvert\\delta^n\\gamma\n        \\prod_{k=0}^{n-1}{\\beta^k\\alpha}\\right\\lvert\n    = \\len{\\delta^n\\gamma} + \\sum_{k=0}^{n-1}\\len{\\beta^k\\alpha}\\\\\n   &= (n+1) + \\sum_{k=0}^{n-1}(k+1) = (n+1) + \\sum_{k=1}^{n+1}k\n    = \\frac{1}{2}n^2 + \\frac{3}{2}n + 1.\n\\end{align*}\nThe reason for this inefficiency can be seen in the fact that\nrule~\\clause{\\delta} produces a series of calls to\n\\fun{cat/2}\\index{cat@\\fun{cat/2}} following the pattern\n\\begin{equation}\n\\fun{rev}_0(s) \\twoheadrightarrow \\fun{cat}(\\fun{cat}(\\dots\n\\fun{cat}(\\el, [x_n]), \\dots, [x_2]), [x_1]),\n\\label{eq:rev0}\n\\end{equation}\nwhere \\(s = [x_1, x_2, \\dots, x_n]\\). The cost of all these calls to\n\\fun{cat/2}\\index{cat@\\fun{cat/2}} is thus\n\\begin{equation*}\n\\abovedisplayskip=4pt\n\\belowdisplayskip=4pt\n 1 + 2 + \\dots + (n-1) = \\tfrac{1}{2}n(n-1) \\sim\n\\tfrac{1}{2}n^2,\n\\end{equation*}\nbecause the cost of \\(\\fun{cat}(s,t)\\)\\index{cat@\\fun{cat/2}} is \\(1 +\n\\fun{len}(s)\\), where\n\\begin{equation}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{len}(\\el) & \\xrightarrow{\\smash{a}} & 0;\\\\\n\\fun{len}(\\cons{x}{s}) & \\xrightarrow{\\smash{b}} & 1 + \\fun{len}(s).\n\\label{eq:len}\n\\end{array}\n\\end{equation}\nThe problem is not calling \\fun{cat/2}, but the fact that the calls\nare embedded in the most unfavourable configuration. Indeed, we proved\nthe associativity\\index{stack!catenation!associativity} of\n\\fun{cat/2}\\index{cat@\\fun{cat/2}} \\vpageref{proof:assoc_cat}, to wit,\n\\(\\fun{cat}(\\fun{cat}(s,t),u) \\equiv\n\\fun{cat}(s,\\fun{cat}(t,u))\\).\n\n\\par\\vskip\\baselineskip\n\nLet \\(\\Call{f(x)}\\) be the cost of the call \\(f(x)\\). Then\n\\begin{align*}\n\\Call{\\fun{cat}(\\fun{cat}(s,t),u)}\n  &= (\\fun{len}(s) + 1) + (\\fun{len}(\\fun{cat}(s,t)) + 1)\\\\\n  &= (\\fun{len}(s) + 1) + (\\fun{len}(s) + \\fun{len}(t) + 1) & (\\pred{LenCat}{s,t})\\\\\n  &= 2 \\cdot \\fun{len}(s) + \\fun{len}(t) + 2,\n\\end{align*}\nassuming \\(\\pred{LenCat}{s,t} \\colon \\fun{len}(\\fun{cat}(s,t)) =\n\\fun{len}(s) + \\fun{len}(t)\\). On the other hand:\n\\begin{align*}\n  \\Call{\\fun{cat}(s,\\fun{cat}(t,u))}\n  &= (\\fun{len}(t) + 1) + (\\fun{len}(s) + 1)\\\\\n  &= \\fun{len}(s) + \\fun{len}(t) + 2.\n\\end{align*}\nFrom which we conclude:\n\\begin{equation}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n\\Call{\\fun{cat}(\\fun{cat}(s,t),u)} = \\fun{len}(s) +\n\\Call{\\fun{cat}(s,\\fun{cat}(t,u))}.\n\\label{ineq:cat_assoc}\n\\end{equation}\nThe items of~\\(s\\) are being traversed twice, although one visit\nsuffices.\n\nYet another way to determine the cost of \\fun{rev\\(_0\\)/1} consists in\nfirst guessing that it is \\emph{quadratic}\\index{cost!quadratic\n  $\\sim$}, that is, \\(\\C{\\fun{rev}_0}{n} = an^2 + bn +\nc\\)\\index{rev0@$\\C{\\fun{rev}_0}{n}$}, where \\(a\\), \\(b\\) and~\\(c\\) are\nunknowns.  Since there are three coefficients, we only need three\nvalues of~\\(\\C{\\fun{rev}_0}{n}\\) to determine them, for instance\n\\(n=0, 1, 2\\). Making some traces, we find \\(\\C{\\fun{rev}_0}{0} = 1\\),\n\\(\\C{\\fun{rev}_0}{1} = 3\\) and \\(\\C{\\fun{rev}_0}{2} = 6\\), so we solve\n\\begin{equation*}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n\\C{\\fun{rev}_0}{0} = c = 1,\\quad\n\\C{\\fun{rev}_0}{1} = a + b + c = 3,\\quad\n\\C{\\fun{rev}_0}{2} = a \\cdot 2^2 + b \\cdot 2 + c = 6.\n\\end{equation*}\nWe draw \\(a = \\myfrac1/2\\), \\(b = \\myfrac3/2\\) and~\\(c = 1\\), that is\n\\(\\C{\\fun{rev}_0}{n} = (n^2 + 3n +\n2)/2\\)\\index{rev0@$\\C{\\fun{rev}_0}{n}$}. Since the assumption about\nthe quadratic behaviour could have been wrong, it is then important to\ntry other values with the newly found formula, for instance\n\\(\\C{\\fun{rev}_0}{4} = (4+1)(4+2)/2 = 15\\), then compare with the cost\nof \\(\\fun{rev}_0([1,2,3,4])\\)\\index{rev0@$\\C{\\fun{rev}_0}{n}$}, for\nexample. Here, the contents of the stack is irrelevant, only its\nlength matters.\n\nAfter finding a formula for the cost using the empirical method above,\nit is necessary to prove it for all values of~\\(n\\). Since the initial\nequations are recurrent, the proof method of choice is\n\\emph{induction}.\n\nLet \\(\\pred{Quad}{n}\\)\\index{Quad@\\predName{Quad}} be the property\n\\(\\C{\\fun{rev}_0}{n} = (n^2 + 3n + 2)/2\\). We already checked its\nvalidity for some small values, here, \\(n = 0, 1, 2\\). Let us suppose\nit is valid for some value of~\\(n\\) (induction hypothesis) and let us\nprove \\(\\pred{Quad}{n+1}\\). We already know \\(\\C{\\fun{rev}_0}{n+1} =\n\\C{\\fun{rev}_0}{n} + n + 2\\)\\index{rev0@$\\C{\\fun{rev}_0}{n}$}. The\ninduction hypothesis implies\n\\begin{equation*}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n\\C{\\fun{rev}_0}{n+1} = (n^2 + 3n + 2)/2 + n + 2\n                     = ((n+1)^2 + 3(n+1) + 2)/2,\n\\end{equation*}\nwhich is \\(\\pred{Quad}{n+1}\\)\\index{Quad@\\predName{Quad}}. Therefore,\nthe induction principle says that the cost we found experimentally is\nalways correct.\n\nTo draw the cost of \\fun{rev/1}\\index{rev@\\fun{rev/1}}, it is\nsufficient to notice that the first argument of\n\\fun{rcat/2}\\index{rcat@\\fun{rcat/2}} strictly decreases at each\nrewrite, so an evaluation trace has the shape \\(\\epsilon\\eta^n\\zeta\\),\nso \\(\\C{\\fun{rev}}{n} = n + 2\\). The cost is\n\\emph{linear}\\index{cost!linear $\\sim$}, so\n\\fun{rev/1}\\index{rev@\\fun{rev/1}} must be used instead of\n\\fun{rev\\(_0\\)/1}\\index{rev0@\\fun{rev\\(_0\\)/1}} in all contexts.\n\n%\\newpage\n\\paragraph{Exercises}\n\n\\begin{enumerate}\n\n  \\item Prove \\(\\pred{LenRev}{s} \\colon \\fun{len}(\\fun{rev}_0(s)) \\equiv\n  \\fun{len}(s)\\).\n\n  \\item Prove \\(\\pred{LenCat}{s,t} \\colon \\fun{len}(\\fun{cat}(s,t)) \\equiv\n  \\fun{len}(s) + \\fun{len}(t)\\).\n\n  \\item What is wrong with the proof of involution of\n  \\fun{rev/1}\\index{rev@\\fun{rev/1}} in section~3.4.9 of the book of\n  \\cite{CousineauMauny_1998}?\n\n\\end{enumerate}\n", "meta": {"hexsha": "80fcfec9523a7faaf5d3cb24ac141bff803edaa9", "size": 19551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reversal.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": "reversal.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": "reversal.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.4106090373, "max_line_length": 171, "alphanum_fraction": 0.6323973198, "num_tokens": 7888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.6610928990546696}}
{"text": "The goal of $\\beta_0$ is to capture the expansion of a displaced fluid\nelement due to the stratification of the atmosphere.  \\maestro\\ computes\n$\\beta_0$ as:\n\\begin{equation}\\label{eq:beta_0}\n\\beta_0(r,t) = \\rho_0 \\exp\\left (  \\int_0^r  \\frac{1}{\\gammabar p_0} \\frac{\\partial p_0}{\\partial r^\\prime} dr^\\prime \\right )\n\\end{equation}\n\n\\section{Constant Composition}\nConsider an isentropically stratified atmosphere, with a constant\ncomposition as a function of $r$.  If you displace a parcel of fluid\nupwards, it will expand adabatically and continue to rise until its\ndensity matches the background density.  Even if $\\gammabar$ is not\nconstant in $r$, following from the definition of $\\beta_0$,\n\\begin{equation}\n\\frac{1}{\\beta_0} \\frac{d\\beta_0}{dr} = \\frac{1}{\\gammabar p_0} \\frac{dp_0}{dr}\n\\end{equation}\nand the definition of $\\Gamma_1$,\n\\begin{equation}\n\\Gamma_1 = \\left . \\frac{d \\log p}{d \\log \\rho} \\right |_s\n\\end{equation}\nSo, at constant entropy, from the definition of $\\Gamma_1$, it must hold\nthat\n\\begin{equation}\n\\frac{1}{\\rho} \\frac{d \\rho}{dr} = \\frac{1}{\\Gamma_1 p} \\frac{d p}{dz} \\enskip .\n\\end{equation}\nComparing to the defintion of $\\beta_0$ then\n\\begin{equation}\n\\frac{1}{\\beta_0} \\frac{\\beta_0}{dr} =\\frac{1}{\\gammabar p_0}\\frac{dp_0}{dr} = \\frac{1}{\\rho_0} \\frac{d\\rho_0}{dr}  \\enskip .\n\\end{equation}\nTherefore, $\\beta_0 = \\rho_0$.  \n\nThis means that if we have a constant composition and an\nisentropically stratified atmosphere, as we displace a fluid element,\nit will always remain neutrally buoyant.\n\n\n\n\\section{Composition Gradient}\n\nIf there is a change in composition with $r$, the situation is more\ncomplicated.  Consider again an isentropically stratified atmosphere,\nnow with a composition gradient.  If you displace a parcel of fluid\nupwards, it will rise.  If there are no processes that change the\ncomposition (e.g.\\ reactions), then the composition in the fluid\nelement will remain fixed.  As it rises, it will the ambient medium\nwill have a different composition that it has.  In this case, what is\nthe path to equilibrium?\n\n\\section{On the Effect of Chemical Potential}\n\\label{Sec:On the Affect of Chemical Potential}\n\nIn \\maestro, we do things in an operator split fashion --- the hydro is\nde-coupled from the burning.  This means that during the hydro parts\nof the algorithm (where $\\beta_0$ is used), the system is fixed in\nchemical equilibrium. For completeness, however, here we describe the\neffects of the species' chemical potentials, which were neglected in\nthe original derivation of $\\beta_0$.  Note that similar terms appear\nin the calculation of things such as specific heats,\nwhich \\textit{may} be important in the burning step --- there appears to\nbe very little about this in the literature, but everyone seems to\nassume it makes little difference.\n\n\\subsection{Derivation of $\\alpha$}\n\\label{Sec:Derivation of alpha}\nIn paper I, $\\alpha$ is defined as\n\\begin{equation}\\label{eq:alpha}\n\\alpha\\equiv -\\left(\n\\frac{(1-\\rho h_p)p_T-\\rho c_p}{\\rho^2c_pp_\\rho}\\right)\n\\end{equation}\nwhere \n\\[\nh_p \\equiv \\left(\\frac{\\partial h}{\\partial p}\\right)_{T,X}, \\quad\nc_p \\equiv \\left(\\frac{\\partial h}{\\partial T}\\right)_{p,X}, \\quad\np_T \\equiv \\left(\\frac{\\partial p}{\\partial T}\\right)_{\\rho,X}, \\quad\np_\\rho \\equiv \\left(\\frac{\\partial p}{\\partial \\rho}\\right)_{T,X}\n\\]\nwhere the subscript $X$ means holding all $X_i$ constant.  In the\nabsence of reactions, the $X$ subscript can be dropped from all\nderivatives and with the use of the equation of state $p=p(\\rho,T)$,\n$\\alpha$ can be written as $\\alpha=\\alpha(\\rho,T)$.  Such a system\nwithout reactions and in thermal equilibrium could be either a pure\nsystem of one species, or a system of many species in chemical (and\ntherefore \\emph{thermodynamic}) equilibrium.  Cox and Giuli (hereafter\nCG) call the former type of system a ``simple system'' and therefore\nthe latter a ``non-simple system'' in chemical equilibrium.  The\nanalysis in paper I that reduced \\eqref{eq:alpha} to\n\\begin{equation}\\label{eq:alpha_simp_no_rxn} \n\\alpha = \\frac{1}{\\Gamma_1p_0} \n\\end{equation} \nused CG's discussion of the various adiabatic $\\Gamma$'s.  However,\ntheir discussion only pertains to ``simple systems'' or ``non-simple\nsystems'' in chemical equilibrium.  In general, nuclear reactions will\nbe important and therefore this analysis needs to be reformed.\n\nEven in the presence of reactions, \\eqref{eq:alpha} can be rewritten\nas was done in paper I:\n\\begin{equation}\\label{eq:alpha2}\n\\alpha = -\\frac{1}{p\\chi_\\rho c_p}\\left[\\left(\\frac{1}{\\rho\\chi_\\rho}\n- \\frac{\\rho e_\\rho}{p\\chi_\\rho}\\right)\\frac{p\\chi_T}{T} - c_p\\right],\n\\end{equation}\nwhere\n\\begin{align*}\n\\chi_{\\rho} &\\equiv \\left(\\frac{\\partial\\ln p}{\\partial\\ln\\rho}\n\\right)_{T,X} \\\\\n\\chi_{T} &\\equiv \\left(\\frac{\\partial\\ln p}{\\partial\\ln T}\n\\right)_{\\rho,X}.\n\\end{align*}\nFollowing the results of paper I, we want to find a relation\nbetween $p\\chi_\\rho$ and $\\Gamma_1$.\n\nFor an equation of state $p=p(\\rho,T,X)$ we have\n\\[\nd\\ln p = \\left(\\frac{\\partial\\ln p}{\\partial\\ln\\rho}\\right)_{T,X}d\\ln\\rho +\n\\left(\\frac{\\partial\\ln p}{\\partial\\ln T}\\right)_{\\rho,X}d\\ln T +\n\\sum_i\\left(\\frac{\\partial\\ln p}{\\partial\\ln X_i}\\right)_{\\rho,T,(X_j,j\n\\neq i)} d\\ln X_i.\n\\]\nWe define another logarithmic derivative\n\\begin{align*}\n\\chi_{X_{i}} &\\equiv \\left(\\frac{\\partial\\ln p}{\\partial\\ln X_i}\n\\right)_{\\rho,T,(X_j,j\\neq i)}\n\\end{align*}\nand therefore\n\\[\nd\\ln p = \\chi_\\rho \\ d\\ln\\rho + \\chi_T \\ d\\ln T + \\sum_i \\chi_{X_i}\\ \nd\\ln X_i.\n\\]\nFrom here we get the general statement \n\\[\n\\frac{\\partial\\ln p}{\\partial \\ln \\rho} = \\chi_\\rho + \n\\chi_T\\frac{\\partial \\ln T}{\\partial\\ln \\rho} +\n\\sum_i\\chi_{X_i}\\frac{\\partial\\ln X_i}{\\partial\\ln \\rho}\n\\]\nwhich must hold for an adiabatic process as well, and therefore we have\n\\begin{equation}\\label{eq:gamma1}\n  \\Gamma_1 = \\chi_\\rho + \\chi_T\\left(\\Gamma_3-1\\right) \n  + \\sum_i\\chi_{X_i}\\Gamma_{4,i}\n\\end{equation}\nwhere we use CG's definition of $\\Gamma_1$ and $\\Gamma_3$ and introduce a \nfourth gamma function:\n\\[\n\\Gamma_1 \\equiv \\left(\n\\frac{\\partial \\ln p}{\\partial \\ln \\rho}\\right)_{\\text{AD}},\\quad\n\\Gamma_3-1\\equiv \\left(\n\\frac{\\partial \\ln T}{\\partial \\ln \\rho}\\right)_{\\text{AD}},\\quad\n\\Gamma_{4,i}\\equiv \\left(\n\\frac{\\partial\\ln X_i}{\\partial\\ln\\rho}\\right)_{\\text{AD}},\n\\]\nwhere the subscript AD means along an adiabat.  We now derive an expression\nfor $\\Gamma_3$.\n  \nThe first law of thermodynamics can be written as\n\\[\ndQ = dE + pdV - \\sum_i\\mu_idN_i\n\\]\nwhere $\\mu_i=\\left(\n\\frac{\\partial E}{\\partial N_i}\\right)_{\\text{AD},\\rho,(N_j,j\\neq i)}$ is\nthe chemical potential; or per unit mass we have\n\\begin{align*}\n  dq &= de - \\frac{p}{\\rho^2}d\\rho - \\sum_i\\mu_id\n  \\left(\\frac{n_i}{\\rho}\\right)\\\\\n  &= de - \\frac{p}{\\rho^2}d\\rho - \\sum_i\n  \\left(\n  \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}dX_i\n\\end{align*}\nwhere we have used $X_i \\equiv \\rho_i/\\rho = A_in_i/\\rho N_\\text{A}$ \nand the chemical potential has been replaced with \n$\\mu_i = \\frac{A_i}{N_\\text{A}}\\left(\\frac{\\partial e}{\\partial X_i}\n  \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}$.\nUsing this and expressing the specific internal energy as $e=e(\\rho,T,X)$ \nwe then have\n\\[\ndq = c_vdT +\n\\left[\\left(\\frac{\\partial e}{\\partial \\rho}\\right)_{T,X} -\\frac{p}{\\rho^2}\n  \\right]d\\rho + \n\\sum_i\\left[\n  \\left(\\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,T,(X_j,j\\neq i)} -\n  \\left(\\frac{\\partial e}{\\partial X_i}\n  \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\\right]dX_i\n\\]\nand\n\\begin{align}\\label{eq:gamma3_first}\n\\left(\\frac{d\\ln T}{d\\ln\\rho}\\right)_\\text{AD} \\equiv \\Gamma_3-1\n&= \\frac{1}{c_vT}\\left[\n\\frac{p}{\\rho} - \\left(\\frac{\\partial e}{\\partial\\ln\\rho}\\right)_{T,X} + \n\\right.{}\\nonumber\\\\\n&\\qquad\\qquad  \\left.\\sum_i \\left[\n    \\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)} \n    - \n    \\left(\\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,T,(X_j,j\\neq i)}\n    \\right]X_i\\Gamma_{4,i}\\right]\n\\end{align}\n\nNow we need to evaluate $\\left(\\partial e/\\partial \\ln\\rho\\right)_{T,X}$.\nAgain using the first law and the fact that $ds=dq/T$ is an exact \ndifferential (i.e. mixed derivatives are equal) we have\n\\begin{align}\\label{eq:dedlnrho}\n  \\left(\n  \\frac{\\partial}{\\partial\\rho}\\left[\\frac{c_v}{T}\\right]\\right)_{T,X} &=\n  \\left(\\frac{\\partial}{\\partial T}\\left[\\frac{1}{T}\n    \\left(\\frac{\\partial e}{\\partial\\rho}\\right)_{T,X} - \\frac{p}{T\\rho^2}\n    \\right]\\right)_{\\rho,X}{}\\nonumber\\\\\n  \\frac{1}{T}\\left(\\frac{\\partial}{\\partial\\rho}\\left(\n  \\frac{\\partial e}{\\partial T}\\right)_{\\rho,X}\\right)_{T,X} &=\n  -\\frac{1}{T^2}\\left(\\frac{\\partial e}{\\partial\\rho}\\right)_{T,X} +\n  \\frac{1}{T}\\left(\\frac{\\partial}{\\partial T}\\left(\n  \\frac{\\partial e}{\\partial\\rho}\\right)_{T,X}\\right)_{\\rho,X}\n  +\\frac{p}{T^2\\rho^2} - \n  \\frac{1}{T\\rho^2}\\left(\\frac{\\partial p}{\\partial T}\\right)_{\\rho,X}\n  {}\\nonumber\\\\\n  \\therefore\\quad \\left(\\frac{\\partial e}{\\partial\\ln \\rho}\\right)_{T,X} &=\n  \\frac{p}{\\rho}\\left(1-\\chi_T\\right),\n\\end{align}\nexactly the same result if we were to exclude species information.\nSimlarly, we can find an expression for the derivative of energy with \nrespect to composition\n\\begin{align*}\n  \\left(\\frac{\\partial}{\\partial X_i}\\left[\n    \\frac{c_v}{T}\\right]\\right)_{\\rho,T,(X_j,j\\neq i)} &=\n  \\left(\\frac{\\partial}{\\partial T}\\left[\n    \\frac{1}{T}\\left(\\frac{\\partial e}{\\partial X_i}\n      \\right)_{\\rho,T,(X_j,j\\neq i)} - \\frac{1}{T}\\left(\n      \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right]\\right)_{\\rho,X}\\\\\n  \\frac{1}{T}\\left(\\frac{\\partial }{\\partial X_i}\\left(\n  \\frac{\\partial e}{\\partial T}\\right)_{\\rho,X}\\right)_{\\rho,T,(X_j,j\\neq i)}\n  &= \\frac{1}{T^2}\\left[\\left(\\frac{\\partial e}{\\partial X_i}\n    \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)} - \n    \\left(\\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,T,(X_j,j\\neq i)}\n    \\right] + \\\\\n  &\\ \\ \\ \\ \\ \\frac{1}{T}\\left[\n    \\left(\\frac{\\partial}{\\partial T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,T,(X_j,j\\neq i)}\n    \\right)_{\\rho,X} - \n    \\left(\\frac{\\partial }{\\partial T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right)_{\\rho,X}\\right]\\\\\n  \\therefore\\quad \n  \\left(\\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,T,(X_j,j\\neq i)} &=\n  \\left(\\frac{\\partial e}{\\partial X_i}\n  \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)} - \\left(\n  \\frac{\\partial}{\\partial\\ln T}\\left(\n  \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n  \\right)_{\\rho,X}.\n\\end{align*}\nPlugging these back into \\eqref{eq:gamma3_first} we have\n\\begin{equation}\\label{eq:gamma3_second}\n  \\Gamma_3-1 = \\frac{1}{c_vT}\\left[\\frac{p}{\\rho}\\chi_T +\\sum_i\n    \\left(\\frac{\\partial}{\\partial\\ln T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right)_{\\rho,X}X_i\n    \\Gamma_{4,i}\\right],\n\\end{equation}\nor\n\\begin{equation}\\label{eq:cv}\n  c_v = \\frac{1}{T(\\Gamma_3-1)}\\left[\\frac{p}{\\rho}\\chi_T +\\sum_i\n    \\left(\\frac{\\partial}{\\partial\\ln T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right)_{\\rho,X}X_i\n    \\Gamma_{4,i}\\right].\n\\end{equation}\n\nWe can obtain an expression for the specific heat at constant pressure \nfrom the enthalpy\n\\begin{align*}\n  c_p \\equiv \\left(\\frac{\\partial h}{\\partial T}\\right)_{p,X} &=\n  \\left(\\frac{\\partial e}{\\partial T}\\right)_{p,X} - \\frac{p}{\\rho^2}\n  \\left(\\frac{\\partial \\rho}{\\partial T}\\right)_{p,X}\\\\\n  &= \\left(\\frac{\\partial e}{\\partial T}\\right)_{p,X} + \\frac{p}{\\rho^2}\n  \\left(\\frac{\\partial p}{\\partial T}\\right)_{\\rho,X}\n  \\left(\\frac{\\partial \\rho}{\\partial p}\\right)_{T,X}\\\\\n  &=\\left(\\frac{\\partial e}{\\partial T}\\right)_{p,X} + \\frac{p}{\\rho T}\n  \\frac{\\chi_t}{\\chi_\\rho}.\n\\end{align*}\nThe first term on the rhs can be obtained from writing $e=e(p,T,X)$ and\n$p=p(\\rho,T,X)$:\n\\begin{align*}\n  de &= \\left(\\frac{\\partial e}{\\partial p}\\right)_{T,X}dp\n  + \\left(\\frac{\\partial e}{\\partial T}\\right)_{p,X}dT +\n  \\sum_i \\left(\\frac{\\partial e}{\\partial X_i}\\right)_{p,T,(X_j,j\\neq i)}\n  dX_i\\\\\n  dp &= \\left(\\frac{\\partial p}{\\partial \\rho}\\right)_{T,X}d\\rho +\n  \\left(\\frac{\\partial p}{\\partial T}\\right)_{\\rho,X}dT + \\sum_i \n  \\left(\\frac{\\partial p}{\\partial X_i}\\right)_{\\rho,T,(X_j,j\\neq i)}dX_i\\\\\n  \\therefore \\ \\left(\\frac{\\partial e}{\\partial T}\\right)_{\\rho,X} &= \n  \\left(\\frac{\\partial e}{\\partial p}\\right)_{T,X}\n  \\left(\\frac{\\partial p}{\\partial T}\\right)_{\\rho,X} + \n  \\left(\\frac{\\partial e}{\\partial T}\\right)_{p,X}\\\\\n  \\Rightarrow \\ \\left(\\frac{\\partial e}{\\partial T}\\right)_{p,X} &= c_v -\n  \\left(\\frac{\\partial e}{\\partial \\rho}\\right)_{T,X}\n  \\left(\\frac{\\partial \\rho}{\\partial p}\\right)_{T,X}\n  \\left(\\frac{\\partial p}{\\partial T}\\right)_{\\rho,X}\\\\\n  &= c_v - \\frac{p\\chi_T}{\\rho T\\chi_\\rho}\\left(1-\\chi_T\\right)\n\\end{align*}\nand \n\\[\nc_p = \\frac{p}{\\rho T}\\frac{\\chi_T^2}{\\chi_\\rho} + c_v\n\\]\nDividing this by \\eqref{eq:cv} and using the relation between the \n$\\Gamma$'s, \\eqref{eq:gamma1}, we then have\n\\begin{align}\\label{eq:pchirho}\n  \\gamma \\equiv \\frac{c_p}{c_v} &= 1 + \\frac{p(\\Gamma_3-1)}{\\rho }\n  \\frac{\\chi_T^2}{\\chi_\\rho}\\left[\\frac{p}{\\rho}\\chi_T +\\sum_i\n    \\left(\\frac{\\partial}{\\partial\\ln T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right)_{\\rho,X}X_i\n    \\Gamma_{4,i}\\right]^{-1}{}\\nonumber\\\\\n  &= 1 + \\frac{p\\chi_T\\left(\\Gamma_1 - \\chi_\\rho -\n    \\sum_i \\chi_{X_i}\\Gamma_{4,i}\\right)}{p\\chi_\\rho\\chi_T + \\rho\n    \\chi_\\rho\\sum_i \\left(\n    \\frac{\\partial}{\\partial \\ln T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right)_{\\rho,X}X_i\\Gamma_{4,i}}{}\\nonumber\\\\\n  &= \\frac{p\\chi_T\\Gamma_1 + \\sum_i \\left[\\rho\\chi_\\rho\\left(\n    \\frac{\\partial}{\\partial \\ln T}\\left(\\frac{\\partial e}{\\partial X_i}\n    \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\\right)_{\\rho,X}X_i - p\\chi_T\n    \\chi_{X_i}\\right]\\Gamma_{4,i}}{p\\chi_\\rho\\chi_T + \\rho\n    \\chi_\\rho\\sum_i \\left(\n    \\frac{\\partial}{\\partial \\ln T}\\left(\n    \\frac{\\partial e}{\\partial X_i}\\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\n    \\right)_{\\rho,X}X_i\\Gamma_{4,i}}{}\\nonumber\\\\\n  \\Rightarrow p\\chi_\\rho &= \\frac{1}{\\chi_T\\gamma}\\left[p\\chi_T\\Gamma_1 + \n    \\sum_i \\left[\\rho\\chi_\\rho\\left(1-\\gamma\\right)\\left(\n      \\frac{\\partial}{\\partial \\ln T}\\left(\\frac{\\partial e}{\\partial X_i}\n      \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\\right)_{\\rho,X}X_i - p\\chi_T\n      \\chi_{X_i}\\right]\\Gamma_{4,i}\\right].\n\\end{align}\n\nPlugging \\eqref{eq:pchirho} into \\eqref{eq:alpha2} and rewriting the \npartial derivative of $e$ with the help of \\eqref{eq:dedlnrho} we have\n\\begin{align*}\n\\alpha &= -\\frac{1}{p\\chi_\\rho c_p}\\left[\\left(\\frac{1}{\\rho\\chi_\\rho}\n  - \\frac{\\rho e_\\rho}{p\\chi_\\rho}\\right)\\frac{p\\chi_T}{T} - c_p\\right] \\\\\n&=\\frac{\\gamma}{c_p}\\frac{c_p\\chi_T + \\left(\\rho\n  \\left(\\frac{\\partial e}{\\partial\\ln\\rho}\\right)_{T,X}-p\\right)\n  \\frac{\\chi_T^2}{T\\rho\\chi_\\rho}}\n{p\\chi_T\\Gamma_1 + \n    \\sum_i \\left[\\rho\\chi_\\rho\\left(1-\\gamma\\right)\\left(\n      \\frac{\\partial}{\\partial \\ln T}\\left(\\frac{\\partial e}{\\partial X_i}\n      \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\\right)_{\\rho,X}X_i - p\\chi_T\n      \\chi_{X_i}\\right]\\Gamma_{4,i}}\\\\\n&=\\frac{\\gamma}{\\Gamma_1 p c_p}\\left[\\frac{c_p - \\frac{p\\chi_T^2}\n    {T\\rho\\chi_\\rho}}\n  {1 + \\sum_i \\left[\\frac{\\rho\\chi_\\rho}{p\\chi_T}\n      \\left(1-\\gamma\\right)\\left(\n      \\frac{\\partial}{\\partial \\ln T}\\left(\\frac{\\partial e}{\\partial X_i}\n      \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\\right)_{\\rho,X}X_i - \n      \\chi_{X_i}\\right]\\frac{\\Gamma_{4,i}}{\\Gamma_1}}\\right]\\\\\n&=\\left(\\frac{1}{\\Gamma_1p}\\right)\n\\left[1 + \\sum_i \\left[\\frac{\\rho\\chi_\\rho}{p\\chi_T}\n    \\left(1-\\gamma\\right)\\left(\n    \\frac{\\partial}{\\partial \\ln T}\\left(\\frac{\\partial e}{\\partial X_i}\n    \\right)_{\\rho,\\text{AD},(X_j,j\\neq i)}\\right)_{\\rho,X}X_i - \n    \\chi_{X_i}\\right]\\frac{\\Gamma_{4,i}}{\\Gamma_1}\\right]^{-1}\\\\\n\\end{align*}\n\\[\\boxed{\n  \\alpha = \\frac{1}{\\Gamma_1p}\\left[1 + \\sum_i\\left[\\frac{\\rho^2p_\\rho}\n      {pp_T}(1-\\gamma)\\frac{N_\\text{A}}{A_i}\n      \\left(\\frac{\\partial\\mu_i}{\\partial T}\\right)_{\\rho,X}X_i - \n      \\chi_{X_i}\\right]\\frac{\\Gamma_{4,i}}{\\Gamma_1}\\right]^{-1}\n}\n\\]\n\n\\subsection{Recalling Derivation of $\\beta_0$}\n\\label{Recalling Derivation of beta0}\nRecall from paper I that $\\beta_0$ was derived from the equation \n\\begin{equation}\n\\nabla\\cdot\\mathbf{U} + \\alpha\\mathbf{U}\\cdot\\nabla p_0 = \\tilde{S}\n\\end{equation}\nin such a fashion that we ended up with an equation of the form\n\\begin{equation}\\label{eq:beta constraint}\n\\nabla\\cdot\\left(\\beta_0(r)\\mathbf{U}\\right) = \\beta_0\\tilde{S}.\n\\end{equation}\nThe derivation in Appendix B of paper I for a $\\beta_0$ that\nsatisfies \\eqref{eq:beta constraint} automatically assumed $\\alpha\n= \\left(\\Gamma_{1_0}p_0\\right)^{-1}$.  This would have to be modified\nwith the above derivation of $\\alpha$ to be correct in a non-operator\nsplit fashion.\n", "meta": {"hexsha": "194c73ecaea2ebf0da02b9ed3f04e9bd1a30e6bf", "size": 16770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/beta0/beta0.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/beta0/beta0.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/beta0/beta0.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": 44.1315789474, "max_line_length": 126, "alphanum_fraction": 0.6643410853, "num_tokens": 6203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6610599350990793}}
{"text": "\n%\n% section for MDP\n%\n\n\\section{Markov Decision Process}\n\n\\subsection{Definition}\n\nA \\cindex{Markov decision process} (MDP) is a Markov reward process with decisions. It is an environment in which all stated are Markov. It is a tuple $\\langle \\mathcal{S}, \\mathcal{A}, \\mathcal{R}, \\mathcal{P}, \\gamma \\rangle$:\n\n\\begin{itemize}\n\t\\item $\\mathcal{S}$ is a finite set of states.\n\t\\item $\\mathcal{A}$ is a finite set of actions.\n\t\\item $\\mathcal{R}$ is a reward function.\n\t\\item $\\mathcal{P}$ is a state transition probability matrix.\n\t\\item $\\gamma \\in [0,1]$ is a discount factor.\n\\end{itemize}\n\n\\subsection{Goals and Equations}\n\n\\subsubsection{Environment}\n\n\\cindex{environment} has \\cindex{state} $S_t \\in \\mathcal{S}$ and generate \\cindex{reward} $R_{t+1} \\in \\mathbb{R}$. Anything that cannot be changed arbitrarily by the agent is part of environment. The goal of reinforcement learning is to maximize expected value of cumulative sum of received scalar reward.\n\nThe reward signal should be chosen so it will not affect how agent act.\n\n\\subsubsection{Agent}\n\n\\cindex{agent} has \\cindex{action} $A_t \\in \\mathcal{A}(S_t)$ and \\cindex{observation} $O_t$ of state $S_t$. Agent may know everything about how the environment works but still unable to solve problem, such as the Rubik cube puzzle.\n\n\\subsubsection{State and Reward}\n\nThe probability of next state and reward is :\n\\begin{equation}\n\tp(s^\\prime,r|s,a) = \\mathbb{P}\\{S_t=s',R_t=r|S_{t-1}=s,A_{t-1}=a\\}\n\\end{equation}\n\nThe \\cindex{state-transition probabilities} is :\n\\begin{equation}\n\tp(s'|s,a)=P\\{S_t=s'|S_{t-1}=s,A_{t-1} = a \\}=\\sum_{r \\in \\mathbb{R}} p(s',r|s,a)\n\\end{equation}\n\n\n\n\n\nUsually the state and reward probability will be treated as independent, so their formulas are:\n\n\\begin{equation}\n\t\\mathcal{P}_{s,s'}^a = \\mathbb{P}[S_{t+1}=s' | S_t = s, A_t = a]\n\\end{equation}\n\n\n\\begin{equation}\n\t\\mathcal{P}_{s,s'}^{\\pi} = \\sum_{a \\in A(s)} \\pi(a|s) \\mathcal{P}_{s,s'}^a\n\\end{equation}\n\n\n\\begin{equation}\n\t\\mathcal{R}_s^a = \\mathbb{E}[R_{t+1}|S_t =s, A_t=a]\n\\end{equation}\n\n\n\\begin{equation}\n\t\\mathcal{R}_s^\\pi = \\sum_{a \\in A(s)} \\pi(a|s) \\mathcal{R}_s^a\n\\end{equation}\n\n\n\nThe expected reward of state-action pair is:\n\\begin{equation}\n\tr(s,a) = \\mathbb{E}[R_t|S_{t-1}=s,A_{t-1}=a]= \\sum_{r \\in \\mathbb{R}} \\sum_{s' \\in \\mathbf{S}} p(s',r|s,a)\n\\end{equation}\n\n\\subsubsection{Episode}\nAn \\cindex{episode} is an order sequence of $S_0, A_0,R_1,S_1,A_1, \\dots, R_n, S_n$ in MDP. So an \\cindex{episode} will always end.\n\n\\cindex{continuing task} is a list of actions that never terminate.\n\nEpisode task can be converted to continuing task by appending infinite \\cindex{absorbing state}.\n\n\n\\subsubsection{Goal}\nThe \\cindex{expected return} is the sum of rewards in the episode:\n\\begin{equation}\n\tG_t=R_{t+1}+R_{t+2} + R_{t+3} +\\dots + R_T\n\\end{equation}\n\n\\begin{itemize}\n\t\\item \\cindex{terminal state}: $R_T$ \n\t\\item $S$: All non-terminal states\n\t\\item $S^+$: all terminal and non-terminal states\n\\end{itemize}\n\n\n\\cindex{discounted return} for continuing task is defined as:\n\\begin{equation}\n\t\\begin{aligned}\n\t\tG_t&=R_{t+1}+\\gamma R_{t+2} + \\gamma^2 R_{t+3} + \\dots  \\\\\n\t\t&= \\sum_{k=0}^\\infty \\gamma^k R_{t+k_1} \\\\\n\t\t&= R_{t+1} + \\gamma G_{t+1}\n\t\\end{aligned}\n\\end{equation}\n\nwhere $0 \\leq \\gamma \\leq 1$.\n\n\n\\subsubsection{Policy}\n\nA stochastic policy is a probability of selecting next possible action:\n\n\\begin{equation}\n\t\\pi(a|s)=\\mathbb{P}[A_t = a | S_t = s]\n\\end{equation}\n\n\\subsubsection{Value Function}\n\nThe \\cindex{state-value} function $V_\\pi$ for policy $\\pi$ is:\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\tV_{\\pi}(s) &= \\mathbb{E}_{\\pi}[G_t|S_t=s] \\\\\n\t\t&=\\mathbb{E}[R_{t+1} + \\gamma V_{\\pi}(S_{t+1})| S_t = s]\n\t\\end{aligned}\n\\end{equation}\n\nThe \\cindex{action-value} function $q_\\pi$ for policy $\\pi$ is:\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\tq_{\\pi}(s,a) &= \\mathbb{E}_{\\pi}[G_t|S_t=s,A_t=a] \\\\\n\t\t\t\t\t&= \\mathbb{E}[R_{t+1} + \\gamma q_{\\pi}(S_{t+1}, A_{t+1})| S_t = s, A_t = a]\n\t\\end{aligned}\n\\end{equation}\n\n\\subsubsection{Bellman Equation}\n\n\nBellman equation (\\cindex{backup} process) is an expansion of value function:\n\n\\begin{equation}\\label{bellman:v}\n\t\\begin{aligned}\n\t\tV_{\\pi}(s) &= \\sum_{a \\in \\mathcal{A}(s)} \\pi(a|s) q_{\\pi}(s,a) \\\\\n\t\t&= \\sum_{a \\in \\mathcal{A}(s)} \\pi(a|s) \\left( \\mathcal{R}_s^a + \\gamma \\sum_{s' \\in \\mathcal{S}} \\mathcal{P}_{s,s'}^a V(S') \\right)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\tq_{\\pi}(s,a) &= R_s^a + \\gamma \\sum_{s' \\in \\mathcal{S}} \\mathcal{P}_{s,s'}^a V_{\\pi}(s') \\\\\n\t\t&= R_s^a + \\gamma \\sum_{s' \\in \\mathcal{S}} \\mathcal{P}_{s,s'}^a \\left( \\sum_{a', s'} \\pi(a'|s') q_{\\pi}(s',a') \\right )\n\t\\end{aligned}\n\\end{equation}\n\n\n\n\\subsubsection{Bellman Equation Solution}\n\nFormula (\\ref{bellman:v}) is for a single state. Let \n\\begin{equation}\n\tV_{\\pi} = \\left [\\begin{matrix}\n \tV_{\\pi}(s_1) \\\\\n \t\\vdots \\\\\n \tV_{\\pi}(s_n)\n \\end{matrix} \\right ]\n\\end{equation}\n\nFormula (\\ref{bellman:v}) now becomes:\n\n\\begin{equation}\n\t\\mathbf{V}_{\\pi}=\\mathbf{R}^{\\pi} + \\gamma \\mathbf{P}^{\\pi} \\mathbf{V}_{\\pi} \n\\end{equation}\n\nSo the solution to \\cindex{Bellman Equation} is:\n\n\\begin{equation}\n\t\\mathbf{V}_{\\pi}=(\\mathbf{I} - \\gamma \\mathbf{P}^{\\pi})^{-1}\\mathbf{R}^{\\pi}\n\\end{equation}\n\nIt is a fixed point solution to formula (\\ref{bellman:v}).\n\n\\subsection{Optimal Policy}\n\n\\subsubsection{Policy Partial Order}\n\n$\\pi \\geq \\pi^{\\prime}$ if $\\forall s \\in \\mathcal{S}, V_{\\pi} (s) \\geq V_{\\pi^{\\prime}} (s)$ . \n\n\nFor MDP all optimal solution share the same value function $V_*$ and include at least one deterministic policy $\\pi_*$. \n\n\n\\subsubsection{Optimal State-value Function}\n\nThe optimal state-value function $V_*$ is defined as:\n\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\tV_*(s) &= \\underset{\\pi}{\\max} \\ V_{\\pi}(s) \\\\\n\t\t&= \\underset{a}{\\max}\\ q_* (s, a) \\\\\n\t\t&= \\underset{a}{\\max}\\ \\left( \\mathcal{R}_s^a + \\gamma \\sum_{s' \\in \\mathcal{S}} \\mathcal{P}_{s,s'}^a V_*(s') \\right )\n\t\\end{aligned}\n\\end{equation}\n\n\\subsubsection{Optimal Action-value Function}\n\n\nThe optimal action-value function $q_*$ is defined as:\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\tq_*(s,a)&=\\underset{\\pi}{\\max}\\ q_{\\pi}(s,a)\\\\\n\t\t&=\\mathbb{E}[R_{t+1}+\\gamma V_*(S_{t+1})|S_t=s, A_t=a]\\\\\t\t\n\t\t&=\\mathcal{R}_s^a+\\gamma \\sum_{s' \\in \\mathcal{S}} \\mathcal{P}_{s,s'}^a V_*(s')\\\\\n\t\t&=\\mathcal{R}_s^a+\\gamma \\sum_{s' \\in \\mathcal{S}} \\mathcal{P}_{s,s'}^a \\ \\underset{a'}{\\max}\\  q_*(s',a')\n\t\\end{aligned}\n\\end{equation}\n\nHere $\\mathcal{R}_s^a$ is an expectation. In model-free learning and controlling it is the sample return from environment.\n\n\\subsubsection{Optimal Policy from Action Value Function} Once the optimal action value function is known, we can calculate the optimal policy by:\n\n\\begin{equation}\\label{optimal:policy}\n\t\\pi_*(a|s) =\n\t\\begin{cases}\n\t\t1& \\text{, if $a = \\underset{a \\in \\mathcal{A}(s)}{\\text{argmax}}\\ q_*(s,a)$}\\\\\n\t\t0& \\text{, else}\n\t\\end{cases}\n\\end{equation}\n\nSo the optimal policy is a greedy algorithm.\n\nCompared with $V_*$, $q_*$ is better because it does not need to do one step lookahead.\n\n\\subsubsection{Reason for Complex Algorithms}\n\nThere is no closed form for optimal Bellman policy equation, so many iterative solution exists:\n\\begin{itemize}\n\t\\item value iteration\n\t\\item policy iteration\n\t\\item $Q$-learning\n\t\\item Sarsa\n\\end{itemize}\n\n", "meta": {"hexsha": "da85ddf6cb535efe46daaef2133ff5d560df9f5d", "size": 7257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/reinforcement_learning/rl.2.mdp.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.2.mdp.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.2.mdp.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": 29.5, "max_line_length": 307, "alphanum_fraction": 0.6680446465, "num_tokens": 2681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.661059927812457}}
{"text": "The previous chapter began an introduction to the problem of robotic perception, which consists of tasks related to sensing and understanding the robot's own movements as well as the environment in which it operates\\cite{SiegwartNourbakhshEtAl2011}. This chapter continues that discussion by diving more deeply into one of the most powerful and challenging tools in robotic perception: computer vision. In particular, this chapter will focus on some of the fundamental mathematical tools for calibrating cameras and processing their images to extract some useful information about the scene\\cite{ForsythPonce2011}\\cite{HartleyZisserman2002}\\nocite{Tsai1987}.\n\\nocite{Bradski2000}\n\n\\notessection{Camera Models and Calibration}\nAs was discussed in the previous chapter, cameras provide a crucial sensing modality in the context of robotics. This is generally due to the fact that images inherently contain an enormous amount of information about the environment. However, while images do contain a lot of information, extracting the information that is relevant to the robot is quite challenging. One of the most basic tasks related to image processing is determining how a particular point in the scene maps to a point in the camera image, which is sometimes referred to as \\textit{perspective projection}. Last chapter, the \\textit{pinhole camera model} and the \\textit{thin lens model} were presented, and in this chapter the pinhole camera model is leveraged to further explore perspective projection\\footnote{All results also hold under the thin lens model, assuming the camera is focused at $\\infty$.}.\n\n\\begin{figure}[ht]\n\\includegraphics[width=0.8\\textwidth]{tex/figs/ch08_figs/pinholecamera2.png}\n\\centering\n\\caption{Graphical representation of the pinhole camera model. In this model the point $O_C$ is the camera center, $c$ is the image center, and $f$ is the focal length of the camera. It is assumed that all light rays from point $P$ in the scene pass through point $O_C$ and are captured on the image plane at point $p$.}\n\\label{fig:pinhole_cam}\n\\end{figure}\n\n\\subsection{Perspective Projection}\nThe pinhole camera model, shown graphically in Figure \\ref{fig:pinhole_cam}, can be used to mathematically define relationships between points $P$ in the scene and points $p$ on the image plane. Notice that any point $P$ in the scene can represented in two ways: in camera frame coordinates (denoted as $P_C$) or in world frame coordinates (denoted as $P_W$). The overall objective of this section is to find derive a mathematical model that can be used to map a point $P_W$ expressed in world frame coordinates to a point $p$ on the image plane. To accomplish this two transformations are combined together, namely a transformation of $P$ from world frame coordinates to camera frame coordinates ($P_W$ to $P_C$) and a transformation from camera coordinates to image coordinates ($P_C$ to $p$).\n\n\n\\subsubsection{Mapping Camera Frame Coordinates to Image Coordinates ($P_C \\xrightarrow{} p$)}\nThe first step considered is the mapping from a point in the scene expressed in camera frame coordinates, $P_C$, to the corresponding point on the image plane, $p$, using the pinhole camera model. Recall from the previous chapter the pinhole camera equations:\n\\begin{equation} \\label{eq:PC2xy}\n    x=f\\frac{X_C}{Z_C}, \\quad  y = f\\frac{Y_C}{Z_C},\n\\end{equation}\nwhere $P_C = (X_C, Y_C, Z_C)$, $p = (x, y)$, and $f$ is the focal length of the pinhole camera\\footnote{The $z$ term of $p$ is generally not included simply because $z=f$ is a fixed value.}. \n\nNote that the quantities $x$ and $y$ are coordinates in the \\textit{camera frame}, but it is often desirable to express the point $p$ in terms of \\textit{pixel coordinates}. However, pixel coordinates are generally defined with respect to a reference frame in the lower corner of the image plane (to avoid negative coordinates). This new reference frame is shown in Figure \\ref{fig:camera_coordinates}, where the image center $c$ is defined in this new reference frame with coordinates $(\\tilde{x}_0, \\tilde{y}_0)$, where $\\tilde{(\\cdot)}$ is the notation used to denote a coordinate with respect to this new reference frame.\n\\begin{figure}[ht]\n\\includegraphics[width=0.55\\textwidth]{tex/figs/ch08_figs/imageframe.png}\n\\centering\n\\caption{A new reference frame with coordinates denoted by $\\tilde{(\\cdot)}$  is defined with its origin in the lower corner of the image plane. The image center coordinates in this new frame are denoted $(\\tilde{x}_0, \\tilde{y}_0)$.}\n\\label{fig:camera_coordinates}\n\\end{figure}\nIn this new reference frame, the point $P_C$ gets mapped to the coordinates $(\\tilde{x}, \\tilde{y})$ by:\n\\begin{equation} \\label{eq:PC2xtyt}\n    \\tilde{x} = f\\frac{X_C}{Z_C} + \\tilde{x}_0, \\quad  \\tilde{y} = f\\frac{Y_C}{Z_C} + \\tilde{y}_0.\n\\end{equation}\nFinally, these new coordinates can be mapped to pixel coordinates if the number of pixels per unit distance are known. In particular, the point $P_C$ is mapped to pixel coordinates $(u,v)$ by:\n\\begin{equation} \\label{eq:PC2uv}\n   u = \\alpha \\frac{X_C}{Z_C} + u_0, \\quad  v = \\beta \\frac{Y_C}{Z_C} + v_0,\n\\end{equation}\nwhere $\\alpha = k_xf$, $u_0 = k_x \\tilde{x}_0$, $\\beta = k_y f$, $v_0 = k_y \\tilde{y}_0$, and $k_x$ and $k_y$ are the number of pixels per unit distance in image coordinates.\n\n\\paragraph{Homogeneous Coordinates:}\nNote that the transformation from the point $P_C$ in camera frame coordinates to $p$ in pixel coordinates given by \\eqref{eq:PC2uv} is not linear. However, this transformation can be represented as a linear mapping\\footnote{Expressing the perspective projection as a linear map will simplify the mathematics later on.} through an additional change of coordinates. In particular, the points $P_C$ and $p$ will be expressed in \\textit{homogeneous coordinates}.\n\nFor a 2D point $(x_1,x_2)$ or a 3D point $(x_1,x_2,x_3)$ in Euclidean space, the point can be represented in homogeneous coordinates by the transformation:\n\\begin{equation}\n(x_1,\\:x_2) \\implies (\\alpha x_1, \\:\\alpha x_2, \\:\\alpha), \\quad \\text{and} \\quad (x_1,\\:x_2,\\:x_3) \\implies (\\alpha x_1,\\:\\alpha x_2, \\:\\alpha x_3, \\: \\alpha),\n\\end{equation}\nfor any $\\alpha \\neq 0$. These new coordinates are called homogeneous coordinates because the scaling factor $\\alpha$ can be chosen arbitrarily as long as $\\alpha \\neq 0$. A set of homogeneous coordinates can then be transformed back by: \n\\begin{equation}\n(y_1, \\: y_2, \\:y_3) \\implies \\Big(\\frac{y_1}{y_3}, \\: \\frac{y_2}{y_3}\\Big), \\quad \\text{and} \\quad (y_1,\\:y_2,\\:y_3,\\:y_4) \\implies \\Big(\\frac{y_1}{y_4}, \\: \\frac{y_2}{y_4}, \\: \\frac{y_3}{y_4}\\Big).\n\\end{equation}\nTo denote when a point is described in homogeneous coordinates the superscript $h$ will be used. For example, the point $P_C = (X_C, Y_C, Z_C)$ in camera frame coordinates can be expressed by:\n\\begin{equation*}\n    P_C^h = (X_C, Y_C, Z_C, 1),\n\\end{equation*}\nby choosing $\\alpha = 1$, and the point $p = (u,v)$ in pixel coordinates can be expressed in homogeneous coordinates by:\n\\begin{equation*}\n    p^h = (Z_C u, \\: Z_C v, \\:Z_C) = (\\alpha X_C + u_0 Z_C, \\: \\beta Y_C + v_0 Z_C),\n\\end{equation*}\nby choosing $\\alpha = Z_C$ and substituting the expressions \\eqref{eq:PC2uv}. With the expression of these points in homogeneous coordinates it can be seen that their relationship is transformed from the nonlinear relationship \\eqref{eq:PC2uv} to the \\textit{linear} relationship:\n\\begin{equation}\n\\begin{bmatrix}\n\\alpha & 0 & u_{0} & 0 \\\\\n0 & \\beta & v_{0} & 0  \\\\\n0 & 0 & 1 & 0\n\\end{bmatrix}\n\\begin{pmatrix}\nX_{c} \\\\\nY_{c} \\\\\nZ_{c} \\\\\n1\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n\\alpha X_{c} + u_{0}Z_{c} \\\\\n\\beta Y_{c} + v_{0}Z_{c} \\\\\nZ_{c} \\\\\n\\end{pmatrix}.\n\\end{equation}\n\nOften in practice a skewness parameter $\\gamma$ is also added (which generally ends up being close to 0), and this relationship can be written in the more compact form:\n\\begin{equation} \\label{eq:PC2uvhomo}\n    \\begin{bmatrix}\n        K & 0_{3 \\times 1}\n    \\end{bmatrix} P_C^h = p^h, \\quad K = \\begin{bmatrix}\n\\alpha & \\gamma & u_{0} \\\\\n0 & \\beta & v_{0}  \\\\\n0 & 0 & 1\n\\end{bmatrix}.\n\\end{equation}\nThe matrix $K$ defined in \\eqref{eq:PC2uvhomo} is sometimes referred to as the \\textit{camera matrix} or \\textit{matrix of intrinsic parameters}. It is referred to in this way because it contains the five parameters that define the fundamental characteristics of the camera (from the perspective of the pinhole camera model). While these parameters may be specified by the camera manufacturer, they are often extracted by performing a camera calibration.\n\n\n\\subsubsection{Mapping World Coordinates to Camera Coordinates ($P_W \\xrightarrow{} P_C$)}\nRecall from Figure \\ref{fig:pinhole_cam} that a point $P$ in the scene can either be expressed in terms of camera frame coordinates $P_C$ or world frame coordinates $P_W$. While the previous section discussed the use of the pinhole model to map $P_C$ coordinates to pixel coordinates $p$, this section will discuss the mapping between the camera and world frame coordinates of the point $P$ (see Figure \\ref{fig:Pc2Pw}).\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=0.65\\textwidth]{tex/figs/ch08_figs/world2camera.png}\n\\caption{A depiction of the point $P$ expressed either in camera coordinates, $P_C$, or in world frame coordinates, $P_W$. The world frame origin is denoted by $O_W$ and the camera frame origin is denoted by $O_C$.}\n\\label{fig:Pc2Pw}\n\\end{figure}\n\nFrom Figure \\ref{fig:Pc2Pw} it can be seen that $P_C$ can be written as:\n\\begin{equation}\nP_{C} = t + q,\n\\end{equation}\nwhere $t$ is the vector from $O_C$ to $O_W$ expressed in camera frame coordinates and $q$ is the vector from $O_W$ to $P$ expressed in camera frame coordinates. However, the vector $q$ is in fact the same vector as $P_W$, just expressed in different coordinates (i.e. with respect to a different frame). The coordinates can be related by a rotation:\n\\begin{equation}\nq = RP_W,\n\\end{equation}\nwhere R is the rotation matrix relating the camera frame to world frame and is defined as:\n\\begin{equation} \\label{eq:rotmatrix}\nR =\n\\begin{bmatrix}\ni_w \\cdot i & j_w \\cdot i & k_w \\cdot i \\\\\ni_w \\cdot j & j_w \\cdot j & k_w \\cdot j \\\\\ni_w \\cdot k & j_w \\cdot k & k_w \\cdot k\n\\end{bmatrix},\n\\end{equation}\nwhere $i$, $j$, and $k$ are the unit vectors that define the camera frame and $i_w$, $j_w$, and $k_w$ are the unit vectors that define the world frame. To summarize, the point $P_W$ can be mapped to camera frame coordinates $P_C$ as:\n\\begin{equation}\nP_C = t + R P_W,\n\\end{equation}\nwhere $t$ is the vector in camera frame coordinates from $O_C$ to $O_W$ and $R$ is the rotation matrix defined in \\eqref{eq:rotmatrix}.\nSimilar to the previous section, these expressions can also be equivalently expressed for the case where the points $P_W$ and $P_C$ are expressed in homogeneous coordinates:\n\\begin{equation} \\label{eq:Pw2Pchomo}\n\\begin{split}\n\\begin{pmatrix}\n    P_C \\\\ 1\n    \\end{pmatrix} = \\begin{bmatrix}\nR & t \\\\\n0_{1\\times3} & 1\n\\end{bmatrix}\n\\begin{pmatrix}\nP_W \\\\ 1\n\\end{pmatrix}.\n\\end{split}\n\\end{equation}\n\n\n\\subsubsection{Mapping World Frame Coordinates to Image Coordinates ($P_W \\xrightarrow{} p$)}\nThe original objective of perspective projection was to find a way to mathematically relate the position of a point $P$ in world frame coordinates (denoted $P_W$) to the corresponding pixel coordinates $p$ on the image plane. With the relationship \\eqref{eq:Pw2Pchomo} developed for mapping $P_W$ to the camera frame coordinates $P_C$, and the relationship \\eqref{eq:PC2uvhomo} for mapping $P_C$ to pixel coordinates $p$, the direct mapping from $P_W$ to $p$ can now be defined. In particular, simply combining the two transformation together yields:\n\\begin{equation*}\np^h = \\begin{bmatrix}\nK \\quad 0_{3\\times 1}\n\\end{bmatrix}\n\\begin{bmatrix}\nR && t \\\\\n0_{1 \\times 3} && 1\n\\end{bmatrix}\nP_W^h,\n\\end{equation*}\nwhich can then be simplified to:\n\\begin{equation} \\label{eq:Pw2uvhomo}\np^h = K\\begin{bmatrix}\n    R & t\n\\end{bmatrix} P_W^h.\n\\end{equation}\nIn \\eqref{eq:Pw2uvhomo}, $P_W^h$ is the homogeneous coordinate representation of $P_W$ and $p^h$ is the homogeneous coordinate representation of $p$. Additionally, recall that the matrix $K \\in \\mathbb{R}^{3\\times3}$ is the matrix of intrinsic camera parameters, and the matrix $[R \\:\\:\\: t] \\in \\mathbb{R}^{3\\times 4}$ contains \\textit{extrinsic} parameters (i.e. that describe the camera's position and orientation relative the points in the scene). Note that the total number of degrees of freedom is 11, where 5 are from the intrinsic parameters that define $K$, 3 are from the rotation matrix $R$, and 3 are from the position vector $t$.\n\n\\subsection{Camera Calibration: Direct Linear Method}\nBefore the expression \\eqref{eq:Pw2uvhomo} can be used in practice, the camera's intrinsic and extrinsic parameters need to be determined (i.e. $K$, $R$, and $t$). One approach is to use the direct linear transformation method for camera calibration, which requires a set of known correspondences $p_i \\xleftrightarrow[]{} P_{W,i}$ for $i = 1,\\dots,n$.\n\n\\subsubsection{Direct Linear Calibration: Step 1}\nFirst, each corresponding pair of points $p_i = (u_i,v_i)$ and $P_{W,i} = (X_{W,i}, Y_{W,i}, Z_{W,i})$ is written in homogeneous coordinates and the expression \\eqref{eq:Pw2uvhomo} is used to write:\n\\begin{equation} \\label{eq:correspondance}\n    p_i^h = M P_{W,i}^h, \\quad i = 1,....n\n\\end{equation}\nwhere $M = K[R \\:\\:\\: t]$ is referred to as the \\textit{homography}. The first step of the camera calibration process is to use the $n$ correspondences to compute the homography $M$, and then later the intrinsic and extrinsic parameters can be extracted from $M$. To determine $M$, a useful first step is to rewrite $M$ in terms of its rows:\n\\begin{equation}\n    M = \\begin{bmatrix}\n        m_1 \\\\ m_2 \\\\ m_3\n    \\end{bmatrix},\n\\end{equation}\nwhere $m_i \\in \\R^{1 \\times 4}$ is the $i$-th row of $M$. By considering the rows of $M$ individually, the relationship \\eqref{eq:correspondance} can be written as:\n\\begin{equation*}\n    \\begin{bmatrix}\n        \\alpha u_i \\\\ \\alpha v_i \\\\ \\alpha\n    \\end{bmatrix} = \\begin{bmatrix}\n         m_1 \\cdot P_{W,i}^h \\\\ m_2 \\cdot P_{W,i}^h \\\\ m_3 \\cdot P_{W,i}^h \\\\\n    \\end{bmatrix}, \\quad i = 1,....n\n\\end{equation*}\nwhich by mapping the homogeneous coordinates $p_i^h$ back to the original coordinates $p_i$ yields the $2n$ expressions:\n\\begin{equation*}\n\\begin{split}\n    u_i &= \\frac{m_1 \\cdot P_{W,i}^h}{m_3 \\cdot P_{W,i}^h}, \\quad i = 1,\\dots,n \\\\\n    v_i &= \\frac{m_2 \\cdot P_{W,i}^h}{m_3 \\cdot P_{W,i}^h}, \\quad i = 1,\\dots,n,\n\\end{split}\n\\end{equation*}\nor equivalently (via algebraic manipulation) the expressions:\n\\begin{equation}\n\\begin{split}\n    u_i(m_3 \\cdot P_{W,i}^h) - (m_1 \\cdot P_{W,i}^h) &= 0, \\quad i = 1,\\dots,n \\\\\n    v_i(m_3 \\cdot P_{W,i}^h) - (m_2 \\cdot P_{W,i}^h) &= 0, \\quad i = 1,\\dots,n.\n\\end{split}\n\\end{equation}\nNow, these $2n$ equations can be combined together in one large matrix equation:\n\\begin{equation}\n    \\tilde{P}m = 0, \\quad m = \\begin{bmatrix}\n        m_1^\\top  \\\\ m_2^\\top  \\\\ m_3^\\top \n    \\end{bmatrix},\n\\end{equation}\nwhere $m \\in \\R^{12 \\times 1}$ is a vector consisting of the stacked rows of $M$ and $\\tilde{P} \\in \\R^{2n \\times 12}$ is a matrix of \\textit{known} coefficients determined by the quantities $u_i$, $v_i$, and $P^h_{W,i}$. For a more concrete representation of how $\\tilde{P}$ is defined, the first couple rows are given by:\n\\begin{equation} \\label{eq:Pmeq}\n\\tilde{P} =\n     \\begin{bmatrix}\n  -(P_{W,1}^h)^\\top  & 0_{1\\times 4} & u_{1} (P_{W,1}^h)^\\top  \\\\\n  0_{1 \\times 4} & -(P_{W,1}^h)^\\top  & v_{1} (P_{W,1}^h)^\\top   \\\\\n  -(P_{W,2}^h)^\\top  & 0_{1\\times 4} & u_{2} (P_{W,2}^h)^\\top  \\\\\n  \\vdots & \\vdots & \\vdots\n \\end{bmatrix}.\n\\end{equation}\nNote that $n \\geq 6$ (i.e. at least 6 correspondences have been made) is a requirement to ensure that $m$ can be uniquely defined. Ideally, with this sufficient number of correspondences the equation \\eqref{eq:Pmeq} could be directly solved. However, in practice a more robust procedure is to build $\\tilde{P}$ with more than 6 points, which would lead to an overdetermined set of equations that may not have a solution\\footnote{This is particularly true in real-world applications where noise corrupts the data.}! \nTherefore, the determination of $m$ is accomplished by formulation the optimization problem:\n\\begin{equation} \\label{eq:mopt}\n\\begin{split}\n\\underset{m}{\\text{min.}} \\:\\:& \\lVert \\tilde{P} m \\rVert^2, \\\\\n    \\text{s.t.}\\:\\:& \\lVert m \\rVert^2 = 1,\n\\end{split}\n\\end{equation}\nwhere the constraint $\\lVert m \\rVert^2 = 1$ is required to ensure that the optimization problem does not simply choose $m_i=0$ for each $i = 1,\\dots,12$. This optimization problem is called a \\textit{constrained least-squares} problem.\n\n\\begin{example}[Constrained Least-Squares] \\label{ex:constlsq}\n\\theoremstyle{definition}\nThe constrained least squares problem \n\\begin{equation*}\n\\begin{split}\n\\underset{x}{\\text{min.}} \\:\\:& \\lVert A x \\rVert^2, \\\\\n    \\text{s.t.}\\:\\:& \\lVert x \\rVert^2 = 1,\n\\end{split}\n\\end{equation*}\nwith $x\\in \\R^n$ and $A \\in \\R^{m \\times n}$ and $m > n$ is a finite-dimensional optimization problem. Consider the corresponding Lagrangian:\n\\begin{equation*}\nL = x^\\top  A^\\top Ax + \\lambda (1 - x^\\top x),\n\\end{equation*}\nand the necessary optimality conditions:\n\\begin{equation*}\n\\begin{split}\n\\nabla_x L &= 2(A^\\top A - \\lambda I)x = 0, \\\\\n\\nabla_\\lambda L &= 1 - x^\\top x = 0. \\\\\n\\end{split}\n\\end{equation*}\nThe first NOC can be rewritten as $A^\\top A x = \\lambda x$, and therefore any $x$ that satisfies this condition must be an eigenvector of the matrix $A^\\top A$. Additionally, while all the eigenvectors satisfy this condition the minimizer is the eigenvector associated with the smallest eigenvalue.\nThis eigenvector can efficiently be computed by a singular value decomposition of $A = U\\Sigma V^\\top $ and then choosing $m$ to be the column of $V$ associated with the smallest singular value (since $A^\\top A = V\\Sigma^2 V^\\top $).\n\\end{example}\n\n\\subsubsection{Direct Linear Calibration: Step 2}\nOnce the optimization problem \\eqref{eq:mopt} has been solved for $m$ the homography $M$ is completely defined. The next step in the camera calibration process is to extract the intrinsic and extrinsic camera parameters from the matrix $M$. For this section the matrix $M$ is expressed in terms of its columns:\n\\begin{equation*}\nM = \\begin{bmatrix}\n    c_1 & c_2 & c_3 & c_4\n\\end{bmatrix},\n\\end{equation*}\nwhere $c_i$ is the $i$-th column of $M$. It is now possible to factorize $M$ as:\n\\begin{equation}\n    M = K\\begin{bmatrix}\n        R & t\n    \\end{bmatrix},\n\\end{equation}\nby taking the first three columns of $M$ and performing a \\textit{RQ factorization}:\n\\begin{equation}\n\\begin{bmatrix}\n    c_1 & c_2 & c_3\n\\end{bmatrix} = KR,\n\\end{equation}\nwhere $R$ is an orthogonal matrix and $K$ is an upper triangular matrix. Once $K$ is known the vector $t$ can be computed by $t = K^{-1} c_4$.\n\n\\subsubsection{A Flexible Camera Calibration Method (Zhang, 2000):} \\label{subsubsec:zhang}\nThe homography $M$ is defined for a \\textit{specific} set of extrinsic parameters $R$ and $t$. In practice it might be desirable to estimate the camera's intrinsic parameters from $N$ \\textit{different} images from different perspectives (and therefore with $N$ different homographies). In this case the procedure described in \\cite{Zhang2000} can be used to extract the intrinsic parameters $K$. \n\nThis approach begins by assuming that the known points $P_W$ for each individual image lie on a plane. For example the calibration ``scene'' might consist of a pattern (e.g. a checkerboard pattern) on a planar surface. In this case, it can simply be assumed that the world frame origin also lies on this plane such that $Z_W = 0$ for all points on the plane. Since $Z_W = 0$ the relationship between $p^h$ and $P^h_W$ given by \\eqref{eq:Pw2uvhomo} can be simplified to:\n\\begin{equation}\np^h = \\tilde{M} \\tilde{P}_W^h,\n\\end{equation}\nwith\n\\begin{equation}\n    \\tilde{M} = K\\begin{bmatrix}\n    r_1 & r_2 & t\n\\end{bmatrix}, \\quad \\tilde{P}_W^h = \\begin{bmatrix}\n    X_W & Y_W & 1\n\\end{bmatrix}^\\top ,\n\\end{equation}\nwhere $\\tilde{M}$ is the simplified homography matrix, $\\tilde{P}_W^h$ is the simplified position of the point $P$ in world frame written in homogeneous coordinates, and $r_i$ is the $i$-th column of the rotation matrix $R$. Note that the homography matrix $\\tilde{M}$ can still be estimated using the same procedure discussed before.\n\nA set of constraints on the intrinsic parameter matrix $K$ are next identified by writing the homography $\\tilde{M}$ as:\n\\begin{equation*}\n    \\begin{bmatrix}\n        \\tilde{c}_1 & \\tilde{c}_2 & \\tilde{c}_3\n        \\end{bmatrix} = \\begin{bmatrix}\n        Kr_1 & Kr_2 & Kt\n    \\end{bmatrix}.\n\\end{equation*}\nThis relationship, and the knowledge that $r_1$ and $r_2$ are orthonormal, leads to the following constraints:\n\\begin{equation} \\label{eq:zhangconst}\n    \\tilde{c}_1^\\top  B \\tilde{c}_2 = 0, \\quad \\tilde{c}_1^\\top  B \\tilde{c}_1 = \\tilde{c}_2^\\top  B \\tilde{c}_2,\n\\end{equation}\nwhere $B = K^{-\\top}K^{-1} \\in \\R^{3 \\times 3}$ is a \\textit{symmetric} matrix. Solving for the intrinsic camera parameters $K$ can therefore be accomplished by using the constraints \\eqref{eq:zhangconst} to solve for the symmetric matrix $B$, and then to use the definition of $B$ to back out the parameters that define $K$.\n\nSeveral useful tricks can be employed to compute the matrix $B$ from the constraints \\eqref{eq:zhangconst}. The main trick is to notice that even though $B$ consists of nine parameters, since it is symmetric only six parameters are required to fully specify it. Therefore $B \\in \\R^{3\\times 3}$ is reparameterized as a vector $b \\in \\R^6$ as:\n\\begin{equation}\n    b = \\begin{bmatrix}\n        B_{11} & B_{12} & B_{22} & B_{13} & B_{23} & B_{33}\n    \\end{bmatrix}^\\top .\n\\end{equation}\nThis reparameterization is useful because it allows us to rewrite the expression $\\tilde{c}_i^\\top B\\tilde{c}_j$ as:\n\\begin{equation}\n    \\tilde{c}_i^\\top B\\tilde{c}_j = v_{ij}^\\top  b,\n\\end{equation}\nwhere:\n\\begin{equation*}\n\\begin{split}\n   v_{ij} = \\begin{bmatrix}\n        \\tilde{c}_{i1}\\tilde{c}_{j1}, & \\tilde{c}_{i1}\\tilde{c}_{j2}+\\tilde{c}_{i2}\\tilde{c}_{j1}, & \\tilde{c}_{i2}\\tilde{c}_{j2}, & \\tilde{c}_{i3}\\tilde{c}_{j1} + \\tilde{c}_{i1}\\tilde{c}_{j3}, & \\tilde{c}_{i3}\\tilde{c}_{j2} + \\tilde{c}_{i2}\\tilde{c}_{j3}, & \\tilde{c}_{i3}\\tilde{c}_{j3}\n    \\end{bmatrix}^\\top ,\n\\end{split}\n\\end{equation*}\nwhere $\\tilde{c}_{ik}$ is the $k$-th element of the column vector $\\tilde{c}_i$ and $\\tilde{c}_{jk}$ is the $k$-th element of the column vector $\\tilde{c}_j$. With this reparameterization, the constraints \\eqref{eq:zhangconst} can be rewritten as:\n\\begin{equation*}\n\\begin{split}\n\\tilde{c}_1^\\top  B \\tilde{c}_2 = 0 &\\implies v_{12}^\\top b = 0 \\\\\n\\tilde{c}_1^\\top  B \\tilde{c}_1 = \\tilde{c}_2^\\top  B \\tilde{c}_2 &\\implies (v_{11} - v_{22})^\\top  b = 0,\n\\end{split}\n\\end{equation*}\nor by combining them:\n\\begin{equation} \\label{eq:bconst}\n    \\begin{bmatrix}\n        v_{12}^\\top  \\\\ (v_{11} - v_{22})^\\top \n    \\end{bmatrix}b = 0,\n\\end{equation}\nwhich is linear in the unknowns $b$. Importantly, while the homographies $M$ are different for each image, the intrinsic camera parameters (i.e. the vector $b$) are the same! Therefore for $N$ images from the same camera (but with potentially different perspectives) these constraints \\eqref{eq:bconst} can be stacked to give:\n\\begin{equation} \\label{eq:allbconst}\n    Vb = 0,\n\\end{equation}\nwhere $V \\in \\R^{2N \\times 6}$. In the case where the skewness parameter $\\gamma$ is included in $K$ there must be $N \\geq 3$ images in order to specify $B$ uniquely. Similar to how the homography for an image $M$ was computed in the previous section, the vector $b$ will be specified by the solution to the constrained least squares problem:\n\\begin{equation} \\label{eq:bopt}\n\\begin{split}\n\\underset{b}{\\text{min.}} \\:\\:& \\lVert Vb \\rVert^2, \\\\\n    \\text{s.t.}\\:\\:& \\lVert b \\rVert^2 = 1.\n\\end{split}\n\\end{equation}\nOnce $b$ has been determined, the intrinsic camera parameters $K$ can be solved for recalling the definition of $B = K^{-T}K^{-1}$. In particular, the intrinsic parameters are given by:\n\\begin{equation} \\label{eq:B2K}\n\\begin{split}\n    v_0 &= \\frac{B_{12}B_{13} - B_{11}B_{23}}{B_{11}B_{22} - B_{12}^2}, \\\\\n    \\lambda &= B_{33} - \\frac{B_{13}^2 + v_0(B_{12}B_{13} - B_{11}B_{23})}{B_{11}}, \\\\\n    \\alpha &= \\sqrt{\\frac{\\lambda}{B_{11}}}, \\\\\n    \\beta &= \\sqrt{\\frac{\\lambda B_{11}}{B_{11}B_{22} - B_{12}^2}}, \\\\\n    \\gamma &= \\frac{-B_{12}\\alpha^2\\beta}{\\lambda}, \\\\\n    u_0 &= \\frac{\\gamma v_0}{\\beta} - \\frac{B_{13}\\alpha^2}{\\lambda},\n\\end{split}\n\\end{equation}\nwhere $\\lambda$ can be though of as a scaling parameter that accounts for the fact that there are five unknown camera intrinsic parameters but six degrees of freedom in $B$.\n\nOnce the camera intrinsic parameters $K$ have been extracted from this procedure, given any new homography $\\tilde{M}$ the extrinsic parameters can be computed by:\n\\begin{equation}\n\\begin{split}\n    r_1 &= \\frac{K^{-1}\\tilde{c}_1}{\\lVert K^{-1}\\tilde{c}_1 \\rVert}, \\\\\n    r_2 &= \\frac{K^{-1}\\tilde{c}_2}{\\lVert K^{-1}\\tilde{c}_2 \\rVert}, \\\\\n    r_3 &= r_1 \\times r_2, \\\\\n    t &= \\frac{K^{-1}\\tilde{c}_3}{\\lVert K^{-1}\\tilde{c}_1 \\rVert}.\n\\end{split}\n\\end{equation}\nAs one final step, it is noted that the matrix $R$ defined with columns $r_1$, $r_2$, and $r_3$ will not in generally satisfy the properties of a rotation matrix (i.e. orthonormality). One final step to this overall procedure is to correct this issue by finding the rotation matrix that best corresponds to these column vectors. This is accomplished again by optimization, and in particular by formulating the problem:\n\\begin{equation} \\label{eq:Ropt}\n\\begin{split}\n\\underset{R}{\\text{min.}} \\:\\:& \\lVert R - Q \\rVert^2, \\\\\n    \\text{s.t.}\\:\\:& R^\\top R = I,\n\\end{split}\n\\end{equation}\nwhere\n\\begin{equation*}\n    Q = \\begin{bmatrix}\n        r_1 & r_2 & r_3\n    \\end{bmatrix}.\n\\end{equation*}\nThis problem is solved by choosing $R = UV^\\top $ where $U$ and $V$ are defined by the singular value decomposition of $Q = U\\Sigma V^\\top $.\n\n\\subsection{Limitations}\n\n\\subsubsection{Radial Distortion}\nThe pinhole camera model provides a nominal camera model for which it is relatively straightforward to develop a mathematical model of the perspective projection. However, in practice this model is not a perfect representation of the imaging process. One such effect that is not captured by the pinhole model is \\textit{radial distortion}, which is an effect seen in real lenses where either barrel distortion or pincushion distortion will affect the real pixel coordinates. Images showing both barrel and pincushion distortion are provided in Figure \\ref{fig:distortion}.\n\n\\begin{figure}[ht]\n\\includegraphics[width=0.75\\textwidth]{tex/figs/ch08_figs/lensdistortion.png}\n\\centering\n\\caption{Different kinds of radial distortions that are seen in real lenses, which may affect the accuracy of the pinhole camera model.}\n\\label{fig:distortion}\n\\end{figure}\n\nThere are methods that can be used to correct for image distortion. A simple and efficient way is to model the relationship between the ideal pixel coordinates $(u,v)$ and the distorted pixel coordinates $(u_d,v_d)$ as:\n\\begin{equation}\n\\begin{bmatrix}\n    u_d \\\\\n    v_d\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n    u_d \\\\\n    v_d\n\\end{bmatrix}\n(1+kr^2)\n\\begin{bmatrix}\n    u-u_{cd} \\\\\n    v-v_{cd}\n\\end{bmatrix}\n+\n\\begin{bmatrix}\n    u_{cd} \\\\\n    v_{cd}\n\\end{bmatrix}\n\\end{equation}\nwhere $k \\in \\mathbb{R}$ is the radial distortion factor, $(u_{cd}, v_{cd})$ are the pixel coordinates of the image center, and $r^2=(u-u_{cd})^2+(v-v_{cd})^2$ is the square of the distance between the ideal pixel location and the center of distortion.. Note that $k$ differs in different cameras and needs to be pre-determined.\n\n\\subsubsection{Measuring Depth}\nOnce the camera intrinsic and extrinsic parameters $K$, $R$, and $t$ are known it is still not possible to map pixel coordinates to the corresponding point in space. Mathematically this is a result of the matrix $M$ in \\eqref{eq:correspondance} not being invertible, but intuitively this is because the distance along the line of sight from $p$ to $P$ in Figure \\ref{fig:pinhole_cam} can not be determined!\n\nHowever, there are some techniques that can enable depth estimates to be made with a single camera. One approach is known as \\textit{depth from focus}, where several images are taken until the projection of point $P$ is in focus. Based on the thin lens model, when this occurs:\n\\begin{equation*}\n    \\frac{1}{z} + \\frac{1}{Z} = \\frac{1}{f},\n\\end{equation*}\nwhere $f$ is the focal length, $Z$ is the depth of the point $P$ in camera frame, and $z$ is the depth of the image plane in the camera frame when the projection of point $P$ is in focus. Since $f$ and $z$ are known, the depth $Z$ can therefore be computed.\nIf two cameras are used, depth estimation is possible via \\textit{binocular reconstruction} or \\textit{stereo vision}. This approach requires known corresponding pixel coordinates $p$ and $p'$ of each camera, and then uses \\textit{triangulation} to determine the 3D position of the source point $P$ in the scene.\n\n\\subsection{Exercises}\n\\subsubsection{Camera Calibration}\nComplete \\textit{Problem 1: Camera Calibration} located in the online repository:\n\n\\vspace{\\baselineskip}\n\n\\url{https://github.com/PrinciplesofRobotAutonomy/AA274A_HW3},\n\n\\vspace{\\baselineskip}\n\nwhere you will estimate the intrinsic parameters of a camera using the method described in Section \\ref{subsubsec:zhang}.\n", "meta": {"hexsha": "2f20097cd222607cc003345730b5b895dbd966c8", "size": 29690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch08.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/ch08.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/ch08.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": 68.0963302752, "max_line_length": 880, "alphanum_fraction": 0.7217581677, "num_tokens": 9129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6610154358894635}}
{"text": "\\documentclass[a4paper,14pt]{article}\n\\title{Tensor Products of Vector Spaces}\n\\usepackage{amsmath, amssymb, amsthm}\n\\usepackage{tikz-cd}\n\\newtheorem*{prop}{Proposition}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem*{remark}{Remark}\n\\newtheorem*{defn}{Definition}\n\\newtheorem*{thm}{Theorem}\n\\begin{document}\n\\maketitle\n\\section{Hom spaces, dual spaces}\nIf $V$ and $W$ are two vector spaces over the same field $\\mathbb{F}$, then the set of all linear maps $T: V \\to W$ is denoted by $Hom(V, W)$. Under the usual definition of function addition and scalar multiplication, $Hom(V, W)$ is a vector space.\n\nSince any field $\\mathbb{F}$ can be considered as a vector space over itself, we can in particular form the space $Hom(V, \\mathbb{F})$. This space is called the \\textbf{dual space} of $V$, and will be denoted $V^{\\ast}$.\n\n\\section{Quotient spaces}\nIf $V$ is a vector space over $\\mathbb{F}$ and $W$ is a subspace of $V$, a \\textbf{coset} of $W$ is a set $v + W := \\{v + w : w \\in W\\}$. \n\n\\begin{prop}\nThe collection of cosets is a partition of $V$.\n\\begin{proof}\nIf $z$ is in both $u + W$ and $v + W$, then $u + w_1 = z = v + w_2$, so $v = u + (w_1 - w_2) \\in u + W$. Similarly, $u \\in v + W$. If $y \\in u + W$, then $y - u \\in W$, so $y \\in v + W$. Similarly every $z \\in v + W$ is in $u + W$, so $u + W = v + W$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nFor any vector space $V$ and subspace $W$, you can define addition between cosets and scalar multiplication on cosets such that collection of cosets becomes a vector space over $\\mathbb{F}$.\n\\end{prop}\n\n\\begin{remark}\nThe vector space of cosets of $W$ in $V$ is called the \\textbf{quotient space}, and is denoted $V/W$.\n\\end{remark}\n\n\\begin{prop}\nThe map $\\pi: V \\to V/W$ defined by $v \\mapsto v + W$ is a linear map.\n\\end{prop}\n\n\\begin{remark}\nThe function $\\pi$ is called the \\textbf{canonical map}.\n\\end{remark}\n\n\\begin{prop}\nThe kernel of any linear map $f: V \\to W$ is a subspace of $V$, so $V / ker f$ is a quotient space.\n\\end{prop}\n\n\\begin{thm}\nIf $f: V \\to W$ is linear and $U$ is a subspace of $V$ such that $U \\subseteq ker f$, then there is a unique linear map $\\phi: V / U \\to W$ such that $\\pi ; \\phi = f$, where $\\pi$ is the canonical map.\n\n\\begin{proof}\n    Define $\\phi$ by $v + U \\mapsto vf$. Routine verification shows that it's well-defined, linear and satisfies $\\pi ; \\phi = f$. $\\phi$ is unique because any other candidate $\\psi$ must have $(v + U)\\phi = vf = (v \\pi) \\psi = (v + U) \\psi$, meaning $\\phi = \\psi$.\n\\end{proof}\n\\end{thm}\n\n\\section{Vector space of scalar-valued functions}\n\\begin{prop}\nIf $\\mathbb{F}$ is any field and $X$ is any set, you can form a vector space by considering the collection of all functions $X \\to \\mathbb{F}$. \n\n\\begin{proof}\nIf $f, g: X \\to \\mathbb{F}$, we define addition by $x(f + g) := xf + xg$ and scalar multiplication by $x(\\alpha f) = \\alpha (x f)$. That this is a vector space is a routine verification.\n\\end{proof}\n\\end{prop}\n\n\\begin{remark}\nThis vector space is denoted $\\mathbb{F}^X$.\n\nYou are probably familiar with the vector space $\\mathbb{F}^n$. If you think about it, $\\mathbb{F}^n$ is actually a special case of a space $\\mathbb{F}^X$, where $X = \\{1, \\ldots, n\\}$. The general idea, then, is that a function $X \\to \\mathbb{F}$ is a bag of scalars labeled by elements of $X$ There is exactly one scalar for each label. We can add two bags $B_1$ and $B_2$ of labeled scalars: the result is another bag of labeled scalars where for each label $x \\in X$, the associated scalar is the sum of the scalars labeled by $x$ in $B_1$ and $B_2$. Scalar multiplication of a bag $B$ by $\\alpha$ is just the bag where each scalar in $B$ is multiplied by $\\alpha$.\n\\end{remark}\n\n\\begin{defn}\nA function $f: X \\to \\mathbb{F}$ is said to have \\textbf{finite support} when the set $\\{x \\in X : xf \\neq 0\\}$ is finite.\n\\end{defn}\n\n\\begin{prop}\nThe subset of $\\mathbb{F}^X$ of functions with finite support is a subspace of $\\mathbb{F}^X$.\n\\end{prop}\n\n\\section{Free vector spaces}\n\\begin{defn}\nFor any set $X$, a \\textbf{free vector space} on $X$ with respect to some field $\\mathbb{F}$, is any pair $(V, f)$ where $V$ is a vector space on $\\mathbb{F}$ and $f: X \\to V$ is a function such that for any vector space $W$ over $\\mathbb{F}$ and any function $g: X \\to W$, there is a unique linear map $T: V \\to W$ such that $f;T = g$.\n\nIn other words, for every $W$ and every function $g: X \\to W$ there is a unique linear $T: V \\to W$ such that this diagram commutes:\n\n\\begin{center}\n\\begin{tikzcd}[row sep=large]\n    X \\arrow[rd, \"g\"] \\arrow[r, \"f\"] \n    & V \\arrow[d, dashed, \"\\exists! \\> T\"] \\\\\n                                   & W\n\\end{tikzcd}\n\\end{center}\n\nThis property is called the \"universal property\" for free vector spaces.\n\\end{defn}\n\n\\begin{prop}\n    If a free vector space of a set $X$ over a field $\\mathbb{F}$ exists, it is ``unique up to unique isomorphism'': if $(V, f: X \\to V)$ and $(W, g: X \\to W)$ are free vector spaces for $X$ over $\\mathbb{F}$, there is a unique linear isomorphism $T: V \\to W$ such that $f;T = g$.\n\n\\begin{proof}\n    Since $(V, f)$ is a free vector space, by the universal property there is a linear map $r: V \\to W$ such that $f;r = g$. Similarly there is a linear map $s: W \\to V$ such that $g;s = f$. This implies $g;s;r = g$ and $f;r;s = f$.\n\n\\begin{center}\n\\begin{tikzcd}[row sep=large]\n    & X \\arrow[ld, \"f\"swap] \\arrow[rd, \"g\"] \\\\\n    V \\arrow[rr, yshift=0.7ex, \"r\"] & & W \\arrow[ll, yshift=-0.7ex, \"s\"]\n\\end{tikzcd}\n\\end{center}\n\n But we can apply the universal properties to $f$ and $g$ themselves: there is a unique linear map $p: V \\to V$ such that $f = f;p$, and similarly a unique linear map $q: W \\to W$ such that $g = g;q$. Since the identity maps $id_V$ and $id_W$ on $V$ and $W$ work for $p$ and $q$, respectively, and since $s;r$ and $r;s$ also fit the criteria, we must have $r;s = id_V$ and $s;r = id_W$. So $r$ and $s$ are inverses of each other, hence bijective, hence linear isomorphisms.\n\nTo prove that $r$ is the unique linear isomorphism $L: V \\to W$ such that $f;L = g$, note that $f = g;s$, so $g;s;L = g$. $s;L$, being the composition of linear maps, is linear, so we must have $s;L = id_W$. So $L$ is a post-inverse for $s$, implying $L = r$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nThere is a free vector space for every set $X$ and every field $\\mathbb{F}$.\n\\begin{proof}\n    The pair $(V, f)$ works, where $V$ is the subspace of $\\mathbb{F}^X$ of functions of finite support and $f: X \\to V$ is defined by $xf$ being the function that maps $x$ to $1 \\in \\mathbb{F}$ and $y \\neq x$ to $0 \\in \\mathbb{F}$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf $(V, f)$ is a free vector space for $X$, then $f$ is injective.\n\\begin{proof}\nIf $xf = yf$ for some $x \\neq y \\in X$, then any function $g: X \\to W$ which has $xg \\neq yg$ will not have a factorization through $f$, contradicting the universal property.\n\\end{proof}\n\\end{prop}\n\n\\section{Multilinear maps}\nIf $V_1, \\ldots, V_n$ are some vector spaces over a field $\\mathbb{F}$, then for any integer $i$, $1 \\leq i \\leq n$, and for any $v = (v_1, \\ldots, v_{i-1}, v_{i+1}, \\ldots, v_n) \\in \\prod_{j=1, j \\neq i}^n V_j$, we can define the function $\\lambda_i[v]: V_i \\to \\prod_1^n V_j$ by $z \\lambda_i[v] := (v_1, \\ldots, v_{i-1}, z, v_{i+1}, \\ldots, v_n)$. It is routine to prove that each such function is a linear map $V_i \\to \\prod_1^n V_j$.\n\nFor any vector space $W$ over $\\mathbb{F}$, a function $\\phi: \\prod_1^n V_j$ is said to be \\textbf{multilinear} when for every $i$ and every $v \\in \\prod_{j=1, j \\neq i}^n V_j$, the composite function $\\lambda_i[v];\\phi$ is a linear map $V_i \\to W$. When $W = \\mathbb{F}$ (that is, the vector space over $\\mathbb{F}$, then $\\phi$ is said to be a \\textbf{multilinear form}.\n\n\\begin{prop}\nDenote the collection of all multilinear maps $\\prod_1^n V_i \\to W$ by $ML(V_1, \\ldots, V_n; W)$. By the usual definition of function addition and function scalar multiplication, this is a vector space over $\\mathbb{F}$.\n\\end{prop}\n\n\\section{Tensor products}\nA tensor product of vector spaces $(V_1, \\ldots, V_n)$ is a vector space $Z$ and a multilinear map $\\otimes$ such that $\\otimes$ is, in some sense, the most general multilinear map on $\\prod_1^n V_i$. We give a universal property that defines the tensor product (similar to what was done for free vector spaces), prove some general properties about it, and then explicitly construct one of the tensor products.\n\n\\begin{defn}\n    For any vector spaces $V_1, \\ldots, V_n$ over a common field $\\mathbb{F}$, a \\textbf{tensor product} of $(V_1, \\ldots, V_n)$ is a pair $(Z, \\otimes)$ where $Z$ is a vector space and $\\otimes$ is a multilinear map $\\prod_1^n V_i \\to Z$ such that for every vector space $W$ over $\\mathbb{F}$ and every multilinear map $f: \\prod_1^n V_i \\to W$, there is a unique linear map $T: Z \\to W$ such that $f = \\otimes;T$.\n\nIn other words, for every vector space $W$ and every multilinear map $f: \\prod_1^n V_i \\to W$ there is a unique linear $T: Z \\to W$ such that this diagram commutes:\n\n\\begin{center}\n\\begin{tikzcd}[row sep=large]\n    \\prod_1^n V_i \\arrow[rd, \"f\"] \\arrow[r, \"\\otimes\"]\n    & Z \\arrow[d, dashed, \"\\exists! \\> T\"] \\\\\n    & W\n\\end{tikzcd}\n\\end{center}\n\\end{defn}\n\n\\begin{prop}\nIf $(Z, \\otimes)$ is a tensor product of $(V_1, \\ldots, V_n)$, then it is unique up to unique isomorphism.\n\\begin{proof}\nThis has the same form as the \"unique up to unique isomorphism\" proof for free vector spaces, so it is omitted here.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf $(Z, \\otimes)$ is a tensor product of $(V_1, \\ldots, V_n)$ and $W$ is any vector space over the same field as the $V_i$'s, then $Hom(Z, W)$ is isomorphic to $ML(V_1, \\ldots, V_n; W)$.\n\\begin{proof}\n    The universal property induces a map $\\phi: ML(V_1, \\ldots, V_n; W) \\to Z$. If $T: Z \\to W$ is any linear map, then $\\otimes;T$ is multilinear since $\\otimes$ is, so $(\\otimes;T) \\phi = T$, hence $\\phi$ is surjective. It must also be injective: if $T = f \\phi = g \\phi$, then $f = \\otimes;T = g$.\n\\end{proof}\n\\end{prop}\n\\begin{corollary}\nFor any tensor product $(Z, \\otimes)$ of $(V_1, \\ldots, V_n)$, the space of all multilinear forms on $\\prod_1^n V_i$ is isomorphic to $Z^{\\ast}$.\n\\end{corollary}\n\n\\begin{prop}\nIf $(Z, \\otimes)$ is a tensor product of $(V_1, \\ldots, V_n)$, then $img \\otimes$ generates $Z$.\n\\begin{proof}\nLet $Y$ be the subspace of $Z$ generated by $img \\otimes$. Consider $\\otimes': \\prod_1^n V_i \\to Y$, defined to be $\\otimes$ but with its codomain restricted to $Y$. $\\otimes'$ is clearly multilinear since $\\otimes$ is, so we have some $T: Z \\to Y$, linear, such that $\\otimes; T = \\otimes'$. But also, if we let $j: Y \\to Z$ be the inclusion of $Y$ into $Z$, it is linear and $\\otimes'; j = \\otimes$. \n\n\\begin{center}\n\\begin{tikzcd}\n    \\prod_1^n V_i \\arrow[rd, \"\\otimes'\"] \\arrow[r, \"\\otimes\"] \\arrow[rdd, \"\\otimes\"]\n    & Z \\arrow[d, \"T\"] \\arrow[dd, bend left=45, \"id_Z\"] \\\\\n    & Y \\arrow[d, hook, \"j\"] \\\\\n    & Z\n\\end{tikzcd}\n\\end{center}\n\nBy combining these two, we get: $\\otimes;T;j = \\otimes$. But $T;j$ is linear, and by the universal property $id_Z$ is the unique linear map such that $\\otimes; id_Z = \\otimes$. So $T;j = id_Z$, implying $j$ is surjective. So $Y = Z$.\n\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nFor any vector spaces $(V_1, \\ldots, V_n)$ over a common field $\\mathbb{F}$, there is a tensor product. The vector space is denoted $\\bigotimes_1^n V_i$ (or $V_1 \\otimes V_2$ in the case of $n = 2$) and the multilinear map is denoted $\\otimes: \\prod_1^n V_i \\to \\bigotimes_1^n V_i$, where usually infix notation is used: for all $(v_1, \\ldots, v_n) \\in \\prod_1^n V_i$, $(v_1, \\ldots, v_n) \\mapsto v_1 \\otimes \\cdots \\otimes v_n$.\n\\begin{proof}\n    Let $(F(\\prod_1^n V_i), \\iota)$ be any free vector space on $\\prod_1^n V_i$. If $W$ is any vector space and $\\phi: \\prod_1^n V_i \\to W$ is any multilinear map, by the universal property of the free vector space we have a unique linear map $T: F(\\prod_1^n V_i) \\to W$ such that $\\iota;T = \\phi$.\n\n\\begin{center}\n\\begin{tikzcd}\n    \\prod_1^n V_i \\arrow[d, \"\\phi\"] \\arrow[r, \"\\iota\"]\n    & F(\\prod_1^n V_i) \\arrow[dl, \"T\"] \\\\\n    W\n\\end{tikzcd}\n\\end{center}\n\nFor all $(v_1, \\ldots, v_n) \\in \\prod_1^n V_i$, let us denote $(v_1, \\ldots, v_n) \\iota$ by $[v_1, \\ldots, v_n]$. $\\iota$ is not multilinear since the zero of $F(\\prod_1^n V_i)$ is not in the image of $\\iota$, but we can make it multilinear by composing it with another map.\n\nConsider the subspace $Z$ generated by all vectors of the form:\n\n$$[v_1, \\dots, v_{i-1}, \\alpha v, v_{i+1}, \\dots, v_n] - [v_1, \\dots, v_{i-1}, v, v_{i+1}, \\dots, v_n]$$\n\nand\n\n$$[v_1, \\dots, v_{i-1}, v + w, v_{i+1}, \\dots, v_n] - [v_1, \\dots, v_{i-1}, v, v_{i+1}, \\dots, v_n] - [v_1, \\dots, v_{i-1}, w, v_{i+1}, \\dots, v_n]$$\n\nfor some $i$, $1 \\leq i \\leq n$ and some $\\alpha \\in \\mathbb{F}$, $v, w \\in V_i$. If we let $\\pi: F(\\prod_1^n V_i) \\to F(\\prod_1^n V_i) / Z$ be the canonical map from $F(\\prod_1^n V_i)$ to the quotient space induced by $Z$, the claim is that $(F(\\prod_1^n V_i), \\iota; \\pi)$ is a tensor product. If we denote $(v_1, \\dots, v_n) \\iota \\pi$ by $\\langle v_1, \\dots, v_n \\rangle$, then, for example, $\\langle v + w, v_2, \\dots, v_n \\rangle = \\langle v, v_2, \\dots, v_n \\rangle + \\langle w, v_2, \\dots, v_n \\rangle$ since the difference of the two sides is an element of $Z$. So $\\iota ; \\pi$ is multilinear.\n\nNow, $Z$ is a subset of $ker T$ because $\\phi$ is multilinear. Also, by the property of the quotient space, there is a unique linear $f: F(\\prod_1^n V_i) / Z \\to W$ such that $\\pi; f = T$.\n\n\\begin{center}\n\\begin{tikzcd}\n    \\prod_1^n V_i \\arrow[d, \"\\phi\"] \\arrow[r, \"\\iota\"]\n    & F(\\prod_1^n V_i) \\arrow[dl, \"T\"] \\arrow[d, \"\\pi\"] \\\\\n    W & F(\\prod_1^n V_i) / Z \\arrow[l, \"f\"]\n\\end{tikzcd}\n\\end{center}\n\nSo $(F(\\prod_1^n V_i)/Z, \\iota;\\pi)$ is a tensor product for $(V_1, \\ldots, V_n)$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nFor any vector spaces $X, Y, Z$ over a common field, we have $(X \\otimes Y) \\otimes Z$ is isomorphic to $X \\otimes Y \\otimes Z$ is isomorphic to $X \\otimes (Y \\otimes Z)$.\n\\begin{proof}\n    We will construct the isomorphism between $(X \\otimes Y) \\otimes Z$ and $X \\otimes Y \\otimes Z$ and wave our hands about the other isomorphism. First, for any $z \\in Z$, we can construct a map $\\phi_z: X \\times Y \\to X \\otimes Y \\otimes Z$ by $(x, y) \\phi_z := x \\otimes y \\otimes z$. This function is multilinear, so by the universal property of $X \\otimes Y$, there's a unique linear map $T_z: X \\otimes Y \\to X \\otimes Y \\otimes Z$ such that $(x \\otimes y ) T_z = x \\otimes y \\otimes z$ for all $(x, y) \\in X \\times Y$.\n\n\\begin{center}\n\\begin{tikzcd}[row sep=large]\n    X \\times Y \\arrow[rd, \"\\phi_z\"] \\arrow[r, \"\\otimes\"] \n    & X \\otimes Y \\arrow[d, \"T_z\"] \\\\\n    & X \\otimes Y \\otimes Z\n\\end{tikzcd}\n\\end{center}\n\nUsing $T_z$, we can define a function $\\phi: (X \\otimes Y) \\times Z \\to X \\otimes Y \\otimes Z$ by $(a, z) \\phi := a T_z$. This is linear in the first parameter because each $T_z$ is linear. Also, \n\n\\begin{align*}\n(x \\otimes y) T_{z_1 + z_2} & = x \\otimes y \\otimes (z_1 + z_2) \\\\\n                            & = x \\otimes y \\otimes z_1 + x \\otimes y \\otimes z_2 \\\\\n                            & = (x \\otimes y) T_{z_1} + (x \\otimes y) T_{z_2}\n\\end{align*}\n    \nfor all $x \\in X$, $y \\in Y$. Since elements $x \\otimes y$ generate $X \\otimes Y$, we have $T_{z_1 + z_2} = T_{z_1} + T_{z_2}$. For a similar reason, $T_{\\alpha z} = \\alpha T_z$ for all $\\alpha \\in \\mathbb{F}$. So $\\phi$ is bilinear, which gives, by the universal property, a linear map $T: (X \\otimes Y) \\otimes Z \\to X \\otimes Y \\otimes Z$.\n\n\\begin{center}\n\\begin{tikzcd}[row sep=large]\n    (X \\otimes Y) \\times Z \\arrow[rd, \"\\phi\"] \\arrow[r, \"\\chi\"] \n    & (X \\otimes Y) \\otimes Z \\arrow[d, \"T\"] \\\\\n                                   & X \\otimes Y \\otimes Z\n\\end{tikzcd}\n\\end{center}\n\nNow, if we define a map $\\psi: X \\times Y \\times Z \\to (X \\otimes Y) \\otimes Z$ by $(x, y, z) \\psi := (x \\otimes y) \\otimes z$, this is a multilinear map, so there's an induced linear map $S: X \\otimes Y \\otimes Z \\to (X \\otimes Y) \\otimes Z$. By the universal property, this map $S$ has that $(x \\otimes y \\otimes z) ST = x \\otimes y \\otimes z$ for all $(x, y, z) \\in X \\times Y \\times Z$. So $ST$ is a linear map $X \\otimes Y \\otimes Z \\to X \\otimes Y \\otimes Z$ such that, when it is restricted to the generating set of $\\{x \\otimes y \\otimes z : (x, y, z) \\in X \\times Y \\times Z\\}$, becomes the identity map. So in fact $ST$ is the identity map.\n\nSimilarly, it can be proved that the elements of the form $(x \\otimes y) \\otimes z$ are a generating set for $(X \\otimes Y) \\otimes Z$ (elements $a \\otimes z$ for $a \\in X \\otimes Y$ definitely are, but $x \\otimes y$ generate $X \\otimes Y$ and $\\otimes$ is bilinear), so for a similar reason $TS$ is an identity map as well. So $S$ and $T$ are linear and inverses of one another, meaning that $X \\otimes Y \\otimes Z$ and $(X \\otimes Y) \\otimes Z$ are isomorphic.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nFor any spaces $V$ and $W$ over a field $\\mathbb{F}$, $V \\otimes W$ is isomorphic to $W \\otimes V$.\n\\begin{proof}\n    The multilinear maps $\\phi: V \\times W \\to W \\otimes V$ and $\\psi: W \\times V \\to V \\otimes W$ defined by $(v, w) \\phi := w \\otimes v$ and $(w, v) \\psi := v \\otimes w$ induce, respectively, linear maps $S: V \\otimes W \\to W \\otimes V$ and $T: W \\otimes V \\to V \\otimes W$. We have that $(v \\otimes w) ST = v \\otimes w$ and $(w \\otimes v) TS = w \\otimes v$ for all $v \\in V$, $w \\in W$. Since these generate $V \\otimes W$ and $W \\otimes V$, $S$ and $T$ are isomorphisms.\n\\end{proof}\n\\end{prop}\n\n\\section{Finite dimensional facts}\n\n\\begin{prop}\n    If $V_1, \\ldots, V_n$ are all finite dimensional vector spaces with $V_i$ having dimension $d_i$, and, for all $i$, $\\beta_i = \\{v_{i,1}, \\dots, v_{i,d_i}\\}$ is a basis for $V_i$, then if $f: \\prod_1^n \\beta_i \\to \\mathbb{F}$ is any function, $f$ can be extended to exactly one multilinear form $g: \\prod_1^n V_i \\to \\mathbb{F}$.\n\nFurthermore, $dim ML(V_1, \\ldots, V_n; \\mathbb{F}) = \\prod_1^n dim V_i$.\n\n\\begin{proof}\n    If $\\phi: \\prod_1^n V_i \\to \\mathbb{F}$ is any multilinear form, then for all $z \\in \\prod_1^n V_i$, $z = (z_1, \\dots, z_n) = (\\sum_j \\alpha_{1,j} v_{1,j}, \\dots, \\sum_j \\alpha_{n,j} v_{n,j})$, so\n    \n$$z \\phi = \\sum_{j \\in \\prod_1^n [d_i]} \\alpha_{1,j_1} \\cdots \\alpha_{n,j_n} (v_{1,j_1}, \\ldots, v_{n,j_n}) \\phi$$\n\nwhere $[n] := \\{1, \\ldots, n\\}$ for any $n$. This shows that any multilinear map is completely determined by how the \"basis tuples\" $(v_{1,j_1}, \\ldots, v_{n,j_n})$ get mapped, which proves the first statement.\n\nFor any $I \\in \\prod_1^n [d_i]$ we define $f_I: \\prod_1^n V_i \\to \\mathbb{F}$ to be the multilinear form that maps the basis tuple $(v_{I_1}, \\ldots, v_{I_n})$ to $1$ and all other basis tuples to $0$. Then the collection of these functions is a basis for $ML(V_1, \\ldots, V_n; \\mathbb{F})$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf $V_1, \\ldots, V_n$ are all finite dimensional vector spaces, then $dim(\\otimes_1^n V_i) = \\prod_1^n dim V_i$.\n\\begin{proof}\nThe previous proposition establishes that $dim ML(V_1, \\ldots, V_n; \\mathbb{F}) = \\prod_1^n dim V_i$. But we know that $ML(V_1, \\ldots, V_n; \\mathbb{F})$ and $(\\otimes_1^n V_i)^{\\ast} = Hom(\\otimes_1^n V_i, \\mathbb{F}$ are isomorphic. If we could establish that $\\otimes_1^n V_i$ is finite-dimensional, then the result would be proved since every finite dimensional vector space is isomorphic with its dual.\n\nBut we know the set of elements $v_1 \\otimes \\dots \\otimes v_n$ generates $\\otimes_1^n V_i$, and we know that $v_1 \\otimes \\dots \\otimes v_n$ is a linear combination of \"basis tensors\" $e_1 \\otimes \\dots \\otimes e_n$, where each $e_i$ is an element of a basis $\\beta_i$ for $V_i$. So the collection of \"basis tensors\" generates $\\otimes_1^n V_i$, hence it is finitely-generated, so finite dimensional.\n\\end{proof}\n\\end{prop}\n\n\n\\begin{prop}\nIf $V$ and $W$ are finite dimensional, then $Hom(V, W) \\cong V^{\\ast} \\otimes W$.\n\\begin{proof}\n    This can be seen from the two spaces having the same dimension. We know $dim(V^{\\ast} \\otimes W) = dim V^{\\ast} dim W = dim V dim W$. To complete the proof, if $\\{v_1, \\ldots, v_m\\}$ and $\\{w_1, \\ldots, w_n\\}$ are bases for $V$ and $W$, respesctively, then the collection of maps $g_{ij}: V \\to W$ defined by $v_k g_{ij} = \\delta_{ik} w_j$ (where $\\delta$ is the Kronecker delta) is a basis for $Hom(V, W)$. So $dim Hom(V, W) = dim V dim W$.\n\\end{proof}\n\\end{prop}\n\n\\section{Tensor spaces}\n\\begin{defn}\n    If we $V$ is any vector space, and if we define $V_1 := V$ and $V_{-1} := V^{\\ast}$, then any tensor product $V_{\\epsilon_1} \\otimes \\cdots \\otimes V_{\\epsilon_n}$ with each $\\epsilon_i \\in \\{1, -1\\}$, is isomorphic to $V^{\\otimes p} \\otimes (V^{\\ast})^{\\otimes q}$ for some $p, q \\in \\mathbb{N}$, by commutativity and associativity of the tensor product. We call such a product the \\textbf{tensor space of type $(p, q)$} and denote it by $T_q^p(V)$. Elements of $T_q^p(V)$ are called \\textbf{tensors of type $(p, q)$}. Such tensors are said to be \\textbf{contravariant of degree $p$} and \\textbf{covariant of degree q}. When $q = 0$, the tensors are said to be \\textbf{contravariant}, and similary when $p = 0$ they are said to be \\textbf{covariant}.\n\\end{defn}\n\\end{document}\n", "meta": {"hexsha": "ee037ad51ecb4611d02b814fd23e69ec54c35ae8", "size": 21306, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/linalg/tensors.tex", "max_stars_repo_name": "nham/math_notes", "max_stars_repo_head_hexsha": "ed76a02ed2748eadf765167f361861eef981b8bb", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-02-07T15:37:10.000Z", "max_stars_repo_stars_event_max_datetime": "2015-02-07T17:03:04.000Z", "max_issues_repo_path": "notes/linalg/tensors.tex", "max_issues_repo_name": "nham/math_notes", "max_issues_repo_head_hexsha": "ed76a02ed2748eadf765167f361861eef981b8bb", "max_issues_repo_licenses": ["CC0-1.0"], "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/linalg/tensors.tex", "max_forks_repo_name": "nham/math_notes", "max_forks_repo_head_hexsha": "ed76a02ed2748eadf765167f361861eef981b8bb", "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.0702875399, "max_line_length": 755, "alphanum_fraction": 0.6545104665, "num_tokens": 7637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.6610154155809412}}
{"text": "\\documentclass[12pt]{article}\n \\usepackage[margin=0.8in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb,amsfonts}\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{Citadel Boston Regional Datathon 2021}\n\\author{Shinjini Ghosh, Lay Jain, Pawan Goyal}\n\\date{\\today}\n\\maketitle\n\n\n\\section*{SEIVR Model Equations}\n\\begin{align*}\n    % \\def\\arraystretch{1.5}\n    % \\renewcommand\\arraystretch{1.5}\n    \\Dot{S} & = \\alpha R_S - \\frac{S}{N}\\beta I- \\frac{S}{N}\\chi E-\\rho S \\\\[4pt]\n    \\Dot{V_1} &= \\rho S + \\rho R_S - \\frac{V_1}{N}\\beta I - \\frac{V_1}{N}\\chi E - \\phi V_1 \\\\[4pt]\n    \\Dot{V_2} &= \\phi V_1 + \\phi ' R_1 + (1-\\delta_2)I_2 - \\frac{V_2}{N} \\beta I - \\frac{V_2}{N} \\chi E \\\\[4pt]\n    \\Dot{E_1} &= \\frac{V_1}{N} \\beta I + \\frac{V_1}{N} \\chi E - \\theta E_1\\\\[4pt]\n    \\Dot{E_2} &= \\frac{V_2}{N} \\beta I + \\frac{V_2}{N} \\chi E - \\theta E_2 \\\\[4pt]\n    \\Dot{E_S} &= \\frac{S}{N} \\beta I + \\frac{S}{N} \\chi E - \\theta E_S \\\\[4pt]\n    \\Dot{I_1} &= \\theta E_1 - \\delta_1 I_1 - (1-\\delta_1) I_1 \\\\[4pt]\n    \\Dot{I_2} &= \\theta E_2 - \\delta_2 I_2 - (1-\\delta_2) I_2 \\\\[4pt]\n    \\Dot{I_S} &= \\theta E_S - \\delta_S I_S - (1-\\delta_S) I_S \\\\[4pt]\n    \\Dot{R_1} &= (1-\\delta_1) I_1 - \\phi ' R_1 \\\\[4pt]\n    \\Dot{R_S} &= (1-\\delta_S) I_S - \\rho R_S - \\alpha R_S \\\\[4pt]\n    \\Dot{D} &= \\delta_1 I_1 + \\delta_2 I_2 + \\delta_S I_S \\\\\n\\end{align*}\n\\vspace{-4mm}\nwhere \n\\vspace{-5mm}\n\\begin{align*}\n    I &= I_1 + I_2 + I_3 \\\\\n    E &= E_1 + E_2 + E_3 \\\\\n    N &= S + V_1 + V_2 + E_1 + E_2 + E_S + I_1 + I_2 + I_S + R_1 + R_2 + R_S + D \\\\\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "9797f0c26f6533ba26108ce13f22da189551eaaf", "size": 2165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/writeup.tex", "max_stars_repo_name": "layjain/BRD-21", "max_stars_repo_head_hexsha": "6bb0957436f02fe91d9de46eae4d3171f2b42591", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "layjain/BRD-21", "max_issues_repo_head_hexsha": "6bb0957436f02fe91d9de46eae4d3171f2b42591", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "layjain/BRD-21", "max_forks_repo_head_hexsha": "6bb0957436f02fe91d9de46eae4d3171f2b42591", "max_forks_repo_licenses": ["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.8490566038, "max_line_length": 193, "alphanum_fraction": 0.6221709007, "num_tokens": 911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6609147130170898}}
{"text": "\\subsection{Naive Algorithms}\n  Here we show three naive algorithms for calculating the new capacities that make use of the Trust Transfer\n  corollary~(\\ref{trusttransfer}). To prove the correctness of the algorithms, it suffices to prove that\n  \\begin{equation}\n  \\label{naive:req1}\n     \\forall i \\in [n], c'_i \\leq x_i \\mbox{ and}\n  \\end{equation}\n  \\begin{equation}\n  \\label{naive:req2}\n     \\sum\\limits_{i=1}^{n}c'_i = F - V \\enspace.\n  \\end{equation}\n  Due to the nature of these algorithms, the only inputs necessary are the initial flows $x_i$, the number of $A$'s neighbours\n  $n$ and the desired flow reduction $V$. Proofs of correctness and complexity can be found in the Appendix.\n\n  \\subimport{common/algorithms/}{fcfscode.tex}\n\n  The previous algorithm nullifies all outgoing trust to one player after the other in the order they are given in the input,\n  until the desired indirect trust is achieved. The complexity of this algorithm is $O\\left(n\\right)$.\n\n  \\subimport{common/algorithms/}{abscode.tex}\n\n  This algorithm finds a \\texttt{reduction} value such that the configuration $\\forall i \\in \\left[n\\right], c'_i =\n  \\max{\\left(0, x_i - \\mbox{\\texttt{reduction}}\\right)}$ achieves the desired flow.\n\n  The function \\texttt{preprocess(}$x_i$\\texttt{)} returns a data structure \\texttt{X} containing the set of flows\n  $\\left(x_i\\right)$, such that the corresponding function \\texttt{popMin(X)} is able to repeatedly return a tuple\n  consisiting of the index of the minimum element and a new data structure missing exactly the minimum element.\n  Examples of such pairs of functions are:\n  \\begin{equation*}\n  \\begin{gathered}\n    \\begin{cases}\n      \\texttt{preprocess = quickSort} \\\\\n      \\texttt{popMin = (}x_1\\texttt{, X}\\setminus \\{x_1\\}\\texttt{)}\n    \\end{cases}\n    \\mbox{ and} \\\\\n    \\begin{cases}\n      \\texttt{preprocess = FibonacciHeap} \\\\\n      \\texttt{popMin = (find-min(X),delete-min(X))}\n    \\end{cases} \\enspace.\n  \\end{gathered}\n  \\end{equation*}\n  In the general case, the complexity of the algorithm \\texttt{abs} is proven to be\n  $O\\left(preprocess\\right) + O\\left(n\\right)O\\left(popMin\\right)$. In both specific cases, the complexity is\n  $O\\left(n\\log{n}\\right)$. This algorithm also minimizes the $||\\Delta_i||_\\infty$ norm for the specific set of old flows\n  $x_i$ given as input. A proof of this fact can be found in the Appendix.\n\n  \\subimport{common/algorithms/}{propcode.tex}\n  This algorithm reduces all outgoing direct trust proportionally in such a way that the desired flow is achieved. The\n  complexity of this algorithm is proven to be $O\\left(n\\right)$.\n", "meta": {"hexsha": "7743c36940a522fd36bf996b89ef246fb5736a11", "size": 2607, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "may31deliverable/riskinvalgs/naive.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/naive.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/naive.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.14, "max_line_length": 126, "alphanum_fraction": 0.7222861527, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6609147007345136}}
{"text": "\\paragraph{Answer 1.}\n\nThe method to answer these questions is simply to try small words by\nconstructing them in order to satisfy the constraints.\n\\begin{enumerate}\n\n  \\item The \\label{aba} shortest word \\(x\\) belonging to L(r) is found\n    by taking \\(\\epsilon\\) in place of \\(\\lparen a \\disjM{}\n    b\\rparen\\kleeneM\\). So \\(x = aba\\). Let us check if \\(x \\in L(s)\\)\n    or not. \\(L(s)\\) is made of the union of four sub-languages\n    (subsets). To make this clear, let us remove the useless\n    parentheses on the right side:\n    \\begin{equation*}\n    s = \\lparen ab \\rparen\\kleeneM{} \\, \\disjM{} \\, \\lparen ba\n    \\rparen\\kleeneM{} \\, \\disjM{} \\, a\\kleeneM{} \\, \\disjM{} \\,\n    b\\kleeneM.\n    \\end{equation*}\n    Therefore, membership tests on \\(L(s)\\) have to be split\n    into four: one membership test on \\(\\lparen ab\n    \\rparen\\kleeneM\\), one on \\(\\lparen ba \\rparen\\kleeneM\\),\n    one on \\(a\\kleeneM\\) and another one on\n    \\(b\\kleeneM\\). In other words, \\(x \\in L(s)\\) is equivalent to\n    \\begin{equation*}\n    x \\in L(\\lparen ab \\rparen\\kleeneM) \\;\n     \\text{or} \\; x \\in L(\\lparen ba \\rparen\\kleeneM) \\;\n     \\text{or} \\; x \\in L(a\\kleeneM) \\; \\text{or} \\; x\n     \\in L(b\\kleeneM).\n    \\end{equation*}\n    Let us test the membership with \\(x = aba\\):\n    \\begin{enumerate}\n  \n      \\item The words in \\(L(\\lparen ab \\rparen\\kleeneM)\\) are\n        \\(\\epsilon\\), \\(ab\\), \\(abab\\ldots\\) Thus \\(aba \\not\\in\n        L(\\lparen ab \\rparen\\kleeneM)\\).\n\n      \\item The words in \\(L(\\lparen ba \\rparen\\kleeneM)\\) are\n        \\(\\epsilon\\), \\(ba\\), \\(baba\\ldots\\) Hence \\(aba \\not\\in\n        L(\\lparen ba \\rparen\\kleeneM)\\).\n\n      \\item The words in \\(L(a\\kleeneM)\\) are \\(\\epsilon\\), \\(a\\),\n        \\(aa\\ldots\\) Therefore \\(aba \\not\\in L(a\\kleeneM)\\).\n\n      \\item The words in \\(L(b\\kleeneM)\\) are \\(\\epsilon\\), \\(b\\),\n        \\(bb\\ldots\\) So \\(aba \\not\\in L(b\\kleeneM)\\).\n  \n    \\end{enumerate}\n    The conclusion is \\(aba \\not\\in L(s)\\).\n\n    \\item What is the shortest word belonging to \\(L(s)\\)?  Since the\n      four sub-languages composing \\(L(s)\\) are starred, it means that\n      \\(\\epsilon \\in L(s)\\). Since we showed at the item~(\\ref{aba})\n      that \\(aba\\) is the shortest word of \\(L(r)\\), it means that\n      \\(\\epsilon \\not\\in L(r)\\) because \\(\\epsilon\\) is of length\n      \\(0\\).\n\n    \\item This question is a bit more difficult. After a few tries, we\n      cannot find any~\\(x\\) such that \\(x \\in L(r)\\) and \\(x \\in\n      L(s)\\). Then we may try to prove that \\(L(r) \\cap L(s) =\n      \\varnothing\\), \\emph{i.e.,} there is no such~\\(x\\). How should we\n      proceed? The idea is to use the decomposition of \\(L(s)\\) into\n      for sub-languages and try to prove\n      \\begin{align*}\n        L(r) \\cap L(\\lparen ab \\rparen\\kleeneM) &= \\varnothing,\\\\\n        L(r) \\cap L(\\lparen ba \\rparen\\kleeneM) &= \\varnothing,\\\\\n        L(r) \\cap L(a\\kleeneM) &= \\varnothing,\\\\\n        L(r) \\cap L(b\\kleeneM) &= \\varnothing.\n      \\end{align*}\n      If all these four equations are true, they imply\n        \\(L(r) \\cap L(s) = \\varnothing\\).\n      \\begin{enumerate}\n\n        \\item Any word in \\(L(r)\\) ends with \\(a\\) whereas any word in\n          \\(L(\\lparen ab \\rparen\\kleeneM)\\) finishes with \\(b\\) or is\n          \\(\\epsilon\\). Thus \\(L(r) \\cap L(\\lparen ab \\rparen\\kleeneM)\n          = \\varnothing\\).\n\n        \\item For the same reason, \\(L(r) \\cap L(b\\kleeneM) =\n          \\varnothing\\).\n \n        \\item Any word in \\(L(r)\\) contains both \\(a\\) and \\(b\\)\n          whereas any word in \\(L(a\\kleeneM)\\) contains only \\(b\\) or\n          is \\(\\epsilon\\). Therefore \\(L(r) \\cap L(a\\kleeneM) =\n          \\varnothing\\).\n\n        \\item Any word in \\(L(r)\\) starts with \\(a\\) whereas any word\n          in \\(L(\\lparen ba \\rparen\\kleeneM)\\) starts with \\(b\\) or is\n          \\(\\epsilon\\). Thus \\(L(r) \\cap L(\\lparen ba \\rparen\\kleeneM)\n          = \\varnothing\\).\n\n      \\end{enumerate}\n      Finally, since all the four equations are false, they imply\n      that\n      \\begin{equation*}\n        L(r) \\cap L(s) = \\varnothing.\n      \\end{equation*}\n\n    \\item Let us construct letter by letter a word \\(x\\) which does\n      not belong neither to \\(L(r)\\) not \\(L(s)\\). First, we note that\n      all words in \\(L(r)\\) start with \\(a\\), so we can try to start\n      \\(x\\) with \\(b\\): this way \\(x \\not\\in L(r)\\). So we have \\(x =\n      b\\ldots\\) and we have to fill the dots with some letters in such\n      a way that \\(x \\not\\in L(s)\\).\n\n      We use again the decomposition of~\\(L(s)\\) into four\n      sub-languages and make sure that~\\(x\\) does not belong to any of\n      those sub-languages. First, because \\(x\\) starts with \\(b\\), we\n      have \\(x \\not\\in L(a\\kleeneM)\\) and \\(x \\not\\in L(\\lparen\n      ab \\rparen\\kleeneM)\\). Now, we have to add some more letters\n      such that \\(x \\not\\in L(b\\kleeneM)\\) and \\(x \\not\\in L(\\lparen\n      ba \\rparen\\kleeneM)\\). Since any word in \\(L(b\\kleeneM)\\) has a\n      letter \\(b\\) as second letter or is \\(\\epsilon\\), we can choose\n      the second letter of \\(x\\) to be \\(a\\). This\n      way \\(x=ba\\ldots \\not\\in L(b\\kleeneM)\\). Finally, we have to\n      add more letters to make sure that\n      \\begin{equation*}\n      x=ba\\ldots \\not\\in L(\\lparen ba\\rparen\\kleeneM).\n      \\end{equation*}\n      Any word in \\(L(\\lparen ba\\rparen\\kleeneM)\\) is\n      either \\(\\epsilon\\) or \\(ba\\) or \\(baba\\ldots\\), hence the third\n      letter is \\(b\\). Therefore, let us choose the letter \\(a\\) as\n      the third letter of \\(x\\) and we thus have \\(x=baa \\not\\in\n      L(\\lparen ba\\rparen\\kleeneM)\\). In summary, \\(baa \\not\\in L(r),\n      baa \\not\\in L(b\\kleeneM), baa \\not\\in L(\\lparen\n      ba\\rparen\\kleeneM), baa \\not\\in L(a\\kleeneM), baa \\not\\in\n      L(\\lparen ab\\rparen\\kleeneM)\\), which is equivalent\n      to \\(baa \\not\\in L(r)\\) and \\(baa \\not\\in L(\\lparen\n      ab \\rparen\\kleeneM) \\cup L(\\lparen ba \\rparen\\kleeneM) \\cup\n      L(a\\kleeneM) \\cup L(b\\kleeneM) = L(s)\\). Therefore, \\(x=baa\\) is\n      one possible answer.\n\n\\end{enumerate}\n", "meta": {"hexsha": "cd10d93e4361f847860de447d636c8d22e4cc694", "size": 5984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regexp_answer_01.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_answer_01.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_answer_01.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": 45.3333333333, "max_line_length": 71, "alphanum_fraction": 0.5798796791, "num_tokens": 2031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6609146893012442}}
{"text": "%Admittedly, structure learning is an overloaded term, so in this chapter, we aim to define it and provide example problems. We will also identify and focus on its Bayesian variant.\nIn this chapter we define the Bayesian structure learning problem and cover relevant technical background material.\n\n\\section{What is structure learning?}\nLearning structure is a broad problem; we define it as an unsupervised learning problem wherein a user has data\nand a priori assumes some unobserved, or \\emph{latent}, organization of the data. Example organizations of the data might include a flat clustering, i.e. the data can be partitioned into some $\\numcluster$ distinct groups. A logical extension of a flat clustering organization is a mixed-membership model, \nwhere data can be organized into $\\numcluster$ groups but each datum may belong to many groups simultaneously. \nIn this thesis, we are particularly interested in hierarchical clustering, where data are organized into a tree structure, with data closer on the tree being logically or semantically similar. We are also interested in\nlinear dynamical systems, wherein time-series data\nevolve according to a linear transition function.\n\nA structure learning problem first begins with data, and an assumption of a structure class. It then recovers a plausible structure and returns it to the user. Formally, we assume a structure class $\\structures$ and return a candidate structure $\\structure \\in \\structures$.\n%In a structure learning problem, corresponding algorithms exist which have various properties and trade-offs. \nPerhaps the most famous is the $\\numcluster$-means problem, which assumes $\\numcluster$ \ndiscrete clusters to which the data belong. \nThe corresponding algorithm recovers a $\\numcluster$-partition of the data.  \nAnalogously in mixed-membership modeling, latent Dirichlet allocation \\citep[LDA; ][]{Blei2003} recovers a topic model structure for text data.\n\nWe formalize structure learning probabilistically. We will later cover the Bayesian variant, but in vanilla structure learning,\nthere exists some latent structure $\\structure$\nand a likelihood function $\\p(\\dataset \\given \\structure)$.\nRecovering a structure amounts to\nmaximizing likelihood, i.e.\n\\begin{align*}\n    \\structure^* = \\argmax_{\\structure} \\p(\\dataset \\given \\structure)\n\\end{align*}\nWe now outline two structure learning problems\nwhich are running examples in this thesis. We first introduce the structure classes and present a candidate likelihood function. We then discuss the relevant\nalgorithms that actually perform\nthe maximum likelihood optimization.\n\n\\subsection{Linear dynamical system}\nIn a linear dynamical system (LDS), \neach observed data point is a sequence, \n$\\x = \\sequence$, and our dataset\nis a collection of $\\numdata$ such sequences, $\\data = \\sequencen$.\nWe focus on stochastic LDSs where\nthe transition function is probabilistic.\nThe underlying structure class for the\ntransition function\nis linear-Gaussian $p(\\state_{\\t + 1} \\given \\state_t, \\dynmat, \\dyncovar) = \\N(\\dynmat \\state_\\t, \\dyncovar)$ with learnable parameters $\\dynmat, \\dyncovar$.\nAlthough the underlying structure in this situation\nis not discrete, as in the case\nof flat or hierarchical clusterings, it is still\nan assumption about the organization of data. Intuitively,\nan LDS structure implies that data that temporally\nclose to each other are a simple transition away from each other.\nStructure learning in an LDS amounts\nto solving the maximum\nlikelihood problem\n\\begin{align*}\n    \\dynmat^*, \\dyncovar^* = \\argmax_{\\dynmat, \\dyncovar} \\prod_{n = 1}^N \\prod_{\\t = 1}^{\\T - 1} \\p(\\state^{(\\n)}_{\\t + 1} \\given \\state^{(\\n)}_\\t, \\dynmat, \\dyncovar)\n\\end{align*}\nand lends itself to a closed-form solution, namely\nlinear regression. This formulation can also be visualized\nas a graphical model, shown in \\autoref{fig:graphical-model-lds}.\n\n\\begin{figure}[htp!]\n    \\centering\n    \\includegraphics{tikz/lds}\n    \\caption{The graphical model for a linear dynamic system}\n    \\label{fig:graphical-model-lds}\n\\end{figure}\n\n\\subsection{Hierarchical clustering}\nHierarchical clustering is a structure learning problem\nwhere the structure class is trees. Specifically,\ngiven a dataset $\\dataset$,\nwe are interested in rooted trees with $\\numdata$ leaves\nwith each leaf corresponding to a data point.\nSuch a tree encodes relationships between data: \nif data points $a$ and $b$ are close in data space, we'd hope\nthe leaves corresponding to $a$ and $b$ appear closer\ntogether in a tree that captures the data's structure.\n\nAlgorithms for hierarchical clustering can be broadly\ndivided into two categories: divisive and agglomerative.\nDivisive, or top-down, clustering algorithms recover a tree by recursively\npartitioning data until just leaves remain. Examples\ninclude spectral clustering \\citep{Shi2000} and recursive $\\numcluster$-means.\nAgglomerative, or bottom-up, clustering algorithms\ninitialize clusters as leaves, and recursively\nmerge clusters until a full binary tree is formed.\nPairs of clusters to merge are chosen according to\na heuristic, also called a linkage-criterion,\nan example of which is single-linkage,\nwhere clusters are merged according to the minimum\ndistance between data points in each cluster.\n\nHierarchical clustering can also be formalized as an optimization problem\nby minimizing carefully constructed cost\nfunction,\n$C(\\structure, \\dataset)$,\nas shown in \\citet{Dasgupta2016}.\nTreating this cost as the\nenergy in a Gibbs distribution,\nwe can also frame hierarchical clustering\nas a probabilistic model\n$\\p(\\dataset \\given \\tree) = \\exp{-C(\\tau, \\dataset)/T}$ for some temperature $T$.\nRecovering a hierarchical clustering of the\ndata is therefore a maximum likelihood problem:\n\\begin{align*}\n    \\tree^* = \\argmax_{\\tree} \\exp{-C(\\tau, \\dataset)/T}\n\\end{align*}\n\n\\citet{Dasgupta2016} uses a greedy algorithm\nto optimize this likelihood.\nThe graphical model for hierarchical clustering is pictured in \\autoref{fig:graphical-model-hc}.\n\n\\begin{figure}[htp!]\n    \\centering\n    \\includegraphics{tikz/hc}\n    \\caption{Graphical model for hierarchical clustering}\n    \\label{fig:graphical-model-hc}\n\\end{figure}\n\n\\section{Bayesian structure learning}\n\nStructure learning is a useful generalization\nof several popular problems. However, it has some\ndrawbacks in its presented formulation.\nConsider a dataset that has ambiguity in its\nlatent structure. For example, in \\autoref{fig:ambiguous-structure}, we picture two examples of ambiguous latent structure. In a hierarchical clustering problem, if data are positioned in particular ways, we could organize the data\nin several plausible ways. In one example, there are\nthree equally valid hierarchical clusterings (using binary trees), and in the second example, there are two\nplausible clusterings. Structure learning as presented\ncannot disambiguate between equally valid clusterings or indicate to a user that there exist alternative candidates.\n\n\\begin{figure*}[htp!]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{img/structure/3-cluster-both}\n    \\caption{Examples of ambiguous hierarchical structure in data. The left set of points could plausibly be hierarchically clustered in three different ways. The right set of points has two plausible hierarchical clusterings.}\n    \\label{fig:ambiguous-structure}\n\\end{figure*}\n\nBayesian structure learning (BSL) puts a prior on the structure class $\\p(\\structure)$, and rather than\nreturning a candidate structure $\\structure^*$,\nit returns a posterior distribution over all\nstructures $\\p(\\structure \\given \\dataset)$. It generalizes \nvanilla structure learning, as $\\p(\\structure \\given \\dataset)$ could,\nin principle,\nbe a delta distribution for a single candidate structure.\nIn practice, however, the BSL\nformulation enables algorithms that capture\nuncertainty and ambiguity in how data is organized.\nIn \\autoref{fig:ambiguous-structure-probability},\nwe picture the same ambiguous hierarchical clusterings\nalong with the intuitively correct distribution over possible clusterings. \n\n\\begin{figure*}[htp!]\n    \\centering\n    \\begin{subfigure}{\\textwidth}\n        \\centering\n        \\includegraphics[width=0.7\\textwidth]{img/structure/3-cluster-distribution}\n        \\caption{}\n    \\end{subfigure}\n    \\begin{subfigure}{\\textwidth}\n        \\centering\n        \\includegraphics[width=0.7\\textwidth]{img/structure/3-cluster-linear-distribution}\n        \\caption{}\n    \\end{subfigure}\n    \\caption{Examples of how Bayesian structure learning could uncover ambiguity in latent structure. In (a), all three possible clusterings are given equal probability and in (b), the two most likely clusterings split the probability.}\n    \\label{fig:ambiguous-structure-probability}\n\\end{figure*}\n\nBSL can be formalized\nas a latent variable model,\nwhere we assume a prior over structures $\\p(\\structure)$,\nand a likelihood model $p(\\dataset \\given \\structure)$.\nThe goal is then to perform Bayesian\ninference to obtain the posterior distribution $p(\\structure \\given \\dataset)$. The simple graphical model for this generative process is pictured in \\autoref{fig:graphical-model-bsl}.\n\n\\begin{figure}[htp!]\n    \\centering\n    \\includegraphics[]{tikz/lvm}\n    \\caption{The graphical model for Bayesian structure learning. Note the addition of a prior distribution over the structure.}\n    \\label{fig:graphical-model-bsl}\n\\end{figure}\n\nThe design space of Bayesian structure learning\namounts to first deciding a structure class (hierarchical clusterings, flat clusterings, linear dynamical systems, etc.) and additionally choosing a\nparticular prior distribution over the structures.\nThere is interest, however, in developing strategies for automatically\ninferring structure class through search \\citep{Kemp2008, Grosse2012}.\nOnce a structure class and prior are selected, computing the posterior distribution $\\p(\\structure \\given \\dataset)$ amounts to Bayesian inference,\nand more often than not this posterior distribution is analytically intractable and we must resort to\napproximate inference. Thus, in practice, we \nalso decide on an approximate inference strategy (variational inference, MCMC, etc.).\n\n\\subsection{Bayesian linear dynamical system}\n\nA Bayesian linear dynamical system (BLDS)\nis an LDS with the addition of a prior\nover the transition matrix and noise covariance. \nAlthough there are many choices of prior,\nin this thesis, we use the matrix-Normal-inverse-Wishart (MNIW) prior, which is conjugate, details of which\nare located in \\autoref{sec:stats-mniw}.\n\nThe choice of this prior results in a generative model\n\\begin{align*}\n    \\dynmat, \\dyncovar &\\sim MNIW(\\Psi, \\dynmat_0, V, \\nu) \\\\\n    \\state_{\\t + 1} | \\state_t, \\dynmat, \\dyncovar &\\sim \\N(\\dynmat \\state_t, \\dyncovar)\n\\end{align*}\nwhich is also visualized in \\autoref{fig:graphical-model-blds}.\n\n\\begin{figure}[htp!]\n    \\centering\n    \\includegraphics[]{tikz/blds}\n    \\caption{The graphical model for a Bayesian linear dynamical system. Note the addition of a prior over the dynamics parameters.}\n    \\label{fig:graphical-model-blds}\n\\end{figure}\n\nBecause the MNIW prior is conjugate\nwith a linear dynamical system likelihood,\nthe posterior distribution $\\p(\\dynmat, \\dyncovar \\given \\sequencen)$ is also MNIW\nand can be computed in closed form. This structure class\nis explored in more detail in \\autoref{chap:solar}.\n\nAnother structure class of interest is trees,\nspecifically hierarchical clusterings.\nIn the next chapter, we detail\nhow hierarchical clustering can be formalized \nin the Bayesian structure learning framework.\n", "meta": {"hexsha": "c8e69706ffbed8159cc4c8f70e610c6fd7cb790d", "size": 11562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/content/structure/structure-learning.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/structure-learning.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/structure-learning.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": 51.6160714286, "max_line_length": 306, "alphanum_fraction": 0.7841203944, "num_tokens": 2736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.6607532837784774}}
{"text": "% !TeX root = ../main.tex\n\\section{Type Rule Derivation Tree Example}\n\\label{sec:typeRuleTree}\nThis is an example of how to create a type derivation tree for a program written in HCL. It is based on the following code snippet.\n\n\\begin{lstlisting}[language=HCL]\nnum x = 5\nbool b = x greaterThan 0\nb print\n\\end{lstlisting}\n\nThe program calls two functions, $greaterThan$ and $print$.\nThey are declared with the following types:\n\n\\begin{lstlisting}[language=HCL]\nfunc[num, num, bool] greaterThan # Two number parameters, returns bool\nfunc[bool, none] print # overloaded to take a bool parameter, returns nothing\n\\end{lstlisting}\n\nFollowing the type rules specified in section \\ref{typerules}, this derivation tree will be produced:\n\\begin{center}\n\t\\begin{math}\n\t\t\\cfrac\n\t\t{\\cfrac\n\t\t\t{E\\vdash 5 : num}\n\t\t\t{E\\vdash num\\ x = 5 : \\texttt{ok}}\\quad \\cfrac\n\t\t\t\t{\\cfrac\n\t\t\t\t\t{\\cfrac\n\t\t\t\t\t\t{E(x) : num\\quad E \\vdash 0 : num}\n\t\t\t\t\t\t{E\\vdash x\\ greaterThan\\ 0: bool}}\n\t\t\t\t\t{E\\vdash bool\\ b = x\\ greaterThan\\ 0 : \\texttt{ok}}\\quad \\cfrac\n\t\t\t\t\t{E\\vdash b : bool}\n\t\t\t\t\t{E\\vdash b\\ print : (none, \\texttt{ok})}}\n\t\t\t\t{E\\vdash bool\\ b = x\\ greaterThan\\ 0;\\ b\\ print : \\texttt{ok}}}\n\t\t{E \\vdash num\\ x = 5;\\ bool\\ b = x\\ greaterThan\\ 0;\\ b\\ print : \\texttt{ok}}\n\t\\end{math}\n\\end{center}", "meta": {"hexsha": "308097f9a2457faafdeed16a4b79d38a5eb03890", "size": 1266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Appendix/TypeTree.tex", "max_stars_repo_name": "C0DK/P3-HCL", "max_stars_repo_head_hexsha": "b6adbc46cc7347aacd45dce5fddffd6fee2d37ac", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-08T12:34:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-09T11:33:53.000Z", "max_issues_repo_path": "report/Appendix/TypeTree.tex", "max_issues_repo_name": "C0DK/P3-HCL", "max_issues_repo_head_hexsha": "b6adbc46cc7347aacd45dce5fddffd6fee2d37ac", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2018-02-17T14:30:17.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-13T17:37:09.000Z", "max_forks_repo_path": "report/Appendix/TypeTree.tex", "max_forks_repo_name": "C0DK/P3-HCL", "max_forks_repo_head_hexsha": "b6adbc46cc7347aacd45dce5fddffd6fee2d37ac", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-04T13:55:53.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-04T13:55:53.000Z", "avg_line_length": 34.2162162162, "max_line_length": 131, "alphanum_fraction": 0.6753554502, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6607532764084506}}
{"text": "\\subsection{Tranformations}\r\n\\dfont{Transformations} are operations we can apply to a function in order to obtain a \\ifont{new} function.\r\nThe most common transformations include translations, stretches and reflections.\r\nWe summarize these below.\r\n\r\n\\begin{center}\r\n\\framebox{\r\n$\\begin{array}{ccccl}\r\n\\mbox{\\underline{Function}}&\\qquad&\\mbox{\\underline{Conditions}}&\\qquad&\\mbox{\\underline{How to graph $F(x)$ given the graph of $f(x)$}}\\\\\r\nF(x)=f(x)+c&\\qquad&c>0&\\qquad&\\mbox{Shift $f(x)$ upwards by $c$ units}\\\\\r\nF(x)=f(x)-c&\\qquad&c>0&\\qquad&\\mbox{Shift $f(x)$ downwards by $c$ units}\\\\\r\nF(x)=f(x+c)&\\qquad&c>0&\\qquad&\\mbox{Shift $f(x)$ to the left by $c$ units}\\\\\r\nF(x)=f(x-c)&\\qquad&c>0&\\qquad&\\mbox{Shift $f(x)$ to the right by $c$ units}\\\\\r\n\\hline\r\nF(x)=-f(x)&\\qquad&~&\\qquad&\\mbox{Reflect $f(x)$ about the $x$-axis}\\\\\r\nF(x)=f(-x)&\\qquad&~&\\qquad&\\mbox{Reflect $f(x)$ about the $y$-axis}\\\\\r\n\\hline\r\nF(x)=|f(x)|&\\qquad&~&\\qquad&\\mbox{Take the part of the graph of $f(x)$ that lies}\\\\\r\n~&\\qquad&~&\\qquad&\\mbox{below the $x$-axis and reflect it about the $x$-axis}\\\\\r\n\\end{array}$}\r\n\\end{center}\r\n\r\nFor horizontal and vertical stretches, different resources use different terminology and notation. \r\nUse the one you are most comfortable with!\r\nBelow, both $a,b$ are positive numbers. Note that we only use the term \\ifont{stretch} in this case:\r\n\r\n\\begin{center}\r\n\\framebox{\r\n$\\begin{array}{ccccl}\r\n\\mbox{\\underline{Function}}&\\qquad&\\mbox{\\underline{Conditions}}&\\qquad&\\mbox{\\underline{How to graph $F(x)$ given the graph of $f(x)$}}\\\\\r\nF(x)=af(x)&\\qquad&a>0&\\qquad&\\mbox{Stretch $f(x)$ vertically by a factor of $a$}\\\\\r\nF(x)=f(bx)&\\qquad&b>0&\\qquad&\\mbox{Stretch $f(x)$ horizontally by a factor of $1/b$}\\\\\r\n\\end{array}$}\r\n\\end{center}\r\n\r\nIn the next case, we use both the terms \\ifont{stretch} and \\ifont{shrink}.\r\nWe also split up vertical stretches into two cases ($0<a<1$ and $a>1$), and split up horizontal stretches into two cases ($0<b<1$ and $b>1$).\r\nNote that having $0<a<1$ is the same as having $1/c$ with $c>1$.\r\nAlso note that \\ifont{stretching by a factor of $1/c$} is the same as \\ifont{shrinking by a factor $c$}.\r\n\r\n\\begin{center}\r\n\\framebox{ \r\n$\\begin{array}{ccccl}\r\n\\mbox{\\underline{Function}}&\\qquad&\\mbox{\\underline{Conditions}}&\\qquad&\\mbox{\\underline{How to graph $F(x)$ given the graph of $f(x)$}}\\\\\r\nF(x)=cf(x)&\\qquad&c>1&\\qquad&\\mbox{Stretch $f(x)$ vertically by a factor of $c$}\\\\\r\nF(x)=(1/c)f(x)&\\qquad&c>1&\\qquad&\\mbox{Shrink $f(x)$ vertically by a factor of $c$}\\\\\r\nF(x)=f(cx)&\\qquad&c>1&\\qquad&\\mbox{Shrink $f(x)$ horizontally by a factor of $c$}\\\\\r\nF(x)=f(x/c)&\\qquad&c>1&\\qquad&\\mbox{Stretch $f(x)$ horizontally by a factor of $c$}\\\\\r\n\\end{array}$}\r\n\\end{center}\r\n\r\nSome resources keep the condition $0<c<1$ rather than using $1/c$.\r\nThis is illustrated in the next table.\r\n\r\n\\begin{center}\r\n\\framebox{\r\n$\\begin{array}{ccccl}\r\n\\mbox{\\underline{Function}}&\\qquad&\\mbox{\\underline{Conditions}}&\\qquad&\\mbox{\\underline{How to graph $F(x)$ given the graph of $f(x)$}}\\\\\r\nF(x)=df(x)&\\qquad&d>1&\\qquad&\\mbox{Stretch $f(x)$ vertically by a factor of $d$}\\\\\r\nF(x)=df(x)&\\qquad&0<d<1&\\qquad&\\mbox{Shrink $f(x)$ vertically by a factor of $1/d$}\\\\\r\nF(x)=f(dx)&\\qquad&d>1&\\qquad&\\mbox{Shrink $f(x)$ horizontally by a factor of $d$}\\\\\r\nF(x)=f(dx)&\\qquad&0<d<1&\\qquad&\\mbox{Stretch $f(x)$ horizontally by a factor of $1/d$}\\\\\r\n\\end{array}$}\r\n\\end{center}\r\n\r\n\\begin{example}{Transformations and Graph Sketching}{TransformationsGraphSketching}\r\nIn this example we will use appropriate transformations to sketch the graph of the function $y=|\\sqrt{x+2}-1|-1$.\r\n\\end{example}\r\n\\begin{solution} \r\nWe start with the graph of a function we know how to sketch, in particular, $y=\\sqrt{x}$:\r\nTo obtain the graph of the function $y=\\sqrt{x+2}$ from the graph $y=\\sqrt{x}$, we must shift $y=\\sqrt{x}$ to the left by $2$ units.\r\nTo obtain the graph of the function $y=\\sqrt{x+2}-1$ from the graph $y=\\sqrt{x+2}$, we must shift $y=\\sqrt{x+2}$ downwards by $1$ unit.\r\n$$\\includegraphics[width=6in]{images/transf1}$$\r\nTo obtain the graph of the function $y=|\\sqrt{x+2}-1|$ from the graph $y=\\sqrt{x+2}-1$, we must take the part of the graph of $y=\\sqrt{x+2}-1$ that lies below the $x$-axis and reflect it (upwards) about the $x$-axis.\r\nFinally, to obtain the graph of the function $y=|\\sqrt{x+2}-1|-1$ from the graph $y=|\\sqrt{x+2}-1|$, we must shift $y=|\\sqrt{x+2}-1|$ downwards by $1$ unit:\r\n$$\\includegraphics[width=6in]{images/transf2}$$\r\n\\end{solution}", "meta": {"hexsha": "d5ce35a98872275ead1d93eaa51beafbc2b76f3c", "size": 4468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-2-1-transformations.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-2-1-transformations.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-2-1-transformations.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.025974026, "max_line_length": 217, "alphanum_fraction": 0.6700984781, "num_tokens": 1598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.6607532764084503}}
{"text": "\\paragraph{Question 2.}\n\nGiven the binary alphabet \\(\\Sigma = \\{a, b\\}\\) and the order on\nletters \\(a < b\\), write regular definitions for the following\nlanguages.\n\\begin{enumerate*}\n\n  \\item All words starting and ending with \\(a\\).\n\n  \\item All non-empty words.\n\n  \\item All words in which the third last letter is \\(a\\).\n\n  \\item All words containing exactly three \\(a\\).\n\n  \\item All words containing at least one \\(a\\) before a \\(b\\).\n\n  \\item All words in which the letters are in increasing order.\n\n  \\item All words with no letter following the same one.\n\n\\end{enumerate*}\n", "meta": {"hexsha": "eb06fc3af58251470105a740043b9209a2645cfc", "size": 581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regexp_question_02.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_02.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_02.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": 25.2608695652, "max_line_length": 64, "alphanum_fraction": 0.6953528399, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6607532635109034}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 4}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\n\\section{Expectation of discrete random variables}\nThe intuition of expectation is the \\emph{average value} of an experiment. Suppose we do an experiment for $N$ repeated times. The probability of each possible outcome $x$ can be approximately defined by \n\\begin{equation*}\n    \\Prob(x) \\approx f(x) = \\frac{freq(x)}{N}.\n\\end{equation*}\nThen the average outcome is\n\\begin{equation*}\n    m \\approx \\frac{1}{N}\\sum_{x} freq(x)x = \\sum_x f(x)x\n\\end{equation*}\n\n\\begin{definition}\nThe \\textbf{mean value}, or \\textbf{expectation}, or \\textbf{expected value} of the random variable $X$ with mass function $f$ is defined to be \n\\begin{equation*}\n    \\Exp(X) = \\sum_{x:f(x)>0} xf(x)\n\\end{equation*}\nwhenever this sum is absolutely convergent.\n\\end{definition}\n\n\\begin{remark}\n\\begin{enumerate}[(a)]\n    \\item For notation convenience, we also write $\\Exp(X) = \\sum_x xf(x)$.\n    \\item We require \\textbf{absolute convergence} in order that $\\Exp(X)$ be unchanged by reordering the $x_i$. \n\\end{enumerate}\n\\end{remark}\n\n\\begin{theorem}[Riemann Rearrangement Theorem] \\href{https://en.wikipedia.org/wiki/Riemann_series_theorem}{See this: Riemann series theorem}.\n\\end{theorem}\n\n\\begin{lemma}\nIf $X$ has mass function $f$ and $g:\\R\\to\\R$, then\n\\begin{equation*}\n    \\Exp(g(x)) = \\sum_x g(x) f(x)\n\\end{equation*}\nwhenever this sum is absolutely convergent.\n\\end{lemma}\n\n\\begin{example}\nIf $X$ is a random variable with mass function f, and $g(x) = x^2$, then \n\\begin{equation*}\n    \\Exp(X^2) = \\sum_x g(x)f(x) = x^2 f(x).\n\\end{equation*}\n\\end{example}\n\n\\begin{definition}\nIf $k$ is a positive integer, the $k$th \\text{moment} $m_k$ of $X$ is defined to be \n\\begin{equation*}\n    m_k = \\Exp(X^k).\n\\end{equation*}\nThe $k$th \\textbf{central moment} $\\sigma_k$ is defined as\n\\begin{equation*}\n    \\sigma_k = \\Exp\\left( (X-m_1)^k \\right) = \\Exp\\left( (X-E(X))^k \\right).\n\\end{equation*} \n\\end{definition}\n\nThe two moments of most use are $m_1 = \\Exp(X)$ and $\\sigma_2 = \\Exp( (X - \\Exp(X))^2$, called the \\textbf{mean} (or \\textbf{expectation)} and \\textbf{variance} of $X$. These two quantities are measures of the mean and dispersion of $X$; that is, $m_1$ is the average value of $X$, and $\\sigma_2$ measures the amount by which $X$ tends to deviate from this average. The mean $m_1$ is often denoted $\\mu$, and the variance of $X$ is often denoted $\\Var(X)$. The positive square root $\\sigma = \\Var(X)$ is called the \\textbf{standard deviation}, and in this notation $\\sigma_2 = \\sigma^2$. \n\nThe central moments $\\{\\sigma_i\\}$ can be expressed in terms of the ordinary moments $\\{m_i\\}$. For example, $\\sigma_1 = 0$, and \n\\begin{equation*}\n    \\begin{aligned} \n        \\sigma_{2} &=\\sum_{x}\\left(x-m_{1}\\right)^{2} f(x) \\\\ \n        &=\\sum_{x} x^{2} f(x)-2 m_{1} \\sum_{x} x f(x)+m_{1}^{2} \\sum_{x} f(x) \\\\ \n        &=m_{2}-m_{1}^{2} ,\n    \\end{aligned}\n\\end{equation*}\nwhich may be written as \n\\begin{equation}\n    \\label{eq:4-1}\n    \\tag{4-1}\n    \\Var(X) = \\Exp\\left( (X-E(X))^2 \\right) = \\Exp(X^2) - \\Exp(X)^2.\n\\end{equation}\n\n\\begin{example}[Binomial variables]\nLet $X$ be a random variable with binomial distribution. The p.m.f. is \n\\begin{equation*}\n    f(k) = \\binom{n}{k} p^k q^{n-k} \\quad k = 0,\\dots, n,\n\\end{equation*}\nwhere $q = 1-p$. The expectation of $X$ is\n\\begin{equation*}\n    \\Exp(X) = \\sum_{k=0}^n k f(k) = \\sum_{k=0}^n k\\binom{n}{k} p^k q^{n-k}.\n\\end{equation*}\nWe use the following algebraic identity to compute $\\Exp(X)$.\n\\begin{equation}\n    \\label{eq:4.2}\n    \\tag{4-2}\n    \\sum_{k=0}^n \\binom{n}{k} x^k = (1+x)^n, \n\\end{equation}\nDifferentiate it and multiply by $x$, we obtain \n\\begin{equation}\n    \\label{eq:4.3}\n    \\tag{4-3}\n    \\sum_{k=0}^n k \\binom{n}{k} x^k = nx(1+x)^{n-1}. \n\\end{equation}\nWe substitute $x = p / q$ to obtain $\\Exp(X) = np$. A similar argument shows that the variance of $X$ is given by $\\Var(X) = npq$. \n\\end{example}\n\nWe can think of the process of calculating expectations as a \\textbf{linear operator} on the space of random variables. \n\n\\begin{theorem}\nThe expectation operator $\\Exp$ has the following properties: \n\\begin{enumerate}[(a)]\n    \\item if $X\\geq 0$, then $\\Exp(X) \\geq 0$,\n    \\item if $a, b \\in \\R$, then $\\Exp(aX+bY) = a\\Exp(X) + b\\Exp(Y)$,\n    \\item the random variable 1, taking the value 1 always, has expectation $\\Exp(1) = 1$. \n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nWe only prove the second property, which is also called the linear property.\n\nWe must use the joint p.m.f. of $X$ and $Y$ to compute the expectation. \n\\begin{equation*}\n    \\begin{split}\n        \\Exp(aX+bY) &= \\sum_{i, j} (ax_i + by_j) f(x_i, y_j) \\\\\n        &= a \\sum_{i,j} x_i f(x_i, y_j) + b\\sum_{i,j} y_j f(x_i, y_j) \\\\\n        &= a\\sum_{i} x_i f_X(x_i) + b\\sum_{j}y_j f_Y(y_j) \\\\ \n        &= a\\Exp(X) + b\\Exp(Y),\n    \\end{split}\n\\end{equation*}\nwhere $f_X(x)$ and $f_Y(y)$ are marginal p.m.f. of $X$ and $Y$ respectively.\n\\end{proof}\n\n\\begin{caution}\nIt is \\textbf{NOT} in general true that $\\Exp(XY)$ is the same as $\\Exp(X)\\Exp(Y)$. \n\\end{caution}\n\n\\begin{lemma}\nIf $X$ and $Y$ are independent, then $\\Exp(XY) = \\Exp(X)\\Exp(Y)$. \n\\end{lemma}\n\\begin{proof}\nIf $X, Y$ are independent, $f(x,y) = f_X(x) f_Y(y)$. Then\n\\begin{equation*}\n    \\Exp(XY) = \\sum_{ij} x_i y_j f(x,y) = \\sum_{i} \\left( x_i f_X(x_i) \\right) \\sum_{j} \\left( y_j f_Y(y_j) \\right) = \\Exp(X) \\Exp(Y).\n\\end{equation*}\n\\end{proof}\n\n\\begin{definition}\n$X$ and $Y$ are called \\textbf{uncorrelated} if $\\Exp(XY) = \\Exp(X)\\Exp(Y)$.\n\\end{definition}\n\n\\begin{caution}\nIndependent variables are uncorrelated. But the converse is \\textbf{NOT} true.\n\\end{caution}\n\n\\begin{theorem}\nFor random variables $X$ and $Y$, \n\\begin{enumerate}[(a)]\n    \\item $\\Var(aX) = a^2 \\Var(X)$ for $a \\in \\R$,\n    \\item $\\Var(X+Y) = \\Var(X) + \\Var(Y)$ is $X$ and $Y$ are uncorrelated.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{remark}\nThe above theorem shows that the variance operator $\\Var$ is \\textbf{NOT} a linear operator, even when it \nis applied only to uncorrelated variables. \n\\end{remark}\n\n%==============================================\nSometimes the sum $S = \\sum xf(x)$ does not converge absolutely, which means the mean of the distribution does not exist. Here is an example. \n\\begin{example}\n\\textbf{A distribution without a mean.} Let $X$ have mass function \n\\begin{equation*}\n    f(k) = Ak^{-1} \\quad k = \\pm 1, \\pm 2, \\dots,\n\\end{equation*}\nwhere $A$ is chosen so that $\\sum_k f(k) = 1$. The sum $\\sum_k kf(k) = A\\sum_{k\\neq 0} k^{-1}$ doesn't converge absolutely, because both the positive and the negative parts diverge. \n\\end{example}\nThis example is suitable to point out that we can base probability theory upon the expectation operator $\\Exp$ rather than upon the probability measure $\\Prob$. Roughly speaking, the way we proceed is to postulate axioms, such as (a)-(c) of the above Theorem, for a so-called ``expectation operator\" $\\Exp$ acting on a space of ``random variables\". The probability of an event can then be recaptured by defining $\\Prob(A) = \\Exp(I_A)$.  \n\nRecall the indicator function of a set $A$ is defined as\n\\begin{equation*}\n    I_A(\\omega) = \\begin{cases} 1 & \\omega \\in A, \\\\\n    0 & \\omega \\not\\in A. \\end{cases}\n\\end{equation*}\nIn addition, we have $\\Exp(I_A) = \\Prob(A)$.\n\n%==============================================\n\n\\section{Dependence of discrete random variables}\n\\begin{definition}\nThe \\textbf{joint distribution function} $F:\\R^2 \\to [0,1]$ of $X$ and $Y$, where $X$ and $Y$ are discrete variables, is given by \n\\begin{equation*}\n    F(x, y) = \\Prob(X\\leq x \\text{ and } Y \\leq y). \n\\end{equation*}\nTheir \\textbf{joint mass function} $f:\\R^2 \\to [0,1]$ is given by \n\\begin{equation*}\n    f(x,y) = \\Prob(X = x \\text{ and } Y = y). \n\\end{equation*}\n\\end{definition}\n\nWe write $F_{X,Y}$ and $f_{X,Y}$ when we need to stress the role of $X$ and $Y$. We may think of the joint mass function in the following way. If $A_x = \\{X = x\\}$ and $B_y = \\{Y = y\\}$, then \n\\begin{equation*}\n    f(x,y) = \\Prob(A_x \\cap B_y).\n\\end{equation*}\n\n\\begin{lemma}\nThe discrete random variables $X$ and $Y$ are \\textbf{independent} if and only if \n\\begin{equation}\n    \\label{eq:4.4}\n    \\tag{4-4}\n    f_{X,Y}(x,y) = f_X(x)f_Y(y) \\quad \\forall x,y \\in \\R.\n\\end{equation}\nMore generally, $X$ and $Y$ are independent if and only if $f_{X,Y}(x, y)$ can be \\textbf{factorized as the product} $g(x)h (y)$ of a function of $x$ alone and a function of $y$ alone. \n\\end{lemma}\n\\begin{remark}\nWe stress that the factorization \\eqref{eq:4.4} must hold for all $x$ and $y$ in order that $X$ and $Y$ be independent. \n\\end{remark}\n\n\\begin{lemma}\n\\begin{equation*}\n    \\Exp(g(X, Y))=\\sum_{x, y} g(x, y) f_{X, Y}(x, y).\n\\end{equation*}\n\\end{lemma}\n\n\\begin{definition}\nThe \\textbf{covariance} of $X$ and $Y$ is\n\\begin{equation*}\n    \\cov(X,Y) = \\Exp\\left( (X-\\Exp(X))(Y-\\Exp(Y)) \\right).\n\\end{equation*}\nThe \\textbf{correlation (coefficient)} of $X$ and $Y$ is \n\\begin{equation*}\n\\corr(X, Y) = \\rho(X,Y) = \\frac{\\cov(X,Y)}{\\sqrt{\\Var(X)\\Var(Y)}}\n\\end{equation*}\nas long as the variances are non-zero. \n\\end{definition}\n\n\\begin{remark}\nNotice the following two equations.\n\\begin{enumerate}\n    \\item $\\cov(X,X) = \\Var(X)$,\n    \\item $\\cov(X,Y) = \\Exp(XY) - \\Exp(X)\\Exp(Y)$.\n\\end{enumerate}\n\\end{remark}\n\nCovariance itself is not a satisfactory measure of dependence because the scale of values which $\\cov(X, Y)$ may take contains no points which are clearly interpretable in terms of the relationship between $X$ and $Y$.\n\n\\begin{theorem}[Cauchy-Schwarz inequality] For random variables $X$ and $Y$, \n\\begin{equation*}\n    \\Exp(XY)^2 \\leq \\Exp(X^2) \\Exp(Y^2)\n\\end{equation*} \nwith equality if and only if $\\Prob(aX = bY) = 1$ for some real $a$ and $b$, at least one of which is non-zero. \n\\end{theorem}\n\n\\begin{proof}\nFor $a, b \\in \\R$, let $Z = aX - bY$. Then \n\\begin{equation*}\n    0 \\leq \\Exp(Z^2) = a^2 \\Exp(X^2) - 2ab\\Exp(XY) + b^2\\Exp(Y^2).\n\\end{equation*}\nThus the right-hand side is a quadratic in the variable $a$ with at most one real root. Its discriminant must be non-positive. That is to say, if $b \\neq 0$, \n\\begin{equation*}\n    \\Exp(XY)^2 - \\Exp(X^2) \\Exp(Y^2) \\leq 0. \n\\end{equation*}\nThe discriminant is zero if and only if the quadratic has a real root. This occurs if and only if \n\\begin{equation*}\n    \\Exp\\left( (aX-bY)^2 \\right) = 0\n\\end{equation*}\nfor some $a$ and $b$.\n\\end{proof}\n\nWe define $X' = X-\\Exp(X), Y' = Y - \\Exp(Y)$. Since all $X, Y$ satisfy the Cauchy-Schwarz inequality, so do $X'$ and $Y'$. Therefore, \n\\begin{equation*}\n    \\Exp(X'Y')^2 \\leq \\Exp(X'^2) \\Exp(Y'^2) \\quad \\Leftrightarrow \\quad \\cov(X, Y)^2 \\leq \\Var(X)\\Var(Y).\n\\end{equation*}\nTherefore, \n\\begin{equation*}\n    \\rho(X,Y)^2 \\leq 1 \\quad \\Rightarrow \\quad \\rho(X,Y) \\in [-1, 1].\n\\end{equation*}\nwhich gives the following lemma.\n\n\\begin{lemma}\nThe correlation coefficient $\\rho$ satisfies $\\abs{\\rho (X, Y) } \\leq 1$ with equality if and only if $\\Prob(aX + bY = c) = 1$ for some $a, b, c \\in \\R$. \n\\end{lemma}\n\n\n\\section{Expectation of continuous random variables}\n\\subsection{Idea of translating expectation from discrete to continuous}\nSuppose we have a continuous random variable $X$ with $f$ being the probability density function. We split $X$ into small intervals $\\Delta x$. Then $p_i = f(x_i)\\Delta x$. $\\frac{p_i}{\\Delta x}$ is an approximation of probability density function. Therefore, \n\\begin{equation*}\n    \\Exp(X) \\approx \\sum_{i} x_i p_i = \\sum_{i} x_i f(x_i) \\Delta x,\n\\end{equation*}\nwhich is the Remann sum. We take the limit and get\n\\begin{equation*}\n    \\Exp(x) = \\int_{-\\infty}^\\infty x f(x)dx.\n\\end{equation*}\n\n\\subsection{Expectation}\n\\begin{definition}\nThe \\textbf{expectation} of a continuous random variable $X$ with density function $f$ is given by \n\\begin{equation*}\n    \\Exp(X) = \\int_{-\\infty}^\\infty xf(x) dx\n\\end{equation*}\nwhenever this integral exists.\n\\end{definition}\n\n\\begin{theorem}\nIf $X$ and $g(X)$ are continuous random variables, then \\begin{equation*}\n    \\Exp\\left( g(X) \\right) = \\int_{-\\infty}^\\infty g(x)f(x) dx.\n\\end{equation*}\n\\end{theorem}\n\n\\begin{definition}\nThe $k$th \\textbf{moment} of a continuous variable $X$ is defined as\n\\begin{equation*}\n    \\Exp(X^k) = \\int_{-\\infty}^\\infty x^k f(x) dx\n\\end{equation*}\nwhenever the integral converges.\n\\end{definition}\n\n\\begin{example}[Cauchy distribution] The random variable $X$ has the Cauchy distribution t if it has density \nfunction \n\\begin{equation*}\n    f(x) = \\frac{1}{\\pi (1+x^2)}, \\quad x \\in \\R.\n\\end{equation*}\nThis distribution is notable for having \\textbf{no moments}.\n\\end{example}\n\n\\section{Dependence of continuous random variables}\n\\begin{definition}\nThe \\textbf{joint distribution function} of $X$ and $Y$ is the function $F: \\R^2 \\to [0, 1]$ given by \n\\begin{equation*}\n    F(x,y) = \\Prob(X\\leq x, Y \\leq y).\n\\end{equation*}\n\\end{definition}\n\n\\begin{definition}\nThe random variables $X$ and $Y$ are \\textbf{(jointly) continuous} with \\textbf{joint (probability) density function} $f : \\R^2 \\to [0, \\infty)$ if\n\\begin{equation*}\n    F(x, y)=\\int_{v=-\\infty}^{y} \\int_{u=-\\infty}^{x} f(u, v) d u d v \\quad \\text{for each } x, y\\in\\R. \n\\end{equation*}\nIf $F$ is sufficiently differentiable at the point $(x , y)$, then we usually specify \n\\begin{equation*}\n    f(x, y)=\\frac{\\partial^{2}}{\\partial x \\partial y} F(x, y).\n\\end{equation*}\n\\end{definition}\n\n\\begin{newnotion}{Probabilities}\n\\begin{equation*}\n    \\begin{aligned} \n        \\Prob(a \\leq X \\leq b, c \\leq Y \\leq d) &=F(b, d)-F(a, d)-F(b, c)+F(a, c) \\\\ \n        &=\\int_{y=c}^{d} \\int_{x=a}^{b} f(x, y) d x d y. \\end{aligned}\n\\end{equation*}\nIf $B$ is a sufficiently nice subset of $\\R^2$, then\n\\begin{equation*}\n    \\Prob \\left( (X, Y) \\in B \\right)=\\iint_{B} f(x, y) d x d y.\n\\end{equation*}\n\\end{newnotion}\n\\begin{newnotion}{Marginal distributions}\nThe marginal distribution functions of $X$ and $Y$ are\n\\begin{equation*}\n    F_{X}(x)=\\Prob(X \\leq x)=F(x, \\infty), \\quad F_{Y}(y)=\\Prob(Y \\leq y)=F(\\infty, y). \n\\end{equation*}\n\\begin{equation*}\n    F_{X}(x)=\\int_{-\\infty}^{x}\\left(\\int_{-\\infty}^{\\infty} f(u, y) d y\\right) d u.\n\\end{equation*}\nMarginal density function of $X$ and $Y$:\n\\begin{equation*}\n    f_{X}(x)=\\int_{-\\infty}^{\\infty} f(x, y) d y, \\quad f_{Y}(y)=\\int_{-\\infty}^{\\infty} f(x, y) d x.\n\\end{equation*}\n\\end{newnotion}\n\n\\begin{newnotion}{Expectation}\nIf $g: \\R^2 \\to \\R$ is a sufficiently nice function, then \n\\begin{equation*}\n    \\Exp(g(X, Y))=\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} g(x, y) f(x, y) d x d y;\n\\end{equation*}\nin particular, setting $g(x, y) = ax + by$, \n\\begin{equation*}\n    \\Exp(aX+bY) = a\\Exp(X) + b\\Exp(Y).\n\\end{equation*}\n\\end{newnotion}\n\n\\begin{newnotion}{Independence}\nThe random variables $X$ and $Y$ are independent if and only if \n\\begin{equation*}\n    F(x,y) = F_X(x) F_Y(y) \\quad \\forall x, y \\in \\R,\n\\end{equation*}\nwhich, for \\textbf{continuous random variables}, is equivalent to requiring that \n\\begin{equation*}\n    f(x,y) = f_X(x) f_Y(y).\n\\end{equation*}\n\\end{newnotion}\n \n\\begin{theorem}[Cauchy-Schwarz inequality] For any pair $X, Y$ of jointly continuous variables, we have that \n\\begin{equation*}\n    \\Exp(XY)^2 \\leq \\Exp(X^2) \\Exp(Y^2), \n\\end{equation*}\nwith equality if and only if $\\Prob(aX = bY) = 1$ for some real $a$ and $b$, at least one of which is non-zero. \n\\end{theorem}\n\n\n\\end{document}", "meta": {"hexsha": "299fdba9138e3146b138898089bd542b0dea9fd4", "size": 15481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_4.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_4.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_4.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": 38.6059850374, "max_line_length": 588, "alphanum_fraction": 0.6498288224, "num_tokens": 5497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.6607287271804809}}
{"text": "\\SecDef{properties}{Properties of the Decomposition}\n\n\\subsection{Cryptographic Properties}\nThe decomposition uncovers an interesting property of the 6-bit APN permutation $S_0$: it is affine-equivalent to a 6-bit APN involution $S_{\\inv}$. The DDT and the LAT of the involution $S_{\\inv}$ are illustrated in \\FigRef{ddt-lat} (the DDT of $\\Swap \\circ S_{\\inv} \\circ \\Swap$ is illustrated, because it has clearer structure). $S_{\\inv}$ has differential uniformity 2 and its linearity is 16. The left and right halves of the output of $S_{\\inv}$ have algebraic degree 4 and 3 respectively.\n\n\\FigTex{ddt-lat}\n\nWe used the algorithm from~\\cite{LinAffEQ} to find all pairs of affine self-equivalence mappings, i.e. maps $A,B\\in\\affbij{6}$ such that $S_{\\inv} = B \\circ S_{\\inv} \\circ A$. In~\\cite{LinAffEQ} it was suggested as a measure of symmetry of the permutation. The number of such pairs is invariant under affine-equivalence. Therefore, the decomposition is not necessary to count them. On the other hand, the decomposition shows that these maps have a simple expression. Let $(a,b)\\otimes(c,d) \\eqdef (ac, bd)$ denote the component-wise $\\fielde{3}$-multiplication. Then, for each $\\lambda \\in \\fielde{3},\\lambda \\ne 0$ the following holds for all $x,y\\in\\fielde{3}$:\n$$\nS_{\\inv}(\\lambda x, \\lambda^{-1}y) = (\\lambda, \\lambda^{-1}) \\otimes S_{\\inv}(x,y).\n$$\nThat is, multiplying the input halves by $\\lambda$ and $\\lambda^{-1}$ is equivalent to multiplying the output halves by $\\lambda$ and $\\lambda^{-1}$. In~\\SecRef{relations} it is shown that this property is similar to a property that the Kim mapping has.\n\n\\subsection{Univariate Representations}\n\nIn this section I show that there exist 6-bit APN permutations with simpler univariate polynomials, than a random permutation or the Dillon's APN permutation has. These results are based on interpolating the involution $S_{\\inv}$ in $\\fielde{6} \\simeq \\fielde{3} \\times \\fielde{3}$ using different field basis. This is done by composing $S_{\\inv}$ with linear maps corresponding to the basis change. All polynomial presented in this section are defined over $\\fielde{6} \\simeq \\field{}[v]/(v^6 + v^4 + v^3 + v + 1)$, where $v$ is primitive.\n\n\\textbf{Single polynomial.}\nIn~\\cite{DillonAPN}, the APN permutation was given as a univariate polynomial over $\\fielde{6}$ with 52 nonzero coefficients. Our decomposition allows to obtain an APN permutation from 25 monomials. The permutation $s$ of $\\fielde{6}$ given by\n\\begin{align*}\n    s(x) &= x^{58} + x^{51} + x^{44} + x^{37} + \\VV^{27}x^{36} + \\VV^{38}x^{32} + x^{30} \\\\\n         &+ \\VV^{53}x^{28} + \\VV^{7}x^{25} + \\VV^{51}x^{24} + x^{23} + \\VV^{53}x^{21} + \\VV^{7}x^{18} + \\VV^{24}x^{17}\\\\\n         &+ \\VV^{7}x^{16} + \\VV^{46}x^{14} + \\VV^{7}x^{11} + \\VV^{4}x^{10} + x^{9} + \\VV^{22}x^{8} + \\VV^{46}x^{7}\\\\\n         &+ \\VV^{3}x^{4} + \\VV^{50}x^{3} + \\VV^{56}x^{2} + \\VV^{52}x\n\\end{align*}\nis APN.\n\n\\textbf{Composition of 2 polynomials.}\nDillon~\\etal{} also represented $S_0$ as the composition $S_0 = f_2 \\circ f_1^{-1}$, where polynomials $f_1$ and $f_2$ contain 18 monomials each. Using our decomposition, we found more compact polynomials. Let $f_1', f_2'$ be permutations of $\\fielde{6}$ given by\n\\begin{align*}\nf_1'(x) &= \\VV^{11}x^{34} + \\VV^{53}x^{20} + x^{8} + x,\\\\\nf_2'(x) &= \\VV^{28}x^{48} + \\VV^{61}x^{34} + \\VV^{12}x^{20} + \\VV^{16}x^{8} + x^{6} + \\VV^{2}x.\n\\end{align*}\nThen $f_2' \\circ f_1'^{-1}$ is an APN permutation.\n\n\\textbf{Composition of 3 polynomials.}\nFinally, the representation becomes even simpler if 3 functions are used in the composition. Let $i,m$ be permutations of $\\fielde{6}$ given by\n$$\ni(x) = \\VV^{21}x^{34} + x^{20} + x^8 + x, \\quad\nm(x) = \\VV^{52}x^8 + \\VV^{36}x.\n$$\nThen $i \\circ m \\circ i^{-1}$ is an APN permutation. Similarly, let $i',m'$ be permutations of $\\fielde{6}$ given by\n$$\ni'(x) = \\VV^{37}x^{48} + x^{34} + \\VV^{49}x^{20} + \\VV^{21}x^{8} + \\VV^{30}x^{6} + x, \\quad\nm'(x) = x^8.\n$$\nThen $i' \\circ m' \\circ i'^{-1}$ is also an APN permutation.\nThese decompositions are obtained by interpolating parts of the decomposition separately. $i$ and $i'$ correspond to the part with the inverses and $m,m'$ correspond to the central linear layer.\n", "meta": {"hexsha": "107247e968b8cad309b13831e18972cfdca0ed32", "size": 4197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strAPN/2properties.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/2properties.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/2properties.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": 85.6530612245, "max_line_length": 663, "alphanum_fraction": 0.6726233024, "num_tokens": 1440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6606824886573149}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{cctbx_preamble}\n\\usepackage{amscd}\n\\usepackage{latexsym}\n\\usepackage{listings}\n\\lstset{language=Python,tabsize=2,columns=spaceflexible}\n\n\\title{Change of Basis\\\\of\\\\Electron Density and Structure Factors}\n\\author{\\lucjbourhis}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\section{Change of basis}\n\n\\subsection{Transformations}\n\nLet us consider two frames of the real space, $\\mathcal{R}=(\\omega, e_1, e_2, e_3)$ and $\\mathcal{R}'=(\\omega', e'_1, e'_2, e'_3)$, where $\\omega$ and $\\omega'$ are the origins and $\\{e_i\\}$ and $\\{e'_j\\}$ are the basis vectors. The 3-vector of coordinates $x$ and $x'$ of a site in respectively $\\mathcal{R}$ and $\\mathcal{R}'$ are related by\n\\begin{equation}\nx' = \\sym{R}{t}x.\n\\label{eqn:change::of::basis::position}\n\\end{equation}\nwhere $\\sym{R}{t}$ is the change-of-basis operator from $\\mathcal{R}$ to $\\mathcal{R}'$. We will only consider the case where $\\sym{R}{t}$ is orthogonal and the unit cell $U$ is invariant under $R$.\n\nA corollary is the corresponding law for the miller indices,\n\\begin{equation}\nh' = hR^{-1}.\n\\label{eqn:change::of::basis::miller::index}\n\\end{equation}\nand therefore\n\\begin{equation}\nh'x' = hx + h't\n\\label{eqn:change::of::basis::hx}\n\\end{equation}\nIndeed, since scalar product should be independent of the basis, $h'$ must statisfy\\footnote{It is most natural in crystallography to represent any position $x$ by a column vector and any miller index $h$ by a row vector (mathematically speaking $h$ is in the reciprocal space of $x$ and therefore $h$ is really a linear form). Therefore the scalar product $h.x$ reads like the mere matrix product $hx$ and the operator relation $h.Rx = R^Th.x$ is the trivial matrix product $hRx$ interpreted in two ways using associativity.} $h'\\Delta x' = h\\Delta x$ for any vector $\\Delta x'$ (as opposed to the point\\footnote{Let's not forget the positions make an affine space whereas the miller indices are only the reciprocal of the associated vector space and of course \\eqnref{change::of::basis::position} results in $\\Delta x' = R \\Delta x$} $x$).\n\nThe transformation law for the electron density $\\rho(x)$ and $\\rho'(x')$ in the respective frames \n$\\mathcal{R}$ and $\\mathcal{R}'$ reads\n\\begin{equation}\n\\rho'(x') = \\rho(x).\n\\label{eqn:change::of::basis::rho}\n\\end{equation}\nThe transformation for the structure factors can then be deduced from it,\n\\begin{align}\nF'(h') &= \\int_U \\rho'(x') e^{i2\\pi h'x'}d^3x', \\nonumber\\\\\n&= e^{i2\\pi h' t}  \\int_{\\sym{R}{t}^{-1}U} \\rho(x) e^{i2\\pi h x} d^3x, \\nonumber\\\\\n\\intertext{by using \\eqnref{change::of::basis::rho,change::of::basis::hx} and the Jacobian of $x \\mapsto \\sym{R}{t}x$ being 1 since $R$ is orthogonal. Thus the invariance of $U$ and the periodicity of $\\rho$ results in}\nF'(h') &= e^{i2\\pi h't} F(h).\n\\label{eqn:change::of::basis::F}\\\\\n\\intertext{or equivalently with \\eqnref{change::of::basis::miller::index}}\nF'(h) &= e^{i2\\pi ht} F(hR)\n\\label{eqn:change::of::basis::F::bis}\n\\end{align}\n\n\\subsection{Implementation}\n\n\\Eqnref{change::of::basis::F} is the formula implemented in the \\cctbx\\ in \\code{sym\\_equiv.h}, c.f. \\code{sym\\_equiv\\_index::phase\\_eq} and its use in \\code{change\\_basis.h}. It is particularly convenient since a \\code{miller.array} stores $h$ and $F(h)$ in two parallel arrays. By looping over the both of them at the same time, one can compute and immediately store the new miller index $h'$ and the value $F'(h')$ for that new miller index. However it means that the ordering of the original and new data are related as follow\n\\begin{equation}\n\\begin{CD}\n\\ldots @. \\ldots\\\\\nF(h_{i-1}) @= F'(h'_{i-1})\\\\\nF(h_i) @= F'(h'_i)\\\\\nF(h_{i+1}) @= F'(h'_{i+1})\\\\\n\\ldots @. \\ldots\n\\end{CD}\n\\label{eqn:miller::array::change::basis}\n\\end{equation}\n\nOnce the array $\\{F'(h')\\}$ is computed, one can move back to the more natural memory layout\n\\begin{equation}\n\\begin{CD}\n\\ldots @. \\ldots\\\\\nF(h_{i-1}) @= F'(h_{i-1})\\\\\nF(h_i) @= F'(h_i)\\\\\nF(h_{i+1}) @= F'(h_{i+1})\\\\\n\\ldots @. \\ldots\n\\end{CD}\n\\label{eqn:miller::array::transform}\n\\end{equation}\nwith the following one-liner\n\\begin{lstlisting}\n# op is (R|t) and f is a miller.array\noriginal, transform = f.common_set(\n\tf.change_basis(sgtbx.change_of_basis_op(op))\n\\end{lstlisting}\nif need be.\n\n\\section{Invariance and symmetry cross-correlation: an application}\n\nThe following questions are recurrent after any method processing a structure in P1: is the structure invariant under an operator $\\sym{R}{t}$ in some ``new'' basis which is not necessarily the ``old'' one we have done that processing in? That is true of the dual space solution method (Phenix.hyss, ShelXD) and also of charge flipping. In practice, the change of basis to consider from the old to the new basis is just a change of origin. The goal is to assess how well this symmetry holds and to find the origin shift.\n\nThe key change of variable to consider is\n\\begin{equation}\nx' - \\omega = \\sym{R}{t}(x - \\omega),\n\\end{equation}\nwhere $\\omega$ is the sought origin. So the change-of-basis operator is $\\sym{R}{t + (I-R)\\omega}$.\nThe sought symmetry is realised if the following invariance holds\\footnote{i.e. $\\rho = \\rho'$, as functions.}\n\\begin{equation}\n\\rho(x) = \\rho(x').\n\\end{equation}\nHow well this is realised can be quantified by considering the overlap of those two functions\n\\begin{align}\nc(\\omega) &= \\int_U \\rho(x) \\rho(x') d^3x.\\\\\n\\intertext{The bigger $c(\\omega)$, the better the symmetry and therefore one should find the value of $\\omega$ maximising $c(\\omega)$. Parseval theorem gives its equivalent in Fourier space,}\nc(\\omega) &= \\sum_h F(h) \\overline{F'(h)}. \\nonumber\\\\\n\\intertext{Then, with \\eqnref{change::of::basis::F::bis}, }\nc(\\omega) = c(d) &= \\sum_h F(h) \\overline{F(hR)} e^{-i 2\\pi h d}, \n\\end{align}\nby denoting $d=t + (I-R)\\omega$. This formula is a Fourier transform, which provides an efficient way to compute $c(d)$ on a grid over the entire unit cell to search for a maximum. It also features $F(hR)$ which is the result of applying the change-of-basis operator $\\sym{R}{0}$ to $F$. Thus, the \\code{cctbx} lets us compute $c(d)$ very easily:\n\\begin{lstlisting}\n# The rotation part r is a sgtbx.rot_mx and f is a miller.array\noriginal, transform = f.common_set(\n\tf.change_basis(sgtbx.change_of_basis_op(sgtbx.rt_mx(r)))\ncc = original * transform.conjugate().data() / original.sum_sq()\ncc_map = cc.fft_map(\n\tsymmetry_flags=maptbx.use_space_group_symmetry,\n\tresolution_factor=cc.d_min()) # e.g.\n\\end{lstlisting}\n\n\nAs a side note, in real space, that Fourier transform of the product $F(h) \\overline{F(hR)}$ is the convolution,\n\\begin{align}\nc(d) &= \\int_U \\rho(d-x) \\rho(-R^{-1}x) d^3x \\nonumber\\\\\n\\intertext{which can be recast as a cross-correlation,}\n&= \\int_U \\rho(x+d) \\rho(R^{-1}x) d^3x. \\nonumber\n\\end{align}\n\n\n\\end{document}  ", "meta": {"hexsha": "e34467ac3729daa0c59f44599d9209570776b066", "size": 6794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cctbx/miller/transform_and_change_of_basis.tex", "max_stars_repo_name": "rimmartin/cctbx_project", "max_stars_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 155, "max_stars_repo_stars_event_min_datetime": "2016-11-23T12:52:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:35:44.000Z", "max_issues_repo_path": "cctbx/miller/transform_and_change_of_basis.tex", "max_issues_repo_name": "rimmartin/cctbx_project", "max_issues_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 590, "max_issues_repo_issues_event_min_datetime": "2016-12-10T11:31:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T23:10:09.000Z", "max_forks_repo_path": "cctbx/miller/transform_and_change_of_basis.tex", "max_forks_repo_name": "rimmartin/cctbx_project", "max_forks_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 115, "max_forks_repo_forks_event_min_datetime": "2016-11-15T08:17:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T15:30:14.000Z", "avg_line_length": 52.2615384615, "max_line_length": 841, "alphanum_fraction": 0.7076832499, "num_tokens": 2190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6606824885650447}}
{"text": "\\section{Motion along a curve}\\label{sec:MotionAlongCurve}\n\nWe have already seen that if $t$ is time and an object's location is\ngiven by ${\\bf r}(t)$, then the derivative ${\\bf r}'(t)$ is the\nvelocity vector ${\\bf v}(t)$.\nJust as ${\\bf v}(t)$ is a vector describing how ${\\bf r}(t)$ changes,\nso is ${\\bf v}'(t)$ a vector describing how ${\\bf v}(t)$ changes,\nnamely, ${\\bf a}(t)={\\bf v}'(t)={\\bf r}''(t)$ is the \n\\dfont{acceleration vector}.\n\n\\begin{example}{}{}\nSuppose ${\\bf r}(t)=\\langle \\cos t,\\sin t,1\\rangle$. Then\n${\\bf v}(t)=\\langle -\\sin t,\\cos t,0\\rangle$ and \n${\\bf a}(t)=\\langle -\\cos t,-\\sin t,0\\rangle$. This describes the\nmotion of an object traveling on a circle of radius 1, with constant\n$z$ coordinate 1. The velocity vector is of course tangent to the\ncurve; note that ${\\bf a}\\cdot{\\bf v}=0$, so ${\\bf v}$ and ${\\bf a}$\nare perpendicular. In fact, it is not hard to see that ${\\bf a}$\npoints from the location of the object to the center of the circular\npath at $(0,0,1)$.\n\\end{example}\n\nRecall that the unit tangent vector is given by ${\\bf T}(t)=\n{\\bf v}(t)/|{\\bf v}(t)|$, so ${\\bf v}=|{\\bf v}|{\\bf T}$. If we take\nthe derivative of both sides of this equation we get\n\n\\begin{equation}\\label{eq:acceleration decomposition initial}\n{\\bf a}=|{\\bf v}|'{\\bf T}+|{\\bf v}|{\\bf T}'.\n\\end{equation}\n\nAlso recall the definition of the curvature,\n$\\kappa=|{\\bf T}'|/|{\\bf v}|$, or $|{\\bf T}'|=\\kappa|{\\bf v}|$. Finally,\n    recall that we defined the unit normal vector as\n${\\bf N}={\\bf T}'/|{\\bf T}'|$, so ${\\bf T}'=|{\\bf T}'|{\\bf N}=\n\\kappa|{\\bf v}|{\\bf N}$.\nSubstituting into Equation~\\ref{eq:acceleration decomposition initial} we get\n\n\\begin{equation}\\label{eq:acceleration decomposition final}\n{\\bf a}=|{\\bf v}|'{\\bf T}+\\kappa|{\\bf v}|^2{\\bf N}.\n\\end{equation}\n\nThe quantity $|{\\bf v}(t)|$ is the speed of the object, often written as\n$v(t)$; $|{\\bf v}(t)|'$ is the rate at which the speed is changing, or\nthe scalar acceleration of the object, $a(t)$. Rewriting \nEquation~\\ref{eq:acceleration decomposition final} with these gives\nus\n$${\\bf a}=a{\\bf T}+\\kappa v^2{\\bf N}=\na_{T}{\\bf T}+a_{N}{\\bf N};$$\n$a_T$ is the \\dfont{tangential component of acceleration} and \n$a_N$ is the \\dfont{normal component of acceleration}. \nWe have already seen that $a_T$ measures how the speed is changing; if\nyou are riding in a vehicle with large $a_T$ you will feel a force\npulling you into your seat. The other component, $a_N$, measures how\nsharply your direction is changing \\emph{with respect to time}. So it\nnaturally is related to how sharply the path is curved, measured by\n$\\kappa$, and also to how fast you are going. Because $a_N$ includes\n$v^2$, note that the effect of speed is magnified; doubling your speed\naround a curve quadruples the value of $a_N$. You feel the effect of\nthis as a force pushing you toward the outside of the curve, the\n``centrifugal force.''\n\nIn practice, if want $a_N$ we would use the formula for $\\kappa$:\n$$a_N=\\kappa |{\\bf v}|^2= {|{\\bf r}'\\times{\\bf r}''|\\over\n|{\\bf r}'|^3}|{\\bf r}'|^2={|{\\bf r}'\\times{\\bf r}''|\\over|{\\bf r}'|}.$$\nTo compute $a_T$ we can project ${\\bf a}$ onto ${\\bf v}$:\n$$a_T={{\\bf v}\\cdot{\\bf a}\\over|{\\bf v}|}={{\\bf r}'\\cdot{\\bf r}''\\over\n|{\\bf r}'|}.$$\n\n\\begin{example}{}{}\nSuppose ${\\bf r}=\\langle t,t^2,t^3\\rangle$. \nCompute ${\\bf v}$, ${\\bf a}$,\n$a_T$, and $a_N$.\n\\end{example}\n\\begin{solution}\nTaking derivatives we get\n${\\bf v}=\\langle 1,2t,3t^2\\rangle$ \nand ${\\bf a}=\\langle 0,2,6t\\rangle$. Then\n$$a_T={4t+18t^3\\over \\sqrt{1+4t^2+9t^4}}\n\\quad\\hbox{and}\\quad\na_N={\\sqrt{4+36t^2+36t^4}\\over\\sqrt{1+4t^2+9t^4}}.$$\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:MotionAlongCurve}}\n\n\\begin{enumialphparenastyle}\n\n\n\\begin{ex}\nLet ${\\bf r}=\\langle \\cos t,\\sin t,t\\rangle$. \nCompute ${\\bf v}$, ${\\bf a}$,\n$a_T$, and $a_N$.\n\\begin{sol}\n\t$\\langle -\\sin t,\\cos t,1\\rangle$,\n\t$\\langle -\\cos t, -\\sin t,0\\rangle$,\n\t$0$, $1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet ${\\bf r}=\\langle \\cos t,\\sin t,t^2\\rangle$. \nCompute ${\\bf v}$, ${\\bf a}$,\n$a_T$, and $a_N$.\n\\begin{sol}\n\t$\\langle -\\sin t,\\cos t,2t\\rangle$,\n\t$\\langle -\\cos t, -\\sin t,2\\rangle$,\n\t$4t/\\sqrt{4t^2+1}$, $\\sqrt{4t^2+5}/\\sqrt{4t^2+1}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet ${\\bf r}=\\langle \\cos t,\\sin t,e^t\\rangle$. \nCompute ${\\bf v}$, ${\\bf a}$,\n$a_T$, and $a_N$.\n\\begin{sol}\n\t$\\langle -\\sin t,\\cos t,e^t\\rangle$,\n\t$\\langle -\\cos t, -\\sin t,e^t\\rangle$,\n\t$e^{2t}/\\sqrt{e^{2t}+1}$, $\\sqrt{2e^{2t}+1}/\\sqrt{e^{2t}+1}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet ${\\bf r}=\\langle e^t,\\sin t,e^t\\rangle$. \nCompute ${\\bf v}$, ${\\bf a}$,\n$a_T$, and $a_N$.\n\\begin{sol}\n\t$\\langle e^t,\\cos t,e^t\\rangle$,\n\t$\\langle e^t, -\\sin t,e^t\\rangle$,\n\t$(2e^{2t}-\\cos t\\sin t)/\\sqrt{2e^{2t}+\\cos^2 t}$, \n\t$\\sqrt{2}e^t|\\cos t+\\sin t|/\\sqrt{2e^{2t}+\\cos^2 t}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose an object moves so that its acceleration is given by\n${\\bf a}=\\langle -3\\cos t,-2\\sin t,0\\rangle$. At time $t=0$ the object\nis at $(3,0,0)$ and its velocity vector is $\\langle\n0,2,0\\rangle$. Find ${\\bf v}(t)$ and ${\\bf r}(t)$ for the object.\n\\begin{sol}\n\t$\\langle -3\\sin t,2\\cos t,0\\rangle$,\n\t$\\langle 3\\cos t, 2\\sin t,0\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose an object moves so that its acceleration is given by\n${\\bf a}=\\langle -3\\cos t,-2\\sin t,0\\rangle$. At time $t=0$ the object\nis at $(3,0,0)$ and its velocity vector is $\\langle\n0,2.1,0\\rangle$. Find ${\\bf v}(t)$ and ${\\bf r}(t)$ for the object.\n\\begin{sol}\n\t$\\langle -3\\sin t,2\\cos t+0.1,0\\rangle$,\n\t$\\langle 3\\cos t, 2\\sin t+t/10,0\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose an object moves so that its acceleration is given by\n${\\bf a}=\\langle -3\\cos t,-2\\sin t,0\\rangle$. At time $t=0$ the object\nis at $(3,0,0)$ and its velocity vector is $\\langle\n0,2,1\\rangle$. Find ${\\bf v}(t)$ and ${\\bf r}(t)$ for the object.\n\\begin{sol}\n\t$\\langle -3\\sin t,2\\cos t,1\\rangle$,\n\t$\\langle 3\\cos t, 2\\sin t,t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose an object moves so that its acceleration is given by\n${\\bf a}=\\langle -3\\cos t,-2\\sin t,0\\rangle$. At time $t=0$ the object\nis at $(3,0,0)$ and its velocity vector is $\\langle\n0,2.1,1\\rangle$. Find ${\\bf v}(t)$ and ${\\bf r}(t)$ for the object.\n\\begin{sol}\n\t$\\langle -3\\sin t,2\\cos t+1/10,1\\rangle$,\n\t$\\langle 3\\cos t, 2\\sin t+t/10,t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDescribe a situation in which the normal component of\nacceleration is 0 and the tangential component of acceleration is\nnon-zero. Is it possible for the tangential component of acceleration\nto be 0 while the normal component of acceleration is non-zero? Explain.\nFinally, is it possible for an object to move (not be stationary)\nso that both the tangential and normal components of acceleration are 0?\nExplain.\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "8e9a0498c91a685f4a494c5acdd0c88ed0c8716e", "size": 6800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13-vector-functions/13-4-motion-along-curve.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "13-vector-functions/13-4-motion-along-curve.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "13-vector-functions/13-4-motion-along-curve.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": 35.7894736842, "max_line_length": 77, "alphanum_fraction": 0.6397058824, "num_tokens": 2573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6606824842723776}}
{"text": "\\chapter{Sampling CT Signals}\n\nUp until now in the course we have focused on either CT or DT signals and systems. Practical systems though often are hybrid and require conversion between DT and CT signals. For example a CT audio signal might be converted to a DT audio signal for storage and/or transmission, and at a later time or location converted back to a CT signal for playback through a speaker.\n\nIt is also common to design a CT system and then implement it as a DT system. Advantages of this approach are e.g. such implementations are less susceptible to component variations, require no tuning a build time, are easier to change (firmware or software update), easier to prototype, and more easily use encryption. \n\nIn this lecture we focus on \\emph{sampling} of CT signals to produce a DT signal $x[n] = x(nT)$ with sample index $n$ and sample time $T$. In the next lecture we consider the case of converting from a DT to CT signal. \n\n\\section{Sampling Theory}\n\nThe process of sampling is to produce a DT signal $x[n]$ from a CT signal $x(t)$ by sampling time at regular intervals $T\\in \\mathbb{R}^+$ called the \\emph{sample-time}, or equivalently sampling at a frequency of $\\tfrac{1}{T}$ Hz or $\\tfrac{2\\pi}{T}$ rad/s. Mathematically this is simple to express in the time domain as $x[n] = x(nT)$, however we seek a system that can perform this task.\n\nRecall the impulse train is the periodic signal\n\\[\nx_1(t) = \\sum\\limits_{n=-\\infty}^{\\infty} \\delta(t-nT_0)\n\\]\nwith period $T_0$ and frequency $\\omega_0 = \\tfrac{2\\pi}{T_0}$. The exponential CT Fourier series of the impulse train is given by\n\\[\nx_1(t) = \\sum\\limits_{n=-\\infty}^{\\infty} a_n e^{j\\tfrac{2\\pi}{T_0}nt}\n\\]\nwhere the Fourier series coefficients are\n\\[\na_n = \\frac{1}{T_0} \\int\\limits_{-\\frac{T_0}{2}}^{\\frac{T_0}{2}} \\delta(t) e^{-jn\\omega_0 t} \\; dt = \\frac{1}{T_0} \n\\]\nNow, lets take the Fourier Transform of the Fourier series representation\n\\begin{align*}\nX_1(j\\omega) &= \\int\\limits_{-\\infty}^{\\infty} \\sum\\limits_{n=-\\infty}^{\\infty} \\frac{1}{T_0} e^{j\\tfrac{2\\pi}{T_0}nt}e^{j\\omega t}\\; dt\\\\\n&= \\frac{1}{T_0} \\sum\\limits_{n=-\\infty}^{\\infty} \\int\\limits_{-\\infty}^{\\infty} e^{j\\tfrac{2\\pi}{T_0}nt}e^{j\\omega t}\\; dt\\\\\n&= \\frac{1}{T_0} \\sum\\limits_{n=-\\infty}^{\\infty} \\delta(\\omega - \\omega_0 n)\n\\end{align*}\nalso an impulse train in the frequency domain. Now suppose we have another signal $x_2(t)$ and we multiply $x_1(t)$ and $x_2(t)$ to get a signal $y(t)$.\n\\[\ny(t) = x_1(t) \\cdot x_2(t) = \\sum\\limits_{n=-\\infty}^{\\infty} x_2(t) \\delta(t-nT_0) = \\sum\\limits_{n=-\\infty}^{\\infty} x_2(nT_0) \\delta(t-nT_0)\n\\]\nSince $y(t)$ is non-zero only at the locations of the delta functions, we can treat $y(nT_0) = x_2(nT_0)$ as the DT signal $x_2[n]$. This is illustrated below\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/samplinf_timedomain.pdf}\n\\end{center}\n\nEquivalently in the frequency domain the modulation theorem gives\n\\[\ny(t) = x_1(t) \\cdot x_2(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\frac{1}{2\\pi} X_1(j\\omega) * X_2(j\\omega) = Y(j\\omega)\n\\]\nLets do the convolution\n\\begin{align*}\n  Y(j\\omega) &= \\frac{1}{2\\pi} X_1(j\\omega) * X_2(j\\omega)\\\\\n  &=  \\frac{1}{2\\pi} \\left[  \\frac{1}{T_0} \\sum\\limits_{n=-\\infty}^{\\infty} \\delta(\\omega - \\omega_0 n) \\right] * X_2(j\\omega)\\\\\n  &= \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty}  \\frac{1}{T_0} \\sum\\limits_{n=-\\infty}^{\\infty} \\delta(\\omega - \\omega^\\prime - \\omega_0 n) X_2(j\\omega^\\prime) \\; d\\omega^\\prime\\\\\n  &= \\frac{1}{2\\pi T_0} \\sum\\limits_{n=-\\infty}^{\\infty} X_2(j(\\omega - n\\omega_0)) \n\\end{align*}\nThus the sampling process in the frequency domain causes periodic replication of the Fourier transform of the signal being sampled, $x_2(t)$, which are sometimes called \\emph{images}. This signal $Y(j\\omega)$ is periodic in $\\omega_0 = \\tfrac{2\\pi}{T_0}$ \\emph{radians per second} and corresponds to the DT Fourier Transform of $x_2[n]  \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_2\\left(e^{j\\omega}\\right)$, which is periodic in $2\\pi$ \\emph{radians per sample time}.\n\nTo help us visualize this, suppose that the signal $x_2(t)  \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X_2(j\\omega)$ is \\emph{band-limited} to $B$ Hz, that is $X_2(j\\omega) = 0$ for all $-2\\pi B < \\omega < 2\\pi B$. This is shown schematically as the magnitude spectrum below:\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandlimited.pdf}\n\\end{center}\nAfter sampling ($y(t) = x_1(t)*x_2(t)$) and assuming $\\omega_0 > 4\\pi B$ the spectrum of the sampled signal is:\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandlimitedsampled1.pdf}\n\\end{center}\nIf instead $\\omega_0 < 4\\pi B$ the images overlap and we get \\emph{aliasing}, where high frequency content gets added to the lower frequency content. This is shown below with the lighter lines showing the images and the heavier line showing their sum.\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandlimitedsampled2.pdf}\n\\end{center}\nAs we will see next time, to reconstruct the signal $x_2[n]$ back to $x_2(t)$ we need to ensure that $\\omega_0 > 4\\pi B$ rad/s or equivalently $f_0 > 2 B$ Hz, which requires the sample time $T_0 < \\tfrac{1}{2B}$ seconds. This is called the \\emph{Nyquist} sample rate/frequency. \n\n\\begin{example} Consider a signal representing a musical chord (an additive mixture of three notes)\n  \\[\n  x(t) = \\sin(2\\pi\\cdot (261) t) + \\sin(2\\pi\\cdot (329) t) + \\sin(2\\pi\\cdot (392) t) \n  \\]\n  Suppose it is sampled at a frequency of $f_0 = 1$ kHz. Then there is no aliasing into the frequency range $(0, 500)$ Hz. After reconstruction $x(t)$ would be unmodified. Suppose instead it is sampled at $f_0 = 500$ Hz. Then the signal component at $261$ Hz aliases to $239 = 500-261$ Hz, the signal component at $329$ Hz aliases to $171 = 500-329$ Hz, and the signal component at $392$ Hz aliases to $108 = 500-392$ Hz. When reconstructed, the signal now has an additional 3 tones mixed in at audible frequencies, but do not correspond to (Western) musical notes, i.e.\n  \\[\n  x(t) = \\sin(2\\pi\\cdot (108) t) + \\sin(2\\pi\\cdot (171) t) + \\sin(2\\pi\\cdot (239) t) + \\sin(2\\pi\\cdot (261) t) + \\sin(2\\pi\\cdot (329) t) + \\sin(2\\pi\\cdot (392) t) \n  \\]\n\\end{example}\n\n\\section{Practical Sampling}\n\nSampling in practice requires addressing three issues. First, we cannot generate the impulse train, but can only approximate it. Second, digital signals must have a fixed bit width so we have to convert the real signal value to a \\emph{quantized} one. Lastly, since in general we have no control over the input signal means we need to ensure the signal is approximately band-limited before sampling.\n\n\\subsection{Sample and Hold}\nSampling is typically accomplished using a circuit called a \\emph{sample-and-hold}, schematically illustrated below.\n\n\\begin{center}\n  \\includegraphics[scale=0.8]{graphics/smaple_hold.pdf}\n\\end{center}\n\n\nThe CT signal is applied to the input of the first op-amp buffer. The output of this first buffer is switched into a charging capacitor for the \\emph{sample time}, then disconnected (high impedance) at regular intervals for the \\emph{hold time}, typically using a MOSFET switch. The effect is the capacitor is charged to the current value of $x(t)$ during the sample-time, which it maintains during the hold-time, the value of which is bufered by the second op-amp. This can be mathematically modeled as a pulse train with a width equal to the sample time rather than as an impulse train.\n\n\\subsection{Quantization}\n\nTo quantize the signal after the sample-and-hold into $N$ bits, several strategies can be used. One popular approach is called \\emph{successive approximation}, illustrated below\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/sar.pdf}\n\\end{center}\n\nThe current quantized digital value is held in a counter connected to a clock signal. The direction of the counter (up or down) is controlled by a comparator connected to the output of the sample and hold and the current counter output and a digital-to-analog converter (DAC, usually a resistor ladder) that converts it back to an analog value. If the DAC value is less than the held value, the counter counts up, if the DAC value is greater than the held value the counter counts down. In this fashion the counter output tracks the held value after a settling time required for convergence, at which point the counter value is clocked into a register for storage.\n\n\\subsection{Anti-aliasing}\n\nBefore the sample and hold we need to include a filter to limit the bandwidth. This can be accomplished by a CT low-pass filter called an \\emph{anti-aliasing} filter whose cutoff frequency in the ideal case is $\\omega_c = 2\\pi B$. As we saw in lecture 24 ideal filters cannot be implemented, thus we specify the anti-aliasing filter as a pass-band gain/frequency and a stop-band gain/frequency. Since the transition band is non-zero for a practical filter, this means we have to either lower the pass-band relative to the ideal or increase the sample rate. In the best case, the filter should have a stop-band frequency at half the sampling frequency with the order of the filter and pass-band frequency adjusted as needed. Alternatively the gain that defines the stop-band can be relaxed. This gives a desired frequency response magnitude that looks like the following.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/antialias.pdf}\n\\end{center}\nThe bold dotted line shows the maximum frequency response of the first image.  \n", "meta": {"hexsha": "b6c733cb5c289212fa04388cbd696bbc9ea69514", "size": 9428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "23-sampling.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": "23-sampling.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": "23-sampling.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": 84.9369369369, "max_line_length": 870, "alphanum_fraction": 0.7350445482, "num_tokens": 2801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.6606824783181462}}
{"text": "\\chapter{Initial Value Problems and their Properties}\n\\label{cha:IVP}\n\\input{models}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Introduction to initial value problems}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\begin{Definition*}{ode}{Ordinary differential equations} \\label{Definition:IVP}\n  \\defindex{differential equation!ordinary|see{ordinary differential equation}} \\index{ODE|see{ordinary\n      differential equation}} An \\define{ordinary differential\n    equation} (ODE) is an equation for a function $u(t)$, defined on\n  an interval $I \\subset \\R$ and with values in the real or complex\n  numbers or in the space $\\R^d$ ($\\C^d$), of the form\n  \\begin{gather}\n    F\\bigl(t, u(t), u'(t), u''(t), \\dots, u^{(n)}(t)\\bigr) = 0.\n  \\end{gather}\n  Here $F(\\ldots)$ denotes an arbitrary function of its arguments.\n  The \\textbf{order}\\defindex{order!of a differential equation} $n$ of\n  a differential equation is the highest derivative which occurs.  If\n  the dimension $d$ of the value range of $u$ is higher than one, we\n  talk about systems of differential equations.\n\\end{Definition*}\n\n\\begin{remark}\n  A differential equation, which is not ordinary, is called partial.\n  These are equations or systems of equations, which involve partial\n  derivatives with respect to several independent variables.  While\n  the functions in an ordinary differential equation may be dependent\n  on additional parameters, derivatives are only taken with respect to\n  one variable, typically, but not exclusively, this variable is\n  time. Due to the fact that this manuscript just deals with ordinary\n  differential equations, the adjective will be omitted in the\n  following.\n\\end{remark}\n\n\\begin{Definition}{explicit-ode}{Explicit differential equation}\n  \\defindex{ordinary differential equation!explicit} An \\define{explicit\n    differential equation} of first order is a equation of the form\n  \\begin{align}\n    \\label{eq:IVP:ode}\n    u'(t) &= f(t,u(t))\\\\\n    \\text{or shorter:}\\qquad u'&=f(t,u). \\notag\n  \\end{align}\n  A differential equation of order $n$ is called explicit, if it is of\n  the form\n  \\begin{gather*}\n    u^{(n)}(t) = F\\left(t, u(t), u'(t), \\ldots, u^{(n-1)}(t)\\right)\n  \\end{gather*}\n\\end{Definition}\n\n\\begin{Lemma}{first-order}\n  Every differential equation of higher order can be written as a\n  system of first-order differential equations. If the equation is\n  explicit, then the system is explicit.\n\\end{Lemma}\n\n\\begin{proof}\n  By the introduction of additional variables $u_0(t) = u(t)$, $u_1(t)\n  = u'(t)$ to $u_{n-1}(t) = u^{(n-1)}(t)$, each differential equation of\n  order $n$ can be transformed into a system of $n$ differential equations\n  of first order. This system has the form\n  \\begin{gather}\n    \\label{eq:IVP:13}\n    \\begin{pmatrix}\n      u_0'(t) - u_1(t) \\\\\n      u_1'(t) - u_2(t) \\\\\n      \\vdots\\\\\n      u_{n-2}'(t) - u_{n-1}(t) \\\\\n      F\\bigl(t, u_0(t),u_1(t),\\dots,u_{n-1}(t), u_{n-1}'(t)\\bigr)\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      0\\\\0\\\\\\vdots\\\\0\\\\0\n    \\end{pmatrix}.\n  \\end{gather}\n  In the case of an explicit equation, the system has the form\n  \\begin{gather}\n    \\label{eq:IVP:13a}\n    \\begin{pmatrix}\n      u_0'(t) \\\\\n      u_1'(t) \\\\\n      \\vdots\\\\\n      u_{n-2}'(t) \\\\\n      u_{n-1}' (t)\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      u_1(t)\\\\u_2(t)\\\\\\vdots\\\\u_{n-1}(t)\\\\F\\bigl(t, u_0(t),u_1(t),\\dots,u_{n-1}(t)\\bigr)\n    \\end{pmatrix}.\n  \\end{gather}\n\\end{proof}\n\n\\begin{example}\n  \\label{ex:IVP:sine-1}\n  The differential equation\n  \\begin{gather}\n    \\label{eq:IVP:17}\n    u'' + \\omega^2 u = f(t)\n  \\end{gather}\n  can be transformed into the system\n  \\begin{gather}\n    \\label{eq:IVP:18}\n    \\begin{split}\n      u_1' - u_2 &= 0, \\\\\n      u_2' + \\omega^2 u_1 &= f(t).\n    \\end{split}\n  \\end{gather}\n  The transformation is not uniquely determined. In this example, a\n  more symmetric system can be obtained:\n  \\begin{gather}\n    \\label{eq:IVP:18a}\n    \\begin{split}\n      u_1' - \\omega u_2 &= 0, \\\\\n      u_2' + \\omega u_1 &= f(t).\n    \\end{split}\n  \\end{gather}\n  From a numerical perspective, system ~\\ref{eq:IVP:18a} should be\n  chosen over ~\\ref{eq:IVP:18} to avoid loss of significance or overflow,\n  i.e. if $|\\omega| \\ll 1$ or $|\\omega| \\gg 1$.\n\\end{example}\n\n\\begin{Definition}{autonomization}\n  A differential equation of the form~\\eqref{eq:IVP:ode} is called\n  \\textbf{autonomous}, \\defindex{autonomous differential equation} if\n  the right hand side $f$ is not explicitly dependent on $t$, i.e.\n  \\begin{gather}\n    u'=F(u).\n  \\end{gather}\n\n  Each differential equation can be transformed into an autonomous\n  differential equation.  This is called\n  \\textbf{autonomization}. \\defindex{autonomization}\n  \\begin{equation*}\n    U = \\begin{pmatrix} u \\\\ t \\end{pmatrix},\n    \\qquad\n    F(U) = \\begin{pmatrix} f(t,u) \\\\ 1 \\end{pmatrix},\n    \\qquad\n    U' = F(U)\n  \\end{equation*}\n\n  A method which provides the same solution for the autonomous\n  differential equation as for the original IVP, is called\n  \\textbf{invariant under autonomization}.\n\\end{Definition}\n\n\nDifferential equations usually provide sets of solutions from which we\nhave to choose a solution. An important selection criteria is setting\nan initial value which leads to a well-posed problem (see below).\n\n\\begin{Definition}{IVP}\n  \\index{IVP|see{initial value problem}} Given a point\n  $(t_0,u_0)\\in \\R \\times \\R^d$.  Furthermore, let the function\n  $f(t,u)$ with values in $\\R^d$ be defined in a neighborhood\n  $I\\times U \\subset \\R\\times \\R^d$ of the initial value.  Then an\n  \\define{initial value problem} (IVP) is defined as follows: find a\n  function $u(t)$, such that\n  \\begin{subequations}\n    \\label{eq:IVP}\n    \\begin{align}\n      \\label{eq:IVP:2}\n      u'(t)&=f\\bigl(t,u(t)\\bigr)\n      \\\\\n      \\label{eq:IVP:3}\n      u(t_0)&=u_0\n  \\end{align}\n  \\end{subequations}\n\\end{Definition}\n\n\\begin{Definition}{local-solution}\n    \\label{def:IVP:local solution}\n  \\defindex{solution!local} We call a continuously differentiable\n  function $u(t)$ with $u(t_0) = 0$ a \\define{local solution} of the\n  IVP~\\eqref{eq:IVP}, if there exists a neighborhood $J$ of the point\n  in time $t_0$ in which $u$ and $f(t,u(t))$ are defined and if the\n  equation~\\eqref{eq:IVP:2} holds for all $t\\in J$.\n\\end{Definition}\n\n\\begin{remark}\n  We introduced the IVP deliberately in a ``local'' form because the\n  local solution term is the most useful one for our purpose. Due to\n  the fact that the neighborhood $J$ in the definition above can be\n  arbitrarily small, we will have to deal with the extension to larger\n  intervals below.\n\\end{remark}\n\n\\begin{remark}\n  Through the substitution of $t\\mapsto \\tau$ with $\\tau = t-t_0$ it\n  is possible to transform every IVP at the point $t_0$ to a IVP in\n  point $0$. We will make use of this fact and soon always assume\n  $t_0 = 0$.\n\\end{remark}\n\n\\begin{Lemma}{volterra}\n  Under the assumption that the right hand side $f$ is continuous in\n  both arguments, the function $u(t)$ is a solution of the initial\n  value problem~\\eqref{eq:IVP} if and only if it is a solution of the\n  \\define{Volterra integral equation} (VIE) \\index{VIE!see{Volterra\n      integral equation}}\n  \\begin{gather}\n    \\label{eq:volterra}\n    u(t) = u_0 + \\int_{t_0}^t f\\bigl(s,u(s)\\bigr)\\ds.\n  \\end{gather}\n  The formulation as integral equation allows on the other hand a more\n  general solution term, because the problem is already well-posed for\n  functions $f(t,u)$, which are just integrable with respect to $t$.\n  In that case the solution $u$ would be just absolutely continuous\n  and not continuously differentiable.\n\\end{Lemma}\n\n\\begin{remark} \\label{remark:volterra}\n  Both the theoretical analysis of the IVP and the numerical methods\n  (with exception of the BDF methods) in this lecture notes, solve\n  actually never the IVP~\\eqref{eq:IVP} but always the associated\n  integral equation ~\\eqref{eq:volterra}.\n\\end{remark}\n\n\\begin{Theorem*}{peano}{Peano's existence theorem}\n  \\defindex{Peano's theorem}\n  \\label{satz:peano}\n  Let the function $f(t,u)$ be continuous on the closed set\n  \\begin{gather*}\n    \\overline D =\\bigl\\{\n    (t,u) \\in \\R\\times\\R^d \\;\\big|\n    \\;|t-t_0| \\le \\alpha,\\;\n    |u-u_0|\\le\\beta\n    \\bigr\\},\n  \\end{gather*}\n  where $\\alpha,\\beta>0$. Then there exists a solution\n    $u(t) \\in C^1(I)$\n  on the interval\n    $I=[t_0-T,t_0+T]$\n  with\n  \\begin{gather*}\n    T=\\min\\left(\\alpha ,\\frac{\\beta}{M}\\right),\\;\n    M=\\max_{(t,u)\\in \\overline D} \\ |f(t,u)|.\n  \\end{gather*}\n\\end{Theorem*}\n\nThe proof of this theorem is of little consequence for the remainder\nof these notes.  For its verification, we refer to textbooks on the\ntheory of ordinary differential equations.\n\n\\begin{remark}\n  The Peano existence theorem does not make any statements about the\n  uniqueness of a solution and also just guarantees local existence.\n  The second limitation is addressed by the following theorem. The\n  first will be postponed to section~\\ref{sec:IVP:well-posedness}.\n\\end{remark}\n\n\\begin{Theorem*}{peano-continuation}{Peano's continuation theorem}\n  Let the assumptions of Theorem~\\ref{satz:peano} hold. Then, the\n  solution can be extended to an interval $I_m = [t_-, t_+]$ such that\n  the points $\\bigl(t_-,u(t_-)\\bigr)$ and $\\bigl(t_+,u(t_+)\\bigr)$ are\n  on the boundary of $\\overline D$. Neither the values of $t$, nor of\n  $u(t)$ need to be bounded as long as $f$ remains bounded.\n\\end{Theorem*}\n\n\\begin{example}\n  The IVP\n  \\begin{gather*}\n    u' = 2 \\sqrt{\\lvert u \\rvert}, \\qquad u(0) = 0,\n  \\end{gather*}\n  has solutions $u(t) = t^2$ and $u(t) = 0$.\n\\end{example}\n\n\\begin{example}\n  The functions $1/(t-t_0)$ are solutions to the IVP\n  \\begin{gather*}\n    u'=-u^2, \\qquad u(t_0) = 1.\n  \\end{gather*}\n\\end{example}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Linear differential equations\n  and Grönwall's inequality}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  The examination of linear differential equation turns out to be\n  particularly simple. On the other hand, results obtained here will\n  provide us with important statements for general non-linear\n  IVP. Therefore we pay particular attention to the linear case.\n\\end{intro}\n\n\\begin{Definition}{linear-ode}\n    \\defindex{ordinary differential equation!linear} An IVP according to\n  definition ~\\ref{Definition:IVP} is called \\textbf{linear} \\defindex{linear\n    differential equation} if the right hand side $f$ is an affine\n  function of $u$. Thus, we can write it in the form\n  \\begin{subequations}    \n    \\label{eq:IVP:4}\n    \\begin{xalignat}{2}\n      \\label{eq:IVP:5}\n      u'(t) &= A(t)u(t) + b(t)\n      & \\forall t &\\in \\R \\\\\n      \\label{eq:IVP:6}\n      u(t_0) &= u_0\n    \\end{xalignat}\n  \\end{subequations}\n  with a continuous matrix function $A:\\R\\to \\C^{d \\times d}$. If in\n  addition $b(t) \\equiv 0$, we call it \\define{homogeneous}.\n\\end{Definition}\n\n\\begin{Definition}{integrating-factor}\n    Let the matrix function $A:I\\to \\C^{d\\times d}$ be continuous.  Then\n  the function defined by\n  \\begin{gather}\n    \\label{eq:IVP:7}\n    M(t) = \\exp\\left(-\\int_{t_0}^t A(s) \\ds\\right)\n  \\end{gather}\n  is called \\define{integrating factor} of the\n  equation~\\eqref{eq:IVP:5}.\n\\end{Definition}\n\n\\begin{corollary}\n  The integrating factor $M(t)$ has the properties\n  \\begin{align}\n    \\label{eq:IVP:14}\n    M(t_0) &= \\identity\\\\\n    \\label{eq:IVP:15}\n    M'(t) &= -M(t)A(t).\n  \\end{align}\n\\end{corollary}\n\n\\begin{Lemma}{linear-representation}\n  % Voraussetzungen an A und b\n  A solution of the IVP~\\eqref{eq:IVP:4} is given through the \n  representation\n  \\begin{gather}\n    \\label{eq:IVP:8}\n    u(t) =  M(t)^{-1}\\left(u_0 + \\int_{t_0}^t M(s) b(s) \\ds\\right)\n  \\end{gather}\n  with the integrating factor $M(t)$ of the equation~\\eqref{eq:IVP:7}.\n  This solution exists for all $t\\in \\R$.\n\\end{Lemma}\n\n\\begin{proof}\n  We consider the auxiliary function $w(t) = M(t) u(t)$ with the\n  integrating factor $M(t)$ of the equation~\\eqref{eq:IVP:7}. Using the\n  product rule, there holds\n  \\begin{gather}\n    \\label{eq:IVP:19}\n    w'(t) =  M(t) u'(t) + M'(t) u(t)\n    =  M(t) u'(t) - M(t)A(t)u(t).\n  \\end{gather}\n  Comparing this to the differential equation~\\eqref{eq:IVP:5}, we see\n  that $w$ solves\n  \\begin{gather*}\n    w'(t) = M(t) b(t).\n  \\end{gather*}\n\tThis can be integrated directly to obtain\t\n  \\begin{gather*}\n    w(t) = u_0 + \\int_{t_0}^t M(s) b(s) \\ds,\n  \\end{gather*}\n  where we use that $w(t_0) = u_0$.  According to\n  lemma~\\ref{Lemma:appendix:exp-1} about the \\putindex{matrix\n    exponential}, $M(t)$ is invertible for all $t$.  With the\n  definition of $w(t)$ we are therefore able to solve for $u(t)$,\n  which results in the equation~\\eqref{eq:IVP:8}. The global\n  solvability follows from the fact that the solution is defined for\n  arbitrary $t\\in \\R$.\n\\end{proof}\n\n\\begin{example}\n  \\label{ex:IVP:sine-2}\n  The equation in example~\\ref{ex:IVP:sine-1} is linear and can be\n  written in the form of~\\eqref{eq:IVP:4} with\n  \\begin{align*}\n    A(t) = A &=\n    \\begin{pmatrix}\n      0 & \\omega \\\\ -\\omega & 0\n    \\end{pmatrix}\n    \\\\\n    b(t) &= f(t).\n  \\end{align*}\n  Let now $f(t) \\equiv 0$. The Jordan canonical form of $A$ is\n  \\begin{gather*}\n    A = C^{-1}\n    \\begin{pmatrix}\n      \\omega i \\\\ & -\\omega i\n    \\end{pmatrix}\n    C\n  \\end{gather*}\n  with a suitable transformation matrix $C$. The integrating factor is\n  \\begin{gather*}\n    M(t) = e^{At} = C^{-1}\n    \\begin{pmatrix}\n      e^{\\omega i} \\\\ & e^{-\\omega i}\n    \\end{pmatrix} C\n    =\n    \\begin{pmatrix}\n      \\cos \\omega t & \\sin \\omega t \\\\\n      -\\sin \\omega t & \\cos \\omega t\n    \\end{pmatrix}.\n  \\end{gather*}\n  Thus, given an initial value $(u_0, v_0)^T$, the solution is\n  \\begin{gather*}\n    u(t) =  \\begin{pmatrix}\n      \\cos \\omega t & \\sin \\omega t \\\\\n      -\\sin \\omega t & \\cos \\omega t\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      u_0\\\\v_0\n    \\end{pmatrix}.\n  \\end{gather*}\n  The missing details in this argument and the case for an\n  inhomogenety $f(t) = \\cos \\alpha t$ are left as an exercise.\n\\end{example}\n\n\\begin{remark}\n  If the function $b(t)$ in~\\eqref{eq:IVP:5} is only integrable, the\n  function $u(t)$ defined in~\\eqref{eq:IVP:8} is absolutely continuous\n  and thus differentiable almost everywhere. The chain\n  rule~\\eqref{eq:IVP:19} is applicable in all points of\n  differentiability and $w(t)$ solves the Volterra integral equation\n  corresponding to~\\eqref{eq:IVP:4}. Thus, the representation\n  formula~\\eqref{eq:IVP:8} holds generally for solutions of linear\n  Volterra integral equations.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{Lemma*}{gronwall}{Grönwall}\n  Let be $w(t)$, $a(t)$ and $b(t)$ be nonnegative, integrable\n  functions, such that $a(t)w(t)$ is integrable. Furthermore, let\n  $b(t)$ be monotonically nondecreasing and let $w(t)$ satisfy the\n  integral inequality\n  \\begin{gather}\n    \\label{eq:IVP:10}\n    w(t) \\le b(t) + \\int_{t_0}^t a(s)w(s)\\ds,\\qquad t\\ge t_0.\n  \\end{gather}\n  Then, for almost all $t \\ge t_0$ there holds:\n  \\begin{gather}\n    \\label{eq:IVP:11}\n    w(t) \\le b(t) \\exp\\left( \\int_{t_0}^t  a(s) \\ds\\right).\n  \\end{gather}\n\\end{Lemma*}\n\n\\begin{proof}\n  Using the integrating factor\n  \\begin{gather*}\n    m(t) = \\exp\\left(-\\int_{t_0}^t a(s) \\ds\\right),\n    \\quad\n    \\frac1{m(t)} = \\exp\\left(\\int_{t_0}^t a(s) \\ds\\right),\n  \\end{gather*}\n  we introduce the auxiliary function\n  \\begin{gather*}\n    v(t) = m(t) % \\exp\\left(-\\int_{t_0}^t a(s) \\ds\\right)\n    \\int_{t_0}^t a(s)w(s)\\ds,\n  \\end{gather*}\n  This function is absolutely continuous and almost everywhere\n  \\begin{gather*}\n    v'(t) = m(t) a(t) %\\exp\\left(-\\int_{t_0}^t a(s) \\ds\\right)\n    \\left[\n      w(t) - \\int_{t_0}^t a(s) w(s) \\ds\n    \\right].\n  \\end{gather*}\n  By assumption~\\eqref{eq:IVP:10}, the bracket on the right is bounded\n  by $b(t)$. Thus,\n  \\begin{gather*}\n    v'(t) \\le m(t) a(t) b(t) %\\exp\\left(-\\int_{t_0}^t a(s) \\ds\\right),\n  \\end{gather*}\n  and since $v(t_0) = 0$ by its definition,\n  \\begin{gather*}\n    v(t) \\le \\int_{t_0}^t m(s) a(s) b(s) % \\exp\\left(-\\int_{t_0}^s a(r)\n    \\ds.\n  \\end{gather*}\n  From the definition of $v(t)$, we obtain\n  \\begin{gather*}\n    \\int_{t_0}^t a(s)w(s)\\ds = \\frac1{m(t)} % \\exp\\left(\\int_{t_0}^t a(s) \\ds\\right)\n    v(t)\n    \\le \\frac1{m(t)} \\int_{t_0}^t m(s)a(s)b(s) \\ds\n    % \\exp\\left( %\\int_{t_0}^t a(r) \\dr\n    %   - \\int_{t_0}^s a(r) \\dr\\right)\\ds\n  \\end{gather*}\n  Finally, since $b(t)$ is nondecreasing we obtain almost everywhere\n  \\begin{align*}\n    \\int_{t_0}^t a(s)w(s)\\ds\n    &\\le  \\frac{b(t)}{m(t)} \\int_{t_0}^t a(s)\n    \\exp\\left(-\\int_{t_0}^s a(r) \\dr\\right)\\ds\n    \\\\\n    &= \\frac{b(t)}{m(t)} \\left[-\n    \\exp\\left(-\\int_{t_0}^s a(r) \\dr\\right)\n      \\right]_{t_0}^t\n    \\\\\n    &= \\frac{b(t)}{m(t)} \\bigl(m(t_0)-m(t)\\bigr)\n      = \\frac{b(t)}{m(t)} - b(t)\n  \\end{align*}\n  Now, entering into the integral inequality~\\eqref{eq:IVP:10}, we\n  obtain\n  \\begin{gather*}\n    w(t) \\le b(t) + \\int_{t_0}^t a(s)w(s)\\ds = \\frac{b(t)}{m(t)},\n  \\end{gather*}\n  which proves the lemma.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{remark}\n\tOn the form of the requirements~\\eqref{eq:IVP:10} as well as the\n  estimation~\\eqref{eq:IVP:11}, we can see that Grönwall's\n  inequality is basically based on the construction of a majorant for \n\t$w(t)$, which satisfies a linear IVP.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{Corollary}{IVP:unique-linear}\n  Let the functions $u(t)$ and $v(t)$ be two solutions of the linear\n  differential equation~\\eqref{eq:IVP:5}. If both functions\n  coincide in a point $t_0$ then they are identical.\n\\end{Corollary}\n\n\\begin{proof}\n\tThe difference $w(t) = v(t) - u(t)$ solves the integral equation\n  \\begin{gather*}\n    w(t) = \\int_{t_0}^t A(s) w(s) \\ds.\n  \\end{gather*}\n  Hence $|w(t)|$ satisfies the integral inequality\n  \\begin{gather*}\n    |w(t)| \\le \\int_{t_0}^t |A(s)| |w(s)| \\ds,\n  \\end{gather*}\n\tfrom which we conclude with Grönwall's inequality~\\eqref{eq:IVP:11} \n\tfor $b(t) = 0$, that $|w(t)|=0$ for all $t$ and therefore\n  $u(t) = v(t)$.\n\\end{proof}\n\n\\begin{corollary}\n  The representation formula~\\eqref{eq:IVP:8} in\n  Lemma~\\ref{Lemma:linear-representation} defines the unique solution to the\n  IVP~\\eqref{eq:IVP:4}. In particular, solutions of linear IVP are\n  always defined on the whole real axis.\n\\end{corollary}\n\n\\begin{example}\n  Let $A \\in \\C^{d\\times d}$ be diagonalizable with possibly repeated\n  eigenvalues $\\lambda_1,\\dots,\\lambda_d$ and corresponding\n  eigenvectors $\\psi^{(i)}$. Let $\\Psi$ be the matrix of column\n  vectors $\\psi^{(i)}$. Then, the solution of the IVP\n  \\begin{gather*}\n    \\begin{split}\n      u' &= A u,\\\\\n      u(0) &= u_0,\n    \\end{split}\n  \\end{gather*}\n  is given by the formula\n  \\begin{gather*}\n    u(t) = e^{At} u_0 = \\Psi \\exp\n    \\begin{pmatrix}\n      \\lambda_1\\\\&\\ddots\\\\&&\\lambda_d\n    \\end{pmatrix}\n    \\Psi^{-1} u_0.\n  \\end{gather*}\n  This is due to the fact, that $M(t) = e^{-At}$ and $e^{-\\Psi A\n    \\psi^{-1}t} = \\Psi e^{-At} \\Psi^{-1}$.\n\\end{example}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Lemma}{solution-space}\n  \\index{homogeneous}\n  \\index{ordinary differential equation!linear!homogeneous}\n  The solutions of the homogeneous, linear differential equation\n  \\begin{gather}\n    \\label{eq:IVP:9}\n    u'(t) = A(t) u(t)\n  \\end{gather}\n  with $u:\\R\\to\\R^d$, define a vector space of dimension $d$. Let\n  $\\{\\psi^{(i)}\\}_{i=1,\\dots,d}$ be a basis of $\\R^d$. \n\tThen the solutions $\\phi^{(i)}(t)$ of the equation~\\eqref{eq:IVP:9} with \n  initial values $\\phi^{(i)}(0) = \\psi^{(i)}$ form a basis of the solution\n  space. The vectors $\\{\\phi^{(i)}(t)\\}$ are linear independent\n  for all $t\\in \\R$.\n\\end{Lemma}\n\n\n\\begin{proof}\n  At first we observe that for two solutions $u(t)$ and $v(t)$ of the\n  equation~\\eqref{eq:IVP:9}, their sum and their scalar multiples are\n  solutions too, due to linearity \\index{linear} of the derivative\n  and the right hand side.  Therefore the vector space structure is\n  proven.\n \n  Let now $\\phi^{(i)}(t)$ be solutions of the IVP with linear\n  independent initial values $\\{\\psi^{(i)}\\}$.  As a consequence the\n  functions are linear independent as well.\n\n  Assume that $w(t)$ is a solution of the equation~\\eqref{eq:IVP:9},\n  which cannot be written as a linear combination of $\\psi^{(i)}$.\n  Then $w(0)$ is not a linear combination of the vectors $\\psi^{(i)}$:\n  else let's say $w(0) = \\sum \\alpha_i \\psi^{(i)}$, then\n  $w(t) = \\sum \\alpha_i \\phi^{(i)}(t)$ would be a linear combination\n  because of uniqueness proven in\n  corollary~\\ref{Corollary:IVP:unique-linear}.  Since $\\{\\psi^{(i)}\\}$\n  according to the assumtions is a basis of $\\R^d$, such a $w(0)$\n  cannot exist.  Hence it is shown that $\\phi^{(i)}(t)$ is a basis of\n  the solution space of dimension $d$.\n  \n  It remains to show that the $\\phi^{(i)}(t)$ are linearly independent\n  for all $t\\in \\R$. To this end, assume that the set $\\phi^{(i)}(t)$\n  is linearly dependent for a value $t_1$.  Then the following holds\n  true without loss of generality\n  \\begin{gather*}\n    \\phi^{(d)}(t_1) = \\sum_{i=1}^{d-1}\\alpha_i\\phi^{(i)}(t_1) =: w(t).\n  \\end{gather*}\n  Again according to corollary~\\ref{Corollary:IVP:unique-linear} we\n  have $\\phi^{(d)} \\equiv w$, moreover $\\phi^{(d)}(0) = w(0)$ which\n  again is a contradiction to the assumption $\\psi^{(d)}$ is a linear\n  combination of the other initial values.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Definition}{fundamental-system}\n  A basis $\\{\\phi^{(1)},\\dots,\\phi^{(d)}\\}$ of the solution space of\n  the linear differential equation~\\eqref{eq:IVP:9}, in particular the\n  basis with initial values $\\phi^{(i)}(0) = e_i$, is called\n  \\define{fundamental system} of solutions.  The\n  matrix function\n  \\begin{gather}\n    \\label{eq:IVP:12}\n    \\fundam(t) =\n    \\begin{pmatrix}\n      \\phi^{(1)}(t)\\dots\\phi^{(d)}(t)\n    \\end{pmatrix}\n  \\end{gather}\n  with column vectors $\\phi^{(i)}(t)$ is called\n  \\define{fundamental matrix}.\n\\end{Definition}\n\n\\begin{Corollary}{fundamental-regular}\n  The fundamental matrix is regular for all $t\\in \\R$ and solves the\n  IVP\n  \\begin{align*}\n    \\fundam'(t) &= A(t)\\fundam(t)\\\\\n    \\fundam (0) &= \\identity.\n  \\end{align*}\n\\end{Corollary}\n\n\\begin{proof}\n  The initial value is part of the definition. On the other hand,\n  splitting the the matrix valued IVP into its column vectors, we\n  obtain the original IVP defining the solution space. Regularity\n  follows from linear independence of solutions for any $t$.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Well-posedness of the IVP}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\label{sec:IVP:well-posedness}\n\n\n\\begin{Definition}{hadamard} \n  A mathematical problem is called \\define{well-posed} if the\n  following \\textbf{Hadamard conditions} are satisfied:\n  \\index{Hadamard conditions}\n  \\begin{enumerate}\n  \\item A solution exists.\n  \\item The solution is unique.\n  \\item The solution is continuously dependent on the data.\n  \\end{enumerate}\n  The third condition in this form is purely qualitative. Typically,\n  in order to characterize problems with good approximation\n  properties, we will require \\putindex{Lipschitz continuity}, which\n  has a more quantitative character.\n\\end{Definition}\n\n\\begin{example}\n  The IVP\n  \\begin{gather*}\n    u'= \\sqrt[3]{u}, \\qquad u(0) = 0,\n  \\end{gather*}\n  has solutions of the form\n  \\begin{gather*}\n    u(t) =\n    \\begin{cases}\n      0 \\\\\n      c \\left(\\tfrac23t\\right)^{3/2}.\n    \\end{cases}\n  \\end{gather*}\n  Thus, the solution is not unique and therefore, the IVP is not\n  well-posed.\n  Let now the initial value be nonzero, but slightly positive. Then, a small\n  perturbation, which changes its sign, will have dramatic effect on\n  the solution.\n\\end{example}\n\n\\begin{Definition}{Lipschitz-condition}\n  The function $f(t,y)$ satisfies on its domain $D = I\\times\\Omega \\subset\n  \\R \\times \\R^d$ an uniformly continuous \\define{Lipschitz condition} if \n\tit is Lipschitz continuous with regard to $y$, i.e., it exists a \n\tpositive constant $L$, such that\n  \\begin{gather}\n    \\label{eq:IVP:1}\n    \\forall t\\in I;\\,x,y\\in\\Omega \\;:\\;\n    \\abs{f(t,x)-f(t,y)} \\le L \\abs{x-y}\n  \\end{gather}\n  It satisfies a local Lipschitz condition if the same holds true for all \n  compact subsets of $D$.\n\\end{Definition}\n\n\n\\begin{example}\n  Let $f(t,u)\\in C^1(\\R \\times\\R^d )$ and let all partial derivatives\n  with respect to components of $u$ be bounded by\n  \\begin{gather*}\n    \\max_{\\substack{t\\in \\R\\\\u\\in \\R^d\\\\1\\le i,j \\le d}}\n   \\abs{\n     \\frac{\\partial}{\\partial u_i} f_j(t,u)\n   } \\le K.\n  \\end{gather*}\n  Then, $f$ satisfies the Lipschitz condition~\\eqref{eq:IVP:1} with\n  $L=K$. Indeed, by using Taylor expansion, we see that\n  \\begin{multline*}\n    f_j(t, u) - f_j(t,v)\n    = \\int_0^1 \\frac{d}{ds}f_j\\bigl(t,u+s(v-u)\\bigr)\\ds\\\\\n    = \\int_0^1 \\sum_{i=1}^d(u_i-v_i)\\partial_if_j\\bigl(t,u+s(v-u)\\bigr)\\ds.\n  \\end{multline*}\n  It is an easy conclusion that\n  \\begin{gather*}\n    \\abs{f(t,u)-f(t,v)}\n    \\le K \\abs{u-v}.\n  \\end{gather*}\n\\end{example}\n\n\n\\begin{Theorem*}{IVP-stability}{Stability}\n  Let $f(t,u)$ and $g(t,u)$ be two continuous functions on a\n  cylinder $D = I \\times \\Omega$ where the interval $I$ contains\n  $t_0$ and $\\Omega$ is a convex set in $\\R^d$.  Furthermore, let\n  $f$ admit a Lipschitz condition with constant $L$ on $D$. Let $u$\n  and $v$ be solutions to the IVP\n  \\begin{xalignat}{2}\n    \\label{eq:IVP:20}\n    u'&=f(t,u) \\quad\\forall t\\in I,& u(t_0)&= u_0,\\\\\n    \\label{eq:IVP:21}\n    v'&=g(t,v) \\quad\\forall t\\in I,& v(t_0)&= v_0.\n  \\end{xalignat}\n  Then, there holds\n  \\begin{gather}\n    \\label{eq:IVP:22}\n    \\abs{u(t)-v(t)} \\le e^{L|t-t_0|}\n    \\left[ \\abs{u_0-v_0}\n      + \\int_{t_0}^{t} \\max_{x\\in\\Omega}\n      \\abs{f(s,x)-g(s,x)}\\ds\n    \\right].\n  \\end{gather}\n\\end{Theorem*}\n\n\\begin{proof}\n  Both $u(t)$ and $v(t)$ solve their respective Volterra integral\n  equations. Taking the difference, we obtain\n  \\begin{align*}\n    u(t)-v(t) &= u_0-v_0\n           + \\int_{t_0}^t \\bigl[ f(s,u(s)) - g(s,v(s)) \\bigr]\\ds\n    \\\\\n         &= u_0-v_0\n           + \\int_{t_0}^t \\bigl[ f(s,u(t)) - f(s,v(s)) \\bigr]\\ds\n           + \\int_{t_0}^t \\bigl[ f(s,v(t)) - g(s,v(s)) \\bigr]\\ds.\n  \\end{align*}\n  Thus, its norm admits the integral inequality\n  \\begin{align*}\n    \\abs{u(t)-v(t)}\n    &\\le \\abs{u_0-v_0} + \\int_{t_0}^t\\abs{f(s,u(t)) - f(s,v(s))} \\ds\n    + \\int_{t_0}^t \\abs{f(s,v(t)) - g(s,v(s))} \\ds\n    \\\\\n    &\\le \\underbrace{\\abs{u_0-v_0}\n      + \\int_{t_0}^t \\max_{x\\in\\Omega} \\abs{f(s,x)-g(s,x)}\\ds}_{b(t)}\n      + \\int_{t_0}^t L \\abs{u(s)-v(s)} \\ds.\n  \\end{align*}\n  This inequality is in the form of the assumption in Grönwall's\n  lemma, and its application yields the stability result.\n\\end{proof}\n\n\n\\begin{Theorem*}{picardlindelof}{Picard-Lindelöf}\n  \\defindex{Picard-Lindelöf theorem} \n  Let $f(t,y)$ be continuous on a cylinder\n  \\begin{gather*}\n    D = \\{ (t,y) \\in \\R \\times\n    \\R^d | \\ |t-t_0| \\le a, |y-u_0| \\le b \\}.\n  \\end{gather*}\n  Let $f$ be bounded such that there is a constant $M = \\max_D\n  \\abs{f}$ and satisfy the Lipschitz condition~\\eqref{eq:IVP:1} with\n  constant $L$ on $D$.  Then the IVP\n  \\begin{gather*}\n    \\begin{split}\n      u' &= f(t,u) \\\\ u(t_0) &= u_0\n    \\end{split}\n  \\end{gather*}\n  is uniquely solvable on the interval\n  $I = [t_0-T,t_0+T]$ where\n  $T = \\min \\{ a, \\frac{b}{M} \\}$.\n\\end{Theorem*}\n\n\\begin{proof}\n  First, we assume for simplicity $t_0=0$ or we transform the problem\n  accordingly. Abbreviate $I = [-T,T]$ and\n  \\begin{gather*}\n    \\Omega = \\bigl\\{x\\in \\R^d\\big| \\abs{x-u_0} \\le b \\bigr\\}.\n  \\end{gather*}\n\n  We introduce the operator $F(u)$ which is defined\n  through the \\putindex{Volterra integral\n    equation}~\\eqref{eq:volterra} as\n  \\begin{gather}\n    \\label{eq:IVP:16}\n   F(u)(t) = u_0 + \\int\\limits_{0}^t f(s,u(s)) \\ds.\n  \\end{gather}\n  Obviously $u$ is a solution of the Volterra integral\n  equation~\\eqref{eq:volterra} if and only if $u$ is a \\putindex{fixed\n    point} of $F$ i.e., $u=Fu$. We can obtain such a fixed-point by\n  the iteration $u^{(k+1)} = F(u^{(k)})$ with some initial guess\n  $u^{(0)}:I\\to\\Omega$. From the boundedness of $f$, we obtain for\n  $t-t_0 \\le T$\n  \\begin{align*}\n    \\abs{u^{(k+1)}(t)-u_0} = \\abs[big]{\\int_{t_0}^t f(s,u^{(k)}(s))\\ds } \\le \\int_{t_0}^t\n    \\abs{f(s,u^{(k)}(s))}\\ds \\le TM \\le b.\n  \\end{align*}\n  Thus, from $u^{(0)}:I\\to\\Omega$ follows $u^{(k)}:I\\to\\Omega$ for all\n  $k$ and the iteration is well-defined.\n  \n  We now show that $F$ is a contraction under the assumtions of the\n  theorem. We follow the technique\n  in~\\cite[\\S117]{Heuser86} and choose on the space $\\mathcal C(I)$,\n  which is the space of the continuous functions on $I$, the norm\n  \\begin{gather*}\n    \\norm{u}_e := \\underset{t \\in I}{max} ~e^{-2 L t} |u(t)|.\n  \\end{gather*}\n  \n  With estimating the difference of operator $F$ applied to two functions:\n  \\begin{align*}\n    |F(u)(t) - F(v)(t)|\n    & = \\left| u_0 - u_0 + \\int\\limits_{0}^t (f(s,u(s)) - f(s,v(s))) \\ds \\right| \\\\\n    & \\le \\int\\limits_{0}^t \\left| f\\bigl(s,u(s)\\bigr) - f\\bigl((s,v(s)\\bigr) \\right| \\ds \\\\\n    & \\le \\int\\limits_{0}^t L |u(s) - v(s)| \\underbrace{e^{-2 L s} e^{2 L s}}_{= 1} \\ds \\\\\n    & \\le L \\norm{u-v}_e \\int\\limits_{0}^t e^{2 L s} \\ds \\\\\n    & = L \\norm{u-v}_e \\frac{e^{2 L t} - 1}{2 L} \\\\\n    & \\le \\frac12 e^{2 L t} \\norm{u-v}_e.\n  \\end{align*}\n\n  It follows   \n  \\begin{gather*}\n    e^{-2 L t}|F(u)(t) - F(v)(t)| \\le \\frac12 \\norm{u-v}_e,\n  \\end{gather*}\n  for all $t$ and we observe:\n  \\begin{gather*}\n    |F(u)(t) - F(v)(t)|_e \\le \\frac12 \\norm{u-v}_e.\n  \\end{gather*}\n  Thus, we have shown that $F$ is a contraction on the space of the\n  continuous functions with the norm $\\norm{.}_e$.  Therefore, we can apply\n  the \\putindex{Banach fixed-point theorem}, concluding that $F$ has\n  exactly one fixed-point. This proves the theorem.\n\\end{proof}\n\n\\begin{remark}\n  The norm $\\norm{u}_e$ had been chosen with regard to Grönwall's\n  inequality, which was not used in the proof explicitly.  It is\n  equivalent to the norm $\\norm{u}_\\infty$ because $e^{-2 L t}$ is strictly\n  positiv and bounded. On the other hand one could have performed the\n  proof with some more calculations with respect to the ordinary\n  Tchebychev distance (maximum norm) $\\norm{u}_\\infty$.\n\\end{remark}\n\n\\begin{remark}\n  Currently our solution is restricted to $I = [t_0 - T, t_0 + T]$.\n  Since $T$ is chosen in such a way in\n  equation~\\ref{Theorem:picardlindelof} that the graph of $u$ does not\n  leave the domain, this extension always ends on the boundary of\n  $D$. One can now extend the solution by solving the next IVP\n  $\\left\\{\\begin{array}{l}\n            u' = f(t,u)\\\\\n            u(t_1) = u_1\\\\\n  \\end{array}\\right\\}$\n\ton the interval $I_1$. This way one obtains a solution on\n $I \\cup I_1 \\cup I_2 \\cup ...$.\n\\end{remark}\n\n\\begin{corollary}\n  Let the function $f(t,u)$ admit the Lipschitz condition on $\\R\\times\n  \\C^d$. Then, the IVP has a unique solution on the whole real axis.\n\\end{corollary}\n\n\\begin{proof}\n  The boundedness was used in order to guarantee that $u(t)\\in \\Omega$\n  for any $t$. This is not necessary anymore, if $\\Omega =\n  \\C^d$. Thus, the limitation of the interval $I$ becomes unnecessary\n  as well. Finally, the fixed point argument does not depend on\n  boundedness of the set.\n\\end{proof}\n% \\begin{theorem}[Differential stability]\n%   In addition to the assumptions of the Picard-Lindelöf theorem, let\n%   the gradient of $f$ with respect to its second argument, $\\nabla_u\n%   f(t,u)$ exist and be continuous in $D$. Then, the solution of the\n%   IVP depends continuously on the initial value $u_0$ and the gradient\n%   of the solution $u$ with respect to $u_0$ solves the IVP\n%   \\begin{gather}\n%     \\label{eq:IVP:23}\n%     \\begin{split}\n%     (\\nabla_{u_0} u)' &= \\nabla_u f(t,u) \\nabla_{u_0} u,\n%     \\\\\n%     \\nabla_{u_0} u(t_0) &= \\mathbb I.\n%     \\end{split}\n%   \\end{gather}\n% \\end{theorem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\\section{Examples}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% \\begin{example}\n% \tIt exists a solution of the IVP\n%     $\\left\\{\\begin{array}{l}\n%       u'=\\sin(u)\\\\\n%       u(0)=7\\\\\n%     \\end{array}\\right\\}$?\n\n%   \\begin{enumerate}\n%     \\item The IVP is autonomous.\n%     \\item $|\\sin(u)| \\le 1$\n%     \\item $\\sin(u)$ satisfies the Lipschitz condition with $L=1$.\n%     \\item $D = \\R \\times \\R$\n%   \\end{enumerate}\n\n%   $\\Rightarrow$ Due to the theorems of Peano~\\eqref{satz:peano} and Picard-Lindelöf~\\eqref{Theorem:picardlindelof} it follows:\n%   $\\exists! u : \\R \\to \\R$\n% \\end{example}\n\n% \\begin{example}\n%   $\\left\\{\\begin{array}{l}\n%     u'(t) = -u^2\\\\\n%     u(-1) = 1\\\\\n%   \\end{array}\\right\\}$\n\n%   \\begin{enumerate}\n%     \\item $u^2$ is continuous in $\\R$.\n%     \\item However we just have a local Lipschitz condition.\n%   \\end{enumerate}\n%   \\noindent $\\Rightarrow$ $u(t) = \\frac1t$ auf $(-\\infty,0)$\n% \\end{example}\n\n% \\begin{example}\n%   $\\left\\{\\begin{array}{l}\n%     u' = \\lambda u\\\\\n%     u(0) = u_0\\\\\n%   \\end{array}\\right\\}$\n\n% \t\\begin{enumerate}\n%   \\item $\\lambda u$ is Lipschitz continuous on $\\R$\n% \t\\end{enumerate}\n\n%   \\noindent $\\Rightarrow e^{\\lambda t} u_0$ is the unique solution in $\\R$.\n% \\end{example}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "1c7b9fe0576fbaaca3c83a6e49c8b704d26eca53", "size": 34076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/awa.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": "ode/awa.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": "ode/awa.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.2388831437, "max_line_length": 128, "alphanum_fraction": 0.6170031694, "num_tokens": 11580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.6606824724100493}}
{"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 9, 2014}\n\\rhead{Jon Allen}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\begin{enumerate}\n\\item\nLet $f_0,f_1,f_2,\\dots,f_n,\\dots$ denote the Fibonacci sequence. By evaluating each of the following expressions for small values of $n$, conjecture a general formula and then prove it, using mathematical induction and the Fibonacci recurrence:\n\\begin{enumerate}\n\\item\n$f_1+f_3+\\dots+f_{2n-1}$\n\\begin{align*}\n  &\\cancel{0},1,\\cancel{1},2,\\cancel{3},5,\\cancel{8},13,\\cancel{21},34,\\dots\\\\\n  1&=1,\\quad 1+2=3,\\quad 1+2+5=8,\\quad 1+2+5+13=21\\\\\n  f_{2n}&=f_1+f_3+\\dots+f_{2n-1}\n\\end{align*}\n\\subsubsection*{proof}\nWe already know the sum for $n=1$. Lets look at $n>1$\n\\begin{align*}\n  f_1+f_3+f_5+\\dots+f_{2n-1}&=f_1+\\sum\\limits_{k=2}^{n}{f_{2k-1}}\\\\\n  f_n&=f_{n-1}+f_{n-2}\\\\\n  f_1+f_3+f_5+\\dots+f_{2n-1}&=1+\\sum\\limits_{k=2}^{n}{f_{2k-3}+f_{2k-2}}\\\\\n  &=1+0+\\sum\\limits_{k=1}^{2n-2}{f_{k}}=1+f_0+\\sum\\limits_{k=1}^{2n-2}{f_{k}}\\\\\n  s_n&=f_0+f_1+f_2+\\dots+f_n=f_{n+2}-1\\\\\n  f_1+f_3+f_5+\\dots+f_{2n-1}&=1+s_{2n-2}=1+f_{2n-2+2}-1\\\\\n  &=f_{2n}\n\\end{align*}\nAnd we have our result. $\\Box$\n\\item\n$f_0+f_2+\\dots+f_{2n}$\n\\begin{align*}\n  &0,\\cancel{1},1,\\cancel{2},3,\\cancel{5},8,\\cancel{13},21,\\cancel{34},55,\\dots\\\\\n  0&=0,\\quad0+1=1\\quad0+1+3=4\\quad0+1+3+8=12,\\quad0+1+3+8+21=33\\\\\n  f_{2n+1}-1&=f_0+f_2+\\dots+f_{2n}\n\\end{align*}\n\\subsubsection*{proof}\nWhen looking for the pattern so we established that the formula is true for $n=0,1,2,3,4$ which is more than sufficient for a basis.\n\\begin{align*}\n  f_0+f_2+\\dots+f_{2n}&=\\sum\\limits_{k=0}^n{f_{2k}}\\\\\n  f_n&=f_{n-1}+f_{n-2}\\\\\n  f_0+f_2+\\dots+f_{2n}&=f_0+\\sum\\limits_{k=1}^n{f_{2k-2}+f_{2k-1}}\\\\\n  &=0+\\sum\\limits_{k=0}^{2n-1}{f_{k}}\\\\\n  s_n&=f_0+f_1+f_2+\\dots+f_n=f_{n+2}-1\\\\\n  f_0+f_2+\\dots+f_{2n}&=s_{2n-1}=f_{(2n-1)+2}-1\\\\\n  &=f_{2n+1}-1\n\\end{align*}\nAnd our result is proved. $\\Box$\n\\item\n$f_0-f_1+f_2-\\dots+(-1)^nf_{n}$\n\\begin{align*}\n  n&=1:0-1=-1,\\quad n=2:0-1+1=0,\\quad n=3:0-1+1-2=-2\\\\\n  n&=4:0-1+1-2+3=1,\\quad n=5:0-1+1-2+3-5=-4\\\\\n  &f_0-f_1+(f_0+f_1)-(f_1+f_2)+(f_2+f_3)-\\dots\\\\\n  &f_0-f_1+f_0+f_1-f_1-f_2+f_2+f_3-\\dots\\\\\n  &-f_1+(-1)^nf_{n-1}\n\\end{align*}\nSo our general formula is $-1+(-1)^nf_{n-1}$\n\\subsubsection*{proof}\nWe know that the sum is 0 when $n=0$ and the sum is -1 when $n=1$. Let us look at when $n>1$\n\\begin{align*}\n  f_0-f_1+f_2-\\dots+(-1)^nf_{n}&=\\sum\\limits_{k=0}^n{(-1)^kf_k}\\\\\n  &=f_0-f_1+\\sum\\limits_{k=2}^n{(-1)^kf_k}\\\\\n  &=-1+\\sum\\limits_{k=2}^n{(-1)^k(f_{k-2}+f_{k-1})}\\\\\n  &=-1+\\sum\\limits_{k=0}^{n-2}{(-1)^k(f_{k}+f_{k+1})}\\\\\n  &=-1+\\sum\\limits_{k=0}^{n-2}{(-1)^kf_{k}}+\\sum\\limits_{k=0}^{n-2}{(-1)^kf_{k+1}}\\\\\n  &=-1+\\sum\\limits_{k=0}^{n-2}{(-1)^kf_{k}}-\\sum\\limits_{k=1}^{n-1}{(-1)^kf_{k}}\\\\\n  &=-1+(-1)^0f_0+\\sum\\limits_{k=1}^{n-2}{(-1)^kf_{k}}-\\sum\\limits_{k=1}^{n-2}{(-1)^kf_{k}}-(-1)^{n-1}f_{n-1}\\\\\n  &=-1+(-1)^nf_{n-1}\n\\end{align*}\nAnd we have our proof. $\\Box$\n%\\item\n%${f_0}^2+{f_1}^2+\\dots+{f_n}^2$\n%\\begin{align*}\n%  0^2&=0\\\\\n%  0+1^2&=1\\\\\n%  0+1^2+1^2&=2\\\\\n%  0+1^2+1^2+2^2&=6\\\\\n%  0+1^2+1^2+2^2+3^2&=15\\\\\n%  0+1^2+1^2+2^2+3^2+5^2&=40\\\\\n%  0+1^2+1^2+2^2+3^2+5^2+6^2&=76\\\\\n%  0+1^2+1^2+2^2+3^2+5^2+6^2+7^2&=125\\\\\n%\\end{align*}\n%\\begin{align*}\n%  {f_0}^2+{f_1}^2+\\dots+{f_n}^2&=\\sum\\limits_{k=0}^n{{f_{k}}^2}\\\\\n%  &={f_0}^2+{f_1}^2+\\sum\\limits_{k=2}^n{(f_{k-1}+f_{k-2})^2}\\\\\n%  &={f_0}^2+{f_1}^2+\\sum\\limits_{k=2}^n{{f_{k-1}}^2+2f_{k-2}f_{k-1}+{f_{k-2}}^2}\\\\\n%  &={f_0}^2+{f_1}^2+{f_{1}}^2+2f_{0}f_{1}+{f_{0}}^2+\\sum\\limits_{k=3}^n{{f_{k-1}}^2+2f_{k-2}f_{k-1}+{f_{k-2}}^2}\\\\\n%  &={f_0}^2+{f_1}^2+{f_{1}}^2+2f_{0}f_{1}+{f_{0}}^2+\\sum\\limits_{k=3}^n{(f_{k-2}+f_{k-3})^2+2f_{k-2}f_{k-1}+{f_{k-2}}^2}\\\\\n%  %{f_0}^2+{f_1}^2+\\sum\\limits_{k=2}^n{{f_{k}}^2}&={f_0}^2+{f_1}^2+\\sum\\limits_{k=2}^n{{f_{k-1}}^2+2f_{k-2}f_{k-1}+{f_{k-2}}^2}\\\\\n%  %\\sum\\limits_{k=2}^n{{f_{k}}^2}-\\sum\\limits_{k=2}^n{{f_{k-1}}^2}&=\\sum\\limits_{k=2}^n{2f_{k-2}f_{k-1}+{f_{k-2}}^2}\\\\\n%  %\\sum\\limits_{k=2}^n{{f_{k}}^2}-\\sum\\limits_{k=1}^{n-1}{{f_{k}}^2}&={f_n}^2+\\sum\\limits_{k=2}^{n-1}{{f_{k}}^2}-{f_1}^2-\\sum\\limits_{k=2}^{n-1}{{f_{k}}^2}\n%\\end{align*}\n\\end{enumerate}\n\\setcounter{enumi}{2}\n\\item\nProve th following about the Fibonacci numbers:\n\\begin{enumerate}\n\\setcounter{enumii}{1}\n\\item\n$f_n$ is divisible by 3 if and only if $n$ is divisible by 4.\n\\subsubsection*{proof}\nLet $f_n=3a_n+b_n$ where $a_n\\in\\mathbb{N}$ and $b_n\\in\\{0,1,2\\}$.\nLets assume that $b_{n-1}=b_{n-2}=0$.\nThen $f_n=3a_{n-1}+3a_{n-2}$ which means that for all $n$, $3\\mid f_n$.\nThree seconds of scratchwork shows this is clearly not true at least for low values of $n$.\nNow lets assume that $3\\nmid f_n$ for all $n$.\nBut $3\\mid f_0$ and $3\\mid f_4$ so clearly this isn't true.\nWe know now that 3 sometimes divides Fibonacci numbers, but not always.\nSo lets assume that $3\\mid f_{n}$.\nThen for $f_{n-1}=3a_{n-1}+2$ or $f_{n-1}=3a_{n-1}+1$.\nNote that these cases can be seen at $f_4$ and $f_8$ respectively.\nAlso note that $4\\mid4$ and $4\\mid8$.\nFinally notice that these two (four?) facts conveniently provide a basis for the following inductive proof in two cases where $3\\mid f_n$ and $4\\mid n$.\n\nFirst we look at the case where $f_{n-1}=3a_{n-1}+2$.\nLet the algebra walk the walk.\n\\begin{align*}\n  f_{n+1}&=3a_n+3a_{n-1}+2=3(a_n+a_{n-1})+2=3a_{n+1}+2\\\\\n  f_{n+2}&=3a_{n+1}+2+3a_n=3a_{n+2}+2\\\\\n  f_{n+3}&=3a_{n+2}+2+3a_{n+1}+2=3a_{n+2}+3a_{n+1}+3+1=3a_{n+3}+1\\\\\n  f_{n+4}&=3a_{n+3}+1+3a_{n+2}+2=3(a_{n+3}+a_{n+2}+1)\n\\end{align*}\nAnd because $4\\mid n$ then $4\\mid n+4$.\nFurther, $3\\mid f_{n+4}$ in this case.\nAlso notice that we have shown the other half of the if and only if.\nThree does not divide any of $f_{n+1},f_{n+2},$ or $f_{n+3}$.\n\nNow lets examine the case where $f_{n-1}=3a_{n-1}+1$. We proceed as above, with maths.\n\\begin{align*}\n  f_{n+1}&=3a_n+3a_{n-1}+1=3a_{n+1}+1\\\\\n  f_{n+2}&=3a_{n+1}+1+3a_{n}=3a_{n+2}+1\\\\\n  f_{n+3}&=3a_{n+1}+1+3a_{n+2}+1=3a_{n+3}+2\\\\\n  f_{n+4}&=3a_{n+3}+2+3a_{n+2}+1=3(a_{n+3}+a_{n+2}+1)\n\\end{align*}\nSo we see that this case meets all the conditions of the last case.\n\nWe have shown that a Fibanocci style recurrence relation is either always divisible by three or is divisible by three only every fourth number. In our case the numbers are not always divisible by three. The index of every fourth number that divides three is itself divided by four. Thus we have proven the assertion. $\\Box$\n\\end{enumerate}\n\\item\nProve that the Fibonacci sequence is the solution of the recurrence relation\n\\[a_n=5a_{n-4}+3a_{n-5},\\quad(n\\ge5),\\]\nwhere $a_0=0,a_1=1,a_2=1,a_3=2,$ and $a_4=3$. Then use this formula to show that the Fibonacci numbers satisfy the condition that $f_n$ is divisible by 5 if and only if $n$ is divisible by 5.\n\\subsubsection*{proof}\nLets just try to wrangle the Fibanocci sequence into the relation shown.\n\\begin{align*}\n  f_n&=f_{n-1}+f_{n-2}\\\\\n  f_n&=(f_{n-2}+f_{n-3})+(f_{n-3}+f_{n-4})\\\\\n  f_n&=(f_{n-3}+f_{n-4})+(f_{n-4}+f_{n-5})+(f_{n-4}+f_{n-5})+f_{n-4}\\\\\n  f_n&=(f_{n-4}+f_{n-5})+f_{n-4}+f_{n-4}+f_{n-5}+f_{n-4}+f_{n-5}+f_{n-4}\\\\\n  f_n&=5f_{n-4}+3f_{n-5}\n\\end{align*}\nSince the relation is the same and the first five numbers are the same, the sequence is the same. $\\Box$\n\nThe case where $5\\mid f_{n-4}$ and $5\\mid f_{n-5}$ is the trivial case and would mean that five divides all $f_n$ which is clearly not true, so we will just write off that case.\n\nLet $f_n=5a_n+b_n$ where $a_n\\in\\mathbb{N}$ and $b_n\\in\\{0,1,2,3,4\\}$.\n\nNow lets assume that $5\\mid f_{n-5}$ and $5\\nmid f_{n-4}$. In other words $b_{n-5}=0$ and $b_{n-4}\\ne0$\n\\begin{align*}\n  f_n&=5(5a_{n-4}+b_{n-4})+3(5a_{n-5})\\\\\n  f_n&=5(5a_{n-4}+b_{n-4}+3a_{n-5})\n\\end{align*}\nSo $b_n=0$ and therefore $5\\mid f_n$ if $5\\mid f_{n-5}$ and $5\\nmid f_{n-4}$.\n\nNow lets check on $5\\mid f_{n-4}$ and $5\\nmid f_{n-5}$\n\\begin{align*}\n  f_n&=5(5a_{n-4})+3(5a_{n-5}+b_{n-5})\\\\\n  f_n&=5(5a_{n-4}+3a_{n-5})+3b_{n-5}\n\\end{align*}\nSince $3b_{n-5}\\in\\{3,6,9,12\\}$ we can say that $5\\nmid 3b_{n-5}$ and therefore $5\\nmid f_n$\nAnd for our last case lets find out what happens if five divides neither $f_{n-4}$ nor $f_{n-5}$.\n\\begin{align*}\n  f_n&=5(a_{n-4}+b_{n-4})+3(5a_{n-5}+b_{n-5)}\\\\\n  f_n&=5(a_{n-4}+b_{n-4}+3a_{n-5})+3b_{n-5}\n\\end{align*}\nAs above $5\\nmid 3b_{n-5}$ so $5\\nmid f_n$.\n\nSo we see 5 divides $f_n$ only every 5th $f_n$. Since $f_5=5$ we can say that $5\\mid f_n$ if and only if $5\\mid n$.\n\\setcounter{enumi}{6}\n%\\item\n%* Let $m$ and $n$ be positive integers whose greatest common divisor is $d$. Prove that the greatest common divisor of the Fibonacci numbers $f_m$ and $f_n$ is the Fibonacci number $f_d$.\n\\setcounter{enumi}{10}\n\\item\nThe \\emph{Lucas numbers} $l_0,l_1,l_2,\\dots,l_n,\\dots$ are defined using the same recurrence relation defining the Fibonacci numbers, but with differenct initial conditions:\n\\[l_n=l_{n-1}+l_{n-2}, (n\\ge2),l_0=2,l_1=1.\\]\nProve that\n\\begin{enumerate}\n\\item\n$l_n=f_{n-1}+f_{n+1}$ for $n\\ge1$\n\\subsubsection*{proof}\nWe can see that $l_1=1=0+1=f_0+f_2=f_{1-1}+f_{1+1}$. Also note that $l_2=l_1+l_0=1+2=f_{1}+f_{3}=f_{2-1}+f_{2+1}$. So our assumption holds for $n=1,2$. Lets assume it holds for any $n-1, n-2$ and verify that it holds for $n$.\n\\begin{align*}\n  l_n&=l_{n-1}+l_{n-2}&\\text{by definition of Lucas number}\\\\\n  &=(f_{n-2}+f_{n})+(f_{n-3}+f_{n-1})&\\text{by assumption}\\\\\n  &=(f_{n}+f_{n-1})+(f_{n-2}+f_{n-3})\\\\\n  &=f_{n+1}+f_{n-1}&\\text{by definition of Fibanocci number}\n\\end{align*}\nSo the assumption holds for $n\\ge3$ and we have proved our result by induction. $\\Box$\n\\item\n${l_0}^2+{l_1}^2+\\dots+{l_n}^2=l_nl_{n+1}+2$ for $n\\ge0$\n\\subsubsection*{proof}\nSo we see that ${l_0}^2=2^2=4=2+2=(2)(1)+2=l_0l_1$ and ${l_0}^2+{l_1}^2=2^2+1^2=5=3+2=(1)(3)+2=l_1l_2+2$. Now we know that our idea holds for $n=0,1$. Let us assume that our idea holds for all $n$. Lets see if it holds for $n+1$.\n\\begin{align*}\n  {l_0}^2+{l_1}^2+\\dots+{l_n}^2+{l_{n+1}}^2&=l_nl_{n+1}+2+{l_{n+1}}^2\\\\\n  &=l_nl_{n+1}+2+l_{n+1}(l_{n}+l_{n-1})\\\\\n  &=l_nl_{n+1}+2+l_{n+1}l_{n}+l_{n+1}l_{n-1}\\\\\n  &=l_{n+1}(l_n+l_{n}+l_{n-1})+2\\\\\n  &=l_{n+1}(l_n+l_{n+1})+2\\\\\n  &=l_{n+1}l_{n+2}+2\\\\\n\\end{align*}\nWell, it looks like it holds for $n+1$ and therefore by induction it holds for all $n$. $\\Box$\n\\end{enumerate}\n\\item\nLet $h_0,h_1,h_2,\\dots,h_n,\\dots$ be the sequence defined by\n\\[h_n=n^3,(n\\ge0).\\]\nShow that $h_n=h_{n-1}+3n^2-3n+1$ is the recurrence relation for the sequence.\n\\begin{align*}\n  h_n&=n^3\\\\\n  &=(n-1+1)^3\\\\\n  &=(n-1)^3+3(n-1)^2+3(n-1)+1\\\\\n  &=h_{n-1}+3(n^2-2n+1)+3n-3+1\\\\\n  &=h_{n-1}+3n^2-6n+3+3n-3+1\\\\\n  &=h_{n-1}+3n^2-3n+1\\\\\n\\end{align*}\n\\item\nDetermine the generating function for each of the following sequences:\n\\begin{enumerate}\n\\setcounter{enumii}{2}\n\\item\n$\\binom{\\alpha}{0},-\\binom{\\alpha}{1},\\binom{\\alpha}{2},\\dots,(-1)^n\\binom{\\alpha}{n},\\dots,$ ($\\alpha$ is a real number)\n\\begin{align*}\n  \\binom{\\alpha}{0}-\\binom{\\alpha}{1}x+\\binom{\\alpha}{2}x^2-\\dots+(-1)^n\\binom{\\alpha}{n}x^n+\\dots&=\\sum\\limits_{n=0}^\\infty{(-1)^n\\binom{\\alpha}{n}x^n}\\\\\n  \\sum\\limits_{n=0}^\\infty{(-1)^n\\binom{\\alpha}{n}x^n}&=\\sum\\limits_{n=0}^\\infty{\\binom{\\alpha}{n}(-x)^n}\\\\\n  \\intertext{By newton's generalised binomial theorem}\n  &=(1-x)^\\alpha\\\\\n\\end{align*}\n\\setcounter{enumii}{4}\n\\item\n$1,-\\frac{1}{1!},\\frac{1}{2!},\\dots,(-1)^n\\frac{1}{n!},\\dots$\n\\end{enumerate}\n\\begin{align*}\n  1-\\frac{1}{1!}x+\\frac{1}{2!}x^2-\\dots+(-1)^n\\frac{1}{n!}x^n+\\dots&=\\sum\\limits_{n=0}^\\infty{(-1)^n\\frac{1}{n!}x^n}\\\\\n  &=\\sum\\limits_{n=0}^\\infty{\\frac{(-x)^n}{n!}}\\\\\n  &=e^{-x}\n\\end{align*}\n\\item\nLet $S$ be the multiset $\\{\\infty\\cdot e_1,\\infty\\cdot e_2,\\infty\\cdot e_3,\\infty\\cdot e_4\\}$. Determine the generating function for the sequence $h_0,h_1,h_2,\\dots,h_n,\\dots,$ where $h_n$ is the number of $n$-combinations of $S$ with the following added restrictions:\n\\begin{enumerate}\n\\setcounter{enumii}{2}\n\\item\nThe element $e_1$ does not occur, and $e_2$ occurs at most once.\n\\begin{align*}\n  1&=(1+x^2+x^3+\\dots)-(x+x^2+x^3\\dots)\\\\\n  &=\\frac{1}{1-x}-\\frac{x}{1-x}=\\frac{1-x}{1-x}\\\\\n  1+x&=(1+x^2+x^3+\\dots)-(x^2+x^3+x^4\\dots)\\\\\n  &=\\frac{1}{1-x}-\\frac{x^2}{1-x}=\\frac{1-x^2}{1-x}\\\\\n  (1+x+x^2+x^3+\\dots)^2&=\\frac{1}{(1-x)^2}\\\\\n  g(x)&=\\frac{1-x^2}{(1-x)^3}\n\\end{align*}\n\\item\nThe element $e_1$ occurs 1,3,or 11 times, and the element $e_2$ occurs 2,4, or 5 times.\n\\begin{align*}\n  x^n&=1+x^2+x^3+\\dots-1-x-x^2-\\dots-x^{n-1}-x^{n+1}-x^{n+2}\\dots\\\\\n  &=\\frac{1}{1-x}-\\frac{1-x^{n-1}}{1-x}-\\frac{x^{n+1}}{1-x}=\\frac{x^{n-1}-x^{n+1}}{1-x}\\\\\n  x^1+x^3+x^{11}&=\\frac{x^0-x^2}{1-x}+\\frac{x^2-x^4}{1-x}+\\frac{x^{10}-x^{12}}{1-x}\\\\\n  &=\\frac{1-x^4+x^{10}-x^{12}}{1-x}\\\\\n  x^2+x^4+x^5&=\\frac{x^1-x^3}{1-x}+\\frac{x^3-x^5}{1-x}+\\frac{x^4-x^6}{1-x}\\\\\n  &=\\frac{x+x^4-x^5-x^6}{1-x}\\\\\n  g(x)&=\\frac{(1-x^4+x^{10}-x^{12})(x+x^4-x^5-x^6)}{(1-x)^2}\n\\end{align*}\n\\item\nEach $e_i$ occurs at least 10 times.\n\\begin{align*}\n  (x^{10}+x^{11}+x^{12}+\\dots)^4&=x^{40}(1+x+x^2+\\dots)^4\\\\\n  &=\\frac{x^{40}}{(1-x)^4}\n\\end{align*}\n\\end{enumerate}\n\\item\nDetermine the generating function for the sequence of cubes\n\\[0,1,8,\\dots,n^3,\\dots\\]\n\\begin{align*}\n  0x^0+1x^1+8x^2+\\dots&=\\sum\\limits_{n=0}^{\\infty}{n^3x^n}\\\\\n  \\frac{1}{1-x}&=\\sum\\limits_{n=0}^\\infty{x^n}\\\\\n  \\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\frac{1}{1-x}\\right)&=\\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\sum\\limits_{n=0}^\\infty{x^n}\\right)\\\\\n  \\frac{1}{(1-x)^2}&=\\sum\\limits_{n=0}^\\infty{nx^{n-1}}\\\\\n  \\frac{x}{(1-x)^2}&=\\sum\\limits_{n=0}^\\infty{nx^n}\\\\\n  \\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\frac{x}{(1-x)^2}\\right)&=\\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\sum\\limits_{n=0}^\\infty{nx^n}\\right)\\\\\n  \\frac{1}{(1-x)^2}+\\frac{2x}{(1-x)^3}&=\\sum\\limits_{n=0}^\\infty{n^2x^{n-1}}\\\\\n  \\frac{x}{(1-x)^2}+\\frac{2x^2}{(1-x)^3}=\\frac{x-x^2+2x^2}{(1-x)^3}=\\frac{x+x^2}{(1-x)^3}&=\\sum\\limits_{n=0}^\\infty{n^2x^n}\\\\\n  \\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\frac{x+x^2}{(1-x)^3}\\right)&=\\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\sum\\limits_{n=0}^\\infty{n^2x^n}\\right)\\\\\n  \\frac{1+2x}{(1-x)^3}+\\frac{3x+3x^2}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^{n+1}}\\\\\n  \\frac{1-x+2x-2x^2+3x+3x^2}{(1-x)^4}=\\frac{1+4x+x^2}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^{n+1}}\\\\\n  \\frac{x+4x^2+x^3}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n  g(x)&=\\frac{x+4x^2+x^3}{(1-x)^4}\\\\\n%  \\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\frac{x}{(1-x)^2}\\left(1+\\frac{2x}{1-x}\\right)\\right)&=\\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\sum\\limits_{n=0}^\\infty{n^2x^n}\\right)\\\\\n%  \\left(\\frac{1}{(1-x)^2}+\\frac{2x}{(1-x)^3}\\right)\\left(1+\\frac{2x}{1-x}\\right)+\\frac{x}{(1-x)^2}\\left(\\frac{2}{1-x}+\\frac{2x}{(1-x)^2}\\right)&=\\sum\\limits_{n=0}^\\infty{n^3x^{n-1}}\\\\\n%  x\\left(\\frac{1}{(1-x)^2}+\\frac{2x}{(1-x)^3}\\right)\\left(1+\\frac{2x}{1-x}\\right)+x\\frac{x}{(1-x)^2}\\left(\\frac{2}{1-x}+\\frac{2x}{(1-x)^2}\\right)&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  x\\left(\\frac{1}{(1-x)^2}+\\frac{2x}{(1-x)^3}+\\frac{2x}{(1-x)^3}+\\frac{4x^2}{(1-x)^4}\\right)+x\\left(\\frac{2x}{(1-x)^2}+\\frac{2x^2}{(1-x)^4}\\right)&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{x}{(1-x)^2}+\\frac{4x^2}{(1-x)^3}+\\frac{4x^3}{(1-x)^4}+\\frac{2x^2}{(1-x)^2}+\\frac{2x^3}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{x+2x^2}{(1-x)^2}+\\frac{4x^2}{(1-x)^3}+\\frac{6x^3}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{(x+2x^2)(1-x)^2}{(1-x)^4}+\\frac{4x^2(1-x)}{(1-x)^4}+\\frac{6x^3}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{(x+2x^2)(1-2x+x^2)+4x^2-4x^3+6x^3}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{x-2x^2+x^3+2x^2-4x^3+2x^4+4x^2+2x^3}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{x-x^3+2x^4+4x^2}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n%  \\frac{x+4x^2-x^3+2x^4}{(1-x)^4}&=\\sum\\limits_{n=0}^\\infty{n^3x^n}\\\\\n\\end{align*}\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "b698d61d46b37fc3c837c84cec138fa5ff61d5c3", "size": 15792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-hw-2014-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-hw-2014-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-hw-2014-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": 49.0434782609, "max_line_length": 323, "alphanum_fraction": 0.600810537, "num_tokens": 8078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6606551345181209}}
{"text": "% !TEX root=../presentation_1.tex\n\\section{Introduction}\n\n\\subsection{Minimum-Weight Spanning Tree (MST)}\n\n\\begin{frame}\n\\frametitle{Minimum-Weight Spanning Tree (MST)}\n\n\\begin{itemize}\n  \\item A \\textbf{weighted} graph $G = (V,E,W)$.\n  \\item A \\textbf{spanning tree} is a tree that covers all vertices.\n  \\item A spanning tree is \\textbf{minimum} if the sum of all weights in the tree is the minimum among all spanning trees.\n\\end{itemize}\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{figures/mst.pdf}\n    \\caption{An example of MST}\n\\end{figure}\n\\end{frame}\n\n\\subsection{Greedy Sequential Algorithms}\n\n\\begin{frame}\n\\frametitle{Greedy Sequential Algorithms}\n\n\\begin{itemize}\n% \\item \\textcolor{red}{\\textbf{Red}} rule. Heaviest edge in a cycle is not in the MST.\n% \\item \\textcolor{blue}{\\textbf{Blue}} rule. \n\\item Lightest edge across a cut is in the MST.\n\\end{itemize}\n\\begin{itemize}\n  \\item Kruskal's algorithm\n    \\begin{itemize} \n      \\item Adding the minimum weighted edge without forming a cycle.\n    \\end{itemize}\n  \\item Prim's algorithm\n    \\begin{itemize} \n      \\item Expanding by selecting the minimum weighted outgoing edge.\n    \\end{itemize}\n  \\item Boruvka's algorithm\n    \\begin{itemize}\n      \\item Locally merging components by picking the minimum weighted edge connecting both components.\n    \\end{itemize}\n\\end{itemize}\n\\end{frame}\n\n% \\begin{frame}\n% \\begin{figure}\n%     \\resizebox{.48\\textwidth}{!}{\n% \\animategraphics{12}{figures/KruskalDemo-}{0}{92}\n% }\n%     \\resizebox{.48\\textwidth}{!}{\n% \\animategraphics{12}{figures/PrimAlgDemo-}{0}{57}\n% }\n% \\caption{Left: Kruskal's Algorithm; Right: Prim's Algorithm}\n% \\end{figure}\n% \\end{frame}", "meta": {"hexsha": "932ffeb7adce4b808f12524662dcf74d1aed3e4f", "size": 1694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/introduction.tex", "max_stars_repo_name": "renmengye/dist-mst-talk", "max_stars_repo_head_hexsha": "25f6a36c4cae5688fe7fa7965d4945e07f4b2909", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/introduction.tex", "max_issues_repo_name": "renmengye/dist-mst-talk", "max_issues_repo_head_hexsha": "25f6a36c4cae5688fe7fa7965d4945e07f4b2909", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/introduction.tex", "max_forks_repo_name": "renmengye/dist-mst-talk", "max_forks_repo_head_hexsha": "25f6a36c4cae5688fe7fa7965d4945e07f4b2909", "max_forks_repo_licenses": ["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.7192982456, "max_line_length": 122, "alphanum_fraction": 0.7113341204, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749422, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6606551254450599}}
{"text": "\n\n    \\filetitle{diff}{First difference pseudofunction}{modellang/diff}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\ndiff(Expr)\ndiff(Expr,K)\n\\end{verbatim}\n\n\\paragraph{Description}\\label{description}\n\nIf the input argument \\texttt{K} is not specified, this pseudofunction\nexpands to\n\n\\begin{verbatim}\n((Expr)-(Expr{-1}))\n\\end{verbatim}\n\nIf the input argument \\texttt{K} is specified, it expands to\n\n\\begin{verbatim}\n((Expr)-(Expr{K}))\n\\end{verbatim}\n\nThe two derived expressions, \\texttt{Expr\\{-1\\}} and \\texttt{Expr\\{K\\}},\nare based on \\texttt{Expr}, and have all its time subscripts shifted by\n--1 or by \\texttt{K} periods, respectively.\n\n\\paragraph{Example}\\label{example}\n\nThese two lines\n\n\\begin{verbatim}\ndiff(Z)\ndiff(log(X{1})-log(Y{-1}),-2)\n\\end{verbatim}\n\nwill expand to\n\n\\begin{verbatim}\n((Z)-(Z{-1}))\n((log(X{1})-log(Y{-1}))-(log(X{-1})-log(Y{-3})))\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "417b7c1ee31e9aefe63b1f9186364f6144c2ab77", "size": 886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/diff.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/diff.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/diff.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.4583333333, "max_line_length": 72, "alphanum_fraction": 0.6963882619, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6606551230875994}}
{"text": "% Notes about SICP\n\n\\documentclass{article}\n\n\\usepackage{times}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\title{NOTES of SICP}\n\\author{南山竹\\\\\n  \\texttt{https://github.com/junjiemars/sicp.git}}\n\\date{\\today}\n\\maketitle\n\n\\begin{abstract}\nFocus on the math parts\n\\end{abstract}\n\n\n\\section*{1.2 Procedures and the Processes They Generate}\n\n\\subsection*{1.2.4 Exponentiation}\nConsider computing the exponential of a given number $n$ based on $b$.\n\\begin{align*}\nb^n &= b \\cdot b^{n-1},\\\\\nb^0 &= 1,\n\\end{align*}\nThis is a linear recursive process, which requires $\\Theta(n)$ steps and $\\Theta(n)$ spaces.\\\\\n\\\\\nWe can compute exponentials in $\\Theta(log\\: n)$ steps by using successive squaring.\n\\begin{align*}\nb^n &= (b^{\\frac{n}{2}})^2 && \\text{if } n \\text{ is even,}\\\\\nb^n &= b \\cdot b^{n-1} && \\text{if } n \\text{ is odd.}\n\\end{align*}\nTranslate the above computing to iterative process.\n\\begin{align*}\nb^n &= (b^2)^{\\frac{n}{2}} && \\text{if } n \\text{ is even,}\\\\\nb^n &= b \\cdot (b^2)^{\\frac{n-1}{2}} && \\text{if } n \\text{ is odd.}\n\\end{align*}\n\n\n\\end{document}", "meta": {"hexsha": "378f0b823e297ec5ba6ffb138e82820ec566fc9f", "size": 1059, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes.tex", "max_stars_repo_name": "junjiemars/sicp", "max_stars_repo_head_hexsha": "00cf11e1d8c0a18a3ddda39be83d3ae777b17eb8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes.tex", "max_issues_repo_name": "junjiemars/sicp", "max_issues_repo_head_hexsha": "00cf11e1d8c0a18a3ddda39be83d3ae777b17eb8", "max_issues_repo_licenses": ["MIT"], "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": "junjiemars/sicp", "max_forks_repo_head_hexsha": "00cf11e1d8c0a18a3ddda39be83d3ae777b17eb8", "max_forks_repo_licenses": ["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.6279069767, "max_line_length": 94, "alphanum_fraction": 0.657223796, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.6605831471615621}}
{"text": "\\chapter{Semantics for First-Order Logic}\n\n\\section{Truth, Models, and Assignments}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item In this chapter, we're going to develop the standard semantics for the first-order languages we've described and studied in the previous chapter. That is, we want to define the concept of a \\emph{model} for these languages. The aim is, as always in logical semantics, to give a formal account of valid inference using truth-preservation across all models (cf. 1.1.5 and 5.2.1). We will do so, making use of several ideas from the elementary set-theory chapter, in particular \\S3.6. So, make sure you're up to speed on properties, relations, and functions.\n\t\t\n\t  \\item Note that a model for propositional logic,\n\t\ti.e.\\ an assignment,\n\t\tinterprets the \\emph{non-logical} vocabulary of the language in question (as truth-values).\n\t\tThe meaning of logical vocabulary,\n\t\ti.e.\\ the sentential operators,\n\t\tis given by the truth-functions.\n\t\tIn first-order logic, the situation is similar.\n\t\tA model interprets the non-logical vocabulary of the first-order language in question,\n\t\ti.e.\\ the signature.\n\t\tThe meaning of the sentential operators is still given by the truth-functions, and we know how those work.\n\t\tThe meaning of the quantifiers, instead, we'll have to study in a bit more detail.\n\t\t\n\t\t\\item Let's begin by informally describing the idea of how we use the concepts from set-theory to provide the notion of a model for a first-order language. In \\S8.1, we discussed the idea that in first-order logic, we need to take the subject-predicate structure of sentences into account but we abstract away from the concrete terms and predicates involved. For now, let's focus on simple, term-property sentences, like ``the ball is red.'' Logically speaking, i.e. abstracting away from the concrete terms and predicates involved, the structure of this sentence is \\[P(a),\\] where $a$ is a constant and $P$ is a unary predicate. Now, constants denote objects and unary predicates express properties. But remember that a property, at least for us, is just a set of objects, the set of objects with the property (cf. 3.6.1). The property of being red, in this picture, is the set of all red things. Now ask yourself, when is the sentence ``the ball is red'' true? Well, the natural answer is, just in case the ball is actually red, i.e. iff the ball is a member of the set of red things. \n\t\t\n\t  \\item How can we formally model this?\n\t\tWell, by assigning the ball as the denotation to $a$ and the set of all red things,\n\t\t$\\{x:\\text{x is red}\\}$,\n\t\tas the interpretation to $P$.\n\t\tTo distinguish the actual ball from it's name, we call the ball $\\llbracket a\\rrbracket$ and use $a$ as its name.\n\t\tOur observation, so far, is that $P(a)$ should be true \\emph{under the intended interpretation} of $a$ and $P$ iff $\\llbracket a\\rrbracket\\in\\{x:\\text{x is red}\\}$, i.e. iff the ball is a member of the set of red things.\n\t\tBut now remember that for our logical purposes, we abstract away from the concrete terms and predicates involved, so we should forget about their meaning, too: $P(a)$ is just a formula.\n\t\tBut we can use the idea we just described to obtain natural truth-conditions for $P(a)$.\n\t\tAll we need to know is which object $a$ denotes and which property, conceived as a set, $P$ expresses.\n\t\tThen, we can say that $P(a)$ is true iff the object denoted by $a$ is in the set expressed by $P$.\n\t\tAnd that's precisely what a model for first-order logic does: it tells us which objects the terms denote and it tells us which properties (i.e. sets) the predicates express.\n\t\tFrom there, the definition of truth-in-a-model flows rather naturally.\n\t\t\n\t\t\\item Now let's generalize the idea from the previous point. Remember, from 8.1.5, that the general form of a simple sentence in first-order logic is \\[R(t_1, \\mathellipsis, t_n),\\] where $R$ is an $n$-ary predicate and $t_1,\\mathellipsis, t_n$ are terms. For example, the structure of ``the letter is in the left drawer'' is $R(t,u)$, where $t$ stands for ``the letter,'' $u$ stands for ``the left drawer,'' and $R$ stands for ``\\dots is in \\underline{\\phantom{\\dots}}.'' Now, on the intended interpretation, the terms denote the objects in question, that's clear: $\\llbracket t\\rrbracket$ is the letter and $\\llbracket u\\rrbracket$ is the left drawer. The predicate $R$ instead denotes the relation of one thing being inside another. Remember, from 3.6.2, that a binary relation is a set of ordered pairs: the set of pairs where the first thing stands in the relation to the second. So the relation of one thing being inside another is the set $\\{(x,y):x\\text{ is inside }y\\}$. On the intended interpretation, therefore, $R(t,u)$ is true iff $(\\llbracket t\\rrbracket, \\llbracket u\\rrbracket)\\in \\{(x,y):x\\text{ is inside }y\\}$. Now, generally speaking, a model $\\mathcal{M}$ gives us for each term $t$ an object $\\llbracket t\\rrbracket^\\mathcal{M}$ denoted by $t$ in $\\mathcal{M}$, and the model gives us for each $n$-ary predicate $R$ a set $R^\\mathcal{M}$ of $n$-tuples. A formula $R(t_1, \\mathellipsis, t_n)$, then, will be true in model $\\mathcal{M}$ iff $(\\llbracket t_1\\rrbracket^\\mathcal{M}, \\mathellipsis, \\llbracket t_n\\rrbracket^\\mathcal{M})\\in R^\\mathcal{M}$. This is the general idea for truth of simple sentences in a model: a simple sentence is true iff the objects denoted by the terms stand in the relation expressed by the predicate. \t\t\n\t\t\n\t  \\item Note that in the case of the distinguished identity predicate, $=$, the situation is even easier.\n\t\tIn 8.2.4, we discussed the idea that we want $=$ to express actual identity.\n\t\tThe simple identity claim ``Darth Sidious is Palpatine'' is true, for example, iff ``Darth Sidious'' and ``Palpatine'' denote the same person (and for those of you who don't like Star Wars, they do!).\n\t\tThis straight-forwardly generalizes to abstract models: the (one and only) way to achieve what we want is by saying that $t_1=t_2$ is true in a model $\\mathcal{M}$ iff $t_1$ and $t_1$ denote the same object in the model, i.e.\n\t\tiff\n\t\t$\\llbracket t_1\\rrbracket^\\mathcal{M}=\\llbracket t_2\\rrbracket^\\mathcal{M}$.\n\t\n\t  \\item Let's continue thinking about the denotations of terms a bit more.\n\t\tIn 8.1.3--4, we discussed the different kinds of terms recognized in classical, first order logic: constants, variables, and function expressions.\n\t\tNow, constants denote fixed objects, so it's quite clear how to interpret them in a model $\\mathcal{M}$:\n\t\tjust assign an object $a^\\mathcal{M}$ to each constant $a$.\n\t\tAlso with function expressions, it's quite clear what to do.\n\t\tIf we have a function expression like ``the LCA of \\dots and \\underline{\\phantom{\\dots}},''\n\t\tformalized as a binary function symbol $f$,\n\t\tthe intended interpretation is the function that maps any two individuals to their LCA.\n\t\tAnd abstractly speaking, the interpretation of $f$ in a model $\\mathcal{M}$ should just be a binary function, $f^\\mathcal{M}$.\n\t\tIn fact,\n\t\twhen we consider iterations of functions, it's quite clear how to calculate their semantic values using recursion.\n\t\tTake ``the LCA of Ada Lovelace and the LCA of Alan Turing and Angela Merkel,''\n\t\tfor example.\n\t\tIf we formalize this term as \\[f(a,f(b,c)),\\] where $a$ stands for ``Ada Lovelace,'' $b$ for ``Alan Turing,'' $c$ for ``Angela Merkel,'' and $f$ for `the LCA of \\dots and \\underline{\\phantom{\\dots}},''\n\t\tthen the value $\\llbracket f(a,f(b,c))\\rrbracket^\\mathcal{M}$ in a model $\\mathcal{M}$ can be calculated as follows:\n\t\\begin{align*}\n\t\\llbracket f(a,f(b,c))\\rrbracket^\\mathcal{M}&=f^\\mathcal{M}(a^\\mathcal{M}, \\llbracket f(b,c)\\rrbracket^\\mathcal{M})\\\\\n\t&=f^\\mathcal{M}(a^\\mathcal{M}, f^{\\mathcal{M}}(b^\\mathcal{M}, c^\\mathcal{M}))\n\t\\end{align*}\n\t\twhere $a^\\mathcal{M}$ is the object denoted by $a$ in\n\t\t$\\mathcal{M}$, $b^\\mathcal{M}$\n\t\tis the object denoted by $b$ in\n\t\t$\\mathcal{M}$, $c^\\mathcal{M}$\n\t\tis the object denoted by $c$ in $\\mathcal{M}$,\n\t\tand $f^\\mathcal{M}$ is the function expressed by $f$ in $\\mathcal{M}$.\n\t\tWhat's not so clear is how to handle variables, which is what we're going to discuss next.\n\t\n\t\\item Remember that the variables $x,y,z,\\mathellipsis$ are, essentially, logical pronouns, i.e. expressions like ``he,'' ``she,'' ``it.'' How do you figure out what a pronoun like ``it'' refers to? Take the sentence ``it is red,'' for example. Formally, we abstract this to \\[P(x),\\] where $x$ stands for ``it,'' and $P$ stands for ``\\dots is red.'' If we want to know whether $P(x)$ is true, we need to know what $x$ stands for. And even on the intended reading, the natural language sentence itself doesn't give us any clue towards the denotation of $x$. We need more information. If, for example, you're talking to a friend and she says ``Yesterday, I bought a ball. It is red.'' Then you know that $x$ is supposed to refer to the ball. Or if another friend says ``My favorite pen is lying there on the table. It's red.'' Then $x$ is supposed to refer to the pen. There are two important points here: (i) you need some context to determine what pronouns stand for, and (ii) the denotation of the same pronoun in the same sentence can change from context to context. This is all in line with the way we think about variables in mathematics (cf.  2.2.3--10). How can we formally model this behavior? There is nothing in the formula $P(x)$ itself that lets us determine the relevant context, so we shall model the context as \\emph{additional semantic information}: we will introduce the notion of an \\emph{assignment} $\\alpha$, which is essentially just a function that assigns to every variable $x\\in\\mathcal{V}$ an object $\\alpha(x)$. In the same spirit as before, using assignments, we will be able to say that $P(x)$ is true in a model $\\mathcal{M}$ \\emph{under an assignment} $\\alpha$ iff $\\alpha(x)\\in P^\\mathcal{M}$. That is, in order to be able to think about variables, our definition of truth will be relative to a model \\emph{and} an assignment. In order to take into account that the same variable, even within the same sentence, can have different meanings in different contexts, we'll consider different assignments in the same model. \n\t\n\t  \\item The information provided by a model and assignment together is enough to recursively calculate the truth-value $\\llbracket\\phi\\rrbracket^\\mathcal{M}_\\alpha$ (in a model $\\mathcal{M}$ under an assignment $\\alpha$) for formulas $\\phi$, which involve only the sentential operators $\\neg,\\land,\\lor,\\to,\\leftrightarrow$.\n\t\tWe do this just as in propositional logic, i.e. using the truth-functions.\n\t\tThe only really interesting question is how to handle the quantifiers.\n\t\tThe questions are:\n\t\t\\[\\llbracket \\exists x\\phi\\rrbracket^\\mathcal{M}_\\alpha=???\\]\\[\\llbracket \\forall x\\phi\\rrbracket^\\mathcal{M}_\\alpha=???\\]\n\t\tLet's consider the latter, i.e. universal statements like ``everything that's scarlet is red,'' in some more detail (the case for existential claims is analogous).\n\t\tThe form of this statement, as discussed in the previous chapter, is\n\t\t\\[\\forall x(S(x)\\to R(x)),\\]\n\t\twhere $S$ stands for ``\\dots is scarlet'' and $R$ stands for ``\\dots is red.''\n\t\tNow, in light of this, we intuitively want ``everything that's scarlet is red'' to be true iff every object that is scarlet is also red.\n\t\tModeling this in a model under an assignment is not straight-forward, however.\n\t\tSuppose we're dealing with a model $\\mathcal{M}$ which interprets $S$ and $R$ as the sets $S^\\mathcal{M}$ and $R^\\mathcal{M}$ respectively and an assignment $\\alpha$ which tells us that $\\alpha(x)$ is the ball.\n\t\tThis allows us to determine the value of\n\t\t$\\llbracket S(x)\\to R(x)\\rrbracket^\\mathcal{M}_\\alpha$.\n\t\tWe get the value $0$ if the ball is a member of $S^\\mathcal{M}$ (the set of scarlet things in the model) but not of $R^\\mathcal{M}$ (the set of red things in the model); otherwise we get the value 1.\n\t\tBut that is just the truth-value of the formula for \\emph{one} possible value of $x$, namely the the value under $\\alpha$---the ball.\n\t\tTo be able to talk about truly \\emph{all} objects, all possible values $x$ can take, we simply \\emph{change} the values of $x$ under $\\alpha$.\n\t\tLet's write $\\alpha[x\\mapsto d]$ for the assignment that is defined just like $\\alpha$ for all variables other than $x$ but assigns the value $d$ to $x$.\n\t\tWith this notation, we can simply go through all the possible values $x$ can take and check whether $R(x)\\to S(x)$ is true.\n\t\tIf this is the case, we declare $\\forall x(R(x)\\to S(x))$ true; if we can find a value for $x$ such that $R(x)\\to S(x)$ is false, we declare $\\forall x(R(x)\\to S(x))$ false.\n\t\tA bit more precisely, we get:\n\t\t\\[\\llbracket \\forall x(S(x)\\to R(x))\\rrbracket^\\mathcal{M}_\\alpha=1\\text{ iff for all objects }d,\\llbracket S(x)\\to R(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1\\]\n\t\tMore generally, we get the following truth-condition for $\\forall x\\phi$ in a model under an assignment $\\alpha$:\n\t\t\\[\\llbracket \\forall x\\phi\\rrbracket^\\mathcal{M}_\\alpha=1\\text{ iff for all objects }d,\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1\\]\n\t\tIn words, $\\forall x\\phi$ is true in a model under an assignment iff for every possible value of $x$, if we change the value of $x$ to that value (while keeping all the other values the same), $\\phi$ comes out true in the model.\n\t\tAnalogously, we can motivate the following clause for $\\exists$:\n\t\t\t\\[\\llbracket \\exists x\\phi\\rrbracket^\\mathcal{M}_\\alpha=1\\text{ iff for some }d,\\text{ we have }\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1\\]\n\t\tThat is, $\\exists x\\phi$ is true in a model under an assignment iff there is a possible value for $x$, such that if we change the value of $x$ to that value (keeping the rest fixed), we get $\\phi$ to be true.\n\t\tThis is the fundamental idea of how the semantics for $\\forall$ and $\\exists$ works.\n\n\t\t\\item Should we really consider \\emph{all} possible values $x$ can take in the recursive clauses for $\\forall$ and $\\exists$? There are good, intuitive reasons to say that the answer is: \\emph{no}! Huh? Well, consider the statement ``everybody passes the course.'' The logical form of this statement is $\\forall xP(x)$, where $P$ stands for ``\\dots passes.'' If we consider all things as possible values for $x$, this sentence clearly is false: if $x$ denotes the ball, for example, then $P(x)$ is clearly false---a ball can't pass the course. But that's also not what I meant. I mean that every \\emph{student} passes the course. Now, there are two ways of going about modeling this: \\emph{either} we revise the grammatical structure of our sentence to $\\forall x(S(x)\\to P(x))$ \\emph{or} we restrict the possible values for $x$. In the former case, we get the right result, since trivial counterexamples like the ball no longer make problems: if $x$ denotes the ball, then $S(x)$ is false and so $S(x)\\to P(x)$ is true. The only real counterexample will now be a student, i.e. a member of $S^\\mathcal{M}$, that is not a member of $P^\\mathcal{M}$.\tSo, the solution works. But it has a certain flair of ``cheating:'' we revised the grammatical structure of the sentence we wanted to model to something else than what we actually said. In general, this sort of move is not liked by logicians. The other solution, restricting the possible values, is more generally liked. It's the one we shall adopt: in a model $\\mathcal{M}$, we shall restrict the values for all our syntactic expressions to values from a fixed set $D^\\mathcal{M}$---the \\emph{domain} of discourse in the model. The domain of discourse fixes the kinds of things we're talking about. In our example, ``everybody passes,'' the intended domain of discourse should include all and only the students in the course. In arbitrary model, however, the domain can, of course, be arbitrary.\\footnote{There is also a deeper, more technical reason: there is no \\emph{universal} set $U$ of absolutely everything. To see this, note that a set is a thing, so we'd get $U\\in U$. But this kind of thing usually spells trouble: we can quickly derive paradoxes when we allow for sets to contain themselves. This is why in standard set-theory, universal sets, and more generally, sets containing themselves are banned.}\n\t\t\n\t\\item Now everything is in place. We will spend the rest of the chapter pouring the previous ideas into fully formal, precise definitions. But before we do so, it's worth going through two ideas that one might have for how the quantifiers should work that actually \\emph{don't} work. This will shed light on the idea that we're actually using in this course. The first idea is to use substitution as follows: why don't we say that $\\forall x\\phi$ is true iff $(\\phi)[x:=t]$ is true for every term $t$, and, analogously, $\\exists x\\phi$ is true iff for some term $t$, $(\\phi)[x:=t]$? This is known as the \\emph{substitutional account of the quantifiers}. Considering an example of a concrete language and intuitive model quickly shows why this account can't be correct. Take the statement ``there is a red thing,'' which we formalize as $\\exists xR(x)$ in a language with the predicate $R$ for ``\\dots is red'' and additionally only the constant $a$ for the ball. Suppose that we're in a model $\\mathcal{M}$ where there are only two things, the cup and the ball. The constant $a$ duly denotes the ball and $R$ expresses the property of being red, which in our model is such that the cup is red but the ball is not. Additionally, we're working with an assignment $\\alpha$ such that $\\alpha(x)$ is the ball for all variables $x\\in\\mathcal{V}$. Intuitively, it's correct that there is a red thing, namely the cup. So, $\\exists R(x)$ should be true in the model. And, in fact, if we use our idea from above, we get this result: simply change the value of $x$ to the cup and $R(x)$ becomes true. But there is no term that, given our model and assignment, denotes the cup. So, we can't find a $t$ such that  $(R(x))[x:=t]$ comes out true. Our language is just not expressive enough to talk about all the objects in our model. There is no natural way of fixing this. It's simply unfeasible to postulate that we have names for all objects in all models---there are simply to many. There is a way of \\emph{somehow} fixing the idea, but we won't explore it in the course. We'll return to the idea of substitution in the proof theory chapter.\n\t\t\n\t  \\item Another approach we might be tempted to use is to say that:\n\t\t\\[\\llbracket \\forall x(S(x)\\to R(x))\\rrbracket^\\mathcal{M}_\\alpha=1\\text{ iff for every assignment }\\beta, \\llbracket S(x)\\to R(x)\\rrbracket^\\mathcal{M}_\\beta=1\\]\n\t\tThat is, we might be tempted to say that $\\forall x(S(x)\\to R(x))$ is true in a model under an assignment iff $S(x)\\to R(x)$ is true under every other possible assignment in the model.\n\t\tThis actually works in the case of relatively ``simple'' statements like $\\forall x(S(x)\\to R(x))$---if $S(x)\\to R(x)$ is true under every assignment, then it must be true for every object, since for each object we will find at least one assignment $\\beta$ such that $\\beta(x)$ is the object.\n\n\t\tThe approach, however, doesn't work in general. To be precise, we can't say the following:\n\t\t\\[\\llbracket \\forall \\phi\\rrbracket^\\mathcal{M}_\\alpha=1\\text{ iff for every assignment }\\beta, \\llbracket \\phi\\rrbracket^\\mathcal{M}_\\beta=1\\]\n\t\t\\[\\llbracket \\exists \\phi\\rrbracket^\\mathcal{M}_\\alpha=1\\text{ iff for some assignment }\\beta, \\llbracket \\phi\\rrbracket^\\mathcal{M}_\\beta=1\\]\n\t\tOnce the quantificational structure of formulas gets more involved, the approach yields the intuitively wrong outcomes.\n\t\tActually, to illustrate the problem, we can look at a statement with just one quantifier but one other kind of variable.\n\t\tSuppose that we're in a context where ``it'' clearly refers to the smallest natural number, i.e. 0.\n\t\tThen consider the statement\n\t\t``every natural number is bigger than it.''\n\t\tFormally, we'd represent this statement as\n\t\t\\[\\forall yR(x,y),\\]\n\t\twhere $R$ stands for\n\t\t``\\dots is smaller than (or equal to) \\underline{\\phantom{\\dots}}.''\n\t\tThe model the intended reading suggests is to let\n\t\t$D^\\mathcal{M}=\\mathbb{N}$,\n\t\ti.e. we talk about the natural numbers,\n\t\t$R^\\mathcal{M}=\\{(n,m):n\\leq m\\}$\n\t\t(i.e. the relation of being smaller than: the set of numbers such that the first is smaller than (or equal) to the second),\n\t\tand $\\alpha(x)$ is the number zero.\n\t\tIntuitively speaking,\n\t\ton this reading,\n\t\t$\\forall yR(x,y)$ should come out true in such a modeling situation:\n\t\tzero is indeed such that it is smaller than every other number (and identical to itself).\n\t\tBut, alas, the present proposal gives another verdict:\n\t\tit's not the case that for every assignment $\\beta$, $\\llbracket R(x,y)\\rrbracket^\\mathcal{M}_\\beta=1$.\n\t\tJust take any assignment $\\beta$ which assigns $2$ to $x$ and $1$ to $y$.\n\t\tSince $(2,1)\\notin \\{(n,m):n\\leq m\\}=R^\\mathcal{M}$, we get $\\llbracket R(x,y)\\rrbracket^\\mathcal{M}_\\beta=0$.\n\t\tAnd so, according to the proposal, $\\llbracket \\forall yR(x,y)\\rrbracket^\\mathcal{M}_\\alpha=0$.\n\t\t---The problem is that, intuitively, the value of $x$ needs to remain fixed.\n\t\tOur official account from 9.1.9 guarantees this, but the account under consideration does not.\n\t\tThe problem has very much to do with what happens when we have more than one quantifier in a statement.\n\t\tIn fact, our argument can be used to show that in our intended model,  $\\llbracket \\exists x\\forall yR(x,y)\\rrbracket^\\mathcal{M}_\\alpha$ turns out to be $0$, though intuitively it should be $1$.\n\t\tTo see this,\n\t\tnote that our proposal would say that\n\t\t$\\llbracket \\exists x\\forall yR(x,y)\\rrbracket^\\mathcal{M}_\\alpha=1$\n\t\tiff there exists a assignment $\\beta$, such that\n\t\t$\\llbracket \\forall yR(x,y)\\rrbracket^\\mathcal{M}_\\beta=1$,\n\t\twhich in turn would be the case iff for every assignment $\\gamma$, we have\n\t\t$\\llbracket R(x,y)\\rrbracket^\\mathcal{M}_\\gamma=1$.\n\t\tBut we just figured out that no-matter what we start with, while there is a assignment $\\beta$ such that\n\t\t$\\llbracket \\forall yR(x,y)\\rrbracket^\\mathcal{M}_\\beta=1$,\n\t\tit's not the case that, then,\n\t\tfor all assignments $\\gamma$,\n\t\t$\\llbracket R(x,y)\\rrbracket^\\mathcal{M}_\\gamma=1$.\n\t\tNested quantifiers are, in fact, the ultimate reason why we need the official definition that we endorse.\n\t\n\t\\item That's it, these are the ideas that we're going to develop in this chapter. Let's briefly sum up:\n\t\n\t\\begin{itemize}\n\t\n\t\t\\item A model interprets the signature by assigning denotation to every constant, a function to every function symbol, and an $n$-ary relation to every $n$-ary relation symbol\n\t\t\n\t\t\\item An assignment in a model tells us what the variables denote. It plays the role of the context in natural language. \n\t\n\t\t\\item We can recursively calculate the denotation of arbitrary terms in a model under an assignment.\n\t\t\n\t\t\\item We can recursively calculate the truth-value of a formula relative to a model under an assignment.\n\t\n\t\\end{itemize}\n\t\n\tThe rest is, more or less, standard. Validity will be defined as truth-preservation across all models, just like in propositional logic. We'll now make these concepts fully precise.\n\t\n\t\\end{enumerate}\n\t\n\\section{Models and Assignments}\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\t\t\\item As we just said, a model interprets the signature. So, let $\\mathcal{S}=(\\mathcal{C}, \\mathcal{F}, \\mathcal{R})$ be a signature. A \\emph{model} for $\\mathcal{S}$ is a structure $\\mathcal{M}=(D^\\mathcal{M},\\cdot^\\mathcal{M})$, such that:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item $D^\\mathcal{M}$ is a non-empty (!) set, the \\emph{domain} of $\\mathcal{M}$\n\t\t\t\n\t\t\t\\item $\\cdot^\\mathcal{M}$ is an \\emph{interpretation function}, which assigns to:\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item every constant $c\\in\\mathcal{M}$ an element $c^\\mathcal{M}\\in D^\\mathcal{M}$ of the domain\n\t\t\t\t\n\t\t\t  \\item every function symbol $f^n\\in\\mathcal{F}$,\n\t\t\t\ta function $f^\\mathcal{M}:(D^{\\mathcal{M}})^n\\to D^{\\mathcal{M}}$\n\t\t\t\t\n\t\t\t  \\item every predicate $R^n\\in\\mathcal{R}$, a set\n\t\t\t\t$R^\\mathcal{M}\\subseteq (D^{\\mathcal{M}})^n$.\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item \\emph{Examples}. The following are all examples of models for their respective signatures (I took the signatures from Example 7.2.3). It's important to note that for signatures with an intended reading (as in the cases of arithmetic and set-theory), there are both ``intended'' and ``unintended'' models:\n\t\t\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\n\t\t\t\t\t\n\t\t\t\t\\item Signature $\\mathcal{S}_{PA}=(\\{0\\}, \\{S^1, +^2, \\cdot^2\\}, \\emptyset)$\n\t\t\t\t\n\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\t\\item The standard, intended model:\n\t\t\t\t\t\n\t\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\mathbb{N}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $0^\\mathcal{M}=0$\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $S^\\mathcal{M}(n)=n+1$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $+^\\mathcal{M}(n,m)=n+m$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $\\cdot^\\mathcal{M}(n,m)=n\\cdot m$\n\t\t\t\t\t\n\t\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\t\n\t\t\t\t\t\\item A natural, but non-intended model on the even numbers:\n\t\t\t\t\t\n\t\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\{n\\in\\mathbb{N}:n\\text{ is even}\\}$\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\item $0^\\mathcal{M}=0$\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $S^\\mathcal{M}(n)=n+2$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $+^\\mathcal{M}(n,m)=n+m$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $\\cdot^\\mathcal{M}(n,m)=n\\cdot m$\n\t\t\t\t\t\n\t\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\t\n\t\t\t\t\t\\item A natural, but non-intended model on the odd numbers:\n\t\t\t\t\t\n\t\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\{n\\in\\mathbb{N}:n\\text{ is odd}\\}$\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\item $0^\\mathcal{M}=1$\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $S^\\mathcal{M}(n)=n+2$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $+^\\mathcal{M}(n,m)=\\begin{cases}n+m&\\text{if }n+m\\text{ is odd}\\\\n+m+1&\\text{ otherwise}\\end{cases}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $\\cdot^\\mathcal{M}(n,m)=n\\cdot m$\n\t\t\t\t\t\n\t\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\t\n\t\t\t\t\tWhy the weird clause for $+^\\mathcal{M}$? Because $+^\\mathcal{M}$ needs to be a function from $\\{n\\in\\mathbb{N}:n\\text{ is odd}\\}$ to $\\{n\\in\\mathbb{N}:n\\text{ is odd}\\}$ and $n+m$ can be even if $n,m$ are both odd: just take $1+1$.\n\t\t\t\t\t\t\n\t\t\t\t\t\\item A weird, non-intended model:\n\t\t\t\t\t\n\t\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\mathbb{N}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\item $0^\\mathcal{M}=42$\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $S^\\mathcal{M}(n)=n$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $+^\\mathcal{M}(n,m)=n\\cdot m$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $\\cdot^\\mathcal{M}(n,m)=n^m$\n\t\t\t\t\t\n\t\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\\item A \\emph{really} weird, non-intended model:\n\t\t\t\t\t\n\t\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\{\\ast\\}$\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\item $0^\\mathcal{M}=\\ast$\n\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $S^\\mathcal{M}(\\ast)=\\ast$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $+^\\mathcal{M}(\\ast,\\ast)=\\ast$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $\\cdot^\\mathcal{M}(\\ast,\\ast)=\\ast$\n\t\t\t\t\t\n\t\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{S}_\\emptyset=(\\emptyset,\\emptyset,\\emptyset)$\n\t\n\t\t\t\t\\begin{itemize}\n\t\t\t\t\n\t\t\t\t\t\\item Literally, every set is a model!\n\t\t\t\t\n\t\t\t\t\\end{itemize}\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{S}_\\in=(\\{\\emptyset\\}, \\emptyset, \\{\\in^2\\})$\n\t\t\t\t\n\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\\item The intended model cannot be described using our methods, since there is no set of all sets (leads to paradox). But here is a natural, model for the language:\n\t\t\t\t\t\n\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\mathbb{N}\\cup\\wp(\\mathbb{N})$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\emptyset^\\mathcal{M}=\\emptyset$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\in^\\mathcal{M}=\\{(x,X)\\in \\mathbb{N}\\times\\wp(\\mathbb{N}): x\\in X\\}$\n\t\t\t\t\t\t\n\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\\item The following model is not really intended, but works:\n\t\t\t\t\t\n\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\wp(\\mathbb{N})$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\emptyset^\\mathcal{M}=\\emptyset$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\in^\\mathcal{M}=\\{(X,Y): X\\subseteq Y\\}$\n\t\t\t\t\t\t\n\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\\item The following model is weird:\n\t\t\t\t\t\n\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\{a,b,c\\}$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\emptyset^\\mathcal{M}=c$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\in^\\mathcal{M}=\\{(a,c), (b,c), (c,c), (a,b)\\}$\n\t\t\t\t\t\t\n\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\n\t\t\t\t\\item $\\mathcal{S}=(\\{a,b,c\\}, \\{f^1, g^2\\}, \\{P^1, R^2\\})$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\n\t\t\t\t\t\t\\item There is no real intended model, so let's just describe some arbitrary one.\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $D^\\mathcal{M}=\\{1,2,3,4\\}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $a^\\mathcal{M}=1, b^\\mathcal{M}=3, c^\\mathcal{M}=2$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $f^\\mathcal{M}(x)=x$ for each $x\\in D^\\mathcal{M}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $g^\\mathcal{M}(x,y)=min(x,y)$ for all $x,y\\in D^\\mathcal{M}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $P^\\mathcal{M}=\\{1,3\\}$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item $R^\\mathcal{M}=\\{(1,1), (1,2),(2,2) (2,3), (3,3)\\}$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\\end{itemize}\t\t\n\t\t\t\t\t\t\t\n\t\t\t\\end{enumerate}\t\t\n\t\t\t\n\t\t\t\\item \\label{fo_sem_empty} Note that the domain in every model is postulated to be non-empty. The reason for this is that otherwise, we'd get weird results, which we'll be able to see in a moment. But for now, you can already note that if we had an empty domain, we couldn't assign denotations to the constants. But in natural language reasoning, it's a standard presupposition that if you're talking about something, if you give it a name, then it exists---at least for the purpose of your reasoning process. \n\t\n\t\t\\item Next, we give a precise formulation to the concept of an assignment in a model. This is easy: an \\emph{assignment} in a model $\\mathcal{M}=(D^\\mathcal{M},\\cdot^\\mathcal{M})$ of signature $\\mathcal{S}$ is a function $\\alpha:\\mathcal{V}\\to D^\\mathcal{M}$. \n\t\t\n\t\t\\item \\emph{Examples}: Note that for the assignment, the only component of the model that matters is the domain, since the variables assume values from here.\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item Models with domain $D^\\mathcal{M}=\\mathbb{N}$ (9.2.2.i.a--d):\n\t\t\t\n\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\t\\item $\\alpha(x_1)=0, \\alpha(y)=1, \\alpha(z)=2$\n\t\t\t\t\t\n\t\t\t\t\t\\item $\\alpha(x)=1, \\alpha(y)=0, \\alpha(z)=3$\n\t\t\t\t\t\n\t\t\t\t\t\\item $\\alpha(x)=0, \\alpha(y)=0, \\alpha(z)=0$\n\t\t\t\t\t\n\t\t\t\t\t\\item For $\\mathcal{V}=\\{x_i:i\\in\\mathbb{N}\\}$, $\\alpha(x_i)=i$.\n\t\t\t\t\t\\item $\\alpha(x)=1$ for all $x\\in\\mathcal{V}$.\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\t\n\t\t\t\\item Models with domain $D^\\mathcal{M}=\\mathbb{N}\\cup\\wp(\\mathbb{N})$ (9.2.2.iii.a):\n\n\t\t\t\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\t\t\t\\item $\\alpha(x)=2, \\alpha(y)=\\{2\\}, \\alpha(z)=\\mathbb{N}$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\alpha(x)=\\{x\\in\\mathbb{N}:n\\text{ is even}\\}, \\alpha(y)=\\{n\\in\\mathbb{N}:x\\text{ is odd}\\}, \\alpha(z)=\\{n\\in\\mathbb{N}:x\\text{ is prime}\\}$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\item $\\alpha(x)=0$ for all $x\\in\\mathcal{V}$.\n\n\t\t\t\t\t\t\\end{enumerate}\n\n\t\t\t\\item For $D^\\mathcal{M}=\\{\\ast\\}$ (9.2.2.i.e) there is only \\emph{one} assignment, which is the constant assignment $\\alpha(x)=\\ast$ for all $x\\in\\mathcal{V}$\n\n\t\t\\end{enumerate}\n\t\t\n\t\t\n\t\tNote that \\emph{any} function $\\alpha:\\mathcal{V}\\to D^\\mathcal{M}$ is an assignment: we can have that multiple variables assume the same value or that some values are not assumed by any variable.\n\t\t\n\t\t\\item With the concept of a model and an assignment in place, we can define the \\emph{denotation} $\\llbracket t\\rrbracket_\\alpha^\\mathcal{M}$ of a term $t$ in a model $\\mathcal{M}$ under assignment $\\alpha$ by the following recursion:\n\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item\t\t\\begin{enumerate}[(i)]\n\n\t\t\t\t\t\\item $\\llbracket x\\rrbracket_\\alpha^\\mathcal{M}=\\alpha(x)$\n\t\t\t\t\t\\item $\\llbracket c\\rrbracket_\\alpha^\\mathcal{M}=c^\\mathcal{M}$\n\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\t\n\t\t\t\t\\item $\\llbracket f(t_1,\\mathellipsis,t_n)\\rrbracket_\\alpha^\\mathcal{M}=f^\\mathcal{M}(\\llbracket t_1\\rrbracket_\\alpha^\\mathcal{M}, \\mathellipsis, \\llbracket t_n\\rrbracket_\\alpha^\\mathcal{M})$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\\item \\emph{Examples}: \n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item In the standard model for $\\mathcal{S}_{PA}$ (9.2.2.i.a) with $\\alpha(x)=0,\\alpha(y)=1,\\alpha(z)=2$ (9.2.5.i.a):\n\t\t\t\\begin{align*}\n\t\t\t\\llbracket 0\\rrbracket^\\mathcal{M}_\\alpha&=0\\\\\n\t\t\t\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha&=0\\\\\n\t\t\t\\llbracket S(0)\\rrbracket^\\mathcal{M}_\\alpha&=1\\\\\n\t\t\t\\llbracket y\\cdot S(0)\\rrbracket^\\mathcal{M}_\\alpha&=1\\\\\n\t\t\t\\llbracket S(((x\\cdot y)+z))\\rrbracket^\\mathcal{M}_\\alpha&=3\n\t\t\t\\end{align*}\n\t\t\t\n\t\t\t\\item In the non-intended model for $\\mathcal{S}_{PA}$ (9.2.2.i.b), which has $D^\\mathcal{M}=\\{x:x\\text{ is even}\\}$, with $\\alpha(x)=0,\\alpha(y)=0,\\alpha(z)=0$ (9.2.5.i.c):\n\t\t\t\\begin{align*}\n\t\t\t\\llbracket 0\\rrbracket^\\mathcal{M}_\\alpha&=0\\\\\n\t\t\t\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha&=0\\\\\n\t\t\t\\llbracket S(0)\\rrbracket^\\mathcal{M}_\\alpha&=2\\\\\n\t\t\t\\llbracket y\\cdot S(0)\\rrbracket^\\mathcal{M}_\\alpha&=0\\\\\n\t\t\t\\llbracket S(((x\\cdot y)+z))\\rrbracket^\\mathcal{M}_\\alpha&=2\n\t\t\t\\end{align*}\n\t\t\t\n\t\t\t\\item In the non-intended model for $\\mathcal{S}_{PA}$ (9.2.2.i.c), which has $D^\\mathcal{M}=\\{x:x\\text{ is odd}\\}$, with $\\alpha(x)=1$ for all $x\\in\\mathcal{V}$ (9.2.5.i.e):\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\llbracket 0\\rrbracket^\\mathcal{M}_\\alpha&=1\\\\\n\t\t\t\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha&=1\\\\\n\t\t\t\\llbracket S(0)\\rrbracket^\\mathcal{M}_\\alpha&=3\\\\\n\t\t\t\\llbracket y\\cdot S(0)\\rrbracket^\\mathcal{M}_\\alpha&=3\\\\\n\t\t\t\\llbracket S(((x\\cdot y)+z))\\rrbracket^\\mathcal{M}_\\alpha&=5\n\t\t\t\\end{align*}\n\t\t\t\n\t\t\t\\item In the non-intended model for $\\mathcal{S}_{PA}$ (9.2.2.i.d), which has $D^\\mathcal{M}=\\{x:x\\text{ is odd}\\}$, with $\\alpha(x)=0,\\alpha(y)=1,\\alpha(z)=2$ (9.2.5.i.a):\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\llbracket 0\\rrbracket^\\mathcal{M}_\\alpha&=42\\\\\n\t\t\t\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha&=0\\\\\n\t\t\t\\llbracket S(0)\\rrbracket^\\mathcal{M}_\\alpha&=42\\\\\n\t\t\t\\llbracket y\\cdot S(0)\\rrbracket^\\mathcal{M}_\\alpha&=1^{42}=1\\\\\n\t\t\t\\llbracket S(((x\\cdot y)+z))\\rrbracket^\\mathcal{M}_\\alpha&=(0^1)\\cdot 2=0\n\t\t\t\\end{align*}\n\t\t\t\n\t\t  \\item Consider the abstract model (9.2.2.iv).\n\t\t\tIn that model we have under the assignment $\\alpha(x)=1, \\alpha(y)=4, \\alpha(z)=2$, we have:\n\t\t\t\\begin{align*}\n\t\t\t  \\llbracket f(f(x))\\rrbracket^\\mathcal{M}_\\alpha&=f^{\\mathcal{M}}(f^{\\mathcal{M}}(\\alpha(x))=1\\\\\n\t\t\t  \\llbracket g(b,c)\\rrbracket^\\mathcal{M}_\\alpha&=min(b^\\mathcal{M}, c^\\mathcal{M})=min(3,2)=2\\\\\n\t\t\t  \\llbracket g(b,y)\\rrbracket^\\mathcal{M}_\\alpha&=min(b^\\mathcal{M}, \\alpha(y))=min(3,4)=3\\\\\n\t\t\t  \\llbracket g(f(f(x)), g(b,c))\\rrbracket^\\mathcal{M}_\\alpha&=min(\\alpha(x), min(b^\\mathcal{M}, c^\\mathcal{M}))=min(1,min(3,2))=1\\\\\n\t\t\t  \\llbracket f(g(g(a,b),g(b,c))))\\rrbracket^\\mathcal{M}_\\alpha&=min(min(a^\\mathcal{M}, b^\\mathcal{M}), min(b^\\mathcal{M}, c^\\mathcal{M}))=min(min(1,3), min(3,2))=1\\\\\n\t\t\t\\end{align*}\n\n\t\t\\end{enumerate}\n\t\tNote that both the model and assignment crucially affect the values of terms.\n\t\tThe results in weird models can be weird.\n\t\tTry some more examples by yourself.\n\t\t\n\t\t\\item Finally, we shall define the crucial operation of changing the value of a variable under an assignment, which we need for the clauses for the quantifiers. Let $\\alpha$ be an assignment in a model $\\mathcal{M}=(D^\\mathcal{M},\\cdot^\\mathcal{M})$. We define the function $\\alpha[x\\mapsto d]$, which is the result of setting the value of variable $x\\in\\mathcal{V}$ to $d\\in D^\\mathcal{M}$, by the following condition:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item $\\alpha[x\\mapsto d](y)=\\begin{cases} \\alpha(y) &\\text{if }y\\neq x\\\\ d & \\text{if }y=x\\end{cases}$\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\tIt follows immediately from the definition that for all  $d\\in D^\\mathcal{M}$, \\[\\llbracket x\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=d.\\] We introduce the following useful notation for iterated changes: instead of $\\alpha[x\\mapsto d][y\\mapsto e]$ we write $\\alpha[x\\mapsto d, y\\mapsto e]$.\n\t\t\n\t\t\\item To tighten our understanding of terms and their denotations, we shall prove the following lemma:\n\t\t\\begin{lemma}[Term Locality Lemma]\n\t\tLet $\\mathcal{M}$ be a model and $t$ a term with precisely the variables in set $V$ in it. Then for all assignments $\\alpha$ and $\\beta$ in $\\mathcal{M}$, if $\\alpha(x)=\\beta(x)$ for all $x\\in V$, then $\\llbracket t\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket t\\rrbracket_\\beta^\\mathcal{M}$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\tWe also prove this fact by induction on terms. \n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\\item For the induction base, note we distinguish two cases: (a) $t$ is a constant or (b) $t$ is a variable. If (a), $t$ is a constant $a\\in\\mathcal{C}$, we can reason that $\\llbracket a\\rrbracket^\\mathcal{M}_\\alpha=a^\\mathcal{M}=\\llbracket a\\rrbracket^\\mathcal{M}_\\beta$ for all assignments $\\alpha,\\beta$. If (b) $t$ is a variable $x$, then $V=\\{x\\}$ and so $\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha=\\alpha(x)=\\beta(x)=\\llbracket a\\rrbracket^\\mathcal{M}_\\beta$. \n\t\t\n\t\t\\item For the induction step, consider a term $f(t_1, \\mathellipsis, t_n)$ and suppose the induction hypothesis for all $t_i$, i.e. if $t_i$ contains precisely variables $V_i$ and $\\alpha(x)=\\beta(x)$ for all $x\\in V_i$, then $\\llbracket t_i\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket t_i\\rrbracket_\\beta^\\mathcal{M}$. Now suppose that $f(t_1, \\mathellipsis, t_n)$ contains variables $V$ and $\\alpha(x)=\\beta(x)$ for all $x\\in V$. Now for each $t_i$, we get that the variables $V_i$ in $t_i$ are also in $t$, i.e. $V_i\\subseteq V$. Since $\\alpha(x)=\\beta(x)$ for all $x\\in V$, it follows that $\\alpha(x)=\\beta(x)$ for all $x\\in V_i$. But then, by the induction hypothesis, we get for each $t_i$ that $\\llbracket t_i\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket t_i\\rrbracket_\\beta^\\mathcal{M}$. We can conclude that:\n\t\\begin{center}\n\t\t\\begin{tabular}{c c c c c c ll}\n\t\t$\\llbracket f(t_1, \\mathellipsis, t_n)\\rrbracket^\\mathcal{M}_\\alpha$ = & $f^\\mathcal{M}($ & $\\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha$ &  \\dots & $\\llbracket t_n\\rrbracket^\\mathcal{M}_\\alpha)$\\\\\n\t\t & & \\rotatebox{90}{=} & & \\rotatebox{90}{=} &\\\\\n\t\t& $f^\\mathcal{M}($ & $\\llbracket t_1\\rrbracket^\\mathcal{M}_\\beta$ &  \\dots & $\\llbracket t_n\\rrbracket^\\mathcal{M}_\\beta)$&=$\\llbracket f(t_1, \\mathellipsis, t_n)\\rrbracket^\\mathcal{M}_\\beta$ \\\\\n\t\t\\end{tabular}\n\t\t\\end{center}\n\t\t\n\t\\end{itemize}\nThis concludes our induction.\t\t\t\t\n\t\t\n\t\\end{proof}\n\tThe Locality Lemma essentially states that the value of a term under an assignment only depends on the values the assignment gives to the variables in the term. In fact, we can infer the following corollary about \\emph{ground terms}, i.e. terms without variables in them\n\t\t\\begin{corollary}[Ground Terms Lemma]\n\t\tLet $\\mathcal{M}$ be a model and $t\\in\\mathcal{T}$ a ground term. Then for all assignments $\\alpha,\\beta$, we have $\\llbracket t\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket t\\rrbracket_\\beta^\\mathcal{M}$.\n\t\t\\end{corollary}\n\t\t\\begin{proof}\n\t\tExercise 9.7.3.\n\t\t\\end{proof}\n\t\n\t  \\item \\textbf{This passage has been added for clarification purposes.}\n\n\t\tThere was some confusion about how to solve exercise 9.7.2, also among the TAs.\n\t\tSo, I suppose I should have been clearer on the different variants of inductive proof, and so I'm trying to remedy the situation here.\n\t\tRemember that for \\emph{every} inductively defined set, we have a corresponding principle for proof by induction.\n\t\tThe idea is that if we can establish that all the basic or initial elements of the set have a property and the property is preserved under the constructions, then all elements of the set have the property.\n\t\tWe're mainly relying on two versions of this proof principle, induction on terms and inductions of formulas.\n\t\tBut sometimes, we want to prove things about inductively defined \\emph{subsets} of the terms or formulas.\n\t\tThis exercise is such a case.\n\n\t\tIn this exercise, we want to prove that all terms of a certain form, namely numerals of the form\n\t\t$S(\\underbrace{\\mathellipsis}_{n\\text{ times}}S(0)\\mathellipsis))=n$\n\t\thave a certain semantic property: a given denotation.\n\t\tIn order to use proof by induction for this purpose, we need to recognize that the terms in question have an inductive structure: their set can be defined by induction.\n\t\tThe definition, in this case, is simple: the initial element is the term (!) 0 and the construction is writing the function symbol $S$ in front of a term.\n\t\tLet's call the terms constructed in this way \\emph{natural numerals}.\n\t\tThe corresponding induction principle for the construction of natural numerals states that if the natural numeral 0 has a property, and if a natural numeral $n$ has the property then the numeral $S(n)$ has the property, then all natural numerals have the property in question.\n\t\tHere is the solution for exercise i) of 9.7.2:\n\n\t\t\\begin{lemma}[9.7.2.i]\n          Let $\\mathcal{M}$ be the standard model for the $PA$ (as defined in 9.2.2) and $\\alpha$ an arbitrary assignment.\n\t\t  Then for all terms of the form $n\\in\\mathcal{T}$, we have $\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha=n$.\n\t\t\\end{lemma}\n        \\begin{proof}\n          We prove this fact using induction on the natural numerals, i.e. terms of the form $n=S(\\mathellipsis S(0)\\mathellipsis)$.\n\t\t  For the base case, consider the term $0$.\n\t\t  By definition, we have that $\\llbracket 0\\rrbracket^\\mathcal{M}_\\alpha=0^\\mathcal{M}=0$.\n\t\t  Now, for the induction step, assume the induction hypothesis, that for the term $n=S(\\mathellipsis S(0)\\mathellipsis)$ we have  $\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha=n$.\n\t\t  We need to show that for the term $S(n)=n+1$, we have  $\\llbracket S(n)\\rrbracket^\\mathcal{M}_\\alpha=n+1$.\n\t\t  Now note that $\\llbracket S(n)\\rrbracket^\\mathcal{M}_\\alpha=S^\\mathcal{M}(\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha)=\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha+1$.\n\t\t  But by the induction hypothesis, we have $\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha=n$, so we have  $\\llbracket S(n)\\rrbracket^\\mathcal{M}_\\alpha=n+1$, as desired.\n        \\end{proof}\n\n        Note that we can use similar methods for other inductively definable subsets of terms or formulas.\n\t\tWe can, for example, prove facts about all terms without variables (i.e. \\emph{ground terms}) by showing that all constants have the property and the property is preserved under applying function symbols.\n\t\tOr, we can show that all formulas with an even number of negations have a property by showing that all atomic formulas have the property and that the property is preserved under writing two negations in front of a formula.\n\t\tIn the following, we shall often (sometimes implicitly) make use of such ``restricted'' forms of induction on terms or variables.\n\t\n\t\\end{enumerate}\n\n\n\\section{Truth in a Model}\n\n\n\t\\begin{enumerate}[\\thesection.1]\n\t\t\t\n\t\t\\item Using the ideas from \\S9.1, we can now define the truth-value $\\llbracket\\phi\\rrbracket^\\mathcal{M}_\\alpha$ of a formula $\\phi$ under an assignment $\\alpha$ in a model $\\mathcal{M}$ by the following recursion:\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\n\t\t  \\item\t\\begin{enumerate}[(a)]\n\n\t\t\t\t  \\item $\\llbracket R(t_1,\\mathellipsis, t_n)\\rrbracket_\\alpha^\\mathcal{M}=\\begin{cases} 1 & \\text{if }(\\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha,\\mathellipsis, \\llbracket t_n\\rrbracket^\\mathcal{M}_\\alpha)\\in R^\\mathcal{M}\\\\0 &\\text{otherwise}\\end{cases}$\n\n\t\t\t\t  \\item $\\llbracket t_1=t_2\\rrbracket_\\alpha^\\mathcal{M}=\\begin{cases} 1 & \\text{if }\\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha=\\llbracket t_2\\rrbracket^\\mathcal{M}_\\alpha)\\\\0 &\\text{otherwise}\\end{cases}$\n\t\t\t\t\\end{enumerate}\n\n\t\t  \\item \\begin{enumerate}[(a)]\n\n\t\t\t\t  \\item  $\\llbracket\\neg \\phi\\rrbracket^\\mathcal{M}_\\alpha=f_\\neg(\\llbracket\\phi\\rrbracket^\\mathcal{M}_\\alpha)$\n\n\t\t\t\t  \\item  $\\llbracket(\\phi\\circ \\psi)\\rrbracket^\\mathcal{M}_\\alpha=f_\\circ( \\llbracket\\phi\\rrbracket^\\mathcal{M}_\\alpha, \\llbracket\\psi\\rrbracket^\\mathcal{M}_\\alpha)$ for $\\circ=\\land,\\lor,\\to,\\leftrightarrow$\n\n\t\t\t\t  \\item $\\llbracket\\exists x\\phi\\rrbracket_\\alpha^\\mathcal{M}=max(\\{\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}: d\\in D^\\mathcal{M}\\})$\n\n\t\t\t\t  \\item[] $\\llbracket\\forall x\\phi\\rrbracket_\\alpha^\\mathcal{M}=min(\\{\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}: d\\in D^\\mathcal{M}\\})$\n\n\t\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\\end{enumerate}\n\n\t\t\tNote that we're using the $min$ and $max$ functions here as functions defined on (non-empty) \\emph{sets} of truth-values $X\\subseteq\\{0,1\\}$, i.e. $min(X)$ is the smallest element of $X$ and $max(X)$ is the biggest element of $X$. More explicitly, we have $max(\\{0\\})=0, max(\\{1\\})=1, max(\\{1,0\\})=1$, and $min(\\{0\\})=0, min(\\{1\\})=1, min(\\{1,0\\})=0$. It might \\emph{look} like $\\{\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}: d\\in D^\\mathcal{M}\\}$ is a (possibly) quite big set, depending on the size of $D^\\mathcal{M}$. But note that each of the individual values $\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}$ is either $0$ or $1$. Since multiplicity doesn't matter in sets, the set $\\{\\llbracket \\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}: d\\in D^\\mathcal{M}\\}$ is either $\\{0\\}$, $\\{1\\}$, or $\\{0,1\\}$.\n\t\t\n\t\t\t\n\t  \\item Just like in (5.1.11), we can define truth in a model under a assignment as a \\emph{property} of formulas.\n\t\tHere, we don't do this as an alternative definition, as we did in \\S5.1, but rather, we take the property\n\t\t$\\mathcal{M},\\alpha\\vDash\\phi$\n\t\tof a formula being true in a model under an assignment to be \\emph{defined} as follows:\n\t\t\t\n\t\t\t\\begin{itemize}\n\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash\\phi$\n\t\t\t\tiff\n\t\t\t\t$\\llbracket\\phi\\rrbracket^\\mathcal{M}_\\alpha=1$\n\t\t\t\n\t\t\t\\end{itemize}\n\t\t\t\n\t  \\item Using this definition,\n\t\twe can provide the following lemma,\n\t\twhich has the potential to make Definition 9.3.1 more transparent:\n\t\t\t\n\t\t\t\\begin{lemma} For every model $\\mathcal{M}$ and assignment $\\alpha$, we have:\n\t\t\t\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash R(t_1,\\mathellipsis, t_n)$\n\t\t\t\tiff\n\t\t\t\t$(\\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha,\\mathellipsis, \\llbracket t_n\\rrbracket^\\mathcal{M}_\\alpha)\\in R^\\mathcal{M}$\n\t\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash t_1=t_2$\n\t\t\t\tiff\n\t\t\t\t$\\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha=\\llbracket t_2\\rrbracket^\\mathcal{M}_\\alpha$\n\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash \\neg\\phi$\n\t\t\t\tiff\n\t\t\t\t$\\mathcal{M},\\alpha\\nvDash\\phi$\n\t\t\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash(\\phi\\land\\psi)$\n\t\t\t\tiff\n\t\t\t\t$\\mathcal{M},\\alpha\\vDash\\phi$ and $\\mathcal{M},\\alpha\\vDash\\psi$\n\t\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash(\\phi\\lor\\psi)$\n\t\t\t\tiff\n\t\t\t\t$\\mathcal{M},\\alpha\\vDash\\phi$ or $\\mathcal{M},\\alpha\\vDash\\psi$\n\t\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash(\\phi\\to\\psi)$\n\t\t\t\tiff\n\t\t\t\t$\\mathcal{M},\\alpha\\nvDash\\phi$ or $\\mathcal{M},\\alpha\\vDash\\psi$\n\t\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash(\\phi\\leftrightarrow\\psi)$\n\t\t\t\tiff\n\t\t\t\teither $\\mathcal{M},\\alpha\\vDash\\phi$ and $\\mathcal{M},\\alpha\\vDash\\psi$,\n\t\t\t\tor $\\mathcal{M},\\alpha\\nvDash\\phi$ and $\\mathcal{M},\\alpha\\nvDash\\psi$.\n\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash\\exists x\\phi$\n\t\t\t\tiff\n\t\t\t\tthere exists a $d\\in D^\\mathcal{M}$, such that  $\\mathcal{M},{\\alpha[x\\mapsto d]}\\vDash \\phi$\n\t\t\t\t\n\t\t\t  \\item $\\mathcal{M},\\alpha\\vDash\\forall x\\phi$\n\t\t\t\tiff\n\t\t\t\tfor all $d\\in D^\\mathcal{M}$, we have $\\mathcal{M},{\\alpha[x\\mapsto d]}\\vDash \\phi$\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\\end{enumerate}\n\n\t\t\t\n\t\t\t\\end{lemma}\n\t\t\t\n\t\t\t\\begin{proof}\n\t\t\tBy a straightforward induction on complexity, which is left as an exercise.\n\t\t\t\\end{proof}\n\t\t\t\n\t\tNote that clauses (viii) and (ix) are, more or less, explicitly the clauses we gave as our motivation in \\S9.1.\n\t\t\t\n\t\t\\item \\emph{Examples}: Here are some examples of truth in a model. \n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item First, let's take the standard model (9.2.2.i.a) of $\\mathcal{S}_{PA}$. Let's take an assignment $\\alpha$ with $\\alpha(x)=0, \\alpha(y)=1, \\alpha(z)=2$. We get\n\t\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash S(0)=y$\n\t\t\t\t\n\t\t\t\tTo see this, simply note that $\\llbracket S(0)\\rrbracket^\\mathcal{M}_\\alpha=S^\\mathcal{M}(\\llbracket 0\\rrbracket^\\mathcal{M}_\\alpha)=S^\\mathcal{M}(0)=1$ and $\\llbracket y\\rrbracket^\\mathcal{M}_\\alpha=\\alpha(y)=1$.\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\nvDash S(0)=x$\n\t\t\t\t\n\t\t\t\tThis follows from the previous observation that $\\llbracket S(0)\\rrbracket^\\mathcal{M}_\\alpha=1$ and $\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha=\\alpha(x)=0$\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash S(0)\\neq x$\n\t\t\t\t\n\t\t\t\tThis follows from the previous by propositional reasoning.\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash (S(0)\\neq x\\lor 4\\neq 4)$\n\t\t\t\t\n\t\t\t\t\tThis follows from the previous by propositional reasoning.\n\t\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash S(0)=x\\to 1\\neq 1$\n\t\t\t\t\n\t\t\t\tFollows from (b) and propositional reasoning.\n\t\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash\\forall x(S(x)\\neq 0)$\n\n\t\t\t\tWe need to show that for each  $n\\in D^\\mathcal{M}=\\mathbb{N}$, we have $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)\\neq 0$. So let $n\\in \\mathbb{N}$ be an arbitrary number. We know that  $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)\\neq 0$ iff $\\mathcal{M},\\alpha[x\\mapsto n]\\nvDash S(x)=0$. So, we can use indirect proof to establish that $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)\\neq 0$ by leading $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)=0$ to a contradiction. So, assume $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)=0$. It follows that $\\llbracket S(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n]}=\\llbracket0\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n]}$. We have $\\llbracket S(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n]}=S^\\mathcal{M}(n)=n+1$. And we have $0^\\mathcal{M}=0$. So we get that $n+1=0$. But we know that there is no natural number $n\\in\\mathbb{N}$ such that $n+1=0$. So, we can conclude that $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)\\neq 0$, as desired.\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash \\exists x S(x)=S(S(0))$\n\t\t\t\t\n\t\t\t\tTo show this, we need to establish that there exists an $n\\in\\mathbb{N}$ such that  $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash S(x)=S(S(0))$. We can easily check that $\\llbracket S(S(0))\\rrbracket_\\alpha^\\mathcal{M}=2$. So, we let $n=1$. For $n=1$, we have $\\llbracket S(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto 1]}=S^\\mathcal{M}(\\alpha[x\\mapsto 1](x))=S^\\mathcal{M}(1)=2$. By Lemma 9.2.9, we have $\\llbracket S(S(0))\\rrbracket_{\\alpha[x\\mapsto1]}^\\mathcal{M}=2$ since $\\llbracket S(S(0))\\rrbracket_\\alpha^\\mathcal{M}=2$ and $S(S(0))$ is a ground-term. Hence: \\[\\llbracket S(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n]}=\\llbracket S(S(0))\\rrbracket_{\\alpha[x\\mapsto1]}^\\mathcal{M},\\] as desired.\t\t\t\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash \\forall x\\exists y x\\cdot y=x$.\n\t\t\t\t\n\t\t\t\tThis formula involves a nested quantifier. Let's first unfold what we have to show: $\\mathcal{M},\\alpha\\vDash \\forall x\\exists y x\\cdot y=x$ iff for all $n\\in\\mathbb{N}$, we have $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash \\exists y x\\cdot y=x$. And we have $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash \\exists y x\\cdot y=x$ iff there exists an $m\\in\\mathbb{N}$ such that $\\mathcal{M},\\alpha[x\\mapsto n, y\\mapsto m]\\vDash x\\cdot y=x$. So, what we need to show in order to prove that $\\mathcal{M},\\alpha\\vDash \\forall x\\exists y x\\cdot y=x$ is that for each $n\\in\\mathbb{N}$, there exists an $m\\in\\mathbb{N}$ such that $\\mathcal{M},\\alpha[x\\mapsto n, y\\mapsto m]\\vDash x\\cdot y=x$. So let $n\\in\\mathbb{N}$ be arbitrary. Now if we set $m=1$, then we get \n\t\t\t\t\\begin{align*}\n\t\t\t\t\\llbracket x\\cdot y\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n, y\\mapsto 1]}&=\\alpha[x\\mapsto n, y\\mapsto 1](x)\\cdot \\alpha[x\\mapsto n, y\\mapsto 1](y)\\\\\n\t\t\t\t&=n\\cdot 1\\\\\n\t\t\t\t&=n\n\t\t\t\t\\end{align*}\n\t\t\tBut surely, also $\\llbracket x\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n, y\\mapsto 1]}=n$. So, we have \\[\\llbracket x\\cdot y\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n, y\\mapsto 1]}=\\llbracket x\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto n, y\\mapsto 1]},\\] meaning $\\mathcal{M},\\alpha[x\\mapsto n, y\\mapsto 1]\\vDash x\\cdot y=x$. So, we have $\\mathcal{M},\\alpha[x\\mapsto n]\\vDash \\exists y x\\cdot y=x$ and, since $n$ was arbitrary $\\mathcal{M},\\alpha\\vDash \\forall x \\exists y x\\cdot y=x$, as desired.\n\t\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\item Let's consider some examples in the abstract structure (9.2.2.iv) under the assignment $\\alpha(x)=1, \\alpha(y)=3, $ and $\\alpha(z)=4$.\n\t\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\\item $\\mathcal{M},\\alpha\\vDash P(a)$\n\t\t\t\t\n\t\t\t\tSimply note that $\\llbracket a\\rrbracket^\\mathcal{M}_\\alpha=a^\\mathcal{M}=1\\in \\{1,3\\}=P^\\mathcal{M}$\n\t\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash P(x)$\n\t\t\t\t\n\t\t\t\tSimply note that $\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha=\\alpha(x)=1\\in \\{1,3\\}=P^\\mathcal{M}$\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\nvDash P(z)$\n\t\t\t\t\n\t\t\t\tSimply note that $\\llbracket z\\rrbracket^\\mathcal{M}_\\alpha=\\alpha(z)=4\\notin \\{1,3\\}=P^\\mathcal{M}$\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash R(x,x)$\n\t\t\t\t\n\t\t\t\tFirst,  remember that $\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha=1.$ It follows that $(\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha,\\llbracket x\\rrbracket^\\mathcal{M}_\\alpha)=(1,1)\\in\\{(1,1), (1,2),(2,2) (2,3), (3,3)\\}\\in R^\\mathcal{M}$.\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash \\exists y (y\\neq x\\land R(y,y))$\n\t\t\t\t\n\t\t\t\tWe need to show that there exists a $d\\in D^\\mathcal{M}$ such that $\\mathcal{M},\\alpha[y\\mapsto d]\\vDash y\\neq x\\land R(y,y)$. Let $d=3$. We get $\\llbracket y\\rrbracket^\\mathcal{M}_{\\alpha[y\\mapsto 3]}=\\alpha[y\\mapsto 3](y)=3$  and $3\\neq 1=\\alpha[y\\mapsto 3](x)$. Hence $\\mathcal{M},\\alpha[y\\mapsto 3]\\vDash y\\neq x$. Further, since $\\llbracket y\\rrbracket^\\mathcal{M}_{\\alpha[y\\mapsto 3]}=3,$ we have that $(\\llbracket y\\rrbracket^\\mathcal{M}_{\\alpha[y\\mapsto 3]},\\llbracket y\\rrbracket^\\mathcal{M}_{\\alpha[y\\mapsto 3]})=(3,3)\\in R^\\mathcal{M}$. So, we have $\\mathcal{M},\\alpha[y\\mapsto 3]\\vDash R(y,y)$. At this point, we have $\\mathcal{M},\\alpha[y\\mapsto 3]\\vDash y\\neq x\\land R(y,y)$. We get $\\mathcal{M},\\alpha\\vDash \\exists y (y\\neq x\\land R(y,y))$, as desired.\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash \\forall x P(g(a,x))$\n\t\t\t\t\n\t\t\t\tWe need to show that for each $d\\in D^\\mathcal{M}$ that $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash P(g(a,x))$. We will do this by showing that for each $d\\in D^\\mathcal{M},$ we have $\\llbracket g(a,x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. Since $1\\in P^\\mathcal{M}$, the claim follows.  Why should it be that $\\llbracket g(a,x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$? Well, we know that $\\llbracket g(a,x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=g^\\mathcal{M}(\\llbracket a\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}, \\llbracket x\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]})$, since $g^\\mathcal{M}(x,y)=min(x,y)$, $\\llbracket a\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=a^\\mathcal{M}$, and $\\llbracket x\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=\\alpha[x\\mapsto d](d)=d$, we get $\\llbracket g(a,x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=min(1,d)$. Now, $D^\\mathcal{M}=\\{1,2,3,4\\}$, so for each $d\\in D^\\mathcal{M}$, we have $\\llbracket g(a,x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=min(1,d)=1$. But that's all we needed to show.\n\t\t\t\t\n\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash \\forall x P(a)$. \n\t\t\t\t\n\t\t\t\tWe need to show that for each $d\\in D^\\mathcal{M}$ that $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash P(a)$. But the value of $P(a)$ is the same under each assignment: the proof of $\\mathcal{M},\\alpha\\vDash P(a)$ doesn't depend on $\\alpha$. So, clearly for each $d\\in D^\\mathcal{M}$ that $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash P(a)$.\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item Note that in order to show that quantified claims are true in a model under an assignment we actually need to do some work. A stark contrast between first-order logic and propositional logic is that in the latter, we can simply calculate the truth-value of a formula under a assignment without too much effort. In first-order logic, in contrast, the definition of truth in a model under an assignment \\emph{is} recursive and can thus be calculated, but it is not always easy to do so; we often need to prove non-trivial claims to establish that a quantified claim is true in a model.\n\t\t\\item Nested quantifiers, as example 9.3.4.i.h, are somewhat tricky to wrap your head around. Here are some reading guidelines that might help understand what's going on:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t  \\item $\\mathcal{M},\\alpha\\vDash \\exists x\\forall y \\phi$\n\t\t\tiff there is a change of value of $x$ such that for all subsequent changes of $y$ which keep $x$ fixed, $\\phi$ is true.\n\t\t\n\t\t  \\item $\\mathcal{M},\\alpha\\nvDash \\exists x\\forall y\\phi$\n\t\t\tiff for all changes of $x$ there is a subsequent change of $y$ (which keeps $x$ the same) such that $\\phi$ becomes false.\n\t\t\n\t\t  \\item $\\mathcal{M},\\alpha\\vDash \\forall x\\forall y\\phi$\n\t\t\tiff for all changes of $x$ and subsequent changes of $y$, $\\phi$ is true.\n\t\t\n\t\t  \\item $\\mathcal{M},\\alpha\\nvDash \\forall x\\forall y\\phi$\n\t\t\tiff for some change of $x$'s value there is a change of $y$'s value which keeps $x$'s value fixed and makes $\\phi$ false.\n\t\t\n\t\t  \\item $\\mathcal{M},\\alpha\\vDash \\exists x\\exists y\\phi$\n\t\t\tiff for some change of $x$'s value there is a subsequent change of $y$'s value, which keeps the value of $x$ fixed and makes $\\phi$ true\n\t\t\n\t\t  \\item $\\mathcal{M},\\alpha\\nvDash \\exists x\\exists y\\phi$\n\t\t\tiff for all changes of the values of $x$ and subsequent changes of $y$, $\\phi$ is false.\n\n\n\t\t  \\item $\\mathcal{M},\\alpha\\vDash \\forall x \\exists y\\phi$ iff for all changes of $x$'s value there is a change of $y$'s value that leaves $x$ fixed and makes $\\phi$ true\n\n\t\t  \\item $\\mathcal{M},\\alpha\\nvDash \\forall x \\exists y\\phi$ iff there exists a value for $x$ such that for all subsequent changes in the value of $y$ (keeping $x$ fixed), $\\phi$ becomes false\n\n\t\t\\end{enumerate}\t\n\t\t\n\t\tThese clauses can be used to help you think about what you need to show in order to establish whether a complex quantified claim is true.\n\t\t\n\t\t\\item We conclude our discussion of truth in a model by proving that sentences, that is formulas with no free variables, have determinate truth-values, i.e. their truth-values don't depend on assignments:\n\t\t\\begin{proposition}[Sentence Lemma]\n\t\tLet $\\mathcal{M}$ be a model and $\\phi\\in\\mathcal{L}$ a sentence (i.e. a formula with no free variables). Then for all assignments $\\alpha,\\beta$, we have $\\llbracket\\phi\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket\\phi\\rrbracket_\\beta^\\mathcal{M}$.\n\t\t\\end{proposition}\n\t\tWe're actually going to prove something slightly stronger:\n\t\t\\begin{lemma}[Formula Locality Lemma]\n\t\tLet $\\mathcal{M}$ be a model and $\\phi\\in\\mathcal{L}$ whose free variables form the set $V$. Then for all assignments $\\alpha$ and $\\beta$, if $\\alpha(x)=\\beta(x)$ for all $x\\in V$, then $\\llbracket\\phi\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket\\phi\\rrbracket_\\beta^\\mathcal{M}$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\tWe prove the claim using induction.\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item \\emph{Base cases}: \\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item Note that if the free variables in  $R(t_1,\\mathellipsis, t_n)$ form the set $V$, then for each term $t_i$, the free variables in $t_i$ are all in $V$. So, if $\\alpha(x)=\\beta(x)$ for all $x\\in V$, we can infer using the Term Locality Lemma that $\\llbracket t_i\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket t_i\\rrbracket_\\beta^\\mathcal{M}$.  From this the claim quickly follows. For note that we get that   $(\\llbracket t_1\\rrbracket_\\alpha^\\mathcal{M}, \\mathellipsis, \\llbracket t_n\\rrbracket_\\alpha^\\mathcal{M})\\in R^\\mathcal{M}$ iff  $(\\llbracket t_1\\rrbracket_\\beta^\\mathcal{M}, \\mathellipsis, \\llbracket t_n\\rrbracket_\\beta^\\mathcal{M})\\in R^\\mathcal{M}$. Since\n\t\t\t\t\n\t\t\t\t\\[\\llbracket R(t_1,\\mathellipsis, t_n)\\rrbracket_\\alpha^\\mathcal{M}=\\begin{cases} 1 & \\text{if }(\\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha,\\mathellipsis, \\llbracket t_1\\rrbracket^\\mathcal{M}_\\alpha)\\in R^\\mathcal{M}\\\\0 &\\text{otherwise}\\end{cases}\\]\n\t\t\t\tand \n\t\t\t\t\\[\\llbracket R(t_1,\\mathellipsis, t_n)\\rrbracket_\\beta^\\mathcal{M}=\\begin{cases} 1 & \\text{if }(\\llbracket t_1\\rrbracket^\\mathcal{M}_\\beta,\\mathellipsis, \\llbracket t_1\\rrbracket^\\mathcal{M}_\\beta)\\in R^\\mathcal{M}\\\\0 &\\text{otherwise}\\end{cases}\\]\n\t\t\t\tthe claim follows immediately.\n\t\t\t\t\n\t\t\t\t\t\t\t\t\\item The case for $t_1=t_2$ is completely analogous to (a) except that there are just two terms involved.\n\t\t\t\t\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\item  \\emph{Induction Steps}: \\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\\item Suppose the induction hypothesis that if the free variables in $\\phi$ are in $V$ and $\\alpha(x)=\\beta(x)$ for all $x\\in V$, then $\\llbracket\\phi\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket\\phi\\rrbracket_\\beta^\\mathcal{M}$. Now consider $\\neg\\phi$. Clearly, the free variables in $\\neg\\phi$ are the same as in $\\phi$. So, we can conclude that  $\\llbracket\\phi\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket\\phi\\rrbracket_\\beta^\\mathcal{M}$ by the induction hypothesis. Since further $\\llbracket\\neg\\phi\\rrbracket_\\alpha^\\mathcal{M}=1-\\llbracket\\phi\\rrbracket_\\alpha^\\mathcal{M}$ and $\\llbracket\\neg\\phi\\rrbracket_\\beta^\\mathcal{M}=1-\\llbracket\\phi\\rrbracket_\\beta^\\mathcal{M}$, the claim follows as desired.\n\t\t\t\n\t\t\t\\item The case for $(\\phi\\circ \\psi)$ works similar to the case for $\\neg\\phi$ and is left as an exercise.\n\t\t\t\n\t\t\t\\item Suppose the induction hypothesis that if the free variables in $\\phi$ are in $V$ and $\\alpha(x)=\\beta(x)$ for all $x\\in V$, then $\\llbracket\\phi\\rrbracket_\\alpha^\\mathcal{M}=\\llbracket\\phi\\rrbracket_\\beta^\\mathcal{M}$. We only consider $\\forall y\\phi$ and leave $\\exists y\\phi$ as an exercise. Suppose that the free variables in $\\forall y\\phi$ are the $V$'s and $\\alpha(x)=\\beta(x)$ for all $x\\in V$. Then, the free variables in $\\phi$ are $V\\cup\\{y\\}$ (or $V$ if $y$ does not occur in $\\phi$, but then the proof is even easier). Now we distinguish two cases: (i) $\\llbracket\\forall y\\phi\\rrbracket_\\alpha^\\mathcal{M}=1$ or (ii)  $\\llbracket\\forall y\\phi\\rrbracket_\\alpha^\\mathcal{M}=0$. \n\t\t\t\n\t\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\t\\item From $\\llbracket\\forall y\\phi\\rrbracket_\\alpha^\\mathcal{M}=1$, it follows that for all $d\\in D^\\mathcal{M}$ we have $\\mathcal{M},\\alpha[y\\mapsto d]\\vDash\\phi$. But for each $d$, consider $\\beta[y\\mapsto d]$. Since $\\alpha(x)=\\beta(x)$ for all $x\\in V$, we have that $\\alpha[y\\mapsto d](x)=\\beta[y\\mapsto d](x)$ for all $x\\in V$. Moreover, $\\alpha[y\\mapsto d](y)=d=\\beta[y\\mapsto d](y)$. Hence $\\alpha[y\\mapsto d](x)=\\beta[y\\mapsto d](x)$ for all $x\\in V\\cup\\{y\\}$. But by the induction hypothesis, this means that $\\llbracket\\phi\\rrbracket_{\\alpha[y\\mapsto d]}^\\mathcal{M}=\\llbracket\\phi\\rrbracket_{\\beta[y\\mapsto d]}^\\mathcal{M}=1$. So, $\\llbracket\\forall y\\phi\\rrbracket_\\beta^\\mathcal{M}=1$, as desired.\n\t\t\t\t\n\t\t\t  \\item  From $\\llbracket\\forall y\\phi\\rrbracket_\\alpha^\\mathcal{M}=0$,\n\t\t\t\tit follows that for some\n\t\t\t\t$d\\in D^\\mathcal{M}$\n\t\t\t\twe have\n\t\t\t\t$\\mathcal{M},\\alpha[y\\mapsto d]\\nvDash\\phi$.\n\t\t\t\tFor this $d$,\n\t\t\t\tconsider\n\t\t\t\t$\\beta[y\\mapsto d]$.\n\t\t\t\tSince\n\t\t\t\t$\\alpha(x)=\\beta(x)$\n\t\t\t\tfor all $x\\in V$,\n\t\t\t\twe have that\n\t\t\t\t$\\alpha[y\\mapsto d](x)=\\beta[y\\mapsto d](x)$\n\t\t\t\tfor all $x\\in V$.\n\t\t\t\tMoreover,\n\t\t\t\t$\\alpha[y\\mapsto d](y)=d=\\beta[y\\mapsto d](y)$.\n\t\t\t\tHence\n\t\t\t\t$\\alpha[y\\mapsto d](x)=\\beta[y\\mapsto d](x)$\n\t\t\t\tfor all\n\t\t\t\t$x\\in V\\cup\\{y\\}$.\n\t\t\t\tBut by the induction hypothesis, this means that\n\t\t\t\t$\\llbracket\\phi\\rrbracket_{\\alpha[y\\mapsto d]}^\\mathcal{M}=\\llbracket\\phi\\rrbracket_{\\beta[y\\mapsto d]}^\\mathcal{M}=0$.\n\t\t\t\tSo,\n\t\t\t\t$\\llbracket\\forall y\\phi\\rrbracket_\\beta^\\mathcal{M}=0$,\n\t\t\t\tas desired.\n\t\t\t\t\n\t\t\t\\end{itemize}\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\tThis concludes our induction.\n\t\t\\end{proof}\n\t\tThe Sentence Lemma is a simple corollary of the Formula Locality Lemma.\n\t\t\n\t\t\\item We can use the Sentence Lemma to justify the following definition of truth in a model:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item For $\\phi$ a sentence, we define $\\mathcal{M}\\vDash\\phi$ as $\\mathcal{M},\\alpha\\vDash\\phi$.\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\tBy the Sentence Lemma, if $\\phi$ is true under one assignment, then $\\phi$ is true under all of them; and similarly, if $\\phi$ is false under some assignment, then $\\phi$ is false under all of them. So, whenever we're reasoning about $\\mathcal{M}\\vDash\\phi$, we can supply an arbitrary assignment $\\alpha$ as needed for the above definitions to work.\n\t\t\t\t\n\t\\end{enumerate}\n\n\n\\section{Consequence and Validity}\n\n\n\t\\begin{enumerate}[\\thesection.1]\n\n\n\t\t\\item In this section, we discuss the notion of valid inference in first-order logic. This makes the section one of the core sections of the lecture. At the same time, we can be relatively brief, since all the work we've been doing so-far was to make this part here easy. So, we begin by giving the official definition of validity in first-order logic. As we indicated before, we define the notion for sentences:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item For $\\Gamma$ a set of sentences and $\\phi$ a sentence, we say that $\\Gamma\\vDash\\phi$ iff for all models $\\mathcal{M}$, if $\\mathcal{M}\\vDash\\psi$ for all $\\psi\\in\\Gamma$, then $\\mathcal{M}\\vDash\\phi$.\n\t\t\t\n\t\t\t\\item This gives us:  $\\Gamma\\nvDash\\phi$ iff there exists a (counter)model $\\mathcal{M}$, such that $\\mathcal{M}\\vDash\\psi$ for all $\\psi\\in\\Gamma$, but $\\mathcal{M}\\nvDash\\phi$\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\tThe notion of logical equivalence is defined just like propositional logic $\\phi\\equi \\psi$ means both $\\phi\\vDash\\psi$ and $\\psi\\vDash\\phi$. Similarly, logical truth is defined as being a consequence of the empty set, i.e. $\\vDash\\phi$ means $\\emptyset\\vDash\\phi$.\n\t\t\n\t\t\\item \\emph{Examples}\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\\item $\\forall xP(x)\\vDash P(a)$\n\t\t\n\t\t\\item[] To see this, suppose that $\\mathcal{M},\\alpha\\vDash\\forall xP(x)$ for some arbitrary model $\\mathcal{M}$ and assignment $\\alpha$. It follows that for all $d\\in D^\\mathcal{M}$, we have $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash P(x)$. But $a^\\mathcal{M}\\in D^\\mathcal{M}$. So, if we set $d=a^\\mathcal{M}$, we get $\\mathcal{M},\\alpha[x\\mapsto a^\\mathcal{M}]\\vDash P(x)$. But that just means that $\\alpha[x\\mapsto a^\\mathcal{M}](x)=a^\\mathcal{M}\\in P^\\mathcal{M}$, from which it immediately follows that $\\mathcal{M},\\alpha\\vDash P(a)$.\n\t\t\n\t\t\\item $P(a)\\vDash\\exists xP(x)$\n\t\t\n\t\t\\item[] To see this, suppose that $\\mathcal{M},\\alpha\\vDash P(a)$ for some arbitrary model $\\mathcal{M}$ and assignment $\\alpha$. This means that $a^\\mathcal{M}\\in P^\\mathcal{M}$. But then, we can simply set $d=a^\\mathcal{M}$, and get that $\\mathcal{M},\\alpha[x\\mapsto a^\\mathcal{M}]\\vDash P(x)$ and so $\\mathcal{M},\\alpha\\vDash\\exists xP(x)$, as desired.\n\t\t\n\\item $\\exists x(P(x)\\land Q(x))\\vDash \\exists xP(x)\\land \\exists xQ(x)$\n\n\t\t\\item[] Suppose that $\\llbracket\\exists x(P(x)\\land Q(x))\\rrbracket^\\mathcal{M}_\\alpha=1$. That means that we can change the value of only $x$ to $d$ such that $\\llbracket P(x)\\land Q(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. Hence $\\llbracket P(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$ and $\\llbracket Q(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. So we can change the value of only $x$ to $d$ such that $\\llbracket P(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, meaning $\\llbracket\\exists xP(x)\\rrbracket^\\mathcal{M}_\\alpha=1$; and we can change the value of only $x$ to $d$ such that $\\llbracket Q(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, meaning $\\llbracket\\exists xQ(x)\\rrbracket^\\mathcal{M}_\\alpha=1$. Hence $\\llbracket\\exists xP(x)\\land \\exists xQ(x)\\rrbracket^\\mathcal{M}_\\alpha=1$, as desired.\n\n\t\t\\item $\\forall x(P(x)\\to \\exists yR(x,y))\\vDash \\neg \\exists x(P(x)\\land \\forall y\\neg R(x,y))$\n\t\t\n\t\t\\item[] Suppose that $\\llbracket \\forall x(P(x)\\to \\exists yR(x,y))\\rrbracket^\\mathcal{M}_\\alpha=1$. This means that for every change of $x$ to $d$, $\\llbracket P(x)\\to \\exists yR(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. Now suppose for proof by contradiction that $\\llbracket\\neg \\exists x(P(x)\\land \\forall y\\neg R(x,y))\\rrbracket^\\mathcal{M}_\\alpha=0$ meaning  \\[\\llbracket\\exists x(P(x)\\land \\forall y\\neg R(x,y))\\rrbracket^\\mathcal{M}_\\alpha=1.\\] Then there is a change of $x$ to $d$ such that $\\llbracket P(x)\\land \\forall y\\neg R(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. Hence $\\llbracket P(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$ and $\\llbracket\\forall y\\neg R(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. But if $\\llbracket P(x)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, then we must have $\\llbracket\\exists yR(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, since $\\llbracket P(x)\\to \\exists yR(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$ (by the above reasoning). So, to take stock, we have $\\llbracket\\forall y\\neg R(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$ and $\\llbracket \\exists yR(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, which quickly leads to contradiction. For example, it's easily observed in class that $\\exists yR(x,y)$ is equivalent to $\\neg\\forall y\\neg R(x,y)$, so we get $\\llbracket\\neg\\forall y\\neg R(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, which gives a contradiction to $\\llbracket\\forall y\\neg R(x,y)\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. Hence using proof by contradiction, we get $\\llbracket \\neg \\exists x(P(x)\\land \\forall y\\neg R(x,y))\\rrbracket^\\mathcal{M}_\\alpha,$ as desired.\n\t\t\n\t\t\\item $\\vDash \\forall x(P(x)\\lor \\neg P(x))$\n\t\t\n\t\t\\item[] To see this, suppose that for some model $\\mathcal{M}$ and assignment $\\alpha$, we have $\\mathcal{M},\\alpha\\nvDash  \\forall x(P(x)\\lor \\neg P(x))$. This means that there exists a $d\\in D^\\mathcal{M}$ such that $\\mathcal{M},\\alpha[x\\mapsto d]\\nvDash  P(x)\\lor \\neg P(x)$. But this means that both $\\mathcal{M},\\alpha[x\\mapsto d]\\nvDash  P(x)$ and $\\mathcal{M},\\alpha[x\\mapsto d]\\nvDash  \\neg P(x)$ and so both $\\mathcal{M},\\alpha[x\\mapsto d]\\nvDash  P(x)$ and $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash  P(x),$ which is a contradiction. Hence $\\mathcal{M},\\alpha\\nvDash  \\forall x(P(x)\\lor \\neg P(x))$ for all models $\\mathcal{M}$ and assignments $\\alpha$.\n\t\t\n\t\t\\item $\\vDash\\exists x~x=\\mathsf{Batman}$ (it's logically true that Batman exists)\n\t\t\n\t\t\\item[] Let $\\mathcal{M}$ be an arbitrary model and $\\alpha$ an arbitrary assignment therein. We have $\\mathsf{Batman}^\\mathcal{M}\\in D^\\mathcal{M}$; that is, the denotation of $\\mathsf{Batman}$ is a member of the domain. So, set set $d=\\mathsf{Batman}^\\mathcal{M}$ and consider  $\\llbracket x\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto\\mathsf{Batman}^\\mathcal{M}]}=\\mathsf{Batman}^\\mathcal{M}=\\llbracket\\mathsf{Batman}\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto\\mathsf{Batman}^\\mathcal{M}]}$. So $\\llbracket x=\\mathsf{Batman}\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto\\mathsf{Batman}^\\mathcal{M}]}=1$. So $\\llbracket\\exists x~x=\\mathsf{Batman}\\rrbracket^\\mathcal{M}_\\alpha=1$, which is what we needed to show.\n\t\t\n\t\t\\item $\\forall x\\exists y R(x,y)\\nvDash \\exists y \\forall xR(x,y)$ \n\t\t\n\t\t\\item[] To show this, we need to provide a countermodel:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item $D^\\mathcal{M}=\\mathbb{N}$\n\t\t\t\n\t\t\t\\item $R^\\mathcal{M}=\\{(n,m):n\\leq m\\}$\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\tIt's relatively easily checked that $\\forall x\\exists y R(x,y)$ is true under every assignment in this model, since for every number there's a bigger number: for every $n\\in\\mathbb{N}$ we can pick $n+1\\in\\mathbb{N}$ and get $\\mathcal{M},\\alpha[x\\mapsto n, y\\mapsto n+1]\\vDash R(x,y)$. At the same time, it's not the case that some number is bigger than all others: there is $n\\in\\mathbb{N}$ such that for all $m\\in\\mathcal{M}$, $\\mathcal{M},\\alpha[x\\mapsto n, y\\mapsto n+1]\\vDash R(x,y)$.\n\t\t\n\t\t\\item $\\exists xP(x)\\land \\exists x Q(x)\\nvDash \\exists x(P(x)\\land Q(x))$ \n\t\t\n\t\t\\item[] Here's a countermodel:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item $D^\\mathcal{M}=\\{a,b\\}$\n\t\t\t\n\t\t\t\\item $P^\\mathcal{M}=\\{a\\}$\n\t\t\t\\item $Q^\\mathcal{M}=\\{b\\}$\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\tIn this model, there we can find $a^\\mathcal{M}$ such that $\\mathcal{M},\\alpha[x\\mapsto a^\\mathcal{M}]\\vDash P(x)$ and so $\\mathcal{M},\\alpha\\vDash\\exists x P(x)$, and we can find $b^\\mathcal{M}$ such that $\\mathcal{M},\\alpha[x\\mapsto b^\\mathcal{M}]\\vDash Q(x)$ and so $\\mathcal{M},\\alpha\\vDash\\exists x Q(x)$. But neither $a^\\mathcal{M}$ nor $b^\\mathcal{M}$ is such that $\\mathcal{M},\\alpha[x\\mapsto a^\\mathcal{M}/b^\\mathcal{M}]\\vDash P(x)\\land Q(x)$---nothing is both $P$ and $Q$. \n\t\t\n\t\t\\item $\\forall x(P(x)\\lor Q(x))\\nvDash \\forall xP(x)\\lor \\forall xQ(x)$\n\n\t\\item[] The same countermodel works:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item $D^\\mathcal{M}=\\{a,b\\}$\n\t\t\t\n\t\t\t\\item $P^\\mathcal{M}=\\{a\\}$\n\t\t\t\\item $Q^\\mathcal{M}=\\{b\\}$\n\t\t\n\t\t\\end{itemize}\n\n\n\\end{enumerate}\n\t\t\n\t\t\n\t\t\\item We note that all the laws of classical propositional logic are valid in first-order logic (cf. 5.2.6). Additionally, we can prove the following logical laws concerning the quantifiers:\n\t\t\t\t\n\t\t\\begin{proposition}[Quantifier Laws] For all formulas $\\phi$ and $\\psi$, we have:\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\\item $\\forall x\\phi\\vDash(\\phi)[x:=t]$  where $t$ is a ground term\n%\t\t\n\t\t\\item $(\\phi)[x:=t]\\vDash\\exists x\\phi$ where $t$ is a ground term\n\n\t\t\\item $\\forall x\\phi\\vDash\\exists x\\phi$\n\t\t\n\t\t\\item $\\forall x\\phi\\equi \\neg \\exists x\\neg\\phi$\n\t\n\t\t\t\\item $\\exists x\\phi\\equi \\neg \\forall x\\neg \\phi$\n\t\t\n\t\t\t\\item $\\forall x\\forall y\\phi\\equi \\forall y\\forall x\\phi$\n\n\t\\item $\\exists x\\exists y\\phi\\equi \\exists y\\exists x\\phi$\n\n\t\\item $\\exists x\\forall y\\phi\\vDash \\forall y \\exists x\\phi$\n\t\t\n\t\\item $(\\forall x\\phi\\land \\forall x\\psi)\\equi \\forall x(\\phi\\land \\psi)$\n\n\t\\item $(\\exists x\\phi\\lor \\exists x\\psi)\\equi \\exists x(\\phi\\lor \\psi)$\n\n\t\\item $\\forall x\\phi\\lor \\forall x\\psi\\vDash \\forall x(\\phi\\lor \\psi)$  \n\n\t\\item  $\\exists x(\\phi\\land \\psi)\\vDash \\exists x\\phi\\land \\exists x \\psi$  \n\t\\item $(\\phi\\to \\forall x\\psi)\\equi \\forall x(\\phi\\to \\psi)$ if $x$ is not free in $\\phi$\n\n\t\\item $(\\phi\\to \\exists x\\psi)\\equi \\exists x(\\phi\\to \\psi)$ if $x$ is not free in $\\phi$\n\n\t\\item $(\\forall x\\phi\\to \\psi)\\equi \\exists x(\\phi\\to \\psi)$ if $x$ is not free in $\\psi$\n\n\t\\item $(\\exists x\\phi\\to \\psi)\\equi \\forall x(\\phi\\to \\psi)$ if $x$ is not free in $\\psi$\n\n\t\t\\end{enumerate}\n\n\t\\end{proposition}\n\t\n\t\\begin{proof}\n\tWe only prove (iii) and leave the rest as \\emph{very} useful exercises.\n\t\n\t\\begin{enumerate}[(i)]\n\t\\setcounter{enumi}{2}\n\t\t\\item  This law holds because we stipulated that $D^\\mathcal{M}\\neq \\emptyset$ in Definition 9.2.1. Since $D^\\mathcal{M}\\neq \\emptyset$, if $\\llbracket\\forall x\\phi\\rrbracket_\\alpha^\\mathcal{M}=1$, i.e. for all $d\\in D^\\mathcal{M},$ we have $\\llbracket\\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$, we can always pick a $d\\in D^\\mathcal{M}$ such that $\\llbracket\\phi\\rrbracket^\\mathcal{M}_{\\alpha[x\\mapsto d]}=1$. But that just means $\\llbracket\\exists x\\phi\\rrbracket_\\alpha^\\mathcal{M}=1$.\n\t\t\t\n\t\n%\t\t\\item Suppose that $\\mathcal{M}$ is a model such that $\\mathcal{M},\\alpha\\vDash\\forall x\\phi$ (for some arbitrary $\\alpha$). This means that for all $d\\in D^\\mathcal{M}$, $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash\\phi$. Since $\\forall x\\phi$ is a sentence, $\\phi$ has precisely one free variable, $x$. Therefore, the result of $(\\phi)[x:=t]$ is also a sentence. \n\t\n\t\\end{enumerate}\n\t\n\t\\end{proof}\n\t\n\t\n\t\t\\item \\label{fo_sem_free} The law $\\forall x\\phi\\vDash\\exists x\\phi$ might seem strange, but the underlying assumption that leads to it,  $D^\\mathcal{M}\\neq \\emptyset$, is necessary to get some important logical laws to work. For example, we clearly want that $\\forall xP(x)\\vDash P(a)$ (9.4.2.i): if everybody passes, then you pass. But if we'd allow for $D^\\mathcal{M}= \\emptyset$, this law could fail. For simply consider a model with $D^\\mathcal{M}= \\emptyset$. In that model $\\forall xP(x)$ would be \\emph{trivially} true: for every $d\\in D^\\mathcal{M}$, we'd have that $\\mathcal{M},\\alpha[x\\mapsto d]\\vDash P(a)$. But since $D^\\mathcal{M}= \\emptyset$, we can't have $a^\\mathcal{M}\\in D^\\mathcal{M}$ and so also not in $P^\\mathcal{M}$, which means that $\\mathcal{M}\\nvDash P(a)$.\n\t\t\n\t\t\n\t\t\\item Next, we observe that the Deduction Theorem and the I Can't Get No Satisfaction Theorem both hold for first-order logic as well:\n\t\t\\begin{theorem}[Deduction Theorem]\n\t\t\tLet $\\phi,\\psi\\in\\mathcal{L}$ be formulas and $\\Gamma\\subseteq\\mathcal{L}$ a set of formulas. Then the following two are equivalent:\n\t\t\t\\begin{enumerate}[1.]\n\t\t\t\n\t\t\t\t\\item $\\Gamma\\cup\\{\\phi\\}\\vDash\\psi$\n\t\t\t\t\n\t\t\t\t\\item $\\Gamma\\vDash \\phi\\to\\psi$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\tExactly as in 5.2.14.\n\t\t\t\\end{proof}\n\t\t\t\\begin{theorem}[I Can't Get No Satisfaction]\n\t\t\tLet $\\Gamma\\subseteq\\mathcal{L}$ be a set of formulas and $\\phi\\in\\mathcal{L}$ a formula. Then, the following are equivalent:\n\t\t\t\\begin{enumerate}[1.]\n\t\t\t\n\t\t\t\t\\item $\\Gamma\\vDash\\phi$\n\t\t\t\t\n\t\t\t\t\\item $\\Gamma\\cup\\{\\neg\\phi\\}$ is unsatisfiable\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\\end{theorem} \n\t\t\t\\begin{proof}\n\t\t\tExactly as in 6.2.6.\n\t\t\t\\end{proof}\n\t\tHowever, as we'll see in the next chapter, the deduction theorem doesn't give us decidability anymore. We can use it, however, to derive interesting logical truths, such as \\[\\vDash \\forall x\\phi\\to (\\phi)[x:=t]\\] for $t$ a ground term, which we can infer directly from 9.4.3.i. The I Can't Get No Satisfaction Theorem, instead, will play the same role in first-order logic as in propositional logic: it's the foundation of the tableau method, which we'll discuss in the next chapter. \n\t\t\n\t\t\\item We conclude this chapter with a long example in which we're going to \\emph{prove} the correct answer for the Albert, Betty, Charles puzzle from the first lecture. Here we go:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\\item Consider the signature $\\mathcal{S}=(\\{a,b,c\\}, \\emptyset, \\{M^1, L^2\\})$.\n\n\t\t\\item Our intended reading is that $M$ stands for ``\\dots is married'', $L$ stands for ``\\dots looks at \\underline{\\phantom{\\dots}}'', $a$ means ``Albert,'' $b$ stands for ``Betty,'' and $c$ stands for ``Charles.''\n\t\t\n\t\t\\item \\emph{Claim}: \\[\\neg M(a), M(c), L(c,b), L(b,a)\\vDash \\exists x\\exists y(M(x)\\land \\neg M(y)\\land L(x,y)).\\]\n\t\t\n\t\t\\item \\emph{Proof}: \t\n\t\t\n\t\tLet $\\mathcal{M}$ be a model and $\\alpha$ arbitrary, such that $\\llbracket M(c)\\rrbracket_\\alpha^\\mathcal{M}=1$, $\\llbracket\\neg M(a)\\rrbracket_\\alpha^\\mathcal{M}=1$, $\\llbracket L(c,b)\\rrbracket_\\alpha^\\mathcal{M}=1$, and $\\llbracket L(b,a)\\rrbracket_\\alpha^\\mathcal{M}=1$. So $a^\\mathcal{M}\\notin M^\\mathcal{M}$, $c^\\mathcal{M}\\in M^\\mathcal{M}$, and $( c^\\mathcal{M}, b^\\mathcal{M}), ( b^\\mathcal{M}, a^\\mathcal{M})\\in L^\\mathcal{M}$. We have that $\\llbracket \\exists x\\exists y(M(x)\\land \\neg M(y)\\land L(x,y))\\rrbracket_\\alpha^\\mathcal{M}=1$ holds iff there are changes for $x$ to $d$ and $y$ to $d'$ such that \\[\\llbracket (M(x)\\land \\neg M(y)\\land L(x,y))\\rrbracket_{\\alpha[x\\mapsto d, y\\mapsto d']}^\\mathcal{M}=1.\\] Now, we know that either (i) $b^\\mathcal{M}\\in M^\\mathcal{M}$ or (ii) $b^\\mathcal{M}\\notin M^\\mathcal{M}$. \t\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item If (i) $b^\\mathcal{M}\\in M^\\mathcal{M}$, then we can set $d=b^\\mathcal{M}$ and $d'=a^\\mathcal{M}$. We'd get $d\\in M^\\mathcal{M}$ and so $\\llbracket M(x))\\rrbracket_{\\alpha[x\\mapsto d, y\\mapsto d']}^\\mathcal{M}=1$; $d'\\notin M^\\mathcal{M}$ and so $\\llbracket\\neg M(y)\\rrbracket_{\\alpha[x\\mapsto d, y\\mapsto d']}^\\mathcal{M}=1$; and $( d,d')\\in L^\\mathcal{M}$ and so $\\llbracket L(x,y))\\rrbracket_{\\alpha[x\\mapsto d, y\\mapsto d']}^\\mathcal{M}=1$; giving us, $\\llbracket \\exists x\\exists y(M(x)\\land \\neg M(y)\\land L(x,y))\\rrbracket_{\\alpha[x\\mapsto d, y\\mapsto d']}^\\mathcal{M}=1$. \n\t\t\t\n\t\t\\item If (ii) $b^\\mathcal{M}\\notin M^\\mathcal{M}$, we can set $d=c^\\mathcal{M}$ and $d'=b^\\mathcal{M}$. In a similar way, we get \n\t\t\t\t\n\t\t\\end{itemize}\n\nEither way, we get $\\llbracket \\exists x\\exists y(M(x)\\land \\neg M(y)\\land L(x,y))\\rrbracket_{\\alpha[x\\mapsto d, y\\mapsto d']}^\\mathcal{M}=1$, which is what we wanted to show.\n\n\t\\end{itemize}\n\t\n\t\\smiley\n\n\t\\end{enumerate}\n\n\n%\\section{Expressivity and Theories}\n\n\\section{Core Ideas}\n\n\\begin{itemize}\n\t\n\t\t\\item A model interprets the signature by assigning denotation to every constant, a function to every function symbol, and an $n$-ary relation to every $n$-ary relation symbol\n\t\t\n\t\t\\item An assignment in a model tells us what the variables denote. It plays the role of the context in natural language. \n\t\n\t\t\\item We can recursively calculate the denotation of arbitrary terms in a model under an assignment.\n\t\t\n\t\t\\item We can recursively calculate the truth-value of a formula relative to a model under an assignment:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item a universally quantified claim is true in a model under a assignment iff the formula after the quantifier remains true for every possible change of the value of the variable in the assignment\n\t\t\t\n\t\t\t\\item an existentially quantified claim is true in a model under a assignment iff the formula after the quantifier becomes true for at least one possible change of the value of the variable in the assignment\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t\\item Validity is defined as in every logic as truth-preservation across models.\n\t\t\n\t\t\\item The Deduction Theorem holds for first-order logic but doesn't lead to decidability.\n\t\n\t\\end{itemize}\n\n\n\\section{Self Study Questions}\n\n\\begin{enumerate}[\\thesection.1]\n\n\\item Which of the following entails that $\\mathcal{M},\\alpha\\vDash\n  \\forall x (P(x)\\to Q(x))$?\n\n  \\begin{enumerate}[(a)]\n\n  \\item There exists no $d\\in D^\\mathcal{M}$ such that $d\\in\n  P^\\mathcal{M}$.\n    \n  \\item There exists no $d\\in D^\\mathcal{M}$ such that $d\\in\n    Q^\\mathcal{M}$.\n  \n  \\item There exists no $d\\in D^\\mathcal{M}$ such that $d\\in\n    P^\\mathcal{M}$ and $d\\in Q^\\mathcal{M}$.\n\n  \\item There exists no $d\\in D^\\mathcal{M}$ such that $d\\in\n    P^\\mathcal{M}$ and $d\\notin Q^\\mathcal{M}$.\n\n   \\item For all $d\\in D^\\mathcal{M}$, it holds that  $d\\in\n  P^\\mathcal{M}$.\n\n   \\item For all $d\\in D^\\mathcal{M}$, it holds that  $d\\in\n  Q^\\mathcal{M}$.\n    \n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\in\n    P^\\mathcal{M}$, then $d\\in Q^\\mathcal{M}$\n\n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\in\n    Q^\\mathcal{M}$, then $d\\in P^\\mathcal{M}$\n    \n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\notin\n    P^\\mathcal{M}$, then $d\\notin Q^\\mathcal{M}$\n\n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\notin\n    Q^\\mathcal{M}$, then $d\\notin P^\\mathcal{M}$\n    \n  \\end{enumerate}\n\n\\item Which of the following entails that $\\mathcal{M},\\alpha\\nvDash\n  \\forall x (P(x)\\to Q(x))$?\n\n  \\begin{enumerate}[(a)]\n\n  \\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\notin\n  P^\\mathcal{M}$.\n    \n  \\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\notin\n    Q^\\mathcal{M}$.\n  \n  \\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\in\n    P^\\mathcal{M}$ and $d\\in Q^\\mathcal{M}$.\n\n  \\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\in\n    P^\\mathcal{M}$ and $d\\notin Q^\\mathcal{M}$.\n\n   \\item For all $d\\in D^\\mathcal{M}$, it holds that  $d\\in\n  P^\\mathcal{M}$.\n\n   \\item For all $d\\in D^\\mathcal{M}$, it holds that  $d\\in\n  Q^\\mathcal{M}$.\n    \n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\in\n    P^\\mathcal{M}$, then $d\\in Q^\\mathcal{M}$\n\n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\in\n    Q^\\mathcal{M}$, then $d\\in P^\\mathcal{M}$\n    \n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\notin\n    P^\\mathcal{M}$, then $d\\notin Q^\\mathcal{M}$\n\n  \\item For all $d\\in D^\\mathcal{M}$, it holds that if $d\\notin\n    Q^\\mathcal{M}$, then $d\\notin P^\\mathcal{M}$\n    \n  \\end{enumerate}\n\n\\item Which of the following entails that $\\mathcal{M},\\alpha\\vDash\n  \\exists x (P(x)\\to Q(x))$?\n\n\\begin{enumerate}[(a)]\n\n\\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\in\n  P^\\mathcal{M}$.\n\n  \\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\in Q^\\mathcal{M}$.\n  \n\\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\in\n  P^\\mathcal{M}$ and $d\\in Q^\\mathcal{M}$.\n\n\\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\notin\n  P^\\mathcal{M}$.\n\n\\item There exists a $d\\in D^\\mathcal{M}$ such that $d\\notin\n  Q^\\mathcal{M}$.\n\n\\item For all $d\\in D^\\mathcal{M}$, if $d\\in P^\\mathcal{M}$, then\n  $d\\in Q^\\mathcal{M}$.\n\n\\item For all $d\\in D^\\mathcal{M}$, if $d\\in Q^\\mathcal{M}$, then\n  $d\\in P^\\mathcal{M}$.\n\n\\item For all $d\\in D^\\mathcal{M}$, $d\\in P^\\mathcal{M}$\n\n\\item For all $d\\in D^\\mathcal{M}$, $d\\notin P^\\mathcal{M}$\n\n\\item For all $d\\in D^\\mathcal{M}$, $d\\in Q^\\mathcal{M}$\n  \n\\item For all $d\\in D^\\mathcal{M}$, $d\\notin Q^\\mathcal{M}$\n  \n\\end{enumerate}\n  \n\\end{enumerate}\n\n\\section{Exercises}\n\t\n\t\\begin{enumerate}[\\thesection.1]\n\t\n\t\t\t\\item Determine the denotation of the following terms in the models $\\mathcal{M}$ from (9.2.2.i.d) under the assignment $\\alpha(x_i)=2i+1$ for $i\\in\\mathbb{N}$:\n\t\t\t\n\t\t\t\\begin{enumerate}\n\t\t\t\n\t\t\t\t\\item $x_2$\n\t\t\t\t\n\t\t\t\t\\item $S(x_2)$\n\t\t\t\t\n\t\t\t\t\\item $(x_1+x_3)$\n\t\t\t\t\n\t\t\t\t\\item $S(S(S(x_0)))$\n\t\t\t\t\n\t\t\t\t\\item $S(0\\cdot x_1)$\n\t\t\t\t\n\t\t\t\t\\item $2+2$\n\t\t\t\t\n\t\t\t\t\\item $[h]$ $(x_1\\cdot x_2)+x_3$\n\n\t\t\t\t\\item $0+0$\n\t\t\t\t\n\t\t\t\t\\item $(0\\cdot 0)+1$ (you can write down a shorthand version)\n\t\t\t\t\n\t\t\t\t\\item $42$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\n\t\t\n\t\t\t\\item $[h]$ Prove, using induction on terms, that in model (9.2.2.i.a) of $\\mathcal{S}_{PA}$, we have $\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha=n$, for all assignments $\\alpha$\n\t\t\t\t\t\t\n\t\t\t\\item Prove, using induction on terms, that in model (9.2.2.i.b) of $\\mathcal{S}_{PA}$, we have $\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha=2\\cdot n$, for all assignments $\\alpha$\n\n\t\t\t\\item Prove, using induction on terms, that in model (9.2.2.i.d) of $\\mathcal{S}_{PA}$, we have $\\llbracket n\\rrbracket^\\mathcal{M}_\\alpha=42$, for all assignments $\\alpha$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\item Prove the Ground Terms Lemma as a corollary of the Term Locality Lemma.\n\t\t\t\n\t\t\t\\item $[\\nosym]$ Explain why and how the law of bivalence holds on the first-order semantics.\n\t\t\t\n\t\t\t\\item Determine whether the following claims hold in the standard model (9.2.2.i.a) of $\\mathcal{S}_{PA}$ under the assignment $\\alpha(x)=1, \\alpha(y)=2,\\alpha(z)=3$:\n\t\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\\item $\\mathcal{M},\\alpha\\vDash x=1$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash S(x)=S(S(x))$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash2+2=4$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash1\\cdot1=0$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash\\forall x S(x)\\neq 0$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash((2\\cdot 2)=5\\land S(44)=7)$\n\t\t\t\t\t\\item $[h]$ $\\mathcal{M},\\alpha\\vDash\\forall x\\forall y(S(x)= S(y)\\to x= y)$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash\\forall x\\forall y(S(x)=(y+1)\\to S(x)=S(y))$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash\\forall x\\exists yS(x)=y$\n\t\t\t\t\t\\item $\\mathcal{M},\\alpha\\vDash \\exists x\\forall yS(x)=y$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\t\t\t\n\t\t\t\n\t\t\n\t\t\\item Take the model (9.2.2.iii.a) for $\\mathcal{S}_\\in$. Consider the assignment $\\alpha$ with $\\alpha(x)=\\{x:x\\text{ is even}\\}$ and $\\alpha(y)=\\{x:x\\text{ is odd}\\}$.\n\t\tProve the following facts:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item  $\\mathcal{M},\\alpha\\vDash \\exists y(y\\in x)$\n\t\t\n\t\t\t\\item $[h]$ $\\mathcal{M},\\alpha\\vDash\\forall x\\neg (x\\in \\emptyset)$\n\t\t\t\n\t\t\t\\item $\\mathcal{M},\\alpha\\vDash\\neg\\exists z(z\\in x\\land z\\in y)$\t\t\t\n\t\t\t\\item $\\mathcal{M},\\alpha\\vDash\\exists z\\forall u(u\\in z\\leftrightarrow u\\in x\\lor u\\in y)$\n\t\t\n\t\t\t\\item $\\mathcal{M},\\alpha\\nvDash \\forall x\\forall y(x=y\\leftrightarrow \\forall z(z\\in x\\leftrightarrow z\\in y))$ (\\emph{Hint}: Note that counterexamples can't be sets!)\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\emph{Hint}: You will need to rely on basic number theoretic and set-theoretic facts.\n\t\t\n\t\t\\item Prove Lemma 9.3.3.\n\t\t\t\t\n\t\t\\item Find a model that shows that $\\{(\\phi)[x:=t]:t\\in\\mathcal{T}\\}\\nvDash\\forall x\\phi$ (cf. 9.1.11).\n\t\t\n\t\t\\item Is it the case that $\\{(\\phi)[x:=t]:t\\in\\mathcal{T}\\}\\vDash\\exists x\\phi$? Prove it or provide a countermodel.\n\t\t\n\t\t\\item Remember the numeric quantifiers from 8.6.7. Prove the following facts:\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\\item $\\mathcal{M}\\vDash \\exists x\\exists y(P(x)\\land P(y)\\land x\\neq y)$ iff $P^\\mathcal{M}$ has at least two elements.\n\t\t\n\t\t\\item $\\mathcal{M}\\vDash \\forall x\\forall y\\forall z(P(x)\\land P(y)\\land P(z)\\to x=y\\lor x=z\\lor y=z)$ iff $P^\\mathcal{M}$ has at most two elements.\n\t\t\n\t\t\\item $\\mathcal{M}\\vDash \\exists x\\exists y(P(x)\\land P(y)\\land \\forall z(P(z)\\to x=z\\lor y=z))$ iff $P^\\mathcal{M}$ has precisely two elements.\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item This one's a real challenge. Suppose that $\\mathcal{M}$ is a model for a language with a function symbol $f^1\\in\\mathcal{F}$ such that:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item $\\mathcal{M}\\vDash \\forall x\\forall y(f(x)=f(y)\\to x=y)$\n\t\t\t\n\t\t\t\\item $\\mathcal{M}\\vDash \\forall xf(x)\\neq x$\n\t\t\t\n\t\t\t\\item $\\mathcal{M}\\vDash\\exists x\\neg\\exists yf(y)=x$\n\t\t\n\t\t\\end{itemize}\n\n\t\tShow that the domain $D^\\mathcal{M}$ cannot be finite, i.e. there is no number $n$ such that there are exactly $n$ elements in $D^\\mathcal{M}$.\n\t\t\n\t\t\\item Prove the remaining quantifier laws 9.4.3.\n\t\t\n\t\t\\item Prove the following:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\\item $\\forall xP(x)\\vDash \\forall yP(y)$\n\n\t\t\\item $\\exists x\\exists yS(x,y)\\vDash \\exists y\\exists xS(x,y)$\n\n\t\t\\item $[h]$ $\\neg \\exists xP(x)\\vDash \\forall x(P(x)\\to Q(x))$\n\n\t\t\\item $\\forall xP(x)\\vDash \\forall x(Q(x)\\to P(x)\\lor R(x))$\n\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item Check the following:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\n\t\t\t\\item $[h]$ $\\forall x(P(x)\\to Q(x)), \\exists x\\neg P(x)\\vDash \\forall x\\neg Q(x)$\n\n\t\t\t\\item $\\forall x(P(x)\\to \\exists yS(x,y))\\vDash \\forall x\\exists y(P(x)\\to S(x,y))$\n\n\t\t\t\\item $\\forall xP(x)\\to \\forall yQ(y)\\vDash \\forall x(P(x)\\to \\forall yQ(y))$\n\n\t\t\t\\item $\\exists x(P(x)\\to \\forall yQ(y))\\vDash \\exists xP(x)\\to \\forall yQ(y)$\n\n\t\t\t\\item $\\vDash \\forall x\\exists yS(x,y)\\to \\exists xS(x,x)$\n\n\t\t\t\\item $\\exists x\\neg\\exists yS(x,y)\\vDash \\exists x\\forall yS(x,y)$\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item For each of the following formulas, provide a model $\\mathcal{M}^+$ and an assignment $\\alpha^+$ such that the formula is true in the model under the assignment, as well as a model $\\mathcal{M}^-$ and an assignment $\\alpha^-$ such that the formula is false.\n\n\\begin{enumerate}[(i)]\n\n\\item $R(x,y)\\to \\forall x\\forall yR(x,y)$\n\n\\item $\\forall x\\forall y(R(x,y)\\land R(y,x)\\to R(x,x))$\n\n\\item $\\forall x\\exists yR(x,y)\\to \\exists y \\forall xR(x,y)$\n\n\\end{enumerate}\n\n\t\n\\end{enumerate}\n\n\\vfill\n\n\\hfill \\rotatebox[origin=c]{180}{\n\\fbox{\n\\begin{minipage}{0.5\\linewidth}\n\n\\subsection*{Self Study Solutions}\n\n%\\emph{Some explanations in the appendix.}\n\n\\begin{enumerate}\n\n\\item[9.6.1] (a), (d), (f), (g), (j)\n\n\\item[9.6.2] (d)\n\n\\item[9.6.3] (b), (c), (d), (f), (i), (j)\n\n\\end{enumerate}\n\n\n\\end{minipage}}}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"../../logic.tex\"\n%%% End: \n\n", "meta": {"hexsha": "3b2214b8cb632b62673c302f3f468e5f95341d73", "size": 89986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lib/notes/tex/mainmatter/fo-semantics.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/mainmatter/fo-semantics.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/mainmatter/fo-semantics.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": 63.2812939522, "max_line_length": 2365, "alphanum_fraction": 0.6723712578, "num_tokens": 30519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6605831400669476}}
{"text": "\\subsection{General Approach}\\label{sec:general-approach}\nAlthough the problem \\eqref{eqn:original_target} -- \\eqref{eqn:original_rate_constraint} is not a standard GP, we can transform it to a Reversed GP by introducing an auxiliary variable ${t_0}$ \\cite{Chiang2005}\n\n\\begin{eqnarray}\n  {\\mathop {\\min }\\limits_{{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,{t_0}} }&{1/{t_0}} \\label{eqn:transformed_target} \\\\\n  {{\\text{ subject to }}}&{\\frac{1}{2}\\left[ {\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2 + \\left\\| {{{\\mathbf{S}}_P}} \\right\\|_F^2} \\right] \\leqslant P} \\label{eqn:transformed_power_constraint} \\\\\n  {}&{{t_0}/{z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right) \\leqslant 1} \\label{eqn:transformed_current_constraint} \\\\\n  {}&{{2^{\\bar R}}/\\left[ {\\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{(1 - \\rho )}}{{\\sigma _n^2}}{C_n}} \\right)} } \\right] \\leqslant 1} \\label{eqn:transformed_rate_constraint}\n\\end{eqnarray}\n\nWe cannot apply GP tools to the new problem yet, as $1/{z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)$ and $1/\\left[ {\\prod\\nolimits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{(1 - \\rho )}}{{\\sigma _n^2}}{C_n}} \\right)} } \\right]$ are not posynomials. To solve this, \\cite{Clerckx2018} suggested a conservative approach to approximate the terms with posynomials in the denominator by new posynomials, based on the Arithmetic Mean-Geometric Mean (AM-GM) inequality.\n\nConsider constraint \\eqref{eqn:transformed_current_constraint} first. The posynomial at the denominator can be decomposed as the sum of monomials\n\n\\begin{equation}\\label{eqn:transformed_current_posynomial_decomposition}\n  {z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right) = \\sum\\limits_{k = 1}^K {{g_k}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)}\n\\end{equation}\n\nSince monomial $\\left\\{ {{g_k}} \\right\\}$ is nonnegative for all $k$, the AM-GM inequality suggests a posynomial upper bound for the previous non-posynomial term\n\n\\begin{equation}\\label{eqn:transformed_current_am_gm}\n  \\frac{1}{{\\sum\\limits_{k = 1}^K {{g_k}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)} }} \\leqslant \\prod\\limits_{k = 1}^K {{{\\left( {\\frac{{{g_k}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)}}{{{\\gamma _k}}}} \\right)}^{ - {\\gamma _k}}}}\n\\end{equation}\n\nThe nonnegative coefficients $\\left\\{ {{\\gamma _k}} \\right\\}$ are chosen to satisfy $\\sum\\nolimits_{k = 1}^K {{\\gamma _k}}  = 1$. Similarly, define $\\bar \\rho  = 1 - \\rho $ and let $\\left\\{ {{g_{nk}}\\left( {{{\\mathbf{S}}_I},\\bar \\rho } \\right)} \\right\\}$ be the monomials of the posynomial $1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}{C_n}$, we have\n\n\\begin{equation}\\label{eqn:transformed_rate_posynomial_decomposition}\n  1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}{C_n} = \\sum\\limits_{k = 1}^{{K_n}} {{g_{nk}}} \\left( {{{\\mathbf{S}}_I},\\bar \\rho } \\right)\n\\end{equation}\n\nApply the AM-GM inequality to \\eqref{eqn:transformed_rate_posynomial_decomposition}, we have\n\n\\begin{equation}\\label{eqn:transformed_rate_am_gm}\n  \\frac{1}{{1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}{C_n}}} \\leqslant \\prod\\limits_{k = 1}^{{K_n}} {{{\\left( {\\frac{{{g_{nk}}\\left( {{{\\mathbf{S}}_I},\\bar \\rho } \\right)}}{{{\\gamma _{nk}}}}} \\right)}^{ - {\\gamma _{nk}}}}}\n\\end{equation}\n\nwith ${\\gamma _{nk}} \\geqslant 0$ and $\\sum\\nolimits_{k = 1}^{{K_n}} {{\\gamma _{nk}}}  = 1$. In this way, we transformed the problem into a standard GP\n\n\\begin{eqnarray}\n  {\\mathop {\\min }\\limits_{{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho ,{t_0}} }&{1/{t_0}} \\label{eqn:general_target} \\\\\n  {{\\text{ subject to }}}&{\\frac{1}{2}\\left[ {\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2 + \\left\\| {{{\\mathbf{S}}_P}} \\right\\|_F^2} \\right] \\leqslant P} \\label{eqn:general_power_constraint} \\\\\n  {}&{{t_0}\\prod\\limits_{k = 1}^K {{{\\left( {\\frac{{{g_k}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)}}{{{\\gamma _k}}}} \\right)}^{ - {\\gamma _k}}}}  \\leqslant 1} \\label{eqn:general_current_constraint} \\\\\n  {}&{2^{\\bar R}}\\prod\\limits_{n = 0}^{N - 1} {\\prod\\limits_{k = 1}^{{K_n}} {{{\\left( {\\frac{{{g_{nk}}\\left( {{{\\mathbf{S}}_I},\\bar \\rho } \\right)}}{{{\\gamma _{nk}}}}} \\right)}^{ - {\\gamma _{nk}}}}} }  \\leqslant 1 \\label{eqn:general_rate_constraint} \\\\\n  {}&{\\rho  + \\bar \\rho  \\leqslant 1} \\label{eqn:general_ratio_constraint}\n\\end{eqnarray}\n\nIt is worth noting that the tightness of the AM-GM inequality depends on the choice of $\\left\\{ {{\\gamma _k},{\\gamma _{nk}}} \\right\\}$. In this paper, we employ the iterative method proposed in \\cite{Clerckx2018} that updates the coefficient sets at iteration $i$ with the previous solution ${{\\mathbf{S}}_P^{(i - 1)},{\\mathbf{S}}_I^{(i - 1)},{\\rho ^{(i - 1)}}}$ by\n\n\\begin{eqnarray}\n  {{\\gamma _k} = \\frac{{{g_k}\\left( {{\\mathbf{S}}_P^{(i - 1)},{\\mathbf{S}}_I^{(i - 1)},{\\rho ^{(i - 1)}}} \\right)}}{{{z_{DC}}\\left( {{\\mathbf{S}}_P^{(i - 1)},{\\mathbf{S}}_I^{(i - 1)},{\\rho ^{(i - 1)}}} \\right)}},}&{k = 1, \\ldots ,K} \\\\\n  {{\\gamma _{nk}} = \\frac{{{g_{nk}}\\left( {{\\mathbf{S}}_I^{(i - 1)},{{\\bar \\rho }^{(i - 1)}}} \\right)}}{{1 + \\frac{{{{\\bar \\rho }^{(i - 1)}}}}{{\\sigma _n^2}}{C_n}\\left( {{\\mathbf{S}}_I^{(i - 1)}} \\right)}},}&\\begin{gathered}\n  n = 0, \\ldots ,N - 1 \\hfill \\\\\n  k = 1, \\ldots ,{K_n} \\hfill \\\\\n\\end{gathered}\n\\end{eqnarray}\n\nOnce $\\left\\{ {{\\gamma _k},{\\gamma _{nk}}} \\right\\}$ are obtained, we solve \\eqref{eqn:general_target} -- \\eqref{eqn:general_ratio_constraint} to obtain ${\\mathbf{S}}_P^{(i)},{\\mathbf{S}}_I^{(i)},{\\rho ^{(i)}}$. The iteration is repeated until it converges. Algorithm \\ref{alg:general} summarizes the procedures involved in the optimization. The successive approximation approach is also known as inner approximation method \\cite{Marks1978}, which cannot guarantee a global optimal solution but the result satisfies the Karush–Kuhn–Tucker (KKT) conditions.\n\n\\begin{algorithm}\n  \\caption{General Waveform Design}\n  \\label{alg:general}\n  \\begin{algorithmic}[1]\n    \\State \\textbf{Initialize:} $i \\leftarrow 0$, ${\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star $ in \\eqref{eqn:optimal_phases}, ${{{\\mathbf{S}}_P},{{\\mathbf{S}}_I}}$ in \\eqref{eqn:initial_amplitude}, $\\rho ,\\bar \\rho  = 1 - \\rho ,\\bar R,z_{DC}^{(0)} = 0$\n    \\Repeat\n      \\State $i \\leftarrow i + 1,\\mathop {{{\\mathbf{S}}_P}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_P},\\mathop {{{\\mathbf{S}}_I}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_I},\\ddot \\rho  \\leftarrow \\rho ,\\ddot{\\bar{\\rho}}  \\leftarrow \\bar \\rho $\n      \\State ${\\gamma _k} \\leftarrow {g_k}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\ddot \\rho } \\right)/{z_{DC}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\ddot \\rho } \\right),k = 1, \\ldots ,K$\n      \\State ${\\gamma _{nk}} \\leftarrow {g_{nk}}\\left( {\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,\\ddot{\\bar{\\rho}} } \\right)/\\left( {1 + \\frac{{\\ddot{\\bar{\\rho}}}}{{\\sigma _n^2}}{C_n}\\left( {\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} } \\right)} \\right),n = 0, \\ldots ,N - 1,k = 1, \\ldots ,{K_n}$\n      \\State ${{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho  \\leftarrow \\arg \\min $ \\eqref{eqn:general_target} -- \\eqref{eqn:general_ratio_constraint}\n      \\State $z_{DC}^{(i)} \\leftarrow {z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)$\n    \\Until{$\\left| {z_{DC}^{(i)} - z_{DC}^{(i - 1)}} \\right| < $ or $i = {i_{\\max }}$}\n  \\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\subsection{Decoupled Design}\\label{sec:decoupled-design}\nFor the transmitter with multiple antennas ($M > 1$), the previous method is involved with weight design across space and frequency. In this part, we will investigate an approach proposed in \\cite{Clerckx2018} that decouples the optimization in spatial and frequency domains without impacting performance. As suggested by \\eqref{eqn:mutual_information} and \\eqref{eqn:power_waveform_second_order} -- \\eqref{eqn:waveform_end}, the optimum weight vectors ${{\\mathbf{w}}_{P,n}}$ and ${{\\mathbf{w}}_{I,n}}$ that maximize the rate and energy correspond to the MRT beamformers, which are given by\n\n\\begin{align}\\label{eqn:mrt_weights}\n  {{\\mathbf{w}}_{P,n}} &= {s_{P,n}}{\\mathbf{h}}_n^H/\\left\\| {{{\\mathbf{h}}_n}} \\right\\| \\\\\n  {{\\mathbf{w}}_{I,n}} &= {s_{I,n}}{\\mathbf{h}}_n^H/\\left\\| {{{\\mathbf{h}}_n}} \\right\\|\n\\end{align}\n\nTherefore, the received power and information signals \\eqref{eqn:received_signal} rewrites as\n\n\\begin{align}\\label{eqn:mrt_received_components}\n  {y_P}(t) &= \\sum\\limits_{n = 0}^{N - 1} {\\left\\| {{{\\mathbf{h}}_n}} \\right\\|} {s_{P,n}}\\cos \\left( {{w_n}t} \\right) = \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {\\left\\| {{{\\mathbf{h}}_n}} \\right\\|} {s_{P,n}}{e^{j{w_n}t}}} \\right\\} \\\\\n  {y_I}(t) &= \\sum\\limits_{n = 0}^{N - 1} {\\left\\| {{{\\mathbf{h}}_n}} \\right\\|} {s_{I,n}}{{\\tilde x}_n}\\cos \\left( {{w_n}t} \\right) = \\Re \\left\\{ {\\sum\\limits_{n = 0}^{N - 1} {\\left\\| {{{\\mathbf{h}}_n}} \\right\\|} {s_{I,n}}{{\\tilde x}_n}{e^{j{w_n}t}}} \\right\\}\n\\end{align}\n\nIn this way, the weight optimization on multiple transmit antennas is converted into an equivalent problem on a single antenna. For the $n$-th subband, the equivalent channel gain is $\\left\\| {{{\\mathbf{h}}_n}} \\right\\|$ with the power allocated to multisine and modulated waveform denoted by $s_{P,n}^2$ and $s_{I,n}^2$ ($\\frac{1}{2}\\sum\\nolimits_{n = 0}^{N - 1} {\\left( {s_{P,n}^2 + s_{I,n}^2} \\right)}  \\leqslant P$). The problem can be solved using Algorithm \\ref{alg:general}, with the second and fourth order terms reduced to\n\n\\begin{align}\\label{eqn:decoupled_terms}\n  \\mathbb{E}\\left[ {{y_P}{{(t)}^2}} \\right] &= \\frac{1}{2}\\sum\\limits_{n = 0}^{N - 1} {{{\\left\\| {{{\\mathbf{h}}_n}} \\right\\|}^2}} s_{P,n}^2 \\\\\n  \\mathbb{E}\\left[ {{y_P}{{(t)}^4}} \\right] &= \\frac{3}{8}\\sum\\limits_{\\substack{ {n_0},{n_1},{n_2},{n_3} \\\\ {n_0} + {n_1} = {n_2} + {n_3} }}  {\\left[ {\\prod\\limits_{j = 0}^3 {{s_{P,{n_j}}}} \\left\\| {{{\\mathbf{h}}_{{n_j}}}} \\right\\|} \\right]}  \\\\\n  \\mathbb{E}\\left[ {{y_I}{{(t)}^2}} \\right] &= \\frac{1}{2}\\sum\\limits_{n = 0}^{N - 1} {{{\\left\\| {{{\\mathbf{h}}_n}} \\right\\|}^2}} s_{I,n}^2 \\\\\n  \\mathbb{E}\\left[ {{y_I}{{(t)}^4}} \\right] &= \\frac{6}{8}{\\left[ {\\sum\\limits_{n = 0}^{N - 1} {{{\\left\\| {{{\\mathbf{h}}_n}} \\right\\|}^2}} s_{I,n}^2} \\right]^2}\n\\end{align}\n\nHence, the target function ${z_{DC}}$ is only a function of two $N$-dimensional vectors ${{\\mathbf{s}}_{P/I}} = \\left[ {{s_{P/I,0}}, \\ldots ,{s_{P/I,N - 1}}} \\right]$, and the mutual information $I$ can be simplified as\n\n\\begin{equation}\\label{eqn:decoupled_mutual_information}\n  I\\left( {{{\\mathbf{s}}_I},\\rho } \\right) = {\\log _2}\\left( {\\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{(1 - \\rho )}}{{\\sigma _n^2}}s_{I,n}^2{{\\left\\| {{{\\mathbf{h}}_n}} \\right\\|}^2}} \\right)} } \\right)\n\\end{equation}\n\nSimilarly, we decompose the posynomials ${z_{DC}}\\left( {{{\\mathbf{s}}_P},{{\\mathbf{s}}_I},\\rho } \\right) = \\sum\\limits_{k = 1}^K {{g_k}} \\left( {{{\\mathbf{s}}_P},{{\\mathbf{s}}_I},\\rho } \\right)$ and $1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}{C_n} = \\sum\\limits_{k = 1}^{{K_n}} {{g_{nk}}} \\left( {{{\\mathbf{s}}_I},\\bar \\rho } \\right)$ with ${C_n} = s_{I,n}^2{\\left\\| {{{\\mathbf{h}}_n}} \\right\\|^2}$, then apply the AM-GM inequality to the constraints with posynomials in the denominator. The equivalent GP problem write as\n\n\\begin{eqnarray}\n  {\\mathop {\\min }\\limits_{{{\\mathbf{s}}_P},{{\\mathbf{s}}_I},\\rho ,\\bar \\rho ,{t_0}} }&{1/{t_0}} \\label{eqn:decoupled_target} \\\\\n  {{\\text{ subject to }}}&{\\frac{1}{2}\\left[ {\\left\\| {{{\\mathbf{s}}_I}} \\right\\|^2 + \\left\\| {{{\\mathbf{s}}_P}} \\right\\|^2} \\right] \\leqslant P} \\label{eqn:decoupled_power_constraint} \\\\\n  {}&{{t_0}\\prod\\limits_{k = 1}^K {{{\\left( {\\frac{{{g_k}\\left( {{{\\mathbf{s}}_P},{{\\mathbf{s}}_I},\\rho } \\right)}}{{{\\gamma _k}}}} \\right)}^{ - {\\gamma _k}}}}  \\leqslant 1} \\label{eqn:decoupled_current_constraint} \\\\\n  {}&{2^{\\bar R}}\\prod\\limits_{n = 0}^{N - 1} {\\prod\\limits_{k = 1}^{{K_n}} {{{\\left( {\\frac{{{g_{nk}}\\left( {{{\\mathbf{s}}_I},\\bar \\rho } \\right)}}{{{\\gamma _{nk}}}}} \\right)}^{ - {\\gamma _{nk}}}}} }  \\leqslant 1 \\label{eqn:decoupled_rate_constraint} \\\\\n  {}&{\\rho  + \\bar \\rho  \\leqslant 1} \\label{eqn:decoupled_ratio_constraint}\n\\end{eqnarray}\n\nFollowing \\eqref{eqn:initial_amplitude}, the amplitudes of power and information waveform can be initialized to\n\n\\begin{equation}\\label{eqn:initial_amplitude_decoupled}\n  {s_{P,n}} = {s_{I,n}} = c\\left\\| {{{\\mathbf{h}}_n}} \\right\\|\n\\end{equation}\n\nCompared with the general approach, the decoupled design guarantees the same performance by a joint space-frequency design with a lower computational complexity, which converts the original $N \\times M$ matrices ${{{\\mathbf{S}}_P},{{\\mathbf{S}}_I}}$ to $N$-dimensional vectors ${{{\\mathbf{s}}_P},{{\\mathbf{s}}_I}}$ via MRT beamformers. Algorithm \\ref{alg:decoupled} summarizes the optimization process of the decoupling strategy.\n\n\\begin{algorithm}\n  \\caption{Decoupled Waveform Design}\n  \\label{alg:decoupled}\n  \\begin{algorithmic}[1]\n    \\State \\textbf{Initialize:} $i \\leftarrow 0$, ${\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star $ in \\eqref{eqn:optimal_phases}, ${{{\\mathbf{s}}_P},{{\\mathbf{s}}_I}}$ in \\eqref{eqn:initial_amplitude_decoupled}, $\\rho ,\\bar \\rho  = 1 - \\rho ,\\bar R,z_{DC}^{(0)} = 0$\n    \\Repeat\n      \\State $i \\leftarrow i + 1,\\mathop {{{\\mathbf{s}}_P}}\\limits^{..}  \\leftarrow {{\\mathbf{s}}_P},\\mathop {{{\\mathbf{s}}_P}}\\limits^{..}  \\leftarrow {{\\mathbf{s}}_I},\\ddot \\rho  \\leftarrow \\rho ,\\ddot{\\bar{\\rho}}  \\leftarrow \\bar \\rho $\n      \\State ${\\gamma _k} \\leftarrow {g_k}\\left( {{{\\mathop {\\mathbf{s}}\\limits^{..} }_P},{{\\mathop {\\mathbf{s}}\\limits^{..} }_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\ddot \\rho } \\right)/{z_{DC}}\\left( {{{\\mathop {\\mathbf{s}}\\limits^{..} }_P},{{\\mathop {\\mathbf{s}}\\limits^{..} }_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\ddot \\rho } \\right),k = 1, \\ldots ,K$\n      \\State ${\\gamma _{nk}} \\leftarrow {g_{nk}}\\left( {{{\\mathop {\\mathbf{s}}\\limits^{..} }_I},\\ddot{\\bar{\\rho}} } \\right)/\\left( {1 + \\frac{{\\ddot{\\bar{\\rho}} }}{{\\sigma _n^2}}{C_n}\\left( {{{\\mathop {\\mathbf{s}}\\limits^{..} }_I}} \\right)} \\right),n = 0, \\ldots ,N - 1,k = 1, \\ldots ,{K_n}$\n      \\State ${{\\mathbf{s}}_P},{{\\mathbf{s}}_I},\\rho ,\\bar \\rho  \\leftarrow \\arg \\min $ \\eqref{eqn:decoupled_target} -- \\eqref{eqn:decoupled_ratio_constraint}\n      \\State $z_{DC}^{(i)} \\leftarrow {z_{DC}}\\left( {{{\\mathbf{s}}_P},{{\\mathbf{s}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)$\n    \\Until{$\\left| {z_{DC}^{(i)} - z_{DC}^{(i - 1)}} \\right| < $ or $i = {i_{\\max }}$}\n  \\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\subsection{Lower Bound}\\label{sec:lower-bound}\nThe deterministic multisine waveform not only boosts the harvested energy but also avoids interference to the modulated waveform. To highlight its benefit on rate and energy, we compare the performance of superposed waveform to two baselines. In the first case, there is no multisine component. Only modulated waveform is used for WIPT (i.e. ${{\\mathbf{S}}_P} = 0,\\frac{1}{2}\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2 = P$) and the twofold benefit disappears. In the second baseline, it is assumed that the power waveform behaves as a deterministic multisine from WPT perspective but as CSCG distributed from WIT perspective. Therefore, the energy benefit of the multisine is maintained but the rate benefit is lost. The power waveform creates an interference term $\\sqrt {1 - \\rho } {{\\mathbf{h}}_n}{{\\mathbf{w}}_{P,n}}$ to the information waveform, and the lower bound of the mutual information writes as\n\n\\begin{equation}\\label{eqn:mutual_information_lower_bound}\n  {I_{LB}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{{\\mathbf{\\Phi }}_P},{{\\mathbf{\\Phi }}_I},\\rho } \\right) = \\sum\\limits_{n = 0}^{N - 1} {{{\\log }_2}} \\left( {1 + \\frac{{(1 - \\rho ){{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{I,n}}} \\right|}^2}}}{{\\sigma _n^2 + (1 - \\rho ){{\\left| {{{\\mathbf{h}}_n}{{\\mathbf{w}}_{P,n}}} \\right|}^2}}}} \\right)\n\\end{equation}\n\nIt leads to a smaller rate-energy region than the ideal case. Also, the MRT beamformers ${{\\mathbf{w}}_{P,n}},{{\\mathbf{w}}_{I,n}}$ in \\eqref{eqn:mrt_weights} are suboptimal due to the interference, and the corresponding phases ${\\mathbf{\\Phi }}_P^ \\star, {\\mathbf{\\Phi }}_I^ \\star $ in \\eqref{eqn:optimal_phases} are not the best solution for $M > 1$. Minimum Mean Squared Error (MMSE) combiner can be further exploited for a better joint design over space and frequency domains.\n\nConsider the suboptimal phases ${\\mathbf{\\Phi }}_P^ \\star $ and ${\\mathbf{\\Phi }}_I^ \\star $ in \\eqref{eqn:optimal_phases} for simplicity. In such cases, the target function is still as \\eqref{eqn:target_function_truncated} while the lower bound of the achievable rate is now\n\n\\begin{equation}\\label{mutual_information_lower_bound_rewritten}\n  {I_{LB}}\\left( {{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right) = {\\log _2}\\left( {\\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{(1 - \\rho ){C_n}}}{{\\sigma _n^2 + (1 - \\rho ){D_n}}}} \\right)} } \\right)\n\\end{equation}\n\nwith ${C_n} = \\sum\\nolimits_{{m_0},{m_1}} {\\prod\\nolimits_{j = 0}^1 {{s_{I,n,{m_j}}}{A_{n,{m_j}}}} } $ and ${D_n} = \\sum\\nolimits_{{m_0},{m_1}} {\\prod\\nolimits_{j = 0}^1 {{s_{P,n,{m_j}}}{A_{n,{m_j}}}} } $. Thus, the previous rate constraint \\eqref{eqn:transformed_rate_constraint} is replaced by\n\n\\begin{equation}\\label{eqn:transformed_rate_constraint_lower_bound}\n  {2^{\\bar R}}\\frac{{\\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}{D_n}} \\right)} }}{{\\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}\\left( {{D_n} + {C_n}} \\right)} \\right)} }} \\leqslant 1\n\\end{equation}\n\nDecompose the posynomials in the denominators as\n\n\\begin{equation}\\label{eqn:posynomial_lower_bound}\n  1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}\\left( {{D_n} + {C_n}} \\right) = \\sum\\limits_{j = 1}^{{J_n}} {{f_{nj}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho } \\right)}\n\\end{equation}\n\nwhere $\\left\\{ {{f_{nj}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho } \\right)} \\right\\}$ is the monomial terms. With a proper choice of nonnegative $\\left\\{ {{\\gamma _{nj}}} \\right\\}$ satisfying $\\sum\\nolimits_{j = 1}^{{J_n}} {{\\gamma _{nj}}}  = 1$, the standard GP can be written as\n\n\\begin{eqnarray}\n  {\\mathop {\\min }\\limits_{{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho ,{t_0}} }&{1/{t_0}} \\label{eqn:lower_bound_target} \\\\\n  {{\\text{subject to}}}&{\\frac{1}{2}\\left[ {\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2 + \\left\\| {{{\\mathbf{S}}_P}} \\right\\|_F^2} \\right] \\leqslant P} \\label{eqn:lower_bound_power_constraint} \\\\\n  {}&{{t_0}\\prod\\limits_{k = 1}^K {{{\\left( {\\frac{{{g_k}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)}}{{{\\gamma _k}}}} \\right)}^{ - {\\gamma _k}}}}  \\leqslant 1} \\label{eqn:lower_bound_current_constraint} \\\\\n  {}&{{2^{\\bar R}}\\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{\\bar \\rho }}{{\\sigma _n^2}}{D_n}\\left( {{{\\mathbf{S}}_P}} \\right)} \\right)} \\prod\\limits_{j = 1}^{{J_n}} {{{\\left( {\\frac{{{f_{nj}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho } \\right)}}{{{\\gamma _{nj}}}}} \\right)}^{ - {\\gamma _{nj}}}}}  \\leqslant 1} \\label{eqn:lower_bound_rate_constraint} \\\\\n  {}&{\\rho  + \\bar \\rho  \\leqslant 1 \\label{eqn:lower_bound_ratio_constraint}}\n\\end{eqnarray}\n\nAlgorithm \\ref{alg:lower-bound} shows the basic idea to obtain the lower-bound of R-E region. It boils down to Algorithm \\ref{alg:general} when the interference posynomial ${D_n} = 0$ for all $n$.\n\n\\begin{algorithm}\n  \\caption{Lower-Bound of R-E Region}\n  \\label{alg:lower-bound}\n  \\begin{algorithmic}[1]\n    \\State \\textbf{Initialize:} $i \\leftarrow 0$, ${{\\mathbf{w}}_{P,n}},{{\\mathbf{w}}_{I,n}}$ in \\eqref{eqn:mrt_weights}, ${{{\\mathbf{S}}_P},{{\\mathbf{S}}_I}}$ in \\eqref{eqn:initial_amplitude}, $\\rho ,\\bar \\rho  = 1 - \\rho ,\\bar R,z_{DC}^{(0)} = 0$\n    \\Repeat\n      \\State $i \\leftarrow i + 1,\\mathop {{{\\mathbf{S}}_P}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_P},\\mathop {{{\\mathbf{S}}_I}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_I},\\ddot \\rho  \\leftarrow \\rho ,\\ddot{\\bar{\\rho}}  \\leftarrow \\bar \\rho $\n      \\State ${\\gamma _k} \\leftarrow {g_k}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,\\ddot \\rho } \\right)/{z_{DC}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,\\ddot \\rho } \\right),k = 1, \\ldots ,K$\n      \\State ${\\gamma _{nj}} \\leftarrow {f_{nj}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,\\ddot \\rho } \\right)/\\left( {1 + \\frac{{\\ddot{\\bar{\\rho}}}}{{\\sigma _n^2}}\\left( {{D_n}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} } \\right) + {C_n}\\left( {\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} } \\right)} \\right)} \\right)$\n      \\State ${{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho  \\leftarrow \\arg \\min $ \\eqref{eqn:lower_bound_target} -- \\eqref{eqn:lower_bound_ratio_constraint}\n      \\State $z_{DC}^{(i)} \\leftarrow {z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho } \\right)$\n    \\Until{$\\left| {z_{DC}^{(i)} - z_{DC}^{(i - 1)}} \\right| < $ or $i = {i_{\\max }}$}\n  \\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\subsection{PAPR Constraints}\\label{sec:papr-constraints}\nAnother practical constraint at the transmitter is PAPR. We assume the modulated information waveform is with unit PAPR (by PSK or FSK) so that the limitation only influence the design of multisine power waveform. Following \\eqref{eqn:power_waveform}, the PAPR constraint on antenna $m$ writes as\n\n\\begin{equation}\\label{eqn:papr_power_waveform}\n  {\\text{PAPR}_m} = \\frac{{\\mathop {\\max }\\limits_t {{\\left| {{x_{P,m}}(t)} \\right|}^2}}}{{\\mathbb{E}\\left[ {{{\\left| {{x_{P,m}}(t)} \\right|}^2}} \\right]}} = \\frac{{\\mathop {\\max }\\limits_t {{\\left| {{x_{P,m}}(t)} \\right|}^2}}}{{\\frac{1}{2}{{\\left\\| {{{\\mathbf{s}}_{P,m}}} \\right\\|}^2}}} \\leqslant \\eta\n\\end{equation}\n\nWe assume the optimum phases ${\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star $ in \\eqref{eqn:optimal_phases} are used in the optimization of ${{\\mathbf{S}}_I},{{\\mathbf{S}}_P}$. To handle the PAPR constraint \\eqref{eqn:papr_power_waveform}, we introduce an oversampling factor ${O_s}$ to sample the power waveform at ${t_q} = qT/N{O_s}$ for $q = 0, \\ldots ,N{O_s} - 1$ with $T = 1/\\Delta f$. For a sufficiently large ${O_s}$, the PAPR constraint can be expressed as\n\n\\begin{equation}\\label{eqn:papr_sample}\n  {\\left| {{x_{P,m}}\\left( {{t_q}} \\right)} \\right|^2} \\leqslant \\frac{1}{2}\\eta {\\left\\| {{{\\mathbf{s}}_{P,m}}} \\right\\|^2}\n\\end{equation}\n\nwhere the l.h.s. obtained from equation \\eqref{eqn:power_waveform} is\n\n\\begin{equation}\\label{eqn:papr_average_sample}\n  {\\left| {{x_{P,m}}\\left( {{t_q}} \\right)} \\right|^2} = \\sum\\limits_{{n_0},{n_1}} {{s_{P,{n_0},m}}{s_{P,{n_1},m}}\\cos \\left( {{w_{{n_0}}}{t_q} + \\phi _{P,{n_0},m}^ \\star } \\right)\\cos \\left( {{w_{{n_1}}}{t_q} + \\phi _{P,{n_1},m}^ \\star } \\right)}\n\\end{equation}\n\nHowever, ${\\left| {{x_{P,m}}\\left( {{t_q}} \\right)} \\right|^2}$ is no longer a posynomial as some coefficients can be negative with time-varying arguments. It is named signomial \\cite{Boyd2007} and can be decomposed either as the sum of monomials or as the difference of two posynomials\n\n\\begin{equation}\\label{eqn:papr_signomial}\n  {\\left| {{x_{P,m}}\\left( {{t_q}} \\right)} \\right|^2} = {f_{mq}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right) = {f_{mq1}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right) - {f_{mq2}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)\n\\end{equation}\n\nTherefore, the PAPR constraint rewrites as\n\n\\begin{equation}\\label{eqn:papr_standard}\n  \\frac{{{f_{mq1}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)}}{{\\frac{1}{2}\\eta {{\\left\\| {{{\\mathbf{s}}_{P,m}}} \\right\\|}^2} + {f_{mq2}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)}} \\leqslant 1\n\\end{equation}\n\nSimilarly, denote the posynomial at the denominator as\n\n\\begin{equation}\\label{eqn:papr_denominator}\n  \\frac{1}{2}\\eta {\\left\\| {{{\\mathbf{s}}_{P,m}}} \\right\\|^2} + {f_{mq2}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right) = \\sum\\limits_{k = 1}^{{K_{mq2}}} {{g_{mq2k}}} \\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)\n\\end{equation}\n\nWith a proper choice of nonnegative $\\left\\{ {{\\gamma _{mq2k}}} \\right\\}$ satisfying $\\sum\\nolimits_{k = 1}^{{K_{mq2}}} {{\\gamma _{mq2k}}}  = 1$, we apply AM-GM inequality to \\eqref{eqn:papr_standard} and obtain the new constraint\n\n\\begin{equation}\\label{eqn:papr_equivalent_inequality}\n  {f_{mq1}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)\\prod\\limits_{k = 1}^{{K_{mq2}}} {{{\\left( {\\frac{{{g_{mq2k}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)}}{{{\\gamma _{mq2k}}}}} \\right)}^{ - {\\gamma _{mq2k}}}}}  \\leqslant 1\n\\end{equation}\n\nIn this way, the optimization problem \\eqref{eqn:general_target} -- \\eqref{eqn:general_ratio_constraint} with an extra PAPR constraint \\eqref{eqn:papr_power_waveform} is replaced by a standard GP\n\n\\begin{eqnarray}\n  {\\mathop {\\min }\\limits_{{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho ,{t_0}} }&{1/{t_0}} \\label{eqn:papr_target} \\\\\n  {{\\text{ subject to }}}&{\\frac{1}{2}\\left[ {\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2 + \\left\\| {{{\\mathbf{S}}_P}} \\right\\|_F^2} \\right] \\leqslant P} \\label{eqn:papr_power_constraint} \\\\\n  {}&{{t_0}\\prod\\limits_{k = 1}^K {{{\\left( {\\frac{{{g_k}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)}}{{{\\gamma _k}}}} \\right)}^{ - {\\gamma _k}}}}  \\leqslant 1} \\label{eqn:papr_current_constraint} \\\\\n  {}&{{2^{\\bar R}}\\prod\\limits_{n = 0}^{N - 1} {\\prod\\limits_{k = 1}^{{K_n}} {{{\\left( {\\frac{{{g_{nk}}\\left( {{{\\mathbf{S}}_I},\\bar \\rho } \\right)}}{{{\\gamma _{nk}}}}} \\right)}^{ - {\\gamma _{nk}}}}} }  \\leqslant 1} \\label{eqn:papr_rate_constraint} \\\\\n  {}&{{f_{mq1}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)\\prod\\limits_{k = 1}^{{K_{mq2}}} {{{\\left( {\\frac{{{g_{mq2k}}\\left( {{{\\mathbf{S}}_P},{\\mathbf{\\Phi }}_P^ \\star } \\right)}}{{{\\gamma _{mq2k}}}}} \\right)}^{ - {\\gamma _{mq2k}}}}}  \\leqslant 1} \\label{eqn:papr_papr_constraint} \\\\\n  {}&{\\rho  + \\bar \\rho  \\leqslant 1} \\label{eqn:papr_ratio_constraint}\n\\end{eqnarray}\n\nAlgorithm \\ref{alg:papr} shows the gist of the optimization procedure. For the system with multiple transmit antenna and valid PAPR constraints, the decoupling strategy is suboptimal since the arguments of cosines are indeed frequency-dependent. Also, the multisine waveform is oversampled to satisfy the PAPR constraint, which further increases the overall computational complexity.\n\n\\begin{algorithm}\n  \\caption{Waveform Design with PAPR Constraints}\n  \\label{alg:papr}\n  \\begin{algorithmic}[1]\n    \\State \\textbf{Initialize:} $i \\leftarrow 0$, ${\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star $ in \\eqref{eqn:optimal_phases}, ${{{\\mathbf{S}}_P},{{\\mathbf{S}}_I}}$ in \\eqref{eqn:initial_amplitude}, $\\rho ,\\bar \\rho  = 1 - \\rho ,\\bar R,z_{DC}^{(0)} = 0$\n    \\Repeat\n      \\State $i \\leftarrow i + 1,\\mathop {{{\\mathbf{S}}_P}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_P},\\mathop {{{\\mathbf{S}}_I}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_I},\\ddot \\rho  \\leftarrow \\rho ,\\ddot{\\bar{\\rho}}  \\leftarrow \\bar \\rho $\n      \\State ${\\gamma _k} \\leftarrow {g_k}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\ddot \\rho } \\right)/{z_{DC}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\ddot \\rho } \\right),k = 1, \\ldots ,K$\n      \\State ${\\gamma _{nk}} \\leftarrow {g_{nk}}\\left( {\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,\\ddot{\\bar{\\rho}}} \\right)/\\left( {1 + \\frac{{\\ddot{\\bar{\\rho}}}}{{\\sigma _n^2}}{C_n}\\left( {\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} } \\right)} \\right),n = 0, \\ldots ,N - 1,k = 1, \\ldots ,{K_n}$\n      \\State ${\\gamma _{mq2k}} \\leftarrow {g_{mq2k}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^ \\star } \\right)/\\left( {\\frac{1}{2}\\eta {{\\left\\| {\\mathop {{{\\mathbf{s}}_{P,m}}}\\limits^{..} } \\right\\|}^2} + {f_{mq2}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^ \\star } \\right)} \\right),$\n      \\Statex $m = 1, \\ldots ,M,q = 0, \\ldots ,N{O_s} - 1,k = 1, \\ldots ,{K_{mq2}}$\n      \\State ${{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho  \\leftarrow \\arg \\min $ \\eqref{eqn:papr_target} -- \\eqref{eqn:papr_ratio_constraint}\n      \\State $z_{DC}^{(i)} \\leftarrow {z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^ \\star ,{\\mathbf{\\Phi }}_I^ \\star ,\\rho } \\right)$\n    \\Until{$\\left| {z_{DC}^{(i)} - z_{DC}^{(i - 1)}} \\right| < $ or $i = {i_{\\max }}$}\n  \\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\subsection{Multiple Rectennas}\\label{sec:multiple-rectennas}\nThe R-E region is expected to be enlarged by using multiple rectennas. In this part, we extend the general MISO strategy in \\cite{Clerckx2018} to $U$ rectennas, which can either serve a single user in a point-to-point MIMO or spread across multiple users in an MU-MISO. Note that there exists a tradeoff between the energy harvested in different rectennas since they have different preference on the transmitted waveform. The fairness issue can be solved by introducing weight ${v_u}$ for rectenna $u = 1, \\ldots ,U$ and considering the weighted sum of DC components as a new target function\n\n\\begin{equation}\\label{eqn:weighted_target}\n  {Z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{{\\mathbf{\\Phi }}_P},{{\\mathbf{\\Phi }}_I},\\rho } \\right) = \\sum\\limits_{u = 1}^U {{v_u}{z_{DC,u}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{{\\mathbf{\\Phi }}_P},{{\\mathbf{\\Phi }}_I},\\rho } \\right)}\n\\end{equation}\n\nWith multiple rectennas, the frequency response is extended to\n\n\\begin{equation}\\label{eqn:mo_channel}\n  {h_{n,m,u}} = {A_{n,m,u}}{e^{j{{\\bar \\psi }_{n,m,u}}}}\n\\end{equation}\n\nTherefore, the phase of the received signal on rectenna $u$ in subband $n$ transmitted by antenna $m$ equals\n\n\\begin{equation}\\label{eqn:received_phase}\n  {\\psi _{n,m,u}} = {\\phi _{n,m}} + {{\\bar \\psi }_{n,m,u}}\n\\end{equation}\n\nwhere ${\\phi _{n,m}}$ is the beamforming phase. In such cases, it is impossible to ensure ${\\psi _{n,m,u}} = 0$ for all rectennas as there are three constraints $n,m,u$ but only two variables $n,m$. With a specific phase design, the arguments of cosines in \\eqref{eqn:power_waveform_second_order} -- \\eqref{eqn:waveform_end} are not guaranteed to be zero such that the target function ${Z_{DC}}$ is indeed a signomial.\n\nDenoting ${\\widetilde {\\mathbf{h}}_{n,u}} = \\sqrt {{k_2}{v_u}} {{\\mathbf{h}}_{n,u}}$, the channel matrix for subband $n$ can be constructed as\n\n\\begin{equation}\\label{eqn:mo_channel_matrox}\n  {\\widetilde {\\mathbf{H}}_n} = {\\left[ {\\widetilde {\\mathbf{h}}_{n,1}^T \\ldots \\widetilde {\\mathbf{h}}_{n,U}^T} \\right]^T}\n\\end{equation}\n\nIt is mentioned in \\cite{Clerckx2016} that a possible phase choice ${\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime $ is to set the $\\left( {n,m} \\right)$ entries as\n\n\\begin{equation}\\label{eqn:mo_phases}\n  \\phi _{P,n,m}^\\prime  = \\phi _{I,n,m}^\\prime  = \\angle {v_{{\\text{max}},n,m}}\n\\end{equation}\n\nwhere ${v_{{\\text{max}},n,m}}$ is the $m$-th term of the dominant right singular vector ${{\\mathbf{v}}_{{\\text{max}},n}}$ that can be obtained by singular value decomposition of ${\\widetilde {\\mathbf{H}}_n}$. Also, the subband amplitudes can be initialized using the maximum eigenvalue $\\sigma _n^\\prime $\n\n\\begin{equation}\\label{eqn:mo_initial_amplitude}\n  {s_{P,n,m}} = {s_{I,n,m}} = c\\sigma _n^\\prime \n\\end{equation}\n\nwhere $c$ is the coefficient to guarantee the transmit power constraint. Note the initialization is irrelevant to $m$.\n\nTo convert the problem into a standard GP, we introduce an auxiliary variable ${t_0}$ and rewrite the signomial as the difference of two posynomials\n\n\\begin{equation}\\label{eqn:mo_current_signomial}\n  {Z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) = {f_1}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) - {f_2}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) \\geqslant {t_0}\n\\end{equation}\n\nFurthermore, we can decompose the first posynomial as\n\n\\begin{equation}\\label{eqn:mo_current_posynomial}\n  {f_1}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) = \\sum\\limits_{k = 1}^{{K_1}} {{g_{1k}}} \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)\n\\end{equation}\n\nWith a proper choice of nonnegative $\\left\\{ {{\\gamma _{1k}}} \\right\\}$ satisfying $\\sum\\nolimits_{k = 1}^{{K_1}} {{\\gamma _{1k}}}  = 1$, \\eqref{eqn:mo_current_signomial} rewrites as\n\n\\begin{align}\\label{eqn:mo_current_signomial_rewritten}\n  \\frac{{{t_0} + {f_2}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}}{{{f_1}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}} &= \\left( {{t_0} + {f_2}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)} \\right) \\nonumber \\\\\n  &\\quad \\prod\\limits_{k = 1}^{{K_1}} {{{\\left( {\\frac{{{g_{1k}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}}{{{\\gamma _{1k}}}}} \\right)}^{ - {\\gamma _{1k}}}}} \\\\\n  &\\leqslant 1\n\\end{align}\n\nSimilarly, the denominator of rate constraint \\eqref{eqn:transformed_rate_constraint} is indeed a product of signomials, with each factor expressed as\n\n\\begin{equation}\\label{eqn:mo_rate_signomial}\n  1 + \\frac{{(1 - \\rho )}}{{\\sigma _n^2}}{C_n} = {f_{1nk}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) - {f_{2nk}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)\n\\end{equation}\n\nTherefore, we can rewrite the rate constraint \\eqref{eqn:transformed_rate_constraint} as\n\n\\begin{align}\\label{eqn:mo_rate_constraint_original}\n  \\prod\\limits_{n = 0}^{N - 1} {\\left( {1 + \\frac{{(1 - \\rho )}}{{\\sigma _n^2}}{C_n}} \\right)}  &= \\prod\\limits_{n = 0}^{N - 1} {\\left( {{f_{1nk}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) - {f_{2nk}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)} \\right)}  \\\\\n  &\\geqslant {2^{\\bar R}} \\label{eqn:mo_rate_constraint_original_end}\n\\end{align}\n\nOne possible approach is to unwrap the result of signomial multiplication as a new signomial. In this way, \\eqref{eqn:mo_rate_constraint_original_end} is reduced to\n\n\\begin{equation}\\label{eqn:mo_rate_constraint_unwrapped}\n  f_1^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) - f_2^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) \\geqslant {2^{\\bar R}}\n\\end{equation}\n\nwhich is equivalent to\n\n\\begin{equation}\\label{eqn:mo_rate_constraint_rewritten}\n  \\frac{{{2^{\\bar R}} + f_2^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}}{{f_1^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}} \\leqslant 1\n\\end{equation}\n\nBy decomposing $f_1^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right) = \\sum\\nolimits_{j = 1}^{{J_1}} {g_{1j}^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)} $ and introducing another nonnegative coefficient set $\\left\\{ {\\gamma _{1j}^\\prime } \\right\\}$ with $\\sum\\nolimits_{j = 1}^{{J_1}} {\\gamma _{1j}^\\prime }  = 1$ for AM-GM inequality, it can be converted to\n\n\\begin{equation}\\label{eqn:mo_rate_constraint_standard}\n  \\left( {{2^{\\bar R}} + f_2^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)} \\right)\\prod\\limits_{j = 1}^{{J_1}} {{{\\left( {\\frac{{g_{1j}^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}}{{\\gamma _{1j}^\\prime }}} \\right)}^{ - \\gamma _{1j}^\\prime }}}  \\leqslant 1\n\\end{equation}\n\nHence, the problem is transformed into a standard GP\n\n\\begin{eqnarray}\n  {\\mathop {\\min }\\limits_{{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho ,{t_0}} }&{1/{t_0}} \\label{eqn:mo_target} \\\\\n  {{\\text{ subject to }}}&{\\frac{1}{2}\\left[ {\\left\\| {{{\\mathbf{S}}_I}} \\right\\|_F^2 + \\left\\| {{{\\mathbf{S}}_P}} \\right\\|_F^2} \\right] \\leqslant P} \\label{eqn:mo_power_constraint} \\\\\n  {}&{\\left( {{t_0} + {f_2}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)} \\right)\\prod\\limits_{k = 1}^{{K_1}} {{{\\left( {\\frac{{{g_{1k}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}}{{{\\gamma _{1k}}}}} \\right)}^{ - {\\gamma _{1k}}}}}  \\leqslant 1} \\label{eqn:mo_current_constraint} \\\\\n  {}&{\\left( {{2^{\\bar R}} + f_2^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)} \\right)\\prod\\limits_{j = 1}^{{J_1}} {{{\\left( {\\frac{{g_{1j}^\\prime \\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)}}{{\\gamma _{1j}^\\prime }}} \\right)}^{ - \\gamma _{1j}^\\prime }}}  \\leqslant 1} \\label{eqn:mo_rate_constraint} \\\\\n  {}&{\\rho  + \\bar \\rho  \\leqslant 1 \\label{eqn:mo_ratio_constraint}}\n\\end{eqnarray}\n\nIt is worth noting that the GP method is not the best optimization approach due to the predetermined suboptimal beamforming phases ${\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime $. Also, the unwrap process from \\eqref{eqn:mo_rate_constraint_original} to \\eqref{eqn:mo_rate_constraint_unwrapped} significantly increases the computational complexity and is more suitable for small $n$ and $m$. The procedure is concluded in Algorithm \\ref{alg:mo}.\n\n\\begin{algorithm}\n  \\caption{Waveform Design for Multiple Rectennas}\n  \\label{alg:mo}\n  \\begin{algorithmic}[1]\n    \\State \\textbf{Initialize:} $i \\leftarrow 0$, ${{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime }$ in \\eqref{eqn:mo_phases}, ${{{\\mathbf{S}}_P},{{\\mathbf{S}}_I}}$ in \\eqref{eqn:mo_initial_amplitude}, $\\rho ,\\bar \\rho  = 1 - \\rho ,\\bar R,Z_{DC}^{(0)} = 0$\n    \\Repeat\n      \\State $i \\leftarrow i + 1,\\mathop {{{\\mathbf{S}}_P}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_P},\\mathop {{{\\mathbf{S}}_I}}\\limits^{..}  \\leftarrow {{\\mathbf{S}}_I},\\ddot \\rho  \\leftarrow \\rho ,\\ddot{\\bar{\\rho}}  \\leftarrow \\bar \\rho $\n      \\State ${\\gamma _{1k}} \\leftarrow {g_{1k}}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\ddot \\rho } \\right)/{f_1}\\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\ddot \\rho } \\right),k = 1, \\ldots ,{K_1}$\n      \\State $\\gamma _{1j}^\\prime  \\leftarrow g_{1j}^\\prime \\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\ddot \\rho } \\right)/f_1^\\prime \\left( {\\mathop {{{\\mathbf{S}}_P}}\\limits^{..} ,\\mathop {{{\\mathbf{S}}_I}}\\limits^{..} ,{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\ddot \\rho } \\right),j = 1, \\ldots ,{J_1}$\n      \\State ${{\\mathbf{S}}_P},{{\\mathbf{S}}_I},\\rho ,\\bar \\rho  \\leftarrow \\arg \\min $ \\eqref{eqn:mo_target} -- \\eqref{eqn:mo_ratio_constraint}\n      \\State $Z_{DC}^{(i)} \\leftarrow {Z_{DC}}\\left( {{{\\mathbf{S}}_P},{{\\mathbf{S}}_I},{\\mathbf{\\Phi }}_P^\\prime ,{\\mathbf{\\Phi }}_I^\\prime ,\\rho } \\right)$\n    \\Until{$\\left| {Z_{DC}^{(i)} - Z_{DC}^{(i - 1)}} \\right| < $ or $i = {i_{\\max }}$}\n  \\end{algorithmic}\n\\end{algorithm} ", "meta": {"hexsha": "b8fcf15e168ce11c2da2c5ee1e2e4175c9759288", "size": 40751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/thesis/rate-energy-tradeoff/iterative-algorithms.tex", "max_stars_repo_name": "SnowzTail/signal-optimisation-for-wireless-information-and-power-transmission", "max_stars_repo_head_hexsha": "f53382f99610becd8d78ee34cc9c3d49d2c7f61b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-07-10T21:31:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T18:01:41.000Z", "max_issues_repo_path": "tex/thesis/rate-energy-tradeoff/iterative-algorithms.tex", "max_issues_repo_name": "SnowzTail/signal-optimisation-for-wireless-information-and-power-transmission", "max_issues_repo_head_hexsha": "f53382f99610becd8d78ee34cc9c3d49d2c7f61b", "max_issues_repo_licenses": ["MIT"], "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/thesis/rate-energy-tradeoff/iterative-algorithms.tex", "max_forks_repo_name": "SnowzTail/signal-optimisation-for-wireless-information-and-power-transmission", "max_forks_repo_head_hexsha": "f53382f99610becd8d78ee34cc9c3d49d2c7f61b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-12T23:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T18:01:46.000Z", "avg_line_length": 104.7583547558, "max_line_length": 903, "alphanum_fraction": 0.6213099065, "num_tokens": 16284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6605831372291019}}
{"text": "\\section{Renormalization Group}\nBlock spin trnasformation for matrice slacing $a$ to $la$.\nThe parttion function is\n\\begin{align}\n    Z &=\n    \\sum_{ \\left\\{ \\sigma \\right\\}} e^{K\\left[ \\sigma \\right]}\\\\\n    &=\n    \\sum_{ \\left\\{ \\sigma' \\right\\}} e^{K' \\left[ \\sigma' \\right]}\n\\end{align}\nwhere\n\\begin{align}\n    K'\n    &=\n    K_0'\n    +\n    K'_2\n    \\sum_{n,m} \\sigma'_{i} \\sigma'_{j}\n    +\n    K'_3\n    \\sum_{n-m,n} \\sigma'_i \\sigma'_j\n    +\n    K_4' \\sum_{\\square}\n    \\sigma'_i \\sigma'_j \\sigma'_k \\sigma'_l\n    + \\cdots\n\\end{align}\nAt fixed points\n\\begin{align}\n    K^* &= R\\left( K^* \\right)\n\\end{align}\nwhich we can expand near fixed point\n\\begin{align}\n    K'_{\\alpha}\n    -\n    K_{\\alpha}^*\n    &=\n    R\\left( K \\right)\n    -\n    K^*\\\\\n    &\\approx\n    R\\left( K^* \\right)\n    +\n    \\left( K - K^* \\right)_{\\beta}\n    \\left.\n    \\frac{\\partial R}{\\partial K_{\\beta}}\n    \\right|_{K=K^*}\n    +\n    \\cdots\n\\end{align}\nFor simplicity assume the matrix $\\frac{\\partial R_\\alpha}{\\partial K_\\beta}$\nis symmetric.\nThen if $\\lambda > 1$ we say it is a relevant direciton,\nbut if $\\lambda < 1$ it is irrelevant.\nAnd if it's equal to zero then it's marginal.\nTHey are relevant for areason.\n\nBig diagram here.\n\\begin{figure}[h]\n    \\begin{center}\n        \\includesvg{rgflow}\n    \\end{center}\n    \\caption{RG flow}%\n    \\label{fig:rgflow}\n\\end{figure}\n\\begin{align}\n    K &=\n    \\beta J\\\\\n    &=\n    \\frac{J}{k_B \\left( T - T_c + T_c \\right)}\\\\\n    &\\approx\n    \\frac{J}{k_B T_c}\n    \\left( \n    1\n    +\n    \\underbrace{\\frac{T - T_c}{T_c}}_{t}\n    + \\cdots\n    \\right)\n\\end{align}\n\nCritical exponent $\\nu$.\n\\begin{align}\n    t' &= \\lambda t\\\\\n    t^{(n)} &= \\lambda^n t\\\\\n\\end{align}\nso the correlation length scales like\n\\begin{align}\n    \\xi\\left( t' \\right) &= \\frac{1}{l} \\xi\\left( t \\right)\\\\\n    \\xi\\left( t^{(n)} \\right)\n    &=\n    \\frac{\\xi\\left( t \\right)}{l^n}\n\\end{align}\nwith\n\\begin{align}\n    n\n    &=\n    \\frac{\\ln \\left( b/t \\right)}{\\ln \\lambda}\n\\end{align}\nNote\n\\begin{align}\n    \\lambda^n t\n    &=\n    e^{n \\ln \\lambda} t\n    =\n    e^{\\frac{\\ln (b/t)}{\\ln \\lambda} \\ln \\lambda} t\\\\\n    &=\n    \\frac{b}{t} t\\\\\n    &= b\n\\end{align}\nAnd\n\\begin{align}\n    l^n &=\n    e^{n\\ln l}\\\\\n    &=\n    e^{\\frac{\\ln(b/t)}{\\ln \\lambda} \\ln \\lambda}\\\\\n    &=\n    \\left( \\frac{b}{t} \\right)^{\\frac{\\ln l}{\\ln \\lambda}}\n\\end{align}\nso then\n\\begin{align}\n    \\xi\\left( t \\right)\n    &=\n    l^n \\xi\\left( t' \\right)\n    =\n    \\underbrace{l^n}_{t/b}\n    \\xi\\left( \\underbrace{\\lambda^n t}_{b} \\right)\\\\\n    &\\sim\n    t^{- \\frac{\\ln l}{\\ln \\lambda}} = t^{-\\nu}\n\\end{align}\nHence\n\\begin{align}\n    \\nu &=\n    \\frac{\\ln l}{\\ln \\lambda}\n\\end{align}\n\nNow let us calculate the $\\alpha$.\nConsider $f(t)$ to be the free energy per site.\n\\begin{align}\n    l^d f(t)\n    &-\n    f\\left( t' \\right)\n\\end{align}\nwhich implies\n\\begin{align}\n    f(t)\n    &=\n    \\underbrace{\n    \\frac{1}{l^{dn}}\n    }_{\n    \\left( \\frac{t}{b} \\right)^{-d \\underbrace{\n    \\frac{\\ln l}{\\ln \\lambda}}_{\n    \\nu\n    }}\n    }\n    f\\left( \\lambda^n t \\right)\\\\\n    &\\sim t^{d\\nu}\n\\end{align}\nRecalling that\n\\begin{align}\n    n &=\n    \\frac{\\ln b/t}{\\ln \\lambda}\n\\end{align}\nAnd the specific heat is proportional to\n\\begin{align}\n    C &\\sim\n    -\\frac{\\partial^2 f}{\\partial t^2}\n    \\sim\n    t^{\\underbrace{d\\nu - 2}_{\\alpha}}\n\\end{align}\nhence\n\\begin{align}\n    \\alpha &= d\\nu - 2\n\\end{align}\nwhich is the Josephson relation.\n", "meta": {"hexsha": "b680890e64d7a2f10f3555b8fc10db1c8c86bace", "size": 3386, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture35.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/lecture35.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/lecture35.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": 19.5722543353, "max_line_length": 77, "alphanum_fraction": 0.5428233904, "num_tokens": 1309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6605324703148461}}
{"text": "\\documentclass{article}\n\n\\usepackage{style/preamble}\n\\usepackage{parskip}\n\\usepackage[normalem]{ulem}\n\n\\begin{document}\n  \\title{\\sout{Problem Set} 5 - Affine charts}\n  \\date{}\n  \\maketitle\n\n\n\n\n\n\n\\section{Singularities}\n\\textbf{Notation:} Set of solutions of a bunch of polynomial equations is called a \\emph{variety}. Varities in $\\bbc^n$ are called \\emph{affine varities} and varities in $\\bbp^n$ are called \\emph{projective varieties}.\n\nWe'll start with two examples of singularities, one in $\\bbc^2$ and one in $\\bbp^1$.\n\n\\begin{ex}\n  The affine variety given by $p(z,w) = z^2 - w^2$ is an intersection of two lines, and hence has a singularity at $(0,0)$.\n  In general, if the lowest degree terms in $p(z,w)$ are of degree $\\ge 2$ then the corresponding variety has a singularity at $(0,0)$ and hence is not a Riemann surface.\n  As far as varieties in $\\bbc^2$ are concerned, this is the only way singularities arise but in higher dimensions the singularities are much more complicated and hence interesting.\n\\end{ex}\n\n\\begin{ex}[Hyperelliptic curve]\n  Consider $p(z,w) = z^2 - q(w)$ with $q(w) = w^4 - w$.\n  The homogenization of $p$ is $\\conj{p}(z,w,t) = z^2 t^2 - w^4 - w t^3$.\n  The points at $\\infty$ are given by plugging in $t = 0$,\n  \\begin{align*}\n    \\conj{p}(z,w,t) &= 0 \\\\\n    w^4 &= 0\n  \\end{align*}\n  So there is exactly one point at $\\infty$, namely $[1:0:0]$.\n\n  The projection map $\\conj{S_p} \\rightarrow \\bbp^1$ sending $[z:w:1] \\mapsto w$ and $[1:0:0] \\mapsto \\infty$ is a degree 2 map which ramifies at 5 points: the roots of $q(z)$ and $\\infty$.\n\n  Plugging in Riemann-Hurwitz we get:\n  \\begin{align*}\n    \\chi(\\conj{S_p})\n    &= 2 \\cdot \\chi(\\bbp^1) - \\sum_{5}\\mathrm{index} - 1 \\\\\n    &= 4 - 5 \\\\\n    &= -1\n  \\end{align*}\n  But there is no surface with Euler characteristic -1.\n  The reason we see this is that $\\conj{S_p}$ is not a Riemann surface and has a singularity at $\\infty$.\n\\end{ex}\n\n\n\n\n\n\n\\section{Affine charts on $\\bbp^2$}\nThere is a natural cover of $\\bbp^2$ given by three open sets\n\\begin{align*}\n  \\bbp^2\n  &= \\set{[z : w : t] \\mid \\mbox{ not all } z,w,t \\mbox{ zero}} \\\\\n  &= \\set{[z : w : 1]} \\cup \\set{[z : 1 : t]} \\cup \\set{[1 : w : t]} \\\\\n  &=: U_t \\cup U_w \\cup U_z\n\\end{align*}\nWe can define charts on these as\n\\begin{align*}\n  \\varphi_z: U_z &\\longrightarrow \\bbc^2 \\\\\n  [1 : w : t] &\\longmapsto (w,t)\\\\\\\\\n  \\varphi_z: U_w &\\longrightarrow \\bbc^2 \\\\\n  [z : 1 : t] &\\longmapsto (z,t)\\\\\\\\\n  \\varphi_z: U_t &\\longrightarrow \\bbc^2 \\\\\n  [z : w : 1] &\\longmapsto (z,w)\n\\end{align*}\nA projective variety $\\conj{S_p}$ cut out by the polynomial $\\conj{p}(z,w,t)$ is a Riemann surface if and only if the affine varities $\\conj{S_p} \\cap U_t$, $\\conj{S_p} \\cap U_w$, and $\\conj{S_p} \\cap U_z$ are Riemann surfaces.\nThese are called \\emph{affine charts} on $\\conj{S_p}$.\n\nThe varieties\n$\\conj{S_p} \\cap U_t$, $\\conj{S_p} \\cap U_w$, $\\conj{S_p} \\cap U_z$\ncan be described as\n\\begin{align*}\n  \\conj{S_p} \\cap U_t\n  &= \\set{(z,w) \\mid \\conj{p}(z,w,1) = 0} \\\\\\\\\n  \\conj{S_p} \\cap U_w\n  &= \\set{(z,t) \\mid \\conj{p}(z,1,t) = 0} \\\\\\\\\n  \\conj{S_p} \\cap U_z\n  &= \\set{(w,t) \\mid \\conj{p}(1,w,t) = 0}\n\\end{align*}\nIn order to check that a projective variety is a Riemann surface, we first break the variety into affine charts, and then check that each of the charts is a Riemann surface using the Jacobian.\n\n\n\n\n\n\n\n\n\n\n\n\\section{Jacobian}\n\\begin{theorem}\n  The affine variety $S = \\set{(z,w) : p(z,w) = 0} \\subseteq \\bbc^2$ is a Riemann surface if the Jacobian, defined as\n  \\begin{align*}\n    J(z,w) := \\begin{bmatrix} \\dfrac{\\partial p}{\\partial z} & \\dfrac{\\partial p}{\\partial w} \\end{bmatrix}\n  \\end{align*}\n  does not vanish, at all points $(z,w)$ in $S$.\n\\end{theorem}\n\\begin{proof}[Proof]\n  The reason is essentially that if at $(z,w)$, we have $\\dfrac{\\partial p}{\\partial z} \\neq 0$ then projection onto the $w$ coordinate locally defines a chart around $(z,w)$.\n  Similarly, if at $(z,w)$, we have $\\dfrac{\\partial p}{\\partial w} \\neq 0$ then projection onto the $z$ coordinate locally defines a chart around $(z,w)$.\n  If both are non-zero then both charts are valid and the deritvatives of transition functions are given by the rational functions\n  \\begin{align*}\n    \\left(\\frac{\\partial p}{\\partial w}\\right) \\cdot \\left(\\frac{\\partial p}{\\partial z}\\right)^{-1}\n  \\end{align*}\n  which are complex differentiable as the denominator is non-zero.\n\\end{proof}\n\n\\begin{ex}\n  The polynomial $z^2 - q(w)$ has Jacobian $\\begin{bmatrix} 2z & -q'(w) \\end{bmatrix}$. The Jacobian vanishes 0 precisely when $z = 0$ and $q'(w) = 0$. For this to be true for a point on the curve, $z=0 \\implies q(w) = 0$. Both $q(w) = 0 $ and $q'(w) = 0$ implies that $w$ is a repeated root of $q$.\n  Thus the corresponding variety is a Riemann surface if $q(w)$ has no repeated roots.\n\\end{ex}\n\n\\begin{ex}[Fermat]\n  For the projective variety cut out by $\\conj{p}(z,w,t) = z^p + w^p - t^p$, the three affine charts are given by\n  \\begin{align*}\n    z^p + w^p - 1  &&& \\begin{bmatrix} pz^{p-1} & pw^{p-1} \\end{bmatrix}\\\\\n    z^p + 1 - t^p &&& \\begin{bmatrix} pz^{p-1} & pt^{p-1} \\end{bmatrix}\\\\\n    1 + w^p - t^p &&& \\begin{bmatrix} pw^{p-1} & pt^{p-1} \\end{bmatrix}\n  \\end{align*}\n  The Jacobians vanish at $(0,0)$ but these points are not on the affine varities.\n\\end{ex}\n\n\\begin{ex}[Elliptic curves]\n  The equation $z^2 = w^3 + w$ has homogenization $\\conj{p}(z,w,t) = z^2 t - w^3 - w t^2$.\n  In the three charts this polynomial and the Jacobians become\n  \\begin{align*}\n    z^2  - w^3 - w  &&& \\begin{bmatrix} 2z & -3w^2 - 1 \\end{bmatrix}\\\\\n    z^2 t - 1 - t^2 &&& \\begin{bmatrix} 2zt & z^2 - 2t \\end{bmatrix}\\\\\n    t - w^3 - w t^2 &&& \\begin{bmatrix} 1 - 2wt & -3w^2 - t^2 \\end{bmatrix}\n  \\end{align*}\n  It is easy to see that all the Jacobians do not vanish anywhere on the varieties.\n\\end{ex}\n\n\\begin{ex}[Hyperelliptic curves]\n  The equation $z^2 = w^4 + w$ has homogenization $\\conj{p}(z,w,t) = z^2 t^2 - w^3 - w t^3$.\n  In the three charts this polynomial and the Jacobians become\n  \\begin{align*}\n    z^2  - w^4 - w  &&& \\begin{bmatrix} 2z & -4w^3 - 1 \\end{bmatrix}\\\\\n    z^2 t^2 - 1 - t^3 &&& \\begin{bmatrix} 2zt^2 & 2z^2t - 3t^2 \\end{bmatrix}\\\\\n    t^2 - w^3 - w t^3 &&& \\begin{bmatrix} 2t - 3wt^2 & -3w^2 - t^2 \\end{bmatrix}\n  \\end{align*}\n  In this case, the third Jacobian vanishes at the point $(0,0)$ which is on the curve, and hence our original projective variety is singular at the point at $\\infty$.\n\\end{ex}\n\nIt is possible to remove singularities of hyperelliptic curves ($z^2 = q(w)$ with $\\deg q > 3$) by putting charts at $\\infty$ artificially.\nThe resulting Riemann surface has genus $\\left \\lfloor{\\dfrac{\\deg q - 1}{2}}\\right \\rfloor $. See \\\\ \\url{https://en.wikipedia.org/wiki/Hyperelliptic_curve#Genus_of_the_curve}.\n\n\\end{document}\n", "meta": {"hexsha": "44775890c3f2882cb5a03fc945c20b587b54486c", "size": 6779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PSet05.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": "PSet05.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": "PSet05.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": 42.9050632911, "max_line_length": 299, "alphanum_fraction": 0.6433102227, "num_tokens": 2491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.6605324700341095}}
{"text": "\n\\subsection{Functions and brackets}\n\n\\subsubsection{Functions (or maps)}\n\nFunctions take other terms, and are themselves terms. For example if we wanted to know if someone can legally drive in a specific country, we could use:\n\n\\(P(you,age(UK))\\)\n\nA function may not be able to produce an output for all inputs. For examples \\(age(green)\\) has no interpretation.\n\nFunctions can also take different numbers of inputs. Constants, such as “you” and “UK” can be shown as functions with \\(0\\) inputs. As a result we could instead write:\n\n\\(P(you(),age(UK()))\\)\n\nWe generally denote functions with a lower case letter, so would instead write:\n\n\\(P(y(),a(b()))\\)\n\nFunctions are also called maps.\n\n", "meta": {"hexsha": "749c8f7eca2b09eb277965ccb355753a0209dba9", "size": 691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/01-03-functions.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/preteriteLogic/01-03-functions.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/preteriteLogic/01-03-functions.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4090909091, "max_line_length": 167, "alphanum_fraction": 0.7351664255, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.660487097125979}}
{"text": "\\problemname{Counting Greedily Increasing Supersequences}\nGiven a permutation $A = (a_1, a_2, \\dots, a_N)$ of the integers $1, 2, \\dots, N$, we define the \\emph{greedily increasing subsequence} (GIS) in the following way.\n\nLet $g_1 = a_1$. For every $i > 1$, let $g_i$ be the leftmost integer in $A$ that is strictly larger than $g_{i-1}$.\nIf for a given $i$ there is no such integer, we say that the GIS of the sequence is the sequence $(g_1, g_2, ..., g_{i - 1})$.\n\nFor example, consider the permutation $(2, 3, 1, 5, 4, 7, 6)$.\nFirst, we have $g_1 = 2$.\nThe leftmost integer larger than $2$ is $3$, so $g_2 = 3$.\nThe leftmost integer larger than $3$ is $5$ ($1$ is too small), so $g_3 = 5$.\nFinally, $g_4 = 7$.\nThus, the GIS of $(2, 3, 1, 5, 4, 7, 6)$ is $(2, 3, 5, 7)$.\n\nGiven a sequence $G = (g_1, g_2, \\dots, g_L)$, how many permutations $A$ of the integers $1, 2, \\dots, N$ have $G$ as its GIS?\n\n\\section*{Input}\nThe first line of input contains the integers $1 \\le N \\le 10^6$, the number of elements of the permutation $A$,\nand $1 \\le L \\le 10^6$, the length of the sequence $G$.\n\nThe next line contains $L$ positive integers between $1$ and $N$, the elements $g_1, \\dots, g_L$ of the sequence $G$.\n\n\\section*{Output}\nOutput a single integer: the number of $N$-element permutations having the given sequence as its GIS.\nSince this number may be large, output it modulo the prime number $10^9 + 7$.\n", "meta": {"hexsha": "c7ebef41c382af84fd1b4527dd6eaa991858631c", "size": 1407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "countinggis/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": "countinggis/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": "countinggis/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": 56.28, "max_line_length": 163, "alphanum_fraction": 0.6730632552, "num_tokens": 499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.7826624890918021, "lm_q1q2_score": 0.6604850537887872}}
{"text": "\\chapter{Combining Models}\n\\section{Introduction}\n\\begin{description}\n\t\\item[\\textbf{committees}] Train $L$ different models and then make predictions using the average of the predictions made by each model.\n\t\\item[\\textbf{boosting}] Train multiple models in sequence in which the error function used to train a particular model depends on the performance of the previous models.\n\t\\item[\\textbf{decision trees}] Different models are responsible for making predictions in different regions of input space.\n\t\\item[\\textbf{mixtures of experts}] Models are viewed as mixture distributions in which the component densities,as well as the mixing coefficients,are conditioned on the input variables.\n\t\\begin{align}\n\tp(t|\\vec{x})=\\sum\\limits_{k=1}^{K}\\pi_k(\\vec{x})p(t|\\vec{x},k)\n\t\\end{align}\n\tin which $\\pi_k(\\vec{x})=p(k|\\vec{x})$ represents the input-dependent mixing coefficients,and $k$ indexes the model.\n\\end{description}\n\n\\section{Bayesian Model Averaging}\nIn Bayesian model averaging the whole data set is generated by a single model.By contrast,when we combine multiple models,we see that different data points within the data set can potentially be generated from different values of the latent variable $\\vec{z}$ and hence by different components.\n\n\\section{Committees}\nThe simplest way to construct a committee is to average the predictions of a set of individual models,to cancel the contribution arising from variance and bias.\n\n\\textbf{Bootstrap} data to introduce variability between the different models within the committee.Suppose we generate $M$ bootstrap data sets\n\\begin{align}\ny_{COM}(\\vec{x})=\\dfrac{1}{M}\\sum\\limits_{m=1}^{M}y_m(\\vec{x})\n\\end{align}\nwhere $m=1,...,M$.This procedure is known as \\textbf{bootstrap aggregation} or \\textbf{bagging}.\n\n\\section{Boosting}\nHere we describe the most widely used form of boosting algorithm:\\textbf{AdaBoost},short for 'adaptive boosting'.The base classifiers are known as \\textbf{weak learners} and are trained in \\textbf{sequence} using a \\textbf{weighted form of the data set} in which the weighting coefficient associated with each data point depends on the performance of the previous classifiers.\n\nConsider a two-class classification problem,in which the training data comprises input vectors $\\vec{x}_1,...,\\vec{x}_N$ along with corresponding binary target variables $t_1,...,t_N$ where $t_n\\in \\{-1,1\\}$.Each data point is given an associated weighting parameter $w_n$,initially set $1/N$ for all.A base classifier function $y(\\vec{x})\\in \\{-1,1\\}$\n\\begin{SCfigure*}\n\t\\caption{Shematic illustration of boosting framework}\n\t\\includegraphics{prml/Figure14.1}\n\\end{SCfigure*}\n\n\\begin{algorithm}[H]\n\t\\caption{\\color{red}{AdaBoost}}\n\t\\label{algo:AdaBoost}\n\t\\DontPrintSemicolon % Some LaTeX compilers require you to use \\dontprintsemicolon instead \n\t\\KwIn{A set $\\vec{X} = \\{\\vec{x}_1, \\vec{x}_2, \\ldots, \\vec{x}_N\\}$,$\\{t_1,...,t_N\\}$}\n\t\\KwOut{$y(\\vec{x})$,.}\n\t1. Initialize the data weighting coefficients $\\{w_n\\}$ by setting $w_n^{1}=1/N$ for $n=1,...,N$. \\;\n\t2. \\For{$m=1,...,N$}{\n\t\t(a) Fit a classifier $y_m(\\vec{x})$ to the training data by minimizing the weighted error function\n\t\t\\begin{align}\n\t\tJ_m=\\sum\\limits_{n=1}^{N}w_n^{(m)}I(y_m(\\vec{x}_n)\\neq t_n)\n\t\t\\end{align}\n\t\twhere $I(y_m(\\vec{x}_n)\\neq t_n)$ is the indicator function and equals $1$ when $y_m(\\vec{x}_n)= t_n$ and $0$ otherwise. \\;\n\t\t(b) Evaluate  the quantities\n\t\t\\begin{align}\n\t\t\\epsilon_m=\\dfrac{\\sum_{n=1}^{N}w_n^{(m)}I(y_m(\\vec{x}_n)\\neq t_n)}{\\sum_{n=1}^{N}w_n^{(m)}}\n\t\t\\end{align}\n\t\tand then use these to evaluate\n\t\t\\begin{align}\n\t\t\\alpha_m=\\ln\\{\\dfrac{1-\\epsilon_m}{\\epsilon_m}\\}.\n\t\t\\end{align}\n\t\t\\;\n\t\t(c) Update the data weighting coefficients\n\t\t\\begin{align}\n\t\tw_n^{(m+1)}=w_n^{(m)}\\exp\\{\\alpha_m I(y_m(\\vec{x}_m)\\neq t_n)\\}\n\t\t\\end{align}\n\t}\n\t3. Make predictions using the final model,which is given by\n\t\\begin{align}\n\tY_M(\\vec{x})=sign(\\sum_{m=1}^{M}\\alpha_m y_m(\\vec{x}))\n\t\\end{align}\n\t\t\n\\end{algorithm}\n\n\\subsection{Minimizing exponential error}\nConsider the exponential error function defined by\n\\begin{align}\nE=\\sum_{n=1}^{N}\\exp\\{-t_n f_m(\\vec{x}_n)\\}\n\\end{align}\nwhere $f_m(\\vec{x})$ is a classifier defined in terms of a linear combination of base classifiers $y_l(\\vec{x})$ of the form\n\\begin{align}\nf_m(\\vec{x})=\\dfrac{1}{2}\\sum_{l=1}^{m}\\alpha_l y_l(\\vec{x})\n\\end{align}\nand $t_n\\in \\{-1,1\\}$ are the training set target values.Our goal is to minimize $E$ with respect to the weighting coefficients $\\alpha_l$ and parameters of the base classifiers $y_l(\\vec{x})$.\n\nSeparating off the contribution from base classifier $y_m(\\vec{x})$,\n\\begin{align}\nE&=\\sum_{n=1}^{N}\\exp\\{-t_n f_m(\\vec{x}_n)\\} \\\\\n&=\\sum_{n=1}^{N}\\exp\\{-t_n \\dfrac{1}{2}\\sum_{l=1}^{m}\\alpha_l y_l(\\vec{x}) \\} \\\\\n&=\\sum_{n=1}^{N}\\exp\\{-t_n f_{m-1}(\\vec{x}_n)-\\dfrac{1}{2}t_n \\alpha_m y_m(\\vec{x}_n)\\} \\\\\n&=\\sum_{n=1}^{N}w_n^{(m)}\\exp\\{-\\dfrac{1}{2}t_n \\alpha_m y_m(\\vec{x}_n)\\}\n\\end{align}\nwhere the coefficients $w_n^{(m)}=\\exp\\{-t_n f_{m-1}(\\vec{x}_n)\\}$ can be viewed as constants because we are optimizing only $\\alpha_m$ and $y_m(\\vec{x})$.Denote by $\\mathcal{T}_m$ the set of data points correctly classified by $y_m(\\vec{x})$ and misclassified points by $\\mathcal{M}_m$,then we in turn rewrite the error function\n\\begin{align}\nE &=e^{-\\alpha_m/2}\\sum_{n\\in\\mathcal{T}_m}w_n^{(m)}+e^{\\alpha_m/2}\\sum_{n\\in\\mathcal{M}_m}w_n^{(m)} \\\\\n&=(e^{\\alpha_m/2}-e^{-\\alpha_m/2})\\sum_{n=1}^{N}w_n^{(m)}I(y_m(\\vec{x}_n)\\neq t_n)+e^{-\\alpha_m/2}\\sum_{n=1}^{N}w_n^{(m)}\n\\end{align}\nThen we can minimize this with respect to $y_m(\\vec{x}_n)$ and $\\alpha_m$.\n\\begin{align}\n\\because w_n^{(m)}=\\exp\\{-t_n f_{m-1}(\\vec{x}_n)\\} \\\\\n\\therefore w_n^{(m+1)}=\\exp\\{-t_n f_{m}(\\vec{x}_n)\\} \\\\\n\\therefore w_n^{(m+1)}=w_n^{(m)}\\exp\\{-\\dfrac{1}{2}t_n\\alpha_m y_m(\\vec{x}_n)\\}\n\\end{align}\nMaking use of the fact that\n\\begin{align}\nt_n y_m(\\vec{x})=1-2I(y_m(\\vec{x}_n)\\neq t_n)\n\\end{align}\nwe see updates at the next iteration\n\\begin{align}\nw_n^{(m+1)}=w_n^{(m)}\\exp(-\\alpha_m/2)\\exp\\{\\alpha_m I(y_m(\\vec{x}_n)\\neq t_n)\\}\n\\end{align}\nBecause the term $\\exp(-\\alpha_m/2)$ is independent of $n$,so can be discarded.\n\n\\subsection{Error functions for boosting}\n\n\n\n\\section{Tree-based Models}\n\n\n\n\n\n\n\\section{Conditional Mixture Models}\n\n\n\n\n\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": "fda9ce9b724d0fa2b78358d081d4414500115a2c", "size": 6252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Combining 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/Combining 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/Combining 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": 42.2432432432, "max_line_length": 376, "alphanum_fraction": 0.7005758157, "num_tokens": 2075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.7826624890918021, "lm_q1q2_score": 0.6604850507160205}}
{"text": "% !TEX root = ../main.tex\n% chktex-file 21\n% chktex-file 46\n\\section{Effects of Coarsening}%\n\\label{sec:cons}\n\nWe have just seen how to compute a coarsened graph $G_c$ via the REC algorithm.\nWhat remains to be answered is how coarsening affects the performance of graph algorithms when $G_c$ is used as a proxy for the original graph $G$.\nIn the first step we will present a graph similarity measure.\nUsing this measure we will then put bounds on the dissimilarity of $G$ and $G_c$.\nFinally we will use those bounds to analyze the influence of coarsening on the performance of the \\textit{spectral clustering algorithm}.\nThe results described in this section were found by \\citet{Loukas2018}.\n\n\\subsection{Restricted Spectral Similarity}%\n\\label{sec:cons:rss}\n\nTo compare a graph $G$ with its coarsened version $G_c$ we will use the notion of \\textit{spectral similarity}.\nAs we have seen before, $G$ can be viewed as an operator that transforms an input signal $x \\in \\mathbb{R}^N$.\nWe described this transform in terms of the graph's Laplacian $L$,\nmore specifically in terms of the Laplacian's eigenbasis ${\\{ u_k \\}}_{k = 1}^{N}$ and spectrum ${\\{ \\lambda_k \\}}_{k = 1}^{N}$.\nSimilarly the coarsened graph $G_c$ can be described in terms of its Laplacian $L_c$.\nSince $L \\in \\mathbb{R}^{N \\times N}$ and $L_c \\in \\mathbb{R}^{n \\times n}$ act on signal spaces of different dimensionality, they cannot be compared directly however.\nInstead we compare $L$ with $\\widetilde{L} = C^{\\top} L_c C$, the upsampled version of $L_c$.\nWe say $\\widetilde{L}$ is an \\textit{$\\varepsilon$-approximation} of $L$ iff.\\  $\\widetilde{L}$ scales the eigenvectors $u_k$ of $L$ by a factor of roughly $\\lambda_k$ in the direction of $u_k$:\n\\begin{wrapfigure}{r}{0.25\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{gfx/cons/rss.pdf}\n\t\\caption{See \\cref{eq:cons:rss}.}\\label{fig:cons:rss}\n\\end{wrapfigure}\n\\begin{align}\n\t\\forall k \\leq K:\\ (1 - \\varepsilon) \\underbrace{u_k^{\\top} L u_k}_{\\lambda_k} \\leq u_k^{\\top} \\widetilde{L} u_k \\leq (1 + \\varepsilon) \\underbrace{u_k^{\\top} L u_k}_{\\lambda_k} \\text{ with } \\varepsilon \\geq 0\\label{eq:cons:rss}\n\\end{align}\nThe reason \\cref{eq:cons:rss} is only quantified for the first $K$ eigenvectors of $L$ is, that $\\text{rank}(L) = N - c > n - c = \\text{rank}(\\widetilde{L})$;\ni.e.\\ $\\widetilde{L}$ has a higher dimensional null space\\footnote{%\n\tHere $c$ denotes the number of connected components of $G$.\n\tThey reduce the rank since $\\lambda_1 = \\cdots = \\lambda_c = 0$.\n}.\nThus the inequality in \\cref{eq:cons:rss} cannot hold for a signal $x$ that is in the null space of $\\widetilde{L}$ but not in that of $L$.\nTherefore the similarity condition is restricted to the first $K$ eigenvectors, as they represent the most important ``low-frequency'' components of $G$.\nThis restricted condition is called \\textit{restricted spectral similarity} (RSS).\n\nThe choice of $K$ in RSS depends on the level of detail that should be considered when comparing $L$ and $\\widetilde{L}$.\nIf $G$ has $c'$ clusters, i.e.\\ connected subgraphs with relatively few or even no edges going out of it, a choice of $K = c'$ is reasonable.\nThat way RSS checks whether the clusters of $G$ are preserved in the coarsened graph $G_c$ and how much the connectedness between the clusters changes.\nDetails like the connections within clusters on the other hand do not have a strong influence on the RSS similarity if $K = c'$, since they are described by the ``high-frequency'' eigenvectors $u_\\ell$ of $L$ where $\\ell > K$.\n\n\\subsection{Bounding REC via RSS}%\n\\label{sec:cons:bound}\n\nNow we will use RSS to bound the eigenvalue distortion caused by a single application of the REC coarsening algorithm.\nIt can be shown that the probability of satisfying the RSS condition for a single eigenvector $u_k$ with a sufficiently small eigenvalue $\\lambda_k$ is lower-bounded by\n\\begin{align}\n\t\\forall \\lambda_k \\leq \\frac{\\nu_\\text{min}}{4}:\\ P\\mkern-2mu\\left((1 - \\varepsilon) \\lambda_k \\leq u_k^{\\top} \\widetilde{L} u_k \\leq (1 + \\varepsilon) \\lambda_k\\right)\n\t\\geq 1 - \\frac{r \\nu_{\\text{max}}}{2 \\varepsilon d_{\\text{avg}}} \\left(1 + \\frac{3 - 4 \\lambda_k}{\\nu_{\\text{min}}}\\right)\\label{eq:cons:bound}\n\\end{align}\nwhere $r = \\frac{N - n}{N}$ is the graph reduction ratio, $d_{\\text{avg}} = \\frac{1}{N} \\sum_{v_i \\in \\mathcal{V}} d_i$ is the average weighted vertex degree and $\\nu_{\\text{min}}$, $\\nu_{\\text{max}}$ are the minimum and maximum of the neighborhood weights ${\\{ d_i + d_j - w_{i j}  \\}}_{e_{i j} \\in \\mathcal{E}}$.\nFor a formal proof of this bound we refer to \\citet[Suppl.~2]{Loukas2018}.\nHere we will instead give an intuition for its key statements:\n\\begin{enumerate}[label=\\textbf{\\arabic*.}]\n\t\\item \\textbf{$\\varepsilon$-term:}\n\t\tUnsurprisingly the RSS bound is inversely proportional to $\\varepsilon$.\n\t\tRelaxing the RSS bound makes it is more likely to be satisfied.\n\t\\item \\textbf{$r$-term:}\n\t\tThe RSS bound is linearly dependent on the reduction ratio $r$.\n\t\tThe more the graph size is reduced, the smaller the probability of satisfying the bound.\n\t\\item \\textbf{$\\lambda_k / \\nu_{\\text{min}}$-term:}\n\t\tThe bound is also linearly dependent on the eigenvalue $\\lambda_k$.\n\t\tAdditionally, since $\\lambda_k$ is proportional to the arbitrarily large weights $w_{i j}$, it is normalized via $\\nu_{\\text{min}}$.\n\t\tTo get an intuition for the influence of the eigenvalue on the RSS bound, two opposing effects have to be considered:\n\t\t\\begin{enumerate}[label=(\\roman*)] % chktex 36\n\t\t\t\\item \\textbf{Negative effect:}\\label{itm:cons:bound:neg}\n\t\t\t\tThe eigenvector $u_k$ for a large $\\lambda_k$ represents a ``high-frequency'' component of $G$ that is more easily distorted by coarsening than a smooth ``low-frequency'' eigenvector $u_\\ell$ with eigenvalue $\\lambda_{\\ell \\ll k}$ (see~\\cref{fig:sgt:graphFourier}).\n\t\t\t\tFormally this means that the approximated eigenvector $\\widetilde{u}_k := \\Pi u_k$ has a lower overlap with the original $u_k$ than $\\widetilde{u}_\\ell$ has with its original $u_\\ell$, i.e.\\ $\\langle u_k, \\widetilde{u}_k \\rangle < \\langle u_\\ell, \\widetilde{u}_\\ell \\rangle$.\n\t\t\t\t$\\pmb{\\Rightarrow}$ This effect causes the RSS probability bound to \\textit{decrease} with increasing, more easily distorted, eigenvalues.\n\t\t\t\\item \\textbf{Positive effect:}\\label{itm:cons:bound:pos}\n\t\t\t\tRecall that $u_k^\\top \\widetilde{L} u_k = \\widetilde{u}_k^\\top L \\widetilde{u}_k$ and $\\lambda_k = u_k^\\top L u_k$.\n\t\t\t\tRSS checks whether $L$ transforms $u_k$ similarly to its approximate $\\widetilde{u}_k$.\n\t\t\t\tWhen writing the latter transform in terms of $L$'s eigenbasis we get $\\widetilde{u}_k^\\top L \\widetilde{u}_k = \\sum_{m = 1}^N \\lambda_m \\langle u_m, \\widetilde{u}_k \\rangle^2$.\n\t\t\t\tFor large eigenvalues $\\lambda_k$ the self-overlap $\\langle u_k, \\widetilde{u}_k \\rangle^2$ is weighted more strongly than the overlap with low-valued eigenvectors $u_{\\ell \\ll k}$.\n\t\t\t\t$\\pmb{\\Rightarrow}$ This effect causes the RSS probability bound to \\textit{increase} with increasing, more strongly weighted, eigenvalues.\n\t\t\\end{enumerate}\n\t\tAs long as the eigenvector distortion described in~\\ref{itm:cons:bound:neg} is not too large ($\\lambda_k \\leq \\frac{\\nu_\\text{min}}{4}$), the positive effect described in~\\ref{itm:cons:bound:pos} dominates, i.e.\\ $\\lambda_k \\langle u_k, \\widetilde{u}_k \\rangle^2 > \\lambda_\\ell \\langle u_\\ell, \\widetilde{u}_\\ell \\rangle^2$ for $k \\gg \\ell$ despite $\\langle u_k, \\widetilde{u}_k \\rangle < \\langle u_\\ell, \\widetilde{u}_\\ell \\rangle$.\n\t\tThis is why the RSS probability bound increases with increasing $\\lambda_k$'s, up to the point where they become too large and the bound becomes undefined.\n\t\tThis can be seen in \\cref{fig:cons:example:regular}.\n\t\tIt shows the RSS bound for a $20$-regular graph, which is defined up to $\\lambda_{20}$, after that the eigenvector distortion becomes too large.\n\t\\item \\textbf{$\\nu_{\\text{max}}/d_{\\text{avg}}$-term:}\n\t\tFinally the bound also depends on the quotient between the maximum weight $\\nu_{\\text{max}}$ within an edge neighborhood $\\mathcal{N}_{i j}$ and the average weighted vertex degree $d_{\\text{avg}}$.\n\t\tThis quotient can be interpreted as a measure of how much the weight distribution within $G$ varies when comparing local clusters with the global average.\n\t\tRegular graphs minimize this quotient, as all their local clusters have the same weight.\n\t\tThe key implication is that the distortion of the graph Laplacian caused by coarsening is proportional to the regularity of the coarsened graph, i.e.\\ coarsening distorts regular graphs less than highly irregular graphs.\n\t\tThis can be seen in \\crefrange{fig:cons:example:regular}{fig:cons:example:bunny} for three increasingly irregular example graphs.\n\\end{enumerate}\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{subfigure}{0.33\\textwidth}\n\t\t\\includegraphics[width=\\linewidth]{gfx/cons/example/regular.png}\n\t\t\\caption{Regular graph ($d = 20$)}\\label{fig:cons:example:regular}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.33\\textwidth}\n\t\t\\includegraphics[width=\\linewidth]{gfx/cons/example/yeast.png}\n\t\t\\caption{Yeast (protein network)}\\label{fig:cons:example:yeast}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.33\\textwidth}\n\t\t\\includegraphics[width=\\linewidth]{gfx/cons/example/bunny.png}\n\t\t\\caption{Bunny (point cloud)}\\label{fig:cons:example:bunny}\n\t\\end{subfigure}\n\t\\caption{%\n\t\tComparison of the RSS-bound and the actual error constants $\\varepsilon$ for the eigenvectors of multiple coarsened graphs ($r = 0.4$).\n\t\tConfidence bounds for $p_s \\in \\{0.5, 0.7\\}$ are shown.\n\t\t\\source{Loukas2018}\n\t}\\label{fig:cons:example}\n\\end{figure}\n\n\\vspace{-1em}%\n\\subsection{Implications for Spectral Clustering}%\n\\label{sec:cons:sc}\n\nLastly we will evaluate the effect coarsening has on the performance of the \\textit{spectral clustering algorithm}~\\cite{Luxburg2007}.\nAs we have seen in \\cref{sec:sgt:spectrum}, the positive and negative vertex signal strengths of the Fiedler vector $u_2$ describe a $2$-clustering of the graph $G$ where the cluster boundary can be interpreted as a heat-flow bottleneck.\nThis idea can be extended to the $K$-clustering scenario by considering the first $K$ eigenvectors $U_K = \\{ u_2, \\dots, u_K \\}$ instead of only looking at $u_2$.\nTo obtain a vertex clustering, the vertex basis vectors ${\\{ b_i \\}}_{v_i \\in \\mathcal{V}}$ are projected onto the spectral basis $U_K$, i.e.\\ the Fourier transform $\\widehat{b}_i = {(\\langle u_2, b_i \\rangle, \\dots, \\langle u_K, b_i \\rangle)}^\\top$ is computed for each vertex.\nAfterwards regular $K$-means clustering is performed on the Fourier-transformed vertex basis ${\\{\\,\\widehat{b}_i \\}}_{v_i \\in \\mathcal{V}}$ to get the clustering $S = (S_1, \\dots, S_K)$ with $S_k \\subseteq \\mathcal{V}$.\n\nFor large graphs $G$, computing the eigenbasis $U_K$ of $L \\in \\mathbb{R}^{N \\times N}$ is expensive.\nTo speed this up, one can compute the lower dimensional eigenbasis $\\widetilde{U}_K = \\{ C^\\top u'_2, \\dots, C^\\top u'_K \\}$ instead, where $u'_k$ are the eigenvectors of the coarsened Laplacian $L_c \\in \\mathbb{R}^{n \\times n}$.\nSince we want a clustering on the original vertex set $\\mathcal{V}$, not the coarsened vertices $\\mathcal{V}_c$, the coarse eigenvectors $u'_k \\in \\mathbb{R}^n$ need to be upsampled to $C^\\top u'_k \\in \\mathbb{R}^N$.\nIn total this is often cheaper than computing $U_K$ directly.\n\nThe question now is how much worse the spectral clustering results become when the vertex basis vectors ${\\{ b_i \\}}_{v_i \\in \\mathcal{V}}$ are projected onto $\\widetilde{U}_K$ instead of $U_K$.\nTo answer this question, it was shown by \\citet[Coroll.~5.1]{Loukas2018} that the RSS bound also implies a bound on the absolute spectral clustering error;\ntherefore the intuitions we discussed in \\cref{sec:cons:bound} also hold for spectral clustering.\nMost notably this implies that the absolute clustering error introduced by coarsening depends on the regularity of the graph, i.e.\\ regular graphs are best suited to speed up spectral clustering via coarsening.\n\\Cref{fig:cons:mnist} shows the relative performance decrease caused by coarsening for an exemplary regular graph.\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\twidth=0.5\\linewidth,\n\t\t\theight=0.3\\linewidth,\n\t\t\txmin=8, xmax=42,\n\t\t\tymin=0, ymax=0.04,\n\t\t\txtick={10,20,30,40},\n\t\t\txticklabels={10\\%,20\\%,30\\%,40\\%},\n\t\t\txtick pos=bottom,\n\t\t\tytick={0,0.01,0.02,0.03,0.04},\n\t\t\tyticklabels={0\\%,1\\%,2\\%,3\\%,4\\%},\n\t\t\tytick pos=left,\n\t\t\txlabel={reduction ratio $r$},\n\t\t\tylabel={relative error},\n\t\t\tymajorgrids=true,\n\t\t\tlabel style={font=\\tiny},\n\t\t\ttick label style={font=\\tiny},\n\t\t\ttick align=outside,\n\t\t\ty tick label style={/pgf/number format/.cd, fixed, scaled ticks=false, precision=2, /tikz/.cd}\n\t\t]\n\t\t\t\\addplot [mark=*, color=blau] table [x=r, y=ref10, col sep=comma] {data/cons/mnist.csv};\n\t\t\\end{axis}\n\t\\end{tikzpicture}%\n\t\\quad\\includegraphics[width=0.29\\linewidth]{gfx/cons/mnistGraph.png}\n\t\\caption{%\n\t\t(Left)~Relative spectral clustering error on a coarsened $12$-nearest neighbor similarity graph for $N=1000$ images from the MNIST dataset.\n\t\tOnly images of the digits 0 to 4 were sampled, thus $K = 5$.\n\t\t(Right)~The full MNIST similarity graph $G$ with vertex colors indicating the clustering obtained via $\\widetilde{U}_K$. Edges that are contracted in $G_c$ are shown in red.\n\t\t\\source{Loukas2018}\n\t}\\label{fig:cons:mnist}\n\\end{figure}\n% \\vspace{-0.7cm}\n", "meta": {"hexsha": "dd85f14f4573dcdbfeefdb58f717fc6534672745", "size": 13369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/content/chapter-consequences.tex", "max_stars_repo_name": "Cortys/ml-seminar", "max_stars_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/content/chapter-consequences.tex", "max_issues_repo_name": "Cortys/ml-seminar", "max_issues_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/content/chapter-consequences.tex", "max_forks_repo_name": "Cortys/ml-seminar", "max_forks_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.5773809524, "max_line_length": 435, "alphanum_fraction": 0.730795123, "num_tokens": 4145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8438951084436076, "lm_q1q2_score": 0.6604850461068701}}
{"text": "\\chapter{Acoustic Tubes}\\label{ch:brass}\n\nThe dynamics of woodwind and brass instruments is based on wave propagation in acoustic tubes. Although the physical processes that generate the sound are fundamentally different from those in strings, the underlying models have many similarities. The main difference between acoustic tubes and the (ideal) strings, is that tubes have a varying cross-sectional area, causing wave dispersion and greatly influencing the modal frequencies and modal shapes present in the system.\n\nIn this work, planar wave propagation is assumed (rather than spherical), such that the behaviour of the systems can be approximated using 1D systems. Although higher-dimensional models might better capture some physical effects (see e.g. \\cite{Kemp2002}), 1D systems already show good agreement between model and measurement \\cite{Eveno2012}. Moreover, looking towards real-time implementation of these models, the choice to simplify to 1D has been made due to the low relative computational cost. \n\nThis chapter first presents Webster's equation, which extends the 1D wave equation presented in Section \\ref{sec:1DWave} by introducing a spatially varying cross-section. Although not used for the contributions in Part \\ref{part:contributions}, Webster's equation forms a good basis for the second part of this chapter, which decomposes Webster's equation into a system of two coupled first-order PDEs. This has been used to model the trombone in paper \\citeP[H].\n\n\\section{Webster's equation}\\label{sec:webstersEq}\nFor an (axially symmetric) acoustic tube of length $L$ (in m), where the wavelengths of the frequencies at interest are much larger than the radius of the tube, one can simplify the system to be one-dimensional \\cite{Bilbao2018}. For low-amplitude vibrations, the air propagation in this tube can be described using \\textit{Webster}'s equation \\cite{Webster1919}\n\\begin{equation}\\label{eq:webstersPDE}\n    S\\partial_t^2\\Psi = c^2\\partial_x(S\\partial_x\\Psi),\n\\end{equation}\nwith \\textit{acoustic potential} $\\Psi = \\Psi(x,t)$ (in m$^2$/s), the cross-sectional area along the tube, or bore profile $S = S(x)$ (in m$^2$) and the speed of sound in air $c$ (in m/s). The state variable $\\Psi$ is defined for $t\\geq 0$ and $x \\in \\D$ where domain $\\D = [0, L]$. If $S(x)$ is constant, Eq. \\eqref{eq:webstersPDE} reduces to the 1D wave equation in Eq. \\eqref{eq:1DwavePDE}. This shows that for a cylindrical acoustic tube, the fundamental frequency is not affected by the cross-sectional area, but solely relies on length $L$ and wave speed $c$ according to Eq. \\eqref{eq:fundamentalFreq}. The acoustic potential can be related to pressure $p = p(x,t)$ (in Pa) and particle velocity $v = v(x,t)$ (in m/s) according to \\cite{Bilbao2018}\n\\begin{equation}\\label{eq:pressureVelocityWebster}\n    p = \\rho_0 \\pt \\Psi, \\qaq v = -\\px \\Psi,\n\\end{equation}\nwith air density $\\rho_0$ (in kg/m$^3$).\n\nThe interesting thing about the presence of a variable cross-section, is that it causes dispersive or scattering behaviour, especially at locations of high (spatial) variation of $S$. See Figure \\ref{fig:websterPropagation}. Contrary to frequency dispersion as happens in a stiff string (see Chapter \\ref{ch:stiffString}), all frequencies travel at the same speed, but some components of the wave get reflected due to the geometry of the tube.\n\n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$t = 1$ ms.\\label{fig:websterPropagation1}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/brass/websterPropagation1.eps}}\\hfill\n    \\subfloat[$t = 5$ ms.\\label{fig:websterPropagation2}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/brass/websterPropagation2.eps}}\\hfill\n    \\subfloat[$t = 8$ ms.\\label{fig:websterPropagation3}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/resonators/brass/websterPropagation3.eps}}\n    \\caption{Wave propagation and dispersion in an acoustic tube of varying cross-section (shown in grey) modelled by Webster's equation in Eq. \\eqref{eq:webstersPDE}. Positive acoustic potential $\\Psi$ is shown in red and negative in blue, which is also plotted for clarity. \\label{fig:websterPropagation}}\n\\end{figure}\n%test for git\n\n\\subsubsection{Boundary conditions}\nThe choices for boundary conditions in an acoustic tube are open and closed, defined as \\cite{Bilbao2018}\\footnote{The Dirichlet condition is identical to the one shown in Eq. \\eqref{eq:contDirichlet}, but is derived from $p(0, t) = p(L, t) = 0$ and the time-derivative has thus been kept here.}\n\\begin{subequations}\\label{eq:contBoundariesBrass}\n    \\begin{align}\n        \\partial_t\\Psi(0, t) &= 0, & \\partial_t\\Psi(L, t) &= 0, & &\\text{(Dirichlet, open)},\\label{eq:contDirichletBrass}\\\\\n        \\partial_x\\Psi(0, t) &= 0, & \\partial_x\\Psi(L, t) &= 0, & &\\text{(Neumann, closed)}\\label{eq:contNeumannBrass}.\n    \\end{align}\n\\end{subequations}\nThis might be slightly counter-intuitive when compared to the 1D wave equation, as ``closed\" might imply the ``fixed\" or Dirichlet boundary condition. The opposite can be intuitively shown by imagining a wave front with a positive acoustic potential (and thus positive pressure according to Eq. \\eqref{eq:pressureVelocityWebster}) moving through a tube and hitting a closed end. What reflects is also a wave front with a positive acoustic potential, i.e., the sign of the potential does not flip. This also happens using the free or Neumann condition for the 1D wave equation (see Figure \\ref{fig:boundaryCondsCont}).\nHere, the following boundaries are chosen\n\\begin{equation}\\label{eq:openClosed}\n    \\partial_x\\Psi(0, t) = 0, \\quad \\text{and} \\quad \\partial_t\\Psi(L, t) = 0,\n\\end{equation}\ni.e. closed at the left end and open at the right end.\n\n\\subsection{Discrete time}\nThe state variable is discretised to the grid function $\\Psi_l^n$ and is defined for $n\\in \\mathbb{N}^0$ and $l = \\{0, \\hdots, N\\}$, where $N$ is the number of intervals between the grid points.\nAs the cross-section is distributed in space, $S(x)$ needs to be discretised to a grid function as well, albeit only in space (as it is not time-varying). Following \\cite{Bilbao2018}, it is useful to introduce \\textit{interleaved grid points} at $l-1/2$ and $l+1/2$ for $S$ and are defined as \n\\begin{equation}\\label{eq:sHalf}\n    \\Sm = \\mxm S(x=lh), \\qaq \\Sp = \\mxp S(x=lh),\n\\end{equation}\nand approximate a `true' (possibly measured) bore profile $S(x)$ sampled at $x=lh$ with grid spacing $h$ (see Figure \\ref{fig:variableCrossSection}). Using these definitions, one can discretise Eq. \\eqref{eq:webstersPDE} to the following FD scheme \\cite{theBible}\\footnote{Notice that in \\cite{theBible}, Webster's equation is $\\Sbar_l \\delta_{tt}\\Psi^n_l = c^2\\dxp(\\Sm(\\dxm\\Psiln))$ but is identical to Eq. \\eqref{eq:discWebster}. This discretisation has been chosen for a more straightforward energy analysis in Section \\ref{sec:energyAnalysisWebster}.}\n\\begin{equation}\\label{eq:discWebster}\n    \\Sbar_l \\delta_{tt}\\Psi^n_l = c^2\\dxm\\left(\\Sp(\\dxp\\Psiln)\\right),\n\\end{equation}\nwhere\n\\begin{equation}\\label{eq:Sbar}\n    \\Sbar_l = \\mxp\\Sm = \\mxm\\Sp = \\mxx S(x=lh),\n\\end{equation}\nthe choice of which will become apparent in Section \\ref{sec:stabilityEnergyWebster}.\nThe right-hand side of the scheme contains an operator applied to two grid functions ($S$ and $\\Psi$) multiplied onto each other. In order to expand this, the product rule must be used. Recalling Eq. \\eqref{eq:productRule} and applying this to backwards spatial operators instead yields\n\\begin{equation}\n    \\dxm (u_l^nw_l^n) = (\\dxm u_l^n)(\\mxm w_l^n) + (\\mxm u_l^n)(\\dxm w_l^n).\n\\end{equation}\nUsing the product rule, the right-hand side of Eq. \\eqref{eq:discWebster} can be expanded to\n\\begin{equation*}\n    \\Sbar\\dtt\\Psiln = c^2\\left[(\\dxm \\Sp)(\\mxm (\\dxp \\Psiln)) + (\\mxm \\Sp)(\\dxm (\\dxp \\Psiln))\\right],\n\\end{equation*}\nand solving for $\\Psinp$ yields the following update equation (see Appendix \\ref{app:webstersUpdateEq}):\n\\begin{equation}\n    \\Psinp = 2(1-\\lambda^2)\\Psiln-\\Psinm+ \\frac{\\lambda^2\\Sp}{\\Sbar_l}\\Psilp + \\frac{\\lambda^2\\Sm}{\\Sbar_l}\\Psilm,\\label{eq:webstersUpdateEq}\n\\end{equation}\nwith \n\\begin{equation}\n    \\lambda = \\frac{ck}{h},\n\\end{equation}\nand similar to the 1D wave equation in Section \\ref{sec:1DWaveDisc} needs to abide\n\\begin{equation}\\label{eq:CFLwebster}\n    \\lambda \\leq 1,\n\\end{equation}\nin order for the scheme to be stable. See Section \\ref{sec:stabilityEnergyWebster} for a derivation. The number of grid points $N$ can then be calculated in the same way as for the 1D wave equation in Eq. \\eqref{eq:orderOfCalc}, and the stencil is similar to Figure \\ref{fig:stencil1DWave}.\n\nNotice that at the boundaries, Eq. \\eqref{eq:webstersUpdateEq} requires values of $S$ outside of the defined domain through its definition in Eq. \\eqref{eq:Sbar} (i.e., $S_{N+1/2}$ and $S_{-1/2}$). To solve this, one can set $\\Sbar_0 = S(0)$ and $\\Sbar_N = S(L)$ from which $S_{-1/2}$ and $S_{N+1/2}$ can be calculated according to\n\\begin{subequations}\n    \\begin{align}\n        \\Sbar_0 = \\frac{1}{2}(S_{1/2} + S_{-1/2}) \\ &\\Rightarrow \\ S_{-1/2} = 2\\Sbar_0 - S_{1/2},\\\\\n        \\Sbar_N = \\frac{1}{2}(S_{N+1/2} + S_{N-1/2}) \\ &\\Rightarrow \\ S_{N+1/2} = 2\\Sbar_N - S_{N-1/2}.\\label{eq:Snph}\n    \\end{align} \n\\end{subequations}\nAlthough these values will not be needed when discretising the boundary conditions in Eq. \\eqref{eq:contBoundariesBrass}, they will be useful at a later point.\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/resonators/brass/variableCrossSection.eps}\n    \\caption{Approximations to $S(x)$ used in Eq. \\eqref{eq:discWebster}. Dashed lines indicate the interleaved grid on which $S$ is sampled (Eq. \\eqref{eq:sHalf}) and solid lines indicate $\\Sbar$ which are averages of these (Eq. \\eqref{eq:Sbar}). \\label{fig:variableCrossSection}}\n\\end{figure}\n\n\n\\subsubsection{Boundary conditions}\nOne can discretise the continuous boundary conditions in Eq. \\eqref{eq:openClosed} (closed at $x=0$, open at $x=L$) using centred difference operators for higher accuracy\n\\begin{subequations}\\label{eq:discBoundariesBrass}\n    \\begin{align}\n        \\dxd\\Psi_0^n &= 0 \\quad \\Rightarrow \\quad\\Psi_{-1}^n = \\Psi_1^n ,\\quad \\!\\!\\!\\!\\!\\!&&\\text{(Neumann, closed)}, \\label{eq:closedLeftBrass}\\\\\n        \\dtd\\Psi_N^n &= 0\\quad\\Rightarrow \\quad \\Psi_N^n = 0, \\quad \\!\\!\\!\\!\\!\\!&&\\text{(Dirichlet, open)}\\label{eq:openRightBrass}.\n    \\end{align}\n\\end{subequations} \nAt the left boundary, Eq. \\eqref{eq:webstersUpdateEq} can be expanded to:\n\\begin{equation*}\n    \\begin{aligned}\n        \\Psi_0^{n+1} &= 2(1-\\lambda^2)\\Psi_0^n-\\Psi_0^{n-1}+ \\frac{\\lambda^2S_{1/2}}{\\bar S_0}\\Psi_1^n + \\frac{\\lambda^2S_{-1/2}}{\\bar S_0}\\Psi_{-1}^n,\\\\[-0.5em]\n        \\xLeftrightarrow{\\mystrut\\ \\text{Eq. \\eqref{eq:closedLeftBrass}}\\ }\\quad\\Psi_0^{n+1} &= 2(1-\\lambda^2)\\Psi_0^n-\\Psi_0^{n-1}+ \\frac{\\lambda^2(S_{1/2}+S_{-1/2})}{\\bar S_0}\\Psi_1^n,\n    \\end{aligned}\n\\end{equation*}\nand as $\\Sbar_0 = \\frac{1}{2}(S_{1/2}+S_{-1/2})$ through Eq. \\eqref{eq:Sbar}, this can be solved to\n\\begin{equation}\\label{eq:leftBoundaryWebster}\n    \\Psi_0^{n+1} = 2(1-\\lambda^2)\\Psi_0^n-\\Psi_0^{n-1}+ 2\\lambda^2\\Psi_1^n.\n\\end{equation}\nOne can implement the right boundary condition by simply reducing the range of operation to $l = \\{0, \\hdots, N-1\\}$, as $\\Psi_N^n = 0$ according to Eq. \\eqref{eq:openRightBrass}. A more realistic boundary condition for the open end is presented in the following.\n\n\\subsection{Radiation}\\label{sec:radiating}\nOne of the ways that an acoustic tube loses energy is through radiation. The right boundary condition presented in Eq. \\eqref{eq:openClosed} can be changed to be radiating according to \\cite{theBible}\n\\begin{equation}\\label{eq:radCont}\n    \\partial_x\\Psi(L,t) = -a_1\\partial_t\\Psi(L,t)-a_2\\Psi(L,t),\n\\end{equation}\nwhere, for a tube terminating on an infinite plane \\cite{Atig2004}\n\\begin{equation}\n    a_1 = \\frac{1}{2(0.8216)^2c}\\ , \\quad \\text{and} \\quad a_2 = \\frac{L}{0.8216\\sqrt{S_0S(1)/\\pi}}\\ ,\n\\end{equation}\nwhich determine the amount of loss and inertia at the radiating boundary respectively. \n\nThe radiating boundary in Eq. \\eqref{eq:radCont} can then be discretised to \\cite{theBible}\n\\begin{equation}\\label{eq:centRadBound}\n    \\delta_{x\\cdot}\\Psi_N^n = -a_1\\dtd\\Psi_N^n - a_2\\mu_{t\\cdot}\\Psi_N^n,\n\\end{equation}\nwhich can be expanded and solved for $\\Psi_{N+1}^n$ according to\n\\begin{equation}\n    \\Psi_{N+1}^n = h\\left(-\\frac{a_1}{k}(\\Psi_N^{n+1} - \\Psi_N^{n-1}) - a_2(\\Psi_N^{n+1} + \\Psi_N^{n-1})\\right) + \\Psi_{N-1}^n.\n\\end{equation}\nSubstitution into Eq. \\eqref{eq:webstersUpdateEq} at the $l=N$ yields the following update equation\n\\begin{equation}\n    \\Psi_N^{n+1} = \\frac{2(1-\\lambda^2)\\Psi_N^n-\\Psi_N^{n-1}+\\alpha_-\\Psi_N^{n-1} + 2\\lambda^2\\Psi_{N-1}^n}{\\left(1+\\alpha_+\\right)},\n\\end{equation}\nwhere\n\\begin{equation}\n    \\alpha_\\pm = h\\left(\\frac{a_1}{k}\\pm a_2\\right)\\frac{\\lambda^2S_{N+1/2}}{\\bar S_N}.\n\\end{equation}\nOne can observe that $S_{N+1/2}$ is needed which is outside the defined domain. As mentioned before, setting $\\Sbar_N = S(L)$, one can calculate $S_{N+1/2}$ using Eq. \\eqref{eq:Snph} to solve the issue. \n\n\\subsection{Excitation}\\label{sec:webstersExcitation}\nAlthough excitations will be discussed more in-depth in Part \\ref{part:exciters}\\todo{maybe refer to chapter/section instead}, a simple way to excite Webster's equation will be presented here.\n\nFollowing \\cite{Bilbao2018}, one can create an input signal $v_\\text{in} = v_\\text{in}(t)$ that interacts with the particle velocity of the tube. As this relates to the acoustic potential as in Eq. \\eqref{eq:pressureVelocityWebster}, one can change the boundary condition of the left boundary to\n\\begin{equation}\n    \\px \\Psi(0, t) = - v_\\text{in}.\n\\end{equation}\nDiscretising this using the centred spatial operator, yields\n\\begin{equation}\n    \\dxd \\Psi_0^n = -v_\\text{in}^n \\quad \\Rightarrow \\quad \\Psi_{-1}^n = 2h v_\\text{in}^n + \\Psi_1^n,\n\\end{equation}\nand can be substituted into the update equation in Eq. \\eqref{eq:webstersUpdateEq} at $l=0$ to get\n\\begin{align}\n    \\Psi_0^{n+1} &= 2(1-\\lambda^2)\\Psi_0^n-\\Psi_0^{n-1} \\frac{\\lambda^2S_{1/2}}{\\Sbar_0}\\Psi_1^n + \\frac{\\lambda^2S_{-1/2}}{\\Sbar_0}\\left(2h v_\\text{in}^n + \\Psi_1^n\\right),\\nonumber\\\\\n    \\Psi_0^{n+1} &= 2(1-\\lambda^2)\\Psi_0^n-\\Psi_0^{n-1} +2\\lambda^2\\Psi_1^n + \\frac{2h\\lambda^2S_{-1/2}}{\\Sbar_0} v_\\text{in}^n.\n\\end{align}\nThe input signal is arbitrary, but looking towards lip excitation, and following \\cite{theBible}, one can set the input to a pulse train as shown in Figure \\ref{fig:inputWebster}. More details can be found in Chapter \\ref{ch:physInspExcitations}.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/brass/inputWebster.eps}\n    \\caption{A pulse train with a frequency of $213$ Hz a duty cycle of 50\\% and an attack of $22$ ms, used to generate the output in Figure \\ref{fig:outputWebster}. \\label{fig:inputWebster}}\n\\end{figure}\n\n% At the left boundary, one can sed $\\bar S_N = S_N$ from which $S_{N+1/2}$ can be calculated:\n% \\begin{equation}\n%     S_N = \\frac{1}{2}(S_{N+1/2} + S_{N-1/2}) \\ \\Rightarrow \\ S_{N+1/2} = 2S_N - S_{N-1/2}.\n% \\end{equation}\n% % \\begin{equation}\n% %         S_0 = \\frac{1}{2}(S_{1/2} + S_{-1/2}) \\ \\Rightarrow \\  S_{-1/2}\n% %         = 2S_0 - S_{1/2}\n% % \\end{equation}\n\n\n\n% The same can be done for the right boundary ($\\bar S_N = S_N$) if this is chosen to be anything else but open (e.g., closed or radiating -- see Section \\ref{sec:radiating}):\n% \\begin{equation}\n%     S_N = \\frac{1}{2}(S_{N+1/2} + S_{N-1/2}) \\ \\Rightarrow \\ S_{N+1/2} = 2S_N - S_{N-1/2}.\n% \\end{equation}\n% For now though, we follow the conditions given in \\eqref{eq:openClosed} and we can simply set the right boundary to its initial state\n% \\begin{equation}\n%     \\Psi_N^n = \\Psi_N^0\n% \\end{equation}\n% which is normally $0$. A more realistic open end is a radiating one, which can be found below.\n\n\\subsection{Matrix form and output}\\label{sec:outputWebster}\nOne can write scheme \\eqref{eq:discWebster} in matrix form by saving the state in a vector $\\boldPsi^n = [\\Psi_0^n, \\hdots, \\Psi_N^n]^T$ and creating a $\\Dxx$ matrix that includes the effect of the cross-sectional area $S$. Assuming Neumann boundary conditions yields\n\\begin{equation}\n    \\Dxx = \\frac{1}{h^2}\\begin{bmatrix}\n        -2& 2 &  & & & \\mathbf{0}& \\\\\n        \\frac{S_{1/2}}{\\Sbar_1} & -2 &\\frac{S_{3/2}}{\\Sbar_1} & & & & \\\\\n        & \\ddots & \\ddots & \\ddots &  & & \\\\\n        & & \\frac{S_{l-1/2}}{\\Sbar_l}& -2 & \\frac{S_{l+1/2}}{\\Sbar_l} & & \\\\\n        & & & \\ddots & \\ddots & \\ddots & \\\\\n        & & &  & \\frac{S_{N-3/2}}{\\Sbar_{N-1}}  & -2 & \\frac{S_{N-1/2}}{\\Sbar_{N-1}} \\\\\n        & \\mathbf{0} & & & & 2 & -2 \\\\\n    \\end{bmatrix}.\n\\end{equation}\nNotice that there are no appearances of $S$ at the boundaries as these vanish due to the boundary conditions as in Eq. \\eqref{eq:leftBoundaryWebster}.\nUsing $\\I_N$ as the $N\\times N$ identity matrix, one can write scheme \\eqref{eq:discWebster} in matrix form as\n\\begin{equation}\\label{eq:matrixFormWebsters}\n    \\A\\boldPsi^{n+1} = \\B\\boldPsi^n + \\C \\boldPsi^{n-1} + \\mathbf{v}^n\n\\end{equation}\nwhere \n\\begin{equation*}\n    \\begin{gathered}\n    \\A = \\begin{bmatrix}\n        \\I_{N}& \\mathbf{0}\\\\\\\n        \\mathbf{0} & 1 + \\alpha_+\\\n    \\end{bmatrix}, \\quad \\B = 2\\I + c^2 k^2 \\Dxx, \\quad \\text{and} \\quad \\C = \\begin{bmatrix}\n        -\\I_N & \\mathbf{0}\\\\\\\n        \\mathbf{0}& -1 + \\alpha_-\n    \\end{bmatrix},\n    \\end{gathered}\n\\end{equation*}\nand the $(N+1)\\times 1$ input vector $\\mathbf{v}^n$ consists of zeros except for the first index:\n\\begin{equation}\n    \\mathbf{v}_i^n = \n    \\begin{cases}\n        \\frac{2h \\lambda^2 S_{-1/2}}{\\Sbar_0}v_\\text{in}^n, & \\text{if } i = 1,\\\\\n        0,& \\text{otherwise}.\n    \\end{cases}\n\\end{equation}\n%\nNotice how the radiation is included by changing the last entry of matrices $\\A$ and $\\C$.\nThe output of an implementation of Webster's equation is shown in Figure \\ref{fig:outputWebster}. The parameters used for the scheme, the input signal and the geometry used to obtain the output can be found in Table \\ref{tab:websterParams}, Figure \\ref{fig:inputWebster}, and Figure \\ref{fig:geometryWebster} respectively.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/brass/outputWebster.eps}\n    \\caption{The output of Webster's equation at $\\Psi_N^n$ using the input in Figure \\ref{fig:inputWebster}, the parameters in Table \\ref{tab:websterParams}, and the geometry in Figure \\ref{fig:geometryWebster}. \\label{fig:outputWebster}}\n\\end{figure}\n\n\\begin{table}[h]\n    \\begin{center}\n    \\begin{tabular}{|l|c|c|}\n        \\hline\n        Name & Symbol (unit) & Value\\\\ \\hline\n        Length & $L$ (m) & $\\approx 3$\\\\\n        Wave speed & $c$ (m/s) & 343\\\\\n        Cross-sectional area & $S(x)$ & See paper \\citeP[H]\\\\\\hline\n        \\end{tabular}\n    \\caption{Parameters for the implementation of Webster's equation. The length is slightly below $3$ m to yield $\\lambda = 1$ in Eq. \\eqref{eq:CFLwebster}.\\label{tab:websterParams}}\n    \\end{center}\n\\end{table}\n{\\renewcommand{\\arraystretch}{1}\n\n\\hspace{0.1\\textwidth}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/resonators/brass/geometryWebster.eps}\n    \\caption{The geometry used for the implementation. See paper \\citeP[H] for more details. \\label{fig:geometryWebster}}\n\\end{figure}\n\n\n\\subsection{Energy analysis}\\label{sec:energyAnalysisWebster}\nThe energy analysis of Webster's equation with a radiating boundary might seem straightforward. However, due to the varying cross-sectional area, the energy balance deserves a more detailed treatment, especially at the boundaries. For this analysis, (centred) Neumann boundary conditions are used for both boundaries (for generality) and the input is ignored. This section follows the steps presented in Section \\ref{sec:energyAnalysis}.% to retain generality. %These can then easily be adapted to Dirichlet if needed.\n\n\\subsubsection{Step 1: Obtain $\\dtp \\h$}\nUsually, to ensure vanishing boundary terms when using centred Neumann boundary conditions, the primed inner product in Eq. \\eqref{eq:primedInnerProd} is chosen. However, as the system has a spatially varying cross-section, the more general weighted inner product in Eq. \\eqref{eq:weightedInnerProd} has to be chosen instead.\n\nTaking an inner product weighted by free parameters $0 < \\el, \\er \\leq 2$ at the left and right boundary respectively, of scheme \\eqref{eq:discWebster} with $(\\dtd \\Psiln)$ over discrete domain $d$, yields \n\\begin{equation}\\label{eq:powerBalanceWebster}\n    \\dtp \\h = \\langle \\dtd\\Psiln ,\\Sbar_l \\delta_{tt}\\Psi^n_l\\rangle_d^{\\el,\\er} - c^2\\langle\\dtd\\Psiln, \\dxm(\\Sp(\\delta_{x+}\\Psiln))\\rangle_d^{\\el,\\er} = 0.\n\\end{equation}\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$} \nAs the right boundary is set to be radiating according to Eq. \\eqref{eq:centRadBound}, the energy balance will eventually be of the following form:\n\\begin{equation}\\label{eq:radiatingEnergyForm}\n    \\delta_{t+}(\\mathfrak{h}+\\mathfrak{h}_\\text{b}) = \\b-\\mathfrak{q}_\\text{b},\n\\end{equation}\nwhere $\\mathfrak{h}_\\text{b}$ is the energy stored by the radiating boundary through the inertia term, $\\mathfrak{q}_\\text{b}$ describes the the energy losses through radiation and $\\b$ is the general boundary term.\n\n% As one can rewrite\n% \\begin{equation}\\label{eq:switchSignsWebster}\n%     \\dxp\\left(\\Sm(\\delta_{x-}\\Psiln)\\right) \\ \\Longleftrightarrow\\  \\dxm\\big(\\Sp(\\dxp\\Psiln)\\big),\n% \\end{equation}\nStarting at Eq. \\eqref{eq:powerBalanceWebster}, the last term can -- using identity \\eqref{eq:weightedIdentityMinus} -- be rewritten to\n\\begin{equation*}\n    c^2\\langle\\Sp \\dtd \\dxp \\Psiln, (\\dxp \\Psiln)\\rangle_{\\underline{d}} + \\b_\\text{r} - \\b_\\text{l},\n\\end{equation*}\nwhere\n\\begin{subequations}\n    \\begin{align}\n     \\mathfrak{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     \\mathfrak{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\\end{subequations}\nare the right and left boundary term respectively (notice that $\\b_\\text{l}$ is subtracted). One can immediately observe that the boundary terms vanish if Dirichlet boundary conditions would be used. \n    \nThen, using identities \\eqref{eq:prodIdentity1} and \\eqref{eq:prodIdentity2} yields \n\\begin{equation*}\n    \\dtp \\h = \\b_\\text{r} - \\b_\\text{l}\n\\end{equation*}\nwhere\n\\begin{equation}\\label{eq:energyBalanceWebster}\n    \\begin{gathered}\n        \\h = \\t + \\v, \\qwiq \\t = \\frac{1}{2} \\left(\\lVert\\sqrt{\\Sbar_l} \\dtm \\Psiln \\rVert_d^{\\el, \\er}\\right)^2 \\quad \\text{and} \\\\\n        % \\v =c^2\\langle\\dtd \\dxp \\Psiln, \\Sp(\\dxp \\Psiln)\\rangle_{\\underline{d}}\\ .\n        \\v = \\frac{c^2}{2}\\langle \\Sp\\dxp \\Psiln, e_{t-}\\dxp\\Psiln\\rangle_{\\underline{d}}.\n    \\end{gathered}\n\\end{equation}\nNotice that $\\Sbar_l$ is included in the norm by using its square-root.\n\nThe next step is to find definitions for $\\el$ and $\\er$ such that the boundary terms vanish if radiation were to be ignored. In other words, the boundary terms need to be rewritten such that \n\\begin{align*}\n    \\dxd \\Psi_0^n &= 0\\  \\Rightarrow\\ \\b_\\text{l} = 0 \\\\\n    \\dxd \\Psi_N^n &= 0\\  \\Rightarrow\\ \\b_\\text{r} = 0\n\\end{align*} \nfor the left and right boundary respectively. It can be shown that, for the special cases of $\\epsilon_\\text{r} = S_{N-1/2}/\\mu_{xx}S_N$ and $\\epsilon_\\text{l} = S_{1/2}/\\mu_{xx}S_0$, the boundary terms vanish in this case\n\\begin{subequations}\\label{eq:centStrictDissip}\n\\begin{align}\n    \\mathfrak{b}_\\text{r} &= c^2 (\\dtd\\Psi_N^n)S_{N-1/2}(2-\\epsilon_\\text{r})(\\delta_{x\\cdot}\\Psi_N^n)\\label{eq:centStrictDissipRight},\\\\\n    \\mathfrak{b}_\\text{l} &= c^2 (\\dtd\\Psi_0^n)S_{1/2}(2-\\epsilon_\\text{l})(\\delta_{x\\cdot}\\Psi_0^n).\\label{eq:centStrictDissipLeft}\n\\end{align}\n\\end{subequations}\nSee Appendix \\ref{app:boundaryWebster} for a derivation of this. %Also note that $\\el, \\er \\leq 2$ to the boundary terms to be non-negative. \n\nTo add the energy stored and dissipated by the radiating boundary, its definition in Eq. \\eqref{eq:centRadBound} can be substituted into the right boundary term $\\b_\\text{r}$ in Eq. \\eqref{eq:centStrictDissipRight} as \n\\begin{align*}\n    \\mathfrak{b}_\\text{r} &= c^2 (\\dtd\\Psi_N^n)S_{N-1/2}(2-\\epsilon_\\text{r})(-a_1\\dtd\\Psi_N^n - a_2\\mu_{t\\cdot}\\Psi_N^n),\\\\\n    &= c^2 S_{N-1/2}(2-\\epsilon_\\text{r})\\left(-a_1(\\dtd\\Psi_N^n)^2 - a_2(\\dtd\\Psi_N^n)(\\mu_{t\\cdot}\\Psi_N^n)\\right).\n\\end{align*}\nThis can then be decomposed in $\\h_\\text{b}$ and $\\q_\\text{b}$ used in Eq. \\eqref{eq:powerBalanceWebster}. \n% These can be obtained by substituting the definition of the radiating boundary Eq. \\eqref{eq:centRadBound} into \\eqref{eq:centStrictDissipRight} to get\n\nUsing identity \\eqref{eq:prodIdentity4} yields the definitions for $\\h_\\text{b}$ and $\\q_\\text{b}$ in Eq. \\eqref{eq:radiatingEnergyForm}\n\\begin{equation}\n    \\h_\\text{b} = \\frac{c^2 S_{N-1/2}(2-\\epsilon_\\text{r}) a_2}{2} \\mtm(\\Psi_N^n)^2, \\qaq \\q_\\text{b} = c^2 S_{N-1/2}(2-\\epsilon_\\text{r})a_1(\\dtd\\Psi_N^n)^2.\n\\end{equation}\nFinally, $\\b = \\b_\\text{l}$ and can be shown to vanish for both Dirichlet and (centred) Neumann conditions.\n\n\\subsubsection{Step 3: Check units}\n\\SWcomment[It seems like in order for the units to make sense, one must write Eq. \\eqref{eq:webstersPDE} as\n\\begin{equation}\n    \\frac{S\\rho}{c^2} \\ptt\\Psi = \\frac{B}{c^2}\\px(S(\\px\\Psi)),\n\\end{equation}\nwhere $B$ is the bulk modulus of air (in N/m$^2$)]\n\\subsubsection{Step 4: Implementation}\nFigure \\ref{fig:energyWebsters} shows the energetic output of Webster's equation with a radiating boundary at $x=L$. To highlight the effect of the radiation, the parameters are set to $L = 1$ and $S(x) = 0.01$ for all $x\\in \\D$.  The system is excited with a raised cosine close to the left boundary, and when the excitation reaches the radiating boundary, the total energy in the system decreases due to the losses. The energy stored by the boundary $\\h_\\text{b}$ is also shown and indeed increases when the wave reaches the boundary.\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}[->,node distance=3cm,\n        thick,main node/.style={circle,draw}]\n    \n        \\node[] (image) at (0,0) {\n        \\includegraphics[width=\\textwidth]{figures/resonators/brass/energyWebster2.eps}\n        };\n    \n        \\node[] (he) at (0.2,0.5) {\\small $\\mathfrak{h}_\\text{e}$};\n\n        \\node[] (h) at (-5.75, 1) {\\small $\\mathfrak{h}$};\n        \\node[] (v) at (-5.75, 0.5) {\\small $\\color{red}\\mathfrak{v}$};\n        \\node[] (t) at (-5.75, 0) {\\small $\\color{blue}\\mathfrak{t}$};\n        \\node[] (hb) at (-5.75, -0.5) {\\small $\\color[HTML]{00DB00}\\mathfrak{h}_\\text{b}$};      \n    \\end{tikzpicture}\n      \\caption{The kinetic (blue), potential (red), and total (black) energy as well as the energy stored by the radiation condition (green) of an implementation of Webster's equation are plotted in the left panel. Notice that the energy decreases between $n=60$ and $n=70$ as the excitation reached the boundary where damping is included. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergyDamping}) and shows that the deviation of the energy is within machine precision. \\label{fig:energyWebsters}}\n\\end{figure}\n\n\\subsection{Stability through energy analysis}\\label{sec:stabilityEnergyWebster}\nFrequency domain analysis as presented in Section \\ref{sec:stabilityAnalysis}, or more specifically, von Neumann analysis, can not be performed on Webster's equation due to the varying cross-section of the system \\cite{theBible}. Instead, stability conditions can be obtained through energy analysis explained in Section \\ref{sec:stabilityAnalysisEnergy}.\n\nConsider the following scheme\n\\begin{equation}\n    [S]_l \\delta_{tt}\\Psi^n_l = c^2\\dxm(\\Sp(\\delta_{x+}\\Psiln)),\n\\end{equation}\nwhere $[S]_l$ is a still undetermined second-order approximation to the true geometry of the acoustic tube and will be shown to be $\\Sbar_l$ below. As done for the 1D wave equation in Section \\ref{sec:stabilityAnalysisEnergy}, the potential energy $\\v$ in Eq. \\eqref{eq:energyBalanceWebster} can be rewritten using identity \\eqref{eq:prodIdentityEnergyStab} as\n\\begin{equation*}\n    \\v = \\frac{c^2}{2}\\left(\\lVert\\sqrt{S_{l+1/2}}\\mtm\\dxp\\Psiln\\rVert_{\\underline{d}}^2-\\frac{k^2}{4}\\lVert\\sqrt{S_{l+1/2}}\\dtm\\dxp \\Psiln\\rVert_{\\underline{d}}^2\\right).\n\\end{equation*}\nFor spatially varying systems, one can use the following extension of the bound given in Eq. \\eqref{eq:spatialBound} \\cite{theBible}\n\\begin{equation}\\label{eq:spatialBoundWebster}\n    \\lVert \\sqrt{\\phi_l}\\dxp \\uln \\rVert_{\\underline{d}} \\leq\\frac{2}{h}\\lVert \\sqrt{\\mxm\\phi_l} \\uln \\rVert_d,\n\\end{equation}\nwhere spatially varying function $\\phi_l > 0$ is defined over the same domain as $u$. The following condition can then be put on $\\v$\n\\begin{align*}\n    \\v &\\geq \\frac{c^2}{2}\\left(\\lVert\\sqrt{S_{l+1/2}}\\mtm\\dxp\\Psiln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{4}\\left(\\frac{2}{h}\\lVert\\sqrt{\\mxm \\Sp}\\dtm\\Psiln\\rVert_{d}\\right)^2\\right),\\\\\n    &\\geq \\frac{c^2}{2}\\left(\\lVert\\sqrt{S_{l+1/2}}\\mtm\\dxp\\Psiln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{h^2}\\lVert\\sqrt{\\mxx S_l}\\dtm\\Psiln\\rVert_{d}^2\\right)\\\\\n    & \\geq \\frac{c^2}{2}\\left(\\lVert\\sqrt{S_{l+1/2}}\\mtm\\dxp\\Psiln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{h^2}\\left(\\lVert\\sqrt{\\mxx S_l}\\dtm\\Psiln\\rVert_{d}^{\\el,\\er}\\right)^2\\right),\n\\end{align*}\nwhere the last step is possible because $0 < \\el, \\er \\leq 2$.\n% Assuming that $\\el, \\er \\leq 2$, the following is true\n% \\begin{equation}\n%     \\lVert \\uln \\rVert^{\\el, \\er}_d\\leq \\lVert \\uln\\rVert_d\n% \\end{equation}\n% \\begin{equation}\n%     \\t \\geq \n% \\end{equation}\nSubstituting this into the energy balance in Eq. \\eqref{eq:energyBalanceWebster} yields\n\\begin{align*}\n    \\h = \\t + \\v \\geq &\\  \\frac{1}{2} \\left(\\lVert\\sqrt{[S]_l} \\dtm \\Psiln \\rVert_d^{\\el, \\er}\\right)^2 \\\\\n    &+ \\frac{c^2}{2}\\left(\\lVert\\sqrt{S_{l+1/2}}\\mtm\\dxp\\Psiln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{h^2}\\left(\\lVert\\sqrt{\\mxx S_l}\\dtm\\Psiln\\rVert_{d}^{\\el,\\er}\\right)^2\\right),\n\\end{align*}\nand as $\\lVert\\sqrt{S_{l+1/2}}\\mtm\\dxp\\Psiln\\rVert_{\\underline{d}}^2$ is non-negative, the following is also true\n\\begin{equation*}\n    \\h = \\t + \\v \\geq \\frac{1}{2} \\left(\\lVert\\sqrt{[S]_l} \\dtm \\Psiln \\rVert_d^{\\el, \\er}\\right)^2- \\frac{\\lambda^2}{2}\\left(\\lVert\\sqrt{\\mxx S_l}\\dtm\\Psiln\\rVert_{d}^{\\el,\\er}\\right)^2.\n\\end{equation*}\nThis can be written as\n\\begin{equation}\n    \\h \\geq \\frac{1}{2} \\sum_d \\left(\\sqrt{[S]_l} - \\lambda^2\\sqrt{\\mxx S_l}\\right)(\\dtm \\Psiln)^2 \n\\end{equation}\nwhich is non-negative if\n\\begin{align*}\n    \\text{min}\\Big(\\sqrt{[S]_l} - \\lambda^2\\sqrt{\\mxx S_l}\\Big) \\geq 0,\\\\\n    \\lambda \\leq \\text{min}\\left(\\sqrt{\\frac{[S]_l}{\\mxx S_l}}\\right).\n\\end{align*}\nFor the special choice of $[S]_l = \\mxx S_l$, this condition reduces to\n\\begin{equation}\n    \\lambda \\leq 1,\n\\end{equation}\nalso given in \\eqref{eq:CFLwebster}. This choice of $[S]_l$ is equal to $\\Sbar_l$ through Eq. \\eqref{eq:Sbar}, hence its choice in Eq. \\eqref{eq:discWebster}.\n\n\\subsection{Modal analysis}\nFollowing Section \\ref{sec:oneStepForm}one can perform a modal analysis of the system by writing Eq. \\eqref{eq:matrixFormWebsters} in one-step  form (ignoring the input vector). The variable cross-section causes the modes of the system to vary in interesting ways. If the tube is perfectly cylindrical and $S(x)$ is thus constant, Webster's equation reduces to the 1D wave equation and the modal frequencies are integer multiples of the fundamental frequency. \nFor low cross-sectional variations, the modes generally follow a linear pattern. See Figure \\ref{fig:webstersModes}. The damping per mode, however, follows a different pattern, where higher damping occurs around $\\fs/4$, and is due to the comb-filtering effect that the radiation has on the system. \\SWcomment[is this true?]\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/brass/webstersModes.eps}\n    \\caption{The result of a modal analysis of Webster's equation with parameters and geometry given in \\ref{sec:outputWebster}. Notice the higher damping for modes around $\\fs/4$. \\label{fig:webstersModes}}\n\\end{figure}\n\n\\section{First-order system}\\label{sec:firstOrderSystem}\nUntil now, only PDEs that are second-order in time have been presented, i.e., that are dependent on the acceleration of the state variable. This section presents a system of two coupled first-order PDEs which are instead dependent on the velocity. State-of-the-art research on brass instruments in the context of FDTD methods also uses this coupled system (see e.g.\\cite{Bilbao2016, Harrison2018}) and has been used in this project to model the trombone in paper \\citeP[H].\\todo{look at wording}\n\n\\subsection{Continuous time}\nUsing the same variables as before for cross-sectional area $S=S(x)$, wave speed $c$, and air density $\\rho_0$, a system of PDEs that describes air propagation in an acoustic tube can be defined as follows:\n\\begin{subequations}\\label{eq:firstOrderSystem}\n\\begin{align}\n    \\frac{S}{\\rho_0 c^2}\\partial_t p &= -\\partial_x(Sv),\\label{eq:contPressure}\\\\\n    \\rho_0\\partial_tv &= -\\partial_xp\\label{eq:discVelocity},\n\\end{align}\n\\end{subequations}\nwhere pressure $p = p(x,t)$ (Pa) and particle velocity $v = v(x,t)$ (m/s) are defined for $x\\in \\D$ with domain $\\D = [0, L]$ and tube length $L$ (in m). These state variables are related to the acoustic potential $\\Psi$ as shown in Eq. \\eqref{eq:pressureVelocityWebster} as\n\\begin{equation}\\label{eq:pressureVelocityFirstOrder}\n    p = \\rho_0\\partial_t \\Psi, \\quad v = -\\partial_x\\Psi.\n\\end{equation}  \nIndeed it can be shown by substituting these definitions into Eq. \\eqref{eq:contPressure}, Webster's equation can be obtained:\n\\begin{equation}\n  \\nonumber\n        \\frac{S}{\\rho_0 c^2}\\partial_t(\\rho_0 \\partial_t\\Psi) = -\\partial_x(S(-\\partial_x\\Psi))\\quad \\Longrightarrow \\quad S\\partial_t^2\\Psi = c^2\\partial_x(S\\partial_x\\Psi).\n\\end{equation}\n\n\n\\subsubsection{Boundary conditions}\nFor the first-order PDE system in Eq. \\eqref{eq:firstOrderSystem}, the boundary conditions are defined as follows:\n\\begin{subequations}\n    \\begin{align}\\label{eq:firstOrderBoundaryConditionsCont}\n        p(0,t) &= 0, &  p(L,t) &= 0, & &\\quad\\text{(Dirichlet, open)},\\\\\n        S(0)v(0) &= 0, & S(L)v(L) &= 0, & &\\quad \\text{(Neumann, closed)},\n    \\end{align}\n\\end{subequations}\nwhich, through Eq. \\eqref{eq:pressureVelocityFirstOrder}, relate to the boundary conditions of Webster's equation in Eq. \\eqref{eq:contBoundariesBrass}.\n\n\\subsection{Discrete time}\\label{sec:firstOrderDiscrete}\nIt is useful to place either $p$ or $v$ on an interleaved grid (see Figure \\ref{fig:interleavedGrid}). Following \\cite{Harrison2018}, $v$ is placed on this interleaved grid both in space and time. \nAccordingly, system \\eqref{eq:firstOrderSystem} is discretised as\n\\begin{subequations}\\label{eq:firstOrderFDS}\n    \\begin{align}\n        \\frac{\\bar S_l}{\\rho_0 c^2}\\delta_{t+}p_l^n &= -\\delta_{x-}(S_{l+1/2}v_{l+1/2}^{n+1/2}),\\label{eq:discPressure}\\\\\n        \\rho_0 \\delta_{t-}v_{l+1/2}^{n+1/2}&=-\\delta_{x+}p_l^n,\\label{eq:discVelocity}\n    \\end{align}\n\\end{subequations}\nafter which the update equations become\n\\begin{subequations}\n    \\begin{align}\n        p_l^{n+1} &= p_l^n - \\frac{\\rho_0 c \\lambda}{\\bar{S}_l}(S_{l+1/2}v_{l+1/2}^{n+1/2}-S_{l-1/2}v_{l-1/2}^{n+1/2}),\\label{eq:pressureUpdate}\\\\\n        v_{l+1/2}^{n+1/2} &= v_{l+1/2}^{n-1/2}-\\frac{\\lambda}{\\rho_0 c}(p_{l+1}^n - p_l^n),\\label{eq:velocityUpdate}\n    \\end{align}\n\\end{subequations}\nwhere (again) $\\lambda = ck/h \\leq 1$ for stability. The pressure is defined for $l=\\{0, \\hdots, N\\}$ and the velocity for $l=\\{0, \\hdots, N-1\\}$ where $N$ is the number of intervals between the grid points on the pressure grid. Notice that the range of calculation for the particle velocity is one fewer grid point than that of the pressure.\n\nAn advantage of using an interleaved grid like this, is that the forward and backward FD operators are second-order accurate, and can be shown through a Taylor series expansion as done in \\ref{sec:FDoperators} (also see \\cite{Harrison2018}).\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{figures/resonators/brass/interleavedGridFigure.pdf}\n    \\caption{The interleaved grid used for the system of FD schemes in Eq. \\eqref{eq:firstOrderFDS}. Grid points on the regular grid (in black) are used for pressure $p$, while points on the interleaved grid (in white) are used for particle velocity $v$.\\label{fig:interleavedGrid}}\n\\end{figure}\n\n\\subsubsection{Boundary conditions}\\label{sec:boundariesFirstOrder}\nThe boundary conditions in Eq. \\eqref{eq:firstOrderBoundaryConditionsCont} can be discretised as follows\n\\begin{subequations}\n    \\begin{align}\\label{eq:firstOrderBoundaryConditions}\n        p_0^n &= 0, & p_N^n &= 0, & &\\text{(Dirichlet, open),}\\\\\n        \\mu_{x-}(S_{1/2}v_{1/2}^n) &= 0, & \\mu_{x+}(S_{N-1/2}v_{N-1/2}^n) &= 0, & &\\text{(Neumann, closed)}.\n    \\end{align}\n\\end{subequations}\n\\todo{stencil?}\n\\subsection{Matrix form}\nSystem \\eqref{eq:firstOrderFDS} can be written in matrix form, by saving the states of $p_l^n$ and $v_{l+1/2}^{n+1}$ in vectors as \n\\begin{equation}\n    \\mathbf{p}^n = [p_0^n, \\hdots, p_N^n]^T, \\qaq \\mathbf{v}^{n+1/2} = [v_{1/2}^{n+1/2}, \\hdots, v_{N-1/2}^{n+1/2}]^T\n\\end{equation}\nwhich are of sizes $(N+1)\\times 1$ and $N\\times 1$ respectively. One may then write the scheme in matrix form as  \n\\begin{subequations}\n    \\begin{align}\n        \\mathbf{v}^{n+1/2} &= \\mathbf{v}^{n-1/2} + \\B_p \\mathbf{p}^n\\\\\n        \\mathbf{p}^{n+1} &= \\mathbf{p}^n + \\B_v \\mathbf{v}^{n+1/2} \n    \\end{align}\n\\end{subequations}\nwhere\n\\begin{equation}\n    \\B_v = \\frac{\\rho_0 c}\\lambda \\begin{bmatrix}\n        -\\frac{2S_{1/2}}{\\Sbar_0}& & & \\mathbf{0}\\\\\n        \\frac{S_{1/2}}{\\Sbar_1} & -\\frac{S_{3/2}}{\\Sbar_1} & & \\\\\n        & \\ddots & \\ddots & \\\\\n        & & \\frac{S_{N-3/2}}{\\Sbar_{N-1}} & -\\frac{S_{N-1/2}}{\\Sbar_{N-1}} \\\\\n        \\mathbf{0} & & & \\frac{2 S_{N-1/2}}{\\Sbar_N} \\\\\n    \\end{bmatrix}.\n\\end{equation}\nis of size $(N+1) \\times N$.\n\n\\begin{equation}\n    \\B_p = \\frac{\\lambda}{\\rho c}\\begin{bmatrix}\n        1& -1& & & \\mathbf{0} &\\\\\n         & 1 & -1 & & & \\\\\n       & & \\ddots & \\ddots & &\\\\\n         & & & 1& -1& \\\\\n        & \\mathbf{0} & & & 1& -1 \\\\\n    \\end{bmatrix}.\n\\end{equation}\nis of size $N \\times (N+1)$.\n\nAlternatively, one can write the scheme in one-step form by concatenating the states of the pressure and particle velocity into one vector. The matrix form will then be \n\\begin{equation}\n    \\underbrace{\\begin{bmatrix}\n        \\mathbf{p}^{n+1}\\\\\n        \\mathbf{v}^{n+1/2}\n    \\end{bmatrix}}_{\\u^{n+1}} = \\B\\underbrace{\\begin{bmatrix}\n        \\mathbf{p}^{n}\\\\\n        \\mathbf{v}^{n-1/2}\n    \\end{bmatrix}}_{\\u^{n}} \n\\end{equation}\nwhere\n\\begin{equation}\n    \\B = \\begin{bmatrix}\n        \\I_{N+1}+\\B_v\\B_p & \\B_v  \\\\\n        \\B_p & \\I_{N}\n    \\end{bmatrix},\n\\end{equation}\nis of size $(2N + 1) \\times (2N + 1)$ and may be directly used as matrix $\\Q$ for the modal analysis using a one-step form described in Section \\ref{sec:oneStepForm}.\n\nFinally the concatenated vector is defined as,\n\\begin{equation}\n    \\u^n = [p_0^n, \\hdots, p_N^n, v_{1/2}^{n-1/2}, \\hdots, v_{N-1/2}^{n-1/2}]^T\n\\end{equation}\nand will be of size $(2N + 1) \\times 1$. \n\n\\subsection{Energy analysis}\nThis section presents an energy analysis of the first-order system presented above using the techniques presented in Section \\ref{sec:energyAnalysis}. For the bulk of the analysis, \\cite{Harrison2018} is followed. \n\n\\subsubsection{Step 1: Obtain $\\dtp \\h$}\nTo obtain the correct energy balance, an inner product of Eq. \\eqref{eq:discPressure} with $\\mu_{t+}p_l^n$ needs to be taken over discrete domain $d = \\{0, \\hdots, N\\}$. Using the primed inner product in Eq. \\eqref{eq:primedInnerProd} and, after taking all terms to the left-hand side, yields\\footnote{The primed rather than the weighted inner product can be used here as the eventual boundary terms can be shown to vanish when using the boundary conditions in Eq. \\eqref{eq:firstOrderBoundaryConditions}.}\n\\begin{equation}\\label{eq:firstOrderPrimed}\n    \\delta_{t+}\\mathfrak{h} = \\frac{1}{\\rho_0 c^2}\\langle \\mu_{t+}p_l^n, \\Sbar \\delta_{t+}p_l^n \\rangle_{d}' +\\langle \\mu_{t+}p_l^n, \\dxm(S_{l+1/2}v_{l+1/2}^{n+1/2})\\rangle_{d}' = 0.\n\\end{equation}\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\nFor the rest of the analysis, the following superscripts and subscripts will be assumed unless denoted otherwise: $n$ and $l$ for $p$, $l$ for $\\bar S$, $l+1/2$ for $S$ and $l+1/2$ and $n+1/2$ for $v$. After performing summation by parts of the last term using identity \\eqref{eq:primedIdentityMinus}, Eq. \\eqref{eq:firstOrderPrimed} becomes\n\\begin{equation}\\label{eq:discEnergyFirstOrder}\n    \\delta_{t+}\\mathfrak{h} = \\frac{1}{\\rho_0 c^2}\\langle \\mu_{t+}p, \\bar S \\delta_{t+}p \\rangle_{d}' -\\langle \\mu_{t+}\\dxp p, Sv\\rangle_{\\underline{d}} = -\\mathfrak{b} \\quad \\end{equation}\nwhere the boundary term is\n\\begin{align}\n    \\mathfrak{b} &= \\mathfrak{b}_\\text{r} - \\mathfrak{b}_\\text{l}, \\quad \\text{with} \\nonumber\\\\\n    \\mathfrak{b}_\\text{r} &= (\\mu_{t+}p_N)\\mu_{x+}(S_{N-1/2}v_{N-1/2})\\quad \\text{and}\\label{eq:firstOrderRightBoundary}\\\\\n    \\mathfrak{b}_\\text{l} &= (\\mu_{t+}p_0)\\mu_{x-}(S_{1/2}v_{1/2})\\label{eq:firstOrderLeftBoundary},\n\\end{align}\nand can be shown to vanish under the boundary conditions shown in Eq. \\eqref{eq:firstOrderBoundaryConditions}. Then, Eq. \\eqref{eq:discVelocity} can be substituted into Eq. \\eqref{eq:discEnergyFirstOrder} to get\n\\begin{align}\n    \\delta_{t+}\\mathfrak{h} &= \\frac{1}{\\rho_0 c^2}\\langle \\mu_{t+}p, \\bar S \\delta_{t+}p \\rangle_{d}' -\\langle \\mu_{t+}(-\\rho_0\\delta_{t-}v), Sv\\rangle_{\\underline{d}} = 0\\\\\n    &= \\frac{1}{\\rho_0 c^2}\\langle \\mu_{t+}p, \\bar S \\delta_{t+}p \\rangle_{d}' + \\rho_0 \\langle \\delta_{t\\cdot}v, Sv\\rangle_{\\underline{d}} = 0.\n\\end{align}\nFinally, one can use identities \\eqref{eq:prodIdentity3} and \\eqref{eq:prodIdentity2} for the first and second term respectively to get\n\\begin{equation}\\label{eq:energyBalanceFirstOrder}\n    \\begin{gathered}\n        \\mathfrak{h} = \\mathfrak{t} + \\mathfrak{v}\\quad \\text{where}\\\\\n       \\mathfrak{t} = \\frac{\\rho_0}{2}\\langle Sv, e_{t-}v\\rangle_{\\underline{d}}\\quad \\text{and} \\quad \\mathfrak{v} = \\frac{1}{2\\rho_0 c^2}\\left(\\lVert\\sqrt{\\bar S }p\\rVert'_d\\right)^2.\n    \\end{gathered}\n\\end{equation}\n\\subsubsection{Step 3: Check units}\nWriting the terms in Eq. \\eqref{eq:energyBalanceFirstOrder} in their units yields\n\\begin{align*}\n    \\t = \\frac{\\rho_0}{2}\\langle Sv, e_{t-}v\\rangle_{\\underline{d}}\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}& \\ \\text{kg}\\cdot \\text{m}^{-3}\\cdot \\text{m} \\cdot (\\text{m}^2 \\cdot \\text{m}\\cdot\\text{s}^{-1} \\cdot \\text{m}\\cdot\\text{s}^{-1}),\\\\\n    & = \\text{kg} \\cdot \\text{m}^2 \\cdot \\text{s}^{-2},\\\\\n    \\v = \\frac{1}{2\\rho_0 c^2}\\left(\\lVert\\sqrt{\\bar S }p\\rVert'_d\\right)^2\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}&\\  (\\text{kg} \\cdot \\text{m}^{-3} \\cdot \\text{m}^2 \\cdot \\text{s}^{-2})^{-1} \\cdot(\\text{m} \\cdot \\text{kg} \\cdot \\text{m}^{-1}\\cdot \\text{s}^{-2})^2,\\\\\n    &= \\text{kg} \\cdot \\text{m}^2 \\cdot \\text{s}^{-2},\n\\end{align*}\nand indeed have the correct units.\n\\subsubsection{Step 4: Implementation}\nFigure \\ref{fig:energyFirstOrder} shows the energetic output of an implementation of the first order system in Eq. \\eqref{eq:firstOrderFDS}, and shows that the energy is within machine precision.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}[->,node distance=3cm,\n        thick,main node/.style={circle,draw}]\n    \n        \\node[] (image) at (0,0) {\n        \\includegraphics[width=\\textwidth]{figures/resonators/brass/energyFirstOrder.eps}\n        };\n    \n        \\node[] (he) at (0.2,0.5) {\\small $\\mathfrak{h}_\\text{e}$};\n\n        \\node[] (h) at (-5.75, 1) {\\small $\\mathfrak{h}$};\n        \\node[] (v) at (-5.75, 0.5) {\\small $\\color{red}\\mathfrak{v}$};\n        \\node[] (t) at (-5.75, 0) {\\small $\\color{blue}\\mathfrak{t}$};\n    \\end{tikzpicture}\n      \\caption{The kinetic (blue), potential (red), and total (black) energy of an implementation of the first-order system in Eq. \\eqref{eq:firstOrderFDS} are plotted in the left panel. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}) and shows that the deviation of the energy is within machine precision. \\label{fig:energyFirstOrder}}\n\\end{figure}\n\n\\subsection{Adding radiation}\n\\def\\r{\\text{r}}\n\\def\\one{{(1)}}\nFollowing \\cite{Harrison2018}, radiation  can be added to the schemes using a circuit representation of the Levine and Schwinger radiation model (See Figure \\ref{fig:circuit}). This section will provide a derivation \\SWcomment[I'll actually move most of this to an appendix...]\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{figures/resonators/brass/circuit.pdf}\n    \\caption{The circuit representation of the Levine and Schwinger radiation model. \\label{fig:circuit}}\n\\end{figure}\n\nThe system can be described as\n\\begin{subequations}\\label{eq:barVPSystem}\n    \\begin{align}\n        \\bar v &= \\mu_{t+}v_\\one + \\frac{1}{R_2}\\mu_{t+}p_\\one + C_\\r \\delta_{t+}p_\\one,\\label{eq:barV}\\\\\n        \\bar p &= L_\\r \\delta_{t+}v_\\one,\\label{eq:barP1}\\\\\n        \\bar p &= \\left(1+\\frac{R_1}{R_2}\\right)\\mu_{t+}p_\\one+ R_1 C_\\r\\delta_{t+}p_\\one\\label{eq:barP2},\n    \\end{align}\n\\end{subequations}\nwhere $\\bar p^{n+1/2}$ and $\\bar v^{n+1/2}$ are placed on the interleaved temporal grid and are related to the tube by\n\\begin{equation}\\label{eq:barVars}\n    \\bar p = \\mu_{t+}p^n_N, \\quad \\bar S_N \\bar v = \\mu_{x-}\\left(S_{N+1/2}v_{N+1/2}^{n+1/2}\\right).\n\\end{equation}\nThis can be applied to the right boundary of the tube by evaluating Eq. \\eqref{eq:pressureUpdate} at $l = N$\n\\begin{equation}\n    p_N^{n+1} = p_N^n - \\frac{\\rho_0 c \\lambda}{\\bar{S}_N}\\left(S_{N+1/2}v_{N+1/2}^{n+1/2}-S_{N-1/2}v_{N-1/2}^{n+1/2}\\right),\n\\end{equation}\nand, rewriting this to \n\\begin{align}\n    p_N^{n+1} &= p_N^n - \\frac{\\rho_0 c \\lambda}{\\bar{S}_N}\\left(2\\mu_{x-}\\left(S_{N+1/2}v_{N+1/2}^{n+1/2}\\right)-2S_{N-1/2}v_{N-1/2}^{n+1/2}\\right)\\nonumber,\\\\\n    p_N^{n+1} &= p_N^n - \\frac{2\\rho_0 c \\lambda}{\\bar{S}_N}\\left(\\bar S_N \\bar v-S_{N-1/2}v_{N-1/2}^{n+1/2}\\right)\\label{eq:preSolutP}.\n\\end{align}\nA definition for $\\bar v$ can then be found by first expanding Eq. \\eqref{eq:barV} to \n\\begin{equation}\\label{eq:vBarExpanded}\n    \\bar v = \\frac{1}{2}\\left(v_\\one^{n+1} + v_\\one^n\\right) + \\left(\\frac{1}{2R_2} + \\frac{C_\\r}{k}\\right) p_\\one^{n+1} +\\left(\\frac{1}{2R_2} - \\frac{C_\\r}{k}\\right)p_\\one^n\n\\end{equation}\nafter which it should be made solely dependent on the known values $v_\\one^n$, $p_\\one^n$ and $p_N^n$ and the unknown $p_N^{n+1}$ (as this can be obtained using Eq. \\eqref{eq:preSolutP}).\n\nEquation \\eqref{eq:barP1} can be expanded to \n\\begin{equation}\\label{eq:voneNext}\n    v_\\one^{n+1} = \\frac{k}{L_\\r}\\bar p + v_\\one^n ,\n\\end{equation}\nand Eq. \\eqref{eq:barP2} to \n\\begin{align*}\n    &\\bar p =\\left(1+\\frac{R_1}{R_2}\\right)\\mu_{t+}p_\\one+ R_1 C_\\r\\delta_{t+}p_\\one,\\\\\n    &\\bar p =\\frac{1}{2}\\left(1+\\frac{R_1}{R_2}\\right)\\left(p_\\one^{n+1} + p_\\one^n\\right) + \\frac{R_1C_\\r}{k}\\left(p_\\one^{n+1} - p_\\one^n\\right),\\\\\n    \\left(\\frac{1}{2}+\\frac{R_1}{2R_2} + \\frac{R_1C_\\r}{k}\\right)&p_\\one^{n+1} = \\bar p + \\left(\\frac{R_1C_\\r}{k} - \\frac{1}{2} - \\frac{R_1}{2R_2}\\right)p_\\one^n\n\\end{align*}\nand finally solved for $p_\\one^{n+1}$ as\n\\begin{equation}\\label{eq:poneNext}\n    p_\\one^{n+1} = \\underbrace{\\left(\\frac{2R_2k}{2R_1R_2C_\\r + k(R_1 + R_2)}\\right)}_{\\zeta_1}\\bar p + \\underbrace{\\left(\\frac{2R_1R_2C_\\r - k(R_1 + R_2)}{2R_1R_2C_\\r + k(R_1 + R_2)}\\right)}_{\\zeta_2} p_\\one^n .\n\\end{equation}\nEquations \\eqref{eq:voneNext} and \\eqref{eq:poneNext} can then be substituted into Eq. \\eqref{eq:vBarExpanded} and, using the definition of $\\bar p$ from Eq. \\eqref{eq:barVars}, yields\n\\begin{align}\n    \\bar v &= \\frac{1}{2}\\left(\\frac{k}{L_\\r}(\\mu_{t+}p_N^n) + 2v_\\one^n\\right)+\\left(\\frac{1}{2R_2} + \\frac{C_\\r}{k}\\right)\\zeta_1\\mu_{t+}p_N^n\\nonumber \\\\\n    & \\qquad\\qquad+ \\left(\\frac{1}{2R_2} + \\frac{C_\\r}{k}\\right)\\zeta_2p_\\one^n + \\left(\\frac{1}{2R_2} - \\frac{C_\\r}{k}\\right)p_\\one^n\\nonumber,\\\\\n    \\bar v &= \\underbrace{\\left(\\frac{k}{2L_\\r} + \\frac{\\zeta_1}{2R_2}+\\frac{C_\\r\\zeta_1}{k}\\right)}_{\\zeta_3}\\mu_{t+}p_N^n + v_\\one^n + \\underbrace{\\left(\\frac{\\zeta_2+1}{2R_2} + \\frac{C_\\r\\zeta_2 - C_\\r}{k}\\right)}_{\\zeta_4}p_\\one^n.\n\\end{align}\nFinally, substituting this definition for $\\bar v$ into Eq. \\eqref{eq:preSolutP} yields\n\\begin{align}\n    p_N^{n+1} &= p_N^n - \\frac{2\\rho_0c\\lambda}{\\bar S_N}\\left(\\bar S_N\n    \\left[\\zeta_3\\left(\\frac{p_N^{n+1} + p_N^n}{2}\\right) + v_\\one^n + \\zeta_4p_\\one^n\\right] - S_{N-1/2}v_{N-1/2}^{n+1/2}\\right)\\nonumber\\\\\n    p_N^{n+1} &= p_N^n - \\rho_0c\\lambda\\left(\\zeta_3(p_N^{n+1} + p_N^n) + 2(v_\\one^n + \\zeta_4p_\\one^n)-\\frac{2S_{N-1/2}v_{N-1/2}^{n+1/2}}{\\bar S_N}\\right)\\nonumber\n\\end{align}\nand yields a definition for $p_N^{n+1}$ based on known values of the system \n\\begin{equation}\n    p_N^{n+1} = \\frac{1 - \\rho_0c\\lambda\\zeta_3}{1+\\rho_0c\\lambda\\zeta_3}p_N^n - \\frac{2\\rho_0c\\lambda}{1+\\rho_0c\\lambda\\zeta_3} \\left( v_\\one^n+\\zeta_4p_\\one^n - \\frac{S_{N-1/2}v_{N-1/2}^{n+1/2}}{\\bar S_N}\\right).\n\\end{equation}\n\\subsection{Energy}\n\\SWcomment[not done yet...]\nRecalling the condition at the right boundary from \\eqref{eq:firstOrderRightBoundary}\n\\begin{equation}\n    \\mathfrak{b}_\\r = (\\mu_{t+}p_N)\\underbrace{\\mu_{x+}(S_{N-1/2}v_{N-1/2})}_{\\mu_{x-}S_{N+1/2}v_{N+1/2}},\n\\end{equation}\nusing Eq. \\eqref{eq:barVars} one can rewrite this to\n\\begin{equation}\n    \\mathfrak{b}_\\r = \\bar p\\bar S_N\\bar v.\n\\end{equation}\nthen we can \n", "meta": {"hexsha": "caee8223a29c46bfa8d657abf369efb0a786c65d", "size": 49896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/resonators/brass.tex", "max_stars_repo_name": "SilvinWillemsen/phdThesis", "max_stars_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aauPhdCollectionThesis/resonators/brass.tex", "max_issues_repo_name": "SilvinWillemsen/phdThesis", "max_issues_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aauPhdCollectionThesis/resonators/brass.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": 71.5868005739, "max_line_length": 755, "alphanum_fraction": 0.6926607343, "num_tokens": 17567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895106480586, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6604850402924177}}
{"text": "\\chapter{The Game of Nim}\n\\marginurl{%\n    The game of Nim:\\\\\\noindent\n    Introduction to Combinatorial Game Theory \\#3\n}{youtu.be/H-SyB0NK3H8}\n\nThis chapter discusses probably the most famous combinatorial game, the game\nof \\emph{Nim}.\nIn this game there are several piles of chips on the table. On each turn\nthe current player may remove some number of chips from \\emph{one} of the piles;\nhowever, the player should remove \\emph{at least one chip}.\nWe say that a game of Nim is a $k$-pile game of Nim if there are $k$ piles.\n\\marginurl{%\n  You can play Nim on this website\n}{dotsphinx.com/games/nim/}\n\nWe start from analysis of the game when we have one pile of chips. It is clear\nthat the first player to move wins since he/she may remove all the chips.\n\nConsider a more complicated case when we have two piles of size $n$ and $m$\nrespectively. We need to consider two cases:\n\\begin{enumerate}\n  \\item If $n = m$, then the second player to move wins. Indeed, we can\n    use the symmetric strategy; i.e., if the first player removes $s$\n    chips from one pile we also remove $s$ chips from the other pile.\n    It is clear that we can always make a move as long as the first player can.\n  \\item Otherwise, the first player wins because it can move to the state\n    with two equal piles.\n\\end{enumerate}\n\nThe case of three piles is even more complicated. So we spend the rest of the\nchapter studying it.\n\n\\section{Nim Sum}\n\nWe start from a definition of the XOR operation\n$\\lxor : \\set{0, 1} \\times \\set{0, 1} \\to \\set{0, 1}$,\nalso known as ``exclusive or''), this operation is defined as follows:\n$a \\lxor b = 1$ iff $a \\neq b$.\n\nIt is well-known that any number $n \\in \\N_0$\ncan be represented as a binary number ($\\N_0$ denotes nonnegative integers);\n\\nomenclature[S]{$\\N_0$}{denotes the set of nonnegative integers}\nwe write $n = (a_\\ell, \\dots, a_0)_2$ if $n = \\sum_{i = 0}^\\ell a_i 2^i$.\nFor example,\n$5 = 4 + 1 = 1 \\cdot 2^2 + 0 \\cdot 2^1 + 1 \\cdot 2^0 = (1, 0, 1)_2$ and\n$6 = 4 + 2 = 1 \\cdot 2^2 + 1 \\cdot 2^1 + 0 \\cdot 2^0 = (1, 1, 0)_2$.\nSo we can define the Nim sum $\\bitwisexor : \\N_0 \\times \\N_0 \\to \\N_0$, also\nknown as bitwise xor, as follows:\n$(a_\\ell, \\dots, a_0)_2 \\bitwisexor (b_\\ell, \\dots, b_0)_2 =\n    (a_\\ell \\lxor b_\\ell, \\dots, a_0 \\lxor b_0)_2$.\nFor example, $5 \\bitwisexor 6 = (1, 0, 1)_2 \\bitwisexor (1, 1, 0)_2 =\n(1 \\lxor 1, 0 \\lxor 1, 1 \\lxor 0)_2 = (0, 1, 1)_2$.\n\\nomenclature[N]{$\\bitwisexor$}{denotes the Nim sum}\n\n\\begin{exercise}\n  Show that $a \\bitwisexor (b \\bitwisexor c) = (a \\bitwisexor b) \\bitwisexor c$\n  for any $a, b, c \\in \\N_0$.\n\\end{exercise}\nHence, we are going to write $a \\bitwisexor b \\bitwisexor c$ instead of\n$a \\bitwisexor (b \\bitwisexor c)$ and $(a \\bitwisexor b) \\bitwisexor c$.\n\n\\section{Bouton's Theorem}\n\nNow we may notice that $a \\bitwisexor b = 0$ iff $a = b$. So\nour result about $2$-pile Nim can be rephrased:\na position $(a, b)$ in the $2$-pile Nim is a P-position iff\n$a \\bitwisexor b = 0$. Which leads us to the next theorem.\n\\begin{theorem}[Bouton]\n\\label{theorem:bouton}\n  A position $(a, b, c)$ in $3$-pile Nim is a P-position iff\n  $a \\bitwisexor b \\bitwisexor c = 0$\n\\end{theorem}\n\\begin{proof}\n  We prove the statement using structural induction.\n  First note that the only terminal position the $3$-pile Nim is $(0, 0, 0)$\n  and $(0, 0, 0)$ and $0 \\bitwisexor 0 \\bitwisexor 0 = 0$.\n\n  Let us consider\n  some $(a, b, c)$ such that $a \\bitwisexor b \\bitwisexor c \\neq 0$.\n  We need to show that there is a move from this position to a P-position.\n  Let $a \\bitwisexor b \\bitwisexor c =\n      (0, \\dots, 0, 1, r_{k - 1}, \\dots, r_0)_2$. So among $a$, $b$, and $c$\n  there is a number that has $1$ in the $k$th position.\n  Note that without loss of generality\n  $a = (p_\\ell, \\dots, p_{k + 1}, 1, p_{k - 1}, \\dots, p_0)_2$.\n  Consider $a' = (p_\\ell, \\dots, p_{k + 1}, 0,\n    p_{k - 1} \\lxor r_{k - 1}, \\dots, r_0 \\lxor p_0)_2$. It is clear that\n  $a' < a$ and $a' \\bitwisexor b \\bitwisexor c = 0$.\n  Hence, $(a', b, c)$ is a P-position and therefore, $(a, b, c)$ is an\n  N-position.\n\n  Finally, let us consider $(a, b, c)$ such that\n  $a \\bitwisexor b \\bitwisexor c = 0$. Assume that there is a move to a\n  position $(a', b, c)$ such that $a' \\bitwisexor b \\bitwisexor c = 0$.\n  This implies that\n  $(a' \\bitwisexor b \\bitwisexor c) \\bitwisexor\n      (a \\bitwisexor b \\bitwisexor c) =  a \\bitwisexor a' = 0$, whence $a = a'$.\n\\end{proof}\n\n\\begin{exercise}\n  Prove that a position $(a_1, \\dots, a_n)$ in $k$-pile Nim is a P-position\n  iff $a_1 \\bitwisexor \\dots \\bitwisexor a_k = 0$.\n\\end{exercise}\n\n\nUsing Bouton's theorem we can analyse games that do not look like the game of\nNim. An important example of such a game is the \\emph{turning turtles} game.\n\\begin{game}[Turning Turtles Game]\n  Given a horizontal line of $m$ coins with some coins showing heads and some\n  tails. Each turn, a player have to flip one coin from head to tail, and in the\n  same time (if he/she wants), flip one more coin to the left of it.\n\\end{game}\nThe game is equivalent to the game of Nim with each coin showing head in $k$th\nposition equals to a pile of $k$ chips.\n\\begin{enumerate}\n  \\item Flip one coin of position $k$ from head to tail. This move is equivalent\n    with removing all stones from a pile with $k$ stones.\n  \\item Flip one coin of position $k$ from head to tail and flip another coin\n    (from tail to head) to the left of it in position $t$. This move is equivalent\n    with removing some stones from a pile with $k$ stones leaving $t$ stones in\n    that pile.\n  \\item Flip one coin of position $k$ from head to tail and flip another coin \n    (from head to tail) to the left of it in position $t$. This move is equivalent\n    with removing some stones from a pile with $k$ stones leaving $t$ stones in that\n    pile. Note that having two piles with a same number of stones is the same as\n    having none of both piles by Bouton's theorem and the fact that \n    $x \\bitwisexor x = 0$.\n\\end{enumerate}\n\n\\section{Error-correcting Codes}\nUsing developed methods we may solve the following question about an extension\nof the game discussed in \\Cref{chapter:strong-induction}:\nAlice has chosen a number from $1$ to $1000$. Bob wants to\nguess the number so he is asking Alice ``yes'' or ``no'' questions.\nHow many questions does Bob need to ask to determine the number in the\nworst-case scenario if Alice may lie to one of Bob's questions?\n\nIt is clear that Bob can use the same strategy as if Alice cannot lie bu ask\nevery question twice and if the answer for the same question are different ask\nit third time. Hence, the number of questions necessary is at most $21$. In this\nsection we show how Bob can guess the number using only $15$ questions.\n\nTo solve this question we need to introduce the notion of error-correcting\ncodes. To illustrate this notion consider completely different scenario.\nTwo people wish to send a number from $\\range{n}$ by sending $m$ bits;\nunfortunately the channel connecting them is not unreliable so among $m$ sent\nbits $d$ may be corrupted, but they still want to be able to reconstruct the\noriginal message. How can they do this? To answer this question we need to\nintroduce error-correcting codes.\n\\begin{definition}\n  Let $x, y \\in \\set{0, 1}^m$ we say that the Hamming distance \n  $\\hammingDist{x}{y}$between $x$ and\n  $y$ is the number of positions where these two strings are different.\n\n  A function $C : \\range{n} \\to \\set{0, 1}^m$ is an error-correcting code\n  correcting $d$ errors if for any $z \\in \\set{0, 1}^m$ there is at most one \n  $i$ such that $\\hammingDist{C(i)}{z} \\le d$.\n\\end{definition}\nIt is clear that if they know such a code, they can send a number from\n$\\range{n}$ and reconstruct it back. We may also note that if Bob knows such a\ncode for $n = 1000$ and $d = 1$, then Bob may guess the Alice's number using $m$\nquestions.\n\n\nHence, to prove that it is enough for Bob to ask 15 questions, we need to show\nthat there is an error-correcting code with $n = 1000$, $m = 15$, and $d = 1$.\nOne may notice that instead of constructing an error correcting code, it is\nenough to construct a set $S \\subseteq \\set{0, 1}^m$ such that $S$ has $n$\nelements and $\\hammingDist{x}{y} \\ge 2d + 1$ for any $x, y \\in S$. Indeed, assume\nsuch a set exists; without loss of generality $S = \\set{x_1, \\dots, x_n}$.\nConsider $C : \\range{n} \\to \\set{0, 1}^m$ such that $C(i) = a_i$. We claim that\n$C$ is an error-correcting code correcting $d$ errors. Assume the opposite;\ni.e., that for some $z$ there are $i$, $j$ such that \n$\\hammingDist{C(i)}{z}, \\hammingDist{C(j)}{z} \\le d$. This implies that \n$\\hammingDist{C(i)}{C(j)} = \\hammingDist{a_i}{a_j} \\le 2d + 1$ which is a\ncontradiction.\n\n\nIn the rest of the section we construct such a set $S$ for $n \\ge 1000$, $m =\n15$, and $d = 1$. Note that any two P-positions in turning turtles are different\nin at least $3$ positions. Hence, let us consider the set \n$S \\subseteq \\set{0, 1}^m$ of P-positions in turning turtles with $m$ coins\n(heads are represented by $0$ and tails are represented by $1$). To finish the\nconstruction of the set, we use the following lemma that we prove in\n\\Cref{chapter:principles}.\n\\begin{lemma}\n\\label{lemma:turning-turtles-number-P}\n  There are at least $2^{2^r - r - 1}$ P-positions in turning turtles with \n  $2^r - 1$ coins.\n\\end{lemma}\n\nCombining this together we prove the following theorem.\n\\begin{theorem}\n  Let $r$ be an integer, let $n = 2^{2^r - r - 1}$, and $m = 2^r - 1$.\n  There is an error-correcting code $C : \\range{n} \\to \\set{0, 1}^m$\n  correcting $1$ error.\\footnote{%\n    Nonetheless that these constructions seem very artificial and theoretical,\n    in fact a code based on a very similar idea, the binary Golay code, was used\n    to encode pictures of Jupiter and Saturn sent by Voyager~1 and Voyager~2.\n  }\n\\end{theorem}\nThe code constructed in this section is called \\emph{Hamming code} and in\n\\Cref{chapter:principles} we will show that it is optimal; i.e., we cannot\nreduce $m$ without reducing $n$.\n\n\\begin{chapterendexercises}\n  \\exercise \\emph{Nimble} is a game played on a board made of a line of squares\n    labeled $0$, $1$, \\dots A finite number of coins is placed on squares with\n    possibly more than one coin on a square. A move consists in taking one coin\n    and moving it to any square to the left, possibly over some coins and\n    possibly onto a square containing some coins. Players, as usual, alternate\n    moves and the game ends when all the coins are on the square $0$. The last\n    player to move wins. Determine P- and N-positions in this game.\n  \\exercise In \\emph{staircase Nim}, a staircase of $n$ steps contains coins of\n    some of the steps. We can describe any position by a tuple $(a_1, \\dots, a_n)$,\n    where $a_i$ is the number of coins on the $i$th step. A move in staircase\n    Nim consists of moving any number of coins from the $i$th step to \n    $(i - 1)$th step. Coins reaching the ground (step $0$) are removed from the\n    play. The game ends when all the coins are removed. Players alternate moves;\n    the last player to move wins. Show that $(a_1, \\dots, a_n)$ is a P-position\n    if coins on odd steps $(x_1, x_3, \\dots)$ form a P-position in the game of\n    Nim.\n  \\exercise In \\emph{index-$k$ Nim} players can remove chips from at least\n    one but up to $k$ different piles. Show that $(a_1, \\dots, a_n)$ is a\n    P-position in index-$k$ Nim iff \n    $\\sum_{j = 1}^n b_{j, i} \\equiv 0 \\pmod{k + 1}$ for every \n    $i \\in \\set{0, 1, \\dots, \\ell}$, where $(b_{j, \\ell} \\dots b_{j, 0})_2$ is\n    the binary representation of $a_j$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "e16644069f1ef88c01523ea4bb146283653c7b19", "size": 11612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_2/chapter_11_the_game_of_nim.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_2/chapter_11_the_game_of_nim.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_2/chapter_11_the_game_of_nim.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": 50.2683982684, "max_line_length": 84, "alphanum_fraction": 0.6959180158, "num_tokens": 3750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.6604850390871154}}
{"text": "\\section{Linear Scalable Transformer\rmodel}\n\nAs stated earlier, the proposed model proposes the replacement of the\rscaled dot-product attention from original Transformer architecture by a\rkernelized attention with relative positional encoding\r\n\nThe proposed model replaces the scaled-dot-product-attention by a\rkernelized attention with RPE. Following the observations of\r\\citet{shaw2018selfattention} that\raccumulating absolute positional encoding with relative positional\rencoding yield no benefits, the positional encoding is also removed -\ralthough for some specific applications it might be beneficial to\rmaintain it. The algorithm used to calculate each term is chosen\rdynamically to occupy the least memory depending on the sequence lengths\rand embedding dimensions - as memory usage is easier to evaluate\rprecisely than execution time.\r\n\nIn this work we have chosen the following formulation, with\r$\\phi(x) = elu(x) + 1$.\r\n\n\\begin{equation}\nA = \\frac{\\left( \\phi(Q) \\times \\phi(K^T) + S^{rel} \\right)}{\\sum_j \\left( \\phi(Q) \\times \\phi(K^T) + S^{rel} \\right)} \\times V\n\\end{equation}\n\nThis is essentially a combination of two terms: the kernelized attention\rproposed by  \\citet{katharopoulos2020transformers}, and the relative positional encoding proposed by\r\\citet{shaw2018selfattention}. The left\rterm is the score matrix of shape $(L_Q, L_K)$, with a denominator\rwhich scales all rows so that they sum to 1. For the sake of the\rimplementation, the multiplication must be distributed as:\r\n\n\\begin{equation}\nA = \\frac{\\left( \\phi(Q) \\times \\phi(K^T) \\times V \\right) + \\left( S^{rel} \\times V\\right)}{\\sum_j \\left( \\phi(Q) \\times \\phi(K^T) \\right) + \\sum_j \\left( S^{rel} \\right)}\n\\end{equation}\n\nThe denominator can be easily calculated by applying the (naive or\rlinear complexity) algorithms with V replaced by a matrix of shape\r$(L_K, 1)$ full of 1.\r\n\nFor each case (masked/bidirectional) the algorithm is chosen between\rnaive and linear complexity to occupy the least memory.\r\n\n\\begin{itemize}\r\n\\item\r\nfor the masked $Q \\times K^T \\times V$ term, the memory occupied by\r\nthe naive algorithm is $L_QL_K$ while the linear complexity\r\nalgorithm occupies $d^2 \\times max(L_Q, L_K)$\r\n\\item\r\nfor the bidirectional $Q \\times K^T \\times V$ term, the memory\r\noccupied by the naive algorithm is $L_QL_K$ while the linear\r\ncomplexity algorithm occupies $d^2$\r\n\\item\r\nfor the $S_{rel} \\times V$ term (masked and bidirectional), the\r\nmemory occupied by the naive algorithm is $L_QL_K$ while the linear\r\ncomplexity algorithm occupies $L_Q \\times (2k+1 + 4)$\r\n\\end{itemize}\n\n\\endinput\n", "meta": {"hexsha": "bccf71fad0ddc1d2f8fea754dd9d348f3570d84e", "size": 2583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/05-scalable-transformer.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/05-scalable-transformer.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/05-scalable-transformer.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": 66.2307692308, "max_line_length": 599, "alphanum_fraction": 0.764614789, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6604850310741168}}
{"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\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\\section*{CHAPTER 1}\n\n\\subsection*{Conjuction Fallacy}\n\\noindent\nThe probability of the joint realization of two events, say $A$ and $B$, cannot be larger than the probability of either of the two events, considered on its own. Denoting the probabilities of the events by $\\mathbb{P}(A)$, $\\mathbb{P}(B)$, and $\\mathbb{P}(A \\cap B)$, the basic law of probability law takes the form,\n\n\\begin{align*}\n\\mathbb{P}(A \\cap B) \\leq \\mathbb{P}(A) \\enspace \\text{  or  } \\enspace \\mathbb{P}(A \\cap B) \\mathbb{P}(B).\n\\end{align*}\n\n\\subsection*{Binary Relations}\n\\noindent\n\\textbf{Definition} A \\textit{Binary Relation}, given sets $X$ and $Y$, is a set $R$ such that\n\n\\begin{equation*}\nR \\subseteq X \\times Y.\n\\end{equation*}\n\n\\noindent\nA binary relation is a set of ordered pairs $xy \\in X \\times Y$, where $xy$ is an abbreviation for $(x,y)$. If $X=Y$, then $R$ is said to be a binary relation on $X$. A binary relations $R$ is a \\textit{quasi order} on a set $X$ if it is \\textit{reflexive} and \\textit{transitive}. That is, for all $x$, $y$, and $z$ in $X$, \n\n\\begin{align*}\nxRx && (\\text{reflexivity}) \\\\\nxRy \\text{ } \\& \\text{ } yRz \\implies xRz && (\\text{reflexivity})\n\\end{align*}\n\n\\noindent\nA binary relation $R$ is an \\textit{equivalence relation} on a set $X$ if it is \\textit{reflexive}, \\textit{transitive}, and \\textit{symmetric} on $X$. for all $x$, $y$, and $z$ in $X$,\n\n\\begin{equation*}\nxRy \\iff yRx.\n\\end{equation*}\n\n\\subsection*{Partitions}\n\\noindent\nThe family $\\mathcal{X} = \\big \\{ [x] \\lvert x \\in X \\big \\}$ of subsets is called a \\textit{partition} of $X$ induced by $\\sim$. Any partition $\\mathcal{X}$ of $X$ satisfies the following three properties,\n\n\\begin{enumerate}\n\\item $Y \\in X$ implies $Y \\neq \\emptyset$;\n\\item $Y,Z \\in \\mathcal{X}$ and $Y \\neq Z$ imply $Y \\cap Z \\neq \\emptyset$;\n\\item $\\cup \\mathcal{X} = X$.\n\\end{enumerate}\n\n\\noindent\nConversely, any family $\\mathcal{X}$ of subsets of a set $X$ satisfying $[1]$, $[2]$, and $[3]$ is called a partition of $X$.\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 2: Sample Spaces}\n\n\\subsection*{The Sample Space}\n\\noindent\nWhat is critical is that all feasible outcomes have a description in the sample space. It is of no importance that the sample space contains outcomes that never happen in practice: in the framework of a probabilistic model, such outcomes may be assigned zero probability. \\\\\n\n\\noindent\nA sample space which is either \\textbf{finite} or \\textbf{countable} is called \\textit{discrete}.  \\\\\n\n\\begin{tcolorbox}\n\\begin{center}\nFinite vs. Countable\n\\end{center}\n\n\\textbf{Finite}: A definite number. Not infinite. In other words it could be measured, or given a value.\n\n\\vspace*{.5cm}\n\n\\textbf{Countable}: Either finite or a countably infinite (implying that the cardinality of a countable set is a subset of $\\N$). Elements of a countable set can always be counted one at a time and, although the counting may never finish, every element of the set is associated with a unique natural number.\n\\end{tcolorbox}\n\n\\subsection*{Concept of an Event}\n\\noindent\nFundamentally, an \\textit{Event} is a subset of the sample space. In general, each event pertaining to a particular experiment may be identified with a subset of the relevant sample space. However, with respect to the converse, the general assumption that all subsets of the sample space are events to which a probability could be assigned would create mathematical difficulties.\n\n\\subsection*{Indicator Functions}\n\\noindent\n\\textbf{Definition}: An \\textit{Indicator Function} is a function defined on a set $\\Omega$ that indicates membership of an element in a subset of $X$ of $\\Omega$. Let $\\Omega$ be a non-empty set and $X$ a subset of $\\Omega$. The indicator function on $X$ is a function $I_x : \\Omega \\rightarrow \\{ 0,1 \\}$ by,\n\n\\begin{equation*}\nI_x(w) =  \\begin{cases} \n      0 & w \\in X \\\\\n      1 & w \\in \\overline{X} \\text{  } (\\text{or } w \\not \\in X)\n   \\end{cases}\n\\end{equation*}\n\n\\noindent\nProperties of Indicator Functions:\n\n\\begin{itemize}\n\\item For subsets $X, Y$ of $\\Omega$, $I_{X \\cap Y}=I_X \\cdot I_Y$, i.e. for every $w \\in \\Omega$, $I_{X \\cap Y}(w)=I_X(w) \\cdot I_Y(w)$.\n\\item $I_{X \\cup Y}=I_X + I_Y - I_{X \\cap Y}$ (if $X,Y$ are disjoint, $I_{X \\cup Y}=I_X + I_Y$)\n\\item $I_{A^C}=1-I_A$\n\\item If $X \\subseteq Y$, then $I_X \\subseteq I_Y$, i.e. $I_X(w) \\leq I_Y(w)$ for every $w \\in \\Omega$.\n\\end{itemize}\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 3: Probability and Area}\n\n\\subsection*{Axioms for a Field}\n\\noindent\n\\textbf{Definition}: Let $\\Omega$ be a set. Let $\\field$ be a nonempty collection of subsets of $\\Omega$ satisfying the axioms\n\n\\begin{adjustwidth}{2.5em}{0pt}\n\\textbf{[F1]} For all $A, B \\in \\field$, $A \\cup B \\in \\field$.\n\n\\vspace{.1cm}\n\\noindent\n\\textbf{[F2]} For each $A \\in \\field$, $\\overline{A} \\in \\field$ also.\n\\end{adjustwidth}\n\n\\vspace{.5cm}\n\\noindent\n\\textbf{Theorem 3.2:} Let $\\field$ be a field of subsets of $\\Omega$. Then, \n\\begin{frame}{}\n\\begin{enumerate}[label=(\\roman*)]\n\\item $\\Omega \\in \\field$\n\\item $\\emptyset \\in \\field$\n\\item For all $A, B \\in \\field$, $A \\setminus B = A \\overline{B} \\in \\field$\n\\item $\\bigcup\\limits_{i=1}^{n} A_i \\in \\field$\n\\item $\\bigcap\\limits_{i=1}^{n} A_i \\in \\field$\n \\makebox(0,0){\\put(3,5\\normalbaselineskip){%\n               $\\left.\\rule{0pt}{2.2\\normalbaselineskip}\\right\\}$ $\\field$ is closed under finite union \\textbf{and} finite intersection}}\n\\end{enumerate}\n\\end{frame}\n\n\\subsection*{Infinite Sample Spaces and $\\sigma$-Fields}\n\\noindent\n\\textbf{Definition}: A field $(\\Omega, \\field)$ is called a $\\sigma$-field if it is \\textit{closed under countable union}, that is, if for any countable collection $A_1, \\ldots, A_n, \\ldots$ of sets in $\\field$, we have $\\bigcup_{n=1}^{\\infty} A_n \\in \\field$. Note that for any sets $A_1, \\ldots, A_n, \\ldots$, we have\n\n\\begin{equation*}\n\\bigcap_{n=1}^{\\infty} A_n = \\overline{\\bigcup_{n=1}^{\\infty} \\overline{A_n}}\n\\end{equation*}\n\n\\noindent\nAs a $\\sigma$-field, $\\field$ is closed under both countable union and complementation. We conclude that $\\field$ is also closed under countable intersection.\n\n\\subsection*{Borel Fields}\n\\noindent\nRecall that a set $S$ of real numbers is an \\textit{open} set of $\\R$ if for any $x \\in S$, there exists some $\\delta > 0$ such that whenever $\\lvert x - y \\rvert < \\delta$, then $y \\in S$. The standard family of events for $\\R$ is a distinguished $\\sigma$-field $\\mathcal{B}$ containing all the open sets of $\\R$. In fact, $\\mathcal{B}$ is the `smallest' $\\sigma$-field containing these open sets. The collection $\\mathcal{B}$ is called the \\textit{Borel Field} of $\\R$, and the events in $\\mathcal{B}$ are referred to as the \\textit{Borel sets} of $\\R$. These definitions extend naturally to the case where all the sample space is $\\R^n$. \n\n\\begin{center}\n\\includegraphics[width=9cm, height=5cm]{probthoerycommonterms}\n\\end{center}\n\n\\noindent\n\\subsection*{General Strategy}\nWe start with a field of sets $\\field$ on a set $\\Omega$. Then, we introduce the concept of a probability measure $\\mathbb{P}$ as a function assigning a number $\\mathbb{P}(A)$, with $0 \\leq \\mathbb{P}(A) \\leq 1$, to every event $A$ in $\\field$. This function $\\mathbb{P} : \\field \\rightarrow [0,1]$ will be assumed to satisfy a number of axioms (given in Ch. 4). The probability measure $\\mathbb{P}$ is not assumed in general to be defined on all subsets of the sample space due to the case of an uncountable sample space leading to a contradiction.\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 4: Probability Measures}\nWe shall define a probability measure $\\mathbb{P}$ as a function assigning a number $\\mathbb{P}(A)$ to each event in $A$ in a field $\\field$. For all events $A$, $\\mathbb{P}$ will satisfy the following conditions,\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item $\\mathbb{P}(\\Omega) = 1$;\n\\item $0 \\leq \\mathbb{P}(A) \\leq 1$;\n\\item $\\mathbb{P}(A \\cup B) = \\mathbb{P}(A) + \\mathbb{P}(B)$ for incompatible events $A,B$;\n\\item $\\mathbb{P}(\\bigcup_{i=1}^{n}) = \\sum_{i=1}^{n} \\mathbb{P}(A_i)$ for pairwise incompatible events $A_1, \\ldots, A_n$ (\\textit{finite additivity});\n\\end{enumerate}\n\n\\noindent\nBy requiring that if $A_1, \\ldots, A_i, \\ldots$ is a countably infinite sequence of pairwise incompatible events, then $\\bigcup_{i=1}^{n} A_i$ is an event. Moreover, \n\n\\begin{equation}\n\\mathbb{P} \\big ( \\bigcup_{i=1}^{\\infty} \\big ) = \\sum_{i=1}^{\\infty} \\mathbb{P}(A_i).\n\\end{equation}\n\n\\subsection*{Finitely Additive Probability Space}\nLet $\\field$ be a field of sets on $\\Omega$. Then, the triple $(\\Omega, \\field, \\mathbb{P})$ is a \\textit{finitely additive probability space} iff $\\mathbb{P}$ is a real valued function on $\\field$ satisfying the following three conditions: For all $A,B \\in \\field$,\n\n\\begin{itemize}\n\\item $[K1] \\mathbb{P}(\\Omega) = 1$;\n\\item $[K2] \\mathbb{P}(A) \\geq 0$;\n\\item $[K3]$ if $A \\cap B = 0$, then $\\mathbb{P}(A \\cup B) = \\mathbb{P}(A) + \\mathbb{P}(B)$;\n\\end{itemize}\n\n\\noindent\nThe function $\\mathbb{P}$ is called a \\textit{probability measure}. In the special case where $\\field$ is a $\\sigma$-field, \n\n\\begin{equation}\n\\mathbb{P} \\big ( \\bigcup_{i=1}^{\\infty} \\big ) = \\sum_{i=1}^{\\infty} \\mathbb{P}(A_i)\n\\end{equation}\n\n\\noindent\nholds for any countable family $\\big \\{ A_i \\lvert i \\in \\N \\big \\}$ of pairwise disjoint events, then $(\\Omega, \\field, \\mathbb{P})$ is called a \\textit{probability space}. \\\\\n\n\\subsection*{Probability and Counting Measure}\n\\noindent\nSuppose that $\\Omega$ is a finite set, and let $\\field$ be a field of its subsets. For any event $A \\in \\field$, we define\n\n\\begin{equation*}\n\\prob{A} = \\frac{\\lvert A \\rvert}{\\lvert \\Omega \\rvert}\n\\end{equation*}\n\n\\noindent\nThe value of the probability measure on $\\mathbb{P}$ for a particular event $A$ is the ratio of the number of elements of $A$ to the total number of elements in the sample space $\\Omega$. The probability measure is sometimes called the \\textit{counting measure} and is appropriate when it makes sense to attribute an equal weight or likelihood to each point of the sample space.\n\\subsection*{Probability Distribution}\n\n\\noindent\n\\textbf{Definition}: Let $\\Omega$ be a finite or countable sample space. Then $p$ is a \\textit{probability distribution} on $\\Omega$ iff $p$ is a real valued function on $\\Omega$ satisfying\n\n\\begin{align*}\np(x) \\geq 0 \\text{ for all } x \\in \\Omega; \\\\\n\\sum_{x \\in \\Omega} p(x) = 1.\n\\end{align*}\n\n\\noindent\n\\textbf{Theorem}: Let $\\field$ be a field of sets on a finite or countable sample space $\\Omega$, and let $p$ be a probability distribution on $\\Omega$. Define a function $\\mathbb{P}$ on $\\field$ by\n\n\\begin{equation}\n\\mathbb{P}(A) = \\sum_{x \\in A} p(x),\n\\end{equation}\n\n\\noindent\nfor all $A \\in \\field$. Then $(\\Omega, \\field, \\mathbb{P})$ is a \\textit{probability space}. When $(A_i)_{i \\in I}$ is a sequence of pairwise events, with the index set $I$ being finite or countable, and each of the events $A_i$ being finite or countable, \n\n\\begin{align*}\n\\sum_{i \\in I} \\mathbb{P}(A_i) & = \\sum_{i \\in I} \\sum_{x \\in A_i} p(x) \\\\\n& = \\sum_{x \\in \\bigcup_{i \\in I} A_i} p(x) \\\\\n& = \\mathbb{P}(\\bigcup_{i \\in I} A_i)\n\\end{align*}\n\n\\subsection*{Remarks}\n\\noindent\nThe material in this chapter suggests that the notions of a field of events and of a probability measure are only considered with finite or countable sample spaces because the probability of any subset of the sample space could be computed from the probability distribution. With uncountable sample spaces, the notion of a probability distribution is useless. It turns out that `probability density functions' is a conceptual notion related to that of probability distributions.\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 5: Basic Rules of Probability Calculus}\n\\noindent\n\\textbf{Theorem}: Let $\\Omega$ be a sample space, and $(\\Omega, \\field, \\mathbb{P})$ a finite additive probability space. We do note assume that $\\Omega$ or $\\field$ are finite. Then, for any events $A,B,C \\in \\field$,\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item $\\prob{A} + \\prob{\\overline{A}} = 1$\n\\item $\\prob{\\emptyset}=0$\n\\item If $A_1, \\ldots, A_n$ are incompatible events in $\\field$, then\n\n\\begin{equation*}\n\\mathbb{P} \\Big ( \\sum_{j=1}^{n} A_j \\Big ) = \\sum_{j=1}^{n} \\prob{A_j}\n\\end{equation*}\n\n\\item If $A \\subseteq B$, then $\\prob{A} \\leq \\prob{B}$\n\\item $\\prob{A \\cup  B} = \\prob{A} + \\prob{B} - \\prob{A \\cap B}$\n\\item \n\n\\begin{align*}\n\\prob{A \\cup B \\cup C} =  \\enspace & \\prob{A} + \\prob{B} + \\prob{C} \\\\\n& - \\prob{AB} - \\prob{AC} - \\prob{BC} \\\\\n& + \\prob{ABC}\n\\end{align*}\n\n\\item $\\prob{A\\overline{B}} = \\prob{A \\setminus B} = \\prob{A} - \\prob{AB}$\n\\end{enumerate}\n\n\\subsection*{Poincar\\'{e}'s Identity}\n\\noindent\nWe write $S(k,n)$ for the collection of subsets of the set $\\{ 1, \\ldots, n \\}$ containing exactly $k$ elements, with $1 \\leq k \\leq n$. For any finite collection $A_1, \\ldots, A_n$ of events, we have\n\n\\begin{equation*}\n\\prob{\\bigcup_{i=1}^{n} A_i} = \\sum_{i=0}^{n-1} (-1)^i \\sum_{J \\in S(i_1, n)} \\prob{\\bigcap_{k \\in J} A_k}\n\\end{equation*}\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 6}\n\\subsection*{Sampling with Replacement and with Ordering}\n\\noindent\nLet $A_1, A_2, \\ldots, A_n$ be $n$ finite sets containing $m_1, m_2, \\ldots, m_n > 0$ points, respectively. Then, \n\n\\begin{equation}\n\\lvert A_1, A_2, \\ldots, A_n \\rvert = m_1 \\cdot m_2 \\ldots \\cdot m_n\n\\end{equation}\n\n\\noindent\nIn a set containing $n > 0$ elements, there are exactly $n^m$ ordered samples of size $m \\geq 1$, with replacement.\n\n\\subsection*{Sampling without Replacement and with Ordering}\nThe number of ordered samples of size $m$ without replacement, in a set of $n \\geq m > 1$ elements, is equal to \n\n\\begin{equation*}\n(n)_m = n(n-1) \\cdot \\ldots \\cdot (n-m+1) = \\frac{n!}{(n-m)!}\n\\end{equation*}\n\n\\noindent\nThe first equality defines the notation $(n)_m$. We have thus $(n)_n = n!$.\n\n\\subsection*{Stirling's Formula}\n\\noindent\nFor any positive integer $n$, we have \n\n\\begin{equation}\nn! \\sim (2 \\pi)^{\\frac{1}{2}} n^{n + \\frac{1}{2}} e^{-n}.\n\\end{equation}\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 7}\n\\subsection*{Binomial Coefficient}\n\\noindent\nIn a set of size $n \\geq 0$, the number of subsets of size $m \\geq 0$ is equal to \n\n\\begin{equation*}\n{n \\choose m} = \\frac{n!}{m! (n-m)!}.\n\\end{equation*}\n\n\\noindent\nThe coefficient ${n \\choose m}$ is called the binomial coefficient and is used in the \\textit{binomial theorem}. It represents the number of ways of splitting a set of $n$ elements into two subsets containing $n-m$ and $m$ elements with $0 \\leq m \\leq n$.\n\n\\subsection*{Binomial Theorem}\n\\noindent\nLet $a$ and $b$ be any two real number, and let $n$ be a positive integer. Then, \n\n\\begin{equation*}\n(a+b)^n = \\sum_{k=0}^{n} {n \\choose k} a^k b^{n-k}.\n\\end{equation*}\n\n\\noindent\nWe can generalize this theorem to satisfy the following when $0 \\leq m \\leq n$,\n\n\\begin{align*}\n{n \\choose m} & = {n \\choose n-m}; \\\\\n{n \\choose m} & = {n-1 \\choose m-1} + {n-1 \\choose m}; \\\\\n2^n & = {n \\choose 0} + {n \\choose 1} + \\cdots + {n \\choose n} = \\sum_{k=0}^{n} {n \\choose k}. \\\\\n\\end{align*}\n\n\\subsection*{Multinomial Coefficient}\n\\noindent\nIn attempts to generalize the binomial coefficient, we define the \\textit{multinomial coefficient}. It will later be used in the definition of the \\textit{multinomial distribution}. There are exactly\n\n\\begin{equation*}\n{n \\choose m_1 m_2 \\ldots m_k} = \\frac{n!}{m_1! \\cdot m_2! \\cdot \\ldots \\cdot m_k!}\n\\end{equation*}\n\n\\noindent\nways of splitting a set containing $n \\geq 0$ elements into $k \\geq 0$ subsets containing $m_1, m_2, \\ldots, m_k$ elements with $m_1 + m_2 + \\ldots + m_k = n$ and $m_i \\geq 0$ for $i = 1, 2, \\ldots, k$.\n\n\\subsection*{Multinomial Theorem}\n\\noindent\n\\noindent\nLet $a_1, a_2, \\ldots, a_k$ be any $k$ real numbers, and let $n$ be a positive integer. Then,\n\n\\begin{equation*}\n(a_1 + a_2 + \\ldots + a_k)^n = \\sum_{(m_1, m_2, \\ldots, m_k)} {n \\choose m_1 m_2 \\ldots m_k} a_1^{m_1} a_2^{m_2} \\cdots a_k^{m_k},\n\\end{equation*}\n\n\\noindent\nwhere the summation runs over all $k$-tuples $(m_1, m_2, \\ldots, m_k)$ of non-negative integers $m_i$, $0 \\leq i \\leq k$, satisfying $\\sum_{i=1}^{k} m_1 = n$.\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 8: Discrete Distributions}\nFive cases of discrete distributions are considered in this chapter. In the first three cases, the sample space is finite. \n\n\\subsubsection*{Bernoulli Distribution}\n\\noindent\nRecall that a \\textit{probability distribution} is a real valued function $p$ defined on a finite or countable sample space $\\Omega$ and satisfying the two conditions:\n\n\\begin{enumerate}\n\\item $p(x) \\geq 0$ for all $x \\in \\Omega$;\n\\item $\\sum_{x \\in \\Omega} p(x) = 1$.\n\\end{enumerate}\n\n\\noindent\nLet $\\Omega = \\{ 0,1 \\}$ be a sample space, and let $\\alpha$ be any real number, with $0 \\leq \\alpha \\leq 1$. The probability distribution $p$ defined on $\\Omega$ by \n\n\\begin{equation*}\np(x) =  \\begin{cases} \n      \\alpha & \\text{if } x = 1 \\\\\n      1-\\alpha & \\text{if } x = 0\n      \\end{cases}\n\\end{equation*}\n\n\\noindent\nis called a \\textit{Bernoulli distribution} with parameter $\\alpha$. Any probability distribution on the sample space $\\Omega$ is a Bernoulli distribution because there is always some parameter $\\alpha \\geq 0$ satisfying the above equation. \n\n\\subsubsection*{Bernoulli Distribution: Empirical Situation}\n\\noindent\nAn experimenter is selecting a single ball from an urn containing only black and white balls in proportions $\\alpha$ and $1-\\alpha$, respectively. When a black ball is selected, $1$ is recorded; otherwise, $0$ is recorded.\n\n\\subsubsection*{Binomial Distribution}\nLet $\\Omega = \\{ 0, 1, \\ldots, n \\}$ be a sample space, with $n$ a positive integer, and let $\\alpha$ be any real number, with $0 \\leq \\alpha \\leq 1$. The probability distribution $p$ defined on $\\Omega$ by\n\n\\begin{equation*}\np(m) = {n \\choose m} a^m (1 - \\alpha)^{n-m}\n\\end{equation*}\n\n\\noindent\nis called a \\textit{binomial distribution} with parameters $\\alpha$ and $n$.\n\n\\subsubsection*{Binomial Distribution: Empirical Situation}\n\\noindent\nAn experimenter is selecting $n$ balls, with replacement, from an urn containing only black and white balls. The probability of getting a black ball if a single ball is selected is equal to $\\alpha$. The number $m$ of black balls obtained is recorded.\n\n\\subsubsection*{Multinomial Distribution}\n\\noindent\nLet $n$ and $k$ be two integers with $n \\geq k > 0$. Let the sample space $\\Omega$ be the set of all $k$-tuples $(m_1, m_2, \\ldots, m_k)$ of non-negative integer satisfying $\\sum_{i=1}^{k} m_i=n$. Let $\\alpha_1, \\ldots, \\alpha_k$ be non-negative real numbers satisfying $\\sum_{k=1}^{i=1} \\alpha_i = 1$. The probability distribution $p$ defined on $\\Omega$ by the equation\n\n\\begin{equation*}\np(m_1, m_2, \\ldots, m_k) = {n \\choose m_1 \\text{ } m_2 \\cdots m_k } a_1^{m_1} a_2^{m_2} \\cdots a_k^{m_k}\n\\end{equation*}\n\n\\noindent\nis called the \\textit{multinomial distribution} with parameters $\\alpha_1, \\ldots, \\alpha_k$ and $n$.\n\n\\subsubsection*{Multinomial Distribution: Empirical Situation}\n\\noindent\nAn experimenter is sampling balls with replacement from an urn containing $k$ different types of balls, numbered $1 \\ldots k$. If a single ball is selected from the urn, the probability that it is a ball of type $i$ $(1 \\leq i \\leq k)$ is equal to $\\alpha_i$; thus, $(0 \\leq i \\leq k)$. Suppose $n$ balls are sampled, and that the experimenter records the number $m_i$ of balls of each type.\n\n\\subsubsection*{Geometric Distribution}\n\\noindent\nLet $\\Omega = \\{ 1, 2, \\ldots, n, \\ldots \\}$ be the sample space, and let $\\alpha$ be a real number with $0 < \\alpha < 1$. The function $p$ defined on $\\Omega$ by the equation\n\n\\begin{equation*}\np(n) = \\alpha ( 1-\\alpha )^{n-1}\n\\end{equation*}\n\n\\noindent\nis called the \\textit{geometric distribution} with parameter $\\alpha$. The function $p$ is clearly non-negative.\n\n\\subsubsection*{Geometric Distribution: Empirical Situation}\n\\noindent\nAn experimenter is drawing balls with replacement from an urn containing black and white balls. We suppose that the probability of drawing a black ball is a constant $\\alpha$. The drawing is continued until the first black ball is drawn. The experimenter only records the number of the particular trial where this occurs. Thus, if the first black ball is drawn on trial $5$, the experimenter records the number $5$ as the outcome of the experiment.\n \n\\subsubsection*{Poisson Distribution}\n\\noindent\nLet $\\Omega = \\{ 0, 1, 2, \\ldots, n, \\ldots \\}$ be the sample space, and let $\\lambda$ be a positive real number. The probability distribution $p$ defined on $\\Omega$ by the equation\n\n\\begin{equation*}\np(k) = e^{- \\lambda} \\frac{\\lambda^k}{k!}.\n\\end{equation*}\n\n\\noindent\nis called a \\textit{Poisson distribution} with parameter $\\lambda$. \n\n\\subsubsection*{Poisson Distribution: Empirical Situation}\n\\noindent\nAn experimenter is watching a display for the appearance of signals of some kind. We suppose that these signals have the following characteristics: they are punctual; the occurrence of a signal has no effect on the occurrence of the next one; and the occurrence of the signals is random but homogeneous, in the sense that the signal is just as likely to occur within one interval of time of a given length within some other interval of the same length. \n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 9: Conditional Probability}\n\n% TODO: Look into this more...\n\n\\noindent\nThe conditional probability of some event $A$ `given' an event $B$ is the probability that $A$ occurs when we know for sure that $B$ must also occur (or has occurred). The usual notation is $\\condprob{A}{B}$. Let $(\\Omega, \\field, \\mathbb{P})$ be a finite additive probability space. For all events $A,B$ such that $\\prob{B} \\neq 0$, we define\n\n\\begin{equation*}\n\\condprob{A}{B} = \\frac{\\prob{A \\cap B}}{\\prob{B}}.\n\\end{equation*}\n\n\\subsection*{Some Consequences of Conditional Probability}\n\\noindent\n\\textbf{Theorem}: Suppose that $(\\Omega, \\field, \\mathbb{P})$ is a finitely additive probability space. For all events $A,B,$ and $C$, such that $\\prob{C} \\neq 0$, we have\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item $\\condprob{\\Omega}{C} = 1$;\n\\item $\\condprob{A}{C} \\geq 0$;\n\\item if $A \\cap B \\neq \\emptyset$, then $\\condprob{A \\cup B}{C} = \\condprob{A}{C} + \\condprob{B}{C}$;\n\\item if $A \\cap B \\neq \\emptyset$, then $\\condprob{A}{C} = 0$;\n\\item if $\\prob{A} \\neq 0$, then $\\condprob{A}{C} = \\frac{\\prob{A} \\condprob{C}{A}}{\\prob{C}}$.\n\\end{enumerate}\n\n\\noindent\n\\textbf{Theorem}: Suppose that $(\\Omega, \\field, \\mathbb{P})$ is a finitely additive probability space. Let $C$ be some event such that $\\prob{C} \\neq 0$. For any $A \\in \\field$, define $\\mathbb{P}_C(A) = \\condprob{A}{C}$. Then $(\\Omega, \\field, \\mathbb{P}_C)$ is a finitely additive probability space.\n\n% What is the proof for this? \n\\noindent\nWhen we condition by some event $C \\in \\field$, with $C \\neq \\Omega$, it is almost as if we were restricting consideration to a smaller sample space $C \\subseteq \\Omega$. For example, suppose that $A \\cap C$ and $B \\cap C$ are two incompatible events, and that $\\prob{C} \\neq 0$. It is not difficult to show that\n\n\\begin{equation*}\n\\condprob{A \\cup B\t}{C} = \\condprob{A}{C} + \\condprob{B}{C},\n\\end{equation*}\n\n\\noindent\nwhich is essentially the defining additivity property of probabilities holding for smaller sample space $C$.\n\n\\subsection*{Theorem of Total Probabilities}\n\\noindent\nThe idea here is that the probability of an event $A$ can in many cases be decomposed additively in terms of the probabilities of other events that \\textit{cover} $\\Omega$. The idea is to decompose the probability of $A$ through the sum\n\n\\begin{equation*}\n\\prob{A} = \\prob{A \\cup H_1} + \\prob{A \\cup H_2} + \\ldots + \\prob{A \\cup H_n} .\n\\end{equation*}\n\n\\noindent\nNote that $\\condprob{A}{H_i} \\prob{H_i} = \\prob{A \\cap H_i}$ for $1 \\leq i \\leq n$. For events $E_1, E_2, \\ldots, E_n$ that are pairwise incompatible, the notation $\\sum_{i=1}^{n} E_i$ has the same meaning as the notation $\\bigcup_{i=1}^{n} E_i$. Thus, we can more formally define the \\textit{Theorem of Total Probabilities}. \\\\\n\n\\noindent\n\\textbf{Theorem}: Let $(H_i)_{1 \\leq i \\leq n}$ be a family of pairwise incompatbile events in a finitely additive probability space $(\\Omega, \\field, \\mathbb{P})$, such that $\\sum_{i=1}^{n} H_i = \\Omega$. Then, for all $A \\in \\field$,\n\n\\begin{equation*}\n\\prob{A} = \\sum_{i=1}^{n} \\prob{A \\cap H_i}.\n\\end{equation*}\n\n\\noindent\nIf $\\prob{H_i} \\neq 0$, for all $i$, $1 \\leq i \\leq n$, then\n\n\\begin{equation*}\n\\prob{A} = \\sum_{i=1}^{n} \\condprob{A}{H_i} \\prob{H_i}.\n\\end{equation*}\n\n\\subsection*{Remarks}\n\\noindent\nThe theorem presented in this section represents results based on a finite set of events. Versions of this theorem also hold in the cases of countable and uncountable collections of events $H_i$, but the probabilities of joint events $A \\cap E_i$ are replaced by a joint density function.\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 10: Independence \\& Bayes' Theorem}\n\\noindent\nIn a finite additive probability space $(\\Omega, \\field, \\mathbb{P})$, two events $A,B$ are independent if\n\n\\begin{equation*}\n\\prob{A \\cap B} = \\prob{A}\\prob{B}.\n\\end{equation*}\n\n\\noindent\nAn event $A$ is \\textit{independent} of some event $B$ when knowing that $B$ is realized does not affect the probability of $A$. It is not required that $\\prob{A}, \\prob{B} > 0$. However, if $\\prob{A} = 0$, then $\\prob{A \\cap B} = 0$, since $A \\cap B \\subseteq A$, and $\\prob{A \\cap B} = \\prob{A}\\prob{B} = 0$. An event of probability zero is thus independent of any other event. Suppose that $A$ and $B$ are two independent events in a finite additive probability space $(\\Omega, \\field, \\mathbb{P})$. Then,\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item $\\overline{A}$ and $B$ are independent;\n\\item if $\\prob{B} \\neq 0$, then $\\prob{A \\lvert B} = \\prob{A}$.\n\\end{enumerate}\n\n\\subsection*{Bayes Theorem}\nLet $(H_i)_{1 \\leq i \\leq n}$ be a family of pairwise incompatible events in a finitely additive probability space $(\\Omega, \\field, \\mathbb{P})$, satisfying $\\bigcup_{i=1}^{n} H_i = \\Omega$ and $\\prob{H_i} \\neq 0$, for all $i, 1 \\leq i \\leq n$. If $D \\in \\field$ is any event such that $\\prob{D} \\neq 0$, then, for $1 \\leq i \\leq n$, \n\n\\begin{equation*}\n\\prob{H_i \\lvert D} = \\frac{\\prob{D \\lvert H_i}\\prob{H_i}}{\\sum_{j=1}^{n} \\prob{D \\lvert H_j}\\prob{H_j}}.\n\\end{equation*}\n\n\\subsection*{Remarks}\n\\noindent\nThe events $H_i$ are called \\textit{hypotheses} and $\\prob{H_i}$ is called \\textit{a priori probability} of hypothesis $H_i$. The conditional probability $\\condprob{H_i}{D}$ is referred to as the \\textit{a posteriori probability} provided by the realization of the event $D$. Suppose that some experiment has been performed, and some `data' (the event $D$) have been collected. A number of alternative `theories' are considered. An intuitively appealing question is: what are the `respective probabilities' of the various theories, given the data? Bayes Theorem suggests that such `probabilities' might perhaps be recomputed from the a priori probabilities of these hypotheses via the system of equations for $1 \\leq i \\leq n$. For instance, in what sense can we talk about the `probability' of a theory? \n\\end{document} ", "meta": {"hexsha": "930ec5b87c359c76b06e46a0fde12461de93e838", "size": 30113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability-theory/exam-review/exam-1/E1_REVIEW.tex", "max_stars_repo_name": "jShiohaha/math-classes", "max_stars_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "probability-theory/exam-review/exam-1/E1_REVIEW.tex", "max_issues_repo_name": "jShiohaha/math-classes", "max_issues_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "probability-theory/exam-review/exam-1/E1_REVIEW.tex", "max_forks_repo_name": "jShiohaha/math-classes", "max_forks_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.8694096601, "max_line_length": 805, "alphanum_fraction": 0.6392255836, "num_tokens": 9100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140728, "lm_q2_score": 0.843895100591521, "lm_q1q2_score": 0.6604850228490601}}
{"text": "\n\\subsection{Bias and variance of the Robinson estimator}\n\nrobinson: can't have confounded in dummy. but can in real. general result of propensity stuff?\n\nFraming: Partialling out is an alternative to OLS where \\(n<<p\\) doesn't hold. alterntive to LASSO etc\n\n\\(\\hat \\theta \\approx N(\\theta, V/n)\\)\n\n\\(V=(E[\\hat D^2)^{-1}E[\\hat D^2\\epsilon^2 ](E[\\hat D^2])^{-1}\\)\n\nThese are robust standard errors. \n\n\\subsubsection{Moments of the Robinson estimator}\n\nIf IID then\n\n\\(Var (\\hat \\theta) =\\dfrac{\\sigma^2_\\epsilon }{\\sum_i(x_i-\\hat X_i)^2}\\)\n\nOtherwise, can use GLM\n\nWhat are the properties of the estimator?\n\n\\(E[\\hat \\theta ]=E[\\dfrac{\\sum_i (X_i-\\hat X_i)(y_i-\\hat y_i)}{\\sum_i(x_i-\\hat X_i)^2}]\\)\n\n\n\\subsection{Non-linear treatment effects in the Robinson estimator}\n\nPage on reformulating as non-linear. can do it. show can be estimated using arg min\nhttps://arxiv.org/pdf/1712.04912.pdf\n\n\n\\subsection{DML}\n\nin DML. page on orthogonality scores, page on constructing them; page on using them to estimate parameters (GMM)\n\nWe have \\(P(X)=f(\\theta , \\rho)\\)\n\\(\\hat \\theta = f(X, n)\\)\n\\(\\theta = g(\\rho , X)\\)\n\nSo error is:\n\\(\\hat \\theta - \\theta=f(X, n)-g(\\rho , X)\\)\n\nBias is defined as:\n\\(Bias(\\hat \\theta, \\theta ) = E[\\hat \\theta - \\theta]=E[\\hat \\theta ] - \\theta \\)\n\\(Bias = E[\\hat \\theta - \\theta]=E[f(X, n)-g(\\rho , X)]\\)\n\\(Bias = E[\\hat \\theta - \\theta]=E[f(X, n)]-g(\\rho ,X)\\)\n\ndouble ML: regression each parametric parameter on ML of other variables.\neg: get \\(e(x|z)\\)\n\\(e(d|x)\\)\n\\(d=m(x)+v\\)\n\\(d\\) is correlated with \\(x\\) so bias.\n\\(v\\) is corrleated with \\(d\\) but not \\(x\\). use as \"iv\".\nStill need estimate for \\(g(x)\\).\n\nfor iterative, process is:\n+ estimate \\(g(x)\\)\n+ plug into other and estimate theta\n+ this section should be in sample splitting. rename iterative estimation. separate pages for bias, variance\n+ how does this work?? paper says random forest regression and OLS. intialise \\(\\theta \\) randomly?\n+ page on bias, variance, efficiency?\n+ page on sample splitting, why?\n\n+ page on goal: \\(x\\) and \\(z\\) orthogonal for split sampling\n+ page on \\(X=m_0(Z)+\\mu\\), first stage machine learning, synthetic instrumental variables? h3 on that for multiple variables on interest. regression for each\n\n\\subsection{DML1}\nDivide into \\(k\\).\n\nFor each do ML on nuicance (how???) use all instances outside of sample\n\nThen do GMM using orthogonality condition to calculate \\(\\theta \\). (how??) use instances in sample\n\nAverage \\(\\theta \\) from each class\n\n\n\\subsection{Last stage Robinson}\n\nSeparate page for last stage: note we can do OLS, GLS etc with choice of \\(\\Omega \\).\n\n\n\n", "meta": {"hexsha": "21dcbdaf14c35a4d8485f83407bb300e27140f3a", "size": 2598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/semiParametric/01-03-robinsonBV.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/semiParametric/01-03-robinsonBV.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/semiParametric/01-03-robinsonBV.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9285714286, "max_line_length": 158, "alphanum_fraction": 0.6836027714, "num_tokens": 778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924954, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.6604750827292251}}
{"text": "\\chapter{Floating Point Numbers}\n\\label{chapter:floatingpoint}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{IEEE-754 Floating Point Number Representation}\n\\label{chapter::floatingpoint}\n\nThis section provides an overview of the IEEE-754 32-bit binary floating \npoint format.\\cite{ieee:754}\n\n\\begin{itemize}\n\\item Recall that the place values for integer binary numbers are:\n\\begin{verbatim}\n   ... 128 64 32 16 8 4 2 1\n\\end{verbatim}\n\\item We can extend this to the right in binary similar to the way we do for \ndecimal numbers:\n\\begin{verbatim}\n   ... 128 64 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16 1/32 1/64 1/128 ...\n\\end{verbatim}\nThe `.' in a binary number is a binary point, not a decimal point.\n\n\\item We use scientific notation as in $2.7 \\times 10^{-47}$ to express either \nsmall fractions or large numbers when we are not concerned every last digit \nneeded to represent the entire, exact, value of a number.\n\n\\item The format of a number in scientific notation is $mantissa \\times base^{exponent}$\n\n\\item In binary we have $mantissa \\times 2^{exponent}$\n\n\\item IEEE-754 format requires binary numbers to be {\\em normalized} to \n$1.significand \\times 2^{exponent}$ where the {\\em significand}\nis the portion of the {\\em mantissa} that is to the right of the binary-point.\n\n\\begin{itemize}\n\\item The unnormalized binary value of $-2.625$ is $-10.101$\n\\item The normalized value of $-2.625$ is $-1.0101 \\times 2^1$\n\\end{itemize}\n\n\\item We need not store the `1.' part because {\\em all} normalized floating \npoint numbers will start that way.  Thus we can save memory when storing\nnormalized values by inserting a `1.' to the left of significand.\n\n{\n\\small\n\\setlength{\\unitlength}{.15in}\n\\begin{picture}(32,4)(0,0)\n\t\\put(0,1){\\line(1,0){32}}\t\t% bottom line\n\t\\put(0,2){\\line(1,0){32}}\t\t% top line\n\n\t\\put(0,1){\\line(0,1){2}}\t\t% left vertical\n\t\\put(0,2){\\makebox(1,1){\\tiny 31}}\t% left end bit number marker \n\n\t\\put(32,1){\\line(0,1){2}}\t\t% vertical right end \n\t\\put(31,2){\\makebox(1,1){\\tiny 0}}\t% right end bit number marker\n\n\t\\put(0,0){\\makebox(1,1){\\small sign}}\n\t\\put(1,0){\\makebox(8,1){\\small exponent}}\n\t\\put(9,0){\\makebox(23,1){\\small significand}}\n\n    \\put(0,1){\\makebox(1,1){1}}\t\t% sign\n\n\t\\put(1,1){\\line(0,1){2}}\t\t% seperator\n\t\\put(1,2){\\makebox(1,1){\\tiny 30}}\t% bit marker\n\n    \\put(1,1){\\makebox(1,1){1}}\t\t% exponent\n    \\put(2,1){\\makebox(1,1){0}}\n    \\put(3,1){\\makebox(1,1){0}}\n    \\put(4,1){\\makebox(1,1){0}}\n    \\put(5,1){\\makebox(1,1){0}}\n    \\put(6,1){\\makebox(1,1){0}}\n    \\put(7,1){\\makebox(1,1){0}}\n    \\put(8,1){\\makebox(1,1){0}}\n\n\t\\put(8,2){\\makebox(1,1){\\tiny 23}}\t% bit marker\n\t\\put(9,1){\\line(0,1){2}}\t\t% seperator\n\t\\put(9,2){\\makebox(1,1){\\tiny 22}}\t% bit marker\n\n    \\put(9,1){\\makebox(1,1){0}}\n    \\put(10,1){\\makebox(1,1){1}}\n    \\put(11,1){\\makebox(1,1){0}}\n    \\put(12,1){\\makebox(1,1){1}}\n    \\put(13,1){\\makebox(1,1){0}}\n    \\put(14,1){\\makebox(1,1){0}}\n    \\put(15,1){\\makebox(1,1){0}}\n    \\put(16,1){\\makebox(1,1){0}}\n    \\put(17,1){\\makebox(1,1){0}}\n    \\put(18,1){\\makebox(1,1){0}}\n    \\put(19,1){\\makebox(1,1){0}}\n    \\put(20,1){\\makebox(1,1){0}}\n    \\put(21,1){\\makebox(1,1){0}}\n    \\put(22,1){\\makebox(1,1){0}}\n    \\put(23,1){\\makebox(1,1){0}}\n    \\put(24,1){\\makebox(1,1){0}}\n    \\put(25,1){\\makebox(1,1){0}}\n    \\put(26,1){\\makebox(1,1){0}}\n    \\put(27,1){\\makebox(1,1){0}}\n    \\put(28,1){\\makebox(1,1){0}}\n    \\put(29,1){\\makebox(1,1){0}}\n    \\put(30,1){\\makebox(1,1){0}}\n    \\put(31,1){\\makebox(1,1){0}}\n\\end{picture}\n}\n\n%\\item $-((1 + \\frac{1}{4} + \\frac{1}{16}) \\times 2^{128-127}) = -(1 \\frac{5}{16} \\times 2^{1}) = -(1.3125 \\times 2^{1}) = -2.625$\n\\item $-((1 + \\frac{1}{4} + \\frac{1}{16}) \\times 2^{128-127}) = -((1 + \\frac{1}{4} + \\frac{1}{16}) \\times 2^1) = -(2 + \\frac{1}{2} + \\frac{1}{8}) = -(2 + .5 + .125) = -2.625$\n\n\\item IEEE-754 formats: \n\n\\begin{tabular}{|l|l|l|}\n\\hline\n\t\t\t\t& IEEE-754 32-bit\t& IEEE-754 64-bit\t\\\\\n\\hline\nsign\t\t\t& 1 bit\t\t\t\t& 1 bit\t\t\t\\\\\nexponent\t\t& 8 bits (excess-127)\t\t\t& 11 bits (excess-1023)\t\t\\\\\nmantissa\t\t& 23 bits\t\t\t& 52 bits\t\t\\\\\nmax exponent\t& 127\t\t\t\t& 1023\t\t\t\\\\\nmin exponent\t& -126\t\t\t\t& -1022\t\t\t\\\\\n\\hline\n\\end{tabular}\n\n\\item When the exponent is all ones, the significand is all zeros, and\nthe sign is zero, the number represents positive infinity.\n\n\\item When the exponent is all ones, the significand is all zeros, and\nthe sign is one, the number represents negative infinity.\n\n\\item Note that the binary representation of an IEEE-754 number in memory\ncan be compared for magnitude with another one using the same logic as for\ncomparing two's complement signed integers because the magnitude of an \nIEEE number grows upward and downward in the same fashion as signed integers.\nThis is why we use excess notation and locate the significand's sign bit on\nthe left of the exponent.\n\n\\item Note that zero is a special case number.  Recall that a normalized\nnumber has an implied 1-bit to the left of the significand\\ldots\\ which\nmeans that there is no way to represent zero!\nZero is represented by an exponent of all-zeros and a significand of \nall-zeros.  This definition allows for a positive and a negative zero \nif we observe that the sign can be either 1 or 0.\n\n\\item On the number-line, numbers between zero and the smallest fraction in \neither direction are in the {\\em \\gls{underflow}} areas.\n\\enote{Need to add the standard lecture number-line diagram showing\nwhere the over/under-flow areas are and why.}\n\n\\item On the number line, numbers greater than the mantissa of all-ones and the \nlargest exponent allowed are in the {\\em \\gls{overflow}} areas.\n\n\\item Note that numbers have a higher resolution on the number line when the \nexponent is smaller.\n\n\\item The largest and smallest possible exponent values are reserved to represent\nthings requiring special cases. For example, the infinities, values representing\n``not a number'' (such as the result of dividing by zero), and for a way to represent\nvalues that are not normalized. For more information on special cases see \\cite{ieee:754}.\n\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Floating Point Number Accuracy}\nDue to the finite number of bits used to store the value of a floating point\nnumber, it is not possible to represent every one of the infinite values\non the real number line.  The following C programs illustrate this point.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Powers Of Two}\nJust like the integer numbers, the powers of two that have bits to represent \nthem can be represented perfectly\\ldots\\ as can their sums (provided that the\nsignificand requires no more than 23 bits.)\n\n\\listing{powersoftwo.c}{Precise Powers of Two} \n\\listing{powersoftwo.out}{Output from {\\tt powersoftwo.c}}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Clean Decimal Numbers}\nWhen dealing with decimal values, you will find that they don't map simply\ninto binary floating point values.\n% (the same holds true for binary integer numbers).  \n\nNote how the decimal numbers are not accurately represented as they get larger.\nThe decimal number on line 10 of \\listingRef{cleandecimal.out}\ncan be perfectly represented in IEEE format.  However, a problem arises in \nthe 11Th loop iteration.  It is due to the fact that the\nbinary number can not be represented accurately in IEEE format.  Its least\nsignificant bits were truncated in a best-effort attempt at rounding the value\noff in order to fit the value into the bits provided.  This is an example of\n{\\em low order truncation}.  Once this happens, the value of \\verb@x.f@ is\nno longer as precise as it could be given more bits in which to save its value.\n\n\\listing{cleandecimal.c}{Print Clean Decimal Numbers} \n\\listing{cleandecimal.out}{Output from {\\tt cleandecimal.c}}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection{Accumulation of Error}\nThese  rounding errors can be exaggerated when the number we multiply \nthe \\verb@x.f@ value by is, itself, something that can not be accurately \nrepresented in IEEE \nform.\\footnote{Applications requiring accurate decimal values, such as \nfinancial accounting systems, can use a packed-decimal numeric format\nto avoid unexpected oddities caused by the use of binary numbers.}\n\\enote{In a lecture one would show that one tenth is a repeating \nnon-terminating binary number that gets truncated.  This discussion \nshould be reproduced here in text form.}\n\nFor example, if we multiply our \\verb@x.f@ value by $\\frac{1}{10}$ each time, \nwe can never be accurate and we start accumulating errors immediately.\n\n\\listing{erroraccumulation.c}{Accumulation of Error} \n\\listing{erroraccumulation.out}{Output from {\\tt erroraccumulation.c}}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Reducing Error Accumulation} \nIn order to use floating point numbers in a program without causing \nexcessive rounding problems an algorithm can be redesigned such that the \naccumulation is eliminated.  \nThis example is similar to the previous one, but this time we recalculate the \ndesired value from a known-accurate integer value.  \nSome rounding errors remain present, but they can not accumulate.\n\n\\listing{errorcompensation.c}{Accumulation of Error} \n\\listing{errorcompensation.out}{Output from {\\tt erroraccumulation.c}}\n", "meta": {"hexsha": "684161d672825e19445ccee8dfbfaaaecb103814", "size": 9557, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/float/chapter.tex", "max_stars_repo_name": "johnwinans/rvalp", "max_stars_repo_head_hexsha": "5bc8807ff28611bf6ea4d5cc0b983ada6d469bdb", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2018-05-23T07:10:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T19:26:06.000Z", "max_issues_repo_path": "book/float/chapter.tex", "max_issues_repo_name": "johnwinans/rvalp", "max_issues_repo_head_hexsha": "5bc8807ff28611bf6ea4d5cc0b983ada6d469bdb", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-04-03T06:19:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-04T22:38:40.000Z", "max_forks_repo_path": "book/float/chapter.tex", "max_forks_repo_name": "johnwinans/rvalp", "max_forks_repo_head_hexsha": "5bc8807ff28611bf6ea4d5cc0b983ada6d469bdb", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2018-08-23T15:14:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-01T05:54:16.000Z", "avg_line_length": 42.4755555556, "max_line_length": 174, "alphanum_fraction": 0.664434446, "num_tokens": 2867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6604750716870836}}
{"text": "\\chapter{Incremental Gradient Methods} \n\n\\section{Kaczmarz Algorithm and MSC for Linear Problem}\n%Now we have the problem with data $\\{X^i, Y^i\\}_{i=1}^N$ with $X^i \\in \\mathbb{R}^n$ and $Y^i \\in \\mathbb{R}$. One way to fit those data is to use linear regression, i.e \n%\\begin{problem}Find $W^{*} \\in \\mathbb{R}^{n}$ and $\\theta^{*} \\in \\mathbb{R}$ s.t:\n%\\begin{equation}\n%(W^*,\\theta^*) = \\mathop{\\arg\\min}_{W \\in \\mathbb{R}^{n},\\theta \\in \\mathbb{R}} \\sum_{i=1}^N\\|X^i \\cdot W + \\theta - Y^i\\|^2.\n%\\end{equation}\n%\\end{problem}\n\n%Now, we can note $\\tilde{W} = (W, \\theta)$ and $\\tilde{X}^i = (X^i, 1)$ so, we can reform the problem by:\n%\\begin{problem}Find $\\tilde{W}^{*} \\in \\mathbb{R}^{n+1}$  s.t:\n%\\begin{equation}\\label{equ:splitform-opt}\n%\\tilde{W}^* = \\mathop{\\arg\\min}_{\\tilde{W \\in \\mathbb{R}^{n+1}}} \\sum_{i=1}^N\\|\\tilde{X}^i \\cdot \\tilde{W} - Y^i\\|^2.\n%\\end{equation}\n%\\end{problem}\n\n%And if we note a matrix $A \\in \\mathbb{R}^{N \\times (n+1)}$ with i-th row of $A$, $A_i = \\tilde{X}^i$ and $b = (Y^1, \\cdots, Y^N)^{T} \\in \\mathbb{R}^N$, then the problem can be reformed as:\n%\\begin{problem}Find $\\tilde{W}^{*} \\in \\mathbb{R}^{n+1}$  s.t:\n%\\begin{equation}\\label{equ:matrixform-opt}\n%\\tilde{W}^* = \\mathop{\\arg\\min}_{\\tilde{W} \\in \\mathbb{R}^{n+1}} \\|A \\tilde{W} - b\\|^2.\n%\\end{equation}\n%\\end{problem}\n%And it is equivalent to solve the next normal equation:\n%\\begin{problem} $\\tilde{W}^{*} \\in \\mathbb{R}^{n+1}$  is the solution of \\ref{equ:matrixform-opt} iff:\n%\\begin{equation}\\label{equ:matrixform-equ}\n%A^TA \\tilde{W}^* = A^Tb.\n%\\end{equation}\n%\\end{problem}\n\n%So, it is easy to see that the gradient descent method for \\ref{equ:splitform-opt} and \\ref{equ:matrixform-opt} is exact the gradient descent method for the equation \\ref{equ:matrixform-equ}.\n\\subsection{Least square problem}\nThe general least square problem is:\n\\begin{problem}\\label{pro:standerLS}\n\tFind ${x}^{*} \\in \\mathbb{R}^{n}$  s.t:\n\t\\begin{equation}\\label{equ:leastsquare}\n\t{x}^* = \\mathop{\\arg\\min}_{{x} \\in \\mathbb{R}^{n}} \\frac{1}{2}\\|A {x} - b\\|^2 \\Leftrightarrow {x}^* = \\mathop{\\arg\\min}_{{x} \\in \\mathbb{R}^{n}} \\sum_{i=1}^n \\frac{1}{2}(A_i \\cdot {x} - b_i)^2,\n\t\\end{equation}\n\twith $A \\in \\mathbb{R}^{m\\times n}$ and $\\rm{rank}(A) = n$, and $A_i$\n\tis the i-th row of $A$, but we take it as an column vector.\n\\end{problem}\nIf we take $f_i = \\frac{1}{2}(A_i \\cdot {x} - b_i)^2$, then we can use the general incremental gradient descent method to solve the above problem. So the iterative step is:\n\\begin{equation}\\label{equ:IGDforLS}\nx_{t+1} = x_t - \\eta_t \\nabla f_{i_t}(x_t) = x_t - \\eta_t (A_{i_t} \\cdot x_t - b_{i_t})A_{i_t}.\n\\end{equation}\nThe only difference is the way to choose $i_t$, if we take:\n\\begin{align}\n\\mathbb{P}(i_t = s) = \\frac{1}{m}, \\quad s = 1:m,  \\\\\ni_1, \\cdots, i_T \\quad \\text{are independent},\n\\end{align}\nwe will get SGD. If we take \n\\begin{equation}\ni_t \\equiv t \\mod(m), \\quad i_t \\in 1:m,\n\\end{equation}\nwe will get the cycle incremental gradient method. \n\n\\newpage\n\n\\subsection{Kaczmarz algorithm}\nFirst, Kaczmarz algorithm is proposed for consistent problem i.e. $Ax\n= b$ has solution for $A \\in \\mathbb{R}^{m\\times n}$. So the solution\ncan be expressed as:\n\n$$\nA^T=  (A_1,\\ldots, A_m)\n$$\n\n$$\nA= \n\\begin{pmatrix}\nA_1^T\\\\\n\\vdots\\\\\nA_m^T\n\\end{pmatrix}\n$$\n\n\\begin{equation}\n\\bigcap_{i=1}^m \\{x \\in \\mathbb{R}^n ~:~ A_i \\cdot x = b_i\\}\n\\end{equation}\nUse this structure, a simple idea is to set that $x_{t+1} - x_{t} \\in  \\{x \\in \\mathbb{R}^n ~:~ A_i \\cdot x = b_i\\}$ in \\ref{equ:IGDforLS}. This lead to:\n\\begin{equation}\\label{equ:KacamarzAlgo}\nx_{t+1} = x_t -  \\frac{1}{\\|A_{i_t}\\|^2}(A_{i_t} \\cdot x_t - b_{i_t})A_{i_t}. \n\\end{equation}\n\n\\begin{eqnarray*}\n(A_{i_t} \\cdot x_t - b_{i_t})A_{i_t}\n&=&A_{i_t} (A_{i_t}^T x_t - b_{i_t})\n=A_{i_t} (Ax_t -b)\\cdot e_{i_t}=A_{i_t} e_{i_t}^T(Ax_t -b)\\\\\n& =& (e_{i_t}A_{i_t}^T)^T(Ax_t -b)\n=(e_{i_t}e_{i_t}^TA)^T(Ax_t -b) \\\\\n&=&A^Te_{i_t}e_{i_t}^T(Ax_t -b) \n=[e_{i_t}^T(Ax_t -b)] A^Te_{i_t}\n\\end{eqnarray*}\n\nor \n$$\nx_{t+1} - x_{t} \\in  {\\rm range}(A^Te_t)\n$$\nRecall\n$$\ny_{t+1} - y_{t} \\in  {\\rm range}(e_t)\n$$\nand\n$$\n(y_{t+1} , e_t)_{AA^T} = (b,e_t)\n$$\n$$\n(x_{t+1}, A^Te_t) = (b,e_t)=(x,A^Te_t)\n$$\nIf \n$$\nx_{t+1} - x_{t}=\\eta=\\alpha A^Te_t\n$$\nthen\n$$\n(x_{t}+\\alpha A^Te_t, A^Te_t) = (b,e_t)\n$$\n$$\n(A(x_{t}+\\eta), e_t) = (b,e_t)\n$$\nor, find $\\eta\\in V_t$ such that \n$$\n(A(x_{t}+\\eta)-b, e_t) = 0.\n$$\n\nand\n$$\n\\alpha=\\frac{1}{(A^Te_t, A^Te_t)}(b-Ax_t,e_t)\n$$\nLet \n$$\nV_t={\\rm range}(A^Te_t), \n$$\nand, consider the $\\ell^2$ projection\n$$\nQ_t:  \\mathbb R^m\\mapsto V_t\n$$\nthen\n$$\nQ_t(x_{t+1} - x)=0.\n$$\n\nAnother way(in Prof. Xu's paper about random MSC) to connect Kaczmarz and MSC is to solve:\n\\begin{equation}\\label{norm}\nAA^T y = b,\\quad x=A^Ty\n\\end{equation}\nthen we use G-S for the above equation, and then multiply $A^T$ for the iteration process and get the Kaczmarz process.\n\nApply Gauss-Seidel to \\eqref{norm}, \n$$\ny_{t+1} = y_t -  \\frac{1}{\\|A_{i_t}\\|^2}e_{i_t}^T(AA^Ty_t - b) e_{i_t}. \n$$\nand\n$$\nA^Ty_{t+1} =A^T y_t -  \\frac{1}{\\|A_{i_t}\\|^2}e_{i_t}^T(AA^Ty_t - b) A^Te_{i_t}. \n$$\n$$\nx_{t+1} =x_t -  \\frac{1}{\\|A_{i_t}\\|^2}e_{i_t}^T(Ax_t - b) A^Te_{i_t}. \n$$\n\n\\subsection{Relationship between IGD and Kaczmarz}\nConsider the least square problem\n$$\n\\|Ax-b\\|=\\min.\n$$\nIn some case, the solution satisfies \n$$\nA^TAx^*=A^Tb. \n$$\nIf we write \n$$\nf(x)=\\|Ax-b\\|^2=\\sum_{i=1}^mf_i(x)\n$$\nThen the IGD algorithm for the above form is:\n\\begin{equation}\\label{equ:IGDforLS}\nx_{t+1} = x_t - \\eta_t \\nabla f_{i_t}(x_t) = x_t - \\eta_t (A_{i_t} \\cdot x_t - b_{i_t})A_{i_t}.\n\\end{equation}\nbut the Kaczmarz algorithm for this problem is:\n\\begin{equation}\\label{equ:KacamarzAlgo}\nx_{t+1} = x_t -  \\frac{1}{\\|A_{i_t}\\|^2}(A_{i_t} \\cdot x_t - b_{i_t})A_{i_t}. \n\\end{equation}\n\nThe IGD for the above problem is equivalent to apply damped\nGauss-Seidel method to the normal equation\n\\begin{equation}\n\\label{normA}\nAA^Ty=b  \n\\end{equation}\n\\begin{enumerate}\n\t\\item If the above problem is consistent, then the IGD method would\n\tconverge to a solution of the above problem.  But the solution of\n\tequation \\eqref{normA} may not be the least square solution???\n\t\n\t\\item If the above problem \\eqref{normA} is inconsistent, if the IGD\n\tconverges to something, say $\\tilde x$, then \n\t$$\n\tAx-b\\perp \\mathbb R^m?\n\t$$\n\t\\item But we know SGD (with diminishing learning rate) always converge\n\tto the original least square?\n\\end{enumerate}\n\n{\\bf{Juncai's simple answers}:}\n\\begin{enumerate}\n\t\\item If the above problem is consistent, i.e. $Ax = b$ has solution( this solution will be unique if $\\rm{rank}(A) = n$), then it is not sure to say what $y_t$ for \\eqref{normA} will converges to, but we can make sure that $A^T y_t$ will converges to $x^*$ i.e. the solution for $Ax = b$.\n\t\n\t\\item If \\eqref{normA} is inconsistent, then $Ax = b$ is also inconsistent. So the SGD with diminishing stepsize will convergence to the solution for $A^TA x = A^Tb$, and the means that a special damped random G-S type MSC will convergence into a high dimension affine space like $y^* + \\rm{ker}(A^T)$ such that $A^T y^* = x^*$.\n\t\n\t\\item For inconsistent case( if $b \\neq 0$, the inconsistent for $Ax=b$ and $AA^Ty = b$ is equivalent). The Kaczmarz algorithm and the IGD for $\\min \\frac{1}{2}\\|Ax - b\\|^2$ is different with the ``special\" choice for the stepsize $\\eta_t$, is should be a random variable! Because in Kaczmarz algorithm, it is same to choose \n\t\\begin{equation}\n\t\\eta_t = \\frac{1}{\\|A_{i_t}\\|^2},\n\t\\end{equation}\n\tin the IGD algorithms for  $\\min \\frac{1}{2}\\|Ax - b\\|^2$. If we didn't want such special choice for $\\eta_t$, the Kaczmarz algorithm is equal to choose $\\eta_t = 1$ for \n\t\\begin{equation}\n\t\\min \\frac{1}{2}\\|D^{-1}(Ax - b)\\|^2 = \\min \\frac{1}{2} \\|Ax-b\\|^2_{\\rm{diag}(AA^T)^{-1}},\n\t\\end{equation}\n\twhere $D = \\rm{diag}(AA^T)^{\\frac{1}{2}}$.\n\t\n\t\\item For inconsistent system, use $\\min \\frac{1}{2}\\|Ax - b\\|^2$ as example, the stander SGD method fort this problem will not converges without diminishing stepsize because:\n\t\\begin{equation}\n\t\\mathbb{E}\\|x_{t+1} - x^*\\|^2 \\ge (1 - 2 \\lambda_{max}(A^TA) \\eta_t) \\mathbb{E}\\|x_t - x^*\\|^2 + \\eta_t^2 (\\min_i \\|A_i\\|^2)\\|Ax^* - b\\|^2.\n\t\\end{equation}\n\tAnd it seems that the above inequality can be extended to general convex problem see \n\t\n\t\\item If $AA^T y = b$ is inconsistent, then the damped G-S without diminishing(Kaczmarz for Ax = b)  cannot converges to anything. Because, we can can assume that will converges to some thing like $y^*$, then by taking limit in both side of the next damped G-S \n\t\\begin{equation}\n\t\\lim_{t} y_{t+1} = \\lim_t (y_t -  \\frac{1}{\\|A_{i_t}\\|^2}e_{i_t}^T(AA^Ty_t - b) e_{i_t}). \n\t\\end{equation}\n\tthis will lead to that \n\t$$\n\tAA^Ty^* - b = 0,\n\t$$\n\tthis is contrary to the inconsistent assumption. Here, even we multiply $A^T$ in both side, we can know that $A^T y_t$ will converges to nothing. We can use the same idea to proof this, if it converges, then\n\t$$\n\tAx^* - b = 0,\n\t$$\n\tand because of the fact that $A x = b$ is also inconsistent if $AA^T y = b$ is inconsistent. \n\\end{enumerate}\n\n\n\\subsection{A special case: A is SPD}\nIf $A \\in \\mathbb{R}^n$ is a SPD matrix, the next problem: \n\\begin{problem}\\label{pro:standerLS}\n\tFind ${x}^{*} \\in \\mathbb{R}^{n}$  s.t:\n\t\\begin{equation}\\label{equ:spd-opt-equ}\n\t{x}^* = \\mathop{\\arg\\min}_{{x} \\in \\mathbb{R}^{n}} \\frac{1}{2}\\|A {x} - b\\|^2 \\Leftrightarrow {x}^* = \\mathop{\\arg\\min}_{{x} \\in \\mathbb{R}^{n}} \\sum_{i=1}^n\\frac{1}{2\\|A_i\\|^2}(A_i \\cdot {x} - b_i)^2 \\Leftrightarrow Ax^{*} = b\n\t\\end{equation}\n\there $A_i$ is the i-th row of $A$, but we take it as an column vector. \n\\end{problem}\nSo the incremental gradient method  with $f_i = \\frac{1}{2\\|A_i\\|^2}(A_i \\cdot {x} - b_i)^2$ for a single step can be taken as:\n\\begin{equation}\nx_{t+1} = x_t - \\eta_t \\nabla f_{i_t}(x_t) = x_t - \\eta_t \\frac{(A_{i_t} \\cdot x_t - b_{i_t})}{\\|A_{i_t}\\|^2}A_{i_t}.\n\\end{equation}\n\nThen we can prove that, incremental gradient method for both cycle or random type is linear convergence. The crucial point is $Ax^* = b$, so we will have\n\\begin{equation}\n\\nabla f_i(x) = \\frac{A_i \\cdot (x - x^*)}{\\|A_i\\|^2}A_i.\n\\end{equation}\n\nIf we take $\\eta_t = 1$, then this method is the Kaczmarz algorithm to solve least squares problem. \n\n\\subsubsection{MSC for linear problems}\nNow we would like to discuss the relation between the Karczmarz\nalgorithm above and the method of subspace correction for solving $Ax\n= b$.\n\nIf $A \\in \\mathbb{R}^{n \\times n}$ is a SPD matrix,  we now consider the subspace correction method to solve \n\\begin{equation}\\label{equ:SPD}\nAx = b,\n\\end{equation}\nwith the space decomposition \n\\begin{equation}\n\\mathbb{R}^n = \\rm{span}\\{A_i, i = 1, \\cdots, n\\},\n\\end{equation}\nwhere $A_i$ is the same as above. \n\nFor the subspace correction method, the correction formula for subspace $V_i = \\rm{span}\\{A_i\\}$ is:\n\\begin{equation}\nx_{new} = x_{old} + I_i \\bm{A}_i^{-1} Q_i r(x_{old}),\n\\end{equation}\nwhere $P_i$ and $I_i$ are the projection(restriction) and interpolation operator w.r.t subspace $V_i$, and $\\bm{A}_i$ is the inverse of the restricted problem in $V_i$, $r(x_{old}) = b - Ax_{old}$ is the residual. \n\nSo we can investigate a single step in MSC for this equation under this space decomposition as:\n\\begin{equation}\nx_{k+1} = x_k - \\frac{A_i^T(Ax_k - b)}{A_i^T A A_i}A_i,\n\\end{equation}\nhere we can rewrite it as:\n\\begin{equation}\\label{equ:MSC}\nx_{k+1} = x_k - \\frac{(A_i, x_k - x^*)_A}{\\|A_i\\|^2_A}A_i.\n\\end{equation}\n\nSo the relationship between those two methods is that, we need to change the inner product. For the stander problem \\ref{pro:standerLS}, \n\\begin{equation}\nf_i = \\frac{(A_i \\cdot x - b_i)^2}{2\\|A_i\\|^2} = \\frac{(A_i, x - x^*)^2}{2\\|A_i\\|^2},\n\\end{equation}\nand this is equivalent to solve $Ax = b$, but in fact this is also equivalent to define $f_i$ as:\n\\begin{equation}\\label{equ:newinnerpro}\nf_i = \\frac{(A_i, x - x^*)_A^2}{2\\|A_i\\|_A^2},\n\\end{equation}\nthus we have:\n\\begin{equation}\n\\nabla f_i = \\frac{(A_i, x_k - x^*)_A}{\\|A_i\\|^2_A} A A_i.\n\\end{equation}\n\nSo we have, the incremental gradient method with $f_i$ defined by \\ref{equ:newinnerpro} is have the next relation with the MSC \\ref{equ:MSC}. \n\\begin{equation}\n-A^{-1} \\nabla f_i(x) = I_i \\bm{A}_i^{-1}Q_i r(x),\n\\end{equation}\n\n\\begin{lemma}\n\tSteepest descent direction under the inner product of $(\\cdot, \\cdot)_A$ for $f_i$ is $- A^{-1} \\nabla f_i$. \n\\end{lemma}\n\\begin{proof}\n\tIf we assume the next descent direction is $d$, for the first order approximation for $f_i$ we have:\n\t\\begin{equation}\n\t|(\\nabla f_i, d)| = |(A^{-1} \\nabla f_i, A d)| = |(A^{-1} \\nabla f_i, d)_A| \\le \\|A^{-1} \\nabla f_i\\|_A \\|d\\|_A.\n\t\\end{equation}\n\tSo, under the inner product $(\\cdot, \\cdot)_A$ to get equality in above inequality, we just need $ d $ and $A^{-1} \\nabla f_i$ is parallel. \n\\end{proof}\n\nAll in all, we have the next relation between MSC for $Ax = b$ with decomposition $\\mathbb{R}^n = \\rm{span}\\{A_i, i = 1, \\cdots, n\\}$and gradient or incremental gradient method for $\\min \\sum_i f_i$ with \n$f_i = \\frac{(A_i, x - x^*)_A^2}{2\\|A_i\\|_A^2}$ and descent under the inner production of $(\\cdot, \\cdot)_A$. \n\\begin{itemize}\n\t\\item The PSC for $Ax = b$ is equal to the gradient descent for $\\min \\sum_i f_i$.\n\t\\item The SSC for $Ax = b$ is equal to the cycle incremental gradient descent for $\\min \\sum_i f_i$.\n\t\\item The random SSC for $Ax = b$ is equal to the SGD for $\\min \\sum_i f_i$.\n\\end{itemize}\n\n\\subsubsection{convergence analysis}\nJust use the stander MSC analysis and the newly proposed random MSC theory by Prof. Xu, we can analysis the random SSC as:\n\\begin{equation}\n\\mathbb{E} \\|x_{t+1} - x^*\\|_A^2 \\le (1 - \\frac{\\delta_t}{n})\\mathbb{E} \\|x_{t} - x^*\\|_A^2.\n\\end{equation}\nFor the SGD for $\\sum_i f_i$ under metric $(\\cdot,\\cdot)_A$, to analysis its convergence performance, we should also use the inner product $(\\cdot,\\cdot)_A$, so this can be covered by the above result naturally. \n\n\n\n\\section{SGD with small step size and weak convergence for linear case}\nNow we start our problem with solving \n\\begin{equation}\n\\min \\frac{1}{2}\\|Ax - b\\|^2,\n\\end{equation}\nwith $A \\in \\mathbb{R}^{m \\times n}$ and $\\rm{rank}(A) = n$.\nHere we note $f_i = \\frac{1}{2}(A_i^T x - b_i)$ with $A_i$ is the i-th row of A. So we write the general SGD for the above problem as:\n\\begin{algorithm}\\caption{General SGD}\n\t\\label{alg:gSGD}\n\t\\begin{equation}\\label{equ:sgd-iteration}\n\tx_{t+1} = x_{t} - \\eta_t \\nabla f_{i_t}(x_t), \\quad t = 0:T,\n\t\\end{equation}\n\t\\begin{equation}\n\t\\mathbb{P}(i_t = s) = p_i, \\quad s = 1:m,\n\t\\end{equation}\n\t\\begin{equation}\n\ti_1, \\cdots, i_T \\quad \\text{are independent}.\n\t\\end{equation}\n\\end{algorithm}\n\nSo now, we would like to discuss the relation for tanditional SGD and Kaczmarz algorithm under the general SGD framework and weak convergence property for inconsistent case.\n\n\\subsection{Kaczmarz algorithm}\nIf we take:\n\\begin{equation}\n\\eta_t = \\frac{1}{\\|A_{i_t}\\|^2},\n\\end{equation}\nas an {\\bf random variable} without diminishing, then this is the general random Kaczmarz. \n\n\\subsection{Weak convergence}\nHere the result is:\n\\begin{theorem}\n\tFor those next two choice of $\\eta_t$ and $p_i$, \n\t\\begin{itemize}\n\t\t\\item Traditional SGD for LS:\n\t\t\\begin{equation}\n\t\t\\eta_t = \\eta \\quad p_i = \\frac{1}{m}.\n\t\t\\end{equation}\n\t\t\\item Random damped Kaczmarz for LS:\n\t\t\\begin{equation}\n\t\t\\eta_t = \\frac{\\eta}{\\|A_{i_t}\\|^2} \\quad p_i = \\frac{\\|A_i\\|^2}{\\|A\\|_F^2}.\n\t\t\\end{equation}\n\t\\end{itemize}\n\tWe have the weak convergence without diminishing step size to $x^*$ as the solution of $\\min \\frac{1}{2}\\|Ax - b\\|^2$, i.e.\n\t\\begin{equation}\n\t\\lim_{t \\to \\infty}\\|\\mathbb{E}x_t - x^*\\|^2  = 0.\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n\tFor the first case:\n\t\\begin{align}\n\t\\mathbb{E}( x_{t+1}| x_t) &= x_t - \\mathbb{E}(\\eta_t \\nabla f_{i_t}(x_t) | x_t) \\\\\n\t&= x_t - \\frac{\\eta}{m}A^T(b - Ax_t)\n\t\\end{align}\n\tTake $\\mathbb{E}_{x_t}$ on both side of the above equation, we have:\n\t\\begin{align}\n\t\\mathbb{E}_{x_t}\\mathbb{E}( x_{t+1}| x_t) &= \\mathbb{E}x_{t+1} \n\t= \\mathbb{E}x_t - \\frac{\\eta}{m}A^T(A\\mathbb{E}x_t - b) \\\\\n\t&= \\mathbb{E}x_t - \\frac{\\eta}{m}A^TA( \\mathbb{E}x_t - x^*)\n\t\\end{align}\n\tSo we have:\n\t\\begin{align}\n\t\\|\\mathbb{E}x_{t+1} - x^*\\|\n\t= \\|(I - \\frac{\\eta}{m}A^TA)\\| \\|(\\mathbb{E}x_t - x^*)\\|\n\t\\end{align}\n\tSimilarly for the second case, we have:\n\t\\begin{align}\n\t\\|\\mathbb{E}x_{t+1} - x^*\\|\n\t= \\|(I - \\frac{\\eta}{\\|A\\|_F^2}A^TA)\\| \\|(\\mathbb{E}x_t - x^*)\\|\n\t\\end{align}\n\\end{proof}\n\n\n\\begin{theorem}\n\tFor the next choice of $\\eta_t$ and $p_i$, \n\t\\begin{equation}\n\t\\eta_t = \\eta \\quad p_i = \\frac{\\|A_i\\|^2}{\\|A\\|_F^2}.\n\t\\end{equation}\n\tthis weak convergence to \n\t\\begin{equation}\n\t\\frac{1}{2}\\|Ax - b\\|^2_{D}\n\t\\end{equation}\n\twith \n\t\\begin{align}\n\tD = \\rm{diag}(\\|A_1\\|^2, \\ldots, \\|A_m\\|^2) = \\rm{diag}(AA^T).\n\t\\end{align}\n\t\n\tAnd for the next choice of $\\eta_t$ and $p_i$,\n\t\\begin{equation}\n\t\\eta_t = \\frac{\\eta}{\\|A_{i_t}\\|^2} \\quad p_i = \\frac{1}{m}.\n\t\\end{equation}\n\tthis weak convergence to \n\t\\begin{equation}\n\t\\frac{1}{2}\\|Ax - b\\|^2_{G}\n\t\\end{equation}\n\twith \n\t\\begin{align}\n\tG = \\rm{diag}(\\|A_1\\|^{-1}, \\ldots, \\|A_m\\|^{-1}) = D^{-1}.\n\t\\end{align}\n\\end{theorem}\nThis means that, even the general SGD method for $\\min \\frac{1}{2}\\|Ax-b\\|^2$ with constant step size and non-uniform will weak converges to a solution for another problem. The similar situation happens to damped Kaczmarz. {\\bf All this happened because of the face that\n\t\\begin{equation}\n\t\\mathbb{E} \\nabla f_i \\neq \\nabla f.\n\t\\end{equation}}\n\n\n\\section{Exact and nearly exact interpolation case}\n\nFor general deep learning problem, the object function is like:\n\\begin{problem}\n\tFind $W^* \\in \\mathbb{R}^n$ such that:\n\t\\begin{equation}\n\tW^* \\in \\mathop{\\arg\\min}_{W} \\frac{1}{m}\\sum_{i=1}^mf_i(W) = \\mathop{\\arg\\min}_{W} \\frac{1}{m}\\sum_{i=1}^m \\|f(W;X^i) - Y^i\\|^2.\n\t\\end{equation}\n\\end{problem}\n\nInterpolation means that:\n\\begin{equation}\n\\min_{W} \\frac{1}{m}\\sum_{i=1}^mf_i(W) = 0,\n\\end{equation}\nwith $f_i(W) =  \\|f(W;X^i) - Y^i\\|^2$.For simple expression, we use $f_i(x)$ not $f_i(W)$.\n\nAs we know, even for general convex problem, SGD method connot to be proved convergence with small constant step size. But here, we extend assumptions with similar to exact interpolation case like:\n\\begin{assumption}\\label{assum:ideal}\n\t$f_i \\ge 0$ satisfies the next conditions:\n\t\\begin{itemize}\n\t\t\\item $ f$ satisfies the $\\lambda$-strong convex property.\n\t\t\\item $\\nabla f_i$ is Lipschitz continuous with constant $H$.\n\t\t\\item We can interpolate every point exactly, i.e.\n\t\t\\begin{equation}\n\t\tx^* = \\mathop{\\arg\\min}_{x} \\sum_{i=1}^mf_i(x)  \\in \\mathop{\\arg\\min}_{x} f_i(x), \\quad \\forall i  =  1:m.\n\t\t\\end{equation}\n\t\\end{itemize}\n\\end{assumption}\n\nSo, in some degree this means that:\n\\begin{equation}\nx^* = \\cap_{i=1}^m \\mathop{\\arg\\min}_{x} f_i(x).\n\\end{equation}\nand this can be seen as the generalization of the consistence in linear regression problem. \n\\begin{theorem}\n\tUnder the assumption \\ref{assum:ideal}, we can prove the SGD method \\ref{alg:SGD} with small constant step size $\\eta$ has the linear convergence, i.e \n\t\\begin{equation}\n\t\\mathbb{E}\\|x_t - x^*\\|^2 \\le \\delta^t \\|x_0 - x^*\\|^2,\n\t\\end{equation}\n\tfor some constant $ 0 < \\delta < 1$.\n\\end{theorem}\n\n\\begin{proof}\n\tFor SGD method, we have:\n\t\\begin{align}\n\t\\mathbb{E} \\|x_{t+1} - x^*\\|^2 &\\le \\mathbb{E} \\|x_t - x^*\\|^2  - 2 \\eta_t \\mathbb{E} (\\nabla f_{i_t}(x_t) \\cdot (x_t - x^*)) + \\eta_t^2 \\mathbb{E} \\|\\nabla f_{i_t}(x_t)\\|^2\\\\ \n\t&= \\mathbb{E} \\|x_t - x^*\\|^2  - 2 \\eta_t \\mathbb{E} (\\nabla f(x_t) \\cdot (x_t - x^*))  + \\eta_t^2 \\mathbb{E} \\|\\nabla f_{i_t}(x_t)\\|^2 \\\\\n\t&\\le \\mathbb{E} \\|x_t - x^*\\|^2 - 2\\eta_t \\lambda \\mathbb{E}\\|x_t - x^*\\|^2 + \\eta_t^2 \\mathbb{E}\\|\\nabla f_{i_t}(x_t) - \\nabla f_{i_t}(x^*)\\|^2 \\\\\n\t&\\le (1- 2\\eta_t \\lambda + \\eta_t^2 H^2) \\mathbb{E}\\|x_t - x^*\\|^2.\n\t\\end{align} \n\tSo if \n\t\\begin{equation}\n\t\\eta_t < \\frac{2\\lambda}{H^2}, \n\t\\end{equation}\n\tthen we have $1- 2\\eta_t \\lambda + \\eta_t^2 H^2 = \\delta < 1$, which finishes this proof.\n\\end{proof}\n\nThis result can be taken as an extension for the convergence result for random Kacamarz algorithm for consistent system. \n\n\nIn many cases, the third assumption in assumption \\ref{assum:ideal} is hard to satisfy. But in many applications, we found that, we don't need real diminishing stepsize to preserve the convergence, we just need some even not very small stepsize or decrease it just few steps to make $\\sum_i f_i$ becomes convergence or just very small oscillation in the last of iterations.  Here we try to gives another reasonable assumption to explain why those happens:\n\\begin{assumption}\\label{assum:nearideal}\n\t$f_i \\ge 0$ satisfies the next conditions:\n\t\\begin{itemize}\n\t\t\\item $ f$ satisfies the $\\lambda$-strong convex property.\n\t\t\\item $\\nabla f_i$ is Lipschitz continuous with constant $H$.\n\t\t\\item For the minimizer $x^*$, we have the near consistent property:\n\t\t\\begin{equation}\n\t\t\\sum_{i}^m\\frac{1}{m}\\|\\nabla f_i(x^*)\\| \\le \\epsilon,\n\t\t\\end{equation}\n\t\there $\\epsilon$ is a small positive constant. \n\t\\end{itemize}\n\\end{assumption}\n\n\\begin{theorem}\n\tUnder the assumption \\ref{assum:nearideal}, we can prove the SGD method \\ref{alg:SGD} with step size $\\eta_t$ has the next properties, i.e \n\t\\begin{equation}\n\t\\mathbb{E}\\|x_t - x^*\\|^2 \\le (1- 2\\eta_t \\lambda + \\eta_t^2 H^2) \\mathbb{E} \\|x_{t-1} - x^*\\|^2 + (\\eta_t \\epsilon)^2.\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tFor SGD method, we have:\n\t\\begin{align}\n\t\\mathbb{E} \\|x_{t+1} - x^*\\|^2 &\\le \\mathbb{E} \\|x_t - x^*\\|^2  - 2 \\eta_t \\mathbb{E} (\\nabla f_{i_t}(x_t) \\cdot (x_t - x^*)) + \\eta_t^2 \\mathbb{E} \\|\\nabla f_{i_t}(x_t)\\|^2\\\\ \n\t&= \\mathbb{E} \\|x_t - x^*\\|^2  - 2 \\eta_t \\mathbb{E} (\\nabla f(x_t) \\cdot (x_t - x^*))  + \\eta_t^2 \\mathbb{E} \\|\\nabla f_{i_t}(x_t)\\|^2 \\\\\n\t&\\le \\mathbb{E} \\|x_t - x^*\\|^2 - 2\\eta_t \\lambda \\mathbb{E}\\|x_t - x^*\\|^2 + \\eta_t^2 \\mathbb{E}\\|\\nabla f_{i_t}(x_t) - \\nabla f_{i_t}(x^*)\\|^2 +  (\\eta_t \\epsilon)^2\\\\\n\t&\\le (1- 2\\eta_t \\lambda + \\eta_t^2 H^2) \\mathbb{E}\\|x_t - x^*\\|^2 + (\\eta_t \\epsilon)^2.\n\t\\end{align}\n\\end{proof}\n\nBy using supermartingale convergence theorem, fro diminishing stepsize one can prove that:\n\\begin{theorem}\n\tTake $\\eta_t$ as diminishing stepsize with $\\sum_t \\eta_t = \\infty$ and $\\sum_t \\eta^2_t < \\infty$, then\n\t$\\mathbb{E}\\|x_t - x^*\\|$ converges. \n\\end{theorem}\nBut it seems hard to find the convergence rate.  And for constant stepsize:\n\\begin{theorem}\n\tFor constant stepsize, if $\\eta_t = \\eta$ is a constant and small enough, then \n\t\\begin{equation}\n\t\\mathbb{E} \\|x_{t} - x^*\\|^2 \\le \\delta^t \\|x_0 - x^*\\| + \\frac{1 - \\delta^t}{1- \\delta}(\\eta\\epsilon)^2.\n\t\\end{equation}\n\\end{theorem}\n\n\\subsection{Inconsistent case}\nLike the inconsistent case in linear regression, we can have the next assumption:\n\\begin{assumption}\\label{assum:inconsistent}\n\t$f_i \\ge 0$ satisfies the next conditions:\n\t\\begin{itemize}\n\t\t\\item $ f$ satisfies the $\\lambda$-strong convex property.\n\t\t\\item $\\nabla f_i$ is Lipschitz continuous with constant $H$.\n\t\t\\item We have the next inconsistent property: there exist a $\\delta > 0$ such that \n\t\t\\begin{equation}\n\t\t\\min_{x } \\sum_i^m \\|\\nabla f_i(x)\\|^2 \\ge \\delta.\n\t\t\\end{equation}\n\t\\end{itemize}\n\tIn fact, the last assumption is exactly the inverse of the consistent case. \n\\end{assumption}\nThen we can prove that, without the diminishing stepsize, the problem cannot converges.\n\\begin{theorem}\n\tWe have the next estimate for the iteration process:\n\t\\begin{equation}\n\t\\mathbb{E}\\|x_{t+1} - x^*\\|^2 \\ge (1 - 2\\eta_t H)\\mathbb{E} \\|x_t - x^*\\|^2 + \\eta_t^2 \\frac{\\delta}{m}.\n\t\\end{equation}\n\\end{theorem}\n\n\n\n\\section{Deep learning cases}\n\\subsection{``consistent\" cases: separable!}\nAs we will see, the third assumption in \\ref{assum:ideal} makes the key role in proving the convergence. Here we would like to show that, in some cases in deep learning, this will happen. Now we can consider a simple example as one dimension function interpolate with artificial neural network. So we have the data set $(x^i, y^i)$ with $i = 1, \\cdots, m$. As we know, if we use the ReLU function \n\\begin{equation}\n\\rm{ReLU}(x) = \\max\\{0,x\\},\n\\end{equation} \nthe one-dimension artificial neural network can cover the piecewise linear function. So for a general ANN model from $\\mathbb{R}$ to $\\mathbb{R}$, $f(W;x)$ can fixed all data $(x_i, y_i)$ exactly. Thus, we have \n\\begin{equation}\n0 \\le \\min_W \\sum_i^m f_i = 0 = \\sum_i^m \\min_W (f(W;x^i) - y^i)^2,\n\\end{equation}\nso this satisfy the third assumption in \\ref{assum:ideal}.\n\n\\subsection{near consistent case}\nHere we can talk about the near consistent assumption in assumption \\ref{assum:nearideal}. Because of the powerful expression power for ANN, even you cannot interpolate those data exactly, we can use the next analysis to show some reasonableness for our assumption. \n\nTo be added...\n\n%When we consider about ANN for classification problem, first we would like to divide our data into $C$ classes: \n%\\begin{equation}\n%S_k := \\{i :Y_i = e_k\\}, k = 1,\\cdots,C. \n%\\end{equation}\n%Let us define $\\hat{x}^k$ by \n%\\begin{equation}\n%\\hat{x}^k \\in \\mathop{\\arg\\min}_{x} f_i\n%\\end{equation}\n\n\nHere in real classification application like ImageNet problem, because even the Top 5 error is not zero, which means that $f_i(x^*)$ cannot be very close to $\\min f_i$, especially for those $i$ that is classified into wrong classes.\n\n\n\\section{SGD as smoother}\n%\\subsection{GD and G-S}\n%An interesting result is that, in fact the convergence result for both traditional subspace correction(Jacobi or G-S) and the gradient descent method, they both converges linearly like:\n%\\begin{equation}\n%\\|x_k - x^*\\|_{*}^2 \\le \\delta^k \\|x_0 - x^*\\|_{*}^2.\n%\\end{equation}\n%So the general behaviour for GD likes G-S very much, the most important properties is that: it convergence very fast at beginning and then slow. Here is a typical performance for GD in small deep learning problem:\n%\\begin{figure}[!htb]        \n%\t\\center{\\includegraphics[width=8cm] {NN_GD.png}}        \n%\t\\caption{Gradient descent for a small deep learning model for MNISET}      \n%\t\\label{Kernels}\n%\\end{figure}\n\n\\subsection{SGD and GD}\nThe most important properties for SGD is that if you take expectation for SGD then you get SD. So in some degree, SGD may works like GD, but the convergence result for SGD is not good as GD, because now we only have:\n\\begin{equation}\n\\mathbb{E}\\|x_k - x^*\\|^2 \\le \\frac{M}{k}.\n\\end{equation}\nHowever, in recent paper by using stochastic differential equation to analysis SGD, they show a special case with \n\\begin{equation}\n\\min_{x \\in \\mathbb{R}} f(x) = f_1(x) + f_2(x),\n\\end{equation}\nwith $f_1(x) = (x - a)^2$ and $f_2(x) = (x - b)^2$. We know that $\\alpha = \\frac{a+b}{2}$ is the solution for this problem. If we take the stepsize for SGD(learning rate) as a constant $\\eta$, so we get an approximation SDE system:\n\\begin{align}\nd X_t = -2(X_t - \\alpha )dt + 2\\sqrt{\\eta}dB_t, \\quad X_0 = x_0.\n\\end{align}\nSo we can solve the above system and get \n\\begin{align}\nX_t \\sim \\mathcal{N}(\\alpha + (x_0 - \\alpha)e^{-2t}, \\eta(1 - e^{-4t})).\n\\end{align}\nSo in the beginning, the variance is small, thus the behaviour of SGD resembles GD and has the same convergence rate as GD. {\\bf However, as the SGD requires only one evaluation of the gradient at each iteration, it is exactly twice as fast as GD in the beginning.}\n\nSo we think that, GD often works like G-S very much, as converges fast in the beginning. And SGD with small constant learning rate in the first few steps has the same performance for GD and even faster w.r.t the computational cost. So, SGD can be a good smoother in some sense. ", "meta": {"hexsha": "41a2b74e58453415087bc7abac7557c5dabf1f23", "size": 27513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/CIGD.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/CIGD.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/CIGD.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.3958990536, "max_line_length": 455, "alphanum_fraction": 0.6648493439, "num_tokens": 10307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6604750621227542}}
{"text": "\\section{$p$-adic integers}\nLet $p$ be a prime number. To construct the $p$-adic integers, we have different ways of definition. We are going to present all of them.\n\\subsection{Topological approach}\nFix $p$ as above then $\\mathfrak{p} := \\left<p\\right> = p\\zz$ is a prime ideal in $\\zz$ (moreover, it is maximal). We are going to use the notion of linear topological rings. \n\\begin{defi}\nLet $(R,+,0,-,\\cdot,1)$ be a ring with topology $\\tau$. We call $R$ a topological ring if $+, \\cdot : R^2 \\longrightarrow R$ are continuous wrt. product topology. We call a topological ring $R$ linear topological if there is a open neighborhood basis of zero wrt. $\\tau$:\n$$\\beta(0) := \\{U \\in \\tau : U\\ \\trm{open},\\ 0 \\in U\\}$$\n\\end{defi}\n\\bsp Clearly, $\\zz$ is a ring which is a topological ring wrt. discrete topology $\\tau_\\zz = \\mathcal{P}(\\zz) = \\{A \\subset \\zz\\}$. More interestingly, let us consider the field of real numbers $\\rz$ with standard topology $\\tau_{\\mathrm{stand}}$ with\n$$\\tau_{\\mathrm{stand}} = \\left<B(y,\\eps) := \\{x \\in \\rz : d(x,y) < \\eps\\} : y \\in \\rz, \\eps \\in \\rz_{+}\\right>.$$ To show continuity of addition we first prove that negation $- : \\rz \\longrightarrow \\rz, x \\longmapsto -x$ is continuous:\n$$\\bao{rclcl}\n-^{-1} B(x,\\eps) &=& \\{y \\in \\rz : d(-y,x) < \\eps\\} &=& \\{y \\in \\rz : -\\eps < -(x + y) < \\eps\\}\\\\\n&&&&\\\\\n &=& \\{y \\in \\rz : \\eps < y - (-x) < \\eps\\} &=&  \\{y \\in \\rz : d(y,-x) < \\eps\\}\\\\\n &&&&\\\\ &=& B(-x,\\eps).\\\\\n \\ea$$\nThus the preimage is indeed a generator for the standard topology on $\\rz$ for all generators $B(x,\\eps)$. We claim the it suffice to show that subtraction $- : \\rz^2 \\longrightarrow \\rz$ is continuous at zero. Clearly:\n$$\\bao{rcl}\n-^{-1} (B(0,\\eps)) &=& \\{(x,y) \\in \\rz^2 : d(x - y, 0) < \\eps\\}\\\\&&\\\\ &=& \\{(x,y) : -\\eps < x - y < \\eps\\}\\\\\n&&\\\\\n& =& \\bigcup_{x \\in \\rz,\\delta \\in (0,\\eps)} B(x,\\delta) \\times B(-x,\\eps - \\delta)\\\\&&\\\\\n&=& \\bigcup_{y \\in \\rz,\\ \\delta \\in (0,\\eps)} B(-y,\\eps - \\delta) \\times B(y,\\delta)\\\\\n\\ea$$\nis an open element in the product topology proving our previous claim. Since all elements $x \\in \\rz$ have a neighborhood system $B(x,\\eps) = x + B(0,\\eps)$ we may apply the last proof and see each preimage is of type\n$$\\bigcup_{y \\in \\rz,\\ \\delta \\in (0,\\eps)} B(y,\\delta) \\times B(x - y, \\eps - \\delta).$$\nAnalogously, we claim that $^{-1} : \\rz^\\times \\longrightarrow \\rz^\\times$ is continuous for all $x \\in \\rz^\\times$ and $B(x,\\eps)$. For simplicity, we assume $0 \\notin B(x,\\eps)$ (otherwise we may decompose $B(x,\\eps)$ to $B(x,\\eps) \\cap \\rz_{<0}$ and $B(x,\\eps) \\cap \\rz_{>0}$ and proceed with each component).\n%We have $B(x^{-1},\\eps/x)$ as preimage being clearly an open element in $\\tau_{\\mathrm{stand}}$.\n$$\\bao{rcl}\n(1/)^{-1}(B(x,\\eps)) &=& \\{y \\in \\rz^\\times : d(y^{-1},x) < \\eps\\}\\\\\n&&\\\\\n&=& \\{y : \\rz^\\times : x - \\eps < 1/y < x + \\eps\\}\\\\\n&&\\\\\n&=& \\left\\{y : \\rz^\\times : \\frac{1}{x - \\eps} > y > \\frac{1}{x + \\eps}\\right\\}\\\\\n&&\\\\\n&=& B(x/(2(x^2 - \\eps^2)), \\eps/(x^2 - \\eps^2))\\\\\n\\ea$$\nclearly being open in $\\tau_{\\mathrm{stand}}$. Now we will show that the division map $/ : \\left(\\rz^\\times\\right)^2 \\longrightarrow \\rz^\\times, (x,y) \\longmapsto x/y$ is continuous in the product topology at one.\n$$\\bao{rcl}\n/^{-1}(B(1,\\eps)) &=& \\left\\{(x,y) \\in \\left(\\rz^\\times\\right)^2 : d(x/y, 1) < \\eps\\right\\}\\\\\n&&\\\\\n&=& \\{(x,y) : 1 - \\eps < x/y < 1 + \\eps\\}\\\\\n&&\\\\\n&=& \\left\\{(x,y) \\in \\left(\\rz_{>0}\\right)^2 : \\frac{x}{1 - \\eps} > y > \\frac{x}{1 + \\eps}\\right\\}\\\\&&\\\\&& \\cup \\left\\{(x,y) \\in \\left(\\rz_{<0}\\right)^2: \\frac{x}{1 - \\eps} < y < \\frac{x}{1 + \\eps}\\right\\}\\\\\n&&\\\\\n&=& B(x,\\delta) \\times B\\left(\\frac{x}{2(1 - \\eps^2)}, \\frac{\\eps x}{1 - \\eps^2}\\right) \\cup \\{\\mathrm{bollocks}\\}\\\\\n\\ea$$\n%The product topology is $\\tau_{\\rz \\times \\rz} = \\left<U \\times \\rz, \\rz \\times V: U, V \\in \\tau\\right>$. Then for $B(y,\\eps)$, we find an $0 < \\delta < \\eps$ such that\n%$$\\bao{rcl}\n%+^{-1}(B(y,\\eps)) &=& \\left\\{(x,x') \\in \\rz^2 : d(x + x', y) < \\eps\\right\\}\\\\\n%&&\\\\\n% &=& \\bigcup_{\\delta \\in (0,\\eps)} \\left\\{(z,z') \\in \\rz^2 : \\forall x \\in \\rz,\\ z \\in B(x,\\delta) \\wedge z' \\in B(y - x, \\eps - \\delta)\\right\\}\\\\\n%&&\\\\\n% &=:& \\bigcup_{\\substack{x \\in \\rz\\\\\\delta \\in (0,\\eps)\\\\}} B(x,\\delta) \\times B(y - x,\\eps - \\delta)\\\\\n% &&\\\\\n% &=& \\bigcup_{\\delta \\in (0,\\eps)}\\left\\{(z,z') \\in \\rz^2 : \\forall x' \\in \\rz,\\ z' \\in B(x',\\delta) \\wedge z \\in B(y - x', \\eps - \\delta)\\right\\}\\\\\n% &&\\\\\n% &=& \\bigcup_{\\substack{x' \\in \\rz\\\\\\delta \\in (0,\\eps)\\\\}} B(y - x', \\eps - \\delta) \\times B(x',\\delta)\\\\\n% \\ea$$\n%Without loss of generality, each subset $B(x,\\delta) \\times B(y - x, \\eps - \\delta)$, indexed by $x \\in \\rz$ and $\\delta \\in (0,\\eps)$,  is contained in a well chosen family of ascending neighborhoods of $x$ and $y - x$. Therefore, the preimages are open in the product topology. For the continuity of the multiplication, we first distinguish the unit group $(\\rz^\\times,\\cdot,1)$ and then complete with zero. Thus, let $y \\in \\rz^\\times$ and the other parameter as above.\n%$$\\bao{rcl}\n%\\cdot^{-1}(B(y,\\eps)) &=& \\{(x,x') \\in \\rz^2 : d(x x', y) < \\eps\\}\\\\\n%&&\\\\\n%&=& \\bigcup_{\\delta \\in (0, \\min(|x|, \\eps))} \\{(z,z') : \\forall x \\in \\rz^\\times,\\ z \\in B(x,\\delta), z' \\in \\underbrace{B(y/(x - \\delta), \\eps/(x - \\delta))}_{U_{-,\\delta}}\\}\\\\\n%&&\\\\\n%&& \\cap \\{(z,z') : \\forall x \\in \\rz^\\times,\\ z \\in B(x,\\delta), z' \\in \\underbrace{B(y/(x + \\delta, \\eps/(x + \\delta))}_{U_{+,\\delta}}\\}\\\\ \n%&&\\\\\n%&=& \\bigcup_{\\substack{x \\in \\rz^\\times\\\\0 < \\delta < \\min(|x|, \\eps)}} B(x,\\delta) \\times (U_{-,\\delta} \\cap U_{+,\\delta})\n%\\ea$$\n%By symmetry of the metric, we may reverse both factors. This shows $(R^\\times, \\cdot, 1, ^{-1}, \\tau)$ is a topological group.\\\\\n\\indent Next, we construct a neighborhood basis of zero for any commutative ring with one and an ideal $0 \\subsetneq I \\subsetneq R$. Pick $\\beta(0) := \\{I^i \\subset R : i \\geq 1\\}$ then this defines a neighborhood system of zero as\n$$I \\supsetneq I^2 \\supsetneq \\ldots \\supsetneq I^i \\supsetneq I^{i+1} \\supsetneq \\ldots \\supsetneq 0,$$\ni.e. each ideal contains the zero module and, therefore, the zero element. ", "meta": {"hexsha": "66fbe54ea45354394964aee75a4fb483811ade78", "size": 6077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "p_adic/p_ad_def.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "p_adic/p_ad_def.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "p_adic/p_ad_def.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": 84.4027777778, "max_line_length": 473, "alphanum_fraction": 0.5789040645, "num_tokens": 2354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.6604750537259371}}
{"text": "\n\\subsection{Vector bundles}\n\nA vector bundle consists of a base manifold (a base space), and a real vector space at each point in the base manifold.\n\n\\subsubsection{Example}\n\nFor example we can have a base manifold of a circle, and have a \\(1\\)-dimensional vector space at each point on the circle to create an infinitely extended cylinder.\n\n\n", "meta": {"hexsha": "564526eb7a0140ee375cf7fa5074ba6b09222bb2", "size": 344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsTopological/07-01-vector.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/07-01-vector.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/07-01-vector.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.2727272727, "max_line_length": 165, "alphanum_fraction": 0.773255814, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6603609811576018}}
{"text": "In this section, we turn our attention to temperature-aware reliability\nanalysis.\n\nLet $(\\Omega, \\F, \\probability)$ be a probability space (see\n\\xref{probability-theory}), and let $\\life: \\Omega \\to \\real$ be a random\nvariable that represents the lifetime of the system. The lifetime is the time\nuntil the system experiences a fault after which it no longer meets certain\nrequirements. Also, let $F(\\cdot | \\vg)$ be the distribution function of \\life,\nwhich gives the probability of failure before a certain moment in time, where\n\\vg is a vector of parameters. The expectation $\\expectation{\\life}$ is called\nthe \\ac{MTTF}. Lastly, the complementary distribution function of \\life is\n\\[\n  R(t | \\vg) = 1 - F(t | \\vg),\n\\]\nwhich, in the context of reliability analysis, gives the probability of survival\nup to a certain moment in time and is called the reliability function of the\nsystem.\n\nThe lifetime \\life is a function of the lifetimes of the \\np processing elements\nthat the system is composed of. Denote these individual lifetimes by\n$\\set{\\life_i}{\\Omega \\to \\real}_{i = 1}^\\np$. Each $\\life_i$ is characterized\nby a physical model of wear \\cite{jedec2016} that describes the stress that\nprocessing element~$i$ is exposed to. Each $\\life_i$ is also assigned an\nindividual $R_i(\\cdot | \\vg_i)$, which models the failures due to this stress.\n\nThe structure of $R(\\cdot | \\vg)$ with respect to $\\set{R_i(\\cdot | \\vg_i)}_{i =\n1}^\\np$ is problem specific, and it can be especially diverse in the context of\nfault-tolerant systems. Therefore, $R(\\cdot | \\vg)$ is to be devised by the\ndesigner of the system under consideration. To give an example, suppose that the\nfailure of any of the \\np processing elements makes the whole system fail, and\nthat $\\set{\\life_i}_{i = 1}^\\np$ are conditionally independent given the\nparameters gathered in \\vg. In this scenario,\n\\begin{equation} \\elab{reliability-model}\n  \\begin{split}\n    & \\life = \\min_{i = 1}^\\np \\life_i \\text{ and} \\\\\n    & R(t | \\vg) = \\prod_{i = 1}^\\np R_i(t | \\vg_i).\n  \\end{split}\n\\end{equation}\n\n\\subsection{Periodic Thermal Stress}\n\nIn this subsection, we present a model that is frequently used for\ncharacterizing the lifetime $\\life_i$ of a single processing element when it is\nexposed to repetitive temperature-induced stress \\cite{huang2009b, xiang2010}.\nThe scenario under consideration is that the system is experiencing a periodic\nworkload with a certain period, which is denoted by \\period. The resulting\ntemperature profile is a dynamic steady-state temperature profile, which will be\ndiscussed in \\sref{dynamic-steady-analysis}.\n\nThe lifetime $\\life_i$ is assumed to have a Weibull distribution as follows:\n\\[\n  \\life_i | \\vg_i \\sim \\mathrm{Weibull}(\\scale_i, \\shape_i)\n\\]\nwhere $\\scale_i$ and $\\shape_i$ are called the scale and shape parameters,\nrespectively, and $\\vg_i = (\\scale_i, \\shape_i)$. The distribution function of\n$\\life_i$ is\n\\begin{equation} \\elab{weibull-distribution}\n  F_i(t | \\vg_i) = 1 - \\exp\\left(-\\left(\\frac{t}{\\scale_i}\\right)^{\\shape_i}\\right),\n\\end{equation}\nthe reliability function of the processing element is\n\\begin{equation} \\elab{weibull-reliability}\n  R_i(t | \\vg_i) = 1 - F_i(t | \\vg_i) = \\exp\\left(-\\left(\\frac{t}{\\scale_i}\\right)^{\\shape_i}\\right),\n\\end{equation}\nand the corresponding \\ac{MTTF} is\n\\begin{equation} \\elab{weibull-expectation}\n  \\mean_i = \\expectation{\\life_i} = \\scale_i \\, \\Gamma\\left(1 + \\frac{1}{\\shape_i}\\right)\n\\end{equation}\nwhere $\\Gamma$ stands for the gamma function.\n\n\\begin{remark} \\rlab{weibull-homogeneity}\nThe Weibull model has a special case: assuming that $\\shape_i = \\shape$ for $i =\n\\range{1}{\\np}$, the reliability function in \\eref{reliability-model} belongs to\na Weibull distribution whose shape parameter is $\\shape$ and scale parameter is\ngiven by\n\\[\n  \\scale = \\left(\\sum\\left(\\frac{1}{\\scale_i}\\right)^\\shape\\right)^{-\\frac{1}{\\shape}}.\n\\]\n\\end{remark}\n\nIt is natural to expect that the usage conditions and hence the corresponding\nstress change over the period \\period. The distribution of $\\life_i$ should then\nreflect this aspect, which is not prominent in \\eref{weibull-distribution}. In\norder to take this into account, the period is split into \\nk{i} time intervals\n$\\set{\\dt_{ij}}_{j = 1}^{\\nk{i}}$ so that the conditions that are relevant to\nthe model remain unchanged in each interval. Let\n\\[\n  \\life_{ij} | \\vg_{ij} \\sim \\mathrm{Weibull}(\\scale_{ij}, \\shape_{ij})\n\\]\nbe the time to failure that the processing element would have if interval~$j$\nwas the only interval present and denote the corresponding \\ac{MTTF} by\n$\\mean_{ij}$.\n\nIn the case of temperature-induced failures, we specify that $\\shape_{ij} =\n\\shape_i$ for $j = \\range{1}{\\nk{i}}$; that is, the shape parameters are all\nequal. The reason is that, unlike the scale parameters, the shape parameters are\nindependent of the operating temperature \\cite{chang2006}. As shown in\n\\cite{xiang2010}, in this scenario, the reliability function of the processing\nelement can still be approximated by means of \\eref{weibull-reliability} with\nthe following scale parameter:\n\\[\n  \\scale_i = \\frac{\\sum_{j = 1}^{\\nk{i}} \\dt_{ij}}{\\sum_{j = 1}^{\\nk{i}} \\frac{\\Delta t_{ij}}{\\scale_{ij}}}.\n\\]\nApplying \\eref{weibull-expectation} at the level of individual intervals,\n$\\scale_i$ is rewritten as\n\\[\n  \\scale_i = \\frac{\\sum_{j = 1}^{\\nk{i}} \\dt_{ij}}{\\Gamma\\left(1 + \\frac{1}{\\shape_i}\\right) \\sum_{j = 1}^{\\nk{i}} \\frac{\\Delta t_{ij}}{\\mean_{ij}}}.\n\\]\nNote now that the model in \\eref{weibull-reliability} becomes fully specified as\nsoon as $\\dt_{ij}$ and $\\mean_{ij}$ are identified for $j = \\range{1}{\\nk{i}}$.\nThis part depends on the particular failure mechanism that is being considered,\nwhich we discuss next.\n\n\\subsection{Thermal-Cycling Fatigue}\n\\slab{thermal-cycling-fatigue}\n\nLet us tailor the above Weibull model to thermal-cycling fatigue\n\\cite{jedec2016}. This type of fatigue is of particular interest to us due to\nits prominent dependence on temperature fluctuations: apart from the average and\nmaximum values, the frequencies and amplitudes of temperature oscillations\nmatter in this case.\n\nTime intervals with constant relevant conditions correspond to thermal cycles.\nIn order to detect them in a given temperature curve, the curve is first\nanalyzed using a peak-detection algorithm in order to extract a set of extrema.\nThe rainflow counting method \\cite{xiang2010} is then applied to these extrema.\nThe result is a set of \\nk{i} thermal cycles. Each detected cycle is\ncharacterized by a number of properties, including the desired duration\n$\\dt_{ij}$. Regarding the corresponding $\\mean_{ij}$, it can be expressed as\nfollows:\n\\[\n  \\mean_{ij} = \\nk{ij} \\dt_{ij}\n\\]\nwhere \\nk{ij} stands for the mean number of such cycles to failure.\n\n\\begin{remark}\nA cycle detected by the rainflow counting method does not have to be formed by\nadjacent extrema; cycles can overlap. This feature makes the counting method\nvery efficient at mitigating overestimation. A cycle could be a half cycle,\nmeaning that only an upward or downward swing is present in the time series,\nwhich is assumed to be adequately accounted for.\n\\end{remark}\n\nThe number \\nk{ij} is estimated using a modified version of the Coffin--Manson\nequation with the Arrhenius term as follows \\cite{xiang2010, jedec2016}:\n\\begin{equation} \\elab{thermal-cycling-mean-cycles}\n  \\nk{ij} = a_i (\\Delta\\q_{ij} - \\Delta\\q_{0, ij})^{-b_i} \\exp\\left(\\frac{c_i}{k \\q_{\\maximum, ij}}\\right)\n\\end{equation}\nwhere $a_i$, $b_i$ (called the Coffin--Manson exponent), and $c_i$ (called the\nactivation energy) are empirically determined constants; $k$ is the Boltzmann\nconstant; $\\Delta\\q_{ij}$ is the excursion of the cycle in question;\n$\\Delta\\q_{0, ij}$ is the portion of the temperature excursion that resides in\nthe elastic region, which does not cause damage; and $\\q_{\\maximum, ij}$ is the\nmaximum temperature during the cycle.\n\nThe reliability model of a single processing element is now fully specified. The\nreliability function is the one in \\eref{weibull-reliability} with\n\\begin{equation} \\elab{thermal-cycling-scale}\n  \\scale_i = \\frac{\\sum_{j = 1}^{\\nk{i}} \\dt_{ij}}{\\Gamma\\left(1 + \\frac{1}{\\shape_i}\\right) \\sum_{j = 1}^{\\nk{i}} \\frac{1}{\\nk{ij}}}\n\\end{equation}\nwhere \\nk{ij} is given in \\eref{thermal-cycling-mean-cycles}. Using\n\\eref{weibull-expectation}, the \\ac{MTTF} of the processing element is as\nfollows:\n\\begin{equation} \\elab{thermal-cycling-mean-time}\n  \\mean_i = \\frac{\\sum_{j = 1}^{\\nk{i}} \\dt_{ij}}{\\sum_{j = 1}^{\\nk{i}} \\frac{1}{\\nk{ij}}}.\n\\end{equation}\n\nIn conclusion, it is worth emphasizing that the reliability model requires\ndetailed information about the thermal cycles to which the processing element is\nexposed, which is the topic of \\cref{certainty-development} and, in particular,\n\\sref{dynamic-steady-analysis} where dynamic steady-state temperature analysis\nis discussed in detail.\n", "meta": {"hexsha": "71057ccb3f241c26f680c8ba79c367d80788830d", "size": 8886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/background/reliability-model.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/background/reliability-model.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/background/reliability-model.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.6627906977, "max_line_length": 149, "alphanum_fraction": 0.7430790007, "num_tokens": 2522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6603609678352153}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% =================================================================================================\n% create checkpoint file\n\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   import cdblib\n   checkpoint_file = 'tests/semantic/output/detg2.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n% =================================================================================================\n\\section*{The determinant of the metric}\n\nOur game here is to compute (the leading terms) in $\\det g$ of the metric in RNC form\n\\begin{dgroup*}\n   \\begin{dmath*} g_{a b}(x) = \\cdb{gab.001}+\\BigO{\\eps^5} \\end{dmath*}\n\\end{dgroup*}\nFor the sake of simplicity let's assume that we are working in 3-dimensions. The following\nanalysis is easily generalsied to other dimensions (and the final answers for $\\det g$ and\nfriends are unchanged).\n\nDefine $\\eps^{abc}_{ijk}$ by\n\\begin{align}\n   \\eps^{abc}_{ijk} =\n        \\delta^a_i \\delta^b_j \\delta^c_k - \\delta^b_i \\delta^a_j \\delta^c_k\n      + \\delta^c_i \\delta^a_j \\delta^b_k - \\delta^c_i \\delta^b_j \\delta^a_k\n      + \\delta^b_i \\delta^c_j \\delta^a_k - \\delta^a_i \\delta^c_j \\delta^b_k\n\\end{align}\nIt is easy to see that $\\eps^{abc}_{ijk}$ is anti-symmetric in both its upper and lower\nindices. A trivial computation shows that for any $3{}\\times{}3$ square matrix $M_{ab}$,\n\\begin{align}\n   \\eps^{abc}_{123} M_{1a} M_{2b} M_{3c}\n   = \\left(\n          \\delta^a_1 \\delta^b_2 \\delta^c_3 - \\delta^b_1 \\delta^a_2 \\delta^c_3\n        + \\delta^c_1 \\delta^a_2 \\delta^b_3 - \\delta^c_1 \\delta^b_2 \\delta^a_3\n        + \\delta^b_1 \\delta^c_2 \\delta^a_3 - \\delta^a_1 \\delta^c_2 \\delta^b_3\n     \\right)M_{1a} M_{2b} M_{3c}\n   = \\det M\n\\end{align}\nThis can be easily generalised to\n\\begin{align}\n   \\eps^{abc}_{ijk} M_{pa} M_{qb} M_{rc}\n   =\n   \\begin{cases}\n      \\pm \\det M &\\text{when $(ijk)$ and $(pqr)$ are permutations of $(123)$}\\\\\n      0 & \\text{otherwise}\n   \\end{cases}\n\\end{align}\nThe $\\pm$ sign in the above depends on the particular permutations of $(ijk)$ and $(pqr)$. If\nboth permutations are even or both odd then the sign is $+1$ otherwise the sign is $-1$.\nThe same arguments can also be applied to a matrix inverse $N^{-1}$ leading to\n\\begin{align}\n   \\eps^{ijk}_{uvw} N^{pu} N^{qv} M^{rw}\n   =\n   \\begin{cases}\n      \\pm \\det {N^{-1}} &\\text{when $(ijk)$ and $(pqr)$ are permutations of $(123)$}\\\\\n      0 & \\text{otherwise}\n   \\end{cases}\n\\end{align}\nNote that the $\\pm$ in this case will match exactly that for the case of $\\det M$. Thus,\nmultiplying both expressions and summing over all choices for $(ijk)$ and $(pqr)$ leads\nto\n\\begin{align}\n   \\sum_{\\substack{(ijk)\\\\(pqr)}}\\left(\\det N^{-1}\\right) \\det M\n   = \\eps^{ijk}_{uvw} N^{pu} N^{qv} M^{rw} \\eps^{abc}_{ijk} M_{pa} M_{qb} M_{rc}\n\\end{align}\nwhere the sum on the left hand side includes just those $(ijk)$ and $(prq)$ that are\npermutations of $(123)$. There are $3!$ choices for $(ijk)$ and $3!$ choices for\n$(pqr)$ and thus the left hand side is easily reduced to $(3!)^2 \\det M/\\det N$ where\n$\\det N = 1/\\det N^{-1}$. For the right hand side notice that\n\\begin{align}\n   \\eps^{ijk}_{uvw} \\eps^{abc}_{ijk} = 3! \\eps^{abc}_{uvw}\n\\end{align}\nwhich leads to\n\\begin{align}\n   \\det M = \\frac{1}{3!} \\det N \\eps^{abc}_{uvw} M_{pa} M_{qb} M_{rc} N^{pu} N^{qv} N^{rw}\n\\end{align}\n\nFor our RNC metric we will set $N^{ab} = g^{ab}$ and $M_{ij} = g_{ij}(x)$. Since $g^{ab}$ is\nof the form ${\\rm diag}(-1,1,1,1)$ we have $\\det g = -1$ and thus\n\\begin{align}\n   \\det g(x) = - \\frac{1}{3!} \\eps^{abc}_{ijk}\\, g_{pa}(x)\\, g_{qb}(x)\\, g_{rc}(x)\\, g^{ip} g^{jq} g^{kr}\n\\end{align}\n\nThe $\\eps^{abc}_{ijk}$ can be constructed in Cadabra by applying the \\verb|asym| algorithm\nto the upper indices of $\\delta^a_i \\delta^b_j \\delta^c_k$. Note that \\verb|asym| will\ninclude the $1/3!$ coeffcient as part of its output.\n\nThe following code computes $-\\det g$ rather than $\\det g$.\n\n{\\bf Note} that Calzetta etal. use an opposite sign for $R_{abcd}$ so when comparing the\nfollowing results against Calzetta do take note of this flipped sign in $R_{abcd}$.\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   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Integer(1..2).\n\n   \\nabla{#}::Derivative.\n\n   d{#}::KroneckerDelta.\n\n   g^{a b}::Symmetric.\n   g_{a b}::Symmetric.\n\n   R_{a b c d}::RiemannTensor.\n\n   x^{a}::Weight(label=numx,value=1).\n\n   def truncate (obj,n):\n\n       ans = Ex(0)\n\n       for i in range (0,n+1):\n          foo := @(obj).\n          bah = Ex(\"numx = \" + str(i))\n          keep_weight (foo, bah)\n          ans = ans + foo\n\n       return ans\n\n   import cdblib\n\n   g0ab = cdblib.get('g_ab_0','metric.json')\n   g1ab = cdblib.get('g_ab_1','metric.json')  # zero in RNC\n   g2ab = cdblib.get('g_ab_2','metric.json')\n   g3ab = cdblib.get('g_ab_3','metric.json')\n   g4ab = cdblib.get('g_ab_4','metric.json')\n   g5ab = cdblib.get('g_ab_5','metric.json')\n\n   gab := @(g0ab) + @(g1ab) + @(g2ab) + @(g3ab) + @(g4ab) + @(g5ab).  # cdb (gab.001,gab)\n   gxab := gx_{a b} -> @(gab).\n\n   eps := d^{a}_{i} d^{b}_{j}.   # cdb(eps.001,eps)\n   asym (eps,$^{a},^{b}$)        # cdb(eps.002,eps) # includes a factor of 1/2!\n\n   # compute negative Ndetg rather than det g\n   Ndetg := @(eps) gx_{p a} gx_{q b} g^{i p} g^{j q}.  # note 1/2! included in eps\n\n   substitute       (Ndetg,gxab)\n   distribute       (Ndetg)\n   Ndetg = truncate (Ndetg,5)                                          # cdb (Ndetg.001,Ndetg)\n   substitute       (Ndetg,$g^{a b} g_{b c} -> d^{a}_{c}$,repeat=True) # cdb (Ndetg.002,Ndetg)\n   eliminate_kronecker (Ndetg)                                         # cdb (Ndetg.003,Ndetg)\n   sort_product     (Ndetg)                                            # cdb (Ndetg.004,Ndetg)\n   rename_dummies   (Ndetg)                                            # cdb (Ndetg.005,Ndetg)\n   canonicalise     (Ndetg)                                            # cdb (Ndetg.006,Ndetg)\n\n   # introduce the Ricci tensor\n\n   substitute     (Ndetg,$R_{a b c d} g^{a c} -> R_{b d}$,repeat=True)                                  # cdb (Ndetg.101,Ndetg)\n   substitute     (Ndetg,$\\nabla_{a}{R_{b c d e}} g^{b d}  -> \\nabla_{a}{R_{c e}}$,repeat=True)         # cdb (Ndetg.102,Ndetg)\n   substitute     (Ndetg,$\\nabla_{a b}{R_{c d e f}} g^{c e}  -> \\nabla_{a b}{R_{d f}}$,repeat=True)     # cdb (Ndetg.103,Ndetg)\n   substitute     (Ndetg,$\\nabla_{a b c}{R_{d e f g}} g^{d f}  -> \\nabla_{a b c}{R_{e g}}$,repeat=True) # cdb (Ndetg.104,Ndetg)\n\n   # the following are based on sqrt-Ndetg.tex\n\n   sqrtNdetg := 1/2 + (1/2) @(Ndetg)\n               - (1/8) (1/9) R_{a b} R_{c d} x^{a} x^{b} x^{c} x^{d}\n               - (1/4) (1/18) R_{a b} \\nabla_{c}{R_{d e}} x^{a} x^{b} x^{c} x^{d} x^{e}.\n               # cdb (sqrtNdetg.001,sqrtNdetg)\n\n   sort_product   (sqrtNdetg)                                          # cdb (sqrtNdetg.002,sqrtNdetg)\n   rename_dummies (sqrtNdetg)                                          # cdb (sqrtNdetg.003,sqrtNdetg)\n   canonicalise   (sqrtNdetg)                                          # cdb (sqrtNdetg.004,sqrtNdetg)\n\n   logNdetg := -1 + @(Ndetg)\n               - (1/2) (1/9) R_{a b} R_{c d} x^{a} x^{b} x^{c} x^{d}\n               - (1/18) R_{a b} \\nabla_{c}{R_{d e}} x^{a} x^{b} x^{c} x^{d} x^{e}.\n               # cdb (logNdetg.001,logNdetg)\n\n   sort_product   (logNdetg)                                           # cdb (logNdetg.002,logNdetg)\n   rename_dummies (logNdetg)                                           # cdb (logNdetg.003,logNdetg)\n   canonicalise   (logNdetg)                                           # cdb (logNdetg.004,logNdetg)\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\begin{dmath*} \\cdb*{eps.001} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{eps.002} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.001} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.002} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.003} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.004} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.005} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.006} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{Ndetg.104} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{sqrtNdetg.004} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{logNdetg.004} \\end{dmath*}\n\\end{dgroup*}\n\n% =================================================================================================\n% the remaining code is just for pretty printing\n\n\\clearpage\n\n\\begin{cadabra}\n   # note: keeping numbering as is (out of order) to ensure R appears before \\nabla R etc.\n   def product_sort (obj):\n       substitute (obj,$ x^{a}                            -> A000^{a}               $)\n       substitute (obj,$ g^{a b}                          -> A001^{a b}             $)\n       substitute (obj,$ \\nabla_{c d e f}{R_{a b}}        -> A007_{a b c d e f}     $)\n       substitute (obj,$ \\nabla_{c d e}{R_{a b}}          -> A006_{a b c d e}       $)\n       substitute (obj,$ \\nabla_{c d}{R_{a b}}            -> A005_{a b c d}         $)\n       substitute (obj,$ \\nabla_{c}{R_{a b}}              -> A004_{a b c}           $)\n       substitute (obj,$ \\nabla_{e f g h}{R_{a b c d}}    -> A011_{a b c d e f g h} $)\n       substitute (obj,$ \\nabla_{e f g}{R_{a b c d}}      -> A010_{a b c d e f g}   $)\n       substitute (obj,$ \\nabla_{e f}{R_{a b c d}}        -> A009_{a b c d e f}     $)\n       substitute (obj,$ \\nabla_{e}{R_{a b c d}}          -> A008_{a b c d e}       $)\n       substitute (obj,$ R_{a b}                          -> A002_{a b}             $)\n       substitute (obj,$ R_{a b c d}                      -> A003_{a b c d}         $)\n       sort_product   (obj)\n       rename_dummies (obj)\n       substitute (obj,$ A000^{a}                 -> x^{a}                          $)\n       substitute (obj,$ A001^{a b}               -> g^{a b}                        $)\n       substitute (obj,$ A002_{a b}               -> R_{a b}                        $)\n       substitute (obj,$ A003_{a b c d}           -> R_{a b c d}                    $)\n       substitute (obj,$ A004_{a b c}             -> \\nabla_{c}{R_{a b}}            $)\n       substitute (obj,$ A005_{a b c d}           -> \\nabla_{c d}{R_{a b}}          $)\n       substitute (obj,$ A006_{a b c d e}         -> \\nabla_{c d e}{R_{a b}}        $)\n       substitute (obj,$ A007_{a b c d e f}       -> \\nabla_{c d e f}{R_{a b}}      $)\n       substitute (obj,$ A008_{a b c d e}         -> \\nabla_{e}{R_{a b c d}}        $)\n       substitute (obj,$ A009_{a b c d e f}       -> \\nabla_{e f}{R_{a b c d}}      $)\n       substitute (obj,$ A010_{a b c d e f g}     -> \\nabla_{e f g}{R_{a b c d}}    $)\n       substitute (obj,$ A011_{a b c d e f g h}   -> \\nabla_{e f g h}{R_{a b c d}}  $)\n\n       return obj\n\n   def get_term (obj,n):\n\n       x^{a}::Weight(label=numx).\n\n       foo := @(obj).\n       bah  = Ex(\"numx = \" + str(n))\n       keep_weight (foo,bah)\n\n       return foo\n\n   def reformat (obj,scale):\n       foo  = Ex(str(scale))\n       bah := @(foo) @(obj).\n       distribute     (bah)\n       bah = product_sort (bah)\n       rename_dummies (bah)\n       canonicalise   (bah)\n       sort_sum       (bah)\n       factor_out     (bah,$x^{a?}$)\n       ans := @(bah) / @(foo).\n       return ans\n\n   def rescale (obj,scale):\n       foo  = Ex(str(scale))\n       bah := @(foo) @(obj).\n       distribute  (bah)\n       factor_out  (bah,$x^{a?}$)\n       return bah\n\n   # ---------------------------------------------------------------\n   # reformat Ndetg\n\n   Rterm0 = get_term (Ndetg,0)       # cdb(Rterm0.701,Rterm0)\n   Rterm1 = get_term (Ndetg,1)       # cdb(Rterm1.701,Rterm1)\n   Rterm2 = get_term (Ndetg,2)       # cdb(Rterm2.701,Rterm2)\n   Rterm3 = get_term (Ndetg,3)       # cdb(Rterm3.701,Rterm3)\n   Rterm4 = get_term (Ndetg,4)       # cdb(Rterm4.701,Rterm4)\n   Rterm5 = get_term (Ndetg,5)       # cdb(Rterm5.701,Rterm5)\n\n   Rterm0 = reformat (Rterm0,  1)    # cdb(Rterm0.702,Rterm0)\n   Rterm1 = reformat (Rterm1,  1)    # cdb(Rterm1.702,Rterm1)\n   Rterm2 = reformat (Rterm2,  3)    # cdb(Rterm2.702,Rterm2)\n   Rterm3 = reformat (Rterm3,  6)    # cdb(Rterm3.702,Rterm3)\n   Rterm4 = reformat (Rterm4,180)    # cdb(Rterm4.702,Rterm4)\n   Rterm5 = reformat (Rterm5, 90)    # cdb(Rterm5.702,Rterm5)\n\n   Ndetg := @(Rterm0) + @(Rterm1) + @(Rterm2) + @(Rterm3) + @(Rterm4) + @(Rterm5).  # cdb (Ndetg.701,Ndetg)\n\n   # ---------------------------------------------------------------\n   # reformat sqrtNdetg\n\n   Rterm0 = get_term (sqrtNdetg,0)   # cdb(Rterm0.801,Rterm0)\n   Rterm1 = get_term (sqrtNdetg,1)   # cdb(Rterm1.801,Rterm1)\n   Rterm2 = get_term (sqrtNdetg,2)   # cdb(Rterm2.801,Rterm2)\n   Rterm3 = get_term (sqrtNdetg,3)   # cdb(Rterm3.801,Rterm3)\n   Rterm4 = get_term (sqrtNdetg,4)   # cdb(Rterm4.801,Rterm4)\n   Rterm5 = get_term (sqrtNdetg,5)   # cdb(Rterm5.801,Rterm5)\n\n   Rterm0 = reformat (Rterm0,  1)    # cdb(Rterm0.802,Rterm0)\n   Rterm1 = reformat (Rterm1,  1)    # cdb(Rterm1.802,Rterm1)\n   Rterm2 = reformat (Rterm2,  6)    # cdb(Rterm2.802,Rterm2)\n   Rterm3 = reformat (Rterm3, 12)    # cdb(Rterm3.802,Rterm3)\n   Rterm4 = reformat (Rterm4,360)    # cdb(Rterm4.802,Rterm4)\n   Rterm5 = reformat (Rterm5,360)    # cdb(Rterm5.802,Rterm5)\n\n   sqrtNdetg := @(Rterm0) + @(Rterm1) + @(Rterm2) + @(Rterm3) + @(Rterm4) + @(Rterm5).  # cdb (sqrtNdetg.801,sqrtNdetg)\n\n   # ---------------------------------------------------------------\n   # reformat logNdetg\n\n   Rterm0 = get_term (logNdetg,0)    # cdb(Rterm0.901,Rterm0)\n   Rterm1 = get_term (logNdetg,1)    # cdb(Rterm1.901,Rterm1)\n   Rterm2 = get_term (logNdetg,2)    # cdb(Rterm2.901,Rterm2)\n   Rterm3 = get_term (logNdetg,3)    # cdb(Rterm3.901,Rterm3)\n   Rterm4 = get_term (logNdetg,4)    # cdb(Rterm4.901,Rterm4)\n   Rterm5 = get_term (logNdetg,5)    # cdb(Rterm5.901,Rterm5)\n\n   Rterm0 = reformat (Rterm0,  1)    # cdb(Rterm0.902,Rterm0)\n   Rterm1 = reformat (Rterm1,  1)    # cdb(Rterm1.902,Rterm1)\n   Rterm2 = reformat (Rterm2,  3)    # cdb(Rterm2.902,Rterm2)\n   Rterm3 = reformat (Rterm3,  6)    # cdb(Rterm3.902,Rterm3)\n   Rterm4 = reformat (Rterm4,180)    # cdb(Rterm4.902,Rterm4)\n   Rterm5 = reformat (Rterm5, 90)    # cdb(Rterm5.902,Rterm5)\n\n   logNdetg := @(Rterm0) + @(Rterm1) + @(Rterm2) + @(Rterm3) + @(Rterm4) + @(Rterm5).  # cdb (logNdetg.901,logNdetg)\n\n\\end{cadabra}\n\n\\clearpage\n\n% =================================================================================================\n\\section*{The metric determinant in Riemann normal coordinates}\n\n\\begin{dgroup*}\n   \\Dmath*{-\\det g(x) = \\cdb{Ndetg.701}+\\BigO{\\eps^6}}\n\\end{dgroup*}\n\n% =================================================================================================\n\\section*{The volume element in Riemann normal coordinates}\n\nIf $-\\det g(x)$ is non-negative then we also have\n%\n\\begin{dgroup*}\n   \\Dmath*{\\sqrt{-\\det g(x)} = \\cdb{sqrtNdetg.801}+\\BigO{\\eps^6}}\n\\end{dgroup*}\n\n% =================================================================================================\n\\section*{The log of -detg in Riemann normal coordinates}\n\nApart from the signs, this matches exactly the expression given by Calzetta etal. (eq. A14)\n\n\\begin{dgroup*}\n   \\Dmath*{\\log\\left(-\\det g(x)\\right) = \\cdb{logNdetg.901}+\\BigO{\\eps^6}}\n\\end{dgroup*}\n\n\\clearpage\n\n% =================================================================================================\n% export selected objects, these will later be imported into a library\n% these are the objects that will appear in the paper\n\n\\begin{cadabra}\n   cdblib.create ('detg2.export')\n\n   cdblib.put ('Ndetg',    Ndetg,    'detg2.export')\n   cdblib.put ('sqrtNdetg',sqrtNdetg,'detg2.export')\n   cdblib.put ('logNdetg', logNdetg, 'detg2.export')\n\n   checkpoint.append (Ndetg)\n   checkpoint.append (sqrtNdetg)\n   checkpoint.append (logNdetg)\n\n\\end{cadabra}\n\n% =================================================================================================\n% export checkpoints in 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": "022075bfae9f1b7a94e9443102a9c2de4e063b24", "size": 16133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/detg2.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/detg2.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/detg2.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": 41.5798969072, "max_line_length": 127, "alphanum_fraction": 0.5282340544, "num_tokens": 5719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.6603607710950883}}
{"text": "\\chapter{Statistical distance}\n\n\n\n% \\begin{figure}[H]\n%     \\centering\n%     \\includegraphics[width=.45\\textwidth]{scatter_dist_question.png}\n%     % \\caption{A comic}\n%     \\label{fig:scatter_dist_questions} \n% \\end{figure}\n\n\n\\begin{figure}[H]\n    \\captionsetup[subfigure]{labelformat=empty}\n    \\centering\n    \\subfloat[$X \\thicksim P$]{{\\includegraphics[width=5cm]{red_scatter.png} }}%\n    \\qquad\n    \\subfloat[$Y \\thicksim Q$]{{\\includegraphics[width=5cm]{other_scatter.png} }}%\n    \\caption{Samples from two different one dimensional sources, $X$ and $Y$; the x \n    axis represents the values that they take. \n    How can we tell if they come from the same distribution?}\n    \\label{fig:scatter_dist_questions}%\n\\end{figure}\n\n\nSuppose that we are given samples from two unknown distributions $P$ and $Q$, an \nimportant question to ask is: are $P$ and $Q$ equal?\n\n\nThe Integral Probability Metric (IPM) and f-divergence are two very rich and well studied\nfamilies of measures of \"distance\" between probability measures.\n\nWe start by introducing the Reproducing Kernel Hilbert Spaces (RKHS), which will serve as a \nbuilding block for the maximum mean discrepancy (\\cite{TwoSampleTestGrettonBernhard}), an important instance of IPM.\n\nAs we saw in the previous chapter, to understand causality, it is crucial to be able to \nmeasure statistical dependence between random variables; therefore our ability of \nperforming causal inference will largely hinge on our ability to measure dependence \nbetween random variables. \n\n\\newpage\n\\section{Reproducing Kernel Hilbert Space}\n\nKernels are an important component of the RKHS, and we will begin by defining them.\n\n\\subsection{Kernels}\n\n\\begin{definition}\n    Let $\\mathcal{X}$ be a non-empty set. A function \n    $k: \\mathcal{X} \\times \\mathcal{X} \\rightarrow \\R$ is a kernel if \n    \\begin{enumerate}\n        \\item $k$ is symmetric: $k(x, y) = k(y, x)$, $\\forall x, y \\in \\mathcal{X}$\n        \\item $k$ is positive semi-definite, i.e. $\\forall x_1, ..., x_n \\in \\mathcal{X}$,\n        the \"Gram Matrix\" $K$, defined by $K_{ij} = k(x_i, x_j)$ is positive semi-definite\n        \\footnote{A matrix $M \\in \\R^{n\\times n}$ is positive semi-definite if $\\forall a \\in \\R^n$\n        , $a^\\intercal Ma \\geq 0$}.\n    \\end{enumerate}\n\\end{definition}\n\nIt is easy construct new kernels since they are preserved under addition, multiplication and other operations. \n(See for example \\cite{GrettonNotes}).\n\nOne example of a kernel --- and one of the most popular ones --- is the Gaussian Kernel defined on $\\R^d$:\n\n$$\n    k(x, y) = \\exp (-\\gamma^{-2}\\norm{x - y}^2)\n$$\n\n\\subsection{Constructing the Reproducing Kernel Hilbert Space}\n\nLet $\\mathcal{X}$ be an arbitrary set and $\\mathcal{H}$ a Hilbert space of real valued functions\non $\\mathcal{X}$. As per general convention, addition and multiplication are define pointwise:\n\n\\begin{equation}\n    \\begin{array}{lll}\n    (\\lambda \\cdot f)(x) & :=\\lambda \\cdot f(x) & \\forall \\lambda \\in \\R, \\forall f \\in \\mathcal{H} \\text { and } \\forall x \\in \\mathcal{X} \\\\\n    (f+g)(x) & :=f(x)+g(x) & \\forall f \\in \\mathcal{H}, \\forall g \\in \\mathcal{H} \\text { and } \\forall x \\in \\mathcal{X}\n    \\end{array}\n\\end{equation}\n\n% One powerful fact about Hilbert spaces is that every Hilbert space admits an orthonormal basis, \n% and each vectorin the Hilbert space can be expanded as a series in terms of this orthonormal basis.\n\n% For instance L2 blah blah\n\n% $f \\in L^1$ then we can decompose $f$ as follows:\n\n% $$\n%     f(x) = \\int_{-\\infty}^{\\infty} \\hat{f}(\\omega) e^{2 \\pi i x \\omega} d \\omega\n%     = \\inp*{\\hat{f}}{\\phi(x)}\n% $$\n\nWe will now take a look at Hilbert spaces whose structure is highly linked with a kernel. \nNote that if we pick some $x \\in \\mathcal{X}$, then $k(x, .)$ is a function from $\\mathcal{X}$ to $\\R$.\n\n\\begin{definition}\n    Let $\\mathcal{H}$ be a Hilbert space of functions $f: \\mathcal{X} \\rightarrow \\R$. \n    $\\mathcal{H}$ is called a Reproducing Kernel Hilbert Space (RKHS) if there is a kernel k such that\n\n    \\begin{enumerate}\n        \\item $ k(x, \\cdot) \\in \\mathcal{H} \\quad \\forall x \\in \\mathcal{X}$\n        \\item $ \\inp*{f}{k(x, \\cdot)} = f(x) \\quad \\forall f \\in \\mathcal{H}$\n    \\end{enumerate}\n\n\\end{definition}\n\nGiven the kernel $k$ it is convenient to define the feature map $\\phi: \\mathcal{X} \\rightarrow \\mathcal{H}$ as:\n\n$$\n    \\phi(x) = k(x, \\cdot)\n$$\n\nThe intuition is that in this space, we can view functions as linear combinations\\footnote{\n    Note that if $f(x)$ is an element of $\\mathcal{H}$, then we write $f$ as the coefficients\n    for the feature representation. \n} of features:\n\n$$\n    f(x) =  \\inp*{f}{k(x, \\cdot)} = \\inp*{f}{\\phi(x)}\n$$\n\n\nThe power of this setup --- which is known as the kernel trick --- is that inner products between\nfeatures (which can live in infinite spaces) are simple function evaluations; \nindeed by letting $f(x) = k(x, x^\\prime)$ we get\n\n$$\n    \\inp*{k(x^\\prime, \\cdot)}{k(x, \\cdot)} = k(x, x^\\prime)\n$$\n\nObserve that both conditions imply that $k$ spans $\\mathcal{H}$, i.e.\n\n\\begin{equation}\n    \\mathcal{H}=\\overline{\\operatorname{span}\\{k(\\cdot, x): x \\in \\mathcal{X}\\}}\n\\end{equation}\n\nIndeed is is possible to go the other way around\\footnote{See the excellent lecture notes on \nRKHS \\cite{BartlettNotes} for more details.} and first define the following vector space\n\n\\begin{equation}\n    \\operatorname{span}(\\{\\phi(x): x \\in \\mathcal{X}\\})=\\left\\{f(\\cdot)=\n    \\sum_{i=1}^{n} \\alpha_{i} k\\left(\\cdot, x_{i}\\right): n \\in \\N, x_{i} \n    \\in \\mathcal{X}, \\alpha_{i} \\in \\R\\right\\}\n\\end{equation}\n\nWe can then equip this space with an inner product and to show that it is complete in order to create\na Hilbert Space (at which point we will have created a RKHS). \n\n\\subsection{The kernel trick in action}\n\nWe will now show an application to illustrate both the power of the RHKS and to refine our intuition of it. \nSuppose that we have \nsome data say $\\{ x_i, y_i\\}_{i \\in [n]}$; we believe for example $y$ to be a smooth function of $x$ and we \nexpect some independent additive noise.\n\nWe can estimate $f$ as follows\n\\footnote{Note that it is not obvious how to implement the optimization as $\\mathcal{H}$ may be infinite. However,\nthis setup with a Gaussian kernel is in fact equivalent to a Gaussian Processes, which can be easily\nimplemented in practice (see \\cite{JordanNotes}).}, pick an RHKS $\\mathcal{H}$ with a Gaussian kernel, and some \n$\\Omega > 0$:\n\n\\begin{equation}\n    f^{*}=\\arg \\min _{f \\in \\mathcal{H}}\\left(\n        \\sum_{i=1}^{n} \n        \\left(y_{i} - \\inp*{f}{\\phi\\left(x_{i}\\right)}_{\\mathcal{H}} \\right)^{2}\n        + \\Omega \\norm{f}_{\\mathcal{H}}^{2}\\right)\n\\end{equation}\n\nAn amazing result is that an optimization of the above form will always admit a representation of the\nform:\n\n\\[\n    f^{*} = \\sum_{i=1}^{n} \\alpha_{i} \\phi\\left(x_{i}\\right)\n\\]\nwhere $\\alpha_{i} \\in \\mathbb{R}$ for all $1 \\leq i \\leq n$.\n\nThis is known as the Representer Theorem (\\cite{scholkopf2001generalized}); all it requires is \nthat we be in the usual RHKS setup, and that\nthe regularization be a strictly increasing\\footnote{In our case regularization is linear,\nwe thus simply need to pick $\\Omega \\geq 0$.} real valued function.\nIf we wish to approximate a prediction for some new sample $x$, we can do so as follows:\n\n\n$$\n    f^{*}(x) = \\inp*{f^{*}}{\\phi\\left(x\\right)} = \n    \\sum_{i=1}^{n} \\alpha_{i} \\inp*{\\phi\\left(x_i\\right)}{\\phi\\left(x\\right)} =\n    \\sum_{i=1}^{n} \\alpha_{i} k\\left(x_i, x\\right)\n$$\n\nIt is precisely because the solution is of this form, that we may exploit the kernel trick. We can\nalso quickly see what the role of the kernel is. If for example, $k$ is the Gaussian Kernel, then\nthe solution will be a linear combination of scaled Gaussians centered at the data points\n\\footnote{In fact this will always be the case when we can write $k\\left(x, y\\right) = \\tilde{k}\\left(x - y\\right)$}. \n\nAs a final remark we will explain the role of the penalty $\\Omega \\norm{f}_{\\mathcal{H}}^{2}$; from \nstatistical models, we know that this kind of term is known as regularization and is supposed to help \nchoose a \"simpler\" model. As we will now show, this is also the case here.\n\nTo see this, we will use Mercer's Theorem (as stated in the lecture notes of \\cite{BartlettNotes}) --- a Generalization of the spectral theorem for positive-semidefinite\nmatrices\\footnote{Recall that our Kernel $k$ is a generalization of a positive-semidefinite Matrix}.\n\n\\begin{theorem}[Mercer's] \n\nSuppose $k$ is a continuous positive semi-definite kernel on a compact set $\\mathcal{X}$, then if\n, for all $f \\in L_{2}(\\mathcal{X})$\n\n\\[\n\\int_{\\mathcal{X}} k(u, v) f(u) f(v) d u d v \\geq 0\n\\]\n\nthen $k$ has the following decomposition\n\n\\begin{equation}\n    k(u, v)=\\sum_{i=1}^{\\infty} \\lambda_{i} \\psi_{i}(u) \\psi_{i}(v)\n\\end{equation}\n\nwhere $\\{\\psi_i\\}$ forms an orthonormal basis of $L_2(\\mathcal{X})$, \nsuch that the corresponding sequence of eigenvalues $\\{\\lambda_i\\}$ are non-negative.\n\nThe convergence is absolute and uniform, that is,\n\\[\n\\lim _{n \\rightarrow \\infty} \\sup _{u, v}\\left|k(u, v)-\\sum_{i=1}^{n} \\lambda_{i} \\psi_{i}(u) \\psi_{i}(v)\\right|=0\n\\]\n    \n\\end{theorem}\n\nWe can now use this decomposition of the Kernel to get further insight, using Mercer's theorem we can \nthus write --- assuming the conditions are met:\n\n$$\n    k \\left(x, x^{\\prime}\\right)=\\sum_{i=1}^{\\infty} \n    \\underbrace{\\left[\\sqrt{\\lambda_{i}} \\psi_{i}(x)\\right]}_{\\phi_{i}(x)} \n    \\underbrace{\\left[\\sqrt{\\lambda_{i}} \\psi_{i}\\left(x^{\\prime}\\right)\\right]}_{\\phi_{i}\\left(x^{\\prime}\\right)}\n$$\n\nWe can thus rewrite the solution as follows\n\n$$\n    f^{*}(x) = \\sum_{i=1}^{n} \\alpha_{i} k\\left(x_i, x\\right) = \n    \\sum_{i=1}^{\\infty} \\phi_i\\left(x\\right) \n    \\sum_{j=1}^{n} \\alpha_{j}  \\phi_i\\left(x_j\\right) = \n    \\sum_{i=1}^{\\infty} \\sqrt{\\lambda_{i}} \\psi_{i}(x) f^{*}_i \n$$\n\nNote that due to the $\\Omega \\norm{f}_{\\mathcal{H}}^{2}$ penalty, $f^{*}_i$ must decay for higher values of $i$. Note that\nfor example for the Fourier Transform\n, in the basis $\\{\\psi_i\\}$, higher values of $i$ correspond to higher \nfrequency functions; similarly, for the Gaussian Kernel, higher indices basis functions correspond to \nhigher frequencies\\footnote{In the fourier space, we have the following\nbasis $\\psi_\\omega = \\exp (2\\pi i x \\omega)$}. Thus, a higher $\\Omega$ will force a faster decay on $f_i$ and thus result in smoother functions\n-- in principle, this will reduce overfitting. \n\n% \\begin{figure}[htp]\n\\begin{figure}[H]\n\n    \\centering\n    \\includegraphics[width=.33\\textwidth]{gp_goodfit.png} \n    \\includegraphics[width=.33\\textwidth]{gp_underfit.png} \n    \\includegraphics[width=.33\\textwidth]{gp_overfit.png} \n    \\caption{Small RKHS norm results in smooth functions. \n    From left to right $\\Omega = 2$, $\\Omega = 14$, $\\Omega = 0.2$, \n    we fix the Gaussian kernel with $\\gamma = 0.6$}\n    \\label{fig:kernel_smoothness}  \n\\end{figure}\n\n\n\\section{Integral Probability Metric}\n\n\\subsection{Introduction}\n\nWe now turn to the question of statistical distance, i.e. given samples of $P$ and\n$Q$, how can we determine if $P = Q$?\n\nObserve that if two random variables $X$, $Y$ share the same distribution, then \n\n$$\n\\E(g(X)) = \\E(g(Y))\n$$\n\nfor any continuous and bounded function $g : \\R \\rightarrow \\R$. \nIt turns out that the reciprocal statement holds as well. (See \\cite{TwoSampleTestGrettonBernhard})\n\nThis motivates the following construction\n\n$$\nD_\\mathcal{F} (P, Q) = \n\\sup _{g \\in \\mathcal{F}} \\mid \\mathop{\\E}_{X \\sim P} g(X) - \\mathop{\\E}_{Y \\sim Q} g(Y) \\mid\n$$\n\nwhere $\\mathcal{F}$ is a class of real-valued bounded measurable functions.\n\n% See for example \\cite{sriperumbudur2009integral} for a detailed analaysis\n\nThis defines a rich class of distance measures known as \nintegral probability metrics (IPMs) (see \\cite{muller1997integral}). Depending\non how we choose $\\mathcal{F}$ we may end up with different popular distance measures, such as\nthe Wasserstein distance or the Total variation distance to name a few. \n\nThe goal is to design an $\\mathcal{F}$ that is \"expressive\" enough so that the IPM goes to zero iff $P = Q$,\nand on the other hand, we need $\\mathcal{F}$ to be \"restrictive\" enough so as to have fast and \nreliable guarantees of the empirical estimate of the IPM (\\cite{TwoSampleTestGrettonBernhard}.)\n\n\n\\subsection{MMD}\n\nConsider $\\mathcal{F}=\\left\\{f:\\|f\\|_{\\mathcal{H}} \\leq 1\\right\\}$, this is known\nas the maximum mean discrepancy (MMD); where $\\mathcal{H}$, is a reproducing kernel Hilbert space \n(RHKS) with $k$ as its reproducing kernel. \n\nWe will next extend the notion of the feature map to the \\textbf{embedding of probability distributions}. \nRecall that if $\\phi$ is the associated feature map to the kernel $k$ from \nRKHS $\\mathcal{H}$ then we have $g(x) = \\inp*{g}{\\phi(x)}$.\n\nWe define $\\mu_P \\in \\mathcal{H}$, s.t. $\\forall g \\in \\mathcal{H}$, we have that\n$\\mathop{\\E}_{X} g(X) = \\inp*{g}{\\mu_P}$. We will now show under which conditions $\\mu_P$ exits\n(we follow the derivations as done by \\cite{Peters2008diploma}).\n\n\\begin{lemma}\\label{embedding_existance}\n    If k is measurable and $\\mathop{\\E}_{X} \\sqrt{k(X, X)} < \\infty$ then\n    $\\mu_P \\in \\mathcal{H}$\n\\end{lemma}\n\n\\begin{proof}\n\\begin{align*}\n    \\left|\\E_{X} g(X)\\right| &\\leq \n    \\E_{X}|g(X)| \\\\\n    &=\n    \\E_{X}\\left| \\inp*{g}{\\phi(X)}_{\\mathcal{H}}\\right| \\\\\n    &\\leq\n    \\E_{X} \\norm{g}_{\\mathcal{H}} \\norm{\\phi(X)}_{\\mathcal{H}} \\\\\n    &= \\norm{g}_{\\mathcal{H}} \\E_{X} \\sqrt{k(X, X)}\n\\end{align*}\n\nThe first inequality follows from the triangle inequality, and the following equality by using \nthe feature map representation; we conclude by applying Cauchy-Schwartz.\n\nThus $E_{X} g(X)$ is a bounded linear operator $\\forall g \\in \\mathcal{F}$, and by the\nRiesz representer theorem it follows that there exists a $\\mu_P \\in \\mathcal{H}$\ns.t. $\\mathop{\\E}_{X} g(X) = \\inp*{g}{\\mu_P}$. \n\\end{proof}\n\n\nWe can also see that the mean embedding of the distribution $P$ is the expectation under $P$\nof the feature map $\\phi$.\n\n$$\n    \\mathop{\\E}_{X \\sim P} g(X) = \n     \\inp*{g}{ \\mathop{\\E}_{X \\sim P} \\phi(X)} = \\inp*{g}{\\mu_P}\n$$\n\nAssuming Lemma \\ref{embedding_existance} --- and using Cauchy-Schwartz, \nwe can explicitly solve the MMD in terms of the mean embeddings:\n\n\\begin{align*} \n    \\text{MMD}_\\mathcal{F} (P, Q) \n    &= \n    \\sup _{g \\in \\mathcal{F}} \\mid \\mathop{\\E}_{X \\sim P} g(X) - \\mathop{\\E}_{Y \\sim Q} g(Y) \\mid \\\\\n    &= \n    \\sup _{g \\in \\mathcal{F}} \\mid \\inp*{g}{\\mu_P - \\mu_Q} \\mid \\\\\n    &=\n    \\norm{\\mu_P - \\mu_Q}_\\mathcal{H}\n\\end{align*}\n\nWe can therefore see the MMD as the feature mean difference of the distributions; we can further\nexpand this expression to get the result as a function of the kernel.\n\n\\begin{align*}\n    \\text{MMD}_\\mathcal{F}^2 (P, Q)\n    &=\n    \\norm{\\mathop{\\E}_{X \\sim P} \\phi(X)  - \\mathop{\\E}_{Y \\sim Q} \\phi(Y) }_\\mathcal{H}^2 \\\\\n    &= \\mathop{\\E}_{X \\sim P} \\mathop{\\E}_{X^\\prime \\sim P} \\inp*{\\phi(X)}{\\phi(X^\\prime)} - \n    2 \\mathop{\\E}_{X \\sim P} \\mathop{\\E}_{Y \\sim Q} \\inp*{\\phi(X)}{\\phi(Y)} +\n    \\mathop{\\E}_{Y \\sim Q} \\mathop{\\E}_{Y^\\prime \\sim Q} \\inp*{\\phi(Y)}{\\phi(Y^\\prime)} \\\\\n    &= \\mathop{\\E}_{X \\sim P} \\mathop{\\E}_{X^\\prime \\sim P} k \\left( X, X^\\prime \\right) - \n    2 \\mathop{\\E}_{X \\sim P} \\mathop{\\E}_{Y \\sim Q} k \\left( X, Y \\right) +\n    \\mathop{\\E}_{Y \\sim Q} \\mathop{\\E}_{Y^\\prime \\sim Q} k \\left( Y, Y^\\prime \\right)\n\\end{align*}\n\nNote that we can straightforwardly estimate with samples the above expression; all the we require is \nto specify a kernel: \\textit{so how do we choose a kernel}?\n\nWe need to ensure that $\\text{MMD}(P, Q) = 0$ iff $P = Q$, in other words, $\\mu_P$ needs to be injective\nas a function of $P$. Intuitively this means that $\\mathcal{F}$ needs to be expressive enough to \nreproduce enough continuous functions. One can show that to check if the resulting embedding \n$\\mu_P$ is injective, we may check either of these sufficient conditions (\\cite{sriperumbudur2008injective}) \non the Kernel $k$:\n\n\\begin{enumerate}\n    \\item $k$ is a universal kernel.\n    \\item $k$ is a convolution kernel on $\\R^n$, for which the Radon-Nikodym derivative of \n    its inverse Fourier transform is supported almost everywhere.\n\\end{enumerate}\n\nThe first condition is basically what we knew intuitively: \nIf we consider a compact metric space, say $(\\mathcal{X}, d)$, then a Kernel $k$ on $\\mathcal{X}$\nis called universe if the corresponding RKHS is dense \nin the space $C(\\mathcal{X})$ of all continuous functions. The drawback is that the input space $\\mathcal{X}$ needs to be compact --- which excludes $\\R^n$; \nthis means that we cannot use universality to check our Gaussian kernel. Luckily the second condition\nis enough.\n\nAssuming $k$ is a bounded continuous positive definite function, then if we can write\n$k(x, y) = \\psi (x - y)$ we say that $k$ is a convolution kernel.\n\nFrom inspection it is clear that the Gaussian kernel is convolutional\n\n$$\n    k(x, y) = \\exp (-\\gamma^{-2}\\norm{x - y}^2)\n$$\n\nA cool fact about the Gaussian is that it is the fixed point of convolution\n, which trivially implies\nthat the inverse Fourier transform of a Gaussian is supported everywhere. \n This means that the Gaussian kernel satisfies the second\ncondition, and it therefore generates an injective embedding $\\mu_P$.\n\nWe note that HSIC is to MMD, what the Mutual Information is to the Kullback–Leibler divergence (in the \nsense that they measure the distance between the joint and product of the marginal distributions to test for independence).\n\nIn practice the Gaussian kernel is very popular, it is used in the HSIC test when used as a\nscore function by \\cite{Mooij2016jmlr}; but how do we find the parameter --- sometimes referred to \nas the bandwidth --- of the kernel?\n\nOne approach is the median heuristic (\\cite{scholkopf2002learning}):\n\n$$\n\\hat{\\gamma}(\\mathbf{u}):=\\operatorname{median}\\left\\{\\left\\|u_{i}-u_{j}\\right\\|:  i<j ,\\left\\|u_{i}-u_{j}\\right\\| \\neq 0\\right\\}\n$$\n\n\\subsection{The case for MMD}\n\nIn their study, \\cite{sriperumbudur2009integral}) argue that the \"IPM is much\nsimpler than estimating f-divergences, and that the estimators\nare strongly consistent while exhibiting good rates of convergence. IPMs also account for the properties of\nthe underlying space $\\mathcal{M}$ through the Kernel in case of MMD. This is especially\nuseful when considering disjoint supports between P and Q\"\n\nAnother argument for the MMD, is that we only need to choose a kernel; in contrast, \nwhen applying the f-divergence in practice we need to quantize in order to get an \nempirical distribution. While both can be seen as a hyperparameter, the effect of \ndiscretisation is not as obvious as that of choosing a kernel. \n\n\\section{f-divergence}\n\nThe f-divergence (\\cite{csiszar2004information}) is another family of probability measures, and more simple than IPM.\n\n\\begin{definition}[f-divergence]\n    ~\nLet $P$ and $Q$ be two probability distributions over a space $\\Omega$, \nsuch that $P$ is absolutely continuous with respect to $Q$; and let \n$f: \\R_+ \\rightarrow \\R$ be a convex function satisfying $f(1) = 0$. The $f$ divergence of \n$P$ from $Q$ is defined as\n\n$$\n    \\infdiv{P}{Q} := \\int_\\Omega f \\left( \\frac{dP}{dQ} \\right) dQ\n$$\n    \n\\end{definition}\n\n\nWe first show why divergence has some desirable properties for a probability measure:\n\n\n\\begin{align*}\n    \\infdiv{P}{Q} &= \\E_Q \\left[ f \\left( \\frac{dP}{dQ} \\right) \\right] \\\\\n    &\\geq f \\left( \\E_Q \\left[  \\frac{dP}{dQ} \\right]  \\right) \\\\\n    &= f \\left( \\int_\\Omega \\frac{dP}{dQ} dQ  \\right) \\\\\n    &= f(1) \\\\\n    &= 0\n\\end{align*}\n\nThe inequality follows from the convexity of $f$, this tells us that \n$\\infdiv{P}{Q} \\geq 0$. From the definition it is clear that $\\infdiv{P}{P} = 0$; further,\nif $f$ is \\textit{strictly} convex at $1$, then we have that $\\infdiv{P}{Q} = 0$ iff $P = Q$.\n\nTherefore roughly speaking, all f-divergences define a way to measure similarities between distributions. \n\nHowever, in general it is not symmetric in $P$ and $Q$, so it is not a metric.\n\nThe following are some examples of f-divergences:\n\n\\begin{itemize}\n    \\item[--] \\textbf{Kullback-Leibler (KL) divergence}: $f(x) = x \\log(x)$\n    \\item[--] \\textbf{Total Variation (TV)}: $f(x) = \\frac{1}{2} \\abs{x - 1}$, note that \n    in this case we have\n    $$\n        \\infdiv{P}{Q} = \\frac{1}{2} \\E_Q \\left[ \\abs{ \\frac{dP}{dQ} - 1} \\right]\n        = \\frac{1}{2} \\int_\\Omega \\abs{ dP - dQ} \n    $$\n    Note that the TV is also a metric on the space of probability distributions.\n\\end{itemize}\n\n% While seemingly less flexible than IPM, the f-divergences have a very rich theory behind them, \n\n\n% There are many very useful theoretical results about f-divergences, among them is the \n% data processing inequality which also plays a central role in many proofs in Information Theory. \n\n% \\begin{lemma}[Data Processing Inequality (DPI)]\n%     Let $X$ and $Y$ be two random variables, and let $P_X$ and $Q_X$ be two measures on $X$. If we \n%     pass these measures through a kernel, say $P_{Y|X}$ the resulting measures $P_X$ and $Q_X$ will\n%     satisfy:\n\n%     $$\n%         \\infdiv{P_X}{Q_X} \\geq \\infdiv{P_Y}{Q_Y}\n%     $$\n%     \\label{lemma:dpi}\n% \\end{lemma}\n\n% A proof of this lemma and more ineteresting facts about f-divergences can be found in chapter\n% 2 of \\cite{duchiEE377}. \n\n\\section{Independence tests}\n\nIt is rather straightforward to come up with independence tests once we are we are able to test \nfor the distance between distributions. Say we are given two random variables $X$ and $Y$, with \nvalues over the product space $\\mathcal{X} \\times \\mathcal{Y}$. If their joint distribution is \n$P_{X, Y}$, and their marginal distributions are $P_X$ and $P_Y$. Then to check if $X \\bigCI Y$\nwe need to verify if $P_{X, Y} = P_X \\otimes P_Y$.\n\nIf we want to create an independence test from an f-divergence, say $f(x) = x\\log(x)$, then we \ncan do as follows:\n\n$$\n    I (X; Y) :=  \\infdiv{P_{X, Y}}{P_X \\otimes P_Y}\n$$\n\nThis is in fact the well known Mutual Information from Information Theory! \n\nRecall that for the MMD we need to provide a kernel, since we are now in a product space, we need \nto provide a product kernel on the space ($\\mathcal{X}, \\mathcal{Y}$): (\\cite{Peters2008diploma})\n\n\\begin{align*}\n    \\mathcal{X} \\times \\mathcal{Y} \\quad &\\rightarrow \\qquad \\R \\\\\n    ( (x, y) (\\tilde{x}, \\tilde{y})) &\\mapsto k(x, \\tilde{x}) \\cdot l(y, \\tilde{y})\n\\end{align*}\n\nwhere $k$ and $l$ are kernels on $\\mathcal{X}$ and $\\mathcal{Y}$ respectively. We can then define the \nMMD to test independence as follows:\n\n$$\n    \\operatorname{MMD}\\left( P_{X, Y}, P_X \\otimes P_Y  \\right)\n$$\n\nObserve that \n\n$$\n    \\operatorname{MMD}\\left( P_{X, Y}, P_X \\otimes P_Y  \\right)^2 = \\operatorname{HSIC}(P_{X, Y})\n$$\n\nThe HSIC is the MMD distance between the joint and product distribution. \n\n\n", "meta": {"hexsha": "49ec04a6343656a6624c9994814e07b5e9dbe364", "size": 22819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main/ch3_distance.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/ch3_distance.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/ch3_distance.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": 41.2640144665, "max_line_length": 169, "alphanum_fraction": 0.685130812, "num_tokens": 7127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219503, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.6603607691582905}}
{"text": "\\section{Practical Training Method\n in Large-Scale Machine Learning Problems}\n\n\\subsection{Basic Gradient Descent Type Algorithms}\nNow we suppose we have a machine learning model\n\\begin{equation}\nf(x; w),\n\\end{equation}\nwhere $f$ can be any machine learning model like: linear regression, SVM or deep learning models. \n\nWe have data as \n$$\nz_i=\\{x_i, y_i\\}\\quad i = 1:N,\n$$\nand the loss between the label and prediction is:\n$$\nf_i(w) = l(f(x_i, w), y_i),\n$$\none example of $l$ is:\n$$\nl(f(x_i, w), y_i) = \\|f(x_i, w)- y_i\\|^2.\n$$\nWhat we want to solve is:\n\\begin{equation}\n\\mathop{\\min}_{{w} \\in \\mathbb{R}^{n}} \\frac{1}{N}\\sum_{i=1}^N f_i(w).\n\\end{equation}\n\n\\subsubsection{Mini-Batch Method}\nNow we introduce the Mini-Batch algorithm which is mostly used in basic algorithm for above problem:\n\\begin{algorithm}[H]\n\\caption{Mini-Batch}\n\\label{alg:mini-batch}\n{\\bf Input}: learning rate $\\eta_t$, batch size $m$, parameter initialization $ w_0$, number of epochs $K$. \\\\\n%For iteration $t = 1: K\\frac{N}{m}$ \\\\\nFor Epoch $k = 1:K$\\\\\nShuffle data and get mini-batch $B_1, \\cdots, B_{\\frac{N}{m}}$, choose mini-batch as: $B_{i_t}$ with\n$$\ni_t \\equiv t \\mod(\\frac{N}{m}),\n$$\nCompute the gradient on $B_{i_t}$:\n$$\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t})\n$$\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t - \\eta_t g_t.\n\\end{equation}\n\\end{algorithm}\n\nThis method is a little different from pure SGD type method as we still have\n$$\n\\mathbb{E} g_t = \\nabla f,\n$$\nexcept  the choice of $\\nabla f_i$ and $\\nabla f_{i+1}$ are dependent.\nBut this method works very well with some suitable batch-size. Recently, many researches show that small batch-size may lead to some flat minimizer with better generalization error. And some research suggests that, you can use a small batch size at the beginning and increase the batch size slowly with iteration.\n\n\n\\subsection{Deterministic Algorithm(a specially case):  Incremental Gradient Descent Method}\nThe cycle incremental gradient descent method:\n\\begin{algorithm}\\caption{CIGD}\n\t\\label{alg:CIGD}\n\t\\begin{equation}\\label{equ:GS-iteration}\n\tx_{t+1} = \\Pi_{\\mathcal{X}}(x_{t} - \\eta_t \\nabla f_{i_t}(x_t)), \\quad t = 0:T,\n\t\\end{equation}\n\t\\begin{equation}\n\ti_t \\equiv t \\mod(m), \\quad i_t \\in 1:m,\n\t\\end{equation}\n\\end{algorithm}\n\n\n\\subsection{Convergence for CIGD}\nWe start with the iteration scheme step by step, and analyze it first, and then sum a cycle iteration together.\n\nA simple sufficient condition for the above assumption is that $f_i \\in C^2(\\mathcal{X})$ and is convex with $\\mathcal{X}$ is a compact convex set. \n\nHere we prove an important lemma:\n\\begin{lemma}\\label{lem:CIGDexpand}Let $\\{x_k\\}$ be the sequence generated by algorithm \\ref{alg:CIGD} with $\\eta_t = \\eta_k$ for $t = km:((k+1)m-1)$, then for any $y \\in \\mathcal{X}$, we have\n\t\\begin{equation}\\label{equ:CIGDexpand}\n\t\\|x_{(k+1)m} - y\\|^2 \\le \\|x_{km} - y\\|^2 - 2m\\eta_k(f(x_{km}) - f(y)) + \\eta_k^2\\beta m^2M^2,\n\t\\end{equation}\n\twhere $\\beta = 2 - \\frac{1}{m}$\n\\end{lemma}\n\n\\begin{proof}\n\tBy the definition of iteration scheme:\n\t\\begin{equation}\\label{equ:basicinequICGD}\n\t\\|x_{km+j} - y\\|^2 \\le \\|x_{km+j-1} - y\\|^2 -2\\eta_k \\nabla f_{j}(x_{km+j-1})^{T}(x_{km+j-1}-y) + \\eta_k^2 M^2, \\quad \\forall j = 1:m.\n\t\\end{equation}\n\tBecause of the convexity of $f_i$, we have\n\t\\begin{equation}\n\t\\nabla f_{j}(x_{km+j-1})^{T}(x_{km+j-1}-y) \\ge f_{j}(x_{km+j-1}) - f_{j}(y).\n\t\\end{equation}\n\tAdd all $j = 1:m$ together\n\t\\begin{equation}\n\t\\|x_{(k+1)m} - y\\|^2 \\le \\|x_{km} - y\\|^2 -2m\\eta_k (f(x_{km}) - f(y))+ m\\eta_k^2 M^2 + 2\\eta_k\\sum_{j=1}^m(f_{j}(x_{km}) - f_{j}(x_{km+j-1}) ).\n\t\\end{equation}\n\tFor the last term we have:\n\t\\begin{equation}\n\tf_{j}(x_{km}) - f_{j}(x_{km+j-1}) \\le M\\| x_{km} - x_{km + 1} \\| + \\cdots + M\\|x_{km+j-2} - x_{km+j-1}\\| \\le 2(j-1)\\eta_k M^2,\n\t\\end{equation}\n\tthe last inequality can be proven by take $y = x_{km + j -1}$ in \\ref{equ:basicinequICGD}.\n\t\n\tFinally we have\n\t\\begin{equation}\n\t\\|x_{(k+1)m} - y\\|^2 \\le \\|x_{km} - y\\|^2 -2m\\eta_k (f(x_{km}) - f(y))+ m\\eta_k^2 M^2 + 2\\eta_k^2 M^2m(m-1),\n\t\\end{equation}\n\twhich is the form of \\ref{equ:CIGDexpand} with $\\beta = 2 - \\frac{1}{m}$.\n\\end{proof}\n\nUsing this lemma, we can have the next results:\n\\begin{theorem}\n\tLet $\\eta_k$ be fixed at some positive constant $\\eta$.\n\t\\begin{itemize}\n\t\t\\item If $ f^* = \\min_{x \\in \\mathcal{X}}f(x) = -\\infty$, then\n\t\t\\begin{equation}\n\t\t\\mathop{\\lim\\inf}_{k \\to \\infty} f(x_k) = f^*.\n\t\t\\end{equation}\n\t\t\\item If $f^* > -\\infty$, then \n\t\t\\begin{equation}\n\t\t\\mathop{\\lim\\inf}_{k \\to \\infty} f(x_k) \\le f^* + \\frac{\\eta \\beta m M^2}{2},\n\t\t\\end{equation}\n\t\twhere $\\beta$ is the same in lemma \\ref{lem:CIGDexpand}.\n\t\\end{itemize}\n\\end{theorem}\n\n\\begin{theorem}\n\tIf $X^* = \\mathop{\\arg\\min}f(x)$ is nonempty. Then for $\\epsilon > 0$, we have \n\t\\begin{equation}\n\t\\min_{ 0\\le k \\le N} f(x_k) \\le f^* + \\frac{\\eta \\beta m^2 M^2 + \\epsilon}{2m},\n\t\\end{equation}\n\twhere $N$ is given by\n\t\\begin{equation}\n\tN = m \\lfloor \\frac{\\rm{dist}(x_0;X^*)^2}{\\eta \\epsilon}\\rfloor.\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\n\tIf the stepsize $\\eta_k$ satisfy\n\t\\begin{equation}\n\t\\lim_{k \\to \\infty} \\eta_k = 0, \\quad \\sum_{k=0}^{\\infty} \\eta_k = \\infty.\n\t\\end{equation}\n\tThen,\n\t\\begin{equation}\n\t\\mathop{\\lim\\inf}_{k\\to \\infty} f(x_k) = f^*.\n\t\\end{equation}\n\tFurthermore, if $X^*$ is nonempty and \n\t\\begin{equation}\n\t\\sum_{k=0}^\\infty \\eta_k^2 < \\infty,\n\t\\end{equation}\n\tthen $\\{x_k\\}$ converges to some $x^* \\in X^*$.\n\\end{theorem}\n\nAs far as we know, it is still an open problem to establish rate of\nconvergence for CIGD method.  In contrast, convergence rate in $L^2$\ncan be established for stochastic gradient (SGD) method.  \n\\subsection{Some comments}\nMinimizing $f_1$ and $f_2$ (or $\\sum_i f_i$) alternatively by using\ngradient descent, this is the so-called ``cycle incremental gradient\nmethod\".   This kind of incremental methods are obviously closely\nrelated to subspace correction method for both\nstochastic and cycle types.  Such connections need to be further\ninvestigated. \n\nWith some assumption such as differentiability, convexity, Lipschitz\ncontinuity, boundedness for gradient etc, qualitatively convergence\ncan be established for cycle type methods when diminishing stepsize\n(or learning rate) is applied, but it is not known how convergence rate\ncan be established without randomization.\n\nSome relevant discussions can be found in Bertsekas \\cite{bertsekas2015convex, bertsekas2011incremental}\n", "meta": {"hexsha": "0460b56fe65b0b5cadcb73061897b4aec339aaa6", "size": 6431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/PracticalSGD.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/PracticalSGD.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/PracticalSGD.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": 37.6081871345, "max_line_length": 313, "alphanum_fraction": 0.6776551081, "num_tokens": 2352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650248, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.6603607656589221}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\pi n}{n}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\r\n\r\nThe series $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\pi n}{n}$ is an alternating series. Note $b_n = |a_n| = \\frac1n$. Since the sequence $b_n$ is decreasing and $b_n \\to 0$, by the Alternating Series Test, $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\pi n}{n}$ converges.\r\n\r\nTo figure out whether $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\pi n}{n}$ converges absolutely or conditionally, we consider the series\r\n\\[\r\n\\sum_{n=1}^\\infty \\left|\\frac{\\cos \\pi n}{n}\\right|\r\n= \\sum_{n=1}^\\infty \\frac{1}{n}\r\n\\]\r\nwhich diverges by the $p$-test, so the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\pi n}{n}$ converges conditionally.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "f6c8f3a7922cf47ff17f0e9238e732c4715ea1a1", "size": 1475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/k2.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/k2.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/k2.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 35.9756097561, "max_line_length": 276, "alphanum_fraction": 0.6589830508, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.6603607600356421}}
{"text": "\\title{Variational Inference}\n\n\\subsection{Variational Inference}\n\nVariational inference is an umbrella term for algorithms which cast\nposterior inference as optimization\n\\citep{hinton1993keeping,waterhouse1996bayesian,jordan1999introduction}.\n\nThe core idea involves two steps:\n\\begin{enumerate}\n   \\item posit a family of distributions $q(\\mathbf{z}\\;;\\;\\lambda)$\n   over the latent variables;\n   \\item match $q(\\mathbf{z}\\;;\\;\\lambda)$ to the posterior by\n   optimizing over its parameters $\\lambda$.\n \\end{enumerate}\nThis strategy converts the problem of computing the posterior\n$p(\\mathbf{z} \\mid \\mathbf{x})$ into an optimization problem:\nminimize a divergence measure\n\\begin{align*}\n  \\lambda^*\n  &=\n  \\arg\\min_\\lambda \\text{divergence}(\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  ,\n  q(\\mathbf{z}\\;;\\;\\lambda)\n  ).\n\\end{align*}\nThe optimized distribution $q(\\mathbf{z}\\;;\\;\\lambda^*)$ is used as\na proxy to the posterior $p(\\mathbf{z}\\mid \\mathbf{x})$.\n\nEdward takes the perspective that the posterior is (typically)\nintractable, and thus we must build a model of latent variables that\nbest approximates the posterior.\nIt is analogous to the perspective\nthat the true data generating process is unknown, and thus we build\nmodels of data to best approximate the true process.\n\nFor details on variational inference classes defined in Edward,\nsee the \\href{/api/inference}{inference API}.\nFor background on specific variational inference algorithms in\nEdward, see the other inference \\href{/tutorials/}{tutorials}.\n\n\\subsubsection{References}\\label{references}\n\n", "meta": {"hexsha": "508abeb6c0fd9fde9003c51987f0540d529aa003", "size": 1558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/variational-inference.tex", "max_stars_repo_name": "xiangze/edward", "max_stars_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5200, "max_stars_repo_stars_event_min_datetime": "2016-05-03T04:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:32:26.000Z", "max_issues_repo_path": "docs/tex/tutorials/variational-inference.tex", "max_issues_repo_name": "xiangze/edward", "max_issues_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 724, "max_issues_repo_issues_event_min_datetime": "2016-05-04T09:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:41:12.000Z", "max_forks_repo_path": "docs/tex/tutorials/variational-inference.tex", "max_forks_repo_name": "xiangze/edward", "max_forks_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1004, "max_forks_repo_forks_event_min_datetime": "2016-05-03T22:45:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T00:08:08.000Z", "avg_line_length": 34.6222222222, "max_line_length": 72, "alphanum_fraction": 0.7599486521, "num_tokens": 405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.6603607559749327}}
{"text": "\\subsection{part a}\n$$\\vec X_0 = \\begin{bmatrix}\n\t-1\\\\1\n\\end{bmatrix}$$\nTolerance is: $10^{-7}$\n\n\nAnswer is:\n$$\\vec X_{ans} = \\begin{bmatrix}\n\t-1.7556\\\\\n\t0.3655\n\\end{bmatrix}$$\n\\subsubsection{figures}\n\\newpage\n\\begin{itemize}\n\t\\item Steepest Descent\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part a Steepest Descent + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part a Steepest Descent + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\t\\item BFGS\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part a BFGS + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\caption{BFGS and Golden Section}\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part a BFGS + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\\end{itemize}\n\\subsubsection{result}\n\\begin{itemize}\n\t\\item Time\n\\begin{table}[h]\n\t\\caption {Time compare between four methods} \n\t\\begin{center}\n\t\t\\begin{tabular}{ |l|l|l|l| }\n\t\t\t\\hline\n\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\t$0.238\\sec$ & $0.183\\sec$ & $0.164\\sec$ & $0.102\\sec$\\Tstrut\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\t\\item Number of Cost calculation\n\\begin{table}[h]\n\t\\caption {Number of Cost calculation compare between four methods} \n\t\\begin{center}\n\t\t\\begin{tabular}{ |l|l|l|l| }\n\t\t\t\\hline\n\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\t$360$ & $336$ & $242$ & $213$\\Tstrut\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\t\\item Number of Gradient calculation\n\\begin{table}[h]\n\t\\caption {Number of Gradient calculation compare between four methods} \n\t\\begin{center}\n\t\t\\begin{tabular}{ |l|l|l|l| }\n\t\t\t\\hline\n\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\t$19$ & $13$ & $13$ & $9$\\Tstrut\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{itemize}", "meta": {"hexsha": "a78e46186baa864c3ac703acf37d281f4ba7ccce", "size": 2666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW3/Report/Q1/Q1_a.tex", "max_stars_repo_name": "alibaniasad1999/Optimal-Control", "max_stars_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T13:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T13:16:54.000Z", "max_issues_repo_path": "HW/HW3/Report/Q1/Q1_a.tex", "max_issues_repo_name": "alibaniasad1999/Optimal-Control", "max_issues_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW3/Report/Q1/Q1_a.tex", "max_forks_repo_name": "alibaniasad1999/Optimal-Control", "max_forks_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.66, "max_line_length": 101, "alphanum_fraction": 0.6792948237, "num_tokens": 1029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.6603607505387664}}
{"text": "\\section{Radial orbital density plots}\nThe radial orbital density, ${\\psi}^2(r)$, plots are created by integrating over angular portion of the norm of the single particle wave function.\n\n\\begin{equation}\n    {\\psi}^2(r) = \\int_0^{2\\pi}\\int_0^{\\pi} \\psi^2(r,\\theta,\\phi) r^2 \\sin(\\theta) dr d\\theta d\\phi\n\\end{equation}\n\nDiscretizing this expression using a uniform radial grid and a Lebedev-Laikov quadrature for the angular components, yields a form that can be readily evaluated.\n\n\\begin{equation}\\label{eq:plotted}\n    {\\psi}^2(r_i) = 4 \\pi {r_i^2}  \\sum_j^{N^{ang}} w^{ang}_j \\psi^2(r_i,\\theta_j,\\phi_j) \n\\end{equation}\n\nThe function ${\\psi}^2(r_i)$ from Equation~\\ref{eq:plotted} can be plotted with the points $r_i$ serving as the abscissa.\nSince the singly occupied orbitals are normalized, the proximity of the sum of the radial quadrature to unity is used as a check.\n\n\\begin{equation}\\label{eq:norm}\n    \\sum_i^{N^{rad}} {\\psi}^2(r_i) w^{rad}_i = \\sum_i^{N^{rad}} {\\psi}^2(r_i) {\\Delta}r \\approx  1\n\\end{equation}\n\n\\subsection{Required software versions}\n\\begin{table}[H]\n\\begin{tabular}{ll}\nRequired software      & version     \\\\\n\\texttt{numpy}  & 1.18.4      \\\\\n\\texttt{quadpy} & 0.16.2      \\\\\n\\texttt{pyscf}  & 1.7.0       \\\\\n\\texttt{cclib}  & 1.6.3       \\\\\n\\end{tabular}   \n\\end{table}\n\n\n\\subsection{Step 1: Generating a Molden file}\nMolden files were generated using \\texttt{cclib}, with the exception of the natural orbital from the CIPSI calculations. \nSince QuantumPackage is not supported by \\texttt{cclib}, Molden files were created using the native utility in QuantumPackage 2.0. \nFor the Molden files generated with cclib, the \\texttt{-g/--ghost} flag indicates the presence of a ghost atom.\nBy default the only molecular orbitals can be written to a Molden file, therefore the \\texttt{-n/--naturalorbtials} flag was created to allow natural orbitals to be written in place of molecular orbitals.\nThis flag is not yet available in the official distribution, but a request to incorporate it in the official distribution has been opened (\\url{https://github.com/cclib/cclib/pull/948}).\n\n%\\lstinputlisting[label=cclibmoldenbasic,caption=Using \\texttt{cclib} to write a Molden file from an output file. ,language={bash}]{parts/cclibmolden.sh}\n\\inputminted{zsh}{parts/cclibmolden.sh}\n\n\\subsection{Step 2: Integrating over the angular components of the singly occupied orbital}\n\n\\texttt{quadpy} was used to generate the Lebedev-Laikov integration weights and points.\nThe singly occupied molecular/natural orbital was evaluated at these points using \\texttt{PySCF}.\n\n%\\lstinputlisting[label=anionradialint,caption=Using \\texttt{Quadpy} and \\texttt{PySCF} to integrate the singly occupied orbital. ,language={Python}]{parts/anionradialint.py}\n\\inputminted{python}{parts/anionradialint.py}\n\n", "meta": {"hexsha": "bb6d617ef20924b0e190918537c73d4bdba0e40d", "size": 2807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "si_doc/parts/radial_int.tex", "max_stars_repo_name": "shivupa/Water4_JCP_Special_Issue_Supplemental_Material", "max_stars_repo_head_hexsha": "80eea8ec20b63401fa917cf7c7fd251816c26bf5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "si_doc/parts/radial_int.tex", "max_issues_repo_name": "shivupa/Water4_JCP_Special_Issue_Supplemental_Material", "max_issues_repo_head_hexsha": "80eea8ec20b63401fa917cf7c7fd251816c26bf5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "si_doc/parts/radial_int.tex", "max_forks_repo_name": "shivupa/Water4_JCP_Special_Issue_Supplemental_Material", "max_forks_repo_head_hexsha": "80eea8ec20b63401fa917cf7c7fd251816c26bf5", "max_forks_repo_licenses": ["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.0392156863, "max_line_length": 204, "alphanum_fraction": 0.7449234058, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.660191259461507}}
{"text": "\\subsection{Power series}\\label{subsec:power_series}\n\n\\begin{definition}\\label{def:convergent_power_series}\n  Let \\( \\BbbK\\Bracks{X} \\) be the space of formal power series defined in \\fullref{def:formal_power_series}.\n\n  To each formal power series\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty a_k X^k\n  \\end{equation*}\n  there corresponds a function, called a \\term{power series}\n  \\begin{equation}\\label{def:convergent_power_series/series}\n    p(x) \\coloneqq \\sum_{k=0}^\\infty a_k x^k.\n  \\end{equation}\n\n  We sometimes slightly generalize this notion slightly by using a \\enquote{shift} by \\( \\alpha \\in \\BbbK \\): define the function\n  \\begin{equation}\\label{def:convergent_power_series/shifted_series}\n    p(x) \\coloneqq \\sum_{k=0}^\\infty a_k (x - \\alpha)^k.\n  \\end{equation}\n\n  If the limit exists (as a \\hyperref[def:convergent_series]{numeric series}) for a certain \\( x \\in \\BbbK \\), we say that the series \\term{converges} at \\( x \\).\n\n  The series is no longer \\enquote{formal} because it is now a proper function instead of an abstract algebraic object, although a power series may only be defined in a subset of \\( \\BbbK \\) (that is, a \\hyperref[def:partial_function]{partial function}).\n\\end{definition}\n\n\\begin{theorem}\\label{thm:power_series_radius_of_convergence}\n  For every power series \\eqref{def:convergent_power_series/series}, there exists a nonnegative extended real number \\( r \\in [0, +\\infty] \\), called its \\term{radius of convergence}, such that \\eqref{def:convergent_power_series/series} converges absolutely if \\( \\abs{x} < r \\) and diverges if \\( \\abs{x} > r \\).\n\n  The behavior of the series is more complicated when \\( \\abs{x} = r \\) (unless \\( r = 0 \\), in which case the power series converges if and only if \\( x = 0 \\)).\n\\end{theorem}\n\\begin{proof}\n  Define\n  \\begin{equation*}\n    q \\coloneqq \\limsup_{n \\to \\infty} \\sqrt[n]{\\abs{a_n}},\n  \\end{equation*}\n  where we put \\( q = +\\infty \\) if the limit does not exist. We have\n  \\begin{equation*}\n    \\limsup_{n \\to \\infty} \\sqrt[n]{\\abs{x^n a_n}} = \\abs{x} q.\n  \\end{equation*}\n\n  By \\fullref{thm:cauchys_root_test}, \\eqref{def:convergent_power_series/series} converges absolutely if \\( \\abs{z} q < 1 \\) and diverges if \\( \\abs{z} q > 1 \\).\n\n  Thus, \\( r \\coloneqq \\tfrac 1 q \\) is the desired radius of convergence.\n\n  Note that we may also use \\fullref{thm:dalamberts_ratio_test} for finding the same radius of convergence by \\fullref{rem:nonnegative_series_convergence_test_equivalence}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:power_series_parity}\n  Power series of the form\n  \\begin{equation}\\label{thm:power_series_parity/odd}\n    f_o(z) \\coloneqq \\sum_{m \\text{ is odd}} a_m z^m = \\sum_{k=0}^\\infty a_{2k+1} z^{2k+1}\n  \\end{equation}\n  are \\hyperref[def:group/function_parity]{odd functions} and power series of the form\n  \\begin{equation}\\label{thm:power_series_parity/even}\n    f_e(z) \\coloneqq \\sum_{m \\text{ is even}} a_m z^m = \\sum_{k=0}^\\infty a_{2k} z^{2k}\n  \\end{equation}\n  are even functions.\n\\end{proposition}\n\\begin{proof}\n  If \\eqref{thm:power_series_parity/odd} converges for \\( z \\in \\BbbC \\),\n  \\begin{equation*}\n    f_o(-z)\n    =\n    \\sum_{k=0}^\\infty a_{2k+1} (-z)^{2k+1}\n    =\n    \\sum_{k=0}^\\infty a_{2k+1} (-1)^{2k+1} z^{2k+1}\n    =\n    - \\sum_{k=0}^\\infty a_{2k+1} z^{2k+1}\n    =\n    - f_o(z).\n  \\end{equation*}\n\n  Analogously, since \\( (-1)^{2k} = 1 \\), we have \\( f_e(-z) = f_e(z) \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:power_series_are_locally_uniform_convergent}\n  A power series is \\hyperref[def:function_net_convergence/locally_uniform]{locally uniformly convergent} in the interior of its domain of convergence.\n\\end{proposition}\n\\begin{proof}\n  Assume that the series \\eqref{def:convergent_power_series/series} converges inside the ball \\( B(0, R) \\). Fix \\( x \\in B(0, R) \\) and \\( R_x < R - \\abs{x} \\). Then the geometric series\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty a_k R_x^k\n  \\end{equation*}\n  converges and dominates \\eqref{def:convergent_power_series/series} in the ball \\( B(x, R_x) \\). Thus, by \\fullref{thm:weierstrass_series_criterion}, \\eqref{def:convergent_power_series/series} converges uniformly in \\( B(x, R_x) \\).\n\n  Since the choice of \\( x \\in B(0, R) \\) was arbitrary, we conclude that \\eqref{def:convergent_power_series/series} is locally uniformly convergent.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:series_termwise_operations}\n  Suppose that the power series \\eqref{def:convergent_power_series/series} has a (potentially infinite) radius of convergence \\( R \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:series_termwise_operations/differentiation} \\( p(x) \\) is differentiable in \\( B(0, R) \\) and can be differentiated termwise as\n    \\begin{equation}\\label{thm:series_termwise_operations/derivative}\n      p'(x) = \\sum_{k=0}^\\infty a_{k+1} (k+1) x^k.\n    \\end{equation}\n\n    Furthermore, \\( p'(x) \\) has the same radius of convergence as \\( p(x) \\).\n\n    \\thmitem{thm:series_termwise_operations/integration} If the series is real and \\( \\abs{x} < R \\), \\( p(x) \\) is integrable in \\( [0, x] \\) (or \\( [x, 0] \\)) and can be integrated termwise as\n    \\begin{equation}\\label{thm:series_termwise_operations/primitive}\n      \\int_0^x p(t) dt = \\sum_{k=0}^\\infty a_k \\frac {x^{k+1}} {k+1}.\n    \\end{equation}\n  \\end{thmenum}\n\\end{theorem}\n\\begin{proof}\n  \\SubProofOf{thm:series_termwise_operations/differentiation} Note that the right-hand side of \\fullref{thm:series_termwise_operations/derivative} is a power series. Furthermore, its radius of convergence is, by \\fullref{thm:power_series_radius_of_convergence},\n  \\begin{equation*}\n    \\lim_{k \\to \\infty} \\abs{\\frac {a_{k+1} (k+1) x^k} {a_{k+2} (k+2) x^{k+1}}}\n    =\n    \\abs{x} \\lim_{k \\to \\infty} \\frac {k+1} {k+2} \\abs{\\frac {a_{k+1}} {a_{k+2}}}\n    =\n    R.\n  \\end{equation*}\n\n  Fix \\( x \\in B(0, R) \\) and choose \\( r \\in (\\abs{x}, R) \\). Both series are uniformly convergent in \\( B(0, r) \\). By \\fullref{thm:derivative_limit_exchange/sequence}, the equality \\fullref{thm:series_termwise_operations/derivative} holds in \\( B(0, r) \\), hence it also holds for \\( x \\).\n\n  \\SubProofOf{thm:series_termwise_operations/integration} Analogously to \\fullref{thm:series_termwise_operations/differentiation}, we conclude that the right-hand side of \\fullref{thm:series_termwise_operations/primitive} is a power series with radius of convergence \\( R \\).\n\n  The rest follows directly from \\fullref{thm:riemann_intergral_limit_exchange}.\n\\end{proof}\n", "meta": {"hexsha": "e237038f1d67f1ea2ce07edb8bb6e5c5bbff23e7", "size": 6447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/power_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/power_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/power_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": 53.2809917355, "max_line_length": 313, "alphanum_fraction": 0.6983092911, "num_tokens": 2188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6601912545247968}}
{"text": "\\documentclass{article}\n%\\usepackage{authblk}\n\\usepackage{amssymb, amsmath}\n\\usepackage{hyperref}\n\\usepackage{verbatim}\n\n%\\author[1]{Todor Milev}\n\\date{April 2018}\n%\\affil[1]{FA Enterprise System}\n\\title{Elliptic curve secp256k1 \\\\ Implementation notes}\n\\author{Todor Milev\\footnote{FA Enterprise System}\\\\ todor@fa.biz}\n\\newcommand{\\secpTwoFiveSixKone}{{\\bf secp256k1}}\n\\renewcommand{\\mod}{{~\\bf mod~}}\n\\begin{document}\n\\maketitle\n\\section{Introdution}\nPublic/private key cryptography is arguably the most important aspect of modern crypto-currency systems. The somewhat slow execution of private/public key cryptography algorithms appears to be one of the main bottlenecks of FAB's Kanban system. \n\n\nFollowing Bitcoin, FAB coin uses the standard public/private key cryptography ECDSA over \\secpTwoFiveSixKone. Here, ECDSA stands for Elliptic Curve Digital Signature Algorithm and \\secpTwoFiveSixKone{} stands for the elliptic curve:\n\n\\[\ny^2 = x^3 + 7\n\\]\n(we specify the base point later), over the finite field:\n\n\\[\n\\mathbb Z / p\\mathbb Z, \n\\]\nwhere\n\\begin{equation}\\label{eqThePrime}\np= 2^{256} - 2^{32} - 977.\n\\end{equation}\n\nIn this document, we discuss and document technical details of FAB's implementation of ECDSA over  \\secpTwoFiveSixKone{}. Our openCL implementation is based on the project \\cite{secp256k1:openCLimplementationHanh0}, which is in turn based on the C project libsecp256k1 \\cite{Wuille:secp256k1}.\n\n\\section{Operations in $\\mathbb Z / p\\mathbb Z$}\nRecall from (\\ref{eqThePrime}) that $p$ is the prime given by\n\\[\np= 2^{256} - 2^{32} - 977.\n\\]\nIn this section, we describe our implementation of $Z / p\\mathbb Z$.\n\\subsection{Representations of numbers}\nA number in $x$ in $\\mathbb Z / p\\mathbb Z$ is represented by a large integer $X$, in turn represented by a sequence of $10$ small integers $x_0,\\dots, x_9$ for which $0 \\leq x_i < 2^{32}$ and such that\n\\[\nX = \\sum_{i=0}^{9} x_i \\left(2^{26}\\right)^i.\n\\]\nThe representations of $x$ is not unique but becomes so when we request that \n\\[\n0\\leq x_i < 2^{26}\n\\]\nand \n\\[\n0 \\leq X < p = 2^{256} - 2^{32} - 977.\n\\]\nWe say that the unique representation $x_0, \\dots, x_9$ of $x$ above is its \\emph{normal form} (and $x$ is \\emph{normalized}). Two elements of $ \\mathbb Z / p \\mathbb Z$ are equal if and only if their normal forms are equal. We will not assume that a number $x$ is represented by its normal form as some of the operations described below do not require that.\n\nIn what follows, we shall use the notation\n\\[\na'=a \\mod q\n\\]\nto denote remainder $0\\leq a' <q$  of $a$ when dividing $a$ by $q$. For the rest of this section, we also set \n\\[\nd= 2^{26}.\n\\]\nIn this way the normal form of a large number $X$ is its $d$-base representation (here $d$ is the ``digit'' of the base).\n\n\\subsection{Computing the normal form of $x$}\\label{secNormalFormOfFieldElement}\n\n\\subsection{Multiplying two elements}\nLet $a$ be an element represented by $A = \\sum a_i d^i$ with $a_0, \\dots, a_8<2^{30}$ and $a_9<2^{22}$. Likewise, let $b$ be represented by $B=\\sum b_j d^j$ with analogous inequalities on the coefficients $b_j$. In this section, we show how to compute the normal form of $a\\cdot b$. This operation is implemented in the function \\verb|ECMultiplyFieldElementsInner|. \n\nCompute as follows.\n\\[\n\\begin{array}{rcl}\n\\displaystyle A\\cdot B &=&\\displaystyle \\left(\\sum_{i=0}^9 a_i d^i \\right) \\left(\\sum_{j=0}^9 b_j d^j\\right) \\\\\n&=&\\displaystyle  \\sum_{k=0}^{18} \\left(\\underbrace{ \\sum_{i=0}^k a_i b_{k-i} }_{=\\bar t_k} \\right) d^k \\\\\n&=&\\displaystyle \\sum_{k=0}^{18} \\bar t^k d^k,\n\\end{array}\n\\]\nwhere we have set $\\displaystyle \\bar t_k = \\left(\\sum_{i=0}^k a_i b_{k-i} \\right)$. Since $0\\leq a_i,b_i < d$, the $\\bar t_k$'s are smaller than $2^{64}$ and can be computed by standard arithmetic using the \\verb|uint64_t| integer type of the GPU. \n\nLet\n\\[\nA\\cdot B = \\sum_{k=0}^{19} t_k d^k\n\\] \nwith $0\\leq t_k < d$ be the unique representation of $A\\cdot B$ base $d$. Then the $t_k$ can be computed from the $\\bar t_k$'s consecutively via \n\\[\n\\begin{array}{rcl}\n\\displaystyle t_0 &= &\\displaystyle \\bar t_0 \\mod d\\\\\n\\displaystyle c_0 &= &\\displaystyle \\left\\lfloor \\frac{\\bar t_0}{d} \\right\\rfloor\\\\ \\\\\\hline \\\\\n\\displaystyle t_1 &= &\\displaystyle c_0 + \\bar t_0 \\mod d\\\\\n\\displaystyle c_1 &= &\\displaystyle \\left\\lfloor \\frac{c_0 + \\bar t_0}{d} \\right\\rfloor \\\\\n\\displaystyle t_2 &= &\\displaystyle c_1 + \\bar t_1 \\mod d\\\\\n\\displaystyle c_2 &= &\\displaystyle \\left\\lfloor \\frac{c_1 + \\bar t_1}{d} \\right\\rfloor \\\\\n&\\vdots&\\\\\n\\displaystyle t_{18} &= &\\displaystyle c_{17} + \\bar t_{17} \\mod d\\\\\n\\displaystyle c_{18} &= &\\displaystyle \\left\\lfloor \\frac{c_{17} + \\bar t_{17}}{d} \\right\\rfloor \\\\ \\\\ \\hline\n\\displaystyle t_{19} &= &\\displaystyle  c_{18}.\n\\end{array}\n\\]\nIn the above, all computations except the first and the last are similar, as indicated by the horizontal line, and $\\lfloor\\bullet \\rfloor$ stands as usual for the floor function. Both $\\mod d$ and division by $d$ are carried out by bit-shift operations and are therefore fast.\n\nLet $S = (A\\cdot B \\mod p)$; computing the normal form $S = \\sum s_i d^i$, $0\\leq s_i < d$, $S < p$ is the final aim of the present discussion. Since $2^{256} \\mod p = 2^{32}+977$, it follows that \n\\begin{equation} \\label{eqReducet0plust10dPower10}\n\\begin{array}{rcll}\nt_0+ t_{10} d^{10} \\mod p \n&=&\\displaystyle t_0+t_{10} 2^{26\\cdot 10} &\\mod p\\\\\n&=&\\displaystyle t_0 + t_{10} \\cdot 2^4\\cdot 2^{256}  &\\mod p\\\\\n&=&\\displaystyle t_0 + t_{10} 2^4 \\left(2^{32} + 977 \\right)&\\mod p\\\\\n&=&\\displaystyle \\left(t_0 +t_{10}2^4\\cdot 977\\right) + t_{10} 2^{10}\\cdot d&\\mod p \\\\\n\\displaystyle \\text{set }g_{0} = t_0 +t_{10}2^4\\cdot 977 \\mod d \\\\\n\\displaystyle \\text{set }f_{0} =\\left\\lfloor \\frac{t_0 +t_{10}2^4\\cdot 977}{d}\\right\\rfloor \\\\\n&=& g_0 + \\left(\\underbrace{ f_0+t_{10} 2^{10}}_{=h_0}\\right) d &\\mod p.\n\\end{array}\n\\end{equation}\nSet $\\displaystyle h_0 = f_0+t_{10} 2^{10}$ as indicated above. The computation above shows how ``reduce'' the $d$-digit $t_{10}$ by modifying the two least significant $d$-digits. Accounting for the ``carry-over'' digit $h_0$, we can continue with this process for the next pair of digits $ t_1 d+t_{11} d^{11}$, and so on. This is done below (similar steps have been omitted).\n\\[\n\\begin{array}{rcll}\nh_0 d +t_1 d+ t_{11} d^{11} \\mod p \n&=&\\displaystyle \\left(h_0+t_1+t_{11} d^{10}\\right) d &\\mod p\\\\\n&=& \\dots \\text{compute as in (\\ref{eqReducet0plust10dPower10})} \\dots\\\\\n\\displaystyle \\text{set }g_{1} = h_0+t_1 +t_{11}2^4\\cdot 977 \\mod d \\\\\n\\displaystyle \\text{set }f_{1} =\\left\\lfloor \\frac{h_0+t_1 +t_{11}2^4\\cdot 977}{d}\\right\\rfloor \\\\\n&=& g_1d + \\left(\\underbrace{ f_1+t_{11} 2^{10}}_{=h_1}\\right) d^2 &\\mod p\\\\\n&\\vdots&\\\\\nh_8 d^9 + t_{9} d^9 + t_{19} d^{19}\\mod p &=& \\dots\\\\\n\\displaystyle \\text{set }g_{9} = h_8+t_9 +t_{19}2^4\\cdot 977 \\mod d \\\\\n\\displaystyle \\text{set }f_{9} =\\left\\lfloor \\frac{h_8+t_9 +t_{19}2^4\\cdot 977}{d}\\right\\rfloor \\\\\n&=&g_9 d^9 + \\left( \\underbrace{f_9+t_{19} 2^{10}}_{=h_9}\\right)d^{10} &\\mod p.\n\\end{array}\n\\]\nIn the computations above, $t_{19}$ is maximum $26$ bits long and so\n\\begin{equation}\\label{eqh9inequality}\nh_9 < f_9 + 2^{26}2^{10} < 2^{37}.\n\\end{equation}\nIn order to obtain the normal form of $S$, we need to modify the digits $g_9$ and $h_9$ as follows.\n\\[\n\\begin{array}{rcll}\n\\displaystyle g_9 d^9 + h_9 d^{10} \\mod p &=&\\displaystyle  (g_9+h_9 d )d^9 &\\mod p \\\\\n\\displaystyle \\text{set }r =g_9 + h_9 d \\mod 2^{22}\\\\\n\\displaystyle \\text{set }m = \\left\\lfloor \\frac{g_9 + h_9 d }{2^{22}} \\right\\rfloor\\\\\n&=& \\left( r + m \\cdot 2^{22} \\right) d^9  &\\mod p\\\\\n&=& r d^9 + m 2^{256} &\\mod p\\\\\n&=& r d^9 + m\\left(2^{32}+977\\right) &\\mod p.\\\\\n\\end{array}\n\\]\nFrom inequality (\\ref{eqh9inequality}), we get that $h_9 d < 2^{37} 2^{26} = 2^{63}$, and so the computations above fit in \\verb|uint64_t| type. Again using (\\ref{eqh9inequality}) we get the following estimates for the sizes of digits.\n\\[\n\\begin{array}{rcl}\n\n\\displaystyle g_9+ h_9 d &<& \\displaystyle 2^{64}\\\\\n\\displaystyle m=\\left\\lfloor \\frac{g_9 + h_9 d }{2^{22}} \\right\\rfloor&<& \\displaystyle \\frac{2^{64}}{2^{22}} = 2^{42}\\\\\nm\\left(2^{32}+977\\right) &<& 2^{33}\\cdot 2^{42} = 2^{75} < d^3.\n\\end{array}\n\\]\nThus the number $m\\left(2^{32}+977\\right)$ can be written in the form $z_0 + z_1 d + z_2 d^2 $ with $0\\leq z_0, z_1, z_2 < d$. Collecting the information so far, we get \n\\begin{equation}\\label{eqAtimesBalmostNormalForm}\nA\\cdot B \\mod p = (z_0 + g_0) + (z_1 + g_1)d + (z_2+g_2)d^2 + \\sum _{k=3}^{8} g_k d^k + r d^9,\n\\end{equation}\nwhere $z_0+g_0 < 2d$, $z_1+g_1 <2d$, $z_2+g_2<2d$, $g_k< d$, $r < 2^{22}$. Except in the cases when $z_i+g_i\\geq d$, this expression is normalized. To ensure our result is normalized, we need to reduce the representation above according to Section \\ref{secNormalFormOfFieldElement}. This does not need to be done immediately as the form \\eqref{eqAtimesBalmostNormalForm} satisfies all assumptions of the present discussion. \n\n\n\n\n\n\\bibliographystyle{plain}\n\\bibliography{../bibliography.bib}\n\\end{document}", "meta": {"hexsha": "a6de7be8e3077c8780caf93bf277a630967ed92a", "size": 9004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/ECDSA/notes_on_elliptic_curve_implementation.tex", "max_stars_repo_name": "blockchaingate/Kanban", "max_stars_repo_head_hexsha": "b48c5db37107a09749ef3c4014fca939ac98f073", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-06-27T01:06:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-29T14:21:28.000Z", "max_issues_repo_path": "doc/ECDSA/notes_on_elliptic_curve_implementation.tex", "max_issues_repo_name": "blockchaingate/Kanban", "max_issues_repo_head_hexsha": "b48c5db37107a09749ef3c4014fca939ac98f073", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2018-12-03T16:18:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T11:49:18.000Z", "max_forks_repo_path": "doc/ECDSA/notes_on_elliptic_curve_implementation.tex", "max_forks_repo_name": "FAB-Coin/Kanban-js", "max_forks_repo_head_hexsha": "75b0bd96b98d13b2ee7b7467dcf4b79f2e21c29c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-22T18:09:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T06:33:39.000Z", "avg_line_length": 53.2781065089, "max_line_length": 424, "alphanum_fraction": 0.6836961351, "num_tokens": 3371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382023207901, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6601912523123538}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\begin{document}\nJon Allen\n\nSeptember 11, 2013\n\nSection 2.2 Problems 25,28,43,51 Section 2.3 Problems 13,19\n\\section*{2.2}\n\\subsection*{25}\nSolve \\(x \\sin \\left( x^2 \\right) \\mathrm{d}x=\\frac{\\cos \\sqrt{y}}{\\sqrt{y}}\\mathrm{d}y\\)\n\n\\(u=x^2, \\mathrm{d}u=2x\\,\\mathrm{d}x, v=y^{1/2}, \\mathrm{d}v=\\frac{1}{2}y^{-1/2}\\,\\mathrm{d}y\\)\n\n\\begin{align*}\n\\frac{1}{2}\\int{\\sin u\\,\\mathrm{d}u}&=2\\int{\\cos v\\,\\mathrm{d}v}\\\\\n-\\frac{1}{2}\\cos{x^2}&=2\\sin{\\sqrt{y}}+C\n\\end{align*}\n\\subsection*{28}\nSolve \\(\\frac{\\mathrm{d}\\phi}{\\mathrm{d}\\theta}=\\frac{\\left(5-2\\cos\\theta\\right)^3 \\sin\\theta\\cos^4\\phi}{\\sin\\phi}\\)\n\n\\( \\frac{\\sin\\phi}{\\cos^4\\phi}\\,\\mathrm{d}\\phi=\\left(5-2\\cos\\theta\\right)^3\\sin\\theta\\,\\mathrm{d}\\theta,\\quad u=\\cos\\phi,\\quad \\mathrm{d}u=-\\sin\\phi\\,\\mathrm{d}\\phi,\\quad v=5-2\\cos\\theta,\\quad \\mathrm{d}v=2\\sin\\theta\\,\\mathrm{d}\\theta \\)\n\\begin{align*}\n-\\int{u^{-4}\\,\\mathrm{d}u}&=\\frac{1}{2}\\int{v^3\\,\\mathrm{d}v}\\\\\n\\frac{1}{3}u^{-3}&=\\frac{1}{8}v^4+C\\\\\n\\frac{1}{3}\\cos^3\\phi&=\\frac{1}{8}\\left(5-2\\cos\\theta\\right)^4+C\n\\end{align*}\n\\subsection*{43}\nSolve the IVP\n\\(\\mathrm{d}x=\\cos{y}\\mathrm{d}y, x(0)=2\\)\n\\begin{align*}\n\\int{\\mathrm{d}x}&=\\int{\\cos{y}\\mathrm{d}y}\\\\\nx&=\\sin{y} + C\\\\\n2&=\\sin{0}+C\\\\\nx&=\\sin{y}+2\n\\end{align*}\n\\subsection*{51}\nSolve the IVP\n\\(\\frac{\\mathrm{d}y}{\\mathrm{d}x}=\\frac{1}{1+x^2},\\; y(0)=1\\)\n\\begin{align*}\n\\int{\\mathrm{d}y}&=\\int{\\frac{1}{1+x^2}\\,\\mathrm{d}x}\\\\\ny&=\\arctan{x}+C\\\\\n1&=\\arctan{0}+C=1\\\\\ny&=\\arctan{x}+1\n\\end{align*}\n\\section*{2.3}\n\\subsection*{13}\nSolve \\(\\frac{\\mathrm{d}y}{\\mathrm{d}t}+y\\cot{t}=\\cos{t}\\)\n\\begin{align*}\n\\mu (t)&=e^{\\int{\\cot{t}\\,\\mathrm{d}t}}\\\\\n\\cot t&=\\frac{\\cos t}{\\sin t},\\;u=\\sin t,\\;\\mathrm{d}u=\\cos t\\,\\mathrm{d}t\\\\\n\\mu(t)&=e^{\\int{\\frac{1}{u}\\,\\mathrm{d}u}}\\\\\n&=e^{\\ln\\left\\lvert\\sin t\\right\\rvert}=\\sin t\\\\\n\\int{\\frac{\\mathrm{d}}{\\mathrm{d}t}\\left(y\\sin t\\right)\\,\\mathrm{d}t}&=\\int{\\sin{t}\\cos{t}\\,\\mathrm{d}t},\\;u=\\sin t,\\;\\mathrm{d}u=\\cos t\\,\\mathrm{d}t\\\\\ny\\sin t&=\\frac{\\sin^2 t}{2}+C\\\\\ny&=\\frac{1}{2}\\sin t+C\\csc t\n\\end{align*}\nNote that \\(-\\frac{1}{2}\\cos t \\cot t+C_0\\csc t=-\\frac{1}{2}\\frac{\\cos^2 t}{\\sin t}+C_0\\csc t=-\\frac{1}{2}\\frac{1-\\sin^2 t}{\\sin t}+C_0\\csc t=-\\frac{1}{2}\\left(\\frac{1}{\\sin t}-\\sin t\\right)+C_0\\csc t=\\frac{1}{2}\\sin t-\\frac{1}{2}\\csc t+C_0\\csc t=\\frac{1}{2}\\sin t+(C_0-\\frac{1}{2})\\csc t=\\frac{1}{2}\\sin t+C_1\\csc t\\) and so my answer is equivalent to the book's answer.\n\\subsection*{19}\nSolve \\(\\frac{\\mathrm{d}\\theta}{\\mathrm{d}r}-r\\theta=r\\)\n\\begin{align*}\n\\mu(r)&=e^{\\int{-r\\,\\mathrm{d}r}}=e^{-\\frac{r^2}{2}}\\\\\n\\int{\\frac{\\mathrm{d}}{\\mathrm{d}t}\\left(\\theta e^{-\\frac{r^2}{2}}\\right)\\,\\mathrm{d}t}&=\\int{r e^{-\\frac{r^2}{2}}\\,\\mathrm{d}r}\\\\\n\\theta e^{-\\frac{r^2}{2}}&=-e^{-\\frac{r^2}{2}}+C\\\\\n\\theta&=-1+Ce^{\\frac{r^2}{2}}\n\\end{align*}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "fca90148ec55ad709fb05b5fbd2e10391042b69a", "size": 2848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential equations/diffeq-hw-2013-09-10.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-10.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-10.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.0136986301, "max_line_length": 371, "alphanum_fraction": 0.590238764, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6601912490762609}}
{"text": "\\section{09/09}\nWe can apply the algorithm given previously to actually \\emph{find} an\nassignment of the boolean variables which will satisfy at least $\\sfrac{7m}{8}$\nclauses. Specifically, consider the following algorithm\n\\begin{algorithm}\n    \\caption{Randomized Max 3-SAT Algorithm}\n    \\begin{algorithmic}[1]\n        \\Function{Solve}{\\texttt{formula}}\n            \\State $\\texttt{result} \\gets 0$\n            \\While{$\\texttt{result} < \\sfrac{7m}{8}$}\n                \\State $\\texttt{bool-vec}, \\texttt{result} \\gets \\Call{Try-Solve}{\\texttt{formula}}$\n            \\EndWhile\n            \\State \\Return \\texttt{bool-vec}\n        \\EndFunction\n        \\Function{Try-Solve}{\\texttt{formula}}\n            \\State $\\texttt{bool-vec} \\gets \\Call{Sample}{\\set{0,1}^n}$\n            \\State $k \\gets$ number of satisfied clauses in \\texttt{formula}\n            \\State \\Return $(\\texttt{bool-vec}, k)$\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\nClearly, the above algorithm will \\emph{eventually} return the desired boolean\nvector. However, we are concerned with how many iterations this algorithm will\nrequire. To determine this, we must first determine the probability that the\nrandomly selected boolean vector will satisfy at least $\\sfrac{7m}{8}$ clauses.\n\nLet $X$ represent the number of satisfied clauses. Recall that $\\expectation{X}\n= \\sfrac{7m}{8}$. Let us call this value $\\mu$. Then\n\\begin{align*}\\mu\n    &= \\expectation{X}\\\\\n    &= \\sum_{x=0}^m x\\prob{X = x}\\\\\n    &= \\sum_{x < \\mu} x\\prob{X = x} + \\sum_{x \\geq \\mu} x\\prob{X = x}\\\\\n    \\shortintertext{Notice that, since $x < \\mu$, $x \\leq \\mu - c$ for some constant $0 < c \\leq 1$}\n    &\\leq \\left(\\mu - c\\right)\\sum_{x < \\mu}\\prob{X = x} + m\\sum_{x \\geq \\mu} \\prob{X = x}\\\\\n    \\shortintertext{setting $p = \\prob{X \\geq \\mu}$}\\\\\n    &= (\\mu - c)(1 - p) + mp\n    \\shortintertext{Solving for $p$}\\\\\n    p &\\geq \\frac{c}{c - \\mu + m}\\\\\n      &= \\bigTh{\\frac{1}{m}}\n\\end{align*}\n\nBefore we finish this analysis, we should consider the Geometric Random\nVariable.\n\n\\subsection{Geometric Random Variable}\n\\begin{definition}{Geometric Random Variable}{geometricrv}\n    Consider some Bernoulli trial, i.e., an event with exactly two possible\n    outcomes, denotes ``success'' and ``failure'', and suppose success occurs\n    with probability $p$. The \\emph{Geometric Distribution}, denoted $X \\sim\n    G(p)$, is the number of trials necessary until a success occurs. \n\\end{definition}\n\n\\begin{lemma}{}{}\n    Let $X$ be some discrete random variable that takes integer values. Then\n    \\[\\expectation{X} = \\sum_{x = 1} \\prob{X \\geq x}\\]\n\\end{lemma}\n\n\\begin{proof}\n    \\begin{align*}\\expectation{X}\n        &= \\sum_{x=1}^{\\infty}x \\prob{X=x}\\\\\n        &= \\sum_{x=1}^{\\infty}\\sum_{i=1}^x \\prob{X=x}\\\\\n        &= \\sum_{x=1}^{\\infty}\\sum_{i=x}^{\\infty}\\prob{X=i}\\\\\n        &= \\sum_{x=1}^{\\infty}\\prob{X \\geq x}\n    \\end{align*}\n\\end{proof}\n\n\\begin{theorem}{Expectation of Geometric Random Variable}{}\n    Let $X \\sim G(p)$. Then $\\expectation{X} = \\frac{1}{p}$.\n\\end{theorem}\n\n\\begin{proof}\n    Observe that $\\prob{X = k} = (1 - p)^{k - 1}p$, hence\n    \\[\\prob{X \\geq k} = (1 - p)^{k - 1}\\]\n    and\n    \\begin{align*}\\expectation{X}\n        &= \\sum_{k=1}^{\\infty} k\\prob{X = k}\\\\\n        &= \\sum_{k=1}^{\\infty} \\prob{X \\geq k}\\\\\n        &= \\sum_{k=1}^{\\infty} (1 - p)^{i - 1}\\\\\n        &= \\frac{1}{1 - (1 - p)}\\\\\n        &= \\frac{1}{p}\n    \\end{align*}\n\\end{proof}\n\nNow, returning to our Max 3-SAT algorithm, notice that the probability that it\nrequires $k$ iterations to output an assignment of at least $\\sfrac{7m}{8}$\n\\True clauses is\n\\begin{align*}(1 - p)^k\n    &\\leq \\left(1 - \\frac{c}{m}\\right)^k\\hbox{ for some $c > 0$}\\\\\n    &\\leq e^{\\frac{-ck}{m}}\\\\\n    \\shortintertext{setting $k = \\sfrac{m}{c}\\ln{n}$}\n    &= \\frac{1}{m}\n\\end{align*}\nObserve that our algorithm is a Las Vegas algorithm. However, there is an\nanalogous Monte Carlo algorithm:\n\\begin{algorithm}\n    \\caption{Randomized Max 3-SAT Algorithm (MC Variant)}\n    \\begin{algorithmic}[1]\n        \\Function{Solve}{\\texttt{formula}}\n            \\State $\\texttt{result} \\gets 0$\n            \\State $\\texttt{bool-vec} \\gets \\vec{0}$\n            \\ForRange{$i$}{1}{$\\sfrac{m}{c}\\ln{n}$}\n                \\State $\\texttt{new-bool-vec}, \\texttt{new-result} \\gets \\Call{Try-Solve}{\\texttt{formula}}$\n                \\If{$\\texttt{new-result} > \\texttt{result}$}\n                    \\State $\\texttt{result} \\gets \\texttt{new-result}$\n                    \\State $\\texttt{bool-vec} \\gets \\texttt{new-bool-vec}$\n                \\EndIf\n            \\EndForRange\n            \\State \\Return \\texttt{bool-vec}\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Binomial Random Variable}\n\\begin{definition}{Geometric Random Variable}{}\n    Consider some Bernoulli trial, i.e., an event with exactly two possible\n    outcomes, denotes ``success'' and ``failure'', and suppose success occurs\n    with probability $p$. The \\emph{Binomial Distribution}, denoted $X \\sim\n    B(n, p)$, is the number of successes after $n$ trials.\n\\end{definition}\n\n\\begin{theorem}{}{}\n    Let $X \\sim B(n, p)$. Then $\\expectation{X} = np$.\n\\end{theorem}\n\n\\begin{proof}\n    Again, \\nameref{thm:linexp} is useful here. Let $X_i$ be the indicator\n    random variable that is 1 when trial $i$ is a success. Then\n    \\[\\expectation{X_i} = \\prob{X_i = 1} = p\\]\n    hence\n    \\[\\expectation{X} = \\sum_{i=1}^n \\expectation{X_i} = np\\qedhere\\]\n\\end{proof}\n\n\\subsection{Randomized Quicksort}\nThe \\emph{Quicksort} algorithm is a computer science staple, one of the most\nfamous algorithms of the 20th century. A simplified version of the original\nimplementation is below:\n\n\\begin{algorithm}\n    \\caption{Simplified variant of Quicksort algorithm.}\n    \\label{alg:quicksort}\n    \\begin{algorithmic}[1]\n        \\Function{Quicksort}{\\texttt{arr}}\n            \\State $n \\gets \\Call{Len}{\\texttt{arr}}$\n            \\If{$n \\leq 1}$\n                \\State \\Return \\texttt{arr}\n            \\Else\n                \\State $\\texttt{left}, P, \\texttt{right} \\gets \\Call{Partition}{\\texttt{arr}}$\n                \\State \\Return $\\Call{Quicksort}{\\texttt{left}} + P + \\Call{Quicksort}{\\texttt{right}}$\n            \\EndIf\n        \\EndFunction\n        \\Function{Partition}{\\texttt{arr}}\n            \\State $\\texttt{pivot} \\gets \\texttt{arr}[0]$\n            \\State $\\texttt{left}, P, \\texttt{right} \\gets [], [], []$\n            \\For{$a \\in \\texttt{arr}}$\n                \\If{$a < \\texttt{pivot}}$\n                    \\State $\\texttt{left}.\\Call{Append}{a}$\n                \\ElsIf{$a = \\texttt{pivot}$}\n                    \\State $P.\\Call{Append}{a}$\n                \\Else\n                    \\State $\\texttt{right}.\\Call{Append}{a}$\n                \\EndIf\n            \\EndFor\n            \\State \\Return $\\texttt{left}, P, \\texttt{right}$\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\n\nNotice that the worst case of this algorithm is $\\bigO{n^2}$.\n%TODO demonstrate worst case quicksort\nOn the other hand, the best case is $\\bigO{n\\log{n}}$.\n%TODO demonstrate best case quicksort\nWe can consider a randomized variant --- functionally, the same algorithm, but\nwith the partition scheme changed. Rather than selecting the element with index\n0 as the pivot, select a \\emph{random} element as the pivot. Let us consider the\nnumber of comparisons in this variant.\n\n\\begin{theorem}{}{}\n    The above randomized variant of Quicksort has an expected runtime of\n    $\\bigO{n\\log{n}}$.\n\\end{theorem}\n\n\\begin{proof}\n    Let $X$ denote the number of comparisons. It should be clear that\n    $\\prob{X=x}$ is impractical to compute directly. Instead, notice that two\n    elements of the array will be compared \\emph{at most} once --- when one of\n    the two elements is the pivot \\emph{end}. \n\n    Assume the sorted order of the elements is $a_0$, $a_1$, \\dots, $a_n$, and\n    let $X_{i,j}$ denote the indicator random variable that is 1 when $a_i$ and\n    $a_j$ are compared. Notice that if any of $a_{i+1}$, $a_{i + 2}$, \\dots,\n    $a_{j - 1}$ are chosen, then $a_i$ and $a_j$ will end up in separate\n    partitions and never be compared. Additionally, if any values $a_0$, $a_1$,\n    \\dots, $a_{i - 1}$ or $a_{j + 1}$, $a_{j + 2}$, \\dots, $a_{n-1}$ are chosen,\n    this will have no effect on whether $a_i$ and $a_j$ are compared.\n    \n    Thus, the probability that $a_i$ and $a_j$ are compared is simply the\n    probability that either value is chosen as the pivot from $a_i$, $a_{i +\n    1}$, \\dots, $a_j$, which is\n    \\[\\frac{2}{j - i + 1}\\]\n    Thus, we have\n    \\begin{align*}\\expectation{X}\n        &=\\sum_{i=0}^{n-1}\\sum_{j=i+1}^{n-1}\\expectation{X_{i,j}}\\\\\n        &=\\sum_{i=0}^{n-1}\\sum_{j=i+1}^{n-1}\\frac{2}{j - i + 1}\\\\\n        \\shortintertext{writing $k = j - i$}\\\\\n        &=\\sum_{i=0}^{n-1}\\sum_{k=1}^{n - i - 1}\\frac{2}{k + 1}\\\\\n        &\\leq\\sum_{i=0}^{n-1}2H_n\\\\\n        &\\leq 2nH_n\\\\\n        &=\\bigO{n\\log{n}}\\qedhere\n    \\end{align*}\n\\end{proof}", "meta": {"hexsha": "fb3bb7a249b9d5e3461c935933d789ab5f748366", "size": 8939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0909.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/0909.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/0909.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": 42.5666666667, "max_line_length": 108, "alphanum_fraction": 0.6063318045, "num_tokens": 2944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519376, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6601400795836978}}
{"text": "\\chapter{Intensity models}\n\\label{chap:intensity}\n\n\\added{A rigorous treatment of intesity modeling can be found in} \\textcite{bieleckirutkowski2002credit} and \\textcite{brigo2007interest} contains a gentler introduction.\n\n\\section{Foundations of intensity models}\n\n\\subsection{Introduction}\n\n\\added{This section is based on } \\textcite[pp. 759--764]{brigo2007interest}.\n\nLet $(\\Omega, \\F, \\Pm)$ be a fixed probability space and $\\default$ a random time, meaning that $\\default : \\Omega \\rightarrow \\R_+ \\cup \\{ 0 \\}$ is a measurable random variable. In our setting $\\default( \\omega )$ will be the time of the default. The corresponding indicator variable is $H_t = \\1_{ \\{\\default \\leq t \\} }$. Hence, $H_t=0$ before the default and $H_t = 1$ at the default and after it.\n\nIf we assume that $\\default$ is exponentially distributed with parameter $\\gamma > 0$, then\n  \\begin{align}\n    \\label{exponential-cumulative-inverse}\n    \\Pm( \\default > t ) = \\e^{- \\gamma t } .\n  \\end{align} \nWe note that the random variable $\\default \\gamma$ is exponentially distributed with parameter $1$, since\n  \\begin{align}\n    \\label{exponentiallywithparameter1}\n    \\Pm( \\default \\gamma > t ) = \\Pm( \\default > \\frac{t}{\\gamma} ) = \\e^{-t} .\n  \\end{align}\nNow \n  \\begin{align}\n    \\Pm( \\default > t + \\dx t \\ | \\ \\default > t ) & = \\frac{ \\Pm( \\default > t + \\dx t ) }{ \\Pm( \\default > t ) } \\\\ &= \\e^{ - \\gamma ( t + \\dx t ) } \\e^{ \\gamma t } \\\\\n    & =  \\e^{ - \\gamma \\dx t } \\\\\n    &= \\Pm( \\default > \\dx t ) ,\n  \\end{align}\nwhich implies that the distribution has no memory. While memorylessness is often a desirable property, time homogeneous is not a desirable property in credit risk modeling. \n\nHowever, we can easily see the theoretical connection between interest rate and default intensity using a simplified model, where the risk-free rate $r$ and the parameter $\\gamma$ are positive constants. Now the zero-coupon bond with maturity $T$ and no recovery value at the default has the expected discounted value of\n  \\begin{align}\n    \\Pm( \\default > t ) \\e^{-r T} + \\Pm( \\default \\leq t ) \\cdot 0 = \\e^{ - (r+\\gamma) T} .\n  \\end{align}\nThus the parameter $\\gamma > 0$ can be seen as a credit spread over the risk-free rate.\n\nWe can generalize the equation \\ref{exponential-cumulative-inverse} and introduce time-dependency by setting\n  \\begin{align}\n    \\Pm( \\default > t ) = \\e^{- \\Gamma(t) } ,\n  \\end{align}\nwhere $\\Gamma(t)$ is the cumulative hazard function. Intuitively we assume that $\\Gamma$ is a strictly increasing function. Now if $r(t)$ is a deterministic short-rate, then \na defaultable zero-coupon bond with maturity $T$ and no recovery value has expected discounted value of\n  \\begin{align}\n    \\label{price_with_cumulative_hazard_function}\n    \\e^{ - \\left( \\int_0^T r(s) \\dx s + \\Gamma(T) \\right) }.\n  \\end{align}\n  \nAs in equation \\ref{exponentiallywithparameter1}, if $\\xi = \\Gamma(\\default)$, then\n  \\begin{align}\n    \\Pm( \\Gamma(\\default) > t ) = \\Pm( \\default > \\Gamma^{-1}(t) ) = \\e^{-t}\n  \\end{align}\nmeaning that $\\xi$ is exponentially distributed with parameter $1$ and $\\default \\sim \\Gamma^{-1}(\\xi)$. Now we may simulate the default time by drawing a realization of $\\xi$ and taking $\\default = \\Gamma^{-1}(\\xi)$.\n\nNext we assume that\n  \\begin{align}\n    \\label{Gammaisgammaintegral}\n    \\Gamma(t) = \\int_0^t \\gamma (s) \\dx s,\n  \\end{align}\nwhere $\\gamma > 0$ almost everywhere. Now the equation \\ref{price_with_cumulative_hazard_function} can be written as\n  \\begin{align}\n    \\e^{ - \\int_0^T \\left( r(s) + \\gamma(s) \\right) \\dx s }\n  \\end{align}\nand again $\\gamma(t)$ can be viewed as a credit spread over the risk-free rate. Now\n  \\begin{align}\n    \\Pm( t \\leq \\default < t + \\dx t ) &= \\e^{- \\Gamma(t) } - \\e^{- \\Gamma(t + \\dx t) } \\\\\n      &=\\e^{- \\Gamma(t) } \\left( 1 - \\e^{ - \\int_t^{t + \\dx t} \\gamma (s) \\dx s } \\right) \\\\\n      &\\approx \\e^{- \\Gamma(t) } \\int_t^{t + \\dx t} \\gamma (s) \\dx s \\\\\n      &\\approx \\e^{- \\Gamma(t) } \\lambda(t) \\dx t \\\\\n      &= \\e^{ - \\int_0^t \\gamma (s) \\dx s } \\lambda(t) \\dx t ,\n  \\end{align}\nwhere the first approximation uses $\\e^x \\approx 1 + x$ given $x \\approx 0$ and the second is based on the definition of the integral and the assumption that $\\lambda$.\n\nSimilarly the conditional probability has the following approximation\n  \\begin{align}\n    \\Pm (\\default \\leq t + \\dx t | \\default > t) &= \\frac{ \\Pm (t < \\default \\leq t + \\dx t) }{ \\Pm (\\default > t) } \\\\\n      &= \\frac{ \\e^{- \\Gamma(t) } - \\e^{- \\Gamma(t + \\dx t) } }{ \\e^{- \\Gamma(t) } } \\\\\n      &= 1 - \\e^{ - \\int_t^{t + \\dx t} \\gamma (s) \\dx s } \\\\\n      &\\approx \\gamma(t) \\dx t\n  \\end{align}\n\nSuppose that $F$ is the cumulative distribution function of $\\default$, so\n  \\begin{align}\n    F(t) = \\Pm ( \\default \\leq t ),\n  \\end{align}\nand the function $F$ is absolutely continuous. This means that the derivative of $F$ exists and $F' = f$ almost everywhere, where $f$ is the density funtion of $\\default$. We denote $\\bar{F} (t) = 1 - F (t) = \\Pm ( \\default > t )$ and make the following assumptions\n  \\begin{enumerate}[labelindent=\\parindent, leftmargin=*, label*=(\\Alph*)]\n    \\item $\\Pm ( \\default = t ) = F ( 0 ) = 0$ for all $t \\geq 0$. \\label{intensityassumptionA}\n    \\item $F (t) < 1$ for all $0 \\leq t < \\infty$. \\label{intensityassumptionB}\n  \\end{enumerate}\nNow we may use Bayes rule to see that\n\\begin{align}\n     \\frac{\\Pm (\\default \\leq t + \\dx t | \\default > t)}{\\dx t} &= \\frac{\\Pm (t < \\default \\leq t + \\dx t)}{ \\Pm (\\default > t) \\dx t } \\\\ \n     &=  \\frac{F(t+\\dx t)-F(t)}{ \\Pm (\\default > t) \\dx t } \\\\\n     &\\longrightarrow \\frac{f(t)}{\\Pm (\\default > t)} \\\\\n     &= \\frac{f(t)}{\\bar{F} (t)} \\\\\n     &= - \\frac{\\dx}{\\dx t} \\log ( \\bar{F} (t) ) \\\\\n     &= \\frac{\\dx}{\\dx t} \\Gamma(t) \\\\\n     &= \\gamma(t)\n  \\end{align}\nas $\\dx t \\rightarrow 0^+$.\n\nWe note that\n\t\\begin{align}\n\t\t\\dx \\Pm ( \\default > t ) &= - \\lambda (t) \\e^{ - \\int_0^t \\gamma (s)  \\dx s } \\\\\n\t\t\t&= - \\lambda (t) \\dx \\Pm ( \\default > t )\n\t\\end{align}\nholds.\n\nIn summary,\n  \\begin{align}\n    \\gamma (t) &= \\Gamma' (t) \\\\\n    \\Gamma (t) &= \\int_0^t \\gamma (s) \\dx s \\\\\n    \\Pm ( \\default > t ) &= \\e^{- \\Gamma (t) } = \\e^{ - \\int_0^t \\gamma (s)  \\dx s } \\\\\n    \\gamma (t) \\dx t &\\approx \\Pm (\\default \\leq t + \\dx t | \\default > t) .\n  \\end{align}\nIn general setting, the function $\\gamma(t)$ is the hazard function of $\\default$. The hazard function can be seen as the instantaneous probability of default happening just after the time $t$ given the survival up to time $t$. In the context of credit risk, we shall call the function $\\gamma$ as the intensity function.\n\nIf $\\lambda (t) = \\lambda > 0$ is a deterministic constant, then $F$ is the cumulative distribution function of exponential distribution with parameter $\\lambda$ and therefore $\\E (\\default) = 1/\\lambda$ and $\\Var (\\default) = 1/\\lambda^2$. Also\n  \\begin{align}\n    \\label{survivalexpectationforconstanthazard}\n    \\E ( \\1_{ \\{ \\default > t \\} } ) = \\Pm ( \\default > t ) = \\e^{-\\int_0^t \\lambda_s \\dx s} = \\e^{-\\lambda t} .\n  \\end{align}\nThus $\\default$ is signaled by the first jump of time-homogenous Poisson distribution with parameter $\\lambda$. Similarly, if $\\lambda (t) > 0$ is deterministic function, then $\\default$ is the first jump of non-homogenous Poisson distribution with rate function $\\lambda(t)$. If $\\lambda (t)$ is a stochastic process, then $\\default$ will follow a Cox process.\n\n\\subsection{The credit triangle}\n\n\\added{The derivation of the credit triangle follows } \\textcite[pp. 54--55]{o2011modelling} although the note after the credit triangle might be original.\n\nIn this section we consider a simplified CDS contract in the intensity framework. We assume the following\n\n\\begin{enumerate}[labelindent=\\parindent, leftmargin=*]\n\t\\item $\\lambda (t) = \\lambda > 0$ is a deterministic constant.\n\t\\item The timing of default $\\default$ is independent from interest rates under the measure $\\Pm$.\n\t\\item The recovery rate $0 \\leq \\Rec \\leq 1$ is a deterministic constant and it is paid at the moment of the default.\n\t\\item CDS with no upfront costs pays premium continuously at rate $s$ until the default $\\default$ or the termination date $T$.\n\\end{enumerate}\n\nThe last assumption means that in the interval $[t,t+ \\dx t]$ the paid premium is $s \\dx t$ and if $\\dx t$ is tiny, then the present value of this is $\\Bond(0,t) s \\dx t$. The value of the premium leg is then\n\\begin{align}\n\\label{trianglevaluationpremium}\n\\E \\left( \\int_0^T \\DF(0,t) s \\1_{\\{ \\default > t \\}} \\dx t  \\right) &= s \\int_0^T \\E \\left( \\DF(0,t) \\1_{\\{ \\default > t \\}} \\right) \\dx t \\\\\n&= s \\int_0^T  \\Bond(0,t) \\Pm ( \\default > t ) \\dx t .\n\\end{align}\n\nFor the valuation of the protection leg, we calculate\n\\begin{align}\n\\E \\left( \\DF(0,\\default) (1-\\Rec) \\1_{ \\{ \\default \\leq T \\} } \\right) &= (1-\\Rec) \\E \\left( \\int_0^T \\DF(0,t) \\1_{ \\{ t \\leq \\default < \\default + \\dx t \\} } \\right) \\\\\n&= \\LGD \\int_0^T \\E \\left( \\DF(0,t) \\1_{ \\{ t \\leq \\default < \\default + \\dx t \\} } \\right) \\\\\n&= \\LGD \\int_0^T \\Bond(0,t) \\Pm ( t \\leq \\default < t + \\dx t ) \\\\\n&= - \\LGD \\int_0^T \\Bond(0,t) \\dx \\Pm ( \\default > t ),\n\\end{align}\nwhere in the last step we used the derivative of the identity $\\Pm ( \\default \\leq t ) = 1 - \\Pm ( \\default > t )$. \n\nNow\n\\begin{align}\n\\E \\left( \\DF(0,\\default) \\LGD \\1_{ \\{ \\default \\leq T \\} } \\right) = \\LGD \\lambda \\int_0^T \\Bond(0,t) \\Pm ( \\default > t ) \\dx t\n\\end{align}\nand since this must be equal to value in equation (\\ref{trianglevaluationpremium}), we get the following identity\n\\begin{align}\ns = \\lambda \\LGD.\n\\end{align}\nThis is the credit triangle. It is also quick and easy to understand, but only one of the three variables are actually directly observable from market data. If $\\Rec = 0$, then $s = \\lambda$ and the default intensity is the coupon rate intensity of the CDS.\n\nIt should be noted that the model has pathological behavior if $\\Rec \\approx 1$. If $\\Rec = 1$, then a defaultable zero coupon bond is more valuable than otherwise identical risk-free bond since the defaultable bond might pay the principal earlier\\footnote{One reasonable restriction that will preclude this is $\\Rec < \\Bond(0,T)$}. Since the recovery value is rarely near the notional value, this is not a serious problem.\n\nNowadays credit default swaps are traded with standardized coupon rates and upfront payments. However, if the CDS has a upfront value of $U$, then\n\t\\begin{align}\n\t\tU &= s \\int_0^T  \\Bond(0,t) \\Pm ( \\default > t ) \\dx t - \\LGD \\lambda \\int_0^T \\Bond(0,t) \\Pm ( \\default > t ) \\dx t \\\\\n\t\t&= (s - \\lambda \\LGD) Q(r, \\lambda) ,\n\t\\end{align}\nwhere \n\t\\begin{align}\n\t\tQ(r, \\lambda) &= \\int_0^T  \\Bond(0,t) \\Pm ( \\default > t ) \\dx t .\n\t\\end{align}\nIf we assume that the short-rate is roughly a constant $r$ for all times $0 < t < T$, then\n\t\\begin{align}\n\t\tQ(r, \\lambda) &\\approx \\int_0^T  \\e^{-(r+\\lambda)t} \\dx t \\\\\n\t\t\t&= \\frac{1-\\e^{-(r+\\lambda)T}}{r+\\lambda}\n\t\\end{align}\nand thus\n\t\\begin{align}\n\t\tU &= (s - \\lambda \\LGD) \\frac{1-\\e^{-(r+\\lambda)T}}{r+\\lambda}.\n\t\\end{align}\n\n\\section{Pricing}\n\n\\added{The pricing argumentation follows closely } \\textcite[pp. 790--792]{brigo2007interest}\n\nIn this section we assume that the $\\sigma$-algebra $(\\F_t)$ presents partial market information without default and \n\\begin{align}\n\\Hf_t = \\sigma( \\1_{ \\{\\default \\leq s \\} } | s \\leq t ) = \\sigma( H(s) | s \\leq t ) \n\\end{align}\nis the knowledge of the default up to time $t$. By\n\\begin{align}\n\\G_t = \\F_t \\vee \\Hf_t\n\\end{align}\nwe denote the smallest $\\sigma$-algebra containing $\\F_t$ and $\\Hf_t$. We assume that conditions \\ref{DS1} and \\ref{DS2} of Section \\ref{sec:doublystochastic} are satisfied by the process $\\lambda$.\n\nTheorem \\ref{eq_takingthedefaultinformationoutdoubly} is an important tool in our arsenal, so we restate it here. Under very reasonable assumptions, we have that\n\t\\begin{align}\n\t\t\\E_{\\Pm} \\left( \\1_{ \\{ \\default > T \\} } X | \\G_t  \\right) = \\1_{ \\{ \\default > t \\} } \\e^{ \\int_0^t \\lambda(s) \\dx s }  \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\right)\n\t\\end{align}\nfor random variables $X$ and $T \\geq t$.\n\n\\subsubsection{Defaultable zero coupon bond with no recovery}\n\nA defaultable $T$-bond with no recovery has pay-off $H_T = \\1_{\\{\\default > T\\}}$. Now by Lemma \\ref{eq_takingthedefaultinformationoutdoubly}, \n  \\begin{align}\n    \\DBond_0(t,T) =& \\E_{\\Pm} \\left( \\exp^{ - \\int_t^T r(s) \\dx s } H_T \\ | \\ \\F_t \\vee \\Hf_t \\right) \\\\\n    =& \\1_{\\{\\default > t\\}} \\exp^{ \\int_0^t \\lambda (s) \\dx s } \\E_{\\Pm} \\left( \\exp^{ - \\int_t^T r(s) \\dx s } H_T \\ | \\ \\F_t \\right) \\\\\n    =& \\1_{\\{\\default > t\\}} \\exp^{ \\int_0^t \\lambda (s) \\dx s } \\E_{\\Pm} \\left( \\exp^{ - \\int_t^T r(s) \\dx s } \\E_{\\Pm} \\left( H_T | \\F_T \\right) \\ | \\ \\F_t \\right) \\\\\n    =& \\1_{\\{\\default > t\\}} \\exp^{ \\int_0^t \\lambda (s) \\dx s } \\E_{\\Pm} \\left( \\exp^{ - \\int_t^T r(s) \\dx s } \\exp^{ - \\int_0^T \\lambda (s) \\dx s }  \\ | \\ \\F_t \\right) \\\\\n=& \\1_{\\{\\default > t\\}} \\E_{\\Pm} \\left( \\exp^{ - \\int_t^T (r(s) + \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right)\n  \\end{align}\nIf $\\lambda(s) \\geq 0$ almost surely, then we may see\n  \\begin{align}\n  r(s) + \\lambda (s) \\geq r(s)\n  \\end{align}\nis the defaultable short-rate. Thus we may reuse all the machinery from the short-rate models.\n\n\\subsubsection{Defaultable zero coupon bond with partial recovery $0 < \\Rec < 1$ at the maturity}\n\nA defaultable zero coupon bond with maturity $T$ and partial recovery at the maturity has pay-off \n  \\begin{align}\n    \\1_{\\{\\default > T\\}} + \\Rec \\1_{\\{\\default \\leq T\\}} &= ( 1 - \\Rec ) \\1_{\\{\\default > T\\}} + \\Rec \\\\\n    &= \\1_{\\{\\default > T\\}} \\LGD + \\Rec\n  \\end{align} \nat the maturity. Thus the price of it at the time $t$ is\n  \\begin{align}\n    \\DBond_M(t,T) = \\DBond_0(t,T) \\LGD +  \\Bond(t,T) \\Rec,\n  \\end{align}\nwhere $\\DBond_0$ is the price of defaultable zero coupon bond with no recovery and $\\Bond$ is the price of non-defaultable zero coupon bond.\n\n\\subsubsection{Defaultable zero coupon bond with partial recovery at the default}\n\nThe price of a defaultable zero coupon bond with partial recovery at the default is\n\\begin{align}\n\\DBond_D(t,T) = \\DBond_0 (t,T) + \\Rec Q(t,T) ,\n\\end{align}\nwhere\n  \\begin{align}\n    Q(t,T) = \\E_{\\Pm} \\left( \\e^{ - \\int_t^{\\default} r(s) \\dx s } \\1_{\\{t < \\default \\leq T\\}} \\ | \\ \\F_t \\vee \\Hf_t \\right),\n  \\end{align}\nwhich is the expected value of $1$ paid at the time of the default at the time $t$. Now\n  \\begin{align}\n    Q(t,T) &= \\frac{ \\1_{ \\{\\default > t \\} } }{ \\Pm (\\default > t | \\F_t) } \\E_{\\Pm} \\left( \\e^{ - \\int_t^{\\default} r(s) \\dx s } \\1_{\\{t < \\default \\leq T\\}} \\ | \\ \\F_t \\right) \\\\\n    = & \\1_{ \\{\\default > t \\} } \\e^{ \\int_0^t \\lambda(s) \\dx s } \\E_{\\Pm} \\left( \\int_0^{\\infty} \\1_{\\{t < \\default \\leq T\\}} \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_t \\right) \\\\\n    = & \\1_{ \\{\\default > t \\} } \\e^{ \\int_0^t \\lambda(s) \\dx s } \\E_{\\Pm} \\left( \\int_{t}^{T} \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_t \\right) .\n  \\end{align}\nNow we can use Fubini's theorem to evaluate\n  \\begin{align}\n  &\\E_{\\Pm} \\left( \\int_{t}^{T} \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_t \\right) \\\\\n  = &\\E_{\\Pm} \\left( \\E_{\\Pm}  \\left( \\int_{t}^{T} \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_{T} \\right) \\ | \\ \\F_t \\right) \\\\\n    = &\\E_{\\Pm} \\left( \\int_{t}^{T} \\DF(t,s) \\E_{\\Pm}  \\left( \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_{T} \\right) \\ | \\ \\F_t \\right) \\\\\n    = &\\E_{\\Pm} \\left( \\int_{t}^{T} \\DF(t,s) \\Pm \\left( s \\leq \\default < s + \\dx s \\ | \\ \\F_{T} \\right) \\ | \\ \\F_t \\right) \\\\\n    =  &\\E_{\\Pm} \\left( \\int_{t}^{T} \\DF(t,s) \\lambda(s) \\e^{ - \\int_0^s \\lambda(u) \\dx u } \\dx s \\ | \\ \\F_t \\right) \\\\\n    =  &\\E_{\\Pm} \\left( \\int_{t}^{T} \\e^{ - \\int_t^s r(u) \\dx u }  \\lambda(s) \\e^{ - \\int_0^s \\lambda(u) \\dx u } \\dx s \\ | \\ \\F_t \\right) .   \n  \\end{align}\nThus\n  \\begin{align}\n    Q(t,T) &= \\1_{ \\{\\default > t \\} } \\E_{\\Pm} \\left( \\int_{t}^{T}  \\lambda(s) \\e^{ - \\int_t^s (r(u) + \\lambda(u)) \\dx u } \\dx s \\ | \\ \\F_t \\right) \\\\\n    &= \\1_{ \\{\\default > t \\} } \\int_{t}^{T} \\E_{\\Pm} \\left( \\lambda(s) \\e^{ - \\int_t^s (r(u) + \\lambda(u)) \\dx u } \\ | \\ \\F_t \\right) \\dx s\n  \\end{align}\n and\n\\begin{align}\n\\DBond_D(t,T) = \\DBond_0 (t,T) + \\1_{ \\{\\default > t \\} } \\Rec \\int_{t}^{T} \\E_{\\Pm} \\left( \\lambda(s) \\e^{ - \\int_t^s (r(u) + \\lambda(u)) \\dx u } \\ | \\ \\F_t \\right) \\dx s\n\\end{align}\n\\subsection{The protection leg of a credit default swap}\n\nWe now developed a price for the protection leg that pays $\\LGD$ at the default $\\default$, if $S < \\default \\leq T$. The price of it at the time $0 \\leq t < T$ is\n  \\begin{align}\n    \\Protection(t) &= \\1_{ \\{ \\default > t \\} } \\E_{\\Pm} \\left( \\1_{ \\{ S < \\default < T \\} } \\DF(t,\\default) \\LGD \\ | \\ \\G_t \\right) \\\\\n    &= \\frac{ \\1_{ \\{ \\default > t \\} } }{ \\Pm (\\default > t | \\F_t ) } \\E_{\\Pm} \\left( \\1_{ \\{ S < \\default < T \\} } \\DF(t,\\default) \\LGD \\ | \\ \\F_t \\right) .\n  \\end{align}\nNow heuristically\n  \\begin{align}\n    & \\E_{\\Pm} \\left( \\1_{ \\{ S < \\default < T \\} } \\DF(t,\\default) \\ | \\ \\F_t \\right) \\\\ \n    = & \\E_{\\Pm} \\left( \\int_0^{\\infty} \\1_{ \\{ S < s < T \\} } \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_t \\right) \\\\\n    = & \\E_{\\Pm} \\left( \\int_{S}^{T} \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_t \\right) \\\\\n    = & \\E_{\\Pm} \\left( \\E_{\\Pm}  \\left( \\int_{S}^{T} \\DF(t,s) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_{T} \\right) \\ | \\ \\F_t \\right) \\\\\n    = & \\E_{\\Pm} \\left( \\int_{S}^{T} \\DF(t,s) \\E_{\\Pm}  \\left( \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_{T} \\right) \\ | \\ \\F_t \\right) \\\\\n    = & \\E_{\\Pm} \\left( \\int_{S}^{T} \\DF(t,s) \\Pm \\left( s \\leq \\default < s + \\dx s \\ | \\ \\F_{T} \\right) \\ | \\ \\F_t \\right) \\\\\n    = & \\E_{\\Pm} \\left( \\int_{S}^{T} \\DF(t,s) \\lambda(u) \\exp^{ - \\int_0^s \\lambda(u) \\dx u } \\dx s \\ | \\ \\F_t \\right) \\\\\n    = & \\E_{\\Pm} \\left( \\int_{S}^{T} \\exp^{ - \\int_t^s r(u) \\dx u }  \\lambda(u) \\exp^{ - \\int_0^s \\lambda(u) \\dx u } \\dx s \\ | \\ \\F_t \\right) \\\\\n    = & \\exp^{ \\int_0^t \\lambda(u) \\dx u } \\E_{\\Pm} \\left( \\int_{S}^{T}  \\lambda(s) \\exp^{ - \\int_t^s (r(u) + \\lambda(u)) \\dx u } \\dx s \\ | \\ \\F_t \\right) .\n  \\end{align}\nThus\n \\begin{align}\n\\Protection(t) &= \\1_{ \\{ \\default > t \\} } \\LGD \\E_{\\Pm} \\left( \\int_{S}^{T}  \\lambda(s) \\exp^{ - \\int_t^s (r(u) + \\lambda(u)) \\dx u } \\dx s \\ | \\ \\F_t \\right) \\\\\n\t&= \\1_{ \\{ \\default > t \\} } \\LGD \\int_{S}^{T} \\E_{\\Pm} \\left( \\lambda(u) \\exp^{ - \\int_t^s (r(u) + \\lambda(s)) \\dx u }  \\ | \\ \\F_t \\right) \\dx s,\n\\end{align}\nwhere we have assumed that the $\\LGD$ is a constant.\n\n\\subsection{The premium leg of a credit default swap}\n\nThe premium leg of a CDS with a coupon rate $C$ has a value\n\\begin{align}\n\\Premium(t, C) = &\\1_{ \\{ \\default > t \\} } \\E_{\\Pm} \\left( \\DF(t,\\default) C^{h(\\default)} \\1_{ \\{ S < \\default < T \\} } \\ | \\ \\G_t \\right) \\\\\n\t&+ \\1_{ \\{ \\default > t \\} } \\sum_{i=1}^n \\E_{\\Pm} \\left( \\DF(t,t_i) C_i \\1_{ \\{ \\default > t_i \\} } \\ | \\ \\G_t \\right) ,\n\\end{align}\nwhere $C_i = C \\dayc (t_{i-1}, t_i)$, $t_{h(\\default)}$ is the last coupon date before the default (if it occurs) and $C^{h(\\default)} = C \\dayc (t_{h(\\default)}, \\default) \\approx C(\\default - t_{h(\\default)})$. We have also re-indexed the coupon dates so that $t_0 \\leq t \\leq t_1$.\n\nNow \n\t\\begin{align}\n\t \tC_i(t,T) &= \\E_{\\Pm} \\left( \\DF(t,t_i) \\1_{ \\{ \\default > t_i \\} } \\ | \\ \\G_t \\right) \\\\\n\t \t&= \\1_{ \\{ \\default > t_i \\} } \\exp^{ \\int_0^t \\lambda(s) \\dx s } \\E_{\\Pm} \\left( \\DF(t,t_i) \\1_{ \\{ \\default > t_i \\} } \\ | \\ \\F_t \\right) \\\\\n\t \t&= \\1_{ \\{ \\default > t_i \\} } \\exp^{ \\int_0^t \\lambda(s) \\dx s } \\E_{\\Pm} \\left( \\exp^{ \\int_t^{t_i} r(s) \\dx s } \\exp^{ \\int_0^{t_i} \\lambda(s) \\dx s } \\ | \\ \\F_t \\right) \\\\\n\t \t&= \\1_{ \\{ \\default > t_i \\} } \\E_{\\Pm} \\left( \\exp^{ \\int_t^{t_i} (r(s) - \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right)\n\t\\end{align}\nand, by recycling the earlier calculations, we get that\n\t\\begin{align}\nC^{h(\\default)}(t,T) &= \\E_{\\Pm} \\left( (\\default - t_{h(\\default)}) \\DF(t,\\default) \\1_{ \\{ S < \\default < T \\} } \\ | \\ \\G_t \\right) \\\\\n\t&= \\1_{ \\{ \\default > t \\} } \\exp^{ \\int_0^t \\lambda(s) \\dx s } E\n\\end{align}\nwhere the expectation\n\t\\begin{align}\n\t\tE &= \\E_{\\Pm} \\left( (\\default - t_{h(\\default)}) \\DF(t,\\default) \\1_{ \\{ S < \\default < T \\} } \\ | \\ \\F_t \\right) \\\\\n\t\t&= \\E_{\\Pm} \\left( \\int_t^{\\infty} (s - t_{h(s)}) \\DF(t,s)  \\1_{ \\{ S < s < T \\} } \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_t \\right)\t\\\\\t\n\t\t&= \\E_{\\Pm} \\left( \\E_{\\Pm} \\left( \\int_S^T (s - t_{h(s)}) \\DF(t,\\default) \\1_{ \\{ s \\leq \\default < s + \\dx s \\} } \\ | \\ \\F_T \\right)  \\ | \\ \\F_t \\right) \\\\\n\t\t&= \\E_{\\Pm} \\left( \\int_S^T (s - t_{h(s)}) \\DF(t,s) \\Pm( s \\leq \\default < s + \\dx s \\ | \\ \\F_T )  \\ | \\ \\F_t \\right) \\\\\n\t\t&= \\E_{\\Pm} \\left( \\int_S^T (s - t_{h(s)}) \\DF(t,s) \\e^{ -\\int_0^s \\lambda(u) \\dx u } \\lambda(s) \\ \\dx s  \\ | \\ \\F_t \\right) \\\\\n\t\t&= \\int_S^T \\E_{\\Pm} \\left(  (s - t_{h(s)}) \\DF(t,s) \\e^{ -\\int_0^s \\lambda(u) \\dx u } \\lambda(s)  \\ | \\ \\F_t \\right) \\dx s .\n\t\\end{align}\nHence \n\t\\begin{align}\nA &= C C^{h(\\default)}(t,T) \\\\\n&= \\1_{ \\{ \\default > t \\} } C \\int_S^T \\E_{\\Pm} \\left(  (s - t_{h(s)}) \\DF(t,s) \\e^{ -\\int_t^s \\lambda(u) \\dx u } \\lambda(s)  \\ | \\ \\F_t \\right) \\dx s\t.\t\n\t\\end{align}\nThus\n\\begin{align}\n\\Premium(t, C) &= \\1_{ \\{ \\default > t \\} } C \\left( C^{s(\\default)}(t,T) + \\sum_{i=1}^n \\dayc (t_{i-1}, t_i) C_i(t,T) \\right) \\\\\n\t&= C \\left( \\sum_{i=1}^n \\dayc (t_{i-1}, t_i) \\DBond_0(t,t_i) \\right) + A ,\n\\end{align}\nwhere $\\DBond_0$ is the price of zero coupon bond with no recovery and $A$ is term representing the accrued coupon before the default.\n\nAs we saw here, the most complicated part in the pricing of the premium leg of a CDS is the accrued coupon payment before the default. If we wish to simplify the model, then the accrual payment could be dropped or we could assume that premium is paid continuously. Both will result in biased priced, but this might be acceptable. If the accrued coupon payment is dropped, then the premium leg is just a portfolio of defaultable zero-coupon bonds with no recovery.\n\nIf the accrued coupon payment term has to simplified, it could be assumed that default happens in the middle of the coupon period or that the coupon is paid continuously during the accrual period.\n\n\\subsubsection{Premium leg of a CDS with continuous premium}\n\nWe may also suppose that premium leg pays a continuous premium $c$. If $\\dx t > 0$ is small, then premium leg pays from $t$ to $\\dx t$ the amount of $c \\dx t$ assuming that the credit event does not occur. By using the old tricks, we may value this default intensity as\n\t\\begin{align}\n\t\t&\\E_{\\Pm} \\left( c \\e^{ - \\int_t^{t+\\dx t} r(s) \\dx s} \\dx t \\1_{ \\{ \\default > t + \\dx t\t  \\} } \\ | \\ \\G_t \\right) \\\\\n\t\t= &\\1_{ \\{ \\default  > t \\} } \\E_{\\Pm} \\left( c \\e^{ - \\int_t^{t+\\dx t} (r(s) + \\lambda(s)) \\dx s} \\dx t \\ | \\ \\F_t \\right) .\n\t\\end{align}\nBy taking the limit of this process we have that\n\t\\begin{align}\n\t\t\\Premium(t, c) &= c \\int_t^T \\1_{ \\{ \\default  > u \\} } \\E_{\\Pm} \\left(  \\e^{ - \\int_t^{u} (r(s) + \\lambda(s)) \\dx s} \\ | \\ \\F_t \\right) \\dx u \\\\\n\t\t&= c \\int_t^T \\DBond_0(t,s) \\dx s ,\n\t\\end{align}\nwhere $\\DBond_0(t,u)$ is the price of a defaultable $u$-bond with no recovery at the time $t$.\n\n\n\\section{The assumption that the default is independent from interest rates}\n\nAll the pricing formulas had the term\n\t\\begin{align}\n\t\t\\E_{\\Pm} \\left( \\exp^{ - \\int_t^T (r(s) + \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right) .\n\t\\end{align}\nIf the default is independent of the interest rates under the risk neutral measure, then we may write\n\t\\begin{align}\n\t\t\\E_{\\Pm} \\left( \\exp^{ - \\int_t^T (r(s) + \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right) &= \\Bond(t,T) \\Gamma(t,T), \n\t\\end{align}\nwhere\n\t\\begin{align}\n\t\t\\Gamma(t,T) &= \\E_{\\Pm} \\left( \\exp^{ - \\int_t^T \\lambda(s) \\dx s } \\ | \\ \\F_t \\right)\n\t\\end{align}\nHence\n\t\\begin{align}\n\t\t\\DBond_0(t,T) &= \\1_{ \\{\\default > t \\} } \\Bond(t,T) \\Gamma(t,T) \\\\\n\t\t\\DBond_M(t,T) &= \\1_{ \\{\\default > t \\} } \\Bond(t,T) \\left( \\Gamma(t,T) \\LGD + \\Rec \\right) \n\t\\end{align}\nfor bonds with zero recovery or partial recovery at the maturity. As now\n  \\begin{align}\n\t\tQ(t,T) &= \\1_{ \\{\\default > t \\} } \\int_{t}^{T} \\E_{\\Pm} \\left( \\lambda(s) \\e^{ - \\int_t^s (r(u) + \\lambda(u)) \\dx u } \\ | \\ \\F_t \\right) \\dx s \\\\\n\t\t&= \\1_{ \\{\\default > t \\} } \\int_{t}^{T} \\Bond(t,s) \\E_{\\Pm} \\left( \\lambda(s) \\e^{ - \\int_t^s \\lambda(u) \\dx u } \\ | \\ \\F_t \\right) \\dx s \\\\\n\t\t&= \\1_{ \\{\\default > t \\} } \\int_{t}^{T} \\Bond(t,s) \\E_{\\Pm} \\left( - \\frac{\\partial}{\\partial s} \\e^{ - \\int_t^s \\lambda(u) \\dx u } \\ | \\ \\F_t \\right) \\dx s ,\n\t\\end{align}\nwe have that\n  \\begin{align}\n\t\\DBond_D(t,T) = \\DBond_0 (t,T) + \\1_{ \\{\\default > t \\} } \\Rec \\int_{t}^{T} \\Bond(t,s) \\E_{\\Pm} \\left( - \\frac{\\partial}{\\partial s} \\e^{ - \\int_t^s \\lambda(u) \\dx u } \\ | \\ \\F_t \\right) \\dx s\n\t\\end{align}\n\t\n\\section{$A(M,N)$ model for credit risk}\n\nWe assume that there are $N$ state-variables driving short-rate and intensity processes under the risk-neutral measures. Of these, $M$ follow square-root process and $N-M$ are gaussian. We follow the presentation in \\textcite[pp. 457--476]{nawalkabeliaevasoto2007dynamic}.\n\nMore precisely, the correlated gaussian process are\n\\begin{align}\n\\dx Y_i(t) &= - k_i Y_i(t) \\dx t + \\nu_i \\dx W_i (t),\n\\end{align}\nwhere $W_i$ is a Wiener process and \n\\begin{align}\n\\dx W_i (t) \\dx W_j (t) &= \\rho_{ij} \\dx t    \n\\end{align}\nfor all $i,j = 1,2, \\ldots, N-M$. Here $-1 < \\rho_{ij} = \\rho_{ji} < 1$ and $\\rho_{ii} = 1$. The $M$ square-root processes are\n\\begin{align}\n\\dx X_m(t) = \\alpha_m ( \\theta_m - X_m(t) ) \\dx t + \\sigma_m \\sqrt{ X_m(t) } \\dx Z_m (t)\n\\end{align}\nwhere $Z_m$ are independent Wiener process and\n\\begin{align}\n\\dx W_i (t) \\dx Z_m (t) &= 0    \n\\end{align}\nfor all $i = 1,2, \\ldots, N-M$ and $m = 1,2, \\ldots, M$. The short-rate is defined by\n\\begin{align}\n\\label{riskfree_process}\nr(t) = \\delta_r + \\sum_{m=1}^{M} a_mX_m(t) + \\sum_{i=1}^{N-M} c_iY_i(t),\n\\end{align}\nand the default intensity by\n\\begin{align}\n\\label{spreadprocess}\n\\lambda(t) = \\delta_{\\lambda} + \\sum_{m=1}^{M} b_mX_m(t) + \\sum_{i=1}^{N-M} d_iY_i(t),\n\\end{align}\nwhere $\\delta_r, \\delta_{\\lambda}$ are constants and $a_m, c_m$ for $m=1,2, \\ldots, M$ and $c_i, d_i$ for $i=1,2, \\ldots, N-M$ for non-negative constants.\n\nAs shown earlier in Equation \\ref{}, the price of a defaultable $T$-bond with recovery of a face value is given by\n\t\\begin{align}\n\t\t\\DBond(t,T) = \\DBond_0(t,T) +\\Rec \\int_t^T \\E_{\\Pm} \\left( \\lambda(u) \\e^{ - \\int_t^u (r(s) + \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right) \\dx u ,\n\t\\end{align}\nwhere\n\t\\begin{align}\n\t\t\\DBond_0(t,T) = \\E_{\\Pm} \\left( \\e^{ - \\int_t^T (r(s) + \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right)\n\t\\end{align}\nis the price of a defaultable bond with no recovery.\n\nWe denote\n\t\\begin{align}\n\t\tG(t,T) &= \\E_{\\Pm} \\left( \\lambda(T) \\e^{ - \\int_t^T (r(s) + \\lambda(s)) \\dx s } \\ | \\ \\F_t \\right) \\\\\n\t\t&= \\frac{\\partial}{\\partial \\phi} \\left( \\eta(t,T,\\phi) \\right)_{\\phi=0} ,\n\t\\end{align}\nwhere\n\t\\begin{align}\n\t\t\\eta(t,T,\\phi) &= \\E_{\\Pm} \\left( \\e^{ - \\int_t^T (r(s) + \\lambda(s)) \\dx s } \\e^{\\phi \\lambda(T)} \\ | \\ \\F_t \\right)\n\t\\end{align}\nThe solution to this expectation is given by (under certain assumptions)\n\t\\begin{align}\n\t\t\\eta(t,T,\\phi) = \\e^{ A^{\\dagger}(\\tau) - \\sum\\limits_{m=1}^M(a_m+b_m)B_m^{\\dagger}(\\tau)X_m(t) - \\sum\\limits_{i=1}^{N-M} (c_i + d_i) C_i^{\\dagger}(\\tau) Y_i(t) - H^{\\dagger}(t,T) },\n\t\\end{align}\nwhere $\\tau = T-t$ and\n\\begin{align}\nH^{\\dagger}(t,T) &= \\int_t^T (\\delta_r + \\delta_{\\lambda}) \\dx x = (\\delta_r + \\delta_{\\lambda}) \\tau, \\\\\n\\beta_{1m} &= \\sqrt{\\alpha_m^2 + 2 (a_m+b_m) \\sigma_m^2} , \\\\\n\\beta_{2m} &= \\frac{-\\alpha_m+\\beta_{1m}}{2} , \\\\\n\\beta_{3m} &= \\frac{-\\alpha_m-\\beta_{1m}}{2} , \\\\\n\\beta_{4m} &= \\frac{-\\alpha_m - \\beta_{1m} + \\phi b_m \\sigma_m^2}{-\\alpha_m + \\beta_{1m} + \\phi b_m \\sigma_m^2} , \\\\\nB_m^{\\dagger}(\\tau) &= \\frac{ 2 }{ (a_m + b_m) \\sigma_m^2 } \\left( \\frac{ \\beta_{2m} \\beta_{4m} \\e^{\\beta_{1m} \\tau} - \\beta_{3m} }{ \\beta_{4m} \\e^{\\beta_{1m} \\tau} - 1 } \\right), \\\\\nA_X^{\\dagger}(\\tau) &= \\sum_{m=1}^M \\frac{\\alpha_m \\theta_m}{\\sigma_m^2} \\left( \\beta_{3m} \\tau + \\log \\left( \\frac{ 1-\\beta_{4m}\\e^{ \\beta_{1m} \\tau }  }{1-\\beta_{4m}} \\right) \\right) \\\\\nq_i &= 1 + \\phi k_i \\frac{d_i}{c_i + d_i} \\\\\nC_i^{\\dagger}(\\tau) &= \\frac{1 - q_i\\e^{-k_i \\tau}}{k_i}, \\\\\nD^{\\dagger} (\\tau) &= \\tau - q_i C_i^{\\dagger}(\\tau) - q_j C_j^{\\dagger}(\\tau) + q_iq_j \\frac{ 1 - \\e^{ - (k_i + k_j) \\tau} }{k_i + k_j} \\\\\nA_Y^{\\dagger}(\\tau) &= \\sum_{i=1}^{N-M} \\sum_{j=1}^{N-M} \n\t\\frac{ (c_i+d_i)(c_j+d_j) \\nu_i \\nu_j \\rho_{ij} }{ k_i k_j }\n\t D^{\\dagger} (\\tau) \\\\\nA^{\\dagger}(\\tau) &= \\phi \\delta_{\\lambda} + \\frac{1}{2}A_Y^{\\dagger}(\\tau) - 2 A_X^{\\dagger}(\\tau)\n\\end{align}\nfor all $i = 1,2, \\ldots, N-M$ and $m=1,2, \\ldots, M$. Now $G(t,T)$ can be approximated as the numerical derivative of $\\eta(t,T,\\phi)$ at $0$.\n\nUnder this model\n\t\\begin{align}\n\t\t\\DBond_0(t,T) = \\e^{ A^{\\dagger}(\\tau) - \\sum\\limits_{m=1}^M(a_m+b_m)B_m^{\\dagger}(\\tau)X_m(t) - \\sum\\limits_{i=1}^{N-M} (c_i + d_i) C_i^{\\dagger}(\\tau) Y_i(t) - H^{\\dagger}(t,T) }\n\t\\end{align},\nwhere $\\tau = T-t$ and\n\\begin{align}\nH(t,T) &= \\int_t^T \\left( \\delta_r + \\delta_{\\lambda} \\right) \\dx x = \\left( \\delta_r + \\delta_{\\lambda} \\right) \\tau, \\\\\n\\beta_m &= \\sqrt{ \\alpha_m^2 + 2(a_c+b_m)\\sigma_m^2 }, \\\\\nB_m(\\tau) &= \\frac{2 (\\e^{\\beta_m \\tau} - 1) }{ \\beta_m + (\\e^{\\beta_m \\tau} - 1) + 2 \\beta_m }, \\\\\nA_X (\\tau) &=  \\sum_{m=1}^M \\frac{\\alpha_m \\theta_m}{\\sigma_m^2} \\log \n\t\\frac{ 2 \\beta_m \\e^{ \\frac{(\\beta_m + \\alpha_m)\\tau}{2} }  }{ (\\beta_m + \\alpha_m) + (\\e^{\\beta_m \\tau} - 1) + 2 \\beta_m }, \\\\\nC_i (\\tau) &= \\frac{1 - \\e^{ - k_i \\tau } }{ k_i }, \\\\\nD(\\tau) &= \\tau - C_i(\\tau) - C_j(\\tau) + \\frac{ 1 - \\e^{ -(k_i+k_j)\\tau } }{k_i + k_j}, \\\\\nA_Y (\\tau) &= \\sum_{i=1}^{N_M} \\sum_{j=1}^{N_M} \\frac{ (c_i+d_i)(c_j+d_j)\\nu_i \\nu_j \\rho_{ij} }{k_i k_j} D(\\tau), \\\\\nA(\\tau) &= 2 A_X (\\tau) + \\frac{1}{2} A_Y (\\tau) .\n\\end{align}\nThe risk-free bond $\\Bond(t,T)$ may be priced using the equation above, but with $b_m = 0$ and $d_i = 0$ for all $m=1,2, \\ldots M$ and $i=1,2, \\ldots, N-M$. By differentiating of $Y_i^*(t) = c_i Y_i(t)$, we get that\n\t\\begin{align}\n\t\t\\dx Y_i^*(t) &= c_i \\dx Y_i(t) \\\\\n\t\t\t&= -k_i c_i Y_i(t) + c_i \\nu_i \\dx W_i(t) \\\\\n\t\t\t&= -k_i Y_i^*(t) + \\left( c_i \\nu_i \\right) \\dx W_i(t) .\n\t\\end{align}\nThis implies that we may use the formulas in Subsection \\ref{subsec-AMN-interestrate} by replacing $\\nu_i$ with $c_i \\nu_i$ and $Y_i(t)$ with $c_i Y_i(t)$. Similarly differentiating $X_m^* = a_m X_m(t)$ yields\n\t\\begin{align}\n\t\t\\dx X_m^*(t) &= a_m \\dx X_m(t) \\\\\n\t\t\t&= \\alpha_m( a_m \\theta_m - a_m X_m(t) ) \\dx t + \\sigma_m \\sqrt{a_m} \\sqrt{a_mX_m(t)} \\dx Z_m(t) \\\\\n\t\t\t&= \\alpha_m( (a_m \\theta_m) - X_m^*(t) ) \\dx t + (\\sigma_m \\sqrt{a_m}) \\sqrt{X_m^*(t)} \\dx Z_m(t)\n\\end{align}\nend we see that $\\theta_m$ needs to be replaced to $a_m \\theta_m$, $\\sigma_m$ to $\\sigma_m \\sqrt{a_m}$ and $X_m(t)$ to $a_m X_m(t)$. Thus we may also use the machinery of Chapter \\ref{chap:fourier} to price derivatives that only depends on the risk-free rate with similar changes.\n\nSince common state-variables may drive both risk-free rate and the default intensity, they may be correlated under the models of this family. As some of the state-variables may not be shared, these models have potentially a very rich structure. \n\nWe adopt the following notation. The model $D((a_X,b_X,c_X),(a_Y,b_Y,c_Y))$ is the model defined in the Equations \\ref{riskfree_process} and \\ref{spreadprocess} with the following properties\n\t\\begin{itemize}\n\t\t\\item $a_X$ is the number of square-root processes that are present in both Equations \\ref{riskfree_process} and \\ref{spreadprocess},\n\t\t\\item $b_X$ is the number of square-root processes that are unique to the risk-free rate process,\n\t\t\\item $c_X$ is the number of square-root processes that are unique to the spread process,\n\t\t\\item $a_Y$ is the number of gaussian processes that are present in both Equations \\ref{riskfree_process} and \\ref{spreadprocess},\n\t\t\\item $b_Y$ is the number of gaussian processes that are unique to the risk-free rate process and\n\t\t\\item $c_Y$ is the number of gaussian processes that are unique to the spread process.\n\t\\end{itemize}\nThus it is $A(M,N)$ model with\n\t\\begin{align}\n\t\tM &= a_X + b_X + c_X \\\\\n\t\tN - M &= a_Y + b_Y + c_Y .\n\t\\end{align}\n", "meta": {"hexsha": "0a57d8c8672937f35b08d9b0f5bc035cbbc8ed25", "size": 32174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intensiteetti.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": "intensiteetti.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": "intensiteetti.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": 63.5849802372, "max_line_length": 463, "alphanum_fraction": 0.5985578417, "num_tokens": 12418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.660140078324598}}
{"text": "\\mychapter{20}{Lesson 20} %181205\n\n\\section{Random Oracle Model (ROM)}\n\nThe Random Oracle Model treats a given hash function $H$ as a truly random function. As a reminder: a truly random function $R$ is defined to have a specific evaluation behaviour. They do act, in fact, as truth tables\\footnotemark:\n\n\\begin{itemize}\n    \\item if the argument hasn't been submitted to the function beforehand, then a value is chosen \\uar{} from the codomain, and assigned as the image of said argument in the function;\n    \\item otherwise, the function will return the image as assigned in the corresponding previous evaluation.\n\\end{itemize}\n\n\\footnotetext{Such tables are also aptly called \\emph{rainbow tables}.}\n\n\\subsection{Full domain hashing}\n\nLet $(f, f^{-1}, \\Gen)$ be a \\tdp{} scheme over some domain $\\mathcal{X}_{\\pk}$\n\nTake \\rsa:\n\\begin{itemize}\n    \\item $(m, \\pk, \\sk) \\pickUAR \\Gen\\rsa(1^\\lambda)$\n    \\item $f(\\pk, x) = x^{\\pk} \\mod n$\n    \\item $f^{-1}(\\sk, y) = y^{\\sk} \\mod n$\n\\end{itemize}\n\nBuild a similar asymmetric-authentication scheme as such:\n\n\\begin{itemize}\n    \\item $(m, \\pk, \\sk) \\pickUAR \\Gen\\rsa(1^\\lambda)$\n    \\item $Sign_{\\sk, H}(x): \\sigma = f^{-1}(\\sk, H(m))$\n    \\item $Verify_{\\pk, H}: H(m) = f(pk, \\sigma)$\n\\end{itemize}\n\n\\begin{exercise}\n    Show \\rsa-sign is not secure without $H$. (Hint: The scheme becomes malleable)\n\\end{exercise}\n\n\\begin{theorem}\n    If the above scheme (full-domain hash) uses a \\tdp{} for $f, f^{-1}$, then it is (asymmetric)-\\ufcma under the random oracle model.\n\\end{theorem}\n\n\\begin{proof}\n    Idea: Reduce to \\tdp, program the random oracle.\n\n    \\begin{cryptoredux}\n        {fdhufcma}\n        {}\n        {tdp}\n        {ufcma(a)}\n\n        \\receive{\\shortstack[l]{\n            $(pk, sk) \\pickUAR \\Gen(1^\\lambda)$ \\\\\n            $x \\pickUAR \\mathcal{X}_{pk}$ \\\\\n            $y = f(pk, x)$\n        }}{$pk, y$}{}\n\n        \\invoke{$*$}{$pk$}{}\n\n        \\cseqdelay\n        \\cseqbeginloop\n        \\return{}{$m$}{}\n        \\invoke{}{$\\sigma$}{}\n        \\cseqendloop\n        \\cseqdelay\n\n        \\return{}{$(m^*, \\sigma^*)$}{}\n\n        \\send{}{$\\sigma^*$}{}\n    \\end{cryptoredux}\n\n    Notes: this is a loose reduction\n\n    Some assumptions are made:\n\n    \\begin{itemize}\n        \\item The adversary makes the same number of RO queries as the number of signing queries done by the distinguisher (without loss of generality)\n        \\item The RO query must be done \\emph{before} the corresponding sign query, otherwise the adversary cannot sign the messages, as specified by the scheme\n    \\end{itemize}\n\n    The RO queries are actually an analogue of the definition of a random function, and it is the \\emph{programming} step of the oracle itself; then if the signing queries do not correspond to any RO query, abort the game.\n\n\\end{proof}\n\n\\section{ID Scheme}\n\n\\subsubsection{``Sigma'' protocol}\n\n\\subsection{Fiat-Shamir scheme}\n\n\\subsubsection{Honest Verifier Zero-Knowledge (HVZK)}\n\n\\subsubsection{Special Soundness (SS)}\n", "meta": {"hexsha": "194a37d7854f84460715182979ee30d10f0b2c21", "size": 2973, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_20.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_20.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_20.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": 32.3152173913, "max_line_length": 231, "alphanum_fraction": 0.6498486377, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619306896955, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6601400739358283}}
{"text": "%% -*- coding:utf-8 -*-\n\\chapter{Base definitions}\n\n\\section{Definitions}\n\n\\subsection{Object}\n\n\\begin{definition}[Class]\n  A class is a collection of sets (or sometimes other mathematical\n  objects) that can be unambiguously defined by a property that all\n  its members share. \n  \\label{def:class}\n\\end{definition}\n\n\\begin{definition}[Object]\n  \\label{def:object}\n  In category theory object is considered as something that does not\n  have internal structure (aka point) but has a property that makes\n  different objects belong to the same \\mynameref{def:class}\n\\end{definition}\n\n\\begin{remark}[Class of Objects]\n  \\label{rem:objclass}\n  The \\mynameref{def:class} of \\mynameref{def:object}s will be marked as \n  $\\catob{C}$ (see \\cref{fig:class_of_objects}).\n\\end{remark}\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    \\node at (0,4) {$\\cat{C}$};\n    \n    \\node[ele,label=left:$a$] (a) at (2,2) {};    \n    \\node[ele,label=left:$b$] (b) at (2,1) {};    \n    \\node[ele,label=left:$c$] (c) at (0,2) {};\n    \\node[ele,label=left:$d$] (d) at (0,1) {};\n    \n    \\node[draw,fit= (a) (b) (c) (d),minimum width=4cm, minimum\n      height=4cm] {}  ;\n\n  \\end{tikzpicture}\n  \\caption{Class of objects $\\catob{C}=\\{a,b,c,d\\}$}\n  \\label{fig:class_of_objects}\n\\end{figure}\n\n\n\\subsection{Morphism}\nMorphism is a kind of relation between 2 \\mynameref{def:object}s. \n\\begin{definition}[Morphism]\n  \\label{def:morphism}\n  A relation between two \\mynameref{def:object}s $a$ and $b$ \n  \\[\n  f_{ab}: a \\rightarrow b\n  \\]\n  is called\n  \\textit{morphism}. Morphism assumes a direction i.e. one \\mynameref{def:object}\n  ($a$) is called \\textit{source} and another one ($b$)\n  \\textit{target}.\n\n  The \\mynameref{def:set} of all morphisms between objects $a$ and $b$\n  is denoted as $\\hom\\left(a, b\\right)$.\n\\end{definition}\n\nThe important remark about morphisms is below\n\\begin{remark}[Morphism]\n\\label{rem:morphism}\nThe morphism has to be considered as a relation between objects. We\nwill avoid standard (from set theory) notation for morphisms: $f(a) =\nb$. The reason for this is the following. Let $f_1: a \\to b$ and $f_2:\na \\to b$ are 2 different morphisms. The notation $f_1(a) = b, f_2(a) =\nb$ leads to incorrect conclusion that $f_1 = f_2$. \n\nFor instance if $a\n= b = \\mathbb{R}$ then 2 functions $f_1(x) = x, f_2(x) = -x$ set 2\ndifferent ordering on $\\mathbb{R}$ and as result have not to be\nconsidered as the same functions.\n\\end{remark}\n\n\\begin{definition}[Domain]\n  \\label{def:domain}\n  Given a \\mynameref{def:morphism} $f: a \\to b$, the\n  \\mynameref{def:object} $a$ is called domain and denoted as $\\dom f$.\n\\end{definition}\n\n\\begin{definition}[Codomain]\n  \\label{def:codomain}\n  Given a \\mynameref{def:morphism} $f: a \\to b$, the\n  \\mynameref{def:object} $b$ is called codomain and denoted as $\\cod f$.\n\\end{definition}\n\n\\mynameref{def:morphism}s have several properties. \\footnote{The\n  properties don't have any proof and postulated as axioms}\n\\begin{axiom}[Composition]\n  \\label{axm:composition}\n  If we have 3 \\mynameref{def:object}s $a, b$ and $c$ and 2\n  \\mynameref{def:morphism}s \n  \\[\n  f_{ab} : a \\rightarrow b\n  \\]\n  and \n  \\[\n  f_{bc} : b \\rightarrow c\n  \\]\n  then there exists \\mynameref{def:morphism} \n  \\[\n  f_{ac} : a \\rightarrow c\n  \\]\n  such that\n  \\[\n  f_{ac} = f_{bc} \\circ f_{ab}\n  \\]\n\\end{axiom}\n\n\\begin{remark}[Composition]\n  \\label{rem:composition}\n  The equation\n  \\[\n  f_{ac} = f_{bc} \\circ f_{ab}\n  \\]\n  means that we apply $f_{ab}$ first and then we apply $f_{bc}$ to the\n  result of the application i.e. if our objects are sets and $x \\in a$\n  then \n  \\[\n  f_{ac} ( x ) = f_{bc} ( f_{ab} ( x ) ),\n  \\]\n  where $f_{ab} ( x ) \\in b$.\n\\end{remark}\n\n\\begin{axiom}[Associativity]\n  \\label{axm:associativity}\n  The \\mynameref{def:morphism}s \\mynameref{axm:composition}s should\n  follow associativity property:\n  \\[\n  f_{ce} \\circ (f_{bc} \\circ f_{ab}) = (f_{ce} \\circ f_{bc}) \\circ\n  f_{ab} = f_{ce} \\circ f_{bc} \\circ f_{ab}.\n  \\]\n\\end{axiom}\n\n\\begin{definition}[Identity morphism]\n  \\label{def:id}\n  For every \\mynameref{def:object} $a$ we define a special\n  \\mynameref{def:morphism} $\\idm{a} : a \\rightarrow a$ with the\n  following properties: $\\forall f_{ab} : a \\rightarrow b$\n  \\begin{equation}\n    \\idm{a} \\circ f_{ab} = f_{ab}\n    \\label{eq:leftid}\n  \\end{equation}\n  and\n  $\\forall f_{ba} : b \\rightarrow a$\n  \\begin{equation}\n    f_{ba} \\circ \\idm{a}  = f_{ba}.\n    \\label{eq:rightid}\n  \\end{equation}\n  This morphism is called as \\textit{identity morphism}.\n\\end{definition}\n\nNote that \\mynameref{def:id} is unique, see\n\\mynameref{thm:identity_unique} below.\n\n\\begin{definition}[Commutative diagram]\n  A commutative diagram is a diagram of \\mynameref{def:object}s (also known as\n  vertices) and \\mynameref{def:morphism}s (also known as arrows or\n  edges) such that all directed paths in the diagram with the same\n  start and endpoint lead to the same result by composition\n  \\label{def:commutative_diagram}\n\n  The following diagram commutes if $f_{ab} = f_{cb} \\circ f_{ac}$.\n\n  \\begin{center}\n    \\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]\n      \\matrix (m) [matrix of math nodes, row sep=3em,\n        column sep=2.5em, text height=1.5ex, text depth=0.25ex]\n              { a& & b \\\\\n                & c & \\\\ };\n              %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n              \\path[->]\n              (m-1-1) edge node[description] {$ f_{ab} $} (m-1-3)\n              edge node[description] {$  f_{ac} $} (m-2-2)\n              (m-2-2) edge node[description] {$  f_{cb} $} (m-1-3);\n    \\end{tikzpicture}\n  \\end{center}\n\\end{definition}\n\n\n\\begin{remark}[Class of Morphisms]\n  \\label{rem:morphclass}\n  The \\mynameref{def:class} of \\mynameref{def:morphism}s will be marked as \n  $\\cathom{C}$ (see \\cref{fig:class_of_morphisms})\n\\end{remark}\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    \\node at (0,4) {$\\cat{C}$};\n    \n    \\node[ele,label=left:$a$] (a) at (0,2) {};    \n    \\node[ele,label=left:$b$] (b) at (0,1) {};    \n    \\node[ele,label=right:$c$] (c) at (2,2) {};\n    \\node[ele,label=right:$d$] (d) at (2,1) {};\n    \n    \\node[draw,fit= (a) (b) (c) (d),minimum width=4cm, minimum\n      height=4cm] {}  ;\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to\n    node[pos=0.5,above]{$f$} (c); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (b) to\n    node[pos=0.5,left]{$g$} (a); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (b) to\n    node[pos=0.5,right]{$h$} (c); \n\n\n  \\end{tikzpicture}\n  \\caption{Class of morphisms $\\cathom{C}=\\{f,g,h\\}$, where $h = f\n    \\circ g$}\n  \\label{fig:class_of_morphisms}\n\\end{figure}\n\n\n\\begin{definition}[Monomorphism]\n  \\label{def:monomorphism}\n  If $\\forall g_1, g_2$ the equation \n  \\[\n  f \\circ g_1 = f \\circ g_2\n  \\]\n  leads to \n  \\[\n  g_1 = g_2\n  \\]\n  then $f$ is called \\textit{monomorphism}.\n\\end{definition}\n\n\\begin{definition}[Epimorphism]\n  \\label{def:epimorphism}\n  If $\\forall g_1, g_2$ the equation \n  \\[\n  g_1 \\circ f = g_2 \\circ f\n  \\]\n  leads to \n  \\[\n  g_1 = g_2\n  \\]\n  then $f$ is called \\textit{epimorphism}.\n\\end{definition}\n\n\\begin{definition}[Isomorphism]\n\\label{def:isomorphism} \nA \\mynameref{def:morphism} $f: a \\to b$ is called \\textit{isomorphism} if\n$\\exists g: b \\to a$ such that $f \\circ g = \\idm{a}$ \nand $g \\circ f = \\idm{b}$.  \nIf there is an isomorphism $f$ between objects $a$ and $b$\nthen it is denoted as $a \\cong_f b$. \n\\end{definition}\n\n\\begin{remark}[Isomorphism]\n\\label{rem:isomorphism}\nThere are can be many different \\mynameref{def:isomorphism}s between 2\n\\mynameref{def:object}s. \n\nIf there is an unique isomorphism between 2 objects then the objects\ncan be treated as the same object.\n\\end{remark}\n\n\\subsection{Category}\n\n\\begin{definition}[Category]\n  \\label{def:category}\n  A category $\\cat{C}$ consists of \n  \\begin{itemize}\n  \\item \\mynameref{def:class} of\n    \\mynameref{def:object}s $\\catob{C}$\n  \\item \\mynameref{def:class} of \\mynameref{def:morphism}s $\\cathom{C}$\n    defined for $\\catob{C}$, i.e. each morphism $f_{ab}$ from \n    $\\cathom{C}$ has both source\n    $a$ and target $b$ from $\\catob{C}$\n  \\end{itemize}\n  For any \\mynameref{def:object} $a$ there should be unique\n  \\mynameref{def:id} $\\idm{a}$. Any morphism should satisfy\n  \\mynameref{axm:composition} and \\mynameref{axm:associativity}. See\n  \\cref{fig:category}   \n\\end{definition}\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    \\node at (0,4.5) {$\\cat{C}$};\n    \n    \\node[ele,label=left:$a$] (a) at (0,2) {};    \n    \\node[ele,label=left:$b$] (b) at (0,1) {};    \n    \\node[ele,label=right:$c$] (c) at (2,2) {};\n    \\node[ele,label=right:$d$] (d) at (2,1) {};\n    \n    \\node[draw,fit= (a) (b) (c) (d),minimum width=5cm, minimum\n      height=5cm] {}  ;\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to\n    node[pos=0.5,above]{$f$} (c); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (b) to\n    node[pos=0.5,left]{$g$} (a); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (b) to\n    node[pos=0.5,right]{$h$} (c);\n\n    \\draw (a) to [out=45,in=135,looseness=20] node[above] {$\\idm{a}$} (a);\n    \\draw (b) to [out=-45,in=-135,looseness=20] node[below] {$\\idm{b}$} (b);\n    \\draw (c) to [out=45,in=135,looseness=20] node[above] {$\\idm{c}$} (c);\n    \\draw (d) to [out=-45,in=-135,looseness=20] node[below] {$\\idm{d}$} (d);\n\n  \\end{tikzpicture}\n  \\caption{Category $\\cat{C}$. It consists of 4 objects\n    $\\catob{C} = \\{a,b,c,d\\}$ and 7 morphisms\n    $\\catob{C} = \\{f,g,h = f \\circ g, \\idm{a}, \\idm{b},\n    \\idm{c}, \\idm{d}\\}$}\n  \\label{fig:category}\n\\end{figure}\n\n\\begin{definition}[Set of morphisms]\n\\label{def:morphism_set}\n  The set of morphisms between objects $a$ and $b$ in the $\\cat{C}$\n  will be denoted as $\\hom_{\\cat{C}}(a, b)$\n\\end{definition}\n\nThe \\mynameref{def:category} can be considered as a way to represent a\nstructured data. \\mynameref{def:morphism}s are the ones which form the\nstructure. \n\n\\begin{definition}[Opposite category]\n\\label{def:op_category}\n\\index{Category!opposite}\n\\index{Category!dual}\nIf $\\cat{C}$ is a \\mynameref{def:category} then opposite (or dual) category\n$\\cat{C}^{op}$ is constructed in the following way: \\mynameref{def:object}s\nare the same, but the \\mynameref{def:morphism}s are inverted i.e. \nif $f \\in \\cathom{C}$ and $\\dom f = a, \\cod f = b$, then the\ncorresponding morphism $f^{op} \\in \\cathom{C^{op}}$ has $\\dom f^{op} =\nb, \\cod f^{op} = a$ (see \\cref{fig:op_category})\n\\end{definition}\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    \\node at (0,4.5) {$\\cat{C}$};\n    \n    \\node[ele,label=left:$a$] (a) at (0,2) {};    \n    \\node[ele,label=left:$b$] (b) at (0,1) {};    \n    \\node[ele,label=right:$c$] (c) at (2,2) {};\n    \\node[ele,label=right:$d$] (d) at (2,1) {};\n    \n    \\node[draw,fit= (a) (b) (c) (d),minimum width=5cm, minimum\n      height=5cm] {}  ;\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (c) to\n    node[pos=0.5,above]{$f^{op}$} (a); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to\n    node[pos=0.5,left]{$g^{op}$} (b); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (c) to\n    node[pos=0.5,right]{$h^{op}$} (b);\n\n    \\draw (a) to [out=45,in=135,looseness=20] node[above] {$\\idm{a}$} (a);\n    \\draw (b) to [out=-45,in=-135,looseness=20] node[below] {$\\idm{b}$} (b);\n    \\draw (c) to [out=45,in=135,looseness=20] node[above] {$\\idm{c}$} (c);\n    \\draw (d) to [out=-45,in=-135,looseness=20] node[below] {$\\idm{d}$} (d);\n\n  \\end{tikzpicture}\n  \\caption{Opposite category $C^{op}$ to the category from\n    \\cref{fig:category} . It consists of 4 objects\n    $\\catob{C^{op}} = \\catob{C} = \\{a,b,c,d\\}$ and 7 morphisms\n    $\\cathom{C^{op}} = \\{f^{op},g^{op},h^{op} = g^{op} \\circ\n    f^{op}, \\idm{a}, \\idm{b}, \n    \\idm{c}, \\idm{d}\\}$}\n  \\label{fig:op_category}\n\\end{figure}\n\n\\begin{remark}{Composition on $C^{op}$}\n\\label{rem:op_composition}\n\\index{Composition!opposite category}\nAs you can see from \\cref{fig:op_category} the\n\\mynameref{axm:composition} is reverted for\n\\mynameref{def:op_category}. If $f,g,h = f \\circ g \\in\n\\cathom{C}$ then $f \\circ g$ translated into $g^{op} \\circ\nf^{op}$ in opposite category.\n\\end{remark}\n\n\\begin{definition}[Small category]\n\\label{def:small_category}\n\\index{Category!small}\nA category $\\cat{C}$ is called \\textit{small} if both $\\catob{C}$ and\n$\\cathom{C}$ are \\nameref{def:set}s\n\\end{definition}\n\n\\begin{definition}[Large category]\n\\label{def:large_category}\n\\index{Category!large}\nA category $\\cat{C}$ is not \\mynameref{def:small_category} then it is\ncalled \\textit{large}. The example of large category is\n\\mynameref{def:setcategory} \n\\end{definition}\n\n\\section{\\textbf{Set} category example}\n\nThere are several examples of categories that will also be used later\n\n\\begin{definition}[Set]\n  \\label{def:set}\n  Set is a collection of distinct object. The objects are called the\n  elements of the set.\n\\end{definition}\n\n\\begin{definition}[Binary relation]\n  \\label{def:binary_relation}\n  If $A$ and $B$ are 2 \\mynameref{def:set}s then a subset of $A \\times B$ is\n  called binary relation $R$ between the 2 sets, i.e. $R \\subset A \\times B$.\n\\end{definition}\n\n\\begin{definition}[Function]\n  \\label{def:function}\n  Function $f$ is a special type of \\mynameref{def:binary_relation}. I.e.\n  if $A$ and $B$ are 2 \\mynameref{def:set}s then a subset of $A \\times B$ is\n  called function $f$ between the 2 sets if $\\forall a \\in A \\, \\exists!\n  b \\in B$ such that $(a,b) \\in f$. In other words function definition\n  does not allow ``multi value''.\n\\end{definition}\n\n\\begin{definition}[Cartesian product]\n  \\label{def:cartesian_product}\n  If $A$ and $B$ are two sets then we can define a new set $A \\times B\n  = \\left\\{(a,b)|a \\in A, b \\in B\\right\\}$ that is called as the\n  \\textit{cartesian product}.\n\\end{definition}\n\n\n\\begin{definition}[\\textbf{Set} category]\n  \\label{def:setcategory}\n  \\index{Object!\\textbf{Set} category}\n  \\index{Morphism!\\textbf{Set} category}\n  \\index{Category!\\textbf{Set}}\n  In the set category we consider a \\mynameref{def:set} of\n  \\mynameref{def:set}s where \n  \\mynameref{def:object}s are the \\mynameref{def:set}s and\n  \\mynameref{def:morphism}s are \\mynameref{def:function}s between the\n  sets.\n\n  The \\mynameref{def:id} is trivial function such that $\\forall x \\in\n  X: \\idm{X}(x) = x$.\n\n  In general case when we say \\textbf{Set} category we assume the set\n  of all sets. But the result is inconsistent because famous Russell's\n  paradox \\cite{wiki:russell_paradox} can be applied. To avoid such\n  situations we consider a limitation that is applied on our\n  construction, for instance \n  ZFC \\cite{wiki:zfc}. If we apply the limitation we have that set of\n  all sets is not a set itself and as result the  \\textbf{Set}\n  category is a \\mynameref{def:large_category}\n  \\index{Category!large}\n\\end{definition}\n\n\\begin{remark}[Set vs Category]\n  \\label{rem:set_vs_category}\n  There is an interesting relation between sets and categories. In both\n  we consider objects(sets) and relations between\n  them(morphisms/functions). \n\n  In the set theory we can get info about functions by looking inside\n  the objects(sets) aka use ``microscope'' \\cite{bib:milewski2018category} \n\n  Contrary in the category theory we initially don't have any info about object\n  internal structure but can get it using the relation between the\n  objects i.e. using \\mynameref{def:morphism}s. In other words we can use\n  ``telescope'' \\cite{bib:milewski2018category}  there.\n\\end{remark}\n\n\\begin{definition}[Categorical approach]\n\\label{def:categorical_approach}\nThe description of a system via its communications we will call as\n\\textit{categorical approach}.\n\nThis description is contrary to an ordinary system description via its\ninternal structure.\n\\end{definition}\n\n\\begin{definition}[Singleton]\n\\label{def:singleton_set} \nThe \\textit{singleton} is a \\mynameref{def:set} with only one element.\n\\end{definition}\n\n\\begin{example}[Domain]\n  \\label{ex:domain_set}\n  Given a function $f: X \\to Y$, the set $X$ is the domain. I.e. $\\dom\n  f = X$\n\\end{example}\n\n\\begin{example}[Codomain]\n  \\label{ex:codomain_set}\n  Given a function $f: X \\to Y$, the set $Y$ is the codomain. I.e.\n  $\\cod f = Y$\n\\end{example}\n\n\n\\begin{definition}[Surjection]\n  \\label{def:surjection}\n  The function $f: X \\rightarrow Y$ is surjective (or onto) if\n  $\\forall y \\in Y$, $\\exists x \\in X$ such that\n  $f\\left(x\\right) = y$ (see \\cref{fig:surjection,fig:bijection}).\n\\end{definition}\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    \\node at (0,5) {$X$};\n    \\node at (4,5) {$Y$};\n    \n    \\node[ele,label=left:$x_1$] (x1) at (0,4) {};    \n    \\node[ele,label=left:$x_2$] (x2) at (0,3) {};    \n    \\node[ele,label=left:$x_3$] (x3) at (0,2) {};\n    \\node[ele,label=left:$x_4$] (x4) at (0,1) {};\n\n    \\node[ele,,label=right:$y_1$] (y1) at (4,4) {};\n    \\node[ele,,label=right:$y_2$] (y2) at (4,3) {};\n    \\node[ele,,label=right:$y_3$] (y3) at (4,2) {};\n\n    \\node[draw,fit= (x1) (x2) (x3) (x4),minimum width=2cm] {} ;\n    \\node[draw,fit= (y1) (y2) (y3),minimum width=2cm] {} ;  \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (x1) -- (y2);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x2) -- (y1);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x3) -- (y3);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x4) -- (y3);\n  \\end{tikzpicture}\n  \\caption{A surjective (non-injective) function from domain $X$ to\n    codomain $Y$ }\n  \\label{fig:surjection}\n\\end{figure}\n\n\n\\begin{remark}[Surjection vs Epimorphism]\n  \\label{rem:surjection_epimorphism}\n  \\mynameref{def:surjection} and \\mynameref{def:epimorphism} are\n  related each other. Consider a non-surjective function $f: X\n  \\rightarrow Y' \\subset Y$ (see \\cref{fig:surjection_epimorphism}). One can\n  conclude that there is not an \\mynameref{def:epimorphism} because  \n  $\\exists g_1: Y' \\to Y'$ and  $g_2 : Y \\to Y$ such\n  that $g_1 \\ne g_2$ because they operates on different\n  \\mynameref{def:domain}s but from other hand $g_1(Y') = g_2(Y')$. For\n  instance we can choose $g_1 = \\idm{Y'}, g_2=\\idm{Y}$. As\n  soon as $Y'$ is \\mynameref{def:codomain} of $f$ we always have\n  $g_1(f(X)) = g_2(F(X))$.\n  \n  As result we can say that an \\mynameref{def:surjection} is a\n  \\mynameref{def:epimorphism} in the \\textbf{Set} category. Moreover\n  there is a proof \n  \\cite{bib:proofwiki:Surjection_iff_Epimorphism_in_Category_of_Sets}\n  of that fact.\n\n\\end{remark}\n\n\n% https://tex.stackexchange.com/questions/19987/\n% drawing-a-bijective-map-with-tikz \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    \\node at (0,5) {$X$};\n    \\node at (4,5) {$Y$};\n    \\node at (5.5,3.5) {$Y'$};\n    \n    \\node[ele,label=left:$x_1$] (x1) at (0,4) {};    \n    \\node[ele,label=left:$x_2$] (x2) at (0,3) {};    \n    \\node[ele,label=left:$x_3$] (x3) at (0,2) {};\n    \\node[ele,label=left:$x_4$] (x4) at (0,1) {};\n\n    \\node[ele,,label=right:$y_1$] (y1) at (4,4) {};\n    \\node[ele,,label=right:$y_2$] (y2) at (4,3) {};\n    \\node[ele,,label=right:$y_3$] (y3) at (4,2) {};\n    \\node[ele,,label=right:$y_4$] (y4) at (4,1) {};\n    \n    \\node[draw,fit= (x1) (x2) (x3) (x4),minimum width=2cm] {} ;\n    \\node[draw,fit= (y1) (y2) (y3) (y4),minimum width=2cm] {} ;\n    \\node[draw,fit= (y1) (y2) (y3),minimum width=2cm] {} ;\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (x1) -- (y2);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x2) -- (y1);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x3) -- (y3);\n\n  \\end{tikzpicture}\n  \\caption{A non-surjective function $f$ from domain $X$ to\n    codomain $Y' \\subset Y$.\n    $\\exists g_1: Y' \\rightarrow Y', g_2: Y \\rightarrow Y$ such that\n    $g_1(Y') = g_2(Y')$, but as soon as $Y' \n    \\ne Y$ we have $g_1 \\ne g_2$. Using the fact that $Y'$ is codomain\n    of $f$ we got $g_1 \\circ f = g_2 \\circ f$.\n    I.e. the function $f$ is not epimorphism. }\n  \\label{fig:surjection_epimorphism}\n\\end{figure}\n\n\n\\begin{definition}[Injection]\n  \\label{def:injection}\n  The function $f: X \\rightarrow Y$ is injective (or one-to-one function) if\n  $\\forall x_1, x_2 \\in X$, such that $x_1 \\ne x_2$ then\n  $f\\left(x_1\\right) \\ne f\\left(x_2\\right)$ (see\n  \\cref{fig:injection,fig:bijection}).  \n\\end{definition}\n\n% https://tex.stackexchange.com/questions/19987/\n% drawing-a-bijective-map-with-tikz \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    \\node at (0,5) {$X$};\n    \\node at (4,5) {$Y$};\n    \n    \\node[ele,label=left:$x_1$] (x1) at (0,4) {};    \n    \\node[ele,label=left:$x_2$] (x2) at (0,3) {};    \n    \\node[ele,label=left:$x_3$] (x3) at (0,2) {};\n    \\node[ele,label=left:$x_4$] (x4) at (0,1) {};\n\n    \\node[ele,,label=right:$y_1$] (y1) at (4,4) {};\n    \\node[ele,,label=right:$y_2$] (y2) at (4,3) {};\n    \\node[ele,,label=right:$y_3$] (y3) at (4,2) {};\n    \\node[ele,,label=right:$y_4$] (y4) at (4,1) {};\n\n    \\node[draw,fit= (x1) (x2) (x3) (x4),minimum width=2cm] {} ;\n    \\node[draw,fit= (y1) (y2) (y3) (y4),minimum width=2cm] {} ;  \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (x1) -- (y2);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x2) -- (y1);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x3) -- (y3);\n  \\end{tikzpicture}\n  \\caption{A injective (non-surjective) function from domain $X$ to\n    codomain $Y$ }\n  \\label{fig:injection}\n\\end{figure}\n\n\n\\begin{remark}[Injection vs Monomorphism]\n  \\label{rem:injection_monomorphism}\n  \\mynameref{def:injection} and \\mynameref{def:monomorphism} are\n  related each other. Consider a non-injective function $f: X\n  \\rightarrow Y$ (see \\cref{fig:injection_monomorphism}). One can\n  conclude that it is not monomorphism because $\\exists g_1, g_2$ such\n  that $g_1 \\ne g_2$ and $f(g_1(a_1)) = y_3 = f(g_2(b_1))$.\n\n  As result we can say that an \\mynameref{def:injection} is a\n  \\mynameref{def:monomorphism} in \\textbf{Set} category. Moreover\n  there is a proof \n  \\cite{bib:proofwiki:Injection_iff_Monomorphism_in_Category_of_Sets}\n  of that fact.\n\\end{remark}\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    \\node at (0,5) {$A$};\n    \\node at (0,0) {$B$};\n    \\node at (4,5) {$X$};\n    \\node at (8,5) {$Y$};\n\n    \\node[ele,label=left:$a_1$] (a1) at (0,4) {};\n    \\node[ele,label=left:$a_2$] (a2) at (0,3) {};    \n\n    \\node[ele,label=left:$b_1$] (b1) at (0,2) {};    \n    \\node[ele,label=left:$b_2$] (b2) at (0,1) {};    \n\n    \n    \\node[ele,label=left:$x_1$] (x1) at (4,4) {};    \n    \\node[ele,label=left:$x_2$] (x2) at (4,3) {};    \n    \\node[ele,label=left:$x_3$] (x3) at (4,2) {};\n    \\node[ele,label=left:$x_4$] (x4) at (4,1) {};\n\n    \\node[ele,,label=right:$y_1$] (y1) at (8,4) {};\n    \\node[ele,,label=right:$y_2$] (y2) at (8,3) {};\n    \\node[ele,,label=right:$y_3$] (y3) at (8,2) {};\n    \\node[draw,fit= (a1) (a2),minimum width=2cm] {} ;\n    \\node[draw,fit= (b1) (b2),minimum width=2cm] {} ;\n\n    \\node[draw,fit= (x1) (x2) (x3) (x4),minimum width=2cm] {} ;\n    \\node[draw,fit= (y1) (y2) (y3),minimum width=2cm] {} ;  \n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (x1) -- (y2);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x2) -- (y1);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x3) -- (y3);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x4) -- (y3);\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (a1) -- (x3);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (a2) -- (x3);\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (b1) -- (x4);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (b2) -- (x4);\n\n  \\end{tikzpicture}\n  \\caption{A non-injective function $f$ from domain $X$ to\n    codomain $Y$. $\\exists g_1: A \\rightarrow X, g_2: B\n    \\rightarrow X$ such that $g_1 \\ne g_2$ but $f\n    \\circ g_1 = f \\circ g_2$. I.e. the function $f$ is not monomorphism. }\n  \\label{fig:injection_monomorphism}\n\\end{figure}\n\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    % the texts\n    \\node at (0,5) {$X$};\n    \\node at (4,5) {$Y$};\n    \n    \\node[ele,label=left:$x_1$] (x1) at (0,4) {};    \n    \\node[ele,label=left:$x_2$] (x2) at (0,3) {};    \n    \\node[ele,label=left:$x_3$] (x3) at (0,2) {};\n    \\node[ele,label=left:$x_4$] (x4) at (0,1) {};\n\n    \\node[ele,,label=right:$y_1$] (y1) at (4,4) {};\n    \\node[ele,,label=right:$y_2$] (y2) at (4,3) {};\n    \\node[ele,,label=right:$y_3$] (y3) at (4,2) {};\n    \\node[ele,,label=right:$y_4$] (y4) at (4,1) {};\n\n    \\node[draw,fit= (x1) (x2) (x3) (x4),minimum width=2cm] {} ;\n    \\node[draw,fit= (y1) (y2) (y3) (y4),minimum width=2cm] {} ;  \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (x1) -- (y4);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x2) -- (y2);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x3) -- (y1);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (x4) -- (y3);\n  \\end{tikzpicture}\n  \\caption{An injective and surjective function (bijection)}\n  \\label{fig:bijection}\n\\end{figure}\n\n\\begin{definition}[Bijection]\n  \\label{def:bijection}\n  The function $f: X \\rightarrow Y$ is bijective (or one-to-one\n  correspondence) if it is an \\mynameref{def:injection} and a\n  \\mynameref{def:surjection} (see \\cref{fig:bijection}). \n\\end{definition}\n\nThere is a question what is the categorical analog of a single\n\\mynameref{def:set}. Main characteristic of a category is a structure\nbut the set by definition does not have a structure. Which category\ndoes not have any structure? The answer is\n\\mynameref{def:discrete_category}. \n\n\\begin{definition}[Discrete category]\n  \\label{def:discrete_category}\n  Discrete category is a \\mynameref{def:category} where\n  \\mynameref{def:morphism}s are only \\mynameref{def:id}s.\n\\end{definition}\n  \n\\section{Programming languages examples}\n\nIn the programming languages we consider types as\n\\mynameref{def:object}s and functions as\n\\mynameref{def:morphism}s. The critical requirements for such\nconsideration is that the functions have to be pure functions (without\nside effects). This requirement mainly is satisfied by functional\nlanguages such as Haskell and Scala. From other side the functional\nlanguages use lazy evaluation to improve their performance. The laziness\ncan also make category theory axiom invalid (see\n\\mynameref{rem:hask_lazy_eval}). \n\nStrictly speaking neither Haskell (pure functional language) nor C++\ncan be considered as a category in general. For the first approximation\na functional language (Haskell, Scala) can be considered as a\ncategory if we avoid to use functions with side effects (mainly for\nScala) and use strict (for both Haskell and Scala) evaluations. Take\nthe fact into consideration and define categories for 3 languages\n\n\\begin{definition}[\\textbf{Hask} category]\n\\label{def:haskcategory}\nThe objects in the \\textbf{Hask} category are Haskell types and\nmorphisms are functions\n\\end{definition}\n\n\\begin{definition}[Pure function]\n\\label{def:pure_function}\nThe function is pure if it's execution give the same results\nindependently from the environment. \n\\end{definition}\n\n\\begin{definition}[\\textbf{Scala} category]\n\\label{def:scalacategory}\nThe objects in the \\textbf{Scala} category are Scala types and\nmorphisms are functions. We don't define functions that have a state\nin the category. I.e. the functions are \\mynameref{def:pure_function}s. \n\\end{definition}\n\n\\begin{definition}[\\textbf{C++} category]\n\\label{def:cppcategory}\nThe objects in the \\textbf{C++} category are Scala types and\nmorphisms are functions. We don't define functions that have a state\nin the category. I.e. the functions are \\mynameref{def:pure_function}s. \n\\end{definition}\n\n\nIn any case we can construct a simple toy category that can be easy\nimplemented in any language. Particularly we will look into category\nwith 3 objects that are types: Int, Bool, String. There are also\nseveral functions between them (see \\cref{fig:pl_example}).   \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    % the texts    \n    \\node[ele,label=right:Int] (int) at (6,4) {};    \n    \\node[ele,label=right:Bool] (bool) at (6,0) {};    \n    \\node[ele,label=left:String] (string) at (0,0) {};\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (int) to\n    node[right]{isEven} (bool); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (string) to\n    node[pos=0.5,sloped,above]{stringLength} (int); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (string) to\n    node[pos=0.5,sloped,above]{isStringLengthEven} (bool); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (string) -- (bool);\n    \\draw (int) to [out=45,in=135,looseness=50] node[above]\n          {$id_{Int}$} (int); \n    \\draw (string) to [out=-45,in=-135,looseness=50] node[below]\n          {$id_{String}$} (string); \n    \\draw (bool) to [out=-45,in=-135,looseness=50] node[below]\n          {$id_{Bool}$} (bool); \n\n  \\end{tikzpicture}\n  \\caption{Programming language category example. Objects are types: Int,\n    Bool, String. Morphisms are several functions}\n  \\label{fig:pl_example}\n\\end{figure}\n\n\n\\subsection{\\textbf{Hask} toy category}\n\\begin{example}[\\textbf{Hask} toy category]\n  \\label{ex:haskcategory}\n  \\index{Object!\\textbf{Hask} example}\n  \\index{Morphism!\\textbf{Hask} example}\n  Types in Haskell are considered as \\mynameref{def:object}s.\n  Functions are considered as \\mynameref{def:morphism}s.\n  We are going to implement \\mynameref{def:category} from\n  \\cref{fig:pl_example}.\n\n  The function \\mintinline{haskell}{isEven}\n  converts\\mintinline{haskell}{Int} type \n  into Bool.\n  \\begin{minted}{haskell}\n    isEven :: Int -> Bool\n    isEven x = x `mod` 2 == 0\n  \\end{minted}\n\n  There is also \\mynameref{def:id} that is defined as follows\n  \\begin{minted}{haskell}\n    id :: a -> a\n    id x = x\n  \\end{minted}\n\n  If we have an additional function\n  \\begin{minted}{haskell}\n    stringLength :: String -> Int\n    stringLength x = length x\n  \\end{minted}\n  then we can create a \\mynameref{axm:composition}\n  \\begin{minted}{haskell}\n    isStringLengthEven :: String -> Bool\n    isStringLengthEven = isEven . stringLength\n  \\end{minted}\n\n  %% If we consider pure (without effects) functions then\n  %% \\mynameref{axm:associativity} is also satisfied.\n\\end{example}\n\n%http://math.andrej.com/2016/08/06/hask-is-not-a-category/\n\\begin{remark}[Haskell lazy evaluation]\n  \\label{rem:hask_lazy_eval}\n  Each Haskell type has a special value $\\bot$. The fact that the\n  value and lazy evaluations are part of the language, make several\n  category law invalid, for instance \n  \\mynameref{def:id} behaviour become invalid in specific cases:\n\n  The following code\n  \\begin{minted}{haskell}\n    seq undefined True\n  \\end{minted}\n  produces \\textit{undefined}\n  But the following\n  \\begin{minted}{haskell}\n    seq (id.undefined) True\n    seq (undefined.id) True\n  \\end{minted}\n  produces \\textit{True} in both cases.\n  As result we have\n  (we cannot compare compare functions in Haskell, but if we\n  could we can get the following)\n  \\begin{minted}{haskell}\n    id . undefined /= undefined\n    undefined . id /= undefined,\n  \\end{minted}\n  i.e. \\eqref{eq:leftid} and\n  \\eqref{eq:rightid} are not satisfied.  \n\\end{remark}\n\n\\subsection{\\textbf{C++} toy category}\n\\begin{example}[\\textbf{C++} toy category]\n  \\label{ex:cppcategory}\n  \\index{Object!\\textbf{C++} example}\n  \\index{Morphism!\\textbf{C++} example}\n  We will use the same trick as in \\mynameref{ex:haskcategory} and\n  will assume \n  types in C++ as \\mynameref{def:object}s, \n  functions as \\mynameref{def:morphism}s.\n  We also are going to implement\n  \\mynameref{def:category} from \\cref{fig:pl_example}.\n\n\n  We  also define 2 functions:\n  \\begin{minted}{c++}\n    auto isEven = [](int x) { \n      return x % 2 == 0; \n    };\n\n    auto stringLength = [](std::string s) { \n      return static_cast<int>(s.size()); \n    };\n  \\end{minted}\n\n  Composition can be defined as follows:\n  \\begin{minted}{c++}\n    // h = g . f\n    template <typename A, typename B> \n    auto compose(A g, B f) {\n      auto h = [f, g](auto a) {\n        auto b = f(a);\n        auto c = g(b);\n        return c;\n      };\n      return h;\n    };\n  \\end{minted}\n\n  The \\mynameref{def:id}:\n  \\begin{minted}{c++}\n    auto id = [](auto x) { return x; };\n  \\end{minted}\n\n  The usage examples are the following:\n  \\begin{minted}{c++}\n    auto isStringLengthEven = compose<>(isEven, stringLength);\n\n    auto isStringLengthEvenL = compose<>(id, isStringLengthEven);\n\n    auto isStringLengthEvenR = compose<>(isStringLengthEven, id);  \n  \\end{minted}\n\n  Such construction will always provides us the category as soon as we\n  use pure function (functions without effects).\n\\end{example}\n\n\\subsection{\\textbf{Scala} toy category}\n\\begin{example}[\\textbf{Scala} toy category]\n  \\label{ex:scalacategory}\n  \\index{Object!\\textbf{Scala} example}\n  \\index{Morphism!\\textbf{Scala} example}\n\n  We will use the same trick as in \\mynameref{ex:haskcategory} and\n  will assume \n  types in Scala as \\mynameref{def:object}s, \n  functions as \\mynameref{def:morphism}s.\n  We also are going to implement\n  \\mynameref{def:category} from \\cref{fig:pl_example}.\n\n  \\begin{minted}{scala}\n    object Category {\n      def id[A]: A => A = a => a\n      def compose[A, B, C](g: B => C, f: A => B): \n          A => C = g compose f \n      \n      val isEven = (i: Int) => i % 2  == 0\n      val stringLength = (s: String) => s.length\n      val isStringLengthEven = (s: String) => \n          compose(isEven, stringLength)(s)\n    }\n  \\end{minted}\n\n  The usage example is below\n  \\begin{minted}{scala}\n    \n    class CategorySpec extends Properties(\"Category\") {\n      import Category._\n      import Prop.forAll\n      \n      property(\"composition\") = forAll { (s: String) =>\n        isStringLengthEven(s)  == isEven(stringLength(s))\n      }\n      \n      property(\"right id\") = forAll { (i: Int) =>\n        isEven(i)  == compose(isEven, id[Int])(i)\n      }\n      \n      property(\"left id\") = forAll { (i: Int) =>\n        isEven(i)  == compose(id[Boolean], isEven)(i)\n      }\n    }\n  \\end{minted}\n\\end{example}\n\n\n\\section{Quantum mechanics examples}\nThe most critical property of quantum system is the superposition\nprinciple. The \\mynameref{def:setcategory} cannot be used for it\nbecause it does not satisfy the principle. but a simple modification\nof the \\textbf{Set} category does. \n\\begin{definition}[\\textbf{Rel} category]\n  \\label{def:relcategory}\n  \\index{Object!\\textbf{Rel} category}\n  \\index{Morphism!\\textbf{Rel} category}\n  We will consider a set of sets (same as \\mynameref{def:setcategory})\n  i.e. \\mynameref{def:set}s as \\mynameref{def:object}s. Instead of\n  \\mynameref{def:function}s we will use \\mynameref{def:binary_relation}s as\n  \\mynameref{def:morphism}s. \n\n  The \\textbf{Rel} category is similar to the finite dimensional\n  Hilber space especially because it assumes some kind of superposition.\n  Really consider $\\cat{Rel}$ - the \\textbf{Rel} category. $X, Y \\in\n  \\catob{Rel}$ - 2 sets which consists of different elements. Let $f: X\n  \\to X$ - \\mynameref{def:morphism}. Each element $x \\in X$ is\n  mapped to a subset $Y' \\subset Y$. The $Y'$ can be\n  \\mynameref{def:singleton_set}  (in this case no differences with\n  \\mynameref{def:setcategory}) but there can be a situation when $Y'$\n  consists of several elements. In the case we will get some kind of\n  superposition that is analogiest to quantum systems.\n\\end{definition}\n\nIn the quantum mechanics we say about Hilber spaces.\n\\begin{definition}[Hilbert space]\n  \\label{def:hilbert_space} The Hilbert space is a complex vector space\n  with an inner product as a complex number ($\\mathbb{C}$).\n\n  Later we will consider only finite dimensional Hilber spaces.\n  We will denote a Hilbert space of dimensional $n$ as\n  $\\mathcal{H}_n$. Obviously $\\mathcal{H}_1 = \\mathbb{C}$.\n\\end{definition}\n\n\\begin{definition}[Dual space]\n\\label{def:dual_space}\nEach Hilber space $\\mathcal{H}$ has an associated with it dual space\n$\\mathcal{H}^\\ast$ that consists of linear functionals  \n\\end{definition}\n\n\\begin{example}[Dirac notation]\n\\label{ex:dirac_notation}\nConsider a ket-vector $\\ket{\\psi} \\in \\mathcal{H}$. Then the\ncorresponding vector from \\mynameref{def:dual_space} is called\nbra-vector $\\bra{\\psi} \\in \\mathcal{H}^\\ast$. From the definition of\ndual space the bra-vector is a linear functional i.e. \n\\[\n\\bra{\\psi} : \\mathcal{H} \\to \\mathbb{C},\n\\]\n$\\forall \\ket{\\phi} \\in \\mathcal{H}$ we have \n\\(\n\\bra{\\psi}\\left(\\ket{\\phi}\\right) = \\left(\\ket{\\psi}, \\ket{\\phi}\\right)\n\\) - inner product that is often written as $\\bra{\\psi}\\ket{\\phi}$.\n\\end{example}\n\n\nThe\ntransformation between 2 \\mynameref{def:hilbert_space}s that preserves\nthe structure is called \nlinear map or linear transformations.\n\\begin{definition}[Linear map]\n\\label{def:linear_map}\nThe linear map between2 \\mynameref{def:hilbert_space}s $\\mathcal{A}$\nand $\\mathcal{B}$ is a mapping $f: \\mathcal{A} \\to \\mathcal{B}$ that\npreserves additions  \n\\[\nf(a_1 + a_2) = f(a_1) + f(a_2),\n\\]\nand scalar multiplications:\n\\[\nf(c \\cdot a) = c \\cdot f(a)\n\\]\nwhere $a,a_{1,2} \\in \\mathcal{A}$ and $f(a), f(a_{1,2}) \\in \\mathcal{B}$.\n\\end{definition}\n\n\\begin{remark}[Linear map]\n\\label{rem:linear_map} \nNote that \\mynameref{def:linear_map} does not preserve inner product.\nTBD (verify the statement ???)\n\\end{remark}\n\nIf we want to combine 2 Hilbert spaces into one we use a notion of\ndirect sum.\n\\begin{definition}[Direct sum of Hilber spaces]\n  \\label{def:fdhilb_direct_sum}\n  Let $\\mathcal{A}, \\mathcal{B}$ are 2 Hilber spaces. The\n  direct sum $\\mathcal{A} \\oplus \\mathcal{B}$ is defined as follows\n  \\[\n  \\mathcal{A} \\oplus \\mathcal{B} = \\{a \\oplus b | a \\in \\mathcal{A}, b\n  \\in \\mathcal{B}\\}.\n  \\]\n  The inner product is defined as follows\n  \\[\n  \\bra{a_1 \\oplus b_1}\\ket{a_2 \\oplus b_2} =\n  \\bra{a_1}\\ket{a_2} + \\bra{b_1}\\ket{b_2}.\n  \\]\n\\end{definition}\n\n\\begin{definition}[\\textbf{FdHilb} category]\n  \\label{def:fdhilbcategory}\n  \\index{Object!\\textbf{FdHilb} category}\n  \\index{Morphism!\\textbf{FdHilb} category}\n\n  Most common case in quantum mechanics is the case of quantum states\n  in the finite dimensional Hilbert space. We can consider the set of\n  all finite dimensional Hilbert spaces as a category. The\n  \\mynameref{def:object}s in the category are finite dimensional\n  \\mynameref{def:hilbert_space}s and \\mynameref{def:morphism}s are\n  \\mynameref{def:linear_map}s. The category is denoted as\n  \\textbf{FdHilb}. It is very similar to   \\mynameref{def:relcategory}.\n  The brief relation is   described in the\n  \\cref{tab:set_vs_rel_vs_fdhilb}.  \n  \\begin{table}\n    \\centering\n    \\caption{Relations between \\textbf{Set}, \\textbf{Rel} and \\textbf{FdHilb} categories}\n    \\label{tab:set_vs_rel_vs_fdhilb}\n    \\begin{adjustbox}{width=1\\textwidth}\n      \\small\n      \\begin{tabular}{l|l|l|l}\n        \\toprule\n        & \\textbf{Set} & \\textbf{Rel} & \\textbf{FdHilb}\\\\\n        \\midrule\n        \\mynameref{def:object} & \\mynameref{def:set} &\n        \\mynameref{def:set} &\n        finite dimensional \\mynameref{def:hilbert_space}\\\\\n        \\mynameref{def:morphism} & \\mynameref{def:function} &\n          \\mynameref{def:binary_relation} & \n          \\mynameref{def:linear_map}\\\\\n          \\mynameref{def:initial_object} & empty set & empty set & trivial\n          \\mynameref{def:hilbert_space} of dimensional 0 \\\\\n          \\mynameref{def:terminal_object} & \\mynameref{def:singleton_set} &\n          \\mynameref{def:singleton_set} & $\\mathbb{C}$ \\\\\n          \\mynameref{def:product} & \\mynameref{def:cartesian_product} &\n          \\mynameref{def:cartesian_product}& \\mynameref{def:fdhilb_direct_sum} \\\\\n          \\mynameref{def:sum} & \\mynameref{ex:set_sum} &\n          \\mynameref{ex:set_sum} & \\mynameref{def:fdhilb_direct_sum} \\\\\n          \\bottomrule\n      \\end{tabular}\n    \\end{adjustbox}\n  \\end{table}\n\\end{definition}\n\n\\begin{example}[Rabi oscillations]  \n  \\label{ex:rabioscillations}\n  For our example we consider a 2 level atom with states $\\ket{a}$ -\n  excited and $\\ket{b}$ - ground.\n  As soon as we consider a 2-level system we are in the 2 dimensional\n  \\mynameref{def:hilbert_space} i.e. have only one\n  \\mynameref{def:object}. Lets call \n  it as $\\ket{\\psi}$. The category in the example will be called as\n  $\\cat{Rabi}$. I.e. $\\catob{Rabi} = \\mathcal{H}_2\n  \\{\\ket{\\psi}\\}$.  \n\n  The atom interacts with light beam of\n  frequency $\\omega = \\omega_{ab}$. The state of the system is\n  described by the following equation \\cite{bib:quantum_optics_mine}:\n  \\begin{equation}\n    \\ket{\\psi} = \\cos{\\frac{\\omega_R t}{2}} \\ket{a} -\n      i \\sin{\\frac{\\omega_R t}{2}} \\ket{b},\n    \\nonumber\n  \\end{equation}\n  where $\\omega_R$ - Rabi frequency \\cite{bib:quantum_optics_mine}. \n\n  The interaction time $t$ is fixed and corresponds to $\\omega_R t =\n  \\pi$ i.e. the interaction can be described a linear operator $\\hat{L}$.\n  \n  There are 4 different states and as result 4\n  \\mynameref{def:morphism}s:\n  \\begin{eqnarray}\n    \\ket{\\psi}_0 = \\ket{a},\n    \\nonumber \\\\\n    \\ket{\\psi}_1 = \\hat{L} \\ket{\\psi}_0 = -i \\ket{b},\n    \\nonumber \\\\\n    \\ket{\\psi}_2 = \\hat{L}^2 \\ket{\\psi}_0 = - \\ket{a},\n    \\nonumber \\\\\n    \\ket{\\psi}_3 = \\hat{L}^3 \\ket{\\psi}_0 = i \\ket{b},\n    \\nonumber\n  \\end{eqnarray}\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    \\node[ele,label=right:$\\ket{\\psi}$] (0) at (2,2) {};    \n    \n\n    \\draw (0) to [out=45,in=135,looseness=50] node[pos=0.5,above]\n          {$\\hat{L}$} (0);\n    \\draw (0) to [out=45,in=135,looseness=100] node[pos=0.5,above]\n          {$\\hat{L}^2$} (0);\n    \\draw (0) to [out=45,in=135,looseness=150] node[pos=0.5,above]\n          {$\\hat{L}^3$} (0);\n    \\draw (0) to [out=45,in=135,looseness=200] node[pos=0.5,above]\n          {$\\idm{\\ket{\\psi}} = \\hat{L}^4$} (0);\n\n  \\end{tikzpicture}\n  \\caption{Rabi oscillations as a category $\\cat{Rabi}$}\n  \\label{fig:example_quantum}\n\\end{figure}\n\\end{example}\n", "meta": {"hexsha": "a075b12236d5b69e043a01bfa69c27b7f0eaee49", "size": 42854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cattheory/basedefinitions.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/basedefinitions.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/basedefinitions.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.7558799676, "max_line_length": 89, "alphanum_fraction": 0.652867877, "num_tokens": 15128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6601400731443708}}
{"text": "\\chapter{Measurement}\n\n\\paragraph{Quantity, magnitude, and unit}\n\nThe quantity 1 kg has magnitude 1 and unit kg (kilogram).\nThe magnitude is a number.\nThe quantity 2 kg is twice 1 kg.\nThe quantity 10 kg is ten times 1 kg.\n\n\\section{SI units and prefixes}\n\nSI stands for \\emph{syst\\`eme international d'unit\\'es}\n(international system of units).\n\nThe units are grouped into two kinds: base units and derived units.\nBase units don't depend on other units.\nDerived units depend on other units.\nExample base units are kilogram (kg), meter (m), and second (s).\nExample derived units are newton (N, which is \\si{kg.m.s^{-2}})\nand joule (J, which is \\si{N.m}).\n\nA prefix can be put before a unit to enlarge or shrink it.\nExample prefixes are\n\\si{\\micro} (micro, \\(10^{-6}\\)),\nm (milli, \\(10^{-3}\\)),\nk (kilo, \\(10^3\\)),\nM (mega, \\(10^6\\)).\nThe quantities \\SI{1}{kg}, \\SI{1000}{g}, and \\SI{1000000}{mg} are the same quantity.\n\nSome units are rarely used.\nAn example rare unit is megagram (1 million grams).\n\nFor the complete list of SI units and prefixes, search the Internet%\n\\footnote{\\url{https://en.wikipedia.org/wiki/International_System_of_Units\\#Units_and_prefixes}}%\n\\footnote{\\url{https://physics.nist.gov/cuu/Units/units.html}}%\n.\n\n\\paragraph{A psychological effect}\nSomeone sounds heavier in grams than in kilograms.\nFor example, one friend of mine weighs one hundred \\emph{thousand} grams.\nWe compare numbers more easily than we compare units.\n\n\\section{Writing numbers in scientific notation}\n\n% https://en.wikipedia.org/wiki/Significant_figures\nAn example number in scientific notation is \\( 1.23 \\times 10^{50} \\).\nWithout scientific notation, we would need to write out that number with its 47 trailing zeros.\n\nThe number \\( 1.23 \\times 10^{50} \\) has three significant figures.\n\n\\section{Reporting a measurement and its uncertainty}\n\nHow do we measure quantities?\nHow do report a measurement?\n\nEvery measurement has an uncertainty.\nTools have limited precision.\nWe report a measurement by writing \\SI{1.00(5)}{cm} or \\SI[separate-uncertainty]{1.00+-0.05}{cm}\nto mean that the actual quantity is somewhere between 0.95 cm and 1.05 cm.\nWe don't know the actual quantity.\nWe only know that it's between those.\n\n\\section{Sanity check with dimensional analysis}\n\nDimensional analysis can sanity-check a calculation.\nIf the unit is wrong, the calculation is wrong.\nIf the unit is right, the calculation may be right.\n\nDimensional analysis is a test.\nIt can detect falsehood.\nIt can't prove correctness.\n", "meta": {"hexsha": "03feccfbaed9ecc64c662f7e776369503e2fdd8a", "size": 2506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/measurement.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/measurement.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/measurement.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.8055555556, "max_line_length": 97, "alphanum_fraction": 0.7505985634, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519376, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.6601400709499862}}
{"text": "\\section{Distance Metric}\n\\label{sec:dist}\n\nWe represent each context with a high dimensional probability vector\ncalled the substitute vector as described in the previous section.  In\nthis section we compare various distance metrics in this high\ndimensional space with the goal of discovering one that will judge\nvectors that belong to the same syntactic category similar and vectors\nthat belong to different syntactic categories distant.  The distance\nmetrics we have considered are listed in Table~\\ref{tab:metrics}.\n\n\\begin{table}[ht] \\centering\n\\small\n\\begin{tabular}{|lll|}\n\\hline\nCosine($\\mathbf{p}, \\mathbf{q}$) & = & $<\\mathbf{p},\\mathbf{q}> / (\\|\\mathbf{p}\\|_{2} \\|\\mathbf{q}\\|_{2})$ \\\\\nEuclid($\\mathbf{p}, \\mathbf{q}$) & = & $\\|\\mathbf{p} - \\mathbf{q}\\|_{2}$ \\\\\nManhattan($\\mathbf{p}, \\mathbf{q}$) & = & $\\|\\mathbf{p} - \\mathbf{q}\\|_{1}$ \\\\\nMaximum($\\mathbf{p}, \\mathbf{q}$) & = & $\\|\\mathbf{p} - \\mathbf{q}\\|_{\\infty}$ \\\\\nKL2($\\mathbf{p}, \\mathbf{q}$) & = & $\\sum_i p_iln(p_i/q_i) + q_iln(q_i/p_i) $\\\\\nJS($\\mathbf{p}, \\mathbf{q}$) & = & $\\sum_i p_iln(p_i/m_i) + q_iln(q_i/m_i) $\\\\\n& & where $m_i = (p_i + q_i) / 2$\\\\\n\\hline\n\\end{tabular}\n\\caption{Similarity metrics.  JS is the Jensen-Shannon divergence and\n  KL2 is a symmetric implementation of Kullback-Leibler divergence.}\n\\label{tab:metrics}\n\\end{table}\n\nTo judge the merit of each distance metric we obtained supervised\nbaseline scores using leave-one-out cross validation and the weighted\nk-nearest-neighbor algorithm\\footnote{Neighbors were weighted using\n  1/distance, $k=30$ was chosen empirically.} on the gold tags of the\ntest corpus.  The results are listed in Table~\\ref{tab:distscores}\nsorted by score.  \n\n\\begin{table}[ht] \\centering\n\\begin{tabular}{|l|c|}\n\\hline\nMetric & Accuracy(\\%) \\\\\n\\hline\nKL2 & 0.6889 \\\\\nManhattan & 0.6865 \\\\\nJensen & 0.6801 \\\\\nCosine & 0.6706 \\\\\nMaximum & 0.6663 \\\\\nEuclid & 0.6255 \\\\\nlg2-Maximum & 0.5361 \\\\\nlg2-Cosine & 0.4847 \\\\\nlg2-Euclid & 0.4038 \\\\\nlg2-Manhattan & 0.3729 \\\\\n\\hline\n\\end{tabular}\n\\caption{Supervised baseline scores with different distance metrics.\n  Log-metric indicates that metric applied to the log of the\n  probability vectors.}\n\\label{tab:distscores}\n\\end{table}\n\n% K=30\n% KL2 0.688884263114072\n% Manhattan 0.686511240632806\n% Jensen 0.680099916736053\n% Cosine 0.670566194837635\n% Maximum 0.666278101582015\n% Euclid 0.625478767693589\n% lg2-Maximum 0.536136552872606\n% lg2-Cosine 0.484721065778518\n% lg2-Euclid 0.403788509575354\n% lg2-Manhattan 0.37285595337219\n\n% K=20\n% KL2 & 68.95\\\\\n% Manhattan & 68.75\\\\\n% Jensen & 68.43\\\\\n% Cosine & 67.45\\\\\n% Maximum\t& 66.55\\\\\n% Euclid & 63.33\\\\\n% log-Maximum & 54.20\\\\\n% log-Cosine & 49.33\\\\\n% log-Euclid & 41.21\\\\\n% log-Manhattan & 37.59\\\\\n\nThe entries with the log- prefix indicate a metric applied to the log\nof the probability vectors.  Distance metrics on log probability\nvectors performed poorly compared to their regular counterparts\nindicating differences in low probability words are relatively\nunimportant and high probability substitutes determine syntactic\ncategory.  The surprisingly good result achieved by the simple Maximum\nmetric (which identifies the dimension with the largest difference\nbetween two vectors) also support this conclusion.  The maximum score\nof 69\\% can be taken as a rough upper bound for an unsupervised\nlearner using this space on the 45-tag 24K test corpus because 31\\% of\nthe instances are assigned to the wrong part of speech by the majority\nof their closest neighbors.  We will discuss ways to push this upper\nbound higher by including other features in\nSection~\\ref{sec:sparsity}.\n\n% moreover we are using probability vectors so its more natural to use\n% kl2\n\n", "meta": {"hexsha": "8bf200f7e6cb557e709614c2a7f3f54df14c558a", "size": 3673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/cl2012/acl12/distance.tex", "max_stars_repo_name": "ai-ku/upos", "max_stars_repo_head_hexsha": "27d610318a0c777e2ca88b1ab2de5aa48f5a399f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-01-24T11:27:18.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-18T11:35:02.000Z", "max_issues_repo_path": "papers/cl2012/acl12/distance.tex", "max_issues_repo_name": "ai-ku/upos", "max_issues_repo_head_hexsha": "27d610318a0c777e2ca88b1ab2de5aa48f5a399f", "max_issues_repo_licenses": ["MIT"], "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/cl2012/acl12/distance.tex", "max_forks_repo_name": "ai-ku/upos", "max_forks_repo_head_hexsha": "27d610318a0c777e2ca88b1ab2de5aa48f5a399f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-06T07:56:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-06T07:56:00.000Z", "avg_line_length": 36.0098039216, "max_line_length": 109, "alphanum_fraction": 0.7299210455, "num_tokens": 1187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6601400695470583}}
{"text": "\\section{Root: Roots of Functions}\n\\subsection{Quadratics}\n\\subsection*{quadreal, quadcmpx}\nThese address $ax^2+bx+c=0$ for real a,b,c and for complex a,b,c.\nInternally, quadreal calls quadcmpx if the discriminant is less than zero.\n\nWe follow the analysis in NR92 pg 184.  However, we add generation of\nalpha and beta terms via:\n\\begin{eqnarray}\n  x_1    & = & \\alpha + \\beta\\\\\n  x_2    & = & \\alpha - \\beta \\mbox{ therefore, }\\\\  \n  \\alpha & = & \\frac{x_1+x_2}{2}\\\\\n  \\beta  & = & \\frac{x_1-x_2}{2}\n\\end{eqnarray}\n\n[HGG: Initially I couldn't find a way to extract $\\alpha$ and\n$\\beta$ from the NR92 approach.  I even implemented quadreal in\nEXTENDED reals (80-bit), to cover potential truncations.  Finally I went\nback and looked for an extraction.  The problem of course was that\nI was initially looking for $\\alpha$ and $\\beta$ as sources for\n$x_1$ and $x_2$, not as results.]\n\n\\subsection{Nonlinear Functions}\nIn one dimension, root finding means finding a value x such\nthat $f(x) = 0$.  Generally you need a clue to get started,\ne.g., from examining a graph.  Examination allows selection\nof a bracketing pair, x1 and x2, which straddles the x-axis\n(and thus straddles at least one root).  NR92 argues\npersuasively that you should {\\em always} bracket the root\nbefore applying a numerical technique.\n\nThat brings up the next question.  How can you recognize a\nbracket pair?  f(x1) will have the opposite sign from f(x2).\nHere are some approaches:\n\\begin{verbatim}\n     Given: y1:=f(x1); y2:=f(x2);\n     \n     a) IF (y1>0.0 AND y2<0.0) OR (y1<0.0 AND y2>0.0) THEN (*bracketed*)\n     \n     b) IF y1*y2<0.0 THEN (*bracketed*)\n     \n     c) IF sgn(y1) = -sgn(y2) THEN (*bracketed*)\n\\end{verbatim}\n\nI haven't timed these out, but on the basis of short-circuit\nevaulation of relationals, and on the basis of no procedure\ncalls and no multiplies, \"a\" should be the best.  I'll use\nit in the following routines.\n\nGiven an arbitrary pair, we can reach out further and\nfurther trying to get a bracket, or we can close the gap\nnarrower and narrower.  Both can be useful.\n\n\\subsection*{bracket\\_out}\nInspired by NR92's zbrac.  The idea is to start with two\npoints, expand by the golden ratio iteratively, and see if\nthere comes a time when the y's are of opposite signs.\n\nNR92 uses 1.6 as the growth factor.  Just to be different,\nI'll use the Golden constant.  Also,\nI'll require $x1<x2$.  NR92's algorithm actually works for\n$x2<x1$ also, but it isn't as obvious.  I think the slight\nreduction in generality is more than paid back in\nreadability.\n\n\\subsection*{bracket\\_in}\nInspired by NR92's zbrak.  In testing, I noticed that when\nthe segments just happen to line up exactly on a root, they\nmiss it.  So doing different ranges is a good idea,\nor doing n's which are not multiples of one another.  [HGG: All\nthings considered, I like this routine better than\nbracket\\_out, but they can work together.]\n\n\\subsection*{root\\_bisect}\nInspired by NR92's rtbis.  Also covered by Hopk88, pg 67.\n\nThe basic trick is to note that the segment sizes get\nsmaller by 1/2 every time, so we can just do:\n\\begin{verbatim}\n     h:=x2-x1;\n     ...\n     h:=0.5*h;\n\\end{verbatim}\n\nThe exit criterion is:\n\\begin{verbatim}\n     IF h<tol THEN RETURN x; END;\n\\end{verbatim}\n\nEach iteration requires a decision on where to go next,\nbased on y values.  But to do this, we need to know which\ndirection in x corresponds to which direction in y.  So we\nneed to orient the function.  NR92 does $f>0$ at $x+dx$.  Just\nto be different, I'll do the opposite:\n\\begin{verbatim}\n     y:=func(x1);\n     IF y>0.0 THEN\n       x:=x2; h:=x1-x2;\n     ELSE\n       x:=x1; h:=x2-x1;\n     END;\n     (*initialize*)\n     h:=h*0.5; x:=x+h;\n     FOR i:=1 TO maxiter DO\n       y:=func(x);\n       IF y<0 THEN\n         x:=x+h;\n       ELSE\n         x:=x-h;\n       END;\n       IF h<xacc THEN RETURN x; END;\n       h:=h*0.5;\n     END;\n\\end{verbatim}\n     \nI decided to precalc y1 and y2 in order to do the bracketing\ncheck.  That led to slight modifications in the\ninitialization.  Next, after running into cases of hitting\nthe root dead on, I decided to add a check for y=0.  I also\nhad a nice bug in the $h < {\\mbox xacc}$ line.  I was vaguely thinking h\nwould always be positive, so I skipped doing an ABS(h) for\nthe comparison with xacc.  That of course failed, because if\nfunc has a negative slope, h is negative.  Putting in ABS\ndid the job.\n\n\n\\subsection*{root\\_brent}\nBrent's algorithm is used in the netlib matrix libraries.\nThe quadratic formula is given in NR92, eqn 9.3.1. \\dots 9.3.5.\nBut NR92 only gives code, not the algorithm.  To demonstrate\nderivation from the ideas rather than the raw code, I have\nused more descriptive naming than NR92, and changed the use\nof temporaries.  I also added quick victory checks at the\nstart.\n\nThe bracket pair $a \\dots b$ is always the biggest interval of\ninterest.  Sometimes we also have a point c which is known\nbe on a's side but a little closer to b (thus giving a\nsmaller bracket).  At worst, c is identical to a.  So the\nbest shot for the next interval is $b-c$, called diffnext.\n\nThe hard part is deciding what to do about tolerances.  The\nproblem is that Brent's algorithm is carefully crafted with\ntruncation errors in mind.  You can't just go around pulling\ntemp variables out of loops etc. [HGG: Which I did at one point,\nthen thought better of it.]\n\nAfter building the code, I tested with $x1>x2$, $x2>x1$, $x's <0$,\n$x's > 0$, and x's straddling 0.  Does just fine as long as\nthere is only one root in the x1 \\dots x2 range.  But I can get\n$root=0.0$ or a genuine error if there are $>1$ roots.  I\nsuspect that is due to confusing the c as it moves back and\nforth between a and b.  Maybe I'll look at this more later.\n\n\n\\subsection*{root\\_newtraph}\nThe basic newton-raphson root finder is analyzed by Hopk88,\npg 83 and an algorithm is given in Krey88, pg 953.  NR92\nalso covers it, pg .  The formula is:\n\\begin{equation}    \n  x_{i+1}:=x_i-f(x_i)/f'(x_i)\n\\end{equation}\nThus, you must be able to provide $f'(x)$.\n\nThe various authors agree that this algorithm can go wrong\nsometimes.  NR92 addresses that by using Brent's idea of\ndropping back to bisection in a pinch.  We will follow their\nlead.  The question is, when should you go to bisection?\nGiven brackets a and b, and r for rootnext:\n\\begin{verbatim}\n     a........r.........b\n\\end{verbatim}\n\nThen $(a-r)*(r-b)$ should be positive no matrixter which\ndirection the axis points.  That is, it could be 2 positives\nor 2 negatives.  If we get a negative from the multiply, r\nis out of bounds.\n\nWhen we need bisection, we can do: $\\mbox{root}:=0.5*(a+b)$.\nAgain, we don't care whether $a<b$ or $a>b$.  However, to have a\ndelta for checking exit criteria, we need:\n\\begin{verbatim}\n     tmp:=root;\n     root:=0.5*(a+b);\n     delta:=root-tmp;\n\\end{verbatim}\n\nWe start with an arbitrary r set at a, and work from there.\nTo assure that a and b remain bracketing, we need to stick\nto a convention.  Let a be such that $f(a)<0$ and b such that\n$f(b)>0$.  Then when a new root is formed, find its f, and set\nthe proper a or b to root.\n\nNR92 also provides tests for converging too slowly.  My\nalgorithm just relies on bisection to safely drag the\nsolution to the root.  I have not found conditions which\nmake this an issue --- if some arise, we'll deal with it\nthen.\n", "meta": {"hexsha": "14b4bbf8c3941f93a432dea7bd4ca69be1f99900", "size": 7317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/root.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/root.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/root.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": 36.7688442211, "max_line_length": 74, "alphanum_fraction": 0.7095804291, "num_tokens": 2173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6601400605895316}}
{"text": "\\subsubsection{Dirichlet inversion}\nDefine the Dirichlet convolution $f*g(n)$ as:\n\n$$f*g(n)=\\sum^n_{d=1}[d|n]f(n)g(\\frac{n}{d})$$\n\nAssume we are going to calculate some function $S(n)=\\sum^n_{i=1}f(i)$,\nwhere $f(n)$ is a multiplicative function.\nSay we find some $g(n)$ that is simple to calculate,\nand $\\sum^n_{i=1}f*g(i)$ can be figured out in $O(1)$ complexity.\nThen we have\n\n\\begin{equation*}\n\\begin{split}\n\\sum^n_{i=1}f*g(i)\t&=\\sum^n_{i=1}\\sum_d[d|i]g(\\frac{i}{d})f(d)\\\\\n\t\t\t\t\t&=\\sum^n_{\\frac{i}{d}=1}\\sum^{\\floor*{\\frac{n}{\\frac{i}{d}}}}_{d=1}g(\\frac{i}{d})f(d)\\\\\n\t\t\t\t\t&=\\sum^n_{i=1}\\sum^{\\floor*{\\frac{n}{i}}}_{d=1}g(i)f(d)\\\\\n\t\t\t\t\t&=g(1)S(n)+\\sum^n_{i=2}g(i)S(\\floor*{\\frac{n}{i}})\\\\\nS(n)\t\t\t\t&=\\frac{\\sum^n_{i=1}f*g(i)-\\sum^n_{i=2}g(i)S(\\floor*{\\frac{n}{i}})}{g(1)}\\\\\n\\end{split}\n\\end{equation*}\n\nIt can be proven that $\\floor*{\\frac{n}{i}}$ has at most $O(\\sqrt{n})$ possible values.\nTherefore, the calculation of $S(n)$ can be reduced to $O(\\sqrt{n})$ calculations of $S(\\floor*{\\frac{n}{i}})$.\nBy applying the master theorem, it can be shown that the complexity of such method is $O(n^{\\frac{3}{4}})$.\n\nMoreover, since $f(n)$ is multiplicative, we can process the first $n^{\\frac{2}{3}}$ elements via linear sieve,\nand for the rest of the elements, we apply the method shown above. The complexity can thus be enhanced to $O(n^{\\frac{2}{3}})$.\n\nFor the prefix sum of Euler's function $S(n)=\\sum^n_{i=1}\\varphi(i)$, notice that $\\sum_{d|n}\\varphi(d)=n$.\nHence $\\varphi*I=id$. ($I(n)=1,id(n)=n$)\nNow let $g(n)=I(n)$, and we have $S(n)=\\sum^n_{i=1}i-\\sum^n_{i=2}S(\\floor*{\\frac{n}{i}})$.\n\nFor the prefix sum of Mobius function $S(n)=\\sum^n_{i=1}\\mu(i)$, notice that $\\mu*I=(n)\\{[n=1]\\}$.\nHence $S(n)=1-\\sum^n_{i=2}S(\\floor*{\\frac{n}{i}})$.\n\nSome other convolutions include $(p^k)\\{1-p\\}*id=I$, $(p^k)\\{p^k-p^{k+1}\\}*id^2=id$ and $(p^k)\\{p^{2k}-p^{2k-2}\\}*I=id^2$.\n\nUsage:\n\\begin{enumerate}\n\t\\item \\texttt{CUBEN} should be $N^{\\frac{1}{3}}$.\n\t\\item Pass \\texttt{p\\_f} that returns the prefix sum of $f(x)(1\\le x<th)$.\n\t\\item Pass \\texttt{p\\_g} that returns the prefix sum of $g(x)(0\\le x\\le N)$.\n\t\\item Pass \\texttt{p\\_c} that returns the prefix sum of $f*g(x)(0\\le x\\le N)$.\n\t\\item Pass \\texttt{th} as the thereshold, which generally should be $N^{\\frac{2}{3}}$.\n\t\\item Pass \\texttt{mod} as the module number, \\texttt{inv} as the inverse of $g(1)$ regarding \\texttt{mod}.\n\t\\item \\textbf{Remember that $x$ in \\texttt{p\\_g(x)} and \\texttt{p\\_c(x)} may be larger than \\texttt{mod}!}\n\t\\item Run \\texttt{init(n)} first.\n\t\\item Use \\texttt{ans(x)} to fetch answer for $\\frac{n}{x}$.\n\\end{enumerate}\n\n\\lstinputlisting{src/mathematics/computation/dirichlet-convolution.cpp}\n", "meta": {"hexsha": "570f4c297244e844b3823e0f492aa0e7eb5082e3", "size": 2671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/mathematics/computation/dirichlet-convolution.tex", "max_stars_repo_name": "Nisiyama-Suzune/LMR", "max_stars_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2018-08-15T11:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T23:38:29.000Z", "max_issues_repo_path": "src/mathematics/computation/dirichlet-convolution.tex", "max_issues_repo_name": "Nisiyama-Suzune/LMR", "max_issues_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mathematics/computation/dirichlet-convolution.tex", "max_forks_repo_name": "Nisiyama-Suzune/LMR", "max_forks_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2019-07-18T10:27:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-08T13:03:47.000Z", "avg_line_length": 51.3653846154, "max_line_length": 127, "alphanum_fraction": 0.6304754773, "num_tokens": 1053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6600147673211422}}
{"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{Full FDTD for the 1D Case}\n% TODO: Reference to that\nWe're starting with the previously [REF] derived six equations that stem from Maxwell. They're listed here again for convenience:\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 \\text{ .}\n\\end{align}\nThe operator \\( \\partial_x \\) is a shorthand for the partial derivative \\( \\frac{\\partial}{\\partial x} \\).\n\nAgain, we're only considering a discretization along one axis (\\textit{z-axis}), but now we won't force the conditions a plane wave. Thus spatial derivatives along other axes (\\textit{x-axis} and \\textit{y-axis}) will be disregarded, but the electric and magnetic field will not be constricted to a single axis. This reasoning leads to the following modified equations:\n\\begin{align}\n\t\\partial_z E_y &= \\mu \\partial_t H_x \\\\\n\t\\partial_z E_x &= -\\mu \\partial_t H_y \\\\\n\t0 &= -\\mu \\partial_t H_z \\\\\n\t- \\partial_z H_y &= \\varepsilon \\partial_t E_x + \\sigma E_x \\\\\n\t\\partial_z H_x  &= \\varepsilon \\partial_t E_y + \\sigma E_y \\\\\n\t0 &= \\varepsilon \\partial_t E_z + \\sigma E_z \\text{ .}\n\\end{align}\nNote that equations 3 and 6 [REF] can be dropped, since they only state that there is time-variance in the electric and magnetic field along the z-axis. The discretization is done in a staggered manner (\\textit{Yee-grid}) as in the case of the plane wave and leads to the equations\n% TODO: Add mention of Yee grid to plane wave note\n\\begin{align}\n\t\\frac{E_y^{n+1/2}(k+1)-E_y^{n+1/2}(k)}{\\Delta z} &= \\mu \\frac{H_x^{n+1}(k+1/2)-H_x^{n}(k+1/2)}{\\Delta t} \\text{ ,} \\\\\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} \\text{ ,} \\\\\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} + \\sigma E_x^n(k) \\text{ ,} \\\\\n\t\\frac{H_x^{n}(k+1/2)-H_x^{n}(k-1/2)}{\\Delta z} &= \\varepsilon \\frac{E_y^{n+1/2}(k)-E_y^{n-1/2}(k)}{\\Delta t} + \\sigma E_y^n(k) \\text{ ,}\n\\end{align}\nwhere a new unknown variable \\( E_x^n(k) \\) appears -- originally -- due to the contribution of the current density term in Ampere's circuital law [REF]. This new unknown variable can be eliminated by averaging between two time steps as in \n% TODO: Ref\n\\begin{equation}\n\tE_x^n(k) = \\frac{E_x^{n+1/2}(k)-E_x^{n-1/2}(k)}{2} \\text{ .}\n\\end{equation}\n\nRearranging gives the iterative algorithm:\n\\begin{align}\n\tH_x^{n+1}(k+1/2) &= H_x^{n}(k+1/2) + \\frac{\\Delta t}{\\mu \\Delta z}\\left( E_y^{n+1/2}(k+1)-E_y^{n+1/2}(k) \\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) \\\\\n\tE_x^{n+1/2}(k) &= E_x^{n-1/2}(k) - \\frac{\\Delta t}{\\varepsilon \\Delta z + \\frac{1}{2}\\sigma \\Delta z \\Delta t} \\left( H_y^{n}(k+1/2)-H_y^{n}(k-1/2) \\right) \\\\\n\tE_y^{n+1/2}(k) &= E_y^{n-1/2}(k) + \\frac{\\Delta t}{\\varepsilon \\Delta z + \\frac{1}{2}\\sigma \\Delta z \\Delta t} \\left( H_x^{n}(k+1/2)-H_x^{n}(k-1/2) \\right) \\text{ .}\n\\end{align}\n% TODO: Refs\nIn each time step, first [20] and [21] are determined for the electric field, then the magnetic field is determined with [18] and [19]. For numerical stability, the CFL condition\n\\begin{equation}\n\t\\Delta t \\leq \\frac{\\Delta z}{c}\n\\end{equation}\nhas to also be fulfilled. For this case we arrive at the following factors\n\\begin{align}\n\t\\frac{\\Delta t}{\\mu \\Delta z} &= \\frac{1}{Z_0 \\mu_r} \\\\\n\t\\frac{\\Delta t}{\\varepsilon \\Delta z + \\frac{1}{2}\\sigma \\Delta z \\Delta t} &= \\frac{\\frac{\\Delta z}{c}}{\\varepsilon \\Delta z + \\frac{1}{2}\\sigma \\Delta z \\frac{\\Delta z}{c}} = \\frac{Z_0}{\\varepsilon_r + \\frac{1}{2} Z_0 \\sigma \\Delta z}\n\\end{align}\nfor the spatial derivative terms in 18-21.\n% TODO: Refs\n\n\n\\section{Simulations}\n\n\n\\end{document}          \n", "meta": {"hexsha": "bab466e3aff3aa6991e1d0c558e4713e99712bdd", "size": 4278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/full_formulation_1d/full_formulation_1d.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/full_formulation_1d/full_formulation_1d.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/full_formulation_1d/full_formulation_1d.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": 57.8108108108, "max_line_length": 369, "alphanum_fraction": 0.6610565685, "num_tokens": 1591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.659986913933731}}
{"text": "\n\\subsection{Profit}\n\nThe profit of a firm is the difference between revenue and costs.\n\n\\(\\pi = pq-c\\)\n\nWhere \\(q\\) is the amount producted, and \\(p\\) is the price, and \\(c\\) is a function of production.\n\n\\subsection{Maximising profit}\n\n\\(\\pi = pq-c\\)\n\nThe firm's production \\(q\\) affects the market price \\(p\\).\n\n\\(\\dfrac{\\delta \\pi }{\\delta q}= \\dfrac{\\delta }{\\delta q} [pq-c]\\)\n\n\\(\\dfrac{\\delta \\pi }{\\delta q}= p+q\\dfrac{\\delta p}{\\delta q}-\\dfrac{\\delta c}{\\delta q}\\)\n\nThe firm chooses \\(Q\\) to maximise profits.\n\n\\(p+q\\dfrac{\\delta p}{\\delta q}=\\dfrac{\\delta c}{\\delta q}\\)\n\nThe right side is marginal costs (MC), the left is marginal revenue.\n\n\\(p[1+\\dfrac{q}{p}\\dfrac{\\delta p}{\\delta q}]=MC\\)\n\nWe know that the price elasticity of demand is: \\(\\epsilon = \\dfrac{p}{q}\\dfrac{\\delta q}{\\delta p}\\)\n\nSo we have:\n\n\\(p[1+\\dfrac{1 }{\\epsilon }]=MC\\)\n\n\\(p=\\dfrac{\\epsilon }{1+\\epsilon }MC\\)\n\n\\subsection{Intensive and extensive margins}\n\n\\(revenue = pq\\)\n\n\\(MR=p +q\\dfrac{\\delta p}{\\delta q}\\)\n\n\\(p\\) is the extensive margin.\n\n\\(q\\dfrac{\\delta p}{\\delta q}\\) is the (negative) intensive margin.\n\nmonopoly pricing. when lower prices, gain money on extensive margin. lose money on intensive margin.\n\n", "meta": {"hexsha": "e74894295a4aff45119a4212805acf76084dd189", "size": 1203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/producer/01-01-profit.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/producer/01-01-profit.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/producer/01-01-profit.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.0625, "max_line_length": 101, "alphanum_fraction": 0.6541978387, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619979547273, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6599869119790598}}
{"text": "\\chapter{Appendix Statistics}\r\n\r\n\\section*{Concepts from Mathematical Statistics}The sampling distribution of an estimator is the probability distribution of the estimator under repeated sampling.  The standard error of a measurement is essentially the standard deviation of the process by which the measurement was generated.  When the underlying probability distribution of the generating process is known the standard error can be used to calculate confidence intervals.  Otherwise Chebyshev's inequality can be used. The standard error of a sample from a population is the standard deviation of the sampling distribution and may be estimated as $\\frac{\\sigma}{\\sqrt{n}}$\r\n\r\nCompleteness is the ability of a statistical estimator to ensures that the parameters of the underlying probability distribution representing the model can be estimated from the statistic.\r\n\r\nConsider a family of probability distributions for a random variable $X$ parameterized by a parameter $\\theta$. A quantity $T(X)$ that depends on the random variable $X$ but not on the parameter $\\theta$ is called a statistic.  A statistic that captures all of the information in X that is relevant to the estimation of $\\theta$ is called a sufficient statistic. Since the conditional distribution of $X$ given $T(X)$ does not depend on $\\theta$, neither does the conditional expected value of $g(X)$ given $T(X)$. The conditional expected value is itself a statistic and so is available for use in estimation. If $g(X)$ is an estimator of $\\theta$, then typically the conditional expectation of $g(X)$ given $T(X)$ is a better estimator of $\\theta$. The Rao-Blackwell theorem makes this precise.\r\n\r\n\\section*{L-Estimators \\& M-Estimators}Order statistics of a sample ${X_i}$ can be used to estimate quantiles. An L statistic is a linear combination of an order statistic.  L statistics are used in Box plots.  An M-Estimator is the minima of sums of functions of the sample data.  Maximum Likelihood and Least Squares are examples of M-Estimators.\r\n\r\n\\section*{Testing for normality and other distributions } Powerful inference methods can be employed when data is generated by a Gaussian process. This section describes techniques for testing the normality of a sample and comparing two samples.  Kolmogorov-Smirnov test uses the fact that the empirical cumulative distribution function is normal in the limit. It is a non-parametric and distribution free test. Given the empirical distribution\r\n \\[F_n(x) = \\frac{1}{n} \\sum\\limits_{n}^{i=1} \\biggl\\{\\begin{array}{c}1 :x_i\\leq x \\\\0 : x_i>x\\\\ \\end{array}\\]\r\n , and a test CDF\\[ F(x)\\] the K-S test statistics are $D_n^+ = max(F_n(x)-F(x) ) $ and $D_n^- = min(F_n(x)-F(x) )$ The generality of this test comes at a loss in precision near the tails of a distribution.  The K-S statistics are more sensitive near points close to the median, and are only valid for continuous distributions.  The Kuipers test uses the statistic $D_n^+ + D_n^- $ and is useful for detecting changes in time series since the statistic is invariant in ???? transformation of the dependent variable $ F_n$.  The Anderson-Darling test is based on the K-S test and uses the specific distribution to specify the ????critical values??? of the test.  The chi-squared is based on the sample histogram and allows comparison against a discrete distribution, but has the potential drawback of being sensitive to how the histogram is binned and requires more samples to be valid.  The Shapiro-Wilk test uses the expected values of the order statistics of $F(x)$ to calculate the test statistic.  It is sensitive to data that are very close together, and numerical implementations may suffer from a loss of accuracy for large sample sizes.\r\n\r\n K-S [Chakravarti, Laha, and Roy, (1967). Handbook of Methods of Applied Statistics, Volume I, John Wiley and Sons, pp. 392-394].  Shapiro-Wilk [Shapiro, S. S. and Wilk, M. B. (1965). \"An analysis of variance test for normality (complete samples)\", Biometrika, 52, 3 and 4, pages 591-611.]\r\n\r\n\r\n\\section*{Regression Methods}Standard least squares regression consists in fitting a line through the data points (training points in learning theory) that minimizes the sum of square residuals.  The underlying assumption is that the data and the response can be modeled by a linear relationship.  In the event that the model accurately captures the functional dependence of the response generated by the data, and under the assumptions that the data is corrupted by Gaussian noise, precise statistical inferences can be made on the model parameters.  Modifications to this standard model include nonlinear mapping of the input data, local fitting, biased estimators, subset selection, coefficient shrinking, weighted least squares, and basis expansion transformations.\r\n\r\nThe multiple regression model in matrix notation can be expressed\r\nas\r\n(BBCREVISIT)\r\n\r\nThese equations hold for the univariate and the multivariate case.\r\n\r\n$\\textbf{Y} = \\textbf{X}{\\beta} + \\textbf{e}$.\r\n\r\nwhere $\\textbf{e} =_d N(\\mathbf{\\mu},\\mathbf{\\Sigma})$\r\n\r\n$E \\textbf{Y} = \\mathbf{\\mu} X \\mathbf{\\beta}$\r\n\r\n$var \\textbf{Y} = \\sigma^2 \\textbf{I}$\r\n\r\nMaximum Likelihood and Least Squares give same estimator;\r\n\r\n$\\widehat{\\mathbf{\\beta}}=(X^TX)^{-1} X^T Y$\r\n\r\n$\\hat{\\sigma}^2 = frac{1}{n} || Y- \\hat{\\mu} ||^2$\r\n\r\nMultivariate regression is the extension to $YM = Xb + e$\r\n\r\nHere $Y, X, b$, and $e$ are as described for the multivariate regression model and $M$ is an $m x s$ matrix of coefficients defining linear transformation of the dependent variables. The normal equations are $X'Xb = X'YM$ and a solution for the normal equations is given by $b = (X'X)-X'YM$. Here the inverse of $X'X$ is a generalized inverse if $X'X$ contains\r\nredundant columns.\r\n\r\n\\section*{Generalized Linear Models}Suppose we have $n$ observations of $k$ dimensional data denoted $\\{x_i\\}_{i=1}^{k}$ and for each observation we have a response $y_i$. We wish to fit the observations to the responses. Generalized Linear Regression is a modeling technique that allows for non normal distributions and models non-linear relationships in the training data. M-estimators are used to fit a generalized linear model Ref Huber (1964).\r\nA linear model $ Y =\\Lambda(X)=X\\beta + \\epsilon$ fits a linear relationship between the dependent variables $Y_i$ and the predictor variables $X_i$ \\begin{equation}Y_i=\\Lambda(X_i)=b_o + b \\circ X_i.\\end{equation}\r\nA generalized linear model $Y= g(\\Lambda(X) ) + \\epsilon $ fits the data to $ Y = g (X \\circ W)$. Fitting the model consists of minimizing the objective function $\\sum\\limits_{i=1}^{n} g(e_i)=\\sum\\limits_{i=1}^{n} g(y_i- x_i \\beta)$\r\n, where $e_i$ are the residuals $y_i-x_i \\beta$. We see that for ordinary least squares $g(e_i)=e_i^2$, and the usual matrix equations fall out by differentiating with respect to $\\beta$. Carrying this out for general $g$ \\begin{equation} \\sum\\limits_{i=1}^{n} \\frac{\\partial  g(y_i-x_i \\beta)}{\\partial \\beta}=0 \\end{equation} gives the system of $k+1$ equations to solve for estimating the coefficients $b_i$.  If we set$\\alpha(x)=\\frac{g'(x)}{x}$ and calculate the derivative above, we have to solve \\begin{equation} \\sum\\limits_{i=1}^{n} \\omega(e_i) (y_i-x_i \\beta) x_i = 0 \\end{equation}. Which gives rise to a weighted least squares where the weights depend on the residuals - which depend on the coefficients - which depend on the weights.  This suggests an iterative algorithm; \\begin{equation} \\beta^\\tau = ( X^{t} W^{(\\tau-1)} X )^{-1} X^{t} W^{\\tau-1} y \\end{equation} where $W_{ij}^{(\\tau-1)}=\\alpha(e_{i}^{(\\tau-1})$.  Several parameterizations are popular for the exponential family. The most general form of the distribution \\[ p(x,\\theta) = f(x,\\theta)e^{g(x,\\theta)} \\in C^2(\\dblr \\otimes \\dblr ) \\otimes C^2(\\dblr \\otimes \\dblr )\\].  The estimators derived below assume that $f$ and $g$ are separable, \\[ p(x,\\theta) = f(x) h(\\theta) e^{\\alpha(x) \\beta(\\theta)} \\in C^2(\\dblr) \\otimes C^2(\\dblr ) \\otimes C^2(\\dblr ) \\otimes C^2(\\dblr ) \\].  From \\[ \\int\\limits_{x=-\\infty}^{x=+\\infty} p(x,\\theta) dx \\: =1\\] we get \\[ \\fderiv{\\theta}{p(x,\\theta)} = 0 = \\sderiv{\\theta}{p(x,\\theta)}d \\] Since the parametrization we have chosen for the exponential family allows, in the sequel we drop the notation for dependent variable and denote the derivative with a prime. \\[ \\fderiv{\\theta}{p(x,\\theta)} = \\fderiv{\\theta}{f h e^{\\alpha \\beta}} = h' f e^{\\alpha \\beta} + f h \\alpha \\beta' e^{\\alpha \\beta} = \\bigl( \\frac{h'}{h} + \\alpha \\beta' \\bigr) p(x,\\theta) \\] which gives \\[\\int \\fderiv{\\theta}{p(x,\\theta)} dx = \\int \\bigl( \\frac{h'}{h} + \\alpha \\beta' \\bigr) p(x,\\theta) dx= \\frac{h'}{h} \\int p(x,\\theta) dx \\:+\\: \\beta' \\int \\alpha(x) p(x,\\theta) dx = \\frac{h'}{h}+\\beta' E[\\alpha(x)] \\] so that \\[E[\\alpha(x)]=-\\frac{h'}{h \\beta'}\\]. Continuing along this vein,\\begin{gather*} 0 =\\int \\sderiv{\\theta}{p(x,\\theta)} dx = \\int \\fderiv{\\theta}{\\bigl( \\frac{h'}{h} + \\alpha \\beta' \\bigr) p(x,\\theta) } dx =\\\\  \\int \\bigr(\\frac{h''}{h}-\\frac{(h')^2}{h^2}+\\alpha \\beta'' \\bigl ) p(x,\\theta) + (\\frac{h'}{h}+\\alpha \\beta') \\fderiv{\\theta}{p(x,\\theta)} \\: dx = \\\\ \\int \\bigr(\\frac{h''}{h}-\\frac{(h')^2}{h^2}+\\alpha \\beta'' \\bigl ) p(x,\\theta) + (\\frac{h'}{h}+\\alpha \\beta')^2 p(x,\\theta) \\: dx = \\\\ \\int \\bigr(\\frac{h''}{h}-\\frac{(h')^2}{h^2}+\\alpha \\beta'' \\bigl ) p(x,\\theta) + (\\frac{h'}{h}+\\alpha \\beta')^2 p(x,\\theta) \\: dx = \\\\ \\int \\bigr(\\frac{h''}{h}-\\frac{(h')^2}{h^2}+\\alpha \\beta'' \\bigl ) p(x,\\theta) + (\\alpha \\beta'- E[\\alpha(x)]\\beta')^2 p(x,\\theta) \\: dx \\end{gather*}  Keeping in mind that  \\[ Var[a x ]= E[ (ax-E(ax)^2 ] = a^2 E [ (x-E[x])^2] =a^2 Var[x]  \\]  we get the variance via\\[ \\bigr(\\frac{h''}{h}-\\frac{(h')^2}{h^2}+E[\\alpha(x)] \\beta'' \\bigl )+ Var[\\alpha(x) \\beta'(\\theta)] = \\bigr(\\frac{h''}{h}-\\frac{(h')^2}{h^2}+E[\\alpha(x)] \\beta'' \\bigl )+ (\\beta')^2 Var[\\alpha(x)] = 0 \\]  The score $U(x)$ is given by \\[ U(x)=\\pfderiv{\\theta}{L(\\theta,x)} = \\pfderiv{\\theta}{\\log \\: p(x,\\theta)}=\\pfderiv{\\theta}{\\bigr( \\log h(\\theta) + \\log f(x) + \\alpha(x) \\beta(\\theta)\\bigl) } = \\frac{h'}{h} + \\alpha \\beta'\\] so \\[E[U(x)]=\\beta'E[\\alpha(x)] + \\frac{h'}{h} =0 \\].  The Fisher Information $\\mathcal{F}$ is defined \\[\\mathcal{F}=Var[U(x)] =Var[ \\alpha \\beta' + \\frac{h'}{h}]= Var[ \\alpha \\beta'] \\] So from above we have \\[Var[U(x)]= Var[ \\alpha \\beta'] =\\bigr(-\\frac{h''}{h}+\\frac{(h')^2}{h^2}-E[\\alpha(x)] \\beta'' \\bigl )\\].  Now differentiating,  \\[ \\fderiv{\\theta}{U(\\theta,x)} = \\frac{h''}{h} - \\frac{(h')^2}{h^2} + \\alpha \\beta''\\] \\[E[U'(\\theta,x)]=\\frac{h''}{h} - \\frac{(h')^2}{h^2} + E[\\alpha] \\beta'' =  \\frac{h''}{h} - \\frac{(h')^2}{h^2} -\\frac{ \\beta'' h'}{\\beta'}= - Var[U(x)] \\].  Note that if we write the parametrization of the separable exponential family as \\[ p(x,\\theta) =  e^{\\alpha(x) \\beta(\\theta)+\\log(f(x))+\\log(h(\\theta))}\\] then, \\[\\sderiv{\\theta}{\\log(h(\\theta))}=\\fderiv{\\theta}{\\frac{h'}{h}}=\\frac{h''}{h}-\\frac{(h')^2}{h^2}\\].     (BBCREVISIT - this duplicates and has notation clash with material above).\r\n\r\nA general form of the exponential distribution \\begin{equation} \\rho(x;\\theta) = exp( \\frac{x \\theta - \\xi(\\theta) }{\\sigma} ) \\nu ( x) \\end{equation} has a log likelihood for a random sample $\\{ X_i  \\}_{i=1 \\hdots N}$ given functionally by \\begin{equation} \\mathcal{L} (\\theta) =  \\sum\\limits_{i=1}^{N} [ X_i  \\theta  - \\xi (\\theta) + log   ( \\nu ( X_i ) ) ] \\end{equation} The scale parameter $\\sigma$ and $\\theta$ are orthogonal parameters in that E [ ] The Generalized Linear model can  $\\rho'$ is referred to as a link function in the statistical literature.  If $\\rho'(x)= x\\field(1)$ and $\\epsilon=(\\epsilon_1, \\hdots ,\\epsilon_n)$ are iid $N(\\mu,\\sigma)$ we have multiple linear regression.  In classification problems or binomial models the logit $\\rho'(x)=log(x/(1-x))$ link function is used. The logit is extended to the $k$ category case by \\begin{equation}\\rho'( x_i | x_j j \\neq i)= log ( \\frac{x_i}{1- \\sum\\limits_{j \\neq i} x_j})\\end{equation}. The posterior probability densities ${p_i(?)}$ bbcrevisit (or $p_i$ the probability of observing class $i$)  of k classes are modeled by linear functions of the input variables $x_i$.\r\n\r\n\\section*{Fitting the GLM}Iteratively re-weighted least squares (IRLS) is used to for fitting generalized linear models and in finding M-estimators.  The objective function\r\n\r\n\\begin{equation}\r\nJ(\\beta^{i+1}) = arg min \\sum w_i ( \\beta) | y_i - f_i (\\beta) |\r\n\\end{equation}\r\n\r\nis solved iteratively using a Gauss-Newton or Levenberg-Marquardt (LM) algorithm. LM is an iterative technique that finds a local minimum of a function that is expressed as the sum of squares of nonlinear functions. It is a combination of steepest descent and the Gauss-Newton method. When the current solution is far from the minimum the next iterate is in the direction of steepest descent. When the current solution is close to the minimum the next iterate is a Gauss-Newton step.\r\n\r\nLinear least-squares estimates can behave badly when the error is not normal.  Outliers can be removed, or accounted for by employing a robust regression that is less sensitive to outliers than least squares.  M-Estimators introduced by Huber generalize maximum likelihood estimation and are less biased and more efficient.  Instead of trying to minimize the log likelihood\r\n\r\n\\begin{equation}\r\nL(\\theta) = \\sum - log ( p(x_i, \\theta)\r\n\\end{equation}\r\n\r\nHuber proposed minimizing\r\n\r\n\\begin{equation}\r\nM(\\theta) = \\sum  \\rho(x_i, \\theta)\r\n\\end{equation}\r\n\r\nwhere $\\rho$ reduces the effect of outliers. Common loss function are the Huber, and Tukey Bisquare.  For $\\rho(x) = x^2$ we have the familiar least squares loss.\r\n\r\nM estimators arise from the desire to apply Maximum Likelihood Estimators to noisy normal data, and to model more general distributions. They provide a regression that is robust against outliers in the training set, and allow for modeling of non-Gaussian processes. When $\\rho$ above is a probability distribution, we are preforming a maximum likelihood estimation.\r\n\r\nThe Huber function which is a hybrid $L^2$ $L^1$ norm\r\n\\begin{equation}\r\n\\rho_\\eta(e_i)=\\biggl\\{\\begin{array}{cc}\r\n\\frac{e_i^2}{2} & |e_i| \\leq \\eta \\\\\r\n  \\eta |e_i| - \\frac{\\eta^2}{2} & |e_i| > \\eta \\\\\r\n\\end{array}\r\n\\end{equation}\r\nThe  Tukey Bisquare estimator is given by\r\n\\begin{equation}\r\ng_\\eta(e_i)=\\biggl\\{ \\begin{array}{cc} \\frac{\\eta^2}{6} (\r\n1-[1-\\frac{e_i}{\\eta}_2]^3) & |e_i| \\leq \\eta \\\\\r\n\\frac{\\eta^2}{6} & |e_i| > \\eta \\\\\r\n\\end{array}\r\n\\end{equation}\r\n\r\nNumerical procedures for doing this calculation are the Newton-Raphson method [see the section on root finding below ], and Fisher-Scoring method [ replace $ \\frac{\\partial^2 \\mathcal{L}(\\mathbf{\\theta})}{\\partial \\mathbf{\\theta} \\partial \\mathbf{\\theta}^{t} }$ with $E[ \\frac{\\partial^2 \\mathcal{L}(\\mathbf{\\theta})}{\\partial \\mathbf{\\theta} \\partial \\mathbf{\\theta}^{t} }  ]$. For high dimensional data, many models may be fit in an attempt to find the simplest one that can explain the data.  In the language of statistical learning theory, the choice of a norm $\\rho$ is tantamount to choosing a loss function. Restricting the admissible functions to the one parameter family of exponential probability distributions defines the capacity via a functional form of the law of large numbers. \\cite{Scholkopf B. (2002)}\r\n\r\n\r\n\r\n\\section*{Feature Subset Selection (FSS)}The goal of feature selection techniques to to improve the model building process by eliminating features that do not have discriminative power. Algorithms for feature selection either rank features or create subsets of increasing optimality.  FSS should be contrasted with feature extraction techniques such as PCA, LLE, or Laplacian eigenmaps.  The goal of feature extraction is to transform data from a high dimensional space to a low dimensional one while preserving the relevant information.\r\n\r\nThe statistical approach to feature selection most commonly used is stepwise regression.  Common optimality criteria are FSS schemes the Kolmogorov-Smirnov Test ,the t-test, the f-test, the Wilks Lambda Test and Wilcoxon Rank Sum Test.\r\n\r\nIt's important to distinguish the FSS process from a data dimension reduction process such as PCA which requires all the original measurements to compute the projection. The better FSS algorithms are recursive\r\n\r\nConstruct a $p x M$ basis matrix $H^{T}$ and transform feature vector $x' = H^{T} x$.\r\n\r\n\r\nGeneralize to $L^{2}$ with smoothing splines\r\n\r\nSmoothing spline $RSS(f,\\lambda)= \\sum\\limits_{i=1}^{N} (y_{i} -f(x_{i}) )^{2} + \\lambda \\int f''(t)^{2} dt$. where $f \\in C^{2}(\\field{R} )$ This is minimized in $L^{2}$ the first term measuring closeness of fit, and the second term penalizes curvature. $\\lambda \\rightarrow 0$ gives any function interpolating the data points ${x_i}_{i  \\in {1, ... N} } $ an $\\lambda \\rightarrow \\infty$ constrains $f$ to be linear.\r\n\r\n\\section*{Longitudinal Data Analysis} Longitudinal data analysis is the observation of multiple subjects over repeated intervals. Binary repeated responses are typically modelled with a marginal or random effects model, which will be made precise below. Marginal Models are a generalization of the GLM presented above for correlated data.  Here, the correlation is inter subject across time.  Statistical analysis of longitudinal data must take into account that serial observations of a subject are likely to be correlated, time may be an explanatory variable, and that missing response data my induce a bias in the results.  Let ${X_{ij}}$ be time varying or fixed covariates for the binary response ${Y_{ij}}$ of subject $i \\in {1,...n}$ at time intervals $j \\in {t_1,...t_m}$. By convention $X_{ij} \\in \\field{R} x \\field{R^p}$ where the first dimension is the intercept. The marginal model is; $logit (E(Y_{ij} | X_{ij}) ) = X_{ij}^{\\dagger} \\beta$ and enforces the assumption that the relationship between the covariates and the response is the same for all subjects. Recall that for a binary response, $E(Y_{ij} | X_{ij}) = P(Y_{ij}=1 | X_{ij})$.  The random effects model takes into account that the relationship between the covariates and response varies between subjects; $logit (P(Y_{ij}=1 | X_{ij}) ) = X_{ij}^{\\dagger} \\beta_i$ If it is know that only a subset of the covariates are involved in the inter-subject variability, we can set $\\beta_i= \\beta + \\beta_i$ and write $logit (P(Y_{ij}=1 | X_{ij}, \\beta_i) ) = X_{ij}^{\\dagger} \\beta + O X_{ij} \\beta_i$ Where the kernel of $O : \\dblr^n \\rightarrow \\dblr^{n'}$ is the span of the covariates that do not change between subjects.  If $\\lambda_i =_d N(0,\\sigma)$ then the difference in the parameter vectors $\\beta$ in the two models differ according to $\\sigma$.\r\n\r\nThe GEE method of fitting the marginal model is described in: \\cite{Liang, K-Y and Zeger, S. L.(1986)}  The Survival Analysis is a form of longitudinal analysis that takes into consideration the amount of time an observation is made on a subject.  GLM's can be used to fit discrete longitudinal hazard models derived from survival analysis, see  \\cite{Prentice and Gloeckler (1978)}.   \\cite{Meyer, B.D. (1990)} generalized that approach to account for an unobserved subject heterogeneity.  \\cite{Holmen, M (2005)} applied the hazard model of \\cite{Prentice, R. and L. Gloeckler (1978)} to the takeover hazard of large firms.  A negative relationship between dual class ownership and value is empirically known, and that relationship can be explained by the lower takeover probability of the dual class firms.  Dual class entities had a higher risk for takeover, but the hazard is lower since these firms use the dual class structure to change the capital structure in a way that allows the controlling shareholders to remain in control by reducing firm value.  The proportional hazards model can be discretized, but it is important to identify whether the process is truly a discrete process.  In that case the link function should be the logit as the Marginal Model above specifies, rather than the log-log function of the discretized proportional model.  The difference is the modelling of a probability transition in the former case versus a rate for the latter case.  Variable selection techniques for longitudinal data are relatively limited and most seem to rely on Wald type tests. Wald tests to include a variable are based on already computed maximum likelihood values. The Rao score test is used to include a covariate in the model building process.  The Wald test calculates \\[z^2=\\frac{\\widehat{\\beta}}{stderr}=_d  \\chi^2\\]  The likelihood ratio statistic for comparing two models $L_0 \\in L_1$ \\[-2 \\frac{L_0}{L_1} =_d \\chi^2\\] is useful for backward stepwise variable subset selection. The degrees of freedom of the of the statistic is equal to the difference in dimension of the two models.\r\n\r\n\r\n\\section*{Discretization \\& Sheppard's Correction}W. Sheppard (1898) Derived an approximate relationship between the moments of a continuous distribution and it's discrete approximation. This provides a transformation to statistical estimators that correct for the binning of continuous data.  As the scale at which datum are collected is increased, the variance of an estimate can become biased.  It is important to assess  bias caused by grouping and to correct it if necessary. The  bias of the approximate maximum likelihood estimator where observations are approximated by interval midpoints $O(w^2)$, where $w$ is the bin width. A Sheppards correction can be used to reduce the bias to order $O(w^3)$,  Signal processing engineers often have to deal with such a quantization effect when designing finite precision systems, image processing being a particularly relevant example. The engineering community typically models the quantization noise $Q=[X]-X$, where $[X]$ is the quantized realization of $X$. One might be tempted to apply a Sheppard's correction to the moments of the quantized data, thinking that $Var(X)<Var([X])$ but it is possible to construct examples where $Q$ and $[X]$ are independent, or where $Cov(X,Q)$ is such that $Var(X)>Var([X])$.  Shepard's correction is limited in that is doesn't apply to the first moment, and the frequencies of the first and last bins need to be low.  Expand $p(x;\\theta)$ in a Taylor series and substitute in the Maximum Likelihood equations. \\cite{Lindley, D. V. (1950)}  Suppose we have n realizations of iid RV's ${X_1, \\hdots , X_n}$ and the data is collected on a discrete grid on the range of $X$ $Ran(X)=\\{[y_i-d_i/2,y_i+d_i/2]\\}_{i=1}^{i=m}$ where the intervals are centered on the location where a measurement. The realized values ${y_1, \\hdots , y_m}$ have probabilities $p_i=\\int\\limits_{y_i - d_i /2}^{y_i+d_i /2} p(x;\\theta) \\;\\; dx$ Expanding $p(x;\\theta)$ in a Taylor series about $y$, $p(x;\\theta)= \\sum\\limits_{i=0}^{\\infty} \\frac{p^{(i)}(y) }{i!} (x-y)^i$.\r\n\r\n\r\n\\section*{Multidimensional Scaling}Multidimensional scaling (MDS) is an alternative to factor analysis. The aim of MDS and factor analysis is to detect meaningful underlying dimensions that explain similarities or dissimilarities data points. In factor analysis, the similarities between points are expressed via the correlation matrix. With MDS any kind of similarity or dissimilarity matrix may be used.  Given $n$ observations ${x_i}_{i=1}^{n} \\in \\dblr^k$ and $n^2$ distances $d_{ij}$ between them, MDS looks for $n$ points ${\\xi_i}_{i=1}^{n}$ in $dblr^l : l<k$ that preserve the distance relations. When a metric $\\rho()$ exists for the similarity measure, gradient descent is used to minimize the MDS functional $S(\\xi_1, \\ldots , \\xi_l)=\\biggl( \\sum_{i \\neq j} d_{ij}-||\\xi_i-\\xi_j||_{\\rho}\\biggr)^\\frac{1}{2}$.\r\n\r\n\r\n\\section*{Principal Components} For a data set $\\textbf{X} \\in\r\nM_{(N,m)}(\\mathbb{R}) = { x_1, x_2, \\ldots x_N | x_i \\in\r\n\\mathbb{R}^m } $, the first k principal components provided the\r\nbest k dimensional linear approximation to that data set.\r\nFormally, we model the data via $f(\\theta) = \\mu + \\textbf{V}_k\r\n\\theta | \\mu \\in \\mathbb{R}^m, V_k \\in O_{m,k}(\\mathbb{R}),\r\n\\theta \\in \\mathbb{R}^k$ so $f(\\theta)$ is an affine hyperplane\r\nin $\\mathbb{R}^m$\r\n\r\n\r\n\\section*{Evaluating classifier performance} Multi-class problems can be treated simultaneously or broken in to a sequence of two class problems.  Cross validation is used both for classifier parameter tuning and for feature subset selection.  Student-t and ANOVA can be used to evaluate the performance of classifiers against one another.  The Student-t test compares two classifiers, while the ANOVA test can compare multiple classifiers against one another.  Confusion matrices and ROC graphs are commonly employed visualization tools for assessing classifier performance. The rows of a confusion matrix add to the total population for each class, and the columns represent the predicted class.  An ROC curve plots the TP rate against the FP rate. Often a curve in ROC space is drawn using classifier parameters for tuning purposes.\r\n\r\n\\begin{table}[h]\r\n\\begin{tabular}{|c|c|}\r\n  \\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n  TN &  FP \\\\\r\n  \\hline\r\n  FN & TP \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\caption{Two class confusion matrix where the proportions are\r\nspecified}\r\n\\end{table}\r\n\r\nCommon performance metrics for the two class problem are sensitivity (TP), specificity (TN), precision (the proportion of predicted cases within a class that were correct), and accuracy (the overall proportion of correct predictions). These metric can be extended to more than two classes by defining $A=tr ( C ) / || C ||_{L^\\infty}$ where $C$ is the confusion matrix. TP, FN, FP, TN are proportions defined for the two class problem.\r\n\r\n\r\n\\section*{Covariance Matrix Estimation } For numerical stability in regression algorithms, the covariance matrix needs to be positive definite.  An well conditioned estimator for the covariance matrix of a process can be obtained by mixing the sample covariance with the identity matrix.  This is a linear shrinkage estimator based on a modified Frobenius norm for $A \\in M_{mn}$  \\begin{equation} ||\\mathbf{A}||_{\\cal{F}}= \\sqrt{ \\frac{tr (A A^t)}{n}} \\end{equation}  Without loss of generality, set $\\mu =0$ and let $\\widehat{\\Sigma} = \\alpha \\mathbb{I} + \\beta \\mathbf{S}$ where $\\mbf{S}=\\frac{\\mbf{X}^T \\mbf{X}}{n}$ is the sample covariance.  We seek to minimize $E( ||\\widehat{\\Sigma} - \\Sigma||^2)$, but since we don't know the true population covariance matrix, we have to form an approximation.\r\n\r\nMany applications in statistics and machine learning require an estimate of the covariance matrix or it's inverse. Generally we avoid taking inverses of matrices in practice for stability reasons. The sample covariance matrix usually performs poorly as a proxy for the underlying covariance matrix.  There is a large literature on this subject; particularly fomr the finance industry where this is an important part of portfolio theory.two major challenges in covariance estimation are the positive-defniteness constraint and the high-dimensionality where the number of parameters grows quadratically in the dimension.\r\n\r\n\\section*{Testing For Normality}In this section we will use the term $EPDF_X$ to mean the empirical probability density function. There are a variety of univariate tests to help determine which parametric distribution your data belongs to. These fall under the category of Goodness of Fit testing. For a parametric family the null hypothesis $H_o : X=_d p(x| \\theta)$ is tested against the alternative that $X$ does not belong to the family $p(x|\\theta)$ There are also family of test to determine whether two $EPDF$'s come from the same distribution.  Keep in mind that there are many transformations ( polynomial, logarithmic, \\& rational )  to transform data to look more Normal.  The presence of tails and skew will be the most problematic to deal with.\r\n\r\nThe Anderson-Darling test determines whether a sample comes from a specified distribution. The sample data can is transformed to a uniform distribution and then a uniformity test is then done on the transformed data. The test statistic is compared against pre-computed values for the assumed probability distribution.\r\n\r\nThe Kolmogorov-Smirnov is non-parametric a form of minimum distance estimation.  It can be used to test a sample against a reference or to compare two samples against each other.  In the one sided case the KS statistic calculates the distance between the $EPDF$ of a sample and a reference.  In the two sided case the distance between the $EPDS$'f of the two samples are calculated.  The KS test is robust to location and shape, making it  Omnibus tests evaluate whether the explained variance in a set of data is significantly greater than the unexplained variance. For example is the F-test in ANOVA. Omnibus tests of normality based on the likelihood ratio outperform the Anderson-Darling test statistic.\r\n\r\n", "meta": {"hexsha": "cb995b790c91c824b70f98ec1e1d97fad51991de", "size": 28922, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix_Statistics.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_Statistics.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_Statistics.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": 184.2165605096, "max_line_length": 4365, "alphanum_fraction": 0.732037895, "num_tokens": 7911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6599869097625196}}
{"text": "\\chapter{P-positions and N-positions}\n\\label{chapter:combinatorial-games}\n\\marginpar{%\n  This part is based on Part I of\n  ``Game Theory''\n  by Ferguson.\n}\n\\marginurl{%\n    Combinatorial Games:\\\\\\noindent\n    Introduction to Combinatorial Game Theory \\#1\n}{youtu.be/DbCKHPlMN2c}\nIn this part we use our knowledge about basics of mathematical reasoning\nto study games similar to checkers, chess, shogi, and tic tac toe. The games we\nare going to study are called combinatorial games. In these games there are two\nplayers, each know all the information, there are no chance moves, and when the\ngame ends there is always a winner.\n(The last condition implies that among the aforementioned games only checkers\nare combinatorial since all of them allow draws; however, we may change the\nrules to disallow the draws and this change would make all of them\ncombinatorial.) Such a game is determined by a set of positions, and possible\nmoves from each position for each player. Usually, players are taking turns\nuntil they reach a position such that no moves are possible and one of the\nplayer is declared a winner.\n\n\\section{Take-Away Game}\n\nSince chess, shogi and even tic tac toe are relatively complicated,\nwe are going to start from much simpler example of combinatorial games.\n\\begin{game}[Take-Away Game]\n\\label{game:take-away-21-3-2-1}\n  In this game there are two players.\n  \\begin{itemize}\n    \\item They have a pile of $21$ chips.\n    \\item They make moves in turns with player I starting,\n      each move consists of moving one, two or three chips out of the pile.\n    \\item The player that removes the last chip wins.\n  \\end{itemize}\n\\end{game}\nThe question we would like to answer is whether there is a strategy for one of\nthe players to always win. So in the rest of this part we assume that both\nplayers are playing optimally; i.e., if there is a winning strategy they follow\nthe strategy.\n\nTo analyze this game we need the following two observations:\n\\begin{enumerate}\n  \\item the game is symmetric and the only difference between the players is\n    who makes the first move, and\n  \\item if at some point the players have $n$ chips it does not matter how they\n    achieved this, it will not affect the rest of the game.\n\\end{enumerate}\nUsing these remarks and induction (this style of induction is sometimes\nreferred as \\emph{backward induction}) we are able to analyze the game.\n\nLet us consider some certain states of the game.\nAssume that they have at most $3$ chips left, in this case the player that make\nthe move wins. However, if there are $4$ chips, the\nplayer that makes the first move should always take at least $1$ chip so she\nloses since after her turn there are at most $3$ chip. Similarly, if there\nare $5$ chips, the first player to move wins since she can take a chip and\nmake the second player to start with $4$.\n\nSo we can formulate the following conjecture.\nAssume that $n$ chips left in the pile. Let $r$ be the remainder of $n$ modulo\n$4$. Then if $r = 0$, the first player to move loses, otherwise, the other\nplayer loses.\n\nLet us prove this using induction. We already proved the base case so\nwe need to prove the induction step from $n$ to $n + 1$.\n\\begin{itemize}\n  \\item If $n \\equiv 0 \\pmod{4}$, then the first player to move can remove one\n    chip and the other player will start with $n$ chips so by the induction\n    hypothesis he/she loses.\n  \\item If $n \\equiv 1 \\pmod{4}$, then the first player to move can remove two\n    chips and the other player will start with $n$ chips so by the induction\n    hypothesis he/she loses.\n  \\item If $n \\equiv 2 \\pmod{4}$, then the first player to move can remove three\n    chips and the other player will start with $n$ chips so by the induction\n    hypothesis he/she loses.\n  \\item If $n \\equiv 3 \\pmod{4}$, then after the current player moves the other\n    player will start with either $n$, or $n - 1$, or $n - 2$ chips. But all\n    these numbers have non-zero remainders modulo $4$. So the other player\n    can win in any case.\n\\end{itemize}\n\nTo study combinatorial games we need to give a formal definition of them.\n\\begin{definition}\n  A game is combinatorial if\n  \\begin{itemize}\n    \\item there are two players,\n    \\item there is a set of possible positions in the game,\n    \\item for each position and each player, there is a fixed set of possible\n      legal moves,\n    \\item players alternate moving,\n    \\item the game ends when no moves are possible for the player whose\n      turn is to move.\n  \\end{itemize}\n  There are possible winning conditions,\n  \\begin{description}\n    \\item [normal play rule:] the player that made the last move wins, and\n    \\item [mis\\`ere play rule:] the player that made the last move loses.\n  \\end{description}\n  If the game never ends, we declare a draw. If the game always ends, we\n  say that the game satisfies \\emph{the ending condition}.\n\n  If the possible moves are the same for both players the game is\n  called \\emph{impartial} otherwise it is called \\emph{partisan}.\n\\end{definition}\n\nNote that these games do not allow random moves, hidden information,\nsimultaneous moves, and a draw in a finite number of steps so\npoker, battleships, rock-paper-scissors, and tic tac toe are not\ncombinatorial games.\n\nSince we gave a formal definition of combinatorial games we can give a framework\nthat allows to analyze these games.\n\\marginurl{%\n    P-positions and N-positions:\\\\\\noindent\n    Introduction to Combinatorial Game Theory \\#2\n}{youtu.be/YV_oWBi1_ck}\n\\begin{definition}\n  We say that a position in a combinatorial game is \\emph{terminal} if there\n  are no legal moves.\n\n  All terminal positions are \\emph{P-positions}. Every position that allows for\n  the current player to move to a P-position is an \\emph{N-position}. If all\n  possible moves lead to N-positions, then the position is a P-position.\n\n  For the game using the Mis\\`ere rule, the definition is the same except the\n  terminal positions are N-positions.\n\\end{definition}\n\nUsing this definition, one may create the following procedure that would allow\nto determine which positions are P-positions and which are N-positions.\n\\begin{template}\n  \\textbf{Steps necessary to find P- and N-positions} \\\\\n\n  \\begin{enumerate}\n    \\item Label all terminal positions as P-positions.\n    \\item If some position is not labeled but all the moves lead to labeled\n      positions, then label the position using the definition; i.e., if there\n      are moves leading to P-position, it is an N-position, otherwise it is a\n      P-position.\n    \\item If not all the positions are labeled, go to Step~2.\n  \\end{enumerate}\n\\end{template}\n\n\nNote that P- and N-positions are defined recursively so in some games not all\nthe positions are either P- or N-positions. (For example, if there are no\nterminal positions.) However, \\Cref{theorem:grundy-to-np}\nproves that if the game satisfies the ending condition, then all the positions\nare either P- or N-positions.\n\n\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{l l l l l l l l l}\n      \\toprule\n      0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\\\\n      \\midrule\n      P & N & N & N & P & N & N & N & P \\\\\n      \\bottomrule\n  \\end{tabular}\n  \\caption{P-positions and N-positions for \\Cref{game:take-away-21-3-2-1}}\n  \\label{table:take-away-21-3-2-1}\n\\end{table}\n\n\nSo in \\Cref{game:take-away-21-3-2-1} the only terminal position is $0$;\nhence, $0$ is a P-position. Similarly we can go to $0$ from $1$, $2$, and\n$3$ so they are N-positions. Hence, $4$ is a P-position,\nsince all the moves from $4$ lead to N-positions.\n\\begin{exercise}\n  Show that a position $n$ is a P-position if $4$ divides $n$, and\n  it is an N-position otherwise.\n\\end{exercise}\n\nIn other words, in this game, P-positions coincide with the positions where the\ncurrent player loses. However, it is not a coincidence.\n\\begin{theorem}\n  If some position in a combinatorial game is an N-position, then the player to\n  move has a winning strategy if we start from this position. If the position\n  is a P-position, then the other player has a winning strategy.\n\\end{theorem}\n\n\\subsection{Subtractraction Games}\nLet us define a big class of games that generalizes the take-away game we\ndiscussed at the beginning of the chapter.\n\\begin{game}\n  Let $S \\subseteq \\N$ be some set. The subtraction game with the subtraction\n  set $S$ is the following combinatorial game.\n  Two players start with a pile of $n$ chips.\n  On each move they remove $s \\in S$ chips out of the pile.\n\\end{game}\n\nSo \\Cref{game:take-away-21-3-2-1} is the subtraction game with the subtraction\nset $\\set{1, 2, 3}$.\n\nLet us analyze the subtraction game with the subtraction set $\\set{1, 3, 4}$.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{l l l l l l l l l}\n      \\toprule\n      0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\\\\n      \\midrule\n      P & N & P & N & N & N & N & P & N \\\\\n      \\bottomrule\n  \\end{tabular}\n  \\caption{P-positions and N-positions for \\Cref{game:take-away-21-3-2-1}}\n  \\label{table:subtraction-4-3-1}\n\\end{table}\nClearly $0$ is a P-position since it is the only terminal position in the game.\nWe can go to $0$ from $1$ so $1$ is an N-position. The only possible move from\n$2$ is to $1$ so $2$ is a P-position. From $3$ and $4$ we can go to $0$\nso they are N-positions. From $5$ and $6$ one may go to $2$ so they are a\nN-positions as well. Hence, $7$ is a P-position.\n\nNow we may notice the pattern: $n$ is a P-position iff $n \\equiv 0 \\pmod{7}$\nor $n \\equiv 2 \\pmod{7}$. We prove is using induction. The base case for $n < 8$\nwe already proved. Let us now prove the induction step. Assume that the\nstatement is true for all $k < n$. Consider the following cases.\n\\begin{enumerate}\n  \\item If $n \\equiv 0 \\pmod{7}$, the current player can move to\n    $n - 1 \\equiv 5 \\pmod {7}$, $n - 3 \\equiv 4 \\pmod {7}$, or\n    $n - 3 \\equiv 5 \\pmod {7}$ which are all N-positions so $n$ is a P-position.\n  \\item If $n \\equiv 1 \\pmod{7}$, the current player can move to $n - 1$ which\n    is a P-position so $n$ is an N-position.\n  \\item If $n \\equiv 2 \\pmod{7}$, the current player can move to\n    $n - 1 \\equiv 1 \\pmod {7}$, $n - 3 \\equiv 6 \\pmod {7}$, or\n    $n - 4 \\equiv 5 \\pmod {7}$ which are all N-positions so $n$ is a P-position.\n  \\item If $n \\equiv 3 \\pmod{7}$, the current player can move to $n - 1$ which\n    is a P-position so $n$ is an N-position.\n  \\item If $n \\equiv 4 \\pmod{7}$, the current player can move to $n - 4$ which\n    is a P-position so $n$ is an N-position.\n  \\item If $n \\equiv 5 \\pmod{7}$, the current player can move to $n - 3$ which\n    is a P-position so $n$ is an N-position.\n  \\item If $n \\equiv 6 \\pmod{7}$, the current player can move to $n - 4$ which\n    is a P-position so $n$ is an N-position.\n\\end{enumerate}\n\n\n\\begin{chapterendexercises}\n  \\exercise\n    Two players I and II are playing the following game.\n    \\begin{itemize}\n      \\item They start with a number $0$ written on a blackboard.\n      \\item On each step one of the players replace a number $n$ on the\n        blackboard by either $n + 1$ or by $n + 2$.\n      \\item Player I makes the first move and players do moves one\n        after another.\n      \\item The player who writes $20$ wins.\n    \\end{itemize}\n    Who has a winning strategy?\n    (Note that the game is not a combinatorial game).\n  \\exercise\n    Two players I and II are playing the following game.\n    \\begin{itemize}\n      \\item Initially, there are $20$ numbers written on a blackboard:\n        $10$ numbers $1$ and $10$ numbers $2$.\n      \\item On each step one of the players select two numbers;\n        and if they were the same, replace them by $2$;\n        otherwise, replace them by $1$.\n      \\item Player I makes the first move and players do moves one\n        after another.\n    \\end{itemize}\n    Who is the winner? (Note that the game is not a combinatorial game).\n  \\exercise Consider the subtraction game where players may subtract $2$ and $3$\n    chips on their turn, is $5$ an N-position?\n  \\exercise Consider the Mis\\`ere subtraction game where players may subtract\n    $1$, $2$ or $5$ chips on their turn, identify N-positions and\n    P-positions.\n  \\exercise Consider the Mis\\`ere subtraction game where players may subtract\n    $1$, $5$ or $6$ chips on their turn, identify N-positions and\n    P-positions.\n  \\exercise\n    In the subtraction game where players may subtract $1$, $2$, or $5$ chips\n    on their turn, identify N-positions and P-positions.\n  \\exercise Two players one by one put bishops on the chessboard such that none\n    of the bishops attack each other. Determine the winning strategy.\n  \\exercise Consider the following game: two players I and II are writing an\n    $11$-digit number from left to right, one digit after another. Player I\n    wins  if $7$ divides the number and player II wins otherwise.\n    Determine who is the winner if player I makes the first move.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "02831fcb73f878028b21542e4f4a2f151576bbab", "size": 12857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_2/chapter_10_p_n_positions.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_2/chapter_10_p_n_positions.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_2/chapter_10_p_n_positions.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": 45.1122807018, "max_line_length": 80, "alphanum_fraction": 0.712141246, "num_tokens": 3621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6599869097625196}}
{"text": "\\section{HW2}\n%\\begin{enumerate}\n\\begin{QandA}\n\t\\item Translate the following sentences into Predicate Logic. \t\n\t(You may choose your own letters to serve as non-logical constants,)\n\t\\begin{QandA}\n\t\t\\item If one person is taller than another person and that second person is taller than a third one, then the first is taller than the third one.\n\t\t\\begin{answered}\n\t\t\t$(\\forall x)(\\forall y)(\\forall z)(\\text{person}(x) \\land \\text{person}(y) \\land \\text{person}(z) \\land \n\t\t\tx \\ne y \\land x \\ne z \\land y \\ne z \\land \\text{taller}(x, y) \\land \\text{taller}(y,z)) \\rightarrow (\\text{taller}(x,z))$\n\t\t\\end{answered}\n\t\t\n\t\t\\item If one number is between two other numbers, then neither of the two others is between it and the third one.\n\t\t\\begin{answered}\n\t\t\t$(\\forall a)(\\forall b)(\\forall c)(\\text{number}(a) \\land \\text{number}(b) \\land \\text{number}(c) \\land a < b \\land b < c)\n\t\t\t\\rightarrow (\\neg (b < a \\land a < c) \\land \\neg (b < c \\land c < a))$\n\t\t\\end{answered}\n\t\t         \n\t\t\\item If you move a wolf, a goat and a cabbage across a river and you have a boat that can hold two but no more than two of the four of you, then there is exactly one strategy (for getting all of you safely across) .\n\t\t(N.B. you do not need to translate the part in parentheses.)\n\t\t\\begin{answered}\n\t\t\t$(\\forall x)(\\forall y)(\\forall z)(\\forall k)(\\forall w)(\\text{wolf}(x) \\land \\text{goat}(y) \\land \\text{cabbage}(z) \\land \n\t\t\t\\text{you}(k) \\land \\text{boat}(w) \\land (\\text{canHold}(w,\\lbrace x \\rbrace) \\land \\text{canHold}(w,\\lbrace y \\rbrace) \\land \\text{canHold}(w,\\lbrace z \\rbrace)\n\t\t\t\\land \\text{canHold}(w,\\lbrace k \\rbrace) \\land \\text{canHold}(w,\\lbrace x,y \\rbrace) \\land \\text{canHold}(w,\\lbrace x,z \\rbrace) \\land \\text{canHold}(w,\\lbrace x,k \\rbrace) \\land\n\t\t\t\\text{canHold}(w,\\lbrace y,z \\rbrace) \\land \\text{canHold}(w,\\lbrace y,k \\rbrace) \\land \\text{canHold}(w,\\lbrace z,k \\rbrace) \\land \\neg \\text{canHold}(w,\\lbrace x,y,z \\rbrace) \\land \n\t\t\t\\neg \\text{canHold}(w,\\lbrace x,y,k \\rbrace) \\land \\neg \\text{canHold}(w,\\lbrace x,z,k \\rbrace) \\land \\neg \\text{canHold}(w,\\lbrace y,z,k \\rbrace) \\land \\neg \\text{canHold}(w,\\lbrace x,y,z,k \\rbrace) \\land \\text{moveAcrossRiver}(x) \\land \\text{moveAcrossRiver}(y)\n\t\t\t\\land \\text{moveAcrossRiver}(z) \\land \\text{moveAcrossRiver}(k)) \\rightarrow \n\t\t\t(\\exists x)(\\text{strategy}(x) \\land \\text{True}(x)) \\land (\\forall y)((\\text{strategy}(y) \\land y \\ne x) \\rightarrow (\\neg \\text{True}(y)))$\n\t\t\\end{answered}\n\t\\end{QandA}\n\t\\item Give as many non-equivalent translations of sentence (a) into Predicate Logic as you can think of.\n\t\\begin{QandA}\n\t\t\\item Three girls met two boys.\n\t\t\\begin{answered}\n\t\t\t\\begin{itemize}\n\t\t\t\\item $(\\forall x)(\\forall y)(\\forall z)(\\forall a)(\\forall b)(\\text{girl}(x) \\land \\text{girl}(y) \\land \\text{girl}(z) \\land \n\t\t\tx \\ne y \\land y \\ne z \\land x \\ne z \\land \\text{boy}(a) \\land \\text{boy}(b) \\land a \\ne b \\land \n\t\t\t\\text{met}(\\lbrace x,y,z \\rbrace, \\lbrace a,b \\rbrace)$ \n\t\t\t\\footnote{\n\t\t\t$``\\text{met}\"$ in $ \\text{met}(\\lbrace x,y,z \\rbrace, \\lbrace a,b \\rbrace)$ has meaning of \n\t\t\t$\\lbrace \\alpha | (\\forall \\alpha)(\\forall \\beta)((\\text{function}(\\alpha) \\land \\text{function}(\\beta) \\land \\alpha \\ne \\beta) \n\t\t\t\\rightarrow (\\alpha \\in \\lbrace a, b \\rbrace ^ {\\lbrace x, y, z \\rbrace} \\land \\beta \\not\\in \\lbrace a, b \\rbrace ^ {\\lbrace x, y, z \\rbrace})) \\rbrace$ (we use PC loosely here as ). In words, $``\\text{met}\"$ is a set of functions that maps set $\\lbrace x,y,z \\rbrace$ to set \n\t\t\t$\\lbrace a,b \\rbrace$. $\\lbrace a, b \\rbrace ^ {\\lbrace x, y, z \\rbrace}$\n\t\t\trepresents all possible combinations of $``\\text{met}\"$ relation that can happen between boys and girls.}\n\t\t\t\\item $(\\forall x)(\\forall y)(\\forall z)(\\forall a)(\\forall b)(\\text{girl}(x) \\land \\text{girl}(y) \\land \\text{girl}(z) \\land \n\t\t\t\t\t\tx \\ne y \\land y \\ne z \\land x \\ne z \\land \\text{boy}(a) \\land \\text{boy}(b) \\land a \\ne b \n\t\t\t\t\t\t\\land \\text{met}(x,a) \\land \\text{met}(x,b) \\land \\text{met}(y,a) \\land \\text{met}(y,b) \\land \\text{met}(z,a) \\land \n\t\t\t\t\t\t\\text{met}(z,b)\n\t\t\t\t)$\n\t\t\t\\end{itemize}\n\t\t\\end{answered}\n\t\\end{QandA}\n\t\n\t\\item (Note well: this exercise consists of 4 parts: a, b, c and d.)\n\t\\begin{QandA}\n\t\t\\item Translate the following sentences into Predicate Logic. Use the 1-place predicate P for ‘person’ and the 2-place predicate R for `met’.\n\t\t\\begin{QandA}\n\t\t\t\\item No one has met everyone.\n\t\t\t\\begin{answered}\n\t\t\t\t$(\\forall x)(\\exists y)(P(x) \\land P(y) \\land x \\ne y \\land \\neg R(x,y))$\n\t\t\t\\end{answered}\n\t\t\t\\item No one has met anyone.\n\t\t\t\\begin{answered}\n\t\t\t\t$\\neg ((\\exists x)(\\exists y)(P(x) \\land P(y) \\land x \\ne y \\land R(x,y)))$\n\t\t\t\\end{answered}\n\t\t\t\\item No one has met no one.\n\t\t\t\\begin{answered}\n\t\t\t\t$(\\forall x)(\\exists y)(P(x) \\land P(y) \\land x \\ne y \\land R(x,y))$\n\t\t\t\\end{answered}\n\t\t\t\\item If someone has met no one, then no one has met everyone.\n\t\t\t\\begin{answered}\n\t\t\t\t$(\\exists x)(\\forall y)((P(x) \\land P(y) \\land x \\ne y \\land \\neg R(x,y)) \\rightarrow \n\t\t\t\t(\\neg (\\exists z)(P(z) \\land z \\ne y \\land R(z,y)))$\n\t\t\t\\end{answered}\n\t\t\t\\item If someone has met someone, then it is not the case that no one has met anyone.\n\t\t\t\\begin{answered}\n\t\t\t\t$((\\exists x)(\\exists y)(P(x) \\land P(y) \\land x \\ne y \\land R(x,y)) \\rightarrow \n\t\t\t\t(\\neg (\\forall x)(\\forall y)(P(x) \\land P(y) \\land x \\ne y \\land \\neg R(x,y)))$\n\t\t\t\\end{answered}\n\t\t\\end{QandA}\n\t\t\\item Let $M = \\langle U,I \\rangle$ be the following model for the language ${P,R}$:\n\t\t\\begin{align*}\n\t\t\t  & U = \\lbrace a,b,c,d \\rbrace                                                   \\\\\n\t\t\t  & I(P) = U (\\text{so every individual in the universe of M is a person})        \\\\\n\t\t\t  & I(R) = \\lbrace <a,b>, <a,c>, <a,d>, <b,a>, <c,a>, <d,a>, <c,d>, <d,c>,\\rbrace \n\t\t\\end{align*}\n\t\t\\begin{QandA}\n\t\t\t\\item Which of the sentences (i)-(v) are true in M and which false, assuming that the words \n\t\t\tno one, everyone, anyone, someone range over persons and that R translates the transitive verb meet?\n\t\t\t\\begin{answered}\n\t\t\t\t(i), (ii), (iv) are false and (iii), (v) are true.\n\t\t\t\\end{answered}\n\t\t\t\\item Go through the calculation of the truth value in M of (i) by applying the truth definition for PC to the translation of (i) into PC you have given under (a).\n\t\t\t\\begin{answered}\n\t\t\t\t\\begin{align*}\n\t\t\t\t & \\llbracket (\\forall x)(\\exists y)(P(x) \\land P(y) \\land x \\ne y \\land \\neg R(x,y)) \\rrbracket_{M,a} = 1  \\\\\n\t\t\t\t\\text{iff} & \\; \\text{for every} \\; a' \\approx_{x} a \\quad \\llbracket (\\exists y)(P(x) \\land P(y) \\land x \\ne y \\land \\neg R(x,y)) \\rrbracket_{M,a'} = 1 \\\\\n\t\t\t\t\\text{iff} & \\; \\text{for every} \\; a' \\approx_{x} a \\; \\text{for some} \\; a'' \\approx_{y} a' \\quad \\llbracket (P(x) \\land P(y) \\land x \\ne y \\land \\neg R(x,y)) \\rrbracket_{M,a''} = 1 \\\\\n\t\t\t\t\\text{iff} &\\; \\text{for every} \\; a' \\approx_{x} a \\; \\text{for some} \\; a'' \\approx_{y} a' \\quad \n\t\t\t\t\\langle \\llbracket x \\rrbracket_{M,a''} \\rangle \\in I_{M}(P) \\; and \\; \\\\\n\t\t\t\t& \\langle \\llbracket y \\rrbracket_{M,a''} \\rangle \\in I_{M}(P)\n\t\t\t\t\\; and \\;  \\llbracket x \\rrbracket_{M,a''} \\ne \\llbracket y \\rrbracket_{M,a''} \\; and \\; \\llbracket R(x,y) \\rrbracket_{M,a''} = 0 \\\\\n\t\t\t\t\\text{iff} &\\; \\text{for every} \\; a' \\approx_{x} a \\; \\text{for some} \\; a'' \\approx_{y} a' \\quad \n\t\t\t\t\\langle \\llbracket x \\rrbracket_{M,a''} \\rangle \\in I_{M}(P) \\; and \\; \\\\\n\t\t\t\t& \\langle \\llbracket y \\rrbracket_{M,a''} \\rangle \\in I_{M}(P)\n\t\t\t\t\\; and \\;  \\llbracket x \\rrbracket_{M,a''} \\ne \\llbracket y \\rrbracket_{M,a''} \\; and \\; \n\t\t\t\t\\langle \\llbracket x \\rrbracket_{M,a''}, \\llbracket y \\rrbracket_{M,a''} \\rangle \\not\\in I_{M}(R) \\\\\n\t\t\t\t\\text{iff} &\\; \\text{for every} \\; a' \\approx_{x} a \\; \\text{for some} \\; a'' \\approx_{y} a' \\quad \n\t\t\t\t\\langle a''(x) \\rangle \\in I_{M}(P) \\; and \\; \\\\\n\t\t\t\t& \\langle a''(y) \\rangle \\in I_{M}(P)\n\t\t\t\t\\; and \\;  a''(x) \\ne a''(y) \\; and \\; \n\t\t\t\t\\langle a''(x), a''(y) \\rangle \\not\\in I_{M}(R)\n\t\t\t\t\\end{align*}\n\t\t\t\tThe above statement is false because if we let $a''(x) = a$ and there is no such $a''(y)$ that can make whole PC to\n\t\t\t\ttrue. If $a''(y) = a$, then $a''(x) \\ne a''(y)$ is false. If $a''(y) = b$, then $\\langle a, b \\rangle \\in I_M(R)$,\n\t\t\t\twhich makes $\\langle a''(x), a''(y) \\rangle \\not\\in I_{M}(R)$ false. If $a''(y) = c$, then $\\langle a, c \\rangle \\in I_M(R)$,\n\t\t\t\twhich makes $\\langle a''(x), a''(y) \\rangle \\not\\in I_{M}(R)$ false.\n\t\t\t\\end{answered}\n\t\t\\end{QandA}\n\t\t\\item Which of the sentences (i)-(v), if any is/are true in all models for PC?\n\t\t\\begin{answered}\n\t\t\t(v)\n\t\t\\end{answered}\n\t\t\\item For each of the sentences (i)-(v) that is not true in M modify the interpretation of $I(M)$ in such a way that this sentence comes out true in the modified model. (But leave the Universe $U$ as it is!)\n\t\t\\begin{answered}\n\t\t\t\\begin{itemize}\n\t\t\t\\item (i) We modify the model by removing $\\langle a,b \\rangle$ from $I(R)$ \n\t\t\t\\item (ii) We modify the model by making $I(R) = \\lbrace \\langle a, a \\rangle \\rbrace$\n\t\t\t\\item (iv) We modify the model by removing $\\langle a,b \\rangle, \\langle a,c \\rangle, \\langle a,d \\rangle$ from $I(R)$ \n\t\t\t\\end{itemize}\n\t\t\\end{answered}\n\t\\end{QandA}\n\t%\\end{enumerate}\n\\end{QandA}", "meta": {"hexsha": "3bb830042e5798c4252786c0fb806b721461ea3a", "size": 9060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/380M-hans/hw2.tex", "max_stars_repo_name": "xxks-kkk/Code-for-blog", "max_stars_repo_head_hexsha": "3d5ae181f2b6c986f3dc1977d190847757d30834", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-10-04T08:20:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-11T23:43:59.000Z", "max_issues_repo_path": "2018/380M-hans/hw2.tex", "max_issues_repo_name": "xxks-kkk/Code-for-blog", "max_issues_repo_head_hexsha": "3d5ae181f2b6c986f3dc1977d190847757d30834", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-10-22T20:10:50.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-22T20:10:50.000Z", "max_forks_repo_path": "2018/380M-hans/hw2.tex", "max_forks_repo_name": "xxks-kkk/Code-for-blog", "max_forks_repo_head_hexsha": "3d5ae181f2b6c986f3dc1977d190847757d30834", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2017-12-26T09:02:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T05:17:27.000Z", "avg_line_length": 67.6119402985, "max_line_length": 279, "alphanum_fraction": 0.61401766, "num_tokens": 3347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.659986907545979}}
{"text": "\\section{Derivatives of Exponential \\& Logarithmic Functions}\\label{sec:DerivativeExpLog}\r\nAs with the sine function, we don't know anything about derivatives that allows\r\nus to compute the derivatives of the exponential and logarithmic\r\nfunctions without going back to basics. Let's do a little work with\r\nthe definition again:\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}a^x&=&\\lim_{\\Delta x\\to 0} \\frac{a^{x+\\Delta x}-a^x}{\\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to 0} \\frac{a^xa^{\\Delta x}-a^x}{\\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to 0} a^x\\frac{a^{\\Delta x}-1}{\\Delta x}\\cr\r\n\\\\\r\n&=&a^x\\lim_{\\Delta x\\to 0} \\frac{a^{\\Delta x}-1}{\\Delta x}\\cr\r\n\\end{eqnarray*}\r\nThere are two interesting things to note here: As in the case of the\r\nsine function we are left with a limit that involves $\\Delta x$ but\r\nnot $x$, which means that if $\\ds \\lim_{\\Delta x\\to 0} (a^{\\Delta x}-1)/\\Delta x$ exists,\r\nthen it is a constant number. This means that $\\ds a^x$ has a remarkable property: its\r\nderivative is a constant times itself.\r\n\r\nWe earlier remarked that the hardest limit we would compute is\r\n$\\ds \\lim_{x\\to0}\\sin x/x=1$; we now have a limit that is just a bit too\r\nhard to include here. In fact the hard part is to see that\r\n$\\ds \\lim_{\\Delta x\\to 0} (a^{\\Delta x}-1)/\\Delta x$ even exists---does this fraction really get closer\r\nand closer to some fixed value? Yes it does, but we will not prove\r\nthis fact.\r\n \r\nWe can look at some examples. Consider $\\ds (2^x-1)/x$ for some small\r\nvalues of $x$: 1, $0.828427124$, $0.756828460$, $0.724061864$,\r\n$0.70838051$, $0.70070877$ when $x$ is 1, $1/2$, $1/4$, $1/8$, $1/16$,\r\n$1/32$, respectively. It looks like this is settling in around $0.7$,\r\nwhich turns out to be true (but the limit is not exactly $0.7$).\r\nConsider next $\\ds (3^x-1)/x$: $2$,  $1.464101616$,\r\n$1.264296052$, $1.177621520$, $1.13720773$, $1.11768854$, at the same\r\nvalues of $x$. It turns out to be true that in the limit this\r\nis about $1.1$. Two examples don't establish a pattern, but if you do\r\nmore examples you will find that the limit varies directly with the\r\nvalue of $a$: bigger $a$, bigger limit; smaller $a$, smaller limit. As\r\nwe can already see, some of these limits will be less than 1 and some\r\nlarger than 1. Somewhere between $a=2$ and $a=3$ the limit will be\r\nexactly 1; the value at which this happens is called $e$, so that\r\n$$\\lim_{\\Delta x\\to 0} {e^{\\Delta x}-1\\over \\Delta x}=1.$$ As you\r\nmight guess from our two examples, $e$ is closer to 3 than to 2, and\r\nin fact $e\\approx 2.718$.\r\n\r\nNow we see that the function $\\ds e^x$ has a truly remarkable property:\r\n\\begin{eqnarray*}\r\n{d\\over dx}e^x&=&\\lim_{\\Delta x\\to 0} {e^{x+\\Delta x}-e^x\\over \\Delta x}\\cr\\\\\r\n&=&\\lim_{\\Delta x\\to 0} {e^xe^{\\Delta x}-e^x\\over \\Delta x}\\cr\\\\\r\n&=&\\lim_{\\Delta x\\to 0} e^x{e^{\\Delta x}-1\\over \\Delta x}\\cr\\\\\r\n&=&e^x\\lim_{\\Delta x\\to 0} {e^{\\Delta x}-1\\over \\Delta x}\\cr\\\\\r\n&=&e^x\\cr\r\n\\end{eqnarray*}\r\nThat is, $\\ds e^x$ is its own derivative, or in other words the\r\nslope of $\\ds e^x$ is the same as its height, or the same as its second\r\ncoordinate: The function $\\ds f(x)=e^x$ goes through the point $\\ds (z,e^z)$\r\nand has slope $\\ds e^z$ there, no matter what $z$ is. It is sometimes\r\nconvenient to express the function $\\ds e^x$ without an exponent, since\r\ncomplicated exponents can be hard to read. In such cases we use\r\n$\\exp(x)$, e.g., $\\ds \\exp(1+x^2)$ instead of \r\n$\\ds e^{1+x^2}$.\r\n\r\nWhat about the logarithm function? This too is hard, but as the\r\ncosine function was easier to do once the sine was done, so is the\r\nlogarithm easier to do now that we know the derivative of the\r\nexponential function. Let's start with $\\ds \\log_e x$, which as you\r\nprobably know is often abbreviated $\\ln x$ and called the ``natural\r\nlogarithm'' function.\r\n\r\nConsider the relationship between the two functions,\r\nnamely, that they are inverses, that one ``undoes'' the\r\nother. Graphically this means that they have the same graph except\r\nthat one is ``flipped'' or ``reflected'' through the line $y=x$:\r\n\\figure[!ht]\r\n\\centerline{\\vbox{\\beginpicture\r\n\\normalgraphs\r\n%\\ninepoint\r\n\\setcoordinatesystem units <1truecm,1truecm> point at 0 0\r\n\\setplotarea x from -2 to 2, y from 0 to 4\r\n\\axis left shiftedto x=0 /\r\n\\axis bottom shiftedto y=0 /\r\n\\setquadratic\r\n\\plot  -2.000 0.250 -1.867 0.274 -1.733 0.301 -1.600 0.330 -1.467 0.362 \r\n-1.333 0.397 -1.200 0.435 -1.067 0.477 -0.933 0.524 -0.800 0.574 \r\n-0.667 0.630 -0.533 0.691 -0.400 0.758 -0.267 0.831 -0.133 0.912 \r\n0.000 1.000 0.133 1.097 0.267 1.203 0.400 1.320 0.533 1.447 \r\n0.667 1.587 0.800 1.741 0.933 1.910 1.067 2.095 1.200 2.297 \r\n1.333 2.520 1.467 2.764 1.600 3.031 1.733 3.325 1.867 3.647 \r\n2.000 4.000 /\r\n\\setcoordinatesystem units <1truecm,1truecm> point at -5 -2\r\n\\setplotarea x from 0 to 4, y from -2 to 2\r\n\\axis left shiftedto x=0 /\r\n\\axis bottom shiftedto y=0 /\r\n\\setquadratic\r\n\\plot 0.250 -2.000 0.375 -1.415 0.500 -1.000 0.625 -0.678 0.750 -0.415 \r\n0.875 -0.193 1.000 0.000 1.125 0.170 1.250 0.322 1.375 0.459 \r\n1.500 0.585 1.625 0.700 1.750 0.807 1.875 0.907 2.000 1.000 \r\n2.125 1.087 2.250 1.170 2.375 1.248 2.500 1.322 2.625 1.392 \r\n2.750 1.459 2.875 1.524 3.000 1.585 3.125 1.644 3.250 1.700 \r\n3.375 1.755 3.500 1.807 3.625 1.858 3.750 1.907 3.875 1.954 \r\n4.000 2.000 /\r\n\\endpicture}}\r\n\\caption{The exponential and logarithmic functions. \\label{fig:exponential and log functions}}\r\n\\endfigure\r\n\r\n\\noindent \r\nThis means that the slopes of these two functions are closely related\r\nas well: For example, the slope of $\\ds e^x$ is $e$ at $x=1$; at the\r\ncorresponding point on the $\\ln(x)$ curve, the slope must be $1/e$,\r\nbecause the ``rise'' and the ``run'' have been interchanged. Since the\r\nslope of $\\ds e^x$ is $e$ at the point $(1,e)$, the slope of $\\ln(x)$ is\r\n$1/e$ at the point $(e,1)$.\r\n\r\n\\figure\r\n\\centerline{\\vbox{\\beginpicture\r\n\\normalgraphs\r\n%\\ninepoint\r\n\\setcoordinatesystem units <1truecm,1truecm> point at 0 0\r\n\\setplotarea x from -2 to 2, y from 0 to 4\r\n\\axis left shiftedto x=0 /\r\n\\axis bottom shiftedto y=0 /\r\n\\setquadratic\r\n\\plot  -2.000 0.250 -1.867 0.274 -1.733 0.301 -1.600 0.330 -1.467 0.362 \r\n-1.333 0.397 -1.200 0.435 -1.067 0.477 -0.933 0.524 -0.800 0.574 \r\n-0.667 0.630 -0.533 0.691 -0.400 0.758 -0.267 0.831 -0.133 0.912 \r\n0.000 1.000 0.133 1.097 0.267 1.203 0.400 1.320 0.533 1.447 \r\n0.667 1.587 0.800 1.741 0.933 1.910 1.067 2.095 1.200 2.297 \r\n1.333 2.520 1.467 2.764 1.600 3.031 1.733 3.325 1.867 3.647 \r\n2.000 4.000 /\r\n\\setlinear\r\n\\plot -0.443 0 2 3.386 /\r\n\\setcoordinatesystem units <1truecm,1truecm> point at -5 -2\r\n\\setplotarea x from 0 to 4, y from -2 to 2\r\n\\axis left shiftedto x=0 /\r\n\\axis bottom shiftedto y=0 /\r\n\\setquadratic\r\n\\plot 0.250 -2.000 0.375 -1.415 0.500 -1.000 0.625 -0.678 0.750 -0.415 \r\n0.875 -0.193 1.000 0.000 1.125 0.170 1.250 0.322 1.375 0.459 \r\n1.500 0.585 1.625 0.700 1.750 0.807 1.875 0.907 2.000 1.000 \r\n2.125 1.087 2.250 1.170 2.375 1.248 2.500 1.322 2.625 1.392 \r\n2.750 1.459 2.875 1.524 3.000 1.585 3.125 1.644 3.250 1.700 \r\n3.375 1.755 3.500 1.807 3.625 1.858 3.750 1.907 3.875 1.954 \r\n4.000 2.000 /\r\n\\setlinear\r\n\\plot 0 -0.443 3.386 2 /\r\n\\endpicture}}\r\n\\caption{The exponential and logarithmic functions. \\label{fig:slope of exponential and log functions}}\r\n\\endfigure\r\n\r\nMore generally, we know that the slope of $\\ds e^x$ is $\\ds e^z$ at the point\r\n$\\ds (z,e^z)$, so the slope of $\\ln(x)$ is $\\ds 1/e^z$ at $\\ds (e^z,z)$.\r\nIn other words, the slope of $\\ln x$ is the reciprocal of the first\r\ncoordinate at any point; this means that the slope of $\\ln x$ at\r\n$(x,\\ln x)$ is $1/x$. The upshot is:\r\n$${d\\over dx}\\ln x = {1\\over x}.$$\r\nWe have discussed this from the point of view of the graphs, which is\r\neasy to understand but is not normally considered a rigorous\r\nproof---it is too easy to be led astray by pictures that seem\r\nreasonable but that miss some hard point. It is possible to do this\r\nderivation without resorting to pictures, and indeed we will see an\r\nalternate approach soon.\r\n\r\nNote that $\\ln x$ is defined only for $x>0$. It is sometimes useful to\r\nconsider the function $\\ln |x|$, a function defined for\r\n$x\\not=0$. When $x<0$, $\\ln |x|=\\ln(-x)$ and \r\n$${d\\over dx}\\ln |x|={d\\over dx}\\ln (-x)={1\\over -x}(-1)={1\\over x}.$$\r\nThus whether $x$ is positive or negative, the derivative is the same.\r\n\r\nWhat about the functions $\\ds a^x$ and $\\ds \\log_a x$? We know that the\r\nderivative of $\\ds a^x$ is some constant times $\\ds a^x$ itself, but what\r\nconstant? Remember that ``the logarithm is the exponent'' and you will\r\nsee that $\\ds a=e^{\\ln a}$. Then\r\n$$a^x = (e^{\\ln a})^x = e^{x\\ln a},$$\r\nand we can compute the derivative using the chain rule:\r\n$${d\\over dx} a^x = {d\\over dx}(e^{\\ln a})^x = {d\\over dx}e^{x\\ln a} = \r\n(\\ln a)e^{x\\ln a} =(\\ln a)a^x.$$\r\nThe constant is simply $\\ln a$. Likewise we can compute the derivative\r\nof the logarithm function $\\ds \\log_a x$. Since\r\n$$x=e^{\\ln x}$$\r\nwe can take the logarithm base $a$ of both sides to get\r\n$$\r\n\\log_a(x)=\\log_a(e^{\\ln x})=\\ln x \\log_a e.\r\n$$\r\nThen\r\n$${d\\over dx}\\log_a x = {1\\over x}\\log_a e.$$\r\nThis is a perfectly good answer, but we can improve it slightly.\r\nSince \r\n\\begin{eqnarray*}\r\na&=&e^{\\ln a}\\cr\r\n\\log_a(a) &=& \\log_a(e^{\\ln a}) = \\ln a\\log_a e\\cr\r\n1&=&\\ln a\\log_a e\\cr\r\n{1\\over \\ln a}&=&\\log_a e,\\cr\r\n\\end{eqnarray*}\r\nwe can replace $\\ds \\log_a e$ to get\r\n$${d\\over dx}\\log_a x = {1\\over x\\ln a}.$$\r\n\r\nYou may if you wish memorize the formulas.\r\n\r\n\\begin{formulabox}[Derivative Formulas for $a^x$ and $\\log_ax$]\r\n$${d\\over dx}a^x = (\\ln a)a^x \\quad \\hbox{and}\\quad\r\n{d\\over dx}\\log_a x = {1\\over x\\ln a}.$$\r\n\\end{formulabox}\r\n\r\nBecause the ``trick'' $\\ds a=e^{\\ln a}$ is often useful, and sometimes\r\nessential, it may be better to remember the trick, not the formula.\r\n\r\n\\begin{example}{Derivative of Exponential Function}{DerivativeExponentialFunction}\r\nCompute the derivative of $\\ds f(x)=2^x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n\\begin{eqnarray*}\r\n{d\\over dx}2^{x} &=& {d\\over dx}(e^{\\ln 2})^x\\\\\r\n\\\\\r\n&=& {d\\over dx}e^{x\\ln 2}\\\\\r\n\\\\\r\n&=& \\left({d\\over dx} x\\ln 2\\right) e^{x\\ln 2}\\\\\r\n\\\\\r\n&=& (\\ln 2)  e^{x\\ln 2}=2^x\\ln2\r\n\\end{eqnarray*}\\vspace{-0.2cm}\r\n\\end{solution}\r\n\r\n\\begin{example}{Derivative of Exponential Function}{DerivativeExponentialFunction2}\r\nCompute the derivative of $\\ds f(x)=2^{x^2}=2^{(x^2)}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n\\begin{eqnarray*}\r\n{d\\over dx}2^{x^2} &=& {d\\over dx}e^{x^2\\ln 2}\\\\\r\n\\\\\r\n&=& \\left({d\\over dx} x^2\\ln 2\\right) e^{x^2\\ln 2}\\\\\r\n\\\\\r\n&=& (2\\ln 2) x  e^{x^2\\ln 2}\\\\\r\n\\\\\r\n&= & (2\\ln 2) x 2^{x^2}\r\n\\end{eqnarray*}\\vspace{-0.2cm}\r\n\\end{solution}\r\n\r\n\\begin{example}{Power Rule}{PowerRule} \r\nRecall that we have not justified the power rule except when the\r\nexponent is a positive or negative integer.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe can use the exponential function to take care of other exponents.\r\n\\begin{eqnarray*}\r\n{d\\over dx}x^r&=&{d\\over dx}e^{r\\ln x}\\\\\r\n\\\\\r\n&=&\\left({d\\over dx}r\\ln x\\right)e^{r\\ln x}\\\\\r\n\\\\\r\n&=&(r{1\\over x})x^r\\\\\r\n\\\\\r\n&=&rx^{r-1}\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:DerivativeExpLog}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\nFind the derivatives of the functions.\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds 3^{x^2}$\r\n\\begin{sol}\r\n\t$\\ds 2\\ln(3)x3^{x^2}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds {\\sin x \\over e^x}$\r\n\\begin{sol}\r\n\t$\\ds {\\cos x-\\sin x \\over e^x}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds (e^x)^2$\r\n\\begin{sol}\r\n\t$\\ds 2e^{2x}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds \\sin(e^x)$\r\n\\begin{sol}\r\n\t$\\ds e^x\\cos(e^x)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds e^{\\sin x}$\r\n\\begin{sol}\r\n\t$\\ds  \\cos (x) e^{\\sin x}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds x^{\\sin x}$\r\n\\begin{sol}\r\n\t$\\ds x^{\\sin x}\\left(\\cos x\\ln x+{\\sin x\\over x}\\right)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds x^3e^x$\r\n\\begin{sol}\r\n\t$\\ds 3x^2e^x+x^3e^x$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds x+2^x$\r\n\\begin{sol}\r\n\t$\\ds 1+2^x\\ln(2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds (1/3)^{x^2}$\r\n\\begin{sol}\r\n\t$\\ds -2x\\ln(3)(1/3)^{x^2}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds e^{4x}/x$\r\n\\begin{sol}\r\n\t$\\ds e^{4x}(4x-1)/x^2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds \\ln(x^3+3x)$\r\n\\begin{sol}\r\n\t$\\ds (3x^2+3)/(x^3+3x)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds \\ln(\\cos(x))$\r\n\\begin{sol}\r\n\t$\\ds -\\tan(x)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds\\sqrt{\\ln(x^2)}/x$\r\n\\begin{sol}\r\n\t$\\ds (1-\\ln(x^2))/(x^2\\sqrt{\\ln(x^2)})$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds \\ln(\\sec(x) + \\tan(x))$\r\n\\begin{sol}\r\n\t$\\ds \\sec(x)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds x^{\\cos(x)}$\r\n\\begin{sol}\r\n\t$\\ds x^{\\cos(x)}(\\cos(x)/x-\\cos(x)\\ln(x))$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds x\\ln x$\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ln (\\ln (3x) )$\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds {1+\\ln (3x^2 )\\over 1+ \\ln(4x)}$\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind the value of $a$ so that the tangent line to\r\n$y=\\ln(x)$ at $x=a$ is a line through the origin.  Sketch the\r\n resulting situation.\r\n\\begin{sol}\r\n$e$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nIf $\\ds f(x) = \\ln(x^3 + 2)$ compute $\\ds f'(e^{1/3})$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}\r\n", "meta": {"hexsha": "3cf514da95ed441b4424f34cf3879666c4322f95", "size": 13323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-7-der-exp-log.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-7-der-exp-log.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-7-der-exp-log.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.8732057416, "max_line_length": 104, "alphanum_fraction": 0.6241086842, "num_tokens": 5282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.65998690399437}}
{"text": "\\chapter{Mathematical appendix}\n\\label{chap:math}\n\nIn this chapter, we shall review the intuition behind basic results in probability theory and stochastic calculus. We shall omit most of the measure theory needed and be pretty vague of the technical arguments.\n\nIn the following we let $(\\Omega, \\F)$ be a probability space with a measure $\\Pf$ be a probability measure. Here $\\Omega$ is the state space, $\\F$ is the $\\sigma$-algebra of $\\Omega$. Let $\\Pm$ be also a probability measure on the space $(\\Omega, \\F)$. If for all $A \\in \\F$, it holds that $\\Pf (A) = 0$ implies $\\Pm (A) = 0$, then we say that $\\Pm$ is absolutely continous with respect to $\\Pf$ on $\\F$ and we write $\\Pm \\ll \\Pf$. If $\\Pm \\ll \\Pf$ and $\\Pf \\ll \\Pm$, then the measures are said to be equivalent on $\\F$. Thus measures are equivalent if and only if their null sets are the same.\n\n\\section{Characteristic function and Fourier transformation}\n\nA probability distribution function of random variable $X$ is any measurable function $f_X$ that satisfies\n\t\\begin{align}\n\t\t\\Pf ( X \\in A ) = \\int_A f_X \\ \\dx \\mu\n\t\\end{align}\nfor all $A \\in \\F$, where $\\mu$ is the Lebesgue measure. The characteristic function $g_X$ is the function\n\t\\begin{align}\n\t\tg_X (\\omega) &= \\E_{\\Pf} \\left( \\e^{i \\omega X} \\right) \\\\\n\t\t\t&= \\int_{-\\infty}^{\\infty} \\e^{i \\omega x} f_X(x) \\ \\dx x\n\t\\end{align}\nif the expectation exists. This is just the Fourier transformation of the probability distribution function. If the characteristic function $g_X$ is integrable, then the inverse Fourier transformation gives\n\t\\begin{align}\n\t\tf_X = \\frac{1}{2 \\pi} \\int_{-\\infty}^{\\infty} \\e^{- i \\omega x} g_X x \\ \\dx x .\n\t\\end{align}\nAccording to \\cite{carrmadan1999optionvaluation}, Gil-Pelaez' Inversion gives that\n\t\\begin{align}\n\t\t\\Pf( x < X ) = \\frac{1}{2} - \\frac{1}{\\pi} \\int_0^{\\infty} \\frac{\\im \\left( \\e^{-i \\omega x} g_X( \\omega) \\right)}{ \\omega} \\ \\dx  \\omega\n\t\\end{align}\nand \n\t\\begin{align}\n\t\t\\Pf( x \\geq X ) = \\frac{1}{2} + \\frac{1}{\\pi} \\int_0^{\\infty} \\re \\left( \\frac{\\e^{-i  \\omega x} g_X( \\omega)}{ i  \\omega} \\right) \\ \\dx  \\omega .\n\t\\end{align}\t\n\n\\section{Radon-Nikod\\'{y}m-theorem and the change of measure}\n\\label{sec:radonnikodymtheorem}\n\nOne of the basic tool of the probability measures is the Radon-Nikod\\'{y}m-theorem. For the proof, see any basic text on the measure theory (for example, \\textcite[pp. 449-450]{billingsley2012probabilityandmeasure}). We recall that a function $f$ is $\\F$-measurable if $\\{ \\omega \\in \\Omega \\ | \\ f(\\omega) \\leq x \\} \\in \\F$ for any $x \\in \\R$.\n\n\\begin{thm}[Radon-Nikod\\'{y}m-theorem]\n\tIf $\\Pf$ and $\\Pm$ be probability measures on measurable space $(\\Omega, \\F)$ and $\\Pm \\ll \\Pf$, then there exists a non-negative $\\F$-measurable function $\\xi$ such that\n\t\\begin{align}\n\t&\\int_{\\Omega} \\xi \\ \\dx \\Pf < \\infty \\text{ and } \\\\\n\t\\Pm (A) = &\\int_A \\xi \\ \\dx \\Pf\n\t\\end{align}\n\tfor all $A \\in \\F$. The function $\\xi$ is $\\Pf$-unique and it is called as the Radon-Nikod\\'{y}m-derivate of $\\Pf$ with respect to measure $\\Pm$ and filtration $\\F$.\n\\end{thm}\n\nThe Radon-Nikod\\'{y}m-derivate of $\\Pf$ with respect to $\\Pm$ is denoted by\n\\begin{align}\n\\xi = \\frac{\\dx \\Pm}{\\dx \\Pf}\n\\end{align}\nand alternatively we may write\n\\begin{align}\n\\dx \\Pm = \\xi \\dx \\Pf .\n\\end{align}\nSince $\\Pm$ is a probability measure, it is clear that $\\E_{\\Pf} (\\xi) = 1$. \n\nIf $X = \\1_A$ for some $A \\in \\F$, then\n\\begin{align}\n\\E_{\\Pm} (X) = \\Pm (A) = \\int_A \\xi \\dx \\Pf = \\E_{\\Pf} ( \\1_A \\xi ) = \\E_{\\Pf} (\\xi X) .\n\\end{align}\nIf $X$ is integrable and $\\F$-measurable random variable, then we may approximate it with simple functions and we may conclude the following important consequence of the Radon-Nikod\\'{y}m-derivate.\n\n\\begin{lemma}\n\t\\label{radonnikodymconsequence}\n\tSuppose that the function $\\xi$ is the Radon-Nikod\\'{y}m-derivate of $\\Pf$ with respect to $\\Pm$. If $X$ is integrable and $\\F$-measurable random variable, then\n\t\\begin{align}\n\t\\E_{\\Pm} (X) = \\E_{\\Pf} ( \\xi X).\n\t\\end{align}\n\\end{lemma}\n\nConversely, if $\\xi$ is $\\F$-measurable, integrable and non-negative function with $\\E_{\\Pf} (\\xi) = 1$, then we may define a function $\\Pm : \\F \\rightarrow [0,1]$ by\n\\begin{align}\n\\label{RadonNikodymbyrandomvariable}\n\\Pm ( A ) = &\\int_A \\xi \\dx \\Pf = \\E_{\\Pf} ( \\1_A \\xi )\n\\end{align}\nfor all $A \\in \\F$. It is easy to see that $\\Pm$ is a probability measure on measurable space $(\\Omega, \\F)$ and $\\Pm \\ll \\Pf$. Also\n\\begin{align}\n\\xi = \\frac{\\dx \\Pm}{\\dx \\Pf} .\n\\end{align}\nBy Equation \\ref{RadonNikodymbyrandomvariable},\n\t\\begin{align}\n\t\t\\E_{\\Pm} (X) = \\E_{\\Pf} (X \\frac{\\dx \\Pm}{\\dx \\Pf} )\n\t\\end{align}\nholds for simple functions and, by limit argumentation, it holds for any integrable random variable. Heuristically\n\t\\begin{align}\n\t\t \\int_A X \\ \\dx \\Pm &= \\int_A X \\ \\dx \\Pf \\ \\frac{\\dx \\Pm}{\\dx \\Pf} \\\\\n\t\t \t&= \\int_A X \\ \\dx \\Pf \n\t\\end{align}\nfor all $A \\in \\F$.\n\n\\section{Conditional expectation}\n\nThe associated $\\sigma$-algebra $\\F$ can be seen as the known information structure. Random variables are $\\F$-measurable functions which means that the sets\\footnote{These sets generate the Borel algebra of the reals.} $\\{ \\ \\omega \\ | \\ X(\\omega) \\leq a \\ \\} \\in \\F$ for all $a \\in \\R$. This may be interpreted as that $\\F$-measurable functions are those functions whose outcome is known based on the information $\\F$.\n\nIf $\\F = \\{ \\emptyset, \\Omega \\}$, then only constant functions are $\\F$-measurable and knowning the value of random variable gives no information about the true state of the system $\\omega$. If $\\emptyset \\not = A \\subset \\Omega$ and $A \\in \\F$, then $\\1_A$ is $\\F$-measurable function. So if we know the value of $\\1_A$, we may deduce either $\\omega \\in A$ or $\\omega \\not \\in A$ although we may not have exact information about the true state $\\omega$ of the random system $\\Omega$. So if $\\G$ is a $\\sigma$-sub-algebra of $\\F$, then $\\F$ carries more information than $\\G$.\n\nLet $X$ be a $\\F$-measurable random variable and $\\G$ a $\\sigma$-sub-algebra of $\\F$ generated by partion $B_1, B_2, \\ldots, B_m$ of $\\Omega$. For simplicity, we assume that $X$ is simple, meaning that\n  \\begin{align}\n    X &= \\sum_{i=1}^n x_i \\1_{A_i}\n  \\end{align}\nwhere $x_i \\in \\R$ and $A_i \\in \\F$ for $i=1,2, \\ldots, n$ and the collection $A_1, A_2, \\ldots A_n$ is a partition of $\\Omega$. We denote $C_{ij} = A_i \\cap B_j$.\n\nIf we know that the event $B_j$ is true, then $X = x_i$ only if $C_{ij} \\not = \\emptyset$ and, in a sense, the average value of $X$ will be\n  \\begin{align}\n    y_j = \\sum_{i=1}^n x_i \\frac{\\Pf( C_{ij} )}{ \\Pf( B_j ) }\n  \\end{align}\nassuming that $\\Pf (B_j ) \\not = 0$. If $\\Pf (B_j ) = 0$, then\n  \\begin{align}\n    \\E (X \\1_{B_j} ) = 0\n  \\end{align}\nand we set $y_j = 0$. Now we may define a new random variable\n  \\begin{align}\n    Y = \\sum_{j=1}^m y_j \\1_{B_j} .\n  \\end{align}\nNow $Y$ is $\\G$-measurable and integrable. Furthermore,\n  \\begin{align}\n    \\E (X \\1_{B_j} ) &= \\sum_{i=1}^n \\E ( x_i \\1_{A_i} \\1_{B_j} ) \\\\\n      &= \\sum_{i=1}^n x_i \\Pf ( C_{ij} ) \\\\\n      &= y_j \\Pf ( B_j ) \\\\\n      &= \\E (Y \\1_{B_j} )\n  \\end{align}\nfor all $j = 1,2, \\ldots, m$. This motivates us to define the conditional expectation given a $\\sigma$-sub-algebra $\\G$.\n\nFor a fixed $\\F$-measurable and integrable random variable $X$, the conditional expectation of $X$ given $\\G$ is the random variable $\\E (X | \\G)$ with the following properties:\n  \\begin{enumerate}[label=\\roman*)]\n    \\item $\\E (X | \\G)$ is $\\G$-measurable and integrable,\n    \\item for every $G \\in \\G$,\n      \\begin{align}\n        \\label{conditionalsecondcond}\n        \\int_G X \\dx \\Pf = \\int_G \\E (X | \\G) \\dx \\Pf.\n      \\end{align}\n  \\end{enumerate}\n  \nThus conditional expectation is a random variable and \n\\begin{align}\n\t\\E (X) = \\E (\\E (X | \\G)).\n\\end{align} \nWe may use Radon-Nikod\\'{y}m-theorem or orthogonal projections in $\\Le^2$-space to prove the existance of a conditional expectations and it is unique $\\Pf$-surely. In the following, we shall not always make the distinction between sets or random variables that match everywhere or just $\\Pf$-everywhere. \n\nLet $X_i$ be the throw of a fair coin at the time $i$. So $X_i (\\omega) \\in \\{ 0, 1\\}$ with equal probabilities. For simplicity, we consider only two time periods $i=1,2$ and we code \n\t\\begin{align}\n\t\t\\Omega = \\{ \\ X_iX_j \\ | \\ i,j \\in \\{0,1\\} \\ \\} = \\{ \\ 00, 01, 10, 11 \\ \\},\n\t\\end{align} \nwith $\\Pf( \\omega ) = 1/4$ for all $\\omega \\in \\Omega$. Let $\\F = \\{ \\emptyset, \\Omega \\}$ and $X(ij)= X_1(i)+X_2(j)$. Now\n\\begin{align}\n\\E_{\\Pf} \\left( X \\ | \\ \\F \\right) = 1\n\\end{align}\nsince\n\t\\begin{align}\n\t\t\\int_\\emptyset X \\ \\dx \\Pf &= 0, \\\\\n\t\t\\int_\\Omega X \\ \\dx \\Pf &= 1 \\\\\n\t\\end{align}\nIf we know the result of the first throw, then we may pick \n\t\\begin{align}\n\t\t\\G = \\F \\ \\cup \\ \\{ 00, 01 \\} \\ \\cup \\ \\{ 10, 11 \\}\n\t\\end{align} \nNow\n\t\\begin{align}\n\t\t\\int_{ \\{ 00, 01 \\} } X \\ \\dx \\Pf &= \\frac{X_1(0) + X_1(0) + X_2(0) + X_2(1)}{4} = \\frac{1}{4}, \\\\\n\t\t\\int_{ \\{ 10, 11 \\} } X \\ \\dx \\Pf &= \\frac{X_1(1) + X_1(1) + X_2(0) + X_2(1)}{4} = \\frac{3}{4}, \\\\\n\t\t\\int_{ \\{ 00, 01 \\} } \\alpha \\ \\dx \\Pf &= \\frac{\\alpha}{2}, \\\\\n\t\t\\int_{ \\{ 10, 11 \\} } \\beta \\ \\dx \\Pf &= \\frac{\\beta}{2}, \\\\\n\t\\end{align}\nimplies that  $Y$ defined by $Y(00) = Y(01) = \\frac{1}{2}$ and $Y(10) = Y(11) = \\frac{3}{2}$ is the conditional expectation of $X$ over $\\G$ as now\n\t\\begin{align}\n\t\t\\int_G Y \\ \\dx \\Pf = \\int_G X \\ \\dx \\Pf\n\t\\end{align}\nfor all $G \\in \\G$.\n\nIf $\\G = \\{ \\emptyset, \\Omega \\}$, then $\\G$-measurable functions are constant functions. The integral over the empty set is zero for all integrable randon variables and \n      \\begin{align}\n        \\int_{\\Omega} X \\dx \\Pf = \\E (X) = \\int_{\\Omega} \\E (X) \\dx \\Pf.\n      \\end{align}\nWe see that $\\E (X | \\{ \\emptyset, \\Omega \\}) = \\E (X)$ and the conditional expectation gives no further information. If $X$ is $\\G$-measurable, then the equation \\ref{conditionalsecondcond} is trivially satisfied and we see that $X = \\E (X | \\G)$. In particular, $X = \\E (X | \\F)$ as $X$ is $\\F$-measurable.\n\nWe present some of the basic properties of conditional expectations.\n\n\\begin{thm}\nSuppose that $\\G$ and $\\Ho$ are sub-$\\sigma$-fields of $\\F$ and $X$ and $Y$ are integrable random variables. Then\n  \\begin{enumerate}[label=\\roman*)]\n    \\item $\\E \\left| \\E ( X | \\G ) \\right| \\leq \\E \\left| X \\right|$,\n    \\item $\\E (aX+bY | \\G ) = a\\E (X | \\G ) + b\\E (Y | \\G )$ for all $a,b \\in \\R$,\n    \\item if $X \\leq Y$, then $\\E (X| \\G) \\leq \\E (Y| \\G)$,\n    \\item $\\left| \\E (X | \\G) \\right| \\leq \\E (\\left| X \\right| | \\G)$,\n    \\item if $XY \\in \\Le^1 (\\Omega, P)$ and $Y$ if $G$-measurable, then $\\E (XY | \\G) = Y \\E (X | \\G)$,\n    \\item if $\\Ho \\subseteq \\G$, then $\\E ( \\E (X | \\G ) | \\Ho ) = \\E ( \\E (X | \\Ho ) | \\G ) =  \\E (X | \\Ho )$,\n    \\item if $\\sigma (X)$ and $\\G$ are independent, then $\\E (X | \\G) = \\E (X)$,\n    \\item if $P(G) \\in \\{ 0,1 \\}$ for all $G \\in \\G$, then $\\E (X | \\G) = \\E (X)$,\n  \\end{enumerate}\n\\end{thm}\n\nSee \\textcite[pp. 472--477]{billingsley2012probabilityandmeasure}\n\n\\section{Filtrations and martingales}\n\nA collection $(\\F_t)$  of $\\sigma$-sub-algebras of $\\F$ is called a filtration if $\\F_t \\subseteq F_s$ for all $0 \\leq t \\leq s$. Informally a filtration presents the flow of information. We assume some standard technical conditions for the filtrations. Every $\\Pf$-null set 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\nA stochastic process $X$ is a function $X : (\\R_+ \\cup \\{ 0 \\}) \\times \\Omega \\rightarrow \\R$. It is often written as $X = (X(t))$, where the argument $\\omega \\in \\Omega$ is dropped. It is then a collection of random variables with index set $\\{t \\geq 0\\}$. We say that the process $(X(t))$ is adapted to the filtration $(\\F_t)$ if $X(t)$ is $\\F_t$-measurable for each $t$. Thus the variable $X(t)$ of an adapted process contains the information of the process that has been accumulated so far.\n\nA $(\\F_t)$-adapted stochastic process is a martingale if $\\E_{\\Pf} \\left( \\left| X(t) \\right| \\right) < \\infty$ and\n  \\begin{align}\n    \\E_{\\Pf} ( X(s) \\ | \\ \\F_t ) = X(t)\n  \\end{align} \nfor all $0 \\leq t < s < \\infty$. Thus a martingale is a process, where the present value is the best estimate for the all future expected values given the past information contained in the process.\n\n\\section{A stopping time and localization}\n\\label{sec:stoppingtime}\n\nA random variable $\\tau : \\Omega \\rightarrow \\R_+ \\cup \\{ 0 \\}$ is a stopping time with respect to the filtration $\\F_t$ if\n\t\\begin{align}\n\t\t\\label{stoppingtimedefinition}\n\t\t\\{ \\ \\tau \\leq t \\ \\} = \\{ \\omega \\in \\Omega \\ | \\ \\tau(\\omega) \\leq t \\} \\in \\F_t\n\t\\end{align}\nholds for all $t \\geq 0$. This is equivalent to the existence of $(\\F_t)$-adapted random process $(X(t))$ that\n\t\\begin{align}\n\t\tX(t) = \\begin{cases} 0, \\ &t \\leq \\tau, \\\\ 1, \\ &t > \\tau . \\end{cases}\n\t\\end{align}\nIf $\\tau$ is time of a default, then the condition of the Equation \\ref{stoppingtimedefinition} means that at the time $t$ the information in the filtration will tell if the default has occured or not, that is $\\tau \\leq t$ or not.\n\nStopping times are used to localized behavior. For example, a local martingale is a $(\\F_t)$-adapted process \nif there is such a sequence $(\\tau_n)$ of stopping times that\n\t\\begin{align}\n\t\t\\Pf ( \\tau_n < \\tau_{n+1} ) &= 1,\n\t\t\\Pf ( \\lim\\limits_{n \\rightarrow \\infty} \\tau_n = \\infty ) &= 1,\n\t\\end{align}\nand the stopped process defined by\n\t\\begin{align}\n\t\tX_{\\tau_n}(t) = X( \\min(t, \\tau_n) )\n\t\\end{align}\nis a $(\\F_t)$-martingale for all $n \\geq 1$.\n\n\\section{Brownian motion}\n\nFor reference, see \\textcite[pp. 530--545]{billingsley2012probabilityandmeasure}\n\nIn order to keep notation efficient, we denote in this section\n\t\\begin{align}\n\t\t\\E_t( \\cdot ) = \\E_t( \\ \\cdot \\ | \\ \\F_t ) .\n\t\\end{align}\nWe also write $W(t, \\omega) = W(t)$.\n\nLet $(\\F_t)$ be a filtration of the probability space. A Brownian motion (or a Wiener process) $W(t), t \\geq 0$ with respect to filtration $(\\F_t)$ is a stochastic process satisfying the following\n  \\begin{enumerate}\n    \\item $W(0) = 0$ almost surely,\n    \\item $W(t)$ is $\\F_t$-measurable for each $ t\\geq 0$,\n    \\item $t \\mapsto W(t)$ is $\\Pf$-surely continuous,\n    \\item for any finite set of times $0 \\leq t_1 < t_2 < \\ldots < t_n \\leq T$, the random variables\n      \\begin{align}\n        W(t_2) - W(t_1), W(t_3) - W(t_2), \\ldots , W(t_n) - W(t_{n-1})\n      \\end{align}\n      are independent,\n    \\item $W(s) - W(t) \\sim N(0, s-t)$ for all $0 < t < s$.\n  \\end{enumerate}\nThese imply that $W(t) = W(t) - W(0) \\sim N(0,t)$ and\n  \\begin{align}\n    \\Var (W(s) - W(t) = \\E \\left( (W(s) - W(t)^2 \\right) = s - t\n  \\end{align}\nfor all $0 < t < s$.\n\nA Brownian motion $W(t)$ is indeed a martingale in respect to the natural filtration since $\\E_t ( W(s) - W(0 ) = 0$ and\n  \\begin{align}\n    \\E_t ( W(s) ) = \\E_t ( W(s) - W(t) + W(t) ) = \\E_t ( W(s) - W(t ) + W(t) = W(t) .\n  \\end{align}\nSimilarly $W(s)^2 = (W(s) - W(t)^2 + 2W(s)W(t) - W(t)^2$ implies that\n  \\begin{align}\n    \\E_t ( W(s)^2 -s ) &= \\E_t \\left( (W(s) - W(t)^2 + 2W(s)W(t) - W(t)^2 \\right) -s \\\\\n      &= \\Var_t (W(s) - W(t)) + 2 \\E_t (W(s)) W(t) - W(t)^2 - s \\\\\n      &= s-t + W(t)^2 - s \\\\ &= W(t)^2 -t\n  \\end{align}\nmeaning that $W(t)^2 - t$ is also a martingale.\n\nIf $f,g : [0,T] \\rightarrow \\R$ are functions, then the covariation of $f$ and $g$ up to time $T$ is\n  \\begin{align}\n    \\langle f,g \\rangle (T) = \\lim_{ \\left| \\Pi \\right| \\rightarrow 0} \\sum_{i=0}^{n-1} (f( t_{i+1} ) - f (t_i) )(g( t_{i+1} ) - g (t_i) ),\n  \\end{align}\nwhere $\\Pi = \\{ t_0, t_1, \\ldots , t_n \\}$, $0 = t_0 < t_1 < \\ldots < t_n = T$ is a partition with mesh $\\left| \\Pi \\right| = \\max_i ( t_{i+1} - t_{i} ) $. The quadratic variation of a function $f$ up to time $T$ is\n  \\begin{align}\n    \\langle f \\rangle_T = \\langle f,f \\rangle (T) = \\lim_{ \\left| \\Pi \\right| \\rightarrow 0} \\sum_{i=0}^{n-1} (f( t_{i+1} ) - f (t_i) )^2.\n  \\end{align}\n  \nIf the function $f$ has continuous derivate, then we may use intermediate value theorem to conclude that \n  \\begin{align}\n    \\sum_{i=0}^{n-1} (f( t_{i+1} ) - f (t_i) )^2 &= \\sum_{i=0}^{n-1} (f'(s_i))^2 (t_{i+1} - t_i)^2 \\\\\n      & \\leq \\left| \\Pi \\right| \\sum_{i=0}^{n-1} (f'(s_i))^2 (t_{i+1} - t_i),\n  \\end{align}\nfor some $t_i \\leq s_i \\leq t_{i+1}$ and where\n  \\begin{align}\n     \\sum_{i=0}^{n-1} (f'(s_i))^2 (t_{i+1} - t_i) \\rightarrow \\int_0^T (f'(t))^2 \\dx t < \\infty\n  \\end{align}\nas $\\left| \\Pi \\right| \\rightarrow 0$. Here we also used the continuity of $f'$ to keep the integral finite. This implies that $\\langle f \\rangle_T = 0$ for a smooth function $f$.\n\nFor random processes the quadratic variation is defined when the limit in probability exists for any sequence of partitions. \n\n\\begin{thm}\nIf $W= (W(t))$ is a Brownian motion, then $\\langle W \\rangle_T = T$ for all $T \\geq 0$.\n\\end{thm}\n\n\\begin{proof}\nFirst $\\E \\left( (W(t_{i+1}) - W(t_i) )^2 \\right) = t_{i+1} - t_i$. We recall the fact that for a random variable $ X \\sim N(0, \\sigma^2)$ we have $\\Var (X^2) = 2 \\sigma^4$. Thus \n  \\begin{align}\n    \\Var \\left( (W(t_{i+1}) - W(t_i) )^2 \\right) =  2 (t_{i+1} - t_i)^2. \n  \\end{align}\nThese and the independence of increments implies that\n  \\begin{align}\n    \\E \\left( \\sum_{i=0}^{n-1} (W(t_{i+1}) - W(t_i) )^2 \\right) = T\n  \\end{align}\nand\n  \\begin{align}\n    \\Var \\left( \\sum_{i=0}^{n-1} (W(t_{i+1}) - W(t_i) )^2 \\right) = 2 \\sum_{i=0}^{n-1} (t_{i+1} - t_i)^2 \\leq 2 \\left| \\Pi \\right| T .\n  \\end{align}\nThis means that $\\langle W \\rangle_T$ $\\Le^2$-converges to $T$.\n\\end{proof}\n\nThe Brownian motion accumulates one unit of quadratic variation per unit of time. The previous result is often written informally as $\\dx W(t) \\dx W(t) = dt$. Similarly we may calculate the covariation $\\langle W, t \\rangle_T = 0$. It is enough to note that\n  \\begin{align}\n    \\left| \\sum_{i=0}^{n-1} (W(t_{i+1}) - W(t_i) )( t_{i+1} - t_i ) \\right| \\leq T \\max_i \\left| W(t_{i+1}) - W(t_i) \\right| \n  \\end{align}\nand by continuity of the paths we may force $\\max_i \\left| W(t_{i+1}) - W(t_i) \\right|$ converge to zero. This we will use informally as $\\dx W(t) \\dx t = 0$. Since $f(t) = t$ is a smooth function, we have that $\\langle t, t \\rangle (T) = 0$ and thus $\\dx t \\dx t = 0$. Hence\n  \\begin{align}\n    \\dx W(t) \\ \\dx W(t) &= dt, \\\\\n    \\dx W(t) \\ \\dx t &= 0, \\\\\n    \\dx t \\ \\dx t &= 0.\n  \\end{align}\n  \n\\section{It\\^{o}-integral}\n\nFor reference, see \\textcite[pp. 21--55]{oksendal2003stochastic}.\n\nWe would like to calculate the integral of a stochastic function $h$ with respect to a Brownian motion $W$ over the time interval $[0,T]$. Let $(\\F_t)$ be the filtration induced by the Brownian motion $W$. Since $h$ and $W$ are random and $W$ is $\\Pf$-nowhere differentiable, we need to tread carefully. If a $(\\F_t)$ adapted function $h(\\omega,t)$ is constant on each subinterval $[t_i, t_{i+1}]$ given a partition $0 = t_0 < t_1 < \\ldots < t_n = T$ of $[0,T]$, then $h$ is called simple. For a simple function we may write\n  \\begin{align}\n    I(h) (\\omega) = \\sum_{i=0}^{n-1} h(\\omega,t_i) ( W(t_{i+1}, \\omega) - W(t_i, \\omega) ) .\n  \\end{align}\nThe key here is that the function $h(\\omega,t_i)$ is at the earliest moment and therefore It\\^{o}-integral is not forward looking. Now $I(h)$ itself is a random variable. If $h$ is structured enough, then we may approximate it with simple function and define It\\^{o}-integral as the limit of this process, if it is exists. Without going into details, we note that if $(\\F_t)$-adapted process satisfies\\footnote{Unless otherwise noted, we shall always assume that this condition will be satisfies.} that\n  \t\\begin{align}\n\t\\label{H-ito-restriction}\n\t\\E \\left( \\int_0^T h^2 (\\omega,u) \\dx u \\right) < \\infty\n\t\\end{align}\nthen the limit \n\t\\begin{align}\n\t\tI(t, \\omega) = \\int_0^t  h (\\omega,u) \\ \\dx W(u, \\omega)\n\t\\end{align}\nexists and is called the It\\^{o}-integral of $h$ from $0$ to $t$.\n\nUnder these common assumptions, the It\\^{o}-integral $I(t)$ satifies the following\n\t\\begin{enumerate}\n\t\t\\item $I(t)$ is $(\\F_t)$-adapted,\n\t\t\\item $I(t)$ is continuous,\n\t\t\\item $I(t)$ is a martingale and $\\E( I(t) \\ | \\ \\F_0 ) = 0$ for all $t \\geq 0$ and\n\t\t\\item $I(t)$ satisfies the It\\^{o}-isometry\n\t\t\\begin{align}\n\t\t\\E \\left( I(h)^2 \\right) = \\E \\left( \\int_0^T h^2 (\\omega,u) \\dx u \\right) < \\infty .\n\t\t\\end{align}\n\t\\end{enumerate}\n\nThe  quadratic variation of It\\^{o}-integral up to time $t$ is\n  \\begin{align}\n    \\int_0^t h^2 \\dx s .\n  \\end{align}\n  \nNothing restricts It\\^{o}-integral to be one dimensional. If $W(t)$ is $d$-dimensional Wiener process and $h(t, \\omega) : \\R \\times \\Omega \\rightarrow \\R^{p \\times d}$, then we demand that\n\t\\begin{align}\n\t\t\\E \\left( \\int_0^t \\left| h(s, \\omega) \\right|^2 \\ \\dx s \\right) < \\infty \n\t\\end{align}\nwhere\n\t\\begin{align}\n\t\t\\left| h(s, \\omega) \\right|^2 = \\mathrm{tr} ( h(s, \\omega)^{\\top} h(s, \\omega) ) .\n\t\\end{align}\nIf we relax the condition above, then we may not guarantee that the It\\^{o}-integral will be martingale even if the integral exists.\n  \n\\section{It\\^{o} processes and It\\^{o}'s lemma}\n\\label{sec:itoprocess}\n\nFor reference, see \\textcite[pp. 21--55]{oksendal2003stochastic}.\n\nAn adapted process $X$ is called an It\\^{o}-process if it can be written as\n  \\begin{align}\n    X(t) = X(0) + \\int_0^t \\mu(s) \\dx s + \\int_0^t \\sigma(s) \\dx W(s) ,\n  \\end{align}\nwhere $\\mu(t, \\omega), \\sigma(t, \\omega)$ are adapted and integrable processes. This is usually written in more informal differential notation as\n  \\begin{align}\n    \\dx X(t) = \\mu(t) \\dx t + \\sigma(t) \\dx W(t) .\n  \\end{align}\nThe function $\\mu(t)$ is called as the drift and the function $\\sigma(t)$ is called as the volatility. The quadratic variation of the It\\^{o} process is\n  \\begin{align}\n    \\langle X \\rangle_t = \\int_0^t \\sigma^2(u) \\dx u .\n  \\end{align}\nThis is consistent with the heurestic calculation\n  \\begin{align}\n    \\dx X(t) \\ \\dx X(t) &= ( \\mu(t) \\dx t )^2 + 2 \\mu(t) \\sigma(t) \\dx t \\dx W(t) + ( \\sigma(t) \\dx W(t )^2 \\\\\n      &= \\sigma^2 (t) \\dx t .\n  \\end{align}\n\n\\begin{thm}[It\\^{o}'s lemma]\nIf a function $g : \\R \\times [0,T] \\rightarrow \\R$ is in the class $C^{2,1}$ and $Y(t) = g(t, X(t))$, where $X(t)$ is an It\\^{o}-process, then $Y(t)$ is also an It\\^{o}-process with the presentation\n  \\begin{align}\n    \\dx Y(t) = \\left( \\frac{\\partial g}{\\partial t} + \\frac{\\partial g}{\\partial x} \\mu(t) + \\frac{1}{2} \\frac{\\partial^2 g}{\\partial x^2} \\sigma^2(t) \\right) \\dx t + \\frac{\\partial g}{\\partial t} \\sigma(t) \\dx W(t) .\n  \\end{align}\n\\end{thm}\n\nThe formula itself is a short-hand for\n  \\begin{align}\n    Y_t = Y_0 + \\int_0^t g_t (u) \\dx u + \\int_0^t g_x (u) \\dx X_u + \\frac{1}{2} \\int_0^t g_{xx} (u) \\dx \\langle X \\rangle_u ,\n  \\end{align}\nwhere, for example, $g_x$ is the partial differential of $g$ with respect to first variable.\n\nIf It\\^{o}-process\n\t\\begin{align}\n\t\t\\dx X(t) = \\mu(t) \\dx t + \\sigma(t) \\dx W(t) .\n\t\\end{align}\nhas $\\mu: \\R \\times \\Omega \\rightarrow \\R^d$, $\\mu: \\R \\times \\Omega \\rightarrow \\R^{p \\times d}$ and $W(t)$ is $d$-dimensional Wiener process, then the equation in It\\^{o}'s lemma can be written as\n\t\\begin{align}\n\t\t\\dx Y = g_t \\dx t + g_x \\mu \\dx t + g_x \\sigma \\dx W + \\frac{1}{2} \\sum_{i=1}^p \\sum_{j=1}^p g_{x_i, x_j} (\\sigma^{\\top} \\sigma)_{i,j} \\dx t ,\n\t\\end{align}\nwhere $g_x = \\left( g_{x_1} g_{x_2} \\cdots g_{x_p}  \\right)$.\n\nIt\\^{o}'s lemma can be used to calculate integrals. If $g(x,t) = x^2$ and $X_t = W_t$, then \n  \\begin{align}\n    \\dx g(W_t,t) = \\dx t + 2 W(t) \\dx W(t),\n  \\end{align}\nwhich is the short-hand for\n  \\begin{align}\n    W(t)^2 = t + 2 \\int_0^t W(s) \\dx W(s) .\n  \\end{align}\nThis means that \n  \\begin{align}\n    \\int_0^t W(s) \\dx W(s) = \\frac{1}{2} \\left( W(t)^2 - t \\right).\n  \\end{align}\n  \n\\section{Geometric Brownian motion}\n\nA stochastic process $X$ is a geometric Brownian motion if it satisfies the stochastic differential equation\n  \\begin{align}\n    \\dx X(t) = \\mu X(t) \\dx t + \\sigma X(t) \\dx W(t),\n  \\end{align}\nwhere $\\mu$ and $\\sigma > 0$ are constants and $W$ is a Brownian motion. The constant $\\mu$ is the drift and $\\sigma$ is the diffusion (or volatility). The solution of this SDE can be calculated by using It\\^{o}'s lemma with the function $g(x, t) = \\log(x)$. Now $\\frac{\\partial g}{\\partial x} = 1/x$ and $\\frac{\\partial^2 g}{\\partial x^2} = -1/x^2$. Thus\n   \\begin{align}\n    \\dx \\log X(t) &= \\left( 0+ \\mu X(t) / X(t) - \\frac{1}{2} \\sigma^2 X^2 (t) / X^2 (t) \\right) \\dx t + \\sigma X(t) / X(t) \\dx W(t) \\\\\n      &= \\left( \\mu  - \\frac{1}{2} \\sigma^2 \\right) \\dx t + \\sigma \\dx W(t)\n  \\end{align}\nand integrating from $0$ to $t$ gives us\n  \\begin{align}\n    \\log (X(t) / X(0) ) = \\left( \\mu  - \\frac{1}{2} \\sigma^2 \\right) t + \\sigma W(t) . \n  \\end{align}\nThus\n  \\begin{align}\n    X(t) = X(0) \\e^{ (\\mu  - \\frac{1}{2} \\sigma^2 ) t + \\sigma W(t) } .\n  \\end{align}\nThis means that for given $X(0)$, the variable $X(t)$ is log-normally distributed with parameters $( \\mu  - \\frac{1}{2} \\sigma^2 ) t$ and $\\sqrt{t}\\sigma$. Now the mean of $X(t)$ is\n  \\begin{align}\n    \\exp \\left( ( \\mu  - \\frac{1}{2} \\sigma^2 ) t + \\frac{1}{2} ( \\sqrt{t} \\sigma )^2 \\right) = \\exp \\left( \\mu t \\right)\n  \\end{align}\nand the variance is\n  \\begin{align}\n    ( \\exp ( \\sigma^2 t ) - 1 ) \\exp ( )\n  \\end{align}\n  \n\\section{Girsanov's theorem}\n\\label{sec:girsanov}\n\nFor reference, see \\textcite[pp. 161--171]{oksendal2003stochastic}.\n\nAs a converse of Radon-Nikod\\'{y}m-theorem, if $L$ almost surely positive and $\\E_{\\Pf} (L) = 1$, then we may define a new measure\n\t\\begin{align}\n    \\label{radonnikodymgirsanovconnection}\n\t\t\\Pm(A) = \\E_{\\Pf} (L \\1_A)\n\t\\end{align}\nfor all $A \\in \\F$ and now \n\t\\begin{align}\n\t\tL = \\frac{\\dx \\Pm}{\\dx \\Pf}\n\t\\end{align}\nis the Radon-Nikod\\'{y}m-derivate with respect to $\\Pf$ and $\\Pm$. \n\n\\begin{thm}[Girsanov's theorem]\n\tLet $W(t)$ be a Brownian motion in the probability space $(\\Omega, \\F, \\Pf)$ with respect to filtration $(\\F_t)$ and assume that the process $\\kappa(t)$ is an $(\\F_t)$-adapted process. We define\n\t\\begin{align}\n\t\\label{doleansexponential}\n\tL(t) &= \\exp \\left( \\int_0^t \\kappa(s) \\dx W(s) - \\frac{1}{2} \\int_0^t \\kappa^2 (s) \\dx s \\right) \\\\\n\t&= \\exp \\left( \\int_0^t \\kappa(s) \\dx W(s - \\frac{1}{2} \\langle \\kappa(s) \\rangle_t \\right), \n\t\\end{align}\n\tIf we assume that $\\E_{\\Pf} (L_T) = 1$, then the process\n\t\\begin{align}\n\tW^*(t) &= W(t) - \\int_0^t \\kappa(s) \\dx s.\n\t\\end{align}\n\tis a Brownian motion under the equivalent probability measure $\\Pm$ defined by the Equation \\ref{radonnikodymgirsanovconnection}.\n\\end{thm}\n\nThe process $\\kappa$ is called as the Girsanov kernel of the probability transformation. If we assume that the Girsanov kernel satisfies the Novikov Condition\n  \\begin{align}\n    \\E_{\\Pf} \\exp \\left( \\frac{1}{2} \\int_0^T \\kappa^2 (s) \\dx s \\right) < \\infty ,\n  \\end{align}\nthen the condition $\\E_{\\Pf} (L(T)) = 1$ is satisfied.\n\nThe process $L(t)$ defined in the equation \\ref{doleansexponential} is the solution to the stochastic differential equation\n  \\begin{align}\n    \\dx L(t) = \\kappa(t) L(t) \\dx W(t)\n  \\end{align}\nwith the condition $L(0) = 1$.\n\nThe significant consequence of the theorem is the fact that the drift of stochastic process is very malleable. If   \n  \\begin{align}\n    \\dx X(t) = \\mu(t) \\dx t + \\sigma(t) \\dx W(t),\n  \\end{align}\nwhere $\\sigma(t) > 0$, then we choose $\\kappa(t) = - (\\mu(t) - a(t)) / \\sigma(t)$. If the Girsanov kernel satisfies assumptions of the Girsanov's theorem, then we have a equivalent measure $\\Pm$ under which\n  \\begin{align}\n    W^*(t) = W(t) - \\int_0^t \\kappa(s) \\dx s\n  \\end{align}\nis a Brownian motion. Thus $\\dx W(t) = \\dx W^*(t) + \\kappa(t) \\dx t$ and\n  \\begin{align}\n    \\dx X(t) = \\mu(t) \\dx t + \\sigma(t) (\\dx W^*(t) + \\kappa(t) \\dx t) = a(t) \\dx t + \\sigma(t) \\dx W^* (t)\n  \\end{align}\nunder the measure $\\Pm$. We see that the measure change leaves diffusion unchanged, but the measure may be changed almost at the will. The Brownian motions $W(t)$ and $W^*(t)$ are not the same, but a priori their statistical properties are the same. Especially if $a(t) \\equiv 0$, then the process $X(t)$ is driftless under the measure $\\Pm$. Thus\n  \\begin{align}\n    \\E_{\\Pm} (X(T) | \\F_t) = X(t)\n  \\end{align}\nand it is a martingale.\n\n\\section{Martingale representation theorem}\n\nSuppose that the filtration $(\\F_t)$ is generated by a Brownian motion $W(t)$. One of the properties of the It\\^{o}-integral was that\n\t\\begin{align}\n\t\tI(t) = \\int_0^t h(s) \\dx W(s)\n\t\\end{align}\nwas a martingale, when $h(t)$ satisfies Equation \\ref{H-ito-restriction}. Martingale representation states that if $M$ is a square integrable martingale, that is\n\t\\begin{align}\n\t\t\\E_{\\Pf} (M^2) < \\infty ,\n\t\\end{align}\nthen\n\t\\begin{align}\n\t\tM(t) = \\int_0^t h(s) \\dx W(s),\n\t\\end{align}\nwhere $h(t)$ is $(\\F_t)$-adapted and it satisfies Equation \\ref{H-ito-restriction}. Thus\n\t\\begin{align}\n\t\t\\dx M(t) =  h(t) \\dx W(t),\n\t\\end{align}\n  \n\\section{Feynman-Kac theorem}\n\\label{sec:faynmankac}\n\nFor reference, see \\textcite[pp. 145--147]{oksendal2003stochastic}.\n\nThe Feynman-Kac theorem states that the solution of the partial differential equation\n\t\\begin{align}\n\t\t\\frac{\\partial V(t,x)}{\\partial t} + \\frac{\\partial V(t,x)}{\\partial x} f(x) + \\frac{1}{2} \\frac{\\partial^2 V(t,x)}{\\partial x^2} \\sigma^2 (x) = r V(t,x)\n\t\\end{align}\nwith the terminal boundary condition $V(T,x) = g(x)$ is \n\t\\begin{align}\n\t\tV(t,x) = \\e^{-r(T-t)} \\E_{\\Pm} \\left( g(X_T) \\ | \\ X(t) = x \\right) ,\n\t\\end{align}\nwhere the process $X(t) = x$ satisfies\n\t\\begin{align}\n\t\t\\dx X(s) = f(X(s)) \\dx s + \\sigma( X(s) ) \\dx W(s)\n\t\\end{align}\nunder the probability measure $\\Pm$, where $W(s)$ is a Brownian motion under the measure $\\Pm$.\n\n\\section{Partial information}\n\nWe assume that the $\\sigma$-algebra $(\\F_t)$ presents partial market information without default and \n\\begin{align}\n\\Hf_t = \\sigma( \\1_{ \\{\\default \\leq s \\} } | s \\leq t ) = \\sigma( H(s) | s \\leq t ) \n\\end{align}\nis the knowledge of the default up to time $t$. By\n\\begin{align}\n\\F_t \\vee \\Hf_t\n\\end{align}\nwe denote the smallest $\\sigma$-algebra containing $\\F_t$ and $\\Hf_t$. Also\n\\begin{align}\n\\F_{\\infty} = \\bigvee_t \\F_t\n\\end{align}\nthe smallest $\\sigma$-algebra containing all algebras $\\F_t$.\n\n\\begin{lemma}\n\t\\label{lemma-weaksigmasameness}\n\tFor every $A \\in \\F_t \\vee \\Hf_t$, there exists such $B \\in \\F_t$ that\n\t\\begin{align}\n\t\\label{eq-weaksigmasameness}\n\tA \\cap \\{ \\default > t \\} = B \\cap \\{ \\default > t \\},\n\t\\end{align}\n\twhere $t \\in \\R_+$.\n\\end{lemma}\n\n\\begin{proof}\n\tWe consider the filtration given by\n\t\\begin{align}\n\t\\G_t = \\{ A \\in \\F_t \\vee \\Hf_t \\ | \\ A \\cap \\{ \\default > t \\} = B \\cap \\{ \\default > t \\} \\textup{ for some } B \\in \\F_t \\}\n\t\\end{align}\n\tand it is sufficient to show that $\\F_t \\vee \\Hf_t \\subseteq \\G_t$. It is clear that $\\F_t \\subseteq \\G_t$. If $A \\in \\Hf_t$, then $A \\cap \\{ \\default > t \\}$ is either $\\emptyset$ or $\\{ \\default > t \\}$ and it follows that $\\Hf_t \\subseteq \\G_t$.\n\t\n\tTrivially $\\Omega \\in \\G_t$ and it is also easy to see that $\\G_t$ is closed under countable unions. If $A \\in \\G_t$ and $B \\in \\F_t$ satisfies the equation (\\ref{eq-weaksigmasameness}), then \n\t\\begin{align}\n\t\\kom{A} \\cup \\{ \\default \\leq t \\} = \\kom{B} \\cup \\{ \\default \\leq t \\}\n\t\\end{align}\n\tand \n\t\\begin{align}\n\t\\kom{A} \\cap \\{ \\default > t \\} &= ( \\kom{A} \\cup \\{ \\default \\leq t \\} ) \\cap \\{ \\default > t \\} \\\\ \n\t&= ( \\kom{B} \\cup \\{ \\default \\leq t \\} ) \\cap \\{ \\default > t \\} \\\\\n\t&= \\kom{B} \\cap \\{ \\default > t \\}\n\t\\end{align} \n\twhich implies that $\\kom{A} \\in \\G_t$. Hence, $\\G_t$ is a $\\sigma$-algebra and $\\F_t \\vee \\Hf_t \\subseteq \\G_t$.\n\\end{proof}\n\nThis can be used to show the following important result.\n\n\\begin{lemma}\n\\label{lemma_takingthedefaultinformationout}\nIf $X$ is non-negative integrable random variable, then\n\t\\begin{align}\n\t\\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\vee \\Hf_t \\right) = \\frac{\\1_{ \\{ \\default > t \\} }}{\\Pm (\\default > t | \\F_t )} \\E_{\\Pm}  \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\right) .\n\t\\end{align}\n\\end{lemma}\n\n\\begin{proof}\n\tLet $A \\in \\F_t \\vee \\Hf_t$. By Lemma \\ref{lemma-weaksigmasameness}, there is $B \\in \\F_t$ such that\n\t\\begin{align}\n\t\\1_A \\1_{ \\{ \\default > t \\} } = \\1_B \\1_{ \\{ \\default > t \\} } .\n\t\\end{align}\n\tBy this and the definition of conditional expectation we have\n\t\\begin{align}\n\t\\int_A \\1_{ \\{ \\default > t \\} } X \\Pm( \\default > t | \\F_t ) \\ \\dx \\Pm & = \\int_B \\1_{ \\{ \\default > t \\} } X \\Pm( \\default > t | \\F_t ) \\ \\dx \\Pm \\\\\n\t&= \\int_B \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\right) \\Pm( \\default > t | \\F_t ) \\ \\dx \\Pm \\\\\n\t&= \\int_B \\1_{ \\{ \\default > t \\} } \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\right) \\ \\dx \\Pm \\\\\n\t&= \\int_A \\1_{ \\{ \\default > t \\} } \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\right) \\ \\dx \\Pm .\n\t\\end{align}\n\tSince $A \\in \\F_t \\vee \\Hf_t$ is arbitrary, we have that\n\t\\begin{align}\n\t\\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X \\Pm( \\default > t | \\F_t ) | \\F_t \\vee \\Hf_t \\right) \n\t&= \\1_{ \\{ \\default > t \\} } \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\right),\n\t\\end{align}\n\twhere we have used facts $\\1_{ \\{ \\default > t \\} } \\in \\Hf_t$ and $\\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } X | \\F_t \\right) \\in \\F_t$. As $\\Pm( \\default > t | \\F_t )$ is $\\F_t \\vee \\Hf_t$-measurable, it can be taken out of the expectations. Since it is non-zero, we have the claim.\n\\end{proof}\n\n\\begin{thm}\n\\label{eq_takingthedefaultinformationout}\nLet $T > t$. If $X$ is non-negative integrable $\\F_T$-measurable random variable, then\n\t\\begin{align}\n\t\\E_{\\Pm} \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\vee \\Hf_t \\right) = \\frac{\\1_{ \\{ \\default > t \\} }}{\\Pm (\\default > t | \\F_t )} \\E_{\\Pm}  \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\right) .\n\t\\end{align}\n\\end{thm}\n\n\\begin{proof}\nWe will consider variable $Y = \\1_{ \\{T> \\default \\} } X$. If $T > t$, then\n\t\\begin{align}\n\t\t\\1_{ \\{T> \\default \\} } X = Y = \\1_{ \\{t> \\default \\} } Y,\n\t\\end{align}\nand by the assumptions we may use Lemma \\ref{lemma_takingthedefaultinformationout}. Hence\n\t\\begin{align}\n\t\t\\E_{\\Pm} \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\vee \\Hf_t \\right) \n\t\t&= \\E_{\\Pm} \\left( \\1_{ \\{t> \\default \\} } Y  | \\F_t \\vee \\Hf_t \\right) \\\\\n\t\t&= \\frac{\\1_{ \\{ \\default > t \\} }}{\\Pm (\\default > t | \\F_t )} \\E_{\\Pm}  \\left( \\1_{ \\{ \\default > t \\} } Y | \\F_t \\right) \\\\\n\t\t&= \\frac{\\1_{ \\{ \\default > t \\} }}{\\Pm (\\default > t | \\F_t )} \\E_{\\Pm}  \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\right)\n\t\\end{align}\nas required.\n\\end{proof}\n\n\\section{Doubly stochastic default time}\n\\label{sec:doublystochastic}\n\nThe introduce the following technical assumptions:\n\\begin{DS}\n\t\\item\\label{DS1} There exists a non-negative $\\F_t$-progressive process $\\lambda (t)$ such that \n\t\\begin{align}\n\t\\Pm (\\default > t | \\F_t ) = \\e^{ - \\int_0^t \\lambda(s) \\dx s }\n\t\\end{align}\n\t\\item\\label{DS2} For all $t \\geq 0$, it holds that \n\t\\begin{align}\n\t\\Pm (\\default > t | \\F_t ) = \\Pm (\\default > t | \\F_{\\infty} ),\n\t\\end{align}\n\twhere\n\t\\begin{align}\n\t\\F_{\\infty} = \\bigvee_{t \\geq 0} F_t .\n\t\\end{align}\n\\end{DS}\nThe stopping times satisfying both \\ref{DS1} and \\ref{DS2} are doubly stochastic stopping times.\n\nThe condition \\ref{DS1} means that with only partial market information $\\F_t$, the exact default time is never known as\n\\begin{align}\n0 < \\Pm (\\default > t | \\F_t ) < 1\n\\end{align}\nfor all $t \\geq 0$. Hence $\\F_t \\not = \\F_t \\vee \\G_t$ and $\\default$ is not a stopping time under the filtration $(\\F_t)$.\n\nNow the Theorem \\ref{eq_takingthedefaultinformationout} directly implies the following.\n\n\\begin{thm}\n\t\\label{eq_takingthedefaultinformationoutdoubly}\n\tIf we assume \\ref{DS1} and $T > t$, then \n\t\\begin{align}\n\t\\E_{\\Pm} \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\vee \\Hf_t \\right) = \\1_{ \\{ \\default > t \\} } \\e^{ \\int_0^t \\lambda(s) \\dx s }  \\left( \\1_{ \\{ \\default > T \\} } X | \\F_t \\right)\n\t\\end{align}\nholds for every  non-negative integrable $\\F_T$-measurable random variable $X$.\n\\end{thm}\n\nThe previous Theorem is important, because we usually assume that the short rate $r(t)$ is adapted to partial information $(\\F_t)$. In pricing instruments that are sensitive to credit risk, we have to start with full market information but the Theorem shows how we may switch back to partial information set.\n\nSince \n\\begin{align}\n\\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } (1 - \\1_{ \\{ \\default > T \\} } ) | \\F_t  \\right) &= \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } - \\1_{ \\{ \\default > T \\} } | \\F_t  \\right) \\\\\n&= \\E_{\\Pm} \\left( \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } - \\1_{ \\{ \\default > T \\} } | \\F_T \\right) | \\F_t  \\right) \\\\\n&= \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } - \\Pm (\\default > T | \\F_T ) | \\F_t  \\right)  \n\\end{align}\nwe know now that if \\ref{DS1} holds, then\n\\begin{align}\n\\Pm ( t <\\default \\leq T | \\F_t \\vee \\Hf_t ) &= \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } - \\1_{ \\{ \\default > T \\} } | \\F_t \\vee \\Hf_t \\right) \\\\\n&= \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } (1 - \\1_{ \\{ \\default > T \\} } ) | \\F_t \\vee \\Hf_t \\right) \\\\\n&= \\frac{\\1_{ \\{ \\default > t \\} }}{\\Pm (\\default > t | \\F_t )} \\E_{\\Pm} \\left( \\1_{ \\{ \\default > t \\} } (1 - \\1_{ \\{ \\default > T \\} } ) | \\F_t  \\right) \\\\\n&= \\1_{ \\{ \\default > t \\} } \\E_{\\Pm} \\left( 1 - \\e^{ - \\int_t^T \\lambda (s) \\dx s } | \\F_t  \\right)\n\\end{align}\nThus we may approximate that\n\\begin{align}\n\\Pm ( t <\\default \\leq t+ \\dx t | \\F_t \\vee \\Hf_t ) \\approx \\1_{ \\{ \\default > t \\} } \\lambda (t) \\dx t .\n\\end{align}\n\nThe condition \\ref{DS2} is equivalent to the condition that every $(\\F_t)$-martingale is also a $(\\F_t \\vee \\Hf_t)$-martingale. See, for example, \\cite{filipovic2009term}.\n\n\\section{Characteristic functions and Fourier inversion method}\n\nThis following method is based on work of \\textcite{heston1993closed} and the presentation is based on \\textcite[pp. 222--233]{nawalkabeliaevasoto2007dynamic}.\n\nGiven a probability density function $f(x)$ under a measure $\\Pm$, the characteristic function associated with the density function is\n  \\begin{align}\n    g(t) = \\E_{\\Pm} \\left( \\exp^{\\boldsymbol{i}tx} \\right) = \\int_{-\\infty}^{\\infty} \\exp^{\\boldsymbol{i}tx} f(x) \\dx x .\n  \\end{align}\nIt can be shown that there is a one-to-one correspondence between probability density function and characteristic functions and we can calculate\n  \\begin{align}\n    \\int_k^{\\infty} f(x) \\dx x = \\frac{1}{2} + \\frac{1}{\\pi} \\int_0^{\\infty} \\Re \\left( \\frac{\\exp^{-\\boldsymbol{i}sk} g(s)}{\\boldsymbol{i} s} \\right) \\dx s\n  \\end{align}\n\nIn order to calculate certain derivative prices, we have to evaluate expectations in the form of\n  \\begin{align}\n    \\Pi_{1t} &= \\E_{\\Pm} \\left( \\frac{\\exp^{-\\int_t^S r(u) \\dx u}Z(S,T) \\1_{ \\{ Z(S,T) \\geq K \\} } }{Z(t,T)} \\right) \\\\\n     Z(t,T) &= \\E_{\\Pm} \\left( \\exp^{-\\int_t^S r(u) \\dx u} \\right)\n  \\end{align}\na\n  \\begin{align}\n    \\Pi_{1t} &= \\int_k^{\\infty} f_{1t} (y) \\dx y \\\\\n    &= \\frac{1}{2} + \\frac{1}{\\pi} \\int_0^{\\infty} \\Re \\left( \\frac{\\exp^{-\\boldsymbol{i}sk} g_{1t}(s)}{\\boldsymbol{i} s} \\right) \\dx s\n  \\end{align}\n\n\\section{A Gaussian calculation}\n\nFor a continuous function $g$, we may approximate $\\int_0^t g(s) \\dx s$ by the sequence\n  \\begin{align}\n    \\frac{t}{n} \\sum_{k=1}^n g \\left( \\frac{kt}{n} \\right)\n  \\end{align}\n\n\\begin{thm}\n\t\\label{gaussiancalculation}\nIf $X$ is continuous and Gaussian stochastic process, then the stochastic process\n  \\begin{align}\n    Y = \\int_0^t X_s \\dx s\n  \\end{align}\nalso has Gaussian distribution with\n  \\begin{align}\n    \\E Y &= \\int_0^t \\E X_s \\dx s, \\\\\n    \\Var Y &= \\int_0^t \\int_0^t \\Cov (X_s, X_u) \\dx s \\dx u .\n  \\end{align}  \n\\end{thm}\n\n\\begin{proof}\nBy using the idea above, we may approximate the distribution of $Y$ by the distributions of\n  \\begin{align}\n    Y_n = \\frac{t}{n} \\sum_{k=1}^n X \\left( \\frac{kt}{n} \\right),\n  \\end{align}\nwhich are gaussian as they are linear combinations of gaussian variables. Since the expectation is a linear operation, we have\n  \\begin{align}\n    \\E Y_n = \\frac{t}{n} \\sum_{k=1}^n \\E X \\left( \\frac{kt}{n} \\right) \\rightarrow \\int_0^t \\E X_s \\dx s\n  \\end{align}\nand\n  \\begin{align}\n    \\Var Y_n = \\frac{t}{n} \\sum_{k=1}^n \\sum_{j=1}^n \\Cov \\left( X \\left( \\frac{kt}{n} \\right), X \\left( \\frac{jt}{n} \\right) \\right) \\rightarrow \\int_0^t \\int_0^t \\Cov (X_s,X_u) \\dx s \\dx u .\n  \\end{align}\n\\end{proof}\n\n\\section{Differential evolution}\n\nDifferential evolution (DE) is a class of optimization methods based on evolutionary algorithms. It was introduced by \\cite{storn1996usage} and \\cite{storn1997differential}. DE requires no prior knowledge about the optimization problem. On the other hand, this means that after the algorithm has ran its course, we have no guarantees that the result is actually an optimal. It can be used to canvas large areas of the solution space. Therefore it can be useful to find the initial guess for other optimization algorithms that are sensitive to the precision of the initial value.\n\nSuppose that $f: D \\rightarrow \\R$ is the fitness function that is to be minimized. Here $D$ is a hypercube in real space $\\R^n$.\n\nThe basic algorithm starts be selection of the initial population $I_0 \\subset D$. Let $I_k$ be the the population of $k$:th generation. The for every $x \\in I_k$ we generate a distinct alternative candidate $z$ has some heritage with $x$. If $f(z) < f(x)$, then we replace $x$ with $z$ in $(k+1)$:th generation. Therefore the fitness of the next generation as at least as good as the previous. The canon way of choosing the candidate is as follows: \n\n\\begin{enumerate}\n\t\\item For all $x \\in I_k$ pick three distinct points $a, b, c$ from $I_k \\setminus \\{ x \\}$.\n\t\\item Let $y = a + F(b-c)$ and randomly pick an index $j = 1,2, \\ldots, n$. We generate an evolutionary agent $z = (z_1, z_2, \\ldots, z_n)$ by having $z_j = y_j$. For $z_l$, where $j \\not = l \\in \\{1,2, \\ldots, n\\}$ we pick $y_l$ with the probability of $C$ and otherwise $x_l$. Thus $z \\not = x$. If $z \\not \\in D$ then a new candidate is picked or it is scaled back to the search space.\n\\end{enumerate}\n\nThe number $F$ is called the differential weight and usually $F \\in [ 0,2]$. The probability $C$ is the crossover probability. The choice of these parameters obviously influence the convergence. For example, small differential weights and crossover probabilities causes the population to converge quickly.\n\nSince the basic setup of algorithm is very flexible, there are many variants. In the following, we outline the algorithm used in the data analysis of this thesis.\n\nThe initial population is chosen with uniform distribution. The size of the population is 1024 for models without default and 512 otherwise. For every 10 (or 5 for models with default) generations, a random check is made to see if there is a culling . The probability of this grows with each generations. The size of the culling is inversely proportional to the amount of replaces during the previous cycle. Only the members with worst fitness are removed. However, the population will always has at least $32$ members.\n\nFor the candidate vectors we use two different strategies. Either we pick five distinct $a,b,c,d,e$ and\n\t\\begin{align}\n\t\tz = a + F(b-c) + F(d-e) \n\t\\end{align}\nor we pick four distinct candidates $p, a, b, c$ and\n\t\\begin{align}\n\tz = a + F(p-a) + F(b-c)\n\t\\end{align}\nwhere $p$ is in the top $5 \\%$ of the candidates. This first behaviour increases the chances of exploration while the latter approach will boost convergence. The algorithm is set up so that earlier exploration is preferred while later on the convergence is favored. Differential weight and the crossover probability are choosen randomly for each candidate. The algorithm is more likely to choose values that promote convergence later on the run.\n\n\n \n", "meta": {"hexsha": "ec9c882e273d44225b6d37d88b6b5f37f3b9b411", "size": 43519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math.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": "math.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": "math.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": 53.9937965261, "max_line_length": 595, "alphanum_fraction": 0.6311036559, "num_tokens": 16088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.65998689600968}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 3, 2022}\n\\subsection{Quadratic Residues \\emph{continued}}\n\n\\recall \\cref{defn:legendre-symbol} and \\cref{prop:5.1.2} from last class (right above).\n\nWe now prove the earlier proposition:\n\\begin{proof}[Proof of \\cref{prop:5.1.2}]\n    ~\\begin{enumerate}\n        \\item[(c)] is clear.\n        \\item[(a)]\n            By Fermat's Little Theorem, if $p\\nmid a$, we have $a^{p-1}\\equiv 1\\mod p$, so\n            \\[(a^{(p-1)/2}+1)(a^{(p-1)/2}-1)\\equiv 0\\mod p\\]\n            Since mod $p$ we have an integral domain, then we have that $a^{(p-1)/2}\\equiv \\pm 1\\mod p$. We know that $a^{(p-1)/2}\\equiv 1\\mod p$ if and only if $a$ is a quadratic residue mod $p$,\n        \\item[(b)]\n            This applies (a).\n            \\[\\lege{ab}{p} = (ab)^{(p-1)/2} = a^{(p-1)/2}\\cdot b^{(p-1)/2} = \\lege{a}{p}\\lege{b}{p}\\]\n    \\end{enumerate}\n\\end{proof}\n\\begin{corollary}\n    We have some corollaries:\n    \\begin{enumerate}[1)]\n        \\item There are exactly $\\frac{p-1}{2}$ quadratic residues and $\\frac{p-1}{2}$ quadratic non-residues mod $p$.\n        \\item The product of two residues is a residue, the product of a residue and a non-residue is a non-residue, and the product of a non-residue and a non-residue is a residue.\n        \\item If $g$ is a primitive root modulo $p$, then\n              \\[\\lege{g^i}{p} = (-1)^i.\\]\n        \\item We have\n              \\[\\lege{-1}{p} = (-1)^{(p-1)/2}\\]\n              which has a fancy name. This is the \\emph{``First Supplemental Law of Quadratic Reciprocity''}.\n    \\end{enumerate}\n\\end{corollary}\n\n\\subsection{Gauss's Lemma}\nWe now discuss a characterization of the Legendre symbol due to Gauss.\n\\begin{definition}\n    For $p\\in\\ZZ_+$ an odd prime,\n    \\[S = \\left\\{-\\frac{p-1}{2}, -\\frac{p-3}{2}, \\dots, -1, 1, 2, \\dots, \\frac{p-1}{2}\\right\\}\\]\n    is called the \\ul{set of least residues mod $p$}.\n\\end{definition}\n\n\\begin{definition}\n    Let $a\\in\\ZZ$ such that $p\\nmid a$. Define $\\mu$ to be the number of negative least residues of the integers\n    \\[a, 2a, 3a, \\dots, \\left(\\frac{p-1}{2}\\right)a\\]\n\\end{definition}\n\n\\begin{example}\n    If $p=7$ and $a=4$, then $\\frac{p-1}{2} = 3$, and\n    $1\\cdot 4, 2\\cdot 4, 3\\cdot 4$ are congruent to $-3, 1, -2$ mod $7$. Thus $\\mu = 2$.\n\\end{example}\n\\begin{lemma}[Gauss's Lemma]\\label{lemma:gauss-lemma}\n    Let $p\\in\\ZZ_+$ be an odd prime and let $a\\in\\ZZ$ be such that $p\\nmid a$. Then\n    \\[\\lege{a}{p} = (-1)^\\mu.\\]\n\\end{lemma}\n\\begin{proof}\n    It is convenient for us to partition the list $S$ as\n    \\begin{align*}\n        P & = \\{1, 2, \\cdots, \\frac{p-1}{2}\\}    \\\\\n        N & = \\{-1, -2, \\cdots, -\\frac{p-1}{2}\\}\n    \\end{align*}\n    so that $\\mu = |aP\\cap N|$\\footnote{There's an abuse of notation here, but we conflate integers with their equivalence classes in $S$.}.\n\n    A key observation is that if $x, y\\in P$ with $x\\neq y$, then\n    \\[ax\\not\\equiv \\pm ay\\mod p\\]\n    for otherwise,\n    \\[a \\equiv \\pm y\\mod p\\]\n    which is impossible since $x$ and $y$ are distinct elements of $P$ (positive residue classes, so not in $N$).\n\n    Thus $aP = \\{\\varepsilon_i i\\mid 1\\leq u\\leq \\frac{p-1}{2}\\}$ for some $\\varepsilon_i = \\pm 1$.\n\n    Now we mimic the elementary proof of Euler's Theorem:\n    \\begin{align*}\n        a^{(p-1)/2}\\cdot \\left(\\frac{p-1}{2}\\right)! & \\equiv \\left(\\prod_{i=1}^{(p-1)/2} \\varepsilon_i\\right)\\cdot \\left(\\frac{p-1}{2}\\right)! \\\\\n        a^{(p-1)/2}                                  & \\equiv \\left(\\prod_{i=1}^{(p-1)/2} \\varepsilon_i\\right)                                  \\\\\n                                                     & \\equiv (-1)^\\mu\n    \\end{align*}\n    since $\\mu$ is equal to the order of the set that is contributing every $-1$ as $\\varepsilon_i$.\n\n    Applying \\cref{prop:5.1.2} (Euler's criterion), this concludes the proof.\n\\end{proof}\nWe'll use this lemma to prove Quadratic Reciprocity later.\n\nWe now use it to prove the \\emph{Second Supplemental Law} of Quadratic Reciprocity.\n\\begin{proposition}[5.1.3, the \\emph{Second Supplemental Law of Quadratic Reciprocity}]\n    For $p\\in\\ZZ_+$ be an odd prime.\n    \\[\\lege{2}{p} = (-1)^{(p^2 - 1)/8}\\]\n    We note $\\dfrac{p^2-1}{8} = \\dfrac{(p-1)(p+1)}{2\\cdot 4}$. From this, it follows that we're really saying\n    \\[\\lege{2}{p} = \\begin{cases}\n            1  & \\text{when $p = \\pm 1\\mod 8$} \\\\\n            -1 & \\text{when $p = \\pm 3\\mod 8$}\n        \\end{cases}\\]\n\\end{proposition}\n\\begin{proof}\n    We apply Gauss's Lemma with $a = 2$.\n    \\[2P = \\{2, 4, 6, \\dots, p-1\\}\\]\n    First suppose that $p\\equiv 1\\mod 4$. Then $\\frac{p-1}{2}$ is even, so\n    \\[2P = \\bigg\\{\\underbrace{2, 4, 6, \\dots, \\frac{p-1}{2}}_{\\in P}, \\underbrace{\\frac{p+3}{2}, \\dots, p-1}_{\\in N}\\bigg\\}\\]\n    with the first $\\frac{p-1}{4}$ elements in $P$ and the last $\\frac{p-1}{4}$ elements in $N$. So $\\mu = |2P\\cap N| = \\frac{p-1}{4}$, so Gauss's Lemma gives\n    \\[\\lege{2}{p}\n        = (-1)^{\\frac{p-1}{4}}\n        = \\left((-1)^{\\frac{p-1}{4}}\\right)^{\\frac{p+1}{2}}\n        = (-1)^{\\frac{p^2-1}{8}}\\]\n    since $\\frac{p+1}{2}$ is odd.\n\n    Now suppose $p\\equiv 3\\mod 4$. Then\n    \\[2P = \\bigg\\{\\underbrace{2, 4, 6, \\dots, \\frac{p-3}{2}}_{\\in P}, \\underbrace{\\frac{p+1}{2}, \\dots, p-1}_{\\in N}\\bigg\\}\\]\n    The first $\\frac{p-3}{4}$ elements are in $P$, and the last $\\frac{p+1}{4}$ elements are in $N$. Then $\\mu = \\frac{p+1}{4}$, so\n    \\[\\lege{2}{p}\n        = (-1)^{\\frac{p+1}{4}}\n        = \\left((-1)^{\\frac{p+1}{4}}\\right)^{\\frac{p-1}{2}}\n        = (-1)^{\\frac{p^2-1}{8}}\\]\n\\end{proof}\n\n\\subsection{Quadratic Reciprocity}\n\\begin{theorem}[Law of Quadratic Reciprocity]\\label{thm:qr}\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\\begin{proof}\n    \\emph{coming soon!}\n\\end{proof}\n\nHere's the motivation behind this: we used Euler's Criterion to easily calculate the quadratic character of some $a$ mod $p$. With Quadratic Reciprocity, we can solve the question ``If we fix odd prime $q$, for which $p$ is $q$ a quadratic residue?''\n\n\\begin{example}\n    Which odd primes $p\\in\\ZZ_+$ have $3$ as a quadratic residue?\n\n    Suppose $p\\equiv 1\\mod 4$. Then\n    \\[\\lege{3}{p} = \\lege{p}{3} = \\begin{cases}\n            1  & \\text{if $p\\equiv 1\\mod 3$}  \\\\\n            -1 & \\text{if $p\\equiv -1\\mod 3$}\n        \\end{cases}\\]\n    Then $p\\equiv 1\\mod 4$ and $p\\equiv 1\\mod 3$ so $p\\equiv 1\\mod 12$ gives us \\[\\lege{3}{p} = 1\\] and $p\\equiv 5\\mod 12$ gives \\[\\lege{3}{p} = -1.\\]\n\n    Now suppose $p\\equiv 3\\mod 4$. Then\n    \\[\\lege{3}{p} = -\\lege{p}{3} = \\begin{cases}\n            1  & \\text{if $p\\equiv -1\\mod 3$} \\\\\n            -1 & \\text{if $p\\equiv 1\\mod 3$}\n        \\end{cases}\\]\n    Thus,\n    \\begin{align*}\n        p & \\equiv 11\\mod 12\\text{ gives }\\lege{3}{p} = 1\\text{, and } \\\\\n        p & \\equiv 7\\mod 12\\text{ gives }\\lege{3}{p} = -1\n    \\end{align*}\n\n    So we conclude that $\\lege{3}{p} = 1$ iff $p\\equiv \\pm 1\\mod 12$.\n\\end{example}", "meta": {"hexsha": "9db1d848c09d70360cdab53780864345dcb88f6e", "size": 7096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-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-03-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-03-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": 46.9933774834, "max_line_length": 250, "alphanum_fraction": 0.5638387824, "num_tokens": 2707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8376199572530449, "lm_q1q2_score": 0.659986894412742}}
{"text": "\\lab{Application}{Cracking Blackjack}{Cracking Blackjack}\n\\label{Ch:BJ}\n\n\\objective{Exploit the weaknesses of a pseudorandom number generator that is based on a Linear Congruential Generator.}\n\n\\section*{Blackjack}\n\n\\begin{figure}[H]\n\\includegraphics[scale = .9]{Blackjack_game_1.jpg}\n\\caption{Initial Round of a BlackJack Game}\n\\end{figure}\n\nBlack Jack is a card game that involves the use of randomness.\nThe game is simple.\nThe dealer deals the player and himself each two cards.\nHe flips over his first card so that the player can see it.\nThe player has to choose to take another card (\"hit\") or not (\"stand\").\nIf 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.\nFace cards are worth 10 points.\nAces can count either as 11 or 1.\nThe value of all 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 automatically loses.\nIf his value is 21 and below and dealer has above 21 then the player wins.\nIf they both have 21 or under than the player with the hand of highest value wins.\nIf both hands have the same value, the game is a tie.\n\n\\section*{Shuffling Algorithms}\n\nOne use of Pseudorandom Number Generators (PRNGs) is to shuffle cards.\nThe main goal of these algorithms is that the card order be random--so that no single player has an advantage based on order.\nOften, as strange as it may seem, online gambling sites will post their shuffling algorithms online.\nThe only things they do not post are their seed values.\nOften the time in milliseconds from midnight is used as the seed value.\n\nJohn von Neumann said ``Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.\"\nAs seen in the last lab, weak PRNGs are periodic and are predictable once a few outputs are known.\nThis lab will have you break blackjack based on a weak PRNG.\n\n\\section*{Cracking Blackjack}\nFor these next problems you will need three files that are provided with this lab: Black.py, BlackEasy.py, and bjHelp.py.\nBlack.py and BlackEasy.py are are programs that run games of Blackjack that use a Linear Congruentail Generator (LCG) to shuffle the cards.\nThey generate 52 random numbers and then the argsort of those numbers is the order of the cards.\nThe parameters for BlackEasy.py are a$=2521$, c$=13$, mod$=2^{16}$.\nFor Black.py they are a$=25214903917$, c$=11$, mod$=2^{48}$.\nIn order to play them type \\li{python <<filename>> <<numberofgames>>} in your command line.\nThey 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.\nThe 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).\nIt prints all shuffles as a list of cards in Stats that have the same first three cards as the inputted 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.\nExamples: '6diamond', 'Kclub'.\n\n\\begin{warn}\nBoth BlackEasy.py and Black.py use functions that are incompatible with ipython. They need to run \\li{python Black.py} in command line.\n\\end{warn}\n\n\n\n\\begin{problem}\nPlay 10 games of BlackEasy.py and by the 5th game be able to predict the cards.\nYou can write your own functions or use the ones in bjHelp.py.\nYou will want to open two command prompts, one to play the game and one to predict the cards. \n\\end{problem}\n\nNot too hard.\nThat is because there is only $2^{16}$ seed values.\nThis 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": "430cbb7b5edf713f4ea079fd03c494178c80dff7", "size": 4058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Blackjack/Blackjack.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/Blackjack/Blackjack.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/Blackjack/Blackjack.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 47.1860465116, "max_line_length": 139, "alphanum_fraction": 0.767619517, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.6599084903206335}}
{"text": "\\paragraph{Performance Measure} \\label{performance_measure}\nThe presented parameters for a sliding window simulation are resulting in a huge amount of different configured\nsimulations. Every configured simulation tries to detect gestures in the test data stream for every experimentee. It can\nbe argued how to compare the performance of those simulations. Have misrecognized gestures in the assessment more weight\nthan correctly recognized or the other way around? It is no easy decision to weigh the mistakes of a simulation against\nthe success of a simulation.\n\nAll containing data points of a supposed detected gesture are labeled by a simulation. Those labels can be compared\nto the original labels that were made by the experimentee. This results in true positive ($tp$), true negative\n($tn$), false positive ($fp$) and false negative ($fn$) labels for every gesture $GesA, GesB, \\dots, GesH$. Seen from\nthis point of view, a simulation is a multi-class classificator for the gesture classes\n$K_{GesA}, K_{GesB}, \\dots, K_{GesH}$. Common performance measures for multi-class classificator are $Precision_{\\mu}$,\n$Recall_{\\mu}$ and $F_{\\beta}score_{\\mu}$ as mentioned in \\cite{sokolova2009systematic}.\n\n\\begin{equation}\n    Precision_{\\mu} = \\frac{\\sum \\limits_{i=1}^{l} tp_i}{\\sum \\limits_{i=1}^{l} (tp_i + fp_i)}\n\\end{equation}\n\\begin{equation}\n    Recall_{\\mu} = \\frac{\\sum \\limits_{i=1}^{l} tp_i}{\\sum \\limits_{i=1}^{l} (tp_i + fn_i)}\n\\end{equation}\n\\begin{equation}\n    F_{\\beta}score_{\\mu} = \\frac{(\\beta^2 + 1)Precision_{\\mu} Recall_{\\mu}}{\\beta^2 Precision_{\\mu} + Recall_{\\mu}}\n\\end{equation}\n\nThe $F_{1}score_{\\mu}$ is used in the following subsection to rank the different simulations.\n", "meta": {"hexsha": "6a85af5448e71609566ad338a93585ee47441b32", "size": 1701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/experiment/experimental_protocol/sliding_window_simulation/performance_measure.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/experiment/experimental_protocol/sliding_window_simulation/performance_measure.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/experiment/experimental_protocol/sliding_window_simulation/performance_measure.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": 65.4230769231, "max_line_length": 120, "alphanum_fraction": 0.7519106408, "num_tokens": 472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6599084728509406}}
{"text": "Before the proofs that are the main results of this thesis we will start with a formal introduction of partizan poset games in general and partizan poset games played on chess-colored Young diagrams in particular.\n%\\\\\n\\begin{defn}[Partizan Poset Games]\nLet $P$ be any colored poset and let $p_L,p_R$ denote arbitrary elements in $P$ of Left and Right respectively. The partizan poset game $G_{\\rm PP}(P)$ played on $P$ is a partizan two-player game where the Left player has the option to select any white element $p_L$ in $P$ and then remove $p_L$ together with all elements greater than $p_L$ and equivalently for the Right player but with black elements in $P$. More formally we have:\n\\begin{align*}\n&G_{\\rm PP}(P)=\\{L|R\\}&~\\\\\n&L=\\{G_{\\rm PP}(P\\setminus S_{\\rm P}(p_L)):p_L\\in P\\text{ is white}\\}&~\\\\\n&R=\\{G_{\\rm PP}(P\\setminus S_{\\rm P}(p_R)):p_R\\in P\\text{ is black}\\}&\\\\\n&S_{\\rm P}(p)=\\{p':p'\\in P,p'\\ge p\\}&~\n\\end{align*}\n\\end{defn}\n~\\\\\nMore specifically, this thesis deals with partizan poset games played on posets that are chess-colored and in the form of Young diagrams. We will denote such a game, with $k\\ge1$ rows in the Young diagram, as $A_\\lambda$, where $\\lambda=(\\lambda_1,\\lambda_2,\\dots,\\lambda_k)$ is as in Definition \\ref{def:lambda} and $\\lambda_1\\ge \\lambda_2\\ge \\dots\\ge \\lambda_k$ denotes the lengths of the 1st, 2nd,$\\dots,k$'th rows respectively. In particular, when $k=3$ or $k=2$, we will use the notation $A_{x,y,z}$ and $A_{x,y}$ respectively.\n\n\\subsection{All Poset Games Are Numbers}\nAs it is, we have that all poset games are numbers. In particular, for a large number of partizan poset games, the value is bounded.% as $0\\le G\\le 1$.\n%According to Section \\ref{section:numbers} in general and Theorem \\ref{numthm} in particular, it is, using \\emph{Conway Induction}, sufficient to show that for a poset game $G$ we have $G^L<G^R$.\n%\\\\\n\\begin{thm}\n\\label{thm:posetnum}\nAll poset games are numbers.\n\\end{thm}\n\\begin{proof2}{Proof of Theorem \\ref{thm:posetnum}}\nAssume that we have an arbitrary poset game $G$. Using \\emph{Conway Induction} (Theorem \\ref{thm:conind}) it suffices to assume that $G^L,G^R$ are numbers and then deduce that $G$ is a number as well. By Theorem \\ref{thm:number} it is then sufficient to show that $G^L<G^R$ for all options of $G$.\n\\\\\nIf we can show that $G^L<G$ and $G^R>G$ for any Left and Right options of $G$, then it also holds that $G^L<G^R$, and hence $G$ must be a number.\n\\\\\\\\\nConsider the scenario where Left moves to some option $G^{L_1}$, as illustrated in Figure \\ref{fig:posetnum1}. We have that $G^{L_1}<G$ since Right always wins in $G^{L_1}-G$.\n\\\\\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{0.45\\textwidth}\n\\begin{tikzpicture}\n\\path[draw,use Hobby shortcut,closed=true]\n(0,-0.2) .. (1.2,1) .. (2.5,2) .. (.3,3.3) .. (-1.4,1.3) .. (-1.3,.3);\n\\node (G) at (0.3,1.5) {$G$};\n\\end{tikzpicture}\n\\end{subfigure}\n%$\\hfill$\n\\begin{subfigure}{0.45\\textwidth}\n\\begin{tikzpicture}\n\\path[draw,use Hobby shortcut,closed=true]\n(0,0) .. (.5,1) .. (1,2) .. (.3,3) .. (-1,1) .. (-1,.5);\n\\path[dashed,draw,use Hobby shortcut,closed=true]\n(0,-0.2) .. (1.2,1) .. (2.5,2) .. (.3,3.3) .. (-1.4,1.3) .. (-1.3,.3);\n\\path[draw,use Hobby shortcut,closed=true]\n(1.5,2.3) .. (1.8,2) .. (2,2.4) .. (1.7,3);\n\\node (G) at (0,1.5) {$G^{L_1}$};\n\\draw (1,2) -- (1.5,2.3);\n\\node at (1.5,2.3) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n\\draw [<-,thick] (1.5,1) -- (2,0.5);\n\\node at (2.2,.3) {G};\n\\end{tikzpicture}\n\\end{subfigure}\n\\captionof{figure}{Arbitrary poset game $G$ and $G$ with an arbitrary Left option $G^{L_1}$.}\n\\label{fig:posetnum1}\n\\end{figure} \n\nThis is easily understood from the following. In the game $G^{L_1}-G$ in Figure \\ref{fig:posetnum2} the Right player wins if it plays first, since then Right can move to $-G^{L_1}$ in $-G$ and then mimic Left's moves until Left has no moves left. If Left starts and plays in the part of $G$ that is not included in $G^{L_1}$, i.e., the small appendage of G in Figure \\ref{fig:posetnum1}, then Right can move to $-G^{L_1}$ in that component and copy Left in the same way as before. If Left starts and plays in the $G^{L_1}$-part of either component, then Right can copy Left until either Left has no moves or until Left plays in the appendage part of the $-G$ component, and then Right can just move to the option that removes that appendage, which makes the two components mirrored again, so Right can then copy Left until Left has no moves and loses.\n\\\\\nSince Right wins in $G^{L_1}-G$ no matter if Right starts or not, then $G^{L_1}-G<0$.\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}\n\\path[draw,use Hobby shortcut,closed=true]\n(0,0) .. (.5,1) .. (1,2) .. (.3,3) .. (-1,1) .. (-1,.5);\n\\node (G) at (0,1.5) {$G^{L_1}$};\n\\end{tikzpicture}\n{\\scalefont{10}\n\\begin{tikzpicture}\n\\node at (0,3){};\n\\node at (0,1.5){-};\n\\node at (0,0){};\n\\end{tikzpicture}\n}\n\\begin{tikzpicture}\n\\path[draw,use Hobby shortcut,closed=true]\n(0,0) .. (.5,1) .. (1,2) .. (.3,3) .. (-1,1) .. (-1,.5);\n\\path[dashed,draw,use Hobby shortcut,closed=true]\n(0,-0.2) .. (1.2,1) .. (2.5,2) .. (.3,3.3) .. (-1.4,1.3) .. (-1.3,.3);\n\\path[draw,use Hobby shortcut,closed=true]\n(1.5,2.3) .. (1.8,2) .. (2,2.4) .. (1.7,3);\n\\node (G) at (0,1.5) {$G^{L_1}$};\n\\draw (1,2) -- (1.5,2.3);\n\\node at (1.5,2.3) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n\\end{tikzpicture}\n\\captionof{figure}{The poset game $G^{L_1}-G$.}\n\\label{fig:posetnum2}\n\\end{figure}\n%\\\\\nIn the exact same way, it is possible to show that Left always wins in $G^{R_1}-G$, and hence that $G^{R_1}-G>0$. We therefore have $G^{L_1}<G^{R_1}$. Since $G^{L_1}$ and $G^{R_1}$ were arbitrary, this holds for any Left and Right options $G^{L_1},G^{R_1}$, and therefore $G$ must be a number.\n\\end{proof2}\n\nThis lets us know that all poset games are numbers. But we can also bound the value of some partizan poset games, as will be seen in Theorem \\ref{thm:value}.\n\n\\begin{minipage}[b]{0.5\\textwidth}\n\\begin{thm}\nAny partizan poset game $G$ with a single smallest element colored white, covered only by black elements, has a value $0< G< 1$. \n\\\\\nAn example game can be seen in Figure \\ref{fig:partizanvalue}.\n\\label{thm:value}\n\\end{thm}\n\\end{minipage}\n\\begin{minipage}{0.05\\textwidth}\n~\n\\end{minipage}\n\\begin{minipage}[b]{0.45\\textwidth}\n\n%\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[baseline=-0.65ex,scale=.2]\n  \\draw[thick] (0,-2) -- (-4,0);\n  \\draw[thick] (0,-2) -- (4,0);\n  \\draw[dashed] (-4,0) -- (-6,2);\n  \\draw[dashed] (-4,0) -- (-4,3);\n  \\draw[dashed] (-4,0) -- (-2,2);\n  \\draw[dashed] (4,0) -- (6,2);\n  \\draw[dashed] (4,0) -- (4,3);\n  \\draw[dashed] (4,0) -- (2,2);\n  \\node (zero) at (0,-2) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n  \\node (1) at (-4,0) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n  \\node (2) at (4,0) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n\\end{tikzpicture}\n\\captionof{figure}{}\n\\label{fig:partizanvalue}\n%\\end{figure}\n\\end{minipage}\n\\begin{proof2}{Proof of Theorem \\ref{thm:value}}\nLet $G$ be any partizan poset game with a single smallest element colored white, covered only by black elements. Clearly $G>0$ since Left can remove the smallest element in the poset, removing all elements, resulting in no options for Right, so Left wins. \n\\\\\nMoreover, since the game with only the smallest (white) element left is either an option of Right, or an option of an option of Right, or an option of an option of an option of Right,\\dots, etc., and all $G^R>G$, then $G<1$.\n\\end{proof2}\n%Obviously, the value of games for which the coloring is reversed that of Theorem \\ref{thm:value} is also bounded, but as $0>G>-1$ instead. \n%\\\\\nWe may note that this theorem holds for all chess-colored partizan poset games with a single smallest elements, e.g., games played on chess-colored Young diagrams.\n\\\\\\\\\nIn addition to bounding the value of some games, it is also possible to determine that a player should try to play the option of removing as great elements as possible.\n\\begin{thm}[Play Strategy]\n\\label{thm:playstrategy}\nA player should only play the options of removing elements not lower than any other element of the same color.\n\\end{thm}\n\\begin{proof2}{Proof of Theorem \\ref{thm:playstrategy}}\nWe will prove this theorem by showing that any option of removing an element that is lower than some other element of the same color is also a dominated option. \n\\\\\nLet $G$ be any partizan poset game, let $G^{L_{x_1}},G^{L_{x_2}}$ be the Left options when removing the elements $x_1$ and $x_2$ respectively and let $x_1>x_2$.\nThe option $G^{L_{x_2}}$ must be an option of $G^{L_{x_1}}$. This is because $x_1>x_2$, which yields that the option of removing $x_2$ also removes $x_1$, and therefore the option of removing $x_1$ does not remove any elements that are not removed when playing the option of removing $x_2$. \n\\\\\nSince $G^{L_{x_2}}$ is an option of $G^{L_{x_1}}$ and Theorem \\ref{thm:posetnum} yields that $G$ is a number, then $G^{L_{x_1}}>G^{L_{x_2}}$ and hence $G^{L_{x_2}}$ is dominated by $G^{L_{x_1}}$, i.e., Left should not play the option $G^{L_{x_2}}$.\n\\\\\nSimilarly, this holds for Right options as well.\n\\end{proof2}\n\\newpage\n%\n%\\subsection{Partizan Tree Poset Games And Blue-Red Hackenbush}\n%\\begin{thm}\n%A Partizan tree poset game where no element is covering more than one element is equivalent to a game of Blue-Red Hackenbush.\n%\\end{thm}\n%\\begin{proof2}\n%Consider a partizan tree poset game $G$. Then transform every element in the poset of $G$ to a stick in the game of Blue-Red Hackenbush, color them according to the appropriate player, connect every stick with the stick that it covers and connect the least element to the ground. We then have an equivalent game of Blue-Red Hackenbush.\n%\\begin{figure}[H]\n%\\centering\n%\\begin{tikzpicture}[scale=1]\n%  \\node (zero) at (-6,-1) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (1) at (-8,.5) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (2) at (-6,.5) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (3) at (-4,.5) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (4) at (-9,2) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (5) at (-7,2) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (6) at (-4,2) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\draw[thick] (zero) -- (1) -- (4);\n%  \\draw[thick] (zero) -- (2);\n%  \\draw[thick] (1) -- (5);\n%  \\draw[thick] (zero) -- (3) -- (6);\n%%\\end{tikzpicture}\n%%\\begin{tikzpicture}[scale=0.5]\n%    \\draw[densely dashed] (-1,-1) -- (1,-1);\n%    \\node[hackennode] (down)   at ( 0,  -1) {};\n%    \\node[hackennode] (middle) at ( 0,   0) {};\n%    \\node[hackennode] (left)   at (-1.5, 1) {};\n%    \\node[hackennode] (right)  at ( 1.5, 1) {};\n%    \\node[hackennode] (top)    at ( 0,   1) {};\n%    \\node[hackennode] (top2)   at (-2,   2) {};\n%    \\node[hackennode] (top3)   at (-1,   2) {};\n%    \\node[hackennode] (top4)   at ( 1.5, 2) {};\n%\n%    \\draw[hackenline,blue]\n%\t\t(down) -- (middle);\n%    \\draw[hackenline,red]\n%\t\t(middle) -- (right);\n%    \\draw[hackenline,red]\n%\t\t(middle) -- (left);\n%    \\draw[hackenline,blue]\n%        (middle) -- (top);\n%    \\draw[hackenline,red]\n%        (left) -- (top2);\n%    \\draw[hackenline,blue]\n%        (left) -- (top3);\n%    \\draw[hackenline,blue]\n%        (right) -- (top4);\n%\n%\\end{tikzpicture}\n%\\end{figure}\n%\\begin{figure}[H]\n%\\centering\n%\\begin{tikzpicture}[scale=1]\n%  \\node (zero) at (-6,-1) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (1) at (-8,.5) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (2) at (-6,.5) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (3) at (-4,.5) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (4) at (-9,2) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (5) at (-7,2) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (6) at (-4,2) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\draw[thick] (zero) -- (1) -- (4);\n%  \\draw[thick] (zero) -- (2);\n%  \\draw[thick] (1) -- (5);\n%  \\draw[thick] (zero) -- (3) -- (6);\n%%\\end{tikzpicture}\n%%\\begin{tikzpicture}[scale=0.5]\n%    \\draw[densely dashed] (-1,-1) -- (1,-1);\n%    \\node[hackennode] (down)   at ( 0,  -1) {};\n%    \\node[hackennode] (middle) at ( 0,   0) {};\n%    \\node[hackennode] (left)   at (-1.5, 1) {};\n%    \\node[hackennode] (right)  at ( 1.5, 1) {};\n%    \\node[hackennode] (top)    at ( 0,   1) {};\n%    \\node[hackennode] (top2)   at (-2,   2) {};\n%    \\node[hackennode] (top3)   at (-1,   2) {};\n%    \\node[hackennode] (top4)   at ( 1.5, 2) {};\n%\n%    \\draw[hackenline,blue]\n%\t\t(down) -- (middle);\n%    \\draw[hackenline,red]\n%\t\t(middle) -- (right);\n%    \\draw[hackenline,red]\n%\t\t(middle) -- (left);\n%    \\draw[hackenline,blue]\n%        (middle) -- (top);\n%    \\draw[hackenline,red]\n%        (left) -- (top2);\n%    \\draw[hackenline,blue]\n%        (left) -- (top3);\n%    \\draw[hackenline,blue]\n%        (right) -- (top4);\n%\n%\\draw[<->, blue, shorten <= 0.25cm, shorten >= 0.1cm] (-6,-1) to[out=-20,in=-180] (0,-.5);\n%\\draw[<->, red, shorten <= 0.25cm, shorten >= 0.1cm] (-8,.5) to[out=20,in=-135] (-.625,.25);\n%\\draw[<->, blue, shorten <= 0.25cm, shorten >= 0.1cm] (-6,.5) to[out=-30,in=-180] (0,.5);\n%\\draw[<->, red, shorten <= 0.25cm, shorten >= 0.1cm] (-4,.5) to[out=50,in=140] (.875,.75);\n%\\draw[<->, red, shorten <= 0.25cm, shorten >= 0.1cm] (-9,2) to[out=30,in=-160] (-1.75,1.5);\n%\\draw[<->, blue, shorten <= 0.25cm, shorten >= 0.1cm] (-7,2) to[out=30,in=120] (-1.1,1.8);\n%\\draw[<->, blue, shorten <= 0.25cm, shorten >= 0.1cm] (-4,2) to[out=30,in=160] (1.5,1.5);\n%\n%\n%\\end{tikzpicture}\n%\\end{figure}\n%\\begin{figure}[H]\n%\\centering\n%\\begin{tikzpicture}[scale=1]\n%    \\draw[densely dashed] (-1,-1) -- (1,-1);\n%    \\node[hackennode] (down)   at ( 0,  -1) {};\n%    \\node[hackennode] (middle) at ( 0,   0) {};\n%    \\node[hackennode] (left)   at (-1.5, 1) {};\n%    \\node[hackennode] (right)  at ( 1.5, 1) {};\n%    \\node[hackennode] (top)    at ( 0,   1) {};\n%    \\node[hackennode] (top2)   at (-2,   2) {};\n%    \\node[hackennode] (top3)   at (-1,   2) {};\n%    \\node[hackennode] (top4)   at ( 1.5, 2) {};\n%\n%    \\draw[hackenline,blue]\n%\t\t(down) -- (middle);\n%    \\draw[hackenline,red]\n%\t\t(middle) -- (right);\n%    \\draw[hackenline,red]\n%\t\t(middle) -- (left);\n%    \\draw[hackenline,blue]\n%        (middle) -- (top);\n%    \\draw[hackenline,red]\n%        (left) -- (top2);\n%    \\draw[hackenline,blue]\n%        (left) -- (top3);\n%    \\draw[hackenline,blue]\n%        (right) -- (top4);\n%        \n%  \\node (zero) at (0,-.5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n%  \\node (1) at (-.75,.5) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n%  \\node (2) at (-0,.5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n%  \\node (3) at (.75,.5) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n%  \\node (4) at (-1.75,1.5) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n%  \\node (5) at (-1.25,1.5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n%  \\node (6) at (1.5,1.5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n%%  \\draw[thick, dashed] (zero) -- (1) -- (4);\n%%  \\draw[thick, dashed] (zero) -- (2);\n%%  \\draw[thick, dashed] (1) -- (5);\n%%  \\draw[thick, dashed] (zero) -- (3) -- (6);\n%\\end{tikzpicture}\n%\\end{figure}\n%jjjj\n%\\end{proof2}\n%\\newpage\n\n\\subsection{Chess-Colored Young Diagram Partizan Poset Games}\nFor chess-colored Young diagrams, we have a very regular structure. This regularity makes it possible to reduce the games significantly, and make even stronger statements about the values of these games. A general result about how we can reduce games played on chess-colored Young diagrams is the following.\n\n\\begin{lem}\n\\label{lem:chessdomopt}\nThe dominating option of $A_\\lambda$, with $\\lambda=(\\lambda_1,\\lambda_2,\\dots,\\lambda_k)$, is always to remove the greatest element of your color in one of the rows.\n\\end{lem}\n~\\\\\nLemma \\ref{lem:chessdomopt} follows from Theorem \\ref{thm:playstrategy}. For a better understanding of what the lemma yields, we will provide some examples of the concept. \n\\begin{ex}{}\nLet $k=4$. With $\\lambda_1=9,\\lambda_2=7,\\lambda_3=7,\\lambda_4=2$, Lemma \\ref{lem:chessdomopt} gives us that: $$A_{9,7,7,2}=\\left\\{A_{8,7,7,2},A_{9,5,5,2},A_{9,7,6,2},A_{9,7,7,1}\\middle|A_{7,7,7,2},A_{9,6,6,2},A_{9,7,5,2},A_{9,7,7,0}\\right\\}.$$\n\\end{ex}\n\\begin{ex}{}\nFor $x=y=3,z=1$ Lemma \\ref{lem:chessdomopt} gives us $$A_{3,3,1}=\\left\\{A_{2,2,1},A_{3,1,1},A_{3,3,0}\\middle|A_{1,1,1},A_{3,2,1}\\right\\},$$ as illustrated in Figure \\ref{fig:chessdomex}.\n\\begin{figure}[H]\n\\centering\n$\n\\begin{tabular}{ | c | c | c |}\n\\hline\n~&\\cellcolor[gray]{0}&~\\\\\n\\hline\n\\cellcolor[gray]{0}&~&\\cellcolor[gray]{0}\\\\\n\\hline\n~\\\\\n\\cline{1-1}\n\\end{tabular}\n=\\left\\{\n\\begin{tabular}{ | c | c |}\n\\hline\n~&\\cellcolor[gray]{0}\\\\\n\\hline\n\\cellcolor[gray]{0}&~\\\\\n\\hline\n~\\\\\n\\cline{1-1}\n\\end{tabular}\n,\n\\begin{tabular}{ | c | c | c |}\n\\hline\n~&\\cellcolor[gray]{0}&~\\\\\n\\hline\n\\cellcolor[gray]{0}\\\\\n\\cline{1-1}\n~\\\\\n\\cline{1-1}\n\\end{tabular}\n,\n\\begin{tabular}{ | c | c | c |}\n\\hline\n~&\\cellcolor[gray]{0}&~\\\\\n\\hline\n\\cellcolor[gray]{0}&~&\\cellcolor[gray]{0}\\\\\n\\hline\n\\end{tabular}\n\\;\\middle|\\;\n\\begin{tabular}{ | c |}\n\\hline\n~\\\\\n\\hline\n\\cellcolor[gray]{0}\\\\\n\\hline\n~\\\\\n\\hline\n\\end{tabular}\n,\n\\begin{tabular}{ | c | c | c |}\n\\hline\n~&\\cellcolor[gray]{0}&~\\\\\n\\hline\n\\cellcolor[gray]{0}&~\\\\\n\\cline{1-2}\n~\\\\\n\\cline{1-1}\n\\end{tabular}\n\\right\\}\n$\n\\captionof{figure}{Concept of Lemma \\ref{lem:chessdomopt}.}\n\\label{fig:chessdomex}\n\\end{figure}\n\\end{ex}\n%~\\\\\n%Lemma \\ref{lem:chessdomopt} follows from Theorem \\ref{thm:playstrategy}, but we will provide an explicit proof and prove Lemma \\ref{lem:chessdomopt} using Theorem \\ref{thm:number} by showing that options when removing non-maximal elements are options of a option when a maximal element is removed, and must therefore be dominated by this option. \n%\\begin{proof2}{Proof of Lemma \\ref{lem:chessdomopt}}\n%Let $G=A_\\lambda$, with $\\lambda=(\\lambda_1,\\lambda_2,\\dots,\\lambda_k)$, and let $G^{L_i},i\\in\\{1,2,\\dots,k\\}$ denote an arbitrary option of Left when playing in the $i$'th row and $G^{R_i},i\\in\\{1,2,\\dots,k\\}$ denote an arbitrary option of Right when playing in the $i$'th row. Let $G^{L_i^{max}},G^{R_i^{max}}$ denote the game options of $G$ when removing the greatest white and black element respectively in the $i$'th row for players Left and Right. \\\\\n%We will then have that $G^{L_i^{max}}>G^{L_i}$ for any other option for Left in the $i$'th row. This is because any other Left option when playing in the $i$'th row except removing the greatest Left element is a game option of $G^{L_i^{max}}$ and by Theorem \\ref{thm:number} we have $G^{L_i^{max}L}<G^{L_i^{max}}$. The same argument also gives us that $G^{R_i^{max}}<G^{R_i}$ for all other Right options of playing in the $i$'th row. Therefore $G^{L_1^{max}},G^{L_2^{max}},G^{L_3^{max}}, G^{R_1^{max}},G^{R_2^{max}},G^{R_3^{max}}$ must be the dominating game options of $G$, and hence Lemma \\ref{lem:chessdomopt} is valid for $G$ itself.\n%\\end{proof2}\n\n\\newpage\n\\subsubsection{Two-Row Chess-Colored Young Diagrams}\n\\input{tworow.tex}\n\\newpage\n\\subsubsection{Three-Row Chess-Colored Young Diagrams}\n\\input{threerow.tex}", "meta": {"hexsha": "2f74007b855e4bb90933e9d762383981574d0f44", "size": 19173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/partizanposetgames.tex", "max_stars_repo_name": "ghw329/DDSC", "max_stars_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/thesis/partizanposetgames.tex", "max_issues_repo_name": "ghw329/DDSC", "max_issues_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/thesis/partizanposetgames.tex", "max_forks_repo_name": "ghw329/DDSC", "max_forks_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.9107142857, "max_line_length": 851, "alphanum_fraction": 0.6381891201, "num_tokens": 7405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790619, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.6598704352364946}}
{"text": "\\documentclass{article}\n\\title{Chapter 05}\n\\author{Newton Ni}\n\n\\usepackage{bussproofs}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\n% Set cardinality: |#1|\n\\newcommand{\\cardinality}[1]{\\lvert#1\\rvert}\n\n% Set: { #1 }\n\\newcommand{\\set}[1]{\\{\\ #1\\ \\}}\n\n% Set comprehension: { #1 | #2 }\n\\newcommand{\\comp}[2]{\\set{#1\\ \\mid\\ #2}}\n\n% t₁, t₂, t₃, ...\n\\newcommand{\\term}[1]{\\texttt{t\\textsubscript{#1}}}\n\n% v₁, v₂, v₃, ...\n\\newcommand{\\val}[1]{\\texttt{v\\textsubscript{#1}}}\n\n% v₁, v₂, v₃, ...\n\\newcommand{\\var}[1]{\\texttt{x\\textsubscript{#1}}}\n\n\\renewcommand{\\ss}[2]{#1 \\longrightarrow #2}\n\\renewcommand{\\bs}[2]{#1 \\Downarrow #2}\n\n% Monospace\n\\newcommand{\\ms}[1]{\\texttt{#1}}\n\n\\newcommand{\\LabelR}[1]{\\RightLabel{\\textsc{#1}}}\n\n\\theoremstyle{remark}\n\\newtheorem*{case}{Case}\n\n\\begin{document}\n\\maketitle\n\n\\section{5.3.3}\n\n    \\textit{Give a careful proof that} $|FV(\\term{})| \\le size(\\term{})$ \\textit{for every term} $\\term{}$.\n\n    \\begin{proof}\n        By structural induction on terms \\term{}. Our inductive hypothesis is:\n        $$H(\\term{}): |FV(\\term{})| \\le size(\\term{})$$\n\n        \\begin{case}[\\textsc{T-Var}]\n            Here, $|FV(\\var{})| = |\\{\\var{}\\}| = 1 \\le size(\\var{}) = 1$.\n        \\end{case}\n\n        \\begin{case}[\\textsc{T-Abs}]\n            Here, $|FV(\\lambda \\var{}. \\term{1})| = |FV(\\term{1}) \\setminus \\{\\var{}\\}|$.\n            \\begin{itemize}\n                \\item If $\\var{} \\in FV(\\term{1})$, then $|FV(\\term{1}) \\setminus \\{\\var{}\\}| = |FV(\\term{1})| - 1$.\n                \\item Otherwise $|FV(\\term{1}) \\setminus \\{\\var{}\\}| = |FV(\\term{1})|$.\n            \\end{itemize}\n            It follows that $|FV(\\term{1}) \\setminus \\{\\var{}\\}| \\le |FV(\\term{1})|$.\n            \\begin{align*}\n                |FV(\\lambda \\var{}. \\term{1})| &= |FV(\\term{1}) \\setminus \\{\\var{}\\}| \\\\\n                                               &\\le |FV(\\term{1})| \\tag{By above} \\\\\n                                               &\\le size(\\term{1}) \\tag{By inductive hypothesis} \\\\\n                                               &\\le size(\\term{1}) + 1 \\\\\n                                               &\\le size(\\lambda \\var{}. \\term{1}) \\tag{By definition of $size$}\n            \\end{align*}\n        \\end{case}\n\n        \\begin{case}[\\textsc{T-App}]\n            \\begin{align*}\n                |FV(\\term{1}\\ \\term{2})| &= |FV(\\term{1}) \\cup FV(\\term{2})| \\\\\n                                         &\\le |FV(\\term{1})| + |FV(\\term{2})| \\\\\n                                         &\\le size(\\term{1}) + size(\\term{2}) \\tag{By inductive hypothesis} \\\\\n                                         &\\le size(\\term{1}\\ \\term{2}) \\tag{By definition of $size$}\n            \\end{align*}\n        \\end{case}\n    \\end{proof}\n\n\\pagebreak\n\\section{5.3.6}\n\n    \\textit{Adapt these rules to describe the other three strategies for}\n    \\textit{evaluation---full beta-reduction, normal-order, and lazy evaluation.}\n\n    \\subsection*{Full Beta-Reduction}\n\n        \\begin{prooftree}\n            \\LabelR{E-App1}\n            \\AxiomC{$\\ss{\\term{1}}{\\term{1}'}$}\n            \\UnaryInfC{$\\ss{\\term{1}\\ \\term{2}}{\\term{1}'\\ \\term{2}}$}\n        \\end{prooftree}\n\n        \\begin{prooftree}\n            \\LabelR{E-App2}\n            \\AxiomC{$\\ss{\\term{2}}{\\term{2}'}$}\n            \\UnaryInfC{$\\ss{\\term{1}\\ \\term{2}}{\\term{1}\\ \\term{2}'}$}\n        \\end{prooftree}\n\n        \\begin{prooftree}\n            \\LabelR{E-Abs}\n            \\AxiomC{$\\ss{\\term{1}}{\\term{1}'}$}\n            \\UnaryInfC{$\\ss{\\lambda \\var{}.\\ \\term{1}}{\\lambda \\var{}.\\ \\term{1}'}$}\n        \\end{prooftree}\n\n        \\begin{prooftree}\n            \\LabelR{E-AppAbs}\n            \\AxiomC{}\n            \\UnaryInfC{$\\ss{\n                (\\lambda \\var{}.\\ \\term{1})\\ \\term{2}\n            }{\n                [\\var{} \\mapsto \\term{2}] \\term{1}\n            }$}\n        \\end{prooftree}\n\n    \\subsection*{Normal-Order}\n\n        % TODO\n\n    \\subsection*{Lazy}\n\n        \\begin{prooftree}\n            \\LabelR{E-App1}\n            \\AxiomC{$\\ss{\\term{1}}{\\term{1}'}$}\n            \\UnaryInfC{$\\ss{\\term{1}\\ \\term{2}}{\\term{1}'\\ \\term{2}}$}\n        \\end{prooftree}\n\n        \\begin{prooftree}\n            \\LabelR{E-AppAbs}\n            \\AxiomC{}\n            \\UnaryInfC{$\\ss{\n                (\\lambda \\var{}.\\ \\term{1})\\ \\term{2}\n            }{\n                [\\var{} \\mapsto \\term{2}] \\term{1}\n            }$}\n        \\end{prooftree}\n\n\\section{5.3.8}\n\n    \\textit{Exercise 4.2.2 introduced a ``big-step'' style of evaluation for arithmetic expressions,}\n    \\textit{where the basic evaluation relation is ``term \\term{} evaluates to final result \\val{}''.}\n    \\textit{Show how to formulate the evaluation rules for lambda-terms in the big-step style.}\n\n    \\begin{prooftree}\n        \\LabelR{E-Abs}\n        \\AxiomC{}\n        \\UnaryInfC{$\\bs{\\lambda \\var{}.\\ \\term{}}{\\lambda \\var{}.\\ \\term{}}$}\n    \\end{prooftree}\n\n    \\begin{prooftree}\n        \\LabelR{E-App}\n        \\AxiomC{$\\bs{\\term{1}}{\\lambda \\var{}.\\ \\term{}}$}\n        \\AxiomC{$\\bs{\\term{2}}{\\val{2}}$}\n        \\AxiomC{$\\bs{[\\var{} \\mapsto \\val{2}]\\ \\term{}}{\\term{}'}$}\n        \\TrinaryInfC{$\\bs{\\term{1}\\ \\term{2}}{\\term{}'}$}\n    \\end{prooftree}\n\n\\end{document}\n", "meta": {"hexsha": "905dff9406d8d45e375bf4c1f5671a32237cc06f", "size": 5155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter-05/chapter-05.tex", "max_stars_repo_name": "nwtnni/tapl", "max_stars_repo_head_hexsha": "7a4184297f4de9ded7d918bc04895302dde9c161", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-28T17:20:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-28T17:20:53.000Z", "max_issues_repo_path": "chapter-05/chapter-05.tex", "max_issues_repo_name": "nwtnni/tapl", "max_issues_repo_head_hexsha": "7a4184297f4de9ded7d918bc04895302dde9c161", "max_issues_repo_licenses": ["MIT"], "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/chapter-05.tex", "max_forks_repo_name": "nwtnni/tapl", "max_forks_repo_head_hexsha": "7a4184297f4de9ded7d918bc04895302dde9c161", "max_forks_repo_licenses": ["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.4213836478, "max_line_length": 116, "alphanum_fraction": 0.4822502425, "num_tokens": 1774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6598704309661968}}
{"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{Warming up}\n\nThe reader might be familiar with most of the materials in this lecture. Our goal is to fix notation and present the basic structural results on Noetherian and Artinian rings or modules, including the celebrated Nakayama's Lemma which will be used repeatedly.\n\n\\section{Review on ring theory}\nLet $R$ be a ring, supposed to be commutative with unit $1 \\neq 0$ as customary. Recall that an ideal $I \\subsetneq R$ is called\n\\begin{compactitem}\n\t\\item \\emph{prime}, if $ab \\in I \\iff (a \\in I) \\vee (b \\in I)$;\n\t\\item \\emph{maximal}, if $I$ is maximal among the proper ideals of $R$ with respect to inclusion.\n\\end{compactitem}\nRecall the following standard facts\n\\begin{itemize}\n\t\\item $I$ is prime if and only if $R/I$ is an integral domain, i.e. has no zero divisors except $0$;\n\t\\item $I$ is maximal if and only if $R/I$ is a field; in particular, maximal ideals are prime;\n\t\\item every proper ideal $I$ is contained in a maximal ideal (an application of Zorn's Lemma).\\index{Zorn's Lemma}\n\\end{itemize}\n\n\\begin{definition}[Local rings] \\index{local ring}\n\tThe ring $R$ is called \\emph{local} if it has a unique maximal ideal, \\emph{semi-local} if it has only finitely many maximal ideals.\n\t\n\tLet $\\mathfrak{m}$ be the maximal ideal of a local ring $R$. We call $R/\\mathfrak{m}$ the \\emph{residue field} of $R$. A local homomorphism between local rings $\\varphi: R_1 \\to R_2$ is a ring homomorphism such that $\\varphi(\\mathfrak{m}_1) \\subset \\mathfrak{m}_2$. Consequently, local homomorphisms induce embeddings on the level of residue fields.\n\\end{definition}\nSometimes we denote a local ring by the pair $(R, \\mathfrak{m})$.\n\n\\begin{remark}\n\tLet $R$ be a local ring with maximal ideal $\\mathfrak{m}$, then $R^\\times = R \\smallsetminus \\mathfrak{m}$. The is easily seen as follows. An element $x \\in R$ is invertible if and only if $Rx = R$. Note that $Rx=R$ is equivalent to that $x$ is not contained in any maximal ideal, and the only maximal ideal is $\\mathfrak{m}$.\n\\end{remark}\n\nThroughout these lectures, we shall write \\index{Spec@$\\Spec(R)$} \\index{MaxSpec@$\\MaxSpec(R)$}\n\\begin{align*}\n\t\\Spec(R) & := \\{ \\text{prime ideals of } R \\}, \\\\\n\t\\MaxSpec(R) & := \\{ \\text{maximal ideals of } R \\}.\n\\end{align*}\nThey are called the \\emph{spectrum} and the \\emph{maximal spectrum} of $R$, respectively. The upshot is that $\\Spec(R)$ comes with a natural topology.\n\n\\begin{definition}[Zariski topology] \\index{Zariski topology}\\index{$V(\\mathfrak{a})$}\n\tFor any ideal $\\mathfrak{a} \\subset R$, set $V(\\mathfrak{a}) := \\{ \\mathfrak{p} \\in \\Spec(R): \\mathfrak{p} \\supset \\mathfrak{a} \\}$. Then there is a topology on $\\Spec(R)$, called the \\emph{Zariski topology}, whose closed subset are precisely $V(\\mathfrak{a})$, for various ideals $\\mathfrak{a}$.\n\\end{definition}\nIndeed, we only have to prove the family of subsets $\\{ V(\\mathfrak{a}) : \\mathfrak{a} \\subset R \\}$ is closed under finite union and arbitrary intersections. It boils down to the easy observation that $V(\\mathfrak{a}) \\cup V(\\mathfrak{b}) = V(\\mathfrak{a}\\mathfrak{b})$ (check this!) and $\\bigcap_{\\mathfrak{a} \\in \\mathcal{A}} V(\\mathfrak{a}) = V\\left( \\sum_{\\mathfrak{a} \\in \\mathcal{A}} \\mathfrak{a} \\right)$, where $\\mathcal{A}$ is any family of ideals.\n\nGiven a ring homomorphism $\\varphi: R_1 \\to R_2$, if $I \\subset R_2$ is an ideal, then $\\varphi^{-1}(I) \\subset R_1$ is also an ideal.\n\\begin{proposition}\n\tGiven $\\varphi$ as above, it induces a continuous map\n\t\\begin{align*}\n\t\t\\varphi^\\sharp: \\Spec(R_2) & \\longrightarrow \\Spec(R_1) \\\\\n\t\t\\mathfrak{p} & \\longmapsto \\varphi^{-1}(\\mathfrak{p})\n\t\\end{align*}\n\twith respect to the Zariski topologies on spectra.\n\\end{proposition}\n\\begin{proof}\n\tClearly, $ab \\in \\varphi^{-1}(\\mathfrak{p})$ is equivalent to $\\varphi(a)\\varphi(b) \\in \\mathfrak{p}$, which is in turn equivalent to $(\\varphi(a) \\in \\mathfrak{p}) \\vee (\\varphi(b) \\in \\mathfrak{p})$ when $\\mathfrak{p}$ is prime.\n\t\n\tTo show the continuity of $\\varphi^\\sharp$, observe that for any ideal $\\mathfrak{a} \\subset R_1$ and $\\mathfrak{p} \\in \\Spec(R_2)$, we have $\\varphi^{-1}(\\mathfrak{p}) \\supset \\mathfrak{a}$ if and only if $\\mathfrak{p} \\supset \\varphi(\\mathfrak{a})$, i.e. $\\mathfrak{p} \\in V(\\varphi(\\mathfrak{a}) R_2)$. Hence the preimage of closed subsets are still closed.\n\\end{proof}\n\nMore operations on spectra:\n\\begin{itemize}\n\t\\item Take $R_1$ to be a subring of $R_2$ and $\\varphi$ be the inclusion map, the map above becomes $\\mathfrak{p} \\mapsto \\mathfrak{p} \\cap R_1$.\n\t\\item Take $\\varphi: R \\twoheadrightarrow R/I$ to be a quotient homomorphism, then $\\varphi^{-1}$ is the usual bijection from $\\Spec(R/I)$ onto $V(I)$.\n\t\\item In general, $\\varphi^{-1}$ does not induce $\\MaxSpec(R_2) \\to \\MaxSpec(R_1)$, as illustrated in the case $\\varphi: \\Z \\hookrightarrow \\Q$.\n\\end{itemize}\n\nAt this stage, we can prove a handy result concerning prime ideals.\n\\begin{proposition}[Prime avoidance]\\label{prop:prime-avoidance} \\index{prime avoidance}\n\tLet $I$ and $\\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n$ be ideals of $R$ such that $I \\subset \\bigcup_{i=1}^n \\mathfrak{p}_i$. Suppose that\n\t\\begin{compactitem}\n\t\t\\item either $R$ contains an infinite field, or\n\t\t\\item at most two of the ideals $\\mathfrak{p}_1, \\ldots, \\mathfrak{p}_n$ are non-prime,\n\t\\end{compactitem}\n\tthen there exists $1 \\leq i \\leq n$ such that $I \\subset \\mathfrak{p}_i$.\n\\end{proposition}\n\\begin{proof}\n\tIf $R$ contains an infinite field $F$, the ideals are automatically $F$-vector subspaces of $R$. Since $I = \\bigcup_{i=1}^r I \\cap \\mathfrak{p}_i$ whereas an $F$-vector space cannot be covered by finitely many proper subspaces, there must exist some $i$ with $I \\cap \\mathfrak{p}_i = I$.\n\n\tUnder the second assumption, let us argue by induction on $n$ that $\\forall i \\; I \\not\\subset \\mathfrak{p}_i$ implies $I \\not\\subset \\bigcup_{i=1}^n \\mathfrak{p}_i$. The case $n=1$ is trivial. When $n \\geq 2$, by induction we may choose, for each $i$, an element $x_i \\in I \\smallsetminus \\bigcup_{j \\neq i} \\mathfrak{p}_j$. Suppose on the contrary that $I \\subset \\bigcup_{j=1}^n \\mathfrak{p}_j$, then we would have $x_i \\in \\mathfrak{p}_i$, for all $i=1, \\ldots, n$.\n\n\tWhen $n=2$ we have $x_1 + x_2 \\notin \\mathfrak{p}_1 \\cup \\mathfrak{p}_2$ and $x_1 + x_2 \\in I$, a contradiction. When $n > 2$, we may assume $\\mathfrak{p}_1$ is prime, therefore\n\t\\[ x_1 + \\prod_{j=2}^n x_j \\notin \\bigcup_{i=1}^n \\mathfrak{p}_i, \\]\n\tagain a contradiction.\n\\end{proof}\n\n\\begin{exercise}\n\tThe following construction from \\cite[Exercise 3.17]{Eis95} shows that the assumptions of Proposition \\ref{prop:prime-avoidance} cannot be weakened. Take $R = (\\Z/2\\Z)[X, Y] / (X,Y)^2$, which has a basis $\\{1, X, Y\\}$ (modulo $(X,Y)^2$) as a $\\Z/2\\Z$-vector space. Show that the image $\\mathfrak{m}$ of $(X, Y)$ in $R$ is the unique prime ideal, and can be expressed as a union of three ideals properly contained in $\\mathfrak{m}$.\n\\end{exercise}\n\n\\section{Localization of rings and modules} \\index{localization}\\index{$M[S^{-1}]$}\nLet $S$ be a \\emph{multiplicative subset} of $R$, which means that\n\\begin{inparaenum}[(a)]\\index{multiplicative subset}\n\t\\item $1 \\in S$,\n\t\\item $S$ is closed under multiplication, and\n\t\\item $0 \\notin S$.\n\\end{inparaenum}\nThe \\emph{localization} of $R$ with respect to $S$ is the ring $R[S^{-1}]$ formed by classes $[r,s]$ with $r \\in R$, $s \\in S$, modulo the equivalence relation\n\\[ [r,s] = [r',s'] \\iff \\exists t \\in S, \\; (rs' - r's)t = 0. \\]\n\nYou should regard $[r,s]$ as a token for $r/s$; the ring structure of $R[S^{-1}]$ is therefore evident. In brief, localization amounts to formally inverting the elements of $S$, whence the notation $R[S^{-1}]$. Note that condition (c) guarantees $R[S^{-1}] \\neq \\{0\\}$.\n\n\\begin{exercise}\n\tGiven $R$ and $S$, show that $r \\mapsto r/1$ yields a natural homomorphism $R \\to R[S^{-1}]$ and show that its kernel equals $\\{r: \\exists s \\in S, \\; sr=0 \\}$.\n\\end{exercise}\n\nThe universal property of $R \\to R[S^{-1}]$ can be stated using commutative diagrams as follows.\n\\[\n\t\\forall \\left\\{ \\begin{array}{l}\n\t\t\\varphi: R \\to R': \\; \\text{ring homomorphism} \\\\\n\t\t\\text{s.t. } \\varphi(S) \\subset (R')^\\times\n\t\\end{array}\\right. ,\\quad\n\t\\begin{tikzcd}\n\t\tR \\arrow[r] \\arrow[rd, \"\\varphi\"'] & R[S^{-1}] \\arrow[d, dashed, \"\\exists!\"] \\\\\n\t\t& R'\n\t\\end{tikzcd}\n\\]\n\nConsequently, if $S \\subset R^\\times$ then $R \\simeq R[S^{-1}]$ canonically. Furthermore, the homomorphism $R \\to R[S^{-1}]$ induces a bijection\n\\begin{equation}\\label{eqn:localization-Spec} \\begin{tikzcd}[row sep=tiny, column sep=small]\n\t\\Spec(R[S^{-1}]) \\arrow[leftrightarrow, r, \"1:1\"] & \\left\\{ \\mathfrak{p} \\in \\Spec(R): \\mathfrak{p} \\cap S = \\emptyset \\right\\} \\arrow[phantom, r, \"\\subset\" description] & \\Spec(R) \\\\\n\t\\mathfrak{p} R[S^{-1}] = \\{ r/s: r \\in \\mathfrak{p}, \\; s \\in S \\} & \\mathfrak{p} \\arrow[mapsto, l] & \\\\\n\t\\mathfrak{q} \\arrow[mapsto, r] & \\text{its preimage} .\n\\end{tikzcd}\\end{equation}\n\n\\begin{exercise}\n\tCheck the properties above.\n\\end{exercise}\n\nLet us review some important instances of the localization procedure.\n\\begin{enumerate}\n\t\\item Take $S$ to be the subset of non zero-divisors of $R$. This is easily seen to be a multiplicative subset (check it!) and $K(R) := R[S^{-1}]$ is called the \\emph{total fraction ring} of $R$. The reader is invited to check that $R \\to K(R)$ is the ``biggest localization'' such that the natural homomorphism $R \\to R[S^{-1}]$ is injective. Hint: state this in terms of universal properties.\\index{total fraction ring}\n\t\n\tWhen $R$ is an integral domain, we shall take $S := R \\smallsetminus \\{0\\}$; in this case the total fraction ring $\\text{Frac}(R) := K(R)$ is the well-known \\emph{field of fractions} of $R$.\\index{field of fractions}\n\t\n\t\\item Take any $\\mathfrak{p} \\in \\Spec(R)$ and $S := R \\smallsetminus \\mathfrak{p}$. From the definition of prime ideals, one infers that $S$ is a multiplicative subset of $R$. The corresponding localization is denoted by $R \\to R_{\\mathfrak{p}} := R[S^{-1}]$. We see from \\eqref{eqn:localization-Spec} that\n\t\t\\[ \\MaxSpec(R_{\\mathfrak{p}}) = \\{ \\mathfrak{p} R_{\\mathfrak{p}} \\}; \\]\n\tin particular, $R_{\\mathfrak{p}}$ is a local ring with maximal ideal $\\mathfrak{p}R_{\\mathfrak{p}}$. This is the standard way to produce local rings; we say that $R_{\\mathfrak{p}}$ is the localization of $R$ at the prime $\\mathfrak{p}$.\n\n\t\\item Suppose $f \\in R$ is not nilpotent, that is, $f^n \\neq 0$ for every $n$. Take $S := \\{ f^n : n \\geq 0 \\}$. The corresponding localization is denoted by the self-explanatory notation $R \\to R[f^{-1}]$.\n\\end{enumerate}\n\n\\begin{exercise}\n\tDescribe the following localizations explicitly.\n\t\\begin{enumerate}[(a)]\n\t\t\\item $R = \\Z$, and we localize at the prime ideal $(p)$ where $p$ is a prime number.\n\t\t\\item $R = \\CC[X_1, \\ldots, X_n]$ and we localize at the maximal ideal generated by $X_1, \\ldots, X_n$.\n\t\t\\item $R = \\CC\\llbracket X \\rrbracket$ (the ring of formal power series) and $S := \\{X^n : n \\geq 0 \\}$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tProve that $R[X]/(fX-1) \\rightiso R[f^{-1}]$ by mapping $X \\mapsto f^{-1}$. Hint: use the universal property.\n\\end{exercise}\n\nAlways let $S \\subset R$ be a multiplicative subset. The localization $M[S^{-1}]$ of an $R$-module $M$ can be defined in the manner above, namely as the set of equivalence classes $[m,s]$ with $m \\in M$ and $s \\in S$, such that\n\\[ [m,s] = [m',s'] \\iff \\exists t \\in S, \\; t(s'm - sm')=0. \\]\nAs in the case of rings, we shall write $m/s$ instead of $[m,s]$. It is an $R[S^{-1}]$-module, equipped with a natural homomorphism $M \\to M[S^{-1}]$ of $R$-modules. This yields a functor: for any homomorphism $f: M \\to N$ we have a natural $f[S^{-1}]: M[S^{-1}] \\to N[S^{-1}]$, mapping $m/s$ to $f(m)/s$; furthermore $f[S^{-1}] \\circ g[S^{-1}] = (f \\circ g)[S^{-1}]$ whenever composition makes sense.\n\nA slicker interpretation is to use the natural isomorphism $M[S^{-1}] \\rightiso R[S^{-1}] \\dotimes{R} M$ which maps $m/s$ to $(1/s) \\otimes m$. Hereafter, we shall identify $M[S^{-1}]$ and $R[S^{-1}] \\dotimes{R} M$ without further comments.\n\nIn the same vein, we may define $M[f^{-1}]$ and $M_{\\mathfrak{p}}$, for non-nilpotent $f \\in R$ and $\\mathfrak{p} \\in \\Spec(R)$ respectively. Localization ``commutes'' with several standard operation on modules, which we sketch below. The details are left to the reader.\n\\begin{itemize}\n\t\\item For $R$-modules $M$, $N$, we have a natural isomorphism of $R[S^{-1}]$-modules\n\t\t\\begin{gather*}\n\t\t\t(M \\dotimes{R} N)[S^{-1}] \\simeq M[S^{-1}] \\dotimes{R[S^{-1}]} N[S^{-1}], \\\\\n\t\t\t(M \\oplus N)[S^{-1}] \\simeq M[S^{-1}] \\oplus N[S^{-1}].\n\t\t\\end{gather*}\n\t\tSame for arbitrary direct sums. This is easily seen by viewing $M[S^{-1}]$ as $M \\otimes_R R[S^{-1}]$.\n\t\\item Note that $\\Hom_R(M, N)$ is also an $R$-module: simply set $(rf)(m) = r \\cdot f(m)$ for any $f \\in \\Hom_R(M, N)$. There is a natural homomorphism\n\t\t\\begin{gather}\\label{eqn:localization-Hom}\n\t\t\t\\Hom_R(M, N)[S^{-1}] \\to \\Hom_{R[S^{-1}]} \\left( M[S^{-1}], N[S^{-1}] \\right)\n\t\t\\end{gather}\n\t\tsending $s^{-1} \\otimes \\varphi$ to $s^{-1}\\varphi: m/t \\mapsto \\varphi(m)/st$. It is clearly an isomorphism for $M = R$, thus also for $M = R^a$ where $a \\in \\Z_{\\geq 0}$, but this is not the case in general, as there is no uniform bound for the ``denominators'' for any given $\\psi: M[S^{-1}] \\to N[S^{-1}]$ --- some finiteness condition is needed. Let us assume $M$ to be \\emph{finitely presented}\\index{finitely presented}, i.e. there is an exact sequence\n\t\t\\[ R^a \\to R^b \\to M \\to 0, \\quad a,b \\in \\Z_{\\geq 0}. \\]\n\t\tIn this case \\eqref{eqn:localization-Hom} is an isomorphism, as easily seen from the commutative diagram with exact rows:\n\t\t\\[ \\begin{tikzcd}[column sep=tiny]\n\t\t\t0 \\arrow[r] & \\Hom(M,N)[S^{-1}] \\arrow[r] \\arrow[d] & \\Hom(R^b, N)[S^{-1}] \\arrow[r] \\arrow[d, \"\\simeq\"] & \\Hom(R^a, N)[S^{-1}] \\arrow[d, \"\\simeq\"] \\\\\n\t\t\t0 \\arrow[r] & \\Hom(M[S^{-1}], N[S^{-1}]) \\arrow[r] & \\Hom(R[S^{-1}]^b, N[S^{-1}]) \\arrow[r] & \\Hom(R[S^{-1}]^a, N[S^{-1}])\n\t\t\\end{tikzcd}\\]\n\t\tHere we used the fact that localization preserves exactness: see the Proposition \\ref{prop:localization-exactness} below.\n\t\\item Let $\\varphi: R \\to R'$ be a ring homomorphism and $S \\subset R$ be a multiplicative subset, so that $S' := \\varphi(S) \\subset R'$ is also multiplicative. View $R'$ as an $R$-module, then we have\n\t\\[\\begin{tikzcd}[row sep=tiny]\n\t\t\\underbracket{R'[(S')^{-1}]}_{\\text{as ring}} \\arrow[r, \"\\sim\"] & \\underbracket{R'[S^{-1}]}_{\\text{as module}} \\arrow[equal, r] & R[S^{-1}] \\dotimes{R} R' \\\\\n\t\tr'/\\varphi(s) \\arrow[mapsto, rr] & & (1/s) \\otimes r' \\\\\n\t\tr'\\varphi(r)/\\varphi(s) & & (r/s) \\otimes r' \\arrow[mapsto, ll]\n\t\\end{tikzcd}\\]\n\t\\item As a special case, take $\\varphi$ to be a quotient homomorphism $R \\to R/I$, we get a natural isomorphism\n\t\t\\[ (R/I)[(S')^{-1}] \\simeq R[S^{-1}] \\dotimes{R} (R/I) = \\frac{R[S^{-1}]}{I[S^{-1}]} \\]\n\t\tfrom the right exactness of $\\otimes$.\n\\end{itemize}\n\nWe prove an easy yet fundamental property of localizations, namely they are exact functors.\n\\begin{proposition}[Exactness of localization]\\label{prop:localization-exactness}\n\tLet $S$ be any multiplicative subset of $R$. If\n\t\\[ \\cdots \\to M_i \\xrightarrow{f_i} M_{i+1} \\to \\cdots \\]\n\tis an exact sequence of $R$-modules, then\n\t\\[ \\cdots \\to M_i[S^{-1}] \\xrightarrow{f_i[S^{-1}]} M_{i+1}[S^{-1}] \\to \\cdots \\]\n\tis also exact.\n\\end{proposition}\n\\begin{proof}\n\tBy homological common sense, we are reduced to the exact sequences\n\t\\begin{inparaenum}[(i)]\n\t\t\\item $0 \\to M' \\to M \\to M''$ (i.e. left exactness),\n\t\t\\item $M' \\to M \\to M'' \\to 0$ (i.e. right exactness).\n\t\\end{inparaenum}\n\tThe case (ii) is known for tensor products in general.\n\t\n\tAs for (i), note that for every homomorphism $g: M \\to M''$,\n\t\\begin{align*}\n\t\t\\Ker\\left(g[S^{-1}]\\right) & = \\left\\{ \\frac{y}{s} \\in M[S^{-1}]: \\exists t \\in S, \\; t g(y)=0 \\right\\}  \\xlongequal{\\because y/s = ty/ts} \\left\\{ \\frac{y}{s} : y \\in \\Ker(g)  \\right\\} \\\\\n\t\t& = \\Image\\left[ \\Ker(g)[S^{-1}] \\to M[S^{-1}] \\right].\n\t\\end{align*}\n\tThus it remains to show that if $f: M' \\hookrightarrow M$, then $f[S^{-1}]: M'[S^{-1}] \\to M[S^{-1}]$ is injective as well. If $x/s \\mapsto f(x)/s = 0$ under $f[S^{-1}]$, there exists $t \\in S$ such that $tf(x) = f(tx) = 0$ in $M$, therefore $tx=0$ in $M'$, but the latter condition implies $x/s = 0$ in $M'[S^{-1}]$.\n\\end{proof}\n\n\\begin{lemma}\n\tLet $M$ be an $R$-module. The localizations $M \\to M_{\\mathfrak{m}}$ for various maximal ideals $\\mathfrak{m}$ assemble into an injection\n\t\\[ M \\hookrightarrow \\prod_{\\mathfrak{m} \\in \\MaxSpec(R)} M_{\\mathfrak{m}}. \\]\n\\end{lemma}\n\\begin{proof}\n\tLet $m \\in M$ be such that $m \\mapsto 0 \\in M_{\\mathfrak{m}}$ for all $\\mathfrak{m}$. This means that for all $\\mathfrak{m}$ there exists $s \\in R \\smallsetminus \\mathfrak{m}$ such that $sm=0$. Hence the annihilator ideal $\\text{ann}_R(m) := \\{r \\in R: rm=0 \\}$ is not contained in any maximal ideal, thus $\\text{ann}_R(m) = R$.\n\\end{proof}\nThere is an analogue for rings. Observe that when $R$ is an integral domain, all the localizations $R[S^{-1}]$ can be regarded as subrings of the field of fractions $\\text{Frac}(R)$.\n\\begin{lemma}\n\tLet $R$ be an integral domain, then $R = \\bigcap_{\\mathfrak{m} \\in \\MaxSpec(R)} R_{\\mathfrak{m}}$ as subrings of $\\mathrm{Frac}(R)$.\n\\end{lemma}\n\\begin{proof}\n\tOnly the inclusion $\\supset$ requires proof. Let $x \\in \\text{Frac}(R)$ and define $D := \\{r \\in R: rx \\in R \\}$ (the ideal of denominators). Suppose $x \\in R_{\\mathfrak{m}}$ for all maximal $\\mathfrak{m}$, then $D \\not\\subset \\mathfrak{m}$ for all maximal $\\mathfrak{m}$. The same reasoning as above leads to $D=R$.\n\\end{proof}\nIt will be important to gain finer control on the ideals $\\mathfrak{m}$ in the assertion above, say by using some prime ideals ``lower'' than the maximal ones. We will return to this issue later.\n\n\\section{Radicals and Nakayama's lemma}\nWe begin with two important notions of radicals. The first version is defined as follows. Given an ideal $I$ of $R$, the \\emph{nilpotent radical} $\\sqrt{I}$ is defined to be\n\\[ \\sqrt{I} := \\{ r \\in R: \\exists n, \\; r^n \\in I \\}. \\]\nIt is readily seen to be an ideal from the binomial identity $(a+b)^{2n} = \\sum_{k=0}^{2n} \\binom{2n}{k} a^k b^{2n-k}$. It should also be clear that $\\sqrt{I} \\subset R$ equals the preimage of $\\sqrt{0} \\subset R/I$. \\index{nilpotent radical}\n\n\\begin{exercise}\n\tShow that $\\sqrt{\\sqrt{I}} = I$ for all ideal $I$.\n\\end{exercise}\n\n\\begin{proposition}\n\tLet $I$ be a proper ideal of $R$. We have\n\t\\[ \\sqrt{I} = \\bigcap_{\\substack{\\mathfrak{p} \\in \\Spec(R) \\\\ \\mathfrak{p} \\supset I }} \\mathfrak{p}. \\]\n\\end{proposition}\n\\begin{proof}\n\tBy replacing $R$ by $R/I$, this is easily reduced to the case $I = \\{0\\}$. If $r$ is nilpotent and $\\mathfrak{p} \\in \\Spec(R)$, then $r^n = 0 \\in \\mathfrak{p}$ implies $r \\in \\mathfrak{p}$. Conversely, suppose that $r$ is not nilpotent. There exists a prime ideal in $R[r^{-1}]$, which comes from some $\\mathfrak{p} \\in \\Spec(R)$ with $r \\in R \\smallsetminus \\mathfrak{p}$ by \\eqref{eqn:localization-Spec}. Hence $r \\notin \\mathfrak{p}$.\n\\end{proof}\n\\begin{remark}\\index{reduced ring}\n\tA ring $R$ is called \\emph{reduced} if $\\sqrt{0} = \\{0\\}$. In any case, $R_\\text{red} := R \\big/ \\sqrt{0}$ is a reduced ring. Furthermore, any reduced quotient of $R$ factors through $R_\\text{red}$.\n\\end{remark}\n\nThe second radical is probably familiar to the readers. The \\emph{Jacobson radical} $\\text{rad}(R)$ of the ring $R$ is the intersection of all maximal ideals. The previous proposition implies $\\text{rad}(R) \\supset \\sqrt{(0)}$. Note that\n\\[ a \\in \\text{rad}(R) \\implies (1+a) \\in R^\\times . \\]\nIndeed, $1+a$ cannot be contained in any maximal ideal $\\mathfrak{m}$, for otherwise $1 = (1+a)-a \\in \\mathfrak{m}$, which is absurd. \\index{Jacobson radical}\n\nTo prove the celebrated Nakayama's Lemma, let us recall an easy variant of the Cayley--Hamilton theorem from linear algebra.\n\\begin{lemma}\\label{prop:Cayley-Hamilton}\\index{Cayley--Hamilton theorem}\n\tSuppose that $I \\subset R$ is an ideal, $M$ is an $R$-module with generators $x_1, \\ldots, x_n$ and $\\varphi \\in \\End_R(M)$ satisfies $\\varphi(M) \\subset IM$, then there exists a polynomial $P(X) = X^n + a_{n-1} X^{n-1} + \\cdots + a_0 \\in R[X]$ with $a_i \\in I$, such that $P(\\varphi) = \\varphi^n + a_{n-1} \\varphi^{n-1} + \\cdots + a_0 = 0$.\n\\end{lemma}\n\\begin{proof}\n\tWrite $\\varphi(x_i) = \\sum_{j=1}^n a_{ij} x_j$ where $a_{ij} \\in I$. Set $A := (a_{ij})_{1 \\leq i,j \\leq n} \\in \\text{Mat}_n(R)$. Regard $M$ as an $R[X]$-module by letting $X$ act as $\\varphi$. Then we have the matrix equation over $R[X]$\n\t\\[ (X \\cdot \\identity_{n \\times n} - A) \\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{pmatrix} = \\begin{pmatrix} 0 \\\\ \\vdots \\\\ 0 \\end{pmatrix} \\]\n\tMultiplying by the cofactor matrix $(X \\cdot \\identity_M - A)^\\vee$ on the left, we see that $P(X) := \\det(X \\cdot \\identity_{n \\times n} - A) \\in R[X]$ acts as $0$ on each $x_i$, thus on the whole $M$. This is the required polynomial.\n\\end{proof}\n\n\\begin{theorem}[Nakayama's Lemma]\\label{prop:NAK}\\index{Nakayama's lemma}\n\tSuppose that $M$ is a finitely generated $R$-module and $I$ is an ideal of $R$ such that $IM = M$. Then there exists $a \\in I$ such that $(1+a)M=0$. If $I \\subset \\text{rad}(R)$, then we have $M = \\{0\\}$ under these assumptions.\n\\end{theorem}\n\\begin{proof}\n\tWrite $M = Rx_1 + \\cdots + Rx_n$. Plug $\\varphi = \\identity_M$ into Lemma \\ref{prop:Cayley-Hamilton} to deduce that $P(\\identity_M) = 1 + \\underbracket{a_{n-1} + \\cdots + a_0}_{=: a \\in I}$ acts as $0$ on $M$. This proves the first part. Assume furthermore that $I \\subset \\text{rad}(R)$, then $1+a \\in R^\\times$ so that $M = (1+a)M = 0$.\n\\end{proof}\n\n\\begin{figure}[h]\n\t\\centering \\includegraphics[height=180pt]{Nakayama.png} \\\\ \\vspace{1em}\n\t\\begin{minipage}{0.7\\textwidth}\n\t\t\\small Nakayama's Lemma is named after Tadashi Nakayama (1912---1964). Picture borrowed from \\cite{obi-NAK}.\n\t\\end{minipage}\n\\end{figure}\n\n\\begin{corollary}\\label{prop:NAK-generation}\n\tLet $M$ be a finitely generated $R$-module, and let $I \\subset \\mathrm{rad}(R)$ be an ideal of $R$. If the images of $x_1, \\ldots, x_n \\in M$ in $M/IM$ form a set of generators, then $x_1, \\ldots, x_n$ generate $M$.\n\\end{corollary}\n\\begin{proof}\n\tApply Theorem \\ref{prop:NAK} to $N := M/(Rx_1 + \\cdots + Rx_n)$; our assumption $M = IM + Rx_1 + \\cdots + Rx_n$ entails that $IN=N$, thus $N=0$.\n\\end{proof}\n\nWe record another amusing consequence of Theorem \\ref{prop:NAK}.\n\\begin{proposition}\n\tLet $M$ be a finitely generated $R$-module and $\\psi \\in \\End_R(M)$. If $\\psi$ is surjective then $\\psi$ is an automorphism.\n\\end{proposition}\n\\begin{proof}\n\tIntroduce a variable $Y$. Make $M$ into an $R[Y]$-module by letting $Y$ act as $\\psi$. Put $I := (Y)$ so that $IM=M$. Theorem \\ref{prop:NAK} yields some $Q(Y) \\in R[Y]$ satisfying $(1 - Q(Y)Y) M = 0$, that is, $Q(\\psi)\\psi = \\identity_M$.\n\\end{proof}\n\n\\section{Noetherian and Artinian rings}\nAn $R$-module $M$ is called \\emph{Noetherian} (resp. \\emph{Artinian}) if every ascending (resp. descending) chain of submodules eventually stabilizes. Recall that in a short exact sequence $0 \\to M' \\to M \\to M'' \\to 0$, we have $M$ is Noetherian (resp. Artinian) if and only if $M'$ and $M''$ are. Being both Noetherian and Artinian is equivalent to being a module of \\emph{finite length}\\index{length}, that is, a module admitting composition series. \\index{Artinian}\\index{Noetherian}\n\nIf we take $M := R$ on which $R$ acts by multiplication, then the submodules are precisely the ideals of $R$. We say that $R$ is a Noetherian (resp. Artinian) ring if $R$ as an $R$-module is Noetherian (resp. Artinian); this translates into the corresponding chain conditions on the ideals. Both chain conditions are preserved under passing to quotients and localizations. Finitely generated modules over a Noetherian ring are Noetherian. The following result ought to be known to the readers.\n\\begin{theorem}[Hilbert's Basis Theorem] \\index{Hilbert's basis theorem}\n\tIf $R$ is Noetherian, then so is the polynomial algebra $R[X_1, \\ldots, X_n]$ for any $n \\in \\Z_{\\geq 1}$.\n\\end{theorem}\nJoint with the foregoing remarks, we infer that finitely generated algebras over Noetherian rings are still Noetherian.\n\nOn the other hand, being Artinian is a rather stringent condition on rings.\n\\begin{theorem}\\label{prop:Artinian-length}\n\tA ring $R$ is Artinian if and only if $R$ is of finite length as an $R$-module. Such rings are semi-local.\n\\end{theorem}\n\\begin{proof}\n\tAs noticed before, having finite length implies that $R$ is Noetherian as well as Artinian. Assume conversely that $R$ is an Artinian ring. First we claim that $\\MaxSpec(R)$ is finite, i.e. $R$ is semi-local. If there were an infinite sequence of distinct maximal ideals $\\mathfrak{m}_1, \\mathfrak{m}_2, \\ldots$, we would have an infinite chain\n\t\\[ \\mathfrak{m}_1 \\supset \\mathfrak{m}_1 \\mathfrak{m}_2 \\supset \\mathfrak{m}_1 \\mathfrak{m}_2 \\mathfrak{m}_3 \\supset \\cdots. \\]\n\tThis chain is strictly descending, since $\\mathfrak{m}_1 \\cdots \\mathfrak{m}_i = \\mathfrak{m}_1 \\cdots \\mathfrak{m}_{i+1}$ would imply $\\mathfrak{m}_{i+1} \\supset \\mathfrak{m}_1 \\cdots \\mathfrak{m}_i$, hence $\\mathfrak{m}_{i+1} \\supset \\mathfrak{m}_j$ for some $1 \\leq j \\leq i$ because maximal ideals are prime. From the Artinian property we conclude that there are only finitely many maximal ideals $\\mathfrak{m}_1, \\ldots, \\mathfrak{m}_n$ of $R$.\n\t\n\tSet $\\mathfrak{a} := \\mathfrak{m}_1 \\cdots \\mathfrak{m}_n$. Since $R$ is Artinian we must have $\\mathfrak{a}^k = \\mathfrak{a}^{k+1}$ for some $k > 0$. We claim that $\\mathfrak{a}^k = 0$.\n\t\n\tPut $\\mathfrak{b} := \\{r \\in R: r\\mathfrak{a}^k = 0 \\}$, we have to show $\\mathfrak{b}=R$. If not, let $\\mathfrak{b}'$ be a minimal ideal lying strictly over $\\mathfrak{b}$. Thus $\\mathfrak{b}' = Rx + \\mathfrak{b}$ for any $x \\in \\mathfrak{b}' \\smallsetminus \\mathfrak{b}$. We must have $\\mathfrak{a}x + \\mathfrak{b} \\subsetneq \\mathfrak{b}'$, for otherwise $M := \\mathfrak{b}'/\\mathfrak{b}$ is finitely generated (say by $x$) and satisfies $M = \\mathfrak{a}M$, then Theorem \\ref{prop:NAK} plus $\\mathfrak{a} \\subset \\text{rad}(R)$ would imply $M = \\{0\\}$, which is absurd. By minimality we have $\\mathfrak{b} = \\mathfrak{a}x + \\mathfrak{b}$. It follows that $\\mathfrak{a}x \\subset \\mathfrak{b}$, i.e. $\\mathfrak{a}^{k+1} x = 0$; from $\\mathfrak{a}^k = \\mathfrak{a}^{k+1}$ we infer $x \\in \\mathfrak{b}$. Contradiction.\n\t\n\tAll in all, we obtain a descending chain of ideals\n\t\\begin{align*}\n\t\tR & \\supset \\mathfrak{m}_1 \\supset \\mathfrak{m}_1 \\mathfrak{m}_2 \\supset \\cdots \\supset \\mathfrak{m}_1 \\cdots \\mathfrak{m}_n = \\mathfrak{a} \\\\\n\t\t& \\supset \\mathfrak{a} \\mathfrak{m}_1 \\supset \\mathfrak{a} \\mathfrak{m}_1 \\mathfrak{m}_2 \\supset \\cdots \\supset \\mathfrak{a} \\mathfrak{m}_1 \\cdots \\mathfrak{m}_n = \\mathfrak{a}^2 \\\\\n\t\t& \\supset \\cdots \\supset \\mathfrak{a}^k = \\{0\\}.\n\t\\end{align*}\n\tEach subquotient thereof, which is \\textit{a priori} an $R$-module, is actually an $R/\\mathfrak{m}_i$-vector space for some $1 \\leq i \\leq n$. Such a vector space must also satisfy the descending chain condition on vector subspaces, otherwise pulling-back will contradict the Artinian assumption on $R$. Artinian vector spaces must be finite-dimensional. It follows that all these subquotients are of finite length, hence so is $R$ itself.\n\\end{proof}\n\n\\begin{corollary}\\label{prop:Artinian-dim-0}\n\tA ring $R$ is Artinian if and only if it is Noetherian and every prime ideal of $R$ is maximal.\n\\end{corollary}\n\\begin{proof}\n\tIf $R$ is Artinian, then $R$ is of finite length, hence is Noetherian as well. For every prime ideal $\\mathfrak{p}$, we have $\\mathfrak{p} \\supset \\{0\\} = (\\mathfrak{m}_1 \\cdots \\mathfrak{m}_n)^k$ in the notations of the proof above, therefore $\\mathfrak{p} \\supset \\mathfrak{m}_i$ for some $i$, so $\\mathfrak{p} = \\mathfrak{m}_i$ is maximal.\n\n\tConversely, if $R$ is Noetherian but of infinite length, then the nonempty set of ideals\n\t\\[ \\mathcal{S} := \\left\\{ \\text{ideals } I \\subsetneq R: R/I \\text{ has infinite length} \\right\\} \\]\n\tcontains a maximal element $\\mathfrak{p}$. We contend that $\\mathfrak{p}$ is prime. If $xy \\in \\mathfrak{p}$ with $x,y \\notin \\mathfrak{p}$, then $R/(\\mathfrak{p}+Rx)$ has finite length by the choice of $\\mathfrak{p}$; on the other hand, $\\mathfrak{a} := \\{ r \\in R: rx \\in \\mathfrak{p}\\} \\supsetneq \\mathfrak{p}$ (as $y \\in \\mathfrak{a}$), hence $R/\\mathfrak{a}$ has finite length as well. From the short exact sequence $0 \\to R/\\mathfrak{a} \\xrightarrow{x} R/\\mathfrak{p} \\to R/(\\mathfrak{p}+Rx) \\to 0$ we see $R/\\mathfrak{p}$ has finite length, contradiction.\n\t\n\tIf we assume moreover that every prime ideal is maximal, then for the $\\mathfrak{p}$ chosen above, $R/\\mathfrak{p}$ will be a field, thus of finite length. This is impossible.\n\\end{proof}\n\nRings whose prime ideals are all maximal are said to have \\emph{dimension zero}, in the sense of Krull dimensions; we shall return to this point in \\S\\ref{sec:Krull-dimension}.\n\n\\section{What is commutative algebra?}\nIn broad terms, \\emph{commutative algebra} is the study of commutative rings. Despite its intrinsic beauty, we prefer to motivate from an external point of view. See also \\cite{Eis95}.\n\n\\begin{asparaenum}[(A)]\n\t\\item \\textbf{Algebraic geometry}\\index{variety}. To simplify matters, we consider affine algebraic varieties over an algebraically closed field $\\Bbbk$. Roughly speaking, such a variety is the zero locus $\\mathcal{X} = \\{ f_1 = \\cdots = f_r = 0 \\}$ in $\\mathbb{A}^n = \\Bbbk^n$ of $f_i \\in \\Bbbk[X_1, \\ldots, X_n]$. The choice of equations is of course non-unique: what matters is the ideal $I(\\mathcal{X}) := \\{ f \\in \\Bbbk[X_1, \\ldots, X_n] : f|_{\\mathcal{X}} = 0 \\}$. Conversely, every ideal $\\mathfrak{a}$ defines a subset $V(\\mathfrak{a}) := \\{x \\in \\Bbbk^n : \\forall f \\in \\mathfrak{a}, \\; f(x)=0 \\}$. As consequences of Hilbert's Nullstellensatz\\index{Nullstellensatz}, which we will discuss later, we have\n\t\\[ V \\circ I(\\mathcal{X}) = \\mathcal{X}, \\qquad I \\circ V(\\mathfrak{a})  = \\sqrt{\\mathfrak{a}}. \\]\n\tOne can deduce from this that the (closed) subvarieties of $\\mathbb{A}^n$ are in bijection with ideals $\\mathfrak{a}$ satisfying $\\sqrt{\\mathfrak{a}} = \\mathfrak{a}$.\n\n\tFurthermore, $\\Bbbk[\\mathcal{X}] := \\Bbbk[X_1, \\ldots, X_n]/I(\\mathcal{X})$ may be regarded as the ring of ``regular functions'' (i.e. functions definable by means of polynomials) on $\\mathcal{X}$, and $\\MaxSpec(\\Bbbk[\\mathcal{X}])$ is in bijection with the points of $\\mathcal{X}$: to $x = (x_1, \\ldots, x_n) \\in \\mathcal{X}$ we attach\n\t\\[ \\mathfrak{m}_x = (X_1 - x_1, \\ldots, X_n - x_n) \\supset I(\\mathcal{X}). \\]\n\tBy passing to the ring $\\Bbbk[\\mathcal{X}]$, we somehow obtain a description of $\\mathcal{X}$ that is independent of embeddings into affine spaces. Moreover, $\\mathcal{X}$ inherits the Zariski topology from that on $\\Spec(\\Bbbk[\\mathcal{X}])$.\n\n\tNaively speaking, the geometric properties of $\\mathcal{X}$ transcribe in ring-theoretic terms to the reduced Noetherian $\\Bbbk$-algebra $\\Bbbk[\\mathcal{X}]$. For example, assume that $f \\in \\Bbbk[\\mathcal{X}]$ is not nilpotent, then the formation of $\\Bbbk[\\mathcal{X}][f^{-1}]$ corresponds to taking the Zariski-open subset $\\mathcal{X}_f = \\{x \\in \\mathcal{X}: f(x) \\neq 0 \\}$ of $\\mathcal{X}$. This may be explained as follows:\n\t\\[ \\mathcal{X}_f \\simeq \\left\\{ (x_1, \\ldots, x_n, y) : f_1(x_1, \\ldots, x_n) = \\cdots = f_r(x_1, \\ldots, x_n) = 0, \\; f(x_1, \\ldots, x_n)y = 1 \\right\\} \\]\n\twhich is also an affine algebraic variety in $\\Bbbk^{n+1}$, and one may verify that $\\Bbbk[\\mathcal{X}_f] = \\Bbbk[\\mathcal{X}][f^{-1}]$.\n\n\t\\item \\textbf{Invariant theory}\\index{invariant theory}. Let $G$ be a group acting on a finite-dimensional $\\Bbbk$-vector space $V$ from the right, and let $\\Bbbk[V]$ be the $\\Bbbk$-algebra of polynomials on $V$. Thus $\\Bbbk[V]$ carries a left $G$-action by $gf(v) = f(vg)$. For ``reasonable'' groups $G$, say finite or $\\Bbbk$-algebraic ones, the classical invariant theory seeks to describe the subalgebra $\\Bbbk[V]^G$ of invariants\\footnote{More generally, we are also interested in the algebra of invariant differential operators with polynomial coefficients.} in terms of \\emph{generators} and \\emph{relations}.\n\n\tIn particular, one has to know when is the algebra $\\Bbbk[V]^G$ finitely generated. This is actually the source of many results in commutative algebra, such as the Basis Theorem and Nullstellensatz of Hilbert. For example, let the symmetric group $G = \\mathfrak{S}_n$ act on $V = \\Bbbk^n$ in the standard manner, then our question is completely answered by the following classical result: $\\Bbbk[V]^G$ equals the polynomial algebra $\\Bbbk[e_1, \\ldots, e_n]$, where $e_i$ stands for the $i$-th elementary symmetric function in $n$ variables.\n\n\tThe same questions may be posed for any affine algebraic variety $V$. From the geometric point of view, if $\\Bbbk[V]^G$ is finitely generated, it will consist of regular functions of some kind of quotient variety $V /\\!/ G$. The study of quotients in this sense naturally leads to \\emph{geometric invariant theory}, for which we refer to \\cite{AG4} for details.\n\\end{asparaenum}\n", "meta": {"hexsha": "9983397775e1c4e8a109087d17bc71f201d77a97", "size": 33495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "YAlg3-1.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-1.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-1.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": 91.0190217391, "max_line_length": 819, "alphanum_fraction": 0.6797133901, "num_tokens": 11832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6598704264364408}}
{"text": "\\section{Introduction}\n\nThe main focus of the report is to find anomaly in data set from NSL-KDD dataset. Most of these patterns represent normal behaviour, but there are several cases that due to faulty device or attack to the network with abnormal patterns. In this report, spectral clustering method is going to be used.\n\nMost of spectral clustering algorithms here are highly dependent on the eigenvector decomposition of the graph Laplacian and are variants of the normalized cut method. Basic idea of clustering started from \\textit{Normalized Cuts and Image Segmentation}. All graph clustering objective function can be written as: \\\\\n\n\\begin{figure}[ht]\n\\begin{mdframed}\n$J = cut(A,B)/assoc(1) + cut(A,B)/assoc(2)$. \\\\\n$assoc(1) = \\sum_{i \\in C_k} 1$ for \\textit{Ratio cut}.  \\\\\n$assoc(1) \\sum_{i,j \\in C_k} w_{i,j}$ for \\textit{Normalized cut}. \\\\\n\\end{mdframed}\n\\caption{Objective function of graph clustering algorithm}\n\\end{figure}\n\nIn \\textit{Learning spectral clustering}, a new algorithm for spectral clustering with an objective function that minimize the error measure between a given partition and the minimum normalized cut partition is suggested. In \\textit{On Spectral Clustering: Analysis and an algorithm}, a similar approach with previous one is used except the authors normalize the rows of the chosen eigenvectors. In \\textit{Kernel K-means, Spectral Clustering and Normalized Cut}, the authors present kernel k-means algorithm and derive the nomi- nalized cut algorithm as a special case of the kernel k-means. In \\textit{Linearized Cluster Assignment via Spectral Ordering}, the authors suggest a new way clustering method that is able to partition the data into $K$ clusters. \\\\\n\n\n", "meta": {"hexsha": "b52908fc674ca79a081fdc064430c6a43b680d43", "size": 1710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/references/reference_research/introduction.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/introduction.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/introduction.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": 90.0, "max_line_length": 762, "alphanum_fraction": 0.7842105263, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6598540119346609}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Centers of Mass and Centroids}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious questions relating to centers of mass and centroids.\n\\end{abstract}\n\\maketitle\n\n%\\begin{exercise}%%Community Calculus Section 09.06\n%A thin plate fills the upper half of the unit circle $x^2 + y^2 = 1$. Find the centroid.\n%\\[ \\overline{x} = \\answer{0} \\text{ and } \\overline{y} = \\answer{\\frac{4}{3 \\pi}}. \\]\n%\\end{exercise}\n\n\\begin{exercise}%%Community Calculus 09.06\nFind the centroid of the region bounded above by $y = x$ and below by $y = x^2$.\n\\[ \\overline{x} = \\answer{\\frac{1}{2}} \\text{ and } \\overline{y} = \\answer{\\frac{2}{5}}. \\]\n\\end{exercise}\n\n\\begin{exercise}%%Community Calculus 09.06\nFind the centroid of the region bounded above by $y = 4-x^2$ and below by $y = 0$.\n\\[ \\overline{x} = \\answer{0} \\text{ and } \\overline{y} = \\answer{\\frac{8}{5}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nA thin plate in the plane defined by $x^2 \\leq y \\leq 1$ and $x \\geq 0$ has density $y$ at the point $(x,y)$. Compute the center of mass.\n\\begin{hint}\nUse $y$ as the variable of slicing. The center of mass of a single slice $(\\tilde x, \\tilde y)$ is then $(\\sqrt{y}/2,y)$.\n\\end{hint}\n\\[ \\overline{x} = \\answer{\\frac{1}{2}} \\text{ and } \\overline{y} = \\answer{\\frac{5}{7}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nA thin plate in the plane defined by $x^2 \\leq y \\leq 2x^2$ and $0 \\leq x \\leq 1$ has density $x$ at the point $(x,y)$. Compute the center of mass.\n\\begin{hint}\nUse $x$ as the variable of slicing. The center of mass of a single slice $(\\tilde x, \\tilde y)$ is then $(x,3x^2/2)$.\n\\end{hint}\n\\[ \\overline{x} = \\answer{\\frac{4}{5}} \\text{ and } \\overline{y} = \\answer{1}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nThe same thin plate as above ($x^2 \\leq y \\leq 2x^2$ and $0 \\leq x \\leq 1$) now has density $x^{-2}$ at the point $(x,y)$.  Because the density of the plate is now higher near the origin than in the previous problem, this suggests that the center of mass will shift \\wordChoice{\\choice{away from}\\choice[correct]{towards}} the origin relative to the previous exercise.\n\nCompute the center of mass.\n\\[ \\overline{x} = \\answer{\\frac{1}{2}} \\text{ and } \\overline{y} = \\answer{\\frac{1}{2}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nCompute the centroid of a thin wire along the graph $y = \\sqrt{1-x^2}$ between $x = 0$ and $x=1$. \n\\begin{hint}\nRecall that \n\\[ M = \\int ds \\]\n\\[ \\overline{x} = \\frac{1}{M} \\int x ds \\]\n\\[ \\overline{y} = \\frac{1}{M} \\int y ds \\]\nwhere $ds$ is the arc length element. We also know that\n\\[ \\int \\frac{dx}{\\sqrt{1-x^2}} = \\arcsin x + C. \\]\n\\end{hint}\n\\[ \\overline{x} = \\answer{\\frac{2}{\\pi}} \\text{ and } \\overline{y} = \\answer{\\frac{2}{\\pi}}. \\]\n\\end{exercise}\n\n\n\\section*{Sample Quiz Questions}\n\\begin{question}%%%%%[CentroidQuad01]\n\nCompute the centroid of the region bounded by the inequalities \\[-2 \\leq x \\leq 0 \\qquad \\text{ and } \\qquad {3x^2-\\frac{13}{2}} \\leq y \\leq {3x^2-\\frac{11}{2}}.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left(-\\frac{3}{2},-3 \\right)\\)}\n\\choice{\\(\\displaystyle \\left(-1,-3 \\right)\\)}\n\\choice{\\(\\displaystyle \\left(-\\frac{1}{2},-3 \\right)\\)}\n\\choice{\\(\\displaystyle \\left(-\\frac{3}{2},-2 \\right)\\)}\n\\choice[correct]{\\(\\displaystyle \\left(-1,-2 \\right)\\)}\n\\choice{\\(\\displaystyle \\left(-\\frac{1}{2},-2 \\right)\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe key calculations are as follows: \n\\[ \\begin{aligned}\nM & = \\int_{-2}^{0} \\left[ \\left({3x^2-\\frac{11}{2}}\\right) - \\left({3x^2-\\frac{13}{2}}\\right) \\right] dx , \\\\\nM_y & = \\int_{-2}^{0} x \\left[ \\left({3x^2-\\frac{11}{2}}\\right) - \\left({3x^2-\\frac{13}{2}}\\right) \\right] dx, \\\\\nM_x & = \\frac{1}{2} \\int_{-2}^{0} \\left[ \\left({3x^2-\\frac{11}{2}}\\right)^2 - \\left({3x^2-\\frac{13}{2}}\\right)^2 \\right] dx.\n\\end{aligned}\\]\n \\begin{hint}\n \\[ \\begin{aligned}\nM & = \\int_{-2}^{0} \\left[ \\left({3x^2-\\frac{11}{2}}\\right) - \\left({3x^2-\\frac{13}{2}}\\right) \\right] dx = \\int_{-2}^{0} \\left[{1}\\right] dx = 2, \\\\\nM_y & = \\int_{-2}^{0} x \\left[ \\left({3x^2-\\frac{11}{2}}\\right) - \\left({3x^2-\\frac{13}{2}}\\right) \\right] dx = \\int_{-2}^{0} x \\left[{1}\\right] dx = -2, \\\\\nM_x & = \\frac{1}{2} \\int_{-2}^{0} \\left[ \\left({3x^2-\\frac{11}{2}}\\right)^2 - \\left({3x^2-\\frac{13}{2}}\\right)^2 \\right] dx = \\int_{-2}^{0} \\left[{3x^2-6}\\right] = -4, \\\\\n \\overline{x} &  = \\frac{M_y}{M} = -1, \\\\\n \\overline{y} &  = \\frac{M_x}{M} = -2.\\end{aligned}\\]\n \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\n\n\n\\begin{question}%%%%%[2015C.12]\n\nFind the \\(y\\)-coordinate of the centroid of the region bounded by the \\(x\\)-axis, the \\(y\\)-axis, and the graph of \\(y = \\cos x\\) for \\(0 \\leq x \\leq \\pi/2\\) if the density is constant.\n\\begin{hint}\nUse the identity \\[ \\cos^2 x  = \\frac{1 + \\cos 2x}{2} \\]\nto calculate the integral of $\\cos^2 x$.\n\\end{hint}\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{\\pi}{18}\\)}\n\\choice{\\(\\displaystyle \\frac{\\pi}{12}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{\\pi}{8}\\)}\n\\choice{\\(\\displaystyle \\frac{\\pi}{6}\\)}\n\\choice{\\(\\displaystyle \\frac{\\pi}{4}\\)}\n\\choice{\\(\\displaystyle \\frac{\\pi}{2}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe area of the region is given by\n\\[ M = \\int_0^{\\frac{\\pi}{2}} \\cos x~dx = 1 \\]\nand \n\\[\\begin{aligned}\n M_x & = \\int_0^{\\frac{\\pi}{2}} \\frac{0 + \\cos x}{2} \\cos x~ dx = \\frac{1}{2} \\int_0^{\\frac{\\pi}{2}} \\cos^2 x ~ dx \\\\\n& \\frac{1}{2} \\int_0^{\\frac{\\pi}{2}} \\frac{1 + \\cos 2x}{2} dx = \\frac{\\pi}{8}. \n\\end{aligned}\\]\nTherefore \\(\\overline{y} = M_x / M = \\pi/8\\).\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.02]\n\nFind the \\(y\\)-coordinate of the centroid of the region in the upper half-plane (i.e., for \\(y > 0\\)) bounded by the semicircle \\(y = \\sqrt{1-x^2}\\). (It is easiest to use a geometric formula to find the area of the region.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{4 \\pi}{3}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{4}{3 \\pi}\\)}\n\\choice{\\(\\displaystyle \\frac{7 \\pi}{3}\\)}\n\\choice{\\(\\displaystyle \\frac{7}{3 \\pi}\\)}\n\\choice{\\(\\displaystyle \\frac{28 \\pi}{9}\\)}\n\\choice{\\(\\displaystyle \\frac{28}{9 \\pi}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\end{document}\n", "meta": {"hexsha": "cc7ccca2f05eb66bf25d445c1de9f44ac68f7a39", "size": 6226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "centroids/07centroidpractice.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": "centroids/07centroidpractice.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": "centroids/07centroidpractice.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": 43.2361111111, "max_line_length": 368, "alphanum_fraction": 0.6256023129, "num_tokens": 2357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914975839675, "lm_q2_score": 0.8740772384450968, "lm_q1q2_score": 0.6598539973427902}}
{"text": "\\chapter{Forcing}\nWe are now going to introduce Paul Cohen's technique of \\vocab{forcing},\nwhich we then use to break the Continuum Hypothesis.\n\nHere is how it works.\nGiven a transitive model $M$ and a poset $\\Po$ inside it,\nwe can consider a ``generic'' subset $G \\subseteq \\Po$, where $G$ is not in $M$.\nThen, we are going to construct a bigger universe $M[G]$ which contains both $M$ and $G$.\n(This notation is deliberately the same as $\\ZZ[\\sqrt2]$, for example -- in the algebra case,\nwe are taking $\\ZZ$ and adding in a new element $\\sqrt 2$, plus everything that can be generated from it.)\nBy choosing $\\Po$ well, we can cause $M[G]$ to have desirable properties.\n\nPicture:\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(14cm);\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\tpair A1 = 0.4*A;\n\t\tpair B1 = 0.4*B;\n\t\tdraw(MP(\"V_\\omega\", A1, dir(0))--B1);\n\t\tdraw(MP(\"V_{\\omega+1} = \\mathcal P(V_\\omega)\", 0.45*A, dir(0))--0.45*B);\n\t\tDrawing(\"\\omega\", 0.45*M, dir(45));\n\n\t\tfilldraw(O--A1--(A1+0.30*M)..(0.85*M)..(B1+0.30*M)--B1--cycle,\n\t\t\topacity(0.3)+lightgreen, heavygreen+1);\n\t\tdraw(O--0.85*M, heavygreen+1);\n\t\tfilldraw(O--(1.3*A1)..(0.85*M)..(1.3*B1)--cycle,\n\t\t\topacity(0.1)+lightred, heavyred+1);\n\n\t\tDrawing(\"\\aleph_1^V\", 0.95*M, dir(0));\n\n\t\tpair F = 0.55*B+0.10*A;\n\t\tDrawing(\"f\", F, dir(90));\n\t\tdraw(F--0.55*M, dotted, EndArrow, Margins);\n\t\tdraw(F--0.45*M, dotted, EndArrow, Margins);\n\n\t\tDrawing(\"\\aleph_1^M\", 0.55*M, dir(45));\n\t\tDrawing(\"\\aleph_1^{M[G]}\", 0.65*M, dir(45));\n\n\t\tdraw(0.85*M--M);\n\t\tMP(\"\\mathrm{On}^V\", M, dir(90));\n\t\tMP(\"\\mathrm{On}^M = \\mathrm{On}^{M[G]}\", 0.85*M, dir(135));\n\n\t\tMP(\"M \\subseteq M[G]\", 0.85*M, 3*dir(0)+dir(45));\n\n\t\tDrawing(\"\\mathbb P\", 0.3*M+0.3*A, dir(135));\n\t\tDrawing(\"G\", 0.55*A+0.1*B, dir(45));\n\t\\end{asy}\n\\end{center}\n\nThe model $M$ is drawn in green, and its extension $M[G]$ is drawn in red.\n\nThe models $M$ and $M[G]$ will share the same ordinals, which is represented here\nas $M$ being no taller than $M[G]$.\nBut one issue with this is that forcing may introduce some new bijections between cardinals of $M$\nthat were not there originally; this leads to the phenomenon called \\vocab{cardinal collapse}:\nquite literally, cardinals in $M$ will no longer be cardinals in $M[G]$, and instead just an ordinal.\nThis is because in the process of adjoining $G$, we may accidentally pick up some bijections which were not in the earlier universe.\nIn the diagram drawn, this is the function $f$ mapping $\\omega$ to $\\aleph_1^M$.\nEssentially, the difficulty is that ``$\\kappa$ is a cardinal'' is a $\\Pi_1$ statement.\n\nIn the case of the Continuum Hypothesis, we'll introduce a $\\Po$ such that\nany generic subset $G$ will ``encode'' $\\aleph_2^M$ real numbers.\nWe'll then show cardinal collapse does not occur, meaning $\\aleph_2^{M[G]} = \\aleph_2^M$.\nThus $M[G]$ will have $\\aleph_2^{M[G]}$ real numbers, as desired.\n\n\\section{Setting up posets}\n\\prototype{Infinite Binary Tree}\nLet $M$ be a transitive model of $\\ZFC$.\nLet $\\Po = (\\Po, \\le) \\in M$ be a poset with a maximal element $1_\\Po$\nwhich lives inside a model $M$.\nThe elements of $\\Po$ are called \\vocab{conditions};\nbecause they will force things to be true in $M[G]$.\n\n\\begin{definition}\n\tA subset $D \\subseteq \\Po$ is \\vocab{dense} if for all $p \\in \\Po$,\n\tthere exists a $q  \\in D$ such that $q \\le p$.\n\\end{definition}\nExamples of dense subsets include the entire $\\Po$ as well\nas any downwards ``slice''.\n\n\\begin{definition}\n\tFor $p,q \\in \\Po$ we write $p \\parallel q$,\n\tsaying ``$p$ is \\vocab{compatible} with $q$'',\n\tif there exists $r \\in \\Po$ with $r \\le p$ and $r \\le q$.\n\tOtherwise, we say $p$ and $q$ are \\vocab{incompatible}\n\tand write $p \\perp q$.\n\\end{definition}\n\\begin{example}[Infinite binary tree]\n\tLet $\\Po = 2^{<\\omega}$ be the \\vocab{infinite binary tree} shown below,\n\textended to infinity in the obvious way:\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(8cm);\n\t\t\tpair P = Drawing(\"\\varnothing\", (0,4), dir(90));\n\t\t\tpair P0 = Drawing(\"0\", (-5,2), 1.5*dir(90));\n\t\t\tpair P1 = Drawing(\"1\", (5,2),  1.5*dir(90));\n\t\t\tpair P00 = Drawing(\"00\", (-7,0), 1.4*dir(120));\n\t\t\tpair P01 = Drawing(\"01\", (-3,0), 1.4*dir(60));\n\t\t\tpair P10 = Drawing(\"10\", (3,0),  1.4*dir(120));\n\t\t\tpair P11 = Drawing(\"11\", (7,0),  1.4*dir(60));\n\n\t\t\tpair P000 = Drawing(\"000\", (-8,-3));\n\t\t\tpair P001 = Drawing(\"001\", (-6,-3));\n\t\t\tpair P010 = Drawing(\"010\", (-4,-3));\n\t\t\tpair P011 = Drawing(\"011\", (-2,-3));\n\n\t\t\tpair P100 = Drawing(\"100\", (2,-3));\n\t\t\tpair P101 = Drawing(\"101\", (4,-3));\n\t\t\tpair P110 = Drawing(\"110\", (6,-3));\n\t\t\tpair P111 = Drawing(\"111\", (8,-3));\n\n\t\t\tlabel(\"$\\vdots$\", (-7,-3), dir(-90));\n\t\t\tlabel(\"$\\vdots$\", (-3,-3), dir(-90));\n\t\t\tlabel(\"$\\vdots$\", (3,-3), dir(-90));\n\t\t\tlabel(\"$\\vdots$\", (7,-3), dir(-90));\n\n\t\t\tdraw(P01--P0--P00);\n\t\t\tdraw(P11--P1--P10);\n\t\t\tdraw(P0--P--P1);\n\t\t\tdraw(P000--P00--P001);\n\t\t\tdraw(P100--P10--P101);\n\t\t\tdraw(P010--P01--P011);\n\t\t\tdraw(P110--P11--P111);\n\t\t\\end{asy}\n\t\\end{center}\n\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The maximal element $1_\\Po$ is the empty string $\\varnothing$.\n\t\t\\ii $D = \\{\\text{all strings ending in $001$}\\}$ is an example of a dense set.\n\t\t\\ii No two elements of $\\Po$ are compatible unless they are comparable.\n\t\\end{enumerate}\n\\end{example}\n\n\nNow, I can specify what it means to be ``generic''.\n\\begin{definition}\n\tA nonempty set $G \\subseteq \\Po$ is a \\vocab{filter} if\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The set $G$ is upwards-closed:\n\t\t$\\forall p \\in G (\\forall q \\ge p) (q \\in G)$.\n\t\t\\ii Any pair of elements in $G$ is compatible.\n\t\\end{enumerate}\n\tWe say $G$ is \\vocab{$M$-generic} if for all $D$ which are \\emph{in the model $M$},\n\tif $D$ is dense then $G \\cap D \\neq \\varnothing$.\n\\end{definition}\n\\begin{ques}\n\tShow that if $G$ is a filter then $1_\\Po \\in G$.\n\\end{ques}\n\\begin{example}[Generic filters on the infinite binary tree]\n\tLet $\\Po = 2^{<\\omega}$.\n\tThe generic filters on $\\Po$ are sets of the form\n\t\\[ \\left\\{ 0,\\; b_1,\\; b_1b_2,\\; b_1b_2b_3,\\; \\dots \\right\\}. \\]\n\tSo every generic filter on $\\Po$ corresponds\n\tto a binary number $b = 0.b_1b_2b_3\\dots$.\n\n\tIt is harder to describe which reals correspond to generic filters,\n\tbut they should really ``look random''.\n\tFor example, the set of strings ending in $011$ is dense,\n\tso one should expect ``$011$'' to appear inside $b$,\n\tand more generally that $b$ should contain every binary string.\n\tSo one would expect the binary expansion of $\\pi-3$ might correspond to a generic,\n\tbut not something like $0.010101\\dots$.\n\tThat's why we call them ``generic''.\n\\end{example}\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\n\\begin{exercise}\n\tVerify that these are every generic filter $2^{<\\omega}$ has the form above.\n\tShow that conversely, a binary number gives a filter, but it need not be generic.\n\\end{exercise}\n\nNotice that if $p \\ge q$, then the sentence $q \\in G$ tells us more information than the sentence $p \\in G$.\nIn that sense $q$ is a \\emph{stronger} condition.\nIn another sense $1_\\Po$ is the weakest possible condition,\nbecause it tells us nothing about $G$; we always have $1_\\Po \\in G$\nsince $G$ is upwards closed.\n\n\\section{More properties of posets}\nWe had better make sure that generic filters exist.\nIn fact this is kind of tricky, but for countable models it works:\n\\begin{lemma}[Rasiowa-Sikorski lemma]\n\tSuppose $M$ is a \\emph{countable} transitive model of $\\ZFC$\n\tand $\\Po$ is a partial order.\n\tThen there exists an $M$-generic filter $G$.\n\\end{lemma}\n\\begin{proof}\n\tEssentially, hit them one by one.\n\t\\Cref{prob:rslemma}.\n\\end{proof}\n\nFortunately, for breaking $\\CH$ we would want $M$ to be countable anyways.\n% This is really just the proof of the Baire category theorem.\n\nThe other thing we want to do to make sure we're on the right track is guarantee\nthat a generic set $G$ is not actually in $M$.\n(Analogy: $\\ZZ[3]$ is a really stupid extension.)\nThe condition that guarantees this is:\n\n\\begin{definition}\n\tA partial order $\\Po$ is \\vocab{splitting} if\n\tfor all $p \\in \\Po$, there exists $q,r \\le p$\n\tsuch that $q \\perp r$.\n\\end{definition}\n\\begin{example}[Infinite binary tree is (very) splitting]\n\tThe infinite binary tree is about as splitting as you can get.\n\tGiven $p \\in 2^{<\\omega}$, just consider the two elements right under it.\n\\end{example}\n\n\\begin{lemma}[Splitting posets omit generic sets]\n\tSuppose $\\Po$ is splitting.  Then if $F \\subseteq \\Po$ is a filter\n\tsuch that $F \\in M$, then $\\Po \\setminus F$ is dense.\n\tIn particular, if $G \\subseteq \\Po$ is generic, then $G \\notin M$.\n\\end{lemma}\n\\begin{proof}\n\tConsider $p \\notin \\Po \\setminus F \\iff p \\in F$.\n\tThen there exists $q, r \\le p$ which are not compatible.\n\tSince $F$ is a filter it cannot contain both;\n\twe must have one of them outside $F$, say $q$.\n\tHence every element of $p \\in \\Po \\setminus (\\Po \\setminus F)$\n\thas an element $q \\le p$ in $\\Po \\setminus F$.\n\tThat's enough to prove $\\Po \\setminus F$ is dense.\n\t\\begin{ques}\n\t\tDeduce the last assertion of the lemma about generic $G$. \\qedhere\n\t\\end{ques}\n\\end{proof}\n\n\\section{Names, and the generic extension}\nWe now define the \\emph{names} associated to a poset $\\Po$.\n\n\\begin{definition}\n\tSuppose $M$ is a transitive model of $\\ZFC$, $\\Po = (\\Po, \\le) \\in M$ is a partial order.\n\tWe define the hierarchy of \\vocab{$\\Po$-names} recursively by\n\t\\begin{align*}\n\t\t\\Name_0 &= \\varnothing \\\\\n\t\t\\Name_{\\alpha+1} &= \\PP(\\Name_\\alpha \\times \\Po) \\\\\n\t\t\\Name_{\\lambda} &= \\bigcup_{\\alpha < \\lambda} \\Name_\\alpha.\n\t\\end{align*}\n\tFinally, $\\Name = \\bigcup_\\alpha \\Name_\\alpha$ denote the class of all $\\Po$-names.\n\t% For $\\tau \\in \\Name$, let $\\nrank(\\tau)$ be the least $\\alpha$ such that $\\tau \\in \\Name_\\alpha$.\n\\end{definition}\n(These $\\Name_\\alpha$'s are the analog of the $V_\\alpha$'s:\neach $\\Name_\\alpha$ is just the set of all names with rank $\\le \\alpha$.)\n\n\\begin{definition}\n\tFor a filter $G$, we define the \\vocab{interpretation} of $\\tau$ by $G$,\n\tdenoted $\\tau^G$, using the transfinite recursion\n\t\\[ \\tau^G\n\t\t= \\left\\{ \\sigma^G\n\t\t\\mid \\left<\\sigma, p\\right> \\in \\tau\n\t\t\\text{ and } p \\in G\\right\\}. \\]\n\tWe then define the model\n\t\\[ M[G] = \\left\\{ \\tau^G \\mid \\tau \\in \\Name^M \\right\\}. \\]\n\tIn words, $M[G]$ is the interpretation of all the possible $\\Po$-names\n\t(as computed by $M$).\n\\end{definition}\n\n\\textbf{You should think of a $\\Po$-name as a ``fuzzy set''.}\nHere's the idea.\nOrdinary sets are collections of ordinary sets,\nso fuzzy sets should be collections of fuzzy sets.\nThese fuzzy sets can be thought of like the Ghosts of Christmases yet to come:\nthey represent things that might be, rather than things that are certain.\nIn other words, they represent the possible futures of $M[G]$ for various choices of $G$.\n\nEvery fuzzy set has an element $p \\in \\Po$ pinned to it.\nWhen it comes time to pass judgment,\nwe pick a generic $G$ and filter through the universe of $\\Po$-names.\nThe fuzzy sets with an element of $G$ attached to it materialize into the real world,\nwhile the fuzzy sets with elements outside of $G$ fade from existence.\nThe result is $M[G]$.\n\n\\begin{example}[First few levels of the name hierarchy]\n\tLet us compute\n\t\\begin{align*}\n\t\t\\Name_0 &= \\varnothing \\\\\n\t\t\\Name_1 &= \\PP(\\varnothing \\times \\Po) \\\\\n\t\t&= \\{\\varnothing\\} \\\\\n\t\t\\Name_2 &= \\PP(\\{\\varnothing\\} \\times \\Po) \\\\\n\t\t&= \\PP\\left( \\left\\{ \n\t\t\t\\left<\\varnothing, p\\right>\n\t\t\t\\mid p \\in \\Po\n\t\t\\right\\} \\right).\n\t\\end{align*}\n\\end{example}\nCompare the corresponding von Neuman universe.\n\\[ V_0 = \\varnothing, \\; V_1 = \\{\\varnothing\\}, \\;\nV_2 = \\left\\{ \\varnothing, \\left\\{ \\varnothing \\right\\} \\right\\}. \\]\n\n\\begin{example}[Example of an interpretation]\n\tAs we said earlier, $\\Name_1 = \\{\\varnothing\\}$.\n\tNow suppose\n\t\\[ \\tau =\n\t\t\\left\\{\n\t\t\t\\left<\\varnothing, p_1\\right>,\n\t\t\t\\left<\\varnothing, p_2\\right>,\n\t\t\t\\dots,\n\t\t\t\\left<\\varnothing, p_n\\right>\n\t\t\\right\\} \n\t\t\\in \\Name_2. \\]\n\tThen \n\t\\[\n\t\t\\tau^G\n\t\t= \\left\\{ \\varnothing \\mid\n\t\t\\left<\\varnothing, p\\right> \\in \\tau \\text{ and } p \\in G\\right\\}\n\t\t=\n\t\t\\begin{cases}\n\t\t\t\\{\\varnothing\\} & \\text{if some } p_i \\in G \\\\\n\t\t\t\\varnothing & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\tIn particular, remembering that $G$ is nonempty we see that\n\t\\[ \\left\\{ \\tau^G \\mid \\tau \\in \\Name_2 \\right\\} = V_2. \\]\n\tIn fact, this holds for any natural number $n$, not just $2$.\n\\end{example}\nSo, $M[G]$ and $M$ agree on finite sets.\n\nNow, we want to make sure $M[G]$ contains the elements of $M$.\nTo do this, we take advantage of the fact that $1_\\Po$ must be in $G$, and define\nfor every $x \\in M$ the set\n\\[ \\check x = \\left\\{ \\left<\\check y, 1_\\Po\\right> \\mid y \\in x \\right\\} \\]\nby transfinite recursion.\nBasically, $\\check x$ is just a copy of $x$ where we add check marks and tag every element with $1_\\Po$.\n\n\\begin{example}\n\tCompute $\\check 0 = 0$ and $\\check 1 = \\left\\{ \\left<\\check 0, 1_\\Po\\right> \\right\\}$.\n\tThus \\[ (\\check 0)^G = 0 \\quad\\text{and}\\quad (\\check 1)^G = 1. \\]\n\\end{example}\n\\begin{ques}\n\tShow that in general, $(\\check x)^G = x$.\n\t(Rank induction.)\n\\end{ques}\n\nHowever, we'd also like to cause $G$ to be in $M[G]$.\nIn fact, we can write down the name exactly: we define\n\\[ \\dot \\Po \\defeq \\left\\{ \\left<\\check p, p\\right> \\mid p \\in \\Po \\right\\}. \\]\n\\begin{ques}\n\tShow that $(\\dot \\Po)^G = G$.\n\\end{ques}\n\\begin{ques}\n\tVerify that $M[G]$ is transitive:\n\tthat is, if $\\sigma^G \\in \\tau^G \\in M[G]$, show that $\\sigma^G \\in M[G]$.\n\t(This is offensively easy.)\n\\end{ques}\n\nIn summary,\n\\begin{moral}\n\t$M[G]$ is a transitive model extending $M$ (it contains $G$).\n\\end{moral}\n\nMoreover, it is reasonably well-behaved even if $G$ is just a filter.\nLet's see what we can get off the bat.\n\\begin{lemma}[Properties obtained from filters]\n\tLet $M$ be a transitive model of $\\ZFC$.\n\tIf $G$ is a filter, then $M[G]$ is transitive\n\tand satisfies $\\Extensionality$, $\\Foundation$, \n\t$\\EmptySet$, $\\Infinity$, $\\Pairing$, and $\\Union$.\n\\end{lemma}\n\nThis leaves $\\PowerSet$, $\\Replacement$, and Choice.\n\\begin{proof}\n\tHence, we get $\\Extensionality$ and $\\Foundation$ for free.\n\tThen $\\Infinity$ and $\\EmptySet$ follows from $M \\subseteq M[G]$.\n\n\tFor $\\Pairing$, suppose $\\sigma_1^G, \\sigma_2^G \\in M[G]$.\n\tThen\n\t\\[ \\sigma = \n\t\t\\left\\{ \\left<\\sigma_1, 1_\\Po\\right>, \\left<\\sigma_2, 1_\\Po\\right> \\right\\}\n\t\\]\n\tsatisfies $\\sigma^G = \\{\\sigma_1^G, \\sigma_2^G\\}$.\n\t(Note that we used $M \\vDash \\Pairing$.)\n\t$\\Union$ is left as a problem, which you are encouraged to try now.\n\\end{proof}\nUp to here, we don't need to know anything about when a sentence is true in $M[G]$;\nall we had to do was contrive some names like $\\check x$ or\n$\\left\\{ \\left<\\sigma_1, 1_\\Po\\right>, \\left<\\sigma_2, 1_\\Po\\right> \\right\\}$\nto get the facts we wanted.\nBut for the remaining axioms, we \\emph{are} going to need this extra power\nare true in $M[G]$.\nFor this, we have to introduce the fundamental theorem of forcing.\n\n\\section{Fundamental theorem of forcing}\nThe model $M$ unfortunately has no idea what $G$ might be,\nonly that it is some generic filter.\\footnote{You might\n\tsay this is a good thing; here's why.\n\tWe're trying to show that $\\neg \\CH$ is consistent with $\\ZFC$,\n\tand we've started with a model $M$ of the real universe $V$.\n\tBut for all we know $\\CH$ might be true in $V$ (what if $V=L$?),\n\tin which case it would also be true of $M$.\n\n\tNonetheless, we boldly construct $M[G]$ an extension of the model $M$.\n\tIn order for it to behave differently from $M$, it has to be out of reach of $M$.\n\tConversely, if $M$ could compute everything about $M[G]$,\n\tthen $M[G]$ would have to conform to $M$'s beliefs.\n\n\tThat's why we worked so hard to make sure $G \\in M[G]$ but $G \\notin M$.}\nNonetheless, we are going to define a relation $\\Vdash$,\ncalled the \\emph{forcing} relation.\nRoughly, we are going to write\n\\[ p \\Vdash \\varphi(\\sigma_1, \\dots, \\sigma_n) \\]\nwhere $p \\in \\Po$, $\\sigma_1, \\dots, \\sigma_n \\in M[G]$, if and only if:\n\\begin{quote}\n\tFor \\emph{any} generic $G$,\n\tif $p \\in G$,\n\tthen $M[G] \\vDash \\varphi(\\sigma_1^G, \\dots, \\sigma_n^G)$.\n\\end{quote}\nNote that $\\Vdash$ is defined without reference to $G$:\nit is something that $M$ can see.\nWe say $p$ \\vocab{forces} the sentence $\\varphi(\\sigma_1, \\dots, \\sigma_n)$.\nAnd miraculously, we can define this relation in such a way that the converse is true:\n\\emph{a sentence holds if and only if some $p$ forces it}.\n\n\n\\begin{theorem}\n\t[Fundamental theorem of forcing]\n\tSuppose $M$ is a transitive model of ZF.\n\tLet $\\Po \\in M$ be a poset, and $G \\subseteq \\Po$ is an $M$-generic filter.\n\tThen,\n\t\\begin{enumerate}[(1)]\n\t\t\\ii Consider $\\sigma_1, \\dots, \\sigma_n \\in \\Name^M$,\n\t\tThen\n\t\t\\[ M[G] \\vDash \\varphi[\\sigma_1^G, \\dots, \\sigma_n^G] \\]\n\t\tif and only if there exists a condition $p \\in G$\n\t\tsuch that $p$ \\emph{forces} the sentence $\\varphi(\\sigma_1, \\dots, \\sigma_n)$.\n\t\tWe denote this by $p \\Vdash \\varphi(\\sigma_1, \\dots, \\sigma_n)$.\n\t\t\\ii This forcing relation is (uniformly) definable in $M$.\n\t\\end{enumerate}\n\\end{theorem}\n\nI'll tell you how the definition works in the next section.\n\n\\section{(Optional) Defining the relation}\nHere's how we're going to go.\nWe'll define the most generous condition possible such that\nthe forcing works in one direction ($p \\Vdash \\varphi(\\sigma_1, \\dots, \\sigma_n)$ means\n$M[G] \\vDash \\varphi[\\sigma_1^G, \\dots, \\sigma_n^G]$).\nWe will then cross our fingers that the converse also works.\n\nWe proceed by induction on the formula complexity.\nIt turns out in this case that the atomic formula (base cases)\nare hardest and themselves require induction on ranks.\n\nFor some motivation, let's consider how we should define\n$p \\Vdash \\tau_1 \\in \\tau_2$ given that we've\nalready defined $p \\Vdash \\tau_1 = \\tau_2$.\nWe need to ensure this holds iff\n\\[ \\forall \\text{$M$-generic $G$ with $p \\in G$}:\n\t\\ M[G] \\vDash \\tau_1^G \\in \\tau_2^G. \\]\nSo it suffices to ensure that any generic $G \\ni p$ hits a condition $q$ which forces $\\tau_1^G$ to \\emph{equal} a member $\\tau^G$ of $\\tau_2^G$.\nIn other words, we want to choose the definition of $p \\Vdash \\tau_1 \\in \\tau_2$ to hold if and only if\n\\[\n\t\\left\\{ q \\in \\Po\n\t\t\\mid \\exists \\left<\\tau, r\\right> \\in \\tau_2\n\t\t\\left( q \\le r \\land q \\Vdash(\\tau=\\tau_1) \\right) \\right\\}\n\\]\nis dense below in $p$.\nIn other words, if the set is dense, then the generic must hit $q$, so it must hit $r$, meaning that $\\left<\\tau_r\\right> \\in \\tau_2$ will get interpreted such that $\\tau^G \\in \\tau_2^G$, and moreover the $q \\in G$ will force $\\tau_1 = \\tau$.\n\nNow let's write down the definition\\dots\nIn what follows, the $\\Vdash$ omits the $M$ and $\\Po$.\n\\begin{definition}\n\tLet $M$ be a countable transitive model of ZFC.\n\tLet $\\Po \\in M$ be a partial order.\n\tFor $p \\in \\Po$ and $\\varphi(\\sigma_1, \\dots, \\sigma_n)$\n\ta formula in the language of set theory,\n\twe write $\\tau \\Vdash \\varphi(\\sigma_1, \\dots, \\sigma_n)$\n\tto mean the following, defined by induction on formula complexity plus rank.\n\t\\begin{enumerate}[(1)]\n\t\t\\ii $p \\Vdash \\tau_1 = \\tau_2$ means\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\ii For all $\\left<\\sigma_1, q_1\\right> \\in \\tau_1$ the set\n\t\t\t\\[ D_{\\sigma_1, q_1}\n\t\t\t\t\\defeq\n\t\t\t\t\\left\\{ r \\mid\n\t\t\t\tr \\le q_1 \\lthen \\exists \\left<\\sigma_2, q_2\\right> \\in \\tau_2 \\left( r \\le q_2 \\land r \\Vdash (\\sigma_1 = \\sigma_2) \\right)\\right\\}.\n\t\t\t\\]\n\t\t\tis dense in $p$.\n\t\t\t(This encodes ``$\\tau_1 \\subseteq \\tau_2$''.)\n\t\t\t\\ii For all $\\left<\\sigma_2, q_2\\right> \\in \\tau_2$,\n\t\t\tthe set $D_{\\sigma_2, q_2}$ defined similarly is dense below $p$.\n\t\t\\end{enumerate}\n\t\t\\ii $p \\Vdash \\tau_1 \\in \\tau_2$ means\n\t\t\\[\n\t\t\\left\\{ q \\in \\Po\n\t\t\\mid \\exists \\left<\\tau, r\\right> \\in \\tau_2 \n\t\t\\left( q \\le r \\land q \\Vdash(\\tau=\\tau_1) \\right)\n\t\t\\right\\} \\]\n\t\tis dense below $p$.\n\t\t\\ii $p \\Vdash \\varphi \\land \\psi$ means $p \\Vdash \\varphi$ and $p \\Vdash \\psi$.\n\t\t\\ii $p \\Vdash \\neg \\varphi$ means $\\forall q \\le p$, $q \\not\\Vdash \\varphi$.\n\t\t\\ii $p \\Vdash \\exists x \\varphi(x, \\sigma_1, \\dots, \\sigma_n)$ means that the set\n\t\t\\[\n\t\t\t\\left\\{ q \\mid \\exists \\tau \\left( q \\Vdash\n\t\t\t\t\\varphi(\\tau, \\sigma_1, \\dots, \\sigma_n ) \\right)\n\t\t\t\\right\\}\n\t\t\\]\n\t\tis dense below $p$.\n\t\\end{enumerate}\n\\end{definition}\nThis is definable in $M$!\nAll we've referred to is $\\Po$ and names, which are in $M$.\n(Note that being dense is definable.)\nActually, in parts (3) through (5) of the definition above,\nwe use induction on formula complexity.\nBut in the atomic cases (1) and (2) we are doing induction on the ranks of the names.\n\nSo, the construction above gives us one direction (I've omitted tons of details, but\\dots).\n\nNow, how do we get the converse: that a sentence is true if and only if something forces it?\nWell, by induction, we can actually show:\n\\begin{lemma}[Consistency and Persistence]\n\tWe have\n\t\\begin{enumerate}[(1)]\n\t\t\\ii (Consistency) If $p \\Vdash \\varphi$ and $q \\le p$ then $q \\Vdash \\varphi$.\n\t\t\\ii (Persistence) If $\\left\\{ q \\mid q \\Vdash \\varphi \\right\\}$\n\t\tis dense below $p$ then $p \\Vdash \\varphi$.\n\t\\end{enumerate}\n\\end{lemma}\nYou can prove both of these by induction on formula complexity.\nFrom this we get:\n\\begin{corollary}[Completeness]\n\tThe set $\\left\\{ p \\mid p \\Vdash \\varphi \\text{ or } p \\Vdash \\neg\\varphi \\right\\}$\n\tis dense.\n\\end{corollary}\n\\begin{proof}\n\tWe claim that whenever $p \\not\\Vdash \\varphi$ then\n\tfor some $\\ol p \\le p$ we have $\\ol p \\Vdash \\neg\\varphi$;\n\tthis will establish the corollary.\n\n\tBy the contrapositive of the previous lemma,\n\t$\\{q \\mid q \\Vdash \\varphi\\}$ is not dense below $p$,\n\tmeaning for some $\\ol p \\le p$, every $q \\le \\ol p$ gives $q \\not\\Vdash \\varphi$.\n\tBy the definition of $p \\Vdash \\neg\\varphi$,\n\twe have $\\ol p \\Vdash \\neg\\varphi$.\n\\end{proof}\nAnd this gives the converse: the $M$-generic $G$ has to hit some condition\nthat passes judgment, one way or the other.\nThis completes the proof of the fundamental theorem.\n\n\\section{The remaining axioms}\n\\begin{theorem}[The generic extension satisfies $\\ZFC$]\n\tSuppose $M$ is a transitive model of $\\ZFC$.\n\tLet $\\Po \\in M$ be a poset, and $G \\subseteq \\Po$ is an $M$-generic filter.\n\tThen \\[ M[G] \\vDash \\ZFC. \\]\n\\end{theorem}\n\\begin{proof}\n\tWe'll just do $\\Comprehension$, as the other remaining axioms are similar.\n\t\n\tSuppose $\\sigma^G, \\sigma_1^G, \\dots, \\sigma_n^G \\in M[G]$\n\tare a set and parameters, and\n\t$\\varphi(x,x_1, \\dots, x_n)$ is a formula\n\tin the language of set theory.\n\tWe want to show that the set\n\t\\[ A = \\left\\{ \n\t\tx \\in \\sigma^G \\mid M[G] \\vDash \\varphi[x, \\sigma_1^G, \\dots, \\sigma_n^G]\n\t\\right\\} \\]\n\tis in $M[G]$; i.e.\\ it is the interpretation of some name.\n\n\tNote that every element of $\\sigma^G$ is of the form $\\rho^G$\n\tfor some $\\rho \\in \\dom(\\sigma)$ (a bit of abuse of notation here,\n\t$\\sigma$ is a bunch of pairs of names and $p$'s,\n\tand the domain $\\dom(\\sigma)$ is just the set of names).\n\tSo by the fundamental theorem of forcing, we may write\n\t\\[ A = \n\t\t\\left\\{ \\rho^G \\mid \\rho \\in \\dom(\\sigma)\n\t\t\t\\text{ and }\n\t\t\t\\exists p \\in G\n\t\t\t\\left( p \\Vdash \\rho \\in \\sigma\n\t\t\t\\land \\varphi(\\rho, \\sigma_1, \\dots, \\sigma_n)\n\t\t\t\\right)\n\t\t\\right\\}.\n\t\\]\n\tTo show $A \\in M[G]$ we have to write down a $\\tau$\n\tsuch that the name $\\tau^G$ coincides with $A$.\n\tWe claim that\n\t\\[\n\t\t\\tau\n\t\t=\n\t\t\\left\\{ \\left<\\rho, p\\right>\n\t\t\t\\in \\dom(\\sigma) \\times \\Po \\mid\n\t\t\tp \\Vdash \\rho \\in \\sigma\n\t\t\t\\land \\varphi(\\rho, \\sigma_1, \\dots, \\sigma_n)\n\t\t\\right\\}\n\t\\]\n\tis the correct choice.\n\tIt's actually clear that $\\tau^G = A$ by construction;\n\tthe ``content'' is showing that $\\tau$ is in actually a name of $M$,\n\twhich follows from $M \\vDash \\Comprehension$.\n\n\tSo really, the point of the fundamental theorem of forcing\n\tis just to let us write down this $\\tau$;\n\tit lets us show that $\\tau$ is in $\\Name^M$\n\twithout actually referencing $G$.\n\\end{proof}\n\n\n\\section\\problemhead\n\\begin{problem}\n\tFor a filter $G$ and $M$ a transitive model of $\\ZFC$,\n\tshow that $M[G] \\vDash \\Union$.\n\\end{problem}\n\n\\begin{problem}[Rasiowa-Sikorski lemma]\n\t\\label{prob:rslemma}\n\tShow that in a countable transitive model $M$ of $\\ZFC$,\n\tone can find an $M$-generic filter on any partial order.\n\t\\begin{hint}\n\t\tLet $D_1$, $D_2$, \\dots be the dense sets (there are countably many of them).\n\t\\end{hint}\n\t\\begin{sol}\n\tSince $M$ is countable, there are only countably many dense sets (they live in $M$!),\n\tsay \\[ D_1, D_2, \\ldots, D_n, \\ldots \\in M. \\]\n\tUsing Choice,\n\tlet $p_1 \\in D_1$, and then let $p_2 \\le p_1$ such that $p_2 \\in D_2$\n\t(this is possible since $D_2$ is dense), and so on.\n\tIn this way we can inductively exhibit a chain\n\t\\[ p_1 \\ge p_2 \\ge p_3 \\ge \\dots \\]\n\twith $p_i \\in D_i$ for every $i$.\n\n\tHence, we want to generate a filter from the $\\{p_i\\}$.\n\tJust take the upwards closure -- let $G$ be the set of $q \\in \\Po$ such that $q \\ge p_n$ for some $n$.\n\tBy construction, $G$ is a filter (this is actually trivial).\n\tMoreover, $G$ intersects all the dense sets by construction.\n\t\\end{sol}\n\\end{problem}\n\n%\\begin{exercise}\n%\tShow that $\\rank \\sigma^G \\le \\nrank(\\sigma)$ for any $\\sigma \\in \\Name^M$.\n%\\end{exercise}\n\n%\\begin{exercise}\n%\tCheck that\n%\t\\begin{enumerate}[(1)]\n%\t\t\\ii $(\\check x)^G = x$.\n%\t\t\\ii $(\\dot G)^G = G$.\n%\t\\end{enumerate}\n%\\end{exercise}\n", "meta": {"hexsha": "347ec103b6af0d9e22144d97bc93f6ee14a9c2d7", "size": 26078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/set-theory/forcing.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/forcing.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/forcing.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.1257309942, "max_line_length": 242, "alphanum_fraction": 0.6584093872, "num_tokens": 9118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825006, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.6598291052916564}}
{"text": "\\chapter{Context methods I}\n\nContext methods are a group of methods of compression which exploits the different probablities of symbols based on the preceeding characters - the context. Each of these methods usually works in a completely different manner, but the basis idea about context is common to all of them.\n\n\\section{Entrophy of higher order}\n\nEntrophy of higher order is closely related to context methods. Order is length of the context preceeding the character. When is order $0$ it means that the context is empty and it is just and ordinary entrophy.\n\n\\begin{dt}{Entrophy of $0$ order, $T = \\Sigma^+$.}\n  The entrophy of $0$ order is defined $$H_{0}(T) = - \\sum_{a \\in \\Sigma} \\frac{|T_a|}{n} \\log_2 \\frac{|T_a|}{n}.$$\n\\end{dt}\n\n\\begin{dt}{Entrophy of $k$ order, $k > 0$.}\n  The entrophy of $k$ order is defined $$H_{k}(T) = \\frac{1}{n} \\sum_{w \\in \\Sigma^k} |w_T| H_0(w_T).$$\n\\end{dt}\n\n\\begin{figure}\n    $$H_{0}(\\text{aabaabaaabaaabaa}) = - (\\frac{12}{16} \\log_2 \\frac{12}{16} + \\frac{4}{16} \\log_2 \\frac{4}{16})$$\n  \\caption{$H_{0}(\\text{aabaabaaabaaabaa})$}\n\\end{figure}\n\n\\begin{figure}\n  \\begin{center}\n  \\begin{tabular}{c|c|c}\n    $w$ & $w_T$ & $|w_T|$ \\\\\n    \\hline\n    a & ababaabaaba & 11 \\\\\n    b & aaaa & 4 \\\\\n  \\end{tabular}\n  \\end{center}\n    $$H_{1}(\\text{aabaabaaabaaabaa}) = \\frac{1}{16} (11 H_{0}(\\text{ababaabaaba}) + 4 H_{0}(\\text{aaaa}))$$\n  \\caption{$H_{1}(\\text{aabaabaaabaaabaa})$}\n\\end{figure}\n\n\\begin{figure}\n  \\begin{center}\n  \\begin{tabular}{c|c|c}\n    $w$ & $w_T$ & $|w_T|$ \\\\\n    \\hline\n    aa & bbabab & 5 \\\\\n    ab & aaaa & 4 \\\\\n    ba & aaaa & 4 \\\\\n    bb & $\\varepsilon$ & 0 \\\\\n  \\end{tabular}\n  \\end{center}\n    $$H_{2}(\\text{aabaabaaabaaabaa}) = \\frac{1}{16} (5 H_{0}(\\text{bbabab}) + 4 H_{0}(\\text{aaaa}) + 4 H_{0}(\\text{aaaa}))$$\n  \\caption{$H_{2}(\\text{aabaabaaabaaabaa})$}\n\\end{figure}\n\n\\begin{figure}\n  \\begin{center}\n  \\begin{tabular}{c|c|c}\n    $w$ & $w_T$ & $|w_T|$ \\\\\n    \\hline\n    aaa & bb & 2 \\\\\n    aab & aaaa & 4 \\\\\n    aba & aaaa & 4 \\\\\n    abb & $\\varepsilon$ & 0 \\\\\n    baa & baa & 3 \\\\\n    bab & $\\varepsilon$ & 0 \\\\\n    bba & $\\varepsilon$ & 0 \\\\\n    bbb & $\\varepsilon$ & 0 \\\\\n  \\end{tabular}\n  \\end{center}\n    $$H_{3}(\\text{aabaabaaabaaabaa}) = \\frac{1}{16} (2 H_{0}(\\text{bb}) + 4 H_{0}(\\text{aaaa}) + 4 H_{0}(\\text{aaaa}) + 3 H_{0}(\\text{baa}))$$\n  \\caption{$H_{3}(\\text{aabaabaaabaaabaa})$}\n\\end{figure}\n\n\\begin{figure}\n  \\begin{center}\n  \\begin{tabular}{c|c|c}\n    $w$ & $w_T$ & $|w_T|$ \\\\\n    \\hline\n    aaaa & $\\varepsilon$ & 0 \\\\\n    aaab & aa & 2 \\\\\n    aaba & aaaa & 4 \\\\\n    aabb & $\\varepsilon$ & 0 \\\\\n    abaa & baa & 3 \\\\\n    abab & $\\varepsilon$ & 0 \\\\\n    abba & $\\varepsilon$ & 0 \\\\\n    abbb & $\\varepsilon$ & 0 \\\\\n    baaa & bb & 2 \\\\\n    baab & a & 1 \\\\\n    baba & $\\varepsilon$ & 0 \\\\\n    babb & $\\varepsilon$ & 0 \\\\\n    bbaa & $\\varepsilon$ & 0 \\\\\n    bbab & $\\varepsilon$ & 0 \\\\\n    bbba & $\\varepsilon$ & 0 \\\\\n    bbbb & $\\varepsilon$ & 0 \\\\\n  \\end{tabular}\n  \\end{center}\n    $$H_{4}(\\text{aabaabaaabaaabaa}) = \\frac{1}{16} (2 H_{0}(\\text{aa}) + 4 H_{0}(\\text{aaaa}) + 3 H_{0}(\\text{baa}) + 2 H_{0}(\\text{bb}) + 1 H_{0}(\\text{a}))$$\n  \\caption{$H_{4}(\\text{aabaabaaabaaabaa})$}\n\\end{figure}\n\n\\section{PPM}\n\n", "meta": {"hexsha": "ca0c945da93e3554e5d8fef0eec8647b50c9da05", "size": 3200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kod/ch6.tex", "max_stars_repo_name": "exander77/handouts", "max_stars_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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": "kod/ch6.tex", "max_issues_repo_name": "exander77/handouts", "max_issues_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "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": "kod/ch6.tex", "max_forks_repo_name": "exander77/handouts", "max_forks_repo_head_hexsha": "c30e8f1128bc71ea69c7a83daaf8915b6a8eff36", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6530612245, "max_line_length": 285, "alphanum_fraction": 0.5703125, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924674, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6598290938274355}}
{"text": "\\hypertarget{delaunay}{%\n\\section{Delaunay}\\label{delaunay}}\n\nThe \\texttt{delaunay} module creates Delaunay triangulations from point\nclouds. It is dimensionally independent, so generates tetrahedra in 3D\nand higher order simplices beyond.\n\nTo use the module, first import it:\n\n\\begin{lstlisting}\nimport delaunay\n\\end{lstlisting}\n\nTo create a Delaunary triangulation from a list of points:\n\n\\begin{lstlisting}\nvar pts = []\nfor (i in 0...100) pts.append(Matrix([random(), random()]))\nvar del=Delaunay(pts)\nprint del.triangulate()\n\\end{lstlisting}\n\nThe module also provides \\texttt{DelaunayMesh} to directly create meshes\nfrom Delaunay triangulations.\n\n\\hypertarget{triangulate}{%\n\\section{Triangulate}\\label{triangulate}}\n\nThe \\texttt{triangulate} method performs the delaunay triangulation. To\nuse it, first construct a \\texttt{Delaunay} object with the point cloud\nof interest:\n\n\\begin{lstlisting}\nvar del=Delaunay(pts)\n\\end{lstlisting}\n\nThen call \\texttt{triangulate}:\n\n\\begin{lstlisting}\nvar tri = del.triangulate()\n\\end{lstlisting}\n\nThis returns a list of triangles\n\\texttt{{[}\\ {[}i,\\ j,\\ k{]},\\ ...\\ {]}}.\n\n\\hypertarget{delaunaymesh}{%\n\\section{DelaunayMesh}\\label{delaunaymesh}}\n\nThe \\texttt{DelaunayMesh} constructor function creates a \\texttt{Mesh}\nobject directly from a point cloud using the Delaunay triangulator.\n\n\\begin{lstlisting}\nvar pts = []\nfor (i in 0...100) pts.append(Matrix([random(), random()]))\nvar m=DelaunayMesh(pts)\nShow(plotmesh(m))\n\\end{lstlisting}\n\nYou can control the output dimension of the mesh (e.g.~to create a 2D\nmesh embedded in 3D space) using the optional \\texttt{outputdim}\nproperty.\n\n\\begin{lstlisting}\nvar m = DelaunayMesh(pts, outputdim=3)\n\\end{lstlisting}\n\n\\hypertarget{circumsphere}{%\n\\section{Circumsphere}\\label{circumsphere}}\n\nThe \\texttt{Circumsphere} class calculates the circumsphere of a set of\npoints, i.e.~a sphere such that all the points are on the surface of the\nsphere. It is used internally by the \\texttt{delaunay} module.\n\nCreate a \\texttt{Circumsphere} from a list of points and a triangle\nspecified by indices into that list:\n\n\\begin{lstlisting}\nvar sph = Circumsphere(pts, [i,j,k]) \n\\end{lstlisting}\n\nTest if an arbitrary point is inside the \\texttt{Circumsphere} or not:\n\n\\begin{lstlisting}\nprint sph.pointinsphere(pt)\n\\end{lstlisting}\n", "meta": {"hexsha": "1325f7ba4aca55d94607ec2f46470603766f27b2", "size": 2301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/src/Reference/delaunay.tex", "max_stars_repo_name": "mattsep/morpho", "max_stars_repo_head_hexsha": "50bb935653c0675b81e9f2d78573cf117971a147", "max_stars_repo_licenses": ["MIT"], "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/src/Reference/delaunay.tex", "max_issues_repo_name": "mattsep/morpho", "max_issues_repo_head_hexsha": "50bb935653c0675b81e9f2d78573cf117971a147", "max_issues_repo_licenses": ["MIT"], "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/src/Reference/delaunay.tex", "max_forks_repo_name": "mattsep/morpho", "max_forks_repo_head_hexsha": "50bb935653c0675b81e9f2d78573cf117971a147", "max_forks_repo_licenses": ["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.7558139535, "max_line_length": 72, "alphanum_fraction": 0.7631464581, "num_tokens": 693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6598290907979798}}
{"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*{4.3.1}\nIndividuals filing federal income tax returns prior to March 31 received an average refund of \\$1056. Consider the population of “last-minute” filers who mail their tax return during the last five days of the income tax period (typically April 10 to April 15).\n\\begin{enumerate}\n  \\item A researcher suggests that a reason individuals wait until the last five days is that on average these individuals receive lower refunds than do early filers. Develop appropriate hypotheses such that rejection of $H_{0}$ will support the researcher’s contention.\n  \\begin{align*}\n    \\text{Average of people that fill last days} &= \\mu_{l}\\\\\n    H_{0} &= \\mu \\leq \\mu_{l}\\\\\n    H_{\\alpha} &= \\mu > \\mu_{l}\\\\\n  \\end{align*}\n\n  \\item For a sample of 400 individuals who filed a tax return between April 10 and 15, the sample mean refund was \\$910. Based on prior experience a population standard deviation of $\\sigma$ \\$1600 may be assumed. What is the $p$-value?\n  \\begin{align*}\n    \\sigma &= 1600\\\\\n    \\mu &= 1056\\\\\n    \\bar{x} &= 910\\\\\n    n &= 400\\\\\n    \\sigma_{\\bar{x}} &= \\frac{\\sigma}{\\sqrt{n}}\\\\\n    \\sigma_{\\bar{x}} &= \\frac{1600}{\\sqrt{400}}\\\\\n    \\sigma_{\\bar{x}} &= 80\\\\\n    z &= \\frac{\\bar{x} - \\mu}{\\sigma_{\\bar{x}}}\\\\\n    z &= \\frac{910 - 1056}{80}\\\\\n    z &= -1.825\\\\\n    p-value &= 0.0340005\n  \\end{align*}\n\n  \\item At $\\alpha =.05$, what is your conclusion?\n\n  As the p-value is less than $\\alpha$, we can reject $H_{0}$, which means that $H_{\\alpha}$ is true, which means that the individuals who mail the tax return in the last 5 days truly receive less than the ones who send them earlier\n\n  \\item Repeat the preceding hypothesis test using the critical value approach.\n\n  \\begin{align*}\n    z &= -1.825\\\\\n    \\text{critical value} (z_{0}) &= -1.64485\n  \\end{align*}\n  As $z < z_{0}$ we reject the null hypothesis\n\n\\end{enumerate}\n\\pagebreak\n\n\\section*{4.3.2}\nIn a study entitled How Undergraduate Students Use Credit Cards, it was reported that undergraduate students have a mean credit card balance of \\$3173 (Sallie Mae, April 2009). This figure was an all-time high and had increased 44\\% over the previous five years. Assume that a current study is being conducted to determine if it can be concluded that the mean credit card balance for undergraduate students has continued to increase compared to the April 2009 report. Based on previous studies, use a population standard deviation $\\sigma =\\$1000$.\n\\begin{enumerate}\n  \\item State the null and alternative hypotheses.\n  \\begin{align*}\n    \\text{Updated CC balance} &= \\mu_{c}\\\\\n    H_{0} &= \\mu \\geq \\mu_{c}\\\\\n    H_{\\alpha} &= \\mu < \\mu_{c}\\\\\n  \\end{align*}\n\n  \\item What is the $p$-value for a sample of 180 undergraduate students with a sample mean credit card balance of \\$3325?\n  \\begin{align*}\n    \\sigma &= 1000\\\\\n    \\mu &= 3173\\\\\n    \\bar{x} &= 3325\\\\\n    n &= 180\\\\\n    \\sigma_{\\bar{x}} &= \\frac{\\sigma}{\\sqrt{n}}\\\\\n    \\sigma_{\\bar{x}} &= \\frac{1000}{\\sqrt{180}}\\\\\n    \\sigma_{\\bar{x}} &= 74.53559924999\\\\\n    z &= \\frac{\\bar{x} - \\mu}{\\sigma_{\\bar{x}}}\\\\\n    z &= \\frac{3325 - 3173}{74.53559924999}\\\\\n    z &= 2.03929399547981\\\\\n    p-value &= 0.020710347281277\n  \\end{align*}\n\n  \\item Using a .05 level of significance, what is your conclusion?\n\n  As the $p$-value is smaller than .05, we can reject the null hypothesis, meaning that the credit card balance for undergraute students has continued rising\n\n\\end{enumerate}\n\\pagebreak\n\n\\section*{4.3.3}\nConsider the following hypothesis test:\n\\begin{align*}\n  H_{0}: \\mu \\leq 25\\\\\n  H_{\\alpha}: \\mu > 25\\\\\n\\end{align*}\nA sample of 40 provided a sample mean of 26.4. The population standard deviation is 6.\n\\begin{enumerate}\n  \\item Compute the value of the test statistic.\n\n  \\begin{align*}\n    \\sigma &= 6\\\\\n    \\mu &= 25\\\\\n    \\bar{x} &= 26.4\\\\\n    n &= 40\\\\\n    \\sigma_{\\bar{x}} &= \\frac{\\sigma}{\\sqrt{n}}\\\\\n    \\sigma_{\\bar{x}} &= \\frac{6}{\\sqrt{40}}\\\\\n    \\sigma_{\\bar{x}} &= 0.9486832980505\\\\\n    z &= \\frac{\\bar{x} - \\mu}{\\sigma_{\\bar{x}}}\\\\\n    z &= \\frac{26.4 - 25}{0.9486832980505}\\\\\n    z &= -1.47572957474524\\\\\n  \\end{align*}\n\n  \\item What is the $p$-value?\n  \\begin{align}\n    p-value &= 0.070008251598585\n  \\end{align}\n\n  \\item At $\\alpha = .01$, what is your conclusion?\n\n  As the $p-value$ is greater than alpha,the null hypothesis cannot be rejected, so we don't have a definitive answer to this question\n\n  \\item What is the rejection rule using the critical value? What is your conclusion?\n\n  The rejection rule is that $z < z_{0}$, but it this case $z =-1.47572957474524$ and $z_{0} = -2.32634787404084$, so the rejection does not hold\n\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "34aa27db1cfa781cfb17fab1e26fecb6c3094939", "size": 5116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework4_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/Homework4_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/Homework4_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": 38.7575757576, "max_line_length": 548, "alphanum_fraction": 0.6673182174, "num_tokens": 1614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928951399098, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6598290862537964}}
{"text": "\\subsubsection{Explicit, Coupled, Advective-Dispersive Mass Transfer}\\label{sec:adv_dif_mass_transfer}\n\nThe third Cauchy type mixed boundary condition defines a\nsolute flux along a boundary.  The fixed concentration flux Cauchy boundary\ncondition can be provided at the external boundary of any mass balance model.\nFor a vertically oriented system with advective velocity in the $\\hat{k}$\ndirection,\n\n    \\begin{align}\n      -D\\frac{\\partial C(z, t)}{\\partial z}\\Big|_{z \\in \\Gamma} &+ v_zC(z, t) = v_zC(t)\n      \\intertext{where}\n      C(t) &= \\mbox{ a known concentration function }[kg/m^{3}].\\nonumber\n    \\end{align}\n\nIn the Degradation Rate and Mixed Cell models, the Cauchy boundary condition\ncan be selected to enforce coupled advective and dispersive flow,\n\n\\begin{align}\n  J_{coupled} &= J_{adv} + J_{dis} \\nonumber\\\\\n  &= \\theta vC(z,t_n) -\\theta D\\frac{\\partial C}{\\partial z}.\n\\end{align}\n\nThe resulting mass transfer into the Degradation Rate or Mixed Cell model is then,\n\n\\begin{align}\nm_{jk}(t_n) &= A\\Delta t \\theta_k \\left( v C(z,t_n)\\Big|_{z=r_j} - D \\frac{\\partial C(z,t_n)}{\\partial z}\\Big|_{z=r_j} \\right).\n\\end{align}\n\n", "meta": {"hexsha": "8890433c050b7459fc0b2f84b89ac08ac136c18d", "size": 1141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nuclide_models/mass_transfer/adv_dis.tex", "max_stars_repo_name": "katyhuff/2017-huff-rapid", "max_stars_repo_head_hexsha": "cfb06a9a2e744914e7f3d088014db7a71a68c39d", "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": "nuclide_models/mass_transfer/adv_dis.tex", "max_issues_repo_name": "katyhuff/2017-huff-rapid", "max_issues_repo_head_hexsha": "cfb06a9a2e744914e7f3d088014db7a71a68c39d", "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": "nuclide_models/mass_transfer/adv_dis.tex", "max_forks_repo_name": "katyhuff/2017-huff-rapid", "max_forks_repo_head_hexsha": "cfb06a9a2e744914e7f3d088014db7a71a68c39d", "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.3448275862, "max_line_length": 127, "alphanum_fraction": 0.7160385627, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6597433404120598}}
{"text": "\\subsection{Shared Secret Encryption}\n\\label{ssec:secret_enc}\n\nAs mentioned above, the shared secret from\n$P_{i}$ to $P_{j}$ is $s_{i\\to j} = f_{i}(j)$.\nTo encrypt this, we need to compute their shared secret:\n\n\\begin{equation}\n    k_{ij} = \\pk_{i}^{\\sk_{j}} = \\pk_{j}^{\\sk_{i}} = \n    g_{1}^{\\sk_{i}\\sk_{j}}.\n\\end{equation}\n\n\\noindent\nEncryption and decryption are based on the idea of a one-time pad;\nin particular, we use outputs of cryptographic hashes of\nthe $x$-coordinate of the shared secret along with the index\nof the participant receiving the message as our ``one-time pad''.\nThis does not meet the technical definition of a one-time pad\nas it is usually defined (one standard reference is~\\cite{hac1996}),\nbut the idea is similar.\nBy including the index of the intended recipient in the hash function,\neach symmetric encryption key is unique.\nSee Alg.~\\ref{alg:enc_dec} for details.\n\n\\input{algs/encryption_and_decryption.tex}\n\n", "meta": {"hexsha": "f282ecab8de86fb843fe0df2549200402b81d3ac", "size": 940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/tcrypt_sse.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_sse.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_sse.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": 34.8148148148, "max_line_length": 70, "alphanum_fraction": 0.7361702128, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6597433219888807}}
{"text": "\\subsection{The Cholesky Decomposition}\\label{sec:cholesky}\nIn \\autoref{sec:simulatingvalues}, we utilised the Cholesky decomposition on the covariance matrix in the stochastic shadow fading part. The Cholesky decomposition is a decomposition algorithm for \\gls{symmetric}, \\gls{pd-matrix} into the product of a \\gls{lt-matrix} and its \\gls{conjugate-transpose}, and is primarily used for solving systems of linear equations~\\cite{Press:2007:NRE:1403886}. In this Section, we present and describe the Cholesky decomposition, as well as the problems the decomposition creates for our computation time of the stochastic shadow fading part of the link model, as well as possible ways for us to optimise our usage of the Cholesky decomposition. \\autoref{algo:cholesky} contains a pseudo code description of the Cholesky decomposition. \\medbreak\n\n\\begin{algorithm}[H]\n    \\DontPrintSemicolon\n    \\KwResult{The Cholesky decomposition of the input matrix}\n    \\SetKwFunction{Cholesky}{Cholesky}\n    \\SetKwProg{Fn}{Function}{:}{}\n    \\Fn{\\Cholesky{matrix, N}}{\n        result $\\leftarrow$ empty matrix of size N $\\times$ N \\;\n        \\For{n $\\leftarrow$ 0, n < N}{\n            \\For{m $\\leftarrow$ 0, m < n + 1}{\n                sum $\\leftarrow$ 0\\;\n                \\For{i $\\leftarrow$ 0, i < m}{\n                    sum $\\leftarrow$ sum + result$_{n,i} \\cdot$ result$_{m,i}$\\;\n                }\n                \\If{n = m}{\n                    \\If{$\\text{matrix}_{n,n} - \\text{sum} \\leq 0$}{\n                        throw error; matrix is not positive-definite\n                    }\n\n                    results$_{n,m}$ $\\leftarrow$ $\\sqrt{\\text{matrix}_{n,n} - \\text{sum}}$\\;\n                }\n                \\Else{\n                    results$_{n,m} \\leftarrow \\frac{1}{\\text{result}_{m,m}} \\cdot (\\text{matrix}_{n,m} - sum)$\\;\n                }\n            }\n        }\n        \\KwRet result\n    }\n    \\caption{Cholesky decomposition}\n    \\label{algo:cholesky}\n\\end{algorithm}\n\\medbreak\nThe first issue we have found with the Cholesky decomposition, or more specifically with the covariance matrix, is that the covariance matrix is not guaranteed to be a \\gls{pd-matrix}. The covariance matrix is based on the relation between links in the network, which means that whether the matrix is positive-definite or not is entirely based on the network. To work around this, we have employed a tool called NearPD~\\cite{website:nearPD} to transform our covariance matrix into a new matrix that has the positive-definite property, while minimising the Frobenius norm~\\cite{website:frobieniusnorm} of the difference between the original and the new matrix. This significantly increases the time required to compute the link model, however, which leads us to our next major issue: The computational time required by the Cholesky decomposition itself. The computational time required for the NearPD tool and the Cholesky decomposition can be seen in \\autoref{table:cholesky:spdtime}.\\smallbreak\n\nThe Cholesky decomposition has a computational complexity of $O(n^3)$~\\cite{Press:2007:NRE:1403886}. With a fully connected network of 1000 nodes, we would have a $\\frac{1000(1000+1)}{2} - 1000 = 499500$ (\\autoref{eq:lengthoflinks}) unique links, which means that our correlation (and covariance) matrix would be of size $499500 \\times 499500$. This is a major issue, as we would like to be able to compute the link model in a relatively short amount of time. To combat this issue, we have two possible solutions: removing links with a distance over a certain threshold, and clustering nodes that are very close to each-other. We present the first solution in this section, and clustering in \\autoref{sec:clustering}.\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{|c|c|c|c|}\n        \\hline\n        Nodes & Links & NearPD          & Cholesky                 \\\\\\hline\n        10    & 45    & 3 milliseconds  & \\textless{}1 millisecond \\\\\\hline\n        20    & 190   & 88 milliseconds & 3 milliseconds           \\\\\\hline\n        30    & 435   & 1 seconds       & 34 milliseconds          \\\\\\hline\n        40    & 780   & 6 seconds       & 200 milliseconds         \\\\\\hline\n        50    & 1225  & 32 seconds      & 720 milliseconds         \\\\\\hline\n        60    & 1770  & 113 seconds     & 3 seconds                \\\\\\hline\n        70    & 2415  & 285 seconds     & 6 seconds                \\\\\\hline\n        80    & 3160  & 584 seconds     & 12 seconds               \\\\\\hline\n        90    & 4005  & 22 minutes      & 26 seconds               \\\\\\hline\n        100   & 4950  & 35 minutes      & 45 seconds               \\\\\\hline\n        110   & 5995  & 75 minutes      & 93 seconds               \\\\\\hline\n        120   & 7140  & 127 minutes     & 155 seconds              \\\\\\hline\n        130   & 8385  & 235 minutes     & 250 seconds              \\\\\\hline\n        140   & 9730  & Timeout         & \\dots                    \\\\\\hline%582 seconds              \\\\\\hline\n        %150   & 11175 & \\dots           & 14 minutes               \\\\\\hline\n        %160   & 12720 & \\dots           & 17 minutes               \\\\\\hline\n        %170   & 14365 & \\dots           & 20 minutes               \\\\\\hline\n        %180   & 16110 & \\dots           & 29 minutes               \\\\\\hline\n        %190   & 17955 & \\dots           & 39 minutes               \\\\\\hline\n        %200   & 19900 & \\dots           & 52 minutes               \\\\\\hline\n    \\end{tabular}\n    \\caption{Computation time measurement for NearPD and Cholesky decomposition.}\n    \\label{table:cholesky:spdtime}\n\\end{table}\n\n\\autoref{table:cholesky:spdtime} shows time measurements from running the cholesky decomposition computation with different network topology sizes with the NearPD tool. The measurements shows that the NearPD tool is not fast enough, as at only 130 nodes with 8385 links the tool takes 235 minutes to compute the \\gls{pd-matrix}. This is not fast enough and a better solution will have to be found. The cholesky decomposition computation speed is also problematic, as the goal is 1000 nodes and already at 120 nodes the decomposition takes more than 2 minutes.\n\n\\subsubsection{Distance Threshold}\\label{sec:distancethreshold}\nIn \\autoref{sec:linkmodel}, we saw that the distance dependent \\gls{pathloss} has significantly more importance in the total \\gls{pathloss} than the stochastic shadow fading part. In \\autoref{eq:pathlossdetermG}, we see that the distance \\gls{pathloss} is 92 \\acrshort{dbm} for links of 100 meters, and 100.2 \\acrshort{dbm} for the diagonal links of $141.42$ meters, and in \\autoref{eq:pathlossfadingG}, we see (stochastic) \\gls{pathloss} values between $-13.837$ and $6.413$. This means that, entirely based on the distance part of the link model, according to the formula for computing packet error probability in \\autoref{sec:pep}, with a distance of 1000 meters, and a transmission power of 26 \\acrshort{dbm}, we would have a link \\gls{pathloss} of $147$ \\acrshort{dbm} (disregarding the stochastic shadow fading part of the \\gls{pathloss}), which in turn would mean that the \\gls{rssi} on the receiving end of the link would be $26 - 147 = -121$, or equivalent to a packet loss probability of 99.999~\\% (assuming the noise figure and thermal noise is the same as in \\autoref{sec:pep}, and the packet size is 160 bits). Hence removing links that are far away can potentially reduce the size of the correlation matrix significantly. To show this, we ran an experiment, where we generated 1000 nodes with random locations in a $25 \\times 25$ kilometre area, created links between these nodes based on their location, and iteratively scaled the maximum distance allowed between nodes (the distance threshold) and calculated the link path loss, based on the distance threshold. The results of this experiment can be seen in \\autoref{table:cholesky:distance-threshold}. Recall that a fully connected network topology of 1000 nodes would have a total of 499500 links. With a distance threshold of 1000 meters, we get a total of 2346 links in our $25 \\times 25$ kilometre area, which is a significant improvement as we would be able to compute the Cholesky decomposition in approximately six seconds (disregarding the positive-definiteness of the correlation matrix) according to \\autoref{table:cholesky:spdtime}.\n\n%The experiment consisted of generating 1000 random nodes in a 25 kilometre square area, create links from those nodes based on their location, iteratively scale the maximum allowed distance of the links (distance threshold) and calculate the link path loss. The results can be read in \\autoref{table:cholesky:distance-threshold}.\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{|c|c|c|}\n        \\hline\n        Distance threshold & Links & Probability \\\\\\hline % & Cholesky         \\\\\\hline\n        % 100 meters         & 182   & \\\\\\hline % & 3 milliseconds   \\\\\\hline\n        % 125 meters         & 256   & \\\\\\hline % & 7 milliseconds   \\\\\\hline\n        % 150 meters         & 360   & \\\\\\hline % & 20 milliseconds  \\\\\\hline\n        % 175 meters         & 483   & \\\\\\hline % & 46 milliseconds  \\\\\\hline\n        200 meters         & 92    & 0.001~\\%    \\\\\\hline % & 97 milliseconds  \\\\\\hline\n        % 225 meters         & 773   & \\\\\\hline % & 185 milliseconds \\\\\\hline\n        250 meters         & 139   & 0.001~\\%    \\\\\\hline % & 333 milliseconds \\\\\\hline\n        % 275 meters         & 1157  & \\\\\\hline % & 646 milliseconds \\\\\\hline\n        300 meters         & 208   & 0.001~\\%    \\\\\\hline % & 1 second         \\\\\\hline\n        % 325 meters         & 1589  & \\\\\\hline % & 1 second         \\\\\\hline\n        350 meters         & 296   & 0.001~\\%    \\\\\\hline % & 2 seconds        \\\\\\hline\n        % 375 meters         & 2076  & \\\\\\hline % & 4 seconds        \\\\\\hline\n        400 meters         & 394   & 0.001~\\%    \\\\\\hline % & 6 seconds        \\\\\\hline\n        % 425 meters         & 2642  & \\\\\\hline % & 8 seconds        \\\\\\hline\n        450 meters         & 490   & 0.001~\\%    \\\\\\hline % & 11 seconds       \\\\\\hline\n        % 475 meters         & 3290  & \\\\\\hline % & 15 seconds       \\\\\\hline\n        500 meters         & 592   & 6.000~\\%        \\\\\\hline % & 21 seconds       \\\\\\hline\n        % 525 meters         & 4035  & \\\\\\hline % & 28 seconds       \\\\\\hline\n        550 meters         & 723   & 82.333~\\%    \\\\\\hline % & 37 seconds       \\\\\\hline\n        % 575 meters         & 4830  & \\\\\\hline % & 49 seconds       \\\\\\hline\n        600 meters         & 846   & 99.999~\\%   \\\\\\hline % & 62 seconds       \\\\\\hline\n        % 625 meters         & 5723  & \\\\\\hline % & 82 seconds       \\\\\\hline\n        650 meters         & 994   & 99.999~\\%   \\\\\\hline % & 142 seconds      \\\\\\hline\n        %675 meters         & 6656  & \\\\\\hline % & 184 seconds      \\\\\\hline\n        700 meters         & 1164  & 99.999~\\%   \\\\\\hline % & 273 seconds      \\\\\\hline\n        % 725 meters         & 7608  & \\\\\\hline % & 375 seconds      \\\\\\hline\n        750 meters         & 1349  & 99.999~\\%   \\\\\\hline % & 454 seconds      \\\\\\hline\n        % 775 meters               & 8696 \\\\\\hline %  & 454 seconds      \\\\\\hline\n        800 meters         & 1507  & 99.999~\\%   \\\\\\hline %  & 580 seconds      \\\\\\hline\n        % 825 meters               & 9837 & \\\\\\hline %  & 708 seconds      \\\\\\hline\n        850 meters         & 1714  & 99.999~\\%   \\\\\\hline % & 544 seconds      \\\\\\hline\n        % 875 meters               & 1101 & \\\\\\hline %5 & 571 seconds      \\\\\\hline\n        900 meters         & 1910  & 99.999~\\%   \\\\\\hline % & 665 seconds      \\\\\\hline\n        % 925 meters               & 1225 & \\\\\\hline %1 & 783 seconds      \\\\\\hline\n        950 meters         & 2102  & 99.999~\\%   \\\\\\hline % & 916 seconds      \\\\\\hline\n        % 975 meters               & 1356 & \\\\\\hline %8 & 1058 seconds     \\\\\\hline\n        1000 meters        & 2346  & 99.999~\\%   \\\\\\hline % & 1214 seconds     \\\\\\hline\n    \\end{tabular}\n    \\caption{Results from the distance threshold experiments.}\n    \\label{table:cholesky:distance-threshold}\n\\end{table}\n\n\n% as the last row in \\autoref{table:cholesky:distance-threshold} of 750m gives good results. More aggressive thresholds drastically reduces the total amount of links more, but has the potential of removing links that should have been there.\n\n% 55 \\log_{10} \\left( d(l_1) \\right) - 18\n\n\n% \\subsection{Cholesky decomposition}\\label{sec:cholesky}\n%In this section we present and describe the Cholesky decomposition, and the problem it creates for our computation time, and how we propose to optimise the decomposition algorithm for our particular needs.\n%sec:simulatingvalues\n% The cholesky decomposition or cholesky factorization is a matrix decomposition, of a positive-definite matrix, resulting in a lower triangular matrix and its conjugate transpose.\n\n%In \\autoref{sec:linkmodel} we utilise the Cholesky decomposition in \\autoref{eq:pathlossstoch}. The Cholesky decomposition is a matrix decomposition, on a \\gls{pd-matrix}. The decomposition results in a \\gls{lt-matrix} and its \\gls{conjugate-transpose}. The Cholesky decomposition is an expensive computation of cubic time complexity, as such we intend to speed up the algorithm. Furthermore since the decomposition requires an \\gls{pd-matrix} to work, we choose to verify our auto-correlation matrix before decomposing it, to ensure that the decomposition will run correctly.\n\n% is a decomposition of a Hermitian, positive-definite matrix into the product of a lower triangular matrix and its conjugate transpose,\n\n\n% In \\autoref{sec:linkmodel} we utilise the Cholesky decomposition in \\autoref{eq:pathlossstoch}. \n% In \\autoref{sec:linkmodel} we utilise the Cholesky decomposition. The Cholesky decomposition is an expensive computation of cubic time complexity and, as such, it needs to be more efficient for our use case. \n\n%Initially we propose to optimise the algorithm by changing the data structure from a matrix to an ordered map of key-value pairs. The keys will a tuple of links and the value will be the result of the auto-correlation function from \\autoref{eq:pathlossautocorrelation}.\\medbreak\n\n\n\n%, where the pair will be sorted after the link with the largest id, will be the first element in the pair, eg. $l_1.id = 1$ and $l_2.id = 2$ then $key = (l_2, l_1)$. The map must be ordered since the cholesky decomposition uses previous calculated values, to calculate the next.\n\n% shortly introduce cholesky\n\n% our intended improvements\n\n\n", "meta": {"hexsha": "9b7c4e29d250a8cea0123a4f91680451d635c907", "size": 14430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/p9/sections/02-link-modelling/02a-cholesky.tex", "max_stars_repo_name": "Joklost/masters", "max_stars_repo_head_hexsha": "66bccba28a32ee47b7b874122de41c87f253349e", "max_stars_repo_licenses": ["MIT"], "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/p9/sections/02-link-modelling/02a-cholesky.tex", "max_issues_repo_name": "Joklost/masters", "max_issues_repo_head_hexsha": "66bccba28a32ee47b7b874122de41c87f253349e", "max_issues_repo_licenses": ["MIT"], "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/p9/sections/02-link-modelling/02a-cholesky.tex", "max_forks_repo_name": "Joklost/masters", "max_forks_repo_head_hexsha": "66bccba28a32ee47b7b874122de41c87f253349e", "max_forks_repo_licenses": ["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.3137254902, "max_line_length": 2110, "alphanum_fraction": 0.6405405405, "num_tokens": 4028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6597337121911976}}
{"text": "\\chapter{Background and related work}\n\nTo give some background to our method this chapter first gives a brief overview of machine learning and neural networks. Then, a selection of face detection, recognition, and reconstruction methods are presented. More emphasis is given to facial reconstruction methods, especially those that have been developed recently and use neural networks and synthetic data in one way or another.\n\n% Finally, selected parts of computer graphics theory are presented.\n\n\\section{Machine learning and neural networks}\n\nIf we have a parametric function $f(\\bm{x};\\bm{\\theta}) = \\bm{y}$, how should the parameters $\\bm{\\theta}$ be adjusted so that, with input $\\bm{x}$, the output of the function matches $\\bm{y}$ as closely as possible? Machine learning, and especially its most common form, supervised machine learning, can be used to solve this problem. In supervised learning, the parameters $\\bm{\\theta}$ are iteratively adjusted until the output of the function cannot be further made more accurate. To make these kinds of small adjustments, a number of training pairs $(\\bm{x}_i,\\bm{y}_i)$ are needed in addition to some metric that tells how well the function is performing. \\cite{Goodfellow2016,LeCun2015}\n\nThe function performance can be measured by a separate loss function that tells how far the output of the function is from the desired values. In the case of fitting a simple line function to a collection of points, the loss function could be visualized as the sum of the distances of the points from the line. If the points lie exactly on the line, the loss becomes zero, and further away the points are from the line, the bigger the loss becomes. Especially with more complex functions, the loss could be visualized as a multi-dimensional hilly landscape. Lower values of the loss function are valleys, and higher values are hills. The lower it is possible to travel in this loss landscape, the better the function under optimization performs. With complex functions, the loss landscape has numerous valleys and hills. Even if it seems that the loss is now small, because you are at the bottom of a valley, it is very much possible that there exists another valley somewhere else that is even deeper and thus better. \\cite{Goodfellow2016,LeCun2015}\n\nTo adjust the parameters of the function, an algorithm called gradient descent is used. The gradient of the loss function can be visualized as an arrow that, at any point in the loss landscape, points towards the direction of the greatest ascent. To travel towards lower loss function values, that is, towards the bottoms of the valleys, a step into the opposite direction of the gradient should be taken. When repeated enough many times, a loss function minimum is reached. The problem with gradient descent is that, after reaching a bottom of a valley, the algorithm cannot continue. This means that the optimization could get stuck into a local minimum even though much better minima would be available further away. \\cite{Goodfellow2016,LeCun2015}\n\nIf a very accurate gradient is calculated using all the available training data, it is very much possible for the gradient descent algorithm to get stuck at a local minimum. The accurate gradient calculation is also time-consuming and usually needs the whole dataset to be kept in memory. This is not feasible for very large datasets. The \\ac{SGD} algorithm solves this problem by calculating a less accurate gradient from a smaller, randomly selected, part of the training dataset. This small selection of training samples is called a minibatch. The more random gradient is faster to calculate, and because it is noisy, it will help the gradient descent algorithm to escape from local minima. \\cite{Goodfellow2016,LeCun2015}\n\nInstead of using just one function as the target of the optimization, a composite of multiple functions, a network, can also be used. These networks are usually called neural networks because the functional parts are loosely inspired by neuroscience. A neural network has an input layer, any number of hidden layers, and an output layer. The adjacent layers can be fully connected to each other with distinct weights for each connection, and the values that flow through the network can be modified with activation functions. The hidden layers are called so because the training data does not give any desired output for them. Instead, when trained, the network is free to come up with its internal representations. The training of a neural network like this is enabled by the backpropagation algorithm. For it to work, one requirement is that the functions that compose the network are differentiable. If this is the case, the gradient calculated at the output layer can be backpropagated through the network, and all the parameters of the network can be adjusted accordingly. \\cite{Goodfellow2016,LeCun2015}\n\nThe machine learning algorithms used today are largely the same as in the 1980s. The massive increase of computing power, storage space, and memory amounts in recent years has enabled the training of networks that were previously thought very hard to train. The modern general processing \\acp{GPU} have been instrumental in making the training process faster, as their architecture suits the task very well. Some other smaller developments, e.g., using the \\ac{RELU} activation function, have also played their part in making the training of deeper networks easier. Modern neural networks can have tens of millions of parameters, and the networks can be very deep with tens, if not hundreds, of layers. Deep learning, the name given to this new era of machine learning, reflects this fact. A good example of the deep learning advantage is the application of deep neural networks by \\textcite{Krizhevsky2012} in the 2012 ImageNet competition. Their results were impressive, almost halving the error rate compared to the best competitors. \\cite{Goodfellow2016,LeCun2015}\n\nThe functions that the network is composed of can also perform filtering using convolutions. These kinds of networks are called \\acfp{CNN}. Convolutions can be though as small filters that are slid over the larger underlying signal and that produce a new, modified, signal. Convolutions are especially well suited for processing images. One of the first applications of \\acp{CNN} was a method to recognize handwritten digits, developed by \\textcite{Lecun1998}. Many convolutions, with differing filter values, can be applied to the same image. This allows the extraction of different features from the image. The hierarchical nature of the \\acp{CNN} means that, at the first layers, the extracted features are edges, and then continuing deeper inside the network the features become parts, and parts become objects. The structure of \\acp{CNN} has been directly inspired by the concepts in visual neuroscience. \\cite{Goodfellow2016,LeCun2015}\n\nAn ordinary \\ac{CNN} usually has fully connected layers at the end and will produce a one-dimensional vector as the final output \\cite{Lecun1998}. In \\acfp{FCNN}, the fully connected part at the end is replaced by a convolutional upsampling part \\cite{Long2015}. This means that, for \\acp{FCNN}, both the inputs and outputs can be images. \\acp{FCNN} have been successfully used for dense image semantic segmentation. Semantic segmentation means understanding the image at the pixel level, i.e., giving each pixel of the input image a meaningful class \\cite{Long2015,Ronneberger2015}. The training of \\acp{FCNN} has been made easier with the introduction of the concept of skip connections. Skip connections connect the downsampling and upsampling parts of the \\ac{FCNN} directly. Skip connections have been shown to help gradients propagate from the output towards the input side of the network, transfer high-frequency detail from the input side to output side, and help to avoid singularities in the loss landscape \\cite{Ronneberger2015,Orhan2017,Goodfellow2016}.\n\nDesigning and training the neural networks, especially the deep ones, would be very time-consuming if the training code had to be reimplemented at low-level with every design iteration. To get fast enough training speeds, using \\acp{GPU} is necessary. The training code has to be executable on \\acp{GPU}, and efficient transfer of training data to the \\acp{GPU} needs to be implemented. To help make the neural network design process, code generation for the \\acp{GPU}, data transfer to the \\acp{GPU}, and the training process easier, numerous software frameworks have been developed in recent years. Good examples of these software frameworks are \\textcite{cntk}, \\textcite{tensorflow}, and \\textcite{pytorch}. With these frameworks, the neural network can be designed at high-level with the Python scripting language. Changes to the network topology can be made easily, and the framework will take care of converting the high-level network description into optimized low-level code that is ready to be run on \\acp{GPU}. \\cite{cntk,tensorflow,pytorch}\n\n\\section{Face detection and reconstruction}\n\nThe techniques for processing human faces in images are broadly classified into three categories by \\textcite{Datta2015}: face detection, face recognition, and face reconstruction. Face detection tells us if there exists a human face in an image in the first place, and can give the approximate location and size of the face. Face recognition goes a step further as it can identify the actual person in the image. Face reconstruction does not necessarily have anything to do with identification but rather finding out the underlying facial geometry, i.e., the facial shape, of the human pictured.\n\n\\begin{figure}\n    \\centering\n    \\subfloat[\\cite{Sakai1972}]{\\label{fig:face_detection_1a}\\includegraphics[height=.3\\textwidth]{takeo}}\\qquad\\qquad\n    \\subfloat[]{\\label{fig:face_detection_1b}\\includegraphics[height=.3\\textwidth]{eigenfaces}}\n    \\caption[Face detection 1]{One of the first face detection systems was developed in the early 1970s by \\textcite{Sakai1972}. Their algorithm was based on analyzing slices of a binary image of the head as shown in \\protect\\subref{fig:face_detection_1a}. Face recognition based on eigenfaces, as proposed by \\textcite{Turk1991}, was one of the first commercially viable methods for face recognition. Visualizations of eigenfaces are shown in \\protect\\subref{fig:face_detection_1b} (Copyright of AT\\&T Laboratories Cambridge).}\n    \\label{fig:face_detection_1}\n\\end{figure}\n\nOne of the first automated face detection systems was developed in the early 1970s by \\textcite{Sakai1972}. The input was a 5-bit grayscale image with a resolution of 140x208. The image was processed with an edge detecting filter and then thresholded to obtain a binary image containing contours of the face. See figure \\ref{fig:face_detection_1a} for an example. The binary image was then scanned slice-by-slice from top to bottom. Each slice was analyzed while an elaborate state machine kept track whether the image contained a human or not. The face had to be centered in the image and could have only a small amount of tilt in any direction. This method did not work at all if the person in the image had glasses or a beard.\n\nThe method of using eigenfaces for recognizing humans from pictures was introduced by \\textcite{Turk1991} in 1991. It was one of the first accurate and fast enough methods to be used commercially. The method captured the relevant variation in a collection of facial images, that is, the principal components of the distribution, into eigenvectors. The eigenvectors can be visualized as ghostly faces, eigenfaces, as is shown in figure \\ref{fig:face_detection_1b}. Any picture of a human face could then be deconstructed into a linear combination of eigenvectors, and inversely, reconstructed with the same linear combination of the same eigenvectors. The face recognition could be done by comparing the weights of the linear combinations as the weights would be similar between two images of the same person.\n\n\\begin{figure}\n    \\centering\n    \\subfloat[\\cite{Viola2001}]{\\label{fig:face_detection_2a}\\includegraphics[height=.28\\textwidth]{viola}}\\hfill\n    \\subfloat[ \\cite{Osadchy2007}]{\\label{fig:face_detection_2b}\\includegraphics[height=.28\\textwidth]{osadchy}}\n    \\caption[Face detection 2]{Face detection speed was greatly increased by a method introduced by \\textcite{Viola2001}. The method was based on fast evaluation of rectangular filters and machine learning. Some filters are visualized in \\protect\\subref{fig:face_detection_2a}. Convolutional neural networks were used by \\textcite{Osadchy2007} for fast face detection and pose estimation. \\protect\\subref{fig:face_detection_2b} shows how the algorithm performed on a somewhat difficult image.}\n    \\label{fig:face_detection_2}\n\\end{figure}\n\nThe speed of detecting faces and generating the bounding boxes around them was dramatically improved by \\textcite{Viola2001} in 2001. Their proposed method was based on the idea of the integral image, rectangular feature filters, and machine learning. The integral image, or summed area tables, was an intermediate representation of the image that allowed rapid summation of pixels in arbitrary rectangular areas. The rectangular feature filters are illustrated in figure \\ref{fig:face_detection_2a}. The filter calculated the sum of the pixels in the white area which was then subtracted from the sum of the black area. The filter could thus find intensity variations between arbitrary rectangular areas rapidly. Hundreds of thousands of possible combinations of these filters existed for a 24x24 pixel detection window, and machine learning was used to select few thousand of the most relevant filters for human face detection. Applying the resulting combination of filters to images was fast, and faces could be detected and tracked near real-time with contemporary hardware.\n\nIn 2007, \\textcite{Osadchy2007} published a novel method for simultaneously detecting faces and estimating their poses in real-time using convolutional neural networks. Figure \\ref{fig:face_detection_2b} shows how the network was able to detect multiple faces in one image including their yaw from left to right and in-plane rotation. Their network topology was similar to the one used by \\textcite{Lecun1998} in 1998 to recognize hand-written digits. The training data consisted of real human faces which were manually annotated with the pose data. The method could do face detection and pose estimation at the same time quicker and more accurately than previous methods that did the tasks separately.\n\n\\begin{figure}\n    \\centering\n    \\subfloat[\\cite{Blanz1999}]{\\label{fig:face_reconstruction_1a}\\includegraphics[height=.2\\textwidth]{blanz}}\n    \n    \\subfloat[\\cite{Richardson2016a}]{\\label{fig:face_reconstruction_1b}\\includegraphics[width=\\textwidth]{richardson1}}\n    \\caption[Face reconstruction 1]{Facial geometry and texture reconstruction using a 3D morphable model was proposed by \\textcite{Blanz1999}. The steps of their algorithm are shown in \\protect\\subref{fig:face_reconstruction_1a}. \\textcite{Richardson2016a} used a \\ac{CNN} and an iteration process to fit the morphable model to the input image. The steps are shown in \\protect\\subref{fig:face_reconstruction_1b}.}\n    \\label{fig:face_reconstruction_1}\n\\end{figure}\n\nIn 1999, \\textcite{Blanz1999} introduced a new technique to reconstruct human facial geometry from a single image using a 3D morphable face model. They started by scanning hundreds of real human faces with a 3D laser scanner. The scan produced accurate vertex positions and colors. The generated 3D face models were processed so that they all came into full correspondence with each other. Using \\ac{PCA} decomposition, an average face model and a set of basis face vectors were created. \\ac{PCA} was also done for the vertex color data. This allowed a parametric creation of 3D face models and their textures. The process of reconstructing the facial geometry from a single image started with a coarse manual alignment of the average face model over the image. An analysis-by-synthesis loop was then repeated where the face model was rendered over the image, and the factors of the principal components were adjusted until an optimization minimum was reached. Finally, additional detailed facial texture information was extracted from the image as the color \\ac{PCA} components did not contain enough high-resolution data. Steps of this process are shown in figure \\ref{fig:face_reconstruction_1a}.\n\nMore recently, in 2016, \\textcite{Richardson2016a} proposed a method to extract 3D morphable model parameters from real-world images using a \\ac{CNN}. The steps of their algorithm are visualized in figure \\ref{fig:face_reconstruction_1b}. They started by aligning the average morphable face model over the image using another posing algorithm. The face was segmented out of the background and fed to the \\ac{CNN} along with a rendered version of the current morphable face model. The \\ac{CNN} was trained to output a correction term to the morphable model parameters to make the rendered face model match the segmented real face image better. The face model rendering and parameter correction calculation were repeated iteratively multiple times to increase the quality of the reconstruction. The \\ac{CNN} was completely trained on synthetic data generated using the 3D morphable face model. Because fine facial details could not be extracted using this method, they were later captured with a separate shape-from-shading algorithm.\n\n\\textcite{Richardson2016} improved their previous method of \\cite{Richardson2016a}. The problem with their previous method was that it needed separate initialization of the average face model over the input image and that the method could not extract fine details without an external algorithm. The improved algorithm could do both in one go using two connected networks, a \\ac{CNN} and an \\ac{FCNN}. The \\ac{CNN} was applied iteratively to the input image and a coarse geometry using a 3D morphable model was recovered. A depth map was generated from this model, and the map was fed to the \\ac{FCNN} along with the input image. The \\ac{FCNN} was trained to do fine detail reconstruction, i.e., shape-from-shading, within the depth map in one shot without iteration. The \\ac{CNN} was trained in a supervised manner with synthetic data rendered using the 3D morphable model, and the \\ac{FCNN} was trained in an unsupervised manner using real-world images.\n\n\\textcite{Kim2017} introduced a method that could estimate a wide variety of 3D morphable model parameters from a real-world image in a single shot using a \\ac{CNN}. The estimated parameters included facial pose, facial shape, facial expression, skin reflectance, and scene illumination. No iteration was needed to refine the results. Before feeding the real-world images to the network, their variety was reduced by segmenting the faces out of the backgrounds using facial landmark detection. The network was trained exclusively on synthetic training data derived from the 3D morphable model. To get the parameter distributions of the synthetic training data to better model the real-world distributions, a novel breeding method was introduced that used real-world facial images to update the training set. A network trained with the breeding outperformed a network trained only on synthetic data.\n\n\\textcite{Tewari2017} were able to train an autoencoder \\ac{CNN} completely unsupervised using only real-world images. No separately generated synthetic data was used. The \\ac{CNN} was able to extract 3D morphable model parameters including facial pose, facial shape, facial expression, skin reflectance, and scene illumination in a single iteration. The method relied on a novel analytical and differentiable decoder layer that used the morphable model parameters to reconstruct the input image. It was possible to train the network in an unsupervised manner because the loss could be backpropagated through the decoder layer. With a method like this, the real-world distribution of the morphable model parameters could be captured the best, and the network could generalize well to real-world images.\n\n\\begin{figure}\n    \\centering\n    \\subfloat[\\cite{Sela2017}]{\\label{fig:face_reconstruction_2a}\\includegraphics[height=.3\\textwidth]{sela1}}\\qquad\\qquad\n    \\subfloat[\\cite{Guler2016}]{\\label{fig:face_reconstruction_2b}\\includegraphics[height=.3\\textwidth]{guler1}}\n    \n    \\subfloat[\\cite{Yu2017}]{\\label{fig:face_reconstruction_2c}\\includegraphics[height=.3\\textwidth]{yu1}}\n    \\caption[Face reconstruction 2]{The method of \\textcite{Sela2017} generated dense correspondence and depth map images. Their results are shown in \\protect\\subref{fig:face_reconstruction_2a}. \\textcite{Guler2016} generated dense correspondences using quantized regression which resulted in outputs shown in \\protect\\subref{fig:face_reconstruction_2b}. \\textcite{Yu2017} proposed a method that could estimate dense 2D pixel flow between the input image and a front-facing template mesh. Visualization of their method is shown in \\protect\\subref{fig:face_reconstruction_2c}.}\n    \\label{fig:face_reconstruction_2}\n\\end{figure}\n\nAfter the work on this thesis had started, multiple papers were published that had similar ideas regarding \\acp{CNN} and dense geometry generation. \\textcite{Sela2017} proposed an \\ac{FCNN} that could map a real-world human face image to a dense correspondence image and a dense depth map image. Examples of these images are shown in figure \\ref{fig:face_reconstruction_2a}. In contrast to most of the previously mentioned methods, this method did not use a 3D morphable model in the reconstruction process. The correspondence and depth map images were then used with a separate algorithm to extract the 3D mesh of the face. The network was trained with synthetic data with a wide range of facial shapes, facial poses, facial materials, lighting conditions, and background textures. A surprising result was that even though the synthetic data was created with a limited generative model, the network could generalize beyond the limited scope of the training material.\n\n\\textcite{Guler2016} trained an \\ac{FCNN} to estimate dense correspondences between image pixels and a 3D template mesh projected onto a 2D deformation-free space, or in other words, a UV space. Their approach was very similar to ours, but instead of plain regression, they used quantized regression. The mappings generated by this method are illustrated in figure \\ref{fig:face_reconstruction_2b}. The training dataset was generated from real-world images that had existing facial landmark annotations. The dataset generation was done by first fitting the 3D template mesh over the image using the landmarks and then rasterizing the mesh using colors representing locations in the deformation-free space.\n\n\\textcite{Yu2017} used an \\ac{FCNN} to generate dense facial correspondences between the input image and a 3D morphable face model. Two images were generated from the input image: a 2D flow image and a matchability mask image. The 2D flow image estimated the flow between the input image pixels and a synthetic rendering of an average frontal face. The matchability image indicated which correspondences were valid inside the average face. These images are visualized in figure \\ref{fig:face_reconstruction_2c}. In the beginning, the network was trained with synthetic data generated from a 3D morphable model. Later, the network was refined using annotated real-world images. Simple rectangular occlusions were also added to the training data which made the model more robust against obstructions over the faces.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[height=.4\\textwidth]{jackson1}\n    \\caption[Face reconstruction 3]{Results of the method proposed by \\textcite{Jackson2017}. They used \\acp{FCNN} to regress from the input image into a 3D volume directly.}\n    \\label{fig:face_reconstruction_3}\n\\end{figure}\n\nIn late 2017, \\textcite{Jackson2017} published a novel method that used \\acp{FCNN} for direct 2D-to-3D facial geometry reconstruction. No intermediate fitting steps were used. The training dataset consisted of real-world images and corresponding 3D binary volumes that modeled the faces in the input images. Inside the volume, if a voxel was inside the face, it was given a value of 1, and 0 otherwise. The 3D binary volumes were created using a 3D morphable model that was already fitted to the input images. The actual 3D facial geometry was recovered by generating the iso-surface of the regressed binary volume. Results of this method are shown in figure \\ref{fig:face_reconstruction_3}.\n\n\\iffalse\n\n\\section{Computer graphics and rendering}\n\nComputer graphics theory is a vast subject area. The relevant parts of it, for this thesis, are 3D mesh representation, texture mapping, surface reflectance models (\\acsp{BRDF}), the light transport equation, path tracing, and antialiasing.\n\n\\begin{gather}\nL_o(p, \\omega_o) = L_e(p, \\omega_o) + \\int_\\Omega f(p, \\omega_o, \\omega_i) L_i(p, \\omega_i) |cos\\theta_i| d\\omega_i\n\\end{gather}\n\n\\begin{Verbatim}\n- how 3D meshes are composed of triangles\n- triangles have vertices that have 3D world coordinates and 2D UV coordinates\n- UV coordinates are used for texture mapping\n- rendering can be performed by shooting rays from the camera\n- realistic images can be generated by solving the lighting equation\n- lighting equation can be solved using path tracing\n- light bouncing determined by surface reflectance models (BRDFs)\n- reflectance models (BRDFs)\n- smoothing edges using antialiasing\n\\end{Verbatim}\n\n\\begin{figure}[h]\n    \\includegraphics[width=\\textwidth]{tex-mapping}\n    \\caption[Texture mapping]{An illustration of the texture mapping process. A 3D mesh consists of triangles. Each vertex of a triangle usually has at least a 3D world coordinate (red) and a 2D UV coordinate (green). UV coordinates map the triangle onto the 2D UV space of the texture. The color from the texture can be applied to the triangle when rendering.}\n    \\label{fig:tex_mapping_1}\n\\end{figure}\n\n\\fi\n", "meta": {"hexsha": "9be2dfbdc7cd3f0d9e327acd54692356258ee310", "size": 26170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/parts/4background.tex", "max_stars_repo_name": "mikoro/master-thesis", "max_stars_repo_head_hexsha": "5af27c5e4186938b6f192a839f4d19370e21f917", "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/parts/4background.tex", "max_issues_repo_name": "mikoro/master-thesis", "max_issues_repo_head_hexsha": "5af27c5e4186938b6f192a839f4d19370e21f917", "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/parts/4background.tex", "max_forks_repo_name": "mikoro/master-thesis", "max_forks_repo_head_hexsha": "5af27c5e4186938b6f192a839f4d19370e21f917", "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": 204.453125, "max_line_length": 1199, "alphanum_fraction": 0.8077187619, "num_tokens": 5819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6597127047144747}}
{"text": "\\subsection{Governing equations of the coarse-scale (continuum) model}\nConsider the dynamic equilibrium of a naturally fractured rock mass $\\Omega$. Let $\\Gamma$ denote the boundary of $\\Omega$ and let $\\Gamma$ be divided into mutually exclusive sets $\\Gamma_u$ and $\\Gamma_t$.   The body contains a set of natural fractures denoted by $\\Gamma_{cr}$ and is subjected to a body force $\\mathbf{g}$.  Let material points in the the undeformed and the deformed configuration be denoted by $\\mathbf{X}$ and $\\mathbf{x}$, respectively. Let $\\mathbf{u}\\left(\\mathbf{X}, t\\right)=\\mathbf{x}\\left(\\mathbf{X}, t\\right)-\\mathbf{X}$ denote the displacement of material point $\\mathbf{x}$ at time $t$.    Equilibirum of $\\Omega$ is governed by\n\\begin{equation}\n\\label{eqn:equil}\n\\rho_s \\ddot{\\mathbf{u}} =\\nabla \\cdot \\boldsymbol{\\sigma} +\\mathbf{g},\\:\\forall \\mathbf{x}\\in\\Omega, t\\geq0,\n\\end{equation}\nin which $\\ddot{\\mathbf{u}}=\\ddot{\\mathbf{u}}\\left(\\mathbf{x}, t\\right)$ denotes the second partial derivative of the displacement field and $\\rho_s$ is the density of the rock mass. \n\n", "meta": {"hexsha": "848bf1b2a6e8d776df4f7e51e4fcf9497d607493", "size": 1076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "unused/subsection_governingEquationsOfCourseScale.tex", "max_stars_repo_name": "yetisir/up-scaling-dem-simulations", "max_stars_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "unused/subsection_governingEquationsOfCourseScale.tex", "max_issues_repo_name": "yetisir/up-scaling-dem-simulations", "max_issues_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "unused/subsection_governingEquationsOfCourseScale.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": 119.5555555556, "max_line_length": 659, "alphanum_fraction": 0.7295539033, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.6596931506376967}}
{"text": "\\documentclass[notitlepage]{problem-solving}\n\n\\usepackage{mathtools}\n\n\\author{Matt McCarthy}\n\\date{June 2016}\n\\title{Generating Monoids from Categories}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{thm*}\n\tLet $C$ be a category and let $A$ be an object in $C$.\n\tThen $C[A,A]$ forms a monoid under arrow composition.\n\\end{thm*}\n\n\\section{Background}\n\n\\begin{definition}[Category]\n\tA \\textit{category}, $C$ consists of the following.\n\t\\begin{enumerate}\n\t\t\\item A class of \\textit{objects}, denoted $Obj(C)$.\n\t\t\\item A class of \\textit{arrows}, denoted $Arr(C)$.\n\t\tEach arrow $f\\in Arr(C)$ has a source object $A\\in Obj(C)$, a target object $B\\in Obj(C)$, and is denoted $f:A\\rightarrow B$.\n\t\tWe denote the class of all arrows going from $A\\in Obj(C)$ to $B\\in Obj(C)$ as $C[A,B]$.\n\t\t\\item A partial composition $\\circ:Arr(C)\\times Arr(C)\\rightarrow Arr(C)$ such that for any $f:A\\rightarrow B,g:B\\rightarrow D$, $gf:A\\rightarrow D\\in Arr(C)$.\n\t\\end{enumerate}\n\tFurthermore, the following axioms must hold.\n\t\\begin{enumerate}\n\t\t\\item For all $f:A\\rightarrow B,g:B\\rightarrow D,h:D\\rightarrow E\\in Arr(C)$, $h(gf) = (hg)f$.\n\t\t\\item For all $A\\in Obj(C)$, there exists an $id_A\\in C[A,A]$ such that for all arrows $f:X\\rightarrow A$, $g:A\\rightarrow Y$ $id_A\\, f =f$ and $g\\, id_A = g$.\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Monoid]\n\tLet $M$ be a set, and let $*:M^2\\rightarrow M$ be a binary operation.\n\tThen $(M,*)$ forms a \\textit{monoid} if all of the following are satisfied.\n\t\\begin{enumerate}\n\t\t\\item For all $a,b,c\\in M$, $a*(b*c)=(a*b)*c$.\n\t\t\\item There exists an $e\\in M$ such that for all $a\\in M$, $e*a=a*e=a$.\n\t\\end{enumerate}\n\\end{definition}\n\n\\section{Solution}\n\n\\begin{thm}\n\tLet $C$ be a category and let $A$ be an object in $C$.\n\tThen $C[A,A]$ forms a monoid under arrow composition.\n\\end{thm}\n\\begin{proof}\n\tLet $f,g\\in C[A,A]$.\n\tThen\n\t\\[\n\t\tA \\xrightarrow{f} A \\xrightarrow{g} A\n\t\\]\n\tand thus\n\t\\[\n\t\tA \\xrightarrow{fg} A.\n\t\\]\n\tTherefore, arrow composition forms a binary operation on $C[A,A]$.\n\n\tNext, we claim that $id_A$ is the identity for $C[A,A]$ with respect to arrow composition.\n\tLet $f\\in C[A,A]$.\n\tThen, by definition, we know that $f\\, id_A = id_A\\, f = f$.\n\tThus, $id_A$ is the identity for $C[A,A]$ with respect to arrow composition.\n\n\tLastly, we must show that arrow composition is associative for all arrows in $C[A,A]$.\n\tLet $f,g,h\\in C[A,A]$.\n\tConsider $f(gh)$.\n\t\\[\n\t\tA \\xrightarrow{f(gh)} A = A\\xrightarrow{gh} A \\xrightarrow{f} = A\\xrightarrow{h} A\\xrightarrow{g} A\\xrightarrow{f} A\n\t\\]\n\tNow consider $(fg)h$.\n\t\\[\n\t\tA \\xrightarrow{(fg)h} A = A\\xrightarrow{h} A\\xrightarrow{fg} A = A\\xrightarrow{h} A\\xrightarrow{g} A\\xrightarrow{f}A\n\t\\]\n\tTherefore, $(fg)h=f(gh)$ and $C[A,A]$ is associative with respect to arrow composition.\n\tThus, $C[A,A]$ forms a monoid under arrow composition.\n\\end{proof}\n\n\n\\end{document}\n", "meta": {"hexsha": "743f288a07f77e70f55b6cbd67254459ce66eb9d", "size": 2850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-summer/monoids-from-categories/monoids-from-categories.tex", "max_stars_repo_name": "matt-mccarthy/problem-solving", "max_stars_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2016-summer/monoids-from-categories/monoids-from-categories.tex", "max_issues_repo_name": "matt-mccarthy/problem-solving", "max_issues_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016-summer/monoids-from-categories/monoids-from-categories.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": 33.9285714286, "max_line_length": 161, "alphanum_fraction": 0.6722807018, "num_tokens": 993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6596924985901933}}
{"text": "\\section{Optics}\n    \\subsection{Traveling Waves}\n    Let's first just consider a sine wave. We see that $y=sin(x)$. Let's say that the y-axis is the vertical displacement vertically, and x-axis is the horizontal displacement. The amplitude is $y_0$ and $-y_0$. Our original equation needs a few fixes. \n    \\begin{align*}\n        y&=y_0sin(x)\\\\\n        \\shortintertext{Because you cannot take the sin of something in meters, we need to change this to be an angle. Pme full oscilation coresponds to $2\\pi rad$ or $\\lambda$ distance}\\\\\n        y&=y_0sin\\left(2\\pi\\frac{x}{\\lambda}\\right)\\\\\n        \\shortintertext{Sometimes we use the parameter called the wave number:}\\\\\n        k&=\\frac{2\\pi}{\\lambda}\\\\\n        y&=y_0sin(kx)\n    \\end{align*}\n    What if also the wave moves to the right at speed $v$ (figure 6.16)? Let's take advantage of inertial frames. Let the prime axis ($x'$ and $y'$) travel \\underline{with} the wave. In the prime frame, $v'=0$. We can write $y'=y_0'sin(kx')$. Now we want to get $y$ based on $y'$. We can see that $y_0=y'_0$. What about $x$ and $x'$?\n    \\begin{align*}\n        \\Delta x&=v\\Delta t=v(t-0)\\\\\n        x-x'&=vt\\\\\n        \\shortintertext{Both sides of this equation provide a positive displacement. And now to get $y$ from $y'$, we will sub out x' for x.}\n        y'&=y_0sin(kx')\\\\\n        &=y_0sin(kx')\\\\\n        y&=y_0sin(k(x-vt))\\\\\n        y&=y_0sin(kx-kvt)\\\\\n        \\shortintertext{Let's look at $kv$}\\\\\n        \\to kv&=\\frac{2\\pi}{\\lambda}v\\\\\n        &=\\frac{2\\pi}{\\lambda}\\frac{\\lambda}{T}\\\\\n        &=\\frac{2\\pi}{T}\\\\\n        y&=y_0sin\\left(\\frac{2\\pi}{\\lambda}x-\\frac{2\\pi}{T}t\\right)\\\\\n        \\shortintertext{Notice that $\\frac{2\\pi}{T}=2\\pi f=\\omega$ Where $\\omega$ is the angular frequency.}\\\\\n        y&=y_0sin(kx-\\omega t)\\\\\n        \\shortintertext{Recall from 1D kinematics: $x=x_0+v_0t+\\frac{1}{2}a_xt^2$}\n        \\shortintertext{We will add a phase constant $\\Phi_0$}\\\\\n        \\to y(x,t)&=y_0sin(kx-wt+\\phi_0)\n        \\shortintertext{The total phase is:}\\\\\n        \\phi&=kx-\\omega t+\\phi_0\\\\\n    \\end{align*}\n    \\subsubsection{Example 1}\n    The following $\\vec{E}$ and $\\vec{B}$ fields satisfy this set of four equations (figure 7.1)\n    \\begin{align*}\n        \\vec{E}&=E_0sin(kz-\\omega t)\\hat{i}\\\\\n        \\vec{B}1&=B_0sin(kz-\\omega t)\\hat{j}\\\\\n        \\shortintertext{The pointing vector tells us the direction and magnitude of this combined electromagnetic wave. We must cross $\\vec{B}$ and $\\vec{E}$ in order to get the correct direction. In this case we are going to to $\\vec{E}\\times\\vec{B}$}\\\\\n        \\vec{S}&\\approx\\vec{E}\\times\\vec{B}\\\\\n        \\shortintertext{In order to make this an equality we must add $\\frac{1}{\\mu_0}$.}\\\\\n        \\alignedbox{\\vec{S}}{=\\frac{1}{\\mu_0}\\vec{E}\\times\\vec{B}}\\\\\n        \\shortintertext{This means that electric fields do not need a median in order to move. Now let's figure out how fast this electromagnetic wave moves. We recently saw in class that $kv=\\omega$. For this case we do find that $v=\\frac{\\omega}{k}=\\frac{1}{\\sqrt{\\mu_0\\epsilon_0}}$. It was immediately noticed that light traveled at exactly this value. This is denoted as:}\\\\\n        c&=\\frac{1}{\\sqrt{\\mu_0\\epsilon_0}}\\approx3\\times10^8\\frac{m}{s}\\\\\n        \\shortintertext{It turns out that light is an electromagnetic wave! Optics is the applied study of electromagnetic waves.}\n    \\end{align*}\n\n\n    \\subsection{Electromagnetic Spectrum}\n    For light,\n    \\begin{align*}\n        c=\\frac{\\omega}{k}=\\frac{2\\pi f}{\\frac{2\\pi}{\\lambda}}\\\\\n        c=\\lambda f\\\\\n        \\shortintertext{Notice that we can change the wavelength or the frequency but the product must result in c. This gives us a spectrum or wavelengths we can choose.}\n    \\end{align*}\n    In terms of wavelength, humans can see from violet $(\\sim400nm)$ up to red $(\\sim600nm)$.  In terms of frequency, red is about $1.21\\times10^34$ and violet is around $7.86\\times10^31$\n\n\n    \\subsection{Creating EM waves}\n    Figure 7.2. I flip the switch up and change the capacitor to $Q_0=cv_0$. Then I flip the switch to exclude the battery. The new circuit just excludes the battery. The charges are going to flow cw through the inductor, which rejects the current. The charges are going to equilibriate and the current is going to weaken. This is an oscilating current.\n    \\begin{align*}\n        \\omega&=\\frac{1}{\\sqrt{lc}}\\\\\n        f&=\\frac{1}{2\\pi}\\frac{1}{\\sqrt{lc}}\\\\\n    \\end{align*}\n\n    \n    \\subsection{Pointing Vectors}\n    Recall that was saw that we can make an EM wave with an LC oscillator circuit. The energy stored in an electric field in a capacitor is:\n    \\begin{equation*}   \n        U_E=\\frac{1}{2}CV^2\n    \\end{equation*}\n    The energy density can be written more generally as, where $u_E$ is the energy density and $U_B$ is the potential energy:\n    \\begin{equation*}\n        u_E=\\frac{U_E}{volume}=\\frac{1}{2}\\epsilon_0E^2\n    \\end{equation*}\n    The energy stored in a magnetic field in an inductor is:\n    \\begin{equation*}\n        U_B=\\frac{1}{2}LI^2\n    \\end{equation*}\n    The energy density can be writted more generally as:\n    \\begin{equation*}\n        u_B=\\frac{U_B}{volume}=\\frac{1}{2}\\frac{1}{\\mu_0}B^2\n    \\end{equation*}\n    Consider figure 7.1 again. On the EM wave, the energy density is:\n    \\begin{align*}\n        u&=u_E+u_B\\\\\n        u&=\\frac{1}{2}\\epsilon_0E^2+\\frac{1}{2}\\frac{1}{\\mu_0}B^2\\\\\n        u&=\\frac{1}{2}\\epsilon_0(cB)^2+\\frac{1}{2}\\frac{1}{\\mu_0}B^2\\\\\n        \\shortintertext{Recall that $c=\\frac{1}{\\sqrt{\\epsilon_0\\mu_0}}$}\\\\\n        u&=\\frac{1}{2}\\epsilon_0\\frac{1}{\\epsilon_0}B^2+\\frac{1}{2}\\frac{1}{\\mu_0}B^2\\\\\n        u&=\\frac{1}{\\mu_0}B^2\\\\\n        \\shortintertext{Equivalently, because $B=\\frac{E}{c}$:}\\\\\n        \\to u&=\\frac{1}{\\mu_0}\\frac{E^2}{c^2}\\\\\n        &=\\frac{1}{\\mu_0}\\epsilon_0\\mu_0E^2\\\\\n        \\alignedbox{u}{=\\epsilon_0E^2}\\\\\n        &\\text{Energy density in EM wave}\n    \\end{align*}\n    An electromagnetic wave transports energy in its EM fields. This energy transport is called the pointing vector $\\vec{S}$.\n    \\begin{align*}\n        S&=\\frac{energyfluxthroughareaintime\\Delta t}{A\\Delta t}\\\\\n        &=\\frac{1}{\\mu_0}EB\\\\\n        \\alignedbox{\\text{In Vector Form, }\\vec{s}}{=\\frac{1}{\\mu_0}\\vec{E}\\times\\vec{B}}\n    \\end{align*}\n    $u(z,t)$ is the wave's energy density, so if i want the energy transport in time, we must multiply it by the volume to get energy.\n    \\begin{align*}\n        u*volume&=u*A\\\\\n        S&=\\frac{uAc\\Delta t}{A\\Delta t}=uc\\\\\n        &=\\epsilon_0E^2c=\\epsilon_0(cE)(E)\n    \\end{align*}\n    When we see light, our eye is detecting the EM waves in the pointing vector. Our brain arranges out the fast oscillations. So essentially, the intensity of light we see is the time-average pointing vector. Intensity is script i:\n    \\begin{align*}\n        i&=S_{avg}=\\left(\\frac{1}{\\mu_0}EB\\right)_{avg}\\\\\n        &=\\left(\\frac{1}{\\mu_0}E\\frac{E}{c}\\right)_{avg}\\\\\n        &=\\frac{1}{\\mu_0c}(E^2)_{avg}\\\\\n        &\\neq\\frac{1}{\\mu_0}(E_{avg})^2\\\\\n        E&=E_0sin(kz-\\omega t)\\\\\n        E_{avg}&=0\\\\\n        (E^2)_{avg}&=E_0^2(sin^2(kz-\\omega t))_{avg}=\\frac{1}{2}E_0^2\\\\\n        i&=\\frac{1}{\\mu_0c}\\frac{E_0^2}{2}\\\\\n        \\shortintertext{We can also write:}\\\\\n        \\sqrt{(E^2)}_{avg}&=E_{rms}\\\\\n        E_{rms}&=\\frac{E_0}{\\sqrt{2}}\n    \\end{align*}\n    More on intensity. The general definition of intensity is:\n    \\begin{equation*}\n        \\mathscr{I}=\\frac{P}{A}\n    \\end{equation*}\n    Light has no mass, and there is no mass in electromagnetic fields. Although it doesn't have math, it had momentum and pressure. Radiation pressure $(P_{rad}$):\n    % First PRAD below is power radiation, after \\frac{F_{rad}c}{A} P_rad changes to rad pressure\n    \\begin{align*}\n        P_{rad}&=\\frac{dW}{d}=\\frac{\\vec{F_rad}\\cdot d\\vec{z}}{dt}=\\frac{F_{rad}dz}{dt}\\\\\n        P_{rad}&=F_{rad}c\\\\\n        \\mathscr{I}&=\\frac{P}{A}\\\\\n        &=\\frac{F_{rad}c}{A}\\\\\n        &=\\mathscr{P}_{rad}c\\\\\n        \\to P_{rad}&=\\frac{\\mathscr{I}}{c}\\\\\n    \\end{align*}\n    Note: $F=ma$ does not apply here, but Newton's second law, $\\vec{F}_{net}=\\frac{d}{dt}\\vec{p}$. For a massive object,\n    \\begin{align*}\n        \\vec{p}&=m\\vec{v}\\\\\n        \\vec{F}_{net}&=\\frac{d}{dt}(m\\vec{v})\\\\\n        &=m\\frac{d}{dt}\\vec{v}\\\\\n        &=m\\vec{a}\\\\\n    \\end{align*}\n    Here, we do not have mass in the EM wave. We cannot use $\\vec{F}=m\\vec{a}$ in any calculations.\\newline\\newline\n    Let's consider an EM wave that is incident on a surface. How much force will be exerted on the surface when the wave hits it? This depends on whether the wave is absorbed or reflected.\n    \\begin{align*}\n        \\vec{F}&=\\frac{\\Delta \\vec{p}}{\\Delta t}\\\\\n        \\shortintertext{If the wave is reflected, how must $\\Delta\\vec{p}$ look? Let's call the initial momentum $\\vec{p}_0$.}\\\\\n        \\Delta\\vec{p}&=\\vec{p}_+-\\vec{p}_0\\\\\n        &=-2\\vec{p}_0\\\\\n        \\shortintertext{By contrast, during an absorbtion,}\n        \\Delta\\vec{p}&=\\vec{p}_f-\\vec{p}_i\\\\\n        \\Delta\\vec{p}&=-\\vec{p}_0\\\\\n    \\end{align*}\n    With this, consider:\n    \\begin{align*}\n        \\mathscr{P}_{rad}&=\\frac{\\mathscr{I}}{c}\\\\\n        \\frac{F_{rad}}{A}&=\\frac{\\mathscr{I}}{c}\\\\\n        \\alignedbox{F_{rad}}{=\\frac{\\mathscr{I}A}{c}=\\frac{S_{avg}A}{c}\\text{ Absorbtion}}\\\\\n        \\shortintertext{For reflection we can just update the derivation:}\\\\\n        \\alignedbox{F_{rad}}{=2\\frac{\\mathscr{I}A}{c}=2\\frac{S_{avg}A}{c}\\text{Reflection}}\\\\\n    \\end{align*}\n    If you would like to use EM waves to exert a force on something, it is twice as efficient to have the wave reflect instead of absorb. For example, a solar sail. Consider a satalite in space that has a solar sail that is being pushed by the electromagnetic waves of the sun. The sunlight will exert a force with reflection. Keep in mind that $A$ is the sail's cross sectional area.\n    \\begin{align*}\n        F_{rad}&=2\\frac{\\mathscr{I}A}{c}\\\\\n        \\shortintertext{This is exerted on the sail}\\\\\n        2\\frac{\\mathscr{I}A}{c}&=ma\\\\\n        a&=\\frac{2\\mathscr{I}A}{mc}\\\\\n    \\end{align*}\n\n\n    \\subsection{Polarization of Light}\n    With a normal electromagnetic wave, $\\vec{E}=E\\hat{i}=E_0sin(kz-\\omega t+\\mathscr{P}_0)\\vec{i}$ and $\\vec{B}=B\\hat{j}=B_0sin(kz-\\omega t+\\mathscr{P}_0)\\hat{j}$. When such a wave $\\left(\\vec{S}=\\frac{1}{\\mu_0}\\vec{E}\\times\\vec{B}\\right)$ reaches a surface, that surface can polarize the light. Light from the sun and lightbulds are unpolarized. A \\underline{polaroid} is a thin material that polarizes light. It does so by building long parallel chains of molecules. When sunlight reflects of the road, it is largely polarized in plane with the road. So windshields are polarized vertically to block thin horizontal glare.\n    \\subsubsection{Example 1}\n    This is an intensity example. A $18W$ light bulb is 1m away from a tennis ball (diameter of 12cm). How much energy has the tennis ball absorbed. Assume that the ball absorbs 70 percent of incident energy (figure 7.3). Let's assume the light bulb is isotropic (the same in all directions). Let's assume theres no reflection off the table for simplicity. How do we determine how much light goes towards the ball? First lets determine which variables cover which units. r is going to be the distance from the ball, and $r_{ball}$ is the radius of the ball. $P_{light} = 18W$, $r=1m$, $r_{ball}=6cm=0.06m$, $t=1hr=3600s$. More generally, let's say that $P_{light}=P_{src}=18W$. First we need to determine the amount of power incident on the ball (\"absorbed\") is $P_{inc}=P_{src}\\frac{a_{ball}}{a_{shell}}$. This is where $a_{ball}$ is the cross sectional area and $a_{shell}$ is the surface area of the sphere.\n    \\begin{align*}\n        P_{inc}&=P_{src}\\frac{a_{ball}}{a_{shell}}\\\\\n        &=P_{src}\\frac{\\pi r_{ball}^2}{4\\pi r^2}\\\\\n        \\alignedbox{P_{inc}}{=\\frac{1}{4}P_{src}\\frac{r_{ball}^2}{r^2}}\\\\\n        \\shortintertext{This is the power incident on the tennis ball, but how intense is the light at the tennis ball?}\\\\\n        \\mathscr{I}_{attheball}=\\frac{P_{src}}{A_{shellattheball}}=\\frac{P_{src}}{4\\pi r^2}\\\\\n        \\shortintertext{Notice that $P_{inc}=\\mathscr{I}_{src}a_{ball}$. The energy absorbed in one hour is $\\mathscr{E}=P_{inc}t$}\\\\\n        \\mathscr{E}&=\\frac{0.7}{4}P_{src}\\frac{r_{ball}^2}{r^2}t\\\\\n        \\mathscr{E}&=\\frac{0.7}{4}(18W)\\frac{(0.6m)^2}{(1m)^2}(3600s)\\\\\n        \\alignedbox{\\mathscr{E}}{=40.8J}\\\\\n    \\end{align*}\n\n\n    \\subsection{Geometric or Ray Optics}\n    Reflection: consider a bullet. If we shoot a gun such that it hits the floor, it will bounce back (reflect off the surface) at a 90 degree angle from the angle it came in at. This is due to Newton's second law, every action must have an equal and opposite reaction (figure 7.4).\n    \\begin{align*}\n        \\vec{F}&=m\\vec{a}\\\\\n        \\vec{F}&=\\frac{\\Delta\\vec{p}}{\\Delta t}\\\\\n    \\end{align*}\n    The law of reflection states that $\\theta_1=\\theta_1'$. Let's now consider light incident on a still surface of water (figure 7.5). The law of refraction is known as snell's law:\n    \\begin{align*}\n        n_1sin\\theta_1&=n_2sin\\theta_2\\\\\n        \\shortintertext{n is the index of refraction. The value of n depends on the medium}\\\\\n        n&=\\frac{c}{v}\\\\\n        \\shortintertext{For gasses a good approximation for n is 1. This also applies in a vaccum}\\\\\n        n_{water}&=1.333\\\\\n        n_{diamonds}&=2.42\\\\\n    \\end{align*}\n    The incident angle at which light will totally internally reflect is called the critical angle $(\\theta_c)$. Now we are going to figure out what $\\theta_c$ is.\n    \\begin{align*}\n        n_1sin\\theta_c&=n_2sin90^o\\\\\n        \\theta_c&=arcsin\\frac{n_2}{n_1}\\\\\n        \\shortintertext{For diamond to air,}\\\\\n        \\theta_c&=arcsin\\frac{1}{2.42}\\\\\n        &=24.4\\si{\\degree}\\\\\n    \\end{align*}\n    A great application of this idea is fiber optic cables. For wavelets in Refraction we will wait some time $(\\Delta t)$ for the wavelength to travel into the water. Keep in mind that light travels faster in air than in water.\n\n\n    \\subsection{Thin Lens Refraction}\n    Look at figure 7.7. Here are the rules for ray diagrams (thin lenses):\n    \\begin{itemize}\n        \\item A raythrough the center of the lenz from the object goes straight through the lens.\n        \\item Parallel rays go through the focal point.\n    \\end{itemize}\n    The crossing point from any two rays gives the image location. Real images are inverted. The thin lens equation is the following:\n    \\begin{equation*}\n        \\frac{1}{f}=\\frac{1}{d_0}+\\frac{1}{d_i}\n    \\end{equation*}\n    For this problem, let's find $d_i$.\n    \\begin{align*}\n        \\frac{1}{f}-\\frac{1}{d_0}&=\\frac{1}{d_i}\\\\\n        d_i&=\\left(\\frac{1}{f}-\\frac{1}{d_0}\\right)^{-1}\\\\\n        &=\\left(\\frac{1}{f}+\\frac{1}{-d_0}\\right)^{-1}\\\\\n        &=\\frac{f(-d_0)}{f+(-d_0)}\\\\\n        d_i&=\\frac{fd_0}{d_0-f}\\\\\n        &=\\frac{(15cm)(46cm)}{46cm-15cm}=22.3cm\\\\\n    \\end{align*}\n    With my ray diagram, I get 21.5cm, which is pretty close to 22.3cm\n    \\subsubsection{Example 1}\n    Here $f=15cm$ and $d_0=10cm$. This is figure 7.8. This gives is a virtual image. Virtual images are upright and cannot be seen/projected on a screen. Again, $\\frac{1}{f}=\\frac{1}{d_0}+\\frac{1}{d_i}$ gives:\n    \\begin{align*}\n        d_i&=\\frac{fd_0}{d_0-f}\\\\\n        d_i&=\\frac{(15cm)(10)}{(10cm)-(15cm)}=-30cm\n    \\end{align*}\n    By hand on the board, we got -33cm. With a pen on gridpaper, we should be within 0.5cm.\n    \\newline\\newline\n    The ratio of image height to object (with a minus sign) is called magnification.\n    \\begin{equation*}\n        m=\\frac{h_i}{h_0}=\\frac{-d_i}{d_0}\n    \\end{equation*}\n    Here we have $m=\\frac{h_i}{h_0}=\\frac{37cm}{11.5cm}=3.2$ also, if we calculate using $d_i$ and $d_0$, $m=-\\frac{-33cm}{10cm}=3.3$\n    \\newline\\newline\n    Diverging lens ray diagram (figure 7.9). Must treat f as negative. \n    \\begin{align*}\n        d_i=\\frac{fd_0}{d_0-f}=\\frac{(-15cm)(47cm)}{47cm-(-15cm)}\n    \\end{align*}\n    I measure -11.4cm. This matches exactly. Now to calculate the magnification:\n    \\begin{align*}\n        m&=\\frac{h_i}{h_0}=\\frac{-d_i}{d_0}\\\\\n        &=\\frac{2.5cm}{10cm}\\text{ or }-\\frac{-11.4cm}{47cm}\\\\\n        &= 0.25\n    \\end{align*}\n    \n    \\subsection{Wave Interference}\n    Let's recall from last class that we treated light as particle-like. For example, ray tracing. However at times, light acts like a wave. For context, let's consider water waves. Both waterwaves and light waves have interference. Let's think about an interferometer (figure 7.10). The interference equation is the following:\n    \\begin{equation*}\n        differenceinpathlength=integernumberof\\lambda s\n    \\end{equation*}\n    For our laser interferometer, this equation will give constructive interference.\n    \\begin{equation*}\n        2d_1-2d_2=m\\lambda\n    \\end{equation*}\n    Where $m$ is the integer from above. Now for destructive interference:\n    \\begin{align*}\n        2d_1-2d_2=m\\lambda+\\frac{1}{2}\\lambda\\\\\n        2d_1-2d_2=\\left(m+\\frac{1}{2}\\right)\\lambda\n    \\end{align*}\n    let's discuss more of what happens at an interface. Consider again light refracting from air to water. We know that $n_{air}=1$ and $n_{water}=1.33$. $n=\\frac{c}{v}$. In waves, $v=\\lambda f$. If in air or a vacuum, $c=\\lambda f$, but in water $v=\\lambda f$. Either $\\lambda$ or $f$ needs to change because of the change in medium.\n    \\begin{align*}\n        \\frac{c}{n}&=\\frac{\\lambda f}{n}\\\\\n        \\shortintertext{Do we want $\\frac{c}{n}=\\frac{\\lambda}{n}f$ or $\\frac{c}{n}=\\lambda\\frac{f}{n}$?}\\\\\n        \\shortintertext{We cannot have the second option because frequency \\underline{must} be constant across the boundary. There is no way for the frequency to change as it goes through an interface. If this were the case then the frequency would increase when it comes back in contact with air.}\n    \\end{align*}\n    \\subsubsection{Example 2}\n    This involes thin film interference. On a soap bubble there are many different colors that reflect off of the bubble. We are going to assume that the soapy water has $n= 1.4$. Some of the light will reflect and some of the light will refract and then reflect off the inner surface. Recall that the interference equation is $difinpathlength=integernumberof\\lambda s$.\n    \\begin{align*}\n        2t&=m\\lambda\\\\\n        \\shortintertext{This is on the right track but an important detail is missing.}\n    \\end{align*}\n    In order to determine what this important detail thats missing is, we must consider first a wave phase shift. With a heavy rope knotted with a light rope, we can see that the wave from the rope is refracted, not reflected.\\newline\\newline\n    The following is true for light:\n    \\begin{itemize}\n        \\item From high n to low n, there is no phase change upon reflection.\n        \\item From low n to high n, there is a $180\\si{\\degree}$ or $\\pi rad$ or flip in phase, or $\\frac{1}{2}\\lambda$\n        \\item For refraction/transmission, there is never a phase change.\n    \\end{itemize}\n    Earlier, we found $2t=m\\lambda$. But we must still account for phase flips for reflections.\n    \\begin{align*}\n        difinpathlength&=integernumberof\\lambda s\\\\\n        2t+\\frac{1}{2}\\lambda&=m\\lambda\\\\\n        \\shortintertext{Because the changeing of the color of the light occurs within the soapy bubble, we are going to use the wavelength of light in soapy water on both sides of our equation.}\n        \\to 2t+\\frac{1}{2}\\frac{\\lambda_0}{n_{s.w.}}&=m\\frac{\\lambda_0}{n_{s.w.}}\\\\\n        2t&=\\left(m-\\frac{1}{2}\\right)\\frac{\\lambda_0}{n_{s.w.}}\\text{ constructive}\\\\\n        2t&=\\left(m-\\frac{1}{2}\\right)\\frac{\\lambda_0}{n_{s.w.}}+\\frac{1}{2}\\frac{\\lambda_0}{n_{s.w.}}\\\\\n        2t&=m\\frac{\\lambda_0}{n_{s.w.}}\\text{ destructive}\n        \\shortintertext{Both the constructive and destructive are for $m=1,2,3,4,$.}\n    \\end{align*}\n\n    \\subsection{Slit Interference}\n    For a single slit diffraction, $\\frac{a}{2}sin\\theta=m\\lambda$ for construction, $m=0,1,2$. For destructino, it is $asin\\theta=m\\lambda$, $m=0,1,2$. For double slit interference, the contructive equation is $dsin\\theta=m\\lambda$ for $m=0,1,2$. Destructive is $dsin\\theta=\\left(m+\\frac{1}{2}\\right)\\lambda$. Notice that $sin\\theta=\\frac{y_m}{\\sqrt{y_m^2+D^2}}$.\n\n    \\subsection{Crystallography}\n    Also called Xr-ray diffraction or bragg diffration. The following is a basic crystal (figure 7.11). \n    \\begin{align*}\n        differenceinpathlength&=intnum\\lambda\\\\\n        \\alignedbox{2dsin\\theta}{=m\\lambda}\n    \\end{align*}\n    \\subsection{Electron Diffraction}\n    Consider a single-slit setup. When shooting electrons at the slit, we also see an interference pattern. Electrons, then must also have wave characteristics. deBroglie:\n    \\begin{equation*}\n        \\lambda_c=\\frac{h}{p}\n    \\end{equation*}\n    Where $h$ is the Planchs constant.\n\n    \\subsection{Special Relativity}\n    \\begin{itemize}\n        \\item 1860s Maxwell unifies electricity and magnetism.\n        \\item Light is an electromagnetic wave\n        \\item Waves require a medium\n        \\item In 1877, Nichelsen and mosley try to measure the luminous ether, the medium in which light must travel. They measured no change.\n    \\end{itemize}\n    Einstein came up with two postulates to try to understand everythign that doesn't make sense (1905). The Principle of Relativity: The laws of physice are the same in all inertial (non-accelerating) frames. Invariance of c. Signals don't arrive instantaneously but propogate. Thus, there must be a maximum universal speed.\n    \\subsubsection{Example}\n    Let's look at a light clock (figure 7.12). The left side of the figure is when the light clock is at rest. We can derive that $t_0=\\frac{2L_0}{c}$. The right side of the figure is when the light clock is at speed. We know that the light is moving at $\\sqrt{c^2 + u^2}$. Now let's put this into terms of light:\n    \\begin{align*}\n        t&=\\frac{2\\sqrt{L_0^2+\\left(\\frac{ut}{2}\\right)^2}}{\\sqrt{c^2+u^2}}\\\\\n        &=\\frac{2\\sqrt{\\left(\\frac{ct}{2}\\right)^2+\\left(\\frac{ut}{2}\\right)^2}}{\\sqrt{c^2+u^2}}\\\\\n        &=\\frac{2\\sqrt{\\left(\\frac{1}{2}\\right)^2\\left[(ct)^2+(ut)^2\\right]}}{\\sqrt{c^2+u^2}}\\\\\n        t&=\\frac{t\\sqrt{c^2+u^2}}{\\sqrt{c^2+u^2}}\\\\\n        t&=t\\\\\n        \\shortintertext{However, this is \\underline{NOT} reality. From a special relativity (SR) approach things are different. Light always travels at c in \\underline{all} inertial reference frames. We can use the same figure as before but we much do a different analysis. Becuase the speed of light is always c, our analysis triangles from before does not work. The way the velocity vectors combine is differnet.}\\\\\n        t&=\\frac{2\\sqrt{L_0^2+\\left(\\frac{ut}{2}\\right)^2}}{c}\\\\\n        t&=\\frac{2\\left(\\frac{ct_0}{2}\\right)^2\\left(\\frac{ut}{2}\\right)^2}{c}\\\\\n        (ct)^2&=(ct_0)^2+(ut)^2\\\\\n        (ct)^2-(ut)^2&=(ct_0)^2\\\\\n        t^2(c^2-u^2)&=(ct_0)^2\\\\\n        t^2&=\\frac{(ct_0)^2}{c^2-u^2}\\\\\n        t&=\\frac{ct_0}{\\sqrt{c^2-u^2}}\\\\\n        \\alignedbox{t}{=t_0\\frac{1}{\\sqrt{1-\\frac{u^2}{c^2}}}}\n        \\shortintertext{This is called Time Dilation. Time panes move slowly for moving objects.}\n    \\end{align*}\n    Now let's say the clokc ticks at rest with a time of $t_0=1sec$. In order to make the clock tick one percent slower, that is, $t=1.01sec$, the clock must move at a speed of $42,000,000\\frac{m}{s}$!\n\\newpage", "meta": {"hexsha": "62d5174c9c73bf3731f3deb79b781eb98294b5d7", "size": 23313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics204/Sections/7Optics.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/7Optics.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/7Optics.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": 66.6085714286, "max_line_length": 910, "alphanum_fraction": 0.6488654399, "num_tokens": 7681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7690802264851918, "lm_q1q2_score": 0.6596924940502255}}
{"text": "\\subsection{Frechet spaces}\\label{subsec:frechet_spaces}\n\n\\begin{definition}\\label{def:frechet_space}\\mcite[1.8 (f)]{Rudin1991Functional}\n  An \\term{F-space} is a \\hyperref[thm:uniform_space_completion]{complete} \\hyperref[def:metric_topology]{metrizable} \\hyperref[def:topological_vector_space]{topological vector space}. We can assume that an F-space is a tuple \\( (\\mscrX, \\rho) \\), where \\( \\rho \\) is a \\hyperref[def:complete_metric_space]{complete} \\hyperref[def:translation_invariant_metric]{translation-invariant} \\hyperref[def:metric_space]{metric}.\n\n  A \\term{Frechet space} is a \\hyperref[def:locally_convex_space]{locally convex} F-space.\n\\end{definition}\n", "meta": {"hexsha": "8c7a160a27fb66b712dac49820f5e58c341f6ded", "size": 668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/frechet_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/frechet_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/frechet_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": 83.5, "max_line_length": 420, "alphanum_fraction": 0.7829341317, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6596924884575628}}
{"text": "% \\documentclass[10pt]{article}\r\n% \\usepackage{amsmath}\r\n% \\usepackage{amssymb}\r\n% \\usepackage[margin=1in]{geometry}\r\n% \\setlength\\parindent{0pt}\r\n%\r\n% \\begin{document}\r\n% \\noindent\r\n\r\n\\section{Dispersion of Matter Waves}\r\nAn equation which is closely related to the wave equation is the Schrodinger equation:\r\n\r\n$$i\\frac{\\partial\\psi(x,t)}{\\partial t}=-\\frac{1}{2m}\\frac{\\partial^{2}\\psi(x,t)}{\\partial x^{2}},$$\r\n\r\nwhere $m$ is a positive real number. Here $\\psi(x,t)$ is a \\it wavefunction \\rm that describes the movement of a quantum mechanical matter wave with mass $m$. Much like the ordinary wave equation, the Schrodinger equation also admits traveling wave solutions of the form\r\n\r\n$$\\psi_{p}(x,t)=e^{ip\\left(x-\\frac{pt}{2m}\\right)},$$\r\n\r\nwhere $p\\in\\mathbb{R}$ is an arbitrary real number.\r\n\r\n\\begin{enumerate}[label=\\alph*)]\r\n\\item (3 pts) What is the dispersion relation for the wave solutions of the Schrodinger equation? Give a brief sketch.\r\n\r\n\r\n\\item (2 pts) What is the phase velocity of these traveling waves?\r\n\r\n\\item (3 pts) Let us consider beats formed using a superposition of different wave solutions with similar frequencies. Let $p_{0}$ be a given real number. Consider a superposition of the form\r\n\r\n$$\\xi(x,t)=\\psi_{p_{0}-\\Delta p}(x,t)+\\psi_{p_{0}}(x,t)+\\psi_{p_{0}+\\Delta p}(x,t),$$\r\n\r\nwhere $\\Delta p$ is some small number such that $\\Delta p\\ll p_{0}$. To linear order in $\\Delta p$, show that we have\r\n\r\n$$\\xi(x,t)=\\left(2\\cos\\left[\\left(x-\\frac{p_{0}}{m}t\\right)\\Delta p\\right]+1\\right)\\psi_{p_{0}}(x,t).$$\r\n\\\\\r\n\r\nThe previous result shows that, just like in the classical phenomenon of beats, a superposition of traveling matter waves with similar frequencies will give you an “envelope” function that modulates $\\psi_{k_{0}}$. A reasonable definition of the group velocity in this case would be the velocity of the envelope function.\r\n\r\n\r\n\\item (2 pts) What is the group velocity of the superposition? Does this match up with what you expected from your knowledge of group velocities for classical waves?\r\n\\\\\r\n\r\nAs an aside, the values of p actually correspond to the momentum of the quantum mechanical wave. With this interpretation, you may find your expression for the group velocity to be very familiar.\r\n\r\n% \\item (2 pts) Now consider these waves to be trapped in a box from $x=0$ to $x=L$. Inside the box, a right-moving wave will bounce off the wall to become a left-moving wave and vice versa. The waves inside the box must therefore be a general combination of a left-moving wave and a right-moving wave which will form a standing wave:\r\n%\r\n% $$f(x,t)=Ae^{ip\\left(x-\\frac{pt}{2m}\\right)}+Be^{-ip\\left(x+\\frac{pt}{2m}\\right)}.$$\r\n%\r\n% Since the particle cannot exit the box, quantum mechanics requires that the above superposition go to zero at the boundaries, i.e., $f(x=0,t)=0$ and $f(x=L,t)=0$. Up to an overall constant, find all the linear combinations which form valid quantum mechanical standing waves. What are the allowed values of $p$?\r\n\\end{enumerate}\r\n\r\n % Notice that the act of putting the waves into a box severely restricts the possible values of $p$ the standing wave is allowed to have. The previously unrestricted value of $p$ is now reduced to a discrete set of values. Thus we say that the act of restricting the wave \\it quantizes \\rm its momentum (and hence also energy). This is a very generic phenomenon in quantum mechanics.\r\n%\\end{document}\r\n", "meta": {"hexsha": "36b4e1ce0c4857bdb3c43d1395ff1328d09f20ff", "size": 3412, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Quizzes/Schrodinger_dispersion.tex", "max_stars_repo_name": "rxa254/VibrationsAndWaves", "max_stars_repo_head_hexsha": "347a25413921e3a8ffde9ece48dc357bd417239c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-20T05:11:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-20T05:11:53.000Z", "max_issues_repo_path": "Quizzes/Schrodinger_dispersion.tex", "max_issues_repo_name": "rxa254/VibrationsAndWaves", "max_issues_repo_head_hexsha": "347a25413921e3a8ffde9ece48dc357bd417239c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Quizzes/Schrodinger_dispersion.tex", "max_forks_repo_name": "rxa254/VibrationsAndWaves", "max_forks_repo_head_hexsha": "347a25413921e3a8ffde9ece48dc357bd417239c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.3773584906, "max_line_length": 385, "alphanum_fraction": 0.7291910903, "num_tokens": 895, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6596161867516039}}
{"text": "%!TEX root = main.tex\n\\paragraph{Fast multipole method}\n\nThe fast multipole method (\\fmm) is an algorithm that can reduce the quadratic time and space complexity of such matrix-vector multiplication down to $\\mathcal{O}(N)$.\nIn the context of \\fmm, $\\{\\mathbf{r}_i\\}$ and $\\{\\mathbf{r}_j'\\}$ in Equation \\ref{eq:nbody_sum} are often referred to as the set of targets and sources respectively, with $\\{q_j\\}$ representing the source densities (charges).\nThe goal of \\fmm is to efficiently compute the potential at $N$ targets $\\{s_i\\}$ induced by all $N$ sources and the kernel function $g$.\nFollowing the common notations in the literature, we use $\\mathbf{x}_i$ and $\\mathbf{y}_j$, instead of $\\mathbf{r}_i$ and $\\mathbf{r}_j'$, to denote targets and sources respectively in this subsection.\n\nThe \\fmm algorithm builds upon two fundamental ideas: (1) approximating the far-range interactions between distant clusters of sources and targets using low-rank methods, while computing the near-range interactions exactly, and (2) partitioning the domain using a tree structure to maximize the far-range portion in the computation.\n\nTo construct the octree, we first create a cube that encloses all sources/targets and then recursively subdivide the domain until each cube at the finest level only contains a constant number of points.\nFigure \\ref{fig:near_far_decomp} depicts a 3-level quadtree.\nThe potentials of targets in node $B$ consist of three contributions: the influence from sources in the near-field of $B$: $\\mathcal{N}(B)$, in the interaction list of $B$: $\\mathcal{I}(B)$, and in the rest of the domain.\n$B$'s near-field includes $B$ and its neighbors, where the interactions are computed exactly.\nThe remaining domain is in $\\mathcal{F}(B)$, $B$'s far-field.\nIn $\\mathcal{F}(B)$, the nodes that are the children of $B$'s parent's neighbors but are not adjacent to $B$ compose $\\mathcal{I}(B)$, the interaction list of $B$, whose contributions to $B$ are approximated by low-rank methods.\nThe contributions from the rest of the far-field are approximated at coarser levels via $B$'s ancestors.\n\nThe classic \\fmm \\cite{greengard1987fast, cheng1999fast} relies on truncated analytical expansions to approximate far-field interactions, whereas its kernel-independent variant \\cite{ying2004kernel} uses equivalent densities (charges) instead.\nIn \\kifmm, each node is associated with upward and downward equivalent densities (see Figure \\ref{fig:multipole} and \\ref{fig:local}), the analog of multipole and local expansions in the analytical \\fmm.\nThe upward equivalent densities $q^{B,u}$ are used to approximate the influence of sources in $B$ on targets in $\\mathcal{F}(B)$;\nthe downward equivalent densities $q^{B,d}$ are used to approximate the influence of sources in $\\mathcal{F}(B)$ on sources in $B$.\nTo find these densities, we match the potential of equivalent densities to the potential of actual sources at the check surfaces:\n%\n\\begin{align}\\label{eq:multipole_local}\n    \\sum_{\\mathbf{y}_{j} \\in B} g\\left(\\mathbf{x}_{i}^{B,u}, \\mathbf{y}_{j}\\right) q_{j} &= \\sum_{j} g\\left(\\mathbf{x}_{i}^{B,u}, \\mathbf{y}^{B,u}_{j}\\right) q^{B,u}_{j}, \\quad \\forall i  \\nonumber \\\\\n    \\sum_{\\mathbf{y}_{j} \\in \\mathcal{F}(B)} g\\left(\\mathbf{x}_{i}^{B,d}, \\mathbf{y}_{j}\\right) q_{j} &= \\sum_{j} g\\left(\\mathbf{x}_{i}^{B,d}, \\mathbf{y}^{B,d}_{j}\\right) q^{B,d}_{j}, \\quad \\forall i\n\\end{align}\n%\nWe then solve the linear systems for $\\{q^{B,u}_{j}\\}$ and $\\{q^{B,d}_{j}\\}$.\nHere, $\\mathbf{x}_{i}^{B}$ and $\\mathbf{y}_{j}^{B}$ denote the discretization points of the check surface and equivalent surface of $B$ respectively.\n\nThe algorithm also defines the following operators:\n%\n\\begin{itemize}\n    \\item particle-to-multipole (P2M): For a leaf node $B$, compute $B$'s upward equivalent densities, \\ie multipole expansion, from the sources in $B$. (Figure \\ref{fig:multipole})\n    \\item multipole-to-multipole (M2M): For a non-leaf node $B$, evaluate $B$'s multipole expansion based on the multipole expansions of all $B$'s children. (Figure \\ref{fig:translations} left)\n    \\item multipole-to-local (M2L): For a node $B$, evaluate $B$'s downward equivalent densities, \\ie local expansion, by using the multipole expansions of all nodes in $\\mathcal{I}(B)$. (Figure \\ref{fig:translations} middle)\n    \\item local-to-local (L2L): For a non-leaf node $B$, add the contribution of $B$'s local expansion to the local expansions of $B$'s children. (Figure \\ref{fig:translations} right)\n    \\item local-to-particle (L2P): For a leaf node $B$, evaluate $B$'s local expansion at the locations of targets in $B$.\n    This step adds all far-field contribution to the potentials of targets in $B$. \n    \\item particle-to-particle (P2P): For a leaf node $B$, evaluate the potential induced by all sources in $\\mathcal{N}(B)$ directly.\n\\end{itemize}\n%\nAs indicated by the arrows in Figure \\ref{fig:translations}, translation operators in \\kifmm share the same procedure: (1) evaluating the potentials on the check surface, and (2) solving the equation arising from matching the potentials for the equivalent densities.\n\nFigure \\ref{fig:fmm_sketch} outlines the complete \\fmm algorithm.\nDuring the upward pass, we compute P2M at all leaf nodes and perform M2M in post-order tree traversal.\nNext, we compute M2L for all nodes.\nFinally, we compute L2L in pre-order tree traversal, and perform L2P and P2P at all leaf nodes during the downward pass.\n\n\\begin{figure*}\n\\centering\n    \\subfloat[][A 3-level quadtree.]{\\includegraphics[width=0.35\\textwidth]{near_far_decomposition.pdf}\n        \\label{fig:near_far_decomp}}\n    \\subfloat[][Sketch of FMM algorithm using a binary tree.]{\\includegraphics[width=0.6\\textwidth]{fmm_sketch.pdf}\n        \\label{fig:fmm_sketch}}\\\\\n    \\subfloat[][]{\\includegraphics[width=0.4\\textwidth]{multipole_expansion.pdf}\n        \\label{fig:multipole}}\n   \\subfloat[][]{\\includegraphics[width=0.4\\textwidth]{local_expansion.pdf}\n        \\label{fig:local}}\\\\\n\\subfloat[][]{\\includegraphics[width=\\textwidth]{translations.pdf}\n        \\label{fig:translations}}\n    \\caption{Illustrations of the \\fmm algorithm.\n    \\textbf{c},\\textbf{d}, Multipole and local expansion in \\kifmm.\n    \\textbf{e}, M2M (left), M2L (middle) and L2L (right) operators in \\kifmm. Node $C$ is the parent of $B$, and node $A$ is in the interaction list of $B$.\n    }\n\\end{figure*}\n\nThe original Exafmm \\cite{yokota2012tuned,yokota2013fmm} implements the classical \\fmm based on dual tree traversal and focuses on low-accuracy optimizations.\nRecently, Exafmm received a major update to adopt \\kifmm due to its great extensibility.\nIts current generation, Exafmm-t \\cite{Wang2021}, offers highly optimized \\kifmm operators, allows pre-computing and caching invariant matrices and more importantly, provides a high-level Python interface to reach a broader audience.", "meta": {"hexsha": "1c683ae0f556f1b3d42c0f26fefaab09ea4f8744", "size": 6853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/methods_exafmm.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/methods_exafmm.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/methods_exafmm.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": 95.1805555556, "max_line_length": 332, "alphanum_fraction": 0.7406975047, "num_tokens": 1895, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242132, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6595645517119662}}
{"text": "\\documentclass{beamer}\n\n\\input{beamer-config.tex}\n\n\\input{required-packages.tex}\n\n\\input{font-config.tex}\n\n\\input{custom-commands.tex}\n\n\\input{math-ops.tex}\n\n\\input{tikz-config.tex}\n\n\\input{theorem-config.tex}\n\n\n\\title{\n    \\Subtitle{COMP0005 Algorithms}  \\\\\n    {\\huge\\itshape Graphs}                  \\\\\n}\n\\author{Jieyou Xu}\n\\date{\\today}\n\n\n\\begin{document}\n\\frame{\\titlepage}\n\n\\section{Introduction to Graphs}\n\n\\begin{frame}{Undirected Simple Graph}\n    An \\Keyword{undirected simple graph} $G$ is a two-tuple\n    \\begin{equation}\n        G = (V, E)\n    \\end{equation}\n    Where\n    \\begin{enumerate}\n        \\item $V$ is the set of \\Keyword{vertices} (or \\Keyword{nodes}, \\Keyword{points})\n        \\item $E$ is the set of \\Keyword{edges} (or \\Keyword{links}) where each \\Keyword{edge} connects two \\Keyword{vertices}\n        \\begin{itemize}\n            \\item Not allowing \\textit{self-loops}:\n            \\begin{equation}\n                E \\subseteq \\set{(x, y) \\mid (x, y) \\in V^2 \\land x \\ne y}\n            \\end{equation}\n            \\item Allowing \\textit{self-loops}:\n            \\begin{equation}\n                E \\subseteq \\set{(x, y) \\mid (x, y) \\in V^2}\n            \\end{equation}\n        \\end{itemize}\n    \\end{enumerate}\n\\end{frame}\n\n\\begin{frame}\n    No \\textit{self-loops}\n    \\begin{figure}[H]\n        \\centering\n        \\begin{equation*}\n            \\psmatrix[colsep=2em, rowsep=1em, mnode=circle, linewidth=0.5pt]\n                x & y\n                \\ncline{-}{1, 1}{1, 2}\n            \\endpsmatrix\n        \\end{equation*}\n    \\end{figure}\n    \n    Allowing \\textit{self-loops}\n    \\begin{figure}[H]\n        \\centering\n        \\begin{equation*}\n            \\psmatrix[colsep=2em, rowsep=1em, mnode=circle, linewidth=0.5pt]\n                x & y\n                \\ncline{-}{1, 1}{1, 2}\n                \\nccircle{-}{1, 2}{1em}\n            \\endpsmatrix\n        \\end{equation*}\n    \\end{figure}\n\\end{frame}\n\n\\begin{frame}{Directed Simple Graph}\n    A \\Keyword{directed simple graph} $G$ is a \\textit{graph} in which \\textit{edges} have orientation\n    \\begin{equation}\n        G = (V, A)\n    \\end{equation}\n    Where\n    \\begin{enumerate}\n        \\item $V$ is the set of \\Keyword{vertices} (or \\Keyword{nodes}, \\Keyword{points})\n        \\item $A$ is the set of \\Keyword{directed edges} where each \\Keyword{edge} connects two vertices with a \\Keyword{direction}\n    \\end{enumerate}\n\\end{frame}\n\n\\begin{frame}{Directed Edge}\n    In a \\Keyword{directed simple graph}, each \\Keyword{edge} $(x, y)$ connects \\textit{vertex} $x \\to y$.\n    \\begin{figure}[H]\n        \\centering\n        \\begin{equation*}\n            \\psmatrix[colsep=2em, rowsep=1em, mnode=circle, linewidth=0.5pt]\n                x & y\n                \\ncline{->}{1, 1}{1, 2}\n            \\endpsmatrix\n        \\end{equation*}\n    \\end{figure}\n    For the \\Keyword{directed edge} $(x, y)$ from $x \\to y$\n    \\begin{itemize}\n        \\item $x$ is the \\Keyword{tail} of the edge\n        \\item $y$ is the \\Keyword{head} of the edge\n    \\end{itemize}\n    \n    The \\Keyword{edge} $(y, x)$ is the \\Keyword{inverted edge} of $(x, y)$\n    \\begin{figure}[H]\n        \\centering\n        \\begin{equation*}\n            \\psmatrix[colsep=2em, rowsep=1em, mnode=circle, linewidth=0.5pt]\n                x & y\n                \\ncline{->}{1, 2}{1, 1}\n            \\endpsmatrix\n        \\end{equation*}\n    \\end{figure}\n\\end{frame}\n\n\\begin{frame}{Directed Edge}\n    It is also possible for a \\textit{loop} (or \\textit{cycle}) to form between nodes\n    \\begin{figure}[H]\n        \\centering\n        \\begin{equation*}\n            \\psmatrix[colsep=2em, rowsep=1em, mnode=circle, linewidth=0.5pt]\n                x & y\n                \\ncarc[arcangle=45]{->}{1, 1}{1, 2}\n                \\ncarc[arcangle=45]{->}{1, 2}{1, 1}\n            \\endpsmatrix\n        \\end{equation*}\n    \\end{figure}\n\\end{frame}\n\n\\end{document}\n", "meta": {"hexsha": "b90fd465378f4aacff31050b846d93cadc13408c", "size": 3862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "graph/graph.tex", "max_stars_repo_name": "jieyouxu/COMP0005-Algorithms-Notes", "max_stars_repo_head_hexsha": "9f10d8b0a107098fa21ad0977eec50071c52f1b0", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "jieyouxu/COMP0005-Algorithms-Notes", "max_issues_repo_head_hexsha": "9f10d8b0a107098fa21ad0977eec50071c52f1b0", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "jieyouxu/COMP0005-Algorithms-Notes", "max_forks_repo_head_hexsha": "9f10d8b0a107098fa21ad0977eec50071c52f1b0", "max_forks_repo_licenses": ["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.8208955224, "max_line_length": 131, "alphanum_fraction": 0.5605903677, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540518, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.6595518920556122}}
{"text": "\\chapter{Adaptive Resonance Theory}\nART networks are self-organizing networks that have been able to solve the \\emph{stability-plasticity} dilemma. ART able to \\emph{switch modes} between plastic and stable without damage to previous learned weight values.\n\n\\begin{description}\n\\item[Stability-plasticity dilemma] not able to learn new information on top of old\n\\item[Plasticity] for the integration of new knowledge\n\\item[Stability] to prevent the forgetting of previous knowledge\n\\end{description}\n\n\\section{ART-1}\nDesigned to cluster and recognize binary patterns only.\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=8cm]{chapter10_1}\n\\end{figure}\n\n\\noindent The feed-forward weight matrix is:\n$$\\mathbf{W} = [\\mathbf{w}_1 \\mathbf{w}_2 \\ldots \\mathbf{w}_M]^{T}$$\nThe feedback weight vector is:\n$$\\mathbf{V} = [\\mathbf{v}_1 \\mathbf{v}_2 \\ldots \\mathbf{v}_N]^{T}$$\nThe feed-forward weight is proportional to the corresponding feedback weight value:\n$$w_{ji} \\propto v_{ij}$$\n\\begin{center} where $v_{ij} \\in {0,1}$ and $w_{ji} \\in [0,1]$\\end{center}\nOutput layer is a \\emph{winner-take-all} layer\n\n\\subsubsection{Control Signals of the Network}\n$$\ncontrol1 = \n\\begin{cases}\n0 & comparison\\ mode \\\\\n1 & input\\ mode\n\\end{cases}\n$$\n\n$$\ncontrol2 = \n\\begin{cases}\n0 & failed\\ vigilance\\ test \\\\\n1 & satisfied\\ vigilance\\ test\n\\end{cases}\n$$\n\n\\subsubsection{Vigilance Test}\nSimilarity between input pattern $\\mathbf{X}$ and feedback pattern $\\mathbf{V}_j$:\n$$s_j = \\frac{|\\mathbf{X} \\cap \\mathbf{V}_j|}{| \\mathbf{X} |}$$\nVigilance test is satisfied if $s_j$ is greater than vigilance value $\\rho$\n\n\\section{ART-1 Algorithm}\n\\subsubsection{Step 1: Initialization}\nInitialize vigilance threshold $\\rho$, feed-forward weights $w_{ij}$, and feedback weights $v_{j1}$:\n$$0 \\le \\rho \\le 1$$\n$$w_{ij} = \\frac{1}{1+N}$$\n$$v_{ji} = 1$$\n\\subsubsection{Step 2: The total synaptic input}\n\\begin{equation*}\n\\begin{split}\n\\mathbf{u}_j &= \\sum_{i=1}^{n} w_{ji} x_i \\\\\n&= \\frac{|\\mathbf{V}_j \\cap \\mathbf{X}|}{0.5 + |\\mathbf{V}_j|} \\\\\n& \\propto | \\mathbf{V}_j \\cap \\mathbf{X}_i |\n\\end{split}\n\\end{equation*}\n\\begin{center}Since $w_{ji} \\propto v_{ij}$ \\end{center}\n\n\\subsubsection{Step 3: The winner $m$}\n$$m = arg\\!\\max_{j=1...M} u_j\\ for\\ y_j \\ne 0$$\nThe output\n$$\ny_j = \n\\begin{cases}\n1 & j = m \\\\\n0 & j \\ne m\n\\end{cases}\n$$\n\\subsubsection{Step 4: Calculate similarity}\n$$s_j = \\frac{|\\mathbf{X} \\cap \\mathbf{V}_m |}{| \\mathbf{X} |}$$\nIf $s \\ge \\rho$, go to step 5. \\\\\nElse if the top-later has any active nodes left, go to step 6. \\\\\nElse, go to step 5 to create a new cluster.\n\\subsubsection{Step 5: Update the weights of winning node}\n$$\\mathbf{V}_m^{new} = \\mathbf{V}_m \\cap \\mathbf{X}$$\n$$\\mathbf{w}_m^{new} = \\frac{\\mathbf{V}_m^{new}}{0.5 + | \\mathbf{V}_m^{new} |}$$\nGo to step 2.\n\\subsubsection{Step 6: Continue search}\nSetting output $y_m = 0$. \\\\\nGo to step 3 to find a new winner $m$\n", "meta": {"hexsha": "ef9fff8bc6022c5e863bc89b6bb4fda2d02c2665", "size": 2882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter10.tex", "max_stars_repo_name": "Andyccs/neural-network-summary", "max_stars_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter10.tex", "max_issues_repo_name": "Andyccs/neural-network-summary", "max_issues_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter10.tex", "max_forks_repo_name": "Andyccs/neural-network-summary", "max_forks_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.511627907, "max_line_length": 220, "alphanum_fraction": 0.6908396947, "num_tokens": 1020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6595518746351706}}
{"text": "\\chapter{}\n\n\\rmk{1} We follow the convention that the derivative with respect to a vector is the transpose of the gradient, the latter being a row vector. Wherever present, the acronym CRLB stands for “Cramer-Rao lower bound”. \n\n\\begin{ex} \\label{ex:5.1}\n    For an underlying parametric family $\\{f(x|\\theta)\\}_{\\theta\\in\\Theta}$, let $\\theta=H(\\xi)$ be a reparametrization, where $H(\\cdot)$ is differentiable and injective in a vicinity of $\\xi$. Show that \n    \\[\n        I(\\xi)=I(H(\\xi))[H'(\\xi)]^2. \n    \\]\n    \\emph{Hint:} since\\[\n        I(\\xi)=\\mathbb{E}\\left(\\frac{\\pder}{\\pder \\xi}\\log f(x|H(\\xi))\\right)^2, \n    \\]\n    you can use the chain rule. \n\\end{ex}\n\n\\begin{solution}\n    \\[\n        \\begin{aligned}\n            I(\\xi)&=\\mathbb{E}\\left(\\frac{\\pder \\log f(x|H(\\xi))}{\\pder \\xi}\\right)^2\\\\\n            &=\\mathbb{E}\\left(\\frac{\\pder \\log f(x|H(\\xi))}{\\pder H(\\xi)}\\cdot\\frac{\\pder H(\\xi)}{\\pder \\xi}\\right)^2\\\\\n            &=\\mathbb{E}\\left[\\left(\\frac{\\pder \\log f(x|H(\\xi))}{\\pder H(\\xi)}\\right)^2\\cdot\\left(\\frac{\\pder H(\\xi)}{\\pder \\xi}\\right)^2\\right]\\\\\n            &=\\mathbb{E}\\left(\\frac{\\pder \\log f(x|H(\\xi))}{\\pder H(\\xi)}\\right)^2\\cdot\\left(\\frac{\\pder H(\\xi)}{\\pder \\xi}\\right)^2\\\\\n            &=I(H(\\xi))[H'(\\xi)]^2. \n        \\end{aligned}\n    \\]\n\\end{solution}\n\n\\begin{ex} \\label{ex:5.2}\n    In this problem, we finish a proof we started in class. Consider the following setting. \n    \\begin{enumerate}[(i)]\n        \\item $\\mathcal{P}=\\{\\mathbb{P}_\\theta\\}_{\\theta\\in\\Theta}$, 1-dimensional exponential family generated by $(T,h)$, $\\mathbf{X}\\sim \\mathcal{P}$, i.e., \n        \\[\n            f(\\mathbf{x|\\theta})=h(\\mathbf{x})\\exp\\left(H(\\theta)T(\\mathbf{x})-B(\\theta)\\right); \n        \\]\n        \\item $\\tau(\\theta):=\\mathbb{E}_\\theta T(\\mathbf{X})$, $\\eta=H(\\theta)\\in\\mathcal{E}$; \n        \\item the parameter functions $\\theta\\mapsto B(\\theta), \\tau(\\theta), H(\\theta)$ are, respectively, $C^1, C^1$ and $C^2$ in a\n        vicinity of the true parameter value $\\theta$ and satisfy $|\\tau'(\\theta)H'(\\theta)H''(\\theta)|>0$; \n        \\item $\\Theta$ is open in $\\mathbb{R}$. \n    \\end{enumerate}\n    \\begin{enumerate}[(a)]\n        \\item Prove that\n        \\[\n        \\tau(\\theta):=\\mathbb{E}_{\\theta} T(\\mathbf{X})=\\frac{B^{\\prime}(\\theta)}{H^{\\prime}(\\theta)}, \\quad  Var_{\\theta} T(\\mathbf{X})=\\frac{B^{\\prime \\prime}(\\theta)}{\\left(H^{\\prime}(\\theta)\\right)^{2}}-\\frac{\\eta^{\\prime \\prime}(\\theta) B^{\\prime}(\\theta)}{\\left(H^{\\prime}(\\theta)\\right)^{3}}=\\frac{B^{\\prime \\prime}(\\theta)-\\eta^{\\prime \\prime}(\\theta) \\tau(\\theta)}{\\left(\\eta^{\\prime}(\\theta)\\right)^{2}}\n        \\]\n        You may assume that\n        \\[\n            \\frac{\\partial}{\\partial \\theta} \\int_{\\mathbb{R}} f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x})=\\int_{\\mathbb{R}} \\frac{\\partial}{\\partial \\theta} f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x}), \n        \\]\n        \\[\n            \\frac{\\partial^{2}}{\\partial \\theta^{2}} \\int_{\\mathbb{R}} f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x})=\\int_{\\mathbb{R}} \\frac{\\partial^{2}}{\\partial \\theta^{2}} f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x}). \n        \\]\n        \\item Conclude that \\(Var_{\\theta} T(\\mathbf{X})\\) attains the CRLB, i.e.,\n        \\[\n         Var_{\\theta} T(\\mathbf{X})=\\frac{1}{I(\\tau(\\theta))}\n        \\]\n        Also conclude that, almost surely, it is the only unbiased estimator of \\(\\tau(\\theta)\\) to do so.\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item \\label{ex:5.2.a} Let $\\theta=H^{-1}(\\eta)$, then \n        \\[\n            \\mathbb{E}_\\theta T(X) = A'(\\eta) =\\frac{\\pder B(H^{-1}(\\eta))}{\\pder \\eta}=B'(H^{-1}(\\eta))\\frac{1}{H'(\\theta)}=\\frac{B'(\\theta)}{H'(\\theta)}. \n        \\]\n        \\[\n            \\begin{aligned}\n                Var_\\theta T(X)&=A''(\\eta)\\\\\n                &=\\left(\\frac{B'(H^{-1}(\\eta))}{H'(H^{-1}(\\eta))}\\right)'\\\\\n                &=\\frac{B''(H^{-1}(\\eta))(H^{-1}(\\eta))'}{H'(H^{-1}(\\eta))}-\\frac{B'(H^{-1}(\\eta))H''(H^{-1}(\\eta))(H^{-1}(\\eta))'}{\\left(H'(H^{-1}(\\eta))\\right)^2}\\\\\n                &=\\frac{B''(\\theta)}{(H'(\\theta))^2}-\\frac{B'(\\theta)H''(\\theta)}{(H'(\\theta))^3}\\\\\n                &=\\frac{B''(\\theta)-\\eta''(\\theta)\\tau(\\theta)}{(\\eta'(\\theta))^2}. \n            \\end{aligned}\n        \\]\n        \\item \\[\n            I(\\theta)=Var_\\theta\\left(\\frac{f'(\\mathbf{x|\\theta})}{f(\\mathbf{x|\\theta})}\\right)=Var_{\\theta}(\\eta'(\\theta)T(\\mathbf{x})-B'(\\theta))=Var_\\theta(T(\\mathbf{x}))(\\eta'(\\theta))^2. \n        \\]\n        Then from Exercise \\ref{ex:5.1}, \n        \\begin{equation}\n            I(\\tau(\\theta))=\\frac{I(\\theta)}{(\\tau'(\\theta))^2}=\\left[\\frac{\\eta'(\\theta)}{\\tau'(\\theta)}\\right]^2Var_\\theta T(\\mathbf{x}). \n            \\label{eq:5.2.1}\n        \\end{equation}\n        And from Exercise \\ref{ex:5.2} \\ref{ex:5.2.a},\n        \\[\n            Var_\\theta T(X)=\\frac{B''(\\theta)-\\eta''(\\theta)\\tau(\\theta)}{(\\eta'(\\theta))^2}, \\qquad \\tau(\\theta)=\\frac{B'(\\theta)}{\\eta'(\\theta)}. \n        \\]\n        \\[\n            \\tau'(\\theta)=\\frac{B''(\\theta)-\\tau(\\theta)\\eta''(\\theta)}{\\eta'(\\theta)}, \n        \\]\n        and \\[\n            \\frac{\\tau'(\\theta)}{\\eta'(\\theta)}=Var_\\theta T(X).\n        \\]\n        So, \n        \\[\n            I(\\tau(\\theta))=\\left[\\frac{\\eta'(\\theta)}{\\tau'(\\theta)}\\right]^2Var_\\theta T(\\mathbf{x})=\\frac{\\eta'(\\theta)}{\\tau'(\\theta)}=\\frac{1}{Var_\\theta T(\\mathbf{x})}. \n        \\]\n        If a statistic $\\delta$ can attain the lower bond, then it can be written as following form: \n        \\[\n           \\delta=a\\left(\\eta'(\\theta)T(X)-B'(\\theta)\\right)+b.\n        \\]\n        And if $\\mathbb{E}(\\delta)=\\tau(\\theta)$, $Var_\\theta(\\delta)=\\frac{(\\tau'(\\theta))^2}{I(\\theta)}$. Solve them, we can get that $a=1/H'(\\theta)$, $b=\\tau(\\theta)$. So, the statistic can only be $T(X)$. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Complete the following table: \n    \\begin{center}\n        \\begin{tabular}{ccc}\n            \\hline\n            distribution & parameter $\\tau(\\theta)$ & $I(\\tau(\\theta))$ \\\\ \\hline\n            $\\mathcal{N}(\\mu, \\sigma^2)$ & $\\mu$ &  \\\\\n            $\\mathcal{N}(\\mu, \\sigma^2)$ & $\\sigma^2$ &  \\\\\n            $B(n,p)$ & $p$ &  \\\\\n            $Poi(\\lambda)$ & $\\lambda$ &  \\\\\n            $\\Gamma(\\alpha, \\lambda)$ & $\\beta=\\lambda^{-1}$ &  \\\\\n            \\hline\n            \\end{tabular}\n    \\end{center}\n\\end{ex}\n\n\\begin{solution}\n    In order to simplify the problem, we only calculate the 1-dimension case: \n    \\begin{itemize}\n        \\item \\[\n            p_\\mu(x)=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-1/2\\sigma^2(x^2-2\\mu x+\\mu^2)\\right), \n        \\]\n        Then \n        \\[\n            h(x)=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-x^2/2\\sigma^2\\right), \\eta(\\mu) T(x)-B(\\mu)=\\frac{\\mu}{\\sigma^2}x-\\frac{\\mu^2}{2\\sigma^2}. \n        \\] \n        So, if $h(\\mu)=\\mu$, from \\ref{eq:5.2.1}, \n        \\[\n            I(\\mu)=\\left(\\frac{\\eta'(\\mu)}{h'(\\mu)}\\right)^2Var(T(X))=\\frac{1}{\\sigma^4}\\sigma^2=1/\\sigma^2. \n        \\]\n        \\item \\[\n        \\begin{aligned}\n            \\mathcal{L}_\\sigma&=\\log\\left(\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-1/2\\sigma^2(x-\\mu)^2\\right)\\right)\\\\\n            &=-\\frac{1}{2}\\left(x-\\mu\\right)^2\\sigma^{-2}-\\log(\\sqrt{2\\pi}\\sigma)\n        \\end{aligned}\n        \\]\n        \\[\n            \\mathcal{L}'_\\sigma = \\left(x-\\mu\\right)^2\\sigma^{-3}-\\sigma^{-1}, \n        \\]\n        \\[\n            \\mathcal{L}''_\\sigma = -3\\left(x-\\mu\\right)^2\\sigma^{-4}+\\sigma^{-2}, \n        \\]\n        Then $E(X)=\\mu$, $E(X^2)=Var(X)+(EX)^2=\\sigma^2+\\mu^2$, \n        \\[\n            I(\\sigma)=-E(\\mathcal{L''_\\sigma})=2\\sigma^{-2}. \n        \\]\n        \\[\n            I(\\sigma^2)=\\frac{I(\\sigma)}{(2\\sigma)^2}=\\frac{1}{2\\sigma^4}. \n        \\]\n        \\item \\[\n            f_p(x)=\\binom{n}{x}p^x(1-p)^{n-x}=\\binom{n}{x}\\exp\\left(x\\log(p)-x\\log(1-p)+n\\log(1-p)\\right), \n        \\]\n        $\\eta(p)T(x)-B(p)=\\log\\frac{p}{1-p}x-n\\log\\frac{1}{1-p}$, \n        \\[\n            I(np)=\\left(\\frac{\\eta'(p)}{n}\\right)^2Var(T(X))=\\left(\\frac{1}{np(1-p)}\\right)^2np(1-p)=\\frac{1}{np(1-p)}. \n        \\]\n        \\[\n            I(p)=\\frac{I(np)}{1/n^2}=\\frac{n}{p(1-p)}. \n        \\]\n        \\item For Poisson distribution, $\\eta(\\lambda)=\\log \\lambda$, $T(x)=x$, $E(x)=Var(x)=\\lambda$. So, \n        \\[\n            I(\\lambda)=\\frac{1}{\\lambda^2}\\lambda=1/\\lambda. \n        \\]\n        \\item For Gamma distribution, $\\eta(\\lambda)=-\\lambda$, $T(x)=x$, $E(x)=\\alpha/\\lambda$, $Var(x)=\\alpha/\\lambda^2$. So,\n        \\[\n            I(\\alpha\\beta)=\\left(\\frac{1}{-\\alpha/\\lambda^2}\\right)^2\\frac{\\alpha}{\\lambda^2}=\\lambda^2/\\alpha=\\frac{1}{\\alpha\\beta^2}, \n        \\]\n        So, \\[\n            I(\\beta)=\\frac{I(\\alpha\\beta)}{(1/\\alpha)^2}=\\frac{\\alpha}{\\beta^2}. \n        \\]\n    \\end{itemize}\n\\end{solution}\n\n\\begin{ex}\n    Let $X\\sim \\Gamma(\\alpha_0, \\lambda)$, $\\lambda>0$, where $\\alpha_0$ is known. We see in the class that $I(\\alpha_0/\\lambda)=\\lambda^2/\\alpha_0$. Use this result to find $I(1/\\lambda)$. \n\\end{ex}\n\n\\begin{solution}\n    Let $\\xi=\\alpha_0/\\lambda$, $\\theta=H(\\xi)=\\frac{1}{\\alpha_0}\\xi=1/\\lambda$. Then\n    \\[\n        I(1/\\lambda)=I(\\theta)=\\frac{I(\\xi)}{(H'(\\xi))^2}=\\frac{\\lambda^2}{\\alpha_0}\\alpha_0^2=\\alpha_0\\lambda^2. \n    \\]\n\\end{solution}\n\n\\begin{ex}\n    Let \\(X \\sim \\mathcal{N}\\left(\\mu, \\sigma_{0}^{2}\\right), \\mu>0\\), where \\(\\sigma_{0}^{2}>0\\) is known. \n    \\begin{enumerate}[(a)]\n        \\item Find \\(I\\left(\\mu / \\sigma_{0}^{2}\\right)\\) (hint: no calculations needed). \n        \\item Use the result in (a) to compute \\(I\\left(\\mu^{2}\\right)\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item From previous problem, $\\eta(\\mu)=\\mu$, $T(X)=x/\\sigma^2$. And $E(T(X))=\\mu/\\sigma^2$, $Var(T(X))=1/\\sigma^2$. So, \n        \\[\n            I(\\mu/\\sigma^2)=\\left(\\frac{1}{1/\\sigma^4}\\right)1/\\sigma^2=\\sigma^2. \n        \\]\n        \\item Let $\\theta=\\mu/\\sigma^2$, $h(\\theta)=\\sigma^4\\theta^2=\\mu^2$. So, \n        \\[\n            I(h(\\theta))=\\frac{I(\\theta)}{(h'(\\theta))^2}=\\frac{\\sigma^2}{4\\sigma^4\\mu^2}=\\frac{1}{4\\sigma^2\\mu^2}. \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Prove the lemma stated in class. \n    \\begin{enumerate}[(i)]\n        \\item Suppose that the conditions A-(a),(b),(c) hold, and that\n        \\[\n        \\frac{\\partial}{\\partial \\theta} \\int_{\\mathbb{R}^{n}} f(\\boldsymbol{x} \\mid \\theta) G(d \\boldsymbol{x})=\\int_{\\mathbb{R}^{n}} \\frac{\\partial}{\\partial \\theta} f(\\boldsymbol{x} \\mid \\theta) G(d \\boldsymbol{x}), \\quad \\theta \\in \\Theta .\n        \\]\n        Then,\n        \\[\n        \\mathbb{E}_{\\theta}\\left(\\frac{\\partial}{\\partial \\theta} \\log f(\\boldsymbol{X} \\mid \\theta)\\right)=0, \\quad I(\\theta)= Var_{\\theta}\\left(\\frac{\\partial}{\\partial \\theta} \\log f(\\boldsymbol{X} \\mid \\theta)\\right). \n        \\]\n        \\item If, in addition,\n        \\[\n        \\begin{gathered}\n        \\exists \\frac{\\partial^{2}}{\\partial \\theta^{2}} \\log f(\\boldsymbol{x} \\mid \\theta), \\quad x \\in \\operatorname{supp} f(\\boldsymbol{x} \\mid \\theta), \\\\\n        \\frac{\\partial^{2}}{\\partial \\theta^{2}} \\int_{\\mathbb{R}^{n}} f(\\boldsymbol{x} \\mid \\theta) G(d \\boldsymbol{x})=\\int_{\\mathbb{R}^{n}} \\frac{\\partial^{2}}{\\partial \\theta^{2}} f(\\boldsymbol{x} \\mid \\theta) G(d \\boldsymbol{x}),\n        \\end{gathered}\n        \\]\n        for \\(\\theta \\in \\Theta\\), then,\n        \\[\n        I(\\theta)=-\\mathbb{E}_{\\theta}\\left(\\frac{\\partial^{2}}{\\partial \\theta^{2}} \\log f(\\boldsymbol{X} \\mid \\theta)\\right). \n        \\]\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(i)]\n        \\item \\[\n            \\begin{aligned}\n                E  \\left[\\left.{\\frac {\\partial }{\\partial \\theta }}\\log f(X|\\theta )\\right|\\theta \\right]={}&\\int _{\\mathbb {R} }{\\frac {{\\frac {\\partial }{\\partial \\theta }}f(X|\\theta )}{f(X|\\theta )}}f(X|\\theta )\\der x\\\\[3pt]={}&{\\frac {\\partial }{\\partial \\theta }}\\int _{\\mathbb {R} }f(X|\\theta )\\der x\\\\[3pt]={}&{\\frac {\\partial }{\\partial \\theta }}1=0.\n            \\end{aligned}\n        \\]\n        \\[\n            \\begin{aligned}\n                I(\\theta)&=E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2\\\\\n                &=E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)- E  \\left[{\\frac {\\partial }{\\partial \\theta }}\\log f(X|\\theta )\\right]\\right)^2\\\\\n                &=Var\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)\n            \\end{aligned}\n        \\]\n        \\item \\[\n            \\begin{aligned}\n                \\frac {\\partial ^{2}}{\\partial \\theta ^{2}}\\log f(X|\\theta )&=\\frac{\\pder}{\\pder \\theta}\\left(\\frac{f'(X|\\theta)}{f(X|\\theta)}\\right)\\\\\n                &=\\frac{\\frac{\\pder^2}{\\pder\\theta^2}f(X|\\theta)}{f(X|\\theta)}-\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2\n            \\end{aligned}\n        \\]\n        and\n        \\[\n            E \\left[{\\frac {{\\frac {\\partial ^{2}}{\\partial \\theta ^{2}}}f(X|\\theta )}{f(X|\\theta )}}\\right]=\\int_{\\mathbb{R}}{\\frac {{\\frac {\\partial ^{2}}{\\partial \\theta ^{2}}}f(X|\\theta )}{f(X|\\theta )}}f(X|\\theta )\\der x={\\frac {\\partial ^{2}}{\\partial \\theta ^{2}}}\\int _{\\mathbb {R} }f(X|\\theta )\\der x=0. \n        \\]\n        So, \\[\n            \\frac {\\partial ^{2}}{\\partial \\theta ^{2}}\\log f(X|\\theta )=-\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2, \n        \\]\n        \\[\n            E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2=-E\\left(\\frac {\\partial ^{2}}{\\partial \\theta ^{2}}\\log f(X|\\theta )\\right). \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Consider the following lemma. Assume that \n    \\begin{enumerate}[(a)]\n        \\item \\(\\Theta\\) is an open interval; \n        \\item  \\(A:=\\{x ; f(x \\mid \\theta)>0\\}\\) is independent of \\(\\theta\\); \n        \\item \\(\\delta(X) \\in \\Delta\\). \n    \\end{enumerate}\n    Let \\(\\psi(x \\mid \\theta)=\\frac{\\partial}{\\partial \\theta} \\log f(x \\mid \\theta)\\), assumed to exist at every pair \\(x, \\theta\\). For some \\(\\varepsilon>0\\), let \\(b_{\\theta}\\) be a function that satisfies\n    \\[\n    \\begin{aligned}\n    \\mathbb{E}_{\\theta} b_{\\theta}^{2}(X) &<\\infty \\\\\n    \\left|\\frac{1}{\\Delta} \\frac{f(x \\mid \\theta+\\Delta)-f(x \\mid \\theta)}{f(x \\mid \\theta)}\\right| & \\leq b_{\\theta}(x) \\quad \\text { if }|\\Delta|<\\varepsilon .\n    \\end{aligned}\n    \\]\n    Then,\n    \\[\n    \\mathbb{E}_{\\theta} \\psi(X, \\theta)=0\n    \\]\n    and\n    \\[\n    \\frac{\\partial}{\\partial \\theta} \\mathbb{E}_{\\theta} \\delta(X)=\\mathbb{E}_{\\theta}(\\delta(X) \\psi(X, \\theta))= Cov_{\\theta}(\\delta, \\psi)=\\int \\delta(x) \\frac{\\partial}{\\partial \\theta} \\log f(x \\mid \\theta) G(d x)\n    \\]\n    (and thus the \\(C R L B\\) is \\(\\left(\\frac{\\partial}{\\partial \\theta} \\mathbb{E}_{\\theta}(\\delta)\\right)^{2} / I(\\theta)\\)).\n\n    Assume \\(f\\) is the density of a Cauchy \\((0,1)\\) random variable, and consider the location family associated with\n    \\[\n    f(x-\\theta)=\\frac{1}{\\pi} \\frac{1}{1+(x-\\theta)^{2}}, \\quad \\theta \\in \\mathbb{R} .\n    \\]\n    Use the above lemma to establish the information inequality for the family \\(\\{f(x-\\theta)\\}_{\\theta \\in \\mathbb{R}}\\). \n    \n    (suggestion: however clumsy the technical condition looks, this is an easy problem. For this location family, just show that\n    \\[\n    \\left|\\frac{1}{\\Delta} \\frac{f(x \\mid \\theta+\\Delta)-f(x \\mid \\theta)}{f(x \\mid \\theta)}\\right| \\leq 2+\\varepsilon\n    \\]\n    This can be done by expanding the left-hand side of the inequality. Now define\n    \\[\n    b_{\\theta}(X):=2+\\varepsilon,\n    \\]\n    and note that\n    \\[\n    \\mathbb{E}_{\\theta} b_{\\theta}^{2}(X)<\\infty\n    \\]\n    By using the lemma above, conclude that the information inequality holds for any estimator \\(\\delta(X)\\) such that \\(\\left.\\mathbb{E}_{\\theta} \\delta^{2}(X)<\\infty\\right)\\)\n\\end{ex}\n\n\\begin{solution}\n    For Cauchy$(0,1)$, \n    \\begin{align*}\n        &\\quad\\,\\left|\\frac{1}{\\Delta} \\frac{f(x \\mid \\theta+\\Delta)-f(x \\mid \\theta)}{f(x \\mid \\theta)}\\right|  \\\\\n        &= \\left|\\frac{1}{\\Delta} \\frac{1+(x-\\theta)^2-1-(x-\\Delta-\\theta)^2}{1+(x-\\Delta-\\theta)^2}\\right|\\\\\n        &= \\left|\\frac{1}{\\Delta} \\frac{2\\Delta(x-\\theta)-\\Delta^2}{1+(x-\\Delta-\\theta)^2}\\right|\\\\\n        &= \\left|2\\frac{x-\\theta}{1+(x-\\Delta-\\theta)^2}-\\frac{\\Delta}{1+(x-\\Delta-\\theta)^2}\\right|\\\\\n        &= \\left|2\\frac{x-\\Delta-\\theta}{1+(x-\\Delta-\\theta)^2}+\\frac{\\Delta}{1+(x-\\Delta-\\theta)^2}\\right|\\\\\n        &\\leqslant2\\frac{|x-\\Delta-\\theta|}{1+(x-\\Delta-\\theta)^2}+\\frac{|\\Delta|}{1+(x-\\Delta-\\theta)^2}\\\\\n        &\\leqslant2+\\varepsilon. \n    \\end{align*}\n    Because $|x|<1+x^2$. Let $b(X)=2+\\varepsilon$, then $\\mathbb{E}b^2<\\infty$. So, the information inequality holds for any estimator $\\delta(X)$ with $\\mathbb{E}_{\\theta} \\delta^{2}(X)<\\infty$.\n    \\[\n        \\mathcal{L}'=\\frac{\\pder}{\\pder \\theta}\\log f(x)=-\\frac{2(x-\\theta)}{1+(x-\\theta)^2}, \n    \\]\n    \\[\n        \\begin{aligned}\n            E\\left(\\mathcal{L}'\\right)^2&=4E\\left(\\frac{x-\\theta}{1+(x-\\theta)^2}\\right)^2, \n        \\end{aligned}\n    \\]\n    \\[\n        \\begin{aligned}\n            E_{\\theta}\\left[\\frac{X-\\theta}{1+(X-\\theta)^2}\\right]^2\n            &=\\frac{1}{\\pi}\\int_{\\mathbb R}\\left[\\frac{x-\\theta}{1+(x-\\theta)^2}\\right]^2\\frac{1}{1+(x-\\theta)^2}\\der x\n            \\\\&=\\frac{1}{\\pi}\\int_{\\mathbb R}\\frac{(x-\\theta)^2}{(1+(x-\\theta)^2)^3}\\der x\\\\&=\\frac{2}{\\pi}\\int_0^\\infty\\frac{t^2}{(1+t^2)^3}\\der t\n            \\\\&=\\frac{1}{\\pi}\\int_0^\\infty\\frac{\\sqrt u}{(1+u)^3}\\der u\n            \\\\&=\\frac{1}{\\pi}B\\left(\\frac{3}{2},\\frac{3}{2}\\right)\n            \\\\&=\\frac{1}{8}\n        \\end{aligned}\n    \\]\n    So, $I(\\theta)=1/2$, \n    \\[\n        Var(\\delta)\\geqslant2\n    \\]\n\\end{solution}\n\n\\begin{ex}\n    The following theorem establishes a bound for the variance of an unbiased estimator in a multiparameter setting. \n\n    Suppose the following conditions hold. \n    \\begin{enumerate}[(i)]\n        \\item \\(\\delta(\\boldsymbol{X}) \\in \\Delta\\) : an \\(\\mathbb{R}\\)-valued unbiased estimator; \n        \\item \\(\\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta)\\) : an \\(\\mathbb{R}^{r}\\)-valued function with finite second moments; \n        \\item \\[\n        \\begin{aligned}\n            \\mathbb{R}^{r} \\ni \\gamma(\\theta) &= Cov_{\\theta}(\\delta(\\boldsymbol{X}), \\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta))\\\\\n            &:=\\mathbb{E}_{\\theta}\\left\\{\\left(\\delta(\\boldsymbol{X})-\\mathbb{E}_{\\theta} \\delta(\\boldsymbol{X})\\right)\\left(\\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta)-\\mathbb{E}_{\\theta}(\\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta))\\right)\\right\\};\n        \\end{aligned}\n        \\]\n        \\item \\[\n            \\begin{aligned}\n                C(\\theta) &= Cov_{\\theta}(\\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta), \\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta))\\\\\n                &:=\\mathbb{E}_{\\theta}\\left\\{\\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta)-\\mathbb{E}_{\\theta}(\\boldsymbol{X} \\mid \\theta)\\right\\}\\left\\{\\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta)-\\mathbb{E}_{\\theta} \\boldsymbol{\\Psi}(\\boldsymbol{X} \\mid \\theta)\\right\\}^T; \n            \\end{aligned}\n        \\]\n    \\end{enumerate}\n    Then,\n        \\[\n            Var_{\\theta} \\delta(\\boldsymbol{X}) \\geq \\gamma^T(\\theta) C^{-1}(\\theta) \\gamma(\\theta)\n        \\]\n    We will break up its proof into simple steps. \n        \\begin{enumerate}[(a)]\n            \\item Let \\(\\mathbf{a} \\in \\mathbb{R}^{r}\\). Show that \n            \\[\n                Var_{\\theta} \\delta(\\mathbf{X}) \\geq \\frac{\\left[ Cov_{\\theta}\\left(\\delta(\\mathbf{X}), \\mathbf{a}^T \\boldsymbol{\\Psi}(\\mathbf{X} \\mid \\theta)\\right)\\right]^{2}}{ Var_{\\theta}\\left(\\mathbf{a}^T \\boldsymbol{\\Psi}(\\mathbf{X})\\right)}; \n            \\]\n            \\item Conclude that\n            \\[\n                Var_{\\theta} \\delta(\\mathbf{X}) \\geq \\sup _{\\mathbf{a} \\in \\mathbb{R}^{n}} \\frac{\\left(\\mathbf{a}^T \\gamma(\\theta)\\right)^{2}}{\\mathbf{a}^T C(\\theta) \\mathbf{a}}. \n            \\]\n            \\item Consider the following result. \n            Let \\(p\\) be a \\(r \\times 1\\) column vector, let \\(P=p p^T\\), and let \\(Q\\) be an \\(r \\times r\\) real matrix. Then\n            \\[\n            \\sup _{\\mathbf{a} \\in \\mathbb{R}^{r}} \\frac{\\mathbf{a}^T P \\mathbf{a}}{\\mathbf{a}^T Q \\mathbf{a}}=\\text { largest eigenvalue of } Q^{-1} P=p^T Q^{-1} p. \n            \\]\n            Use the lemma to conclude that\n            \\[\n             Var_{\\theta} \\delta(\\mathbf{X}) \\geq \\gamma^T(\\theta) C^{-1}(\\theta) \\gamma(\\theta). \n            \\]\n        \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item From Cauchy-Schwarz inequality, \n        \\[\n            [Cov(X,Y)]^2\\leqslant Var(X) Var(Y). \n        \\]\n        So, \\[\n            Var(\\delta(X))\\geqslant \\frac{[Cov(\\delta(X), a^T\\psi(X))]^2}{Var(a^T\\psi(X))}. \n        \\]\n        \\item $Cov(\\delta(X), a^T\\psi(X))=a^TCov(\\delta(X), \\psi(X))$, $Var(a^T\\psi(X))=a^T\\psi(T(X))a$. So, \n        \\[\n            Var(\\delta(X))\\geqslant \\max_a\\frac{[a^T\\gamma(\\theta)]^2}{a^TC(\\theta)a}. \n        \\]\n        \\item Using the lemma, $P=\\gamma\\gamma^T$\n        \\[\n            Var(\\delta(X))\\geqslant \\gamma^T(\\theta)C^{-1}(\\theta) \\gamma(\\theta). \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Consider the following set of assumptions. \n    \\begin{enumerate}[(a)]\n        \\item \\(\\Theta \\subseteq \\mathbb{R}^{r}\\) is an open rectangle; \n        \\item the set\n        \\(\n            A=\\{\\mathbf{x}: f(\\mathbf{x} \\mid \\theta)>0\\}\n        \\)\n        is independent of \\(\\theta\\); \n        \\item \\(\\frac{\\partial}{\\partial \\theta} f(\\mathbf{x} \\mid \\theta)\\) exists for all \\(\\theta \\in \\Theta\\). \n    \\end{enumerate}\n    For \\(\\theta \\in \\mathbb{R}^{r}\\), define the information matrix at \\(\\theta\\) by\n    \\[\n        I(\\theta)=\\mathbb{E}_{\\theta}\\left(\\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{X} \\mid \\theta)\\right)\\left(\\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{X} \\mid \\theta)\\right)^T. \n    \\]\n    Prove the following theorem (a particular case of Theorem 2.6.6 in Lehmann \\& Casella \\((1998)\\), p. 127). \n\n    \\thm{1} (multiparameter information inequality) \n    \n    Suppose the following assumptions hold. \n    \\begin{enumerate}[(i)]\n        \\item \\(\\{f(x \\mid \\theta)\\}_{\\theta}\\) is a family of generalized densities with respect to the \\(\\sigma\\)-finite measure \\(G(d x)\\); \n        \\item \\(\\mathrm{A}-(\\mathrm{a}),(\\mathrm{b}),(\\mathrm{c})\\); \n        \\item \\(\\mathbb{E}_{\\theta} \\nabla_{\\theta} \\log f(\\boldsymbol{X} \\mid \\theta)=0, \\theta \\in \\Theta\\);  \n        \\item \\(I(\\theta)\\) is nonsingular, \\(\\theta \\in \\Theta\\); \n        \\item \\(\\mathbb{E}_{\\theta} \\delta^{2}(\\boldsymbol{X})<\\infty, \\theta \\in \\Theta\\); \n        \\item \\(\\nabla_{\\theta} \\mathbb{E}_{\\theta} \\delta(\\boldsymbol{X})=\\int \\delta(\\boldsymbol{x}) \\frac{\\partial}{\\partial \\theta} f(\\boldsymbol{x} \\mid \\theta) G(d \\boldsymbol{x})\\). \n    \\end{enumerate}\n    Then,\n    \\[\n         Var_{\\theta} \\delta(\\boldsymbol{X}) \\geq \\nabla_{\\theta} \\mathbb{E}_{\\theta} \\delta(\\boldsymbol{X}) I(\\theta)^{-1} \\nabla_{\\theta} \\mathbb{E}_{\\theta} \\delta(\\boldsymbol{X})^T, \\quad \\theta \\in \\Theta\n    \\]\n    (hint: use the previous problem).\n\\end{ex}\n\n\\begin{solution}\n    In previous problem, let $\\psi(X)=\\frac{\\pder }{\\pder \\theta}\\log f(x)$, then\n    \\[\n        C=I(\\theta); \n    \\]\n    \\[\n        \\begin{aligned}\n            \\nabla_\\theta E(\\delta)^T&=\\frac{\\partial}{\\partial \\theta}\\int \\delta(X)f(X)\\der x\\\\\n            &=\\int\\delta(X)f'(X)\\der x\\\\\n            &=\\int\\delta(X)\\frac{\\pder}{\\pder \\theta}\\log(f(X))f(X)\\der x\\\\\n            &=\\int\\delta(X)\\psi(X)f(X)\\der x\\\\\n            &=E\\left(\\delta(X)-E(\\delta(X))\\right)\\left(\\psi(X)-E(\\psi(X))\\right)\\\\\n            &=Cov(\\delta, \\psi)\\\\\n            &=\\gamma. \n        \\end{aligned}\n    \\]\n    Hence, we finish the proof. \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), \\mu \\in \\mathbb{R}, \\sigma^{2}>0\\). \n    \\begin{enumerate}[(a)]\n        \\item Prove that\n        \\[\n        I\\left(\\mu, \\sigma^{2}\\right)=\\left(\\begin{array}{cc}\n        \\frac{n}{\\sigma^{2}} & 0 \\\\\n        0 & \\frac{n}{2 \\sigma^{4}}\n        \\end{array}\\right)\n        \\]\n        Here you can use the equality\n        \\[\n        \\mathbb{E}_{\\theta} \\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{X} \\mid \\theta) \\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{X} \\mid \\theta)^T=-\\mathbb{E}_{\\theta} \\frac{\\partial^{2}}{\\partial \\theta \\partial \\theta^T} \\log f(\\mathbf{X} \\mid \\theta). \n        \\]\n        \\item Conclude that the variance of an UMVU estimator does not necessarily attain the CRLB. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item Knowing that \n        \\[\n            I(\\theta;\\mathbf{X})=nI(\\theta;X), \n        \\]\n        \\[\n            I(\\mu)=\\frac{n}{\\sigma^2}. \n        \\]\n        \\[\n            I(\\sigma^2)=\\frac{n}{2\\sigma^4}. \n        \\]\n        \\[\n            \\frac{\\pder}{\\pder \\mu \\,\\pder \\sigma}\\log(f(x))=\\frac{\\pder}{\\pder \\sigma \\,\\pder \\mu}\\log(f(x))=-2(x-\\mu)\\sigma^{-3}, \n        \\]\n        \\[\n            E\\left(-2(x-\\mu)\\sigma^{-3}\\right)=0. \n        \\]\n        So, \n        \\[\n            E\\left(\\frac{\\pder}{\\pder \\mu \\,\\pder \\sigma^2}\\log(f(x))\\right)=E\\left(\\frac{\\pder}{\\pder \\sigma^2 \\,\\pder \\mu}\\log(f(x))\\right)=0.\n        \\]\n        \\item Consider $\\frac{(n-1)S^2}{\\sigma^2}\\sim \\chi^2\n        (n-1)$, \n        \\[\n            Var\\left(\\frac{\\sigma^2}{n-1}\\frac{(n-1)S^2}{\\sigma^2}\\right)=\\frac{\\sigma^4}{(n-1)^2}2(n-1)=\\frac{2\\sigma^4}{n-1}>\\frac{2\\sigma^4}{n}. \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    (n.b.: the purpose of this exercise is to provide a simple 1-dimensional example where the variance of the UMVU estimator does not attain the CRLB) \n    \n    Let \\(X \\sim \\operatorname{Poi}(\\lambda), \\lambda>0\\), and let\n    \\[\n        \\delta(X):= \\begin{cases}1, & \\text { if } X=0 \\\\ 0, & \\text { otherwise }\\end{cases}. \n    \\]\n    \\begin{enumerate}[(a)]\n        \\item Conclude that \\(\\delta(X)\\) is UMVU for \\(\\mathbb{E}_{\\lambda} \\delta(X)\\). \n        \\item Find \\(\\mathbb{E}_{\\lambda} \\delta(X)\\) and \\(\\operatorname{Var}_{\\lambda} \\delta(X)\\). \n        \\item Find the CRLB for \\(\\operatorname{Var}_{\\lambda} \\delta(X)\\) (hint: use the formula for the change of variables in the information function). \n        \\item Conclude that the CRLB cannot be met. \n        \\item Why doesn't this contradict the result we showed in class on the attainment of the CRLB in exponential families? (see problem \\#2 in this Problem set.)\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item $\\delta(X)$ is unbiased, and $X$ is a sufficient statistic. So, $\\delta(X)$ is UMVU. \n        \\item \\[\n            E(\\delta(X))=1\\cdot e^{-\\lambda}=e^{-\\lambda}, \\ Var(\\delta(X))=E(\\delta(X))^2-(E\\delta(X))^2=\\frac{e^\\lambda-1}{e^{2\\lambda}}. \n        \\]\n        \\item \\[\n            Var(\\delta)\\geqslant\\frac{\\left(-e^{-\\lambda}\\right)^2}{I(\\lambda)}=\\frac{\\lambda}{e^{2\\lambda}}.\n        \\]\n        \\item When $\\lambda>0$, $e^{\\lambda}-1>\\lambda$. Hence, CRLB cannot be met. \n        \\item Because $\\delta(X)$ is not $C^1$. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\mathbf{X}\\) and \\(\\mathbf{Y}\\) be independent random vectors, where \\(\\mathbf{X} \\sim f(\\mathbf{x} \\mid \\theta), \\mathbf{Y} \\sim g(\\mathbf{y} \\mid \\theta), \\theta \\in \\Theta\\), where \\(f\\) and \\(g\\) are generalized densities. Assume the following conditions hold. \n    \\begin{enumerate}[(i)]\n        \\item A-(a),(b), (c); \n        \\item \\[\n            \\mathbb{E}_{\\theta}\\left(\\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{X} \\mid \\theta)\\right)=0=\\mathbb{E}_{\\theta}\\left(\\frac{\\partial}{\\partial \\theta} \\log g(\\mathbf{X} \\mid \\theta)\\right), \\quad \\theta \\in \\Theta. \n        \\]\n    \\end{enumerate}\n    \\begin{enumerate}[(a)]\n        \\item Show that \\(I_{\\mathbf{X}, \\mathbf{Y}}(\\theta)=I_{\\mathbf{X}}(\\theta)+I_{\\mathbf{Y}}(\\theta)\\), namely, the information contained in each subsample adds up to the information in the whole sample. \n        \\item Use (a) to rewrite the CRLB for an i.i.d. sample \\(X_{1}, \\ldots, X_{n}\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item Let $\\psi(X)=\\frac{\\pder }{\\pder \\theta}\\log f(X; \\theta)$, then \n        \\[\n            \\begin{aligned}\n                I_{X,Y}(\\theta)&=E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)f(Y;\\theta)\\right)^2\\\\\n                &=E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)+\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2\\\\\n                &=E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2+E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(Y;\\theta)\\right)^2\\\\\n                &=I_X(\\theta)+I_Y(\\theta)\n            \\end{aligned}\n        \\]\n        \\item Let $\\delta(X)$ be an unbiased statistics for $\\theta$, \n        \\[\n            I_X(\\theta)=\\sum_{i=1}^nI_{X_i}(\\theta)=nI_x(\\theta). \n        \\]\n        \\[\n            Var_\\theta(\\delta(X))\\geqslant\\frac{1}{nI_x(\\theta)}. \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\n\\begin{ex}\n    Consider an estimator \\(\\delta(\\mathbf{X}) \\in \\Delta\\) under a parametric family \\(\\mathbf{X} \\sim \\mathcal{P}=\\{f(\\mathbf{x} \\mid \\theta)\\}_{\\theta \\in \\Theta}\\), where \\(f(\\mathbf{x} \\mid \\theta)\\) is a generalized density. Suppose, in addition, that the following conditions hold. \n    \\begin{enumerate}[(i)]\n        \\item \\(\\mathbb{E}_{\\theta} \\delta(\\mathbf{X})=g(\\theta), \\theta \\in \\Theta\\), where the function \\(g(\\cdot)\\) is differentiable; \n        \\item the estimator can be explicitly written as\n        \\[\n        \\delta(\\mathbf{x})=g(\\theta)+\\frac{g^{\\prime}(\\theta)}{I(\\theta)} \\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{x} \\mid \\theta), \\quad I(\\theta)>0, \\quad \\theta \\in \\Theta. \n        \\]\n        \\item \\[\n            \\frac{\\partial}{\\partial \\theta} \\int_{\\mathbb{R}^{n}} f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x})=\\int_{\\mathbb{R}^{n}} \\frac{\\partial}{\\partial \\theta} f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x}), \\quad \\theta \\in \\Theta .\n        \\]\n        Show that \\(\\operatorname{Var}_{\\theta} \\delta(\\mathbf{X})\\) attains the CRLB. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{align*}\n        Var(\\delta(X))&=E(\\delta(X)-E\\delta(X))^2\\\\\n        &=E\\left(\\frac{g'(\\theta)}{I(\\theta)}\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2\\\\\n        &=\\left(\\frac{g'(\\theta)}{I(\\theta)}\\right)^2E\\left(\\frac{\\pder}{\\pder \\theta}\\log f(X|\\theta)\\right)^2\\\\\n        &=\\left(\\frac{g'(\\theta)}{I(\\theta)}\\right)^2I(\\theta)\\\\\n        &=\\frac{(g'(\\theta))^2}{I(\\theta)}\\\\\n        &=\\frac{\\left(\\frac{\\pder}{\\pder \\theta}E(\\delta(X))\\right)^2}{I(\\theta)}\\\\\n        &=CRLB. \n    \\end{align*}\n\\end{solution}\n\n", "meta": {"hexsha": "16513b604383b459ff176efde13f7e3a86f1d708", "size": 30491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/Set5.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/Set5.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/Set5.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": 49.9852459016, "max_line_length": 413, "alphanum_fraction": 0.5294021187, "num_tokens": 10983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6595518675832666}}
{"text": "\\section{Methods for pattern selection}\n\n\\subsection{Based on Conditional Mutual Information}\n\\begin{itemize}\n\\item When studying methylation we are faced with two main questions:\n  \\begin{enumerate}\n  \\item Which genes exhibit an L-shape, and \n  \\item What is the optimal threshold for binarizing\nmethylation data for each L-shape gene.\n  \\end{enumerate}\n\\item Following \\cite{Liu} in order to determine whether methylation $X$ and expression $Y$ of a gene exhibit an L--shape, the conditional Mutual Information $cMI(t)$ for different choices of threshold $t$ is computed.\n\\[\n\\mathit{cMI}(t)=I(X,Y|X>t)P(X>t) + I(X,Y|X\\le t)P(X\\le t)\n\\]\n\\item If the relation between methylation and expression shows an L-shape  as $t$ moves from 0 to 1, $\\mathit{cMI}(t)$ first decreases and then increases, its value approaching zero when $t$ coincides with the reflection point. \n\\end{itemize}\n ", "meta": {"hexsha": "9ce27761a340bb48a951b031315ee567717b5d39", "size": 883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Treballs_nostres/2016-07-IBS-Victoria-Poster/sections/methods1.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/methods1.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/methods1.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": 51.9411764706, "max_line_length": 228, "alphanum_fraction": 0.75198188, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6595383517414001}}
{"text": "\\documentclass[a4paper,10pt]{article}\r\n\r\n\\usepackage[utf8]{inputenc}\r\n\r\n\\usepackage{mathtools}\r\n\\usepackage{amsfonts}\r\n\\usepackage{amssymb}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsthm}\r\n\\usepackage{graphicx}\r\n\\usepackage{listings}\r\n\\usepackage{hyperref}\r\n\\usepackage[show]{ed}\r\n\r\n\\usepackage[english]{babel}\r\n\r\n\\title{Elements of Stochastic Processes\\\\Asssignment Sheet 2}\r\n\\author{Tom Wiesing}\r\n\\date{\\today}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\r\n\\section{Exercise 5}\r\n\\subsection{Problem}\r\n\r\nAssume that $X$ is a real valued continuous random variable with density $f_X$\r\nand cumulative distribution function $F_X$. Show that $$\r\n  \\mathbb{E}\\left[X\\right] = \\int_{-\\infty}^{0}{F_x(t)\\mathrm{d}t} + \\int_{0}^{\\infty}{1 - F_x(t)\\mathrm{d}t}\r\n$$.\r\n\r\n\\subsection{Solution}\r\n\r\nFor now assume that $X \\geq 0$, i.e. $X$ never assumes negative values. Then we have:\r\n\r\n$$\r\n  \\mathbb{E}\\left[X\\right] = \\int_{0}^{\\infty}{t f_x(t)\\mathrm{d}t} = \\int_{-\\infty}^{\\infty}{t P[X = t]\\mathrm{d}t}\r\n$$\r\n$$\r\n  = \\int_{0}^{\\infty}{P[X > t]\\mathrm{d}t} = \\int_{0}^{\\infty}{1 - P[X \\leq t]\\mathrm{d}t} = \\int_{0}^{\\infty}{1 - F_X(t)\\mathrm{d}t}\r\n$$ Notice that in the middle of this computation, we switch the integral around.\r\nIntuitively, the integral measures the area under the curve $t P[X = t]$ on the right hand side of the origin by slicing it vertically.\r\nEquivalently, we can also measure the area by slicing it horizontally, which is what we are doing in the next line.\r\n\r\nTo compute the expected value of a generalised random variable (which may now be negative), we write it as a sum of two random variables $$\r\nX = Y - Z\r\n$$ with both $Y, Z \\geq 0$. As the expected value is linear, we can then write\r\n\r\n$$\r\n  \\mathbb{E}\\left[X\\right] = \\mathbb{E}\\left[Y\\right] - \\mathbb{E}\\left[Z\\right] = \\int_{0}^{\\infty}{1 - F_Y(t)\\mathrm{d}t} - \\int_{0}^{\\infty}{1 - F_Z(t)\\mathrm{d}t}\r\n$$\r\n$$\r\n  = \\int_{0}^{\\infty}{1 - F_X(t)\\mathrm{d}t} + \\int_{-\\infty}^{0}{F_x(t)\\mathrm{d}t}\r\n$$.\r\n\r\n\\section{Exercise 6}\r\n\\subsection{Problem}\r\n\r\nFor $\\alpha \\geq 1$ suppose that the random variable $X$ has the density function\r\n$$\r\nf_x(t) =\r\n\\begin{cases}\r\n  \\alpha e^{-\\alpha t} & \\mbox{if } t \\geq 0 \\\\\r\n  0 & \\mbox{else}\r\n\\end{cases}\r\n$$ Compute $\\mathbb{E}[e^X]$.\r\n\r\n\\subsection{Solution}\n\n$$\n\\mathbb{E}[e^X] = \\int_{-\\infty}^{\\infty}{e^t \\begin{cases}\r\n  \\alpha e^{-\\alpha t} & \\mbox{if } t \\geq 0 \\\\\r\n  0 & \\mbox{else}\r\n\\end{cases}\\mathrm{d}t}\r\n= \\int_{0}^{\\infty}{e^t e^{-\\alpha t} \\mathrm{d}t}\n= \\int_{0}^{\\infty}{e^{(1 - \\alpha) t} \\mathrm{d}t}\n= \\frac{1}{\\alpha - 1}\n$$.\n\r\n{\\raggedleft{}$\\square$}\r\n\r\n\\section{Exercise 7}\r\n\\subsection{Problem}\r\n\r\nLet $X$ and $Y$ be independent random variables with uniform distribution in the interval $[0, 1]$. Let $Z$ = $XY$. Find\r\n\\begin{enumerate}[a)]\r\n  \\item the joint probability distribution function of $X$ and $Y$,\r\n  \\item the joint probability distribution function of $X$ and $Z$,\r\n  \\item the joint density function of $X$ and $Z$\r\n\\end{enumerate}.\r\n\r\n\\subsection{Solution}\r\n\\subsubsection{a)}\r\n$$\r\n  F(x, y) = P[X \\leq x, Y \\leq y] = P[X \\leq x]P[Y \\leq y] = x y\r\n$$\r\n\r\n\\subsubsection{b)}\r\n$$\r\n  F(x, z) = P[X \\leq x, Z \\leq z] = P[X \\leq x, X + Y \\leq z]\r\n$$\r\n$$\r\n  = P[X \\leq x, Y \\leq z - x] = P[X \\leq x]P[Y \\leq z - x] = x (z - x)\r\n$$\r\n\r\n\\subsubsection{c)}\r\n$$\r\n  f(x, z) = P[X = x, Z = z] = P[X = x, X + Y = z]\r\n$$\r\n$$\r\n   = P[X = x, Y = z - x] = P[X = x]P[Y = z - x] = 1\r\n$$\r\n\r\n\\section{Exercise 8}\r\n\\subsection{Problem}\r\n\r\nLet $n \\geq 2$ be a natural number and let the joint probability mass function of the discrete random variables $X$ and $Y$ be given by\r\n$$\r\n  p_{X,Y}(x, y) = \\begin{cases}\r\n    k (x + y) & \\mbox{if }1 \\leq x,y \\leq n \\\\\r\n    0 & \\mbox{else}\r\n  \\end{cases}\r\n$$\r\n\r\n\\begin{enumerate}[a)]\r\n  \\item Determine the value of the constant $k$.\r\n  \\item Determine the marginal probability mass functions of $X$ and $Y$.\r\n  \\item Find $P(X \\geq Y)$. \\\\\r\n  \\textit{Hint: You can simplify the calculations by observing that $P(X \\geq Y) = P(Y \\geq X)$. }\r\n\\end{enumerate}\r\n\r\n\\subsection{Solution}\r\n\\subsubsection{a)}\r\nWe observe that $$\r\n  1 = \\sum_{x = 1}^{n}{\\sum_{y = 1}^{n}{k (x + y)}} = k n^2 (n + 1)\r\n$$ and thus have $k = \\frac{1}{n^2 (n + 1)}$.\r\n\\subsubsection{b)}\r\nWe observe that $$\r\n  P[X = x] = \\sum_{y = 1}^{n}{k (x + y)} = k (\\sum_{y = 1}^{n}{(x + y)})\r\n  = k (nx + \\sum_{y = 1}^{n}{y})\r\n  = \\frac{x}{n (n + 1)} + \\frac{1}{2 n}\r\n$$ By symmetry, we have\r\n$$\r\n  P[Y = y] = \\frac{y}{n (n + 1)} + \\frac{1}{2 n}\r\n$$\r\n\\subsubsection{c)}\r\n$$\r\n  P[X \\leq Y] = \\sum_{y=1}^{n}{P[X \\leq y, Y=y]} = \\sum_{y=1}^{n}{\\sum_{x=1}^{y}{P[X = x, Y = y]}}\r\n$$\r\n$$\r\n  = \\sum_{y=1}^{n}{\\sum_{x=1}^{y}{k (x + y)}} = \\frac{1}{2} k n (n + 1)^2 = \\frac{1}{2n}\r\n$$\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "259605b07266974979f3af04e47332dd7497bfcf", "size": 4721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw2/hw2.tex", "max_stars_repo_name": "tkw1536/IntroStochasistcs", "max_stars_repo_head_hexsha": "350f248c08bea8d36770c0321803681ffe2b5cd9", "max_stars_repo_licenses": ["MIT"], "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/hw2.tex", "max_issues_repo_name": "tkw1536/IntroStochasistcs", "max_issues_repo_head_hexsha": "350f248c08bea8d36770c0321803681ffe2b5cd9", "max_issues_repo_licenses": ["MIT"], "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/hw2.tex", "max_forks_repo_name": "tkw1536/IntroStochasistcs", "max_forks_repo_head_hexsha": "350f248c08bea8d36770c0321803681ffe2b5cd9", "max_forks_repo_licenses": ["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.2628205128, "max_line_length": 167, "alphanum_fraction": 0.5907646685, "num_tokens": 1817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.6595113218148857}}
{"text": "\\lab{Image Segmentation}{Image Segmentation}\n\n\\objective{Understand some basic applications of eigenvalues to graph theory.}\n\\label{lab:ImgSeg_eigenvalues}\n\n\\section*{Graph Theory}\n\\begin{figure}\n\n \\begin{tikzpicture}[auto,node distance=1.5cm,\n thick,main node/.style={circle,draw}]\n\n  \\node[main node] (5) [] {6};\n  \\node[main node] (2) [below right of=5] {3};\n  \\node[main node] (3) [above right of=5] {4};\n  \\node[main node] (4) [right of=3] {5};\n  \\node[main node] (1) [right of=2] {2};\n  \\node[main node] (0) [below right of=4] {1};\n\n  \\foreach \\s/\\t in {5/3, 3/4, 4/0, 0/1, 1/2, 2/3, 1/4, 5/0} {\n   \\path[draw] (\\s) edge (\\t);}\n\\end{tikzpicture}\n\\caption{An undirected graph that is connected.}\n\\label{fig:example_graph}\n\\end{figure}\n\n\\begin{figure}\n\n \\begin{tikzpicture}[auto,node distance=2cm,\n thick,main node/.style={circle,draw}]\n\n  \\node[main node] (0) [] {1};\n  \\node[main node] (1) [below of=0] {2};\n  \\node[main node] (2) [right of=0] {3};\n  \\node[main node] (3) [below of=2] {4};\n  \\node[main node] (4) [right of=2] {5};\n  \\node[main node] (5) [right of=3] {6};\n\n   \\path[draw] (0) edge node [left] {3} (1);\n   \\path[draw] (2) edge node [left] {1} (3);\n   \\path[draw] (4) edge node{-1} (5);\n   \\path[draw] (3) edge node{2} (4);\n   \\path[draw] (3) edge node [below]{.5} (5);\n\\end{tikzpicture}\n\\caption{A weighted undirected graph that is not connected.}\n\\label{fig:example_graph2}\n\\end{figure}\n\n% \\begin{tikzpicture}[auto,node distance=1.5cm,\n% thick,main node/.style={circle,draw}]\n%\n%  \\node[main node] (2) [] {2};\n%  \\node[main node] (1) [below left of=2] {1};\n%  \\node[main node] (0) [below right of=2] {0};\n%\n%  \\foreach \\s/\\t in {1/1, 1/2, 1/3, 2/3} {\n%   \\path[draw] (\\s) edge (\\t);}\n%\\end{tikzpicture}\n%\\caption{An undirected graph that is not simple.}\n%\\label{fig:example_graph}\n%\\end{figure}\n\n\n%\\begin{figure}\n% \\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,\n% thick,main node/.style={circle,draw}]\n%\n%  \\node[main node] (A) [] {A};\n%  \\node[main node] (B) [below of=A] {B};\n%  \\node[main node] (C) [right of=A] {C};\n%  \\node[main node] (D) [below of=C] {D};\n%  \\node[main node] (E) [right of=C] {E};\n%  \\node[main node] (F) [right of=D] {F};\n%\n%  \\foreach \\s/\\t in {A/C, B/A, B/D, C/E, C/F, D/C} {\n%   \\path[draw] (\\s) edge (\\t);}\n%\\end{tikzpicture}\n%\\caption{A simple directed graph}\n%\\end{figure}\n\n\n\nGraphs represent relationships between objects.\n%For example, the transition diagram in Figure \\ref{fig:markov1} in Lab \\ref{lab:EigSolve} shows the relationship between states in a Markov chain.\nAn \\emph{undirected graph} is a set of nodes (or vertices) and edges, where each edge connects exactly two nodes and (see Figure \\ref{fig:example_graph}).\nA \\emph{directed graph} has the additional information of an arrow on each edge. \nIn this lab we will only consider undirected graphs, which we will simply call graphs (unless we wish to emphasize the fact that they are undirected).\n\n%A graph is \\emph{simple} if no edge connects a node to itself. \n%The graph in Figure [TODO!] is simple, but the graph in Figure [TODO!] is not.\n\nA \\emph{weighted} graph is a graph with a weight attached to each edge.\nFor example, a weighted graph could represent a collection of cities with roads connecting them.\nThe vertices would be cities, the edges roads, and weight of an edge would be the length of a road.\nSuch a graph is depicted as in Figure \\ref{fig:example_graph2}.\n\nAny graph can be thought of as a weighted graph by assigning a weight of 1 to each edge.\n\n\\subsection*{Adjacency, degree, and Laplacian matrices}\nWe will now introduce three special matrices associated to a graph. \nThroughout this section, assume we are working with a weighted undirected graph with $N$ nodes, and that $w_{ij}$ is the weight attached to the edge connecting node $i$ and node $j$.\nWe first define the adjacency matrix.\n\n\\begin{definition} The \\emph{adjacency matrix} is an $N \\times N$ matrix whose $(i,j)$-th entry is\n\\begin{center}\n\t$ \\begin{cases}  w_{ij} & \\mbox{if an edge connects node i and node j} \\\\ 0 & \\mbox{otherwise.} \\end{cases}$\n\\end{center}\n% If the graph is not simple, there are differing conventions for how to define the diagonal of the adjacency matrix.\n\\end{definition}\n\nFor example, the graph in Figure \\ref{fig:example_graph} has the adjacency matrix $A_1$ and the graph in Figure \\ref{fig:example_graph2} has the adjacency matrix $A_2$, where\n\\[\nA_1 = \\begin{pmatrix}\n0 & 1 & 0 & 0 & 1 & 1\\\\\n1 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 1 & 1\\\\\n1 & 1 & 0 & 1 & 0 & 0\\\\\n1 & 0 & 0 & 1 & 0 & 0\n\\end{pmatrix}. \\qquad A_2 = \n \\begin{pmatrix}\n0 & 3 & 0 & 0 & 0 & 0\\\\\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 2 & .5\\\\\n0 & 0 & 0 & 2 & 0 & -1\\\\\n0 & 0 & 0 & .5 & -1 & 0\n\\end{pmatrix}\n\\]\nNotice that these adjacency matrices are symmetric. This will always be the case for undirected graphs.\n\n\\begin{comment}\nRaising the adjacency matrix to a power yields some very interesting information.\nWe can discover the number of paths of length $n$ between two nodes by raising a graph's adjacency matrix to the $n$th power.\nFor example, by squaring $A$, we can find the number of paths of length two between every pair of nodes.\n\\begin{lstlisting}\n>>> A = np.array([[0,1,0,0,1,0],[1,0,1,0,1,0],\n                  [0,1,0,1,0,0],[0,0,1,0,1,1],\n                  [1,1,0,1,0,0],[0,0,0,1,0,0]])\n\n>>> np.linalg.matrix_power(A,2)\narray([[2, 1, 1, 1, 1, 0],\n       [1, 3, 0, 2, 1, 0],\n       [1, 0, 2, 0, 2, 1],\n       [1, 2, 0, 3, 0, 0],\n       [1, 1, 2, 0, 3, 1],\n       [0, 0, 1, 0, 1, 1]])\n\\end{lstlisting}\nWe can see that no paths of length two exist between node 0 and node 5 because $A^2_{0,5} = 0$.\nBy calculating $A^6$ we can find the number of paths of length six from node 3 to itself.\n\\begin{lstlisting}\n>>> np.linalg.matrix_power(A, 6)\narray([[45, 54, 38, 45, 54, 16],\n       [54, 86, 29, 77, 51, 11],\n       [38, 29, 55, 15, 70, 27],\n       [45, 77, 15, 75, 31,  4],\n       [54, 51, 70, 31, 93, 34],\n       [16, 11, 27,  4, 34, 14]])\n\\end{lstlisting}\nWe see that there are 75 unique paths of length six from node 3 to itself.\nImagine trying to count all of those paths by hand!\nIt would be very easy to count incorrectly.\nThis method makes it very simple to count paths without mistakes.\n\nAdjacency matrices can also be composed of \\li{True} and \\li{False} values.\nIn this case, the $n$th power of such a matrix (using boolean arithmetic)\nis again a matrix of\nboolean values which simply indicate whether there exists a path of length $n$ between the given pair of nodes, rather than indicating the number of such\npaths.\n\n\\begin{problem}\nLet the following matrix represent a directed graph\n\\[\n\\begin{pmatrix}\n0 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 1 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0\n\\end{pmatrix}\n\\]\nBetween which pair of nodes does there exist the greatest number of paths\nof length five?\nFrom which node to which node is there no path of length seven?\n\\end{problem}\n\\end{comment}\n\nThe second matrix is the degree matrix. \n\\begin{definition} The \\emph{degree matrix} is an $N \\times N$ diagonal matrix whose $(i,i)$-th entry is\n\\[ \n\\sum_{j=1}^N w_{ij}.\n\\]\nThis quantity is just the sum of the weight of each edge that touches node $i$.\n\\end{definition}\n%For a directed graph, each node has an \\emph{out-degree} (the number of edges directed away from a node) and an \\emph{in-degree} (the number edges directed toward a node).\nWe call the $(i, i)-th$ entry of the degree matrix the \\emph{degree} of node $i$. As an example, the degree matrices of the graphs in Figures \\ref{fig:example_graph} and \\ref{fig:example_graph2} are $D_1$ and $D_2$, respectively, where\n\n\\[\nD_1 = \\begin{pmatrix}\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 2 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 3 & 0 & 0\\\\\n0 & 0 & 0 & 0 & 3 & 0\\\\\n0 & 0 & 0 & 0 & 0 & 2\n\\end{pmatrix}. \\qquad D_2 = \n \\begin{pmatrix}\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 3.5 & 0 & 0\\\\\n0 & 0 & 0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 0 & 0 & -.5\n\\end{pmatrix}\n\\]\n\nFinally, we can combine the degree matrix and the adjacency matrix into the Laplacian matrix.\n% Wikipedia defines the Laplacian of a simple graph only. I don't know why.\n% The graph in our application is NOT simple. \n% However, the non-simple parts cancel out, meaning that the Laplacian of the graph is the same as if you removed all self edges and then computed the Laplacian.\n% So I just define the Laplacian this way and don't talk about simple graphs.\n\\begin{definition}\nThe \\emph{Laplacian matrix} of a graph is \n\\[D - A \\]\nwhere $D$ is the degree matrix and $A$ is the adjacency matrix of the graph.\n\\end{definition}\n\nFor example, the Laplacian matrix of the graphs in Figures \\ref{fig:example_graph} and \\ref{fig:example_graph2} are $L_1$ and $L_2$, respectively, where\n\n\\[\nL_1 = \\begin{pmatrix}\n3 & -1 & 0 & 0 & -1 & -1\\\\\n-1 & 3 & -1 & 0 & -1 & 0\\\\\n0 & -1 & 2 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3 & -1 & -1\\\\\n-1 & -1 & 0 & -1 & 3& 0\\\\\n-1 & 0 & 0 & -1 & 0 & 2\n\\end{pmatrix}. \\qquad L_2 = \n \\begin{pmatrix}\n3 & -3 & 0 & 0 & 0 & 0\\\\\n-3 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3.5 & -2 & -.5\\\\\n0 & 0 & 0 & -2 & 1 & 1\\\\\n0 & 0 & 0 &- .5 & 1 & -.5\n\\end{pmatrix}\n\\]\n\n\nIn this lab we will learn about graphs by studying their Laplacian matrices.\nWhile the Laplacian matrix seems simple, we can learn surprising things from its eigenvalues.\n\n\n\\begin{problem}\nWrite a function that accepts the adjacency matrix of a graph as an argument. \nYour function should return the Laplacian matrix. \nHint: You can compute the diagonal of the degree matrix in one line by summing over an axis (see Lab \\ref{lab:NumPyArrays}).\nAnother hint: Test your function on the graphs in Figures \\ref{fig:example_graph} and \\ref{fig:example_graph2}.\n\\label{prob:laplacian}\n\\end{problem}\n\n\n\n\\subsection*{Connectivity: first application of Laplacians}\n\nA \\emph{connected graph} is a graph where every vertex is connected to every other vertex by at least one path.\nThe graph in Figure \\ref{fig:example_graph} is connected, whereas the graph in Figure \\ref{fig:example_graph2} is not.\nIn applications, it is often important to know if a graph is connected.\nA naive approach to determine connectivity of a graph is to search every possible path from each vertex.\nWhile this works for very small graphs, most interesting graphs will have thousands of vertices (for example, the internet), and for such graphs this approach is not feasible.\n\nFortunately, there is a better way.\nRecall that the adjacency matrix of an undirected graph is always symmetric. \nThus, it will have real eigenvalues. \nSurprisingly, a graph is connected if the second smallest eigenvalue of its Laplacian matrix is positive. [TODO: cite something!]\nIn many applications the Laplacian matrix is sparse, so by taking advantage of this sparsity, we can cheaply determine if a graph is connected.\n\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Write a function that accepts a symmetric adjacency matrix as an argument and returns the second smallest eigenvalue of the Laplacian matrix.\nUse the \\li{scipy.linalg} package to compute the eigenvalue.\n\n\\item Here is a function that creates a random symmetric matrix of Boolean values with sparsity determined by the input \\li{c}.\n\\begin{lstlisting}\ndef sparse_generator(n, c):\n    ''' Return a symmetric nxn matrix with sparsity determined by c.\n    Inputs:\n        n -- an integer\n        c -- a decimal number in [0,1]. Larger values of c will produce\n             matrices with more entries equal to zero.\n    '''\n    A = np.random.rand(n**2).reshape((n, n))\n    A = ( A > c**(.5) )\n    return A.T.dot(A)\n\\end{lstlisting}\n\\end{enumerate}\n\nRun your function from part 1 of this problem on matrices created by \\li{sparse_generator} with inputs $n = 10, 100$ and $c = .25, .5, .95$. \nWhat do you notice about the likelihood that a random graph is connected?\n\\end{problem}\n\n\n\\section*{Image Segmentation: second application of Laplacians}\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{RegMon.png}\n    \\end{subfigure}\n   \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{NegMon.png}\n    \\end{subfigure}\n    \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{PosMon.png}\n    \\end{subfigure}\n    \n\\caption{An image and its segments.}\n\\label{fig:monument}\n\\end{figure}\nImage segmentation is the process of finding natural boundaries in an image (see for example Figure \\ref{fig:monument}).\nThis is an easy task for humans, who can easily pick out portions of an image that ``belong together.''\nIn this lab, you will learn one way to program a computer to segment images.\n\nThe algorithm we will present comes from a paper by Jianbo Shi and Jitendra Malik in 2000 (\\cite{Shi2000}).\nTheir idea is to represent an image as a weighted graph as follows. \nTo a computer, an \\emph{image} is a collection of \\emph{pixels}. \nEach pixel has a brightness and coordinates describing its location in the image.\nTo define a graph representing this image, we let every pixel be a vertex.\nTwo pixels are connected if the distance between their coordinates is small (less than $r$).\nThe weight of the edge connecting two pixels is related their similarity in brightness, where a low weight means they are very different.\n\nAfter defining this graph, we will segment the image by ``cutting'' (or removing) edges with low weights, which represent lines of high contrast in the image. \nThe ``cut'' is the total weight of the edges removed. Thus, to segment an image, we wish to minimize the ``cut.''\nWe can ``cut'' an image multiple times to segment an image into more than two pieces.\n\nNow let us define the adjacency matrix of the graph associated to an image. \nSince an $N \\times N$ image has $N^2$ pixels, the adjacency matrix will be $N^2 \\times N^2$.\nAfter choosing a radius $r$ and some constants $\\sigma_I$ and $\\sigma_d$, we define the adjacency matrix to be $W = (w_{ij})$, where\n\n\\begin{equation}\n\\label{eq:adjacency}\nw_{ij} = \\begin{cases} \\exp(-\\frac{|I(i) - I(j)|}{\\sigma_I^2}-\\frac{d(i,j)}{\\sigma_d^2}) & \\mbox{ for $d(i,j) < r$} \\\\ 0 & \\mbox{ otherwise,} \\end{cases}\n\\end{equation}\nwhere\n\\begin{itemize}\n\t\\item$d(i,j)$ is the Euclidean distance between pixel $i$ and pixel $j$\n\t\\item $|I(i) - I(j)|$ is the difference in brightness of pixels $i$ and $j$.\n\\end{itemize}\n\nNotice that $W$ will be sparse as long as $r$ is small. Figure \\ref{fig:adjacency} shows what the adjacency matrix looks like for a $4x4$ image when $r=1.2$.\n\n\\begin{figure}\n\\begin{tikzpicture}[dot/.style={circle,fill=black,minimum \n\tsize=4pt,inner sep=0pt,outer sep=-1pt}, >=stealth]\n%scale=.85, transform shape,\n\n\n%image\n\\draw[step=.75,thick](2.999,0)grid(6,3);\n%numbers 1-16\n\\foreach \\x in {1,2,3,4}\n\t\\foreach \\y in {4}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.6, \\y-1.4){\\x};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+4)]in {1,2,3,4}\n\t\\foreach \\y in {3}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.6, \\y-1.2){\\r};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+8)] in {1,2,3,4}\n\t\\foreach \\y in {2}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.5, \\y-.95){\\r};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+12)] in {1,2,3,4}\n\t\\foreach \\y in {1}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.5, \\y-.7){\\r};\n\n\\node[draw=none](image)at(4.5, -.5){$image$};\n\\node[draw=none](flattened)at(7.25,-3){\\textit{flattened image}};\n\\node[draw=none](adjacency)at(12,-3){\\textit{adjacency image}};\n\n%dots within grid\n\\foreach \\x in {1,2,3,4}\n\t\\foreach \\y in {1,2,3,4}\n\t\t\\node[draw, dot]at(\\x*.75+2.6,\\y*.75-.4){};\n\n%color fill\n\\foreach \\x/\\y in {2/3.75, 1.25/3, 2/3, 2.75/3, 2/2.25} {\\node[draw, minimum \n\tsize=.75cm, fill=green!30!black, fill opacity=.25]at(\\x+2.118,\\y-1.118){};}\n\n%circle in image\n\\node[draw, circle, minimum size=2cm,thick](circle)at(4.13,1.86){};\n\n%flattened image\n\\draw[step=.5, thick](6.999,-2.5)grid(7.5,5.5);\n\\foreach \\x in {7}\n\t\\foreach \\y in {1,...,16}\n\t\t\\node[draw=none]at(\\x+.25,\\y*-.5+5.75){\\y};\n\n\\draw[->,thick](6.1, 1.5)--(6.9,1.5);\n\n%adjancey matrix\n\\draw[step=.5](7.9999,-2.5)grid(16,5.5);\n%\\draw[step=2,thick](7.999,-2.5)grid(16,5.5);\n\n%outside labels\n\\foreach \\x in {1,5,9,13} {\\node[draw=none]at(\\x*.5+7.75,5.8){\\x};}\n\\foreach \\y in {1,5,9,13}{\\node[draw=none]at(16.3,\\y*-.5+5.8){\\y};}\n\n%shading of boxes\n\\foreach \\x/\\y in {8.5/5.5, 9/5.5, 8.5/5, 9/5, 9.5/5,9/4.5,9.5/4.5,10/4.5, \n\t9.5/4, 10/4, 10.5/5.5, 11/5,11.5/4.5, 12/4, 12.5/3.5, \n\t13.5/2.5, 14/2, 14.5/1.5, 15/1, 15.5/.5,16/0, 10.5/3.5, 11/3.5, 11/2.5, \n\t11.5/2.5,12/2.5, 11.5/2,12/2, 12.5/1.5, 13/1.5, 12.5/1, 13/1,\n\t13.5/1,13/.5,13.5/.5,14/.5, 13.5/0,14/0, 14.5/-.5,15/-.5,14.5/-1,\n\t15/-1,15.5/-1, 15/-1.5, 15.5/-1.5, 16/-1.5, 15.5/-2, 16/-2, 8.5/3.5,\n\t9.5/2.5,10/2,10.5/1.5,11/1,11.5/.5,12/0, 12.5/-.5, 13/-1, 13.5/-1.5, 14/-2} \n\t{\\node[draw, minimum size=.5cm, fill=black, fill opacity=.25]\n\tat(\\x-.25,\\y-.25){};}\n\n%green shaded boxes\n\\foreach \\x/\\y in {9/3,11/3, 11.5/3, 10.5/3, 13/3} {\\node\n\t[draw, minimum size=.5cm, fill=green!30!black, fill opacity=.25]\n\tat(\\x-.25,\\y-.25){};}\n\n\\node[draw=none]at(8.75,2.75){2};\n\\node[draw=none]at(10.25,2.75){5};\n\\node[draw=none]at(10.75,2.75){6};\n\\node[draw=none]at(11.25,2.75){7};\n\\node[draw=none]at(12.75,2.75){10};\n\n\\end{tikzpicture}\n\n\\caption{The grid at left represents a $4\\times4$ image, which has 16 pixels. Thus the adjacency matrix at right is $16 \\times 16$. We have not calculated the weights in the adjacency matrix, but we have shaded the nonzero entries. For example, the $6^{th}$ row corresponds to the $6^{th}$ pixel. Within that row, entries are nonzero if they correspond to pixels that are at most 1.2 away from pixel 6.}\n\\label{fig:adjacency}\n\\end{figure}\n\n\n\\subsection*{Computing the adjacency matrix}\nLet us write a function that accepts an image \\li{img} and constants \\li{radius}, \\li{sigma_I}, and \\li{sigma_d}. The function will return the adjacency matrix defined in (\\ref{eq:adjacency}) and the diagonal of the corresponding degree matrix. The input \\li{img} should be a 2-D array of brightness values. Here is the function definition, which includes some default values for the constants.\n\\begin{lstlisting}\n1. def adjacency(img, radius=5.0, sigma_I = .15, sigma_d = 1.7):\n\\end{lstlisting}\n\nLater, our function will iterate through the rows of the adjacency matrix, initializing one row at a time. Each row corresponds to a pixel of the original image. Thus, we begin by flattening the image (see Figure \\ref{fig:adjacency}). We also store the dimensions of \\li{img} for later.\n\\begin{lstlisting}\n2.     flat_img = img.flatten()\n3.     height, width = img.shape\n\\end{lstlisting}\n\nNext we want to initialize the adjacency and degree matrices. As can be seen in Figure \\ref{fig:adjacency}, the adjacency matrix should be sparse, so we initialize it as a sparse matrix \\li{W}. The sparse matrix type \\li{lil_matrix} is optimized for building a matrix one entry at a time, which is what we will do. On the other hand, we only need to compute the diagonal of the degree matrix, so we initialize this diagonal as a regular NumPy array \\li{D}.\n\\begin{lstlisting}\n4.     W = spar.lil_matrix((flat_img.size, flat_img.size), dtype=float)\n5.     D = np.zeros((1, flat_img.size))\n\\end{lstlisting}\n\nNow for each pixel in the image, we initialize the corresponding row of the adjacency matrix. \nThe sum of the entries of this row will be the corresponding entry in \\li{D}. \n\nThe function \\li{getNeighbors} returns two flat arrays: \\li{indices} and \\li{distances} (code is provided at the end of this lab). The array \\li{indices} contains the indices of those pixels with \\li{radius} of the input \\li{pixel}. The array \\li{distances} contains the corresponding distances of those pixels from the input \\li{pixel} (all entries of \\li{distances} will be at most \\li{radius}). According to (\\ref{eq:adjacency}), the array \\li{indices} contains exactly the indices of the nonzero entries of the current row of \\li{W}.\\footnote{Note that \\li{W} will be a symmetric matrix. We could possibly speed up this function a lot by taking advantage of this fact.}\n\n\\begin{lstlisting}\n6.     for pixel in xrange(flat_img.size):\n7.         indices, distances = getNeighbors(pixel, radius, height, width)\n8.         weights = # weights[j] should be W[pixel, indices[j]]\n9.         W[pixel, indices] = weights\n10.        D[0,pixel] = weights.sum()\n\\end{lstlisting}\n\nFinally, we convert \\li{W} to the sparse matrix type \\li{csc_matrix}, which is faster for computations. Then we return \\li{W} and \\li{D}. \n\\begin{lstlisting}\n11.    W = W.tocsc()\n12.    return W, D\n\\end{lstlisting}\n\n\n\\begin{problem}\nFinish writing the function \\li{adjacency} described in this section by (a) adding comments and (b) filling in the following line.\n\\begin{lstlisting}\n8.         weights = # weights[j] should be W[pixel, indices[j]]\n\\end{lstlisting}\nYour computation should use (\\ref{eq:adjacency}) and take exactly one line.\n\nImages are typically stored as 2-D arrays of RGB values. To convert such an array to a 2-D array of brightness values, run the following code.\n\\begin{lstlisting}\n# read in the image\nimg_color = plt.imread('dream.png')\n# convert to grayscale\nimg = (img_color[:,:,0]+img_color[:,:,1]+img_color[:,:,2])/3.0\n\\end{lstlisting}\nTest your function on the image \\li{dream.png} (which is currently a 2-D array of RGB values).\n\n\n%Notice that for each pixel you can save time by only checking the pixels $r$ rows and columns away.\n%For that you'll have to handle the pixels on the edges and corners of the image carefully.\n%I gave them new helper code, which abstracts away the edge cases.\n\\label{prob:adjacency_dream}\n\\end{problem}\n\n\\subsection*{Minimizing the 'cut'}\n\nAs was mentioned before, we are trying to minimize the `cut', or the total weight of the edges we remove to create segments. \nLet $L$ be the Laplacian of the adjacency matrix defined in \\ref{eq:adjacency} and let $D$ be the degree matrix.\nShi and Malik proved that we can minimize the `cut' by finding the second smallest eigenvalue of $D^{-1/2}LD^{-1/2}$.\nBecause both $D$ and $L$ will be symmetric matrices, all eigenvalues of $D^{-1/2}LD^{-1/2}$ will be real, and so it makes sense to ask for the second smallest one.\n\nThe eigenvector associated to the second smallest eigenvalue will have $N^2$ entries, some positive and some negative. \nWe can reshape this vector to be an $N \\times N$ mask defining two segments, segments that correspond to the positive and negative values of the eigenvector.\nShi and Malik proved that these are the segments we desire. \n\nHere is the definition of a function that will segment an image.\n\\begin{lstlisting}\n1. def segment(img):\n\\end{lstlisting}\n\nWe use the function \\li{adjacency} from Problem \\ref{prob:adjacency_dream} to compute the adjacency matrix and the diagonal of the degree matrices of the image. \n\\begin{lstlisting}\n2.     W, D = adjacency(img)\n\\end{lstlisting}\n\nNext we create sparse matrices corresponding to $D$ and $D^{-1/2}$ in Shi and Malik's algorithm. Remember that the sparse matrix type \\li{csc_matrix} is best for computations.\n\\begin{lstlisting}\n3.     Dsq = # calculate the square root of D\n4.     D_matrix = spar.spdiags(D, 0, D.shape[1], D.shape[1], format = 'csc')\n5.     Dsq_matrix = # create a sparse matrix with diagonal Dsq\n\\end{lstlisting}\nNow it is simple to compute $D^{-1/2}LD^{-1/2}$. We call this matrix \\li{P}.\n\\begin{lstlisting}\n6.     L = # compute the Laplacian\n7.     P = # compute D^{-1/2}*L*D^{-1/2} as in Shi and Malik's algorithm\n\\end{lstlisting}\nAccording to Shi and Malik, we need the eigenvector corresponding to the second smallest eigenvalue of \\li{P}. We compute this with the \\li{eigs()} method of the \\li{scipy.sparse.linalg} module. We set the parameter \\li{which='SR'} in the function call in order to compute the eigenvalues with Smallest Real part and their corresponding eigenvectors. The parameter \\li{k} in the function call can be used to specify how many eigenvalues the method computes.\n\\begin{lstlisting}\n8.     e = # compute the two smallest eigenvalues of P and their eigenvectors\n9.     eigvec = # eigenvector of the second smallest eigenvalue\n\\end{lstlisting}\n\nNext we create a mask that is \\li{True} wherever \\li{eigvec} is positive and reshape it to be the size of \\li{img}. \n\\begin{lstlisting}\n10.    mask = # create mask\n\\end{lstlisting}\nOnce we have a mask of True-False values, we multiply it by the image entrywise. This zeros out the pixels in the matrix corresponding to the \\li{False} entries in the mask and leaves the pixels corresponding to \\li{True} entries unaffected. We can negate the mask using the tilde operator, which lets us compute the other segment of the image. Finally we return the two segments.\n\\begin{lstlisting}\n11.    pos = # compute positive segment\n12.    neg = # compute negative segment\n13.    return pos, neg\n\\end{lstlisting}\n\n\n\n\\begin{problem} Finish writing the function \\li{segment} described in this section by (a) adding comments and (b) filling in the missing lines. \nYou should be able to fill in these lines with exactly the space indicated. Test your function on the image \\li{dream.png}. Your segments should look like the segments in Figure \\ref{fig:dream_solution} (the original image is on the left). Here are some hints:\n\n\\begin{enumerate}\n\\item Note that in Line 6, you should NOT use your solution to Problem \\ref{prob:laplacian}, because in this problem we are working with sparse matrices, and you have already computed the degree matrix.\n\n\\item Also, in Line 7, multiply sparse matrices \\li{A} and \\li{B} with \\li{A.dot(B)}.\n\\item Here is some code that will plot the segments \\li{neg} and \\li{pos} as well as the original \\li{img}.\n\\begin{lstlisting}\nplt.subplot(131)\nplt.imshow(neg)\nplt.subplot(132)\nplt.imshow(pos)\nplt.subplot(133)\nplt.imshow(img_color)\nplt.show()\n\\end{lstlisting}\n\n\\end{enumerate}\n\n\\end{problem}\n\n\\begin{figure}\n\\centering\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{RegDream.png}\n    \\end{subfigure}\n    \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{NegDream.png}\n    \\end{subfigure}\n    \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{PosDream.png}\n    \\end{subfigure}\n\\caption{Segments of \\li{dream.png}}\n\\label{fig:dream_solution}\n\\end{figure}\n\n\\section*{Appendix: helper code for Problem \\ref{prob:adjacency_dream}}\nHere is the function \\li{getNeighbors} which you can use to compute the adjacency matrix of an image, as in Problem \\ref{prob:adjacency_dream}.\n\n\\lstinputlisting[style=fromfile]{getNeighbors.py}", "meta": {"hexsha": "09a329f8eaf72e469d1dc67b2194083ac0d2963f", "size": 26838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/ImageSegmentation/ImageSegment.tex", "max_stars_repo_name": "m4webb/numerical_computing", "max_stars_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/ImageSegmentation/ImageSegment.tex", "max_issues_repo_name": "m4webb/numerical_computing", "max_issues_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/ImageSegmentation/ImageSegment.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": 45.1818181818, "max_line_length": 673, "alphanum_fraction": 0.6900663239, "num_tokens": 8851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.6595113032591496}}
{"text": "\\section{The Chain Rule}\\label{sec:multivariable chain rules}\n\nConsider the surface $z=x^2y+xy^2$, and suppose that \n$x=2+t^4$ and $y=1-t^3$. We can think of the latter two equations as\ndescribing how $x$ and $y$ change relative to, say, time. Then\n$$z=x^2y+xy^2=(2+t^4)^2(1-t^3)+(2+t^4)(1-t^3)^2$$ \ntells us explicitly how the $z$ coordinate of the corresponding point on the\nsurface depends on $t$. If we want to know $dz/dt$ we can compute it\nmore or less directly, but it's actually a bit simpler to use product and chain\nrules:\n\\begin{align*}\n  {dz\\over dt}&=x^2y'+2xx'y+x2yy'+x'y^2\t\\\\\n  &=(2xy+y^2)x'+(x^2+2xy)y'\t\\\\\n  &=(2(2+t^4)(1-t^3)+(1-t^3)^2)(4t^3)+((2+t^4)^2+2(2+t^4)(1-t^3))(-3t^2)\t\\\\\n\\end{align*}\nIf we look carefully at the middle step,\n$dz/dt=(2xy+y^2)x'+(x^2+2xy)y'$, we notice that $2xy+y^2$ is $\\partial\nz/\\partial x$, and $x^2+2xy$ is $\\partial z/\\partial y$.\nThis turns out to be true in general, and gives us a new chain rule:\n\n\\begin{theorem}{Multivariate Chain Rule}{MultivariateChainRule}\nSuppose that $z=f(x,y)$, $f$ is differentiable,\n$x=g(t)$, and $y=h(t)$.\nAssuming that the relevant derivatives exist, \n$${dz\\over dt}={\\partial z\\over \\partial x}{dx\\over dt}+\n{\\partial z\\over \\partial y}{dy\\over dt}.\n$$\\index{chain rule!multivariate} \n\\end{theorem}\n\\begin{proof}\nIf $f$ is differentiable, then \n$$\\Delta z=f_x(x_0,y_0)\\Delta x+f_y(x_0,y_0)\\Delta y+\\epsilon_1\\Delta\nx + \\epsilon_2\\Delta y,$$\nwhere $\\epsilon_1$ and $\\epsilon_2$ approach 0 as \n$(x,y)$ approaches $(x_0,y_0)$. Then\n\\begin{equation}\\label{eq:dz over dt}\n{\\Delta z\\over\\Delta t}=\nf_x{\\Delta x\\over\\Delta t}+f_y{\\Delta y\\over\\Delta t}+\\epsilon_1{\\Delta\nx\\over\\Delta t} + \\epsilon_2{\\Delta y\\over\\Delta t}.\n\\end{equation}\nAs $\\Delta t$ approaches 0, $(x,y)$ approaches $(x_0,y_0)$ and so\n\\begin{align*}\n\\lim_{\\Delta t\\to0}{\\Delta z\\over\\Delta t} &=  {dz\\over dt}\t\\\\\n\\lim_{\\Delta t\\to0}\\epsilon_1{\\Delta x\\over\\Delta t} &= 0\\cdot{dx\\over dt}\t\\\\\n\\lim_{\\Delta t\\to0}\\epsilon_2{\\Delta y\\over\\Delta t} &= 0\\cdot{dy\\over dt}\t\\\\\n\\end{align*}\nand so taking the limit of~(\\ref{eq:dz over dt})\n as $\\Delta t$ goes to 0 gives \n$$\n{dz\\over dt}=\nf_x{dx\\over dt}+f_y{dy\\over dt},\n$$\nas desired.\n\\end{proof}\n\nWe can write the chain rule in a way that is somewhat closer to the\nsingle variable chain rule:\n$${df\\over dt}=\\langle f_x,f_y\\rangle\\cdot\\langle x',y'\\rangle,$$\nor (roughly) the derivatives of the outside function ``times'' the\nderivatives of the inside functions.\nNot surprisingly, essentially the same chain rule works for functions\nof more than two variables, for example, given a function of three\nvariables $f(x,y,z)$, where each of $x$, $y$ and $z$ is a function of\n$t$, \n$${df\\over dt}=\\langle f_x,f_y,f_z\\rangle\\cdot\\langle x',y',z'\\rangle.$$\n\nWe can even extend the idea further. Suppose that $f(x,y)$ is a\nfunction and $x=g(s,t)$ and $y=h(s,t)$ are functions of two variables\n$s$ and $t$. Then $f$ is ``really'' a function of $s$ and $t$ as well, and \n$${\\partial f\\over\\partial s}=f_xg_s+f_yh_s\\qquad\n{\\partial f\\over\\partial t}=f_xg_t+f_yh_t.$$\nThe natural extension of this to $f(x,y,z)$ works as well.\n\nRecall that we used the ordinary chain rule to do implicit\ndifferentiation\\index{implicit differentiation}. We can do the same\nwith the new chain rule.\n\n\\begin{example}{Equation of a Sphere}{EqSphereExample}\nFind the partial derivative of $x^2+y^2+z^2 = 4$.\n\\end{example}\n\\begin{solution}\nThe equation $x^2+y^2+z^2 = 4$ defines a sphere, which is not a function of\n$x$ and $y$, though it can be thought of as two functions, the top and\nbottom hemispheres. We can think of $z$ as one of these two functions,\nso really $z=z(x,y)$, and we can think of $x$ and $y$ as particularly\nsimple functions of $x$ and $y$, and let $f(x,y,z)=x^2+y^2+z^2$.\nSince $f(x,y,z)=4$, $\\partial f/\\partial x=0$, but\nusing the chain rule:\n\\begin{align*}\n0={\\partial f\\over\\partial x}&=f_x{\\partial x\\over\\partial x}+\nf_y{\\partial y\\over\\partial x}+f_z{\\partial z\\over \\partial x}\t\\\\\n&=(2x)(1)+(2y)(0)+(2z){\\partial z\\over\\partial x},\t\\\\\n\\end{align*}\nnoting that since $y$ is temporarily held constant its derivative\n${\\partial y/\\partial x}=0$. Now we can solve for $\\partial z/\\partial\nx$:\n$${\\partial z\\over \\partial x}=-{2x\\over 2z}=-{x\\over z}.\n$$\nIn a similar manner we can compute $\\partial z/\\partial y$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:multivariable chain rules}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nUse the chain rule to compute $dz/dt$ for\n$z=\\sin(x^2+y^2)$, $x=t^2+3$, $y=t^3$.\n\\begin{sol}\n$4xt\\cos(x^2+y^2)+6yt^2\\cos(x^2+y^2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUse the chain rule to compute $dz/dt$ for\n$z=x^2y$, $x=\\sin(t)$, $y=t^2+1$.\n\\begin{sol}\n$2xy\\cos t+2x^2t$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUse the chain rule to compute $\\partial z/\\partial s$ and \n$\\partial z/\\partial t$ for\n$z=x^2y$, $x=\\sin(st)$, $y=t^2+s^2$.\n\\begin{sol}\n$2xyt\\cos(st)+2x^2s$, $2xys\\cos(st)+2x^2t$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUse the chain rule to compute $\\partial z/\\partial s$ and \n$\\partial z/\\partial t$ for\n$z=x^2y^2$, $x=st$, $y=t^2-s^2$.\n\\begin{sol}\n$2xy^2t-4yx^2s$, $2xy^2s+4yx^2t$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUse the chain rule to compute $\\partial z/\\partial x$ and \n$\\partial z/\\partial y$ for $2x^2+3y^2-2z^2=9$.\n\\begin{sol}\n$x/z$, $3y/(2z)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUse the chain rule to compute $\\partial z/\\partial x$ and \n$\\partial z/\\partial y$ for $2x^2+y^2+z^2=9$.\n\\begin{sol}\n$-2x/z$, $-y/z$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}Chemistry students will recognize the {\\em ideal gas law}, given\n  by $PV=nRT$ which relates the Pressure, Volume, and Temperature of\n  $n$ moles of gas.  (R is the ideal gas constant).  Thus, we can view\n  pressure, volume, and temperature as variables, each one dependent\n  on the other two.\n\n\\begin{enumerate}\n\t\\item If pressure of a gas is increasing at a rate of $0.2\n\t  Pa/\\hbox{min}$ and temperature is increasing at a rate of $1\n\t  K/\\hbox{min}$, how fast is the volume changing?\n\t\\item If the volume of a gas is decreasing at a rate of $0.3\n\t  L/\\hbox{min}$ and temperature is increasing at a rate of $.5\n\t  K/\\hbox{min}$, how fast is the pressure changing?\n\t\\item If the pressure of a gas is decreasing at a rate of $0.4\n\t  Pa/\\hbox{min}$ and the volume is increasing at a rate of $3\n\t  L/\\hbox{min}$, how fast is the temperature changing?\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$\\ds V'=(nR-0.2V)/P$\n\t\\item\t$\\ds P'=(nR+0.6P)/2V$\n\t\\item\t$\\ds T' = (3P-0.4V)/(nR)$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nVerify the following identity in the case of the ideal gas law:\n$${\\partial P\\over \\partial V} {\\partial V\\over \\partial T} \n{\\partial T\\over \\partial P}=-1$$\n\\end{ex}\n\n\\begin{ex}\nThe previous exercise was a special case of the following\nfact, which you are to verify here: If $F(x,y,z)$ is a function of 3\nvariables, and the relation $F(x,y,z)=0$ defines each of the variables\nin terms of the other two, namely $x=f(y,z)$, $y=g(x,z)$ and\n$z=h(x,y)$, then\n$${\\partial x\\over \\partial y} {\\partial y\\over \\partial z} \n{\\partial z\\over \\partial x}=-1$$\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "a728caa3bd2a32aaf6adfe464acc65201e4b310b", "size": 7146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-4-partial-diff-chain-rule.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-4-partial-diff-chain-rule.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-4-partial-diff-chain-rule.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": 35.552238806, "max_line_length": 79, "alphanum_fraction": 0.6719843269, "num_tokens": 2606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370421, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6594502957649254}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amsfonts}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{enumitem}\n\\usepackage{listings}\n\\usepackage{soul}\n\n\\title{Depth First Learning Problem Set 1: Signal propagation}\n\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 1: NN Signal propagation framework}\n\nIn this problem, we will work with the basic framework for analyzing signal propagation in a feedforward neural networks as the width of the network's hidden layers grows towards infinity.  \n\nTo set up the notation, let $x^0 \\in \\mathbb{R}^{di}$ be the (vector-valued) input to the network.  Each layer, $l$, of the network, is a function from $\\mathbb{R}^N \\rightarrow \\mathbb{R}^N$ defined via the two equations:\n\\begin{eqnarray}\nh^l &=& W^l x^{l-1} + b^l \\\\\nx^l &=& \\phi(h^l)\n\\end{eqnarray}\nHere $x^{l-1}$ is the input to the layer, $x^l$ is the output, $W^l$ is an $N\\times N$ matrix containing the layer's weights, and $b^l$ is an $N$-dimensional vector containing the layer's biases.  The function $\\phi$ is the nonlinearity (e.g., sigmoid, ReLU, etc.) used by the network.  We sometimes call the inputs to the nonlinearity ($h^l$) the \\emph{pre-activations}, and we call the outputs of the nonlinearity (which are also the outputs of the layer) the \\emph{activations}.\n\nNote here that we are considering a specific neural-netowrk architecture in which the number of hidden units does not vary from layer to layer, i.e. each layer is $N$-dimensional.  \n\n\\begin{enumerate}[label=(\\alph*)]\n\\item To initialize the network, we usually draw the weights and biases randomly from some distribution.  Let's ignore the bias term for now (i.e. set $b^l=0$ for all layers $l$).  Since the pre-activations $h^l$ are functions of the random variables, they themselves are (vector-valued, $N$-dimensional) random variables. We want to understand what we can say about the distribution of the $h^l$'s as we move through layers of the network, i.e. as a function of $l$.  \n\nSuppose we initialize each weight matrix $W^l$ from a zero-mean Gaussian with variance $\\sigma^2$, i.e. $W^l \\sim \\mathcal{N}(0, \\sigma^2)$. For simplicity, assume the nonlinearity is just the identity function.  We will relax this assumption in the subsequent problems.  \n\n\n\\textbf{What are the mean and variance of the distribution of a single-component, $h^l_i$ of $h^l$, given the mean and the variance of the the previous layer's preactivations ($h^{l-1}_i$)?}\n\n\n\\item You should find in the previous part that the mean of the distribution of $h^l_i$ is always zero, but that each layer of the network multiplies the variance of the distribution by a factor of $N\\sigma^2$.  Typically, the variance of the distribution of pre-activations is a proxy for how much of the nonlinearity we're making use of (e.g. for the sigmoid, if the variance is very small, we're basically in the linear region of the nonlinearity).  To be able to vary the number of layers in a network and not have the behavior change too much, we'd like to have an initialization strategy which keeps the variance of the $h^l$ distribution the same as we change the number of layers.  Clearly, our current strategy ($W^l \\sim \\mathcal{N}(0, \\sigma^2)$) doesn't accomplish this. \n\n\\textbf{Suggest a simple modification of the initialization strategy which would achieve this goal.}\n\n\n\\item Now let's add back in the bias term.  Imagine that we initialize according to a simple zero-mean Gaussian, where the variance (as for the weights in part (a)) was independent of the number of hidden units $N$, that is $b^l \\sim \\mathcal{N}(0, \\sigma_b^2)$.  \n\n\\textbf{Does this initialization suffer from the same problem as the weight initialization described in part (b)?  If so, how can we fix it?}\n\n\\end{enumerate}\n\n\\section*{Problem 2: $N\\rightarrow\\infty$ and the mean-field approximation}\n\nIn this problem, we use the knowledge we gained in problem 1 to properly choose to initialize the weights and biases according to $W^l \\sim \\mathcal{N}(0, \\sigma_w^2/N)$ and $b^l \\sim \\mathcal{N}(0, \\sigma_b^2)$. We'll investigate some techniques that will be useful in understanding precisely how the network's random initialization influences what the net does to its inputs; specifically, we'll be able to take a look at how the \\textit{depth} of the network together with the initialization governs the propagation of an input point as it flows forward through the network's layers.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item \\textbf{A natural property of input points to study as the input flows through the net layer by layer is its length. Intuitively, this is closely related to how the net transforms the input space, and to how the depth of the net relates to that transformation. Compute the length $q^l$ of the activation vector outputted by layer $l$. When considering non-rectangular nets, where layer $l$ has length $N_l$, we want to distinguish this activation norm from the width of individual layers, so what's a more appropriate quantity we can track to understand how the lengths of activation vectors change in the net?}\n\n\\item \\textbf{What probabilistic quantity of the neuronal activations does $q^l$ approximate (with the approximation improving for larger $N$)?}\n\n\\textit{Hint: Recall that all neuronal activations $h^l_i$ are zero-mean, and consider the definition of $q^l$ from part (a) in terms of the empirical distribution of $h^l_i$.}\n\n\\item \\textbf{Calculate the variance of an individual neuron's pre-activations, that is, the variance of $h_i^l$.  Your answer should be a recurrence relation, expressing this variance in terms of $h^{l-1}$ (and the parameters $\\sigma_w$ and $\\sigma_b$}).\n\n(Note 1: You basically did this in problem 1; the differences here are just that the weights are initialized slightly differently and that the bias term exists, and now the noninearity is not just the identity)\n\n(Note 2: This part of the problem does not yet assume that $N\\rightarrow \\infty$)\n\n\\item Now consider the limit that the number of hidden neurons, $N$, approaches infinity.  \n\n\\textcolor{red}\n\n\\textbf{Use the central limit theorem to argue that in this limit, the pre-activations will be zero-mean Gaussian distributed. Be explicit about the conditions under which this result holds.}\n\n\\item With this zero-mean Gaussian approximation of $q^l$, we have a single parameter characterizing this aspect of signal propagation in the net: the variance, $q^l$, of individual neuronal activations (a proxy for squared activation vector lengths). Let's now look at how this variance changes from layer to layer, by deriving the relationship between $q^l$ and $q^{l - 1}$.\n\n\\textbf{In part (a), your answer should have included a term $\\langle (x^{l-1})^2 \\rangle$.  In terms of the activation function $\\phi$ and the variance $q^{l-1}$, write this expectation value as an integral over the standard Gaussian measure.}\n\n\\textbf{Use this result to write a recursion relation for $q^l$ in  terms of $q^{l-1}$, $\\sigma_w$, and $\\sigma_b$}.\n\n\\end{enumerate}\n\n\\section*{Problem 3: Fixed points and stability}\n\nIn the previous problem, we found a recursion relation relating the length of a vector at layer $l$ of a network to the length of the vector at the previous layer, $l-1$ of the network.  In this problem, we are interested in studying the properties of this recursion relation.  In the \\emph{Resurrecting the sigmoid} paper, the results of this problem are used to understand at which bias point to evaluate the Jacobian of the input-output map of the network.  For more information on this topic, see either of the two papers which are suggested reading for this week:\n\\begin{itemize}\n\t\\item \\emph{Exponential expressivity in deep neural networks through transient chaos}\n\t\\item \\emph{Deep information propagation}\n\\end{itemize} \n\nNote that in this problem, we are just taking the recursion relation as a given, i.e. we do not need to worry about random variables or probabilities; all of that went into determining teh recursion relation.  \n\n\\begin{enumerate}[label=(\\alph*)]\n\\item A simple example of a dynamical system is a recurrence defined by some initial value $x_0$ and a relation $x_n = f(x_{n-1})$ for all $n>0$.  This system defines the resulting sequence $x_n$.  Sometimes, these systems have \\emph{fixed points}, which are values $x^*$ such that $f(x^*) = x^*$.\n\n\\textbf{If the value of the system, $x_m$, at some time-step $m$, happens to be a fixed point $x^*$, what is the subsequent evolution of the system?}\n\n\\item \\textbf{For the recurrence relation you derived in the previous problem, what is the equation which a fixed-point of the variance, $q^*$, must satisfy?}  \n\n\\textbf{Under some conditions (i.e. for some values of $\\sigma_w$ and $\\sigma_b$), the value $q^*=0$ is a fixed point of the system.  What are these conditions?}\n\n\\item Now let us be concrete, and look at the recurrence relation in the special case of a nonlinearity $\\phi(h)$ which is both monotonically increasing and satisfies $\\phi(0) = 0$.  Note that both of the nonlinearities considered in the paper we are studying, the $tanh$ and ReLU nonlinearities, satisfy this property.  \n\n\\textbf{Show that those two properties (monotonicity and $\\phi(0)=0$) imply that the length map $q^l(q^{l-1})$ is monotonically increasing.}\n\n\\textbf{Optional: Show that these two properties imply that the length map $q^l(q^{l-1})$ is a concave function.} \n\n(Note: We have not managed to prove this ourselves (and not for lack of trying!), so feel free to skip)\n\n\\textbf{What is the maximum number of times any concave function can intersect the line $y = x$?  What does this imply about the number of fixed points the length map $q^l(q^{l-1})$ can have?}\n\n\\item Let's be concrete now and consider the nonlinearity to be a ReLU.  \n\n\\textbf{Compute (analytically) the length map $q^l = f(q^{l-1})$, which will also depend on $\\sigma_w$ and $\\sigma_b$.  For what values of $\\sigma_w$ and $\\sigma_b$ does the system have fixed point(s)? How does the value of the fixed point depend on $\\sigma_w$ and $\\sigma_b$? }\n\n\n\\item Now let's consider the sigmoid nonlinearity $\\phi(h) = tanh(h)$.  In this case the length map cannot be computed analytically, but it can be done numerically.  \n\n\\textbf{Numerically plot the length map, $q^l=f(q^{l-1})$, for a few values of $\\sigma_w$ and $\\sigma_b$ in the following regimes: (i) $\\sigma_b=0$ and $\\sigma_w < 1$, (ii) $\\sigma_b = 0$ and $\\sigma_w > 1$, and (iii) $\\sigma_b > 0$.  Describe qualitatively the fixed points of the map in each regime.}\n\n\\item Let’s now talk about the stability of fixed points. In a dynamical system, once the system reaches (or starts at) a fixed point, by definition it can never leave. But what happens if the system gets or starts near a fixed point?  In real physical systems, this question is very relevant because physical systems almost always have some noise which pushes the system away from a fixed point.  \n\nIn general, the fixed point can be either stable or unstable.  For a stable fixed point, initializing the system near the fixed point will result in behavior which converges to the fixed point, i.e reducing the magnitude of the perturbation away from the fixed point.  Conversely, for an unstable fixed point, the system initialized nearby will be repelled from the fixed point.  \n\n\\textbf{Relate the stability of a particular fixed point to the derivative of the length map evaluated at that fixed point.}\n\n\\item With this understanding of stability, revisit your result in part (e) for the $tanh$ nonlinearity.\n\n\\textbf{Specifically, discuss the stability of the fixed points in each of the three regimes.  You can evaluate the derivative of the length map by looking at the graphs.}\n\n\\item \\textbf{Do the same stability analysis for the ReLU network.} \n\n\\item \\textbf{(Optional) You should have found above that the both the ReLU and $tanh$ systems never had more than one stable fixed point.  Show that this is a consequence of the concavity of the length map.}\n\n(Hint: You can just draw a picture for this one)\n\n\\end{enumerate}\n\n\\section*{Problem 4: Correlation maps}\n\nIn the previous problem, we discovered a very interesting property of wide neural networks: the existence of fixed points of activation vector lengths.  In this problem, we will explore a similar analysis for correlations between activations due to different inputs to the network and connect this to vanishing/exploding gradients.\n\nDefine the correlation $q_{12}^l$ between two inputs $x^{0,1}$ and $x^{0,2}$ at the $l^{th}$ layer of the network via the following inner product:\n\\begin{equation}\n    q^l_{12} = \\frac{1}{N_L} \\sum_{i=1}^{N_l} h_i^l(x^{0,1}) h_i^l(x^{0,2}),\n\\end{equation}\nwhere the notation $h_i^l(x^{0,1})$ means the pre-activation of the $i^{th}$ neuron of the $l^{th}$ layer of the network given the input $x^{0,1}$.  \n\n\\begin{enumerate}[label=(\\alph*)]\n\n\\item As in the previous problem, though the quantity $q_{12}^l$ is defined for a specific realization of the network, averaged over all neurons, we can use the self-averaging assumption treat this as an estimate of a quantity which characterizes a single neuron but averaged over realizations of the network.  \n\n\\textbf{What is this quantity?  (It is a quantity that comes up quite often when dealing with correlated random variables)}\n\n\\item Now we want to find a recurrence relation to describe the behavior of $q_{12}^l$ as we go through the network.  \n\n\\textbf{Show that}\n\\begin{align*}{q_{12}^{l}=\\mathcal{C}\\left(c_{12}^{l-1}, q_{11}^{l-1}, q_{22}^{l-1} | \\sigma_{w}, \\sigma_{b}\\right) \\equiv \\sigma_{w}^{2} \\int \\mathcal{D} z_{1} \\mathcal{D} z_{2} \\phi\\left(u_{1}\\right) \\phi\\left(u_{2}\\right)+\\sigma_{b}^{2}} \\\\ {u_{1}=\\sqrt{q_{11}^{l-1}} z_{1}, \\quad u_{2}=\\sqrt{q_{22}^{l-1}}\\left[c_{12}^{l-1} z_{1}+\\sqrt{1-\\left(c_{12}^{l-1}\\right)^{2}} z_{2}\\right]},\\end{align*}\n\\textbf{where $\\mathcal{D} z_{1}$ and $\\mathcal{D} z_{2}$ indicate integration with respect to two independent standard normal (Gaussian) variables $z_1$ and $z_2$.  Here $c_{12}^l = q_{12}^l (q^l_{11} q^l_{22})^{-1/2}$ is known as the correlation coefficient.}\n\n(Hint: don't be scared by the ugly-looking definitions of $u_1$ and $u_2$.  This is just done so that we can have the integral over independent Gaussians.  Once you have an expression in terms of dependent Gaussians, a simple change-of-variables should get the result you see above.)\n\n\\item Once you have arrived at the above recurrence relation, note that you have a dynamical system which determines the value of $q_{12}^l$ in terms of $q_{12}^{l-1}$, $q_{11}^{l-1}$, and $q_{22}^{l-1}$.  You know from the previous problem, however, that $q_{11}^{l-1}$ and $q_{22}^{l-1}$ converge to fixed points.  Though you'll have to take it on faith for now, it turns out that the convergence of these values to their fixed point happens quickly (compared to the dynamics of $q_{12}^l$), so it is a reasonable approximation to just replace $q_{11}^{l-1}$ and $q_{22}^{l-1}$ with $q^*$.\n\nAlso, in the following we will be interested not in $q_{12}^l$ itself but instead $c_{12}^l$ (defined above).\n\n\\textbf{In terms of} $\\mathcal{C}\\left(c_{12}^{l-1}, q_{11}^{l-1}, q_{22}^{l-1} | \\sigma_{w}, \\sigma_{b}\\right)$\\textbf{, what is the recurrence relation for the quantity $c_{12}^l$?}\n\n\\item \\textbf{What are the allowed values of $c_{12}^l$?}\n\n\\item It turns out that the recurrence relation you derived above always has a fixed point at $c^* = 1$.  \n\n\\textbf{Show this analytically, and then argue why you could have arrived at this result without any calculation.}\n\n\\item Now let's examine the stability of the fixed point $c^* = 1$.  To do this, as before, we look at the derivative of the recurrence relation, i.e. $dc^l_{12}/dc^{l-1}_{12}$, evaluated at the point $c^* = 1$.  We will call this quantity $\\chi$.  It can be shown that \n\\begin{equation}\n    \\chi = \\sigma_w^2 \\int~\\mathcal{D}z \\left[\\phi'(\\sqrt{q^*} z)\\right]^2\n\\end{equation}\n\n\\textbf{If you want, prove the above relation.  Since this is just algebra and not too instructive, feel free to skip this part. }\n\n\\end{enumerate}\n\n\\section*{Problem 5: Connection between $\\chi$ and exploding/vanishing gradients}\n\nIn the previous problem, we saw that a unit correlation coefficient (the highest value which is allowed) is a fixed point under evolution through the neural network.  However, it was not always stable.  The stability depended on whether the quantity $\\chi$, defined as the derivative of $dc_{12}^l/dc^{l-1}_{12}$, is greater or less than 1.  In this problem, we want to understand the connection between the quantity $\\chi$ and exploding or vanishing gradients.  \n\nA starting point to understand the connection between $\\chi$ and gradients is to consider what it means for the fixed point $c^*=1$ to be stable or unstable.  If $\\chi > 1$, and the fixed point $c^* = 1$ is thus unstable, then two input vectors which are highly correlated will de-correlate as they are processed by the network.  Conversely, if $\\chi < 1$, then two vectors will become more correlated as they are processed.  Thus it seems like if $\\chi > 1$, space is stretched, while if $\\chi < 1$, space is contracted.  In this problem we find that $\\chi$ is precisely the factor by which space is streched or contracted by each layer of the neural network.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Start by considering a plain linear transformation, $\\mathbf{y} = \\mathbf{J}\\mathbf{x}$, where $\\mathbf{x}$ and $\\mathbf{y}$ are vectors and $\\mathbf{J}$ is a matrix. \n\n\\textbf{Averaged over all possible directions in which $\\mathbf{x}$ can point, what is the ratio of the squared length of $\\mathbf{y}$ to that of $\\mathbf{x}$, in relation to the singular values of $\\mathbf{J}$?}\n\n\\item Consider the transformation enacted by layer $l$ of a neural network, \n\\begin{equation}\nh^l &=& W^l \\phi(h^{l-1}) + b^l. \n\\end{equation}\nLet $\\mathbf{D}$ be a diagonal matrix whose entries are $D_{ii} = \\phi'(h_i^{l-1})$.  \n\n\\textbf{In terms of $W^l$ and $D$, what is the Jacobian of the transformation $h^{l-1}\\rightarrow h^l$?}\n\n\\textbf{From the problem above, we want the mean-squared singular value of the Jacobian.  Show that this mean-squared singluar value is exactly equal to the expression for $\\chi$ calculated earlier, when we take the expectation with respect to the distribution of the weight matrix and the distribution of the pre-activations}\n\n\\item How does the value of $\\chi$ relate to exploding and vanishing gradients?\n\n\\item To emphasize that $\\chi$ is a function of $\\sigma_w$ and $\\sigma_b$, we go back to the expression for $\\chi$, \n\\begin{equation}\n    \\chi = \\sigma_w^2 \\int~\\mathcal{D}z \\left[\\phi'(\\sqrt{q^*} z)\\right]^2,\n\\end{equation}\nand explicitly write the dependence of the fixed point $q^*$ on $\\sigma_w$ and $\\sigma_b$.  Remember that this dependence can be written implicitly via the equation\n\\begin{equation}\nq^{*}=\\sigma_{w}^{2} \\int \\phi\\left(\\rho \\sqrt{q^{*}}\\right)^{2} \\mathrm{d} \\rho+\\sigma_{b}^{2}.\n\\end{equation}\n\n\\textbf{Numerically calculate the value of $\\chi$ for several values of $\\sigma_w$ and $\\sigma_b$, for the hyperbolic tangent nonlinearity.  Make a contour plot, and specifically indicate the curve corresponding to $\\chi=1$}\n\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "265e35c4392fb1a11e8896ddb7b44c2a20091683", "size": 19388, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/sigmoid/problem-sets/source/4/problems.tex", "max_stars_repo_name": "skroon/depthfirstlearning.com", "max_stars_repo_head_hexsha": "326c2a5de7497c2383caae937753da3309506e7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 192, "max_stars_repo_stars_event_min_datetime": "2018-06-06T16:01:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T16:56:14.000Z", "max_issues_repo_path": "assets/sigmoid/problem-sets/source/4/problems.tex", "max_issues_repo_name": "skroon/depthfirstlearning.com", "max_issues_repo_head_hexsha": "326c2a5de7497c2383caae937753da3309506e7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-06-05T02:46:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T08:43:34.000Z", "max_forks_repo_path": "assets/sigmoid/problem-sets/source/4/problems.tex", "max_forks_repo_name": "skroon/depthfirstlearning.com", "max_forks_repo_head_hexsha": "326c2a5de7497c2383caae937753da3309506e7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2018-06-07T06:08:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-26T09:25:16.000Z", "avg_line_length": 87.7285067873, "max_line_length": 783, "alphanum_fraction": 0.7422116773, "num_tokens": 5272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384735, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6594502788874748}}
{"text": "\n\\section{Conclusions}\n\\label{sec:conclusions}\n\nIn the following table we collect congruences proved in previous sections, \nrespect to $\\equiv_{2}$ over coefficients $c_{n,k}=\\frac{k+1}{n+1}{{2n-k}\\choose{n-k}}\\in\\mathcal{C}$ :\n\\begin{displaymath}\n    \\begin{split}\n        & \\frac{1}{n+1}{{2n}\\choose{n}} \\equiv_{2} 1 \\leftrightarrow \\exists \\alpha\\in\\mathbb{N}: n=2^{\\alpha}-1  \\\\\n        & \\forall\\alpha\\in\\mathbb{N}:\\frac{k+1}{2^{\\alpha}}{{2^{\\alpha+1}-2-k}\\choose{2^{\\alpha}-1-k}} \\equiv_{2} 1  \\\\\n        & \\forall\\alpha\\in\\mathbb{N}:\\frac{k+1}{2^{\\alpha}+1}{{2^{\\alpha+1}-k}\\choose{2^{\\alpha}-k}} \\equiv_{2} 0 \\leftrightarrow \\exists j\\in\\mathbb{N}: k=2j+1   \\\\\n        & \\forall\\alpha\\in\\mathbb{N}:\\frac{2^{\\alpha}}{s+1}{{2s-2^{\\alpha}+1}\\choose{s-2^{\\alpha}+1}} \\equiv_{2} 0 \\leftrightarrow \n            s\\in\\lbrace 2^{\\alpha}, \\ldots, 2^{\\alpha+1}-2\\rbrace  \\\\\n        & \\forall\\alpha\\in\\mathbb{N}:\\frac{s-2^{\\alpha}+2}{s+1}{{s+2^{\\alpha}-1}\\choose{2^{\\alpha}-1}} \\equiv_{2}\n            \\frac{2^{\\alpha}}{s+1}{{2s-2^{\\alpha}+1}\\choose{s-2^{\\alpha}+1}} \\leftrightarrow \n                s\\in\\lbrace 2^{\\alpha}, \\ldots, 2^{\\alpha+1}-2\\rbrace  \\\\\n        & \\frac{k+1}{n+1}{{2n-k}\\choose{n-k}} \\equiv_{2} 0 \\leftrightarrow \n            n \\in\\lbrace 2^{\\alpha}, \\ldots, 2^{\\alpha+1} - 2\\rbrace \\wedge k \\in \\lbrace 0, \\ldots, n - 2^{\\alpha}\\rbrace \\\\\n    \\end{split}\n\\end{displaymath}\n\nThe following two congruences hold if and only if $\\alpha\\in\\mathbb{N} \\wedge e\\in\\lbrace1,\\ldots,s-2^{{\\alpha}}\\rbrace$:\n\\begin{displaymath}\n    \\begin{split}\n        & {{2s-e-2^{{\\alpha}}+1}\\choose{s-e}} - {{2s-e-2^{{\\alpha}}+1}\\choose{s-e+1}} \\equiv_{2}\n            {{2s-2^{{\\alpha}}+1-e}\\choose{s}} - {{2s-2^{{\\alpha}}+1-e}\\choose{s+1}}\\\\\n        & {{2s-2^{{\\alpha}}+1-e}\\choose{s}} - {{2s-2^{{\\alpha}}+1-e}\\choose{s+1}} \\equiv_{2}\n            {{2s-2^{{\\alpha}+1}-e+1}\\choose{s-2^{{\\alpha}}}} - {{2s-2^{{\\alpha}+1}-e+1}\\choose{s-2^{{\\alpha}}+1}}\\\\\n    \\end{split}\n\\end{displaymath}\n\nTo summarize our work, we provide a study of the congruence\n$\\equiv_{2}$ mapped to the Catalan array $\\mathcal{C}$, both a formal\napproach to characterize different regions and implementations are\ngiven. Even though array $\\mathcal{P}_{\\equiv_{2}}$ is very\ninteresting and deeply studied, is our opinion that\n$\\mathcal{C}_{\\equiv_{2}}$ should deserve interest as well because of\nits recursive flavor and connection to universal counting Catalan\nnumbers and combinatorial objects.\n\nWe finish pointing out directions for further studies: we would like\nto understand how a generalization to congruence $\\equiv_{p}$, for $p$\nprime, can be proved using either a closed formula for the generic\ncoefficient or algebraic generating function manipulations; at last,\nfind a modular characterization of $\\mathcal{C}_{\\equiv_{2}}^{-1}$,\nthe inverse group element of $\\mathcal{C}_{\\equiv_{2}}$, depicted in\n\\autoref{fig:catalan-traditional-inverse-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-triangle}.\n\n\\input{catalan/catalan-traditional-inverse-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-include-figure.tex}\n", "meta": {"hexsha": "2d780341d6e4dc29470bc4f04effd229421e6714", "size": 3113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modular-article/conclusions.tex", "max_stars_repo_name": "massimo-nocentini/master-thesis", "max_stars_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modular-article/conclusions.tex", "max_issues_repo_name": "massimo-nocentini/master-thesis", "max_issues_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modular-article/conclusions.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": 62.26, "max_line_length": 165, "alphanum_fraction": 0.6469643431, "num_tokens": 1112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6593420800102723}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%% Supplemental Material%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\\clearpage\n%\\newpage\n\\section{Choosing Window Size}\nIn genome-wide scans for detecting selection, we apply the \\comale\\\nstatistic on sliding windows of length $L$bp. The single locus\nstatistic values within the window are averaged to get the composite\nstatistic. While the statistic is robust to variation in window-size,\nchoosing a very large window where LD has decayed will weaken the\ncomposite signal, and choosing a small window will decrease the power\nof composite likelihoods. Here, we use a systematic calculation to\nchoose $L$ as the distance where the LD between the favored mutation\nand a site $L/2$bp away remains strong.\n\\label{sec:winSize}\n\\ignore{\nThe optimum\nchoice of window size depends on the linkage disequilibrium (LD)\nbetween the favored allele and its nearby variants.  In an E\\&R\nselection experiment, dynamic of the exact LD between the favored\nallele to other variants depends on a number of parameters including\nrecombination rate ($r$), genomic distance ($l$), LD at the onset of\nselection ($\\rho_0$), initial frequency of the favored allele\n($\\nu_0$), strength of selection ($s$) and span of experiment\n($\\tau$). Moreover, observed LD, additionally depend on the sample\nsize $n$ and sequencing coverage. For simplicity we exclude sampling\nnoise due to finite sampling for sequencing and finite sequencing\ncoverage in our analysis.\n}\n\n\nConsider a segregating site $l$ bp away from the favored allele in a\nselective sweep.  Let $\\rho_\\tau$ be the LD between the favored allele\nand the site, $\\tau$ generations after the onset of selection. Then,\nwe have (see Eqs. 30-31 in \\cite{stephan2006hitchhiking}): \n\\beq\n\\rho_\\tau= \\alpha_\\tau\\beta_\\tau \\rho_0=e^{-r\\tau l}\n\\left(\\frac{K^{(\\tau)}}{K^{(0)}}\\right)\\rho_0\\label{eq:ldt}, \n\\eeq\nwhere $K^{(\\tau)}=2\\nu_\\tau(1-\\nu_\\tau)$ is the heterozygosity at the\nselected site, $r$ is the recombination rate (crossovers/bp/gen). The\n`decay factor', $\\alpha_\\tau=e^{-r\\tau l}$, and `growth factor',\n$\\beta_\\tau$, are due to recombination and selection, respectively.\nUnder regular parameter settings, linkage to the favored allele is\nexpected to increase after onset of selection and then \ndecreases due to crossover events\n(See~\\ref{fig:winSize}-A).  While $\\rho_0$ is\nunknown in pool-seq E\\&R experiments, we compute the value of $l$ so\nthat\n\\beq\n\\alpha_\\tau \\beta_\\tau=1.\\label{eq:eq}\n\\eeq\nIn E\\&R scenarios, we let $\\tau$ be the time of the last sampling. For\ngiven $s$, we aim to compute the smallest window size $L$ over all\npossible starting frequencies. Specifically,\n\n\\beq L=2\\min_{\\nu_0} \\left\\{\n  \\frac{1}{r\\tau}\\log\\left(\\frac{\\hat{\\nu}_\\tau(1-\\hat{\\nu}_\\tau)}{\\nu_0(1-\\nu_0)}\\right)\\right\\},\n  \\label{eq:winSize}\n\\eeq \nwhere the term $\\hat{\\nu}_\\tau$ depends on initial frequency\n$\\nu_0$ and selection strength $s$ (Eq.~\\ref{eq:transition}).\n\n\nWe used \\dmel dataset parameters, $N=250,r=2\\times10^{-8}$ and\n$\\tau=59$ to compute the optimal window size for different values of\n$Ns$, ranging from weak selection to strong selection:\n$Ns\\in\\{20,100,200,500\\}$, or $s\\in\\{0.08,0.4,0.8,2\\}$.  We set\n$L=30$Kbp (See~\\ref{fig:winSize}-B) to provide good resolution for\ndetecting weak selection.\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "0874eb075782e144afcd05c6e2d0016d09681f9b", "size": 3312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/supplemental.tex", "max_stars_repo_name": "airanmehr/timeseries_paper", "max_stars_repo_head_hexsha": "9efc1c849883219fcf0236f64357092159c53140", "max_stars_repo_licenses": ["MIT"], "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/supplemental.tex", "max_issues_repo_name": "airanmehr/timeseries_paper", "max_issues_repo_head_hexsha": "9efc1c849883219fcf0236f64357092159c53140", "max_issues_repo_licenses": ["MIT"], "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/supplemental.tex", "max_forks_repo_name": "airanmehr/timeseries_paper", "max_forks_repo_head_hexsha": "9efc1c849883219fcf0236f64357092159c53140", "max_forks_repo_licenses": ["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.4, "max_line_length": 98, "alphanum_fraction": 0.7195048309, "num_tokens": 941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6593420739748955}}
{"text": "\\documentclass{beamer}\n\n\\input{../../shared_slides.tex}\n\\DeclareMathOperator*{\\perm}{perm}\n\n\\title{Matrix scaling}\n\n\\begin{document}\n\\maketitle\n\\frame{\\tableofcontents}\n\n\\section{Introduction}%\n\n\\begin{frame}\n  \\frametitle{Introduction}\n  \\textbf{given:} a matrix $A \\in \\R^{m\\times n}_+$, vectors $r \\in \\R_{++}^m$ and $c \\in \\R^n_{++}$\\\\\n  \\textbf{find:} diagonal matrices $X$ and $Y$ such that for $B = XAY$ it holds:\n  \\begin{equation}\n    B \\mathbbm{1}_n = r \\quad \\text{and} \\quad B^T \\mathbbm{1}_m = c\n  \\end{equation}\n  where $\\mathbbm{1}_n = (1, \\dots, 1)$ exactly $n$-times.\n  Equivalently\n  \\begin{equation}\n    \\Vert B_{i,:} \\Vert_1 = r_i \\quad \\text{and} \\Vert B_{:, j} \\Vert = c_j.\n  \\end{equation}\n\n  \\begin{block}{}\n    In this case $A$ is called $(r,c)$-scalable.\n  \\end{block}\n  \\onslide<2->{%\n    If $\\Vert r \\Vert_1 \\neq \\Vert c \\Vert_2$ this is not possible.\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Visualization of diagonal scaling}\n\n  \\begin{equation}\n    \\begin{aligned}\n    B = \\begin{bmatrix}\n      x_1 & & & \\\\\n      & x_2 & & \\\\\n      & & \\ddots & \\\\\n      & & & x_m\n    \\end{bmatrix}\n    A\n    \\begin{bmatrix}\n      y_1 & & & \\\\\n      & y_2 & & \\\\\n      & & \\ddots & \\\\\n      & & & y_n\n    \\end{bmatrix}\n    \\\\\n    =\n    \\begin{bmatrix}\n      a_{1,1}x_1y_1 & a_{1,2}x_1y_2 & \\cdots & a_{1,n} x_1y_m \\\\\n      \\vdots   & \\ddots & & \\\\\n      a_{m,1}x_m y_1 & & \\cdots & a_{m,n}x_m y_m\n    \\end{bmatrix}\n    \\end{aligned}\n  \\end{equation}\n  \\begin{block}{\\textbf{Application:} Ill conditioned linear system $Az = b$.}\n    Can multiply both sides by $X$  and substitute $z= Yv$ to get instead\n    \\begin{equation}\n      XAz = X\n    \\end{equation}\n  \\end{block}\n\\end{frame}\n\n\\section{Matchings}%\n\\label{sec:}\n\n\\begin{frame}\n  \\frametitle{$(0-1)$ matrices | bipartite graphs}\n  \\begin{minipage}{0.5\\textwidth}\n    \\begin{equation}\n      \\begin{bmatrix}\n        0 & 1 & 1 \\\\\n        1 & 0 & 0 \\\\\n        0 & 1 & 1\n      \\end{bmatrix}\n    \\end{equation}\n  \\end{minipage}\n  \\begin{minipage}{0.25\\textwidth}\n    \\begin{figure}[ht]\n      \\centering\n      \\includegraphics[width=\\textwidth]{bipartite-graph.png}\n      \\caption{bipartite graph}\n    \\end{figure}\n  \\end{minipage}\n\n  \\onslide<2->{%\n    \\begin{definition}\n      A \\textbf{matching} is a set of edges without common vertices.\n    \\end{definition}\n    % Say something about applications of matching like:\n    % - marriage theorem\n    % - hitchcock transport problem\n    \\begin{definition}\n      A \\textbf{perfect matching} is a matching which covers all vertices.\n    \\end{definition}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Finding the number of perfect matchings}\n  Finding one is easy (polynomial time).\n  Finding all is in \\# P (i.e.\\ hard!).\n  \\begin{block}{Consider $m=n$, $A\\in \\R^{n \\times n}$}\n    Recall:\n    \\begin{equation}\n      \\begin{aligned}\n        \\text{(determinant)} \\quad \\det A = \\sum_{\\sigma} \\sign(\\sigma) \\prod_{i=1}^n a_i \\sigma(i) \\\\\n        \\text{(permanent)} \\quad \\perm A = \\sum_{\\sigma} \\prod_{i=1}^n a_i \\sigma(i)\n      \\end{aligned}\n    \\end{equation}\n  \\end{block}\n  \\begin{block}{Observation}\n    For a $(0,1)-$matrix $A$, $\\perm A$ is the number of perfect matchings.\n    % This means that computing permanent must be hard.\n  \\end{block}\n  One is easy to compute the other one hard. How can this be?\n  % Diagionalize via gaussion elimination gives O(n^3) algorithm for computing determinant.\n  % This doesn't work for permanent because it is not invariant under these operation (not multilinear).\n\\end{frame}\n\n\\section{Permanent}%\n\\label{sec:}\n\n\\begin{frame}\n  \\frametitle{Lower bounding the permanent}\n  % This notion also appears in optimal transport\n  \\begin{definition}\n    A matrix $A \\in \\R^{m\\times n}_+$ is called \\textbf{doubly stochastic}, if sum of every row and every column is $1$.\n  \\end{definition}\n\n  \\begin{block}{van der Waerden (1926) conjectured}\n    For doubly stochastic matrices the following \\emph{lower bound} holds\n    \\begin{equation}\n      \\perm A \\ge \\frac{n!}{n^n}.\n    \\end{equation}\n  \\end{block}\n  \\begin{equation}\n   \\text{Is tight for} A = \\begin{bmatrix}\n      1/n & \\cdots & 1/n \\\\\n      \\vdots & \\ddots & 1/n \\\\\n      1/n & \\dots & 1/n\n    \\end{bmatrix}\n  \\end{equation}\n  Proved independently by Jegortschow and Falikman in '80 / '81.\n\\end{frame}\n\n\n% do we use this at all?\n\\begin{frame}\n  \\frametitle{Upper bounding the permanent}\n  \\begin{block}{Bregman-Minc}\n    For $(0,1)$-matrices\n    \\begin{equation}\n      \\perm A \\le \\prod_{i=1}^n {(r_i !)}^{1/r_i} \\quad \\text{where $r_i := \\Vert A_{i,:} \\Vert$}\n    \\end{equation}\n  \\end{block}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Matrix scaling to approx.\\ permanent}\n  \\begin{block}{}\n    If a $(0, 1)$-matrix $A$ can be scaled to be doubly stochastic, i.e.\\ it is $\\left(\\mathbbm{1}, \\mathbbm{1}\\right)$-scalable, then\n    we can apply lower bound\n    \\begin{equation}\n      \\perm B = \\perm (XAY) = \\left(\\prod_i x_i\\right) \\left(\\prod_j y_j\\right) perm A\n    \\end{equation}\n  \\end{block}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Matrix scaling as an optimization problem}\n  \\begin{itemize}\n    \\item \\textbf{given:} $A, r, c$\n    \\item \\textbf{find:} $X, Y$ such that $B=XAY$ fulfills $B\\mathbbm{1}_m=r$ and $B \\mathbbm{1}_n=c$.\n    \\item $m+n$ unknowns\n          \\item $m+n$ constraints\n  \\end{itemize}\n  Consider the (\\emph{nonconvex}) function\n  \\begin{equation}\n    g(x,y) = \\langle x, A y \\rangle - \\langle r, \\log x \\rangle - \\langle c, \\log y \\rangle\n  \\end{equation}\n  with derivative (coordinatewise)\n  \\begin{equation}\n    \\label{eq:grad-original-formulation}\n    \\begin{aligned}\n      \\nabla_x g(x,y) = Ay - \\frac{r}{x} \\\\\n      \\nabla_y g(x,y) = A^T x - \\frac{c}{y}\n    \\end{aligned}\n  \\end{equation}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Reparametrizing this system}\n  Via reparametrization $x= e^\\xi$ and $y=e^{\\eta}$ we get\n  \\begin{equation}\n    f(\\xi, \\eta) = \\sum_{i,j} a_{i,j} e^{\\xi_i + \\eta_j} - \\langle r, \\xi \\rangle - \\langle c, \\eta \\rangle\n  \\end{equation}\n  which is \\emph{convex}. It's gradient is given by\n  \\begin{equation}\n    \\label{eq:grad-convex-reformulation}\n    \\frac{\\partial f}{\\partial \\xi_i} = \\sum_{j=1}^{n} a_{i,j} e^{\\xi_i + \\eta_j} - r_i\n  \\end{equation}\n  Easy to see that the optimality condition of~\\eqref{eq:grad-convex-reformulation} and~\\eqref{eq:grad-original-formulation} agree.\n  Implies that even the nonconvex function only has \\emph{global} minimizers.\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Matrix scaling as an optimization problem [contd]}\n  It is easy to see that a solution $(x,y)$ of\n  \\begin{equation}\n    \\begin{aligned}\n      Ay - \\frac{r}{x} = 0 \\\\\n      A^T x - \\frac{c}{y} = 0\n    \\end{aligned}\n  \\end{equation}\n  defines a solution to the \\emph{matrix scaling} problem via $X=\\diag x$ and $Y=\\diag y$\n  \\begin{equation}\n    \\left(\\begin{array}{c}\n            a_{1 1} y_1 + a_{1 2} y_2 + \\cdots \\\\\n            a_{2 1} y_1 + a_{2 2} y_2 + \\cdots \\\\\n            a_{m 1} y_1 + a_{m 2} y_2 + \\cdots \\\\\n          \\end{array}\\right)\n        \\begin{array}{c}\n          \\cdot x_1 = r_1\\\\\n          \\cdot x_2 = r_2\\\\\n          \\cdot x_m = r_m\n        \\end{array}\n      \\end{equation}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{}\n  The question remains: how to minimize\n  \\begin{equation}\n    g(x,y) = \\langle x, A y \\rangle - \\langle r, \\log x \\rangle - \\langle c, \\log y \\rangle\n  \\end{equation}\n  \\onslide<2->{%\n    \\begin{block}{alternating minimiziation}\n      Given a problem\n      \\begin{equation}\n        \\begin{aligned}\n          &\\min_{x,y} \\phi(x,y)\\\\\n          x_{k+1} &= \\argmin_x \\phi(x,y_k) \\\\\n          y_{k+1} &= \\argmin_y \\phi(x_{k+1}, y)\n        \\end{aligned}\n      \\end{equation}\n    \\end{block}\n    makes sense as long as the subproblems are easy (e.g. convex).\n  }\n  \\begin{equation}\n    g(x,y) = \\langle x, A y \\rangle - \\langle r, \\log x \\rangle - \\langle c, \\log y \\rangle\n  \\end{equation}\n  \\begin{equation}\n    \\text{opt. cond.\\ for $x$} \\quad Ay - \\frac{r}{x} = 0\n    \\text{opt. cond.\\ for $y$} \\quad Ay - \\frac{c}{y} = 0\n  \\end{equation}\n\\end{frame}\n\n\n% change this to algorithmx package\n\\begin{frame}\n  \\frametitle{}\n\n  \\begin{block}{Sinkhorn '60}\n    Given $(x_0, y_0)$, for $k=1,\\dots$\n    \\begin{equation}\n      \\begin{aligned}\n        x_{k+1}&= \\frac{r}{A y_k} \\\\\n        y_{k+1}&= \\frac{r}{A x_{k+1}} \\\\\n      \\end{aligned}\n    \\end{equation}\n  \\end{block}\n  Linear convergence if $a_{i,j} > 0$.\n  \\textbf{Q:} What if $A$ is not $(r,c)$-scalable?\n  % Then the optimization problem has no solution as FOC are never fulfilled\n\\end{frame}\n\n\\end{document}\n", "meta": {"hexsha": "024ed6b6eb6990f55f3ef77a2236ca2edaa4f5da", "size": 8565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Matrix-scaling/Matrix_scaling.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/Matrix-scaling/Matrix_scaling.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/Matrix-scaling/Matrix_scaling.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": 29.9475524476, "max_line_length": 134, "alphanum_fraction": 0.6088733217, "num_tokens": 3075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6591845148751466}}
{"text": "\n\\subsection{Reals or rationals for analysis}\n\nWhy can't we use rationals for analysis?\n\nIf discontinous at not rational number, it can still be continous for all rationals.\n\neg \\(f(x)=-1\\) unless \\(x^2>2\\), where \\(f(x)=1\\).\n\nContinous for all rationals, because rationals dense in reals\n\nBut can't be differentiated\n\n", "meta": {"hexsha": "1c2706d50c12fcd73e9a082689dec1572621f7c6", "size": 319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-02-rationals.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-02-rationals.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-02-rationals.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.7857142857, "max_line_length": 84, "alphanum_fraction": 0.736677116, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6591845036384536}}
{"text": "\n%----------------------------------------------------------------------------------------\n%\tPACKAGES AND OTHER DOCUMENT CONFIGURATIONS\n%----------------------------------------------------------------------------------------\n\n\\documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size\n\n\\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs\n\\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default\n\\usepackage[english]{babel} % English language/hyphenation\n\\usepackage{amsmath,amsfonts,amsthm} % Math packages\n\n\\usepackage{sectsty} % Allows customizing section commands\n\\allsectionsfont{\\centering \\normalfont\\scshape} % Make all sections centered, the default font and small caps\n\n\\usepackage{fancyhdr} % Custom headers and footers\n\\pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers\n\\fancyhead{} % No page header - if you want one, create it in the same way as the footers below\n\\fancyfoot[L]{} % Empty left footer\n\\fancyfoot[C]{} % Empty center footer\n\\fancyfoot[R]{\\thepage} % Page numbering for right footer\n\\renewcommand{\\headrulewidth}{0pt} % Remove header underlines\n\\renewcommand{\\footrulewidth}{0pt} % Remove footer underlines\n\\setlength{\\headheight}{13.6pt} % Customize the height of the header\n\n\\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\n\\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\n\\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\n\n\\setlength\\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text\n\n%----------------------------------------------------------------------------------------\n%\tTITLE SECTION\n%----------------------------------------------------------------------------------------\n\n\\newcommand{\\horrule}[1]{\\rule{\\linewidth}{#1}} % Create horizontal rule command with 1 argument of height\n\n% \\title{\t\n% \\normalfont \\normalsize \n% \\textsc{university, school or department name} \\\\ [25pt] % Your university, school and/or department name(s)\n% \\horrule{0.5pt} \\\\[0.4cm] % Thin top horizontal rule\n% \\huge Assignment Title \\\\ % The assignment title\n% \\horrule{2pt} \\\\[0.5cm] % Thick bottom horizontal rule\n% }\n\n% \\author{John Smith} % Your name\n\n% \\date{\\normalsize\\today} % Today's date or a custom date\n\n\\begin{document}\n\n% \\maketitle % Print the title q\n\n\\section{Co-clustering by Block Value Decomposition}\n\nThis is a co-clustering algorithm called Block Value Decomposition (BVD) based on Nonnegative Matrix Factorization (NMF) technique. The goal is to find a factorization for the data matrix $X \\in \\mathbb{R}_{+}^{N \\times M}$, where $N$ is the number of objects, $M$ is the number of features of these objects and the factorization takes the form $$X \\approx USV^T$$, where $U \\in \\mathbb{R}_{+}^{N \\times L}$ is a matrix of rows factors representing features clusters, $S \\in \\mathbb{R}_{+}^{L \\times K}$ is a block matrix representing how blocks are related, and $V \\in \\mathbb{R}_{+}^{M \\times K}$ is a matrix of columns factors representing rows clusters.\n\nThis algorithm solves the following optimization problem:\n$$\\textit{min } ||X - USV^T||^2 \\textit{ s.t. } U \\geq 0, S \\geq 0, V \\geq 0$$\n\nThe optimization problem can be solved using Lagrange multipliers ($\\lambda$), optimizing the following Lagrange function:\n$${\\cal L} = |X - USV^T||^2 - tr(\\lambda_1U^T) - tr(\\lambda_2S^T) - tr(\\lambda_3V^T)$$\n\nThen ${\\cal L}$ must satisfy the K.K.T. conditions:\n$$\\frac{\\partial {\\cal L}}{\\partial U} = 0$$\n$$\\frac{\\partial {\\cal L}}{\\partial S} = 0$$\n$$\\frac{\\partial {\\cal L}}{\\partial V} = 0$$\n$$\\lambda_1 \\odot U = 0$$\n$$\\lambda_2 \\odot S = 0$$\n$$\\lambda_3 \\odot V = 0$$\n\nSolving the derivatives and equal them to $0$, is possible to solve the optimization problem by applying gradient ascending on ${\\cal L}$ with the following update rules:\n$$U \\gets U \\odot \\frac{XVS^T}{USV^TVS^T}$$\n$$V \\gets V \\odot \\frac{U^TXV}{U^TUSV^TV}$$\n$$S \\gets S \\odot \\frac{S^TU^TX}{S^TU^TUSV^T}$$\n\n\n\\section{Fast Nonnegative Matrix Tri factorization}\n\nIn this case, the goal is to optimize the following problem:\n$$\\textit{min } ||X - USV^T||^2 \\textit{ s.t. } U \\in \\Psi^{n \\times k}, S \\in \\mathbb{R}_{+}^{l \\times k}, V \\in \\Psi^{m \\times l}$$ where $U$ and $V$ turns into cluster indicator matrices, with vectors $\\vec{u_i}$ and $\\vec{v_j}$ that contains $1s$ in only one position, indicating the cluster that that this vector belongs, and $0s$ in the rest.\n\nSimilar to the other algorithm, it optimizes $S$ with a multiplicative update rule and the following subproblems:\n$$S \\gets (U^TU)^{-1}U^TXV(V^TV)^{-1}$$\n$$v_{ij} \\left\\{\n\\begin{array}{ll}\n        1 & j = \\textit{argmin}_l ||\\vec{x_i} - \\vec{\\tilde{u_l}}||^2 \\\\\n        0 & \\textit{otherwise}\n    \\end{array}\n\\right.$$\n$$u_{ij} \\left\\{\n\\begin{array}{ll}\n        1 & i = \\textit{argmin}_k ||\\vec{x_j} - \\vec{\\tilde{v_k}}||^2 \\\\\n        0 & \\textit{otherwise}\n    \\end{array}\n\\right.$$\nwhere $\\tilde{U} = US$ and $\\tilde{V} = SV^T$\n\n\n\\section{Overlapping Orthogonal Nonnegative Matrix Tri Factorization}\n\nThis is a proposal algorithm that aims to solve the following problem:\n$$\\textit{min } ||X - UV'||^{2}_{F}$$\n$$\\textit{s.t. } U^TU = I$$\n$$\\left[ \\begin{array}{c} V^{(1)} \\\\ V^{(2)} \\\\ \\vdots \\\\ V^{(k)} \\end{array} \\right]^T\\left[ \\begin{array}{c} V^{(1)} \\\\ V^{(2)} \\\\ \\vdots \\\\ V^{(k)} \\end{array} \\right] = I$$\n$$\\left[ \\begin{array}{c} V^{(1)} \\\\ V^{(2)} \\\\ \\vdots \\\\ V^{(k)} \\end{array} \\right] \\geq 0$$\n$$U, S \\geq 0$$\nwhere $V^{(c)} \\in \\mathbb{R}^{M \\times L}$ and $V^{'}_{c \\cdot} = S_{c \\cdot} V^{(c)^T}$, $\\forall c \\in \\{1, \\dots, k\\}$.\n\nThis way the objects (lines) in $X$ can belong to multiple clusters.\n\n\\end{document}\n", "meta": {"hexsha": "3617a4b0cb01a6807f80fb3461e4c63e9bf69940", "size": 5919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/nmf.tex", "max_stars_repo_name": "lucasbrunialti/biclustering-experiments", "max_stars_repo_head_hexsha": "30e51e23b0c3d91939bf7ec49c47d3035e6ecb57", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-21T08:21:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-10T14:57:06.000Z", "max_issues_repo_path": "paper/nmf.tex", "max_issues_repo_name": "lucasbrunialti/biclustering-experiments", "max_issues_repo_head_hexsha": "30e51e23b0c3d91939bf7ec49c47d3035e6ecb57", "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": "paper/nmf.tex", "max_forks_repo_name": "lucasbrunialti/biclustering-experiments", "max_forks_repo_head_hexsha": "30e51e23b0c3d91939bf7ec49c47d3035e6ecb57", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-01-18T18:10:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T02:23:15.000Z", "avg_line_length": 52.3805309735, "max_line_length": 657, "alphanum_fraction": 0.6399729684, "num_tokens": 1892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.6591844894127702}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 2}\n\nA neutron beam with an intensity of $2 \\times 10^{12}\\text{ neutrons/(cm}^2{\\cdot}\\text{s)}$ is incident on an unknown shielding material and has a beam spot of 5 cm$^2$. The shielding material has a thickness of 10 cm.\n\\begin{enumerate}[a)]\n\\item On average, $3.0\\times10^9$ neutrons/s make it through the shield uncollided. What is the macroscopic cross section of the shield material?\n\\item What is the mean free path of a neutron in the shielding material?\n\\item If a single beam pulse is 10 $\\mu$s, how many collisions are expected to take place in the shielding material?\n\\end{enumerate}\n\n", "meta": {"hexsha": "380484b2f24a5edd3ea8e80a3464ce490c712323", "size": 697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc04/disc04_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/disc04/disc04_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/disc04/disc04_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": 63.3636363636, "max_line_length": 219, "alphanum_fraction": 0.6786226686, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6591685474686316}}
{"text": "% \\documentclass[draft,11pt]{article}\n\\chapter{Different Perspectives on Gaussian\n  Elimination}\n\\label{cha:ge}\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{7 --- Wednesday, April 1}\n%{Spring 2020}{Rasmus Kyng}{More Gaussian\n  %Elimination,\n  %Introduction to Random Matrix Concentration}\n\n\n\\section{An Optimization View of Gaussian Elimination for Laplacians}\nIn this section, we will explore how to exactly minimize a Laplacian\nquadratic form by minimizing over one variable at a time.\nIt turns out that this is in fact Gaussian Elimination in disguise --\nor, more precisely, the variant of Gaussian elimination that we tend\nto use on symmetric matrices, which is called Cholesky factorization.\n\nConsider a Laplacian $\\LL$ of a connected graph $G = (V,E,\\ww)$, where\n$\\ww \\in \\R^E$ is a vector of positive edge weights.\nLet $\\WW \\in \\R^{E \\times E}$ be the diagonal matrix with the edge\nweights on the diagonal, i.e. $\\WW = \\diag(\\ww)$ and\n$\\LL = \\BB\\WW\\BB^\\trp$.\nLet $\\dd \\in \\R^V$ be a demand vector s.t.\\ $ \\dd \\perp \\vecone$.\n\nLet us define an energy\n\\[\n  \\energy(\\xx) =\n-\\dd^\\trp\\xx +\n  \\frac{1}{2}\\xx^\\trp\\LL\\xx\n\\]\nNote that this function is convex and is minimized at $\\xx$ s.t.\\ $\\LL\n\\xx = \\dd$.\n\nWe will now explore an approach to solving the minimization problem\n\\[\n\\min_{\\xx \\in \\R^V } \\energy(\\xx)\n  \\]\n%\nLet $\\xx =\n\\begin{pmatrix}\n  y \\\\ \\zz\n\\end{pmatrix}$ where $y \\in \\R$ and $\\zz \\in \\R^{V \\setminus\n  \\setof{1}}$.\n\nWe will now explore how to minimize over $y$, given any $\\zz$.\nOnce we find an expression for $y$ in terms of $\\zz$,\nwe will be able to reduce  it to a\nnew quadratic minimization problem in $\\zz$,\n\\[\n  \\energy'(\\zz) =\n-\\dd'^\\trp\\zz +\n  \\frac{1}{2}\\zz^\\trp\\LL'\\zz\n\\]\nwhere $\\dd'$ is a demand vector on the remaining vertices, with $\\dd\n\\perp \\vecone$ and $\\LL'$ is a Laplacian of a graph on the remaining\nvertices $V' = V \\setminus \\setof{1}$.\nWe can then repeat the procedure to eliminate another variable and so on.\nEventually, we can then find all the solution to our original\nminimization problem.\n\nTo help us understand how to minimize over the first variable, we\nintroduce some notation for the first row and column of the Laplacian:\n\\begin{equation}\n  \\label{eq:lapuniformlayout}\n  \\LL =\n\\begin{pmatrix}\nW & -\\aa^\\trp \\\\\n-\\aa& \\diag(\\aa) + \\LL_{-1}\n\\end{pmatrix}.\n\\end{equation}\nNote that $W$ is the weighted degree of vertex 1, and that\n\\begin{equation}\n\\begin{pmatrix}\nW & -\\aa^\\trp \\\\\n-\\aa& \\diag(\\aa)\n\\end{pmatrix}\n\\end{equation}\nis the Laplacian of the subgraph of $G$ containing only the edges incident on\nvertex 1, while $\\LL_{-1}$ is the Laplacian of the subgraph of $G$\ncontaining all edges \\emph{not} incident on vertex 1.\n\nLet us also write $\\dd =\n\\begin{pmatrix}\n  b \\\\ \\cc\n\\end{pmatrix}$ where $b \\in \\R$ and $\\cc \\in \\R^{V \\setminus\n  \\setof{1}}$.\n\nNow,\n\\begin{align*}\n  \\energy(\\xx)\n  &=\n  -\\dd^\\trp\\xx +\n  \\frac{1}{2}\\xx^\\trp\\LL\\xx\n  =\n  -\\begin{pmatrix}\n  b \\\\ \\cc\n\\end{pmatrix}^\\trp \\begin{pmatrix}\n  y \\\\ \\zz\n\\end{pmatrix}\n+\n  \\frac{1}{2}\\begin{pmatrix}\n  y \\\\ \\zz\n\\end{pmatrix}^\\trp\n\\left(\n\\begin{array}{ccc}\nW & -\\aa^\\trp \\\\\n-\\aa& \\diag(\\aa) + \\LL_{-1}\n\\end{array} \\right)\n\\begin{pmatrix}\n  y \\\\ \\zz\n\\end{pmatrix}\n  \\\\\n  &=\n    - by  -\\cc^\\trp\\zz\n    +\n    \\frac{1}{2}\n    \\left(\n    y^2 W - 2 y \\aa^\\trp \\zz\n    +\n    \\zz^\\trp \\diag(\\aa) \\zz\n    +\n    \\zz^\\trp \\LL_{-1} \\zz\n    \\right).\n\\end{align*}\nNow, to minimize over $y$, we set $\\frac{\\partial  }{\\partial  y}\n\\energy(\\xx) = 0$ and get\n\\[\n    - b\n    +\n    y W - \\aa^\\trp \\zz\n    = 0\n   .\n  \\]\n  Solving for $y$, we get that the minimizing $y$ is\n\\begin{equation}\n\\label{eq:laponevarmin}\ny = \\frac{1}{W}(b + \\aa^\\trp \\zz).\n\\end{equation}\n\nObserve that\n\\begin{align*}\n  \\energy(\\xx)\n  &=\n    - by  -\\cc^\\trp\\zz\n    +\n    \\frac{1}{2}\n    \\left(\n    y^2 W - 2 y \\aa^\\trp \\zz\n    +\n    \\zz^\\trp \\diag(\\aa) \\zz\n    +\n    \\zz^\\trp \\LL_{-1} \\zz\n    \\right)\n  \\\\* % the * prohibits page break\n  &=\n  - by  -\\cc^\\trp\\zz\n    +\n    \\frac{1}{2}\n    \\left(\n    \\frac{1}{W}( yW - \\aa^\\trp \\zz )^2\n    \\underbrace{\n    -\n    \\frac{1}{W}\\zz^\\trp \\aa\\aa^\\trp \\zz\n    +\n    \\zz^\\trp \\diag(\\aa) \\zz\n    +\n    \\zz^\\trp \\LL_{-1} \\zz\n    }_{\\text{Let } \\SS = \\diag(\\aa) - \\frac{1}{W}\\aa\\aa^\\trp +\\LL_{-1}  }\n    \\right)\n  \\\\* % the * prohibits page break\n  &=\n  - by  -\\cc^\\trp\\zz\n    +\n    \\frac{1}{2}\n    \\left(\n    \\frac{1}{W}( yW - \\aa^\\trp \\zz )^2\n    +\n    \\zz^\\trp\\SS \\zz\n    \\right),\n\\end{align*}\nwhere we simplified the expression by defining $\\SS = \\diag(\\aa) -\n\\frac{1}{W}\\aa\\aa^\\trp +\\LL_{-1}$.\nPlugging in ${y = \\frac{1}{W}(b + \\aa^\\trp \\zz),}$\nwe get\n\\begin{align*}\n  \\min_{y}\n  \\energy\n  \\begin{pmatrix}\n  y \\\\ \\zz\n\\end{pmatrix}\n  &=\n  -\\left(\\cc +  b \\frac{1}{W}\\aa \\right)^\\trp\\zz\n    -\n    \\frac{b^2}{2W}\n    +\n    \\frac{1}{2}\n    \\zz^\\trp\\SS \\zz\n    .\n\\end{align*}\nNow, we define $\\dd' = \\cc +  b \\frac{1}{W}\\aa$\nand $  \\energy'(\\zz) =\n-\\dd'^\\trp\\zz +\n\\frac{1}{2}\\zz^\\trp\\SS\\zz$.\nAnd, we can see that\n\\begin{align*}\n  \\argmin_{\\zz} \\min_{y}\n  \\energy\n  \\begin{pmatrix}\n  y \\\\ \\zz\n\\end{pmatrix}\n  =\n\\argmin_{\\zz}\n    \\energy'(\\zz),\n\\end{align*}\nsince dropping the constant term $    -\n    \\frac{b^2}{2W}$ does not change what the minimizing $\\zz$ values\n    are.\n\\begin{claim}\n\\label{clm:optimgaussclosed}\n\\noindent\n  \\begin{enumerate}\n  \\item $ \\dd' \\perp \\vecone$\n  \\item $ \\SS = \\diag(\\aa) - \\frac{1}{W}\\aa\\aa^\\trp +\\LL_{-1} $ is a\n    Laplacian of a graph on the vertex set $V\\setminus\\setof{1}$.\n  \\end{enumerate}\n\\end{claim}\nWe will prove Claim~\\ref{clm:optimgaussclosed} in a moment.\nFrom the Claim, we see that the problem of finding $\\argmin_{\\zz}\n    \\energy'(\\zz)$, is exactly of the same form as finding $\\argmin_{\\xx}\n    \\energy(\\xx)$, but with one fewer variables.\n\nWe can get a minimizing $\\xx$ that solves $\\argmin_{\\xx}\n    \\energy(\\xx)$ by repeating the variable elimination procedure until we get\ndown to a single variable and finding its value.\nWe then have to work back up to getting a solution for $\\zz$, and then\nsubstitute that into Equation~\\eqref{eq:laponevarmin} to get the value\nfor $y$.\n\\begin{remark}\n  In fact, this perspective on Gaussian elimination also makes sense for any\n  positive definite matrix.\n  In this setting, minimizing over one variable will leave us with\n  another positive definite quadratic minimization problem.\n\\end{remark}\n\n\n% \n\\begin{proof}[Proof of Claim~\\ref{clm:optimgaussclosed}]\nTo establish the first part, we note that  $\\vecone^\\trp \\dd' = \\vecone^\\trp \\cc + b\\frac{\\vecone^\\trp\\aa}{W} =\n\\vecone^\\trp \\cc + b= \\vecone^\\trp \\dd = 0$.\nTo establish the second part, we notice that $\\LL_{-1}$ is a graph\nLaplacian by definition.\nSince the sum of two graph Laplacians is another graph Laplacian, it\nnow suffices to show that $\\SS $ is a graph Laplacian.\n\\begin{claim}\n\\label{clm:lapconditions}\n  A matrix $\\MM$ is a graph Laplacian if and only it satisfies the following conditions:\n  \\begin{itemize}\n  \\item  $\\MM^\\trp = \\MM$.\n  \\item The diagonal entries of $\\MM$ are non-negative, and the\n    off-diagonal entries of $\\MM$ are non-positive.\n  \\item $\\MM \\vecone = \\veczero$.\n  \\end{itemize}\n\\end{claim}\nLet's see that Claim~\\ref{clm:lapconditions} is true. Firstly, when the conditions hold we\ncan write $\\MM = \\DD - \\AA$ where $\\DD$ is diagonal and non-negative,\nand $\\AA$ is non-negative, symmetric, and zero on the diagonal, and from the last condition\n$\\DD(i,i) = \\sum_{j \\neq i} \\AA(i,j)$.\nThus we can view $\\AA$ as a graph adjacency matrix and $\\DD$ as the\ncorresponding diagonal matrix of weighted degrees.\nSecondly, it is easy to check that the conditions hold for any graph\nLaplacian, so the conditions indeed hold if and only if.\nNow we have to check that the claim applies to $\\SS$. We leave\nthis as an exercise for the reader.\n\nFinally, we want to argue that the graph corresponding to $\\SS$ is\nconnected.\nConsider any $i,j \\in V\\setminus\\setof{1}$.\nSince $G$, the graph of $\\LL$, is connected, there exists a simple path in\n$G$ connecting $i$ and $j$.\nIf this path does not use vertex $1$, it is a path in the graph of $\\LL_{-1}$\nand hence in the graph of $\\SS$.\nIf the path does use vertex $1$, it must do so by reaching the vertex\non some edge $(v,1)$ and leaving on a different edge $(1,u)$.\nReplace this pair of edges with edge $(u,v)$, which appears in the graph of\n$\\SS$ because $\\SS(u,v) < 0$. Now we have a path in the graph of $\\SS$.\n\\end{proof}\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=1\n  \\textwidth]{fig/lecture7_schur-clique.jpeg}\n% \\caption{Plotting $\\exp(z)$ compared to $1+z+z^2$.}\n\\label{fig:schurclique}\n\\end{figure}\n\n\\section{An Additive View of Gaussian Elimination}\n\n\\paragraph{Cholesky decomposition basics.}  Again we consider a graph Laplacian $\\LL\n\\in \\R^{n \\times n}$ of a conected graph $G = (V,E,\\ww)$, where as usual\n$\\abs{V} = n$ and $\\abs{E} = m$.\n\nIn this Section, we'll study how to decompose a graph Laplacian as $\\LL = \\matlow \\matlow^\\trp$, where $\\matlow \\in \\R^{n \\times n}$\nis a lower triangular matrix, i.e.\n$\\matlow(i,j) = 0$ for $i < j$.\nSuch a factorization is called a Cholesky\ndecomposition. It is essentially the result of Gaussian elimination with a slight twist\nto ensure the matrices maintained at intermediate steps of the\nalgorithm remain symmetric.\n\nWe use $\\nnz(\\AA)$ to denote the number of non-zero entries of matrix $\\AA$.\n\\begin{lemma}\nGiven an \\emph{invertible} square lower triangular matrix $\\matlow$,\nwe can solve the linear equation $\\matlow \\yy = \\bb$ in time\n$O(\\nnz(\\matlow))$.\nSimilarly, given an upper triangular matrix $\\matup$, we can solve\nlinear equations $\\matup \\zz = \\cc$ in time $O(\\nnz(\\matup))$.\n\\end{lemma}\nWe omit the proof, which is a straight-forward exercise.\nThe algorithms for solving linear equations in upper and lower\ntriangular matrices are known as forward and back substitution respectively.\n\\begin{remark}\n  Strictly speaking, the lemma requires us to have access an adjacency\n  list representation of $\\matlow$ so that we can quickly tell where\n  the non-zero entries are.\n\\end{remark}\n\nUsing forward and back substitution, if we have a decomposition of an\ninvertible matrix $\\MM$ into $\\MM = \\matlow \\matlow^\\trp$, we can now\nsolve linear equations in $\\MM$ in time $O(\\nnz(\\matlow))$.\n\n\\begin{remark}\n We have learned about decompositions using a lower triangular matrix, and later we\n will see an algorithm for computing these.\n In fact, we can have more flexibility than that. From an algorithmic perspective, it is\n sufficient that there exists a permutation matrix $\\PP$ s.t. $\\PP\n \\matlow \\PP^{\\trp}$ is lower triangular. If we know the ordering\n under which the matrix becomes lower triangular, we can perform\n substitution according to that order to solve linear equations in the\n matrix without having to explicitly apply a permutation to the matrix.\n\\end{remark}\n\n\n\\paragraph{Dealing with pseudoinverses.} But how can we solve a linear equation in $\\LL = \\matlow\n\\matlow^\\trp$, where $\\LL$ is not invertible? For graph\nLaplacians we have a simple characterization the kernel, and because\nof this, dealing with the lack of invertibility turns out\nto be fairly easy.\n\nWe can use the following lemma which you will prove in an exercise\nnext week.\n\\begin{lemma}\n  Consider a real symmetric matrix $\\MM = \\XX \\YY \\XX^\\trp$, where\n  $\\XX$ is real and invertible and\n  $\\YY$ is real symmetric.\n  Let $\\proj_{\\MM}$ denote the orthogonal projection to the image\n  of $\\MM$.\n  Then $\\MM^{\\pinv} = \\proj_{\\MM} (\\XX^\\trp)^{-1}\\YY^{\\pinv} \\XX^{-1}\\proj_{\\MM}$.\n\\end{lemma}\n\nThe factorizations $\\LL = \\matlow \\matlow^\\trp$ that we produce will\nhave the property that all diagonal entries of $\\matlow$ are strictly\nnon-zero, except that $\\matlow(n,n) = 0$.\nFrom let us $\\matlowhat$ as the matrix whose entries\nagree with $\\matlow$, except that $\\matlowhat(n,n) = 1$.\nLet $\\calDD$ be the diagonal matrix with $\\calDD(i,i) = 1$ for $i < n$\nand $\\calDD(n,n) = 0$.\nThen $\\matlow \\matlow^{\\trp} = \\matlowhat\\calDD\n\\matlowhat^{\\trp}$, and $\\matlowhat$ is invertible, and $\\calDD^{\\pinv} = \\calDD$.\nFinally, $\\proj_{\\LL} = \\II - \\frac{1}{n}\\vecone\\vecone^{\\trp}$,\nbecause this matrix is acts like identity on vectors orthogonal to\n$\\vecone$ and ensures $\\proj_{\\LL} \\vecone = \\veczero$,\nand this matrix can be applied to a vector in $O(n)$ time.\nThus $\\LL^{\\pinv}  = \\proj_{\\LL}(\\matlowhat^\\trp)^{-1}\\calDD\n\\matlowhat^{-1}\\proj_{\\LL}$, and this matrix can be applied in time $O(\\nnz(\\matlow))$.\n\n\\paragraph{An additive view of Gaussian Elimination.}\nThe following theorem describes Gaussian Elimination / Cholesky\ndecompostion of a graph Laplacian.\n\\begin{theorem}[Cholesky Decomposition on graph Laplacians]\n Let $\\LL\n \\in \\R^{n \\times n}$ be a graph Laplacian of a connected\n graph $G = (V,E,\\ww)$, where\n$\\abs{V} = n$.\n Using Gaussian Elimination, we can compute in $O(n^3)$ time a\n factorization $\\LL = \\matlow\\matlow^{\\trp}$ where $\\matlow$ is lower\n triangular, and has positive diagonal entries except $\\matlow(n,n) = 0$.\n\\end{theorem}\n\\begin{proof}\n  Let $\\LL^{(0)} = \\LL$.\nWe will use $\\AA(:,i)$ to denote the the $i$th column of a matrix $\\AA$.\nNow, for $i = 1$ to $i = n-1$ we define\n\\[\n  \\ll_i = \\frac{1}{\\sqrt{\\LL^{(i-1)}(i,i)}} \\LL^{(i-1)}(:,i)\n  \\text{ and }\n   \\LL^{(i)}  = \\LL^{(i-1)} - \\ll_i \\ll_i^{\\trp}\n \\]\n Finally, we let $\\ll_n = \\veczero_{n \\times 1}$.\n We will show later that\n \\begin{equation}\n   \\label{eq:matlowlastentry}\n   \\LL^{(n-1)} = \\matzero_{n \\times n}.\n \\end{equation}\n It follows that $\\LL = \\sum_{i} \\ll_i \\ll_i^{\\trp}$, provided this\n procedure is well-defined, i.e. $\\LL^{(i-1)}(i,i) \\neq 0$ for all $i\n< n$. We will sketch a proof of this later, while also establishing\nseveral other properties of the procedure.\n\nGiven a matrix $\\AA \\in \\R^{n \\times n}$ and $U \\subseteq [n]$, we will use $\\AA(U, U)$ to\ndenote the principal submatrix of $\\AA$ obtained by restricting to the\nrows and columns with index in $U$, i.e. all entries $\\AA(i,j)$ where\n$i,j \\in U$.\n\\begin{claim}\n  \\label{clm:schurconnected}\n  Fix some $i < n$.\n  Let $U = \\setof{i+1,\\ldots,n}$.\n  Then $\\LL^{(i)}(i,j) = 0$ if $i \\not\\in U$ or $j \\not\\in U$.\n  And $\\LL^{(i)}(U, U)$ is a graph Laplacian of a connected graph on\n  the vertex set $U$.\n\\end{claim}\nFrom this claim, it follows that $\\LL^{(i-1)}(i,i) \\neq 0$ for $i<n-1$,\nsince a connected graph Laplacian on a graph with $\\abs{U} > 1$\nvertices cannot have a zero on the diagonal, and it follows that\n$\\LL^{(n-1)}(i,i) = 0$, because the only graph we allow on one vertex\nis the empty graph. This shows Equation~\\eqref{eq:matlowlastentry} holds.\n\\end{proof}\n\n\\begin{proof}[Sketch of proof of Claim~\\ref{clm:schurconnected}]\n  % We now sketch a proof of Claim~\\ref{clm:schurconnected}.\nWe will focus on the first elimination, as the remaining are similar.\nAdopting the same notation as in Equation~\\eqref{eq:lapuniformlayout},\nwe write\n \\[\n\\LL^{(0)} = \\LL  =\n\\left(\n\\begin{array}{ccc}\nW & -\\aa^\\trp \\\\\n-\\aa& \\diag(\\aa) + \\LL_{-1}\n\\end{array} \\right)\n\\]\nand, noting that\n\\[\n  \\ll_1 \\ll_1^{\\trp} =\n  \\begin{pmatrix}\n   W & -\\aa^\\trp \\\\\n-\\aa & \\frac{1}{W} \\aa \\aa^{\\trp}\n\\end{pmatrix}\n\\]\nwe see that\n\\[\n  \\LL^{(1)}  = \\LL^{(0)} - \\ll_1 \\ll_1^{\\trp} =\n  \\begin{pmatrix}\n   0 & \\veczero \\\\\n\\veczero & \\diag(\\aa) - \\frac{1}{W} \\aa \\aa^{\\trp}  + \\LL_{-1}\n\\end{pmatrix}\n.\n\\]\nThus the first row and column of $\\LL^{(1)}$ are zero claimed.\nIt also follows by Claim~\\ref{clm:optimgaussclosed} that\n$\\LL^{(1)}(\\setof{2,\\ldots,n}, \\setof{2,\\ldots,n})$ is the\nLaplacian of a connected graph.\nThis proves Claim~\\ref{clm:schurconnected} for the case $i = 1$.\nAn induction following the same pattern can be used to prove the claim\nfor all $i < n$.\n\\end{proof}\n\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"agao21_script\"\n%%% TeX-engine: luatex\n%%% End:\n\n\n\n\n\n% \\section{Gaussian Elimination Recap and Structure Claim}\n\n% %Last time, we studied a convex function minimization problem, and saw\n% %how solve it by coordinatewise minimizaiton, which I claimed is really\n% %Gaussian elimination in disguise.\n% %Let's recap part of what we saw.\n\n% Consider a Laplacian $\\LL$ of a connected graph $G = (V,E,\\ww)$, where\n% $\\ww \\in \\R^E$ is a vector of positive edge weights.\n% Let $\\WW \\in \\R^{E \\times E}$ be the diagonal matrix with the edge\n% weights on the diagonal, i.e. $\\WW = \\diag(\\ww)$ and\n% $\\LL = \\BB\\WW\\BB^\\trp$.\n% Let $\\dd \\in \\R^V$ be a demand vector s.t. $ \\dd \\perp \\vecone$.\n\n% We defined an energy\n% \\[\n%   \\energy(\\xx) =\n% -\\dd^\\trp\\xx +\n%   \\frac{1}{2}\\xx^\\trp\\LL\\xx\n% \\]\n\n% Note that this function is convex and is minimized at $\\xx$ s.t. $\\LL\n% \\xx = \\dd$.\n\n% To understand how to minimize over the first variable, we\n% introduce some notation for the first row and column of the Laplacian:\n% \\begin{equation}\n%   \\label{eq:lapuniformlayout}\n%   \\LL =\n% \\left(\n% \\begin{array}{ccc}\n% W & -\\aa^\\trp \\\\\n% -\\aa& \\diag(\\aa) + \\LL_{-1}\n% \\end{array} \\right)\n% \\end{equation}\n% Note that $W$ is the weighted degree of vertex 1, and that\n% \\begin{equation}\n% \\begin{pmatrix}\n% W & -\\aa^\\trp \\\\\n% -\\aa& \\diag(\\aa)\n% \\end{pmatrix}\n% \\end{equation}\n% is the Laplacian of the subgraph of $G$ containing only the edges incident on\n% vertex 1, while $\\LL_{-1}$ is the Laplacian of the subgraph of $G$\n% containing all edges \\emph{not} incident on vertex 1.\n\n% Let us also write $\\dd =\n% \\begin{pmatrix}\n%   b \\\\ \\cc\n% \\end{pmatrix}$ where $y \\in \\R$ and $\\cc \\in \\R^{V \\setminus\n%   \\setof{1}}$.\n\n% Now,\n% \\begin{align*}\n%   \\energy(\\xx)\n%   &=\n%   -\\dd^\\trp\\xx +\n%   \\frac{1}{2}\\xx^\\trp\\LL\\xx\n%   =\n%   -\\begin{pmatrix}\n%   b \\\\ \\cc\n% \\end{pmatrix}^\\trp \\begin{pmatrix}\n%   y \\\\ \\zz\n% \\end{pmatrix}\n% +\n%   \\frac{1}{2}\\begin{pmatrix}\n%   y \\\\ \\zz\n% \\end{pmatrix}^\\trp\n% \\left(\n% \\begin{array}{ccc}\n% W & -\\aa^\\trp \\\\\n% -\\aa& \\diag(\\aa) + \\LL_{-1}\n% \\end{array} \\right)\n% \\begin{pmatrix}\n%   y \\\\ \\zz\n% \\end{pmatrix}\n% \\end{align*}\n% Now, to minimize over $y$, we set $\\frac{\\partial  }{\\partial  y}\n% \\energy(\\xx) = 0$ and get\n% \\[\n%     - b\n%     +\n%     y W - \\aa^\\trp \\zz\n%     = 0\n%    .\n%   \\]\n%   Solving for $y$, we get that the minimizing $y$ is\n% \\begin{equation}\n% \\label{eq:laponevarmin}\n% y = \\frac{1}{W}(b + \\aa^\\trp \\zz).\n% \\end{equation}\n% By substituting in this value of $y$, we found\n% \\begin{align*}\n%   \\min_{y}\n%   \\energy\n%   \\begin{pmatrix}\n%   y \\\\ \\zz\n% \\end{pmatrix}\n%   &=\n%   -\\left(\\cc +  b \\frac{1}{W}\\aa \\right)^\\trp\\zz\n%     -\n%     \\frac{b^2}{2W}\n%     +\n%     \\frac{1}{2}\n%     \\zz^\\trp\\SS \\zz\n%     .\n% \\end{align*}\n% where\n%  $\\SS = \\diag(\\aa) -\n%  \\frac{1}{W}\\aa\\aa^\\trp +\\LL_{-1}$.\n%  We let $\\dd' = \\cc +  b \\frac{1}{W}\\aa$, and $\\energy'(\\zz) =   -\\dd^\\trp\\zz\n% +\n%     \\frac{1}{2}\n%     \\zz^\\trp\\SS \\zz\n%     $, and noted that\n% \\begin{align*}\n%   \\argmin_{\\zz} \\min_{y}\n%   \\energy\n%   \\begin{pmatrix}\n%   y \\\\ \\zz\n% \\end{pmatrix}\n%   =\n% \\argmin_{\\zz}\n%     \\energy'(\\zz),\n% \\end{align*}\n%  and we ended the lecture by stating with the following claim.\n%  \\begin{claim}\n% \\label{clm:optimgaussclosed}\n% \\noindent\n%   \\begin{enumerate}\n%   \\item $ \\dd' \\perp \\vecone$ when $\\dd \\perp \\vecone$.\n%   \\item $\\SS = \\diag(\\aa) - \\frac{1}{W}\\aa\\aa^\\trp +\\LL_{-1} $ is a\n%     Laplacian of a connected graph on the vertex set $V\\setminus\\setof{1}$.\n%   \\end{enumerate}\n% \\end{claim}\n% Now we're ready to prove it.", "meta": {"hexsha": "48937301cabfe50f3a68338edee130b0795b523a", "size": 19336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture7_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/lecture7_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/lecture7_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": 30.9376, "max_line_length": 132, "alphanum_fraction": 0.648065784, "num_tokens": 6747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6591252001727355}}
{"text": "\\lab{Algorithms}{Policy Function Iteration}{Policy Function Iteration}\n\\objective{This section teaches how to improve dynamic programming convergence using policy function iteration.}\n\nNow that we have covered how to solve simple dynamic programming problems by value function iteration, we consider the convergence of the algorithm.  We demonstrate two other methods known as policy function iteration, or Howard's Improvement, and modified policy function iteration.\n\n\\section*{Policy Function Iteration}\nFor infinite horizon dynamic programming problems, it can be shown that value function iteration converges at the rate $\\beta$, where $\\beta$ is the discount factor.  In practice, $\\beta$ is usually close to one which means this algorithm often converges slowly.  \n\nIn order to examine the value function iteration algorithm, it is helpful to see which functions take the most runtime.\n\\begin{problem}\n\\label{prob:profile}\nIn IPython, enter\n\\begin{lstlisting}\n%run -p -s cum Value_Function_Iteration.py\n\\end{lstlisting}\nwhere \\texttt{Value\\_Function\\_Iteration.py} is the name of your script that solves the infinite horizon problem from the Value Function Iteration lab.  This will list the function calls made by your code, sorted by the cumulative time it spends within each function (including time spent in sub-functions).\nRun the same command, this time changing the number of grid points $N$ to be 1000.\nRun the command once more, this time setting $N=1000$ and $\\beta = .95$.\n\\end{problem}\n\nIn Problem \\ref{prob:profile} you should have noticed that runtime was significantly longer to run for larger $N$ or $\\beta$ closer to 1.  The profiler gives more detailed information than just the overall runtime, however.  The results of Problem \\ref{prob:profile} should look something like the following.\n\\begin{verbatim}\n%run -p -s cum Value_Function_Iteration.py\n         622 function calls in 2.542 seconds\n         \n   Ordered by: cumulative time\n\n   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n        1    0.000    0.000    3.065    3.065 <string>:1(<module>)\n        1    0.001    0.001    3.065    3.065 {execfile}\n        1    0.955    0.955    3.064    3.064 Value_Function_Iteration.py:5(<module>)\n       59    0.000    0.000    1.418    0.024 fromnumeric.py:683(argmax)\n       59    1.417    0.024    1.417    0.024 {method 'argmax' of 'numpy.ndarray' objects}\n       59    0.001    0.000    0.613    0.010 fromnumeric.py:1774(amax)\n       59    0.612    0.010    0.612    0.010 {method 'max' of 'numpy.ndarray' objects}\n\\end{verbatim}\nWe notice that the most time was spent in the maximization step.  Remember, the value function iteration method maximizes $V$ (and determines the corresponding $\\psi$) at every step.  Because we find both a new $V$ and a new $\\psi$ at every step, we only apply the new policy function for one iteration.  This gives us a crude approximation to the value function that corresponds to the new policy function, resulting in slow convergence of the value function.  Instead, we might consider finding the exact value function associated with each new policy function.  \n\nThis is the idea behind the policy function iteration algorithm.  In this way we iterate on the policy functions rather than the value functions.  The algorithm for the policy function iteration can be summarized as follows:\n\\begin{enumerate}\n\\item Set an initial policy rule $W' = \\psi_0(W)$ and a tolerance $\\delta$.\n\n\\item \\label{item:step2} Compute the value function assuming this rule is used forever:\n\\begin{equation*}\nV(W_0) = \\sum_{t=0}^\\infty \\beta^t u(\\psi_k(W)-W)\n\\end{equation*}\n\n\\item Determine a new policy $\\psi_{k+1}$ so that\n\\begin{equation*}\n\\psi_{k+1}(W) = \\text{argmax}_{W'} u(W-W') + \\beta V(W-W')\n\\end{equation*}\n\n\\item If $\\delta_k = ||\\psi_{k+1} - \\psi_k|| < \\delta$, stop, otherwise go back to step \\ref{item:step2} with subscript $k+1$.\n\\end{enumerate}\nIn order to compute the value function, $V_k$ corresponding to a given policy $\\psi_k$, we must solve\n\\begin{equation}\n\\label{Val_Fun}\nV_k(W) = u(W-W') + \\beta V_k(W')\n\\end{equation}\nfor $V_k$.\n\nOnce we have discretized $W$, equation \\eqref{Val_Fun} is a linear system which we can rewrite as\n\\begin{equation*}\nV_k(W) = u(W-W') + \\beta QV_k(W)\n\\end{equation*}\nwhere if $W$ is a vector of length $N$, then $Q$ is the $N\\times N$ matrix\n\\begin{equation*}\nQ_{ij} = \\left\\{\n     \\begin{array}{ll}\n       1 & \\text{if} \\quad  W_j = W' = W_i\\\\\n       0 & \\text{otherwise}\n     \\end{array}\n   \\right.\n\\end{equation*}\nThus we have $V_k = (I-\\beta Q)^{-1}u(W-W')$.  Although $Q$ may be large, we can take advantage of the fact that it is sparse, containing only $N$ nonzero entries out of $N^2$ total entries.\n\n\\begin{problem}\n\\label{prob:cake_eating_policyfun}\nSolve the infinite horizon cake eating problem from the Value Function Iteration lab again, this time using policy function iteration.  In order to take advantage of the sparse matrices $I$ and $Q$, use the following imports from the SciPy \\li{sparse} library.\n\\begin{lstlisting}\nfrom scipy import sparse\nfrom scipy.sparse import linalg\n\\end{lstlisting}\nand the following code to initialize $I$ (outside the loop)\n\\begin{lstlisting}\nI = sparse.identity(N)\n\\end{lstlisting}\nand $Q$ (inside the loop)\n\\begin{lstlisting}\nrows = np.arange(0, N)\ncolumns = psi_ind\ndata = np.ones(N)\nQ = sparse.coo_matrix((data, (rows, columns)), shape=(N, N))\nQ = Q.tocsr()\n\\end{lstlisting}\nwhere $N$ is the size of the $W$ grid.  Rather than compute $(I-\\beta Q)^{-1}$ directly, use Scipy's sparse solver\n\\begin{lstlisting}\nV = linalg.spsolve(I-beta*Q, u(W-W[psi_ind]))\n\\end{lstlisting}\nwhere \\texttt{psi\\_ind} gives the indices of $W'$ for a given $W$ according to the current policy.  \nTake $N = 1000$ and $\\beta = .95$.\nPlot the policy function and compare with your policy function from the Value Function Iteration Lab.\n\\end{problem}\n\n\\section*{Modified Policy Function Iteration}\nWhile policy function iteration converges in fewer iterations, solving the linear system can be slow, especially for problems with a large state space.  There is an alternative to this called modified policy function iteration.\n\nIn modified policy function iteration, we don't compute the exact value function corresponding to a policy.  Instead, at step \\ref{item:step2} of the policy iteration algorithm we iterate $m$ times on the value function equation (Bellman equation) to get an approximation of the new value function.  This is faster than solving for the exact value function for large state spaces.  There is no strict rule on the value of $m$, the number of value function iterations.  In practice values such as $m=10$ or $m=15$ often work well.\n\nNote that our methods for solving dynamic programs boil down to some combination of two things: iterating on the value function and iterating on the policy function.  Modified policy function does a combination of the two, taking advantage of the advantages of both methods.  Because modified policy iteration takes only slightly more work to code than value function iteration, it is often preferred in practice.  Whether policy or modified policy iteration will perform better may depend on the problem.\n\n\\begin{problem}\nSolve the same problem as in problem \\ref{prob:cake_eating_policyfun}, this time using the modified policy function iteration method with $m=15$.  In this case let convergence be determined in the same way (computing $\\delta_k$) in the same way as in the value function iteration problem.\n\nUse the same code as in Problem \\ref{prob:cake_eating_policyfun} to initialize the sparse matrix $Q$.\n\\end{problem}\n\n\\begin{problem}\nSolve the cake eating problem with each of the three methods and report how many iterations each takes.  Use $N= 1000$ as the number of grid points for $W$ and $\\beta = 0.95$.  It is important that you use the same initial guess in each case in order to make the results comparable.  The accuracy of the initial guess greatly effects the number of iterations to convergence.  Take your initial guess as $V = 0$ which corresponds to an initial guess of the policy function with indices $[0,1,2,\\ldots, N-1]$ (meaning $\\psi = 0$).\n\\end{problem}\n\nIn general we should see that value function iteration takes more iterations than modified policy function iteration which in turn takes more iterations than policy function iteration.  It is important to note that this does not directly say anything about runtime.  Each iteration of policy iteration may take longer than an iteration of value function iteration.\n\n", "meta": {"hexsha": "3389df232ed1a08a86084a59323d559fd250f265", "size": 8564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/PolicyFunctionIter/Policy_Function_Iteration.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/PolicyFunctionIter/Policy_Function_Iteration.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/PolicyFunctionIter/Policy_Function_Iteration.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.064516129, "max_line_length": 565, "alphanum_fraction": 0.747431107, "num_tokens": 2222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355188, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.6590870107464452}}
{"text": "\\section*{Appendix}\n  Let source $A \\in \\mathcal{V}$, sink $B \\in \\mathcal{V}$, capacity configuration $C$ and a candidate flow $X$. For $X$ to be\n  valid with respect to $C$ the following two conditions must hold:\n  \\begin{align}\n  \\label{flow1}\n    \\forall (v, w) \\in \\mathcal{E}&, x_{vw} \\leq c_{vw} \\\\\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  \\end{align}\n  \n  \\subimport{common/sepproofs/}{saturationsepproof.tex}\n\n  \\subimport{common/sepproofs/}{maxflowcontinuitysepproof.tex}\n\n  \\subimport{common/sepproofs/}{fcfscorrectness.tex}\n\n  \\subimport{common/sepproofs/}{fcfscomplexity.tex}\n\n  \\subimport{common/sepproofs/}{abscorrectness.tex}\n\n  \\subimport{common/sepproofs/}{abscomplexity.tex}\n\n  \\subimport{common/sepproofs/}{absDinfnormminproof.tex}\n\n  \\subimport{common/sepproofs/}{propcorrectness.tex}\n\n  \\subimport{common/sepproofs/}{propcomplexity.tex}\n\n  \\subimport{common/sepproofs/}{maxflowmonotonicitysepproof.tex}\n\n  We will now prove that \\texttt{BinSearch} returns the desired $\\delta^*$ when we provide it with an appropriate interval as\n  input.\n\n  \\ \\\\\n  \\subimport{common/sepproofs/}{dinfbinsearchcorrectness.tex}\n\n  \\subimport{common/sepproofs/}{dinfbinsearchcomplexity.tex}\n\n  \\subimport{common/sepproofs/}{dinfmincorrectness.tex}\n\n  \\subimport{common/sepproofs/}{dinfmincomplexity.tex}\n", "meta": {"hexsha": "34a0927863b1d6531f5b76d1f454f0af62e22b50", "size": 1405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "may31deliverable/appendix.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/appendix.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/appendix.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": 33.4523809524, "max_line_length": 126, "alphanum_fraction": 0.7245551601, "num_tokens": 486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249076, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6588653560799624}}
{"text": "\\documentclass[12pt]{article}\n \n\\usepackage{mathpb}\n\n\\begin{document}\n\n\\section*{Examples}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\begin{verbatim}\n\\begin{theorem}{A}\n    $\\N \\subset \\Z \\subset \\Q \\subset \\R \\subset \\C \\subset \\Ha$\n\\end{theorem}\n\\end{verbatim}\n\n\\begin{theorem}{A}\n$\\N \\subset \\Z \\subset \\Q \\subset \\R \\subset \\C \\subset \\Ha$\n\\end{theorem}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\begin{verbatim}\n\\begin{exercise}{2}\n    Let $z = \\alpha + i\\beta \\in \\C$,\n    $\\Rea(z) = \\alpha$, $\\Ima(z) = \\beta$\n\\end{exercise}\n\\end{verbatim}\n\n\\begin{exercise}{2}\n    Let $z = \\alpha + i\\beta \\in \\C$,\n     $\\Rea(z) = \\alpha$, $\\Ima(z) = \\beta$\n\\end{exercise}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\n\\begin{verbatim}\n\\begin{lemma}{3}\n    Denote $\\card(\\N)  = \\aleph_0$. Then $\\card \\R = 2^{\\aleph_0}$\n\\end{lemma}\n\\end{verbatim}\n\n\\begin{lemma}{3}\n    Denote $\\card(\\N)  = \\aleph_0$. Then $\\card \\R = 2^{\\aleph_0}$\n\\end{lemma}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\begin{verbatim}\n\\begin{problem}{4}\n    Show that $T \\in L(V,V)$ is injective \n    if and only if $\\Ker(T) = \\left\\{ 0 \\right\\}$\n\\end{problem}\n\\end{verbatim}\n\n\\begin{problem}{4}\n    Let $T \\in L(V.)$. Show $\\Range(T) = V$  $\\Ker(T) = \\left\\{ 0 \\right\\}$\n\\end{problem}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\begin{verbatim}\n\\begin{question}{5}\n    Consider $\\Id \\in \\mathcal{L}(V)$. What is $\\Inv (\\Id)$ ?\n\\end{question}\n\\end{verbatim}\n\n\\begin{question}{5}\n    Consider $\\Id \\in S(n)$. What is $\\Inv (\\Id)$ ?\n\\end{question}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\begin{verbatim}\n\\begin{lemma}{2B}\n    \\[ \\limto{x}{0} \\frac{\\sin(x)}{x} = 1 \\]\n\\end{lemma}\n\\end{verbatim}\n\n\\begin{lemma}{2B}\n\\[ \\limto{x}{0} \\frac{\\sin(x)}{x} = 1 \\]\n\\end{lemma}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\begin{verbatim}\n    \\begin{lemma}{2C} \n        Let $x,y \\in V$, $\\lambda \\in F$. Then\n        \\innerp{\\lambda x}{y} = \\lambda \\innerp{x,y}\n    \\end{lemma}\n\\end{verbatim}\n\n\\begin{lemma}{2C} \n    Let $x,y \\in V$, $\\lambda \\in F$. Then\n      $\\innerp{\\lambda x}{y} = \\lambda \\innerp{x}{y}$\n\\end{lemma}\n\n\\noindent\\rule{\\textwidth}{1pt}\n\n\\end{document}\n", "meta": {"hexsha": "d0350cc350a40291af9b9965d522a473535d0cbf", "size": 2057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathpb_example.tex", "max_stars_repo_name": "Jswig/latex-templates", "max_stars_repo_head_hexsha": "104e08adf1d48d8a8c546bc853b79b9b2d744f97", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-17T07:54:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T07:54:45.000Z", "max_issues_repo_path": "mathpb_example.tex", "max_issues_repo_name": "Jswig/latex-templates", "max_issues_repo_head_hexsha": "104e08adf1d48d8a8c546bc853b79b9b2d744f97", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mathpb_example.tex", "max_forks_repo_name": "Jswig/latex-templates", "max_forks_repo_head_hexsha": "104e08adf1d48d8a8c546bc853b79b9b2d744f97", "max_forks_repo_licenses": ["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.1666666667, "max_line_length": 75, "alphanum_fraction": 0.5994166262, "num_tokens": 792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6588653521916518}}
{"text": "\\chapter{Target Propagation}\\label{targetprop}\n\n\\VUname{Target propagation} (sometimes abbreviated to targetprop) is an alternative approach to computing the gradients of a deep feedforward neural network. The idea dates back to \\cite{lecun_learning_1986}, but has recently gained more interest (\\cite{bengio_how_2014}, \\cite{bengio_towards_2015}, \\cite{lee_difference_2015}). Unlike the back-propagation algorithm, the target propagation algorithm is only defined for optimization of feedforward neural networks used in classification problems. For a high-level overview, the back-propagation algorithm can be summarized as follows: The error of the network is computed at the end of the network (after the loss function) and then back-propagated through the network to each layer, where it is used to update the layer parameters. The target propagation algorithm can be viewed as operating conversely: The desired output of the network is back-propagated through the network, creating a \\VUname{target} for each layer. Such targets are then used to compute the error of each individual layer, which in turn is used to update the layer parameters.\n\n\\section{General target propagation overview}\\label{targetprop_general}\n\nUsing notation from section \\ref{backprop_application}, the principle of target propagation can be expressed as a problem of finding a target \\( \\widehat{\\VUvec{h}}^{(i)} \\) for each layer of the neural network so that this target minimizes the loss function of the network, that is\n\\begin{equation}\\label{targetprop_loss_bound}\n\tL \\left( \\widehat{\\VUvec{y}}, \\VUvec{y} \\right) = L \\left( f^{(n)} \\circ \\dots \\circ f^{(i + 1)} \\left( \\VUvec{h}^{(i)} \\right), \\VUvec{y} \\right) > L \\left( f^{(n)} \\circ \\dots \\circ f^{(i + 1)} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right), \\VUvec{y} \\right)\n\\end{equation}\nWith such a target, a \\VUname{layer-local loss function} may be defined as \\( L_i = L \\left( \\widehat{\\VUvec{h}}^{(i)}, \\VUvec{h}^{(i)} \\right) \\). This loss value can in turn be used to compute the gradients for the parameters of the layer as\n\\[ \\nabla_{\\VUvec{a}^{(i)}} J = \\nabla_{\\VUvec{h}^{(i)}} L \\left( \\widehat{\\VUvec{h}}^{(i)}, \\VUvec{h}^{(i)} \\right) \\odot {\\sigma^{(i)}}' \\left( \\VUvec{a}^{(i)} \\right)  = \\nabla_{\\VUvec{h}^{(i)}} L_i \\odot {\\sigma^{(i)}}' \\left( \\VUvec{a}^{(i)} \\right) \\]\n\\[ \\nabla_{\\VUmat{W}^{(i)}} J = \\nabla_{\\VUvec{a}^{(i)}} J {\\VUvec{h}^{(i - 1)}}^T \\]\n\\[ \\nabla_{\\VUvec{b}^{(i)}} J = \\nabla_{\\VUvec{a}^{(i)}} J \\]\nTo summarize, once a proper target for each layer is chosen, the derivatives can be computed using only the input of the layer and the derivatives of the layer-local loss function and the activation function of the layer.\n\nThe open question remaining is how to choose the targets for the layers. For the last layer of the network, the obvious choice of target is\n\\begin{equation}\\label{targetprop_last_layer_target}\n\t\\widehat{\\VUvec{h}}^{(n)} = \\widehat{\\VUvec{y}} - \\eta \\nabla_{\\widehat{\\VUvec{y}}} L \\left( \\widehat{\\VUvec{y}}, \\VUvec{y} \\right)\n\\end{equation}\nwhere \\( \\eta \\) is a step size, i. e. a hyperparameter. Choosing \\( \\eta = 0.5 \\) effectively makes \\( \\widehat{\\VUvec{h}}^{(n)} \\) the same as it would be for back-propagation.\n\nIf all the necessary functions were invertible, a trivial choice of the target for lower levels of the network would be the inverse image of the desired output \\( \\VUvec{y} \\). Then the layer-local loss function value would be \\( L_i = L \\left( \\widehat{\\VUvec{h}}^{(i)}, \\widehat{\\VUvec{h}}^{(i)} \\right) = 0 \\). This trivial choice is, however, practically unfeasible -- the functions in question may not be invertible (e. g. when a ReLU activation function is used). Moreover, such targets may actually not be in the domains of the layer functions \\( f^{(i)} \\). To circumvent these issues, two variations of target propagation have been proposed. (\\cite{bengio_how_2014} and \\cite{lee_difference_2015})\n\n\\section{Vanilla target propagation}\\label{vanilla_targetprop}\n\nVanilla target propagation tries to replace the actual inverse image by an approximation. That is, for each layer \\( f^{(i)} \\) there is defined an approximate inverse function \\( \\widetilde{f}^{(i)} \\), such that\n\\[ f^{(i)} \\left( \\widetilde{f}^{(i)} \\left( \\VUvec{h}^{(i)} \\right) \\right) \\approx \\VUvec{h}^{(i)} \\qquad \\text{and} \\qquad \\widetilde{f}^{(i)} \\left( f^{(i)} \\left( \\VUvec{h}^{(i - 1)} \\right) \\right) \\approx \\VUvec{h}^{(i - 1)} \\]\nThe target can then be chosen as the approximate inverse image represented by\n\\[ \\widehat{\\VUvec{h}}^{(i - 1)} = \\widetilde{f}^{(i)} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right) \\]\nThe approximate inverse function \\( \\widetilde{f}^{(i)} \\) is realized by a neural network layer (in a sense introducing a dual neural network), that is\n\\[ \\widetilde{f}^{(i)} \\left( \\VUvec{h}^{(i)} \\right) = \\widetilde{\\sigma}^{(i)} \\left( \\left( {\\widetilde{\\VUmat{W}}}^{(i)} \\right)^T \\VUvec{h}^{(i)} + \\widetilde{\\VUvec{b}}^{(i)} \\right) \\]\nThis approach is grounded in the fact that using a neural network layer as the approximate inverse function makes the pair \\( \\left( f^{(i)}, \\widetilde{f}^{(i)} \\right) \\) effectively an \\VUname{auto-encoder} (\\cite{bourlard_auto-association_1988}). This connection can be used to apply results holding for auto-encoders to target propagation.\n\nIntroducing another neural network allows the original neural network to be effectively trained using target propagation, but only at the cost of having to train the dual network. However, one of the aforementioned benefits of having the connection to auto-encoders is the fact that the dual network can be trained as a decoder layer in an auto-encoder -- training \\( \\widetilde{f}^{(i)} \\) only to be a good predictor of \\( {f^{(i)}}^{-1} \\). This is achieved by introducing a \\VUname{dual layer-local loss function}\n\\[ \\widetilde{L}_i = L \\left( \\widetilde{f}^{(i)} \\left( f^{(i)} \\left( \\VUvec{h}^{(i - 1)} \\right) \\right), \\VUvec{h}^{(i - 1)} \\right) \\]\nThis choice would, however, only minimize the error at \\( \\VUvec{h}^{(i - 1)} \\). It is more desirable to minimize the error not only at this singular point but also in its neighbourhood. To achieve this, random noise is injected into the input of the dual layer-local loss function, effectively making it\n\\[ \\widetilde{L}_i = L \\left( \\widetilde{f}^{(i)} \\left( f^{(i)} \\left( \\VUvec{h}^{(i - 1)} + \\varepsilon \\right) \\right), \\VUvec{h}^{(i - 1)} + \\varepsilon \\right) \\quad \\text{where} \\quad \\varepsilon \\sim \\mathcal{N} \\left( 0, \\sigma^2 \\right) \\]\n\nTo prove that target propagation is an effective way to learn neural networks, \\cite{lee_difference_2015} state and prove the following theorem:\n\n\\begin{theorem}\\label{targetprop_works}\n\tAssume that \\( \\forall i \\in \\left\\{ 1, \\dots, n \\right\\} \\) there is \\( \\widetilde{f}^{(i)} = {f^{(i)}}^{-1} \\), \\( \\VUvec{h}^{(i)} = f^{(i)} \\left( \\VUvec{h}^{(i - 1)} \\right) = \\VUmat{W}^{(i)} \\sigma^{(i)} \\left( \\VUvec{h}^{(i - 1)} \\right) \\) where \\( \\sigma^{(i)} \\) is a differentiable monotonically increasing element-wise function. Let \\( \\delta \\VUmat{W}^{(i)}_{\\mathrm{BP}} \\) and \\( \\delta \\VUmat{W}^{(i)}_{\\mathrm{TP}} \\) be the update for the \\( i \\)-th layer from back-propagation and target propagation respectively. If \\( \\eta \\) in equation \\ref{targetprop_last_layer_target} is sufficiently small, then the angle \\( \\alpha \\) between \\( \\delta \\VUmat{W}^{(i)}_{\\mathrm{BP}} \\) and \\( \\delta \\VUmat{W}^{(i)}_{\\mathrm{TP}} \\) is bounded by\n\t\\[ 0 < \\frac{1 + \\Delta_1 \\left( \\eta \\right)}{\\frac{\\lambda_{\\mathrm{max}}}{\\lambda_{\\mathrm{min}}} + \\Delta_2 \\left( \\eta \\right)} \\leq \\cos \\left( \\alpha \\right) \\leq 1 \\]\n\t\twhere \\( \\lambda_{\\mathrm{min}} \\) and \\( \\lambda_{\\mathrm{max}} \\) are the smallest and largest singular values of \\( \\left( \\VUmat{J}_{f^{(n)}} \\dots \\VUmat{J}_{f^{(i + 1)}} \\right)^T \\) where \\( \\VUmat{J}_{f^{(k)}} \\) is the Jacobian matrix of \\( f^{(k)} \\) and \\( \\Delta_1 \\left( \\eta \\right) \\) and \\( \\Delta_2 \\left( \\eta \\right) \\) are close to \\( 0 \\) for sufficiently small \\( \\eta \\).\n\\end{theorem}\n\n\\section{Difference target propagation}\n\nAn issue with vanilla target propagation is the fact that even when a layer has already reached a minimum of its loss function, some of the lower layers may still be optimizing and thus disturbing the inputs of the layer and with that increasing the loss again. A solution to this problem is to require that a level reaches its optimum only when all the lower levels have already reached theirs. In other words:\n\\[ \\widehat{\\VUvec{h}}^{(i)} = \\VUvec{h}^{(i)} \\implies \\widehat{\\VUvec{h}}^{(i - 1)} = \\VUvec{h}^{(i - 1)} \\]\nA way to fulfil this restriction is to restrict the targets in the following way:\n\\[ \\widehat{\\VUvec{h}}^{(i - 1)} - \\VUvec{h}^{(i - 1)} = \\widetilde{f}^{(i)} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right) - \\widetilde{f}^{(i)} \\left( \\VUvec{h}^{(i)} \\right) \\]\nThis restriction gives the following formula for the layer target:\n\\begin{equation}\\label{difference_targetprop}\n\t\\widehat{\\VUvec{h}}^{(i - 1)} = \\widetilde{f}^{(i)} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right) + \\VUvec{h}^{(i - 1)} - \\widetilde{f}^{(i)} \\left( \\VUvec{h}^{(i)} \\right)\n\\end{equation}\nThis augmented definition of a target has the same computational benefits as vanilla target propagation -- only the target values have to be back-propagated. All other necessary values are layer-local or have already been computed in the forward pass of the network.\n\n\\begin{remark}\n\tIf the approximate inverse function \\( \\widetilde{f}^{(i)} \\) is substituted by the actual inverse function \\( {f^{(i)}}^{-1} \\), then\n\t\\[ \\widehat{\\VUvec{h}}_{\\mathrm{DTP}}^{(i - 1)} = {f^{(i)}}^{-1} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right) + \\VUvec{h}^{(i - 1)} - {f^{(i)}}^{-1} \\left( \\VUvec{h}^{(i)} \\right) = \\]\n\t\\[ = {f^{(i)}}^{-1} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right) + \\VUvec{h}^{(i - 1)} - \\VUvec{h}^{(i - 1)} = {f^{(i)}}^{-1} \\left( \\widehat{\\VUvec{h}}^{(i)} \\right) = \\widehat{\\VUvec{h}}_{\\mathrm{VTP}}^{(i - 1)} \\]\n\tand Vanilla target propagation and Difference target propagation become equivalent.\n\\end{remark}\n\n\\cite{lee_difference_2015} state and prove the following theorem to show that difference target propagation satisfies the bound in equation \\ref{targetprop_loss_bound}:\n\n\\begin{theorem}\n\tLet the target for layer \\( i - 1 \\) be given by the difference target propagation algorithm (i. e. equation \\ref{difference_targetprop}). Let \\( f^{(i)} \\) and \\( \\widetilde{f}^{(i)} \\) be differentiable and the corresponding matrices \\( \\VUmat{J}_{f^{(i)}} \\) and \\( \\VUmat{J}_{\\widetilde{f}^{(i)}} \\) satisfy\n\t\\[ \\rho \\left( \\left( \\VUmat{I} - \\VUmat{J}_{f^{(i)}} \\VUmat{J}_{\\widetilde{f}^{(i)}} \\right)^T \\left( \\VUmat{I} - \\VUmat{J}_{f^{(i)}} \\VUmat{J}_{\\widetilde{f}^{(i)}} \\right) \\right) < 1\\]\n\twhere \\( \\rho \\) denotes the spectral radius. If \\( \\widehat{\\VUvec{h}}^{(i)} - \\VUvec{h}^{(i)} \\) is sufficiently small, then\n\t\\[ \\left\\lVert \\widehat{\\VUvec{h}}^{(i)} - f^{(i)} \\left( \\widehat{\\VUvec{h}}^{(i - 1)} \\right) \\right\\rVert^2_2 < \\left\\lVert \\widetilde{\\VUvec{h}}^{(i)} - \\VUvec{h}^{(i)} \\right\\rVert^2_2 \\]\n\\end{theorem}\nThe condition on the spectral radius is easily satisfied because \\( \\widetilde{f}^{(i)} \\) learns the inverse of \\( f^{(i)} \\) and so the matrix in question is close to zero.\n", "meta": {"hexsha": "50a124c060db29a250a51671337fbfa111455a49", "size": 11283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "targetprop.tex", "max_stars_repo_name": "marekdedic/VU-text", "max_stars_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "targetprop.tex", "max_issues_repo_name": "marekdedic/VU-text", "max_issues_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "targetprop.tex", "max_forks_repo_name": "marekdedic/VU-text", "max_forks_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 148.4605263158, "max_line_length": 1100, "alphanum_fraction": 0.678277054, "num_tokens": 3790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.6588653510299405}}
{"text": "\\subsection{Cardinals}\\label{subsec:cardinals}\n\n\\begin{definition}\\label{def:equinumerosity}\\mcite[129 \\\\ 145]{Enderton1977Sets}\n  We say that two sets are \\term{equinumerous} if there exists a \\hyperref[def:function_invertibility/bijective]{bijective function} between them.\n\n  If there exists an \\hyperref[def:function_invertibility/injective]{injective} function from \\( A \\) to \\( B \\) that is not necessarily \\hyperref[def:function_invertibility/surjective]{surjective}, we say that \\( A \\) is \\term{dominated by} \\( B \\) or that \\( B \\) \\term{dominates} \\( A \\). If \\( B \\) dominates \\( A \\), and they are not equinumerous, we say that \\( B \\) \\term{strictly dominates} \\( A \\).\n\n  Equinumerosity arises naturally outside the theory of cardinal numbers, unlike set dominance. We are usually instead interested only in injective functions that preserve some structure, i.e. \\hyperref[def:first_order_homomorphism_invertibility/embedding]{embeddings}.\n\\end{definition}\n\n\\begin{lemma}\\label{thm:three_equinumerous_sets_lemma}\\mcite[prop. 6.9]{OpenLogicFull}\n  If \\( A \\subseteq B \\subseteq C \\) and \\( A \\) is \\hyperref[def:equinumerosity]{equinumerous} with \\( C \\), then \\( B \\) is equinumerous with \\( C \\).\n\\end{lemma}\n\\begin{proof}\n  If \\( B = C \\), the lemma is trivial since the \\hyperref[def:multi_valued_function/identity]{identity function} \\( \\id_B: B \\to B \\) is bijective. If \\( B \\subsetneq C \\), however, the identity \\( \\id_B \\) must be extended in order to be a bijective function between \\( B \\) and \\( C \\). It will actually be simpler for us to define a function from \\( C \\) to \\( B \\).\n\n  Let \\( f: C \\to A \\) be a bijective function (such a function exists by the statement of the lemma). Define the set\n  \\begin{equation*}\n    I \\coloneqq \\bigcap\\set{ X \\subseteq C \\given (C \\setminus B) \\subseteq X \\T{and} f(X) \\subseteq X }\n  \\end{equation*}\n  of all intermediate sets between \\( C \\setminus B \\) and \\( C \\) that are invariant under \\( f \\).\n\n  Use \\hyperref[rem:natural_number_recursion]{natural number recursion} to build the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &g: C \\to B \\\\\n      &g(x) \\coloneqq \\begin{cases}\n        x,    &x \\in C \\setminus I \\\\\n        f(x), &x \\in I\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  By construction, \\( C \\setminus B \\subseteq I \\) and thus \\( C \\setminus I \\subseteq C \\setminus (C \\setminus B) = B \\). Therefore, the range of \\( g \\) really is \\( B \\). We must show that \\( g \\) is injective and surjective.\n\n  Let \\( g(x_1) = g(x_2) \\) for some members \\( x_1 \\) and \\( x_2 \\) of \\( C \\). If \\( x_1 \\) and \\( x_2 \\) both belong to either \\( I \\) or \\( C \\setminus I \\), it is trivial to see that \\( x_1 = x_2 \\). It turns out that these are two only possible scenarios. Indeed, without loss of generality, suppose that \\( x_1 \\in I \\) and \\( x_2 \\in C \\setminus I \\). Then \\( f(x_2) = g(x_2) = g(x_1) = x_1 \\). Since \\( I \\) is invariant under \\( f \\) and \\( x_1 \\in I \\), we have \\( x_2 = f(x_1) \\in I \\), which contradicts our choice of \\( x_2 \\). Therefore, \\( g \\) is an injective function.\n\n  To see that \\( g \\) is also surjective, suppose that there exists some \\( y \\in B \\setminus g[B] \\). If \\( y \\in I \\), then by the invariance of \\( f \\) we have \\( g(y) = f(y) \\in I \\) and thus \\( g(y) \\not\\in B \\), which contradicts our definition of \\( g \\). If instead \\( y \\in C \\setminus I \\), then \\( g(y) = y \\) and thus \\( y \\in g[B] \\), which contradicts our choice of \\( y \\). The obtained contradictions show that \\( g \\) is surjective.\n\\end{proof}\n\n\\begin{theorem}[Cantor-Schr\\\"oder-Bernstein theorem]\\label{thm:cantor_schroder_bernstein_theorem}\\mcite[sec. 6.5]{OpenLogicFull}\n  If two sets \\hyperref[def:equinumerosity]{dominate} each other, they are \\hyperref[def:equinumerosity]{equinumerous}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( f: A \\to B \\) and \\( g: B \\to A \\) be injective functions. From \\fullref{thm:function_composition_invertibility} it follows that \\( g \\bincirc f: A \\to A \\) is also an injective function. If we restrict its range to its image \\( g[f[A]] \\), it becomes bijective. Hence, \\( A \\) is equinumerous with \\( g[f[A]] \\). Since \\( g[f[A]] \\subseteq g[B] \\subseteq A \\), from \\fullref{thm:three_equinumerous_sets_lemma} it follows that \\( A \\) is equinumerous with \\( g[B] \\), which is the desired result.\n\\end{proof}\n\n\\begin{remark}\\label{rem:cardinal_definition}\n  \\hyperref[def:equinumerosity]{Set domination} generalizes the \\hyperref[def:subset]{subset relation} between sets.\n\n  If we take a family \\( \\mscrA \\) of sets, then domination is a \\hyperref[def:preordered_set]{preorder} rather than a true \\hyperref[def:partially_ordered_set]{partial order}.\n  \\begin{itemize}\n    \\item Reflexivity follows because the \\hyperref[def:multi_valued_function/identity]{identity function} for any set is injective.\n    \\item Transitivity is a consequence of \\fullref{thm:function_composition_invertibility}.\n    \\item Antisymmetry fails if \\( A \\) dominates \\( B \\) and \\( B \\) dominates \\( A \\), but \\( A \\neq B \\). For example, the map \\( n \\mapsto 2n \\) from all natural numbers \\( \\BbbN \\) to the even natural numbers \\( 2\\BbbN \\) is injective and the identity map on \\( 2\\BbbN \\) is an injective function from \\( 2\\BbbN \\) to \\( \\BbbN \\), however \\( \\BbbN \\neq 2\\BbbN \\)\n  \\end{itemize}\n\n  As a matter of fact, \\hyperref[def:equinumerosity]{equinumerosity} is also a preorder and the proof for that is identical.\n\n  If we partition \\( \\mscrA \\) using the \\hyperref[def:equinumerosity]{equinumerosity relation} if follows from \\fullref{thm:preorder_to_partial_order} that the result will be a partial ordered set. The equivalence classes of this partition are then subfamilies of \\( \\mscrA \\) such that every two sets in a single subfamily are equinumerous. For example, if \\( \\mscrA = \\set{ \\set{ A, B }, \\set{ C, I }, \\set{ A }, \\set{ C } } \\), then the corresponding equivalence classes are \\( \\set{ \\set{ A, B }, \\set{ C, I } } \\) and \\( \\set{ \\set{ A }, \\set{ C } } \\).\n\n  Each of these equivalence classes consists of sets that are identical in \\enquote{size} (not to be confused with \\enquote{large} and \\enquote{small} sets as defined in \\fullref{def:large_and_small_sets}). In the above example, the corresponding equivalence classes correspond to sets of sizes \\( 1 \\) and \\( 2 \\). If we want to extend this notion of \\enquote{size} to infinite sets, we must introduce a hierarchy of \\enquote{sizes}. A natural candidate for such a hierarchy are the equivalence classes themselves. Unfortunately, this would mean that every family of sets has a different hierarchy. Since the entire universe is only available within the metatheory, we cannot partition the universe itself and must instead resort to finding a concrete representative of each possible equivalence class. We will call these representatives \\term{cardinal numbers}.\n\n  As explained in the proof of \\fullref{thm:cardinality_existence}, it will be convenient for us to define cardinal numbers as certain \\hyperref[def:ordinal]{ordinal numbers} --- see \\fullref{def:cardinal}.\n\\end{remark}\n\n\\begin{definition}\\label{def:cardinal}\n  A \\term{cardinal number} or simply \\term{cardinal} is an \\hyperref[def:ordinal]{ordinal} that is not \\hyperref[def:equinumerosity]{equinumerous} with any smaller ordinal. We usually denote them using the small Greek letters \\( \\kappa \\), \\( \\mu \\) and \\( \\nu \\).\n\n  A cardinal is by definition an ordinal and this is useful. For example, the cardinals are well-ordered in the sense of \\fullref{thm:ordinals_are_well_ordered}.\n\n  We often regard cardinal numbers as abstract entities, however. It is thus accepted to call the ordinal itself the \\term{initial ordinal} of the cardinal.\n\\end{definition}\n\n\\begin{lemma}\\label{thm:natural_number_is_not_equinumerous_to_proper_subset}\n  No natural number (as a member of \\hyperref[thm:smallest_inductive_set_existence]{\\( \\omega \\)}) is equinumerous to a proper subset of itself.\n\\end{lemma}\n\\begin{proof}\n  We will use \\fullref{thm:omega_induction} on \\( n \\in \\omega \\). The lemma holds vacuously for \\( n = 0 \\).\n\n  Now suppose that \\( n \\) is not equinumerous to a proper subset of itself and, aiming at a contradiction, suppose that there exists a subset \\( E \\subseteq \\op{succ}(n) \\) and a bijective function \\( {f: \\op{succ}(n) \\to E} \\).\n  \\begin{itemize}\n    \\item If \\( n \\in E \\), then \\( E \\setminus \\set{ n } \\) is a subset of \\( n \\) and thus the restriction \\( f\\restr_n: n \\to (E \\setminus \\set{ n }) \\) is a bijective function.\n    \\item If \\( n \\not\\in E \\), then \\( E \\) is a subset of \\( n \\) and thus \\( f\\restr_n: n \\to E \\) is a bijective function.\n  \\end{itemize}\n\n  In both cases we obtain that \\( n \\) is equinumerous with a proper subset of itself, which is a contradiction. Hence, this also holds for \\( \\op{succ}(n) \\).\n\n  The induction principle allows us to conclude that the lemma holds for all natural numbers.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:natural_numbers_are_cardinals}\n  The natural numbers (as members of \\hyperref[thm:smallest_inductive_set_existence]{\\( \\omega \\)}) are \\hyperref[def:cardinal]{cardinals}.\n\\end{proposition}\n\\begin{proof}\n  Fix a natural number \\( n \\in \\omega \\). Note that for every \\( m < n \\), \\( m \\) is a proper subset of \\( n \\) by \\fullref{thm:ordinal_ordering_via_subsets}. From \\fullref{thm:natural_number_is_not_equinumerous_to_proper_subset} it follows that no ordinal strictly smaller than \\( n \\) is equinumerous with \\( n \\) and hence \\( n \\) is an initial ordinal.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:omega_is_a_cardinal}\n  The \\hyperref[thm:smallest_inductive_set_existence]{smallest inductive set \\( \\omega \\)} is a \\hyperref[def:cardinal]{cardinal}.\n\n  When regarded as a cardinal, we denote it by \\( \\aleph_0 \\). This is consistent with \\fullref{def:aleph_hierarchy}.\n\\end{proposition}\n\\begin{proof}\n  We will use induction on \\( n < \\omega \\) to show that no function \\( f: \\omega \\to n \\) is surjective. This is trivial for \\( 0 \\). Suppose that it holds for some fixed \\( n \\). Let \\( f: \\omega \\to \\op{succ}(n) \\) be any function. Define\n  \\begin{equation*}\n    \\begin{aligned}\n      &g: \\omega \\to n \\\\\n      &g(m) \\coloneqq \\begin{cases}\n        f(m), &f(m) < n \\\\\n        0,    &f(m) = n\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  Our inductive hypothesis states that \\( g \\) cannot be surjective. Hence, \\( f \\) also cannot be surjective.\n\n  Therefore, \\( \\omega \\) is an initial ordinal.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:cardinality_existence}\n  Every set \\( A \\) is equinumerous with a unique \\hyperref[def:cardinal]{cardinal}. We denote this cardinal by \\( \\card(A) \\) and call it the \\term{cardinality} of \\( A \\).\n\\end{proposition}\n\\begin{proof}\n  By \\fullref{thm:well_ordering_theorem} there exists a relation \\( \\prec \\) that well-orders \\( A \\). The \\hyperref[thm:well_ordered_order_type_existence]{order type} \\( \\ord(A, \\prec) \\) is an ordinal that is equinumerous with \\( A \\), however it may not be the smallest one. Fortunately, we can define\n  \\begin{equation*}\n    \\card(A) \\coloneqq \\min\\set{ \\beta \\leq \\ord(A, \\prec) \\given \\beta \\T{is equinumerous with} A }.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:cardinality_order_compatibility}\n  The set \\( A \\) is dominated by \\( B \\) if and only if \\( \\card(A) \\leq \\card(B) \\).\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof First suppose that \\( \\card(A) \\leq \\card(B) \\). By \\fullref{thm:ordinal_ordering_via_subsets}, we have \\( \\card(A) \\subseteq \\card(B) \\) and thus the identity function \\( \\id_{\\card(A)} \\) is an injective function from \\( \\card(A) \\) to \\( \\card(B) \\). Since \\( A \\) is equinumerous with \\( \\card(A) \\) and \\( B \\) is equinumerous with \\( \\card(B) \\), by \\fullref{thm:function_composition_invertibility} we obtain that there is an injective function from \\( A \\) to \\( B \\) and hence \\( B \\) dominates \\( A \\).\n\n  \\NecessitySubProof Conversely, let \\( f: A \\to B \\) be an injective function. We again use \\fullref{thm:function_composition_invertibility} to conclude that \\( \\card(B) \\) dominates \\( \\card(A) \\).\n\n  We will show that \\( \\card(A) > \\card(B) \\) leads to a contradiction, which by the trichotomy of cardinals will entail that \\( \\card(A) \\leq \\card(B) \\). If we suppose that \\( \\card(A) > \\card(B) \\), then \\( \\card(B) \\subseteq \\card(A) \\) and hence the identity on \\( \\card(B) \\) is an injective function. Thus, \\( \\card(A) \\) dominates \\( \\card(B) \\) and vice versa, which by \\fullref{thm:cantor_schroder_bernstein_theorem} implies that \\( \\card(A) \\) is equinumerous with \\( \\card(B) \\). It follows that \\( \\card(A) = \\card(B) \\), which contradicts our assumption that \\( \\card(A) > \\card(B) \\).\n\n  Therefore, \\( \\card(A) \\leq \\card(B) \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:set_domination_relation_trichotomy}\n  Any two sets are either equinumerous or one strictly dominates the other.\n\n  See also \\fullref{def:pigeonhole_principle}.\n\\end{corollary}\n\\begin{proof}\n  Follows from cardinal trichotomy and \\fullref{thm:cardinality_order_compatibility}.\n\\end{proof}\n\n\\begin{theorem}[Cantor's power set theorem]\\label{thm:cantor_power_set_theorem}\\mcite[thm. 6B]{Enderton1977Sets}\n  The power set of any set \\( A \\) \\hyperref[def:equinumerosity]{strictly dominates} \\( A \\). That is,\n  \\begin{equation*}\n    \\card(A) < \\card(\\pow(A)).\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  The function \\( x \\mapsto \\set{ x } \\) is clearly an injective function from \\( A \\) to \\( \\pow(A) \\), therefore \\( \\pow(A) \\) dominates \\( A \\). The converse is not true, however.\n\n  Indeed, fix some function \\( f: A \\to \\pow(A) \\) and define the set\n  \\begin{equation*}\n    B \\coloneqq \\set{ x \\in A \\colon x \\not\\in f(x) }.\n  \\end{equation*}\n\n  Note that \\( B \\subseteq A \\) and thus \\( B \\in \\pow(A) \\), however \\( B \\) is not in the \\hyperref[def:multi_valued_function/image]{image} of \\( f \\) and thus \\( f \\) is not \\hyperref[def:function_invertibility/surjective]{surjective}.\n\n  Since \\( f \\) was arbitrary, we conclude that no function from \\( A \\) to \\( \\pow(A) \\) is surjective.\n\\end{proof}\n\n\\begin{definition}\\label{def:set_finiteness}\n  We say that the set \\( A \\) is \\term{finite} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:set_finiteness/cardinality} The \\hyperref[thm:cardinality_existence]{cardinality} of \\( A \\) is a natural number. That is, we have \\( \\card(A) < \\aleph_0 \\).\n\n    \\thmitem{def:set_finiteness/dedekind} The set \\( A \\) is not \\hyperref[def:equinumerosity]{equinumerous} all of its proper subsets. That is, if \\( B \\) is a proper subset of \\( A \\), then no function from \\( A \\) to \\( B \\) is injective.\n  \\end{thmenum}\n\n  If a set is not finite, we say that it is \\term{infinite}. If a set does not satisfy \\fullref{def:set_finiteness/dedekind}, we say that it is \\term{Dedekind infinite}.\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:set_finiteness/cardinality}{def:set_finiteness/dedekind} We will use \\fullref{thm:omega_induction} on \\( n < \\aleph_0 \\) to prove that all sets of cardinality \\( n \\) are not Dedekind infinite. The case \\( n = 0 \\) is vacuous. Suppose that all sets of cardinality \\( n \\) are not Dedekind infinite and suppose that \\( A \\) of cardinality \\( \\op{succ}(n) \\) is Dedekind infinite.\n\n  Then there exists a proper subset \\( B \\) of \\( A \\) that is equinumerous with \\( \\op{succ}(n) \\). Since \\( \\op{succ}(n) \\) is the cardinality of \\( A \\), there exists a bijective function \\( f: A \\to \\op{succ}(n) \\). Then \\( f[B] \\subseteq \\op{succ}(n) \\). Furthermore, the inequality is strict because otherwise any member of \\( A \\setminus B \\) would contradict \\fullref{def:pigeonhole_principle}. Therefore, \\( f[B] \\) is a proper subset of \\( \\op{succ}(n) \\) that is equinumerous with it. But this contradicts \\fullref{thm:natural_number_is_not_equinumerous_to_proper_subset}.\n\n  The obtained contradiction shows that \\( A \\) is also not Dedekind infinite.\n\n  \\ImplicationSubProof{def:set_finiteness/dedekind}{def:set_finiteness/cardinality} Let \\( A \\) be a Dedekind infinite set and let \\( f: A \\to B \\) be a bijective function into some proper subset \\( B \\) of \\( A \\). We will construct an injective function from \\( \\omega \\) to \\( A \\). Fix some member \\( x_0 \\in A \\setminus B \\) and recursively define\n  \\begin{equation*}\n    \\begin{aligned}\n      &g: \\omega \\to A \\\\\n      &g(n) \\coloneqq \\begin{cases}\n        x_0,         &n = 0 \\\\\n        f(g(n - 1)), &n > 0\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  We now use induction on \\( m \\) to prove that \\( g(n) = g(m) \\) implies \\( n = m \\). Since \\( g(0) \\not\\in B \\) and \\( g(n) \\in B \\) for any \\( n > 0 \\), the base case holds. Suppose that the inductive hypothesis holds for \\( m \\) and that for some \\( n \\) we have \\( g(n) = g(m + 1) \\). It is clear that \\( g(0) \\neq g(m + 1) \\), so necessarily \\( n > 0 \\). We have\n  \\begin{equation*}\n    f(g(n - 1))\n    =\n    g(n)\n    =\n    g(m + 1)\n    =\n    f(g(m)),\n  \\end{equation*}\n  which by the inductive hypothesis implies that \\( m = n - 1 \\). Thus, \\( g(m + 1) = g(n) \\) and the inductive step is proved.\n\n  Therefore, \\( g \\) is injective and thus \\( A \\) dominates \\( \\omega \\). From \\fullref{thm:cardinality_order_compatibility} it follows that \\( \\card(A) \\geq \\aleph_0 \\) and thus \\( \\card(A) \\) is not a natural number.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:cardinal_is_finite_iff_successor_ordinal}\n  A nonzero cardinal is \\hyperref[def:set_finiteness]{finite} if and only if it is a \\hyperref[def:successor_and_limit_ordinal]{successor ordinal}.\n\\end{proposition}\n\\begin{proof}\n  Finite cardinals are natural numbers by definition and all nonzero natural numbers are successor ordinals.\n\n  Conversely, suppose that \\( \\kappa = \\op{succ}(\\alpha) \\) is a successor ordinal that is a cardinal. That is, \\( \\kappa \\) is not equinumerous with any smaller ordinal and in particular with \\( \\alpha \\). From \\fullref{thm:cardinality_order_compatibility} it follows that \\( \\card(\\alpha) < \\kappa \\).\n\n  Let \\( A \\subseteq \\kappa \\) be a proper subset of \\( \\kappa \\). We want to show that \\( \\card(A) < \\kappa \\).\n\n  If \\( \\alpha \\not\\in A \\), define \\( B \\coloneqq A \\). Otherwise, pick some member \\( x_0 \\in \\kappa \\setminus A \\) and define\n  \\begin{equation*}\n    B \\coloneqq (A \\cup \\set{ x_0 }) \\setminus \\set{ \\alpha }.\n  \\end{equation*}\n\n  In both cases we have \\( \\card(A) = \\card(B) \\), but unlike \\( A \\), \\( B \\) is always a subset of \\( \\alpha \\) since \\( \\kappa = \\alpha \\cup \\set{ \\alpha } \\).\n\n  Therefore,\n  \\begin{equation*}\n    \\card(A) = \\card(B) \\leq \\card(\\alpha) < \\kappa.\n  \\end{equation*}\n\n  Hence, \\( \\kappa \\) dominates every proper subset, which by \\fullref{def:set_finiteness/dedekind} means that \\( \\kappa \\) is a finite cardinal.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:cardinal_is_infinite_iff_limit_ordinal}\n  A cardinal is \\hyperref[def:set_finiteness]{infinite} if and only if it is a \\hyperref[def:successor_and_limit_ordinal]{limit ordinal}.\n\\end{corollary}\n\\begin{proof}\n  This is the contraposition to \\fullref{thm:cardinal_is_finite_iff_successor_ordinal} excluding the zero cardinal.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:power_set_finiteness}\n  A set is finite if and only if its \\hyperref[def:basic_set_operations/power_set]{power set} is finite.\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:finite_unions_and_products_are_finite}\n  All finite \\hyperref[def:basic_set_operations/union]{unions} and \\hyperref[def:cartesian_product]{Cartesian products} of finite sets are finite.\n\\end{proposition}\n\n\\begin{definition}\\label{def:successor_and_limit_cardinal}\n  \\begin{thmenum}\n    \\thmitem{def:successor_and_limit_cardinal/successor} If \\( \\kappa \\) is the smallest cardinal such that \\( \\mu < \\kappa \\) for some other cardinal \\( \\mu \\), we say that \\( \\kappa \\) is the \\term{successor} of \\( \\mu \\) and that \\( \\kappa \\) is itself a \\term{successor cardinal}.\n\n    The existence of \\( \\kappa \\) is guaranteed by \\fullref{thm:successor_cardinal_existence}, but it is natural to ask whether \\( \\kappa \\) can be constructed from \\( \\mu \\) similarly to how the \\hyperref[def:ordinal_successor]{ordinal successor operator} gives us a successor ordinal. This turns out to be a deep question --- see \\fullref{hyp:generalized_continuum_hypothesis}.\n\n    \\thmitem{def:successor_and_limit_cardinal/weak_limit} If \\( \\kappa > 0 \\) is not the successor cardinal of any other cardinal, we say that it is a \\term{weak limit cardinal}.\n\n    See \\fullref{thm:weak_limit_cardinal_equivalences} for some equivalent conditions.\n\n    \\thmitem{def:successor_and_limit_cardinal/strong_limit} We say that \\( \\kappa \\) is a \\term{strong limit cardinal} if \\( \\mu < \\kappa \\) implies that \\( \\card(\\pow(\\mu)) < \\kappa \\).\n\n    We can benefit from using forward references to \\fullref{subsec:transfinite_arithmetic}, more precisely \\fullref{thm:cardinal_exponentiation_power_set}, which justifies using \\hyperref[def:cardinal_arithmetic/exponentiation]{cardinal exponentiation} to rewrite the condition for \\( \\kappa \\) being a strong limit cardinal as\n    \\begin{equation*}\n      \\mu < \\kappa \\T{implies} 2^\\mu < \\kappa.\n    \\end{equation*}\n\n    Every strong limit cardinal is a weak limit cardinal as shown in \\fullref{thm:strong_limit_cardinal_is_weak_limit}, however the converse is only true assuming \\fullref{hyp:generalized_continuum_hypothesis} --- see \\fullref{thm:limit_cardinals_and_gch}.\n\n    Strong limit cardinals are further motivated by the usage of \\hyperref[rem:strongly_inaccessible_cardinal]{regular strong limit cardinals} in \\fullref{thm:strong_regular_cardinal_stages}.\n  \\end{thmenum}\n\n  These notions should not be confused with \\hyperref[def:successor_and_limit_ordinal]{successor and limit ordinals}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:successor_cardinal_existence}\n  For any cardinal there exists a successor cardinal.\n\\end{proposition}\n\\begin{proof}\n  Fix a cardinal \\( \\kappa \\). By \\fullref{thm:hartogs_lemma}, there exists a smallest ordinal \\( \\alpha \\) such that \\( \\kappa \\) does not dominate \\( \\alpha \\). Thus, \\( \\alpha \\) is the initial ordinal of a cardinal \\( \\mu \\) because it is not equinumerous with any smaller ordinal.\n\n  \\Fullref{thm:set_domination_relation_trichotomy} implies that \\( \\kappa < \\mu \\).\n\n  Furthermore, every cardinal smaller than \\( \\mu \\) does not dominate \\( \\kappa \\), i.e. if \\( \\nu < \\mu \\), then \\( \\nu \\geq \\kappa \\).\n\n  Therefore, \\( \\mu \\) is the successor cardinal of \\( \\kappa \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:union_of_set_of_cardinals}\\mcite[prop. 67.13]{OpenLogicFull}\n  If \\( A \\) is a set of cardinals, then \\( \\bigcup A \\) is a cardinal. Furthermore, \\( \\bigcup A \\) is the supremum of \\( A \\) with respect to cardinal ordering.\n\n  See a more thorough discussion of a similar issue in \\fullref{thm:union_of_set_of_ordinals}.\n\\end{proposition}\n\\begin{proof}\n  From \\fullref{thm:union_of_set_of_ordinals} it follows that \\( \\bigcup A \\) is an ordinal. Then there exists some cardinal \\( \\kappa \\in A \\) such that \\( \\alpha \\in \\kappa \\).\n\n  We have \\( \\kappa \\subseteq \\bigcup A \\). Thus, with regards to ordinal ordering, \\( \\alpha < \\kappa \\leq \\bigcup A \\). But since \\( \\kappa \\) is a cardinal, it is not equinumerous with \\( \\alpha \\) and hence \\( \\bigcup A \\) is also not equinumerous with \\( \\alpha \\).\n\n  Therefore, \\( \\bigcup A \\) is a cardinal. It follows from \\fullref{thm:ordinal_ordering_via_subsets} that it is also the supremum of \\( A \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:aleph_hierarchy}\\mcite[def. 68.17]{OpenLogicFull}\n  We use transfinite recursion to define, for each ordinal \\( \\alpha \\), the cardinal\n  \\begin{equation}\\label{eq:def:aleph_hierarchy}\n    \\aleph_\\alpha \\coloneqq \\begin{cases}\n      \\omega,                                        &\\alpha = 0 \\\\\n      \\T{successor cardinal of} \\beta,               &\\alpha = \\op{succ}(\\beta) \\\\\n      \\sup\\set{ \\aleph_\\beta \\given \\beta < \\alpha } &\\alpha \\T{is a limit ordinal}.\n    \\end{cases}\n  \\end{equation}\n\n  We denote the initial ordinal of \\( \\aleph_\\alpha \\) by \\( \\omega_\\alpha \\). In particular, \\( \\omega_0 = \\omega \\) and \\( \\omega_1 \\) is the first \\hyperref[def:set_countability/uncountable]{uncountable ordinal}.\n\n  Note that \\( \\aleph_\\lambda \\) exists and is a cardinal for every limit ordinal \\( \\lambda \\) as a consequence of \\fullref{thm:union_of_set_of_cardinals}.\n\n  See \\fullref{rem:unbounded_transfinite_recursion} for some technical details.\n\n  This hierarchy is important because it describes all infinite cardinals as shown in \\fullref{thm:infinite_cardinal_is_aleph}. It is intimately connected to the simpler \\hyperref[def:beth_hierarchy]{\\( \\beth \\) hierarchy} via \\fullref{hyp:generalized_continuum_hypothesis}.\n\\end{definition}\n\n\\begin{remark}[Unbounded transfinite recursion]\\label{rem:unbounded_transfinite_recursion}\n  Although we cannot formally do unbounded transfinite recursion, there is an easy way to circumvent this.\n\n  Formally, in \\fullref{def:aleph_hierarchy}, for every ordinal \\( \\alpha \\) we use \\fullref{thm:bounded_transfinite_recursion} define a \\( \\alpha \\)-indexed transfinite sequence \\( \\aleph_0, \\aleph_1, \\ldots, \\aleph_\\omega, \\ldots \\) and then use the sequence to define \\( \\aleph_\\alpha \\). The definition does not depend on any particular ordinal \\( \\alpha \\), however, and thus all ways to obtain \\( \\aleph_\\alpha \\) are equivalent.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:aleph_hierarchy_is_strictly_monotone}\n  If \\( \\alpha < \\beta \\), then \\( \\aleph_\\alpha < \\aleph_\\beta \\).\n\\end{proposition}\n\\begin{proof}\n  We will use \\fullref{rem:transfinite_induction} on \\( \\beta \\).\n  \\begin{itemize}\n    \\item The condition \\( \\alpha < \\beta \\) is vacuously false for the base case \\( \\beta = 0 \\), hence by \\eqref{eq:def:intuitionistic_propositional_deductive_systems/rules/efq} the statement vacuously holds.\n\n    \\item Suppose that \\( \\alpha < \\beta \\) and \\( \\aleph_\\alpha < \\aleph_\\beta \\). We then have \\( \\alpha < \\op{succ}(\\beta) \\) and, since, \\( \\aleph_{\\op{succ}(\\beta)} > \\aleph_\\beta \\), also \\( \\aleph_\\alpha < \\aleph_{\\op{succ}(\\beta)} \\).\n\n    \\item Let \\( \\lambda \\) be a limit ordinal and suppose that the proposition holds for all \\( \\beta < \\lambda \\) and for arbitrary \\( \\alpha \\). Then \\( \\aleph_\\beta \\subseteq \\aleph_\\lambda \\) for every \\( \\beta < \\lambda \\), hence \\( \\aleph_\\beta \\leq \\aleph_\\lambda \\) by \\fullref{thm:ordinal_ordering_via_subsets}.\n\n    Suppose that \\( \\alpha < \\lambda \\).\n    \\begin{itemize}\n      \\item If there exists some \\( \\beta_0 < \\lambda \\) such that \\( \\alpha < \\beta_0 \\), clearly \\( \\aleph_\\alpha < \\aleph_{\\beta_0} \\leq \\aleph_\\lambda \\).\n      \\item If \\( \\alpha > \\beta \\) for all \\( \\beta < \\lambda \\), then \\( \\alpha \\) is an upper bound of the set \\( \\lambda = \\set{ \\beta \\given \\beta < \\lambda } \\). Hence, \\( \\alpha \\geq \\lambda \\), which contradicts our choice of \\( \\alpha \\).\n    \\end{itemize}\n\n    Therefore, \\( \\aleph_\\alpha < \\aleph_\\lambda \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{remark}[Cardinal recursion and induction]\\label{rem:cardinal_transfinite_recursion_and_induction}\n  Just like we have (bounded and unbounded) transfinite recursion and induction on ordinals, we also have transfinite recursion and induction on cardinals.\n  \\begin{itemize}\n    \\item We only consider cardinals rather than arbitrary ordinals.\n    \\item In its structured form presented in \\fullref{rem:transfinite_induction}, rather than considering successor ordinals and limit ordinals, we consider successor cardinals and weak limit cardinals.\n  \\end{itemize}\n\n  Thus, recursion and induction on cardinals is formally quite different from the equivalent statements for ordinals. The usage of the two is analogous, however.\n\n  See \\fullref{thm:infinite_cardinal_is_aleph} for how this principles is used.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:infinite_cardinal_is_aleph}\\mcite[prop. 68.19]{OpenLogicFull}\n  For every \\hyperref[def:set_finiteness]{infinite cardinal} \\( \\kappa \\) there exists an ordinal \\( \\alpha \\) such that \\( \\kappa = \\aleph_\\alpha \\).\n\\end{proposition}\n\\begin{proof}\n  We will use \\fullref{rem:cardinal_transfinite_recursion_and_induction} on \\( \\kappa \\).\n\n  \\begin{itemize}\n    \\item The base case \\( \\kappa = 0 \\) vacuously holds because \\( 0 \\) is not an infinite cardinal. The actual base case is \\( \\kappa = \\omega = \\aleph_0 \\), which holds by definition. This case may not seem formally necessary, however we need to consider it separately from the limit case and calling it the \\enquote{base case} seems most appropriate.\n\n    \\item If \\( \\kappa = \\aleph_\\alpha \\) and \\( \\mu \\) is the successor cardinal of \\( \\kappa \\), then by definition \\( \\kappa = \\aleph_{\\op{succ}(\\alpha)} \\).\n\n    \\item Finally, let \\( \\kappa \\) be a limit cardinal and let \\( \\mu = \\aleph_{\\alpha_\\mu} \\) for every infinite cardinal \\( \\mu < \\kappa \\). Define\n    \\begin{equation*}\n      \\alpha \\coloneqq \\bigcup\\set{ \\alpha_\\mu \\given \\mu < \\kappa }.\n    \\end{equation*}\n\n    We have\n    \\begin{align*}\n      \\kappa\n      &\\reloset {\\eqref{eq:def:aleph_hierarchy}} =\n      \\bigcup\\set{ \\aleph_{\\alpha_\\mu} \\given \\mu < \\kappa }\n      \\reloset {\\eqref{eq:thm:ordinal_addition_is_monotone/right}} \\leq \\\\ &\\leq\n      \\bigcup\\set[\\Big]{ \\aleph_\\beta \\given \\beta < \\sup\\set{ \\alpha_\\mu \\given \\mu < \\kappa } }\n      = \\\\ &=\n      \\bigcup\\set{ \\aleph_\\beta \\given \\beta < \\alpha }\n      \\reloset {\\ref{thm:ordinal_is_set_of_smaller_ordinals}} = \\\\ &=\n      \\aleph_\\alpha.\n    \\end{align*}\n\n    If we suppose that \\( \\kappa < \\aleph_\\alpha \\), then similarly to \\fullref{thm:ordinal_ordering_via_addition} there exists some ordinal \\( \\beta_0 < \\alpha \\) such that \\( \\aleph_{\\beta_0} > \\aleph_{\\alpha_\\mu} \\) for every \\( \\mu < \\kappa \\). In particular, \\fullref{thm:aleph_hierarchy_is_strictly_monotone} implies that \\( \\beta_0 > \\alpha_\\mu \\) for every \\( \\mu < \\kappa \\). Thus,\n    \\begin{equation*}\n      \\underbrace{\\bigcup\\set{ \\alpha_\\mu \\given \\mu < \\kappa }}_{\\alpha} \\leq \\beta_0 < \\alpha,\n    \\end{equation*}\n    which is a contradiction. Therefore, \\( \\kappa = \\aleph_\\alpha \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{corollary}\\label{thm:weak_limit_cardinal_equivalences}.\n  The cardinal \\( \\kappa = \\aleph_\\alpha \\) is a weak limit cardinal if and only if \\( \\alpha \\) is a limit ordinal.\n\n  In particular, \\( \\kappa > 0 \\) is a weak limit cardinal if and only if \\( \\mu < \\kappa \\) implies that \\( \\nu < \\kappa \\), where \\( \\nu \\) is the successor cardinal of \\( \\mu \\).\n\\end{corollary}\n\\begin{proof}\n  Clear from \\fullref{def:aleph_hierarchy}.\n\\end{proof}\n\n\\begin{definition}\\label{def:set_countability}\n  We will introduce the notion of \\term{countability}, which generalizes \\hyperref[def:set_finiteness]{finiteness}.\n\n  \\begin{thmenum}\n    \\thmitem{def:set_countability/countably_infinite}\\mcite[159]{Enderton1977Sets} The smallest infinite cardinal is \\hyperref[thm:omega_is_a_cardinal]{\\( \\aleph_0 \\)}. Every set with cardinality \\( \\aleph_0 \\) is called \\term{countably infinite}. The countably infinite sets are precisely those that can be ordered into a \\hyperref[def:sequence]{sequence}.\n\n    \\thmitem{def:set_countability/at_most_countable} A set that is either finite or countably infinite is called \\term{at most countable}.\n\n    \\thmitem{def:set_countability/uncountable} Any set that \\hyperref[def:equinumerosity]{strictly dominates} \\( \\aleph_0 \\) is called \\term{uncountable}. The smallest uncountable cardinal is the successor cardinal \\( \\aleph_1 \\) of \\( \\aleph_0 \\).\n\n    \\thmitem{def:set_countability/continuum} The cardinality of \\( \\pow(\\aleph_0) \\) has a special name --- the \\term{cardinality of the continuum}. It is sometimes denoted by \\( c \\). See \\fullref{hyp:continuum_hypothesis} for its relation to \\( \\aleph_1 \\).\n  \\end{thmenum}\n\n  See \\fullref{rem:countability_etymology} for additional terminology that is potentially more ambiguous.\n\\end{definition}\n\n\\begin{remark}\\label{rem:countability_etymology}\n  Some authors, for example \\cite[159]{Enderton1977Sets}, use the shorted term \\term{countable}, however other authors use \\enquote{countable} to mean \\enquote{countably infinite}. The terms \\term{denumerable} and \\term{enumerable} are also used for \\enquote{countably infinite} and \\enquote{at most countable} respectively. This is done in \\cite[def. 4.4]{OpenLogicFull}, for example. These terms are also ambiguous unfortunately.\n\\end{remark}\n\n\\begin{conjecture}[Continuum hypothesis]\\label{hyp:continuum_hypothesis}\n  The \\hyperref[def:set_countability/continuum]{cardinality of the continuum} \\( c \\) is the \\hyperref[def:set_countability/uncountable]{first uncountable cardinal} \\( \\aleph_1 \\).\n\n  Compare this to \\fullref{hyp:generalized_continuum_hypothesis}.\n\\end{conjecture}\n\n\\begin{remark}\\label{rem:continuum_hypothesis}\\mcite[165]{Enderton1977Sets}\n  \\Fullref{hyp:continuum_hypothesis} has been shown by G\\\"odel not to be disprovable in \\hyperref[def:set]{\\logic{ZFC}} and by Cohen not to be provable in \\logic{ZFC}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:omega_equinumerous_with_omega_squared}\n  The smallest inductive set \\( \\omega \\) is equinumerous with \\( \\omega \\times \\omega \\).\n\\end{proposition}\n\\begin{proof}\n  We can give a short proof using \\fullref{thm:cantor_schroder_bernstein_theorem} using the injective functions \\( (n, m) \\mapsto 2^n 3^m \\) in one direction and \\( n \\mapsto (n, 0) \\) in the other direction. Proving the injectivity of \\( f \\), however, requires \\fullref{thm:fundamental_theorem_of_arithmetic}, and we prove the latter using machinery from \\fullref{sec:commutative_algebra}. We will instead give a direct proof with an explicit construction. We will construct a bijective function from \\( \\omega \\times \\omega \\) to \\( \\omega \\) --- the function visualized in \\cref{fig:thm:omega_equinumerous_with_omega_squared}.\n\n  We begin by defining the diagonal in \\cref{fig:thm:omega_equinumerous_with_omega_squared}. For each natural number \\( k \\), define the set of pairs that sum to \\( k \\):\n  \\begin{equation*}\n    A_k \\coloneqq \\set{ (n, m) \\in \\omega \\times \\omega \\given n + m = k }.\n  \\end{equation*}\n\n  We can use induction to show that \\( \\card(A_k) = k + 1 \\). That is, \\( A_k \\) can \\enquote{fit} \\( k + 1 \\) numbers. We can now define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &d: \\omega \\to \\omega \\\\\n      &d(n) \\coloneqq \\sum_{k=0}^n \\card(A_n)\n    \\end{aligned}\n  \\end{equation*}\n  that gives us how many numbers we have already \\enquote{fit} in the first \\( n \\) diagonals.\n\n  It is clear that the point \\( (n, m) \\) lies in \\( A_{n + m} \\). We want to know how many numbers we have \\enquote{fit} in the diagonal prior to that, for which we can use \\( d(n + m - 1) \\). This leads us to the definition\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: \\omega \\times \\omega \\to \\omega \\\\\n      &f(n, m) \\coloneqq \\begin{cases}\n        0,                &n + m = 0 \\\\\n        d(n + m - 1) + n, &n + m > 0. \\\\\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  We will first show that \\( f \\) is injective using induction on \\( n + m \\) (that is, on the diagonals). Suppose that \\( f(n_1, m_1) = f(n_2, m_2) \\) implies \\( n_1 = n_2 \\) and \\( m_1 = m_2 \\) for all pairs with a sum less than \\( l \\). Let \\( (n_1, m_1) \\) and \\( (n_2, m_2) \\) be two points in \\( A_l \\) such that \\( f(n_1, m_1) = f(n_2, m_2) \\). The cases \\( l <= 1 \\) are trivial, so suppose that \\( l > 1 \\). Then\n  \\begin{equation*}\n    f(n_1, m_1)\n    =\n    d(n_1 + m_1 - 1) + n_1\n    =\n    l - 1 + d(n_1 + m_1 - 2) + n_1\n    =\n    l + f(n_1 - 1, m_1).\n  \\end{equation*}\n\n  We can now apply the inductive hypothesis and obtain that \\( n_1 = n_2 \\) and \\( m_1 = m_2 \\). This proves injectivity.\n\n  To see that \\( f \\) is surjective, we will use induction on \\( k \\in \\omega \\). The base case is again trivial. Now suppose that \\( n + m > 0 \\) and\n  \\begin{equation*}\n    f(n, m) = d(n + m - 1) + n = k.\n  \\end{equation*}\n\n  We have two cases:\n  \\begin{itemize}\n    \\item If \\( m = 0 \\), then\n    \\begin{equation*}\n      f(0, n + m + 1) = d(n + m) + 0 = d(n + m - 1) + n + m = f(n, m) + 1.\n    \\end{equation*}\n\n    \\item If \\( m > 0 \\), then\n    \\begin{equation*}\n      f(n + 1, m - 1) = d(n + m - 1) + n + 1 = f(n, m) + 1.\n    \\end{equation*}\n  \\end{itemize}\n\n  In both cases we have shown that \\( k + 1 = f(n, m) + 1 \\) is in the image of \\( f \\), which concludes the proof of surjectivity (and hence bijectivity).\n\n  Lastly, although it is not necessary for the proof, we can expand the definition of \\( d \\) to see that \\( f \\) is actually a \\hyperref[def:polynomial]{polynomial}:\n  \\begin{equation*}\n    f(n, m)\n    =\n    \\sum_{k=0}^{n + m - 1} (k + 1) + n\n    =\n    \\sum_{k=1}^{n + m} k + n\n    \\reloset {\\eqref{eq:thm:arithmetic_progression_partial_sums}} =\n    \\frac {(n + m) (n + m + 1)} 2 + n.\n  \\end{equation*}\n\n  As an added benefit, this polynomial also handles the case \\( n = m = 0 \\).\n\n  \\begin{figure}\n    \\hfill\n    \\includegraphics[page=1]{output/thm__omega_equinumerous_with_omega_squared.pdf}\n    \\hfill\n    \\includegraphics[page=2]{output/thm__omega_equinumerous_with_omega_squared.pdf}\n    \\hfill\\hfill\n    \\caption{Visualization on an integer coordinate grid of the diagonal sets \\( A_k \\) and of the bijective function defined in \\fullref{thm:omega_equinumerous_with_omega_squared}.}\\label{fig:thm:omega_equinumerous_with_omega_squared}\n  \\end{figure}\n\\end{proof}\n\n\\begin{corollary}\\label{thm:countable_product_of_countable_sets}\n  A finite \\hyperref[def:cartesian_product]{Cartesian product} of at most countable sets is at most countable.\n\\end{corollary}\n\\begin{proof}\n  Let \\( A_1, \\ldots, A_n \\) be a finite family of at most countable sets.\n\n  Suppose that the inductive hypothesis holds for \\( n \\). Countability ensures that there exist injective functions \\( g: A_1 \\times \\cdots \\times A_n \\times \\omega \\) and \\( h: A_{n+1} \\to \\omega \\). Denote by \\( f \\) the bijective function from \\( \\omega \\) to \\( \\omega \\times \\omega \\) obtained in \\fullref{thm:omega_equinumerous_with_omega_squared} and define\n  \\begin{equation*}\n    \\begin{aligned}\n      &F: A_1 \\times \\cdots \\times A_n \\times A_{n+1} \\to \\omega \\\\\n      &F(a_1, \\ldots, a_n, a_{n+1}) \\coloneqq f(g(a_1, \\ldots, a_n), h(a_{n+1}))\n    \\end{aligned}\n  \\end{equation*}\n\n  By \\fullref{thm:function_superposition_invertibility}, the function \\( F \\) is injective as a \\hyperref[def:multi_valued_function/superposition]{superposition} of injective functions.\n\n  Therefore, \\( \\omega \\) dominates the product \\( A_1 \\times \\cdots \\times A_n \\), i.e. the product is countable.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:countably_infinite_union_of_countably_infinite_sets}\\mcite[thm. 6Q]{Enderton1977Sets}\n  A \\hyperref[def:set_countability/countably_infinite]{countably infinite} union of countably infinite sets is countably infinite.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\seq{ A_k }_{k \\in \\omega} \\) be a countably infinite family of countably infinite sets. Define instead the disjoint family\n  \\begin{equation*}\n    B_k \\coloneqq \\set{ (k, a) \\given a \\in A_k }.\n  \\end{equation*}\n\n  Denote the union of the former family by \\( A \\) and of the latter family by \\( B \\). Since each \\( A_k \\) is countably infinite, so is \\( A \\). Furthermore, there exists an obvious injective function from \\( B \\) to \\( A \\), thus\n  \\begin{equation}\\label{thm:countably_infinite_union_of_countably_infinite_sets/union_card_inequality}\n    \\aleph_0 \\leq \\card(A) \\leq \\card(B).\n  \\end{equation}\n\n  Define the multi-valued mapping\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\mscrG: \\omega \\to \\fun(\\omega, B) \\\\\n      &\\mscrG(k) \\coloneqq \\set{ g: \\omega \\to B_k \\given g \\T{is bijective} }.\n    \\end{aligned}\n  \\end{equation*}\n\n  This is a total multi-valued function because we have assumed that \\( B_k \\) is countable for every \\( k \\in \\mscrK \\). \\Fullref{thm:existence_of_multi_valued_function_selection} gives us a single-valued function \\( G: \\omega \\to \\fun(\\omega, B) \\). Since the family \\( \\seq{ B_k }_{k \\in \\omega} \\) is disjoint, \\( G \\) is injective. We can thus \\hyperref[def:function/currying]{uncurry} \\( G \\) to obtain a function \\( g \\) from \\( \\omega \\times \\omega \\) to \\( B \\).\n\n  To prove that \\( g \\) is injective, suppose that \\( g(n_1, m_1) = g(n_2, m_2) \\). Then\n  \\begin{equation*}\n    G(n_1)(m_1) = g(n_1, m_1) = g(n_2, m_2) = G(n_2)(m_2).\n  \\end{equation*}\n\n  Note that \\( n_1 \\neq n_2 \\) would lead to a contradiction because  \\( \\seq{ B_k }_{k \\in \\omega} \\) is a disjoint family. So \\( n_1 = n_2 \\) and we obtain \\( m_1 = m_2 \\) since the function \\( G(n_1): \\omega \\to B_k \\) is injective. Therefore, \\( g \\) itself is also injective.\n\n  It is also surjective because for every \\( a \\in B \\) there exists some \\( k \\in \\omega \\) such that\n  \\begin{equation*}\n    a \\in B_k = \\img(G(k)).\n  \\end{equation*}\n\n  Denote by \\( f \\) the bijective function from \\( \\omega \\) to \\( \\omega \\times \\omega \\) obtained in \\fullref{thm:omega_equinumerous_with_omega_squared}. Then the function \\( f \\bincirc g: \\omega \\to B \\) is bijective by \\fullref{thm:function_composition_invertibility}. Therefore, the union \\( B \\) is countably infinite. From \\eqref{thm:countably_infinite_union_of_countably_infinite_sets/union_card_inequality} it follows that \\( A \\) is also countably infinite.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:at_most_countable_union_of_at_most_countable_sets}\n  An \\hyperref[def:set_countability/at_most_countable]{at most countable} union of at most countable sets is at most countable.\n\\end{corollary}\n\\begin{proof}\n  Let \\( \\seq{ A_k }_{k \\in \\mscrK} \\) be an at most countable family of at most countable sets. Denote their union by \\( A \\). For every \\( A_k \\) let \\( g_k: A_k \\to \\omega \\) be an injective function and define the \\hyperref[def:disjoint_union]{disjoint union}\n  \\begin{equation*}\n    B_k \\coloneqq A_k \\amalg \\set{ n \\in \\omega \\given n \\not\\in \\img(g_k) }\n  \\end{equation*}\n  and the bijective function\n  \\begin{equation*}\n    \\begin{aligned}\n      &h_k: B_k \\to \\omega \\\\\n      &h_k(x) \\coloneqq \\begin{cases}\n        (0, g_k(x)), &x \\in A_k \\\\\n        (1, x),      &\\T{otherwise.}\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\n  For every \\( k \\in \\omega \\setminus \\mscrK \\) instead define\n  \\begin{equation*}\n    B_k \\coloneqq \\set{ (k, n) \\given n \\in \\omega }\n  \\end{equation*}\n  and let \\( h_k: B_k \\to \\omega \\) be the obvious bijective function.\n\n  Then\n  \\begin{equation*}\n    A\n    =\n    \\bigcup_{k \\in \\mscrK} A_k\n    \\subseteq\n    \\bigcup_{k \\in \\mscrK} B_k\n    \\subseteq\n    \\bigcup_{k \\in \\omega} B_k\n  \\end{equation*}\n  and the latter is countably infinite by \\fullref{thm:countably_infinite_union_of_countably_infinite_sets}. Therefore, \\( A \\) is at most countable.\n\\end{proof}\n", "meta": {"hexsha": "3f9d131f7661120ee5931956de13808c564a488b", "size": 42869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/cardinals.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/cardinals.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/cardinals.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": 68.8105939005, "max_line_length": 863, "alphanum_fraction": 0.6903823276, "num_tokens": 13394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8418256452674009, "lm_q1q2_score": 0.6588653463711401}}
{"text": "\\title{Probabilistic Models}\n\n\\subsection{Probabilistic Models}\n\nA probabilistic model asserts how observations from a natural phenomenon arise.\nThe model is a \\emph{joint distribution}\n\\begin{align*}\n  p(\\mathbf{x}, \\mathbf{z})\n\\end{align*}\nof observed variables $\\mathbf{x}$ corresponding to data, and latent\nvariables $\\mathbf{z}$ that provide the hidden structure to generate\nfrom $\\mathbf{x}$. The joint distribution factorizes into two\ncomponents.\n\nThe \\emph{likelihood}\n\\begin{align*}\n  p(\\mathbf{x} \\mid \\mathbf{z})\n\\end{align*}\nis a probability distribution that describes how any data $\\mathbf{x}$\ndepend on the latent variables $\\mathbf{z}$. The likelihood posits a\ndata generating process, where the data $\\mathbf{x}$ are assumed drawn\nfrom the likelihood conditioned on a particular hidden pattern\ndescribed by $\\mathbf{z}$.\n\nThe \\emph{prior}\n\\begin{align*}\n  p(\\mathbf{z})\n\\end{align*}\nis a probability distribution that describes the latent variables\npresent in the data. It posits a generating process of the hidden structure.\n\nFor details on how to specify a model in Edward, see the\n\\href{/api/model}{model API}. We describe several examples in detail\nin the \\href{/tutorials/}{tutorials}.\n", "meta": {"hexsha": "1d4a9ca6818b8b7899fff43e0fea9ce818460612", "size": 1208, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/model.tex", "max_stars_repo_name": "xiangze/edward", "max_stars_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5200, "max_stars_repo_stars_event_min_datetime": "2016-05-03T04:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:32:26.000Z", "max_issues_repo_path": "docs/tex/tutorials/model.tex", "max_issues_repo_name": "xiangze/edward", "max_issues_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 724, "max_issues_repo_issues_event_min_datetime": "2016-05-04T09:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:41:12.000Z", "max_forks_repo_path": "docs/tex/tutorials/model.tex", "max_forks_repo_name": "xiangze/edward", "max_forks_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1004, "max_forks_repo_forks_event_min_datetime": "2016-05-03T22:45:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T00:08:08.000Z", "avg_line_length": 34.5142857143, "max_line_length": 79, "alphanum_fraction": 0.7640728477, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6588653424947839}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{titletoc}\n\\usepackage{titlesec}\n\\usepackage{geometry} \n\\usepackage{fontspec, xunicode, xltxtra}\n\\usepackage{float}\n\\usepackage{cite}\n\\usepackage{amsmath}\n\\usepackage{listings}\n\\usepackage{titletoc}\n\\usepackage{booktabs}\n\n\\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm}\n\\DeclareMathOperator*{\\argmin}{argmin}\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\DeclareMathOperator*{\\logit}{logit}\n\\DeclareMathOperator*{\\var}{var}\n\\DeclareMathOperator*{\\cov}{cov}\n\\DeclareMathOperator*{\\expec}{E}\n\\DeclareMathOperator*{\\deriv}{d}\n\\DeclareMathOperator*{\\const}{constant}\n\n\\begin{document}\n\\title{\\textsf{Homework 9 for Bayesian Data Analysis}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 14.3}\n{\n    Assuming uniform prior distribution for $\\beta|\\sigma$, we have\n    $$p(\\beta|\\sigma, y) \\propto p(y | \\beta, \\sigma) p(\\beta | \\sigma)$$\n    $$\\propto p(y | \\beta, \\sigma) \\propto \\exp{\\left( -\\frac{1}{2\\sigma^2} (y-X\\beta)^T (y-X\\beta) \\right)}.$$\n\n    Note the fact that $$(y-X\\beta)^T (y-X\\beta) = (\\beta-\\hat{\\beta})^T X^T X (\\beta-\\hat{\\beta}) + \\const,$$ we have\n    $$p(\\beta|\\sigma, y) \\propto \\exp{\\left( -\\frac{1}{2\\sigma^2} (y-X\\beta)^T (y-X\\beta) \\right)}$$\n    $$\\propto \\exp{\\left( -\\frac{1}{2\\sigma^2} (\\beta-\\hat{\\beta})^T X^T X (\\beta-\\hat{\\beta}) \\right)}$$\n    $$= \\exp{\\left( -\\frac{1}{2} (\\beta-\\hat{\\beta})^T ((X^T X)^{-1} \\sigma^2)^{-1} (\\beta-\\hat{\\beta}) \\right)},$$\n    which implies that $$\\beta | \\sigma, y \\sim N(\\hat{\\beta}, (X^T X)^{-1} \\sigma^2).$$\n}\n\n\\section*{Question 14.4}\n{\n    Assuming the noninformative prior $p(\\beta, \\log{\\sigma}) \\propto 1$, or $p(\\beta, \\sigma^2) \\propto \\sigma^{-2}$, we obtain\n    $$p(\\sigma | y) = p(\\beta, \\sigma^2 | y) / p(\\beta | \\sigma^2, y) \\propto p(\\beta, \\sigma^2) p(y | \\beta, \\sigma^2) / p(\\beta | \\sigma^2, y)$$\n    $$\\propto \\frac{\\sigma^{-2} \\cdot \\sigma^{-n} \\exp{\\left( -\\frac{1}{2\\sigma^2} (y-X\\beta)^T (y-X\\beta) \\right)}}{[\\det{((X^T X)^{-1} \\sigma^2)]^{-1/2} \\cdot \\exp{\\left( -\\frac{1}{2\\sigma^2} (\\beta-\\hat{\\beta})^T X^T X (\\beta-\\hat{\\beta}) \\right)}}}$$\n\n    Fix $\\beta = \\hat{\\beta}$ in the formula above, and it follows that\n    $$p(\\sigma | y) \\propto \\frac{\\sigma^{-2} \\cdot \\sigma^{-n} \\exp{\\left( -\\frac{1}{2\\sigma^2} (y-X\\hat{\\beta})^T (y-X\\hat{\\beta}) \\right)}}{[\\det{((X^T X)^{-1} \\sigma^2)]^{-1/2}}}$$\n    $$= \\frac{\\sigma^{-2} \\cdot \\sigma^{-n} \\exp{\\left( -\\frac{1}{2\\sigma^2} (y-X\\hat{\\beta})^T (y-X\\hat{\\beta}) \\right)}}{[\\sigma^{2k} \\cdot \\det{((X^T X)^{-1})]^{-1/2}}}$$\n    $$\\propto \\sigma^{-2-n+k} \\cdot \\exp{\\left( -\\frac{1}{2\\sigma^2} (y-X\\hat{\\beta})^T (y-X\\hat{\\beta}) \\right)}.$$\n\n    Compare this expression to the Inverse-$\\chi^2$ distribution\\footnote{https://en.wikipedia.org/wiki/Inverse-chi-squared\\_distribution}, we find that \n    $$s^2 = \\frac{1}{n-k} (y-X\\hat{\\beta})^T (y-X\\hat{\\beta}).$$\n}\n\n\\section*{Question 14.7}\n{\n    $\\widetilde{y}$ conforms a normal distribution, as $\\widetilde{y}$ is a linear combination of $\\beta$, and $p(\\beta | \\sigma, y)$ is normal.\n}\n\n\\section*{Longley data 1}\n{\n    The mean of Inverse-$\\mathrm{\\chi^2}(n-k, s^2)$ is\\footnote{https://en.wikipedia.org/wiki/Scaled\\_inverse\\_chi-squared\\_distribution} \n    $$\\frac{(n-k)s^2}{n-k-2}.$$\n    The calculated result is \n    \\begin{lstlisting}\n        [1] 6.003243\n    \\end{lstlisting}\n}\n\n\\section*{Longley data 2}\n{\n    The posterior mean of $\\beta$ under a conjugate prior $(\\beta_0, \\beta_1) \\sim N(0, I)$ is\n    \\begin{lstlisting}\n    (Intercept)           X \n     -76.759663    1.519031 \n    \\end{lstlisting}\n}\n\n\\section*{Longley data 3}\n{\n    \\begin{lstlisting}\n    > mod.full = BayesReg(dat$GNP.deflator, dat[, -1], g=nrow(dat))\n\n    PostMean PostStError Log10bf EvidAgaH0\n    Intercept 101.6813      0.7431                  \n    x1         23.8697     25.1230 -0.3966          \n    x2          3.1068      6.6053 -0.5603          \n    x3          0.7078      2.5134 -0.5954          \n    x4        -11.0111     10.9543 -0.3714          \n    x5         -6.1556     32.7640 -0.6064          \n    x6          0.7402     10.7025  -0.614          \n\n\n    Posterior Mean of Sigma2: 8.8342\n    Posterior StError of Sigma2: 13.0037\n\n    > mod = BayesReg(dat$GNP.deflator, dat[, c(-1, -3)], g=nrow(dat))\n\n    PostMean PostStError Log10bf EvidAgaH0\n    Intercept 101.6813      0.7494                  \n    x1         14.6884     15.9493 -0.4094          \n    x2         -0.3300      1.2139 -0.5968          \n    x3         -9.9863     10.8264 -0.4087          \n    x4          8.6301      9.3120 -0.4068          \n    x5         -3.5398      5.6814 -0.5194          \n\n\n    Posterior Mean of Sigma2: 8.9846\n    Posterior StError of Sigma2: 13.2249\n\n    > bf.full / bf\n    Bayes factor analysis\n    --------------\n    [1] GNP + Unemployed + Armed.Forces + Population + Year + Employed : 0.1443632 ±0%\n\n    Against denominator:\n    GNP.deflator ~ GNP + Armed.Forces + Population + Year + Employed \n    ---\n    Bayes factor type: BFlinearModel, JZS\n    \\end{lstlisting}\n\n    We find that the reduced model has similar coefficients to the full model. And the ratio of Bayes factor is much less than 1, which means the reduced model is more likely. \n}\n\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "46dec763516f089bdc68b3c681d004e5ab9e07c1", "size": 5234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW9/Homework9.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": "HW9/Homework9.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": "HW9/Homework9.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": 40.5736434109, "max_line_length": 254, "alphanum_fraction": 0.5867405426, "num_tokens": 1947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6588653393889171}}
{"text": "\n\\section{Mathematical functions and Python functions}\\label{sec:functions}\nA mathematical function is a rule that associates a single output value with each input value in a set \\cite{rudin}. Examples are:\n\\begin{eqnarray*}\n    f(x) = x^2 & \\textup{for each value $x$ in the real numbers}  \\\\\n    f(x) = \\sin(x)& \\textup{for each value $x$ in the real numbers}\\\\\n    f(x,y) = x^2 - (y-1)^2 & \\textup{for each pair of values $x,y$, each in the real numbers.}\n\\end{eqnarray*}\nNote the important distinction between the actual function $f$ and the evaluation $f(x)$ of the function at a particular point. Each evaluation of a function is just a single output value, but a function itself is an (often infinite) table of values. If you `look up' an input value in the table by evaluating the function, you'll find the corresponding output value.\n\nOne convenient way to visualize a function is by graphing it. The graphs of the first two functions above are curves. Their input and output values are single numbers, so the functions themselves are infinite tables of ordered pairs. The graph of the third function, on the other hand, is a surface. Its input value is a two-vector and its output value is a number, so the function itself is an infinite table of ordered triples. Ordered triples have to be plotted in three-dimensional space, so the graph ends up being a surface.\n\nPython functions can emulate mathematical functions. Python representations of the mathematical functions above are:\n\\begin{verbatim}\ndef f(x):\n    return x ** 2\n\ndef f(x):\n    return sin(x)\n\ndef f(x,y):\n    return x ** 2 - (y-1) ** 2\n\\end{verbatim}\nThese Python functions act like very large tables of values. If you `look up' an input value by passing it in as an argument, the function will tell you the corresponding output value. It would be very inefficient to store output values corresponding to each input value on a computer, so the functions have to figure out the output values corresponding to arbitrary input values on demand.\n\n\n\\section{A first look at Gaussian processes}\\label{sec:firstlook}\n\nGaussian processes are probability distributions for mathematical functions. The statement `random function $f$ has a Gaussian process distribution with mean $M$ and covariance $C$' is usually written as follows:\n\\begin{equation}\n    f\\sim\\textup{GP}(M,C).\n\\end{equation}\nGaussian processes have two parameters, which are analogous to the parameters of the normal distribution:\n\\begin{itemize}\n    \\item $M$ is the mean function. Like the mean parameter of the normal distribution, $M$ gives the central tendency for $f$. In Bayesian statistics, $M$ is usually considered a prior guess for $f$.\n    \\item $C$ is the covariance function. $C$ takes twice as many arguments as $f$; if $f$ is a function of one variable, $C$ is a function of two variables. $C(x,y)$ gives the covariance of $f(x)$ and $f(y)$, and $C(x,x)$ gives the variance of $f(x)$. Its role is harder to understand than that of the mean function, but among other things it regulates:\n    \\begin{itemize}\n        \\item the amount by which $f$ may deviate from $M$ at any input value $x$,\n        \\item the roughnesss of $f$,\n        \\item the typical lengthscale of changes in $f$.\n    \\end{itemize}\n\\end{itemize}\nSection \\ref{sec:cov} will look at covariance functions in more depth; for the time being don't worry about them too much.\n\nAs with any probability distribution, random values can be drawn from a Gaussian process. However, these values (called `realizations') are actually mathematical functions rather than the usual numbers or vectors. On the computer, the random values we draw will essentially be Python functions, with a few extra features.\n\n\\subsection{What are Gaussian processes good for?}\\label{sub:applications}\nMathematical functions are ubiquitous in science. A very short list of examples:\n\\begin{itemize}\n    \\item Functional responses in predator-prey dynamics \\cite{mathecol}. These functions associate a value for rate of prey capture with each value of predator population size.\n    \\item Transmission functions in epidemiology \\cite{andersonmay}. These functions associate a value for rate of new infections with each value of infected and uninfected population size.\n    \\item Transfer functions in engineering \\cite{duffy}. These functions associate a value for a ratio of Laplace transformed input and output signals with each value of the Laplace input variable $s$.\n    \\item Utility functions in microeconomics \\cite{microecon}. These functions associate a value for a person's satisfaction with each portfolio of goods.\n    \\item Action potentials in neuroscience \\cite{neuro}. These functions associate a value for transmembrane potential with each value of time since depolarization.\n    \\item The annual mean temperature at each point on the earth's surface in earth and atmospheric sciences.\n\\end{itemize}\n\nThe problem of estimating functions is equally widespread, because researchers frequently want to find out what each of the above functions is. In some cases, the phenomena underlying a function are simple and well-understood enough that the function can be derived up to a handful of parameters. For example, in Newtonian mechanics the height of a rock is known to be a parabolic function of the time since it was thrown, and the problem of inferring its trajectory reduces to the problem of inferring its initial height, its initial velocity and the acceleration due to gravity.\n\nIn many other cases it's not possible to deduce nearly as much about a function a priori. In some cases several candidate forms exist, but it's not possible to rule all of them out or even to ascertain that they are the only possibilities. As flexible and convenient probability distributions on function spaces, Gaussian processes are useful for Bayesian inference of functions without the need for reducing the problem to inference of a set of parameters.\n\n\\subsection{Creating a Gaussian process}\\label{sub:inst}\n\nIn the following subsections we will create objects representing a covariance function, a mean function, and finally several random functions drawn from the Gaussian process distribution defined by those objects.\n\n\\subsubsection{Creating a mean function}\\label{subsub:mean}\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/mean.pdf,width=10cm}\n    \\caption{The mean function generated by {\\sffamily `examples/mean.py'}.}\n    \\label{fig:mean}\n\\end{figure}\n\nThe first component we will create is a mean function, represented by class \\class{Mean}. The mean function of a univariate GP can be interpreted as a prior guess for the GP, so it's a univariate function also. The \\class{Mean} class is a wrapper for an ordinary Python function. We will use the parabolic function\n\\begin{equation}\n    M(x) = ax^2 + bx + c.\n\\end{equation}\n\nThe following code will produce an instance of class \\class{Mean} called M:\n\\verbatiminput{../../examples/gp/mean.py}\n\nThe first argument to \\class{Mean}'s init method is the underlying Python function, in this case \\function{quadfun}. The extra arguments \\code{a}, \\code{b}  and \\code{c} will be memorized and passed to \\function{quadfun} whenever M is called; the call \\texttt{M(x)} in the plotting portion of the script doesn't need to pass them in.\n\nMean functions broadcast over their arguments in the same way as \\citetitle[http://docs.scipy.org/doc/numpy/reference/ufuncs.html]{NumPy universal functions} \\cite{numpybook}, which means that \\texttt{M(x)} will return the vector\n\\begin{eqnarray*}\n    \\texttt{[M(x[0]),\\ldots, M(x[N-1])]}.\n\\end{eqnarray*}\n\nThe last part of the code plots \\texttt{M(x)} on $-1<\\texttt{x}<1$, and its output is shown in figure \\ref{fig:mean}. As expected, the plot is a parabola.\n\n\\subsubsection{Creating a covariance function}\\label{subsub:cov}\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/cov.pdf,width=15cm}\n    \\caption{The covariance function generated by {\\sffamily `examples/cov.py'}. On the left is the covariance function $C(x,y)$ evaluated over a square: $-1\\le x\\le 1,\\ -1\\le y\\le 1$. On the right is a slice of the covariance: $C(x,0)$ for $0\\le x \\le 1$}\n    \\label{fig:cov}\n\\end{figure}\n\nGP covariance functions are represented by the class \\class{Covariance}, which like \\class{Mean} is essentially a wrapper for ordinary Python functions. In this example we will use the popular Mat\\`ern covariance function \\cite{banerjee}, which is provided in module \\module{cov_funs}. In addition to the two arguments \\texttt{x} and \\texttt{y}, this function takes three tunable parameters: \\code{amp} controls the amount by which realizations may deviate from their mean, \\code{diff_degree} controls the roughness of realizations (the degree of differentiability), and \\code{scale} controls the lengthscale over which realizations change.\n\nYou're free to write your own functions to wrap in \\class{Covariance} objects. See section \\ref{cha:usercov} for more information.\n\nThe code in \\file{examples/cov.py} will produce an instance of class \\class{Covariance} called C.\n\\verbatiminput{../../examples/gp/cov.py}\n\nThe first argument to \\class{Covariance}'s init method, \\function{eval_fun}, gives the Python function from which the covariance function will be made. In this case, \\function{eval_fun} is \\function{matern.euclidean}. The extra arguments \\code{diff_degree, amp} and \\code{scale} will be passed to \\function{matern.euclidean} every time C is called.\n\nAt this stage, the covariance function C exposes a very simple user interface. In fact, it behaves a lot like the ordinary Python function \\texttt{matern.euclidean} that it wraps, except that like \\texttt{Mean} it `memorizes' the parameters \\code{diff_degree, amp} and \\code{scale} so that you don't need to pass them in when you call it. Covariance functions' calling conventions are slightly different than ordinary numpy universal functions' \\cite{numpybook}:\n\\begin{enumerate}\n    \\item Broadcasting works differently. If C were a numpy universal function, \\texttt{C(x,y)} would return the following array:\n    \\begin{eqnarray*}\n        \\begin{array}{ccc}\n            \\texttt{[C(x[0],y[0])}& \\ldots& \\texttt{C(x[N-1],y[N-1])]},\n        \\end{array}\n    \\end{eqnarray*}\n    where \\texttt{x} and \\texttt{y} would need to be vectors of the same length. In fact \\texttt{C(x,y)} returns a matrix:\n    \\begin{eqnarray*}\n        \\left[\\begin{array}{ccc}\n            \\texttt{C(x[0],y[0])}& \\ldots& \\texttt{C(x[0],y[Ny-1])}\\\\\n            \\vdots&\\ddots&\\vdots\\\\\n            \\texttt{C(x[Nx-1],y[0])}& \\ldots& \\texttt{C(x[Nx-1],y[Ny-1])}\n        \\end{array}\\right],\n    \\end{eqnarray*}\n    and input arguments \\texttt{x} and \\texttt{y} don't need to be the same length.\n    \\item You can call covariance functions with just one argument. \\texttt{C(x)} returns\n    \\begin{eqnarray*}\n         \\texttt{[C(x[0],x[0])}& \\ldots& \\texttt{C(x[Nx-1],x[Nx-1])]} = \\texttt{diag(C(x,x))},\n    \\end{eqnarray*}\n    but is computed much faster than \\texttt{diag(C(x,x))} would be.\n\\end{enumerate}\n\nMost of the code in \\file{examples/cov.py} is devoted to output, which is shown in figure \\ref{fig:cov}. It plots the covariance function \\texttt{C(x,x)} evaluated over a square, and also the `slice' \\texttt{C(x,0)} over an interval. You'll notice that the graph of the full covariance function resembles a rounded A-frame tent.\n\n\\subsubsection{Drawing realizations}\\label{subsub:realizations}\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/realizations.pdf,width=10cm}\n    \\caption{Three realizations from a Gaussian process displayed with mean $\\pm$ 1 sd envelope. Generated by {\\sffamily `examples/realizations.py'}.}\n    \\label{fig:realizations}\n\\end{figure}\n\nFinally, let's generate some realizations (draws) from the Gaussian process defined by M and C and take a look at them. The following code will generate a list of \\class{Realization} objects:\n\\verbatiminput{../../examples/gp/realizations.py}\n\n    The init method of \\class{Realization} takes only two required arguments, a \\class{Mean} object and a \\class{Covariance} object. Each element of \\code{f_list} is a Gaussian process realization, which is essentially a randomly-generated Python function. Like \\class{Mean} objects, \\class{Realization} objects use the same broadcasting rules as numpy universal functions. Typing \\texttt{f(x)} will return the vector\n\\begin{eqnarray*}\n    [\\texttt{f(x[0])}\\ldots \\texttt{f(x[N-1])}].\n\\end{eqnarray*}\n\n\nThe plotting portion of the code calls the function \\function{plot_envelope}, which summarizes some aspects of the distribution. The dashdot black line in the middle is $M$, and the gray band is the $\\pm 1$ standard deviation envelope for $f$, generated by $C$. Each of the three realizations in \\texttt{f_list} is a callable function, and they are plotted superimposed on the envelope. The plot output is shown in figure \\ref{fig:realizations}.\n\n\n\\section{The role of the covariance function}\\label{sec:cov}\nThe following covariance functions for Euclidean coordinates are included in the module \\module{cov_funs}:\n\\begin{itemize}\n    \\item \\texttt{matern.euclidean}\n    \\item \\texttt{sphere.euclidean}\n    \\item \\texttt{pow_exp.euclidean}\n    \\item \\texttt{gaussian.euclidean}\n    \\item \\texttt{quadratic.euclidean}\n\\end{itemize}\nSee section 2.1.3 of \\citetitle[http://www.statsnetbase.com/ejournals/books/book_summary/summary.asp?id=1285]{Banerjee et al.} \\cite{banerjee} for more information on each of these. Each covariance function takes at least two parameters, called \\texttt{amp} and \\texttt{scale}. The following covariance functions take extra parameters:\n\\begin{description}\n    \\item[\\texttt{matern}:] \\texttt{diff_degree}\n    \\item[\\texttt{pow_exp}:] \\texttt{pow}\n    \\item[\\texttt{quadratic}:] \\texttt{phi}.\n\\end{description}\n\nIn this section we'll focus on the Mat\\`ern family, as it is generally considered the state of the art. Its popularity is due to the fact that it has three parameters, each of which clearly controls one of three important properties of realizations: roughness, lengthscale of changes and amplitude.\n\nIn this section we'll set the mean function to zero (more precisely, a function whose output value is zero regardless of input) in order to focus on the covariance. This:\n\\begin{eqnarray*}\n    f\\sim\\textup{GP}(M,C)\n\\end{eqnarray*}\nis equivalent to this:\n\\begin{eqnarray*}\n    f = M + g, \\\\g\\sim \\textup{GP}(0,C),\n\\end{eqnarray*}\nso it's not difficult to adapt the intuition we gain in this section to GPs with nontrivial mean functions.\n\nThe covariance functions listed above are \\emph{stationary} and \\emph{isotropic}. Intuitively, that means our a priori expectation of how $f$ will deviate from its mean doesn't vary with location or with the direction in which we look (for functions of several variables). Section \\ref{cha:usercov} describes how these restrictions can be relaxed.\n\nAll the figures in this section were produced using the file \\file{examples/cov_params.py}. You can follow along by editing the line of that file which reads\n\\begin{verbatim}\nC = Covariance(eval_fun = matern.euclidean, diff_degree = 1.4, amp = 1., scale = 1.)\n\\end{verbatim}\n\nThe actual formulas for the covariance functions are given in section \\ref{cha:usercov}, but the Mat\\`ern formula is fairly inscrutable (though its Fourier transform is much more readable \\cite{stein}). This section will try to help you understand it graphically.\n\n\\subsection*{The \\texttt{amp} and \\texttt{scale} parameters}\\label{sub:ampscale}\n\nThese parameters are common to all covariance functions provided by this package, not just \\texttt{matern.euclidean}. Please see section \\ref{cha:usercov} if you're planning on writing your own covariance functions, as this package provides utilities that will endow them with these parameters.\n\nAs mentioned in section \\ref{subsub:cov}, the covariance function plotted in figure \\ref{fig:cov} resembles a rounded A-frame tent. The width of this tent controls how tightly nearby evaluations of a realization $f$ will be coupled to each other. If the tent is wide, $f(x)$ and $f(y)$ will tend to have similar values when $x$ and $y$ are close to one another. If the tent is narrower, $f(x)$ and $f(y)$ won't be as tightly correlated. The height of the tent controls the overall amplitude of $f$'s deviation from its mean.\n\nThe mathematical definition of the covariance function is as follows:\n\\begin{equation}\n    \\label{covdef}\n    C(x,y)=\\textup{cov}(f(x), f(y)).\n\\end{equation}\nThat implies the following:\n\\begin{eqnarray*}\n    \\textup{var}(f(x))=C(x,x).\n\\end{eqnarray*}\nBy the definition of variance, for any real number $a$\n\\begin{eqnarray*}\n    \\textup{var}( a f(x))=a^2 C(x,x).\n\\end{eqnarray*}\n\nThe covariance function is multiplied by \\texttt{amp}$^\\texttt{2}$, and this effectively multiplies realizations by \\texttt{amp}. In other words, a larger \\texttt{amp} parameter means that realizations will deviate further from their mean. The effects of changing the \\texttt{amp} parameter are illustrated in figure \\ref{fig:amp}.\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/d14a1s1.pdf, width=8cm}\n        \\epsfig{file=figs/d14a4s1.pdf, width=8cm}\n    \\caption{Mat\\`ern covariances with \\texttt{diff_degree=1.4}, \\texttt{scale=1}, and \\texttt{amp=1} (left) and 4 (right), and corresponding realizations. The amplitude of realizations tends to scale with \\texttt{amp}, and the amplitude of the covariance function scales with \\texttt{amp}$^2$. Note the scales on the plots of the covariance functions.}\n    \\label{fig:amp}\n\\end{figure}\n\nSay $C$'s value can be computed from the difference in its arguments, $x-y$, rather than the arguments themselves. In that case, substituting $(x-y)/s$ for $x-y$, where $s$ is greater than 1, will make the input points `appear' closer together.\n\nWhenever a call $C(x,y)$ is made, the distances between elements of the input arrays $x$ and $y$ are divided by the \\texttt{scale} parameter before being passed to the underlying covariance function. In our one-dimensional example this effectively stretches the realizations in the $x$ direction. If \\texttt{scale} is large, the function will be correlated over a larger distance and will not `wiggle' as quickly. Figure \\ref{fig:scale} illustrates the effects of the scale parameter.\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/d14a1s1close.pdf, width=5cm}\n        \\epsfig{file=figs/d14a1s4.pdf, width=5cm}\n        \\epsfig{file=figs/d14a1s4far.pdf, width=5cm}\n    \\caption{Mat\\`ern covariances with \\texttt{diff_degree=1.4}, \\texttt{amp=1} and \\texttt{scale=1} (left) and \\texttt{scale=4} (center, right), and corresponding realizations. A larger value of \\texttt{scale} stretches both covariance functions and realizations (center), so that realizations don't wiggle as rapidly. When the stretched functions are plotted on commensurately stretched axes (right), they look like the unstretched functions again.}\n    \\label{fig:scale}\n\\end{figure}\n\n\\subsection{The \\texttt{diff_degree} parameter}\\label{sub:diffdegree}\nThe \\texttt{diff_degree} parameter, usually denoted $\\nu$, is unique (amongst the covariance functions provided by this package) to the Mat\\`ern family of covariance functions. It controls the sharpness of the ridge of the covariance function, which controls the roughness/smoothness of realizations.\n\nMore specifically, look at the slices $C(x,0)$ that are shown in the upper right-hand panels of the subfigures in figures \\ref{fig:amp} and \\ref{fig:scale}. If \\texttt{diff_degree} is greater than an integer $n$, this slice is $2n$ times differentiable at $x=0$. It turns out that this means realizations will be $n$ times differentiable.\n\nIt's natural to ask what happens when \\texttt{diff_degree} isn't an integer. There is such a thing as \\citetitle[http://en.wikipedia.org/wiki/Fractional_calculus]{fractional calculus}, which deals with things like taking half a derivative. Stein \\cite{stein} discusses the connection briefly. See also Miller and Ross \\cite{fraccalc}.\n\nFor our purposes, it's safe to say that \\texttt{diff_degree} is a roughness index that can be interpreted as a degree of differentiability when it is an integer. Figure \\ref{fig:diffdegree} illustrates the effects of changing this parameter:\n\\begin{description}\n    \\item[0 (not shown):] $C(x,y)=1$ if $y=x$, $0$ if $\\texttt{x}\\ne \\texttt{y}$. Not only are realizations not differentiable, they're not even continuous. $f(x)$ is an independent normal random variable for each value of $x$.\n    \\item[.2:] $C(x,0)$ is not even one time differentiable at its peak, where $x=0$. Realizations are very rough, but continuous.\n    \\item[.5:] If \\texttt{diff_degree} is just larger than $.5$, $C(x,0)$ is differentiable at $x=0$. Realizations, however, aren't differentiable; their roughness is comparable to trajectories of Brownian particles. When \\texttt{diff_degree} is equal to \\texttt{.5}, \\texttt{matern} is equivalent to another covariance function, \\texttt{pow_exp}, with extra argument \\texttt{pow=1}.\n    \\item[1:] If \\texttt{diff_degree} is just larger than $1$, $C(x,0)$ is twice differentiable at $x=0$, and realizations are differentiable.\n    \\item[1.4:] The value from figures \\ref{fig:amp}, \\ref{fig:cov} and \\ref{fig:scale} is shown for comparison.\n    \\item[2:] If \\texttt{diff_degree} is just larger than $2$, $C(x,0)$ is four times differentiable at $x=0$, and realizations are twice differentiable.\n    \\item[10:] Realizations are very smooth. As \\texttt{diff_degree} approaches infinity, \\texttt{matern} gets closer to \\texttt{gaussian}. Realizations from GPs with Gaussian covariances are infinitely differentiable. In fact, if \\texttt{diff_degree} is larger than 10 \\texttt{matern} simply calls \\texttt{gaussian}, because it's much faster. \n\\end{description}\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/d2a1s1.pdf,width=8cm}\n        % \\epsfig{file=figs/d4a1s1.pdf,width=4cm}\n        \\epsfig{file=figs/d5a1s1.pdf,width=8cm}\n        % \\epsfig{file=figs/d8a1s1.pdf,width=4cm}\n        \\epsfig{file=figs/d10a1s1.pdf,width=8cm}\n        \\epsfig{file=figs/d14a1s1close.pdf,width=8cm}\n        \\epsfig{file=figs/d20a1s1.pdf,width=8cm}\n        \\epsfig{file=figs/d100a1s1.pdf,width=8cm}\n    \\caption{Matern draws for various \\texttt{diff_degree} parameters. In increasing orders of smoothness: \\texttt{.2}, \\texttt{.5}, (equivalent to \\texttt{pow_exp} with \\texttt{pow=1}, roughness similar to Brownian motion), \\texttt{1}, \\texttt{1.4} (the examples given so far), \\texttt{2}, \\texttt{10} (nearly equivalent to \\texttt{gaussian}).}\n    \\label{fig:diffdegree}\n\\end{figure}\n\n\\subsection{Suggestions for further experimentation}\n\\label{sec:experiment}\n\n\n\\begin{itemize}\n    \\item Change the parameters of the Mat\\`ern covariance function, and try to guess how realizations will look.\n    \\item Differentiate realizations numerically. Recall that\n    \\begin{eqnarray*}\n        \\frac{df}{dx}=\\lim_{h\\rightarrow 0} \\frac{f(x+h)-f(x)}{h},\n    \\end{eqnarray*}\n    so you can take an approximate `numerical derivative' by evaluating the fraction on the right hand side with $h$ equal to a small number.\n    \\item Replace \\texttt{matern.euclidean} in \\file{examples/cov_params.py} with the Euclidean version of one of the other covariance functions and experiment with the parameters. See Banerjee \\cite{banerjee} for their interesting properties.\n    \\item Replace \\function{zero_fun} in \\file{cov_params.py} with a nontrivial mean function and repeat the preceding.\n\\end{itemize}\n\n\\section{Nonparametric regression: observing Gaussian processes}\\label{sec:observing}\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/obs.pdf,width=8cm}\n        \\epsfig{file=figs/cond.pdf,width=8cm}\n    \\caption{The output of {\\sffamily `examples/observations.py'}: the observed GP with \\texttt{obs_V = .002} (left) and \\texttt{obs_V = 0} (right). Note that in the conditioned case, the $\\pm$ 1 SD envelope shrinks to zero at the points where the observations were made, and all realizations pass through the observed values. Compare these plots to those in figure \\ref{fig:realizations}.}\n    \\label{fig:obs}\n\\end{figure}\n\nConsider the following common statistical situation: You decide on a GP prior for an unknown function $f$, then you observe the value of $f$ at $N$ input points $[o_0\\ldots o_{N-1}]$, possibly with uncertainty. If the observation error is normally distributed, it turns out that $f$'s posterior distribution given the new information is another Gaussian process, with new mean and covariance functions.\n\nThe probability model that represents this situation is as follows:\n\\begin{equation}\n    \\label{regprior}\n    \\left.\\begin{array}{l}\n        \\textup{data}_i \\stackrel{\\tiny{\\textup{ind}}}{\\sim} \\textup{N}(f(o_i), V_i)\\\\\n        f \\sim \\textup{GP}(M,C)\\\\\n    \\end{array}\\right\\}\\Rightarrow f|\\textup{data} \\sim \\textup{GP}(M_o, C_o).\n\\end{equation}\nThis package provides a function called \\function{observe} that imposes normally-distributed observations on Gaussian process distributions. This function converts $f$'s prior to its posterior by transforming $M$ and $C$ in equation \\ref{regprior} to $M_o$ and $C_o$:\n\nThe following code (from \\file{observation.py}) imposes the observations\n\\begin{eqnarray*}\n    f(-.5) = 3.1\\\\\n    f(.5) = 2.9\n\\end{eqnarray*}\nwith observation variance $V=.002$ on the GP distribution defined in \\file{mean.py} and \\file{cov.py}:\n\\verbatiminput{../../examples/gp/observation.py}\n\nThe function \\function{observe} takes a covariance $C$ and a mean $M$ as arguments, and essentially tells them that their realizations' values on \\code{obs_mesh} have been observed to be \\code{obs_vals} with variance \\code{obs_V}. If \\code{obs_V} is \\code{None}, \\function{observe} assumes that the observation precision was infinite; that is, that the realizations' values on \\code{obs_mesh} were observed with no uncertainty. Making (or pretending to make) observations with infinite precision is sometimes called \\emph{conditioning}, and can be a valuable tool for modifying GP priors; for example, if a rate function is known to be zero when a population's size is zero.\n\nThe output of the code is shown in figure \\ref{fig:obs}, along with the output with \\code{obs_V=None}. Compare these to the analogous figure for the unobserved GP, figure \\ref{fig:realizations}. The covariance after observation is visualized in figure \\ref{fig:obscov}. The covariance `tent' has been pressed down at points where $x\\approx \\pm .5$ and/or $y\\approx\\pm .5$, which are the values where the observations were made.\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/obscov.pdf,width=10cm}\n    \\caption{The covariance function from {\\sffamily `observation.py'} after observation. Compare this with the covariance function before observation, visualized in figure \\ref{fig:cov} }\n    \\label{fig:obscov}\n\\end{figure}\n\n\\subsection{Example: Salmonid stock-recruitment functions}\\label{sub:MMKregression}\nMunch, Kottas and Mangel \\cite{mmk} use Gaussian process priors to infer various \\emph{stock-recruitment (SR) functions}. An important concept in fishery science, SR functions relate the size of a fish stock to the number or biomass of recruits to the fishery each year. In other words, they relate population size or biomass to number or biomass of new fish produced. The authors argue that model uncertainty is endemic in stock-recruitment theory, and that in this situation GP priors are a sensible alternative to particular functional forms.\n\nWe don't have the tools yet to fully duplicate Munch, Kottas and Mangel' results; that will have to wait for chapter \\ref{cha:PyMC}. However, we can fit a simpler version of their model now by using the \\function{observe} function. Specifically, we'll fit the data in figure 6 of their paper \\cite{mmk}, which is for three salmonids: chum (\\emph{Onchorhynchus keta}), pink (\\emph{Onchorhynchus gorbuscha}) and sockeye (\\emph{Onchorhynchus nerka}).\n\nThe code is in the script \\file{examples/gp/more_examples/MMKsalmon/regression.py}. The script begins by importing the \\class{salmon} class from \\file{salmon.py} in the same directory.\nThe \\class{salmon} class does the following:\n\\begin{itemize}\n    \\item Reads data from a csv file.\n    \\item Creates a GP prior with a Mat\\`ern covariance function and a linear mean function. The parameters are chosen fairly arbitrarily at this stage. In chapter \\ref{cha:PyMC}, we'll look at how to place priors on these parameters and infer them along with the unknown function itself.\n\n    Note also that I've specified the prior using the data; for instance, the \\texttt{scale} parameter depends on the maximum observed abundance. Some would consider this cheating.\n    \\item `Observes' the unknown function's value to be zero at the origin with no uncertainty. No matter what the data are, every draw from the posterior will have $f(0) = 0$. This isn't really an observation, it's just a convenient way to incorporate the knowledge that if there is no stock, there will be no recruitment.\n    \\item Provides a \\method{plot} method, which just plots the posterior envelope, data and three realizations from the posterior.\n\\end{itemize}\n% The code in \\file{examples/more_examples/MKMsalmon/salmon.py} is shown here:\n% \\verbatiminput{../../examples/gp/more_examples/MKMsalmon/salmon.py}\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/MMKchumreg.pdf,width=10cm}\n        \\epsfig{file=figs/MMKsockeyereg.pdf,width=10cm}\n        \\epsfig{file=figs/MMKpinkreg.pdf,width=10cm}\n    \\caption{Fits to the stock-recruitment data in Munch, Kottas and Mangel' \\cite{mmk} Figure 6 using a simple nonparametric regression.}\n    \\label{fig:MMKregression}\n\\end{figure}\n\nThe main script, \\file{examples/more_examples/MKMsalmon/salmon.py}, creates three \\class{salmon} instances called \\texttt{chum}, \\texttt{pink} and \\texttt{sockeye}, then imposes the data for each species on its prior to obtain its posterior. The observation variance I used was chosen fairly arbitrarily like the prior parameters, and we'll look at inferring it in chapter \\ref{cha:PyMC} also. Finally, each species' \\method{plot} method is called. Output is shown in figure \\ref{fig:MMKregression}.\n% The code in \\file{examples/more_examples/MKMsalmon/regression.py} is shown here:\n% \\verbatiminput{../../examples/gp/more_examples/MKMsalmon/regression.py}\n\nTo reiterate, there are some major drawbacks to this simple model. The observation variance may not actually be known, and we may not be comfortable specifying a single value for each of the prior parameters. Because of these considerations, Munch, Kottas and Mangel opt for a more sophisticated statistical model that has to be fit using MCMC. We will follow them in section \\ref{sub:MMKMCMC}.\n\n\\section{Higher-dimensional GPs}\\label{sec:highdim}\n\nIn addition to functions of one variable such as $f(x)$, this package supports Gaussian process priors for functions of many variables such as $f(\\mathbf{x})$, where $\\mathbf{x}=[x_0\\ldots x_{n-1}]$. This is useful for modeling dynamical or biological functions of many variables as well as for spatial statistics.\n\nAny time you pass an array into a \\texttt{Mean}, \\texttt{Covariance} or \\texttt{Realization}'s init method or evaluate one of these objects on an array, the convention is that the array's last index iterates over spatial dimension. To evaluate a covariance C on the ordered pairs \\texttt{(0,1)}, \\texttt{(2,3)}, \\texttt{(4,5)} and \\texttt{(6,7)}, you could pass in the following two-dimensional array:\n\\begin{verbatim}\n[[0,1]\n [2,3]\n [4,5]\n [6,7]]\n\\end{verbatim}\nor the following three-dimensional array:\n\\begin{verbatim}\n[[[0,1]\n  [2,3]],\n\n  [4,5]\n  [6,7]]]\n\\end{verbatim}\nEither is fine, since in both the last index iterates over elements of the ordered pairs.\n\nThe exception to this rule is one-dimensional input arrays. The array\n\\begin{verbatim}\n[0, 1, 2, 3, 4, 5, 6, 7]\n\\end{verbatim}\nis interpreted as an array of eight one-dimensional values, whereas the array\n\\begin{verbatim}\n[[0, 1, 2, 3, 4, 5, 6, 7]]\n\\end{verbatim}\nis interpreted as a single eight-dimensional value according to the convention above.\n\nMeans and covariances learn their spatial dimension the first time they are called or observed. Some covariances, such as those specified in geographic coordinates, have an intrinsic spatial dimension. Realizations inherit their spatial dimension from their means and covariances when possible, otherwise they learn it the first time they are called. If one of these objects is subsequently called with an input of a different dimension, it raises an error.\n\n\\subsection{Covariance function bundles and coordinate systems}\nThe examples so far, starting with \\file{examples/cov.py}, have used the covariance function \\texttt{matern.euclidean}. This function is an attribute of the \\texttt{matern} object, which is an instance of class \\class{covariance_function_bundle}.\n\nInstances of \\class{covariance_function_bundle} have three attributes, \\texttt{euclidean}, \\texttt{geo_deg} and \\texttt{geo_rad}, which correspond to standard coordinate systems:\n\\begin{itemize}\n    \\item \\texttt{euclidean}: $n$-dimensional Euclidean coordinates.\n    \\item \\texttt{geo_deg}: Geographic coordinates (longitude, latitude) in degrees, with radius 1.\n    \\item \\texttt{geo_rad}: Geographic coordinates (longitude, latitude) in radians, with radius 1.\n\\end{itemize}\nNote that you can effectively change the radius of the geographic coordinate systems using the \\texttt{scale} parameter.\n\nCovariance function bundles are described in more detail in section \\ref{cha:usercov}.\n\n\\subsection{Multithreading GP operations}\nThis package can use multi-core systems to speed up two kinds of computations:\n\\begin{itemize}\n\t\\item filling in covariance matrices,\n\t\\item linear algebra for observing GP's or drawing realizations.\n\\end{itemize}\nIf you've built NumPy against multithreaded linear algebra libraries, all the linear algebra will be parallelized automatically. The functions contained in covariance function bundles (section \\ref{cha:usercov}), which include all the covariance functions distributed with this package, are multithreaded. The number of threads they use is controlled by the environment variable \\code{OMP_NUM_THREADS}. \n\nOn a quad-core system, evaluating a covariance function on large input vectors when \\texttt{OMP_NUM_THREADS} is equal to 4 will use all the cores. Note that there's no point setting \\texttt{OMP_TUM_THREADS} to 5 on a quad-core system, because only four cores are available.\n\n\n\\section{Basis covariances}\\label{sec:basis}\n\n\\begin{figure}[htbp]\n    \\centering\n        \\epsfig{file=figs/basiscov.pdf,width=10cm}\n        \\caption{Three realizations of an observed Gaussian process whose covariance is an instance of \\class{BasisCovariance}. The basis in this case is function \\function{fourier_basis} from module \\module{cov_funs}. 25 basis functions are used.}\n    \\label{fig:basiscov}\n\\end{figure}\n\nIt's possible to create random functions from linear combinations of finite sets of basis functions $\\{e\\}$ with random coefficients $\\{c\\}$:\n\\begin{eqnarray*}\n    f(x) = M(x) + \\sum_{i_0=0}^{n_0-1}\\ldots \\sum_{i_{N-1}=0}^{n_{N-1}-1} c_{i_1\\ldots i_{N-1}} e_{i_1\\ldots i_{N-1}}(x), &\n    \\{c\\}\\sim \\textup{some distribution}.\n\\end{eqnarray*}\nIf the distribution is multivariate normal with mean zero, $f$ is a Gaussian process with mean $M$ and covariance defined by\n\\begin{eqnarray*}\n    C(x,y)=\\sum_{i_0=0}^{n_0-1}\\ldots \\sum_{i_{N-1}=0}^{n_{N-1}-1} \\sum_{j_0=0}^{n_0-1}\\ldots \\sum_{j_{N-1}=0}^{n_{N-1}-1} e_{i_0\\ldots i_{N-1}}(x) e_{j_1\\ldots j_{N-1}}(x) K_{i_0\\ldots i_{N-1}, j_1\\ldots j_{N-1}},\n\\end{eqnarray*}\nwhere $K$ is the covariance of the coefficients $c$.\n\nParticularly successful applications of this general idea (shown in one dimension) are:\n\\begin{description}\n    \\item[Random Fourier series:] $e_i(x) = \\sin(i\\pi x/L)$ or $\\cos(i\\pi x/L)$, for instance \\cite{spanos}.\n    \\item[Gaussian process convolutions:] $e_i(x) = \\exp(-(x-\\mu_n)^2)$, for instance \\cite{convolution}.\n    \\item[B-splines:] $e_i(x) = $ a polynomial times an interval indicator. See \\citetitle[http://en.wikipedia.org/wiki/Basis_B-spline]{Wikipedia}'s article.\n\\end{description}\nSuch representations can be very efficient when there are many observations in a low-dimensional space, but are relatively inflexible in that they generally produce realizations that are infinitely differentiable. In some applications, this tradeoff makes sense.\n\nThis package supports basis representations via the \\class{BasisCovariance} class:\n\\begin{verbatim}\n    C = BasisCovariance(basis, cov, **basis_params)\n\\end{verbatim}\nThe arguments are:\n\\begin{description}\n    \\item[\\texttt{basis}:] Must be an array of functions, of any shape. Each basis function will be evaluated at \\texttt{x} with the extra parameters. The basis functions should obey the same calling conventions as mean functions: return values should have shape \\code{x.shape[:-1]} unless \\texttt{x} is one-dimensional, in which case return values should be of the same shape as \\texttt{x}. Note that each function should take the entire input array as an argument.\n    \\item[\\texttt{cov}:] An array whose shape is either:\n        \\begin{itemize}\n            \\item Of the same shape as \\texttt{basis}. In this case the coefficients are assumed independent, and \\texttt{cov[i[0],...,i[N-1]]} (an $N$-dimensional index) simply gives the prior variance of the corresponding coefficient.\n            \\item Of shape \\texttt{basis.shape * 2}, using Python's convention for tuple multiplication. In this case \\texttt{cov[i[0],...,i[N-1], j[0],...,j[N-1]]} (a $2N$-dimensional index) gives the covariance of $c_{i_0\\ldots i_{N-1}}$ and $c_{j_1\\ldots j_{N-1}}$.\n        \\end{itemize}\n        Internally, the basis array is ravelled and this covariance tensor is reshaped into a matrix; I have made the input convention this way because it seems easier to keep track of which covariance value corresponds to which coefficients. The covariance tensor must be symmetric (\\texttt{cov[i[0],...,i[N-1], j[0],...,j[N-1]]} $=$ \\texttt{cov[j[0],...,j[N-1], i[0],...,i[N-1]]}), and positive semidefinite when reshaped to a matrix.\n    \\item[\\texttt{basis_params}:] Any extra parameters required by the basis functions.\n\\end{description}\n\n\\section{Separable bases}\n\nMany bases, such as Fourier series, can be decomposed into products of functions as follows:\n\\begin{eqnarray*}\n    e_{i_0\\ldots i_{N-1}}(x) = e^0_{i_0}(x)\\ldots e^{N-1}_{i_{N-1}}(x)\n\\end{eqnarray*}\nBasis covariances constructed using such bases can be represented more efficiently using \\texttt{SeparableBasisCovariance} objects. These objects are constructed just like \\texttt{BasisCovariance} objects, but instead of an $n_0\\times \\ldots \\times n_{N-1}$ array of basis functions they take a nested lists of functions as follows:\n\\begin{verbatim}\n    basis = [ [e[0][0], ... ,e[0][n[0]-1]]\n                       ...\n              [e[N-1][0], ... ,e[N-1][n[N-1]-1]] ].\n\\end{verbatim}\nFor an $N$-dimensional Fourier basis, each of the \\texttt{e}'s would be a sine or cosine; frequency would increase with the second index. As with \\texttt{BasisCovariance}, each basis needs to take the entire input array \\texttt{x} and \\texttt{basis_params} as arguments. See \\texttt{fourier_basis} in \\texttt{examples/gp/basiscov.py} for an example.\n\n\\section{Example}\n\nOnce created, a \\class{BasisCovariance} or \\class{SeparableBasisCovariance} object behaves just like a \\class{Covariance} object, but it and any \\texttt{Mean} and \\texttt{Realization} objects associated with it will take advantage of the efficient basis representation in their internal computations. An example of \\class{SeparableBasisCovariance} usage is given in \\file{examples/basis_cov.py}, shown below. Compare its output in figure \\ref{fig:basiscov} to that of \\file{examples/observation.py}.\n\\verbatiminput{../../examples/gp/basiscov.py}\n", "meta": {"hexsha": "9c52bba10ce31c747e1f0545f044773ef19104c8", "size": 39930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pymc/gp/Docs/tutorial1.tex", "max_stars_repo_name": "matthew-brett/pymc", "max_stars_repo_head_hexsha": "3a31613f056e7993a449d89bafef5fdaa40d47e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-03T09:42:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-06T19:23:29.000Z", "max_issues_repo_path": "pymc/gp/Docs/tutorial1.tex", "max_issues_repo_name": "matthew-brett/pymc", "max_issues_repo_head_hexsha": "3a31613f056e7993a449d89bafef5fdaa40d47e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-09-27T02:00:41.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-27T02:15:32.000Z", "max_forks_repo_path": "pymc/gp/Docs/tutorial1.tex", "max_forks_repo_name": "matthew-brett/pymc", "max_forks_repo_head_hexsha": "3a31613f056e7993a449d89bafef5fdaa40d47e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-10-27T13:27:32.000Z", "max_forks_repo_forks_event_max_datetime": "2017-10-27T13:27:32.000Z", "avg_line_length": 84.4186046512, "max_line_length": 674, "alphanum_fraction": 0.7530929126, "num_tokens": 10635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6588118184918615}}
{"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{23 février, 2015}\n\\maketitle\nTheorem: if $f(x)=\\sum\\limits{a_nx^n}$ has radius of convergence $R$ then so does $\\sum\\limits{na_nx^{n-1}}$ and further $f'(x)=\\sum\\limits{na_nx^{n-1}}$ and $\\int_0^x{f(t)\\;\\mathrm{d}t}=\\sum\\limits{\\frac{a_n}{n+1}x^{n+1}}$\n\n\\subsection*{examples}\n$\\sum\\limits_{n=1}^\\infty{\\frac{2^n}{n5^n}}=\\sum\\limits_{n=1}^u{\\left(\\frac{2}{5}\\right)^n\\frac{1}{n}}$\n\n$\\sum\\limits_{n=1}^\\infty{\\frac{x^n}{n}}=\\int_{0}^x{\\sum\\limits_{n=0}{t^n}}=\\int{\\frac{x^{n+1}}{n+1}}=\\int_0^x{\\frac{1}{1-t}}=-\\ln(1-t)|_0^x=-\\ln(1-x)=-\\ln(1-\\frac{2}{5})=\\ln 5-\\ln 3$\n\n$\\sum\\limits_{n=0}{(n+1)x^n}=\\sum\\limits_{n=1}{nx^n}$\nantiderivative is $\\sum\\limits_{n=0}{x^n}=\\frac{1}{1-x}$ and our answer is $\\frac{1}{(1-x)^2}$\n\n$\\sum\\limits{\\frac{n+1}{2^n}}=\\frac{1}{1-\\frac{1}{2}}^2=\\frac{1}{\\frac{1}{2^2}}=4$\n\n\\subsubsection*{approximate pi}\n$\\tan^{-1} x=\\int_0^x{\\frac{1}{1+t^2}\\;\\mathrm{d}t}$\n\n$\\sum\\limits{(-t^2)^n}=\\frac{1}{1+t^2}=\\frac{1}{1-(-t^2)}$ as long as $-1<-t^2<1\\Leftrightarrow-1<t<1$\n\nand so $\\tan^{-1} x=\\int_0^x{\\sum\\limits_{n=0}^\\infty{(-1)^nt^2n}\\;\\mathrm{d}t}$\n\nwe can choose $\\pi/4$ or $\\pi/6$. now $\\frac{\\pi}{4}=\\tan^{-1}1$ but $-1<x<1$\n\nand so $\\pi/6=\\tan^{-1}\\frac{\\sqrt{3}}{3}=\\sum\\limits_{n=0}^\\infty{(-1)^n\\dots}$\n\n\n\\end{document}\n", "meta": {"hexsha": "1a85c709214913c9d42f27bfacb012469f91aba4", "size": 1514, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ra2/ra2-notes-2015-02-23.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-02-23.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-02-23.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": 36.9268292683, "max_line_length": 223, "alphanum_fraction": 0.6129458388, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6588118166547686}}
{"text": "\\chapter{Terminology on sets and functions}\n\\label{ch:sets_functions}\nThis appendix will cover some notions on sets and functions\nsuch as ``bijections'', ``equivalence classes'', and so on.\n\nRemark for experts: I am not dealing with foundational issues in this chapter.\nSee \\Cref{ch:zfc} (and onwards) if that's what you're interested in.\nConsequently I will not prove most assertions.\n\n\\section{Sets}\nA \\vocab{set} for us will just be a collection of elements (whatever they may be).\nFor example, the set $\\NN = \\{1, 2, 3, 4, \\dots\\}$ is the positive integers,\nand $\\ZZ = \\{ \\dots, -2, -1, 0, 1, 2, \\dots\\}$ is the set of all integers.\nAs another example, we have a set of humans:\n\\[ H = \\left\\{ x \\mid \\text{$x$ is a featherless biped} \\right\\}. \\]\n(Here the ``$\\mid$'' means ``such that''.)\n\nThere's also a set with no elements, which we call the \\vocab{empty set}.\nIt's denoted by $\\varnothing$.\n\nIt's conventional to use capital letters for sets (like $H$),\nand lowercase letters for elements of sets (like $x$).\n\n\\begin{definition}\nWe write $x \\in S$ to mean ``$x$ is in $S$'', for example $3 \\in \\NN$.\n\\end{definition}\n\n\\begin{definition}\n\tIf every element of a set $A$ is also in a set $B$,\n\tthen we say $A$ is a \\vocab{subset} of $B$,\n\tand denote this by $A \\subseteq B$.\n\tIf moreover $A \\neq B$, we say $A$ is a \\vocab{proper subset}\n\tand write $A \\subsetneq B$.\n\t(This is analogous to $\\le$ and $<$.)\n\n\tGiven a set $A$, the set of all subsets is denoted $2^A$\n\tor $\\PP(A)$ and called the \\vocab{power set} of $A$.\n\\end{definition}\n\\begin{example}\n\t[Examples of subsets]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\{1,2,3\\} \\subseteq \\NN \\subseteq \\ZZ$.\n\t\t\\ii $\\varnothing \\subseteq A$ for any set $A$. (Why?)\n\t\t\\ii $A \\subseteq A$ for any set $A$.\n\t\t\\ii If $A = \\{1,2\\}$ then $2^A =\n\t\t\\left\\{ \\varnothing, \\{1\\}, \\{2\\}, \\{1,2\\} \\right\\}$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}\n\tWe write\n\t\\begin{itemize}\n\t\t\\ii $A \\cup B$ for the set of elements in\n\t\t\\emph{either} $A$ or $B$ (possibly both),\n\t\tcalled the \\vocab{union} of $A$ and $B$.\n\t\t\\ii $A \\cap B$ for the set of elements in \\emph{both} $A$ and $B$, and\n\t\tcalled the \\vocab{intersection} of $A$ and $B$.\n\t\t\\ii $A \\setminus B$ for the set of elements in $A$ but \\emph{not} in $B$.\n\t\\end{itemize}\n\\end{definition}\n\n\\begin{example}\n\t[Examples of set operations]\n\tLet $A = \\{1,2,3\\}$ and $B = \\{3,4,5\\}$. Then\n\t\\begin{align*}\n\t\tA \\cup B &= \\{1,2,3,4,5\\} \\\\\n\t\tA \\cap B &= \\{3\\} \\\\\n\t\tA \\setminus B &= \\{1,2\\}.\n\t\\end{align*}\n\\end{example}\n\n\\begin{exercise}\n\tConvince yourself: for any sets $A$ and $B$,\n\twe have $A \\cap B \\subseteq A \\subseteq A \\cup B$.\n\\end{exercise}\n\nHere are some commonly recurring sets:\n\\begin{itemize}\n\t\\ii $\\CC$ is the set of complex numbers, like $3.2 + \\sqrt 2 i$.\n\t\\ii $\\RR$ is the set of real numbers, like $\\sqrt 2$ or $\\pi$.\n\t\\ii $\\NN$ is the set of positive integers, like $5$ or $9$.\n\t\\ii $\\QQ$ is the set of rational numbers, like $7/3$.\n\t\\ii $\\ZZ$ is the set of integers, like $-2$ or $8$.\n\\end{itemize}\n(These are pronounced in the way you would expect:\n``see'', ``are'', ``en'', ``cue'', ``zed''.)\n\n\\section{Functions}\nGiven two sets $A$ and $B$, a \\vocab{function} $f$ from $A$ to $B$\nis a mapping of every element of $A$ to some element of $B$.\n\nWe call $A$ the \\vocab{domain} of $f$, and $B$ the \\vocab{codomain}.\nWe write this as $f \\colon A \\to B$ or $A \\taking f B$.\n\\begin{abuse}\n\tIf the name $f$ is not important, we will often just write $A \\to B$.\n\\end{abuse}\nWe write $f(a) = b$ or $a \\mapsto b$ to signal that $f$ takes $a$ to $b$.\n\nIf $B$ has $0$ as an element and $f(a) = 0$,\nwe often say $a$ is a \\vocab{root} or \\vocab{zero} of $f$,\nand that $f$ \\vocab{vanishes} at $a$.\n\n\\subsection{Injective / surjective / bijective functions}\n\n\\begin{definition}\n\tA function $f \\colon A \\to B$ is \\vocab{injective}\n\tif it is ``one-to-one'' in the following sense:\n\tif $f(a) = f(a')$ then $a = a'$.\n\tIn other words, for any $b \\in B$,\n\tthere is \\emph{at most} one $a \\in A$ such that $f(a) = b$.\n\n\tOften, we will write $f \\colon A \\injto B$ to emphasize this.\n\\end{definition}\n\\begin{definition}\n\tA function $f \\colon A \\to B$ is \\vocab{surjective}\n\tif it is ``onto'' in the following sense:\n\tfor any $b \\in B$ there is \\emph{at least} one $a \\in A$\n\tsuch that $f(a) = b$.\n\n\tOften, we will write $f \\colon A \\surjto B$ to emphasize this.\n\\end{definition}\n\\begin{definition}\n\tA function $f \\colon A \\to B$ is \\vocab{bijective}\n\tif it is both injective and surjective.\n\tIn other words, for each $b \\in B$,\n\tthere is \\emph{exactly} one $a \\in A$ such that $f(a) = b$.\n\\end{definition}\n\n\\begin{example}\n\t[Examples of functions]\n\tBy ``human'' I mean ``living featherless biped''.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii There's a function taking every human to their\n\t\tage in years (rounded to the nearest integer).\n\t\tThis function is \\textbf{not injective},\n\t\tbecause for example there are many people with age $20$.\n\t\tThis function is also \\textbf{not surjective}: no one has age $10000$.\n\n\t\t\\ii There's a function taking every\n\t\tUSA citizen to their social security number.\n\t\tThis is also \\textbf{not surjective} (no one has SSN equal to $3$),\n\t\tbut at least it \\textbf{is injective} (no two people have the same SSN).\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Examples of bijections]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $A = \\{1,2,3,4,5\\}$ and $B = \\{6,7,8,9,10\\}$.\n\t\tThen the function $f \\colon A \\to B$ by $a \\mapsto a+5$ is a bijection.\n\t\t\\ii In a classroom with $30$ seats,\n\t\tthere is exactly one student in every seat.\n\t\tThus the function taking each student to the seat they're in\n\t\tis a bijection; in particular, there are exactly $30$ students.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\tAssume for convenience that $A$ and $B$ are finite sets.\n\tThen:\n\t\\begin{itemize}\n\t\t\\ii If $f \\colon A \\injto B$ is injective,\n\t\tthen the size of $A$ is at most the size of $B$.\n\t\t\\ii If $f \\colon A \\surjto B$ is surjective,\n\t\tthen the size of $A$ is at least the size of $B$.\n\t\t\\ii If $f \\colon A \\to B$ is a bijection,\n\t\tthen the size of $A$ equals the size of $B$.\n\t\\end{itemize}\n\\end{remark}\n\nNow, notice that if $f \\colon A \\to B$ is a bijection,\nthen we can ``apply $f$ backwards'':\n(for example, rather than mapping each student to the seat they're in,\nwe map each seat to the student sitting in it).\nThis is called an \\vocab{inverse function};\nwe denote it $f\\inv \\colon B \\to A$.\n\n\\subsection{Images and pre-images}\nLet $X \\taking f Y$ be a function.\n\n\\begin{definition}\n\tSuppose $T \\subseteq Y$.\n\tThe \\vocab{pre-image} $f\\pre(T)$ is the set of all\n\t$x \\in X$ such that $f(x) \\in T$.\n\tThus, $f\\pre(T)$ is a subset of $X$.\n\\end{definition}\n\\begin{example}\n\t[Examples of pre-image]\n\tLet $f \\colon H \\to \\ZZ$ be the age function from earlier.\n\tThen\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $f\\pre(\\{13, 14, 15, 16, 17, 18, 19\\})$ is the set of teenagers.\n\t\t\\ii $f\\pre(\\{0\\})$ is the set of newborns.\n\t\t\\ii $f\\pre(\\{1000, 1001, 1002, \\dots \\}) = \\varnothing$,\n\t\tas I don't think anyone is that old.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{abuse}\n\tBy abuse of notation, we may abbreviate $f\\pre(\\{y\\})$ to $f\\pre(y)$.\n\tSo for example, $f\\pre(\\{0\\})$ above becomes shortened to $f\\pre(0)$.\n\\end{abuse}\n\nThe dual notion is:\n\\begin{definition}\n\tSuppose $S \\subseteq X$.\n\tThe \\vocab{image} $f\\im(S)$ is the set of\n\tall things of the form $f(s)$.\n\\end{definition}\n\\begin{example}\n\t[Examples of images]\n\tLet $A = \\{1,2,3,4,5\\}$ and $B = \\ZZ$.\n\tConsider a function $f \\colon A \\to B$ given by\n\t\\[\n\t\tf(1) = 17 \\quad\n\t\tf(2) = 17 \\quad\n\t\tf(3) = 19 \\quad\n\t\tf(4) = 30 \\quad\n\t\tf(5) = 234.\n\t\\]\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The image $f\\im(\\{1,2,3\\})$ is the set $\\{17, 19\\}$.\n\t\t\\ii The image $f\\im(A)$ is the set $\\{17, 19, 30, 234\\}$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{ques}\n\tSuppose $f \\colon A \\surjto B$ is surjective.\n\tWhat is $f\\im(A)$?\n\\end{ques}\n\n\\section{Equivalence relations}\nLet $X$ be a fixed set now.\nA binary relation $\\sim$ on $X$ assigns a truth value ``true''\nor ``false'' to $x \\sim y$ for each $x$ or $y$.\nNow an \\vocab{equivalence relation} $\\sim$ on $X$ is a binary relation\nwhich satisfies the following axioms:\n\\begin{itemize}\n\t\\ii Reflexive: we have $x \\sim x$.\n\t\\ii Symmetric: if $x \\sim y$ then $y \\sim x$\n\t\\ii Transitive: if $x \\sim y$ and $y \\sim z$ then $x \\sim z$.\n\\end{itemize}\nAn \\vocab{equivalence class} is then a\nset of all things equivalent to each other.\nOne can show that $X$ becomes partitioned by these equivalence classes:\n\n\\begin{example}\n\t[Example of an equivalence relation]\n\tLet $\\NN$ denote the set of positive integers.\n\tThen suppose we declare $a \\sim b$ if $a$ and $b$ have the same last digit,\n\tfor example $131 \\sim 211$, $45 \\sim 125$, and so on.\n\n\tThen $\\sim$ is an equivalence relation.\n\tIt partitions $\\NN$ into ten equivalence classes,\n\tone for each trailing digit.\n\\end{example}\n\nOften, the set of equivalence classes will be denoted $X/{\\sim}$\n(pronounced ``$X$ mod sim'').\n", "meta": {"hexsha": "045539bc9e0944483aacde0f2211a53ce1c7a89a", "size": 8931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/backmatter/sets-functions.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/backmatter/sets-functions.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/backmatter/sets-functions.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.2183908046, "max_line_length": 82, "alphanum_fraction": 0.6552457731, "num_tokens": 3138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6588118166547685}}
{"text": "% ***********************************************************************************\r\n% Pure LaTeX part to be inserted in a document (be careful of depencies of packages & commands)\r\n% Prepared by Qingan Zhao and Ruitong Zhu under the supervision of Arnaud de La Fortelle\r\n% Fall 2017\r\n% 2D heat diffusion subsection of the modeling part\r\n% ***********************************************************************************\r\n\r\n\\subgroup{2}{Qingan Zhao and Ruitong Zhu}\r\n\r\n\\paragraph{Description}\r\nThe aim of this part is to describe and model a PDE that describes temperature dynamics in a two-dimensional body via heat conduction.\r\nBasically, heat conduction is the exchange of heat from regions of higher temperatures into regions with lower temperatures, which varies in the transfer rate for different materials.\r\n\r\nConsider a thin flat body with a constant thickness $h$ and uniform density $\\rho'$. Assume that the faces of the thin body are in perfect insulation, which means there is no heat flow travel in the out-of-plane direction of the body. Hence, heat can only flow in the direction within the plane of the body, which turns into a two-dimensional problem. Then a two-dimensional coordinate system is established such that each point of the body can be described with a coordinate $(x,y)$. Then the (2D-uniform) density of the body is $\\rho = \\rho' h$. Denote the temperature function of each point by $T$ so that the temperature of the body at position $(x,y)$ and time $t$ are described as $T(x,y,t)$, as shown in Figure~\\ref{heatSystem.fig}. The goal is to derive $T(x,y,t)$ when there is no internal heat source.\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{heatSystem.pdf}       \r\n\t\\caption{System description in 2 dimensions}\\label{heatSystem.fig}\r\n\\end{figure}\r\n\r\n\\paragraph{Model}\r\nConsider a small rectangular element of the body with vertices $(x,y)$, $(x+\\ud x,y)$, $(x, y+\\ud y)$, and $(x+\\ud x, y+\\ud y)$. The heat flows are shown in Figure~\\ref{heatElement.fig}.\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=8cm]{HeatElement.pdf}       \r\n\t\\caption{Heat flows in a small rectangular element of the body}\\label{heatElement.fig}\r\n\\end{figure}\r\n\r\nThe heat amount $Q$ (i.e the thermal energy) of the rectangular element at time $t$ is: \r\n\\begin{equation}\r\nQ(x,y,t)=C m T(x,y,t)\r\n\\end{equation}\r\nwhere $C$ is called \\emph{heat capacity}, which is a supposed to be constant (assuming the material is uniform and temperature do not vary too much); $m = \\rho A$ is the mass of the rectangular element where $A$ its surface.\r\n\r\nThe rate of thermal energy change with respect to time is therefore:\r\n\\begin{equation}\\label{thermalEnergyChange.eq}\r\n\\frac{\\partial Q}{\\partial t} = C\\rho \\ud x \\ud y\\frac{\\partial T}{\\partial t}\r\n\\end{equation}\r\n\r\nAs shown in Figure~\\ref{heatElement.fig}, the incoming flow is $F_1 + F_2 + F_3 + F_4$. Denote the heat flux $\\vec q$ in horizontal and vertical directions by $q_x$ and $q_y$, then we have:\r\n\\begin{eqnarray} \r\nF_1 &=& q_x(x,y,t)\\ud y\\label{flow1}\\\\\r\nF_2 &=& -q_y(x,y+\\ud y,t)\\ud x\\label{flow2}\\\\\r\nF_3 &=& q_y(x,y,t)\\ud x\\label{flow3}\\\\\r\nF_4 &=& -q_x(x+\\ud x,y,t)\\ud y\\label{flow4}\r\n\\end{eqnarray}\r\n\r\nNow, we know that according to energy conservation, the thermal energy variation of any small element (as in Equation~(\\ref{thermalEnergyChange.eq})) is equal to the total incoming heat flow.  By putting the partial flows as in Equations~(\\ref{flow1})-(\\ref{flow4}), this conservation principle yields:\r\n\\begin{equation}\\label{thermalEnergyChange.eq2}\r\nC\\rho \\ud x \\ud y\\frac{\\partial T}{\\partial t} = \\ud y [q_x(x,y,t)-q_x(x+\\ud x,y,t)]+\\ud xh[q_y(x,y,t)-q_y(x,y+\\ud y,t)]\r\n\\end{equation}\r\n\r\nNow, another physical principle, \\emph{Fourier's Law}, states that the heat flow is (negatively) proportional to the gradient of temperature:\r\n\\begin{equation}\\label{FourierLaw.eq}\r\n\\vec q = -k\\nabla T\r\n\\end{equation}\r\nwhere $k$ is known as the thermal conductivity of the material (also considered as a constant). Then $q_x$ and $q_y$ are expressed as:\r\n\\begin{equation}\r\n\\begin{split}\r\nq_x=-k\\frac{\\partial T}{\\partial x}\\\\\r\nq_y=-k\\frac{\\partial T}{\\partial y}\r\n\\end{split}\r\n\\end{equation}\r\n\r\nHence, Equation~(\\ref{thermalEnergyChange.eq2}) can be written as:\r\n\\begin{equation}\\label{thermalEnergyChange.eq3}\r\n\\frac{\\partial Q}{\\partial t}=k\\ud yh\\left(\\frac{\\partial T(x+\\ud x,y,t)}{\\partial x}-\\frac{\\partial T(x,y,t)}{\\partial x}\\right)+k\\ud xh\\left(\\frac{\\partial T(x,y+\\ud y,t)}{\\partial y}-\\frac{\\partial T(x,y,t)}{\\partial y}\\right)\r\n\\end{equation}\r\n\r\nCombine Equation~(\\ref{thermalEnergyChange.eq}) and~(\\ref{thermalEnergyChange.eq3}):\r\n\\begin{equation}\r\n\\frac{\\partial T(x,y,t)}{\\partial t}=\\frac{k}{c\\rho}\\left(\\frac{\\partial ^2 T(x,y,t)}{\\partial x^2}+\\frac{\\partial ^2 T(x,y,t)}{\\partial y^2}\\right)\r\n\\end{equation}\r\n\r\nDenote $k/c\\rho$ by $a^2$, and the two-dimensional heat equation can be drawn:\r\n\\begin{equation}\r\n\\frac{\\partial T}{\\partial t}=a^2\\left(\\frac{\\partial ^2 T}{\\partial x^2}+\\frac{\\partial ^2 T}{\\partial y^2}\\right)\r\n\\end{equation}\r\n\r\nIf we would like to solve the PDE in practice, the initial conditions and (or) boundary conditions need to be specified. For initial conditions, assume that in domain $\\Omega$:\r\n\\begin{equation}\r\nT(x,y,0)=\\phi(x,y) \r\n\\end{equation}\r\n\r\nAs for boundary conditions, we should know either the value or the gradient of the function at some boundaries (i.e., fixed temperature or fixed flow).\r\n\r\nFor fixed temperature, for example, at the boundary $x=0$, a boundary condition could be stated as follow:\r\n\\begin{equation}\r\nT(0, y, t)=0\r\n\\end{equation}  \r\nsuch a boundary condition means the temperature will always be $0$ at the line $x=0$ of the 2D plane.\r\n\r\nThe boundary condition could aslo be a fixed flow. For example, at the boundary $x=0$:\r\n\\begin{equation}\r\n\\nabla (0, y, t)=0\r\n\\end{equation}\r\nsuch a boundary condition means that there is no heat transfer at the line $x=0$ of the 2D plane.\r\n\r\nWhen the conditions are given, it is the time to solve the PDE. Most simple PDEs can be solved using analytical methods, such as separation of variables and transform techniques. If the analytical methods do not work, numerical methods can be implemented to find the numerical approximations to the solutions of the PDE. A practical example with boundary conditions will be given in Section 2.3, where the analytical solution will be derived.\r\n\r\nOnce a system has been solved, we could enhance it by implementing the optimization. One thing we could do is to add some controls. For example, we would like the temperature of a plane less as stable as possible. A proper cost function could be a mathematical expression giving $\\ud T/\\ud t$ as a function of the external heat sourse. Tools such as Kalman filter can be implemented to do the optimization. A real world example is in aircraft temperature monitoring, for which temperature changes that above a threshold should be warned. \r\n\r\n", "meta": {"hexsha": "e6fbe08e45e1cd9286e40d1a7eb3792fe5c788cb", "size": 6942, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modeling-2Dheat.tex", "max_stars_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_stars_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-29T06:19:28.000Z", "max_issues_repo_path": "modeling-2Dheat.tex", "max_issues_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_issues_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modeling-2Dheat.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": 67.3980582524, "max_line_length": 812, "alphanum_fraction": 0.7129069432, "num_tokens": 1870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6588118111434895}}
{"text": "%\n% CMPT 354: Database Systems I - A Course Overview\n% Section: Relational Model\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Relational Model}\n\t\\label{sec:relational-model}\n\\begin{easylist}\n\n\t& \\emph{Relational database:} Collection of tables (mathematical concept of a relation\n\t\t&& Tables have unique names; rows represent an entity or relationship\n\t\t\n\t& \\emph{Tuple:} Record/row of a relational database\n\t\t\n\t& \\emph{Relation:} Set of unique tuples\n\t\t&& \\emph{Relation instance:} Actual table with a particular set of rows\n\t\t\t&&& \\emph{Cardinality (relation instance):} Number of tuples in a given relation instance\n\t\t&& \\emph{Relation schema:} Column headings of a table\n\t\t\t&&& Consists of the names of the relation, the names of the columns, and the domain of each field\n\t\t\t&&& \\emph{Domain:} Set of possible values\n\t\t\t\t&&&& \\emph{Relation instance:} Subset of the Cartesian product of the domains; set of distinct, valid tuples/records\n\t\t\t\t\t&&&&& \\emph{Cartesian product:} All elements in a set paired with all elements in another set\n\t\t\t\t\t&&&&& I.e. One possible row\n\t\t\t&&& E.g. Customer relation: \\\\\n\t\t\tCustomer = \\{ sin, firstName, lastName, age, income \\} \\\\\n\t\t\tDomain: integer(9), char(20), char(20), integer, realNumber\n\t\t&& Degree (arity): Number of fields of a relation\n\n\\end{easylist}\n\\subsection{Relational Models vs. Databases}\n\t\\label{subsec:relational-model:relational-models-vs-databases}\n\\begin{easylist}\n\n\t& For differences in terminology, see table~\\ref{tab:equivalent-terms-for-relational-models-and-databases}\n\t\n\t\\Deactivate\n\t\\begin{table}[!htb]\n\t\t\\centering\n\t\t\\caption{Equivalent terms for Relational Models and Databases}\n\t\t\\label{tab:equivalent-terms-for-relational-models-and-databases}\n\t\t\\begin{tabular}{ l l }\n\t\t\tRelational models: & Databases: \\\\\n\t\t\t\\hline\n\t\t\tRelation schema & Table schema \\\\\n\t\t\tRelation instance / relation & Table \\\\\n\t\t\tField & Column/attribute \\\\\n\t\t\tTuple & Record/row\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\Activate\n\n\\end{easylist}\n\\clearpage", "meta": {"hexsha": "49c939a61e97804a334ba025e653dca21973bd1d", "size": 1981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-354-database-systems-i_partial/tex/relational-model.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-354-database-systems-i_partial/tex/relational-model.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-354-database-systems-i_partial/tex/relational-model.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": 36.0181818182, "max_line_length": 120, "alphanum_fraction": 0.7193336699, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.6588118037013291}}
{"text": "\n\n    \\filetitle{arf}{Run autoregressive function on a tseries object}{tseries/arf}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\nX = arf(X,A,Z,Range,...)\n\\end{verbatim}\n\n\\paragraph{Input arguments}\\label{input-arguments}\n\n\\begin{itemize}\n\\item\n  \\texttt{X} {[} tseries {]} - Input data from which initial condition\n  will be taken.\n\\item\n  \\texttt{A} {[} numeric {]} - Vector of coefficients of the\n  autoregressive polynomial.\n\\item\n  \\texttt{Z} {[} numeric \\textbar{} tseries {]} - Exogenous input series\n  or constant in the autoregressive process.\n\\item\n  \\texttt{Range} {[} numeric \\textbar{} Inf {]} - Date range on which\n  the new time series observations will be computed; \\texttt{RANGE} does\n  not include pre-sample initial condition. \\texttt{Inf} means the\n  entire possible range will be used (taking into account the length of\n  pre-sample initial condition needed).\n\\end{itemize}\n\n\\paragraph{Output arguments}\\label{output-arguments}\n\n\\begin{itemize}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item\n  \\texttt{X} {[} tseries {]} - Output data with new observations created\n  by running an autoregressive process described by \\texttt{A} and\n  \\texttt{Z}.\n\\end{itemize}\n\n\\paragraph{Description}\\label{description}\n\nThe autoregressive process has one of the following forms:\n\n\\begin{verbatim}\nA1*x + A2*x(-1) + ... + An*x(-n) = z,\n\\end{verbatim}\n\nor\n\n\\begin{verbatim}\nA1*x + A2*x(+1) + ... + An*x(+n) = z,\n\\end{verbatim}\n\ndepending on whether the range is increasing (running forward in time),\nor decreasing (running backward in time). The coefficients\n\\texttt{A1},\\ldots{}\\texttt{An} are gathered in the input vector\n\\texttt{A},\n\n\\begin{verbatim}\nA = [A1,A2,...,An].\n\\end{verbatim}\n\n\\paragraph{Example}\\label{example}\n\nThe following two lines create an autoregressive process constructed\nfrom normally distributed residuals,\n\n\\[ x_t = \\rho x_{t-1} + \\epsilon_t \\]\n\n\\begin{verbatim}\nrho = 0.8;\nX = tseries(1:20,@randn);\nX = arf(X,[1,-rho],X,2:20);\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "6bcc8bb1868c042b4150361b1f86ef0ab69755e6", "size": 1974, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/tseries/arf.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/tseries/arf.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/tseries/arf.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": 25.3076923077, "max_line_length": 81, "alphanum_fraction": 0.7137791287, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6587683664881511}}
{"text": "Intuitively, an abstract state of the Parametric Hypercubes domain (\\adomain) tracks disjunctive information relying on floating-point intervals of fixed width. A state of \\adomain\\ is made by a set of hypercubes of dimension $|\\variables|$. Each hypercube has $|\\variables|$ sides, one for each variable, and each side contains an abstract non-relational value for the corresponding variable. Each hypercube represents a set of admissible combinations of values for all variables. \n\nThe name Hypercubes comes from the geometric interpretation of the elements of \\adomain . The concrete state of a program with variables in $\\variables$ is an environment in $\\funzione{\\variables}{\\real}$. This can be isomorphically represented by a tuple of values where each item of the tuple represents a program variable. Seen in this way, the concrete state corresponds, geometrically, to \\emph{a point} in the $|\\variables|$-dimensional space. \n%Each dimension of the space represents the possible values that the corresponding variable of the program can assume. The concrete trace of a program is a sequence of points in such space (one for each state of the trace). \nThe hypercubes of our domain \\adomain\\ are \\emph{volumes} in the same $|\\variables|$-dimensional space. \n%Each side of the hypercube is the concretization of the abstract value of the corresponding variable, and thus it corresponds to a set of values in that dimension of the space. The concretization of an hypercube is the set of all the points contained in its volume. A state in \\adomain\\ is composed by a set of hypercubes: its concretization is the union of all the volumes of its hypercubes.  In this way we track disjunctive information.\n\n\\vspace{-10pt}\n\\subsection{Lattice structure}\n\\vspace{-5pt}\nAn abstract state of \\adomain\\ tracks a \\emph{set} of hypercubes, and each hypercube is represented by a tuple of abstract values. The dimension of these tuples is equal to the number of program variables.\n%: this means that each variable is associated to a given item of the tuple (i.e., to a specific side of the hypercube). \n%Consider for instance a program in which $\\variables = \\{x_1, x_2\\}$. In this case, the hypercubes of \\adomain\\ are 2D-rectangles. In particular, the two sides of a single hypercube are two abstract values, one for $x_1$ and one for $x_2$.\n%A priori, our approach is modular w.r.t. the non-relational abstract domain we adopt to approximate the values of single variables inside an hypercube.\nWe abstract floating-point variables through intervals of real values. A set of hypercubes allows us to track disjunctive information, and this is useful when the values of a variable are clustered in different ranges.\n%: instead of having a very big interval to cover them all (and which would cover also a lot of invalid values), we use two (or more) smaller intervals. Since it would be particularly expensive to perform all the lattice operators pointwisely, we partition the possible values into intervals of fixed width. As an example, suppose that the initial vertical velocity of the balls of our case study ranges between $50.0$ and $60.0$ or between $-60.0$ and $-50.0$. A single interval would approximate these values with $[-60.0 .. 60.0]$, while with our approach we track two intervals, $[-60.0 .. -50.0]$ and $[50.0 .. 60.0]$ (with fixed width $10.0$), which distinguish between balls thrown downwards and balls thrown upwards. \nThe performance of this domain, though, becomes a crucial point, because the number of possible hypercubes in the space is potentially exponential with respect to the number of partitions along each spatial axis. \n\nFirst of all, the complexity is lightened by the use of a \\emph{fixed} width for each variable, by partitioning the possible intervals, and by the efficiency of set operators on tuples. Then, another performance booster is the use of a smart representation for intervals: in order to store the specific interval range we just use a single integer representing it. This is possible because each variable $x_i$ is associated to an interval width (specific only for that variable), which we call $w_i$ and which is a parameter of the analysis. Each width $w_i$ represents the width of all the possible abstract intervals associated to $x_i$. More precisely, given a width $w_i$ and an integer index $m$, the interval uniquely associated to the variable $x_i$ is $[m \\times w_i .. (m+1) \\times w_i]$. Notice that the smaller the width associated to a variable, the more granular and precise the analysis on that variable (and the heavier computationally the analysis). In Section \\ref{sec:semantics} we will show how to compute and adjust automatically the widths.\n\n\\textbf{Example:} Consider the case study of Section \\ref{sec:case_study} and in particular the two variables \\statement{px} and \\statement{py}. Suppose that the widths associated to such variables are $w_1 = 10.0, w_2 = 25.0$. The hypercubes in this case are 2D-rectangles that can be represented on the Cartesian plane.\nEach side of a hypercube is identified by an integer index, and a 2D hypercube is then uniquely identified by a pair of integers. For instance, the hypercube $h_1 = ( 0, 1 )$ represents $\\statement{px} \\in [0.0 .. 10.0]$ and $\\statement{py} \\in [25.0 .. 50.0]$, while the hypercube $h_2 = ( 0, 0 )$  associates $\\statement{px}$ to $[0.0 .. 10.0]$ and $\\statement{py}$ to $[0.0 .. 25.0]$. Figure \\ref{fig:hcExample} depicts the two hypercubes associated to the initialization of the case study (i.e., $h_1$ and $h_2$). Instead, Figure \\ref{fig:hcExample2} depicts the six hypercubes obtained after executing the first iteration of the \\statement{while} loop.\n%The ball is moving towards the right of the screen and is going downwards: this is coherent with the fact that the horizontal velocity is certainly positive (between $0.0$ and $60.0$), while the vertical velocity is certainly negative (between $-30.0$ and $-25.0$). \n\n\\vspace{-10pt}\n\\begin{figure}\n\\centering\n\\subfloat[The abstract state after the initialization of the variables \\statement{px,py}, when their widths are, respectively, $10.0$ and $25.0$]{\n\\includegraphics[scale=0.28]{Pics/example_hc_2d.png}\n\\label{fig:hcExample}\n}\\hspace{0.3cm}\n\\subfloat[The abstract state of \\statement{px,py} after the first iteration of the loop (widths are, respectively, $10.0$ and $25.0$)]{\n\\includegraphics[scale=0.28]{Pics/example_hc_2d_2.png}\n\\label{fig:hcExample2}\n}\n\\caption{Cartesian plans}\n\\end{figure}\n\\vspace{-10pt}\n\n\n%\\begin{figure}[ht]\n%\\begin{centering}\n%\\includegraphics[scale=0.35]{Pics/example_hc_2d.png}\n%\\caption{The abstract state of the case study after the initialization of the variables (focusing the attention only on \\statement{px,py}, when their widths are, respectively, $10.0$ and $25.0$)}\n%\\label{fig:hcExample}\n%\\end{centering}\n%\\end{figure}\n%\n%\\begin{figure}[ht]\n%\\begin{centering}\n%\\includegraphics[scale=0.35]{Pics/example_hc_2d_2.png}\n%\\caption{The abstract state of the case study after the first iteration of the loop (focusing the attention only on \\statement{px,py}, when their widths are, respectively, $10.0$ and $25.0$)}\n%\\label{fig:hcExample2}\n%\\end{centering}\n%\\end{figure}\n\n\nWe now formalize our abstract domain. Each abstract state is a set of hypercubes, where each hypercube is composed by $|\\variables|$ integer numbers. The abstract domain is then defined by $\\adomain = \\wp(\\integer^n)$ where $n = |\\variables|$. The definition of lattice operators relies on set operators.\n%: the partial order is defined through set inclusion, the lub and glb are set union and set intersection, respectively, while bottom and top are the empty set and the set containing all possible $n$-dimensional hypercubes, respectively. \nFormally, $\\langle\\wp(\\integer^n), \\subseteq, \\cup, \\cap, \\emptyset, \\integer^n\\rangle$.\n\n%\\begin{lemma}\n%$\\langle\\wp(\\integer^n), \\subseteq, \\cup, \\cap, \\emptyset, \\integer^n\\rangle$ is a complete lattice.\n%\\begin{proof}\n%The proof follows immediately by basic properties of set operators.\n%\\end{proof}\n%\\end{lemma}\n\n\\vspace{-10pt}\n\\subsection{Concretization function}\n\\vspace{-5pt}\nWe denote by $\\agenericdomain$ the non-relational abstract domain on which our analysis is parameterized, and by $n$ the number of variables of the program. Let $\\sigma \\in \\real^n$ be a tuple and $\\sigma_i \\in \\real$ be the $i$-th element of such tuple. Also, let $\\gamma_\\agenericdomain : \\funzione{\\agenericdomain}{\\wp(\\real)}$ be the concretization function of abstract values of the non-relational abstract domain $\\agenericdomain$, and $\\function{getAbsValue}_v : \\funzione{\\naturals}{\\agenericdomain}$ be the function that, given an integer index, returns the abstract value (in the domain $\\agenericdomain$) which corresponds to that index inside the tuple $v$.\nThen, the function $\\gamma_{\\aval} : \\funzione{\\wp(\\agenericdomain^n)}{\\wp(\\real^n)}$ concretizes a set of hypercubes to a set of vectors of $n$ floating point values. Formally, $\\gamma_{\\aval}(\\cel{V}) = \\{\\sigma : \\exists v \\in \\cel{V} : \\forall i \\in [1..n] : \\sigma_i \\in \\gamma_\\agenericdomain(\\function{getAbsValue}_v(i)) \\}$ where $\\cel{V} \\in \\wp(\\agenericdomain^n)$ is a set of hypercubes.\nFinally, based on $\\gamma_{\\aval}$, we can define the function $\\gamma_{\\adomain}$, which maps a subset $\\cel{V}$ of $\\wp(\\agenericdomain^n)$ into an environment. The function $\\gamma_{\\adomain} : \\funzione{\\wp(\\agenericdomain^n)}{\\wp(\\funzione{\\variables}{\\real})}$ concretizes the hypercubes domain. Formally, $\\gamma_{\\adomain}(\\cel{V}) = \\{[\\statement{x} \\mapsto \\cel{\\sigma}_{\\avariableindex{\\statement{x}}} : \\statement{x} \\in \\variables] : \\cel{\\sigma} \\in \\gamma_{\\aval}(\\cel{V})\\}$.  The function $\\gamma_{\\adomain}$ maps the vectors returned by $\\gamma_{\\aval}$ into concrete environments relying on the function $\\avariableindexname : \\funzione{\\variables}{\\naturals}$. The latter, given a variable, returns its index in the tuples which compose the elements of \\adomain.\n\n%Intuitively, we represent a concrete value as a tuple of real values (one for each variable of the program). The concretization of an abstract state $h \\in \\adomain$ is then a set of tuples. The concretization of $h$ is the union of all the concretizations of its hypercubes, i.e., all the points belonging to the volumes of its hypercubes. Each tuple of the concretization of $h$, then, is a point belonging to one hypercube of $h$. \n\n\\vspace{-10pt}\n\\subsection{Convergence of the analysis}\n\\vspace{-5pt}\n%The domain described so far does not ensure the convergence of the analysis. In fact, a \\statement{while} loop may add new hypercubes with increased indices at each iteration, and the dimension of the abstract state (i.e., the hypercubes set) would increase at each iteration without converging. Thus, we need a way to force the convergence of the analysis. Given our abstract state representation, \nThe number of hypercubes in an abstract state may increase indefinitely. In order to make the analysis convergent, we fix for each variable of the program a maximum integer index $n_i$ such that $n_i$ represents the interval $[n_i \\times w_i .. +\\infty]$. The same happens symmetrically for negative values. In this way, the set of indices of a given variable is finite, the resulting domain has finite height, and the analysis is convergent.\n\nThis approach may seem too rough since we establish the bounds of intervals before running the analysis. However, \n%this allows us to control the number of possible intervals in our hypercubes, and this is particularly important for the efficiency of the overall analysis. In addition, \nwhen analysing physics simulations we can use the initialization of variables and the property to verify in order to establish convenient bounds for the intervals. For instance, in the case study presented in Section \\ref{sec:case_study} we are interested in checking if a ball stays in the screen, that is, if \\statement{px} is greater than zero and less than a given value \\statement{w} representing the width of the screen. Since we are only interested in proving that, once a ball has exited the screen, it does not come back, we can abstract together all the values that are greater than \\statement{w}.\n\n%Observe that more sophisticated widening operators could be used as an alternative to the adopted solution described above, but this could affect the performance of the resulting analysis.\n\n%\\subsection{Other data types or non-relational abstractions}\n%\\todogiulia{Secondo me questa subsection si puo' cancellare}\n%As suggested before, for now we focus the application of our abstract domain to physics simulations, and for this reason we abstract floating point variables through intervals of fixed width. However, we may apply other kind of abstractions (e.g., the Sign domain) to our framework to consider other types of variables (integer, boolean, etc.). We will sketch other possible applications of our framework in Section \\ref{sec:otherapplications}.\n\n\\vspace{-10pt}\n\\subsection{Offsets}\n\\vspace{-5pt}\nA loss of precision may occur due to the fact that hypercubes proliferate too much, even using small widths. Consider, for example, the statement \\statement{x = x + 0.01} (which is repeated at each iteration of the \\statement{while} loop) with $1.0$ as the width associated to \\statement{x}. If $[0.0 .. 1.0]$ was the initial interval associated to \\statement{x}, the sequence of abstract states would be: $\\{ [0.0 .. 1.0] \\}$, $\\{ [0.0 .. 1.0], [1.0 .. 2.0] \\}$, $\\{ [0.0 .. 1.0], [1.0 .. 2.0], [2.0 .. 3.0] \\}$ and so on. At each iteration we would add one interval. \n%If the initial interval associated to \\statement{x} was $[0.0 .. 1.0]$, after the first iteration we would obtain two intervals ($[0.0 .. 1.0]$ and $[1.0 .. 2.0]$) because the resulting interval would be $[0.01 .. 1.01]$, which spans over two fixed-width intervals. For the same reason, after the second iteration we would obtain three intervals ($[0.0 .. 1.0],[1.0 .. 2.0]$ and $[2.0 .. 3.0]$) and so on: at each iteration we add one interval. \n\nIn order to overcome these situations, we further improve the definition of our domain: in each hypercube, each variable $v_i$ (associated to width $w_i$) is related to (other than an integer index $i$ representing the fixed-width interval $[i \\times w_i .. (i+1) \\times w_i]$) a specific offset $(o_m,o_M)$ \\emph{inside} such interval. In this way, we use a sub-interval (of arbitrary width) inside the fixed-interval width, thereby restricting the possible values that the variable can assume. Both $o_m$ and $o_M$ must be smaller than $w_i$, greater than or equal to $0$ and $o_m \\leq o_M$. Then, if $i$ and $(o_m,o_M)$ are associated to $v_i$, this means that the possible values of $v_i$ belong to the interval $[(i \\times w_i) + o_m .. (i \\times w_i) + o_M]$.\n\nAn element of our abstract domain is then stored as a map from hypercubes to tuples of offsets. In this way, we can keep the original definition of a hypercube as a tuple of integers, but we also map each hypercube to a tuple of offsets (one for each variable). Now an abstract state is defined by $M : \\funzione{\\integer^{|Vars|}}{{(\\real \\times \\real)}^{|Vars|}}$, i.e., a map where the domain is the set of hypercubes, and the codomain is the set of tuples of offsets.\n\nThe least upper bound between two abstract states ($M=M_1 \\sqcup M_2$) is then defined by $dom(M) = dom(M_1) \\cup dom(M_2)$, and\n\n$$\n\\forall h \\in dom(M) : M(h) = \\begin{cases}\nM_1(h) & \\mbox{if } h \\in dom(M_1) \\wedge h \\notin dom(M_2) \\\\\nM_2(h) & \\mbox{if } h \\in dom(M_2) \\wedge h \\notin dom(M_1) \\\\\nmerge(M_1(h),M_2(h)) & \\mbox{otherwise }\n\\end{cases}$$\nwhere $merge(o_1,o_2)$ creates a new tuple of offsets by merging the two tuples of offsets in input: for each pair of corresponding offsets (for example $(m_1,M_1)$ and $(m_2,M_2)$), the new offset is the widest combination possible (i.e., $(\\min(m_1,m_2)$ and $\\max(M_1,M_2))$). Note that this definition corresponds to the pointwise application of the least upper bound operator over intervals. The widening operator is extended in the same way: it applies the standard widening operators over intervals pointwisely to the elements of the vector representing the offsets.\n", "meta": {"hexsha": "fbff0390ef758136cc8921e2aaeb1a390e273b13", "size": 16233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12. Hypercubes Domain/Sections/3a_hypercubes_domain.tex", "max_stars_repo_name": "vs-team/Papers", "max_stars_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-04-06T08:46:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-19T07:16:23.000Z", "max_issues_repo_path": "12. Hypercubes Domain/Sections/3a_hypercubes_domain.tex", "max_issues_repo_name": "vs-team/Papers", "max_issues_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12. Hypercubes Domain/Sections/3a_hypercubes_domain.tex", "max_forks_repo_name": "vs-team/Papers", "max_forks_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 143.6548672566, "max_line_length": 1060, "alphanum_fraction": 0.7563605002, "num_tokens": 4255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6587683603194281}}
{"text": "\\section{Linear Spaces}\nIn this chapter our approach to estimating $f$ involves the use of\nfinite dimensional linear spaces. \n\nRemember what a linear space is? Remember definitions of dimension,\nlinear subspace, orthogonal projection, etc...\n\nWhy use linear spaces? \n\\begin{itemize}\n\\item Makes estimation and statistical computations easy.\n\\item Has nice geometrical interpretation.\n\\item It actually can specify a broad range of models given we have \n  discrete data.\n\\end{itemize}\n\nUsing linear spaces we can define many families of function $f$; \nstraight lines, polynomials, splines, functions with two continuous\nderivatives, and many other spaces (these are examples for the case\nwhere $\\bx$ is a scalar). The point is: we have many options.\n\nNotice that in most practical situation we will have  observations\n$(\\bX_i,Y_i), i=1,\\dots,n$. In some situations we are only interested\nin estimating $f(\\bX_i),i=1,\\dots,n$. In fact, in many situations it\nis all that matters from a statistical point of view. We will write\n$\\f$ when referring to the this vector and $\\hat{\\f}$ when referring to\nan estimate. Think of how its different to know $f$ and know $\\f$.\n\nLet's say we are interested in estimating $\\f$. A common practice in\nstatistics is to assume that $\\f$ lies in some {\\it linear space}, or\nis well approximated by a $\\g$ that lies in some {\\it linear space}. \n\nFor example for simple linear regression we assume that $\\f$ lies in the\nlinear space \nof lines:\n\\[\n\\alpha + \\beta \\bx, (\\alpha,\\beta)' \\in {\\mathbb R}^2.\n\\]\n\nFor linear regression in general we assume that $\\f$ lies in the\nlinear space of linear combinations of the covariates or rows of the\ndesign matrix. How do we write it out?\n\nNote: Through out this chapter $f$ is used to denote the true\nregression function and $g$ is used to denote an arbitrary function in\na particular space of functions. It isn't necessarily true that $f$ lies\nin this space of function. Similarly we use $\\f$ to denote the true function\nevaluated at the design points or observed covariates and $\\g$ to\ndenote an arbitrary function evaluated at the design points or\nobserved covariates. \n\n\nNow we will see how and why it's useful to use linear models in a more\ngeneral setting. \n\nA linear model  of order $p$ for the\nregression function (\\ref{fdef}) consists of a $p$-dimensional linear \nspace $\\cal G$, having as a basis the function \n\\[\nB_j(\\bx), j=1,\\dots,p\n\\]\ndefined for $\\bx \\in I$. Each member  $g \\in \\cal G$ can be written\nuniquely as a linear combination \n\\[\ng(\\bx) = g(\\bx; \\bg{\\theta}) = \\theta_1 B_1(\\bx) + \\dots + \\theta_p\nB_p(\\bx)\n\\]\nfor some value of the coefficient vector $\\bg{\\theta} =\n(\\theta_1,\\dots,\\theta_p)' \\in {\\mathbb R}^p$. \n\nNotice that $\\bg{\\theta}$ specifies the point $g \\in \\cal G$. \n\nHow would you write this out for linear regression?\n\n\nGiven observations $(\\bX_i,Y_i), i=1,\\dots,n$ the least squares\nestimate (LSE) of $\\f$ or \nequivalently $f(\\bx)$ is defined by $\\hat{f}(\\bx) =\ng(\\bx;\\hat{\\bg{\\theta}})$, \nwhere \n\\[\n\\hat{\\bg{\\theta}} = \\arg\\min_{\\bg{\\theta} \\in {\\mathbb R}^p} \\sum_{i=1}^n \\{Y_i -\ng(\\bX_i,\\bg{\\theta})\\}^2.\n\\]\nDefine the vector $\\g = \\{g(x_1),\\dots,g(x_n)\\}'$. Then the distribution\nof the observations of $Y | X=x$ are in the family \n\\begin{equation}\n\\label{nonparametric}\n\\{ N(\\g,\\sigma^2 {\\mathbf I}_n); \\g = [g(x_1),\\dots,g(x_n)]', \\, g \\in {\\cal G}\\}\n\\end{equation}\nand if we assume the errors $\\varepsilon$ are IID normal and that $f \\in \\cal\n  G$ we have that $\\hat{\\f} = \n[g(x_1;\\hat{\\bg{\\theta}}),\\dots,g(x_n;\\hat{\\bg{\\theta}})]$ is the  \nmaximum likelihood estimate. The estimand $\\f$ is an $n \\times 1$\n  vector. But how many parameters are we really estimating?\n\nEquivalently we can think of the\ndistribution is in the family \n\\begin{equation}\n\\label{parametric}\n\\{N(\\bB \\bg{\\theta},\\sigma^2); \\bg{\\theta} \\in {\\mathbb R}^p\\}\n\\end{equation}\nand the maximum likelihood estimate for $\\bg{\\theta}$ is\n$\\hat{\\bg{\\theta}}$. Here $\\bB$ is a matrix of basis elements defined soon...\n\nHere we start seeing for the first time where the name {\\it non-parametric}\ncomes from. How are the approaches (\\ref{nonparametric}) and\n(\\ref{parametric}) different?\n\nNotice that obtaining $\\hat{\\bg{\\theta}}$ is easy because of the\nlinear model set-up. The ordinary least square estimate is \n\\[\n(\\bB'\\bB)\\hat{\\bg{\\theta}} = \\bB'\\bY\n\\]\nwhere $\\bB$ is is the $n \\times p$ design matrix with elements\n$[\\bB]_{ij}=B_j(\\bX_i)$. When this solution is unique we refer to\n$g(x;\\hat{\\bg{\\theta}})$ as the OLS projection of $\\bY$ into $\\cal G$\n(as learned in the first term).\n\n\n%%%Plagerized\n\\subsection{Parametric versus non-parametric}\nIn some cases, we have reason to believe that the function $f$ is\nactually a member of some linear space $\\cal G$. Traditionally,\ninference for regression models depends on $f$ being representable\nas some combination of known predictors. Under this assumption, $f$\ncan be written as a combination of basis elements for some value of\nthe coefficient vector $\\bg{\\theta}$. This provides a {\\it\nparametric} specification for $f$. No matter how many observations we\ncollect, there is no need to look outside the fixed,\nfinite-dimensional, linear space $\\cal G$ when estimating $f$. \n\n\nIn practical situations, however, we would rarely believe such\nrelationship to be exactly true. Model spaces $\\cal G$ are understood\nto provide (at best) approximations to $f$; and as we collect more and\nmore samples, we have the freedom to audition richer and richer\nclasses of models. In such cases, all we might be willing to say about\n$f$ is that it is {\\it smooth} in some sense, a common assumption\nbeing that $f$ have two bounded derivatives. Far from the assumption\nthat $f$ belong to a fixed, finite-dimensional linear space, we\ninstead posit a {\\it nonparametric} specification for $f$. In this\ncontext, model spaces are employed mainly in our approach to\ninference; first in the questions we pose about an estimate, and then\nin the tools we apply to address them. For example, we are less\ninterested in the actual values of the coefficient $\\bg{\\theta}$,\ne.g. whether or not an element of $\\bg{\\theta}$ is significantly\ndifferent from zero to the 0.05 level. Instead we concern ourselves\nwith functional properties of $g(\\bx; \\hat{\\bg{\\theta}})$, the\nestimated curve or surface, e.g. whether or not a peak is real.\n\nTo ascertain the local behavior of OLS projections onto approximation\nspaces $\\cal G$, define the pointwise, mean squared error (MSE) of\n$\\hat{g}(\\bx) = g(\\bx;\\hat{\\bg{\\theta}})$ as \n\\[\n\\E \\{ f(\\bx) - \\hat{g}(\\bx) \\}^2 = \\bias^2\\{\\hat{g}(\\bx)\\} +\n\\var\\{\\hat{g}(\\bx)\\}\n\\]\nwhere \n\\begin{equation}\n\\label{bias}\n\\bias\\{\\hat{g}(\\bx)\\} = f(x) - \\E\\{\\hat{g}(\\bx)\\}\n\\end{equation}\nand\n\\[\n\\var\\{\\hat{g}(\\bx)\\} = \\E\\{\\hat{g}(\\bx) - \\E[\\hat{g}(\\bx)]\\}^2\n\\]\nWhen the input values $\\{\\bX_i\\}$ are deterministic the expectations\nabove are with respect to the noisy observation ${Y_i}$. In practice,\nMSE is defined in this way even in the random design case, so we look\nat expectations conditioned on $\\bX$. \n\nWhen we do this, standard results in regression theory can be applied\nto derive an expression for the variance term\n\\[\n\\var\\{\\hat{g}(\\bx)\\} = \\sigma^2 \\bB(\\bx)'(\\bB'\\bB)^{-1}\\bB(\\bx)\n\\]\nwhere $\\bB(\\bx) = (B_1(\\bx),\\dots,B_p(\\bx))'$, and the error variance is\nassumed constant.\n\nUnder the parametric specification that  \n$f \\in \\cal G$, what is the bias? \n\n This leads to\nclassical t- and F-hypothesis tests and associated parametric\nconfidence intervals for $\\bg{\\theta}$. Suppose on the other hand,\nthat $f$ is not a member of $\\cal G$, but rather can be reasonably\napproximated by an element in $\\cal G$. The bias (\\ref{bias}) now reflects\nthe ability of functions in $\\cal G$ to capture the essential features\nof $f$.\n\n\n% where the dist$(f,{\\cal G})$ is defined as\n% \\[\n%  \\mbox{dist}(f,{\\cal G}) = \\min_{g \\in \\cal G} ||f-g||,\n% \\]\n% for some norm.\n% An example of a norm that is used frequently is the $L_{\\infty}$ \n% \\[\n% || f - g||_{\\infty} = \\sup_{\\bx \\in I} | f(x) - g(x) |.\n% \\]\n% In general we characterize the contribution of bias to the MSE through\n% the {\\it approximation rate} obtained by $\\cal G$ given our\n% assumptions about the regularity or smoothness of $f$. Broadly, the\n% better the approximation rate (the more flexible the space $\\cal G$,\n% the lower the bias. As we will see, however, we pay for improved\n% approximation power with excess degrees of freedom (e.g. by moving\n% from a linear to quadratic or cubic polynomial) and hence incur extra\n% variability.\n%\\newpage\n", "meta": {"hexsha": "6a6d82e44d8012ef26f24686eb7ef1cb073dade1", "size": 8526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-04-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-04-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-04-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": 40.6, "max_line_length": 81, "alphanum_fraction": 0.7119399484, "num_tokens": 2453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6587683562511369}}
{"text": "\\vspace{-0.2em}\n\\section{The \\tuner tuner}\n\\label{sec:sync_tuner}\n\\vspace{-0.2em}\n%In this section we describe \\tuner, our tuner for momentum SGD.\n%We introduce a noisy quadratic model and work on a local quadratic approximation of $f(x)$ to apply the tuning rule of \\eqref{eqn:noiseless_tuning_rule} to SGD on an arbitrary objective.\n%\\tuner is our implementation of that rule.\n\nHere we describe our tuner for momentum SGD that uses the same learning rate for all variables.\nWe first introduce a noisy quadratic model $f(x)$ as the local approximation of an arbitrary one-dimensional objective. On this approximation, we extend the tuning rule of \\eqref{eqn:noiseless_tuning_rule} to SGD. In section~\\ref{sec:tuner}, \\emph{we generalize the discussion to multidimensional objectives; it yields the \\tuner tuning rule}.\n\n\n\\paragraph{Noisy quadratic model}\n\\label{sec:noisy_quadratics}\n\n\\newcommand{\\oac}{origin-adjusted curvature }\n\\newcommand{\\bx}{\\bar{x}}\n\n\nWe consider a scalar quadratic \n\\begin{equation}\n\tf(x) = \\frac{h}{2} x^2 + C \n\t= \\sum_i \\frac{h}{2n}(x-c_i)^2\n\t\\triangleq \\frac{1}{n} \\sum_i f_i(x)\n%\t\\quad \\sum_i c_i = 0.\n\t\\label{eqn:noise_quad_1d}\n\\end{equation}\nwith $\\sum_i c_i = 0$. $f(x)$ is a quadratic approximation of the original objectives with $h$ and $C$ derived from measurement on the original objective. The function $f(x)$ is defined as the average of $n$ {\\em component functions}, $f_i$.\nThis is a common model for SGD, where we use only a single data point (or a mini-batch) drawn uniformly at random, $S_t \\sim \\mathrm{Uni}([n])$ to compute a noisy gradient, $\\nabla f_{S_t}(x)$, for step $t$.\nHere, $C=\\frac{1}{2n}\\sum_i h c_i^2$ denotes the {\\em gradient variance}.\nAs optimization on quadratics decomposes into scalar problems along the principal eigenvectors of the Hessian, the scalar model in~\\eqref{eqn:noise_quad_1d} is sufficient to study local quadratic approximations of multidimensional objectives.\nNext we get an {\\em exact} expression for the mean square error after running momentum SGD on the scalar quadratic in~\\eqref{eqn:noise_quad_1d} for $t$ steps.\n\n\n\n\\begin{lemma}\n\\label{lem:main_lemma}\nLet $f(x)$ be defined as in \\eqref{eqn:noise_quad_1d},\n$x_1=x_0$ and $x_t$ follow the momentum update \\eqref{eqn:momentum_gd} with stochastic gradients $\\nabla f_{S_t}(x_{t-1})$ for $t \\geq 2$.\nLet $\\mat{e}_1=[1, 0]^T$, the expectation of squared distance to the optimum $x^*$ is\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\t\\E (x_{t+1} - x^{*})^2 & = (\\mat{e}^{\\top}_1 \\mat{A}^t [x_1 - x^{*}, x_0-x^{*}]^{\\top})^2 \\\\\n\t\t& + \\alpha^2 C \\mat{e}^{\\top}_1 (\\mat{I} - \\mat{B}^t)(\\mat{I} - \\mat{B})^{-1}\\mat{e}_1\t,\n\t\t\\label{equ:squared_dist_exact}\t\n\t\\end{aligned}\n\t\\end{equation}\nwhere the first and second term correspond to squared bias \nand variance, and their corresponding momentum dynamics are captured by operators\n\t\\begin{equation}\n\t\\begin{gathered}\n\t\t\\mat{A} = \\begin{bmatrix}\n\t\t1-\\alpha h + \\mu & - \\mu\\\\\n\t\t1 & 0 \\\\\n\t\t\\end{bmatrix}, \\\\\n%\t\t\\quad\n\t\t\\mat{B} = \n\t\t\\begin{bmatrix}\n\t\t(1-\\alpha h + \\mu)^2 &  \\mu^2 & -2\\mu(1-\\alpha h + \\mu)\\\\\n\t\t1 & 0 & 0 \\\\\n\t\t1-\\alpha h + \\mu & 0 & - \\mu\n\t\t\\end{bmatrix}.\n\t\t\\label{equ:mat_def}\n\t\\end{gathered}\n\t\\end{equation}\n\\end{lemma}\n\n\\yell{\nEven though it is possible to numerically work on~\\eqref{equ:squared_dist_exact} directly,\nwe use a scalar, asymptotic surrogate in~\\eqref{eqn:asymptotic_surrogate} based on the spectral radii of operators to simplify analysis and expose insights.\nThis decision is supported by our findings in Section~\\ref{sec:momentum_operator}: the spectral radii can capture empirical convergence rate.}\n\\begin{equation}\n\\begin{aligned}\n%\t\\E ( x_{t+1} - x^{*} )^2\n%\t\\approx  \\rho(\\mat{A})^{2t} ( x_0 - x_{*} )^2 \n%\t\t+ (1-\\rho(\\mat{B})^{t}) \\frac{\\alpha^2 C}{1-\\rho(\\mat{B})}\n\t&\\E ( x_{t+1} - x^{*} )^2 \\\\\n\t\\approx & \\rho(\\mat{A})^{2t} ( x_0 - x_{*} )^2 \n\t\t+ (1-\\rho(\\mat{B})^{t}) \\frac{\\alpha^2 C}{1-\\rho(\\mat{B})}\n\t\\label{eqn:asymptotic_surrogate}\n\\end{aligned}\n\\end{equation}\n\nOne of our design decisions for \\tuner \nis to always work in the robust region of Lemma~\\ref{lem:robustness}.\nWe know that this implies a spectral radius $\\sqrt{\\mu}$ of the momentum operator, $\\mat{A}$, for the bias. \nLemma~\\ref{lem:spectral_var_control} shows that under the exact same condition, the variance operator $\\mat{B}$ has spectral radius $\\mu$.\n \n\n\\begin{lemma}\n\\label{lem:spectral_var_control}\nThe spectral radius of the variance operator, $\\mat{B}$ is $\\mu$, if ${(1-\\sqrt{\\mu})^2} \\leq  \\alpha h \\leq {(1+\\sqrt{\\mu})^2}$.\n\\end{lemma}\n\nAs a result, the surrogate objective of \\eqref{eqn:asymptotic_surrogate}, takes the following form in the robust region.  \n\\begin{equation}\n\t\\E ( x_{t+1} - x^{*} )^2 \n\t\\approx \\mu^t ( x_0 - x^{*} )^2\n\t\t+ (1-\\mu^t) \\frac{\\alpha^2 C}{1-\\mu}\n\t\\label{eqn:noisy_square_dist}\n\\end{equation}\nWe extend this surrogate to multidimensional cases to extract a noisy tuning rule for \\tuner.\n\n%\\vspace{-0.25em}\n\\subsection{Tuning rule}\n\\label{sec:tuner}\n\\vspace{-0.25em}\n\nIn this section, we present \\textsc{SingleStep}, the tuning rule of YellowFin (Algorithm~\\ref{alg:basic-algo}). Based on the surrogate in~\\eqref{eqn:noisy_square_dist}, \\textsc{SingleStep} is a multidimensional SGD version of the noiseless tuning rule in~\\eqref{eqn:noiseless_tuning_rule}. We first generalize~\\eqref{eqn:noiseless_tuning_rule} and~\\eqref{eqn:noisy_square_dist} to multidimensional cases, and then discuss \\textsc{SingleStep}.% in details.\n\nAs discussed in Section~\\ref{sec:robust_properties}, GCN $\\nu$ captures the dynamic range of generalized curvatures in a one-dimensional objective with varying curvature. The consequent robust region described by~\\eqref{eqn:noiseless_tuning_rule} implies homogeneous spectral radii. \n%\\emph{In multidimensional cases, we use a single learning rate and momentum for the entire model.} \nOn a multidimensional non-convex objective, each one-dimensional slice passing a minimum $x^*$ can have \\emph{varying curvature}. As we use \\emph{a single $\\mu$ and $\\alpha$ for the entire model}, if $\\nu$ simultaneously captures the dynamic range of generalized curvature over all these slices, $\\mu$ and $\\alpha$ in~\\eqref{eqn:noiseless_tuning_rule} are in the robust region for all these slices. This implies homogeneous spectral radii $\\sqrt{\\mu}$ according to Lemma~\\ref{lem:robustness}, empirically facilitating convergence at a common rate along all the directions. \n\nGiven homogeneous spectral radii $\\sqrt{\\mu}$ along all directions, the surrogate in~\\eqref{eqn:noisy_square_dist} generalizes on the local quadratic approximation of multiple dimensional objectives. On this approximation with minimum $x^*$, the expectation of squared distance to $x^*$, $\\E \\| x_0 - x^*\\|^2$, decomposes into independent scalar components along the eigenvectors of the Hessian. We define gradient variance $C$ as the sum of gradient variance along these eigenvectors. The one-dimensional surrogates in~\\eqref{eqn:noisy_square_dist} for the independent components sum to $\\mu^t\\| x_0 - x^* \\|^2 + (1-\\mu^t)\\alpha^2 C / (1 - \\mu)$, the \\emph{multidimensional surrogate} corresponding to the one in~\\eqref{eqn:noisy_square_dist}. \n%Given homogeneous spectral radii $\\sqrt{\\mu}$ along all directions, the surrogate in~\\eqref{eqn:noisy_square_dist} generalizes via multidimensional local quadratic approximations. Assuming the quadratic approximation aligns with standard axes, the expectation of squared distance to the optimum of the approximation, $\\E\\|x_t - x^*\\|^2$, decomposes along the standard axes. As the initial squared distance $\\| x_0 - x^*\\|^2$ and gradient variance $C$ also decompose along the axes, the one dimensional surrogates along axes sums to $\\mu^t\\| x_0 - x^* \\|^2 + (1-\\mu^t)\\alpha^2 C / (1 - \\mu)$, the surrogates corresponding to the one in~\\eqref{eqn:noisy_square_dist}. \n%\tNote for quadratic approximation not aligned with the axes, this \\emph{multidimensional surrogates} is attained by decomposing along eigenvectors of the quadratic approximation's Hessian, instead of standard axes. \n\n%%\\begin{minipage}{0.5\\linewidth}\n%%\\vspace{-0.25em}\n%\\begin{equation}\n%\\begin{aligned}\n%\t\\textsc{(SingleStep)} \\notag \\\\\n%\t \\mu_t, \\alpha_t & = && \\arg \\min_{\\mu} \\mu D^2\n%\t\t+ \\alpha^2 C \\\\\n%\ts.t. & &&\\mu \\geq \\left(\\frac{\\sqrt{h_{\\max}/h_{\\min} }-1}{\\sqrt{h_{\\max}/h_{\\min}}+1}\\right)^2 \\\\\n%\t& &&\\alpha = \\frac{(1-\\sqrt{\\mu})^2}{h_{\\min}}\n%\\end{aligned}\n%\\label{equ:noisy_min}\n%\\end{equation}\n%%\\end{minipage}\n%\\begin{minipage}{0.025\\linewidth}\n%\\ \n%\\end{minipage}\n%\\begin{minipage}{0.45\\linewidth}\n%\\vspace{-1.5em}\n%\\begin{algorithm}[H]\n%\t\\footnotesize\n%\t\\caption{\\jianedits{\\tuner}}\n%\t\\begin{algorithmic}\n%\t\\State \\textbf{state: } $\\alpha \\gets 1.0$, $\\mu \\gets 0.0$%, $w\\gets20$\n%\t\\Function{\\tuner}{$\\text{gradient } g_t$, $\\beta$}\n%\t\\State $h_{\\max}, h_{\\min} \\gets \\Call{CurvatureRange}{g_t, \\beta}$\n%\t\\State $C \\gets \\Call{Variance}{g_t, \\beta}$ \n%\t\\State $D \\gets \\Call{Distance}{g_t, \\beta}$ \n%\n%\t\\State $\\mu_t, \\alpha_t \\gets \\Call{SingleStep}{C, D, h_{\\max}, h_{\\min}}$\n%\t\\State $\\mu \\gets \\beta \\cdot \\mu + (1 - \\beta) \\cdot \\mu_t$\n%\t\\State $\\alpha \\gets \\beta \\cdot \\alpha + (1 - \\beta) \\cdot \\alpha_t$ %\\Comment{Smoothing learning rate and momentum for stable control}\n%\t\\Return $\\mu, \\alpha$\n%\t\\EndFunction\n%\t\\end{algorithmic}\n%\t\\label{alg:basic-algo}\n%\\end{algorithm}\n%\\end{minipage}\n%%%%%%%%%%%%%%%%%%%%%%%%% new algorithm %%%%%%%%%%%%%%%%%%%%%%%%\n%%\\begin{minipage}{0.475\\linewidth}\n%%\\vspace{-0.25em}\n%\\begin{algorithm}[H]\n%\t\\footnotesize\n%\t\\caption{\\jianedits{\\tuner}}\n%\t\\begin{algorithmic}\n%%\t\\State \\textbf{state: } $\\alpha \\gets 1.0$, $\\mu \\gets 0.0$%, $w\\gets20$\n%\t\\Function{\\tuner}{$\\text{gradient } g_t$, $\\beta$}\n%\t\\State $h_{\\max}, h_{\\min} \\gets \\Call{CurvatureRange}{g_t, \\beta}$\n%\t\\State $C \\gets \\Call{Variance}{g_t, \\beta}$ \n%\t\\State $D \\gets \\Call{Distance}{g_t, \\beta}$ \n%\n%\t\\State $\\mu_t, \\alpha_t \\gets \\Call{SingleStep}{C, D, h_{\\max}, h_{\\min}}$\n%%\t\\State $\\mu_t, \\alpha_t \\gets \\Call{SingleStep}{C, D, h_{\\max}, h_{\\min}}$\n%%\t\\State $\\mu \\gets \\beta \\cdot \\mu + (1 - \\beta) \\cdot \\mu_t$\n%%\t\\State $\\alpha \\gets \\beta \\cdot \\alpha + (1 - \\beta) \\cdot \\alpha_t$ %\\Comment{Smoothing learning rate and momentum for stable control}\n%\t\\Return $\\mu_t, \\alpha_t$\n%\t\\EndFunction\n%\t\\end{algorithmic}\n%\t\\label{alg:basic-algo}\n%\\end{algorithm}\n%%\\end{minipage}\n%\\begin{minipage}{0.475\\linewidth}\n%\\vspace{-0.25em}\n\\vspace{-0.25em}\n\\begin{algorithm}[h]\n%\t\\footnotesize\n\t\\caption{\\jianedits{\\tuner}}\n\t\\begin{algorithmic}\n%\t\\State \\textbf{state: } $\\alpha \\gets 1.0$, $\\mu \\gets 0.0$%, $w\\gets20$\n\t\\Function{\\tuner}{$\\text{gradient } g_t$, $\\beta$}\n\t\\State $h_{\\max}, h_{\\min} \\gets \\Call{CurvatureRange}{g_t, \\beta}$\n\t\\State $C \\gets \\Call{Variance}{g_t, \\beta}$ \n\t\\State $D \\gets \\Call{Distance}{g_t, \\beta}$ \n\n\t\\State $\\mu_t, \\alpha_t \\gets \\Call{SingleStep}{C, D, h_{\\max}, h_{\\min}}$\n%\t\\State $\\mu_t, \\alpha_t \\gets \\Call{SingleStep}{C, D, h_{\\max}, h_{\\min}}$\n%\t\\State $\\mu \\gets \\beta \\cdot \\mu + (1 - \\beta) \\cdot \\mu_t$\n%\t\\State $\\alpha \\gets \\beta \\cdot \\alpha + (1 - \\beta) \\cdot \\alpha_t$ %\\Comment{Smoothing learning rate and momentum for stable control}\n\t\\Return $\\mu_t, \\alpha_t$\n\t\\EndFunction\n\t\\end{algorithmic}\n\t\\label{alg:basic-algo}\n\\end{algorithm}\n\\vspace{-0.25em}\n%\\end{minipage}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%% new algorithm %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{table*}[t]\n\\begin{minipage}{0.37\\textwidth}\n\\vspace{-1em}\n\\algrenewcommand\\alglinenumber[1]{\\scriptsize #1:}\n\t\\begin{algorithm}[H]\n\t\\small\n\t\\setstretch{1.01}\n\t\\caption{\\small Curvature range}\n\t\\begin{algorithmic}\n\t\t\\State \\textbf{state: } $h_{\\max}$, $h_{\\min}$, $h_i, \\forall i \\in\\{1,2,3,...\\}$\n\t\t\\Function{CurvatureRange}{gradient $g_t$, $\\beta$}\n\t\t\t\\State $h_t \\gets \\| g_t \\|^2$\n\t\t\t\\State $h_{\\max,t}\\gets\\!\\!\\!\\max\\limits_{t - w \\leq i \\leq t}\\!h_i$, $h_{\\min,t}\\gets\\!\\!\\!\\min\\limits_{t - w \\leq i \\leq t}\\!h_i$\n\t\t\t\\State $h_{\\max} \\gets \\beta \\cdot h_{\\max} + (1 - \\beta) \\cdot h_{\\max,t}$ %\\hfill Smoothed largest curvature.\n\t\t\t\\State $h_{\\min} \\gets \\beta \\cdot h_{\\min} + (1 - \\beta) \\cdot h_{\\min,t}$ %\\hfill Smoothed smallest curvature.\n%\t\t\t\\State $h_{\\max} \\gets \\beta \\  h_{\\max} + (1 - \\beta) \\  h_{\\max,t}$ %\\hfill Smoothed largest curvature.\n%\t\t\t\\State $h_{\\min} \\gets \\beta \\ h_{\\min} + (1 - \\beta) \\ h_{\\min,t}$ %\\hfill Smoothed smallest curvature.\n\t\t\t\\Return $h_{\\max}$, $h_{\\min}$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\\label{alg:curv_func}\n\t\\end{algorithm}\n\\end{minipage}\n\\begin{minipage}{0.315\\textwidth}\n\\vspace{-1em}\n\\algrenewcommand\\alglinenumber[1]{\\scriptsize #1:}\n\t\\begin{algorithm}[H]\n\t\\small\n\t\\setstretch{1.5}\n\t\\caption{\\small Gradient variance}\n\t\\begin{algorithmic}\n\t\\State \\textbf{state: } $\\overline{g^2}\\gets0$, $\\overline{g}\\gets0$\n\t\\Function{Variance}{gradient $g_t$, $\\beta$}\n\t\t\\State $\\overline{g^2}\\gets\\beta \\cdot \\overline{g^2} + (1 - \\beta) \\cdot g_t \\odot g_t$\n\t\t\\State $\\overline{g}\\gets\\beta \\cdot \\overline{g} + (1 - \\beta) \\cdot g_t$\n%\t\t\\Return $\\| \\overline{g^2} - \\overline{g}^2 \\|_1$ %\\hfill Sum of elements in the vect\n\t\t\\Return $\\bm{1}^T\\!\\!\\cdot\\left(\\overline{g^2} - \\overline{g}^2\\right)$ %\\hfill Sum of elements in the vect\n\t\\EndFunction\n\t\\end{algorithmic}\n\t\\label{alg:var_func}\n\t\\end{algorithm}\n\\end{minipage}\n\\begin{minipage}{0.3\\textwidth}\n\\vspace{-1em}\n\\algrenewcommand\\alglinenumber[1]{\\scriptsize #1:}\n\t\\begin{algorithm}[H]\n\t\\small\n\t\\setstretch{1.25}\n\t\\caption{\\small Distance to opt.}\n\t\\begin{algorithmic}\n\t\\State \\textbf{state: } $\\overline{\\|g\\|}\\gets0$, $\\overline{h}\\gets0$\n\t\t\\Function{Distance}{gradient $g_t$, $\\beta$}\n\t\t\\State $\\overline{\\|g\\|}\\gets \\beta \\cdot \\overline{\\|g\\|} + (1 - \\beta) \\cdot \\|g_t\\|$\n\t\t\\State $\\overline{h} \\gets \\beta \\cdot \\overline{h} + (1 - \\beta) \\cdot \\| g_t \\|^2$\n\t\t\\State $D \\gets \\beta \\cdot D + (1 - \\beta) \\cdot \\overline{\\|g\\|} /\\overline{h}$\n\t\t\\Return $D$\n\t\\EndFunction\n\t\\end{algorithmic}\n\t\\label{alg:dist_func}\n\t\\end{algorithm}\n\\end{minipage}\n\\end{table*}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%% end of new algorithm\n\n\\begin{wrapfigure}[9]{R}{0.55\\linewidth}\n\\vspace{-2.5em}\n\\hspace{-1em}\n\\begin{minipage}{\\linewidth}\n\t\\begin{equation}\n\t\\begin{aligned}\n\t&\\textsc{(SingleStep)} \\\\\n\t \\mu_t, \\alpha_t = & \\arg \\min_{\\mu} \\mu D^2\n\t\t+ \\alpha^2 C \\\\\n\ts.t.\\  \\mu \\geq & \\left(\\frac{\\sqrt{h_{\\max}/h_{\\min} }-1}{\\sqrt{h_{\\max}/h_{\\min}}+1}\\right)^2 \\\\\n\t\\alpha =& \\frac{(1-\\sqrt{\\mu})^2}{h_{\\min}}\n\t\\end{aligned}\n\t\\label{equ:noisy_min}\n\t\\end{equation}\n\\end{minipage}\n\\end{wrapfigure}\nLet $D$ be an estimate of the current model's distance to a local quadratic approximation's minimum, and $C$ denote an estimate for gradient variance.\n\\textsc{SingleStep} minimizes the \\emph{multidimensional surrogate} after a single step (i.e. $t=1$) while ensuring $\\mu$ and $\\alpha$ in the robust region for all directions. \\emph{A single instance of \\textsc{SingleStep} solves a single momentum and learning rate for the entire model at each iteration.}\nSpecifically, the extremal curvatures $h_{min}$ and $h_{max}$ denote estimates for the largest and smallest generalized curvature respectively. They are meant to capture both generalized curvature variation along all different directions (like the classic condition number)\nand also variation that occurs as the {\\em landscape evolves}. The constraints keep the global learning rate and momentum in the robust region (defined in Lemma~\\ref{lem:robustness}) \nfor slices along all directions.\n%along eigenvectors of the quadratic approximation's Hessian. \n%\\textsc{SingleStep} can be solved in closed form; we refer to Appendix~\\ref{sec:opt} for relevant details on the closed form solution. \n\nThe problem in~\\eqref{equ:noisy_min} does not need iterative solver but has an analytical solution. Substituting only the second constraint, the objective becomes $p(x)=x^2D^2 + (1-x)^4/h_{\\min}^2C$ with $x=\\sqrt{\\mu} \\in [0, 1)$. By setting the gradient of $p(x)$ to 0, we can get a cubic equation whose root $x=\\sqrt{\\mu_p}$ can be computed in closed form using Vieta's substitution. As $p(x)$ is uni-modal in $[0, 1)$, the optimizer for \\eqref{equ:noisy_min} is exactly the maximum of $\\mu_p$ and $(\\sqrt{h_{\\max}/h_{\\min} }-1 )^2 / (\\sqrt{h_{\\max}/h_{\\min}}+1)^2$, the right hand-side of the first constraint in~\\eqref{equ:noisy_min}.\n\n\\tuner uses functions \\textproc{CurvatureRange}, \\textproc{Variance} and \\textproc{Distance} to measure quantities $h_{\\max}$, $h_{\\min}$, $C$ and $D$ respectively. These measurement functions can be designed in different ways.\nWe present the implementations we used for our experiments,\nbased completely on gradients,  in Section~\\ref{sec:oracles}.\n\n\n\n%Let $D$ denote an estimate of the current model's distance to a local quadratic approximation's minimum, and $C$ denote an estimate for gradient variance. The extremal curvatures $h_{min}$ and $h_{max}$ denote estimates for the largest and smallest generalized curvature respectively. They are meant to capture both local curvature variation along all different directions (like the classic condition number)\n%and also variation that occurs as the {\\em landscape evolves}. Thus the constraints keep the global learning rate and momentum in the robust region (defined in Lemma~\\ref{lem:robustness}) along all eigendirections of the quadratic approximation. According to Lemma~\\ref{lem:robustness} and~\\ref{lem:spectral_var_control}, these constraints support the decomposition of \\textsc{SingleStep} objective, as the sum of ~\\eqref{eqn:noisy_square_dist} (with $t=1$) along the eigendirections of the quadratic approximation.\n%\\textsc{SingleStep} can be solved in closed form; we refer to Appendix~\\ref{sec:opt} for discussion on the closed form solution. \n%\\tuner uses functions \\textproc{CurvatureRange}, \\textproc{Variance} and \\textproc{Distance} to measure quantities $h_{\\max}$, $h_{\\min}$, $C$ and $D$ respectively. These measurement functions can be designed in different ways.\n%We present the implementations we used for our experiments,\n%based completely on gradients,  in Section~\\ref{sec:oracles}.\n\n%\\textsc{SingleStep} minimizes the surrogate for the expected squared distance from the optimum of a local quadratic approximation  \\eqref{eqn:noisy_square_dist} after a single step ($t=1$),\n%while keeping all directions in the robust region \\eqref{eqn:robust_region}.\n%This is the SGD version of the noiseless tuning rule in \\eqref{eqn:noiseless_tuning_rule}.\n%It can be solved in closed form; we refer to Appendix~\\ref{sec:opt} for discussion on the closed form solution. \n%\\tuner uses functions \\textproc{CurvatureRange}, \\textproc{Variance} and \\textproc{Distance} to measure quantities $h_{\\max}$, $h_{\\min}$, $C$ and $D$ respectively. These measurement functions can be designed in different ways.\n%We present the implementations we used for our experiments,\n%based completely on gradients,  in Section~\\ref{sec:oracles}.\n\n\n\n\n\\input{oracles}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "b8410880e54492d410a543658ff24c1af0b09a54", "size": 18911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuner.tex", "max_stars_repo_name": "mitliagkas/dshs", "max_stars_repo_head_hexsha": "6d5262af72288dd06544c2d5831d0c198db251bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tuner.tex", "max_issues_repo_name": "mitliagkas/dshs", "max_issues_repo_head_hexsha": "6d5262af72288dd06544c2d5831d0c198db251bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tuner.tex", "max_forks_repo_name": "mitliagkas/dshs", "max_forks_repo_head_hexsha": "6d5262af72288dd06544c2d5831d0c198db251bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.619760479, "max_line_length": 745, "alphanum_fraction": 0.6995399503, "num_tokens": 6197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6587683537748095}}
{"text": "\\documentclass[11pt]{scrartcl}\n\\usepackage{atonu}\n\\usepackage{fullpage}\n\\usepackage{amsmath,amsthm, amsfonts}\n\n\n\\begin{document}\n\\title{Diophantine Equations}\n\\subtitle{BdMO National Camp 2021}\n\\author{\\scshape{Atonu Roy Chowdhury} \\\\\n\\mailto{atonuroychowdhury@gmail.com}}\n\\date{\\today}\n\\maketitle\n\n\\section{What is Diophantine Equation?}\nIn our school textbooks, we often solve equations. But most of the equations are ``algebraic''. By ``algebraic'', I mean you had to solve them for real numbers. But in Diophantine Equations, we are given an equation and we have to find the integer solutions or positive integer solutions of that equation. Sounds fun, right? Alright, let's dive into some diophantine equations, shall we?\n% Some historical remark: Diophantine equation is named after greek mathematician Diophantus. In his book \\textit{Arithmetica}, he discussed about the solution of algebraic equations and the theory of numbers. It contains about 150 peoblems about solvability of equations. There were some cool number theoretic results, such that ``no integer of the form \\(8n+ 7\\) can be written as the sum of three squares.'' Diophantus is the first known human to work with integer solutions of equations. That's why Diophantine equation is named after him. \\\\\n\n\\section{Linear Diophantine Equations}\nIf I ask you, ``How many solutions are there to the equation \\(3x+6y=7\\)?'' you'll probably say that ``There are infinitely many solutions. \\(3x+6y=7\\) denotes a line in the Cartesian coordinate so it contains infinitely many points.'' And you are absolutely correct. But things get more interesting when I tell you to find the integer solutions.\\\\\nWell, if you play around with things a bit, you will find that there is \\textbf{no} integer solution to this equation. Because the LHS is \\(3x+6y = 3(x+2y)\\) which is obviously divisible by \\(3\\) as \\(x,y\\) are integers. But the RHS is \\(7\\), which is not divisible by 7. Hence, a contradiction. \\\\\nNow, if the RHS was divisible by \\(3\\), for instance \\(\\text{RHS} = 9\\), would the equation have integer solutions? If yes, how many? \\\\\nWell, one solution is very easy to find, that is \\(x=1, y=1\\). But are there other solutions? Turns out, there are. \\(x=-1, y=2\\) is another possible solution. If you work around with things, you will find that there are actually infinitely many solutions to this particular equation. \\\\ \nNow a natural question arises: when does a linear diophantine equation have solutions? To find the answer, we need Bezout's Identity.\n\\begin{theorem}[Bezout's Identity]\nLet \\(a\\) and \\(b\\) be positive integers and \\(\\gcd(a,b)=d\\). Then there exists some \\textbf{integer} \\(x\\) and \\(y\\) such that\n\\[ax+by = d\\]\n\\end{theorem}\nThis is actually not that hard to prove. We can use extremal principle to prove this.\n\\begin{proof}\nLet \\(S\\) be the set of all positive integers that can be written as \\(ax+by\\) for some \\textbf{integer} \\(x\\) and \\(y\\). That is\n\\[S = \\left\\{ n\\in \\NN : n = ax+by \\text{ for some integer } x \\text{ and } y \\right\\} \\]\nSince it's a subset of \\(\\NN\\), there exists a smallest value in this set. Let \\(m = \\min(S)\\). We claim that \\(m = d\\). \\\\\nTo show that \\(m=d\\), it's enough to show that \\( m \\mid d\\) and \\(d \\mid m\\). The latter is actually easy to see. Since \\(m \\in S\\), \\(m = an + bk\\) for some integer \\(n\\) and \\(k\\).\n\\[d = \\gcd(a,b) \\implies d \\mid a, d \\mid b \\implies d\\mid an + bk \\implies d \\mid m\\]\nNow we wanna show the other direction. If we divide \\(a\\) by \\(m\\), we shall get some quotient and some remainder. So, \\(a = qm + r\\), where \\(0 \\leq r < m\\). Now,\n\\[ r = a - qm = a - q (an + bk) = a (1-qn) - b(qk)\\]\nTherefore, \\(r\\) can also be written as the form \\(ax+by\\). If \\(r>0\\), then \\(r \\in S\\) which contradicts the minimality of \\(m\\). Therefore \\(r=0\\) and hence \\(m \\mid a\\). In a similar manner, it can be shown that \\(m \\mid b\\). Therefore \\(m \\mid \\gcd(a,b)=d\\) and we are done.\n\\end{proof}\n\\begin{corollary}\nThe equation \\(ax+by=c\\) has solutions in integer if and only if \\(\\gcd(a,b) \\mid c\\).\n\\end{corollary}\nThis follows immediately from Bezout's identity. So I'm not gonna state the proof here. Now we will see that, whenever a linear diophantine equation has solution, it actually has infinitely many solutions. Furthermore, the solutions have a common form.\n\\begin{lemma}\nIf \\((x_0, y_0)\\) is a solution to \\(ax+by = c\\), then all the solutions of this equation are of the form \\[x = x_0 + t\\frac{b}{d}, \\quad y= y_0 - t\\frac{a}{d}\\]\nwhere \\(d\\) is the gcd of \\(a\\) and \\(b\\).\n\\end{lemma}\n\\begin{proof}\n\\(d = \\gcd(a,b) \\implies a = da', b=db'\\) where \\(\\gcd(a,b)=1\\). \\((x_0, y_0)\\) is a solution to \\(ax+by = c\\), let \\((x_1, y_1)\\) be another solution. Then,\n\\begin{equation*}\n\\begin{split}\n&\\textcolor{white}{\\implies} ax_1+by_1 = c = ax_0+by_0 \\\\\n&\\implies da'(x_1- x_0) = db'(y_0 - y_1) \\\\\n&\\implies a'(x_1- x_0) = b'(y_0 - y_1) \\\\\n&\\implies a'\\mid y_0 - y_1 , \\quad b' \\mid x_1- x_0 \\\\\n&\\implies y_1 = y_0 - a't , \\quad x_1 = x_0 + b't\n\\end{split}\n\\end{equation*}\nHence, we are done.\n\\end{proof}\nNow we wish to apply this into a real problem. \n\\begin{exercise}\nSuppose you went to a restaurant where they sell Chicken Nuggets in packs of \\(9\\) and packs of \\(20\\). What is the largest number of nuggets that you can't get from that restaurant?\n\\end{exercise}\nThe problem is basically asking that, what is the largest value of \\(n\\) such that \\(n = 9x + 20 y\\) does not have any solution in non-negative integers? \\(9\\) and \\(20\\) are fairly small numbers. So you can find out by getting your hand dirty that the highest number of nuggets that you can't buy from that restaurant is \\(151\\). But if I ask you the same question with \\(289\\) and \\(475\\) instead of \\(9\\) and \\(20\\), can you still find it out by getting your hand dirty? I suppose not. So we need some kind of general formula for it. And that general formula is \\textit{Chicken-McNugget Theorem}.\n\\begin{theorem}[Chicken-McNugget Theorem]\nLet \\(a\\) and \\(b\\) be two coprime positive integers. Suppose \\(f(a,b)\\) denotes the largest number \\(n\\) such that the equation \\(n = ax+by\\) has no solution in non-negative integers. Then \\[f(a,b) = ab - a - b\\]\n\\end{theorem}\n\\begin{proof}\nThe proof consists of two parts. The first part is showing that \\(n = ab - a - b\\) leads us no solution in non-negative integers to the equation \\(n = ax+by\\). The second part is showing that for every \\(n> ab - a - b\\), we can always find a solution in non-negative integers to the equation \\(n = ax+by\\). \\\\\nFor the first part, assume for the sake of contradiction that there exists some non-negative integers \\(x\\) and \\(y\\) such that \\(ax + by = ab - a - b\\). Taking the equation in \\(\\text{mod }a\\), we get\n\\[by \\equiv -b \\amod{a} \\implies y \\equiv -1 \\amod{a} \\implies \\boxed{y \\geq a-1}\\]\nHere we could divide both sides of the modular equation by \\(b\\) because \\(b\\) is coprime to \\(a\\). Similarly, by taking \\(\\text{mod }b\\), we will get that \\(\\boxed{x \\geq b-1}\\). Therefore, \n\\[ab - a - b = ax + by \\geq a(b-1) + b(a-1) = 2ab - a -b\\]\nContradiction!\\\\\nNow for the second part, consider any integer \\(n > ab - a -b\\). Since \\(\\gcd(a,b)=1\\), by \\textit{Bezout's Identity} we can find integers \\(x'\\) and \\(y'\\) such that \\(ax' + by' = 1\\). Multiplying both sides by \\(n\\), we get an integer solution to the solution \\(ax+by=n\\).\n\\[ax' + by' = 1 \\implies a(x'n) + b(y'n) = n \\implies ax_0 + by_0 = n\\]\nBut we had to find non-negative integer solution to this equation. No worries, we showed in \\textit{Lemma 2.3} that, if we have one solution to the linear diophantine equation then we can find all the solutions. So the general solution to \\(ax+by = n\\) is given by\n\\[x = x_0 + tb, \\quad y = y_0 - ta\\]\nSo we need to show that, upon choosing the correct \\(t\\), we can make both \\(x\\) and \\(y\\) non-negative.\n\\[ax+by = n > ab-a-b \\implies \\boxed{b(y+1) > a(b -1 -x)}\\]\nTherefore, \\(y+1\\) is positive (in other words, \\(y\\) is non-negative) if \\(b-1 \\geq x\\). So if we can keep \\(x\\) between \\(0\\) and \\(b-1\\) inclusive, then we are basically done. \\\\\nIn fact, it's not actually hard to achieve. If we divide \\(x_0\\) by \\(b\\), we get some quotient and remainder. So \\(x_0 = qb + r\\). Notice that, remainder is always non-negative, so \\(0\\leq r \\leq b-1\\). Now if we choose \\(t = -q\\), then \\(x = x_0 + tb = qb + r -qb = r\\). Thus we can achieve \\(0 \\leq x \\leq b-1\\). \\\\\nNow, the conclusion becomes trivial. \n\\[b(y+1) > a(b -1 -x) \\geq 0 \\implies y+1 >0 \\implies y \\geq 0\\]\nSo \\(ax+by=n\\) has solution in non-negative integers.\n\\end{proof}\nNow, what about equations with more than \\(2\\) variables? Let's see an example.\n\\begin{exercise}\nFind all integer solutions of the following equation:\n\\[3x+4y+5z=6\\]\n\\end{exercise}\n\\begin{soln}\nHere we have 3 variables, but we can make it 2-variable equation. One way to do it is taking the mod of any coefficient. Generally it's a good practice to take mod of the highest coefficient. So taking mod \\(5\\), we get\n\\[3x + 4y \\equiv 1 \\amod 5 \\implies \\boxed{3x + 4y = 1 + 5s} \\implies 6 - 5z = 1+5s \\implies \\boxed{ z = 1-s}\\]\nNow we have a 2-variable linear diophantine equation to deal with: \\(3x + 4y = 1 + 5s\\). Can you find one solution to this equation? A bit of trial and error gives us \\(x = -1+3s , y = 1-s\\) is one solution. So by \\textit{Lemma 2.3} we can get all the solutions:\n\\[x = -1+3s + 4t , y = 1-s -3t , z = 1-s\\]\nIt is easy to verify that these values indeed satisfy the equation. \n\\end{soln}\n\n\\section{Whenever in confusion, factor it out}\nFactoring is often useful in solving diophantine equations. For instance, if you have an equation like \\(xy = 6\\), then you can reduce it into 4 cases: \\(x=1, y=6\\); \\(x=2, y=3\\); \\(x=3, y=2\\); \\(x=6, y=1\\). And this might often reduce the complexity of the problem.\n\\begin{exercise}\nSolve in positive integers:\n\\[xyz+x+y+z = 2 + xy+yz+zx\\]\n\\end{exercise}\n\\begin{soln}\nIf we isolate the variables,\n\\[xyz+x+y+z -xy -yz -zx= 2\\]\nLet's try to factorize the LHS.\n\\[x(yz+1 -y - z) - (yz -y - z) = 2\\]\nIf we had a \\(-1\\) in the LHS, then we could factorize it easily. So let's borrow a \\(-1\\) from the RHS.\n\\[x(yz+1 -y - z) - (yz -y - z +1) = 1 \\implies (x-1)(y-1)(z-1)=1\\]\n\\(x,y,z\\) are positive integers, so \\(x-1, y-1, z-1\\) are non-negative integers. Three non-negative integer's product can be \\(1\\) only if they are all \\(1\\). Therefore,\n\\[x-1 = y-1 = z-1 =1 \\implies \\boxed{x=y=z=2}\\]\n\\end{soln}\nThere is a popular factoring trick in Olympiad Folklore. It's popularly known as \\textbf{SFFT} or \\textit{Simon's Favorite Factoring Trick}. What does this trick do? It basically factorises an equation of the form \\[Axy + Bx + Cy + D =0\\]\nAfter factorizing, things get easier to work with. The best idea of illustrating this trick would be showing an example. \n\\begin{exercise}\nFind all primes \\(p,q,r\\) such that\n\\[pqr = 19(p+q+r)\\]\n\\end{exercise}\n\\begin{soln}\nThe RHS is divisible by \\(19\\), which is a prime number. The LHS is the product of three prime numbers. So one of them must be \\(19\\). WLOG, \\(r = 19\\). So the equation becomes\n\\[pq = p+q+19 \\implies pq-p-q=19\\]\nIf we had a \\(1\\) in the LHS, then we could factorize it without any trouble. So let's add \\(1\\) on both sides:\n\\[pq-p-q = 19 \\implies pq-p-q+1=20 \\implies (p-1)(q-1)=20\\]\nThe rest is left as an exercise for the reader.\n\\end{soln}\n\\begin{exercise}\nFind the smallest value of \\(n\\) for which the following equation has \\(69\\) different solutions for \\((x,y)\\):\n\\[\\frac1x + \\frac1y = \\frac1n\\]\n\\end{exercise}\n\\begin{soln}\nLet's try to isolate the variables in the given equation:\n\\[\\frac1x + \\frac1y = \\frac1n \\implies \\frac{x+y}{xy}= \\frac{1}{n} \\implies xy - nx -ny =0\\]\nAs we try to factorize this, we feel the absence of \\(n^2\\). We have the liberty to add it on both sides, so why don't we do it?\n\\[xy - nx -ny =0 \\implies xy - nx -ny +n^2=n^2 \\implies \\boxed{(x-n)(y-n) = n^2}\\]\nNow, we have to find out the smallest \\(n\\) for which there are \\(69\\) different pairs of \\((x,y)\\) satisfying \\((x-n)(y-n) = n^2\\). If you play around things a bit, you'll get that, the number of solutions is precisely the number of divisors of \\(n^2\\). So the question now translates into: find the smallest \\(n\\) with \\(\\tau(n^2)=69\\).\\\\\n\\(69 = 1\\times 69 = 3 \\times 23\\). So the possible values for \\(n^2\\) are either \\(p^{68}\\) and \\(p^{22}q^2\\) where \\(p\\) and \\(q\\) are primes. The smallest value of \\(p^{68}\\) is \\(2^{68}\\). The smallest value of \\(p^{22}q^2\\) is \\(2^{22}3^2\\). As \\(2^{68} > 2^{22}\\ 3^2\\), we can conclude that, \\(2^{22}\\ 3^2\\) is the smallest possible value of \\(n^2\\). Therefore, the smallest possible value of \\(n\\) is \\(2^{11}\\ 3\\).\n\\end{soln}\n\n\n\n\\section{The Legend, The Myth -- The ``Chipa'' Trick}\nThe ``Chipa'' Trick is a bounding strategy for solving diophantine equations. It's specially useful when the problem statement looks like this: ``Find all integer \\(x\\) such that \\(f(x)\\) is a perfect \\(n\\)-th power.'' In that case if you can show that \\((y+1)^n < f(x) < y^n\\), then you can conclude that no such \\(x\\) exists. Because if there existed such \\(x\\), \\(f(x)\\) couldn't lie strictly between two consecutive \\(n\\)-th power. \\\\\nIn this trick, we try to show something like this: \\(X \\leq Y \\leq Z\\), which can be interpreted as \\(Y\\) inside the ``Chipa'' of \\(X\\) and \\(Z\\). That's why this trick is known as ``Chipa'' trick in BdMO camps. Let's try some problems using this trick.\n\\begin{exercise}\nFind all positive integers such that \\(n^2 -19n +89\\) is a perfect square.\n\\end{exercise}\n\\begin{soln}\nThe given expression is \\(n^2 -19n +89\\). Here \\(19\\) is an odd number. If it were even, we could try something like this: \\(n^2 - 2kn + k^2\\). But as it's odd number, it's inside the ``chipa'' of two even numbers. So, \n\\[n^2 -20n < n^2 -19 n < n^2 - 18n\\]\nThe constants don't matter much. Therefore, after some \\(n\\), we shall get that,\n\\[ n^2 -20n +100< n^2 -19 n + 89< n^2 - 18n + 81 \\implies (n-10)^2 < n^2 -19n +89 < (n-9)^2\\]\nWe got our ``chipa''! Now if you play with this inequality a bit, you will find that this inequality holds for \\(n>11\\). That means, when \\(n\\geq 12\\), \\(n^2 -19n +89 \\) lies strictly between two consecutive squares, so it can't be square. \\\\\nWe still have a bit of labour left, We have to calculate by hand for \\(n = 1\\) to \\(11\\). Checking these, we get that, only \\(n=8\\) and \\(n=11\\) makes \\(n^2 -19n +89\\) a perfect square.\n\\end{soln}\n\\begin{exercise}\nFind all positive integers \\(x,y,z\\) such that\n\\[x^2 + y^2 + z^2 + 2xy + 2y(z-1) + 2x(z+1)\\]\nis a perfect square.\n\\end{exercise}\n\\begin{soln}\nLet \\(x^2 + y^2 + z^2 + 2xy + 2y(z-1) + 2x(z+1) = n^2\\). The ``chipa'' is fairly easy to find here. Because the given expression kinda looks like \\((x+y+z)^2\\), but with \\(z+1\\) and \\(z-1\\) instead of \\(z\\). So the ``chipa'' is:\n\\[(x+y+z-1)^2 < n^2 < (x+y+z+1)^2\\]\nSo \\(n\\) must be \\(x+y+z\\). Substituting this, we shall get that \\(x = y\\). So \\((x,y,z)=(m,m,k)\\) is all the solutions.\n\\end{soln}\n\\begin{exercise}\nFind all solutions in positive integers of the equation\n\\[\nx^{3}+(x+1)^{3}+(x+2)^{3}+\\cdots+(x+7)^{3}=y^{3}\n\\]\n\\end{exercise}\n\\begin{soln}\nIt's not hard to see that \\(x^{3}+(x+1)^{3}+(x+2)^{3}+\\cdots+(x+7)^{3} = 8x^3 + 84x^2 + +420x + 784\\). So you get the idea that the ``chipa'' should be \\((2x+a)^3 < y^3 < (2x+b)^3\\). You should be able to figure out what \\(a\\) and \\(b\\) should be. I'll leave the rest as an exercise for you.\n\\end{soln}\n\n\\section{Discriminant}\nYou've probably learned about quadratic equation \\(ax^2 + bx + c =0\\) in high school. The solution of this kind of 2-degree equation is given by:\n\\[x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}\\]\nNotice that, the nature of the solutions depend on \\(b^2-4ac\\). This expression is called discriminant. We want integer solutions here. So we must have a perfect square discriminant. \\[\\Delta = b^2 -4ac = k^2\\]\nThis trick is often useful. When we have 2 variables, we can find the value of one variable using \\textbf{discriminant is perfect square}. Then solving for the other variable becomes a much easier job.\n\\begin{exercise}\nFind all positive integer \\(n\\) such that \\(n^2 - 59n + 881\\) is a perfect square.\n\\end{exercise}\nI believe many of you can solve this problem using ``chipa'' trick. So I'm gonna show a solution using discriminants.\n\\begin{soln}\n\\(n^2 - 59n + 881 = k^2 \\implies n^2 - 59n + 881 - k^2 =0\\). Now if we treat \\(n\\) as variable and \\(k\\) as constant, then the equation becomes a quadratic. So the discriminant must be a perfect square.\n\\[a^2 = \\Delta = 59^2 - 4 (881-k^2) = 4k^2 - 43 \\implies 43= 4k^2 - a^2 = (2k+a)(2k-a)\\]\nwhich gives us \\(k=11\\). Plugging this into our main equation, \n\\[n^2 - 59n + 881 = 121 \\implies n^2 - 59n +760 = 0\\]\nwhich has solutions \\(n=19\\) and \\(n=40\\).\n\\end{soln}\n\\begin{exercise}\nSolve in positive integers:\n\\[(x^2+y)(x+y^2)=(x-y)^3\\]\n\\end{exercise}\n\\begin{soln}\nExpanding out, we get\n\\begin{equation*}\n\\begin{split}\n&\\textcolor{white}{\\implies} (x^2+y)(x+y^2)=(x-y)^3 \\\\\n&\\implies x^3 + y^3 + x^2 y^2 + xy = x^3 - y^3 - 3 x^2 y + 3xy^2 \\\\\n&\\implies y(y^2 + x^2 y + x ) = y(-y^2 -3x^2 + 3xy)\\\\\n&\\implies y^2 + x^2 y + x +y^2 +3x^2 - 3xy = 0\\\\\n&\\implies 2y^2 + (x^2 -3x) y + (3x^2 +x) = 0\n\\end{split}\n\\end{equation*}\nThis is a quadratic equation on \\(y\\). So the discriminant \\(\\Delta = (x^2 -3x)^2 - 4\\cdot 2 (3x^2 +x)\\) must be a perfect square. The rest is left as an exercise for the reader.\n\\end{soln}\n\n\\section{Infinite Descent}\nInfinite descent is often a very useful trick to solve diophantine equations. In this trick, we assume that some solution exist and we take the solution with least sum. Then we show that there exists another solution with even less sum. Hence we arrive at a contradiction. Let's jump into some examples:\n\\begin{exercise}\nProve that the equation \\(a^2+b^2= 3c^2\\) has no solutions in positive integers.\n\\end{exercise}\n\\begin{soln}\nAssume for the sake of contradiction that some solutions exist. We take one such solution \\(a_1, b_1, c_1\\) such that \\(a_1 + b_1 + c_1\\) is the smallest. \\\\\nNotice that \\(\\qr(3) = \\left\\{ 0,1 \\right\\} \\). The RHS is divisible by \\(3\\), hence \\(3 \\mid a_1^2 + b_1^2\\). Then it's easy to see that, we must have \\(a_1^2 \\equiv 0 \\amod 3\\) and \\(b_1^2 \\equiv 0 \\amod 3\\). In other words, \\(3 \\mid a_1\\) and \\(3\\mid b_1\\). Substituting \\(a_1 = 3a_2\\) and \\(b_1 = 3b_2\\) we get,\n\\[\n\t(3a_2)^2 + (3b_2)^2 = 3c_1^2 \\implies 3 (a_2^2+b_2^2) = c_1^2 \\implies 3 \\mid c_1\n\\]\nNow, substituting \\(c_1 = 3c_2\\), we get\n\\[\n\t3 (a_2^2+b_2^2) = (3c_2)^2 \\implies a_2^2+b_2^2 = 3c_2^2\n\\]\nHere \\(a_2 = \\frac{a_1}{3}, b_2 = \\frac{b_1}{3}, c_2 = \\frac{c_1}{3}\\) and \\((a_2, b_2, c_2)\\) is also a solution to the give equation. So we found a solution with even less sum than the least sum. Hence contradiction!\n\\end{soln}\n\\begin{exercise}\nSolve in positive integers: \\(x^3 + 2y^3 = 4z^3\\)\n\\end{exercise}\nThe solution is left as an exercise for the reader.\n\n\\section{A Magical Mod}\nThese type of problems require a magical mod. Like if you take mod \\(n\\) on both sides, you might arrive at some contradiction, or you might get some new information about the problem. But when you are reading the solution, you might be wondering: how did this specific mod came out of nowhere? Well, I'm gonna try to explain the intuitions behind these mods. \n\\begin{exercise}\nLet \\(d\\) be any positive integer not equal to \\(2, 5, 13\\). Show that one can find distinct \\(a, b\\) in the set \\(\\{2,5,13, d\\}\\) such that \\(ab−1\\) is not a perfect square.\n\\end{exercise}\nThe problem is basically saying that: whatever \\(d\\) is, not all of \\(2d-1, 5d-1, 13d-1\\) are perfect squares. So intending to show a contradiction, we assume otherwise. We got three diophantine equations to solve:\n\\begin{equation*}\n\\begin{split}\n2d-1 &= x^2 \\\\\n5d -1 &= y^2 \\\\\n13d-1 &= z^2\n\\end{split}\n\\end{equation*}\nHere we have perfect squares to deal with. We need a magical mod. What should it be? Keep in mind that, our magical mod should have a relatively smaller quadratic residue class. Because if the quadratic residue class is too large, then we will have LOTS of cases to consider. That's why primes are not a good candidate for this. Because \n\\[ \\abs{\\qr(p)} = 1 + \\frac{p-1}{2}\\]\nwhich is not really much of improvement. Turns out powers of \\(2\\) are the best candidates. It can be proved that \n\\[\\abs{ \\qr \\left(2^n\\right) } = \\ceiling{\\frac{2^n}{6}} + 1\\]\nwhich is almost thrice as good as primes. So the lesson from this problem is: \\textbf{Whenever you have squares to deal with, try taking mods of power of \\(2\\). Such as: 4, 8, 16 etc.}. Let's dive into the solution then.\n\\begin{soln}\nWe have to show that, there does not exist any \\(d\\) that satisfies all of the following equations:\n\\begin{equation*}\n\\begin{split}\n2d-1 &= x^2 \\\\\n5d -1 &= y^2 \\\\\n13d-1 &= z^2\n\\end{split}\n\\end{equation*}\nYou can try taking mod \\(4\\) or mod \\(8\\). But they don't produce any contradiction. Do we give up? \\textbf{NO!} We can try taking mod \\(16\\). It's not hard to verify that\n\\[ \\qr(16) = \\left\\{ 0,1,4,9 \\right\\}  \\]\nTherefore, \\(2d-1\\) is a perfect square if \\(2d-1 \\in \\left\\{ 1,9 \\right\\} \\amod{16}  \\implies d \\in \\left\\{ 1,5 \\right\\} \\amod{8} \\implies \\boxed{d \\in \\left\\{ 1,5,9,13 \\right\\} \\amod{16}}\\). \\\\\n\\(5d-1\\) is a perfect square if \\(5d-1 \\in \\left\\{ 0,1,4,9 \\right\\}\\). If you work with this, you'll find that this is equivalent to \\(\\boxed{d \\in \\left\\{ 1,2,10,13 \\right\\} \\amod{16}} \\). Similarly, \\(13d-1\\) is a perfect square if \\(\\boxed{d \\in \\left\\{ 2,5,9,10 \\right\\} \\amod{16}}\\). \\\\\nThere is no common \\(d\\) in these three sets. So there does not any \\(d\\) for which all of \\(2d-1, 5d-1, 13d-1\\) are squares.\n\\end{soln}\nOkay, we've learnt that \\(2^n\\) is a very good candidate when we need to deal with squares. But what about the higher powers? If we need to deal with \\(x^d\\), then it's often a good practice to deal with mod \\(p\\), where \\(p\\) is a prime with \\(d \\mid p-1\\). \\\\\nNow you may ask why. The answer is: whenever \\(d \\mid p-1\\), \\(x^d\\) can take exactly \\(1+\\frac{p-1}{d}\\) different remainders upon division by \\(p\\).\\footnote{You can prove it, I'll leave it as an exercise for you.} \\(1+\\frac{p-1}{d}\\) is a pretty small number when \\(d\\) gets larger. So it's not that hard to work with such \\(p\\). \\\\\nAlright, let's look at some examples.\n\\begin{exercise}\nFind all integer solutions: \\(x^3+y^4=7\\)\n\\end{exercise}\n\\begin{soln}\nWe have power \\(3\\) and power \\(4\\) here. So a prime \\(p\\) with \\(3 \\mid p-1\\) and \\(4 \\mid p-1\\) might do the job. Turns out, \\(13\\) is one such prime. If we take mod \\(13\\),\n\\[x^3 \\equiv 0,1,5,8,12 \\amod{13}, \\quad y^4 \\equiv 0,1,3,9 \\amod{13}\\]\nWe cannot make the sum \\(7\\). Thus, there does not exist any integer with \\(x^3+y^4=7\\).\n\\end{soln}\n\\begin{exercise}\nSolve in integers: \\(x^5 - y^2 = 4\\)\n\\end{exercise}\n\\begin{soln}\nWe need a prime such that \\(5 \\mid p-1\\). \\(p=11\\) is one such prime. Taking mod \\(11\\),\n\\[x^5 \\equiv 0,1,-1 \\amod{11} \\implies y^2 = x^5 - 4 \\equiv 6,7,8 \\amod{11}\\]\nBut \\(\\qr(11) = \\left\\{ 0,1,4,9,5,3 \\right\\} \\). So no solution.\n\\end{soln}\n\\begin{exercise}\nSolve in positive integers: \\(3^x - 2^y = 7\\)\n\\end{exercise}\n\\begin{soln}\nIf \\(y=1\\), we get a solution \\((x,y) = (2,1)\\). So assume \\(y\\geq 2\\). Therefore \\(4 \\mid 2^y\\). Taking mod \\(4\\), we get\n\\[3^x \\equiv -1 \\amod 4\\]\nIf \\(x\\) is even, then it's never possible. So we must have \\(x=2k+1\\) for some integer \\(k\\). We need to improve our mod now. So let's take mod \\(8\\). \n\\[3^{x} = 3\\cdot 3^{2k} = 3 \\cdot 9^k \\equiv 3 \\amod{8} \\implies 7+ 2^y \\equiv 3 \\amod{8}\\]\nwhich is not possible for \\(y\\geq 3\\). We can check \\(y=2\\) by hand but it does not produce any solution. \\\\\nHence the only solution is \\((x,y) = (2,1)\\).\n\\end{soln}\n\n\\section{Practice Problems}\n\\begin{problem}\nProve that the expression\n\\[\\frac{\\gcd(m,n)}{n} \\binom{n}{m}\\]\nis an integer for all pairs of integers \\(n \\geq m \\geq 1\\).\n\\end{problem}\n\\begin{problem}\nLet \\(a\\) and \\(b\\) be coprime positive integers. Prove that there are exactly \\(\\frac{(a-1)(b-1)}{2}\\) integers that cannot be written as \\(ax+by\\) for non-negative integer \\(x,y\\).\n\\end{problem}\n\\begin{problem}\nLet \\(a, b\\), and \\(c\\) be positive integers, no two of which have a common divisor greater than 1. Show that \\(2 a b c-a b-b c-c a\\) is the largest integer that cannot be expresed in the form \\(x b c+y c u+z a b\\), where \\(x, y\\), and \\(z\\) are nonnegative integcrs.\n\\end{problem}\n\\begin{problem}\nLet \\(n>1\\) be an odd integer. Prove that there exist positive integers \\(x\\) and \\(y\\) such that\n\\[\n\\frac{4}{n}=\\frac{1}{x}+\\frac{1}{y}\n\\]\nif and only if \\(n\\) has a prime factor of the form \\(4 k-1 .\\)\n\\end{problem}\n\\begin{problem}\nFind all positive integers \\(m, n\\), where \\(n\\) is odd, that satisfy\n\\[\n\\frac{1}{m}+\\frac{4}{n} \\quad \\frac{1}{12}\n\\]\n\\end{problem}\n\\begin{problem}\nFind all \\(m,p,q\\) with \\(2^mp^2 + 1 = q^7\\), where \\(m\\in\\NN\\) and \\(p,q\\) are primes.\n\\end{problem}\n\\begin{problem}\nFind all integers \\(n\\) for which the equalion\n\\[\nx^{3}+y^{3}+z^{3}-3 x y z=n\n\\]\nis solvable in posilive inlegers.\n\\end{problem}\n\\begin{problem}\nFind all triples \\((x, y, p)\\), where \\(x\\) and \\(y\\) are positive integers\nand \\(p\\) is a prime, satisfying the equation\n\\[\nx^{5}+x^{4}+1=p^{y}\n\\]\n\\end{problem}\n\\begin{problem}\nDetermine all triples \\((x, y, z)\\) of positive integers such that\n\\[\n(x+y)^{2}+3 x+y+1=z^{2} \\text { . }\n\\]\n\\end{problem}\n\\begin{problem}\nDetermine all pairs \\((x, y)\\) of integers that satisfy the equation\n\\[\n(x+1)^{4}-(x-1)^{4}=y^{3} \\text { . }\n\\]\n\\end{problem}\n% \\begin{problem}\n% Let \\(a\\) and \\(b\\) be positive integers such that \\(a b+1\\) divides \\(a^{2}+b^{2}\\).\n% Prove that \\(\\frac{a^{2}+b^{2}}{a b+1}\\) is the square of an integer.\n% \\end{problem}\n\\begin{problem}\nFind the maximal value of \\(m^{2}+n^{2}\\) if \\(m\\) and \\(n\\) are integers between 1 and 1981 satisfying \\(\\left(n^{2}-m n-m^{2}\\right)^{2}=1\\).\n\\end{problem}\n\\begin{problem}\nFind all integers \\(x, y, z\\) satisfying\n\\[\nx^{2}+y^{2}+z^{2}-2 x y z=0 .\n\\]\n\\end{problem}\n\\begin{problem}\nSolve the following equation in integers \\(x, y, z, u\\) :\n\\[\nx^{4}+y^{4}+z^{4}=9 u^{4} \\text { . }\n\\]\n\\end{problem}\n\\begin{problem}\nSolve the following equation in positive integers:\n\\[\nx^{2}-y^{2}=2 x y z\n\\]\n\\end{problem}\n\\begin{problem}\nProve that there are no integer solutions (x, y) to \\(y^2=x^3+23\\).\n\\end{problem}\n\\begin{problem}\nDetermine all integral solutions to the equation\n\\[\na^{2}+b^{2}+c^{2}=a^{2} b^{2} .\n\\]\n\\end{problem}\n\\begin{problem}\nFind all pairs \\((p, q)\\) of prime numbers such that\n\\[\np^{3}-q^{5}=(p+q)^{2} .\n\\]\n\\end{problem}\n\\begin{problem}\nProve that if \\(n\\) is a positive integer such that the\nequation\n\\[\nx^{3}-3 x y^{2}+y^{3}=n\n\\]\nhas a solulion in inlegers \\(x, y\\), then il has at leasl three such solu-\ntions. Prove thal the equalion has no integer solution when \\(n=2891 .\\)\n\\end{problem}\n\\begin{problem}\nFind all triples \\((x, y, z)\\) of nonnegative integers such that\n\\[\n5^{x} 7^{y}+4=3^{z}\n\\]\n\\end{problem}\n\\begin{problem}\nSolve in positive integers: \\(n^7+7=k^2\\)\n\\end{problem}\n\\begin{problem}\nDetermine all pairs $(x, y)$ of integers such that\n\\[1+2^{x}+2^{2x+1}= y^{2}.\\]\n\\end{problem}\n\\begin{problem}\nFind all pairs $(k,n)$ of positive integers such that \\[ k!=(2^n-1)(2^n-2)(2^n-4)\\cdots(2^n-2^{n-1}). \\]\n\\end{problem}\n\\begin{problem}\nFind all triples $(a, b, c)$ of positive integers such that $a^3 + b^3 + c^3 = (abc)^2$.\n\\end{problem}\n\\begin{problem}\nFind all pairs $(m,n)$ of nonnegative integers for which \\[m^2 + 2 \\cdot 3^n = m\\left(2^{n+1} - 1\\right).\\]\n\\end{problem}\n\\begin{problem}\nFind all integer solutions of the equation \\[\\frac{x^{7}-1}{x-1}=y^{5}-1\\]\n\\end{problem}\n\\end{document}\n", "meta": {"hexsha": "92f69ee30feac364e3d3d1036dbb5539b5f72def", "size": 27582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2021/dioph.tex", "max_stars_repo_name": "atonurc/matholy_resources", "max_stars_repo_head_hexsha": "cc2e027c400988451c032fd6b79d5388cc1cf927", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-30T15:03:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T15:03:42.000Z", "max_issues_repo_path": "2021/dioph.tex", "max_issues_repo_name": "atonurc/matholy_resources", "max_issues_repo_head_hexsha": "cc2e027c400988451c032fd6b79d5388cc1cf927", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2021/dioph.tex", "max_forks_repo_name": "atonurc/matholy_resources", "max_forks_repo_head_hexsha": "cc2e027c400988451c032fd6b79d5388cc1cf927", "max_forks_repo_licenses": ["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.4439252336, "max_line_length": 599, "alphanum_fraction": 0.662025959, "num_tokens": 9525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6587683480261727}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 6.08a A problem with {\\tt evaluate} }\n\n\\CdbSetup{action=verbatim}% the following code will raise a run time error\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_{a}::Depends(\\theta,\\varphi,\\partial{#}).\n\n   dVrule := { \\partial_{\\theta}{V_{\\varphi}} = \\sin(\\theta),\n               \\partial_{\\varphi}{V_{\\theta}} = \\cos(\\theta)}.  # cdb(ex-0608.101,dVrule)\n   dV := \\partial_{b}{V_{a}} - \\partial_{a}{V_{b}}.             # cdb(ex-0608.102,dV)\n\n   evaluate (dV, dVrule)                                        # cdb(ex-0608.103,dV)\n\\end{cadabra}\n\n\\vskip 1cm\n\\bgroup\n\\lstset{numbers=none,backgroundcolor=\\color{white}}\n\\begin{lstlisting}\n   Traceback (most recent call last):\n     File \"/usr/local/bin/cadabra2\", line 248, in <module>\n       exec(cmp)\n     File \"ex-0608.py\", line 27, in <module>\n       evaluate (dV, dVrule)\n   RuntimeError: Dependencies on derivatives are not yet handled in the SymPy bridge\n\\end{lstlisting}\n\\egroup\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 6.08b A work around}\n\n\\CdbSetup{action=show}\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_{a}::Depends(\\theta,\\varphi,\\partial{#}).\n\n   hide := \\partial_{a}{V_{b}} -> dV_{a b}.\n\n   dVrule := { dV_{\\theta\\varphi} = \\sin(\\theta),\n               dV_{\\varphi\\theta} = \\cos(\\theta)}.              # cdb(ex-0608.201,dVrule)\n   dV := \\partial_{b}{V_{a}} - \\partial_{a}{V_{b}}.             # cdb(ex-0608.202,dV)\n\n   substitute (dV, hide)                                        # cdb(ex-0608.212,dV)\n   evaluate (dV, dVrule)                                        # cdb(ex-0608.203,dV)\n\\end{cadabra}\n\nThe workaround here is to to hide the derivatives before calling {\\tt evaluate}.\n\n\\begin{align*}\n   \\Cdb{ex-0608.212}\\\\\n   dV_{a b} &= \\Cdb{ex-0608.202}\\\\[10pt]\n            &= \\Cdb{ex-0608.203}\\\\[10pt]\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "cf678a4b200a8b32548cea9d4cb8ac5cd33975a4", "size": 2365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0608.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-0608.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-0608.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.5333333333, "max_line_length": 94, "alphanum_fraction": 0.5484143763, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6587626499771769}}
{"text": "\\chapter{Digital Image Processing}\n\nWe worked with images from\nCRIC Database.\n% TODO Add citation\nThe 400 images\nhave \\(1376~\\times~1020\\)~pixels.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics{R/img/be340ee72689dfe3f8dc9c24de6127f4.png}\n  \\caption{Example of image from CRIC}\n  % TODO Add DOI\n\\end{figure}\n\nWe store the image as 3-D array \\(A\\),\ncontaining\n\\(M\\) rows,\n\\(N\\) columns,\nand\n3 channels\n(red, green, and blue).\nFor clarity\nand\nconvenience,\nsince we used Python as programming language,\nwe use integer values for the discrete coordinates:\n\\(x = 0, 1, 2, \\ldots, M - 1\\),\n\\(y = 0, 1, 2, \\ldots, N - 1\\),\n\\(z = 0, 1, 2\\).\n\\(x\\), \\(y\\), and \\(z\\)\nare referred as spatial variables.\n\nThe value \\(a_{x, y, z}\\)\nis referred as intensity of \\(A\\)\nat \\(x\\), \\(y\\), and \\(z\\)\nand they are integers\nin the interval\n\\([0, 255]\\).\n\nA pixel \\(p\\)\nat coordinates \\((x, y, z\\)\nhas four horizontal and vertical neighbours,\ndenoted by \\(N_4(p)\\):\n\\begin{itemize}\n\\item \\(x - 1, y, z\\)\n\\item \\(x + 1, y, z\\)\n\\item \\(x, y - 1, z\\)\n\\item \\(x, y + 1, z\\)\n\\end{itemize}\nIt also has for diagonal neighbours,\ndenoted by \\(N_D(p)\\):\n\\begin{itemize}\n\\item \\(x - 1, y - 1, z\\)\n\\item \\(x + 1, y - 1, z\\)\n\\item \\(x + 1, y + 1, z\\)\n\\item \\(x - 1, y + 1, z\\)\n\\end{itemize}\nThe \\(N_4(p) \\cup N_D(p)\\)\nis called 8-neighbours of \\(p\\)\nand denoted by \\(N_8(p)\\).\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"masters_dissertation\"\n%%% End:\n", "meta": {"hexsha": "62b3f39c2d2919196f5a19cc4aff30a6d2baf8eb", "size": 1427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "image-processing.tex", "max_stars_repo_name": "rgaiacs/ufop_masters_dissertation", "max_stars_repo_head_hexsha": "6a673025a8f2c9dfc72e950db4ca0ca185df0f4b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-02T16:09:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-02T16:09:01.000Z", "max_issues_repo_path": "image-processing.tex", "max_issues_repo_name": "rgaiacs/ufop_masters_dissertation", "max_issues_repo_head_hexsha": "6a673025a8f2c9dfc72e950db4ca0ca185df0f4b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "image-processing.tex", "max_forks_repo_name": "rgaiacs/ufop_masters_dissertation", "max_forks_repo_head_hexsha": "6a673025a8f2c9dfc72e950db4ca0ca185df0f4b", "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.2985074627, "max_line_length": 62, "alphanum_fraction": 0.6250875964, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6587548616969018}}
{"text": "While SymPy primarily focuses on symbolics, it is impossible to have a\ncomplete symbolic system without the ability to numerically evaluate\nexpressions. Many operations directly use numerical evaluation, such as\nplotting a function, or solving an equation numerically. Beyond this, certain\npurely symbolic operations require numerical evaluation to effectively\ncompute. For instance, determining the truth value of $e + 1 > \\pi$ is most\nconveniently done by numerically evaluating both sides of the inequality and\nchecking which is larger.\n\n\\subsection{Floating-Point Numbers}\n\\label{sec:floating-point}\nFloating-point numbers in SymPy are implemented by the \\texttt{Float} class,\nwhich represents an arbitrary-precision binary floating-point number by\nstoring its value and precision (in bits). This representation is distinct\nfrom the Python built-in \\texttt{float} type, which is a wrapper around\nmachine \\texttt{double} types and uses a fixed precision (53-bit).\n\nBecause Python \\texttt{float} literals are limited in precision, strings\nshould be used to input precise decimal values:\n\\begin{verbatim}\n>>> Float(1.1)\n1.10000000000000\n>>> Float(1.1, 30)   # precision equivalent to 30 digits\n1.10000000000000008881784197001\n>>> Float(\"1.1\", 30)\n1.10000000000000000000000000000\n\\end{verbatim}\nThe \\texttt{evalf} method converts a constant symbolic expression to a\n\\texttt{Float} with the specified precision, here 25 digits:\n\\begin{verbatim}\n>>> (pi + 1).evalf(25)\n4.141592653589793238462643\n\\end{verbatim}\n\\texttt{Float} numbers do not track their accuracy,\nand should be used with caution within symbolic expressions\nsince familiar dangers of floating-point arithmetic apply~\\cite{goldberg1991every}.\nA notorious case is that of catastrophic cancellation:\n\\begin{verbatim}\n>>> cos(exp(-100)).evalf(25) - 1\n0\n\\end{verbatim}\nApplying the \\texttt{evalf} method to the whole expression solves\nthis problem. Internally, \\texttt{evalf} estimates the number of accurate\nbits of the floating-point\napproximation for each sub-expression, and adaptively increases the\nworking precision until the estimated accuracy of the\nfinal result matches the sought number of decimal digits:\n\\begin{verbatim}\n>>> (cos(exp(-100)) - 1).evalf(25)\n-6.919482633683687653243407e-88\n\\end{verbatim}\nThe \\texttt{evalf} method works with complex numbers and supports\nmore complicated expressions, such as\nspecial functions, infinite series, and integrals.\nThe internal error tracking does not provide rigorous error bounds\n(in the sense of interval arithmetic) and cannot be used to accurately track\nuncertainty in measurement data;\nthe sole purpose is to mitigate loss of accuracy that typically occurs\nwhen converting symbolic expressions to numerical values.\n\n\\subsection{The mpmath Library}\n\\label{sec:mpmath}\n\nThe implementation of arbitrary-precision floating-point arithmetic is\nsupplied by the mpmath library~\\cite{mpmath}. Originally, it was developed as a SymPy\nsubmodule but has subsequently been moved to a standalone pure-Python package.\nThe basic datatypes in mpmath are \\texttt{mpf} and \\texttt{mpc}, which\nrespectively act as multiprecision substitutes for Python's \\texttt{float} and\n\\texttt{complex}. The floating-point precision is controlled by a global\ncontext:\n\n% doctest printer doesn't display \"mpf\"\n% no-doctest\n\\begin{verbatim}\n>>> import mpmath\n>>> mpmath.mp.dps = 30    # 30 digits of precision\n>>> mpmath.mpf(\"0.1\") + mpmath.exp(-50)\nmpf('0.100000000000000000000192874984794')\n>>> print(_)   # pretty-printed\n0.100000000000000000000192874985\n\\end{verbatim}\n\nLike SymPy, mpmath is a pure Python library.  A design decision of SymPy is to\nkeep it and its required dependencies pure Python. This is a primary advantage\n of mpmath over other multiple precision libraries such as GNU MPFR~\\cite{Fousse:2007:MMB:1236463.1236468},\nwhich is faster.  Like SymPy, mpmath is also BSD\nlicensed (GNU MPFR is licensed under the GNU Lesser General Public License~\\cite{rosen2005open}).\n\nInternally, mpmath represents\na floating-point number ${(-1)}^s x \\cdot 2^y$ by a tuple $(s, x, y, b)$ where\n$x$ and $y$ are arbitrary-size Python integers\nand the redundant integer $b$ stores the bit length of $x$ for quick access.\nIf GMPY~\\cite{GMPY} is installed, mpmath automatically uses\nthe \\texttt{gmpy.mpz} type for~$x$, and GMPY methods\nfor rounding-related operations, improving performance.\n\nMost mpmath and SymPy functions use the same naming scheme, although this is\nnot true in every case. For example, the symbolic SymPy summation expression\n\\texttt{Sum(f(x), (x, a, b))} representing $\\sum_{x=a}^b f(x)$ is represented\nin mpmath as \\texttt{nsum(f, (a, b))}, where \\texttt{f} is a numeric Python\nfunction.\n\nThe mpmath library supports\nspecial functions, root-finding, linear algebra, polynomial approximation,\nand numerical computation of limits, derivatives, integrals, infinite\nseries, and solving ODEs. All features work in arbitrary precision\nand use algorithms that allow computing hundreds of digits rapidly\n(except in degenerate cases).\n\nThe double exponential (tanh-sinh) quadrature is used for numerical\nintegration by default. For smooth integrands, this algorithm usually\nconverges extremely rapidly, even when the integration interval is infinite\nor singularities are present at the endpoints~\\cite{takahasi1974double,bailey2005comparison}.\nHowever, for good performance, singularities\nin the middle of the interval must be specified\nby the user.\nTo evaluate slowly converging limits and infinite series, mpmath\nautomatically tries Richardson extrapolation and the\nShanks transformation\n(Euler-Maclaurin summation can also be used)~\\cite{BenderOrszag1999}.\nA function to evaluate oscillatory integrals by means of convergence\nacceleration is also available.\n\nA wide array of higher mathematical functions is implemented\nwith full support for complex values of all parameters and arguments,\nincluding complete and incomplete gamma functions,\nBessel functions, orthogonal polynomials, elliptic functions and integrals,\nzeta and polylogarithm functions,\nthe generalized hypergeometric function, and the Meijer G-function.\nThe Meijer G-function instance\n$G_{1, 3}^{3, 0}\\left(0 ; \\tfrac{1}{2}, -1, - \\tfrac{3}{2} \\middle | x \\right)$\nis a good test case~\\cite{Toth2007}; past versions of both Maple and\nMathematica produced incorrect numerical values for large $x > 0$.\nHere, mpmath automatically removes an internal singularity\nand compensates for cancellations (amounting to 656 bits\nof precision when $x = 10000$), giving correct values:\n% doctest printer doesn't display \"mpf\"\n% no-doctest\n\\begin{verbatim}\n>>> mpmath.mp.dps = 15\n>>> mpmath.meijerg([[],[0]], [[-0.5,-1,-1.5],[]], 10000)\nmpf('2.4392576907199564e-94')\n\\end{verbatim}\n\nEquivalently, with SymPy's interface this function can be evaluated as:\n\\begin{verbatim}\n>>> meijerg([[],[0]], [[-S(1)/2,-1,-S(3)/2],[]], 10000).evalf()\n2.43925769071996e-94\n\\end{verbatim}\n\nSymbolic integration and summation often produce hypergeometric\nand Meijer G-function closed forms (see section~\\ref{sec:calculus});\nnumerical evaluation of such special functions is a useful complement\nto direct numerical integration and summation.\n", "meta": {"hexsha": "49562edc791645dee0fff81ffa1af7e136c3fbee", "size": 7173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "numerics.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": "numerics.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": "numerics.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.2774193548, "max_line_length": 107, "alphanum_fraction": 0.7894883591, "num_tokens": 1861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6586643279133066}}
{"text": "\n\\subsection{Algorithmic efficiency}\n\nAn algorithm takes memory and time to run. Analysing these characteristics of algorithms can enable effective choice of algorithms.\n\nComplexity is described using big-O notation. So an algorithm with parameters \\(\\theta \\) would have a time efficiency of \\(O(f(\\theta )\\) where \\(f(\\theta )\\) is a function of \\(\\theta \\).\n\nGenerally we expect \\(f(\\theta )\\) to be weakly increasing for all \\(\\theta \\). As we add additional inputs, these would not decrease the time or space requirements of the algorithm.\n\nAn algorithm which did not change complexity with inputs would have a constant as the largest term. So we would write \\(O(c)\\).\n\nAn algorithm which increase linearly with inputs could be written \\(O(\\theta )\\).\n\nAn algorithm which increased exponentially could be written \\(O(e^\\theta )\\).\n\nComplexity can differ between worst-case scenarios, best-case scenarios and average case scenarios.\n\nWe can describe logical systems by completeness (all true statements are theorems) and soundness (all theorems are true). We have similar definitions for algorithms.\n\nAn algorithm which returns outputs for all possible inputs is complete. An algorithm which never returns an incorrect output is optimal.\n\n", "meta": {"hexsha": "96cfff4db698b16d6ffe032a818ad4faf5b97822", "size": 1243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/optimisationGradientDescent/03-01-newton.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/optimisationGradientDescent/03-01-newton.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/optimisationGradientDescent/03-01-newton.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": 56.5, "max_line_length": 189, "alphanum_fraction": 0.7763475463, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.658664320282533}}
{"text": "\n% \\begin{thm}\n% \t\\label{thm:good_covers_theorem}\n% \tIf $ \\U$, $\\U'$ are \\textbf{good covers} of $ X$ with associated Cech complexes $ \\L^\\bullet(\\U)$ and $ \\L^\\bullet(\\U')$ then\n% \t\\begin{align}\n% \t\tH^i(\\L(\\U)) \\cong  H^i(\\L(\\U'))\n% \t\\end{align}\n% \tfor all $ i \\in \\Z$ i.e. the cohomology of the Cech complex is independent of the good cover and hence is an invariant of the underlying space. Hence, we can define the Cech cohomology of $ X$ as\n% \t\\begin{align}\n% \t\t\\check H^i(X; \\F) :=  H^i(\\L(\\U))\n% \t\\end{align}\n% \tfor any good cover $ \\U$ of $ X$.\n% \\end{thm}\n\n\n\\subsection{Locally Constant Functions}\n\\begin{definition}\n  For a topological space $ X$, let $ \\L(X)$ denote the space of set maps $ f: X \\rightarrow \\F$ which are constant on each connected component of $ X$. Such functions are called \\textbf{locally constant functions}.\\footnote{$\\L$ is an example of a \\textbf{locally constant sheaf}, more on this later. }\n\\end{definition}\n\\begin{ques}\n  Prove that if  $ X$ has $ k$ connected components $ X_1, \\dots, X_k$ then as an $ \\F$ vector space\n  \\begin{align*}\n    \\L(X) \\cong \\F^k\n  \\end{align*}\n  Further, $ \\L(X)$ has a \\textbf{canonical basis} given by functions $ f_1, \\dots, f_k$ defined as\n  \\begin{align*}\n    f_i(X_j) & \\equiv\n    \\begin{cases}\n      1 & \\mbox{ if } i=j \\\\ 0 & \\mbox{ otherwise }\n    \\end{cases}\n  \\end{align*}\n\\end{ques}\n\n\\begin{ques}\n  What is $ \\L(X)$ if $ X$ is the empty set?\n\\end{ques}\n\n\\begin{ques}\n  Show that if we think of $ \\F$ as a disjoint union of two points then $ \\L(X)$ is precisely the space of continuous functions $ X \\rightarrow \\F$. (We'll see later that this is the reason why $\\L$ is a sheaf.)\n\\end{ques}\n\n\n% \\begin{definition}\n%   For a topological space $ X$, let $ \\L(X)$ denote the space of functions $ f: X \\rightarrow \\F$ which are constant on each connected component of $ X$. Such functions are called \\textbf{locally constant functions}.\n% \\end{definition}\n%\n% \\begin{ques}\n%   Show that if we think of $ \\F$ as a disjoint union of two points then $ \\L(X)$ is precisely the space of continuous functions $ X \\rightarrow \\F$.\n% \\end{ques}\n%\n% \\begin{ques}\n%   Prove that if  $ X$ has $ k$ connected components $ X_1, \\dots, X_k$ then as an $ \\F$ vector space\n%   \\begin{align}\n%     \\L(X) \\cong \\F^k\n%   \\end{align}\n%   Further, $ \\L(X)$ has a \\textbf{canonical basis} given by functions $ f_1, \\dots, f_k$ defined as\n%   \\begin{align}\n%     f_i(X_j) &\\equiv\n%     \\begin{cases}\n%       1 & \\mbox{ if } i=j \\\\ 0 & \\mbox{ otherwise }\n%     \\end{cases}\n%   \\end{align}\n% \\end{ques}\n%\n% \\begin{ques}\n%   What is $ \\L(X)$ if $ X$ is the empty set?\n% \\end{ques}\n\n\n\\begin{ques}\n  \\label{q:gluing_diagram}\n  We can construct a 2 holed torus $M^2$ by gluing the sides of an octagon as in Figure \\ref{fig:genus2}. Use the gluing diagram to construct a good cover of $M^2$. Find the cohomology using this good cover.\n\\end{ques}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=11cm]{GluingDiagramHatcher}\n\t\\caption{Constructing a $g$ holed torus $M^g$ using a $4g$-gon. (Image from Hatcher.)}\n  \\label{fig:genus2}\n\\end{figure}\n\\begin{ques}*\n  More generally, it is possible to construct a $g$ holed torus by gluing polygons of $4g$ sides. Repeat Question \\ref{q:gluing_diagram} for this surface.\n\\end{ques}\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=11cm]{Genus2}\n\t\\caption{Gluing diagram for constructing a 2 holed torus $M^2$ using an octagon. (Googled image.)}\n  \\label{fig:genus2}\n\\end{figure}\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.\n  \\begin{figure}[H]\n  \t\\centering\n  \t\\begin{subfigure}[t]{0.4\\textwidth}\n  \t\t\\centering\n  \t\t\\includegraphics[height=3cm]{KleinBottle}\n      \\caption{Klein Bottle}\n  \t\\end{subfigure}\n  \t\\begin{subfigure}[t]{0.59\\textwidth}\n  \t\t\\centering\n  \t\t\\includegraphics[height=3cm]{ProjectivePlane}\n      \\caption{Projective Plane}\n  \t\\end{subfigure}\n  \\end{figure}\n\\end{ques}\n", "meta": {"hexsha": "423c4eefb4809d9d7004a96406ba3e678e1f297d", "size": 4001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dump.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": "dump.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": "dump.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": 36.7064220183, "max_line_length": 303, "alphanum_fraction": 0.664583854, "num_tokens": 1372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744717487329, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.6586643075147383}}
{"text": "\n\n\\subsection{Reduced form equations}\n\nWhere supply is demand.\n\n\\(Q_s=Q_d\\)\n\n\\(\\alpha_1 + \\beta_1P+\\gamma_1I + \\epsilon_1=\\alpha_2 + \\beta_2P+\\gamma_2I + \\epsilon_2\\)\n\n\\((\\alpha_1 -\\alpha_2) + (\\beta_1- \\beta_2)P+(\\gamma_1-\\gamma_2) I + (\\epsilon_1-\\epsilon_2)=0\\)\n\n\n\\((\\beta_1- \\beta_2)P=-(\\alpha_1 -\\alpha_2) - (\\gamma_1-\\gamma_2) I - (\\epsilon_1-\\epsilon_2)\\)\n\n\\(P=-\\dfrac{\\alpha_1 -\\alpha_2}{\\beta_1- \\beta_2} - \\dfrac{\\gamma_1-\\gamma_2}{\\beta_1- \\beta_2} I - \\dfrac{\\epsilon_1-\\epsilon_2}{\\beta_1- \\beta_2}\\)\n\nWe can construct something similar for \\(Q\\). The results are reduced-form parameters with reduced-form errors.\n\n\n\\subsection{More on reduced form}\n\nreduced form for perfect competition, and imperfect\n\nissue is: supply function only defined for perfect competition.\n\nhow do you get equilibrium otherwise? what are the other reduced form equations? strucutral?\n\n", "meta": {"hexsha": "eee9f524d1420afb3ed217b54232df36be316baf", "size": 876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/02-02-reduced.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/02-02-reduced.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/02-02-reduced.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2068965517, "max_line_length": 149, "alphanum_fraction": 0.7146118721, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6586028369686414}}
{"text": "\\section{Paschen's Law}\r\nPaschen's Law applies to the breakdown voltage of a gas between two electrodes. It predicts the minimal voltage required to create an arc. According to Paschen's Law, the breakdown voltage of a gas is dependent mainly on two factors. The first being the pressure $p$ and the second the distance between the electrodes $d$. The breakdown voltage $V_{b}$ is given by the following formula:\r\n%$$V_{b} = \\dfrac{apd}{\\ln \\left(pd\\right) + b}$$", "meta": {"hexsha": "2dfea26fa666c3cad1b0e944a137a2f0a1a3c7b1", "size": 463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Essay/chapters/theory.tex", "max_stars_repo_name": "zpiman/EE", "max_stars_repo_head_hexsha": "7f4c0ed950b0c1695d4358f8c500e86ea918ea3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Essay/chapters/theory.tex", "max_issues_repo_name": "zpiman/EE", "max_issues_repo_head_hexsha": "7f4c0ed950b0c1695d4358f8c500e86ea918ea3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Essay/chapters/theory.tex", "max_forks_repo_name": "zpiman/EE", "max_forks_repo_head_hexsha": "7f4c0ed950b0c1695d4358f8c500e86ea918ea3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 154.3333333333, "max_line_length": 388, "alphanum_fraction": 0.7580993521, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639065, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6586028296459134}}
{"text": "\\subsection*{MATH Library}\n\n\nThe following names are provided by the MATH library:\n\\begin{itemize}\n\\item \\href{https://sourceacademy.org/sicpjs/1.1.4\\#p8}{\\lstinline{math_}$\\textit{name}$},\nwhere $\\textit{name}$ is any name specified in the\nJavaScript\n\\texttt{Math} library, see\\\\\n\\href{https://www.ecma-international.org/ecma-262/9.0/index.html\\#sec-math-object}{\\color{DarkBlue}ECMAScript Specification, Section 20.2}. Examples:\n\\begin{itemize}\n\\item \\verb#math_PI#: \\textit{primitive}, refers to the mathematical constant $\\pi$,\n\\item \\verb#math_sqrt#\\texttt{(n)}: \\textit{primitive}, returns the square root of the \\emph{number} \\texttt{n}.\n\\end{itemize}\n\\end{itemize}\nAll functions can be assumed to run in $O(1)$ time and are considered\n\\textit{primitive}.\n", "meta": {"hexsha": "10eaafb1779beed89d0f973f18fe4b32f5822428", "size": 763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/specs/source_math.tex", "max_stars_repo_name": "parnikkapore/frk_js-slang", "max_stars_repo_head_hexsha": "343bf1eec7e27b5749fad3f82ee9956908c39eef", "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_math.tex", "max_issues_repo_name": "parnikkapore/frk_js-slang", "max_issues_repo_head_hexsha": "343bf1eec7e27b5749fad3f82ee9956908c39eef", "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_math.tex", "max_forks_repo_name": "parnikkapore/frk_js-slang", "max_forks_repo_head_hexsha": "343bf1eec7e27b5749fad3f82ee9956908c39eef", "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": 42.3888888889, "max_line_length": 149, "alphanum_fraction": 0.747051114, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6586028247698337}}
{"text": "\\chapter{Motor selection considerations}\nOne non-obvious matter that differs FOC-enabled motor controllers (like Zubax Komar)\nfrom conventional controllers with trapezoidal or six step commutation\nis so called voltage utilization factor.\nEvery BLDC motor has a characteristic that defines its theoretical maximum rotational speed.\nIt is called  motor speed constant K\\textsubscript{v}.\nIt is measured in revolutions per minute (RPM) per volt or radians per volt second [rad/(V*s)].\nPhysical meaning of this constant is the number of revolutions per minute (rpm) that a motor turns when 1 V (one volt)\nis applied with no load attached to that motor.\n\nFOC-enabled motor controllers have additional voltage utilization factor that decreases the maximum RPM\nfor a given motor and supply voltage. For Komar this factor is:\n\n\\[F\\textsubscript{util} = 0.99\\]\n\\[RPM\\textsubscript{max} = K\\textsubscript{v} \\times V\\textsubscript{supply} \\times F\\textsubscript{util}\\]\n\nRPM\\textsubscript{max} of a FOC enabled motor controller will always be lower than RPM\\textsubscript{max} \nof a conventional controller with trapezoidal or six step commutation. This should be taken into account \nwhen designing a propulsion system.\n\nFor example, a motor with speed constant K\\textsubscript{v} = 320 controlled by Komar\nrunning on fully charged 10S $\\text{LiCoO}_\\text{2}$ battery will have the following theoretical maximum RPM:\n\n\\[RPM\\textsubscript{max} = 320 \\times 10 \\times 4.2 \\times 0.99 = 13305\\]", "meta": {"hexsha": "3c1672c131201889226a5548d0440a0c18fb89ff", "size": 1481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/datasheet/motor_selection.tex", "max_stars_repo_name": "Zubax/Komar", "max_stars_repo_head_hexsha": "d2f3dadf107b29bb862aeee7b75df1b84a15693c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-16T02:44:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:12:05.000Z", "max_issues_repo_path": "docs/datasheet/motor_selection.tex", "max_issues_repo_name": "Zubax/Komar", "max_issues_repo_head_hexsha": "d2f3dadf107b29bb862aeee7b75df1b84a15693c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2020-04-13T11:16:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-01T17:31:09.000Z", "max_forks_repo_path": "docs/datasheet/motor_selection.tex", "max_forks_repo_name": "Zubax/Komar", "max_forks_repo_head_hexsha": "d2f3dadf107b29bb862aeee7b75df1b84a15693c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-15T12:58:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-17T11:03:47.000Z", "avg_line_length": 61.7083333333, "max_line_length": 118, "alphanum_fraction": 0.7947332883, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6585633847320527}}
{"text": "\\begin{definition}~\n\t\\begin{itemize}\n\t\t\\item $ \\mathbb{A} $ is the set of \\emph{names}\n\t\t\\item $ \\overline{\\mathbb{A}} = \\left\\lbrace\\overline{a}\\middle\\vert a\\in\\mathbb{A}\\right\\rbrace $ is the set of \\emph{co-names}\n\t\t\\item $ \\mathbb{L}=\\mathbb{A}\\cup\\overline{\\mathbb{A}} $ is the set of \\emph{labels}\n\t\t\\item $ \\act = \\mathbb{L}\\cup\\{\\tau\\} $ is the set of \\emph{actions}, where $ \\tau $ is the \\emph{internal}(or \\emph{silent}) action\n\t\t\\item $ \\overline{\\overline{a}} = a $\n\t\t\\item A function $ f:\\act\\rightarrow\\act $ is a \\emph{relabelling function} if $ f(\\tau)=\\tau $ and $ f(\\overline{a}) = \\overline{f(a)} $\n\t\t\\item $ \\mathcal{P} $ is the set of all CCS expressions\n\t\t\\item $ \\mathbb{K} $ is the set of all constants\n\t\\end{itemize}\n\\end{definition}\n\\subsection*{Syntax of CCS expressions}\n\\begin{align*}\nP:=&K&\\text{constant} (K\\in\\mathbb{K})\\\\\n&\\alpha.P&\\text{prefixing}(\\alpha\\in\\act)\\\\\n&\\sum_{i\\in I}P_i&\\text{summation}\\\\\n&P\\vert Q&\\text{parallel composition}\\\\\n&P\\backslash L&\\text{restriction}(L\\subseteq \\mathbb{A})\\\\\n&P[f]&\\text{relabelling}(f:\\act\\rightarrow\\act)\n\\end{align*}\n\\subsection*{Notation}\n\\begin{itemize}\n\t\\item $ P_1+P_2=\\sum_{i\\in\\{1,2\\}}P_i $\n\t\\item $ 0 = \\sum_{i\\in\\emptyset}P_i $\n\\end{itemize}\n\\subsection*{Precedence of operators}\n\\begin{enumerate}\n\t\\item Restriction and relabelling\n\t\\item Action prefixing\n\t\\item parallel composition\n\t\\item summation\n\\end{enumerate}\n\\subsection*{SOS Rules for CCS}\n\\begin{align*}\n&(ACT)\\dfrac{}{\\alpha.P\\xrightarrow{\\alpha}P}\n&(SUM_j)\\dfrac{P_j\\xrightarrow{\\alpha}P_j'}{\\sum_{i\\in I}P_i\\xrightarrow{\\alpha}P_j'}\\text{where } j\\in I\\\\\n&(COM1)\\dfrac{P\\xrightarrow{\\alpha}P'}{P\\vert Q\\xrightarrow{\\alpha}P'\\vert Q}\n&(COM2)\\dfrac{Q\\xrightarrow{\\alpha}Q'}{P\\vert Q\\xrightarrow{\\alpha}P\\vert Q'}\\\\\n&(COM3)\\dfrac{P\\xrightarrow{a}P'~~Q\\xrightarrow{\\overline{a}}Q'}{P\\vert Q\\xrightarrow{\\tau}P'\\vert Q'}\n&(RES)\\dfrac{P\\xrightarrow{\\alpha}P'}{P\\backslash L\\xrightarrow{\\alpha}P'\\backslash L}\\text{where } a,\\overline{a}\\notin L\\\\\n&(REL)\\dfrac{P\\xrightarrow{\\alpha}P'}{P[f]\\xrightarrow{f(\\alpha)}P'[f]}\n&(CON)\\dfrac{P\\xrightarrow{\\alpha}P'}{K\\xrightarrow{\\alpha}P'}\\text{where }K\\definedby P\n\\end{align*}", "meta": {"hexsha": "f6eb905e387b04c64da11219888a8074e5bd49b2", "size": 2167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modeling and Verification - Reference/CCS.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Modeling and Verification - Reference/CCS.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modeling and Verification - Reference/CCS.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 49.25, "max_line_length": 139, "alphanum_fraction": 0.682510383, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6585576019925345}}
{"text": "%!TEX root = ../TTT4150-Summary.tex\n\\section{Precise positioning with carrier phase}\nCode measurement accuracy tops out at the meter level. Precise positioning with carrier phase measurements, can achieve centimeter-level accuracy.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Carrier phase and integer ambiguity resolution: A simple model}\nTwo antennas receive the same carrier signal. It's off by $N$ full cycles, and a partial cycle. The partial cycle (phase shift) can be measured, but we don't know $N$. This gives integer ambiguity.\n\nIf we wait for the satellite to move a bit and measure again, we have two equations in two unknowns, and can solve for $N$. Satellite geometry change is essential for the quality of the estimates.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Precise point positioning (PPP)}\n\nPPP is centimeter-level positioning without a reference station, based on precise estimation of all significant error sources. The necessary orbit data is available in various latencies and accuracies. Near real-time is possible, but you get better accuracy if you wait a while.\n\nThe errors we must estimate are:\n\\begin{itemize}\n    \\item Satellite ephemeris and clock error: You can get these from IGS.\n    \\item Ionospheric delay: Eliminate with dual-frequency measurements.\n    \\item Tropospheric delay: Must estimate.\n    \\item Multipath and receiver noise: At least no reference station multipath error now.\n    \\item Phase wind-up correction: Antenna rotation (rover or satellite) will change the carrier phase.\n    \\item Satellite antenna offsets: Orbit models give position of satellite mass center, but pseudorange measurements refer to the antenna phase center.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Carrier phase integer ambiguity}\nAs mentioned, carrier phase has an integer ambiguity. This integer can be fixed.\n\n\\subsubsection{Using code measurements to estimate integers}\nWe can use the code measurement to estimate the carrier integer. But it's hard to use the fairly coarse code pseudorange to estimate this, and you need to average codes over a long time horizon to get a good enough estimate. Therefore, it doesn't really work.\n", "meta": {"hexsha": "e8f2f0642bbf79e3ba062580fc0539653c56241b", "size": 2270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTT4150 Navigation systems/tex/7-precise-positioning.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/7-precise-positioning.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/7-precise-positioning.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": 70.9375, "max_line_length": 278, "alphanum_fraction": 0.7299559471, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.658557599801291}}
{"text": "\\chapter{Markov chain Monte Carlo (MCMC)inference}\n\n\n\\section{Introduction}\nIn Chapter \\ref{chap:Monte-Carlo-inference}, we introduced some simple Monte Carlo methods, including rejection sampling and importance sampling. The trouble with these methods is that they do not work well in high dimensional spaces. The most popular method for sampling from high-dimensional distributions is \\textbf{Markov chain Monte Carlo} or \\textbf{MCMC}.\n\nThe basic idea behind MCMC is to construct a Markov chain (Section \\ref{sec:Markov-models}) on the state space $\\mathcal{X}$ whose stationary distribution is the target density $p^*(\\vec{x})$ of interest (this may be a prior or a posterior). That is, we perform a random walk on the state space, in such a way that the fraction of time we spend in each state $\\vec{x}$ is proportional to $p^*(\\vec{x})$. By drawing (correlated!) samples $\\vec{x}_0, \\vec{x}_1, \\vec{x}_2, \\cdots$ from the chain, we can perform Monte Carlo integration wrt $p^*$.\n\n\n\\section{Metropolis Hastings algorithm}\n\n\n\\section{Gibbs sampling}\n\n\n\\section{Speed and accuracy of MCMC}\n\n\n\\section{Auxiliary variable MCMC *}\n\n", "meta": {"hexsha": "767062813fa34a92c146c34cf618b2f0d3068c15", "size": 1132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterMCMC.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/chapterMCMC.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/chapterMCMC.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 53.9047619048, "max_line_length": 544, "alphanum_fraction": 0.7623674912, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6585480993831782}}
{"text": "%!TEX root=report.tex\n\n\\subsection{Time series analysis - ARIMA}\n\\label{section:result-ts}\n\nTo get an indication of whether its possible to use time series analysis on the GRACE data, a single position (63.5 N 49.5 W, west coast of Greenland) has been selected.\n\nTo analyze the data using an ARIMA model an equidistant dataset is required. For example it would otherwise not be possible to solve the Yule-Walker equations \\cite[s.~122]{time-series-analysis}. In the original GRACE dataset some values are missing, thus they should be interpolated (linear interpolation was used). Also in order to get an indication of the model performance, the last 36 observations (corresponding to one year) have been separated for model validation.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[height=5cm]{figures/ts-initial-split}\n\\caption{GRACE data at 63.5 N 49.5 W, where missing values are interpolated. Blue is the training data and green is the  test data.}\n\\label{fig:ts-initial-split}\n\\end{figure}\n\nThe time series in Figure \\ref{fig:ts-initial-split} is clearly not stationary, thus it is necessary to consider the time series difference.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm]{figures/ts-residual-i1s0}\n\t\\caption{The ARIMA$(0,1,0) \\times (0,0,0)_{36}$ residuals.}\n\t\\label{fig:ts-residual-i1s0}\n\\end{figure}\nOn Figure \\ref{fig:ts-residual-i1s0} there are some seasonal periods where the mean and variance are not the same as the remaining period, thus it is not completely stationary. Taking also the seasonal difference (assuming the season is 36 observations, a year) gives however a very stationary output.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm]{figures/ts-residual-i1s1}\n\t\\caption{The ARIMA$(0,1,0) \\times (0,1,0)_{36}$ residuals.}\n\t\\label{fig:ts-residual-i1s1}\n\\end{figure}\nOn Figure \\ref{fig:ts-residual-i1s1} its seen that the first 37 observations act strange, this is because there aren't enough past observations to estimate the EWH correctly, thus they should be excluded from further analysis.\n\nTo determine the AR and MA terms in the ARIMA model, the ACF and PACF should be estimated using the residuals from Figure \\ref{fig:ts-residual-i1s1}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/ts-acf-ar0s0}\n\t\\caption{ACF and PACF for ARIMA$(0,1,0) \\times (0,1,0)_{36}$ residuals}\n\t\\label{fig:ts-acf-ar0s0}\n\\end{figure}\n\nUsing the PACF in Figure \\ref{fig:ts-acf-ar0s0} and the rules for the AR term \\cite[Table~6.1]{time-series-analysis} \\texttt{AR(2)}, seams like a good guess for the non-seasonal AR term.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/ts-acf-ar2s0}\n\t\\caption{ACF and PACF for ARIMA$(2,1,0) \\times (0,1,0)_{36}$ residuals}\n\t\\label{fig:ts-acf-ar2s0}\n\\end{figure}\n\nThis clearly fitted the non-seasonal trend. From Figure \\ref{fig:ts-acf-ar0s0} it might have looked like there was a \\texttt{AR(3)} or \\texttt{MA(2)} term, but the \\texttt{AR(2)} is the simplest of those and fit the trend just fine. The seasonal part is now extremely apparent in Figure \\ref{fig:ts-acf-ar2s0}, where it looks like either a \\texttt{SAR(2)}- or a \\texttt{SAR(1)}-term.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/ts-acf-ar2s2}\n\t\\caption{ACF and PACF for ARIMA$(2,1,0) \\times (2,1,0)_{36}$ residuals}\n\t\\label{fig:ts-acf-ar2s2}\n\\end{figure}\n\nFrom just looking at the estimated ACF and PACF in Figure \\ref{fig:ts-acf-ar2s2}, ARIMA$(2,1,0) \\times (2,1,0)_{36}$ seems like a good choice. To finally validate the model, a good start is to look at the residuals.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm]{figures/ts-final-residual}\n\t\\caption{ARIMA$(2,1,0) \\times (2,1,0)_{36}$ residuals. The first 111 residuals have been skipped since they cannot be estimated correctly.}\n\t\\label{fig:ts-final-residual}\n\\end{figure}\n\nFigure \\ref{fig:ts-final-residual} looks stationary, there are no outliers nor seasonal trends. To validate the model further the Ljung-Box test can be used. This however requires the residuals to be normally distributed, a QQ-plot (Figure \\ref{fig:ts-final-qq}) shows that this is the case:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm]{figures/ts-final-qq}\n\t\\caption{QQ-plot for the ARIMA$(2,1,0) \\times (2,1,0)_{36}$ residuals.}\n\t\\label{fig:ts-final-qq}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm]{figures/ts-final-ljungbox}\n\t\\caption{Ljung-Box test for the ARIMA$(2,1,0) \\times (2,1,0)_{36}$ residuals.}\n\t\\label{fig:ts-final-ljungbox}\n\\end{figure}\n\nFrom the Ljung-Box test (Figure \\ref{fig:ts-final-ljungbox}) the p-value for the first many lags looks good, however after 25 it can be with 95\\% confidence statically significant concluded that the residuals are correlated. In terms of pure time series analysis is makes the model quite useless, however it is still valuable to do the cross validation.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\centerline{\\includegraphics[height=6cm]{figures/ts-final-forecast}}\n\t\\caption{Forecast on Cross Validation. Blue is the training data, green is the test data. Red is then the predicted test values with its 95\\% confidence interval marked with gray lines.}\n\t\\label{fig:ts-final-forecast}\n\\end{figure}\n\nFrom Figure \\ref{fig:ts-final-forecast} it quite clear that the test data is consistently bellow the expectation line (red). While it is still inside the 95\\% confidence interval, this high correlation in the error between lags indicates that the model is not particular useful. \n", "meta": {"hexsha": "5981de5687ece80de619029d46e45a58d86b7877", "size": 5527, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/result-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/result-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/result-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": 60.7362637363, "max_line_length": 472, "alphanum_fraction": 0.7604487064, "num_tokens": 1638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6585168509389577}}
{"text": "\\section{Introduction}\n\\label{sec:introduction}\n\nThe Rosenblatt Perceptron \\cite{rosenblatt1958perceptron} is a device designed to solve a binary classification problem, i.e. the problem of choosing the correct class for given examples, represented as feature vectors.\nThe perceptron needs to be trained on some training examples in order to determine the best hyperplane to separate them:\nhopefully, the learned hyperplane will be able to correctly classify also new points.\n\nIn this work, we implement and train a Rosenblatt Perceptron and run some computer simulations to verify its theoretical properties.\nIn particular, we try to estimate the capacity of the separation hyperplane learned by the perceptron.\n", "meta": {"hexsha": "c2d5e9ed0adfc9ce08523016657bdb02c7b6e252", "size": 713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/report/01_introduction.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/report/01_introduction.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/report/01_introduction.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": 71.3, "max_line_length": 219, "alphanum_fraction": 0.8260869565, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6585168412820094}}
{"text": "\\chapter{The long exact sequence}\nIn this chapter we introduce the key fact about chain complexes that will allow us to compute\nthe homology groups of any space: the so-called ``long exact sequence''.\n\nFor those that haven't read about abelian categories:\na sequence of morphisms of abelian groups\n\\[ \\dots \\to G_{n+1} \\to G_n \\to G_{n-1} \\to \\dots \\]\nis \\vocab{exact} if the image of any arrow is equal to the kernel of the next arrow.\nIn particular,\n\\begin{itemize}\n\t\\ii The map $0 \\to A \\to B$ is exact if and only if $A \\to B$ is injective.\n\t\\ii the map $A \\to B \\to 0$ is exact if and only if $A \\to B$ is surjective.\n\\end{itemize}\n(On that note: what do you call a chain complex whose homology groups are all trivial?)\nA short exact sequence is one of the form $0 \\to A \\injto B \\surjto C \\to 0$.\n\n\\section{Short exact sequences and four examples}\n\\prototype{Relative sequence and Mayer-Vietoris sequence.}\nLet $\\AA = \\catname{AbGrp}$.\nRecall that we defined a morphism of chain complexes in $\\AA$ already.\n\\begin{definition}\nSuppose we have a map of chain complexes\n\\[ 0 \\to A_\\bullet \\taking f B_\\bullet \\taking g C_\\bullet \\to 0 \\]\nIt is said to be \\vocab{short exact} if \\emph{each row} of the diagram below is short exact.\n\\begin{diagram}\n\t&& \\vdots && \\vdots && \\vdots && \\\\\n\t&& \\dTo^{\\partial_A} && \\dTo^{\\partial_B} && \\dTo^{\\partial_C} && \\\\\n\t0 & \\rTo & A_{n+1} & \\rInj^{f_{n+1}} & B_{n+1} & \\rSurj^{g_{n+1}} & C_{n+1} & \\rTo & 0 \\\\\n\t&& \\dTo^{\\partial_A} && \\dTo^{\\partial_B} && \\dTo^{\\partial_C} && \\\\\n\t0 & \\rTo & A_n & \\rInj^{f_n} & B_n & \\rSurj^{g_n} & C_n & \\rTo & 0 \\\\\n\t&& \\dTo^{\\partial_A} && \\dTo^{\\partial_B} && \\dTo^{\\partial_C} && \\\\\n\t0 & \\rTo & A_{n-1} & \\rInj^{f_{n-1}} & B_{n-1} & \\rSurj^{g_{n-1}} & C_{n-1} & \\rTo & 0 \\\\\n\t&& \\dTo^{\\partial_A} && \\dTo^{\\partial_B} && \\dTo^{\\partial_C} && \\\\\n\t&& \\vdots && \\vdots && \\vdots &&\n\\end{diagram}\n\\end{definition}\n\n\\begin{example}\n\t[Mayer-Vietoris short exact sequence and its augmentation]\n\t\\label{ex:mayer_short_exact}\n\tLet $X = U \\cup V$ be an open cover.\n\tFor each $n$ consider\n\t\\begin{diagram}\n\t\tC_n(U \\cap V) & \\rInj & C_n(U) \\oplus C_n(V) & \\rSurj & C_n(U + V) \\\\\n\t\tc & \\rMapsto & (c, -c) && \\\\\n\t\t&& (c, d) & \\rMapsto & c + d\n\t\\end{diagram}\n\tOne can easily see (by taking a suitable basis)\n\tthat the kernel of the latter map is exactly\n\tthe image of the first map.\n\tThis generates a short exact sequence\n\t\\[ 0 \\to  C_\\bullet(U \\cap V) \\injto C_\\bullet(U) \\oplus C_\\bullet(V)\n\t\\surjto C_\\bullet(U + V) \\to 0. \\]\n\\end{example}\n\\begin{example}\n\t[Augmented Mayer-Vietoris sequence]\n\tWe can \\emph{augment} each of the chain complexes in the Mayer-Vietoris\n\tsequence as well, by appending\n\t\\begin{diagram}\n\t\t0 & \\rTo & C_0(U \\cap V) & \\rInj & C_0(U) \\oplus C_0(V) & \\rSurj & C_0(U+V) & \\rTo & 0\\\\\n\t\t&& \\dSurj^{\\eps} && \\dSurj^{\\eps \\oplus \\eps} && \\dTo^\\eps && \\\\\n\t\t0 & \\rTo & \\ZZ & \\rTo & \\ZZ \\oplus \\ZZ & \\rTo & \\ZZ & \\rTo & 0\n\t\\end{diagram}\n\tto the bottom of the diagram.\n\tIn other words we modify the above into\n\t\\[ 0 \\to  \\wt C_\\bullet(U \\cap V) \n\t\t\\injto \\wt C_\\bullet(U) \\oplus \\wt C_\\bullet(V) \n\t\t\\surjto \\wt C_\\bullet(U + V) \\to 0 \\]\n\twhere $\\wt C_\\bullet$ is the chain complex defined in \\Cref{def:augment}.\n\\end{example}\n\n\\begin{example}\n\t[Relative chain short exact sequence]\n\t\\label{ex:rel_short_exact}\n\tSince $C_n(X,A) \\defeq C_n(X) / C_n(A)$, we have a short exact sequence\n\t\\[ 0 \\to C_\\bullet(A) \\injto C_\\bullet(X) \\surjto C_\\bullet(X,A) \\to 0 \\]\n\tfor every space $X$ and subspace $A$.\n\t%The maps for each $n$ are the obvious ones:\n\t%$C_n(A) \\injto C_n(X)$ inclusion and $C_n(X) \\surjto C_n(X,A)$ projection.\n\tThis can be augmented: we get\n\t\\[ 0 \\to \\wt C_\\bullet(A) \\injto \\wt C_\\bullet(X)\n\t\t\\surjto C_\\bullet(X,A) \\to 0 \\]\n\tby adding the final row\n\t\\begin{diagram}\n\t\t0 & \\rTo & C_0(A) & \\rInj & C_0(X) & \\rSurj & C_0(X,A) & \\rTo & 0\\\\\n\t\t&& \\dSurj^{\\eps} && \\dSurj^{\\eps} && \\dTo && \\\\\n\t\t0 & \\rTo & \\ZZ & \\rTo_\\id & \\ZZ & \\rTo & 0 & \\rTo & 0.\n\t\\end{diagram}\n\\end{example}\n\n\\section{The long exact sequence of homology groups}\nConsider a short exact sequence $0 \\to A_\\bullet \\taking f B_\\bullet \\taking g C_\\bullet \\to 0$.\nNow, we know that we get induced maps of homology groups, i.e.\\ we have\n\\begin{diagram}\n\t\\vdots && \\vdots && \\vdots  \\\\\n\tH_{n+1}(A_\\bullet) & \\rTo^{f_\\ast} & H_{n+1}(B_\\bullet) & \\rTo^{g_\\ast} & H_{n+1}(C_\\bullet) \\\\\n\tH_{n}(A_\\bullet) & \\rTo^{f_\\ast} & H_{n}(B_\\bullet) & \\rTo^{g_\\ast} & H_{n}(C_\\bullet) \\\\\n\tH_{n-1}(A_\\bullet) & \\rTo^{f_\\ast} & H_{n-1}(B_\\bullet) & \\rTo^{g_\\ast} & H_{n-1}(C_\\bullet) \\\\\n\t\\vdots && \\vdots && \\vdots \\\\\n\\end{diagram}\nBut the theorem is that we can string these all together,\ntaking each $H_{n+1}(C_\\bullet)$ to $H_n(A_\\bullet)$.\n\n\\begin{theorem}[Short exact $\\implies$ long exact]\n\t\\label{thm:long_exact}\n\tLet $0 \\to A_\\bullet \\taking f B_\\bullet \\taking g C_\\bullet \\to 0$ \n\tbe \\emph{any} short exact sequence of chain complexes we like.\n\tThen there is an \\emph{exact} sequence\n\t\\begin{diagram}\n\t\t&& \\dots & \\rTo & H_{n+2}(C_\\bullet) \\\\\n\t\tH_{n+1}(A_\\bullet) & \\rTo_{f_\\ast} &\n\t\tH_{n+1}(B_\\bullet) & \\ldTo(4,1)~\\partial \\rTo^{g_\\ast} & H_{n+1}(C_\\bullet) \\\\\n\t\tH_{n}(A_\\bullet) & \\rTo_{f_\\ast} &\n\t\tH_{n}(B_\\bullet) & \\rTo^{g_\\ast} \\ldTo(4,1)~{\\partial} & H_{n}(C_\\bullet) \\\\\n\t\tH_{n-1}(A_\\bullet) & \\rTo_{f_\\ast} &\n\t\tH_{n-1}(B_\\bullet) & \\rTo^{g_\\ast} \\ldTo(4,1)~{\\partial} & H_{n-1}(C_\\bullet) \\\\\n\t\tH_{n-2}(A_\\bullet) & \\rTo & \\dots & \\ldTo(4,1)~\\partial & \n\t\\end{diagram}\n\tThis is called a \\vocab{long exact sequence} of homology groups.\n\\end{theorem}\n\\begin{proof}\n\tA very long diagram chase, valid over any abelian category.\n\t(Alternatively, it's actually possible to use the snake lemma twice.)\n\\end{proof}\n\n\\begin{remark}\n\t\\label{rem:leftdownleft}\n\tThe map $\\partial : H_n(C_\\bullet) \\to H_{n-1}(A_\\bullet)$ can be written explicitly as follows.\n\tRecall that $H_n$ is ``cycles modulo boundaries'', and consider the sub-diagram\n\t\\begin{diagram}\n\t&& B_n & \\rSurj^{g_n} & C_n \\\\\n\t && \\dTo^{\\partial_B} && \\dTo_{\\partial_C} \\\\\n\tA_{n-1} & \\rInj^{f_{n-1}} & B_{n-1} & \\rSurj_{g_{n-1}} & C_{n-1} \\\\\n\t\\end{diagram}\n\tWe need to take every cycle in $C_n$ to a cycle in $A_{n-1}$.\n\t(Then we need to check a ton of ``well-defined'' issues,\n\tbut let's put that aside for now.)\n\n\tSuppose $c \\in C_n$ is a cycle (so $\\partial_C(c) = 0$).\n\tBy surjectivity, there is a $b \\in B_n$ with $g_n(b) = c$,\n\twhich maps down to $\\partial_B(b)$.\n\tNow, the image of $\\partial_B(b)$ under $g_{n-1}$ is zero by commutativity of the square,\n\tand so we can pull back under $f_{n-1}$ to get a unique element of $A_{n-1}$\n\t(by exactness at $B_{n-1}$).\n\n\tIn summary: we go ``\\emph{left, down, left}'' to go from $c$ to $a$:\n\t\\begin{diagram}\n\t\t&& b & \\rMapsto^{g_n} & \\boxed c \\\\\n\t\t&& \\dMapsto^{\\partial_B} && \\dMapsto_{\\partial_C} \\\\\n\t\t\\boxed a & \\rMapsto^{f_{n-1}} & \\partial_B(b) & \\rMapsto_{g_{n-1}} & 0\n\t\\end{diagram}\n\\end{remark}\n\\begin{exercise}\n\tCheck quickly that the recovered $a$ is actually a cycle,\n\tmeaning $\\partial_A(a) = 0$.\n\t(You'll need another row, and the fact that $\\partial_B^2 = 0$.)\n\\end{exercise}\n\nThe final word is that:\n\\begin{moral}\n\tShort exact sequences of chain complexes give\n\tlong exact sequences of homology groups.\n\\end{moral}\nIn particular, let us take the four examples given earlier.\n\\begin{example}[Mayer-Vietoris long exact sequence, provisional version]\n\tThe Mayer-Vietoris ones give, for $X = U \\cup V$ an open cover,\n\t\\[ \\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. \\]\n\tand its reduced version\n\t\\[ \\dots \\to \\wt H_n(U \\cap V) \\to \\wt H_n(U) \\oplus \\wt H_n(V)\n\t\\to \\wt H_n(U+V) \\to \\wt H_{n-1}(U \\cap V) \\to \\dots. \\]\n\\end{example}\nThis version is ``provisional'' because in the next section\nwe will replace $H_n(U+V)$ and $\\wt H_n(U+V)$ with something better.\nAs for the relative homology sequences, we have:\n\\begin{theorem}[Long exact sequence for relative homology]\n\t\\label{thm:long_exact_rel}\n\tLet $X$ be a space, and let $A \\subseteq X$ be a subspace.\n\tThere are long exact sequences\n\t\\[ \\dots \\to H_n(A) \\to H_n(X) \\to H_n(X,A) \\to H_{n-1}(A) \\to \\dots. \\]\n\tand\n\t\\[ \\dots \\to \\wt H_n(A) \\to \\wt H_n(X) \\to H_n(X,A) \\to \\wt H_{n-1}(A) \\to \\dots. \\]\n\\end{theorem}\nThe exactness of these sequences will give \\textbf{tons of information}\nabout $H_n(X)$ if only we knew something about what $H_n(U+V)$\nor $H_n(X,A)$ looked like.  This is the purpose of the next chapter.\n\n\\section{The Mayer-Vietoris sequence}\n\\prototype{The computation of $H_n(S^m)$ by splitting $S^m$ into two hemispheres.}\n\nNow that we have done so much algebra, we need to invoke some geometry.\nThere are two major geometric results in the Napkin.\nOne is the excision theorem, which we discuss next chapter.\nThe other we present here, which will let us take advantage of the\nMayer-Vietoris sequence.\nThe proofs are somewhat involved and are thus omitted;\nsee \\cite{ref:hatcher} for details.\n\nThe first theorem is that the notation $H_n(U+V)$ that we have kept until now\nis redundant, and can be replaced with just $H_n(X)$:\n\\begin{theorem}[Open cover homology theorem]\n\t\\label{thm:open_cover_homology}\n\tConsider the inclusion $\\iota : C_\\bullet(U+V) \\injto C_\\bullet(X)$.\n\tThen $\\iota$ induces an isomorphism\n\t\\[ H_n(U+V) \\cong H_n(X). \\]\n\t% Then there exists a $\\rho : C_\\bullet(X) \\to C_\\bullet(U+V)$ such that\n\t% $\\rho\\iota$ and $\\iota\\rho$ are chain homotopic to the identities.\n\t% Thus $\\iota$ induces an isomorphism\n\\end{theorem}\n\\begin{remark}\n\tIn fact, this is true for any open cover (even uncountable),\n\tnot just those with two covers $U \\cup V$.\n\tBut we only state the special case with two open sets,\n\tbecause this is what is needed for \\Cref{ex:mayer_short_exact}.\n\\end{remark}\nSo, \\Cref{ex:mayer_short_exact} together with the above theorem implies,\nafter replacing all the $H_n(U+V)$'s with $H_n(X)$'s:\n\\begin{theorem}[Mayer-Vietoris long exact sequence]\n\tIf $X = U \\cup V$ is an open cover, then we have long exact sequences\n\t\\[ \\dots \\to H_n(U \\cap V) \\to H_n(U) \\oplus H_n(V)\n\t\t\\to H_n(X) \\to H_{n-1}(U \\cap V) \\to \\dots. \\]\n\tand\n\t\\[ \\dots \\to \\wt H_n(U \\cap V) \\to \\wt H_n(U) \\oplus \\wt H_n(V) \\to\n\t\t\\wt H_n(X) \\to \\wt H_{n-1}(U \\cap V) \\to \\dots. \\]\n\\end{theorem}\n\nAt long last, we can compute the homology groups of the spheres.\n\\begin{theorem}[The homology groups of $S^m$]\n\t\\label{thm:reduced_homology_sphere}\n\tFor integers $m$ and $n$,\n\t\\[ \\wt H_n(S^m) \\cong\n\t\\begin{cases}\n\t\t\\ZZ & n=m \\\\\n\t\t0 & \\text{otherwise}.\n\t\\end{cases}\n\t\\]\n\tThe generator $\\wt H_n(S^n)$ is an $n$-cell which covers $S^n$\n\texactly once (for example, the generator for $\\wt H_1(S^1)$\n\tis a loop which wraps around $S^1$ once).\n\\end{theorem}\n\\begin{proof}\n\tThis one's fun, so I'll only spoil the case $m=1$, and leave the rest to you.\n\tDecompose the circle $S^1$ into two arcs $U$ and $V$, as shown:\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(4cm);\n\t\t\tdraw(unitcircle);\n\t\t\tlabel(\"$S^1$\", dir(45), dir(45));\n\t\t\treal R = 0.1;\n\t\t\tdraw(arc(origin,1-R,-100,100), red+1);\n\t\t\tlabel(\"$V$\", (1-R)*dir(0), dir(180), red);\n\t\t\tdraw(arc(origin,1+R,80,280), blue+1);\n\t\t\tlabel(\"$U$\", (1+R)*dir(180), dir(180), blue);\n\t\t\\end{asy}\n\t\\end{center}\n\tEach of $U$ and $V$ is contractible, so all their reduced homology groups vanish.\n\tMoreover, $U \\cap V$ is homotopy equivalent to two points,\n\thence \n\t\\[ \\wt H_n(U \\cap V) \\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ & n = 0 \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\tNow consider again the segment of the short exact sequence\n\t\\[ \n\t\t\\dots \\to\n\t\t\\underbrace{\\wt H_n(U) \\oplus \\wt H_n(V)}_{= 0} \\to\n\t\t\\wt H_n(S^1) \\taking{\\partial} \\wt H_{n-1}(U \\cap V) \\to\n\t\t\\underbrace{\\wt H_{n-1}(U) \\oplus \\wt H_{n-1}(V)}_{=0} \\to \\dots.\n\t\\]\n\tFrom this we derive that $\\wt H_n(S^1)$ is $\\ZZ$ for $n=1$ and $0$ elsewhere.\n\n\tIt remains to analyze the generators of $\\wt H_1(S^1)$.\n\tNote that the isomorphism was given by the connecting homomorphism $\\partial$,\n\twhich is given by a ``left, down, left'' procedure (\\Cref{rem:leftdownleft})\n\tin the diagram\n\t\\begin{diagram}\n\t\t&& C_1(U) \\oplus C_1(V) & \\rTo & C_1(U+V) \\\\\n\t\t&& \\dTo^{\\partial \\oplus \\partial} && \\\\\n\t\tC_0(U \\cap V) & \\rTo & C_0(U) \\oplus C_0(V). &&\n\t\\end{diagram}\n\tMark the points $a$ and $b$ as shown in the two disjoint paths of $U \\cap V$.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(3cm);\n\t\t\tlabel(\"$S^1$\", dir(45), dir(45));\n\t\t\treal R = 0.1;\n\t\t\t/*\n\t\t\tdraw(arc(origin,1-R,-100,100), red+1);\n\t\t\tlabel(\"$V$\", (1-R)*dir(0), dir(180), red);\n\t\t\tdraw(arc(origin,1+R,80,280), blue+1);\n\t\t\tlabel(\"$U$\", (1+R)*dir(180), dir(180), blue);\n\t\t\t*/\n\t\t\tdot(\"$a$\", dir(90), dir(90));\n\t\t\tdot(\"$b$\", dir(-90), dir(-90));\n\t\t\tdraw(arc(origin,1,90,270), EndArrow, Margins);\n\t\t\tdraw(arc(origin,1,90,-90), EndArrow, Margins);\n\t\t\tlabel(\"$c$\", dir(180), dir(180));\n\t\t\tlabel(\"$d$\", dir(0), dir(0));\n\t\t\\end{asy}\n\t\\end{center}\n\tThen $a-b$ is a cycle which represents a generator of $H_0(U \\cap V)$.\n\tWe can find the pre-image of $\\partial$ as follows:\n\tletting $c$ and $d$ be the chains joining $a$ and $b$, with $c$ contained\n\tin $U$, and $d$ contained in $V$, the diagram completes as\n\t\\begin{diagram}\n\t\t&& (c,d) & \\rMapsto & c-d \\\\\n\t\t&& \\dMapsto && \\\\\n\t\ta-b & \\rMapsto & (a-b, a-b) &&\n\t\\end{diagram}\n\tIn other words $\\partial(c-d) = a-b$, so $c-d$ is a generator for $\\wt H^1(S^1)$.\n\t\n\tThus we wish to show that $c-d$ is (in $H^1(S^1)$) equivalent to the loop $\\gamma$\n\twrapping around $S^1$ once, counterclockwise.\n\tThis was illustrated in \\Cref{ex:S1_c_minus_d}.\n\\end{proof}\n\nThus, the key idea in Mayer-Vietoris is that\n\\begin{moral}\n\tMayer-Vietoris lets us compute $H_n(X)$\n\tby splitting $X$ into two open sets.\n\\end{moral}\n\nHere are some more examples.\n\\begin{proposition}[The homology groups of the figure eight]\n\tLet $X = S^1 \\wedge S^1$ be the figure eight.\n\tThen\n\t\\[\n\t\t\\wt H_n(X) \\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ^{\\oplus 2} & n = 1 \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\tThe generators for $\\wt H_1(X)$ are the two loops of the figure eight.\n\\end{proposition}\n\\begin{proof}\n\tAgain, for simplicity we work with reduced homology groups.\n\tLet $U$ be the ``left'' half of the figure eight plus a little bit of the right,\n\tas shown below.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(4cm);\n\t\t\tdraw(unitcircle);\n\t\t\tdraw(CR(2*dir(180),1), blue+2);\n\t\t\tdraw(arc(origin,1,135,225), blue+2);\n\t\t\tlabel(\"$U$\", 2*dir(180)+dir(135), dir(135), blue);\n\t\t\tlabel(\"$S^1 \\wedge S^1$\", dir(15), dir(15));\n\t\t\\end{asy}\n\t\\end{center}\n\tThe set $V$ is defined symmetrically.\n\tIn this case $U \\cap V$ is contractible, while each of $U$ and $V$\n\tis homotopic to $S^1$.\n\n\tThus, we can read a segment of the long exact sequence as\n\t\\[\n\t\t\\dots \\to\n\t\t\\underbrace{\\wt H_n(U \\cap V)}_{=0}\n\t\t\\to \\wt H_n(U) \\oplus \\wt H_n(V) \\to \\wt H_n(X) \\to \n\t\t\\underbrace{\\wt H_{n-1}(U \\cap V)}_{=0} \\to \\dots.\n\t\\]\n\tSo we get that $\\wt H_n(X) \\cong \\wt H_n(S^1) \\oplus \\wt H_n(S^1)$,\n\tThe claim about the generators follows from the fact that, \n\taccording to the isomorphism above,\n\tthe generators of $\\wt H_n(X)$ are the generators of $\\wt H_n(U)$\n\tand $\\wt H_n(V)$, which we described geometrically\n\tin the last theorem.\n\\end{proof}\n\nUp until now, we have been very fortunate that we have always been able to make\ncertain parts of the space contractible.\nThis is not always the case, and in the next example we will have to\nactually understand the maps in question to complete the solution.\n\n\\begin{proposition}\n\t[Homology groups of the torus]\n\tLet $X = S^1 \\times S^1$ be the torus.\n\tThen\n\t\\[\n\t\t\\wt H_n(X)\n\t\t=\n\t\t\\begin{cases}\n\t\t\t\\ZZ^{\\oplus 2} & n = 1 \\\\\n\t\t\t\\ZZ & n = 2 \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\\end{proposition}\n\\begin{proof}\n\tTo make our diagram look good on 2D paper,\n\twe'll represent the torus as a square with its edges identified,\n\tthough three-dimensionally the picture makes sense as well.\n\tConsider $U$ (shaded light orange) and $V$ (shaded green) as shown.\n\t(Note that $V$ is connected due to the identification of the left and right (blue) edges,\n\teven if it doesn't look connected in the picture).\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tpair A = (0,0);\n\t\t\tpair B = (1,0);\n\t\t\tpair C = (1,1);\n\t\t\tpair D = (0,1);\n\t\t\tdraw(A--B, red+1.5, MidArrow);\n\t\t\tdraw(B--C, blue+1.5, MidArrow);\n\t\t\tdraw(D--C, red+1.5, MidArrow);\n\t\t\tdraw(A--D, blue+1.5, MidArrow);\n\t\t\tfill(box((0.2,0),(0.8,1)), orange+opacity(0.2));\n\t\t\tfill(box(A,(0.3,1)), heavygreen+opacity(0.2));\n\t\t\tfill(box((0.7,0),C), heavygreen+opacity(0.2));\n\t\t\tdraw( (0.3,0)--(0.3,1), heavygreen+dashed+1.2);\n\t\t\tdraw( (0.7,0)--(0.7,1), heavygreen+dashed+1.2);\n\t\t\tdraw( (0.2,0)--(0.2,1), orange+dashed+1.2);\n\t\t\tdraw( (0.8,0)--(0.8,1), orange+dashed+1.2);\n\n\t\t\tlabel(\"$U$\", (0.5, 0.5));\n\t\t\tlabel(\"$V$\", (0.1, 0.8));\n\t\t\tlabel(\"$V$\", (0.9, 0.8));\n\t\t\\end{asy}\n\t\\end{center}\n\tIn the three dimensional picture, $U$ and $V$ are two cylinders which together give the torus.\n\tThis time, $U$ and $V$ are each homotopic to $S^1$, and the intersection $U \\cap V$\n\tis the disjoint union of two circles: thus $\\wt H_1(U \\cap V) \\cong \\ZZ \\oplus \\ZZ$,\n\tand $H_0(U \\cap V) \\cong \\ZZ^{\\oplus 2} \\implies \\wt H_0(U \\cap V) \\cong \\ZZ$.\n\n\tFor $n \\ge 3$, we have\n\t\\[ \n\t\t\\dots \\to\n\t\t\\underbrace{\\wt H_n(U \\cap V)}_{=0}\n\t\t\\to \\wt H_n(U) \\oplus \\wt H_n(V) \\to \\wt H_n(X) \\to \n\t\t\\underbrace{\\wt H_{n-1}(U \\cap V)}_{=0} \\to \\dots.\n\t\\]\n\tand so $H_n(X) \\cong 0$ for $n \\ge 3$.\n\tAlso, we have $H_0(X) \\cong \\ZZ$ since $X$ is path-connected.\n\tSo it remains to compute $H_2(X)$ and $H_1(X)$.\n\n\tLet's find $H_2(X)$ first.\n\tWe first consider the segment\n\t\\[ \n\t\t\\dots \\to\n\t\t\\underbrace{\\wt H_2(U) \\oplus \\wt H_2(V)}_{=0} \\to \\wt H_2(X) \\xhookrightarrow{\\delta}\n\t\t\\underbrace{\\wt H_1(U \\cap V)}_{\\cong \\ZZ \\oplus \\ZZ} \\xrightarrow{\\phi}\n\t\t\\underbrace{\\wt H_1(U) \\oplus \\wt H_1(V)}_{\\cong \\ZZ \\oplus \\ZZ} \\to \\dots\n\t\\]\n\tUnfortunately, this time it's not immediately clear what $\\wt H_2(X)$ because\n\twe only have one zero at the left.\n\tIn order to do this, we have to actually figure out what the maps $\\delta$ and $\\phi$ look like.\n\tNote that, as we'll see, $\\phi$ isn't an isomorphism even though the groups are isomorphic.\n\n\tThe presence of the zero term has allowed us to make the connecting map $\\delta$ injective.\n\tFirst, $\\wt H_2(X)$ is isomorphic to the image of of $\\delta$, which is\n\texactly the kernel of the arrow $\\phi$ inserted.\n\tTo figure out what $\\ker \\phi$ is, we have to think back to how the map\n\t$C_\\bullet(U \\cap V) \\to C_\\bullet(U) \\oplus C_\\bullet(V)$ was constructed:\n\tit was $c \\mapsto (c, -c)$.\n\tSo the induced maps of homology groups is actually what you would guess:\n\ta $1$-cycle $z$ in $\\wt H_1(U \\cap V)$ gets sent $(z, -z)$ in $\\wt H_1(U) \\oplus \\wt H_1(V)$.\n\n\tIn particular, consider the two generators $z_1$ and $z_2$ of\n\t$\\wt H_1(U \\cap V) = \\ZZ \\oplus \\ZZ$,\n\ti.e.\\ one cycle in each connected component of $U \\cap V$.\n\t(To clarify: $U \\cap V$ consists of two ``wristbands'';\n\t$z_i$ wraps around the $i$th one once.)\n\tMoreover, let $\\alpha_U$ denote a generator of $\\wt H_1(U) \\cong \\ZZ$,\n\tand $\\alpha_V$ a generator of $H_2(U) \\cong \\ZZ$.\n\tThen we have that\n\t\\[ z_1 \\mapsto (\\alpha_U, -\\alpha_V) \\qquad\\text{and}\\qquad z_2 \\mapsto (\\alpha_U, -\\alpha_V). \\]\n\t(The signs may differ on which direction you pick for the generators;\n\tnote that $\\ZZ$ has two possible generators.)\n\tWe can even format this as a matrix:\n\t\\[ \\phi = \\begin{bmatrix} 1 & 1 \\\\ -1 & -1 \\end{bmatrix}. \\]\n\tAnd we observe $\\phi(z_1 - z_2) = 0$, meaning this map has nontrivial kernel!\n\tThat is, \\[ \\ker\\phi = \\left< z_1 - z_2 \\right> \\cong \\ZZ. \\]\n\tThus, $\\wt H_2(X) \\cong \\img \\delta \\cong \\ker \\phi \\cong \\ZZ$.\n\tWe'll also note that $\\img \\phi$ is the set generated by $(\\alpha_U, -\\alpha_V)$;\n\t(in particular $\\img\\phi \\cong \\ZZ$ and the quotient by $\\img\\phi$ is $\\ZZ$ too).\n\n\tThe situation is similar with $\\wt H_1(X)$: this time, we have\n\t\\[ \n\t\t\\dots \n\t\t%\\to \\underbrace{\\wt H_1(U \\cap V)}_{\\cong \\ZZ \\oplus \\ZZ}\n\t\t\\xrightarrow{\\phi} \\underbrace{\\wt H_1(U) \\oplus \\wt H_1(V)}_{\\cong \\ZZ \\oplus \\ZZ}\n\t\t\\overset{\\psi}{\\to} \\wt H_1(X) \\overset\\partial\\surjto\n\t\t\\underbrace{\\wt H_0(U \\cap V)}_{\\cong \\ZZ} \n\t\t\\to \\underbrace{\\wt H_0(U) \\oplus \\wt H_0(V)}_{=0} \\to \\dots\n\t\\]\n\tand so we know that the connecting map $\\partial$ is surjective,\n\thence $\\img \\partial \\cong \\ZZ$.\n\tNow, we also have\n\t\\begin{align*}\n\t\t\\ker \\partial \\cong \\img \\psi &\\cong \\left( \\wt H_1(U) \\oplus \\wt H_1(V) \\right) / \\ker \\psi \\\\\n\t\t&\\cong \\left( \\wt H_1(U) \\oplus \\wt H_1(V) \\right) / \\img \\phi \\\\\n\t\t&\\cong \\ZZ\n\t\\end{align*}\n\tby what we knew about $\\img \\phi$ already.\n\tTo finish off we need some algebraic tricks. The first is \\Cref{prop:break_exact},\n\twhich gives us a short exact sequence\n\t\\[\n\t\t0 \\to \\underbrace{\\ker\\partial}_{\\cong \\img\\psi \\cong \\ZZ} \n\t\t\\injto \\wt H_1(X)\n\t\t\\surjto \\underbrace{\\img\\partial}_{\\cong \\ZZ} \\to 0.\n\t\\]\n\tYou should satisfy yourself that $\\wt H_1(X) \\cong \\ZZ \\oplus \\ZZ$ is the\n\tonly possibility, but we'll prove this rigorously with \\Cref{lem:split_exact}.\n\\end{proof}\n\nNote that the previous example is of a different attitude than the previous ones,\nbecause we had to figure out what the maps in the long exact sequence actually were\nto even compute the groups.\nIn principle, you could also figure out all the isomorphisms in the previous proof\nand explicitly compute the generators of $\\wt H_1(S^1 \\times S^1)$,\nbut to avoid getting bogged down in detail I won't do so here.\n\nFinally, to fully justify the last step, we present:\n\\begin{lemma}[Splitting lemma]\n\t\\label{lem:split_exact}\n\tFor a short exact sequence $0 \\to A \\taking f B \\taking g C \\to 0$\n\tof abelian groups, the following are equivalent:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii There exists $p : B \\to A$ such that $A \\taking f B \\taking p A$ is the identity.\n\t\t\\ii There exists $s : C \\to B$ such that $C \\taking s B \\taking g C$ is the identity.\n\t\t\\ii There is an isomorphism from $B$ to $A \\oplus C$ such that the diagram\n\t\t\\begin{diagram}\n\t\t\t&&& & B & &&&  \\\\\n\t\t\t0 & \\rTo & A & \\ruInj(2,1)^f & \\dIsom^\\cong & \\rdSurj(2,1)^g & C & \\rTo & 0 \\\\\n\t\t\t&&& \\rdInj(2,1) & A \\oplus C & \\ruSurj(2,1) &&& \n\t\t\\end{diagram}\n\t\tcommutes. (The maps attached to $A \\oplus C$ are the obvious ones.)\n\t\\end{enumerate}\n\tIn particular, (b) holds anytime $C$ is free.\n\\end{lemma}\nIn these cases we say the short exact sequence \\vocab{splits}. The point is that\n\\begin{moral}\n\tAn exact sequence which splits let us obtain $B$ given $A$ and $C$.\n\\end{moral}\nIn particular, for $C = \\ZZ$ or any free abelian group,\ncondition (b) is necessarily true.\nSo, once we obtained the short exact sequence $0 \\to \\ZZ \\to \\wt H_1(X) \\to \\ZZ \\to 0$,\nwe were done.\n\\begin{remark}\n\tUnfortunately, not all exact sequences split:\n\tAn example of a short exact sequence which doesn't split is\n\t\\[ 0 \\to \\Zc 2 \\xhookrightarrow{\\times 2} \\Zc 4 \\surjto \\Zc 2 \\to 0 \\]\n\tsince it is not true that $\\Zc 4 \\cong \\Zc2 \\oplus \\Zc 2$.\n\\end{remark}\n\\begin{remark}\n\tThe splitting lemma is true in any abelian category.\n\tThe ``direct sum'' is the colimit of the two objects $A$ and $C$.\n\\end{remark}\n\n\\section\\problemhead\n\\begin{problem}\n\tComplete the proof of \\Cref{thm:reduced_homology_sphere},\n\ti.e.\\ compute $H_n(S^m)$ for all $m$ and $n$.\n\t(Try doing $m=2$ first, and you'll see how to proceed.)\n\t\\begin{hint}\n\t\tInduction on $m$, using hemispheres.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tCompute the reduced homology groups\n\tof $\\RR^n$ with $p \\ge 1$ points removed.\n\t\\begin{hint}\n\t\tOne strategy is induction on $p$, with base case $p=1$.\n\t\tAnother strategy is to let $U$ be the desired space and let $V$\n\t\tbe the union of $p$ non intersecting balls.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe answer is $\\wt H_{n-1}(X) \\cong \\ZZ^{\\oplus p}$,\n\t\twith all other groups vanishing.\n\t\tFor $p=1$, $\\RR^n - \\{\\ast\\} \\cong S^{n-1}$ so we're done.\n\t\tFor all other $p$, draw a hyperplane dividing the $p$ points into two halves\n\t\twith $a$ points on one side and $b$ points on the other (so $a+b=p$).\n\t\tSet $U$ and $V$ and use induction.\n\n\t\tAlternatively, let $U$ be the desired space and let $V$\n\t\tbe the union of $p$ disjoint balls, one around every point.\n\t\tThen $U \\cup V = \\RR^n$ has all reduced homology groups trivial.\n\t\tFrom the Mayer-Vietoris sequence we can read $\\wt H_k(U \\cap V) \\cong \\wt H_k(U) \\cap \\wt H_k(V)$.\n\t\tThen $U \\cap V$ is $p$ punctured balls, which are each the same as $S^{n-1}$.\n\t\tOne can read the conclusion from here.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{sproblem}\n\tLet $n \\ge 1$ and $k \\ge 0$ be integers.\n\tCompute $H_k(\\RR^n, \\RR^n \\setminus \\{0\\})$.\n\t\\begin{hint}\n\t\tUse \\Cref{thm:long_exact_rel}.\n\t\tNote that $\\RR^n \\setminus \\{0\\}$ is homotopy\n\t\tequivalent to $S^{n-1}$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIt is $\\ZZ$ for $k=n$ and $0$ otherwise.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{problem}\n\t[Nine lemma]\n\tConsider a commutative diagram\n\t\\begin{center}\n\t\\begin{tikzcd}\n\t\t& 0 \\ar[d] & 0 \\ar[d] & 0 \\ar[d] \\\\\n\t\t0 \\ar[r] & A_1 \\ar[r] \\ar[d] & B_1 \\ar[r] \\ar[d] & C_1 \\ar[r] \\ar[d] & 0 \\\\\n\t\t0 \\ar[r] & A_2 \\ar[r] \\ar[d] & B_2 \\ar[r] \\ar[d] & C_2 \\ar[r] \\ar[d] & 0 \\\\\n\t\t0 \\ar[r] & A_3 \\ar[r] \\ar[d] & B_3 \\ar[r] \\ar[d] & C_3 \\ar[r] \\ar[d] & 0 \\\\\n\t\t& 0 & 0 & 0 & \n\t\\end{tikzcd}\n\t\\end{center}\n\tand assume that all rows are exact,\n\tand two of the columns are exact.\n\tShow that the third column is exact as well.\n\t\\begin{hint}\n\t\t$0 \\to A_\\bullet \\to B_\\bullet \\to C_\\bullet \\to 0$\n\t\tis a short exact sequence of chain complexes.\n\t\tWrite out the corresponding long exact sequence.\n\t\tNearly all terms will vanish.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{sproblem}[Klein bottle]\n\t\\gim\n\tShow that the reduced homology groups of the Klein bottle $K$ are given by\n\t\\[\n\t\t\\wt H_n(K) = \n\t\t\\begin{cases}\n\t\t\t\\ZZ \\oplus \\Zc 2 & n = 1 \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\t\\begin{hint}\n\t\tIt's possible to use two cylinders with $U$ and $V$.\n\t\tThis time the matrix is $\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}$\n\t\tor some variant though; in particular, it's injective, so $\\wt H_2(X) = 0$.\n\t\\end{hint}\n\\end{sproblem}\n\n\\begin{sproblem}\n\t[Triple long exact sequence]\n\t\\label{prob:triple_long_exact}\n\tLet $A \\subseteq B \\subseteq X$ be subspaces.\n\tShow that there is a long exact sequence\n\t\\[\n\t\t\\dots \\to H_n(B,A) \\to H_n(X,A)\n\t\t\\to H_n(X,B) \\to H_{n-1}(B,A) \\to \\dots.\n\t\\]\n\t\\begin{hint}\n\t\tFind a new short exact sequence\n\t\tto apply \\Cref{thm:long_exact} to.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tUse the short exact sequence\n\t\t\\[ 0 \\to C_\\bullet(A,B) \\to C_\\bullet(C,B) \\to C_\\bullet(C,A) \\to 0 \\]\n\t\tof chain complexes.\n\t\\end{sol}\n\\end{sproblem}\n", "meta": {"hexsha": "2b406f6e573991858b9ba6f1c38940ec4fbda6c9", "size": 26242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/homology/long-exact.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/long-exact.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/long-exact.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0030487805, "max_line_length": 101, "alphanum_fraction": 0.6483880802, "num_tokens": 9759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118222, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6585168303499239}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $B = \\set{\\begin{mymatrix}{r} 2 \\\\ -1 \\end{mymatrix},\n    \\begin{mymatrix}{r} 3 \\\\ 2 \\end{mymatrix}}$ be a basis of $\\R^2$\n  and let $\\vect{x} = \\begin{mymatrix}{r} 5 \\\\ -7 \\end{mymatrix}$ be a\n  vector in $\\R^2$. Find $\\coord{\\vect{x}}_B$.\n\\end{ex}\n\n\\begin{ex}\n  Let $B = \\set{\\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix},\n    \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix},\n    \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\end{mymatrix}}$ be a basis of\n  $\\R^3$ and let\n  $\\vect{x} = \\begin{mymatrix}{r} 5 \\\\ -1 \\\\ 4 \\end{mymatrix}$ be a\n  vector in $\\R^2$. Find $\\coord{\\vect{x}}_B$.\n  \\begin{sol}\n    $\\coord{\\vect{x}}_B\n    = \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ -1 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $T:\\R^3\\to\\R^3$ is a linear transformation such that\n  \\begin{equation*}\n    T\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 3 \\\\ 3 \\\\ 3 \\end{mymatrix},\n    \\quad\n    T\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix},\n    \\quad\n    T\\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n  Let $E=\\set{\\vect{e}_1,\\vect{e}_2,\\vect{e}_3}$ be the standard basis\n  of $\\R^3$, and let\n  \\begin{equation*}\n    B = \\set{\\vect{v}_1,\\vect{v}_2,\\vect{v}_3} = \\set{\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    }\n  \\end{equation*}\n  be another basis.\n  \\begin{enumerate}\n  \\item  Find the matrix of $T$ with respect to $E$, i.e.,\n    find $\\coord{T}_{E,E}$.\n  \\item Find $\\coord{T}_{B,B}$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n      \\item The $i\\th$ column of $\\coord{T}_{E,E}$ is\n      $\\coord{T(\\vect{e}_i)}_E = T(\\vect{e}_i)$, so\n      \\begin{equation*}\n        \\coord{T}_{E,E} =\n        \\begin{mymatrix}{ccc}\n          3 & 1 & 1 \\\\\n          3 & 2 & 3 \\\\\n          3 & 3 & -1\n        \\end{mymatrix}.\n      \\end{equation*}\n      \\item The $i\\th$ column of $\\coord{T}_{B,B}$ is\n        $\\coord{T(\\vect{v}_i)}_B$. This requires a calculation:\n        \\begin{equation*}\n          T(\\vect{v}_1) = T\\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n          = \\begin{mymatrix}{c} 3 \\\\ 3 \\\\ 3 \\end{mymatrix} =\n          - 3\\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n          + 0\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n          + 3\\begin{mymatrix}{c} 2 \\\\ 1 \\\\ 1 \\end{mymatrix},\n          \\quad\\mbox{therefore}\n          \\coord{T(\\vect{v}_1)}_B =\n          \\begin{mymatrix}{r} -3 \\\\ 0 \\\\ 3 \\end{mymatrix}.\n        \\end{equation*}\n        \\begin{equation*}\n          T(\\vect{v}_2) = T\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n          = \\begin{mymatrix}{c} 4 \\\\ 5 \\\\ 6 \\end{mymatrix} =\n          - 7\\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n          - 1\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n          + 6\\begin{mymatrix}{c} 2 \\\\ 1 \\\\ 1 \\end{mymatrix},\n          \\quad\\mbox{therefore}\n          \\coord{T(\\vect{v}_2)}_B =\n          \\begin{mymatrix}{r} -7 \\\\ -1 \\\\ 6 \\end{mymatrix}.\n        \\end{equation*}\n        \\begin{equation*}\n          T(\\vect{v}_3) = T\\begin{mymatrix}{c} 2 \\\\ 1 \\\\ 1 \\end{mymatrix}\n          = \\begin{mymatrix}{c} 8 \\\\ 11 \\\\ 8 \\end{mymatrix} =\n          - 11\\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n          + 3\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n          + 8\\begin{mymatrix}{c} 2 \\\\ 1 \\\\ 1 \\end{mymatrix},\n          \\quad\\mbox{therefore}\n          \\coord{T(\\vect{v}_3)}_B =\n          \\begin{mymatrix}{c} -11 \\\\ 3 \\\\ 8 \\end{mymatrix}.\n        \\end{equation*}\n        We therefore have\n        \\begin{equation*}\n          \\coord{T}_{B,B} =\n          \\begin{mymatrix}{rrc}\n            -3 & -7 & -11 \\\\\n            0  & -1 &   3 \\\\\n            3  &  6 &   8 \\\\\n          \\end{mymatrix}.\n        \\end{equation*}\n      \\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T: \\R^2 \\to \\R^2$ be a linear transformation defined by\n  \\begin{equation*}\n    T \\paren{\\begin{mymatrix}{c} a \\\\ b \\end{mymatrix}}\n    = \\begin{mymatrix}{c} a+b \\\\ a-b \\end{mymatrix}.\n  \\end{equation*}\n  Consider the two bases\n  \\begin{equation*}\n    B_1 = \\set{\\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} -1 \\\\ 1 \\end{mymatrix}\n    }\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    B_2 = \\set{\\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ -1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Find the matrix $M_{B_2,B_1}$ of $T$ with respect to the bases $B_1$\n  and $B_2$.\n  \\begin{sol}\n    $M_{B_2 B_1} = \\begin{mymatrix}{rr}\n      1 & -1 \\\\\n      0 & 1\n    \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $M=\\begin{mymatrix}{rr} 1 & 2 \\\\ -2 & 1 \\end{mymatrix}$, and\n  consider the linear transformation $T:\\Mat_{2,2}\\to\\Mat_{2,2}$ given\n  by $T(A) = MAM$. Find the matrix of $T$ with respect to the basis\n  \\begin{equation*}\n    B=\\set{\n      \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & 1 \\\\ 0 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & 0 \\\\ 1 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 1 \\end{mymatrix}.\n    }\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Consider the linear transformation $T:\\Poly_3\\to\\Poly_3$ given by\n  $T(p(x)) = p(x+1)$. Find $\\coord{T}_{B,B}$, where $B=\\set{1,x,x^2,x^3}$.\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{v}=\\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 3 \\end{mymatrix}$\n  and consider the linear function\n  $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w})$.  Find the matrix of $T$\n  with respect to the standard basis of $\\R^3$.\n  \\begin{sol}\n    Recall that\n    $\\proj_{\\vect{v}}(\\vect{w})\n    =\\frac{\\vect{v}\\dotprod\\vect{w}}{\\norm{\\vect{v}}^2}\\vect{v}$. The\n    desired matrix has $i\\th$ column equal to\n    $\\proj_{\\vect{v}}(\\vect{e}_i)$. Therefore, the desired matrix is\n    \\begin{equation*}\n      \\frac{1}{14}\\begin{mymatrix}{rrr}\n        1 & -2 & 3 \\\\\n        -2 & 4 & -6 \\\\\n        3 & -6 & 9\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{v}=\\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 3 \\end{mymatrix}$\n  and consider the linear function\n  $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w})$.  Find the matrix of $T$\n  with respect to the basis\n  \\begin{equation*}\n    B = \\set{\\vect{v}_1,\\vect{v}_2,\\vect{v}_3} = \\set{\n      \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 3 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  \\begin{sol}\n    We have $T(\\vect{v}_1) = \\vect{v}_1$, $T(\\vect{v}_2) = \\vect{0}$,\n    and $T(\\vect{v}_3) = \\vect{0}$. Therefore\n    \\begin{equation*}\n      \\coord{T}_{B,B} =\n      \\begin{mymatrix}{rrr}\n        1 & 0 & 0 \\\\\n        0 & 0 & 0 \\\\\n        0 & 0 & 0\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose that $V$ and $W$ are finite-dimensional vector spaces with\n  bases $B$ and $C$, respectively. Let $T:V\\to W$ be a linear\n  transformation such that\n  \\begin{equation*}\n    T(\\vect{v}_i)=\\vect{w}_i\n  \\end{equation*}\n  for $i=1,\\ldots,n$. Let $M$ be the matrix whose columns are\n  $\\coord{\\vect{v}_1}_B,\\ldots,\\coord{\\vect{v}_n}_B$, and let $N$ be\n  the matrix whose columns are\n  $\\coord{\\vect{w}_1}_C,\\ldots,\\coord{\\vect{w}_n}_C$.  Suppose that\n  $M$ is invertible. Show that $\\coord{T}_{C,B} = NM^{-1}$.\n  \\begin{sol}\n    Since $M$ is invertible, its columns\n    $\\coord{\\vect{v}_1}_B,\\ldots,\\coord{\\vect{v}_n}_B$ are linearly\n    independent and span $\\R^n$; it follows that\n    $\\vect{v}_1,\\ldots,\\vect{v}_n$ is a basis of $V$. To show that\n    $\\coord{T}_{C,B} = NM^{-1}$, it is sufficient to check that\n    $NM^{-1}\\coord{\\vect{v}_i}_B = \\coord{\\vect{w}_i}_C$, for all\n    $i=1,\\ldots,n$. But by assumption, $\\coord{\\vect{v}_i}_B$ is the\n    $i\\th$ column of $M$, so that $\\coord{\\vect{v}_i}_B =\n    M\\vect{e}_i$, where $\\vect{e}_i$ is the $i\\th$ basis\n    vector. Therefore $M^{-1}\\coord{\\vect{v}_i}_B  = \\vect{e}_i$.\n    On the other hand, $N\\vect{e}_i$ is the $i\\th$ column of $N$,\n    i.e., $\\coord{\\vect{w}_i}_C$. We therefore have\n    \\begin{equation*}\n      NM^{-1}\\coord{\\vect{v}_i}_B = N\\vect{e}_i = \\coord{\\vect{w}_i}_C,\n    \\end{equation*}\n    as desired.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "b7be0a6dbf07f776d26fd6a45e1c40dcb2c36165", "size": 8268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsGeneral-Matrix.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsGeneral-Matrix.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsGeneral-Matrix.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 35.4849785408, "max_line_length": 74, "alphanum_fraction": 0.5399129173, "num_tokens": 3464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159129, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6585103288012139}}
{"text": "\\subsection{Leaf-Zone 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}: Heat to/from environment, by-product heat from/to surroundings, internal air circulation, internal air temperature sensor readings (\\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 automation system (\\ref{sec:automation});\n        \\item Control module controls heat pump speed and direction (heating vs. cooling environment, \\ref{sec:automation});\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 $M$ of 28.97 $\\frac g{mol}$, a specific heat capacity of dry air $c_p$ of $1.006 \\frac{J}{g*\\text{K}}$\\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.}, a 4U Class 2 expanded configuration (2x2 units, 16 faces; see \\ref{sec:housing}), and a face insulation RSI per mm of $0.0328\\text{m}^2~  \\degree \\text{C}~\\text{W}^{-1}~\\text{mm}^{-1}$ (see \\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\\\\\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\\\\\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    \\label{eqn:heating}\n    Q_{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    Q_{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\\clearpage\n\n$\\therefore$ A thermoelectric system able to transfer at least \\textbf{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 for even temperature distribution, rapid system flushing, and automatic pollination.\n    \\item \\textit{Temperature Sensors}: Multiple temperature and humidity sensors \\cite{sht31} on small daughterboards frame-mounted throughout the growth environment to measure air temperature ($\\degree$C). Informs the \\textbf{PID control loop}.\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{Thermoelectric Driver Board}: Controls \\textit{magnitude} and \\textit{direction} of heat transfer via a \\textbf{dimmable voltage source} (low-pass-filtered PWM to a voltage buffer and amplifier w/ feedback) and \\textbf{relay H-bridge}, respectively. See Figures \\ref{fig:peltierdriver} and \\ref{fig:thermoregulation_driver}.\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    \\item \\textit{PID Control Loop}: A propotional-integral-derivative control loop enables increased accuracy (see equation \\ref{eqn:pid}). Temperature sensors inform the loop, \"error\" is calculated (current vs desired temperature, see $E(t)$ \\ref{eqn:piderror}), and this informs the magnitude and direction of heat pump control ($u(t)$). Requires tuning of parameters ($K_p, K_i, K_d$; automatic). Built into the automation system (see \\ref{sec:automation});\n\\end{itemize}\n\n\\begin{gather}\n    \\label{eqn:piderror}\n    E(t)=T_{target}(t)-T_{measured}(t)\\\\\n    \\label{eqn:pid}\n    u(t)=K_pE(t)+K_i\\int_0^{t}E(t)dt+K_d\\frac{dE(t)}{dt}\n\\end{gather}\n\n\\clearpage\n\n\\textbf{Figures}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=\\textwidth]{../assets/figures/airthermoregulation_simulation.png}\n  \\hfill\n  \\caption{Thermoelectric driver circuit simulation \\cite{thermo-falstad}}\n  \\label{fig:peltierdriver}\n\\end{figure}\n\n\\begin{figure}[h!]\n    \\centering\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\frame{\\includegraphics[width=\\textwidth]{../assets/schematics/thermoregulation_driver_sch.png}}\n        \\caption{Schematic.}\n        \\label{fig:thermoregulation_driver_sch}\n      \\end{subfigure}\n      \\hspace{.02\\textwidth}\n      \\begin{subfigure}{.43\\textwidth}\n        \\centering\n        \\frame{\\includegraphics[width=\\textwidth]{../assets/schematics/thermoregulation_driver_brd.png}}\n        \\caption{PCB layout.}\n        \\label{fig:thermoregulation_driver_brd}\n      \\end{subfigure}\n      \\caption{Thermoelectric driver board.}\n      \\label{fig:thermoregulation_driver}\n\\end{figure}\n\n\\clearpage", "meta": {"hexsha": "53bd5d24441f90079825f6526b90de6ac79bbc0c", "size": 7254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/design/AirThermoregulation.tex", "max_stars_repo_name": "UpRouteFoundation/PeaPod", "max_stars_repo_head_hexsha": "8693ad8d73e609ab2ebd4fa2b0db7b2ea6e8de1c", "max_stars_repo_licenses": ["MIT"], "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/design/AirThermoregulation.tex", "max_issues_repo_name": "UpRouteFoundation/PeaPod", "max_issues_repo_head_hexsha": "8693ad8d73e609ab2ebd4fa2b0db7b2ea6e8de1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-10-13T04:36:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-13T09:11:25.000Z", "max_forks_repo_path": "docs/tex/design/AirThermoregulation.tex", "max_forks_repo_name": "UpRouteFoundation/PeaPod", "max_forks_repo_head_hexsha": "8693ad8d73e609ab2ebd4fa2b0db7b2ea6e8de1c", "max_forks_repo_licenses": ["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.5504587156, "max_line_length": 684, "alphanum_fraction": 0.7082988696, "num_tokens": 2303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6584138516010485}}
{"text": "\\subsection{Definition of the \\acrshort{twm} problem}%\n\\label{sub:definition_of_the_twm_problem}\n\nOur modelization is practically the same as the one defined by \\citeauthor{comp_mcts_mo}\\cite{comp_mcts_mo} with minor changes.\nThe \\gls{twm} is set on a squared grid of cells \\(X\\).\nEach cell \\(x \\in X\\) is defined by two attributes:\n\n\\begin{itemize}\n    \\item \\(B(x)\\) is a boolean indicating if the cell \\(x\\) is on fire.\n    \\item \\(F(x)\\) is an integer representing the amount of fuel on cell \\(x\\). The more fuel, the longer it burns.\n\\end{itemize}\n\nA state is then represented by the values of these two attributes for all \\(x \\in X\\).\nA state is considered final when no cell is burning anymore.\n\nWe have a set \\(T\\) of firefighter teams which we consider identical.\nAn action consists in placing each team \\(t \\in T\\) setting the attribute \\(a^{i} \\in X\\).\nEvery team can be assigned to any cell and can even be assigned to the same cells.\n\nA burning cell consumes its fuel at a constant rate.\nIf a cell has no more fuel, it extinguishes.\nThe burning rate constitutes the time unite of the game. \nMeaning that, each turn, all burning cells consume one fuel, therefore:\n\n\\[\n    F_{t+1}(x) = \n    \\begin{cases}\n        F_{t}(x)& \\text{if } \\lnot B_{t}(x) \\lor F_{t}(x) = 0\\\\\n        F_{t}(x) - 1& \\text{otherwise }\n    \\end{cases}\n\\]\nThe evolution of the attribute \\(B(x)\\) is stochastic.\nIt is set on a terminal state machine.\nThis transition model is given by the following equation defining \\(\\rho_{1}\\) and \\(\\rho_{2}\\) and the figure~\\ref{fig:B_state_machine}.\n\n\\[\n    \\rho_{1} = \n    \\begin{cases}\n        1 - \\Pi_{y}(1 - P(x, y)B_{t}(x))& \\text{if } F_{t}(x) > 0\\\\\n        0& \\text{otherwise }\n    \\end{cases}\n\\]\n\\[\n    \\rho_{2} = \n    \\begin{cases}\n        1& \\text{if } F_{t}(x) = 0\\\\\n        1 - \\Pi_{i}(1 - S(x)\\delta_{x}(a^{i}))& \\text{otherwise }\n    \\end{cases}\n\\]\n\n\\begin{figure}[htpb]\n    \\ctikzfig{../../../figures/B_state_machine}\n    \\caption{\\(B(x)\\) transition model}%\n    \\label{fig:B_state_machine}\n\\end{figure}\n\n\\(P(x, y)\\) represents the probability that \\(y\\) ignites \\(x\\) if \\(y\\) is burning.\nWe will only consider case where only neighbors cell can ignite each other.\n\\(S(x)\\) is the probability that a firefighter team extinguish the cell \\(x\\).\n\\(\\delta_{x}(a^{i})\\) equals \\(1\\) if firefighter team \\(i\\) has been placed on cell \\(x\\) and \\(0\\) otherwise.\n\nThe reward \\(R(x)\\) is always negative and is the cost of the fire on cell \\(x\\).\nThe reward at time \\(t\\) is therefore \\(\\Sigma_{x \\in X} B_{t}(x)R(x)\\).\nThe score of a final state is the sum of all rewards.\n", "meta": {"hexsha": "e4387f243c13ba6f96f753e5b7904d423b44c629", "size": 2603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/report/src/sections/twm/subs/definition.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/twm/subs/definition.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/twm/subs/definition.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": 40.0461538462, "max_line_length": 137, "alphanum_fraction": 0.6588551671, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6584138350845656}}
{"text": "\\section{Statistical Analysis}\n\nThe Analysis module contains some simple statistics support in the\nform of a \\hyperref{TCL exported C++ data type}{TCL exported C++ data\n  type (\\S}{)}{TCLTYPE}. The class definition is:\n\n\\begin{verbatim}\n\nstruct Stats: public array_ns::array<float>\n{\n  double sum, sumsq;\n  float max, min;\n  Stats(): sum(0), sumsq(0), max(-std::numeric_limits<float>::max()), \n           min(std::numeric_limits<float>::max()) {}\n\n  void clear();\n  double av();\n  double median();\n  double stddev();\n\n  Stats& operator<<=(float x);\n  Stats& operator<<=(const array_ns::array<float>& x);\n  Stats& operator<<=(const array_ns::array<double>& x);\n\n  void add_data(TCL_args args); \n};\n\nstruct HistoStats: public Stats\n{\n  unsigned nbins;\n  bool logbins;\n  HistoStats(): nbins(100), logbins(false) {}\n  array_ns::array<double> histogram();\n  array_ns::array<double> bins();\n\n  double loglikelihood(TCL_args args);\n\n  array_ns::array<double> fitPowerLaw(); //< fit x^{-a} - return a and x_min\n  double fitExponential()                //< fit exp(-x/a) - return a \n  array_ns::array<double> fitNormal();   //< fit exp(-(x-m)^2/2s, return m, s\n    \n  array_ns::array<double> fitLogNormal(); //< fit exp(-(log(x)-log m)^2/2s, return m, s\n};\n\\end{verbatim}\n\nThese classes can be used from the TCL programming environment like\nthis example:\n\n\\begin{verbatim}\n\nHistoStats h\n\n\nunuran rand\nrand.set_gen {distr=pareto(.5,1.7);}\n\nfor {set i 0} {$i<10000} {incr i} {\n    h.add_data [rand.rand]\n}\n\n# obtain average, median, min, max, standard deviation and no. samples\nputs stdout \"[h.av] [h.median] [h.min] [h.max] [h.stddev] [h.size]\"\n\n# fit power law distribution, returning slope and xmin\nputs stdout \"[h.fitPowerLaw]\"\n\n# return log likelihood ratio for power law versus lognormal\narray set pl [h.fitPowerLaw]\narray set ln [h.fitLogNormal]\nset R [h.loglikelihood powerlaw($pl(0),$pl(1)) \n                       lognormal($ln(0),$ln(1) $pl(1)]\nputs stdout \"R=$R p=[expr fabs([erfc $R])]\"\n\\end{verbatim}\n\nFitting parameters is achieved using the likelihood method as\ndescribed in \\cite{Clauset-etal07}.\n\nThe log likelihood ratio function returns ${\\cal R}/\\sqrt{2n}\\sigma$,\nwhere ${\\cal R}=\\ln \\prod_i p_1(x_i)/p_2(x_i)$ is the logarithm of the\nratio of likelihoods for the two distributions $p_1$ and $p_2$.\n\nIf the log likelihood ratio is positive, it means the $p_1$ is more\nlikely to fit the data than $p_2$, and negative is the other way\naround. $p=|\\mathrm{erfc}({\\cal R})|$ is the probability that this conclusion\nis wrong.\\cite{Clauset-etal07}\n\nThe histogram function allows one to do histograms without using the\nGUI widget, which is useful for larger collections of data. The\nparameters to the histogram method are the number of bins (default\n100) and whether linear or logarithmic binning is used.\n", "meta": {"hexsha": "ffffc15e1c026649810d95aa36d3a172973ee7c8", "size": 2809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/analysis.tex", "max_stars_repo_name": "digiperfect/ecolab", "max_stars_repo_head_hexsha": "52751dfa805b67b775ea50e37c5d02c2735ed0d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2017-04-19T15:02:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-18T05:03:56.000Z", "max_issues_repo_path": "doc/analysis.tex", "max_issues_repo_name": "digiperfect/ecolab", "max_issues_repo_head_hexsha": "52751dfa805b67b775ea50e37c5d02c2735ed0d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2016-01-17T21:14:29.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-28T13:18:28.000Z", "max_forks_repo_path": "doc/analysis.tex", "max_forks_repo_name": "digiperfect/ecolab", "max_forks_repo_head_hexsha": "52751dfa805b67b775ea50e37c5d02c2735ed0d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-01-17T20:32:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T19:11:21.000Z", "avg_line_length": 30.8681318681, "max_line_length": 87, "alphanum_fraction": 0.6956212175, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6583735555709321}}
{"text": "\\chapter{Matrix Games}\nThis part uses mathematical methods to model interactions and conflicts between\ndifferent actors. To simplify the analysis we are going to consider interactions\nbetween \\emph{two} actors that are trying to maximize their payoffs.\n\n\\begin{definition}\n  The \\emph{strategic form}, or \\emph{normal form}, of a two-person game is\n  a tuple $(X, Y, A, B)$ such that $X$ and $Y$ are some nonempty sets, and \n  $A, B  : X \\times Y \\to \\R$.\n\n  We say that this game is a matrix game if $X$ and $Y$ are finite.\n\\end{definition}\nThe interpretation is as follows. Simultaneously, the first player chooses \na strategy $x \\in X$ and the second player chooses a strategy $y \\in Y$ , each\nunaware of the choice of the other. Then their choices are made known and the\nfirst player wins $A(x, y)$ and the second player wins $B(x, y)$. (Depending on\nthe monetary unit involved, $A(x, y)$ and $B(x, y)$ will be dollars, rubles,\neuros, etc.) If $A(x, y)$ or $B(x, y)$ is negative, the corresponding player\nloses the absolute value of this amount.\n\nIt is important to note that the notion of a strategy is very broad; e.g., a\nstrategy for a game of chess, is a complete description of how to play the game,\nof what move to make in every possible situation that could occur. We are going\nto ignore the fact that in the game of chess it is physically impossible to\ndescribe all possible strategies since there are too many of them (in fact,\nthere are more strategies than there are atoms in the known universe). On the\nother hand, the number of games of tic tac toe is rather small, so that it is\npossible to study all strategies and find an optimal strategy for each player.\n\nIn cases when $X$ and $Y$ are small sets it is convenient to describe such games\nusing tables. Let us consider the game described by\n\\Cref{table:heads-and-tales-game}.\n\\begin{table}\n  \\begin{center}\n    \\begin{tabular}{l l l  l  l  l  l  l  l}\n      \\toprule\n            & heads  & tales   \\\\\n      \\midrule\n      heads & 1, -1 & -1, 1   \\\\\n      tales & -1, 1 & 1, -1   \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n  \\caption{Heads and tales game}\n  \\label{table:heads-and-tales-game}\n\\end{table}\nIn this game two players put one coin each on the table: if the the coins have\nthe same side up, then the second player pays $1$ dollar to the first player,\notherwise the first player pays $1$ dollar to the second player. In other words,\nthe firs number denotes the payoff of the first player and the second denotes\nthe payoff of the second player.\n\n\\begin{exercise}\n  Describe the game in normal form corresponding to rock paper scissors.\n\\end{exercise}\n\nAn important class of games is zero-sum games.\n\\begin{definition}\n  A game $(X, Y, A, B)$ is \\emph{zero-sum} if $A(x, y) = -B(x, y)$ for all \n  $x \\in X$ and $y \\in Y$.\n\\end{definition}\nIt is clear that the game we described is a zero-sum game.\n\n\\section{Domination and Pareto Optimal Strategies}\nIn \\Cref{part:combinatorial-games} we studies optimal strategies; however, in\ncase of games in the normal form it is not clear what does it mean optimal. To\nillustrate this difficulty, let us discuss the most famous game, the prisoner's\ndilemma:\n\\begin{game}\n  Two members of a criminal gang are arrested and imprisoned. Each prisoner is in\n  solitary confinement with no means of communicating with the other. The\n  prosecutors lack sufficient evidence to convict the pair on the principal\n  charge, but they have enough to convict both on a lesser charge. Simultaneously,\n  the prosecutors offer each prisoner a bargain. Each prisoner is given the\n  opportunity either to betray the other by testifying that the other committed\n  the crime, or to cooperate with the other by remaining silent. The possible\n  outcomes are:\n  \\begin{itemize}\n    \\item If A and B each betray the other, each of them serves two years in\n      prison.\n    \\item If A betrays B but B remains silent, A will be set free and B will serve\n      three years in prison (and vice versa).\n    \\item If A and B both remain silent, both of them will serve only one year in\n      prison (on the lesser charge).\n  \\end{itemize}\n\\end{game}\n\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               & cooperates  & defects   \\\\\n    \\midrule\n    cooperates & -1, -1      & -3, 0    \\\\\n    defects    & 0, -3       & -2, -2   \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\n\n\nLet us try to put ourselves into these prisoners shoes. If our partner is silent,\nthen it is better for us to defect (in this case we are free immediately); if\nour partner defects, then is is also better for us to defect (we'll get two\nyears instead of three). Therefore, no matter what our partner does it is always\nbetter to defect. Since the game is symmetric both players come to this\nconclusion and get two years each; however, if both of them cooperates they\nwould serve only one year\\footnote{%\n  In 1993 Frank, Gilovich, and Regan conducted an experimental study of the\n  prisoner's dilemma. The subjects were students in their first and final years\n  of undergraduate economics, and undergraduates in other disciplines. Subjects\n  were paired, placed in a typical game scenario, then asked to choose either to\n  ``cooperate'' or to ``defect''. \n\n  First year economics students, and students doing disciplines other than\n  economics, overwhelmingly chose to cooperate. But 4th year students in\n  economics tended to not cooperate. Therefore, the authors concluded that\n  that the study of economics reduces cooperation in games. The idea is\n  that much of the time cooperation and consideration of other's perspective are\n  irrational in the narrow sense of the word. Thus, learning that cooperation is\n  irrational in some situations is influencing the behavior of the students\n  towards less cooperation, presumably to the negative.\n}.\n\nLet us generalise the argument we used to justify why defecting is better than\ncooperating.\n\\begin{definition}\n  Let $(X, Y, A, B)$ be a game in normal form. We say that $x_1 \\in X$\n  \\emph{dominates} $x_2 \\in X$ iff $A(x_1, y) \\ge A(x_2, y)$ for all $y \\in Y$.\n  We also say that $x_1$ \\emph{strictly dominates} $x_2$ if $A(x_1, y) > A(x_2,\n  y)$ for all $y \\in Y$.\n\n  Similarly we may define domination of strategies for the second player.\n\\end{definition}\nIt seems reasonable to never choose $x_2$ provided that $x_1$ dominates $x_2$; in\nthe prisoners dilemma ``defects'' dominates ``cooperates''; hence, it seems\nchoosing ``defects'' is the best behaviour for rational agents.\n\nHowever, it also obvious that if both players cooperate is way better than if\nboth of them defects; this observation leads to the following definition.\n\\begin{definition}\n  Let $(X, Y, A, B)$  be a game in the normal form. We say that a pair of\n  strategies $(x, y) \\in X \\times Y$ is Pareto optimal if either \n  $A(x', y') < A(x, y)$ or $B(x', y') < B(x, y)$ for any \n  $(x', y') \\in X \\times Y$.\n\\end{definition}\nIn other words, a pair of strategies is Pareto optimal if any other choice would\ndecrease the payoff for at least one of the players.\n\n\\section{Prisoners Dilemma In Real Life}\nThe reason that prisoner's dilemma is that famous is because there are many\nexamples human interactions as well as interactions in nature that have the same\npayoff matrix. Let us consider two of them.\n\n\\paragraph{Political science.} In political science, the prisoner's dilemma is\noften used to demonstrate the coherence of strategic realism, which holds that\nin international relations, all countries (regardless of their internal policies\nor professed ideology), will act in their rational self-interest given\ninternational anarchy. A standard example is an arms race like the Cold War:\nduring the Cold War the opposing alliances of NATO and the Warsaw Pact both had\nthe choice to arm or disarm. From each side's point of view, disarming when\ntheir opponent continued to arm would have led to military inferiority and\npossible annihilation. Conversely, arming whilst their opponent disarmed would\nhave led to superiority. If both sides chose to arm,\nneither could afford to attack the other, but both incurred the high cost of\ndeveloping and maintaining a nuclear arsenal. If both sides chose to disarm, war\nwould be avoided and there would be no costs.\n\nAlthough the ``best'' overall outcome is for both sides to disarm, the rational\ncourse for both sides is to arm, and this is indeed what happened. Both sides\npoured enormous resources into military research and armament in a war of\nattrition for the next thirty years until the Soviet Union could not withstand\nthe economic cost. \n\n\\paragraph{Sports.} Another example is doping in sports. Two competing athletes\nhave the option to use an illegal and/or dangerous drug to boost their\nperformance. If neither athlete takes the drug, then neither gains an advantage.\nIf only one does, then that athlete gains a significant advantage over their\ncompetitor, reduced by the legal and/or medical dangers of having taken the\ndrug. If both athletes take the drug, however, the benefits cancel out and only\nthe dangers remain, putting them both in a worse position than if neither had\nused doping.\n", "meta": {"hexsha": "b54c8e58aaef190fa739fb98f69024cb1de48aa1", "size": 9244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_6/chapter_27_matrix_games.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_6/chapter_27_matrix_games.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_6/chapter_27_matrix_games.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 50.7912087912, "max_line_length": 82, "alphanum_fraction": 0.7462137603, "num_tokens": 2331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6583400090451991}}
{"text": "% Created 2021-10-22 Fri 12:18\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{dnx}\n\\date{\\today}\n\\title{}\n\\hypersetup{\n pdfauthor={dnx},\n pdftitle={},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 27.2 (Org mode 9.4.4)}, \n pdflang={English}}\n\\begin{document}\n\n\\tableofcontents\n\n\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\usepackage{subcaption}\n\\begin{document}\n\t\n\t\\title{Introduction to Circuitry}\n\t\\author{}\n\t\n\t\\maketitle\n\t\n\t\\begin{abstract}\n\tIn this article we will have an in-depth look at some of the math necessary for circuit analysis, namely exponential function and natural logarithm.\n\tWe also see their uses in a simple circuit as well.\n\t\\end{abstract}\n\t\n\t\\section{Natural Logarithm}\n\tLet's find a function that would satisfy the following equation:\n\t\n\t\\begin{equation}\n\t\\label{simple_equation}\n\tf(ax) = f(a) + f(x)\n\t\\end{equation}\n\t\n\t($f$ as a function of $x$ and $a$ as an arbitrary constant.)\n\t\n\t\n\tWhy do we want such a function? Because it has numerous important properties that we will discuss later in this document.\n\tFor now let's continue finding such a function.\n\tA function $f$ that would satisfy an equation such as above, could have many different forms and finding them all would be a difficult or even an impossible task.\n\tWhat we want to do instead, is to add more properties to the equation that would narrow down the function we are looking for.\n\tThe first property is that we don't want $f$ to be a function that maps all of its inputs to $0$; Because such a function \\textit{would} satisfy the equation (1), but it wouldn't be useful at all.\n\tThe next important property that we want to add which makes a lot sense too, is to find an $f$ that would be continuous and differentiable\\footnote[1]{Because in the wide areas of mathematics we are only interested in continuous and differentiable functions.}.\n\tIn other words, Finding an $f$ that would make the derivative (in respect to $x$) of the right-hand side and left-hand side of equation (1), equal.\n\tIf we find such a function that for a range of inputs $\\frac{d}{dx}f(ax)$ gives \\textbf{equal} values as $\\frac{d}{dx}(f(a) + f(x))$, we can use the fundamental theorem of Calculus to find the function itself.\n\tThe function found in this procedure not only could be an answer for equation (1), moreover it would be differentiable for that range of the values of $x$.\t\n\tNow to find such a function let's differentiate both sides of equation (1). We get:\n\t\n\t$$ \\frac{d}{dx} f(ax) = \\frac{d}{dx} f(a) + \\frac{d}{dx} f(x) $$\n\t\n\tNow $\\frac{d}{dx} f(a)$ is just $0$ (because it's not a function of $x$), therefore we get:\n\t\n\t$$ \\frac{d}{dx} f(ax) = \\frac{d}{dx} f(x) $$\n\t\n\tWhat function $f$ would make the above equation valid? Let's differentiate left side and see what we get.\n\tBy implicit differentiation:\n\t\n\t$$ \\frac{d}{dx} f(ax) = \\frac{d}{dx} ax \\frac{d}{dx} f(ax) = a \\frac{d}{dx} f(ax) $$\n\t\n\tNow if $$\\frac{d}{dx} f(ax) $$ yields the reciprocal of it's argument $ax$, namely $\\frac{1}{ax}$ then:\n\t\n\t$$ \\frac{d}{dx} f(ax) =  a . \\frac{1}{ax} = \\frac{1}{x} = \\frac{d}{dx} f(x) $$\n\t\n\tWe now know the \\textit{derivative} of $f$ should give the reciprocal of it's argument, then $f$ itself is the \\textit{integration} of the reciprocal of it's argument:\n\t\n\t$$f(x) = \\int_{c}^{x} (1/t) dt$$\n\t\n\tWe are almost there.\n\tTo recap, the function $f$ that we got so far has the following property:\n\t\n\t$$ \\frac{d}{dx} f(ax) = \\frac{d}{dx} f(x) $$\n\t\n\tHowever, we initially differentiated the equation (1) and we got to this function so far.\n\tIf the equation had \\textbf{any other} constant beside $ln(a)$, it would still cancel out in the differentiation process.\n\tSo by the (second) fundamental theorem of Calculus, integrating both sides, give the functions \\textit{plus} some constant that it could have any value.\n\tTherefore for the function we got so far:\n\t\n\t$$ f(ax) = f(x) + C $$\n\t\n\tFor some constant $C$.\n\tHowever if we define $f$ as the integral of $1/t$ from \\textbf{\"\\boldmath{$1$} to \\boldmath{$x$}}\"  instead of an \\textbf{\"arbitrary \\boldmath{$c$} to \\boldmath{$x$}\"}, namely:\n\t\n\t$$f(x) = \\int_{1}^{x} (1/t) dt$$\n\t\n\tNot only the derivative of $f(ax)$ would equal to derivative of $f(x)$, moreover:\n\n\t$$ f(ax) = f(x) + f(a)$$\n\t\n\tBecause by letting $x = 1$ we get:\n\t\n\t$$ f(a) = f(1) + C$$\n\t$$ f(a) = 0 + C$$\n\t$$ f(a) = C $$\n\t\n\tAnd $f(ax)$ for other $x$s besides $x = 1$ would still give this constant - which is equal to $f(a)$ - plus $f(x)$. We are now done.\n\t\n\tSuch a function has a special name in math and its called \\textbf{natural logarithm} and it's denoted by $ln$:\n\t\n\t\\begin{equation}\n\tln(x) = \\int_{1}^{x} (1/t) dt\n\t\\end{equation}\n\n\t\\subsection{Logarithm in \"other bases\"}\n\t\n\tIf $b > 0$, $b \\neq 1$ and if $x > 0$, the logarithm of $x$ to the \"base\" $b$ is defined as:\n\t\n\t$$ \\log_b x = \\frac{ln x}{ln b} $$\n\t\n\tA common base $b$ is 10. Example:\n\t\n\t$$ \\log_{10} 1000 = \\frac{ln 1000}{ln 10} = \\frac{\\ln (10 * 10 * 10)}{ \\ln 10} = \\frac{3 \\ln 10}{\\ln 10} = 3 $$\n\t\n\tor for example another widely used base, logarithm in base 2:\n\t\n\t$$ \\log_{2} 8 = \\frac{ln 8}{ln 2} = \\frac{\\ln (2 * 2 * 2)}{ \\ln 2} = \\frac{3 \\ln 2}{\\ln 2} = 3 $$\n\t\n\t\\section{The constant $e$}\n\tThe constant $e$ is a number that we define as the value in which $\\ln(e) = 1$.\n\tPlugging it in the definition of the natural logarithm, it means it's a number which the area under the curve of $\\frac{1}{x}$ \\textit{from $1$ to that number $e$} is 1.\n\n\tNow a property of natural logarithm that we left out is the following property, for a \\textit{rational} $n$:\n\t\n\t$$ \\ln(x^n) = n\\ln(x) $$ \n\t\n\tProof (by power rule):\n\t\n\t$$ \\frac{d}{dx} \\ln(x^n) = \\frac{1}{x^n} . \\frac{d}{dx} x^n = \\frac{n}{x^n} . x^{n-1} = \\frac{n}{x} = n \\ln x$$\n\t\n\tEven though the following property is true only for the rational powers of $x^n$, we can \"fill in\" for the irrational numbers as well.\n\tBy defining the output for the irrational powers as the limit approaching to the closest neighboring rational power.\n\tGraphically we fill in the wholes in the graph for irrational numbers.\n\t\n\tTo recap, we have found a function and we called it $\\ln(x)$ which has the following properties:\n\t\\begin{flalign*}\n\t& 1) \\; \\ln(ax) = \\ln(a) + \\ln(x) &\\\\\n\t& 2) \\;\\; (\\ln x)' = \\frac{1}{x} &\\\\\n\t& 3) \\; \\ln(x^n) = n \\ln x &\n\t\\end{flalign*}\n\t\n\tNow we want to find the \\textit{inverse} of the natural logarithm.\n\tTo do so, what expression should we give to the natural logarithm that it would give us the term $x$ itself?\n\tSuch an expressions would be the inverse of the natural logarithm.\n\tThis expression is $e^x$; Because:\n\t\n\t$$ \\ln e^x = x \\ln e = x $$\n\t\n\tTherefore, $e^x$ is defined as the inverse of the natural logarithm:\n\t\n\t$$ e^x = \\ln ^{-1} x $$\n\t\n\tNow we will discover one of the most significant mathematical properties of this function, which appears frequently in the universe.\n\t\n\t\\section{The Function $\\mathbf{e^x}$}\n\tThe function $e^x$ has numerous important properties.\n\tOne of the most important ones, which we use over and over in circuitry and other fields as well is \\textit{the derivative of the function $e^x$ which is $e^x$ itself}.\n\t\n\tProof:\n\t$$ y = e^x $$\n\t\n\tTherefore (by the 3nd property of $\\ln$):\n\t\n\t$$ \\ln e^x = x $$\n\n\tTaking implicit differentiation of both-sides (by the 2nd property of $\\ln$):\n\t\n\t$$ \\frac{d}{dx} \\ln y = \\frac{d}{dx}x $$\n\t$$ \\frac{1}{y} \\frac{d}{dx} y = 1$$\n\t\n\tFinally:\n\t$$\\frac{d}{dx} y = y$$\n\t\n\tWhich means:\n\t\n\t\\vspace{5mm}\n\t\n\t\\begin{equation}\n\t\\frac{d}{dx} e^x = e^x\n\t\\end{equation}\n\t\n\t\\vspace{5mm}\n\t\n\tThis function is called the exponential function and is also denoted by \\boldmath$\\exp(x)$.\n\tThis function is the solution to \\textit{$y' = y$}.\n\tIn other words, what function gives the same values as it's instantaneous rate of change? $e^x$.\n\t\n\tConcept of logarithms and exponential function could be approached in many different ways.\n\tOne can differentiate the function $a^x$ via plugging it into the definition of the derivative.\n\tUsing this method we get a function times a weird-looking limit.\n\tThus continuing to prove that this limit is the inverse of the famous constant $e$ to the power of $a$; Then we shall call this inverse function as the logarithm in base $e$.\n\tAnother way which we used in this article is by defining the logarithm \\textit{first} then defining the constant $e$ as a number that if we give to the natural logarithm, it yields $1$.\n\tAnyhow all the different ways lead to the same concepts but we used the latter one which we think is the right way to explain these topics.\n\t\n\t\\subsection{Applications of the Function $e^x$}\n\tWe now examine a case which the exponential function appear in circuit analysis.\n\tAssume a simple circuit consisting of a battery, a resistor and an inductor.\n\tThese elements are connected in series and has the value as shown in the following schematic:\n\n\t\\begin{figure}[h!]\n \t\\centering\n\t\\begin{subfigure}[b]{0.6\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{circuit1.png}\n\t\\end{subfigure}\n\t\\end{figure}\n\t\n\tWe now want to analyze this circuit; This means that our goal is to find the voltage drops (of each element) and the currents flowing through each loop.\n\tFor analyzing this circuit we use the laws that come from the nature.\n\tNamely, conservative of energy (which is called KVL in circuit analysis), Ohm's law and the formula for induced voltage of an inductor.\n\tLet's start analyzing this circuit step-by-step.\n\t\n\tBy the law of conservation of energy, adding up the voltage drops of each element should sum up to zero.\n\tThis means:\n\t\n\t$$V_{battery} + V_{resistor} + V_{inductor} = 0$$\n\t\n\tNow this let's substitute corresponding values of each term.\n\tVoltage drop across a battery is constant over time and in this example is 5; Let's denote this constant $\\varepsilon$ for a general battery.\n\tTherefore $V_{battery} = \\varepsilon$.\n\tFor the resistor by Ohm's law, voltage drop across the resistor should be proportional to a constant, times the current flowing through it: $V_{resistor} = Ri$.\n\tAs for the inductor, voltage drop across it is proportional to a constant times the \\textit{instantaneous rate of change} of it's current over time\\footnote[1]{The exact reason why the induced voltage of an inductor (or more generally Faraday's law of induction) is proportional to rate of change of it's current over time comes from a more general theory which is the \"theory of relativity\".\n\tWe shall discuss these topics in the later articles in-details.\n\tBut in basic terms when electrons gain speed they (and space between them) gets contracted; Thus producing \"magnetic effect\".\n\tChanging of this magnetic effect causes instant accumulation of electrons which EMF gets produced.}.\n\tHence: $V_{inductor} = L\\frac{di}{dt}$.\n\tNow let's plug all of these into the equation. \n\t\n\t$$\\varepsilon - Ri(t) - L\\frac{di}{dt} = 0 $$\n\t\n\tBringing $-L\\frac{di}{dt}$ to the other side we get:\n\t\n\t$$\\varepsilon - Ri(t) = L\\frac{di}{dt} $$\n\t\n\tNow here comes the interesting part.\n\tLet's take the whole expression on the left-hand side as a single term and call it $U$.\n\tTherefore:\n\t\n\t$$ U = \\varepsilon - Ri(t) $$\n\t\n\tTaking a look at this expression, we see $\\varepsilon$ term is just a constant, therefore the $U$ is merely a function of $i$ over time.\n\tOn the right-hand side we have the derivative of $i$ over time! (times a constant $L$ too).\n\tEssentially what we have here is a function on one side and it's derivative on the other side.\n\tTo find this $U$ we simply have to look at a function \\textit{whose value at different inputs, are same as it's derivative at those points}.\n\tThis is were exponents come to play.\n\tSolving this equation, we get:\n\t\n\t\\begin{equation}\n\t \ti(t) = \\frac{\\varepsilon}{R}(1 - e^{-(R/L)t})\n\t\\end{equation}\n\t\n\tBy the way, the exact steps of how we got to this expression is omitted; They are merely algebraic manipulations for solving these differential equations. \n\tThe important part is that this function is in form of exponential function $e^x$.\n\t\n\tTo recap what really happened, we know by the physical property of an inductor that the voltage drop across it, is proportional to the rate of change of it's current over time.\n\tAnd this value, because of the conservation of energy, should be equal to the voltage gain/drop of the battery plus the resistor.\n\tThe voltage gain of battery is just a fixed number over time; But for the resistor we know from Ohm's law that the voltage drop across it is linearly proportional (approx. for a real resistor) to it's current. So from putting these facts together, we are looking for a set of values over time in which their instantaneous rate of change is the same as their own values at those points.\n\t\n\tFinally substituting values of $\\varepsilon$, $R$ and $L$ for this into this equation we get:\n\t\n\t$$ i(t) = 0.05(1 - e^{-(100)t})  $$\n\t\n\tPlotting this function we get:\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\begin{subfigure}[b]{0.9\\linewidth}\n\t\t\t\\includegraphics[width=\\linewidth]{Figure_1.png}\n\t\t\\end{subfigure}\n\t\\end{figure}\n\n\tSimilar situation would happen if we had a capacitor instead of an inductor.\n\tWith the difference that the part in which the derivative appears (in this case derivative of charge $Q$ over time instead of current $i$ over time), would be for the resistor.\n\tNamely, if we had a capacitor instead of an inductor in this circuit, we should have gotten:\n\t\n\t$$\\varepsilon - Ri(t) - \\frac{Q}{C} = 0 $$\n\t\n\tBecause the voltage drop across a capacitor is proportional to the accumulated charges $Q$ in one plate over a constant $C$ (capacitance).\n\tAnd that number, should be equal to the resistivity  $R$, times the current for the resistor part (Ohm's law).\n\tCurrent by definition is just the change of $Q$ overtime ($i(t) = \\frac{dq}{dt}$).\n\tConsequently, solving that differential equation should give us the change of $Q$ over time (instead of $i$) as an exponential.\n\t\n\tIn future tutorials we shall discuss and analyze the circuits consisting of both capacitor and inductor beside resistors and power supplies.\n\tFor now, our goal was to get the big picture of the math behind this circuits and solve a basic one.\n\t\n\t\\section{What's Next?}\n\tIn the follow up article, we will discuss some math behind circuits consisting of sinusoidal signals; Namely \\textit{root mean square (rms)} and to see why is's convenient to define such an expression in AC circuitry.\n\tSubsequently we'll start writing some software code that we'd use in later articles and projects as boilerplate.\n\t\n\tThese documents are published under an open license (see the project's root directory for more info), and were intended to be part of an open and a collaborative project.\n\tFeel free to fork this document, send pull request and also give your feedback.\n\tThanks for reading!\n\t\n\\end{document}\n\\end{document}\n", "meta": {"hexsha": "75f07eb9b5df78e0a2f0f34ce133ef14718a332b", "size": 15049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2_Logarithm_and_exponential_functions/ln_and_exp_functions.tex", "max_stars_repo_name": "DigitalNX/docs", "max_stars_repo_head_hexsha": "7bf9ca4ae054cd0816f45da67dff96000600420f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-01-16T19:10:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:10:55.000Z", "max_issues_repo_path": "2_Logarithm_and_exponential_functions/ln_and_exp_functions.tex", "max_issues_repo_name": "DigitalNX/docs", "max_issues_repo_head_hexsha": "7bf9ca4ae054cd0816f45da67dff96000600420f", "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": "2_Logarithm_and_exponential_functions/ln_and_exp_functions.tex", "max_forks_repo_name": "DigitalNX/docs", "max_forks_repo_head_hexsha": "7bf9ca4ae054cd0816f45da67dff96000600420f", "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.0798722045, "max_line_length": 393, "alphanum_fraction": 0.7140673799, "num_tokens": 4338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519376, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.6583202684180256}}
{"text": "\\subsection{Banach space interpolation}\\label{subsec:banach_space_interpolation}\n\n\\begin{definition}\\label{def:interpolated_topological_vector_space}\\mcite[24]{BerghLofstrom1976}\n  Let \\( \\BbbK \\) be either the \\hyperref[def:set_of_real_numbers]{field \\( \\BbbR \\) of real numbers} or the \\hyperref[def:set_of_real_numbers]{field \\( \\BbbC \\) of complex numbers}.\n\n  \\begin{thmenum}\n    \\thmitem{def:interpolated_topological_vector_space/compatibility} We say that two \\hyperref[def:topological_vector_space]{topological vector spaces} \\( \\mscrX_0 \\) and \\( \\mscrX_1 \\) are \\term{compatible} if they can both be \\hyperref[def:morphism_invertibility/left_cancellative]{embedded} \\hyperref[def:global_continuity]{continuously} into a \\hyperref[def:separation_axioms/T2]{Hausdorff} topological vector space \\( \\mscrU \\), in which case we can regard them as subspaces of \\( \\mscrU \\).\n\n    In particular, both \\( \\mscrX_0 \\) and \\( \\mscrX_1 \\) are Hausdorff. We write \\( \\overline{\\mscrX} \\coloneqq (\\mscrX_0, \\mscrX_1) \\).\n\n    \\thmitem{def:interpolated_topological_vector_space/intersection} Denote by\n    \\begin{equation*}\n      \\Delta \\overline{\\mscrX} \\coloneqq \\mscrX_0 \\cap \\mscrX_1\n    \\end{equation*}\n    the \\term{intersection} of \\( \\mscrX_0 \\) and \\( \\mscrX_1 \\) (when regarded as subspaces of \\( \\mscrU \\)).\n\n    \\thmitem{def:interpolated_topological_vector_space/sum} Denote by\n    \\begin{equation*}\n      \\Sigma \\overline{\\mscrX} \\coloneqq ( \\mscrX_0 + \\mscrX_1 )\n    \\end{equation*}\n    the \\term{sum} of \\( \\mscrX_0 \\) and \\( \\mscrX_1 \\). If \\( x \\in \\Sigma \\overline{\\mscrX} \\), then there exist (possibly nonunique) vectors \\( x_0 \\in X_0 \\) and \\( x_1 \\in X_1 \\) such that \\( x = x_0 + x_1 \\).\n\n    \\thmitem{def:interpolated_topological_vector_space/intermediate_space} Let \\( \\overline{\\mscrX} \\) be a pair of compatible spaces. We say that the space \\( \\mscrX \\) is an \\term{intermediate} space for \\( \\overline{\\mscrX} \\) if \\( \\Delta \\overline{\\mscrX} \\subseteq X \\subseteq \\Sigma \\overline{\\mscrX} \\) with continuous linear inclusions.\n\n    \\thmitem{def:interpolated_topological_vector_space/morphisms} We introduce \\hyperref[def:category/morphisms]{morphisms} between two compatible pairs \\( \\overline{\\mscrX} \\) and \\( \\overline{\\mscrY} \\) that are, strictly speaking, not \\hyperref[def:function]{functions} between the pairs themselves. We define an \\term{operator} \\( T: \\overline{\\mscrX} \\to \\overline{\\mscrY} \\) between compatible pairs to be a function \\( T \\) from \\( \\Sigma \\overline{\\mscrX} \\) to \\( \\Sigma \\overline{\\mscrY} \\) that satisfies the additional conditions\n    \\begin{align*}\n      T(\\mscrX_0) \\subseteq Y_0\n      &&\n      T(\\mscrX_1) \\subseteq Y_1.\n    \\end{align*}\n\n    \\thmitem{def:interpolated_topological_vector_space/category} If \\( \\cat{C} \\) is a \\hyperref[def:subcategory]{subcategory} of the category \\hyperref[def:category_of_topological_vector_spaces]{\\( \\cat{TopVect}_{\\BbbK} \\)} of topological vector spaces. We define the category \\( \\cat{Interp}_{\\cat{C}} \\) as the product category \\( \\cat{TopVect}_{\\BbbK} \\times \\cat{TopVect}_{\\BbbK} \\). More explicitly:\n    \\begin{refenum}\n      \\refitem{def:category/objects} The \\hyperref[def:set]{class} of objects is the class of all pairs of \\hyperref[def:interpolated_topological_vector_space/compatibility]{compatible spaces}.\n      \\refitem{def:category/morphisms} The morphisms between two compatible pairs are the \\hyperref[def:interpolated_topological_vector_space/morphisms]{continuous linear operators} \\( T: \\overline{\\mscrX} \\to \\overline{\\mscrY} \\) between them.\n      \\refitem{def:category/composition} Composition of morphisms is the usual \\hyperref[def:multi_valued_function/composition]{function composition} if we regard a morphism \\( T: \\overline{\\mscrX} \\to \\overline{\\mscrY} \\) as a function from \\( \\Sigma \\overline{\\mscrX} \\) to \\( \\Sigma \\overline{\\mscrY} \\).\n    \\end{refenum}\n\n    \\thmitem{def:interpolated_topological_vector_space/interpolation_space} We say that the intermediate spaces \\( \\mscrX \\) for \\( \\overline{\\mscrX} \\) and \\( \\mscrY \\) for \\( \\overline{\\mscrY} \\) are a pair of \\term{interpolation spaces} with respect to \\( \\overline{\\mscrX} \\) and \\( \\overline{\\mscrY} \\) if, for any continuous linear \\hyperref[def:interpolated_topological_vector_space/morphisms]{operator} \\( T: \\overline{\\mscrX} \\to \\overline{\\mscrY} \\) between the compatible pairs, we have \\( T(\\mscrX) \\subseteq Y \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{def:banach_space_sum_and_intersection_norms}\\mcite[24]{BerghLofstrom1976}\n  Let \\( \\mscrX \\coloneqq (\\mscrX_0, \\mscrX_1) \\) be a \\hyperref[def:interpolated_topological_vector_space/compatibility]{compatible pair} of \\hyperref[def:banach_space]{Banach spaces}.\n\n  \\begin{thmenum}\n    \\thmitem{def:banach_space_sum_and_intersection_norms/intersection} The intersection \\( \\Delta \\overline{\\mscrX} = \\mscrX_0 \\cap \\mscrX_1 \\) is a Banach space with norm\n    \\begin{equation}\\label{eq:def:banach_space_sum_and_intersection_norms/intersection}\n      \\norm{x}_{\\Delta \\overline{\\mscrX}} \\coloneqq \\max \\set{ \\norm{x}_{\\mscrX_0}, \\norm{x}_{\\mscrX_1} }.\n    \\end{equation}\n\n    \\thmitem{def:banach_space_sum_and_intersection_norms/sum} The sum \\( \\Sigma \\overline{\\mscrX} = \\mscrX_0 + \\mscrX_1 \\) is a Banach space with norm\n    \\begin{equation}\\label{eq:def:banach_space_sum_and_intersection_norms/sum}\n      \\norm{x}_{\\Delta \\overline{\\mscrX}} \\coloneqq \\inf \\set{ \\norm{x_0}_{\\mscrX_0} + \\norm{x_1}_{\\mscrX_1} : x_0 + x_1 = x }.\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{def:banach_space_sum_and_intersection_norms/intersection} We will first show that \\( \\norm{x}_{\\Delta \\overline{\\mscrX}} \\) is indeed a norm.\n  \\begin{refenum}\n    \\refitem{def:norm/N1} We have\n    \\begin{equation}\\label{eq:def:banach_space_sum_and_intersection_norms/intersection/zero}\n      \\norm{x}_{\\Delta \\overline{\\mscrX}} = \\max \\set{ \\norm{x}_{\\mscrX_0}, \\norm{x}_{\\mscrX_1} } = 0 \\T{if and only if} \\norm{x}_{\\mscrX_0} = \\norm{x}_{\\mscrX_1} = 0.\n    \\end{equation}\n\n    Clearly \\( 0 \\) belongs to both \\( \\mscrX_0 \\) and \\( \\mscrX_1 \\) hence to their intersection. Therefore, \\eqref{eq:def:banach_space_sum_and_intersection_norms/intersection/zero} is satisfied if and only if \\( x = 0 \\).\n\n    \\refitem{def:norm/N2} Absolute homogeneity follows from\n    \\begin{equation*}\n      \\norm{tx}_{\\Delta \\overline{\\mscrX}}\n      =\n      \\max \\set{ \\norm{tx}_{\\mscrX_0}, \\norm{tx}_{\\mscrX_1} }\n      \\reloset {\\ref{def:norm/N2}} =\n      \\abs{t} \\max \\set{ \\norm{x}_{\\mscrX_0}, \\norm{x}_{\\mscrX_1} }\n      =\n      \\abs{t} \\norm{x}_{\\Delta \\overline{\\mscrX}}.\n    \\end{equation*}\n\n    \\refitem{def:norm/N3} Subadditivity follows from\n    \\begin{balign*}\n      \\norm{x + y}_{\\Delta \\overline{\\mscrX}}\n      &=\n      \\max \\set{ \\norm{x + y}_{\\mscrX_0}, \\norm{x + y}_{\\mscrX_1} }\n      \\reloset {\\ref{def:norm/N3}} \\leq \\\\ &\\leq\n      \\max \\set{ \\norm{x}_{\\mscrX_0} + \\norm{y}_{\\mscrX_0}, \\norm{x}_{\\mscrX_1} + \\norm{y}_{\\mscrX_1} }\n      \\reloset {\\ref{eq:thm:preordered_magma_max_distributivity}} \\leq \\\\ &\\leq\n      \\max \\set{ \\norm{x}_{\\mscrX_0}, \\norm{x}_{\\mscrX_1} } + \\max \\set{ \\norm{y}_{\\mscrX_0}, \\norm{y}_{\\mscrX_1} }\n      = \\\\ &=\n      \\norm{x}_{\\Delta \\overline{\\mscrX}} + \\norm{y}_{\\Delta \\overline{\\mscrX}}.\n    \\end{balign*}\n  \\end{refenum}\n\n  We will now show the completeness of \\( \\norm{\\cdot}_{\\Delta \\overline{\\mscrX}} \\) directly. Let \\( \\{ x_k \\}_{k=1}^\\infty \\subseteq \\Delta \\overline{\\mscrX} \\) be a \\hyperref[def:fundamental_net]{fundamental sequence}. Both \\( \\mscrX_0 \\) and \\( \\mscrX_1 \\) are complete, therefore \\( \\{ x_k \\}_{k=1}^\\infty \\) converges to the same value. Both are subspaces of \\( \\mscrU \\), therefore the limit of the sequence is the same in both. In particular, it belongs to the intersection \\( \\Delta \\overline{\\mscrX} \\).\n\n  Denote the limit of \\( \\{ x_k \\}_{k=1}^\\infty \\) by \\( x \\). Let \\( \\varepsilon > 0 \\) and let \\( k_0 \\) be an index such that both \\( \\norm{x_k - \\xi_0}_{\\mscrX_0} < \\varepsilon \\) and \\( \\norm{x_k - \\xi_1}_{\\mscrX_1} < \\varepsilon \\) whenever \\( k \\geq k_0 \\). Then, for any \\( k \\geq k_0 \\),\n  \\begin{equation*}\n    \\norm{x_k - x}_{\\Delta \\overline{\\mscrX}}\n    =\n    \\max\\set{\\norm{x_k - x}_{\\mscrX_0}, \\norm{x_k - x}_{\\mscrX_1}}\n    <\n    \\varepsilon.\n  \\end{equation*}\n\n  Therefore, the sequence \\( \\{ x_k \\}_{k=1}^\\infty \\) converges to \\( x_0 \\) in \\( \\Delta \\overline{\\mscrX} \\).\n\n  \\SubProofOf{def:banach_space_sum_and_intersection_norms/sum} Again, we will first show that \\( \\norm{x}_{\\Sigma \\overline{\\mscrX}} \\) is indeed a norm.\n  \\begin{refenum}\n    \\refitem{def:norm/N1} Analogously to \\ref{def:banach_space_sum_and_intersection_norms/sum},\n    \\begin{equation*}\n      \\norm{x}_{\\Sigma \\overline{\\mscrX}} = \\inf \\set{ \\norm{x_0}_{\\mscrX_0} + \\norm{x_1}_{\\mscrX_1} : x_0 + x_1 = x } = 0\n    \\end{equation*}\n    if and only if\n    \\begin{equation*}\n      \\norm{x}_{\\mscrX_0} = \\norm{x}_{\\mscrX_1} = 0.\n    \\end{equation*}\n\n    \\refitem{def:norm/N2} Absolute homogeneity follows from\n    \\begin{equation*}\n      \\norm{tx}_{\\Sigma \\overline{\\mscrX}}\n      =\n      \\inf \\set{ \\norm{tx_0}_{\\mscrX_0} + \\norm{tx_1}_{\\mscrX_1} | x_0 + x_1 = x }\n      \\reloset {\\ref{def:norm/N2}} =\n      \\abs{t} \\norm{x}_{\\Sigma \\overline{\\mscrX}}.\n    \\end{equation*}\n\n    \\refitem{def:norm/N3} Subadditivity follows from\n    \\begin{align*}\n      &\\phantom{{}={}}\n      \\norm{x + y}_{\\Sigma \\overline{\\mscrX}}\n      = \\\\ &=\n      \\inf \\set{ \\left( \\norm{x_0}_{\\mscrX_0} + \\norm{x_1}_{\\mscrX_1} \\right) + \\left( \\norm{y_0}_{\\mscrX_0} + \\norm{y_1}_{\\mscrX_1} \\right) | \\substack{\\textstyle{x_0 + x_1 = x} \\\\ \\textstyle{y_0 + y_1 = y}} }\n      \\leq \\\\ &\\leq\n      \\norm{x}_{\\Sigma \\overline{\\mscrX}} + \\norm{y}_{\\Sigma \\overline{\\mscrX}}.\n    \\end{align*}\n  \\end{refenum}\n\n  It remains to prove the completeness of \\( \\norm{\\cdot}_{\\Sigma \\overline{\\mscrX}} \\). Let \\( \\{ x_0^{(k)} + x_1^{(k)} \\}_{k=1}^\\infty \\subseteq \\Sigma \\overline{\\mscrX} \\) be a \\hyperref[def:fundamental_net]{fundamental sequence}. Fix \\( \\varepsilon > 0 \\). Then there exists an index \\( m_0 \\) such that \\( k, m \\geq k_0 \\) implies\n  \\begin{equation*}\n    \\norm{x_0^{(k)} + x_1^{(k)} - x_0^{(m)} + x_1^{(m)}}_{\\Sigma \\overline{\\mscrX}} < \\varepsilon.\n  \\end{equation*}\n\n  But\n  \\begin{equation*}\n    \\norm{x_0^{(k)} - x_0^{(m)}}_{\\mscrX_0}\n    \\leq\n    \\norm{\\left(x_0^{(k)} + x_1^{(k)} \\right) - \\left( x_0^{(m)} + x_1^{(m)} \\right)}_{\\Sigma \\overline{\\mscrX}}\n    <\n    \\varepsilon,\n  \\end{equation*}\n  hence the sequence \\( \\{ x_0^{(k)} \\}_{k=1}^\\infty \\) is fundamental. Since \\( \\mscrX_0 \\) is complete, this sequence has a limit, which we will denote by \\( \\xi_0 \\). We define \\( \\xi_1 \\) analogously.\n\n  With the same \\( \\varepsilon \\), denote by \\( k_0 \\) an index such that both \\( \\norm{x_0^{(k)} - \\xi_0}_{\\mscrX_0} < \\tfrac \\varepsilon 2 \\) and \\( \\norm{x_1^{(k)} - \\xi_1}_{\\mscrX_1} < \\tfrac \\varepsilon 2 \\) whenever \\( k \\geq k_0 \\).\n\n  Then\n  \\begin{balign*}\n    &\\phantom{{}={}}\n    \\norm{\\left( x_0^{(k)} + x_1^{(k)} \\right) - \\left( \\xi_0 + \\xi_1 \\right)}_{\\Sigma \\overline{\\mscrX}}\n    = \\\\ &=\n    \\inf \\set{ \\norm{x_0}_{\\mscrX_0} + \\norm{x_1}_{\\mscrX_1} : x_0 + x_1 = \\left( x_0^{(k)} + x_1^{(k)} \\right) - \\left( \\xi_0 + \\xi_1 \\right) }\n    \\leq \\\\ &\\leq\n    \\norm{x_0^{(k)} - \\xi_0}_{\\mscrX_0} + \\norm{x_1^{(k)} - \\xi_1}_{\\mscrX_1}\n    <\n    \\tfrac \\varepsilon 2 + \\tfrac \\varepsilon 2\n    =\n    \\varepsilon.\n  \\end{balign*}\n\n  Therefore, \\( \\xi_0 + \\xi_1 \\) is the limit of the sequence \\( \\{ x_0^{(k)} + x_1^{(k)} \\}_{k=1}^\\infty \\subseteq \\Sigma \\overline{\\mscrX} \\) in \\( \\Sigma \\overline{\\mscrX} \\).\n\\end{proof}\n\n\\begin{example}\\label{thm:lp_interpolation_spaces/definition}\n  The spaces \\( L^p(\\BbbR) \\) are interpolation spaces for the pair \\( (L^1(\\BbbR), L^\\infty(\\BbbR)) \\). The pair is compatible because both are subspaces of the space \\( S(\\BbbR) \\) of all Lebesgue-measurable real function with metric\n  \\begin{equation*}\n    \\rho(f, g) \\coloneqq \\int_{\\BbbR} \\frac {\\abs{f(x) - g(x)}} {1 + \\abs(f(x) - g(x))} d\\lambda.\n  \\end{equation*}\n\\end{example}\n\n\\begin{definition}\\label{def:lebesgue_space}\\cite[6]{BerghLofstrom1976}\n  Let \\( \\mu: U \\to [0, \\infty] \\) be a positive measure and \\( p \\) be a positive real number. The \\term{Lebesgue space} \\( L_p \\) is defined as the set of bounded functions \\( f: U \\mapsto \\BbbK \\) such that the norm\n  \\begin{equation*}\n    \\norm{f}_{L_p} \\coloneqq \\begin{dcases}\n      \\parens[\\Big]{\\int_U \\abs{f(t)}^p dt}^{1/p}, &0 < p < \\infty \\\\\n      \\ess\\sup_{t \\in U} \\abs{f(t)} , &p = \\infty\n    \\end{dcases}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{theorem}[The Riesz-Thorin interpolation theorem]\\label{thm:riesz_thorin}\\mcite[24]{BerghLofstrom1976}\n  Fix two measure spaces \\( (U, \\mu) \\) and \\( (V, \\nu) \\). Let \\( T: S(U, \\mu) \\to S(V, \\nu) \\) be a continuous linear map between the corresponding spaces of measurable functions.\n\n  Suppose that for some real numbers \\( p_0, p_1, q_0, q_1 \\geq 1 \\) we have\n  \\begin{equation*}\n    T(L^{p_j}(U, \\mu)) \\subseteq T(L^{q_j}(V, \\nu)), j = 0, 1.\n  \\end{equation*}\n\n  Additionally, let \\( \\theta \\in (0, 1) \\) and\n  \\begin{align*}\n    \\frac 1 p = \\frac {1 - \\theta} {p_0} + \\frac {\\theta} {p_1}\n    &&\n    \\frac 1 q = \\frac {1 - \\theta} {q_0} + \\frac {\\theta} {q_1}.\n  \\end{align*}\n\n  Then\n  \\begin{equation*}\n    T(L^p(U, \\mu)) \\subseteq L^q(V, \\nu)\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\norm{T}_{\\hom(L^p, L^q)} \\leq \\norm{T}_{\\hom(L^{p_0}, L^{q_0})}^{1 - \\theta} \\norm{T}_{\\hom(L^{p_1}, L^{q_1})}^\\theta.\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{definition}\\label{def:distribution_function}\\cite[6]{BerghLofstrom1976}\n  Let \\( \\mu: U \\to [0, \\infty] \\) be a positive measure and \\( p \\) be a positive real number.\n\n  \\begin{thmenum}\n    \\thmitem{def:distribution_function/distribution_function} Given a scalar-valued function \\( f: U \\mapsto \\BbbK \\), we define its \\term{distribution function} as\n    \\begin{align*}\n      &m_f: [0, \\infty] \\to \\BbbK \\\\\n      &m_f(\\sigma) \\coloneqq \\mu(\\set{ x :  > \\sigma }).\n    \\end{align*}\n\n    \\thmitem{def:distribution_function/rearrangement} We define the \\term{decreasing rearrangement} of \\( f \\) as\n    \\begin{equation*}\n      f^*(t) \\coloneqq \\inf\\set{ \\sigma : m_f(\\sigma) \\leq t }.\n    \\end{equation*}\n\n    \\thmitem{def:distribution_function/lorenz_space} The \\( (p, q)-\\)Lorenz space, for potentially infinite positive \\( q > 0 \\), is the set of functions \\( f: U \\mapsto \\BbbK \\) for which the quasinorm\n    \\begin{equation*}\n      \\norm{f}_{L_{p,q}} \\coloneqq \\begin{dcases}\n        \\parens[\\Big]{\\int_0^\\infty \\parens[\\Big]{\\frac {f^*(\\tau)} {\\tau^p}}^q \\frac {d t} t}^{\\frac 1 q}, &1 \\leq q < \\infty \\\\\n        \\ess\\sup\\parens[\\Big]{\\frac {f^*(t)} {t^p}}, &q = \\infty\n      \\end{dcases}\n    \\end{equation*}\n    is finite.\n\n    In particular, when \\( q = \\infty \\), we use the notation\n    \\begin{equation*}\n      \\norm{f}_{L^{p*}} \\coloneqq \\parens[\\Big]{p \\int_0^\\infty \\sigma^p m_f(\\sigma) \\frac {d \\sigma} \\sigma}^{\\frac 1 p}\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{theorem}[The Marcinkiewicz interpolation theorem]\n  Fix two measure spaces \\( (U, \\mu) \\) and \\( (V, \\nu) \\). Let \\( T: S(U, \\mu) \\to S(V, \\nu) \\) be a continuous linear map between the corresponding spaces of measurable functions.\n\n  Suppose that for some real numbers \\( p_0, p_1, q_0, q_1 \\geq 1 \\) we have\n  \\begin{equation*}\n    T(L^{p_j}(U, \\mu)) \\subseteq T(L^{q_j *}(V, \\nu)), j = 0, 1.\n  \\end{equation*}\n\n  Additionally, let \\( \\theta \\in (0, 1) \\) and\n  \\begin{align*}\n    \\frac 1 p = \\frac {1 - \\theta} {p_0} + \\frac {\\theta} {p_1}\n    &&\n    \\frac 1 q = \\frac {1 - \\theta} {q_0} + \\frac {\\theta} {q_1}.\n  \\end{align*}\n\n  Then, if \\( p \\leq q \\),\n  \\begin{equation*}\n    T(L^p(U, \\mu)) \\subseteq L^q(V, \\nu)\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\norm{T}_{\\hom(L^p, L^q)} \\leq C_\\theta \\norm{T}_{\\hom(L^{p_0}, L^{q_0*})}^{1 - \\theta} \\norm{T}_{\\hom(L^{p_1}, L^{q_1*})}^\\theta\n  \\end{equation*}\n  for some constant \\( C_\\theta \\).\n\\end{theorem}\n\n\\begin{definition}\\label{def:banach_interpolation_space_exponent}\\mcite[27]{BerghLofstrom1976}\n  Let \\( \\overline{\\mscrX} \\coloneqq ( \\mscrX_0, \\mscrX_1 ) \\) and \\( \\overline{\\mscrY} \\coloneqq ( \\mscrY_0, \\mscrY_1 ) \\) be compatible pairs of Banach spaces. If \\( \\mscrX \\) and \\( \\mscrY \\) are a pair of interpolation spaces and, additionally, the inequality\n  \\begin{equation}\\label{da:def:banach_interpolation_space_exponent}\n    \\norm{T}_{\\hom(\\mscrX, \\mscrY)} \\leq C \\norm{T}_{\\hom(\\mscrX_0, \\mscrY_0)}^{1-\\theta} \\cdot \\norm{T}_{\\hom(\\mscrX_1, \\mscrY_1)}^{\\theta}\n  \\end{equation}\n  holds for some constant \\( C > 0 \\) and \\( \\theta \\in [0, 1] \\), we say that the pair \\( (\\mscrX, \\mscrY) \\) are \\term{interpolation spaces of exponent} \\( \\theta \\).\n\n  If, additionally, \\( C = 1 \\), we say that \\( (\\mscrX, \\mscrY) \\) is an \\term{exact pair} of interpolation spaces.\n\\end{definition}\n\n\\begin{definition}\\label{def:k_functional}\\mcite[38]{BerghLofstrom1976}\n  Let \\( \\overline{\\mscrX} \\coloneqq ( \\mscrX_0, \\mscrX_1 ) \\) be a compatible pair of Banach spaces. Instead of the norm \\( \\norm{\\cdot}_{\\mscrX_1} \\) in \\( \\mscrX_1 \\), we can consider \\hyperref[def:equivalent_metrics]{equivalent norms} of the type \\( t\\norm{\\cdot}_{\\mscrX_1} \\) for \\( t \\geq 0 \\). Furthermore, we can also introduce equivalent norms in \\( \\Sigma \\overline{\\mscrX} \\) via the \\term{\\( K \\)-functional}\n  \\begin{alignedeq}\\label{eq:def:k_functional}\n    &K: (0, \\infty) \\times {\\Sigma \\overline{\\mscrX}} \\\\\n    &K(t, x) \\coloneqq \\inf \\set{ \\norm{x_0}_{\\mscrX_0} + t\\norm{x_1}_{\\mscrX_1} : x_0 + x_1 = x }.\n  \\end{alignedeq}\n\n  See \\fullref{def:k_functional_properties/equivalent_norm} for a proof that \\( x \\mapsto K(t, x) \\) for a fixed \\( t \\geq 0 \\) is an equivalent norm in the sum \\( \\Sigma \\overline{\\mscrX} \\).\n\\end{definition}\n\n\\begin{proposition}\\label{def:k_functional_properties}\\mcite[38]{BerghLofstrom1976}\n  The \\hyperref[def:k_functional]{\\( K \\)-functional} has the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{def:k_functional_properties/basic} For any fixed \\( x \\in \\Sigma \\overline{\\mscrX} \\), the function \\( t \\mapsto K(t, x) \\) is positive, \\hyperref[def:partially_ordered_set/homomorphism]{monotone} and \\hyperref[def:convex_functions]{concave}.\n\n    \\thmitem{def:k_functional_properties/inequality} For positive real numbers \\( t, s > 0 \\), we have the following inequality:\n    \\begin{equation}\\label{eq:def:k_functional_properties/inequality}\n      K(t, x) \\leq \\max\\set{1, \\frac t s} K(s, x).\n    \\end{equation}\n\n    \\thmitem{def:k_functional_properties/equivalent_norm} For any fixed \\( t > 0 \\), the function \\( x \\mapsto K(t, x) \\) is an \\hyperref[def:equivalent_metrics]{equivalent norm} in the sum \\( \\Sigma \\overline{\\mscrX} \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{def:k_functional_properties/basic} That \\( t \\mapsto K(t, x) \\) is positive is a slight generalization of \\fullref{def:norm/N1}, which can be proved as in \\fullref{def:banach_space_sum_and_intersection_norms/sum}.\n\n  Monotonicity follows from the monotonicity of the infimum.\n\n  To see that \\( t \\mapsto K(t, x) \\) is concave, fix \\( x \\), \\( \\lambda \\in [0, 1] \\) and \\( t, s > 0 \\). We have\n  \\begin{align*}\n    &\\phantom{{}={}}\n    K(\\lambda t + (1 - \\lambda) s, x)\n    = \\\\ &=\n    \\inf \\set{ \\norm{x_0}_{\\mscrX_0} + (\\lambda t + (1 - \\lambda) s)\\norm{x_1}_{\\mscrX_1} | x_0 + x_1 = x }\n    = \\\\ &=\n    \\inf \\set{ \\lambda \\left(\\norm{x_0}_{\\mscrX_0} + t \\norm{x_1}_{\\mscrX_1} \\right) + (1 - \\lambda) \\left(\\norm{x_0}_{\\mscrX_0} + s \\norm{x_1}_{\\mscrX_1} \\right) | x_0 + x_1 = x }\n    \\geq \\\\ &\\geq\n    \\lambda K(t, x) + (1 - \\lambda) K(s, x).\n  \\end{align*}\n\n  \\SubProofOf{def:k_functional_properties/inequality} Fix positive real numbers \\( t, s > 0 \\).\n  \\begin{itemize}\n    \\item If \\( t \\leq s \\), by monotonicity we have\n    \\begin{equation}\\label{eq:def:k_functional_properties/inequality/monotonicity}\n      K(t, x) \\leq K(s, x)\n    \\end{equation}\n\n    \\item If \\( t > s \\), we use concavity with\n    \\begin{equation*}\n      s = \\frac s t t + \\left(1 - \\frac s t \\right) 0\n    \\end{equation*}\n    to obtain\n    \\begin{equation*}\n      K(s, x) \\geq \\frac s t K(t, x) + \\left(1 - \\frac s t \\right) K(0, x).\n    \\end{equation*}\n\n    By positivity of \\( K \\), we have \\( K(t, x) = 0 \\) if and only if \\( t = 0 \\), hence\n    \\begin{equation}\\label{eq:def:k_functional_properties/inequality/concavity}\n      K(t, x) \\leq \\frac t s K(s, x).\n    \\end{equation}\n  \\end{itemize}\n\n  Combining \\eqref{eq:def:k_functional_properties/inequality/monotonicity} and \\eqref{eq:def:k_functional_properties/inequality/concavity}, we obtain \\eqref{eq:def:k_functional_properties/inequality}.\n\n  \\SubProofOf{def:k_functional_properties/equivalent_norm} That \\( x \\mapsto K(t, x) \\) for a fixed \\( t > 0 \\) is a slight generalization of the proof in \\fullref{def:banach_space_sum_and_intersection_norms/sum}.\n\n  That the norms \\( \\norm{\\cdot}_{\\Sigma \\overline{\\mscrX}} \\) and \\( K(t, \\cdot) \\) are equivalent follows from \\eqref{eq:def:k_functional_properties/inequality} with \\( s = 1 \\) for the upper bound and \\( t = 1, s = t \\) for the lower bound. That is,\n  \\begin{equation*}\n    \\min\\set{1, t} \\underbrace{K(1, x)}_{\\norm{x}_{\\Sigma \\overline{\\mscrX}}} \\leq K(t, x) \\leq \\max\\set{1, t} \\underbrace{K(1, x)}_{\\norm{x}_{\\Sigma \\overline{\\mscrX}}}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{thm:lp_interpolation_spaces/k_functional}\n  The \\hyperref[def:k_functional]{\\( K \\)-functional} for the pair \\( (L_1(\\BbbR), L_\\infty(\\BbbR)) \\) from \\fullref{thm:lp_interpolation_spaces/definition} is\n  \\begin{equation*}\n    K(t, f) \\coloneqq \\int_0^t f^*(\\tau) d\\tau.\n  \\end{equation*}\n\\end{example}\n\n\\begin{definition}\\label{def:lorenz_quasinorm}\n  For \\( \\theta \\in \\BbbR \\), \\( q \\in (0, \\infty] \\) and nonnegative functions \\( g: [0, \\infty) \\to [0, \\infty] \\) we define\n  \\begin{equation}\\label{eq:def:lorenz_quasinorm}\n    \\Phi_{\\theta,q}(g) \\coloneqq \\begin{dcases}\n      \\left( \\int_0^\\infty \\left( \\frac {g(\\tau)} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau \\right)^{\\tfrac 1 q}, &0 < q < \\infty \\\\\n      \\ess\\sup_{t \\geq 0} \\left( \\frac {g(t)} {t^\\theta} \\right),                                                &q = \\infty\n    \\end{dcases}\n  \\end{equation}\n  and\n  \\begin{equation}\\label{eq:def:lorenz_quasinorm/gamma}\n    \\gamma_{\\theta,q} \\coloneqq \\Phi_{\\theta,q}(\\min(t, 1)).\n  \\end{equation}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:lorenz_quasinorm/properties}\n  The function \\hyperref[def:lorenz_quasinorm]{\\( \\Phi_{\\theta,q} \\)} has the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:lorenz_quasinorm/properties/reciprocal} For \\( s > 0 \\) and \\( h(t) \\coloneqq g(\\tfrac t s) \\) we have\n    \\begin{equation}\\label{eq:thm:def:lorenz_quasinorm/properties/reciprocal}\n      \\Phi_{\\theta,q}(h) = \\frac 1 {s^{\\theta}} \\Phi_{\\theta,q}(g).\n    \\end{equation}\n\n    \\thmitem{thm:def:lorenz_quasinorm/properties/gamma} For finite \\( q \\) we have\n    \\begin{equation}\\label{eq:thm:def:lorenz_quasinorm/properties/gamma}\n      \\gamma_{\\theta,q} = \\left( \\frac 1 {q \\theta (1 - \\theta)} \\right)^{\\tfrac 1 q}.\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:lorenz_quasinorm/properties/reciprocal} The case \\( q = \\infty \\) is obvious. For \\( 0 < q < \\infty \\), we have\n  \\begin{balign*}\n    \\Phi_{\\theta,q}(h)\n    &=\n    \\left( \\int_0^\\infty \\left( \\frac {h(\\tau)} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau \\right)^{\\tfrac 1 q}\n    = \\\\ &=\n    \\left( \\frac 1 {s^{\\theta q}} \\int_0^\\infty \\left( \\frac {g(\\tfrac \\tau s)} {\\left(\\tfrac \\tau s \\right)^\\theta} \\right)^q \\frac {d{\\tfrac \\tau s}} {\\tfrac \\tau s} \\right)^{\\tfrac 1 q}\n    = \\\\ &=\n    \\frac 1 {s^{\\theta}} \\Phi_{\\theta,q}(g).\n  \\end{balign*}\n\n  \\SubProofOf{thm:def:lorenz_quasinorm/properties/gamma} We can raise \\( \\gamma_{\\theta,q} \\) to the \\( q \\)-th power for brevity of notation:\n  \\begin{balign*}\n    \\gamma_{\\theta,q}^q\n    &=\n    \\Phi_{\\theta,q}(\\min(t, 1))^q\n    = \\\\ &=\n    \\int_0^1 \\left( \\frac {\\tau} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau + \\int_1^\\infty \\left( \\frac {1} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau\n    = \\\\ &=\n    \\int_0^1 \\tau^{(1 - \\theta) q - 1} d\\tau + \\int_1^\\infty \\tau^{-\\theta q - 1} d\\tau\n    = \\\\ &=\n    \\frac {1 - 0} {(1 - \\theta) q} + \\frac {\\lim_{\\tau \\to \\infty} \\tau^{-\\theta q} - 1} {-\\theta q}\n    = \\\\ &=\n    \\frac 1 {(1 - \\theta) q} - \\frac 1 {-\\theta q}\n    = \\\\ &=\n    \\frac {-\\theta q - (1 - \\theta) q} {(1 - \\theta) (-\\theta) q^2}\n    = \\\\ &=\n    \\frac 1 {(1 - \\theta) \\theta q}\n  \\end{balign*}\n\\end{proof}\n\n\\begin{definition}\\label{def:k_functional_interpolation_space}\\mcite[40]{BerghLofstrom1976}\n  Let \\( \\overline{\\mscrX} \\coloneqq ( \\mscrX_0, \\mscrX_1 ) \\) be a compatible pair of Banach spaces.\n\n  For \\( \\theta \\in (0, \\infty) \\), \\( q \\in (0, \\infty] \\), we introduce the following norm:\n  \\begin{equation}\\label{eq:def:k_functional_interpolation_space/norm}\n    \\norm{x}_{\\theta,q,K} \\coloneqq \\Phi_{\\theta,q}(K(t, x)).\n  \\end{equation}\n\n  The subspace of \\( \\Sigma\\overline{\\mscrX} \\) for which this norm is finite is denoted by either\n  \\begin{align*}\n    K_{\\theta,q}(\\overline{\\mscrX})\n    &&\n    \\mscrX_{\\theta,q,K}.\n  \\end{align*}\n\\end{definition}\n\n\\begin{theorem}\\label{thm:k_functional_interpolation}\\mcite[thm. 3.1.2]{BerghLofstrom1976}\n  Let \\( \\theta \\in (0, 1) \\) and \\( q \\in (0, \\infty] \\). The space \\( \\mscrX_{\\theta,q,K} \\) defined in \\fullref{eq:def:k_functional_interpolation_space/norm} is an \\hyperref[def:banach_interpolation_space_exponent]{exact interpolation space} of exponent \\( \\theta \\). Furthermore,\n  \\begin{equation}\\label{eq:thm:k_functional_interpolation/inequality}\n    K(s, x) \\leq (\\gamma_{\\theta,q})^{-1} s^\\theta \\norm{x}_{\\theta,q,K}.\n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\n  Note that \\( K(s, x) \\) is a norm on \\( \\Sigma \\overline{X} \\) by \\fullref{def:k_functional_properties/equivalent_norm}. Therefore, \\( \\norm{\\cdot}_{\\theta,q,K} \\), the composition of \\( K(s, x) \\) with the \\hyperref[def:lorenz_quasinorm]{Lorenz quasinorm} \\( \\Phi_{\\theta,q} \\), is a norm.\n\n  We denote by \\( \\mscrX_{\\theta,q,K} \\) the space consisting of all vectors from \\( \\Sigma \\overline{\\mscrX} \\) where the norm \\eqref{eq:def:k_functional_interpolation_space/norm} is finite.\n\n  From \\eqref{eq:def:k_functional_properties/inequality} it follows that\n  \\begin{equation*}\n    \\min(1, \\tfrac t s) K(s, x) \\leq K(t, x)\n  \\end{equation*}\n  and hence\n  \\begin{equation*}\n    \\underbrace{\\Phi_{\\theta,q}}_{\\text{depends on } t} \\parens[\\Big]{ \\min(1, \\tfrac t s) K(s, x) } \\leq \\underbrace{\\Phi_{\\theta,q}(K(s, x))}_{\\text{norm in } \\mscrX_{\\theta,q,K}}.\n  \\end{equation*}\n\n  By \\eqref{eq:thm:def:lorenz_quasinorm/properties/reciprocal}, we have\n  \\begin{equation*}\n    \\Phi_{\\theta,q}(\\min(1, \\tfrac t s)) = \\tfrac 1 {s^\\theta} \\underbrace{\\Phi_{\\theta,q}(\\min(1, t))}_{\\hyperref[eq:def:lorenz_quasinorm/gamma]{\\gamma_{\\theta,q}}},\n  \\end{equation*}\n  and \\eqref{eq:thm:k_functional_interpolation/inequality} follows.\n\n  It remains to show that \\( \\mscrX_{\\theta,q,K} \\) is an exact interpolation space of exponent \\( \\theta \\).\n\n  Note that \\( K(1, x) = \\norm{x}_{\\Sigma \\overline{\\mscrX}} \\) and thus \\eqref{eq:thm:k_functional_interpolation/inequality} with \\( s = 1 \\) implies that\n  \\begin{equation*}\n    \\gamma_{\\theta,q} \\norm{x}_{\\Sigma \\overline{\\mscrX}} \\leq \\norm{x}_{\\theta,q,K},\n  \\end{equation*}\n  which shows that \\( \\mscrX_{\\theta,q,K} \\) can be embedded continuously into \\( \\Sigma \\overline{\\mscrX} \\).\n\n  On the other hand, for \\( x \\in \\Delta \\overline{\\mscrX} \\) we have\n  \\begin{equation*}\n    K(t, x) \\leq \\norm{x} \\leq \\norm{x}_{\\Delta \\overline{\\mscrX}} \\T{since} x = x + 0\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    K(t, x) \\leq \\norm{x} \\leq t \\norm{x}_{\\Delta \\overline{\\mscrX}} \\T{since} x = 0 + x.\n  \\end{equation*}\n\n  Therefore,\n  \\begin{equation*}\n    K(t, x) \\leq \\min(1, t) \\norm{x}_{\\Delta \\overline{\\mscrX}},\n  \\end{equation*}\n  which after applying \\( \\Phi_{\\theta,q} \\) becomes\n  \\begin{equation*}\n    \\norm{x}_{\\theta,q,K} \\leq \\gamma_{\\theta,q} \\norm{x}_{\\Delta \\overline{\\mscrX}}.\n  \\end{equation*}\n\n  Hence, we have the chain of continuous linear inclusions of Banach spaces\n  \\begin{equation*}\n    \\Delta \\overline{\\mscrX} \\subseteq X \\subseteq \\Sigma \\overline{\\mscrX}.\n  \\end{equation*}\n\n  Finally, to show that \\( \\mscrX \\) is an interpolation space of exponent \\( \\theta \\), fix a linear operator \\( T: \\overline{\\mscrX} \\mapsto \\overline{CY} \\) between compatible pairs and let \\( \\mscrY \\) be an intermediate space for \\( \\overline{CY} \\).\n\n  Then\n  \\begin{align*}\n    K(t, Tx)_{\\overline{CY}}\n    &\\leq\n    \\inf \\set{ \\norm{y_0}_{\\mscrY_0} + t \\norm{y_1}_{\\mscrY_1} : y_0 + y_1 = Tx }\n    \\leq \\\\ &\\leq\n    \\inf \\set{ \\norm{T}_{\\hom(\\mscrX_0, \\mscrY_0)} \\norm{x_0}_{\\mscrX_0} + t \\norm{T}_{\\hom(\\mscrX_1, \\mscrY_1)} \\norm{x_1}_{\\mscrY_1} : x_0 + x_1 = x }\n    = \\\\ &=\n    \\norm{T}_{\\hom(\\mscrX_0, \\mscrY_0)} K\\parens[\\Bigg]{\\frac {\\norm{T}_{\\hom(\\mscrX_1, \\mscrY_1)}} {\\norm{T}_{\\hom(\\mscrX_0, \\mscrY_0)}} t, x}.\n  \\end{align*}\n\n  By applying \\( \\Phi_{\\theta,q} \\) to both sides and using \\eqref{eq:thm:def:lorenz_quasinorm/properties/reciprocal}, we obtain\n  \\begin{equation*}\n    \\norm{Tx}_{\\overline{\\mscrY}_{\\theta,q,K}}\n    \\leq\n    {\\norm{T}_{\\hom(\\mscrX_1, \\mscrY_1)}}^{1 - \\theta} {\\norm{T}_{\\hom(\\mscrX_0, \\mscrY_0)}}^{\\theta} \\norm{x}_{\\overline{\\mscrY}_{\\theta,q,K}}.\n  \\end{equation*}\n\n  Thus, \\( \\mscrX \\) satisfies \\fullref{def:banach_interpolation_space_exponent} for being an exact interpolating space with exponent \\( \\theta \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:discrete_k_interpolation_space}\n  For positive numbers \\( \\theta \\) and \\( q \\), we denote by \\( \\lambda^{\\theta,q} \\) the set of all doubly-infinite real sequences \\( \\{ x_k \\}_{k=-\\infty}^\\infty \\) such that the norm\n  \\begin{equation}\\label{eq:def:discrete_k_interpolation_space}\n    \\norm{\\{ x_k \\}_{k=-\\infty}^\\infty}_{\\lambda^{\\theta,q}} \\coloneqq \\left( \\sum_{k=-\\infty}^\\infty \\left( \\frac {\\abs{x_k}} {2^{k\\theta}} \\right)^q \\right)^{\\tfrac 1 q}\n  \\end{equation}\n  is finite.\n\\end{definition}\n\n\\begin{theorem}\\label{thm:discrete_k_interpolation}\\mcite[lemma 3.1.3]{BerghLofstrom1976}\n  The vector \\( x \\in \\Sigma\\overline{\\mscrX} \\) belongs to \\hyperref[def:k_functional_interpolation_space]{\\( \\mscrX_{\\theta,q,K} \\)} if and only if the sequence \\( \\{ x_k \\}_{k=-\\infty}^\\infty \\) defined as\n  \\begin{equation}\\label{eq:thm:discrete_k_interpolation/sequence}\n    x_k \\coloneqq K(2^k, x)\n  \\end{equation}\n  belongs to \\hyperref[def:discrete_k_interpolation_space]{\\( \\lambda^{\\theta,q} \\)}.\n\n  Furthermore, for any integer \\( k \\) the following inequalities hold:\n  \\begin{equation}\\label{eq:thm:discrete_k_interpolation/inequalities}\n    \\frac 1 {2^\\theta} \\ln 2 \\norm{x_k}_{\\lambda^{\\theta,q}}\n    \\leq\n    \\norm{x}_{\\theta,q,K}\n    \\leq\n    2 \\cdot \\ln 2 \\norm{x_k}_{\\lambda^{\\theta,q}}.\n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\n  We have\n  \\begin{equation*}\n    \\norm{x}_{\\theta,q,K}^q\n    =\n    \\int_0^\\infty \\left( \\frac {K(\\tau, x)} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau\n    =\n    \\sum_{k=-\\infty}^\\infty \\int_{2^k}^{2^{k+1}} \\left( \\frac {K(\\tau, x)} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau.\n  \\end{equation*}\n\n  By \\fullref{def:k_functional_properties/inequality}, for each integer \\( k \\),\n  \\begin{equation*}\n    K(2^k, x) \\leq 2 K(2^k, x).\n  \\end{equation*}\n\n  By the \\hyperref[def:k_functional_properties/basic]{monotonicity} of \\( K \\), for \\( t \\in [2^k, 2^{k+1}] \\) we have\n  \\begin{equation*}\n    K(2^k, x) \\leq K(t, x) \\leq 2 K(2^k, x).\n  \\end{equation*}\n\n  Denote \\( x_k \\coloneqq K(2^k, x) \\). For \\( 2^k \\leq t \\leq 2^{k+1} \\) we have\n  \\begin{equation*}\n    \\frac{x_k}{2^{(k+1)\\theta}} \\leq \\frac{K(t, x)}{t^\\theta} \\leq 2 \\frac{x_k}{2^{k\\theta}}\n  \\end{equation*}\n\n  Therefore,\n  \\begin{align*}\n    \\norm{x}_{\\theta,q,K}^q\n    &=\n    \\sum_{k=-\\infty}^\\infty \\int_{2^k}^{2^{k+1}} \\left( \\frac {K(\\tau, x)} {\\tau^\\theta} \\right)^q \\frac {d\\tau} \\tau\n    \\leq \\\\ &\\leq\n    2^q \\sum_{k=-\\infty}^\\infty \\left(\\frac{x_k}{2^{k\\theta}} \\right)^q \\cdot \\ln \\tau \\mid_{\\tau=2^k}^{2^{k+1}}\n    = \\\\ &=\n    \\ln 2 \\cdot 2^q \\sum_{k=-\\infty}^\\infty \\left(\\frac{x_k}{2^{k\\theta}} \\right)^q\n    = \\\\ &=\n    2^q \\ln 2 \\norm{\\{ x_k \\}_{k=-\\infty}^\\infty}_{\\lambda^{\\theta,q}}^q\n  \\end{align*}\n  and similarly for the lower bound.\n\\end{proof}\n\n\\begin{definition}\\label{def:e_functional}\\mcite[174]{BerghLofstrom1976}\n  Let \\( \\overline{\\mscrX} = (\\mscrX_0, \\mscrX_1) \\) be a compatible pair of Banach spaces. Let \\( x \\in \\Sigma \\overline{\\mscrX} \\). Put\n  \\begin{alignedeq}\\label{eq:def:e_functional}\n    &E: (0, \\infty) \\times {\\Sigma \\overline{\\mscrX}} \\\\\n    &E(t, x) \\coloneqq \\inf \\set{ \\norm{x - x_0}_{\\mscrX_1} : \\norm{x_0}_{\\mscrX_0} \\leq t }.\n  \\end{alignedeq}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:e_functional/properties}\\mcite[lemma 7.1.3]{BerghLofstrom1976}\n  When \\( \\overline{\\mscrX} \\) are quasi-Banach spaces, the \\hyperref[def:e_functional]{\\( E \\)-functional} has the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{def:k_functional_properties/decreasing} For fixed \\( x \\in \\Sigma\\overline{\\mscrX} \\), the function \\( t \\mapsto E(t, x) \\) is decreasing.\n\n    \\thmitem{def:k_functional_properties/subaditive} For \\( \\varepsilon \\in (0, 1) \\), we have\n    \\begin{equation*}\n      E(t, x + y) \\leq E(\\varepsilon t, x) + E((1 + \\varepsilon) t, y).\n    \\end{equation*}\n\n    \\thmitem{def:k_functional_properties/positive} \\( x = 0 \\) if and only if \\( E(t, x) = 0 \\) for all \\( t > 0 \\).\n\n    \\thmitem{def:k_functional_properties/k_functional_connection}\\mcite[thm. 7.1.4]{BerghLofstrom1976}\n    \\begin{equation*}\n      E(t, x) = \\sup \\set{ \\frac {K(s, x) - t} s : s > 0 }.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{definition}\\label{def:approximation_space}\\mcite[def. 7.1.5]{BerghLofstrom1976}\n  Let \\( \\overline{\\mscrX} = (\\mscrX_0, \\mscrX_1) \\) be a compatible pair of Banach spaces. We define an \\term{approximation space} \\( E_{\\alpha,q}(\\overline{\\mscrX}) \\) for \\( x \\in \\Sigma\\overline{\\mscrX} \\) as the space of all members of \\( \\Sigma\\overline{\\mscrX} \\) for which the following norm\n  \\begin{equation}\\label{eq:def:approximation_space/norm}\n    \\norm{x}_{\\alpha,q,E} \\coloneqq \\Phi_{-\\alpha,q}(E(t,a))\n  \\end{equation}\n  is finite.\n\n  Here \\( \\alpha \\) and \\( q \\) are both positive real numbers and \\( q \\) is potentially \\( \\infty \\).\n\\end{definition}\n\n\\begin{theorem}\\label{thm:interpolation_space_and_approximation_space}\\mcite[thm. 7.1.6]{BerghLofstrom1976}\n  Let \\( \\mscrX \\) be a compatible pair of Banach spaces. Let \\( \\alpha \\) and \\( q \\) be positive real numbers and define\n  \\begin{align*}\n    \\theta \\coloneqq \\frac 1 {\\alpha + 1},\n    &&\n    r \\coloneqq \\theta q.\n  \\end{align*}\n\n  Then\n  \\begin{equation*}\n    (E_{\\alpha,\\theta q}(\\overline{\\mscrX}))^\\theta = K_{\\theta,q}(\\overline{\\mscrX}).\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{theorem}\\label{thm:interpolation_space_and_approximation_space_reiteration}\\mcite[thm. 7.1.8]{BerghLofstrom1976}\n  Let \\( \\mscrX \\) be a compatible pair of Banach spaces. Let \\( \\theta, \\alpha_0, \\alpha_1, r_0, r_1 \\) and \\( q \\) be positive real numbers such that \\( \\alpha_0 \\neq \\alpha_1 \\) and define \\( r \\coloneqq \\theta q \\) and\n  \\begin{align*}\n    \\alpha \\coloneqq (1 - \\theta) \\alpha_0 + \\theta \\alpha_1,\n    &&\n    \\beta \\coloneqq - \\frac {\\alpha_1 - \\alpha} {\\alpha_0 - \\alpha}.\n  \\end{align*}\n\n  Then\n  \\begin{equation*}\n    K_{\\theta,q}(E_{\\alpha_0,r_0}(\\overline{\\mscrX}), E_{\\alpha_1,r_1}(\\overline{\\mscrX})) = E_{\\alpha,q}(\\overline{\\mscrX})\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    E_{\\beta,r}(E_{\\alpha_0,r_0}(\\overline{\\mscrX}), E_{\\alpha_1,r_1}(\\overline{\\mscrX}))^\\theta = E_{\\alpha,q}(\\overline{\\mscrX}).\n  \\end{equation*}\n\\end{theorem}\n", "meta": {"hexsha": "5d14bd51b763ffec3b31507896aff75049df7698", "size": 35983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/banach_space_interpolation.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_space_interpolation.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_space_interpolation.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.3584615385, "max_line_length": 541, "alphanum_fraction": 0.64199761, "num_tokens": 13680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.658320257952359}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{mathtools}\n\\usepackage{latexsym}\n\\usepackage{amsfonts}\n\\usepackage{enumitem}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{color, colortbl}\n\\usepackage{amssymb}\n\\setlength{\\parskip}{\\baselineskip}\n\\renewcommand{\\det}[1]{|#1|}\n\\newcommand{\\mf}{-\\frac{1}{2}}\n\\newcommand{\\Mu}{M}\n\\newcommand{\\hp}{\\circ}\n\\newcommand{\\fc}{\\frac{1}{\\sqrt{(2\\pi)^{d+m}(\\sigma^2)^m }}}\n\\newcommand{\\todo}[1]{\\textbf{\\textcolor{red}{TODO: #1}}}\n\\newcommand{\\note}[1]{\\textbf{\\textcolor{red}{NOTE: #1}}}\n\\newcommand{\\ps}{\\begin{bmatrix} \\psi_1 & 0 \\\\ 0 & \\psi_2 \\end{bmatrix}}\n\\begin{document}\n\\raggedright\n\\section{Probabilistic PCA}\n\nWhen I observe data then the best k orthogonal basis of a projection\nspace are the eigenvectors of the covariance matrix.\n\n\\begin{align}\n&\\arg\\min ||X - UU^\\top X ||^@_F \\\\\n=&tr(M^\\top M)\\\\\n=&tr(X^TX + X^TUU^TUU^TX - zX^TUU^TX)\\\\\n=& \\max tr(X^TUU^TX) \\\\\n=& tr(U^TXX^TU)\n\\end{align}\nNow I can also try and solve the following problem.\n\nI observe data x and I assume that it was generated in the following way:\n\\begin{align}\nz \\sim & \\mathcal{N}(0, I_d)\\\\\nx \\sim & \\mathcal{N}(Wz+\\mu, \\sigma^2 I_m)  \n\\end{align}\nAnd I need to find $W, \\mu, \\sigma^2$ so that $p(x)$ is maximized. $W\n\\in \\mathcal{R}^{m\\times d}$.\n\n\\begin{align}\n  p(x) &= \\prod_{i=1}^n \\int p(x_i | z_i) p(z_i)\\\\\n  l(x) &= \\sum_{i=1}^n \\log(\\int p(x_i|z_i) p(z_i)) \\label{obj}\\\\\n\\end{align}\nFor simplicity lets drop subscripts and derive $p(x) = \\int p(x|z) p(z)$.\n\\begin{align}\n  p(z) &= \\frac{1}{\\sqrt{(2\\pi)^d\\det{I_d}}} \\exp(-\\frac{1}{2} z^T  I_d^{-1} z)\\\\\n  p(x|z) &= \\frac{1}{\\sqrt{(2\\pi)^m(\\sigma^2)^m \\det{I_m}}}\n  \\exp(-\\frac{1}{2}(x-Wz-u)^T(\\sigma^2I_m)^{-1}(x-Wz-\\mu))\n\\end{align}\n\nWhat is $\\int p(x|z) p(z)$. I know it is a guassian. I also can use\nmathematica. I can also use the fact that its solution is given in\nkevin murphy's book. But lets derive it.\n\\begin{align}\n  \\int p(x|z)p(z) &= \\fc \\int\n  \\exp{\\mf (z^Tz + (x-\\mu - Wz)^T(\\sigma^{-2})(x-\\mu-Wz))}\n\\end{align}\nLet $(x-\\mu)/\\sigma = y,\\; W/\\sigma=V$\n\\begin{align}\n  \\int p(x|z)p(z) &= \\fc \\int \\exp(\\mf (z^Tz + (y - Vz)^T(y-Vz)))\\\\\n  &= \\fc\\exp(\\mf y^Ty) \\int \\exp(\\mf (z^T (I+V^TV) z  - 2z^TV^Ty))\n\\end{align}\nLet $U = (I+V^TV)^{-1}$\n\\begin{align}\n  &= \\fc \\exp(\\mf y^Ty) \\int \\exp(\\mf ( \\left(z^TU^{-1}z -2z^TU^{-1}a + a^TU^{-1}a\\right) - a^TU^{-1}a  ))\n\\end{align}\nThis means that $V^Ty = U^{-1}a \\implies a = UV^Ty$\n\\begin{align}\n  &= \\fc \\exp(\\mf (y^Ty - a^TU^{-1}a) ) \\int \\exp(\\mf ((z-a)^T U^{-1}(z-a)))\\\\\n  &= \\fc \\sqrt{(2\\pi)^d \\det{U}} \\exp(\\mf (y^Ty - a^TU^{-1}a) )\\\\\n  &= \\fc \\sqrt{(2\\pi)^d \\det{U}} \\exp(\\mf (y^Ty - y^TVU^TU^{-1}UV^Ty))\\\\\n  &= \\fc \\sqrt{(2\\pi)^d \\det{U}} \\exp(\\mf (y^Ty - y^TVU^TV^Ty) )\\\\\n  &= \\fc \\sqrt{(2\\pi)^d \\det{U}} \\exp(\\mf (y^T(I-VU^TV^T)y)\n\\end{align}\n\nJust substitute back $y$ and $V$ and $U$ to get the answer\n\\begin{align}\n  \\int p(x|z)p(z) &= \\frac{\\sqrt{(2\\pi)^d \\det{U}}}{\\sqrt{(2\\pi)^{d+m}(\\sigma^2)^m }} \\exp(\\mf ((x-\\mu)^T\\frac{(I-V(I+V^TV)^{-1}V^T)}{\\sigma^2}(x-\\mu))\n\\end{align}\n\nInterestingly, $(I-V(I+V^TV)^{-1}V^T) = (I+VV^T)^{-1}$\nThis means that\n\\begin{align}\n  p(z) = \\int p(x|z)p(z) &= \\frac{1}{\\sqrt{(2\\pi)^{m}(\\sigma^2)^m \\det{U}^{-1}}}  \\exp(\\mf ((x-\\mu)^T (\\sigma^2 (I+VV^T))^{-1}  (x-\\mu)))\n\\end{align}\nAlso note that by Sylvester's theorem $\\det{U} = \\det{I+V^TV}^{-1} = \\det{I+VV^T}^{-1} $.\n\nSo finally we have proven that $p(x) = \\mathcal{N}(\\mu,\n\\sigma^2I+WW^T)$\n\nNow substitute this results back into \\ref{obj} to get\n\n\\begin{align}\n  l(x) &= \\sum_{i=1}^n \\log(\\frac{1}{\\sqrt{(2\\pi)^{m}(\\sigma^2)^m \\det{I+VV^T}}}  \\exp(\\mf ((x_i-\\mu)^T (\\sigma^2 (I+VV^T))^{-1}  (x_i-\\mu))))\\\\\n  &= \\mf \\sum_{i=1}^n ((x_i-\\mu)^T (\\sigma^2I+WW^T))^{-1}  (x_i-\\mu)) + \\log((2\\pi)^{m} \\det{\\sigma^2I+WW^T})\n\\end{align}\nNow get rid of constant terms like $m\\log(2\\pi)$ and the constant\nmultipliers which don't affect the optimization (However now I have to\nminimize the quantity since I removed $\\mf$)\n\\begin{align}\n  &= \\sum_{i=1}^n ((x_i-\\mu)^T (\\sigma^2I+WW^T)^{-1}  (x_i-\\mu)) + \\log(\\det{\\sigma^2I+WW^T})\n\\end{align}\nNow minimize this quantity wrt $\\mu, W, \\sigma$ to get the MLE\nparameters\n\nWrt $\\mu$\\\\\nLet $Y=(\\sigma^2I+WW^T))^{-1}$, then wrt $\\mu$ the derivative is\n\\begin{align}\n  =& \\sum_{i=1}^n \\frac{\\partial}{\\partial \\mu}  ((x_i-\\mu)^T Y  (x_i-\\mu)) \\\\\n  =& \\sum_{i=1}^n \\frac{\\partial}{\\partial \\mu}  (\\mu^T Y\\mu -\n  2x_i^TY\\mu + x_i^TYx_i)) \\\\\n  =& \\sum_{i=1}^n  (Y+Y^T)\\mu -  (2x_i^TY)^T )) \\\\\n\\end{align}\nHowever $Y$ is symmetric, therefore $Y+Y^T = 2Y^T$, which means\n$$\\mu = \\frac{1}{n}{\\sum_{i=1}^n x_i}$$\n\n\nLet $y_i = x_i - \\mu$ then wrt $\\sigma$ and $W$ the objective to\nminimize is: where $\\sum y_i = 0$\n\\begin{align}\n  =& \\sum_{i=1}^n \\left(  (y_i^T\n  (\\sigma^2I+WW^T)^{-1}  y_i) + \\log(\\det{\\sigma^2I+WW^T}) \\right)\\\\\n\\end{align}\nLet's level up and concatenate all the $y_i$ into a matric $Y$, then\nthe objective becomes\n\\begin{align}\n  tr(Y^T (\\sigma^2I+WW^T)^{-1}Y) + n\\log(\\det{\\sigma^2I+WW^T})\n\\end{align}\nInterestingly $\\sigma^2I+WW^T$ are inseparable, replace them by $V = (\\sigma^2I+WW^T)^{-1}$ to\nget the new objective\n\\begin{align}\n  \\arg\\min_V tr(Y^TVY) - n\\log(\\det{V})\n\\end{align}\n\n\\begin{align}\n  \\frac{\\partial}{\\partial V} tr(Y^TVY) - n\\log(\\det{V}) &= YY^T - n\n  V^{-1} = 0\\\\\n  V^{-1} = (\\sigma^2I+WW^T) &= \\frac{1}{n}YY^T\n\\end{align}\n\nNow to solve this equation we would have to let $\\sigma$ equal the\nlast $d-m$ eigenvalues so they would equal each other and then we can\n do an eigen decomposition\nof $C = YY^T/n - \\sigma^2I = U\\sqrt{S}MM^T\\sqrt{S^T}U^T \\in \\mathcal{R}^{d \\times\n  d}$ then we derive the PCA solution assuming that we had perfect\nknowledge of the ppopulation means.\n\nBut if instead of taking derivative wrt $V$ we take derivative wrt $W$\nand actually recognize the constraint that $W$ would not be able to\nperfectly match $C=YY^T/n$  then we would get: \\todo{COMPLETE THIS}\n\\begin{align}\n  (YY^T/n(\\sigma^2I+WW^T))W &= W\n\\end{align}\n\n\\section{Probabilistic CCA}\nI will use the following objective as my starting point for CCA.\nLet $A=\\Sigma_{xx}, B=\\Sigma_{YY}, C=\\Sigma_{XY}$\n\\begin{align}\n  \\arg\\max_{U,V} \\;& tr(U^T C V)\\\\\n  \\text{subject to } & U^TAU=I,\\; V^TBV=I\n\\end{align}\nWe can solve this in two ways.\n\\subsection{Approach 1}\nThe usual approach is to first find a single direction and then show\nthat the remaining directions follow as the remaining eigen-vectors of\na matrix all of which would follow the required constraints. Let's\nrecap that approach first.\n\nLet $u,\\; v$ be two directions, then the lagrangian of the objective\nbecomes\n\\begin{align}\n  \\mathcal{L} &=u^TCv + \\lambda (u^tAu-1 ) + \\mu (v^TBv-1)\\\\\n  \\frac{\\partial \\mathcal{L}}{\\partial u} &= v^TC^T + u^T(2\\lambda A)  =0 = Cv + 2\\lambda A^Tu\\\\\n  \\frac{\\partial \\mathcal{L}}{\\partial v} &= u^TC + v^T(2\\mu B)  =0=C^Tu+2\\mu B^T v\\\\\n  u &= -\\frac{1}{2\\lambda}A^{-T}Cv\\\\\n  -C^T (-\\frac{1}{2\\lambda}A^{-T}Cv) &= 2\\mu B^Tv\\\\\n  B^{-T}C^TA^{-T}Cv &=4\\lambda \\mu v\n\\end{align}\nNow use $B=B^T,\\; A=A^T,\\; 4\\lambda \\mu = \\kappa$, also use the fact that B can be decomposed\ninto its cholesky factors $B=DD^T \\implies B^{-1}=D^{-T}D^{-1}$ to simplify the objective:\n\\begin{align}\n  D^{-T}D^{-1}C^TA^{-1}CD^{-T}D^Tv &=\\kappa v  \\\\\n  D^{-1}C^TA^{-1}CD^{-T}D^Tv &=\\kappa D^Tv  \n\\end{align}\nLet $v'=D^Tv$ to get\n\\begin{align}\n  D^{-1}C^TA^{-1}CD^{-T}v' &=\\kappa v'  \\\\\n  \\text{Let } M &= D^{-1}C^TA^{-1}CD^{-T}\n\\end{align}\nNow we claim that the successive orthogonal eigen vectors $v'$ of the\nsymmateric matrix $M$ would give us the\nsolutions as $v=D^{-T}v', \\; u = -\\frac{1}{2\\lambda}A^{-T}CD^{-T}v'$.\n\nIt is easy to see that $v^TBv = v'^T D^{-1}BD^{-T}v' = 1$ and all\nsubsequent vectors would also obey this.\n\nWe can check that $u^TAu =\n\\frac{1}{4\\lambda^2}v'^TD^{-1}C^TA^{-1}AA^{-T}CD^{-T}v' =\n\\frac{1}{4\\lambda^2}v'^TMv'=\\frac{\\mu}{\\lambda}$\nWe are free to choose $\\lambda, \\mu$ so to satisfy the constraints we\nshould choose $\\mu=\\lambda$.\n\\subsection{Approach 2}\nThis approach adds one lagrange multiplier per constraint\nand uses hard algebra to grind through. Specifically the lagrangian becomes\n\\begin{align}\n  L &= tr(U^TCV) + \\sum \\lambda_{ij}(u_i^TAu_j - \\delta_{ij}) + \\sum\n  \\mu_{ij}(v_i^TBv_j - \\delta_{ij})\\\\\n  &= tr(U^TCV) + 1^T U^T(A\\hp \\Lambda)U 1 - tr(\\Lambda) + 1^T V^T(B\\hp \\Mu)V 1 - tr(\\Mu) \\\\\n  &= tr(U^TCV + 1^T U^T(A\\hp \\Lambda)U 1 - \\Lambda + 1^T V^T(B\\hp  \\Mu)V 1 - \\Mu)\\\\\n  \\frac{\\partial L}{\\partial U}&= V^TC^T + 11^TU^T(A\\hp (\\Lambda + \\Lambda)^T) = 0\n\\end{align}\n\\todo{Confirm that this method would work}\n\\subsection{Probabilistic CCA}\nBasically we have to find the MLE estimates of the parameters of a two\nobserved, one hidden variable model defined with the following\ngenerative story. \n\nI observe data coming in two pairs and I assume that it was generated\nin the following way\n\\begin{align}\n  z &\\sim \\mathcal{N}(0, I_d)\\\\\n  x &\\sim \\mathcal{N}(W_1z + u_1, \\psi_1)\\\\\n  y &\\sim \\mathcal{N}(W_2z + u_2, \\psi_2)\n\\end{align}\nNow I want to estimate the parameters $W_1, W_2, \\psi_1, \\psi_2,\nu_1, u_2$ on the basis of the data. So basically I need to\nmaximize the likelihood of the parameters.\n\\begin{align}\n  \\mathcal{L} &= \\prod_i \\int_z p(x_i|z) p(y_i|z) p(z)\\\\\n  \\log(\\mathcal{L}) &= \\sum_i \\log(\\int_z p(x_i|z) p(y_i|z) p(z))\n\\end{align}\nLets focus on $I = \\int_z p(x|z) p(y|z) p(z)$. Let $\\dim(x)=m\\; \\dim(y)=q$\n\\begin{align}\n  p(z)&= \\frac{1}{\\sqrt{(2\\pi)^d}} \\exp(\\mf z^Tz)\\\\\n  p(x|z)&= \\frac{1}{\\sqrt{(2\\pi)^m\\det{\\psi_1}}}  \\exp( \\mf (x-W_1z-u_1)^T\\psi_1^{-1}(x-W_1z-u_1))\\\\\n  p(y|z)&= \\frac{1}{\\sqrt{(2\\pi)^q\\det{\\psi_2}}}  \\exp( \\mf (y-W_2z-u_2)^T\\psi_2^{-1}(y-W_2z-u_2))\\\\\n  I &= \\int_z p(x|z) p(y|z) p(z)\\\\\n  &= \\frac{1}{\\sqrt{(2\\pi)^{d+m+q} \\det{\\psi_1}\\det{\\psi_2} }}\\int_z \\exp(\\mf\n  \\big( z^Tz + (x-W_1z-u_1)^T\\psi_1^{-1}(x-W_1z-u_1) + \\notag\\\\\n  & \\qquad (y-W_2z-u_2)^T\\psi_2^{-1}(y-W_2z-u_2) \\big) ) \n\\end{align}\nNow the basic idea is the same as probabilistic PCA, the final\nprobability distribution is joint guassian over $x, y$, and then we\nwant to maximize the likelihood of parameters.\n\nLet $a = x-u_1, \\; b = y-u_2$ and focus only on the quadratic term $T$.\n\\begin{align}\n  T &= z^Tz + (a-W_1z)^T\\psi_1^{-1}(a-W_1z) +\n  (b-W_2z)^T\\psi_2^{-1}(b-W_2z)\\\\\n  (a-W_1z)^T\\psi_1^{-1}(a-W_1z) &= (a^T\\psi_1^{-1}a)+  (z^TW_1^T\\psi_1^{-1}W_1z) - 2z^TW_1^T\\psi_1^{-1}a\\\\\n  (b-W_2z)^T\\psi_2^{-1}(b-W_2z) &= (b^T\\psi_2^{-1}b)+  (z^TW_2^T\\psi_2^{-1}W_2z) - 2z^TW_2^T\\psi_2^{-1}b\\\\\n  T &= z^T(I+W_1^T\\psi_1^{-1}W_1+W_2^T\\psi_2^{-1}W_2)z -2z^T(W_1^T\\psi_1^{-1}a + W_2^T\\psi_2^{-1}b) + \\notag\\\\\n  & \\qquad ((a^T\\psi_1^{-1}a) + (b^T\\psi_2^{-1}b))\n\\end{align}\nOnce again we have to complete the squares which means that we'd have to match $T$ above to an expression like the following\n\\begin{align}\n  (z-\\mu)^T V^{-1}(z-\\mu)=  (z^T V^{-1}z) -2z^TV^{-1}\\mu + (\\mu^T V^{-1}\\mu)\n\\end{align}\nWhich means that $V = (I+W_1^T\\psi_1^{-1}W_1+W_2^T\\psi_2^{-1}W_2)^{-1}$ and $V^{-1}\\mu = (W_1^T\\psi_1^{-1}a + W_2^T\\psi_2^{-1}b) \\implies \\mu = V(W_1^T\\psi_1^{-1}a + W_2^T\\psi_2^{-1}b)$.\n\nLet $c = ((a^T\\psi_1^{-1}a) + (b^T\\psi_2^{-1}b)) - (\\mu^T V^{-1}\\mu)$, then basically the integral $I$ becomes the following:\n\\begin{align}\n  I &= \\frac{1}{\\sqrt{(2\\pi)^{d+m+q} \\det{\\psi_1}\\det{\\psi_2} }}\n  \\exp(\\mf c) \\int \\exp(\\mf (z-\\mu)^T V^{-1}(z-\\mu))\\\\\n  &= \\frac{\\sqrt{\\det{V}}}{\\sqrt{(2\\pi)^{m+q} \\det{\\psi_1}\\det{\\psi_2} }} \\exp(\\mf c)\\\\\n  &= ((2\\pi)^{m+q}\n  \\det{\\psi_1}\\det{\\psi_2}\\det{V}^{-1})^{-1/2}\\exp(\\mf c) \\label{ccasimple}\n\\end{align}\n\nOf course we only want to maximize the real likelihood.\n\\begin{align}\n  \\log(\\mathcal{L})&= \\sum \\log(I_i) \\\\\n  &= \\mf (\\sum_i c_i + n \\log((2\\pi)^{m+q} \\det{\\psi_1}\\det{\\psi_2}\\det{V}^{-1}))\n\\end{align}\nAfter removing constants we get the following objective\n\\begin{align}\n  & \\arg\\min (\\sum_i c_i + n \\log(\\det{\\psi_1}\\det{\\psi_2}\\det{I+W_1^T\\psi_1^{-1}W_1+W_2^T\\psi_2^{-1}W_2}))\\\\\n  c_i &= ((a_i^T\\psi_1^{-1}a_i) + (b_i^T\\psi_2^{-1}b_i)) - (\\mu_i^T V^{-1}\\mu_i)\\\\\n  \\mu_i &= V(W_1^T\\psi_1^{-1}a_i + W_2^T\\psi_2^{-1}b_i)\\\\\n  V &= (I+W_1^T\\psi_1^{-1}W_1+W_2^T\\psi_2^{-1}W_2)^{-1}\\\\\n  \\implies c_i &= a_i^T\\psi_1^{-1}a_i + b_i^T\\psi_2^{-1}b_i - (W_1^T\\psi_1^{-1}a_i + W_2^T\\psi_2^{-1}b_i)^T V^T(W_1^T\\psi_1^{-1}a_i + W_2^T\\psi_2^{-1}b_i)\n\\end{align}\n\nNow strictly speaking one could muddle his/her way through by computer\nassisted algebra but it would be better to simplify the forms.\n\nThe trick is to go back to Expression~\\ref{ccasimple} and to then\nview it as a higher dimensional Guassian. Specifically\n\\begin{align}\n  I &= \\frac{1}{\\sqrt{(2\\pi)^{m+q}\\det{\\psi_1}\\det{\\psi_2}\\det{V}^{-1}}}\\exp(\\mf c)\\\\\n  &=\n  \\frac{1}{\\sqrt{(2\\pi)^{m+q}\\det{\\psi_1}\\det{\\psi_2}\\det{V}^{-1}}}\\exp(\\mf\n  ((a^T\\psi_1^{-1}a) + (b^T\\psi_2^{-1}b)) - (\\mu^T V^{-1}\\mu))\\\\\n  &= \\frac{1}{\\sqrt{(2\\pi)^{m+q}\\det{\\psi_1}\\det{\\psi_2}\\det{V}^{-1}}}\\exp(\\mf ((a^T\\psi_1^{-1}a) + (b^T\\psi_2^{-1}b)) - (W_1^T\\psi_1^{-1}a + W_2^T\\psi_2^{-1}b)^T V^T(W_1^T\\psi_1^{-1}a + W_2^T\\psi_2^{-1}b))\n\\end{align}\nNow consider just the quadratic term Q\n\\begin{align}\n  Q &= a^T\\psi_1^{-1}a + b^T\\psi_2^{-1}b - (W_1^T\\psi_1^{-1}a +\n  W_2^T\\psi_2^{-1}b)^T V^T(W_1^T\\psi_1^{-1}a + W_2^T\\psi_2^{-1}b)\\\\\n  Q &= a^T(\\psi_1^{-1} - \\psi_1^{-T}W_1V^TW_1^T \\psi_1^{-1}) a +\n  b^T(\\psi_2^{-1} - \\psi_2^{-T}W_2V^TW_2^T \\psi_2^{-1}) b  \\notag\\\\\n  & \\qquad - b^T\\psi_2^{-T}W_2V^TW_1^T\\psi_1^{-1}a -\n  a^T\\psi_1^{-T}W_1V^TW_2^T\\psi_2^{-1}b\\\\\n  &= \\begin{bmatrix} a^T & b^T \\end{bmatrix}\n    \\begin{bmatrix}\n       \\psi_1^{-1} - \\psi_1^{-T}W_1V^TW_1^T \\psi_1^{-1} & -\\psi_1^{-T}W_1V^TW_2^T\\psi_2^{-1} \\\\\n       -\\psi_2^{-T}W_2V^TW_1^T\\psi_1^{-1}  & \\psi_2^{-1} -\\psi_2^{-T}W_2V^TW_2^T\\psi_2^{-1}  \\end{bmatrix}\n    \\begin{bmatrix}a    \\\\ b \\end{bmatrix}\\\\\n    &= \\begin{bmatrix} a^T & b^T \\end{bmatrix}\n    (\\ps^{-1} - \\begin{bmatrix}\n        \\psi_1^{-T}W_1V^TW_1^T \\psi_1^{-1} & \\psi_1^{-T}W_1V^TW_2^T\\psi_2^{-1} \\\\\n       \\psi_2^{-T}W_2V^TW_1^T\\psi_1^{-1}  & \\psi_2^{-T}W_2V^TW_2^T\\psi_2^{-1}  \\end{bmatrix})\n    \\begin{bmatrix}a    \\\\ b \\end{bmatrix}\\\\\n    &= \\begin{bmatrix} a^T & b^T \\end{bmatrix}\n    (\\ps^{-1} - \\ps^{-1} \\begin{bmatrix}\n        W_1V^TW_1^T  & W_1V^TW_2^T \\\\\n       W_2V^TW_1^T  & W_2V^TW_2^T  \\end{bmatrix}\\ps^{-1})\n    \\begin{bmatrix}a    \\\\ b \\end{bmatrix} \\\\\n    &= \\begin{bmatrix} a^T & b^T \\end{bmatrix}\n    (\\ps^{-1} - \\ps^{-1}\n    \\begin{bmatrix} W_1 \\\\ W_2 \\end{bmatrix}\n    V\n    \\begin{bmatrix} W_1^T & W_2^T \\end{bmatrix}\n    \\ps^{-1})\n    \\begin{bmatrix}a    \\\\ b \\end{bmatrix}\n\\end{align}\nNow note that $\\psi$ and $V$ are both symmetric. Also note that\n\\begin{align}\n  V &= (I+W_1^T\\psi_1^{-1}W_1+W_2^T\\psi_2^{-1}W_2)^{-1}\\\\\n  &= (I + \\begin{bmatrix} W_1^T W_2^T \\end{bmatrix} \\begin{bmatrix}\n    \\psi_1 & 0 \\\\ 0 & \\psi_2 \\end{bmatrix}^{-1} \\begin{bmatrix} W_1\n    \\\\ W_2 \\end{bmatrix})^{-1}\n\\end{align}\nAlso consider\n\\begin{align}\n  \\Sigma &= \\begin{bmatrix} \\psi_1 & 0 \\\\ 0 &\n    \\psi_2 \\end{bmatrix} + \\begin{bmatrix} W_1 \\\\ W_2 \\end{bmatrix}  \\begin{bmatrix} W_1^T & W_2^T \\end{bmatrix}\n\\end{align}\nBy the woodbury identity we know its inverse is as follows\n\\begin{align}\n  \\Sigma^{-1} &= \\ps^{-1} - \\ps^{-1}\\begin{bmatrix} W_1\n    \\\\ W_2 \\end{bmatrix}(I+ \\begin{bmatrix} W_1^T &\n    W_2^T \\end{bmatrix} \\ps^{-1} \\begin{bmatrix} W_1\n    \\\\ W_2 \\end{bmatrix})^{-1} \\begin{bmatrix} W_1^T &\n    W_2^T \\end{bmatrix} \\ps^{-1}\n\\end{align}\nThe determinant of $\\Sigma$ can also be shown to be equal to the form\nin the square root by using the fact that $$\\det{A+UV^T} = \\det{I+V^TA^{-1}U}\\det{A}$$\n\nOnce we have done this derivation then we can move forward by\ncalculating the loglikelihood for a general guassian.\nLet $u = [u_1; u_2]$, and $v_i = [x_i; y_i]$\n\\begin{align}\n  \\mathcal{-L}  &\\sim n\\log(\\det{\\Sigma}) + \\sum_i tr((v_i-u)^T\\Sigma^{-1}(v_i-u))\n\\end{align}\nNow we can cycle the things inside the trace and take out constant\nthings from the summation and replace $\\sum v_i/n = \\xi$ and $\\sum\n(v_iv_i^T - \\xi \\xi^T)/n = \\Xi$ also replace $v_i - u = v_i - \\xi +\n\\xi - u$\n\n\\begin{align}\n  \\mathcal{-L}  &\\sim \\log(\\det{\\Sigma}) + tr(\\Sigma^{-1}\\Xi)+(\\xi -\n  u)^T\\Sigma^{-1}(\\xi - u) \\label{ccal}\n\\end{align}\n\nNow again we have to minimize Expression~\\ref{ccal} and $\\xi, \\Xi$ are\ngiven to us through the data. It is easy to set $u$ but $\\Sigma$ needs\nto be chosen more carefully because it is constrained to be of the\nform\n\\begin{align}\n  \\Sigma &= \\begin{bmatrix} \\psi_1 & 0 \\\\ 0 & \\psi_2 \\end{bmatrix} + \\begin{bmatrix} W_1 \\\\ W_2 \\end{bmatrix}  \\begin{bmatrix} W_1^T &    W_2^T \\end{bmatrix}\\\\\n  \\Sigma &= \\begin{bmatrix} \\psi_1 & 0 \\\\ 0 &\n    \\psi_2 \\end{bmatrix} + W W^T\n\\end{align}\n\nI repeat that the problem only occurs because $\\Sigma$ needs to be of\na certain form. If it could have been a general matrix then I wouldn't\nhave any problems. I'd just take the derivative of\nexpression~\\ref{ccal} and set it to 0. In any case the term\n$(\\xi - u)^T\\Sigma^{-1}(\\xi - u)$ is zero so we dont need to worry\nabout its derivative.\n\nNow let's take derivative of $-\\mathcal{L}$ wrt to $\\psi_1,\n\\psi_2, W=[W_1; W_2]$. We must work with $\\det{\\Sigma}\\ne 0$\n\nWrt $\\psi_1$:\n\\begin{align}\n  \\partial \\mathcal{L} &= tr(\\Sigma^{-1} \\partial \\Sigma - \\Xi\\Sigma^{-1}\\partial\\Sigma\\Sigma^{-1})\\\\\n  &=  tr((\\Sigma^{-1}  - \\Sigma^{-1}\\Xi\\Sigma^{-1})\\partial\\Sigma)\\\\\n  &\\implies (\\Sigma^{-1}  - \\Sigma^{-1}\\Xi\\Sigma^{-1}) \\begin{bmatrix}I & 0\\\\ 0 & 0\\end{bmatrix} = 0\n\\end{align}\n\nWrt $\\psi_2$:\n\\begin{align}\n  \\partial \\mathcal{L} &= tr(\\Sigma^{-1} \\partial \\Sigma - \\Xi\\Sigma^{-1}\\partial\\Sigma\\Sigma^{-1}) = 0\\\\\n  &=  tr((\\Sigma^{-1}  - \\Sigma^{-1}\\Xi\\Sigma^{-1})\\partial\\Sigma)\\\\\n  &\\implies (\\Sigma^{-1}  - \\Sigma^{-1}\\Xi\\Sigma^{-1}) \\begin{bmatrix}0 & 0\\\\ 0 & I\\end{bmatrix} = 0\n\\end{align}\n\nWrt $W$:\n\\begin{align}\n \\partial \\mathcal{L} &= (\\Sigma^{-1}  - \\Sigma^{-1}\\Xi\\Sigma^{-1})W = 0\n\\end{align}\n\nNow we need to find $\\psi, W$ that satisfy these three constraints and\nlater check which of those is the minima ? \nIn order to find the solutions Bach first studies the solutions. He\nsays that assume you that such poins exist. Then those points \nfirst satisfy some conditions. \n\\begin{enumerate}\n\\item $WW^T \\preccurlyeq \\Xi$\n\\item $\\Psi = \\Sigma\\Xi^{-1}(\\Xi - WW^T)$\n\\item $\\psi_1 = \\Xi_{11} - W_1 W_1^T$ and $\\psi_1 = \\Xi_{22} - W_1 W_1^T$\n\\end{enumerate}\n\nBut of course he didnt come up with these relations from thin air. It\nis conceivable that he did try to study the solution but the\nconditions themselves would have come as a results of search. Anyway\nlet's derive some of the lemmas to get comfortable with them\n\n\\begin{align}\n           & (\\Sigma^{-1}  - \\Sigma^{-1}\\Xi\\Sigma^{-1})W = 0           \\\\\n  \\implies & W = \\Xi\\Sigma^{-1}W \\\\\n  \\implies & W = \\Xi(\\Psi + WW^T)^{-1}W \\\\\n  \\implies & W = \\Xi(\\Psi^{-1} - \\Psi^{-1} W(I+W^T\\Psi^{-1}W)^{-1}W^T\\Psi^{-1})W \\label{eq1}\\\\\n  \\implies & W = \\Xi(\\Psi^{-1}W - \\Psi^{-1} W(I+W^T\\Psi^{-1}W)^{-1}W^T\\Psi^{-1}W) \\label{eq2}\\\\\n\\end{align}\nNow let $W^T\\Psi^{-1}W = V$, then Expression~\\ref{eq2}\n\\begin{align}\n  W &= \\Xi(\\Psi^{-1}W - \\Psi^{-1} W(I+V)^{-1}V) \\\\\n  W &= \\Xi\\Psi^{-1}W(I - (I+V)^{-1}V)\\\\\n  W &= \\Xi\\Psi^{-1}W(I + V)^{-1}\\\\\n  W +WV &= \\Xi \\Psi^{-1}W\\\\\n  W + WW^T\\Psi^{-1}W &= \\Xi \\Psi^{-1}W\\\\\n  W &= (\\Xi - WW^T) \\Psi^{-1}W\\\\\n  \\implies \\Psi &= \\Xi - WW^T \\;\\text{\\todo{If we assume that $WW^T$ is invertible}}\\\\\n\\end{align}\nNow do the cholesky decomposition $\\Psi^{-1} = M^TM$ and apply to Expression!\\ref{eq1}\n\\begin{align}\n  W &= \\Xi(M^TM - M^T M W(I+W^T M^T MW)^{-1}W^T M^T M)W \\\\\n\\end{align}\nLet $V = MW$ to get\n\\begin{align}\n  W &= \\Xi M^TMW - \\Xi M^T M W(I+W^T M^T MW)^{-1}W^T M^T MW \\\\\n  &= \\Xi M^TV - \\Xi M^T V(I+V^TV)^{-1}V^T V \\\\\n  V &= M\\Xi M^TV(I - (I+V^TV)^{-1}V^TV)\n\\end{align}\nSince $\\Psi$ is invertible so $M$ is invertible.\n\\begin{align}\n  M^{-1}V &= \\Xi M^TV(I - (I+V^TV)^{-1}V^TV)\n\\end{align}\n\nNo strike this he derivation goes as follows\n\\begin{align}\n  W &= \\Xi(\\Psi + WW^T)^{-1}W \\\\\n  W &= \\Xi(\\Psi^{1/2}\\Psi^{1/2} + \\Psi^{1/2}\\Psi^{-1/2}WW^T\\Psi^{-1/2}\\Psi^{1/2})^{-1}W \\\\\n  W &= \\Xi\\Psi^{-1/2}(I + \\Psi^{-1/2}WW^T\\Psi^{-1/2})^{-1}\\Psi^{-1/2}W \\\\\n  \\Psi^{-1/2}W &= \\Psi^{-1/2}\\Xi\\Psi^{-1/2}(I + \\Psi^{-1/2}WW^T\\Psi^{-1/2})^{-1}\\Psi^{-1/2}W \\\\\n  \\Psi^{-1/2}WW^T\\Psi^{-1/2} &= \\Psi^{-1/2}\\Xi\\Psi^{-1/2}(I + \\Psi^{-1/2}WW^T\\Psi^{-1/2})^{-1}\\Psi^{-1/2}WW^T\\Psi^{-1/2} \\\\\n\\end{align}\nNow note that $\\Psi^{-1/2}WW^T\\Psi^{-1/2}$ is psd therefore it has a eigen-decomposition $USU^T$.\nIf we ASSUME that it is pd then we can say that \n\\begin{align}\n  I &= \\Psi^{-1/2}\\Xi\\Psi^{-1/2}(I+USU^T)^{-1}\\\\\n  (I+USU^T) &= \\Psi^{-1/2}\\Xi\\Psi^{-1/2} \\\\\n  \\implies \\Xi  &\\succcurlyeq \\Psi^{1/2}USU^T\\Psi^{1/2} = WW^T\n\\end{align}\n\n\\todo{It is not clear why we can assume that $WW^T$ which is a psd matrix is spd, but go ahead.}\n \n\\todo{Actually complete the derivation.}\n\n\\section{Incremental Statistical language models}\n\\subsection{PPCA as a language model}\nIt is not possible since it only has one view of data. and I do not\nwant to model the next word as the hidden state rather I want to say\nthat the next word is a view that is hidden from us and it is\nconnected to the visible view through a latent state.  \n\n\\subsection{Using PCCA as a language model}\n\\todo{Anything that I can do with PGCCA I can do with PCCA. It makes\n  sense to derive those things in the easier case and then to forge\n  ahead, Think about complexity, performance, advantages etc. at this\n  point.}\n\nTo do this I need to derive p(view 2| view 1) and ensure that it can\nbe computed efficiently. p(view 2 | view 1) would become the guassian\nlanguage model. \nSo basically\n\\begin{align}\n  p(y|x) &= \\frac{p(y,x)}{p(x)} \\\\\n  &= \\frac{\\int p(y,x,z)}{p(x)}\\\\\n  &= \\frac{\\int p(y,x|z)p(z)}{p(x)}\\\\\n  &= \\frac{\\int p(y|z)p(x|z)p(z)}{p(x)}\\\\\n\\end{align}\nBoth the numerator and the denominator I have calculated before so\nplug those values in to get $p(y|x)$ in closed form.\n\nNow the joint pdf of (view-1, view-2) that we calculated was joint normal with\nthe following multivariate normal distribution.\n\n\\pagebreak\nUnder probabilistic interpretation of CCA two views have the joint pdf as follows\n\\begin{align}\n  \\mu &= [\\tilde{\\mu}_1; \\tilde{\\mu}_2]\\; \\text{The sample mean.}\\\\\n  \\Sigma &= \\begin{bmatrix} W_1 W_1^T + \\Psi_1 & W_1 W_2^T \\\\ W_2 W_1^T & W_2 W_2^T + \\Psi_2\\end{bmatrix}\\\\\n  \\Psi_1 &= \\tilde{\\Sigma}_{11} - W_1 W_1^T\\\\\n  \\Psi_2 &= \\tilde{\\Sigma}_{22} - W_2 W_2^T\\\\\n  W_1 &= \\tilde{\\Sigma}_{11}U_{1d}\\\\\n  W_2 &= \\tilde{\\Sigma}_{22}U_{2d}\\\\\n  U_{1d} &= \\tilde{\\Sigma}_{11}^{-1/2} \\text{lsv}_d(\\tilde{\\Sigma}_{11}^{-1/2}\\tilde{\\Sigma}_{12}\\tilde{\\Sigma}_{22}^{-1/2})\\text{lsv=left singular vector}\\\\\n  U_{2d} &= \\tilde{\\Sigma}_{22}^{-1/2} \\text{rsv}_d(\\tilde{\\Sigma}_{11}^{-1/2}\\tilde{\\Sigma}_{12}\\tilde{\\Sigma}_{22}^{-1/2})\\\\\n  \\text{Sample Covariance} &= \\begin{bmatrix} \\tilde{\\Sigma}_{11} &\n    \\tilde{\\Sigma}_{12} \\\\ \\tilde{\\Sigma}_{21} & \\tilde{\\Sigma}_{22} \\end{bmatrix}\n\\end{align}\nWe know that $E[V_2 | V_1]$ is the following:\n$$E[V_2 | V_1] = \\tilde{\\mu}_2 + (W_2W_1^T)(W_1W_1^T+\\Psi_1)^{-1}(V_1 - \\mu_2)$$\n$$p(V_2 | V_1) = \\mathcal{N}(E[V_2 | V_1], W_2W_2^T+\\Psi_2 - W_2W_1^T(W_1W_1^T+\\Psi_1)^{-1}W_1W_2^T)$$\nSo now if we want to get a probability then we can explicitly calculate it.\n\nSo assume that I observe the following two views \\note{Both k and n are hyper-param}\n\\begin{align}\n  \\text{View-1: }\\begin{bmatrix}1 0 1 0 0 0 1 \\ldots\\end{bmatrix}\\\\\n  \\text{View 1 contains words 1 to n-1}\\\\\n  \\text{View-2: }\\begin{bmatrix}0 0 0 0 1 0 0 \\ldots\\end{bmatrix}\\\\\n  \\text{View 2 contains the nth word}\n\\end{align}\n%% Then we can estimate $\\alpha = E[\\text{View 2} | \\text{View 1}]$ and\n%% $\\beta = \\max(\\alpha - \\text{View 1})$.\nSo at test time my observations are encoded in view 1, which are encoded into a\nV-long count vector. Now I want to do prediction of view 2 which can then be used for  \n\\section{Probabilistic GCCA}\nWe want to derive probabilistic GCCA because then we can give a generative semantics to my embeddings and use them for language modelling.\n\\todo{TODO}\n\\end{document}\n", "meta": {"hexsha": "b65e39369427baa18b3323cbd4ec868f9f1fadc1", "size": 23852, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/themath_generative.tex", "max_stars_repo_name": "se4u/mvlsa", "max_stars_repo_head_hexsha": "19b91d190466b94b3eea72a6fcd43ac623b71a0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-08-07T10:11:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-16T02:42:58.000Z", "max_issues_repo_path": "tex/themath_generative.tex", "max_issues_repo_name": "se4u/mvlsa", "max_issues_repo_head_hexsha": "19b91d190466b94b3eea72a6fcd43ac623b71a0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-06-22T16:52:13.000Z", "max_issues_repo_issues_event_max_datetime": "2015-06-22T16:52:13.000Z", "max_forks_repo_path": "tex/themath_generative.tex", "max_forks_repo_name": "se4u/mvlsa", "max_forks_repo_head_hexsha": "19b91d190466b94b3eea72a6fcd43ac623b71a0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-06-14T17:39:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T02:42:59.000Z", "avg_line_length": 44.2523191095, "max_line_length": 206, "alphanum_fraction": 0.6086282073, "num_tokens": 10333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.6583202481765645}}
{"text": "\\subsubsection{Resonance ($\\omega = \\gamma$)}\r\n\\noindent\r\nIn the case where $\\omega = \\gamma$, we need to add an extra factor of $t$ to our guess for $y_p$. So,\r\n\\begin{equation*}\r\n\ty_p = At\\cos{(\\omega t)} + Bt\\sin{(\\omega t)}\r\n\\end{equation*}\r\nSolving for $A$ and $B$,\r\n\\begin{equation*}\r\n\tmy_p'' + ky_p = 2Bm\\omega\\cos{(\\omega t)} - 2Am\\omega\\sin{(\\omega t)} = F_0\\cos{(\\omega t)}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\implies A = 0 \\text{ and } B = \\frac{F_0}{2m\\omega}\r\n\\end{equation*}\r\nSo our solution is,\r\n\\begin{equation*}\r\n\ty = C_1\\cos{(\\omega t)} + C_2\\sin{(\\omega t)} + \\frac{F_0}{2m\\omega}t\\sin{(\\omega t)}\r\n\\end{equation*}\\\\\r\n\r\n\\noindent\r\nLet's look specifically at the IVP where $y(0) = 0$ and $y'(0) = 0$.\r\n\\begin{equation*}\r\n\tC_1 = C_2 = 0\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\ty = \\frac{F_0}{2m\\omega}t\\sin{(\\omega t)}\r\n\\end{equation*}\\\\\r\n\r\n\\noindent\r\nHere, the amplitude grows with $t$, creating bigger and bigger waves. This is resonance, and you can see mathematically how it is responsible for one string causing another tuned the same to vibrate and the collapsing of bridges.\r\n\r\n\\begin{center}\r\n\t\\includegraphics[width=0.75\\textwidth]{./higherOrder/forcedVibrs/resonance.png}\r\n\\end{center}", "meta": {"hexsha": "25fd52ebbfa46b8a228f3b90b0e5e0dabfb22816", "size": 1218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/forcedVibrs/resonance.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/resonance.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/resonance.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": 35.8235294118, "max_line_length": 230, "alphanum_fraction": 0.6609195402, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6583035490371884}}
{"text": "\\chapter{The two extremal problems}\n%\\addcontentsline{toc}{chapter}{The two extremal problems}\n \\section{The extremal limit problem}\n\\paragraph{The answer to the extremal limit problem} It turns out that all possible non-degenerate limiting distributions i.e. all extreme values distribution make up a one-parameter family $G_\\gamma(x) = \\exp(-(1 + \\gamma x)^{-\\frac{1}{\\gamma}})$, where the support of G is the set $\\{ x : 1 + \\gamma x > 0}$ and $\\gamma \\in \\mathbb{R}$ is the \\textbf{E}xtreme \\textbf{V}alue \\textbf{I}nded or \\textbf{EVI}. The three sub-cases are the following :\n\\begin{itemize}\n\t\\item \\underline{$\\gamma = 0$ :} \\textbf{Gumbel distribution} \\newline\n\t$G_\\gamma(u) = \\exp(- \\exp(- u))$, $u \\in \\mathbb{R}$\n\t\\item \\underline{$\\gamma > 0$ :} \\textbf{Fréchet distribution} \\newline\n\t$G_\\gamma(u) = \\exp(- (1 + \\gamma u)^{- \\frac{1}{\\gamma}})$, $u \\in ]- \\gamma^{-1}, + \\infty[$\n\t\\item \\underline{$\\gamma > 0$ :} \\textbf{Weibull distribution} \\newline\n\t$G_\\gamma(u) = \\exp(- (1 + \\gamma u)^{- \\frac{1}{\\gamma}})$, $u \\in ]- \\infty, - \\gamma^{-1}[$\n\\end{itemize}\nFor the derivations and proofs relative to this section, please report to the appendix.\n\\section{The domain of attraction problem}\n\\paragraph{Definition} The domain of attraction of an extreme value distribution family (i.e. Gumbel, Fréchet-type or Weibull-type) is the set of distribution functions $F_X$\\footnote{$F_X$ being the distribution of the $X_i$ of the sample.} such that the sequence of standardized maxima $(M_n^*)_{n \\ge 0}$ will converge in distribution to that extreme value distribution family.\n\\paragraph{Remark} There are many approaches to characterize the domains of attraction of the extreme value distribution families. We have decided to use Von Mises' theorem to characterize them. This is the historical approach, and a rather straightforward one, still by no means are alternative approaches uninteresting\\footnote{In particular, conditions based on the sole behaviour of $F_X$ can be formulated.}.\n\\paragraph{Hazard function} Let $X$ be a random variable with probability density function/mass function $f_X$ and distribution function $F_X$, then we define the hazard function $r$ as follows : \\newline\n$r(x) = \\frac{f_X(x)}{1 - F_X(x)}$.\n\\paragraph{A few preliminary notations} $\\Phi_\\alpha$, $\\Psi_\\alpha$, $\\Delta$ are respectively the symbols used to denote a Fréchet, a Weibull and a Gumbel distributions, with :\n\\begin{itemize}\n\t\\item $\\Phi_\\alpha(x) = \\exp(- x^\\alpha)$\n\t\\item $\\Psi_\\alpha(x) = \\exp(-  \\lvert x \\rvert^\\alpha)$ (let us bear in mind that this is a notation, due to historical reasons).\n\t\\item $\\Delta(x) = \\exp(- \\exp(- x))$\n\\end{itemize}\n\\paragraph{Von Mises' theorem}\n\\begin{enumerate}\n\t\\item If $x^+ = + \\infty$ and $x r(x) \\xrightarrow[x \\rightarrow + \\infty]{} \\alpha > 0$, then $F_X \\in \\mathcal{D}(\\Phi_\\alpha)$.\n\t\\item If $x^+ < + \\infty$ and $(x^+ - x) r(x) \\xrightarrow[x \\rightarrow x^+]{} \\alpha > 0$, then $F_X \\in \\mathcal{D}(\\Psi_\\alpha)$.\n\t\\item If $r(x)$ is ultimately positive in the neighbourhood of $x^+$ (with $x^+ \\le + \\infty$), is differentiable on that neighbourhood and is such that $\\frac{\\mathrm{d}r}{\\mathrm{d}x}(x) \\xrightarrow[x \\rightarrow x^+]{} 0$, then $F_X \\in \\mathcal{D}(\\Delta)$.\n\\end{enumerate}\n\\section{Conclusion}\n\\paragraph{Fisher-Tippett-Gnedenko theorem} The \\tetxbf{Fisher-Tippett-Gnedenko} theorem, also known as the \\textbf{extremal theorem}, states that if the sequence of standardized maxima converges in distribution to a non-degenerate distribution, then this distribution belongs to one of the three aforementioned extreme value distribution families. The theorem thus provides an answer to the \\textit{extremal limit problem}. Von Mises' theorem, encountered in the previous section, provides a complementary answer, that to the \\textit{domain of attraction problem}.\n\n\n\n\n\n\n", "meta": {"hexsha": "8890fcb93aa0e1d17c0fa66be7f20de95542aded", "size": 3856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/main/ch1_theExtremalProblems.tex", "max_stars_repo_name": "CillianMH/pdmExtremeValueTheory", "max_stars_repo_head_hexsha": "f7a7504c2eca0c6be665bcfc3d98dfee6c02de41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/main/ch1_theExtremalProblems.tex", "max_issues_repo_name": "CillianMH/pdmExtremeValueTheory", "max_issues_repo_head_hexsha": "f7a7504c2eca0c6be665bcfc3d98dfee6c02de41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/main/ch1_theExtremalProblems.tex", "max_forks_repo_name": "CillianMH/pdmExtremeValueTheory", "max_forks_repo_head_hexsha": "f7a7504c2eca0c6be665bcfc3d98dfee6c02de41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.8717948718, "max_line_length": 565, "alphanum_fraction": 0.7201763485, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.65830354555751}}
{"text": "\n\\subsection{The Euclidian metric}\n\nFor the Euclidian metric:\n\n\\(M=I\\)\n\n\\((dv )^TMdv =(dv)^T dv = d x^2+d y^2 + d z^2\\)\n\n\\(Action = \\int \\sqrt {dx^2+dy^2 + dz^2}\\)\n\n\\(Action = \\int \\sqrt {\\dot x^2+\\dot y^2 + \\dot z^2}d t\\)\n\n\\(Action = \\int vd t\\)\n\nWhat are symmetries here? Gallilean group and?\n\n", "meta": {"hexsha": "7c3acb6bec2501750f78ea90bfb949bb158a8bdc", "size": 296, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/physics/worldlines/04-01-euclid.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/physics/worldlines/04-01-euclid.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/physics/worldlines/04-01-euclid.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.4444444444, "max_line_length": 57, "alphanum_fraction": 0.5844594595, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6582596134900022}}
{"text": "\\section{Motion Model}\n\nThe motion model, $f$, is responsible for predicting the next state given the current state (and the control commands, if applicable).\n\nI use a simpler motion model than Justin's from 2020. Primarily, we do not use GPS coordinates or control parameters for making predictions, and these variables are not included in the state.\n\n\\begin{equation}\n    f(\\boldsymbol{\\hat{x}}_{k-1}, \\boldsymbol{u}, \\Delta t) = \n    \\begin{pmatrix}\n    x_{k-1} + \\dot{x}_{k-1} \\cdot \\Delta t \\\\\n    \\dot{x}_{k-1} \\\\\n    y_{k-1} + \\dot{y}_{k-1} \\cdot \\Delta t \\\\\n    \\dot{y}_{k-1} \\\\\n    \\phi_{k-1} + \\dot{\\phi}_{k-1} \\cdot \\Delta t \\\\\n    \\dot{\\phi}_{k-1} \\\\\n    v_{l,k-1} \\\\\n    v_{r,k-1}\n    \\end{pmatrix}\n\\end{equation}\n\nWe need to encode this system of equations into a matrix that can be used directly in the EKF. We cannot use simple matrix multiplication to compute $\\cos{\\phi}$ and $\\sin{\\phi}$, so these are re-computed and set at the start of the \\textit{Predict} phase on every clock cycle, and treated as if they are constants (cos\\_phi and sin\\_phi). Important robot characteristics are the constants $R$ = WHEEL\\_RADIUS and $L$ = WHEELBASE\\_LEN.\n\n\\begin{equation}\n    \\boldsymbol{F}_{k} =\n    \\begin{pmatrix}\n    1 & \\Delta t & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & \\frac{R}{2} \\textrm{cos\\_phi} & \\frac{R}{2} \\textrm{cos\\_phi} \\\\\n    0 & 0 & 1 & \\Delta t & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & \\frac{R}{2} \\textrm{sin\\_phi} & \\frac{R}{2} \\textrm{sin\\_phi} \\\\\n    0 & 0 & 0 & 0 & 1 & \\Delta t & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & \\frac{R}{L} & -\\frac{R}{L} \\\\\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\nThis matrix gives us the correct behavior of predicting the next state given the current state, as shown in the following equation.\n\n\\begin{equation}\n    \\boldsymbol{\\hat{x}}_{k+1} = \\boldsymbol{F}_{k} \\cdot \\boldsymbol{\\hat{x}}_{k}\n\\end{equation}\n\nWe use SymPy to calculate the Jacobean of the motion model. SymPy is a great python package for performing symbolic operations such as this. We obtain the following Jacobean, which is useful for linearizing the EKF.\n\n\\begin{equation}\n    \\begin{pmatrix}\n    1 & \\Delta t & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & -\\frac{R}{2} (v_l + v_r) \\sin{\\phi} & 0 & \\frac{R}{2} \\cos{\\phi} & \\frac{R}{2} \\cos{\\phi}  \\\\\n    0 & 0 & 1 & \\Delta t & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & \\frac{R}{2} (v_l + v_r) \\cos{\\phi} & 0 & \\frac{R}{2} \\sin{\\phi}  & \\frac{R}{2} \\sin{\\phi}  \\\\\n    0 & 0 & 0 & 0 & 1 & \\Delta t & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & \\frac{R}{L} & -\\frac{R}{L} \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\n    \\end{pmatrix}\n\\end{equation}", "meta": {"hexsha": "b6a9ff9b950cd2f78d78b24e435fe7364d246558", "size": 2732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/IGVC EKF Derivation/sections/motionmodel.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/motionmodel.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/motionmodel.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": 48.7857142857, "max_line_length": 435, "alphanum_fraction": 0.579795022, "num_tokens": 1091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6582596120855502}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\n\\newgeometry{margin=1in}\n\n\\title{Assignment 6}\n\n\n\\section{Question 1}\n\\begin{statebox}{Timescale Invariance}{question-1}\n    \\begin{align*}\n        S(t_{i+1}) &= S(t_i) + \\mu\\delta tS(t_i) + \\sigma\\delta tY_iS(t_i) \\\\S(t_{i+1}) &= S(t_i) + \\mu\\delta t^{1/4}S(t_i) + \\sigma\\delta tY_iS(t_i)\n    \\end{align*}\n    Please verify or dispute the timescale invariance of the two models above by numerical experiments.\n\\end{statebox}\n\nTherefore, we have the following code, which verifies the timescale invariance of the models by numerical experiments. And the result of the code below with the arguments $S_0=1$, $\\mu=0.05$, $\\sigma=0.5$, is Figure~\\ref{F:1}.\n\n\\lstset{showspaces=false, showtabs=false, tabsize=2, framexleftmargin=5mm, frame=shadowbox, numbers=left, numberstyle=\\tiny, breakautoindent=false}\n\\lstinputlisting[style=Matlab-Pyglike]{code/timescale_invariance_asset_path.m}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figures/2019-10-30-timescale-invariance.png}\n\t\\caption{Timescale Invariance Asset Path}\\label{F:1}\n\\end{figure}\n", "meta": {"hexsha": "30b6d32fa912e69377dfaafc63f43a5b2be7dbb4", "size": 1109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA216/sections/6.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/6.tex", "max_issues_repo_name": "AllenYZB/homework", "max_issues_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-01-13T03:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:49:10.000Z", "max_forks_repo_path": "MA216/sections/6.tex", "max_forks_repo_name": "AllenYZB/homework", "max_forks_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-02T05:46:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T23:11:28.000Z", "avg_line_length": 42.6538461538, "max_line_length": 226, "alphanum_fraction": 0.7321911632, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6582321854894685}}
{"text": "\\documentclass{article}\n\\pagestyle{empty}\n\\usepackage{amsmath,amssymb,amsfonts}\n\\usepackage{graphicx}\n\\usepackage{multicol}\n\\setlength{\\oddsidemargin}{0in} \\setlength{\\evensidemargin}{0in}\n\\setlength{\\topmargin}{0in} \\setlength{\\textheight}{8.5in}\n\\setlength{\\textwidth}{6.5in}\n\n\\makeatletter\n\\renewcommand*\\env@matrix[1][*\\c@MaxMatrixCols c]{%\n\t\\hskip -\\arraycolsep\n\t\\let\\@ifnextchar\\new@ifnextchar\n\t\\array{#1}}\n\\makeatother\n\n\\begin{document}\n\\begin{flushleft}\n\t\\bfseries{MATH 260, Linear Systems and Matrices, Fall `14}\\\\\n\t\\bfseries{Activity 4:  Matrices, RREF, and Solutions to Systems}\\\\\n\t%\\bfseries{Honor Code:} \\hspace{3.5in}\\bfseries{Names:}\\\\\n\\end{flushleft}\n\\begin{flushleft}\n\n\\section*{Row Operation Review}\n\n\\begin{center}\n$\\left[\\begin{array}{rrr|r}\n1 & 1 & 2 & 4\\\\\n2 & -1 & 1 & -4\\\\\n4 & 1 & 5 & 4\\\\\n\\end{array}\\right]\n$\\\\\n\\end{center}\n\nThere are three basic row operations we can perform (see page 134 of the text):\\\\\n$R_i$ means row \\textit{i} before an operation while $R_i^*$ denotes row \\textit{i} after an operation.\\\\\n1) Row swap between row \\textit{i} and row \\textit{j}, denoted: $R_i \\leftrightarrow R_j$\\\\\n2) Multiply a row \\textit{i} by a constant \\textit{c} ( with $c\\neq 0$) , denoted: $R_i^*=c R_i$\\\\\n3) Add a (multiple) of a row to another row, denoted: $R_i^*= R_i+c R_j$\\\\\n\\hrulefill \\\\\n\n\\vspace{0.2in}\n\\noindent\nLets try these out with our augmented matrix:\\\\\na) Perform the following row operations:\\\\\n\\vspace{0.2in}\n$\\begin{array}{c}\nR_2^* = R_2 + (-2) R_1\\\\\n\\rightarrow \\\\\nR_3^*=R_3+ (-4) R_1\\\\\n\\end{array}\n$\n\\hspace{0.25in}\n$\\begin{bmatrix}[ccc|c]\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\end{bmatrix}$\n\\hspace{0.2in}\n$\\begin{array}{c}\n\\\\\n\\\\\nR_2^* = - \\frac{1}{3} R_2 \\\\\n\\rightarrow \\\\\n\\\\\n\\end{array}\n$\n\\hspace{0.5in}\n$\\begin{bmatrix}[ccc|c]\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\end{bmatrix}$\\\\\n\\vspace{0.1in}\n$\\begin{array}{c}\nR_1^* = R_1 + (-1) R_2\\\\\n\\rightarrow \\\\\nR_3^*=R_3+ (3) R_2\\\\\n\\end{array}$\n\\hspace{0.25in}\n$\\begin{bmatrix}[ccc|c]\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}& \\hspace{0.2in}\\\\\n& & & \\\\\n\\end{bmatrix}$\\\\\n\n\\vspace{0.2in}\n\nYou should now have a matrix with 5 non-zero entries.  The first non-zero entry in each row should be a positive 1.\n\n\\newpage\n\\section{RREF}\nThe matrix we got at the end of the warmup was in \\textit{reduced row echelon form}. A matrix in RREF has the following traits (see page 136 of the text):\n\\begin{enumerate}\n\\item Any zero rows are at the bottom\n\\item The leftmost non-zero entry of each non-zero row equals 1.\\\\\n (This entry is called its \\textbf{pivot} or \\textbf{leading 1}.)\n\\item Each pivot is further to the right than the pivot in the row above it.\n\\item Each pivot is the only non-zero entry in its column.\\\\\n\\end{enumerate}\nDetermine if each of the following matrices is in RREF or not. If not, perform row operations to turn it into RREF.\\\\\n\\vspace{0.1in}\n\\begin{center}\n$\\textbf{M}=\\begin{bmatrix}[ccc|c]\n1 & 0 & -1 & 1\\\\\n0 & 1 & 1 & 0\\\\\n0 & 0 & 3 & -1\n\\end{bmatrix}$\n\\hspace{0.15in}\n$\\textbf{T}=\\begin{bmatrix}[cc|c]\n2 & -1 & 0\\\\\n1 & -1 & -3\n\\end{bmatrix}$\n\\hspace{0.15in}\n$\\textbf{A}=\\begin{bmatrix}[cccc|c]\n1 & 0 & 0 & 2 & 5\\\\\n0 & 1 & 0 & -2 & 2\\\\\n0 & 0 & 1 & 5 & 6\\\\\n0 & 0 & 0 & 0 & 2 \\\\\n\\end{bmatrix}$\\\\\n\\end{center}\n\n\\pagebreak\n\n\\section{Number of Solutions}\n\nTwo of the previous matrices, have the same traits in RREF, \\textbf{M} and \\textbf{T}.\\\\\n\n\\vspace{0.2in}\n\na) Describe the similarities between the two matrices in RREF.\n\n\\vspace{1.5in}\n\nb) What's different about \\textbf{A} and the matrix from the warmup?  \\textit{Hint: Look at where zeros occur.}  Write out what the last line of matrix \\textbf{A} represents in equation form.\n\n\\vspace{1.5in}\n\nJust like when we dealt with systems of equations, augmented matrices (which are representing systems!) can have 3 types of solutions:  unique, infinitely many, or none.  For the first two (unique and infinitely many) the system is said to be `consistent'.  For the last type, no solutions, the system is `inconsistent'.\n\n\\vspace{0.2in}\n\nc) Find which of the above matrices have unique solutions, infinite solutions, or no solutions by converting each back into equations (i.e. with $x_1$ ... $x_4$ as variables).\n\n\\newpage\n\n\\section{Rank and Pivots}\n\nA \\textbf{pivot column} of a matrix is any column that has a leading 1 in it (the rest of the entries in that column are zeros) once the matrix is put into RREF.  Note that if we're looking at augmented matrices, the last column (the one to the right of the vertical bar) is never a pivot column.\n\n\\vspace{0.2in}\n\nEx: For matrix \\textbf{M}, all three columns are pivot columns.\n\n\\vspace{0.2in}\n\nThe \\textbf{rank} of a matrix is the number of \\textit{pivot columns} it has (again, once it is in RREF).\n\n\\vspace{0.2in}\n\nEx: For matrix \\textbf{M} the rank is 3.\n\n\\vspace{0.2in}\n\na) Identify the pivot columns of each of \\textbf{T} and \\textbf{A} from page 2.\n\n\\vspace{2in}\n\nb) Identify the rank of each of \\textbf{T} and \\textbf{A}.\n\n\n\\end{flushleft}\n\\end{document}", "meta": {"hexsha": "472d51f06414d59166a224a6986ed64937e93a5b", "size": 5493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Fall 2014 - Capaldi A/Activities/Activity04_GaussJordanElim.tex", "max_stars_repo_name": "Pelonza/PB-LinAlg", "max_stars_repo_head_hexsha": "c92c2f3f9e3fc87a1a89041eb7bfaa1a87c9276d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fall 2014 - Capaldi A/Activities/Activity04_GaussJordanElim.tex", "max_issues_repo_name": "Pelonza/PB-LinAlg", "max_issues_repo_head_hexsha": "c92c2f3f9e3fc87a1a89041eb7bfaa1a87c9276d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fall 2014 - Capaldi A/Activities/Activity04_GaussJordanElim.tex", "max_forks_repo_name": "Pelonza/PB-LinAlg", "max_forks_repo_head_hexsha": "c92c2f3f9e3fc87a1a89041eb7bfaa1a87c9276d", "max_forks_repo_licenses": ["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.0163934426, "max_line_length": 320, "alphanum_fraction": 0.6763153104, "num_tokens": 2073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.6582182058345206}}
{"text": "\\section{Model Description}\n\n\\subsection{Introduction}\n\nThe hinged rigid body class is an instantiation of the state effector abstract class. The state effector abstract class is a base class for modules that have dynamic states or degrees of freedom with respect to the rigid body hub. Examples of these would be reaction wheels, variable speed control moment gyroscopes, fuel slosh particles, etc. Since the state effectors are attached to the hub, the state effectors are directly affecting the hub as well as the hub is back affecting the state effectors.\n\nSpecifically, a hinged rigid body state effector is a rigid body that has a diagonal inertia with respect to its $\\mathcal{S}_i$ frame as seen in Figure~\\ref{fig:FlexFigure}. It is attached to the hub through a hinge with a linear torsional spring and linear damping term. The dynamics of this multi-body problem have been derived and can be seen in Reference~\\cite{Allard2016rz}. The derivation is general for $N$ number of panels attached to the hub but does not allow for multiple interconnected panels. \n\n\\begin{figure}[htbp]\n\t\\centerline{\n\t\t\\includegraphics[width=0.8\\textwidth]{Figures/Fig4_4_2}}\n\t\\caption{Hinged rigid body frame and variable definitions}\n\t\\label{fig:FlexFigure}\n\\end{figure}\n\n\\subsection{Equations of Motion}\n\nThe following equations of motion (EOMs) are pulled from Reference~\\cite{Allard2016rz} for convenience. Equation~\\eqref{eq:Rbddot3} is the spacecraft translational EOM, Equation~\\eqref{eq:Final6} is the spacecraft rotational EOM, and Equation~\\eqref{eq:solar_panel_final3} is the hinged rigid body rotational EOM. These are the coupled nonlinear EOMs that need to be integrated in the simulation. \n\n\\begin{multline}\nm_{\\text{sc}} \\ddot{\\bm r}_{B/N}-m_{\\text{sc}} [\\tilde{\\bm{c}}]\\dot{\\bm\\omega}_{\\cal B/N}+\\sum_{i}^{N}m_{\\text{sp}_i} d_i  \\bm{\\hat{s}}_{i,3}\\ddot{\\theta}_i = \\bm F_{\\textnormal{ext}} - 2 m_{\\text{sc}} [\\tilde{\\bm\\omega}_{\\cal B/N}]\\bm{c}'\\\\\n-m_{\\text{sc}} [\\tilde{\\bm\\omega}_{\\cal B/N}][\\tilde{\\bm\\omega}_{\\cal B/N}]\\bm{c}-\\sum_{i}^{N}m_{\\text{sp}_i}d_i\\dot{\\theta}_i^2 \\bm{\\hat{s}}_{i,1}\n\\label{eq:Rbddot3}\n\\end{multline}\n\n\\begin{multline}\n\tm_{\\text{sc}}[\\tilde{\\bm{c}}]\\ddot{\\bm r}_{B/N}+[I_{\\text{sc},B}] \\dot{\\bm\\omega}_{\\cal B/N} +\\sum\\limits_{i}^{N}\\biggl\\lbrace I_{s_i,2}\\bm{\\hat{h}}_{i,2}+m_{\\text{sp}_i}d_i [\\tilde{\\bm{r}}_{S_i/B}] \\bm{\\hat{s}}_{i,3}\\biggr\\rbrace\\ddot{\\theta}_i = \\\\\n\t-[\\bm{\\tilde{\\omega}}_{\\cal B/N}] [I_{\\text{sc},B}] \\bm\\omega_{\\cal B/N} \n\t- [I'_{\\text{sc},B}] \\bm\\omega_{\\cal B/N} - \\sum\\limits_{i}^{N}\\biggl\\lbrace\\dot{\\theta}_i [\\bm{\\tilde{\\omega}}_{\\cal B/N}] \\left(I_{s_i,2} \\bm{\\hat{h}}_{i,2}+m_{\\text{sp}_i} d_i [\\tilde{\\bm{r}}_{S_i/B}] \\hat{\\bm s}_{i,3}\\right)\\\\ +m_{\\text{sp}_i}d_i\\dot{\\theta}_i^2[\\tilde{\\bm{r}}_{S_i/B}] \\bm{\\hat{s}}_{i,1} \\biggr\\rbrace + \\bm{L}_B\n\t\\label{eq:Final6}\n\\end{multline}\n\n\\begin{multline}\nm_{\\text{sp}_i} d_i \\hat{\\bm s}_{i,3}^{T} \\ddot{\\bm r}_{B/N}+ \\biggl[\\left(I_{s_{i,2}} + m_{\\text{sp}_i}d_i^{2}\\right) \\hat{\\bm s}_{i,2}^{T}-m_{\\text{sp}_i} d_i \\hat{\\bm s}_{i,3}^{T} [\\tilde{\\bm r}_{H_i/B}]\\biggr] \\dot{\\bm\\omega}_{\\cal B/N} \\\\\n+ \\left( I_{s_{i,2}} + m_{\\text{sp}_i} d_i^{2} \\right) \\ddot \\theta_i \n= - k_i \\theta_i - c_i \\dot\\theta_i + \\hat{\\bm s}_{i,2}^T \\bm \\tau_{\\text{ext},H_i} + \\left( I_{s_{i,3}} - I_{s_{i,1}} + m_{\\text{sp}_i}d_i^{2}\\right) \\omega_{s_{i,3}} \\omega_{s_{i,1}}\\\\\n- m_{\\text{sp}_i} d_i \\hat{\\bm s}_{i,3}^{T} [\\tilde{\\bm\\omega}_{\\cal B/N}][\\tilde{\\bm\\omega}_{\\cal B/N}] \\bm r_{H_i/B} \n\\label{eq:solar_panel_final3}\n\\end{multline}\n\n\\subsection{Back Substitution Method}\n\nIn order to integrate the EOMs in a modular fashion, a back substitution method was developed and can be seen in Reference~\\cite{Allard2016rz}. The hinged rigid body model must adhere to this analytical form, and the details are briefly summarized in the equations following. First the hinged rigid body EOM is substituted into the translational EOM and rearranged:\n\\begin{multline}\n\\Big(m_{\\text{sc}} [I_{3\\times3}] +\\sum_{i=1}^{N}m_{\\text{sp}_i}d_i \\bm{\\hat{s}}_{i,3} \\bm a_{\\theta_i}^T\\Big)\\ddot{\\bm r}_{B/N}+\\Big(-m_{\\text{sc}} [\\tilde{\\bm{c}}] +\\sum_{i=1}^{N}m_{\\text{sp}_i}d_i \\bm{\\hat{s}}_{i,3} \\bm b_{\\theta_i}^T\\Big) \\dot{\\bm\\omega}_{\\cal B/N} \\\\\n= m_{\\text{sc}} \\ddot{\\bm r}_{C/N} \t- 2 m_{\\text{sc}} [\\tilde{\\bm\\omega}_{\\cal B/N}] \\bm c'\n-m_{\\text{sc}} [\\tilde{\\bm\\omega}_{\\cal B/N}][\\tilde{\\bm\\omega}_{\\cal B/N}]\\bm{c}\n-\\sum_{i=1}^{N}\\Big(m_{\\text{sp}_i}d_i \\dot{\\theta}_i^2 \\bm{\\hat{s}}_{i,1}+m_{\\text{sp}_i}d_i c_{\\theta_i} \\bm{\\hat{s}}_{i,3} \\Big)\n\\label{eq:Rbddot8}\n\\end{multline}\n\nFollowing the same pattern for the hub rotational EOM, Eq.~\\eqref{eq:Final6}, yields:\n\\begin{multline}\n\\Big[m_{\\text{sc}}[\\tilde{\\bm{c}}] +\\sum\\limits_{i=1}^{N}\\big( I_{s_{i,2}}\\bm{\\hat{s}}_{i,2}+m_{\\text{sp}_i}d_i [\\tilde{\\bm{r}}_{S_{c,i}/B}] \\bm{\\hat{s}}_{i,3}\\big)\\bm a_{\\theta_i}^T \\Big]\\ddot{\\bm r}_{B/N}\\\\\n+\\Big[[I_{\\text{sc},B}]+\\sum\\limits_{i=1}^{N}\\big( I_{s_{i,2}}\\bm{\\hat{s}}_{i,2}+m_{\\text{sp}_i}d_i [\\tilde{\\bm{r}}_{S_{c,i}/B}] \\bm{\\hat{s}}_{i,3}\\big) \\bm b_{\\theta_i}^T\\Big] \\dot{\\bm\\omega}_{\\cal B/N}\n= \n-[\\bm{\\tilde{\\omega}}_{\\cal B/N}] [I_{\\text{sc},B}] \\bm\\omega_{\\cal B/N} \n- [I'_{\\text{sc},B}] \\bm\\omega_{\\cal B/N} \\\\\n-\\sum\\limits_{i=1}^{N}\\biggl\\lbrace\\big(\\dot{\\theta}_i [\\bm{\\tilde{\\omega}}_{\\cal B/N}] +c_{\\theta_i} [I_{3\\times3}]\\big) \\left(I_{s_{i,2}} \\bm{\\hat{s}}_{i,2}+m_{\\text{sp}_i} d_i [\\tilde{\\bm{r}}_{S_{c,i}/B}] \\hat{\\bm s}_{i,3}\\right) +m_{\\text{sp}_i}d_i\\dot{\\theta}_i^2[\\tilde{\\bm{r}}_{S_{c,i}/B}] \\bm{\\hat{s}}_{i,1} \\biggr\\rbrace + \\bm{L}_B\n\\label{eq:Final9}\n\\end{multline}\t\n\nWith the following definitions:\n\n\\begin{subequations}\n\t\\begin{align}\n\t\\bm a_{\\theta_i} &= - \\frac{m_{\\text{sp}_i} d_i}{\\left( I_{s_{i,2}} + m_{\\text{sp}_i} d_i^{2} \\right)} \\hat{\\bm s}_{i,3}\n\t\\label{eq:solar_panel_final11}\n\t\\\\\n\t\\bm b_{\\theta_i} &= -\\frac{1}{\\left( I_{s_{i,2}} + m_{\\text{sp}_i} d_i^{2} \\right)} \\bigg[\\left(I_{s_{i,2}} + m_{\\text{sp}_i}d_i^{2}\\right) \\hat{\\bm s}_{i,2}+m_{\\text{sp}_i} d_i [\\tilde{\\bm r}_{H_i/B}] \\hat{\\bm s}_{i,3}\\bigg]\n\t\\\\\n\t\\begin{split}\n\tc_{\\theta_i} &= \\frac{1}{\\left( I_{s_{i,2}} + m_{\\text{sp}_i} d_i^{2} \\right)} \\Big(- k_i \\theta_i - c_i \\dot\\theta_i + \\hat{\\bm s}_{i,2} \\cdot \\bm \\tau_{\\text{ext},H_i} + \\left( I_{s_{i,3}} - I_{s_{i,1}} + m_{\\text{sp}_i}d_i^{2}\\right) \\omega_{s_{i,3}} \\omega_{s_{i,1}} \\\\\n\t&- m_{\\text{sp}_i} d_i \\hat{\\bm s}_{i,3}^{T} [\\tilde{\\bm\\omega}_{\\cal B/N}][\\tilde{\\bm\\omega}_{\\cal B/N}] \\bm r_{H_i/B}\\Big)\n\t\\label{eq:solar_panel_final6}\n\t\\end{split}\n\t\\end{align}\n\\end{subequations}\n\nThe equations can now be organized into the following matrix respresentation:\n\n\\begin{equation}\n\\begin{bmatrix}\n[A] & [B]\\\\\n[C] & [D]\n\\end{bmatrix} \\begin{bmatrix}\n\\ddot{\\bm r}_{B/N}\\\\\n\\dot{\\bm\\omega}_{\\cal B/N}\n\\end{bmatrix} = \\begin{bmatrix}\n\\bm v_{\\text{trans}}\\\\\n\\bm v_{\\text{rot}}\n\\end{bmatrix}\n\\label{eq:backSub}\n\\end{equation}\n\nFinally, the hinged rigid body model must make ``contributions\" to the matrices defined in Equations~\\eqref{eq:backSub}. These contributions are defined in the following equations: \n\n\\begin{align}\n[A_{\\textnormal{contr}}] &= m_{\\text{sp}_i}d_i \\bm{\\hat{s}}_{i,3} \\bm a_{\\theta_i}^T\n\\\\\n[B_{\\textnormal{contr}}] &= m_{\\text{sp}_i}d_i \\bm{\\hat{s}}_{i,3} \\bm b_{\\theta_i}^T \n\\\\\n[C_{\\textnormal{contr}}] &= \\big( I_{s_{i,2}}\\bm{\\hat{s}}_{i,2}+m_{\\text{sp}_i}d_i [\\tilde{\\bm{r}}_{S_{c,i}/B}] \\bm{\\hat{s}}_{i,3}\\big)\\bm a_{\\theta_i}^T\n\\\\\n[D_{\\textnormal{contr}}] &= \\big( I_{s_{i,2}}\\bm{\\hat{s}}_{i,2}+m_{\\text{sp}_i}d_i [\\tilde{\\bm{r}}_{S_{c,i}/B}] \\bm{\\hat{s}}_{i,3}\\big) \\bm b_{\\theta_i}^T\n\\\\\n\\bm v_{\\text{trans,contr}} &= -\\Big(m_{\\text{sp}_i}d_i \\dot{\\theta}_i^2 \\bm{\\hat{s}}_{i,1}+m_{\\text{sp}_i}d_i c_{\\theta_i} \\bm{\\hat{s}}_{i,3} \\Big)\n\\\\\n\\bm v_{\\text{rot,contr}} &= -\\biggl\\lbrace\\big(\\dot{\\theta}_i [\\bm{\\tilde{\\omega}}_{\\cal B/N}] +c_{\\theta_i} [I_{3\\times3}]\\big) \\left(I_{s_{i,2}} \\bm{\\hat{s}}_{i,2}+m_{\\text{sp}_i} d_i [\\tilde{\\bm{r}}_{S_{c,i}/B}] \\hat{\\bm s}_{i,3}\\right) +m_{\\text{sp}_i}d_i\\dot{\\theta}_i^2[\\tilde{\\bm{r}}_{S_{c,i}/B}] \\bm{\\hat{s}}_{i,1} \\biggr\\rbrace \n\\end{align}\n\nThe final equation that is needed is:\n\n\\begin{equation}\n\\ddot \\theta_i = \\bm a_{\\theta_i}^T \\ddot{\\bm r}_{B/N} + \\bm b_{\\theta_i}^T \\dot{\\bm\\omega}_{\\cal B/N} + c_{\\theta_i}\n\\label{eq:solar_panel_final5}\n\\end{equation}\n\n\n", "meta": {"hexsha": "a0100faf5d725c34ef3f94b8fb559ecd8d124178", "size": 8285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/dynamics/HingedRigidBodies/_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/HingedRigidBodies/_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/HingedRigidBodies/_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": 69.0416666667, "max_line_length": 507, "alphanum_fraction": 0.6487628244, "num_tokens": 3505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740728, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6581729854920434}}
{"text": "\\section*{Maneouver Computations}\n\\addcontentsline{toc}{section}{Maneouver Computations}\nLet us assume symmetric flight (no lateral aerodynamic force $Q=0$ nor lateral thrust force as $\\nu=0$), the thrust generated by the engines is parallel to the \\textit{x} wind axis (thus $\\epsilon=0$),  and that the maneuver takes place flawlessly, this is in the vertical plane too; $\\xi=\\dot{\\xi}=0$.\\\\\nAs the maneuver is a rather short, we will also assume that the fuel consumed i negligible and no mass fraction is lost; $\\dot{m}=0$.\\\\\nThe motion equations follow \\cite{tierno}:\n\n\\begin{equation*}\n\t\\begin{cases}\n\tT\\cos(\\epsilon)\\cos(\\nu) - D -mg\\sin\\gamma-m\\dot{V}=0\\\\\n\tT\\cos(\\epsilon)\\sin(\\nu) - Q+mg\\cos\\gamma\\sin\\mu+...\\\\\n\t...+mV(\\dot{\\gamma}\\sin\\mu-\\dot{\\Xi}\\cos\\gamma\\cos\\mu)=0\\\\\n\t-T\\sin\\epsilon-L+mg\\cos\\gamma\\cos\\mu+...\\\\\n\t...+mV(\\dot{\\gamma}\\cos\\mu-\\dot{\\Xi}\\cos\\gamma\\sin\\mu)=0\\\\\n\t\\dot{x}_e=V\\cos\\gamma\\cos\\Xi\\\\\n\t\\dot{y}_e=V\\cos\\gamma\\sin\\Xi\\\\\n\t\\dot{x}_e=-V\\sin\\gamma\n\t\\end{cases}\n\\end{equation*}\n\nAnd for each of the phases that compose the maneuver, they can be simplified by substituting the flight conditions.\n\n\\begin{center}\n\\begin{tabular}{|l|c|c|c|}\\hline\n\t& $\\mu$ & $\\gamma=\\dot{\\gamma}$ & $\\xi=\\dot{\\xi}=\\nu=\\epsilon=Q$\\\\ \\hline  \\hline\n\tCruise & 0 & 0 & 0 \\\\ \\hline\n\tSemicirle & 0 & f(t) & 0 \\\\ \\hline\n\tInversion& f(t) & 0 & 0 \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection*{First phases - cruise}\n\\addcontentsline{toc}{subsection}{First phases - cruise}\n\\begin{equation}\n\t\\begin{cases}\n\t\tT - D -m\\dot{V}=0\\\\\n\t\t0=0\\\\\n\t\t-L+mg=0\\\\\n\t\t\\dot{x}_e=V\\\\\n\t\t\\dot{y}_e=0\\\\\n\t\t\\dot{x}_e=0\n\t\\end{cases}\n\\end{equation}\nThere are three equations and four variables; $\\alpha$, $\\pi$ and V\nTotal degrees of freedom is one, although in further study both $\\alpha$ and $\\pi$ will be fixated.\n\n\\subsection*{Second phase - semicircle}\n\\addcontentsline{toc}{subsection}{Second phase - semicircle}\n\\begin{equation}\n\t\\begin{cases}\n\t\tT - D -mg\\sin\\gamma-m\\dot{V}=0\\\\\n\t\t0=0\\\\\n\t\t-L+mg\\cos\\gamma+mV\\dot{\\gamma}=0\\\\\n\t\t\\dot{x}_e=V\\cos\\gamma\\\\\n\t\t\\dot{y}_e=0\\\\\n\t\t\\dot{z}_e=-V\\sin\\gamma\n\t\\end{cases}\n\\label{eq:semicircle}\n\\end{equation}\nThere are four equations and four variables: $\\alpha$, $\\pi$, V and $\\gamma$. The elevator and gas control lever or throttle are for controlling $\\alpha$ and $\\pi$ respectively. In further study both of them will be fixed.\n\n\n\\subsection*{Third phase - inversion}\n\\addcontentsline{toc}{subsection}{Third phase - inversion}\n\\begin{equation}\n\t\\begin{cases}\n\t\tT - D -m\\dot{V}=0\\\\\n\t\tmg\\sin\\mu=0\\\\\n\t\t-L-mg\\cos\\mu=0\\\\\n\t\t\\dot{x}_e=V\\\\\n\t\t\\dot{y}_e=0\\\\\n\t\t\\dot{z}_e=0\n\t\\end{cases}\n\\end{equation}\nThere are three equations and five variables; $\\alpha$, $\\pi$, V and $\\mu$. Except from the velocity, they can be controlled by the pilot trhough the elevator deflection, gas lever and ailerons respectively.\nTotal degrees of freedom are, therefore, 2. In further study both the elevator deflection and gas elever will be fixated.\n\n\\subsection*{Forth phase - cruise}\n\\addcontentsline{toc}{subsection}{Forth phase - cruise}\n\\begin{equation}\n\t\\begin{cases}\n\t\tT - D -m\\dot{V}=0\\\\\n\t\t0=0\\\\\n\t\t-L+mg=0\\\\\n\t\t\\dot{x}_e=V\\\\\n\t\t\\dot{y}_e=0\\\\\n\t\t\\dot{z}_e=0\n\t\\end{cases}\n\\end{equation}\nThere are three equations and four variables; $\\alpha$, $\\pi$ and V. The dynamics are identical to those in the first phase, as both of them are cruise flight.", "meta": {"hexsha": "68a4b2eef8926d940eaaeac63574d65f318ba700", "size": 3333, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/eqmov.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/eqmov.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/eqmov.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": 37.4494382022, "max_line_length": 304, "alphanum_fraction": 0.6825682568, "num_tokens": 1195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6581729843508642}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Semantic segmentation models}\r\n\\label{section:semantic_segmentation}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\nIn the last few years, DL techniques were rapidly developed in different life applications such as computer vision.  \r\nImage segmentation is a well-known technique employed for computer vision. \r\nIt aims to label each pixel in the input image to its matching class and it is applied in many real-life practical applications such as self-driving cars, medical imaging, traffic control systems, video surveillance, and many others.\r\nIn this work, we present a comparative study of five DL models based on Fully Convolutional Networks (FCN)~\\cite{Long} to detect and localise delamination in composite plates.\r\nFurther, these models aim to perform image semantic segmentation by assigning every pixel of the input image as damaged or not damaged. \r\nFCN is created by stacking convolutional layers in an encoder-decoder scheme and skipping dense layers. \r\nThe encoder part is responsible for extracting condensed feature maps from the input image at different scale levels by applying cascaded convolutions with strides followed by pooling operations.\r\nThe decoder part is responsible for upsampling the condensed feature maps to the same size as the original input image using transposed convolution with strides or upsampling with interpolation.\r\n\r\nIn this work, the softmax activation function was applied at the output layer for all implemented models in this comparative study.\r\nThe softmax calculates the probability for each predicted output of being damaged or undamaged for every single pixel, which implies that the sum of the two probabilities must be one. \r\nEq.~(\\ref{softmax}) depicts the softmax activation function, where \\(P(x)_{i}\\) is the probability of each target class \\(x_{j}\\) over all possible target classes \\(x_{j}\\), C in our case are two classes  (damaged and undamaged).\r\nTo predict the label of the output (\\(y_{pred}\\)) an \\(\\argmax\\) function is applied to select the maximum probability between both of them.\r\n\t\\begin{equation}\r\n\t\tP(x)_{i} = \\frac{e^{x_{i}}}{\\sum_{j}^{C} e^{x_{j}}}\r\n\t\t\\label{softmax}\r\n\t\\end{equation} \r\n\t\\begin{equation}\r\n\t\ty_{pred} = \\argmax_{i}\\left( P(x)_{i} \\right)\r\n\t\t\\label{argmax}\r\n\t\\end{equation}\r\nSelecting a suitable loss function is an important issue because it measures how well the model learns and performs.\r\nTherefore, in all models, we have applied the categorical cross-entropy (CCE) loss function~\\cite{Bonaccorso2020}, which is also called \\enquote{softmax loss function}.\r\nCCE is used as the objective function to estimate the difference between the actual damage (ground truth) and the predicted damage.\r\nFurther, since we have only two classes to be predicted, it is worth mentioning that a Sigmoid activation function at the output layer can be used with a binary cross-entropy (BCE), with no impacts on the predicted outputs.\r\nEq.~(\\ref{CCE}) illustrates the CCE, where \\( P(x)_{i}\\) is the softmax value of the target class. \r\n\t\\begin{equation}\r\n\tCCE = -\\log\\left( P(x)_{i} \\right)\r\n\t\\label{CCE}\r\n\t\\end{equation}\r\n\r\nAdditionally, it is also important to select a proper accuracy metric of the model, therefore, we have applied intersection over union (\\(IoU\\)) (Jaccard index)~\\cite{Bertels2019} as our accuracy metric. \r\n\\(IoU\\) is estimated by determining the intersection area between the ground truth and the predicted output.\r\nIn this work, we have two classes (damaged and undamaged), the \\(IoU\\) is computed by taking the \\(IoU\\) for the damaged class only.\r\nThe \\(IoU\\) metric is defined as in Eq.~(\\ref{IoU}):\r\n\\begin{equation}\r\nIoU = \\frac{Intersection}{Union} = \\frac{\\hat{Y} \\cap Y}{\\hat{Y} \\cup Y} \r\n\\label{IoU}\r\n\\end{equation}\r\nwhere \\(\\hat{Y}\\) represents the predicted vector of damaged and undamaged values, and \\(Y\\) represents the vector of ground truth values.\r\nThe \\(IoU\\) can be calculated by multiplying the predicted output (matrix of \\(zeros\\) and \\(ones\\)) with its ground truth (matrix of \\(zeros\\) and \\(ones\\)) to find the intersection, then it is divided over the union which can be calculated by counting all pixels with non-zero values of the predicted output and its ground truth.\r\n\r\nFurthermore, Adam optimizer was applied as our optimization method in order to increase the \\(IoU\\) and to reduce the loss during the training.\r\nIn the next subsections, we present five FCN models for pixel-wise semantic segmentation to detect and localise delaminations.", "meta": {"hexsha": "5b3efda41380c04d2c6b174b2ba58deb8f5bb379", "size": 4580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/journal_papers/MSSP_2/semantic_segmentation.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/MSSP_2/semantic_segmentation.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/MSSP_2/semantic_segmentation.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": 95.4166666667, "max_line_length": 332, "alphanum_fraction": 0.7447598253, "num_tokens": 1047, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6581729782109144}}
{"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\\newtheorem{theorem}{Theorem}\n\\newtheorem{remark}{Remark}\n\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\\vspace {1em} \n\\begin {Instruction} \nAdapted From Virginia Williams' lecture notes.\n\\end {Instruction}  \n\n{\\LARGE \\textbf {COMP 285 (NC A\\&T, Spr `22)}\\hfill \\textbf {Lecture 14} } \n\n\\begin{centering}\n\\section*{Universal Hash Families}\n\\end{centering}\n\n\\section{Hashing with a completely random hash function}\n\nWhat does it mean for $h$ to be random? One possibility is that $h$ is chosen uniformly and at random from amongst the set of all hash functions $h : U \\rightarrow \\{1, 2, \\cdots , n\\}$. In fact picking such a hash function is not really practical. Note that there are $n^{|U|}$ possible hash functions. Representing just one of these hash functions requires $\\log ( n^{|U|} ) = |U|\\log n$ bits. In fact, this means we need to write down $h(x)$ for every $x \\in U$ in order to represent $h$. That's a lot of storage space! Much more than the size of the set we are trying to store in the hash table. One could optimize this somewhat by only recording $h(x)$ for all keys $x$ seen so far (and generating $h(x)$ randomly on the fly when a new $x$ is encountered), but this is impractical too. How would we check if a particular key $x$ has already been encountered? Looks like we would need a hash table for that. But wait, isn't that what we set out to implement? Overall, it is clear that picking a completely random hash function is completely impractical.\n\nDespite this, we will analyze hashing assuming that we have a completely random hash function and then explain how this assumption can be replaced by something that is practical.\n\n\\textbf{Expected cost of hash table operations with random hash functions} \n\nWhat is the expected cost of performing any of the operations Insert, Lookup, or Delete with a random hash function? Suppose that the keys currently in the hash table are $x_1, \\cdots, x_n$. Consider an operation involving key $x_i$ . The cost of the operation is linear in the size of the hash bucket that $x_i$ maps to. Let $X$ be the size of the hash bucket that $x_i$ maps to. $X$ is a random variable and\n\n\\begin{align*}\n  \\mathbb{E}[X] &= \\sum_{j=1}^n \\mathbb{P}[h(x_i) = h(x_j)] \\\\\n  &= 1 + \\sum_{j\\neq i} \\mathbb{P}[h(x_i) = h(x_j)] \\tag{We are guaranteed to collide with ourselves} \\\\\n  &= 1 + \\frac{n-1}{n} \\leq 2\n\\end{align*}\nHere the last step follows from the fact that $\\mathbb{P}[h(x_i ) = h(x_j )] = 1/n$ when $h$ is random. Note that each key appears in the hash table at most once.\n\nThus the expected cost of any hashing operation is a constant.\n\n\\subsection{Universal Hash Functions \\& Intro to Graphs}\nCan we retain the expected cost guarantee of the previous section with a much simpler (i.e.,practical) family of hash functions? In the analysis of the previous section, the only fact we used about random hash functions was that $\\mathbb{P}[h(x_i ) = h(x_j )] = 1/n$. Is it possible toconstruct a small, practical subset of hash functions with this property?\n\nThinking along these lines, in 1978, Carter and Wegman introduced the notion of universal hashing: Consider a family $F$ of hash functions from $U to \\{1, 2, \\cdots , n\\}$. We say that $F$ isuniversal if, for every $x_i \\neq x_j$, for an $h$ chosen randomly from $F$ , $\\mathbb{P}[h(xi ) = h(xj )] \\leq 1/n$.\n\nClearly the analysis of the previous section shows that for any universal family, the constant expected running time guarantee applies. The family of all hash functions is universal. Is there a simpler universal family?\n\n\\section{A universal family of hash functions} \nSuppose that the elements of the $U$ are encoded as non-negative integers in the range ${0, \\cdots, |U| - 1}$. Pick a prime $p \\geq |U|$. For $a, b \\in \\{0, \\cdots p - 1\\}$, consider the family of hash functions \n\n$$\nh_{a,b}(x) = (ax + b \\mod p) \\mod n\n$$\n\nwhere $a \\in \\{1, \\cdots , p - 1\\}$ and $b \\in {0, 1, \\cdots , p - 1}$. \n\n\\textbf{Proposition 1}. \\textit{This family of hash functions $F$ is universal}. \n\nIn order to prove this statement, first, let’s count the number of hash functions in this family $F$ . We have $p-1$ choices for $a$, and $p$ choices for $b$, so $|F| = p(p-1)$. In order to prove that $F$ is universal, we need to show that for an $h$ chosen randomly from $F$ , $\\mathbb{P}[h(x_i ) = h(x_j )] \\leq 1/n$. Since there are $p(p - 1)$ hash functions in $F$ , this is equivalent to showing that the number of hash functions in $F$ that map $x_i$ and $x_j$ to the same output is less than or equal to $\\frac{p(p-1)}{n}$ . To show that this is true, first consider how $h_{a,b}$ behaves without the $\\mod n$. Call these functions $f_{a,b}$:\n$$\nf_{a,b}(x) = ax + b \\mod p \n$$\nThe $f_{a,b}$ have the following useful property: \n\n\\textbf{Proposition 2.} \\textit{For a given $x_1, x_2, y_1, y_2 \\in \\{0, \\cdots , p - 1\\}$ such that $x_1 \\neq x_2$ there exists only one function $f_{a,b}$ such that $f_{a,b}(x_1) = y_1$, and $f_{a,b}(x_2) = y_2$}\n\n Proof. Solve the above two equations for $a$ and $b$:\n\n \\begin{align*}\n  ax_1 + b &\\equiv y_1 (\\mod p) \\\\\n  ax_2 + b &\\equiv y_2 (\\mod p)\n\\end{align*}\nBy subtracting the two equations, we get:\n$$\na(x_1 - x_2) \\equiv y_1 - y_2 (\\mod 6)\n$$\nSince $p$ is prime and $x1 \\neq x2$, the above equation has only one solution for $a \\in \\{0, \\cdots , p -1\\}$.\nThen\n$$\nb \\equiv y_1 - ax_1 (\\mod p)\n$$\nSo we have found the unique a and b such that $f_{a,b}(x_1) = y_1$ and $f_{a,b}(x_2) = y_2.$\n\nIn the above proof, note that $a = 0$ only when $y_1 = y_2 = b$. This is why we restrict $a \\neq 0$, we don’t want the hash function mapping all elements to the same value $b$. Now, we have shown that for a given $x_1, x_2$, for each selection of $y_1, y_2$ with $y_1 \\neq y_2$, there is exactly one function $f_{a,b}$ that maps $x_1$ to $y_1$ and $x_2$ to $y_2$. So, in order to find out how many functions $h_{a,b}$ map $x_1$ and $x_2$ to the same value $\\mod n$, we just need to count the number of pairs $(y_1, y_2)$ where $y_1 \\neq y_2$ and $y_1 \\equiv y_2 (mod n)$. There are $p$ possible selections of $y_1$ for this pair, and then $\\leq (p - 1)/n$ of the possibilities for $y_2$ will be equal to $y_1 \\mod n$. (Convince yourself that this is true.) This gives a total of $\\frac{p(p-1)}{n}$ functions $h_{a,b}$ that map $x_1$ and $x_2$ tothe same element. So then\n\n\\begin{align*}\n\\mathbb{P}[h_{a,b}(x_1) &\\leq h_{a,b}(x_2)] \\\\\n&\\leq \\frac{p(p-1)/n}{|F|} \\\\\n&= \\frac{p(p-1)}{p(p-1)(n)} \\\\\n&= \\frac{1}{n}\n\\end{align*}\n\nwhich means the family $F$ of the $h_{a,b}$ is universal, as desired.\n\nWrapping up the discussion on hashing, if we pick a random hash function from this family, then the expected cost of any hashing operation is constant. Note that picking a random hash function from the family simply involves picking $a, b$ – significantly simpler than picking a completely random hash function.\n\n\\section{Balls and Bins} \n\nA useful abstraction in thinking about hashing with random hash functions is the following experiment: Throw $m$ balls randomly into $n$ bins. (The connection to hashing should be clear: the balls represent the keys and the bins represent the hash buckets.) The balls into bins experiment arises in several other problems as well, e.g., analysis of load balancing. In the context of hashing, the following questions arise about the balls and bins experiment:\n\n\\begin{itemize}\n  \\item How large does $m$ have to be so that with probability greater than $1/2$, we have (at least) two balls in the same bin? This tells us how large our hash table needs to be to avoid any collisions. We will explore this at the end of these notes.\n  \\item Suppose $m = n$; what is the maximum number of balls that fall into a bin? This tells us the size of the largest bucket in the hash table when the number of keys is equal to the number of buckets in the table. We might explore this in the next homework.\n\\end{itemize}\n\n\\textbf{No Collisions}\n\nThe first question is related to the so called birthday paradox: Suppose you have $23$ people in a room. Then (somewhat surprisingly) the probability that there exists some pair with the same birthday is greater than $1/2$! (This assumes that birthdays are independent and randomly distributed.) $23$ seems like an awfully small number to get a pair with the same birthday. There are $365$ days in a year! How do we explain this? Consider throwing $m$ balls into $n$ bins. The expected number of pairs that fall into the same bucket is $m(m - 1)/2n$. (This follows from linearity of expectation. Note that the probability that a fixed pair falls into the same bucket is $1/n$.) Thus the probability that there is a collision is upper bounded by the expected number of collisions which is $m(m - 1)/2n$. (Convince yourself that this is true.) On the other hand, we can also show that the probability that all $m$ balls fall into distinct bins is at most $e^{-m(m-1)/2n}$:\n\n\\textit{Proof}\n$$\n\\mathbb{P}[\\text{no collisions}] = \\prod_{i=1}^{m-1}\\left( 1 - \\frac{i}{n}\\right)\n$$\nNow we use the fact that $(1-x) \\leq e^{-x}$:\n$$\n\\left(1 - \\frac{i}{n}\\right) \\leq e^{-i/n}\n$$\nSo\n\\begin{align*}\n  \\mathbb{P}[\\text{no collision}] &\\leq \\prod_{i=1}^{m-1} e^{i/n} \\\\\n  \\mathbb{P}[\\text{no collision}] &\\leq e^{\\sum_{i=1}^{m-1} -i/n} \\\\\n  \\mathbb{P}[\\text{no collision}] &\\leq e^{-m(m-1)/(2n)} \\\\\n\\end{align*}\n\nFor $m$ about $\\sqrt{(2 n \\ln 2)n} \\approx 1.18\\sqrt{n}$ this probability is less than $1/2$, i.e., the probability of a collision is greater than $1/2$.\n\nThis is a useful design principle to keep in mind: If we want to design a hash table with no collisions, then the size of the hash table should be larger than the square of the number of elements we need to store in it. For our purposes in this note, insisting on no collisions means that the number of elements in the hash table can only be a small fraction of the hash tablesize which is quite wasteful. \n\nThe birthday problem calculation is useful in other contexts. Here is an application: Suppose we assign random $b$-bit IDs to $m$ users. How large does $b$ have to be to ensure that all users have distinct IDs with probability $1 - \\delta$. Here $\\delta > 0$ is a given error tolerance. Assigning $b$-bit IDs is identical to mapping to $n = 2^b$ buckets. The birthday problem calculation shows us that the probability of a collision is at most $m^2/2n = m^2/2^{b+1}$. We should set $b$ large enough such that this bound is at most $\\delta$. Thus $b$ should be at least $2 \\log m - 1 + log(1/\\delta)$.\n\n\n\\section{Intro to Graphs} \nA graph is a set of vertices and edges connecting those vertices. Formally, we define a graph $G$ as $G = (V, E)$ where $E \\subseteq V \\times V$ . For ease of analysis, the variables $n$ and $m$ typically stand for the number of vertices and edges, respectively. Graphs can come in two flavors, directed or undirected. If a graph is undirected, it must satisfy the property that $(i, j) \\in E \\iff (j, i) \\in E$ (i.e., all edges are bidirectional). In undirected graphs, $m \\leq \\frac{n(n-1)}{2}$ . In directed graphs, $m \\leq n(n - 1)$. Thus, $m = O(n^2)$ and $\\log m = O(\\log n)$. A connected graph is a graph in which for any two nodes $u$ and $v$ there exists a path from $u$ to $v$ . For an undirected connected graph $m \\geq n - 1$. A sparse graph is a graph with few edges (for example, $\\Theta(n)$ edges) while a dense graph is a graph with many edges (for example, $m = \\Theta(n^2)$).\n\n\n\n\n\n\n\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\n\n", "meta": {"hexsha": "eee249ef2cd15a070a311f1a98afe2d96bac3880", "size": 12753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/lectures/lecture14.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/lecture14.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/lecture14.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": 64.0854271357, "max_line_length": 1057, "alphanum_fraction": 0.7054810633, "num_tokens": 3866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8652240877899776, "lm_q1q2_score": 0.6581332670895579}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\n\\title{Vibing Math (Geometry Problem)}\n\\author{Shreenabh Agrawal }\n\\date{\\today}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\geometry{a4paper, portrait, margin=1in}\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage[makeroom]{cancel}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\nConsider an isosceles triangle $ABC$ in which $AB = BC = 10$ units. Let $P_1, P_2, P_3, ... P_{60}$ be $60$ points on $BC$. Then, $$\\sum_{i=1}^{60} (AP_i^2 + P_iB\\times P_iC) = ?$$\t\n\n\\section{Solution}\nBy Stewart's Theorem, \n$$(AB^2\\times P_iC) + (AC^2\\times P_iB) = BC ( AP_i^2 + P_iB\\times P_iC)$$\nNow, $AB = 10$ and $AC = 10$ ,so above expression becomes, \n$$100 (P_iB + P_iC) = BC (AP_i^2 + P_iB\\times P_iC )$$\nBut here, $P_iB + P_iC = BC$, hence the above equation becomes\n$$100 \\cancel{(P_iB + P_iC)} = \\cancel{BC} (AP_i^2 + P_iB\\times P_iC )$$\n$$100 = (AP_i^2 + P_iB \\times P_iC)$$\nThis is true for all $i$ in $P_i$. Hence, the answer is\n$$\\sum_{i=1}^{60} (AP_i^2 + P_iB\\times P_iC) = 60 \\times 100$$\n$$\\boxed{= 6,000}$$\n\\end{document}\n\n", "meta": {"hexsha": "fb0a2988cebb3e87bee0e48385cb317258c858ed", "size": 1128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tig. and Geometry/vibing_math's questions/Sigma Geometry Stewart Triangle 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": "Tig. and Geometry/vibing_math's questions/Sigma Geometry Stewart Triangle 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": "Tig. and Geometry/vibing_math's questions/Sigma Geometry Stewart Triangle 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": 30.4864864865, "max_line_length": 181, "alphanum_fraction": 0.670212766, "num_tokens": 458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.6581332578373732}}
{"text": "\\documentclass[modern]{aastex63}\n\n\\usepackage{acro}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\DeclareMathOperator{\\var}{var}\n\n\\newcommand{\\dd}{\\mathrm{d}}\n\\newcommand{\\diff}[2]{\\frac{\\dd #1}{\\dd #2}}\n\n\\DeclareAcronym{PSD}{\n  short = {PSD},\n  long = {power spectral density}\n}\n\\DeclareAcronym{SNR}{\n  short = {SNR},\n  long = {signal to noise ratio}\n}\n\n\\begin{document}\n\n\\title{Optimal Detection of Stochastic Signals}\n\\author[0000-0003-1540-8562]{Will M. Farr}\n\\email{wfarr@flatironinstitute.org}\n\\affiliation{Center for Computational Astronomy, Flatiron Institute, New York NY 10010, United States}\n\\affiliation{Department of Physics and Astronomy, Stony Brook University, Stony Brook NY 11794, United States}\n\n\\begin{abstract}\n%\n  I derive an optimal statistic for detection of a common stochastic signal in\n  independent data streams.  I compute the SNR in terms of the \\ac{PSD} of the\n  common signal and each stream's noise, and give several useful limits.\n%\n\\end{abstract}\n\n\\section{Formalities}\n\nImagine we have a stochastic stationary zero-mean Gaussian signal, $h(t)$, whose\n\\ac{PSD} is $P_h(f)$:\n%\n\\begin{equation}\nP_h(f) = \\lim_{T \\to \\infty} \\frac{1}{T} \\left| \\int_{-T}^{T} \\dd t \\, e^{-2\\pi f t} h(t) \\right|^2.\n\\end{equation}\n%\nThe signal is linearly projected into two data streams\\footnote{The formalism\nhere generalizes easily to an arbitrary number of data streams.} with\nindependent stochastic stationary zero-mean Gaussian noise:\n%\n\\begin{equation}\n  s_1(t) = A_1 h(t) + n_1(t)\n\\end{equation}\n%\nand\n%\n\\begin{equation}\n  s_2(t) = A_2 h(t) + n_2(t),\n\\end{equation}\n%\nwhere the \\ac{PSD} of each stream's noise is\n%\n\\begin{equation}\n  P_i(f) = \\lim_{T \\to \\infty} \\frac{1}{T} \\left| \\int_{-T}^{T} \\dd t \\, e^{-2\\pi f t} n_i(t) \\right|^2,\n\\end{equation}\n%\nand the signal and both noise streams are independent:\n%\n\\begin{equation}\n  p\\left( h, n_1, n_2 \\right) = p\\left( h \\right) p\\left( n_1 \\right) p\\left( n_2 \\right).\n\\end{equation}\n\nStationarity implies that the Fourier components are independent; Gaussianity\nand the \\acp{PSD} imply that\n%\n\\begin{equation}\n  \\tilde{h}(f) \\sim N\\left[0, \\sqrt{T P_h(f)} \\right]\n\\end{equation}\n%\nand\n%\n\\begin{equation}\n  \\tilde{s}_i(f) \\sim N\\left[ A_i \\tilde{h}(f), \\sqrt{T P_i(f)} \\right],\n\\end{equation}\n%\nwhere $N[\\mu, \\sigma]$ is a Gaussian distribution with mean $\\mu$ and standard\ndeviation $\\sigma$.  Integrating out the (unknown) signal $h$\\footnote{See\n\\citet{Cornish2013}.}, we have the marginal likelihood for the data streams\n%\n\\begin{multline}\n  \\mathcal{L} \\left( s_1(f), s_2(f) \\mid P_h(f) \\right) = \\int \\dd h(f) \\, N\\left[ A_1 \\tilde{h}(f), \\sqrt{T P_1(f)} \\right]\\left( s_1(f) \\right) \\\\ \\times N\\left[ A_2 \\tilde{h}(f), \\sqrt{T P_2(f)} \\right]\\left( s_2(f) \\right) N\\left[0, \\sqrt{T P_h(f)} \\right]\\left( h(f) \\right).\n\\end{multline}\nA bit of algebra reveals\n%\n\\begin{multline}\n  \\mathcal{L} \\left( s_1, s_2 \\mid P_h \\right) = \\\\ \\frac{1}{2\\pi \\sqrt{S_h \\left( A_2^2 S_1 + A_1^2 S_2 \\right) + S_1 S_2}} \\exp\\left[ - \\frac{\\left(A_2 s_1 - A_1 s_2\\right)^2 S_h + s_2^2 S_1 + s_1^2 S_2}{2 \\left(\\left(A_2^2 S_1 + A_1^2 S_2 \\right)S_h + S_1 S_2 \\right)}\\right],\n\\end{multline}\n%\nwhere we have suppressed the dependence on $f$ for the moment, and absorbed the\n$T$-dependence into $S$ via\n%\n\\begin{equation}\n  S_x \\equiv T P_x\n\\end{equation}\n%\n(i.e.\\ $S_x$ is the variance of $\\tilde{x}$).\n\nThe maximum-likelihood estimator of $P_h$ is\n%\n\\begin{equation}\n  \\label{eq:ml-est}\n \\hat{P}_h \\equiv \\frac{1}{T} \\frac{\\left( A_2 S_1 s_2 + A_1 S_2 s_1 \\right)^2 - S_1 S_2 \\left( A_2^2 S_1 + A_1^2 S_2 \\right)}{\\left( A_2^2 S_1 + A_1^2 S_2 \\right)^2}.\n\\end{equation}\n%\nThe expected value of $\\hat{P}_h$ is\n%\n\\begin{equation}\n  \\left\\langle \\hat{P}_h \\right\\rangle = P_h\n\\end{equation}\n%\n(i.e.\\ $\\hat{P}$ is an un-biased estimator of $P_h$---whatever that is worth)\nand the variance is\n%\n\\begin{equation}\n  \\label{eq:est-variance}\n  \\var \\hat{P}_h = \\frac{2 \\left( S_h \\left(A_2^2 S_1 + A_1^2 S_2 \\right) + S_1 S_2 \\right)^2}{T^2 \\left( A_2^2 S_1 + A_1^2 S_2 \\right)^2} = \\frac{2 \\left( P_h \\left(A_2^2 P_1 + A_1^2 P_2 \\right) + P_1 P_2 \\right)^2}{\\left( A_2^2 P_1 + A_1^2 P_2 \\right)^2}\n\\end{equation}\n%\nNote that the variance in Eq.\\ \\eqref{eq:est-variance} is independent of $T$, so\nthat the \\ac{SNR} \\emph{in a single frequency bin} is independent of time.\n\nTypically we will be estimating the power in some range of frequencies, not just\nin a single bin.  Because the different frequencies are independent\n(stationarity), the optimal estimator for the integral of $P_h(f)$ over some\nrange is given by\n%\n\\begin{equation}\n  \\int_{f_0}^{f_1} \\dd f \\, \\hat{P}_h(f) \\simeq \\sum_{f = f_0}^{f_1} \\Delta f \\hat{P}_h(f),\n\\end{equation}\n%\nwhere $\\Delta f = 1/T$ is the frequency resolution implied by an observation\nover a time $T$.   The mean of this estimator is the integral of $P_h$ over the\ncorresponding interval; the variance of this estimator is given by\n%\n\\begin{equation}\n  \\sum_{f = f_0}^{f_1} \\Delta f^2 \\var \\hat{P}_h(f),\n\\end{equation}\n%\nand therefore the \\ac{SNR} of such a measurement is given by\n%\n\\begin{equation}\n  \\label{eq:finite-bandwidth-snr}\n  \\rho = \\frac{\\sqrt{T} \\int_{f_0}^{f_1} \\dd f \\, P_h\\left( f \\right)}{\\sqrt{\\int_{f_0}^{f_1} \\dd f \\, \\var \\hat{P}_h(f)}}\n\\end{equation}\n%\nwith $\\var \\hat{P}_h$ given by Eq.\\ \\eqref{eq:est-variance}.  We see that the\n\\ac{SNR} for a measurement over some finite bandwidth grows with $\\sqrt{T}$, as\nit should.\n\n\\section{Useful Limits}\n\n\\subsection{Signal-Dominated Limit}\n\nIf $A^2_{1,2} P_h \\gg P_{1,2}$ over the relevant range of frequencies, we have\n%\n\\begin{equation}\n  \\var \\hat{P}_h \\simeq 2 P_h^2,\n\\end{equation}\n%\nand the per-bin \\ac{SNR} asymptotes to $1/2$.  The finite-bandwidth \\ac{SNR},\nEq.\\ \\eqref{eq:finite-bandwidth-snr}, becomes\n%\n\\begin{equation}\n  \\rho \\simeq \\sqrt{\\frac{T \\left( f_1 - f_0 \\right)}{2}} \\frac{\\left\\langle P_h \\right\\rangle}{\\sqrt{\\left\\langle P_h^2 \\right\\rangle}}\n\\end{equation}\n%\nwhere angle brackets indicate an average over frequencies $f_0 \\leq f \\leq f_1$.\nNote that in this limit the \\ac{SNR} is independent of the amplitude of $P_h$.\n\n\\subsection{Noise-Dominated Limit}\n\nIn the opposite limit, $A_{1,2} P_h \\ll P_{1,2}$, we have\n%\n\\begin{equation}\n  \\var \\hat{P}_h \\simeq \\frac{2 P_1^2 P_2^2}{\\left( A_2^2 P_1 + A_1^2 P_2\\right)^2} = \\frac{2}{\\left( A_1^2 / P_1 + A_2^2/P_2 \\right)^2},\n\\end{equation}\n%\nand the finite-bandwidth \\ac{SNR} becomes\n%\n\\begin{equation}\n  \\rho \\simeq \\sqrt{\\frac{T\\left(f_1 - f_0 \\right)}{2}} \\frac{\\left\\langle P_h \\right\\rangle}{ \\sqrt{\\left\\langle \\frac{1}{\\left( A_1^2 / P_1 + A_2^2/P_2 \\right)^2}\\right\\rangle}}\n\\end{equation}\n%\nand the \\ac{SNR} is reduced compared to the signal-dominated case by a factor\n%\n\\begin{equation}\n  \\label{eq:approx-snr-reduction}\n  \\alpha \\sim \\frac{A_1^2 P_h}{P_1} + \\frac{A_2^2 P_h}{P_2}.\n\\end{equation}\n%\n\n\\bibliography{StochasticStats}\n\n\\end{document}\n", "meta": {"hexsha": "7925e404b32778a6e3a4767f38f3a2157d5e23ca", "size": 6881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "StochasticStats.tex", "max_stars_repo_name": "farr/StochasticStats", "max_stars_repo_head_hexsha": "2bf257006a7caee6c9524d042bc1680c54587f22", "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": "StochasticStats.tex", "max_issues_repo_name": "farr/StochasticStats", "max_issues_repo_head_hexsha": "2bf257006a7caee6c9524d042bc1680c54587f22", "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": "StochasticStats.tex", "max_forks_repo_name": "farr/StochasticStats", "max_forks_repo_head_hexsha": "2bf257006a7caee6c9524d042bc1680c54587f22", "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.7303921569, "max_line_length": 280, "alphanum_fraction": 0.6839122221, "num_tokens": 2630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6581332551938918}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% UMB-CS240-2016S: Programming in C\n% Copyright 2016 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/UMB-CS240-2016S\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nThe C programming language, as of C99, supports complex number math with the three built-in types \\texttt{double \\_Complex}, \\texttt{float \\_Complex}, and \\texttt{long double \\_Complex}.\nWhen the header \\texttt{<complex.h>} is included, the three complex number types are also accessible as \\texttt{double complex}, \\texttt{float complex}, \\texttt{long double complex}.\nStandard arithmetic operators \\texttt{+}, \\texttt{-}, \\texttt{*}, \\texttt{/} can be used with real, complex, and imaginary types in any combination.\n\nThe following program shows how complex numbers can be used in C. It loads components of complex numbers from a file and prints their sum on standard output.\n\n\\lstset{language=c,tabsize=4}\n\\lstinputlisting[firstline=10]{\\resDirectory/complex-numbers.h}\n\\lstinputlisting[firstline=10]{\\resDirectory/complex-numbers.c}\n\nThe program compiles and executes as expected.\nBased on the given source code, provide \\textbf{brief} answers for the following questions.\n\n\\begin{enumerate}\n\\item\nIn \\texttt{complex-numbers.h:10}, function \\texttt{cprint} is declared but not defined.\nWhat is the advantage of declaring a function in a header file?\nExplain why removing this line causes a compilation error and how the error can be resolved without including this line.\n\n\\item\nIn \\texttt{complex-numbers.c:13}, \\texttt{fp} is checked to make sure it is not \\texttt{null}.\nA CS240 student argues this checking is unnecessary if we make sure the file \\texttt{complex-numbers.txt} exists.\nDescribe whether you support this argument or not and provide brief explanations for your reasoning.\n\n\\item\nIn \\texttt{complex-numbers.c:17}, variables \\texttt{a} and \\texttt{b} are passed by reference to function \\texttt{scanf}.\nExplain what happens if they are passed by value.\n\n\\item\nIn \\texttt{complex-numbers.c:18}, \\texttt{I} is used but it is not explicitly declared either in \\texttt{complex-numbers.c} or \\texttt{complex-numbers.h}.\nThis also applies to functions \\texttt{creal} and \\texttt{cimag} in \\texttt{complex-numbers.c:31}.\nBriefly explain why such practice has not caused compilation error.\n\n\\item\nIn \\texttt{complex-numbers.c:21}, variable \\texttt{sum} is passed to \\texttt{cprint} by value. Modify this line and the function \\texttt{cprint} such that \\texttt{num} is passed by reference.\n\n\\end{enumerate}\n", "meta": {"hexsha": "e7bed460494cc3153ef6accd2de5a94442dca174", "size": 2707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/main/f02/f02q03.tex", "max_stars_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_stars_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-03T18:41:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-03T18:41:24.000Z", "max_issues_repo_path": "src/tex/main/f02/f02q03.tex", "max_issues_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_issues_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-05-16T23:55:39.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-20T03:04:35.000Z", "max_forks_repo_path": "src/tex/main/f02/f02q03.tex", "max_forks_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_forks_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.5957446809, "max_line_length": 191, "alphanum_fraction": 0.7399335057, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7341195385342972, "lm_q2_score": 0.8962513668985, "lm_q1q2_score": 0.65795563987826}}
{"text": "\\subsection{Undamped Forced Vibrations ($b = 0$)}\r\n\\noindent\r\nOur equation now becomes\r\n\\begin{equation*}\r\n\tmy'' + ky = F_0\\cos{(\\gamma t)}\r\n\\end{equation*}\r\nWe can use the method of undetermined coefficients to solve this system.\\\\\r\n\r\n\\noindent\r\nExtracting the coefficients for the auxiliary equation and finding the roots,\r\n\\begin{equation*}\r\n\tmr^2 + k = 0 \\implies r = \\pm i\\sqrt{\\frac{k}{m}} = i\\omega\r\n\\end{equation*}\r\nSo, our homogeneous solution is\r\n\\begin{equation*}\r\n\ty_h = C_1\\cos{(\\omega t)} + C_2\\sin{(\\omega t)}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nFor guessing the form of $y_p$, we'll need to break into two cases depending on if $\\omega = \\gamma$. One case will give rise to beats and the other resonance.\r\n\r\n\\input{./higherOrder/forcedVibrs/beats.tex}\r\n\\input{./higherOrder/forcedVibrs/resonance.tex}", "meta": {"hexsha": "75d7b825f6883959c7b148253195073ae95c4dcf", "size": 811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/forcedVibrs/undampedForcedVibrs.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/undampedForcedVibrs.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/undampedForcedVibrs.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": 35.2608695652, "max_line_length": 160, "alphanum_fraction": 0.7065351418, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6578364729798453}}
{"text": "\\chapter{Nonlinear resonances} \\label{app-A}\n\nThe study of nonlinear resonances is important in many areas of physics \\cite{Reichl1992}. A derivation of the nonlinear resonance condition in Eq.~\\ref{eq:resonance_lines} (in one dimension) is included in this appendix. The derivation follows \\cite{LundLecture1} closely.\n\nWe return to one-dimensional motion and write\n%\n\\begin{equation}\\label{eq:Hill_nonlinear}\n    x'' + k(s) x = \\Delta B,\n\\end{equation}\n%\nwhere $\\Delta B$ represents all the nonlinear terms in the magnetic field expansion (and also linear deviations from the design fields). The stable solution $x_0$ when $\\Delta B = 0$ is given by Eq.~\\eqref{eq:Hill_solution}. We now define\n%\n\\begin{equation}\n    \\phi(s) = \\frac{1}{\\nu} \\oint{\\frac{ds}{\\beta(s)}},\n\\end{equation}\n%\nwhere $\\nu$ is the tune. Moving to the normalized coordinate $u = x / \\sqrt{\\beta}$, with $\\dot{u} = du/d\\phi$ we have\n%\n\\begin{equation}\\label{eq:pert1}\n    \\ddot{u} + \\nu^2 u = -\\nu^2 \\sum_{n=0}^{\\infty}{\\left(\\beta^{\\frac{n+3}{2}} b_{n+1}\\right) u^n}.\n\\end{equation}\n%\n$\\beta$ (the oscillation amplitude of the unperturbed motion) and $b_n$ (a multipole coefficient) are periodic in $\\phi$ since they depend only on the position in the ring. Grouping these terms and Fourier expanding gives\n%\n\\begin{equation}\n    \\ddot{u} + \\nu^2 u = -\\nu^2 \\sum_{n=0}^{\\infty}\\sum_{k=-\\infty}^{\\infty} C_{n,k} \\, u^n \\, e^{ik\\phi}.\n\\end{equation} \n%\nWe then perturb around $u_0$, the solution to the homogeneous equation, writing $u = u_0 + \\delta u$, and keep only linear powers of $\\delta u$. \n%\n\\begin{equation}\n    \\ddot{\\delta u} + \\nu^2 \\delta u \\approx -\\nu^2 \\sum_{n=0}^{\\infty}\\sum_{k=-\\infty}^{\\infty} C_{n,k} \\, u_0^n \\, e^{ik\\phi}.\n\\end{equation}\n%\nNoting that\n%\n\\begin{equation}\n    u_0^n \\propto \\cos^n(\\nu\\phi) = \\frac{1}{2^n}\\sum_{m=0}^{n} \\binom{n}{m} e^{i(n-2m)\\nu\\phi},\n\\end{equation} \n%\nleads to\n%\n\\begin{equation}\\label{eq:pert2}\n    \\ddot{\\delta u} + \\nu^2 \\delta u \\approx -\\nu^2 \\sum_{n=0}^{\\infty}\\sum_{k=-\\infty}^{\\infty} \\sum_{m=0}^{n} {n \\choose m} \\frac{C_{n,k}}{2^n} e^{i\\left[(n - 2m)\\nu + k\\right]\\phi}.\n\\end{equation}\n%\nA resonance condition may occur when any of the frequency components of the driving terms are close to the tune $\\nu$; i.e., when\n%\n\\begin{equation}\n    (n - 2m)\\nu + k = \\pm \\nu.\n\\end{equation}\n%\nDipole terms correspond to integer tunes, quadrupole terms to 1/2 integer tunes, sextupole terms to 1/3 integer tunes, and so on. The same is true in the vertical dimension. The inclusion of coupling between $x$ and $y$ leads to the following resonance conditions:\n%\n\\begin{equation}\\label{eq:resonance_lines1}\n    M_x \\nu_x + M_y \\nu_y = N,\n\\end{equation}\n%\nwhere $M_x$, $M_y$, and $N$ are integers and $|M_x| + |M_y|$ is the order of the resonance. These resonance lines are plotted in Fig.~\\ref{fig:resonance_lines}.\n%\n\\begin{figure}[!p]\n    \\centering\n    \\includegraphics[width=\\textwidth]{Images/chapter1/resonance_lines.png}\n    \\caption{Resonance lines in tune space defined by Eq.~\\eqref{eq:resonance_lines1}.}\n    \\label{fig:resonance_lines}\n\\end{figure}\n%\n\\begin{figure}[!p]\n    \\begin{subfigure}[b]{1.0\\textwidth}\n        \\includegraphics[width=\\textwidth]{Images/chapter1/sextupole.png}\n        \\label{fig:sextupole_a}\n    \\end{subfigure}\n    \\vfill\n    \\vspace*{1.0cm}\n    \\vfill\n    \\begin{subfigure}[b]{\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{Images/chapter1/sextupole_second_order.png}\n        \\label{fig:sextupole_b}\n    \\end{subfigure}\n    \\caption{Third-order (top) and fourth/fifth-order (bottom) resonances excited by a sextupole perturbation to a linear lattice. (Adapted from \\cite{Lee2011}.)}\n    \\label{fig:sextupole}\n\\end{figure}\n%\n\nIt is helpful to visualize the particle trajectory when a resonance line is encountered; therefore, a numerical experiment from \\cite{Lee2011} is reproduced here. We consider a sextupole perturbation in an otherwise linear lattice, modeling the sextupole as a thin-lens kick. The turn-by-turn trajectories of particles with several different initial amplitudes are plotted in the top row of \\ref{fig:sextupole} for different tunes $\\nu_x$. The third-order resonance leads to a well-known triangular region of stability as the tune approaches 2/3. The bottom plot reveals fourth and fifth-order resonances only obtained from second-order perturbation analysis. ", "meta": {"hexsha": "582f988a04d83680c4d43686895e174b7a773d04", "size": 4380, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MainText/appendixA.tex", "max_stars_repo_name": "austin-hoover/dissertation", "max_stars_repo_head_hexsha": "53845b2acfd6da962c19967a98987208988d841e", "max_stars_repo_licenses": ["MIT"], "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/appendixA.tex", "max_issues_repo_name": "austin-hoover/dissertation", "max_issues_repo_head_hexsha": "53845b2acfd6da962c19967a98987208988d841e", "max_issues_repo_licenses": ["MIT"], "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/appendixA.tex", "max_forks_repo_name": "austin-hoover/dissertation", "max_forks_repo_head_hexsha": "53845b2acfd6da962c19967a98987208988d841e", "max_forks_repo_licenses": ["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.9302325581, "max_line_length": 660, "alphanum_fraction": 0.7043378995, "num_tokens": 1422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.6577901515543796}}
{"text": "\\documentclass[11pt]{article}\n\n\n\\usepackage{amsfonts}\n\\usepackage{fancyvrb}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{url}\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 Vehicle Routing}\n\\normalsize\n\n\n\\section{Problem Statement}\n\n\nIn this assignment you will design an algorithm to solve a problem faced by package delivery companies, {\\em The Vehicle Routing Problem (VRP)}.  Every day, a delivery company needs to deliver goods to many different customers.  The deliveries are achieved by dispatching a fleet of vehicles from a centralized storage warehouse.  The goal of this problem is to design a route for each vehicle (similar to traveling salesman tours) so that all of the customers are served by exactly one vehicle and the travel distance of the vehicles is minimized.  Additional problem complexity comes from the fact that the vehicles have a fixed storage capacity and the customers have different demands.  Figure \\ref{fig:vrp} illustrates a small VRP and a feasible solution to that problem.  The customers are labeled from $0$ to $4$, with $0$ being the warehouse.  The solution uses two vehicles which are indicated by different colored routes.\n\n\n\\begin{figure}[h]\n        \\centering\n        \\begin{subfigure}[b]{8.0cm}%{0.3\\textwidth}\n                \\centering\n                \\includegraphics[width=6cm]{figures/vrp_1.pdf}\n                \\caption{The VRP input data.}\n                \\label{fig:vrp: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        \\hfill\n        \\begin{subfigure}[b]{8.0cm}\n                \\centering\n                \\includegraphics[width=6cm]{figures/vrp_2.pdf}\n                \\caption{A solution to the VRP using 2 vehicles.}\n                \\label{fig:vrp:sol}\n        \\end{subfigure}\n        \\caption{A Vehicle Routing Example}\\label{fig:vrp}\n\\end{figure}\n\n\\section{Assignment}\n\nWrite an algorithm to solve the vehicle routing problem.  The problem is mathematically formulated in the following way:  We are given a list of locations $N = 0 \\ldots n-1$.  By convention, location 0 is the warehouse location, where all of the vehicles start and end their routes.  The remaining locations are customers.  Each location is characterized by three values  $\\langle d_i,x_i,y_i \\rangle \\; i \\in N$ a demand $d_i$ and a point $x_i,y_i$.  The fleet of vehicles $V = 0 \\ldots v-1$ is fixed and each vehicle has a limited capacity $c$.  All of the demands assigned to a vehicle cannot exceed its capacity $c$.  For each vehicle $i \\in V$, let $T_i$ be the sequence of customer deliveries made by that vehicle and let ${\\it dist}(c_1,c_2)$ be the Euclidean distance between two customers.\\footnote{${\\it dist}(j,k) = \\sqrt{(x_{j} - x_{k})^2 + (y_{j} - y_{k})^2}$}  Then the vehicle routing problem is formalized as the following optimization problem,\n$$\n\\begin{array}{ll}\n\\mbox{minimize:} & \\displaystyle \\sum_{i \\in V} \\left( dist(0, T_{i,0}) + \\sum_{\\langle j,k \\rangle \\in T_{i}} dist(j, k) + dist(T_{i,|T_i|-1}, 0) \\right)\\\\\n\\mbox{subject to:} & \\\\\n     & \\displaystyle \\sum_{j \\in T_{i}} d_j \\leq c \\;\\;\\; (i \\in V) \\\\\n     & \\displaystyle \\sum_{i \\in V}  (j \\in T_{i}) = 1 \\;\\;\\; (j \\in N \\setminus 0) \n\\end{array}\n$$\nIn this variant of the vehicle routing problem, we assume the vehicles can travel in straight lines between each pair of locations.\n\n\\section{Data Format Specification}\n\nThe input consists of $|N| + 1$ lines.  The first line contains 3 numbers: The number of customers $|N|$, the number of vehicles $|V|$, and the vehicle capacity $c$.\nIt is followed by $|N|$ lines, each line represents a location triple $\\langle d_i,x_i, y_i \\rangle$, with a demand $d_i \\in \\mathbb{N}$ and a point  $x_i, y_j \\in \\mathbb{R}$.\n\n\\vspace{0.2cm}\n\\noindent\nInput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n|N| |V| c\nd_0 x_0 y_0\nd_1 x_1 y_1\n...\nd_|N|-1 x_|N|-1 y_|N|-1\n\\end{Verbatim}\n%\nThe output has $|V|+1$ lines.  The first line contains two values $obj$ and $opt$.  $obj$ is the length of all of the vehicle routes (i.e. the objective value) as a real number.  $opt$ should be $1$ if your algorithm proved optimality and $0$ otherwise.  The following $|V|$ lines represent the vehicle routes $T$ encoding the solution.  Each vehicle line starts with warehouse identifier $0$ followed by the identifiers of the customers serviced by that vehicle and ends with the warehouse identifier $0$.  Each vehicle line can contain between $2$ and $|N|+2$ values depending on how many customers that vehicle services.  Each customer identifier must appear in one of these vehicle lines.\n\n\\vspace{0.2cm}\n\\noindent\nOutput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\nobj opt\n0 t_0_1 t_0_2 ... 0 \n0 t_1_1 t_1_2 ... 0 \n...\n0 t_|V|-1_1 t_|V|-1_2 ... 0\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} \\mbox{}\n%\\vspace{0.1cm}\n\\noindent\n(based on Figure \\ref{fig:vrp})\n\n\\vspace{0.2cm}\n\\noindent\nInput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n5 4 10\n0 0 0\n3 0 10\n3 -10 10\n3 0 -10\n3 10 -10\n\\end{Verbatim}\n\n\\vspace{0.2cm}\n\\noindent\nOutput Example 1\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n80.6 0\n0 1 2 3 0 \n0 4 0\n0 0\n0 0\n\\end{Verbatim}\n%\nThis output represents the following routes for each vehicle.  Vehicle 0 - $\\{0 \\rightarrow 1, 1 \\rightarrow 2, 2 \\rightarrow 3, 3 \\rightarrow 0\\}$;  Vehicle 1 - $\\{0 \\rightarrow 4, 4 \\rightarrow 0\\}$; Vehicle 2 - $\\{0 \\rightarrow 0\\}$; Vehicle 3 - $\\{0 \\rightarrow 0\\}$.  Note the following equivalent solution using the same routes with different vehicles.  \n\n\\vspace{0.2cm}\n\\noindent\nOutput Example 2\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n80.6 0\n0 4 0\n0 0\n0 1 2 3 0 \n0 0\n\\end{Verbatim}\n\n\\section{Instructions}\n\n\\input{instructions.tex}\n\n%We use \\texttt{stdout} for output.\n%Output to other stream will be ignored (you may want to send runtime information to \\texttt{stderr}). Your submission will be tested on a department linux machine. If your algorithm is a standalone program, please name it \\texttt{nr},\n%otherwise, please specify the compilation procedure,\n%it is appreciated if you also provide a script that follows the above format to run the program.\n\n\\paragraph{Resources}\nYou will find several vehicle routing 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": "a35f96a3c2f72e1fbb6c838f71f97faa8ef30893", "size": 7212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/vrp.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/vrp.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/vrp.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": 38.9837837838, "max_line_length": 960, "alphanum_fraction": 0.7131170272, "num_tokens": 2170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.6577901510950116}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb,amsfonts}\n\\usepackage{enumitem}\n\\usepackage{tabu}\n\\usepackage{xcolor}\n\\usepackage{mathtools}\n\\usepackage{tcolorbox} \n\\usepackage{changepage} \n\\usepackage{kpfonts}\n\\usepackage{picture}\n\\usepackage{venndiagram}\n\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\begin{document}\n\\section*{CHAPTER 7}\n\n\\noindent\n\\textbf{Problem 3:} Consider a card game, using the standard $52$-card deck, in which each of four players is dealt thirteen cards. Compute the probabilities that a specific player: $(a)$ has no clubs; $(b)$ has exactly ten clubs; $(c)$ has at least three of four aces.\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 4:} (Cont.) In the same card game, what is the probability that each player is dealt a jack?\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 9:} Recall that there are U.S. senators (two from each state).\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item If two senators are chosen at random, what is the probability that they are from the same state?\n\\item If the $100$ senators are organized into disjoint sets of two, what is the probability that, in each set, the two senators are from the same state?\n\\item In a committee of ten senators, what is the probability that no two are from the same state? (Assume that there are no restrictions on committee memberships)\n\\end{enumerate}\n\n\\vspace*{3cm}\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 8}\n\n\\noindent\n\\textbf{Problem 3:} Compute the probability that, in a sample of $10$ people in the population at large, $2$ have their birthdays in May or June, $3$ have their birthdays in December or January, and the $5$  remaining ones have their birthdays during the rest of the year. (Just give the formula. Also, you may assume for simplicity that all the months have the same number of days.)\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 4:} Two fair dice are thrown repeatedly until for the first time their sum exceeds $4$. What is the distribution of the trial number of that event?\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 5:} Check the accuracy of the approximation of the binomial distribution with parameters $50$ and $\\frac{1}{50}$ by the Poisson distribution with parameter $1$. Compute both distributions for the values $0$, $1$, $3$, and $5$.\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 8:} In a particular ESP (extrasensory perception) experiment, an experimenter looks at one of five cards on each trial, and the subject is to guess at which card the experimenter is looking. Assuming that the subject does not have ESP, what is the distribution of the outcome (successful guess, unsuccessful guess) of a trial?\n\n\\vspace*{5cm}\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\section*{CHAPTER 9}\n\n\\noindent\n\\textbf{Problem 1:} Archie has three coins in his pocket: a standard coin, a coin with heads on both sides, and a coin with tails on both sides. He pulls one coin out of his pocket, looks at one side of the coin, and notices that it is a tail. He reasons that the probability of seeing a head on the other side of this coin is $\\frac{1}{2}$. Do you agree with his reasoning?\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 2:} Let $a$, $b$, and $c$ be outcomes in some finite sample space $\\Omega$ having $2^{\\Omega}$ as a field of events, with some probability measure $\\mathbb{P}$. You are told that $\\mathbb{P}(\\{ a,b \\} \\lvert \\{ b,c \\}) = \\alpha$ and that $\\mathbb{P}(\\{ c \\}) = \\beta$.\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item Compute $\\mathbb{P}(\\{ b \\})$ in terms of $\\alpha$ and $\\beta$.\n\\item Give some possible values for $\\alpha$ and $\\beta$.\n\\item Find constraints on $\\alpha$ and $\\beta$, that is, find a general expression constraining the possible values of $\\alpha$ and $\\beta$.\n\\item Find an expression constraining the possible values of $\\mathbb{P}(\\{ a \\})$.\n\\end{enumerate}\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 8:} Consider, in some ethnic group, the set of all families having two children. Let us assume that, for such families, the probability of having a boy is $.5$. Take one family at random and suppose that one of their children is a boy. What is the probability that the other child is also a boy?\n\n\\vspace*{5cm}\n\n\\noindent\n\\textbf{Problem 12:} An astronomer has detected punctual signals from an unknown source in the sky. The signals are of two kinds, which she denotes `$A$' and `$B$.' She assumes that the occurrence of the signals is governed by a random process, namely, that the number of signals of any kind received in the course of one hour has a Poisson distribution with parameter $\\lambda$. When a signal occurs, it is an `$A$' signal with probability $\\theta$ and a `$B$' signal with probability $1-\\theta$. Write a formula for the distribution of `$A$'  signals received in one hour.\n\n\\vspace*{5cm}\n\n\\end{document} ", "meta": {"hexsha": "07c3146077a1b653161cf6f88ad75862d81689d3", "size": 5320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability-theory/exam-review/exam-1/EXAM_1_REVIEW.tex", "max_stars_repo_name": "jShiohaha/math-classes", "max_stars_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "probability-theory/exam-review/exam-1/EXAM_1_REVIEW.tex", "max_issues_repo_name": "jShiohaha/math-classes", "max_issues_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "probability-theory/exam-review/exam-1/EXAM_1_REVIEW.tex", "max_forks_repo_name": "jShiohaha/math-classes", "max_forks_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.8453608247, "max_line_length": 574, "alphanum_fraction": 0.6680451128, "num_tokens": 1336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085758631159, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.6577901452946485}}
{"text": "\\documentclass[a4paper, draft]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[australian]{babel}\n\\usepackage{mathtools}\n\\title{Preliminary 3 Unit Notes}\n\\author{Curly Macadam}\n\\date{}\n\\begin{document}\n\\maketitle\n\\section{Algebra}\n\\subsection{Index laws}\n\\begin{enumerate}\n\\item \\(a^m \\times a^n = a^{m+n}\\)\n\\item \\(a^m \\div a^n = a^{m-n}\\)\n\\item \\((a^m)^n = a^{mn}\\)\n\\item \\((ab)^n = a^{n}b^{n}\\)\n\\item \\(\\left(\\dfrac{a}{b}\\right)^n = \\dfrac{a^n}{b^n}\\)\n\\item \\(a^0 = 1\\)\n\\item \\(a^{-n} = \\dfrac{1}{x^n}\\)\n\\item \\(a^{\\frac{1}{n}} = \\sqrt[n]{a}\\)\n\\end{enumerate}\n\\subsection{Binomial Products}\n\\[\\begin{align*}\n(a+b)(x+y) &= ax + ay + bx + by \\\\\n(a+b)(a-b) &= a^2 - b^2 \\\\\n(a+b)^2 &= a^2 + 2ab + b^2 \\\\\n(a-b)^2 &= a^2 - 2ab + b^2\n\\end{align*}\\]\n\\subsection{Factorising}\n\\[\\begin{align*}\nx^2 + (a+b) + ab &= (x+a)(x+b) \\\\\na^3 + b^3 &= (a+b)(a^2 - ab + b^2) \\\\\na^3 - b^3 &= (a-b)(a^2 + ab + b^2)\n\\end{align*}\n\\]\n\\end{document}\n", "meta": {"hexsha": "7f7e201918bbcf6a62b1e0b067683ed506e6f41f", "size": 926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prelim3unit/prelimnotes3unit.tex", "max_stars_repo_name": "megaminxwin/curly-maths-notes", "max_stars_repo_head_hexsha": "d1308386bc2548ca0476df34f6db2cc5e5548d2f", "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": "prelim3unit/prelimnotes3unit.tex", "max_issues_repo_name": "megaminxwin/curly-maths-notes", "max_issues_repo_head_hexsha": "d1308386bc2548ca0476df34f6db2cc5e5548d2f", "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": "prelim3unit/prelimnotes3unit.tex", "max_forks_repo_name": "megaminxwin/curly-maths-notes", "max_forks_repo_head_hexsha": "d1308386bc2548ca0476df34f6db2cc5e5548d2f", "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.027027027, "max_line_length": 56, "alphanum_fraction": 0.555075594, "num_tokens": 411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.6577901447819007}}
{"text": "\\title{CFD laboratory 1\\\\Laminar flow development between two parallel plates}\n\\author{\n        Sergio M. Vanegas A.\\\\\n        Francesco de Pas\\\\\n                Department of Mathematics\\\\\n        Polimi---Politecnico di Milano\\\\\n        Milano, Italia\n}\n\\date{\\today}\n\n\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\n\\begin{document}\n\\maketitle\n\n\\begin{abstract} \n        The first test case is the steady-state development of incompressible flow between two parallel plates in the laminar regime (Figure~\\\\\\ref{fig:sketch}). The plates are considered infinite in the direction transversal to the flow. The flow develops from a condition of uniform velocity (rectangular profile) imposed at the inlet boundary, reaching a fully-developed state at a certain distance downstream of it. \\cite{FL:01}\n\\end{abstract}\n\n\\section{Introduction}\n        The fully developed laminar flow between two parallel plates admits an analytical solution (plane Poiseuille flow):\n\n        \\begin{equation} \\label{eq:system}\n                \\begin{cases}\n                        u(x,y,z) = u(y) = - \\frac{\\delta ^ 2}{2 \\mu} \\frac{dp_e}{dx} \\frac{y}{\\delta} (2 - \\frac{y}{\\delta}) \\; v(x,y,z) = 0 \\; w(x,y,z) = 0 \\\\\n                        \\frac{dp_e}{dx} = const < 0 \\\\\n                        \\tau_{yx}(x,y,z) = - 2 \\mu \\frac{1}{2} \\left( \\frac{\\partial u}{\\partial y} + \\frac{\\partial v}{\\partial x} \\right) = - \\mu \\frac{du}{dy} = \\frac{dp_e}{dx} (\\delta - y) = \\tau_{yx}(y)\n                \\end{cases}\n        \\end{equation}\n\n        Where \\( \\mu \\) is the dynamic viscosity of the fluid, \\( \\delta \\) is the half-distance between the plates, \\(u, v, w\\) are the velocity components along directions \\( x, y, z \\) (Figure~\\ref{fig:sketch}), \\( p_e \\) is the excess pressure with respect to the hydrostatic component, and \\( \\tau_{yx} \\) is the only nonzero shear stress. \\cite{FL:01}\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Case_Sketch.png}\n                \\centering\n                \\caption{Sketch of the Case}\n                \\label{fig:sketch}\n        \\end{figure}\n\n        The configuration of the problem is as follows:\n        \\begin{itemize}\n                \\item Length \\( L = 10 \\: cm \\),\n                \\item Length \\( L_p = 9 \\: cm \\),\n                \\item Half-channel height \\(\\delta = 5 \\: mm\\),\n                \\item Bulk velocity \\( U_b = 5 \\: mm/s \\),\n                \\item Fluid: Water at \\( 20^{\\circ}C \\; ( \\rho = 998.23 \\: kg/m^3\\), \\\\ Kinematic Viscosity \\( \\nu = 1.006E-6 \\: m^2/s ) \\).\n        \\end{itemize}\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Conditions.png}\n                \\centering\n                \\caption{Domain and boundary conditions}\n                \\label{fig:conditions}\n        \\end{figure}\n\n        \\paragraph{Outline}\n        The remainder of the report is organized as follows: Section~\\ref{sec:developed_flow} provides some gross estimate of the required \\( L_p \\) to achieve a fully-developed flow in terms of channel height; Section~\\ref{sec:independence} shows how a suitable configuration of the cartesian computational mesh was found; Section~\\ref{sec:CFD_validation} compares the simulated solution with the analytical model both graphically and numerically; Finally, Section~\\ref{sec:vorticity} provides some analysis regarding the vorticity profile on both the developing and fully-developed region. It is worth noting that all simulations had a relative convergence tolerance of $ 1E-3 $ for all variables taken into consideration.\n\n\\section{Fully-developed flow conditions} \\label{sec:developed_flow}\n\n        The following plot was generated from a half-domain simulation with a 40-by-40 mesh, in a $ 12 \\: cm $ long domain with a $ 2 \\: cm $ margin, as per the lab document's recommendation. The observed profile was taken in\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Fully_Developed_Francesco.png}\n                \\centering\n                \\caption{X-velocity Y-profile per delta-step}\n                \\label{fig:delta-steps}\n        \\end{figure}\n\n        As we can see in Figure~\\ref{fig:delta-steps}, the X-velocity Y-Profile stabilizes after roughly 4 deltas ($ 2 \\: cm $), making our choice of an 18-delta channel with a 2-delta margin at the beginning ($ 10 \\: cm $ total) more than enough for the case of study. From now on, unless said otherwise, all X-specific data was taken after 12 deltas into the actual channel ($ 7 \\: cm $ from the origin of the X-axis), simulating the whole channel as opposed to just the lower half and using a \\( 10 \\: cm \\) domain with a \\( 1 \\: cm \\) margin in its stead.\n\n\\section{Grid independence study} \\label{sec:independence}\n\n        The following Grid-Independence study was performed by fixing 40 cells either along the X or Y axis, and then progressively increasing the amount of cells on the other axis until both X-velocity profile and Pressure-gradient convergence was observed.\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Grid_Ind_U_Profiles.png}\n                \\centering\n                \\caption{X-velocity derivative Y-profile per cell amount}\n                \\label{fig:grid_ind_u}\n        \\end{figure}\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Grid_Ind_P_Gradient.png}\n                \\centering\n                \\caption{P-gradient vs cell amount}\n                \\label{fig:grid_ind_p}\n        \\end{figure}\n\n        As we can observe in Figure~\\ref{fig:grid_ind_u}, X-refinement is pretty much irrelevant for the X-velocity derivative profile; nevertheless, such is not the case for the Pressure-gradient which, as we can see in Figure~\\ref{fig:grid_ind_p}, did not stabilize after at least 35 cells across the X-axis.\n\n        In the case of Y-refinement, 25 cells were enough to stabilize both the X-velocity derivative profile and average Pressure-gradient. Therefore, a 40-by-40 mesh kept being used for the remainder of the laboratory, since simulation times were low enough for a wide Y-refinement margin to not be a problem.\n\n\\section{CFD solution validation} \\label{sec:CFD_validation}\n\n        From Equation System~\\ref{eq:system} and Equation~\\ref{eq:bulk_speed} (which describes Bulk velocity as a function of the Pressure-gradient magnitude), we derive the expressions in Equation System~\\ref{eq:analytical}.\n\n        \\begin{equation} \\label{eq:bulk_speed}\n                U_b = - \\frac{1}{3 \\mu} \\frac{dp_e}{dx} \\delta ^ 2 \n        \\end{equation}\n\n        \\begin{equation} \\label{eq:analytical}\n                \\begin{cases}\n                        \\frac{dp_e}{dx} = - \\frac{3 \\mu}{\\delta ^ 2} U_b \\\\\n                        u(y) = - \\frac{\\delta}{2 \\mu} \\frac{dp_e}{dx} y (2 - \\frac{y}{\\delta})\n                \\end{cases}\n        \\end{equation}\n\n        In order to objectively measure the simulation error with respect to the analytical solution, we use the expressions in Equation System~\\ref{eq:errors}. It is worth noting that the velocities inside the $ L^2 $-norm and $ L^{\\infty} $-norm were evaluated for a fixed value of x inside the fully-developed region.\n\n        \\begin{equation} \\label{eq:errors}\n                \\begin{cases}\n                        \\frac{dp}{dx}_{err} = \\frac{\\left| \\frac{dp_e}{dx} - \\frac{dp_e}{dx}_{sim} \\right|}{\\left| \\frac{dp_e}{dx} \\right|} \\\\\n                        u_{err, L^2} = \\frac{\\left| \\left| \\frac{u - u_{sim}}{u} \\right| \\right|_{L ^ 2}}{\\sqrt{2 \\delta}} = \\sqrt{\\frac{\\int_{0}^{2 \\delta} \\left| \\frac{u(y) - u_{sim}(y)}{u(y)} \\right|^2 dy}{2 \\delta}} \\\\\n                        u_{err, L^{\\infty}} = \\left| \\left| \\frac{u - u_{sim}}{u} \\right| \\right|_{L ^ \\infty} = \\sup_{y \\in [0, 2 \\delta]} \\left| \\frac{u(y) - u_{sim}(y)}{u(y)} \\right|\n                \\end{cases}\n        \\end{equation}\n\n        The results were the following:\n\n        \\begin{itemize}\n                \\item Pressure-gradient relative error: \\( 5.807746E-03 \\).\n                \\item X-velocity relative Root-Mean-Squared error: \\( 5.288724e-03 \\).\n                \\item X-velocity relative Maximum error: \\( 2.613112e-02 \\).\n        \\end{itemize}\n\n        Aditionally, as we can observe in Figure~\\ref{fig:u_comparison} and Figure~\\ref{fig:tau_comparison}, the profiles for both X-velocity and Shear-stress were coherent with the analytical model.\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{U_Profile_Comparison.png}\n                \\centering\n                \\caption{X-velocity profile comparison at \\(x = 0.07 \\: m \\)}\n                \\label{fig:u_comparison}\n        \\end{figure}\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Tau_Profile_Comparison.png}\n                \\centering\n                \\caption{Shear-stress profile comparison at \\(x = 0.07 \\: m \\)}\n                \\label{fig:tau_comparison}\n        \\end{figure}\n\n\\section{Vorticity} \\label{sec:vorticity}\n\n        Using data from the original simulation (for visualization purposes) and a 100-by-40 mesh, we plotted vorticity across all channel regions and obtained Figure~\\ref{fig:vorticity} as a result.\n\n        \\begin{figure}[!ht]\n                \\includegraphics[width=\\textwidth]{Vorticity_Profile_Francesco.png}\n                \\centering\n                \\caption{Vorticity surface-profile}\n                \\label{fig:vorticity}\n        \\end{figure}\n\n        The main two differences between the developing and fully-developed regions are:\n\n        \\begin{itemize}\n                \\item Peak vorticity magnitude is higher on the developing region.\n                \\item The vorticity profile is completely linear on the fully-developed region, whereas it presents variable slope on the developing one.\n        \\end{itemize}\n\n\\bibliographystyle{abbrv}\n\\bibliography{main}\n\n\\end{document}\n", "meta": {"hexsha": "0298a0c85f9d25172d360e1711cef4cd881dd655", "size": 9895, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Fluids_Labs/Lab_1/main.tex", "max_stars_repo_name": "sergiovaneg/LaTex_Documents", "max_stars_repo_head_hexsha": "22daa8196b611089e6753e600c39922c55522d9b", "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": "Fluids_Labs/Lab_1/main.tex", "max_issues_repo_name": "sergiovaneg/LaTex_Documents", "max_issues_repo_head_hexsha": "22daa8196b611089e6753e600c39922c55522d9b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fluids_Labs/Lab_1/main.tex", "max_forks_repo_name": "sergiovaneg/LaTex_Documents", "max_forks_repo_head_hexsha": "22daa8196b611089e6753e600c39922c55522d9b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-21T14:26:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T14:26:02.000Z", "avg_line_length": 58.8988095238, "max_line_length": 724, "alphanum_fraction": 0.6324406266, "num_tokens": 2594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.6577901431368985}}
{"text": "\\lab{Applications}{Norms and Geometry}{Norms and Geometry}\n\\objective{Build intuition about the geometries associated with different norms and metric spaces.}\n\n{\\bf Outline}\n\\begin{itemize}\n\\item Review $\\ell^p$ norms. Talk about how each is equivalent, but yields different notions of geometry.\n\\item Talk about different matrix norms. Talk about the right way to calculate them as well.\n\\end{itemize}\n\\begin{problem}\nWrite a function plotting unit ball in different norms.\n\\end{problem}\n\n\n\n\\begin{problem}\nWrite a function that transforms some star-shaped object into its equivalent object in other norms. What is the star of david in the infinity norm? (or something like that)\n\\end{problem}\n\n\\section*{Condition Number}\n\nLet $A$ be an invertible $n \\times n $ matrix, and consider the system $Ax = b$. Even though $A$ is invertible, we may not be able to compute $x$ exactly.  Maybe $A$ cannot be represented exactly in floating point numbers. Or we may not know $A$ exactly. And even if we can represent $A$ exactly, small roundoff errors can occur in the process of solving the system. Thus, when we solve $Ax-b$ we obtain a solution $x'$ which may be not equivalent to the true solution $x$. Unfortunately, even if $Ax'$ is very close to $b$, $x'$ may not be close to $x$. \n\nThe residual of $x'$ is defined $r = \\norm{Ax'-b}$ and the relative residual is $\\frac{\\norm{r}}{\\norm{b}}$. However, we are interested in the relative error of $x'$ which is defined $\\frac{\\norm{e}}{\\norm{x}}$ where $e$ is the error $x-x'$. It is the error, not the residual, which measures how close our imperfect $x'$ is to the true solution $x$. \n\nFortunately, these two quantities can be related. If we choose a vector norm $\\norm{\\cdot} _v$ and a matrix norm $\\norm{\\cdot} _M$ such that \n\n\\begin{equation} \\label{eq:normcondition}\n\\norm{Ax}_v \\leq \\norm{A}_M\\norm{x}_v \\quad \\forall x \\in  \\mathbb{F}^n, A \\in \\mathbb{F}^{n \\times n}\n\\end{equation}\nthen it can be shown that \n\\begin{equation*}\n\\frac{1}{\\norm{A} \\norm{A^{-1}}} \\frac{\\norm{r}}{\\norm{b}} \\leq \\frac{\\norm{e}}{\\norm{A}} \\leq \\norm{A} \\norm{A^{-1}} \\frac{\\norm{r}}{\\norm{b}}\n\\end{equation*}\n\nThe number $\\norm{A} \\norm{A^{-1}} = \\kappa (A)$ is called the \\emph{condition number} of $A$. If $\\kappa (A)$ is small, then $A$ is well=conditioned, and the relative error is close to the relative residual. If $\\kappa (A)$ is large, then $A$ is ill-conditioned, and the relative error may be many times larger than the relative residual. Also, if $A$ is ill-conditioned, then small changes in the entries of $A$ can result in large changes in the solutions to $Ax = b$. \n\n\\begin{problem}\nLet $A =\\begin{pmatrix}1 & 3\\\\2 & 5.999\\end{pmatrix}$ and $b = \\begin{pmatrix}5\\\\9.999\\end{pmatrix}$. Calculate the condition number of $A$. Now test the sensitivity of the system $Ax = b$ to small changes in $b$. What do you find?\n\\end{problem}\n", "meta": {"hexsha": "03284c875e063facb8dfa6c63495c88853fa7f4f", "size": 2879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/NormsGeometry/Norms_Geometry.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/NormsGeometry/Norms_Geometry.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/NormsGeometry/Norms_Geometry.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": 71.975, "max_line_length": 555, "alphanum_fraction": 0.7141368531, "num_tokens": 843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.6577901383620306}}
{"text": "\\graphicspath{ {./img/TheFEM/} }\n\\chapter{Quadratures: numerical integration}\n\n\\section*{Preliminary}\n\nThe formulation of finite element algorithms is strongly based on the weak formulation of the boundary value problems. In loose terms, in typical finite element algorithms the boundary value problem originally written as a set of governing differential equations and properly specified boundary conditions, is re-formulated in the form of integral representations. For instance, this is the case in the boundary value problem of linearized theory of elasticity where the differential equations (corresponding to the equilibrium of a material point) and the tractions (and/or displacement) boundary conditions are shown to be equivalent to the the integral form representation of the principle of virtual displacements. In this case a finite element algorithm results from the discretization through interpolation schemes of the integrand appearing in the principle. However to generate an efficient method, valid over arbitrary domains it is necessary to implement effective numerical integration algorithms. To illustrate the need for numerical integration in the formulation of finite element methods consider a typical term resulting from the discretization of the internal virtual energy in the principle of virtual displacements such as the stiffness matrix given by: \n\n\n\n\\begin{equation}\nK^{QP} = \\int_VH_{ij}^QC_{ijkl}H_{kl}^P\\operatorname dV.\n\\label{sample integral 1}\n\\end{equation}\n\nThe accurate computation of these integrals is important to the formulation of the finite element algorithm. \n\nNote that the integration given by \\eqref{sample integral 1} is conducted over a domain $V$ which is typically a finite element of arbitrary shape (e.g., a distorted quadrilateral element) therefore difficulting the computation of $K^{QP}$. This chapter discusses the most relevant details required in the numerical computation of integrals like the one appearing in \\eqref{sample integral 1} which are typical in finite element algorithms. In the first part of the chapter we define a general formula for numerical integration. For completeness we derive integration formulas based on Lagrange interpolation although emphasis will be placed on the more efficient Gaussian integration formulas.\n\nAt the end of this chapter\\footnote{{\\bf This chapter, together with theoretical and computational learning activities is complemented by Jupyter Notebooks 5 and 6 available at the course REPO. Notebook 5 covers numerical integration as used in the finite element method, while notebook 6 combines interpolation theory with numerical integration in the calculation of the stiffness matrix for a finite element.}} the student should be able to:\n\n\n\\begin{itemize}\n\\item[•] Recognize the difference between explicit and numerical computation of integrals.\n\\item[•] Recognize the advantages and disadvantages of different numerical integration schemes.\n\\item[•] Propose integration schemes for specific finite elements.\n\\item[•] Implement efficient Python subroutines required in the integration of functions over specific finite elements.\n\\end{itemize}  \n\n\n\n\\section{Statement of the problem}\n\n\\begin{tcolorbox}\n\\paragraph*{A note on notation:}\nRecall that in our indicial notation we are using subscripts to refer to the scalar components of a vector or a tensor function, while superscripts are reserved to represent elements of the interpolating polynomial. Thus for scalar components of a vector we use:\n\n\\[V_i\\equiv\\begin{bmatrix}V_x&V_y&V_z\\end{bmatrix}.\\]\n\nFor interpolation of a scalar function we use:\n\n\\[p(x)=L^Q(x)f^Q.\\]\n\nAnd for interpolation of a vector function we use:\n\n\\[u_i(x)=L_i^Q(x)u^Q\\]\n\n\\end{tcolorbox}\n\nIn the most general case we are interested in numerically computing integrals of the general form\n\n\n\\begin{equation}\nI\\;=\\iiint f(x,y,z)dV\n\\label{sample integral 2}\n\\end{equation}\n\nwhere the triple integral represents an integration over a given volume. As in the case of interpolation theory, the problem of integration can also be solved from the fundamental problem of integrating a one-dimensional function like\n\n\\begin{equation}\n\\int\\limits_a^b {f(x)dx}  \\approx \\sum\\limits_{I = 1}^N {{w^I}} f({x^I}).\n\\label{quadra}\n\\end{equation}\n\n\n\n\n\nIn this fundamental one-dimensional problem the integral of a function $f(x)$ from $x = a$ to $x= b$ is approximated by a weighted summation of the values of the function at a set of $N$-points. In \\eqref{quadra} $w^I$ represents a weighting factor associated to the value of the function $f({x^I})$ at the point $I$. \n\n\n\nThis numerical approximation of the integral in terms of a weighted summation is called a quadrature formula and the derivation of a specific quadrature corresponds to prescribing the required number of points $N$, the corresponding weighting factors and the location of the $N$ sampling or integration points.\n\n\\paragraph*{Example}\nUsing the following set of quadrature points and weighting factors\n\n\\begin{center}\n\\begin{tabular}{cc}\n  \\hline\n  $x^I$ & $w^I$ \\\\\n  \\hline\n  $-0.86113$  & $0.34785$  \\\\\n  $-0.33998$  & $0.65214$  \\\\\n  $ +0.33998$  & $0.65214$  \\\\\n  $ +0.86113$  & $0.34785$  \\\\\n  \\hline\n\\end{tabular}\n%\\captionof{table}{Definition of integration points and weighting factors for a numerical integration of the type $\\int\\limits_{ - 1}^{ + 1} {f(x)dx}$}\n\\label{ejemplo}\n\\end{center}\n\nevaluate the integral\n\n\n\\begin{equation}\nI = \\int\\limits_{ - 1}^{ + 1} {({x^3} + 4{x^2} - 10)dx}.\n \\label{eqeje}\n\\end{equation} \n\n\nThe numerical evaluation of the integral in \\eqref{eqeje} just reduces to the computation of the following weighted summation:\n\n\\begin{align*}\n\\int\\limits_{ - 1}^{ + 1} {({x^3} + 4{x^2} - 10)dx} \\approx 0.34785 \\cdot f( - 0.86113) + 0.65214 \\cdot f( - 0.33998) \\\\\n + 0.34785 \\cdot f(0.86113) + 0.65214 \\cdot f(0.33998) = -17.3333\n\\end{align*}\n\n\n\\section{Numerical integration using interpolation polynomials}\nA simple quadrature formula can be easily obtained if one represents the actual function $f(x)$ through a Lagrange based interpolation polynomial $p(x)$:\n\n\n\\begin{equation}\n\\int\\limits_a^b {f(x)dx \\approx \\int\\limits_a^b {p(x)dx} } .\n \\label{polybased}\n\\end{equation} \n\nwhere\n\n\n\\begin{equation}\np(x) = {L^I}(x)f({x^I})\n \\label{Lagracof}\n\\end{equation} \n\n\nand ${L^I}(x)$ is the Lagrange interpolation polynomial associated to point $x^I$.\n\nSubstituting \\cref{Lagracof} in \\cref{polybased} yields\n\n\n\\[\\int\\limits_a^b f(x)\\ dx  \\approx \\int\\limits_a^b L^I(x)f(x^I)dx  \\equiv f(x^I)\\int\\limits_a^b L^I(x)dx\\, \\]\n\nwhich can be written like\n\n\\begin{equation}\n\\int\\limits_a^b {f(x)dx}  \\approx \\sum\\limits_{I = 1}^N w^I f(x^I)\n\\label{general}\n\\end{equation}\n\nafter noticing that\n\n\\begin{equation}\nw^I = \\int\\limits_a^b {L^I(x)\\ dx}. \n\\label{pesos}\n\\end{equation}\n\n\\begin{tcolorbox}\nIntegration schemes are classified in Newton-Cotes and Gaussian quadratures methods. In the first case the range of integration is divided into $N-1$ subintervals of constant size $\\frac{b-a}{N-1}$ while in the second group one searches for the optimum location of the integration points inside the interval in order to obtain maximum accuracy. \n\\end{tcolorbox}\n\n\n\\paragraph*{Example: Extended trapezoidal rule}\nConsider the particular case in which $N=2$ (i.e., 1 integration interval). Clearly, in this case the size of the interval is $h=b-a$ and the interpolating polynomial is given by:\n\n\\[p(x) = {L^1}(x){f^1} + {L^2}(x){f^2} \\equiv {L^1}(x)f(a) + {L^2}(x)f(b)\\]\n\nwith interpolation polynomials corresponding to:\n\n\\[{L^1}(x) = \\frac{{(x - {x^2})}}{{({x^1} - {x^2})}} \\equiv  - \\frac{1}{h}(x - b)\\]\n\n\\[{L^2}(x) = \\frac{{(x - {x^1})}}{{({x^2} - {x^1})}} \\equiv \\frac{1}{h}(x - a).\\]\n\nSubstitution in \\eqref{pesos} yields:\n\n\\[{w^1} =  - \\frac{1}{h}\\int\\limits_a^b {(x - b)dx}  \\equiv \\frac{h}{2}\\]\n\n\\[{w^2} =  + \\frac{1}{h}\\int\\limits_a^b {(x - a)dx}  \\equiv \\frac{h}{2}\\]\n\ngiving the final quadrature\n\n\\[I = {w^1}{f^1} + {w^2}{f^2} \\equiv \\frac{h}{2}\\left[ {f(a) + f(b)} \\right]\\]\n\nor equivalently:\n\n\\begin{equation}\n\\int\\limits_a^b {f(x)dx = h\\left[ {\\frac{1}{2}{f(a)} + \\frac{1}{2}{f(b)}} \\right]}.\n\\label{trapecio}\n\\end{equation}\n\n\\paragraph*{Example: Computation of a definite integral}\nUse the trapezoidal rule to compute the integral\n\n\\[I=\\int\\limits_{ - 1}^{ + 1} {({x^3} + 4{x^2} - 10)dx}.\\]\n\nIn this case h=2.0, therefore:\n\n\\[I = f( - 1) + f( + 1) \\equiv  - 7 - 5 =  - 12\\]\n\n\\paragraph*{Example: Integration over two-dimensional domains.}\n\\Cref{fig:rieman} shows an schematic description of a two-dimensional domain (continuous black line) denoted by $R$. We wish to compute the integral\n\n\n\n\\[I = \\iint\\limits_R {f(x,y)dA}. \\]\n\nTo proceed with the computation, the domain has been divided in $N$ rectagular subdomains (black dashed lines) in such a way that a typical subdomain has dimensions $\\Delta {x_i} \\times \\Delta {y_i}$ as shown in the auxiliary figure.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{img/rieman.pdf}\n\\caption{Riemman partition for a two-dimensional domain.}\n\\label{fig:rieman}\n\\end{figure}\n\nDefining\n\n\\[\\left| p \\right| = \\max \\left| {\\Delta {x_i}} \\right| \\vee \\max \\left| {\\Delta {y_i}} \\right|\\]\n\nas the norm of the partition, we have, according to the definition of an integral as a Riemman sum that:\n\n\n\\[I = \\iint\\limits_R {f(x,y)dA}  \\equiv \\mathop {\\lim }\\limits_{\\left| p \\right| \\to 0} \\sum\\limits_{j = 1}^N {f({x_j},{y_j})\\Delta {x_j}} \\Delta {y_j}.\\]\n\n\nTaking each one of the limits independently allows to identify 2 integration process such that the integral over $R$ reduces to the double integral given by:\n\n\\[I = \\int {\\int {f(x,y)dxdy} }. \\]\n\nTo identify the integration limits consider \\cref{fig:dirx} showing a rectangular integration domain with largest side parallel to the $x$ direction and with mid height corresponding to a $y$ constant value. The small sides of the rectangle have abscissas ${x_1}(y)$ and ${x_2}(y)$ respectively.\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{img/dirx.pdf}\n\\caption{Integration along the $x$ direction.}\n\\label{fig:dirx}\n\\end{figure}\n\nConsidering once again the definition of an integral as the limit of a Riemman sum we then have that for constant $y$ values the contribution to the integral over region $R$ of the rectangle bounded by ${x_1}(y)$ and ${x_2}(y)$ is given by:\n\n\n\n\\[\\int\\limits_{{x_1}(y)}^{{x_2}(y)} {f(x,y)dx}\\]\n\nin such a way that the computation of the integral over the full region $R$ is completed after repeating the process for constant values of $y$ varying between $y_1$ and $y_2$ giving for the total integral:\n\n\n\\begin{equation}\nI = \\int\\limits_{{y_1}}^{{y_2}} {\\left\\{ {\\int\\limits_{{x_1}(y)}^{{x_2}(y)} {f(x,y)dx} } \\right\\}dy}\n\\label{iterada}\n\\end{equation}\n\n\nTo clarify  \\cref{iterada}, note that the internal integral can be written as a function of $y$\n\n\n\\[F(y) = \\int\\limits_{{x_1}(y)}^{{x_2}(y)} {f(x,y)dx} \\]\n\nand the external integral like:\n\n\n\\[I = \\int\\limits_{{y_1}}^{{y_2}} {F(y)dy}. \\]\n\n\nAlternatively (see \\cref{fig:diry}) it is possible to define:\n\n\n\\[H(x) = \\int\\limits_{{y_1}(x)}^{{y_2}(x)} {f(x,y)dy} \\]\n\nin such a way that the full integral $I$ is defined by:\n\n\\[I = \\int\\limits_{{x_1}}^{{x_2}} {H(x)dx}. \\]\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{img/diry.pdf}\n\\caption{Integration along the $y$ direction.}\n\\label{fig:diry}\n\\end{figure}\n\n\nLet us apply the previous ideas to compute the integral\n\n\\[I = \\int {\\int {x{y^2}} } dA\\]\n\nover the region shown in \\cref{fig:ejeint}.\n\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{img/ejeint.pdf}\n\\caption{Integration along the $x$ direction over the triangular region $R$.}\n\\label{fig:ejeint}\n\\end{figure}\n\nIdentifying the lower and upper integration limits along the $y$ direction as ${y_1} = 0$ and ${y_2} = 2$ respectively, and the functions ${{x_1}(y)}$ and ${{x_2}(y)}$ like:\n\n\\[x_1(y) = \\frac{y}{2}\\]\nand\n\\[x_2(y) = 1\\]\nwe have that:\n\\[F(y) = \\int\\limits_{{x_1}(y)}^{1.0} {x{y^2}dx}  \\equiv \\int\\limits_{y/2}^{1.0} {x{y^2}dx} \\]\n\nthen\n\n\\[F(y) = \\left. {\\frac{1}{2}{x^2}{y^2}} \\right|_{y/2}^{1.0} \\equiv \\frac{1}{2}{y^2} - \\frac{1}{8}{y^4}\\]\n\nusing this function to integrate in $y$ one finally gets that:\n\n\\[I = \\int\\limits_0^{2.0} {F(y)dy}  \\equiv \\int\\limits_0^{2.0} {(\\frac{1}{2}{y^2} - \\frac{1}{8}{y^4})dy}  \\equiv \\frac{8}{{15}}.\\]\n\n\nProceeding alternatively (see \\cref{fig:ejeinty}) it is possible to write:\n\n\\[H(x) = \\int\\limits_{{y_1}(x)}^{{y_2}(x)} {x{y^2}dy} \\]\n\nand\n\n\\[I = \\int\\limits_{{x_1}}^{{x_2}} {H(x)dx} \\]\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{img/ejeinty.pdf}\n\\caption{Integration along the $y$ direction over the triangular region $R$.}\n\\label{fig:ejeinty}\n\\end{figure}\n\nwhere:\n\n\\[{y_1}(x) = 0\\]\n\\[{y_2}(x) = 2x\\]\n\nthen\n\n\\[H(x) = \\int\\limits_0^{2x} {x{y^2}dy}  \\equiv \\left. {\\frac{1}{3}x{y^3}} \\right|_0^{2x} \\equiv \\frac{8}{3}{x^4}\\]\n\nso the integral reduces to:\n\n\\[I = \\int\\limits_0^{1.0} {\\frac{8}{3}{x^4}dx}  \\equiv \\frac{8}{{15}}.\\]\n\n\\section{Gaussian quadratures}\nIn the numerical quadrature corresponding to the extended trapezoidal rule written in the form\n\n\\begin{equation}\n\\int\\limits_a^b {f(x)dx \\approx \\sum\\limits_{I = 1}^{npts} {{w^I}f({x^I})} }\n\\label{quadra2}\n\\end{equation}\n\nthe integration points are equidistantly spaced. In a Gaussian quadrature in addition to adjusting the $N$ weighting factors $w^I$ one also leaves as adjustable parameters the location of the $N$ integration points. As a result, there are now $2N$ parameters to adjust in the derivation of an algorithm to numerically approximate the integral of $f(x)$ between $x=a$ and $x=b$ with the maximum accuracy and the minimum number of operations. This class of quadratures provide better precision than those based on Newton-Cotes techniques (such as the trapezoidal rule) when the function to integrate can be appropriately represented by a polynomial.\n\nIn general, different Gaussian quadratures are found in the literature reported in terms of tables providing the locations of integration (or Gauss) points and the corresponding weighting factors $w^I$. As an example \\cref{ejemplo2} gives abscissas and weighting factors for a 4-point Gaussian quadrature.\n\n\\begin{center}\n\\begin{tabular}{cc}\n  \\hline\n  $x^I$ & $w^I$ \\\\\n  \\hline \n  $-0.86113$  & $0.34785$  \\\\\n  $-0.33998$  & $0.65214$  \\\\\n  $ +0.33998$  & $0.65214$  \\\\\n  $ +0.86113$  & $0.34785$  \\\\\n  \\hline\n\\end{tabular}\n\\captionof{table}{Abscissas and weighting factors to compute $\\int\\limits_{ - 1}^{ + 1} {f(x)dx}$}\n\\label{ejemplo2}\n\\end{center}\n\nTo facilitate coding of these quadratures and allow for approximation of general integrals, it is common to consider a primitive range of integration $[-1.0,+1.0]$ which requires transforming the original integral (including the function and its integration limits)to this primitive integral as discussed in \\cref{isopar}. \\Cref{fig:quagauss} schematizes the primitive integration range and the corresponding Gauss points denoted by the black $x$s. Transformation of a given integral to the primitive space is discussed at a later section.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{img/quagauss.pdf}\n\\caption{Schematic reperesentation of a Gaussian quadrature in the primitive range $[-1.0,1.0]$.}\n\\label{fig:quagauss}\n\\end{figure}\n\n\\paragraph*{Example:Derivation of a Gaussian quadrature}\nLet $n=2$ and the integration interval $[a,b]=[-1,+1]$. Find $w^1$, $w^2$ and $x^1$, $x^2$ such the quadrature\n\n\n\\[I = \\int\\limits_{ - 1}^{ + 1} {f(x)dx}  \\approx {w^1}f({x^1}) + {w^2}f({x^2})\\]\n\nintegrated exactly the function  $f(x)$ corresponding to a third order polynomial like:\n\n\n\n\\[f(x) = {a_0} + {a_1}x + {a_2}{x^2} + {a_3}{x^3}.\\]\n\nUsing $f(x)$ in $I$ and stating the integral for each term we have:\n\n\n\\[I = \\int\\limits_{ - 1}^{ + 1} {{a_0}dx}  + \\int\\limits_{ - 1}^{ + 1} {{a_1}xdx}  + \\int\\limits_{ - 1}^{ + 1} {{a_2}{x^2}dx}  + \\int\\limits_{ - 1}^{ + 1} {{a_3}{x^3}dx} \\]\n\nwhere:\n\n\\[\\int\\limits_{ - 1}^{ + 1} {dx}  = 2 = {w^1} \\cdot 1 + {w^2} \\cdot 1\\]\n\n\\[\\int\\limits_{ - 1}^{ + 1} {xdx}  = 0 = {w^1} \\cdot {x^1} + {w^2} \\cdot {x^2}\\]\n\n\\[\\int\\limits_{ - 1}^{ + 1} {{x^2}dx}  = \\frac{2}{3} = {w^1} \\cdot {({x^1})^2} + {w^2} \\cdot {({x^2})^2}\\]\n\n\\[\\int\\limits_{ - 1}^{ + 1} {{x^3}dx}  = 0 = {w^1} \\cdot {({x^1})^3} + {w^2} \\cdot {({x^2})^3}.\\]\n\nThe resulting system of equations is solved in order to determine the 4 quadrature parameters, namely $w^1$, $w^2$ and $x^1$, $x^2$ giving $w^1 = 1$, $w^2 = 1$, $x^1 =  - \\sqrt 3 /3$ and $x^1 =  + \\sqrt 3 /3$ which allows us to write the quadrature in the general form:\n\n\\[I = \\int\\limits_{ - 1}^{ + 1} {f(x)dx}  \\approx 1.0 \\cdot f( - \\sqrt 3 /3) + 1.0 \\cdot f( + \\sqrt 3 /3)\\]\n\nwhich is exact for polynomial functions of order at most 3.\n\nThe idea behind Gaussian quadratures can be extended to the integration of higher order polynomials, however its derivation requires an effective method to determine the weighting factors and the abscissas of the Gauss points. The next section discusses a method which is applicable to $2n$-order polynomials, in which advantage is taken from the property of orthogonality existing in certain special polynomials.\n\n\n\n\n%\\newpage\n\\section{Numerical integration in the finite element method}\n\\label{isopar}\n\n\\subsection{One-dimensional domains}\nThe systematization and construction of tables with coordinates and weighting factors for different quadratures is  useful if these are specified for a fixed range. For mathematical convenience it is common to use as base interval $[-1,+1]$. However considering that we are interested in integrating a function $f(x)$ in the general range with limits $x=a$ and $x=b$ it is required that we re-write the integral like:\n\n\\begin{equation}\n\\int\\limits_a^b {f(x)dx \\equiv } \\int\\limits_{ - 1}^{ + 1} {F(r)dr}. \n\\label{trans}\n\\end{equation}\n\nThe mapping indicated in \\cref{trans} is described in \\cref{fig:map}, in which the space represented by the independent variable $x$ and contained between $x=a$ and $x=b$ is mapped to a fictitious \"natural\" space described by a new independent variable $r$ and enclosed in $r=-1$ y $r=1$.\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=12cm]{img/mapping.pdf}\n\\caption{Mapping between the physical space $[a,b]$ and the primitive or natural space $[-1.0,+1.0].$}\n\\label{fig:map}\n\\end{figure}\n\nThis is exactly the same transformation used when approximating unknown functions using interpolation theory over arbitrary distorted domains. Repeating for convenience, the transformation between both spaces can be written like:\n\n\\[x = x(r)\\]\n\\[r = r(x)\\]\n\nand where $x(r)$ and $r(x)$ represent functional relationships between both spaces. For instance, in reference to \\cref{fig:map}, it is evident that independent of the functional relationship this must satisfy the condition $x(-1.0)=a$ and $x(+1)=b$. Therefore, a valid relationship can be derived after assuming that both spaces are related through a Lagrange interpolating polynomials as follows:\n\n\\[x(r) = {L^1}(r)x({r^1}) + {L^2}(r)x({r^2})\\]\n\n\nand where the interpolation polynomials are given by:\n\n\n\\[{L^1}(r) = \\frac{{(r - {r^2})}}{{({r^1} - {r^2})}} \\equiv \\frac{1}{2}(1 - r)\\]\n\n\\[{L^2}(r) = \\frac{{(r - {r^1})}}{{({r^2} - {r^1})}} \\equiv \\frac{1}{2}(1 + r)\\]\n\nwhich results in:\n\n\\[x(r) = \\frac{1}{2}(a + b) + \\frac{r}{2}(b - a).\\]\n\n\nIt is also necessary to re-write $f(x)$ using as independent variable $r$ instead of $x$ using the functional relationship $x=x(r)$ like:\n\n\\[f = f(x) \\equiv f[x(r)] = \\hat F(r)\\]\n\nwhere $\\hat F(r)$ represents the same function but now written in terms of $r$.\n\n\nFinally, to complete the transformation it is necessary to transform physical differential space elements, that is $dx$. Proceeding directly from the mapping via the Lagrange interpolation polynomials we have:\n\n\n\n\\[\\frac{{dx}}{{dr}} = \\frac{{d{L^1}(r)}}{{dr}}x({r^1}) + \\frac{{d{L^2}(r)}}{{dr}}x({r^2}) \\equiv \\frac{1}{2}(b - a)\\]\n\nand therefore\n\n\\[\\frac{{dx}}{{dr}} = \\frac{1}{2}(b - a)\\]\n\nwhich allows us to finally write the integral in the fictitious domain enclosed in $[-1, +1]$ according to:\n\n\\[\\int\\limits_a^b {f(x)dx \\equiv } \\int\\limits_{ - 1}^{ + 1} {\\hat F(r)\\frac{\\ell}{2}dr}  \\equiv \\int\\limits_{ - 1}^{ + 1} {F(r)dr} \\]\n\n\nand where $\\ell= \\frac{1}{2}(b - a).$\n\n\\begin{tcolorbox}\nThe module {\\bf Gaussutil()} in the finite element code {\\bf SolidsPy} contains several one-dimensional and two-dimensional Gauss quadratures.\n\\end{tcolorbox}\n\n\n\\paragraph*{Example}\n\n\nUse a 2 point Gaussian quadrature (see \\cref{ejemplo3}) to evaluate the integral:\n\n\\[I = \\int\\limits_0^3 {({2^x} - x)dx}. \\]\n\n\n\\begin{center}\n\\begin{tabular}{cc}\n  \\hline\n  $x^I$ & $w^I$ \\\\\n  \\hline \n  $-0.577350269189626$  &  $1.000000$  \\\\\n  $+0.577350269189626$  & $1.000000$  \\\\\n  \\hline\n\\end{tabular}\n\\captionof{table}{Abscissas and weighting factors to compute $\\int\\limits_{ - 1}^{ + 1} {f(r)dr}$}\n\\label{ejemplo3}\n\\end{center}\n\nTo perform the numerical integration using the 2-point Gaussian quadrature given in \\cref{ejemplo3} it is necessary to transform the integration range and the integrand of the function to the range corresponding to $[-1.0,+1.0]$. The transformation is given by:\n\n\\[x(r) = \\frac{3}{2} + \\frac{3}{2}r\\]\n\nwhile the differential elements satisfy\n\n\\[dx = \\frac{3}{2}dr.\\]\n\nTo transform the function we use:\n\n\\[\\hat f(r) = f[x(r)] \\equiv f\\left( {\\frac{3}{2} + \\frac{3}{2}r} \\right)\\]\n\n\nfrom which:\n\n\\[I = \\int\\limits_0^3 {({2^x} - x)dx}  \\equiv \\int\\limits_{ - 1.0}^{ + 1.0} {\\left[ {{2^{\\frac{3}{2}(1 + r)}} - \\frac{3}{2}(1 + r)} \\right]\\frac{3}{2}dr} \\]\n\nand evaluating:\n\n\\[I = \\sum\\limits_{I = 1}^2 {{w^I}\\left[ {{2^{\\frac{3}{2}(1 + {r^I})}} - \\frac{3}{2}(1 + {r^I})} \\right]\\frac{3}{2}}  = 1.0 \\cdot (1.37678967978) + 1.0 \\cdot (4.18374583924) \\equiv 5.56053551\\]\n\n\\subsection{Two-dimensional domains}\nIn the finite element method there is interest in computing integrals like:\n\n\\begin{equation}\nI=\\int_{V(\\overrightarrow x)} f(\\overrightarrow x)\\operatorname dV(\\overrightarrow x)\n\\label{integral}\n\\end{equation}\n\nwhere $V(\\overrightarrow x)$ is the domain of a typical finite element in a reference system with position vector $\\overrightarrow x$. In one-dimensional problems $V(\\overrightarrow x)\\equiv\\lbrack x_a,x_b\\rbrack$; in two-dimensional problems $V(\\overrightarrow x)$ is a plane surface; and in three-dimensional problems $V(\\overrightarrow x)$ is a volume. Moreover, previously we have defined a finite element like a local interpolation space where values of a function are known at specific points (nodes). For instance, in two-dimensional space we had a quadrilateral bi-lineal element as the one shown in \\cref{fig:generalElement}.\n\n%\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=8cm]{img/physical}\n\\caption{Arbitrary bi-lineal element defined in the physical space}\n\\label{fig:generalElement}\n\\end{figure}\n\nAs in the one-dimensional case discussed in the previous section, to conduct numerical integration in a systematic way, we actually need to transform generalized finite elements into canonical interpolation spaces (see \\cref{fig:IsoTrans}).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=12cm]{img/isopar}\n\\caption{Transformation from a general distorted element in the physical space to a perfect square in the natural space}\n\\label{fig:IsoTrans}\n\\end{figure}\n\nRepeating the transformation for convenience, we have:\n\n\\begin{equation}\n\\begin{aligned}\nx_i &=x_i(\\overrightarrow r)\\\\\nr_I &=r_I(\\overrightarrow x)\n\\end{aligned}\n\\label{eq:transQ}\n\\end{equation}\n\nwhere $\\overrightarrow x$ and $\\overrightarrow r$ denote position vectors in the physical and canonical space respectively. Using the above to transform functions we can write:\n\n\n\n\\begin{equation}\nf=f(\\overrightarrow x)\\equiv f\\lbrack x_i(\\overrightarrow r)\\rbrack\\equiv F(\\overrightarrow r).\n\\label{eq:FtransQ}\n\\end{equation}\n\n\n\\Cref{eq:FtransQ} above indicates that passing $f(\\overrightarrow x)$ from the physical to the natural space representation corresponds to a change of variables. In the particular case of classical finite element methods the change of variables is conducted after approximating the physical geometry using interpolation. particularly, using the same set of shape functions as in the approximation of the primary fields we can write:\n\n\\begin{equation}\nx_i(\\overrightarrow r)=N_i^Q(\\overrightarrow r)x^Q\n\\label{eq:Strans}\n\\end{equation}\n\nwhere $x^Q$ denotes the spatial coordinates of nodal point $Q$ and $=N_i^Q(\\overrightarrow r)$ is the shape function associated to the nodal point $Q$. According to this expression in the finite element method the geometry is interpolated in terms similar to the ones used for the primary field variable.\n\nTo transform the domain of integration we start once again from the general functional relationship:\n\n\\[x_i =x_i(\\overrightarrow r)\\]\n\nand  use it to stablish the relationship between differential lengths in both spaces as:\n\n\n\\begin{equation}\ndx_i=\\frac{\\partial x_i}{\\partial r_J}dr_j.\n\\label{eq:diflen}\n\\end{equation}\n\nThe second order tensor $\\frac{\\partial x_i}{\\partial r_J}$ appearing in \\ref{eq:diflen} is the Jacobian of the transformation $J_{iJ}$ explicitly defined by;\n\n\n\\[J_{iJ}=\\frac{\\partial x_i}{\\partial r_J}\\]\n\nand this tensor contains all the information regarding the geometric changes between both spaces. In terms of the shape functions it follows that:\n\n\\begin{equation}\nJ_{iJ}=\\frac{\\partial x_i}{\\partial r_J}\\equiv\\frac{\\partial N_i^Q}{\\partial r_J}x^Q.\n\\label{eq:disJac}\n\\end{equation}\n\nTo complete the transformation we make use of Nanson's formula from continuum mechanics, from which:\n\n\n\\[ dV(\\overrightarrow x)=\\left|J\\right|dV(\\overrightarrow r)\\]\n\n\nwhere $\\left|J\\right|$ is the determinant of the Jacobian tensor. We can write for $I$ in both spaces:\n\n\n\\begin{equation}\nI=\\int_{V(\\overrightarrow x)}f(\\overrightarrow x)\\operatorname dV(\\overrightarrow x)\\equiv\\int_{V(\\overrightarrow r)}F(\\overrightarrow r)\\left|J(\\overrightarrow r)\\right|\\operatorname dV(\\overrightarrow r)\n\\label{eq:twoInte}\n\\end{equation}\n\n\nConsider now the particular case of a two-dimensional bi-lineal finite element discussed previously and its transformation into the natural space shown in \\cref{fig:IsoMap}. Notice that this canonical element is a perfect square of element side $2.0$ contained between $x\\in\\left[-1.0\\;,\\;+1.0\\right]$ and $y\\in\\left[-1.0\\;,\\;+1.0\\right]$ which is the same range of the fundamental quadrature studied in the one-dimensional context.\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=12cm]{img/mapping2}\n\\caption{Transformation from a general distorted element in the physical space to a perfect square in the natural space}\n\\label{fig:IsoMap}\n\\end{figure}\n\n\nIn the particular case of the transformation described in \\cref{fig:IsoMap} we have that\n\n\n\\[dV(\\overrightarrow r)=drds\\]\n\ntherefore\n\n\\[dV(\\overrightarrow x)=\\left|J\\right|drds\\]\n\n\nand \\cref{eq:twoInte} takes the form:\n\n\n\\begin{equation}\nI=\\int_{S(\\overrightarrow x)}f(\\overrightarrow x)\\operatorname dS(\\overrightarrow x)\\equiv\\int_{r=-1}^{r=+1}\\int_{s=-1}^{s=+1}F(r,s)\\left|J(r,s)\\right|\\operatorname drds.\n\\label{eq:bilineal}\n\\end{equation}\n\nTo integrate \\ref{eq:bilineal} using a quadrature of $Ngpts$ integration points we use:\n\n\\begin{equation}\nI=\\int_{r=-1}^{r=+1}\\int_{s=-1}^{s=+1}F(r,s)\\left|J(r,s)\\right|\\operatorname drds\\approx\\sum_{i=1}^{Ngpts}\\sum_{j=1}^{Ngpts}F(r_i,s_j)\\left|J(r_i,s_j)\\right|w_iw_j\n\\label{eq:Iquad}\n\\end{equation}\n\nwhich can be simplified into\n\n\\begin{equation}\nI=\\int_{r=-1}^{r=+1}\\int_{s=-1}^{s=+1}F(r,s)\\left|J(r,s)\\right|\\operatorname drds\\approx\\sum_{k=1}^{Ngpts\\ast Ngpts}F(r_k,s_k)\\left|J(r_k,s_k)\\right|\\alpha_k\n\\label{eq:Iquad1}\n\\end{equation}\n\nwhich the one-dimensional version resulting from the iterated summation. The points marked with a cross in \\cref{fig:IsoMap} represent integration points.\n\n\\begin{tcolorbox}\nNotebook 5 in the REPO uses transformation or mapping from the physical to the canonical space, together with numerical integration, to compute the area of a distorted quadrilateral finite element.\n\\end{tcolorbox}\n\n\n\n\\subsection{Matrix formulation}\nFor the computer implementation of the different methods discussed so far it is practical to use a combined notation in terms of index and matrix representation of variables. Consider the interpolated version of a vector field, for instance the displacement vector in elasticity:\n\n\\begin{equation}\nu_i(\\overrightarrow r)=N_i^Q(\\overrightarrow r)u^Q\n\\label{eq:mixed}\n\\end{equation}\n\n\nin which:\n\n\\begin{itemize}\n\\item[•] Susbcript $i$ refers to the normal components of vectors in the physical space\n\\item[•] Superscript $Q$ refers to the contribution from nodal point $Q$ to the approximated field (in this case $u_i(\\overrightarrow r)$)\n\\item[•] $\\overrightarrow r$ position vector of a point in the natural space. In index notation we refer to the scalar components of this vector using capitalized subscripts as $\\overrightarrow r=r_I$\n\\item[•] $N_i^Q(\\overrightarrow r)$ shape function associated to the nodal point $Q$ evaluated at the point $\\overrightarrow r$.\n\\end{itemize}\n\nThe contribution to the $Q$ nodal point implicit in \\cref{eq:mixed} can be written in explicit expanded form as:\n\\[\n\\begin{array}{l}\\begin{Bmatrix}u\\\\v\\end{Bmatrix}=\\left[\\cdots\\begin{array}{cc}N^Q(\\overrightarrow r)&0\\\\0&N^Q(\\overrightarrow r)\\end{array}\\cdots\\right]\\begin{Bmatrix}\\vdots\\\\\\begin{array}{c}u^Q\\\\v^Q\\end{array}\\\\\\vdots\\end{Bmatrix}.\\\\\\end{array}\n\\]\n\n\nTo compute the Jacobian tensor at point $\\overrightarrow r$ assume that the nodal coordinates are stored in a matrix\n\n\n\n\\[\n\\begin{array}{l}coord\\;=\\begin{bmatrix}\\vdots\\\\\\begin{array}{cc}x^Q&y^Q\\end{array}\\\\\\vdots\\end{bmatrix}\\\\\\end{array}\n\\]\n\nthen we can further express:\n\n\\begin{equation}\n\\begin{array}{l}\\begin{bmatrix}\\frac{\\partial x}{\\partial r}&\\frac{\\partial y}{\\partial r}\\\\\\frac{\\partial x}{\\partial s}&\\frac{\\partial y}{\\partial s}\\end{bmatrix}=\\begin{bmatrix}\\cdots&\\begin{array}{c}\\frac{\\partial N^Q}{\\partial r}\\\\\\frac{\\partial N^Q}{\\partial s}\\end{array}&\\cdots\\end{bmatrix}\\begin{bmatrix}\\vdots\\\\\\begin{array}{cc}x^Q&y^Q\\end{array}\\\\\\vdots\\end{bmatrix}\\\\\\end{array}\n\\label{eq:jac}\n\\end{equation}\n\nHaving found the Jacobian of the transformation the remaining step consists in transforming the integrand $f(\\overrightarrow{x})$. This step however is not constructed explicitly  but it depends on the structure of $f(\\overrightarrow{x})$. In most finite element algorithms the problem formulation involves spatial derivatives of the primary function rather than the primary function itself. To consider these terms in the transformed version of $I$, it becomes necessary to relate spatial differentiation in both spaces. To clarify this aspect of the formulation assume that $I$ is of the form:\n\n\\[I=\\int_{V(\\overrightarrow x)}\\frac{\\partial f}{\\partial\\overrightarrow x}\\operatorname dV(\\overrightarrow x).\\]\n\nWe already found that\n\n\\[\\operatorname dV(\\overrightarrow x)=\\left|J\\right|\\operatorname dV(\\overrightarrow r)\\]\n\nand to transform the integrand\n\n\n\\[\\frac{\\partial f}{\\partial\\overrightarrow x}\\]\n\nwe recall that in the finite element method the interpolation of the primary variable is conducted directly in the natural space. This means that we already have $F(\\overrightarrow r)$ or more explicitly that:\n\n\n\n\n\n\\[F(\\overrightarrow r)=N^Q(\\overrightarrow r)F^Q.\\]\n\nHowever to capture correctly the physics of the problem we are interested in finding\n\n\\[\\frac{\\partial f}{\\partial\\overrightarrow x}.\\]\n\nUsing implicit differentiation:\n\n\\[\\frac{\\partial f}{\\partial x_i}=\\frac{\\partial F}{\\partial r_J}\\frac{\\partial r_J}{\\partial x_i}\\]\n\nand re-arranging for convenience we write\n\n\\begin{equation}\n\\frac{\\partial f}{\\partial x_i}=\\frac{\\displaystyle\\partial r_J}{\\displaystyle\\partial x_i}\\frac{\\partial F}{\\partial r_J}.\n\\end{equation}\n\nNotice that the first factor is the Jacobian inverse given by;\n\n\\[\\frac{\\partial r_J}{\\partial x_i}=\\left(J_{iJ}\\right)^{-1}\\equiv\\left(\\frac{\\displaystyle\\partial x_i}{\\displaystyle\\partial r_J}\\right)^{-1}\\]\n\nwhile the second factor reads:\n\n\\[\\frac{\\partial F}{\\partial r_J}=\\frac{\\partial N^Q}{\\partial r_J}F^Q\\]\n\nwhich allows us to write:\n\n\\[I=\\int_{V(\\overrightarrow x)}\\frac{\\partial f}{\\partial\\overrightarrow x}\\operatorname d{V(\\overrightarrow x)}\\equiv\\int_{V(\\overrightarrow r)}J_{iJ}^{-1}\\frac{\\displaystyle\\partial N^Q}{\\displaystyle\\partial r_J} F^Q \\left|J(\\overrightarrow r)\\right|\\operatorname dV(\\overrightarrow r).\\]\n\n\n\\begin{tcolorbox}\nAs an in-class activity Notebook 6 in the REPO requires the computation of the stiffness matrix for a plane strain solid element.\n\\end{tcolorbox}\n\n\\paragraph*{Proposed problems}\n\\begin{enumerate}\n\n\\item \\label{punto01} Compute the integral of the function\n\n\\[f(x,y)=4x^2+3xy+y^2\\]\n\nover the two-dimensional domains shown in the figure\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=12cm]{domain1}\n\\caption{Integration domains for problem 1}\n\\label{fig:intdomains}\n\\end{figure}\n\n\\item \\label{punto02} Compute the jacobian of the transformation of the domains shown in the figure\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=14cm]{domain2}\n\\caption{Integration domains for problem 1}\n\\label{fig:jacdomains}\n\\end{figure}\n\nto a perfectly square canonical element of side $2.0$.\n\n\\item \\label{punto03} Compute the integral of the function\n\n\\[f(r,s)=rs\\]\n\nover the triangular domain shown in the figure\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=7cm]{domain3}\n\\caption{Integration domains for problem 1}\n\\label{fig:tridomains}\n\\end{figure}\n\n\n\n\\end{enumerate}\n", "meta": {"hexsha": "45edd8b8d67d3027a47c15387eec714de58dc893", "size": 33480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course_notes/src/quadratures.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/quadratures.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/quadratures.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": 41.7456359102, "max_line_length": 1273, "alphanum_fraction": 0.7206391876, "num_tokens": 10209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.6577901315361719}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath}\n\\usepackage{verbatim}\n\n%opening\n\\title{Demonstration of the solution of the system of mass and energy balances for MS Birka Main Engines}\n\\author{Francesco Baldi}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n\n\\end{abstract}\n\n\\section{Initial system}\n\n\\subsection{Mass balances}\n\nMass balance on the split after the compressor, with one flow going to the engine inlet valves and the other flow going to the bypass valve\n\\begin{equation}\n\\dot{m}_{air,comp} = \\dot{m}_{air,cyl} + \\dot{m}_{air,bypass} \\\\\n\\end{equation}\n\nMass balance on the mixer before the turbine, with one flow coming from the engine exhaust valves and the other flow coming from the bypass valve\n\\begin{equation}\n\\dot{m}_{eg,turb} = \\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass} \\\\\n\\end{equation}\n\nNote that the exhaust gas mass flow from the cylinders is fully defined as follows:\n\\begin{equation}\n\\dot{m}_{eg,cyl} = \\dot{m}_{air,cyl} + \\dot{m}_{fuel,cyl} \\\\\n\\end{equation}\n\n\\subsection{Energy balances}\n\nEnergy balance on the turbocharger: the power generated by the turbine must be equal to the power absorbed by the compressor\n\\begin{equation}\n\\dot{m}_{air,comp} \\Delta h_{comp} = \\dot{m}_{eg,turb} c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech}\n\\end{equation}\n\nEnergy balance on the mixer between the air flow after the bypass valve and the exhaust gas flow after the exhaust valve\n\\begin{equation}\n\\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0) + \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0) = \\dot{m}_{eg,turb} c_{p,eg} (T_{turb,in} - T_0)\n\\end{equation}\n\n\nThe system of four equations is to be solved in the four following unknowns:\n\\begin{itemize}\n\t\\item $ \\dot{m}_{eg,turb} $\n\t\\item $ \\dot{m}_{air,bypass} $\n\t\\item $ \\dot{m}_{air,comp} $\n\t\\item $ T_{turb,in} $ (In the case of the Main engines)\n\t\\item $ T_{cyl,out} $ (In the case of the Auxiliary engines)\n\\end{itemize}\n\n\\section{Calculating the explicit system}\n\nTo calculate what we need, we must make the system explicit on the variables we need to calculate. This process is different for the main and auxiliary engines, mostly because the temperature measurement of the exhaust gas before the turbine is positioned differently\n\n\\subsection{Main Engines}\n\nIn the case of the main engines, the temperature at the \\textbf{cylinder outlet} is measured and, hence, known. \n\nFirst, we make all equations explicit in $ \\dot{m}_{air,bypass} $ thus eliminating both \n$ \\dot{m}_{eg,turb} $ and $ \\dot{m}_{air,comp} $\n\n$$\n(\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}) \\Delta h_{comp} = (\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}) c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech} \n$$\n$$\n\\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0) + \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0)  = (\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}) c_{p,eg} (T_{turb,in} - T_0)\n$$\n\nAt this point, we use the first equation to simplify the system and make it explicit in the $ \\dot{m}_{air,bypass} $ variable alone:\n\n\\begin{eqnarray*}\n(\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}) c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech}  & = & (\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}) \\Delta h_{comp} \\\\\nT_{turb,in} - T_{turb,out} & = & \\frac{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}}{\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}} \\frac{\\Delta h_{comp}}{c_{p,eg} \\eta_{mech}} \\\\\nT_{turb,in} & = & T_{turb,out} + \\frac{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}}{\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}} \\frac{\\Delta h_{comp}}{c_{p,eg} \\eta_{mech}}  \\\\\n\\end{eqnarray*}\n\nWe can now substitute this expression in the second equation:\n\n\\begin{multline}\n\t\\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0) + \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0)  =  \\\\ \n\t(\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}) c_{p,eg} (T_{turb,out} + \\frac{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}}{\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}} \\frac{\\Delta h_{comp}}{c_{p,eg} \\eta_{mech}} - T_0)\n\\end{multline}\n\nWe now have to simplify this equation in order to make the term $ \\dot{m}_{air,bypass} $ explicit. \n\\begin{comment}\nOne first thing we can do is noticing that the fraction:\n$$\n\\frac{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}}{\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}}\n$$\nCan be rewritten as:\n$$\n\\frac{1}{1 + \\frac{\\dot{m}_{fuel,cyl}}{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}}}\n$$\nSince the numerator of the \"subfraction\" is much smaller than the denominator, we can make the assumption that this fraction behaves as:\n$$\n\\frac{1}{1 + \\epsilon}\n$$\nFor which we know that:\n$$\n\\frac{1}{1 + \\epsilon} \\approx 1 - \\epsilon \n$$\nThat corresponds to:\n$$\n1 - \\frac{\\dot{m}_{fuel,cyl}}{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}}\n$$\n\\begin{multline}\n\\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0) + \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0)  =  \\\\ \n(\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}) c_{p,eg} \\left[T_{turb,out} + \\left( 1 - \\frac{\\dot{m}_{fuel,cyl}}{\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}} \\right) \\frac{\\Delta h_{comp}}{c_{p,eg} \\eta_{mech}} - T_0\\right]\n\\end{multline}\n\\end{comment}\n\nWe first execute the multiplication in the term on the right of the equal:\n\\begin{multline}\n\\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0) + \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0)  =  \\\\\n\\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,out} - T_0) + \\\\\n\\dot{m}_{air,bypass} c_{p,eg} (T_{turb,out} - T_0) + \\\\ \n\\frac{\\Delta h_{comp}}{c_{p,eg} \\eta_{mech}}(\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}) c_{p,eg}\n\\end{multline}\n\nNow, we can group together the elements in the variable of interest:\n\\begin{multline}\n\\dot{m}_{air,bypass} \\left[ c_{p,air} (T_{comp,out} - T_0) - c_{p,eg} (T_{turb,out} - T_0) - \\frac{\\Delta h_{comp}}{\\eta_{mech}} \\right] = \\\\\n\\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,out} - T_0) - \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0) + \\frac{\\Delta h_{comp}}{\\eta_{mech}}\\dot{m}_{air,cyl}\n\\end{multline}\n\nThis can be further simplified into:\n\\begin{multline}\n\\dot{m}_{air,bypass} \\left[ c_{p,air} (T_{comp,out} - T_0) - c_{p,eg} (T_{turb,out} - T_0) - \\frac{\\Delta h_{comp}}{\\eta_{mech}} \\right] = \\\\\n\\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,out} - T_{cyl,out}) + \\frac{\\Delta h_{comp}}{\\eta_{mech}}\\dot{m}_{air,cyl}\n\\end{multline}\n\nFinally, we can assume the specific heat at constant pressure of air and exhaust gas to be sufficiently similar for considering them equal in the term at the numerator (we ignored changes in the properties of the mixture in other points as well):\n\\begin{multline}\n\\dot{m}_{air,bypass} \\left[ c_{p,eg} (T_{comp,out} - T_{turb,out}) - \\frac{\\Delta h_{comp}}{\\eta_{mech}} \\right] = \\\\\n\\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,out} - T_{cyl,out}) + \\frac{\\Delta h_{comp}}{\\eta_{mech}}\\dot{m}_{air,cyl}\n\\end{multline}\n\nFrom which we can derive the final form:\n\\begin{equation}\n\\dot{m}_{air,bypass} = \\frac{\\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,out} - T_{cyl,out}) + \\frac{\\Delta h_{comp}}{\\eta_{mech}}\\dot{m}_{air,cyl}}{c_{p,eg} (T_{comp,out} - T_{turb,out}) - \\frac{\\Delta h_{comp}}{\\eta_{mech}}} \n\\end{equation}\n\nWhich can be rewritten, in order to have both numerator and denominator positive, as follows:\n\\begin{equation}\n\\dot{m}_{air,bypass} = \\frac{\\dot{m}_{eg,cyl} c_{p,eg} (T_{cyl,out} - T_{turb,out}) - \\frac{\\Delta h_{comp}}{\\eta_{mech}}\\dot{m}_{air,cyl}}{c_{p,eg} (T_{turb,out} - T_{comp,out}) - \\frac{\\Delta h_{comp}}{\\eta_{mech}}} \n\\end{equation}\n\n\n\n\\subsection{Auxiliary Engines}\n\nIn the case of the auxiliary engines, what we know instead is the temperature of the exhaust gas \\textbf{before the turbine}, hence after the merging between the exhaust gas and the bypass.\n\nIn this case, however, things appear to be simple: the energy balance on the turbocharger can be calculated as there is only one variable unknown: the total mass flow in the compressor, and hence the bypass flow:\n$$\n(\\dot{m}_{air,cyl} + \\dot{m}_{air,bypass}) \\Delta h_{comp} = (\\dot{m}_{eg,cyl} + \\dot{m}_{air,bypass}) c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech}\n$$\n$$\n\\dot{m}_{air,cyl} \\Delta h_{comp} + \\dot{m}_{air,bypass} \\Delta h_{comp} = \\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,in} - T_{turb,out}) + \\dot{m}_{air,bypass} c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech}\n$$\n$$\n\\dot{m}_{air,bypass} (\\Delta h_{comp} - c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech}) = \\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,in} - T_{turb,out}) - \\dot{m}_{air,cyl} \\Delta h_{comp}\n$$\n\\begin{equation}\n\\dot{m}_{air,bypass} = \\frac{\\dot{m}_{eg,cyl} c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech} - \\dot{m}_{air,cyl} \\Delta h_{comp}}{\\Delta h_{comp} - c_{p,eg} (T_{turb,in} - T_{turb,out}) \\eta_{mech}}\n\\end{equation}\n\nNow that we have the value for the bypass flow, it is easy to calculate backwards the temperature of the exhaust gas after the cylinder outlet valves, before the merging with the bypass flow:\n\n$$\n\\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0) + \\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0) = \\dot{m}_{eg,turb} c_{p,eg} (T_{turb,in} - T_0)\n$$\n$$\n\\dot{m}_{eg,cyl} c_{p,eg}  (T_{cyl,out} - T_0) = \\dot{m}_{eg,turb} c_{p,eg} (T_{turb,in} - T_0) - \\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0)\n$$\n\\begin{equation}\nT_{cyl,out} = T_0 + \\frac{\\dot{m}_{eg,turb} c_{p,eg} (T_{turb,in} - T_0) - \\dot{m}_{air,bypass} c_{p,air} (T_{comp,out} - T_0)}{\\dot{m}_{eg,cyl} c_{p,eg}}\n\\end{equation}\n\n\n\\end{document}\n", "meta": {"hexsha": "dcb8ccb861733674084959023036d1f52db53efd", "size": 9238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manuscript/Other/EngineBalance.tex", "max_stars_repo_name": "francescobaldi86/Ecos2015PaperExtension", "max_stars_repo_head_hexsha": "486cbb770c5394938f08af3d880d1300d71dc753", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-09-05T10:58:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-21T07:28:36.000Z", "max_issues_repo_path": "Manuscript/Other/EngineBalance.tex", "max_issues_repo_name": "francescobaldi86/Ecos2015PaperExtension", "max_issues_repo_head_hexsha": "486cbb770c5394938f08af3d880d1300d71dc753", "max_issues_repo_licenses": ["MIT"], "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/Other/EngineBalance.tex", "max_forks_repo_name": "francescobaldi86/Ecos2015PaperExtension", "max_forks_repo_head_hexsha": "486cbb770c5394938f08af3d880d1300d71dc753", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-03-14T19:30:37.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-10T10:07:43.000Z", "avg_line_length": 48.8783068783, "max_line_length": 267, "alphanum_fraction": 0.6622645594, "num_tokens": 3456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6577799421641389}}
{"text": "\\documentclass[letterpaper]{article}\n\\usepackage[margin=0.7in]{geometry}\n\\usepackage{amssymb, amsthm, times}\n\\usepackage{multicol}\n\\hbadness=99999     % Gets rid of 'underfill' typeset errors with LaTeX\n\\renewcommand{\\qedsymbol}{$\\blacksquare$}  % Changes QED symbol for closing a proof\n\\begin{document}\n\\begin{multicols*}{2}\n\n% See list here: https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols\n\\subsection*{General Symbols}\n$\\mathbb{N}$\\\\\n$\\mathbb{Z}$\\\\\n$\\mathbb{R}$\\\\\n$\\mathbb{C}$\\\\\n$\\mathbb{Q}$\\\\\n$<$\\\\\n$>$\\\\\n$\\leq$\\\\\n$\\geq$\\\\\n$\\nleq$\\\\\n$\\ngeq$\\\\\n$\\nless$\\\\\n$\\ngtr$\\\\\n$\\pi$\\\\\n$\\times$\\\\\n$\\pm$\\\\\n\n\n\\subsection*{CH 1: Logic}\n$\\neg$\\\\\n$\\land$\\\\\n$\\lor$\\\\\n$\\oplus$\\\\\n$\\to$\\\\\n$\\leftrightarrow$\\\\\n$\\exists$\\\\\n$\\forall$\\\\\n=\\\\\n$\\neq$\\\\\n$\\equiv$\\\\\n$\\not\\equiv$\\\\\n$\\therefore$\\\\\n\n\\subsection*{CH 2: Proofs}\n$\\blacksquare$\\\\\n$\\mid$\\\\\n$\\nmid$\\\\\n\n\\subsection*{CH 3: Sets}\n$\\in$\\\\\n$\\ni$\\\\\n$\\subset$\\\\\n$\\supset$\\\\\n$\\subseteq$\\\\\n$\\nsubseteq$\\\\\n$\\cup$\\\\\n$\\cap$\\\\\n$\\emptyset$\\\\\n$\\varnothing$\\\\\n$\\oplus$\\\\\n$\\notin$\\\\\n$\\nexists$\\\\\n$\\not\\subset$\\\\\n$\\not\\supset$\\\\\n$\\supseteq$\\\\\n$\\nsupseteq$\\\\\n\n\\subsection*{CH 4: Functions}\n$\\lceil x \\rceil$\\\\\n$\\lfloor x \\rfloor$\\\\\n$\\circ$\\\\\n\n\\subsection*{CH 5: Boolean Algebra}\n$\\overline{text}$\\\\\n$\\cdot$\\\\\n$\\uparrow$\\\\\n$\\downarrow$\\\\\n\n\\subsection*{CH 6: Relations}\n$\\prec$\\\\\n$\\preceq$\\\\\n$\\langle \\rangle$\\\\\n\n\\subsection*{CH 7: Computation}\n$\\delta$\n\n\\end{multicols*}\n\\end{document}\n", "meta": {"hexsha": "487e3f1777a463195917957b732f79a4ed0a30d2", "size": 1406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "symbols.tex", "max_stars_repo_name": "minhduccao/ics6b-latex-templates", "max_stars_repo_head_hexsha": "688656082091fa15f5fadbeb2e1f2c0f0e29d05f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "symbols.tex", "max_issues_repo_name": "minhduccao/ics6b-latex-templates", "max_issues_repo_head_hexsha": "688656082091fa15f5fadbeb2e1f2c0f0e29d05f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "symbols.tex", "max_forks_repo_name": "minhduccao/ics6b-latex-templates", "max_forks_repo_head_hexsha": "688656082091fa15f5fadbeb2e1f2c0f0e29d05f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-08T01:35:24.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-08T01:35:24.000Z", "avg_line_length": 15.6222222222, "max_line_length": 83, "alphanum_fraction": 0.6088193457, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.6577799404656226}}
{"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 \\#5 \\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:}\nIn the simple stereo system,\n\\begin{equation*}\n    Z = f\\frac{T}{d},\\ d= x_r - x_l\n\\end{equation*}\nSince the only source of noise is the localization of corresponding points in the two images, i.e. the disparity $d$, we have the error estimation as:\n\\begin{equation*}\n    \\Delta Z = \\sqrt{\\left( \\frac{\\partial Z}{\\partial d}\\Delta d\\right)^2+ \\left( \\frac{\\partial Z}{\\partial f}\\Delta f\\right)^2 + \\left( \\frac{\\partial Z}{\\partial T}\\Delta T\\right)^2} = |\\frac{\\partial Z}{\\partial d}|\\Delta d = \\frac{fT}{d^2}\\Delta d\n\\end{equation*}\nThe error in depth is directly proportional to the baseline $T$, focal length $f$, error in disparity $\\Delta d$, and $\\frac{1}{d^2}$. So in order to have less error in depth we should have more disparity, small baseline and focal length, and small error in disparity.\n\n%%---------------------------------------------------------------\n%% Question 2\n%%---------------------------------------------------------------\n\\section{Solution:}\n(a) \n\\begin{equation*}\nT = \\left[ \\begin{array}{cccc}\n1 & 0 & 0 & -7\\\\\n0 & 1 & 0 & -1\\\\\n0 & 0 & 1 & -2\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right],\\ R_{Y90}  = \\left[ \\begin{array}{cccc}\n0 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 0\\\\\n-1 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right],\\ R_{Z90}  = \\left[ \\begin{array}{cccc}\n0 & -1 & 0 & 0\\\\\n1 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 1\\\\\n\\end{array} \\right]\n\\end{equation*}\n\n\\begin{equation*}\nM_1 =  R_{Z90} R_{Y90} T = \\left[ \\begin{array}{cccc}\n0 & -1 & 0 & 1\\\\\n0 & 0 & 1 & -3\\\\\n-1 & 0 & 0 & 10\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right]\n\\end{equation*}\n\n\n\\noindent (b) \n\\begin{equation*}\nT = \\left[ \\begin{array}{cccc}\n1 & 0 & 0 & -10\\\\\n0 & 1 & 0 & -1\\\\\n0 & 0 & 1 & -3\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right],\\ R_{Y90}  = \\left[ \\begin{array}{cccc}\n0 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 0\\\\\n-1 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right],\\ R_{Z90}  = \\left[ \\begin{array}{cccc}\n0 & -1 & 0 & 0\\\\\n1 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 1\\\\\n\\end{array} \\right]\n\\end{equation*}\n\n\\begin{equation*}\nM_2 =  R_{Z90} R_{Y90} T = \\left[ \\begin{array}{cccc}\n0 & -1 & 0 & 1\\\\\n0 & 0 & 1 & -2\\\\\n-1 & 0 & 0 & 7\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right]\n\\end{equation*}\n\n\n\\noindent (c) Consider the homogeneous coordinates of $p_1$ and $p_2$ in camera 1 and 2 coordinates are:\n\n\\begin{equation*}\np_1 = \\left[ \\begin{array}{c}\n-\\frac{3}{10}k\\\\\n\\frac{1}{10}k\\\\\nk\\\\\n1\n\\end{array} \\right],\\ p_2 = \\left[ \\begin{array}{c}\n-\\frac{3}{7}l\\\\\n\\frac{2}{7}l\\\\\nl\\\\\n1\n\\end{array} \\right]\n\\end{equation*}\n\n\\noindent The world coordinates will be:\n\\begin{equation*}\np_1' = M_1^{-1}p1 = \\left[ \\begin{array}{c}\n10 - k\\\\\n1 + \\frac{3}{10}k\\\\\n3 + \\frac{1}{10}k\\\\\n1\n\\end{array} \\right],\\ p_2' = M_2^{-1}p_2 = \\left[ \\begin{array}{c}\n7 - l\\\\\n1 + \\frac{3}{7}l\\\\\n2 + \\frac{2}{7}l\\\\\n1\n\\end{array} \\right]\n\\end{equation*}\nLetting $p_1' = p_2'$ we have $k = 10$ and $l = 7$, and thus the world coordinate of $p$ is $(0, 4, 4)$.\n\n%%---------------------------------------------------------------\n%% Question 3\n%%---------------------------------------------------------------\n\\section{Solution:}\n(a) \n\\begin{equation*}\n    x = f\\frac{X}{Z} = 3, \\ y = f\\frac{Y}{Z} = 6,\\ z = f = 1\n\\end{equation*}\nThe location of the object at time $t = 0$ is (3, 6).\\\\\n(b)\n\n\\begin{equation*}\n    p_0  = \\left[ \\begin{array}{c}\nf\\frac{T_x}{T_z}\\\\\nf\\frac{T_y}{T_z}\\\\\nf\n\\end{array} \\right] = \\left[ \\begin{array}{c}\n5\\\\\n10\\\\\n1\n\\end{array} \\right] \n\\end{equation*}\nThe image coordinates of the focus of expansion is $(5, 10)$.\\\\\n(c) Time to collision\n\\begin{equation*}\n    \\tau = \\frac{Z}{w} = 10\n\\end{equation*}\n\n%%---------------------------------------------------------------\n%% Question 4\n%%---------------------------------------------------------------\n\\section{Solution:}\nThe acceleration of object is \n\\begin{equation*}\n    a = \\frac{2\\Delta S}{t^2} = \\left[ \\begin{array}{c}\n20\\\\\n40\\\\\n10\n\\end{array} \\right]\n\\end{equation*}\nThe location of object at time $t$ is \n\\begin{equation*}\nP_t = P_0 + \\frac{1}{2}at^2 = \\left[ \\begin{array}{c}\n10 +10t^2\\\\\n20 + 20t^2\\\\\n5t^2\n\\end{array} \\right]\n\\end{equation*}\nIts image coordinates\n\\begin{equation*}\np_t = \\left[ \\begin{array}{c}\nf\\frac{X}{Z}\\\\\nf\\frac{Y}{Z}\\\\\n\\end{array} \\right]=\\left[ \\begin{array}{c}\n\\frac{10 +10t^2}{5t^2}\\\\\n\\frac{20 + 20t^2}{5t^2}\\\\\n\\end{array} \\right]\n\\end{equation*}\nThe focus of expansion is\n\\begin{equation*}\np_0= \\lim\\limits_{t\\to\\infty}p_t = \\lim\\limits_{t\\to\\infty}\\left[ \\begin{array}{c}\n\\frac{10 +10t^2}{5t^2}\\\\\n\\frac{20 + 20t^2}{5t^2}\\\\\n\\end{array} \\right] = \\left[ \\begin{array}{c}\n2\\\\\n4\n\\end{array} \\right ]\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "62288dd8adc3d525e7b12120c590d0cbb2322bb3", "size": 5108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5639-Computer-Vision/Homework-5/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-5/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-5/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": 25.4129353234, "max_line_length": 268, "alphanum_fraction": 0.5366092404, "num_tokens": 2056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580952177051, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6577799279672509}}
{"text": "\\chapter{confCheck} \\label{confcheck}\n\n\\section{Introduction}\n\nConfluence checking is the analysis of an LPE to find ISTEP summands that are \\emph{confluent}.\nA confluent ISTEP summand is a summand with the property that the possible behavior of a system is the same up to branching bisimulation before and after applying that summand.\n\nIf branching bisimulation is sufficient in terms of accuracy, confluence information can be used to speed up state space generation by prioritizing confluent ISTEP summands.\nNote that this means that confluence checking does not bring benefits on its own!\n\n\\section{Algorithm}\n\nConsider all possible pairs of summands $(s, t)$ of the LPE where $s$ is a summand that communicates exclusively over the channel ISTEP and does a recursive process instantiation.\nThen\n\n\\begin{lstlisting}[mathescape]\n$s$ = ISTEP [[$c_s$]] >-> P($v_s(x_1)$, $\\cdots{}$, $v_s(x_n)$)\n$t$ = $A$ ? $a_1$ ? $\\cdots{}$ ? $a_m$ [[$c_t \\land a_1 = h_1 \\land \\cdots{} \\land a_m = h_m$]]\n                      >-> P($v_t(x_1)$, $\\cdots{}$, $v_t(x_n)$)\n\\end{lstlisting}\n\nwhere\n\n\\begin{itemize}\n\\item $x_1$ to $x_n$ are all process parameters of the LPE;\n\\item $v_s$ and $v_t$ are functions that yield the expressions that summands $s$ and $t$, respectively, assign to a given process parameter in their recursive process instantiation.\n\\end{itemize}\n\nFurthermore, let\n\\begin{align*}\n\\rho_s &= [x_1 \\rightarrow v_s(x_1), \\cdots{}, x_n \\rightarrow v_s(x_n)] \\\\\n\\rho_t &= [x_1 \\rightarrow v_t(x_1), \\cdots{}, x_n \\rightarrow v_t(x_n)]\n\\end{align*}\n\nIf for a particular ISTEP summand $s$ the following condition holds for all pairs $(s, t)$ such that $s \\neq t$, then $s$ is confluent:\n\\begin{align*}\nc_s \\land c_t \\rightarrow{} &c_s[\\rho_t] \\land c_t[\\rho_s] \\\\\n&{} \\land h_1 = h_1[\\rho_s] \\land \\cdots{} \\land h_m = h_m[\\rho_s] \\\\\n&{} \\land x_1[\\rho_s][\\rho_t] = x_1[\\rho_t][\\rho_s] \\land \\cdots{} \\land x_n[\\rho_t][\\rho_s] = x_n[\\rho_s][\\rho_t]\n\\end{align*}\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\nIs the second summand confluent?\n\nIf $c_s \\land c_t$ holds, then $c_s[\\rho_t] \\land c_t[\\rho_s]$ holds as well.\nSince $h_i$ does not use $y$, it is unaffected by $\\rho_s$.\nFinally,\n\\begin{align*}\nx[\\rho_s][\\rho_t] = x[\\rho_t][\\rho_s] = x+1 \\\\\ny[\\rho_s][\\rho_t] = y[\\rho_t][\\rho_s] = y+1\n\\end{align*}\n\nand therefore the confluence condition holds.\n\nSo yes, the second summand 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": "d726748a116ebbe3aa5711dcbba4cb386b4a9295", "size": 2956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_tex/lpeopsDoc/confCheck.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/confCheck.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/confCheck.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": 35.1904761905, "max_line_length": 181, "alphanum_fraction": 0.6806495264, "num_tokens": 965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6577704345822333}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{The metric connection}\n\nThis is a very standard computation that shows if\n\\begin{align}\n   \\Gamma^{a}_{b c} = \\frac{1}{2} g^{a d} (  \\partial_{b}{g_{d c}}\n                                          + \\partial_{c}{g_{b d}}\n                                          - \\partial_{d}{g_{b c}} )\n\\end{align}\nthen\n\\begin{align}\n   g_{ab;c} = 0.\n\\end{align}\n\nThis example might well be regarded as the Cadabra counterpart to the familiar \\emph{Hello World} program of undergraduate programming classes.\n\n\\vspace{15pt}\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   g_{a b}::Metric.\n   g_{a}^{b}::KroneckerDelta.\n\n   \\partial_{#}::PartialDerivative.\n\n   cderiv:=\\partial_{c}{g_{a b}} - g_{a d}\\Gamma^{d}_{b c}\n                                 - g_{d b}\\Gamma^{d}_{a c}.             # cdb (term31,cderiv)\n\n   Gamma:=\\Gamma^{a}_{b c} -> (1/2) g^{a d} (  \\partial_{b}{g_{d c}}\n                                             + \\partial_{c}{g_{b d}}\n                                             - \\partial_{d}{g_{b c}} ). # cdb (term32,Gamma)\n\n   substitute          (cderiv,Gamma);     # cdb (term33,cderiv)\n   distribute          (cderiv)            # cdb (term34,cderiv)\n   eliminate_metric    (cderiv)            # cdb (term35,cderiv)\n   eliminate_kronecker (cderiv)            # cdb (term36,cderiv)\n   canonicalise        (cderiv)            # cdb (term37,cderiv)\n\\end{cadabra}\n\n\\subsection*{The metric connection}\n\n\\vspace{-15pt}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{align*}\n   &\\cdb*{term31}\\\\\n   &\\cdb*{term32}\\\\\n   &\\cdb*{term33}\\\\\n   &\\cdb*{term34}\\\\\n   &\\cdb*{term35}\\\\\n   &\\cdb*{term36}\\\\\n   &\\cdb*{term37}\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*{term31}\\\\\n      &\\cdb*{term32}\\\\\n      &\\cdb*{term33}\\\\\n      &\\cdb*{term34}\\\\\n      &\\cdb*{term35}\\\\\n      &\\cdb*{term36}\\\\\n      &\\cdb*{term37}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}}\n\n\\end{document}\n", "meta": {"hexsha": "4fb74297c39f5c693b0a3eee5284e8e0b69f3deb", "size": 2065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cadabra/examples/example-02.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "cadabra/examples/example-02.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cadabra/examples/example-02.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 26.8181818182, "max_line_length": 143, "alphanum_fraction": 0.5288135593, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6577704144522224}}
{"text": "%\n% LaTeX report template \n%\n\n% This is a comment: in LaTeX everything that in a line comes\n% after a \"%\" symbol is treated as comment\n\n\\documentclass[11pt, a4paper]{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{listings}\n\n\n\\title{Assignment No 3} % Title\n\n%\\author{M.V.A.Suhas kumar (EE17B109)} % Author name\n\\author{M.V.A.Suhas Kumar \\\\ {\\small EE17B109}}\n\n\\date{\\today} % Date for the report\n\\begin{document}\t\t\n\t\t\n\\maketitle % Insert the title, author and date\n\\section{Fitting Data to Models}\n%Create new section;it is autonumbered\nThis week’s Python assignment is mainly focused on studying the effect of noise on the fitting process.\\\\\nFirstly,we generated a file fitting.dat with 10 columns with first column as time ,while the remaining columns are data\\\\\nThe data columns correspond to the function with different amounts of noise added.Here,noise random fluctuations in the value due to many small random effects.Noise is assumed to be normally distributed.\\\\\n\nEach column function with given $\\sigma$:\\\\\n\\begin{equation*}\nf(t) = 1.05J_{2}(t) - 0.105t + n(t)\n\\end{equation*}\n\nwith \\begin{equation*}\nPr(n(t)|\\sigma) = \\frac{1}{\\sigma\\sqrt{2\\pi}}exp(\\frac{-n(t)^2}{2\\sigma^2})\n\\end{equation*}\n\n\\begin{figure}[!tbh]\n   \t\\centering\n   \t\\includegraphics[scale=0.4]{q4_plot.png}  % Mention the image name within the curly braces. Image should be in the same folder as the tex file. \n   \t\\caption{Plot of data to be fitted}\n   \t\\label{fig:Data plot}\n   \\end{figure} \n\\newpage\nHere I am plotting the error bar for one data column:\\\\\n\\begin{figure}[!tbh]\n   \t\\centering\n   \t\\includegraphics[scale=0.4]{q5_plot.png}  % Mention the image name within the curly braces. Image should be in the same folder as the tex file. \n   \t\\caption{Data points for $\\sigma$ = 0.1 along with exact function}\n   \t\\label{fig:Error bar}\n   \\end{figure}\n   \nTrue value function is plotted by defining a function:\\\\\n\\begin{equation*}\ng(t,A,B) = AJ_{2}(t)+Bt \n\\end{equation*}\nNext we assume that there exist some function which fits the noise data  with general form  $g(t,A,B) = AJ_{2}(t)+Bt$\\\\\n\\par\nNext we will find the (A,B) values by minimising the mean square error between the predicted values from given (A,B) and data column.\\\\\n\nContour Plot of $MS\\ error$ for w.r.t data column1 for range of (A,B):\n\\begin{figure}[!tbh]\n   \t\\centering\n   \t\\includegraphics[scale=0.5]{q8_plot.png}  % Mention the image name within the curly braces. Image should be in the same folder as the tex file. \n   \t\\caption{contour plot for $\\epsilon_{ij}$ }\n   \t\\label{fig:Contour plot}\n   \\end{figure}\n\nFrom the above plot we can clearly see that there exist a single minima.\n\\newpage\nUsing the Python function lstsq from scipy.linalg to obtain the best estimate of A and B for different data columns:\\\\\n\nThe following plots show the error in A and B for different data columns:\\\\\n\nIn the first plot B error is appearing to be constant but in reality it increases by a small amount.\\\\ \n\n\\begin{figure}[!tbh]\n   \t\\centering\n   \t\\includegraphics[scale=0.5]{q10_plot.png}  % Mention the image name within the curly braces. Image should be in the same folder as the tex file. \n   \t\\caption{A and B error in linear scale}\n   \t\\label{fig:A and B err in linear scale}\n   \\end{figure}\n\\begin{figure}[!tbh]\n   \t\\centering\n   \t\\includegraphics[scale=0.5]{q11_plot.png}  % Mention the image name within the curly braces. Image should be in the same folder as the tex file. \n   \t\\caption{A and B error in log scale}\n   \t\\label{fig:A and B err in log scale}\n   \\end{figure}\n\\newpage\n\nHere I am plotting mean square error of predicted points w.r.t to true points versus sigma of noise.\n\n\\begin{figure}[!tbh]\n   \t\\centering\n   \t\\includegraphics[scale=0.5]{Figure_1.png}  % Mention the image name within the curly braces. Image should be in the same folder as the tex file. \n   \t\\caption{Mean square error for predicted points}\n   \t\\label{fig:pred mean square}\n   \\end{figure}\n   \n\\textbf{Conclusion:}\nIf we calculate the mean square error for the predicted points w.r.t to the data points,In the log scale we observe that there will be a linear variation.\n\n\n \n\\end{document}\n\n\n\n \n", "meta": {"hexsha": "495ecad8039ba2fba9637034ef988d4e51994238", "size": 4145, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week3/week3_latex_rep.tex", "max_stars_repo_name": "suhas1999/EE2703", "max_stars_repo_head_hexsha": "e508f61d7af0c2445c6b30c465eca3fad455f853", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week3/week3_latex_rep.tex", "max_issues_repo_name": "suhas1999/EE2703", "max_issues_repo_head_hexsha": "e508f61d7af0c2445c6b30c465eca3fad455f853", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week3/week3_latex_rep.tex", "max_forks_repo_name": "suhas1999/EE2703", "max_forks_repo_head_hexsha": "e508f61d7af0c2445c6b30c465eca3fad455f853", "max_forks_repo_licenses": ["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.6818181818, "max_line_length": 205, "alphanum_fraction": 0.723522316, "num_tokens": 1192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6575742352555216}}
{"text": "\\documentclass[12pt, titlepage, oneside]{article}\n\n\\input{settings}\n\n\\begin{document}\n\t\n\t\\textbf{ELECENG 3TQ3}\\\\\n\t\\textbf{Elston A.}\n\t\n\\section{Lecture 4}\nWe can calculate the probability of the union between two sets in the following manner:\n\\begin{align*}\nP[A\\u B\\u C] &= P[A] + P[B \\u C] - P[A \\n (B \\u C)] \\\\\n&= P[A] + P[B] + P[C] - P[A\\u B] - P[A \\u C] - P[B \\u C] + P[A \\u B \\u C]\n\\end{align*}\n\n\\subsection{Magic Formula}\n\nSince we know the probability of $P[A|B]$ is as follows\n\\begin{align*}\nP[A|B] = \\frac{P[A \\n B]}{P[B]}\n\\end{align*}\nso if we instead want the probability of B given A, that is $P[B|A]$ then we have the following formula\n\\begin{align*}\nP[B|A] = \\frac{P[A | B]P[B]}{P[A]}\n\\end{align*}\nwhich we can replace the $P[A \\n B]$ term in the numerator by $P[A|B] P[B]$\n\\begin{align}\nP[B|A] = \\frac{P[AB]}{P[A]} = \\frac{P[A|B] P[B]}{P[A]}\n\\end{align}\n\n\\subsection{Consequences}\n\nTotal Probability of an event A when dealing with partitions is given as \n\\begin{align}\n\tP[A] = \\sum_{i=1}^m P[A|B_i]P[B_i]\n\\end{align}\nso if we use Bayes theorem\n\\begin{align}\nP[B_j | A] = \\frac{P[A|B_j] P[B_j]}{\\sum_{i=1}^m P[A|B_i]  P[B_i] }\n\\end{align}\n\n\\ex Consider tossing two different coins. Let C1 be the unfair tossing heads with a probability of 3/4 and let C2 be a fair coin tossing heads with probability 1/2. Lets assume that you randomly chose a coin and toss it. What is the probability that you selected C1 if you find out the coin toss was heads. \n\nIn this case we would be looking for the probability we selected C1 given the outcome was H \n\\begin{equation}\nP[C1|H] = \\frac{ P[H|C1]P[C1] }{P[H|C1]P[C1] + P[H|C2]P[C2]} = \\frac{P[HC1]}{P[HC1] + P[HC2]} = \\frac{3/8}{3/8+1/4} = \\frac{3}{5}\n\\end{equation}\n\n\n\\subsection{Independent Events}\n\nTwo events are independent if and only if \n\\begin{align}\nP[AB] = P[A]P[B]\n\\end{align}\nWe should note that disjoint and independent are not the same. Mutually exclusive events mean they cannot happen at the same time, that is, if A and B are mutually exclusive then $P[AB] = 0$. \n\nIndependent events are such events where observing one events does not change the outcome of the other. In other words, the conditional probability of an event does not change with the extra information about another event since they have no correlation.\n\nGiven two independent events A and B, \n\\begin{align} \nP[A|B] = P[A] \\enspace \\enspace P[B|A] = P[B]\n\\end{align}\n\n\\ex Consider rolling two fair die. Let $A$ be the event that the product of the two numbers is 12, and let $B$ be the event the sum of the two numbers is 6. Are the events independent?\n\nSince we know 6*2 = 2*6 = 4*3 = 3*4 = 12\n\\begin{align}\nP[A] = \\frac{4}{36}\n\\end{align}\nSince we know 1+5 = 5+1 = 3+3 = 2+4 = 4+2 \n\\begin{align}\nP[B] = 5/36\n\\end{align}\nSo we can see that $P[AB] = 0$ so these events are not independent, but disjoint\n\n\\subsection{Properties}\nLet A and B be independent events, then A and $B^c$ are independent as well\n\\begin{align}\nP[A\\n B^c] = P[A] - P[A \\n B] = P[A] - P[A]P[B]  = P[A](1-P[B]) = P[A]P[B^c]\n\\end{align}\n\n\\subsection{Three Events or More Events}\nConsider 3 events A, B, C. They are independent if and only if\n\\items\n\\item A and B are independent\n\\item A and C are independent \n\\item B and C are independent\n\\eitems\n\nThus we can say\n\\begin{align}\nP[A \\n B \\n C] = P[ABC] = P[A]\\n P[B]\\n P[C] = P[A]P[B]P[C]\n\\end{align}\n\\b{Generalization}\n\nFor any $n$ events where $n \\geq 3$ the sets $A_1,A_2,\\dots,A_n$ where each set is independent from the other n-1 other sets.\n\\begin{align}\nP[A_1 \\n A_2 \\n \\dots \\n A_n] = P[A_1]P[A_2]\\dots P[A_n]\n\\end{align}\nand in general\n\\begin{align}\nP[A_1\\u A_2 \\u \\dots \\u A_n] = 1-P[A_1\\n A_2 \\n \\dots \\n A_n]\n\\end{align}\n\n\\ex Consider three independent events A, B, C and assume their probabilities are 0.5, 0.3, and 0.1. What is the probability that at least one event happens\n\\begin{align}\nP[A\\u B \\u C] = 1- P[A]P[B]P[C] = 0.685\n\\end{align}\n\\subsection{Sequential Experiments}\nMany experiments are done in stages where the next stage depends on the previous one. You can think of this as branches. \n\nAs an example we have shown the sequential experiment of tossing a coin two times in a row.\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{images/toss}\n\t\\caption{Coin toss outcomes}\n\t\\label{fig:toss}\n\\end{figure}\n\nConsider tossing a coin 5 times, recording the outcomes and repeating the whole process 10 times. We can define a success trial in many different ways. This type of method is often used in drug design and research. In these cases you perform n tests and record successes as 0 or 1. You can call a trial a success if a certain number of successes are recorded.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "e83372d31f8af7a8eb882f60e99e67023d683c5f", "size": 4684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture4/lec4.tex", "max_stars_repo_name": "elston-jja/EE3TQ3", "max_stars_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture4/lec4.tex", "max_issues_repo_name": "elston-jja/EE3TQ3", "max_issues_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture4/lec4.tex", "max_forks_repo_name": "elston-jja/EE3TQ3", "max_forks_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_forks_repo_licenses": ["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.8818897638, "max_line_length": 359, "alphanum_fraction": 0.6944918873, "num_tokens": 1583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.6575742321156794}}
{"text": "\\section{Homomorphic Encryption}\\label{s:homomorphic-encryption}\n\nSome encryption schemes are inherently ``malleable\", which means that it is possible to transform a ciphertext into another ciphertext which decrypts to a related plaintext.\nHomomorphic encryption is a malleable encryption scheme that allows operations directly on encrypted data so that the results after decryption would correspond to applying matching operations on unencrypted data.\nFor example, having an encryption mechanism $Enc$, the product of any two ciphertexts is equal to a ciphertext of the sum of the two corresponding plaintexts ($M_1$ and $M_2$). Or more generally the application of a function to the ciphertexts corresponds to another function on the plaintexts, as follows:\n\\begin{equation}\\label{eq:homomorphic}\n  Enc(M_1) \\otimes Enc(M_2) = Enc(M_1 \\oplus M_2)\n\\end{equation}\n\nfor some operations $\\otimes$ and $\\oplus$.\n\nHomomorphic encryption enables outsourcing computations to a third party, as for example on the cloud.\nCloud computing is designed to deal with difficult operations and with computationally demanding algorithms.\nHowever, if user's data are unencrypted they can be exposed to attacks from both the cloud provider and third parties (hackers, government agencies, data breaches, etc.).\nEven if the data are stored \\textit{(data at rest)} and transferred \\textit{(data in transit)} securely, when they are in use they can be exposed to security risks, such as side-channel attacks \\cite{zhang2012cross} and hardware Trojans \\cite{becker2013stealthy, tsoutsos2014advanced}.\n\\textit{Data at rest} implies data that is stored physically in any digital form, while \\textit{data in transit} means data traversing the network.\nActive data under constant change which is stored in a non-persistent digital state typically in computer random access memory (RAM), CPU caches, or CPU registers are called \\textit{data in use}.\n\n\nIt is possible, to construct an entire system to work over encrypted data, manipulating and returning encrypted results.\nThis system would be based on homomorphic encryption, which allows to apply a function to the ciphertexts that corresponds to another function on the plaintexts, and in general enables computation on encrypted data.\nThe final results can then be obtained by a single decryption.\nFor instance, given $Enc(M_1)$ and $Enc(M_2)$ (the encryption of $M_1$ and $M_2$), you can compute $Enc(M_1 + M_2)$ without knowing $M_1$, $M_2$ nor the decryption key.\nThe only point in the process where data would be decrypted is when the user wants to see the result, and that would presumably happen in the application or client software, not in the database server in the cloud, rendering the host incapable of leaking any type of information.\n\n\nOne challenge that homomorphic encryption schemes, and in general every encrypted computation framework, face is the inability to make runtime decisions based on encrypted data.\nUsing homomorphic operations requires special care to ensure that branching does not reveal any sensitive data by observing side-channel information (\\textit{e.g.} the branch target).\nFor instance, the host is unable to perform operations like ``\\texttt{if (x > 0) return;}\" when \\texttt{x} is an encrypted variable.\nThis is known as the ``termination problem\", introduced in \\cite{brenner2011secret}, since performing runtime branch decisions is not possible and therefore rendering the algorithms implemented on top of those systems by design more complex.\n\n\nTo address this problem traditional algorithms must be changed to their homomorphic equivalents, a not straightforward process.\nSome work has been done in \\cite{mouris2018terminator} by developing benchmarks targeted for computer architectures based on homomorphic operations.\nThose benchmarks avoid termination problems while maintaining data privacy.\n\n\nThere is not a sole type of homomorphic encryption, different schemes have been proposed for different types of applications.\n\n\n\\subsection{Partially Homomorphic Encryption}\\label{ss:phe}\nThe most widely used type of homomorphic encryption is partially homomorphic encryption (PHE), with schemes like RSA, ElGamal, Benaloh and Paillier.\nPHE has been expanded with applications such as Helios (e-voting PHE based system) \\cite{adida2008helios}, Cryptoleq (Heterogeneous abstract machine for both encrypted and unencrypted computation based on PHE) \\cite{mazonka2016cryptoleq}, and others.\nAll those systems, perform manipulations directly on encrypted data without decrypting them, thus no information leakage is possible.\nWhen the result is eventually decrypted, it will be the same as applying the same manipulations on plaintexts.\n\nThe two most common cases (but not the only ones) of partially homomorphic cryptosystems are \\textit{additively homomorphic} and \\textit{multiplicatively homomorphic}.\n\\begin{itemize}\n  \\item Additively homomorphic systems enable computation over ciphertexts (encrypted data) that result in the encryption of the sum (addition) of two plaintexts. More formally, a cryptosystem is considered to be additively homomorphic iff:\n\n  \\begin{equation}\\label{eq:additively-homomorphic}\n    Enc(M_1) \\otimes Enc(M_2) = Enc(M_1 + M_2)\n  \\end{equation}\n\n  for some operation $ \\otimes $.\n  \\item Multiplicatively homomorphic systems enable computation over ciphertexts that decrypt to the product (multiplication) of two plaintexts. More formally, a cryptosystem is considered to be multiplicatively homomorphic iff:\n\n  \\begin{equation}\\label{eq:multiplicatively-homomorphic}\n    Enc(M_1) \\otimes Enc(M_2) = Enc(M_1 \\cdot M_2)\n  \\end{equation}\n\n  for some operation $ \\otimes $.\n\\end{itemize}\n\nBelow we describe some widely known cryptosystems that are partially homomorphic.\n\n\\subsubsection{RSA Cryptosystem}\\label{ss:rsa}\nPlain RSA encryption is multiplicatively homomorphic. Consider the encryption algorithm described in section \\ref{s:pk-rsa}. We know that $Enc(m) = {m_1}^{e}\\pmod{n}$. Given two ciphertexts $Enc(m_1)$ and $Enc(m_2)$ of plaintexts $m_1$ and $m_2$ respectively,  we can see that the following holds.\n\n\\begin{equation}\n  \\label{eq:homomorphic-rsa}\n  \\begin{gathered}\nEnc(m_1) \\cdot Enc(m_2) = {m_1}^{e}\\pmod{n} \\cdot {m_2}^{e}\\pmod{n} =\\\\ ({m_1}\\cdot{m_2})^{e}\\pmod{n} = Enc({m_1}\\cdot{m_2})\n  \\end{gathered}\n\\end{equation}\n\n\nSo the product of the two ciphertexts corresponds to the ciphertext of the product of the two plaintexts.\n\n\\subsubsection{ElGamal Cryptosystem}\\label{ss:elgamal}\nThe ElGamal cryptosystem is also multiplicative homomorphic. Based on the algorithm described in \\ref{s:pk-elgamal} we know that $Enc(m) = (G,M) = (g^{r} \\pmod{p}, m$, for some random $r \\in_{R} \\mathbb{Z}_{q}$. Consider we have two ciphertexts $Enc(m_1)$ and $Enc(m_2)$ of plaintexts $m_1$ and $m_2$, respectively. We can see that the following holds.\n\n\\begin{equation}\n  \\label{eq:homomorphic-elgamal}\n  \\begin{gathered}\nEnc(m_1) \\cdot Enc(m_2) = (G1, M1) \\cdot (G2, M2) =\\\\ (g^{r_1} \\pmod{p}, m_1 \\cdot y^{r_1} \\pmod{p}) \\cdot (g^{r_2} \\pmod{p}, m_2 \\cdot y^{r_2} \\pmod{p}) =\\\\ (g^{r_1+r_2} \\pmod{p}, (m_1 \\cdot m_2) \\cdot y^{r_1+r_2} \\pmod{p}) = Enc({m_1} \\cdot {m_2})\n  \\end{gathered}\n\\end{equation}\n\nWe can see again that the product of the encryptions of two plaintexts results to the encryption of the encryption of the product of the two plaintexts.\n\n\\subsubsection{Paillier Cryptosystem}\\label{ss:paillier}\nThe Paillier cryptosystem is additively homomorphic. According to \\ref{s:pk-paillier}, we know that $Enc(m) = g^{m} \\cdot r^n \\pmod{n^2}$, for some random $ r \\in_{R} \\mathbb{Z}_{n}^{*}$ . Given two ciphertexts $Enc(m_1)$ and $Enc(m_2)$ of plaintexts $m_1$ and $m_2$ respectively, we can see that the following holds.\n\n\\begin{equation}\n  \\label{eq:homomorphic-paillier}\n  \\begin{gathered}\nEnc(m_1) \\cdot Enc(m_2) = (g^{m_1} \\cdot {r_1}^n \\pmod{n^2}) \\cdot (g^{m_2} \\cdot {r_2}^n \\pmod{n^2}) =\\\\ (g^{m_1} \\cdot {r_1}^n) \\cdot (g^{m_2} \\cdot {r_2}^n)\\pmod{n^2} = g^{m_1 + m_2} \\cdot (r_1 \\cdot r_2) \\pmod{n^2} =\\\\ Enc({m_1} + {m_2})\n  \\end{gathered}\n\\end{equation}\n\nWe can see that the product of the two ciphertexts will decrypt to the sum of their corresponding plaintexts.\n\n\\subsection{Fully Homomorphic Encryption}\\label{ss:fhe}\nAnother form of homomorphic encryption is Fully homomorphic encryption (FHE), first invented by Gentry in \\cite{gentry2009fully}.\nDue to the fact that FHE enables \\textit{arbitrary computation} on ciphertexts, is far more powerful than PHE (which was just called Homomorphic Encryption before FHE systems were discovered) and its appearance sparked the academic interest.\nConsecutively a lot of FHE schemes arise, but unfortunately they come along with a huge performance overhead.\nThis overhead has been a concern and this is the reason that there are not many applications that leverage FHE, despite the wide range of that can benefit from FHE schemes.\nSome implementations are the HElib \\cite{halevi2014algorithms} and the TFHE \\cite{chillotti2016faster}.\n\n\n", "meta": {"hexsha": "fa4a1f88627d84d07dc7f874acb4caf5cd8e925a", "size": 9011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homomorphic-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": "homomorphic-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": "homomorphic-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": 80.4553571429, "max_line_length": 352, "alphanum_fraction": 0.7758295417, "num_tokens": 2400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6575742248623885}}
{"text": "\\documentclass{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{amsthm}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem*{problem}{Problem}\n\n\\begin{document}\n\\title{Finding Formulae for Power Sums}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{Introduction}\n\nOne of the first formulae you learn when starting to study sequences and series is the\nformula for the sum of the first $n$ positive integers. This \nseries has been made famous by an anecdote that when Gauss was a school boy, his\nteacher, wanting to keep the class busy for a few minutes while they stepped out,\ntold the class to calculate the sum of the positive whole numbers to 100. Before he\nhad reached the door, a young Gauss had shouted out the answer.\n\nThe \"trick\" that Gauss used was to realize that by inverting the order of the series\nand aligning terms, then adding the two lines, he could simplify things:\n\n\\begin{alignat*}{6}\n\tS &=& 1   &+& 2  &+& \\cdots &+& 99 &+& 100 \\\\\n\t S &=& 100 &+& 99 &+& \\cdots &+& 2  &+& 1 \\\\\n\t2S &=& 101 &+& 101 &+& \\cdots &+& 101 &+& 101 \\\\\n\\end{alignat*}\n\nIn other words, $2S = 100(101), S=5050$, and in general, $S(n) = \\frac{(n)(n+1)}{2}$.\n\nThe challenge of deriving a closed formula for the powers of integers is an\ninteresting one, which has resulted in some beautiful mathematics. I will present\none way to prove a given formula using induction, and three different ways to derive\nthe formula for:\n\n\\[ S_k(n) = \\sum_{i=1}^{n} i^k \\]\n\nThese three methods will use the Binomial theorem, a combinatorical identity, and\nexponential generating functions.\n\n\\section{Proof by induction}\n\nCan we prove, given a formula for $S_k(n)$, that it is true for all $n$? One method\nto do so is to use induction. The inductive principle says that if something is true\nof the first member of a list, and whenever it is true of a member of the list,\nit is also true for the next member of the list, then it is true for every member.\n\nThe inductive step starts with the assumption that the condition is true for the\n$n^\\text{th}$ element of the list, and then starting from that assumption, proving\nthat the condition must also be true for the next. This can be a little confusing at\nfirst, so let's see it in action.\n\n\\begin{problem} Prove that for all $n \\in \\mathbb{N}$:\n\t\\[ \\sum_{i=1}^{n} i^2 = \\frac{(n)(n+1)(2n+1)}{6} \\]\n\\end{problem}\n\n\\begin{proof}\n\tIf $n = 1$, then $1^2 = \\frac{(1)(2)(3)}{6} = 1$, so for the base case, the formula is valid.\n\n\tNow assume it is true for $n=k$ -- that is:\n\t\\[ \\sum_{i=1}^{k} i^2 = \\frac{(k)(k+1)(2k+1)}{6} \\]\n\n\tThen for $n=k+1$:\n\t\\begin{align*}\n\t\t\\sum_{i=1}^{k+1} i^2 &= \\sum_{i=1}^{k} i^2 + (k+1)^2 \\\\\n\t\t &= \\frac{(k)(k+1)(2k+1)}{6} + (k+1)^2 \\\\\n\t\t &= \\left(k+1\\right)\\left(\\frac{(k)(2k+1) + 6(k+1)}{6}\\right) \\\\\n\t\t &= \\left(k+1\\right)\\left(\\frac{2k^2 +7k +6}{6}\\right) \\\\\n\t\t &= \\left(k+1\\right)\\left(\\frac{(k+2)(2k+3)}{6}\\right) \\\\\n\t\t &= \\frac{(k+1)((k+1)+1)(2(k+1)+1)}{6}\n\t\\end{align*}\n\t\n\tThis is the same formula as before, with $(k+1)$ in the place of $k$. We have\n\tshown that if the formula is valid for $n=k$, then it must also be valid for\n\t$n=k+1$. Since we have shown that the formula is valid for $n=1$, then it must also\n\tbe true for 2, and therefore also for 3, and, by induction, it is true for all\n\t$n \\in \\mathbb{N}$.\n\\end{proof}\n\n\\section{Binomial expansion}\n\nThe Binomial theorem states that:\n\\[ (x + y)^n = \\sum_{i=0}^{n} \\binom{n}{i}x^{n-i}y^{i} \\]\nwhere $\\binom{n}{i} = \\frac{(n)(n-1)(\\cdots)(n-i+1)}{i!}$ for \n$n \\in \\mathbb{R}, i \\in \\mathbb{N}_0$, and $i! = i\\times(i-1)\\times (i-2)\\times \\cdots \n\\times 2 \\times 1$ is the factorial function. For positive integer values of $n$, we can\nwrite $\\binom{n}{k} = \\frac{n!}{k!(n-k)!}$.\n\nFor example:\n\\begin{align*}\n\t(x+y)^5 &= \\binom{5}{0}x^5 + \\binom{5}{1}x^4y + \\binom{5}{2}x^3y^2 + \n\t\\binom{5}{3}x^2y^3 + \\binom{5}{4}xy^4 + \\binom{5}{5}y^5 \\\\\n\t &= x^5 + 5x^4y + 10x^3y^2 + 10x^2y^3 + 5xy^4 + y^5\n\\end{align*}\n\nUnsurprisingly, since $(x+y)^n = (y+x)^n$, the binomial coefficients are symmetrical.\nThat is, $\\binom{n}{k} = \\binom{n}{n-k}$.\n\nTo find a formula for the sum of the squares of the sequence of integers, we will use the\nBinomial expansion of the next power up. That is:\n\\[(n+1)^3 = n^3 + 3n^2 + 3n + 1 \\]\n\nThis gives us an expression for the difference between consecutive cubes, which we can add for\nall integers less than $n$:\n\n\\begin{alignat*}{5}\n\t(n+1)^3 &-& n^3     &=& 3n^2     &+& 3n     &+& 1 \\\\\n\tn^3     &-& (n-1)^3 &=& 3(n-1)^2 &+& 3(n-1) &+& 1 \\\\\n\t      &\\vdots&      &=&       &\\vdots&  &\\vdots& \\\\\n\t3^3     &-& 2^3     &=& 3(2^2)   &+& 3(2) &+& 1 \\\\\n\t2^3     &-& 1^3     &=& 3(1^2)   &+& 3(1) &+& 1 \\\\\n\\end{alignat*}\n\nNow if we add the left-hand side, we see that a number of terms cancel out, and we can replace\n$\\sum_{i=1}^{n} i$ with the formula we derived earlier to get a closed formula for\n$\\sum_{i=1}^{n} i^2$.\n\n\\begin{align*}\n\t3\\sum_{i=1}^{n} i^2 + 3\\sum_{i=1}^{n} i + n &= (n+1)^3 - 1^3 \\\\\n\t3\\sum_{i=1}^{n} i^2 &= n^3 +3n^2+3n - \\frac{3(n)(n+1)}{2} - n \\\\\n\t3\\sum_{i=1}^{n} i^2 &= \\frac{1}{2}\\left(2n^3 +6n^2+6n - 3n^2 -3n - 2n\\right) \\\\\n\t\\sum_{i=1}^{n} i^2  &= \\frac{1}{6}\\left(2n^3 +3n^2+n\\right) \\\\\n\t\\sum_{i=1}^{n} i^2  &= \\frac{1}{6}\\left((n)(n+1)(2n+1)\\right) \n\\end{align*} \n\nWe can use this method for higher exponents $k$ and, as long as we have formulae for all \nof the lower exponents, we can always generate an explicit formula using this method for\n$\\sum_{i=1}^{n} i^k$.\n\n\\section{Using a Binomial identity}\n\n\\subsection{Pascal's Triangle}\n\nThe second method is closely related to the first, but avoids the requirement to derive\na formula for all of the lower order exponents. We will use a binomial identity which\nwe can derive from the well-known property of binomial coefficients which gives us\nPascal's triangle, namely:\n\\[\\binom{n}{k} + \\binom{n}{k+1} = \\binom{n+1}{k+1} \\]\n\nWe can prove this identity as follows:\n\n\\begin{align*}\n\t\\binom{n}{k} + \\binom{n}{k+1} &= \\frac{n!}{k!(n-k)!} + \\frac{n!}{(k+1)!(n-k-1)!} \\\\\n\t&= \\frac{n!}{k!(n-k-1)!}\\left(\\frac{1}{n-k} + \\frac{1}{k+1}\\right) \\\\\n\t&= \\frac{n!}{k!(n-k-1)!}\\left(\\frac{(k+1)+(n-k)}{(n-k)(k+1)}\\right) \\\\\n\t&= \\frac{(n+1)!}{(k+1)!((n+1)-(k+1))!} \\\\\n\t&= \\binom{n+1}{k+1}\n\\end{align*}\n\nFor those who have not heard of it, Pascal's Triangle is an arrangement of the\nbinomial coefficients in a triangle, and each term in the triangle is the sum of the two\nterms directly above it. The first five rows are as follows:\n\n\\begin{tabular}{rccccccccc}\n$n=0$:&    &    &    &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n$n=1$:&    &    &    &  1 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n$n=2$:&    &    &  1 &    &  2 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n$n=3$:&    &  1 &    &  3 &    &  3 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n$n=4$:&  1 &    &  4 &    &  6 &    &  4 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n\\end{tabular}\n\nEach line represents the coefficients of a binomial expansion. For example, the line $n=3$\ncorresponds to $\\binom{3}{0}, \\binom{3}{1}, \\binom{3}{2}, \\binom{3}{3}$.\n\nBy examining Pascal's Triangle (or repeatedly applying the identity above), you can generate\nsome interesting identities. The one we are interested in is:\n\\[ \\sum_{i=1}^{n} \\binom{i}{k} = \\binom{n+1}{k+1} \\]\n\nThis does require some clarification for the value of $\\binom{n}{k}$ when $k>n$. In this case, we use the formula for the binomial coefficient we introduced originally:\n\\[ \\binom{n}{k} = \\frac{(n)(n-1)(\\cdots)(n-k+1)}{k!} \\]\n\nFor $n<k$ this will yield $\\binom{n}{k} = 0$ - and in the context of an interpretation of\nthis meaning the number of ways we can \"choose $k$ items from $n$ options\", this makes sense, as it is impossible to choose $k$ items from fewer than $k$ choices.\n\nThis identity corresponds to adding up all of the numbers on the diagonal one over from the\nnumber of interest in Pascal's Triangle. For example:\n\\[ \\binom{5}{3} = \\binom{4}{2} + \\binom{3}{2} + \\binom{2}{2} = 6 + 3 + 1 \\]\n\nWe can justify this by repeatedly applying the binomial identity:\n\\begin{align*}\n\t\\binom{n+1}{k+1} &= \\binom{n}{k} + \\binom{n}{k+1} \\\\\n\t&= \\binom{n}{k} + \\binom{n-1}{k} + \\binom{n-1}{k+1} \\\\\n\t&= \\binom{n}{k} + \\binom{n-1}{k} + \\binom{n-2}{k} + \\binom{n-2}{k+1} \\\\\n\t&\\vdots \\\\\n\t&= \\sum_{i=1}^{n} \\binom{i}{k} \n\\end{align*}\n\n\\subsection{Applying the Identity}\n\n$\\binom{n}{k}$ is a polynomial in $n$ of order $k$. For example:\n\\[ \\binom{n}{3} = \\frac{1}{6}(n)(n-1)(n-2) = \\frac{1}{6}(n^3-3n^2+2n) \\]\n\nWe can express $n^k$ as a linear combination of $\\binom{n}{i}$ for $i\\leq k$. For $n=3$,\nto continue with that example, we have that:\n\\begin{align*}\n\tn^3 &= 6\\binom{n}{3} +3n^2-2n \\\\\n\t&= 6\\binom{n}{3} + 6 \\binom{n}{2} +\\binom{n}{1}\n\\end{align*}\n\nIn this case, we can now apply this identity along with the one above to get a formula\nfor the sum of cubes:\n\n\\begin{align*}\n\t\\sum_{i=1}^{n} i^3 &= 6\\sum_{i=1}^{n} \\binom{i}{3} + 6\\sum_{i=1}^{n} \\binom{i}{2}\n\t+ \\sum_{i=1}^{n} \\binom{i}{1} \\\\\n\t&= 6\\binom{n+1}{4} +6\\binom{n+1}{3} + \\binom{n+1}{2} \\\\\n\t&= 6\\frac{(n+1)(n)(n-1)(n-2)}{24} +6 \\frac{(n+1)(n)(n-1)}{6} + \\frac{(n+1)(n)}{2} \\\\\n\t&= (n+1)(n) \\frac{(n-1)(n-2) + 4(n-1) + 2}{4} \\\\\n\t&= \\left(\\frac{n(n+1)}{2}\\right)^2\n\\end{align*}\n\nAgain, we can use this method for arbitrary values of $k$.\n\nIt is straightforward to calculate the values of the coefficients of $\\binom{n}{i}$ in\nthe linear combination when we realize that the equation must be true for all values of\n$n$, and (as we saw earlier) $\\binom{n}{k} = 0$ if $n<k$. So for example, if we wanted to \ncalculate the sum $\\sum_{i=1}^{n} i^4$, we could use:\n\\[ n^4 = a_1\\binom{n}{1} + a_2\\binom{n}{2} + a_3 \\binom{n}{3} + a_4 \\binom{n}{4} \\]\nSetting $n=1$, we get the equation:\n\\[ 1^4 = a_1\\binom{1}{1} \\implies a_1 = 1 \\]\n\nNow setting $n=2$:\n\\[ 2^4 = a_1\\binom{2}{1} + a_2\\binom{2}{2} \\implies a_2 = 16-2 = 14 \\]\n\nWith $n=3$:\n\\[ 3^4 = a_1\\binom{3}{1} + a_2\\binom{3}{2} + a_3\\binom{3}{3}\\]\n\\[\\implies a_3 = 81 -3(14) - 3(1)  = 36 \\]\n\nFinally, for $n=4$:\n\\[ 4^4 = a_1\\binom{4}{1} + a_2\\binom{4}{2} + a_3\\binom{4}{3} + a_4\\binom{4}{4}\\]\n\\[\\implies a_3 = 256 -4(36) - 6(14) - 4(1))  = 24\\]\n\nSo we have:\n\\[ n^4 = \\binom{n}{1} + 14\\binom{n}{2} + 36 \\binom{n}{3} + 24 \\binom{n}{4} \\]\n\nAnd:\n\\begin{align*}\n\t\\sum_{i=1}^{n} i^4 &= \\binom{n+1}{2} + 14\\binom{n+1}{3} + 36 \\binom{n+1}{4}\n\t                      + 24 \\binom{n+1}{5} \\\\\n\t\t\t   &= \\frac{1}{30} (n)(n + 1)(2n + 1)(3n^2 +3n - 1)\n\\end{align*}\n\n\\section{Exponential Generating Functions}\n\nI think my favourite method for deriving these formulae is to use generating functions.\nThis feels the most like magic, and it has a deep connection to the Bernoulli numbers,\nwhich arise often in number theory.\n\nA Generating Function is a polynomial representation of a sequence $\\{a_n\\}$ such that\n$a_i$ is the coefficient of $x^i$ for each $i \\geq 0$. For example, the sequence \n$\\{1, \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{8}, \\cdots \\}$ corresponds to the polynomial\n\\[ P(x) = 1 + \\frac{x}{2} + \\frac{x^2}{4} + \\frac{x^3}{8} + \\cdots \\]\n\nWe have a lot of tools for manipulating generating functions, as long as they satisfy\ncertain constraints. For example, we can take term-wise derivatives or integrals of\nthe terms to generate new identities or to calculate complicated infinite sums.\n\nIn the case of $P(x)$, you might recognize it as a geometric series. If it is convergent,\nwe can manipulate it as follows:\n\n\\[ \\frac{x}{2} P(x) = \\frac{x}{2} + \\frac{x^2}{4} + \\frac{x^3}{8} + \\cdots \\]\n\\[ P(x) - \\frac{x}{2} P(x) = 1 \\]\n\\[ P(x) = \\frac{1}{1-\\frac{x}{2}} \\]\n\nAn exponential generating function is similar, but with one difference. Given the sequence\n$\\{a_n\\}$, the generating function is:\n\\[ P(x) = a_0 + \\frac{a_1x}{1!} + \\frac{a_2x^2}{2!} + \\frac{a_3x^3}{3!} + \\cdots \\]\n\nThat is, each term is of the form $\\frac{a_nx^n}{n!}$. What this gains us is that we are\nguaranteed convergence for any sequence which does not grow exponentially. It also gives\nus the ability to manipulate sequences using exponential rules.\n\nWe can use exponential power series to generate formulae for the sum of $i^k$ for all\nvalues of $k$ simultaneously. Define\n\\[ S_k(n) = \\sum_{i=1}^{n} i^k \\]\n\nand consider the corresponding exponential generating function:\n\n\\begin{align*}\n\tP(x) &= S_0(n) + \\frac{S_1(n)x^1}{1!} + \\frac{S_2(n)x^2}{2!} + \\cdots \n\t&  & \\text{By definintion} \\\\\n\t&= \\sum_{i=0}^{\\infty} \\frac{S_i(n)x^i}{i!} &  & \\text{Using summation notation} \\\\\n\t&= \\sum_{i=0}^{n} \\sum_{j=1}^{\\infty} \\frac{j^ix^i}{i!} &  & \n\t\\text{Breaking apart and distributing } S_i(n) \\\\\n\t&= \\sum_{j=1}^{n} \\sum_{i=0}^{\\infty} \\frac{j^ix^i}{i!} &  & \n\t\\text{Swapping order of summation} \\\\\n\t&= \\sum_{j=1}^{n} e^{jx} &  & \\text{Definition of the exponential function} \\\\\n\t&= \\frac{e^{i(n+1)x}-e^x}{e^{x}-1} &  & \\text{Summing a geometric series}\n\\end{align*}\n\nExpanding $e^x$ and $e^{(n+1)x}$, grouping and cross-multiplying, we get:\n\n\\[ \\left( \\sum_{i=1}^{\\infty} \\frac{x^i}{i!} \\right) \n\t\\left( \\sum_{i=0}^{\\infty} \\frac{S_i(n)x^i}{i!}\\right) = \n\t\\sum_{i=1}^{\\infty} \\frac{((n+1)^i - 1)x^i}{i!} \\]\n\n\\begin{multline*}\n\t\\left( x+\\frac{1}{2!}x^2 + \\frac{1}{3!}x^3 + \\cdots \\right)\n\t\\left( S_0(n) + \\frac{S_1(n)}{1!}x + \\frac{S_2(n)}{2!}x^2 + \\cdots \\right) = \\\\\n\t\\left( ((n+1) - 1)x+\\frac{((n+1)^2-1)}{2!}x^2 + \\frac{(n+1)^3-1)}{3!}x^3 + \\cdots \\right)\n\\end{multline*}\n\nBy equating the coefficients of $x^{i+1}$ on each side of this equation, we obtain a formula\nfor $S_i(n)$.\n\n\\begin{align*}\n\tS_0(n) &= n \\\\\n\tS_1(n) + \\frac{S_0(n)}{2!} &= \\frac{1}{2!}((n+1)^2 -1) \\\\\n\t\\frac{S_2(n)}{2!} + \\frac{S_1(n)}{2!} + \\frac{S_0(n)}{3!} \n\t&= \\frac{1}{3!}\\left( (n+1)^3 - 1 \\right) \\\\\n\t\\frac{S_3(n)}{3!} + \\frac{S_2(n)}{2!2!} + \\frac{S_1(n)}{3!} + \\frac{S_0(n)}{4!} \n\t&= \\frac{1}{4!}\\left( (n+1)^4 - 1 \\right) \\\\\n\\end{align*}\n\nThis gives the familiar formulae for $S_i(n)$, and the ability to further expand to\ncalculate $S_4(n)$ and beyond with a recursion formula.\n\n\\begin{align*}\n\tS_1(n) &= \\frac{1}{2}n^2 + \\frac{1}{2}n \\\\\n\tS_2(n) &= \\frac{1}{3}n^3 + \\frac{1}{2}n^2 + \\frac{1}{6}n \\\\\n\tS_3(n) &= \\frac{1}{4}n^4 + \\frac{1}{2}n^3 + \\frac{1}{4}n^2 \\\\\n\tS_4(n) &= \\frac{1}{5}n^5 + \\frac{1}{2}n^4 + \\frac{1}{3}n^3 - \\frac{1}{30}n \n\\end{align*}\n\nIn general:\n\n\\[ \\sum_{i=0}^{k} \\frac{S_i(n)}{(k - i + 1)!i!} = \\frac{(n+1)^{k+1} - 1}{(k+1)!} \\]\n\n\n\\end{document}\n", "meta": {"hexsha": "3e200255697a324c5b7f9629b3124f8ec8eb714e", "size": 14254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "power_sums.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": "power_sums.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": "power_sums.tex", "max_forks_repo_name": "dneary/math", "max_forks_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.296735905, "max_line_length": 168, "alphanum_fraction": 0.6137926196, "num_tokens": 5726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.6575742202718878}}
{"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{Finding The Lower Bound}\n\nLet's say we have the hypothesis sets $\\mathcal{H}_1$ and $\\mathcal{H}_2$,\nwith VC dimensions $d_{vc}(\\mathcal{H}_1)=2$ and $d_{vc}(\\mathcal{H}_2)=3$.\nThis means that $\\mathcal{H}_1$ shatters at most $2$ points, and\n$\\mathcal{H}_2$ shatters at most $3$ points.\n\nIf we join these two hypothesis sets in a single $\\mathcal{H}$, we are\nguaranteed to shatter at least $3$ points. So, the lower bound is the\nmaximum number of points that can be shattered by any $\\mathcal{H}_k$.\n\n\\section{Finding The Upper Bound}\n\nWe are given two upper bound candidates, $\\sum_{k=1}^Kd_{vc}(\\mathcal{H}_k)$\nor $K-1+\\sum_{k=1}^Kd_{vc}(\\mathcal{H}_k)$.\n\n\\subsection {Intuition on $\\sum_{k=1}^Kd_{vc}(\\mathcal{H}_k)$}\n\nLet's start with two hypothesis sets with break point $k=2$ and $N=2$. This\nmeans that these hypothesis sets cannot shatter any combination of 2 points,\nwhich implies that $d_{vc}=1$ for both of them.\n\nThese are the dichotomies realized by $\\mathcal{H}_1$ on these 2 points:\n\n\\begin{equation*}\n\\begin{split}\n\\{a=-1, b=+1\\} \\\\\n\\{a=+1, b=-1\\}\n\\end{split}\n\\end{equation*}\n\nFor $\\mathcal{H}_2$:\n\n\\begin{equation*}\n\\begin{split}\n\\{a=-1, b=-1\\} \\\\\n\\{a=+1, b=+1\\}\n\\end{split}\n\\end{equation*}\n\nThe union hypothesis set $\\mathcal{H}_1\\bigcup\\mathcal{H}_2$ have $d_{vc}=2$,\nso the option where the upper bound is the sum of $d_{vc}$ over all\n$\\mathcal{H}_k$ seems a reasonable choice, at least for these two hypothesis\nsets.\n\n\\subsection{Intuition on $K-1+\\sum_{k=1}^Kd_{vc}(\\mathcal{H}_k)$}\n\nNow let's take $N=3$ points and two new hypothesis sets,\n$\\mathcal{H}_3$ and $\\mathcal{H}_4$. What if we could divide all eight\ndichotomies carefully between these two hypothesis sets so that both\nhypothesis sets have $d_{vc}=1$?\n\nAfter moving the dichotomies around, this is $\\mathcal{H}_3$:\n\n\\begin{equation*}\n\\begin{split}\n\\{a=-1, b=-1, c=-1\\} \\\\\n\\{a=-1, b=-1, c=+1\\} \\\\\n\\{a=-1, b=+1, c=-1\\} \\\\\n\\{a=+1, b=-1, c=-1\\}\n\\end{split}\n\\end{equation*}\n\nThis is $\\mathcal{H}_4$:\n\n\\begin{equation*}\n\\begin{split}\n\\{a=-1, b=+1, c=+1\\} \\\\\n\\{a=+1, b=-1, c=+1\\} \\\\\n\\{a=+1, b=+1, c=-1\\} \\\\\n\\{a=+1, b=+1, c=+1\\}\n\\end{split}\n\\end{equation*}\n\nNoticed something? Well, both hypothesis sets $\\mathcal{H}_3$ and\n$\\mathcal{H}_4$ have $d_{vc}=1$, but the union hypothesis set\n$\\mathcal{H}_3\\bigcup\\mathcal{H}_4$ have $d_{vc}=3$. Also, since in this\nexample $K=2$, the bound seems to hold.\n\n\\subsubsection{Relation With $B(N,k)$}\n\nThe analysis definitely has to do with $B(N, k)$, although I don't know how\nto prove it yet.\n\n\\section{Solution}\n\n$$\n\\max\\{d_{vc}(\\mathcal{H}_k)\\}_{k=1}^K \\leq d_{vc}(\\bigcup _{k=1}^K)\\mathcal{H}_k \\leq K-1+\\sum_{k=1}^Kd_{vc}(\\mathcal{H}_k)\n$$\n\n\\end{document}\n", "meta": {"hexsha": "01c1858cca218698ee1b4e7e3d0d4fd31e99b95c", "size": 3001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-04/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-04/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-04/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": 28.046728972, "max_line_length": 123, "alphanum_fraction": 0.6767744085, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.6575509417720026}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n%\\begin{appendices}\n\n\\appendixpage\n\\noappendicestocpagenum\n\\addappheadtotoc\n\n\\chapter{Tables}\n\\label{appendix:tables}\n\n\\epigraph{A surprise, to be sure, but a welcome one.}{Senator Palpatine}\n\n% todo fix\n%\\dosecttoc\n%\\faketableofcontents\n%\\secttoc\n\\minitoc\n%\\startcontents[sections]\n%\\printcontents[sections]{l}{1}{\\setcounter{tocdepth}{2}}\n\nWe list helpful tables here.\n\n\\section{Logical Equivalences}\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{lc}\n\t\t\\toprule\n\t\tCommutativity & \\(\\begin{aligned} p \\land q &\\equiv q \\land p \\\\ p \\lor q &\\equiv q \\lor p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tAssociativity & \\(\\begin{aligned} (p \\land q) \\land r &\\equiv p \\land (q \\land r) \\\\ (p \\lor q) \\lor r &\\equiv p \\lor (q \\lor r) \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tDistributivity & \\(\\begin{aligned} p \\land (q \\lor r) &\\equiv (p \\land q) \\lor (p \\land r) \\\\ p \\lor (q \\land r) &\\equiv (p \\lor q) \\land (p \\lor r) \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tIdentity & \\(\\begin{aligned} p \\land \\taut &\\equiv p \\\\ p \\lor \\cont &\\equiv p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tNegation & \\(\\begin{aligned} p \\land \\lnot p &\\equiv \\cont \\\\ p \\lor \\lnot p &\\equiv \\taut \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tDouble Negation & \\(\\begin{aligned} \\lnot (\\lnot p) &\\equiv p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tIdempotency & \\(\\begin{aligned} p \\land p &\\equiv p \\\\ p \\lor p &\\equiv p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tUniversal Bound & \\(\\begin{aligned} p \\lor \\taut &\\equiv \\taut \\\\ p \\land \\cont &\\equiv \\cont \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tDe Morgan's & \\(\\begin{aligned} \\lnot (p \\lor q) &\\equiv \\lnot p \\land \\lnot q \\\\ \\lnot (p \\land q) &\\equiv \\lnot p \\lor \\lnot q \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tAbsorption & \\(\\begin{aligned} p \\lor (p \\land q) &\\equiv p \\\\ p \\land (p \\lor q) &\\equiv p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tNegation of \\(\\taut\\) and \\(\\cont\\) & \\(\\begin{aligned} \\lnot \\taut &\\equiv \\cont \\\\ \\lnot \\cont &\\equiv \\taut \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tImplication Equivalence & \\(\\begin{aligned} p \\Rightarrow q &\\equiv \\lnot p \\lor q \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tBi-conditional Equivalence & \\(\\begin{aligned} p \\Leftrightarrow q &\\equiv (p \\Rightarrow q) \\land (q \\Rightarrow p) \\end{aligned}\\) \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\\pagebreak\n\n\\section{Rules of Inference}\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{lrr}\n\t\t\\toprule\n\t\tModus Ponens & & \\(\\begin{aligned} p \\\\ p \\Rightarrow q \\\\ \\therefore q \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tModus Tollens & & \\(\\begin{aligned} p \\Rightarrow q \\\\ \\lnot q \\\\ \\therefore \\lnot p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tGeneralization & \\(\\begin{aligned} p \\\\ \\therefore p \\lor q \\end{aligned}\\) & \\(\\begin{aligned} q \\\\ \\therefore p \\lor q \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tSpecialization & \\(\\begin{aligned} p \\land q \\\\ \\therefore p \\end{aligned}\\) & \\(\\begin{aligned} p \\land q \\\\ \\therefore q \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tConjunction & & \\(\\begin{aligned} p \\\\ q \\\\ \\therefore p \\land q \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tElimination & \\(\\begin{aligned} p \\lor q \\\\ \\lnot p \\\\ \\therefore q \\end{aligned}\\) & \\(\\begin{aligned} p \\lor q \\\\ \\lnot q \\\\ \\therefore p \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tTransitivity & & \\(\\begin{aligned} p \\Rightarrow q \\\\ q \\Rightarrow r \\\\ \\therefore p \\Rightarrow r \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tCases & & \\(\\begin{aligned} p \\lor q \\\\ p \\Rightarrow r \\\\ q \\Rightarrow r \\\\ \\therefore r \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tContradiction & & \\(\\begin{aligned} \\lnot p \\Rightarrow \\cont \\\\ \\therefore p \\end{aligned}\\) \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\\pagebreak\n\n\\section{Set Equivalences}\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{lc}\n\t\t\\toprule\n\t\tCommutativity & \\(\\begin{aligned} A \\cup B &= B \\cup A \\\\ A \\cap B &= B \\cap A \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tAssociativity & \\(\\begin{aligned} (A \\cup B) \\cup C &= A \\cup (B \\cup C) \\\\ (A \\cap B) \\cap C &= A \\cap (B \\cap C) \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tDistributivity & \\(\\begin{aligned} A \\cap (B \\cup C) &= (A \\cap B) \\cup (A \\cap C) \\\\ A \\cup (B \\cap C) &= (A \\cup B) \\cap (A \\cup C) \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tIdentity & \\(\\begin{aligned} A \\cup \\emptyset &= A \\\\ A \\cap U &= A \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tInverse & \\(\\begin{aligned} A \\cup A^{\\mathsf{c}} &= U \\\\ A \\cap A^{\\mathsf{c}} &= \\emptyset \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tDouble Compliment & \\(\\begin{aligned} (A^{\\mathsf{c}})^{\\mathsf{c}} &= A \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tIdempotency & \\(\\begin{aligned} A \\cup A &= A \\\\ A \\cap A &= A \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tUniversal Bound (Domination) & \\(\\begin{aligned} A \\cup U &= U \\\\ A \\cap \\emptyset &= \\emptyset \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tDe Morgan's & \\(\\begin{aligned} (A \\cup B)^{\\mathsf{c}} &= A^{\\mathsf{c}} \\cap B^{\\mathsf{c}} \\\\ (A \\cap B)^{\\mathsf{c}} &= A^{\\mathsf{c}} \\cup B^{\\mathsf{c}} \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tAbsorption & \\(\\begin{aligned} A \\cup (A \\cap B) &= A \\\\ A \\cap (A \\cup B) &= A \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tAbsolute Compliment & \\(\\begin{aligned} \\emptyset^{\\mathsf{c}} &= U \\\\ U^{\\mathsf{c}} &= \\emptyset \\end{aligned}\\) \\\\\n\t\t\\midrule\n\t\tSet Subtraction Equality & \\(\\begin{aligned} A - B &= A \\cap B^{\\mathsf{c}} \\end{aligned}\\) \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\\pagebreak\n\n\\section{Common Growth-rates}\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{ll}\n\t\t\\toprule\n\t\tConstant & \\(\\Theta(1)\\) \\\\\n\t\t\\midrule\n\t\tLogarithmic & \\(\\Theta(\\log(n))\\) \\\\\n\t\t\\midrule\n\t\tLinear & \\(\\Theta(n)\\) \\\\\n\t\t\\midrule\n\t\t-- & \\(\\Theta(n\\log(n))\\) \\\\\n\t\t\\midrule\n\t\tQuadratic & \\(\\Theta(n^2)\\) \\\\\n\t\t\\midrule\n\t\t-- & \\(\\Theta(n^2\\log(n))\\) \\\\\n\t\t\\midrule\n\t\tPolynomial & \\(\\Theta(n^c)\\) \\\\\n\t\t\\midrule\n\t\t-- & \\(\\Theta(2^n)\\) \\\\\n\t\t\\midrule\n\t\tExponential & \\(\\Theta(c^n)\\) \\\\\n\t\t\\midrule\n\t\tFactorial & \\(\\Theta(n!)\\) \\\\\n\t\t\\midrule\n\t\t-- & \\(\\Theta(n^n)\\) \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{\\textit{In ascending order of growth-rate.}}\n\\end{table}\n\n%\\end{appendices}\n\n\\end{document}\n", "meta": {"hexsha": "8ac3f35ac6a1ae5f321d362bd3e32775d49174c7", "size": 5904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "apx.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": "apx.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": "apx.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": 37.3670886076, "max_line_length": 179, "alphanum_fraction": 0.6072154472, "num_tokens": 2292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.6575509405911862}}
{"text": "\\section{Identity types}\\label{chap:identity}\nFrom the perspective of types as proof-relevant propositions, how should we think of \\emph{equality} in type theory? Given a type $A$, and two terms $x,y:A$, the equality $\\id{x}{y}$ should again be a type. Indeed, we want to \\emph{use} type theory to prove equalities. \\emph{Dependent} type theory provides us with a convenient setting for this: the equality type $\\id{x}{y}$ is dependent on $x,y:A$. \n\nThen, if $\\id{x}{y}$ is to be a type, how should we think of the terms of $\\id{x}{y}$. A term $p:\\id{x}{y}$ witnesses that $x$ and $y$ are equal terms of type $A$. In other words $p:\\id{x}{y}$ is an \\emph{identification} of $x$ and $y$. In a proof-relevant world, there might be many terms of type $\\id{x}{y}$. I.e., there might be many identifications of $x$ and $y$. And, since $\\id{x}{y}$ is itself a type, we can form the type $\\id{p}{q}$ for any two identifications $p,q:\\id{x}{y}$. That is, since $\\id{x}{y}$ is a type, we may also use the type theory to prove things \\emph{about} identifications (for instance, that two given such identifications can themselves be identified), and we may use the type theory to perform constructions with them. As we will see shortly, we can give every type a groupoid-like structure.\n\nClearly, the equality type should not just be any type dependent on $x,y:A$. Then how do we form the equality type, and what ways are there to use identifications in constructions in type theory? The answer to both these questions is that we will form the identity type as an \\emph{inductive} type, generated by just a reflexivity term providing an identification of $x$ to itself. The induction principle then provides us with a way of performing constructions with identifications, such as concatenating them, inverting them, and so on. Thus, the identity type is equipped with a reflexivity term, and further possesses the structure that are generated by its induction principle and by the type theory. This inductive construction of the identity type is elegant, beautifully simple, but far from trivial!\n\nThe situation where two terms can be identified in possibly more than one way is analogous to the situation in \\emph{homotopy theory}, where two points of a space can be connected by possibly more than one \\emph{path}. Indeed, for any two points $x,y$ in a space, there is a \\emph{space of paths} from $x$ to $y$. Moreover, between any two paths from $x$ to $y$ there is a space of \\emph{homotopies} between them, and so on. This leads to the homotopy interpretation of type theory, outlined in \\cref{tab:homotopy_interpretation}. The connection between homotopy theory and type theory been made precise by the construction of homotopical models of type theory, and it has led to the fruitful research area of \\emph{synthetic homotopy theory}, the subfield of \\emph{homotopy type theory} that is the topic of this course.\n\n\\begin{table}\n\\begin{center}\n\\caption{\\label{tab:homotopy_interpretation}The homotopy interpretation\\index{Homotopy interpretation}}\n\\begin{tabular}{ll}\n\\toprule\n\\emph{Type theory} &  \\emph{Homotopy theory} \\\\\n\\midrule\nTypes  & Spaces \\\\\nDependent types & Fibrations \\\\\nTerms & Points \\\\\nDependent pair type & Total space \\\\\nIdentity type & Path fibration\\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\subsection{The inductive definition of identity types}\n\n\\begin{defn}\n  Consider a type $A$ and let $a:A$. Then we define the \\define{identity type}\\index{identity type|textbf} of $A$ at $a$ as an inductive family of types $a =_A x$ indexed by $x:A$, of which the constructor is\n  \\begin{equation*}\n    \\refl{a}:a=_Aa.\n  \\end{equation*}\n  The induction principle of the identity type postulates that for any family of types $P(x,p)$ indexed by $x:A$ and $p:a=_A x$, there is a function\n  \\begin{equation*}\n    \\mathsf{path\\usc{}ind}_a:P(a,\\refl{a}) \\to \\prd{x:A}{p:a=_A x} P(x,p)\n  \\end{equation*}\n  that satisfies $\\mathsf{path\\usc{}ind}_a(p,a,\\refl{a})\\jdeq p$.\n\n  A term of type $a=_A x$ is also called an \\define{identification}\\index{identification|textbf} of $a$ with $x$, and sometimes it is called a \\define{path}\\index{path|textbf} from $a$ to $x$.\nThe induction principle for identity types is sometimes called \\define{identification elimination}\\index{identification elimination|textbf} or \\define{path induction}\\index{path induction|textbf}. We also write $\\idtypevar{A}$\\index{Id A@{$\\idtypevar{A}$}|textbf} for the identity type on $A$, and often we write $a=x$ for the type of identifications of $a$ with $x$, omitting reference to the ambient type $A$.\n\\end{defn}\n\n\\begin{rmk}\n  We see that the identity type is not just an inductive type, like the inductive types $\\N$, $\\emptyt$, and $\\unit$ for example, but it is and inductive \\emph{family} of types. Even though we have a type $a=_A x$ for any $x:A$, the constructor only provides a term $\\refl{a}:a=_A a$, identifying $a$ with itself. The induction principle then asserts that in order to prove something about all identifications of $a$ with some $x:A$, it suffices to prove this assertion about $\\refl{a}$ only. We will see in the next sections that this induction principle is strong enough to derive many familiar facts about equality, namely that it is a symmetric and transitive relation, and that all functions preserve equality.\n\\end{rmk}\n\n\\begin{rmk}\n  Since the identity types require getting used to, we provide the formal rules\n  for identity types. The identity type is formed by the formation rule:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash a=_A x~\\mathrm{type}$}\n  \\end{prooftree}\n  The constructor of the identity type is then given by the introduction rule:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\UnaryInfC{$\\Gamma\\vdash \\refl{a}:a=_A a$}\n  \\end{prooftree}\n  The induction principle is now given by the elimination rule:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\AxiomC{$\\Gamma,x:A,p:a=_A x\\vdash P(x,p)~\\mathrm{type}$}\n    \\BinaryInfC{$\\Gamma\\vdash \\mathsf{path\\usc{}ind}_a:P(a,\\refl{a})\\to\\prd{x:A}{p:a=_A x}P(x,p)$}\n  \\end{prooftree}\n  And finally the computation rule is:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash a:A$}\n    \\AxiomC{$\\Gamma,x:A,p:a=_A x\\vdash P(x,p)~\\mathrm{type}$}\n    \\BinaryInfC{$\\Gamma\\vdash \\mathsf{path\\usc{}ind}_a(p,a,\\refl{a})\\jdeq p : P(a,\\refl{a})$}\n  \\end{prooftree}\n  Furthermore we postulate that any universe is closed under identity types, i.e., that there is a function\n  \\begin{equation*}\n    \\check{\\mathsf{Id}}:\\prd{A:\\UU}\\mathsf{Ty}(A)\\to\\mathsf{Ty}(A)\\to\\UU\n  \\end{equation*}\n  satisfying\n  \\begin{equation*}\n    \\mathsf{Ty}(\\check{\\mathsf{Id}}(A,a,x))\\jdeq a=_{\\mathsf{Ty}(A)} x.\n  \\end{equation*}\n\\end{rmk}\n\n\\begin{rmk}\n  One might wonder whether it is also possible to form the identity type at a \\emph{variable} of type $A$, rather than at a term. This is certainly possible: since we can form the identity type in \\emph{any} context, we can form the identity type at a variable $x:A$ as follows:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma,x:A\\vdash x:A$}\n    \\UnaryInfC{$\\Gamma,x:A,y:A\\vdash x=_A y~\\mathrm{type}$}\n  \\end{prooftree}\n  In this way we obtain the `binary' identity type. Its constructor is then also indexed by $x:A$. We have the following introduction rule\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma,x:A\\vdash x:A$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash \\refl{x}:x=_A x$}\n  \\end{prooftree}\n  and similarly we have elimination and computation rules.\n\\end{rmk}\n \n\n\\begin{comment}\nIn the following lemma we show that the identity type on $A$ is contained in any reflexive relation on $A$.\n\n\\begin{lem}\nLet $\\Gamma,x:A,y:A\\vdash R(x,y)~\\mathrm{type}$\\index{reflexive relation|textit}\\index{relation!reflexive}, and suppose that $R$ is reflexive in the sense that there is a term\n\\begin{equation*}\n\\rho:\\prd{x:A}R(x,x)\n\\end{equation*}\nThen there is a term of type\n\\begin{equation*}\n\\prd{y:A} (x=_A y)\\to R(x,y)\n\\end{equation*}\nin context $\\Gamma,x:A$.\n\\end{lem}\n\n\\begin{constr}\nBy weakening the reflexive relation $R$ we obtain\n\\begin{equation*}\n\\Gamma,x:A,y:A,\\alpha:x=_A y\\vdash R(x,y)~\\mathrm{type},\n\\end{equation*}\non which the induction principle is applicable.\nThus we see that by the induction principle for identity types we have a term\n\\begin{equation*}\n\\mathsf{path\\usc{}ind}_x : R(x,x)\\to \\prd{y:A}(x=_A y)\\to R(x,y)\n\\end{equation*}\nso it suffices to construct a term of type $R(x,x)$, which we have by reflexivity of $R$.\n\\end{constr}\n\\end{comment}\n\n\\subsection{The groupoid structure of types}\\label{sec:groupoid}\nWe show that identifications can be \\emph{concatenated} and \\emph{inverted}, which corresponds to the transitivity and symmetry of the identity type. \n\nFurthermore, we observe that we can iteratively take identity types, i.e., we can take identity types of identity types, \n\\begin{equation*}\np =_{(x=_Ay)} q,\n\\end{equation*}\nand so on. In other words, for any two identifications $p,q:x=_A y$, there is a type of identifications of $p$ with $y$. One way to think about this is that the identifications $p,q:x=_A y$ are paths in the type (space) $A$, and an identification of $p$ with $q$ is a \\emph{higher path} from $p$ to $q$, i.e., a \\emph{homotopy}.\n\nUsing the observation that identity types can be iterated we show that concatenation is \\emph{associative}, satisfies the left and right \\emph{unit laws}, and satisfies the left and right \\emph{inverse laws}. These are the \\define{groupoid operations} on the identity type.\n\n\\begin{defn}\\label{defn:id_concat}\nLet $A$ be a type. We define the \\define{concatenation}\\index{concatenation!for identifications}\\index{concat@{$\\mathsf{concat}$}} operation\n\\begin{equation*}\n\\mathsf{concat} : \\prd{x,y,z:A} (\\id{x}{y})\\to(\\id{y}{z})\\to (\\id{x}{z}).\n\\end{equation*}\nWe will write $\\ct{p}{q}$ for $\\mathsf{concat}(p,q)$.\n\\end{defn}\n\n\\begin{constr}\nWe construct the concatenation operation by path induction. It suffices to construct\n\\begin{equation*}\n\\mathsf{concat}(\\refl{x}):\\prd{z:A} (x=z)\\to(x=z).\n\\end{equation*}\nHere we take $\\mathsf{concat}(\\refl{x})_z \\jdeq \\idfunc[(x=z)]$. \nExplicitly, the term we have constructed is\n\\begin{equation*}\n\\lam{x}\\mathsf{path\\usc{}ind}_x(\\lam{z}\\idfunc[(\\id{x}{z})]):\\prd{x,y:A} (x=y)\\to \\prd{z:A} (y=z)\\to (x=z).\n\\end{equation*}\nTo obtain a term of the asserted type we need to swap the order of the arguments $p:x=y$ and $z:A$, using \\cref{ex:swap}.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_inv}\nLet $A$ be a type. We define the \\define{inverse operation}\\index{inverse operation!for identifications|textbf}\\index{inv@{$\\mathsf{inv}$}|textbf}\n\\begin{equation*}\n\\mathsf{inv}:\\prd{x,y:A} (x=y)\\to (y=x).\n\\end{equation*}\nMost of the time we will write $p^{-1}$ for $\\mathsf{inv}(p)$.\n\\end{defn}\n\n\\begin{constr}\nWe construct the inverse operation by path induction. It suffices to construct\n\\begin{equation*}\n\\mathsf{inv}(\\refl{x}): x=x,\n\\end{equation*}\nfor any $x:A$. Here we take $\\mathsf{inv}(\\refl{x})\\defeq \\refl{x}$.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_assoc}\nLet $A$ be a type. We define the \\define{associativity operation}\\index{associativity operation!for identifications|textbf}, which assigns to each $p:x=y$, $q:y=z$, and $r:z=w$ the \\define{associator}\n\\begin{equation*}\n\\mathsf{assoc}(p,q,r) : \\ct{(\\ct{p}{q})}{r}=\\ct{p}{(\\ct{q}{r})}.\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nBy identification elimination it suffices to show that\n\\begin{equation*}\n\\prd{z:A}{q:x=z}{z':A}{r:z=w} \\ct{(\\ct{\\refl{x}}{q})}{r}= \\ct{\\refl{x}}{(\\ct{q}{r})}.\n\\end{equation*}\nLet $q:x=z$ and $r:z=w$. Note that by the computation rule $\\ct{\\refl{x}}{q}\\jdeq q$, so $\\ct{(\\ct{\\refl{x}}{q})}{r}\\jdeq \\ct{q}{r}$. Similarly we have $\\ct{\\refl{x}}{(\\ct{q}{r})}\\jdeq \\ct{q}{r}$. Therefore we can simply take $\\refl{\\ct{q}{r}}$.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_unit}\nLet $A$ be a type. We define the left and right \\define{unit law operations}\\index{unit law operations!for identifications|textbf}, which assigns to each $p:x=y$ the terms\\index{left unit@{$\\mathsf{left\\usc{}unit}$}|textbf}\\index{right unit@{$\\mathsf{right\\usc{}unit}$}|textbf}\n\\begin{align*}\n\\mathsf{left\\usc{}unit}(p) & : \\ct{\\refl{x}}{p}=p \\\\\n\\mathsf{right\\usc{}unit}(p) & : \\ct{p}{\\refl{y}}=p,\n\\end{align*}\nrespectively.\n\\end{defn}\n\n\\begin{constr}\nBy identification elimination it suffices to construct\n\\begin{align*}\n\\mathsf{left\\usc{}unit}(\\refl{x}) & : \\ct{\\refl{x}}{\\refl{x}} = \\refl{x} \\\\\n\\mathsf{right\\usc{}unit}(\\refl{x}) & : \\ct{\\refl{x}}{\\refl{x}} = \\refl{x}.\n\\end{align*}\nIn both cases we take $\\refl{\\refl{x}}$.\n\\end{constr}\n\n\\begin{defn}\\label{defn:id_invlaw}\nLet $A$ be a type. We define left and right \\define{inverse law operations}\\index{inverse law operations!for identifications|textbf}\\index{left inv@{$\\mathsf{left\\usc{}inv}$}|textbf}\\index{right inv@{$\\mathsf{right\\usc{}inv}$}|textbf}\n\\begin{align*}\n\\mathsf{left\\usc{}inv}(p) & : \\ct{p^{-1}}{p} = \\refl{y} \\\\\n\\mathsf{right\\usc{}inv}(p) & : \\ct{p}{p^{-1}} = \\refl{x}.\n\\end{align*}\n\\end{defn}\n\n\\begin{constr}\nBy identification elimination it suffices to construct\n\\begin{align*}\n\\mathsf{left\\usc{}inv}(\\refl{x}) & : \\ct{\\refl{x}^{-1}}{\\refl{x}} = \\refl{x} \\\\\n\\mathsf{right\\usc{}inv}(\\refl{x}) & : \\ct{\\refl{x}}{\\refl{x}^{-1}} = \\refl{x}.\n\\end{align*}\nUsing the computation rules we see that\n\\begin{equation*}\n\\ct{\\refl{x}^{-1}}{\\refl{x}}\\jdeq \\ct{\\refl{x}}{\\refl{x}}\\jdeq\\refl{x},\n\\end{equation*}\nso we define $\\mathsf{left\\usc{}inv}(\\refl{x})\\defeq \\refl{\\refl{x}}$. Similarly it follows from the computation rules that\n\\begin{equation*}\n\\ct{\\refl{x}}{\\refl{x}^{-1}} \\jdeq \\refl{x}^{-1}\\jdeq \\refl{x}\n\\end{equation*}\nso we again define $\\mathsf{right\\usc{}inv}(\\refl{x})\\defeq\\refl{\\refl{x}}$. \n\\end{constr}\n\n\\subsection{The action on paths of functions}\n\nUsing the induction principle of the identity type we can show that every function preserves identifications.\nIn other words, every function sends identified terms to identified terms.\nNote that this is a form of continuity for functions in type theory: if there is a path that identifies two points $x$ and $y$ of a type $A$, then there also is a path that identifies the values $f(x)$ and $f(y)$ in the codomain of $f$. \n\n\\begin{defn}\\label{defn:ap}\nLet $f:A\\to B$ be a map. We define the \\define{action on paths}\\index{action on paths}\\index{function!action on paths} of $f$ as an operation\\index{ap f@{$\\apfunc{f}$}|textbf}\n\\begin{equation*}\n\\apfunc{f} : \\prd*{x,y:A} (\\id{x}{y})\\to(\\id{f(x)}{f(y)}).\n\\end{equation*}\nMoreover, there are operations\\index{ap idfun@{$\\mathsf{ap\\usc{}idfun}$}|textbf}\\index{ap comp@{$\\mathsf{ap\\usc{}comp}$}|textbf}\n\\begin{align*}\n\\mathsf{ap\\usc{}idfun}_A & : \\prd*{x,y:A}{p:\\id{x}{y}} \\id{p}{\\ap{\\idfunc[A]}{p}} \\\\\n\\mathsf{ap\\usc{}comp}(f,g) & : \\prd*{x,y:A}{p:\\id{x}{y}} \\id{\\ap{g}{\\ap{f}{p}}}{\\ap{g\\circ f}{p}}.\n\\end{align*}\n\\end{defn}\n\n\\begin{constr}\nFirst we define $\\apfunc{f}$ by identity elimination, taking\n\\begin{equation*}\n\\apfunc{f}(\\refl{x})\\defeq \\refl{f(x)}.\n\\end{equation*}\nNext, we construct $\\mathsf{ap\\usc{}idfun}_A$ by identity elimination, taking\n\\begin{equation*}\n\\mathsf{ap\\usc{}idfun}_A(\\refl{x}) \\defeq \\refl{\\refl{x}}.\n\\end{equation*}\nFinally, we construct $\\mathsf{ap\\usc{}comp}(f,g)$ by identity elimination, taking\n\\begin{equation*}\n\\mathsf{ap\\usc{}comp}(f,g,\\refl{x}) \\defeq \\refl{g(f(x))}.\\qedhere\n\\end{equation*}\n\\end{constr}\n\n\\begin{defn}\\label{defn:ap-preserve}\nLet $f:A\\to B$ be a map. Then there are identifications\n\\begin{align*}\n\\mathsf{ap\\usc{}refl}(f,x) & : \\id{\\ap{f}{\\refl{x}}}{\\refl{f}(x)} \\\\\n\\mathsf{ap\\usc{}inv}(f,p) & : \\id{\\ap{f}{p^{-1}}}{\\ap{f}{p}^{-1}} \\\\\n\\mathsf{ap\\usc{}concat}(f,p,q) & : \\id{\\ap{f}{\\ct{p}{q}}}{\\ct{\\ap{f}{p}}{\\ap{f}{q}}}\n\\end{align*}\nfor every $p:\\id{x}{y}$ and $q:\\id{x}{y}$.\n\\end{defn}\n\n\\begin{constr}\nTo construct $\\mathsf{ap\\usc{}refl}(f,x)$ we simply observe that ${\\ap{f}{\\refl{x}}}\\jdeq {\\refl{f}(x)}$, so we take\n\\begin{equation*}\n\\mathsf{ap\\usc{}refl}(f,x)\\defeq\\refl{\\refl{f(x)}}.\n\\end{equation*}\nWe construct $\\mathsf{ap\\usc{}inv}(f,p)$ by identification elimination on $p$, taking\n\\begin{equation*}\n\\mathsf{ap\\usc{}inv}(f,\\refl{x}) \\defeq \\refl{\\ap{f}{\\refl{x}}}.\n\\end{equation*}\nFinally we construct $\\mathsf{ap\\usc{}concat}(f,p,q)$ by identification elimination on $p$, taking\n\\begin{equation*}\n\\mathsf{ap\\usc{}concat}(f,\\refl{x},q)  \\defeq \\refl{\\ap{f}{q}}.\\qedhere\n\\end{equation*}\n\\end{constr}\n\n\\subsection{Transport}\n\nDependent types also come with an action on paths: the \\emph{transport} functions.\nGiven an identification $p:\\id{x}{y}$ in the base type $A$, we can transport any term $b:B(x)$ to the fiber $B(y)$.\nThe transport functions have many applications, which we will encounter throughout this course.\n\n\\begin{defn}\nLet $A$ be a type, and let $B$ be a type family over $A$.\nWe will construct a \\define{transport}\\index{transport|textbf} operation\\index{tr B@{$\\mathsf{tr}_B$}|textbf}\n\\begin{equation*}\n\\mathsf{tr}_B:\\prd*{x,y:A} (\\id{x}{y})\\to (B(x)\\to B(y)).\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nWe construct $\\mathsf{tr}_B(p)$ by induction on $p:x=_A y$, taking\n\\begin{equation*}\n\\mathsf{tr}_B(\\refl{x}) \\defeq \\idfunc[B(x)].\\qedhere\n\\end{equation*}\n\\end{constr}\n\nThus we see that type theory cannot distinguish between identified terms $x$ and $y$, because for any type family $B$ over $A$ one gets a term of $B(y)$ as soon as $B(x)$ has a term.\n\nAs an application of the transport function we construct the \\emph{dependent} action on paths\\index{dependent action on paths}\\index{function!dependent action on paths} of a dependent function $f:\\prd{x:A}B(x)$. Note that for such a dependent function $f$, and an identification $p:\\id[A]{x}{y}$, it does not make sense to directly compare $f(x)$ and $f(y)$, since the type of $f(x)$ is $B(x)$ whereas the type of $f(y)$ is $B(y)$, which might not be exactly the same type. However, we can first \\emph{transport} $f(x)$ along $p$, so that we obtain the term $\\mathsf{tr}_B(p,f(x))$ which is of type $B(y)$. Now we can ask whether it is the case that $\\mathsf{tr}_B(p,f(x))=f(y)$. The dependent action on paths of $f$ establishes this identification.\n\n\\begin{defn}\\label{defn:apd}\nGiven a dependent function $f:\\prd{a:A}B(a)$ and a path $p:\\id{x}{y}$ in $A$, we construct a path\\index{apd f@{$\\apdfunc{f}$}|textbf}\n\\begin{equation*}\n\\apd{f}{p} : \\id{\\mathsf{tr}_B(p,f(x))}{f(y)}.\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nThe path $\\apd{f}{p}$ is constructed by path induction on $p$. Thus, it suffices to construct a path\n\\begin{equation*}\n\\apd{f}{\\refl{x}}:\\id{\\mathsf{tr}_B(\\refl{x},f(x))}{f(x)}.\n\\end{equation*}\nSince transporting along $\\refl{x}$ is the identity function on $B(x)$, we simply take $\\apd{f}{\\refl{x}}\\defeq\\refl{f(x)}$. \n\\end{constr}\n\n%\\begin{defn}\\label{defn:path_lifting}\n%Let $A$ be a type, and let $B:A\\to\\type$ be a type family over $A$.\n%We will construct a \\define{path lifting} operation\n%\\begin{equation*}\n%\\mathsf{lift}^B : \\prd*{x,y:A}{p:\\id{x}{y}}{b:B(x)} \\id{\\pairr{x,b}}{\\pairr{y,\\trans{p}{b}}}.\n%\\end{equation*}\n%\\end{defn}\n%\n%\\cref{defn:path_lifting} gives a way to lift a path $p:x=y$ in the base type of a type family, to a path in the $\\Sigma$-type. This, along with the basic groupoid operations developed in \\cref{sec:groupoid}, inspired the \\emph{homotopy interpretation} of type theory.\n\n\\begin{exercises}\n\\item\n  \\begin{subexenum}\n  \\item State Goldbach's Conjecture in type theory.\n  \\item State the Twin Prime Conjecture in type theory.\n  \\end{subexenum}\n\\item \\label{ex:inv_assoc}Show that the operation inverting paths distributes over the concatenation operation, i.e., construct an identification\n  \\begin{align*}\n    \\mathsf{distributive\\usc{}inv\\usc{}concat}(p,q):\\id{(\\ct{p}{q})^{-1}}{\\ct{q^{-1}}{p^{-1}}}.\n  \\end{align*}\n  for any $p:\\id{x}{y}$ and $q:\\id{y}{z}$.\n\\item \\label{ex:inv_con}For any $p:x=y$, $q:y=z$, and $r:x=z$, construct maps\n  \\begin{align*}\n    \\mathsf{inv\\usc{}con}(p,q,r) & : (\\ct{p}{q}=r)\\to (q=\\ct{p^{-1}}{r}) \\\\\n    \\mathsf{con\\usc{}inv}(p,q,r) & : (\\ct{p}{q}=r)\\to (p=\\ct{r}{q^{-1}}).\n  \\end{align*}\n\\item Let $B$ be a type family over $A$, and consider a path $p:\\id{x}{x'}$ in $A$. Construct for any $y:B(x)$ a path\n  \\begin{equation*}\n    \\mathsf{lift}_B(p,y) : \\id{\\pairr{x,y}}{\\pairr{x',\\mathsf{tr}_B(p,y)}}.\n  \\end{equation*}\n  In other words, a path in the \\emph{base type} $A$ \\emph{lifts} to a path in the total space $\\sm{x:A}B(x)$ for every term over the domain, analogous to the path lifting property for fibrations in homotopy theory.\n\\item \\label{ex:semi-ring-laws-N}Show that the operations of addition and multiplication on the natural numbers satisfy the following laws:\n  \\begin{align*}\n    m+(n+k) & =(m+n)+k & m\\cdot (n\\cdot k) & = (m\\cdot n)\\cdot k \\\\\n    m+0 & = m & m\\cdot 1 & = m \\\\\n    0+m & = m & 1\\cdot m & = m \\\\\n    m+n & = n+m & m\\cdot n & = n\\cdot m\\\\\n    & & m\\cdot (n+k) & = m\\cdot n + m\\cdot k.\n  \\end{align*}\n\\item Consider four consecutive identifications\n  \\begin{equation*}\n    \\begin{tikzcd}\n      a \\arrow[r,equals,\"p\"] & b \\arrow[r,equals,\"q\"] & c \\arrow[r,equals,\"r\"] & d \\arrow[r,equals,\"s\"] & e\n    \\end{tikzcd}\n  \\end{equation*}\n  in a type $A$. In this exercise we will show that the \\define{Mac Lane pentagon}\\index{Mac Lane pentagon} for identifications commutes.\n  \\begin{subexenum}\n  \\item Construct the five identifications $\\alpha_1,\\ldots,\\alpha_5$ in the pentagon\n    \\begin{equation*}\n      \\begin{tikzcd}[column sep=-1.5em]\n        &[-2em] \\ct{(\\ct{(\\ct{p}{q})}{r})}{s} \\arrow[rr,equals,\"\\alpha_4\"] \\arrow[dl,equals,swap,\"\\alpha_1\"] & & \\ct{(\\ct{p}{q})}{(\\ct{r}{s})} \\arrow[dr,equals,\"\\alpha_5\"] &[-2em] \\\\\n        \\ct{(\\ct{p}{(\\ct{q}{r})})}{s} \\arrow[drr,equals,swap,\"\\alpha_2\"] & & & & \\ct{p}{(\\ct{q}{(\\ct{r}{s})})}, \\\\\n        & & \\ct{p}{(\\ct{(\\ct{q}{r})}{s})} \\arrow[urr,equals,swap,\"\\alpha_3\"]\n      \\end{tikzcd}\n    \\end{equation*}\n    where $\\alpha_1$, $\\alpha_2$, and $\\alpha_3$ run counter-clockwise, and $\\alpha_4$ and $\\alpha_5$ run clockwise.\n  \\item Show that\n    \\begin{equation*}\n      \\ct{(\\ct{\\alpha_1}{\\alpha_2})}{\\alpha_3} = \\ct{\\alpha_4}{\\alpha_5}.\n    \\end{equation*}\n  \\end{subexenum}\n\\end{exercises}\n\n%\\item In this exercise we show that the action on paths of a function preserves the groupoid-structure of a type.\n%\\begin{subexenum}\n%\\item Construct an identification\n%\\begin{equation*}\n%\\mathsf{ap.assoc}(f,p,q,r)\n%\\end{equation*}\n%witnessing that the diagram\n%\\begin{equation*}\n%\\begin{tikzcd}[column sep=large]\n%\\ap{f}{\\ct{(\\ct{p}{q})}{r}} \\arrow[r,equals,\"\\ap{\\apfunc{f}}{\\mathsf{assoc}(p,q,r)}\"] \\arrow[d,swap,equals,\"{\\mathsf{ap.ct}(f,%\\ct{p}{q},r)}\"] & \\ap{f}{\\ct{p}{(\\ct{q}{r})}} \\arrow[d,equals,\"{\\mathsf{ap.ct}(f,p,\\ct{q}{r})}\"] \\\\ \n%\\ct{\\ap{f}{\\ct{p}{q}}}{\\ap{f}{r}} \\arrow[dd,equals,near start,\"{\\mathsf{whisk\\usc{}r}(\\mathsf{ap.ct}(f,p,q),\\ap{f}{r})}\"]   & %\\ct{\\ap{f}{p}}{\\ap{f}{\\ct{q}{r}}} \\arrow[dd,equals,swap,near end,\"{\\mathsf{whisk\\usc{}l}(\\ap{f}{p},\\mathsf{ap.ct}(f,q,r))}\"]  %\\\\\n%\\\\\n%\\ct{(\\ct{\\ap{f}{p}}{\\ap{f}{q}})}{\\ap{f}{r}} \\arrow[r,equals,swap,\"{\\mathsf{assoc}(\\ap{f}{p},\\ap{f}{q},\\ap{f}{r})}\"yshift=-1em] & \\ct{\\ap{f}{p}}{(\\ct{\\ap{f}{q}}{\\ap{f}{r}})}\n%\\end{tikzcd}\n%\\end{equation*}\n%commutes.\n%\\end{subexenum}\n\n\\begin{comment}\n\\item \\label{ex:trans_triv}Consider two types $A$ and $B$, and let $p:x=y$ in $A$, and $b:B$. \n  \\begin{subexenum}\n  \\item Construct an identification\n    \\begin{align*}\n      \\mathsf{tr\\usc{}triv}(p,b):\\mathsf{tr}_{W_A(B)}(p,b)=b\n    \\end{align*}\n    where $W_A(B)$ is the family $B$ weakened by $A$.\n  \\item Construct for any $f:A\\to B$, an identification \n    \\begin{equation*}\n      \\apd{f}{p}=\\ct{\\mathsf{tr\\usc{}triv}(p,f(x))}{\\mathsf{ap}_f(p)},\n    \\end{equation*}\n    witnessing that the triangle\n    \\begin{equation*}\n      \\begin{tikzcd}[trim right=(a),column sep=0em]\n        \\mathsf{tr}_{W_A(B)}(p,f(x)) \\arrow[dr,equals,swap,\"\\apd{f}{p}\"] \\arrow[rr,equals,\"{\\mathsf{tr\\usc{}triv}(p,f(x))}\"] & & |[alias=a,right]|f(x) \\arrow[dl,equals,\"\\ap{f}{p}\"] \\\\\n        & f(y) & \\phantom{\\mathsf{tr}_{W_A(B)}(p,f(x))}\n      \\end{tikzcd}\n    \\end{equation*}\n    commutes.\n  \\end{subexenum}\n\\item \\label{ex:trans_ap}Let $f:A\\to B$ be a map, and consider $p:x=y$ in $A$. \n  \\begin{subexenum}\n  \\item Construct for any $q:f(x)=b$ in $B$ an identification\n    \\begin{equation*}\n      \\mathsf{tr\\usc{}id\\usc{}left\\usc{}subst}(p,q):\\id{\\mathsf{tr}_{f(\\blank)=b}(p,q)}{\\ct{\\ap{f}{p}^{-1}}{q}}.\n    \\end{equation*}\n  \\item Similarly, construct for any $q':b=f(x)$ in $B$ an identification\n    \\begin{equation*}\n      \\mathsf{tr\\usc{}id\\usc{}right\\usc{}subst}(p,q'):\\id{\\mathsf{tr}_{b=f(\\blank)}(p,q)}{\\ct{q}{\\ap{f}{p}}}.\n    \\end{equation*}\n  \\end{subexenum}\n\\end{comment}\n", "meta": {"hexsha": "de61dcfcda1475d81f3a2d5d109389f52d56f78c", "size": 24611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/identity.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/identity.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/identity.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": 55.4301801802, "max_line_length": 825, "alphanum_fraction": 0.6765673886, "num_tokens": 8622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6575509360626922}}
{"text": "\\chapter{Constraints}\n\\label{cha:conGen}\nFor some optimization problems it is necessary to impose constraints \non the independent variables and/or the dependent variables, as the following example shows.\n\n\\begin{example}{\\em\nSuppose we want to minimize the heating energy of a building, and suppose that\nthe normalized mass flow $\\dot m$ of the heating system is an independent variable, with constraints\n$0 \\le \\dot m \\le 1$.\nWithout using constraints, the minimum energy consumption would be achieved \nfor $\\dot m = 0$, since then the heating system is switched off.\nTo solve this problem, we can impose a constraint on a dependent variable.\nOne possibility is to add a ``penalty'' term to the energy consumption. \nThis could be such that every time a thermal comfort criterion \n(which is a dependent variable)\nis violated, a large positive number is added to the energy consumption.\nThus, if $\\mathrm{ppd}(x)$, with $\\mathrm{ppd} \\colon \\Re^n \\to \\Re$, \ndenotes the predicted percent of dissatisfied people (in percentage), and\nif we require that $\\mathrm{ppd}(x) \\le 10 \\%$, we could use the inequality constraint\n$g(x) \\triangleq \\mathrm{ppd}(x) - 10 \\le 0$.\n}\n\\phantom{abc} \\rbox\n\\end{example}\n\nIn Section~\\ref{sec:boxConFre}, the method that is used in GenOpt to implement box constraints is \ndescribed.\nIn Section~\\ref{sec:conDepVarGen}, penalty and barrier methods that can be used to \nimplement constraints on dependent variables are described.\nThey involve reformulating the cost function and, hence, are problem specific and \nhave to be implemented by the user.\n\n% ============================================\n\\section{Constraints on Independent Variables}\n\\label{sec:conFreParGen}\n\\subsection{Box Constraints}\n\\label{sec:boxConFre}\n\nBox constraints are constant inequality constraints that define a feasible set as\n\\begin{equation}\n\\mathbf X \\triangleq \\bigl\\{ x \\in \\Re^n \\ | \\ \nl^i \\le x^i \\le u^i, \\ i \\in \\{1, \\ldots, n \\} \\bigr\\},\n\\end{equation}\nwhere $-\\infty \\le l^i < u^i \\le \\infty$ for $i \\in \\{1, \\ldots, n \\}$.\n\nIn GenOpt, box constraints are either implemented directly \nin the optimization algorithm by setting $f(x) = \\infty$ for unfeasible iterates,\nor, for some algorithms, the independent variable $x \\in \\mathbf X$ is transformed \nto a new unconstrained variable which we will denote in this section by $t \\in \\Re^n$.\n\n\\begin{subequations}\nInstead of optimizing the constrained variable $x \\in \\mathbf X$, \nwe optimize with respect to the unconstrained variable $t \\in \\Re^n$.\nThe transformation ensures that all variables stay feasible during the iteration process.\nIn GenOpt, the following transformations are used:\\\\\n\n\\noindent\nIf $l^i \\le x^i$, for some $i \\in \\{1, \\ldots, n\\}$,\n\\begin{eqnarray}\n  t^i & = &\\sqrt{x^i - l^i}, \\\\\n  x^i & = &l^i + (t^i)^2.\n\\end{eqnarray}\nIf $l^i \\le x^i \\le u^i$, for some $i \\in \\{1, \\ldots, n\\}$, \n\\begin{eqnarray}\n  t^i & = & \\arcsin\\left( \n    \\sqrt{\\frac{x^i - l^i}{u^i-l^i}}\n    \\right), \\\\\n x^i & = &l^i + (u^i - l^i) \\, \\sin^2 t^i.\n\\end{eqnarray}\nIf $x^i \\le u^i$, for some $i \\in \\{1, \\ldots, n\\}$,\n\\begin{eqnarray}\n  t^i & = & \\sqrt{u^i - x^i}, \\\\\n   x^i & = & u^i - (t^i)^2.\n\\end{eqnarray}\n\\label{sub:traBoxCon}\n\\end{subequations}\n% ----------------------------\n\\subsection{Coupled Linear Constraints}\nIn some cases the constraints have to be formulated in terms of a linear system of equations of the form\n\\begin{equation}\n   A \\, x = b,\n\\end{equation}\nwhere $A \\in \\Re^m \\times \\Re^n$, $x \\in \\Re^n$, $b \\in \\Re^m$, and $\\mathrm{rank}(A) = m$.\\\\\n\nThere are various algorithms that take this kind of restriction into account. However, such restrictions are rare in building simulation and thus not implemented in GenOpt. If there is a need to impose such restrictions, they can be included by adding an appropriate optimization algorithm and retrieving the coefficients by using the methods offered in GenOpt's class \\texttt{Optimizer}.\n\n% -----------------------------------------\n\n\\section{Constraints on Dependent Variables}\n\\label{sec:conDepVarGen}\nWe now discuss the situation where the constraints are non-linear and \ndefined by\n\\begin{equation}\n   g(x) \\le 0,\n\\label{eq:conFunG}\n\\end{equation}\nwhere $g \\colon \\Re^n \\rightarrow \\Re^m$ is once continuously differentiable.\n\\eqref{eq:conFunG} also allows formulating equality constraints of the form\n\\begin{equation}\n  h(x) = 0,\n\\label{eq:equCon}\n\\end{equation}\nfor $h \\colon \\Re^n \\to \\Re^m$, which can be implemented by using penalty functions.\nIn example, one can define $g^i(x) \\triangleq h^i(x)^2$ for $i \\in \\{ 1, \\ldots, m \\}$. Then, since $g^i(\\cdot)$ is non-negative, the only feasible value is $g(\\cdot) = 0$.\nThus, we will only discuss the case of inequality constraints of the form~\\eqref{eq:conFunG}.\\\\\n\nSuch a constraint can be taken into account by adding \\emph{penalty} or \\emph{barrier} functions to the cost function, which are multiplied by a positive weighting factor $\\mu$\nthat is monotonically increased (for penalty functions) or monotonically decreased to zero (for barrier functions).\\\\\n\nWe now discuss the implementation of barrier and penalty functions.\n% ---------------------------\n\\subsection{Barrier Functions}\nBarrier functions impose a punishment if the dependent variable gets close to the \nboundary of the feasible region.\nThe closer the variable is to the boundary, \nthe higher the value of the barrier function becomes.\n\n\\noindent To implement a barrier function for $g(x) \\le 0$,\nwhere $g \\colon \\Re^n \\to \\Re^m$ is a continuously differentiable function whose\nelements are strictly monotone increasing,\nthe cost function $f \\colon \\Re^n \\to \\Re$ can\nbe modified to\n\\begin{equation}\n\\widetilde f(x, \\mu) \\triangleq f(x) + \\mu  \\frac{1}{\\sum_{i=1}^m g^i(x)}\n\\label{eq:barFun}\n\\end{equation}\nwhere $\\widetilde f \\colon \\Re^n \\times \\Re \\to \\Re$.\nThe optimization algorithm is then applied to the new function $\\widetilde f(x,\\mu)$.\nNote that~\\eqref{eq:barFun} requires that $x$ is in the interior of the feasible set\\footnote{I.e., $x$ satisfies the strict inequality $g(x) > 0$.}.\n\n\\indent A drawback of barrier functions is that the boundary of the feasible set\ncan not be reached.\nBy selecting the weighting factors small, one can get close to the boundary. \nHowever, too small a weighting factor can cause the cost function to be ill-conditioned,\nwhich can cause problems for the optimization algorithm.\n\nMoreover, if the variation of the iterates between successive iterations is too big,\nthen the feasible boundary can be crossed. Such a behavior must be prevented\nby the optimization algorithm, which can produce additional problems.\\\\\n\n\nFor barrier functions, one can start with a moderately large weighting factor $\\mu$ \nand let $\\mu$ tend to zero during the optimization process. \nThat is, one constructs a sequence\n\\begin{equation}\n  \\mu_0 > \\ldots > \\mu_i > \\mu_{i+1} > \\ldots > 0.\n  \\label{eq:barFunWeiFac}\n\\end{equation}\nSection~\\ref{sec:ImpWeiFac} shows how $\\mu_i$ can be computed in the coarse of the optimization.\n\nBarrier functions do not allow formulating equality constraints of the form~\\eqref{eq:equCon}.\n\n% --------------------\n\\subsection{Penalty Functions}\n\nIn contrast to barrier functions, \npenalty functions allow crossing the boundary of the feasible set, and they allow\nimplementation of equality constraints of the form~\\eqref{eq:equCon}. \nPenalty functions add a positive term to the cost function if a constraint is violated.\n\n\\noindent To implement a penalty function for $g(x) \\le 0$, where\n$g \\colon \\Re^n \\to \\Re^m$ is once continuously differentiable and each element is strictly\nmonotone decreasing,\nthe cost function $f \\colon \\Re^n \\to \\Re$ can\nbe modified to\n\\begin{equation}\n\\widetilde f(x, \\mu) \\triangleq f(x) + \\mu  \\sum_{i=1}^m \\max(0,  g^i(x))^2,\n\\label{eq:penFun}\n\\end{equation}\nwhere $\\widetilde f \\colon \\Re^n \\times \\Re \\to \\Re$ is once continuously differentiable in $x$.\nThe optimization algorithm is then applied to the new function $\\widetilde f(x,\\mu)$.\n\nAs for the barrier method, selecting the weighting factor $\\mu$ is not trivial.\nToo small a value for $\\mu$ produces too big a violation of the constraint.\nHence, the boundary of the feasible set can be exceeded by an unacceptable amount.\nToo large a value of $\\mu$ can lead to ill-conditioning of the cost function,\nwhich can cause numerical problems.\\\\\n\nThe weighting factors have to satisfy\n\\begin{equation}\n   0 < \\mu_0 < \\ldots < \\mu_i < \\mu_{i+1} < \\ldots,\n  \\label{eq:penFunWeiFac}\n\\end{equation}\nwith $\\mu_i \\to \\infty$, as $i \\to \\infty$.\nSee Section~\\ref{sec:ImpWeiFac} for how to adjust $\\mu_i$.\n% ---------------------------------------\n\n\\subsection{Implementation of Barrier and Penalty Functions}\n\\label{sec:ImpWeiFac}\n\nWe now discuss how the weighting factors $\\mu_i$ can be adjusted.\nFor $i \\in \\Na$, let $x^*(\\mu_i)$ be defined as the solution\n\\begin{equation}\n x^*(\\mu_i) \\triangleq \\arg \\min_{x \\in \\mathbf X} \\widetilde f(x, \\mu_i),\n\\end{equation}\nwhere $\\widetilde f(x, \\mu_i)$ is as in~\\eqref{eq:barFun} or~\\eqref{eq:penFun}, respectively.\nThen, we initialize $i=0$, select an initial value $\\mu_0 > 0$ and compute $x^*(\\mu_0)$.\nNext, we select a $\\mu_{i+1}$ such that it satisfies~\\eqref{eq:barFunWeiFac}\n(for barrier functions) or~\\eqref{eq:penFunWeiFac} (for penalty functions),\nand compute $x^*(\\mu_{i+1})$, using the initial iterate $x^*(\\mu_i)$, and increase the counter \n$i$ to $i+1$.\nThis procedure is repeated until $\\mu_i$ is sufficiently close to zero (for barrier functions)\nor sufficiently large (for penalty functions).\\\\\n\nTo recompute the weighting factors $\\mu_i$, \nusers can request GenOpt to write a counter to the simulation input file, and then compute\n$\\mu_i$ as a function of this counter.\nThe value of this counter can be retrieved by \nsetting the keyword \\texttt{WriteStepNumber} in the optimization command file to \\texttt{true},\nand specifying the string \\texttt{\\%stepNumber\\%} in the simulation input template file. \nGenOpt will replace the string \\texttt{\\%stepNumber\\%} with the current counter value \nwhen it writes the simulation input file.\nThe counter starts with the value $1$ and its increment is $1$.\\\\\n\nUsers who implement their own optimization algorithm in GenOpt can call the method\n\\texttt{increaseStepNumber(...)} in the class \\texttt{Optimizer} to increase the counter.\nIf the keyword \\texttt{WriteStepNumber} in the optimization command file is set to \\texttt{true}, the method calls the simulation to evaluate the cost function for the new value of this counter. If \\texttt{WriteStepNumber} is \\texttt{false}, no new function evaluation is performed by this method since the cost function does not depend on this counter.\\\\\n\n\n\n\n", "meta": {"hexsha": "70fd513a6d69db873c2a7eb4def560eaad64426a", "size": 10680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/manual/constraints.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/constraints.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/constraints.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": 48.3257918552, "max_line_length": 388, "alphanum_fraction": 0.725, "num_tokens": 2987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.657436308127733}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{enumitem}\n\\usepackage{graphicx}\n\\usepackage{xcolor}\n\\usepackage{float}\n\\usepackage[ruled,vlined,linesnumbered]{algorithm2e}\n\\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}\n\\author{Dan Johnson\\\\dansj}\n\\title{Problem Set 7\\\\CME 305}\n\\begin{document}\n    \\DeclareFontFamily{U}{comicdans}{}\n    \\DeclareFontShape{U}{comicdans}{m}{n}{ <-> comicdans }{}\n\n    \\usefont{U}{comicdans}{m}{n}\n\n\t\\maketitle\n\n\t\\section*{Problem 1}\n\tFirst, we show that $\\vec{p}$ is unique. We write the PageRank expression in vector form.\n\t\\begin{gather*}\n\t\t\\vec{p} = \\frac{1 - \\alpha}{|V|} \\vec{1} + \\alpha W \\vec{p}\\\\\n\t\t(I - \\alpha A D^{-1}) D D^{-1} \\vec{p} = \\frac{1 - \\alpha}{|V|} \\vec{1}\\\\\n\t\t(D - \\alpha A) D^{-1} \\vec{p} = \\frac{1 - \\alpha}{|V|} \\vec{1}\n\t\\end{gather*}\n\tIf we can show that $(D - \\alpha A)$ is invertible, then we can multiply both sides by $D(D - \\alpha A)^{-1}$, which will show that $\\vec{p}$ has one solution and is therefore unique. $(D - \\alpha A)$ is nonsingular and invertible if it is strictly diagonally dominant. A matrix $B$ is strictly diagonally dominant if $|B_{ii}| > \\sum_{j \\neq i} |B_{ij}|, \\forall i$. In our case, we need to show that $|D_{ii}| > \\sum_{j \\neq i} |-\\alpha A_{ij}|, \\forall i$. By definition, each $D_{ii} = \\sum_{j \\neq i} A_{ij}$.\n\t\\begin{gather*}\n\t\t|D_{ii}| > \\sum_{j \\neq i} |-\\alpha A_{ij}|\\\\\n\t\t\\left|\\sum_{j \\neq i} A_{ij}\\right| > \\sum_{j \\neq i} |-\\alpha A_{ij}|\\\\\n\t\t\\sum_{j \\neq i} A_{ij} > \\sum_{j \\neq i} \\alpha A_{ij}\n\t\\end{gather*}\n\t$\\alpha \\in (0, 1)$, so this is clearly true. Therefore, $(D - \\alpha A)$ is invertible which means that $\\vec{p}$ has one solution and is therefore unique.\n\t$\\blacksquare$\n\t\n\tNow we look to compute $\\vec{p}$. We construct a new graph $G' = (V', E')$ so that we can solve a Laplacian system. Let $V' = V \\cup \\{ v \\}$.\n\tLet $E' = \\{ e \\text{ with weight } \\alpha w_e | \\forall e \\in E \\} \\cup \\{ \\{u,v \\} \\text{ with weight } (1 - \\alpha) \\deg_G(u) | \\forall u \\in V \\}$. We now construct $D'$, $A'$, and $\\mathcal{L}'$.\n\t\\begin{gather*}\n\t\tD' = \n\t\t\\begin{pmatrix}\n\t\t\\alpha D + (1 - \\alpha) D & \\vec{0}\\\\\n\t\t\\vec{0}^T & (1-\\alpha) \\vec{1}^T D \\vec{1}\n\t\t\\end{pmatrix}\\\\\n\t\tA' = \n\t\t\\begin{pmatrix}\n\t\t\\alpha A & (1-\\alpha) D \\vec{1}\\\\\n\t\t(1-\\alpha) (D \\vec{1})^T & 0\n\t\t\\end{pmatrix}\\\\\n\t\t\\mathcal{L}' = \n\t\t\\begin{pmatrix}\n\t\tD - \\alpha A & -(1-\\alpha) D \\vec{1}\\\\\n\t\t-(1-\\alpha) (D \\vec{1})^T & (1-\\alpha) \\vec{1}^T D \\vec{1}\n\t\t\\end{pmatrix}\n\t\\end{gather*}\n\tWe now want to solve a Laplacian system that computes $\\vec{p}$. We note that $G'$ is fully connected by construction, so $\\mathcal{L}' \\vec{1} = 0 \\vec{1}$. We construct $\\vec{x}'$ and $\\vec{b}'$ so that solving the Laplacian system $\\mathcal{L}' \\vec{x}' = \\vec{b}'$ solves for $\\vec{p}$.\n\t\\begin{gather*}\n\t\t\\vec{x}' = \n\t\t\\begin{pmatrix}\n\t\tD^{-1}\\vec{p}\\\\\n\t\t1\n\t\t\\end{pmatrix}\\\\\n\t\t\\vec{b}' = \n\t\t\\begin{pmatrix}\n\t\t\\frac{1 - \\alpha}{|V|} \\vec{1} - (1-\\alpha) D\\vec{1}\\\\\n\t\t-(1-\\alpha) (D \\vec{1})^T D^{-1}\\vec{p} + (1-\\alpha) \\vec{1}^T D \\vec{1}\n\t\t\\end{pmatrix}\\\\\n\t\t\\vec{b}' = \n\t\t\\begin{pmatrix}\n\t\t\\frac{1 - \\alpha}{|V|} \\vec{1} + (\\alpha - 1) D\\vec{1}\\\\\n\t\t(\\alpha-1) \\vec{1}^T \\vec{p} + (1-\\alpha) \\vec{1}^T D \\vec{1}\n\t\t\\end{pmatrix}\\\\\n\t\t\\vec{b}' = \n\t\t\\begin{pmatrix}\n\t\t\\frac{1 - \\alpha}{|V|} \\vec{1} + (\\alpha - 1) D\\vec{1}\\\\\n\t\t\\alpha-1 + (1-\\alpha) \\vec{1}^T D \\vec{1}\n\t\t\\end{pmatrix}\n\t\\end{gather*}\n\tSo, now we have our Laplacian system $\\mathcal{L}' \\vec{x}' = \\vec{b}'$. The system is solved in $O(\\mathcal{T})$ time and gives us back some $\\vec{x}''$. Since $\\mathcal{L}' \\vec{1} = 0 \\vec{1}$, we notice that our target solution $\\vec{x}' = \\vec{x}'' + c\\vec{1}$. So, we solve for $c$ knowing that the last component of $\\vec{x}'$ is 1 and using the last component of the solution to the Laplacian $\\vec{x}''$.\n\t\\begin{gather*}\n\t\t1 = [\\vec{x}'']_{n+1} + c\n\t\\end{gather*}\n\tWe then get $\\vec{x}'$ easily. The first $n$ components of this vector are $D^{-1}\\vec{p}$. So, we get $\\vec{p} = D \\vec{x}'$. So, the algorithm constructs $G'$ and then $\\mathcal{L}$ and $\\vec{b}'$ all in $O(|V| + |E|)$ time. It then solves this Laplacian system in $O(\\mathcal{T})$ time and gets $\\vec{p}$ in $O(|V| + |E|)$ time. Therefore, the total run time of this algorithm is $O(|V| + |E| + \\mathcal{T})$.\n\t$\\blacksquare$\n\t\n\t\\section*{Problem 2}\n\t\\begin{align*}\n\t\tM \n\t\t&= D^{-1/2} \\tilde{W} D^{1/2}\\\\\n\t\t&= D^{-1/2} \\frac{1}{2} (I + A D^{-1}) D^{1/2}\\\\\n\t\t&= \\frac{1}{2} (D^{-1/2} D^{1/2} + D^{-1/2} A D^{-1/2})\\\\\n\t\t&= \\frac{1}{2} (I + D^{-1/2} A D^{-1/2})\n\t\\end{align*}\n\tThis matrix is clearly symmetric because $I$, $D^{-1/2}$, and $A$ are symmetric. We now use the normalized Laplacian.\n\t\\begin{align*}\n\t\tM\n\t\t&= \\frac{1}{2} (I + D^{-1/2} A D^{-1/2})\\\\\n\t\t&= \\frac{1}{2} (I + I - N(G))\\\\\n\t\t&= I - \\frac{1}{2} N(G)\n\t\\end{align*}\n\tWe find the relationship between eigenvalues of $N$ and $M$.\n\t\\begin{gather*}\n\t\tN(G) \\vec{v}_i = \\lambda_i(N(G)) \\vec{v}_i\\\\\n\t\t\\frac{1}{2} N(G) \\vec{v}_i = \\frac{1}{2} \\lambda_i(N(G)) \\vec{v}_i\\\\\n\t\t\\vec{v}_i - \\frac{1}{2} N(G) \\vec{v}_i = \\vec{v}_i - \\frac{1}{2} \\lambda_i(N(G)) \\vec{v}_i\\\\\n\t\t\\left( I - \\frac{1}{2} N(G) \\right) \\vec{v}_i = \\left(1 - \\frac{1}{2} \\lambda_i(N(G)) \\right) \\vec{v}_i\\\\\n\t\tM \\vec{v}_i = \\left(1 - \\frac{1}{2} \\lambda_i(N(G)) \\right) \\vec{v}_i\\\\\n\t\t\\lambda_i(M) = 1 - \\frac{1}{2} \\lambda_i(N)\n\t\\end{gather*}\n\tThe largest eigenvalue for $M$ is the smallest for $N$. From the notes, we know that $\\lambda_1(N) = 0$, so $\\lambda_{\\max}(M) = 1$. The second smallest eigenvalue of $N$ is $\\lambda_2(N)$, so the second largest eigenvalue of $M$ is $\\lambda_{n-1}(M) = 1 - \\frac{1}{2} \\lambda_2(N)$.\n\t$\\blacksquare$\n\t\n\t\\section*{Problem 3}\n\tFirst, we want to get $\\tilde{W}^k$ into an easier form. Let $M = D^{-1/2} \\tilde{W} D^{1/2}$ like in problem 2.\n\t\\begin{align*}\n\t\t\\tilde{W} = D^{1/2} M D^{-1/2}\\\\\n\t\t\\tilde{W}^k = D^{1/2} M^k D^{-1/2}\n\t\\end{align*}\n\tLet $x = p - \\frac{1}{||d||_1}d$.\n\t\\begin{align*}\n\t\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1 \n\t\t&= \\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1} \\tilde{W}^k d\\right|\\right|_1\\\\\n\t\t&= \\left|\\left|\\tilde{W}^k x\\right|\\right|_1\n\t\\end{align*}\n\tWhy does $\\tilde{W}^k d = d$?\n\t\\begin{align*}\n\t\t\\tilde{W} d \n\t\t&= \\frac{1}{2} (I + A D^{-1}) d\\\\\n\t\t&= \\frac{1}{2} (d + A \\vec{1})\\\\\n\t\t&= \\frac{1}{2} (d + d)\\\\\n\t\t&= d\\\\\n\t\t&\\downarrow\\\\\n\t\t\\tilde{W}^k d &= d\n\t\\end{align*}\n\tWe now look back at the LHS.\n\t\\begin{gather*}\n\t\t\\left|\\left|\\tilde{W}^k x\\right|\\right|_1 \n\t\t\\leq \\sqrt{n} \\left|\\left|\\tilde{W}^k x\\right|\\right|_2 \n\t\t= \\sqrt{n} \\left|\\left|D^{1/2} M^k D^{-1/2} x\\right|\\right|_2\n\t\t\\leq \\sqrt{n} \\left|\\left|D^{1/2}\\right|\\right|_2 \\left|\\left|M^k D^{-1/2} x\\right|\\right|_2\\\\\n\t\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1 \n\t\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} \\left|\\left|M^k D^{-1/2} x\\right|\\right|_2\\\\\n\t\\end{gather*}\n\tFrom problem 2, we know the largest eigenvalue of $M$ is 1.\n\t\\begin{align*}\n\t\tM \\sqrt{d}\n\t\t&= \\frac{1}{2} (I + D^{-1/2} A D^{-1/2}) \\sqrt{d}\\\\\n\t\t&= \\frac{1}{2} (\\sqrt{d} + D^{-1/2} A \\vec{1})\\\\\n\t\t&= \\frac{1}{2} (\\sqrt{d} + D^{-1/2} d)\\\\\n\t\t&= \\frac{1}{2} (\\sqrt{d} + \\sqrt{d})\\\\\n\t\t&= \\sqrt{d}\\\\\n\t\\end{align*}\n\tSo, we know that $\\sqrt{d}$ is the eigenvector of the largest eigenvalue. If $\\sqrt{d} \\perp D^{-1/2} x$, then we can bound the 2 norm with the second largest eigenvalue.\n\t\\begin{align*}\n\t\t\\sqrt{d}^T (D^{-1/2} x) \n\t\t&= \\vec{1}^T \\left( p - \\frac{1}{||d||_1}d \\right)\\\\\n\t\t&= 1 - 1\\\\\n\t\t&= 0\n\t\\end{align*}\n\tThe first term is zero because the sum of probabilities is 1 and the second term is 1 by definition. So, we can bound $\\left|\\left|M^k D^{-1/2} x\\right|\\right|_2$ using the second largest eigenvalue: $1 - \\frac{1}{2} \\lambda_2(N)$.\n\t\\begin{gather*}\n\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1 \n\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} \\left|\\left|M^k D^{-1/2} x\\right|\\right|_2\n\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} \\left|\\left|(1 - \\frac{1}{2} \\lambda_2(N))^k D^{-1/2} x\\right|\\right|_2\\\\\n\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1\n\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} (1 - \\frac{1}{2} \\lambda_2(N))^k \\left|\\left|D^{-1/2}\\right|\\right|_2  \\left|\\left|x\\right|\\right|_2\n\t\\end{gather*}\n\tBound $\\left|\\left|D^{-1/2}\\right|\\right|_2$, $\\left|\\left|x\\right|\\right|_2$, and $(1 - \\frac{1}{2} \\lambda_2(N))^k$.\n\t\\begin{gather*}\n\t\t\\left|\\left|D^{-1/2}\\right|\\right|_2 \\leq \\frac{1}{\\sqrt{d_{\\min}}}\\\\\n\t\t\\left|\\left|x\\right|\\right|_2 = \\left|\\left|p - \\frac{1}{||d||_1}d\\right|\\right|_2 \\leq 1 + 1 = 2\\\\\n\t\t(1 - \\frac{1}{2} \\lambda_2(N))^k \\leq \\exp \\left( -\\frac{k}{2} \\lambda_2(N) \\right)\n\t\\end{gather*}\n\tNow we can finally bound it.\n\t\\begin{gather*}\n\t\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1\n\t\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} \\exp \\left( -\\frac{k}{2} \\lambda_2(N) \\right) \\frac{1}{\\sqrt{d_{\\min}}}  2 \n\t\t\\leq \\epsilon\\\\\n\t\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1\n\t\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} \\exp \\left( -\\frac{c}{2} \\log(\\frac{n d_{\\max}}{d_{\\min}}) \\right) \\frac{1}{\\sqrt{d_{\\min}}}  2 \n\t\t\\leq \\epsilon\\\\\n\t\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1\n\t\t\\leq \\sqrt{n} \\sqrt{d_{\\max}} \\exp (c) \\frac{\\sqrt{d_{\\min}}}{\\sqrt{n} \\sqrt{d_{\\max}}} \\frac{1}{\\sqrt{d_{\\min}}}  2 \n\t\t\\leq \\epsilon\\\\\n\t\t\\left|\\left|\\tilde{W}^k p - \\frac{1}{||d||_1}d\\right|\\right|_1\n\t\t\\leq  \\exp (c)   2 \n\t\t\\leq \\epsilon\\\\\n\t\t\\text{Suppose } c = \\log (1/4)\\\\\n\t\t\\exp (\\log (1/4))   2 = 1/2 \\leq \\epsilon\n\t\\end{gather*}\n\tSo, we can clearly pick a $c$ such that the LHS is less than or equal to $\\epsilon$. We can always pick a $c$ such that this is true given a $\\epsilon$. \n\t\\begin{gather*}\n\t\tc \\leq \\log \\left( \\frac{\\epsilon}{2}\\right)\\\\\n\t\t\\text{Example: } c = \\log \\left( \\frac{\\epsilon}{2}\\right) - 1\n\t\\end{gather*}\n\tTherefore, we have shown that $k$ is of the given form.\n\t$\\blacksquare$\n\t\n\t\\section*{Problem 4}\n\t\\begin{enumerate}[label=\\alph*.]\n\t\t\\item We think about this problem using effective resistance. We know what the commute time from $a$ to $b$ is from lemma 3 in lecture 14.\n\t\t\\begin{gather*}\n\t\t\tC_{ab} = ||\\vec{d}||_1 (\\vec{1}_a - \\vec{1}_b)^T  \\mathcal{L}^\\dagger (\\vec{1}_a - \\vec{1}_b)\n\t\t\\end{gather*}\n\t\tWe also know the effective resistance between $a$ and $b$ from the same lecture.\n\t\t\\begin{gather*}\n\t\t\t\\tilde{R}_{ab} = \\sum_{e \\in E} r_e f_e^2 = (\\vec{1}_a - \\vec{1}_b)^T  \\mathcal{L}^\\dagger (\\vec{1}_a - \\vec{1}_b)\n\t\t\\end{gather*}\n\t\tSo, we know that the commute time between $a$ and $b$ in terms of the effective resistance between $a$ and $b$. \n\t\t\\begin{gather*}\n\t\t\tC_{ab} = \\left( \\sum_{v \\in V} \\deg(v) \\right) \\tilde{R}_{ab}\n\t\t\\end{gather*}\n\t\tWe know that the size of the min cut separating $a$ and $b$ is 1, so the only path between $a$ and $b$ is the edge $\\{a, b\\}$. The effective resistance $\\tilde{R}_{ab}$ is therefore just the resistance between $a$ and $b$ which is 1. We also know that $\\sum_{v \\in V} \\deg(v) =2m$ because every edge is counted twice, once at each endpoint. \n\t\t\\begin{gather*}\n\t\tC_{ab} = (2m) (1) = 2m\n\t\t\\end{gather*}\n\t\t\n\t\t\\item Again, we have the commute time in terms of effective resistance.\n\t\t\\begin{gather*}\n\t\tC_{ab} = \\left( \\sum_{v \\in V} \\deg(v) \\right) \\tilde{R}_{ab} = 2 m \\tilde{R}_{ab}\n\t\t\\end{gather*}\n\t\tWe want to show that this is upper-bounded by $2m d(a, b)$.\n\t\t\\begin{align*}\n\t\t\tC_{ab} &\\leq 2m d(a, b)\\\\\n\t\t\t2 m \\tilde{R}_{ab} &\\leq 2m d(a, b)\\\\\n\t\t\t\\tilde{R}_{ab} &\\leq d(a, b)\n\t\t\\end{align*}\n\t\tWhen we find the effective resistance, we have to consider all paths between $a$ and $b$. If all paths use the same edge, the edges are in series and the resistance is added normally. If the edges are used in some of the paths, the edges are in parallel, so the effective resistance is defined as $\\frac{1}{\\tilde{R}_{ab}} = \\frac{1}{R_1} + \\frac{1}{R_2}$. In our case, $R = 1$ for all edges. This means that the largest effective resistance is if all the edges between $a$ and $b$ are in series or, equivalently, there is just one path between the two nodes. In this case, every edge in the path would sum to $d(a, b)$, which means $C_{ab} = 2m d(a, b)$. Now if we have any other path between the two nodes, they will be in parallel.\n\t\t\\begin{gather*}\n\t\t\t\\frac{1}{\\tilde{R}_{ab}} = \\frac{1}{R_1} + \\frac{1}{R_2}\n\t\t\\end{gather*}\n\t\tClearly, $\\tilde{R}_{ab}$ is largest when the effective resistance of the second path is infinitely large which can be interpreted as no path existing. Since adding any path lowers the effective resistance, the commute time must be upper-bounded by the case of a single shortest path.\n\t\t\\begin{align*}\n\t\tC_{ab} &\\leq 2m d(a, b)\n\t\t\\end{align*}\n\t\\end{enumerate}\n\t\n\t\\section*{Problem 5}\n\t\\begin{enumerate}[label=\\alph*.]\n\t\t\\item If $G$ is a tree, there is only one path between $a$ and $b$. Otherwise, this induces a cycle and $G$ is not a tree. As argued in problem 4 part b, in the case where there is only one path between $a$ and $b$, the effective resistance is the sum of all the weights of this path. With each weight being one, the effective resistance $\\tilde{R}_{ab}$ becomes $d(a, b)$.\n\t\t\\begin{gather*}\n\t\tC_{ab} = \\left( \\sum_{v \\in V} \\deg(v) \\right) \\tilde{R}_{ab} = 2 m d(a, b)\n\t\t\\end{gather*}\n\t\t\n\t\t\\item \n\t\tFirst, we note the relationship between hit time and commute time.\n\t\t\\begin{gather*}\n\t\t\tC_{ab} = H_{ab} + H_{ba}\n\t\t\\end{gather*}\n\t\tI state that the max commute time in a graph is larger than the max hit time. We easily prove this by taking the nodes from the max hit time and see that the commute time for these nodes is the max hit time plus the time it takes to get back to the first node. In the lecture notes, we found an upper bound on the cover time.\n\t\t\\begin{align*}\n\t\t\t\\text{Cover}(G) \n\t\t\t&\\leq \\left( \\max_{a, b \\in V} H_{ab} \\right) O(\\log n)\\\\\n\t\t\t&\\leq \\left( \\max_{a, b \\in V} C_{ab} \\right) O(\\log n)\\\\\n\t\t\t&\\leq 2m d(a, b) O(\\log n)\\\\\n\t\t\t&\\leq 2m n O(\\log n)\\\\\n\t\t\t&\\leq O( mn \\log n)\n\t\t\\end{align*}\n\t\tIn the third line, we use the upper bound found in problem 4 part b. In the forth line we note that $d(a, b) < n$.\n\t\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "8dbe4e3cc340661591f99a0dbbbd9e8b4f02313b", "size": 14065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/hw7.tex", "max_stars_repo_name": "dsjohns2/Comic-Dans", "max_stars_repo_head_hexsha": "0547e9044d010919b61cb5e6df656e40190c34d2", "max_stars_repo_licenses": ["MIT"], "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/hw7.tex", "max_issues_repo_name": "dsjohns2/Comic-Dans", "max_issues_repo_head_hexsha": "0547e9044d010919b61cb5e6df656e40190c34d2", "max_issues_repo_licenses": ["MIT"], "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/hw7.tex", "max_forks_repo_name": "dsjohns2/Comic-Dans", "max_forks_repo_head_hexsha": "0547e9044d010919b61cb5e6df656e40190c34d2", "max_forks_repo_licenses": ["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.4790874525, "max_line_length": 736, "alphanum_fraction": 0.6014930679, "num_tokens": 5957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.6574362970197446}}
{"text": "\\chapter{Constructing an formula}\n\\label{chapter:constructingaformula}\nThe class \\formulaClass represents SMT formulas, which are\ndefined according to the following abstract grammar\n\n\\[\n\\begin{array}{rccccccccccccc}\n  p &\\quad ::=\\quad & a & | & b & | & x & | & (p + p) & | & (p \\cdot p) & | & (p^e) \\\\\n  v &\\quad ::=\\quad & u & | & x \\\\\n  s &\\quad ::=\\quad & f(v,\\ldots,v) & | & u & | & x \\\\\n  e &\\quad ::=\\quad & s = s \\\\\n  c &\\quad ::=\\quad & p = 0 & | & p < 0 & | & p \\leq 0 & | & p > 0 & | & p \\geq 0 & | & p \\neq 0 \\\\\n \\varphi &\\quad ::=\\quad & c & | & (\\neg \\varphi) & | &\n (\\varphi\\land\\varphi) & | &\n (\\varphi\\lor\\varphi) & | & \n (\\varphi\\rightarrow\\varphi) & | \\\\ &&\n (\\varphi\\leftrightarrow\\varphi) & | &\n (\\varphi\\oplus\\varphi)\n\\end{array}\n\\]\n\nwhere $a$ is a rational number, $e$ is a natural number greater one, $b$ is a \\emph{Boolean variable} and the \\emph{arithmetic variable} $x$ is an inherently existential quantified and either real- or integer-valued. We call $p$ a \\emph{polynomial} and use a \\carl multivariate polynomial with \\cln rationals as coefficients to represent it. The \\emph{uninterpreted function} $f$ is of a certain \\emph{order} $o(f)$ and each of its $o(f)$ arguments are either an arithmetic variable or an \\emph{uninterpreted variable} $u$, which is also inherently existential quantified, but has no domain specified. Than an \\emph{uninterpreted equation} $e$ has either an uninterpreted function, an uninterpreted variable or an arithmetic variable as left-hand respectively right-hand side. A \\emph{constraint} $c$ compares a polynomial to zero, using a \\emph{relation symbol}. Furthermore, we keep constraints in a normalized representation to be able to differ them better.\n\n\\section{Normalized constraints}\nA normalized constraint has the form\n\\[a_1\\overbrace{x_{1,1}^{e_{1,1}}\\cdot\\ldots\\cdot x_{1,k_1}^{e_{1,k_1}}}^{m_1}+\\ldots+a_n\\overbrace{x_{n,1}^{e_{n,1}}\\cdot\\ldots\\cdot x_{n,k_n}^{e_{n,k_n}}}^{m_n}\\ + \\ d\\ \\sim \\ 0\\]\nwith $n\\geq0$, the \\emph{$i$th coefficient} $a_i$ being an integral number ($\\neq 0$), $d$ being a integral number, $x_{i,j_i}$ being a real- or integer-valued variable and $e_{i,j_i}$ being a natural number greater zero (for all $1\\leq i\\leq n$ and $1\\leq j_i\\leq k_i$). Furthermore, it holds that\n$x_{i,j_i}\\neq x_{i,l_i}$ if $j_i\\neq l_i$ (for all $1\\leq i\\leq n$ and $1\\leq j_i, l_i\\leq k_i$) and $m_{i_1}\\neq m_{i_2}$ if $i_1\\neq i_2$ (for all $1\\leq i_1,i_2\\leq n$). If $n$ is $0$ then $d$ is $0$ and $\\sim$ is either $=$ or $<$. In the former case we have the normalized representation of any variable-free consistent constraint, which semantically equals \\true, and in the latter case we have the normalized representation of any variable-free inconsistent constraint, which semantically equals \\false. Note that the monomials and the variables in them are ordered according the \\polynomialOrder of \\carl.\nMoreover, the first coefficient of a normalized constraint (with respect to this order) is always positive and the greatest common divisor of $a_1,\\ldots,\\ a_n,\\ d$ is $1$. If all variable are integer valued the constraint is further simplified to\n\\[\\frac{a_1}{g}\\cdot m_1\\ +\\ \\ldots\\ +\\ \\frac{a_n}{g}\\cdot m_n\\ + \\ d'\\  \\sim' \\ 0,\\]\nwhere $g$ is the greatest common divisor of $a_1,\\ldots,\\ a_n$, \n\\[\\sim'=\\left\\{\n\\begin{array}{ll}\n\\leq, &\\text{ if }\\sim\\text{ is }< \\\\\n\\geq, &\\text{ if }\\sim\\text{ is }> \\\\\n\\sim, &\\text{ otherwise }\n\\end{array}\n\\right.\\]\nand\n\\[\nd' = \\left\\{\n\\begin{array}{ll}\n\\lceil\\frac{d}{g}\\rceil &\\text{ if }\\sim'\\text{ is }\\leq \\\\[1.5ex]\n\\lfloor\\frac{d}{g}\\rfloor &\\text{ if }\\sim'\\text{ is }\\geq \\\\[1.5ex]\n\\frac{d}{g} &\\text{ otherwise }\n\\end{array}\n\\right.\\]\nIf additionally $\\frac{d}{g}$ is not integral and $\\sim'$ is $=$, the constraint is simplified $0<0$, or if $\\sim'$ is $\\neq$,\nthe constraint is simplified $0=0$.\n\nWe do some further simplifactions, such as the elimination of multiple roots of the left-hand sides in equations and inequalities with the relation symbol $\\neq$, e.g., $x^3=0$ is simplified to $x=0$. We also simplify constraints whose left-hand sides are obviously positive (semi)/negative (semi) definite, e.g., $x^2\\leq 0$ is simplified to $x^2=0$, which again can be simplified to $x=0$ according to the first simplification rule.\n\n\\section{Boolean combinations of constraints and Boolean variables}\nA formula is stored as a directed acyclic graph, where the intermediate nodes represent the Boolean operations on the sub-formulas represented by the successors of this node. The leaves (nodes without successor) contain either a Boolean variable, a constraint or an uninterpreted equality. Equal formulas, that is formulas being leaves and containing the same element or formulas representing the same operation on the same sub-formulas, are stored only once.\n\nThe construction of formulas, which are represented by the \\formulaClass, is mainly based on the presented abstract grammar. A formula being a leaf wraps the corresponding objects representing a Boolean variable, a constraint or an uninterpreted equality. A Boolean combination of Boolean variables, constraints and uninterpreted equalities consists of a Boolean operator and the sub-formulas it interconnects. For this purpose we either firstly create a set of formulas containing all sub-formulas and then construct the Formula or (if the formula shall not have more than three sub-formulas) construct the formula directly passing the operator and sub-formulas. Formulas, constraints and uninterpreted equalities are non-mutable, once they are constructed. %TODO: explain mutable member of formulas for information storage\n\nWe give a small example constructing the formula \\[(\\neg b\\ \\land\\ x^2-y<0\\ \\land\\ 4x+y-8y^7=0 )\\ \\rightarrow\\ (\\neg(x^2-y<0)\\ \\lor\\ b ),\\] with the Boolean variable $b$ and the real-valued variables $x$ and $y$, for demonstration. Furthermore, we construct the UF formula\n\\[v = f(u,u)\\ \\oplus\\ w \\neq u\\]\nwith $u$, $v$ and $w$ being uninterpreted variables of not specified domains $S$ and $T$, respectively,\nand $f$ is an uninterpreted function with not specified domain $T^{S\\times S}$.\n\nFirstly, we show how to create real valued (integer valued analogously with \\texttt{VT\\_INT}), Boolean and uninterpreted variables:\n\\scriptsize\n\\begin{verbatim}\ncarl::Variable x = smtrat::newVariable( \"x\", carl::VariableType::VT_REAL );\ncarl::Variable y = smtrat::newVariable( \"y\", carl::VariableType::VT_REAL );\ncarl::Variable b = smtrat::newVariable( \"b\", carl::VariableType::VT_BOOL );\ncarl::Variable u = smtrat::newVariable( \"u\", carl::VariableType::VT_UNINTERPRETED );\ncarl::Variable v = smtrat::newVariable( \"v\", carl::VariableType::VT_UNINTERPRETED );\ncarl::Variable w = smtrat::newVariable( \"w\", carl::VariableType::VT_UNINTERPRETED );\n\\end{verbatim}\n\\normalsize\nUninterpreted variables, functions and function instances combined in equations or inequalities comparing them are constructed the following way.\n\\scriptsize\n\\begin{verbatim}\ncarl::Sort sortS = smtrat::newSort( \"S\" );\ncarl::Sort sortT = smtrat::newSort( \"T\" );\ncarl::UVariable uu( u, sortS );\ncarl::UVariable uv( v, sortT );\ncarl::UVariable uw( w, sortS );\ncarl::UninterpretedFunction f = smtrat::newUF( \"f\", sortS, sortS, sortT );\ncarl::UFInstance f1 = smtrat::newUFInstance( f, uu, uw );\ncarl::UEquality ueqA( uv, f1, false );\ncarl::UEquality ueqB( uw, uu, true );\n\\end{verbatim}\n\\normalsize\nNext we see an example how to create polynomials, which form the left-hand sides of the constraints:\n\\scriptsize\n\\begin{verbatim}\nsmtrat::Poly px( x );\nsmtrat::Poly py( y );\nsmtrat::Poly lhsA = px.pow(2) - py;\nsmtrat::Poly lhsB = smtrat::Rational(4) * px + py - smtrat::Rational(8) * py.pow(7);\n\\end{verbatim}\n\\normalsize\nConstraints can then be constructed as follows:\n\\scriptsize\n\\begin{verbatim}\nsmtrat::ConstraintT constraintA( lhsA, carl::Relation::LESS );\nsmtrat::ConstraintT constraintB( lhsB, carl::Relation::EQ );\n\\end{verbatim}\n\\normalsize\nNow, we can construct the atoms of the Boolean formula\n\\scriptsize\n\\begin{verbatim}\nsmtrat::FormulaT atomA( constraintA );\nsmtrat::FormulaT atomB( constraintB );\nsmtrat::FormulaT atomC( b );\nsmtrat::FormulaT atomD( ueqA );\nsmtrat::FormulaT atomE( ueqB );\n\\end{verbatim}\n\\normalsize\nand the formulas itself (either with a set of arguments or directly):\n\\scriptsize\n\\begin{verbatim}\nsmtrat::FormulasT subformulasA;\nsubformulasA.insert( smtrat::FormulaT( carl::FormulaType::NOT, atomC ) );\nsubformulasA.insert( atomA );\nsubformulasA.insert( atomB );\nsmtrat::FormulaT phiA( carl::FormulaType::AND, std::move(subformulasA) );\nsmtrat::FormulaT phiB( carl::FormulaType::NOT, atomA )\nsmtrat::FormulaT phiC( carl::FormulaType::OR, phiB, atomC );\nsmtrat::FormulaT phiD( carl::FormulaType::IMPLIES, phiA, phiC );\nsmtrat::FormulaT phiE( carl::FormulaType::XOR, atomD, atomE );\n\\end{verbatim}\n\\normalsize\nNote, that $\\land$ and $\\lor$ are $n$-ary constructors, $\\neg$ is a unary constructor and all the other Boolean operators are binary.\n\n", "meta": {"hexsha": "a386713f08ee5608914bf385bda64818ef350a2e", "size": 8958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/constructingformulas.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": "manual/constructingformulas.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": "manual/constructingformulas.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": 68.9076923077, "max_line_length": 961, "alphanum_fraction": 0.7234873856, "num_tokens": 2732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6573066267918805}}
{"text": "\\documentclass{acmsiggraph}\n\n\\usepackage{parskip}\n\\usepackage{graphicx}\n\\usepackage{footmisc}\n\\usepackage{amsmath}\n\\usepackage{url}\n\\onlineid{0}\n\n\\title{\\Large Plotting the Single-Electron Solution to Schr\\\"{o}dinger's Equation with OpenCL}\n\n\\author{Tim Horton\\thanks{e-mail: hortot2@rpi.edu}\\\\Rensselaer Polytechnic Institute}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{320.png}\n    \\caption{The 3-2-0 orbital of the hydrogen atom}\n\\end{figure}\n\n\\section{Abstract}\n\nThe realm of physics provides many readily parallelizable algorithms --- often involving the simple evaluation of a function at an enormous number of points in space --- which also happen to produce attractive visualizations. One such visualization is that of the probability distribution of the single electron within a hydrogen atom (or He$^+$, Li$^{2+}$, and so on). By evaluating Schr\\\"{o}dinger's equation at millions of points, one can construct a representation of the likely location of the electron --- the orbital cloud, if you will. Luckily, the evaluation of this function at a particular point is entirely independent of nearby points, so it is effectively perfect for parallelization. We will use OpenCL to develop and benchmark (on a varied array of hardware, from dated CPUs to very modern GPUs) an implementation of this algorithm which will produce a simple --- but attractive --- image of the atomic orbital of the single-electron hydrogen atom.\n\n\\section{Physics}\n\nQuantum mechanics --- since Louis de Broglie's paper {\\it Research on Quantum Theory} --- tells us that matter behaves sometimes as a wave, and other times as a particle. The electron in a hydrogen atom is no different: when it isn't being observed, it doesn't exist at a particular point in space, but instead expands as a wave. The atomic orbital cloud which we're plotting here is actually simply a plot of the density of that wave at all points surrounding the atom's nucleus.\n\nAll of the equations below are borrowed from \\cite{quantumBook}, but have been slightly modified to fit our purposes, as discussed in section \\ref{simpSection}.\n\n\\subsection{Schr\\\"{o}dinger's Equation}\n\nFrom \\cite{quantumBook}, we find the single-electron solution to Schr\\\"{o}dinger's equation:\n\n\\begin{equation}\\label{psi}\n\\psi\\left(n, l, m\\right)=\\psi_c\n\\left(\\mathit{e}^{-r/n}\\right)\n\\left(\\frac{2r}{n}\\right)^l\n\\left[L_{n-l-1}^{2l+1}\n    \\left(\\frac{2r}{n}\\right)\\right]\nY_l^m\\left(\\theta,\\phi\\right),\n\\end{equation}\n\n\\begin{equation}\\label{psiConstant}\n\\psi_c=\\sqrt{\\left(\\frac{2}{n}\\right)^3\n    \\frac{\\left(n-l-1\\right)!}{2n\\left[\\left(n+l\\right)!\\right]^3}}.\n\\end{equation}\n\nThis is the fundamental formula involved in our computation --- it is this equation which we evaluate at each sample. The result of this equation gives the probability that the single electron of our hydrogen atom is at the particular chosen location in the spherical coordinate system, $\\left(\\theta, \\phi, r\\right)$, which is the information that we eventually aim to plot.\n\nOne will notice that $\\psi_c$ is independent of the coordinates of evaluation, $\\left(\\theta, \\phi, r\\right)$, so it --- as an obvious optimization --- can be computed once and cached for the entire image.\n\nIndeed, while all of the benchmarks in this paper were done with $\\psi_c$ included, one might notice that --- since it's a constant term across the entire image, and we're scaling the image by {\\it another} constant scale factor --- that it doesn't actually affect the visualization, and can be entirely discarded. It appears that discarding the overhead required to pass this value in as an argument to each of the kernel instances and to multiply it into the value of $\\psi$ gives a performance increase of between 6 and 10 percent: quite a significant improvement for no change in output!\n\nAlso, $\\psi$ depends on two external functions: $Y$, the spherical harmonic equation (equation \\ref{yFunc}), and $L$, the Laguerre polynomial (equation \\ref{laguerre}), which will be detailed in sections \\ref{sphericalHarmonics} and \\ref{laguerreLegendre}, respectively.\n\n\\subsection{Spherical Harmonics}\n\n\\label{sphericalHarmonics}\n\n$Y$, a solution to Laplace's spherical harmonic function, provides the angular component of $\\psi$:\n\n\\begin{equation}\\label{yFunc}\nY_l^m\\left(\\theta,\\phi\\right)=\\epsilon\n\\sqrt{\\frac{\\left(2l+1\\right)}{4\\pi}\n    \\frac{\\left(l-\\left|m\\right|\\right)!}{\\left(l+\\left|m\\right|\\right)!}}\n\\mathit{e}^{{\\rm i}m\\phi}\nP^m_l\\left(\\cos\\theta\\right),\n\\end{equation}\n\n\\begin{equation}\\label{yEpsilon}\n\\epsilon=\\begin{cases}\n\\left(-1\\right)^m & \\text{$m\\ge0$} \\\\\n1 & \\text{$m<0$}\n\\end{cases}.\n\\end{equation}\n\n$Y$ depends on an additional external function, $P$, the Legendre polynomial (equation \\ref{legendre}).\n\n\\subsection{Laguerre and Legendre}\n\n\\label{laguerreLegendre}\n\nKey to the evaluation of Schr\\\"{o}dinger's equation are the Laguerre and Legendre polynomials. Unfortunately, the generation of both requires symbolically solving differential equations. \\cite{legendreCite} Since OpenCL (rightfully) lacks a symbolic differential equation solver (and the implementation of such a program is far outside of the scope of this project), we have added to our kernel a simple table of the first few polynomials, computed with Mathematica. This limits the range of input $n, l, m$ parameters which can be used with this program, but extending the tables is very simple and requires only patience.\n\nThe generating equations for these polynomials are as follows:\n\n\\begin{equation}\\label{laguerre}\nL^\\alpha_n\\left(x\\right)=\\frac{x^{-\\alpha}e^x}{n!}\\frac{d^n}{dx^n}\\left(e^{-x}x^{n+\\alpha}\\right),\n\\end{equation}\n\n\\begin{equation}\\label{legendre}\nP^u_v\\left(z\\right)=\\frac{\\left(1+z\\right)^{\\mu/2}}{\\left(1-z\\right)^{\\mu/2}}\n\\tilde{F}_{2,1}\n\\left(-v,v+1;1-\\mu;\\frac{1-z}{2}\\right),\n\\end{equation}\n\nwhere $\\tilde{F}$ is Gauss' hypergeometric function, which we don't need to bother ourselves with since we're simply allowing Mathematica to evaluate it and using the comparatively simple symbolic results in our table.\n\n\\section{Implementation}\n\n\\subsection{Overview}\n\nOur implementation is twofold: an OpenCL kernel (written in the C-like OpenCL kernel language) which performs the evaluation of all of the Schr\\\"{o}dinger's equation samples required for a single pixel of the output image, and a Python script which parses command line options, uses PyOpenCL to load and run the kernel and PIL to create the output image, and performs timed benchmarks.\n\n\\subsection{Simplifications}\n\n\\label{simpSection}\n\nThe decision was made during the implementation phase to redefine the Bohr radius so that $a=1$; this was done in order to keep intermediate numbers within the range of single-precision floating point values, as OpenCL doesn't currently support native double-precision math on any of the GPUs available for benchmarking. Since we're only using this software to generate visualizations, this doesn't affect the output; it simply scales the distances away from the atomic level. The equations above have $a=1$ already substituted in, for brevity.\n\nTo keep the implementation of this algorithm within the scope of this project, we also decided to use a fixed-camera orthogonal projection. This worked to significantly simplify the process of iteration over all of the samples, as with this restriction, the program simply has to iterate over all of the pixels in the image, evaluating many points in the $z$ dimension for each pixel, without worrying about complex transformations between coordinate systems.\n\n\\subsection{Evaluation}\n\nAfter arguments have been parsed and an OpenCL context has been created, we create a buffer large enough to store the entirety of the resultant image, and also compute the constant term of $\\psi$, both of which are passed to each instance of the kernel.\n\nFor each pixel in the image, we spawn an instance of our OpenCL kernel which evaluates 2000 samples in the $z$ dimension. Each sample represents the value of the density function, $\\psi$, at that point in space (the cartesian coordinates of the image have to be converted into spherical coordinates in order to evaluate $\\psi$). All 2000 samples are summed and stored into their respective pixel in the image buffer.\n\nOnce computation has completed, the buffer is copied back from working memory (either video memory or system memory) to the final image buffer in system memory. Once there, pixel values are scaled linearly so that the brightest pixel is 100\\% white, and the image is compressed to PNG and saved to the filesystem.\n\n\\subsection{Complex Math}\n\nThe OpenCL specification unfortunately currently does not include complex math primitives, which are necessary for the evaluation of $\\psi$. It does reserve the {\\bf complex} keyword, which suggests that perhaps support for something similar to GCC's complex type is coming in a future version of OpenCL, which would put it on ground more similar to CUDA.\n\nIn order to solve this problem, we implemented a small library of complex math functions which make use of the OpenCL {\\bf float2} type to store complex numbers. This library includes various complex number constructors, as well as exponentiation, multiplication, square root, the exponential function, and conjugation. These functions are used extensively within the evaluation of $\\psi$.\n\n\\section{Hardware}\n\nBenchmarks will be performed on a number of different computation devices across a few different computers:\n\n\\subsection{GPU}\n\n\\begin{itemize}\n\n\\item ATI Radeon 4890, 800$\\times$850MHz, 1GB, 250\\$\\footnote{All hardware prices listed are approximate launch prices. Prices of older hardware, especially the Core 2 Quad, have dropped significantly since introduction.\\label{fn:prices}}\\footnote{Tested on Windows, with ATI Stream SDK\\label{fn:windows}}\n\n\\end{itemize}\n\n\\subsection{CPUs}\n\n\\begin{itemize}\n\n\\item Intel Core i7 620M, 2$\\times$3333MHz, 4GB, 332\\$\\footref{fn:prices}\\footnote{Tested on Mac OS X, with Apple OpenCL\\label{fn:osx}}\n\n\\item Intel Core 2 Quad Q6600, 4$\\times$3000MHz, 4GB, 851\\$\\footref{fn:prices}\\footnote{Tested on Linux, with ATI Stream SDK\\label{fn:linux}}\n\n\\item Intel Core 2 Duo E7200, 2$\\times$2530MHz, 8GB, 133\\$\\footref{fn:prices}\\footref{fn:osx}\n\n\\end{itemize}\n\nThese machines run a variety of different operating systems (including Mac OS X, Windows, and Linux). Comparisons made later in this paper assume that each OS and the drivers and OpenCL implementation used within them are created equally; this is only somewhat reasonable, and should be kept in mind when interpreting results.\n\nAlso, it should be noted that while each core on a given CPU could potentially be evaluating samples in parallel, a GPU's cores are much more restricted (less general-purpose) and must work in small groups to accomplish their work. Therefore, given the kernel used for this project, the 4890 listed above only has 50 compute units (16 stream processors work together to compute a single sample).\n\n\\section{Results}\n\nThree computers have spent countless hours performing calculations to bring you the following results, as each benchmark point is the minimum of five individual trials.\n\n\\subsection{Communication Overhead}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{overheadPlot.pdf}\n    \\caption{Overhead from image buffer copy as a percentage of the total runtime; smaller values are better}\n    \\label{fig:overheadPlot}\n\\end{figure}\n\nThe algorithm we implemented for this project required no communication between  cores whatsoever during the course of the computation. The primary overhead involved in the entire process is the single copy of the $n\\times n$ output buffer from working memory into system memory, where it is then normalized, compressed, and output (we don't consider these parts of the process when measuring performance or overhead, as they're written in Python, a language not known for its performance characteristics).\n\nThe overhead incurred during this copy can be seen in the chart in figure \\ref{fig:overheadPlot} to be negligible --- in the range of a tenth of a percent of the total runtime when working on the GPU, and a one-hundred-thousandth of a percent when working on the CPU, where the data has a shorter distance to travel.\n\n\\subsection{Strong Scaling}\n\n\\label{strongScaling}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{strongPlotOne.pdf}\n    \\caption{Runtime as core count increases on the 4890 with a fixed resolution ($400\\times400$); smaller values are better}\n    \\label{fig:strongPlotOne}\n\\end{figure}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{strongPlotTwo.pdf}\n    \\caption{Speedup as core count increases (measured against the single-core run) on the 4890 with a fixed resolution ($400\\times400$); the orange line is the theoretical maximum speedup, given linear scaling and 50 execution units (800 cores / 16 cores per unit); the red line is a linear speedup curve; larger values are better}\n    \\label{fig:strongPlotTwo}\n\\end{figure}\n\nIn order to measure the strong scalability of our implementation, we fix the problem size and vary the number of processing units used to compute it. For this benchmark, we will fix the image at $400\\times400$ pixels, requiring $320,000,000$ total samples, and we will vary the number of cores of the 4890 that we use.\n\nOne can see in figure \\ref{fig:strongPlotTwo} that this implementation is strongly scalable; the speedup is almost perfectly linear as the core count increases. It should be noted that since --- for our kernel --- the 4890 only has 50 compute units, the linear increase is only maintained until we reach 50 cores; after that, the performance gains plateau as they should.\n\n\\subsection{Large- vs. Small-scale Parallelism}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{runtimePlot.pdf}\n    \\caption{Runtime vs. Resolution on all hardware; smaller values are better}\n    \\label{fig:runtimePlot}\n\\end{figure}\n\nAs one can see in figure \\ref{fig:runtimePlot}, the GPU significantly outperforms all of the CPUs. This is not surprising, as it can perform more than an order of magnitude more parallel computations, but it does validate the premise of this experiment.\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{speedupPlot.pdf}\n    \\caption{Speedup of fastest GPU (4890) over fastest CPU (Core 2 Quad) as resolution increases; larger values are better}\n    \\label{fig:speedupPlot}\n\\end{figure}\n\nFigure \\ref{fig:speedupPlot} shows that our implementation converges to an approximately 14.7x speedup (between the fastest of each class of hardware, namely, the 4890 and Core 2 Quad) as the resolution of the output image increases. Noise in the speedup values with smaller images is likely due to measurement error and the overhead and unpredictability involved when copying data to/from video memory.\n\nIt should be noted that these speedup values are across different pieces of hardware at different core clock speeds, and, as such, do not represent the actual parallel speedup gained (for that, look at section \\ref{strongScaling}). This is, instead, a representation of the performance potentially gained by moving computation to the GPU.\n\n\\subsection{Cost Effectiveness of Hardware}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{dollarPlot.pdf}\n    \\caption{Samples per second per dollar with a fixed resolution ($500\\times500$); larger values are better}\n    \\label{fig:costEffectiveness}\n\\end{figure}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{wattPlot.pdf}\n    \\caption{Samples per second per heavy-load watt with a fixed resolution ($500\\times500$); larger values are better}\n    \\label{fig:wattPlot}\n\\end{figure}\n\nOne oft-cited measure of the performance of a computational device is its {\\it performance-per-dollar}; this is especially of interest for consumers with budgets or people building large computation clusters. In order to measure performance-per-dollar, we have to define {\\it performance} in the context of our problem. In all of the plots in this section, performance is measured as the number of samples per second. Figures \\ref{fig:costEffectiveness} and \\ref{fig:wattPlot} all use a 500$\\times$500 image, with 2000 samples per pixel, for $500,000,000$ total samples.\n\nFigure \\ref{fig:costEffectiveness} illustrates the performance-per-dollar of our four devices. As is quite evident already, the 4890 --- though in the same price range as most of the other devices, and significantly cheaper than the Core 2 Quad --- manages to dominate the chart. It's safe to say that if an institution is looking into buying a large number of a particular device for scientific computation, they should seriously consider looking into high-end graphics cards. Indeed; each dollar spent on a 4890 goes 18 times farther, performance-wise, than it would if spent on the next-most-cost-effective chip, the Core 2 Duo E7200.\n\nAnother important point when considering the cost of various pieces of hardware is how much it will cost to run. One way to measure this is to consider the power efficiency of the chip, in terms of performance-per-watt. Again using the same measure of performance from our performance-per-dollar comparison, we can see in figure \\ref{fig:wattPlot} that the GPU continues to dominate, even though it requires three times more energy to run than its closest competitor, the Core 2 Quad. As one might expect, the older --- thus, less power efficient --- Core 2 Duo falls behind the other CPUs on this scale: though it was the performance-per-dollar winner out of the three CPUs, it would cost significantly more than the other two to run for any period of time.\n\n\\section{Future Work}\n\nThere are quite a few things which have come up while developing this project that would be interesting to implement if we were to continue work on the codebase. We will discuss a few of these below:\n\n\\subsection{Camera Transformation}\n\n\\label{cameraTransformation}\n\nOne key feature that is missing from the current implementation is the ability to manipulate the \"camera\" location, changing your viewport on the orbital cloud. Implementing this would add a bit of complexity, but would allow for interesting video rendering --- for example, video of the camera spinning around the atom, providing a better idea of the actual shape of the cloud. It can be hard --- without prior knowledge --- to comprehend the shape of the cloud from our current visualization.\n\nIn addition, if the number of samples was sufficiently reduced, or a fast enough video card was obtained, one could implement {\\it live} manipulation of the camera's view, which could assist in inspection of the orbital cloud to an even greater extent.\n\n\\subsection{Slicing}\n\n\\begin{figure}\n    \\includegraphics[width=84.5mm]{320-slice.png}\n    \\caption{A slice through the 3-2-0 orbital of the hydrogen atom}\n    \\label{fig:slice}\n\\end{figure}\n\nSection \\ref{cameraTransformation} covered the ideal solution to the problem of comprehending the shape of the orbital from our 2D representation --- however, if that solution proved to be too challenging, one could instead generate an animation of slices through the cloud, each slice being similar to figure \\ref{fig:slice}. This would provide another form of interesting visualization of the resulting data, rather similar to the data collected by an MRI device.\n\n\\subsection{Automatic Scaling}\n\nOur OpenCL kernel currently contains an arbitrary zoom factor which needs to be adjusted based on the orbital configuration --- higher energy electron states lead to larger probability clouds. Automatically generating this zoom factor would lead to significantly improved ease of use when changing between different configurations. This could most effectively be implemented by finding a formula for a reasonable scale factor given a set of $n, l, m$ values.\n\n\\subsection{Coloring}\n\nA third way to make the visualization more appealing (or even more informative) would be to provide some manner of colorization. One potential algorithm would be to colorize each sample based on its depth in $z$; the resulting image would then have more depth information, which might increase the ease with which it is interpreted. A variety of other coloring functions are possible, but none were pursued during this project, for time's sake.\n\n\\subsection{Generalization of Parameters}\n\nEquations \\ref{laguerre} and \\ref{legendre} provide a generalized way to construct Laguerre and Legendre polynomials, respectively. However, our implementation does not make use of these functions, instead using a table of simplified solutions, generated with Mathematica, which is limited in scope.\n\nThe length of the table determines the range of $n, l, m$ values which can be passed into our program, and is the only restriction on generality within our implementation. If one were to construct these functions on the fly from their generating equations, the algorithm would be completely generalized in terms of $n, l, m$, and would be significantly more useful from an exploratory standpoint.\n\nHowever, as discussed in section \\ref{laguerreLegendre}, this would require (at least) the implementation of a symbolic differential equation solver in OpenCL, which could potentially be a very time-consuming task (it could also increase the number of GPU stream processors per kernel required, significantly decreasing the speedup gained).\n\nAlternatively, one could write a translation program to automatically generate the table from Mathematica, removing the slow, error-prone human translation step, and very quickly expand the size of the table to something more useful.\n\n\\subsection{Multiple Electrons}\n\nAnother feature that would be incredibly cool to implement would be simulation of atoms with more than one electron. In this case, interference between the electrons changes the pattern to be significantly more complex (and much more interesting, as well). It's also a good bit more complex to compute: there is no exact solution of the Schr\\\"{o}dinger's equation for multiple electrons. Instead, an implementation would depend on a numerical differential equation solver, which would significantly affect performance.\n\n\\section{Conclusion}\n\nAfter consuming many computer-hours computing the 3-2-0 orbital repeatedly, we've come to a few clear conclusions. Firstly, scientific computation --- the calculation of atomic orbitals, at the very least --- should clearly be a prime target for porting to parallel computation on the GPU, as the field takes off. Projects like Folding@Home are already taking advantage of this (besides being massively parallel, as a web-distributed project) by providing ATI Stream SDK and CUDA ports of their client, and the last few years have seen an explosion in other such projects.\n\nWe've also found that --- for problems which are embarrassingly easy to parallelize, like this one --- it's very easy to implement your problem using OpenCL. We've used MPI and pthreads in the past, and it seems that OpenCL (perhaps because it's a more modern API) is a bit easier to use in terms of implementation. The added benefit of kernels running on a wider array of hardware (not just the CPU, like MPI, but on the GPU as well) means that OpenCL is a no-brainer --- at least for this sort of simple project. It's quite likely that a problem requiring a large amount of inter-kernel communication would be better suited by something with more communications primitives, like MPI. Indeed, besides {\\it barrier}, OpenCL doesn't seem to have any manner of inter-kernel communications functions.\n\n\n\n\n\\section{Code}\n\nAll of the code developed for this project is available under the two-clause BSD license, and is hosted on GitHub:\n\n\\url{http://github.com/hortont424/orbitals}\n\n\\url{git://github.com/hortont424/orbitals.git}\n\nThe code has only been tested with the Apple and ATI OpenCL compilers, but should work with few to no changes on NVIDIA's SDK.\n\n\\bibliographystyle{acmsiggraph}\n\\nocite{*}\n\\bibliography{paper}\n\n\\end{document}", "meta": {"hexsha": "c38be4e78b7c304706f123fb843c72518c69ffab", "size": 23989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/paper.tex", "max_stars_repo_name": "hortont424/orbitals", "max_stars_repo_head_hexsha": "86d0f2a3d3f203d8add58470b0ed2a3f6084ab14", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-13T14:49:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T14:49:24.000Z", "max_issues_repo_path": "paper/paper.tex", "max_issues_repo_name": "hortont424/orbitals", "max_issues_repo_head_hexsha": "86d0f2a3d3f203d8add58470b0ed2a3f6084ab14", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-12-25T09:43:47.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-25T09:43:47.000Z", "max_forks_repo_path": "paper/paper.tex", "max_forks_repo_name": "hortont424/orbitals", "max_forks_repo_head_hexsha": "86d0f2a3d3f203d8add58470b0ed2a3f6084ab14", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-12-25T09:33:20.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-25T09:33:20.000Z", "avg_line_length": 79.6976744186, "max_line_length": 964, "alphanum_fraction": 0.7848597274, "num_tokens": 5497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6573022331591025}}
{"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*{ECE302 Project 2: Estimation Techniques}\n\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Scenario 1\n   \\item Bayes MMSE Estimator\n\\end{itemize}\n\n\n\\subsection*{Scenario 1}\n\n\\begin{par}\nAn implementation of a Bayes MMSE and Linear MMSE estimators of the random variable Y from the random variable X where X = Y + W. Here Y \\ensuremath{\\tilde{\\;}} U(-1,1) and W \\ensuremath{\\tilde{\\;}} U(-2,2). Note that in this project, N represents the number of samples taken from the respective distributions.\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nclear;\nclc;\nclose all;\n\nN = 10000;\n\nY1 = random('Uniform',-1,1,N,1);\nW = random('Uniform',-2,2,N,1);\nX1 = Y1 + W;\n\\end{verbatim}\n\n\n\\subsection*{Bayes MMSE Estimator}\n\n\\begin{par}\nHere we take $\\hat{y} = E[Y | X = x]$. Calculating this condition expectation leads to: \\begin{verbatim}latex\\end{verbatim} \\ensuremath{\\backslash}usepackage\\{mathworks\\} \\ensuremath{\\backslash}[ \\ensuremath{\\backslash}hat\\{y\\} =       \\ensuremath{\\backslash}begin\\{cases\\}       0 \\& x\\ensuremath{\\backslash}leq 0 \\ensuremath{\\backslash}\\ensuremath{\\backslash}       \\ensuremath{\\backslash}frac\\{100-x\\}\\{100\\} \\& 0\\ensuremath{\\backslash}leq x\\ensuremath{\\backslash}leq 100 \\ensuremath{\\backslash}\\ensuremath{\\backslash}       0 \\& 100\\ensuremath{\\backslash}leq x    \\ensuremath{\\backslash}end\\{cases\\} \\ensuremath{\\backslash}] \\begin{verbatim}/latex\\end{verbatim}\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nY1est = zeros(N,1);\nfor i = 1:N\n    if X1(i) < -1\n        Y1est(i) = .5 + .5*X1(i);\n    elseif X1(i) < 1\n        Y1est(i) = 0;\n    else\n        Y1est(i) = -.5 + .5*X1(i);\n    end\nend\n\nempmmse1 = mean((Y1 - Y1est).^2);\n\nactmmse1 = .25;\n\\end{verbatim}\n\\begin{verbatim}\nY1est = (1/5)*X1;\n\nemplmmse1 = mean((Y1 - Y1est).^2);\n\nactlmmse1 = 4/15;\n\\end{verbatim}\n\\begin{verbatim}\ntable([empmmse1; emplmmsel],[actmmse1; actlmmse1],'VariableNames', ...\n    [\"Empirical MSE\",\"Theorhetical MSE\"],'RowNames', ...\n    [\"MMSE\",\"LMMSE\"])\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}Unrecognized function or variable 'emplmmsel'.\n\nError in proj2 (line 55)\ntable([empmmse1; emplmmsel],[actmmse1; actlmmse1],'VariableNames', ...\n\\end{verbatim} \\color{black}\n    \\begin{verbatim}\nm = 5;\nn = 5;\n\nY2est = zeros(N,m);\nemplmmse2 = zeros(1,m);\nactlmmse2 = zeros(1,m);\nleg = strings(1,m);\n\nfor j = 1:m\n    muY2 = 1;\n    varY2 = j;\n    varR = j;\n\n    Y2 = random('Normal',muY2,sqrt(varY2),N,1);\n    R = random('Normal',muR,sqrt(varR),N,n);\n    X2 = Y2 + R;\n\n    CXX = varY2*ones(n) + diag(varR*ones(1,n));\n    CXY = varY2*ones(n,1);\n\n    a = CXX\\CXY;\n\n    a0 = muY2 - dot(a,muY2*ones(n,1));\n\n    Y2est(:,j) = a0 + dot(repmat(a',N,1),X2,2);\n\n    emplmmse2(j) = mean((Y2 - Y2est(:,j)).^2);\n\n    actlmmse2(j) = varY2 - CXY'*a;\n\n    leg(j) = \"\\sigma_Y^2 = \" + j + \", \\sigma_R^2 = \" + j;\nend\n\nsz = 25;\n\nfigure;\nfor j = 1:m\n    scatter(emplmmse2(j),actlmmse2(j),sz,j,'filled','DisplayName',leg(j));\n    hold on;\nend\nxlabel(\"Empirical LMMSE\");\nylabel(\"Theorhetical LMMSE\");\nlegend('location','northwest');\ngrid on;\ntitle(\"LMMSE with \" + n + \" observations\");\n\\end{verbatim}\n\n\n\n\\end{document}\n    \n", "meta": {"hexsha": "2a609870579a6e93b95ba206b9de9230ff610d5c", "size": 3426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2020-maltz/Homeworks/test.tex", "max_stars_repo_name": "cooper-union-ee/ece210-matlab-seminar", "max_stars_repo_head_hexsha": "e6f47fdd570c5a9b03d96f20c755bf622f843368", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2020-maltz/Homeworks/test.tex", "max_issues_repo_name": "cooper-union-ee/ece210-matlab-seminar", "max_issues_repo_head_hexsha": "e6f47fdd570c5a9b03d96f20c755bf622f843368", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2020-maltz/Homeworks/test.tex", "max_forks_repo_name": "cooper-union-ee/ece210-matlab-seminar", "max_forks_repo_head_hexsha": "e6f47fdd570c5a9b03d96f20c755bf622f843368", "max_forks_repo_licenses": ["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.8260869565, "max_line_length": 665, "alphanum_fraction": 0.6482778751, "num_tokens": 1241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6572282687993408}}
{"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 principal components}\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\n\nDo note that the Heptathalon data, and code for two functions are available in the portal!\n\nFirst, the data needs to be removed from the portal, and loaded into \\textbf{R}.   Then, as explained in the lecture, some rescaling is necessary:\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> hept.df <- read.csv(\"Heptathalon.csv\", row.names = 1)\n> hept.df$X100mHurdles.S. <- hept.df$X100mHurdles.S. * -1\n> hept.df$X200m.sec. <- hept.df$X200m.sec. * -1\n> hept.df$r800m.s. <- hept.df$r800m.s. * -1\n\\end{Sinput}\n\\end{Schunk}\n\nYou may like to consider whether this particular rescaling is a good one.   Perhaps it would have been better to take reciprocals?\n\n\n\\section{A principal components analysis}\n\nEssentially, all we need to carry out a principal component analysis are the eigenvalues and eigenvectors of the covariance or correlation matrix.   This is as simple as:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> hept.cormat <- cor(hept.df[,-1])\n> hept.covmat <- cov(hept.df[,-1])\n> hep1.ev <- eigen(hept.cormat)\n> hep1.ev\n> hep2.ev <- eigen(hept.covmat)\n> hep2.ev\n\\end{Sinput}\n\\end{Schunk}\n\nAnd a scree plot can be quite easily obtained using \\verb+plot(hep1.ev$values, type = \"b\")+\n\n\n\\section{Using the in-built functions}\n\nIn practice, we will use the inbuilt functions.   There is an older function, \\texttt{princomp()}, which is retained partly for compatibility with S-Plus and partly because it allows us to provide a covariance matrix to the function (such as a robust estimate rather than the usual estimator).   The advantage of using the inbuilt functions are that the objects created have various methods associated.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> hept.princomp <- princomp(hept.df[,-1], scale = TRUE)\n> summary(hept.princomp)\n> plot(hept.princomp) ## produces scree plot\n> biplot(hept.princomp) ## produces biplot\n> loadings(hept.princomp) ## pretty printed \n> predict(hept.princomp) ## scores\n> par(mfrow = c(3,3))\n> apply(predict(hept.princomp), 2, qqnorm)\n\\end{Sinput}\n\\end{Schunk}\n\nThe latter two lines are a reminder that if the original data were multivariate normal, then all the infinite linear combinations (including the principal components) will be univariate normal.\n\n\\begin{itemize}\n\\item Why did we add the instruction \\verb+scale = TRUE+ in the call to \\verb+princomp()+.   What is the analagous instruction to the command \\verb+prcomp()+\n\\item How many components do you wish to retain in the heptathalon analysis?\n\\item Can you interpret the principal components (by altering the arguments to \\verb+choices+ you can examine different variables, e.g.  \\verb+biplot(hept.princomp,choices = c(1,3))+)?\n\\item Do the principal component scores suggest a different method for awarding medals (details on the actual winner can be found on the web)?\n\\end{itemize}\n\n\n\\begin{itemize}\n\\item Before moving on, it is a very good idea to conduct a principal component analysis of the US Arrests data: contrast the scree plot from an analysis based on the covariance matrix and an analysis based on the correlation matrix?   What information does the former analysis give you?\n\\end{itemize}\n\n\n\\section{Using \\texttt{prcomp()}}\n\n\\texttt{prcomp()} uses the original data, and do note that it returns the square roots of the eigenvalues (in principle at least).   We use this routine to examine the turtles data:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> library(Flury)\n> data(turtles)\n\\end{Sinput}\n\\end{Schunk}\n\nThe helpfile gives you one suggestion for eda.   We follow Flury (1997) below, and consider only the males.   We take natural logarithms and multiply the values by 10.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> data(turtles)\n>   turtles.m <- subset(turtles, turtles$Gender == \"Male\")\n>   turtles.m <- 10 * log(turtles.m[,-1])\n>   turtles.m.prcomp <- prcomp(turtles.m)\n>   summary(turtles.m.prcomp)\n> plot(turtles.m.prcomp)\n> turtles.m.prcomp$sdev^2 ## extract eigenvalues\n> par(xpd = NA)\n> biplot(turtles.m.prcomp)\n\\end{Sinput}\n\\end{Schunk}\n\n\\begin{itemize}\n\\item How many principal components do you need to retain here?\n\\item How do you interpret the principal components?\n\\end{itemize}\n\n\n\\section{Aside: the value of reducing dimensions}\n\nHere's a lot of code we've seen before, it produces a three cluster solution from five variables collected on mammalian milk.   We tried plotting the cluster solutions against the original data - but perhaps we don't need a five dimensional representation.   The last five lines try plotting the cluster solution against the first two principal components.   Some of the inbuilt visulisation functions in the \\texttt{cluster} library do this for you!\n\n\\begin{Schunk}\n\\begin{Sinput}\n> library(cluster)\n> library(flexclust)\n> data(milk)\n> milk.dist <- dist(milk)\n> milk.hclust <- hclust(milk.dist)\n> plot(milk.hclust)\n> milk.cut <- cutree(milk.hclust, 3)\n> z <- predict(prcomp(milk, scale = TRUE)) ##a\n> plot(z, col = milk.cut, pch = milk.cut, main = \"a\")\n> ## run the command windows() to compare these side by side\n> z <- predict(prcomp(milk, scale = FALSE)) ##b\n> plot(z, col = milk.cut, pch = milk.cut, main = \"b\")\n\\end{Sinput}\n\\end{Schunk}\n\n\\begin{itemize}\n\\item What's the difference between graph $a$ and $b$.\n\\end{itemize}\n\n\\section{Further routines for considering the number of dimensions needed}\n\n(R code for the two functions, \\texttt{Horn()} and \\texttt{stickometer()} is available from the portal - improvements and suggestions are most welcome)\n\n\nHere we consider Horn's method for simulating from the sample covariance matrix:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> require(MASS)\n> Horn <- function(data, reps){\n+   p <- dim(data)[2]\n+   n <- dim(data)[1]\n+   Varmat <- matrix(0,p,p)\n+   Mean <- mean(data)\n+   diag(Varmat) <- diag(var(data))\n+     Evals <- princomp(data, cor = TRUE)$sdev^2\n+     idx <- barplot(Evals, names.arg = paste(\"PC\", c(1:7)), \n+     xlab = \"Component\", ylab = \"Proportion of trace\", \n+     main = \"Proportion of trace explained\")\n+       results <- matrix(0,reps,p)\n+       for (i in 1:reps){\n+       SimData <- mvrnorm(n, Mean, Varmat)\n+       ExpEvalsH <- princomp(SimData, cor = TRUE)$sdev^2\n+       results[i,] <- ExpEvalsH\n+       lines(idx, ExpEvalsH, type = \"b\", pch = 16)\n+       }\n+     lines(idx, apply(results, 2, mean), type = \"b\", col = \"red\")\n+   legend(\"topright\", lty = 1, pch = 16, legend = \"Expected values\")\n+   Results <- data.frame(Evals = Evals, ExpEvalsH = ExpEvalsH)\n+ }\n\\end{Sinput}\n\\end{Schunk}\n\n\nHaving entered this function (it is available in the portal), it can be used on the heptathalon data simply by entering:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> Horn(hept.df[-1], 10)\n\\end{Sinput}\n\\end{Schunk}\n\\includegraphics{STAT3401Week5PCAlab-hornhept}\nto get ten replicates.  You may wish to consider more than 10.\n\n\nIn a similar way, we can get Joliffe's stick estimates as follows:\n\n\\begin{Schunk}\n\\begin{Sinput}\n>  stickometer <- function(p){\n+   vec <- 1 / (1:p)\n+   stick <- vector(\"numeric\", p) \n+   stick[1] <- sum(vec)\n+      for (i in 2:p){\n+      stick[i] <- sum(vec[-(1:(i-1))])}\n+   stick <- 1/p * stick\n+   names(stick) <- paste(\"Comp.\", c(1:p), sep = \"\")\n+   return(stick)\n+ }\n\\end{Sinput}\n\\end{Schunk}\n\nAnd so, for the heptathalon data (we created the \\texttt{hept.princomp} object earlier), we can create a barplot of the proportion of variance explained and superimpose a line from the expected values as follows:\n\n\\begin{Schunk}\n\\begin{Sinput}\n>  stick <- stickometer(7)\n>  proptrace <- hept.princomp$sdev^2 / sum(hept.princomp$sdev^2)\n>  stick ## checking the values\n>  proptrace ## checking the values\n>  idx <- barplot(proptrace, names.arg = paste(\"PC\", c(1:7)), \n+  xlab = \"Component\", ylab = \"Proportion of trace\", \n+  main = \"Proportion of trace explained\")\n>  lines(idx, stick, type = \"b\", pch = 16)\n>  legend(\"topright\", lty = 1, pch = 16, legend = \"Expected values\")\n\\end{Sinput}\n\\end{Schunk}\n\\includegraphics{STAT3401Week5PCAlab-stickhept}\n\nIt would be nice to see this laid out properly!\n\n\n\\begin{itemize}\n\\item Does either method alter your recommendation as to how many principal components should be retained?\n\\item What alterations need to be be made to the line:\n\\begin{verbatim}\nproptrace <- hept.princomp$sdev^2 / sum(hept.princomp$sdev^2)\n\\end{verbatim}\nin order to work with \\texttt{prcomp()} objects?\n\\end{itemize}\n\n\n\\section{Examining the Mahalanobis distance}\n\nThe following function will partition the Mahalanobis distance between the retained and non-retained components:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> princomp2dist <- function(obj.princomp, retain){\n+  scores <- t(t(obj.princomp$scores^2) / obj.princomp$sdev)\n+  dtot <- apply(scores, 1, sum)\n+  d1 <- apply(scores[,c(1:retain)], 1, sum)\n+  d2 <- apply(scores[,-c(1:retain)], 1, sum)\n+  dists <- data.frame(dtot = dtot, d1 = d1, d2 = d2)\n+  return(dists)\n+ }\n\\end{Sinput}\n\\end{Schunk}\n\n\nSo for example, if we wanted to retain three components from the heptathalon data we could use the following:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> hept.princomp <- princomp(hept.df[-1], scores = TRUE, scale = TRUE)\n> ## form a princomp object\n> hept.m <- princomp2dist(hept.princomp, 3)\n\\end{Sinput}\n\\end{Schunk}\n\n\nAll that remains to be done is to plot the retained distances as a suitable qq plot.   One could also consider a scatter plot of retained versus non-retained distances to see if there are any individuals who are not well explained by the 3 dimensional representation using something like \\verb+plot(hept.m$d1, hept.m$d2)+\n\n\n\\end{document}\n\n\n", "meta": {"hexsha": "40b721b13905e3c64fe806dd43c1683cfe6067f8", "size": 9883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/STAT3401Week5pcaLab.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/STAT3401Week5pcaLab.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/STAT3401Week5pcaLab.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": 35.9381818182, "max_line_length": 450, "alphanum_fraction": 0.7171911363, "num_tokens": 2930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.6572282687993407}}
{"text": "\\section{Simplicial Homology}\r\n\\subsection{Oriented Simplices and Boundary Homomorphism}\r\nWe slightly modify our definition of simplex by associating each simplex with an orientation.\r\nFor a simplex $\\langle v_0,\\ldots,v_n\\rangle$, we can shuffle the vertices around which defines an action of $S_{n+1}$ on it.\r\nWrite $A_{n+1}\\unlhd S_{n+1}$ as the alternating group, then it also acts on the simplex by restriction.\r\nAn orientation on $\\sigma=\\langle v_0,\\ldots,v_n\\rangle$ is a choice of ordering defined up to the action of $A_{n+1}$.\r\nSo we can now view $\\langle v_0,\\ldots,v_n\\rangle$ as a simplex with an orientation.\r\n\\begin{example}\r\n    $0$-simplex does not have a notion of orientation.\\\\\r\n    There are two possible orderings of $1$-simplex, namely $\\langle v_0,v_1\\rangle$ and $\\langle v_1,v_0\\rangle$ which have different orientation.\\\\\r\n    For $2$-simplices, again there are two orientations and they are $\\langle v_0,v_1,v_2\\rangle=\\langle v_1,v_2,v_0\\rangle=\\langle v_2,v_0,v_1\\rangle$ and $\\langle v_1,v_0,v_2\\rangle=\\langle v_0,v_2,v_1\\rangle=\\langle v_2,v_1,v_0\\rangle$.\r\n\\end{example}\r\nSo afterwards when we mention simplex we mean oriented simplex.\r\n\\begin{definition}\r\n    Let $K$ be a simplicial complex, we define the group $C_n(K)$ of $n$-chains to be the free abelian group generated by the simplices of dimension $n$ in $K$, i.e.\r\n    $$C_n(K)=\\bigoplus_{\\sigma\\in K,\\dim\\sigma=n}\\langle\\sigma\\rangle$$\r\n    where $\\langle\\sigma\\rangle$ is the free group generated by $\\sigma$.\r\n\\end{definition}\r\nWe will convention that we have made our choice of some orientation.\r\nFor a simplex $\\sigma$ in this orientation, the same simplex in the other orientation is denoted $\\bar\\sigma$.\r\nIn $\\langle\\sigma\\rangle$, we identify $\\bar\\sigma$ by $-\\sigma$.\r\n\\begin{definition}\r\n    The $n^{th}$ boundary homomorphism is a homomorphism $\\partial=\\partial_n:C_n(K)\\to C_{n-1}(K)$ induced by\r\n    $$\\partial_n\\langle v_0,\\ldots,v_n\\rangle = \\sum_{i=0}^n(-1)^i\\langle v_1,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle$$\r\n    where $\\langle v_1,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle=\\langle v_0,\\ldots,v_{i-1},v_{i+1},\\ldots,v_n\\rangle$.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\partial\\langle v_0,v_1\\rangle=\\langle v_1\\rangle-\\langle v_0\\rangle$.\r\n    $\\partial\\langle v_0,v_1,v_2\\rangle=\\langle v_1,v_2\\rangle-\\langle v_0,v_2\\rangle+\\langle v_0,v_1\\rangle=\\langle v_1,v_2\\rangle+\\langle v_2,v_0\\rangle+\\langle v_0,v_1\\rangle$ which is indeed the (oriented) topological boundary of the simplex $\\langle v_0,v_1,v_2\\rangle$.\r\n\\end{example}\r\n\\begin{remark}\r\n    We have $\\partial\\bar\\sigma=-\\partial\\sigma$.\r\n\\end{remark}\r\n\\subsection{The Homology Groups of Simplicial Complexes}\r\n\\begin{definition}\r\n    Let $K$ be a simplicial complex and $n\\in\\mathbb Z$, the group of $n$-cycles of $K$ is $Z_n(K)=\\ker\\partial_n$.\r\n    The group of $n$-boundaries is $B_n(K)=\\operatorname{Im}\\partial_{n+1}$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    $B_n(K)\\subset Z_n(K)$, or in other words $\\partial_{n-1}\\circ\\partial_n=0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Pick an $n$-simplex $\\langle v_0,\\ldots,v_n\\rangle$, then\r\n    \\begin{align*}\r\n        \\partial_{n-1}\\circ\\partial_n(\\langle v_0,\\ldots,v_n\\rangle)&=\\partial_{n-1}\\left( \\sum_{i=0}^n(-1)^i\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle \\right)\\\\\r\n        &=\\sum_{i=0}^n(-1)^i\\partial_{n-1}(\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle)\\\\\r\n        &=\\sum_{j<i}(-1)^j(-1)^i\\langle v_0,\\ldots,\\hat{v}_j,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle\\\\\r\n        &\\quad+\\sum_{j>i}(-1)^{j-1}(-1)^i\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,\\hat{v}_j,\\ldots,v_n\\rangle\\\\\r\n        &=0\r\n    \\end{align*}\r\n    as desired.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The $n^{th}$ (simplicial) homology group of the simplicial complex $K$ is defined as $H_n(K)=Z_n(K)/B_n(K)$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Take the simplicial complex $K$ generated by boundary of a $2$-simplex (which can be taken as a triangulation of $S^1$).\r\n    Then $C_0(K)\\cong C_1(K)\\cong\\mathbb Z^3$ and $C_n(K)=0$ for all $n>1$.\r\n    So we only need to understand $\\partial_1$.\r\n    Say its $0$-simplices are $\\langle v_0\\rangle,\\langle v_1\\rangle,\\langle v_2\\rangle$ and $1$-simplices are $\\langle v_0,v_1\\rangle,\\langle v_1,v_2\\rangle,\\langle v_2,v_0\\rangle$, then $\\partial_1:C_1(K)\\to C_0(K)$ maps\r\n    \\begin{align*}\r\n        \\langle v_0,v_1\\rangle &\\mapsto \\langle v_1\\rangle-\\langle v_0\\rangle\\\\\r\n        \\langle v_1,v_2\\rangle &\\mapsto \\langle v_2\\rangle-\\langle v_1\\rangle\\\\\r\n        \\langle v_2,v_0\\rangle &\\mapsto \\langle v_0\\rangle-\\langle v_2\\rangle\r\n    \\end{align*}\r\n    So if we take the free abelian groups as free $\\mathbb Z$-modules generated by the simplices, then $\\partial_1$ has the matrix\r\n    $$\\begin{pmatrix}\r\n        -1&0&1\\\\\r\n        1&-1&0\\\\\r\n        0&1&-1\r\n    \\end{pmatrix}$$\r\n    So $Z_1(K)=\\ker\\partial_1=\\langle(1,1,1)\\rangle=\\langle \\langle v_0,v_1\\rangle +\\langle v_1,v_2\\rangle + \\langle v_2,v_0\\rangle\\rangle$ and $B_1(K)=\\ker\\partial_2=0$, therefore $H_1(K)\\cong\\mathbb Z$.\\\\\r\n    As for the $H_0(K)$, we have $Z_0(K)=\\ker\\partial_0=C_0(K)\\cong\\mathbb Z^3$ and $B_0(K)=\\operatorname{Im}\\partial_1\\cong\\langle (-1,1,0),(0,-1,1)\\rangle$, hence $H_0(K)\\cong\\mathbb Z^3/\\langle (-1,1,0),(0,-1,1)\\rangle\\cong\\mathbb Z$.\r\n    And $H_n(K)=0$ for $n>1$.\r\n\\end{example}\r\n\\begin{example}\r\n    Take $L$ the simplicial complex generated by the $2$-simplex (so it is a solid triangle which is a triangulation of the closed unit disk).\r\n    Then $C_0(L)=C_0(K),C_1(L)=C_1(K)$ but $C_2(L)=\\langle\\langle v_0,v_1,v_2\\rangle\\rangle$ where $K$ is as in the previous example.\r\n    Now $\\partial_2(\\langle v_0,v_1,v_2\\rangle)=\\langle v_0,v_1\\rangle+\\langle v_1,v_2\\rangle+\\langle v_2,v_0\\rangle$ which is the generator of $\\ker\\partial_1$, therefore $Z_1(L)=B_1(L)$ and hence $H_1(L)=0$.\r\n    Note that $L,K$ coincides on $0$ and $1$-simplices they contain, so $H_0(L)\\cong H_0(K)\\cong\\mathbb Z$.\r\n    Now easily $Z_2(L)=\\ker\\partial_2=0$ and therefore $H_2(L)=0$, therefore $H_0(L)\\cong\\mathbb Z$ and $H_n(L)=0$ for any $n\\neq 0$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Let $K$ be a simplicial complex.\r\n    If $d$ is the number of path components of $|K|$, then $H_0(K)\\cong\\mathbb Z^d$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Denote by $\\pi_0(K)$ the set of path-connected components of $|K|$.\r\n    Write $\\mathbb Z[A]$ as the free abelian group generated by a set $A$, then $\\mathbb Z[\\pi_0(K)]\\cong\\mathbb Z^d$.\r\n    Consider a $q:C_0(K)\\to\\mathbb Z[\\pi_0(K)]$ sending a vertex $\\langle v\\rangle$ to the path component containing $v$ and extend it to a homomorphism.\r\n    Then $q$ is surjective.\r\n    Note that $\\partial_0=0$, so $Z_0(K)=C_0(K)$, therefore $H_0(K)\\cong C_0(K)/B_0(K)$, therefore it suffices to show that $\\ker q=B_0(K)$.\r\n    If $\\langle v_0,v_1\\rangle\\in C_1(K)$, then $q\\circ\\partial_1(\\langle v_0,v_1\\rangle)=q(\\langle v_1\\rangle-\\langle v_1\\rangle)=0$ since $v_0$ and $v_1$ are joined by a path.\r\n    This means that $B_0(K)\\subset\\ker q$.\r\n    Conversely, $\\ker q$ is generated by elements of $C_0(K)$ of the form $\\langle w\\rangle-\\langle v\\rangle$ where $v,w$ are in the same path components of $|K|$.\r\n    But then there is a sequence of vertices $v=v_1,v_2,\\ldots,v_n=w$ in $K$ with $\\langle v_i,v_{i+1}\\rangle\\in K$.\r\n    Then\r\n    $$\\langle w\\rangle-\\langle v\\rangle=(\\langle v_n\\rangle-\\langle v_{n-1}\\rangle)+(\\langle v_{n-1}\\rangle-\\langle v_{n-2}\\rangle)\\cdots +(\\langle v_2\\rangle-\\langle v_1\\rangle)\\in\\operatorname{Im}\\partial_1=B_0(K)$$\r\n    Hence $\\ker q\\subset B_0(K)$.\r\n    This completes the proof.\r\n\\end{proof}\r\n\\begin{remark}\r\n    There is a very rough analogy between $\\pi_1(|K|)$ and $H_1(K)$ as $B_1(K)$ is kind of homotopies between the loops in $Z_1(K)$.\r\n    They are of course not the same as $H_1(K)$ is always abelian, but in fact, there does exist a certain connection as one can show that $H_1(K)\\cong\\pi_1(|K|)^{\\operatorname{ab}}$.\r\n\\end{remark}\r\n\\subsection{Chain Maps and Homotopies}\r\nWe want to understand the maps on homology that is induced by maps of simplicial complexes.\r\n\\begin{definition}\r\n    A chain complex $C_\\bullet$ is a sequence of abelian groups $C_n,n\\in\\mathbb Z$ with homomorphisms $\\partial_n:C_n\\to C_{n-1}$ such that $\\partial_{n-1}\\circ\\partial_n=0$ for all $n$.\\\\\r\n    A chain map $f_\\bullet:C_\\bullet\\to D_\\bullet$ between chain complexes is a collection of homomorphisms $f_n:C_n\\to D_n$ indexed by $n\\in\\mathbb Z$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            C_n\\arrow{r}{\\partial_n}\\arrow[swap]{d}{f_n}&C_{n-1}\\arrow{d}{f_{n-1}}\\\\\r\n            D_n\\arrow[swap]{r}{\\partial_n}&D_{n-1}\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes for any $n$.\r\n\\end{definition}\r\nHomology usually deals with the cases where nontrivial groups only occur at nonnegative $n$.\r\nIn these situations, we can just define $C_n$ for $n\\ge 0$ and $\\partial_n$ for $n\\ge 1$ -- because those are what we care about -- and leave the rest of the groups and boundary maps to be zero.\r\nThis will be the case for the simplicial complexes.\r\n\\begin{definition}\r\n    Given a chain complex $C_\\bullet$, we define the group of $n$-cycles to be $Z_n(C_\\bullet)=\\ker\\partial_n$ and the group of $n$-boundaries to be $B_n(C_\\bullet)=\\operatorname{Im}\\partial_n$.\r\n    Then $B_n(C_\\bullet)\\unlhd Z_n(C_\\bullet)$, so we define the $n^{th}$ homology group is then $H_n(C_\\bullet)=Z_n(C_\\bullet)/B_n(C_\\bullet)$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $f_\\bullet:C_\\bullet\\to D_\\bullet$ is a chain map, then for any $n\\in\\mathbb Z$, we have a well-defined homomorphism $f_\\ast:H_n(C_\\bullet)\\to H_n(D_\\bullet)$ via $[c]\\mapsto [f_n(c)]$ for $c\\in Z_n(C_\\bullet)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suffices to show that the map is well-defined.\r\n    For $c\\in Z_n(C_\\bullet)$, we have $\\partial_n\\circ f_n(c)=f_{n-1}\\circ\\partial_n(c)=0$, so indeed $f_n(c)\\in Z_n(D_\\bullet)$.\r\n    Also, if $c\\in B_n(C_\\bullet)$, then there is some $c'\\in C_{n-1}$ such that $c=\\partial_{n+1}(c')$, so $f_n(c)=f_n\\circ\\partial_{n+1}(c')=\\partial_{n+1}\\circ f_{n+1}(c')$, therefore $f_n(c)\\in B_n(D_\\bullet)$.\r\n    Hence $f_\\ast$ is well-defined.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    A simplicial map $f:K\\to L$ induces a chain map $f_\\bullet:C_\\bullet(K)\\to C_\\bullet(L)$ via\r\n    $$f_n:\\sigma\\mapsto\\begin{cases}\r\n        f(\\sigma)\\text{, if $\\dim f(\\sigma)=n$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    for $\\sigma\\in K,\\dim\\sigma=n$.\r\n    Hence for each $n\\in\\mathbb N$, $f_\\bullet$ induces a homomorphism $f_\\ast:H_n(K)\\to H_n(L)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We need to show that $\\partial_n\\circ f_n=f_{n-1}\\circ\\partial_n$.\r\n    Suffices to demonstrate this on generators.\r\n    Let $\\sigma=\\langle v_0,\\ldots,v_n\\rangle$.\r\n    If $\\dim f(\\sigma)=n$, then $f(\\sigma)=\\langle f(v_0),\\ldots,f(v_n)\\rangle$, then there is a one-to-one correspondence between faces of $\\sigma$ and fases of $f(\\sigma)$, hence necessarily $f_{n-1}\\circ\\partial_n(\\sigma)=\\partial_n\\circ f_n(\\sigma)$.\r\n    If $\\dim f(\\sigma)\\le n-2$, then $f_{n-1}\\circ\\partial_n(\\sigma)=0=\\partial_n\\circ f_n(\\sigma)$.\r\n    We are left with the case $\\dim f(\\sigma)=n-1$.\r\n    Assume $f(v_0)=f(v_1)$ and $f(v_1),\\ldots,f(v_n)$ are all distinct.\r\n    In that case $f(\\langle v_0,\\ldots,v_n\\rangle)=f(\\langle v_1,\\ldots,v_n\\rangle)$.\r\n    We know that $f_n(\\sigma)=0$, so $\\partial_n\\circ f_n(\\sigma)=0$.\r\n    Now\r\n    \\begin{align*}\r\n        f_{n-1}\\circ\\partial_n(\\sigma)&=f_{n-1}\\left(\\sum_{i=0}^n(-1)^i\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle\\right)\\\\\r\n        &=\\sum_{i=0}^n(-1)^if_{n-1}(\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle)\\\\\r\n        &=f_{n-1}(\\langle v_1,\\ldots,v_n\\rangle)-f_{n-1}(\\langle v_0,v_2,\\ldots,v_n\\rangle)\\\\\r\n        &=0\r\n    \\end{align*}\r\n    Therefore $\\partial_n\\circ f_n(\\sigma)=0=f_{n-1}\\circ\\partial_n(\\sigma)$ too, which means $f_\\bullet$ is indeed a chain map.\r\n\\end{proof}\r\n\\begin{remark}\r\n    If $f:K\\to L$ and $g:L\\to M$ are simplicial maps, then $(g\\circ f)_\\ast=g_\\ast\\circ f_\\ast$.\r\n    Also, if $K$ is a simplicial complex, then $(\\operatorname{id}_K)_\\ast=\\operatorname{id}_{H_n(K)}$.\r\n\\end{remark}\r\nA natural question is that when do chain maps induce the same maps on homology.\r\n\\begin{definition}\r\n    Let $f_\\bullet,g_\\bullet:C_\\bullet\\to D_\\bullet$ be chain maps.\r\n    A chain homotopy $h_\\bullet$ between $f_\\bullet$ and $g_\\bullet$ is a collection of homomorphisms $h_n:C_n\\to D_{n+1}$ such that $g_n(c)-f_n(c)=\\partial_{n+1}\\circ h_n(c)+h_{n-1}\\circ\\partial_n(c)$.\r\n    We say $f_\\bullet$ and $g_\\bullet$ are chain homotopic, written as $f_\\bullet\\simeq g_\\bullet$ if such $h_\\bullet$ exists.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $f_\\bullet\\simeq g_\\bullet:C_\\bullet\\to D_\\bullet$, then $f_\\ast=g_\\ast$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $c\\in Z_n(C_\\bullet)$, then $g_n(c)-f_n(c)=\\partial_{n+1}\\circ h_n(c)+h_{n-1}\\circ\\partial_n(c)=\\partial_{n+1}\\circ h_n(c)\\in B_n(D_\\bullet)$, therefore $[g_n(c)]=[f_n(c)]$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the triangle $K$ and the line segment $L$, both as simplicial complexes in the obvious way.\r\n    Say the vertices in $K$ are $e_0,e_1,e_2$ and those in $L$ are $e_0,e_1$ and let $i:L\\to K$ be the natural inclusion $e_0\\mapsto e_0,e_1\\mapsto e_1$, $r$ be the simplicial retraction $e_0\\mapsto e_0,e_1\\mapsto e_1,e_2\\mapsto e_0$, both as simplicial maps.\r\n    Now $r\\circ i=\\operatorname{id}_L$, but $i\\circ r\\neq \\operatorname{id}_K$.\r\n    However, we can define a chain homotopy between $(i\\circ r)_\\bullet$ and $\\operatorname{id}_{C_\\bullet(K)}$.\r\n    This would be given by $h_\\bullet$ which is everywhere zero except $h_0(\\langle e_2\\rangle)=\\langle e_2,e_0\\rangle$ and $h_1(\\langle e_1,e_2\\rangle)=-\\langle e_0,e_1,e_2\\rangle$ which works since\r\n    \\begin{align*}\r\n        (\\partial_1\\circ h_0+h_{-1}\\circ\\partial_0)(\\langle e_2\\rangle)&=\\partial_1(\\langle e_2,e_0\\rangle)\\\\\r\n        &=\\langle e_0\\rangle-\\langle e_2\\rangle\\\\\r\n        &=(i_0\\circ r_0-\\operatorname{id}_{C_0(K)})(\\langle e_2\\rangle)\\\\\r\n        (\\partial_2\\circ h_1+h_0\\circ\\partial_1)(\\langle e_1,e_2\\rangle)&=\\partial_2(-\\langle e_0,e_1,e_2\\rangle)+h_0(\\langle e_2\\rangle-\\langle e_1\\rangle)\\\\\r\n        &=-\\langle e_0,e_1\\rangle-\\langle e_1,e_2\\rangle-\\langle e_2,e_0\\rangle+\\langle e_2,e_0\\rangle\\\\\r\n        &=(i_1\\circ r_1-\\operatorname{id}_{C_1(K)})(\\langle e_1,e_2\\rangle)\\\\\r\n        (\\partial_3\\circ h_2+h_1\\circ\\partial_2)(\\langle e_0,e_1,e_2\\rangle)&=h_1(\\langle e_0,e_1\\rangle+\\langle e_1,e_2\\rangle+\\langle e_2,e_0\\rangle)\\\\\r\n        &=-\\langle e_0,e_1,e_2\\rangle\\\\\r\n        &=(i_2\\circ r_2-\\operatorname{id}_{C_2(K)})(\\langle e_0,e_1,e_2\\rangle)\r\n    \\end{align*}\r\n    Therefore $(i\\circ r)_\\ast=i_\\ast\\circ r_\\ast$ would just be the identity on $H_n(K)$.\r\n    In particular, $r_\\ast$ is an isomorphism on the homology groups.\r\n\\end{example}\r\n\\begin{definition}\r\n    A simplicial complex $K$ is a cone if there is a vertex $x_0$ such that for all other simplices $\\tau\\in K$, there exists $\\sigma\\in K$ such that $x_0\\in\\sigma$ and $\\tau\\le\\sigma$.\r\n\\end{definition}\r\nPerhaps nonsurprisingly,\r\n\\begin{lemma}\r\n    If $K$ is a cone, then $H_0(K)\\cong\\mathbb Z$ and $H_n(K)=0$ if $n\\neq 0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $i:\\{\\langle x_0\\rangle\\}\\to K$ be the obvious inclusion and $r:K\\to\\{\\langle x_0\\rangle\\}$ be constant.\r\n    Then $r\\circ i=\\operatorname{id}_{\\{\\langle x_0\\rangle\\}}$, therefore $r_\\ast\\circ i_\\ast=\\operatorname{id}_{H_n(\\{\\langle x_0\\rangle\\})}$.\r\n    We shall show that $i_\\ast\\circ r_\\ast=\\operatorname{id}_{H_n(K)}$ which implies $H_n(K)\\cong H_n(\\{\\langle x_0\\rangle\\})$ from where the result follows.\\\\\r\n    We will build a chain homotopy between $\\operatorname{id}_{C_\\bullet(K)}$ and $i_\\bullet\\circ r_\\bullet$ where $i_\\bullet$ and $r_\\bullet$ are the induced chain maps.\r\n    Let $\\sigma=\\langle v_0,\\ldots,v_n\\rangle\\in K$, then we define\r\n    $$h_n(\\sigma)=\\begin{cases}\r\n        0\\text{, if $x_0\\in\\sigma$}\\\\\r\n        \\langle x_0,v_0,\\ldots,v_n\\rangle\\text{, otherwise}\r\n    \\end{cases}$$\r\n    which is well-defined as $K$ is a cone with vertex $x_0$.\r\n    We want to show that $\\partial_{n+1}\\circ h_n+h_{n-1}\\circ\\partial_n=\\operatorname{id}_{C_n(K)}-i_n\\circ r_n$.\r\n    Suppose $n>0$ and $x_0\\notin\\sigma$, then\r\n    \\begin{align*}\r\n        &\\quad(\\partial_{n+1}\\circ h_n+h_{n-1}\\circ\\partial_n)(\\sigma)\\\\\r\n        &=\\partial_{n+1}(\\langle x_0,v_0,\\ldots,v_n\\rangle)+h_{n-1}\\left( \\sum_{i=0}^n(-1)^i\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n \\rangle\\right)\\\\\r\n        &=\\langle v_0,\\ldots,v_n\\rangle+\\sum_{i=0}^n(-1)^{i+1}\\langle x_0,v_0,\\ldots,\\hat{v}_i,\\ldots,v_n \\rangle\\\\\r\n        &\\quad+\\sum_{i=0}^n(-1)^i\\langle x_0,v_0,\\ldots,\\hat{v}_i,\\ldots,v_n \\rangle\\\\\r\n        &=\\langle v_0,\\ldots,v_n\\rangle=\\sigma\\\\\r\n        &=(\\operatorname{id}_{C_n(K)}-i_n\\circ r_n)(\\sigma)\r\n    \\end{align*}\r\n    which works.\r\n    If $n>0$ but $x_0\\in\\sigma$, then $x_0=v_j$ for some $j$.\r\n    Consequently,\r\n    \\begin{align*}\r\n        &\\quad(\\partial_{n+1}\\circ h_n+h_{n-1}\\circ\\partial_n)(\\sigma)\\\\\r\n        &=0+h_{n-1}\\left( \\sum_{i=0}^n(-1)^i\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n \\rangle\\right)\\\\\r\n        &=(-1)^j\\langle x_0=v_j,v_0,\\ldots,\\hat{v}_j,\\ldots,v_n\\rangle\\\\\r\n        &=\\langle v_0,\\ldots,v_n\\rangle=\\sigma\\\\\r\n        &=(\\operatorname{id}_{C_n(K)}-i_n\\circ r_n)(\\sigma)\r\n    \\end{align*}\r\n    The case $n=0$ is trivial.\r\n    Therefore $h_\\bullet$ is indeed a chain homotopy as desired.\r\n\\end{proof}\r\n\\begin{example}\r\n    Any $n$-simplex $K$ is a cone, so by the lemma\r\n    $$H_n(K)\\cong\\begin{cases}\r\n        \\mathbb Z\\text{, if $n=0$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Take $L=\\partial\\sigma_n$ be the boundary of the $n$-simplex, then $|L|\\cong S^{n-1}$ for $n\\ge 2$.\r\n    The obvious inclusion $L\\hookrightarrow K$ of simplicial complexes induces a chain map\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&0\\arrow{r}\\arrow{d}&C_{n-1}(L)\\arrow{r}{\\partial_{n-1}}\\arrow[equal]{d}&\\cdots\\arrow{r}{\\partial_1}&C_0(L)\\arrow{r}\\arrow[equal]{d}&0\\\\\r\n            0\\arrow{r}&C_n(K)\\arrow[swap]{r}{\\partial_n}&C_{n-1}(K)\\arrow[swap]{r}{\\partial_{n-1}}&\\cdots\\arrow[swap]{r}{\\partial_1}&C_0(K)\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    So evidently $H_d(L)\\cong H_d(K)$ for $d\\le n-2$.\r\n    Since $H_{n-1}(K)=0$, we have $Z_{n-1}(L)=Z_{n-1}(K)=B_{n-1}(K)$.\r\n    Also $B_{n-1}(L)=0$, therefore $H_{n-1}(L)\\cong Z_{n-1}(L)=B_{n-1}(K)$.\r\n    But this is easy enough to calculate:\r\n    $K$ only has one $n$-simplex $\\sigma$, so $C_n(K)=\\mathbb Z\\sigma$ and hence $B_{n-1}\\cong\\mathbb Z$ as $\\partial_n$ has to be injective.\r\n    Thus\r\n    $$H_d(L)=\\begin{cases}\r\n        \\mathbb Z\\text{, if $d=0$ or $d=n-1$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    This means homology can actually detect ``higher dimensional holes''.\r\n\\end{example}\r\n\\subsection{Continuous Maps and Homotopies}\r\nFor a map $\\phi:|K|\\to|L|$, we want to associate to it a homomorphism $\\phi_\\ast:H_n(K)\\to H_n(L)$.\r\nNote that a chief difficulty in this is that $\\phi$ may not contain much information about the structures of $K,L$ as simplicial complexes, since it is just a continuous map between topological spaces.\r\nThe idea is to use a simplicial approximation.\r\nThat is, instead of looking for $\\phi_\\ast:H_n(K)\\to H_n(L)$ directly, we seek $\\phi_\\ast:H_n(K^{(r)})\\to H_n(L^{(r)})$ for sufficiently large $r$ and show that $H_n(K^{(r)})\\cong H_n(K)$ for any simplicial complex $K$ and $r\\in\\mathbb N$.\r\nEventually, we will show that $H_n(K)$ only depends on $|K|$.\\\\\r\nFirst step on that journey is the notion of homotopy on simplicial maps.\r\n\\begin{definition}\r\n    Two simplicial maps $f,g:K\\to L$ are contiguous if, for every $\\sigma\\in K$, there exists some $\\tau\\in L$ such that $f(\\sigma)$ and $g(\\sigma)$ are both faces of $\\tau$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Suppose given $\\phi:|K|\\to |L|$ with $f,g:K\\to L$ different simplicial approximations to $\\phi$.\r\n    Then choose any $x\\in\\sigma^\\circ,\\phi(x)\\in\\tau^\\circ$, we know that $f(\\sigma)\\le\\tau$ and $g(\\sigma)\\le\\tau$ and hence $f,g$ are contiguous.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    If $f,g:K\\to L$ are contiguous, then $f_\\ast=g_\\ast:H_n(K)\\to H_n(L)$ for all $n$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We shall construct a chain homotopy.\r\n    Fix a total order $<$ on vertices of $K$ and use the convention that $\\sigma=\\langle v_0,\\ldots,v_n\\rangle$ is oriented in such a way that $v_0<\\ldots<v_n$.\r\n    We write $\\langle v_0,\\ldots,v_n\\rangle=0$ if $v_0,\\ldots,v_n$ are not in general position.\r\n    Easy to see this is compatible with everything.\r\n    Define $h_n:C_n(K)\\to C_{n+1}(L)$ by\r\n    $$h_n(\\langle v_0,\\ldots,v_n\\rangle)=\\sum_{i=0}^n(-1)^i\\langle f(v_0),\\ldots,f(v_i),g(v_i),\\ldots,g(v_n)\\rangle$$\r\n    Note that whenever the summand is nonzero, it would be an $(n+1)$-simplex of $L$ since $f,g$ are contiguous.\r\n    We have some calculations to do.\r\n    \\begin{align*}\r\n        (\\partial\\circ h+h\\circ\\partial)(\\sigma)&=\\partial\\left( \\sum_{i=0}^n(-1)^i\\langle f(v_0),\\ldots,f(v_i),g(v_i),\\ldots,g(v_n)\\rangle \\right)\\\\\r\n        &\\quad+h\\left( \\sum_{i=0}^n(-1)^i\\langle v_0,\\ldots,\\hat{v}_i,\\ldots,v_n\\rangle \\right)\\\\\r\n        &=\\sum_{i\\le j}(-1)^{i+j}\\langle f(v_0),\\ldots,\\widehat{f(v_i)},\\ldots,f(v_j),g(v_j),\\ldots,g(v_n)\\rangle\\\\\r\n        &\\quad-\\sum_{i\\ge j}(-1)^{i+j}\\langle f(v_0),\\ldots, f(v_j),g(v_j),\\ldots,\\widehat{g(v_i)},\\ldots,g(v_n)\\rangle\\\\\r\n        &\\quad+\\sum_{j<i}(-1)^{i+j}\\langle f(v_0),\\ldots, f(v_j),g(v_j),\\ldots,\\widehat{g(v_i)},\\ldots,g(v_n)\\rangle\\\\\r\n        &\\quad-\\sum_{j>i}(-1)^{i+j}\\langle f(v_0),\\ldots,\\widehat{f(v_i)},\\ldots,f(v_j),g(v_j),\\ldots,g(v_n)\\rangle\\\\\r\n        &=\\sum_{i=0}^n\\langle f(v_0),\\ldots,f(v_{i-1}),g(v_i),\\ldots,g(v_n)\\rangle\\\\\r\n        &\\quad-\\sum_{i=0}^n\\langle f(v_0),\\ldots,f(v_i),g(v_{i+1}),\\ldots,g(v_n)\\rangle\\\\\r\n        &=\\langle g(v_0),\\ldots,g(v_n)\\rangle-\\langle f(v_0),\\ldots,f(v_n)\\rangle\\\\\r\n        &=g(\\sigma)-f(\\sigma)\r\n    \\end{align*}\r\n    as desired.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $K$ be a simplicial complex and $K'$ be its barycentric subdivision.\r\n    A simplicial map $s:K'\\to K$ is a simplicial approximation to $\\operatorname{id}_{|K|}$ iff for every $\\sigma\\in K$, $s(\\hat\\sigma)$ is a vertex of $\\sigma$.\r\n    Also, such $s$ always exists.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $s:K'\\to K$ be a simplicial approximation to $\\operatorname{id}_{|K|}$, which just means $\\operatorname{id}_{|K|}(\\operatorname{St}_{K'}(\\hat\\sigma))\\subset\\operatorname{St}_K(s(\\hat\\sigma))$.\r\n    In particular, $\\sigma\\circ\\subset\\operatorname{St}_K(s(\\hat\\sigma))$, therefore $s(\\hat\\sigma)$ is a vertex of $\\sigma$.\\\\\r\n    Conversely, suppose $s(\\hat\\sigma)$ be a vertex of $\\sigma$ for any $\\sigma\\in K$.\r\n    Choose any $\\tau'\\in K'$ with $\\tau'^\\circ\\subset\\operatorname{St}_{K'}(\\hat\\sigma)$ (i.e. $\\hat\\sigma$ is a vertex of $\\tau'$).\r\n    Then $\\tau'^\\circ$ is contained in the interior of a simplex $\\tau\\in K$ such that $\\sigma\\le\\tau$.\r\n    Thus $s(\\hat\\sigma)$ is also a vertex of $\\tau$.\r\n    But $\\tau'^\\circ\\subset\\tau^\\circ\\subset\\operatorname{St}_K(s(\\hat\\sigma))$.\r\n    But such $\\tau'^\\circ$ necessarily cover $\\operatorname{St}_{K'}(\\hat\\sigma)$, therefore $\\operatorname{id}_{|K|}(\\operatorname{St}_{K'}(\\hat\\sigma))\\subset\\operatorname{St}_K(s(\\hat\\sigma))$ as desired.\\\\\r\n    To see such an $s$ exists, we simply just need to send $\\hat\\sigma$ to an arbitrarily chosen vertex of $\\sigma$ which, as one can verify, works.\r\n\\end{proof}\r\n\\begin{proposition}\\label{barycentric_iso_homol}\r\n    Let $s:K'\\to K$ be the simplicial approximaion to the identity obtained like in the proof above, then $s_\\ast:H_n(K')\\to H_n(K)$ is an isomorphism for all $n$.\r\n\\end{proposition}\r\nWe will postpone this proof until more machinery is developed.\r\nBut let us see some implications first.\r\n\\begin{corollary}\r\n    Let $K$ be a simplicial complex, then for all $r$, there is a canonical isomorphism $H_n(K)\\cong H_n(K^{(r)})$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Suffices to make the choice for $r=1$.\r\n    Choose a simplicial approximation $s:K'\\to K$ to the identity on $|K|$ which induces an ismorphism $s_\\ast:H_n(K')\\to H_n(K)$ by the preceding proposition.\r\n    To see this is canonical, we shall show that this isomorphism is independent of the choice of $s$.\r\n    But this is obvious since any other choice $s'$ is contiguous with $s$.\r\n\\end{proof}\r\nWe write $\\nu_{K,r,s}:H_n(K^{(r)})\\to H_n(K^{(s)})$ as the canonical ismorphism for $r\\ge s$ and write $\\nu_{K,r}=\\nu_{K,r,0}$.\r\nThen $\\nu_{K,r_2,r_3}\\circ \\nu_{K,r_1,r_2}=\\nu_{K,r_1,r_3}$.\r\n\\begin{proposition}\r\n    To each continuous map $f:|K|\\to|L|$, there is an associated homomorphism $f_\\ast:H_n(K)\\to H_n(L)$ given by $f_\\ast=s_\\ast\\circ\\nu_{K,r}^{-1}$ where $s:K^{(r)}\\to L$ is a simplicial approximation to $f$.\r\n    This homomorphism does not depend on the choice of $r$ or $s$.\r\n    Furthermore, if $g:|M|\\to |K|$ is continuous for some other simplicial complex $M$, then $(f\\circ g)_\\ast=f_\\ast\\circ g_\\ast$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We already know that the homomorphism does not depend on the choice of $s$.\r\n    If $s:K^{(r)}\\to L,t:K^{(q)}\\to L$ are both simplicial approximations to $f$ where WLOG $r\\ge q$, then let $a:K^{(r)}\\to K^{(q)}$ be a simplicial approximation to the identity on $|K|=|K^{(q)}|$.\r\n    Now $s,t\\circ a:K^{(r)}\\to L$ are both simplicial approximations to $f$, hence are contiguous and induces the same homomorphism $s_\\ast=(t\\circ a)_\\ast=t_\\ast\\circ a_\\ast=t_\\ast\\circ\\nu_{K,r,q}$, so $s_\\ast\\circ\\nu_{K,r}^{-1}=t_\\ast\\circ\\nu_{K,r,q}\\circ\\nu_{K,r}^{-1}=t_\\ast\\circ\\nu_{K,q}$ as desired.\\\\\r\n    Now let $s:K^{r}\\to L$ and $t:M^{q}\\to K^{r}$ be simplicial approximations to $f,g$ respectively (here we used $|K|=|K^{(r)}|$).\r\n    Then $s\\circ t$ is a simplicial approximation of $f\\circ g$, so\r\n    $$(f\\circ g)_\\ast=(s\\circ t)_\\ast\\circ\\nu_{M,q}^{-1}=s_\\ast\\circ t_\\ast\\circ \\nu_{M,q}^{-1}=(s_\\ast\\circ\\nu_{K,r}^{-1})\\circ(\\nu_{K,r}\\circ t_\\ast\\circ\\nu_{M,q}^{-1})=f_\\ast\\circ g_\\ast$$\r\n    as desired.\r\n\\end{proof}\r\nAnd now we finally arrive at:\r\n\\begin{corollary}\r\n    If $|K|\\cong|L|$, then $H_n(K)\\cong H_n(L)$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nWe can do even better.\r\n\\begin{lemma}\r\n    If $L$ is a simplicial complex residing in $\\mathbb R^m$, then there exists $\\epsilon=\\epsilon(L)>0$ such that if $f,g:|K|\\to|L|$ satisfies $|f(x)-g(x)|<\\epsilon$ for any $x\\in |K|$, then $f_\\ast=g_\\ast$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    The set $\\{\\operatorname{St}_L(w):w\\in L\\}$ forms an open cover of $|L|$.\r\n    So by Lebesgue number lemma, there exists $\\epsilon>0$ such that each ball of radius $2\\epsilon$ in $L$ lies in some $\\operatorname{St}_L(w)$.\r\n    We take $\\epsilon(L)=\\epsilon$.\r\n    Let $f,g:|K|\\to|L|$ as in the statement and consider the open cover of $|K|$ given by $\\{f^{-1}(B_\\epsilon(y)):y\\in L\\}$ which admits $\\delta>0$ such that each $B_\\delta(x)$ is contained in some member of this cover again by Lebesgue number lemma.\r\n    This would mean that $f(B_\\delta(x))\\subset B_\\epsilon(x)$, so $g(B_\\delta(x))\\subset B_{2\\epsilon}(y)$.\r\n    Choose some large $r$ such that $\\operatorname{mesh}(K^{(r)})<\\delta/2$, then for each vertex $v\\in K^{(r)}$, the diameter of $\\operatorname{St}_{K^{(r)}}(v)$ is strictly less than $\\delta$, so both $f(\\operatorname{St}_{K^{(r)}}(v))$ and $g(\\operatorname{St}_{K^{(r)}}(v))$ are contained in some $\\operatorname{St}_L(w)$.\r\n    Set $s(v)=w$, then $s$ is a simplicial approximation to both $f$ and $g$, hence $f_\\ast=s_\\ast\\circ \\nu_{K,r}^{-1}=g_\\ast$.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    If two maps $f,g:|K|\\to|L|$ are homotopic, then $f_\\ast=g_\\ast$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $H:|K|\\times I\\to |L|$ be the homotopu between $f,g$, so $H(\\cdot,0)=f,H(\\cdot,1)=g$.\r\n    As $|K|\\times I$ is compact, $H$ is uniformly continuous.\r\n    Thus for $\\epsilon=\\epsilon(L)$ as in the preceding lemma, there is some $\\delta>0$ such that $|H(x,s)-H(x,t)|<\\epsilon$ whenever $|s-t|<\\delta$.\r\n    Now choose $0=t_0<t_1<\\ldots<t_k=1$ such that $t_i-t_{i-1}<\\delta$ for any $i$ and let $f_i(x)=H(x,t_i)$.\r\n    By construction $|f_i(x)-f_{i-1}(x)|<\\epsilon$ for any $x\\in |K|$, therefore $(f_i)_\\ast=(f_{i-1})_\\ast$ for all $i$.\r\n    In particular, $f_\\ast=(f_0)_\\ast=\\cdots=(f_k)_\\ast=g_\\ast$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $|K|,|L|$ are homotopy equivalent, then $H_n(K)\\cong H_n(L)$ for all $n$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\n\\begin{definition}\r\n    We write $H_n(X)=H_n(K)$ if $X=|K|$.\r\n\\end{definition}", "meta": {"hexsha": "9a197330417cb8d089b3aadd540234c2b55349ac", "size": 28485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/simphomol.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": "5/simphomol.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": "5/simphomol.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": 72.8516624041, "max_line_length": 327, "alphanum_fraction": 0.6537124803, "num_tokens": 10417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6572282602853915}}
{"text": "\\label{sec:Averaging}\n\nA {\\it mesh catalog} is a set $\\{ \\M_0 \\ldots \\M_{n-1} \\}$\nof $n$ meshes which are all embeddings\nof the same simplicial complex\n(that is, they have the same vertices, edges, and faces,\nbut the vertex positions may be different).\n\n\\subsection{Linear weights}\n\\label{sec:Linear-weights}\n\nWe can compute a {\\it weighted average mesh} by averaging the vertex positions:\n\\begin{equation}\n\\p_i(\\w) = \\sum_{j=0}^{n-1} w_j \\p_{ij}\n\\end{equation}\nwhere $\\p_{i}; (i=0 \\ldots m-1)$ is the position of the $i$th vertex of the average mesh,\nand $\\p_{ij}$ is the position of the $i$th vertex of the $j$th catalog element.\n\nIn {\\it catalog fitting} we fit a registered weighted average mesh,\nto a set of data, $\\{ \\d_k \\in \\Reals^3; k=0 \\ldots p-1 \\}$\nby minimizing\n\\begin{equation}\nf(\\M(\\Tr,\\w)) = \\sum_{k=0}^{p-1} \\| \\d_k - \\Pr_{\\M(\\Tr,\\w)} (\\d_k) \\|^2 ,\n\\end{equation}\nover a family of registration transforms $\\{\\Tr\\}$\nand vectors of weights $\\w \\in \\Reals^n$.\nThe vertex positions $\\p(\\Tr,\\w) = (\\p_0(\\Tr,\\w) \\ldots  \\p_{n-1}(\\Tr,\\w))$\nof the registered average mesh, $\\M(\\Tr,\\w)$, are given by:\n\\begin{equation}\n\\p_i(\\Tr,\\w) = \\Tr ( \\sum_{j=0}^{n-1} w_j \\p_{ij} )\n\\end{equation}\n\nThe partial derivative with respect to $\\Tr$\nis:\n\\begin{eqnarray}\n\\De{\\Tr}{f(\\M(\\Tr,\\w))}{\\Tr^0,\\w^0}\n& = &\n\\De{\\p}{f(\\M))}{\\M(\\Tr^0,\\w^0)}\n\\circ\n\\De{\\Tr}{\\p(\\Tr,\\w)}{\\Tr^0,\\w^0}\n\\\\\n& = &\n\\De{\\p}{f(\\M))}{\\M(\\Tr^0,\\w^0)}\n\\circ\n\\De{\\Tr}{\\Tr\\p(\\w^0)}{\\Tr^0}\n\\nonumber\n\\end{eqnarray}\n\n$\\De{\\p}{f(\\M))}{\\M(\\Tr^0,\\w^0)}$ is the derivative of $f$ with respect to\nthe vertex positions of of the registered average mesh.\nIt's value for data fitting distance functions\nis given in \\autoref{sec:data-fitting}.\n\n$\\Df{\\Tr}{\\Tr\\p}$ is given in \\autoref{sec:Transforms}\nfor various families of transforms $\\{\\Tr\\}$: affine, euclidean, and rigid.\n\nUsing the chain rule, the partial derivative with respect to $\\w$ is:\n\\begin{eqnarray}\n\\De{\\w}{f(\\M(\\Tr,\\w))}{\\Tr^0,\\w^0}\n& = &\n\\De{\\w}{f(\\Tr(\\M(\\w)))}{\\Tr^0,\\w^0}\n\\\\\n& = &\n\\De{\\p}{f(\\M))}{\\M(\\Tr^0,\\w^0)}\n\\circ\n\\De{\\Tr}{\\Tr\\p(\\w^0)}{\\Tr^0}\n\\circ\n\\De{\\w}{\\p(\\w)}{\\w^0}\n\\nonumber\n\\end{eqnarray}\n\n$\\Df{\\p}{f}$ and $\\Df{\\Tr}{\\Tr\\p}$ are already known\nso we need only determine $\\Df{\\w}{\\p(\\w)}$.\nUsing reasoning similar\nto equation \\ref{eq:total-registration-transform-derivative},\nwe have $\\p(\\w) = \\bigoplus_{j=0}^{m-1} \\p_i(\\w)$,\nand\n$\\Df{\\w}{\\p(\\w)}\n=\n\\Df{\\w}{\\bigoplus_{j=0}^{m-1} \\p_i(\\w)}\n=\n\\bigoplus_{j=0}^{m-1} \\Df{\\w}{\\p_i(\\w)}$,\nso we can restrict ourselves to\n$\\Df{\\w}{\\p(\\w)}$, where $\\p(\\w) = \\sum_{i=0}^{n-1} w_i \\p_i$,\nand $\\p, \\p_i \\in \\Reals^3$.\n\nNote that $\\p(\\w)$ is a linear transform from $\\Reals^n \\mapsto \\Reals^3$,\nwhich can be expressed as $\\P = \\sum_{i=0}^{n-1} \\p_i \\otimes \\e_i$,\nwhere $\\e_i$ are the canonical basis vectors of $\\Reals^n$.\n($\\P$ can be written as a matrix whose $i$th column is the vector $\\p_i$.)\nThus it follows that\n\\begin{equation}\n\\Df{\\w}{\\p(\\w)} = \\Df{\\w}{\\P\\w} = \\P\n\\end{equation}\n\n\\subsection{Convex weights}\n\\label{sec:Convex-weights}\n\nIt may be desireable to restrict the weights to be convex,\nthat is, $0 \\leq w_i \\leq 1; \\sum w_i = 1$.\nTo use unconstrained optimization methods with convex weights,\nwe re-parameterize:\n\\begin{equation}\nu_i(\\w) = {{w_i^2} \\over {\\| \\w \\|^2}}\n\\end{equation}\nwhere, as usual, $\\| \\w \\|^2 = \\sum_{j=0}^{n-1} w_j^2$.\n\nThen we need to compute\n\\begin{eqnarray}\n\\De{\\w}{\\p(\\u(\\w))}{\\w^0}\n& = &\n\\De{\\u}{\\p(\\u)}{\\u(\\w^0)}\n\\circ\n\\De{\\w}{\\u(\\w)}{\\w^0}\n\\\\\n& = &\n\\P\n\\circ\n\\De{\\w}{\\u(\\w)}{\\w^0}\n\\nonumber\n\\end{eqnarray}\n\nThe partial derivatives are\n\\begin{eqnarray}\n\\Df{w_j}{u_i(\\w))}\n& = &\n\\Df{w_j}{{w_i^2} \\over {\\| \\w \\|^2}}\n\\\\\n& = &\n{{2 w_j} \\over {\\| \\w \\|^4}} \\left( \\delta_{ij} \\| \\w \\|^2 - w_i^2 \\right)\n\\nonumber\n\\end{eqnarray}\n", "meta": {"hexsha": "61ecfed0fd0c8201d6e3aa80e0ab8b9e9a98a300", "size": 3737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/averaging.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/averaging.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/averaging.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0977443609, "max_line_length": 89, "alphanum_fraction": 0.6098474712, "num_tokens": 1535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6572269302479437}}
{"text": "\\section{Hyperparameter Tuning}\\label{section:background-hyperparameter}\nHyperparameter tuning is the process of optimizing a model to find the hyperparameters that will perform optimally given a specified metric. This metric is usually either the validation loss or the validation accuracy.\nHyperparameters are generally chosen by hand or by some automated process, but are not learned as a part of the model itself as opposed to the model weights.\n\nMethods to find the optimal hyperparameters include manual tuning, grid search, random search, genetic algorithms, bayesian optimization, and hyperband, among others.\nRandom and grid searches are very time-consuming and computationally expensive, as they potentially run less than optimal parameters and do not use knowledge of previous runs to select the next set of parameters.\nBayesian optimization attempts to curtail this problem by taking previous runs into account, greatly speeding up the learning process and not experimenting with less than optimal hyperparameters~\\cite{bayesian}.\nHyperband is a bandit-based approach to hyperparameter optimizations that can abandon or reduce the budget of an experimental run if the network performance is below with a chosen parameter set is below a certain threshold~\\cite{hyperband}.\n\n\\subsection{Bayesian Optimization}\\label{subsection:background-bayesian}\nThe idea behind Bayesian optimization is that the hyperparameters of a network follow a probabilistic distribution $\\text{P}(y | x)$ where $y$ is the score determined by some objective function and $x$ is a set of hyperparameters.\nBased on this probabilistic model, an optimal set of hyperparameters can then be calculated.\nApplying these hyperparameters to the model, the objective function can then be used to calculate the scores.\nThe probabilistic distribution is then updated and the process is repeated until the maximum number of iterations is reached.\n\nBayesian optimization relies on the following~\\cite{bayesiantds}:\n\\begin{enumerate}\n\t\\itemsep-1em\n\t\\item A clearly defined hyperparameter domain of possible configurations $\\chi$ over which to search,\n\t\\item An objective function which calculates a score that we wish to minimize using a set of hyperparameters,\n\t\\item A surrogate model that represents the probabilistic distribution of the hyperparameters,\n\t\\item A selection function to evalute which hyperparameters should be evaluated next, and\n\t\\item A history of score-hyperparameter pairs used to update the surrogate model.\n\\end{enumerate}\nThe domain must be chosen by the researcher and is usually defined with respect to previous knowledge or based on related works.\nThe objective function is evaluated by running the model and calculating its error using a predetermined loss function.\n\nThe surrogate model used is essentially a mapping of hyperparameters to scores from the objective function.\nAn example for the surrogate model is the Tree-structured Parzen Estimator (TPE)~\\cite{tpe}.\nTPE takes advantage of Bayes' rule and represents the probability function $\\text{P}(y~|~x)$ as\n\\begin{equation}\\label{eq:bohb-1}\n\t\\begin{split}\n\t\t\\text{P}(y~|~x) &= \\frac{\\text{P}(x~|~y) \\cdot \\text{P}(x)}{\\text{P}(y)}\\\\\n\t\t\\text{with } \\text{P}(x~|~y) &=\n\t\t\\begin{cases}\n\t\tl(x) &\\text{when } y < y^* \\\\\n\t\tg(x) &\\text{when } y \\geq y^*\n\t\t\\end{cases}\n\t\\end{split}\n\\end{equation}\nwhere $y^*$ is a threshold value. $l(x)$ is thus a probability density function formed from the set of observations using hyperparameters $x^i \\in \\chi$ which have been performed such that the loss of the network is less than $y^*$. \nConversely, $g(x)$ is the density function formed from the remaining observations.\n$y^*$ is chosen by the algorithm such that $\\text{P}(y<y^*) = \\gamma$ with $\\gamma$ being a value chosen by the researcher.\n\nThe selection function chooses which hyperparameters $x \\in \\chi$ should be chosen for each successive experiment and is commonly based on the expected improvement~\\cite{bayesiantds}:\n\\begin{align}\n\tEI_{y^*}(x) &= \\int_{-\\infty}^{y^*} (y^* - y) p(y~|~x)dy\n\\end{align}\nHere, $y^*$ is again a threshold value, $x$ is the proposed set of hyperparameters, $y$ is the actual value of the objective function using hyperparameters $x$ and $p(y~|~x)$ is the surrogate probability model expressing the probability of $y$ given $x$.\nSubstituting the values of $p(y~|~x)$ from the surrogate function we get\n\\begin{equation}\n\t\\begin{split}\n\t\tEI_{y^*}(x) &= \\frac{\\gamma y^* l(x) - l(x) \\int_{-\\infty}^{y^*}p(y)dy}{\\gamma l(x) + (1 - \\gamma)g(x)}\\\\\n\t\t&\\propto \\left(\\gamma + \\frac{g(x)}{l(x)} (1 - \\gamma)\\right)^{-1}\n\t\\end{split}\n\\end{equation}\nWe can see from this function that the expected improvement is proportional to $\\frac{l(x)}{g(x)}$ and thus, to maximize the expected improvement, samples should be drawn from the maximum value in $l(x)$.\nThe selected hyperparameters are then evaluated with regards to the objective function and the results used to update the surrogate model.\n\n\\subsection{Hyperband}\\label{section:background-hyperband}\nHyperband is a learning strategy that \"relies on a principled early-stopping strategy to allocate resources\"~\\cite{hyperband}. \nIt is a variation of successive halving, and in fact uses successive halving in its inner loop~\\cite{successivehalving}.\n\nSuccessive halving randomly samples $n$ hyperparameter sets in the search domain $\\chi$.\nIt then evaluates all of these sets for $B$ iterations to calculate the validation loss.\nThe lowest performing half is then discarded and the remaining evaluated for a further $B$ iterations.\nThis is repeated until only one hyperparameter set remains.\n\nSuccessive halving suffers from the $n \\text{ vs } \\frac{B}{n}$ problem, which is whether to train more configurations $n$ or to explore fewer, but with more resources $B$.\nIf a larger $n$ is chosen, configurations which are slower to converge might be killed off too quickly.\nIf a larger $\\frac{B}{n}$ is chosen, then lower performing configurations may be given more resources, thus wasting resources that could otherwise be spent on higher performing configurations~\\cite{hyperband}.\n\nHyperband attempts to solve this issue by considering several possible values of $n$ for a fixed $B$.\nThe pseudocode in Algorithm \\ref{algorithm:hyperband} shows how Hyperband uses an outer loop, performing essentially a grid search with multiple values of $n$ and an inner loop utilizing a method similar to successive halving but with the top $\\left\\lfloor n_i/\\eta\\right\\rfloor$ instead of the top half.\n\n\\input{algorithms/hyperband}\n\n\\subsection{Bayesian Optimization with Hyperband}\\label{section:background-bohb}\n\"BOHB: Robust and Efficient Hyperparameter Optimization at Scale\" by Stefan Falkner, Aaron Klein, and Frank Hutter proposes a hyperparameter optimization approach which seeks to combine the benefits of both Bayesian optimization and Hyperband~\\cite{bohb}.\nThis approach seeks to have strong anytime performance, strong final performance, effectively use parallel resources, be easily scalable, and be robust and flexible.\n\nBOHB works by using Hyperband to determine the number of configurations to evaluate with a given budget, but replaces the random selection of configurations with a Bayesian model based search.\nThe process of using Bayesian optimization for configuration sampling can be seen in Algorithm \\ref{algorithm:bohb}. In this algorithm, $l'(x)$ is the $l(x)$ component of the newly updated probability density function.\n\nEven though Hyperband also provides strong anytime performance compared to random search and Bayesian optimization, Fakner et al. observed an improvement of over 55x against a random search at larger budgets, converging to the global optimum much faster than either Hyperband or Bayesian optimization alone~\\cite{bohb}.\n\n\\input{algorithms/bohb}", "meta": {"hexsha": "55e5b2b9b0ec02080287d4dfd0b1f0cc58ab841b", "size": 7804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/3_2-hyperparameters.tex", "max_stars_repo_name": "yvan674/bachelor-thesis", "max_stars_repo_head_hexsha": "00121f35245c20ddf77bd5d0ca9467460849902c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/3_2-hyperparameters.tex", "max_issues_repo_name": "yvan674/bachelor-thesis", "max_issues_repo_head_hexsha": "00121f35245c20ddf77bd5d0ca9467460849902c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/3_2-hyperparameters.tex", "max_forks_repo_name": "yvan674/bachelor-thesis", "max_forks_repo_head_hexsha": "00121f35245c20ddf77bd5d0ca9467460849902c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.7011494253, "max_line_length": 319, "alphanum_fraction": 0.7844695028, "num_tokens": 1831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6572269254474908}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Elementary maths}\n\n\\vspace{-5pt}\n\nThis example is based on a similar example in the \\href{../../python/examples/example-01.pdf}{Python collection}. Its purpose is to show that Cadabra is fluent in Python -- which is not surprisng since the Cadabra language is based on Python (and a subset of LaTeX).\n\n\\vspace{-8pt}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{cadabra}\n   from sympy import *\n   x, y, z = symbols('x y z')\n   a, b, c = symbols('a b c')\n   ans = expand((a+b)**3)                                  # cdb (ans.101,ans)\n   ans = factor(-2*x+2*x+a*x-x**2+a*x**2-x**3)             # cdb (ans.102,ans)\n   ans = solve(x**2-4, x)                                  # cdb (ans.103,ans)\n   ans = solve([2*a-b - 3, a+b+c - 1,-b+c - 6],[a,b,c])    # cdb (ans.104,ans)\n   ans = N(pi,50)                                          # cdb (ans.105,ans)\n   ans = apart(1/((1 + x)*(5 + x)))                        # cdb (ans.106,ans)\n   ans = together((1/(1 + x) - 1/(5 + x))/4)               # cdb (ans.107,ans)\n   ans = simplify(tanh(log(x)))                            # cdb (rhs.108,ans)\n   ans = simplify(tanh(I*x))                               # cdb (rhs.109,ans)\n   ans = simplify(sinh(3*x) - 3*sinh(x) - 4*(sinh(x))**3)  # cdb (rhs.110,ans)\n   ans = tanh(log(x))                                      # cdb (lhs.108,ans)\n   ans = tanh(UnevaluatedExpr(I*x))                        # cdb (lhs.109,ans)\n   ans = sinh(3*x) - 3*sinh(x) - 4*(sinh(x))**3            # cdb (lhs.110,ans)\n\\end{cadabra}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      &\\cdb*{ans.101}\\\\\n      &\\cdb*{ans.102}\\\\\n      &\\cdb*{ans.103}\\\\\n      &\\cdb*{ans.104}\\\\\n      &\\cdb*{ans.105}\\\\\n      &\\cdb*{ans.106}\\\\\n      &\\cdb*{ans.107}\\\\\n      \\cdb{lhs.108} &= \\Cdb{rhs.108}\\\\\n      \\cdb{lhs.109} &= \\Cdb{rhs.109}\\\\\n      \\cdb{lhs.110} &= \\Cdb{rhs.110}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\vspace{-8pt}\n\n\\begin{align*}\n   &\\cdb*{ans.101}\\\\\n   &\\cdb*{ans.102}\\\\\n   &\\cdb*{ans.103}\\\\\n   &\\cdb*{ans.104}\\\\\n   &\\cdb*{ans.105}\\\\\n   &\\cdb*{ans.106}\\\\\n   &\\cdb*{ans.107}\\\\\n   \\cdb{lhs.108} &= \\Cdb{rhs.108}\\\\\n   \\cdb{lhs.109} &= \\Cdb{rhs.109}\\\\\n   \\cdb{lhs.110} &= \\Cdb{rhs.110}\n\\end{align*}\n\n\\clearpage\n\n\\section*{Linear Algebra}\n\n\\vspace{-10pt}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{cadabra}\n   from sympy import linsolve\n   lamda = Symbol('lamda')\n   mat  = Matrix([[2,3], [5,4]])                   # cdb (ans.201,mat)\n   eig1 = mat.eigenvects()[0][0]                   # 1st eigenvalue\n   eig2 = mat.eigenvects()[1][0]                   # 2nd eigenvalue\n   v1   = mat.eigenvects()[0][2][0]                # 1st eigenvector\n   v2   = mat.eigenvects()[1][2][0]                # 2nd eigenvector\n   eig  = simplify(Matrix([eig1,eig2]))            # cdb (ans.202,eig)\n   vec  = simplify(5*Matrix([]).col_insert(0,v1)\n                               .col_insert(1,v2))  # cdb (ans.203,vec)\n   det  = expand((mat - lamda * eye(2)).det())     # cdb (ans.204,det)\n   rhs  = Matrix([[3],[7]])                        # cdb (ans.205,rhs)\n   ans  = list(linsolve((mat,rhs),x,y))[0]         # cdb (ans.206,ans)\n\\end{cadabra}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      &\\cdb*{ans.201}\\\\\n      &\\cdb*{ans.202}\\\\\n      &\\cdb*{ans.203}\\\\\n      &\\cdb*{ans.204}\\\\\n      &\\cdb*{ans.205}\\\\\n      &\\cdb*{ans.206}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\begin{align*}\n   &\\cdb*{ans.201}\\\\\n   &\\cdb*{ans.202}\\\\\n   &\\cdb*{ans.203}\\\\\n   &\\cdb*{ans.204}\\\\\n   &\\cdb*{ans.205}\\\\\n   &\\cdb*{ans.206}\n\\end{align*}\n\n\\clearpage\n\n\\section*{Limits}\n\n\\vspace{-10pt}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{cadabra}\n   n, dx = symbols('n dx')\n   ans = limit(sin(4*x)/x,x,0)                  # cdb (ans.301,ans)\n   ans = limit(2**x/x,x,oo)                     # cdb (ans.302,ans)\n   ans = limit(((x+dx)**2 - x**2)/dx, dx,0)     # cdb (ans.303,ans)\n   ans = limit((4*n + 1)/(3*n - 1),n,oo)        # cdb (ans.304,ans)\n   ans = limit((1+(a/n))**n,n,oo)               # cdb (ans.305,ans)\n\\end{cadabra}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      &\\cdb*{ans.301}\\\\\n      &\\cdb*{ans.302}\\\\\n      &\\cdb*{ans.303}\\\\\n      &\\cdb*{ans.304}\\\\\n      &\\cdb*{ans.305}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\begin{align*}\n   &\\cdb*{ans.301}\\\\\n   &\\cdb*{ans.302}\\\\\n   &\\cdb*{ans.303}\\\\\n   &\\cdb*{ans.304}\\\\\n   &\\cdb*{ans.305}\n\\end{align*}\n\n\\section*{Series}\n\n\\vspace{-10pt}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{cadabra}\n   ans = series((1 + x)**(-2), x, 1, 6)         # cdb (ans.401,ans)\n   ans = series(exp(x), x, 0, 6)                # cdb (ans.402,ans)\n   ans = Sum(1/n**2, (n,1,50)).doit()           # cdb (ans.403,ans)\n   ans = Sum(1/n**4, (n,1,oo)).doit()           # cdb (ans.404,ans)\n\\end{cadabra}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      &\\cdb*{ans.401}\\\\\n      &\\cdb*{ans.402}\\\\\n      &\\cdb*{ans.403}\\\\\n      &\\cdb*{ans.404}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\begin{align*}\n   &\\cdb*{ans.401}\\\\\n   &\\cdb*{ans.402}\\\\\n   &\\cdb*{ans.403}\\\\\n   &\\cdb*{ans.404}\n\\end{align*}\n\n\\clearpage\n\n\\section*{Calculus}\n\nThis example shows how {\\tt\\small\\verb|\\Cdb|} can be used to set the equation tag on the far right hand side.\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{cadabra}\n   ans = diff(x*sin(x),x)                                    # cdb (ans.501,ans)\n   ans = diff(x*sin(x),x).subs(x,pi/4)                       # cdb (ans.502,ans)\n   ans = integrate(2*sin(x)**2, (x,a,b))                     # cdb (ans.503,ans)\n   ans = Integral(2*exp(-x**2), (x,0,oo))                    # cdb (lhs.504,ans)\n   ans = ans.doit()                                          # cdb (ans.504,ans)\n   ans = Integral(Integral(x**2 + y**2, (y,0,x)), (x,0,1))   # cdb (lhs.505,ans)\n   ans = ans.doit()                                          # cdb (ans.505,ans)\n\\end{cadabra}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      &\\cdb*{ans.501}\\\\\n      &\\cdb*{ans.502}\\\\\n      &\\cdb*{ans.503}\\\\\n       \\cdb{lhs.504}&=\\Cdb{ans.504}\\\\\n       \\cdb{lhs.505}&=\\Cdb{ans.505}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\begin{align*}\n   &\\cdb*{ans.501}\\\\\n   &\\cdb*{ans.502}\\\\\n   &\\cdb*{ans.503}\\\\\n    \\cdb{lhs.504}&=\\Cdb{ans.504}\\\\\n    \\cdb{lhs.505}&=\\Cdb{ans.505}\n\\end{align*}\n\n\\clearpage\n\n\\section*{Differential equations}\n\n\\vspace{-10pt}\n\n\\begin{minipage}[t]{0.70\\textwidth}\n\\begin{cadabra}\n   y = Function('y')\n   C1, C2 = symbols('C1 C2')\n\n   ode = Eq(y(x).diff(x) + y(x), 2*a*sin(x))\n   sol = expand(dsolve(ode,y(x)).rhs)                              # cdb (ans.601,sol)\n   cst = solve([sol.subs(x,0)],dict=True)\n   sol = sol.subs(cst[0])                                          # cdb (ans.602,sol)\n\n   ode = Eq(y(x).diff(x,2) + y(x), 0)\n   sol = expand(dsolve(ode,y(x)).rhs)                              # cdb (ans.603,sol)\n   cst = solve([sol.subs(x,0),sol.diff(x).subs(x,0)-1],dict=True)\n   sol = sol.subs(cst[0])                                          # cdb (ans.604,sol)\n\n   ode = Eq(y(x).diff(x,2) + 5*y(x).diff(x) - 6*y(x), 0)\n   sol = expand(dsolve(ode,y(x)).rhs)                              # cdb (ans.605,sol)\n   sol = sol.subs({C1:2,C2:3})                                     # cdb (ans.606,sol)\n\\end{cadabra}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.30\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      &\\cdb*{ans.601}\\\\\n      &\\cdb*{ans.602}\\\\\n      &\\cdb*{ans.603}\\\\\n      &\\cdb*{ans.604}\\\\\n      &\\cdb*{ans.605}\\\\\n      &\\cdb*{ans.606}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\begin{align*}\n   &\\cdb*{ans.601}\\\\\n   &\\cdb*{ans.602}\\\\\n   &\\cdb*{ans.603}\\\\\n   &\\cdb*{ans.604}\\\\\n   &\\cdb*{ans.605}\\\\\n   &\\cdb*{ans.606}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "c90e20543a1d4d57f598c4d603c26da09b5a8c76", "size": 7858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cadabra/examples/example-01.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-01.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-01.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": 29.2118959108, "max_line_length": 266, "alphanum_fraction": 0.4928735047, "num_tokens": 3062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940925, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6571970541656775}}
{"text": "\\gotosection{0}{4}\n\\subsection{Functions}\n\n\\begin{exercise}{9}\n  \\begin{enumerate}\n    \\item $\\begin{aligned}[t]\n            (f \\circ g \\circ h)(a) &= f(g(h(a))) = f(g(h(3))) \\\\\n                                   &= f(g(-3+2)) = f(g(-1)) \\\\\n                                   &= f(3 \\times (-1)) = f(-3) \\\\\n                                   &= (-3)^2-1 = 8\n          \\end{aligned}$\n    \\item $\\begin{aligned}\n            (f \\circ g \\circ h)(a) &= f(g(h(a))) = f(g(h(1))) \\\\\n                                   &= f(g(1-3)) = f(g(-2)) \\\\\n                                   &= f(-2-3) = f(-5) \\\\\n                                   &= (-5)^2 = 25\n          \\end{aligned}$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{10}\n  \\begin{enumerate}\n    \\item Let the function \\FunSS{f}{B}{C} and \\FunSS{g}{A}{B} be onto.\n          Then the composition $f \\circ g$ is onto.\n\n    \\Proof{} For every $c \\in C$: since \\FunSS{f}{B}{C} is surjective, there\n    exists $b \\in B$ such that $f(b) = c$; since \\FunSS{g}{A}{B} is surjective,\n    there exists $a \\in A$ such that $g(a) = b$. Therefore, for every $c \\in C$,\n    there exists $a \\in A$ such that $(f \\circ g)(a) = f(g(a)) = c$.\n    Thus, $f \\circ g$ is surjective, or onto. \\QED\n\n    \\item Let the function \\FunSS{f}{B}{C} and \\FunSS{g}{A}{B} be one to one.\n          Then the composition $f \\circ g$ is one to one.\n\n    \\Proof{} For every $c \\in C$ such that there exists $a \\in A$ such that\n    $f(g(a)) = c$, suppose there do exist $x, y \\in A$ such that both $f(g(x)) = c$\n    and $f(g(y)) = c$. Since $f$ is injective, $g(x) = g(y)$. Since $g$ is injective\n    , $x = y$. Therefore, there is at most one $x$ such that $(f \\circ g)(x) =\n    f(g(x)) = c$. Thus, $f \\circ g$ is injective, or one to one. \\QED\n  \\end{enumerate}\n\\end{exercise}\n", "meta": {"hexsha": "d0d03f74150e1077e39db336a0dbcc2a14b8fa27", "size": 1792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW3/sec04.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/sec04.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/sec04.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": 42.6666666667, "max_line_length": 84, "alphanum_fraction": 0.4698660714, "num_tokens": 608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.657043781329633}}
{"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{A System of Linear Equations}\n\nThis problem can be solved by utilizing a system of linear equations.\nEach equation represents the input and output of a specific router node.\nFirst we must construct a table of the input and output flow of each node.\nThe input and output must be equivalent for each node.\nSolving for variables for each node gives us a system of linear equations.\n\n\\begin{center}\n\\begin{tabular}{c | l | l}\n\n    \\textbf{Node} & \\textbf{Input} & \\textbf{Output} \\\\ \\hline\n\n    A & 100                         & $2x_1 + x_2$ \\\\\n    B & $x_1 + x_2$                 & $x_3 + x_5$  \\\\\n    C & $50 + x_1$                  & $x_3 + x_5$  \\\\\n    D & $x_4 + x_5$                 & $x_2 + 120$  \\\\\n    E & $x_2 + x_3 + x_5$ \\hspace{8mm} & $x_4$                         \n    \n\\end{tabular}\n\n\n\\begin{tabular}{c | l}\n    \\textbf{Node} & \\textbf{Equations} \\\\ \\hline\n    A & $2x_1 + x_2 = 100$ \\\\\n    B & $x_1 + x_2 - x_3 - x_5 = 0$    \\\\\n    C & $x_1 - x_3 - x_5 = -50$        \\\\\n    D & $-x_2 + x_4 + x_5 = 120$       \\\\\n    E & $x_2 + x_3 - x_4 + x_5 = 0$\n\\end{tabular}\n\\end{center}\n\nUtilizing this system of equations, we can construct a matrix equation of the form $Ax = b$ representing it.\nThis becomes equation (1) below:\n\n\\begin{center}\n\\begin{equation}\n    \\begin{bmatrix}\n        2 & 1 & 0 & 0 & 0   \\\\\n        1 & 1 & -1 & 0 & -1 \\\\\n        1 & 0 & -1 & 0 & -1 \\\\\n        0 & -1 & 0 & 1 & 1  \\\\\n        0 & 1 & 1 & -1 & 1 \n    \\end{bmatrix}\n    \\begin{bmatrix}\n        x_1 \\\\\n        x_2 \\\\\n        x_3 \\\\\n        x_4 \\\\\n        x_5\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        100 \\\\\n        0 \\\\\n        -50 \\\\\n        120 \\\\\n        0\n    \\end{bmatrix}\n\\end{equation}\n\\end{center}\n\n\\end{document}\n", "meta": {"hexsha": "01dd9542b3549bc8550d892473697d0979bcbe53", "size": 2045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Projects/matrix_theory/docs/tex/system_of_equations.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/system_of_equations.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/system_of_equations.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": 25.2469135802, "max_line_length": 108, "alphanum_fraction": 0.5457212714, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.657043776893009}}
{"text": "%!TEX root = paper.tex\r\n\\subsection{Linear standing wave}\r\nThe linear standing wave test illustrates the different linear dispersion relations and the ability of the numerical method to represent them in an accurate manner. \r\nBoth, the linearized systems of the hydrostatic and dispersive have an analytic standing wave solution\r\n\\begin{align}\r\n\\xi(\\bx,t)&=-a\\sin\\left(\\kappa x \\right)\\cos\\left(\\kappa ct\\right), \\\\\r\n u(\\bx,t) &=a \\frac{c}{d}\\cos\\left(\\kappa x\\right)\\sin\\left(\\kappa ct\\right), \\\\\r\n v(\\bx,t) &=0, \\qquad \\forall \\ \\bx=(x, y)^T \\in \\Omega, \\forall t \\in \\mathbb{R},\r\n\\end{align}\r\nwhere the phase velocity $c=\\frac{\\omega_{\\text{nh,}\\fnh}}{\\kappa}$ is chosen for the dispersive equation set and $c=\\csw$ for the hydrostatic equation set, respectively. For the \\nh\\ model, the analytic vertical velocity has to be defined as\r\n\\[\r\nw(\\bx,t)=-\\frac{d}{2}\\partial_x u=\\frac{1}{2}ac\\kappa\\sin\\left(\\kappa x \\right)\\sin\\left(\\kappa ct\\right),\r\n\\]\r\nwhich is derived directly from \\eqref{eq:nh_closure}.\r\nIn different model runs, we vary the depth $d$ while keeping the wave length $\\lambda=\\frac{2\\pi}{\\kappa}=20$ m and the amplitude $a=0.01$m constant to get ratios for $\\frac{d}{\\lambda}$ between $0.05$ and $1.0$, and ratios for $\\frac{a}{d}$ between $0.01$ and $0.005$, respectively.\r\nWe impose double periodic boundary conditions on a grid length of one wave length. The simulation time is chosen long enough to measure one wave period. \r\n\r\n\\subsubsection{Results of \\nh\\ model}\r\nThe resulting normalized phase velocities for the shallow water model and the \\nh\\ equation set with either the linear or the quadratic vertical pressure are displayed in figure \\ref{fig:nh_standingwave}. Furthermore, they are compared to their analytical reference phase velocities and the full reference phase velocity as derived in section \\ref{sec:dispersion}. \r\nIn each case, the numerical dispersion relation matches the corresponding analytical one precisely.\r\n% The coincidence between numerical and analytical phase velocities is very good. \r\nIn a close neighborhood of the shallow water assumption (i.e., in the limit $\\frac{d}{\\lambda} \\rightarrow 0$), the quadratic vertical pressure profile gives a better phase velocity compared to the full reference solution than the linear profile, as expected from series expansions around this state used in \\Bt\\ models.\r\n% \\svnote{Can we have an additional detail plot of this neighborhood?} \\ajnote{Then only thinner lines would help. I could also provide the whole image with different plotting style (thinner lines and ) One could also use absolute errors between numerical values and reference phase velocities. }\\jbnote{What are you expecting to see?}\\svnote{I expect to see what we describe in the text, i.e., that the quadratic vertical pressure profile gives a better phase velocity than the linear one near $d/\\lambda=0$, see added figure.}\r\nHowever, for ratios $\\frac{d}{\\lambda} > 0.25$ approximately, the linear profile matches better.\r\n\r\n\\begin{figure}[htbp]\r\n        \\includegraphics*[width=0.95\\textwidth]{standingwave_nh.eps}\r\n        \\caption{Standing wave: Comparison of simulated hydrostatic and \\nh\\ phase velocities with analytic reference values for all simulations (left) and a zoom onto the close neighborhood of the long wave limit (right)}\r\n        \\label{fig:nh_standingwave}\r\n\\end{figure}\r\n\r\n", "meta": {"hexsha": "d7dfa14dc3770f9be621e002faa80ad77d63082b", "size": 3365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/papers/theoretical_1d/B_standingwave.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_standingwave.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_standingwave.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": 105.15625, "max_line_length": 529, "alphanum_fraction": 0.7545319465, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6570348310253676}}
{"text": "\\section{Juncai}\n\\subsection{Classification Problems for DNN}\nNow we want to make some rigorous mathematical statement about classification problem for DNN. What we want to state and prove is about, what's the necessary and sufficient conditions for $\\{x_i, y_i\\}_{i \\in I}$ such that, DNN model(with one hidden layer, when we talks about DNN model in this subsection, we always mean one hidden layer model.) can ``separate\" them. \n\nLet us note:\n\\begin{align}\nA_k = \\{x_i ~ | ~  y_i = e_k, i \\in I\\} \\quad k = 1:c. \n\\end{align}\nWe need the next two assumptions for data first:\n\\begin{assumption}[Boundedness]We say those data $\\{x_i, y_i\\}$ for $i \\in I$ are bounded if there exist a $M < \\infty$ such that\n\\begin{align}\n\\|x_i\\| < M \\quad \\forall i \\in I.\n\\end{align}\n\\end{assumption}\n\\begin{assumption}[Consistence]We say those data $\\{x_i, y_i\\}$ for $i \\in I$ are consistent for classification if\n\\begin{align}\nA_k \\cap A_k =  \\emptyset \\quad \\forall k\\neq l.\n\\end{align}\n\\end{assumption}\nThen we can have the next definition for what means ``DNN can separate  $\\{A_k\\}_{k=1}^c$\":\n\\begin{definition}\nWe say that DNN model can separate $\\{A_k\\}_{k=1}^c$ or DNN model can fix the classification problem for $\\{x_i ,y_i\\}_{i \\in I}$ means that there is a function $f: \\mathbb{R}^n \\to \\mathbb{R}^c$ such that:\n\\begin{align}\nf(x) = e_k \\quad \\forall x \\in A_k, ~~ k = 1:c,\n\\end{align}\nwith \n\\begin{align}\nf(x) = a(W_2 \\sigma(W_1 x + b_1) + b_2),\n\\end{align}\nfor some \n\\begin{align}\nW_1 \\in \\mathbb{R}^{m \\times n}, \\quad b_1 \\in \\mathbb{R}^m \\quad W_2 \\in \\mathbb{R}^{c\\times m}, \\quad b_2 \\in \\mathbb{R}^c, \\quad \\epsilon > 0,\n\\end{align}\nand $\\sigma, a: \\mathbb{R} \\to \\mathbb{R}$.\nHere $\\sigma$ can be ``Sigmoid\", ``ReLU\", ``Heaviside\" or $a$ function, with\n\\begin{equation}\n\\sigma(x) = \\frac{1}{1 + e^{-x}}, \\quad r(x) = \\max\\{0,x\\}, \\quad H(x) = \\begin{cases}\n1 ~~ &x > 0 \\\\\n0 ~~ &x \\le 0.\n\\end{cases}\n\\end{equation}\nand $a$ is a variant form of Heaviside function or combine of two ReLU functions like:\n%\\begin{equation}\n%\\hat{H}_{\\epsilon}(x) = \\begin{cases}\n%0 \\quad & x < \\epsilon, \\\\\n%\\frac{x}{1-2\\epsilon} - \\frac{\\epsilon}{1-2\\epsilon} \\quad & \\epsilon \\le x < 1-\\epsilon, \\\\\n%1 \\quad & x \\ge 1-\\epsilon.\n%\\end{cases}\n%\\end{equation}\n%By the way, $H_{\\epsilon}(x) = \\frac{1}{1-2\\epsilon}r(x - \\epsilon) +  \\frac{1}{1-2\\epsilon}r(x - 1 + \\epsilon).$\n\\begin{equation}\na(x) = \\begin{cases}\n0 \\quad & x < 0, \\\\\nx \\quad & 0 \\le x < 1, \\\\\n1 \\quad & x \\ge 1.\n\\end{cases}\n\\end{equation}\nBy the way, $a(x) = r(x ) - r(x - 1).$\n\n\\end{definition}\n\nHere we define what means ``$\\{A_k\\}_{k=1}^c$ are separable with positive distance\":\n\\begin{definition}\nWe say that $\\{A_k\\}_{k=1}^c$ are separable with positive distance when there exists a small positive number $\\epsilon$, such that\n\\begin{align}\nd(\\bar{A}_k, \\bar{A}_l) > \\epsilon, \\quad \\forall k \\neq l,\n\\end{align}\nwhere $\\bar{A}_k$ means the closure of $A_k$ and $d(\\bar{A}_k, \\bar{A}_l)$ define the distance of two sets as:\n\\begin{align}\nd(\\bar{A}_k, \\bar{A}_l) = \\inf_{x \\in A_k, y \\in A_l} d(x,y).\n\\end{align}\n\\end{definition}\n\nAs for the ``separable with positive distance\" property, we have the next lemma:\n\\begin{lemma}If $\\{A_k\\}_{k=1}^c$ are separable with positive distance $\\epsilon$, then there exist a smooth feature map $\\phi: \\mathbb{R}^n \\to \\mathbb{R}^c$ such that:\n\\begin{align}\n\\phi(x) = e_k \\quad \\forall x \\in \\bar{A}_k,\\quad k = 1:c.\n\\end{align}\n\\end{lemma}\n\\begin{proof}This proof is based on the partition of unity theorem. Because of the positive distance with $\\epsilon$ property, we define \n\\begin{equation}\n\\mathcal{M}_k = \\{x ~|~ d(x, \\bar{A}_k) < \\frac{\\epsilon}{2}\\}.\n\\end{equation}\nSo, $\\mathcal{M}_k$ is an open set as the continuity for $d(\\cdot, \\bar{A}_k)$. Let \n\\begin{equation}\n\\mathcal{M}_0 = (\\bigcup_{k=1:c} \\bar{A}_k)^c,\n\\end{equation}\nso $\\mathcal{M}_0$ is an open set too. And \n\\begin{equation}\n\\mathbb{R}^n = (\\bigcup_{k=0:c} \\mathcal{M}_k).\n\\end{equation}\nSo we can apply the partition of unity for the above decomposition, getting $\\{\\phi_k\\} \\in C^{\\infty}(\\mathbb{R}^n)$ for $k = 0:c$ and \n\\begin{equation}\n1 = \\sum_{k=0}^c \\phi_k \\quad \\text{with} \\quad supp(\\phi_k) \\subset \\mathcal{M}_k.\n\\end{equation}\nThen we will see that:\n\\begin{equation}\n\\phi_k(x_l) = \\delta_{kl} \\quad \\forall x_l \\in \\bar{A}_l, \\quad k, l = 1:c,\n\\end{equation}\nbecause of the definition of $\\mathcal{M}_k$ and the results of partition of unity.\n\nAt last, we can get $\\phi$ as:\n\\begin{align}\n\\phi: \\mathbb{R}^n &\\to \\mathbb{R}^c \\\\\n x &\\mapsto (\\phi_1(x), \\cdots, \\phi_c(x)),\n\\end{align}\nand it satisfy the condition.\n\\end{proof}\n\nNow we can have those next theorem:\n\\begin{theorem}\nIf $I$ is a finite index set, then DNN can always separate $\\{A_k\\}_{k=1}^c$.\n\\end{theorem}\n\n\\begin{theorem}\nIf $\\{A_k\\}_{k=1}^c$ are separable with positive distance, then it can be separated by DNN.\n\\end{theorem}\n\\begin{proof}\nWe know that \n\\begin{equation}\na(e_k) = e_k \\quad k = 1:c.\n\\end{equation}\n\nBecause of the universal approximation property for ``Sigmoid\", ``ReLu\", ``Heaviside\" or $a(x)$ type Neural Network, we can take \n\\begin{align}\n\\hat{W}_2\\sigma(W_1 x + b_1) + \\hat{b}_2,\n\\end{align}\nto approximate $\\phi$ in $B_M$ such that,\n\\begin{align}\n\\|\\hat{W}_2\\sigma(W_1 x + b_1) + \\hat{b}_2 - \\phi(x) \\|_{L^{\\infty}} < \\delta < \\frac{1}{4}, \\quad \\forall \\|x\\| \\le M.\n\\end{align}\n{\\bf Here $\\delta$ is independent with the distant of training data, we can choose any one in $(0, \\frac{1}{2})$ in fact. \nThis is because of the linearly separable of $\\{e_k\\}_{k=1}^c$ points.\n}\n\nNow we can take the DNN model as:\n\\begin{align}\nf(x) = a(\\frac{1}{1-2\\delta}\\hat{W}_2\\sigma(W_1 x + b_1) + (\\hat{b}_2 -\\frac{\\delta}{1-2\\delta}\\bm{1})).\n\\end{align}\nSo we only need to check that $f(x) = e_k$ if $x\\in A_k$ with $k=1:c$. \n\nIf $x \\in A_k$ for any $k=1:c$, we know that \n\\begin{align}\n|(\\hat{W}_2\\sigma(W_1 x + b_1) + \\hat{b}_2 - e_k)_i| < \\delta, \\quad  i = 1:c,\n\\end{align}\nwhich means that\n\\begin{equation}\n\\begin{cases}\n(\\hat{W}_2\\sigma(W_1 x + b_1) + \\hat{b}_2 )_i < \\delta \\quad &i\\neq k \\\\\n(\\hat{W}_2\\sigma(W_1 x + b_1) + \\hat{b}_2 )_i  > 1- \\delta \\quad &i = k.\n\\end{cases}\n\\end{equation}\nThus by the definition of $a(x)$, we know:\n\\begin{equation}\na(\\frac{x}{1-2\\delta} - \\frac{\\delta}{1-2\\delta}) = \\begin{cases}\n0 \\quad & x < \\delta, \\\\\n\\frac{x}{1-2\\delta} - \\frac{\\delta}{1-2\\delta} \\quad & \\delta \\le x < 1 - \\delta, \\\\\n1 \\quad & x \\ge 1 - \\delta.\n\\end{cases}\n\\end{equation}\nSo we have \n$f(x) = e_k$ if $x\\in A_k$ with $k=1:c$, for \n\\begin{align}\nf(x) = a(W_2\\sigma(W_1 x + b_1) + b_2),\n\\end{align}\nwith \n\\begin{equation}\nW_2 = \\frac{1}{1-2\\delta}\\hat{W}_2, ~ \\text{and} ~ b_2 = \\hat{b}_2 -\\frac{\\delta}{1-2\\delta}\\bm{1}.\n\\end{equation}\nThis finishes this proof.\n\\end{proof}\n\n\\begin{remark}\nHere $W_2$ have a special structure like as \n\\begin{align}\nW_2 = diag\\{\\omega_1, \\cdots, \\omega_c\\},\n\\end{align}\nwhere $\\omega_i \\in \\mathbb{R}^{1\\times n_i}$ with $\\sum_{i=1}^c n_i = m$.\n\\end{remark}\n\n\\begin{theorem}\nIf $\\{A_k\\}_{k=1}^c$ can be separated by DNN, then $\\{A_k\\}_{k=1}^c$ are separable with positive distance. \n\\end{theorem}\n\\begin{proof}First we know that,\n\\begin{align}\nA_k \\subset L_k := \\{x ~|~ f(x) = e_k\\}.\n\\end{align}\nHere $L_k$ is a closed set and $d(L_k, L_l) \\ge \\delta > 0$ because of the continuity of $f$. So, \n$\\{A_k\\}_{k=1}^c$ are separable with positive distance.\n\\end{proof}\n\n\\subsection{Linearly Separable and Global Minima}\n\nHere we note those data sets $\\{x_i, y_i\\}_{i=1}^N$ as $\\{A_k\\}_{k=1}^c$ with $y = e_k$ for any $x \\in A_k$. The simple NN model or perceptron with Heaviside function or $H_{\\epsilon}$ like:\n\\begin{equation}\nH_{\\epsilon}(x) = \\begin{cases}\n0 \\quad & x < -\\epsilon, \\\\\n\\frac{x}{2\\epsilon} - \\frac{1}{2} \\quad & -\\epsilon \\le x < \\epsilon, \\\\\n1 \\quad & x \\ge \\epsilon.\n\\end{cases}\n\\end{equation}\ncan classify those data means there exist $W \\in \\mathbb{R}^{c\\times n}$ and $b \\in \\mathbb{c}$ such that \n\\begin{align}\nH(Wx + b) = e_k \\quad x \\in A_k, ~ k =1:c.\n\\end{align}\n\nNote the loss function as:\n\\begin{align}\nL(\\theta) = \\sum_{i=1}^N\\|H(Wx_i + b) - y_i\\|^2. \n\\end{align}\n\n\\begin{properties}Those next two statements are equivalent:\n\\begin{enumerate}\n\\item The perceptron can classify those data.\n\\item $\\min L(\\theta) = 0$.\n\\end{enumerate}\n\\end{properties}\n\n\n\\begin{theorem}\\label{theo:linearconvex}\nLet\n\\begin{align}\n\\Theta := \\mathop{\\arg\\min}_{\\theta}L(\\theta).\n\\end{align}\nThen $\\Theta$ is a convex set if the perceptron can classify those data.\n\\end{theorem}\n\n\\begin{proof}\nIf the perceptron can classify those data, then $\\Theta \\neq \\emptyset$. So, let $\\theta_1, \\theta_2 \\in \\Theta$, let us consider $\\theta = t\\theta_1 + (1-t)\\theta_2$ with $t \\in [0,1]$.\nThen for any data $(x_i, y_i)$ and $\\theta = (W, b)$ we have\n\\begin{align}\nH(Wx_i + b) = H(t(W_1x_i + b_1) + (1-t)(W_2x_i + b_2)),\n\\end{align}\nand \n\\begin{align}\nH(W_1x_i + b_1) = H(W_2x_i + b_2) = y_i = e_k,\n\\end{align}\nfor some $1 \\le k \\le c$.\n\nBecause of the properties of Heaviside function(its level sets are convex sets), we know that:\n\\begin{align}\n(W_1 x_i + b_1)_j, (W_2 x_i + b_2)_j  \\le 0 \\quad &\\text{if}~ j \\neq k \\\\\n(W_1 x_i + b_1)_j, (W_2 x_i + b_2)_j    > 0 \\quad &\\text{if}~ j = k.\n\\end{align}\nThis means that $H(Wx_i + b) = e_k = y_i$, so $\\theta \\in \\Theta$.\n\\end{proof}\n\n%\\begin{remark}\n%This result also holds for $H_\\epsilon$ and $\\hat{H}_{\\epsilon}$, and in fact \n%\\begin{align}\n%\\hat{H}_{\\epsilon}(x) = H_{\\frac{1-2\\epsilon}{2}}(x -1).\n%\\end{align}\n%\\end{remark}\n\n\n\\begin{theorem}\\label{theo:linearinfinity}\nIf $A_i$ are compact sets, then \nthere are infinity global minima for $L(\\theta)$ if $\\{A_i\\}$ are also linearly separable.\n\\end{theorem}\n\\begin{proof}If $\\{A_i\\}$ are also linearly separable, then there exist $\\theta=(W,b)$ such that\n\\begin{align}\nH(Wx + b) = e_k \\quad x \\in A_k, ~ k =1:c.\n\\end{align}\nLet us note that:\n\\begin{align}\n(Wx + b)_k = \\omega_k^T x + b_k,\n\\end{align}\nso we have\n\\begin{align}\n\\omega_k^T x + b_k > 0 \\quad &\\text{if}~ x \\in A_k \\\\\n\\omega_k^T x + b_k \\le 0 \\quad &\\text{if}~ x \\in A \\setminus A_k.\n\\end{align}\nBy using the compactness for $A_k$, we have \n\\begin{align}\n\\min_{x\\in A_k} \\omega_k^T x + b_k = \\epsilon > 0.\n\\end{align}\nSo, there at leat have those different $\\theta_{k,\\delta}$ with \n\\begin{align}\n\\theta_{k,\\delta} = (W, \\hat{b}), \n\\end{align}\nand \n\\begin{align}\n\\begin{cases}\n\\hat{b}_i = b_i \\quad &\\text{if}~ i \\neq k \\\\\n\\hat{b}_i = b_i - \\delta \\quad &\\text{if}~ i = k,\n\\end{cases}\n\\end{align}\nfor any $0 \\le \\delta < \\epsilon$.\n\nNow, we next prove that, we can not only change $b$ but also $W$. First, we can assume that\n\\begin{align}\n\\omega_k^T x + b_k > 0 \\quad &\\text{if}~ x \\in A_k \\\\\n\\omega_k^T x + b_k >0 \\quad &\\text{if}~ x \\in A \\setminus A_k.\n\\end{align}\nIf this is not true, we can change $b_k$ such that this $\\theta$ can satisfy the above conditions with the above trick. Using the compactness again,\n\\begin{align}\n\\min_{x\\in A_k} \\omega_k^T x + b_k &\\ge \\epsilon > 0 \\\\\n\\max_{x\\in A\\setminus A_k} \\omega_k^T x + b_k &\\le -\\epsilon < 0,\n\\end{align}\nand $\\|x\\| < M $ for all $x \\in A$.\nSo we may construct $\\theta_{k,\\delta}$ like:\n\\begin{align}\n\\theta_{k,\\delta} = (\\hat{W}, b), \n\\end{align}\nand \n\\begin{align}\n\\begin{cases}\n\\hat{\\omega}_i = \\omega_i \\quad &\\text{if}~ i \\neq k \\\\\n\\hat{\\omega}_i = \\omega_i + \\omega \\quad &\\text{if}~ i = k,\n\\end{cases}\n\\end{align}\nwith $\\omega \\in B(0, \\frac{\\delta}{M}) \\subset \\mathbb{R}^n$ for any $0 < \\delta < \\epsilon$. Then we can check that\n\\begin{align}\n\\hat{\\omega}_k^T x + b_k > 0 \\quad &\\text{if}~ x \\in A_k \\\\\n\\hat{\\omega}_k^T x + b_k >0 \\quad &\\text{if}~ x \\in A \\setminus A_k.\n\\end{align}\nThis means $\\theta_{k,\\delta}$ with above form also belongs to $\\Theta$. \nThis shows that, $\\Theta$ is infinity set and have both degree of freedom on $W$ and $b$.\n\\end{proof}\n\n\n\\begin{theorem}\nIf the perceptron can classify those data, then the SGD method for $\\min L(\\theta)$ will convergence with small positive learning rate. \n\\end{theorem}\n\n\\subsection{Separable and Global Minima}\nIn simple terms, we assume that those $\\{A_k\\}_{k=1}^c$ are compact sets. Then the positive distance can be got from the consistency.  Here we note that, we want to use general DNN model with just one hidden layer to separate those data, so the loss function will be:\n\\begin{align}\nL(\\theta) = \\sum_{i=1}^N\\|H(W_2\\sigma(W_1x_i + b_1) + b_2) - y_i\\|^2, \n\\end{align}\nwith $H$ could be $\\hat{H}_{\\epsilon}$ or $H_\\epsilon$.\n\n\\begin{theorem}Let\n\\begin{align}\n\\Theta := \\mathop{\\arg\\min}_{\\theta}L(\\theta).\n\\end{align}\nFor $(\\theta_1, \\theta_2) \\in \\Theta$, we note that \n\\begin{equation}\n\\Theta_2(\\theta_1) = \\{\\theta ~|~ (\\theta_1, \\theta) \\in \\Theta \\}.\n\\end{equation}\nThen $\\Theta_2(\\theta_1)$ is a convex set if the DNN model can classify those data with compactness assumption.\n\\end{theorem}\n\n\\begin{proof}\nBecause of the continuity of $g(x) = \\sigma(W_1x + b_1)$, so we have that $\\{g(A_k)\\}_{i=k}^c$ are also compact sets, and the consistency of $A_k$ also shows the consistency of $g(A_k)$. \n\nThen because DNN model can classify those data, so $g(A_k)$ are also linear separable w.r.t to $\\hat{H}_\\epsilon$.\nSo, for fixed $\\theta_1$, we can finish this proof by using Theorem \\ref{theo:linearconvex}.\n\\end{proof}\n\n\\begin{theorem}If $A_i$ are compact sets, then \n$\\Theta_2(\\theta_1)$ is a infinity set if $\\{A_i\\}$ can be separated by DNN model.\n\\end{theorem}\n\\begin{proof}Use the analysis in the theorem above and we can get a similar poof with Theorem \\ref{theo:linearinfinity}.\n\\end{proof}\n\n\nNext, we want to talk about some properties about $\\theta_1$ part. We can also get some infinity property for \n\\begin{equation}\n\\Theta_1(\\theta_2) = \\{\\theta ~|~ (\\theta, \\theta_2) \\in \\Theta \\}\n\\end{equation} with some special $\\theta_2$.\n\n\\subsection{Discussion with Prof. Xu on 3/10/2017}\nProf. Xu proposed those next points about vanishing gradient and random strategies in training algorithms:\n\\begin{enumerate}\n\\item ``Vanishing Gradient' is a mathematical problem. \n\n\\item For deep neural network models, ReLU activation function is better than Sigmoid in many cases just likes that singular system can be solved more easily than nearly singular system. \n\n\\item For some components in $\\frac{\\partial f^J_i}{\\partial \\theta^k_{st}} \\approx 0$, we may just take those as 0.\n\n\\item For classification problems, if the class is not big, like $c = 10$, and we may have $100000$ data, and mini-batch size is $100$, which means for every mini-batch, we have $10$ samples in every class. One way for good \"mini-batch\" is to choose those $10$ samples in the same class as separable as possible. {\\bf And in some degree, SGD is doing this. }\n\nIf the class is too big, like $c = 1000$ but mini-bath size is still $100$, we can change our mind to choose those mini-batch just comes from one class and also as separable as possible. \n\nHere is a suggested strategy for how to choose those mini-batch  as separable as possible from Prof. Xu. For example, we have $N$ data for one class, and we want to choose $m$ data from this data set  as separable as possible. We may use next steps:\n\\begin{itemize}\n\\item Use KNN method for those data with $k = m$.\n\\item Use the uniform sampling strategy to choose one data in every cluster, then we get $m$ samples.\n\\end{itemize}\n\n\\end{enumerate}\n\n\n\\subsection{Train good smoother for multigrid methods}\nWe are going to using the idea of deconvolution to get some good smoother in multigrid method with fixing the restriction and interpolation method. \n\nData $\\{u_k, f_k\\}_{k=1}^N$ such that \n\\begin{equation}\nA u_k = f_k,\n\\end{equation}\nwith $A$ is the linear FEM matrix with uniform grids. \n\nThen we have stander nested multi-grids like $\\{\\mathcal{G}_j \\}_{j=1}^J$, and $P_{j}^{j+1}$ is the interpolation operator form $\\mathcal{G}_j$ to $\\mathcal{G}_{j+1}$. We may have $S_j$ as the smoother in grid $\\mathcal{G}$, there are also what we will trained. Under those set up, we may note $B(S_j)$ as the multigrid solve for $B \\approx A^{-1}$.\n\nSo we optimization problem is:\n\\begin{equation}\n\\min_{S_j} \\sum_{k=1}^N\\| u_k - B(S_j)f_k\\|^2.\n\\end{equation}\n\nThere are two points we need to take care of:\n\\begin{itemize}\n\\item How to choose those data $\\{u_k, f_k\\}_{k=1}^N$?\n\nFor this problem, Prof. Xu, suggested that we need to choose good data by choosing fine $f_k$ not $u_k$. \n\n\\item How to solve those above optimization problem?\n\nOne way to train this model is to compute \n\\begin{equation}\n\\sum_{k=1}^N\\| u_k - B(S_j)f_k\\|^2 = \\sum_{k=1}^N \\| (I - B(S_j)A)u_k\\|^2.\n\\end{equation}\nAnd then, we may use ``BP\" for $I - B(S_j)A$ for $S_j$ from $j = J: -1 :1$? But, how to implement this, we may need to check more details. \n\\end{itemize}\n\n\\subsubsection{Another viewpoint for this problem}\nWe can use the idea for best convergence rate with \n\\begin{equation}\n\\min_{S_j} \\|I - B(S_j)A\\|^2,\n\\end{equation}\nthen the above question is the next $min-max$ problem:\n\\begin{equation}\n\\min_{S_j} \\max_{\\|u\\| = 1}\\|(I - B(S_j)A)u\\|^2.\n\\end{equation}\nAnd then we may take this method as:\n\\begin{equation}\n \\sum_{k=1}^N \\| (I - B(S_j)A)u_k\\|^2 \\approx \\max_{\\|u\\| = 1}\\|(I - B(S_j)A)u\\|^2.\n\\end{equation}\n\n\n\n\n\n\\subsection{Seminar notes on 11/31/2017}\n\\begin{itemize}\n\\item Runge phenomenon and overfitting. \n\\item How about sample points and interpolation and Runge phenomenon.\n\\end{itemize}\n\n\\subsection{Discussion on 12/13/2017}\n\\subsubsection{Statistical learning based regression(classification)\n  problems}\n\nHere we suppose that for all image with label and task we want to solve, we have the next joint distribution in real world as:\n\\begin{equation}\\label{eq:jointdit}\n(X,Y) \\sim p_{\\rm data},\n\\end{equation}\nas \n\\begin{equation}\\label{eq:defPr}\n\\rm{Pr}(X \\in I_x, Y \\in I_y) = \\int_{I_x \\times I_y}p_{\\rm data}(x,y)dxdy,\n\\end{equation}\nwith $X \\in \\mathbb{R}^{n\\times n}$ and $Y \\in \\mathbb{R}^c$.\n\nSo for regression problem, the function that we want to interpolate is:\n\\begin{equation}\\label{eq:deff}\nf^*(x) = \\mathbb{E}_Y (Y | X = x).\n\\end{equation}\nThis is in fact that \n\\begin{equation}\\label{eq:f*}\nf^* = \\mathop{\\arg\\min}_{f ~\\text{is a distribution}}\\mathbb{E}_{X\\times Y} \\|y - f(x)\\|^2.\n\\end{equation}\n\nFor classification problem, the values of $Y$ should be some discrete values such as $\\{e_1, \\cdots, e_c\\}$. So the reals problem that we may try to solve is to use some function family to approximate the $f^*$ by:\n\\begin{equation}\\label{eq:stat_opt}\n\\mathbb{E}_{X} (\\|f^*(x) - f(x;\\Theta)\\|^2) = \\mathbb{E}_{X\\times Y}(\\|y - f(x;\\Theta)\\|^2).\n\\end{equation}\n\n\\hrule\n\\paragraph{Jinchao:}  In general, we assume that the label $y$  of a given\ndata $x$ is also a random variable depending on $x$.  For example, for\n$c$-classification problem, \n$$\n\\sum_{k=1}^cP\\{Y=e_k | X=x\\}=1.\n$$\n\n$$\nY: \\{e_1,\\ldots e_k\\}\\mapsto \\mathbb R^c.\n$$\n\nThere are at least five different concepts:\n\\begin{enumerate}\n\\item The original expected loss\n\\item The empirical loss with $N$-sampled data\n\\item SGD directly from the original data [training]\n\\item SGD from the $N$-sampled data [training]\n\\item SGD with epoch from $N$-sampled data [training]\n\\end{enumerate}\n\nJinchao's questions:\n\\begin{enumerate}\n\\item From pure math point of view, generalization error is a concept\n  for model, not for training algorithms\n\\item In the literature, people often relate the generalization error\n  with a training algorithm.   This would only make sense if we treat\n  a training algorithm as a modeling procedure. \n\\item In other words, the training algorithm, when finished in\n  practice, has not really solved the original model problem\n  accurately, namely a global minimizer or a ``good local minimizer''\n\\end{enumerate}\n\nTraditionally, generalization error = test error. \n\nFor expected loss, the concept of ``training data'' and ``test data''\nshould not apply. \n\n``test data'' are those data from the original data space (for\nexpected loss) that are not in the ``training data''\n\nIn practice, we should never aim to accurately find a global minimizer\nof the empirical loss function, which is why we need ``validation\ndata''.  The role of the validation data \n\n\n\\begin{quote}\n{\\bf Jinchao's conjecture:}  Under reasonable assumptions, the exact\nglobal minimizer of the empirical loss function would for sure lead to\nover-fitting. \n\\end{quote}\n\nIn this case, we can find a DNN so that the emirical lost function is\nzero. \n\nWe also note that a global minimizer of the expected loss function is\nalso a global minimizer of the empirical loss function.  But in\npractice, it is hard to find a global minimizer of the expected loss\nfunction.  The practical approximation of the global minimizer would\nlead to over-fitting. \n\nThe above conclusions are not valid for cross-entry with soft-max.\n\nThere are many kinds of data\n\\begin{enumerate}\n\\item All feasible data:\n\\item training data\n\\item validation data\n\\item test data\n\\end{enumerate}\n\nThe labelled data can be divided to, subjectively or statistically,\ninto \n\\begin{enumerate}\n\\item training data\n\\item validation data\n\\item test data\n\\end{enumerate}\n\\bigskip \n\\hrule\n\\bigskip \n\n\\subsubsection{Manifold distance}\nFor classification problem, we may state that \n\\begin{equation}\\label{def:manifoldAk}\nA_k = \\{x: f(x) = e_k\\},\\quad 1 \\le k \\le c,\n\\end{equation}\nwith $f$ is defined above \\eqref{eq:deff}. Then the manifold distance means that\n\\begin{equation}\\label{key}\n\\rm{dist}(A_k, A_l) \\ge \\delta > 0, \\quad k \\neq l.\n\\end{equation}\n", "meta": {"hexsha": "ae6d2ee86c3fb1dcac751a1a38747f8f19110cbc", "size": 21404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/juncai.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/juncai.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/juncai.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": 38.28980322, "max_line_length": 369, "alphanum_fraction": 0.6830498972, "num_tokens": 7474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.657034818007395}}
{"text": "\\section{Substitution Rule}\\label{sec:SubRule}\r\n\r\n\r\n\r\nAntiderivatives play a key role in the the process of evaluating definite integrals exactly.  In particular, the Fundamental Theorem of Calculus tells us that if $F$ is any antiderivative of $f$, then\r\n$$\\int_a^b f(x) \\, dx = F(b) - F(a).$$\r\nFurthermore, we realized that each elementary derivative rule leads to a corresponding elementary antiderivative (or indefinite integral), as summarized in Table~\\ref{T:4.4.Act2}.  Thus, if we wish to evaluate an integral such as \r\n$$\\int_0^1 \\left(x^3 - \\sqrt{x} + 5^x \\right) \\,dx,$$\r\nit is straightforward to do so, since we can easily integrate $f(x) = x^3 - \\sqrt{x} + 5^x.$ In particular, since a function $F$ whose derivative is $f$ is given by $F(x) = \\frac{1}{4}x^4 - \\frac{2}{3}x^{3/2} + \\frac{1}{\\ln(5)}5^x$, the Fundamental Theorem of Calculus tells us that\r\n\\begin{eqnarray*}\r\n\\int_0^1 \\left(x^3 - \\sqrt{x} + 5^x\\right) \\,dx & = & \\left. \\frac{1}{4}x^4 - \\frac{2}{3}x^{3/2} + \\frac{1}{\\ln(5)}5^x\\right|_0^1 \\\\\r\n\t\t\t\t\t\t\t\t& = & \\left( \\frac{1}{4}(1)^4 - \\frac{2}{3}(1)^{3/2} + \\frac{1}{\\ln(5)}5^1 \\right) - \\left( \\frac{1}{4}(0)^4 - \\frac{2}{3}(0)^{3/2} + \\frac{1}{\\ln(5)}5^0 \\right) \\\\\r\n\t\t\t\t\t\t\t\t& = & \\frac{1}{4} - \\frac{2}{3} + \\frac{5}{\\ln(5)} - \\frac{1}{\\ln(5)} \\\\\r\n\t\t\t\t\t\t\t\t& = & -\\frac{5}{12} + \\frac{4}{\\ln(5)}.\r\n\\end{eqnarray*}\r\nBecause an algebraic formula for an antiderivative of $f$ enables us to evaluate the definite integral $\\int_a^b f(x) \\, dx$ exactly, we see that we have a natural interest in being able to find such algebraic antiderivatives.  Note that we emphasize \\emph{algebraic} antiderivatives, as opposed to any antiderivative, since we know by the Second Fundamental Theorem of Calculus that $G(x) = \\int_a^x f(t) \\, dt$ is indeed an antiderivative of the given function $f$, but one that still involves a definite integral.  One of our main goals in this section is to develop understanding, in select circumstances, of how to ``undo'' the process of differentiation in order to find an algebraic antiderivative for a given function.\r\n\r\n\r\n\\subsection*{Reversing the Chain Rule: Substitution} \r\n\r\nIt is usually straightforward to integrate a function of the form\r\n$$h(x) = f(u(x)),$$\r\nwhenever $f$ is a familiar function whose antiderivative is known and $u(x)$ is a linear function.  For example, if we consider\r\n$$h(x) = (5x-3)^6,$$\r\nin this context the \\textit{outer function} $f$ is $f(u) = u^6$, while the \\textit{inner function} is $u(x) = 5x - 3$.  Since the antiderivative of $f$ is $F(u) = \\frac{1}{7}u^7+C$, we \r\nsee that the antiderivative of $h$ is\r\n$$H(x) = \\frac{1}{7} (5x-3)^7 \\cdot \\frac{1}{5} + C = \\frac{1}{35} (5x-3)^7 + C.$$\r\nThe inclusion of the constant $\\frac{1}{5}$ is essential precisely because the derivative of the inner function is $u'(x) = 5$.  Indeed, if we now compute $H'(x)$, we find by the Chain Rule (and Constant Multiple Rule) that\r\n$$H'(x) = \\frac{1}{35} \\cdot 7(5x-3)^6 \\cdot 5 = (5x-3)^6 = h(x),$$\r\nand thus $H$ is indeed the general antiderivative of $h$.\r\n\r\nHence, in the special case where the outer function is familiar and the inner function is linear, we can antidifferentiate composite functions according to the following rule.\r\n\r\n\r\n\\begin{formulabox}[]{\r\nIf $h(x) = f(ax + b)$ and $F$ is a known algebraic antiderivative of $f$, then the general antiderivative of $h$ is given by\r\n$$H(x) = \\frac{1}{a} F(ax+b) + C.$$\r\n}\r\n\\end{formulabox}\r\n\r\nOf course, a natural question  arises: what happens when the inner function is not a linear function?  For example, can we find antiderivatives of such functions as \r\n$$g(x) = x e^{x^2} \\ \\mbox{and} \\ h(x) = e^{x^2}?$$\r\n\r\nIt is important to explicitly remember that differentiation and antidifferentiation are essentially inverse processes; that they are not quite inverse processes is due to the $+C$ that arises when antidifferentiating.  This close relationship enables us to take any known derivative rule and translate it to a corresponding rule for an indefinite integral.  For example, since\r\n$$\\frac{d}{dx} \\left[x^5\\right] = 5x^4,$$\r\nwe can equivalently write\r\n$$\\int 5x^4 \\, dx = x^5 + C.$$\r\n\r\nRecall that the Chain Rule states that\r\n$$\\frac{d}{dx} \\left[ f(g(x)) \\right] = f'(g(x)) \\cdot g'(x).$$\r\nRestating this relationship in terms of an indefinite integral,\r\n\\begin{equation} \\label{E:usubst}\r\n\\int f'(g(x)) g'(x) \\, dx = f(g(x))+C.\r\n\\end{equation}\r\nHence, Equation~(\\ref{E:usubst}) tells us that if we can take a given function and view its algebraic structure as $f'(g(x)) g'(x)$ for some appropriate choices of $f$ and $g$, then we can antidifferentiate the function by reversing the Chain Rule.  It is especially notable that both $g(x)$ and $g'(x)$ appear in the form of $f'(g(x)) g'(x)$; we will sometimes say that we seek to \\emph{identify a function-derivative pair}\\index{function-derivative pair} when trying to apply the rule in Equation~(\\ref{E:usubst}).\r\n\r\nFor example: Find\r\n$$\\int 2x\\cos(x^2)\\,dx.$$\r\nThis is not a ``simple'' derivative, but a little thought reveals that\r\nit must have come from an application of the chain rule. Multiplied\r\non the ``outside'' is $2x$, which is the derivative of the ``inside''\r\nfunction $\\ds x^2$. Checking:\r\n$${d\\over dx}\\sin(x^2)  = \\cos(x^2){d\\over dx}x^2 = 2x\\cos(x^2),$$\r\nso \r\n$$\\int 2x\\cos(x^2)\\,dx=\\sin(x^2)+C .$$\r\n\r\nIn the situation where we can identify a function-derivative pair, we will introduce a new variable $u$ to represent the function $g(x)$.  Observing that with $u = g(x)$, it follows in Leibniz notation that $\\frac{du}{dx} = g'(x)$, so that in terms of differentials\\footnote{If we recall from the definition of the derivative that $\\frac{du}{dx} \\approx \\frac{\\triangle{u}}{\\triangle{x}}$ and use the fact that $\\frac{du}{dx} = g'(x)$, then we see that $g'(x) \\approx \\frac{\\triangle{u}}{\\triangle{x}}$.  Solving for $\\triangle u$, $\\triangle u \\approx g'(x) \\triangle x$.  It is this last relationship that, when expressed in ``differential'' notation enables us to write $du = g'(x) \\, dx$ in the change of variable formula.}, $du = g'(x)\\, dx$.  Now converting the indefinite integral of interest to a new one in terms of $u$, we have  \r\n$$\\int f'(g(x)) g'(x) \\, dx = \\int f'(u) \\,du.$$\r\nProvided that $f'$ is an elementary function whose antiderivative is known, we can now easily evaluate the indefinite integral in $u$, and then go on to determine the desired overall antiderivative of $f'(g(x)) g'(x)$.  We call this process \\emph{$u$-substitution}. \r\n\r\nTo summarize: If we suspect that a given function is the derivative of\r\nanother via the chain rule, we let $u$ denote a likely candidate for\r\nthe inner function, then translate the given function so that it is\r\nwritten entirely in terms of $u$, with no $x$ remaining in the\r\nexpression. If we can integrate this new function of $u$, then the\r\nantiderivative of the original function is obtained by replacing $u$\r\nby the equivalent expression in $x$.\r\n\r\n\\begin{theorem}{$ u $-Substitution Rule for Indefinite Integrals}{SubstitutionRule}\r\nIf $u=g(x)$ is a differentiable function whose range is an interval $I$ and $f$ is continuous on $I$, then\r\n$$\\int f(g(x))g'(x)\\,dx=\\int f(u)\\,du.$$\r\n\\end{theorem}\r\n\r\nEven in simple cases you may prefer to use this mechanical procedure,\r\nsince it often helps to avoid silly mistakes. For example, consider\r\nagain this simple problem:\r\n$$\\int 2x\\cos(x^2)\\,dx.$$\r\nLet $\\ds u=x^2$, then $du/dx = 2x$ or $du = 2x\\,dx$. Since we have exactly \r\n$2x\\,dx$ in the original integral, we can replace it by $du$:\r\n$$\\int 2x\\cos(x^2)\\,dx=\\int \\cos u\\,du=\\sin u +C = \\sin(x^2)+C.$$\r\nThis is not the only way to do the algebra, and typically there are\r\nmany paths to the correct answer. Another possibility, for example,\r\nis: Since $du/dx = 2x$, $dx=du/2x$, and then the integral becomes\r\n$$\\int 2x\\cos(x^2)\\,dx=\\int 2x\\cos u\\,{du\\over 2x}=\\int \\cos u\\,du.$$\r\nThe important thing to remember is that you must eliminate all\r\ninstances of the original variable $x$.\r\n\r\n\\begin{example}{Substitution Rule}{usub}\\label{usub}\r\nEvaluate the indefinite integral\r\n$$\\int x^3 \\cdot \\sin (7x^4 + 3) \\, dx$$\r\nand check the result by differentiating.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe can make two key algebraic observations stand regarding the integrand, $x^3 \\cdot \\sin (7x^4 + 3)$.  First, $\\sin (7x^4 + 3)$ is a composite function; as such, we know we'll need a more sophisticated approach to antidifferentiating.  Second, $x^3$ is almost the derivative of $(7x^4 + 3)$; the only issue is a missing constant.  Thus, $x^3$ and $(7x^4 + 3)$ are nearly a function-derivative pair.  Furthermore, we know the antiderivative of $f(u) = \\sin(u)$.  The combination of these observations suggests that we can evaluate the given indefinite integral by reversing the chain rule through $u$-substitution.\r\n\r\nLetting $u$ represent the inner function of the composite function $\\sin (7x^4 + 3)$, we have\r\n$$u = 7x^4 + 3,$$\r\nand thus $\\frac{du}{dx} = 28x^3.$  In differential notation, it follows that $du = 28x^3 \\, dx$, and thus $x^3 \\, dx = \\frac{1}{28} \\, du$.  We make this last observation because the original indefinite integral may now be written \r\n$$\\int \\sin (7x^4 + 3) \\cdot x^3 \\, dx,$$\r\nand so by substituting the expressions in $u$ for $x$ (specifically $u$ for $7x^4 + 3$ and $\\frac{1}{28} \\, du$ for $x^3 \\, dx$), it follows that\r\n$$\\int \\sin (7x^4 + 3) \\cdot x^3 \\, dx = \\int \\sin(u) \\cdot \\frac{1}{28} \\, du.$$\r\nNow we may evaluate the original integral by first evaluating the easier integral in $u$, followed by replacing $u$ by the expression $7x^4 + 3$.  Doing so, we find\r\n\\begin{eqnarray*}\r\n\\int \\sin (7x^4 + 3) \\cdot x^3 \\, dx & = & \\int \\sin(u) \\cdot \\frac{1}{28} \\, du \\\\\r\n\t\t\t\t\t\t& = & \\frac{1}{28} \\int \\sin(u) \\, du \\\\\r\n\t\t\t\t\t\t& = & \\frac{1}{28} (-\\cos(u)) + C \\\\\r\n\t\t\t\t\t\t& = & -\\frac{1}{28} \\cos(7x^4 + 3) + C.\r\n\\end{eqnarray*}\r\nTo check our work, we observe by the Chain Rule that\r\n$$\\frac{d}{dx} \\left[ -\\frac{1}{28}\\cos(7x^4 + 3) + C \\right] = -\\frac{1}{28} \\cdot (-1)\\sin(7x^4 + 3) \\cdot 28x^3 = \\sin(7x^4 + 3) \\cdot x^3,$$\r\nwhich is indeed the original integrand.\r\n\\end{solution}\r\n\r\nAn essential observation about our work in Example~\\ref{usub}  is that the $u$-substitution only worked because the function multiplying $\\sin (7x^4 + 3)$ was $x^3$.  If instead that function was $x^2$ or $x^4$, the substitution process may not (and likely would not) have worked.  This is one of the primary challenges of antidifferentiation: slight changes in the integrand make tremendous differences.  For instance, we can use $u$-substitution with $u = x^2$ and $du = 2xdx$ to find that\r\n\\begin{eqnarray*}\r\n\\int xe^{x^2} \\, dx & = & \\int e^u \\cdot \\frac{1}{2} \\, du \\\\\r\n\t\t\t& = & \\frac{1}{2} \\int e^u \\, du \\\\\r\n\t\t\t& = & \\frac{1}{2} e^u + C \\\\\r\n\t\t\t& = & \\frac{1}{2} e^{x^2} + C.\r\n\\end{eqnarray*}\r\nIf, however, we consider the similar indefinite integral\r\n$$\\int e^{x^2} \\, dx,$$\r\nthe missing $x$ to multiply $e^{x^2}$ makes the $u$-substitution $u = x^2$ no longer possible.  Hence, part of the lesson of $u$-substitution is just how specialized the process is: it only applies to situations where, up to a missing constant, the integrand that is present is the result of applying the Chain Rule to a different, related function.\r\n\r\n\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRuleex}\r\nEvaluate $\\ds\\int(ax+b)^n\\,dx$, assuming $a,b$ are\r\nconstants, $a\\not=0$, and $n$ is a positive integer.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe let $u=ax+b$ so $du=a\\,dx$ or $dx=du/a$. Then\r\n$$\r\n  \\int(ax+b)^n\\,dx=\\int {1\\over a} u^n\\,du={1\\over a(n+1)}u^{n+1}+C=\r\n  {1\\over a(n+1)}(ax+b)^{n+1}+C.\r\n$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRulex}\r\nEvaluate $\\ds\\int \\sin(ax+b)\\,dx$, assuming that $a$ and $b$ are\r\nconstants and $a\\not=0$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nAgain we let $u=ax+b$ so $du=a\\,dx$ or $dx=du/a$. Then\r\n$$\r\n  \\int\\sin(ax+b)\\,dx=\\int {1\\over a} \\sin u\\,du={1\\over a}(-\\cos u)+C=\r\n-{1\\over a}\\cos(ax+b)+C.\r\n$$\r\n\\end{solution}\r\n\r\n\\begin{formulabox}[Strategy for Substitution Rule]\r\nA general strategy to follow is:\r\n\\begin{enumerate}\\setlength{\\itemsep}{0 in}\r\n\\item Choose a possible $u=u(x)$. \\dfont{Tip:} Choose a substitution $u$ so that its derivate also appears in the integral (up to a constant).\r\n\\item Calculate $du=u'(x)~dx$.\r\n\\item Either replace $u'(x)~dx$ by $du$, or replace $dx$ by $\\ds{\\frac{du}{u'(x)}}$, and cancel.\r\n\\item Write the rest of the integrand in terms of $u$. If this is not possible, the substitution will not work: You must go back to step 1.\r\n\\item Find the indefinite integral. (Again, if this is not possible, try a different substitution, or a different method).\r\n\\item Rewrite the result in terms of $x$.\r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Substitution}{Substitution}\r\nEvaluate the following integral: $\\ds\\int \\frac{2x}{\\sqrt{1-4x^2}}\\,dx.$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe try the substitution:\r\n$$u=1-4x^2.$$\r\nThen,\r\n$$du=-8x~dx$$\r\nIn the numerator we have $2x~dx$, so rewriting the differential gives:\r\n$$-\\frac{1}{4}du=2x~dx.$$\r\nThen the integral is:\r\n\\begin{eqnarray*}\r\n\\int \\frac{2x}{\\sqrt{1-4x^2}}\\,dx&=&\\int \\left(1-4x^2\\right)^{-1/2}(2x~dx)\\\\\r\n\\\\\r\n&=&\\int u^{-1/2}\\left(-\\frac{1}{4}du\\right)\\\\\r\n\\\\\r\n&=&\\left(\\frac{-1}{4}\\right)\\frac{u^{1/2}}{1/2}+C\\\\\r\n\\\\\r\n&=&-\\frac{\\sqrt{1-4x^2}}{2}+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n\r\n\\begin{example}{Substitution}{Substitution}\r\nEvaluate the following integral: $\\ds\\int \\sech^2(7t-3)\\ dt$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n We employ substitution, with $u = 7t-3$ and $du = 7dt$. We have:\r\n$$ \\int \\sech^2 (7t-3)\\ dt=  \\frac17 \\int \\sech^2 (u)\\ du= \\frac17\\tanh (u) + C = \\frac17\\tanh (7t-3) + C.$$\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\\begin{example}{Substitution}{Substitution2}\r\nEvaluate the following integral: $\\ds\\int \\cos x(\\sin x)^5\\,dx.$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nIn this question we will let $u=\\sin x$.\r\nThen,\r\n$$du=\\cos x~dx.$$\r\nThus, the integral becomes:\r\n\\begin{eqnarray*}\r\n\\int \\cos x(\\sin x)^5\\,dx&=&\\int u^5\\,du\\\\\r\n\\\\\r\n&=&\\frac{u^6}{6}+C\\\\\r\n\\\\\r\n&=&\\frac{(\\sin x)^6}{6}+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\\begin{example}{Substitution}{Substitution3}\r\nEvaluate the following integral:\r\n$\\ds\\int \\frac{\\cos(\\sqrt x)}{\\sqrt x}\\,dx.$\r\n%\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe use the substitution:\r\n$$u=x^{1/2}.$$\r\nThen,\r\n$$du=\\frac{1}{2}x^{-1/2}dx.$$\r\nRewriting the differential we get:\r\n$$2~du=\\frac{1}{\\sqrt x}~dx.$$\r\nThe integral becomes:\r\n\\begin{eqnarray*}\r\n\\int \\frac{\\cos(\\sqrt x)}{\\sqrt x}\\,dx&=&2\\int \\cos u\\,du\\\\\r\n\\\\\r\n&=&2\\sin u+C\\\\\r\n\\\\\r\n&=&2\\sin(\\sqrt x)+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n\r\n%\\begin{example}{Substitution with Inverse Trigonometric Functions}{Substitution with Inverse Trigonometric Functions}\r\n%From items \\ref{invsin} and \\ref{invtan} in  Theorem \\ref{thm:indef_alg} and the method of substitution with $ u=\\frac{x}{a} $ where $ a>0 $ (try it!), we get the following:\r\n%\\[\r\n%\\int \\frac{1}{x^2+a^2}=\\frac1a\\arctan\\left(\\frac{x}{a}\\right)+C \\text{ and } \\int \\frac{1}{\\sqrt{a^2-x^2}}\\; dx = \\arcsin\\left(\\frac{x}{a}\\right)+C\r\n%\\] \r\n\r\n%\\end{example}\r\n\r\n\\begin{example}{Integrating by substitution}{ex_sub10}\r\n{\r\nEvaluate $\\ds \\int \\sin x\\cos x\\ dx$.\r\n}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{There is not a composition of function here to exploit; rather, just a product of functions. Do not be afraid to experiment; when given an integral to evaluate, it is often beneficial to think ``If I let $u$ be \\textit{this}, then $du$ must be \\textit{that} \\ldots'' and see if this helps simplify the integral at all.\r\n\r\nIn this example, let's set $u = \\sin x$. Then $du = \\cos x\\ dx$, which we have as part of the integrand! The substitution becomes very straightforward:\r\n\t\t\\begin{align*}\r\n\t\t\\int \\sin x\\cos x\\ dx &=\t\\int u\\ du \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac12u^2+ C \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac12\\sin^2 x + C.\r\n\t\t\\end{align*}\r\nOne would do well to ask ``What would happen if we let $u = \\cos x$?'' The result is just as easy to find, yet looks very different. The challenge to the reader is to evaluate the integral letting $u = \\cos x$ and discover why the answer is the same, yet looks different.\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\nOur examples so far have required ``basic substitution.'' The next example demonstrates how substitutions can be made that often strike the new learner as being ``nonstandard.''\\\\\r\n\r\n%\\enlargethispage{\\baselineskip}\r\n\r\n\r\n\\begin{example}{Substitution}{Substitution4}\r\nEvaluate the following integral:\r\n$\\ds\\int 2x^3\\sqrt{x^2+1}\\,dx.$\r\n%\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThis problem is a little bit different than the previous ones.\r\nIt makes sense to let:\r\n$$u=x^2+1,$$\r\nthen\r\n$$du=2x~dx.$$\r\nMaking this substitution gives:\r\n\\begin{eqnarray*}\r\n\\int 2x^3\\sqrt{x^2+1}\\,dx&=&\\int x^2\\sqrt{x^2+1}(2x)\\,dx\\\\\r\n\\\\\r\n&=&\\int x^2u^{1/2}\\,du\\\\\r\n\\end{eqnarray*}\r\nThis is a problem because our integrals can't have a mixture of two variables in them.\r\nUsually this means we chose our $u$ incorrectly.\r\nHowever, in this case we can eliminate the remaining $x$'s from our integral by using:\r\n$$u=x^2+1\\quad\\to\\quad x^2=u-1.$$\r\nWe get:\r\n\\begin{eqnarray*}\r\n\\int x^2u^{1/2}\\,du&=&\\int (u-1)u^{1/2}\\,du\\\\\r\n\\\\\r\n&=&\\int u^{3/2}-u^{1/2}\\,du\\\\\r\n\\\\\r\n&=&\\frac{2}{5}u^{5/2}-\\frac{2}{3}u^{3/2}+C\\\\\r\n\\\\\r\n&=&\\frac{2}{5}(x^2+1)^{5/2}-\\frac{2}{3}(x^2+1)^{3/2}+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Integrating by substitution}{ex_sub4}\r\nEvaluate $\\ds\\int x\\sqrt{x+3}\\ dx$.\r\n\\end{example}\r\n\\begin{solution}\r\n{Recognizing the composition of functions, set $u = x+3$. Then $du = dx$, giving what seems initially to be a simple substitution. But at this stage, we have:\r\n\t$$\\int x\\sqrt{x+3}\\ dx = \\int x\\sqrt{u}\\ du.$$\r\nWe cannot evaluate an integral that has both an $x$ and an $u$ in it. We need to convert the $x$ to an expression involving just $u$.\r\n\r\nSince we set $u = x+3$, we can also state that $u-3 = x$. Thus we can replace $x$ in the integrand with $u-3$. It will also be helpful to rewrite $\\sqrt{u}$ as $u^\\frac12$.\r\n\\begin{align*}\r\n\t\t\\int x\\sqrt{x+3} \\ dx &= \\int (u-3)u^\\frac12\\ du \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\int \\big(u^\\frac32 - 3u^\\frac12\\big) \\ du \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac25u^\\frac52 - 2u^\\frac32 + C \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac25(x+3)^\\frac52 - 2(x+3)^\\frac32 + C.\r\n\\end{align*}\r\nChecking your work is always a good idea. In this particular case, some algebra will be needed to make one's answer match the integrand in the original problem.\r\n}\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Integrating by substitution}{ex_sub5}\r\nEvaluate $\\ds \\int \\frac{1}{x\\ln x}\\ dx$.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{This is another example where there does not seem to be an obvious composition of functions. The line of thinking used in Example \\ref{exa:ex_sub4} is useful here: choose something for $u$ and consider what this implies $du$ must be. If $u$ can be chosen such that $du$ also appears in the integrand, then we have chosen well.\r\n\r\nChoosing $u = 1/x$ makes $du = -1/x^2\\ dx$; that does not seem helpful. However, setting $u = \\ln x$ makes $du = 1/x\\ dx$, which is part of the integrand. Thus:\r\n\\begin{align*}\r\n\t\\int \\frac1{x\\ln x}\\ dx \t&=\t\\int \\frac{1}{\\underbrace{\\ln x}_{1/u}}\\underbrace{\\frac1x\\ dx}_{du} \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t&= \\int \\frac1u\\ du \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t&= \\ln |u| + C \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t&= \\ln | \\ln x| + C.\r\n\\end{align*}\r\nThe final answer is interesting; the natural log of the natural log. Take the derivative to confirm this answer is indeed correct.\r\n}\r\n\\end{solution}\r\n\r\n\\subsection{Integrals Involving Trigonometric Functions}\r\n\r\nSection \\ref{sec:Powers of trigonometric functions} delves deeper into integrals of a variety of trigonometric functions; here we use substitution to establish a foundation that we will build upon. \r\n\r\nThe next three examples will help fill in some missing pieces of our antiderivative knowledge. We know the antiderivatives of the sine and cosine functions; what about the other standard functions tangent, cotangent, secant and cosecant? We discover these next.\\\\\r\n\r\n\\begin{example}{Integration by substitution: antiderivatives of $\\tan x$}{ex_sub6}\r\nEvaluate $\\ds \\int \\tan x\\ dx.$\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{The previous paragraph established that we did not know the antiderivatives of tangent, hence we must assume that we have learned something in this section that  can help us evaluate this indefinite integral. \r\n\r\n%\\enlargethispage{\\baselineskip}\r\nRewrite $\\tan x$ as $\\sin x/\\cos x$. While the presence of a composition of functions may not be immediately obvious, recognize that $\\cos x$ is ``inside'' the $1/x$ function. Therefore, we see if setting $u = \\cos x$ returns usable results. We have that $du = -\\sin x\\ dx$, hence $-du = \\sin x\\ dx$. We can integrate:\r\n\\begin{align*}\r\n\t\t\\int \\tan x \\ dx &= \\int \\frac{\\sin x}{\\cos x}\\ dx \\\\\r\n\t\t\t\t\t\t\t&= \\int \\frac1{\\underbrace{\\cos x}_u}\\underbrace{\\sin x\\ dx}_{-du} \\\\\r\n\t\t\t\t\t\t\t&= \\int \\frac {-1}u \\ du\\\\\r\n\t\t\t\t\t\t\t&= -\\ln |u| + C \\\\\r\n\t\t\t\t\t\t\t&= -\\ln |\\cos x| + C.\r\n\\end{align*}\r\nSome texts prefer to bring the $-1$ inside the logarithm as a power of $\\cos x$, as in:\r\n\\begin{align*}\r\n-\\ln |\\cos x| + C &= \\ln |(\\cos x)^{-1}| + C\\\\\r\n\t\t\t&= \\ln \\left| \\frac{1}{\\cos x}\\right| + C\\\\\r\n\t\t\t&= \\ln |\\sec x| + C.\r\n\\end{align*}\r\nThus the result they give is $\\int \\tan x \\ dx = \\ln|\\sec x| + C$. These two answers are equivalent.\r\n}\\\\\r\n\r\n\\end{solution}\r\n\r\n\\begin{example}{Integrating by substitution: antiderivatives of $\\sec x$}{ex_sub7}\r\nEvaluate $\\ds\\int \\sec x\\ dx$.\r\n\\end{example}\r\n\r\n%\\enlargethispage{2\\baselineskip}\r\n\r\n\\begin{solution}\r\n{This example employs a wonderful trick: multiply the integrand by ``1'' so that we see how to integrate more clearly. In this case, we write ``1'' as\r\n$$1 = \\frac{\\sec x + \\tan x}{\\sec x + \\tan x}.$$\r\nThis may seem like it came out of left field, but it works beautifully. Consider:\r\n\\begin{align*}\r\n\t\t\t\\int \\sec x\\ dx\t&=\t\\int \\sec x\\cdot \\frac{\\sec x + \\tan x}{\\sec x + \\tan x}\\ dx \\\\\r\n\t\t\t\t\t\t\t&= \\int \\frac{\\sec^2 x + \\sec x\\tan x}{\\sec x + \\tan x}\\ dx.\\\\\r\n\\intertext{Now let $u = \\sec x+\\tan x$; this means $du = (\\sec x\\tan x+ \\sec^2 x)\\ dx$, which is our numerator. Thus:}\r\n\t\t\t\t\t\t&= \\int \\frac{du}{u} \\\\\r\n\t\t\t\t\t\t&= \\ln |u| + C \\\\\r\n\t\t\t\t\t\t&= \\ln |\\sec x+\\tan x| + C.\r\n\\end{align*}\r\n\\vskip -\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n%\\clearpage\r\n\r\n\r\nWe can use similar techniques to those used in Examples \\ref{ex_sub6} and \\ref{ex_sub7} to find antiderivatives of $\\cot x$ and $\\csc x$ (which the reader can explore in the exercises.) We summarize our results here.\r\n\r\n\\begin{theorem}{Antiderivatives of Trigonometric Functions}{triganti}\r\n{\\begin{minipage}{.45\\textwidth}\\small\\index{integration!of trig. functions}\r\n\t\\begin{enumerate}\r\n\t\\item\t\t$\\ds \\int \\sin x \\ dx = -\\cos x +C$\r\n\t\\item\t\t$\\ds\\int \\cos x\\ dx = \\sin x + C$\r\n\t\\item\t\t$\\ds \\int \\tan x\\ dx = -\\ln|\\cos x|+C$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\begin{minipage}{.55\\textwidth}\\small\r\n\t\\begin{enumerate}\\addtocounter{enumi}{3}\r\n\t\\item\t\t$\\ds \\int \\csc x \\ dx = -\\ln|\\csc x+\\cot x| +C$\r\n\t\\item\t\t$\\ds\\int \\sec x\\ dx = \\ln|\\sec x+\\tan x| + C$\r\n\t\\item\t\t$\\ds \\int \\cot x\\ dx = \\ln|\\sin x|+C$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\\end{theorem}\r\n\r\n\r\n\r\nWe explore one more common trigonometric integral.\\\\\r\n\r\n\\begin{example}{Integration by substitution: powers of $\\cos x$ and $\\sin x$}{ex_sub8}\r\n{\r\nEvaluate $\\ds \\int \\cos^2x\\ dx$.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{We have a composition of functions as $\\cos^2x = \\big(\\cos x\\big)^2$. \r\n%with $\\cos x$ inside the $x^2$ function. \r\nHowever, setting $u = \\cos x$ means $du = -\\sin x\\ dx$, which we do not have in the integral. Another technique is needed.\r\n\r\nThe process we'll employ is to use a Power Reducing formula for $\\cos^2x$ (perhaps consult the back of this text for this formula), which states \r\n\t$$\\cos ^2x = \\frac{1+\\cos(2x)}{2}.$$\r\n\tThe right hand side of this equation is not difficult to integrate. We have:\r\n\\begin{align*}\r\n\t\\int \\cos^2x\\ dx &= \\int \\frac{1+\\cos(2x)}2\\ dx \\\\\r\n\t\t\t\t\t\t\t\t\t&=\t\\int \\left( \\frac12 + \\frac12\\cos(2x)\\right)\\ dx. \\\\\r\n\\intertext{Now use Key Idea \\ref{idea:linearsub}:}\r\n\t\t\t\t\t\t\t\t\t&= \\frac12x + \\frac12\\frac{\\sin(2x)}{2} + C \\rule[-10pt]{0pt}{5pt}\\\\\r\n\t\t\t\t\t\t\t\t\t&= \\frac12x + \\frac{\\sin(2x)}4 + C.\r\n\\end{align*}\r\nWe'll make significant use of this power--reducing technique in future sections.\r\n}\\\\\r\n\\end{solution}\r\n\r\n\r\n\r\n\\subsection{ Simplifying the Integrand}\r\n\r\nIt is common to be reluctant to manipulate the integrand of an integral; at first, our grasp of integration is tenuous and one may think that working with the integrand will improperly change the results. Integration by substitution works using a different logic: as long as \\textit{equality} is maintained, the integrand can be manipulated so that its \\textit{form} is easier to deal with. The next two examples demonstrate common ways in which using algebra first makes the integration easier to perform.\\\\\r\n\r\n%\\enlargethispage{2\\baselineskip}\r\n\r\n\\begin{example}{Integration by substitution: simplifying first}{ex_sub9}\r\n{\r\nEvaluate $\\ds\\int \\frac{x^3+4x^2+8x+5}{x^2+2x+1}\\ dx$.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{One may try to start by setting $u$ equal to either the numerator or denominator; in each instance, the result is not workable. \r\n\r\nWhen dealing with rational functions (i.e., quotients made up of polynomial functions), it is an almost universal rule that everything works better when the degree of the numerator is less than the degree of the denominator. Hence we use polynomial division.\r\n\r\nWe skip the specifics of the steps, but note that when $x^2+2x+1$ is divided into $x^3+4x^2+8x+5$, it goes in $x+2$ times with a remainder of $3x+3$. Thus \r\n\t$$\\frac{x^3+4x^2+8x+5}{x^2+2x+1} = x+2 + \\frac{3x+3}{x^2+2x+1}.$$\r\nIntegrating $x+2$ is simple. The fraction can be integrated by setting $u = x^2+2x+1$, giving $du = (2x+2)\\ dx$. This is very similar to the numerator. Note that $du/2 = (x+1)\\ dx$ and then consider the following:\r\n\\begin{align*}\r\n\\int \\frac{x^3+4x^2+8x+5}{x^2+2x+1}\\ dx & = \\int \\left(x+2 + \\frac{3x+3}{x^2+2x+1}\\right)\\ dx  \\rule[-13pt]{0pt}{5pt} \\\\\r\n\t\t\t\t\t&= \\int (x+2)\\ dx + \\int \\frac{3(x+1)}{x^2+2x+1}\\ dx  \\rule[-13pt]{0pt}{5pt}\\\\\r\n\t\t\t\t\t& = \\frac12x^2+2x+C_1 + \\int \\frac{3}{u}\\frac{du}{2}  \\rule[-13pt]{0pt}{5pt}\\\\\r\n\t\t\t\t\t&= \\frac12x^2+2x+C_1 + \\frac32\\ln|u| + C_2 \\rule[-13pt]{0pt}{5pt}\\\\\r\n\t\t\t\t\t&= \\frac12x^2+2x+\\frac32\\ln|x^2+2x+1| + C.\r\n\\end{align*}\r\nIn some ways, we ``lucked out'' in that after dividing, substitution was able to be done. In later sections we'll develop techniques for handling rational functions where substitution is not directly feasible.\r\n}\\\\\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Integration by alternate methods}{ex_sub11}\r\n{\r\nEvaluate $\\ds\\int \\frac{x^2+2x+3}{\\sqrt{x}}\\ dx$ with, and without, substitution.}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{We already know how to integrate this particular example. Rewrite $\\sqrt{x}$ as $x^\\frac12$ and simplify the fraction:\r\n\t$$ \\frac{x^2+2x+3}{x^{1/2}} = x^\\frac32 + 2x^\\frac12 + 3x^{-\\frac12}.$$\r\nWe can now integrate using the Power Rule:\r\n\\begin{align*}\r\n\t\\int \\frac{x^2+2x+3}{x^{1/2}}\\ dx &= \\int\\left(x^\\frac32 + 2x^\\frac12 + 3x^{-\\frac12}\\right)\\ dx\\\\\r\n\t\t\t\t\t\t&=\t\\frac25x^\\frac52 + \\frac43x^\\frac32 + 6x^\\frac12 + C\r\n\\end{align*}\r\nThis is a perfectly fine approach. We demonstrate how this can also be solved using substitution as its implementation is rather clever.\r\n\r\nLet $u = \\sqrt{x} = x^\\frac12$; therefore \r\n\t\t$$du = \\frac12x^{-\\frac12}dx = \\frac{1}{2\\sqrt{x}}\\ dx \\quad \\Rightarrow \\quad 2du = \\frac{1}{\\sqrt{x}}\\ dx.$$\r\n\t\t\r\nThis gives us $\\ds \\int \\frac{x^2+2x+3}{\\sqrt{x}}\\ dx = \\int (x^2+2x+3)\\cdot2\\ du$. What are we to do with the other $x$ terms? Since $u = x^\\frac12$, $u^2 = x$, etc. We can then replace $x^2$ and $x$ with appropriate powers of $u$. We thus have\r\n\\begin{align*}\r\n\\int \\frac{x^2+2x+3}{\\sqrt{x}}\\ dx &= \\int (x^2+2x+3)\\cdot2\\ du\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\int 2(u^4 + 2u^2 + 3)\\ du \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac25u^5 + \\frac43u^3 + 6u + C \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac25x^\\frac52 + \\frac43x^\\frac32 + 6x^\\frac12+C,\r\n\\end{align*}\r\nwhich is obviously the same answer we obtained before. In this situation, substitution is arguably more work than our other method. The fantastic thing is that it works. It demonstrates how flexible integration is.\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\\subsection{Substitution and Inverse Trigonometric Functions}\r\n\r\n%In Section \\ref{sec:deriv_inverse_function} \r\nWhen studying derivatives of inverse functions, we learned that $$\\frac{d}{dx}\\big(\\tan^{-1}x\\big) = \\frac{1}{1+x^2}.$$ Applying the Chain Rule to this is not difficult; for instance, $$\\frac{d}{dx}\\big(\\tan^{-1}5x\\big) = \\frac{5}{1+25x^2}.$$ We now explore how Substitution can be used to ``undo'' certain derivatives that are the result of the Chain Rule applied to Inverse Trigonometric functions. We begin with an example.\\\\\r\n\r\n\\begin{example}{Integrating by substitution: inverse trigonometric functions}{ex_subst14}\r\n{\r\nEvaluate $\\ds \\int \\frac{1}{25+x^2}\\ dx$.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{The integrand looks similar to the derivative of the arctangent function. Note:\r\n\\begin{align*}\r\n\\frac{1}{25+x^2} &= \\frac{1}{25(1+\\frac{x^2}{25})}\\\\\r\n\t\t\t\t\t\t\t&= \\frac{1}{25(1+\\left(\\frac{x}{5}\\right)^2)} \\\\\r\n\t\t\t\t\t\t\t&= \\frac{1}{25}\\frac{1}{1+\\left(\\frac{x}{5}\\right)^2}\\ .\r\n\\end{align*}\r\nThus $$\\int\\frac{1}{25+x^2}\\ dx = \\frac{1}{25}\\int \\frac{1}{1+\\left(\\frac{x}{5}\\right)^2}\\ dx.$$ This can be integrated using Substitution. Set $u = x/5$, hence $du = dx/5$ or $dx=5du$. Thus\r\n\\begin{align*}\r\n\\int\\frac{1}{25+x^2}\\ dx &= \\frac{1}{25}\\int \\frac{1}{1+\\left(\\frac{x}{5}\\right)^2}\\ dx \\\\\r\n\t\t\t\t\t\t\t\t\t\t&= \\frac15\\int \\frac{1}{1+u^2}\\ du \\\\\r\n\t\t\t\t\t\t\t\t\t\t&= \\frac15\\tan^{-1}u + C \\\\\r\n\t\t\t\t\t\t\t\t\t\t&= \\frac15\\tan^{-1}\\left(\\frac x5\\right)+C\r\n\\end{align*}\r\n\\vskip -\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\nExample \\ref{exa:ex_subst14} demonstrates a general technique that can be applied to other integrands that result in inverse trigonometric functions. The results are summarized here.\r\n\r\n\r\n\\begin{theorem}{Integrals Involving Inverse Trigonomentric Functions}{int_inverse_trig}\r\n{Let $a>0$.\r\n%\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\int \\frac{1}{a^2+x^2}\\ dx = \\frac1a\\tan^{-1}\\left(\\frac{x}{a}\\right) + C$\r\n%\\addtocounter{enumi}{1}\r\n\\item\t\t$\\ds \\int \\frac{1}{\\sqrt{a^2-x^2}}\\ dx = \\sin^{-1}\\left(\\frac{x}{a}\\right)+C$\r\n%\\end{enumerate}\r\n%\\end{minipage}\r\n%\\begin{minipage}[t]{.5\\linewidth}\r\n%\\begin{enumerate}\\addtocounter{enumi}{1}\r\n\\item\t\t$\\ds \\int \\frac{1}{x\\sqrt{x^2-a^2}}\\ dx = \\frac1a\\sec^{-1}\\left(\\frac{|x|}{a}\\right)+C$\r\n\\end{enumerate}\r\n%\\end{minipage}\r\n}\r\n\\end{theorem}\r\n\r\n\r\nLet's practice using Theorem \\ref{thm:int_inverse_trig}.\\\\\r\n\r\n\\begin{example}{Integrating by substitution: inverse trigonometric functions}{ex_subst15}\r\n{Evaluate the given indefinite integrals.\r\n$$\\int \\frac{1}{9+x^2}\\ dx,\\quad \\int \\frac{1}{x\\sqrt{x^2-\\frac{1}{100}}}\\ dx\\quad \\text{ and }\\quad  \\int \\frac{1}{\\sqrt{5-x^2}}\\ dx.$$\r\n}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{Each can be answered using a straightforward application of Theorem \\ref{thm:int_inverse_trig}.\\\\\r\n\r\n$\\ds \\int \\frac{1}{9+x^2}\\ dx = \\frac13\\tan^{-1} \\frac x3 + C$, as $a = 3$.\\vskip 10pt\r\n\r\n$\\ds \\int  \\frac{1}{x\\sqrt{x^2-\\frac{1}{100}}}\\ dx = 10\\sec^{-1}10x + C$, as $a = \\frac1{10}$.\\vskip 10pt\r\n\r\n$\\ds \\int \\frac{1}{\\sqrt{5-x^2}} = \\sin^{-1}\\frac{x}{\\sqrt{5}}+C$, as $a = \\sqrt{5}$.\\\\\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\\enlargethispage{2\\baselineskip}\r\nMost applications of Theorem \\ref{thm:int_inverse_trig} are not as straightforward. The next examples show some common integrals that can still be approached with this theorem.\\\\\r\n\r\n\\begin{example}{Integrating by substitution: completing the square}{ex_subst16}\r\n{Evaluate $\\ds \\int\\frac{1}{x^2-4x+13}\\ dx$.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{Initially, this integral seems to have nothing in common with the integrals in Theorem \\ref{thm:int_inverse_trig}. As it lacks a square root, it almost certainly is not related to arcsine or arcsecant. It is, however, related to the arctangent function.\r\n\r\nWe see this by \\textit{completing the square} in the denominator. We give a brief reminder of the process here. \r\n\r\nStart with a quadratic with a leading coefficient of 1. It will have the form of $x^2 + bx + c$. Take 1/2 of $b$, square it, and add/subtract it back into the expression. I.e., \r\n\\begin{align*} \r\nx^2+bx+ c &= \\underbrace{x^2 + bx + \\frac{b^2}4}_{(x+b/2)^2} - \\frac{b^2}4 + c\\\\\r\n   &= \\left(x+\\frac b2\\right)^2 + c-\\frac{b^2}4\r\n\\end{align*}\r\nIn our example, we take half of $-4$ and square it, getting $4$. We add/subtract it into the denominator as follows:\r\n\r\n\\begin{align*}\r\n\\frac{1}{x^2-4x+13} &= \\frac{1}{\\underbrace{x^2-4x+4}_{(x-2)^2}-4+13}\\\\\r\n\t\t\t\t&=\\frac{1}{(x-2)^2 + 9}\r\n\\end{align*}\r\nWe can now integrate this using the arctangent rule. Technically, we need to substitute first with $u=x-2$, but we omit this step here. Thus we have \r\n$$ \\int \\frac{1}{x^2-4x+13}\\ dx = \\int \\frac{1}{(x-2)^2+9}\\ dx = \\frac13\\tan^{-1}\\frac{x-2}{3}+C.$$\r\n\\vskip -\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Integrals requiring multiple methods}{ex_subst17}\r\n{\r\nEvaluate $\\ds \\int \\frac{4-x}{\\sqrt{16-x^2}}\\ dx$.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{This integral requires two different methods to evaluate it. We get to those methods by splitting up the integral: \r\n$$ \\int \\frac{4-x}{\\sqrt{16-x^2}}\\ dx = \\int \\frac{4}{\\sqrt{16-x^2}}\\ dx - \\int \\frac{x}{\\sqrt{16-x^2}}\\ dx.$$\r\nThe first integral is handled using a straightforward application of Theorem \\ref{thm:int_inverse_trig}; the second integral is handled by substitution, with $u = 16-x^2$. We handle each separately.\r\n\r\n$\\ds \\int \\frac{4}{\\sqrt{16-x^2}}\\ dx = 4\\sin^{-1}\\frac{x}{4} + C$.\r\n\\vskip 10pt\r\n\r\n$\\ds \\int\\frac{x}{\\sqrt{16-x^2}}\\ dx$: Set $u = 16-x^2$, so $du = -2xdx$ and $xdx = -du/2$. We have \r\n\\begin{align*}\r\n\\int\\frac{x}{\\sqrt{16-x^2}}\\ dx &= \\int\\frac{-du/2}{\\sqrt{u}}\\\\\r\n\t\t\t\t&= -\\frac12\\int \\frac{1}{\\sqrt{u}}\\ du \\\\\r\n\t\t\t\t&= - \\sqrt{u} + C\\\\\r\n\t\t\t\t&= -\\sqrt{16-x^2} + C.\r\n\\end{align*}\r\nCombining these together, we have \r\n$$ \\int \\frac{4-x}{\\sqrt{16-x^2}}\\ dx = 4\\sin^{-1}\\frac x4 + \\sqrt{16-x^2}+C.$$\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\r\n\r\nThis section has focused on evaluating indefinite integrals as we are learning a new technique for finding antiderivatives. However, much of the time integration is used in the context of a definite integral. Definite integrals that require substitution can be calculated using the following workflow:\r\n\r\n\\begin{enumerate}\r\n\\item\t\tStart with a definite integral $\\ds \\int_a^b f(x)\\ dx$ that requires substitution.\r\n\\item\t\tIgnore the bounds; use substitution to evaluate $\\ds \\int f(x)\\ dx$ and find an antiderivative $F(x)$.\r\n\\item\t\tEvaluate $F(x)$ at the bounds; that is, evaluate $F(x)\\Big|_a^b = F(b) - F(a)$.\r\n\\end{enumerate}\r\nThis workflow works fine, but substitution offers an alternative that is powerful and amazing (and a little time saving).  The next example shows how to use the Substitution Rule when dealing with definite integrals.\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRuledefex}\r\nEvaluate $\\ds\\int_2^4 x\\sin(x^2)\\,dx$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nFirst we compute the\r\nantiderivative, then evaluate the integral.\r\nLet $\\ds u=x^2$, so $du=2x\\,dx$ or $x\\,dx=du/2$. Then\r\n$$\r\n  \\int x\\sin(x^2)\\,dx=\\int {1\\over 2} \\sin u\\,du={1\\over 2}(-\\cos u)+C=\r\n  -{1\\over 2}\\cos(x^2)+C.\r\n$$\r\nNow\r\n$$\r\n  \\int_2^4 x\\sin(x^2)\\,dx=\\left.-{1\\over 2}\\cos(x^2)\\right|_2^4\r\n  =-{1\\over 2}\\cos(16)+{1\\over 2}\\cos(4).\r\n$$\r\nA somewhat neater alternative to this method is to change the original\r\nlimits to match the variable $u$. Since $\\ds u=x^2$, when $x=2$, $u=4$,\r\nand when $x=4$, $u=16$. So we can do this:\r\n$$\r\n  \\int_2^4 x\\sin(x^2)\\,dx=\r\n  \\int_4^{16} {1\\over 2} \\sin u\\,du=\\left.-{1\\over 2}(\\cos u)\\right|_4^{16}\r\n  =-{1\\over 2}\\cos(16)+{1\\over 2}\\cos(4).\r\n$$\r\nAn incorrect, and dangerous, alternative is something like this:\r\n$$\r\n  \\int_2^4 x\\sin(x^2)\\,dx=\\int_2^4 {1\\over 2} \\sin u\\,du=\r\n  \\left.-{1\\over 2}\\cos (u)\\right|_2^4=\r\n  \\left.-{1\\over 2}\\cos(x^2)\\right|_2^4=-{1\\over 2}\\cos(16)+{1\\over\r\n  2}\\cos(4).\r\n$$\r\nThis is incorrect because $\\ds\\int_2^4 {1\\over 2} \\sin u\\,du$\r\nmeans that $u$ takes on values between 2 and 4, which is wrong. It\r\nis dangerous, because it is very easy to get to \r\nthe point $\\ds\\left.-{1\\over 2}\\cos (u)\\right|_2^4$ and forget to substitute\r\n$\\ds x^2$ back in for $u$, thus getting the incorrect answer\r\n$\\ds -{1\\over 2}\\cos(4)+{1\\over 2}\\cos(2)$. An acceptable alternative is something like:\r\n$$ \r\n  \\int_2^4 x\\sin(x^2)\\,dx=\\int_{x=2}^{x=4} {1\\over 2} \\sin u\\,du=\r\n  \\left.-{1\\over 2}\\cos (u)\\right|_{x=2}^{x=4}=\r\n  \\left.-{1\\over 2}\\cos(x^2)\\right|_2^4=-{\\cos(16)\\over 2}+{\\cos(4)\\over2}.\r\n$$\r\n\\end{solution}\r\n\r\n\\subsection{Substitution and Definite Integrals}\r\n\r\nThe following theorem states how the bounds of a definite integral can be changed as the substitution is performed.\r\n\r\n\\begin{theorem}{Substitution Rule for Definite Integrals}{SubstitutionRuledef}\r\nIf $g'$ is continuous on $[a,b]$ and $f$ is continuous on the range of $u=g(x)$, then\r\n$$\\int_a^b f(g(x))g'(x)\\,dx=\\int_{g(a)}^{g(b)}f(u)\\,du.$$\r\n\\end{theorem}\r\n\r\n\r\n\r\nIn effect, Theorem \\ref{thm:SubstitutionRuledef} states that once you convert to integrating with respect to $u$, you do not need to switch back to evaluating with respect to $x$. A few examples will help one understand.\\\\\r\n\r\n\\begin{example}{Definite integrals and substitution: changing the bounds}{ex_sub12}\r\n{\r\nEvaluate $\\ds\\int_0^2 \\cos(3x-1)\\ dx$ using Theorem \\ref{thm:SubstitutionRuledef}.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{Observing the composition of functions, let $u=3x-1$, hence $du = 3dx$. As $3dx$ does not appear in the integrand, divide the latter equation by 3 to get $du/3 = dx$. \r\n\r\nBy setting $u = 3x-1$, we are implicitly stating that $g(x) = 3x-1$. Theorem \\ref{thm:SubstitutionRuledef} states that the new lower bound is $g(0) = -1$; the new upper bound is $g(2) = 5$. We now evaluate the definite integral:\r\n\\begin{align*}\r\n\\int_1^2 \\cos(3x-1) \\ dx &=\t\\int_{-1}^5 \\cos u \\frac{du}{3} \\\\\r\n\t\t\t\t\t\t\t\t&= \\frac{1}{3} \\sin u\\Big|_{-1}^5 \\\\\r\n\t\t\t\t\t\t\t\t&= \\frac{1}{3}\\big(\\sin 5- \\sin (-1)\\big)\\approx -0.039.\r\n\t\t\t\t\t\t\t\t%&\\approx -0.039.\r\n\\end{align*}\r\nNotice how once we converted the integral to be in terms of $u$, we never went back to using $x$.\r\n\r\n\r\n\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\begin{subfigure}{.5\\textwidth}\r\n  \\centering\r\n  \\includegraphics[width=.8\\textwidth]{figures/figsubst12a}\r\n  \\caption{}\r\n  \\label{fig:sub1}\r\n\\end{subfigure}%\r\n\\begin{subfigure}{.5\\textwidth}\r\n  \\centering\r\n  \\includegraphics[width=.8\\textwidth]{figures/figsubst12b}\r\n  \\caption{}\r\n  \\label{fig:sub2}\r\n\\end{subfigure}\r\n\\caption{Graphing the areas defined by the definite integrals of Example \\ref{exa:ex_sub12}. \\label{fig:subst12}}\r\n\\label{fig:test}\r\n\\end{figure}\r\n\r\n\r\n\r\n%\\begin{figure}\r\n%\\centering\r\n%\r\n%\\includegraphics[width=0.7\\linewidth]{figures/figsubst12a}\r\n%\r\n%\\caption{Graphing the areas defined by the definite integrals in Example \\ref{exa:ex_sub12}}\r\n%\\label{fig:figsubst12a}\r\n%\\end{figure}\r\n%\r\n%\r\n%\\mtable{.7}{Graphing the areas defined by the definite integrals of Example \\ref{exa:ex_sub12}.}{fig:subst12}{\\begin{tabular}{ccc}\r\n%\\includegraphics{figures/figsubst12a} & &\\includegraphics{figures/figsubst12b}\\\\\r\n%(a) & & (b)\r\n%\\end{tabular}\r\n\r\n\r\nThe graphs in Figure \\ref{fig:subst12} tell more of the story. In (a) the area defined by the original integrand is shaded, whereas in (b) the area defined by the new integrand is shaded. In this particular situation, the areas look very similar; the new region is ``shorter'' but ``wider,'' giving the same area.\r\n}\\\\\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Definite integrals and substitution: changing the bounds}{ex_subst13}\r\n{\r\nEvaluate $\\ds \\int_0^{\\pi/2} \\sin x \\cos x\\ dx$ using Theorem \\ref{thm:SubstitutionRuledef}.\r\n}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{We saw the corresponding indefinite integral in Example \\ref{exa:ex_sub10}. In that example we set $u = \\sin x$ but stated that we could have let $u = \\cos x$. For variety, we do the latter here.\r\n\r\nLet $u = g(x) = \\cos x$, giving $du = -\\sin x\\ dx$ and hence $\\sin x\\ dx = -du$. The new upper bound is $g(\\pi/2) = 0$; the new lower bound is $g(0) = 1$. Note how the lower bound is actually larger than the upper bound now. We have\r\n\\begin{align*}\r\n\t\\int_0^{\\pi/2} \\sin x\\cos x\\ dx &= \\int_1^0 -u\\ du \\quad \\text{\\scriptsize (switch bounds \\& change sign)}\\\\%&= \\int_1^0u\\ (-1)du\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t%&= \\int_1^0 -u\\ du \\quad \\text{\\scriptsize (switch bounds \\& change sign)}\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&=\t\\int_0^1 u\\ du\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac12u^2\\Big|_0^1= 1/2.%\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t%&= 1/2.\r\n\\end{align*}\r\nIn Figure \\ref{fig:subst13} we have again graphed the two regions defined by our definite integrals. Unlike the previous example, they bear no resemblance to each other. However, Theorem \\ref{thm:SubstitutionRuledef} guarantees that they have the same area.\r\n\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\begin{subfigure}{.5\\textwidth}\r\n  \\centering\r\n  \\includegraphics[width=.8\\linewidth]{figures/figsubst13a}\r\n  \\caption{}\r\n  \\label{fig:sub1}\r\n\\end{subfigure}%\r\n\\begin{subfigure}{.5\\textwidth}\r\n  \\centering\r\n  \\includegraphics[width=.8\\linewidth]{figures/figsubst13b}\r\n  \\caption{}\r\n  \\label{fig:sub2}\r\n\\end{subfigure}\r\n\\caption{Graphing the areas defined by the definite integrals of Example \\ref{exa:ex_subst13}. \\label{fig:subst13}}\r\n\\label{fig:test}\r\n\\end{figure}\r\n\r\n%%\\ifthenelse{\\boolean{longpage}}\r\n%%{% if longpage\r\n%\\mtable{.3}{Graphing the areas defined by the definite integrals of Example \\ref{ex_subst13}.}{fig:subst13}{\\begin{tabular}{ccc}\r\n%\\includegraphics{figures/figsubst13a} & &\\includegraphics{figures/figsubst13b}\\\\\r\n%(a) & & (b)\r\n%\\end{tabular}\r\n%\r\n%} %ends \\mtable\r\n%}% ends if longpage\r\n%{% not longpage\r\n%\\mtable{.32}{Graphing the areas defined by the definite integrals of Example \\ref{ex_subst13}.}{fig:subst13}{\\begin{tabular}{c}\r\n%\\myincludegraphics{figures/figsubst13a} \\\\ (a) \\\\ \\myincludegraphics{figures/figsubst13b}\\\\\r\n%(b)\r\n%\\end{tabular}\r\n%}% ends figure\r\n%}% ends if not longpage \r\n%\\vskip-\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRuledef2}\r\nEvaluate $\\ds\\int_{1/4}^{1/2}{\\cos(\\pi t)\\over\\sin^2(\\pi t)}\\,dt$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nLet $u=\\sin(\\pi t)$ so $du=\\pi\\cos(\\pi t)\\,dt$ or $du/\\pi=\\cos(\\pi\r\nt)\\,dt$.\r\nWe change the limits to $\\ds \\sin(\\pi/4)=\\sqrt2/2$ and \r\n$\\sin(\\pi/2)=1$.\r\nThen\r\n$$\r\n  \\int_{1/4}^{1/2}{\\cos(\\pi t)\\over\\sin^2(\\pi t)}\\,dt=\r\n  \\int_{\\sqrt2/2}^{1}{1\\over \\pi}{1\\over u^2}\\,du=\r\n  \\int_{\\sqrt2/2}^{1} {1\\over \\pi}u^{-2}\\,du=\r\n  \\left.{1\\over \\pi}{u^{-1}\\over -1}\\right|_{\\sqrt2/2}^{1}=\r\n  -{1\\over\\pi}+{\\sqrt2\\over\\pi}.\r\n$$\r\n\\end{solution}\r\n\r\nThe following theorem sometimes allows us to greatly simplify the calculations of integrals, by exploiting their symmetry.\r\n\r\n\\begin{theorem}{Integrals of Symmetric Functions}{symm_integrals}\r\nSuppose $f$ is continuous on $[-a, a]$.\r\n\\begin{enumerate}\r\n\\item  If $f$ is  even  (that is,  {$f(-x) = f(x)$}), then $\\displaystyle  { \\int\\limits_{-a}^a f(x) \\ dx} = 2  {\\int\\limits_0^a f(x) \\ dx}$.\r\n\\item  If $f$ is  {odd} (that is,  {$f(-x) = -f(x)$}), then $\\displaystyle   {\\int\\limits_{-a}^a f(x) \\  dx }=  {\\int\\limits_{0}^a f(x) \\ dx}+  {\\int\\limits_{-a}^0 f(x) \\ dx}= 0$.\r\n\\end{enumerate}\r\n\\end{theorem}\r\n\r\n\r\n\\begin{proof}\r\nSince the definite integral is additive with respect to the interval of integration, we have\r\n\\[\r\n\\int_{-a}^{a} f(x) \\; dx = \\int_{-a}^{0} f(x) \\; dx + \\int_{0}^{a} f(x) \\; dx =\\star\r\n\\]\r\nSubstitute $ u=-x $ in the first integral to get \r\n\\[\r\n\\star = \\int_{ a}^{0} f(-u) \\; -du + \\int_{0}^{a} f(x) \\; dx = \\int_{ 0}^{a} f(-u) \\; du + \\int_{0}^{a} f(x) \\; dx \r\n\\]\r\nSince $ u $ is simply a \"dummy variable\" we can replace it with $ x $ to get\r\n\\[\r\n\\star = \\int_{ 0}^{a} f(-x) \\; dx + \\int_{0}^{a} f(x) \\; dx = \\int_{0}^{a} f(x) + f(-x) \\; dx\r\n\\]\r\nIf $ f $ is even, then $ f(-x)=f(x) $, and   $ f $ is odd then $ f(x)+f(-x)=0 $ giving the equations in the theorem.\r\n\\end{proof}\r\n\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\begin{subfigure}{.5\\textwidth}\r\n  \\begin{tikzpicture}[/pgf/declare function={f= x^2+1;}]\r\n    \\begin{axis}[\r\n      axis lines=middle,\r\n       xtick       = {-2,0,2},\r\n      xticklabels = {$-a$,$0$,$a$},\r\n       ytick       = {},\r\n       yticklabels = {},\r\n      samples     = 160,\r\n      domain      = -2:2,\r\n      xmin = -2, xmax = 2,\r\n      ymin = 0, ymax = 5,\r\n    ]\r\n    \\addplot[name path=poly, black, thick, mark=none, ] {f};\r\n     \\addplot [draw=none,name path=B] {0};     % “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=-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:-1,1) {$A_1$};\r\n    \\node at (axis cs:1,1) {$A_2$};\r\n  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{Even symmetry, $ A_1=A_2$}\r\n  \\label{fig:symm1}\r\n\\end{subfigure}%\r\n\\begin{subfigure}{.5\\textwidth}\r\n\\begin{tikzpicture}[/pgf/declare function={f=x^3;}]\r\n  \\begin{axis}[\r\n      axis lines=middle,\r\n      xtick       = {-2,0,2},\r\n          xticklabels = {$-a$,$0$,$a$},\r\n           ytick       = {},\r\n          yticklabels = {},\r\n      samples     = 160,\r\n      domain      = -2:2,\r\n      xmin = -2, xmax = 2,\r\n      ymin = -8, ymax = 8,\r\n    ]\r\n  \\addplot[name path=poly, black, thick, mark=none, ] {f};\r\n   \\addplot [draw=none,name path=B] {0};     % “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=0:2}]; % filling\r\n  \\addplot [red!60] fill between[of = poly and B,soft clip={domain=-2:0}]; % filling\r\n  ];\r\n  %% Choosing the coordinates manually is annoying:\r\n  \\node at (axis cs:-1.5,-1) {$A_1$};\r\n  \\node at (axis cs:1.5,1) {$A_2$};\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\caption{Odd symmetry, $ A_1=-A_2$.}\r\n  \\label{fig:symm2}\r\n\\end{subfigure}\r\n\\label{fig:symm_integral}\r\n\\end{figure}\r\n\r\n\\begin{example}{Odd Symmetry and Integrals}{symm-integral1}\r\nUse properties of integrals to evaluate $\\displaystyle \\int_{-3}^{3}1-x^4 {d}{x}$\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nSince $ 1-x^4 $ is an odd function, that is, if $ f(x)=1-x^4 $, then $ f(-x) = 1-(-x)^4=1-x^4=f(x)$. So by symmetry (Theorem \\ref{thm:symm_integrals}) we have\r\n\\[\r\n\\int_{-3}^{3}1-x^4 {d}{x}=2\\int_{0}^{3}1-x^4 {d}{x}= 2\\left(x-\\frac{x^5}{5}\\right|+0^3=2\\left(3-\\frac{243}{5} \\right)\r\n= -\\frac{456}{5}\\]\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Even Symmetry and Integrals}{symm-integral2}\r\nUse properties of integrals to evaluate $\\displaystyle{{{\\int_{{-{5}}}^{{5}}}{\\left(\\frac{\\sin(x)}{x^2+1} \\right)}{d}{x}}}\r\n$\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nSince $ sin(x) $ is an odd function, and $ x^2+1 $ is an even function, the quotient of the two is odd.  That is, if $ f(x)= \\frac{\\sin(x)}{x^2+1}   $, then $ f(-x) =  \\frac{\\sin(-x)}{(-x)^2+1}  = \\frac{-\\sin(x)}{x^2+1} = -f(x) $. So by symmetry (Theorem \\ref{thm:symm_integrals}) we have\r\n\\[\r\n\\int_{-5}^{5}{\\left(\\frac{\\sin(x)}{x^2+1} \\right)}{d}{x}=0\r\n\\]\r\n\\end{solution}\r\n\r\n\r\nIntegration by substitution is a powerful and useful integration technique. Section \\ref{sec:Parts} introduces another technique, called Integration by Parts. As substitution ``undoes'' the Chain Rule, integration by parts ``undoes'' the Product Rule. Together, these two techniques provide a strong foundation on which most other integration techniques are based.\r\n\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:SubRule}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\nFind the following indefinite and definite integrals.\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int (1-t)^9\\,dt$\r\n\\begin{sol}\r\n $\\ds -(1-t)^{10}/10+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int (x^2+1)^2\\,dx$\r\n\\begin{sol}\r\n $\\ds x^5/5+2x^3/3+x+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int x(x^2+1)^{100}\\,dx$\r\n\\begin{sol}\r\n $\\ds (x^2+1)^{101}/202+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {1\\over\\root 3 \\of {1-5t}}\\,dt$ \r\n\\begin{sol}\r\n $\\ds -3(1-5t)^{2/3}/10+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int \\sin^3x\\cos x\\,dx$\r\n\\begin{sol}\r\n $\\ds (\\sin^4x)/4+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int x\\sqrt{100-x^2}\\,dx$\r\n\\begin{sol}\r\n $\\ds -(100-x^2)^{3/2}/3+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {x^2\\over\\sqrt{1-x^3}}\\,dx$\r\n\\begin{sol}\r\n $\\ds \\ds -2\\sqrt{1-x^3}/3+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int \\cos(\\pi t)\\cos\\bigl(\\sin(\\pi t)\\bigr)\\,dt$\r\n\\begin{sol}\r\n $\\ds \\sin(\\sin\\pi t)/\\pi+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {\\sin x\\over\\cos^3 x}\\,dx$\r\n\\begin{sol}\r\n $\\ds \\ds 1/(2\\cos^2 x)=(1/2)\\sec^2x+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int\\tan x\\,dx$\r\n\\begin{sol}\r\n $-\\ln|\\cos x|+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n  $\\ds\\int_0^\\pi\\sin^5(3x)\\cos(3x)\\,dx$\r\n\\begin{sol}\r\n $0$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int\\sec^2x\\tan x\\,dx$\r\n\\begin{sol}\r\n $\\ds \\tan^2(x)/2+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_0^{\\sqrt{\\pi}/2} x\\sec^2(x^2)\\tan(x^2)\\,dx$\r\n\\begin{sol}\r\n $1/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {\\sin(\\tan x)\\over\\cos^2x}\\,dx$\r\n\\begin{sol}\r\n $-\\cos(\\tan x)+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_3^4 {1\\over(3x-7)^2}\\,dx$\r\n\\begin{sol}\r\n $1/10$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_0^{\\pi/6}(\\cos^2x - \\sin^2x)\\,dx$\r\n\\begin{sol}\r\n $\\ds \\sqrt3/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {6x\\over(x^2 - 7)^{1/9}}\\,dx$\r\n\\begin{sol}\r\n $\\ds (27/8)(x^2-7)^{8/9}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_{-1}^1 (2x^3-1)(x^4-2x)^6\\,dx$\r\n\\begin{sol}\r\n $\\ds -(3^7+1)/14$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_{-1}^1 \\sin^7 x\\,dx$\r\n\\begin{sol}\r\n $0$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int f(x) f'(x)\\,dx$ \r\n\\begin{sol}\r\n $\\ds f(x)^2/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "aac4575360ef48e4373a844a70ce7a422814b7c4", "size": 50157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-1-sub-rule.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7-techniques-of-integration/7-1-sub-rule.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7-techniques-of-integration/7-1-sub-rule.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.2387931034, "max_line_length": 840, "alphanum_fraction": 0.6411866738, "num_tokens": 17433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.757794360334681, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.6570348011757964}}
{"text": "\\par\n\\chapter{Algorithm Design}\n\\label{chapter:algorithmDesign}\n\\par\nLet us begin with a very quick description of the sparse\nfactorizations we will use.\nWe assume that the matrix $A$ has symmetric structure, or more\ngenerally, if $a_{i,j} \\ne 0$, then we treat $a_{j,i}$ as nonzero.\n\\par\nLet us ignore pivoting for a moment.\nThe matrix will be factored as $A = (L+I)D(I+U)$.\nThe rows and columns of $A$ are partitioned into {\\it fronts}.\nWe use the upper case Roman letters $I$ and $J$ to refer to\nindex sets for a front.\nWe use $\\bnd{J}$ to represent the {\\it boundary} of front $J$,\nnamely those rows and columns $k \\notin J$ \nsuch that $l_{k,j} \\ne 0$ and or $u_{j,k} \\ne 0$.\n\\par\nThere are two steps to compute the entries in a front.\nThe first is to form the temporary matrix\n\\begin{equation}\n\\label{alg:eqn:1}\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & T_{\\bnd{J},\\bnd{J}}\n\\end{array} \\right \\rbrack\n=\n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n-\n\\left \\lbrack \\begin{array}{c}\nL_{J,*} \\\\\nL_{\\bnd{J},*}\n\\end{array} \\right \\rbrack\nD_{*,*} \n\\left \\lbrack \\begin{array}{cc}\nU_{*,J} & U_{*,\\bnd{J}}\n\\end{array} \\right \\rbrack.\n\\end{equation}\nThe $*$ subscript means all rows and columns that precede $J$.\nWe think of the temporary matrix on the left\nas {\\it fully assembled}, i.e.,\nthe original entries are present plus all updates from rows and\ncolumns that precede the front.\n\\par\nThe second step is to factor the front as\n\\begin{equation}\n\\label{alg:eqn:2}\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & T_{\\bnd{J},\\bnd{J}}\n\\end{array} \\right \\rbrack\n=\n\\left \\lbrack \\begin{array}{cc}\nL_{J,J} + I & 0 \\\\\nL_{\\bnd{J},J} & I\n\\end{array} \\right \\rbrack\n\\left \\lbrack \\begin{array}{cc}\nD_{J,J} & 0 \\\\\n0 & H_{\\bnd{J},\\bnd{J}}^J\n\\end{array} \\right \\rbrack\n\\left \\lbrack \\begin{array}{cc}\nI + U_{J,J} & U_{J,\\bnd{J}} \\\\\n0 & I\n\\end{array} \\right \\rbrack.\n\\end{equation}\n\\par\nIn equation~(\\ref{alg:eqn:1}) there will likely be many columns $i$ such\nthat $L_{J,i}$ and $U_{i,J}$ are zero, in which case they need not\ntake part in the first equation.\nSince all preceding rows and columns are found in fronts\nthemselves, we can rewrite equation~(\\ref{alg:eqn:1}) as\n\\begin{equation}\n\\label{alg:eqn:3}\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & T_{\\bnd{J},\\bnd{J}}\n\\end{array} \\right \\rbrack\n=\n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n-\n\\sum_{\\bnd{I} \\cap J \\ne \\emptyset}\n\\left \\lbrack \\begin{array}{c}\nL_{J,I} \\\\\nL_{\\bnd{J},I}\n\\end{array} \\right \\rbrack\nD_{I,I} \n\\left \\lbrack \\begin{array}{cc}\nU_{I,J} & U_{I,\\bnd{J}}\n\\end{array} \\right \\rbrack.\n\\end{equation}\n\\par\nThe fronts can be grouped into a {\\it front tree} using a {\\it\nparent} relation: $par(I) = J$ means that $J$ is the parent of $I$\nin the front tree.\nThere is one special property that relates the boundaries of fronts\nand the front tree: if $\\bnd{I} \\cap J \\ne \\emptyset$, then $I$ is\na descendent of $J$, or conversely, $J$ is an ancestor of $I$.\nFront $I$ need not update all of its ancestors, nor does front $J$\nneed to be updated by all of its descendents, but when an update\ndoes occur, it is between two fronts that have a\nancestor-descendent relationship.\nThe front tree is defined by the parent relation:\nthe {\\it parent} of $I$ is the front that contains the first row\nand column in $\\bnd{I}$, in other words, the closest supported\nancestor to $I$.\n(Of course, if $\\bnd{I} = \\emptyset$, then its parent does not\nexist, and $I$ is a root of the tree, actually a forest if $A$ is\nreducible.)\nThere is one important property that relates the boundary sets of a\nfront and its parent: \nif $par(I) = J$, then $\\bnd{I} \\subseteq J \\cup \\bnd{J}$.\n\\par\nUsing the front tree, let us describe the fronts that are\ndescendents of a front.\nWe use the ${\\widehat {\\ }}$ operator to denote a subtree.\n${\\widehat J}$, the subtree rooted at $J$,\nis the set of fronts that contains $J$ and all of its descendents.\nWe can write the subtree relation in a recursive form.\n$$\n{\\widehat J} = J \\cup \\bigcup_{par(I) = J} {\\widehat I}\n$$\nUsing these two relations, we can rewrite\nequation~(\\ref{alg:eqn:3}) as follows.\n\\begin{eqnarray}\n\\label{alg:eqn:4}\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & T_{\\bnd{J},\\bnd{J}}\n\\end{array} \\right \\rbrack\n& = &\n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n-\n\\sum_{par(I) = J}\n\\left \\lbrack \\begin{array}{c}\nL_{J,{\\widehat I}} \\nonumber \\\\\nL_{\\bnd{J},{\\widehat I}}\n\\end{array} \\right \\rbrack\nD_{{\\widehat I},{\\widehat I}} \n\\left \\lbrack \\begin{array}{cc}\nU_{{\\widehat I},J} & U_{{\\widehat I},\\bnd{J}}\n\\end{array} \\right \\rbrack \\\\\n& = & \n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n- \n\\sum_{par(I) = J}\nL_{\\bnd{I}, {\\widehat I}}\nD_{{\\widehat I}, {\\widehat I}}\nU_{{\\widehat I}, \\bnd{I}}\n\\end{eqnarray}\nOne more trick is necessary.\nRecall equation~(\\ref{alg:eqn:2}).\nOnce we have assembled the temporary matrix, we factor into the\n$L$, $D$ and $U$ portions plus an additional matrix\n$H_{\\bnd{J},\\bnd{J}}^J$ which we call the update matrix.\nUsing the update matrices of the children, we can rewrite \nequation~(\\ref{alg:eqn:4}) as follows.\n\\begin{equation}\n\\label{alg:eqn:mf}\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & T_{\\bnd{J},\\bnd{J}}\n\\end{array} \\right \\rbrack\n= \n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n- \n\\sum_{par(I) = J}\nH_{\\bnd{I},\\bnd{I}}^I\n\\end{equation}\nThis is the defining equation for the multifrontal method\n\\cite{duf83-multifrontal}.\nThe matrix on the left is the {\\it frontal matrix} for front $J$,\nand is usually dense and almost always treated as if it were dense.\nThe first matrix on the right consists of original entries and is\nusually sparse.\nEach of the $H_{\\bnd{I},\\bnd{I}}^I$ update matrices are treated as\nif they were dense.\n\\par\nThere are many advantages to the multifrontal method.\nThe computations are almost all dense matrix operations.\nIn a serial environment, the temporary storage for the update\nmatrices can be handled as a stack, a last-in first-out list\nstructure.\nThis makes the transition to an out-of-core implementation very easy.\nBut, the one disadvantage is that the frontal matrices can take up\nan immense amount of space for the largest fronts, typically near\nthe top of the tree.\nThis is the main reason that we do not use this algorithm\nin the {\\bf SPOOLES} library.\n\\par\nReturn to equation~(\\ref{alg:eqn:3}) for a moment.\nA left-looking block general sparse algorithm computes three of the\nfour submatrices on the left.\n\\begin{eqnarray*}\nT_{J,J} & = & A_{J,J}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap J, I} D_{I, I} U_{I, \\bnd{I} \\cap J}\n\\\\\nT_{\\bnd{J},J} & = & A_{\\bnd{J},J}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap \\bnd{J}, I} D_{I, I} U_{I, \\bnd{I} \\cap J}\n\\\\\nT_{J,\\bnd{J}} & = & A_{J,\\bnd{J}}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap J, I} D_{I, I} U_{I, \\bnd{I} \\cap \\bnd{J}}\n\\end{eqnarray*}\nand then factors the three as follows.\n\\begin{eqnarray*}\nT_{J,J}       & = & (L_{J,J} + I)D_{J,J}(I + U_{J,J}) \\\\\nT_{\\bnd{J},J} & = & L_{\\bnd{J},J}D_{J,J}(I + U_{J,J}) \\\\\nT_{J,\\bnd{J}} & = & (L_{J,J} + I)D_{J,J}U_{J,\\bnd{J}}\n\\end{eqnarray*}\nIf the fronts are large there are good computational kernels to be had.\nThe disadvantage lies in the irregular access patterns for the\ncomputed factor submatrices; this makes an out-of-core\nimplementation problematic.\nOn the other hand, working storage is modest, for there are no\nupdate matrices waiting to be assembled.\n\\par \\bigskip \\par\n\\noindent {\\large\\bf Pivoting and delayed rows and columns}\n\\par \\bigskip \\par\nLet us now turn to pivoting during the factorization.\nIt is not the actual swapping of rows and columns that gives\nproblems --- one must merely keep track\nof indices and permute rows and columns.\nWhat does complicate matters is when rows and columns cannot be\neliminated from a front due to stability reasons.\n(The remaining lower right matrix in $T_{J,J}$ may be zero, or\neliminating rows and columns may result in large entries in\n$L_{\\bnd{J},J}$ or $U_{J,\\bnd{J}}$.)\nThe delayed rows and columns must be {\\it passed} up to the parent\nfront, enlarging the parent front where an attempt will be made\nto eliminate them with the rows and columns in the parent's front.\n\\par\nLet us assume symmetric pivoting for the moment, where the row and\ncolumn permutation matrices are identical.\nLet the rows and columns in front $I$ be partitioned into two sets,\n$I_e$ contains the eliminated rows and columns\nand\n$I_d$ contains the delayed rows and columns.\nLet us look first at the multifrontal method for it is easier to\nunderstand.\n\\begin{equation}\n\\label{alg:eqn:mf-delayed}\n\\left \\lbrack \\begin{array}{cc}\nT_{I,I} & T_{I, \\bnd{I}} \\\\\nT_{\\bnd{I},I} & T_{\\bnd{I},\\bnd{J}}\n\\end{array} \\right \\rbrack\n=\n\\left \\lbrack \\begin{array}{cc}\nL_{I_e,I_e} + I & 0 \\\\\nL_{I_d \\cup \\bnd{J},I_e}  & I\n\\end{array} \\right \\rbrack\n\\left \\lbrack \\begin{array}{cc}\nD_{I_e,I_e} & 0 \\\\\n0           & H_{I_d \\cup \\bnd{I},I_d \\cup \\bnd{I}}^I\n\\end{array} \\right \\rbrack\n\\left \\lbrack \\begin{array}{cc}\nI + U_{I_e,I_e} & U_{I_e,I_d \\cup \\bnd{J}} \\\\\n0 & I \\\\\n\\end{array} \\right \\rbrack.\n% \\left \\lbrack \\begin{array}{cc}\n% T_{I,I} & T_{I, \\bnd{I}} \\\\\n% T_{\\bnd{I},I} & T_{\\bnd{I},\\bnd{J}}\n% \\end{array} \\right \\rbrack\n% =\n% \\left \\lbrack \\begin{array}{ccc}\n% L_{I_e,I_e} + I & 0 & 0 \\\\\n% L_{I_d,I_e}     & I & 0 \\\\\n% L_{\\bnd{J},I_e}   & 0 & I\n% \\end{array} \\right \\rbrack\n% \\left \\lbrack \\begin{array}{ccc}\n% D_{I_e,I_e} & 0                 & 0 \\\\\n% 0           & H_{I_d,I_d}^I     & H_{I_d,\\bnd{I}}^I \\\\\n% 0           & H_{\\bnd{I},I_d}^I & H_{\\bnd{I},\\bnd{I}}^I\n% \\end{array} \\right \\rbrack\n% \\left \\lbrack \\begin{array}{ccc}\n% I + U_{I_e,I_e} & U_{I_e,I_d}, & U_{I_e,\\bnd{J}} \\\\\n% 0 & I & 0 \\\\\n% 0 & o & I \\\\\n% \\end{array} \\right \\rbrack.\n\\end{equation}\n\\par\nThe update matrix for $I$ contains the delayed rows and columns\nas well as the usual update matrix $H^I_{\\bnd{I},\\bnd{I}}$\nthat would normally occur.\n$$\nH^I_{I_d \\cup \\bnd{I}, I_d \\cup \\bnd{I}} \n=\n\\left \\lbrack \\begin{array}{cc}\nH^I_{I_d,I_d}     & H^I_{I_d, \\bnd{I}} \\\\\nH^I_{\\bnd{I},I_d} & H^I_{\\bnd{I},\\bnd{I}}\n\\end{array} \\right \\rbrack\n$$\nRecall, the $I_e$ rows and columns are fully assembled, so they can\nbe merged into the parent front. Let us define the new front after\nmerging all delayed rows and columns from the children as\n$$\n{\\widetilde J} = J \\cup \\bigcup_{par(I) = J } I_d.\n$$\nWe can now write the multifrontal equation with pivoting as follows.\n\\begin{equation}\n\\label{alg:eqn:mf-pivoting}\n\\left \\lbrack \\begin{array}{cc}\nT_{{\\widetilde J},{\\widetilde J}} & T_{{\\widetilde J}, \\bnd{J}} \\\\\nT_{\\bnd{J},{\\widetilde J}} & T_{\\bnd{J},\\bnd{J}}\n\\end{array} \\right \\rbrack\n= \n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n- \n\\sum_{par(I) = J}\nH_{I_d \\cup \\bnd{I}, I_d \\cup \\bnd{I}}^I\n\\end{equation}\nDelaying rows and columns from one front to its parent really\ndoesn't change the multifrontal algorithm very much.\nThis is the reason that a factorization with pivoting has usually\nbeen implemented by a multifrontal algorithm.\n\\par\nNow let us return to a left-looking general sparse factorization\nand try to incorporate pivoting.\nThe equations that accumulate updates from the descendent fronts\nmust be modifed to include the delayed rows and columns from the\nchildren.\n\\begin{eqnarray*}\nT_{{\\widetilde J},{\\widetilde J}} & = & A_{J,J}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap J, I_e} \nD_{I_e, I_e} \nU_{I_e, \\bnd{I} \\cap J}\n+ \\sum_{par(I) = J} \n\\left \\lbrack \\begin{array}{cc}\nH_{I_d, I_d} & H_{I_d, \\bnd{I} \\cap J} \\\\\nH_{\\bnd{I} \\cap J, I_d} & 0 \\\\\n\\end{array} \\right \\rbrack\n\\\\\nT_{\\bnd{J},{\\widetilde J}} & = & A_{\\bnd{J},J}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap \\bnd{J}, I_e} D_{I_e, I_e} U_{I_e, \\bnd{I} \\cap J}\n+ \\sum_{par(I) = J} H_{\\bnd{I} \\cap \\bnd{J}, I_d}\n\\\\\nT_{{\\widetilde J},\\bnd{J}} & = & A_{J,\\bnd{J}}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap J, I_e} D_{I_e, I_e} U_{I_e, \\bnd{I} \\cap \\bnd{J}}\n+ \\sum_{par(I) = J} H_{I_d, \\bnd{I} \\cap \\bnd{J}}\n\\end{eqnarray*}\nIt appears that since we do not know the structure of ${\\widetilde J}$\nuntil the delayed rows and columns of the children of $J$ are known, \nwe cannot start the computation until the children of $J$ are finished.\nThis is not quite true.\nWrite the above equations as follows, marking the ${\\widetilde T}$ \nmatrices on the left as distinct from the $T$ matrices on the right.\n\\begin{eqnarray*}\n{\\widetilde T}_{{\\widetilde J},{\\widetilde J}} & = & T_{J,J}\n+ \\sum_{par(I) = J} \n\\left \\lbrack \\begin{array}{cc}\nH_{I_d, I_d} & H_{I_d, \\bnd{I} \\cap J} \\\\\nH_{\\bnd{I} \\cap J, I_d} & 0 \\\\\n\\end{array} \\right \\rbrack\n\\\\\n{\\widetilde T}_{\\bnd{J},{\\widetilde J}} & = & T_{\\bnd{J},J}\n+ \\sum_{par(I) = J} H_{\\bnd{I} \\cap \\bnd{J}, I_d}\n\\\\\n{\\widetilde T}_{{\\widetilde J},\\bnd{J}} & = & T_{J,\\bnd{J}}\n+ \\sum_{par(I) = J} H_{I_d, \\bnd{I} \\cap \\bnd{J}}\n\\end{eqnarray*}\nThe $T$ matrices have the following form.\n\\begin{eqnarray*}\nT_{J,J} & = & A_{J,J}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap J, I_e} \nD_{I_e, I_e} \nU_{I_e, \\bnd{I} \\cap J}\n\\\\\nT_{\\bnd{J},J} & = & A_{\\bnd{J},J}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap \\bnd{J}, I_e} D_{I_e, I_e} U_{I_e, \\bnd{I} \\cap J}\n\\\\\nT_{J,\\bnd{J}} & = & A_{J,\\bnd{J}}\n- \\sum_{\\bnd{I} \\cap J \\ne \\emptyset} \nL_{\\bnd{I} \\cap J, I_e} D_{I_e, I_e} U_{I_e, \\bnd{I} \\cap \\bnd{J}}\n\\end{eqnarray*}\nThe computation of $T_{J,J}$, $T_{\\bnd{J},J}$ and $T_{J,\\bnd{J}}$\ndoes not depend on any delayed rows and columns from the children,\nand so it can begin to execute before the children are complete.\nIt is key to note that $J$ and $\\bnd{J}$ are known before the\nfactorization starts and do not change due to any delayed rows or\ncolumns.\nIt is true that we do not know $I_e$ for each descendent of $J$\n{\\it until} front $I$ is complete, but in some sense that does not\nmatter.\nAll that is necessary is to keep track of which descendent fronts $I$ \nhave $I_e \\ne \\emptyset$ and $\\bnd{I} \\cap J \\ne \\emptyset$.\nThe three equations with ${\\widetilde T}$ on the left\nare simply an assembly of matrices ---\none matrix comes from the updates from the descendents,\none matrix from delayed rows and columns.\n\\par \\bigskip \\par\n\\noindent {\\bf A serial factorization}\n\\par \\bigskip \\par\nThere are five simple steps to a serial factorization:\ninitialize the front, load original entries, accumulate updates\nfrom descendents, assemble any delayed rows and columns from the\nchildren, then factor the front and update any delayed rows and\ncolumns. \nHere is the algorithm step by step.\n\\par\n\\noindent Loop over the fronts in a post-order traversal\n\\begin{enumerate}\n\\item\nInitialize \n$\\displaystyle\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n= 0.\n$\n\\item\nLoad with original entries \n\\par\n$\\displaystyle\n\\mbox{\\qquad} \n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n\\mbox{\\tt +=}\n\\left \\lbrack \\begin{array}{cc}\nA_{J,J} & A_{J, \\bnd{J}} \\\\\nA_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n$\n\\item\nAccumulate updates from descendents.\n\\par\nFor $I_e \\ne \\emptyset$ and $\\bnd{I} \\cap J \\ne \\emptyset$.\n\\par\n$\\mbox{\\qquad}\\displaystyle\n\\left \\lbrack \\begin{array}{cc}\nT_{J,J} & T_{J, \\bnd{J}} \\\\\nT_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n\\mbox{\\tt -=}\n\\left \\lbrack \\begin{array}{c}\nL_{\\bnd{I}\\cap J,I_e} \\\\\nL_{\\bnd{I}\\cap \\bnd{J},I_e} \n\\end{array} \\right \\rbrack\nD_{I_e,I_e}\n\\left \\lbrack \\begin{array}{cc}\nU_{I_e, \\bnd{I} \\cap J} & U_{I_e, \\bnd{I}\\cap \\bnd{J}} \n\\end{array} \\right \\rbrack\n$\n\\item\nAssemble postponed rows and columns.\n\\par $\\widetilde J = J$.\n\\par for $par(I) = J$ and $I_d \\ne \\emptyset$\n\\par\n$\\mbox{\\qquad} {\\widetilde J} := {\\widetilde J} \\cup I_d$\n\\par\n$\\mbox{\\qquad} \\displaystyle\n\\left \\lbrack \\begin{array}{cc}\nT_{{\\widetilde J},{\\widetilde J}} & T_{{\\widetilde J}, \\bnd{{\\widetilde J}}} \\\\\nT_{\\bnd{{\\widetilde J}},{\\widetilde J}} & 0\n\\end{array} \\right \\rbrack\n\\mbox{\\tt +=}\n\\left \\lbrack \\begin{array}{cc}\nH_{I_d \\cup (\\bnd{I} \\cap J), I_d \\cup (\\bnd{I} \\cap J)}\n& H_{I_d \\cup (\\bnd{I} \\cap J), \\bnd{I} \\cap \\bnd{J}} \\\\\nH_{\\bnd{I} \\cap \\bnd{J}), I_d \\cup (\\bnd{I} \\cap J)} & 0\n\\end{array} \\right \\rbrack\n$\n\\item\nFactor the front.\n\\par\n$T_{J_e,J_e} \n    =  (L_{J_e,J_e} + I)D_{J_e,J_e} (I + U_{J_e,J_e})$\n\\par\n$T_{J_d \\cup \\bnd{J},J_e} \n   = L_{J_d \\cup \\bnd{J},J_e} D_{J_e,J_e} (I + U_{J_e,J_e}) $\n\\par\n$T_{J_e,J_d \\cup \\bnd{J}} \n   = (L_{J_e,J_e} + I)D_{J_e,J_e} U_{J_e,J_d \\cup \\bnd{J}})$\n\\par\n$H_{J_d,J_d}^J \n   = T_{J_d,J_d} - L_{J_d, J_e} D_{J_e,J_e} U_{J_e,J_d}$\n\\par\n$H_{J_d,\\bnd{J}}^J \n   = T_{J_d,\\bnd{J}} - L_{J_d, J_e} D_{J_e,J_e} U_{J_e,\\bnd{J}}$\n\\par\n$H_{\\bnd{J},J_d}^J \n   = T_{\\bnd{J},J_d} - L_{\\bnd{J}, J_e} D_{J_e,J_e} U_{J_e,J_d}$\n\\end{enumerate}\nThe last step needs a bit of elaboration. \nThe factorization of a front is a complex process.\nThe matrix $D_{J_e,J_e}$ is diagonal or block diagonal.\nOur codes try to detect large block pivots as a way of taking\nadvantage of the speed of BLAS3 kernels.\n\\par\nConsider symmetric pivoting for now. (Nonsymmetric pivoting is much\nthe same but the notation gets more complicated.)\n\\begin{center}\n\\begin{minipage}{3.5 in}\n\\begin{tabbing}\nXXX\\=XXX\\=XXX\\=XXX\\=XXX\\kill\n$J_e = J_d = \\emptyset$ \\\\\nwhile a pivot block $(\\bfj, \\bfj)$ can be found \\\\\n\\> $J_e := J_e \\cup \\bfj$,\n   ${\\widetilde J} := {\\widetilde J} \\setminus \\bfj$ \\\\\n\\> $D_{\\bfj,\\bfj} = T_{\\bfj,\\bfj}$\\\\\n\\> $L_{{\\widetilde J}\\cup\\bnd{J},\\bfj} \n      = A_{{\\widetilde J}\\cup\\bnd{J},\\bfj} D_{\\bfj,\\bfj}^{-1}$\\\\\n\\> $U_{{\\widetilde J}\\cup\\bnd{J},\\bfj} \n      = D_{\\bfj,\\bfj}^{-1} A_{\\bfj,{\\widetilde J}\\cup\\bnd{J}} $ \\\\\n\\> $T_{{\\widetilde J}, {\\widetilde J}}\n   := T_{{\\widetilde J}, {\\widetilde J}}\n    - L_{{\\widetilde J}, \\bfj} D_{\\bfj,\\bfj} U_{\\bfj,{\\widetilde J}}$ \\\\\n\\> $T_{\\bnd{J}, {\\widetilde J}}\n   := T_{\\bnd{J}, {\\widetilde J}}\n    - L_{\\bnd{J}, \\bfj} D_{\\bfj,\\bfj} U_{\\bfj,{\\widetilde J}}$ \\\\\n\\> $T_{{\\widetilde J}, \\bnd{J}}\n   := T_{{\\widetilde J}, \\bnd{J}}\n    - L_{{\\widetilde J}, \\bfj} D_{\\bfj,\\bfj} U_{\\bfj,\\bnd{J}}$\\\\\nend while \\\\\n$J_d = {\\widetilde J}$\n\\end{tabbing}\n\\end{minipage}\n\\end{center}\nNote the matrix-matrix multiply with the explicit inverse\nof $D_{\\bfj,\\bfj}$.\nWe actually compute the inverse\n$D_{\\bfj,\\bfj}^{-1}$ as part of the test for acceptability \nof the pivot block.\n(See Section~\\ref{section:PivotFinder} for more details.)\n\\par \\bigskip \\par\n\\noindent {\\bf Parallel factorization }\n\\par \\bigskip \\par\nWe have one major assumption as we move towards a parallel\nalgorithm. {\\it \nOnce a front is complete (all updates from descendent fronts\nhave been made and any postponed rows and columns from the children\nhave been assembled), the its factorization takes place inside\none thread or processor.}\nThis does not lead to a {\\it scalable} algorithm\n\\cite{sch93-scalability}, but it is important for efficiency to\nhave the pivot selection process inside one thread of computation.\n\\par\nIn light of this constraint, let us look at the five steps of the\nfactorization.\nSteps 1, 2, 4 and 5 must be done by one thread, the owner of the\nfront $J$.\nIt is Step 3 that must be parallelized across the processors.\nNow for the major question: if front $I$ updates front $J$,\nwho performs the computation? There are three possibilities.\n\\begin{itemize}\n\\item\nThe owner of front $I$. (The fan-in method \n\\cite{ash90-fan-in}.)\n\\item\nThe owner of front $J$. (The fan-out method \n\\cite{geo87-fan-out}.)\n\\item\nSome other processor. (The fan-both method\n\\cite{ash93-fan-both}.)\n\\end{itemize}\nWe have chosen the fan-in paradigm for this library.\nIt is a simple method, fairly efficient and can take advantage of\nsubtree-subcube mappings \\cite{geo87-fan-out} better than either\nthe fan-out or fan-both methods.\nAny algorithm will distribute the factor entries among the threads,\nbut there can be only one owner that computes\nthe factor pivots of a given front.\nFurthermore, the fan-in algorithm features no exchange of factor\nentries among the threads, rather it is partial updates, or\n{\\it aggregate} updates that are exchanged.\n\\par\nStep 3 needs some modification for thread $q$.\n\\begin{itemize}\n\\item[$3^\\prime.$]\nFor $I$ owned by thread $q$, \n$I_e \\ne \\emptyset$\nand $\\bnd{I} \\cap J \\ne \\emptyset$\n\\par\n$\\mbox{\\qquad}\\displaystyle\n\\left \\lbrack \\begin{array}{cc}\nT^q_{J,J} & T^q_{J, \\bnd{J}} \\\\\nT^q_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n\\mbox{\\tt -=}\n\\left \\lbrack \\begin{array}{c}\nL_{\\bnd{I}\\cap J,I_e} \\\\\nL_{\\bnd{I}\\cap \\bnd{J},I_e} \n\\end{array} \\right \\rbrack\nD_{I_e,I_e}\n\\left \\lbrack \\begin{array}{cc}\nU_{I_e, \\bnd{I} \\cap J} & U_{I_e, \\bnd{I}\\cap \\bnd{J}} \n\\end{array} \\right \\rbrack\n$\n\\begin{tabbing}\nXXX\\=XXX\\=XXX\\=XXX\\=\\kill\nIf $J$ is owned by thread $q$ then \\\\\n\\> for each supporting thread $r$ \\\\\n\\>\\> $\\displaystyle\n\\left \\lbrack \\begin{array}{cc}\nT^q_{J,J} & T^q_{J, \\bnd{J}} \\\\\nT^q_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n\\mbox{\\tt +=}\n\\left \\lbrack \\begin{array}{cc}\nT^r_{J,J} & T^r_{J, \\bnd{J}} \\\\\nT^r_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n$ \\\\\n\\> end for \\\\\n% else \\\\\n% \\> send\n% $\\displaystyle\n% \\left \\lbrack \\begin{array}{cc}\n% T^q_{J,J} & T^q_{J, \\bnd{J}} \\\\\n% T^q_{\\bnd{J},J} & 0\n% \\end{array} \\right \\rbrack\n% $ to the owner of $J$ \\\\\nend if\n\\end{tabbing}\n\\end{itemize}\nOf course we are omitting the rendevous (in a threaded context)\nor send/receive (in a distributed context) logic in the algorithm\ndescription. It should be clear that the aggregate updates\n(on the left)\nand the delayed rows and columns \n(on the right)\n$$\nT_J^q =\n\\left \\lbrack \\begin{array}{cc}\nT^q_{J,J} & T^q_{J, \\bnd{J}} \\\\\nT^q_{\\bnd{J},J} & 0\n\\end{array} \\right \\rbrack\n\\qquad \\qquad\nH^I =\n\\left \\lbrack \\begin{array}{cc}\nH_{I_d \\cup (\\bnd{I} \\cap J), I_d \\cup (\\bnd{I} \\cap J)}\n& H_{I_d \\cup (\\bnd{I} \\cap J), \\bnd{I} \\cap \\bnd{J}} \\\\\nH_{\\bnd{I} \\cap \\bnd{J}), I_d \\cup (\\bnd{I} \\cap J)} & 0\n\\end{array} \\right \\rbrack\n$$\nmust be made available to the threads \nor communicated to the processors that need them.\n\\par\nThe presence of pivoting, and thus the possibility that a front may\nnot have any eliminated rows and columns, makes an implementation\nsomewhat tricky.\nThis is a key point and needs to be explained further.\nIt is simple to determine {\\it prior to the factorization}\nwhich threads will support which fronts, but it is possible that a\nnone of the fronts owned by a thread will have any eliminated rows\nand columns that support some given front $J$. \nThe aggregate matrix $T_J^q$ would never been created but the owner\nof front $J$ will be expecting it.\nIn short, the communication patterns of the factorization without\npivoting must be obeyed for the process to terminate satisfactorily.\nIf an aggregate matrix is indeed empty, meaning that due to delayed\nrows and columns the updates that would have been performed will\nnot be forthcoming, the entries are not actually transfered,\nbut the notification is made.\n\\par \\bigskip \\par\n\\noindent {\\bf Parallel solve }\n\\par \\bigskip \\par\nLet us now consider the forward and backsolves.\nWe make one assumption: the data partition of the factors $L$, $D$\nand $U$ will be maintained during the solve.\nIn other words, the entries in $L$, $D$ and $U$\nare found in basic submatrices,\n$L_{J_d \\cup \\bnd{J}, J_e}$, \n$D_{J_e, J_e}$ and\n$L_{J_e, J_d \\cup \\bnd{J}}$, \nand these submatrices are not split\nup across threads or processors.\nThere is still the concept of a thread or processor owning a front.\nIn the threaded code we do allow for different maps from fronts\nto owners.\\footnote{\nFor example, the forward and backsolves could be done with fewer\nthreads than the factorization.\n}\n\\par\nWe do not actually compute $A = (L + I)D(I + U)$, instead we\ncompute $(L + I)(D + {\\widehat U})$ where ${\\widehat U} = DU$.\nRecall, the eliminated rows and columns for a front, $J_e$,\nare split into pivot blocks that we denote by $\\bfj$.\nBy convention, let the boundary of $\\bfj$ be\n$$\n\\bnd{\\bfj} = \\{k\\ |\\ l_{k,j} \\ne 0 \\mbox{\\ for some\\ }j \\in \\bfj\\}.\n$$\nNote, $\\bnd{\\bfj} \\subset J_e \\cup J_d \\cup \\bnd{J}$.\nThe serial solve $(I+L)(D+U)x = b$ is found in\nFigure~\\ref{fig:serial-solve}.\n\\begin{figure}\n\\caption{Serial forward and back solve}\n\\label{fig:serial-solve}\n\\begin{center}\n\\begin{minipage}{3.5 in}\n\\begin{tabbing}\nXXX\\=XXX\\=XXX\\=XXX\\=XXX\\=\\kill\nfor $J$ in a post-order traversal \\\\\n\\> for $\\bfj \\in J_e$ in ascending order \\\\\n\\>\\> $y_{\\bfj} = b_{\\bfj}$ \\\\\n\\>\\> $b_{\\bnd{\\bfj}} :=\n      b_{\\bnd{\\bfj}} - L_{\\bnd{\\bfj},\\bfj} y_{\\bfj}$ \\\\\n\\> end for\\\\\nend for\\\\\nfor $J$ in a pre-order traversal \\\\\n\\> for $\\bfj \\in J_e$ in descending order \\\\\n\\>\\> $y_{\\bfj} := y_{\\bfj} \n        - {\\widehat U}_{\\bfj,\\bnd{\\bfj}} x_{\\bnd{\\bfj}}$ \\\\\n\\>\\> $x_{\\bfj} = D_{\\bfj,\\bfj}^{-1} y_{\\bfj}$ \\\\\n\\> end for\\\\\nend for\n\\end{tabbing}\n\\end{minipage}\n\\end{center}\n\\end{figure}\n\\par\nAs we distribute the forward solve across threads or processors,\nwe see that the right hand side vector $b$ accumulates updates of\nthe form $L_{\\bnd{\\bfj},\\bfj} y_{\\bfj}$ from descendents of $J$.\nSince these updates are made in a distributed fashion, each thread\nor processor needs a copy of $b$, or at least of copy of the\nentries in $b$ that it will interact with.\nThe same holds in a slightly different sense for the backward solve.\nInstead of a vector $b$ that needs to be gathered and accumulated,\nit is a solution vector $x$ that needs to be scattered to threads\nor processors that need it.\n\\par\nA well designed map of fronts to threads or processors will no\ndoubt take advantage of locality within the front tree, e.g.,\na subtree-subcube map.\nIn these cases, the entries that {\\it active} on a thread or\nprocessor will be a fraction of the total entries.\nIt thus pays to take have local vectors $b^q$ and $x^q$ for thread $q$.\nThese vectors should contain only those entries that are active\non thread $q$.\nThis is particularly important when we are solving several right\nhand sides at once.\n\\par\nFigure~\\ref{fig:parallel-solve} describes the\nthe parallel solve $(I+L)(D+U)x = b$ as done by thread $q$.\n\\begin{figure}\n\\caption{Parallel forward and back solve}\n\\label{fig:parallel-solve}\n\\begin{center}\n\\begin{minipage}{3.5 in}\n\\begin{tabbing}\nXXX\\=XXX\\=XXX\\=XXX\\=XXX\\=\\kill\nfor $J$ in a post-order traversal \\\\\n\\> if  $J$ owned by $q$ then \\\\\n\\>\\> gather $b_{J_e} = \\sum_r b_{J_e}^r$ \\\\\n\\>\\> for $\\bfj \\in J_e$ in ascending order \\\\\n\\>\\>\\> $y_{\\bfj} = b_{\\bfj}$ \\\\\n\\>\\>\\> $b^q_{\\bnd{\\bfj}} :=\n      b^q_{\\bnd{\\bfj}} - L_{\\bnd{\\bfj},\\bfj} y_{\\bfj}$ \\\\\n\\>\\> end for\\\\\n\\> else if $b_{J_e}^q \\ne 0$ then \\\\\n\\>\\> communicate $b_{J_e}^q$ to $b_{J_e}$ somehow \\\\\n\\> end if\\\\\nend for\\\\\nfor $J$ in a pre-order traversal \\\\\n\\> if  $J$ owned by $q$ then \\\\\n\\>\\> for $\\bfj \\in J_e$ in descending order \\\\\n\\>\\>\\> $y_{\\bfj} := y_{\\bfj} \n        - {\\widehat U}_{\\bfj,\\bnd{\\bfj}} x^q_{\\bnd{\\bfj}}$ \\\\\n\\>\\>\\> $x_{\\bfj} = D_{\\bfj,\\bfj}^{-1} y_{\\bfj}$ \\\\\n\\>\\> end for\\\\\n\\>\\> store $x_{J_e}$ in $x^q_{J_e}$ \\\\\n\\>\\> communicate $x_{J_e}$ to those who need it \\\\\n\\> else if $x_{J_e}$ needed by thread $q$ then \\\\\n\\>\\> obtain $x_{J_e}$ and store in $x^q_{J_e}$ \\\\\n\\> end if \\\\\nend for\n\\end{tabbing}\n\\end{minipage}\n\\end{center}\n\\end{figure}\n\\par\nThe interplay between local and global information can take many\nforms.\nIn our present threaded solves there are global right hand side and\nsolution vectors that are protected by locks.\nIn the MPI version explicit messages will communicate information\namong the processors.\n", "meta": {"hexsha": "3adc7c2f4a8a571a0ccd664b8cd099d925c75447", "size": 27726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ccx_prool/SPOOLES.2.2/documentation/ReferenceManual/algorithmDesign.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/ReferenceManual/algorithmDesign.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/ReferenceManual/algorithmDesign.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": 34.4422360248, "max_line_length": 79, "alphanum_fraction": 0.6669912717, "num_tokens": 10425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6568824267951741}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n\n\\chapter{The Theory of FDTD}\n\\section{Yee Cell}\nMaxwell's equations are a set of equations which can be written in differential form or integral form. They are the foundation of macroscopic electromagnetic phenomenas. There are two kinds of numerical solver to Maxwell's equation. One kind of solvers were developed from integral form of Maxwell's equations, called integral equation solvers, including MoM, BEM etc. Another kind of solvers, like FDTD and FEM, were developed from differential form of Maxwell's equations, called differential equation solvers.\n\nFDTD is based on Maxwell's equations in differential form, which are shown as follows. Then Maxwell's equations are modified by discretized in central-difference way.\n\\begin{equation}\\label{ch2 eq:maxwellH}\n\\nabla\\times\\mathbf{\\mathit{H}}=\\frac{\\partial \\mathbb{\\mathit{D}}}{\\partial t}+\\mathbf{\\mathit{J}},\n\\end{equation}\n\\begin{equation}\\label{ch2 eq:maxwellE}\n\\nabla\\times\\mathbf{\\mathit{E}}=-\\frac{\\partial \\mathbb{\\mathit{B}}}{\\partial t}-\\mathbf{\\mathit{J}}_m.\n\\end{equation}\n\n%各向同性线性介质中的本构关系为\n%\\begin{equation}\\label{bengouguanxi}\n%\\begin{cases}\n%\\mathbf{\\mathit{D}}&=\\varepsilon\\mathbf{\\mathit{E}}\\\\\n%\\mathbf{\\mathit{B}}&=\\mu\\mathbf{\\mathit{H}}\\\\\n%\\mathbf{\\mathit{J}}&=\\sigma\\mathbf{\\mathit{E}}\\\\\n%\\mathbf{\\mathit{J}}_m&=\\sigma_m \\mathbf{\\mathit{H}}\n%\\end{cases}.\n%\\end{equation}\n%真空中$$\\sigma=0$$，$$\\sigma_m=0$$，以及\n%\\begin{eqnarray*}\n%\\varepsilon=\\varepsilon_0=8.85\\times 10^{-12}F/m\\\\\n%\\mu=\\mu_0=4\\pi\\times 10^{-7}H/m.\n%\\end{eqnarray*}\n\nIn  Cartesian coordinate system，the equation\\eqref{ch2 eq:maxwellH} and \\eqref{ch2 eq:maxwellH} are written in following forms:\n\\begin{equation}\\label{ch2 eq:3dmaxwellE}\n\\begin{cases}\n\\frac{\\partial H_z}{\\partial y}-\\frac{\\partial H_y}{\\partial z}=\\varepsilon\\frac{\\partial E_x}{\\partial t}+\\sigma E_x\\\\\n\\frac{\\partial H_x}{\\partial z}-\\frac{\\partial H_z}{\\partial x}=\\varepsilon\\frac{\\partial E_y}{\\partial t}+\\sigma E_y\\\\\n\\frac{\\partial H_y}{\\partial x}-\\frac{\\partial H_x}{\\partial y}=\\varepsilon\\frac{\\partial E_z}{\\partial t}+\\sigma E_z\n\\end{cases}\n\\end{equation}\n\n\\begin{equation}\\label{ch2 eq:3dmaxwellH}\n\\begin{cases}\n\\frac{\\partial E_z}{\\partial y}-\\frac{\\partial H_y}{\\partial z}=-\\mu\\frac{\\partial H_x}{\\partial t}-\\sigma_m H_x\\\\\n\\frac{\\partial E_x}{\\partial z}-\\frac{\\partial H_z}{\\partial x}=-\\mu\\frac{\\partial H_y}{\\partial t}-\\sigma_m H_y\\\\\n\\frac{\\partial E_y}{\\partial x}-\\frac{\\partial H_x}{\\partial y}=-\\mu\\frac{\\partial H_z}{\\partial t}-\\sigma_m H_z\n\\end{cases}.\n\\end{equation}\n\nThe six equations in \\eqref{ch2 eq:3dmaxwellE} and \\eqref{ch2 eq:3dmaxwellH} are a set of partial differential equations in space-time formulations form which represent each filed vector component. They are hard to deal in that form, so we need to discretize them in space and time at first.Let $u(x,y,z,t)$ represent any field vector component of $\\mathbf{\\mathit{E}}$ or $\\mathbf{\\mathit{H}}$ in Cartesian coordinate system. On the aspect of space, we assume that the discreteness on space is uniform, which means the space steps, also called the lengths of grids, are equal to each other in $x$, $y$, and $z$ directions and written as $\\Delta x$, $\\Delta y$, and $\\Delta z$ respectively. We also use $i$, $j$, and $k$ to represent the grid index in directions of $x$, $y$, and $z$ respectively. On the aspect of time, wo assume the discreteness is uniform, too. Besides, we adopt the symbol $\\Delta t$ to represent the length of time step, which also called the distance between two iterations, and $n$ to represent the index of time steps. After all, we can represent any field vector component in the following notion to indicate the location where the field vector components are sampled in space and time:\n\\begin{equation}\nu(x,y,z,t)=u(i\\Delta x,j\\Delta y,k\\Delta z,n\\Delta t)=u^n(i,j,k).\n\\end{equation}\n\nThere are three forms of finite difference, forward, backward, and central difference, which are considered commonly. Here we pick the central difference as it has second-order numerical accuracy. Let us take the $x$ direction as an example to illustrate a field vector component's spatial first partial derivative:\n\\begin{equation}\\label{ch2 eq:space discrete}\n\\frac{\\partial u^n(i,j,k)}{\\partial x} \\approx \\frac{\n\tu^n(i+\\frac{1}{2},j,k)-u^n(i-\\frac{1}{2},j,k)\n\t}{\\Delta x}.\n\\end{equation}\nAnd the its first partial derivative on time is:\n\\begin{equation}\\label{ch2 eq:time discrete}\n\\frac{\\partial u^n(i,j,k)}{\\partial t} \\approx \\frac{\n\tu^{n+\\frac{1}{2}}(i,j,k)-u^{n-\\frac{1}{2}}(i,j,k)\n}{\\Delta x}.\n\\end{equation}\n\nNow we have discretized the six equations in \\eqref{ch2 eq:3dmaxwellH} and \\eqref{ch2 eq:3dmaxwellE}. The next step we should do is considering how we position those discrete points of every field vector component. The answer is Yee cell.\n\nIn space, we position those discrete points like what illustrated in \\ref{ch2 fig: yee cell}. This is the spatial structure of Yee cell.\n\n\\begin{figure}[hp]\n\\centering\n\t\t\\begin{tikzpicture}\n\t\t\\def \\len {6}\n\t\t\\def \\hlen {3}\n\t\t\\def \\coe {-0.75}\n\t\t\n\t\t%back rectangle wigh dashline\n\t\t\\draw(0,0) rectangle +(\\len,\\len);\n\t\t\\draw [dashed] ($(0,0)+0.5*(0,\\len)$) -- +(\\len,0);\n\t\t\\draw [dashed] ($(0,0)+0.5*(\\len,0)$) -- +(0,\\len);\n\t\t\n\t\t%front rectangle wigh dashline\n\t\t\\draw($(0,0)+\\coe*(\\hlen,\\hlen)$) rectangle +(\\len,\\len);\n\t\t\\draw [dashed] ($(0,0)+(0,\\hlen)+\\coe*(\\hlen,\\hlen)$) -- +(\\len,0);\n\t\t\\draw [dashed] ($(0,0)+(\\hlen,0)+\\coe*(\\hlen,\\hlen)$) -- +(0,\\len);\n\t\t\n\t\t%connect two rectangle\n\t\t\\draw (0,0) -- ($(0,0)+\\coe*(\\hlen,\\hlen)$);\n\t\t\\draw ($(0,0)+(0,\\len)$) -- ($(0,0)+(0,\\len)+\\coe*(\\hlen,\\hlen)$);\n\t\t\\draw ($(0,0)+(\\len,0)$) -- ($(0,0)+(\\len,0)+\\coe*(\\hlen,\\hlen)$);\n\t\t\\draw ($(0,0)+(\\len,\\len)$) -- ($(0,0)+(\\len,\\len)+\\coe*(\\hlen,\\hlen)$);\n\t\t\n\t\t%all dashline\n\t\t\\draw [dashed] ($(0,0)+(0,\\hlen)$) -- ($(0,0)+(0,\\hlen)+\\coe*(\\hlen,\\hlen)$);\n\t\t\\draw [dashed] ($(0,0)+(\\hlen,0)$) -- ($(0,0)+(\\hlen,0)+\\coe*(\\hlen,\\hlen)$);\n\t\t\\draw [dashed] ($(0,0)+(\\len,\\hlen)$) -- ($(0,0)+(\\len,\\hlen)+\\coe*(\\hlen,\\hlen)$);\n\t\t\\draw [dashed] ($(0,0)+(\\hlen,\\len)$) -- ($(0,0)+(\\hlen,\\len)+\\coe*(\\hlen,\\hlen)$);\n\t\t\n\t\t\\draw [dashed] ($(0,0)+0.5*\\coe*(\\hlen,\\hlen)$) -- ++(\\len,0) -- ++(0,\\len) -- ++(-\\len,0) -- cycle;\n\t\t\n\t\t%axis\n\t\t\\draw [->] (0,0) -- +(\\len+2,0) node[right]{$y$};\n\t\t\\draw [->] (0,0) -- +(0,\\len+2) node[above]{$z$};\n\t\t\\draw [->] (0,0) -- +($(0,0)-(\\hlen,\\hlen)$) node[below,left]{$x$};\n\t\t\n\t\t%nodes\n\t\t%Hx\n\t\t\\node[shape=circle,fill=cyan,inner sep=0pt] at (\\hlen,\\hlen) {$H_x$};\n\t\t\\node[shape=circle,fill=cyan,inner sep=0pt] at ($(\\hlen,\\hlen)+\\coe*(\\hlen,\\hlen)$) {$H_x$};\n\t\t%Hz\t\t\n\t\t\\node[shape=circle,fill=cyan,inner sep=0pt] at ($(0,0)+(\\hlen,0)+0.5*\\coe*(\\hlen,\\hlen)$) {$H_z$};\n\t\t\\node[shape=circle,fill=cyan,inner sep=0pt] at ($(0,0)+(\\hlen,0)+0.5*\\coe*(\\hlen,\\hlen)+(0,\\len)$) {$H_z$};\n\t\t%Hy\n\t\t\\node[shape=circle,fill=cyan,inner sep=0pt] at ($(0,0)+(0,\\hlen)+0.5*\\coe*(\\hlen,\\hlen)$) {$H_y$};\n\t\t\\node[shape=circle,fill=cyan,inner sep=0pt] at ($(0,0)+(0,\\hlen)+0.5*\\coe*(\\hlen,\\hlen)+(\\len,0)$) {$H_y$};\n\t\t%Ez\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)$) {$E_z$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+\\coe*(\\hlen,\\hlen)$) {$E_z$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+(\\len,0)$) {$E_z$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+\\coe*(\\hlen,\\hlen)+(\\len,0)$) {$E_z$};\n\t\t%Ex\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+0.5*\\coe*(\\hlen,\\hlen)+(0,\\hlen)$) {$E_x$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+0.5*\\coe*(\\hlen,\\hlen)+(\\len,0)+(0,\\hlen)$) {$E_x$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+0.5*\\coe*(\\hlen,\\hlen)+(0,-\\hlen)$) {$E_x$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(0,\\hlen)+0.5*\\coe*(\\hlen,\\hlen)+(\\len,0)+(0,-\\hlen)$) {$E_x$};\n\t\t%Ey\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(\\hlen,\\hlen)+(0,\\hlen)$) {$E_y$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(\\hlen,\\hlen)+\\coe*(\\hlen,\\hlen)+(0,\\hlen)$) {$E_y$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(\\hlen,\\hlen)+(0,-\\hlen)$) {$E_y$};\n\t\t\\node[shape=circle,fill=pink,inner sep=0pt] at ($(\\hlen,\\hlen)+\\coe*(\\hlen,\\hlen)+(0,-\\hlen)$) {$E_y$};\n\t\t\\end{tikzpicture}\n\\caption{The spatial discrete structure of Yee cell}\\label{ch2 fig: yee cell}\n\\end{figure}\n\nWe can see from the figure \\ref{ch2 fig: yee cell} that in Yee cell each three components of $\\mathbf{\\mathit{E}}$ and $\\mathbf{\\mathit{H}}$ are discretized on the surface. Electric field components $\\mathit{E}_x$, $\\mathit{E}_y$, and $\\mathit{E}_z$ are on the center of edges, and magnetic field components $\\mathit{H}_x$, $\\mathit{H}_y$, and $\\mathit{H}_z$ are on the center of surfaces. In this way, for each electric discrete point there are four magnetic discrete points encircling it. Conversely, for each magnetic discrete point there will be four electric discrete points encircling it. This way of distributing discrete points fit into Faraday's law and Ampere's law in nature. In time aspect, Yee cell adopted the time-stepping manner. For any discrete point in space, the updated value of the electric filed in time is dependent on the stored value of magnetic field of the last time. Iterating the process in a marching-in-time way, we can make an analog to the continuous electromagnetic waves's propagation. \n\nIn summary, Yee cell can describe the interaction between electrics and magnetics naturally. Given a specific problem with specific coefficients, initial state, and boundary condition, we can use FDTD to obtain the distribution of electromagnetic waves in any given transient.\n\nTo indicate the location of discrete points in space and time, we need to give any location of Yee cell a serial number. Here, we follow this rule: in any direction, the serial number of Yee cell's edges is integer, and the serial number of the center of Yee cell's edge is half integer; all time location of electric discrete points are integer, and all time location of magnetic discrete points are half integer. For each field vector component, the serial number in space is illustrated in the following table.\n\n\\begin{table}\n\\caption{The serial number of components of $\\mathbf{\\mathit{E}}$ and $\\mathbf{\\mathit{H}}$ in Yee cell}\n\t\\centering\n\t\\begin{tabular}{ccccc}\n\t\t\\toprule\n\t\t\\multirow{2}{5em}{Field components} & \\multicolumn{3}{c}{The location in space} & \\multirow{2}{6em}{The location in time}\\\\\n\t\t\\cline{2-4}\n\t\t& $x$ & $y$ & $z$ &\\\\\n\t\t\n\t\t\\midrule\n\t\t$E_x$ & $i+\\frac{1}{2}$ & $j$ & $k$ & \\multirow{3}{1em}{$n$}\\\\\n\t\t\\cline{1-4}\n\t\t$E_y$ & $i$ & $j+\\frac{1}{2}$ & $k$ & \\\\\n\t\t\\cline{1-4}\n\t\t$E_z$ & $i$ & $j$ & $k+\\frac{1}{2}$ & \\\\\n\t\t\\cline{1-5}\n\t\t\n\t\t$H_x$ & $i$ & $j+\\frac{1}{2}$ & $k+\\frac{1}{2}$ & \\multirow{3}{3em}{$n+\\frac{1}{2}$}\\\\\n\t\t\\cline{1-4}\n\t\t$H_y$ & $i+\\frac{1}{2}$ & $j$ & $k+\\frac{1}{2}$ & \\\\\n\t\t\\cline{1-4}\n\t\t$H_z$ & $i+\\frac{1}{2}$ & $j+\\frac{1}{2}$ & $k$ & \\\\\t\t\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\\section{The Updating Formulations}\n\nLet us take the \\eqref{ch2 eq:3dmaxwellE} as an example to explain the how to update a field vector component and the updating formulations. According to the \\eqref{ch2 eq:space discrete} and \\eqref{ch2 eq:time discrete}, we change \\eqref{ch2 eq:3dmaxwellH} into the discrete form, which shown below:\n\n\\begin{equation}\\label{ch2 eq:ex discrete}\n\\begin{split}\nE^{n+1}_{x}\\left( i+\\frac{1}{2},j,k \\right)=&CA(m) \\cdot E^{n}_{x}\\left( i+\\frac{1}{2},j,k \\right)+CB(m)\\\\\n{}&\\cdot\\left[\n\\frac{H^{n+\\frac{1}{2}}_{z}\\left(i+\\frac{1}{2},j+\\frac{1}{2},k\\right)-H^{n+\\frac{1}{2}}_{z}\\left(i+\\frac{1}{2},j-\\frac{1}{2},k\\right)}{\\Delta y}\\right.\\\\\n{}&-\n\\left.\\frac{H^{n+\\frac{1}{2}}_{y}\\left(i+\\frac{1}{2},j,k+\\frac{1}{2}\\right)-H^{n+\\frac{1}{2}}_{z}\\left(i+\\frac{1}{2},j,k-\\frac{1}{2}\\right)}{\\Delta z}\n\\right].\n\\end{split}\n\\end{equation}\n\nAnd there has\n\\begin{equation}\nCA(m)=\\frac{\n\t1-\\frac{\\sigma(m)\\Delta t}{2\\varepsilon(m)}\n\t}{\n\t1-\\frac{\\sigma(m)\\Delta t}{2\\varepsilon(m)}\t\n\t},\n\\end{equation}\nand\n\\begin{equation}\nCB(m)=\\frac{\n\t\\frac{\\Delta t}{\\varepsilon(m)}\n}{\n1+\\frac{\\sigma(m)\\Delta t}{2\\varepsilon(m)}\t\n}.\n\\end{equation}\\label{ch2 eq:ex discrete simple}\nWe use $m$ to represent the spatial location the discrete point have which is at the right of equal sign. \n\nTo explain the algorithm in a clear way, we assume all mediums are lossless medium, ie $\\sigma=\\sigma(m)=0$. Hence, there has $CA(m)=1$, and $CB(m)=\\frac{\\Delta t}{\\varepsilon(m)}$. So, now, \\eqref{ch2 eq:ex discrete} is\n\n\\begin{equation}\n\\begin{split}\nE^{n+1}_{x}\\left( i+\\frac{1}{2},j,k \\right)=&E^{n}_{x}\\left( i+\\frac{1}{2},j,k \\right)+\\frac{\\Delta t}{\\varepsilon(m)}\\\\\n{}&\\cdot\\left[\n\\frac{H^{n+\\frac{1}{2}}_{z}\\left(i+\\frac{1}{2},j+\\frac{1}{2},k\\right)-H^{n+\\frac{1}{2}}_{z}\\left(i+\\frac{1}{2},j-\\frac{1}{2},k\\right)}{\\Delta y}\\right.\\\\\n{}&-\n\\left.\\frac{H^{n+\\frac{1}{2}}_{y}\\left(i+\\frac{1}{2},j,k+\\frac{1}{2}\\right)-H^{n+\\frac{1}{2}}_{z}\\left(i+\\frac{1}{2},j,k-\\frac{1}{2}\\right)}{\\Delta z}\n\\right].\n\\end{split}\n\\end{equation}\n\nIn the same way we modified the field vector components of $\\mathbf{\\mathit{H}}$. Let us take the $H_x$ as an example, now the first equation in \\eqref{ch2 eq:3dmaxwellH} is:\n\n\\begin{equation}\\label{ch2 eq:hx discrete simple}\n\\begin{split}\nH^{n+\\frac{1}{2}}_{x}\\left( i,j+\\frac{1}{2},k+\\frac{1}{2} \\right)=&H^{n-\\frac{1}{2}}_{x}\\left( i,j+\\frac{1}{2},k+\\frac{1}{2} \\right)+\\frac{\\Delta t}{\\mu}\\\\\n{}&\\cdot\\left[\n\\frac{\n\tE^n_y\\left(i,j+\\frac{1}{2},k+1\\right)-E^n_y\\left(i,j+\\frac{1}{2},k\\right)\n\t}{\\Delta z}\\right.\\\\\n{}&+\\left.\n\\frac{\n\tE^n_z\\left(i,j,k+\\frac{1}{2}\\right)-E^n_z\\left(i,j+1,k+\\frac{1}{2}\\right)\n}{\\Delta z}\n\\right]\n\\end{split}\n\\end{equation}\nAll other field vector components can be processed in the exactly same way we stated above. Therefore, we obtain each field vector component's discrete form updating formulation.\n\n\\section{Courant Condition}\nAccording to the last section, we know that instead of a set of continuous partial differential equations, FDTD solving a set of discretized Maxwell's equations. So, like other numerical approximate methods, FDTD has a necessary condition for convergence while solving partial differential equations numerically. As a consequence, the time step must be less than a certain time.\n\nAt first, we consider the time step, $\\Delta t$. As any field can be deposited into several harmonic electromagnetic fields, we examine the limitation of $\\Delta t$ in harmonic electromagnetic field.\n\nHere is a harmonic electromagnetic field:\n\\begin{equation}\\label{stability: shi xie chang}\nu(x,y,z,t)=u_0exp(j\\omega t).\n\\end{equation}\nThe first-order partial differential equation of \\eqref{shi xie chang} respect to time is：\n\\begin{equation}\\label{stability: u partial t}\n\\frac{\\partial u}{\\partial t}=j\\omega u.\n\\end{equation}\n\nBy using central difference approximations to the left side of equation \\eqref{stability: u partial t}, we obtain:\n\\begin{equation}\\label{stability: chafen}\n\\frac{u^{n+\\frac{1}{2}}-u^{n-\\frac{1}{2}}}{\\Delta t}=j\\omega u^n,\n\\end{equation}\nIn which $u_n=u(x,y,z,n\\Delta t)$.\n\nLet the growth factor $q$ be:\n\\begin{equation}\\label{stability: q}\n\tq=\\frac{u^{n+\\frac{1}{2}}}{u^n}=\\frac{u^n}{u^{n-\\frac{1}{2}}}.\n\\end{equation}\n\nThen, combining the equation \\eqref{stability: q} and \\eqref{stability: chafen}, we obtain this equation:\n\\begin{equation}\nq^2-j\\omega \\Delta tq-1=0\n\\end{equation}\\label{ch2 eq:temp eq}\n\nSolving the equation \\eqref{ch2 eq:temp eq}, we will have:\n\\begin{equation}\nq=\\frac{j\\omega \\Delta t}{2}\\pm\\sqrt{1-\\left(\\frac{\\omega \\Delta  t}{2}\\right)^2}.\n\\end{equation}\n\nIf we want the value of fields converge along the marching of time, the condition $|q|\\leqslant 1$ must be satisfied. Hence, there is\n\\begin{equation}\\label{ch2 eq:stability: dt}\n\\frac{\\omega \\Delta t}{2}\\leqslant 1.\n\\end{equation}\n\nEquation \\eqref{ch2 eq:stability: dt} is the necessary condition of $\\Delta t$ required by a field which need to be stable.\n\nFor Maxwell's equations, which have six field components, we know that all rectangular components of electromagnetic field fit in the homogeneous wave equation which is following:\n\\begin{equation}\\label{stability: qicibodong}\n\\frac{\\partial^2 f}{\\partial x^2}+\\frac{\\partial^2 f}{\\partial y^2}+\\frac{\\partial^2 f}{\\partial z^2}+\\frac{\\omega^2}{c^2}f=0.\n\\end{equation}\n\nAs any wave can be expanded to plain waves, so we consider the solution of plain waves of homogeneous wave equation:\n\\begin{equation}\\label{stability: pingmianbo}\nu(x,y,z,t)=u_0 exp[-j(k_x x+k_y y+k_z z-\\omega t)].\n\\end{equation}\n\nSubstituting the equation \\eqref{stability: pingmianbo} into \\eqref{stability: qicibodong}, and discretize the result by using central difference, then we obtain the following equations:\n\\begin{equation}\\label{stability: qicibodong lisan}\n\\frac{\\sin^2 \\left( \\frac{k_x\\Delta x}{2} \\right)}{\\left(\\frac{\\Delta x}{2}\\right)^2}+\n\\frac{\\sin^2 \\left( \\frac{k_y\\Delta y}{2} \\right)}{\\left(\\frac{\\Delta y}{2}\\right)^2}+\n\\frac{\\sin^2 \\left( \\frac{k_z\\Delta z}{2} \\right)}{\\left(\\frac{\\Delta z}{2}\\right)^2}-\n\\frac{\\omega^2}{c^2}=0.\n\\end{equation}\nThe $c$ is the speed of light in media among it.\n\nSimplify the equation \\eqref{stability: qicibodong lisan} and substitute it into \\eqref{ch2 eq:stability: dt}. Then we obtain\n\\begin{equation}\n\\left(\\frac{c\\Delta t}{2}\\right)^2\n\\left[\n\\frac{\\sin^2 \\left( \\frac{k_x\\Delta x}{2} \\right)}{\\left(\\frac{\\Delta x}{2}\\right)^2}+\n\\frac{\\sin^2 \\left( \\frac{k_y\\Delta y}{2} \\right)}{\\left(\\frac{\\Delta y}{2}\\right)^2}+\n\\frac{\\sin^2 \\left( \\frac{k_z\\Delta z}{2} \\right)}{\\left(\\frac{\\Delta z}{2}\\right)^2}\n\\right]=\n\\left(\\frac{\\omega\\Delta t}{2}\\right)^2\\leqslant 1.\n\\end{equation}\nThis equation is true under the following condition:\n\\begin{equation}\\label{stability: courant}\nc\\Delta t\\leqslant\n\\frac{1}{\n\t\\sqrt{\\frac{1}{(\\Delta x)^2}\\frac{1}{(\\Delta y)^2}+\\frac{1}{(\\Delta z)^2}}\n\t}.\n\\end{equation}\nThe equation \\eqref{stability: courant} give out the relationship between time step $\\Delta t$ and space step $\\Delta x$, which called courant condition.\n\n\\section{The limitation of $\\Delta x$}\nIn the last section, the relationship between the time step and the space step was been determined. Taking the 1D situation as an instance, from the equation \\eqref{stability: qicibodong lisan} we have:\n\\begin{equation}\n\\frac{\\sin^2 \\left( \\frac{k_x\\Delta x}{2} \\right)}{\\left(\\frac{\\Delta x}{2}\\right)^2}-\n\\frac{\\omega^2}{c^2}=0.\n\\end{equation}\\label{ch2 eq:dispersion}\n\nWe can observe the fact from the equation \\eqref{ch2 eq:dispersion} that the dispersion can be avoided only if $\\Delta x\\rightarrow 0$. So, we need to evaluate to what extent the $\\Delta x$ can be treated as closed to 0 in numerical approximation. According to triangle functions, when $\\phi\\leqslant \\pi/12$, $sin\\phi\\approx\\phi$. So, there has\n\\begin{equation}\\label{stability: space}\n\t\\Delta x\\leqslant \\frac{2\\pi}{12k}=\\frac{\\lambda}{12}.\n\\end{equation}\n\nEquation \\eqref{stability: space} is the requirement for space step $\\Delta x$. For circumstances of 2D or 3D, they are the same as 1D situation, just make space steps of each dimension meet the condition \\eqref{stability: space}. To signals whose band are wide and belong to non-homogeneous waves, make sure the space step meet the requirement \\eqref{stability: space} of the shortest wave length.\n\n\n\\section{Boundary conditions of FDTD}\nIn theory, by following the rules of FDTD we can simulate almost every electromagnetic wave in the infinite space and the length of time is infinite, too. However, as the power of computation is limited, and problems are always have significant big size, we can, and should simulate the the waves in the target area we concerned even in fact those waves are propagating in the infinite space. One possible way to do that is to design boundary conditions properly. Given a problem, we can compute discrete field points which are in the target area to observe how the wave changes in the whole area. There are two kinds of boundary conditions, absorbing boundary conditions (ABC) and truncating boundary conditions (TBC). In reality, people always adopt ABC, which allow them simulate the situation a wave propagating in the infinite space. Among ABCs, Mur and perfectly matched layer (PML) are two main boundary conditions.\n\n\\section{The ways of parallel computing of FDTD}\n\nTo satisfy the Courant condition, the grids of Yee cell must be fine enough, which means the number of discrete field points we need to compute will be significantly massive, therefore, solving a real problem in a big size seems not practical. Parallel computing, as to this problem, is a quite efficient solution.\n\nThere are three level of parallelism. The top level is task level. In this level, a huge task need to be completed is divided into several independent smaller tasks. After those smaller tasks computed by some computing cores, we merge the solutions of those smaller tasks into a integral solution, which answers the original task. According to the parallelism nature of FDTD, that all computing cores need exchange some boundary data with its adjacent computing cores, FDTD is suitable to be computed in parallel computing. So far, we have massage passing interface (MPI) method and parallel virtual machine (PVM) method of this parallelism level.\n\nThe lower level of parallelism is instruction level parallelism. This level of parallelism always considered by CPU manufacturers, hardly by users.\n\nThe lowest level of parallelism if data level. In this level, several data can be evaluated by one instruction simultaneously if a task have been reorganized appropriately. In FDTD, as all discrete field points of the same field vector component have a shared updating formulation, we can compute several discrete field points by every single instruction when those points belong to the same field vector component. For parallelism in this level, there are some implementations of FDTD by using vector processor instruction sets.\n\n\\section{Conclusion}\nIn this chapter, de discussed several aspects of FDTD. First, we introduce the theories of FDTD algorithm. Then we describe the updating formulations for every field vector components, which are the key of FDTD. After that, the necessary condition, Courant condition was stated. Satisfying this condition make sure all field vector components keep stable and being convergent, which make FDTD useful in reality. Then we discussed the boundary conditions of FDTD, which influence the accuracy of FDTD. Finally, we introduced several ways of parallel computing to make FDTD faster. All things we discussed above in this chapter are the foundations of the works in this paper.", "meta": {"hexsha": "47ba941c2a9b8dc17dc11ccdc1d14cb4674c711c", "size": 22593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "latex-en/chapters/chapter2.tex", "max_stars_repo_name": "obserthinker/bachelorgraduatethesis", "max_stars_repo_head_hexsha": "445351447c95a48b5f8af4b1081c3dcf0018045c", "max_stars_repo_licenses": ["MIT"], "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-en/chapters/chapter2.tex", "max_issues_repo_name": "obserthinker/bachelorgraduatethesis", "max_issues_repo_head_hexsha": "445351447c95a48b5f8af4b1081c3dcf0018045c", "max_issues_repo_licenses": ["MIT"], "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-en/chapters/chapter2.tex", "max_forks_repo_name": "obserthinker/bachelorgraduatethesis", "max_forks_repo_head_hexsha": "445351447c95a48b5f8af4b1081c3dcf0018045c", "max_forks_repo_licenses": ["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.6460176991, "max_line_length": 1212, "alphanum_fraction": 0.7022086487, "num_tokens": 7355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6568824143254244}}
{"text": "\\section{Introduction}\n\nOne of the important scientific computing problems is computing the real roots\nof polynomials. It has wide applications in computer graphics. For the\npolynomials with low order, like quadratic or cubic, we can use formulas to get\nroots directly. However, according to the Abel–Ruffini theorem, there is no\nsolution in radicals to general polynomial equations of five degrees or higher\nwith arbitrary coefficients\\cite{Abel-Ruffini}.\n\nThere are a lot of algorithms to find the real roots of polynomials. Although\nmost root-finding algorithms, Newton’s method for example, may produce some real\nroots, the convergence of algorithms are not guaranteed. Furthermore, these\nmethods cannot generally certify having found all real roots. Which means if\nsuch methods do not find any root, one cannot know if there are real roots or\nnot. Moreover, there are some cases where one does not need the exact roots of\npolynomial equations. Take ray tracing as an example. When computing the\ndistance from intersection point to ray’s end point, the object with smallest\ndistance is important to us, instead of exact distance to point of intersection.\nIn these cases, computing exact roots is not very essential.\n\nReal-root isolation is an appropriate method for the above problems. It will\ngenerate a sequence of disjoint intervals. Each interval contains only one real\nroot of the polynomial. And combining these intervals together, all real roots\ncould be found. Besides that, isolating the roots instead of computing them out\nmight speed up the cases that do not need exact roots, as mentioned above. \n\nThis project aims to implement a real-root isolation program based on Budan’s\ntheorem and continued fraction. These two methods are based on Descartes’ rule\nof signs, which describes how to get information on the number of positive real\nroots of a polynomial and first introduced by René Descartes\\cite{rule_of_sign}. Budan’s theorem,\ndeveloped from Descartes’ rule of signs, provides the methods to bound the\nnumber of real roots of a polynomial in an interval\\cite{Budan}. Vincent introduced the\ncontinued fraction method in his work in 1834\\cite{Vincent}. Both methods work only on\nsquare-free polynomials. Therefore, this project takes Yun’s algorithm to\nperform square free decomposition\\cite{Yuns}.\n\nThe organization of this report is as follows. Section \\ref{methods} will introduce the\ntheory basis of this project. Section \\ref{implementation} describes how the program implemented\nand what have been tried to optimize. Running time comparison and analysis of\nhow error propagation through computation will be discussed in Section\n\\ref{analysis}. Finally, a conclusion is drawn in Section \\ref{conclusion}.\n", "meta": {"hexsha": "5256449bb0a3dced10b12d75e1ca2a2d34e2c5af", "size": 2730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/020introduction.tex", "max_stars_repo_name": "willyii/PolynomialRootFinding", "max_stars_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/020introduction.tex", "max_issues_repo_name": "willyii/PolynomialRootFinding", "max_issues_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-13T00:53:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-13T00:53:54.000Z", "max_forks_repo_path": "report/020introduction.tex", "max_forks_repo_name": "willyii/PolynomialRootFinding", "max_forks_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-13T12:54:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T12:54:48.000Z", "avg_line_length": 65.0, "max_line_length": 97, "alphanum_fraction": 0.8142857143, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660687, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.6568824075756327}}
{"text": "% ------------------------------------------------------ %\n%  BIOE60011 Probability and Statistics For Bioengineers %\n%  Formula Booklet for Practice and Exams %\n% ----------------------------------------------------- %\n% Author: \n%           Binghuan Li  <binghuan.li19@imperial.ac.uk>, \n%           Peter Xie    <peter.xie19@imperial.ac.uk>\n% ------------------------------------------------------ %\n%  Reviewer: \n%           Zhuang Liu, Bishr Al-Badri, \n%           Eliott Stoclet, Rea Tresa\n% ------------------------------------------------------ %\n%  Update Date: 29th December 2021  %\n% ------------------------------------------------------ %\n%  Graph credentials by Dr Joseph van Batenburg-Sherwood %\n% ------------------------------------------------------ %\n% This work is licensed under a Creative Commons Attribution 4.0 International License %\n% ------------------------------------------------------ %\n\n% keep the font size by default\n\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% set font \n\\usepackage[sfdefault]{arimo} \n\n% set page margin\n\\usepackage[top=2cm, bottom=1cm, left=2cm, right=2cm]{geometry}\n\n% set math env\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{mathrsfs} \n\\usepackage{mathtools} \n\\usepackage{amssymb}\n\\usepackage{changepage}\n% set graphics env\n\\usepackage{float}\n\\usepackage{graphics}\n\n% table scaling\n\\usepackage{adjustbox}\n\n% write pdf info\n\\usepackage{hyperref}\n%\\hypersetup{hidelinks}\n\\hypersetup{pdfauthor={Li, Binghuan},\n            pdftitle={Probs-and-Stats, Formula Sheet},\n            pdfsubject={last update date: \\today},\n            }\n            \n% env to insert external pdf \n\\usepackage{pdfpages}\n\n\\usepackage{booktabs}\n\n\\usepackage{framed}\n\n% set section title size\n\\usepackage{titlesec}\n\\titleformat*{\\section}{\\large\\bfseries}\n\\titleformat*{\\subsection}{\\normalsize\\bfseries}\n\n% caption setting env\n\\usepackage{caption}\n\\captionsetup[table]{labelformat=empty}\n\n% set header/footer\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\lhead{\\textit{Probability and Statistics for Bioengieering - Formula Sheet}}\n\\rhead{\\thepage}\n\n%% start the doc!\n\\begin{document}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Mean, Median and Standard Deviation}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{adjustbox}{width=\\columnwidth,center}\n    \\begin{tabular}{c| c| c | c}\n        Mean & Median & Standard Deviation & MAD\\\\ [0.7ex] \\hline \n        $\\displaystyle \\bar{x}=\\frac{1}{n}\\sum_{i=1}^{n}x_{i} = \\frac{x_{1}+x_{2}+...+x_{n}}{n}$ & \n        $\\Tilde{x} = \\begin{cases} \n        x(\\frac{n+1}{2}) \\\\\n        0.5(x(\\frac{n}{2})+x(\\frac{n}{2}+1)) \n        \\end{cases}$ &\n        $\\displaystyle s = \\sqrt{\\frac{1}{n-1}\\sum_{i=1}^{n} (x_{i}-\\bar{x})^{2}}$\n        & $\\displaystyle MAD = k|\\widetilde{x_{i} - \\hat{x}}|$ \\\\\n          &  &  &  $k = 1.4826$\\\\\n    \\end{tabular}\n    \\end{adjustbox}\n\\end{table}\n\n\\begin{itemize}\n    \\item[-] $s$, $s^{2}$ and $\\bar{x}$ denote \\underline{sample} S.D., variance and mean.\n    \\item[-] $\\sigma$, $\\sigma^{2}$ and $\\mu$ denote \\underline{population} S.D., variance and mean (expected value).\\\\\n    \n    \\item[-] \\textbf{Trimmed Mean at $p\\%$} - Remove p/2 percentile from both ends of the data and calculate the mean\n    \\item[-] \\textbf{Standard Error on the mean} - \n    $\\displaystyle S_{\\bar{X}} = \\frac{S_{X}}{\\sqrt{n}}$, where $n$ is the sample size, $S_{X}$ is the standard deviation\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Probability Theory}\n\\subsection*{Set Theory}\n\\begin{table}[H]\n    \\centering\n    \\begin{adjustbox}{width=\\columnwidth,center}\n    \\begin{tabular}{c| c| c |c}  \n        Union & Intersection & Complement & Relative Complement\\\\ [0.7ex] \\hline \\vspace{1ex}\n       A \\underline{OR} B & A \\underline{AND} B & \\underline{NOT} A & A \\underline{AND} \\underline{NOT} B \\\\\n       \\includegraphics[width=0.2\\textwidth]{./images/AorB.pdf}&\\includegraphics[width=0.2\\textwidth]{./images/AandB.pdf}&\\includegraphics[width=0.2\\textwidth]{./images/notA.pdf}&\\includegraphics[width=0.2\\textwidth]{./images/Aand_notB.pdf}\\\\\n       $P(A\\cup B) = P(A)+P(B)-P(A\\cap B)$ &&$P(A') = 1 - P(A)$ &\n    \\end{tabular}\n    \\end{adjustbox}\n\\end{table}\n\n%%\n\\subsection*{Counting}\n\\begin{itemize}\n\\item Product Rule - $\\displaystyle n = n_{1}\\times n_{2}\\times n_{3}\\times...\\times n_{k}$\n    \\item Permutations: Ordered, dependent selections (without replacement) -\n    $\\displaystyle P_{k,n} = \\frac{n!}{(n-k)!}$\n    \\item Combinations: Unordered selections (without replacement) - \n    $\\displaystyle C_{k,n} = \\frac{P_{k,n}}{k!} = {n \\choose k} = \\frac{n!}{k!(n-k)!}$\n\\end{itemize}\n\n%%\n\\subsection*{Conditional Probability}\n\\begin{itemize}\n    \\item Conditional probability: knowing that A has happened, the probability of B given A - $\\displaystyle P(B|A) = \\frac{P(B \\cap A)}{P(A)}$\n    \\item Bayes Theorem - $\\displaystyle P(A_{j}|B) = \\frac{P(B|A_{j})P(A_{j})}{\\sum_{i=1}^{k}P(B|A_{i})P(A_{i})} $\\\\\\\\\n    (Applies if events A are mutually exclusive and exhaustive (defines the whole set)).\n\\end{itemize}\n\n%%\n\\subsection*{Independence}\n\\begin{itemize}\n    \\item Independent: event A is unaffected by event B\n    \\[P(A|B) = P(A), \\quad\\quad P(B|A) = P(B), \\quad\\quad P(A\\cap B)=P(A)P(B)\\]\n\\end{itemize}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Probability Distributions and Discrete Random Variables}\n\\subsection*{Binomial and Poisson Distribution}\n\\begin{minipage}{.8\\textwidth}\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{l c c}  \n        & Binomial Distribution & Poisson Distribution\\\\ [0.7ex] \\hline \\vspace{1ex}\n        Probability Density Function & $ \\displaystyle b(x;n,p) ={ n \\choose x} p^{x}(1-p)^{n-x}$  & $\\displaystyle po(x,\\lambda) = \\frac{e^{-\\lambda}\\lambda^{x}}{x!}$  \\\\ [0.5ex]\n        Expected Value, $E(x)$ & $E(x) = np$ & $E(x) = \\lambda$\\\\ [0.5ex] \n        Variance, $V(x)$ & $\\displaystyle V(x) = np(1-p) = npq$ & $\\displaystyle V(x) = \\lambda(1-\\frac{\\lambda}{n})$  \\\\ [0.5ex] \n    \\end{tabular}\n\\end{table}\n\\end{minipage}\n\\begin{minipage}{.2\\textwidth}\n\\begin{framed}\nNote: \\\\\\\\\n$V(x)$ can also be expressed as $V(x)=E(x^{2})-(E(x))^{2}$.    \n\\end{framed}\n\n\\end{minipage}\n\n%%\n\\subsection*{Discrete Random Variables}\n% \\begin{adjustwidth}{-100pt}{-100pt}\n\\begin{table}[H]\n    \\centering\n    \\begin{adjustbox}{width=\\columnwidth,center}\n    \\begin{tabular}{c| c| c}  \n        Bernoulli RV & Expected Value & Variance\\\\ [1.0ex] \\hline \n        $p(x;\\alpha) = \\begin{cases}\n        1-\\alpha, & if \\ x=0 \\\\\n        \\alpha, & if \\ x=1\\\\\n        0, & otherwise\n        \\end{cases}$\n        &\n        $\\displaystyle E(x)=\\mu_{X}=\\sum_{x\\in D}xp(x)$\n        &\n        $\\displaystyle V(X) = \\sigma_{X}^{2}=\\sum_{x\\in D}(x-\\mu_{X})^{2}p(x)=E[(X-\\mu_{X})^{2}]$\n    \\end{tabular}\n    \\end{adjustbox}\n\\end{table}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Continuous Random Variables and Joint Probability}\n\\subsection*{Random Variables}\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{|l|c|}\n    \\hline\n     \\addlinespace[.3ex] Probability density function & $\\displaystyle P(a \\leq X \\leq b) = \\int_{a}^{b}f(x)dx$ \\\\ [.5ex] \\hline\n    \\addlinespace[.3ex] Cumulative distribution function & $\\displaystyle F(x) = P(X\\leq x) = \\int_{-\\infty}^{x} f(y)dy \\  \\text{and} \\ \\int_{-\\infty}^{+\\infty} f(x)dx = 1$ \\\\ [.5ex] \\hline\n    \\addlinespace[.3ex] Expected value & $\\displaystyle \\mu_{X} = E(X) = \\int_{-\\infty}^{+\\infty} xf(x) dx$ \\\\ [.5ex] \\hline \n    \\addlinespace[.3ex] Variance & $\\displaystyle \\sigma_{X}^{2} = V(X) = \\int_{-\\infty}^{+\\infty} (x-\\mu)^{2}f(x) dx$ \\\\ [.3ex] \\hline\n    \\end{tabular}\n\\end{table}\n\n\\subsection*{Joint Probability Distributions}\n\\begin{itemize}\n    \\item Discrete Joint random variables\n    \\begin{table}[H]\n    \\centering\n    % \\begin{adjustbox}{width=\\columnwidth,center}\n    \\begin{tabular}{c| c| c}  \n        Joint probability mass function (PMF) & Expected Value & Marginal PMFs\\\\ [0.7ex] \\hline \n        \\addlinespace[.4ex] $p(x,y)=P(X=x$ and $Y=y)$ \n        & \n        $\\displaystyle E[h(X,Y)]=\\sum_{X}\\sum_{Y}h(x,y)p(x,y)$\n        &\n        $P_{X}(x)=\\sum_{y}p(x,y)$\\\\ \n        \n        $\\sum_{x}\\sum_{y}p(x,y)=1$\n        &\n        &\n        $P_{Y}(y)=\\sum_{x}p(x,y)$\\\\ \n    \\end{tabular}\n\\end{table}\n\n    \\item Continuous Joint random variables\n    \\begin{table}[H]\n    \\centering\n   \\begin{adjustbox}{width=\\columnwidth,center}\n    \\begin{tabular}{c| c| c}  \n        Joint probability mass function (PDF) & Expected Value & Marginal PDFs\\\\ [0.7ex] \\hline \n        \\addlinespace[.4ex] $\\displaystyle P[(X,Y)\\in A]=\\int\\int_{A} f(x,y) dx dy$\n        &\n        $\\displaystyle E[h(X,Y)]=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}h(x,y)f(x,y)dx dy$\n        & \n        $\\displaystyle f_{X}(x)=\\int_{-\\infty}^{+\\infty} f(x,y)dy$ \\\\ [2ex]\n        \n        &\n        $\\displaystyle P[a\\leq X\\leq b, c \\leq Y \\leq d]=\\int_{c}^{d}\\int_{a}^{b}f(x,y)dx dy$\n        & \n        $\\displaystyle f_{Y}(y)=\\int_{-\\infty}^{+\\infty} f(x,y)dx$\n    \\end{tabular}\n    \\end{adjustbox}\n\\end{table}\n\\end{itemize}\n\n\\vspace{-1cm}\n\\subsection*{Independence}\n$X$ and $Y$ are independent if for every pair $x, y$:\n\\begin{itemize}\n    \\item Discrete: \\quad $p(x,y) = p_{x}(x)p_{y}(y)$\n    \\item Continuous: \\quad $f(x,y) = f_{x}(x)f_{y}(y)$\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Normal Distribution}\n\n\\begin{minipage}{0.7\\textwidth}\n\\begin{itemize}\n    \\item Probability Density Function (pdf):\\[f(x) = \\frac{1}{\\sqrt{2\\pi \\sigma^{2}}}e^{-\\frac{(x-\\mu)^{2}}{2\\sigma^{2}}}\\]\n    \\item Cumulative Distribution Function (cdf): \\[F(X) = \\frac{1}{2}\\bigg[ 1+ \\text{erf}\\bigg( \\frac{x-\\mu}{\\sqrt{2\\sigma^{2}}} \\bigg) \\bigg]\\]\n    where \\[\\text{erf}(x) = \\frac{2}{\\sqrt{\\pi}} \\int_{0}^{x} e^{-t^{2}}dt\\]\n\\end{itemize}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.3\\textwidth}\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{l c}\\hline\n        Discrete & Continuous \\\\ \\hline\n        $X=A$ & $A-0.5 < Y < A+0.5$\\\\ \n        $X\\leq A$ & $Y<A+0.5$\\\\ \n        $X<A$ & $Y<A-0.5$ \\\\\n        $X\\geq A$ & $Y>A-0.5$ \\\\\n        $X>A$ & $Y>A+0.5$ \\\\\n    \\end{tabular}\\caption{Continuity Correction - Normal approximation of discrete distributions (e.g. Binomial)}\n\\end{table}\n\\end{minipage}\n\n%%\n\\subsection*{Standard Normal Distribution}\nStandard normal distribution is a special case of normal distribution with $\\mu = 0$ and $\\sigma =1$.\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{c|c}\n        Probability Density Function (PDF) &  \n        Cumulative Distribution Function (CDF)\\\\ \\hline\n        $\\displaystyle f(Z) = \\frac{1}{\\sqrt{2\\pi }}e^{-\\frac{z^{2}}{2}}$ & \n        $\\displaystyle \\Phi(z) = F(Z) = \\frac{1}{2}\\bigg[ 1+ \\text{erf}\\bigg( \\frac{z}{\\sqrt{2}} \\bigg) \\bigg]$ and \\ $\\displaystyle Z = \\frac{X-\\mu}{\\sigma}$\n    \\end{tabular}\n\\end{table}\n\n\n%%\n\\subsection*{Central Limit Theorem}\nFor sufficiently large n:\n\\begin{itemize}\n    \\item Mean sample mean is the population mean - $\\displaystyle E[\\bar{X}] = \\mu_{\\bar{X}} = \\mu$\n    \\item Sample mean variance decreases as sample size increase - $\\displaystyle  V[\\bar{X}] = \\sigma_{\\bar{X}}^{2} = \\frac{\\sigma^{2}}{n}$\n    \\item Standard error on the mean (SEM) is the SD of sample means - $\\displaystyle \\sigma_{\\bar{X}} = \\frac{\\sigma}{\\sqrt{n}}$\n\\end{itemize}\n\n%%\n\\subsection*{Margin of Error, Confidence Intervals}\nUnknown $\\sigma$, large $n$.\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{c|c}\n        Confidence interval (CI) &  \n        Margin of Error (ME)\\\\ \\hline\n        $\\displaystyle CI = \\bar{X} [\\bar{X_{l}}, \\bar{X_{u}}] \\ =\\  \\bigg[\\bar{X}-Z_{\\frac{\\alpha}{2}}\\frac{\\sigma}{\\sqrt{n}},\\ \\bar{X}+Z_{\\frac{\\alpha}{2}}\\frac{\\sigma}{\\sqrt{n}}\\bigg]$ & \n        $\\displaystyle ME = \\bar{X}\\pm ME_{\\bar{X}} = \\lvert Z_{\\frac{\\alpha}{2}} \\rvert \\frac{\\sigma}{\\sqrt{n}}$\n    \\end{tabular}\n\\end{table}\n\n%%\n\\subsection*{$t$-distribution}\nUnknown $\\sigma$, small n. Test statistic - $\\displaystyle T=\\frac{\\bar{X}-\\mu}{S/\\sqrt{n}}$.\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{c|c}\n        Confidence interval (CI) &  \n        Margin of Error (ME)\\\\ \\hline\n        $\\displaystyle CI = \\bar{X} [\\bar{X_{l}}, \\bar{X_{u}}] \\ =\\  \\bigg[\\bar{X}-t_{\\lvert{\\frac{\\alpha}{2},n-1} \\rvert}\\frac{s}{\\sqrt{n}},\\ \\bar{X}+t_{\\lvert{\\frac{\\alpha}{2},n-1}\\rvert}\\frac{s}{\\sqrt{n}}\\bigg]$ & \n        $\\displaystyle ME = \\bar{X}\\pm ME_{\\bar{X}} = \\lvert Z_{\\frac{\\alpha}{2},n-1} \\rvert \\frac{s}{\\sqrt{n}}$\n    \\end{tabular}\n\\end{table}\n%%\n\\subsection*{$\\chi^{2}$-distribution and $F$-distribution}\n\\begin{itemize}\n    \\item $\\chi^{2}$-distribution is obtained by squaring normal distribution.\n    \\item For $n$ observations with unknown $\\mu$ and $\\sigma$, test statistic - $\\displaystyle \\frac{(n-1)S^{2}}{\\sigma^{2}} $\n\n    \\item $F$-statistic is the ratio of two variances (see ANOVA).\\[F(\\nu_{1}, \\nu_{2}) = \\chi_{1}^{2}(\\nu_{1})/ \\chi_{2}^{2}(\\nu_{2})\\]\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\newpage\n\\section{Hypothesis Testing}\n%%\n\\subsection*{NHST Types of Errors}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{table}[H]\n    \\begin{tabular}{|c|c|c|}\\hline\n        $\\mathbf{H_{0}}$ & \\textbf{True} & \\textbf{False} \\\\\\hline\n        \\textbf{Do not reject} & True negative, $1-\\alpha$ & False negative, $\\beta$\\\\ \\hline\n        \\textbf{Reject} & False positive, $\\alpha$ & True positive, $1-\\beta$\\\\ \\hline\n    \\end{tabular}\n\\end{table}\n\\end{minipage} \\hfill\n\\begin{minipage}{0.45\\textwidth} \\vspace{.2cm}\n\\begin{itemize}\n    \\item $\\alpha$ denotes the probability of type I error.\n    \\item $\\beta$ denotes the probability of type II error.\n\\end{itemize}\n\\end{minipage}\n\n\\subsection*{$z$-test \\& $t$-test}\n\\begin{itemize}\n\\item Assumptions:\n    \\begin{itemize}\n        \\item{Data are sampled from a normal distribution. Often lognormal distribution is more appropriate (Use SW or AD test to confirm)}\n        \\end{itemize}\n    \\item Null Hypothesis $H_{0}$: \\begin{itemize}\n        \\item one sample: no differences between the means and a population mean.\n        \\item two sample: no differences between the two sample means. \n        \\item p-value is an estimate of the probability of getting a test-statistic more extreme. Reject $H_{0}$ if $p \\leq \\alpha$.\n    \\end{itemize}\n\\end{itemize}\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{l | c | c}\\hline \n    & Expression & Notes \\\\ \\hline\n    $z$-test statistic &   $ \\displaystyle Z = \\frac{\\bar{X}-\\mu}{\\sigma / \\sqrt{n}}$ & $\\displaystyle \\frac{\\text{effect}}{\\text{error}}$, same below \\\\ [1.2em] \\hline\n    \n    $t$-test one-sample statistic &   $ \\displaystyle T = \\frac{\\bar{X}_{B}-\\mu_{A}}{s_{B}/\\sqrt{n}}$ & $v = n-1$\\\\ [1.2em] \\hline \n    \n    $t$-test two-sample statistic &   $ \\displaystyle T = \\frac{\\bar{X}_{B}-\\bar{X}_{A}}{\\sqrt{\\frac{S_{A}^{2}}{n_{A}}+\\frac{S_{B}^{2}}{n_{B}}}}$ & assume similar variances, $v = n_{A}+n_{B}-2$\\\\ [1.5em] \\hline \n    \n    Welch-Satterthwaite Equation  & $\\displaystyle \\nu = \\frac{(s_{\\bar{X}_{1}}^{2}+s_{\\bar{X}_{2}}^{2})^{2}}{\\frac{s_{\\bar{X}_{1}}^{4}}{n_{1}-1}+ \\frac{s_{\\bar{X}_{2}}^{4}}{n_{2}-1}}$ & $s_{\\bar{X}_{1}}^{2} = \\frac{s_{1}^{2}}{n_{1}}, \\quad s_{\\bar{X}_{2}}^{2} = \\frac{s_{2}^{2}}{n_{2}}$\n    \\end{tabular}\n\\end{table} \n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.75\\textwidth]{./images/zTest_and_tTest.pdf}\n\\end{figure}\n\n%% \n\\vspace{-2cm}\n\\subsection*{ANOVA}\nAssumptions:\n\\begin{itemize}\n\\item{Data are sampled from a normal distribution. Often lognormal distribution is more appropriate (Use SW or AD test to confirm)}\n\\item{All groups have similar variance (homoscedastic) (Use Levene’s or Bartlett’s test to confirm)}\n\\item{Hypothesis $H_{0}$: no differences between the means of any of the groups}\n\\end{itemize}\n%%\n\\subsection*{One-way ANOVA}\n\\begin{itemize}\n    \\item Sample means and grand mean: \n        \\begin{table}[H]\n        \\centering\n        \\begin{tabular}{c|c}\n        Sample Means & Grand Mean \\\\ \\hline\n        $\\displaystyle \\bar{X}_{i} = \\frac{1}{J} \\sum_{j=1}^{J}X_{i, j}$\n        & \n        $\\displaystyle \\bar{X} = \n        \\frac{1}{N}\\sum^{I}_{i=1}\\sum^{J}_{j=1}X_{i,j} = \\frac{1}{I}\\sum_{i=1}^{I}\\bar{X}_{i}$\\\\\n         \\end{tabular}\n        \\end{table}\n        \\begin{itemize}\n            \\item $I$ denotes the number of groups\n            \\item $J_{i}$ denotes the number of observations for a given group. \n            \\item $N$ is the total number of observations, $N = \\sum_{i=1}^{I}J_{i}$.\n            \\item $X_{i,j}$ is a random variable that denotes the $j^{th}$ observation from the $i^{th}$ group.\n        \\end{itemize}\n        \n    \\item Sums of Squares: $SS_{T} = SS_{R}+SS_{M}$\n        \\begin{table}[H]\n        \\centering\n        \\begin{tabular}{c|c|c|c}\n        & Sum of Squares & DoF & Notes \\\\ \\hline\n        Total & $\\displaystyle SS_{T} = \\sum_{i=1}^{I}\\sum_{j=1}^{J_{i}}(X_{i,j}-\\bar{X})^{2}=(N-1)S_{grand}^{2}$ & $\\displaystyle \\nu_{T}=N-1$ & $\\displaystyle S^{2}_{grand} = \\frac{1}{N-1}\\sum^{I}_{i=1}\\sum_{j=1}^{J_{i}}(X_{i,j}-\\bar{X})^{2} $\\\\ \\hline\n\n        Model & $\\displaystyle SS_{M} = \\sum^{I}_{i=1}J_{i}(\\bar{X}_{i}-\\bar{X})^{2}$ & $\\displaystyle \\nu_{M}=I-1$\\\\ \\hline\n         \n        Residuals & $\\displaystyle SS_{R} = \\sum_{i=1}^{I}\\sum_{j=1}^{J_{i}}(X_{i,j}-\\bar{X}_{i})^{2}=\\sum_{i=1}^{I}S_{i}^{2}(J_{i}-1)$ & $\\displaystyle \\nu_{R} = N-I$ & $\\displaystyle S_{i}^{2} = \\frac{\\sum_{j=1}^{J_{i}}(X_{i,j}-\\bar{X}_{i})^{2}}{J_{i}-1}$\\\\ \n         \\end{tabular}\n        \\end{table}\n   \n   \\item Mean square values and test-statistic:\n   \\[MS_{M} = \\frac{SS_{M}}{\\nu_{M}} = \\frac{1}{I-1}\\sum^{I}_{i=1}J_{i}(\\bar{X}_{i}-\\bar{X})^{2} \\quad \\quad \\quad  MS_{R} = \\frac{SS_{R}}{\\nu_{R}} = \\frac{1}{N-I} \\sum_{i=1}^{I}\\sum_{j=1}^{J_{i}}(X_{i,j}-\\bar{X}_{i})^{2}\\]\n   \\[F = \\frac{MS_{M}}{MS_{R}} \\quad \\quad \\quad p =1-f(F, \\nu_{M}, \\nu_{R})\\]\n\\end{itemize}\n\n\n\\subsection*{Two-way ANOVA}\n        \\begin{table}[H]\n        \\begin{adjustbox}{width=\\columnwidth,center}\n        \\begin{tabular}{c|c|c|c|c|c}\n        & Sum of Squares & DoF & Mean Square & F-Statistic & Notes \\\\ \\hline\n        Total & $\\displaystyle SS_{T} = \\sum_{g=1}^{G}\\sum_{i=1}^{I}\\sum_{j=1}^{J}(X_{g,i,j}-\\bar{X})^{2}$ & $\\displaystyle \\nu_{T}=N-1$ & & & $N=GIJ$\\\\ \\hline\n\n        Model & $\\displaystyle SS_{M} = \\sum_{g=1}^{G}\\sum^{I}_{i=1}J(\\bar{X}_{gi}-\\bar{X})^{2}$ & $\\displaystyle \\nu_{M}=GI-1$ & & &\\\\ \\hline\n         \n        Residuals & $\\displaystyle SS_{R} = \\sum_{g=1}^{G}\\sum_{i=1}^{I}\\sum_{j=1}^{J}(X_{g,i,j}-\\bar{X}_{gi})^{2}$ & $\\displaystyle \\nu_{R} = N-GI$ & $\\displaystyle MS_{R} = \\frac{SS_{R}}{\\nu_{R}}$ & & \\\\ \\hline\n         \n        $SS_{A}$  & $\\displaystyle SS_{A} = IJ \\sum_{g=1}^{G}(\\bar{X}_{g}-\\bar{X})^{2}$ & $\\displaystyle \\nu_{A} = G-1$ & $\\displaystyle MS_{A} = \\frac{SS_{A}}{\\nu_{A}}$ & $\\displaystyle F_{A} = \\frac{MS_{A}}{MS_{R}}$ & $SS_{M}$ grouped by G\\\\ \\hline\n         \n        $SS_{B}$  & $\\displaystyle SS_{B} = GJ \\sum_{i=1}^{I}(\\bar{X}_{i}-\\bar{X})^{2}$ & $\\displaystyle \\nu_{B} = I-1$ & $\\displaystyle MS_{B} = \\frac{SS_{B}}{\\nu_{B}}$ & $\\displaystyle F_{B} = \\frac{MS_{B}}{MS_{R}}$ & $SS_{M}$ grouped by I\\\\ \\hline\n         \n        $SS_{A \\times B}$  & $\\displaystyle SS_{A \\times B} = SS_{M}-SS_{A}-SS_{B}$ & $\\displaystyle \\nu_{A \\times B} = \\nu_{M}-\\nu_{A}-\\nu_{B}$ & $\\displaystyle MS_{A\\times B} = \\frac{SS_{A\\times B}}{\\nu_{A\\times B}}$ & $\\displaystyle F_{A\\times B} = \\frac{MS_{A\\times B}}{MS_{R}}$ & left over $SS$\\\\\n         \\end{tabular}\n         \\end{adjustbox}\n        \\end{table}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{./images/twoWayANOVA.pdf}\n\\end{figure}\n\\subsection*{Post-Hoc Tests}\n\\begin{itemize}\n            \\item Bonferroni - pairwise t-tests. Statistically significant if $p < p_{crit}$\n            \\item Tukey Kramer Test (less conservative than Bonferroni).\n        \\end{itemize}\n\\subsection*{Non-parametric Tests}\n\\begin{itemize} \\itemsep0.4cm\n    \\item \\textbf{Sign test}: one sample, asymmetric data.\n    \\begin{itemize}\n        \\item Compare each sample to a pre-defined median value $\\tilde{\\mu}_{0}$: +ve/-ve difference?\n        \\item Make hypothesis: \n        \\begin{itemize}\n            \\item $H_{0}$: the population median $\\tilde{\\mu}$ from which the sample is taken is equal to $\\tilde{\\mu}_{0}$.\n            \\item $H_{1}$: $\\tilde{\\mu} \\neq \\tilde{\\mu}_{0}$.\n        \\end{itemize}\n        \\item If $H_{0}$ is true, we should obtain at least $n/2$ of data points that are negative.   \n        \\item find $P$ by taking binomial test by taking $p=0.5$.\n    \\end{itemize}\n    \n    \\item \\textbf{Wilcoxon Sign-rank test}: one sample, non-asymmetric data.\n    \\begin{itemize}\n        \\item Compare each sample to a pre-defined median value $\\tilde{\\mu}_{0}$. Consider both the \\textbf{sign} and \\textbf{magnitude} of differences.\n        \\item Sort and find the rank of the differences. Multiply the ranks by their sign. \n        \\begin{table}[H]\n            \\centering\n            \\begin{tabular}{l|c|c|c}\n            rank  &  ...  &  ...&  ...\\\\ \\hline\n            $\\lvert$difference$\\rvert$ & ...  &  ...&  ...\\\\  \\hline\n            sign & ...  &  ...&  ...\\\\ \\hline\n            signed rank & ... &  ... &  ...\\\\ \n            \\end{tabular}\n        \\end{table}\n        \\item calculate the absolute sum of the signed ranks, for +ve and -ve, respectively.\n        \\begin{itemize}\n            \\item $W^{+} = \\sum_{i}^{n^{+}}R_{i}^{+}$ and $W^{-} = \\sum_{i}^{n^{-}}-R_{i}^{-}$\n            \\item the smaller one becomes the test statistic.\n        \\end{itemize}\n        \\item Critical value $W_{crit}$ can be located from the table. \n    \\end{itemize}\n    \n    \\item \\textbf{Mann-Whitney U-test}: two samples.\n    \\begin{itemize}\n        \\item Make hypothesis: \n        \\begin{itemize}\n            \\item $H_{0}$: the mean rank of the two levels are equal. (If samples are independent are from similar underlying distributions : mean rank -> median.)\n            \\item $H_{1}$: the mean rank of the two levels are different.\n        \\end{itemize}\n        \\item Group both samples, rank and correct averages \\textbf{in one table}.\n         \\begin{table}[H]\n            \\centering\n            \\begin{tabular}{l|c|c|c}\n            rank  &  ...  &  ...&  ...\\\\ \\hline\n            data value & ...  &  ...&  ...\\\\ \n            \\end{tabular}\n        \\end{table}\n        \\item Calculate the sum ranks for each group $W$.\n        \\[W_{X}=\\sum_{i}^{n_{X}}R_{i}^{X} \\quad \\quad W_{Y}=\\sum_{i}^{n_{Y}}R_{i}^{Y}\\]\n        \\item Calculate U-statistic for each group\n        \\[U_{i} = W_{i}-\\frac{n_{i}(n_{i}+1)}{2}\\]\n        \\item For $n<8$: $U_{crit}$ can be found from the table. Reject $H_{0}$ if $min(U_{1}, U_{2})<u_{crit}$\n        \\item For $n\\geq 8$: \\[\\mu_{U}=\\frac{n_{1}n_{2}}{2} \\quad \\quad \\sigma_{U}^{2}= \\frac{n_{1}n_{2}(n_{1}+n_{2}+1)}{12}\\]\n        z-statistic can be calculated by \\[Z_{i}=\\frac{U_{i}-\\mu_{U}(+continuity)}{\\sigma_{U}}\\]\n    \\end{itemize}\n    \n    \\item \\textbf{Kruskall-Wallis test}: more than two samples.\n    \\begin{itemize}\n        \\item $H_{0}$: the $I$ independent random samples all come from identical populations.\n        \\item Calculate the sum ranks for each group: \n        \\[H=-3(N+1)+\\frac{12}{N(N+1)}\\sum_{i=1}^{k}\\frac{W_{i}^{2}}{J_{i}}\\]\n        \\item For all $J_{i} > 5$, and if $H_{0}$ is true, $H$ is approximated to $\\chi^{2}$ distribution with $\\nu = I-1$.\n    \\end{itemize}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{./images/nonparasummary.pdf}\n\\end{figure}\n\n    % \\item K-S test statistic: \\[K = \\sqrt{n}D_{n}\\] p-value is $\\displaystyle p = 1-KS(\\sqrt{n}D_{n})$.\n\n    % \\item Shapiro-Wilk test statistic: \\[W = \\frac{(\\sum a_{i}z_{i})^{2}}{(\\sum x_{i}-\\bar{x})^{2}}\\] \n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\newpage\n\\section{Correlation and Regression}\n\\subsection*{Correlation}\n\\begin{table}[H]\n    \\centering\n    \\begin{adjustbox}{width=\\columnwidth,center}\n    \\begin{tabular}{c|c}\n    Covariance (discrete and continuous)& Correlation Coefficient \\\\ \\hline \n    $\\displaystyle cov(X, Y)= E[(x-\\mu_{X})(y-\\mu_{Y})] \n    = E(XY)-E(X)E(Y)=\\begin{cases}\n    \\displaystyle \\sum_{x}\\sum_{y}(x-\\mu_{X})(y-\\mu_{Y})p(x,y)\\\\\n    \\displaystyle \\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}  (x-\\mu_{X})(y-\\mu_{Y})f(x,y) dxdy %& continuous \n    \\end{cases} $\n     &  $\\displaystyle \\rho_{X,Y} = \\frac{cov(X,Y)}{\\sigma_{X}\\sigma_{Y}}$\\\\ \n    \\end{tabular}\n    \\end{adjustbox}\n\\end{table}\n  \\begin{itemize}\n     \\item \\textbf{Pearson's correlation coefficient}: $r$ is an point estimator of $R = \\hat{\\rho}$.  Assume linear relationship between $X$ and $Y$. \n     \\[\\sigma_{X}^{2} = S_{XX} = \\frac{\\sum_{i=1}^{n}(x_{i}-\\bar{x})^{2}}{n-1}, \\quad \\quad \\sigma_{Y}^{2} = S_{YY} = \\frac{\\sum_{i=1}^{n}(y_{i}-\\bar{y})^{2}}{n-1}, \\quad \\quad cov(x,y) = S_{XY} = \\frac{\\sum_{i=1}^{n}(x_{i}-\\bar{x})(y_{i}-\\bar{y})^{2}}{n-1}\\]\n    % \\[\\Downarrow\\]\n    \\[\\Rightarrow \\quad r_{X, Y} = \\frac{S_{XY}}{\\sqrt{S_{XX}}\\sqrt{S_{YY}}} = \\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}}} \\quad \\in [-1, 1]\\]\n    \n    \\item \\textbf{Test statistic and DoF}\n    \\[T = \\frac{R\\sqrt{n-2}}{\\sqrt{1-R^{2}}}, \\quad \\quad \\nu = n-2\\]\n     \\item \\textbf{Spearman's rank correlation coefficient}: no linear relationship between $X$ and $Y$ -  $ \\displaystyle \\rho = 1- \\frac{6\\sum(x_{i}-y_{i})^{2}}{n(n^{2}-1)}$, where $x_{i}, y_{i}$ are ranks. Otherwise we evaluate Pearson's r on the ranks (if $x_{i}, y_{i}$ are tied).\n  \\end{itemize}\n  %%\n \n\\subsection*{Regression}\n\\begin{itemize}\n    \\item \\textbf{Regression model} - $Y = b_{0} + b_{1}X + \\epsilon$, where $\\epsilon$ is a normally distributed random variable with $E(\\epsilon) = 0$ and $V(\\epsilon) = \\sigma_{\\epsilon}^{2}$.\n    \\item \\textbf{Estimate of the best fit line}\n    \n    \\begin{minipage}{.45\\textwidth}\n    \\begin{table}[H] \\centering\n    \\begin{tabular}{c|c|c}\n    \\multicolumn{3}{c}{$\\mathbf{Y=\\hat{b}_{0}+\\hat{b}_{1}X}$}\\\\ \\hline\n    slope & $\\displaystyle \\hat{b}_{1} = \\frac{S_{xy}}{S_{xx}}$ & $\\displaystyle s_{\\hat{b}_{1}} = \\frac{s_{\\epsilon}}{\\sqrt{S_{xx}}}$\\\\ \\hline\n    intercept & $\\displaystyle \\hat{b}_{0} = \\bar{y}-\\hat{b}_{1}\\bar{x} $ & $\\displaystyle s_{\\hat{b}_{0}} = \\sqrt{\\frac{1}{n}+\\frac{\\bar{x}^{2}}{S_{xx}}}$\n    \\end{tabular}\\end{table}\n    \\end{minipage}\n    \\begin{minipage}{.05\\textwidth}\\[\\xrightarrow{\\text{with}}\\]\n    \\end{minipage}\n    \\begin{minipage}{.45\\textwidth}\n    \\begin{tabular}{c|c|c} \\centering\n    $S_{xx}$ & $S_{yy}$ & $S_{xy}$ \\\\ \\hline\n    $\\displaystyle \\sum_{i=1}^{n}(x_{i}-\\bar{x})^{2}$ & $\\displaystyle \\sum_{i=1}^{n}(y_{i}-\\bar{y})^{2}$ & $\\displaystyle \\sum_{i=1}^{n}(x_{i}-\\bar{x})(y_{i}-\\bar{y})^{2}$ \n    \\end{tabular}\\end{minipage}\n    \\begin{itemize}\n        \\item Best estimator for variance of residuals -  $\\displaystyle \\hat{\\sigma}_{\\epsilon}^{2} = s_{\\epsilon}^{2} = \\frac{SS_{R}}{\\nu_{R}} = \\frac{\\sum_{i=1}^{n}(y_{i}-\\hat{y}_{i})^{2}}{n-2}$\n    \\end{itemize}\n    \n    \\item \\textbf{Coefficient of determination}: \\[r^{2} = 1-\\frac{SS_{R}}{SS_{T}}, \\quad \\quad \\text{where} \\quad SS_{T}=S_{yy}, \\quad SS_{R}=s_{\\epsilon}^{2}\\nu_{R}, \\quad \\quad \\]\n    \n    \\item \\textbf{Confidence interval}:\n     \\begin{table}[H] \\centering\n    \\begin{tabular}{c|c|c}\n\n   slope & intercept & variance of residual \\\\ \\hline\n   $CI=\\hat{b}_{1} + t_{1-\\frac{\\alpha}{2}, \\nu}s_{\\hat{b}_{1}}$ & $CI=\\hat{b}_{0} + t_{1-\\frac{\\alpha}{2}, \\nu}s_{\\hat{b}_{0}}$ &\n   $s_{\\epsilon}^{2}= SS_{R}/\\nu_{R}$ and $\\nu_{R}=n-2$\n    \\end{tabular}\\end{table}\n    \n    \\item \\textbf{Confidence bands}: uncertainty on the mean\n    \\[CI = \\hat{y}^{*}\\pm t_{\\frac{\\alpha}{2}, n-1}s_{\\hat{y}^{*}} \\quad \\quad s_{\\hat{y}^{*}} = s_{\\epsilon}\\sqrt{\\frac{1}{n}+\\frac{(x^{*}-\\bar{x})^{2}}{\\sum_{i=1}^{n}(x_{i}-\\bar{x})^{2}}}\\]\n    \n    \\item \\textbf{Prediction bands}: uncertainty on a single measurement\n    \\[s_{pred}^{2} = s_{\\hat{y}^{*}}^{2} + s_{\\epsilon}^{2} \\quad \\quad PI=\\hat{y}^{*}\\pm t_{\\frac{\\alpha}{2}, n-2} s^{*}_{pred}\\]\n\\end{itemize}\n \n\\vspace*{\\fill}\n\\framebox{\\footnotesize  \\href{https://www.overleaf.com/read/yrxtbmqnvzgh}{Scripted} by B Li \\& P Xie. \\ Last update: \\today}\n% \\begin{flushright}\n%     \\begin{figure}[H]\n%     \\includegraphics[width=.1\\textwidth]{by-nceu.eps}\n%     This work is licensed under a Creative Commons Attribution 4.0 International License\n% \\end{figure}\n% \\end{flushright}\n  \n% insert data tables from the external pdf source\n\\includepdf[pages=-]{./images/Z_t_F_Tables.pdf}\n\n\n\n\n% end the doc\n\\end{document}", "meta": {"hexsha": "965ac5038fed9c3a11c4b5b1ea6a392705cf7934", "size": 28516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PaS_formula_sheet.tex", "max_stars_repo_name": "binghuan-li/Probability-and-Statistics", "max_stars_repo_head_hexsha": "3167d58a3e1241c673ab22ffd969bf349add7d53", "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": "PaS_formula_sheet.tex", "max_issues_repo_name": "binghuan-li/Probability-and-Statistics", "max_issues_repo_head_hexsha": "3167d58a3e1241c673ab22ffd969bf349add7d53", "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": "PaS_formula_sheet.tex", "max_forks_repo_name": "binghuan-li/Probability-and-Statistics", "max_forks_repo_head_hexsha": "3167d58a3e1241c673ab22ffd969bf349add7d53", "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.1917591125, "max_line_length": 301, "alphanum_fraction": 0.573467527, "num_tokens": 10325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.656876072529877}}
{"text": "\\section{M/M/\\texorpdfstring{$\\infty$}{Infinity} Queues}\n\\label{sec:M-M-inf-Queues}\n\nA $M/M/\\infty$ 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 infinite 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-inf-Queue}\t\n%\t\\centering\n%\t\\includegraphics{fig/M-M-inf-Queue}\n%\t\\caption{An M/M/k 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{theorem}[Utilization]\n\t\\label{thm:M-M-inf-Utilization}\n\tFor any $M/M/\\infty$, the utilization is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-inf-Utilization}\n\t\\varrho = \\frac{\\lambda}{\\mu}\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{theorem}[State Probability]\n\\label{thm:M-M-inf-Probability-State}\n\tFor any $M/M/\\infty$, the state probability is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-inf-Probability-State}\n\t\\pi_{i} = \\Big(\\frac{\\lambda}{\\mu})^{i} \\frac{1}{i!} \\pi_{0}\n\t\\end{equation}\n\t\n\twith\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-inf-Probability-State-Zero}\n\t\\pi_{0} = e^{-\\frac{\\lambda}{\\mu}}\n\t\\end{equation}\n\t\n\tThat is $N^{M/M/\\infty} \\sim Poisson(\\frac{\\lambda}{\\mu})$.\n\\end{theorem}\n\nSince, $N^{M/M/\\infty} \\sim Poisson(\\frac{\\lambda}{\\mu})$, then\n\n\\begin{equation}\n\\label{eqn:M-M-inf-Mean-System-Jobs}\n\\expected{N} = \\frac{\\lambda}{\\mu}\n\\end{equation}\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}}$,\n$\\expected{T_{S}}=\\frac{1}{\\mu}$,\nconsidering that $\\expected{N_{Q}}=0$ and $\\expected{T_{Q}}=0$, because every arrival il always served immediately.\n\nIn particular we obtain\n\n\\begin{equation}\n\\label{eqn:M-M-inf-Mean-Response-Time}\n\\expected{T} = \\frac{1}{\\mu}\n\\end{equation}\n\n", "meta": {"hexsha": "1914d30c2c21f9cf017147b149765a6f4162be2d", "size": 2070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/m-m-inf-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-inf-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-inf-queues.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 29.5714285714, "max_line_length": 155, "alphanum_fraction": 0.6917874396, "num_tokens": 695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789132480439, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.6568760651095835}}
{"text": "\\section {Introduction to DFA Framework}\n\\setlength{\\parindent}{0pt}\n(Prepared by Namrata Priyadarshani and Shivam Bansal)\n\n\\vspace{0.3cm}\n\nIn this module, we build up common framework to express DFA. Some common characteristics of DFA are described below: \n\n\\subsection{Transfer Functions and Meet operator}\n\nLet s be a statement and the value before statement is in[s] and after statement is out[s]. Then, for a forward DFA, \\textbf{Transfer function} is defined as the function that takes in[s] as argument and converts it into out[s]. \\textbf{Meet operator} expresses in[s] as the function of out[p] for all predecessor p of s. These functions operates in reverse direction in the case of Backward DFA.\n\\newline\nMost of the time, we consider running the algorithm at the Basic Block level granularity and define Transfer function and meet operator for the values in[B] and out[B] i.e. the input and output values of the basic block B. \n\n\\subsection{Partial ordered values}\n\nThere is a partial order within the elements of Domain represented by $\\geq$ operator.\nDirected Acyclic Graph is one way to represent the ordering. The graph contains an edge from $a \\rightarrow b$ iff $a \\geq b$.\n%insert image\n\\includegraphics[scale=0.3]{images/91_1.png}\nThere is one value greater than all values in Domain known as Top value (T) and one value less than all values in Domain known as Bottom value ($ \\bot $).\n\n\\subsection{Constant Propagation DFA}\nDifferent DFA has different direction, boundary condition, meet operator and transfer function. The structure and flow of algorithm remains same for all DFA. In fixed-point-algorithm first the boundary condition is specified, all other values are set to top value and then iterate until no change occur in any value.\n\nFor constant propagation the DFA is specified by:\n\\begin{itemize}\n    \\item \\textbf{Domain}: set of constant definitions\n    \\item \\textbf{Direction}: Forward\n    \\item \\textbf{Transfer function}: $f_{B} = \\lambda x. GEN[B] \\cup (x-KILL[B]) $\n    \\item \\textbf{Meet operator}: $\\cap$ (set intersection)\n    \\item \\textbf{Boundary condition}: $out[entry] = \\phi$\n\\end{itemize}\n", "meta": {"hexsha": "d36a3752a277d0b7b84428e932224b56ba92d331", "size": 2139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module91.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": "module91.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": "module91.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": 62.9117647059, "max_line_length": 396, "alphanum_fraction": 0.7671809257, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6568760595443635}}
{"text": "\\section*{Ex.34.4-6}\n\\subsection*{Formula satisfiability}\n\nWe are given an algorithm, call it $A$, which can decide formula satisfiability in polynomial time. To find a satisfying assignment with the use of $A$ do the following:\n\nLet $x_1,\\ldots,x_k$ be the $k$ input variables to the formula problem. First call $A$, to decide if the formula instance has a satisfying assignment. If not it will return 0, and no more work needs to be done. If it returns 1, there exists an assignment which we can find.\n\nNote that if we set $x_i=1$ for some $i\\in\\{1,\\ldots,k\\}$, and then run $A$ it will tell us if there exists a solution when $x_i=1$. If there doesn't, then set $x_1 =0$. Do this for all $i\\in\\{1,\\ldots,k\\}$, and you will get a satisfying assignment. For each variable we call $A$ once, which is $O(n^m)$, and we do this $k$ times plus some constant work. This yields an algorithm that finds the satisfying assignment in $O(kn^m)=O(n^m)$ time. Which is polynomial.\n\n", "meta": {"hexsha": "851d44dbfd4d147b859b7de7af9e6f50d68bfb08", "size": 970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.4-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.4-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.4-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": 97.0, "max_line_length": 463, "alphanum_fraction": 0.7319587629, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788903594354, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6568760428487024}}
{"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 02}\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}\nA short implementation and demonstration of na\\\"{i}ve Bayes classifiers on hand-written digit images.\n\\end{abstract}\n\n\\newpage\n\\section{Problem Description}\nThe task: using the \\texttt{zipcode} data from the Elements of Statistical Learning book website and Bayes rule, do the following:\n\\begin{enumerate}\n  \\item Construct Gaussian classifiers for all of the digits (0-9) using the training data set. Do so by computing the means and covariances of each class in order to fit the Gaussian distribution for the class.\n  \\item Use the constructed classifiers to classify the test set.\n  \\item Display the results in a ``confusion matrix.\"\n\\end{enumerate}\n\\textit{Hint}: If you find that a matrix (specifically any of the covariance matrices) is numerically or actually singular, and therefore cannot be inverted, regularize it by adding an identity matrix multiplied by a small factor to ``breathe\" on it. This can help make the matrix invertible, but one needs to exercise caution as it can adversely affect the results of computations.\n\n\\section{Results}\nThe na\\\"{i}ve Bayes classifiers performed rather well, achieving nearly 94\\% accuracy. While this does leave something to be desired, improving on this performance benchmark might require improving the numerical accuracy of the program (using something better than double-precision variables), finding a better regularization factor for regularizing non-invertible matrices ($0.5$ seemed to work well enough, no more effort was put forth to improve on this), application of additional techniques (like PCA), or even using this classifier as an element of a composite classifier.\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=.6\\linewidth]{R_confusion_matrix_output}\n  \\caption{R output of a confusion matrix displaying the classification results using the na\\\"{i}ve Bayes classifier.}\n  \\label{fig:confusion_matrix}\n\\end{figure}\n\n\\section{Code}\nAfter struggling for too long with R code and singular matrices, it was deemed better to switch to a familiar and high performance language - namely C++. Thus, the classification code was written in C++ and the confusion matrix was ported to R for data presentation.\n\n\\subsection{C++ Code}\n\\begin{verbatim}\n#include <string>\n#include <vector>\n#include <Eigen/Dense>\n#include <cmath>\n\n#include <iostream>\n#include <fstream>\n#include <exception>\n\n#define PI 3.141592653589793238462643383279502884L\n#define REGULARIZATION_FACTOR 0.5\n\nconst std::string TRAINING_FILE_NAME = \"zip.train\"; // 2007 items\nconst std::string TEST_FILE_NAME = \"zip.test\"; // 7291 items\n\ntypedef struct {\n  unsigned label;\n  Eigen::VectorXd features;\n} ClassificationObject;\n\ntypedef struct {\n  unsigned label;\n  double prior;\n  Eigen::VectorXd mean;\n  Eigen::MatrixXd covariance;\n  double covarianceDeterminant;\n  Eigen::MatrixXd covarianceInverse;\n} ClassInfo;\n\n\nstd::vector<ClassificationObject>\nReadData(\n  const std::string& fileName,\n  const unsigned featureDim,\n  const unsigned numItems) {\n\n  std::ifstream fin;\n  fin.clear(); fin.open(fileName.c_str());\n\n  if (!fin.good()) {\n    throw std::exception();\n  }\n\n  std::vector<ClassificationObject> data; data.reserve(numItems);\n\n  for (unsigned i = 0; i < numItems; ++i) {\n    ClassificationObject classificationObject;\n    double dummy;\n    fin >> dummy;\n    classificationObject.label = (unsigned) dummy;\n\n    classificationObject.features.resize(featureDim);\n    for (unsigned j = 0; j < featureDim; ++j) {\n      fin >> classificationObject.features(j);\n    }\n    data.push_back(classificationObject);\n  }\n\n  return data;\n}\n\nClassInfo\nComputeClassInfo(\n  const std::vector<ClassificationObject>& data,\n  const unsigned classLabel,\n  const unsigned featureDim) {\n \n  ClassInfo classInfo;\n  classInfo.label = classLabel;\n  classInfo.mean.setZero(featureDim);\n  classInfo.covariance.setZero(featureDim, featureDim);\n\n  // compute mean and prior probability at once\n  std::vector<ClassificationObject> subset;\n  for (const ClassificationObject& classificationObject : data) {\n    if (classificationObject.label == classLabel) {\n      classInfo.mean += classificationObject.features;\n      subset.push_back(classificationObject);\n    }\n  }\n  classInfo.mean /= subset.size();\n  classInfo.prior = (double) subset.size() / (double) data.size();\n\n  // covariance matrix\n  // Note: I use a nifty trick that is simpler in code (not sure if\n  //       simpler computationally). Let $P_i = x_i - mu$, where $i$\n  //       corresponds to a particular observation vector. Then\n  //       $A$ is the concatenation of all the $P_i$ as column\n  //       vectors ($A = [P_1 ... P_m]$). Then\n  //       $\\frac{1}{m} * A * A^t$ results in the same computations\n  //       that create the covariance matrix as more traditional\n  //       formulae.\n  Eigen::MatrixXd A(featureDim, subset.size());\n  for (unsigned j = 0; j < subset.size(); ++j) {\n    A.col(j) = subset[j].features - classInfo.mean;\n  }\n  classInfo.covariance = A * A.transpose();\n  classInfo.covariance /= (double) subset.size();\n  if (classInfo.covariance.determinant() - 0.1 <= 0.0) {\n    Eigen::MatrixXd regularizationMatrix;\n    regularizationMatrix.setIdentity(featureDim, featureDim);\n    regularizationMatrix *= REGULARIZATION_FACTOR;\n    classInfo.covariance += regularizationMatrix;\n  }\n  classInfo.covarianceDeterminant = classInfo.covariance.determinant();\n  classInfo.covarianceInverse = classInfo.covariance.inverse();\n\n  return classInfo;\n}\n\ndouble\nGaussianPdf(\n  const Eigen::VectorXd& testFeatureVector,\n  const ClassInfo& classSummary) {\n\n  const Eigen::VectorXd& x = testFeatureVector;\n  const Eigen::VectorXd& mu = classSummary.mean;\n  const double& sigmaDet = classSummary.covarianceDeterminant;\n  const Eigen::MatrixXd& sigmaInv = classSummary.covarianceInverse; \n\n  double scalingFactor = 1.0 / sqrt(pow(2.0 * PI, mu.size()) * sigmaDet);\n  double exponent = -0.5 * (((x - mu).transpose() * sigmaInv).dot((x - mu)));\n\n  return scalingFactor * exp(exponent);\n}\n\nunsigned\nClassifyObject(const ClassificationObject& object, const std::vector<ClassInfo>& classSummaries) {\n  unsigned mostLikelyClass = 0;\n  double highestProbability = classSummaries.front().label;\n\n  for (const ClassInfo& classSummary : classSummaries) {\n    double probability = GaussianPdf(object.features, classSummary) * classSummary.prior;\n    if (probability > highestProbability) {\n      mostLikelyClass = classSummary.label;\n      highestProbability = probability;\n    }\n  }\n\n  return mostLikelyClass;\n}\n\nEigen::MatrixXi\nPerformClassifications(const std::vector<unsigned>& labelSet,\n  const std::vector<ClassInfo>& classSummaries,\n  const std::vector<ClassificationObject>& testObjects) {\n\n  Eigen::MatrixXi confusionMatrix(labelSet.size(), labelSet.size());\n  confusionMatrix.setZero(labelSet.size(), labelSet.size());\n\n  unsigned i = 1;\n  unsigned onePercent = testObjects.size() / 100;\n  for (const ClassificationObject& object : testObjects) {\n    if (i % onePercent == 0) {\n      std::cout << i << \"% processed.\" << std::endl;\n    }\n    i++;\n\n    unsigned classifiedAs = ClassifyObject(object, classSummaries);\n    confusionMatrix(object.label, classifiedAs)++;\n  }\n\n  return confusionMatrix;\n}\n\n\nint\nmain(const int argc, const char** argv) {\n  std::cout << \"Reading Data...\" << std::endl;\n  std::vector<ClassificationObject> trainingData = ReadData(\n    TRAINING_FILE_NAME,\n    256,\n    7291\n  );\n  std::vector<ClassificationObject> testData = ReadData(\n    TEST_FILE_NAME,\n    256,\n    2007\n  );\n\n  std::cout << \"Training Models...\" << std::endl;\n  std::vector<ClassInfo> classSummaries; classSummaries.reserve(10);\n  for (unsigned label = 0; label <= 9; ++label) {\n    classSummaries.push_back(ComputeClassInfo(trainingData, label, 256));\n  }\n\n  std::cout << \"Classifying Objects...\" << std::endl;\n  Eigen::MatrixXi confusionMatrix = PerformClassifications(\n    {0,1,2,3,4,5,6,7,8,9},\n    classSummaries,\n    testData\n  );\n\n  std::cout << \"Results:\" << std::endl;\n  std::cout << confusionMatrix << std::endl;\n\n  return 0;\n}\n\\end{verbatim}\n\n\\subsection{R Code}\n\\begin{verbatim}\n############\n# Plotting #\n############\nrequire(caret)\n\nresults <-data.matrix(read.table(\"results\"))\ndimnames(results) <- list(c(0,1,2,3,4,5,6,7,8,9), c(0,1,2,3,4,5,6,7,8,9))\n\nactuals.f <- list()\npredictions.f <- list()\nfor (i in 1:nrow(results)) {\n  for (j in 1:ncol(results)) {\n    actuals.f <- c(actuals.f, rep(i - 1, results[i, j]))\n    predictions.f <- c(predictions.f, rep(j - 1, results[i, j]))\n  }\n}\nactuals.f <- factor(unlist(actuals.f))\npredictions.f <- factor(unlist(predictions.f))\n\nconfusionMatrix(data = predictions.f, reference = actuals.f)\n\\end{verbatim}\n\n\\subsection{The student would like to thank...}\nThe student would like to thank the authors of the Eigen C++ matrix library. This library has proved quick, easy and effective numerous times, this time being no exception. The Eigen library and more information can both be found at\\hfill\\\\\n\\texttt{http://eigen.tuxfamily.org}.\n\n\\end{document}\n", "meta": {"hexsha": "e60a3b407e73a00c1c57a0e9226a9a12218ed2a2", "size": 9447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "STAT775/HW02/HW02.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/HW02/HW02.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/HW02/HW02.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": 34.1046931408, "max_line_length": 578, "alphanum_fraction": 0.7221340108, "num_tokens": 2377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672320414787, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.6568514362154828}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 3, 2022}\n\n\\subsection{Arithmetic Functions}\n\nWe look at arithmetic functions and how they act on prime numbers:\n\\begin{definition}[Arithmetic Function]\n    An \\ul{arithmetic function} is a function $f: \\ZZ_+ \\to \\CC$.\n\n    \\emph{(Typically, these are integer valued.)}\n\\end{definition}\n\\begin{example}We have some examples of arithmetic functions:\n    \\begin{itemize}\n        \\item Euler $\\phi$ function.\n        \\item $\\tau(n)$, the counting function. It takes a positive integer and counts the number of positive divisors of $n$. \\[\\tau(n) = \\sum_{d\\mid n} 1\\]\n        \\item $\\sigma(n)$, the sum of divisors function. It is the sum over all the positive divisors of $n$. \\[\\sigma(n) = \\sum_{d\\mid n}d\\]\n    \\end{itemize}\n\\end{example}\nWe have some properties of these functions, like \\emph{multiplicative}, \\emph{completely multiplicative}, \\emph{additive}, \\emph{completely additive}.\n\n\\begin{definition}[Multiplicativity]\n    An arithmetic function $f$ is \\ul{multiplicative} if\n    \\begin{align*}\n        f(mn) & = f(m)f(n)\\quad \\text{whenever }(m, n) = 1\n        \\intertext{$f$ is said to be \\ul{totally or completely multiplicative} if }\n        f(mn) & = f(m)f(n)\\quad \\forall m, n\\in\\ZZ_+\n    \\end{align*}\n    regardless of coprimality.\n\\end{definition}\n\nIf $f$ is multiplicative and $n_1, \\dots, n_k$ are positive pairwise coprime integers, then \\[f(n_1\\dots n_k) = f(n_1)f(n_2)\\dots f(n_k).\\]\n\nA particular case that is useful is when we write\n\\[n=p_1^{e_1}p_2^{e_2}\\cdots p_k^{e_k}\\]\nso that assuming multiplicativity, we have that\n\\[f(n) = f(p_1^{e_1}) f(p_2^{e_2}) \\cdots f(p_k^{e_k})\\]\nA common type of arithmetic function is a summatory function, namely a function $f$ of the form\n\\[f(n) = \\sum_{d\\mid n} g(d), \\quad \\text{where $g$ is some arithmetic function.}\\]\n\n\\emph{Food for thought:} how special are summatory functions within the set of all arithmetic functions?\n\nA special property of summatory functions is that they ``inherit multiplicativity''.\n\\begin{lemma}\\label{lemma:summatory-preserves-multiplicativity}\n    If $g$ is a multiplicative function, and \\[f(n) = \\sum_{d\\mid n}g(d)\\quad \\forall n,\\] then $f$ itself is multiplicative.\n\\end{lemma}\n\n\\begin{proof}\n    Suppose $m, n\\in \\ZZ_+$ are coprime positive integers.\n\n    The divisors $d$ of $mn$ are the products $a\\cdot b$ where $a\\mid m$ and $b\\mid n$. Each such pair $a, b$ yields a uniquely determined produce $d = a\\cdot b$. Conversely, since $(m, n) = 1$, each divisor $d$ of $mn$ determines a unique divisor $a=\\gcd(d, m)$ and $b = \\gcd(d, n)$ so that $d = a\\cdot b$.\n\n    Thus there is a \\emph{bijection} between divisors of $mn$ and $m, n$ separately\n    \\[d\\mid mn \\longleftrightarrow (a\\mid m, b\\mid n)\\]\n    Thus we have\n    \\begin{align*}\n        f(m\\cdot n) & = \\sum_{d\\mid mn}g(d)                                              \\\\\n                    & = \\sum_{a\\mid m}\\sum_{b\\mid n}g(ab)                                \\\\\n                    & = \\sum_{a\\mid m}\\sum_{b\\mid n}g(a)g(b)                             \\\\\n                    & = \\left(\\sum_{a\\mid m} g(a)\\right) \\left(\\sum_{b\\mid n}g(b)\\right)\n        = f(m)\\cdot f(n)\n    \\end{align*}\n    Thus completes the proof that $f$ is multiplicative.\n\\end{proof}\n\n\\recall The functions introduced earlier\n\\[\\tau(n) = \\sum_{d\\mid n} 1\\qquad \\sigma(n) = \\sum_{d\\mid n}d\\]\nSo $\\tau$ is the summatory function of the constant $1$ functions, and $\\sigma$ is the summatory function of the identity function. We know that the constant $1$ function and the identity function are both completely multiplicative, so $\\sigma$ and $\\tau$ are multiplicative functions.\n\nThe implication of which is that it suffices to apply $\\tau$ and $\\sigma$ on prime powers and multiply.\n\nLet $p$ be a prime. Then\n\\begin{align*}\n    \\tau(p^e)   & = e + 1\\quad  \\text{(from $p^0$ to $p^e$)}.          \\\\\n    \\intertext{We also have}\n    \\sigma(p^e) & = 1 + p + p^2 + \\cdots + p^e = \\frac{p^{e+1}-1}{p-1}\n\\end{align*}\nTherefore, if $n=p_1^{e_1}p_2^{e_2}\\cdots p_k^{e_k}$, then\n\\begin{align*}\n    \\tau(n)   & = \\prod_{i=1}^k (e_i + 1)                                 \\\\\n    \\sigma(n) & = \\prod_{i=1}^k \\left(\\frac{p_i^{e_i+1}-1}{p_i-1}\\right).\n\\end{align*}\n\\begin{remark}\n    There are higher order divisor functions\n    \\[\\sigma_k(n) = \\sum_{d\\mid n}d^k\\]\n    so $\\sigma_0 = \\tau, \\sigma_1 = \\sigma, \\dots$\n\\end{remark}\n\n\\subsection{Review of \\texorpdfstring{$\\ZZ/n\\ZZ$}{Z/nZ} and its units}\n\n\\begin{definition}[Modular Congruence]\n    If $a, b, m\\in \\ZZ$, $m\\neq 0$, we say that \\ul{$a$ is congruent to $b$ modulo $m$} if $m\\mid b-a$. We write\n    \\begin{equation*}\n        a\\equiv b\\mod{m}, \\text{ or more simply } a\\equiv b\\ (m)\n    \\end{equation*}\n\\end{definition}\nCongruence mod $m$ is an equivalence relation on $\\ZZ$. If $a\\in \\ZZ$, $\\overline{a}$ denotes the set of integers congruent to $a\\mod m$, i.e. $\\overline{a} = \\{a + km \\mid k\\in \\ZZ\\}$.\n\n\\begin{definition}[$\\ZZ/m\\ZZ$, Residues mod $m$]\n    The set of congruence classes mod $m$ is denoted $\\ZZ/m\\ZZ$. This is a quotient ring of the ring of integers $\\ZZ$.\n\n    If $\\overline{a}_1, \\overline{a}_2, \\dots, \\overline{a}_m$ form a complete set of congruence classes mod $m$, then the set of integers $\\{a_1, a_2, \\dots, a_m\\}$ is called a \\ul{complete set of residues mod $m$}.\n\\end{definition}\n\n$\\ZZ/m\\ZZ$ can be endowed with the structure of a commutative ring by setting\n\\begin{align*}\n    \\overline{a} + \\overline{b}               & = \\overline{a + b} \\\\\n    \\text{and }\\overline{a}\\cdot \\overline{b} & = \\overline{ab},\n\\end{align*}\nand proving that this is well-defined as ring operations.\n\n\\begin{proposition}\n    The set of units in $\\ZZ/m\\ZZ$ is exactly\n    \\[\\{\\overline{a}\\mid (a, m) = 1\\}\\]\n\\end{proposition}\n\\begin{proof}\n    Let $\\overline{a}\\in \\ZZ/m\\ZZ$, then\n    \\begin{align*}\n                              & \\exists \\overline{b}\\in \\ZZ/m\\ZZ\\text{ s.t. }\\overline{b}\\cdot \\overline{a}\\equiv 1\\mod m \\\\\n        \\Longleftrightarrow\\  & \\exists b, n\\in \\ZZ\\text{ s.t. } ba - mn = 1                                              \\\\\n        \\intertext{Then by B\\'ezout's identity...}\n        \\Longleftrightarrow\\  & (a, m) = 1\n    \\end{align*}\n\\end{proof}\n\n\\subsection{The Euler \\texorpdfstring{$\\phi$}{phi} Function}\nFor $n\\in \\ZZ_+$, $\\phi(n)$ is defined to be the number of integers $1\\leq m\\leq n$ coprime to $n$.\n\\begin{example}\n    We have some examples of the Euler $\\phi$ functions:\n    \\begin{align*}\n        \\phi(1)   & = 1                                                                 \\\\\n        \\phi(p)   & = p-1 \\text{ for any prime $p$}\n        \\intertext{Let $e\\geq 1$, }\n        \\phi(p^e) & = p^e-p^{e-1} \\text{ for prime powers, we exclude multiples of $p$}\n    \\end{align*}\n\\end{example}\n\n\\emph{Wouldn't be great if $\\phi$ were multiplicative? It is!}\n\\begin{theorem}\n    If $(m,n) = 1$, then $\\phi(mn) = \\phi(m)\\phi(n)$.\n\\end{theorem}\n\\begin{proof}\n    By the Chinese Remainder Theorem\\footnote{This is an easy way to prove this assuming Math 1530 (Abstract Algebra). There is another way to prove this with one hand tied behind the back, it just takes more mental muscle to do. }, $\\ZZ/mn\\ZZ\\cong \\ZZ/m\\ZZ\\times \\ZZ/n\\ZZ$ if $(m, n) = 1$.\n\n    Taking the unit groups on both sides, we have\n    \\[(\\ZZ/mn\\ZZ)^\\times \\cong (\\ZZ/m\\ZZ)^\\times \\times (\\ZZ/n\\ZZ)^\\times\\]\n    and the Euler $\\phi$ function is simply measuring the order of said unit groups ($\\phi(n) = \\left|(\\ZZ/n\\ZZ)^\\times\\right|$).\n\\end{proof}\n\nHere is an important fact about the Euler $\\phi$ function:\n\\begin{proposition}\n    We have\n    \\begin{equation*}\n        \\sum_{d\\mid n}\\phi(d) = n.\n    \\end{equation*}\n\\end{proposition}\n\\begin{proof}\\emph{(1: a cute, snazzy proof)}\n    Consider the $n$ rational numbers\n    \\[\\frac{1}{n}, \\frac{2}{n}, \\dots, \\frac{n-1}{n}, \\frac{n}{n} = 1\\]\n    and reduce all to lowest terms so that the numerator and denominator are coprime.\n\n    Q: Given a positive divisor $d$ of $n$, how many fractions have $d$ as the denominator?\n\n    A: We have exactly $\\phi(d)$ of them.\n\n    Conversely, every denominator $d$ is certainly a divisor of $n$. So we conclude that $\\displaystyle n = \\sum_{d\\mid n}\\phi(d)$.\n\\end{proof}\n\\begin{proof}\\emph{(2: using what we've learnt)}\n    We use the fact that $\\phi$ is multiplicative, and that this function is a summatory function of $\\phi$, so this function itself is multiplicative. We can decompose this into prime powers. So it suffices to show this for prime powers.\n\n    Let $n = p^k$. Let\n    \\[f(n) = \\sum_{d\\mid n}\\phi(d).\\]\n    Then we have\n    \\begin{align*}\n        f(p^k) = \\sum_{d\\mid p^k} \\phi(d) & = 1 + (p-1) + (p^2 - p) + \\dots + (p^k-p^{k-1})\n        \\intertext{which is a telescoping sum which leaves}\n                                          & = p^k\n    \\end{align*}\n    which is as intended.\n\\end{proof}", "meta": {"hexsha": "32502cc39b8c95dbecb3344a4f8fbbbe11929918", "size": 8821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-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-02-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-02-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": 49.2793296089, "max_line_length": 307, "alphanum_fraction": 0.6163700261, "num_tokens": 2900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042216, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6568514267284724}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 1}\n\\subsection{Lecture Notes - Lagrangian Mechanics Part 1}\n\\subsubsection{Newtonian Mechanics to Lagrangian Mechanics}\nRecall the Newtonian formulation of classical mechanics; given the forces $\\v{F}_1(t), \\cdots \\v{F}_n(t)$ on a particle, we can solve Newton's second law (a second order differential equation):\n\\[\\sum_{i=1}^n \\v{F}_i(t) = m \\ddot{\\v{r}}(t)\\]\nTo obtain the trajectory $\\v{r}(t)$, which is uniquely determined by the initial conditions $\\v{r}(t_0)$ and $\\dot{\\v{r}}(t_0)$. \n\nIn this course, we will begin by looking at the Lagrangian formulation of classical mechanics. While this formulation contains no new physics compared to the Newtonian formulation, there are two distinct benefits:\n\\begin{enumerate}\n    \\item We can obtain EOM that do not depend on the coordinate system\n    \\item It is easier to treat constrained systems. \n\\end{enumerate}\n\\subsubsection{The Variational Principle Setup}\nTo do this, we will use a new approach, known as the \\textbf{Variational principle}. To set this up, let us consider the trajectory (as well as some \"wrong\" paths between the same two endpoints) travelled by a particle:\n\\begin{center}\n    \\includegraphics[scale=0.4]{Lecture-1/L1-img1.png}\n\\end{center}\nThe trajectory from time $t_1$ to $t_2$ is parametrized by the generalized coordinate $q$. Examples of these are $x_1, y_1, \\theta_1$. \n\\subsubsection{Generalized Coordinates}\nFor $N$ particles, a generalized coordinate $q_i$ depends on the positions of the $N$ particles:\n\\[q_i = q_i(\\v{r}_1, \\cdots, \\v{r}_N)\\]\nIn Cartesian coordinates, we have $3N$ coordinates but these are not necessarily independent. In general, we may have constraint functions $f_\\alpha(\\v{r}, \\dot{\\v{r}}, t) = 0$ where $\\alpha = 1, \\cdots, k$ (i.e. $k$ constraints). We then have $q_i$ independent coordinates, where $i = 1, \\cdots n$ where $i = 3N - k$. In other words, for a system of $N$ particles, we have $3N - k$ independent/generalized coordinates. Generalized coordinates allow us to avoid worrying about the constrained parameters. \n\\subsubsection{Hamilton's Principle and the Lagrangian}\nLet us consider assigning to each generalized coordinate $q(t)$ a number/value:\n\\[q(t) \\mapsto S[q(t)] \\in \\RR\\]\nThis is a functional (as denoted by the square brackets), as it takes in a function as an argument. Now, let us consider \\textbf{Hamilton's principle}:\n\\begin{center}\n    \\textit{The actual path of a particle between times $t_1$ and $t_2$ is such that the line integral:\n    \\[ S[q] = \\int_{t_1}^{t_2} \\LL(q_1, \\dot{q}_1, t) dt\\]\n    is stationary.}\n\\end{center}\nThough the principle saysthe integral is stationary, often this correponds to a minimum (though not always). The function $\\LL$ is defined as:\n\\[\\LL = T - U\\]\nwhere $T$ is the kinetic energy and $U$ is the potential energy. This is called the \\textbf{Lagrange Function} or \\textbf{Lagrangian}. $S$ is called the \\textbf{action}. Though we have not shown it explicitly, this Lagrange function gives the correct trajectory. Note that we have in essence replaced a second order ODE (Newton's second law) with an integral of $\\LL$. Having two endpoints $t_1$ and $t_2$ is consistent with the two initial conditions for a second order ODE. \n\\end{document}", "meta": {"hexsha": "c382eaab8a873aa864ea27eee6c15aca7394568c", "size": 3300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-1/Lecture-Notes-1.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-1/Lecture-Notes-1.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-1/Lecture-Notes-1.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 86.8421052632, "max_line_length": 505, "alphanum_fraction": 0.7427272727, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6568514192140359}}
{"text": "\\documentclass{article}\n\n\\usepackage[margin=1in]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{gensymb}\n\n\\newcommand{\\norm}[1]{\\lvert\\lvert \\, #1 \\, \\rvert\\rvert}\n\\newcommand{\\cross}{\\times}\n\\newcommand{\\pvec}[1]{\\vec{#1}^{\\,\\prime}}\n\n\\title{Mobile Robot Kinematics for FTC}\n\\author{Ryan Brott}\n\\date{}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\nIn FIRST Tech Challenge (FTC), kinematics are used all of the time---they're essential to robot operation. However, few teams  understand where the relationships come from or even acknowledge them explicitly, especially for holonomic drives. This paper intends to demystify the role and derivation of drive kinematics with a unified approach.\n\n\\section{Drive Kinematics}\n\nThis section systematically derives the forward and inverse kinematics for a variety of drives found in FTC (i.e., differential, mecanum, and swerve). The forward kinematics describe how the robot moves with specific wheel velocities. The inverse kinematics describe the opposite---how the wheels move during a given robot motion. \n\n\\subsection{Robots as Rigid Bodies}\n\nMost FTC robots have a robust structure that holds all of the components together into one coherent system. When acted upon by a force, the robot does not materially deform, and its constituent parts remain essentially fixed relative to each other. Objects with this property are called rigid bodies, and their kinematics can be summarized with a single translational and angular velocity vector pair. The translational velocity describes the motion of the axis or tation, while the angular velocity magnitude points along the axis of rotation and has magnitude equal to the angular speed.\\\\\n\\\\\nConsider a point in the body with position $\\vec{r}$. This position can be written as the sum $\\vec{R} + \\pvec{r}$ where $\\vec{R}$ points from the origin to the axis of rotation and $\\pvec{r}$ extends perpendicular to $\\vec{\\omega}$. Differentiation\\footnote{The time derivative of a vector $\\vec{v}$ in pure rotation described by $\\vec{\\omega}$ is $\\frac{d\\vec{v}}{dt} = \\vec{\\omega} \\cross \\vec{v}$.} gives the velocity relationship\n\\begin{align*}\n    \\frac{d\\vec{r}}{dt} &= \\frac{d\\vec{R}}{dt} + \\frac{d\\pvec{r}}{dt} \\\\\n    &= \\vec{V} + \\vec{\\omega} \\cross \\pvec{r}.\n\\end{align*}\nAs FTC robots are generally confined to a plane, we have\n\\begin{align*}\n    \\vec{r} &= x \\, \\hat{\\imath} + y \\, \\hat{\\jmath}\\\\\n    \\vec{V} &= v_x \\, \\hat{\\imath} + v_y \\, \\hat{\\jmath}\\\\\n    \\vec{\\omega} &= \\omega \\, \\hat{k}.\n\\end{align*}\nIn this special case, the velocity is\n\\[\n    \\vec{v} = \\frac{d\\vec{r}}{dt} = (v_x - y \\, \\omega) \\, \\hat{\\imath} + (v_y + x \\, \\omega) \\, \\hat{\\jmath}.\n\\]\n\\\\\nNow for a given configuration $(v_x, v_y, \\omega)$ it is possible to compute the two-dimensional velocity of any point on the robot. \n\n\\subsection{Differential Drives}\n\nPerhaps the simplest practical mobile robot drive configuration is a differential drive with two normal wheels. These wheels have radius $R$ and are spaced $2l$ units apart. Let the center of rotation (i.e., the midpoint of the wheel positions) be the origin with the wheel axles laying parallel to the y-axis. With this setup, the wheel center positions are \\((\\pm l, 0)\\).\\\\\n\\\\\nUsing the results of the previous subsection, the desired velocities are\n\\begin{align*}\n    \\vec{v}_l &= (v_x - l \\, \\omega) \\, \\hat{\\imath} + v_y \\, \\hat{\\jmath}\\\\\n    \\vec{v}_r &= (v_x + l \\, \\omega) \\, \\hat{\\imath} + v_y \\, \\hat{\\jmath}.\n\\end{align*}\nFurthermore, the orientation of the wheels gives us the tangential velocities in terms of the wheel angular velocities\n\\begin{align*}\n    \\pvec{v}_l &= \\omega_l R \\, \\hat{\\imath}\\\\\n    \\pvec{v}_r &= \\omega_r R \\, \\hat{\\imath}.\n\\end{align*}\nFor traction wheels, the corresponding velocities must \\textit{exactly} match. This yields the equations\n\\begin{align*}\n    v_x - l \\, \\omega &= \\omega_l R \\\\\n    v_x + l \\, \\omega &= \\omega_r R \\\\\n    v_y &= 0 \\\\\n    v_y &= 0.\n\\end{align*}\nFrom this we can solve to obtain the forward and inverse kinematics\n\\begin{equation*}\n    \\begin{aligned}[c]\n        v_x &= \\frac{R}{2}(\\omega_l + \\omega_r) \\\\\n        v_y &= 0 \\\\\n        \\omega &= \\frac{R}{2l}(\\omega_r - \\omega_l),\n    \\end{aligned}\n    \\qquad\\qquad\n    \\begin{aligned}[c]\n        \\omega_l &= \\frac{v_x - l \\, \\omega}{R} \\\\\n        \\omega_r &= \\frac{v_x + l \\, \\omega}{R}.\n    \\end{aligned}\n\\end{equation*}\nIn matrix form, these relations are\n\\begin{equation*}\n    \\begin{bmatrix}\n        v_x \\\\\n        v_y \\\\\n        \\omega\n    \\end{bmatrix}\n    =\n    \\frac{R}{2}\n    \\begin{bmatrix}\n        1 & 1 \\\\\n        0 & 0 \\\\\n        -\\frac{1}{l} & \\frac{1}{l}\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\omega_l \\\\\n        \\omega_r\n    \\end{bmatrix},\n    \\qquad\\qquad\n    \\begin{bmatrix}\n        \\omega_l \\\\\n        \\omega_r\n    \\end{bmatrix}\n    =\n    \\frac{1}{R}\n    \\begin{bmatrix}\n        1 & 0 & -l\\\\\n        1 & 0 & l\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        v_x \\\\\n        v_y \\\\\n        \\omega\n    \\end{bmatrix}.\n\\end{equation*}\nThese same kinematics can be applied to differential drives with multiple wheels per side. However, you'll quickly realize that it is no longer possible to satisfy all the constraints. To rotate properly, the wheels must overcome static friction and slide parallel to the wheel axis. This slippage can be mathematically accounted for by treating this scrub direction as a passive degree of freedom (like an omni wheel) as we'll see in the next section. With this assumption, the kinematics are the same as above with all motors on each side sharing the same velocity.\n\n\\subsection{Mecanum Drives}\n\nMecanum drives consist of four mecanum wheels with rollers at $45\\degree$ angles with respect to the axle positioned in a rectangle. Looking from above, the main diagonal wheels have counterclockwise-rotated rollers, while the alternate diagonal wheels have clockwise-rotated rollers. The careful combination of these two different directions enables omnidirectional movement. The track width (distance between opposing wheels) is $2l$ and the wheelbase (distance between adjacent wheels) is $2b$. Place the center of rotation at the origin as before with wheel center positions \\((\\pm l, \\pm b)\\).\\\\\n\\\\\nUsing the same procedure as before, we obtain\n\\begin{align*}\n    \\vec{v}_{fl} &= (v_x - l \\, \\omega) \\, \\hat{\\imath} + (v_y + b \\, \\omega) \\, \\hat{\\jmath}\\\\\n    \\vec{v}_{bl} &= (v_x - l \\, \\omega) \\, \\hat{\\imath} + (v_y - b \\, \\omega) \\, \\hat{\\jmath}\\\\\n    \\vec{v}_{br} &= (v_x + l \\, \\omega) \\, \\hat{\\imath} + (v_y - b \\, \\omega) \\, \\hat{\\jmath}\\\\\n    \\vec{v}_{fr} &= (v_x + l \\, \\omega) \\, \\hat{\\imath} + (v_y + b \\, \\omega) \\, \\hat{\\jmath}.\n\\end{align*}\nComputing the tangential velocities from the angular velocities is bit trickier for mecanum wheels. The tangential force acts $45\\degree$ from the roller, resulting in a speed reduction of $\\sqrt{2}$. The direction of the velocity points perpendicular to the roller axis (viewed from above). Thus, the velocities are\n\\begin{align*}\n    \\pvec{v}_{fl} &= \\frac{R \\, \\omega_{fl}}{2} (\\hat{\\imath} - \\hat{\\jmath})\\\\\n    \\pvec{v}_{bl} &= \\frac{R \\, \\omega_{bl}}{2} (\\hat{\\imath} + \\hat{\\jmath})\\\\\n    \\pvec{v}_{br} &= \\frac{R \\, \\omega_{br}}{2} (\\hat{\\imath} - \\hat{\\jmath})\\\\\n    \\pvec{v}_{fr} &= \\frac{R \\, \\omega_{fr}}{2} (\\hat{\\imath} + \\hat{\\jmath}).\n\\end{align*}\nThe vectors can't be directly equated for non-square configurations due to the passive motion of the rollers. Instead we equate the portion of each vector in the tangential velocity direction. For example, the front left constraint is\n\\[\n    \\vec{v}_{fl} \\cdot \\pvec{v}_{fl} = \\pvec{v}_{fl} \\cdot \\pvec{v}_{fl}.\n\\]\nThe final system is\n\\begin{align*}\n    \\frac{R \\, \\omega_{fl}}{2}(v_x - l \\, \\omega - v_y - b \\, \\omega) &= \\frac{R^2\\omega_{fl}^2}{2}\\\\\n    \\frac{R \\, \\omega_{bl}}{2}(v_x - l \\, \\omega + v_y - b \\, \\omega) &= \\frac{R^2\\omega_{bl}^2}{2}\\\\\n    \\frac{R \\, \\omega_{br}}{2}(v_x + l \\, \\omega - v_y + b \\, \\omega) &= \\frac{R^2\\omega_{br}^2}{2}\\\\\n    \\frac{R \\, \\omega_{fr}}{2}(v_x + l \\, \\omega + v_y + b \\, \\omega) &= \\frac{R^2\\omega_{fr}^2}{2}.\n\\end{align*}\nwhich yields the matrix kinematics\n\\begin{equation*}\n    \\begin{bmatrix}\n        v_x \\\\\n        v_y \\\\\n        \\omega\n    \\end{bmatrix}\n    =\n    \\frac{R}{4}\n    \\begin{bmatrix}\n        1 & 1 & 1 & 1 \\\\\n        -1 & 1 & -1 & 1 \\\\\n        -\\frac{1}{l+b} & -\\frac{1}{l+b} & \\frac{1}{l+b} & \\frac{1}{l+b}\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\omega_{lf} \\\\\n        \\omega_{lb} \\\\\n        \\omega_{rb} \\\\\n        \\omega_{rf}\n    \\end{bmatrix}\n    \\qquad\\qquad\n    \\begin{bmatrix}\n        \\omega_{lf} \\\\\n        \\omega_{lb} \\\\\n        \\omega_{rb} \\\\\n        \\omega_{rf}\n    \\end{bmatrix}\n    =\n    \\frac{1}{R}\n    \\begin{bmatrix}\n        1 & -1 & -(l + b) \\\\\n        1 & 1 & -(l + b) \\\\\n        1 & -1 & (l + b) \\\\\n        1 & 1 & (l + b)\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        v_x \\\\\n        v_y \\\\\n        \\omega\n    \\end{bmatrix}\n\\end{equation*}\n\n\\subsection{Swerve Drives}\nUnlike the previous drives, swerve drives have actuated wheel directions. Nevertheless, swerve kinematics can still be derived within the same framework. Let each wheel have coordinates $(x_i, y_i)$, orientation $\\phi_i$, tangential velocity $\\vec{v}_i$, and angular velocity $\\omega_i$.\\\\\n\\\\\nFor simplicity, we will assume the swerve wheels do not slip and directly equate the tangential velocities: $v_x - y_i \\, \\omega = R \\, \\omega_i \\operatorname{cos} \\phi_i$ and $v_y + x_i \\, \\omega = R \\, \\omega_i \\operatorname{sin} \\phi_i$. This gives the following inverse kinematics\\footnote{$\\operatorname{atan2}$ is the standard two-argument arctangent function available in most programming environments}:\n\\begin{align*}\n    \\phi_i &= \\operatorname{atan2} \\big( v_y + x_i \\, \\omega, \\; v_x - y_i \\, \\omega \\big)\\\\\n    \\omega_i &= \\frac{1}{R} \\sqrt{(v_x - y_i \\, \\omega)^2 + (v_y + x_i \\, \\omega)^2}\n\\end{align*}\n\nForward kinematics for a collection of multiple wheels can be computed by solving the corresponding overdetermined system.\n\n\\section{Odometry}\nThe previous section focused on finding the relationship between configuration and wheel velocities. This by itself is sufficient to employ the inverse kinematics for sending the appropriate control signals. However, the forward kinematics cannot be directly used for odometry. To localize the robot, the local velocities must be integrated into positions and transformed into the global frame.\n\n\\subsection{Constant Velocity Odometry}\nFor simplicity, this method assumes constant translational and rotational velocity over each measurement period. In practice, this is a good assumption so long as measurements are frequent enough (additionally, estimating acceleration or other higher order derivatives robustly from wheel position data is nontrivial).\\\\\n\\\\\nWithout loss of generality, we take the robot heading $\\theta$ to be $0$ initially. A measurement is then taken $\\Delta t$ time later. During this period the robot's global velocity is\n$$\n\\begin{bmatrix}\n    \\dot{x}_G \\\\\n    \\dot{y}_G \\\\\n    \\dot{\\theta}_G\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n    \\operatorname{cos} \\theta & -\\operatorname{sin} \\theta & 0 \\\\\n    \\operatorname{sin} \\theta & \\operatorname{cos} \\theta & 0 \\\\\n    0 & 0 & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\dot{x}_R \\\\\n    \\dot{y}_R \\\\\n    \\dot{\\theta}_R\n\\end{bmatrix}.\n$$\nIntegrating this over time gives\n$$\n\\begin{bmatrix}\n    \\Delta x_G \\\\\n    \\Delta y_G \\\\\n    \\Delta \\theta_G\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n    \\frac{\\operatorname{sin} \\Delta \\theta_R}{\\Delta \\theta_R} & -\\frac{1 - \\operatorname{cos} \\Delta \\theta_R}{\\Delta \\theta_R} & 0 \\\\[4pt]\n    \\frac{1 - \\operatorname{cos} \\Delta \\theta_R}{\\Delta \\theta_R} & \\frac{\\operatorname{sin} \\Delta \\theta_R}{\\Delta \\theta_R} & 0 \\\\[4pt]\n    0 & 0 & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\Delta x_R \\\\\n    \\Delta y_R \\\\\n    \\Delta \\theta_R\n\\end{bmatrix}.\n$$\nThis can then be rotated and added to the previous estimate to complete the update\n$$\n\\begin{bmatrix}\n    x_{G,\\,t+1} \\\\\n    y_{G,\\,t+1} \\\\\n    \\theta_{G,\\,t+1}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n    x_{G,\\,t} \\\\\n    y_{G,\\,t} \\\\\n    \\theta_{G,\\,t}\n\\end{bmatrix}\n+\n\\begin{bmatrix}\n    \\operatorname{cos} \\theta_{G,\\,t} & -\\operatorname{sin} \\theta_{G,\\,t} & 0 \\\\\n    \\operatorname{sin} \\theta_{G,\\,t} & \\operatorname{cos} \\theta_{G,\\,t} & 0 \\\\\n    0 & 0 & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\frac{\\operatorname{sin} \\Delta \\theta_R}{\\Delta \\theta_R} & -\\frac{1 - \\operatorname{cos} \\Delta \\theta_R}{\\Delta \\theta_R} & 0 \\\\[4pt]\n    \\frac{1 - \\operatorname{cos} \\Delta \\theta_R}{\\Delta \\theta_R} & \\frac{\\operatorname{sin} \\Delta \\theta_R}{\\Delta \\theta_R} & 0 \\\\[4pt]\n    0 & 0 & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\Delta x_R \\\\\n    \\Delta y_R \\\\\n    \\Delta \\theta_R\n\\end{bmatrix}.\n$$\n\n\\subsection{Tracking Wheels}\nTracking wheels are passive omni wheels intended solely for odometry. Each wheel has an arbitrary position $(x_i, y_i)$ and orientation $\\phi_i$ in the robot frame. Similar to swerve, the tangential velocities of each wheel are $\\vec{v}_i = (v_x - y_i \\, \\omega) \\, \\hat{\\imath} + (v_y + x_i \\, \\omega) \\, \\hat{\\jmath}$ and $\\pvec{v}_i = R \\, \\omega_i (\\operatorname{cos} \\phi_i \\, \\hat{\\imath} + \\operatorname{sin} \\phi_i \\, \\hat{\\jmath})$. \n$$\n    \\omega_i = \\frac{1}{R}\\Big[v_x \\operatorname{cos} \\phi_i + v_y \\operatorname{sin} \\phi_i + \\omega \\, (x_i \\operatorname{sin} \\phi_i - y_i \\operatorname{cos} \\phi_i)\\Big]\n$$\nIf placed properly, three tracking wheels are sufficient to determine the $(v_x, v_y, \\omega)$ configuration:\n$$\n\\begin{bmatrix}\n    \\omega_1\\\\\n    \\omega_2\\\\\n    \\omega_3\n\\end{bmatrix}\n=\n\\frac{1}{R}\n\\begin{bmatrix}\n    \\operatorname{cos} \\phi_1 & \\operatorname{sin} \\phi_1 & x_1 \\operatorname{sin} \\phi_1 - y_1 \\operatorname{cos} \\phi_1 \\\\\n    \\operatorname{cos} \\phi_2 & \\operatorname{sin} \\phi_2 & x_2 \\operatorname{sin} \\phi_2 - y_2 \\operatorname{cos} \\phi_2 \\\\\n    \\operatorname{cos} \\phi_3 & \\operatorname{sin} \\phi_3 & x_3 \\operatorname{sin} \\phi_3 - y_3 \\operatorname{cos} \\phi_3 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    v_x\\\\\n    v_y\\\\\n    \\omega\n\\end{bmatrix}\n$$\n$$\n\\begin{bmatrix}\n    \\Delta \\theta_1\\\\\n    \\Delta \\theta_2\\\\\n    \\Delta \\theta_3\n\\end{bmatrix}\n=\n\\frac{1}{R}\n\\begin{bmatrix}\n    \\operatorname{cos} \\phi_1 & \\operatorname{sin} \\phi_1 & x_1 \\operatorname{sin} \\phi_1 - y_1 \\operatorname{cos} \\phi_1 \\\\\n    \\operatorname{cos} \\phi_2 & \\operatorname{sin} \\phi_2 & x_2 \\operatorname{sin} \\phi_2 - y_2 \\operatorname{cos} \\phi_2 \\\\\n    \\operatorname{cos} \\phi_3 & \\operatorname{sin} \\phi_3 & x_3 \\operatorname{sin} \\phi_3 - y_3 \\operatorname{cos} \\phi_3 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\Delta x_R\\\\\n    \\Delta y_R\\\\\n    \\Delta \\theta_R\n\\end{bmatrix}\n$$\nFor example, take the common configuration of two tracking wheels placed parallel to the robot's $x$-axis at $(0,\\pm y_0)$ and a third placed parallel to the robot's $y$-axis at $(x_0,0)$. For simplicity, all wheels point in the positive direction of their corresponding axis. This gives the following matrices:\n\\begin{equation*}\n    \\begin{bmatrix}\n        \\Delta \\theta_1\\\\\n        \\Delta \\theta_2\\\\\n        \\Delta \\theta_3\n    \\end{bmatrix}\n    =\n    \\frac{1}{R}\n    \\begin{bmatrix}\n        1 & 0 & -y_0 \\\\\n        1 & 0 & y_0 \\\\\n        0 & 1 & x_0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\Delta x_R\\\\\n        \\Delta y_R\\\\\n        \\Delta \\theta_R\n    \\end{bmatrix}\n\\end{equation*}\n\\begin{equation*}\n    \\begin{bmatrix}\n        \\Delta x_R\\\\\n        \\Delta y_R\\\\\n        \\Delta \\theta_R\n    \\end{bmatrix}\n    =\n    \\frac{R}{2y_0}\n    \\begin{bmatrix}\n        y_0 & y_0 & 0\\\\\n        x_0 & -x_0 & 2y_0\\\\\n        -1 & 1 & 0\\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\Delta \\theta_1\\\\\n        \\Delta \\theta_2\\\\\n        \\Delta \\theta_3\n    \\end{bmatrix}\n    \\quad\\leftrightarrow\\quad\n    \\begin{aligned}[c]\n        \\Delta x_R &= \\frac{R}{2}(\\Delta \\theta_1 + \\Delta \\theta_2)\\\\\n        \\Delta y_R &= R\\bigg[\\frac{x_0}{2y_0}(\\Delta \\theta_1 - \\Delta \\theta_2) + \\Delta \\theta_3\\bigg]\\\\\n        \\Delta \\theta_R &= \\frac{R}{2y_0}(\\Delta \\theta_2 - \\Delta \\theta_1)\n    \\end{aligned}\n\\end{equation*}\nTwo tracking wheels and a heading sensor is also sufficient for localization.\n$$\n\\begin{bmatrix}\n    \\Delta \\theta_1\\\\\n    \\Delta \\theta_2\\\\\n    \\Delta \\theta_3\n\\end{bmatrix}\n=\n\\frac{1}{R}\n\\begin{bmatrix}\n    \\operatorname{cos} \\phi_1 & \\operatorname{sin} \\phi_1 & x_1 \\operatorname{sin} \\phi_1 - y_1 \\operatorname{cos} \\phi_1 \\\\\n    \\operatorname{cos} \\phi_2 & \\operatorname{sin} \\phi_2 & x_2 \\operatorname{sin} \\phi_2 - y_2 \\operatorname{cos} \\phi_2 \\\\\n    0 & 0 & R\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\Delta x_R\\\\\n    \\Delta y_R\\\\\n    \\Delta \\theta_R\n\\end{bmatrix}\n$$\n\n\\end{document}", "meta": {"hexsha": "2b4b5150cee6b86fcf973b83f9ebc84e4aa54966", "size": 16735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/pdf/Mobile_Robot_Kinematics_for_FTC.tex", "max_stars_repo_name": "acmerobotics/motion-planner", "max_stars_repo_head_hexsha": "448a3adb2d2f821aed9e42998ef216ca4732f690", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 140, "max_stars_repo_stars_event_min_datetime": "2018-08-07T00:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T18:17:25.000Z", "max_issues_repo_path": "doc/pdf/Mobile_Robot_Kinematics_for_FTC.tex", "max_issues_repo_name": "acmerobotics/motion-planner", "max_issues_repo_head_hexsha": "448a3adb2d2f821aed9e42998ef216ca4732f690", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2018-08-09T03:13:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T20:25:36.000Z", "max_forks_repo_path": "doc/pdf/Mobile_Robot_Kinematics_for_FTC.tex", "max_forks_repo_name": "acmerobotics/motion-planner", "max_forks_repo_head_hexsha": "448a3adb2d2f821aed9e42998ef216ca4732f690", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 65, "max_forks_repo_forks_event_min_datetime": "2018-08-10T03:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T22:12:41.000Z", "avg_line_length": 43.0205655527, "max_line_length": 600, "alphanum_fraction": 0.6487600837, "num_tokens": 5511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6568514173354267}}
{"text": "\\lab{Value Function Iteration}{Value Function Iteration}\n\\newcommand\\ve{\\varepsilon}\n\\objective{This section teaches the fundamentals of Dynamic Programming using value function iteration.}\n\n%Often it is of interest to optimize decision making in some sequential process.  For example, an oil company may need to decide\n%how much oil to excavate and sell each month as prices change, a person entering retirement may need to decide how much of their\n%savings to spend each year, or a model of economic growth may require a decision about how much to invest in capital versus how\n%much to spend each year.  In this lab we will formulate a general dynamic optimization problem.  We will explore techniques for\n%solving such a problem with both finite and infinite time horizons.\n\nPreviously we have optimizated a single decision or question.\nIn this lab we will optimize a sequence of decisions.\nThe techniques to solve these problems are called dynamic optimization.\n\nDynamic optimization provides different answers than optimization techniques we have studied previously.\nFor example, an oil company might want to know how much oil to excavate in one day in order to maximize profit.\nIf we only consider today, then the answer is to excavate and sell as much as possible.\nIf each day is considered in isolation, then the strategy to optimize profit is to maximize excavation in order to maximize profits.\nHowever, in reality oil prices change from day to day and as supply increases or decreases, and so maximizing excavation may in fact lead to less profit.\nOn the other hand, if the oil company considers how production on one day will affect subsequent decisions, they may be able to maximize their profits.\nIn this lab we will explore techniques for solving such a problem.\n\n\\section*{The Cake Eating Problem}\n\nRather than maximizing oil profits, we will focus on solving a general problem that can be applied in many areas called the cake eating problem.\nGiven a cake of a certain size, how do we eat it to maximize our enjoyment (in other words, our utility) over time?\nSome people may prefer to eat all of their cake at once, and not save any for later.\nOthers may prefer to only eat a little bit at a time.\nThese preferences will be expressed precisely using a utility function.\nOur task is to find an optimal strategy given an increasing utility function, $u$.\nPrecisely, given a cake of size $W_0$ and some amount of consumption $c_0 \\in [0, W_0]$, the utility gained is given by\n\\[\nu(c_0).\n\\]\n\nIf we want to maximize utility over one time period, we will consume the entire cake.  How do we maximize utility over several days?\n\n\\subsection*{Discount Factors}\n\nA person or firm will typically have a preference for saving or consuming.\nFor example, a dollar today can be invested and yield interest, whereas a dollar received next year will not include the accrued interest.\nIn this lab, cake now will yield more utility than cake in the future.\nWe can model this by multiplying future utility by a discount factor $\\beta \\in (0,1)$.\nFor example, if we were to consume $c_0$ cake at time $0$ and $c_1$ cake at time $1$, then the total utility gained will be\n\\[\nu(c_0) + \\beta u(c_1).\n\\]\n\n\\subsection*{The Optimization Problem}\n\nIf we are to consume a cake of size $W_0$ over $T$ time periods, then we can represent our consumption at each step as a vector\n\\[\n(c_0, c_1, ... , c_T)\n\\]\nwhere\n\\[\n\\sum_{i=1}^T c_i = W_0.\n\\]\n\nWe will call such a vector a policy.  Thus, our optimization problem is to\n\n\\begin{align*}\n\\mbox{maximize }  & \\sum_{t=0}^T \\beta^t u(c_t) \\\\\n\\mbox{subject to } & \\sum_{t=0}^T c_t = 1, c_t \\geq 0.\n\\end{align*}\n\n\\begin{problem}\n\nIt might seem obvious what sort of policy will yield the most utility, but the truth may surprise you.\nSee Figure \\ref{fig:diff_pols} for some examples.\nWrite a function called \\li{graph_policy} will accepts\n\\begin{itemize}\n\\item a policy,\n\\item a utility function, and\n\\item a discount factor;\n\\end{itemize}\nand returns the total utility gained with the policy input.\nAlso display a plot of the total utility gained over time.\nEnsure that the policy that the user passes in sums to 1.\nOtherwise, raise an \\li{InputError}.\n\n%\\begin{figure}\n%\\begin{subfigure}{.5\\textwidth}\n%    \\includegraphics[width=\\textwidth]{fixed_time.pdf}\n%\\end{subfigure}\n%\\begin{subfigure}{.5\\textwidth}\n%    \\includegraphics[width=\\textwidth]{fixed_w.pdf}\n%\\end{subfigure}\n%\\caption{Slices of the finite horizon value function for fixed values of $t$ and $W$, respectively.}\n%\\label{fig:valueslices}\n%\\end{figure}\n\\end{problem}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{diff_policies.pdf}\n\\caption{Plots for various policies with a square root utility function.  Policy 1 eats all the cake in the first step while policy 2 eats all the cake in the last step.  Their difference in utility demonstrate the effect of the discount factor on waiting to eat.  Policy 3 eats the same amount of cake at each step, while policy 4 starts eating a lot of cake but eats less and less as time goes on and the cake runs out.}\n\\label{fig:diff_pols}\n\\end{figure}\n\n\\section*{The Value Function}\n\nWe have posed the cake eating problem as an optimization problem, but we do not have a good way to solve it yet.\nTo that end, we introduce the value function.\nThe value function  $V(a,b,W)$ is the maximal value of\n\n\\begin{align*}\n\\mbox{maximize } & \\sum_{t=a}^b \\beta^tu(c_t) \\\\\n\\mbox{subject to } & \\sum_{t=a}^b c_t = W, c_t \\geq 0\n\\end{align*}\n\nfor $t = a, a+1, ... b$.\nIn other words, it gives the utility gained from following an optimal policy from time $a$ to time $b$.  \n%The Value function gives how much utility that a policy from time $a$ to $b$ yields given a cake of size $W$.\nSo if we start with a cake of size $W_0$ at time $0$ and have half the cake left at time $t$, then $V(t, T, \\frac{W_0}{2})$ gives how much utility we will gain by proceeding optimally from $t$.\n\nThus, if we know what the optimal policy in the future is, we can figure out the optimal policy for the present, since\n\n\\[\nV(t, T, W_{t}) = \\max_{W_{t+1}} u(W_{t} - W_{t+1}) + \\beta V(t+1, T, W_{t+1}).\n\\]\nRecall that we know what the utility function $u$ is, as well as $\\beta$.\nAlso, note that our consumption at time $t$ is given by the amount of cake at the beginning of time $t$ minus the amount of cake at the beginning of time $t+1$, or $W_t - W_{t+1}$.\n\nIn other words, if we know how to maximize utility in the future, we only need to maximize utility in the now in order to maintain optimality.\nSo if we know what $V(t+1, T, W_{t+1})$ yields for all possible $W_{t+1}$, then we choose the best $W_{t+1}$ to figure out what the value function yields in the present.\nThus, if we can evaluate the value function, we can also determine the optimal policy.\n\n\\subsection*{Solving the Optimization Problem}\n\n\\begin{problem}\n\nIn this problem we will write a helper function that will help us choose the optimal policy.\nWe will assume our discritized cake has volume $1$ and an integer $N$ equaly-sized pieces.\nWrite a method that accepts $N$ and a utility function.\nCreate a vector whose entries correspond to possible amounts of cake given the discretization.\nFor example, if we wanted to consider a cake split into 4 pieces, the vector should be\n\\[\nw = (0, 0.25, 0.5, 0.75, 1.0)\n\\]\nReturn a matrix whose $ij^{th}$ entry is the amount of utility gained by starting with $i$ cake pieces and ending with $j$ pieces.\nIn other words, the $ij^{th}$ entry should be $u(w_i - w_j)$.\nLet the default utility function be the square root function.\nSet impossible situations to 0 (i.e., eating more than you have).\nWe call the resulting matrix the consumption matrix.\n\n\\end{problem}\n\nHow can we find the value function if we do not know the optimal policy?\nSo far in our problem, we do not know how to start eating in order to maximize utility.\nHowever, we know that we do not want to have any cake left over when time runs out.\nThus, the amount of utility we gain from having $W_{T-1}$ cake at time $T-1$ is given by $u(W_{T-1})$, and so we know $V(T-1, T, W_{T-1})$ given a choice of $W_{T-1}$.\nFor example, if we had a cake split into 4 pieces and wanted to eat it in $T=4$ time intervals, we could express what we know about the value function from time $T$ to $T+1$ as\n\n\\[\n\\begin{bmatrix}\n* & * & * & * & u(1) & 0 \\\\\n* & * & * & * & u(0.75) & 0 \\\\\n* & * & * & * & u(0.5) & 0 \\\\\n* & * & * & * & u(0.25) & 0 \\\\\n* & * & * & * & :w\nu(0) & 0 \\\\\n\\end{bmatrix}\n\\]\n\nwhere the $ij^{th}$ entry gives the value of having $w_j$ cake at time $j$ and $*$ represents unknown values.  \nThis is called the value function matrix, and note that it is dimension $N \\times T+2$, since we want columns for $t = 0$ and $t = T+1$.\nThe last column is there to show that after time $4$, there is no value in having any cake.\n\n\\begin{problem}\nWrite a function that accepts \n\\begin{itemize}\n\\item $T$ (the number of time steps),\n\\item $N$ (the number of pieces into which we split our cake), \n\\item a discount factor $\\beta$, and\n\\item a utility function;\n\\end{itemize}\nand returns the value function matrix with the last two columns filled in.\nLet the default utility function be the square root function.\n\\end{problem}\n\nAs we mentioned in the previous section, if we know what the value function evaluates to in the future, we can evaluate the value function in the present.\nIf we are at time $t$, and we know what the value function evaluates to at time $t+1$ (given by the appropriate column of the value function matrix we have built), then we can calculate\n\\[\nV_t(W_t) = u(W_{t} - W_{t+1}) + \\beta V_{t+1}(W_{t+1})\n\\]\nfor all possible values of $W_t$ and $W_{t+1}$.\nThis will produce an $N \\times N$ matrix giving the value of all possible values of starting with a cake of size $W_t$ and finishing with size $W_{t+1}$.\nWe call this matrix the current value matrix.\n%If we choose the maximal value of each row, then we know the optimal amount of cake to end up with a the end of time $t$, and thus how much cake to eat.\nThe largest entry of each row then is the optimal value that the value function can attain at this step, given that we start with the amount of cake that corresponds to the row.\nThus, the maximal values of each row become the column of the value function matrix at time $t$ and if we know one column of the value matrix, we may iterate backwards to fill the rest of it in.\nNote that we can start this process with just the column of zeros that we know occupies the last column of the value function matrix.\n\n\\begin{problem}\nModify the solution to the previous problem to determine the entire value function matrix.\nInitialize the matrix as zeros, and starting from the next to last column \n\\begin{itemize}\n\\item calculate the current value matrix,\n\\item find the largest value in each row, and\n\\item fill in the column with these values.\n\\end{itemize}\n\\end{problem}\n\nNow that the value function matrix is filled in we could say that the optimization problem is solved in some sense.\nHowever, it is not immediately apparent how to make decisions given the value function matrix only.\nWhat we really want is the optimal policy.\nIt turns out that we already calculated it in the previous problem - we just didn't keep track of it.\nRecall that we calculated a current value matrix for each column of the value matrix, and that the $ij^{th}$ entry of that matrix was the value of starting with $i$ pieces of cake and finishing with $j$ pieces of cake.\nThus, the policy for starting a time step with $i$ pieces of cake is $w_i - w_j$ (the vector $w = (w_1, ..., w_N)$ is the equal partition of the cake), where $j$ is the index of w that corresponds to the maximum value of row $i$ in the current value matrix.\nWe can use this information to fill out an $N \\times T+1$ policy matrix at the same time that we fill out the value matrix (T+1 because we inlcude $t=0$).\nThe $ij^{th}$ entry of the policy matrix tells us how much cake to eat if we start with $w_i$ cake at time $j$. \n\n\\begin{problem}\nModify the solution to the previous problem to determine the policy matrix.\nInitialize the matrix as zeros and fill it in starting from the last column at the same time that you determining the value function matrix.\n\\end{problem}\n\n\\begin{problem}\nThe $ij^{th}$ entry of the policy matrix tells us how much cake to eat at time $j$ if we start with $i$ pieces.\nUse this information to find the optimal policy for starting with a cake of size 1 split into $N$ pieces, and then plot the policy.\n\\end{problem}\n\nA summary of the arrays generated in this lab is given below, in the order that they were generated in the lab:\n\nConsumption matrix: Equal to $u(u_i - w_j)$, the utility gained when you start with $i$ pieces and end with $j$ pieces. \n\nValue Function matrix: How valuable is it to have $w_i$ pieces at time $j$.\n\nCurrent Value matrix: How valuable is each possible decision at time $t$.\n\nPolicy matrix: The amount of cake we decide to eat at time $t$.\n\n\n\\begin{comment}\n%\n% This is the old version of the lab.  I am keeping it in for now.\n% If we wish to expand this lab then this material may help write\n% more sections, i.e. infinite horizon porblems.\n%\n\n\\section*{The Sequential Problem, Finite Horizon}\nSuppose there are time periods $t=0,1,\\ldots, T$ and at each time period we take an action $c_t$. Furthermore, at the beginning\nof each time period $t$ we are in some state $W_t$.  In many cases $W_t$ might represent an available resource, such as money.\nAt each time we receive some reward, $u(W_t,c_t)$, for taking action $c_t$ given state $W_t$.  We assume that rewards are worth\nmore now than later. We let $\\beta\\in (0,1)$ represent what is called the discount factor, which gives the ratio of preference for\nrewards today versus rewards tomorrow.  For example, receiving a dollar today is preferable to receiving a dollar in a year\nbecause taking a dollar today and putting it into a savings account results in having more than a dollar in a year.  Lastly, over\ntime our state variable $W_t$ changes according to some rule depending on the previous state and our actions,\n\\begin{equation}\n\\label{motion}\nW_{t+1} = g(W_t,c_t).\n\\end{equation}\nEquation \\eqref{motion} is sometimes referred to as the law of motion, as it describes how we move from state to state.\nMathematically such a problem can be represented as follows:\n\\begin{equation*}\n\\text{maximize} \\sum_{t=0}^T \\beta^t u(W_t,c_t) \\quad \\text{s.t.} \\quad W_{t+1} = g(W_t,c_t)\n\\end{equation*}\nwhere our initial state, $W_0$, is given.  There may also be restrictions on our choices $c_t$.  For example, in many applications\nthe state $W_t$ represents the amount of some resource available, and $c_t$ represents the amount we use up in time period $t$.\n In this case we would require $c_t \\in [0,W_t]$.\n\nFor simplicity, lets assume that $u$ is a function of $c_t$ only (this is often, though not always, the case in practice).\n First let's consider the case that $T=0$.  So we maximize\n\\begin{equation}\\label{1perprob}\nu(c_0)\n\\end{equation}\nover $c_0 \\in [0,W_0]$.  In most cases $u$ is increasing, which we will assume here.  In this case it will be optimal to choose\n the largest value of $c_0$ possible, that is, $c_0 = W_0$.  Thinking of $W_0$ as our available resources, this simply means\n that if we don't have future periods to consider, we will use all of it.\n\nIn fact, this is always true in the last period.  In a problem with $T$ periods we know that we will use all of our resources\nremaining in period $T$.  Consider the two period problem:\n\\begin{equation}\n\\label{2perprob}\n\\max \\, \\{u(c_0) + \\beta u(c_1)\\}\n\\end{equation}\nwhere $c_0 \\in [0,W_0]$, $c_1 \\in [0,W_1]$ and $W_1 = g(W_0,c_0)$.  We know that in the last period we will use all of our\nremaining resources, so $c_1 = W_1=g(W_0,c_0)$.  Substituting gives\n\\begin{equation}\n\\label{2perproba}\n\\max \\, \\{u(c_0) + \\beta u(g(W_0,c_0))\\}.\n\\end{equation}\nNow we need only determine $c_0$.  Taking the derivative of \\eqref{2perproba} with respect to $c_0$ and setting equal to zero\ngives the first order condition\n\\begin{equation}\n\\label{FOC}\nu'(c_0) = -\\beta u'(g(W_0,c_0))g_c(W_0,c_0)\n\\end{equation}\nwhere $g_c$ is the partial derivative of $g$ with respect to $c_0$.\n\nGiven a specific form for $u$ we could solve for $W_1$ and obtain the optimal solution.  In fact, we can solve a problem of\nany length $T$ in this manner, by starting at the last time period and working backward.  We know that $W_{T+1} = 0$.  Working\nbackward in time we obtain an equation at each time step $t<T$ by taking the derivative with respect to $c_t$ and setting the equation equal to zero.  This process is called backward induction.  The equations at each time step, such as equation \\eqref{FOC}, are sometimes called the inter-temporal Euler equations.  These equations, along with $c_T = W_T$, make $T+1$ equations to go with our $T+1$ unknowns $\\{c_0,c_1,c_2,\\ldots,c_T\\}$, where we can use the law of motion \\eqref{motion} to relate the $c_t$ and $W_t$\n\n\\section*{The Recursive Problem, Finite Horizon}\nApproaching the problem sequentially like this can be somewhat messy.  The dynamic programming approach we consider now is more\neasily adaptable to many situations.  The key to the dynamic programming approach is to define our optimization problem in terms\n of subproblems.  Notice that if we are in time period $t$, we face a problem of exactly the same form as the problem at time\n $0$.  We are in some state $W_t$, and want to maximize the sum from $t$ to $T$.  With this idea in mind, we define a function\n  $V_t(W_t)$ called the value function.  The function $V_t$ gives the value of entering time $t$ in state $W_t$ and making\n  optimal decisions moving forward.  So\n\\begin{equation*}\nV_{t-1}(W_{t-1}) = \\max_{c_t} \\left\\{u(c_{t-1}) + \\beta V_t(g(W_{t-1},c_{t-1}))\\right\\}.\n\\end{equation*}\nThis is called the Bellman Equation.  The key to this formulation is that we decide what to do in period $t-1$ with the\nassumption that our actions in the remaining periods will be optimal.  This is called the principal of optimality.\n\nLet us consider a specific example from economics called The Cake Eating Problem.  Suppose $W_t$ represents the amount of\ncake available at time $t$.  At each time period we can choose how much to consume.  What we eat, $c_t$, gives us a reward.\nWhat we save, $W_t-c_t$, does not give us a reward (until it is eaten in a later period).  The law of motion \\eqref{motion}\nbecomes\n\\begin{equation}\\label{LOM_EX}\nW_{t+1} = g(W_t,c_t) = W_t-c_t\n\\end{equation}\n\nNow we have completely defined the problem.  The Bellman Equation is\n\\begin{equation*}\nV_{t-1}(W_{t-1}) = \\max_{c_t} \\left\\{u(c_{t-1}) + \\beta V_t(W_{t-1}-c_{t-1})\\right\\}.\n\\end{equation*}\nNotice that by the law of motion, each $c_t$ is determined by $W_t$ and $W_{t+1}$.\nIn fact, rearranging \\eqref{LOM_EX}, we have\n\\begin{equation*}\nc_t = W_t - W_{t+1}.\n\\end{equation*}\nWe can therefore rewrite the value function as\n\\begin{equation}\nV_{t-1}(W_{t-1}) = \\max_{W_t} \\left\\{u(W_{t-1} - W_{t}) + \\beta V_t(W_t)\\right\\}.\n\\label{cake_valfn}\n\\end{equation}\n\nWe see that determining the optimal actions $c_t$ is equivalent to determining the optimal states $W_{t}$ in the\nabove formulation. The solution to this\nproblem is often called a \\emph{policy function}.  A policy function determines an action based on the current\nstate.  Denoting the policy function by $\\psi$, this can be written as\n\\begin{equation*}\nW_{t+1}=\\psi_t \\left(W_t\\right).\n\\end{equation*}\nThe policy function gives the optimal amount of cake to leave for the next period (equivalent to the amount of consumption) given\nthe amount of cake at the start of the period.  In other words, it determines the choice of $W_t$ that satisfies the $\\max$\ncondition in \\eqref{cake_valfn}.\n\nAs before, we know that in the last time period we should not save anything.  So $V_{T+1}(W_{T+1}) = 0$, i.e. there is\nno value in leaving wealth for period $T+1$. Stated in another way, our action at time $T$ should be to eat all of the\nremaining cake $W_T$, so $W_{T+1} = \\psi_T(W_T) = 0$.\nPlugging this result into the Bellman Equation gives us $V_T(W_T) = u(W_T)$.\nNow consider the value function equation for period $T-1$:\n\\begin{align*}\nV_{T-1}(W_{T-1}) &= \\max_{W_T} \\left\\{u(W_{T-1} - W_T) + \\beta V_T(W_T)\\right\\} \\\\\n                 &= \\max_{W_T} \\left\\{u(W_{T-1} - W_T) + \\beta u(W_T)\\right\\}.\n\\end{align*}\nWe can determine this value by optimizing over $W_T$, where $0 \\leq W_T \\leq W_{T-1}$.\nContinuing backwards in this manner leads us to the solution of the original problem.\n\n\\begin{problem}\n\\label{prob:cake_prob}\nWe recommend reading the entire problem before beginning to work on it, as many questions may be addressed further on.  This applies to the other problems in this lab as well.\n\nFollow the steps below to solve the problem described above.  Take $u(c_t) = \\sqrt{c_t}$.\nYou will write a function called \\li{eatCake} that takes parameters $\\beta$ (the discount factor),\n$N$ (the number of discrete cake values to consider), $W_{max}$ (the original size of the cake,\nset to the default value of $1$), a keyword argument \\li{finite} (set to default value \\li{True}),\na keyword argument  $T$ (the number of time periods, set to\ndefault value \\li{None}), and a keyword argument \\li{plot}, which indicates whether or not\nto plot the computed results. The function should return arrays representing the value function and the\npolicy function (we describe how to compute these in the following steps).\n\\begin{enumerate}\n\\item Approximate the continuum of possible cake sizes by creating an array\nof evenly-spaced values that range from to 0 to $W_{max}$ inclusive.\nLet the number of possible cake values be given by $N$. In Python, this can be accomplished easily by\nusing the \\li{linspace} function in NumPy. You should obtain an array (call it $w$) of the form\n\\[\nw = (w_1, w_2, \\ldots, w_N),\n\\]\nwhere $w_1 = 0$ and $w_N = W_{max}$.\n\n\\item Note that in order to compute the value function, we need $u(W_{t-1}-W_t)$.\nWe will pre-compute all such possible values and store them in an array, as follows:\nCreate an $N$ by $N$ matrix that contains\nall possible values of $W_{t-1} - W_t$ (where $W_{t-1}$ corresponds to rows and $W_{t}$ to columns).  Make sure that\n$c_t \\geq 0$ is satisfied by replacing negative entries in the matrix with zeros.  Then take the square root to get a matrix\nof $u(W_{t-1}-W_t)$.  To make sure we do not choose $W_{t-1} - W_t < 0$ when maximizing, replace the corresponding entries of\nthe $u(W_{t-1}-W_t)$ matrix with a large negative number (e.g. $-10^{10}$). You should end up with a matrix whose\n$(i,j)$-th entry is equal to $\\sqrt{w_i - w_j}$ when $i \\geq j$, and is equal to $-10^{10}$ when $i < j$.\n\n\\item Next, create an $N$ by $T+2$ (corresponding to $t=0,1,\\ldots, T+1$) matrix representing the value function for a given\ntime $t$ and state $W_t$.  We can initialize it with zeros and begin filling in the columns starting with the last (which we\nknow is zeros), as explained below.\n\n\\item Now we are ready to iterate backward and compute the value function for each time period.  To find $V_T$, we first compute\n$u(W_T - W_{T+1}) + \\beta V_{T+1}(W_{T+1})$ for all values of $W_{T}$ and $W_{T+1}$.  This will result in an $N$ by $N$ matrix\nwhere the rows correspond to values of $W_{T}$ and the columns correspond to values of $W_{T+1}$.\n%Note that to compute this\n%we need a matrix representing $\\beta V_{T+1}(W_{T+1})$.  Because this quantity does not depend on $W_T$, its rows should be\n%equal.  To do this, we want to take $\\beta V_{T+1}(W_{T+1})$ as a row vector and stack this vector to create a matrix with\n%equal rows.  There are multiple ways to do this.  One is the \\li{np.repeat} function.  For example, if \\li{b} is a row vector\n%it could be used like the following.\n%\\begin{lstlisting}\n%b = [[1, 2, 3]]\n%np.repeat(b, 3, axis = 0)\n%array([[1, 2, 3],\n%[1, 2, 3],\n%[1, 2, 3]])\n%\\end{lstlisting}\n%In general, be careful about having the correct rows, columns, transposes, etc throughout your code.\n\nNow we maximize over choices of $W_{T+1}$ (choosing how much to save for the next period).  Then we will have a row vector\nrepresenting the value function for period $T$ across all possible $W_{T+1}$.  Iterate this procedure to fill in the value\nfunction for all $t=T+1,T,\\ldots, 0$.\n\n\\item In each iteration, you maximize to find the value function at time $t$.  Save the values of $W_{t+1}$ that achieve the\nmaximum.  The result is an $N$ by $T+1$ matrix whose $(n,t)$ entry gives the optimal amount of cake to leave for period\n$t+1$, given that we start period $t$ with the the $n$-th value of our vector of cake.  This is the policy function.\n\n\\item If the keyword argument \\li{plot} is set to \\li{True}, plot the surface of the Value and Policy functions.\nThis can be done by including the following import lines\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> from matplotlib import cm\n>>> from mpl_toolkits.mplot3d import Axes3D\n\\end{lstlisting}\nand using the following code:\n\\begin{lstlisting}\n>>> W = np.linspace(0, Wmax, N)\n>>> x = np.arange(0, N)\n>>> y = np.arange(0, T+2)\n>>> X, Y = np.meshgrid(x, y)\n>>> fig1 = plt.figure()\n>>> ax1 = Axes3D(fig1)\n>>> ax1.plot_surface(W[X], Y, np.transpose(V), cmap=cm.coolwarm)\n>>> plt.show()\n\n>>> fig2 = plt.figure()\n>>> ax2 = Axes3D(fig2)\n>>> y = np.arange(0,T+1)\n>>> X, Y = np.meshgrid(x, y)\n>>> ax2.plot_surface(W[X], Y, np.transpose(psi), cmap=cm.coolwarm)\n>>> plt.show()\n\\end{lstlisting}\nwhere \\li{W} is the vector of cake amounts, \\li{V} is the value function, and \\li{psi} is the policy function.\n\n\\item Return the arrays giving the value function and the policy function.\n\\end{enumerate}\n\nSolve the problem using cake size $1$, discount factor $\\beta = .9$, number of time periods $T = 10$, and number of\ndiscrete cake values $N = 100$. You should also try plotting the value and policy functions for fixed time periods across\n$W_t$, or for fixed $W_t$ across time,\n and make sure that these plots fit your intuition. See Figure \\ref{fig:valueslices}. Your output should\nagree with the figure.\n\\end{problem}\n\n\\begin{figure}\n\\begin{subfigure}{.5\\textwidth}\n    \\includegraphics[width=\\textwidth]{fixed_time.pdf}\n\\end{subfigure}\n\\begin{subfigure}{.5\\textwidth}\n    \\includegraphics[width=\\textwidth]{fixed_w.pdf}\n\\end{subfigure}\n\\caption{Slices of the finite horizon value function for fixed values of $t$ and $W$, respectively.}\n\\label{fig:valueslices}\n\\end{figure}\n\n\\section*{The Recursive Problem, Infinite Horizon}\\label{SecRecProbInFHor}\nNext we consider an infinite horizon problem.  For simplicity, we continue with the example from the previous section.\nSuppose that rather than optimizing over $t = 0,1,\\ldots,T$, we wish to optimize over an infinite time horizon:\n\\begin{equation*}\n\\text{maximize} \\sum_{t=0}^\\infty \\beta^t u(W_t,c_t) \\quad \\text{s.t.} \\quad W_{t+1} = g(W_t,c_t).\n\\end{equation*}\nSince at any time $t$, there are an infinite number of periods remaining, one might suspect that the optimal policy will\nnot depend on the current time $t$.\n\n\\begin{problem}\n\\label{prob:cake_prob2}\nCompute the solution to Problem \\ref{prob:cake_prob} with $T = 1000$, and the rest of the inputs the same.\nPlot the policy function across time for fixed $W_t = 1$.\nNotice that it is the same for all time periods, except those near the end time $T$.\n\\end{problem}\n\nAs suggested by the results of Problem \\ref{prob:cake_prob2},  the policy function for the infinite horizon problem does not\ndepend on the time $t$ (this can be proved).  That is, at any time $t$, the optimal decision depends only on the amount of cake\nat the beginning of the period, not the value of $t$.  So everything can now be written in terms of variables today and variables\ntomorrow. We will denote variables tomorrow with a ``$\\:'\\:$\".\n\\begin{equation}\n\\label{EqBellman}\nV\\left(W\\right) = \\max_{W'\\in[0,W]}\\:\\: \\left\\{u\\left(W - W'\\right) + \\beta V\\left(W'\\right)\\right\\}\n\\end{equation}\nNote that the value function $V$ on the left-hand-side of \\eqref{EqBellman} and on the right-hand-side are the same function.\n\nBecause the problem now has an infinite horizon, the nature of the solution is a little different. The solution to \\eqref{EqBellman}\nis a policy function $W'=\\psi(W)$ that creates a fixed point in $V$. In other words, the solution is a policy function $\\psi(W)$\nthat makes the function $V$ on the left-hand-side of \\eqref{EqBellman} equal the function $V$ on the right-hand-side.\n\nDefine $C$ as an operator on any value function $V_k\\left(W\\right)$. Let $C$ perform the following operation.\n\\begin{equation}\n\\label{EqContraction}\nC\\Bigl(V_k\\left(W\\right)\\Bigr) \\equiv \\max_{W'\\in[0,W]}\\:\\: \\left\\{u\\left(W-W'\\right) + \\beta V_k\\left(W'\\right)\\right\\}.\n\\end{equation}\nNote that the value function on the right-hand-side of \\eqref{EqContraction} and on the left-hand-side are the same function $V_k$,\nbut have different inputs--$W$ versus $W'$. The operator $C$ takes in a function $V_k$, and gives a new\nfunction which we will call $V_{k+1}$:\n\\begin{equation*}\nV_{k+1}\\left(W\\right) \\equiv C\\Bigl(V_k\\left(W\\right)\\Bigr).\n\\end{equation*}\nThe value function $V_{k+1}$ that results from the operation $C$ is not necessarily the same as the value function that the system\nbegan with ($V_k$). However, according to equation \\eqref{EqBellman} we seek a $V$ such that $C(V) = V$.  The solution, then, is the fixed point in $V$.\n\\begin{equation*}\nC\\Bigl(V_k\\left(W\\right)\\Bigr) = V_{k+1}\\left(W\\right) = V_k\\left(W\\right) = V\\left(W\\right)\n\\end{equation*}\n\nWhen trying to solve a fixed point equation, it is often very helpful to utilize the Contraction Mapping Principle, which\nguarantees the existence of a fixed point of a mapping, provided that the map sends any two distinct inputs to outputs\nthat are strictly closer to each other than the inputs, in a controlled way. This principle also provides a constructive\nway to obtain the fixed point, namely by iterating the map.\nFortunately, it can be shown that if $u(\\cdot)$ is real-valued, continuous, and bounded, $\\beta\\in(0,1)$, and that the constraint\nset $W'\\in[0,W]$ is nonempty, compact-valued, and continuous, then the operator $C$ is a contraction and thus we can obtain\na solution $V$ by iteration:\n\\begin{equation*}\n\\lim_{k\\rightarrow\\infty}\\: C^k\\Bigl(V_0\\left(W\\right)\\Bigr) = V_k(W) =  V\\left(W\\right)\n\\end{equation*}\nfor any $V_0$.\n\nRemember, in the infinite horizon problem both the value and policy functions do not depend on time.  Computationally, this means that\n the value and policy functions in the infinite horizon problem are one dimensional.\n\n\\begin{problem}\nExpand your \\li{eatCake} function to solve the Cake Eating Problem with an infinite time horizon. If the keyword argument\n\\li{finite} has the value \\li{True}, then your function should behave as in Problem \\ref{prob:cake_prob}, solving the finite\ntime horizon problem. However, if \\li{finite = False}, solve the infinite time horizon problem through the following steps.\nBoth problems will require you to pre-compute the values $u(W - W')$, where $W$ and $W'$ range over the set of discrete cake\namounts. Be sure to avoid replicating code by factoring it out.\nAs in Problem \\ref{prob:cake_prob}, take $u(c_t) = \\sqrt{c_t}$.\n\\begin{enumerate}\n\\item As in Problem \\ref{prob:cake_prob}, approximate the continuum of possible\ncake sizes by a column vector called $W$ that ranges from 0 to $W_{max}$ in $N$ steps.\n\n\\item \\label{item:step2} Initialize the value function V as a vector of zeros of length $N$.  This is $V_0$.  Perform one iteration\nof the contraction operation given in equation \\eqref{EqContraction} to get a new value function $V_1$ (this should be very similar\nto Problem 1).  Determine the resulting policy function $W' = \\psi_1\\left(W\\right)$.  [HINT: The policy function should be a vector\nof length $N$ of optimal future values of the cake $W'$ given the current value of the cake $W$, and $V_T$ should be an $N$-length\nvector representing the value of entering a period with cake size $W$.]\n\n\\item \\label{item:step3} Measure the distance between the two value functions as the sum of the\nsquared differences,\n\\begin{equation}\n\\label{EqDist}\n\\delta_1\\equiv \\norm{V_1\\left(W\\right) - V_0\\left(W'\\right)}_2^2 = \\left(V_1 - V_0\\right)^T\\left(V_1 - V_0\\right).\n\\end{equation}\nDefined in this way, $\\delta_1\\in [0,\\infty)$.\n\n%\\item \\label{item:step4} Take the resulting $V_1$ from \\ref{item:step2}, and perform the same contraction on it to generate $V_2$\n%and $\\psi_2$. That is, generate,\n%\\begin{equation*}\n%  V_2\\left(W\\right) = C\\Bigl(V_1\\left(W\\right)\\Bigr) = \\max_{W'\\in[0,W]}\\: u\\left(W - W'\\right) + \\beta V_1\\left(W'\\right)\n%\\end{equation*}\n%and the accompanying policy function $W'=\\psi_2\\left(W\\right)$. Calculate the accompanying distance measure for $\\delta_2$ using\n% the formula from \\eqref{EqDist} with the updated period subscripts. Compare $\\delta_2$ with $\\delta_1$ from \\ref{item:step3}.\n%\n%\\item \\label{item:step5} Repeat \\ref{item:step4} and generate $V_3$ and $\\psi_2$ by performing the contraction on $V_2$. Compare\n%$\\delta_3$ to $\\delta_2$ and $\\delta_1$.\n\n\\item Write a loop that performs the contraction operation from steps \\ref{item:step2} and \\ref{item:step3} iteratively\nuntil the distance measure is very small ($\\delta_k < 10^{-9}$).  The distance measure $\\delta_k$ being arbitrarily close to zero means\n you have converged to the fixed point $V_k = V_{k+1} = V$. (For fun, you can show that the policy function converges to the same\n function regardless of what you put in for your initial policy function value.)\n\n\\item If \\li{plot = True}, plot the converged policy function vector\n($y$-axis) as a function of the cake amounts ($x$-axis).\n\n\\item Return the value function and policy function arrays.\n\nCompute the value function and policy function for the infinite time horizon problem with\ncake size $1$, discount factor $\\beta = .9$, and number of\ndiscrete cake values $N = 100$. The plot you generate should agree with Figure \\ref{fig:infinitePolicy}.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{infiniteHorizon.pdf}\n\\caption{Policy function for infinite time horizon.}\n\\label{fig:infinitePolicy}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{convergence.pdf}\n\\caption{Due to the contraction mapping principle, $\\delta_k$ decreases as we perform iterations\nuntil it is small enough to meet our convergence tolerance.}\n\\end{figure}\n\n\\section*{Infinite Horizon, Stochastic, i.i.d.}\\label{SecRecProbInfinHorStochiid}\n\nIn practice, dynamic programming problems often involve some level of uncertainty.\nFor example, as time progresses prices may fluctuate, resources may vary, or preferences themselves may change.\n In this lab, we reexamine the cake eating problem, this time allowing for uncertainty.\n\nWe consider again the problem of optimizing a sequence of decisions over an infinite time horizon.\nWe assume that the individual's preferences deviate each period according to some ``shock\" $\\ve$,\nwhere $\\ve$ is a random variable.  We assume that the shock terms $\\ve$ for each time period are\nindependent and identically\ndistributed (i.i.d.).  In effect, this means the probabilities associated with the $\\ve$ are the\nsame for any time $t$ and do not depend on each other.  We assume for now that the $\\ve$ are\ndistributed normally with mean $\\mu$ and variance $\\sigma^2$.  The Bellman equation can be easily\nrewritten in the following way to incorporate the uncertainty,\n\\begin{equation}\\label{stoch_Bellman}\n   V\\left(W,\\ve\\right) = \\max_{W'\\in[0,W]}\\: \\{\\ve u\\left(W - W'\\right) +\n   \\beta E_{\\ve'}\\left[V\\left(W',\\ve'\\right)\\right]\\},\n\\end{equation}\nwhere $\\ve \\sim N(\\mu,\\sigma^2)$ and\n$E$ is the unconditional expectation operator over $\\ve$.  Note that now the value function depends\non two variables.  It represents the value of entering the period with $W$, the amount of cake,\nand a preference shock of $\\ve$.  For example, in a period where the realization of $\\ve$ is higher,\nwe will get more value from the cake eaten in the current period.  Because we do not know the value of\nthe shock in the next period $\\ve'$, we consider only the expected value for future time.\n\nAs it turns out, we can solve this problem in a manner similar to the infinite horizon deterministic cake-eating\nproblem considered in the Value Function Iteration lab.  It is worth noting that in this case,\n the value and policy functions will be two dimensional, as they will depend on both $W$ and $\\ve$.\n\nIn order to deal with $\\ve$ computationally, we would like to represent it as a vector of possible values\nit could take, along with the corresponding probabilities that it takes each of those values.  However,\n$N(\\mu,\\sigma^2)$ is a continuous distribution, so we cannot represent every value $\\ve$ could take.\nWe need a discrete distribution that approximates $N(\\mu,\\sigma^2)$.\n\nTo do this, we choose $N$ equally spaced points centered about the mean at which to approximate the\ndistribution. Call these values $\\ve_1,\\ldots,\\ve_N$, and let the spacing between adjacent points be\ngiven by $\\delta$.\nWe can then break up the support of the distribution into $N$ bins, where adjacent bins share a common\nendpoint. Call the endpoints of these bins $v_1,\\ldots,v_{N+1}$. By choosing the endpoints to be\nhalfway between each $\\ve_k$, we have the formula\n\\[\nv_k = \\ve_k - \\frac{1}{2}\\delta, \\qquad k=1,\\ldots,N\n\\]\nand\n\\[\nv_{N+1} = \\ve_N + \\frac{1}{2}\\delta.\n\\]\n\n\\begin{figure}[h!]\n\\label{stoch1_fig1}\n\\begin{center}\n\\includegraphics[width = \\textwidth]{discnorm.pdf}\n\\end{center}\n\\caption{Discretization of $N(\\mu,\\sigma^2)$.  We approximate $P(\\ve = \\ve_k)$ by the area of the shaded region.}\n\\end{figure}\n\nWe can then associate $\\ve_k$ with the area under the curve from $v_k$ to $v_{k+1}$.\nIn Python, we can find the area using the function \\li{norm.cdf} found in the \\li{stats} package.\nThe cdf (cumulative distribution function) gives the area under the curve from $-\\infty$ to a specified value.\nFor example, in the following code, \\li{eps} is the area under the curve from 0 to 1.\n\n\\begin{lstlisting}\n>>> from scipy import stats as st\n>>> mu = 0\n>>> sigma = 1\n>>> eps = st.norm.cdf(1,loc=mu,scale=sigma) - st.norm.cdf(0,loc=mu,scale=sigma)\n\\end{lstlisting}\n\nIn general, it is sufficient to take our points $\\ve_k$ ranging from $\\mu - 3\\sigma$ to $\\mu + 3\\sigma$, as this\nrange contains about 99.7\\% of the probability mass.\n\n\\begin{problem}\nWrite a function called \\li{discretenorm} that accepts an integer $K$ representing the number of discrete points\ndesired, a mean $\\mu$, and a standard deviation $\\sigma$. It should return a length-$K$ vector of equally-spaced\nvalues ranging from $\\mu - 3\\sigma$ to $\\mu + 3\\sigma$ inclusive,\nand a length-$K$ vector containing the associated probabilities.\nPlot the approximation of $N(0,1)$ using different values of $K$ to check that your results are plausible.\n\\end{problem}\n\nNow that we have a discrete distribution for $\\ve$, we can solve for the value and policy functions\ndetermined by \\eqref{stoch_Bellman}.\n\n\\begin{problem}\nComplete the following steps to solve the problem described above.\nAssume that the period utility function is $u(c)=\\sqrt{c}$.\nWrite a function \\li{stochEatCake}\nthat accepts parameters $\\beta$ (discount factor), $N$ (number of discrete cake values),\na tuple of values \\li{e_params}, $W_{max}$ (the original size of the cake, set to default value 1),\na keyword argument \\li{iid} (set to default value \\li{True}), and\na keyword argument \\li{plot} (set to default value of \\li{False}). Inside the function, carry out the steps\noutlined below.\n\nThe argument \\li{e_params} is a tuple consisting of the values needed to generate\nthe discrete approximation to $\\ve$. In the present case, this tuple consists (in order) of\n$K$ (the number of discrete approximations of $\\ve$), $\\mu$ (the\nmean of the shock term $\\ve$), and $\\sigma$ (the standard deviation of the shock term $\\ve$),\nsince these are the arguments we need to pass to our \\li{discretenorm} function.\n\n\\begin{enumerate}\n\\item First, compute an approximation of $\\ve$ using the \\li{discretenorm} function created in Problem 1.\nUse $K$ equally spaced points to approximate $N(\\mu,\\sigma^2)$. Denote the resulting $K$-length\nvector of equally-spaced values by\n\\[e =(e_1,\\ldots,e_K),\n\\]\nand denote the $K$-length vector of the associated probabilities\nby\n\\[\\Gamma = (\\Gamma_1,\\ldots,\\Gamma_K).\n\\]\nNote that $\\Gamma_k$ give the probability $P(\\ve = e_k)$.\n\nSince the values needed for the \\li{discretenorm} function are contained in the \\li{e_params} input,\nwe can feed these values directly into the function in the following way:\n\\begin{lstlisting}\n>>> e, gamma = discretenorm(*e_params)\n\\end{lstlisting}\nThe \\li{*} operator essentially unpacks the values of a tuple or list.\n\n\\item As done previously, create a vector\n\\[w = (w_1,\\ldots,w_N)\n\\]\nof possible cake sizes. This should be\na length-$N$ vector of equally spaced values from 0 to $W_{max}$, inclusive.\n\n\\item Represent the value function as a $N \\times K$ matrix $v$, satisfying\n\\[\nv_{i,j} = V(w_i, e_j).\n\\]\n(The rows correspond to different values of $W$ and the columns correspond to different values of $\\ve$.)\nInitialize each entry of the matrix to 0.\n\nLikewise, represent the policy function as a $N \\times K$ matrix $p$, satisfying\n\\[\np_{i,j} = \\psi(w_i,e_j).\n\\]\nInitialize all entries to 0.\n\n\\item In order to evaluate the value function equation, we need to pre-compute $\\ve u(W-W')$ for all values of\n$\\ve,W,W'$.\nBegin by computing all possible values of $u(W-W')$, and storing these values in a $N \\times N$ array,\nas done before. Call this array $u$. Make sure that the upper triangular\nentries of this array are equal to zero, as these entries correspond to consuming more cake than is\navailable, which is impossible.\n\nThe values $\\ve u(W-W')$ will be represented by a three-dimensional array $\\hat{u}$ of size\n$N\\times N\\times K$, satisfying\n\\[\n\\hat{u}_{i,j,k} = v_{i,j}e_k.\n\\]\nWe can compute this array easily as follows:\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> u_hat = np.repeat(u, K).reshape((N,N,K))*e\n\\end{lstlisting}\n\n\n\\item We also need to compute $E_{\\ve'}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr]$ for each value of $W'$.\nThe expected value is simply\n\\begin{equation*}\nE_{\\ve'}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr] = \\sum_{k=1}^K \\Gamma_kV(W',e_k').\n\\end{equation*}\nThe result is a length $N$ vector, call it $E$, satisfying\n\\[\nE_i = E_{\\ve'}\\Bigl[V\\left(w_i,\\ve'\\right)\\Bigr] = \\sum_{k=1}^K \\Gamma_kv_{i,k}\n\\]\nThis calculation can be done by multiplying $\\Gamma$ element-wise to each row of the\nvalue function matrix $v$, and then summing along the rows. Something like the following\nline of code should do the trick:\n\\begin{lstlisting}\n>>> E = (v*gamma).sum(axis=1)\n\\end{lstlisting}\n\n\\item We can now compute the value function contraction\n\\begin{equation*}\\label{EqContractStochiid}\nC\\Bigl(V\\left(W,\\ve\\right)\\Bigr) \\equiv \\max_{W'\\in[0,W]}\\:\n\\Bigl\\{\\ve u\\left(W-W'\\right) + \\beta E_{\\ve'}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr]\\Bigr\\}.\n\\end{equation*}\nThe first task is to create an $N \\times N \\times K$ array $c$ satisfying\n\\[\nc_{i,j,k} = \\hat{u}_{i,j,k} + \\beta E_j.\n\\]\nThis can be done in any manner of ways. Below is a one-liner that does the job.\n\\begin{lstlisting}\n>>> c = np.swapaxes(np.swapaxes(u_hat, 1, 2) + beta*E, 1, 2)\n\\end{lstlisting}\n\nNow, for any $k$, for all $i < j$, set $c_{i,j,k}$ to a large negative number, say $-10^{10}$,\nso that when maximizing over this array, we do not choose to consume more cake than is available.\nAgain, this can be done in a variety of different ways, but the following does the job concisely:\n\\begin{lstlisting}\n>>> c[np.triu_indices(N, k=1)] = -1e10\n\\end{lstlisting}\n\nFinally, maximize over the second axis of $c$ (which corresponds to different values of $W'$)\nto obtain the updated value function matrix:\n\\begin{lstlisting}\n>>> v_new = np.max(c, axis=1)\n\\end{lstlisting}\nYou can likewise update your policy function matrix as follows:\n\\begin{lstlisting}\n>>> max_indices = np.argmax(c, axis=1)\n>>> p = w[max_indices]\n\\end{lstlisting}\n\n\\item We now have our updated value function matrix $v_{new}$ as well as the\nprevious $v$, which we refer to here as $v_{old}$. As we iterate on the value function equation, we need a norm\n\\begin{equation*}\n\\delta = \\|v_{new} - v_{old}\\|_2\n\\end{equation*}\nthat measures the distance between these two value functions to determine convergence.\nYou may compute the norm using the SciPy function \\li{scipy.linalg.norm}, or by direct calculation.\nAt the end of each iteration, make sure to set $v$ to $v_{new}$, so that the updates carry through the\nloop.\nIterate on the contraction until $\\delta < 10^{-9}$.\n\n\\item If \\li{plot = True}, make a 3-D surface plot of the policy function for the converged problem\n$W' = \\psi\\left(W,\\ve\\right)$ which gives the value of the cake tomorrow as a\nfunction of the cake today  and the taste shock today.  Do the same for the value function.\nExample code to create the value function plot is provided below.\n\\begin{lstlisting}\n>>> x = np.arange(0,N)\n>>> y = np.arange(0,K)\n>>> X,Y = np.meshgrid(x,y)\n>>> fig1 = plt.figure()\n>>> ax1 = Axes3D(fig1)\n>>> ax1.plot_surface(w[X], Y, v.T, cmap=cm.coolwarm)\n>>> plt.show()\n\\end{lstlisting}\nCreating the policy function plot is similar.\n\n\\item Return the converged value function matrix $v$ and policy function matrix $p$.\n\n\n\\end{enumerate}\nTest your function using values $\\beta = .9$, $N = 100$, $K = 7$, $\\sigma = .5$, $\\mu = 4\\sigma$,\nand \\li{plot = True}.\nThe proper way to set this up and call the function is as follows:\n\\begin{lstlisting}\n>>> e_params = (7, 4*.5, .5)\n>>> stuff = stochEatCake(.9, 100, e_params, plot=True)\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width = \\textwidth]{stoch_value.pdf}\n    \\caption{3D surface representing the value function for the Stochastic Cake-Eating problem.}\n\\end{figure}\n\n\\section*{Infinite Horizon, Stochastic, AR(1)}\\label{SecRecProbInfinHorStochAR1}\n\nIn the previous example, we assumed that the shocks at time $t$ were independent of what happened in\nprevious periods.  Often a shock may depend on recent events.  We will assume now that the shocks are persistent,\nmeaning preferences in the current period are more likely to be close to what they were in the previous period.\nWe can characterize the persistence by what is called an autoregressive process of order one, denoted AR(1).\nSuch a process is defined as follows.\n\\begin{equation}\\label{EqAR1shock}\n\\ve' = (1-\\rho)\\mu + \\rho\\ve + \\nu' \\quad\\text{where}\\quad \\rho\\in(0,1) \\quad\\text{and}\\quad \\nu\\sim N(0,\\sigma^2).\n\\end{equation}\n\nEssentially, instead of allowing the shocks to have a mean which is independent of the past, the mean is now a\nweighted average (weighted by $\\rho$) of some $\\mu$ and the previous realization of the shock, $\\ve$.  As it turns\n out, we can approximate this process by thinking of it as a Markov Chain. This means we need to determine a\n discrete set of points representing possible values of $\\ve$ and a Markov transition matrix that gives the\n probabilities of moving from one value of $\\ve$ to another.  There are methods for determining the discrete\n approximation of $\\ve$ with a Markov transition matrix.  These methods are beyond the scope of this section,\n but you can use the file \\li{tauchenhussey.py} to implement them in the next problem.\n\nThe Bellman equation becomes the following, in which the only change from the i.i.d. shock case is that the\nexpectations operator is now conditional on the current shock $\\ve$:\n\n\\begin{equation*}\n   V\\left(W,\\ve\\right) = \\max_{W'\\in[0,W]}\\: \\{\\ve u\\left(W - W'\\right) +\n   \\beta E_{\\ve'|\\ve}\\left[V\\left(W',\\ve'\\right)\\right]\\},\n\\end{equation*}\nwhere $\\ve'$ is distributed according to \\eqref{EqAR1shock}.\nLet $\\Gamma_{i,j}=P\\left(\\ve_j'|\\ve_i\\right)$ where $\\ve_j'$ is the value of the shock in\nthe next period and $\\ve_i$ is the value of the shock in the current period.\nIn other words, $\\Gamma$ is the Markov transition matrix.\n\nThe solution to this problem is of the same type as that in the i.i.d. case, since the only difference is\nthe probability distributions of the $\\ve$.\n\n\\begin{problem}\nExpand your \\li{stochEatCake} function to handle the case of AR(1) shock terms. The function should\nhandle this case for the parameter value \\li{iid = False}, and should handle the previous case of\nnormally distributed i.i.d. shock terms for the parameter value \\li{iid = True}. You will need to\nadd a few ``if ... else\" statements, as well as implement the steps outlined below, but most of the\ncode will remain unchanged.\n\n\\begin{enumerate}\n\\item In the AR(1) case, the \\li{e_params} argument should be a tuple of values needed to\ngenerate the arrays $e$ and $\\Gamma$ that approximate the values and distribution of $\\ve$\nas a Markov chain.\nUse the file \\li{tauchenhussey.py} to calculate these arrays.\nThe provided Python function \\li{tauchenhussey} produces the vector $e$ of length $M$\nand an $M\\times M$ transition matrix $\\Gamma$.\nThus, you simply need the following lines of code, similar to the previous case.\n\\begin{lstlisting}\n>>> from tauchenhussey import tauchenhussey\n>>> e, gamma = tauchenhussey(*e_params)\n\\end{lstlisting}\n\n\\item Because our values for $e$ and $\\Gamma$ are different in the AR(1) case than\nin the i.i.d. case, we must compute the expectation in a different manner.\nIn particular, we need to compute the conditional expectation\n\\begin{equation*}\nE_{\\ve'|\\ve}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr].\n\\end{equation*}\nWe obtain a two-dimensional array, since the expectation depends on both $W'$ and on $\\ve$.\nThe expectation can be computed by the matrix multiplication $v\\Gamma^T$.\nYour code should match the following.\n\\begin{lstlisting}\n>>> E = v.dot(gamma.T)\n\\end{lstlisting}\n\n\\item The last difference comes in computing the array $c$. Fortunately, it is easier in this case.\nRecall that $c$ gives the values for\n\\[\n\\ve u\\left(W-W'\\right) + \\beta E_{\\ve'|\\ve}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr].\n\\]\nThe array $\\hat{u}$ contains the values for the first term in the expression, and the array $E$\ncontains the values for the expectation term.\nHence, we obtain $c$ by simple addition. Array broadcasting makes this work without problems.\n\\begin{lstlisting}\n>>> c = u_hat + beta*E\n\\end{lstlisting}\nYou will still need to set the upper triangular entries of $c$ to a large negative number, just as in the\nprevious case.\n\\end{enumerate}\n\nThose are the only differences. Let the following code snippet be a guideline for how to implement\nthese differences.\n\\begin{lstlisting}\n>>> if iid:\n>>>     # compute E as outlined in the previous problem\n>>> else:\n>>>     # compute E as outlined in the current problem\n\\end{lstlisting}\n\nNow test your function with $\\beta = .9$, $N = 100$, \\li{iid = False}, and \\li{plot = True}.\nAs inputs to \\li{tauchenhussey}, let $K=7$, the mean of the process\n$\\mu=4\\sigma$, $\\rho = 1/2$, $\\sigma=1/2$, and\n\\[baseSigma=(0.5+\\frac{\\rho}{4})\\sigma +\n(0.5 - \\frac{\\rho}{4})\\frac{\\sigma}{\\sqrt{1-\\rho^2}}.\n\\]\nYour \\li{e_params} parameter will therefore be a tuple of values containing (in order)\n$K$, $\\mu$, $\\rho$, $\\sigma$, and $baseSigma$.\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "ad3170396d338287d28520d419a8c920616edb05", "size": 51220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2B/DynamicOpt1-Value/DynamicOpt1.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2B/DynamicOpt1-Value/DynamicOpt1.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2B/DynamicOpt1-Value/DynamicOpt1.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": 54.6638207044, "max_line_length": 517, "alphanum_fraction": 0.7340491995, "num_tokens": 14433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.6568217374350417}}
{"text": "The previous chapters focused on using camera models to identify the relationship between points in a 3D scene and their projections onto the camera image, as well as how to leverage those models to reconstruct 3D scene structure from 2D images. \nAlternatively, this chapter begins to look at methods for extracting other types of information through \\textit{image processing}, for example to answer the question ``what object am I seeing?'' rather than ``how far away is this object?''.\nExtracting this type of visual content from raw images is important for mobile robots to be able to intelligently interpret their surroundings. In fact, it can have a major impact on the ability of the robot to perform several tasks including localization and mapping or decision making. This chapter focuses on some of the more commonly used tools in image processing including image filtering, feature detection, and feature description\\cite{SiegwartNourbakhshEtAl2011}\\cite{Moravec1977}.\n\n\\notessection{Image Processing}\nImage processing is a form of signal processing where the input signal is an image (such as a photo or a video) and the output is either an image or a set of parameters associated with the image. While a large number of image processing techniques exist, this chapter focuses on some of the more fundamental methods that are relevant for robotics. In particular, these methods will be related to image filtering, feature detection, and feature description\\footnote{The software library OpenCV implements a number of useful image filtering algorithms: \\url{https://docs.opencv.org}.}.\n\nIn the following methods, grayscale images are treated as functions $I$: $[a,b]\\times[c,d] \\rightarrow [0,L]$, where $I(x,y)$ represents the grayscale pixel intensity at $(x,y)$. \nFor a color image, $I$ is a vector valued function with three components, one each for the red, green, and blue color channels of the image.\n\n\\subsection{Image Filtering}\nImage filtering is one of the principal tasks in image processing. The terminology ``filter'' comes from frequency domain signal processing and refers to the process of accepting or rejecting certain frequency components of a signal (e.g. eliminating high-frequency noise).\n\nPerhaps the most common type of image filtering is \\textit{spatial filtering}.\nThe basic principle of spatial filtering is that a particular pixel is modified in the filtered image based only on the pixels in the immediate spatial neighborhood (see Figure \\ref{fig:spatial_filter_concept_fig}). To be more specific, a spatial filter for an image $I(x,y)$ consists of:\n\\begin{enumerate}\n    \\item A neighborhood $S_{xy}$ of pixels around a particular point $(x,y)$ under examination, typically rectangular.\n    \\item A predefined operation $F$ that is performed on the image pixels encompassed by the neighborhood $S_{xy}$.\n\\end{enumerate}\nOnce the operation $F$ has been applied to all pixels $(x,y)$ in the image $I$ a new image $I'(x,y)$ is defined.\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.75\\textwidth]{tex/figs/ch10_figs/spatialfiltering.png}\n    \\caption{Illustration of the concept of spatial filtering. The spatial filter operates on a neighborhood $S_{xy}$ of each point in the original image to produce a new pixel in the filtered image.}\n    \\label{fig:spatial_filter_concept_fig}\n\\end{figure}\n\nIn general filters can be linear or nonlinear, but many of the most fundamental filters are linear and can be expressed mathematically as:\n\\begin{equation}\n  \\label{eq:correlation}\n    I'(x,y) = F \\circ I = \\sum_{i=-N}^N \\sum_{j=-M}^M F(i,j)I(x+i,y+j),\n\\end{equation}\nwhere $N$ and $M$ are integers that define the width and height of a rectangular neighborhood $S_{xy}$. Based on the size of this neighborhood, it is said that this filter is of size $(2N+1) \\times (2M+1)$. Additionally, the filter operation $F$ is usually called a \\textit{mask} or \\textit{kernel}. Broadly speaking, filters expressed by \\eqref{eq:correlation} are referred to as \\textit{correlation filters}.\n\nAnother type of linear filters that are commonly used are referred to as \\textit{convolution} filters. Convolution filters are similar to correlation filters but use reverse image indices (in fact correlation and convolution filters are identical when the filter mask is symmetric in both the horizontal and vertical directions). In particular, these filters are expressed mathematically as:\n\\begin{equation}\n  \\label{eq:convolution}\n    I'(x,y) = F \\ast I = \\sum_{i=-N}^N \\sum_{j=-M}^M F(i,j)I(x-i,y-j).\n\\end{equation}\nConvolution filters are associative, meaning that for two different filter masks $F$ and $G$ it is true that $F*(G*I) = (F*G)*I$. One example of how the associative property is useful is for smoothing an image \\textit{before} taking applying a differentiation filter. Suppose the mask $F$ implemented a derivative filter and $G$ implemented a smoothing filter, then sequentially applying these filters would result in $F*(G*I)$. However, because of the associative property the masks can be convolved together \\textit{first} such that only one filter needs to be applied to the image (i.e. $(F*G)*I$).\n\nNote that in both the correlation and convolution filters the boundaries of the image need some special care because of the width and height of the mask. For example, Figure \\ref{fig:nopaddingexample} shows how the filtered image is smaller than the original due to the width and height of the mask. Some possible options to handle this include padding the image, cropping it, extending it, or wrapping it. However, as images are generally quite large the exact approach likely won't vary the final result significantly.\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.65\\textwidth]{tex/figs/ch10_figs/centerfilter_nopadding.png}\n    \\caption{Due to the width and height of the mask, the filtered image may be smaller than the original. However this can be fixed with several techniques, such as padding.}\n    \\label{fig:nopaddingexample}\n\\end{figure}\n\n\\begin{example}[Practical Considerations for Image Filtering] \\label{ex:padding}\n\\theoremstyle{definition}\nImplementation of correlation and convolution filters typically leverages some additional ``tricks'' to make things easier to implement. In this example two such tricks will be introduced: zero-padding and a change in indexing. \n\nFirst, to more simply accommodate varying sizes of filters (including even and odd sized filters) the indexing is often changed such that the coordinate of interest is associated with the top-left element in the window rather than the center. In particular, for a correlation filter this would correspond to:\n\\begin{equation}\n  \\label{eq:correlation_newindex}\n    I'(x,y) = F \\circ I = \\sum_{i=1}^K \\sum_{j=1}^L F(x,y)I(x+i-1,y+j-1),\n\\end{equation}\nwhere $K$ and $L$ are integers that define the width and height of the filter and the pixel $(x,y)$ is at row $x$ and column $y$. However, note that with this formulation the output image $I'$ will be shifted up and to the left. To see this consider the pixel at $x=1$ and $y=1$ in the new image $I'$, which would correspond to the top-left pixel $I'$. This new pixel value is generated by applying the filter $F$ over the pixels in the original image $I$ at rows $\\{1,\\dots,K\\}$ and columns $\\{1,\\dots,L\\}$ (which is not centered at $(1,1)$ in the original image $I$). Therefore it will appear as if the image has been shifted! But in practice this isn't an issue as long as you always index with respect to the top-left corner. An example of top-left indexing is shown in Figure \\ref{fig:topleftfilter}\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.65\\textwidth]{tex/figs/ch10_figs/topleftfilter_nopadding.png}\n    \\caption{Top-left indexing is typically easier to implement than center indexing. Notice that when top-left indexing, it appears as if the filtered image has shifted with respect to when center indexing is used.}\n    \\label{fig:topleftfilter}\n\\end{figure}\n\nZero-padding (also commonly referred to as \\textit{same padding}) is another simple trick that can be used to ensure that the output filtered image $I'$ has the same dimension as the input image $I$. In this approach the left and right boundaries of the image are \\textit{each} padded by $\\lfloor K/2 \\rfloor$ columns of zeros, and the top and bottom boundaries are padded by $\\lfloor L/2 \\rfloor$ rows of zeros ($\\lfloor \\cdot \\rfloor$ denotes the ``floor'' operation). For example the image:\n\\begin{equation*}\nI = \\begin{bmatrix}\n    1 & 2 & 3 \\\\\n    4 & 5 & 6 \\\\\n    7 & 8 & 9 \\\\\n    \\end{bmatrix},\n\\end{equation*}\nwould become\n\\begin{equation*}\nI_\\text{padded} = \\begin{bmatrix}\n    0 & 0 & 0 & 0 & 0 \\\\\n    0 & 1 & 2 & 3 & 0 \\\\\n    0 & 4 & 5 & 6 & 0 \\\\\n    0 & 7 & 8 & 9 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 \\\\\n    \\end{bmatrix},\n\\end{equation*}\nfor filters $F \\in \\R^{3\\times 3}$, $F \\in \\R^{2 \\times 2}$, $F \\in \\R^{2 \\times 3}$ and $F \\in \\R^{3 \\times 2}$. When using this padding rule with the correlation filter \\eqref{eq:correlation_newindex} and a filter $F$ with $K = 2,3$ and $L= 2,3$, the new image $I'$ can be defined for values $x \\in \\{1,2,3\\}$ and $y \\in \\{1,2,3\\}$, resulting in $I'$ being the same dimension as the original image $I$. The use of padding (along with top-left indexing) is also shown graphically in Figure \\ref{fig:paddingfilter}\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.7\\textwidth]{tex/figs/ch10_figs/topleftfilter_padding.png}\n    \\caption{Image padding is a commonly used technique to ensure that the size of the filtered image is the same size as the original.}\n    \\label{fig:paddingfilter}\n\\end{figure}\n\\end{example}\n\n\n\\subsubsection{Moving Average Filter}\nThe moving average filter returns the average of pixels in the mask, which achieves a smoothing effect (i.e. removes sharp features in the image). For example, a moving average filter with a normalized $3 \\times 3$ mask is defined with the operation $F$ in \\eqref{eq:correlation} chosen as:\n\\begin{equation*}\n    F = \\frac{1}{9}\\begin{bmatrix}\n    1 & 1 & 1 \\\\\n    1 & 1 & 1 \\\\\n    1 & 1 & 1 \\\\\n    \\end{bmatrix}.\n\\end{equation*}\nNote that due to symmetry of the mask, the correlation \\eqref{eq:correlation} and convolution \\eqref{eq:convolution} filters will be identical. Additionally, the normalization is used to maintain the overall brightness of the image.\n\n\\subsubsection{Gaussian Smoothing Filter}\nGaussian smoothing filters are similar to the moving average filer, but instead of weighting all of the pixels evenly they are weighted by the Gaussian function:\n\\begin{equation*}\nG_\\sigma(x,y) = \\frac{1}{2\\pi\\sigma^2} \\exp \\bigg(-\\frac{x^2 + y^2}{2\\sigma^2} \\bigg).\n\\end{equation*}\nThis function is used to obtain the mask operation $F$ by sampling the function about the center pixel (i.e. for the center pixel with $i=j=0$ in \\eqref{eq:correlation}, sample $G_\\sigma(0,0)$). For example, for a normalized $3\\times3$ mask with $\\sigma$ = 0.85 this filter is approximately defined by:\n\\begin{equation*}\nF = \\frac{1}{16}\n\\begin{bmatrix}\n1 & 2 & 1\\\\\n2 & 4 & 2\\\\\n1 & 2 & 1\n\\end{bmatrix}.\n\\end{equation*}\nLike the moving average filter, this filter mask is symmetric and therefore yields identical results with respect to the correlation \\eqref{eq:correlation} or convolution \\eqref{eq:convolution} filters. The advantage of the Gaussian filter is that it provides more weight to the neighboring pixels that are closer.  An example of this filter is shown in Figure \\ref{fig:gaussianfilter}.\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.8\\textwidth]{tex/figs/ch10_figs/gaussianfilter.png}\n    \\caption{Example of a Gaussian smoothing filter, which produces a smoothing (blurring) effect on the filtered image.}\n    \\label{fig:gaussianfilter}\n\\end{figure}\n\n\\subsubsection{Separable Masks}\nA mask $F$ is called \\textit{separable} if it can be broken down into the convolution of two kernels $F = F_1 \\ast F_2$. If a mask is separable into ``smaller'' masks, then it is often cheaper to apply $F_1$ followed by $F_2$, rather than by $F$ directly. One special case of this is when the mask can be represented as an outer product of two vectors (meaning it is equivalent to the 2D convolution of those two vectors). If the mask is of shape $M\\times M$, and the input image has size $w\\times h$, then the computational complexity of directly performing the convolution is $O(M^2wh)$. However, by separating the masks the computational cost is $O(2Mwh)$, which is linear in $M$ rather than quadratic. As an example, consider the moving average filter mask from before: \n\\begin{equation*}\nF = \\frac{1}{9}\n\\begin{bmatrix}\n1 & 1 & 1\\\\\n1 & 1 & 1\\\\\n1 & 1 & 1\n\\end{bmatrix} = \\frac{1}{9}\n\\begin{bmatrix}\n1 \\\\\n1 \\\\\n1\n\\end{bmatrix}\n\\begin{bmatrix}\n1 & 1 & 1\\\\\n\\end{bmatrix}. \n\\end{equation*}\nAs another example, note that the Gaussian smoothing filter mask is also separable. To see why this is, note that the Gaussian weighting function can be decomposed as:\n\\begin{equation*}\n\\begin{split}\nG_\\sigma(x,y) &= \\frac{1}{2\\pi\\sigma^2} \\exp \\bigg(-\\frac{x^2 + y^2}{2\\sigma^2} \\bigg), \\\\\n    &= \\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp \\bigg(-\\frac{x^2}{2\\sigma^2}\\bigg)\\frac{1}{\\sqrt{2\\pi}\\sigma} \\exp \\bigg(-\\frac{y^2}{2\\sigma^2}\\bigg), \\\\\n    &= g_\\sigma(x) \\cdot g_\\sigma(y).\n\\end{split}\n\\end{equation*}\n\n\\subsubsection{Image Differentiation Filters}\nTaking the derivative of an image can be used to identify certain features, such as edges. On a basic level, the derivative of an image quantifies changes in pixel intensity in both the vertical and horizontal direction. However, since images are represented as functions defined over a discrete domain the traditional method for differentiating continuous functions can not be used. Instead it is more common to just compute differences between pixels, such as using a central difference method:\n\\begin{equation} \\label{eq:cendiff}\n\\begin{split}\n \\frac{\\partial I} {\\partial x} &= \\frac{I(x+1,y) - I(x-1,y)}{2},\\\\\n\\frac{\\partial I} {\\partial y} &= \\frac{I(x,y+1) - I(x,y-1)}{2}.  \n\\end{split}\n\\end{equation}\nwhere $\\partial I/\\partial x$ is the derivative in the horizontal direction and $\\partial I/\\partial y$ is the derivative in the vertical direction. It is of course also possible to define the derivatives using just one side, for example $\\frac{\\partial I}{\\partial x} = I(x+1,y) - I(x,y)$.\n\nIt is also possible to differentiate an image using convolution filters. In particular, one common approach is to use a convolution filter \\eqref{eq:convolution} defined with a mask $F$ called a \\textit{Sobel mask} (also referred to as simply a Sobel operator). For the $x$ direction this mask is denoted as $S_x$ and for the $y$ direction as $S_y$:\n\\begin{equation}\nS_x = \\begin{bmatrix}\n1 & 0 & -1\\\\\n2 & 0 & -2\\\\\n1 & 0 & -1\n\\end{bmatrix}, \\quad S_y =\n\\begin{bmatrix}\n1 & 2 & 1\\\\\n0 & 0 & 0\\\\\n-1 & -2 & -1\n\\end{bmatrix}\n\\end{equation}\nSobel masks are similar to the central difference method but use more neighboring pixels when calculating the derivative (i.e. they also consider the rows above and below to compute the difference). Note that Sobel masks are also separable.\n\n\\subsubsection{Similarity Measures}\nFiltering can also be used to find similar features in different images, which can be useful for solving the correspondence problem in stereo vision or structure-from-motion techniques. \nIn particular, the similarity between the pixel $(x,y)$ in image $I_1$ and pixel $(x', y')$ in image $I_2$ can be computed by:\n\\begin{equation} \\label{eq:similarity}\n\\begin{split}\nSAD &= \\sum_{i=-N}^N \\sum_{j=-M}^M \\rvert I_1(x+i,y+j)-I_2(x^\\prime+i,y^\\prime+j)\\lvert, \\\\\nSSD &= \\sum_{i=-N}^N \\sum_{j=-M}^M [I_1(x+i,y+j)-I_2(x^\\prime+i,y^\\prime+j)]^2,\n\\end{split}\n\\end{equation}\nwhere SAD is an acronym for ``sum of absolute differences'', SSD is an acronym for ``sum of squared differences'', and $N$ and $M$ define the size of the window around the pixels that is considered.\n\n\\subsection{Image Feature Detection}\nA local feature (also sometimes referred to as interest points, interest regions, or keypoints) in an image is a pattern that differs from its immediate neighborhood in terms of intensity, color, or texture. \nLocal features can generally be categorized in several ways, for example whether they provide semantic content or not. For example, features that may provide semantic content include edges or other geometric shapes (e.g. lanes of a road or blobs corresponding to blood cells in medical images). These types of features were some of the first for which feature detectors were proposed in the image processing literature. Features that do not provide semantic content may also be useful, for example in feature tracking, camera calibration, 3D reconstruction, image mosaicing, and panorama stitching. In these cases it may be more important that the feature be able to be located accurately and robustly over time. A third category of features are those that may not have semantic interpretations individually, but may have meaning as a collection.\nFor instance, a scene could be recognized by counting the number of feature matches between the observed scene and a query image. In this case only the number of matches is relevant and not the location or type of feature. Applications where these types of features are important include texture analysis, scene classification, video mining, and\nimage retrieval.\n\nIn this section several feature detection strategies will be discussed. While many strategies exist for different types of features, the focus here will be on two common features that are often useful in robotics: edges and corners.\n\n\n\\subsubsection{Edge Detection}\nAn \\textit{edge} in an image is a region where there is a significant change in intensity values along one direction, and negligible change along the orthogonal direction. In one dimension an edge corresponds to a point where there is a sharp change in intensity, which mathematically can be thought of as a point of a function having a large first derivative and a small second derivative. Many edge detectors rely on this concept by differentiating images and looking for spikes in the derivative.\nAn edge detector can be evaluated based on several criteria for robustness and performance, including accuracy, localization, and single response. Good accuracy implies few false positives or negatives (missed edges), good localization implies that the detected edge should be exactly where the true edge is in the image, and a single response implies \\textit{only} one edge is detected for each real edge. In practice, noise and discretization can make edge detection challenging.\n\nMost edge detection methods rely on two key steps: smoothing and differentiation. Differentiation is performed in both the vertical and horizontal directions to find locations in the image with high intensity gradients. However, differentiation alone is vulnerable to false positives due to image noise, which is why many algorithms will first smooth the image. \n\n\\paragraph{Edge Detection in 1D:}\nAn example of how noise can corrupt image differentiation is given in Figure \\ref{fig:noisy}. \n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{tex/figs/ch10_figs/edge_detection.png}\n    \\caption{Differentiation of signal (e.g. for edge detection) with noise can be particularly challenging, which can be addressed by first smoothing the signal.}\n    \\label{fig:noisy}\n\\end{figure}\nNotice that in this case it is impossible to identify the jump in the signal due to the noise levels.\nSmoothing filters, such as the Gaussian smoothing filter discussed earlier, can help remedy this problem. In particular, suppose the original signal in Figure \\ref{fig:noisy} is defined by $I(x)$. Then a smoothed version can be defined by applying a smoothing convolution filter:\n\\begin{equation*}\ns(x) = g_\\sigma(x) \\ast I(x),\n\\end{equation*}\nwhere $g_\\sigma(x)$ represents a Gaussian smoothing filter, and then by applying the differentiation filter:\n\\begin{equation*}\ns'(x)=\\frac{d}{dx}\\ast s(x).\n\\end{equation*}\nThis process is shown in Figure \\ref{fig:gauss}.\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[width=0.55\\textwidth]{tex/figs/ch10_figs/edge_detection_smooth.png}\n    \\caption{Edge detection through convolution with a Gaussian smoothing filter, followed by a differentiation filter.}\n    \\label{fig:gauss}\n\\end{figure}\nNote however that since these filters are convolutions, the associativity property can be leveraged to actually combine them into a single filter:\n\\begin{equation*}\ns'=(\\frac{d}{dx} * g_\\sigma) * I.\n\\end{equation*}\n\n\\paragraph{Edge Detection in 2D:}\nEdge detection in a two-dimensional image is quite similar to the example previously discussed in 1D. Let the smoothing filter be the Gaussian smoothing filter from before, and a differentiation filter such as the Sobel filter. The gradient of the smoothed image in both the $x$ and $y$ directions can be written as:\n\\begin{equation*}\n\\nabla S= \\begin{bmatrix}\n\\frac{\\partial}{\\partial x} * G_\\sigma * I \\\\ \\frac{\\partial}{\\partial y} * G_\\sigma * I \\end{bmatrix}= \\begin{bmatrix}\nG_{\\sigma,x} * I\\\\G_{\\sigma,y} * I\n\\end{bmatrix}=\\begin{bmatrix}\nS_x\\\\S_y\n\\end{bmatrix},\n\\end{equation*}\nwhere $I$ is the original image and the associativity properties of the smoothing and differentiation convolution filters is used to define the combined filters $G_{\\sigma,x}$ and $G_{\\sigma,y}$. The magnitude of the gradient can then be computed by:\n\\begin{equation*}\n\\lvert\\nabla S\\rvert =\\sqrt{S_x^2+S_y^2},\n\\end{equation*}\nwhich can be used to check against a predefined threshold value for edge detection. To guarantee thin edges it is also possible to filter out points whose gradient magnitude are above the threshold but are not local maxima. Examples of this process are shown in Figures \\ref{fig:sobel} and \\ref{fig:canny}.\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.8\\textwidth]{tex/figs/ch10_figs/sobel.png}\n    \\caption{Edge detection using the ``Sobel'' edge detector.}\n    \\label{fig:sobel}\n\\end{figure}\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.8\\textwidth]{tex/figs/ch10_figs/canny.png}\n    \\caption{Edge detection using the ``Canny'' edge detector.}\n    \\label{fig:canny}\n\\end{figure}\n\n\\subsubsection{Corner Detection}\nA \\textit{corner} in an image is defined as an intersection of two or more edges, and also sometimes as a point where there is a large intensity variation in every direction. \nImportant properties of corner detectors include repeatability and distinctiveness. Repeatability quantifies how well the same features can be found in multiple images even under geometric and photometric transformations. Distinctiveness refers to whether the information carried by the patch surrounding the feature is distinctive, which can be used to reliably produce correspondences. Both of these properties are particularly important in applications such as panorama stitching and 3D reconstruction.\n\nGenerally corner detection can be thought of in a similar way to edge detection, except that instead of looking for change along one direction there should be changes in all directions. One well known corner detector is known as the Harris detector \\cite{Harris1988}, which has the useful property that the detection is invariant to rotations and linear intensity changes (i.e. geometric and photometric invariance). However the Harris detector is not invariant to scale changes or geometric affine changes, which has led to the development of scale-invariant detectors such as the Harris-Laplacian detector or the scale-invariant feature transform (SIFT) detector.\n\n\\subsection{Image Descriptors}\nImage \\textit{descriptors} describe features so that they can be compared across images, or used for object detection and matching. Similar to image detectors, it is also desirable for image descriptors to be repeatable (i.e. invariant with respect to pose, scale, illumination, etc.) and distinct. Perhaps the simplest example of a descriptor is an $n\\times m$ window of pixel intensities centered at the feature, which can be normalized to be illumination invariant. However, such a descriptor is not invariant to pose or scale and is not distinctive, and therefore is generally not useful in practice. \nAlternative detectors/descriptors that have become popular include SIFT, SURF, FAST, BRIEF, ORB, and BRISK. \n\n\\subsection{Exercises}\n\\subsubsection{Linear Filtering}\nComplete \\textit{Problem 3: Linear Filtering} located in the online repository:\n\n\\vspace{\\baselineskip}\n\n\\url{https://github.com/PrinciplesofRobotAutonomy/AA274A_HW3},\n\n\\vspace{\\baselineskip}\n\nwhere you will explore the use of linear filters for image processing.", "meta": {"hexsha": "e9f6d8c12514e753bf09c12914ac591a13fdbf4f", "size": 24687, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch10.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/ch10.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/ch10.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.2332155477, "max_line_length": 846, "alphanum_fraction": 0.7633572326, "num_tokens": 6266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.656821731534552}}
{"text": "\\section*{Ex.34.2-5}\n\\subsection*{Show that any language in NP can be decided by an algorithm running in time $2^{O(n^k)}$ for some constant $k$}\n\nFirst note, that if we can verify a language, then we can also decide it.\n\\\\\nNow, we know that we can verify any language L $\\in$ NP in polynomial time (top of page 1064, CLRS), with a two-input algorithm. As input, the algorithm takes $x\\in L$ and a certificate $y$. Since the length of any certificate is bounded by $O(|x|^c)$, the input $x$ can at most be $O(|x|^c)$ long.\n\\\\\nIf we run the algorithm on every possible input $x\\in {0,1}^*$, with that max length, it will take time $2^{O(n^k)}$.", "meta": {"hexsha": "3aefc148a84b5b719ab4d757b6034c1dfa7dec42", "size": 643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.2-5.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-5.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-5.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": 80.375, "max_line_length": 298, "alphanum_fraction": 0.6982892691, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6568217152180527}}
{"text": "\\documentclass[class=report, float=false, crop=false]{standalone}\n\\usepackage[subpreambles=true]{standalone}\n\n\\input{preamble}\n\n\\graphicspath{{figures/images/}}\n\n% \\begin{cbunit}\n\n\\begin{document}\n\n\\chapter{Ellipsoids}\n\\label{appendix:ellipsoids}\n\n\\section{Definition}\n\nAn ellipsoid is a surface that may be obtained from a sphere by deforming it by means of directional scalings, or more generally, of an affine transformation \\cite{wiki:Ellipsoid}.\\\\\n\nWithin a Cartesian coordiante system in which the origin is the center of the ellipsoid and the coordinate axes are axes of the ellipsoid, a vector \\(\\vec{r} = \\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix} \\in \\mathbb{R}^3\\) belongs to the surface of the ellispoid if and only if\n\\begin{equation}\n\\frac{x^2}{a^2} + \\frac{y^2}{b^2} + \\frac{z^2}{c^2} = 1\n\\label{ellipsoid_cartesian}\n\\end{equation}\nwhere $a$, $b$ and $c \\in \\mathbb{R}$ are the the semi-axes of the ellipsoid.\\\\\n\nEquivalently to equation \\ref{ellipsoid_cartesian}, an ellipsoid $\\mathcal{A}$ can be defined by a positive definite matrix $A \\in \\mathcal{M}_3(\\mathbb{R})$ and a vector $\\vec{v} \\in \\mathbb{R}^3$ such that\n\\begin{equation}\n\\boxed{\\forall \\vec{r} \\in \\mathbb{R}^3, \\vec{r} \\in \\bar{\\mathcal{A}} \\Leftrightarrow (\\vec{r}-\\vec{v})^TA(\\vec{r}-\\vec{v}) = 1}\n\\label{ellipsoid_matrix}\n\\end{equation}\nThe eigenvectors of $A$ then define the principal axes of $\\mathcal{A}$ and the associated eigenvalues are the reciprocals of the squares of the semi-axes. The vector $\\vec{v}$ defines the center of the ellipsoid.\n\n\\section{Homogeneous coordinates}\n\n\\subsection{Quick reminder}\n\nA vector \\(\\vec{r} = \\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix} \\in \\mathbb{R}^3\\) is equivalent to its homogeneous form \\(\\begin{pmatrix} x \\\\ y \\\\ z \\\\ 1 \\end{pmatrix} \\in E^3\\) where $E^3$ is the Euclidean 3D projective space.\\\\\n\nMoreover, we have that in $E^3$, $\\forall \\lambda \\in \\mathbb{R}^*$ and $\\forall (x,y,z) \\in \\mathbb{R}^3$, \\(\\begin{pmatrix} x \\\\ y \\\\ z \\\\ 1 \\end{pmatrix}\\) and \\(\\begin{pmatrix} \\frac{x}{\\lambda} \\\\ \\frac{y}{\\lambda} \\\\ \\frac{z}{\\lambda} \\\\ 1 \\end{pmatrix}\\) represent the exact same point. Therefore, we will always assume that the last coordinate of our vectors in $E^3$ is 1.\\\\\n\nFrom the property above, you naturally have that any point in $E^3$ whose last coordinate would be $0$ is then infinitely far from the origin \\(\\begin{pmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{pmatrix}\\).\n\n\\subsection{Useful affine transformations}\n\n\\subsubsection{Translation}\n\nWe define in $\\mathbb{R}^3$ the translation of vector $\\vec{u} \\in \\mathbb{R}^3$ as\n\\begin{align*}\n\\mathcal{T}_{\\vec{u}} \\colon &\\mathbb{R}^3 \\to \\mathbb{R}^3\\\\     &\\phantomarrow{\\mathbb{R}^3}{\\vec{v}} \\vec{v} + \\vec{u}\n\\end{align*}\n\nIn $E^3$, this function $\\mathcal{T}_{\\vec{u}}$ is represented by the matrix $T_{\\vec{u}}$:\n\\begin{equation}\n\\boxed{T_{\\vec{u}} = \\begin{pmatrix} \\mathbbm{1}_3 & \\vec{u} \\\\ \\vec{0}^T & 1 \\end{pmatrix}}\n\\label{translation_matrix}\n\\end{equation}\n\n\\subsubsection{Dilatation}\n\nWe define in $\\mathbb{R}^3$ the dilatation of factor $a \\in \\mathbb{R}$ as\n\\begin{align*}\n\\mathcal{X}_{a} \\colon &\\mathbb{R}^3 \\to \\mathbb{R}^3\\\\     &\\phantomarrow{\\mathbb{R}^3}{\\vec{v}} a\\vec{v}\n\\end{align*}\n\nIn $E^3$, this function $\\mathcal{X}_{a}$ is represented by the matrix $X_{a}$:\n\\begin{equation}\n\\boxed{X_{a} = \\begin{pmatrix} a\\mathbbm{1}_3 & \\vec{0} \\\\ \\vec{0}^T & 1 \\end{pmatrix}}\n\\label{dilatation_matrix}\n\\end{equation}\n\n\\subsubsection{Rotation}\n\nWe showed in part \\ref{action_rotation} that every 3D rotation can be expressed as the action of some unit quaternion.\\\\\n\nThe product of quaternions being bilinear, we can associate the action of a quaternion to a linear function in a vectorial space and therefore to a matrix \\cite{shoemake}.\\\\\n\nConsider $q = [\\vec{q},q_0],p = [\\vec{p},p_0] \\in \\mathbb{H}$. According to part \\ref{quat_properties}, we have $qp = [\\underbrace{\\vec{q}\\times\\vec{p}}_{Ap} + \\underbrace{q_0\\vec{p}}_{Bp} + \\underbrace{p_0\\vec{q}}_{Cp},\\underbrace{q_0p_0}_{Dp}~\\underbrace{-\\vec{q}\\cdot\\vec{p}}_{Ep}]$, with\n\\begin{align*}\nA = \\begin{pmatrix} \\vec{q} \\times \\bigcdot & \\vec{0} \\\\ \\vec{0}^T & 0 \\end{pmatrix}, B = \\begin{pmatrix} q_0 \\mathbbm{1}_3 & \\vec{0} \\\\ \\vec{0}^T & 0 \\end{pmatrix}, C = \\begin{pmatrix} 0_3 & \\vec{q} \\\\ \\vec{0}^T & 0 \\end{pmatrix}, D = \\begin{pmatrix} 0_3 & \\vec{0} \\\\ \\vec{0}^T & q_0 \\end{pmatrix}, E = \\begin{pmatrix} 0_3 & \\vec{0} \\\\ -\\vec{q}^T & 0 \\end{pmatrix}\n\\end{align*}\nTherefore the left multiplication by $q$ in $\\mathbb{H}$ can be represented by the matrix\n\\begin{align*}\nL_q &= A + B + C + D + E\\\\\n&= \\begin{pmatrix} \\vec{q} \\times \\bigcdot + q_0\\mathbbm{1}_3 & \\vec{q} \\\\ -\\vec{q}^T & q_0 \\end{pmatrix}\n\\end{align*}\n\nSimilarly, we have $pq^* = [\\underbrace{\\vec{q}\\times\\vec{p}}_{Ap} + \\underbrace{q_0\\vec{p}}_{Bp}~\\underbrace{-p_0\\vec{q}}_{-Cp},\\underbrace{q_0p_0}_{Dp} + \\underbrace{\\vec{q}\\cdot\\vec{p}}_{-Ep}]$, therefore the right multiplication by $q^*$ can be represented by the matrix\n\\begin{align*}\nR_{q^*} &= A + B - C + D - E\\\\\n&= \\begin{pmatrix} \\vec{q} \\times \\bigcdot + q_0\\mathbbm{1}_3 & -\\vec{q} \\\\ \\vec{q}^T & q_0 \\end{pmatrix}\n\\end{align*}\n\nConsequently, the matrix representing the action of the unit quaternion $q$ in $\\mathbb{H}$ is\n\\begin{align*}\nQ_q = L_qR_{q^*} = R_{q^*}L_q = \\begin{pmatrix} \\mathcal{Q}_q & \\vec{0} \\\\ \\vec{0}^T & \\underbrace{N^2(q)}_{=1} \\end{pmatrix}\n\\end{align*}\nwhere\n\\begin{equation}\n\\boxed{\\mathcal{Q}_q = (\\vec{q}\\times\\bigcdot + q_0\\mathbbm{1}_3)^2 + \\vec{q}\\vec{q}^T}\n\\label{rotation_matrix_R3}\n\\end{equation}\nis the matrix representing the rotation associated to the unit quaternion $q$ in $\\mathbb{R}^3$.\\\\\n\nTherefore, the matrix reprensenting the action of $q$ in $\\mathbb{H}$ and the rotation associated to $q$ in $E^3$ are the same and we will note the latter\n\\begin{equation}\n\\boxed{Q_q = \\begin{pmatrix} \\mathcal{Q}_q & \\vec{0} \\\\ \\vec{0}^T & 1 \\end{pmatrix}}\n\\label{rotation_matrix}\\\\\n\\end{equation}\n\nWe can develop equation \\ref{rotation_matrix_R3} to get an expression of the rotation matrix $\\mathcal{Q}_q$ in $E^3$. With\n\\begin{align*}\n  \\left(\\vec{e}_1 \\equiv (1, 0, 0)^T, \\vec{e}_2 \\equiv (0, 1, 0)^T, \\vec{e}_3 \\equiv (0, 0, 1)^T\\right)\n\\end{align*}\nthe canonical basis of $E^3$, we have\n\\begin{align*}\n  \\vec{q} \\times \\vec{e}_1 = \\begin{pmatrix} 0 \\\\ q_3 \\\\ -q_2 \\end{pmatrix}, \\vec{q} \\times \\vec{e}_2 = \\begin{pmatrix} -q_3 \\\\ 0 \\\\ q_1 \\end{pmatrix}, \\vec{q} \\times \\vec{e}_3 = \\begin{pmatrix} q_2 \\\\ -q_1 \\\\ 0 \\end{pmatrix}\n\\end{align*}\nsuch that\n\\begin{align*}\n  \\vec{q} \\times \\bigcdot = \\begin{pmatrix} 0 & -q_3 & q_2 \\\\ q_3 & 0 & -q_1 \\\\ -q_2 & q_1 & 0 \\end{pmatrix} \\text{ and } \\vec{q} \\times \\bigcdot + q_0 \\mathbbm{1}_3 = \\begin{pmatrix} q_0 & -q_3 & q_2 \\\\ q_3 & q_0 & -q_1 \\\\ -q_2 & q_1 & q_0 \\end{pmatrix}\n\\end{align*}\nand then\n\\begin{align*}\n  (\\vec{q} \\times \\bigcdot + q_0 \\mathbbm{1}_3)^2 =\n  \\begin{pmatrix}\n    q_0^2 - q_3^2 - q_2^2 & q_1 q_2 - 2 q_0 q_3 & q_1 q_3 + 2 q_0 q_2 \\\\\n    q_1 q_2 + 2 q_0 q_3 & q_0^2 - q_3^2 - q_1^2 & q_2 q_3 - 2 q_0 q_1 \\\\\n    q_1 q_3 - 2 q_0 q_2 & q_2 q_3 + 2 q_0 q_1 & q_0^2 - q_1^2 - q_2^2\n  \\end{pmatrix}\n\\end{align*}\nthus leading to\n\\begin{align*}\n  \\mathcal{Q}_q = (\\vec{q} \\times \\bigcdot + q_0 \\mathbbm{1}_3)^2 + \\vec{q} \\vec{q}^T =\n  \\begin{pmatrix}\n    q_0^2 + q_1^2 - q_3^2 - q_2^2 & 2 q_1 q_2 - 2 q_0 q_3 & 2 q_1 q_3 + 2 q_0 q_2 \\\\\n    2 q_1 q_2 + 2 q_0 q_3 & q_0^2 + q_2^2 - q_3^2 - q_1^2 & 2 q_2 q_3 - 2 q_0 q_1 \\\\\n    2 q_1 q_3 - 2 q_0 q_2 & 2 q_2 q_3 + 2 q_0 q_1 & q_0^2 + q_3^2 - q_1^2 - q_2^2\n  \\end{pmatrix}\n\\end{align*}\nwhere we can note that $q$ is an unit quaternion, \\textit{i.e.} $N^2(q) = \\sum_{i=0}^4 q_i^2 = 1$, and therefore\n\\begin{equation}\n  \\boxed{\\mathcal{Q}_q =\n    \\begin{pmatrix}\n      1 - 2 (q_2^2 + q_3^2) & 2 (q_1 q_2 - q_0 q_3) & 2 (q_1 q_3 + q_0 q_2) \\\\\n      2 (q_1 q_2 + q_0 q_3) & 1 - 2 (q_1^2 + q_3^2) & 2 (q_2 q_3 - q_0 q_1) \\\\\n      2 (q_1 q_3 - q_0 q_2) & 2 (q_2 q_3 + q_0 q_1) & 1 - 2 (q_1^2 + q_2^2)\n    \\end{pmatrix}\n  }\n\\label{rotation_matrix_R3_expression}\n\\end{equation}\nin accordance with \\cite{wiki:quaternions}.\n\n\\section{Belonging matrix}\n\n\\subsection{Definition}\n\nWe want to find for any ellipsoid $\\mathcal{A}$ a matrix $B$ acting on homogeneous coordinates with the following properties\n\\begin{equation}\n\\forall \\vec{r} \\in E^3, \\begin{cases} \\vec{r}^T B \\vec{r} < 0 &\\text{ if } \\vec{r} \\in \\mathcal{A} \\setminus \\bar{\\mathcal{A}} \\\\ \\vec{r}^T B \\vec{r} = 0 &\\text{ if } \\vec{r} \\in \\bar{\\mathcal{A}} \\\\ \\vec{r}^T B \\vec{r} > 0 &\\text{ if } \\vec{r} \\notin \\mathcal{A} \\end{cases}\n\\label{belonging_definition}\n\\end{equation}\nwhich we will call the \\textit{belonging matrix} of $\\mathcal{A}$.\n\n\\subsection{Expression}\n\\label{belonging_exp}\n\nWe have seen with equation \\ref{ellipsoid_matrix} that the belonging to the surface of an ellispoid could be expressed with a matrix whose eigenvectors define the principal axes of the ellipsoid and whose eigenvalues define the reciprocals of the squares of the semi-axes. Therefore, if we denote $(R_i)_{i=1:3}$ the semi-axes of the ellipsoid, this matrix can be written as $A = P^{-1}\\text{diag}(R_1^{-2},R_2^{-2},R_3^{-2})P$.\\\\\n\nThe semi-axes of an ellipsoid define an orthogonal base of $\\mathbb{R}^3$. Therefore P is the transition matrix from the orthogonal base formed by the principal axes of the ellipsoid to the original Euclidean base $(\\vec{e_i})_{i=1:3}$, and inversely for $P^{-1}$.\\\\\n\nConsequently, we have that $\\forall i \\in \\llbracket1,3\\rrbracket, \\vec{v} + R_iP^{-1}\\vec{e_i} \\in \\bar{\\mathcal{A}}$ and so\n\\begin{align*}\n\\forall i \\in \\llbracket1,3\\rrbracket,&(P^{-1}R_i\\vec{e_i})^TA(P^{-1}R_i\\vec{e_i}) = 1\\\\ \\Leftrightarrow&(P^{-1}R_i\\vec{e_i})^TP^{-1}\\text{diag}(R_j^{-2})_{j=1:3}P(P^{-1}R_i\\vec{e_i}) = 1\\\\\n\\Leftrightarrow &R_i\\vec{e_i}^T(P^{-1})^TP^{-1}\\text{diag}(R_j^{-2})_{j=1:3}\\underbrace{PP^{-1}}_{\\mathbbm{1}_3}R_i\\vec{e_i} = 1\\\\\n\\Leftrightarrow &\\vec{e_i}^T(P^{-1})^TP^{-1}\\underbrace{\\text{diag}(R_j^{-2})_{j=1:3}R_i^2\\vec{e_i}}_{\\vec{e_i}} = 1\\\\\n\\Leftrightarrow &\\vec{e_i}^T(P^{-1})^TP^{-1}\\vec{e_i} = 1\n\\end{align*}\nThus, the norm of every column vector of $P^{-1}$ equals to 1. Therefore, $P^{-1}$, and equivalently $P$, is an orthonormal matrix.\\\\\n\nIf $P$ is an orthonormal matrix, then the principal axes of the ellipsoids are derived from the original Euclidean base through rotations and permutations of axis. Without loss of generality, we can consider that there are no permutations of axis, leading to $P = \\mathcal{Q}_q^{-1} = \\mathcal{Q}_q^T$ with $q$ the quaternion describing the orientation of the ellipsoid. Equation \\ref{ellipsoid_matrix} thus becomes:\n\\begin{align*}\n\\forall \\vec{r} \\in \\mathbb{R}^3, \\vec{r} \\in \\bar{\\mathcal{A}} \\Leftrightarrow (\\vec{r}-\\vec{v})^T\\mathcal{Q}_q\\text{diag}(R_i^{-2})_{i=1:3}\\mathcal{Q}_q^T(\\vec{r}-\\vec{v}) = 1\n\\end{align*}\n\nWe can get rid of the $\\vec{v}$ by using homogeneous coordinates. In $E^3$, $\\vec{r} - \\vec{v}$ becomes $T_{-\\vec{v}}\\vec{r}$ and, to conserve the scalar product, $\\text{diag}(R_i^{-2})_{i=1:3}$ becomes $\\text{diag}(R_i^{-2},0)_{i=1:3}$.\\\\\n\nWe always assume that the last coordinate of our vectors in $E^3$ is 1, therefore we can notice that $\\forall \\vec{u} \\in E^3, \\vec{u}^T\\text{diag}(0,0,0,-1)\\vec{u} = -1$. We can then rewrite equation \\ref{ellipsoid_matrix}:\n\\begin{align*}\n\\forall \\vec{r} \\in E^3, \\vec{r} \\in \\bar{\\mathcal{A}} \\Leftrightarrow &\\vec{r}^TT_{-\\vec{v}}^TQ_q\\text{diag}(R_i^{-2},0)_{i=1:3}Q_q^TT_{-\\vec{v}}\\vec{r} = 1\\\\\n\\Leftrightarrow&\\vec{r}^T\\underbrace{T_{-\\vec{v}}^TQ_q\\text{diag}(R_i^{-2},-1)_{i=1:3}Q_q^TT_{-\\vec{v}}}_{\\mathcal{C}}\\vec{r} = 0\n\\end{align*}\nThe matrix $\\mathcal{C}$ is a good candidate for the belonging matrix of $\\mathcal{A}$, we then have to understand how it works.\\\\\n\nThe $T_{-\\vec{v}}$ translation and the $Q_q^T$ rotation bring back the principal axes of the ellipsoid to the original Euclidean base and origin. Without loss of generality, we can then consider that the principal axes of the ellipsoids are along $(\\vec{e_1},\\vec{e_2},\\vec{e_3})$.\\\\\n\nFor a vector \\(\\vec{r} = \\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix} \\in \\mathbb{R}^3\\), we have\n\\begin{align*}\n&\\frac{x^2}{R_1^2} + \\frac{y^2}{R_2^2} + \\frac{z^2}{R_3^2} = \\mu^2\\\\\n\\Leftrightarrow & \\frac{x^2}{(\\mu R_1)^2} + \\frac{y^2}{(\\mu R_2)^2} + \\frac{z^2}{(\\mu R_3)^2} = 1\n\\end{align*}\ntherefore, $\\mu$ can be construed as the rescaling factor that has to be applied to the ellipsoid for $\\vec{r}$ to be on its surface. Then, $\\mu < 1$ if $\\vec{r} \\in \\mathcal{A}\\setminus\\bar{\\mathcal{A}}$, $\\mu = 1$ if $\\vec{r} \\in \\bar{\\mathcal{A}}$, and $\\mu > 1$ otherwise.\\\\\n\nSince we have that $\\forall \\vec{r} \\in E^3, \\vec{r}^T\\mathcal{C}\\vec{r} = \\mu^2 - 1$, $\\mathcal{C}$ is the matrix we have been looking for, and we can define\n\\begin{equation}\n\\boxed{B(\\vec{v},q,(R_i)_{i=1:3}) \\equiv T_{-\\vec{v}}^TQ_q\\text{diag}(R_i^{-2},-1)_{i=1:3}Q_q^TT_{-\\vec{v}}}\n\\label{belonging_matrix}\n\\end{equation}\n\nOne must notice that such a matrix is symmetric. We can also define the \\textit{belonging function} of the ellipsoid $\\mathcal{A}$\n\\begin{equation}\n\\boxed{\\begin{aligned}\\mathcal{F}_{\\mathcal{A}} \\colon &E^3 \\to \\mathbb{R}\\\\     &\\phantomarrow{E^3}{\\vec{r}} \\vec{r}^TB(\\vec{v},q,(R_i)_{i=1:3})\\vec{r}\\end{aligned}}\n\\label{belonging_function}\n\\end{equation}\nsuch that $\\forall \\vec{r} \\in E^3$, $\\vec{r} \\in \\mathcal{A} \\Leftrightarrow \\mathcal{F}_{\\mathcal{A}}(\\vec{r}) \\leq 0$ and\n\\begin{equation}\n\\boxed{\\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = \\mu^2(\\vec{r}) - 1}\n\\end{equation}\nwith $\\mu^2(\\vec{r})$ the rescaling factor that has to be applied to the ellipsoid for $\\vec{r}$ to be on its surface.\n\n\\subsection{Reduced belonging matrix}\n\nThe equation \\ref{belonging_matrix} is theoretically relevant, however it is not computationally efficient.\\\\\n\nOn the one side, resorting to homogeneous coordinates and expressing the translation with a translation matrix (equation \\ref{translation_matrix}) leads to more operations than to express the rotation in $\\mathbb{R}^3$ directly. On the other side, we have seen in part \\ref{quaternions_interest} that the rotation of a vector was quicker performed when converting the quaternion associated to the rotation to a rotation matrix.\\\\\n\nWe then introduce, for an ellipsoid $\\mathcal{A}$ whose centre is located in $\\vec{v}$, whose orientation is described by the unit quaternion $q$ and whose semi-axes are $(R_i)_{i=1:3}$, the associate \\textit{reduced belonging matrix}\n\\begin{equation}\n\\boxed{\\bar{B}(q,(R_i)_{i=1:3}) \\equiv \\mathcal{Q}_q\\text{diag}(R_i^{-2})_{i=1:3}\\mathcal{Q}_q^T}\n\\label{reduced_belonging_matrix}\n\\end{equation}\nwith $\\mathcal{Q}_q$ the $\\mathbb{R}^3$ rotation matrix associated to $q$ (equation \\ref{rotation_matrix_R3}). One must notice that the reduced belonging matrix is also symmetric. Furthermore, this reduced belonging matrix has the following properties\n\\begin{equation}\n\\forall \\vec{r} \\in \\mathbb{R}^3, \\begin{cases} (\\vec{r} - \\vec{v})^T \\bar{B} (\\vec{r} - \\vec{v}) < 1 &\\text{ if } \\vec{r} \\in \\mathcal{A} \\setminus \\bar{\\mathcal{A}} \\\\ (\\vec{r} - \\vec{v})^T \\bar{B} (\\vec{r} - \\vec{v}) = 1 &\\text{ if } \\vec{r} \\in \\bar{\\mathcal{A}} \\\\ (\\vec{r} - \\vec{v})^T \\bar{B} (\\vec{r} - \\vec{v}) > 1 &\\text{ if } \\vec{r} \\notin \\mathcal{A} \\end{cases}\n\\label{reduced_belonging_definition}\n\\end{equation}\naccording to equation \\ref{belonging_definition}, which leads to the following expression for the belonging function:\n\\begin{equation}\n\\boxed{\\begin{aligned}\\mathcal{F}_{\\mathcal{A}} \\colon &\\mathbb{R}^3 \\to \\mathbb{R}\\\\     &\\phantomarrow{\\mathbb{R}^3}{\\vec{r}} (\\vec{r} - \\vec{v})^T\\bar{B}(q,(R_i)_{i=1:3})(\\vec{r}-\\vec{v}) - 1\\end{aligned}}\n\\label{belonging_function_reduced}\n\\end{equation}\n\n\\section{Unit normal vectors}\n\nSince the surface of the ellipsoid -- the locus of points where $\\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = 0$ -- is an isosurface of the function $\\mathcal{F}_{\\mathcal{A}}$, we have that $\\forall \\vec{r_S} \\in \\bar{\\mathcal{A}}, \\vec{\\nabla}\\mathcal{F}_{\\mathcal{A}}(\\vec{r_S})$ is a non-unit outward-facing normal vector to the ellipsoid in $\\vec{r_S}$.\\\\\n\nLet us note $\\forall \\vec{r_S} \\in \\bar{\\mathcal{A}}$, $\\vec{n}(\\vec{r_S})$ the unit outward-facing normal vector to the ellipsoid in $\\vec{r_S}$. Then $\\vec{n}(\\vec{r_S}) // \\vec{\\nabla}\\mathcal{F}_{\\mathcal{A}}(\\vec{r_S})$, we thus have to find the direction of this gradient.\n\n\\subsection{Expression with the belonging matrix}\n\\label{normal_vector_belonging}\n\nWe have that\n\\begin{align*}\n\\forall \\vec{r} \\in E^3, \\mathcal{F}_{\\mathcal{A}}(\\vec{r} + \\vec{dr}) &= (\\vec{r} + \\vec{dr})^TB(\\vec{r} + \\vec{dr})\\\\\n&= \\underbrace{\\vec{r}^TB\\vec{r}}_{\\mathcal{F}_{\\mathcal{A}}(\\vec{r})} + \\underbrace{\\vec{r}^TB\\vec{dr} + \\vec{dr}^TB\\vec{r}}_{2\\vec{dr}^TB\\vec{r}} + \\vec{dr}^TB\\vec{dr}\n\\end{align*}\ntherefore we can show that\n\\begin{align*}\n\\forall \\vec{r} \\in E^3, \\forall i \\in \\llbracket1,3\\rrbracket,~ &\\mathcal{F}_{\\mathcal{A}}(\\vec{r} + dr_i\\vec{e_i}) - \\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = 2dr_i\\vec{e_i}^TB\\vec{r} + dr_i^2\\vec{e_i}B\\vec{e_i}\\\\\n\\Rightarrow&\\frac{\\partial}{\\partial e_i}\\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = \\lim_{dr_i \\to 0} \\frac{\\mathcal{F}_{\\mathcal{A}}(\\vec{r} + dr_i\\vec{e_i}) - \\mathcal{F}_{\\mathcal{A}}(\\vec{r})}{dr_i} = 2\\vec{e_i}^TB\\vec{r}\\\\\n\\Rightarrow&\\vec{\\nabla}\\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = \\sum_{i=1}^3\\left(\\frac{\\partial}{\\partial e_i}\\mathcal{F}_{\\mathcal{A}}(\\vec{r})\\right)\\vec{e_i} = 2\\underbrace{\\sum_{i=1}^3(\\vec{e_i}^TB\\vec{r})\\vec{e_i}}_{B\\vec{r}}\n\\end{align*}\n\\textit{i.e.} $\\vec{\\nabla}\\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = 2B\\vec{r}$. Consequently, we finally have that\n\\begin{equation}\n\\boxed{\\forall \\vec{r_S}\\in \\bar{\\mathcal{A}}, \\vec{n}(\\vec{r_S}) = \\frac{B(\\vec{v},q,(R_i)_{i=1:3})\\vec{r_S}}{|B(\\vec{v},q,(R_i)_{i=1:3})\\vec{r_S}|}}\n\\end{equation}\n\n\\subsection{Expression with the reduced belonging matrix}\n\nWith the same notations while assuming that the centre of the ellipsoid is located in $\\vec{v}$, we can notice that replacing $\\vec{r}$ by $(\\vec{r} - \\vec{v})$ in the demonstration of part \\ref{normal_vector_belonging} leads to the following expression\n\\begin{align*}\n\\forall \\vec{r} \\in E^3, \\forall i \\in \\llbracket1,3\\rrbracket,~ &\\mathcal{F}_{\\mathcal{A}}(\\vec{r} + dr_i\\vec{e_i}) - \\mathcal{F}_{\\mathcal{A}}(\\vec{r}) = 2dr_i\\vec{e_i}^T\\bar{B}(\\vec{r} - \\vec{v}) + dr_i^2\\vec{e_i}\\bar{B}\\vec{e_i}\n\\end{align*}\nand thus, by analogy, the following result\n\\begin{equation}\n\\boxed{\\forall \\vec{r_S}\\in \\bar{\\mathcal{A}}, \\vec{n}(\\vec{r_S}) = \\frac{\\bar{B}(q,(R_i)_{i=1:3})(\\vec{r_S} - \\vec{v})}{|\\bar{B}(q,(R_i)_{i=1:3})(\\vec{r_S} - \\vec{v})|}}\n\\label{surface_vec_reduced}\n\\end{equation}\n\n% \\input{references/biblio}\n\n\\end{document}\n\n% \\end{cbunit}\n", "meta": {"hexsha": "dafa53d90e4e834b222289ab07db4086e9777200", "size": 18670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/appendices/app_ellipsoids.tex", "max_stars_repo_name": "yketa/Umea_2017_Notes", "max_stars_repo_head_hexsha": "3b0e564e9054383bd91ff46930afe5543e9845ca", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/appendices/app_ellipsoids.tex", "max_issues_repo_name": "yketa/Umea_2017_Notes", "max_issues_repo_head_hexsha": "3b0e564e9054383bd91ff46930afe5543e9845ca", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/appendices/app_ellipsoids.tex", "max_forks_repo_name": "yketa/Umea_2017_Notes", "max_forks_repo_head_hexsha": "3b0e564e9054383bd91ff46930afe5543e9845ca", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.7394366197, "max_line_length": 430, "alphanum_fraction": 0.6638993037, "num_tokens": 7509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893520001, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6567775425342047}}
{"text": "%%%% 3D Skewness Example %%%%%%\n\n\\subsection{Dependence on Dimension}\\label{ex:3dmap}\nTo further illustrate that relationship between skewness and accuracy holds as we move towards higher dimensions, we extend the numerical investigation to a three--dimensional parameter space.\nGenerally, we have fewer QoI than number of uncertain model parameters, so we assume that the potential QoI maps are defined by the $2\\times 3$ matrices\n\\begin{equation}\\label{eq:qmap3}\n\\qspace_S := \\left \\lbrace \\qoi^{(s)} =  \\mat{ccc}{1 & 0 & 0\\\\ \\sqrt{s^2 - 1}& 1 & 0} \\right \\rbrace_{s\\in S}.\n\\end{equation}\nHere, as in the previous example, the index $s$ indicates the magnitude of skewness.\nFurthermore, the results of Example~\\ref{ex:rotation} justify the restriction of the maps to this form since any linear map of skewness $s$ is simply a rotation of maps of this form.\n\n%Now, the generalized contours for inverses of maps from $\\RR^3 \\to \\RR^2$ will be isomorphic to 2\\--dimensional contour events in that the inverse sets will be columns in 3\\-space orthogonal to the aforemntioned plane.\n%\n%IMAGE DEMONSTRATING THIS WOULD HELP.\n%We define\n%\n%which is just the map from \\eqref{eq:qmap2} appended with zeros in the third column.\n%We make this choice solely for convience and are justified in doing so owing to Proposition~\\ref{prop:rot_invariance} and the fact of generalized contours of maps from $\\RR^3 \\to \\RR^2$ being parallel columns.\n%The rotational invariance naturally extends to the third dimension.\n\n%We note that $\\bar{N}$ is much higher since we kept the convention of 200 grid cells per dimension in our reference.\n%However, we kept the same number of random samples $N$, so we should expect higher errors due to the overresolved regular grid.\n%Fortunately, we find that the results still generalize.\n%We present the case where $M=1$:\n\n\\begin{figure}[h]\n\\begin{table}[H]\n\\begin{tabular}{ c | c | c | c }\n\\nsamps & $\\qoiA$ & $\\qoiB$ & $\\qoiC$\\\\ \\hline \\hline\n$200$ & $3.33E-01$ & $4.56E-01$ & $6.10E-01$\\\\ \\hline\n\n$400$ & $2.78E-01$ & $3.51E-01$ & $4.97E-01$\\\\ \\hline\n\n$800$ & $2.19E-01$ & $2.95E-01$ & $4.10E-01$\\\\ \\hline\n\n$1600$ & $1.72E-01$ & $2.37E-01$ & $3.35E-01$\\\\ \\hline\n\n$3200$ & $1.36E-01$ & $1.89E-01$ & $2.64E-01$\\\\ \\hline\n\n$6400$ & $1.09E-01$ & $1.47E-01$ & $2.09E-01$\\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\includegraphics[width=0.45\\linewidth]{./images/Plot-reg_BigN_8000000_reg_M_1_rand_I_100000.png}\n\n\\caption{The results of $d^2_\\text{TV}(\\PP_{\\pspace, \\ndiscs, \\nsamps}, \\PP_{\\pspace, \\ndiscs, \\bar{\\nsamps}})$ for $\\ndiscs = 1, \\bar{\\nsamps} = 8,000,000$, with $a, b, c = 1, 2, 4$ in three dimensions.}\n\\label{fig:M1_3d}\n\\end{figure}\n\\FloatBarrier\nIn Figure~\\ref{fig:M1_3d}, it appears that the effect of skewness is even more pronounced in higher dimensions, and that the number of samples required to achieve similar levels of accuracy between two maps with a ratio of skewness 2 is now quadrupled.\nThe analysis of \\cite{BGE+15} suggested a dependence of accuracy related to the skewness raised to a power related to the dimension of the data space.\n", "meta": {"hexsha": "a33cb067664bbdd55b292a185d99962a10229715", "size": 3072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/skew_example_3d.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/skew_example_3d.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/skew_example_3d.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": 59.0769230769, "max_line_length": 252, "alphanum_fraction": 0.7223307292, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6567775405380203}}
{"text": "\\addcontentsline{toc}{section}{Exercise 2.1 Bayes rule for medical diagnosis}\n\\section*{Exercise 2.1 Bayes rule for medical diagnosis}\n\\import{sections/}{exercise 2-1.tex}\n\\newpage\n\\addcontentsline{toc}{section}{Exercise 2.2 Legal reasoning}\n\\section*{Exercise 2.2 Legal reasoning}\n\\import{sections/}{exercise 2-2.tex}\n\\newpage\n\\addcontentsline{toc}{section}{Exercise 2.3 Probabilities are sensitive to the form of the question that was used to generate the answer}\n\\section*{Exercise 2.3 Probabilities are sensitive to the form of the question that was used to generate the answer}\n\\import{sections/}{exercise 2-3.tex}\n\\newpage\n\\addcontentsline{toc}{section}{Exercise 2.4 Deriving the posterior predictive density for the healthy levels game}\n\\section*{Exercise 2.4 Deriving the posterior predictive density for the healthy levels game}\n\\import{sections/}{exercise 2-4.tex}\n", "meta": {"hexsha": "5b33412858fcf9fe01adaf69c251b6bb9a746bfc", "size": 875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter 2.tex", "max_stars_repo_name": "bsuleymanov/Murphy-PML-Solutions", "max_stars_repo_head_hexsha": "3329e8120ae3c634e032e784eba1eb8443a49b74", "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 2.tex", "max_issues_repo_name": "bsuleymanov/Murphy-PML-Solutions", "max_issues_repo_head_hexsha": "3329e8120ae3c634e032e784eba1eb8443a49b74", "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 2.tex", "max_forks_repo_name": "bsuleymanov/Murphy-PML-Solutions", "max_forks_repo_head_hexsha": "3329e8120ae3c634e032e784eba1eb8443a49b74", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.6875, "max_line_length": 137, "alphanum_fraction": 0.7942857143, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629215, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6567775389176584}}
{"text": "\\section{Finding Periodic Solutions}\n\\label{sec:initial}\n\nA separate problem from evaluating, optimizing and continuing periodic solutions is finding an initial candidate solution.\nBecause continuation is a crucial part of this project, having just one single periodic solution might enable to find many others, through tracing and switching solution branches.\nBecause the systems considered in this work have stable periodic solutions, we focus on this case.\nWhen this is not the case, as mentioned in the section about continuation methods (\\autoref{sec:cont}), a homotopy between a trivial system and the target system, combined with continuation methods, might be a promising approach.\n\nStarting from a point in the periodic solution's basin of attraction, one can simply forward integrate such a system.\nThere are several possible problems involved:\n\\begin{itemize}\n\t\\item Forward integration can accumulate errors.\n\t\\item Even if the starting point lies exactly on the periodic trajectory, the sampling interval would probably not be an integer fraction of the period of the periodic trajectory.\n\t\tPeriodicity in the sequence of points are not directly related to periodicity in the continuous system.\n\t\\item Given the nature of the project, it is very likely that period doubling bifurcations are encountered.\n\t\tThese provoke situations where two periodic solutions exist which are difficult to distinguish.\n\\end{itemize}\n\nForward integration yields a sequence of points in phase space $(\\textbf{s}_i)_{i \\in \\N}$.\nTo obtain more manageable data only intersections of the trajectory with a hyperplane $p(\\textbf{x}) = \\langle \\textbf{n}, \\textbf{x}-\\textbf{x}_0 \\rangle = 0$ in a single direction are considered (so called Poincaré sections).\nTo find these, $\\textbf{s}_i, \\textbf{s}_{i+1} = \\textbf{s}_i + h_0 \\cdot \\textbf{f}(\\textbf{s}_i)$ with $p(s_i) \\le 0 < p(s_{i+1})$ are searched.\nBecause of continuity, there needs to exists $h \\in [0,h_0]$ such that $p(\\textbf{s}_i + h \\cdot \\textbf{f}(\\textbf{s}_i)) = 0$, which is found via bisection.\nLet $(\\textbf{u}_i)_{i \\in \\N}$ be the sequence of intersections.\n\nTo find the number of intersections per period, the intersections are partitioned into $k \\in \\N$ disjoint clusters $V_{k,i} = \\{ \\textbf{u}_m\\ |\\ m \\in k\\N+i \\}$ for $i \\in \\N$, $i \\le k$.\nThe relative quality of the $i$-th cluster can then be assessed using the within-cluster variance $\\sum_{v \\in V_{k,i} } ||v - \\E(V_{k,i})||^2$.\nThe correct number $k_{\\text{min}} \\in \\N$ of intersections in one period is then taken to be the one minimizing the sum of within-cluster variances:\n\\[\n\tk_\\text{min} \\coloneqq \\argmin_{k \\in \\N} \\sum_{i = 1}^k \\sum_{v \\in V_{k,i} } ||v - \\E(V_{k,i})||^2 \\text.\n\\]\nFor further information about these measures see for example \\cite{halkidi2001clustering}. %TODO measure...\n\nIn this form the criterion might at best work if the intersection sequence is infinite.\nWhen dealing with finite sequences increasing the number of clusters inevitably leads to lower total within-cluster variances.\nIt is thus necessary to constrain the available values for $k$ and discourage the method of overestimating the number of clusters.\nTrivially an upper limit for $k$ needs to be introduced.\nFurthermore, the minimality criterion needs to be relaxed: Suppose there are $k_\\text{min}$ intersections per period, then all multiples of $k_\\text{min}$ yield equal or lower ratings.\nOne thus wants to choose the minimum $k$ which is in some sense still almost optimal.\n", "meta": {"hexsha": "2c032ce294a560b283d1874b9799f66d43dbbc25", "size": 3506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doctheory/initial.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/initial.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/initial.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": 89.8974358974, "max_line_length": 229, "alphanum_fraction": 0.7629777524, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6567775367335628}}
{"text": "\\section{SCC}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Digraph as DAG}\n  \\begin{exampleblock}{Digraph as DAG (Problem 5.3)}\n    Every digraph is a dag of its SCCs.\n  \\end{exampleblock}\n\n  \\begin{alertblock}{Remark}\n    Two tiered structure of digraphs:\n    \\begin{itemize}\n\t  \\item digraph $\\equiv$ a dag of SCCs\n      \\item SCC: equivalence class over reachability\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{SCC}\n  \\begin{exampleblock}{Kosaraju SCC algorithm, 1978}\n\t\\begin{quote}\n\t  ``SCCs can be topo-sorted in decreasing order of their highest finish time.''\n\t\\end{quote}\n\n\t\\pause\n\t\\centerline{The vertice with the highest finish time is in a source SCC.}\n  \\end{exampleblock}\n\n  \\pause\n  \\begin{alertblock}{Remark}\n    \\begin{itemize}\n      \\item DFS on $G$; \\; DFS/BFS on $G^{T}$\n      \\item DFS on $G^{T}$; DFS/BFS on $G$\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{SCC}\n  \\begin{exampleblock}{Kosaraju SCC algorithm, 1978 (Problem 5.4)}\n    \\begin{itemize}\n      \\item 1st DFS $\\xLongrightarrow{?}$ BFS\n      \\item 2nd DFS $\\xLongrightarrow{?}$ BFS\n    \\end{itemize}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{One-to-all reachability}\n  \\begin{exampleblock}{One-to-all reachability (Problem 5.12)}\n\tDigraph $G = (V, E)$:\n    \\begin{itemize}\n      \\item given $v: v \\leadsto^{?} \\forall u$\n      \\item $\\exists?\\; v: v \\leadsto \\forall u$\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\pause\n  \\[\n\t\\text{SCC; } \\exists! \\text{source vertex } v \\iff v \\leadsto \\forall u\n  \\]\n\n  \\pause\n  \\begin{proof}\n\t\\begin{itemize}\n\t  \\item $\\Longleftarrow$: (1) source (2) $\\exists !$\n\t\t\\pause\n\t  \\item $\\implies$: By contradiction. \n\t\t% \\pause\n\t\t% \\[\n\t\t%   \\exists u: v \\not\\leadsto u \\land \\text{in}[u] > 0 \\implies \\exists u' \\to u \\land v \\nrightarrow u' \\implies \\exists \\text{ cycle}\n\t\t% \\]\n\t\\end{itemize}\n  \\end{proof}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Impacts of vertices}\n  \\begin{exampleblock}{Impacts of vertices (Problem 5.13)}\n\tDigraph $G$:\n\t\\[\n\t  \\text{impact}(v) = |\\set{w: v \\leadsto w}|\n\t\\]\n\n\t\\begin{itemize}\n\t  \\item $\\argmin_{v} \\text{impact}(v)$\n\t  \\item $\\argmax_{v} \\text{impact}(v)$\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\pause\n  \\vspace{0.50cm}\n  \\centerline{$\\argmin_{v} \\text{impact}(v) \\in \\text{SCC of smallest cardinality}$}\n\n  \\pause\n  \\begin{alertblock}{Question}\n\t$\\forall v:$ computing $\\text{impact}(v)$.\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{One-way streets}\n  \\begin{exampleblock}{One-way streets (Problem 5.15)}\n\tDigraph $G$ for city:\n    \\begin{enumerate}\n      \\item $\\forall u,v: u \\leftrightsquigarrow v$\n      \\item $s: s \\leadsto v \\leadsto s$\n    \\end{enumerate}\n  \\end{exampleblock}\n\n  \\pause\n  \\[\n\t(2)\\; \\set{v \\mid s \\leadsto v} \\text{ is an SCC}\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Connectivity}\n  \\begin{exampleblock}{Connectivity (Problem 5.7)}\n\t\\begin{description}[Example:]\n\t  \\item[Prove:] connected undirected graph $G$: \n\t\t\\[\n\t\t  \\exists v: G \\setminus v \\text{ is still connected}\n\t\t\\]\n\t  \\item[Example:] strongly connected digraph $G$:\n\t\t\\[\n\t\t  \\exists v: G \\setminus v \\text{ is not strongly connected}\n\t\t\\]\n\t  \\item[Example:] digraph $G$ with 2 SCCs:\n\t\t\\[\n\t\t  (G + e) \\text{ is not strongly connected}\n\t\t\\]\n\t\\end{description}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{2SAT}\n  \\begin{exampleblock}{2SAT (Problem 5.17)}\n\t\\[\n\t  I: (x_1 \\lor \\overline{x_2}) \\land (\\overline{x_1} \\lor \\overline{x_3}) \\land (x_1 \\lor x_2) \\land (\\overline{x_3} \\lor x_4) \\land (\\overline{x_1} \\lor x_4)\n\t\\]\n  \\end{exampleblock}\n\n  \\pause\n  \\[\n\t\\alpha \\lor \\beta \\equiv \\overline{\\alpha} \\to \\beta \\equiv \\overline{\\beta} \\to \\alpha\n  \\]\n\n  \\pause\n  \\begin{center}\n\tImplication graph $G_I$.\n  \\end{center}\n\n  \\pause\n  \\begin{theorem}\n\t\\[\n\t  \\exists \\text{ SCC } \\exists x: v_x \\in \\text{SCC} \\land v_{\\overline{x}} \\in \\text{SCC} \\iff I \\text{ is not satisfiable}.\n\t\\]\n  \\end{theorem}\n\n  \\pause\n  \\begin{alertblock}{Reference}\n\t\\begin{itemize}\n\t  \\pause\n\t  \\item ``A Linear-time Algorithm for Testing the Truth of Certain Quantified Boolean Formulas'' by Bengt Aspvall, Michael Plass, and Robert Tarjan, 1979.\n\t\\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{2SAT}\n  % \\begin{gather*}\n  %   (x_0\\lor x_2)\\land(x_0\\lor\\lnot x_3)\\land(x_1\\lor\\lnot x_3)\\land(x_1\\lor\\lnot x_4)\\land\\\\\n  %   (x_2\\lor\\lnot x_4)\\land (x_0\\lor\\lnot x_5)\\land (x_1\\lor\\lnot x_5)\\land (x_2\\lor\\lnot x_5)\\land\\\\\n  %   (x_3\\lor x_6)\\land (x_4\\lor x_6)\\land (x_5\\lor x_6)\n  % \\end{gather*}\n  \\begin{columns}\n\t\\column{0.50\\textwidth}\n\t  % \\fignocaption{width = 0.80\\textwidth}{figs/2sat-implication-graph-wiki.png}\n\t  \\fignocaption{width = 0.80\\textwidth}{figs/2sat-implication-graph.pdf}\n\t\\column{0.50\\textwidth}\n\t  \\pause\n\t  \\fignocaption{width = 0.80\\textwidth}{figs/2sat-implication-graph.png}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Odd cycle in digraph}\n%   \\begin{exampleblock}{Odd cycle in digraph (Additional Problem)}\n%     Find an odd cycle in a digraph $G$.\n%   \\end{exampleblock}\n% \n%   \\pause\n%   \\begin{lemma}\n%     A digraph $G$ has an odd directed cycle $\\iff$ $\\exists \\text{scc}: $ scc is non-bipartite (when treated undirected).\n%   \\end{lemma}\n% \n%   \\pause\n%   \\begin{alertblock}{Question}\n% \tTo prove the lemma and design an algorithm.\n%   \\end{alertblock}\n%   % \\begin{proof}\n%   %   $\\Longleftarrow$: undirected $C$; oriented\n%   %     \\begin{itemize}\n%   %   \t\\item odd directed cycle\n%   %   \t\\item choose a direction $\\forall u \\to v$: $\\text{Len}(v \\leadsto u)$ \n%   %     \\end{itemize}\n%   % \\end{proof}\n% \\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "d2926c6903cfbd6e30084d5d8deca5db2b937d07", "size": 5708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-graph-decomposion-20170524/sections/scc.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/scc.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/scc.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.118226601, "max_line_length": 159, "alphanum_fraction": 0.6187806587, "num_tokens": 2067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.6567775345494665}}
{"text": "\\section{Determinants of \\texorpdfstring{$2\\times 2$}{2x2}- and \\texorpdfstring{$3\\times 3$}{3x3}-matrices}\n\n\\begin{outcome}\n  \\begin{enumerate}\n    \\item Calculate the determinant of $2\\times 2$-matrices and\n      $3\\times 3$-matrices.\n  \\end{enumerate}\n\\end{outcome}\n\nLet $A$ be an $n\\times n$-matrix. The \\textbf{determinant}%\n\\index{determinant} of $A$, denoted by $\\det(A)$, is a very important\nnumber which we will explore throughout this chapter.\n\nThe determinant of a$2\\times 2$-matrix is given by the following\nformula.\n\n\\begin{definition}{Determinant of a $2\\times 2$-matrix}{two-by-two-determinant}\n  Let $A=\\begin{mymatrix}{rr}\n    a & b \\\\\n    c & d\n  \\end{mymatrix}$. Then\n  \\begin{equation*}\n    \\det(A) = ad-bc.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{A $2\\times 2$ determinant}{two-by-two-determinant}\n  Find $\\det(A)$ for the matrix\n  $A =  \\begin{mymatrix}{rr}\n    2 & 4 \\\\\n    -1 & 6\n  \\end{mymatrix}$.\n\\end{example}\n\n\\begin{solution}\n  We have $\\det(A) = 2\\cdot 6 - (-1)\\cdot 4 = 12 + 4 = 16$.\n\\end{solution}\n\nThe determinant is also often denoted by enclosing the matrix with two\nvertical lines. Thus\n\\begin{equation*}\n  \\det \\begin{mymatrix}{cc}\n    a & b \\\\\n    c & d\n  \\end{mymatrix} =\\begin{absmatrix}{cc}\n    a & b \\\\\n    c & d\n  \\end{absmatrix}\n  = ad - bc.\n\\end{equation*}\n\n\\begin{definition}{Determinant of a $3\\times 3$-matrix}{3-by-3-determinant}\n  Let $A=\\begin{mymatrix}{ccc}\n    a_{11} & a_{12} & a_{13} \\\\\n    a_{21} & a_{22} & a_{23} \\\\\n    a_{31} & a_{32} & a_{33} \\\\\n  \\end{mymatrix}$. Then\n  \\begin{equation*}\n    \\det(A)\n    = a_{11}a_{22}a_{33}\n    + a_{12}a_{23}a_{31}\n    + a_{13}a_{21}a_{32}\n    - a_{31}a_{22}a_{13}\n    - a_{32}a_{23}a_{11}\n    - a_{33}a_{21}a_{12}.\n  \\end{equation*}\n\\end{definition}\n\nThe following picture may help in memorizing the formula:\n\\begin{equation*}\n  \\begin{tikzpicture}[yscale=0.6,xscale=0.9]\n    \\draw[ultra thick,red!30] (1,-3) -- (3,-1);\n    \\draw[ultra thick,red!30] (2,-3) -- (4,-1);\n    \\draw[ultra thick,red!30] (3,-3) -- (5,-1);\n    \\draw[ultra thick,blue!60] (1,-1) -- (3,-3);\n    \\draw[ultra thick,blue!60] (2,-1) -- (4,-3);\n    \\draw[ultra thick,blue!60] (3,-1) -- (5,-3);\n    \\foreach\\i in {1,2,3} {\n      \\foreach\\j in {1,2,3} {\n        \\path (\\j,-\\i) node {$a_{\\i\\j}$};\n      }\n    }\n    \\foreach\\i in {1,2,3} {\n      \\foreach\\j in {1,2} {\n        \\path (\\j,-\\i) + (3,0) node {$a_{\\i\\j}$};\n      }\n    }\n    \\draw(0.5,-2) node {$\\left[\\rule{0mm}{1.0cm}\\right.$};\n    \\draw(3.5,-2) node {$\\left.\\rule{0mm}{1.0cm}\\right]$};\n  \\end{tikzpicture}\n\\end{equation*}\nHere, we have written down the matrix $A$, then repeated the first two\ncolumns next to it. The blue lines correspond to the positive terms of\nthe determinant: $\\color{blue}a_{11}a_{22}a_{33}$,\n$\\color{blue}a_{12}a_{23}a_{31}$, and\n$\\color{blue}a_{13}a_{21}a_{32}$. The pink lines correspond to the\nnegative terms: $\\color{red}a_{31}a_{22}a_{13}$,\n$\\color{red}a_{32}a_{23}a_{11}$, and $\\color{red}a_{33}a_{21}a_{12}$.\n\n\\begin{example}{A $3\\times 3$ determinant}{3-by-3-determinant}\n  Find $\\det(A)$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      0 & 1 & 2 \\\\\n      3 & 1 & 0 \\\\\n      1 & 1 & -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\det(A) ~=~\n    \\begin{absmatrix}{rrr}\n      0 & 1 & 2 \\\\\n      3 & 1 & 0 \\\\\n      1 & 1 & -1 \\\\\n    \\end{absmatrix}\n    ~=~\n    0\\cdot 1\\cdot (-1)\n    + 1\\cdot 0 \\cdot 1\n    + 2 \\cdot 3 \\cdot 1\n    - 1\\cdot 1\\cdot 2\n    - 1\\cdot 0\\cdot 0\n    - (-1)\\cdot 3\\cdot 1\n    ~=~ 7.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "fe5dfb67fc75fe4c3abe184a671e4b14e2096a7b", "size": 3586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Determinants-TwoAndThree.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Determinants-TwoAndThree.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Determinants-TwoAndThree.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.5846153846, "max_line_length": 107, "alphanum_fraction": 0.5819854992, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6567775333988836}}
{"text": "\\lab{Logistic Regression}{Logistic Regression}\n\\objective{Understand the basics of Logistic Regression, and apply to the Titanic problem.}\n\n\\subsection*{Binary Logistic Regression}\nA \\emph{Logistic Regression Model} is a probability model that can be used to predict outcomes for a set of data.  Usually ``Logistic Regression\" refers to what is more appropriately called \\emph{binary logistic regression}.  This is a model which can assign data points to one of two sets, and is used in many different fields.  One common medical example is predicting whether or not a patient has a particular disease.  Based upon several factors, which may be both continuous (age, height, weight) and categorical (gender, race), we can quantify the probability of infection.  This probability is computed by way of the \\emph{logistic function}, which, given the contributing factors, will return a probability value between $0$ and $1$.  This probability will then be used to assign a label to our input data (`infected' or `not infected', for example) by using some cut-off value, and will depend on the need for accuracy in the specific application.  Success corresponds to a label of $1$, and failure to a label of $0$.\n\nThe logistic function takes in as input any real number and returns a value between $0$ and $1$, and is defined explicitly as\n\\begin{equation}\n\\phi(t) = \\frac{1}{1 + e^{-s}},\n\\end{equation}\nwhere $s$ is some combination of the input variables $x_1, \\cdots, x_n$.  The graph of this function can be seen in Figure ???.   $\\phi(x)$ can then be interpreted as the probability of success.  In some cases it is not possible to find a closed-form expression for the correct combination of the input variables.  However, in many cases we can acheive reasonable accuracy by using a linear combination of $x_i, \\cdots, x_n$, i.e.\n\\begin{equation*}\ns = c_0 + c_1 x_1 + \\cdots + c_n x_n.\n\\end{equation*}\nThis can be written more compactly as\n\\begin{equation*}\ns = \\bf{c}^{T}\\bf{x},\n\\end{equation*}\nwhere $\\bf{x}$ $= (1, x_1, \\cdots , x_n)^{T}$ and $\\bf{c}$ $\\in \\mathbb{R}^{n+1}$.\n\nGiven a training set of labeled data points, a Logistic Regression Model will find the optimal $\\bf{c}$ for the data, and can then be used to predict labels for further data points.\n\n\\subsection*{The Titanic Problem}\nThe Titanic dataset is especially useful for Logistic Regression.  This dataset is composed of actual data obtained concerning the passengers on the ill-fated Titanic voyage, given in the bulleted list below.  Using logistic regression, we can predict whether or not a passenger survived based on this data.  We do so by training a model on a portion of the dataset, the training set, and predicting labels for the remaining data, the test set.\n\nBefore beginning our classification, however, we will first need to process our data.  The Titanic dataset contains much more information than is currently relevant for our purposes.  You can obtain this data in Excel Spreadsheet form at [Insert link here].  We recommend using pandas to read in and process the data.  The columns are as follows:\n\\begin{itemize}\n\\item \\li{pclass}: An integer in $\\{1, 2, 3\\}$ which describes the class the passenger was in.\n\\item \\li{survived}:  The dependent variable.  $1$ indicates survival, and $0$ death.\n\\item \\li{name}: A string containing the passenger's name.\n\\item \\li{sex}: A string, either `male' or `female'.\n\\item \\li{age}: Either an integer or a float.\n\\item \\li{sibsp}: An integer giving the number of siblings and/or spouse who embarked with the passenger.\n\\item \\li{parch}: An integer giving the number of parents and/or children who embarked with the passenger.\n\\item \\li{ticket}: A string containing the transaction code for the ticket(s) purchased.\n\\item \\li{fare}: A float giving the cost of the ticket purchased.\n\\item \\li{cabin}: A string giving the assigned sleeping cabin for the passenger (note that the majority of this column is blank).\n\\item \\li{embarked}: A string in $\\{S, C, Q\\}$ corresponding to the location of the passenger's embarkment, Southampton (UK), Cherbourg (France), or Queenstown (Ireland), respectively.\n\\item \\li{boat}: An int or string for those who survived giving which life boat they rode in.\n\\item \\li{body}: An int giving the number of body for those who died who were found and identified.\n\\item \\li{home.dest}: A string giving the home of or location to which the passenger was headed.\n\\end{itemize}\n\n\\begin{problem}\nCreate a function called \\li{initialize} which will process the Titanic data set into useable format by doing the following:\n\\begin{enumerate}\n\\item Choose the coulmns that you believe will be relevant in predicting the survival of the passengers, and drop the other columns.  You may not use \\li{boat} or \\li{body}, as these are dependent on whether or not the passenger survived.  Be sure to include \\li{survived}, which will be separated later as the independent variable, as well as \\li{sex} and \\li{pclass}.\n\\item Since \\li{sex} is really a binary variable, make it one explicitly by changing ``female\" and ``male\" to be binary values.\n\\item Drop the rows that contain missing values.  Make sure you have a significant number of rows left.  If you have too few, you may need to choose fewer columns to keep before deleting the incomplete rows.\n\\item Because the \\li{pclass} column is an integer in $\\{1, 2, 3\\}$, it will be treated as a ranked variable instead of simply a categorical variable.  It may be useful to rank this variable, or it may mess up our classification.  Include a keyword argument \\li{pclass_change} with default \\li{True}.  If it is set to \\li{True}, eliminate this ranking by dividing \\li{pclass} into two binary columns.  Make one column a boolean for being $1^{st}$ class and the other a boolean for being $2^{nd}$ class. (This means that a value of $1$ would correspond to $[1, 0]$, $2$ to $[0, 1]$, and $3$ to $[0, 0]$.)\n\\item Split the remaining rows into a training and a test set using a $60/40$ split.  Be sure and pick random rows for each group and not rows in any particular order.\n\\end{enumerate}\nHave your function return the training set and the test set, in that order.\n\\end{problem}\n\n\\subsection*{Model Evaluation}\nNow that we have our training set, we can train a model, which can be used to obtain the probability of success for each data point.  The label chosen depends heavily on the probability cut-off value mentioned previously, which we represent as $\\tau$.  In the simplest manner, we can simply pick a value of $\\tau = 0.5$, which will then assign the label with the highest likelihood.  However, it is often beneficial to choose a different value of $\\tau$.  In regards to the probability of infection for serious diseases, it might be best to give a patient medicine if they have even a $10$ percent chance of infection.  So how can we find the ``best\" cut-off value?\n\nIn order to determine this, we need to discuss how to measure the accuracy of the labels predicted.  Say that we have picked a cut-off value $\\tau$, and have assigned labels to the test set.  Using the predicted labels and the actual labels, we can obtain four important values: the number of \\emph{true positives}, \\emph{false positives}, \\emph{true negatives}, and \\emph{false positives}, which are abbreviated TP, FP, TN, and FP, respectively.  These values are integers which together sum to the number of labels predicted.  You can see the definition of these in Table ??? (until the figure is up, true positives are the points with predicted label 1 and true label 1, false positives have predicted label 1 true label 0, true negatives predicted label 0 true label 0, and false negatives true label 1 predicted label 0).  We can now use these to report our accuracy in various metrics:\n\\begin{itemize}\n\\item \\emph{Prediction accuracy} is defined as $\\frac{TP+TN}{TP+FN+FP+TN}$, and is the percentage of correctly predicted cases.\n\\item \\emph{Sensitivity}, also known as the \\emph{true positive rate} or $TPR$, is given by the fraction of correctly predicted cases where the actual outcome is $1$, $\\frac{TP}{TP+FN}$.\n\\item \\emph{Specificity}, the \\emph{true negative rate}, or $TNR$ is the proportion of correctly predicted cases where the true outcome is $0$, $\\frac{TN}{FP+TN}$.\n\\item \\emph{False Positive Rate}, or $FPR$, is the proportion of incorrectly predicted cases where the true outcome is $0$, and is given by $\\frac{FP}{FP+TN}$.\n\\end{itemize}\nAll of these depend strongly on the value chosen for $\\tau$.\n\nA \\emph{roc curve} is useful in measuring the accuracy of a model.  To make a roc curve, we pick many values for $\\tau$, and obtain the False Positive Rate and the True Positive Rate for each.  Then we plot the data points  $(FPR_{\\tau},TPR_{\\tau})$ for each value of $\\tau$ chosen and connect them into a curve.  A completely random label assignment would result in a nearly-linear roc curve, while a more accurate assignment would result in a more steeply-rising curve (see Figure ???).  A good choice for $\\tau$ is the one that intersects the family of lines $y=x+b$ at only one point, which intuitively is the point closest to the vertex $(0, 1)$.  Mathematically, this is given by\n\\begin{equation}\n\\operatorname*{arg\\,max}_{\\tau} (TPR_{\\tau} - FPR_{\\tau}).\n\\end{equation}\n\n\\begin{problem}\nUse the function declaration below to find the best value for $\\tau$.  You should use evenly spaced values from $0$ to $1$, exclusive.\n\\begin{lstlisting}\ndef best_tau(predicted_labels, true_labels, n_tau=100, plot=True):\n    \"\"\"\n    Parameters\n    ----------\n    predicted_labels : ndarray of shape (n,)\n        The predicted labels for the data\n    true_labels : ndarray of shape (n,)\n        The actual labels for the data\n    n_tau : int\n        The number of values to try for tau\n    plot : boolean\n        Whether or not to plot the roc curve\n\n    Returns\n    -------\n    best_tau : float\n        The optimal value for tau for the data.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nNow that we have a good value for $\\tau$, we can quantify the accuracy of a model. We will do so for a few different types of models for the Titanic data you initialized previously.  For the first two, we will use the logistic classifier found in \\li{sklearn.linear_model.LogisticRegression}.  The first model we use will be our ``Unchanged Logistic Classifier\", which will use our Titanic data with \\li{pclass} unchanged.  The second model is the ``Changed Logistic Classifier\", which use the data with \\li{pclass} changed.\n\nWhen using this package to create a classifier, we need to input a keyword argument \\li{C}.  This value represents the inverse of the regularization strength.  Different values will yield different results.  A better value for \\li{C} will yield a more steeply-rising roc curve.  The model can find the coefficients (the vector $\\bf{c}$), along with the probabilities of failure and success for each label.  With these in hand, we can use the function \\li{sklearn.metrics.roc_curve} to obtain the False Positive Rates, the True Positive Rates, and the optimal value for $\\tau$.  You will need to pass in the test data, the probability of success, and the keyword argument \\li{pos_label} $= 1$.  The accuracy of the model with input value \\li{C} can then be obtained using \\li{sklearn.metrics.auc}, which will give the area under the curve.  The larger the area, the more steeply-rising curve we have, and the better the model.  Note that we create a single roc curve using one value for \\li{C} and multiple values for $\\tau$.\n\n\\begin{problem}\nUse the following function declaration to return the auc score for the two Logistic Regression models described.\n\\begin{lstlisting}\ndef auc_scores(unchanged_logreg, changed_logreg):\n    \"\"\"\n    Parameters\n    ----------\n    unchanged_logreg : float in (0,1)\n        The value to use for C in the unchanged model\n    changed_logreg : float in (0,1)\n        The value to use for C in the changed model\n\n    Returns\n    -------\n    unchanged_auc : float\n        The auc for the unchanged model\n    changed_auc : float\n        The auc for the changed model\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nWe can test a Naive Bayes model against our Logistic Regression model for both the unchanged and changed models to see the comparative accuracy.  Use the model \\li{MultinomialNB}, found in \\li{sklearn.naive_bayes}.  You can use it in the same manner as \\li{LogisticRegression}, except instead of passing in the keyword argument \\li{C}, you will pass in a keyword argument \\li{alpha} corresponding to a smoothing parameter.\n\\begin{problem}\nAdd input variables \\li{unchanged_bayes} and \\li{changed_bayes} to your function from the previous problem to obtain the auc for each of these models.  Your function should return all four areas, unchanged logistic regression, changed logistic regression, unchanged Bayes, and changed Bayes, in that order.\n\\end{problem}\n\nDifferent values for \\li{C} and \\li{alpha} will yield different results.  We seek to find those that will maximize the area under the curve.  One way to do so is to pick a number of evenly-spaced points between $0$ and $1$, exclusive, and try each one in turn, keeping the value that yields the greatest accuracy.\n\\begin{problem}\nUse the function declaration below to find the optimal values for \\li{C} and $alpha$ as described.\n\\begin{lstlisting}\ndef find_best_parameters(choices):\n    \"\"\"\n    Parameters\n    ----------\n    choices : int\n        The number of values to try for C and alpha\n\n    Returns\n    -------\n    best : list of length 4\n        The best values for C for the unchanged and changed logistic\n         regression models, and the best values for alpha for the\n         unchanged and changed Naive Bayes models, respectively.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nNow that we have found the optimal inputs for these functions, we can test them against one another.\n\\begin{problem}\nCreate a function called \\li{results} which will graph of the roc curves for each of the methods, and will print out the names of the models with their corresponding areas, in numerically descending order.\n\\end{problem}\n", "meta": {"hexsha": "c8be9f95fe9a6db5a72524d815920da8be0becfd", "size": 14147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MachineLearning/LogisticRegression/LogisticRegression.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": "MachineLearning/LogisticRegression/LogisticRegression.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": "MachineLearning/LogisticRegression/LogisticRegression.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": 90.6858974359, "max_line_length": 1027, "alphanum_fraction": 0.7479324238, "num_tokens": 3463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145404, "lm_q2_score": 0.8152324871074607, "lm_q1q2_score": 0.656777529312559}}
{"text": "\\documentclass[12pt, a4paper]{report}\n\n\\usepackage{amsfonts}\n\\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}\n\\usepackage{titlesec}\n\\usepackage{hyperref}\n\\hypersetup{\n\tcolorlinks,\n\tcitecolor=Fuchsia,\n\tfilecolor=black,\n\tlinkcolor=Sepia,\n\turlcolor=blue\n}\n\n\\titleformat{\\chapter}{\\normalfont\\huge\\bfseries}{\\thechapter.}{10pt}{\\huge\\bfseries}\n\n\n% Title Page\n\\title{Fourier-Motzkin extension to Multivariate Polynomial Integer Constraints}\n\n\\author{Diogo Sampaio}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{tabular}[c]{|c|c|p{0.5\\linewidth}|}\n\t\\hline\n\t2017 - 12 - 07 & Diogo Sampaio & First version\\\\\n\t\\hline\n\\end{tabular}\n\n\\tableofcontents\n\n\\chapter{Introduction}\nQuantifier elimination is the process of removing existential variables of a given first-order formula, obtaining one that is simpler in the number of variables, and that implies the original formula.\n\nA very well known algorithm is the Fourier-Motzkin elimination process, that given a system (or formula) of inequalities removes one quantified variable by combining all of it's upper and lower bounds.\n\nFor example, let the system:\n$$\\exists x ~ | ~ 0 < y \\land z < 1 \\land y < x \\land x < z$$\nIn such formula, $x$ is a existential quantified variable, and $y, z$ are parameters. Using FME to remove variable $x$ from this formula requires to find it's upper and lower bounds. In this case we have the upper bound $$x < z$$ and the lower bound $$y < x.$$ For last $x$ is eliminated by isolating $x$ of each formula and combining lower with upper bounds such as:\n$$y < x < z \\Rightarrow y < z$$\ngenerating the new system:\n$$0 < y \\land z < 1 \\land y < z.$$\n\nThis algorithm is designed for linear systems, where all coefficients of the variable being eliminated are numeric values, and the inequality can be classified as either a upper or lower bound.\n\nWhen dealing with polynomials, variable coefficients might be symbolic expressions. In such case, all possible signs of the coefficient (positive, negative, or zero) must be explored.\ne.g. imagine the system:\n$$\\exists x ~ | ~ a - 1 > 0 \\land -b > 0 \\land ax > 0 \\land bx > 0$$\nwhen eliminating the variable $x$ it is required to classify the terms $ax > 0$ and $bx > 0$ as either upper or lower bounds of $x$. Not knowing the sign of the coefficients ($a, b$) requires to evaluate nine different combinations:\n$$a > 0 \\land b > 0$$\n$$a > 0 \\land b = 0$${\\color{red}$$a > 0 \\land b < 0$$}$$a = 0 \\land b > 0$$\n$$a = 0 \\land b = 0$$\n$$a = 0 \\land b < 0$$\n$$a < 0 \\land b > 0$$\n$$a < 0 \\land b = 0$$\n$$a < 0 \\land b < 0$$\nTo avoid this branching we use an implementation of a theorem used in the positiveness test algorithm, proposed by Markus Schweighofer (\\url{https://doi.org/10.1016/S0022-4049(01)00041-X}), to retrieve symbolic coefficient signs. Using such algorithm it is possible to infer that only the red assumption holds correct.\n\nThe same positiveness test algorithm is of major importance when resolving system over integer variables, instead of reals. It is used in many other techniques required to preserve the precision of the simplified formula, such as extending the normalization (\\url{https://doi.org/10.1145/125826.125848}) ~ technique to symbolic expressions, perform convex hull detection and remove redundant constraints.\n\nOur C++ implementation uses GiNaC (\\url{https://www.ginac.de/}) to manipulate symbolic expressions and GLPK to implement the positiveness test (\\url{https://www.gnu.org/software/glpk}).\n\n\nFor further details please refer to \\emph{Profile Guided Hybrid Compilation} \\S2.7 and \\S5. (\\url{https://hal.archives-ouvertes.fr/tel-01428425})\n\n\\chapter{Access to it}\n\\section{Code access and description}\nThe code is publicly available for download at:\n\n\\url{https://gitlab.inria.fr/nunessam/pghc.git}\n\nSource-code folders contents:\n\\begin{itemize}\n\t\\item doc: this document.\n\t\\item FM: the FME and a stand-alone positiveness tester.\n\t\\item converters: distinct converters to generate input to other quantifier-elimination tools, such as\n\t\\begin{itemize}\n\t\\item QEPCAD: \\url{https://github.com/PetterS/qepcad}\n\t\\item reduce/redlog: \\url{https://sourceforge.net/projects/reduce-algebra/}\n\t\\end{itemize}\n\tas well as input to barvinok \\url{http://barvinok.gforge.inria.fr/} where it tries to discover if it is possible to prove if a system of constraints define a empty / absurd space. For such task it computes maximum and minimum values of polynomials inside a convex polyhedron space (see \\url{https://icps.u-strasbg.fr/upload/icps-2006-173.pdf}).\n\t\\item packages: Dockerfile for a painless process of install.\n\\end{itemize}\n\\section{Compiling requirements}\n\\begin{itemize}\n\t\\item C++11 compatible compiler\n\t\\item GNU make, GiNaC, GLPK\n\\end{itemize}\n{\\color{red}OBS: These tools where tested solely in \\textbf{Linux}.}\n\n\\chapter{How to use}\n\\section{Fourier-Motzkin elimination - Text IO}\n\\subsection{Inputs}\nThe application can either read a input text file or it can read from the standard input stream. Example files can be seen with extension \\texttt{.in} inside the folder FM. The binary file it self is called {\\color{red}\\textbf{\\texttt{Simplifier}}}.\n\\subsection{Input format}\nThe input formula must be given in a disjunction of systems, where each system is a conjunction of terms. In a bottom up manner we have that:\n\\begin{itemize}\n\t\\item A \\emph{term} is a INTEGER VALUED equality or inequality, such as:\t\\begin{verbatim}4*x^2 - 5*y < 0\nx > 0\ny <= s\nN*h - 5*z == 0\n\t\\end{verbatim}\n\t\\item A system of terms declares all quantified variables, parameter such as the example in the file \\texttt{FM/POL.in}:\n\t\\begin{verbatim}[n]->[jj,j,k,kk,ii,i]: -kk^2+j+j^2-kk-2*ii+2*i = 0 &\n\t\tk >= 0 & -1-k+n >= 0 &\n\t\ti >= 0 & -1+k-i >= 0 &\n\t\t-1+j-k >= 0 & -1-j+n >= 0 &\n\t\tkk >= 0 & -1-kk+n >= 0 &\n\t\tii >= 0 & -1+kk-ii >= 0 &\n\t\t-1+jj-kk >= 0 & -1-jj+n >= 0 &\n\t\t-1-k+kk >= 0 & -1-ii+i >= 0 &\n\t\tn >= 0;\n\t\t\\end{verbatim}\n\t\tThe distinct parts of the system are:\n\t\t\\begin{itemize}\n\t\t\\item A system starts with a list, comma separated, of parameters, e.g.: \\texttt{[n]}, \\texttt{[nn,n, z, b]}, \\texttt{[]}.\n\t\t\\item An arrow \\texttt{->} describing \"mapping from\".\n\t\t\\item A list of the quantified variables to be eliminated, comma separated e.g.: \\texttt{[jj,j,k,kk,ii,i]}, \\texttt{[a, bc,c]}, \\texttt{[]}.\n\t\t\\item A list of polynomial terms, initialized by a colon(\\texttt{:}) and separated by the logic and symbol (\\texttt{\\&}) and terminated by a semi-colon (\\texttt{;}).\n\t\\end{itemize}\n\n\t\\item Multiple systems can be represented in a single input file, being interpreted as an \\texttt{logic or} of each one of the systems:\n\t\\begin{verbatim}\n\t[]->[x]: x < 1 & x > 0;\n\t[x]->[a]: a < x & a > 3*x-4;\n\t\\end{verbatim}\n\tis interpreted as $\\{\\exists x \\in \\mathbb{Z} | x < 1 \\land x > 0\\} \\lor \\{\\exists a \\in \\mathbb{Z} | a < x \\land 3x-4 < a\\}$.\n\\end{itemize}\n\n\\section{Fourier-Motzlin elimination - Python Interface}\n\nIn the folder\n\n\\section{Schweighofer Tester}\nIn the same FM folder, the binary file \\texttt{st} allows to interactively play with a single system of constraints. It can read from input files or iteratively add expressions to the system. It allows the user to:\n\\begin{itemize}\n\t\\item ~[A]ppend or [D]elete a constraint.\n\t\\item ~[T]est if an expression is implied by the system.\n\t\\item ~Obtain the [R]oot expressions of the system.\n\t\\item ~[S]how the generated expression of the Schweighofer Tester.\n\t\\item ~Show the Schweighofer Tester [m]onomials generated.\n\t\\item ~[C]hange the degree (number of multiplications) the Schweighofer Tester multiply all system constraints against all others.\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "2a119d057bd4ae1eb8d7a7c70433f74a59f361c4", "size": 7579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doc.tex", "max_stars_repo_name": "dnsampaio/PFME", "max_stars_repo_head_hexsha": "7136612ffa643bfff795adce774f28cc3a5184be", "max_stars_repo_licenses": ["MIT"], "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": "dnsampaio/PFME", "max_issues_repo_head_hexsha": "7136612ffa643bfff795adce774f28cc3a5184be", "max_issues_repo_licenses": ["MIT"], "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": "dnsampaio/PFME", "max_forks_repo_head_hexsha": "7136612ffa643bfff795adce774f28cc3a5184be", "max_forks_repo_licenses": ["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.8657718121, "max_line_length": 404, "alphanum_fraction": 0.7233144214, "num_tokens": 2257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6567394063594105}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Simple linear regression}\\label{sec:regression}\n\nLet $X$ and $Y$ be continuous random variables. We wish to investigate how $X$ influences the behaviour of $Y$.\n\\bit\n\\it $X$ is called the \\emph{explanatory variable} or the \\emph{independent variable}.\n\\it $Y$ is called the \\emph{response variable} or the \\emph{dependent variable}.\n\\eit\n\nSuppose we observe that $X$ takes the value $x$. Unless $Y$ is completely determined by $X$, we cannot predict its value with certainty so instead we focus on the problem of estimating its conditional expectation $E(Y|X=x)$. This leads us to represent $Y$ as the sum of two random variables:\n\\[\nY = \\mu(X) + \\epsilon  \\qquad\\text{where $\\epsilon\\sim N(0,\\sigma^2)$.}\n\\]\n\\bit\n\\it $\\mu(x) = \\expe(Y|X=x)$ is called the \\emph{regression function};\n\\it $\\epsilon = Y - \\expe(Y|X)$ is called the \\emph{error variable}.\n\\eit\n \n%% lemma\n%%By the law of total expectation, the expected value of the error variable is zero.\n%\\begin{lemma}\n%The expected value of the error variable is zero.\n%%$\\expe(\\epsilon) = 0$.\n%\\end{lemma}\n%\\begin{proof}\n%By the law of total expectation, \n%\\[\n%\\expe(\\epsilon) = \\expe\\big[Y - \\expe(Y|X)\\big] = \\expe(Y) - \\expe\\big[\\expe(Y|X)\\big] = \\expe(Y)-\\expe(Y) = 0.\n%\\]\n%\\end{proof}\n\n%% lemma\n%%The law of total variance divides the variance of $Y$ into a component attributed to the explanatory variable $X$, and a component attributed to the error variable $\\epsilon$.\n%The following lemma shows that the variance of $Y$ can be divided into a component attributed to the explanatory variable $X$, and a component attributed to the error variable $\\epsilon$.\n%\\begin{lemma}\n%%$\\var(Y) = \\var(\\mu) + \\expe\\big[\\var(\\epsilon|X)\\big]$.\n%If the error variable $\\epsilon$ is independent of the explanatory variable $X$,\n%\\[\\var(Y) = \\var(\\mu) + \\var(\\epsilon).\n%\\]\n%\\end{lemma}\n%\\begin{proof}\n%$\\epsilon = Y - \\expe(Y|X)$, so (by the definition of conditional variance),\n%\\[\n%\\var(Y|X) = \\expe\\big(\\big[Y-\\expe(Y|X)\\big]^2|X\\big) = \\expe(\\epsilon^2|X) = \\var(\\epsilon|X) = \\var(\\epsilon).\n%\\]\n%By the law of total variance,\n%\\begin{align*}\n%\\var(Y) \n%\t& = \\var\\big[\\expe(Y|X)\\big] + \\expe\\big[\\var(Y|X)\\big] \\\\\n%\t& = \\var\\big[\\mu(X)\\big] + \\expe\\big[\\var(\\epsilon)\\big]\n%\t& = \\var\\big[\\mu(X)\\big] + \\var(\\epsilon).\n%\\end{align*}\n%\\end{proof}\n%\n%\\begin{remark}\n%\\bit\n%\\it $\\var(\\mu) = \\var\\big[\\expe(Y|X)\\big]$ is the \\emph{explained} variance.\n%%\\it $\\expe\\big[\\var(\\epsilon|X)\\big] = \\expe\\big[\\var(Y|X)\\big]$ is the \\emph{unexplained} variance.\n%\\it $\\var(\\epsilon) = \\var(Y|X)$ is the \\emph{unexplained} variance.\n%\\eit\n%\\end{remark}\n\n% lemma\n%The law of total variance divides the variance of $Y$ into a component attributed to the explanatory variable $X$, and a component attributed to the error variable $\\epsilon$.\n%The following lemma shows that the variance of $Y$ can be divided into a component attributed to the explanatory variable $X$, and a component attributed to the error variable $\\epsilon$.\n\\begin{lemma}\\label{lem:partition-of-variance}\n%$\\var(Y) = \\var(\\mu) + \\expe\\big[\\var(\\epsilon|X)\\big]$.\n$\n\\var(Y) = \\var\\big[\\mu(X)\\big] + \\var(\\epsilon).\n$\n\\end{lemma}\n\\begin{proof}\n$\\epsilon = Y - \\expe(Y|X)$, so by the definition of conditional variance,\n\\[\n\\var(Y|X) = \\expe\\big(\\big[Y-\\expe(Y|X)\\big]^2|X\\big) = \\expe(\\epsilon^2|X) = \\var(\\epsilon|X) = \\var(\\epsilon).\n\\]\nBy the law of total variance,\n\\begin{align*}\n\\var(Y) \n\t& = \\var\\big[\\expe(Y|X)\\big] + \\expe\\big[\\var(Y|X)\\big] \\\\\n\t& = \\var\\big[\\mu(X)\\big] + \\expe\\big[\\var(\\epsilon)\\big] \\\\\n\t& = \\var\\big[\\mu(X)\\big] + \\var(\\epsilon).\n\\end{align*}\n\\end{proof}\nLemma~\\ref{lem:partition-of-variance} expresses the variance of $Y$ as the sum of an \\emph{explained variance}, attributed to the variance of the explanatory variable $X$, and an \\emph{unexplained variance} attributed to the error variable $\\epsilon$.\n%\\begin{remark}\n%\\bit\n%\\it $\\var\\big[\\mu(X)\\big] = \\var\\big[\\expe(Y|X)\\big]$ is the \\emph{explained} variance.\n%\\it $\\var(\\epsilon) = \\var(Y|X)$ is the \\emph{unexplained} variance.\n%\\eit\n%\\end{remark}\n\n%-----------------------------\n\\subsection{Linear models}\n\n\\begin{definition}\nA \\emph{linear model} is a model which is linear in its parameters.\n\\bit\n\\it $\\mu(x) = \\alpha + \\beta x + \\gamma x^2$ is a linear model.\n\\it $\\mu(x) = \\alpha e^{\\beta x}$ is not a linear model.\n\\eit\nA \\emph{simple linear model} is a linear model of the form $\\mu(x) = \\alpha + \\beta x$.\n\\end{definition}\n\nThe simple linear regression model is\n\\[\nY = \\alpha + \\beta X + \\epsilon \\quad\\text{where}\\quad \\epsilon\\sim N(0,\\sigma^2).\n\\]\nGiven that $X=x$, we have that $Y\\sim N(\\alpha+\\beta x, \\sigma^2)$ and in particular,\n\\[\n\\expe(Y|X=x) = \\alpha + \\beta x\n\\quad\\text{and}\\quad\n\\var(Y|X=x) = \\sigma^2.\n\\]\n\n%-----------------------------\n\\subsection{Test statistics}\n\nLet $(X_1,Y_1),(X_2,Y_2),\\ldots,(X_n,Y_n)$ be a random sample from the joint distribution of $X$ and $Y$. \nIn Week~\\ref{chap:likelihood} we saw that the maximum likelihood estimators of $\\alpha$, $\\beta$ and $\\sigma^2$ are respectively\n\\[\n\\hat{\\alpha} = \\bar{Y}-\\hat{\\beta}\\bar{X},\\qquad\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2}\n\\qquad\\text{and}\\qquad\n\\hat{\\sigma}^2 = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \n\\]\nwhere $\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} X_i)$ is the so-called \\emph{residual variable} at $X_i$.\n\n\n%%-----------------------------\n%\\subsection{Residual variance}\n%\n%\\begin{definition}\n%%Let $(x_1,x_2,\\ldots,x_n)$ be a realisation of the marginal sample $(X_1,X_2,\\ldots,X_n)$.\n%%Given $X=x$,\n%\n%\\ben\n%\\it $\\hat{y} = \\hat{\\alpha} + \\hat{\\beta}X$ is called the \\emph{predicted value of $Y$} at $X$.\n%\\it $\\hat{\\epsilon} = Y - \\hat{y}$ is called the \\emph{residual variable} at $X$.\n%\\een\n%\\end{definition}\n\n%% theorem: mle of alpha and beta\n%\\begin{theorem}\n%The maximum likelihood estimator of the error variance $\\sigma^2$ is the sample mean of the squared residuals,\n%\\[\n%\\hat{\\sigma}^2 = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \n%\\text{\\quad where\\quad} \n%\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} X_i).\n%\\]\n%\\end{theorem}\n%\n%% proof\n%\\begin{proof}\n%Recall the log-likelihood function:\n%\\[\n%\\ell(\\alpha,\\beta,\\sigma^2)\n%\t= \\frac{n}{2}\\log(2\\pi\\sigma^2) + \\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n%\\]\n%The first partial derivative of $\\ell(\\alpha,\\beta,\\sigma^2)$ with respect to $\\sigma^2$ is\n%\\[\n%\\frac{\\partial\\ell}{\\partial(\\sigma^2)} \n%\t= \\frac{n}{2\\sigma^2} - \\frac{1}{2(\\sigma^2)^2}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n%\\]\n%Setting this equal to zero,\n%\\[\n%\\sigma^2 = \\frac{1}{n}\\sum_{i=1}^n \\big[y_i-(\\alpha+\\beta x_i)\\big]^2.\n%\\]\n%Substituting our estimates for $\\alpha$ and $\\beta$, we obtain the MLE\n%\\[\n%\\hat{\\sigma^2} = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \\text{\\quad where\\quad} \\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i)\n%\\]\n%as required.\n%\n%\\end{proof}\n%\n%\\begin{remark}[Residual Analysis]\n%Our model assumes that $\\epsilon\\sim N(0,\\sigma^2)$ and that $\\epsilon$ is independent of $X$. To test whether these assumptions hold, we plot the points $(x_i,\\hat{\\epsilon}_i)$ on a scatter diagram. If the assumptions do indeed hold, the points should be evenly spread about the horizontal axis, and the extent of their spread should not depend on the $x$-coordinate. \n%This is an example of \\emph{residual analysis}. \n%\\end{remark}\n%\n%% exercise\n%\\begin{exercise}\n%Following a class test, 10 students were asked about the number of hours they had revised for the test. The data is shown in the table below.\n%\\begin{center}\n%\\begin{tabular}{|l|cccccccccc|} \\hline\n%Hours studied ($x$)\t&  4\t &  9 & 10 & 14 &  4 &  7 & 12 & 22 &  1 & 17 \\\\ \n%Test score ($y$)\t\t& 31 & 58 & 65 & 73 & 37 & 44 & 60 & 91 & 21 & 84 \\\\ \\hline\n%\\end{tabular}\n%\\end{center}\n%Perform a simple linear regression to estimate the relationship between the number of hours studied and the score achieved in the test.\n%\\begin{answer}\n%%It is easy to show that \n%%\\begin{align*}\n%%\\sum_{i=1}^n (x_i - \\bar{x})(y_i - \\bar{y})\t\n%%\t\t& = \\sum_{i=1}^n x_iy_i - \\frac{1}{n}\\left(\\sum_{i=1}^n x_i\\right)\\left(\\sum_{i=1}^n y_i\\right) \\text{ and} \\\\\n%%\\sum_{i=1}^n (x_i - \\bar{x})^2\t\t\t\t\n%%\t\t& = \\sum_{i=1}^n x_i^2 - \\frac{1}{n}\\left(\\sum_{i=1}^n x_i\\right)^2.\n%%\\end{align*}\n%%\n%%From the table,\n%%\\bit\n%%\\it $n=10$,\n%%\\it $\\sum_i x_i = 100$ and $\\sum_i y_i = 564$,\n%%\\it $\\sum_i x_i^2 = 1376$ and $\\sum_i x_iy_i = 6945$.\n%%\\eit\n%%This yields\n%Tedious calculations yield\n%\\[\n%\\sum_{i=1}^n(x_i-\\bar{x})^2  = 376 \\text{\\quad and\\quad} \\sum_{i=1}^n (x_i - \\bar{x})(y_i - \\bar{y}) = 1305.\n%\\]\n%Thus\n%\\begin{align*}\n%\\hat{\\beta}\t\n%\t& = \\displaystyle\\frac{\\sum_{i=1}^n (x_i - \\bar{x})(y_i - \\bar{y})}{\\sum_{i=1}^n(x_i-\\bar{x})^2} \n%\t= \\displaystyle\\frac{1305}{376}\t= 3.47,\\\\\t\n%\\intertext{and}\n%\\hat{\\alpha}\n%\t& = \\displaystyle\\bar{y} - \\hat{\\beta}\\bar{x} \n%\t= \\displaystyle\\frac{564}{10} - \\left(\\frac{1305}{376}\\right)\\left(\\frac{100}{10}\\right) = 21.69.\n%\\end{align*}\n%The estimated relationship is therefore $\\hat{y} = 21.69 + 3.471 x$.\n%\\end{answer}\n%\\end{exercise}\n\n%-----------------------------\n%\\subsection{}\n\\bigskip\nLet $x_1,x_2,\\ldots,x_n$ be a fixed realisation of the marginal sample $X_1,X_2,\\ldots,X_n$. Then $\\hat{\\alpha}$, $\\hat{\\beta}$ and $\\hat{\\epsilon}_i$ are all linear combinations of $Y_1,Y_2,\\ldots,Y_n$. Because the $Y_i$ are independent normal variables it thus follows that $\\hat{\\alpha}$, $\\hat{\\beta}$ and $\\hat{\\epsilon}_i$ are also normal variables.\n\n\\begin{theorem}\nThe MLEs of $\\alpha$, $\\beta$ and $\\sigma^2$ respectively satisfy\n\\[\n\\hat{\\alpha} \\sim N\\left(\\alpha,\\frac{\\sigma^2}{n}\\right),\n\\quad\n\\hat{\\beta} \\sim N\\left(\\beta,\\frac{\\sigma^2}{\\sum_{i=1}^n(x_i-\\bar{x})^2}\\right)\n\\quad\\text{and}\\quad\n\\frac{n\\hat{\\sigma}}{\\sigma} \\sim \\chi^2_{n-2}.\n\\]\n%respectively.\n\\end{theorem}\n\n\\begin{proof}\n\\ben\n\\it % alpha\nThe expected value of $\\hat{\\alpha}$ is \n\\begin{align*}\n\\expe(\\hat{\\alpha})\n\t= \\expe(\\bar{Y}-\\beta\\bar{x})\n\t& = \\expe\\left(\\frac{1}{n}\\sum_{i=1}^n Y_i - \\frac{\\beta}{n}\\sum_{i=1}^n x_i\\right) \\\\\n\t& = \\frac{1}{n}\\sum_{i=1}^n \\expe(Y_i) - \\frac{\\beta}{n}\\sum_{i=1}^n x_i \\\\\n\t& = \\frac{1}{n}\\sum_{i=1}^n (\\alpha+\\beta x_i) - \\frac{\\beta}{n}\\sum_{i=1}^n x_i \\\\\n\t& = \\alpha.\n\\end{align*}\nBecause $\\var(Y_i)=\\sigma^2$, the variance of $\\hat{\\alpha}$ is \n\\begin{align*}\n\\var(\\hat{\\alpha})\n\t& = \\var\\left(\\frac{1}{n}\\sum_{i=1}^n Y_i - \\frac{\\beta}{n}\\sum_{i=1}^n x_i\\right) \\\\\n\t& = \\frac{1}{n^2}\\sum_{i=1}^n \\var(Y_i)\n\t= \\frac{\\sigma^2}{n}.\n\\end{align*}\nHence $\\hat{\\alpha} \\sim N(\\alpha,\\sigma^2/n)$, as required.\n\\it % beta\nSince $\\expe(Y_i) = \\alpha + \\beta x_i$ and $\\expe(\\bar{Y}) = \\alpha + \\beta\\bar{x}$, the expected value of $\\hat{\\beta}$ is therefore\n\\begin{align*}\n\\expe(\\hat{\\beta})\n\t& = \\expe\\left[\\frac{\\sum_{i=1}^n (x_i-\\bar{x})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (x_i-\\bar{x})^2}\\right] \\\\\n\t& = \\frac{\\sum_{i=1}^n (x_i-\\bar{x})\\expe(Y_i-\\bar{Y})}{\\sum_{i=1}^n (x_i-\\bar{x})^2} \n`\t= \\frac{\\sum_{i=1}^n \\beta(x_i-\\bar{x})^2}{\\sum_{i=1}^n (x_i-\\bar{x})^2} = \\beta.\n\\end{align*}\nUsing the fact that $\\sum_{i=1}^n x_i = n\\bar{x}$, it is easy to see that $\\hat{\\beta}$ can be rewritten as\n\\[\n\\hat{\\beta} = \\frac{\\sum_{i=1}^n (x_i-\\bar{x})Y_i}{\\sum_{i=1}^n (x_i-\\bar{x})^2}.\n\\]\nBecause $\\var(Y_i)=\\sigma^2$, the variance of $\\hat{\\beta}$ is\n\\begin{align*}\n\\var(\\hat{\\beta})\n\t= \\var\\left[\\frac{\\sum_{i=1}^n (x_i-\\bar{x})Y_i}{\\sum_{i=1}^n (x_i-\\bar{x})^2}\\right]\n\t& = \\frac{1}{\\left[\\sum_{i=1}^n(x_i-\\bar{x})^2\\right]^2}\\sum_{i=1}^n(x_i-\\bar{x})^2\\var(Y_i) \\\\\n\t& = \\frac{\\sigma^2}{\\sum_{i=1}^n(x_i-\\bar{x})^2}.\n\\end{align*}\nHence $\\hat{\\beta}\\sim N\\left(\\beta,\\frac{\\sigma^2}{\\sum_{i=1}^n(x_i-\\bar{x})^2}\\right)$, as required.\n\\it % sigma^2\nRecall that\n\\[\n\\hat{\\sigma}^2 = \\frac{1}{n}\\sum_{i=1}^n \\hat{\\epsilon_i}^2\n\\quad\\text{where}\\quad\n\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i).\n\\]\nConsider\n\\begin{align*}\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n\\big[Y_i-(\\alpha+\\beta x_i)\\big]^2 \n\t& = \\frac{1}{\\sigma^2}\\sum_{i=1}^n\\big[(\\hat{\\alpha}-\\alpha) + (\\hat{\\beta}-\\beta)x_i + (Y_i-(\\hat{\\alpha}+\\hat{\\beta}x_i))\\big]^2 \\\\\n\t& = \\frac{n(\\hat{\\alpha}-\\alpha)^2}{\\sigma^2} + \\frac{(\\hat{\\beta}-\\beta)^2}{\\sigma^2}\\sum_{i=1}^n x_i^2 + \\frac{n\\hat{\\sigma}^2}{\\sigma^2}.\n\\end{align*}\nThe first three terms in this expression all have chi-squared distribution.\n\\bit\n\\it\nBecause $Y_i\\sim N(\\alpha+\\beta x_i,\\sigma^2)$ it follows that $\\big[Y_i-(\\alpha+\\beta x_i)\\big]/\\sigma\\sim N(0,1)$, so\n\\[\n\\displaystyle\\frac{1}{\\sigma^2}\\sum_{i=1}^n\\big[Y_i-(\\alpha+\\beta x_i)\\big]^2\\sim\\chi^2_{n}.\n\\]\n\\it\nBecause $\\hat{\\alpha}\\sim N(\\alpha,\\sigma^2/n)$ it follows that $\\sqrt{n}(\\hat{\\alpha}-\\alpha)/\\sigma\\sim N(0,1)$, so\n\\[\n\\displaystyle\\frac{n(\\hat{\\alpha}-\\alpha)^2}{\\sigma^2} \\sim \\chi^2_1.\n\\]\n\\it \nBecause $\\hat{\\beta}\\sim N\\left(\\beta,\\sigma^2/\\sum_{i=1}^n(x_i-\\bar{x})^2\\right)$ it follows that $(\\hat{\\beta}-\\beta)\\sqrt{\\sum_{i=1}^n x_i^2}/\\sigma \\sim N(0,1)$, so\n\\[\n\\frac{(\\hat{\\beta}-\\beta)^2}{\\sigma^2}\\sum_{i=1}^n x_i^2 \\sim \\chi^2_1.\n\\]\n\\eit\nIt is easy to see that if $U\\sim\\chi^2_a$ and $V\\sim\\chi^2_b$ are independent, then $U+V\\sim\\chi^2_{a+b}$. It thus follows that $n\\hat{\\sigma}/\\sigma\\sim \\chi^2_{n-2}$ as required.\n\\een\n\\end{proof}\n\nWe estimate the error variance using the following unbiased estimator (instead of the MLE),\n\\[\n\\hat{\\sigma}^2 = \\frac{1}{n-2}\\sum_{i=1}^n \\hat{\\epsilon}_i^2 \n\\quad\\text{where}\\quad\n\\hat{\\epsilon}_i = Y_i-(\\hat{\\alpha}+\\hat{\\beta} x_i).\n\\]\nThis estimator for $\\sigma^2$ yields the following test statistics:\n\\[\nT_1 = \\frac{\\hat{\\alpha}-\\alpha}{\\sqrt{\\hat{\\sigma}^2/(n-2)}}\n\\quad\\text{and}\\quad\nT_2 = \\frac{\\hat{\\beta}-\\beta}{\\sqrt{n\\hat{\\sigma}^2/[(n-2)\\sum_{i=1}^n(x_i-\\bar{x})^2]}}.\n\\]\n\n\\bit\n\\it Under the null hypothesis $H_0:\\alpha=0$, \n\\[\nT_1 = \\frac{\\hat{\\alpha}-\\alpha}{\\sqrt{\\hat{\\sigma}^2/(n-2)}} \\sim t_{n-2}.\n\\]\n\\it Uhder the null hypothesis $H_0:\\beta=0$,\n\\[\nT_2 = \\frac{\\hat{\\beta}-\\beta}{\\sqrt{n\\hat{\\sigma}^2/[(n-2)\\sum_{i=1}^n(x_i-\\bar{x})^2]}} \\sim t_{n-2}.\n\\]\n\\eit\n\n$T_2$ can be used to test whether or not $Y$ depends (linearly) on $X$:\n\\begin{align*}\nH_0: \t&\\ Y = \\alpha+\\epsilon, \\\\\nH_1:\t&\\ Y = \\alpha+\\beta X + \\epsilon.\n\\end{align*}\n\n%-----------------------------\n\\subsection{ANOVA for regression}\n\n%For a fixed realisation $(x_1,x_2,\\ldots,x_n)$ of the marginal sample $(X_1,X_2,\\ldots,X_n)$, \nThe \\emph{predicted value} of $Y_i$ is the random variable\n\\[\n\\hat{Y}_i = \\hat{\\alpha} + \\hat{\\beta}X_i.\n\\]\nThe total deviation of $Y_i$ from the overall mean $\\bar{Y}$ can be divided into two components,\n\\[\nY_i - \\bar{Y} = (Y_i-\\hat{Y}_i) + (\\hat{Y}_i - \\bar{Y}),\n\\]\nfrom which it follows that\n\\[\n\\sum_{i=1}^n(Y_i - \\bar{Y})^2 = \\sum_{i=1}^n(Y_i-\\hat{Y}_i)^2 + \\sum_{i=1}^n(\\hat{Y}_i - \\bar{Y})^2.\n\\]\nAs with ANOVA, we define the following sums-of-squares.\n\\[\n\\begin{array}{lll}\nSST\t& = \\displaystyle\\sum_{i=1}^n (Y_i-\\bar{Y})^2\n\\qquad & \\text{The \\emph{total} sum-of-squares.} \\\\\nSSR\t& = \\displaystyle\\sum_{i=1}^n (\\hat{Y}_i-\\bar{Y})^2\n\\qquad & \\text{The \\emph{regression} sum-of-squares.} \\\\\nSSE\t& = \\displaystyle\\sum_{i=1}^n (Y_i-\\hat{Y}_i)^2\n\\qquad & \\text{The \\emph{error} sum-of-squares.} \n\\end{array}\n\\]\n\nThe total sum-of-squares $SST$ is determined by the marginal sample $(Y_1,Y_2,\\ldots,Y_n)$. Substituting for $\\hat{Y}_i = \\hat{\\alpha} + \\hat{\\beta}X_i$ we see that the regression sum-of-squares satisfies\n\\[\nSSR = \\frac{\\big[\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})\\big]^2}{\\sum_{i=1}^n (X_i-\\bar{X})^2}\n\\]\nThe error sum-of-squares is then obtained via $SSE = SST - SSR$.\n\n\\bigskip\nUnder $H_0:\\beta=0$,\n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n (\\hat{Y}_i-\\bar{Y})^2\t\\sim \\chi^2_1\n\\text{\\quad and\\quad}\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n (Y_i-\\hat{Y}_i)^2\t\t\\sim \\chi^2_{n-2}.\n\\]\nThus we have the test statistic\n\\[\nF \n\t= \\frac{SSR}{(n-2)^{-1}SSE} \n\t= \\frac{\\sum_{i=1}^n (\\hat{Y}_i-\\bar{Y})^2}{(n-2)^{-1}\\sum_{i=1}^n (Y_i-\\hat{Y}_i)^2} \n\t\\sim F_{1,n-2} \\quad\\text{under $H_0:\\beta=0$.}\n\\]\nwhich provides another means of testing whether or not $Y$ depends linearly on $X$.\n\n\n%-----------------------------\n\\subsection{The coefficient of determination}\n\nRecall that the \\emph{correlation coefficient} of any pair of random variables $X$ and $Y$ is\n\\[\n\\rho(X,Y) \n\t= \\frac{\\cov(X,Y)}{\\sqrt{\\var(X)\\var(Y)}}\n\t= \\frac{\\expe\\big[(X-\\expe X)(Y-\\expe Y)\\big]}\n\t\t\t{\\sqrt{\\expe\\big[(X-\\expe X)^2\\big]\\expe\\big[(Y-\\expe Y)^2\\big]}}\n\\]\n\nFor a bivariate random sample $(X_1,Y_1),(X_2,Y_2),\\ldots,(X_n,Y_n)$ the \\emph{sample correlation coefficient}, also known as the \\emph{Pearson correlation} is defined by\n\\[\nR = \\frac{\\sum_{i=1}^n(X_i-\\bar{X})(Y_i - \\bar{Y})}{\\sqrt{\\sum_{i=1}^n(X_i-\\bar{X})^2\\sum_{i=1}^n(Y_i-\\bar{Y})^2}} \n\\]\n\nFor the simple linear regression model $Y=\\alpha+\\beta X + \\epsilon$, the MLE of $\\beta$ can be written as,\n\\begin{align*}\n\\hat{\\beta}\n\t& = \\frac{\\sum_{i=1}^n (X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_{i=1}^n (X_i-\\bar{X})^2} \n\t= R\\sqrt{\\frac{\\sum_{i=1}^n(Y_i-\\bar{Y})^2}{\\sum_{i=1}^n(X_i-\\bar{X})^2}}.\n\\end{align*}\n\n%The square of the empirical correlation coefficient is called the \\emph{coefficient of determination}, denoted by $R^2$:\nThe \\emph{coefficient of determination} is the square of the sample correlation, and denoted by $R^2$:\n\\[\nR^2 \n\t= \\frac{\\big[\\sum_{i=1}^n(X_i-\\bar{X})(Y_i - \\bar{Y})\\big]^2}{\\sum_{i=1}^n(X_i-\\bar{X})^2\\sum_{i=1}^n(Y_i-\\bar{Y})^2}\n\t= \\frac{SSR}{SST}.\n%\t= 1 - \\frac{SSE}{SST}.\n\\]\n\nwhere $SSR$ and $SST$ are the regression sum-of-squares and total sum-of-squares respectively. \n\n\\bigskip\nThus $R^2$ is the proportion of the total variation explained by the regression model: it quantifies how well the regression line fits the data points, and as such is an example of a \\emph{goodness-of-fit} statistic (the value $R^2=1$ indicates that the regression line perfectly fits the data). The corresponding quantity for one-way ANOVA is the so-called \\emph{eta-squared} effect size:\n\\[\n\\eta^2 = \\frac{SSG}{SST}.\n\\]\n\n\\begin{example}\nThe table below shows the deaths due to bronchitis ($x$) and corresponding daily temperatures ($y$), averaged over a long period.\n\\begin{center}\n\\begin{tabular}{lcccccccccc}\\hline\n$x$ & 253 & 232 & 210 & 200 & 191 & 187 & 134 & 102 & 81 & 25 \\\\\n$y$ & 35 & 37 & 39 & 41 & 43 & 45 & 47 & 49 & 51 & 53 \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\ben\n\\it Use the simple linear model $y = \\alpha + \\beta x + \\epsilon$ to perform a least-squares regression of $y$ against $x$. \n\\it Test whether the slope of the regression line is significantly different from zero at the 5\\% significance level.\n\\een\n\\begin{solution}\nThe various quantities of interest are computed here:\n%\\bit\n%\\it $n = 10$.\n%\\it $\\sum x_{i} = 1615$.\n%\\it $\\sum x_{i}^{2}\t= 308929$.\n%\\it $\\sum (x_i-\\bar{x})^2\t= 308929 - (1615)^{2}/10 = 48106.5$.\n%\\it $\\sum y_{i} =  440$.\n%\\it $\\sum y_{i}^{2}  = 19690$.\n%\\it $\\sum (y_i-\\bar{y})^2 = 19690 - (440)^{2}/10 = 330$.\n%\\it $\\sum x_{i}y_{i}\t= 67209$.\n%\\it $\\sum (x_i-\\bar{x})(y_i-\\bar{y}) = 67209 - (1615){\\times}(440)/10 = -3851$.\n%\\eit\n\\bit\n\\it $n = 10$.\n\\it $\\bar{x} = 161.5$.\n\\it $\\bar{y} = 44$.\n\\it $\\sum (x_i-\\bar{x})^2\t= 48106.5$.\n\\it $\\sum (y_i-\\bar{y})^2 = 330$.\n\\it $\\sum (x_i-\\bar{x})(y_i-\\bar{y}) = -3851$.\n\\eit\n\nThe MLEs of the regression coefficients are\n\\begin{align*}\n\\hat{\\beta}\t\t&\\quad = \\frac{\\sum (x_i-\\bar{x})(y_i-\\bar{y})}{\\sum (x_i-\\bar{x})^2} = \\frac{-3851}{48106.5} = -0.080052 \\\\\n\\hat{\\alpha}\t&\\quad = \\bar{y}-\\hat{\\beta}\\bar{x} = 44 + 0.080052{\\times}161.5 = 56.928326\n\\end{align*}\n\nThe least squares regression line is \n\\[\ny = 56.928326 - 0.080052x.\n\\]\nTo test the null hypothesis $H_0:\\beta=0$, we compute the regression sum-of-squares:\n\\[\nSSR = \\frac{\\big[\\sum (x_i-\\bar{x})(y_i-\\bar{y})\\big]^{2}}{\\sum (x_i-\\bar{x})^2} \n\t=\\frac{(-3851)^{2}}{48106.5} \n\t= 308.2785\n\\]\nand the error sum-of-squares:\n\\[\nSSE\t= \\sum (y_i-\\bar{y})^2 - SSR = 330.0 - 308.2785 =  21.7215.\n\\]\nThe test statistic is\n\\[\nF = \\frac{SSR}{(n-2)^{-1}SSE} = \\frac{308.2785}{21.7215/8} = 113.54.\n\\]\n\nCritical values of the $F_{1,8}$-distribution are\n\\bit\n\\it $5.318$ at sig. level $0.05$\n\\it $7.570$ at sig. level $0.025$\n\\it $11.25$ at sig. level $0.001$\n\\it $14.68$ at sig. level $0.005$\n\\eit\nThus the null hypothesis $H_0:\\beta = 0$ is strongly rejected at the $5\\%$ significance level.\n\n\\bigskip\nHere we have $R^2 = SSR/SST = 308.2785/330 = 0.9342$, which shows that $Y$ depends on $X$ to a very large extent.\n\\end{solution}\n\\end{example}\n\n\n", "meta": {"hexsha": "275e1ac1b0dd527dff4eded6def49ed4962893a5", "size": 20383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/11D_regression.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/11D_regression.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/11D_regression.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.5786407767, "max_line_length": 389, "alphanum_fraction": 0.626944022, "num_tokens": 7998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.6567393943163994}}
{"text": "\\chapter{Localization}\nBefore we proceed on to defining an affine scheme,\nwe will take the time to properly cover one more algebraic construction\nthat of a \\emph{localization}.\nThis is mandatory because when we define a scheme,\nwe will find that all the sections and stalks\nare actually obtained using this construction.\n\nOne silly slogan might be:\n\\begin{moral}\n\tLocalization is the art of adding denominators.\n\\end{moral}\nYou may remember that when we were working with affine varieties,\nthere were constantly expressions of the form\n$\\left\\{ \\frac{f}{g} \\mid g(p) \\ne 0 \\right\\}$\nand the like.\nThe point is that we introduced a lot of denominators.\nLocalization will give us a concise way of doing this in general.\n\n\\emph{Notational note}:\nmoving forward we'll prefer to denote rings by $A$, $B$, \\dots,\nrather than $R$, $S$, \\dots.\n\n\\section{Spoilers}\nHere is a preview of things to come,\nso that you know what you are expecting.\nSome things here won't make sense,\nbut that's okay, it is just foreshadowing.\n\nLet $V \\subseteq \\Aff^n$, and for brevity let $R = \\CC[V]$ be its coordinate ring.\nWe saw in previous sections how to compute $\\OO_V(D(g))$\nand $\\OO_{V, p}$ for $p \\in V$ a point.\nFor example, if we take $\\Aff^1$ and consider a point $p$, then\n$\\OO_{\\Aff^1}(D(x-p)) = \\left\\{ \\frac{f(x)}{(x-p)^n} \\right\\}$\nand $\\OO_{\\Aff^1, p} = \\left\\{ \\frac{f(x)}{g(x)} \\mid g(p) \\ne 0 \\right\\}$.\nMore generally, we had\n\\begin{align*}\n\t\\OO_{V}(D(g)) &= \\left\\{ \\frac{f}{g^n} \\mid f \\in R \\right\\}\n\t\t\\quad\\text{by \\Cref{thm:reg_func_distinguish_open}} \\\\\n\t\\OO_{V,p} &= \\left\\{ \\frac{f}{g} \\mid f,g \\in R, g(p) \\ne 0 \\right\\}\n\t\t\\quad\\text{by \\Cref{thm:stalks_affine_var}}.\n\\end{align*}\n\nWe will soon define something called a localization,\nwhich will give us a nice way of expressing the above:\nif $R = \\CC[V]$ is the coordinate ring, then\nthe above will become abbreviated to just\n\\begin{align*}\n\t\\OO_{V}(D(g)) &= R_{g} \\\\\n\t\\OO_{V, p} &= R_{\\km} \\quad \\text{where } \\{p\\} = \\VV(\\km).\n\\end{align*}\nThe former will be pronounced \n``$R$ localized away from $g$''\nwhile the latter will be pronounced\n``$R$ localized at $\\km$''.\n\nEven more generally,\nnext chapter we will throw out the coordinate ring $R$\naltogether and replace it with a general commutative ring $A$\n(which are still viewed as functions).\nWe will construct a ringed space called $X = \\Spec A$,\nwhose elements are \\emph{prime ideals} of $A$\nand is equipped with the Zariski topology and a sheaf $\\OO_X$.\nIt will turn out that, in analogy to what we had before,\n\\begin{align*}\n\t\\OO_X(D(f)) &= A[f\\inv] \\\\\n\t\\OO_{X,\\kp} &= A_\\kp\n\\end{align*}\nfor any element $f \\in A$ and prime ideal $\\kp \\in \\Spec A$.\nThus just as with complex affine varieties,\nlocalizations will give us a way to more or less\ndescribe the sheaf $\\OO_X$ completely.\n\n\\section{The definition}\n\\begin{definition}\n\tA subset $S \\subseteq A$ is a \\vocab{multiplicative set}\n\tif $1 \\in S$ and $S$ is closed under multiplication.\n\\end{definition}\n\\begin{definition}\n\tLet $A$ be a ring and $S \\subset A$ a multiplicative set.\n\tThen the \\vocab{localization of $A$ at $S$}, denoted $S\\inv A$,\n\tis defined as the set of fractions\n\t\\[ \\left\\{ a/s \\mid a \\in A, s \\in S \\right\\} \\]\n\twhere we declare two fractions $a_1 / s_1 = a_2 / s_2$\n\tto be equal if $s(a_1s_2 - a_2s_1) = 0$ for some $s \\in S$.\n\tAddition and multiplication in this ring\n\tare defined in the obvious way.\n\\end{definition}\nIn particular, if $0 \\in S$ then $S\\inv A$ is the zero ring.\nSo we usually only take situations where $0 \\notin S$.\n\nWe give in brief now two examples which will be\nmotivating forces for the construction of the affine scheme.\n\\begin{example}\n\t[Localizations of {$\\CC[x]$}]\n\tLet $A = \\CC[x]$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Suppose we let $S = \\left\\{ 1, x, x^2, x^3, \\dots \\right\\}$\n\t\tbe the powers of $x$.\n\t\tThen\n\t\t\\[ S\\inv A = \\left\\{ \\frac{f(x)}{x^n}\n\t\t\t\\mid f \\in \\CC[x], n \\in \\ZZ_{\\ge 0} \\right\\}.  \\]\n\t\tIn other words, we get the Laurent polynomials in $x$.\n\n\t\tYou might recognize this as\n\t\t\\[ \\OO_V(U) \\text{ where } V = \\Aff^1, \\; U = V \\setminus \\{0\\}. \\]\n\t\ti.e.\\ the sections of the punctured line.\n\t\tIn line with the ``hyperbola effect'',\n\t\tthis is also expressible as $\\CC[x,y] / (xy-1)$.\n\n\t\t\\ii Let $p \\in \\CC$.\n\t\tSuppose we let $S = \\left\\{ g(x) \\mid g(p) \\ne 0 \\right\\}$,\n\t\ti.e.\\ we allow any denominators where $g(p) \\ne 0$.\n\t\tThen\n\t\t\\[ S\\inv A = \\left\\{ \\frac{f(x)}{g(x)}\n\t\t\t\\mid f,g \\in \\CC[x], g(p) \\ne 0 \\right\\}.  \\]\n\t\tYou might recognize this is as the stalk $\\OO_{\\Aff^1, p}$.\n\t\tThis will be important later on.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\t[Why the extra $s$?]\n\tWe cannot use the simpler $a_1s_2 - a_2s_1 = 0$ since\n\totherwise the equivalence relation may fail to be transitive.\n\tHere is a counterexample: take\n\t\\[ A = \\Zc{12} \\qquad S = \\{ 2, 4, 8 \\}. \\]\n\tThen we have for example $\\frac12 = \\frac24 = \\frac64 = \\frac32$.\n\tSo we need to have $\\frac12=\\frac32$ which is only true\n\twith the first definition.\n\tOf course, if $A$ is an integral domain (and $0\\notin S$)\n\tthen this is a moot point.\n\\end{remark}\n\n\\begin{example}\n\t[Field of fractions]\n\tLet $A$ be an integral domain and $S = A \\setminus \\{0\\}$.\n\tThen $S\\inv A = \\Frac(A)$.\n\\end{example}\n\n\n\\section{Localization away from an element}\n\\prototype{$\\ZZ$ localized away from $6$ has fractions $\\frac{m}{2^x 3^y}$.}\nWe now focus on the two special cases of localization we will need the most;\none in this section, the other in the next section.\n\\begin{definition}\n\tFor $f \\in A$, we define the \\vocab{localization of $A$ away from $f$},\n\tdenoted $A[1/f]$ or $A[f\\inv]$,\n\tto be $\\{1, f, f^2, f^3, \\dots\\}\\inv A$.\n\t(Note that $\\left\\{ 1, f, f^2, \\dots \\right\\}$ is multiplicative.)\n\\end{definition}\n\\begin{remark}\n\tIn the literature it is more common to\n\tsee the notation $A_f$ instead of $A[1/f]$.\n\tThis is confusing, because in the next section\n\twe define $A_\\kp$ which is almost the opposite.\n\tSo I prefer this more suggestive (but longer) notation.\n\\end{remark}\n\n\\begin{example}\n\t[Some arithmetic examples of localizations]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii We localize $\\ZZ$ away from $6$:\n\t\t\\[ \\ZZ[1/6] = \\left\\{ \\frac{m}{6^n} \\mid m \\in \\ZZ,\n\t\t\tn \\in \\ZZ_{\\ge 0} \\right\\}.  \\]\n\t\tSo $A[1/6]$ consist of those rational numbers whose\n\t\tdenominators have only powers of $2$ and $3$.\n\t\tFor example, it contains $\\frac{5}{12} = \\frac{15}{36}$.\n\n\t\t\\ii Here is a more confusing example:\n\t\tif we localize $\\Zc{60}$ away from the element $5$,\n\t\twe get $(\\Zc{60})[1/5] \\cong \\Zc{12}$.\n\t\tYou should try to think about why this is the case.\n\t\tWe will see a ``geometric'' reason later.\n\t\\end{enumerate}\n\\end{example}\n\n\n\\begin{example}\n\t[Localization at an element, algebraic geometry flavored]\n\tWe saw that if $A$ is the coordinate ring of a variety,\n\tthen $A[1/g]$ is interpreted geometrically as $\\OO_V(D(g))$.\n\tHere are some special cases:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii As we saw, if $A = \\CC[x]$,\n\t\tthen $A[1/x] = \\left\\{ \\frac{f(x)}{x^n} \\right\\}$\n\t\tconsists of Laurent polynomials.\n\n\t\t\\ii Let $A = \\CC[x,y,z]$.\n\t\tThen \\[ A[1/x] = \\left\\{ \\frac{f(x,y,z)}{x^n} \\mid\n\t\t\tf \\in \\CC[x,y,z], \\; n \\ge 0 \\right\\} \\]\n\t\tis rational functions whose denominators are powers of $x$.\n\n\t\t\\ii Let $A = \\CC[x,y]$.\n\t\tIf we localize away from $y-x^2$ we get\n\t\t\\[ A[(y-x^2)\\inv] = \\left\\{ \\frac{f(x,y)}{(y-x^2)^n} \\mid\n\t\t\tf \\in \\CC[x,y], \\; n \\ge 0 \\right\\} \\]\n\t\tBy now you should recognize this as $\\OO_{\\Aff^2}(D(y-x^2))$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[An example with zero-divisors]\n\tLet $A = \\CC[x,y] / (xy)$\n\t(which intuitively is the coordinate ring of two axes).\n\tSuppose we localize at $x$:\n\tequivalently, allowing denominators of $x$.\n\tSince $xy = 0$ in $A$, we now have $0 = x\\inv (xy) = y$,\n\tso $y = 0$ in $A$, and thus $y$ just goes away completely.\n\tFrom this we get a ring isomorphism\n\t\\[ A[1/x] \\cong \\CC[x,1/x].\\] \n\\end{example}\n\n\\section{Localization at a prime ideal}\n\\prototype{$\\ZZ$ localized at $(5)$ has fractions $\\frac{m}{n}$ with $5 \\nmid n$.}\n\\label{sec:localize_prime_ideal}\n\n\\begin{definition}\n\tIf $A$ is a ring and $\\kp$ is a prime ideal, then we define\n\t\\[ A_\\kp \\defeq \\left( A \\setminus \\kp \\right)^{-1} A. \\]\n\tThis is called the \\vocab{localization at $\\kp$}.\n\\end{definition}\n\\begin{ques}\n\tWhy is $S = A \\setminus \\kp$ multiplicative\n\tin the above definition?\n\\end{ques}\n\n%Warning: this notation sort of conflicts with the previous one.\n%The ring $A_\\kp$ is the localization with multiplicative set $A \\setminus \\kp$,\n%while $A_f$ is the localization with multiplicative set $\\{1,f,f^2,\\dots\\}$;\n%these two are quite different beasts!\n%In $A_\\kp$ the subscript denotes the \\emph{forbidden} denominators;\n%in $A_f$ the subscript denotes the \\emph{allowed} denominators.\n\nThis special case is important because we will see that\nstalks of schemes will all be of this shape.\nIn fact, the same was true for affine varieties too.\n\\begin{example}\n\t[Relation to affine varieties]\n\tLet $V \\subseteq \\Aff^n$, let $A = \\CC[V]$\n\tand let $p = (a_1, \\dots, a_n)$ be a point.\n\tConsider the maximal (hence prime) ideal\n\t\\[ \\km = (x_1 - a_1, \\dots, x_n - a_n). \\]\n\tObserve that a function $f \\in A$ vanishes at $p$\n\tif and only if $f \\pmod{\\km} = 0$, equivalently $f \\in \\km$.\n\tThus, by \\Cref{thm:stalks_affine_var} we can write\n\t\\begin{align*}\n\t\t\\OO_{V,p} &= \\left\\{ \\frac{f}{g} \\mid f,g \\in A, g(p) \\ne 0 \\right\\} \\\\\n\t\t&= \\left\\{ \\frac{f}{g} \\mid f \\in A, g \\in A \\setminus \\km \\right\\} \\\\\n\t\t&= \\left( A \\setminus \\km \\right)\\inv A = A_\\km.\n\t\\end{align*}\n\tSo, we can also express $\\OO_{V,p}$ concisely as a localization.\n\\end{example}\nConsequently, we give several examples in this vein.\n\n\\begin{example}\n\t[Geometric examples of localizing at a prime]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii We let $\\km$ be the maximal ideal $(x)$ of $A = \\CC[x]$.\n\t\tThen \\[ A_\\km = \\left\\{ \\frac{f(x)}{g(x)} \\mid g(0) \\ne 0 \\right\\} \\]\n\t\tconsists of the Laurent polynomials.\n\n\t\t\\ii We let $\\km$ be the maximal ideal $(x,y)$ of $A = \\CC[x,y]$.\n\t\tThen \\[ A_\\km = \\left\\{ \\frac{f(x,y)}{g(x,y)} \\mid g(0,0) \\ne 0 \\right\\}. \\]\n\n\t\t\\ii Let $\\kp$ be the prime ideal $(y-x^2)$ of $A = \\CC[x,y]$.\n\t\tThen\n\t\t\\[ A_\\kp = \\left\\{ \\frac{f(x,y)}{g(x,y)} \\mid g \\notin (y-x^2) \\right\\}. \\]\n\t\tThis is a bit different from what we've seen before:\n\t\tthe polynomials in the denominator are allowed to vanish\n\t\tat a point like $(1,1)$, as long as they don't vanish on\n\t\t\\emph{every} point on the parabola.\n\t\tThis doesn't correspond to any stalk we're familiar with right now,\n\t\tbut it will later\n\t\t(it will be the ``stalk at the generic point of the parabola'').\n\n\t\t\\ii Let $A = \\CC[x]$ and localize at the prime ideal $(0)$.\n\t\tThis gives \\[ A_{(0)} = \\left\\{ \\frac{f(x)}{g(x)} \\mid g(x) \\ne 0 \\right\\}. \\]\n\t\tThis is all rational functions, period.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Arithmetic examples]\n\tWe localize $\\ZZ$ at a few different primes.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If we localize $\\ZZ$ at $(0)$:\n\t\t\\[ \\ZZ_{(0)} = \\left\\{ \\frac mn \\mid n \\ne 0 \\right\\}\n\t\t\t\\cong \\QQ. \\]\n\t\t\\ii If we localize $\\ZZ$ at $(3)$, we get\n\t\t\\[ \\ZZ_{(3)} = \\left\\{ \\frac mn \\mid \\gcd(n,3) = 1 \\right\\} \\]\n\t\twhich is the ring of rational numbers\n\t\twhose denominators are relatively prime to $3$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Field of fractions]\n\tIf $A$ is an integral domain,\n\tthe localization $A_{(0)}$\n\tis the field of fractions of $A$.\n\\end{example}\n\n\n\\section{Prime ideals of localizations}\n\\prototype{The examples with $A = \\ZZ$.}\nWe take the time now to mention how you can\nthink about prime ideals of localized rings.\n\\begin{proposition}\n\t[The prime ideals of $S\\inv A$]\n\tLet $A$ be a ring and $S \\subseteq A$ a multiplicative set.\n\tThen there is a natural inclusion-preserving bijection between:\n\t\\begin{itemize}\n\t\t\\ii The set of prime ideals of $S\\inv A$, and\n\t\t\\ii The set of prime ideals of $A$ not intersecting $S$.\n\t\\end{itemize}\n\\end{proposition}\n\\begin{proof}\n\tConsider the homomorphism $\\iota \\colon A \\to S\\inv A$.\n\tFor any prime ideal $\\kq \\subseteq S\\inv A$,\n\tits pre-image $\\psi\\pre(\\kq)$ is a prime ideal of $A$\n\t(by \\Cref{prob:prime_preimage}).\n\tConversely, for any prime ideal $\\kp \\subseteq A$\n\tnot meeting $S$,\n\t$S\\inv \\kp = \\left\\{ \\frac{a}{s} \\mid a \\in \\kp, s \\in S \\right\\}$\n\tis a prime ideal of $S\\inv A$.\n\tAn annoying check shows that this produces the required bijection.\n\\end{proof}\nIn practice, we will almost always use the corollary\nwhere $S$ is one of the two special cases we discussed at length:\n\\begin{corollary}\n\t[Spectrums of localizations]\n\tLet $A$ be a ring.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $\\kp$ is a prime ideal of $A$,\n\t\tthen the prime ideals of $A[1/f]$ are naturally\n\t\tin bijection with prime ideals of $A$\n\t\t\\textbf{do not contain the element} $f$.\n\n\t\t\\ii If $\\kp$ is a prime ideal of $A$,\n\t\tthen the prime ideals of $A_\\kp$ are naturally\n\t\tin bijection with prime ideals of $A$\n\t\twhich are \\textbf{subsets of} $\\kp$.\n\t\\end{enumerate}\n\\end{corollary}\n\\begin{proof}\n\tPart (b) is immediate; a prime ideal doesn't meet $A \\setminus \\kp$\n\texactly if it is contained in $\\kp$.\n\tFor part (a), we want prime ideals of $A$ not containing\n\tany \\emph{power} of $f$.\n\tBut if the ideal is prime and contains $f^n$,\n\tthen it should contain either $f$ or $f^{n-1}$,\n\tand so at least for prime ideals these are equivalent.\n\\end{proof}\nNotice again how the notation is a bit of a nuisance.\nAnyways, here are some examples, to help cement the picture.\n\\begin{example}\n\t[Prime ideals of {$\\ZZ[1/6]$}]\n\tSuppose we localize $\\ZZ$ away from the element $6$,\n\ti.e.\\ consider $\\ZZ[1/6]$.\n\tAs we saw,\n\t\\[ \\ZZ[1/6] = \\left\\{ \\frac{n}{2^x 3^y} \\mid n \\in \\ZZ,\n\t\tx,y \\in \\ZZ_{\\ge 0} \\right\\}.  \\]\n\tconsist of those rational numbers whose\n\tdenominators have only powers of $2$ and $3$.\n\tNote that $(5) \\subset \\ZZ[1/6]$ is a prime ideal:\n\tthose elements of $\\ZZ[1/6]$ with $5$ dividing the numerator.\n\tSimilarly, $(7)$, $(11)$, $(13)$, \\dots\\\n\tand even $(0)$ give prime ideals of $\\ZZ[1/6]$.\n\n\tBut $(2)$ and $(3)$ no longer correspond to\n\tprime ideals; in fact in $A_6$ we have $(2) = (3) = (1)$,\n\tthe whole ring.\n\\end{example}\n\n\\begin{example}\n\t[Prime ideals of $A_{(5)}$]\n\tSuppose we localize $\\ZZ$ at the prime $(5)$.\n\tAs we saw,\n\t\\[ \\ZZ_{(5)} = \\left\\{ \\frac{m}{n} \\mid m,n \\in \\ZZ,\n\t\t\t5 \\nmid n \\right\\}.  \\]\n\tconsist of those rational numbers whose\n\tdenominators are not divisible by $5$.\n\tThis is an integral domain, so $(0)$ is still a prime ideal.\n\tThere is one other prime ideal: $(5)$,\n\ti.e.\\ those elements whose numerators are divisible by $5$.\n\n\tThere are no other prime ideals:\n\tif $p \\ne 5$ is a rational prime,\n\tthen $(p) = (1)$, the whole ring, again.\n\\end{example}\n\n\\section{Prime ideals of quotients}\nWhile we are here, we mention that\nthe prime ideals of quotients $A/I$\ncan be interpreted in terms of those of $A$\n(as in the previous section for localization).\nYou may remember this from \\Cref{prob:inclusion_preserving}\na long time ago, if you did that problem;\nbut for our purposes we actually only care about the prime ideals.\n\\begin{proposition}\n\t[The prime ideals of $A/I$]\n\t\\label{prop:prime_quotient}\n\tIf $A$ is a ring and $I$ is any ideal (not necessarily prime)\n\tthen the prime (resp.\\ maximal) ideals of $A/I$\n\tare in bijection with prime (resp.\\ maximal) ideals of $A$\n\twhich are \\textbf{supersets of} $I$.\n\tThis bijection is inclusion-preserving.\n\\end{proposition}\n\\begin{proof}\n\tConsider the quotient homomorphism $\\psi \\colon A \\surjto A/I$.\n\tFor any prime ideal $\\kq \\subseteq A/I$,\n\tits pre-image $\\iota\\pre(\\kq)$ is a prime ideal\n\t(by \\Cref{prob:prime_preimage}).\n\tConversely, for any prime ideal $\\kp$\n\twith $I \\subseteq \\kp \\subseteq A$,\n\twe get a prime ideal of $A/I$ by looking at $\\kp \\pmod I$.\n\tAn annoying check shows that this produces the required bijection.\n\tIt is also inclusion-preserving --- from which\n\tthe same statement holds for maximal ideals.\n\\end{proof}\n\\begin{example}\n\t[Prime ideals of $\\Zc{60}$]\n\tThe ring $\\Zc{60}$ has three prime ideals:\n\t\\begin{align*}\n\t\t(2) &= \\left\\{ 0, 2, 4, \\dots, 58 \\right\\} \\\\\n\t\t(3) &= \\left\\{ 0, 3, 6, \\dots, 57 \\right\\} \\\\\n\t\t(5) &= \\left\\{ 0, 5, 10, \\dots, 55 \\right\\}.\n\t\\end{align*}\n\tBack in $\\ZZ$, these correspond to the three prime ideals\n\twhich are supersets of\n\t$60\\ZZ = \\left\\{ \\dots, -60, 0, 60, 120, \\dots \\right\\}$.\n\\end{example}\n\n\\section{Localization commute with quotients}\n\\prototype{$(\\CC[xy]/(xy))[1/x] \\cong \\CC[x,x\\inv]$.}\nWhile we are here, we mention a useful result from\ncommutative algebra which lets us compute localizations in quotient rings,\nwhich are surprisingly unintuitive.\nYou will \\emph{not} have a reason to care about this\nuntil we reach \\Cref{sec:localize_prime_ideal},\nand so this is only placed earlier to emphasize that it's\na purely algebraic fact that we can (and do) state this early,\neven though we will not need it anytime soon.\n\nLet's say we have a quotient ring like\n\\[ A/I = \\CC[x,y] / (xy) \\]\nand want to compute the localization of this ring\naway from the element $x$.\n(To be pedantic, we are actually localizing away from $x \\pmod{xy}$,\nthe element of the quotient ring, but we will just call it $x$.)\nYou will quickly find that even the notation becomes clumsy: it is\n\\begin{equation}\n\t\\left( \\CC[x,y] / (xy) \\right)[1/x]\n\t\\label{eq:quotient_localization_before}\n\\end{equation}\nwhich is hard to think about,\nbecause the elements in play are part of the \\emph{quotient}:\nhow are we supposed to think about\n\\[ \\frac{1 \\pmod{xy}}{x \\pmod{xy}} \\]\nfor example?\nThe zero-divisors in play may already make you feel uneasy.\n\nHowever, it turns out that we can actually do the localization\n\\emph{first}, meaning the answer is just\n\\begin{equation}\n\t\\CC[x,y,1/x] / (xy)\n\t\\label{eq:quotient_localization_after}\n\\end{equation}\nwhich then becomes $\\CC[x, x\\inv, y] / (y) \\cong \\CC[x,x\\inv]$.\n\nThis might look like it should be trivial,\nbut it's not as obvious as you might expect.\nThere is a sleight of hand present here with the notation:\n\\begin{itemize}\n\t\\ii In \\eqref{eq:quotient_localization_before},\n\tthe notation $(xy)$ stands for an ideal of $\\CC[x,y]$\n\t--- that is, the set $xy \\CC[x,y]$.\n\n\t\\ii In \\eqref{eq:quotient_localization_after}\n\tthe notation $(xy)$ now stands for an ideal of $\\CC[x,x\\inv,y]$\n\t--- that is, the set $xy \\CC[x,x\\inv,y]$.\n\\end{itemize}\nSo even writing down the \\emph{statement} of the theorem\nis actually going to look terrible.\n\nIn general, what we want to say is that if we have our ring $A$\nwith ideal $I$ and $S$ is some multiplicative subset of $A$,\nthen \\[ \\text{Colloquially: ``}S\\inv (A/I) = (S\\inv A)/I\\text{''}. \\]\nBut there are two things wrong with this:\n\\begin{itemize}\n\\ii The main one is that $I$ is not an ideal of $S\\inv A$, as we saw above.\nThis is remedied by instead using $S\\inv I$,\nwhich consists of those elements of those elements $\\frac xs$\nfor $x \\in I$ and $s \\in S$.\nAs we saw this distinction is usually masked in practice,\nbecause we will usually write $I = (a_1, \\dots, a_n) \\subseteq A$\nin which case the new ideal $S\\inv I \\subseteq A$ can be denoted\nin exactly the same way: $(a_1, \\dots, a_n)$,\njust regarded as a subset of $S\\inv A$ now.\n\n\\ii The second is that $S$ is not, strictly speaking,\na subset of $A/I$, either.\nBut this is easily remedied by instead using the image of $S$\nunder the quotient map $A \\surjto A/I$.\n\nWe actually already saw this in the previous example:\nwhen trying to localize $\\CC[x,y]/(xy)$,\nwe were really localizing at the element $x \\pmod{xy}$,\nbut (as always) we just denoted it by $x$ anyways.\n\\end{itemize}\n\nAnd so after all those words, words, words, we have the hideous:\n\\begin{theorem}\n\t[Localization commutes with quotients]\n\t\\label{thm:localization_commute_quotient}\n\tLet $S$ be a multiplicative set of a ring $A$,\n\tand $I$ an ideal of $A$.\n\tLet $\\ol S$ be the image of $S$\n\tunder the projection map $A \\surjto A/I$.\n\tThen\n\t\\[ {\\ol S}\\inv (A/I) \\cong S\\inv A / S\\inv I \\]\n\twhere $S\\inv I = \\left\\{ \\frac{x}{s} \\mid x \\in I, s \\in S \\right\\}$.\n\\end{theorem}\n\\begin{proof}\n\tDo you actually care? No? Cool, I didn't either.\n\t(Atiyah-Macdonald is the right reference for these\n\ttype of things in the event that you do care.)\n\\end{proof}\nThe notation is a hot mess.\nBut when we do calculations in practice, we instead write\n\\[ \\left( \\CC[x,y,z]/(x^2 + y^2 - z^2) \\right)[1/x]\n\t\\cong \\CC[x,y,z,1/x] / (x^2 + y^2 - z^2) \\]\nor (for an example where we localize at a prime ideal)\n\\[ \\left( \\ZZ[x,y,z]/ (x^2 + yz) \\right)_{(x,y)}\n\t\\cong \\ZZ[x,y,z]_{(x,y)} / (x^2 + yz) \\]\nand so on --- the pragmatism of our ``real-life'' notation\nwhich hides some details actually guides our intuition\n(rather than misleading us).\nSo maybe the moral of this section is that whenever\nyou compute the localization of the quotient ring,\nif you just suspend belief for a bit,\nthen you will probably get the right answer.\n\nWe will later see geometric interpretations of these facts\nwhen we work with $\\Spec A/I$,\nat which point they will become more natural.\n\n\\section{\\problemhead}\n\\begin{problem}\n\tLet $A = \\Zc{2016}$, and consider the element $60 \\in A$.\n\tCompute $A[1/60]$, the localization of $A$ away from $60$.\n\t\\begin{sol}\n\t\tOne should get $A[1/60] = \\Zc{7}$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Injectivity of localizations]\n\tLet $A$ be a ring and $S \\subseteq A$ a multiplicative set.\n\tFind necessary and sufficient conditions\n\tfor the map $A \\to S\\inv A$ to be injective.\n\t\\begin{hint}\n\t\tConsider zero divisors.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIf and only if $S$ has no zero divisors.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{sproblem}\n\t[Alluding to local rings]\n\tLet $A$ be a ring, and $\\kp$ a prime ideal.\n\tHow many maximal ideals does $A_\\kp$ have?\n\t\\begin{hint}\n\t\tOnly one!\n\t\tA proof will be given a few chapters later.\n\t\\end{hint}\n\\end{sproblem}\n\n\n\\begin{problem}\n\tLet $A$ be a ring such that $A_\\kp$ is an integral domain\n\tfor every prime ideal $\\kp$ of $A$.\n\tMust $A$ be an integral domain?\n\t\\begin{hint}\n\t\tNo. Imagine two axes.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tTake $A = \\CC[x,y] / (xy)$.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "c01ed94de585e820e59328ea4caf4a8c14f11d08", "size": 21957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-geom/localization.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-geom/localization.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-geom/localization.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.9025210084, "max_line_length": 82, "alphanum_fraction": 0.6739080931, "num_tokens": 7362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.6567393929795253}}
{"text": "{\\bfseries\\slshape\\sffamily\\color{ChapterTitleColor} \\chapter{Array Support}} \\label{chap:arrys}\n\n\\section{Introduction}\n\nIn most programming languages, the word array usually refers to a data structure that stores identically sized elements in a sequential and continuous block of memory. Lists on the other hand are used to stored non-identically sized elements that might be located anywhere in memory. Arrays are therefore referred to as homogenous collections whereas lists are heterogeneous collections. The advantage of arrays is that they can be used to process information very efficiently. Arrays are often used to store numerical data which require efficient numerical processing. The simplest array is a one dimensional collection of numbers, such as:\n\n\\begin{lstlisting}\n[1.3, 5.6, 7.8, 4.5, 2.3, 1.2]\n\\end{lstlisting}\n\nThis array has six elements. Since the data in an array is guaranteed to be laid out sequentially in memory, accessing individual elements can be efficiently done by using indexing to the appropriate element. Object Pascal has a variety of ways for declaring arrays. For example an array with a fixed number of elements (a static array) can be declared using:\n\n\\begin{lstlisting}\nTMyArray = array[1..100] of double;\n\\end{lstlisting}\n\nIt is also possible to declare so-called dynamic arrays which are allocated a size at runtime, and makes them more flexible:\n\n\\begin{lstlisting}\nvar\n   myArray : array of double;\n\nsetLength (myArray, 100);\n\\end{lstlisting}\n\nArrays need not be only one-dimensional but in principle can be any dimension. A common array structure used in mathematics is the two-dimensional matrix:\n\n$$\n\\setlength{\\delimitershortfall}{0pt}\n\\begin{bmatrix}\n3.4 & 6.7 &  8.9\\\\\n1.2 & 4.5 & 3.1 \\\\\n5.6 & 7.7 & 2.5\n\\end{bmatrix}\n$$\n\nSuch matrices have very widespread applications in science, engineering, statistics and machine learning. Matrices can easily represented using 2D arrays.\n\n\\subsection*{Rhodus Array Syntax}\n\nWe've already encountered the basic syntax used with arrays. Rhodus follows to some degree the model used by Python. In particular we repurpose the list syntax to define literal arrays and use a global method, {\\tt array} to convert lists into the array data model. For example:\n\n\\begin{lstlisting}\n>> a = array([[1,2],[3,4]])\n>> println (a)\n[ 1, 4;\n  9, 16]\n>> type (a)\narray\n\\end{lstlisting}\n\nThe {\\tt array} method also can be used to specify the size of a new array, for example:\n\n\\begin{lstlisting}\n>> a = array(3,4)\n>> b = array(5,5,5)\n\\end{lstlisting}\n\nThe first array, {\\tt a} is a 3 by 4 array while the second array, {\\tt b}, is a three-dimensional array of size 5 in each dimension. By default all elements in a new array are initialized to zero.\nFor now arrays will only be able to contain floating point values.\n\nLike lists, arrays can be in indexed using the usual indexing syntax, for example:\n\n\\begin{lstlisting}\n>> a = array(5,5,5)\n>> a[1,1,2]\n0.0\n>> a[1,1,2] = 3.14\n>> a[1,1,2]\n3.14\n\\end{lstlisting}\n\nLike lists, indexing starts at zero.\n\nRhodus has two variants of arrays. The first is an n-dimensional array and the second, derived from arrays, is the 2-dimensional matrix. The two types only differ is what operations can be applied to them. These operations are governed by two built-in libraries, {\\tt arrays} and {\\tt mat}. Arithmetic operations on arrays are element-wise whereas the operations provided by the matrix library correspond to the classic matrix operations found in linear algebra. For example, multiplying two arrays together is done by multiplying each corresponding element to form a new array of products, for example:\n\n\\begin{lstlisting}\n>> import arrays\n>> a = array([[1,2],[3,4]])\n>> println (arrays.mult (a, a))\n[ 1, 4;\n  9, 16]\n\\end{lstlisting}\n\nIn contrast, multiplication using the {\\tt mat} library yields a different result:\n\n\\begin{lstlisting}\n>> import mat\n>> a = array([[1,2],[3,4]])\n>> println (mat.mult (a, a))\n[   7, 10;\n   15  22]\n\\end{lstlisting}\n\nWe will cover more of this topic shortly.\n\n\\section{Implementing Arrays}\n\nHow do we implement array support? In considering this question, the main point to keep in mind is that access to arrays are meant to be fast and operations on arrays should be as efficient as possible. This requirement will dictate how an array, and in particular a multidimensional arrays is stored. To keep thing simple, let's first consider arrays up to two dimensions. Since we don't know how big arrays will be we need to use dynamic arrays at the Object Pascal level. Secondly, our arrays will be objects that can be garbage collected, this means an array must be derived from the same parent as strings and lists. We begin with a simple array object class:\n\n\\begin{lstlisting}\nTArrayObject = class (TRhodusObject)\nend;\n\\end{lstlisting}\n\nThe parent {\\tt TRhodusObject} class includes a number of fields:\n\n\\begin{lstlisting}\n   blockType : TBlockType;\n   objectType : TSymbolElementType;\n   methodList : TMethodList;\n\\end{lstlisting}\n\nThe {\\tt blockType} is for the garbage collector to know what to do with the object during garbage collection. The {\\tt objectType} just tells us what kind of object it is, string, list, user function or array. Finally, the {\\tt methodlist} is a new field for version 3 of Rhodus and points to a list of methods that can be applied to the object. This is what lets us do things like:\n\n\\begin{lstlisting}\na = \"String\"\nl = a.len()\n\nprintln (\"How long am I\".len())\n\\end{lstlisting}\n\nThe first thing to add to the {\\tt TArrayObject} is the field that will hold the array data. For now, we will only support arrays that hold floating point numbers.\n\n\\begin{lstlisting}\nT1DArray = array of double;\nTArrayObject = class (TRhodusObject)\n   data : T1DArray;\nend;\n\\end{lstlisting}\n\nYou may be thinking, ok this will store a 1D array, but what about a 2D array? The best way to handle n-dimensional arrays is to map then into a 1-dimensional array. If we didn't do this we'd have to have special cases for all the possible dimensions, e.g {\\tt T1DArray, T2DArray, T3DArray}, etc. I don't think we want to do that.\n\nFigure~\\ref{fig:rowMajor} shows how we can map a one-dimensional array to an dimensions. All we do is slice the 1D-array into segments represents the rows, in this case a 2D-array. We can slice at many times as we like to model n-dimensional arrays.\n\n\\begin{figure}[htpb]\n\\centering\n\\includegraphics[scale=0.55]{rowMajor.pdf}\n\\caption{Using a 1D-array to represent a 2D-array.}\n\\label{fig:rowMajor}\n\\end{figure}\n\nWith a bit of simple arithmetic we can convert any 2D-index, such as $(i, j)$, into a single index along the 1D-array. To do this we must know the intended column width of the 2D-array. In the example the column width is 4. By convention, in a 2D index such as $(i, j)$, the $i$ represents the row number and $j$ the column number. Let's say we had a coordinate of $(2,3)$, that represents the second row and third column. One thing we have to be careful of is what is the index of the first element in the array? As with lists, we will always index from zero. this means that the coordinate $(2,3)$ actually means the 3rd row and 4th column. Given a coordinate $(i,j)$, the index along the 1D-array that corresponds to this coordinate will be:\n%\n$$ \\mbox{index} = j + (i \\times \\mbox{width}) $$\n%\nIf we plug $(2,3)$ into this formula we get: $3 + 2 \\cdot 4 = 11$. Hence we would pull the value out of index 11 in the 1D-array. If you look at Figure~\\ref{fig:rowMajor} you can confirm this by eye. We can rewrite the above formula is a more general way:\n%\n$$ \\mbox{index} = i \\cdot d_j + j $$\n%\nwhere $d_j$ is the width or dimension (number of elements) in the $j$th direction. This approach can be extended to any number of dimensions. For example, for a 3D array, with coordinate, $i, j, k$, the formula for computing the index in a linear array can be extended to give:\n%\n$$ \\mbox{index} = i \\cdot d_j \\cdot d_k + j \\cdot d_k + k $$\n%\nwhere $d_j$ is the dimension of the $j$th coordinate, and $d_k$ the dimension of the $k$th coordinate. By induction the formula for a 4D array with correlates $i, j, k, l$, would be:\n%\n$$ \\mbox{index} = i \\cdot d_j \\cdot d_k \\cdot d_l + j \\cdot d_k \\cdot d_l + k \\cdot d_l + l $$\n%\nThis can be turned into a function for computing the index of any array with any dimension as follows\\footnote{Modified from Heffernan's answer in \\url{https://stackoverflow.com/questions/28569850/}}:\n%\n\n\\begin{lstlisting}\n// Given the dimension of the array in the array dimensions\n// and the coordinates in the array index, this routine\n// will return the index assuming the array is stored\n// in a 1D block of memory.\nfunction getIndex (const dimensions, index: array of Integer): integer;\nvar i: Integer;\nbegin\n  result := idx[0];\n  for i := 1 to high(dimensions) do\n    result := result*dimensions[i] + index[i];\nend;\n\\end{lstlisting}\n\nFor example, if we have a 6 dimensional array of dimensions $5,5,5,5,5,5$, which is 15,625 elements, the index at coordinate $1,2,3,3,0,4$ will be position 4829 in the 1D storage array.\n\nWe can create two helper methods for getting and setting a value in an n-dimensional array. The methods will take a dynamic array containing the indices to use.\n\n\\begin{lstlisting}\nfunction TArrayObject.getValue (idx : array of integer) : double;\nvar index : integer;\nbegin\n  for var i := 0 to length (dim) - 1 do\n      if idx[i] >= dim[i] then\n         raise ERuntimeException.Create(outOfRangeMsg);\n\n  index := getIndex (dim, idx);\n  result := data[index];\nend;\n\\end{lstlisting}\n\nFor example in the {\\tt getValue} method we can use the new open array syntax introduced in XE7.\n\n\\begin{lstlisting}\n  value := getValue ([1,3,2])\n\\end{lstlisting}\n\nLikewise we have a {\\tt setValue} method that also takes an dynamic array argument for specifying the indices.\n\n\\begin{lstlisting}\nprocedure TArrayObject.setValue (idx : array of integer; value : double);\nvar index : integer;\n    i : integer;\nbegin\n  for i := 0 to length (dim) - 1 do\n      if idx[i] >= dim[i] then\n         raise ERuntimeException.Create(outOfRangeMsg);\n\n  index := getIndex (dim, idx);\n  data[index] := value;\nend;\n\\end{lstlisting}\n\nFor example:\n\n\\begin{lstlisting}\n  setValue ([6,2,7], value)\n\\end{lstlisting}\n\nIn both methods we need to check for index out of bounds errors. The bounds will be stored in a object variable called dim. We can expand the {\\tt TArrayObject} to:\n\n\\begin{lstlisting}\n  TArrayObject = class (TRhodusObject)\n    private\n    public\n     data : T1DArray;\n     dim  : TIndexArray;  // Of type array of integer;\n\n     function     getValue (idx : array of integer) : double;\n     procedure    setValue (idx : array of integer; value : double);\n\n     function     clone : TArrayObject;\n\n     constructor  Create; overload;\n     constructor  Create (dim : TIndexArray); overload;\n     destructor   Destroy; override;\n\\end{lstlisting}\n\nWe'll add a bunch of extra methods. One in particular is the ability to clone an array. This is implemented in the clone method:\n\n\\begin{lstlisting}\nfunction TArrayObject.clone : TArrayObject;\nbegin\n  result := TArrayObject.Create (dim);\n  result.data := copy (self.data);\nend;\n\\end{lstlisting}\n\nThere are also a bunch of other methods to make like easier, as well as some arithmetic functions such as {\\tt add}, {\\tt subtract}, and {\\tt multiply}. These are all pair-wise operations.\nThat is addition of two arrays is archived by summing up pair-wise values in each array.  For this work, both arrays must have the same dimensions. For a 2 by 2 array addition is defined as:\n\n$$\n\\begin{bmatrix}\n  a_1 & a_2 \\\\\n  a_3 & a_4\n\\end{bmatrix}\n+\n\\begin{bmatrix}\n  b_1 & b_2 \\\\\n  b_3 & b_4\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n  a_1+b_1 & a_2+b_2 \\\\\n  a_3 + b_3 & a_4 + b_4\n\\end{bmatrix}\n$$\n\nThis idea can be extended to n-dimensional arrays. Subtraction is defined in a similar way except we take the difference between each pair. When we come to multiplication we are confronted with two common multiplication approaches. This includes the simple pair-wise multiplication and, arguably, the more common matrix multiplication. For arrays we will provide pair-wise multiplication. This will be specified using the usual multiply operator {\\tt `*'}.\n\nFor 2D-arrays, i.e matrices, we need a way to specify matrix multiplication. Python uses {\\tt `@'}, so we might as well use that too. We'll have to update the lexical scanner, syntax analysis and AST constructions but that is simple to do. For example, let's compare pair-wise and matrix multiplication:\n\n\\begin{lstlisting}\n>> a = array([[1,2],[3,4]])\n>> println (a*a)\n[[   1.0000,     4.0000]],\n[    9.0000,    16.0000]]\n>> println (a@a)\n[[   7.0000,    10.0000]],\n[   15.0000,    22.0000]]\n\\end{lstlisting}\n\nMultiply arrays\n\n[[0]*4]*3\n[[0,0,0,0],[0,0,0,0],[0,0,0,0]]\n\nor\n\n\\begin{lstlisting}\n>>println (a.sqr())\n\\end{lstlisting}\n\nThis squares each element in the array {\\tt a}. $n$-dimensional arrays can be created using the {\\tt array} method:\n\n\nThere are at least two classes of operations we can apply to arrays, these include manipulating the contents of an array, for example extracting rows and columns, or adding rows and columns, and secondly carrying out arithmetic on arrays. Let's first focus on arithmetic operations.\n\n\\section{Matrices}\n\nThere isn't much to say about matrices other than they are strictly 2-dimensional arrays. There is nothing intrinsically different between an array and a matrix other than its dimensions. The key difference is that matrix operations are different from the equivalent array operations. This is particularly the case for multiplication which is dot-product based for matrices. This is handled by the {\\tt mat} library which also offers other classical matrix operations such as computing the inverse and determinant.\n\nAll operations on arrays can also be applied to matrices, but not vice versa, since matrices are strictly 2-dimensional.\n\nAs mention in the last section, matrix multiplication comes in two forms, pair-wise and dot product. Pair-wise multiplication can be easily extended to arrays of any dimension. In Rhodus there are two ways to specify pair-wise multiplication, using the normal multiplication operator, {\\tt *}:\n\n\\begin{lstlisting}\n>> a = array([[1,2],[3,4]])\n>> b = array([[5,6],[7,8]])\n>> x = a*b\n>>println (x)\n[[   5.0000,    12.0000]],\n[   21.0000,    32.0000]]\n\\end{lstlisting}\n\nMatrix multiplication, as defined in linear algebra, is the generated by taking the dot-product of corresponding rows and columns.  Unlike array multiplication, where the two arrays must be the same size, in matrix multiplication this need not be the case. Moreover, matrix multiplication generally applies to 2-dimensional matrices. When applying matrix multiplication, the number of columns of the first matrix must equal the number of rows in the second matrix. The outer rows and columns can be of any size. In Rhodus there are two ways to specify matrix multiplication, either using the {\\tt mult} method from the matrix library or using he special matrix multiplication operator symbol {\\tt @}|. For example:\n\n\\begin{lstlisting}\n>> a = array([[1,2],[3,4]])\n>> b = array([[5,6],[7,8]])\n>> x = a@b\n>> x = mat.mult (a, b)\n>>println (x)\n[[  19.0000,    22.0000]],\n[   43.0000,    50.0000]]\n>>\n\\end{lstlisting}\n\nApplication\n\n[m1, m2]\n\ncombine (m1, m2)\n\n[m1; m2]\n\nmat.appendRow ([m1, m2])\nmat.appendCol ([m1, m2])\n\nm1.appendRow (m2)\nm1.appendCol (m2)\n\nm1.hstack (m2)\nm1.vstack (m2)\n\n%\n%\\section{Useful Reading}\n%\n%\\subsection{Introductory Books}\n%\n%{\\bf 1.} Ball, Thorsten. Writing A Compiler In Go. Thorsten Ball, 2018.\n%\n%{\\bf 2.} Kernighan, Brian W.; Pike, Rob (1984). The Unix Programming Environment. Prentice-Hall. ISBN 0-13-937681-X.\n%\n%{\\bf 3.} Nisan, Noam, and Shimon Schocken. The elements of computing systems: building a modern computer from first principles. MIT press, 2005.\n%\n%{\\bf 4.} Parr, Terence. Language implementation patterns: create your own domain-specific and general programming languages. Pragmatic Bookshelf, 2009.\n%\n%\\subsection{More Advanced Books}\n%\n%{\\bf 1.} Jim Smith, Ravi Nair, Virtual Machines: Versatile Platforms for Systems and Processes, Morgan Kauffmann, June 2005\n%\n%{\\bf 2.} Aho, Alfred V., Ravi Sethi, and Jeffrey D. Ullman. Compilers: Principles, Techniques and Tools (also known as The Red Dragon Book), 1986.\n%\n%\\subsection{Source Code}\n%\n%{\\bf 1.} Mak, Ronald. Writing compilers and interpreters: an applied approach/by Ronald Mark. 1991\n%\n%Note, this is the first edition, 1991. The code is in C, which I found to be understandable. The later editions that use C++ are not as clear. The issue I found is that the object orientated approach that's used tends to obscure the design principles of the interpreter and requires much study to decipher, The C version is much more straightforward.\n%\n%{\\bf 2.} Wren: \\url{https://github.com/wren-lang/wren}.\\index{wren}\n%\n%Of the open source interpreters on GitHub, I found this to be the easiest to read. It's written by Bob Nystrom in C, the same person who is writing the web book: Crafting Interpreters \\url{https://craftinginterpreters.com/}.\n%\n%{\\bf 3.} Gravity: \\index{Gravity} Another open source interpreter worth looking at is Gravity (\\url{https://github.com/marcobambini/gravity}). Gravity, like Wren, is also written in C.\n%\n%{\\bf 4.}  If you prefer Go,\\index{Go} then the source code to look at is the interpreter written by Thorsten Ball (see book reference above).\n%\n%There are umpteen BASIC interpreters\\index{BASIC} and other languages that can be studied.\n%\n%\\bigskip\\medskip\n\n\\begin{center}\n\\pgfornament[width = 8cm, color = cardinal]{83}\n\\end{center} ", "meta": {"hexsha": "800d2613c400c2a8ffb7d5b8d69205680d085de5", "size": 17634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/chapter5.tex", "max_stars_repo_name": "ObjectPascalInterpreter/BookPart_3", "max_stars_repo_head_hexsha": "95150d4d02f7e13e5b1ebb58c249073a384f2a0a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-11-07T22:45:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T21:38:53.000Z", "max_issues_repo_path": "Book/chapter5.tex", "max_issues_repo_name": "ObjectPascalInterpreter/BookPart_3", "max_issues_repo_head_hexsha": "95150d4d02f7e13e5b1ebb58c249073a384f2a0a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-23T02:13:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-07T06:08:17.000Z", "max_forks_repo_path": "Book/chapter5.tex", "max_forks_repo_name": "ObjectPascalInterpreter/BookPart_3", "max_forks_repo_head_hexsha": "95150d4d02f7e13e5b1ebb58c249073a384f2a0a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-24T17:24:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-21T04:56:58.000Z", "avg_line_length": 45.6839378238, "max_line_length": 744, "alphanum_fraction": 0.7386299195, "num_tokens": 4676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.6567393903057768}}
{"text": "\\subsubsection*{Matrix and Vector Operations\\hfill \\hyperlink{linearAlgebraFunctions}{(up)}\\hypertarget{matrixOperations}{}} \\addcontentsline{toc}{subsubsection}{Matrix and Vector Operations}\n\\begin{table}[H]\n\\caption{Matrix and Vector Operations.}\n\\label{tab:matrixOperations}\n\\begin{center}\n\\begin{tabular}{|l|l|}\\hline\n\\hlnkFunc{herm} & Matrix Hermitian\\\\\n\\hlnkFunc{jdot} & Complex Vector Conjugate Dot Product\\\\\n\\hlnkFunc{gemp} & General Matrix Product\\\\\n\\hlnkFunc{gems} & General Matrix Sum \\\\\n\\hlnkFunc{kron} & Kronecker Product \\\\\n\\hlnkFunc{prod3} & 3 by 3 Matrix Product\\\\\n\\hlnkFunc{prod4} & 4 by 4 Matrix Product\\\\\n\\hlnkFunc{prod} & Matrix product \\\\\n\\hlnkFunc{prodh} & Matrix Hermitian Product\\\\\n\\hlnkFunc{prodj} & Matrix Conjugate Product\\\\\n\\hlnkFunc{prodt} & Matrix Transpose Product\\\\\n\\hlnkFunc{trans} & Matrix Transpose\\\\\n\\hlnkFunc{dot} & Vector Dot Product\\\\\n\\hlnkFunc{outer} & Vector Outer Product\\\\\n\\hline\\end{tabular}\n\\end{center}\n%\\label{default}\n\\end{table}\n%", "meta": {"hexsha": "8256c0e5cbb51981c7de2eac88fa0742ca522b6a", "size": 979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/jvsip_book/MatrixOperations.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/MatrixOperations.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/MatrixOperations.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": 39.16, "max_line_length": 191, "alphanum_fraction": 0.7507660878, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6567274310554745}}
{"text": "% s,fatrix2\n\n\\comment{\n\\newcommand{\\A} {\\blmath{A}}\n\\newcommand{\\x} {\\blmath{x}}\n\\newcommand{\\y} {\\blmath{y}}\n\\newcommand{\\z} {\\blmath{z}}\n}\n\n\\subsection{The \\fatrixx class}\n\nThe pronunciation rhymes with matrix.\nThink ``fake matrix''\nor ``fancy matrix.''\n\n\n\\subsubsection{Background}\n\nMost iterative algorithms\nfor image reconstruction\nare described conveniently using matrix notation,\nbut matrices are not necessarily\nthe most suitable data structure\nfor actually implementing an iterative algorithm\nfor large sized problems.\nThe \\fatrixx class\nprovides a convenient bridge\nbetween matrix notation\nand practical system models\nused for iterative image reconstruction.\n\nConsider the simple iterative algorithm\nfor reconstructing \\x from data \\y\nexpressed mathematically:\n\\be\n\\x^{n+1} = \\x^n + \\alpha \\A' (\\y - \\A\\x^n)\n,\\ee{e,fatrixx,iter}\nwhere \\A is the \\emph{system matrix}\nassociated with\nthe image reconstruction problem at hand.\n%\nIf \\A is small enough\nto be stored as a matrix in \\matlab\n(sparse or full),\nthen this algorithm translates\nvery nicely into \\matlab as follows.\n%\\begin{verbatim}\n\\be\n\\ty{x = x + alpha * A' * (y - A * x);}\n\\ee{e,mat2}\n%\\end{verbatim}\nYou really cannot get any closer connection\nbetween the math and the program than this!\nBut often we work\nwith system models\nthat are too big to store\nas matrices (even sparsely) in \\matlab.\nInstead,\nthe models\nare implemented by subroutines\nthat compute the ``forward projection'' operation\n$\\A \\x$\nand the ``backprojection operation\n$\\A' \\z$\nfor input vectors \\x and \\z respectively.\n%\nThe conventional way\nto use one of these system models\nin \\matlab (or C) would be to rewrite\nthe above program as follows.\n\\begin{verbatim}\nAx = forward_project(system_arguments, x)\nresidual = y - Ax;\ncorrection = back_project(system_arguments, residual)\nx = x + alpha * correction\n\\end{verbatim}\nYuch!\nThis is displeasing for two reasons.\nFirst,\nthe code looks a \\emph{lot} less like the mathematics.\nSecond,\nusually you end up with a different version of the code\nfor every different system model\n(forward/back-projector subroutine pair)\nthat you develop.\nHaving multiple versions\nof a simple algorithm\ncreates a software maintenance headache.\n\nThe elegant solution\nis to develop \\matlab objects\nthat know how to perform\nthe following operations:\n\\blist\n\\item\n\\makebox[4em][l]{%\n\\ty{A * x}\n}\n(matrix vector multiplication,\noperation \\ty{mtimes})\n\\item\n\\makebox[4em][l]{%\n\\ty{A'}\n}\n(\\ty{transpose}), and\n\\item\n\\makebox[4em][l]{%\n\\ty{A' * z}\n}\n(\\ty{mtimes} again,\nwith a transposed object).\n\\elist\nOnce such an object is\ndefined,\none can use \\emph{exactly}\nthe same iterative algorithm\nthat one would have used\nwith an ordinary matrix,\n\\eg,\n\\eref{e,mat2}.\n%\nThe \\fatrixx class\nprovides a convenient mechanism\nfor implementing\nsuch linear operators.\n\n\\subsubsection{Creating a \\fatrixx object}\n\nSuppose \\x is of length 1000\nand \\y is of length 2000.\nOne can create a corresponding \\fatrixx object\nusing the following call:\n\\begin{verbatimtab}\nA = fatrix2('imask', [1000 1], 'omask', [2000 1], ...\n\t'arg', system_arguments, ...\n\t'forw', @forward_project, 'back', @back_project);\n\\end{verbatimtab}\nThe resulting \\fatrixx object \\ty{A}\nacts just like a matrix\nin most important respects.\nIn particular,\nwe can use exactly the same iterative algorithm\n\\eref{e,fatrixx,iter} as before,\nbecause\n\\ty{Ax = A * x}\nis handled internally\nby calling\n\\[\n\\ty{\nAx = forward_project(system_arguments, x)\n}\n\\]\nand similarly for\n\\ty{A' * z}.\n\nBasic operations\nlike \\ty{A(:,7)}\nare also implemented,\nbut nonlinear operations\nlike \\ty{exp(A)}\nare not\nbecause those cannot be computed readily\nusing \\ty{forward_project}. \n\nFor many examples, see\nthe \\ty{systems} subdirectory of \\irt.\n\n\\subsubsection\n{\nOperations on a \\fatrixx object\nthat return another \\fatrixx object\n}\n\n\\blist\n\\item\n\\ty{B = A'} or \\ty{B = ctranspose{A}}\n\\\\\n\\fatrixx object Hermitian transpose\n\\item\n\\ty{C = A * B}\n\\\\\n\\fatrixx object multiplication\n(requires compatible sizes)\n\\item\n\\ty{B = 7 * A}\n\\\\\nmultiplying a scalar times a \\fatrixx object\n\\item\n\\ty{A = [A1; A2; A3]}\n\\\\\nvertical concatenation (\\ty{vertcat} is also supported)\n(requires compatible sizes)\n\\item\n\\ty{A = [A1, A2, A3]}\n\\\\\nhorizontal concatenation (\\ty{horzcat} is also supported) % todo?\n(requires compatible sizes)\n\\item\n\\ty{A(:,[3 7])} or \\ty{A([3 7],:)} or \\ty{A(:,2:end)} etc.\n\\\\\nthese return a smaller sized \\fatrixx\n%\\item\n%\\ty{A(:,newmask)} % todo\n\\item\n\\ty{C = B + A}\n\\\\\n\\fatrixx object addition\n(requires compatible sizes)\n\\elist\n\n\n\\subsubsection\n{\nOperations on a \\fatrixx object\nthat return a vector.\n}\n\n\\blist\n\\item\n\\ty{A(:,7)} or \\ty{A(7,:)}\n\\elist\n\n\n\\subsubsection\n{\nOperations on a \\fatrixx object\nthat return a matrix.\n}\n\nThese are practical only if \\ty{A} has sufficiently small size!\n\n\\blist\n\\item\n\\ty{A(:,:)} or \\ty{full(A)}\n\\item\n\\ty{svd(A)}\n\\item\n\\ty{eig(A)}\n% todo: eigs inv\n\\elist\n\n\n\\subsubsection\n{\nOther operations on a \\fatrixx object.\n}\n\n\\blist\n\\item\n\\ty{A(7,9)}\n\\\\\nThis returns a scalar value. % todo\n\\item\n\\ty{sparse(A)}\n\\\\\nBy default, internally this will compute each column of \\A\nusing \\ty{A(:,j)}\nand then create a sparse matrix\nfrom the nonzero elements of those columns.\nFor most large cases,\nthis will be very slow.\nHowever,\na few \\fatrixx objects\nsuch as \\ty{Gdiag}\nhave an internal \\ty{sparse} method\n(provided by the \\ty{'sparse'} option\nto the \\ty{fatrix2} call)\nthat is very efficient.\n\n\\elist\n\n\n\\subsubsection\n{\nSupport for arrays instead of columns\n}\n\nFor an image reconstruction problem\nwith the mask illustrated in \\fref{fig,reg,mask},\nthe size of \\ty{A} should be\n$\\nd \\times 8$\nwhere \\nd is the number of rows of \\A.\n\nSo if we have a $6 \\times 5$ image \\ty{x}\nand we would like to compute\n$\\A \\x$,\nconventionally\none would need to do the following:\n\\\\\n\\cent{\n\\ty{y = A * x(mask)}\n}\n\nThe statement \\ty{x(mask)}\nextracts the relevant $\\np = 8$ values\nout of the $6 \\times 5$ array \\ty{x}.\n\nObjects in the \\fatrixx class\noften can spare the user the need to use \\ty{x(mask)}\nif the object is defined properly.\n\nSuppose that in a tomographic image reconstruction problem\ncorresponding to \\fref{fig,reg,mask},\nthe sinogram size is $9 \\times 8$\nso $\\nd = 72$.\n\nThen if \\ty{A} is one of the predefined tomographic system models\nin \\irt such as \\ty{Gtomo2_wtmex},\nthen the statement\n\\\\\n\\cent{\n\\ty{yc = A * x(mask)}\n}\n\\\\\nwill produce \\emph{column vector} \\ty{yc}\nwith $\\nd = 72$ elements.\n\nOn the other hand,\nthe convenient syntax\n\\\\\n\\cent{\n\\ty{ya = A * x}\n}\n\\\\\nwill produce a $9 \\times 8$ sinogram \\emph{array} output \\ty{ya}.\nThe two different outputs\nare related by\n\\\\\n\\cent{\n\\ty{yc = ya(:)}\n}\n\nIn other words,\nif the input is a column vector (of length \\np),\nthen the output will also be a column vector,\njust like one would expect for an ordinary matrix.\nBut if the input is an \\emph{array},\nof the appropriate dimensions,\nthen the output will also be an array.\n\nWhen defining a new \\fatrixx object,\nthere are several options\nthat one can use to specify\nthe appropriate dimensions.\n\n\\blist\n\\item\n\\ty{imask}\nis the usual input mask.\nDefault is \\ty{true(idim)}\n\\\\\nThis can also be called just \\ty{mask}\nfor backwards compatibility with \\fatrix objects.\n\n\\item\n\\ty{idim}\ndescribes the input array dimensions.\nDefault is \\ty{sum(imask(:))},\n\\ie, an ordinary column vector.\n\n\\item\n\\ty{omask}\nis a rarely used option.\nDefault is \\ty{true(odim)}\n\n\\item\n\\ty{odim}\ndescribes the output array dimensions.\nDefault is \\ty{sum(omask(:))},\n\\ie, an ordinary column vector.\n\\elist\n\nFor a typical \\fatrixx object,\none will use only the \\ty{imask} and \\ty{odim} options.\n\nFor the tomography example above,\nwe would add the name-value pairs\n\\ty{'odim', [9 8]}\nto the \\ty{fatrix2} call.\n\n\n\\subsubsection{Defining \\fatrixx methods}\n\nThe key methods for a \\fatrixx object\nare the \\ty{forw} and \\ty{back} operations.\nFor the obsolete \\fatrix objects,\nthese methods had to support columns and arrays\nand multiples thereof\nwhich made them fairly complicated.\nFor the new \\fatrixx objects,\nthis complexity is handled by the object itself,\nand the user-defined methods are much simpler.\n\n\\blist\n\\item\nThe \\ty{forw} routine\naccepts a single input array\nof size \\ty{idim}\nand returns a single output array\nof size \\ty{odim}.\n\n\\item\nCaution:\nnonzero values in the input array\noutside of \\ty{imask}\nmay cause unpredictable results.\n\n\\item\nConversely,\nthe \\ty{back} routine\naccepts a single input array\nof size \\ty{odim}\nand returns a single output array\nof size \\ty{idim}.\n\n\\item\nCaution:\nthe output array of the \\ty{back} routine\nmust be zero for any pixels\noutsize of the \\ty{omask}.\n%\nSometimes this will happen automatically\nbecause a computationally efficient\n\\ty{back} routine\nwill only evaluate the output\nwithin the \\ty{omask},\nand will set the other values to zero.\n%\nBut for some objects,\nlike \\ty{Gdft},\nthe \\ty{back} routine\nfirst evaluates the entire output\n(using \\ty{ifftn})\nand then performs a \\ty{.*} with \\ty{omask}\nto comply with the requirement.\n\n\\elist\n\n\n\\subsubsection{The 1D dilemma}\n\nUnfortunately,\n\\matlab does not really support 1D arrays.\n(\\matlab's \\ty{size} command always returns \nat least a two-element vectors.)\nSo for any application where\n\\ty{odim} is 1D,\nsuch as MRI with irregular non-Cartesian k-space samples,\n\\ty{A' * y}\nwill produce a 1D array\nnot a 2D array\neven if \\ty{imask} is 2D,\nbecause \\ty{y} will be ``1D'' in such cases.\n", "meta": {"hexsha": "141fb0fd18ab742e2e0e1a6aeda2f379b011d09a", "size": 9357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/s,fatrix2.tex", "max_stars_repo_name": "tianrluo/mirt", "max_stars_repo_head_hexsha": "d2cd8d980a4a7a8ba7523850ed1c31d016f633df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2019-06-04T08:11:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T04:10:47.000Z", "max_issues_repo_path": "doc/s,fatrix2.tex", "max_issues_repo_name": "tianrluo/mirt", "max_issues_repo_head_hexsha": "d2cd8d980a4a7a8ba7523850ed1c31d016f633df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-06-15T22:02:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-27T03:29:20.000Z", "max_forks_repo_path": "doc/s,fatrix2.tex", "max_forks_repo_name": "tianrluo/mirt", "max_forks_repo_head_hexsha": "d2cd8d980a4a7a8ba7523850ed1c31d016f633df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2019-06-12T09:20:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T09:19:27.000Z", "avg_line_length": 20.6101321586, "max_line_length": 65, "alphanum_fraction": 0.7336753233, "num_tokens": 2749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.656727422477815}}
{"text": "\\section{Application to color normalization}\n\nColor normalization is the process of imposing the same color palette on a group of images. This color palette is always somehow related to the color palettes of the original images. For instance, if the goal is to cancel the illumination of a scene (avoid color cast), then the imposed histogram should be the histogram of the same scene illuminated with white light. Of course, in many occasions this information is not available. Following Papadakis et al.~\\cite{Papadakis_ip11}, we define an in-between histogram, which is chosen here as the regularized OT barycenter. \n\n%The advantage with respect to Papadakis et al.'s method is that the influence of the input histograms on the barycenter can be easily tuned by a change of parameters, in fact it has as a special case any of the original image histograms. \n\n%Some other examples for which color normalization is useful are the color balancing of videos,  or as a preprocessing to register/compare several images taken with different cameras (see \\cite{Papadakis_ip11} for more examples). \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Algorithm}\n\nGiven a set of input images $(X^{0[r]})_{r \\in R}$, the goal is to impose on all the images the same histogram $\\mu_X$ associated to the barycenter $X$. As for the colorization problem tackled in Section~\\ref{sec-appli-color}, the first step is to subsample the original cloud of points $X^{0[r]}$ to make the problem tractable. Thus, for every $X^{0[r]}$ we compute a smaller associated point set $X^{[r]}$ using K-means clustering. Then, we obtain the barycenter $X$ of all the point clouds $(X^{[r]})_{r \\in R}$ with the algorithms presented in Section~\\ref{algobar}. Figure~\\ref{im:baryillu} first row, shows an example on two synthetic cloud of points, $X^{[1]}$ in blue and $X^{[2]}$ in red. The cloud of points in green corresponds to the barycenter $X$, which can change its position depending on the parameter $\\rho=(\\rho_1,\\rho_2)$ in~\\eqref{eqbar} from $X^{[1]}$ for $\\rho=(1,0)$ to $X^{[2]}$ when $\\rho=(0,1)$.  This data set $X$ represents the 3-D histogram we want to impose on all the input images. \n\nOnce we have $X$, we compute the regularized and relaxed OT transport maps $T^{[r]}$ between each $X^{[r]}$ and the barycenter $X$, by solving~\\eqref{eq-symm-reg-energy}. The line segments in Figure~\\ref{im:baryillu} represent the transport between point clouds, i.e. if $\\Sig^{[1]}_{i,j}>0$, $X^{[1]}_i$ is linked to $X_j$, and similarly for $\\Sig^{[2]}$. \n\nWe apply $T^{[r]}$ to $X^{[r]}$, obtaining  $\\tilde X^{[r]}$, for all $r \\in R$, that is to say, we obtain a set of point clouds $\\tilde X^{[r]}$ with a color distribution close to $X$.  Finally, to recover a set of high resolution images, we compute each $\\tilde X^{0[r]}$ from $X^{0[r]}$ by up-sampling. A detailed description of the method is given in Algorithm~\\ref{alg-norm}. \n\n\\begin{algorithm}[ht!]\n\\caption{Regularized OT Color Normalization}\n\\label{alg-norm}\n% \\begin{algorithmic}[1]\n\\Require Images $\\left( X^{0[r]} \\right)_{r \\in R} \\in \\RR^{N_0 \\times d}$, $\\la \\in \\RR^+ $, $\\rho \\in [0,1]^{|R|}$ and $k \\in \\RR^+$.\n\n\\Ensure Images $\\left( \\tilde X^{0[r]} \\right)_{r \\in R} \\in \\RR^{N_0 \\times d}$.\n% \\Statex\n\\begin{enumerate}\n\t\\algostep{Histogram down-sample} Compute $X^{[r]}$ from $X^{0[r]}$ using K-means clustering.\n\t\\algostep{Compute barycenter} Compute with either~\\eqref{eq-bar-l2} or~\\eqref{eq-bar-l1} a barycenter $\\mu_X$ where $X$ is a local minimum of~\\eqref{eqbar} using the block coordinate descent described in Section~\\ref{algobar}, see Algorithm~\\ref{algo-block-barycenters}. \n\t\\algostep{Compute transport mappings} For all $r \\in R$ compute $T^{[r]}$ between \\\\ \n\t\t$X$ and $X^{[r]}$ by solving~\\eqref{eq-symm-reg-energy}, such that $T^{[r]}(X^{[r]}_i) = Z^{[r]}_i$, where $Z^{[r]}= \\diag(\\Sig^{[r]} \\U)^{-1} \\Sig^{[r]} X$.\n\t\\algostep{Transport up-sample} For every $T^{[r]}$ compute $\\tilde T^{0[r]}$ following~\\eqref{eq-upsample}.\n\t\\algostep{Obtain high resolution results} Compute $\\foralls r, \\tilde X^{0[r]} = \\tilde T^{0[r]}(X^{0[r]})$.\n\\end{enumerate}\n% \\end{algorithmic}\n\\end{algorithm}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Results}\n\nWe now show some example of color normalization using Algorithm~\\ref{alg-norm}.\n\n\\begin{figure*}[!h]\n\\centering\n\\setlength{\\arrayrulewidth}{2pt}\n%%% OT %%%%\n\\begin{tabular}{@{}c@{\\hspace{1mm}}c@{\\hspace{1mm}}c@{\\hspace{1mm}}c@{}}\n\t$\\rho=(1,0)$ & $\\rho=(0.7,0.3)$ & $\\rho=(0.4,0.6)$ & $\\rho=(0,1)$ \\\\\n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-0-ksum1lambda0nnx4QP1png} &  \n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-03-ksum1lambda0nnx4QP1png} &\n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-06-ksum1lambda0nnx4QP1png} &\n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-1-ksum1lambda0nnx4QP1png} \\\\\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-0-ksum1lambda0nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-03-ksum1lambda0nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-06-ksum1lambda0nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-1-ksum1lambda0nnx4QP1}\\\\\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-0-ksum1lambda0nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-03-ksum1lambda0nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-06-ksum1lambda0nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-1-ksum1lambda0nnx4QP1} \\\\\\hline\n%%% Regularized\n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-0-ksum20lambda00005nnx4QP1} &\n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-03-ksum20lambda00005nnx4QP1} & \n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-06-ksum20lambda00005nnx4QP1} &\n\\includegraphics[width=.23\\linewidth]{./syntheticbary/Barycenter_DiagsyntheticINVrho-1-ksum20lambda00005nnx4QP1} \\\\\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-01-ksum20lambda00005nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-0307-ksum20lambda00005nnx4QP1}& \n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-0604-ksum20lambda00005nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag2-syntheticrho-10-ksum20lambda00005nnx4QP1}\\\\\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-01-ksum20lambda00005nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-0307-ksum20lambda00005nnx4QP1} & \n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-0604-ksum20lambda00005nnx4QP1} &\n\\includegraphics[width=.23\\linewidth,height=.2\\linewidth]{./syntheticbary/Diag1-syntheticrho-10-ksum20lambda00005nnx4QP1} \\\\\n\\end{tabular}\n \\caption{Comparison of classical OT (top 3 first rows) and relaxed/regularized OT (bottom 3 last rows). The original input images $X^{0,[1]}$ and $X^{0,[2]}$ are shown in Figure~\\ref{im:synth}~(a).  \n \t\tRows \\#1 and \\#4 shows the 2-D projections of $X^{[1]}$ (blue) and $X^{[2]}$ (red), and in green the barycenter distribution for different values of $\\rho$. We display a line between $X^{[r]}_i$ and $X_j$ if $\\Sig^{[r]}_{i,j} > 0.1$. \n\t\tRows \\#2 and \\#5 (resp. \\#3 and \\#6) show the resulting normalized images $\\tilde X^{0[1]}$ (resp. $\\tilde X^{0[2]}$), \n\t\tfor each value of $\\rho$.  \n \t\\textbf{Top 3 first rows:} classical OT corresponding to setting $k=1$ and $\\la=0$. \n\t\\textbf{Bottom 3 last rows:}  regularized and relaxed OT, with parameters $k=20$ and $\\lambda=0.0005$. See main text for comments. \\vspace{0.5cm}\n}\n\\label{im:baryillu}\n\\end{figure*}\n\n\n\n%%%%%%%%%%%%%%%%%%\n\\paragraph{Synthetic example}\n\nFigure~\\ref{im:baryillu} shows a comparison of normalization of two synthetic images using classical OT and our proposed relaxed/regularized OT. The results obtained using Algorithm~\\ref{alg-norm} (setting $p=q=2$), using the set of two images ($|R|=2$) already used in Figure~\\ref{im:synth}~(a), denoting here $X^{0[1]}=X^0$ and $X^{0[2]}=Y^0$. Each column shows the same experiment but with different values of $\\rho$, which allows to visualize the interpolation between the color palettes (the colors in the images  evolve from the colors in $X^{[1]}$ towards the colors of $X^{[2]}$). \n\nWith classical OT, the structure of the original data sets in not preserved as we change $\\rho$, and the consequence on the final images (second and third row), is that the geometry of the original images changes in the barycenters. In contrast to classical OT, for all values of $\\rho$ the relaxed/regularized barycenters $X$ have the same number of clusters of the original sets. Note that the consequence of having a transport that maintains the clusters of the original images, is that the geometry is preserved, while the histograms change.\n\n\\newcommand{\\sidecapY}[1]{ \\begin{sideways}\\parbox{.19\\linewidth}{\\centering #1}\\end{sideways} }\n\\newcommand{\\myimgY}[1]{\\includegraphics[width=.26\\linewidth,height=.22\\linewidth]{#1}}\n\n\\begin{figure*}[!h]\n\\centering\n\\begin{tabular}{@{}c@{\\hspace{1mm}}c@{\\hspace{1mm}}c@{\\hspace{1mm}}c@{} }\n\\sidecapY{ Original $X^{0[1]}$ }  & \n\\myimgY{star/fleur_1} &\n\\myimgY{star/wheat_1} &\n\\myimgY{star/parrot_1} \\\\\n\\sidecapY{$\\rho=(1,0)$ } & \n\\myimgY{barycenter/DiagYfleurrho-1-ksum11lambda00009nnx4QP1} &\n\\myimgY{barycenter/wheat/Diag1-wheatrho-1-ksum13lambda001nnx4QP1} &\n\\myimgY{barycenter/parrot/Diag1-parrotrho-1-ksum1lambda0001nnx4QP1} \\\\\n\\sidecapY{$\\rho=(0.7,0.3)$} & \n\\myimgY{barycenter/DiagYfleurrho-06-ksum11lambda00009nnx4QP1} &\n\\myimgY{barycenter/wheat/Diag1-wheatrho-06-ksum13lambda001nnx4QP1}  &\n\\myimgY{barycenter/parrot/Diag1-parrotrho-06-ksum1lambda0001nnx4QP1} \\\\\n\\sidecapY{ $\\rho=(0.4,0.6)$ } & \n\\myimgY{barycenter/DiagYfleurrho-03-ksum11lambda00009nnx4QP1} &\n\\myimgY{barycenter/wheat/Diag1-wheatrho-03-ksum13lambda001nnx4QP1} &\n\\myimgY{barycenter/parrot/Diag1-parrotrho-03-ksum1lambda0001nnx4QP1} \\\\\n\\sidecapY{ $\\rho=(0,1)$ } & \n\\myimgY{barycenter/DiagYfleurrho-0-ksum11lambda00009nnx4QP1} &\n\\myimgY{barycenter/wheat/Diag1-wheatrho-0-ksum13lambda001nnx4QP1} &\n\\myimgY{barycenter/parrot/Diag1-parrotrho-0-ksum1lambda0001nnx4QP1} \\\\\n\\sidecapY{ Original $X^{0[2]}$ } & \n\\myimgY{star/fleur_2} &\n\\myimgY{star/wheat_2} &\n\\myimgY{star/parrot_2} \\\\\n& (a) &  (b) & (c)\n\\end{tabular}\n\\caption{Results for the barycenter algorithm on different images computed with the method proposed in Section~\\ref{algobarysobolev}. The parameters were set to \\textbf{(a)} $k=1.1,\\la=0.0009$, \\textbf{(b)} $k=1.3,\\la=0.01$, and  \\textbf{(b)} $k=1,\\la=0.001$. Note how as $\\rho$ approaches $(0,1)$, the histogram of the barycenter image becomes similar to the histogram of $X^{0[2]}$.}\n\\label{im:bar}\n\\end{figure*}\n\n\\paragraph{Example on natural images} Fig.~\\ref{im:bar} shows the results of the same experiment as in Fig.~\\ref{im:baryillu}, but on the natural images labeled as $X^{0[1]}$ and $X^{0[2]}$ in rows $\\#1$ and $\\#6$. In this case, we only show the transport from $X$ to $X^{0[1]}$, that is to say, we maintain the geometry of $X^{0[1]}$ (row $\\#1$) and match its histogram to the barycenter distribution. As in the previous experiment, note how the colors change smoothly from $(1,0)$ to $(0,1)$ without generating artifacts and match the color and contrast of image $X^{0[2]}$ for $\\rho=(0,1)$. The change in contrast is specially visible for the (b) wheat image.\n\n%%%%%%%\n\\paragraph{Color Normalization} \n\nComputing the barycenter distribution of the histograms of a set of images is useful for color normalization. We show in Figures~\\ref{barflower}, and~\\ref{barclock} the results obtained with Algorithm~\\ref{alg-norm}, and compare them with the standard OT and the method proposed by Papadakis et al.~\\cite{Papadakis_ip11}. The improvement of the relaxation and regularization is specially noticeable in Figures~\\ref{barflower} where OT creates artifacts such as coloring the leaves on violet for Figure~\\ref{barflower}~(a), or introducing new colors on the background in Figure~\\ref{barflower}~(c). In Figure~\\ref{barclock}, OT and Papadakis et al.'s method introduce artifacts mostly on the sky of Figure~\\ref{barclock}~(a) and  Figure~\\ref{barclock}~(b), while the relaxed and regularized version displays a smoother result for Figure~\\ref{barclock}~(a) and~(c) and a more meaningful color transformation (all the clouds have the same color in the fourth row) for Figure~\\ref{barclock}~(b).\n\n\\newcommand{\\myimgZ}[1]{\\includegraphics[width=.28\\linewidth,height=.26\\linewidth]{#1}}\n\\newcommand{\\myTriTab}[1]{ \\begin{tabular}{@{}c@{\\hspace{2mm}}c@{\\hspace{2mm}}c@{} } #1\t\\end{tabular} }\n\n\\begin{figure*}[ht]\n\\centering\n\\myTriTab{ \n\\myimgZ{./barycenter/flowers/flowers-1} &\n\\myimgZ{./barycenter/flowers/flowers-2} &\n\\myimgZ{./barycenter/flowers/flowers-3} \\\\\n\\myimgZ{./barycenter/flowers/Diag1-OT} &\n\\myimgZ{./barycenter/flowers/Diag2-OT} &\n\\myimgZ{./barycenter/flowers/Diag3-OT} \\\\\n\\myimgZ{./barycenter/nicoflowers1} &\n\\myimgZ{./barycenter/nicoflowers2} &\n\\myimgZ{./barycenter/nicoflowers3} \\\\\n\\myimgZ{./barycenter/flowers/Diag1-flowersrho-033333-ksum2lambda0005nnx4QP1} &\n\\myimgZ{./barycenter/flowers/Diag2-flowersrho-033333-ksum2lambda0005nnx4QP1} &\n\\myimgZ{./barycenter/flowers/Diag3-flowersrho-033333-ksum2lambda0005nnx4QP1} \\\\ \n(a) & (b) & (c)\n}\n\\caption{In the first row, we show the original images. In the following rows, we show the result of computing the barycenter histogram and imposing it on each of the original images, with different algorithms. In the second row, we use OT. In the third row, the results were obtained with the method proposed by Papadakis et al.~\\cite{Papadakis_ip11}. On the last row, we show the results obtained with the relaxed and regularized OT barycenter with $k=2,\\la=0.005$. Note how the proposed algorithm is the only one that does not produce artifacts on the final images such as (a) color artifacts on the leaves and (c) different colors on the background.}\n\\label{barflower}\n\\end{figure*}\n\n\n\\begin{figure*}[ht]\n\\centering\n\\myTriTab{ \n\\myimgZ{./barycenter/clockmontague-1} &\n\\myimgZ{./barycenter/clockmontague-2} &\n\\myimgZ{./barycenter/clockmontague-3} \\\\\n\\myimgZ{./barycenter/Diag1-clockmontaguerho-033333-ksum1lambda0nnx4QP1} & %OT\n\\myimgZ{./barycenter/Diag2-clockmontaguerho-033333-ksum1lambda0nnx4QP1} &\n\\myimgZ{./barycenter/Diag3-clockmontaguerho-033333-ksum1lambda0nnx4QP1} \\\\\n\\myimgZ{./barycenter/nicoclock1} &\n\\myimgZ{./barycenter/nicoclock2} &\n\\myimgZ{./barycenter/nicoclock3} \\\\\n\\myimgZ{./barycenter/Diag1-clockmontaguerho-033333-ksum13lambda00005nnx4QP1} &\n\\myimgZ{./barycenter/Diag2-clockmontaguerho-033333-ksum13lambda00005nnx4QP1} &\n\\myimgZ{./barycenter/Diag3-clockmontaguerho-033333-ksum13lambda00005nnx4QP1} \\\\\n(a) & (b) & (c)\n}\n\\caption{Experiment as in Figure~\\ref{barflower} applied on the images of the first row. Our results, presented in the final row, were obtained with $k=1.3$ and $\\la=0.0005$. Contrary to OT (second row) or the method proposed by Papadakis et al.~\\cite{Papadakis_ip11} (third row), the proposed method does not create artifacts on the sky and the clock for images (a) and (c).}\n\\label{barclock}\n\\end{figure*}\n\n\n\\begin{figure*}[ht]\n\\centering\n\\myTriTab{ \n\\myimgZ{./barycenter/clockHD-1} &\n\\myimgZ{./barycenter/clockHD-2} &\n\\myimgZ{./barycenter/clockHD-3} \\\\\n\\myimgZ{./barycenter/Diag1-clockHDrho-033333-ksum11lambda00005nnx4QP1} &\n\\myimgZ{./barycenter/Diag2-clockHDrho-033333-ksum11lambda00005nnx4QP1} &\n\\myimgZ{./barycenter/Diag3-clockHDrho-033333-ksum11lambda00005nnx4QP1} \\\\\n}\n\\caption{The proposed method can be applied as a preprocessing step in a pipeline for objects detection or image registration, where canceling illumination is important. On the first row, we show a set of pictures of the same object taken at different hours of the day or night, and on the second row, the result of our algorithm setting  $(p,q)=(2,2)$, $k=1$ and $\\la=0.0005$. Note how the algorithm is able to normalize the illumination conditions of all the images.}\n\\label{im:colornorm}\n\\end{figure*}\n\nAs a final example, we would like to show in Figure~\\ref{im:colornorm} how this method can be applied as a preprocessing before comparing/registering images of the same object obtained under different illumination conditions.  \n", "meta": {"hexsha": "2665ca36698f8616fa9e7367288937e7e64dee35", "size": 16942, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/sec-application-bary.tex", "max_stars_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_stars_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-27T03:15:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-19T17:21:04.000Z", "max_issues_repo_path": "paper/sections/sec-application-bary.tex", "max_issues_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_issues_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sections/sec-application-bary.tex", "max_forks_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_forks_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-10-12T17:29:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-04T01:52:32.000Z", "avg_line_length": 85.135678392, "max_line_length": 1014, "alphanum_fraction": 0.7426513989, "num_tokens": 5652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.656727416759375}}
{"text": "\n\\section*{Math}\n\n$\\vec{A}\\cdot\\vec{B} = |\\vec{A}||\\vec{B}|\\cos\\phi_{\\text{AB}} = A_xB_x + A_yB_y +\nA_xB_z$\n\\begin{align*}\n  \\vec{A}\\times\\vec{B} &= |\\vec{A}||\\vec{B}|\\sin\\phi_{\\text{AB}}\\hat{n}\\\\\n  &= \\quad(A_yB_z-A_zB_y)\\hat{x}\\\\\n  &\\quad -(A_xB_z-A_zB_x)\\hat{y}\\\\\n  &\\quad +(A_xB_y-A_yB_x)\\hat{z}\n\\end{align*}\nThe cross product can be represented as a determinant\n\\begin{equation*}\n  \\vec{A}\\times\\vec{B} = %\n  \\begin{vmatrix}\n    \\hat{x} & \\hat{y} & \\hat{z}\\\\\n    A_x & A_y & A_z \\\\\n    B_x & B_y & B_z \\\\\n  \\end{vmatrix}\n\\end{equation*}\n\nIf $ax^2 + bx +c = 0$, $x=\\frac{-b \\pm \\sqrt{b^2 = 4ac}}{2a}$\n\n% Derivatives\n$\\frac{dx^m}{dx} = mx^{m-1}$\\\\\n\n% Integrals\n$\\int x^m\\;dx = \\frac{x^{m+1}}{m+1} + C$", "meta": {"hexsha": "67e146d4502540b5b61de48e41e6bd12fd0f179c", "size": 704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Math-01.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Math-01.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Math-01.tex", "max_forks_repo_name": "tcburt/hodudodi", "max_forks_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1428571429, "max_line_length": 81, "alphanum_fraction": 0.5539772727, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6567035142353406}}
{"text": "\\newpage\n\\subsection{Goal}\\label{subsec:goal}\n\nThe use of first- and second-order methods (Gradient Descent, Conjugate Gradient Descent, Newton's method and Levenberg-Marquardt algorithm) in the tasks of unconstrained nonlinear optimization.\n\n\\subsection{Formulation of the problem}\\label{subsec:formulation-of-the-problem}\n\nGenerate random numbers $\\alpha \\in (0, 1)$ and $\\beta \\in (0, 1)$.\nFurthermore, generate the noisy data $\\{x_k, y_k\\}$, where $k = 0, \\dots, 100$, according to the following rule:\n\n\\begin{equation}\n    y_k = \\alpha x_k + \\beta + \\delta_k, x_k = \\frac{k}{100},\n\\end{equation}\n\nwhere $\\delta_k \\sim N(0, 1)$ are values of a random variable with standard normal distribution.\nApproximate the data by the following linear and rational functions:\n\n\\begin{enumerate}\n    \\item $F(x, a, b) = ax + b$ (linear approximant),\n    \\item $F(x, a, b) = \\frac{a}{1 + bx}$ (rational approximant),\n\\end{enumerate}\n\nby means of least squares through the numerical minimization (with precision $\\varepsilon = 0.001$ of the following function:\n\n\\begin{equation}\n    D(a, b) = \\sum^{100}_{k=0}(F(x_k, a, b) - y_k)^2.\n\\end{equation}\n\nTo solve the minimization problem, use the methods of Gradient Descent, Conjugate Gradient Descent, Newton's method and Levenberg-Marquardt algorithm.\nIf necessary, set the initial approximations and other parameters of the methods.\nVisualize the data and the approximants obtained separately for each type of approximant.\nAnalyze the results obtained (in terms of number of iterations, precision, number of function evaluations, etc.) and compare them with those from Task 2 for the same dataset.\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{First-and second-order optimization methods} use to minimize the objective function $f$ on the set $Q$ its value $f(x)$ and the values of its first and second derivatives (gradient, Hessian), respectively.\n\n\\paragraph{Gradient descent}\n\n\\textit{Gradient descent} is an optimization algorithm that's used when training a machine learning model.\nIt's based on a convex function and tweaks its parameters iteratively to minimize a given function to its local minimum.\n\n\\paragraph{Conjugate gradient method}\n\n\\textit{Conjugate gradient methods} represent a kind of steepest descent approach.\nWith steepest descent, minimization of a function begins $f$ starting at $x_0$ by traveling in the direction of the negative gradient - $f'(x_0)$.\nIn subsequent steps, the movement continues in the direction of the negative gradient evaluated at each successive point until convergence.\n\n\\paragraph{Newton's method}\n\n\\textit{Newton's method} is an iterative method for finding the roots of a differentiable function $f$, which are solutions to the equation $f(x) = 0$.\nIn optimization, Newton's method is applied to the derivative $f'$ of a twice-differentiable function $f$ to find the roots of the derivative (solutions to $f'(x) = 0$), also known as the stationary points of $f$.\nThese solutions may be minima, maxima, or saddle points.\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\\subsection{Results}\\label{subsec:results}\n\nIt is known that optimization by \\textit{linear approximation} has a unique solution, so these methods give similar optimal values for $a$ and $b$, regardless of the choice of initial approximations.\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{Direct methods of optimization.}\n    \\label{ris:plot}\n\\end{figure}\n\nFrom the tables below (Tables~\\ref{tbl:direct},~\\ref{tbl:order}), we can conclude that first-and second-order optimization methods require orders of magnitude less computational operations, in contrast to direct methods.\n\n\\begin{table}[ht]\n\\caption{Direct methods}\n\\begin{tabular}{l|l|l|l|}\n\\cline{2-4}\n                                                & \\textbf{method}             & \\textbf{iterations} & \\textbf{function eval} \\\\ \\hline\n\\multicolumn{1}{|l|}{\\multirow{3}{*}{\\textbf{linear}}}   & exhaustive\\_search & 5448000  & 5448000     \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                          & gauss\\_method      & 77376     & 77376        \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                          & nelder\\_mead       & 18         & 3             \\\\ \\hline\n\\multicolumn{1}{|l|}{\\multirow{3}{*}{\\textbf{rational}}} & exhaustive\\_search & 5448000  & 5448000     \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                          & gauss\\_method      & 6448      & 6448         \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                          & nelder\\_mead       & 10         & 2             \\\\ \\hline\n\\end{tabular}\n\\label{tbl:direct}\n\\end{table}\n\n\\begin{table}[ht]\n\\caption{First- and second-order methods}\n\\begin{tabular}{l|l|l|l|}\n\\cline{2-4}\n                                                         & \\textbf{method}              & \\textbf{iterations} & \\textbf{function eval} \\\\ \\hline\n\\multicolumn{1}{|l|}{\\multirow{4}{*}{\\textbf{linear}}}   & gradient\\_descent            & 150                 & 150                    \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & conjugate\\_gradient\\_descent & 80                  & 80                     \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & newton                       & 250                 & 250                    \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & levenberg\\_marquardt         & 34                  & 34                     \\\\ \\hline\n\\multicolumn{1}{|l|}{\\multirow{4}{*}{\\textbf{rational}}} & gradient\\_descent            & 150                 & 150                    \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & conjugate\\_gradient\\_descent & 104                 & 104                    \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & newton                       & 208                 & 208                    \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & levenberg\\_marquardt         & 56                  & 56                     \\\\ \\hline\n\\end{tabular}\n\\label{tbl:order}\n\\end{table}\n\n\\paragraph{Newton's method gives a different result}\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\nIf we consider the Newton method in more detail, then we can conclude from the theorem above [1]: 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,  first- and second-order methods were implemented and analyzed within the problem of the unconstrained optimization problem.\nThis paper also provides a comparative analysis of direct optimization methods and first-and second-order methods.\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_03}{here}: \\url{https://github.com/vanSultan/anal_dev_algo/tree/lab_03}.\n", "meta": {"hexsha": "82ec663471545291e03025446581a86e70e88b27", "size": 8656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab_03/report/lab_03_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_03/report/lab_03_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_03/report/lab_03_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": 65.0827067669, "max_line_length": 442, "alphanum_fraction": 0.6713262477, "num_tokens": 2241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.8872045966995027, "lm_q1q2_score": 0.656686086190161}}
{"text": "\\documentclass[12pt]{article}\n\n%\\usepackage{fullpage}\n\\usepackage{amsmath,amssymb}\n\n\\begin{document}\n\n\\title{Two Dimensional Euler Simulation}\n\n\\author{\nS.J. Montgomery-Smith\\\\\nDepartment of Mathematics\\\\\nUniversity of Missouri\\\\\nColumbia, MO 65211, U.S.A.\\\\\nstephen@math.missouri.edu\\\\\nhttp://www.math.missouri.edu/\\~{}stephen}\n\n\\date{September 10, 2000}\n\n\\maketitle\n\nThis document describes a program I wrote to simulate the \ntwo dimensional Euler Equation --- a program that is part\nof the {\\tt xlock} screensaver as the {\\tt euler2d}\nmode.  A similar explanation may also be found in the\nbook by Chorin \\cite{C}.\n\n\\section{The Euler Equation}\n\nThe Euler Equation describes the motion of an incompressible\nfluid that has no viscosity.  If the fluid is contained\nin a domain $\\Omega$ with boundary $\\partial \\Omega$, then\nthe equation is in the vector field $u$ (the velocity)\nand the\nscalar field $p$ (the pressure):\n\\begin{eqnarray*}\n\\frac{\\partial}{\\partial t} u &=& -u \\cdot \\nabla u + \\nabla p \\\\\n\\nabla \\cdot u &=& 0 \\\\\nu \\cdot n &=& 0 \\quad \\text{on $\\partial \\Omega$}\n\\end{eqnarray*}\nwhere $n$ is the unit normal to $\\partial \\Omega$.\n\n\\section{Vorticity}\n\nIt turns out that it can be easier write these equations\nin terms of the vorticity.  In two dimensions the vorticity\nis the scalar $w = \\partial u_2/\\partial x - \\partial u_1/\\partial y$.\nThe equation for vorticity becomes\n\\[ \\frac{\\partial}{\\partial t} w = -u \\cdot \\nabla w .\\]\nA solution to this equation can be written as follows.  The velocity\n$u$ causes a flow, that is, a function $\\varphi(t,x)$ that tells where\nthe particle initially at $x$ ends up at time $t$, that is\n\\[\n\\frac\\partial{\\partial t} \\varphi(t,x)\n= u(t,\\varphi(t,x)) .\\]\nThen the equation\nfor $w$ tells us that the vorticity is ``pushed'' around by the flow,\nthat is, $w(t,\\varphi(t,x)) = w(0,x)$.\n\n\\section{The Biot-Savart Kernel}\n\nNow, once we have the vorticity, we can recover the velocity $u$ by\nsolving the equation\n\\begin{eqnarray*}\n\\partial u_2/\\partial x - \\partial u_1/\\partial y &=& w \\\\\n\\nabla \\cdot u &=& 0 \\\\\nu \\cdot n &=& 0 \\quad \\text{on $\\partial \\Omega$}.\n\\end{eqnarray*}\nThis equation is solved by using a Biot-Savart kernel $K(x,y)$:\n$$ u(x) = \\int_\\Omega K(x,y) w(y) \\, dy .$$\nThe function $K$ depends upon the choice of domain.  First let us consider\nthe case when $\\Omega$ is the whole plane (in which case the boundary\ncondition $u \\cdot n = 0$ is replaced by saying that $u$ decays at infinity).\nThen\n\\begin{equation*}\nK(x,y) = K_1(x,y) = c \\frac{(x-y)^\\perp}{|x-y|^2} .\n\\end{equation*}\nHere $x^\\perp = (-x_2,x_1)$, and $c$ is a constant, probably something\nlike $1/2\\pi$.  In any case we will set it to be one, which in effect\nis rescaling the time variable, so we don't need to worry about it.\n\nWe can use this as a basis to find $K$ on the unit disk\n$\\Omega = \\Delta = \\{x:|x|<1\\}$.  It turns out to be\n\\begin{equation*}\nK_2(x,y) = K_1(x,y) - K_1(x,y^*) ,\n\\end{equation*}\nwhere $y^* = y/|y|^2$ is called the reflection of $y$ about the\nboundary of the unit disk.\n\nAnother example is if we have a bijective analytic function\n$p:\\Delta \\to {\\mathbb C}$, and we let $\\Omega = p(\\Delta)$.\n(Here we think of $\\Delta$ as a subset of $\\mathbb C$, that is,\nwe are identifying the plane with the set of complex numbers.)\nIn that case we get\n\\[ K_p(p(x),p(y)) = K_2(x,y)/|p'(x)|^2 .\\]\nOur simulation considers the last case.  Examples of such\nanalytic functions include series \n$p(x) = x + \\sum_{n=2}^\\infty c_n x^n$, where\n$\\sum_{n=2}^\\infty n |c_n| \\le 1$.\n(Thanks to David Ullrich for pointing this out to me.)\n\n\\section{The Simulation}\n\nNow let's get to decribing the simulation.  We assume a rather\nunusual initial distribution for the vorticity --- that the\nvorticity is a finite sum of dirac delta masses.\n\\[ w(0,x) = \\sum_{k=1}^N w_k \\delta(x-x_k(0)) .\\]\nHere $x_k(0)$ is the initial place where the points\nof vorticity are concentrated, with values $w_k$.  \nThen at time $t$, the vorticity becomes\n\\[ w(t,x) = \\sum_{k=1}^N w_k \\delta(x-x_k(t)) .\\]\nThe points of fluid $x_k(t)$ are pushed by the\nflow, that is, $x_k(t) = \\varphi(t,x_k(0))$, or\n\\[ \\frac{\\partial}{\\partial t} x_k(t) = u(t,x_k(t)) .\\]\nPutting this all together, we finally obtain the equations\n\\[ \\frac{\\partial}{\\partial t} x_k = \\alpha_k \\]\nwhere\n\\[ \\alpha_k   = \\sum_{l=1}^N w_l K(x_k,x_l) .\\]\nThis is the equation that our simulation solves.\n\nIn fact, in our case, where the domain is $p(\\Delta)$,\nthe points are described by points\n$\\tilde x_k$, where $x_k = p(\\tilde x_k)$.  Then\nthe equations become\n\\begin{eqnarray}\n\\label{tildex-p1}\n\\frac{\\partial}{\\partial t} \\tilde x_k &=& \\tilde\\alpha_k \\\\\n\\label{tildex-p2}\n\\tilde\\alpha_k &=& \\frac1{|p'(\\tilde x_k)|^2}\n     \\sum_{l=1}^N w_l K_2(\\tilde x_k,\\tilde x_l) .\n\\end{eqnarray}\n\nWe solve this $2N$ system of equations using standard\nnumerical methods, in our case, using the second order midpoint method\nfor the first step, and thereafter using the second order Adams-Bashforth \nmethod.  (See for example the book\nby Burden and Faires \\cite{BF}).\n\n\\section{The Program - Data Structures}\n\nThe computer program solves equation (\\ref{tildex-p1}), and displays\nthe results on the screen, with a boundary.  All the information\nfor solving the equation and displaying the output is countained\nin the structure {\\tt euler2dstruct}.  Let us describe some of\nthe fields in {\\tt euler2dstruct}.  \nThe points $\\tilde x_k$ are contained \nin {\\tt double *x}: with the coordinates of\n$\\tilde x_k$ being the two numbers\n{\\tt x[2*k+0]}, {\\tt x[2*k+1]}.  The values $w_k$ are contained\nin {\\tt double *w}.  The total number of points is\n{\\tt int N}.  (But only the first {\\tt int Nvortex} points\nhave $w_k \\ne 0$.)  The coefficients of the analytic function\n(in our case a polynomial) $p$\nare contained in {\\tt double p\\_coef[2*(deg\\_p-1)]} --- here\n{\\tt deg\\_p} is the degree of $p$, and the real and imaginary\nparts of the coefficient\n$c_n$ is contained in {\\tt p\\_coef[2*(n-2)+0]} and {\\tt p\\_coef[2*(n-2)+1]}.\n\n\\section{Data Initialization}\n\nThe program starts in the function {\\tt init\\_euler2d}.  After allocating\nthe memory for the data, and initialising some of the temporary variables\nrequired for the numerical solving program, it randomly assigns the\ncoefficients of $p$, making sure that $\\sum_{n=2}^{\\tt deg\\_p} n |c_n| = 1$.\nThen the program figures out how to draw the boundary, and what rescaling\nof the data is required to draw it on the screen.  (This uses the\nfunction {\\tt calc\\_p} which calculates $p(x)$.)\n\nNext, it randomly assigns the initial values of $\\tilde x_k$.  We want\nto do this in such a way so that the points are uniformly spread over the\ndomain.  Let us first consider the case when the domain is the unit circle\n$\\Delta$.  In that case the proportion of points that we would expect\ninside the circle of radius $r$ would be proportional to $r^2$.  So\nwe do it as follows:\n\\[ r = \\sqrt{R_{0,1}},\\quad \\theta = R_{-\\pi,\\pi}, \\quad\n   \\tilde x_k = r (\\cos \\theta, \\sin \\theta) .\\]\nHere, and in the rest of this discussion, $R_{a,b}$ is a function\nthat returns a random variable uniformly distributed over the interval\n$[a,b]$.\n\nThis works fine for $\\Delta$, but for $p(\\Delta)$, the points \n$p(\\tilde x_k)$ are not uniformly distributed over $p(\\Delta)$,\nbut are distributed with a density proportional to\n$1/|p'(\\tilde x_k)|^2$.  So to restore the uniform density we need\nto reject this value of $\\tilde x_k$ with probability proportional\nto $|p'(\\tilde x_k)|^2$.  Noticing that the condition \n$\\sum_{n=2}^{\\tt deg\\_p} n |c_n| = 1$ implies that \n$|p'(\\tilde x_k)| \\le 2$, we\ndo this by rejecting if $|p'(\\tilde x_k)|^2 < R_{0,4}$.\n(This makes use of the function {\\tt calc\\_mod\\_dp2} which calculates\n$|p'(x)|^2$.)\n\n\\section{Solving the Equation}\n\nThe main loop of the program is in the function {\\tt draw\\_euler2d}.\nMost of the drawing operations are contained in this function, and\nthe numerical aspects are sent to the function {\\tt ode\\_solve}.\nBut there is an aspect of this that I would like\nto discuss in the next section, and so we will look at a simple method for \nnumerically solving differential equations.\n\nThe Euler Method\n(nothing to do with the Euler Equation), is as\nfollows.  Pick a small number $h$ --- the time step (in\nthe program call {\\tt delta\\_t}).  Then we approximate\nthe solution of the equation:\n\\begin{equation}\n\\label{method-simple}\n\\tilde x_k(t+h) = \\tilde x_k(t) + h \\tilde\\alpha_k(t) .\n\\end{equation}\nThe more sophisticated methods we use are variations of \nthe Euler Method, and so the discussion in the following section\nstill applies.\n\nIn the program, the quantities $\\tilde\\alpha_k$, given by\nequations (\\ref{tildex-p2}) are calculated by the function\n{\\tt derivs}\n(which in turns calls {\\tt calc\\_all\\_mod\\_dp2} to\ncalculate $|p'(\\tilde x_k)|^2$ at all the points).\n\n\n\\section{Subtle Perturbation}\n\nAdded later: the scheme described here seems to not be that effective,\nso now it is not used.\n\nOne problem using a numerical scheme such as the Euler Method occurs\nwhen the points $\\tilde x_k$ get close to the boundary\nof $\\Delta$.  In that case, it is possible that the new\npoints will be pushed outside of the boundary.  Even if they \nare not pushed out of the boundary, they may be much closer\nor farther from the boundary than they should be.  \nOur system of equations is very sensitive to how close points\nare to the boundary --- points with non-zero vorticity\n(``vortex points'') that are close to the boundary travel\nat great speed alongside the boundary, with speed that is\ninversely proportional to the distance from the boundary.\n\nA way to try to mitigate this problem is something that I call\n``subtle perturbation.''\nWe map the points in \nthe unit disk to points in the plane using the map\n\\begin{equation*}\nF(x) = f(|x|) \\frac x{|x|} ,\n\\end{equation*}\nwhere $f:[0,1]\\to[0,\\infty]$ is an increasing continuous\nbijection.  It turns out that a good choice is\n\\begin{equation*}\nf(t) = -\\log(1-t) .\n\\end{equation*}\n(The reason for this is that points close to each other \nthat are a distance\nabout $r$ from the boundary will be pushed around so that\ntheir distance from each other is about multiplied by the\nderivative of $\\log r$, that is, $1/r$.)\nNote that the inverse of this function is given by\n\\begin{equation*}\nF^{-1}(x) = f^{-1}(|x|) \\frac x{|x|} ,\n\\end{equation*}\nwhere \n\\begin{equation*}\nf^{-1}(t) = 1-e^{-t} .\n\\end{equation*}\n\nSo what we could do is the following: instead of working with\nthe points $\\tilde x_k$, we could work instead with the points\n$y_k = F(\\tilde x_k)$.  In effect this is what we do.\nInstead of performing the computation (\\ref{method-simple}),\nwe do the calculation\n\\begin{equation*}\ny_k = F(\\tilde x_k(t)) + h {\\cal A}(\\tilde x_k) \\tilde\\alpha_k(t) \n\\end{equation*}\nwhere\n${\\cal A}(x)$ is the matrix of partial derivatives of $F$:\n\\begin{equation*}\n{\\cal A}(x) = \n\\frac{f(|x|)}{|x|}\n\\left[\n\\begin{matrix}\n1 & 0\\\\\n0 & 1\n\\end{matrix}\n\\right]\n+ \\frac1{|x|}\n  \\left(\\frac{f'(|x|)}{|x|} - \\frac{f(|x|)}{|x|^2}\\right)\n\\left[\n\\begin{matrix}\nx_{1}^2   & x_{1} x_{2}\\\\\nx_{1} x_{2} & x_{2}^2\n\\end{matrix}\n\\right],\n\\end{equation*}\nand then compute\n\\begin{equation*}\n\\tilde x_k(t+h) = F^{-1}(y_k).\n\\end{equation*}\nThese calculations are done in the function {\\tt perturb}, if\nthe quantity {\\tt SUBTLE\\_PERTURB} is set.\n\n\\section{Drawing the Points}\n\nAs we stated earlier, most of the drawing functions are contained\nin the function {\\tt draw\\_euler2d}.  If the variable \n{\\tt hide\\_vortex} is set (and the function {\\tt init\\_euler2d}\nwill set this with probability $3/4$), then we only display\nthe points $\\tilde x_k$ for ${\\tt Nvortex} < k \\le N$.  If \n{\\tt hide\\_vortex} is not set, then the ``vortex points''\n$\\tilde x_k$ ($1 \\le k \\le {\\tt Nvortex}$) are displayed in white.\nIn fact the points $p(\\tilde x_k)$ are what are put onto the screen,\nand for this we make use of the function {\\tt calc\\_all\\_p}.\n\n\\section{Addition to Program: Changing the Power Law}\n\nA later addition to the program adds an option {\\tt eulerpower},\nwhich allows one to change the power law that describes how\nthe vortex points influence other points.  In effect, if this\noption is set with the value $m$, then the Biot-Savart Kernel\nis replace by\n$$ K_1(x,y) = \\frac{(x-y)^\\perp}{|x-y|^{m+1}}, $$\nand\n$$ K_2(x,y) = K_1(x,y) - |y|^{1-m} K_1(x,y) .$$\nSo for example, setting $m=2$ corresponds to the \nquasi-geostrophic equation.  (I haven't yet figured out\nwhat $K_p$ should be, so if $m \\ne 1$ we use the unit circle\nas the boundary.)\n\n\\begin{thebibliography}{9}\n\n\\bibitem{BF} Richard L. Burden, J. Douglas Faires, Numerical Analysis,\nsixth edition, Brooks/Cole, 1996.\n\n\\bibitem{C} Alexandre J. Chorin, Vorticity and Turbulence,\nApplied Mathematical Sciences, Vol 103, Springer Verlag, 1994.\n\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "700ad3176e0bc6615d652c6c950973f75c1a2fe6", "size": 12785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hacks/euler2d.tex", "max_stars_repo_name": "MBrassey/xscreensaver_BlueMatrix", "max_stars_repo_head_hexsha": "2152a79ec08a676d940158735700087323d4a556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-15T07:40:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-01T05:51:36.000Z", "max_issues_repo_path": "hacks/euler2d.tex", "max_issues_repo_name": "luc1dLife/xscreensaver_BlueMatrix", "max_issues_repo_head_hexsha": "2152a79ec08a676d940158735700087323d4a556", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hacks/euler2d.tex", "max_forks_repo_name": "luc1dLife/xscreensaver_BlueMatrix", "max_forks_repo_head_hexsha": "2152a79ec08a676d940158735700087323d4a556", "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.825443787, "max_line_length": 77, "alphanum_fraction": 0.7069221744, "num_tokens": 3998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8175744739711884, "lm_q1q2_score": 0.6566543940639362}}
{"text": "\\chapter{Derivation of Pipe-flow Process Model}\n\\label{AppendixB}\nSince the derivation of the model is based on physical relationships and conservation principles it would be convenient to study at least once the consecutive steps performed in order to obtain it. This may provide reader with better understanding of the process as well as present assumptions and approximations that are utilized. The model is derived starting from two equations: equation of continuity and equation of motion. The derivation provided below is based on %\\cite{billmann_isermann,keerthi_phd}.\n\n\\section{Equation of Continuity}\n\nWe start from definition of the mass:\n\n\\begin{equation}\n\\label{eq:mass}\nm = \\rho A \\Delta z\n\\end{equation}\n\nConsidering mass change in time, i. e. mass-flow\n\n\\begin{equation}\n\\label{eq:massflow}\nq = \\frac{\\partial m}{\\partial t} = \\rho A  w\n\\end{equation}\n\nand then, introducing principle of conservation for elementary pipe segment we obtain\n\n\\begin{equation}\n\\label{eq:massflow2}\n\\frac{\\partial m}{\\partial t} = \\rho A w - A\\left(w + \\frac{\\partial w}{\\partial z}\\Delta z\\right) \\left( \\rho + \\frac{\\partial \\rho}{\\partial z}\\Delta z\\right) \n\\end{equation}\n\nSubstituting (\\ref{eq:mass}) to  (\\ref{eq:massflow2}) we obtain\n\n\\begin{equation}\n\\label{eq:massflow3}\n\\frac{\\partial \\left( \\rho A \\Delta z \\right)}{\\partial t} = \\rho A  w - A\\left( \\rho w + \\Delta z \\left( \\rho \\frac{\\partial w}{\\partial z} +w \\frac{\\partial \\rho}{\\partial z} \\right)+\\frac{\\partial w}{\\partial z} \\Delta z  \\frac{\\partial \\rho}{\\partial z} \\Delta z  \\right) \n\\end{equation}\n\nwhere the last term $\\frac{\\partial w}{\\partial z} \\Delta z  \\frac{\\partial \\rho}{\\partial z} \\Delta z$ is small enough to be neglected. Then, substituting\n\n\\begin{equation}\n\\label{eq:ms4}\n\\rho \\frac{\\partial w}{\\partial z} +w \\frac{\\partial \\rho}{\\partial z} = \\frac{\\partial}{\\partial z} \\left( \\rho w \\right)\n\\end{equation}\n\nas\n\n\\begin{equation}\n\\label{eq:ms5}\n\\frac{\\partial}{\\partial z} \\left( \\rho w \\right) + \\frac{\\partial \\rho}{\\partial t} = 0\n\\end{equation}\n\nAssuming, that the process is isothermal we can introduce\n\n\\begin{equation}\n\\label{eq:ms6}\n\\nu = \\sqrt{\\frac{p}{\\rho}}\n\\end{equation}\n\nthus, substituting (\\ref{eq:massflow}) and (\\ref{eq:ms6}) to (\\ref{eq:ms5}) we obtain first equation of our model:\n\n\\begin{equation}\n\\label{eq:cont_fin3}\n\\frac{A}{\\nu^2} \\frac{\\partial p}{\\partial t} + \\frac{\\partial q}{\\partial z} = 0\n\\end{equation}\n\n\n\\section{Equation of Motion}\n\nHere we start from definition of momentum:\n\n\\begin{equation}\n\\label{eq:mm1}\nM = \\rho A \\Delta z w\n\\end{equation}\n\nthen,using principle of conservation:\n\n\\begin{equation}\n\\label{eq:mm2}\n\\frac{\\partial \\left( \\rho A w \\Delta z \\right)}{\\partial t} = A \\left(p + \\frac{\\rho w^2}{2} \\right) - A\\left(p + \\frac{\\partial p}{\\partial z} \\Delta z + \\frac{\\rho w^2}{2} + \\frac{\\partial}{\\partial z} \\left( \\frac{\\rho w^2}{2} \\right) \\Delta z \\right) - F - Y\n\\end{equation}\n\nBy rearranging equation presented above, we obtain:\n\n\\begin{equation}\n\\label{eq:mm3}\n\\frac{\\partial \\left( \\rho A w \\Delta z \\right)}{\\partial t} = A \\left(p + \\frac{\\rho w^2}{2} \\right) - A\\left(\\left(p + \\frac{\\rho w^2}{2} \\right) + \\Delta z \\left( \\frac{\\partial p}{\\partial z} +  \\frac{\\partial}{\\partial z} \\left( \\frac{\\rho w^2}{2} \\right) \\right)\\right) - F - Y\n\\end{equation}\n\nSubstituting \n\n\\begin{equation}\n\\label{eq:mm4}\n \\frac{\\partial}{\\partial z} \\left(p +  \\frac{\\rho w^2}{2} \\right) = \\frac{\\partial p}{\\partial z} +  \\frac{\\partial}{\\partial z} \\left( \\frac{\\rho w^2}{2} \\right) \n\\end{equation}\n\ninto (\\ref{eq:mm3}) we will obtain\n\\begin{equation}\n\\label{eq:mm5}\n\\frac{\\partial \\left( \\rho  w  \\right)}{\\partial t} = -  \\frac{\\partial}{\\partial z} \\left(p +  \\frac{\\rho w^2}{2} \\right) - F- Y\n\\end{equation}\n\nAgain, assuming that the process is isothermal we obtain:\n\n\\begin{equation}\n\\label{eq:mm_fin}\n\\frac{1}{A} \\frac{\\partial q}{\\partial t} + \\left( 1 - \\frac{q^2 \\nu^2}{2 A^2 p}\\right) \\frac{\\partial p}{\\partial z} + \\frac{q \\nu^2}{A^2 p} \\frac{\\partial q}{\\partial z}= - \\frac{\\lambda \\nu^2}{2DA^2} \\frac{q|q|}{p} - \\frac{g sin \\alpha}{\\nu^2} p\n\\end{equation}\n\nTaking into account, that if $w^2 \\ll \\nu^2$, i. e. velocity of the fluid is significantly lower than velocity of the sound in this fluid, we may neglect term $ \\frac{q^2 \\nu^2}{2 A^2 p}$. Moreover, if the pipeline is long, then we may neglect term $ \\frac{q \\nu^2}{A^2 p}$. Thus, we obtain second equation that is included in physical, continuous time model:\n\n\\begin{equation}\n\\label{eq:momen_fin3}\n\\frac{1}{A} \\frac{\\partial q}{\\partial t} + \\frac{\\partial p}{\\partial z} = - \\frac{\\lambda \\nu^2}{2DA^2} \\frac{q|q|}{p} - \\frac{g sin \\alpha}{\\nu^2} p\n\\end{equation}\n", "meta": {"hexsha": "7a4021548bd9c24db1425ab13c2ae719320047ab", "size": 4671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendices/AppendixB.tex", "max_stars_repo_name": "kamil95/LaTeX_PG_PDI", "max_stars_repo_head_hexsha": "fad925c2c0d68f151c661c45841d80c4b7a7b98c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-10-08T16:16:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T20:19:03.000Z", "max_issues_repo_path": "Appendices/AppendixB.tex", "max_issues_repo_name": "dnarloch/LaTeX_PG_PDI", "max_issues_repo_head_hexsha": "593073eeefe019cbdc0e01e72c8146225ea279b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-11-27T19:23:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-17T14:15:29.000Z", "max_forks_repo_path": "Appendices/AppendixB.tex", "max_forks_repo_name": "dnarloch/LaTeX_PG_PDI", "max_forks_repo_head_hexsha": "593073eeefe019cbdc0e01e72c8146225ea279b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-12-15T15:09:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-06T20:00:14.000Z", "avg_line_length": 41.3362831858, "max_line_length": 509, "alphanum_fraction": 0.6822950118, "num_tokens": 1599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6566543939230267}}
{"text": "\\documentclass[12pt]{article}\n\n\\title{Tic-Tac-Toe with SAT}\n\\author{William John Holden}\n\\date{\\today}\n\n\\usepackage{amsmath,amsthm}\n\\usepackage{mathtools}\n%\\usepackage{parskip}\n\\usepackage{amssymb}\n\\usepackage[margin=1.0in]{geometry}\n\\usepackage[hyphens]{url}\n\\usepackage[hidelinks]{hyperref}\n\\usepackage{listings}\n\\lstset{basicstyle=\\ttfamily,columns=flexible,frame=single,breaklines=true,linewidth=1\\textwidth}\n\n\\newcommand{\\tictactoe}[9]{\\begin{center}\\begin{tabular}{ c | c | c }{$#1$} & {$#2$} & {$#3$} \\\\ \\hline {$#4$} & {$#5$} & {$#6$} \\\\ \\hline {$#7$} & {$#8$} & {$#9$} \\end{tabular}\\end{center}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\nIn this exercise we will construct a series of boolean satisfiability clauses to find a winning move for the game Tic-Tac-Toe.\nThroughout this exercise, assume that we are playing as $x$ and that it is our turn to play for any game shown.\nWe treat the SAT solver as a ``black box'' and will not worry about how it works.\nA SAT solver accepts a \\textit{formula} of \\textit{clauses} containing boolean \\textit{variables} in \\textit{conjunctive normal form} (CNF).\nAn example of a formula in CNF is\n\n\\begin{equation}(A \\vee \\neg B)(C)(C \\vee D \\vee E)(B \\vee \\neg C).\\end{equation}\n\nThis formula is \\textit{satisfiable} with the literals $A=T$, $B=T$, $C=T$, $D=F$, and $E=F$.\nThis is not the only satisfying assignment.\n$D$ and $F$ may each take the values $T$ or $F$, but we are constrained in $C=T$.\nIf $C=F$ then the clause $(C)$ cannot be satisfied, and any unsatisfied clause falsifies the entire formula.\n\nSome formulas cannot be satisfied under any assignment of literals to variables. An obvious example is $(A)(\\neg A)$.\nA less obvious example is\n\n\\begin{equation}(A \\vee \\neg B)(B \\vee \\neg C)(C)(\\neg A \\vee \\neg B \\vee \\neg C).\\end{equation}\n\nIn this case, the $(C)$ clause implies $C=T$, which means $B=T$, which then implies $A=T$, but now the final clause is $(F \\vee F \\vee F)$ which falsifies the formula.\n\nA \\textit{SAT solver} is a computer program for finding a set of satisfying literals or proving if no such satisfying assignment exists.\nThough the boolean satisfiability problem is NP-complete, state of the art SAT solvers are very efficient in practice.\nMartin Horenovsky has a very nice article at \\url{https://codingnest.com/modern-sat-solvers-fast-neat-underused-part-1-of-n/} on this subject.\nI originally learned of the satisfiability problem and SAT solvers attending a course on NP-Complete Problems from Alexander Kulikov (\\url{https://www.edx.org/course/np-complete-problems-uc-san-diegox-algs203x}).\n\nOthers have successfully solved Sudoku puzzles using SAT solvers.\nIn this exercise, we will do the same for tic-tac-toe.\nOf course, tic-tac-toe is much less computationally demanding than Sudoku.\nTic-tac-toe has a smaller board ($3 \\times 3$ instead of $9 \\times 9$) and it has fewer constraints.\nIf we consider the size of the tic-tac-toe puzzle to be $n$ for dimensions $\\sqrt{n} \\textrm{ rows} \\times \\sqrt{n} \\textrm{ columns} = x \\times y$ then we can iterate over every row and column to find a winning move in\n\n\\begin{align}O(x \\times y) + O(y \\times x ) + O(2 \\textrm{ diagonals} \\times \\sqrt{n}) &= \\\\\nO(xy)+O(xy)+O(2\\sqrt{n})\n&=O(n).\n\\end{align}\n\nUsing an exponential time tool for a linear time problem may seem crazy, but the goal here is to learn to \\textit{reduce} problems to SAT.\n\n\\section{Reduction to SAT}\n\n\\subsection{Variables}\n\nWe need to express the positions of our tic-tac-toe board as boolean variables. This is pretty easy. We assign a variable letter to each position in reading order:\n\n\\tictactoe{a}{b}{c}{d}{e}{f}{g}{h}{i}\n\nThere are actually \\textit{three} possible states for each position: X, O, and unassigned. However, in this problem we do not need to concern ourselves with the third state.\nWe will consider a variable to be ``true'' if it is marked wtih X and false otherwise.\n\n\\subsection{Contraint 1: Winning Combinations}\n\nThere are eight total winning combinations in tic-tac-toe: satisfy any of the three rows, any of the columns, or either of the diagonals.\nI should note that the word \\textit{or} in the previous sentence is an inclusive or; winning combinations allow for both a row and a column, both a row and a diagonal, and both a column and a diagonal. For example, the assignment\n\n\\tictactoe{o}{o}{x}{o}{o}{x}{x}{x}{}\n\ncan be won by setting $i=x$.  We can express the eight winning combinations as\n\n\\begin{equation}(a \\wedge b \\wedge c) \\vee (d \\wedge e \\wedge f) \\vee (g \\wedge h \\wedge i)\n\\vee\n(a \\wedge d \\wedge g) \\vee (b \\wedge e \\wedge h) \\vee (c \\wedge f \\wedge i)\n\\vee\n(a \\wedge e \\wedge i) \\vee (c \\wedge e \\wedge g).\\end{equation}\n\nThis long formula is in \\textit{disjunctive normal form} (DNF) and not the CNF we want.\nWe could use rules of discrete mathematics, such as DeMorgan's Law and Distributivity, but in this paper on computational tools let us instead use \\textit{Mathematica's} \\texttt{BooleanConvert} function (\\url{https://reference.wolfram.com/language/ref/BooleanConvert.html}).\n\\texttt{BooleanConvert} accepts an expression and converts it to the desired form.\n(\\textit{Mathematica} functionality is available at \\url{https://www.wolframalpha.com}).\n\n\\begin{lstlisting}\nIn[1] := BooleanConvert[((a && b && c) || (d && e && f) || (g && h && i) || (a && d && g) || (b && e && h) || (c && f && i) || (a && e && i) || (c && e && f)),\"CNF\"]\nOut[1] := (a || b || c || d || g) && (a || b || f || g) && (a || b || f ||  i) && (a || c || d || h) && (a || c || e || h) && (a || e || f || g) && (a || e || i) && (a || f || h) && (b || c || d || i) && (b || d || e || f || h) && (b || d || e || i) && (b || d || f ||  i) && (b || e || f || g) && (b || e || g || i) && (b || f || g || i) && (c || d || e || h) && (c || d || e || i) && (c || d || h || i) && (c || e || g) && (c || f || g || h || i)\n\\end{lstlisting}\n\nNow we have our first set of constraints that we can provide to a SAT solver.\nAn assignment of literals to the variables $a$ through $i$ is a winning move if all three variables in any row, column, or diagonal are $x$.\n\n\\subsection{Contraint 2: Board Configuration}\n\nThe game will be shown with some configuration of $x$ and $o$ settings on the board.\nFor each position with an $x$ we will create a clause of unit length where that variable must be true.\nAll positions marked $o$ induce a clause where that variable must be false.\nFor example, given the game\n\n\\tictactoe{x}{o}{x}{o}{x}{o}{o}{}{}\n\nwe will set $a=T$, $b=F$, $c=T$, $d=F$, $e=T$, $f=F$, $g=F$ with the clauses\n\n\\begin{equation}(a)(\\neg b)(c)(\\neg d)(e)(\\neg f)(\\neg g).\\end{equation}\n\nThese clauses must be generated based on game state.\n\n\\subsection{Constraint 3: One Move}\n\nWe assume that it is our turn to play, and we only get to make one move.\nOne might be tempted to construct an ``exactly-one-of'' clause using the \\textit{exclusive or} operation.\nHowever, this is not correct.\nConsider $A \\oplus B \\oplus C$ for $A = B = C = T$. Then $A \\oplus B = F$, but $(A \\oplus B) \\oplus C = (F) \\oplus T = T$.\nWe need a different ``gadget'' to constrain our SAT solver to mark only one square of our tic-tac-toe board with $x$.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "c93c265548351ec2e351735652c058fb0badf8d2", "size": 7184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tic-Tac-Toe.tex", "max_stars_repo_name": "wjholden/Tic-Tac-Toe-SAT", "max_stars_repo_head_hexsha": "9bc114d77abd042d2abce8fbcd7efe805365d323", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tic-Tac-Toe.tex", "max_issues_repo_name": "wjholden/Tic-Tac-Toe-SAT", "max_issues_repo_head_hexsha": "9bc114d77abd042d2abce8fbcd7efe805365d323", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tic-Tac-Toe.tex", "max_forks_repo_name": "wjholden/Tic-Tac-Toe-SAT", "max_forks_repo_head_hexsha": "9bc114d77abd042d2abce8fbcd7efe805365d323", "max_forks_repo_licenses": ["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.125, "max_line_length": 448, "alphanum_fraction": 0.6845768374, "num_tokens": 2213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6566543899302626}}
{"text": "\n\\subsection{Fermat's method}\n\nIdentify the integer as the difference of two squares, and use this.\n\n\\(x=a.b\\)\n\nWe use the midpoint of the two as \\(c=\\dfrac{a+b}{2}\\)\n\nThis only works for odd numbers. If we have\n\nThe we have:\n\n\\begin{itemize}\n\\item \\(a=c+d\\)\n\\item \\(b=c-d\\)\n\\item \\(x=(c+d)(c-d)\\)\n\\item \\(x=c^2-d^2\\)\n\\end{itemize}\n\nWe can test this by trying \\(a\\) to get \\(a^2-x\\), and seeing if this is a square number.\n\n", "meta": {"hexsha": "61de41558a9200c1e4f7662e4bb11bb6a8d04467", "size": 424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/factorise/01-02-fermatMethod.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/factorise/01-02-fermatMethod.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/factorise/01-02-fermatMethod.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.4347826087, "max_line_length": 89, "alphanum_fraction": 0.6438679245, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249076, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6566180490996578}}
{"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 10}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\subsection*{Problem 3c.1}\n\n\\subsubsection*{Problem 3c.1.a}\n\\begin{align*}\nvar[S^2]  &= Var[\\frac{Y'(I_n-P)Y}{n-p}]\\\\\n&= \\frac{1}{(n-p)^2}Var[Y'(I_n-P)Y]\\\\\n&= \\frac{1}{(n-p)^2}\\times (2\\sigma^4(n-p))\\\\\n&= \\frac{2\\sigma^4}{n-p}\n\\end{align*}\n\n\\subsubsection*{Problem 3c.1.b}\n\\begin{align*}\nA_1 &= \\frac{1}{n-p+2}[I_n-X(X'X)^{-1}X']\\\\\n&= \\frac{R}{n-p+2}\\\\\nE[(Y'A_1Y-\\sigma^2)^2] &= Var(Y'A_1Y-\\sigma^2) + (E[Y'A_1Y-\\sigma^2])^2\\\\ \n&= Var(Y'A_1Y) + (E[Y'A_1Y]-\\sigma^2)^2\\\\\n&= \\frac{Var(Y'RY)}{(n-p+2)^2} + ( \\frac{E[Y'RY]}{(n-p+2)}-\\sigma^2)^2\\\\\n&= \\frac{2\\sigma^4(n-p)}{(n-p+2)^2} + (\\frac{\\sigma^2(n-p)}{n-p+2}-\\sigma^2)^2 \\text{ using 3.12 from textbook}\\\\\n&= \\frac{2\\sigma^4(n-p)}{(n-p+2)^2} + \\frac{4\\sigma^4}{(n-p+2)^2}\\\\\n&= \\frac{2\\sigma^4}{n-p+2}\n\\end{align*} \n\n\\subsubsection*{Problem 3c.1.c}\n\\begin{align*}\nE[Y'A_1Y] &= \\frac{E[Y'RY]}{n-p+2}\\\\\n&= \\frac{\\sigma^2(n-p)}{n-p+2}\\text{ using 3.12 from textbook}\\\\\nMSE[Y'A_1Y] &= E[(Y'A_1Y-\\sigma^2)^2]\\\\\n&= \\frac{2\\sigma^4}{n-p+2}\\\\\nMSE[S^2] &= E[S^2-(E[S^2])^2]\\\\\n&= Var(S^2)\\\\\n&= \\frac{2\\sigma^4}{n-p}\\\\\n&<\\frac{2\\sigma^4}{n-p+2}\\\\\n&\\leq MSE[Y'A_1Y]\n\\end{align*}\n\n\\section*{Problem 3d.1}\n\\subsubsection*{Problem 3d.1.a}\nGiven $Y_i \\sim N(\\theta, \\sigma^2)$ or $Y_i = \\theta + \\epsilon_i$ where $\\epsilon_i \\sim N(0, \\sigma^2)$ \\\\\n$\\mathbf{Y} = \\mathbf{1_n}\\theta + \\mathbf{\\epsilon}$ thus $\\hat{\\theta} = (\\mathbf{1_n}'\\mathbf{1_n})^{-1}\\mathbf{1_n'}Y = \\frac{1}{n}\\mathbf{1_n'}Y  = \\bar{Y}$\n\nThus,  using theorem  $3.5(ii)$ $\\bar{Y}$ and $S^2=\\sum_i(Y_i-\\bar{Y})^2$ are independent\n\n\\subsubsection*{Problem 3d.1.b}\nBorrowing from part (a)  we have: $RSS=Q=\\sum_i(Y_i-\\bar{Y})^2$ $\\implies$ using  theorem $3.5(iii)$:\n\n$RSS/\\sigma^2 \\sim \\chi^2_{n-1}$\n\n\\subsection*{Problem 3d.2}\n\\begin{align*}\nRSS &= Y'(I_n-P)Y\\\\\n&= Y'(I_n-P)Y-\\beta'X'(I-P)(Y-X\\beta)+Y'(I-P)(-X\\beta) \\text{ both terms are zero using PX=P and P=P'} \\\\\n&= (Y-X\\beta)'(I_n-P)(Y-X\\beta)\\\\\n&= \\epsilon'(I_n-P)\\epsilon\n\\end{align*}\n\n\\begin{align*}\n(\\hat{\\beta}-\\beta)'X'X(\\hat{\\beta}-\\beta) &= Z'Z\\\\\nZ &= X(\\hat{\\beta}-\\beta)\\\\\n&= X((X'X)^{-1}X'Y-(X'X)^{-1}X'X\\beta)\\\\\n&= P(Y-X\\beta)\\\\\n&= P\\epsilon\\\\\n(\\hat{\\beta}-\\beta)'X'X(\\hat{\\beta}-\\beta) &= \\epsilon'P'P\\epsilon\n\\end{align*}\n\n\\begin{align*}\nCov[RSS, (\\hat{\\beta}-\\beta)'X'X(\\hat{\\beta}-\\beta)] &= Cov[\\epsilon'(I_n-P)\\epsilon, \\epsilon'P'P\\epsilon]\\\\\n&=  Cov[\\epsilon'(I_n-P)\\epsilon, \\epsilon'PP\\epsilon] \\text{ using } P'=P\\\\\n&=  Cov[\\epsilon'(I_n-P)\\epsilon, \\epsilon' P\\epsilon] \\text{ using } PP = P\\\\\n&= \\sigma^2(I-P)P \\\\\n&= 0\n\\end{align*}\nThus, $RSS$ and $(\\hat{\\beta}-\\beta)'X'X(\\hat{\\beta}-\\beta)$ are indepedent\n\n\\subsection*{Problem 3.12}\n\n\\begin{align*}\nY &= X\\beta + \\epsilon\\\\\n\\bar{Y} &= \\frac{1}{n}\\mathbf{1_n}Y\\\\\n\\sum_i(Y_i-\\hat{Y_i})^2  &= (Y-X\\hat{\\beta})'(Y-X\\hat{\\beta})\\\\\n&= (Y-X(X'X)^{-1}X'Y)'(Y-X(X'X)^{-1}X'Y)\\\\\n&= (Y-PY)'(Y-PY)\\\\\n&= Y'(I-P)'(I-P)Y\\\\\n&= Y'(I-P)Y\\text{ using idempotency of } I-P\\\\\nCov[\\frac{1}{n}\\mathbf{1_n}Y, (I-P)Y]\\\\\n&= \\frac{1}{n}\\mathbf{1_n}Cov[Y](I-P)'\\\\\n&= \\sigma^2(n-p)\\frac{1}{n}\\mathbf{1_n}(I-P)'\n\\end{align*}\nSince the first column of the design matrix is all 1, $1_n$ belongs to the column space of $X$  and is orthogonal to $(I-P)'$ (P being the projection matrix) $\\implies Cov[\\frac{1}{n}\\mathbf{1_n}Y, (I-P)Y] = 0$\n\\end{document}\n\n\n\n", "meta": {"hexsha": "ae055eb915ff5272eeed25ddd16faa0defb3d017", "size": 3502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW10/hw10.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/HW10/hw10.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/HW10/hw10.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": 33.3523809524, "max_line_length": 210, "alphanum_fraction": 0.580525414, "num_tokens": 1659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.6566180398138389}}
{"text": "\\lab{Poisson's equation}{Poisson's equation}\n\\label{lab:poisson2d}\n\nSuppose that we want to describe the distribution of heat throughout a region $\\Omega$.\nLet $h(x)$ represent the temperature on the boundary of $\\Omega$ ($\\partial \\Omega$), and let $g(x)$ represent the initial heat distribution at time $t = 0$.\nIf we let $f(x,t)$ represent any heat sources/sinks in $\\Omega$, then the flow of heat can be described by the boundary value problem (BVP)\n\\begin{align}\n\t\\begin{split}\n\t\t& { } u_t = \\triangle u + f(x,t), \\quad x \\in \\Omega, \\quad t >0,\\\\\n\t\t& { }u(x,t) = h(x), \\quad x \\in \\partial \\Omega, \\\\\n\t\t& { }u(x,0) = g(x).\n\t\\end{split}\n\\end{align}\nWhen the source term $f$ does not depend on time, there is often a steady-state heat distribution $u_{\\infty}$ that is approached as $t \\to \\infty$.\nThis steady state $u_{\\infty}$ is a solution of the BVP\n\\begin{align}\n\t\\begin{split}\n\t\t& { }  \\triangle u + f(x) = 0, \\quad x \\in \\Omega,\\\\\n\t\t& { }u(x,t) = h(x), \\quad x \\in \\partial \\Omega.\n\t\\end{split}\n\\end{align}\n\nThis last partial differential equation, $\\triangle u = -f$, is called Poisson's equation.\nThis equation is satisfied by the steady-state solutions of many other evolutionary processes.\nPoisson's equation is often used in electrostatics, image processing, surface reconstruction, computational fluid dynamics, and other areas.\n\n\n\\section*{Poisson's equation in two dimensions}\n\n Consider Poisson's equation together with Dirichlet boundary conditions on a square domain $R = [a,b]\\times [c,d]$:\n \\begin{align}\n\t\\begin{split}\n \tu_{xx} + u_{yy} &= f,\\quad x \\text{ in } R \\subset \\mathbb{R}^2,\\\\\n \tu &= g, \\quad x \\text{ on } \\partial R.\n\t\\end{split}\\label{eqn:2d_poisson}\n\\end{align}\nLet $a = x_{-1}, x_0, \\ldots, x_{N-1} = b$ be a partition of $[a,b]$, and let $c = y_{-1}, y_0, \\ldots, y_{N-1} = d$ be a partition of $[c,d]$.\nSuppose that there are $N+1$ evenly spaced points, so that $N$ is the number of subintervals in each dimension, and $x_i, y_j$ are given by\n\\begin{align*}\n\tx_i &= a + (i+1)h, \\\\\n\ty_j &= c + (j+1)h,\n\\end{align*}\nfor $i,j = 0, \\ldots, N-2$, where $h = x_i-x_{i-1} = y_i-y_{i-1}$.\nWe look for an approximation $U_{i,\\,j}$ on the grid $\\{(x_i,y_j)\\}_{i,j=-1}^{N-1}$.\n\nRecall that\n \\begin{align*}\n \\triangle u &= u_{xx}(x,y) + u_{yy}(x,y) \\\\\n&= \\frac{u(x+h,y) - 2u(x,y)+ u(x-h,y)}{h^2} \\\\\n & \\qquad{}+ \n \\frac{u(x,y+h) - 2u(x,y)+ u(x,y-h)}{h^2} + \\mathcal{O}(h^2).\n \\end{align*}\n We replace $\\triangle $ with the finite difference operator $\\triangle_h$, defined by\n \\begin{align*}\n \\triangle_h U_{ij} &= \\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}(U_{i-1,\\,j} + U_{i+1,\\,j} + U_{i,\\,j-1} + U_{i,\\,j+1}-4U_{i,\\,j}).\n \\end{align*}\n\n Then the set of equations  \n\\[\n\\triangle_h U_{ij} = f_{ij}, \\quad i,j = 0,\\ldots,N-2,\n\\]% $i,j = 1,\\ldots,m$ \ncan be written in matrix form as\n \\[AU + p +  q  = f.\\]\n\n$A$ is a block tridiagonal matrix, given by \n\\begin{align}\n\t\\frac{1}{h^2}\n\\begin{bmatrix}\nT & I & &  &\\\\\nI &T & I & &\\\\\n&\\ddots  & \\ddots & \\ddots & \\\\\n&  & I & T & I \\\\\n&  &  & I & T\\end{bmatrix}\\label{poisson2d:matrixA}\n\\end{align}\n\nwhere $I$ is the $N-1\\times N-1$ % $m\\times m$\nidentity matrix, and $T$ is the tridiagonal matrix\n\\[\\begin{bmatrix}\n-4 & 1 & &  &\\\\\n1 &-4 & 1 & &\\\\\n&\\ddots  & \\ddots & \\ddots & \\\\\n&  & 1 & -4 & 1 \\\\\n&  &  & 1 & -4 \\end{bmatrix}.\\]\n\n\nThe vector $U$ is given by \n\\[U = \\begin{bmatrix} U^0 \\\\ U^1 \\\\ \\\\ U^{N-2} \\end{bmatrix} \\text{ where } U^j = \n\\begin{bmatrix} U_{0,\\,j} \\\\ U_{1,\\,j} \\\\ \\\\ U_{N-2,\\,j} \\end{bmatrix} \\text{ for each } j, \\text{ }0\\leq j \\leq N-2.\\]\n\n% \\[U = \\begin{bmatrix} U^1 \\\\ U^2 \\\\ \\\\ U^m \\end{bmatrix} \\text{ where } U^j =\n% \\begin{bmatrix} U_{1,\\,j} \\\\ U_{2,\\,j} \\\\ \\\\ U_{m,\\,j} \\end{bmatrix} \\text{ for each } j, 1\\leq j \\leq m\\]\n% So $U^j$ represents the $j$th row of interior points in our grid, where $y_j = jh$\n\n\nThe vectors $p$ and $q$ come from the boundary conditions of \\eqref{eqn:2d_poisson}, and are given by \n\\[p = \\begin{bmatrix} p^0 \\\\ \\ldots \\\\ \\\\ p^{N-2} \\end{bmatrix}, \\quad  q = \\begin{bmatrix} q^0 \\\\ \\ldots \\\\ \\\\ q^{N-2} \\end{bmatrix},\\]\nwhere \n\\[p^j = \\frac{1}{h^2} \\begin{bmatrix} g_{-1,\\,j} \\\\ 0 \\\\ \\vdots \\\\0\\\\ g_{N-1,\\,j} \\end{bmatrix} ,\\,\\,\\, 0 \\leq j \\leq N-2,\\]\nand \n\\[q^0 = \\frac{1}{h^2}\\begin{bmatrix} g_{0,-1}  \\\\ g_{1,-1} \\\\ \\vdots \\\\ g_{N-3,-1}\\\\ g_{N-2,-1} \\end{bmatrix}, \\quad q^{N-2} = \\frac{1}{h^2}\\begin{bmatrix} g_{0,N-1} \\\\ g_{1,N-1} \\\\ \\vdots \\\\ g_{N-3,N-1}\\\\ g_{N-2,N-1} \\end{bmatrix}, \\quad q^{j} = \\begin{bmatrix} 0 \\\\ 0 \\\\ \\vdots \\\\ 0 \\\\ 0 \\end{bmatrix} ,\\,\\,\\, 1 \\leq j \\leq N-3.\\]\n\n% The vector $q$ is given by $u = [q^0 \\ldots q^{N-2}]^T$, %   $u = [q^1 \\ldots q^m]^T$,\n% where\n% \\[q^j = \\frac{1}{h^2} \\begin{bmatrix} g_{0,\\,j} \\\\ 0 \\\\ \\vdots \\\\0\\\\ g_{m+1,\\,j} \\end{bmatrix} , \\,\\,\\, 2 \\leq j \\leq m-1\\]\n% and\n% \\[q^1 = \\frac{1}{h^2}\\begin{bmatrix} g_{1,0} + g_{0,1} \\\\ g_{2,0} \\\\ \\vdots \\\\ g_{m-1,0}\\\\ g_{m,0} + g_{m+1,1}\\end{bmatrix}, \\quad q^m = \\frac{1}{h^2}\\begin{bmatrix} g_{1,m+1} + g_{0,m}\\\\ g_{2,m+1} \\\\ \\vdots \\\\ g_{m-1,m+1}\\\\ g_{m,m+1} + g_{m+1,m}\\end{bmatrix}\\]\n\n\n\n\n% \\begin{problem}\n% Find the solution $u$ of the 2D Poisson equation with the given Dirichlet boundary conditions:\n% \\begin{align*}\n% \t\\Delta u &= -\\pi^2 \\sin(\\pi x)\\sin(\\pi y), \\quad (x,y) \\in [0,1]\\times [0,1], \\\\\n% \tu(x,0) &= 1-x, \\\\\n% \tu(x,1) &= 1-2x, \\\\\n% \tu(0,y) &= 1, \\\\\n% \tu(1,y) &= -y.\n% \\end{align*}\n%\n% Graph your solution, and demonstrate convergence of the numerical approximation by\n% creating a log-log plot of the error $E(h).$\n% \\end{problem}\n\n% The matrix $A$ is sparse, and so we can use several functions from the package \\texttt{scipy.sparse.linalg}.\n% In particular, we use the functions \\texttt{spdiags} and \\texttt{spsolve}.\n%\n%  \\begin{verbatim}\n% D1,D2,D3 = -4*np.ones((1,m**2)), np.ones((1,m**2)), np.ones((1,m**2))\n% Dm1, Dm2 = np.ones((1,m**2)), np.ones((1,m**2))\n% for j in range(0,D2.shape[1]):\n% \tif (j%m)==m-1:\n% \t\tD2[0,j]=0\n% \tif (j%m)==0:\n% \t\tD3[0,j]=0\n% diags = np.array([0,-1,1,-m,m])\n% data = np.concatenate((D1,D2,D3,Dm1,Dm2),axis=0) # This stacks up rows\n% A = 1./h**2.*spdiags(data, diags, m**2,m**2).asformat('csr') # This ap\n%  \\end{verbatim}\n\n\\begin{comment}\n\\subsection{2D Heat Equation}\nRecall that the collection of finite difference equations\n\\[\\nabla^2_h U_{ij} = 0, \\quad 1 \\leq i,j\\leq m\\]\ncan be written in matrix form as\n\\[AU + q  = 0\\]\n\nThe Crank-Nicolson method for the 2D heat equation is given by\n\\[U_{i,\\,j}^{n+1}- U_{i,\\,j}^{n} = \\frac{\\Delta t}{2}(\\nabla_h^2 U_{i,\\,j}^{n} + \\nabla_h^2 U_{i,\\,j}^{n+1}) \\text{ for each } 1 \\leq i,j \\leq m\\]\nis a second order accurate in both space and time. Basically we're using a midpoint scheme in time,\nand a trapezoidal scheme in space. The resulting method is implicit, and can be written in matrix form as\n\\begin{align*}\n\tIU^{n+1} &= IU^n + \\frac{\\Delta t}{2}(AU^n + q + AU^{n+1} + q)\\\\\n\t(I - \\frac{\\Delta t}{2}A)U^{n+1}&= (I + \\frac{\\Delta t}{2}A)U^n + \\Delta t q\n\\end{align*}\n\n% TODO: What size must the time step be to ensure stability?\n\nWe will need to take many time steps, where many equations must be solved with the matrix $(I - \\frac{\\Delta t}{2}A)$.\nThe function \\texttt{factorized} from \\texttt{scipy.sparse.linalg} computes the LU decomposition of the matrix.\nThis decomposition reduces the time required for solving consecutive time steps.\n\\end{comment}\n\nThe following code implements the greater portion of the finite difference method; it leaves the construction of the matrix $A$ in \\eqref{poisson2d:matrixA} to problem \\ref{poisson2d:laplace}.\n\n\\begin{lstlisting}\nfrom __future__ import division\nfrom scipy.sparse import spdiags\nfrom scipy.sparse.linalg import spsolve\n\ndef poisson_square(a1,b1,c1,d1,n,bcs, source): \n\t# n = number of subintervals\n\t# We discretize in the x dimension by \n\t# a1 = x_0 < x_1< ... < x_n=b1, and \n\t# We discretize in the y dimension by \n\t# c1 = y_0 < y_1< ... < y_n=d1. \n\t# This means that we have interior points \n\t# {x_1, ..., x_{n-1}}\\times {y_1, ..., y_{n-1}}\n\t# or {x_1, ..., x_m}\\times {y_1, ..., y_m} where m = n-1. \n\t# In Python, this is indexed as \n\t# {x_0, ..., x_{m-1}}\\times {y_0, ..., y_{m-1}}\n\t# We will have m**2 pairs of interior points, and \n\t# m**2 corresponding equations.\n\t# We will organize these equations by their \n\t# y coordinates: all equations centered \n\t# at (x_i, y_0) will be listed first, \n\t# then (x_i, y_1), and so on till (x_i, y_{m-1})\n\tdelta_x, delta_y, h, m = (b1-a1)/n, (d1-c1)/n, (b1-a1)/n, n-1\n\t\n\t####    Construct the matrix A    ####\n\t\n\t\n\t####    Here we construct the vector b    ####\n\tb, Array = np.zeros(m**2), np.linspace(0.,1.,m+2)[1:-1]\n\t# In the next line, source represents \n\t# the inhomogenous part of Poisson's equation\n\tfor j in xrange(m): \n\t\tb[j*m:(j+1)*m] = source(a1+(b1-a1)*Array, c1+(j+1)*h*np.ones(m) )\n\t\n    # In the next four lines, bcs represents the \n\t# Dirichlet conditions on the boundary\n\t# y = c1+h, d1-h\n\tb[0:m] -= h**(-2.)*bcs(a1+(b1-a1)*Array,c1*np.ones(m))\n\tb[(m-1)*m:m**2] -= h**(-2.)*bcs(a1+(b1-a1)*Array,d1*np.ones(m))\n\t# x = a1+h, b1-h\n\tb[0::m] -= h**(-2.)*bcs(a1*np.ones(m),c1+(d1-c1)*Array) \n\tb[(m-1)::m] -= h**(-2.)*bcs(b1*np.ones(m),c1+(d1-c1)*Array)\n\t\n    ####    Here we solve the system A*soln = b    ####\n\tsoln = spsolve(A,b) \n\t\n\t# We return the solution, and the boundary values, \n\t# in the array z.\n\tz = np.zeros((m+2,m+2) ) \n\tfor j in xrange(m): \n\t\tz[1:-1,j+1] = soln[j*m:(j+1)*m]\n\t\n\tx, y = np.linspace(a1,b1,m+2), np.linspace(c1,d1,m+2)\n\tz[:,0], z[:,m+1]  = bcs(x,c1*np.ones(len(x)) ), bcs(x,d1*np.ones(len(x)) )\n\tz[0,:], z[m+1,:] = bcs(a1*np.ones(len(x)),y), bcs(b1*np.ones(len(x)),y)\n\treturn z\n\n\\end{lstlisting}\n\n\\begin{problem}\nConstruct the matrix $A$ in \\eqref{poisson2d:matrixA}. Make sure your matrix is sparse. Then use the code \nabove to solve the boundary value problem\n\\begin{align}\n\t\\begin{split}\n\t\\Delta u = 0, &{}\\quad x \\in [0,1]\\times [0,1],\\\\\n\tu(x,y) = x^3, &{}\\quad (x,y) \\in \\partial ([0,1]\\times [0,1]).\n\t\\end{split}\n\t\\label{poisson2d:laplace}\n\\end{align}\nPlot the 3D solution with $n=100$.\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Laplace.png}\n\\caption{The solution of \\eqref{poisson2d:laplace}.}\n\\end{figure}\n\n\\section*{Poisson's equation and conservative forces}\nIn physics Poisson's equation is used to describe the scalar potential of a conservative force.\nIn general\n\\[ \\Delta V = - f\\]\nwhere $V$ is the scalar potential of the force, or the potential energy a particle would have at that point, and $f$ is a source term.\nExamples of conservative forces include Newton's Law of Gravity (where matter become the source term) and Coulomb's Law, which gives the force between two charge particles (where charge is the source term).\n\nIn electrostatics the electric potential is also known as the voltage, and is denoted by $V.$ \nFrom Maxwell's equations it can be shown that that the voltage obeys Poisson's equation with the electric charge density (like a continuous cloud of electrons) being the source term: \n\\[\n \\Delta V = -\\frac{\\rho}{\\epsilon_0},\n\\]\nwhere $\\rho$ is the charge density and $\\epsilon_0$ is the permissivity of \nfree space, which is a constant that we'll leave as $1$.\n\nUsually a non zero $V$ at a point will cause a charged particle to move to a lower potential, changing $\\rho$ and the solution to $V$.\nHowever, in this analysis we'll assume that the charges are fixed in place.\n\nSuppose we have 3 nested pipes.\nThe outer pipe is attached to \"ground,\" which usually we define to be $V=0$, and the inner two have opposite relative charges.\nPhysically the two inner pipes would function like a capacitor.\n\nThe following code will plot the charge distribution of this setup.\n\\begin{lstlisting}\nimport matplotlib.colors as mcolors\n\ndef source(X,Y):\n    \"\"\"\n    Takes arbitrary arrays of coordinates X and Y and returns an array of the same shape\n    representing the charge density of nested charged squares\n    \"\"\"\n    src = np.zeros(X.shape)\n    src[ np.logical_or(\n        np.logical_and( np.logical_or(abs(X-1.5) < .1,abs(X+1.5) < .1) ,abs(Y) < 1.6),\n        np.logical_and( np.logical_or(abs(Y-1.5) < .1,abs(Y+1.5) < .1) ,abs(X) < 1.6))] = 1\n    src[ np.logical_or(\n        np.logical_and( np.logical_or(abs(X-0.9) < .1,abs(X+0.9) < .1) ,abs(Y) < 1.0),\n        np.logical_and( np.logical_or(abs(Y-0.9) < .1,abs(Y+0.9) < .1) ,abs(X) < 1.0))] = -1\n    return src\n\n#Generate a color dictionary for use with LinearSegmentedColormap\n#that places red and blue at the min and max values of data\n#and white when data is zero\n\ndef genDict(data):\n    zero = 1/(1 - np.max(data)/np.min(data))\n    cdict = {'red':   [(0.0,  1.0, 1.0),\n                   (zero,  1.0, 1.0),\n                   (1.0,  0.0, 0.0)],\n         'green': [(0.0,  0.0, 0.0),\n                   (zero,  1.0, 1.0),\n                   (1.0,  0.0, 0.0)],\n         'blue':  [(0.0,  0.0, 0.0),\n                   (zero,  1.0, 1.0),\n                   (1.0,  1.0, 1.0)]}\n    return cdict\n\n\na1 = -2.\nb1 = 2.\nc1 = -2.\nd1 = 2.\nn =100\nX = np.linspace(a1,b1,n)\nY = np.linspace(c1,d1,n)\nX,Y = np.meshgrid(X,Y)\n\nplt.imshow(source(X,Y),cmap =  mcolors.LinearSegmentedColormap('cmap', genDict(source(X,Y))))\nplt.colorbar(label=\"Relative Charge\")\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{pipesRho.pdf}\n\\caption{The charge density of the 3 nested pipes.}\n\\end{figure}\n\n\nThe function \\li{genDict} scales the color values to be white when the charge density is zero.\nThis is mostly to help visualize where there are neutrally charged zones by forcing them to be white.\nYou may find it useful to also apply it when you solve for the electric  potential.\n\nWith this definition of the charge density, we can solve Poisson's equation for the potential field.\n\n\\begin{problem}\nSolve \n% \\[\\Delta V = -\\rho(x,y)\\]\n\\begin{align}\n\t\\begin{split}\n\t\\Delta V = -\\rho(x,y), &{}\\quad x \\in [-2,2]\\times [-2,2],\\\\\n\tu(x,y) = 0, &{}\\quad (x,y) \\in \\partial ([-2,2]\\times [-2,2]).\n\t\\end{split}\n\t\\label{poisson2d:source}\n\\end{align}\n% \nfor the electric potential $V.$\nUse the source function ($-\\rho$) defined above. % and grid sizes defined above.\n% Use $V=0$ for the boundary conditions on all sides.\n% \\textit{(Due to the size of $A$, this is best done using sparse matrices)}\nPlot the 2D solution using $n=100$.\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{pipesV.png}\n\\caption{The electric potential of the 3 nested pipes.}\n\\end{figure}", "meta": {"hexsha": "b00a62b1836b3b6934f5a9df8aafd89df3081f1b", "size": 14427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/PoissonEquation/Poisson.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume4/PoissonEquation/Poisson.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume4/PoissonEquation/Poisson.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3381088825, "max_line_length": 332, "alphanum_fraction": 0.6253552367, "num_tokens": 5368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6566180342985876}}
{"text": "\\section{Application of our previous calculation of $ H_\\ast(S^n)$ and the ``locality principle''}\n\\begin{theorem}\nLet $n\\geq 1$. There is a surjective monoid homomorphism $[S^n,S^n]\\to \\Z_\\times$, where $\\Z_\\times$ is the multiplicative monoid of $\\Z$. $[S^n,S^n]$ is a monoid under composition. (This is basically the degree...)\n\\end{theorem}\n\\begin{proof}\nGiven $f:S^n\\to S^n$, take the homology, which is just a homomorphism $\\Z\\to \\Z$, all of which are simply multiplication by an integer. The integer by which you're multiplying to get this homomorphism is the integer associated to $f$.\n\nConstruction. If $n=1$, this is just the winding number. Suppose I've constructed this in dimension $n-1$. We have:\n\t\\begin{equation*}\n\t\\xymatrix{ H_{n-1}(S^{n-1})\\ar[d]^n & \\ar[l] H_n(D^n,S^{n-1})\\ar[r]\\ar[d] & H_n(S^n)\\ar[d]\\\\\n\t H_{n-1}(S^{n-1}) & \\ar[l] H_n(D^n,S^{n-1})\\ar[r] & H_n(S^n)}\n\t\\end{equation*}\nSo we're basically suspending $f:S^{n-1}\\to S^{n-1}$. More explicitly, if you have $f:S^{n-1}\\to S^{n-1}$. We can extend to $\\overline{f}:D^n\\to D^n$ by sending $tx\\mapsto tf(x)$ where $tx$ denotes the ray connecting $x\\in S^{n-1}$ to the origin, and we can then quotient out by $S^{n-1}$ to get the map $S^n\\to S^n$ as required.\n\\end{proof}\n\\subsection{Addendum to the ES axioms}\nThere's a further axiom, which isn't due to ES, but rather due to Milnor. It's this.\n\\begin{itemize}\n\\item Suppose $I$ a set. For each $\\alpha\\in I$ there's have a space $X_\\alpha\\in\\mathbf{Top}$. I can consider $\\coprod_\\alpha X_\\alpha$. There are inclusion maps $X_\\alpha\\to\\coprod_\\alpha X_\\alpha$. Then $\\bigoplus_\\alpha h_n(X_\\alpha)\\cong h_n\\left(\\coprod_\\alpha X_\\alpha\\right)$.\n\\end{itemize}\nThis is known for ordinary singular homology.\n\\subsection{Homological algebra}\n\\begin{enumerate}\n\\item Suppose $A,B\\subseteq C$ are abelian groups. Then $A+C\\subseteq C$. You have a sexseq $0\\to A\\cap B\\to A\\oplus B\\to A+C\\to 0$ where the map $c\\mapsto (c,-c)$ is how the map $A\\cap B\\to A\\oplus B$ is defined.\n\\item ``Fundamental isomorphism for abelian groups'' says the following. We have two sexseqs.\n\t\\begin{equation*}\n\t\\xymatrix{0\\ar[r] & A\\cap B\\ar[r]\\ar[d] & B\\ar[r]\\ar[d] & B/A\\cap B\\ar[r]\\ar@{-->}[d]^\\cong & 0\\\\\n\t0\\ar[r] & A\\ar[r] & A+B\\ar[r] & (A+B)/A\\ar[r] & 0}\n\t\\end{equation*}\n\tI'm not going to write out the diagram chase that we did.\n\\item ``Snake lemma''. Suppose I have\\footnote{``It's my Turn'', Jill Clayburgh}:\n\t\\begin{equation*}\n\t\\xymatrix{ & \\ker f^\\prime\\ar[r]\\ar[d] & \\ker f\\ar[r]\\ar[d] & \\ker f^{\\prime\\prime}\\ar[d]\\\\\n\t0\\ar[r] & A^\\prime\\ar[r]\\ar[d]^{f^\\prime} & A\\ar[r]\\ar[d]^f & A^{\\prime\\prime}\\ar[r]\\ar[d]^{f^{\\prime\\prime}} & 0\\\\\n\t0\\ar[r] & B^\\prime\\ar[r]\\ar[d] & B\\ar[r]\\ar[d] & B^{\\prime\\prime}\\ar[r]\\ar[d] & 0\\\\\n\t & \\coker f^\\prime\\ar[r] & \\coker f\\ar[r] & \\coker f^{\\prime\\prime}}\n\t\\end{equation*}\n\tClaim is that there's a map $\\ker f^{\\prime\\prime}\\to\\coker f$ so that $0\\to \\ker f^\\prime\\to \\ker f\\to \\ker f^{\\prime\\prime}\\to\\coker f^\\prime\\to\\coker f\\to \\coker f^{\\prime\\prime}\\to 0$. This is basically the lexseq in homology associated to the sexseqs of the following three chain complexes: $0\\to A^\\prime\\to B^\\prime\\to 0$, $0\\to A\\to B\\to 0$, and $0\\to A^{\\prime\\prime}\\to B^{\\prime\\prime}\\to 0$. Work this out yourself.\n\\end{enumerate}\n\\subsection{Locality}\n\\begin{definition}\nThe (not necessarily open) cover of a topological space. Won't write this.\n\\end{definition}\n\\begin{definition}\nLet ${\\mathscr{A}}$ be a cover of $X$. An $n$-simplex $\\sigma$ is ${\\mathscr{A}}$-small if there is $A\\in \\mathscr{A}$ such that the image of $\\sigma$ is entirely in $A$.\n\\end{definition}\nNotice that if $\\sigma:\\Delta^n\\to X$ is ${\\mathscr{A}}$-small, then so is $d^i\\sigma$. Let's denote by $\\Sin^{\\mathscr{A}}_n(X)$ the set of ${\\mathscr{A}}$-small $n$-simplices. This means that we get a map $\\Sin^{\\mathscr{A}}_n(X)\\to \\Sin^{\\mathscr{A}}_{n-1}(X)$. Let $S^{\\mathscr{A}}_n(X)=\\Z[\\Sin^{\\mathscr{A}}_n(X)]$. Then there's a subchain complex $S^{\\mathscr{A}}_\\ast(X)$.\n\\begin{theorem}\nThe inclusion $S^\\mathscr{A}_\\ast(X)\\subseteq S_\\ast(X)$ is a chain homotopy equivalence.\n\\end{theorem}\n\\begin{corollary}\nIf $ H^\\mathscr{A}_\\ast(X):= H(S^\\mathscr{A}_\\ast(X))$, then $ H^\\mathscr{A}_\\ast(X)\\cong H_\\ast(X)$.\n\\end{corollary}\nWe'll do this on Monday.\n\\begin{example}\nIf $\\mathscr{A}=\\{A,B\\}$, then $\\overline{X-B}=X-\\mathrm{Int}(B)\\subseteq\\mathrm{Int}(A)$. Let $X-B=U$. Then $U\\subseteq \\overline{U}\\subseteq \\mathrm{Int}(A)\\subseteq A\\subseteq X$. This is an excision! So $U\\subseteq A\\subseteq X$ is an excision. But now, $(X-U,A-U)\\to (X,A)$ is an excision, but $(X-U,A-U)=(B,A\\cap B)$, so we have $(B,A\\cap B)\\to (X,A)$ is an excision. Now, also, $S^\\mathscr{A}_\\ast(X)=S_\\ast(A)+S_\\ast(B)$. Says he got off track, let me just write things out and explain in a moment.\n\\begin{equation*}\n\t\\xymatrix{0\\ar[r] & S_n(A)\\cap S_n(B)=S_n(A\\cap B)\\ar[r]\\ar[d] & S_n(B)\\ar[r]\\ar[d] & S_n(B,A\\cap B)\\ar[r]\\ar@{-->}[d]^\\cong & 0\\\\\n\t0\\ar[r] & S_n(A)\\ar[r] & S_n(A)+S_n(B)=S^\\mathscr{A}_n(X)\\ar[r] & S^\\mathscr{A}_n(X)/S_n(A)\\ar[r] & 0}\n\t\\end{equation*}\nBut we can consider $S_\\ast(X)/S_\\ast(A)=S_\\ast(X,A)$. By the lexseq + 5 lemma, this thing is isomorphic to $S^\\mathscr{A}_n(X)/S_n(A)$, so $S_\\ast(B,A\\cap B)\\cong S_\\ast(X,A)$ in homology. This is precisely the excision theorem. QED.\n\\end{example}\n", "meta": {"hexsha": "09fdd1e743b89efff69927a3b036046f4bb8dc37", "size": 5308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-11-locality-principle.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-11-locality-principle.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-11-locality-principle.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": 85.6129032258, "max_line_length": 506, "alphanum_fraction": 0.6588168802, "num_tokens": 2018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.6566180312033145}}
{"text": "\\def\\A{\\mathbb{A}}\n\\def\\k{\\mathbb{C}}\n\\def\\N{\\mathbb{N}}\n\\def\\R{\\mathbb{R}}\n\\def\\P{\\mathbb{P}}\n\\def\\ZZ{\\mathbb{Z}} \n\n\\title{Algorithms for the Toric Hilbert Scheme}\n\\titlerunning{Toric Hilbert Schemes}\n\\toctitle{Algorithms for the Toric Hilbert Scheme}\n\\author{Michael Stillman\n        % \\inst 1\n         \\and Bernd Sturmfels\n        % \\inst 2\n         \\and Rekha Thomas \n        % \\inst 3\n        }\n\\authorrunning{M. Stillman, B. Sturmfels, and R. Thomas}\n% \\institute{Cornell University, Department of Mathematics, Ithaca, NY 14853, USA\n%         \\and UC Berkeley, Department of Mathematics, Berkeley, CA 94720, USA\n%         \\and University of Washington, Department of Mathematics, Seattle, WA 98195, USA}\n\\maketitle\n\n\\begin{abstract}\nThe toric Hilbert scheme parametrizes all algebras isomorphic to a\ngiven semigroup algebra as a multigraded vector space. All components\nof the scheme are toric varieties, and among them, there is a fairly\nwell understood coherent component. It is unknown whether\ntoric Hilbert schemes are always connected. In this chapter we\nillustrate the use of \\Mtwo for exploring the structure of toric\nHilbert schemes. In the process we will encounter algorithms from\ncommutative algebra, algebraic geometry, polyhedral theory and\ngeometric combinatorics.\n\\end{abstract}\n\n\\section*{Introduction}\nConsider the multigrading of the polynomial ring $R =\n\\k[x_1,\\ldots,x_n]$ specified by a non-negative integer $d \\times\nn$-matrix $A = (a_1,\\ldots,a_n)$ such that degree $(x_i) = a_i \\in\n\\N^d$. This defines a decomposition $\\, R = \\bigoplus_{b \\in \\N A} R_b\n$, where $\\N A$ is the subsemigroup of $\\N^d$ spanned by\n$a_1,\\ldots,a_n$, and $R_b$ is the $\\k$-span of all monomials $\\, x^u\n= x_1^{u_1}\\cdots x_n^{u_n}$ with degree $Au = a_1 u_1 +\\cdots + a_n\nu_n = b$.  The {\\it \\ie{toric Hilbert scheme}} $\\,Hilb_A \n\\,$ parametrizes all $A$-homogeneous ideals $I \\subset R$ (ideals that\nare homogeneous under the multigrading of $R$ by $\\N A$) with the\nproperty that $(R/I)_b$ is a $1$-dimensional $\\k$-vector space, for all\n$b \\in \\N A$. We call such an ideal $I$ an $A$-{\\em graded}\\index{ideal!$A$-graded} ideal.\nEquivalently, $I$ is $A$-graded if it is $A$-homogeneous and $R/I$ is\nisomorphic as a multigraded vector space to the semigroup algebra $\\,\n\\k [ \\N A ] = R/I_A$, where $$I_A := \\,\\langle x^u - x^v \\, : \\, Au =\nAv \\rangle \\subset R$$ is the {\\it \\ie{toric ideal}} of $A$. An $A$-graded\nideal is generated by binomials and monomials in $R$ since, by\ndefinition, any two monomials $x^u$ and $x^v$ of the same degree $Au = \nAv$ must be $\\k$-linearly dependent modulo the ideal.\n\nWe recommend \\cite[\\S 4, \\S 10]{HS:St2} as an introductory reference for the \ntopics in this chapter.\nThe study of toric Hilbert schemes for $d=1$ goes back to\nArnold \\cite{HS:Arn} and Korkina et al.\\cite{HS:KPR}, and it was\nfurther developed by Sturmfels  (\\cite{HS:St1} and \\cite[\\S 10]{HS:St2}). \nPeeva and Stillman \\cite{HS:PS1} introduced the scheme structure \nthat gives the toric Hilbert scheme its universal property,\nand from this they derive a formula for the tangent space\nof a point on  $\\, Hilb_A $. Maclagan recently showed that the \nquadratic binomials in \\cite[\\S 5]{HS:St1} define the same scheme as the\ndeterminantal equations in \\cite{HS:PS1}.\nBoth of these systems of global equations are \ngenerally much too big for \npractical computations. Instead, most of our algorithms are based on\nthe local equations given by Peeva and Stillman in \\cite{HS:PS2}\nand the combinatorial approach of Maclagan and Thomas in \\cite{HS:MT}.\n\nWe begin with the computation of a toric ideal using \\Mtwo. Our\nrunning example throughout this chapter is the following $2 \\times\n5$-matrix:\n\\begin{equation}\n\\label{OurMatrix}\nA = \\left( \\begin{matrix}\n           1 & 1 & 1 & 1 & 1  \\\\ \n           0 & 1 & 2 & 7 & 8 \n\\end{matrix} \\right),\n\\end{equation}\nwhich we input to \\Mtwo as a list of lists of \nintegers.\n\\beginOutput\ni1 : A = \\{\\{1,1,1,1,1\\},\\{0,1,2,7,8\\}\\}; \\\\\n\\endOutput\nThe toric ideal of $A$ lives in the multigraded ring $R := \\k [a,b,c,d,e]$.\n\\beginOutput\ni2 : R = QQ[a..e,Degrees=>transpose A]; \\\\\n\\endOutput\n\\beginOutput\ni3 : describe R \\\\\n\\emptyLine\no3 = QQ [a, b, c, d, e, Degrees => \\{\\{1, 0\\}, \\{1, 1\\}, \\{1, 2\\}, \\{1, 7\\}, \\{1 $\\cdot\\cdot\\cdot$\\\\\n\\endOutput\n\nWe use Algorithm 12.3 in \\cite{HS:St2} to compute $I_A$. The first step is\nto find a matrix $B$ whose rows generate the lattice $ker_{\\ZZ}(A)\n:= \\{x \\in \\ZZ^n : Ax = 0 \\}$. \n\n\\beginOutput\ni4 : B = transpose syz matrix A \\\\\n\\emptyLine\no4 = | 1 -2 1  0 0 |\\\\\n\\     | 0 5  -6 1 0 |\\\\\n\\     | 0 6  -7 0 1 |\\\\\n\\emptyLine\n\\              3        5\\\\\no4 : Matrix ZZ  <--- ZZ\\\\\n\\endOutput\n\nAlthough in theory any basis of $ker_{\\ZZ}(A)$ will suffice, in\npractice it is more efficient to use a {\\em reduced} basis\n\\cite[\\S 6.2]{HS:Sch}, which can be computed using the {\\em \\ie{basis\nreduction}} package {\\tt LLL.m2} in \\Mtwo. The command {\\tt LLL} \nwhen applied to the output of {\\tt syz matrix A} will return a \nmatrix of the same size whose columns form a reduced lattice basis \nfor $ker_{\\ZZ}(A)$. The output appears in compressed form as follows:\n\n\\beginOutput\ni5 : load \"LLL.m2\"; \\\\\n\\endOutput\n\\beginOutput\ni6 : LLL syz matrix A \\\\\n\\emptyLine\no6 = | 0  1  2  |\\\\\n\\     | 1  -1 0  |\\\\\n\\     | -1 0  -3 |\\\\\n\\     | -1 -1 2  |\\\\\n\\     | 1  1  -1 |\\\\\n\\emptyLine\n\\              5        3\\\\\no6 : Matrix ZZ  <--- ZZ\\\\\n\\endOutput\n\nWe recompute $B$ using this package to get the following $3 \\times 5$ matrix.\n\\beginOutput\ni7 : B = transpose LLL syz matrix A \\\\\n\\emptyLine\no7 = | 0 1  -1 -1 1  |\\\\\n\\     | 1 -1 0  -1 1  |\\\\\n\\     | 2 0  -3 2  -1 |\\\\\n\\emptyLine\n\\              3        5\\\\\no7 : Matrix ZZ  <--- ZZ\\\\\n\\endOutput\n\nThe advantage of a reduced basis may not be apparent in small\nexamples. However, as the size of $A$ increases, it becomes\nincreasingly important for the termination of Algorithm 12.3 in \\cite{HS:St2}. (To\nappreciate this, consider the matrix (\\ref{non-normal}) from \nSection~4.)\n\nA row $b = b^+ - b^-$ of $B$ is then coded as the binomial\n$x^{b^+}-x^{b^-} \\in R$, and we let $J$ be the ideal generated by all \nsuch binomials. \n\n\\beginOutput\ni8 : toBinomial = (b,R) -> (\\\\\n\\          top := 1_R; bottom := 1_R;\\\\\n\\          scan(#b, i -> if b_i > 0 then top = top * R_i^(b_i)\\\\\n\\               else if b_i < 0 then bottom = bottom * R_i^(-b_i));\\\\\n\\          top - bottom); \\\\\n\\endOutput\n\n\\beginOutput\ni9 : J = ideal apply(entries B, b -> toBinomial(b,R)) \\\\\n\\emptyLine\n\\                                       2 2    3\\\\\no9 = ideal (- c*d + b*e, - b*d + a*e, a d  - c e)\\\\\n\\emptyLine\no9 : Ideal of R\\\\\n\\endOutput\nThe toric ideal equals $(J : (x_1 \\cdots x_n)^\\infty)$, which is \ncomputed via $n$ successive saturations as follows:\n\\beginOutput\ni10 : scan(gens ring J, f -> J = saturate(J,f))\\\\\n\\endOutput\n\nPutting the above pieces of code together, we get the following\nprocedure for computing the toric ideal of a matrix $A$.\n\n\\beginOutput\ni11 : toricIdeal = (A) -> (\\\\\n\\          n := #(A_0);  \\\\\n\\          R = QQ[vars(0..n-1),Degrees=>transpose A,MonomialSize=>16]; \\\\\n\\          B := transpose LLL syz matrix A;\\\\\n\\          J := ideal apply(entries B, b -> toBinomial(b,R));\\\\\n\\          scan(gens ring J, f -> J = saturate(J,f));\\\\\n\\          J\\\\\n\\          ); \\\\\n\\endOutput\n\nSee \\cite{HS:BLR}, \\cite{HS:HS} and \\cite[\\S 4, \\S 12]{HS:St2} for other\nalgorithms for computing toric ideals and various ideas for\nspeeding up the computation.\n\nIn our example, $I_A = \\langle\ncd-be,bd-ae,b^2-ac,a^2d^2-c^3e,c^4-a^3e,bc^3-a^3d,\nad^4-c^2e^3,d^6-ce^5 \\rangle$, which we now compute using this\nprocedure.  \n\n\\beginOutput\ni12 : I = toricIdeal A; \\\\\n\\emptyLine\no12 : Ideal of R\\\\\n\\endOutput\n \n\\beginOutput\ni13 : transpose mingens I\\\\\n\\emptyLine\no13 = \\{-2, -9\\}  | cd-be    |\\\\\n\\      \\{-2, -8\\}  | bd-ae    |\\\\\n\\      \\{-2, -2\\}  | b2-ac    |\\\\\n\\      \\{-4, -14\\} | a2d2-c3e |\\\\\n\\      \\{-4, -8\\}  | c4-a3e   |\\\\\n\\      \\{-4, -7\\}  | bc3-a3d  |\\\\\n\\      \\{-5, -28\\} | ad4-c2e3 |\\\\\n\\      \\{-6, -42\\} | d6-ce5   |\\\\\n\\emptyLine\n\\              8       1\\\\\no13 : Matrix R  <--- R\\\\\n\\endOutput\n\nThis ideal defines an embedding of\n$\\P^1$ as a degree $8$ curve into $\\P^4$. We will see in Section 3\nthat its toric Hilbert scheme $Hilb_A$ has a non-reduced component.\n\nThis chapter is organized into four sections and two appendices as\nfollows. The main goal in Section~1 is to describe an algorithm for\ngenerating all monomial $A$-graded ideals for a given $A$. These\nmonomial ideals are the vertices of the {\\em flip graph} of $A$ whose\nconnectivity is equivalent to the connectivity of $Hilb_A$. We\ndescribe how all neighbors of a given vertex of this graph can be\ncalculated. In Section~2, we explain the role of polyhedral geometry\nin the study of $Hilb_A$. Our first algorithm tests for {\\em\ncoherence} in a monomial $A$-graded ideal. We then show how to compute\nthe polyhedral complexes supporting $A$-graded ideals, which in turn\nrelate the flip graph of $A$ to the {\\em \\ie{Baues graph}} of $A$.  For\nunimodular matrices, these two graphs coincide and hence our method of\ncomputing the flip graph can be used to compute the Baues\ngraph. Section~3 explores the components of $Hilb_A$ via local\nequations around the torus fixed points of the scheme. We include a\ncombinatorial interpretation of these local equations from the point\nof view of integer programming.  The scheme $Hilb_A$ has a {\\em\ncoherent} component, which is examined in detail in Section~4. We prove\nthat this component is, in general, not normal and that its\nnormalization is the toric variety of the Gr\\\"obner fan of $I_A$. We\nconclude the chapter with two appendices, each containing one large\npiece of \\Mtwo code that we use in this chapter. Appendix \\ref{FMe} displays\ncode from the \\Mtwo file {\\tt polarCone.m2} that is used to convert a generator\nrepresentation of a polyhedron to an inequality representation and\nvice versa. Appendix \\ref{Mpor} displays code from the file {\\tt minPres.m2} used for computing minimal\npresentations of polynomial quotient rings. The main ingredient of\nthis package is the subroutine {\\tt removeRedundantVariables}, which is\nwhat we use in this chapter.\n\n\\section{Generating Monomial Ideals}\nWe start out by computing the {\\it \\ie{Graver basis}} $Gr_A$, which is the\nset of binomials in $I_A$ that are minimal with respect to the\npartial order defined by $$\\, x^u - x^v \\,\\leq\\, x^{u'} - x^{v'} \\quad \\iff\n\\quad \\hbox{ $x^u$ divides $x^{u'}$ \\ and \\ $x^v$ divides $x^{v'}$.}\n$$ The set $Gr_A$ is a {\\em universal Gr\\\"obner basis}\\index{Grobner basis@Gr\\\"obner basis!universal} of $I_A$ and\nhas its origins in the theory of integer programming \\cite{HS:Gra}. It\ncan be computed using \\cite[Algorithm 7.2]{HS:St2}, a \\Mtwo version of\nwhich is given below.\n\n\\beginOutput\ni14 : graver = (I) -> (\\\\\n\\          R := ring I;\\\\\n\\          k := coefficientRing R;\\\\\n\\          n := numgens R;\\\\\n\\          -- construct new ring S with 2n variables\\\\\n\\          S := k[Variables=>2*n,MonomialSize=>16];\\\\\n\\          toS := map(S,R,(vars S)_\\{0..n-1\\});\\\\\n\\          toR := map(R,S,vars R | matrix(R, \\{toList(n:1)\\}));\\\\\n\\          -- embed I in S\\\\\n\\          m := gens toS I;\\\\\n\\          -- construct the toric ideal of the Lawrence \\\\\n\\          -- lifting of A\\\\\n\\          i := 0;\\\\\n\\          while i < n do (\\\\\n\\              wts := join(toList(i:0),\\{1\\},toList(n-i-1:0));\\\\\n\\              wts = join(wts,wts);\\\\\n\\              m = homogenize(m,S_(n+i),wts);\\\\\n\\              i=i+1;\\\\\n\\              );\\\\\n\\         J := ideal m;\\\\\n\\         scan(gens ring J, f -> J = saturate(J,f));\\\\\n\\         -- apply the map toR to the minimal generators of J \\\\\n\\         f := matrix entries toR mingens J;\\\\\n\\         p := sortColumns f;\\\\\n\\         f_p) ;  \\\\\n\\endOutput\n   \n   The above piece of code first constructs a new polynomial ring $S$\n   in $n$ more variables than $R$. Assume $S = \\k [x_1, \\ldots, x_n,\n   y_1, \\ldots, y_n]$. The inclusion map {\\tt toS} $: R \\rightarrow\n   S$ embeds the toric ideal $I$ in $S$ and collects its generators in\n   the matrix {\\tt m}. A binomial $x^a - x^b$ lies in $Gr_A$ if and only\n   if $x^ay^b-x^by^a$ is a minimal generator of the toric ideal in $S$\n   of the $(d+n) \\times 2n$ matrix $$\\Lambda(A) := \\left (\n     \\begin{array}{cc} A & 0 \\\\ I_n & I_n \\end{array} \\right),$$ which\n   is called the {\\em \\ie{Lawrence lifting}} of $A$. Since $u \\in\n   ker_{\\ZZ}(A) \\Leftrightarrow (u,-u) \\in ker_{\\ZZ} (\\Lambda(A))$, we\n   use the {\\tt while}\\indexcmd{while} loop to homogenize the binomials in {\\tt m} with\n   respect to $\\Lambda(A)$, using the $n$ new variables in $S$. This\n   converts a binomial $x^a-x^b \\in$ {\\tt m} to the binomial\n   $x^ay^b-x^by^a$.  The ideal generated by these new binomials is\n   labeled $J$. As before, we can now successively saturate $J$\n   to get the toric ideal of $\\Lambda(A)$ in $S$. The image of the\n   minimal generators of this toric ideal under the map {\\tt toR}\n   $: S \\rightarrow R$ such that $x_i \\mapsto x_i$ and $y_i \\mapsto 1$\n   is precisely the Graver basis $Gr_A$. These binomials are the\n   entries of the matrix {\\tt f} and is output by the program.\n\nIn our example $Gr_A$ consists of $42$ binomials.\n\\beginOutput\ni15 : Graver = graver I \\\\\n\\emptyLine\no15 = | -cd+be -bd+ae -b2+ac -cd2+ae2 -a2d2+c3e -c4+a2bd -c4+a3e -bc3+ $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\n\\              1       42\\\\\no15 : Matrix R  <--- R\\\\\n\\endOutput\n \n\nReturning to the general case, an element $b $ of $\\N A$ is called a\n{\\it \\ie{Graver degree}} if there exists a binomial $x^u - x^v$ in the\nGraver basis $Gr_A$ such that $Au = Av = b$. If $b$ is a Graver degree\nthen the set of monomials in $R_b$ is the corresponding {\\it \\ie{Graver\n  fiber}}.  In our running example there are $37$ distinct Graver\nfibers. We define the {\\tt ProductIdeal} of $A$ as $PI := \n\\langle x^ax^b : x^a-x^b  \\in Gr_A \\rangle$. This ideal is contained in\nevery monomial ideal of $Hilb_A$ and hence no monomial in $PI$ can be\na standard monomial of a monomial $A$-graded ideal. Since our purpose\nin constructing Graver fibers is to use them to \ngenerate all monomial $A$-graded ideals, we will be content with\nlisting just the monomials in each Graver fiber that do not lie in\n$PI$.  Since $R$ is multigraded by $A$, we can obtain such a\npresentation of a Graver fiber by simply asking for the basis of $R$\nin degree $b$ modulo $PI$.  \n\n\\beginOutput\ni16 : graverFibers = (Graver) -> (\\\\\n\\           ProductIdeal := (I) -> ( trim ideal(\\\\\n\\              apply(numgens I, a -> ( \\\\\n\\                  f := I_a; leadTerm f * (leadTerm f - f))))); \\\\\n\\           PI := ProductIdeal ideal Graver; \\\\\n\\           R := ring Graver; \\\\\n\\           new HashTable from apply(\\\\\n\\               unique degrees source Graver,\\\\\n\\               d -> d => compress (basis(d,R) {\\char`\\%} PI) ));\\\\\n\\endOutput\n\n\\beginOutput\ni17 : fibers = graverFibers Graver \\\\\n\\emptyLine\no17 = HashTable\\{\\{2, 2\\} => | ac b2 |                                  \\}\\\\\n\\                \\{2, 8\\} => | ae bd |\\\\\n\\                \\{2, 9\\} => | be cd |\\\\\n\\                \\{3, 16\\} => | ae2 bde cd2 |\\\\\n\\                \\{4, 14\\} => | a2d2 c3e |\\\\\n\\                \\{4, 7\\} => | a3d bc3 |\\\\\n\\                \\{4, 8\\} => | a3e a2bd c4 |\\\\\n\\                \\{5, 10\\} => | a3ce a2b2e a2bcd ab3d c5 |\\\\\n\\                \\{5, 14\\} => | a3d2 ac3e b2c2e bc3d |\\\\\n\\                \\{5, 16\\} => | a3e2 a2cd2 ab2d2 c4e |\\\\\n\\                \\{5, 21\\} => | a2d3 bc2e2 c3de |\\\\\n\\                \\{5, 22\\} => | a2d2e abd3 c3e2 |\\\\\n\\                \\{5, 28\\} => | ad4 c2e3 |\\\\\n\\                \\{5, 7\\} => | a4d abc3 b3c2 |\\\\\n\\                \\{5, 8\\} => | a4e a3bd ac4 b2c3 |\\\\\n\\                \\{6, 12\\} => | a3c2e a2bc2d ab4e b5d c6 |\\\\\n\\                \\{6, 14\\} => | a4d2 a2c3e abc3d b4ce b3c2d |\\\\\n\\                \\{6, 18\\} => | a3ce2 a2b2e2 a2c2d2 b4d2 c5e |\\\\\n\\                \\{6, 21\\} => | a3d3 abc2e2 ac3de b3ce2 bc3d2 |\\\\\n\\                \\{6, 24\\} => | a3e3 a2cd2e abcd3 b3d3 c4e2 |\\\\\n\\                \\{6, 28\\} => | a2d4 ac2e3 b2ce3 c3d2e |\\\\\n\\                \\{6, 30\\} => | a2d2e2 acd4 b2d4 c3e3 |\\\\\n\\                \\{6, 35\\} => | ad5 bce4 c2de3 |\\\\\n\\                \\{6, 36\\} => | ad4e bd5 c2e4 |\\\\\n\\                \\{6, 42\\} => | ce5 d6 |\\\\\n\\                \\{6, 7\\} => | a5d a2bc3 b5c |\\\\\n\\                \\{6, 8\\} => | a5e a4bd a2c4 b4c2 |\\\\\n\\                \\{7, 14\\} => | a5d2 a3c3e a2bc3d b6e b5cd c7 |\\\\\n\\                \\{7, 21\\} => | a4d3 a2bc2e2 a2c3de abc3d2 b5e2 b3c2d2 |\\\\\n\\                \\{7, 28\\} => | a3d4 a2c2e3 ac3d2e b4e3 bc3d3 |\\\\\n\\                \\{7, 35\\} => | a2d5 abce4 ac2de3 b3e4 c3d3e |\\\\\n\\                \\{7, 42\\} => | ace5 ad6 b2e5 c2d2e3 |\\\\\n\\                \\{7, 49\\} => | be6 cde5 d7 |\\\\\n\\                \\{7, 7\\} => | a6d a3bc3 b7 |\\\\\n\\                \\{7, 8\\} => | a6e a5bd a3c4 b6c |\\\\\n\\                \\{8, 56\\} => | ae7 bde6 cd2e5 d8 |\\\\\n\\                \\{8, 8\\} => | a7e a6bd a4c4 b8 |\\\\\n\\emptyLine\no17 : HashTable\\\\\n\\endOutput\n\nFor example, the Graver degree $(8,8)$ corresponds to the Graver fiber\n$$ \\bigl\\{\\,\n\\underline{a^7 e}, \\, \\underline{a^6 b d},\\,  \\underline{a^4 c^4}, \\,\na^3 b^2 c^3,\\, a^2 b^4 c^2,\\,  a b^6 c, \\, \\underline{b^8} \\,\\bigr\\}.$$\nOur \\Mtwo code outputs only the four underlined monomials,\nin the format {\\tt  | a7e a6bd a4c4 b8 |}. The three non-underlined \nmonomials lie in the {\\tt ProductIdeal}. Graver degrees are\nimportant because of the following result.\n\n\\begin{lemma}[{\\cite[Lemma 10.5]{HS:St2}}]\nThe multidegree of any minimal generator of any ideal \n$I$ in $Hilb_A$ is a Graver degree.\n\\end{lemma}\n\nThe next step in constructing the toric Hilbert scheme is to compute\nall its fixed points with respect to the scaling action of the\n$n$-dimensional algebraic torus $(\\k^*)^n$. (The torus $(\\k^{\\ast})^n$\nacts on $R$ by scaling variables : $\\lambda \\mapsto \\lambda \\cdot x :=\n(\\lambda_1 x_1, \\ldots, \\lambda_n x_n)$.)  These fixed points are the\nmonomial ideals $M$ lying on $Hilb_A$.  Every term order $\\prec$ on\nthe polynomial ring $R$ gives such a monomial ideal: $M = in_\\prec(I_A\n)$, the initial ideal of the toric ideal $I_A$ with respect to\n$\\prec$. Two ideals $J$ and $J'$ are said to be {\\em torus\n  isomorphic}\\index{ideal!torus isomorphism}\nif $J = \\lambda \\cdot J'$ for some $\\lambda \\in (\\k^{\\ast})^n$. Any\nmonomial $A$-graded ideal that is torus isomorphic to an initial ideal\nof $I_A$ is said to be {\\em coherent}\\index{ideal!coherent}. In particular, the initial\nideals of $I_A$ are coherent and they can be computed by\n\\cite[Algorithm 3.6]{HS:St2} applied to $I_A$. A refinement and fast\nimplementation can be found in the software package {\\tt TiGERS} by\nHuber and Thomas \\cite{HS:HT}.\n\nNow we wish to compute all monomial ideals $M$ on $Hilb_A$ regardless\nof whether $M$ is coherent or not. For this we use the procedure\n{\\tt generateAmonos} given below. This procedure takes in the Graver\nbasis $Gr_A$ and records the numerator of the Hilbert series of $I_A$\nin {\\tt trueHS}. It then computes the Graver fibers of $A$, sorts them\nand calls the subroutine {\\tt selectStandard} to generate a\ncandidate for a monomial ideal on $Hilb_A$.\n\n\\beginOutput\ni18 : generateAmonos = (Graver) -> (\\\\\n\\           trueHS := poincare coker Graver;\\\\\n\\           fibers := graverFibers Graver;\\\\\n\\           fibers = apply(sort pairs fibers, last);\\\\\n\\           monos = \\{\\};\\\\\n\\           selectStandard := (fibers, J) -> (\\\\\n\\           if #fibers == 0 then (\\\\\n\\              if trueHS == poincare coker gens J\\\\\n\\              then (monos = append(monos,flatten entries mingens J));\\\\\n\\           ) else (\\\\\n\\              P := fibers_0;\\\\\n\\              fibers = drop(fibers,1);\\\\\n\\              P = compress(P {\\char`\\%} J);\\\\\n\\              nP := numgens source P; \\\\\n\\              -- nP is the number of monomials not in J.\\\\\n\\              if nP > 0 then (\\\\\n\\                 if nP == 1 then selectStandard(fibers,J)\\\\\n\\                 else (--remove one monomial from P,take the rest.\\\\\n\\                       P = flatten entries P;\\\\\n\\                       scan(#P, i -> (\\\\\n\\                            J1 := J + ideal drop(P,\\{i,i\\});\\\\\n\\                            selectStandard(fibers, J1)))));\\\\\n\\           ));\\\\\n\\           selectStandard(fibers, ideal(0_(ring Graver)));\\\\\n\\           ) ; \\\\\n\\endOutput\n\nThe arguments to the subroutine {\\tt selectStandard}\nare the Graver fibers given as a list of matrices and a monomial \nideal $J$ that should be included in every $A$-graded ideal \nthat we generate. The subroutine then loops through each Graver fiber, \nand at each step selects a standard monomial from that fiber and \nupdates the ideal $J$ by adding the other monomials in this fiber \nto $J$. The final $J$ output by the subroutine is the candidate ideal\nthat is sent back to {\\tt generateAmonos}. It is stored by the program \nif its Hilbert series agrees with that of $I_A$. \nAll the monomial $A$-graded ideals are stored in the list {\\tt monos}.\nBelow, we ask \\Mtwo for the cardinality of {\\tt monos} and its \nfirst ten elements.\n\\beginOutput\ni19 : generateAmonos Graver;\\\\\n\\endOutput\n\\beginOutput\ni20 : #monos \\\\\n\\emptyLine\no20 = 281\\\\\n\\endOutput\n\\beginOutput\ni21 : scan(0..9, i -> print toString monos#i) \\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, c^2*e^3, b*c^2*e^2, b*c*e^4, d^6\\}\\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, c^2*e^3, b*c^2*e^2, c*e^5, b*c*e^4, $\\cdot\\cdot\\cdot$\\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, c^2*e^3, b*c^2*e^2, c*e^5, b*c*e^4, $\\cdot\\cdot\\cdot$\\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, c^2*e^3, b*c^2*e^2, c*e^5, b*c*e^4, $\\cdot\\cdot\\cdot$\\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, c^2*e^3, b*c^2*e^2, d^6, a*d^5\\}\\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, b*c^2*e^2, a*d^4, d^6\\}\\\\\n\\{c*d, b*d, b^2, c^3*e, c^4, b*c^3, a*d^4, a^2*d^3, d^6\\}\\\\\n\\{c*d, b*d, b^2, a^2*d^2, c^4, b*c^3, a*d^4, d^6\\}\\\\\n\\{c*d, b*d, b^2, a^2*d^2, a^3*d, c^4, a*d^4, d^6\\}\\\\\n\\{c*d, b*d, b^2, a^3*e, a^2*d^2, a^3*d, a*d^4, d^6\\}\\\\\n\\endOutput\n\nThe monomial ideals (torus-fixed points) on $Hilb_A$ form the vertices\nof the {\\it \\ie{flip graph}} of $A$ whose edges correspond to the\ntorus-fixed curves on $Hilb_A$. This graph was introduced in \\cite{HS:MT}\nand provides structural information about $Hilb_A$.  The edges\nemanating from a monomial ideal $M$ can be constructed as follows: \nFor any minimal generator $x^u$ of $M$, let $x^v$ be the unique\nmonomial with $x^v \\not\\in M$ and $Au = Av$. Form the {\\it \\ie{wall ideal}},\nwhich is generated by $x^u - x^v$ and all minimal generators of $M$\nother than $x^u$, and let $M'$ be the initial monomial ideal of the\nwall ideal with respect to any term order $\\succ$ for which $x^v \\succ\nx^u$. It can be shown that $M'$ is the unique initial monomial ideal\nof the wall ideal that contains $x^v$.  If $M'$ lies on $Hilb_A$ then\n$\\{M, M'\\}$ is an edge of the flip graph. We now illustrate the \\Mtwo\nprocedure for computing all flip neighbors of a monomial $A$-graded\nideal.\n \n\\beginOutput\ni22 : findPositiveVector = (m,s) -> (\\\\\n\\           expvector := first exponents s - first exponents m;\\\\\n\\           n := #expvector;\\\\\n\\           i := first positions(0..n-1, j -> expvector_j > 0);\\\\\n\\           splice \\{i:0, 1, (n-i-1):0\\}\\\\\n\\           );\\\\\n\\endOutput\n\n\\beginOutput\ni23 : flips = (M) -> (\\\\\n\\           R := ring M;\\\\\n\\           -- store generators of M in monoms\\\\\n\\           monoms := first entries generators M;\\\\\n\\           result := \\{\\};\\\\\n\\           -- test each generator of M to see if it leads to a neighbor \\\\\n\\           scan(#monoms, i -> (\\\\\n\\             m := monoms_i;\\\\\n\\             rest := drop(monoms,\\{i,i\\});\\\\\n\\             b := basis(degree m, R);\\\\\n\\             s := (compress (b {\\char`\\%} M))_(0,0);\\\\\n\\             J := ideal(m-s) + ideal rest;\\\\\n\\             if poincare coker gens J == poincare coker gens M then (\\\\\n\\               w := findPositiveVector(m,s);\\\\\n\\               R1 := (coefficientRing R)[generators R, Weights=>w];\\\\\n\\               J = substitute(J,R1);\\\\\n\\               J = trim ideal leadTerm J;\\\\\n\\               result = append(result,J);\\\\\n\\               )));\\\\\n\\           result\\\\\n\\      );\\\\\n\\endOutput\n\nThe code above inputs a monomial $A$-graded ideal $M$ whose minimal\ngenerators are stored in the list {\\tt monoms}. The flip neighbors of\n$M$ will be stored in {\\tt result}. For each monomial $x^u$ in {\\tt\nmonoms} we need to test whether it yields a flip neighbor of $M$ or\nnot. At the $i$-th step of this loop, we let {\\tt m} be the $i$-th\nmonomial in {\\tt monoms}. The list {\\tt rest} contains all monomials\nin {\\tt monoms} except {\\tt m}. We compute the standard monomial {\\tt\ns} of $M$ of the same degree as $m$.  The wall ideal of $m-s$ is the\nbinomial ideal $J$ generated by $m-s$ and the monomials in {\\tt\nrest}. We then check whether $J$ is $A$-graded by comparing its\nHilbert series with that of $M$. (Alternately, one could check whether\n$M$ is the initial ideal of the wall ideal with respect to $m \\succ\ns$.) If this is the case, we use the subroutine {\\tt\nfindPositiveVector} to find a unit vector $w = (0,\\ldots,1,\\ldots,0)$\nsuch that $w \\cdot s > w \\cdot m$. The flip neighbor is then the\ninitial ideal of $J$ with respect to $w$ and it is stored in {\\tt\nresult}. The program outputs the minimal generators of each flip\nneighbor. Here is an example.\n \n\\beginOutput\ni24 : R = QQ[a..e,Degrees=>transpose A];\\\\\n\\endOutput\n\\beginOutput\ni25 : M = ideal(a*e,c*d,a*c,a^2*d^2,a^2*b*d,a^3*d,c^2*e^3,\\\\\n\\                c^3*e^2,c^4*e,c^5,c*e^5,a*d^5,b*e^6);\\\\\n\\emptyLine\no25 : Ideal of R\\\\\n\\endOutput\n\\beginOutput\ni26 : F = flips M\\\\\n\\emptyLine\n\\                              2 2   3    4   2 3   3 2     5     5     $\\cdot\\cdot\\cdot$\\\\\no26 = \\{ideal (a*e, c*d, a*c, a d , a d, c , c e , c e , a*d , c*e , b* $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no26 : List\\\\\n\\endOutput\n\\beginOutput\ni27 : #F\\\\\n\\emptyLine\no27 = 4\\\\\n\\endOutput\n\\beginOutput\ni28 : scan(#F, i -> print toString entries mingens F_i)\\\\\n\\{\\{a*e, c*d, a*c, a^2*d^2, a^3*d, c^4, c^2*e^3, c^3*e^2, a*d^5, c*e^5,  $\\cdot\\cdot\\cdot$\\\\\n\\{\\{c*d, a*e, a*c, a^2*d^2, a^2*b*d, a^3*d, c^3*e^2, c^4*e, c^5, a*d^4,  $\\cdot\\cdot\\cdot$\\\\\n\\{\\{a*e, c*d, a*c, a^2*d^2, a^3*d, a^2*b*d, c^2*e^3, c^3*e^2, c^4*e, c^5 $\\cdot\\cdot\\cdot$\\\\\n\\{\\{a*e, a*c, c*d, a^2*b*d, a^3*d, a^2*d^2, c^2*e^3, c^3*e^2, c^4*e, c^5 $\\cdot\\cdot\\cdot$\\\\\n\\endOutput\n\nIt is an open problem whether the toric Hilbert scheme $Hilb_A$ is\nconnected. Recent work in geometric combinatorics \\cite{HS:San} suggests\nthat this is probably false for some $A$. This result and its \nimplications for $Hilb_A$ will be discussed further in Section 2.\nThe following theorem of Maclagan and Thomas \\cite{HS:MT} reduces the  \nconnectivity of $Hilb_A$ to a combinatorial problem.\n\n\\begin{theorem} \nThe toric Hilbert scheme $Hilb_A$ is connected if and only if the \nflip graph of $A$ is connected.\n\\end{theorem}\n\nWe now have two algorithms for listing monomial ideals on $Hilb_A$.\nFirst, there is the {\\it \\ie{backtracking algorithm}} whose \\Mtwo\nimplementation was described above.  Second, there is the {\\it \\ie{flip\n  search algorithm}}, which starts with any coherent monomial ideal $M$\nand then constructs the connected component of $M$ in the flip graph\nof $A$ by carrying out local flips as above.  This procedure is also \nimplemented in {\\tt TiGERS} \\cite{HS:HT}. Clearly, the two algorithms\nwill produce the same answer if and only if $Hilb_A$ is connected. In\nother words, finding an example where $Hilb_A$ is disconnected is\nequivalent to finding a matrix $A$ for which the flip search algorithm\nproduces fewer monomial ideals than the backtracking algorithm.\n\n\\section{Polyhedral Geometry}\n\nAlgorithms from polyhedral geometry are essential in the study of the\ntoric Hilbert scheme. Consider the problem of deciding whether or not\na given monomial ideal $M$ in $Hilb_A$ is coherent.  This problem\ngives rise to a system of linear inequalities as follows: Let\n$x^{u_1}, \\ldots, x^{u_r}$ be the minimal generators of $M$, and let\n$x^{v_i}$ be the unique standard monomial with $A u_i = A v_i$. Then\n$M$ is coherent if and only if there exists a vector $w \\in \\R^n$ such\nthat $\\,w \\cdot (u_i - v_i) > 0\\,$ for $i =1,\\ldots,r$.  Thus the test\nfor coherence amounts to solving a {\\sl feasibility problem of linear\nprogramming}, and there are many highly efficient algorithms (based on\nthe simplex algorithms or interior point methods) available for this\ntask. For our experimental purposes, it is convenient to use the code\n{\\tt polarCone.m2}, given in Appendix \\ref{FMe}, which is based on the\n(inefficient but easy-to-implement) {\\em \\ie{Fourier-Motzkin elimination}}\nmethod (see \\cite{HS:Zie} for a description).  This code converts the\ngenerator representation of a polyhedron to its inequality\nrepresentation and vice versa. A simple example is given in Appendix\n\\ref{FMe}. In particular, given a Gr\\\"obner basis $\\mathcal G$ of $I_A$, the\nfunction {\\tt polarCone} will compute all the extreme rays of the {\\em\nGr\\\"obner cone\\index{Grobner cone@Gr\\\"obner cone}} $\\,\\{ w \\in \\R^n \\,: \\,w \\cdot (u_i - v_i) \\geq 0\\,$\nfor each $x^{u_i}-x^{v_i} \\in {\\mathcal G}\\}.$\n\nWe now show how to use \\Mtwo to decide whether a \nmonomial $A$-graded ideal $M$ is coherent. The first step in \nthis calculation is to compute all the standard monomials of $M$ \nof the same degree as the minimal generators of $M$. We do this \nusing the procedure {\\tt stdMonomials}.\n\n\\beginOutput\ni29 : stdMonomials = (M) -> (\\\\\n\\           R := ring M;\\\\\n\\           RM := R/M;\\\\\n\\           apply(numgens M, i -> (\\\\\n\\                 s := basis(degree(M_i),RM); lift(s_(0,0), R)))\\\\\n\\           ); \\\\\n\\endOutput\n\nAs an example, consider the following monomial $A$-graded ideal.\n\n\\beginOutput\ni30 : R = QQ[a..e,Degrees => transpose A ]; \\\\\n\\endOutput\n\\beginOutput\ni31 : M = ideal(a^3*d, a^2*b*d, a^2*d^2, a*b^3*d, a*b^2*d^2, a*b*d^3, \\\\\n\\                a*c, a*d^4, a*e, b^5*d, b^4*d^2, b^3*d^3, b^2*d^4, \\\\\n\\                b*d^5, b*e, c*e^5); \\\\\n\\emptyLine\no31 : Ideal of R\\\\\n\\endOutput\n\\beginOutput\ni32 : toString stdMonomials M \\\\\n\\emptyLine\no32 = \\{b*c^3, c^4, c^3*e, c^5, c^4*e, c^3*e^2, b^2, c^2*e^3, b*d, c^6, $\\cdot\\cdot\\cdot$\\\\\n\\endOutput\n\nFrom the pairs $x^u,x^v$ of minimal generators $x^u$ and\nthe corresponding standard monomials $x^v$, the function {\\tt inequalities}\ncreates a matrix whose columns are the vectors $u-v$. \n\n\\beginOutput\ni33 : inequalities = (M) -> (\\\\\n\\              stds := stdMonomials(M);\\\\\n\\              transpose matrix apply(numgens M, i -> (\\\\\n\\                  flatten exponents(M_i) - \\\\\n\\                      flatten exponents(stds_i)))); \\\\\n\\endOutput\n\\beginOutput\ni34 : inequalities M\\\\\n\\emptyLine\no34 = | 3  2  2  1  1  1  1  1  1  0  0  0  0  0  0  0  |\\\\\n\\      | -1 1  0  3  2  1  -2 0  -1 5  4  3  2  1  1  0  |\\\\\n\\      | -3 -4 -3 -5 -4 -3 1  -2 0  -6 -5 -4 -3 -2 -1 1  |\\\\\n\\      | 1  1  2  1  2  3  0  4  -1 1  2  3  4  5  -1 -6 |\\\\\n\\      | 0  0  -1 0  -1 -2 0  -3 1  0  -1 -2 -3 -4 1  5  |\\\\\n\\emptyLine\n\\               5        16\\\\\no34 : Matrix ZZ  <--- ZZ\\\\\n\\endOutput\n\nIt is convenient to simplify the output of the next procedure \nusing the following program to divide an integer vector \nby the g.c.d. of its components. We also load {\\tt polarCone.m2},\nwhich is needed in {\\tt decideCoherence} below.\n\n\\beginOutput\ni35 : primitive := (L) -> (\\\\\n\\           n := #L-1; g := L#n;\\\\\n\\           while n > 0 do (n = n-1; g = gcd(g, L#n););\\\\\n\\           if g === 1 then L else apply(L, i -> i // g));\\\\\n\\endOutput\n\n\\beginOutput\ni36 : load \"polarCone.m2\" \\\\\n\\endOutput\n\n\\beginOutput\ni37 : decideCoherence = (M) -> (\\\\\n\\           ineqs := inequalities M;\\\\\n\\           c := first polarCone ineqs;\\\\\n\\           m := - sum(numgens source c, i -> c_\\{i\\});\\\\\n\\           prods := (transpose m) * ineqs;\\\\\n\\           if numgens source prods != numgens source compress prods\\\\\n\\           then false else primitive (first entries transpose m)); \\\\\n\\endOutput\n \nLet $K$ be the cone $\\{x \\in {\\mathbb R}^n : g \\cdot x \\leq 0$,\nfor all columns $g$ of {\\tt ineqs} \\}. The command {\\tt\npolarCone ineqs} computes a pair of matrices $P$ and $Q$ such\nthat $K$ is the sum of the cone generated by the columns of $P$\nand the subspace generated by the columns of $Q$. Let {\\tt m} be\nthe negative of the sum of the columns of $P$. Then {\\tt m} lies\nin the cone $-K$. The entries in the matrix {\\tt prods} are the\ndot products $g \\cdot m$ for each column $g$ of {\\tt ineqs}.\nSince $M$ is a monomial $A$-graded ideal, it is coherent if and\nonly if $K$ is full dimensional, which is the case if and only if\nno dot product $g \\cdot m$ is zero. This is the conditional in\nthe {\\tt if .. then} statement of {\\tt decideCoherence}. If $M$\nis coherent, the program outputs the primitive representative of\n{\\tt m} and otherwise returns the boolean {\\tt false}. Notice that \nif $M$ is coherent, the cone $-K$ is the Gr\\\"obner cone corresponding \nto $M$ and the vector {\\tt m} is a weight vector $w$ such that\n$in_w(I_A) = M$. We now test whether the ideal $M$ from \nline {\\tt i29} is coherent.\n\n\\beginOutput\ni38 : decideCoherence M\\\\\n\\emptyLine\no38 = \\{0, 0, 1, 15, 18\\}\\\\\n\\emptyLine\no38 : List\\\\\n\\endOutput\n\nHence, $M$ is coherent: it is the initial ideal with respect to the \nweight vector $w = (0,0,1,15,18)$ of the toric ideal in our running\nexample (\\ref{OurMatrix}). Here is one of the 55 noncoherent\nmonomial $A$-graded ideals of this matrix.\n\n\\beginOutput\ni39 : N = ideal(a*e,c*d,a*c,c^3*e,a^3*d,c^4,a*d^4,a^2*d^3,c*e^5,\\\\\n\\                 c^2*e^4,d^7);\\\\\n\\emptyLine\no39 : Ideal of R\\\\\n\\endOutput\n\\beginOutput\ni40 : decideCoherence N\\\\\n\\emptyLine\no40 = false\\\\\n\\endOutput\n\nIn the rest of this section, we study the connection between\n$A$-graded ideals and polyhedral complexes defined on $A$.  This study\nrelates the flip graph of the toric Hilbert scheme to the Baues\ngraph of the configuration $A$.                  (See \\cite{HS:Reiner} for a\nsurvey of the Baues problem and its relatives).  Let $pos(A) := \\{ Au\n: u \\in \\R^n, u \\geq 0 \\}$ be the cone generated by the columns of $A$\nin $\\R^d$. A {\\em \\ie{polyhedral subdivision}} $\\Delta$ of $A$ is a\ncollection of full dimensional subcones $pos(A_{\\sigma})$ of $pos(A)$\nsuch that the union of these subcones is $pos(A)$ and the intersection\nof any two subcones is a face of each.  Here $A_{\\sigma} := \\{a_j : j\n\\in \\sigma \\subseteq \\{1,\\ldots,n\\} \\}$.  It is customary to identify \n$\\Delta$ with the set of sets $\\{ \\sigma : pos(A_{\\sigma}) \\in \\Delta\n\\}$. If every cone in the \nsubdivision $\\Delta$ is simplicial (the number of extreme rays of the\ncone equals the dimension of the cone), we say that $\\Delta$ is a {\\em\n  \\ie{triangulation}} of $A$. The simplicial complex corresponding\nto a triangulation $\\Delta$ is uniquely obtained by including in\n$\\Delta$ all the subsets of every $\\sigma \\in \\Delta$. We refer the\nreader to \\cite[\\S 8]{HS:St2} for more details.\n\nFor each $\\sigma \\in \\Delta$, let $I_{\\sigma}$ be the prime ideal \nthat is the sum of the toric ideal $I_{A_{\\sigma}}$ and the monomial \nideal $\\langle x_j :j \\not \\in \\sigma \\rangle$. Recall that two\nideals $J$ and $J'$ are said to be \n{\\em torus isomorphic} if $J = \\lambda \\cdot J'$ for some $\\lambda \\in \n(\\k^{\\ast})^n$. The following theorem shows that polyhedral\nsubdivisions of $A$ are related to $A$-graded ideals via their \nradicals.\n\n\\begin{theorem}[Theorem~10.10 {\\cite[\\S 10]{HS:St2}}]\\label{polysubdivisions}\n  If $I$ is an $A$-graded ideal, then there exists a polyhedral\n  subdivision $\\Delta(I)$ of $A$ such that $\\sqrt{I} = \\cap_{\\sigma\n    \\in \\Delta(I)} J_{\\sigma}$ where each component $J_{\\sigma}$ is a\n  prime ideal that is torus isomorphic to $I_{\\sigma}$.\n\\end{theorem}\n\nWe say that $\\Delta(I)$ supports the $A$-graded ideal $I$.\nWhen $M$ is a monomial $A$-graded ideal, $\\Delta(M)$ is a \ntriangulation of $A$. In particular, if $M$ is coherent (i.e, $M =\nin_w(I_A)$ for some weight vector $w$), then $\\Delta(M)$ is the {\\em\n  regular} or {\\em coherent} triangulation\\index{triangulation!regular} of $A$ induced by $w$\n\\cite[\\S 8]{HS:St2}. The coherent triangulations of $A$ are in bijection\nwith the vertices of the {\\em \\ie{secondary polytope}} of $A$ \\cite{HS:BFS},\n\\cite{HS:GKZ}.  \n\nIt is convenient to represent a triangulation $\\Delta$ of $A$ by its \n{\\em Stanley-Reisner} ideal\\index{Stanley-Reisner ideal} $I_{\\Delta} := \\langle x_{i_1}x_{i_2}\n\\cdots x_{i_k} : \\{ i_1, i_2, \\ldots, i_k \\}$ is a non-face of  \n$\\Delta \\rangle$. If $M$ is a monomial $A$-graded ideal,\nTheorem~\\ref{polysubdivisions} implies that $I_{\\Delta(M)}$ is the \nradical of $M$. Hence we will represent triangulations \nof $A$ by their Stanley-Reisner ideals. As seen below, the matrix in\nour running example has eight distinct triangulations \ncorresponding to the eight distinct radicals of the 281 monomial \n$A$-graded ideals computed earlier. All eight are coherent.\n\n\\medskip\n\n\\begin{tabular}{lll}\n{$\\{\\{1,2\\},\\{2,3\\},\\{3,4\\},\\{4,5\\}\\}$}\n&\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle ac, ad, ae, bd, be, ce\n\\rangle$ \\\\  \n{$\\{\\{1,3\\},\\{3,4\\},\\{4,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,&\n$\\langle b, ad, ae, ce \\rangle$ \\\\  \n{$\\{\\{1,2\\},\\{2,4\\},\\{4,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,&\n$\\langle c, ad, ae, be \\rangle$ \\\\ \n{$\\{\\{1,2\\},\\{2,3\\},\\{3,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,&\n$\\langle d, ac, ae, be \\rangle$ \\\\  \n{$\\{\\{1,3\\},\\{3,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle\nb, d, ae \\rangle$ \\\\ \n{$\\{\\{1,4\\},\\{4,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle\nb, c, ae \\rangle$ \\\\  \n{$\\{\\{1,2\\},\\{2,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle\nc, d, ae \\rangle$ \\\\ \n{$\\{\\{1,5\\}\\}$} &\\,\\,\\,\\,$\\leftrightarrow$\\,\\,\\,\\,& $\\langle b, c, d\n\\rangle$   \n\\end{tabular}\n\n\\medskip\n\nThe Baues graph of $A$ is a graph on all the triangulations of\n$A$ in which two triangulations are adjacent if they differ by a\nsingle {\\em \\ie{bistellar flip}} \\cite{HS:Reiner}. The {\\em \\ie{Baues problem}} from\ndiscrete geometry asked whether the Baues graph of a point\nconfiguration can be disconnected for some $A$. Every edge of the\nsecondary polytope of $A$ corresponds to a bistellar flip, and hence\nthe subgraph of the Baues graph that is induced by the coherent\ntriangulations of $A$ is indeed connected: it is precisely the edge\ngraph of the secondary polytope of $A$.  The Baues problem was\nrecently settled by Santos \\cite{HS:San} who gave an example of a six\ndimensional point configuration with $324$ points for which there is\nan isolated (necessarily non-regular) triangulation.\n\nSantos' configuration would also have a disconnected flip graph and hence\na disconnected toric Hilbert scheme if it were true that {\\em every} \ntriangulation of $A$ supports a monomial $A$-graded\nideal. However, Peeva has shown that this need not be the case\n(Theorem~10.13 in \\cite[\\S 10]{HS:St2}). Hence, the map from the set of\nall monomial $A$-graded ideals to the set of all triangulations of\n$A$ that sends $M \\mapsto \\Delta(M)$ is not always\nsurjective, and it is unknown whether Santos' $6 \\times 324$ \nconfiguration has a disconnected toric Hilbert scheme.  \n\nThus, even though one cannot in general conclude that the existence of\na disconnected Baues graph implies the existence of a disconnected\nflip graph, there is an important special situation in which such a\nconclusion is possible. We call an integer matrix $A$ of full row rank\n{\\em unimodular}\\index{matrix!unimodular} if the absolute value of each of its non-zero maximal\nminors is the same constant. A matrix $A$ is unimodular if and only if\nevery monomial $A$-graded ideal is square-free. For a unimodular\nmatrix $A$, the Baues graph of $A$ coincides with the flip graph of\n$A$. As you might expect, Santos' configuration is not unimodular.\n\n\\begin{theorem}[Lemma~10.14 {\\cite[\\S 10]{HS:St2}}]\\label{unimodular}\nIf $A$ is unimodular, then each triangulation of $A$ supports a unique\n(square-free) monomial $A$-graded ideal. In this case, a monomial\n$A$-graded ideal is coherent if and only if the triangulation\nsupporting it is coherent.\n\\end{theorem}\n\nUsing Theorem~\\ref{unimodular} we can compute all the triangulations\nof a unimodular matrix since they are precisely the polyhedral\ncomplexes supporting monomial $A$-graded ideals. Then we could\nenumerate the connected component of a coherent monomial $A$-graded\nideal in the flip graph of $A$ to decide whether the Baues/flip graph\nis disconnected.\n\nLet $\\Delta_r$ be the standard $r$-simplex that \nis the convex hull of the $r+1$ unit vectors in $\\R^{r+1}$, and let \n$A(r,s)$ be the $(r+s+2) \\times (r+1)(s+1)$ matrix whose columns \nare the products of the vertices of $\\Delta_r$ and $\\Delta_s$. All \nmatrices of type $A(r,s)$ are unimodular. From the\nproduct of two triangles we get $$A(2,2) := \n\\left ( \\begin{array}{ccccccccc}\n1&1&1&0&0&0&0&0&0\\\\\n0&0&0&1&1&1&0&0&0\\\\\n0&0&0&0&0&0&1&1&1\\\\\n1&0&0&1&0&0&1&0&0\\\\\n0&1&0&0&1&0&0&1&0\\\\\n0&0&1&0&0&1&0&0&1 \\end{array} \\right ).$$\nWe can now use our algebraic algorithms to compute all\nthe triangulations of $A(2,2)$. Since \\Mtwo requires the first entry \nof the degree of every variable in a ring to be positive, we use \nthe following matrix with the same row space as $A(2,2)$ for our \ncomputation:\n\n\\beginOutput\ni41 : A22 =\\\\\n\\        \\{\\{1,1,1,1,1,1,1,1,1\\},\\{0,0,0,1,1,1,0,0,0\\},\\{0,0,0,0,0,0,1,1,1\\},\\\\\n\\        \\{1,0,0,1,0,0,1,0,0\\},\\{0,1,0,0,1,0,0,1,0\\},\\{0,0,1,0,0,1,0,0,1\\}\\}; \\\\\n\\endOutput\n\\beginOutput\ni42 : I22 = toricIdeal A22\\\\\n\\emptyLine\no42 = ideal (f*h - e*i, c*h - b*i, f*g - d*i, e*g - d*h, c*g - a*i, b* $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no42 : Ideal of R\\\\\n\\endOutput\nThe ideal {\\tt I22} is generated by the 2 by 2 minors of a 3 by 3\nmatrix of indeterminates.  This is the ideal of $\\P^2 \\times \\P^2$\nembedded in $\\P^8$ via the Segre embedding.\n\\beginOutput\ni43 : Graver22 = graver I22;\\\\\n\\emptyLine\n\\              1       15\\\\\no43 : Matrix R  <--- R\\\\\n\\endOutput\n\\beginOutput\ni44 : generateAmonos(Graver22);\\\\\n\\endOutput\n\\beginOutput\ni45 : #monos\\\\\n\\emptyLine\no45 = 108\\\\\n\\endOutput\n\\beginOutput\ni46 : scan(0..9,i->print toString monos#i) \\\\\n\\{f*h, c*h, f*g, e*g, c*g, b*g, c*e, c*d, b*d\\}\\\\\n\\{f*h, d*h, c*h, f*g, c*g, b*g, c*e, c*d, b*d\\}\\\\\n\\{d*i, f*h, d*h, c*h, c*g, b*g, c*e, c*d, b*d\\}\\\\\n\\{e*i, c*h, f*g, e*g, c*g, b*g, c*e, c*d, b*d\\}\\\\\n\\{e*i, d*i, c*h, e*g, c*g, b*g, c*e, c*d, b*d\\}\\\\\n\\{e*i, d*i, d*h, c*h, c*g, b*g, c*e, c*d, b*d\\}\\\\\n\\{f*h, c*h, f*g, e*g, c*g, b*g, c*e, a*e, c*d\\}\\\\\n\\{e*i, c*h, f*g, e*g, c*g, b*g, c*e, a*e, c*d, b*d*i\\}\\\\\n\\{e*i, c*h, f*g, e*g, c*g, b*g, c*e, a*e, c*d, a*f*h\\}\\\\\n\\{e*i, d*i, c*h, e*g, c*g, b*g, c*e, a*e, c*d\\}\\\\\n\\endOutput\n\nThus there are 108 monomial $A(2,2)$-graded ideals and \n{\\tt decideCoherence} will check that all of them \nare coherent. Since $A(2,2)$ is unimodular, each monomial \n$A(2,2)$-graded ideal is square-free and is hence \nradical. These 108 ideals represent the 108 triangulations of \n$A(2,2)$ and we have listed ten of them above.\nThe flip graph (equivalently, Baues graph) of $A(2,2)$ is connected.\nHowever, it is unknown whether the Baues graph of $A(r,s)$ is \nconnected for all values of $(r,s)$.\n\n\\section{Local Equations}\nConsider the reduced Gr\\\"obner basis of a toric ideal $I_A$ for a\nterm order $w$:\n\\begin{equation}\n\\label{GrobnerBasis} \\bigl\\{ \\,\n x^{u_1} -  x^{v_1} \\, , \\,\\, x^{u_2} -  x^{v_2} \\,, \\,\\, \\ldots \\, , \\,\\,\nx^{u_r} -  x^{v_r}\\, \\bigr\\} .\n\\end{equation}\nThe initial ideal $\\,M = in_w(I_A) = \\langle x^{u_1}, x^{u_2}, \\ldots,\nx^{u_r} \\rangle \\,$ is a coherent monomial $A$-graded ideal. In\nparticular, it is a $(\\k^*)^n$-fixed point on the toric Hilbert scheme\n$Hilb_A$.  We shall explain a method, due to Peeva and Stillman\n\\cite{HS:PS2}, for computing local equations of $Hilb_A$ around such a\nfixed point.  A variant of this method also works for computing the\nlocal equations around a non-coherent monomial ideal $M$, but that\nvariant involves local algebra, specifically Mora's tangent cone\nalgorithm, which is not yet fully implemented in \\Mtwo. See \\cite{HS:PS2}\nfor details.\n\nWe saw how to compute the flip graph of $A$ in Section~1. The vertices\nof this graph are the $(\\k^*)^n$-fixed points $M$ and its edges\ncorrespond to the $(\\k^*)^n$-fixed curves.  By computing and\ndecomposing the local equations around each $M$, we get a complete\ndescription of the scheme $Hilb_A$.\n\nThe first step is to introduce a new variable $ \\, z_i \\,$ for each \nbinomial in our Gr\\\"obner basis (\\ref{GrobnerBasis}) and to consider \nthe following $r$ binomials:\n\\begin{equation}\n\\label{FlatFamily}\n x^{u_1} -  z_1 \\cdot x^{v_1} \\,, \\,\\,\n x^{u_2} - z_2  \\cdot x^{v_2} \\,,\\, \\, \\ldots \\, ,\n\\,\\, x^{u_r} -   z_r \\cdot x^{v_r} \n\\end{equation}\nin the polynomial ring $\\k[x,z]$ in  $n+r$ indeterminates.\nThe term order $w$ can be extended to an elimination term order\nin $\\k[x,z]$ so that $x^{u_i}$ is the leading term of\n$ x^{u_i} -  z_i \\cdot x^{v_i} $ for all $i$. \nWe compute the minimal first syzygies\nof the monomial ideal $M$, and form the\ncorresponding $S$-pairs of binomials in (\\ref{FlatFamily}).\nFor each $S$-pair\n$$\n\\frac{lcm(x^{u_i},x^{u_j})}{x^{u_i}} \\cdot (x^{u_i} - z_i \\cdot\nx^{v_i} ) \\,\\,\\, - \\,\\,\\, \\frac{lcm(x^{u_i},x^{u_j})}{x^{u_j}} \\cdot\n(x^{u_j} - z_j \\cdot x^{v_j}) $$\nwe compute a normal form with respect\nto (\\ref{FlatFamily}) using the extended term order $w$.  The result\nis a binomial in $\\k[x,z]$ that factors as \n$$  x^\\alpha \\cdot z^\\beta \\cdot  ( z^\\gamma - z^\\delta ) , $$\nwhere $\\alpha \\in \\N^n$ and $\\beta,\\gamma,\\delta \\in \\N^r$.\nNote that this normal form is not unique but depends on our\nchoice of a reduction path.\nLet $J_M$ denote the ideal in $\\k[z_1 , \\ldots, z_r]$ generated by all \nbinomials $\\, z^\\beta \\cdot  ( z^\\gamma - z^\\delta ) \\,$\ngotten from normal forms of all the $S$-pairs considered above.\n\n\\begin{proposition}[\\cite{HS:PS2}]\\label{localeqns}\nThe ideal $J_M$ is independent of the reduction paths chosen.\nIt defines a subscheme of $\\k^r$ isomorphic to\nan affine open neighborhood of the point $M$ on \nthe toric Hilbert scheme $Hilb_A$.\n\\end{proposition}\n\nWe apply this technique to compute a particularly interesting affine\nchart of $Hilb_A$ for our running example.\nConsider the following set of $13$ binomials:\n\\begin{eqnarray*}\n& \\bigl\\{ \\,a e - z_1 b d ,  \\,\n c d - z_2 b e , \\,\n a c - z_3 b^2 , \\,\n a^2 d^2 - z_4 c^3 e , \\,\n a^2 b d - z_5 c^4 , \\\\ &\n a^3 d - z_6 b c^3 , \\,\n c^2 e^3 - z_7 a d^4 , \\, \n c^3 e^2 - z_8 a b d^3 , \\,\n c^4 e - z_9 a b^2 d^2 , \\\\ &\n c^5 - z_{10} a b^3 d , \\,\n c e^5 - z_{11} d^6 , \\,\n a d^5 - z_{12} b c e^4 , \\,\n b e^6 - z_{13} d^7  \\, \\bigr\\}.\n\\end{eqnarray*}\nIf we set $\\, z_1 = z_2 = \\cdots = z_{13} = 1\\,$\nthen we get a generating set for the toric ideal $I_A$.\nThe $13$ monomials obtained by setting\n$\\, z_1 = z_2 = \\cdots = z_{13} = 0 \\,$\ngenerate the initial monomial ideal $ M = in_w (I_A)$\nwith respect to the weight vector $w = (9, 3, 5, 0, 0)$.\nThus $M$ is one of the $226$ coherent monomial \n$A$-graded ideals of our running example. The above set of \n13 binomials in $\\k[x,z]$ give the universal family \nfor $Hilb_A$ around this $M$.\n\nThe local chart of $Hilb_A$ around the point $M$\nis a subscheme of affine space $\\k^{13}$ with coordinates \n$z_1, \\ldots, z_{13}$, whose\ndefining equations are obtained as follows: \nExtend the weight vector $w$ by assigning\nweight zero to all variables $z_i$, so that\nthe first term in each of the above $13$ binomials\nis the leading term. For each pair of binomials corresponding to a  \nminimal syzygy of $M$, form their $S$-pair and then reduce it to a \nnormal form with respect to the $13$ binomials above.\nFor instance,\n$$\nS \\bigl(\n c^5 - z_{10} a b^3 d , \n c e^5 - z_{11} d^6 \\bigr)\n\\, = \\,\n z_{11} c^4 d^6  - z_{10} a b^3 d e^5\n\\, \\longrightarrow \\,\nb^4 d^2 e^4 \\cdot (z_2^4 z_{11} - z_1 z_{10}).\n$$\nEach such normal form is a monomial in $a,b,c,d,e$ times a binomial in\n$z_1, \\ldots, z_{13}$.  The set of all these binomials, in the\n$z$-variables, generates the ideal $J_M$ of local equations of\n$Hilb_A$ around $M$.  In our example, $J_M$ is generated by $27$\nnonzero binomials.  This computation can be done in \\Mtwo using the\nprocedure {\\tt localCoherentEquations}.\n\n\\beginOutput\ni47 : localCoherentEquations = (IA) -> (\\\\\n\\           -- IA is the toric ideal of A living in a ring equipped\\\\\n\\           -- with weight order w, if we are computing the local \\\\\n\\           -- equations about the initial ideal of IA w.r.t. w.\\\\\n\\           R := ring IA;\\\\\n\\           w := (monoid R).Options.Weights;\\\\\n\\           M := ideal leadTerm IA;\\\\\n\\           S := first entries ((gens M) {\\char`\\%} IA);\\\\\n\\           -- Make the universal family J in a new ring.\\\\\n\\           nv := numgens R; n := numgens M;\\\\\n\\           T = (coefficientRing R)[generators R, z_1 .. z_n, \\\\\n\\                                   Weights => flatten splice\\{w, n:0\\},\\\\\n\\                                   MonomialSize=>16];\\\\\n\\           M = substitute(generators M,T);\\\\\n\\           S = apply(S, s -> substitute(s,T));\\\\\n\\           J = ideal apply(n, i -> \\\\\n\\                     M_(0,i) - T_(nv + i) * S_i);\\\\\n\\           -- Find the ideal Ihilb of local equations about M:\\\\\n\\           spairs := (gens J) * (syz M);\\\\\n\\           g := forceGB gens J;\\\\\n\\           B = (coefficientRing R)[z_1 .. z_n,MonomialSize=>16];\\\\\n\\           Fones := map(B,T, matrix(B,\\{splice \\{nv:1\\}\\}) | vars B);\\\\\n\\           Ihilb := ideal Fones (spairs {\\char`\\%} g);\\\\\n\\           Ihilb\\\\\n\\           );\\\\\n\\endOutput\n \n     \nSuppose we wish to calculate the local equations about $M =\nin_w(I_A)$.  The input to {\\tt localCoherentEquations} is the\ntoric ideal $I_A$ living in a polynomial ring equipped with the \nweight order specified by $w$. This is done as follows:\n\n\\beginOutput\ni48 : IA = toricIdeal A;\\\\\n\\emptyLine\no48 : Ideal of R\\\\\n\\endOutput\n\\beginOutput\ni49 : Y = QQ[a..e, MonomialSize => 16,\\\\\n\\                  Degrees => transpose A, Weights => \\{9,3,5,0,0\\}];\\\\\n\\endOutput\n\\beginOutput\ni50 : IA = substitute(IA,Y);\\\\\n\\emptyLine\no50 : Ideal of Y\\\\\n\\endOutput\n\nThe initial ideal $M$ is calculated in the third line of the\nalgorithm, and {\\tt S} stores the standard monomials of $M$ of the\nsame degrees as the minimal generators of $M$. We could have\ncalculated {\\tt S} using our old procedure {\\tt stdMonomials} but this\ninvolves computing the monomials in $R_b$ for various values of $b$,\nwhich can be slow on large examples. As by-products, {\\tt\n  localCoherentEquations} also gets {\\tt J}, the ideal of the\nuniversal family for $Hilb_A$ about $M$, the ring {\\tt T} of this\nideal, and the ring {\\tt B} of {\\tt Ihilb}, which is the ideal of the\naffine patch of $Hilb_A$ about $M$. The matrix {\\tt spairs} contains\nall the $S$-pairs between generators of {\\tt J} corresponding to the\nminimal first syzygies of $M$. The command {\\tt forceGB} is used to\ndeclare the generators of {\\tt J} to be a Gr\\\"obner basis, and {\\tt\n  Fones} is the ring map from {\\tt T} to {\\tt B} that sends each of\n$a,b,c,d,e$ to one and the $z$ variables to themselves.  The columns\nof the matrix {\\tt (spairs \\% g)} are the normal forms of the\npolynomials in {\\tt spairs} with respect to the forced Gr\\\"obner basis\n{\\tt g} and the ideal {\\tt Ihilb} of local equations is generated by\nthe image of these normal forms in the ring {\\tt B} under the map {\\tt\n  Fones}.\n\n\\beginOutput\ni51 : JM = localCoherentEquations(IA)\\\\\n\\emptyLine\n\\                                                                       $\\cdot\\cdot\\cdot$\\\\\no51 = ideal (z z  - z , z z  - z , - z z  + z , - z z  + z , - z z  +  $\\cdot\\cdot\\cdot$\\\\\n\\              1 2    3   1 2    3     4 7    2     5 8    2     1 5    $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no51 : Ideal of B\\\\\n\\endOutput\n\nRemoving duplications among the generators:\n\n\\smallskip\n$J_M = \\langle\nz_1-z_{10}z_{11},\nz_2-z_4z_7,\nz_2-z_5z_8,\nz_2-z_{11}z_{12},\nz_2-z_1z_{11}z_{13},\\\\\nz_3-z_1z_2,\nz_3-z_5z_9,\nz_4-z_1z_5,\nz_6-z_3z_5,\nz_6-z_1z_2z_5,\nz_7-z_1z_{10},\nz_8-z_1z_7,\\\\\nz_9-z_1z_8,\nz_{12}-z_1z_{13},\nz_1z_2-z_5z_9,\nz_1z_2-z_1z_5z_8,\nz_1z_2-z_1^2z_4z_{10},\nz_1z_2-z_1^2z_5z_7,\\\\\nz_1z_2-z_1z_{11}z_{12},\nz_1z_2-z_2z_{10}z_{11},\nz_1^3z_4-z_3z_{11},\nz_1z_5z_8-z_4z_8,\nz_2z_{10}-z_1z_{12},\\\\\nz_3z_4-z_1z_6,\nz_3z_7-z_2z_8,\nz_3z_8-z_2z_9,\nz_3z_{10}-z_2z_7\n\\rangle$.\n\\smallskip\n\nNotice that there are many generators of $J_M$ that have a single\nvariable as one of its terms. Using these generators we can remove\nvariables from other binomials. This is done in \\Mtwo using the\nsubroutine {\\tt removeRedundantVariables}, which is the main ingredient\nof the package {\\tt minPres.m2} for computing the minimal\npresentations of polynomial quotient rings. Both {\\tt\n  removeRedundantVariables} and {\\tt minPres.m2} are explained in\nAppendix \\ref{Mpor}. The command {\\tt removeRedundantVariables} applied to an\nideal in a polynomial ring (not quotient ring) creates a ring map from\nthe ring to itself that sends the redundant variables to polynomials \nin the non-redundant variables and the non-redundant variables to \nthemselves. Applying this to our ideal $J_M$ we obtain the following \nsimplifications.\n\n\\beginOutput\ni52 : load \"minPres.m2\";\\\\\n\\endOutput\n\\beginOutput\ni53 : G = removeRedundantVariables JM\\\\\n\\emptyLine\n\\                          3  2      4  3                  2 4  3    2  $\\cdot\\cdot\\cdot$\\\\\no53 = map(B,B,\\{z  z  , z z  z  , z z  z  , z z  z  , z , z z  z  , z   $\\cdot\\cdot\\cdot$\\\\\n\\                10 11   5 10 11   5 10 11   5 10 11   5   5 10 11   10 $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no53 : RingMap B <--- B\\\\\n\\endOutput\n\\beginOutput\ni54 : ideal gens gb(G JM)\\\\\n\\emptyLine\n\\               3  2        2\\\\\no54 = ideal(z z  z   - z  z  z  )\\\\\n\\             5 10 11    10 11 13\\\\\n\\emptyLine\no54 : Ideal of B\\\\\n\\endOutput\n\nThus our affine patch of $Hilb_A$ has the coordinate ring \n$$\\k[z_1,z_2,\\ldots,z_{13}]/J_M \\,\\, \\simeq \\,\\,\n\\frac{\\k[z_5,z_{10},z_{11},z_{13}]}{ \\langle z_5 z_{{10}}^3 z_{11}^2 -\n  z_{10}z_{11}^2 z_{13} \\rangle} = \\frac{\\k[z_5,z_{10},z_{11},z_{13}]}\n{\\langle (z_5 z_{10}^2 -z_{13}) z_{10}z_{11}^2 \\rangle}.$$\nHence, we see immediately that there are three\ncomponents through the point $M$ on $Hilb_A$. The restriction of the\ncoherent component to the affine neighborhood of $M$ on $Hilb_A$ is\ndefined by the ideal quotient $\\, (J_M : (z_1 z_2 \\cdots\nz_{13})^\\infty) $ and hence the first of the above components \nis an affine patch of the coherent component. Locally near $M$ it is  \ngiven by the single equation $z_5 z_{10}^2 - z_{13} = 0$ in $\\A^4$. \nIt is smooth and, as expected, has dimension three. The second\ncomponent, $z_{10} = 0$, is also of dimension three and is smooth at $M$.\nThe third component, given by $z_{11}^2 = 0$ is more interesting.  It\nhas dimension three as well, but is not reduced.  Thus we have proved\nthe following result.\n\n\\begin{proposition}\nThe toric Hilbert scheme $Hilb_A$ of the matrix \n$$A = \\left( \\begin{matrix}\n           1 & 1 & 1 & 1 & 1  \\\\ \n           0 & 1 & 2 & 7 & 8 \n\\end{matrix} \\right)$$\nis not reduced.\n\\end{proposition}\n\nWe can use the ring map {\\tt G} from above to simplify {\\tt J} so as\nto involve only the four variables $z_5, z_{10},z_{11}$ and $z_{13}$.\n\n\\beginOutput\ni55 : CX = QQ[a..e, z_5,z_10,z_11,z_13, Weights =>\\\\\n\\            \\{9,3,5,0,0,0,0,0,0\\}];\\\\\n\\endOutput\n \n\\beginOutput\ni56 : F = map(CX, ring J, matrix\\{\\{a,b,c,d,e\\}\\} | \\\\\n\\                  substitute(G.matrix,CX))\\\\\n\\emptyLine\n\\                                          3  2      4  3               $\\cdot\\cdot\\cdot$\\\\\no56 = map(CX,T,\\{a, b, c, d, e, z  z  , z z  z  , z z  z  , z z  z  , z $\\cdot\\cdot\\cdot$\\\\\n\\                                10 11   5 10 11   5 10 11   5 10 11    $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no56 : RingMap CX <--- T\\\\\n\\endOutput\nApplying this map to {\\tt J} we get the ideal {\\tt J1}, \n\\beginOutput\ni57 : J1 = F J\\\\\n\\emptyLine\n\\                                            3  2          2   4  3     $\\cdot\\cdot\\cdot$\\\\\no57 = ideal (c*d - b*e*z  z  , a*e - b*d*z z  z  , a*c - b z z  z  , a $\\cdot\\cdot\\cdot$\\\\\n\\                        10 11             5 10 11           5 10 11    $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no57 : Ideal of CX\\\\\n\\endOutput\n\n\\noindent and adding the ideal $\\langle z_{11}^2 \\rangle$ to {\\tt J1} \nwe obtain the universal family for the non-reduced component of\n$Hilb_A$ about $M$. \n\n\\beginOutput\ni58 : substitute(ideal(z_11^2),CX) + J1\\\\\n\\emptyLine\n\\              2                                  3  2          2   4   $\\cdot\\cdot\\cdot$\\\\\no58 = ideal (z  , c*d - b*e*z  z  , a*e - b*d*z z  z  , a*c - b z z  z $\\cdot\\cdot\\cdot$\\\\\n\\              11             10 11             5 10 11           5 10  $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no58 : Ideal of CX\\\\\n\\endOutput\n\nIn the rest of this section, we present an interpretation of\nthe ideal $J_M$ in terms of the combinatorial theory\nof {\\it \\ie{integer programming}}. See, for instance, \n\\cite[\\S 4]{HS:St2} or \\cite{HS:Tho} for \nthe relevant background. Our reduced Gr\\\"obner basis \n(\\ref{GrobnerBasis}) is the {\\it \\ie{minimal test set}} for\nthe family of integer programs\n\\begin{equation}\n\\label{IP}\n{\\rm Minimize} \\quad\nw \\cdot u \\,\\,\\quad\n{\\rm subject} \\,\\, {\\rm to } \\,\\,\\,\nA \\cdot u = b   \\,\\,\\, {\\rm and}\n \\,\\,\\,u \\in \\N^n, \n\\end{equation}\nwhere $A \\in \\N^{d \\times n}$ and $w\n\\in \\ZZ^n$ are fixed and $b$ ranges over $\\N^d$.\nIf $u' \\in \\N^n$ is any feasible solution\nto (\\ref{IP}), then the corresponding optimal solution\n$u \\in \\N^n$ is computed as follows: the monomial\n$x^u $ is the unique normal form of $x^{u'}$ modulo\nthe Gr\\\"obner basis (\\ref{GrobnerBasis}).\n\nSuppose we had reduced $x^{u'}$\nmodulo the binomials (\\ref{FlatFamily}) instead of (\\ref{GrobnerBasis}).\nThen the output has a $z$-factor that depends on \nour choice of reduction path. To be precise, suppose the\nreduction path has length $m$ and at the $j$-th step we had used the\nreduction $\\, x^{u_{\\mu_j}} \\rightarrow  z_{\\mu_j} \\cdot x^{v_{\\mu_j}}\n$. Then we would obtain the normal form\n$$ \\, z_{\\mu_1} z_{\\mu_2} z_{\\mu_3} \\cdots z_{\\mu_m} \\cdot x^u.$$\nReduction paths can have different lengths. If we take\nanother  path  that\nhas length $m'$ and  uses\n$\\, x^{u_{\\nu_j}} \\rightarrow  z_{\\nu_j} \\cdot x^{v_{\\nu_j}} \\,$\nat the $j$-th step, then the output would be\n$$ \\, z_{\\nu_1} z_{\\nu_2} z_{\\nu_3} \\cdots z_{\\nu_{m'}} \\cdot x^u  .$$\n\n\\begin{theorem} \\label{paths}\nThe ideal $J_M$ of local equations\non $Hilb_A$ is generated by the binomials\n$$ \\, z_{\\mu_1} z_{\\mu_2} z_{\\mu_3} \\cdots z_{\\mu_m} - \nz_{\\nu_1} z_{\\nu_2} z_{\\nu_3} \\cdots z_{\\nu_{m'}} $$ each encoding a\npair of distinct reduction sequences from a feasible solution of an\ninteger program of the type (\\ref{IP}) to the corresponding optimal\nsolution using the minimal test set in (\\ref{GrobnerBasis}).\n\\end{theorem}\n\n\\begin{proof}\nThe given ideal is contained in $J_M$ because its generators\nare differences of monomials arising from the possible\nreduction paths of $\\,{lcm(x^{u_i},x^{u_j})} $,\nfor $1 \\leq i,j \\leq r $. Conversely, any reduction\nsequence can be transformed into an equivalent reduction sequence\nusing S-pair reductions. This follows from standard\narguments in the proof of Buchberger's criterion\n\\cite[\\S 2.6, Theorem 6]{HS:CLO}, and it implies that\nthe binomials  $ \\, z_{\\mu_1}  \\cdots z_{\\mu_m} -\n z_{\\nu_1}  \\cdots z_{\\nu_{m'}}  \\,$ are $\\k[z]$-linear\ncombinations of the generators of $J_M$.\n\\qed\n\\end{proof}\n\nA given feasible solution of an integer program (\\ref{IP})\nusually has many different reduction paths to the optimal solution\nusing  the reduced Gr\\\"obner basis (\\ref{GrobnerBasis}). \nFor our matrix \\ref{OurMatrix} and cost vector \n$w = (9,3,5,0,0)$, the monomial\n$\\, a^2 b d e^6 \\,$  encodes the feasible solution $(2,1,0,1,6)$\nof the integer program \n$$ {\\rm Minimize} \\quad\nw \\cdot u \\,\\,\\quad\n{\\rm subject} \\,\\, {\\rm to } \\,\\,\\,\nA \\cdot u = \\binom{10}{56}   \\,\\,\\, {\\rm and}\n \\,\\,\\,u \\in \\N^5.$$\nThere are $19$ different paths from this feasible solution \nto the optimal solution $(0,3,0,3,4)$ encoded by the monomial \n$\\, b^3 d^3 e^4 $. The generating function for these paths is:\n\\begin{eqnarray*}\n& z_1^2 + 3 z_1 z_2^2 z_5 z_7 + 2 z_1 z_2 z_5 z_7^2 z_{12}\n + 2 z_1 z_2 z_5 z_8 \\\\ & {} + 2 z_1 z_2 z_{12} z_{13} + z_1 z_5 z_9 \n + z_2^3 z_4 z_5 z_7^2 + z_2^3 z_4 z_{13} + z_2^3 z_5 z_{11} \\\\ & {} \n + 2 z_2 z_3 z_5 z_7 + z_3 z_5 z_7^2 z_{12} + z_3 z_5 z_8 + z_3 z_{12} z_{13}.\n\\end{eqnarray*}\nThe difference of any two monomials in this generating function \nis a valid local equation for the toric Hilbert scheme of\n(\\ref{OurMatrix}). For instance, the binomial \n$\\,  z_3 z_5 z_7^2 z_{12} - z_3 z_{12} z_{13} \\,$ lies in $J_M$,\nand, conversely, $J_M$ is generated by binomials obtained in this manner.\n\nThe scheme structure of $J_M$ encodes obstructions to making certain\nreductions when solving our family of integer programs. For instance,\nthe variable $z_3$ is a zero-divisor modulo $J_M$. If we factor it\nout from the binomial $\\,  z_3 z_5 z_7^2 z_{12} - z_3 z_{12} z_{13}\n\\in J_M \\,$, we get \n$\\, z_5 z_7^2 z_{12} - z_{12} z_{13} \\,$,\nwhich does not lie in $J_M$. Thus there is no monomial\n$a^{i_1} b^{i_2} c^{i_3} d^{i_4} e^{i_5} \\,$\nfor which both the paths $ z_5 z_7^2 z_{12} $ and\n$ z_{12} z_{13} $ are used to reach the optimum.\nIt would be a worthwhile combinatorial project to\nstudy the path generating functions and their relation\nto the ideal $J_M$ in more detail.\n\nIt is instructive to note that the binomials\n$ \\, z_{\\mu_1} z_{\\mu_2} \\cdots z_{\\mu_m} \\, - \\,\n z_{\\nu_1} z_{\\nu_2}  \\cdots z_{\\nu_{m'}}  $\nin Theorem~\\ref{paths} do not form a vector space basis\nfor the ideal $J_M$. We demonstrate this for the lexicographic\nGr\\\"obner basis (with $a \\succ b \\succ c \\succ d \\succ e$) of \nthe toric ideal defining the rational normal curve of degree $4$. \nIn this case, we can take $A = \\left ( \\begin{array}{ccccc}\n1 & 1 & 1 & 1 & 1 \\\\ 0 & 1 & 2 & 3 & 4 \\end{array} \\right )$ and the \nuniversal family in question is :\n$$ \n\\bigl\\{\na c    - z_1 b^2, \\,\na d    - z_2 b c,\\,\na e    - z_3 c^2,\\,\nb d    - z_4 c^2,\\,\nb e    - z_5 c d,\\,\nc e    - z_6 d^2\n\\bigr\\}.\n$$ \nThe corresponding ideal of local equations is\n$J_M = \n\\langle z_3 - z_2  z_5, z_2 - z_1  z_4, z_5  - z_4 z_6 \\rangle $,\nfrom which we see that $M$ is a smooth point of $Hilb_A$.\nThe binomial $\\,z_1 z_5 - z_1 z_4 z_6 \\,$ lies in $J_M$\nbut there is no monomial that has the reduction path $z_1 z_5$\nor $z_5 z_1 $ to optimality.  Indeed, any monomial\nthat admits the reductions $z_1 z_5$ or $z_5 z_1$ must be\ndivisible by either $\\, a c e \\, $ or $\\, a b e  $.\nThe path generating functions for these two monomials are\n$$ abe \\quad \\rightarrow \\quad\n(z_3 \\, + \\, z_1 z_4 z_5 \\, +\\, z_2 z_5) \\cdot b c^2 $$\n$$ ace \\quad \\rightarrow \\quad\n(z_3 \\,+ \\,z_1 z_4 z_5 \\,+\\,\nz_2 z_4 z_6) \\cdot c^3 . $$\nThus every reduction to optimality using $z_1$ and $z_5$ must\nalso use $z_4$, and we conclude that $\\,z_1 z_5 - z_1 z_4 z_6 \\,$\nis not in the $\\k$-span of the binomials listed in\nTheorem~\\ref{paths}.\n\n\\section{The Coherent Component of the Toric Hilbert Scheme}\n\nIn this section we study the component of the toric Hilbert scheme\n$Hilb_A$ that contains the point corresponding to the toric ideal\n$I_A$. An $A$-graded ideal is\ncoherent if and only if it is isomorphic to an initial ideal of $I_A$\nunder the action of the torus $(\\k^\\ast)^n$. All coherent $A$-graded\nideals lie on the same component of $Hilb_A$ as $I_A$.\nWe will show that this component need not be\nnormal, and we will describe how its local and global equations can be\ncomputed using \\Mtwo.  Every term order for the toric ideal $I_A$ can\nbe realized by a weight vector that is an element in the lattice $\\,N\n= Hom_\\ZZ( ker_\\ZZ(A) , \\ZZ) \\, \\simeq \\, \\ZZ^{n-d}$.  Two weight\nvectors $w$ and $w'$ in $N$ are considered {\\it equivalent}\\index{weight vectors!equivalent} if they\ndefine the same initial ideal $\\,in_w(I_A) = in_{w'}(I_A)$.  These\nequivalence classes are the relatively open cones of a projective fan\n$\\Sigma_A$ called the {\\em Gr\\\"obner fan\\index{Grobner fan@Gr\\\"obner fan}} of $I_A$  \n\\cite{HS:MR}, \\cite{HS:ST}. This fan lies in \n$\\mathbb R^{n-d}$, the real vector space spanned by the lattice $N$.\n\n\\begin{theorem}\nThe toric ideal $I_A$ lies on a unique irreducible component of\nthe toric Hilbert scheme $Hilb_A$, called the coherent component.\nThe normalization of the coherent\ncomponent is the projective toric variety defined by \nthe Gr\\\"obner fan of $I_A$.\n\\end{theorem}\n\n\\begin{proof}\nThe {\\it \\ie{divisor at infinity}} on the toric Hilbert scheme $Hilb_A$ \nconsists of all points at which at least one of the local coordinates\n(around some monomial $A$-graded ideal) is zero.  This is a proper\nclosed codimension one subscheme of $Hilb_A$, parametrizing\nall those $A$-graded ideals that contain at least one monomial.  \nThe complement of the divisor at infinity in \n$Hilb_A$ consists of precisely  the orbit of $I_A$ \nunder the action of the torus $(\\k^*)^n $.\nThis is the content of \\cite[Lemma 10.12]{HS:St2}.\n\nThe closure of the $(\\k^*)^n $-orbit of $I_A$ is a\nreduced and irreducible component of  $Hilb_A$.\nIt is reduced because $I_A$ is a smooth point on $Hilb_A$,\nas can be seen from the local equations, and it is irreducible\nsince $(\\k^*)^n$ is a connected group. It is a component\nof $Hilb_A$ because its complement lies in a divisor.\nWe call this irreducible component the\n{\\it \\ie{coherent component}} of $Hilb_A$.\n\nIdentifying $(\\k^*)^n$ with $Hom_\\ZZ(\\ZZ^n, \\k^*)$, we note\nthat the stabilizer of $I_A$ consists of those linear forms\n$w$ that restrict to zero on the kernel of $A$. Therefore\nthe coherent component is the closure in $Hilb_A$\nof the  orbit of the point $I_A$ under the action of the torus\n$\\, N \\otimes \\k^* \\, = \\,Hom_\\ZZ( ker_\\ZZ(A), \\k^*)$.\nThe $(N \\otimes \\k^*)$-fixed points\non this component are precisely the coherent monomial \n$A$-graded ideals, and the same holds for the\ntoric variety of the Gr\\\"obner fan. \n\nFix a maximal cone $\\sigma$ in the Gr\\\"obner fan $\\Sigma_A$,\nand let $M = \\langle x^{u_1}, \\ldots, x^{u_r} \\rangle$ \nbe the corresponding (monomial) \ninitial ideal of $I_A$.  As before we write\n$$ \\left \\{ x^{u_1} -  z_1 \\cdot x^{v_1} \\,, \\,\\,\n x^{u_2} - z_2  \\cdot x^{v_2} \\,,\\, \\, \\ldots \\, ,\n\\,\\, x^{u_r} -   z_r \\cdot x^{v_r} \\right \\}$$\nfor the universal family arising from the corresponding\nreduced Gr\\\"obner basis of $I_A$.  Let $J_M$ be the\nideal in $\\k [z_1,z_2,\\ldots,z_r]$ defining this family.\n\nThe restriction of the coherent component to the \naffine neighborhood of $M$ on $Hilb_A$ is defined\nby $\\, J_M :  (z_1 z_2 \\cdots z_r)^\\infty $.\nIt then follows from our combinatorial description of\nthe ideal $J_M$ that this ideal quotient is a binomial prime ideal.\nIn fact, it is the ideal of algebraic relations among the \nLaurent monomials $\\, x^{u_1- v_1}, \\ldots, x^{u_r-v_r}$.\nWe conclude that the restriction of the coherent component to the\naffine neighborhood of $M$ on $Hilb_A$ equals\n\\begin{equation}\n\\label{uv-algebra}\n {\\rm Spec} \\,\\, \\k \\bigl[\n x^{u_1-v_1},\n x^{u_2-v_2},  \\ldots,\n x^{u_r-v_r} \n\\bigr] .\n\\end{equation}\n\nThe abelian group generated by the vectors\n$\\, u_1-v_1, \\ldots, u_r-v_r \\,$  equals\n$\\ker_\\ZZ(A) = Hom_\\ZZ(N,\\ZZ)$. This follows from \n\\cite[Lemma 12.2]{HS:St1} because the\nbinomials $x^{u_i} - x^{v_i}$ generate the toric ideal $I_A$.\nThe cone generated by the vectors $\\, u_1-v_1, \\ldots, u_r-v_r \\,$  is\nprecisely the polar dual $\\sigma^\\vee$ to\nthe Gr\\\"obner cone $\\sigma$. This follows from\n equation (2.6) in \\cite{HS:St1}. We conclude that the\nnormalization of the affine variety\n(\\ref{uv-algebra}) is the normal affine toric variety\n\\begin{equation}\n\\label{normal-uv-algebra}\n {\\rm Spec} \\,\\, \\k \\bigl[\n \\ker_\\ZZ(A) \\,\\cap\\, \\sigma^\\vee \\bigr] .\n\\end{equation}\n\nThe normalization morphism from (\\ref{normal-uv-algebra}) to\n(\\ref{uv-algebra}) maps the identity point in the  toric variety\n (\\ref{normal-uv-algebra}) \nto the point $I_A$ in the affine chart \n(\\ref{uv-algebra}) of the toric Hilbert \nscheme $Hilb_A$. \nClearly, this normalization morphism is equivariant with respect to the\naction by the torus $\\, N \\otimes \\k^* $.\nThese two properties  hold for every maximal cone $\\sigma$ of the \nGr\\\"obner fan $\\Sigma_A$. Hence there exists a unique \n$\\, N \\otimes \\k^* $-equivariant morphism $\\phi$\nfrom the projective toric variety associated with $\\Sigma_A$\nonto the coherent component of $Hilb_A$, such that $\\phi$ maps \nthe identity point to the point $I_A$ on $Hilb_A$, and \n$\\phi$ restricts to the normalization\nmorphism (\\ref{normal-uv-algebra}) $\\rightarrow$ (\\ref{uv-algebra}) on each\naffine open chart. We conclude that $\\phi$\nis the desired normalization map from the\nprojective toric variety associated with the Gr\\\"obner fan of $I_A$ \nonto the coherent component of the toric Hilbert scheme $Hilb_A$.\n\\qed\n\\end{proof}\n\nWe now present an example that shows that the coherent component \nof $Hilb_A$ need not be normal. This example is \nderived from the matrix that appears in Example 3.15 of \\cite{HS:HM}.\nThis example is also mentioned in \\cite{HS:PS1} without details.\nLet $d=4$ and $n=7$ and fix the matrix\n\n\\begin{equation}\n\\label{non-normal}\nA = \\left( \\begin{array}{ccccccc}  \n1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\n0 & 6 & 7 & 5 & 8 & 4 & 3 \\\\\n3 & 7 & 2 & 0 & 7 & 6 & 1 \\\\\n6 & 5 & 2 & 6 & 5 & 0 & 0 \\end{array} \\right).\n\\end{equation}\n\nThe lattice $\\,N =  Hom_\\ZZ ( ker_\\ZZ(A), \\ZZ)$\nis three-dimensional. The toric ideal $I_A$ is minimally \ngenerated by $30$ binomials of total degree between $6$ and $93$.\n\n\\beginOutput\ni59 : A = \\{\\{1,1,1,1,1,1,1\\},\\{0,6,7,5,8,4,3\\},\\{3,7,2,0,7,6,1\\},\\\\\n\\         \\{6,5,2,6,5,0,0\\}\\};\\\\\n\\endOutput\n\\beginOutput\ni60 : IA = toricIdeal A\\\\\n\\emptyLine\n\\              2 3       3 2   2     4 4    8 4   4 3 6    7 2 4     4  $\\cdot\\cdot\\cdot$\\\\\no60 = ideal (a c e - b*d f , a c*d*e f  - b g , d e f  - b c g , a*b c $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no60 : Ideal of R\\\\\n\\endOutput\n\nWe fix the weight vector $w = (0,0,276,220,0,0,215)$ in $N$ and \ncompute the initial ideal $M = in_w(I_A)$. This initial ideal \nhas $44$ minimal generators.\n\n\\beginOutput\ni61 : Y = QQ[a..g, MonomialSize => 16,\\\\\n\\                 Weights => \\{0,0,276,220,0,0,215\\},\\\\\n\\                 Degrees =>transpose A];\\\\\n\\endOutput\n\\beginOutput\ni62 : IA = substitute(IA,Y);\\\\\n\\emptyLine\no62 : Ideal of Y\\\\\n\\endOutput\n\\beginOutput\ni63 : M = ideal leadTerm IA\\\\\n\\emptyLine\n\\              2 3    8 4   7 2 4     4 7 3   5 4 3 5   2 6 5 4   3 3 1 $\\cdot\\cdot\\cdot$\\\\\no63 = ideal (a c e, b g , b c g , a*b c f , b c d f , a b c g , a b c  $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no63 : Ideal of Y\\\\\n\\endOutput\n\n\\begin{proposition} The three dimensional affine variety\n  (\\ref{uv-algebra}), for the initial ideal $M$ with respect to $w =\n  (0,0,276,220,0,0,215)$ of the toric ideal of $A$ in\n  (\\ref{non-normal}), is not normal.\n\\end{proposition} \n\n\\begin{proof}\nThe universal family for the toric Hilbert scheme $Hilb_A$ at $M$ is:\n\\begin{eqnarray*}\n\\{& a^2e^{15}g^{18}-z_1b^3c^6d^{10}f^{16}, \\,\\,\nb^{13}d^{15}f^{16}-z_2a^8ce^{21}g^{14}, \\\\ &\nc^{59} d^{57} f^{110} - z_3  e^{92} g^{134},\na c^{14} d^{11} f^{23} - z_4  b e^{19} g^{29}, \\\\ &\nb^7 c^2 g^4 - z_5  d^4 e^3 f^6, \\,\\,\n\\ldots, \\,\\,\nb c^{34} d^{32} f^{62} - z_{44}  e^{53} g^{76} \\}.\n\\end{eqnarray*}\nThe semigroup algebra in (\\ref{uv-algebra})\nis generated by $44$ Laurent  monomials \ngotten from this family. It turns out that the\nfirst four monomials suffice to generate the semigroup.\nIn other words, for all $j \\in \\{5,6,\\ldots,44\\}$\nthere exist\n$ i_1,i_2,i_3, i_4 \\in \\N $ such that\n$\\,\nz_{j} - \nz_1^{i_1}\nz_2^{i_2}\nz_3^{i_3}\nz_4^{i_4} \\in  J_M : (z_1 \\cdots z_{44})^\\infty $.\nHence the semigroup algebra in (\\ref{uv-algebra}) is:\n$$ \\k \\bigl[\n \\frac{a^2 e^{15} g^{18}}{ b^3 c^6 d^{10} f^{16}}, \n \\frac{ b^{13} d^{15} f^{16} }{a^8 c e^{21} g^{14}},\n \\frac{ c^{59} d^{57} f^{110}} {e^{92} g^{134}}, \n \\frac{ a c^{14} d^{11} f^{23}} {b e^{19} g^{29}}\n\\bigr] \\,\\,\\, \\simeq \\,\\,\\,\n\\frac{\\k[z_1,z_2,z_3,z_4]}{\\langle z_1^5  z_2 z_3 - z_4^2 \\rangle}.\n$$\nThis algebra is not integrally closed, since\na toric hypersurface is normal if and only if\nat least one of the two monomials in the defining equation \nis square-free. Its integral closure \nin $\\k[ ker_\\ZZ(A) ]$ is generated by the\nLaurent monomial\n\\begin{equation}\n\\label{witness}\n\\frac{z_4}{z_1^2} \\,\\, = \\,\\, \n( z_1 z_2 z_3)^{\\frac{1}{2}}  \\,\\, = \\,\\, \n\\frac{ b^5 c^{26} d^{31} f^{55}}{a^3 e^{49} g^{65}}.\n\\end{equation}\nHence the affine chart (\\ref{normal-uv-algebra}) of the toric variety\nof the Gr\\\"obner fan of $I_A$ is the spectrum of the normal domain\n$  \\k[z_1,z_2,z_3,y]/ \\langle\nz_1  z_2 z_3 - y^2 \\rangle$, \nwhere $y$ maps to (\\ref{witness}).\n\\qed\n\\end{proof}\n\nWe now examine the local equations of $Hilb_A$ about $M$ for this \nexample.\n\\beginOutput\ni64 : JM = localCoherentEquations(IA)\\\\\n\\emptyLine\n\\                                                                       $\\cdot\\cdot\\cdot$\\\\\no64 = ideal (z z  - z , z z  - z , z z  - z , z z  - z , z z  - z , z  $\\cdot\\cdot\\cdot$\\\\\n\\              1 2    3   1 2    3   1 5    4   1 3    6   1 3    6   1 $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no64 : Ideal of B\\\\\n\\endOutput\n\\beginOutput\ni65 : G = removeRedundantVariables JM;\\\\\n\\emptyLine\no65 : RingMap B <--- B\\\\\n\\endOutput\n\\beginOutput\ni66 : toString ideal gens gb(G JM)\\\\\n\\emptyLine\no66 = ideal(z_32*z_42^2*z_44-z_37^2*z_42,z_32^3*z_35*z_37^2-z_42^2*z_4 $\\cdot\\cdot\\cdot$\\\\\n\\endOutput\n\nThis ideal has six generators and decomposing it \n%%% $\\langle z_32z_42^2z_44-z_37^2z_42,\n%%% z_32^3z_35z_37^2-z_42^2z_44,\n%%% z_32^4z_35z_37-z_37z_42,\n%%% z_32^2z_35z_37^4z_42-z_42^4z_44^2,\n%%% z_32z_35z_37^6z_42-z_42^5z_44^3,\n%%% z_35z_37^8z_42-z_42^6z_44^4 \\rangle$\nwe see that there are five components \nthrough the monomial ideal $M$ on this toric Hilbert scheme. They \nare defined by the ideals: \n\\begin{itemize}\n\\item $\\langle z_{32}z_{42}z_{44}-z_{37}^2,z_{32}^4z_{35}-z_{42},\nz_{32}^3z_{35}z_{37}^2-z_{42}^2z_{44},\nz_{32}^2z_{35}z_{37}^4-z_{42}^3z_{44}^2,\\\\\n\\indent \\indent z_{32}z_{35}z_{37}^6-z_{42}^4z_{44}^3,\nz_{35}z_{37}^8-z_{42}^5z_{44}^4 \\rangle$ \n\\item $\\langle z_{44},z_{37} \\rangle$\n\\item $\\langle z_{37},z_{42}^2 \\rangle$\n\\item $\\langle z_{42},z_{35} \\rangle$ \n\\item $\\langle z_{42},z_{32}^3 \\rangle$.\n\\end{itemize}\nAll five components are three\ndimensional. The first component is an affine patch of the coherent\ncomponent and two of the components are not reduced. Let $K$ be the \nfirst of these ideals.\n\n\\beginOutput\ni67 : K = ideal(z_32*z_42*z_44-z_37^2,z_32^4*z_35-z_42,\\\\\n\\          z_32^3*z_35*z_37^2-z_42^2*z_44,z_32^2*z_35*z_37^4-z_42^3*z_44^2,\\\\\n\\          z_32*z_35*z_37^6-z_42^4*z_44^3,z_35*z_37^8-z_42^5*z_44^4);\\\\\n\\emptyLine\no67 : Ideal of B\\\\\n\\endOutput\n\nApplying {\\tt removeRedundantVariables} to $K$ we see that \nthe affine patch of the coherent component is, locally at $M$,\na non-normal hypersurface singularity (agreeing with (\\ref{witness})).\nThe labels on the variables depend on the order of elements in \nthe initial ideal $M$ computed by \\Mtwo in line {\\tt i61}.\n\n\\beginOutput\ni68 : GG = removeRedundantVariables K;\\\\\n\\emptyLine\no68 : RingMap B <--- B\\\\\n\\endOutput\n\\beginOutput\ni69 : ideal gens gb (GG K)\\\\\n\\emptyLine\n\\             5           2\\\\\no69 = ideal(z  z  z   - z  )\\\\\n\\             32 35 44    37\\\\\n\\emptyLine\no69 : Ideal of B\\\\\n\\endOutput\n\nThere is a general algorithm due to de Jong \\cite{HS:DJ} for \ncomputing the \\ie{normalization} of any affine variety. \nIn the toric case, the problem of normalization amounts to  \ncomputing the minimal {\\em \\ie{Hilbert basis}} of a given convex\nrational polyhedral cone \\cite{HS:Sch}. An efficient implementation can be \nfound in the software package {\\tt Normaliz}\\indexcmd{Normaliz} by Bruns and\nKoch \\cite{HS:BK}.\n\nOur computational study of the toric Hilbert scheme in this\nchapter was based on local equations rather than\nglobal equations (arising from a projective embedding of  $Hilb_A$),\nbecause the latter system of equations tends to be too large \nfor most purposes. Nonetheless, they are interesting.\nIn the remainder of this section, we present a canonical \nprojective embedding of the coherent component of $Hilb_A$.\n\nLet $G_1, G_2, G_3, \\ldots, G_s$ denote all the {\\it Graver fibers} of\nthe matrix $A$. In Section 1 we showed how to compute them in \n{\\sl Macaulay 2}. Each\nset $G_i$ consists of the monomials in $\\k[x_1,\\ldots,x_n]$ \nthat have a fixed Graver degree.  Consider the set $\\, {\\mathbf G} \\,\n:= \\, G_1 G_2 G_3 \\cdots G_s \\,$ that consists of all monomials that\nare products of monomials, one from each of the distinct Graver\nfibers. Let $t$ denote the cardinality of ${\\mathbf G}$.  We introduce\nan extra indeterminate $z$, and we consider the $\\N$-graded semigroup\nalgebra $\\,\\k[z {\\mathbf G}] $, which is a subalgebra of\n$\\k[x_1,\\ldots,x_n,z]$. The grading of this algebra is $\\,deg(z) = 1\\,$ and\n$\\, deg(x_i) = 0$. Labeling the elements of ${\\mathbf G}$ with\nindeterminates $y_i$, we can write\n$$ \\k[z {\\mathbf G}]   = \n\\k[y_1,y_2,\\ldots,y_t]/P_A, $$\nwhere $P_A$ is a homogeneous toric ideal\nassociated with a configuration of $t$ vectors in $\\ZZ^{n+1}$.\nWe note that the torus $(\\k^*)^n$ acts naturally on \n$\\, \\k[z {\\mathbf G}]$.\n\n\\begin{example} \\rm\nLet $n=4,d=2$ and \n $\\, A \\, = \\, \\left( \\begin{array}{cccc}\n3 & 2 & 1 & 0 \\\\\n0 & 1 & 2 & 3 \n \\end{array} \\right) $,\nso that $I_A$ is the ideal of the twisted cubic curve.\nThere are five Graver fibers:\n\n\\beginOutput\ni70 : A = \\{\\{1,1,1,1\\},\\{0,1,2,3\\}\\};\\\\\n\\endOutput\n\\beginOutput\ni71 : I = toricIdeal A;\\\\\n\\emptyLine\no71 : Ideal of R\\\\\n\\endOutput\n\\beginOutput\ni72 : Graver = graver I;\\\\\n\\emptyLine\n\\              1       5\\\\\no72 : Matrix R  <--- R\\\\\n\\endOutput\n\\beginOutput\ni73 : fibers = graverFibers Graver;\\\\\n\\endOutput\n\\beginOutput\ni74 : peek fibers\\\\\n\\emptyLine\no74 = HashTable\\{\\{2, 2\\} => | ac b2 |     \\}\\\\\n\\                \\{2, 3\\} => | ad bc |\\\\\n\\                \\{2, 4\\} => | bd c2 |\\\\\n\\                \\{3, 3\\} => | a2d abc b3 |\\\\\n\\                \\{3, 6\\} => | ad2 bcd c3 |\\\\\n\\endOutput\n\nThe set ${\\mathbf G} = G_1 G_2 G_3 G_4 G_5 \\,$ consists of\n$22$ monomials of degree $14$.\n\n\\beginOutput\ni75 : G = trim product(values fibers, ideal)\\\\\n\\emptyLine\n\\              5     5   4 3 5   5 3 4   4 2 2 4   3 4   4   2 6 4   4  $\\cdot\\cdot\\cdot$\\\\\no75 = ideal (a b*c*d , a b d , a c d , a b c d , a b c*d , a b d , a b $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no75 : Ideal of R\\\\\n\\endOutput\n\\beginOutput\ni76 : numgens G\\\\\n\\emptyLine\no76 = 22\\\\\n\\endOutput\n\nWe introduce a polynomial ring in $22$ variables\n$y_1,y_2,\\ldots,y_{22}$, and we compute the ideal $P_A$.\nIt is generated by $180$ binomial quadrics. \n\n\\beginOutput\ni77 : z = symbol z;\\\\\n\\endOutput\n\\beginOutput\ni78 : S = QQ[a,b,c,d,z];\\\\\n\\endOutput\n\\beginOutput\ni79 : zG = z ** substitute(gens G, S);\\\\\n\\emptyLine\n\\              1       22\\\\\no79 : Matrix S  <--- S\\\\\n\\endOutput\n\\beginOutput\ni80 : R = QQ[y_1 .. y_22];\\\\\n\\endOutput\n\\beginOutput\ni81 : F = map(S,R,zG)\\\\\n\\emptyLine\n\\                5     5    4 3 5    5 3 4    4 2 2 4    3 4   4    2 6 $\\cdot\\cdot\\cdot$\\\\\no81 = map(S,R,\\{a b*c*d z, a b d z, a c d z, a b c d z, a b c*d z, a b  $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no81 : RingMap S <--- R\\\\\n\\endOutput\n\\beginOutput\ni82 : PA = trim ker F\\\\\n\\emptyLine\n\\              2                                                        $\\cdot\\cdot\\cdot$\\\\\no82 = ideal (y   - y  y  , y  y   - y  y  , y  y   - y  y  , y  y   -  $\\cdot\\cdot\\cdot$\\\\\n\\              21    20 22   19 21    18 22   18 21    17 22   17 21    $\\cdot\\cdot\\cdot$\\\\\n\\emptyLine\no82 : Ideal of R\\\\\n\\endOutput\n\nThese equations define a toric surface\nof degree $30$ in projective $21$-space.\n\\beginOutput\ni83 : codim PA\\\\\n\\emptyLine\no83 = 19\\\\\n\\endOutput\n\\beginOutput\ni84 : degree PA\\\\\n\\emptyLine\no84 = 30\\\\\n\\endOutput\n\nThe surface is smooth, but there are too many equations and the\ncodimension is too large to use the Jacobian criterion for smoothness\n\\cite[\\S 16.6]{HS:Eis} directly. Instead we check smoothness for each\nopen set $y_i \\neq 0$. \n\n\\beginOutput\ni85 : Aff = apply(1..22, v -> (\\\\\n\\                             K = substitute(PA,y_v => 1);\\\\\n\\                             FF = removeRedundantVariables K;\\\\\n\\                             ideal gens gb (FF K)));\\\\\n\\endOutput\n\\beginOutput\ni86 : scan(Aff, i -> print toString i);\\\\\nideal()\\\\\nideal()\\\\\nideal()\\\\\nideal(y_1^4*y_5*y_21-1)\\\\\nideal(y_1^4*y_6^6*y_21-1)\\\\\nideal()\\\\\nideal(y_1^2*y_11^2*y_17-1)\\\\\nideal(y_1^3*y_9^2*y_21^2-1)\\\\\nideal(y_6^3*y_21-y_10,y_1*y_10^3-y_6^2,y_1*y_6*y_10^2*y_21-1)\\\\\nideal(y_6*y_15-1,y_2*y_15^2-y_6*y_14,y_6^2*y_14-y_2*y_15)\\\\\nideal()\\\\\nideal(y_11*y_13-1,y_1^2*y_21^3-y_13^2)\\\\\nideal(y_1^2*y_14^3*y_21^3-1)\\\\\nideal(y_10^2*y_21-1,y_1*y_15^4-y_10^3)\\\\\nideal()\\\\\nideal(y_11*y_20-1,y_3*y_20^2-y_11*y_17,y_11^2*y_17-y_3*y_20)\\\\\nideal(y_11*y_18*y_21-1,y_1*y_21^3-y_11*y_18^2,y_11^2*y_18^3-y_1*y_21^2)\\\\\nideal(y_1*y_19^4*y_21^4-1)\\\\\nideal(y_15*y_22-1)\\\\\nideal()\\\\\nideal(y_20*y_22-1)\\\\\nideal()\\\\\n\\endOutput\n\nBy examining these local equations, we see that $Hilb_A$ is smooth, and also\nthat there are eight fixed points under the\naction of the $2$-dimensional torus. They correspond\nto the variables $y_1,y_2,y_3,y_6,y_{11},y_{15},y_{20}$ and $y_{22}$. \nBy setting any of these eight variables to $1$ in the\n$180$ quadrics above, we obtain an affine variety\nisomorphic to the affine plane.\n\\end{example}\n\n\\begin{theorem} \\label{isomorphism}\nThe coherent component of the toric Hilbert scheme $Hilb_A$ is\nisomorphic to the projective spectrum $\\,Proj \\,\\k[z {\\mathbf G}]\\,$\nof the algebra $\\k[z {\\mathbf G}]$.\n\\end{theorem}\n\n\\begin{proof} The first\nstep is to define a morphism from $\\,Hilb_A \\,$ to\nthe $(t-1)$-dimensional projective space\n$\\P({\\mathbf G}) = Proj \\, \\k[y_1,y_2,\\ldots,y_t]$.\nConsider any point $I$ on $Hilb_A$. We intersect\nthe ideal $I$ with the finite-dimensional vector space\n$\\k G_i$, consisting of all homogeneous polynomials\nin $\\k[x_1,\\ldots,x_n]$ that lie in the $i$-th  Graver degree.\nThe definition of $A$-graded ideal implies that\n$I \\cap \\k G_i$ is a linear subspace of codimension $1$ in $\\k G_i$.\nWe represent this subspace by an equation\n$\\, g_i(I) = \\sum_{u \\in G_i } c_u x^u \\,$, which is \nunique up to scaling. Taking the product of these\npolynomials for $i=1,\\ldots,t$, we get a unique (up to scaling)\npolynomial that is supported on ${\\mathbf G} = G_1 G_2 \\cdots G_t$.\nThe map $\\, I \\mapsto g_1(I) g_2(I) \\cdots g_t(I)\\,$\ndefines a morphism from $Hilb_A \\,$ to $\\P({\\mathbf G})$.\nThis morphism is equivariant with respect to the  $(\\k^*)^n$-action\non both schemes.\n\nConsider the restriction of this equivariant\n morphism to the coherent component of the toric Hilbert scheme.\nIt maps the $(\\k^*)^n$-orbit of the toric ideal $I_A$\ninto the subvariety $\\,Proj \\,\\k[z {\\mathbf G}]\\,$\nof $\\P({\\mathbf G})$. This inclusion\nis an isomorphism onto the dense torus, \nas the dimension of the Newton polytope of \n$$ g(I_A) = \\prod_{i=1}^t \\,(\\sum_{u \\in G_i }  x^u \\,) $$\nequals the dimension of the kernel of $A$. Equivalently,\nthe stabilizer of $g(I_A)$ in $(\\k^*)^n$ \nconsists only of those one-parameter subgroups\n$w$ that restrict to zero on the kernel of $A$.\n\nTo show that our morphism is an isomorphism between the coherent component\nand  $\\,Proj \\,\\k[z {\\mathbf G}]$,\nwe consider the affine chart around an initial monomial ideal\n$M = in_w(I_A)$. The polynomial $g(M)$ is a monomial,\nnamely, it is the product of all standard monomials whose\ndegree is a  Graver degree. Moreover, $g(M)$ is the leading monomial\nof $g(I_A)$ with respect to the weight vector $w$. The Newton\npolytope of $g(I_A)$ is the Minkowski sum of the Newton polytopes \nof the polynomials $\\,g_1(I_A),   \\ldots, g_t(I_A)$,\nand it is a state polytope for $I_A$, by \\cite[Theorem 7.5]{HS:St2}.\n\nLet $g(M) = x^q$, and let  $\\sigma$  be the cone of the\nGr\\\"obner fan  $\\Sigma_A$ that has $w$ in its interior. \nThen  $\\sigma$ coincides with the normal cone at the vertex $q$ of \nthe state  polytope described above  \\cite[\\S 3]{HS:St2}.\nConsider the restriction of our morphism to the affine chart around $M$\nof the coherent component,  as described in (\\ref{uv-algebra}).\nThis restriction defines an isomorphism onto the variety\n\\begin{equation}\n\\label{other-uv-algebra}\nSpec \\,\\,  \\k[\\, x^{p-q} \\, : \\,x^p \\in {\\mathbf G} \\, ]\n\\end{equation}\nOn the other hand, the semigroup algebra in (\\ref{other-uv-algebra})\nis isomorphic to that in  (\\ref{uv-algebra}) because\neach pair of vectors $\\{u_i, v_i\\}$ seen in the \nreduced Gr\\\"obner basis lies in one of the Graver fibers $G_j$.  \nHence our morphism restricts to an isomorphism from the\naffine chart around $M$ of the coherent component onto (\\ref{other-uv-algebra}).\nFinally, note that (\\ref{other-uv-algebra}) is the principal affine\nopen subset of $\\,Proj \\,\\k[z {\\mathbf G}]\\,$ defined by the\ncoordinate $x^q$. Hence we get an isomorphism between the\ncoherent component of $Hilb_A$ and $\\,Proj \\,\\k[z {\\mathbf G}]$.\n\\qed\n\\end{proof}\n\n\\appendix\n\n\\section{Fourier-Motzkin Elimination}\\index{Fourier-Motzkin elimination}\\label{FMe}\n\nWe now give the \\Mtwo code for converting the generator/inequality\nrepresentation of a rational convex polyhedron to the other. It is\nbased on the Fourier-Motzkin elimination procedure for eliminating a\nvariable from a system of inequalities \\cite {HS:Zie}. This code was\nwritten by Greg Smith.\n\nGiven any cone $C \\subset \\R^d$, the polar cone of $C$ is defined to be\n$$C^{\\vee} = \\{ x \\in \\R^d \\mid x \\cdot y \\leq 0, \\mbox{for all\\ } y\n\\in C\\}.$$\n\n\\noindent For a $d \\times n$ matrix $Z$, define\n$cone(Z) = \\{ Z x \\mid x \\in \\R_{\\geq 0}^n \\} \\subset \\R^d,$ and \n$\\mathit{affine}(Z) = \\{ Z x \\mid x \\in \\R^n \\} \\subset \\R^d.$\nFor two integer matrices $Z$ and $H$, both having  $d$\nrows, {\\tt polarCone(Z,H)} returns a list of two integer matrices\n{\\tt\\char`\\{A,E\\char`\\}} such that $$cone(Z) + \\mathit{affine}(H) = \\{ x \\in \\R^d \\mid A^t\nx \\leq 0, E^t x = 0\\}.$$ \nEquivalently, $(cone(Z) + \\mathit{affine}(H))^\\vee = cone(A) + \\mathit{affine}(E).$\n\nWe now describe each routine in the package {\\tt polarCone.m2}\\indexcmd{polarCone.m2}.  We have\nsimplified the code for readability, sometimes at the cost of efficiency.\nWe start with three simple subroutines: {\\tt primitive}, {\\tt toZZ}, and {\\tt\nrotateMatrix}. \n\n\\medskip\nThe routine {\\tt primitive} takes a list of integers {\\tt L}, and divides\neach element of this list by their greatest common denominator.\n\n\\beginOutput\ni87 : code primitive\\\\\n\\emptyLine\no87 = -- polarCone.m2:16-20\\\\\n\\      primitive = (L) -> (\\\\\n\\           n := #L-1;                    g := L#n;\\\\\n\\           while n > 0 do (n = n-1;      g = gcd(g, L#n);\\\\\n\\                if g === 1 then n = 0);\\\\\n\\           if g === 1 then L else apply(L, i -> i // g));\\\\\n\\endOutput\n\n\\medskip\nThe routine {\\tt toZZ} converts a list of rational numbers to a list of \nintegers, by multiplying by their common denominator.\n\\beginOutput\ni88 : code toZZ\\\\\n\\emptyLine\no88 = -- polarCone.m2:28-32\\\\\n\\      toZZ = (L) -> (\\\\\n\\           d := apply(L, e -> denominator e);\\\\\n\\           R := ring d#0;             l := 1_R;\\\\\n\\           scan(d, i -> (l = (l*i // gcd(l,i))));    \\\\\n\\           apply(L, e -> (numerator(l*e))));\\\\\n\\endOutput\n\n\\medskip\nThe routine {\\tt rotateMatrix} is a kind of transpose.  Its input is a\nmatrix, and its output is a matrix of the same shape as the transpose.\nIt places the matrix in the form so that in the routine {\\tt polarCone},\ncomputing a Gr\\\"obner basis will do the Gaussian elimination that is needed.\n\\beginOutput\ni89 : code rotateMatrix\\\\\n\\emptyLine\no89 = -- polarCone.m2:41-43\\\\\n\\      rotateMatrix = (M) -> (\\\\\n\\           r := rank source M;        c := rank target M;\\\\\n\\           matrix table(r, c, (i,j) -> M_(c-j-1, r-i-1)));\\\\\n\\endOutput\n\n\\medskip\nThe procedure of Fourier-Motzkin elimination as presented by \nZiegler in \\cite{HS:Zie} is used, together with some heuristics that he\npresents as exercises.  The following, which is a kind of $S$-pair\ncriterion for inequalities, comes from Exercise 2.15(i) in \\cite{HS:Zie}.\n\nThe routine {\\tt isRedundant} determines if a row vector (inequality)\nis redundant. Its input argument {\\tt V} is the same input that is\nused in {\\tt fourierMotzkin}: it is a list of sets of integers.  Each\nentry contains indices of the original rays that do {\\sl not} vanish\nat the corresponding row vector.  {\\tt vert} is a set of integers; the\noriginal rays for the row vector in question.  A boolean value is\nreturned.  \n\n\\beginOutput\ni90 : code isRedundant\\\\\n\\emptyLine\no90 = -- polarCone.m2:57-65\\\\\n\\      isRedundant = (V, vert) -> (\\\\\n\\           -- the row vector is redundant iff 'vert' contains an\\\\\n\\           -- entry in 'V'.\\\\\n\\           x := 0;            k := 0;\\\\\n\\           numRow := #V;      -- equals the number of inequalities\\\\\n\\           while x < 1 and k < numRow do (\\\\\n\\                if isSubset(V#k, vert) then x = x+1;\\\\\n\\                k = k+1;);     \\\\\n\\           x === 1);\\\\\n\\endOutput\n\n\\medskip\nThe main work horse of {\\tt polarCone.m2} is the subroutine \n{\\tt fourierMotzkin}, which eliminates the first variable in the\ninequalities {\\tt A} using the double description version of\nFourier-Motzkin elimination. The set {\\tt A} is a list of lists of\nintegers, each entry corresponding to a row vector in the system of\ninequalities.  The argument {\\tt V} is a list of sets of integers.\nEach entry contains the indices of the original rays that do {\\sl\n  not} vanish at the corresponding row vector in {\\tt A}.  Note that\nthis set is the {\\sl complement} of the set $V_i$ appearing in\nexercise 2.15 in \\cite{HS:Zie}. The argument {\\tt spot} is the integer\nindex of the variable being eliminated.  \n\nThe routine returns a list {\\tt \\char`\\{projA,projV\\char`\\}} where {\\tt projA} is\na list of lists of integers.  Each entry corresponds to a row vector\nin the projected system of inequalities.  The list {\\tt projV} is a\nlist of sets of integers.  Each entry contains indices of the original\nrays that do {\\sl not} vanish at the corresponding row vector in {\\tt\n  projA}. \n\n\\beginOutput\ni91 : code fourierMotzkin\\\\\n\\emptyLine\no91 = -- polarCone.m2:89-118\\\\\n\\      fourierMotzkin = (A, V, spot) -> (\\\\\n\\           -- initializing local variables\\\\\n\\           numRow := #A;               -- equal to the length of V\\\\\n\\           numCol := #(A#0);           pos := \\{\\};       \\\\\n\\           neg := \\{\\};                  projA := \\{\\};     \\\\\n\\           projV := \\{\\};                k := 0;\\\\\n\\           -- divide the inequalities into three groups.\\\\\n\\           while k < numRow do (\\\\\n\\                if A#k#0 < 0 then neg = append(neg, k)\\\\\n\\                else if A#k#0 > 0 then pos = append(pos, k)\\\\\n\\                else (projA = append(projA, A#k);\\\\\n\\                     projV = append(projV, V#k););\\\\\n\\                k = k+1;);      \\\\\n\\           -- generate new irredundant inequalities.\\\\\n\\           scan(pos, i -> scan(neg, j -> (vert := V#i + V#j;\\\\\n\\                          if not isRedundant(projV, vert)  \\\\\n\\                          then (iRow := A#i;     jRow := A#j;\\\\\n\\                               iCoeff := - jRow#0;\\\\\n\\                               jCoeff := iRow#0;\\\\\n\\                               a := iCoeff*iRow + jCoeff*jRow;\\\\\n\\                               projA = append(projA, a);\\\\\n\\                               projV = append(projV, vert););)));\\\\\n\\           -- don't forget the implicit inequalities '-t <= 0'.\\\\\n\\           scan(pos, i -> (vert := V#i + set\\{spot\\};\\\\\n\\                if not isRedundant(projV, vert) then (\\\\\n\\                     projA = append(projA, A#i);\\\\\n\\                     projV = append(projV, vert););));\\\\\n\\           -- remove the first column \\\\\n\\           projA = apply(projA, e -> e_\\{1..(numCol-1)\\});\\\\\n\\           \\{projA, projV\\});   \\\\\n\\endOutput\n\n\\medskip\nAs mentioned above, {\\tt polarCone} takes two matrices {\\tt Z, H},\nboth having $d$ rows, and outputs a pair of matrices {\\tt A, E} \nsuch that $(\\operatorname{cone}(Z) + \\operatorname{affine}(H))^\\vee =\n\\operatorname{cone}(A) + \\operatorname{affine}(E).$\n\n\\beginOutput\ni92 : code(polarCone,Matrix,Matrix)\\\\\n\\emptyLine\no92 = -- polarCone.m2:137-192\\\\\n\\      polarCone(Matrix, Matrix) := (Z, H) -> (\\\\\n\\           R := ring source Z;\\\\\n\\           if R =!= ring source H then error (\"polarCone: \" | \\\\\n\\                \"expected matrices over the same ring\");\\\\\n\\           if rank target Z =!= rank target H then error (\\\\\n\\                \"polarCone: expected matrices to have the \" |\\\\\n\\                \"same number of rows\");     \\\\\n\\           if (R =!= ZZ) then error (\"polarCone: expected \" | \\\\\n\\                \"matrices over 'ZZ'\");\\\\\n\\           -- expressing 'cone(Y)+affine(B)' as '\\{x : Ax <= 0\\}'\\\\\n\\           Y := substitute(Z, QQ);     B := substitute(H, QQ);   \\\\\n\\           if rank source B > 0 then Y = Y | B | -B;\\\\\n\\           n := rank source Y;         d := rank target Y;     \\\\\n\\           A := Y | -id_(QQ^d);\\\\\n\\           -- computing the row echelon form of 'A'\\\\\n\\           A = gens gb rotateMatrix A;\\\\\n\\           L := rotateMatrix leadTerm A;\\\\\n\\           A = rotateMatrix A;\\\\\n\\           -- find pivots\\\\\n\\           numRow = rank target A;                  -- numRow <= d\\\\\n\\           i := 0;                     pivotCol := \\{\\};\\\\\n\\           while i < numRow do (j := 0;\\\\\n\\                while j < n+d and L_(i,j) =!= 1_QQ do j = j+1;\\\\\n\\                pivotCol = append(pivotCol, j);\\\\\n\\                i = i+1;);\\\\\n\\           -- computing the row-reduced echelon form of 'A'\\\\\n\\           A = ((submatrix(A, pivotCol))^(-1)) * A;\\\\\n\\           -- converting 'A' into a list of integer row vectors \\\\\n\\           A = entries A;\\\\\n\\           A = apply(A, e -> primitive toZZ e);\\\\\n\\           -- creating the vertex list 'V' for double description\\\\\n\\           -- and listing the variables 'T' which remain to be\\\\\n\\           -- eliminated\\\\\n\\           V := \\{\\};                    T := toList(0..(n-1));\\\\\n\\           scan(pivotCol, e -> (if e < n then (T = delete(e, T);\\\\\n\\                          V = append(V, set\\{e\\});)));\\\\\n\\           -- separating inequalities 'A' and equalities 'E'\\\\\n\\           eqnRow := \\{\\};               ineqnRow := \\{\\};\\\\\n\\           scan(numRow, i -> (if pivotCol#i >= n then \\\\\n\\                     eqnRow = append(eqnRow, i)\\\\\n\\                     else ineqnRow = append(ineqnRow, i);));    \\\\\n\\           E := apply(eqnRow, i -> A#i);\\\\\n\\           E = apply(E, e -> e_\\{n..(n+d-1)\\});\\\\\n\\           A = apply(ineqnRow, i -> A#i);\\\\\n\\           A = apply(A, e -> e_(T | toList(n..(n+d-1)))); \\\\\n\\           -- successive projections eliminate the variables 'T'.\\\\\n\\           if A =!= \\{\\} then scan(T, t -> (\\\\\n\\                     D := fourierMotzkin(A, V, t);\\\\\n\\                     A = D#0;          V = D#1;));\\\\\n\\           -- output formating\\\\\n\\           A = apply(A, e -> primitive e);\\\\\n\\           if A === \\{\\} then A = map(ZZ^d, ZZ^0, 0)\\\\\n\\           else A = transpose matrix A;\\\\\n\\           if E === \\{\\} then E = map(ZZ^d, ZZ^0, 0)\\\\\n\\           else E = transpose matrix E;\\\\\n\\           (A, E)); \\\\\n\\endOutput\n\nIf the input matrix $H$ has no columns, it can be omitted.  A sequence of two\nmatrices is returned, as above.\n\\beginOutput\ni93 : code(polarCone,Matrix)\\\\\n\\emptyLine\no93 = -- polarCone.m2:199-200\\\\\n\\      polarCone(Matrix) := (Z) -> (\\\\\n\\           polarCone(Z, map(ZZ^(rank target Z), ZZ^0, 0)));\\\\\n\\endOutput\n\nAs a simple example, consider the permutahedron in $\\R^3$ \nwhose vertices are the following six points. \n\n\\beginOutput\ni94 : H = transpose matrix\\{\\\\\n\\      \\{1,2,3\\},\\\\\n\\      \\{1,3,2\\},\\\\\n\\      \\{2,1,3\\},\\\\\n\\      \\{2,3,1\\},\\\\\n\\      \\{3,1,2\\},\\\\\n\\      \\{3,2,1\\}\\};\\\\\n\\emptyLine\n\\               3        6\\\\\no94 : Matrix ZZ  <--- ZZ\\\\\n\\endOutput\n\nThe inequality representation of the permutahedron is obtained \nby calling {\\tt polarCone} on $H$: the facet normals of the \npolytope are the columns of the matrix in the first argument of the \noutput. The second argument is trivial since our input is a polytope \nand hence there are is no non-trivial affine space contained in it.\nIf we call {\\tt polarCone} on the output, we will get back H as\nexpected. \n\n\\beginOutput\ni95 : P = polarCone H\\\\\n\\emptyLine\no95 = (| 1  1  1  -1 -1 -5 |, 0)\\\\\n\\       | -1 1  -5 1  -1 1  |\\\\\n\\       | -1 -5 1  -1 1  1  |\\\\\n\\emptyLine\no95 : Sequence\\\\\n\\endOutput\n\\beginOutput\ni96 : Q = polarCone P_0\\\\\n\\emptyLine\no96 = (| 1 1 2 2 3 3 |, 0)\\\\\n\\       | 2 3 1 3 1 2 |\\\\\n\\       | 3 2 3 1 2 1 |\\\\\n\\emptyLine\no96 : Sequence\\\\\n\\endOutput\n \n\n\\section{Minimal Presentation of Rings}\\label{Mpor}\n\nThroughout this chapter, we have used on several occasions the simple, yet\nuseful subroutine {\\tt removeRedundantVariables}.\nIn this appendix, we present \\Mtwo code for this routine,\nwhich is the main ingredient for finding minimal\npresentations of quotients of polynomial rings.\nOur code for this routine is a somewhat simplified, but less\nefficient version of a routine in the \\Mtwo package, {\\tt minPres.m2}\\indexcmd{minPres.m2},\nwritten by Amelia Taylor.\n\nThe routine {\\tt removeRedundantVariables} takes as input an ideal {\\tt I} in\na polynomial ring {\\tt A}.  It returns a ring map {\\tt F} from {\\tt A} to\nitself that sends redundant variables to polynomials in the non-redundant\nvariables and sends non-redundant variables to themselves.  For example:\n  \\beginOutput\ni97 : A = QQ[a..e];\\\\\n\\endOutput\n  \\beginOutput\ni98 : I = ideal(a-b^2-1, b-c^2, c-d^2, a^2-e^2)\\\\\n\\emptyLine\n\\                2             2         2       2    2\\\\\no98 = ideal (- b  + a - 1, - c  + b, - d  + c, a  - e )\\\\\n\\emptyLine\no98 : Ideal of A\\\\\n\\endOutput\n  \\beginOutput\ni99 : F = removeRedundantVariables I\\\\\n\\emptyLine\n\\                8       4   2\\\\\no99 = map(A,A,\\{d  + 1, d , d , d, e\\})\\\\\n\\emptyLine\no99 : RingMap A <--- A\\\\\n\\endOutput\nThe non-redundant variables are $d$ and $e$.  The image of $I$ under $F$\ngives the elements in this smaller set of variables.  We take the ideal of a \nGr\\\"obner basis of the image:\n  \\beginOutput\ni100 : I1 = ideal gens gb(F I)\\\\\n\\emptyLine\n\\              16     8    2\\\\\no100 = ideal(d   + 2d  - e  + 1)\\\\\n\\emptyLine\no100 : Ideal of A\\\\\n\\endOutput\nThe original ideal can be written in a cleaner way as\n  \\beginOutput\ni101 : ideal compress (F.matrix - vars A) + I1\\\\\n\\emptyLine\n\\               8           4       2       16     8    2\\\\\no101 = ideal (d  - a + 1, d  - b, d  - c, d   + 2d  - e  + 1)\\\\\n\\emptyLine\no101 : Ideal of A\\\\\n\\endOutput\n  \n  Let us now describe the \\Mtwo code.  The subroutine {\\tt\n    findRedundant} takes a polynomial $f$, and finds a variable $x_i$\n  in the ring of $f$ such that $f = c x_i + g$ for a non-zero\n  constant $c$ and a polynomial $g$ that does not involve the\n  variable $x_i$.  If there is no such variable, {\\tt null} is\n  returned.  Otherwise, if $x_i$ is the first such variable , the list\n  $\\{i, c^{-1} g\\}$ is returned.\n\n\\beginOutput\ni102 : code findRedundant\\\\\n\\emptyLine\no102 = -- minPres.m2:1-12\\\\\n\\       findRedundant=(f)->(\\\\\n\\            A := ring(f);\\\\\n\\            p := first entries contract(vars A,f);\\\\\n\\            i := position(p, g -> g != 0 and first degree g === 0);\\\\\n\\            if i === null then\\\\\n\\                null\\\\\n\\            else (\\\\\n\\                 v := A_i;\\\\\n\\                 c := f_v;\\\\\n\\                 \\{i,(-1)*(c^(-1)*(f-c*v))\\}\\\\\n\\                 )\\\\\n\\            )\\\\\n\\endOutput\n\nThe main function {\\tt removeRedundantVariables} requires an ideal in a\npolynomial ring (not a quotient ring) as input.  The internal\nroutine {\\tt findnext} finds the first entry of the (one row) matrix {\\tt M}\nthat contains a redundancy.  This redundancy is used to modify the list {\\tt\nxmap}, which contains the images of the redundant variables.\nThe matrix {\\tt M}, and the list {\\tt xmap} are both updated, and \nthen we continue to look for more redundancies.\n\n\\beginOutput\ni103 : code removeRedundantVariables\\\\\n\\emptyLine\no103 = -- minPres.m2:14-39\\\\\n\\       removeRedundantVariables = (I) -> (\\\\\n\\            A := ring I;\\\\\n\\            xmap := new MutableList from gens A;       \\\\\n\\            M := gens I;\\\\\n\\            findnext := () -> (\\\\\n\\                 p := null;\\\\\n\\                 next := 0;\\\\\n\\                 done := false;\\\\\n\\                 ngens := numgens source M;\\\\\n\\                 while next < ngens and not done do (\\\\\n\\                   p = findRedundant(M_(0,next));\\\\\n\\                   if p =!= null then\\\\\n\\                        done = true\\\\\n\\                   else next=next+1;\\\\\n\\                 );\\\\\n\\                 p);\\\\\n\\            p := findnext();\\\\\n\\            while p =!= null do (\\\\\n\\                 xmap#(p#0) = p#1;\\\\\n\\                 F1 := map(A,A,toList xmap);\\\\\n\\                 F2 := map(A,A, F1 (F1.matrix));\\\\\n\\                 xmap = new MutableList from first entries F2.matrix;\\\\\n\\                 M = compress(F2 M);\\\\\n\\                 p = findnext();\\\\\n\\                 );\\\\\n\\            map(A,A,toList xmap));\\\\\n\\endOutput\n", "meta": {"hexsha": "752493248f0cf98384eccf49ad94942307409b4e", "size": 100678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/ComputationsBook/chapters/toricHilbertScheme/chapter-m2.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/toricHilbertScheme/chapter-m2.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/toricHilbertScheme/chapter-m2.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.329228243, "max_line_length": 114, "alphanum_fraction": 0.6210492858, "num_tokens": 35599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6566180293180305}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[legalpaper, portrait, margin=1in]{geometry}\n\n\\title{Calculus Q.2}\n\\author{Shreenabh Agrawal}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\n\nEvaluate the Integral:\n$$\\int\\limits_{0}^{\\infty} \\frac{\\left(x^{2}-1\\right) \\ln x}{1+x^{6}} \\: d x$$\n\\section{Solution}\n\nTaking Substitution,\n$$\\begin{aligned}\nx &=\\tan ^{1 / 3} \\theta \\\\\nd x &=\\frac{1}{3} \\tan ^{-2 / 3} \\theta \\sec ^{2} \\theta \\: d \\theta\n\\end{aligned}$$\nThe Integral Becomes,\n\n$$\\begin{aligned}\n{\\Rightarrow} I &=\\frac{1}{3} \\int\\limits_{0}^{\\pi / 2} \\frac{\\left(\\tan ^{2 / 3} \\theta-1\\right) \\ln (\\tan \\theta)}{1+\\tan ^{2} \\theta}\\left(\\frac{\\tan ^{-2 / 3} \\theta \\sec ^{2} \\theta \\: d \\theta}{3}\\right) \\\\\n&=\\frac{1}{9} \\int\\limits_{0}^{\\pi / 2}\\left(1-\\tan ^{-2 / 3} \\theta\\right) \\ln \\tan \\theta \\: d \\theta\n\\end{aligned}$$\nWe know the Formula,\n\n$$\\int\\limits_{0}^{\\pi / 2} \\tan ^{n}(x) \\log (\\tan (x)) d x=\\pi^{2} \\sin ^{3}\\left(\\frac{\\pi n}{2}\\right) \\csc ^{2}(\\pi n)$$\n\n\\begin{flushright}\n[For $-1<n<1$]\n\\end{flushright}\nUsing this, and Splitting the Integral,\n\n$$\\begin{aligned}\n\\Rightarrow I  \n&= \\frac{1}{9}\\left[\\int\\limits_{0}^{\\pi / 2} \\ln (\\tan \\theta) \\: d \\theta-\\int\\limits_{0}^{\\pi / 2}\\left(\\tan ^{-2 / 3} \\theta\\right) \\ln (\\tan \\theta) \\: d \\theta\\right]\\\\\n&=\\frac{1}{9}\\left[0-\\pi^{2} \\sin ^{3}\\left(\\frac{\\pi}{3}\\right) \\csc ^{2}\\left(\\frac{\\pi}{3}\\right)\\right]\n\\end{aligned}$$\n\nThus, the final answer is:\n$$\\boxed{I=\\frac{\\pi^{2}}{6 \\sqrt{3}}}$$\n\n\\end{document}\n", "meta": {"hexsha": "dd0c0da800d643b4614e04132de539c497409667", "size": 1571, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/all.about.mathematics' questions/Calculus #2.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/all.about.mathematics' questions/Calculus #2.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/all.about.mathematics' questions/Calculus #2.tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 30.8039215686, "max_line_length": 212, "alphanum_fraction": 0.6040738383, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541067, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6566180250127682}}
{"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\\begin{python}\ndef pivot(self, A, i, j):\n    \"\"\"\n    pivoting algorithm:\n    | p | closed set | open set |\n    | closed set | p | open set |\n    \"\"\"\n    p = i\n    closed = p\n    for ptr in xrange(i, j):\n        if A[ptr] < A[p]:\n            closed += 1\n            A[ptr], A[closed] = A[closed], A[ptr]\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}\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:\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            gt -= 1\n            A[gt], A[i] = A[i], A[gt]\n        else:\n            i += 1\n\n    return lt+1, gt\n\\end{python}\n\\subsection{Merge Sort}\nTODO\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{Sort 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{Summary}\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=0.80]{sort_summary}}\n\\caption{Sort summary}\n\\label{fig:trie} \n\\end{figure}\n\\section{Partial Quicksort}\n\\subsection{Find $m$ smallest}\n\\runinhead{Heap-based solution.} $O(n \\log m)$\n\\runinhead{Partial Quicksort}  Then the $A[:m]$ is sorted $m$ smallest. The algorithm recursively sort the $A[i:j]$\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 m$} \\\\\n  2F(\\frac{n}{2})+O(n) &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\nTherefore, the complexity is $O(n+m \\log m)$.\n\\begin{python}\ndef partial_qsort(self, A, i, j, m):\n    if i >= j: return\n\n    p = self.pivot(A, i, j)\n    self.partial_qsort(A, i, p, m)\n    if p+1 >= m: return\n    self.partial_qsort(A, p+1, j, m)\n\\end{python}\n\n\\subsection{Find $k$-th}\nUse partial quick sort to find $k$-th smallest element in the unsorted array. The algorithm recursively sort the $A[i:j]$\n\nThe average time complexity is\n\\begin{align*}\nF(n) &= F(n/2) + O(n) \\\\\n&= O(n)\n\\end{align*}\n\\begin{python}\ndef find_kth(self, A, i, j, k):\n    if i >= j: return\n    \n    p = self.pivot(A, i, j)\n    if p == k: return A[p]\n    if p > k:  return self.find_kth(A, i, p, k)\n    else:      return self.find_kth(A, p+1, j, k)\n\\end{python}\nPivoting see section - \\ref{section:pivot}.\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\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 an index/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\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, start, end, cnt):\n    self.start = start\n    self.end = end\n    self.cnt = cnt\n\n    self.left = None\n    self.right = None\n\n  def __repr__(self):\n    return repr(\"[%d,%d)\" % (self.start, self.end))\n\n\nclass SegmentTree(object):\n  \"\"\"empty space\"\"\"\n  def __init__(self):\n    self.root = None\n\n  def build(self, start, end):\n    \"\"\"a node can have right ONLY IF has left\"\"\"\n    if start >= end:\n      return\n\n    root = Node(start, end, end-start)\n    root.left = self.build(start, (end+start)/2)\n    if root.left: \n      root.right = self.build((start+end)/2, end)\n    return root\n\n  def find_delete(self, root, val):\n    \"\"\"\n    :return: index\n    \"\"\"\n    root.cnt -= 1\n    if not root.left:\n      return root.start\n    elif root.left.cnt >= val:\n      return self.find_delete(root.left, val)\n    else:\n      return self.find_delete(root.right, \n                              val - 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\nif __name__ == \"__main__\":\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", "meta": {"hexsha": "294c45047b825aa5bfef8e3662a062168a072d98", "size": 12787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterSort.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": "chapterSort.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": "chapterSort.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.5311778291, "max_line_length": 274, "alphanum_fraction": 0.6469852194, "num_tokens": 3825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.6566024315508653}}
{"text": "\\section{Testing for Weak Instruments}\nTesting for presence of weak instruments is, at the time of writing, an active field of research. For a detailed overview, see \\cite{stock2002survey}. For the purpose of our study, we limit our attention to two tests - the widely-used first-stage F-statistic and the Anderson-Rubin Test, which has gained resurgence in recent years in light of new developments in instrumental variables research. \n\n\\subsection{Defining the `Weakness' precisely}\n\\cite{stock2002testing} posit that the definition of weak instruments depends on the inferential task to be carried out, and cannot be resolved in the abstract. One approach is to define a set of instruments to be weak if $\\mu^2/K$\nis small enough that inferences based on conventional normal\napproximating distributions are misleading. For instance, if a researcher wants their 2SLS estimate bias to be small, one measure\nof whether an instrument(s) is strong is whether $\\mu^2/K$ is\nlarge enough such that the 2SLS relative bias (relative to the bias of ordinary least squares) is below a certain threshold, for example the relative bias is below 10\\%. Hence, to be deemed a `weak' instrument, the 2SLS estimate using that instrument should have relative bias above 10\\%. The definition we discussed (and use for our simulation) is based on relative bias, another definition (for instance on size of test) may result in a different cut-off value.\n\n\n\\subsection{First Stage F-statistic}\nThe first-stage F-statistic is the F-statistic testing the hypothesis that the coefficients on the instruments equal zero ($\\pi=0$) in the first stage of two stage least squares. \n\\cite{stock2002testing} show that the definition of weak instruments discussed above implies a threshold value for $\\mu^2/K$, under weak asymptotics. A weak instrument will have a $\\mu^2/K$ value (and hence, an F-statistic value, since F$-$1 can be treated as an estimator of $\\mu^2/K$ as discussed in Section 2.2) lower than the threshold.\nFor the case of a single endogenous regressor, \\cite{staiger1997stock} provide a rule-of thumb threshold of 10: a value less than 10 indicates that the instruments are weak, in which case the 2SLS estimator is biased and 2SLS t-statistics and confidence intervals are unreliable.\n\n\\cite{stock2002survey} provide a table listing critical values of the first-stage F-statistic such that the relative bias of 2SLS estimates is greater than 10\\%, for different numbers of instruments. The authors arrived at those critical values based on weak-instrument asymptotic approximations. We include a subset of this table (which is relevant for our simulations) as Table B.1 in appendix B for reference.\n\n\n\\subsection{Anderson-Rubin Test}\n\n\nThe AR test is a hypothesis test that has the property of being valid whether instruments are strong, weak or even irrelevant ($\\pi=0$). It tests the null hypothesis $\\beta$ = $\\beta_0$ using the statistic. It was proposed by \\cite{anderson1949estimation}.\n\n\\begin{equation}\n  AR(\\beta) = \\frac{(\\mathbf Y- \\mathbf X\\beta)' P_z (\\mathbf Y-\\mathbf X\\beta)/K}{(\\mathbf Y-\\mathbf X\\beta)' \\mathbf M_Z (\\mathbf Y-\\mathbf X\\beta)/(N-K)}\n        \\end{equation}\n        \nOne definition of the LIML estimator is that it minimizes\n$AR(\\beta)$.\nWith fixed instruments and normal errors, the quadratic\nforms in the numerator and denominator of (3.1) are independent\nchi-squared random variables under the null hypothesis,\nand $AR(\\beta_0)$ has an exact $F_{K,T - K}$ null distribution. Under the more general conditions of weak-instrument asymptotics, $AR(\\beta_0)$ $\\xrightarrow{\\text{d}}$ ${\\chi_k}^2/K$ under the null hypothesis, regardless of the\nvalue of $\\mu^2/K$. Thus the AR statistic provides a fully robust\ntest of the hypothesis $\\beta$ = $\\beta_0$.\n\\par The set of\nvalues of $\\beta$ that are not rejected by a 5\\% Anderson–Rubin test will constitute a 95\\% confidence\nset for $\\beta$. The logic behind the Anderson–Rubin statistic is that it\nnever assumes instrument relevance, and the AR confidence set will have a\ncoverage probability of 95\\% in large samples, regardless of the strength or weakness of instruments.\nIn light of the importance given to the problem of weak instruments in recent years, this test has gained traction among econometricians, who increasingly advocate for its use for robust inference with weak instruments (See \\cite{staiger1997stock}). Particularly, recent research has shown the AR confidence set to be optimal in the single-endogenous-regressor just-identified setting.", "meta": {"hexsha": "0efdad8af53fc2568e1c8cd3d1331965a0c23ce3", "size": 4529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03.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": "ch03.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": "ch03.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": 107.8333333333, "max_line_length": 463, "alphanum_fraction": 0.7820710974, "num_tokens": 1076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.6564820331140091}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[colorlinks]{hyperref}\n\\usepackage{amsmath,esint}\n\\title{Green's Theorem}\n\\author{Naitree Zhu}\n\\date{Last modified: \\today}\n\\begin{document}\n\\maketitle\nIn mathematics, Green's theorem\\footnote{For more information:\\url{http://en.wikipedia.org/wiki/Green\\%27s_Theorem}} gives the relationship between a line integral around a simple closed curve $\\partial\\Sigma$ and a double integral over the plane region $\\Sigma$ bounded by $\\partial\\Sigma$. It is named after George Green and is the two-dimensional special case of the more general Stokes' theorem.\n\\part{Theorem}\nLet $\\partial\\Sigma$ be a positively oriented, piecewise smooth, simple closed curve in a plane, and let $\\Sigma$ be the region bounded by $\\partial\\Sigma$. If P and Q are functions of (\\textit{x, y}) defined on an open region containing $\\Sigma$ and have continuous partial derivatives there, then\n\\begin{equation}\n\\iint_\\Sigma \\left(\\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y}\\right)\\mathrm{d}x\n\\mathrm{d}y=\\oint_{\\partial\\Sigma} \\left\\lbrace P\\mathrm{d}x+Q\\mathrm{d}y\\right\\rbrace\n\\end{equation}\nwhere the path of integration along $\\partial\\Sigma$ is counterclockwise.\n\\part{Relationship to the Stokes theorem}\nGreen's theorem is a special case of the Kelvin–-Stokes theorem, when applied to a region in the \\textit{xy}-plane.\n\\part{Relationship to the divergence theorem}\nConsidering only two-dimensional vector fields, Green's theorem is equivalent to the two-dimensional version of the divergence theorem\n\\begin{equation}\n\\iint_\\Sigma\\left(\\nabla\\cdot\\boldsymbol{F}\\right)\\mathrm{d}S=\\oint_{\\partial\\Sigma}\\boldsymbol{F}\\cdot\\hat{n}\\mathrm{d}l\n\\end{equation}\n\\textbf{F} is the two-dimensional vector field, and $\\hat{n}$ is the outward-pointing unit normal vector on the boundary.\n\\section*{Proof}\nLet $\\boldsymbol{F}=(Q,-P)$. If angle of $\\hat{n}$ to the x-axis is $\\theta$,then outward-pointing unit normal vector $\\hat{n}=(cos\\theta-sin\\theta)$, and $\\mathrm{d}\\boldsymbol{l}=(-sin\\theta,cos\\theta)\\mathrm{d}l$, apply them to eq.~(2), we can easily deduce to eq.~(1) from eq.~(2).\n\\part{Area Calculation}\nGreen's theorem can be used to compute area by line integral,which can be achieved simply by choosing P and Q satisfying $\\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y}=1$.\nThus, area of $\\Sigma$ can be calculated by line integral which is \n\\begin{equation}\nA=\\oint_{\\partial\\Sigma} \\left\\lbrace P\\mathrm{d}x+Q\\mathrm{d}y\\right\\rbrace\n\\end{equation}\nPossible formulas for calculating the area of $\\Sigma$ include:\n\\[\nA=\\oint_{\\partial\\Sigma} x\\mathrm{d}y=-\\oint_{\\partial\\Sigma} y\\mathrm{d}x=\\frac{1}{2}\\oint_{\\partial\\Sigma}\\left(-y\\mathrm{d}x+x\\mathrm{d}y\\right)\n\\]\n\\end{document}", "meta": {"hexsha": "108cfc54cd825f61e69eff5421f3e07e94aaa2fb", "size": 2737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/Green's Theorem/Green's 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/Green's Theorem/Green's 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/Green's Theorem/Green's 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": 73.972972973, "max_line_length": 399, "alphanum_fraction": 0.7544757033, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6564820327383409}}
{"text": "%!TEX root = ../main.tex\n\n%=============================================================================== \n%\n%    Chapter: vectors\n%\n%=============================================================================== \n\n\\chapter{Vectors}\n\\label{chapter:vectors}\n\nIn this chapter we'll learn how to manipulate multi-dimensional objects called vectors.\t\t\t\t\t\t\\index{vector|textbf}\nVectors are the precise way to describe directions in space.\nWe need vectors in order to describe physical quantities like forces, velocities, and accelerations.\n\nVectors are built from ordinary numbers,\nwhich form the \\emph{components} of the vector.\nYou can think of a vector as a list of numbers,\nand \\emph{vector algebra} as operations\nperformed on the numbers in the list.\nVectors can also be manipulated as geometric objects,\nrepresented by arrows in space.\nFor instance, the arrow that corresponds to the vector $\\vec{v}=(v_x,v_y)$ starts at the origin $(0,0)$\nand ends at the point $(v_x,v_y)$.\nThe word vector comes from the Latin \\emph{vehere},\nwhich means \\emph{to carry}.\nIndeed, the vector $\\vec{v}$ takes the point $(0,0)$ and carries it to the point $(v_x,v_y)$.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.4\\textwidth]{figures/vectors/vector_components.pdf}\n\t\\vspace{-2mm}\n\t\\caption{\tThe vector $\\vec{v}=(3,2)$ is an arrow in the Cartesian plane.\n\t\t\tThe horizontal component of $\\vec{v}$ is $v_x=3$\n\t\t\tand the vertical component  is $v_y=2$.}\n\t\\label{fig:vector_components}\n\\end{figure}\n\n\n\n\n", "meta": {"hexsha": "4f18ef2cd1b11aeb6fd0c75c853f0279526dba5b", "size": 1495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sources/original/03_vecs/00.vectors.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/03_vecs/00.vectors.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/03_vecs/00.vectors.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": 35.5952380952, "max_line_length": 114, "alphanum_fraction": 0.6602006689, "num_tokens": 362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6564820307886413}}
{"text": "\\chapter{Quasi-atoms}\n\n\\begin{defn}\n\\emph{Quasi-atoms} funcoid~$\\mathscr{A}$ is the funcoid $A\\rightarrow \\atoms^{\\mathfrak{A}} A$ defined by the formula\n$\\rsupfun{\\mathscr{A}} X = \\atoms^{\\mathfrak{A}} X$.\n\\end{defn}\n\nThis really defines a funcoid because $\\atoms^{\\mathfrak{A}} \\bot = \\emptyset$ and\n$\\atoms^{\\mathfrak{A}}(X\\cup Y) = \\atoms^{\\mathfrak{A}}X\\cup\\atoms^{\\mathfrak{A}}Y$.\n\n\\begin{obvious}\n$\\mathscr{A}$ is a co-complete funcoid.\n\\end{obvious}\n\n\\begin{prop}\n$\\rsupfun{\\mathscr{A}^{-1}} Y = \\bigsqcup Y$.\n\\end{prop}\n\n\\begin{proof}\n$Y \\nasymp \\left\\langle \\mathscr{A} \\right\\rangle^{\\ast} X \\Leftrightarrow Y\n\\nasymp \\atoms^{\\mathfrak{A}} X \\Leftrightarrow \\exists x \\in\n\\atoms^{\\mathfrak{A}} X, y \\in Y : x \\nasymp y \\Leftrightarrow \\exists y\n\\in Y : X \\nasymp y \\Leftrightarrow \\text{(because $X$ is a principal filter)}\n\\Leftrightarrow X \\nasymp \\bigsqcup Y$.\n\\end{proof}\n\nNote\n$\\rsupfun{\\mathscr{A}} \\mathcal{X} =\n\\bigsqcap^{\\mathscr{F}}_{X \\in \\up \\mathcal{X}}\n\\atoms^{\\mathfrak{A}} X$;\n\n$\\rsupfun{\\mathscr{A}^{-1}} \\mathcal{Y} =\n\\bigsqcap^{\\mathscr{F}}_{Y \\in \\up \\mathcal{Y}} \\bigsqcup Y$\n($\\mathcal{Y}$ is filter on the set of ultrafilters).\n\nCan $\\atoms^{\\mathfrak{A}} \\mathcal{X}$ be restored knowing $\\supfun{\\mathscr{A}} \\mathcal{X}$?\nCan $\\bigsqcup \\mathcal{Y}$ be restored knowing $\\supfun{\\mathscr{A}^{-1}} \\mathcal{X}$?\n\n\\begin{prop}\n(Provided that~$A$ is infinite) $\\mathscr{A}$ is not complete.\n\\end{prop}\n\n\\begin{proof}\nTake a nonprincipal ultrafilter~$x$. Then $\\rsupfun{\\mathscr{A}^{-1}}\\{x\\} = \\bigsqcup\\{x\\} = x$\nis a nonprincipal filter.\n\\end{proof}\n\n\\begin{conjecture}\nThere is such filter~$\\mathcal{X}$ that $\\rsupfun{\\mathscr{A}} \\mathcal{X}$ is non-principal.\n\\end{conjecture}\n\nDoes quasi-atoms funcoid define a more elegant replacement of $\\atoms^{\\mathfrak{A}}$? Does this concept have any use?", "meta": {"hexsha": "24aa469397cbca36d595adc0febdbfd0e288c947", "size": 1836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-quasiatoms.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-quasiatoms.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-quasiatoms.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": 35.3076923077, "max_line_length": 118, "alphanum_fraction": 0.6775599129, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6563393358633832}}
{"text": "\\chapter[\\ulex]{Theory: \\ulex}\\label{ch:ulex-theory}\n\n{\\Large NOTE: this chapter has been integrated into a paper, and thereafter much improved.  In the near future, the paper will be re-adapted to replace this chapter.}\n\n\\section{Regular expressions}\n\nThroughout this section, we assume an \\emph{alphabet} $\\Sigma$; any $a \\in \\Sigma$ is a \\emph{symbol}.  Since we support unicode, $\\Sigma$ can be quite large.  Our abstract regular expression (RE) language is as follows:\n\n\\Grammar{\n\\GFirst{\\rm RE}{\\epsilon}{empty string}\n\\GNext{\\CS}{symbol set, $\\CS \\subseteq \\Sigma$}\n\\GNext{\\rm RE\\cdot RE}{concatenation}\n\\GNext{\\rm RE^*}{Kleene-closure}\n\\GNext{\\rm RE \\OR RE}{alternation (union)}\n\\GNext{\\rm RE \\AND RE}{intersection}\n\\GNext{\\neg \\rm RE}{negation}\n}\n\nNote that we treat symbol sets (\\ie{}, character classes) as primitive; this matches the implementation strategy and simplifies the description of DFA generation.  With this representation, the empty set $\\emptyset$ and the alphabet $\\Sigma$ are both treated as symbol sets.  The former will yield an RE that matches no input (\\ie{}, $\\CL\\Sem{\\emptyset} = \\emptyset$), and the latter will match any single symbol.  Notice also that our language of REs allows for intersection and negation in addition to the standard operations.\n\nThe semantics of our RE language are given in the form of a function $\\Ls{-} \\ : \\ \\mathrm{RE} \\rightarrow \\Sigma^*$ from REs to their corresponding language over $\\Sigma$:\n\n\\begin{eqnarray*}\n\\Ls{\\epsilon} \t&=& \t\\epsilon \\\\\n\\Ls{\\CS}\t\t&=& \t\\CS \\\\\n\\Ls{r\\cdot s}\t&=& \t\\Ls{r} \\cdot \\Ls{s} \\\\\n\\Ls{r^*}\t\t&=& \t\\epsilon \\cup \\Ls{r}\\cdot\\Ls{r^*} \\\\\n\\Ls{r \\OR s}\t&=&\t\t\\Ls{r} \\cup \\Ls{s} \\\\\n\\Ls{r \\AND s}\t&=& \t\\Ls{r} \\cap \\Ls{s} \\\\\n\\Ls{\\neg r}\t\t&=& \t\\Sigma \\setminus \\Ls{r}\n\\end{eqnarray*}\n\n\\section{Derivatives}\\label{sec:derivatives}\n\nBrzozowski introduced \\emph{derivatives} of regular expressions as an alternative means of DFA construction \\cite{derivatives}.  His approach is attrative because it easily allows the language of REs to be extended with arbitrary boolean operations.  Further, it is intuitive, relatively easy to implement, goes directly from an RE to a DFA, and with some care in implementation can be made competitive with other DFA construction approaches.  We begin by introducing the notion of a derivative of some language $\\CL$.\n\n\\begin{definition}  The \\New{derivative} of a set of symbol sequences $\\CL \\subset \\Sigma^*$ with respect to a finite symbol sequence $u$ is defined to be $D_u(\\CL) = \\{ v \\ | \\ u\\cdot v \\in \\CL \\}$.\n\\end{definition} \n\nDerivatives give a very natural algorithm for DFA construction.  Before giving that algorithm, however, we need a means of computing derivatives for regular expressions.\n\n\\begin{definition} A regular expression $\\RE$ is \\New{nullable} if the language it defines contains the empty string, that is, if $\\epsilon \\in \\Ls{\\RE}$.\n\\end{definition}\n\nWe also need the following function:\n\\[ \\delta(\\RE) =\n    \\begin{cases}\n        \\epsilon & \\textrm{if} \\ \\epsilon \\in \\CL\\Sem{\\RE} \\\\\n        \\emptyset & \\textrm{if} \\ \\epsilon \\notin \\CL\\Sem{\\RE}\n    \\end{cases}\n\\]\nThe $\\delta$ function takes REs to REs (recall that the empty set is a symbol set, which is an RE).  Intuitively, $\\delta$ collapses an RE to the ``smallest'' RE with the same nullability.\n\nThe following function, due to Brzozowski, gives the derivative of a regular expression with respect to a symbol $a$.  \n\\begin{eqnarray*}\nD_a (\\epsilon)  &=& \\emptyset \\\\\nD_a (\\CS)         &=& \n    \\begin{cases}\n        \\epsilon & \\textrm{if} \\ a \\in \\CS \\\\\n        \\emptyset & \\textrm{if} \\ a \\notin \\CS \\\\\n    \\end{cases} \\\\\nD_a (r \\cdot s) &=& D_a(r)\\cdot s \\OR \\delta(r) \\cdot D_a(s) \\\\\nD_a (r^*)       &=& D_a(r) \\cdot r^* \\\\\nD_a (r \\OR s)   &=& D_a(r) \\OR D_a(s) \\\\\nD_a (r \\AND s)  &=& D_a(r) \\AND D_a(s) \\\\\nD_a (\\neg r)    &=& \\neg D_a(r)\n\\end{eqnarray*}\n\nWe can take the derivative of an RE with respect to a sequence of symbols in a straightforward way:\n\\begin{eqnarray*}\nD_\\epsilon (r) &=& r \\\\\nD_{ua} (r) &=& D_a(D_u(r))\n\\end{eqnarray*}\n\nIntuitively, the derivative of an RE with respect to a symbol $a$ yields a new RE after matching $a$.  The following two theorems, again due to Brzozowski, make this precise.\n\n\\begin{theorem} The derivative $D_s(\\RE)$ of any regular expression $\\RE$ with respect to any sequence $u$ is a regular expression.\n\\end{theorem}\n\n\\begin{theorem} A sequence $u$ is contained in $\\Ls{\\RE}$ if and only if $\\Ls{D_u(\\RE)}$ is nullable.\n\\end{theorem}\n\nDerivatives provide an easy method of DFA construction.  Suppose we want to build a DFA that recognizes $\\RE$.  We can think of each state of the DFA as a regular expression.  We start with a state $Q_0$ that represents $\\RE$.  We then take the derivative of $\\RE$ with respect to each symbol of the alphabet and create a new state each time a new derivative is found, adding each new state to the work list.  We pop a state from the work list and repeat, until the work list is empty.  There will be a transition from $Q_j$ to $Q_k$ if and only if (identifying states and their REs) $D_a (Q_j) = Q_k$ for some symbol $a$; the transition will be labeled with the set of all such $a$.  Finally, any state that represents a nullable RE is an accepting state.  The correctness of the recognizer is a direct consequence of the above theorems.\n\nThe sketch glosses over several important details.  First, what notion of equality do we intend for the equation $D_a (Q_j) = Q_k$?  Ideally, we would identify as a single state all those REs which admit the same language, so that $D_a (Q_j) = Q_k$ if and only if $\\Ls{D_a (Q_j)} = \\Ls{Q_k}$.  This is expensive to compute, so Brzozowski introduced the notion of RE similarity, an equivalence on REs which is easy to compute but still guarantees that the DFA is finite.\n\nLet $\\approx$ denote the least equivalence relation on REs such that\n\\begin{eqnarray*}\nr \\OR r &\\approx& r \\\\\nr \\OR s &\\approx& s \\OR r \\\\\n(r \\OR s) \\OR t &\\approx& r \\OR (s \\OR t)\n\\end{eqnarray*}\n\n\\begin{definition} Two regular expressions $r$ and $s$ are \\New{similar} if $r \\approx s$ and are \\New{dissimilar} otherwise.\n\\end{definition}\n\n\\begin{theorem} Every regular expression has only a finite number of dissimilar derivatives.\n\\end{theorem}\n\nHence, DFA construction is guaranteed to succeed if new states are only created when no existing state is similar to a given derivative.  In fact, we want to do much better then this to avoid blowup in DFA size.\n\n\\begin{remark}\nIn a practical implementation of DFA construction using derivatives, it is crucial to aggresively identify when a derivative admits the same language as an existing state (RE) in the DFA.  The cost of this identification must be balanced against the number of duplicate states avoided.\n\\end{remark}\n\nIn \\ulex{}, we accomplish this by canonicalizing all input and derived REs.  The canonicalization is described in detail in section~\\ref{sec:reg-exp}.\n\n\\section{Factorings}\\label{sec:factorings}\n\nAnother problem with DFA construction is the size of the unicode alphabet: taking the derivative with respect to each unicode symbol is not feasible.  But to construct the DFA, we have to examine every possible derivative of a given RE.  We must try to conservatively estimate what sets of symbols will yield the same derivative for an RE.  Here we break from Brzozowski's work and introduce new terminology and an algorithm to make derivatives more amenable to large alphabets.\n\nLet $\\sim_\\RE$ be the relation defined as follows.  For a regular expression $\\RE$ and symbols $a, b$, $a \\sim_\\RE b$ if and only if $D_a (\\RE) = D_b (\\RE)$.\n\n\\begin{definition}\nThe \\New{derivative classes} of $\\RE$ are the the equivalence classes $\\Sigma/{\\sim_\\RE}$.\n\\end{definition}\n\nUltimately, the outedges for a DFA state and the derivative classes of the RE for that state are in one-to-one correspondence.\\footnote{This is not quite true: we usually drop error transitions, that is, transitions going to the RE $\\emptyset$.}   Hence, we must eventually determine all the derivative classes for an RE in order to construct the DFA.  To avoid testing the entire alphabet a symbol at a time, we introduce an algorithm which (over)partitions $\\Sigma$, so that each partition is a subset of a derivative class.   We can then take the derivative with respect to a representative from each partition, and determine which partitions actually belong to the same derivative class.\n\n\\begin{definition}\nLet $r$ be an RE.  A \\New{factoring} of $\\Sigma$ under $r$ is a partitioning of $\\Sigma$ such that each partition is a subset of a derivative class for $\\RE$.\n\\end{definition}\n\nTo be clear: we are factoring the \\emph{alphabet} into partitions, but the factoring is guided by (\\emph{under}) a regular expression.  A factoring under a given RE is not unique.  The derivative classes for an RE are one possible factoring (with a minimal number of partitions) while the set of all singleton sets of symbols is another factoring (with a maximal number of partitions).  We will present a simple recursive factoring algorithm and prove its correctness, but first, an example.\n\nSuppose we have two regular expressions $r$ and $s$ yielding factorings $\\{ \\CR_1, \\CR_2 \\}$ and $\\{ \\CS_1, \\CS_2 \\}$ respectively.  Let $t = r \\OR s$.  The derivative of $t$ with respect to some symbol $a$ is $D_a(t) = D_a(r) \\OR D_a(s)$.  Hence, if $D_a(r) = D_b(r)$ and $D_a(s) = D_b(s)$ for some symbols $a, b$, then $D_a(t) = D_b(t)$ and so $a \\sim_t b$.  We can use this to give a factoring under $t$.  The relationship between the factorings under $r$, $s$ and $t$ can be visualized as follows:\n\n\\[\n  \\xymatrix{\n    \\bullet \\ar@{-}[rrr]|{\\Sigma} &&& \\bullet \\\\\n    \\bullet \\ar@{-}[rr]|{\\CR_1} && \\bullet \\ar@{-}[r]|{\\CR_2} & \\bullet \\\\\n    \\bullet \\ar@{-}[r]|{\\CS_1} & \\bullet \\ar@{-}[rr]|{\\CS_2} &&  \\bullet \\\\\n    \\bullet \\ar@{-}[r]|{\\CR_1 \\cap \\CS_1} & \n    \\bullet \\ar@{-}[r]|{\\CR_1 \\cap \\CS_2} & \n    \\bullet \\ar@{-}[r]|{\\CR_2 \\cap \\CS_2} &\n    \\bullet\n  }\n\\]\n\nThis small example captures the essential idea of the algorithm.  To give a factoring under an RE, we recursively find factorings under its components and ``compress'' those factorings into a single new factoring that respects them.  The factorings are being compressed (flattened) in the sense that the boundaries of one factoring are forced onto another, causing some partitions to split.  The algorithm we present is in two stages: first, a factoring function recurively collects factorings under an RE; then, a compress function compresses them all onto $\\Sigma$ to produce a single factoring for an RE.  We now make this precise.\n\nThe \\emph{factoring} function $F$ takes a regular expression and gives a factoring of $\\Sigma$ under that RE.  It is defined recursively as follows:\n\\begin{eqnarray*}\nF(\\epsilon)     &=& \\emptyset \\\\\nF(\\CS)          &=& \\{ \\CS \\} \\\\\nF(r \\cdot s)    &=&\n    \\begin{cases}\n        F(r) & \\epsilon \\notin \\Ls{r} \\\\\n        F(r) \\cup F(s) & \\textrm{otherwise}\n    \\end{cases} \\\\\nF(r \\OR s)      &=& F(r) \\cup F(s) \\\\\nF(r \\AND s)     &=& F(r) \\cup F(s) \\\\\nF(r^*)          &=& F(r) \\\\\nF(\\neg r)       &=& F(r)\n\\end{eqnarray*}\n\nThe \\emph{compress} function $C : \\CP(\\Sigma) \\longrightarrow \\CP(\\Sigma)$ takes a set of subsets of the alphabet and produces the smallest partitioning of $\\Sigma$ that respects them.  In particular, if\n\\[ C(\\{\\CS_1, \\CS_2, \\dots, \\CS_m \\}) = \\{ \\CS'_1, \\CS'_2, \\dots, \\CS'_n \\} \\]\nthen we have that $\\{ \\CS'_1, \\CS'_2, \\dots, \\CS'_n \\}$ is a partitioning of $\\Sigma$ such that for each $\\CS'_i$ and $\\CS_k$ either $\\CS'_i \\subseteq \\CS_k$ or $\\CS'_i \\cap \\CS_k = \\emptyset$.\n\n\\begin{theorem}  Let $\\RE$ be an RE.  Then $C(F(r))$ is a factoring of $\\Sigma$ under $\\RE$.\n\\end{theorem}\n\n\\emph{Proof:} by induction on the structure of $\\RE$.  We use $a$ to denote an arbitrary symbol.\n\n\\vskip 5pt\n\\emph{Case} $\\epsilon$: we have $D_a(\\epsilon) = \\emptyset$ for all $a \\in \\Sigma$, so $\\Sigma/{\\sim_\\epsilon} = \\{ \\Sigma \\}$.  We have $C(F(\\epsilon)) = C(\\{ \\emptyset \\})= \\{ \\Sigma \\}$.\n\n\\vskip 5pt\n\\emph{Case} $\\CS$: we have $D_a(\\CS) = \\epsilon$ if $a \\in \\CS$ and $D_a(\\CS) = \\emptyset$ otherwise. Thus the derivative classes are $\\CS$ and $\\Sigma \\setminus \\CS$, which are exactly the sets produced by $C(F(\\CS)) = C(\\{ \\CS \\})$.\n\n\\vskip 5pt\n\\emph{Case} $s \\cdot t$ and $\\epsilon \\notin \\Ls{s}$:  here $D_a(s \\cdot t) = D_a(s) \\cdot t$. Because $t$ is fixed as $a$ varies, the derivative classes are just the derivative classes of $s$.  Since $F(s \\cdot t) = F(s)$ the result holds by the induction hypothesis on $s$.\n\n\\vskip 5pt\n\\emph{Case} $s \\cdot t$ and $\\epsilon \\in \\Ls{s}$: here $D_a(s \\cdot t) = D_a(s) \\cdot t \\OR \\epsilon \\cdot D_a(t)$.  Let $b, c \\in \\Sigma$ such that $b \\sim_s c$ and $b \\sim_t c$.  Then $b \\sim_{s \\cdot t} c$.  The result follows from this fact and the inductive hypothesis applied to $s$ and $t$.\n\n\\vskip 5pt\nThe other cases are similar.", "meta": {"hexsha": "694e9de09016bdd5d464e914529bcd85e5586eac", "size": 12926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lib/mllpt-lib/ml-lpt/doc/theory-ml-ulex.tex", "max_stars_repo_name": "Bxc8214/mlton-test", "max_stars_repo_head_hexsha": "153db2d029f5191b26d68361922be34eabf4cac9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-01-12T07:08:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-12T07:08:31.000Z", "max_issues_repo_path": "lib/mllpt-lib/ml-lpt/doc/theory-ml-ulex.tex", "max_issues_repo_name": "Bxc8214/mlton-test", "max_issues_repo_head_hexsha": "153db2d029f5191b26d68361922be34eabf4cac9", "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": "lib/mllpt-lib/ml-lpt/doc/theory-ml-ulex.tex", "max_forks_repo_name": "Bxc8214/mlton-test", "max_forks_repo_head_hexsha": "153db2d029f5191b26d68361922be34eabf4cac9", "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": 72.2122905028, "max_line_length": 838, "alphanum_fraction": 0.6988240755, "num_tokens": 3809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6562876477909718}}
{"text": "%---------------------------Shear---------------------------\n\\section{Shear\\label{s:hex-shear}}\n\nThe shear metric is the minimum of the Jacobian matrix\nevaluated at the element corners divided by the product of the length of the 3\nedge vectors meeting at that corner:\n\\[\n  q = \\min_{i\\in\\{0,1,\\ldots,8\\}}\n  \\left\\{\n    \\hat \\alpha_i\n  \\right\\}.\n\\]\n\nNote that if $\\hat \\alpha_i \\leq DBL\\_MIN$ for any $i$ or if ${L_{\\min}}^2 \\leq DBL\\_MIN$,\nwe set $q = 0$.\n\n\\hexmetrictable{shear}%\n{$1$}%                                        Dimension\n{$[0.3,1]$}%                                  Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[0,1]$}%                                    Full range\n{$1$}%                                        Cube\n{\\cite{knu:03}}%                              Citation\n{v\\_hex\\_shear}%                              Verdict function name\n", "meta": {"hexsha": "b3a82afa15c8f4f59572d5eab9df9e48317f3036", "size": 890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexShear.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/HexShear.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/HexShear.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": 35.6, "max_line_length": 90, "alphanum_fraction": 0.4404494382, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6562876464946966}}
{"text": "\\setchapterstyle{kao}\n\\setchapterpreamble[u]{\\margintoc}\n\\chapter{Mathematics and Boxes}\n\\labch{mathematics}\n\n\\section{Theorems}\n\nDespite most people complain at the sight of a book full of equations, \nmathematics is an important part of many books. Here, we shall \nillustrate some of the possibilities. We believe that theorems, \ndefinitions, remarks and examples should be emphasised with a shaded \nbackground; however, the colour should not be to heavy on the eyes, so \nwe have chosen a sort of light yellow.\\sidenote{The boxes are all of the \nsame colour here, because we did not want our document to look like \n\\href{https://en.wikipedia.org/wiki/Harlequin}{Harlequin}.}\n\n\\begin{definition}\n\\labdef{openset}\nLet $(X, d)$ be a metric space. A subset $U \\subset X$ is an open set \nif, for any $x \\in U$ there exists $r > 0$ such that $B(x, r) \\subset \nU$. We call the topology associated to d the set $\\tau\\textsubscript{d}$ \nof all the open subsets of $(X, d).$\n\\end{definition}\n\n\\refdef{openset} is very important. I am not joking, but I have inserted \nthis phrase only to show how to reference definitions. The following \nstatement is repeated over and over in different environments.\n\n\\begin{theorem}\nA finite intersection of open sets of (X, d) is an open set of (X, d), \ni.e $\\tau\\textsubscript{d}$ is closed under finite intersections. Any \nunion of open sets of (X, d) is an open set of (X, d).\n\\end{theorem}\n\n\\begin{proposition}\nA finite intersection of open sets of (X, d) is an open set of (X, d), \ni.e $\\tau\\textsubscript{d}$ is closed under finite intersections. Any \nunion of open sets of (X, d) is an open set of (X, d).\\marginnote{You can even insert footnotes inside the theorem \n\tenvironments; they will be displayed at the bottom of the box.}\n\\end{proposition}\n\n\\begin{lemma}\nA finite intersection\\footnote{I'm a footnote} of open sets of (X, d) is \nan open set of (X, d), i.e $\\tau\\textsubscript{d}$ is closed under \nfinite intersections. Any union of open sets of (X, d) is an open set of \n(X, d).\n\\end{lemma}\n\nYou can safely ignore the content of the theorems\\ldots I assume that if \nyou are interested in having theorems in your book, you already know \nsomething about the classical way to add them. These example should just \nshowcase all the things you can do within this class.\n\n\\begin{corollary}[Finite Intersection, Countable Union]\nA finite intersection of open sets of (X, d) is an open set of (X, d), \ni.e $\\tau\\textsubscript{d}$ is closed under finite intersections. Any \nunion of open sets of (X, d) is an open set of (X, d).\n\\end{corollary}\n\n\\begin{proof}\nThe proof is left to the reader as a trivial exercise. Hint: \\blindtext\n\\end{proof}\n\n\\begin{definition}\nLet $(X, d)$ be a metric space. A subset $U \\subset X$ is an open set \nif, for any $x \\in U$ there exists $r > 0$ such that $B(x, r) \\subset \nU$. We call the topology associated to d the set $\\tau\\textsubscript{d}$ \nof all the open subsets of $(X, d).$\\marginnote{\n\tHere is a random equation, just because we can:\n\t\\begin{equation*}\n  x = a_0 + \\cfrac{1}{a_1\n          + \\cfrac{1}{a_2\n          + \\cfrac{1}{a_3 + \\cfrac{1}{a_4} } } }\n\t\\end{equation*}\n}\n\\end{definition}\n\n\\begin{example}\nLet $(X, d)$ be a metric space. A subset $U \\subset X$ is an open set \nif, for any $x \\in U$ there exists $r > 0$ such that $B(x, r) \\subset \nU$. We call the topology associated to d the set $\\tau\\textsubscript{d}$ \nof all the open subsets of $(X, d).$\n\\end{example}\n\n\\begin{remark}\nLet $(X, d)$ be a metric space. A subset $U \\subset X$ is an open set \nif, for any $x \\in U$ there exists $r > 0$ such that $B(x, r) \\subset \nU$. We call the topology associated to d the set $\\tau\\textsubscript{d}$ \nof all the open subsets of $(X, d).$\n\\end{remark}\n\nAs you may have noticed, definitions, example and remarks have \nindependent counters; theorems, propositions, lemmas and corollaries \nshare the same counter.\n\n\\begin{remark}\nHere is how an integral looks like inline: $\\int_{a}^{b} x^2 dx$, and \nhere is the same integral displayed in its own paragraph:\n\\[\\int_{a}^{b} x^2 dx\\]\n\\end{remark}\n\nWe provide two files for the theorem styles: \n\\href{style/plaintheorems.sty}{plaintheorems.sty}, which you should \ninclude if you do not want coloured boxes around theorems; and \n\\href{style/mdftheorems.sty}{mdftheorems.sty}, which is the one used for \nthis document.\\sidenote{The plain one is not showed, but actually it is \nexactly the same as this one, only without the yellow boxes.} Of course, \nyou will have to edit these files according to your taste and the \ngeneral style of the book.\n\n\\section[Boxes \\& Environments]{Boxes \\& Custom Environments\n\\sidenote[*1.6][]{Notice that in the table of contents and in the \n\theader, the name of this section is \\enquote{Boxes \\& Environments}; \n\twe achieved this with the optional argument of the \\texttt{section} \n\tcommand.}}\n\nSay you want to insert a special section, an optional content or just \nsomething you want to emphasise. We think that nothing works better than \na box in these cases. We used \\Package{mdframed} to construct the ones \nshown below. You can create and modify such environments by editing the \nprovided file \\href{style/environments.sty}{environments.sty}.\n\n\\begin{kaobox}[frametitle=Title of the box]\n\\blindtext\n\\end{kaobox}\n\nIf you set up a counter, you can even create your own numbered \nenvironment.\n\n\\begin{kaocounter}\n\t\\blindtext\n\\end{kaocounter}\n\n\\section{Experiments}\n\nIt is possible to wrap marginnotes inside boxes, too. Audacious readers \nare encouraged to try their own experiments and let me know the \noutcomes.\n\n\\marginnote[-2.2cm]{\n\t\\begin{kaobox}[frametitle=title of margin note]\n\t\tMargin note inside a kaobox.\\\\\n\t\t(Actually, kaobox inside a marginnote!)\n\t\\end{kaobox}\n}\n\nI believe that many other special things are possible with the \n\\Class{kaobook} class. During its development, I struggled to keep it as \nflexible as possible, so that new features could be added without too \ngreat an effort. Therefore, I hope that you can find the optimal way to \nexpress yourselves in writing a book, report or thesis with this class, \nand I am eager to see the outcomes of any experiment that you may try.\n\n%\\begin{margintable}\n\t%\\captionsetup{type=table,position=above}\n\t%\\begin{kaobox}\n\t\t%\\caption{caption}\n\t\t%\\begin{tabular}{ |c|c|c|c| }\n\t\t\t%\\hline\n\t\t\t%col1 & col2 & col3 \\\\\n\t\t\t%\\hline\n\t\t\t%\\multirow{3}{4em}{Multiple row} & cell2 & cell3 \\\\ & cell5 \n\t\t\t%%& cell6 \\\\ \n\t\t\t%& cell8 & cell9 \\\\\n\t\t\t%\\hline\n\t\t%\\end{tabular}\n\t%\\end{kaobox}\n%\\end{margintable}\n", "meta": {"hexsha": "80064d3e17dc21b2e2de3ed89bdc21fd4fe1c7d7", "size": 6511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/mathematics.tex", "max_stars_repo_name": "robertdstein/kaobook", "max_stars_repo_head_hexsha": "c2fb69c9bc077a1ffe08e1258e4f6f735f8238cb", "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/mathematics.tex", "max_issues_repo_name": "robertdstein/kaobook", "max_issues_repo_head_hexsha": "c2fb69c9bc077a1ffe08e1258e4f6f735f8238cb", "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/mathematics.tex", "max_forks_repo_name": "robertdstein/kaobook", "max_forks_repo_head_hexsha": "c2fb69c9bc077a1ffe08e1258e4f6f735f8238cb", "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": 38.5266272189, "max_line_length": 115, "alphanum_fraction": 0.7263093227, "num_tokens": 1899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867729389246, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.6562604905755961}}
{"text": "\n\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{setspace}\n\\usepackage[margin=1.0in]{geometry}\n\\usepackage{graphicx}\n\\graphicspath{ {../oldPlots} }\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\n%\\addtolength{\\oddsidemargin}{-.875in}\n%\\addtolength{\\evensidemargin}{-.875in}\n%\\addtolength{\\textwidth}{1.75in}\n\\setlength{\\parskip}{0.08cm}\n\n\\title{nflMarkov: k of n}\n\n\\date{\\today}\n\n\\maketitle\n\n\\tableofcontents\n\n\\newpage\n%%%%%%%%\n\\setcounter{footnote}{0}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{1 of n: a basic markov chain}\n\n\nThis is the first in a series of posts describing my work on a Markov chain tool to analyze football. The code is available from github,\n{\\tt https://github.com/bdilday/nflMarkov}\n\nBefore talking about football, I want to talk about a less complicated problem. It is probably worth saying at this point that I am not a mathematician, nor a computer scientist. What I am is an astronomer and astrophysicist, so obviously I know some math and some programming, but at the same time I'm not necessarily an expert on Markov chains. As with most things, what I know is what I've picked up in order to work on research problems, so what I have to say may be obvious, or naive. In any case, writing this out is in large part for my own sake, just to see it all layed out and to help myself clarify my thoughts on the problem; as well as to hopefully be useful people who read this without much knowledge of Markov chains coming in. \n\nThe first simple problem I want to talk about, which is pretty much the simplest non-trivial Markov chain problem I can think of, is this; imagine a random walk where there are 5 possible states which I will call $s_{-2}, s_{-1}, s_{0}, s_{+1}, s_{+2}$. In each step of the process, the walker can move one step to the right, which happens with probability p, or one step to the left, which happens with probability q=1-p. If the walker lands at position +2 or -2 they stay there. Here is what the transition matrix looks like, \\\\\n\n\n$\nT_{ij} = \\left(\n\\begin{array}{ccccc}\n 1 & 1-p & 0 & 0 & 0 \\\\\n 0 & 0 & 1-p & 0 & 0 \\\\\n 0 & p & 0 & 1-p & 0 \\\\\n 0 & 0 & p & 0 & 0 \\\\\n 0 & 0 & 0 & p & 1 \\\\\n\\end{array}\n\\right)$ \\\\\n\nTo be clear, this is the probability to transition {\\it to} the state i {\\it from} the state j. If I iterate once, i.e., compute $ T^2 = T_{ik}T_{kj}$ (the is the Einstein notation for maytrix multiplication), I get, \\\\\n\n$T^{2} = \n\\left(\n\\begin{array}{ccccc}\n 1 & 1-p & (1-p)^2 & 0 & 0 \\\\\n 0 & (1-p) p & 0 & (1-p)^2 & 0 \\\\\n 0 & 0 & 2 (1-p) p & 0 & 0 \\\\\n 0 & p^2 & 0 & (1-p) p & 0 \\\\\n 0 & 0 & p^2 & p & 1 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nTwo times, \\\\\n\n$ T^{3} =\n\\left(\n\\begin{array}{ccccc}\n 1 & p (1-p)^2-p+1 & (1-p)^2 & (1-p)^3 & 0 \\\\\n 0 & 0 & 2 (1-p)^2 p & 0 & 0 \\\\\n 0 & 2 (1-p) p^2 & 0 & 2 (1-p)^2 p & 0 \\\\\n 0 & 0 & 2 (1-p) p^2 & 0 & 0 \\\\\n 0 & p^3 & p^2 & (1-p) p^2+p & 1 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nThree times, \\\\\n\n$ T^{4} =\n\\left(\n\\begin{array}{ccccc}\n 1 & p (1-p)^2-p+1 & p (1-p)^3+\\left(p (1-p)^2-p+1\\right) (1-p) & (1-p)^3 & 0 \\\\\n 0 & 2 (1-p)^2 p^2 & 0 & 2 (1-p)^3 p & 0 \\\\\n 0 & 0 & 4 (1-p)^2 p^2 & 0 & 0 \\\\\n 0 & 2 (1-p) p^3 & 0 & 2 (1-p)^2 p^2 & 0 \\\\\n 0 & p^3 & (1-p) p^3+\\left((1-p) p^2+p\\right) p & (1-p) p^2+p & 1 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\n\nYou can stare at these and start to see the structure of how you move from state to state as you iterate the Markov chain, but I think the main usefulness is just to illustrate that repeated applications of the transition matrix mix things up in a deterministic and straight-forward (if tedious to enumerate) way. For a simple problem like this you could probably even come up with a closed form solution. \n\nNow let me put in some numbers and keep iterating the transition matrix until it converges. lets try p=1-p=0.5. If I iterate 100 times, and round to zero values less than $ 1 \\times 10^{-6}$, I get, \\\\\n\n$\nT^{100} \\approx T^{\\infty} = \n\\left(\n\\begin{array}{ccccc}\n 1. & 0.75 & 0.5 & 0.25 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0.25 & 0.5 & 0.75 & 1. \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nSo what exactly does this mean? It means if I start in the state $s_{-2}$ (all the way to the left), I end in the state $s_{-2}$ with probability 1. If I start in the state $s_{-1}$ I end in the state $s_{-2}$ with probability 0.75 and $s_{+2}$ with probability 0.25. If I start in the state $s_0$, I end in the state $s_{-2}$ with probability 0.5 and $s_{+2}$ with probability 0.5. In other words, reading down each column (j) tells me the probability to end in the state (i) after 100 (which may as well be infinity) transitions. \\\\\n\nIf I use p=0.501 instead, this is what I get, \\\\\n\n$\n\\left(\n\\begin{array}{ccccc}\n 1. & 0.748498 & 0.498 & 0.248502 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0.251502 & 0.502 & 0.751498 & 1. \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nIf I use p=0.99, I get, \\\\\n\n\n$\n\\left(\n\\begin{array}{ccccc}\n 1. & 0.010101 & 0.00010202 & 1.02 \\times 10^{-6} & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0.989899 & 0.999898 & 0.999999 & 1. \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nThis first post just shows that you can set up a Markov chain that models a random walk and make the states at the end \"sinks\" (or roach motels; once you enter, you never leave), and after iterating enough times, you will always end up in one of the sinks. In the football application, the sinks are going to be scoring events. So we can imagine that making it all the way to the right is like scoring a touchdown, all the way to the left, like giving up a safety. In the next part I'll look at the expectation values associated with such a Markov chain.\n\n\n\\section{2 of n: expectation values of a basic markov chain}\n\nIn part 1 I talked about a simple random walk in 1-dimension, where the states all the way to the left and all the way to the right are sinks (or roach motels). The next step from that is to ask what is the expectation value associated with each state? I mentioned that we could think of the state $s_{+2}$ as scoring a touchdown (+6 or +7 or +8 points) and $s_{-2}$ as giving up a safety (-2 points), but to illustrate the problem, it is convenient to assume that landing at location +2 is worth +1 point and at location -2, -1 point. \n\nAs a concrete example, let me take p=0.6 and ask what the expectation values are, given that I start in state $s_{-1}, s_{0},$ or $s_{+1}$. Iterating the transition matrix to convergence, as I did in part 1, I get, \\\\\n\n$T^{\\infty} = \n\\left(\n\\begin{array}{ccccc}\n 1. & 0.584615 & 0.307692 & 0.123077 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0.415385 & 0.692308 & 0.876923 & 1. \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nThis says that if I start at state $s_0$, I end in state $s_{-2}$ with probability 0.308 and $s_{+2}$ with probability 0.692. If these are worth -1 and +1 points, respectively, then the expectation value for points will be $e_{0} = 0.692-0.308 = 0.384$. In a similar way I can see that the expectation values for states $s_{-1}$ and $s_{+1}$ are $e_{-1} = 0.415-0.585 = -0.169$ and $0.877-0.123 = 0.754$, respectively. I will use $p=0.6$ as sort of a test case and refer back to these values later. So this gives me the answer using the first method. \n\nThe question I want to address now is, other than iterating to convergence, how do we go from the transition matrix (which is relatively easy to code up for football) to the expectation value (which is what we really want to know)? \n%I want to get the expectation values by explicitly setting up a system of equations for them. Although I can setup a transition matrix for football and iterate it, I think this will be a more straight-forward implementation. \nLogically, the expectation value, $e_{0}$, when starting from the state $s_{0}$, should be, \\\\\n\n$\ne_0 = e_{-2} p_{-2,0} + e_{-1} p_{-1,0} + e_{0} p_{0,0} + e_{+1} p_{+1,0} + e_{+2} p_{+2,0}\n$ \\\\\n\nIn words, its the expectation value of the subsequent state in the chain (for example, $ e_{-1}$), multiplied by the probability to transition to that state (for example $ p_{-1, 0}$). Inspection shows that this says (using Einstein notation for matrix/vector multiplication), \\\\\n\n$ \ne_{i} = e_{k} T_{k,i} \n$ \\\\\n\nor, in vector notation, \\\\\n\n$ \\vec{e} = \\vec {e} ~\\vec{T}$, \\\\ \n\nor \\\\\n\n$ \\vec{e} ~(\\vec{T} - \\vec{1}) = 0$, where $ \\vec{1}$ is the identity matrix. \\\\\n\nFor the particular transition matrix we are discussing, we have, \\\\\n\n$\n\\left(\n\\begin{array}{c}\ne_{-2} \\\\\ne_{-1} \\\\\ne_{0} \\\\\ne_{+1} \\\\\ne_{+2}\n\\end{array}\n\\right) = \n\\left(\n\\begin{array}{c}\ne_{-2} \\\\\ne_{-1} \\\\\ne_{0} \\\\\ne_{+1} \\\\\ne_{+2}\n\\end{array}\n\\right)\n\\times \n\\left(\n\\begin{array}{ccccc}\n 1 & 1-p & 0 & 0 & 0 \\\\\n 0 & 0 & 1-p & 0 & 0 \\\\\n 0 & p & 0 & 1-p & 0 \\\\\n 0 & 0 & p & 0 & 0 \\\\\n 0 & 0 & 0 & p & 1 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nBecause $e_{m} T_{m,n} = T_{m,n} e_{m} = T'_{n,m} e_{m}$, where $T'$ is the transpose of $T$, I can also write this as, \\\\\n\n$\\vec{e} = \n\\left(\n\\begin{array}{ccccc}\n 1 & 0 & 0 & 0 & 0 \\\\\n 1-p & 0 & p & 0 & 0 \\\\\n 0 & 1-p & 0 & p & 0 \\\\\n 0 & 0 & 1-p & 0 & p \\\\\n 0 & 0 & 0 & 0 & 1 \\\\\n\\end{array}\n\\right) \\times \n\\vec{e}\n$ \\\\\n\n\nThis way, with the matrix multiplying the vector from the left is the more common way to see a set of equations represented, and some code for numerically solving such an equation expect this convention. The values $ e_{-2}$ and $ e_{+2}$, however, aren't really variables, i.e. quantities that need to take on particular values for the set of equations to hold; they are parameters such that their values are arbitrary, and, once chosen, impact the expectation values for the non-sink states. \\\\\n\nLet me denote by (s, t) states that are {\\bf s}inks, and (n,m) states that are {\\bf NOT} sinks. What I really want to know are the set of values $ e_{n}$, i.e. the expectation values for states that are {\\bf not} sinks. So I can write, \\\\\n\n$ e_{n} = e_{s} T_{s,n} + e_{m} T_{m,n}$ \\\\\n\nRearranging this equation gives, \\\\\n\n$e_{m} ~(T_{m,n} - \\delta_{m,n}) = - e_{s} T_{s,n}$ \\\\\n\nor in vector notation, \\\\\n\n$ \\vec{e}^{n} ~(\\vec{T}^{n} - \\vec{1}) = - \\vec{e}^{s} ~\\vec{T}^{s}$ \\\\\n\nTaking the transpose of both sides I get, \\\\\n\n$ (\\vec{T}^{n} - \\vec{1})' ~\\vec{e}^{n}  = - \\vec{T'}^{s} ~\\vec{e}^{s} $ \\\\\n\nNote that the superscripts here denote sink or non-sink and {\\bf do not} denote exponentiation. Also, let $S$ denote the number of sinks and $N$ the number of non-sinks; then the dimensions of $e^{n}, e^{s}, T'^{n}$, and $T'^{s}$ are \n$N \\times 1$, $S \\times 1$, $N \\times N$, and $N \\times S$, respectively. \n\nFor the particular problem we've been discussing, this can be expanded as,\n\n$\n\\left(\n\\begin{array}{ccc}\n 0 & p & 0 \\\\\n 1-p & 0 & p \\\\\n 0 & 1-p & 0 \\\\\n\\end{array}\n\\right) \\times\n\\left(\n\\begin{array}{c}\n e_{-1} \\\\\n e_{0} \\\\\n e_{+1} \\\\\n\\end{array}\n\\right) = \n- \\left(\n\\begin{array}{cc}\n 1-p & 0 \\\\\n 0 & 0 \\\\\n 0 & p \\\\\n\\end{array}\n\\right) \\times \n\\left(\n\\begin{array}{c}\n e_{-2} \\\\\n e_{+2} \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nor \\\\\n\n$\n\\left(\n\\begin{array}{ccc}\n 0 & p & 0 \\\\\n 1-p & 0 & p \\\\\n 0 & 1-p & 0 \\\\\n\\end{array}\n\\right) \\times\n\\left(\n\\begin{array}{c}\n e_{-1} \\\\\n e_{0} \\\\\n e_{+1} \\\\\n\\end{array}\n\\right) = \n-\\left(\n\\begin{array}{c}\n e_{-2} (1-p) \\\\\n 0 \\\\\n e_{+1} p \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nNote that once I choose values for $e_{-2}$ and $e_{+2}$, the the right hand side is just a constant vector. \\\\\n\n$\n\\left(\n\\begin{array}{ccc}\n 0 & p & 0 \\\\\n 1-p & 0 & p \\\\\n 0 & 1-p & 0 \\\\\n\\end{array}\n\\right) \\times\n\\left(\n\\begin{array}{c}\n e_{-1} \\\\\n e_{0} \\\\\n e_{+1} \\\\\n\\end{array}\n\\right) = \n\\left(\n\\begin{array}{c}\n (1-p) \\\\\n 0 \\\\\n -p \\\\\n\\end{array}\n\\right)\n$ \\\\\n\n\n\nThe formal solution is, \\\\\n\n$ ((\\vec{T}^{n}-\\vec{1})')^{-1} \\cdot (- \\vec{T}^{s} \\cdot \\vec{e}^{s})$ \\\\\n\n$\n=  \\left(\n\\begin{array}{c}\n \\frac{-{e_{-2}} p^3+{e_{+2}} p^3+2 {e_{-2}} p^2-2 {e_{-2}} p+{e_{-2}}}{2 p^2-2 p+1} \\\\\n \\frac{{e_{-2}} (p-1)^2+{e_{+2}} p^2}{2 p^2-2 p+1} \\\\\n \\frac{{e_{+2}} p \\left(p^2-p+1\\right)-{e_{-2}} (p-1)^3}{2 p^2-2 p+1} \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nso if I set $e_{-2} = -1$ and $e_{+2} = +1$, then I get, \\\\\n\n$\n\\left(\n\\begin{array}{c}\n \\frac{2 p^3-2 p^2+2 p-1}{2 p^2-2 p+1} \\\\\n \\frac{p^2-(p-1)^2}{2 p^2-2 p+1} \\\\\n \\frac{(p-1)^3+p \\left(p^2-p+1\\right)}{2 p^2-2 p+1} \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nand then if I further set $p = 0.6$, then I get, \\\\\n\n$\n\\left(\n\\begin{array}{c}\n -0.169231 \\\\\n 0.384615 \\\\\n 0.753846 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nwhich is exactly what I got from iterating the transition matrix until it converges and then reading off the columns. One last thing to note, is that the equation, \\\\\n\n$\n\\vec{e} \\cdot \\vec{T} = \\vec{e}$ \\\\\n\nfrom above implies that (if I multiply by $T$ from the right on both sides), \\\\\n\n$\\vec{e} \\cdot \\vec{T}^2 = \\vec{e} \\cdot \\vec{T}$,  \\\\\n\nbut $\\vec{e} \\cdot \\vec{T} = \\vec{e}$, so \\\\\n\n$\\vec{e} \\cdot \\vec{T}^{2} = \\vec{e}$,  \\\\\n\nand it follows that, \\\\\n\n$\\vec{e} \\cdot \\vec{T}^{\\infty} = \\vec{e}$,  \\\\\n\nwhich is exactly what we got by iterating the transition matrix to convergence.\n\n\n\\section{3 of n: accounting for turnovers}\n\nIn parts 1 and 2 I described a problem that could be modeled as a Markov chain and that roughly corresponds to the scoring of touchdowns and safetys. Now I will discuss introducing the concept of a turnover. In the orginal problem, the walker had a probability to move right of p, and left of (1-p). I will now model the case where a ``turnover'' occurs with probability a. This reverses right and left, so that the walker moves left with probability p and right with probability (1-p). The most straight-forward way to model this augmented problem is to double the size of the number of possible states, by including a flag that tells you whether the walker is moving ``right'' (as in the original problem), or left (after reversing directions). It is convenient to refer to a state as $s^{y}_{x}$, where $x$ refers to location and $y$ to direction. As a concrete example, the state 1 position over from the left sink, and moving to the right can be denoted as $s^{+}_{-1}$, the state one step over from the left sink and moving to the left as $s^{-}_{-1}$. Additionally, the values of the sinks get transposed, so that $e^{+}_{+2} = -e^{-}_{-2}$ (think a touchdown scored in the + direction is +7, a touchdown in the - direction is -7) and $e^{+}_{-2} = e^{-}_{+2}$ (a safety given up in the + direction is worth -2, in the - direction +2). Combining the effects of stepping and turning over, results in a transition matrix that looks like this, \\\\\n\n\n$\n\\left(\n\\begin{array}{cccccccccc}\n 1 & (1-a) (1-p) & 0 & 0 & 0 & 0 & a (1-p) & 0 & 0 & 0 \\\\\n 0 & 0 & (1-a) (1-p) & 0 & 0 & 0 & 0 & a (1-p) & 0 & 0 \\\\\n 0 & (1-a) p & 0 & (1-a) (1-p) & 0 & 0 & a p & 0 & a (1-p) & 0 \\\\\n 0 & 0 & (1-a) p & 0 & 0 & 0 & 0 & a p & 0 & 0 \\\\\n 0 & 0 & 0 & (1-a) p & 1 & 0 & 0 & 0 & a p & 0 \\\\\n 0 & a p & 0 & 0 & 0 & 1 & (1-a) p & 0 & 0 & 0 \\\\\n 0 & 0 & a p & 0 & 0 & 0 & 0 & (1-a) p & 0 & 0 \\\\\n 0 & a (1-p) & 0 & a p & 0 & 0 & (1-a) (1-p) & 0 & (1-a) p & 0 \\\\\n 0 & 0 & a (1-p) & 0 & 0 & 0 & 0 & (1-a) (1-p) & 0 & 0 \\\\\n 0 & 0 & 0 & a (1-p) & 0 & 0 & 0 & 0 & (1-a) (1-p) & 1 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nSo, for example, the walker moves from state $s^{+}_{-1}$ (the 2nd column) to \nthe state $s^{+}_{-2}$ with probability $(1-a)(1-p)$,\nthe state $s^{+}_{0}$ with probability $(1-a) p$,\nthe state $s^{-}_{-2}$ with probability $a p$,\nthe state $s^{-}_{-2}$ with probability $a (1-p)$.\nNote that when $a=0$, ``moving to the right'' (the top-left 5x5) decouples from ``moving to the left'' (the bottom-right 5x5). Specifically, \\\\\n\n$\n\\left(\n\\begin{array}{cccccccccc}\n 1 & 1-p & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 1-p & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & p & 0 & 1-p & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & p & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & p & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 1 & p & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 & 0 & p & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 & 1-p & 0 & p & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1-p & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1-p & 1 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nWith this formulation, everything I talked about in parts 1 and 2 carries over, i.e., the expectation values can be determined by iterating the transition matrix until it converges, or by separating out the sink and non-sink states and explicitly solving the system of equations for the non-sink expectation values. If I take p=1-p=0.5, and a=0, the solution is, \\\\\n\n$\n\\left(\n\\begin{array}{c}\n e^{+}_{-1} \\\\\n e^{+}_{0} \\\\\n e^{+}_{+1} \\\\\n e^{-}_{-1} \\\\\n e^{-}_{0} \\\\\n e^{-}_{+1} \\\\\n\\end{array}\n\\right) =\n\\left(\n\\begin{array}{c}\n -0.5 \\\\\n 0 \\\\\n 0.5 \\\\\n -0.5 \\\\\n 0 \\\\\n 0.5 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nIf I take p=0.6, and a=0, the solution is, \\\\\n\n$\n\\left(\n\\begin{array}{c}\n e^{+}_{-1} \\\\\n e^{+}_{0} \\\\\n e^{+}_{+1} \\\\\n e^{-}_{-1} \\\\\n e^{-}_{0} \\\\\n e^{-}_{+1} \\\\\n\\end{array}\n\\right) =\n\\left(\n\\begin{array}{c}\n -0.169231 \\\\\n 0.384615 \\\\\n 0.753846 \\\\\n -0.753846 \\\\\n -0.384615 \\\\\n 0.169231 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nThese make sense based on the results from parts 1 and 2. If I take p=0.5 and vary the value of $a$, then the result is as shown in Fig. \\ref{fignm_05}. In other words, it makes no difference if I reverse direction or not. This makes sense because either way I am moving left or right with equal probability, and moreover, I have defined the points for landing at location +2 (a ``touchdown'') to be equal to the points for landing in location -2 (a ``safety''). \\\\\n\nIf I set p=0.6 and vary a, the results are as shown in Fig. \\ref{fignm_06}. And, if I set p=0.9 and vary a, the results are as in Fig. \\ref{fignm_09}.\n\nAs a test case to investigate in more detail, let me choose $p=0.6, a=0.1$. In that case the solution is,\n\n$\n\\left(\n\\begin{array}{c}\n e^{+}_{-1} \\\\\n e^{+}_{0} \\\\\n e^{+}_{+1} \\\\\n e^{-}_{-1} \\\\\n e^{-}_{0} \\\\\n e^{-}_{+1} \\\\\n\\end{array}\n\\right) =\n\\left(\n\\begin{array}{c}\n -0.316552 \\\\\n 0.206897 \\\\\n 0.642069 \\\\\n -0.642069 \\\\\n -0.206897 \\\\\n 0.316552 \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nAn important point to note is that the solution has a lot of symmetry. In other words, if you flip the direction you're moving and also flip the starting point, then the expectation value is equal in magnitude and opposite in sign. So, for example, starting from $s_{-1}$ and moving right is the negative of starting from $s_{+1}$ and moving left. I can write this more concisely as, $e^{-}_{i} = -e^{+}_{2m-i}$, where $m$ stands for ``middle''. In this case $m=0$, and \\\\\n\n$\n\\begin{array}{c}\ne^{-}_{-1} = - e^{+}_{+1} \\\\\ne^{-}_{0} = - e^{+}_{0} \\\\\ne^{-}_{+1} = - e^{+}_{-1} \\\\\n\\end{array}\n$ \\\\\n\nMoreover, the transition probabilities are symmetric if we flip directions and flip position around the middle, that is, $T^{+,-}_{i,j} = T^{+,-}_{2 m-i,2 m - j }$. The main point of this section is that we can use the symmetry of the expectation values and transition probabilities to avoid the doubling of the state space. To repeat the general equation for expectation value in terms of transition probabilities (Einstein notation), \\\\\n\n\n$e^{+}_{j} = e^{+}_{i} T^{+}_{i,j} \\\\\n= e^{+}_{i} T^{+,+}_{i,j}  + e^{-}_{i} T^{-,+}_{i,j} \\\\\n$ \\\\\n\nSo far this is just an identity, where I have split up $T$ into the parts where no turnover occurs (the $T^{+}_{i} terms) and the parts where a turn over did occur (the $T^{-}_{i} terms). With the assumption that a ``turnover'' occurs with probability a, and the relations described above, I can write, \\\\\n\n$e^{+}_{j} = (1-a) e^{+}_{i} T^{+,+}_{i,j} - a e^{+}_{2 m-i} T^{+,+}_{2 m -1, 2 m - j}$ \\\\\n\nSo if I generate a matrix, $U$, with elements $U_{i,j} = (1-a) T_{i,j} - a T_{i, 2m - j}$, then I can write the vector equation $\\vec{e} = \\vec{e} \\vec{U}$. Everything discussed in part 2 regarding solving this then carries over. As a concrete example, here is what the $5 \\times 5$ matrix $U$ looks like for this problem, \\\\\n\n$\n\\left(\n\\begin{array}{ccccc}\n 1-a & (1-a) (1-p) & 0 & -a (1-p) & -a \\\\\n 0 & 0 & (1-a) (1-p)-a (1-p) & 0 & 0 \\\\\n 0 & (1-a) p-a (1-p) & 0 & (1-a) (1-p)-a p & 0 \\\\\n 0 & 0 & (1-a) p-a p & 0 & 0 \\\\\n -a & -a p & 0 & (1-a) p & 1-a \\\\\n\\end{array}\n\\right)\n$ \\\\\n\nFinally, since this equation is identical to the one in part 2, with $U$ replacing $T$, the transition matrix without considering turnovers, it follows that a 2nd way to determine the expectation values is to iterate $U$ until it converges, and read off the columns. In the football application, where the transition matrix has (depending on the parameterization) about 8000 elements, iterating may be a better choice, computationally. Another important thing to note here is that I've looked at a restricted case where a turnover allows occured at the same location from which the walker started. So the relation in this case is \n$e^{-}_{i} T^{-,+}_{i,j} = e^{+}_{i} T^{+,+}_{i,2 m -j}$, \nmore generally it is,\n$e^{-}_{i} T^{-,+}_{i,j} = e^{+}_{i} T^{+,+}_{i,j'}$, where $j'$ is the state that the turnover brounght you to.\nAs a concrete example, consider having 1st and 10 from the 20. Say there is a probability $\\eta$ to throw an interception, with the ball ending up 20 yards down field, at the 40. Then the part of the transition matrix encoding that will be\n$ - e_{1-10-60} T^{-,+}_{1-10-60,1-10-20}$.\n\n\n\\section{4 of n: the yards gained distributions (transition matrix)}\n\nIn football, a basic state consists of a set of down-distance-yardline values. One could include score differential, or time I suppose, but I'm not considering those here. The transition matrix can be built by using the yards-gained distribution, along with the probabilities to run a play as opposed to punting or attempting a field goal. So the main questions I want to address here are, \n\n\\begin{itemize}\n\n\\item what are the probabilities for passing versus running versus kicking?\n\n\\item given that a play is run, what is the yards gained distribution? \n\n\\end{itemize}\n\nI am ignoring some context-specific distinctions such as time on the clock, score-differential and weather. This is very much in the same vein as something like RE24 (from the more developed field of baseball analytics) in that it accounts for game state, but is othwerwise context neutral. \n\nWith that being said, it is not immediately obvious what the dependence of the yards-gained distribution on down, distance, and yardline should be. So my starting point was to grab some data and start slicing and dicing and making some graphs. To clarify, yardline is encoded as ``yards-from-own-goal'', abbreviated yfog, where 1 means you are backed up against your end zone, and 99 means you are 1 yard away from scoring a touchdown.\n\n\\begin{itemize}\n\n\\item In between, say yfog=20 and yfog=75, mean yards gained doesn't depend strongly on field position (Fig. \\ref{fignm1}).\n\n\n\n\\item For plays originating between yfog=20 and yfog=75, mean yards gained doesn't depend strongly on yards-to-go (Fig. \\ref{fignm2}).\n\n\n\n\\item The fraction of plays that are passes depends strongly on down and distance, and less strongly on field position (Figs. \\ref{fignm3} \\& \\ref{fignm5}).\n\n\n\n\\item On fourth down, the probabilities to punt versus try a field goal versus go for it vary rapidly as a function of yards-to-go and yards-from-own-goal This is particularly true for yfog $\\sim 50$ to yfog $\\sim 80$ (Figs. \\ref{figep1}, \\ref{figep2}, and \\ref{figep3}).\n\n\n\\end{itemize}\n\n\nSo now the question is, how can we model the yards-gained distribution? Since mean yards gained doesn't depend too strongly on down, distance, and field position, it is instructive to pool a bunch of states, and look in more detail at the distribution to get a feel for what it looks like. In Fig. \\ref{fignm6}, I show distributions for passes (left) and rushes (right), for all first-down plays originating between yfog=20 and yfog=75. \n\n\n\nAfter playing around with some functions, the best general agreement I could find came from the following,  \\\\\n\n$ p(y) = A ~\\frac{e^{(y-y_0)/\\sigma_1}} {1+e^{(y-y_0) (\\sigma_1+\\sigma_2)/(\\sigma_1 \\sigma_2)})} + G ~e^{- (y-g_0)^2/ (2 \\sigma_g^2)}$. \\\\\n\nI refer to this as a ``Bazin plus Gauss'' function; Bazin because I first encountered the ``ratio of exponentials'' in a paper by Bazin, et al, that used it to model supernova light curves ({\\tt http://arxiv.org/abs/1109.0948}), and Gauss for obvious reasons. The first (Bazin) term basically stitches together two exponentials at the location $y_0$. For $y \\ll y_0$, it looks like a rising exponential with a scale factor $\\sigma_1$, and for $y \\gg y_0$, like a declining exponential with a scale factor $\\sigma_2$. The Gaussian part describes being sacked, and in the football application, $G$ is identically 0 for rushes. \n\nUsing this functional form, I use the function minimization package {\\tt pyminuit} to determine the maximum likelihood values for the parameters, $y_0, \\sigma_1, \\sigma_2$ for rushes, and additionally $G/A, g_0,$ and $\\sigma_g$ for passes. For rushes, typical values are $y_0 \\sim 1, \\sigma_1 \\sim 1.5, \\sigma_2 \\sim 3.5$. For passes, typical values are $y_0 \\sim 4.5, \\sigma_1 \\sim 1.8, \\sigma_2 \\sim 8.0, G/A \\sim 0.12, g_0 \\sim -6.5, $ and $\\sigma_g \\sim 3.0$. Figs. \\ref{figye1} \\& \\ref{figym1} compare the model to the empirical distribution for 1st and 10 plays from the 20.\n\nIn the next section I will describe how my model is implemented in code.\n\n\n\\section{5 of n: nflMarkov, the Python code}\n\nIn part 4, I described modeling the yards-gained distribution, including the probabilities to kick versus run a play. Here I will describe how these are controlled in the Markov chain computer program. \n\nThe program reads a parameter file which has a generic form of \\\\\n\n{\\tt parameter-name down ytg-min ytg-max yfog param-value} \\\\\n\nFor a given down and distance range (yards-to-go, or ytg), the parameter values are stored as a function of yards-from-own-goal. Then, during run time, the parameter value is set using linear interpolation over yfog. This gives a very flexible input scheme. As a concrete example, here are example parameter values for ``going for it on 4th'',\n\n\\begin{verbatim}\n4thGoForItProb 4 1 1 0 0\n4thGoForItProb 4 1 1 20 0\n4thGoForItProb 4 1 1 50 0.24\n4thGoForItProb 4 1 1 60 0.78\n4thGoForItProb 4 1 1 70 0.75\n4thGoForItProb 4 1 1 85 0.42\n4thGoForItProb 4 1 1 100 0.50\n\n4thGoForItProb 4 2 4 0 0\n4thGoForItProb 4 2 4 20 0\n4thGoForItProb 4 2 4 40 0.07\n4thGoForItProb 4 2 4 50 0.10\n4thGoForItProb 4 2 4 60 0.45\n4thGoForItProb 4 2 4 80 0.14\n4thGoForItProb 4 2 4 100 0.14\n\\end{verbatim}\n\nThis says that, when its 4th and between 1 and 1 to go (in other words precisely 1), if yfog is between 0 and 20, then interpolate between 0 and 0. In other words the probability to go for it is 0. If yfog is between 20 and 50, interpolate between 0 and 0.24. So for example, half way in between, when yfog=35, the probability would be 0.12. On the other hand, if yards-to-go is between 2 and 4 (inclusive), then the probability at yfog=35 will be the slope, $(0.07-0.00)/(40-20)$, times $35-20 = 15$, plus the initial value at yfog = 20, which is 0. That is, $0 + 0.07/20*15 = 0.0525$, which is a long-winded way of saying that the value is determined through linear interpolation between the points (20, 0) and (40, 0.07). \n. If down is set to 0, it means the parameters hold for downs 1-4. The parameters that are controllable are,\n\n\\begin{verbatim}\nintProb: interception probability\nfumProb: fumble probability\nincompleteProb: incompletion probability\nyardsDistParsRush: parameters of the Bazin-Gauss function for rushes (G identically 0)\nyardsDistParsPass: parameters of the Bazin-Gauss function for passes\n4thGoForItProb: probability to go for it on 4th\n4thFgProb: probability to go for a field goal on 4th\nFgMakeProb: probability to make a field goal\npassProb: given that you run a play, the probability to pass\n\\end{verbatim}\n\nThe code has two modes, empirical and user-defined. If the empirical model is chosen, the parameters controlling the yards-gained distributions are ignored and the distributions are instead read in empirically. \nThe final input is a model name, which determines the output data file name, where the transition matrix and the expectation value vector (among other things) are stored for later reference or ease of comparison to a different model.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n% figures\n\\begin{figure} [!th] \n\\begin{center}\n\\includegraphics[width=4.50in]{markovChains_05.eps}\n\\end{center}\n\\caption{\npoints\n }\n\\label{fignm_05}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{markovChains_06.eps}\n\\end{center}\n\\caption{\npoints\n }\n\\label{fignm_06}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{markovChains_09.eps}\n\\end{center}\n\\caption{\npoints\n }\n\\label{fignm_09}\n\\end{figure}\n\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{nflMarkov1.eps}\n\\end{center}\n\\caption{\nmean yards per play as a function of field position. black is 1st and 10 or more, red is 3 and short, specifically 3 or less. dashed lines show +- 1 standard deviation. what I take away from this is that the standard deviation is so large that you don’t have to worry about variation that depends on field position as long as you’re at 75 yards or less.\n }\n\\label{fignm1}\n\\end{figure}\n\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{nflMarkov2.eps}\n\\end{center}\n\\caption{\n(green, blue, red) = (2nd, 3rd, 4th) downs. The only 1st down values that matter are 1st and 5, 1st and 10 and first and 15, which are\n1 and 5 : 5.27 +- 8.63\n1 and 10; : 5.71 +- 9.00\n1 and 15; : 6.15 +- 8.94\n }\n\\label{fignm2}\n\\end{figure}\n\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{nflMarkov3.eps}\n\\end{center}\n\\caption{\nhere is fraction of plays that are passes by yard from own goal. black, green, blue are 1st, 2nd 3rd downs. the point at yfog=29 is interesting; if you are 3rd down at the 29, you probably got there starting from 1st and 10 at the 20 (a touchback) so you are 3rd and 1 and you rush more often. its so logical!\n }\n\\label{fignm3}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{nflMarkov5.eps}\n\\end{center}\n\\caption{\nhere is fraction of plays that are passes (given that its either a pass or a rush and originates between yfog=20 and yfog=75), based on distance to a first down. green, blue, red are 2nd, 3rd, 4th downs. 1st and 10 is 49.83\\% pass (with N=88547).\n }\n\\label{fignm5}\n\\end{figure}\n\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{empProbs1.eps}\n\\end{center}\n\\caption{\nProbabilities to attempt (pass, rush, field goal, punt) for 4th and $\\ge 4$\n }\n\\label{figep1}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{empProbs2.eps}\n\\end{center}\n\\caption{\nProbabilities to attempt (pass, rush, field goal, punt) for 4th and $< 4$\n }\n\\label{figep2}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{empProbs3.eps}\n\\end{center}\n\\caption{\nProbabilities to attempt (pass, rush, field goal, punt) for 4th and 1\n }\n\\label{figep3}\n\\end{figure}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{nflMarkov6.eps}\n\\end{center}\n\\caption{\ndistributions of yards gained for all 1st downs that originate between 20 and 75, left panel is passes (35\\% or so gain 0 yards), right is rushes.\n }\n\\label{fignm6}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{empYardsDist.eps}\n\\end{center}\n\\caption{\ndistributions of yards gained for all 1st downs that originate between 20 and 75, left panel is passes (35\\% or so gain 0 yards), right is rushes.\n }\n\\label{figye1}\n\\end{figure}\n\n\\begin{figure} [!ht] \n\\begin{center}\n\\includegraphics[width=4.50in]{modelYardsDist.eps}\n\\end{center}\n\\caption{\ndistributions of yards gained for all 1st downs that originate between 20 and 75, left panel is passes (35\\% or so gain 0 yards), right is rushes.\n }\n\\label{figym1}\n\\end{figure}\n\n\\end{document}\n\n", "meta": {"hexsha": "94a858440030fdfb3976a90dba7016c2f524c571", "size": 31858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/nflMarkov_k_of_n.tex", "max_stars_repo_name": "microprediction/nflMarkov", "max_stars_repo_head_hexsha": "ec9ebaf98d760c3bb06b13bd14ef608d3cd7685a", "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/nflMarkov_k_of_n.tex", "max_issues_repo_name": "microprediction/nflMarkov", "max_issues_repo_head_hexsha": "ec9ebaf98d760c3bb06b13bd14ef608d3cd7685a", "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/nflMarkov_k_of_n.tex", "max_forks_repo_name": "microprediction/nflMarkov", "max_forks_repo_head_hexsha": "ec9ebaf98d760c3bb06b13bd14ef608d3cd7685a", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-18T00:38:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-19T16:03:02.000Z", "avg_line_length": 38.5690072639, "max_line_length": 1450, "alphanum_fraction": 0.6571661749, "num_tokens": 11017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219505, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6562604868632357}}
{"text": "\\documentclass{article} \n\n\\usepackage[a4paper, total={6in, 8in}]{geometry}\n% include some useful things\n\\usepackage{verbatim}  % for printing unformatted text\n\\usepackage{float}         % for controlling the location of figure and graphics on the page\n\\usepackage{blindtext}\n\\usepackage{graphicx}\\usepackage{amsmath}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{caption}\n\\usepackage{subcaption}\n%  Begin writing content below this line\n\n\\begin{document}\n\n%  Print your name and the assignment number\n\\begin{center}{\\huge  Deepayan Bhadra - hmwk4 Solutions}\\end{center}\n\n\\section*{Q1(a): Optimality condition for  L2 denoising}\n% The verbatim environment is good for reproducing text without having latex try to format it for you.\nmin $\\frac{\\mu}{2}||\\nabla{x}||^2 + \\frac{1}{2}||x-b||^2$ \n\\\\\\\\\nTaking the gradient and setting it to zero gives the necessary condition: \n\\\\\\\\\n$\\mu \\nabla^T\\nabla(x) + x - b = 0$ \n\\\\\\\\ \nWriting this in the form of a large linear system Ax = b gives \\\\\\\\\n$ (\\mu \\nabla^T\\nabla + I)(x) = b $ \n\n\\section*{Q1(b): Creating Function Handle for linear operator A}\n\n\\begin{verbatim}\n\nimg= mpimg.imread('lena512.bmp')\nimg = img.astype(float)\nb = img/max(img.flatten()) # Scaling to [0,1]\nmu = 2\nx0 = np.random.randn(*b.shape)\nf = lambda x:mu*div2d(grad2d(x))+x-b\noutput = f(x0) # Evaluating A at x0 \n\n\\end{verbatim}\n\n\\section*{Q1(c): Richardson Iteration}\n\n\\begin{verbatim}\n\ndef richardson(A,b,x,t):\n    resids = 1\n    all_res = []\n    while resids > 10e-6:\n        x = x+t*(b-A(x))\n        resids = np.linalg.norm(b-A(x),'fro')\n        all_res = np.append(all_res,resids)\n    return all_res,x\n\nt = 0.05    \nall_res,x = richardson(f,b,x0,t)        \nplt.xlabel('# of iterations')\nplt.ylabel('Residual norm')\nplt.plot(all_res)\nprint(\"# of iterations to convergence is\",all_res.size)\nplt.imshow(b) # Noisy image\nplt.imshow(x.astype(float)) # De-noised image\n\n\\end{verbatim}\n\n\n\\textbf{\\Large{No. of iterations to convergence is 334}}\n\n\\begin{figure}[h!]\n\\centering\n\\begin{subfigure}[h!]{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.5] {./pictures/Noisy1c.jpg}\n\\caption{Richardson: Noisy Image}\n\\end{subfigure}\n\\begin{subfigure}[h!]{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.5] {./pictures/Denoised1c.jpg}\n\\caption{Richardson: De-noised Image}\n\\end{subfigure}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics [scale = 0.85] {./pictures/1c.jpg}\n\\caption{Richardson: Residual norm v/s No. of Iterations}\n\\end{figure}\n\n\\textbf{\\large{(Plots at the end)}}\n\n\n\\section*{Q1(d): Conjugate Gradient}\n\n\\begin{verbatim}\n\ndef conjgrad(A,b,x):\n    tol = 10e-6;\n    xk = x; rk = b-A(xk); pk = rk # Initial values \n    res = [];\n    while np.linalg.norm(rk)>tol:\n        grad = A(pk);\n        alpk = np.dot(rk.flatten(),rk.flatten())/(np.dot(pk.flatten(),\n                                                     grad.flatten()))\n        xk = xk+alpk*pk;\n        rkk = rk-alpk*grad;\n        betak = np.dot(rkk.flatten(),rkk.flatten())/(np.dot(rk.flatten(),\n                                                           rk.flatten()))\n        pk = rkk+betak*pk;\n        rk = rkk;\n        res = np.append(res,np.linalg.norm(rk,'fro')) \n        # Storing all the residuals \n        \n    return x,resids\n\n[x,res] = conjgrad(f,b,x0)\nplt.xlabel('# of iterations')\nplt.ylabel('Residual norm')\nplt.plot(all_res)\nprint(\"No of iterations to convergence is\",all_res.size)\nplt.imshow(b) # Noisy image\nplt.imshow(x.astype(float)) # De-noised image\n\n\\end{verbatim}\n\n\\textbf{\\Large{No. of iterations to convergence is 34}}\\\\\n\\textbf{\\large{(Plots at the end)}}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics [scale = 0.85] {./pictures/1d.jpg}\n\\caption{Conjugate Gradient: Residual norm v/s No. of Iterations}\n\\end{figure}\n\\begin{figure}[h!]\n\\centering\n\\begin{minipage}{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.5] {./pictures/Noisy1c.jpg}\n\\caption{Conjugate Gradient: Noisy Image}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.5] {./pictures/Denoised1c.jpg}\n\\caption{Conjugate Gradient: De-noised Image}\n\\end{minipage}\n\\end{figure}\n\n\\section*{Q1(e): With mu = 10}\n\nThe iteration count increases almost two-fold. This is because, now significantly less weight (1/10) is allotted to the difference factor (x-b) (Images and convergence plots at the end)\n\n\n\\section*{Q1(f): Compute exact solutions using FFT}\n\n\\begin{verbatim}\n\ndef l2denoise(b,mu):\n    kernel = np.zeros((b.shape[0],b.shape[1]))\n    kernel[0,0] = 1\n    kernel[0,1] = -1\n    Dx = np.fft.fft2(kernel)\n    kernel = np.zeros((b.shape[0],b.shape[1]))\n    kernel[0,0] = 1\n    kernel[1,0] = -1\n    Dy = np.fft.fft2(kernel)\n    dd = np.divide(1,(mu*(np.conj(Dx)*Dx+np.conj(Dy)*Dy)+1))\n    x = np.real(np.fft.ifft2(dd*np.fft.fft2(b)))\n    return x\n\nprint('The norm of the gradient of the objective function is')\nnp.linalg.norm(f(l2denoise(b,mu)))\n\n\\end{verbatim}\n\n\\textbf{\\Large{The norm of the gradient of the objective function is\nans = 7.0224e-13}}\n\n\n\\section*{Q2(a): Building Two-Moons dataset}\n\n\n\\begin{verbatim}\ndef make_moons(n):\n    \"\"\"Create a 'two moons' dataset with n feature vectors, \n        and 2 features per vector.\"\"\"\n        \n    assert n%2==0, 'n must be even'\n    # create upper moon\n    theta = np.linspace(-pi / 2, pi / 2, n//2)\n    # create lower moon\n    x = np.r_[np.sin(theta) - pi / 4, np.sin(theta)]\n    y = np.r_[np.cos(theta), -np.cos(theta) + .5]\n    data = np.c_[x, y]\n    # Add some noise\n    data = data + 0.03 * np.random.standard_normal(data.shape)\n\n    # create labels\n    labels = np.r_[np.ones((n//2, 1)), -np.ones((n//2, 1))]\n    labels = labels.ravel().astype(np.int32)\n\n    return data,labels\n\ndata,l = make_moons(100)\nplt.scatter(data[l>0,0],data[l>0,1],c='r')\nplt.scatter(data[l<0,0],data[l<0,1],c='b')\nplt.show()    \nS = np.zeros((100,100))\nsig = 0.09\nB = pdist(data)\nC = squareform(B)\nS = np.exp(-C/sig)\n    \n\\end{verbatim}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics [scale = 0.75] {./pictures/2aTwoMoons.jpg}\n\\caption{Small Dataset: Two Moons}\n\\end{figure}\n\\section*{Q2(b): Compute Normalized Similarity Matrix}\n\n\\begin{verbatim}\nS_sum = np.sum(S,axis=1,keepdims = True)\nD = np.diagflat(S_sum)\ntemp = np.power(S_sum,-0.5)\nS_hat = np.diagflat(temp).dot(S).dot(np.diagflat(temp))\n\\end{verbatim}\n\n\\section*{Q2(c): Spectral Embedding}\n\n\\begin{verbatim}\nE,V = np.linalg.eig(S_hat)\nidx = E.argsort()[::-1]\nE = E[idx]\nV = V[:,idx]\n\nU2 = np.stack([V[:,1],V[:,2]],axis=1)\nplt.scatter(U2[l==1,0],U2[l==1,1],c='r')\nplt.scatter(U2[l==-1,0],U2[l==-1,1],c='b')\nplt.show()\n\\end{verbatim}\n\\textbf{\\large{(Combined plots at the end)}}\n\\section*{Q2(d): k-means clustering}\n\n\\begin{verbatim}\nkmeans = KMeans(n_clusters = 2)\ny_kmeans = kmeans.fit_predict(U2)\nplt.scatter(U2[y_kmeans == 0, 0], U2[y_kmeans == 0, 1], s = 100, c = 'red', label = 'Cluster 1')\nplt.scatter(U2[y_kmeans == 1, 0], U2[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Cluster 2')\nplt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], \n\t\t\t\ts = 300, c = 'yellow', label = 'Centroids')\n\\end{verbatim}\n\n\\begin{figure}[h!]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.75] {./pictures/2cSE.jpg}\n\\caption{Spectral Embedding: Scattered columns of U2}\n\\end{subfigure}\n\\begin{subfigure}[h!]{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.75] {./pictures/2dKM.jpg}\n\\caption{k-means clustering}\n\\end{subfigure}\n\\end{figure}\n\n\\section*{Q3(a): Spectral Grouping Using Nystrom Method}\n\n\\begin{verbatim}\ndata,l = make_moons(100000)\nsig = 0.09\nidx = np.random.choice(100000,size = 200, replace=False) # Random Sampling of 200 columns \nidx_c = np.setdiff1d(np.arange(100000),idx)\ntemp1 = cdist(data,data[idx,:]) # Pairwise distance between two sets of observations\nC = np.exp(-temp1/sig)\nW = C[idx,:]\n\\end{verbatim}\\\\\n\n\\section*{Q3(b): Forming Normalized C, W, M matrices}\n\n\\begin{verbatim}\nZ = C[200:,:]\nW_m = np.sum(W,axis=1,keepdims = True)+ np.sum(np.transpose(Z),\n                                                 axis=1,keepdims = True) \nM_e = np.sum(Z,axis=1,keepdims = True)+ np.transpose(np.sum(Z,\n                                                 axis=0,keepdims = True)\n                                                .dot(np.linalg.inv(W))\n                                                .dot(np.transpose(Z))) \ndiagD = np.concatenate([W_m,M_e],axis=0)\ntemp = np.multiply(np.repeat(diagD,200,axis=1),C)\nC_n = np.dot(temp,np.diagflat(diagD[idx]))\nW_n = C_n[idx,:]\nM_n = C_n[idx_c,:]\n\\end{verbatim}\n\n\\section*{Q3(c): Approximate eigenvectors}\n\n\\begin{verbatim}\nW_hat = W_n + sp.linalg.sqrtm(np.linalg.inv(W_n)).dot(np.transpose(M_n)).dot(M_n).\ndot(sp.linalg.sqrtm(np.linalg.inv(W_n))) \n# Orthogonalization matrix \n\nD_w,U_w = np.linalg.eig(W_hat)\nD_w,U_w = np.real(D_w), np.real(U_w) \n\n# Eigen-decomposition W_hat = V*D*V' \n\nU = np.matmul(C_n,np.matmul(sp.linalg.sqrtm(np.linalg.inv(W_n)),U_w))*\nnp.power(np.expand_dims(D_w,axis=-1),-0.5).T\n\nidx = np.argsort(D_w)[::-1]\nU_w = U_w[idx]\nU = U[:,idx]\n\n\nU = U/np.expand_dims(U[:,0],axis=-1)\nU2 = np.expand_dims(U[:,1],axis=-1)\nplt.scatter(U2[l==1],U2[l==1],c='r')\nplt.scatter(U2[l==-1],U2[l==-1],c='b')\nplt.show()\n# Approximate eigen-vectors\n\\end{verbatim}\n\n\\textbf{\\large{(Combined plots at the end)}}\n\n\\section*{Q3(d): k-means}\n\n\\begin{verbatim}\nkmeans = KMeans(n_clusters = 2)\nU2 = U[:,-3:-1]\ny_kmeans = kmeans.fit_predict(U2)\nplt.scatter(U2[y_kmeans == 0, 0], U2[y_kmeans == 0, 1], s = 100, c = 'red', label = 'Cluster 1')\nplt.scatter(U2[y_kmeans == 1, 0], U2[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Cluster 2')\nplt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 300, c = 'yellow', \nlabel = 'Centroids')\n\\end{verbatim}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics [scale = 0.75] {./pictures/3aTwoMoons.jpg}\n\\caption{Large Dataset: Two Moons}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.75] {./pictures/3cSE.jpg}\n\\caption{Approximate eigenvectors: Scattered columns of U2}\n\\end{subfigure}\n\\begin{subfigure}[h!]{.5\\textwidth}\n\\centering\n\\includegraphics [scale = 0.75] {./pictures/3dKM.jpg}\n\\caption{k-means clustering}\n\\end{subfigure}\n\\end{figure}\n\\end{document}\n\n\n", "meta": {"hexsha": "f4509d493bae2365b4ec3bd40c8f2f1c75b4e8e7", "size": 10207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework-4/hmwk4.tex", "max_stars_repo_name": "dbhadra/CMSC764-Advanced-Numerical-Optimization", "max_stars_repo_head_hexsha": "c2ba0ffc58fbb00df370bb03998277977cade1a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework-4/hmwk4.tex", "max_issues_repo_name": "dbhadra/CMSC764-Advanced-Numerical-Optimization", "max_issues_repo_head_hexsha": "c2ba0ffc58fbb00df370bb03998277977cade1a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework-4/hmwk4.tex", "max_forks_repo_name": "dbhadra/CMSC764-Advanced-Numerical-Optimization", "max_forks_repo_head_hexsha": "c2ba0ffc58fbb00df370bb03998277977cade1a4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1961325967, "max_line_length": 185, "alphanum_fraction": 0.6492603116, "num_tokens": 3345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6562604868632356}}
{"text": "% !TEX root = ../../../proposal.tex\n\n\\section{Background}\n\n\\subsection{Groups, orders, and generators}\n\\label{sec:group-background}\n\nThe two types of groups used for Diffie-Hellman key exchange in practice are\nmultiplicative groups over finite fields (``mod $p$'') and elliptic curve\ngroups. We focus on the ``mod $p$'' case, so a group is typically specified by\na prime $p$ and a generator $g$, which generates a multiplicative subgroup\nmodulo $p$.  Optionally, the group order $q$ can be specified; this is the\nsmallest positive integer $q$ satisfying $g^q \\equiv 1 \\bmod p$.  Equivalently,\nit is the number of distinct elements of the subgroup $\\{g, g^2, g^3, \\dots\n\\bmod p\\}$.\n\nBy Lagrange's theorem, the order $q$ of the subgroup generated by $g$ modulo\n$p$ must be a divisor of $p-1$. Since $p$ is prime, $p-1$ will be even, and\nthere will always be a subgroup of order 2 generated by the element $-1$. For\nthe other factors $q_i$ of $p-1$, there are subgroups of order $q_i \\bmod p$.\nOne can find a generator $g_i$ of a subgroup of order $q_i$ using a randomized\nalgorithm: try random integers $h$ until $h^{(p-1)/q_i} \\ne 1 \\bmod p$; $g_i =\nh^{(p-1)/q_i} \\bmod p$ is a generator of the subgroup.  A random $h$ will\nsatisfy this property with probability $1 - 1/q_i$.\n\nIn theory, neither $p$ nor $q$ is required to be prime. Diffie-Hellman key\nexchange is possible with a composite modulus and with a composite group order.\nIn such cases, the order of the full multiplicative group modulo $p$ is\n$\\phi(p)$ where $\\phi$ is Euler's totient function, and the order of the\nsubgroup generated by $g$ must divide $\\phi(p)$. Outside of implementation\nmistakes, Diffie-Hellman in practice is done modulo prime $p$.\n%\\looseness=-1\n\n\\subsection{Diffie-Hellman Key Exchange}\n\nDiffie-Hellman key exchange allows two parties to agree on a shared secret in\nthe presence of an eavesdropper~\\cite{new-directions-in-crypto-1976}. Alice and Bob begin by\nagreeing on shared parameters (prime $p$, generator $g$, and optionally group\norder $q$) for an algebraic group.  Depending on the protocol, the group may be\nrequested by the initiator (as in IKE), unilaterally chosen by the responder\n(as in TLS), or fixed by the protocol itself (SSH originally built in support\nfor a single group).\n\nHaving agreed on a group, Alice chooses a secret $x_a < q$ and sends Bob $y_a =\ng^{x_a}\\bmod p$.  Likewise, Bob chooses a secret $x_b < q$ and sends Alice $y_b =\ng^{x_b}\\bmod p$. Each participant then computes the shared secret key\n$g^{x_a x_b}\\bmod p$.%  \\looseness=-1 \n\nDepending on the implementation, the public values $y_a$ and $y_b$ might be\n\\emph{ephemeral}---freshly generated for each connection---or \\emph{static} and\nreused for many connections.\n\n\\subsection{Discrete log algorithms}\n\nThe best known attack against Diffie-Hellman is for the eavesdropper to compute\nthe the private exponent $x$ by calculating the discrete log of one of Alice or\nBob's public value $y$. With knowledge of the exponent, the attacker can\ntrivially compute the shared secret.  It is not known in general whether the\nhardness of computing the shared secret from the public values is equivalent to\nthe hardness of discrete log.\n\nThe \\emph{computational Diffie-Hellman assumption} states that computing the\nshared secret $g^{x_ax_b}$ from $g^{x_a}$ and $g^{x_b}$ is hard for some choice\nof groups.  A stronger assumption, the \\emph{decisional Diffie-Hellman\nproblem}, states that given $g^{x_a}$ and $g^{x_b}$, the shared secret\n$g^{x_ax_b}$ is computationally indistinguishable from random for some groups.\nThis assumption is often not true for groups used in practice; even with safe\nprimes as defined below, many implementations use a generator that generates\nthe full group of order $p-1$, rather than the subgroup of order $(p-1)/2$.  This means\nthat a passive attacker can always learn the value of the secret exponent modulo 2.\nTo avoid leaking this bit of information about the exponent, both sides could agree to \ncompute the shared secret as $y^{2x} \\bmod p$.  We have not seen implementations\nwith this behavior.\n%\\looseness=-1\n\nThere are several families of discrete log algorithms, each of which apply to\nspecial types of groups and parameter choices. Implementations must take care\nto avoid choices vulnerable to any particular algorithm. These include:\n\n\\paragraph{Small-order groups}\nThe Pollard rho~\\cite{pollard1975monte} and Shanks' baby step-giant step\nalgorithms~\\cite{shanks1971class} each can be used to compute discrete logs in\ngroups of order $q$ in time $O(\\sqrt{q})$.  To avoid being vulnerable,\nimplementations must choose a group order with bit length at least twice the\ndesired bit security of the key exchange. In practice, this means that group\norders $q$ should be at least 160 bits for an 80-bit security level.\n\n\\paragraph{Composite-order groups}\nIf the group order $q$ is a composite with prime factorization $q = \\prod_i\nq_i^{e_i}$, then the attacker can use the Pohlig-Hellman\nalgorithm~\\cite{pohlig1978improved} to compute a discrete log in time $O(\\sum_i\ne_i \\sqrt{q_i})$.  The Pohlig-Hellman algorithm computes the discrete log in\neach subgroup of order $q_i^{e_i}$ and then uses the Chinese remainder theorem\nto reconstruct the log modulo $q$.  Adrian et al.~\\cite{logjam-2015} found\nseveral thousand TLS hosts using primes with composite-order groups, and were\nable to compute discrete logs for several hundred Diffie-Hellman key exchanges\nusing this algorithm.  To avoid being vulnerable, implementations should choose\n$g$ so that it generates a subgroup of large prime order modulo $p$.\n%\\looseness=-1\n\n\\paragraph{Short exponents}\nIf the secret exponent $x_a$ is relatively small or lies within a known range of\nvalues of a relatively small size, $m$, then the Pollard lambda ``kangaroo''\nalgorithm~\\cite{Pollard2000} can be used to find $x_a$ in time $O(\\sqrt{m})$.  To\navoid this attack, implementations should choose secret exponents to have bit\nlength at least twice the desired security level.  For example, using a 256-bit\nexponent for for a 128-bit security level.\n\n\\paragraph{Small prime moduli} When the subgroup order is not small or\ncomposite, and the prime modulus $p$ is relatively large, the fastest known\nalgorithm is the number field sieve~\\cite{discrete-log-nfs-1993}, which runs in\nsubexponential time in the bit length of $p$, $\\exp\\left((1.923+o(1))(\\log\np)^{1/3} (\\log \\log p)^{2/3}\\right)$. Adrian et al.~recently applied the number field sieve\nto attack 512-bit primes in about 90,000 core-hours~\\cite{logjam-2015}, and\nthey argue that attacking 1024-bit primes---which are widely used in\npractice---is within the resources of large governments. To avoid this attack,\ncurrent recommendations call for $p$ to be at least 2048\nbits~\\cite{sp800}. When selecting parameters, implementers should\nensure all attacks take at least as long as the number field sieve for their parameter set.\n\n\\subsection{Diffie-Hellman group characteristics}\n\n\\paragraph{``Safe'' primes}\nIn order to maximize the size of the subgroup used for Diffie-Hellman, one can\nchoose a $p$ such that $p = 2q + 1$ for some prime $q$. Such a $p$ is called a\n``safe'' prime, and $q$ is a Sophie Germain prime.  For sufficiently large safe\nprimes, the best attack will be solving the discrete log using the number field\nsieve.\nMany standards explicitly specify the use of safe primes for Diffie-Hellman in\npractice.  The Oakley protocol~\\cite{rfc2412} specified five ``well-known''\ngroups for Diffie-Hellman in 1998. These included three safe primes of size\n768, 1024, and 1536 bits, and was later expanded to include six more groups in\n2003~\\cite{rfc3526}. The Oakley groups have been built into numerous other\nstandards, including IKE~\\cite{rfc2409} and SSH~\\cite{rfc4253}.\n\n%Given a finite field, with a cyclic group modulo some prime, $\\mathbb{Z}/p$, and group operations $+$ and $\\cdot$. \n%\n%Both participants choose an element, $a$ and $b$ respectively, randomly from the integers up to the order of the subgroup. The public keys take the form of $g^a$ and $g^b$ where $g$ is a generator of the subgroup and exponentiation is repeated application of the multiplication operation within the group. Both parties then exponentiate their partners public key by their secret to yield values of $g^{ba}$ and $g^{ab}$ respectively. By the abelian nature of the group these are the same group element, thus yielding a shared secret. \n%\n%For the case where the group is sufficiently large, not of smooth order, and $a$ and $b$ are of sufficient length, the Diffie-Hellman assumption posits that that the most efficient way to find the value of $g^{ab}$ given only $g^{a}$ and $g^{b}$ is equivalent to finding a solution to an instance of the discrete log problem, which is assumed hard. However, the above relies on three assumptions that can all be targeted in real implementations of the protocol.\n%\n%The solution to the DLP can be found if the group has a small number of elements or the exponent is small enough such that there is no 'wrap-around' when the generator is exponentiated, reducing the problem to solving the logarithm in the integers.\n%\n%A group can be chosen such that it contains a subgroup in which all the prime factors of the generator are smaller than some value $B$, which for integers is called a '$B-smooth$' integer. Then an attacker can solve the discrete log problem in the orders of the factors, and using the Chinese remainder theorem can reconstruct the unique solution in the original group.\n%\n\n\\paragraph{DSA groups}\nThe DSA signature algorithm~\\cite{fips186} is also based on the hardness of\ndiscrete log.  DSA parameters have a subgroup order $q$ of much smaller size\nthan $p$.  In this case $p-1 = q r$ where $q$ is prime and $r$ is a large\ncomposite, and $g$ generates a group of order $q$.  FIPS 186-4~\\cite{fips186}\nspecifies 160-bit $q$ for 1024-bit $p$ and 224- or 256-bit $q$ for 2048-bit\n$p$.  The small size of the subgroup allows the signature to be much shorter\nthan the size of $p$.\n\n\\subsection{DSA Group Standardization}\n\nDSA-style parameters have also been recommended for use for Diffie-Hellman key\nexchange.  NIST Special Publication 800-56A, ``Recommendation for Pair-Wise Key\nEstablishment Schemes Using Discrete Logarithm\nCryptography''~\\cite{sp800}, first published in 2007, specifies that\nfinite field Diffie-Hellman should be done over a prime-order subgroup $q$ of\nsize 160 bits for a 1024-bit prime $p$, and a 224- or 256-bit subgroup for a\n2048-bit prime.  While the order of the multiplicative subgroups is in line\nwith the hardness of computing discrete logs in these subgroups, no explanation\nis given for recommending a subgroup of precisely this size rather than setting\na minimum subgroup size or using a safe prime.  Using a shorter exponent will\nmake modular exponentiation more efficient, but the order of the subgroup $q$\ndoes not increase efficiency---on the contrary, the additional modular exponentiation\nrequired to validate that a received key exchange message is contained in the correct\nsubgroup will render key exchange with DSA primes less efficient than using a ``safe'' \nprime for the same exponent length.  Choosing a small subgroup order is not known to have\nmuch impact on other cryptanalytic attacks, although the number field sieve is\nsomewhat (not asymptotically) easier as the linear algebra step is performed\nmodulo the subgroup order $q$.~\\cite{logjam-2015}\n\nRFC 5114, ``Additional Diffie-Hellman Groups for Use with IETF\nStandards''~\\cite{rfc5114}, specifies three DSA groups with the above orders\n``for use in IKE, TLS, SSH, etc.''  These groups were taken from test data\npublished by NIST~\\cite{nistffcsamples}. They have been widely implemented in\nIPsec and TLS, as we will show below. We refer to these groups as Group 22\n(1024-bit group with 160-bit subgroup), Group 23 (2048-bit group with 224-bit\nsubgroup), and Group 24 (2048-bit group with 256-bit subgroup) throughout the\nremainder of the paper to be consistent with the group numbers assigned for\nIKE.\n\nRFC 6989, ``Additional Diffie-Hellman Tests for the Internet Key Exchange\nProtocol Version 2 (IKEv2)''~\\cite{rfc6989}, notes that ``mod $p$'' groups with\nsmall subgroups can be vulnerable to small subgroup attacks, and mandates that\nIKE implementations should validate that the received value is in the correct\nsubgroup or never repeat exponents.\n\n\\subsection{Small subgroup attacks}\n\\label{subsec:small-subgroup-attack}\n\nSince the security of Diffie-Hellman relies crucially on the group parameters,\nimplementations can be vulnerable to an attacker who provides maliciously\ngenerated parameters that change the properties of the group. \nWith the right parameters and implementation decisions, an attaker may be able\nto efficiently determine the Diffie-Hellman shared secret. In some cases, a\npassive attacker may be able to break a transcript offline.\n\n\\paragraph{Small subgroup confinement attacks}\nIn a small subgroup confinement attack, an attacker (either a man-in-the-middle\nor a malicious client or server) provides a key-exchange value $y$ that lies in a\nsubgroup of small order.  This forces the other party's view of the shared\nsecret, $y^x$, to lie in the subgroup generated by the attacker.  This\ntype of attack was described by van Oorschot and Wiener~\\cite{van1996diffie}\nand ascribed to Vanstone and Anderson and Vaudenay~\\cite{anderson-1996}.  Small\nsubgroup confinement attacks are possible even when the server does not repeat\nexponents---the only requirement is that an implementation does not validate\nthat received Diffie-Hellman key exchange values are in the correct subgroup.\n\n%Consider a simplified Diffie-Hellman key exchange protocol where Alice and Bob negotiate a shared secret $k = g^{ab} \\bmod p$ using Diffie-Hellman key exchange, and then Alice symmetrically encrypts a message using the secret $k$ and transmits it to Bob.  Alice might specify a safe prime $p$ and a generator $g$ of order $q = (p-1)/2$, and use a static Diffie-Hellman public value $y_a = g^a \\bmod p$.  \n\nWhen working $\\bmod\\,p$, there is always a subgroup of order 2, since $p-1$ is\neven. A malicious client Mallory could initiate a Diffie-Hellman key exchange\nvalue with Alice and send her the value $y_M = p-1 \\equiv -1 \\bmod p$, which is\nis a generator of the group of order $2 \\bmod p$.  When Alice attempts to\ncompute her view of the shared secret as $k_a = y_M^a \\bmod p$, there are only\ntwo possible values, $1$ and $-1 \\bmod p$.\n\nThe same type of attack works if $p-1$ has other small factors $q_i$.  Mallory\ncan send a generator $g_i$ of a group of order $q_i$ as her Diffie-Hellman key\nexchange value. Alice's view of the shared secret will be an element of the\nsubgroup of order $q_i$. Mallory then has a $1/q_i$ chance of blindly guessing Alice's\nshared secret in this invalid group. Given a message from Alice encrypted using\nAlice's view of the shared secret, Mallory can brute force Alice's shared secret in $q_i$ guesses.\n\nMore recently, Bhargavan and\nDelignat-Lavaud~\\cite{bhargavan-channel-bindings-2015} describe ``key synchronization''\nattacks against IKEv2 where a man-in-the-middle connects to both the initiator and\nresponder in different connections, uses a small subgroup confinement attack\nagainst both, and observes that there is a $1/q_i$ probability of the shared\nsecrets being the same in both connections.  Bhargavan and Leurent~\\cite{sloth-2016}\ndescribe several attacks that use subgroup confinement attacks to obtain a\ntranscript collision and break protocol authentication.\n\nTo protect against subgroup confinement attacks, implementations should use\nprime-order subgroups with known subgroup order. Both parties must validate\nthat the key exchange values they receive are in the proper subgroup. That is,\nfor a known subgroup order $q$, a received Diffie-Hellman key exchange value\n$y$ should satisfy $y^q \\equiv 1 \\bmod p$.  For a safe prime, it suffices to\ncheck that $y$ is strictly between $1$ and $p-1$. \n\n\\paragraph{Small subgroup key recovery attacks}\nLim and Lee~\\cite{lim-1997} discovered a further attack that arises when an\nimplementation fails to validate subgroup order and resues a static\nsecret exponent for multiple key exchanges. A malicious party may be able\nto perform multiple subgroup confinement attacks for different prime factors\n$q_i$ of $p-1$ and then use the Chinese remainder theorem to reconstruct the\nstatic secret exponent.\n\nThe attack works as follows.  Let $p-1$ have many small factors $p-1 = q_1 q_2\n\\dots q_n$.  Mallory, a malicious client, uses the procedure described in\nSection~\\ref{sec:group-background} to find a generator of the subgroup $g_i$ of\norder $q_i \\bmod p$.  Then Mallory transmits $g_i$ as her Diffie-Hellman key\nexchange value, and receives a message encrypted with Alice's view of the\nshared secret $g_i^{x_a}$, which Mallory can brute force to learn the value of\n$x_a \\bmod q_i$.  Once Mallory has repeated this process several times, she can\nuse the Chinese remainder theorem to reconstruct $x_a \\bmod \\prod_i q_i$.  The\nrunning time of this attack is $\\sum_i q_i$, assuming that Mallory performs an\noffline brute-force search for each subgroup.\n\nA randomly chosen prime $p$ is likely to have subgroups of large enough order\nthat this attack is infeasible to carry out for all subgroups.  However, if in\naddition Alice's secret exponent $x_a$ is small, then Mallory only needs to carry out this\nattack for a subset of subgroups of orders $q_1, \\dots, q_k$ satisfying\n$\\prod_{i=0}^k q_i > x_a$, since the Chinese remainder theorem ensures that $x_a$\nwill be uniquely defined.\nMallory can also improve on the running time of the attack by taking advantage\nof the Pollard lambda algorithm.  That is, she could use a small subgroup\nattack to learn the value of $x_a \\bmod \\prod_{i=1}^k q_i$ for a subset of\nsubgroups $\\prod_{i=1}^k q_i < x_a$, and then use the Pollard lambda algorithm to\nreconstruct the full value of $a$, as it has now been confined to a smaller\ninterval.\n\nIn summary, an implementation is vulnerable to small subgroup key recovery\nattacks if it does not verify that received Diffie-Hellman key exchange values\nare in the correct subgroup; uses a prime $p$ such that $p-1$ has small\nfactors; and reuses Diffie-Hellman secret exponent values.  The attack is made\neven more practical if the implementation uses small exponents.\n\nA related attack exists for elliptic curve groups: an invalid curve attack.\nSimilarly to the case we describe above, the attacker generates a series of\nelliptic curve points of small order and sends these\npoints as key exchange messages to the victim.  If the victim does not validate that the received\npoint is on the intended curve, they return a response that reveals information\nabout the secret key modulo different group orders.  After enough queries, the\nattacker can learn the victim's entire secret.  Jager, Schwenk, and\nSomorovsky~\\cite{jager-2015} examined eight elliptic curve implementations and\ndiscovered two that failed to validate the received curve point. For elliptic\ncurve groups, this attack can be much more devastating because the attacker has\nmuch more freedom in generating different curves, and can thus find many\ndifferent small prime order subgroups.  For the finite field Diffie-Hellman\nattack, the attacker is limited only to those subgroups whose orders are factors\nof $p-1$.\n\n", "meta": {"hexsha": "aed5024d6649e48ccdbda546c85fca618b6d0f69", "size": 19395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/subgroup/paper/background.tex", "max_stars_repo_name": "dadrian/dissertation", "max_stars_repo_head_hexsha": "5607114fb4340c5b6e944c73ed6019006d3ebec9", "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/subgroup/paper/background.tex", "max_issues_repo_name": "dadrian/dissertation", "max_issues_repo_head_hexsha": "5607114fb4340c5b6e944c73ed6019006d3ebec9", "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/subgroup/paper/background.tex", "max_forks_repo_name": "dadrian/dissertation", "max_forks_repo_head_hexsha": "5607114fb4340c5b6e944c73ed6019006d3ebec9", "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.8662207358, "max_line_length": 535, "alphanum_fraction": 0.7772106213, "num_tokens": 4948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6561124015095924}}
{"text": "﻿\\documentclass{myart}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{colortbl}\n\n\\begin{document}\n\\renewcommand\\figurename{Fig}\n\\thispagestyle{empty}\n\\newpage\n\n\\pagestyle{plain}\n\\pagenumbering{arabic}\n\n\\begin{center}\n\\huge SOLUTION\n\\end{center}\n\n\\begin{center}\n\\large Author:Name \\qquad Student ID:21*****\n\\end{center}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Problem 1}\nFirst, use the bilineartransformation maps:\n\\begin{equation}\nz=\\frac{1+s}{1-s}\n\\end{equation}\n\\qquad We can get\n\\begin{equation}\n(\\frac{15}{4}-K)s^2+\\frac{1}{2}s+(K-\\frac{1}{4})=0\n\\end{equation}\n\\qquad Then, use Routh-Hurwitz criterion\n\\begin{equation}\n\\begin{aligned}\ns^2& \\qquad &\\frac{15}{4}-K \\qquad &K-\\frac{1}{4}\\\\\ns&   \\qquad &\\frac{1}{2}    \\qquad &\\\\\n1&   \\qquad &K-\\frac{1}{4}  \\qquad &\n\\end{aligned}\n\\end{equation}\n\\qquad If the system is stable, it needs to meet the following conditions at the same time\n\\begin{equation}\n\\left.\n\\begin{cases}\n\\frac{15}{4}>0\\\\\nK-\\frac{1}{4}>0\n\\end{cases}\n\\right.\n\\end{equation}\n\\qquad So, the range of K is\n\\begin{equation}\n\\frac{1}{4}<K<\\frac{15}{4}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Problem 2}\n\\subsection{(a)}\n\\begin{equation}\n\\begin{split}\nG(z)&=(1-z^{-1})\\cdot Z[\\frac{1}{s}\\cdot \\frac{5}{s(s+1)}] \\\\\n&=(1-z^{-1})\\cdot Z[5(\\frac{1}{s^2}-\\frac{1}{s}+\\frac{1}{s+1})] \\\\\n&=\\frac{5[(T-1+e^{-T})z+(1-e^{-T}-Te^{-T})]}{(z-1)(z-e^{-T})}\n\\end{split}\n\\end{equation}\n\n\\begin{equation}\n\\begin{split}\nT(z)&=\\frac{G(z)}{1+GH(z)}\\\\\n&=\\frac{G(z)}{1+G(z)}\\\\\n&=\\frac{5[(T-1+e^{-T})z+(1-e^{-T}-Te^{-T})]}{(z-1)(z-e^{-T})+5[(T-1+e^{-T})z+(1-e^{-T}-Te^{-T})]}\n\\end{split}\n\\end{equation}\n\n\\subsection{(b)}\nLet $a=T-1+e^{-T}$, and $b=1-e^{-T}-Te^{-T}$, then\n\\begin{equation}\nT(z)=\\frac{5az+5b}{(z-1)(z-e^{-T})+5az+5b}\n\\end{equation}\n\\qquad The characteristic equation of this system is\n\\begin{equation}\n(z-1)(z-e^{-T})+5az+5b=0\n\\end{equation}\n\\qquad When T=0.1s, $a=0.1-1+e^{-0.1}\\approx 0.0048$, $b=1-e^{-0.1}-0.1e^{-0.1}\\approx 0.0047$.\\par\nThe characteristic equation is\n\\begin{equation}\nz^2-1.88z+0.93=0\n\\end{equation}\n\\qquad Use Jury's stability criterion\n\\begin{equation}\n\\begin{tabular}{p{1cm} p{2cm} p{2cm} p{2cm}}\n   &       1&  -1.88& 0.93\\\\\n -)&    0.93&  -1.88&    1\\\\\n\\hline\n   &   \\cellcolor[rgb]{.99,.3,.3}0.135& -0.132&    0\\\\\n -)&  -0.132&  0.135&    \\\\\n \\hline\n   & \\cellcolor[rgb]{.99,.3,.3}0.00593&      0&     \\\\\n\\end{tabular}\n\\end{equation}\n\\qquad So the system is STABLE when T=0.1s.\n\n\\subsection{(c)}\nSimilarly, when T=1s, $a=1-1+e^{-1}\\approx 0.368$, $b=1-e^{-1}-e^{-1}\\approx 0.264$.\\par\nThe characteristic equation is\n\\begin{equation}\nz^2+0.47z+1.69=0\n\\end{equation}\n\\qquad Use Jury's stability criterion\n\\begin{equation}\n\\begin{tabular}{p{1cm} p{2cm} p{2cm} p{2cm}}\n   &       1&   0.47& 1.69\\\\\n -)&    1.69&   0.47&    1\\\\\n\\hline\n   &   \\cellcolor[rgb]{.99,.3,.3}-1.86& -0.324&    0\\\\\n\\end{tabular}\n\\end{equation}\n\\qquad So the system is UNSTABLE when T=1s.\n\n\\subsection{(d)}\nThe stability of the discrete system is related to the sampling period. If the sampling period is too long, a stable system may not be stable anymore.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Problem 3}\n\\subsection{(a)}\nUse Matlab to solve this problem.\n\\lstinputlisting[language=Matlab]{./code/p3.m}\n\\qquad Root locus:\n\\midpic{1.eps}{Root Locus}\n\n\\newpage\n\\subsection{(b)}\nFrom Figure 2 and Figure 3, we can get that, the root locus and the real axis has three intersections when $K=47.2$ or $K=1.92$ or $K=9.57\\times 10^{-5}$. However, when the two real poles break away from the real axis, $K=9.57\\times 10^{-5}$, and split point coordinates is $(0.998,0)$.\n\\doublepic{2.eps}{$K=47.2$}{3.eps}{$K=1.92$ and $K=9.57\\times 10^{-5}$}\n\n\\subsection{(c)}\nThe closed-loop system's characteristic equation is\n\\begin{equation}\nz^4+(K-3.7123)z^3+(10.3614K+5.1644)z^2+(9.7585K-3.195)z+0.8353K+0.7408=0\n\\end{equation}\n\\qquad From the root locus we can know that the root locus and the unit circle have only two intersections, and these two intersections are actually a complex conjugate pole pair. So we suppose the intersections of the root locus and the unit circle are$ z_1=e^{j\\omega},z_2=e^{-j\\omega} $. Substitute it into the original equation (14), we can get the solution:\n\\begin{equation}\n\\left.\n\\begin{cases}\n\\omega &=-0.000000001295873\\\\\nK &=0.956515005888313\n\\end{cases}\n\\right.\n\\end{equation}\n\\qquad Thus, the maximum $K$ for stability is $0.956515005888313$.\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Problem 4}\nUse Matlab to solve this problem.\n\\lstinputlisting[language=Matlab]{./code/p4.m}\n\\qquad We can get a bode diagram as shown in Figure 4.\n\\maxpic{4.eps}{Bode Diagram}\n\\newpage\nI find the following equivalent digital controllers:\n\nUse forward difference:\n\\begin{equation}\nC(z)=\\frac{z+9}{z+59}\n\\end{equation}\n\nUse backward difference:\n\\begin{equation}\nC(z)=\\frac{11z-1}{61z-1}\n\\end{equation}\n\nUse FOH:\n\\begin{equation}\nC(z)=\\frac{0.1806z-0.01389}{z-8.757\\times 10^{-27}}\n\\end{equation}\n\nUse tustin's approximation:\n\\begin{equation}\nC(z)=\\frac{0.1935z+0.129}{z+0.9355}\n\\end{equation}\n\nUse tustin's approximation with frequency prewarping. And I choose the critical frequency $W_c = 2.4 rad/s $:\n\\begin{equation}\nC(z)=\\frac{0.1794z+0.1488}{z+0.9694}\n\\end{equation}\n\nUse matched pole-zero method:\n\\begin{equation}\nC(z)=\\frac{0.1667z-7.567\\times 10^{-6}}{z-8.757\\times 10^{-27}}\n\\end{equation}\n\n\n\\end{document}", "meta": {"hexsha": "3f3bfdc899779f938e470ce1c3559d63490b1b0c", "size": 5359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/doc.tex", "max_stars_repo_name": "ZJU-CSC-104/LaTeX-Templates", "max_stars_repo_head_hexsha": "679365d003c0517f6b9cfba01ae04fa7255ffdea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-09-28T14:15:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-23T08:57:12.000Z", "max_issues_repo_path": "Homework/doc.tex", "max_issues_repo_name": "ZJU-Robotics-Lab/LaTeX-Templates", "max_issues_repo_head_hexsha": "679365d003c0517f6b9cfba01ae04fa7255ffdea", "max_issues_repo_licenses": ["MIT"], "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/doc.tex", "max_forks_repo_name": "ZJU-Robotics-Lab/LaTeX-Templates", "max_forks_repo_head_hexsha": "679365d003c0517f6b9cfba01ae04fa7255ffdea", "max_forks_repo_licenses": ["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.057591623, "max_line_length": 362, "alphanum_fraction": 0.6488150774, "num_tokens": 2116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.6561123992737959}}
{"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 allocating land using linear programming.}\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.\nIn this formulation, we require 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, such 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\\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 = [1.41, 2.40, 2.40, 0.79]^T$ and the minimum objective value is approximately 7.\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=[1.55, 2.36, 2.36, 0.73]^T$ and the minimum primal objective value is approximately 14.09.\n\\end{problem}\n\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\nYou can learn more about CVXOPT at\n\\url{http://cvxopt.org/index.html}.\n", "meta": {"hexsha": "d96a15b020504ac24614a5327678c74352f348e7", "size": 24979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume2/CVXOPT_Intro/CVXOPT_Intro.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/Volume2/CVXOPT_Intro/CVXOPT_Intro.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/Volume2/CVXOPT_Intro/CVXOPT_Intro.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": 35.2810734463, "max_line_length": 241, "alphanum_fraction": 0.655830898, "num_tokens": 8881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6561123960568949}}
{"text": "\n\\subsection{Sorted lists}\n\nThere can be a total ordering on elements in a list.\n\nWe want to return a list such that only the ordering is changed.\n\n\\(\\forall nm [list[n]>list[m] \\leftrightarrow n>m]\\)\n\n\n\\subsection{Checking a sortable list}\n\\subsection{Sorting algorithms}\n\nEfficient in time and memory\n\nPopular algorithms are:\n\n\\begin{itemize}\n\\item Merge sort\n\\item Quick sort\n\\item Heap sort\n\\end{itemize}\n\n\n\\subsection{Sorting linked lists}\n\n", "meta": {"hexsha": "85fb6e5612adddff646f00171ea1f91ceb41d44d", "size": 446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/sorting/01-01-sorting.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/sorting/01-01-sorting.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/sorting/01-01-sorting.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.5185185185, "max_line_length": 64, "alphanum_fraction": 0.7556053812, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961427, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.6561123931135807}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb}\n\n\\title{Proving the Converse of Pythagorean Theorem}\n\\author{Ethan Xu}\n\\date{October 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\nThe Pythagorean Theorem is defined as: if $a^2+b^2=c^2$, then $\\theta = 90^{\\circ}$. By definition, then the converse of the Pythagorean Theorem is if $\\theta = 90^{\\circ}$, then $a^2+b^2=c^2$.\n\n\\section{Proof}\nLet $\\bigtriangleup ABC$ be a triangle with sides $a$ ($AB$), $b$ ($BC$), $c$ ($AC$) such that:\n\n\\begin{equation}\n    a^2+b^2=c^2\n\\end{equation}\n\nLet $\\bigtriangleup DEF$ be a triangle with sides $a$ ($DE$), $b$ ($EF$), $d$ ($DF$). Let $\\angle DEF = 90^{\\circ}$, such that side $d$ is the hypotenuse. By the Pythagorean Theorem, we have that:\n\n\\begin{equation}\n    a^2+b^2=d^2\n\\end{equation}\n\nNow we can substitute $a^2+b^2$ in (1) for $d^2$ from (2), so we have that $c^2=d^2$. Since $c, d > 0$, $c=d$.\n\nBy SSS Congruence, we have that $\\bigtriangleup ABC \\cong \\bigtriangleup DEF$, so $\\angle ABC = \\angle DEF = 90^{\\circ}$. Hence, $\\bigtriangleup ABC$ contains a right angle. $\\hfill\\square$\n\\end{document}\n", "meta": {"hexsha": "66f62eb7993ceebf29102db3582f509971e0c82d", "size": 1139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "random-proofs/converse_pythagorean/converse_pythagorean.tex", "max_stars_repo_name": "waitblock/gists", "max_stars_repo_head_hexsha": "3dfe65a4f0f593ab4378eb3b518c98e2e882844d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-10T18:44:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T02:48:38.000Z", "max_issues_repo_path": "random-proofs/converse_pythagorean/converse_pythagorean.tex", "max_issues_repo_name": "waitblock/side-projects", "max_issues_repo_head_hexsha": "3dfe65a4f0f593ab4378eb3b518c98e2e882844d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "random-proofs/converse_pythagorean/converse_pythagorean.tex", "max_forks_repo_name": "waitblock/side-projects", "max_forks_repo_head_hexsha": "3dfe65a4f0f593ab4378eb3b518c98e2e882844d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5151515152, "max_line_length": 196, "alphanum_fraction": 0.6698858648, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.6561123892693339}}
{"text": "\\chapter{Countably Infinite Types} \\label{infinite}\nIn the previous sections we saw different flavours of finiteness which were\nreally just different flavours of relations to \\(\\mathbf{Fin}\\).\nIn this section we will see that we can construct a similar classification of\nrelations to \\(\\mathbb{N}\\), in the form of the countably infinite types.\n\\section{Two Countable Types}\nThe two types for countability we will consider are analogous to split\nenumerability and cardinal finiteness.\nThe change will be a simple one: we will swap out lists for streams.\n\\begin{definition}[Streams]\n  \\begin{equation}\n    \\mathbf{Stream}(A) \\coloneqq (\\mathbb{N} \\rightarrow A)\n    \\simeq \\llbracket \\top , \\text{const}(\\mathbb{N}) \\rrbracket\n  \\end{equation}\n\\end{definition}\n\\begin{definition}[Split Countability]\n  \\begin{equation}\n    \\aleph_0!(A) \\coloneqq \\Sigma {(\\mathit{xs} : \\mathbf{Stream}(A))} , \\Pi {(x : A)} , x \\in \\mathit{xs}\n  \\end{equation}\n\\end{definition}\nThis type is definitionally equal to it surjection equivalent (\\(\\mathbb{N}\n\\twoheadrightarrow ! \\; A\\)).\nWe construct the unordered, propositional version of the predicate in much the\nsame way as we constructed cardinal finiteness.\n\\begin{definition}[Countability]\n  \\begin{equation}\n    \\aleph_0(A) \\coloneqq \\lVert \\aleph_0!(A) \\rVert\n  \\end{equation}\n\\end{definition}\n\nFrom both of these types we can derive decidable equality.\n\\begin{lemma}\n  Any countable type has decidable equality.\n\\end{lemma}\n\\section{Closure}\n\\input{figures/pairing-functions}\nWe know that countable infinity is not closed under the exponential (function\narrow), so the only closure we need to prove is \\(\\Sigma\\) to cover all of\nwhat's left.\n\\begin{theorem} \\label{split-countability-sigma}\n  Split countability is closed under \\(\\Sigma\\).\n\\end{theorem}\nWe know that countable infinity is not closed under the exponential (function\narrow), so the only closure we need to prove is \\(\\Sigma\\) to cover all of\nwhat's left.\nTo do this we have to take a slightly different approach to the functions we\ndefined before.\nFigure~\\ref{pairings} illustrates the reason why: previously, we used the\ndepth-first product pairing for each support list.\nThis diverges if the first list is infinite, never exploring anything other than\nthe first element in the second list.\nInstead, we use here the cantor pairing function, which performs a breadth-first\nsearch of the pairings of both lists.\n\nFinally, while we have lost certain closure proofs by allowing for infinite\ntypes, we also \\emph{gain} some: in particular the Kleene star.\n\\begin{theorem}\n  Split countability is closed under Kleene star.\n  \\begin{equation}\n    \\aleph_0!(A) \\rightarrow \\aleph_0!(\\mathbf{List}(A))\n  \\end{equation}\n\\end{theorem}\nAgain, this proof requires a particular pattern to ensure productivity.\nThe pattern here builds an intermediate stream \\(\\mathcal{KV}\\) of non-empty\nlists from the input support stream \\(\\mathit{xs}\\), which is subsequently\nflattened.\n\\begin{equation}\n  \\mathcal{KV}_i \\coloneqq \\left[ \\left[ \\mathit{xs}_{j - 1} \\mid j \\in \\mathit{js} \\right] \\mid \\mathit{js} \\in \\mathbf{List}(\\mathbb{N}) ; \\text{sum}(\\mathit{js}) = i ; 0 \\notin \\mathit{js}  \\right]\n\\end{equation}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../paper\"\n%%% End:", "meta": {"hexsha": "03e66ea33a79be9a1b89cca8e1c743fa24e1d814", "size": 3269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/countable-predicates.tex", "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": ["MIT"], "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/countable-predicates.tex", "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_licenses": ["MIT"], "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/countable-predicates.tex", "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": ["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.1756756757, "max_line_length": 200, "alphanum_fraction": 0.7482410523, "num_tokens": 911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6560408539528212}}
{"text": "\\section{Rational Functions and Partial Fractions}{}{}\\label{sec:Rational Functions}\nA \\dfont{rational function} is a fraction with polynomials in the numerator and\ndenominator.  For example, \n$$\n  {x^3\\over x^2+x-6},\n  \\qquad\\qquad\n  {1\\over (x-3)^2},\n  \\qquad\\qquad\n  {x^2+1\\over x^2-1},\n$$ \nare all rational functions of $x$.  We should mention a special type of rational function that we already know how to integrate: If the denominator has the form $\\ds (ax+b)^n$,\nthe substitution $u=ax+b$ will always work.  The denominator becomes\n$\\ds u^n$, and each $x$ in the numerator is replaced by $(u-b)/a$, and\n$dx=du/a$. While it may be tedious to complete the integration if the\nnumerator has high degree, it is merely a matter of algebra.\n\n\\begin{example}{Substitution and Splitting Up a Fraction}{Substitution and Splitting Up a Fraction}\\label{Substitution and Splitting Up a Fraction}\nFind $\\ds\\int{x^3\\over(3-2x)^5}\\,dx.$ \n\\end{example}\n\n\\begin{solution}\nUsing the substitution \n$u=3-2x$ we get\n\\begin{eqnarray*}\n  \\int{x^3\\over(3-2x)^5}\\,dx\n  &=&{1\\over -2}\\int {\\left({u-3\\over-2}\\right)^3\\over u^5}\\,du\n  ={1\\over 16}\\int {u^3-9u^2+27u-27\\over u^5}\\,du\\cr\n  &=&{1\\over 16}\\int u^{-2}-9u^{-3}+27u^{-4}-27u^{-5}\\,du\\cr\n  &=&{1\\over 16}\\left({u^{-1}\\over-1}-{9u^{-2}\\over-2}+{27u^{-3}\\over-3}\n  -{27u^{-4}\\over-4}\\right)+C\\cr\n  &=&{1\\over 16}\\left({(3-2x)^{-1}\\over-1}-{9(3-2x)^{-2}\\over-2}+\n  {27(3-2x)^{-3}\\over-3}\n  -{27(3-2x)^{-4}\\over-4}\\right)+C\\cr\n  &=&-{1\\over\n    16(3-2x)}+{9\\over32(3-2x)^2}-{9\\over16(3-2x)^3}+{27\\over64(3-2x)^4}+C\n\\end{eqnarray*}\n\\vglue-10pt\n\\end{solution}\n\n\n\nOf course there are other situation in which we can apply known techniques, perhaps after some clever manipulation. The following example demonstrates one such case.\n\n\\begin{example}{Denominator Does Not Factor}{Denominator Does Not Factor}\\label{Denominator Does Not Factor} \nEvaluate $\\ds\\int {x+1\\over x^2+4x+8}\\,dx$. \n\\end{example}\n\n\\begin{solution}\nThe quadratic denominator\ndoes not factor. We could complete the square and use a trigonometric\nsubstitution, but it is simpler to rearrange the integrand:\n$$\n  \\int {x+1\\over x^2+4x+8}\\,dx = \\int {x+2\\over x^2+4x+8}\\,dx -\n  \\int {1\\over x^2+4x+8}\\,dx.\n$$\nThe first integral is an easy substitution problem, using $u=x^2+4x+8$:\n$$\n  \\int {x+2\\over x^2+4x+8}\\,dx={1\\over2}\\int {du\\over u}=\n  {1\\over2}\\ln|x^2+4x+8|.\n$$\nFor the second integral we complete the square:\n$$\n  x^2+4x+8=(x+2)^2+4=4\\left(\\left({x+2\\over2}\\right)^2+1\\right),\n$$\nmaking the integral\n$$ \n  {1\\over4}\\int {1\\over\\left({x+2\\over2}\\right)^2+1}\\,dx.\n$$\nUsing $\\ds u={x+2\\over2}$ we get\n$$\n  {1\\over4}\\int {1\\over\\left({x+2\\over2}\\right)^2+1}\\,dx=\n  {1\\over4}\\int {2\\over u^2+1}\\,dx=\n  {1\\over2}\\arctan\\left({x+2\\over2}\\right).\n$$\nThe final answer is now \n$$\n  \\int {x+1\\over x^2+4x+8}\\,dx={1\\over2}\\ln|x^2+4x+8|-\n  {1\\over2}\\arctan\\left({x+2\\over2}\\right)+C.\n$$\n\\end{solution}\n\n\nMore generally, we can not rely on a rational function having such ``nice\" forms as those above.   There is a general technique\ncalled ``partial fractions'' that, in principle, allows us to \nintegrate any rational function. \n\n\n\n\n\n\n\n% We can always factor out the coefficient of $\\ds x^2$ and put\n%it outside the integral, so we can assume that the denominator has the\n%form $\\ds x^2+bx+c$.  There are three possible cases, depending on how\n%the quadratic factors: either $\\ds x^2+bx+c=(x-r)(x-s)$,\n%$\\ds x^2+bx+c=(x-r)^2$, or it doesn't factor. We can use the quadratic\n%formula to decide which of these we have, and to factor the quadratic\n%if it is possible.\n%\n%\\begin{example}{Factoring a Quadratic}{Factoring a Quadratic}\\label{Factoring a Quadratic}\n%Determine whether $\\ds x^2+x+1$ factors, and factor it if possible.\n%\\end{example}\n%\n%\\begin{solution}\n%The quadratic formula tells us that $\\ds x^2+x+1=0$ when\n%$$x={-1\\pm\\sqrt{1-4}\\over 2}.$$\n%Since there is no square root of $-3$, this quadratic does not factor.\n%\\end{solution}\n%\n%\\begin{example}{Factoring a Quadratic with Real Roots}{Factoring a Quadratic with Real Roots}\\label{Factoring a Quadratic with Real Roots}\n%Determine whether $\\ds x^2-x-1$ factors, and factor it if possible.\n%\\end{example}\n%\n%\\begin{solution}\n%The quadratic formula tells us that $\\ds x^2-x-1=0$ when\n%$$x={1\\pm\\sqrt{1+4}\\over 2}={1\\pm\\sqrt{5}\\over2}.$$\n%Therefore\n%$$\n%  x^2-x-1=\\left(x-{1+\\sqrt{5}\\over2}\\right)\\left(x-{1-\\sqrt{5}\\over2}\\right).\n%$$\n%\\end{solution}\n%\n%If $\\ds x^2+bx+c=(x-r)^2$ then we have the special case we have already\n%seen, that can be handled with a substitution. The other two cases\n%require different approaches.\n%\n%If  $\\ds x^2+bx+c=(x-r)(x-s)$, we have an integral of the form\n%$$\\int{p(x)\\over (x-r)(x-s)}\\,dx$$\n%where $p(x)$ is a polynomial. The first step is to make sure that\n%$p(x)$ has degree less than 2.\n%\n%\\begin{example}{}{}\\label{}\n%Rewrite $$\\ds\\int {x^3\\over (x-2)(x+3)}\\,dx$$ in terms of an integral\n%with a numerator that has degree less than 2. \n%\\end{example}\n%\n%\\begin{solution}\n%To do this we use long division of polynomials to \n%discover that\n%$$\n%  {x^3\\over (x-2)(x+3)}={x^3\\over x^2+x-6}=x-1+{7x-6\\over x^2+x-6}=\n%  x-1+{7x-6\\over (x-2)(x+3)}.\n%$$\n%See \\url{http://en.wikipedia.org/wiki/Polynomial_long_division} for a review on long division.\n%Then\n%$$\n%  \\int {x^3\\over (x-2)(x+3)}\\,dx=\\int x-1\\,dx +\\int {7x-6\\over\n%  (x-2)(x+3)}\\,dx.\n%$$\n%The first integral is easy, so only the second requires some work.\n%\\end{solution}\n%\n%Now consider the following simple algebra of fractions:\n%$$\n%  {A\\over x-r}+{B\\over x-s}={A(x-s)+B(x-r)\\over (x-r)(x-s)}=\n%  {(A+B)x-As-Br\\over (x-r)(x-s)}.\n%$$\n%That is, adding two fractions with constant numerator and denominators\n%$(x-r)$ and $(x-s)$ produces a fraction with denominator $(x-r)(x-s)$\n%and a polynomial of degree less than 2 for the numerator. We want to\n%reverse this process: Starting with a single fraction, we want to\n%write it as a sum of two simpler fractions. An example should make it\n%clear how to proceed.\n\n%\\begin{example}{Partial Fraction Decomposition}{Partial Fraction Decomposition}\\label{Partial Fraction Decomposition} \n%Evaluate $\\ds\\int {x^3\\over (x-2)(x+3)}\\,dx$. \n%\\end{example}\n%\n%\\begin{solution}\n%We start by\n%writing $\\ds{7x-6\\over (x-2)(x+3)}$ as the sum of two fractions.  We\n%want to end up with\n%$${7x-6\\over (x-2)(x+3)}={A\\over x-2}+{B\\over x+3}.$$\n%If we go ahead and add the fractions on the right hand side, we seek a common denominator, and get:\n%$${7x-6\\over (x-2)(x+3)}={(A+B)x+3A-2B\\over (x-2)(x+3)}.$$\n%So all we need to do is find $A$ and $B$ so that $7x-6=(A+B)x+3A-2B$,\n%which is to say, we need $7=A+B$ and $-6=3A-2B$. This is a problem\n%you've seen before: Solve a system of two equations in two\n%unknowns. There are many ways to proceed; here's one: If $7=A+B$ then\n%$B=7-A$ and so $-6=3A-2B=3A-2(7-A)=3A-14+2A=5A-14$. This is easy to\n%solve for $A$: $\\ds A= 8/5$, and then $B=7-A=7-8/5=27/5$. Thus\n%$$\n%  \\int {7x-6\\over (x-2)(x+3)}\\,dx=\n%  \\int {8\\over5}{1\\over x-2}+{27\\over5}{1\\over x+3}\\,dx=\n%  {8\\over5}\\ln |x-2|+{27\\over5}\\ln|x+3|+C.\n%$$\n%The answer to the original problem is now\n%\\begin{eqnarray*}\n%  \\int {x^3\\over (x-2)(x+3)}\\,dx\n%  &=&\\int x-1\\,dx +\\int {7x-6\\over (x-2)(x+3)}\\,dx\\cr\n%  &=&{x^2\\over 2}-x+{8\\over5}\\ln |x-2|+{27\\over5}\\ln|x+3|+C.\\cr\n%\\end{eqnarray*}\n%\\vskip-10pt\n%\\end{solution}\n%\n%Now suppose that $\\ds x^2+bx+c$ doesn't factor. Again we can use long\n%division to ensure that the numerator has degree less than 2, then we\n%complete the square.\n\n\n\n\\subsection{Partial Fraction Decomposition}\\label{sec:partial_fraction}\n\n\nConsider the integral $\\ds\\int \\frac{1}{x^2-1}\\ dx$. We do not have a simple formula for this (if the denominator were $x^2+1$, we would recognize the antiderivative as being the arctangent function). It can be solved using Trigonometric Substitution, but note how the integral is easy to evaluate once we realize:\n\n%This integral is not difficult to evaluate once one realizes the following fact: \n$$\\frac{1}{x^2-1} = \\frac{1/2}{x-1} - \\frac{1/2}{x+1}.$$\nThus \n\\begin{align*}\n\\int\\frac{1}{x^2-1}\\ dx &= \\int\\frac{1/2}{x-1}\\ dx - \\int\\frac{1/2}{x+1}\\ dx \\\\\n\t\t\t&= \\frac12\\ln|x-1| - \\frac12\\ln|x+1| + C.\n\\end{align*}\n\nThis section teaches how to \\textit{decompose} $$\\frac{1}{x^2-1}\\quad  \\text{into}\\quad  \\frac{1/2}{x-1}-\\frac{1/2}{x+1}.$$\n\nWe start with a rational function $f(x)=\\frac{p(x)}{q(x)}$, where $p$ and $q$ do not have any common factors and the degree of $p$ is less than the degree of $q$. It can be shown that any polynomial, and hence $q$, can be factored into a product of linear and irreducible quadratic terms. The following Key Idea states how to decompose a rational function into a sum of rational functions whose denominators are all of lower degree than $q$.\n\nIf we start with a rational function $f(x)=\\frac{p(x)}{q(x)}$, we can assume that perhaps after long division the the fraction is reduced, and is \"proper\", in that $p$ and $q$ do not have any common factors and the degree of $p$ is less than the degree of $q$. Any polynomial, and hence $q$, can be factored into a product of linear and irreducible quadratic terms. The following outlines how to decompose a rational function into a sum of rational functions whose denominators are all of lower degree than $q$.\n%\\clearpage\n\n\n\\begin{formulabox}[Partial Fraction Decomposition] \\label{idea:partial_fraction}\n{Let $\\ds \\frac{p(x)}{q(x)}$ be a rational function, where the degree of $p$ is less than the degree of $q$.\\index{integration!partial fraction decomp.}\n\\begin{enumerate}\n\t\\item\t\\textbf{Linear Terms:} Let $(x-a)$ divide $q(x)$, where $(x-a)^n$ is the highest power of $(x-a)$ that divides $q(x)$. Then the decomposition of $\\frac{p(x)}{q(x)}$ will contain the sum\n\t$$\\frac{A_1}{(x-a)} + \\frac{A_2}{(x-a)^2} + \\cdots +\\frac{A_n}{(x-a)^n}.$$\n\t\\item\t\t\\textbf{Quadratic Terms:} Let $x^2+bx+c$ divide $q(x)$, where $(x^2+bx+c)^n$ is the highest power of $x^2+bx+c$ that divides $q(x)$. Then the decomposition of $\\frac{p(x)}{q(x)}$ will contain the sum \n\t$$\\frac{B_1x+C_1}{x^2+bx+c}+\\frac{B_2x+C_2}{(x^2+bx+c)^2}+\\cdots+\\frac{B_nx+C_n}{(x^2+bx+c)^n}.$$\n\t\\end{enumerate}\n\tTo find the coefficients $A_i$, $B_i$ and $C_i$:\n\t\\begin{enumerate}\n\t\\item\tMultiply all fractions by $q(x)$, clearing the denominators. Collect like terms.\n\t\\item\t\tEquate the resulting coefficients of the powers of $x$ and solve the resulting system of linear equations.\n\t\\end{enumerate}\n}\n\\end{formulabox}\n\nTo find the coefficients $A_i$, $B_i$ and $C_i$, it is helpful to have a process:\n\n\\begin{formulabox}[Partial Fractions: Solving for Coefficients] \\label{idea:partial_fraction2}\nLet $\\ds \\frac{p(x)}{q(x)}$ be a rational function, set up an equation with $\\ds \\frac{p(x)}{q(x)}$ set equal to it's partial fraction form.\n\\begin{enumerate}\n\t\\item\tMultiply by the denominator $ q(x) $ to clear all fractions and obtain the \t``\\textbf{Basic Equation}\".\n\t\n\t\\item\tSolve the Basic Equation for the unknowns using the following guidelines:\n\t\n\t\\begin{enumerate}\n\t\\item Expand the Basic Equation, collect terms according to powers of $ x $ and equate coefficients of like powers of $ x $. This will give a system of linear equations to be solved.\n\t\\item\tAlternatively, for distinct linear factors, you may substitute the roots of the distinct linear factors\n\tto determine the constants.\n\t\\item Another alternative: For repeated linear factors, you may also first substitute the roots of the linear factors, then rewrite the Basic Equation and use other “convenient\" choices for $ x $ to solve for the remaining\n\tcoefficients (or use the method of equating coefficients).\n\t\\end{enumerate}\n\\end{enumerate}\t\n\\end{formulabox}\n\n\n\nThe following examples will demonstrate how to put this into practice. Example \\ref{exa:ex_pf1} stresses the decomposition aspect of the Key Idea.\\\\\n\n\\begin{example}{Decomposing into partial fractions}{ex_pf1}\n{\nDecompose $\\ds f(x)=\\frac{1}{(x+5)(x-2)^3(x^2+x+2)(x^2+x+7)^2}$ without solving for the resulting coefficients.}\n\\end{example}\n\n\n\\begin{solution}\n{The denominator is already factored, as both $x^2+x+2$ and $x^2+x+7$ cannot be factored further. We need to decompose $f(x)$ properly. Since $(x+5)$ is a linear term that divides the denominator, there will be a $$\\frac{A}{x+5}$$ term in the decomposition.\n\nAs $(x-2)^3$ divides the denominator, we will have the following terms in the decomposition:\n$$\\frac{B}{x-2},\\quad \\frac{C}{(x-2)^2}\\quad \\text{and}\\quad \\frac{D}{(x-2)^3}.$$\n\nThe $x^2+x+2$ term in the denominator results in a $\\ds\\frac{Ex+F}{x^2+x+2}$ term.\n\nFinally, the $(x^2+x+7)^2$ term results in the terms $$\\frac{Gx+H}{x^2+x+7}\\quad \\text{and}\\quad \\frac{Ix+J}{(x^2+x+7)^2}.$$\nAll together, we have \n\\begin{align*}\n\\frac{1}{(x+5)(x-2)^3(x^2+x+2)(x^2+x+7)^2} &= \\frac{A}{x+5} + \\frac{B}{x-2}+ \\frac{C}{(x-2)^2}+\\frac{D}{(x-2)^3}+ \\\\\n\t\t& \\frac{Ex+F}{x^2+x+2}+\\frac{Gx+H}{x^2+x+7}+\\frac{Ix+J}{(x^2+x+7)^2}\n\\end{align*}\nSolving for the coefficients $A$, $B \\ldots J$ would be a bit tedious but not ``hard.''\n}\n\\end{solution}\n\n\n\n\n\n\n\n\n\\begin{example}{Decomposing into partial fractions}{ex_pf2}\n{\nPerform the partial fraction decomposition of $\\ds \\frac{1}{x^2-1}$.\n}\n\\end{example}\n\n\\begin{solution}\n{The denominator factors into two linear terms: $x^2-1 = (x-1)(x+1)$. Thus \n$$\\frac{1}{x^2-1} = \\frac{A}{x-1} + \\frac{B}{x+1}.$$\nTo solve for $A$ and $B$, first multiply through by $x^2-1 = (x-1)(x+1)$ to obtain the Basic Equation:\n\\begin{align} \n1 &= \\frac{A(x-1)(x+1)}{x-1}+\\frac{B(x-1)(x+1)}{x+1} \\\\\n\t&= A(x+1) + B(x-1)  \\label{basic2} \\\\\n\t&= Ax+A + Bx-B \\\\\n\t\\intertext{Now collect like terms.}\n\t&= (A+B)x + (A-B).\n\\end{align}\nThe next step is key. Note the equality we have:\n$$1 = (A+B)x+(A-B).$$\nFor clarity's sake, rewrite the left hand side as\n$$0x+1 = (A+B)x+(A-B).$$\nOn the left, the coefficient of the $x$ term is $ 0 $; on the right, it is $(A+B)$. Since both sides are equal, we must have that $0=A+B$. \n\nLikewise, on the left, we have a constant term of $ 1 $; on the right, the constant term is $(A-B)$. Therefore we have $1=A-B$.\n\nWe have two linear equations with two unknowns. This one is easy to solve by hand, leading to \n$$\\begin{array}{c} A+B = 0 \\\\ A-B = 1 \\end{array} \\Rightarrow \\begin{array}{c} A=1/2 \\\\ B = -1/2\\end{array}.$$\n\nNote, that alternatively, we could have substituted the two roots ($ usedx=\\pm 1 $) into the basic equation \\ref{basic2} to solve for the coefficients. $ x=1 $ gives $ 1= 2A$, and $ x=-1 $ gives $ 1=-2B $. \n\nThus we arrive at the partial fraction decomposition $$\\frac{1}{x^2-1} = \\frac{1/2}{x-1}-\\frac{1/2}{x+1}.$$\n}\n\\end{solution}\n\n\n\n\n\n\n\n\n\n\\begin{example}{Integrating using partial fractions}{ex_pf3}\nUse partial fraction decomposition to integrate $\\ds\\int\\frac{1}{(x-1)(x+2)^2}\\ dx.$\n\\end{example}\n\n\\begin{solution}\nWe decompose the integrand as follows, as described in the process \\ref{idea:partial_fraction}:\n$$\\frac{1}{(x-1)(x+2)^2} = \\frac{A}{x-1} + \\frac{B}{x+2} + \\frac{C}{(x+2)^2}.$$\nTo solve for $A$, $B$ and $C$, we multiply both sides by $(x-1)(x+2)^2$ to obtain the Basic Equation and collect like terms:\n\\begin{align}\n1 &= A(x+2)^2 + B(x-1)(x+2) + C(x-1)\\label{eq:pf3}\\\\\n\t&= Ax^2+4Ax+4A + Bx^2 + Bx-2B + Cx-C \\notag \\\\\n\t&= (A+B)x^2 + (4A+B+C)x + (4A-2B-C)\\notag\n\\end{align}\n\n\nWe have $$0x^2+0x+ 1 = (A+B)x^2 + (4A+B+C)x + (4A-2B-C)$$\nleading to the equations \n$$A+B = 0, \\quad 4A+B+C = 0 \\quad \\text{and} \\quad 4A-2B-C = 1.$$\nThese three equations of three unknowns lead to a unique solution:\n$$A = 1/9,\\quad B = -1/9 \\quad \\text{and} \\quad C = -1/3.$$\n\nThus \n$$\\int\\frac{1}{(x-1)(x+2)^2}\\ dx = \\int \\frac{1/9}{x-1}\\ dx + \\int \\frac{-1/9}{x+2}\\ dx + \\int \\frac{-1/3}{(x+2)^2}\\ dx.$$\n\nEach can be integrated with a simple substitution with $u=x-1$ or $u=x+2$  as the denominators are linear functions). The end result is\n$$\\int\\frac{1}{(x-1)(x+2)^2}\\ dx = \\frac19\\ln|x-1| -\\frac19\\ln|x+2| +\\frac1{3(x+2)}+C.$$\n\n{\\textbf{Note:} The Basic Equation \\ref{eq:pf3} offers a direct route to finding the values of $A$, $B$ and $C$. When $x=1$, the right hand side simplifies to $A(1+2)^2 = 9A$. Since the left hand side is still $ 1 $, we have $1 = 9A$. Hence $A = 1/9$.  Likewise, when $x=-2$we obtain $1=-3C$, so $C = -1/3$. Knowing $A$ and $C$, we can find the value of $B$ by choosing yet another value of $x$, such as $x=0$, and solving for $B$, or by equating coefficients.}\n\n\n\\end{solution}\n\n\n\n\n\n\n\n\\begin{example}{Integrating using partial fractions}{ex_pf4}\n{\nUse partial fraction decomposition to integrate $\\ds \\int \\frac{x^3}{(x-5)(x+3)}\\ dx$.\n}\n\\end{example}\n\n\\begin{solution}\n{Our method presumes that the degree of the numerator is less than the degree of the denominator. Since this is not the case here, we begin by using polynomial division to reduce the degree of the numerator. We omit the steps, but encourage the reader to verify that $$\\frac{x^3}{(x-5)(x+3)} = x+2+\\frac{19x+30}{(x-5)(x+3)}.$$\nWe can rewrite the new rational function in partial fraction form:\n$$\\frac{19x+30}{(x-5)(x+3)} = \\frac{A}{x-5} + \\frac{B}{x+3}$$ for appropriate values of $A$ and $B$. Clearing denominators, we have the basic equation: \n\\begin{equation*}\n19x+30 = A(x+3) + B(x-5)\n\\end{equation*}\nSetting $ x=-3 $ gives $ -27=-8B $, so $ B=27/8 $.\\\\\nSetting $ x=5 $ gives $ 125=8A $, so $ A=125/8 $.\n\nWe can now integrate.\n\\begin{align*}\n\\int \\frac{x^3}{(x-5)(x+3)}\\ dx &= \\int\\left(x+2+\\frac{125/8}{x-5}+\\frac{27/8}{x+3}\\right)\\ dx \\\\\n\t\t\t\t\t&= \\frac{x^2}2 + 2x + \\frac{125}{8}\\ln|x-5| + \\frac{27}8\\ln|x+3| + C.\n\\end{align*}\n\nNote: Alternatively, we could have used the method of equating coefficients to solve for $ A $ and $ B $.\n\\begin{align*}\n19x+30 &= A(x+3) + B(x-5)\\\\\n\t\t\t&= (A+B)x + (3A-5B).\n\\intertext{This implies that:}\n19&= A+B \\\\\n30&= 3A-5B.\\\\\n\\intertext{Solving this system of linear equations gives}\n125/8 &=A\\\\\n27/8 &=B.\n\\end{align*}\n}\n\\end{solution}\n\n\n\n%\\clearpage\n\n\n\\begin{example}{Integrating using partial fractions}{ex_pf5}\n{\nUse partial fraction decomposition to evaluate $\\ds \\int\\frac{7x^2+31x+54}{(x+1)(x^2+6x+11)}\\ dx.$\n}\n\\end{example}\n\n\\begin{solution}\n{The degree of the numerator is less than the degree of the denominator so we begin by setting up the partial fraction form. We have:\n\\begin{align*}\n\\frac{7x^2+31x+54}{(x+1)(x^2+6x+11)} &= \\frac{A}{x+1} + \\frac{Bx+C}{x^2+6x+11}. \\\\\n\\intertext{Now clear the denominators to get the Basic Equation.}\n7x^2+31x+54 &= A(x^2+6x+11) + (Bx+C)(x+1)\\\\\n\\intertext{Now collect terms to equate coefficients.}\n\t\t\t\t\t&= (A+B)x^2 + (6A+B+C)x + (11A+C).\\\\\n\\intertext{This implies that:}\n\t\t\t\t7&=A+B\\\\\n\t\t\t\t31 &= 6A+B+C\\\\\n\t\t\t\t54 &= 11A+C.\n\\end{align*}\nSolving this system of linear equations gives the nice result of $A=5$, $B = 2$ and $C=-1$. Thus\n$$\\int\\frac{7x^2+31x+54}{(x+1)(x^2+6x+11)}\\ dx = \\int\\left(\\frac{5}{x+1} + \\frac{2x-1}{x^2+6x+11}\\right)\\ dx.$$\n\nThe first term of this new integrand is easy to evaluate; it leads to a $5\\ln|x+1|$ term. The second term is not hard, but takes several steps and uses substitution techniques.\n\nThe integrand $\\ds \\frac{2x-1}{x^2+6x+11}$ has a quadratic in the denominator and a linear term in the numerator. This leads us to try substitution. Let $u = x^2+6x+11$, so $du = (2x+6)\\ dx$. The numerator is $2x-1$, not $2x+6$, but we can get a $2x+6$ term in the numerator by adding $ 0 $ in the form of ``$7-7$.''\n\\begin{align*}\n\\frac{2x-1}{x^2+6x+11} &= \\frac{2x-1+7-7}{x^2+6x+11} \\\\\n\t\t\t\t\t&= \\frac{2x+6}{x^2+6x+11} - \\frac{7}{x^2+6x+11}.\n\\end{align*}\nWe can now integrate the first term with substitution, leading to a $\\ln|x^2+6x+11|$ term. The final term can be integrated using arctangent. First, complete the square in the denominator:\n$$\\frac{7}{x^2+6x+11} = \\frac{7}{(x+3)^2+2}.$$\nAn antiderivative of the latter term can be found using Theorem \\ref{thm:int_inverse_trig} and substitution:\n$$\\int \\frac{7}{x^2+6x+11}\\ dx = \\frac{7}{\\sqrt{2}}\\tan^{-1}\\left(\\frac{x+3}{\\sqrt{2}}\\right)+C.$$\n\nLet's start at the beginning and put all of the steps together.\n\\small\\begin{align*}\n\\int\\frac{7x^2+31x+54}{(x+1)(x^2+6x+11)}\\ dx &= \\int\\left(\\frac{5}{x+1} + \\frac{2x-1}{x^2+6x+11}\\right)\\ dx \\\\\n\t\t\t&= \\int\\frac{5}{x+1}\\ dx  + \\int\\frac{2x+6}{x^2+6x+11}\\ dx -\\int\\frac{7}{x^2+6x+11}\\ dx \\\\\n\t\t\t&= 5\\ln|x+1|+ \\ln|x^2+6x+11| -\\frac{7}{\\sqrt{2}}\\tan^{-1}\\left(\\frac{x+3}{\\sqrt{2}}\\right)+C.\n\\end{align*}\\normalsize\nAs with many other problems in calculus, it is important to remember that one is not expected to ``see'' the final answer immediately after seeing the problem. Rather, given the initial problem, we break it down into smaller problems that are easier to solve. The final answer is a combination of the answers of the smaller problems.\n}\\\\\n\\end{solution}\n\n\n\nPartial Fraction Decomposition is an important tool when dealing with rational functions. Note that at its heart, it is a technique of algebra, not calculus, as we are rewriting a fraction in a new form. Regardless, it is very useful in the realm of calculus as it lets us evaluate a certain set of ``complicated'' integrals.\n\n%The next section introduces new functions, called the Hyperbolic Functions. They will allow us to make substitutions similar to those found when studying Trigonometric Substitution, allowing us to approach even more integration problems. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Rational Functions}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {1\\over 4-x^2}\\,dx$\n\\begin{sol}\n $-\\ln|x-2|/4+\\ln|x+2|/4+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {x^4\\over 4-x^2}\\,dx$\n\\begin{sol}\n $\\ds -x^3/3-4x-4\\ln|x-2|+$\\hfill\\break$4\\ln|x+2| +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {1\\over x^2+10x+25}\\,dx$\n\\begin{sol}\n $-1/(x+5) +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {x^2\\over 4-x^2}\\,dx$\n\\begin{sol}\n $-x-\\ln|x-2|+\\ln|x+2| +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {x^4\\over 4+x^2}\\,dx$\n\\begin{sol}\n $\\ds -4x+x^3/3+8\\arctan(x/2) +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {1\\over x^2+10x+29}\\,dx$\n\\begin{sol}\n $(1/2)\\arctan(x/2+5/2) +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {x^3\\over 4+x^2}\\,dx$\n\\begin{sol}\n $\\ds x^2/2-2\\ln(4+x^2) +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {1\\over x^2+10x+21}\\,dx$\n\\begin{sol}\n $(1/4)\\ln|x+3|-(1/4)\\ln|x+7| +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {1\\over 2x^2-x-3}\\,dx$\n\\begin{sol}\n $(1/5)\\ln|2x-3|-(1/5)\\ln|1+x| +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int {1\\over x^2+3x}\\,dx$\n\\begin{sol}\n $(1/3)\\ln|x|-(1/3)\\ln|x+3| +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "7c4b0b50535bb51e3a961c33b86b6c1dc4d37836", "size": 22606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-5-rational-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": "7-techniques-of-integration/7-5-rational-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": "7-techniques-of-integration/7-5-rational-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": 40.2959001783, "max_line_length": 511, "alphanum_fraction": 0.6545165, "num_tokens": 8407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.65604084909571}}
{"text": "\\section{Linear Equations}\n\n\\subsection{Elementary Operations}\n\n\\begin{definition}\n\tLet $A$ be an $m\\times n$ matrix. there are three \\cindex{elementary row operation}:\n\t\\begin{enumerate}\n\t\t\\item interchange any two row of $A$.\n\t\t\\item multiply any row of $A$ by nonzero scalar.\n\t\t\\item add any scalar multiple of a row of $A$ to another row.\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\n\tAn $n\\times n$ \\cindex{elementary matrix} is a matrix obtained by performing \\emph{one} elementary operation on $I_n$.\n\\end{definition}\n\n\\begin{definition}\n\tThe \\cindex{rank} of $A_{m \\times n}$, denoted $\\text{rank}(A)$, is the rank\\footnote{The rank of a linear transformation is defined in Definition (\\ref{rankdefinition}) on page \\pageref{rankdefinition}.} of linear transformation $L_A: F^n \\rightarrow F^m$.\n\\end{definition}\n\n\\begin{theorem}\n\tthe rank of a matrix equals the maximum number of linearly independent columns.\n\\end{theorem}\n\\begin{proof}\n\tFor any $A \\in M_{m\\times n}(F)$, \n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\t\\text{rank}(A) &= \\rank{L_A} = \\dimension{R(L_A)} = \\vectorspan{L_A(\\beta)} \\\\\n\t\t\t&= \\vectorspan{\\set{ L_A(e_1), L_A(e_2), \\dots, L_A(e_n) }}\n\t\t\\end{aligned}\n\t\\end{equation*}\n\twe have $L_A(e_j) = A e_j = a_j$ where $a_j$ is the $j$th column of A. Hence\n\t\\begin{equation*}\n\t\tR(L_A) = \\vectorspan{\\set{ a_1, a_2, \\dots, a_n}}\n\t\\end{equation*}\n\\end{proof}\n\n\\begin{theorem}\n    Let $A_{m \\times n}$ has rank $r$. Then there exist invertible matrix $B_{m \\times m}$ and $C_{n \\times n}$ that $D=BAC$, where:\n    \\begin{equation*}\n        D = \\begin{bmatrix}\n\t\t\tI_r & 0 \\\\\n\t\t\t0 & 0 \\\\\n\t\t\\end{bmatrix}\n    \\end{equation*}\n\\end{theorem}\n\n\n\\begin{theorem}\n    Every invertible matrix is a product of elementary matrices.\n\\end{theorem}\n\n\\begin{definition}\n\tFor system $Ax=b$, the matrix $(A|b)$ is the \\cindex{augmented matrix}.\n\\end{definition}\n\n\n\\begin{theorem}\n    If A is an invertible matrix, it is possible to transform augmented matrix $(A|I_n)$ into matrix $(I_n|A^{-1})$ by means of a finite number of elementary row operations.\n\\end{theorem}\n\n\\subsection{System of Equations}\n\n\\begin{definition}\n\tA system $A_{m \\times n} x=b$ of $m$ linear equation in $n$ unknowns is \\cindex{homogeneous} if $b=0$. Otherwise the system is \\cindex{nonhomogeneous}.\n\\end{definition}\n\n\\begin{definition}\n\tA system is \\cindex{consistent} if its solution set is not empty. otherwise it is called \\cindex{inconsistent}.\n\\end{definition}\n\n\\begin{theorem}\n\tLet $K$ be the set of all solutions for $Ax=0$. Then $K=\\nullspace{L_A}$ has dimension of $n- \\rank{L_A}=n-\\rank{A}$.\n\\end{theorem}\n\n\\begin{theorem}\n\tif $m < n$, the system $Ax=0$ has nonzero solution.\n\\end{theorem}\n\\begin{proof}\n    $\\rank{A} \\leq m < n$, so $\\nullspace{A} = n - \\rank{A} > 0$.\n\\end{proof}\n\n\\begin{theorem}\\label{equationfromoneandnullspace}\n\tLet $K$ be the solution set of $Ax=b$, $K_H$ be the solution set of $Ax=0$. Then for all solution $s$ to $Ax=b$,\n\t\\begin{equation}\n\t\tK = \\set{s} + K_H = \\set{s+k: k \\in K_H }\n\t\\end{equation}\n\\end{theorem}\n\n\n\\begin{theorem}\n\tLet $A_{n \\times n}x=b$ be a system of equations. If $A$ is invertible, the solution is $A^{-1}b$. Conversely, if the system has exactly one solution, $A$ is invertible.\n\\end{theorem}\n\n\n\n\\begin{theorem}\n\tLet $Ax=b$ be a system of linear equations. the system is consistent $\\Leftrightarrow$ $\\text{rank}(A) = \\text{rank}(A|b)$.\n\\end{theorem}\n\n\\begin{proof}\n    $R(L_A) = \\vectorspan{\\set{a_1, a_2, \\dots, a_n }}$. Since $b \\in R(L_A)$, the extended span is the same.\n\\end{proof}\n\n\n\\begin{definition}\n\tA matrix is in \\cindex{reduced row echelon form} if:\n\t\\begin{enumerate}\n\t\t\\item any row containing a nonzero entry precedes any row in which all the entries are zero.\n\t\t\\item the first nonzero entry in each row is the only nonzero entry in its column.\n\t\t\\item the first nonzero entry in each row is $1$ and it occurs in a column to the right of the first nonzero entry in the preceding row.\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}\\label{rankoftwomatrix}\n    For $A_{m \\times n}$ and $B_{n \\times p}$, we have:\n    \\begin{equation}\n        \\rank{AB} = \\rank{B} - \\dimension{\\nullspace{A} \\cap \\rangespace{B}}\n    \\end{equation}\n\\end{theorem}\n\\begin{proof}\n    Let $\\beta_i$ be the basis of $\\nullspace{A} \\cap \\rangespace{B}$, expand to the basis $\\beta \\cup \\alpha$ of $B$. Prove $\\alpha$ is a basis of $\\rangespace{AB}$.\n\\end{proof}\n\n\\begin{theorem}\\label{rankofadjoint}\n    For $A_{m \\times n}$, we have\n    \\begin{enumerate}\n        \\item $\\rank{A^\\top A} = \\rank{A} = \\rank{A A^\\top}$.\n        \\item $\\rangespace{A^\\top A} = \\rangespace{A^\\top}$.\n        \\item $\\nullspace{A^\\top A} = \\nullspace{A}$.\n    \\end{enumerate}\n    $A^\\top$ could be replaced by $A^*$ in $C$.\n\\end{theorem}\n\\begin{proof}\n    If $\\exists x \\neq 0 \\left(x \\in \\nullspace{A^\\top} \\cap \\rangespace{A} \\right)$. Then $(A^\\top x = 0) \\wedge \\left(\\exists y(x = A y) \\right)$. So $x^\\top x = y^\\top A^\\top x = y^\\top ( A^\\top x) = 0 $ and then $x =0$. According to \\thmref{rankoftwomatrix}, $\\rank{A^\\top A} = \\rank{A^\\top} - \\dimension{\\nullspace{A^\\top} \\cap \\rangespace{A}} = \\rank{A}$.\n\\end{proof}\n\n\\begin{theorem}\n    For a system of linear equation $Ax = b$, the associated system of \\cindex{normal equations} is defined as $n \\times n$ system\n    \\begin{equation}\n        A^\\top A x = A^\\top b\n    \\end{equation}\n    \n    $A^\\top A x = A^\\top b$ is always consistent and has unique solution when $\\rank{A} = n$. If $Ax=b$ is consistent, two solutions are the same. \\qed\n\\end{theorem}\n\n\n\n", "meta": {"hexsha": "09e6aaa9a8792bd8103d69f507c3dc301049e114", "size": 5530, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra/la.3.linear_equation.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/linear_algebra/la.3.linear_equation.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linear_algebra/la.3.linear_equation.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.8666666667, "max_line_length": 361, "alphanum_fraction": 0.6683544304, "num_tokens": 1860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.65604083199858}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\title{Statistical Machine Learning \\\\ Reading Assignment 1 Report}\n\n\\author{Alireza Sadeghi - Mohsen Shojaee}\n\\newtheorem{theorem}{Theorem}\n\\begin{document}\n\n\\maketitle\n    \n\\section{A Taste of Real Analysis}\nReal Analysis is the field of mathematics on which probability theory is founded, it is therefore convinient to first introduce some basic concepts from real analysis. We begin the this chapter with the definiation of metric space and use the notion of metric to define two core concepts: convergence and continuity. In  \\ref{topology1} we revie the natural topoly defined on a metric space based on the metric function and then in \\ref{topology2} we provide a more general view of topological spaces. \n\\subsection{Metric Space}\nA metric space is a set $M$ together with a metric $d: M \\times M \\to \\mathcal{R}$ satisfying following four properties\n\\begin{itemize}\n\\item d is non-negative\n\\item $d(x,y)=0$ iff $x=y$\n\\item Symmetry: $d(x,y) = d(y,x)$\n\\item Triangle Inequality: $d(x,z) \\leq d(x,y) + d(y,z) $\n\\end{itemize}\n\nStrictly speaking, the pair $(M,d)$ is the metric space as different metric functions can be defined on same $M$, consider for example $\\mathcal{R}^n$; a well-known class of metrics defined on $\\mathcal{R}^n$ is \\textbf{Minkowski Norm}:\n\\[\nd_p(x,y) = \\big ( \\sum_{i=1}^n (x_i - y_i)^p \\big )^{1/p}\n\\]\nwhich for all values of $p \\geq 1$ is a valid metric function.\n\n\\subsubsection{Convergence \\& Continuity}\nThere are different ways for defining convergence, we follow \\cite{pough} and use sequence/subsequence approach. A sequence $(p_n)$ is a list of points $p_1, p_2, \\ldots$ in $M$. Formaly, a sequence is a function $f: \\mathbb{N} \\to M $ in which $f(n) = p_n$. The sequence $(p_n)$ {\\bf converges to the limit} $p$ in $M$ (and denote this by $(p_n) \\to p$ if:\n\\begin{align*}\n& \\forall \\epsilon > 0 \\quad \\exists N \\in \\mathbb{N} \\quad \\text{such that} \\\\\n& n \\geq N \\Rightarrow d(p_n, p) < \\epsilon\n\\end{align*}\nHaving defined convergence, contiuity can be described: For a function $f: M \\to N$ between two metric spaces $(M, d_M)$ and $(N, d_N)$, we say that function is continous if it preserves sequential convergence, that is if $(p_n) \\to p$ then $(f(p_n)) \\to f(p)$.\n\nThe sequence definitation of continiutity stated above is equivalent with the more familiar definiation using $(\\epsilon, \\delta)$ condition: \n\\begin{theorem}\n$f:M \\to N$ is continouts if and only if for each $\\epsilon >0$ and $ p \\in M$ there exisits $\\delta > 0$ such $\\forall x \\in M : \\quad d_M(x,p) < \\delta \\Rightarrow d_N(f(x), f(p)) < \\epsilon$\n\\end{theorem}\n\\subsubsection{Topology of Metric Space} \\label{topology1}\nAlthogh topology can be defined on non-metric spaces (as we will do so in the next section) there is a \\textit{natural} topology induced on metric spaces induced by the distance function. To this end we need to define notion of {\\bf openness} and {\\bf closeness} based metric and convergences. We say that point $p \\in M$ is a limit of $S \\subset M$ if there exists a  sequence in $S$ like $(p_n)$ that $(p_n) \\to p$\n\n{\\bf Closeness:} $S$ is a closed set if it contains all it limits. \n{\\bf Openness:} $S$ is an open set if for each $p \\in S$, $r>0$ exists such that \n\\[\nd(p,q) <r \\Rightarrow q \\in S.\n\\]\nthat is for each point in $S$ an small ball around it is also in $S$.\n\nOne can simply prove that complement of an open set is closed and vice versa. However (like doors) sets can be neighter open nor closed and unlike doors they can be both at the same time. \n\n\\begin{theorem}\\label{topdef}\n\tNow the collection $\\mathcal{T}$ of all open sets of $M$ is the topolgy of $M$, i.e. is satisfies the following three properties:\n\t\\begin{itemize}\n\t\\item $M, \\Phi \\in \\mathcal{T}$ \n\t\\item The intersection of finitely many open sets is an open set\t\n\t\\item The union of arbitrarily many open sets is an open set. \n\\end{itemize}\n\\end{theorem}\n\n\\subsection{Topology: a More General Perspective} \\label{topology2}\nThe three properties stated in \\ref{topdef} are the definiation of topology, one can {\\it handcraft} a collection $\\mathcal{T}$  that satisfies these properties and call it the collection of open sets of $M$, even if they does not satisfy the definiation of openness based on metric or even $M$ is not a metric space at all. \n\n\\section{Theory of Probability}\n\n\\subsection{Introduction}\nIn many cases where statistics and statistical inference is an essential component of situation analysis, one encounters many discrete and continuous random variables and vectors and matrices. These are all special cases of a more general type of random quantity. The generalization of these notions to random quantities is through a notion of \\textit{measure}.\n\n\\subsection{Measure Theory}\nMeasure, to be defined shortly is a way of assigning numerical values to the sizes of sets. Since it's used to give sizes to sets, it's domain is a collection of sets.\n\nIn order to define this \"collection of sets\" notion more thoroughly, we call a collection of sets that is closed under taking complements and finite unions, a \\textbf{\\textit{field}}.\n\nA field, that is closed under taking countable unions is called a \\textbf{\\textit{$\\sigma$-field}}.\n\nA $\\sigma$-field that is generated by the collection C of open subsets of a topological space is called a \\textbf{\\textit{Borel $\\sigma$-field}}\n\\subsection{Measurable Functions}\n\nSuppose \\textit{S} is a set with a $\\sigma$-field \\textit{A} of subsets, and let \\textit{T} be another set with a $\\sigma$-field \\textit{C} of subsets. Now consider a function $f : S \\rightarrow T$. We say \\textit{f} is \\textit{measurable} if for every B $\\in$ C, $f^{-1} \\in A$.\n\nIf \\textit{f} is measurable, one-to-one and onto, and $f^-1$ is also measurable, we say that \\textit{f} is \\textit{bimeasurable}, and also in another case, if the two sets \\textit{S, T} are topological spaces with Borel $\\sigma$-fields, a measurable function is \\textit{Borel measurable}.\n\n\n\\subsection{Mathematical Probability}\n\nIf we'd want to define probability with a measure theoretic approach, we'd say that a measure space \\textit{(S, A, $\\mu$)} is a probability space and $\\mu$ is a probability if $\\mu(S) = 1$. We call each element of \\textit{A} an \\textit{event}, and a measurable function \\textit{X} from \\textit{S} to some other space \\textit{X, B} is called a random quantity.\n\nWhen \\textit{X} is $\\Re$ with the \\textit{Borel $\\sigma$-field}, this random quantity is called a \\textit{Random Variable}. The probability measure $\\mu_x$ induced on \\textit{(X, B}} by X from $\\my$ is called the \\textit{distribution} of X. The expected value or mean \n\n\\section{Stochastic Processes}\n\n\\subsection{Definition}\n\nA stochastic process {X_t}_$t \\in T$ is a collection of random variables X_t, taking values in a common measure space (S, X), indexed by a set T.\n\nThis definition means that for each $t \\in T$, $X_t(\\omega)$ is an S \\rightarrow X-measurable function from $\\Omega$ to S, which yields a probability on S.\n\nSome examples of stochastic processes are as follows:\n\n\\begin{itemize}\n    \\item Every random variable is a trivial stochastic process.\n    \\item Let $T = {1, 2, \\cdots, k}$ and $S = \\Re$. Then {X_t}_$t \\in T$ is a random vector in $\\Re^k$.\n    \\item One-sided random sequence, in which we define T to be {1, 2, \\cdots}.\n    \\item Two-sided random sequences, in which we define T to be \\mathbb{Z}.\n    \\item Spatially-discrete random fields, in which we let T to be $\\mathcal{Z}$.\n    \\item \nand some other types.\n\\end{itemize}\n\n\\subsection{Random Functions}\n\n$X(t, \\omega)$ has two arguments, t and $\\omega$. If we fix the value of t, X_t($\\omega$ is a random variable. For each fixed value of $\\omega$ though, X(t) is a function from T to S, we call it a random function.\n\n\n\\end{document}\n", "meta": {"hexsha": "9974e47d8f77311a54e23e87df8d8b30f2ebd311", "size": 7818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report1/Report1-SL.tex", "max_stars_repo_name": "AlirezaSadeghi/Statistical-Machine-Learning", "max_stars_repo_head_hexsha": "3586191be25d4b06e0be4b2c88958b53f1d66e28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report1/Report1-SL.tex", "max_issues_repo_name": "AlirezaSadeghi/Statistical-Machine-Learning", "max_issues_repo_head_hexsha": "3586191be25d4b06e0be4b2c88958b53f1d66e28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report1/Report1-SL.tex", "max_forks_repo_name": "AlirezaSadeghi/Statistical-Machine-Learning", "max_forks_repo_head_hexsha": "3586191be25d4b06e0be4b2c88958b53f1d66e28", "max_forks_repo_licenses": ["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.8205128205, "max_line_length": 502, "alphanum_fraction": 0.7307495523, "num_tokens": 2214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.65604083199858}}
{"text": "\\chapter{Finite elements in 2D}\n\nIn Chapter~\\ref{chap: FEM 1d} we considered a formally self-adjoint, linear, \nsecond-order differential operator~\\eqref{eq: L self-adjoint}.  The 2D \nequivalent has the form\n\\begin{equation}\\label{eq: L self-adjoint 2d}\n\\begin{aligned}\n\\mathcal{L}u&=-\\nabla\\cdot\\bigl(a\\nabla u\\bigr)+cu\\\\\n\t&=-\\frac{\\partial}{\\partial x}\\biggl(a\\,\\frac{\\partial u}{\\partial x}\\biggr)\n\t-\\frac{\\partial}{\\partial y}\\biggl(a\\,\\frac{\\partial u}{\\partial y}\\biggr)\n\t+cu,\n\\end{aligned}\n\\end{equation}\nwhere the coefficients $a$~and $c$ must be smooth functions of $x$~and $y$, and \nthere is a constant~$a_{\\min}$ such that\n\\[\na(x,y)\\ge a_{\\min}>0\\quad\\text{for $(x,y)\\in\\Omega$,}\n\\]\nensuring that $\\mathcal{L}$ is \\emph{uniformly elliptic}.  Here, as in \nChapter~\\ref{chap: finite diff 2d}, $\\Omega$ is a bounded open subset \nof~$\\mathbb{R}^2$ with a piecewise smooth boundary~$\\Gamma=\\partial\\Omega$, but \nwe will now suppose that\n\\[\n\\Gamma=\\Gamma_{\\mathrm{D}}\\cup\\Gamma_{\\mathrm{N}},\n\\]\nwhere $\\Gamma_{\\mathrm{D}}$~and $\\Gamma_{\\mathrm{N}}$ are non-overlapping, \nrelatively closed subsets of~$\\partial\\Omega$ consisting of finitely many \nsmooth curves.  (Thus, the intersection \n$\\Gamma_{\\mathrm{D}}\\cap\\Gamma_{\\mathrm{N}}$ consists of finitely many\n\\emph{collision points}.) Our aim is to use the finite element method to compute \nnumerical solutions to a \\emph{mixed boundary-value problem} of the form\n\\begin{equation}\\label{eq: self-adjoint bvp 2d}\n\\begin{aligned}\n\\mathcal{L}u&=f&&\\text{in~$\\Omega$,}\\\\\nu&=g_{\\mathrm{D}}&&\\text{on~$\\Gamma_{\\mathrm{D}}$,}\\\\\na\\,\\frac{\\partial u}{\\partial n}&=g_{\\mathrm{N}}&&\n\t\\text{on~$\\Gamma_{\\mathrm{N}}$.}\n\\end{aligned}\n\\end{equation}\nHere, $\\partial u/\\partial n$ is the derivative of~$u$ in the direction of the \n\\emph{outward unit normal}~$\\boldsymbol{n}$ for~$\\Omega$, that is,\n\\[\n\\frac{\\partial u}{\\partial n}(x,y)\n\t=\\boldsymbol{n}(x,y)\\cdot\\nabla u(x,y)\n\t\\quad\\text{for $(x,y)\\in\\partial\\Omega$.}\n\\]\nWe refer to~$\\Gamma_{\\mathrm{D}}$~and $\\Gamma_{\\mathrm{N}}$ as the \n\\emph{Dirichlet}~and \\emph{Neumann} parts of the boundary, respectively, since \nwe specify a Dirichlet boundary condition~$u=g_{\\mathrm{D}}$ \non~$\\Gamma_{\\mathrm{D}}$ and a Neumann boundary \ncondition~$a\\partial u/\\partial n=g_{\\mathrm{N}}$ on~$\\Gamma_{\\mathrm{N}}$. \n\nIn the special case of a \\emph{pure Dirichlet problem}, the Neumann part of the \nboundary is empty and so $u$ is specified on the whole of~$\\Gamma$ (as \nin Chapter~\\ref{chap: finite diff 2d}).  In the opposite case of a \n\\emph{pure Neumann problem}, the Dirichlet part of the boundary is empty and so \n$a\\,\\partial u/\\partial n$ is specified on the whole of~$\\Gamma$.\n\n\\section{First Green identity}\n\nRecall the \\emph{divergence theorem} from vector calculus; on the right-hand \nside, the integral over~$\\Gamma$ is with respect to \\\n\n\\begin{theorem}\\label{thm: divergence}\nIf the vector field $\\boldsymbol{F}:\\Omega\\cup\\Gamma\\to\\mathbb{R}^2$ is $C^1$, \nthen\n\\[\n\\int_\\Omega\\nabla\\cdot\\boldsymbol{F}\n\t=\\int_\\Gamma\\boldsymbol{F}\\cdot\\boldsymbol{n}.\n\\]\n\\end{theorem}\n\nWritten out more explicitly, if \n\\[\n\\boldsymbol{F}(x,y)=P(x,y)\\,\\boldsymbol{i}+Q(x,y)\\,\\boldsymbol{j}\n\\quad\\text{and}\\quad\n\\boldsymbol{n}=n_x\\,\\boldsymbol{i}+n_y\\,\\boldsymbol{j},\n\\]\nthen the divergence theorem says that\n\\[\n\\iint_\\Omega\\biggl(\\frac{\\partial P}{\\partial x}+\\frac{\\partial Q}{\\partial y}\n\t\\biggr)\\,dx\\,dy=\\int_\\Gamma\\bigl(P\\,n_x+Q\\,n_y)\\,ds,\n\\]\nwhere $ds$ is the element of arc length along~$\\Gamma$.  We also recall the \nfollowing vector field identity.\n\n\\begin{lemma}\\label{lem: div phi F}\nFor a $C^1$ scalar field~$\\phi$ and a $C^1$ vector field~$\\boldsymbol{F}$,\n\\[\n\\nabla\\cdot(\\phi\\boldsymbol{F})=(\\nabla\\phi)\\cdot\\boldsymbol{F}\n\t+\\phi\\,\\nabla\\cdot\\boldsymbol{F}.\n\\]\n\\end{lemma}\n\nTogether, Theorem~\\ref{thm: divergence}~and Lemma~\\ref{lem: div phi F} may be \nused to prove a 2D version of~\\eqref{eq: int by parts}.\n\n\\begin{theorem}[First Green Identity]\\label{thm: first Green}\nIf $u:\\Omega\\cup\\Gamma\\to\\mathbb{R}$ is $C^2$, and if \n$v:\\Omega\\cup\\Gamma\\to\\mathbb{R}$ is $C^1$, then\n\\[\n\\int_\\Omega(\\mathcal{L}u)\\,v\n\t=\\int_\\Omega\\bigl(a\\nabla u\\cdot\\nabla v+cuv\\bigr)\n\t-\\int_\\Gamma a\\,\\frac{\\partial u}{\\partial n}\\,v.\n\\]\n\\end{theorem}\n\\begin{proof}\nTaking $\\phi=v$~and $\\boldsymbol{F}=a\\nabla u$ in Lemma~\\ref{lem: div phi F}, \nwe have\n\\[\n\\nabla\\cdot(va\\nabla u)=(\\nabla v)\\cdot(a\\nabla u)+v\\nabla\\cdot(a\\nabla u),\n\\]\nso\n\\begin{align*}\n(\\mathcal{L}u)v&=\\bigl(-\\nabla\\cdot(a\\nabla u)+cu\\bigr)v\n\t=-v\\nabla\\cdot(a\\nabla u)+cuv\\\\\n\t&=(\\nabla v)\\cdot(a\\nabla u)-\\nabla\\cdot(va\\nabla u)+cuv\n\t=\\bigl(a\\nabla u\\cdot\\nabla v+cuv)-\\nabla\\cdot(va\\nabla u).\n\\end{align*}\nApplying Theorem~\\ref{thm: divergence} with~$\\boldsymbol{F}=va\\nabla u$, it \nfollows that\n\\[\n\\int_\\Omega(\\mathcal{L}u)v=\\int_\\Omega\\bigl(a\\nabla u\\cdot\\nabla v+cuv\\bigr)\n\t-\\int_\\Gamma\\boldsymbol(va\\nabla u)\\cdot\\boldsymbol{n},\n\\]\nwhich gives the desired identity because \n$(\\nabla u)\\cdot\\boldsymbol{n}=\\partial u/\\partial n$.\n\\end{proof}\n\nSince \n\\[\n\\int_\\Gamma a\\,\\frac{\\partial u}{\\partial n}\\,v\n\t=\\int_{\\Gamma_{\\mathrm{D}}} a\\,\\frac{\\partial u}{\\partial n}\\,v\n\t+\\int_{\\Gamma_{\\mathrm{N}}} a\\,\\frac{\\partial u}{\\partial n}\\,v,\n\\]\nwe see that if $u$ is a $C^2$ solution of~\\eqref{eq: self-adjoint bvp 2d}, and \nif $v$ is $C^1$, then\n\\begin{equation}\\label{eq: Lu=f weak 2d}\n\\int_\\Omega\\bigl(a\\nabla u\\cdot\\nabla v+cuv\\bigr)=\\int_\\Omega fv\n\t+\\int_{\\Gamma_{\\mathrm{N}}}g_{\\mathrm{N}}v\n\t\\quad\\text{provided $v=0$ on $\\Gamma_{\\mathrm{D}}$.}\n\\end{equation}\nCompare this property with its 1D equivalent~\\eqref{eq: Lu=f weak 1d}.\n\n\\section{Triangulation and nodal basis}\\label{sec: triangulation}\n\n\\begin{figure}\n\\caption{A regular triangulation.}\\label{fig: good Th}\n\\begin{center}\n\\includegraphics[scale=0.7]{../src/chap6/good_triangulation.pdf} \n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\caption{A triangulation that fails to be regular.}\\label{fig: bad Th}\n\\begin{center}\n\\includegraphics[scale=0.7]{../src/chap6/bad_triangulation.pdf} \n\\end{center}\n\\end{figure}\n\nAssume now that $\\Omega$ is a polygon.  It follows by induction on the number \nof vertices that there exists a \\emph{triangulation} of~$\\Omega$, that is, a \nfinite set~$\\mathcal{T}$ of \\emph{non-overlapping} closed triangles whose \nunion is the closure of~$\\Omega$. A triangulation~$\\mathcal{T}$ is \n\\emph{regular} if the following two conditions are satisfied:\n\\begin{enumerate}\n\\item No triangle in~$\\mathcal{T}$ is \\emph{degenerate}, that is, \nno~$K\\in\\mathcal{T}$ has collinear vertices.\n\\item The intersection $K_1\\cap K_2$ of any two distinct triangles $K_1$, \n$K_2\\in\\mathcal{T}$ is either empty, a common edge or a common vertex.\n\\end{enumerate}\nFor example, Figure~\\ref{fig: good Th} shows a regular triangulation with \n7~vertices, or \\emph{nodes}, numbered in red, and 6~triangles, or \n\\emph{elements}, numbered in blue.  (The six boundary edges are \nnumbered in green.) However, the triangulation in \nFigure~\\ref{fig: bad Th} is not regular: the intersection of triangles 2~and 6 \nis an edge of triangle~6 but is not (the whole of) an edge of triangle~2.\nVertex~7 in Figure~\\ref{fig: bad Th} is said to be a \\emph{hanging node}.\n\nA simple data structure to store a triangulation consists of two arrays,\n$\\boldsymbol{P}$~and $\\boldsymbol{T}$.  The first stores the coordinates of the \n$j$th node in its $j$th column, and the second stores the node numbers of the\n$k$th triangle in its $k$th column. A third matrix~$\\boldsymbol{E}$ is required \nto deal with boundary conditions: the $j$th column stores the node numbers of \nthe $j$th boundary edge.  Thus, the triangulation in \nFigure~\\ref{fig: good Th} may be described by\n\\[\n\\boldsymbol{P}=\\begin{bmatrix}\n-2& 2& 2& 1&-1&-2& 0\\\\                \n-2&-2& 0& 2& 2& 0& 0\n\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{T}=\\begin{bmatrix}\n0&0&1&2&3&4\\\\\n6&1&2&3&4&5\\\\\n5&6&6&6&6&6\\end{bmatrix},\n\\]\nwith\n\\[\n\\boldsymbol{E}=\\begin{bmatrix}\n1&2&3&4&5&6\\\\\n2&3&4&5&6&1\\end{bmatrix}.\n\\]\nTo simplify some geometric computations, it is best to ensure that the node\nnumbering within each triangle proceeds counterclockwise, and that the edge\nnode numbering follows the induced orientation of~$\\partial\\Omega$. (Even with \nthis restriction, there are $3$~possibilities for each column \nof~$\\boldsymbol{T}$.)\n\nDenote the maximum element diameter \nby~$h=\\max_{K\\in\\mathcal{T}}\\operatorname{diam}(K)$, and let $V_h$ denote the \nvector space consisting of those functions~$v:\\Omega\\cup\\Gamma\\to\\mathbb{R}$ \nthat are continuous and piecewise-linear with respect to~$\\mathcal{T}$.  Thus,\nif $v\\in V_h$ then for each~$K\\in\\mathcal{T}$ there are coefficients \n$c\\brak{K}_0$, $c\\brak{K}_1$~and $c\\brak{K}_2$ such that\n\\begin{equation}\\label{eq: v K 1 x y}\nv(x,y)=c\\brak{K}_0+c\\brak{K}_1x+c\\brak{K}_2y\n\t\\quad\\text{for $(x,y)\\in K$.}\n\\end{equation}\nLet $\\mathsf{n}\\brak{K}_1$, $\\mathsf{n}\\brak{K}_2$, $\\mathsf{n}\\brak{K}_3$ \ndenote the vertices of the triangle~$K$, and let $\\psi\\brak{K}_1$, \n$\\psi\\brak{K}_2$, $\\psi\\brak{K}_3$ denote the unique linear functions \nsatisfying\n\\begin{equation}\\label{eq: psi node triangle}\n\\psi\\brak{K}_j(\\mathsf{n}\\brak{K}_i)=\\delta_{jk}\n\t\\quad\\text{for $i$, $j\\in\\{1,2,3\\}$.}\n\\end{equation}\nIn Section~\\ref{sec: barycentric}, we will derive explicit representations of \nthese functions.  The property~\\eqref{eq: psi node triangle} implies that if \n$v\\in V_h$ then\n\\[\nv(x,y)=\\sum_{i=1}^3v(\\mathsf{n}\\brak{K}_i)\\psi\\brak{K}_i(x,y)\n\t\\quad\\text{for $(x,y)\\in K$,}\n\\]\nshowing that $v$ is uniquely determined by its values at the nodes \nof~$\\mathcal{T}$.\n\n\\begin{figure}\n\\caption{A piecewise-linear ``tent function'', equal to~$1$ at one node, and \n$0$ at all other nodes.}\\label{fig: tent func}\n\\begin{center}\n\\includegraphics[scale=0.6]{../src/chap6/tent_func.pdf}\n\\end{center}\n\\end{figure}\n\nIn fact, suppose that $\\mathsf{n}_1$, $\\mathsf{n}_2$, \\dots, $\\mathsf{n}_M$ is \nan enumeration of the nodes of~$\\mathcal{T}$.  For~$1\\le r\\le M$, we \ndefine~$\\chi_r\\in V_h$ by requiring\n\\begin{equation}\\label{eq: chi 2d}\n\\chi_r(\\mathsf{n}_s)=\\delta_{rs}\\quad\\text{for $r$, $s\\in\\{1, 2, \\dots, M\\}$.}\n\\end{equation}\nFigure~\\ref{fig: tent func} shows an example of such a ``tent function''.  \nIf $v\\in V_h$, then\n\\[\nv(x,y)=\\sum_{r=1}^M v(\\mathsf{n}_r)\\chi_r(x,y)\n\t\\quad\\text{for $(x,y)\\in\\Omega\\cup\\Gamma$,}\n\\]\nand we call $\\{\\chi_1,\\chi_2,\\ldots,\\chi_M\\}$ the \\emph{nodal basis} for~$V_h$\n(Exercise~\\ref{ex: nodal basis}).\n\n\\section{Finite element method}\n\nSuppose that a regular triangulation~$\\mathcal{T}$ is \\emph{aligned} with \nthe decomposition $\\Gamma=\\Gamma_{\\mathrm{D}}\\cup\\Gamma_{\\mathrm{N}}$ of the \nboundary of~$\\Omega$.  This assumption means that $\\Gamma_{\\mathrm{D}}$ \nis a union of edges of triangles in~$\\mathcal{T}$ (in which \ncase, the same must be true of~$\\Gamma_{\\mathrm{N}}$).  The vertices lying on \nthe Dirichlet boundary~$\\Gamma_{\\mathrm{D}}$ are called the \\emph{fixed nodes}, \nbecause the values of the solution~$u$ are fixed at these points.  The \nremaining vertices are called the \\emph{free nodes}; these belong \nto~$\\Omega\\cup\\Gamma_{\\mathrm{N}}$, but note that the collision points, where\n$\\Gamma_{\\mathrm{D}}$~and $\\Gamma_{\\mathrm{N}}$ meet, are among the fixed nodes.\n\nSuppose that there are $M\\free$~free nodes and $M\\fix$~fixed nodes, giving a \ntotal of $M=M\\free+M\\fix$~nodes. It is convenient to number the nodes so that \nfree ones come first, followed by the fixed ones. That is, $\\mathsf{n}_1$, \n$\\mathsf{n}_2$, \\dots, $\\mathsf{n}_{M\\free}$ are free, and \n$\\mathsf{n}_{M\\free+1}$, $\\mathsf{n}_{M\\free+2}$, \\dots, $\\mathsf{n}_M$ are \nfixed.  \n\nLet $g_{\\mathrm{D},h}:\\Gamma_{\\mathrm{D}}\\to\\mathbb{R}$ be a piecewise-linear \napproximation to~$g_{\\mathrm{D}}$.  An obvious choice is the interpolant, so\nthat\n\\[\ng_{\\mathrm{D},h}(\\mathsf{n}_r)=g(\\mathsf{n}_r)\n    \\quad\\text{for $M\\free+1\\le r\\le M$.}\n\\]\nWe define the trial set\n\\[\nS_h=\\{\\,v\\in V_h:\\text{$v=g_{\\mathrm{D},h}$ on $\\Gamma_{\\mathrm{D}}$}\\,\\}\n\\]\nand the test space\n\\[\nT_h=\\{\\,v\\in V_h:\\text{$v=0$ on $\\Gamma_{\\mathrm{D}}$}\\,\\}.\n\\]\nRecalling \\eqref{eq: Lu=f weak 2d}, the finite element \nsolution~$u_h\\in S_h$ is then defined by requiring that\n\\begin{equation}\\label{eq: FEM 2d}\n\\int_\\Omega\\bigl(a\\nabla u_h\\cdot\\nabla v+cu_hv\\bigr)=\\int_\\Omega fv\n\t+\\int_{\\Gamma_{\\mathrm{N}}}g_{\\mathrm{N}}v\n\t\\quad\\text{for all $v\\in T_h$.}\n\\end{equation}\n\nWe expand the finite element solution in the nodal basis, and enforce the \nDirichlet boundary condition to obtain the representation\n\\begin{equation}\\label{eq: uh U 2d}\nu_h(x,y)=\\sum_{s=1}^MU_s\\chi_s(x,y)=\\sum_{s=1}^{M\\free}U_s\\chi_s(x,y)\n    +\\sum_{s=M\\free+1}^M g_{D,h}(\\mathsf{n}_s)\\chi_s(x,y).\n\\end{equation}\nSince $\\{\\chi_1,\\chi_2,\\ldots,\\chi_{M\\free}\\}$ is a basis for the trial \nspace~$T_h$, the requirement~\\eqref{eq: FEM 2d} is equivalent to\n\\begin{equation}\\label{eq: FEM 2d alt}\n\\int_\\Omega\\bigl(a\\nabla u_h\\cdot\\nabla\\chi_r+cu_h\\chi_r\\bigr)\n    =\\int_\\Omega f\\chi_r\n    -\\int_{\\Gamma_{\\mathrm{N}}}g_{\\mathrm{N}}\\chi_r\n    \\quad\\text{for $1\\le r\\le M\\free$,}\n\\end{equation}\nand so, after inserting the representation~\\eqref{eq: uh U 2d}, we obtain an \n$M\\free\\times M\\free$~linear system\n\\begin{equation}\\label{eq: FEM 2D linear system}\n\\sum_{s=1}^{M\\free}\\bigl(a_{rs}+c_{rs}\\bigr)U_s\n    =f_r+g_{\\mathrm{N},r}-\\sum_{s=M\\free+1}^M(a_{rs}+c_{rs})g_{\\mathrm{D},s}\n    \\quad\\text{for $1\\le r\\le M\\free$,}\n\\end{equation}\nwhere\n\\[\na_{rs}=\\int_\\Omega a\\nabla\\chi_s\\cdot\\nabla\\chi_r,\\qquad\nc_{rs}=\\int_\\Omega c\\chi_s\\chi_r,\\qquad\nf_r=\\int_\\Omega f\\chi_r,\\qquad\ng_{\\mathrm{N},r}=\\int_{\\Gamma_{\\mathrm{N}}}g_{\\mathrm{N}}\\chi_r,\n\\]\nand $g_{\\mathrm{D},s}=g_{\\mathrm{D},h}(\\boldsymbol{n}_s)$. Let \n\\[\n\\boldsymbol{U}=[U_s]_{s=1}^M\n    =\\begin{bmatrix}\\boldsymbol{U}\\free\\\\ \\boldsymbol{U}\\fix \\end{bmatrix}\n\\quad\\text{where}\\quad\n\\boldsymbol{U}\\free=\\begin{bmatrix}U_1\\\\ U_2\\\\ \\vdots\\\\ U_{M\\free}\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{U}\\fix=\\begin{bmatrix}U_{M\\free+1}\\\\ U_{M\\free+2}\\\\ \\vdots\\\\ U_M\n\\end{bmatrix},\n\\]\nand \n\\[\n\\boldsymbol{A}=[a_{rs}]_{\\substack{1\\le r\\le M\\free\\\\ 1\\le s\\le M}}\n=[\\,\\boldsymbol{A}\\free\\quad\\boldsymbol{A}\\fix\\,]\n\\]\nwhere\n\\[\n\\boldsymbol{A}\\free=\\begin{bmatrix}\na_{11}&\\cdots&a_{1M\\free}\\\\\n\\vdots&\\ddots&\\vdots\\\\\na_{M\\free1}&\\cdots&a_{M\\free M\\free}\n\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{A}\\fix=\\begin{bmatrix}\na_{1,M\\free+1}&\\cdots&a_{1M}\\\\\n\\vdots&\\ddots&\\vdots\\\\\na_{M\\free,M\\free+1}&\\cdots&a_{M\\free,M}\n\\end{bmatrix}.\n\\]\nSimilarly, $\\boldsymbol{C}=[\\boldsymbol{C}\\free\\quad\\boldsymbol{C}\\fix]$, and \nwe can write the linear system~\\eqref{eq: FEM 2D linear system} as\n\\[\n\\bigl(\\boldsymbol{A}\\free+\\boldsymbol{C}\\free\\bigr)\\boldsymbol{U}\\free\n    =\\boldsymbol{f}+\\boldsymbol{g}_{\\mathrm{N}}\n-\\bigl(\\boldsymbol{A}\\fix+\\boldsymbol{C}\\fix\\bigr)\\boldsymbol{g}_{\\mathrm{D}}\n\\quad\\text{and}\\quad\n\\boldsymbol{U}\\fix=\\boldsymbol{g}_{\\mathrm{D}},\n\\]\nwith\n\\[\n\\boldsymbol{f}=\\begin{bmatrix}f_1\\\\ f_2\\\\ \\vdots\\\\ f_{M\\free}\\end{bmatrix},\n\\qquad\n\\boldsymbol{g}_{\\mathrm{N}}=\\begin{bmatrix}\ng_{\\mathrm{N},1}\\\\ g_{\\mathrm{N},2}\\\\ \\vdots\\\\ \ng_{\\mathrm{N},M\\free}\\end{bmatrix},\n\\qquad\n\\boldsymbol{g}_{\\mathrm{D}}=\\begin{bmatrix}\ng_{\\mathrm{D},M\\free+1}]\\\\ g_{\\mathrm{D},M\\free+2}]\\\\ \\vdots\\\\\ng_{\\mathrm{D},M}] \n\\end{bmatrix}.\n\\]\n\n\\section{Barycentric coordinates and element matrices}\\label{sec: barycentric}\n\nConsider a triangle~$K$ with vertices $\\boldsymbol{a}_1$, \n$\\boldsymbol{a}_2$~and $\\boldsymbol{a}_3$.  The \\emph{barycentric coordinates} \n$(\\xi_1,\\xi_2,\\xi_3)$ of a point~$\\boldsymbol{x}$ with respect to~$K$ are \ndefined by the relations\n\\[\n\\boldsymbol{x}=\\xi_1\\boldsymbol{a}_1+\\xi_2\\boldsymbol{a}_2\n    +\\xi_3\\boldsymbol{a}_3\n    \\quad\\text{and}\\quad\n\\xi_1+\\xi_2+\\xi_3=1.    \n\\]\nThus, $\\boldsymbol{a}_1$, $\\boldsymbol{a}_2$, $\\boldsymbol{a}_3$ have\nbarycentric coordinates $(1,0,0)$, $(0,1,0)$, $(0,0,1)$, respectively. We will \nsee below that each~$\\xi_p$ is a linear function of~$\\boldsymbol{x}$, so \n\\begin{equation}\\label{eq: xi psi}\n\\xi_p=\\psi_p\\brak{K}(\\boldsymbol{x})\n    \\quad\\text{for $1\\le p\\le 3$,}\n\\end{equation}\nwhere the $\\psi_p\\brak{K}$ are the linear linear shape functions introduced in \nSection~\\ref{sec: triangulation}.  Thus, a level set of any\nbarycentric coordinate is a straight line, as illustrated \nin~\\ref{fig: barycentric}.\n\n\\begin{figure}\n\\caption{Level sets of the barycentric coordinates \n$(\\xi_1,\\xi_2,\\xi_3)$, and the centroid~$\\boldsymbol{c}$.}\n\\label{fig: barycentric}\n\\begin{center}\n\\includegraphics[scale=0.75]{../src/chap6/barycentric.pdf}\n\\end{center}\n\\end{figure}\n\nLet $\\boldsymbol{B}$ denote the inverse transpose \n(Exercise~\\ref{ex: inv transpose}) of the matrix with columns \n$\\boldsymbol{a}_1-\\boldsymbol{a}_3$~and $\\boldsymbol{a}_1-\\boldsymbol{a}_3$, \nthat is,\n\\[\n\\boldsymbol{B}=[\\,(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\\quad\n    (\\boldsymbol{a}_1-\\boldsymbol{a}_3)\\,]^{-T},\n\\]\nand write\n\\begin{equation}\\label{eq: bp vector def}\n\\boldsymbol{B}=[\\,\\boldsymbol{b}_1\\quad\\boldsymbol{b}_2\\,]\n\\quad\\text{with}\\quad\\boldsymbol{b}_3=-(\\boldsymbol{b}_1+\\boldsymbol{b}_2).\n\\end{equation}\nThe \\emph{centroid} of~$K$ is the point\n\\[\n\\boldsymbol{c}=\\tfrac13\\boldsymbol{a}_1+\\tfrac13\\boldsymbol{a}_2\n+\\tfrac13\\boldsymbol{a}_3\n\\]\nwith barycentric coordinates~$(\\tfrac13,\\tfrac13,\\tfrac13)$. The barycentric \ncoordinates of a given point~$\\boldsymbol{x}$ can be computed as follows.\n\n\\begin{theorem}\\label{thm: barycentric}\nWith the notation above,\n\\[\n\\xi_j=\\tfrac13+\\boldsymbol{b}_j\\cdot(\\boldsymbol{x}-\\boldsymbol{c})\n\\quad\\text{for $j\\in\\{1,2,3\\}$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nSince $\\xi_1+\\xi_2+\\xi_3=1$ we can express $\\boldsymbol{x}$ in terms of \n$\\xi_1$~and $\\xi_2$ only,\n\\[\n\\boldsymbol{x}=\\xi_1\\boldsymbol{a}_1+\\xi_2\\boldsymbol{a}_2\n    +(1-\\xi_1-\\xi_2)\\boldsymbol{a}_3\n    =\\boldsymbol{a}_3+\\xi_1(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\n    +\\xi_2(\\boldsymbol{a}_2-\\boldsymbol{a}_3).\n\\]\nThus,\n\\[\n\\boldsymbol{x}-\\boldsymbol{a}_3\n=[\\,(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\\quad\n    (\\boldsymbol{a}_2-\\boldsymbol{a}_3\\,]\n\\begin{bmatrix}\\xi_1\\\\ \\xi_2 \\end{bmatrix}\n=B^{-T}\\begin{bmatrix}\\xi_1\\\\ \\xi_2 \\end{bmatrix}\n\\]\nand so\n\\[\n\\begin{bmatrix}\\xi_1\\\\ \\xi_2 \\end{bmatrix}=B^T(\\boldsymbol{x}-\\boldsymbol{a}_3)\n=\\begin{bmatrix}\\boldsymbol{b}_1^T\\\\ \\boldsymbol{b}_2^T\\end{bmatrix}\n    (\\boldsymbol{x}-\\boldsymbol{a}_3)\n=\\begin{bmatrix}\\boldsymbol{b}_1\\cdot(\\boldsymbol{x}-\\boldsymbol{a}_3)\\\\\n\\boldsymbol{b}_2\\cdot(\\boldsymbol{x}-\\boldsymbol{a}_3)\\end{bmatrix},\n\\]\nthat is,\n\\[\n\\xi_1=\\boldsymbol{b}_1\\cdot(\\boldsymbol{x}-\\boldsymbol{a}_3)\n\\quad\\text{and}\\quad\n\\xi_2=\\boldsymbol{b}_2\\cdot(\\boldsymbol{x}-\\boldsymbol{a}_3),\n\\]\nSince $\\boldsymbol{a}_1$, $\\boldsymbol{a}_2$, $\\boldsymbol{a}_3$ have\nbarycentric coordinates $(1,0,0)$, $(0,1,0)$, $(0,0,1)$, respectively,\n\\[\n\\boldsymbol{b}_1\\cdot(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\n=1=\\boldsymbol{b}_2\\cdot(\\boldsymbol{a}_2-\\boldsymbol{a}_3)\n\\]\nwhereas\n\\[\n\\boldsymbol{b}_1\\cdot(\\boldsymbol{a}_2-\\boldsymbol{a}_3)\n=0=\\boldsymbol{b}_2\\cdot(\\boldsymbol{a}_1-\\boldsymbol{a}_3),\n\\]\nso, for $j\\in\\{1,2\\}$,\n\\[\n\\boldsymbol{b}_j\\cdot(\\boldsymbol{c}-\\boldsymbol{a}_3)\n    =\\boldsymbol{b}_j\\cdot(\n\\tfrac13\\boldsymbol{a}_1+\\tfrac13\\boldsymbol{a}_2+\\tfrac13\\boldsymbol{a}_3\n    -\\boldsymbol{a}_3)\n    =\\tfrac13\\boldsymbol{b}_j\\cdot(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\n    +\\tfrac13\\boldsymbol{b}_j\\cdot(\\boldsymbol{a}_2-\\boldsymbol{a}_3)\n    =\\tfrac13\n\\]\nand hence\n\\[\n\\xi_j=\\boldsymbol{b}_j\\cdot(\n    \\boldsymbol{x}-\\boldsymbol{c}+\\boldsymbol{c}-\\boldsymbol{a}_3)\n    =\\boldsymbol{b}_j\\cdot(\\boldsymbol{x}-\\boldsymbol{c})+\\tfrac13.\n\\]\nFinally,\n\\[\n\\xi_3=1-\\xi_2-\\xi_3=(1-\\tfrac13-\\tfrac13)\n    -(\\boldsymbol{b}_1+\\boldsymbol{b}_2)\\cdot\n    (\\boldsymbol{x}-\\boldsymbol{a}_3)\n    =\\tfrac13+\\boldsymbol{b}_3\\cdot(\\boldsymbol{x}-\\boldsymbol{a}_3).\n\\]\n\\end{proof}\n\nWe define the triangular reference element\n\\[\nK_{\\mathrm{ref}}=\\{\\,(\\xi_1,\\xi_2):\n    \\text{$0\\le\\xi_1\\le1$ and $0\\le\\xi_2\\le\\xi_1$}\\,\\}\n\\]\nwith reference nodes $\\boldsymbol{n}_p=\\boldsymbol{a}_p$ for~$1\\le p\\le 3$,\nand observe that the affine transformation $K_{\\mathrm{ref}}\\to K$ defined by\n\\[\n(\\xi_1,\\xi_2)\\mapsto\\boldsymbol{x}(\\xi_1,\\xi_2)=\\boldsymbol{a}_3\n    +\\xi_1(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\n    +\\xi_2(\\boldsymbol{a}_2-\\boldsymbol{a}_3)\n\\]\nis one-one and onto, with Jacobian determinant\n\\[\n\\frac{\\partial(x_1,x_2)}{\\xi_1,\\xi_2})\n    =\\det[\\,(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\\quad\n            (\\boldsymbol{a}_2-\\boldsymbol{a}_3)\\,].\n\\]\nSince $\\bigl|\\det[\\,(\\boldsymbol{a}_1-\\boldsymbol{a}_3)\\quad\n(\\boldsymbol{a}_2-\\boldsymbol{a}_3)\\,]\\bigr|$ equals the area of the \nparallelogram spanned by the vectors $\\boldsymbol{a}_1-\\boldsymbol{a}_3$~and \n$\\boldsymbol{a}_2-\\boldsymbol{a}_3$, which in turns equals $2\\mathrm{area}(K)$, \nit follows that\n\\begin{equation}\\label{eq: int K f}\n\\int_Kf=2\\,\\mathrm{area}(K)\\int_0^1\\int_0^{1-\\xi_1}\n    f\\bigl(\\boldsymbol{x}(\\xi_1,\\xi_2)\\bigr)\\,d\\xi_2\\,d\\xi_1.\n\\end{equation}\nThe formula in the next theorem allows us to compute $\\int_Kf$ for any \npolynomial~$f$.\n\n\\begin{theorem}\\label{thm: int xi}\nFor all non-negative integers $n_1$, $n_2$, $n_3$,\n\\[\n\\int_K\\xi_1^{n_1}\\xi_2^{n_2}\\xi_3^{n_3}=2\\,\\mathrm{area}(K)\\,\n    \\frac{n_1!\\,n_2!\\,n_3!}{(n_1+n_2+n_3+2)!}.\n\\]\n\\end{theorem}\n\\begin{proof}\nBy~\\eqref{eq: int K f},\n\\begin{align*}\n\\int_K\\xi_1^{n_1}\\xi_2^{n_2}\\xi_3^{n_3}&=2\\,\\mathrm{area}(K)\n    \\int_0^1\\int_0^{1-\\xi_1}\\xi_1^{n_1}\\xi_2^{n_2}(1-\\xi_1-\\xi_2)^{n_3}\n        \\,d\\xi_2\\,d\\xi_1\\\\\n    &=2\\,\\mathrm{area}(K)\n    \\int_0^1\\xi_1^{n_1}\\int_0^{1-\\xi_1}\\xi_2^{n_2}(1-\\xi_1-\\xi_2)^{n_3}\n        \\,d\\xi_2\\,d\\xi_1.\n\\end{align*}\nIntegrating by parts $m$~times, we see that for any~$a>0$,\n\\begin{align*}\n\\int_0^a\\,\\frac{\\xi^n}{n!}\\,\\frac{(a-\\xi)^m}{m!}\\,d\\xi\n&=\\int_0^a\\,\\frac{\\xi^{n+1}}{(n+1)!}\\,\\frac{(a-\\xi)^{m-1}}{(m-1)!}\\,d\\xi\\\\\n&=\\cdots\n=\\int_0^a\\,\\frac{\\xi^{n+m}}{(n+m)!}\\,d\\xi=\\frac{a^{n+m+1}}{(n+m+1)!},\n\\end{align*}\nso\n\\begin{multline*}\n\\int_0^1\\xi_1^{n_1}\\int_0^{1-\\xi_1}\\xi_2^{n_2}(1-\\xi_1-\\xi_2)^{n_3}\n        \\,d\\xi_2\\,d\\xi_1\n    =n_2!\\,n_3!\\int_0^1\\xi_1^{n_1}\\int_0^{1-\\xi_1}\n    \\frac{\\xi_2^{n_2}}{n_2!}\\,\\frac{(1-\\xi_1-\\xi_2)^{n_3}}{n_3!}\n        \\,d\\xi_1\\,d\\xi_1\\\\\n    =n_1!\\,n_2!\\,n_3!\\int_0^1\\frac{\\xi_1^{n_1}}{n_1!}\\,\n        \\frac{(1-\\xi_1)^{n_2+n_3+1}}{(n_2+n_3+1)!}\\,d\\xi_1\n    =\\frac{n_1!\\,n_2!\\,n_3!}{(n_1+n_2+n_3+2)!},\n\\end{multline*}\ngiving the desired formula.\n\\end{proof}\n\n\\begin{figure}\n\\caption{The vectors $\\boldsymbol{b}_1$, $\\boldsymbol{b}_2$~and \n$\\boldsymbol{b}_3$ defined in~\\eqref{eq: bp vector def}.}\\label{fig: b vectors}\n\\begin{center}\n\\includegraphics[scale=0.8]{../src/chap6/b_vectors.pdf}\n\\end{center}\n\\end{figure}\n\nRecalling \\eqref{eq: xi psi}~and Theorem~\\ref{thm: barycentric}, the linear \nshape functions are given by\n\\[\n\\psi_j(\\boldsymbol{x})=\\xi_j\n    =\\tfrac13+\\boldsymbol{b}_j\\cdot(\\boldsymbol{x}-\\boldsymbol{a}_j)\n    \\quad\\text{for $j\\in\\{1,2,3\\}$,}\n\\]\nand so\n\\[\n\\nabla\\psi_j=\\boldsymbol{b}_j\\quad\\text{for $j\\in\\{1,2,3\\}$.}\n\\]\nThus, $\\boldsymbol{b}_j$ is orthogonal to the level sets of~$\\psi_j$ and in \nparticular to the side of~$K$ opposite~$\\boldsymbol{a}_j$, as shown in \nFigure~\\ref{fig: b vectors}.\n\nUsing the same approach as in the 1D case in \nSection~\\ref{sec: matrix assembly 1d}, we will assemble the \n$M\\times(M+R)$ global stiffness \nmatrix~$\\boldsymbol{A}=[\\,\\boldsymbol{A}'\\quad\\boldsymbol{A}'']$ from \nthe $3\\times3$ element stiffness matrices\n\\[\n\\boldsymbol{A}\\brak{K}=\\bigl[a\\brak{K}_{ij}\\bigr]_{i,j=1}^3\n\\quad\\text{where}\\quad\na\\brak{K}_{ij}=\\int_Ka\\nabla\\psi_j\\brak{K}\\cdot\\nabla\\psi\\brak{K}_i.\n\\]\nLikewise, the $M\\times(M+R)$ global mass \nmatrix~$\\boldsymbol{C}=[\\,\\boldsymbol{C}'\\quad\\boldsymbol{C}'']$ will be \nassembled from the $3\\times3$ element mass matrices,\n\\[\n\\boldsymbol{C}\\brak{K}=\\bigl[c\\brak{K}_{ij}\\bigr]_{i,j=1}^3\n\\quad\\text{where}\\quad\nc\\brak{K}_{ij}=\\int_Kc\\psi_j\\brak{K}\\psi\\brak{K}_i.\n\\]\nExplicitly, the entries of the element stiffness matrix are\n\\[\na\\brak{K}_{ij}=\\boldsymbol{b}_j\\cdot\\boldsymbol{b}_i\\int_K a\n    =\\boldsymbol{b}_j\\cdot\\boldsymbol{b}_i\\int_0^1\\int_0^{1-\\xi_1}\n        a\\bigl(\\boldsymbol{x}(\\xi_1,\\xi_2)\\bigr)\\,d\\xi_2\\,d\\xi_1,\n\\]\nand those of the element mass matrix are\n\\[\nc\\brak{K}_{ij}=\\int_Kc\\xi_j\\xi_i=\\int_0^1\\int_0^{1-\\xi_1}\n        c\\bigl(\\boldsymbol{x}(\\xi_1,\\xi_2)\\bigr)\\xi_j\\xi_i\\,d\\xi_2\\,d\\xi_1,\n\\]\nremembering that $\\xi_3=1-\\xi_1-\\xi_2$.\nIn particular, if $a(\\boldsymbol{x})=1$~and $c(\\boldsymbol{x})=1$, then\nTheorem~\\ref{thm: int xi} shows that \n\\[\n\\newcommand{\\bb}{\\boldsymbol{b}}\n\\boldsymbol{A}\\brak{K}=\\mathrm{area}(K)\\begin{bmatrix}\n\\bb_1\\cdot\\bb_1&\\bb_2\\cdot\\bb_1&\\bb_3\\cdot\\bb_1\\\\\n\\bb_1\\cdot\\bb_2&\\bb_2\\cdot\\bb_2&\\bb_3\\cdot\\bb_2\\\\\n\\bb_1\\cdot\\bb_3&\\bb_2\\cdot\\bb_3&\\bb_3\\cdot\\bb_3\n\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{C}\\brak{K}=\\frac{\\mathrm{area}(K)}{12}\\begin{bmatrix}\n2&1&1\\\\ 1&2&1\\\\ 1&1&2 \\end{bmatrix}.\n\\]\n\nThe 3-dimensional element load vector is defined by\n\\[\n\\boldsymbol{f}\\brak{K}=[f\\brak{K}_i]_{i=1}^3\n\\quad\\text{where}\\quad\nf\\brak{K}_i=\\int_K f\\psi\\brak{K}_i\n\t=\\int_0^1\\int_0^{1-\\xi_1}f\\bigl(\\boldsymbol{x}(\\xi_1,\\xi_2)\\bigr)\\xi_i\n\t\\,d\\xi_2 \\,d\\xi_1\n\\]\n\n\\section{Quadratic elements}\n\n\\begin{figure}\n\\caption{The midpoint $\\boldsymbol{m}_j$ of the side opposite to the \nvertex~$\\boldsymbol{a}_j$ for $j\\in\\{1,2,3\\}$.}\n\\label{fig: midpoints}\n\\begin{center}\n\\includegraphics[scale=0.75]{../src/chap6/midpoints.pdf}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\caption{Quadratic shape functions}\n\\label{fig: quad shape funcs}\n\\hfil\n\\includegraphics[scale=0.8]{../src/chap6/quad_shape_funcs/psi1-crop.pdf}\n\\hfil\n\\includegraphics[scale=0.8]{../src/chap6/quad_shape_funcs/psi2-crop.pdf}\n\\hfil\n\\includegraphics[scale=0.8]{../src/chap6/quad_shape_funcs/psi3-crop.pdf}\n\\hfil\n\\\\[2\\jot]\n\\includegraphics[scale=0.8]{../src/chap6/quad_shape_funcs/psi4-crop.pdf}\n\\hfil\n\\includegraphics[scale=0.8]{../src/chap6/quad_shape_funcs/psi5-crop.pdf}\n\\hfil\n\\includegraphics[scale=0.8]{../src/chap6/quad_shape_funcs/psi6-crop.pdf}\n\\hfil\n\\end{figure}\n\n\nA general quadratic polynomial in two variables $x_1$~and $x_2$ has the form\n\\[\nv(x_1,x_2)=a_{00}+a_{10}x_1+a_{01}x_2+a_{20}x_1^2+a_{11}x_1x_2+a_{02}x_2^2.\n\\]\nThus, the space of all such polynomials has dimension~$6$ and we therefore \nrequire $6$ nodes in our triangular element~$K$. For $j\\in\\{1,2,3\\}$, let \n$\\boldsymbol{m}_j$ denote the midpoint of the side of the triangle~$K$ opposite \nthe vertex~$\\boldsymbol{a}_j$, as illustrated in\n\\cref{fig: midpoints}.  The barycentric coordinates of $\\boldsymbol{m}_1$, \n$\\boldsymbol{m}_2$, $\\boldsymbol{m}_3$ are then $(0,\\tfrac12,\\tfrac12)$,\n$(\\tfrac12,0,\\tfrac12)$, $(\\tfrac12,\\tfrac12,0)$, respectively.  We then define \nour 6~nodes in the element~$K$ by\n\\[\n\\boldsymbol{n}\\brak{K}_1=\\boldsymbol{a}_1,\\quad\n\\boldsymbol{n}\\brak{K}_2=\\boldsymbol{a}_2,\\quad\n\\boldsymbol{n}\\brak{K}_3=\\boldsymbol{a}_3,\\quad\n\\boldsymbol{n}\\brak{K}_4=\\boldsymbol{m}_1,\\quad\n\\boldsymbol{n}\\brak{K}_5=\\boldsymbol{m}_2,\\quad\n\\boldsymbol{n}\\brak{K}_6=\\boldsymbol{m}_3,\n\\]\nand the corresponding quadratic shape functions~$\\psi\\brak{K}_j$ \nfor~$1\\le \\le 6$ by requiring that\n\\[\n\\psi\\brak{K}_j(\\boldsymbol{n}\\brak{K}_i)=\\delta_{ij}\n\\quad\\text{for $i$, $j\\in\\{1,2,3,4,5,6\\}$.}\n\\]\nAs functions of the barycentric coordinates, we easily verify that\n\\[\n\\psi\\brak{K}_1(\\boldsymbol{x})=2\\xi_1(\\xi_1-\\tfrac12),\\qquad\n\\psi\\brak{K}_2(\\boldsymbol{x})=2\\xi_2(\\xi_2-\\tfrac12),\\qquad\n\\psi\\brak{K}_3(\\boldsymbol{x})=2\\xi_3(\\xi_3-\\tfrac12),\n\\]\nand\n\\[\n\\psi\\brak{K}_4(\\boldsymbol{x})=4\\xi_2\\xi_3,\\qquad\n\\psi\\brak{K}_5(\\boldsymbol{x})=4\\xi_3\\xi_1,\\qquad\n\\psi\\brak{K}_6(\\boldsymbol{x})=4\\xi_1\\xi_2.\n\\]\n\\cref{fig: quad shape funcs} plots these functions for a typical triangle.\nSince $\\nabla\\xi_j=\\boldsymbol{b}_j$, \n\\[\n\\nabla\\psi\\brak{K}_j(\\boldsymbol{x})=(4\\xi_j-1)\\boldsymbol{b}_j\n\\quad\\text{for $1\\le j\\le 3$,}\n\\]\nand\n\\begin{align*}\n\\nabla\\psi\\brak{K}_4(\\boldsymbol{x})\n    &=4(\\xi_2\\boldsymbol{b}_3+\\xi_3\\boldsymbol{b}_2),\\\\\n\\nabla\\psi\\brak{K}_5(\\boldsymbol{x})\n    &=4(\\xi_3\\boldsymbol{b}_1+\\xi_1\\boldsymbol{b}_3),\\\\\n\\nabla\\psi\\brak{K}_6(\\boldsymbol{x})\n    &=4(\\xi_1\\boldsymbol{b}_2+\\xi_2\\boldsymbol{b}_1).\n\\end{align*}\nUsing \\cref{thm: int xi}\n\n\n\n\n\n\\section{Optimality property}\n\n\\begin{Exercises}\n\n\\exercise\nDerive the weak formulation of the boundary-value \nproblem~\\eqref{eq: self-adjoint bvp 2d} if we replace the Neumann boundary \ncondition with the more general Robin boundary condition\n\\[\na\\,\\frac{\\partial u}{\\partial n}+bu=g_{\\mathrm{N}}\n    \\quad\\text{on $\\Gamma_{\\mathrm{N}}$.}\n\\]\n\\begin{ans}\nThe weak solution $u$ satisfies \n\\[\n\\int_\\Omega(a\\nabla u\\cdot\\nabla v+cuv)+\\int_{\\Gamma_{\\mathrm{N}}}buv\n    =\\int_\\Omega fv+\\int_{\\Gamma_{\\mathrm{N}}}g_{\\mathrm{N}}v\n    \\quad\\text{whenever $v=0$ on $\\Gamma_{\\mathrm{N}}$,}\n\\]\nwith $u=g_{\\mathrm{D}}$ on~$\\Gamma_{\\mathrm{D}}$\n\\end{ans}\n\n\\exercise\nDerive the weak formulation for the elliptic eigenproblem\n\\[\n\\begin{aligned}\n\\mathcal{L}\\phi&=\\lambda b\\phi&&\\text{in $\\Omega$},\\\\\n\\phi&=0&&\\text{on $\\Gamma_{\\mathrm{D}}$,}\\\\\na\\,\\frac{\\partial\\phi}{\\partial n}&=0&&\\text{on $\\Gamma_{\\mathrm{N}}$,}\n\\end{aligned}\n\\]\nwhere, as usual, $\\mathcal{L}\\phi=-\\nabla\\cdot(a\\nabla\\phi)+c\\phi$.\n\\begin{ans}\nThe eigenpair $(\\phi,\\lambda)$ satisfies\n\\[\n\\int_\\Omega(a\\nabla\\phi\\cdot\\nabla v+c\\phi v)=\\lambda\\int_\\Omega b\\phi v\n\\quad\\text{whenever $v=0$ on $\\Gamma_{\\mathrm{D}}$,}\n\\]\nwith $\\phi=0$ on~$\\Gamma_{\\mathrm{D}}$.\n\\end{ans}\n\n\\exercise\\label{ex: drawn triang}\nConsider the triangulation~$\\mathcal{K}$ determined by the nodal coordinate \nmatrix\n\\[\n\\boldsymbol{N}=\\begin{bmatrix}\n1&0&1&0&-1& 0&-1\\\\\n1&1&0&0& 0&-1&-1\\end{bmatrix}\n\\]\nand the triangle connectivity matrix\n\\[\n\\boldsymbol{T}^{\\mathcal{K}}=\\begin{bmatrix}\n1&4&4&3&4&5\\\\\n2&3&2&4&5&7\\\\\n3&2&5&6&6&6\\end{bmatrix}.\n\\]\n\\begin{description}\n\\item{(i)} Draw $\\mathcal{K}$, numbering the nodes and triangles.\n\\item{(ii)} Enumerate the outer edges, given that the edge connectivity\nmatrix is\n\\[\n\\boldsymbol{T}^{\\mathcal{E}}=\\begin{bmatrix}\n6&3&1&2&5&7\\\\\n3&1&2&5&7&6\\end{bmatrix}.\n\\]\n\\item{(iii)} Determine $\\Gamma_{\\mathrm{D}}$~and $\\Gamma_{\\mathrm{N}}$ assuming \n$M^{\\textrm{free}}=4$.\n\\end{description}\n\\begin{ans}\n(i) See \\cref{fig: drawn triang}\\quad (ii) Edges are numbered in italic\\quad\n(iii) $\\Gamma_{\\mathrm{N}}$ consists of edges \n\\emph{1}--\\emph{4}; $\\Gamma_{\\mathrm{D}}$ consists of edges \\emph{5}~and \n\\emph{6}.\n\\begin{figure}\n\\caption{Triangulation for Exercise~\\ref{ex: drawn triang}}\n\\label{fig: drawn triang}\n\\begin{center}\n\\includegraphics[scale=1.0]{../src/chap6/ex1_triangulation.pdf}\n\\end{center}\n\\end{figure}\n\\end{ans}\n\n\\exercise\nSuppose that $\\Omega=\\Omega_1\\cup\\Gamma_{\\mathrm{i}}\\cup\\Omega_2$ where the \n\\emph{interface}~$\\Gamma_{\\mathrm{i}}$ is a piecewise smooth curve, and that\n\\[\na(x,y)=\\begin{cases}\na_1(x,y)&\\text{for $(x,y)\\in\\Omega_1$,}\\\\\na_2(x,y)&\\text{for $(x,y)\\in\\Omega_2$.}\n\\end{cases}\n\\]\nDefine corresponding partial differential operators\n$\\mathcal{L}_ku=-\\nabla\\cdot(a_k\\nabla u)$ on $\\Omega_k$ for~$k\\in\\{1,2\\}$.\nSuppose that\n\\[\n\\mathcal{L}_ku_k=f_k\\quad\\text{on $\\Omega_k$ for $k\\in\\{1,2\\}$,}\n\\]\nand define\n\\[\nu(x,y)=\\begin{cases}\nu_1(x,y)&\\text{for $(x,y)\\in\\Omega_1$,}\\\\\nu_2(x,y)&\\text{for $(x,y)\\in\\Omega_2$,}\n\\end{cases}\n\\qquad\\text{and}\\qquad\nf(x,y)=\\begin{cases}\nf_1(x,y)&\\text{for $(x,y)\\in\\Omega_1$,}\\\\\nf_2(x,y)&\\text{for $(x,y)\\in\\Omega_2$.}\n\\end{cases}\n\\]\nUnder what condition(s) on $u_1$~and $u_2$ do $u$~and $f$ satisfy\n\\[\n\\int_\\Omega a\\nabla u\\cdot\\nabla v\n    =\\int_\\Omega fv\n    -\\int_{\\partial\\Omega}a\\,\\frac{\\partial u}{\\partial n}\\,v\n\\]\nfor any test function~$v$?  Hint: let $\\boldsymbol{n}_{\\mathrm{i}}$ denote the \nunit normal along~$\\Gamma_{\\mathrm{i}}$, outward to~$\\Omega_1$ and inward \nto~$\\Omega_2$.\n\\begin{ans}\nBoth $u$ and its flux~$a\\nabla u$ must be continuous across the interface, that \nis, $u_1=u_2$ and \n$a_1\\boldsymbol{n}_{\\mathrm{i}}u_1=a_2\\boldsymbol{n}_{\\mathrm{i}}u_2$ \non~$\\Gamma_{\\mathrm{i}}$.\n\\end{ans}\n\n\n\\exercise\\label{ex: nodal basis}\nProve that the functions $\\chi_j\\in V_h$ satisfying~\\eqref{eq: chi 2d} form a \nbasis for the piecewise-linear, finite element space~$V_h$, that is, prove that \nthe nodal basis really is a basis. \n\n\\exercise\\label{ex: inv transpose}\nLet $\\boldsymbol{A}$ be a nonsingular matrix.\nShow that $(\\boldsymbol{A}^{-1})^T=(\\boldsymbol{A}^T)^{-1}$; we denote this \n\\emph{inverse transpose} matrix by~$\\boldsymbol{A}^{-T}$.\n\n\\exercise\nConsider a three-point quadrature rule of the form\n\\begin{equation}\\label{eq: 3 quad}\n\\int_Kf\\approx\\frac{\\mathrm{area}(K)}{3}\\sum_{p=1}^3 \n    f(\\boldsymbol{x}\\brak{K}_p)\n\\end{equation}\nwhere, for some choice of the parameter~$\\lambda\\in(0,1)$, \n\\begin{equation}\\label{eq: 3 quad points}\n\\begin{aligned}\n\\boldsymbol{x}\\brak{K}_1=(1-2\\lambda)\\boldsymbol{a}_1+\\lambda\\boldsymbol{a}_2\n    +\\lambda\\boldsymbol{a}_3,\\\\\n\\boldsymbol{x}\\brak{K}_2=\\lambda\\boldsymbol{a}_1+(1-2\\lambda)\\boldsymbol{a}_2\n    +\\lambda\\boldsymbol{a}_3,\\\\\n\\boldsymbol{x}\\brak{K}_3=\\lambda\\boldsymbol{a}_1+\\lambda\\boldsymbol{a}_2\n    +(1-2\\lambda)\\boldsymbol{a}_3.\n\\end{aligned}\n\\end{equation}\nVerify that this rule integrates all quadratic polynomials exactly iff\n$\\lambda=1/6$~or $1/2$.  See Figure~\\ref{fig: quadrature points}.\n\\begin{figure}\n\\caption{Quadrature points \\eqref{eq: 3 quad points} for the \nrule~\\eqref{eq: 3 quad} with $\\lambda=1/6$ (left) and $\\lambda=1/2$ (right).}\n\\label{fig: quadrature points}\n\\begin{center}\n\\includegraphics[scale=0.85]{../src/chap6/quadrature_points-crop.pdf}\n\\end{center}\n\\end{figure}\n\n\\begin{exercise}\nTo achieve higher accuracy, we can consider a six-point quadrature rule\n\\[\n\\int_K f\\approx\\frac{\\mathrm{area}(K)}{3}\\biggl(\n\tw\\sum_{p=1}^3 f\\bigl(\\boldsymbol{x}\\brak{K}_p(\\lambda_1)\\bigr)\n\t+(1-w)\\sum_{p=1}^3 f\\bigl(\\boldsymbol{x}\\brak{K}_p(\\lambda_2)\\bigr)\\biggr),\n\\]\ndepending on the parameters $w$, $\\lambda_1$~and $\\lambda_2$, with \n$\\boldsymbol{x}\\brak{K}_p=\\boldsymbol{x}\\brak{K}_p(\\lambda)$ defined as \nin~\\eqref{eq: 3 quad points}.\n\\end{exercise}\n\n\\begin{figure}\n\\caption{Triangulation for Exercise~\\ref{ex: 2019 exam problem}.}\n\\label{fig: 2019 exam problem}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.70]\n\\draw[-,very thick] (-6,0) -- (0,-6);\n\\draw[-] (0,-6) -- (6,0) -- (6,6) -- (3,9) -- (0,6) -- (-6,0);\n\\draw[-] (-6,0) -- (6,0);\n\\draw[-] (0,-6) -- (0,6) -- (6,6) -- (0,0);\n\\node at (3,7.5) {\\textbf{1}};\n\\node at (2,4) {\\textbf{2}};\n\\node at (-2,2) {\\textbf{3}};\n\\node at (4,2) {\\textbf{4}};\n\\node at (-2,-2) {\\textbf{5}};\n\\node at (2,-2) {\\textbf{6}};\n\\draw[fill,white] (3,9)  circle (0.30); \\draw (3,9) circle (0.30);\n\\node at (3, 9) {$1$};\n\\draw[fill,white] (0,6)  circle (0.30); \\draw (0,6)  circle (0.30);\n\\node at (0, 6) {$2$};\n\\draw[fill,white] (6,6)  circle (0.30); \\draw (6,6)  circle (0.30);\n\\node at  (6, 6) {$3$};\n\\draw[fill,white] (0,0)  circle (0.30); \\draw (0,0)  circle (0.30);\n\\node at  (0, 0) {$4$};\n\\draw[fill,white] (6,0)  circle (0.30); \\draw (6,0)  circle (0.30);\n\\node       at  (6, 0) {$5$};\n\\draw[fill,white] (-6,0) circle (0.30); \\draw (-6,0) circle (0.30);\n\\node at (-6, 0) {$6$};\n\\draw[fill,white] (0,-6) circle (0.30); \\draw (0,-6) circle (0.30);\n\\node       at  (0,-6) {$7$};\n\\node at (5.4,6.3) {*};\n\\node at (5.4,5.7) {*};\n\\node at (-0.3,0.5) {*};\n\\node at (0.7,0.3) {*};\n\\node at (-0.3,-5.4) {*};\n\\node at (5.3,-0.4) {*};\n\\node[below left] at (-3,-3) {$\\Gamma_{\\mathrm{D}}$};\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\n\\exercise\\label{ex: 2019 exam problem}\nConsider the triangulation shown in Figure~\\ref{fig: 2019 exam problem}.\nThe global node numbers are circled and the element numbers are in bold.\nThe choice of the first node in each element is indicated with an asterisk,\nafter which the second and third follow \\textbf{counterclockwise}. The\npart~$\\Gamma_{\\mathrm{D}}$ of the boundary where a Dirichlet boundary \ncondition applies is shown in a thicker line (between nodes $6$~and $7$).  Let\n$\\boldsymbol{f}=[f_r]$ and $\\boldsymbol{A}=[a_{rs}]$ denote the global load \nvector and the global stiffness matrix, and let\n$\\boldsymbol{f}\\brak{p}=[f\\brak{p}_j]$~and \n$\\boldsymbol{A}\\brak{p}=[a\\brak{p}_{jk}]$ denote \nthe element load vector and element stiffness matrix for the $p$th element \n($1\\le p\\le6$).  \n\\begin{description}\n\\item{(a)} Write out the $3\\times6$ connectivity matrix.\n\\item{(b)} Express $f_4$ as a sum over entries~$f\\brak{p}_j$ of the element \nload vectors.\n\\item{(c)} Express $a_{22}$, $a_{35}$~and $a_{47}$ as sums over \nentries~$a\\brak{p}_{jk}$ of the element matrices.\n\\end{description}\n\n\\begin{figure}\n\\caption{Triangulation for Exercise~\\ref{ex: FEM triang}.}\n\\label{fig: FEM triang}\n\\begin{center}\n\\includegraphics[scale=1.0]{../src/chap6/ex2_triangulation-crop.pdf}\n\\end{center}\n\\end{figure}\n\n\\exercise\\label{ex: FEM triang}\nConsider the finite element method for a boundary-value \nproblem~\\eqref{eq: self-adjoint bvp 2d} using the triangulation shows in \n\\cref{fig: FEM triang}.  Note that $\\Gamma_{\\mathrm{D}}$ consists of the bottom\nand right sides of~$\\Omega$ (that is, the thicker edges numbered $6$--$8$.)\n\\begin{description}\n\\item{(i)} What are $M\\free$~and $M\\fix$, the numbers of free and fixed nodes?\n\\item{(ii)} What is $Q_{\\mathrm{N}}$, the number of edges \nalong~$\\Gamma_{\\mathrm{N}}$?\n\\item{(iii)} Write down the triangle connectivity \nmatrix~$\\boldsymbol{T}^{\\mathcal{K}}$.\n\\item{(iv)} Write down the edge connectivity \nmatrix~$\\boldsymbol{T}^{\\mathcal{E}}$.\n\\item{(v)} What are the dimensions of the global load \nvector~$\\boldsymbol{f}=[f_r]$, the global stiffness \nmatrix~$\\boldsymbol{A}=[a_{rs}]$ and the global Neumann \nvector~$\\boldsymbol{g}_{\\mathrm{N}}=[g_{\\mathrm{N},r}]$?\n\\item{(vi)} Express each $f_r$ as a sum of entries~$f\\brak{p}_i$ from the \nelement load vectors $\\boldsymbol{f}\\brak{1}$, $\\boldsymbol{f}\\brak{2}$, \\dots,\n$\\boldsymbol{f}\\brak{10}$.\n\\item{(vii)} Express each nonzero~$a_{rs}$ as a sum of entries~$a\\brak{p}_{ij}$\nfrom the element stiffness matrices $\\boldsymbol{A}\\brak{1}$, \n$\\boldsymbol{A}\\brak{2}$, \\dots, $\\boldsymbol{A}\\brak{10}$.  (From symmetry, it \nsuffices to list the cases with $r\\le s$.)\n\\item{(viii)} Express each $g_{\\mathrm{N},r}$ as a sum of \nentries~$g^{[q]}_{\\mathrm{N},r}$ of the edge Neumann vectors \n$\\boldsymbol{g}^{[1]}_{\\mathrm{N}}$, $\\boldsymbol{g}^{[2]}_{\\mathrm{N}}$, \\dots\n$\\boldsymbol{g}^{[5]}_{\\mathrm{N}}$.\n\\end{description}\n\n\\end{Exercises}\n", "meta": {"hexsha": "300db5d3b7ff6ef8e5c0ea0067328c975e2066eb", "size": 38017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/chap6.tex", "max_stars_repo_name": "billmclean/ComputationalMathsNotes", "max_stars_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-30T21:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T21:30:20.000Z", "max_issues_repo_path": "texsrc/chap6.tex", "max_issues_repo_name": "billmclean/ComputationalMathsNotes", "max_issues_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "texsrc/chap6.tex", "max_forks_repo_name": "billmclean/ComputationalMathsNotes", "max_forks_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.198630137, "max_line_length": 81, "alphanum_fraction": 0.6788541968, "num_tokens": 15199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028205, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6559898147812918}}
{"text": "\\section{Universal kernels(Li Jiang)}\n\n\\begin{definition}\n\tLet $X$ be a non-empty set. Then  a function $k:X\\times X \\rightarrow \\mathbb{K}$ is called a \\textbf{kernel} on $X$ if there exists a $\\mathbb{K}$-Hilbert space $H$ and a map $\\Phi:X\\rightarrow H$ such that for all $x,x' \\in X$ we have\n\t\\begin{equation}\n\tk(x,x') = \\langle \\Phi(x'),\\Phi(x) \\rangle.\n\t\\end{equation}\n\tWe call $\\Phi$ a \\textbf{feature map} and $H$ a \\textbf{feature space} of $k$.\n\\end{definition}\n\nDenote\n\\begin{equation}\nK_X = {\\rm span} \\{k(x,\\cdot), x\\in X\\}.\n\\end{equation}\n\n\\begin{definition}[Universal Kernels]\n\tA continuous kernel $k$ on a compact metric space $X$ is called \\textbf{universal} if $K_X$ is dense in $C(X)$, i.e., for every function $g\\in C(X)$ and all $\\epsilon>0$ there exists an $f\\in K_X$ such that\n\t\\begin{equation}\n\t\\|f-g\\|_{\\infty} \\leq \\epsilon.\n\t\\end{equation} \n\\end{definition}\n\nGiven any \\textbf{feature map} $\\Phi$ and  a \\textbf{feature space} $H$ of $k$, we denote\n\\begin{equation}\nS_{\\Phi,H} = {\\rm span} \\{\\Phi(x): x\\in X\\},\n\\end{equation}\nand\n\\begin{equation}\nF_{\\Phi,H} = \\{f:  \\exists w\\in H, f(x) = \\langle w, \\Phi(x) \\rangle_H, \\forall x\\in X\\}.\n\\end{equation}\n\n\\begin{lemma}\n\t\\begin{equation}\n\t\tK_X = \\{f:  \\exists w\\in S_{\\Phi,H}, f(x) = \\langle w, \\Phi(x) \\rangle_H, \\forall x\\in X\\}.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{lemma}\n\t\\begin{equation}\n\tF_{\\Phi,H} = \\{f:  \\exists w\\in \\overline{S_{\\Phi,H}}, f(x) = \\langle w, \\Phi(x) \\rangle_H, \\forall x\\in X\\}.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\tWe only need to notice that\n\t\\begin{equation}\n\tH = \\overline{S_{\\Phi,H}} \\oplus \\overline{S_{\\Phi,H}}^{\\perp}.\n\t\\end{equation} \n\tThen for any $w\\in H$, there exists a $w_1 \\in \\overline{S_{\\Phi,H}}$, and a $w_2 \\in \\overline{S_{\\Phi,H}}^{\\perp}$ such that $w = w_1 + w_2$. Notice that $\\langle w_2, \\Phi(x) \\rangle_H = 0,~\\forall x\\in X$. So we have\n\t\\begin{equation}\n\t\t\\langle w, \\Phi(x) \\rangle_H = \\langle w_1, \\Phi(x) \\rangle_H,~\\forall x \\in X.\n\t\\end{equation}\n\\end{proof}\n%Easy to observe that there is a surjective between $F_{\\Phi,H}$ and $\\overline{S_{\\Phi,H}}$.\n\n%\\begin{lemma}\n%\tFor any two pairs $(\\Phi,H)$ and $(\\Phi',H')$, there is an isomorphism between $\\overline{S_{\\Phi,H}}$ and $\\overline{S_{\\Phi',H'}}$.\n%\\end{lemma}\n\n%\\begin{lemma}\n%\tLet $X\\neq \\emptyset$ and $k$ be a continuous kernel over $X$ with feature space $H$ and feature map $\\Phi: X\\rightarrow H$, then $\\Phi$ must be continuous.\n%\\end{lemma}\n%\n%\\begin{proof}\n%\t\\begin{equation}\n%\t\\|\\Phi(x) - \\Phi(x')\\|_H^2 = k(x,x) + k(x',x') - k(x,x') - k(x',x).\n%\t\\end{equation}\n%\tSo the continuity of kernel implies the continuity of feature map $\\Phi$.\n%\\end{proof}\n\n\\begin{lemma}\n\tLet $X$ be a compact metric space and $k$ be a continuous kernel over $X$ with feature space $H$ and feature map $\\Phi: X\\rightarrow H$, then we have\n\t\\begin{equation}\n\tK_X \\subset F_{\\Phi,H} \\subset \\overline{K_X}.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\t$K_X \\subset F_{\\Phi,H} $ is a direct corollary of the preceding 2 lemmas. So we only need to show that $F_{\\Phi,H} \\subset \\overline{K_X}$.\\\\\n\tGiven any $f\\in F_{\\Phi,H}$, there exists a $w\\in \\overline{S_{\\Phi,H}}$ such that $f(\\cdot) = \\langle w,\\Phi(\\cdot) \\rangle_H$. Choose a sequence $\\{w_n\\}$ in $S_{\\Phi,H}$ which satisfies $w_n$ converges to $w$ in $H$, then easy to observe that $f_n(\\cdot) = \\langle w_n,\\Phi(\\cdot) \\rangle_H\\in K_X$. Notice that\n\t\\begin{equation}\n\t\t|f_n(x) - f(x)| \\leq \\|w_n - w\\|_H \\sqrt{k(x,x)}\n\t\\end{equation}\n\tDenote $C = \\sup_{x\\in X} \\sqrt{k(x,x)} < \\infty$, then \n\t\\begin{equation}\n\t\t\\|f_n - f\\|_{u} \\leq C \\|w_n - w\\|_H,\n\t\\end{equation}\n\tso $f_n$ converges to $f$ in $C(X)$, which implies $F_{\\Phi,H} \\subset \\overline{K_X}$.\n\\end{proof}\n\n\\begin{corollary}\n\t$K_X$ is dense in $C(X)$ if and only if there exists a pair $\\Phi,H$ such that $F_{\\Phi,H}$ is dense in $C(X)$.\n\\end{corollary}\n\n\n\nAccording to the last theorem, we know that given $H$ and $\\Phi$ as the feature space and feature map of kernel $k$, then we only need to prove that for every function $g\\in C(X)$ and all $\\epsilon>0$ there exists an $\\omega\\in H$ such that \n\\begin{equation}\n\\|\\langle \\omega,\\Phi(\\cdot) \\rangle - g\\|_{\\infty} \\leq \\epsilon.\n\\end{equation} \n\n\n\n\\begin{theorem}\n\tLet $X$ be a compact metric space and $k$ be a continuous kernel on $X$. Suppose that we have a feature map $\\Phi: X\\rightarrow l_2$ of $k$. We write $\\Phi_n: X\\rightarrow \\mathbb{R}$ for its n-th component, i.e., $\\Phi(x) = (\\phi_n(x))_{n\\in \\mathbb{N}}$, $x\\in X$. If $\\mathcal{A}:= {\\rm span} \\{\\phi_n: n\\in \\mathbb{N}\\}$ is dense in $C(X)$, then $k$ is universal.\n\\end{theorem}\n\n\\begin{proof}\n\tWe only need to notice that  $\\mathcal{A}\\subset F_{\\Phi,H} $.\n\\end{proof}\n\n\n\n\\begin{corollary}[Universal Taylor kernels].\n\tFix an $r\\in (0,+\\infty]$ and a $C^\\infty$ function $f:(-r,r) \\rightarrow \\mathbb{R}$ that can be expanded into its Taylor series at 0, i.e., \n\t\\begin{equation}\n\tf(t) = \\sum_{n = 0}^\\infty a_n t^n, ~~t\\in (-r,r).\n\t\\end{equation}\n\tLet $X:= \\{x\\in \\mathbb{R}^d: \\|x\\|_2 < \\sqrt{r}\\}$. If we have $a_n>0$ for all $n\\geq 0$, then $k$ given by\n\t\\begin{equation}\n\tk(x,x') := f(\\langle x,x'\\rangle),~~x,x'\\in X,\n\t\\end{equation}\n\tis a universal kernel on every compact subset of $X$.\n\\end{corollary}\n\n\\begin{proof}\n\tSuppose that $X_0$ is an arbitrary compact subset of $X$.\\\\\n\tNotice that\n\t\\begin{align*}\n\tk(x,x') &= \\sum_{n = 0} a_n (\\sum_{j = 1}^d x_j x_j')^n\\\\\n\t&= \\sum_{n =0}^\\infty a_n \\sum_{\\sum_{i = 1}^d j_i= n,~j_i\\geq0} \\frac{n!}{\\prod_{i = 1}^d j_i!} \\prod_{i = 1}^d x_i^{j_i}\\prod_{i = 1}^d (x'_i)^{j_i}\\\\\n\t&= \\sum_{j_1,\\cdots,j_d\\geq0} a_{j_1+\\cdots+j_d} \\frac{(j_1+\\cdots+j_d)!}{\\prod_{i = 1}^d j_i!} \\prod_{i = 1}^d x_i^{j_i}\\prod_{i = 1}^d (x'_i)^{j_i}\n\t\\end{align*}\n\tDenote that $c_{j_1,\\cdots,j_d} = \\sqrt{a_{j_1+\\cdots+j_d} \\frac{(j_1+\\cdots+j_d)!}{\\prod_{i = 1}^d j_i!}}$, $\\phi_{j_1,\\cdots,j_d} = c_{j_1,\\cdots,j_d} \\prod_{i = 1}^d x_i^{j_i}$, and define feature map $\\Phi: X_0 \\rightarrow l_2$ as\n\t\\begin{equation}\n\t\\Phi(x) := (\\phi_{j_1,\\cdots,j_d}(x))_{j_1,\\cdots,j_d\\geq 0}\n\t\\end{equation}\n\tBecause $c_{j_1,\\cdots,j_d} > 0$ for all $j_1,\\cdots,j_d\\geq0$, so $\\mathcal{A}:= {\\rm span} \\{\\phi_{j_1,\\cdots,j_d}: j_1,\\cdots,j_d\\geq0\\}$ is the d-variable polynomial space. According to the Stone-Weierstrass approximation theorem, we know $\\mathcal{A}$ is dense in $C(X)$.\n\\end{proof}\n\n\n\\begin{corollary}\n\tExponential kernel $k_{\\gamma}(x,x') = e^{\\langle x,x' \\rangle}$ is universal.\n\\end{corollary}\n\n\\begin{lemma}\n\tLet $X$ be a compact metric space and $k$ be a universal kernel on $X$. Then $k(x,x)>0$ for all $x\\in X$, and the \\textbf{normalized kernel} $k^*$: $X\\times X \\rightarrow \\mathbb{R}$ defined by \n\t\\begin{equation}\n\tk^*(x,x') := \\frac{k(x,x')}{\\sqrt{k(x,x)k(x',x')}},~~x,x'\\in X,\n\t\\end{equation}\n\tis universal.\n\\end{lemma}\n\n\n\\begin{corollary}\n\tGaussian RBF kernel $k_{\\gamma}(x,x') = e^{-\\frac{\\|x-x'\\|_2^2}{\\gamma^2}}$ is universal.\n\\end{corollary}\n\n\\begin{theorem}[Stone-Weierstra$\\beta$]\n\tLet $(X,d)$ be a compact metric space and $\\mathcal{A}\\subset C(X)$ be an algebra. Then $\\mathcal{A}$ is dense in $C(X)$ if both $\\mathcal{A}$ does not vanish, i.e., for all $x\\in X$, there exists an $f\\in \\mathcal{A}$ with $f(x)\\neq 0$, and $\\mathcal{A}$ separates points, i.e., for all $x,y\\in X$ with $x\\neq y$, there exists an $f\\in \\mathcal{A}$ with $f(x)\\neq f(y)$.\n\\end{theorem}\n\n\\begin{theorem}\n\tLet $X$ be a compact metric space and $k$ be a continuous kernel on $X$ with $k(x,x)>0$ for all $x\\in X$. Suppose that we have an injective feature map $\\Phi: X\\rightarrow l_2$ of $k$. We write $\\phi_n: X\\rightarrow \\mathbb{R}$ for its n-th component, i.e., $\\Phi(x) = (\\phi_n(x))_{n\\in \\mathbb{N}}$, $x\\in X$. If $\\mathcal{A}:= {\\rm span} \\{\\phi_n: n\\in \\mathbb{N}\\}$ is an algebra, then $k$ is universal.\n\\end{theorem}\n\n\\begin{proof}\n\tWe only need to verify that $\\mathcal{A}$ is dense in $C(X)$, thus we only need to verify $\\mathcal{A}$ satisfies the conditions in Stone-Weierstra$\\beta$ theorem. \\\\\n\tNotice that for all $x\\in X$, we have\n\t\\begin{equation}\n\t\\|\\Phi(x)\\|_{l2}^2 = \\sum_{n=1}^{\\infty} \\phi_n^2(x) = k(x,x) >0.\n\t\\end{equation}\n\tSo for all $x\\in X$, there is at least one $\\phi_n$ such that $\\phi_n(x) \\neq 0$.\\\\\n\tAlso, because $\\Phi$ is injective, we know for any $x\\neq y$, $\\Phi(x)\\neq \\Phi(y)$, which implies there exists a $\\phi_n$ such that $\\phi_n(x) \\neq \\phi_n(y)$.\n\t\n\\end{proof}", "meta": {"hexsha": "3ce4215213431b832b1d35f39749f066bdd4480c", "size": 8374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/JiangKernels.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/JiangKernels.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/JiangKernels.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.5795454545, "max_line_length": 407, "alphanum_fraction": 0.6379269166, "num_tokens": 3303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.6559898133469632}}
{"text": "\\subsubsection{Overdamped ($\\Delta > 0$)}\r\nThis is the simplest and easiest case to deal with because our two roots, $r_1$ and $r_2$, are real and distinct. So, out solution is\r\n\\begin{equation*}\r\n\ty = C_1e^{r_1 t} + C_2e^{r_2 t}\r\n\\end{equation*}\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/overdamped.png}\r\n\\end{center}\r\nWe know that $r_1, r_2 < 0$, so\r\n\\begin{equation*}\r\n\t\\lim\\limits_{t \\to 0}{C_1e^{r_1 t} + C_2e^{r_2 t}} = 0\r\n\\end{equation*}\r\nmeaning the mass's oscillation decays over time.", "meta": {"hexsha": "e49acd49d0d607b003ed942a675b42a3a4b3f95f", "size": 532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/freeVibrs/overdamped.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/freeVibrs/overdamped.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/freeVibrs/overdamped.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9230769231, "max_line_length": 134, "alphanum_fraction": 0.6936090226, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6559656932861844}}
{"text": "\\subsection{Peak-to-Average Ratio}\\label{subsec:peakratio}\n\nIn addition to examining traffic demands across the entire four-hour\nprime-time window, we also explored how subscribers in the treatment\ngroup exhibited different behavior for the 15-minute interval of highest \\green{(95th percentile)\ndemand in a day, regardless of prime-time hours.} We measure the disparity\nbetween a subscriber's daily 95th percentile and \nthe mean usage as the \\emph{peak-to-average ratio} \\red{(PAR)}\\sgfoot{replace all instances of peak-ratio or peak-to-mean ratio with peak-to-average ratio or PAR, which is a standard measurement stat for waveform analysis (also called crest ratio)}. (This metric\nshows the ratio of peak values to the effective value, and extends those used\nin conventional studies of user traffic patterns, such as the Sandvine\nReports' peak traffic analysis ~\\cite{sandvine20141h}.) \n\n\\begin{figure}[t]\n\\centering\n\\begin{minipage}{\\linewidth}\n\\centering\n\\includegraphics[width=.75\\linewidth]{figures/peakratio_cdf_mean-devices.pdf}\n\\caption{\\green{Distribution of the daily peak-to-average ratio per subscriber, averaged for each subscriber over the measurement period in the treatment and  control groups.}}\n\\label{fig:CDF-peak-ratio-mean}\n\\end{minipage}\n\\end{figure}\n\nFigure~\\ref{fig:CDF-peak-ratio-mean} plots the PAR for each \nsubscriber in the treatment and control groups. The median PAR\n for subscribers from the treatment group is 4.64, compared to 4.51\nfor the control group.\nWe found that 40\\% of the subscribers in both groups have PAR\ngreater than 5; the PAR of subscribers in the treatment group is higher than those in the\ncontrol group, perhaps indicating that users in both higher service tiers do\nin fact use the additional capacity for short periods of time. The\nnotable difference occurs for peak-to-average ratios of less-than 5: as\nwe observed in Section~\\ref{subsec:behavior}, \\red{subscribers with more\nmoderate (median) traffic demands tend to increase their peak demand more in\nresponse to the increased service tier.}  Again, we believe these trends\nappear not because users are necessarily eager to fill the additional\ncapacity of a higher service tier, but rather may be occurring because the upgrade\nresults in better performance, and that this improved user experience in\nturn causes these subscribers to make more use of the Internet.\n\n\\green{The lower prime-time ratio by volume, and a consistently higher\npeak-to-average ratio per subscriber} indicates the following:\nsubscribers in the treatment group have higher peak-to-average ratio than\nthose in the control group. \\green{However, these subscribers tend to still have\nlow absolute demand, so the relatively higher PAR for the treatment group does not significantly\naffect total traffic during prime-time and, when it is high, the demand\ntends to be in non-prime-time hours}.  Consistent with the results in\nSection~\\ref{subsec:primetime}, we also found that on weekdays, the\npeak-to-average ratios in the treatment group are higher than the control\ngroup, whereas on weekends peak-to-average ratios for both the control and\ntreatment groups are similar. ", "meta": {"hexsha": "26ecc47fe953b2bfe3ae74fafe23fc79c44c6753", "size": 3148, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Software-Projects/experimental/experimental--tv-data-analysis/comcast-analysis/writing/peakratio.tex", "max_stars_repo_name": "briancabbott/xtrax", "max_stars_repo_head_hexsha": "3bfcbe1c2f5c355b886d8171481a604cca7f4f16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-07T17:32:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T09:14:01.000Z", "max_issues_repo_path": "Software-Projects/experimental/experimental--tv-data-analysis/comcast-analysis/writing/peakratio.tex", "max_issues_repo_name": "briancabbott/xtrax", "max_issues_repo_head_hexsha": "3bfcbe1c2f5c355b886d8171481a604cca7f4f16", "max_issues_repo_licenses": ["MIT"], "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-Projects/experimental/experimental--tv-data-analysis/comcast-analysis/writing/peakratio.tex", "max_forks_repo_name": "briancabbott/xtrax", "max_forks_repo_head_hexsha": "3bfcbe1c2f5c355b886d8171481a604cca7f4f16", "max_forks_repo_licenses": ["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.96, "max_line_length": 262, "alphanum_fraction": 0.8046378653, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895098628499, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6559595473635258}}
{"text": "\\documentclass[letterpaper, twoside, 12pt]{book}\n\\usepackage{packet}\n\n\n\\begin{document}\n\n\\setcounter{chapter}{3}\n\n\\chapter{Packet 4.1: Sections 16.1-16.4}\n\n\\setcounter{chapter}{16}\n\\setcounter{section}{0}\n\n\\section{Vector Fields} %16.1\n\n\\begin{definition}\n  A \\textbf{vector field} assigns a vector to each point in 2D or 3D space.\n    \\[\n      \\vect{F}=\n      \\vect{F}(\\vect{r})=\n      \\vect{F}(x,y)=\n      \\<P(x,y),Q(x,y)\\>=\n      \\<P(\\vect{r}),Q(\\vect{r})\\>=\n      \\<P,Q\\>\n    \\]\n    \\[\n      \\vect{F}=\n      \\vect{F}(\\vect{r})=\n      \\vect{F}(x,y,z)=\n      \\<P(x,y,z),Q(x,y,z),R(x,y,z)\\>=\n      \\<P(\\vect{r}),Q(\\vect{r}),R(\\vect{r})\\>=\n      \\<P,Q,R\\>\n    \\]\n\\end{definition}\n\n          \\begin{problem}\n            Sketch the vector field $\\vect{F}=\\<x+y,2y\\>$ for\n            all $x\\in\\{0,1,2\\}$ and $y\\in\\{0,1,2\\}$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{remark}\n  The gradient vector function\n    \\[\n      \\nabla f (x,y)\n        =\n      \\<f_x(x,y),f_y(x,y)\\>\n    \\]\n    \\[\n      \\nabla f (x,y,z)\n        =\n      \\<f_x(x,y,z),f_y(x,y,z),f_z(x,y,z)\\>\n    \\]\n  is a vector field which yields normal vectors\n  to the level surfaces of the function $f$.\n\\end{remark}\n\n          \\begin{problem}\n            Compute $\\nabla f$ for the function\n            $f(x,y)=x^2-2xy+y$, and then\n            sketch the vector field $\\nabla f$\n            all $x\\in\\{0,1,2\\}$ and $y\\in\\{0,1,2\\}$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\section{Line Integrals} %16.2\n\n\\begin{theorem}\n  Some vector functions which parameterize curves follow.\n  \\begin{itemize}\n    \\item\n    A line segment beginning at $P_0$ and ending at $P_1$:\n      \\[\n        \\vect{r}(t) = \\vect{P_0} + t\\vect{P_0P_1}, 0\\leq t\\leq 1\n      \\]\n    \\item\n    A circle centered at the origin with radius $a$:\n      \\[\n        \\vect{r}(t) = \\<a\\cos t,a\\sin t\\>, 0\\leq t\\leq 2\\pi\n        \\text{ (full counter-clockwise rotation)}\n      \\]\n      \\[\n        \\vect{r}(t) = \\<a\\sin t,a\\cos t\\>, 0\\leq t\\leq 2\\pi\n        \\text{ (full clockwise rotation)}\n      \\]\n    \\item\n    A planar curve given by $y=f(x)$ from $(x_0,y_0)$ to $(x_1,y_1)$\n      \\[\n        \\vect{r}(t) = \\<t,f(t)\\>, x_0\\leq t\\leq x_1\n        \\text{ (left-to-right)}\n      \\]\n      \\[\n        \\vect{r}(t) = \\<-t,f(-t)\\>, -x_0\\leq t\\leq -x_1\n        \\text{ (right-to-left)}\n      \\]\n    \\end{itemize}\n\\end{theorem}\n\n          \\begin{problem}\n            Give a vector function which parameterizes the line segment\n            from the point $(0,3,-2)$ to the point $(4,-1,0)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Give a vector function which parameterizes the curve\n            $y=x^3-2x$ from the point $(1,-1)$ to the point $(-1,1)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Give a vector function which parameterizes the curve\n            $x^2+y^2=9$ from the point $(3,0)$ clockwise to the point $(0,-3)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{definition}\nThe \\textbf{line integral with respect to arclength} of a function of many\nvariables $f(\\vect{r})$ along a curve $C$ is given by\n  \\[\n    \\int_C f(\\vect{r})\\dvar{s} =\n    \\lim_{n\\to\\infty}\\sum_{i=1}^n f(\\vect{r}_{n,i})\\Delta s_{n,i}\n  \\]\nwhere for each positive integer $n$ we've defined a way to partition $C$\ninto $n$ pieces\n  \\[\n    \\Delta C_{n,1},\\Delta C_{n,2},\\dots,\\Delta C_{n,n}\n  \\]\nwhere $\\Delta C_{n,i}$ has length $\\Delta s_{n,i}$, contains the position\nvector $\\vect{r}_{n,i}$, and\n  \\[\n    \\lim_{n\\to\\infty} \\max(\\Delta s_{n,i}) = 0\n  \\]\n\\end{definition}\n\n\\begin{theorem}\nIf $\\vect{r}(t)$ is a parametrization of $C$ for $a \\leq t \\leq b$, then\n  \\[\n    \\int_C f(\\vect{r})\\dvar{s}\n    =\\int_{t=a}^{t=b} f(\\vect{r}(t))\\frac{ds}{dt}\\dvar{t}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Evaluate $\\int_C z + 2xy\\dvar{s}$ where $C$ is the line segment\n            from $(0,-1,3)$ to $(2,2,-3)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Prove that $\\int_C xy\\dvar{s}=\\int_0^1 t^3\\sqrt{1+4t^2}\\dvar{t}$\n            where $C$ is the parabolic arc\n            on $y=x^2$ from $(0,0)$ to $(1,1)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{definition}\nThe \\textbf{line integral of a vector field} $\\vect F$\nover the curve $C$ is given by\n  \\[\n    \\int_C \\vect F\\cdot\\dvar{\\vect r} =\n    \\lim_{n\\to\\infty}\\sum_{i=1}^n\n    \\vect F(\\vect{r}_{n,i})\\cdot\\Delta\\vect{C}_{n,i}\n  \\]\nwhere for each positive integer $n$ we've defined a way to approximate $C$\nwith $n$ vectors\n  \\[\n    \\Delta \\vect{C}_{n,1},\\Delta \\vect{C}_{n,2},\\dots,\\Delta \\vect{C}_{n,n}\n  \\]\nwhere $\\vect{r}_{n,i}+\\Delta \\vect{C}_{n,i}=\\vect{r}_{n,i+1}$\nand\n  \\[\n    \\lim_{n\\to\\infty} \\max(|\\Delta \\vect{C}_{n,i}|) = 0\n  \\]\n\\end{definition}\n\n\\begin{definition}\nThe line integral of a vector field $\\vect F$ over the curve $C$\nmay be computed by\n    \\[\n      \\int_C \\vect{F}\\cdot\\dvar{\\vect r}\n        =\n      \\int_C \\vect{F}\\cdot\\vect{T}\\dvar{s}\n    \\]\nwhere $\\vect T$ yields the unit tangent vectors to the curve $C$.\n\\end{definition}\n\n\\begin{definition}\nIf $\\vect{r}(t)$ is a parametrization of $C$ for $a \\leq t \\leq b$, then\n    \\[\n      \\int_C \\vect{F}\\cdot\\dvar{\\vect r}\n        =\n      \\int_{t=a}^{t=b} \\vect{F}\\cdot\\frac{d\\vect{r}}{dt}\\dvar{t}\n    \\]\n\\end{definition}\n\n          \\begin{problem}\n            Prove that\n            $\\int_C \\<2x,y-x\\>\\cdot\\dvar{\\vect{r}}\n              =\n            \\int_0^1 23t-7 \\dvar{t}$\n            where $C$ is the line segment given by the vector equation\n            $\\vect{r}(t)=\\<1-2t,3t\\>$ for $0\\leq t\\leq 1$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{remark}\n  The work done by a force vector field $\\vect{F}$ over the curve $C$\n  is given by $\\int_C\\vect{F}\\cdot\\dvar{\\vect{r}}$.\n\\end{remark}\n\n          \\begin{problem}\n            Find the work done by the force vector field\n            $\\<-3y,3x\\>$ moving a particle one rotation counter-clockwise\n            around the unit circle $x^2+y^2=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  If $C$ may be split into two curves $C_1$ and $C_2$, then\n  \\[\n    \\int_C f\\dvar{s}\n      =\n    \\int_{C_1} f\\dvar{s}\n      +\n    \\int_{C_2} f\\dvar{s}\n  \\]\n  and\n  \\[\n    \\int_C \\vect F\\cdot\\dvar{\\vect r}\n      =\n    \\int_{C_1} \\vect F\\cdot\\dvar{\\vect r}\n      +\n    \\int_{C_2} \\vect F\\cdot\\dvar{\\vect r}\n  \\]\n\\end{theorem}\n\n\\begin{theorem}\n  If $-C$ is the curve $C$ oriented in the opposite direction, then\n  \\[\n    \\int_C f\\dvar{s}\n      =\n    \\int_{-C} f\\dvar{s}\n  \\]\n  and\n  \\[\n    \\int_C \\vect F\\cdot\\dvar{\\vect r}\n      =\n    - \\int_{-C} \\vect F\\cdot\\dvar{\\vect r}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Write a paragraph explaining why a negative appears in the\n            previous theorem for the\n            line integral of a vector field but not for an arclength\n            line integral.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\section{The Fundamental Theorem for Line Integrals} %16.3\n\n\\begin{definition}\n  If $\\nabla f=\\vect{F}$, then $f$ is a \\textbf{potential function}\n  for the \\textbf{conservative field} $\\vect{F}$.\n\\end{definition}\n\n          \\begin{problem} %x^2-3yz\n            Prove that $\\<2x,-3z,-3y\\>$ is a conservative field by\n            finding a potential function $f$ for it. Hint: such an $f$\n            must satisfy that $f=x^2+\\Phi_1(y,z)$, $f=-3yz+\\Phi_2(x,z)$,\n            and $f=-3yz+\\Phi_3(x,y)$ for some functions $\\Phi_i$. (Why?)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{theorem}\n  The Fundamental Theorem for Line Integrals:\n  If $C$ is any smooth curve beginning at the point $A$ and ending at the\n  point $B$, then\n  \\[\n    \\int_C \\nabla f\\cdot \\dvar{\\vect{r}} = \\left[f\\right]_A^B = f(B)-f(A)\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove that if $C$ is any smooth \\textbf{closed curve}\n            (beginning and ending at the same point), then\n            \\[\n              \\int_C \\nabla f\\cdot \\dvar{\\vect{r}} = 0\n            \\]\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Compute $\\int_C\\<4,z^2,2yz\\>\\cdot\\dvar{\\vect r}$ where\n            $C$ is the curve given by\n            $\\vect{r}(t)=\\<2^t,\\sin (\\pi t),4t^2\\>$ for $0\\leq t\\leq 1$.\n            Then compute $\\int_{C'}\\<4,z^2,2yz\\>\\cdot\\dvar{\\vect r}$ where\n            $C'$ is the line segment starting at $(1,0,0)$ and ending\n            at $(2,0,4)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Prove that if $f$ is a potential function for the vector field\n            $\\<P,Q,R\\>$, then\n            $P_y=Q_x$, $P_z=R_x$, and $Q_z=R_y$. (Hint: use the mixed derivative\n            theorem.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{theorem}\n  $\\vect{F}=\\<P,Q,R\\>$ is a conservative vector field if and only if\n  $P_y=Q_x$, $P_z=R_x$, and $Q_z=R_y$.\n\\end{theorem}\n\n          \\begin{problem}\n            Prove that\n            $\\int_C\\<ye^{xy+z},xe^{xy+z},e^{xy+z}\\>\\cdot\\dvar{\\vect r}=0$\n            where $C$ is the curve given by\n            $\\vect{r}(t)=\\<\\frac{1}{1+t^2},\\cos t,e^{1-t^2}\\>$\n            for $-1 \\leq t \\leq 1$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\section{Green's Theorem} %16.4\n\n\\begin{theorem}\n  Let $C$ be the boundary of the region $R$ in the $xy$ plane oriented\n  counter-clockwise, and let $\\vect{F}$ be a two-dimensional vector field. Then\n  \\[\n    \\int_C \\vect{F}\\cdot\\dvar{\\vect{r}}\n      =\n    \\iint_R \\left(\\frac{\\p Q}{\\p x}-\\frac{\\p P}{\\p y}\\right)\\dvar{A}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Evaluate $\\int_C\\<x^2-y^2,x^3+y-1\\>\\cdot\\dvar{\\vect r}$ where\n            $C$ is the boundary of the unit square oriented counter-clockwise.\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 work done by a force vector field $\\<y,2x\\>$ moving an\n            object around the\n            boundary of the triangle with vertices $(1,2)$, $(-1,-2)$, and\n            $(3,-2)$ oriented clockwise.\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": "a614db99691ea812a0f57e367639489edb9e0428", "size": 11688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packet4_1.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_1.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_1.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.6063157895, "max_line_length": 80, "alphanum_fraction": 0.5293463381, "num_tokens": 3808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6559595460616476}}
{"text": "%%%this is taken form loader (1999)\n\n\\chapter{Local Regression}\nLocal regression is used to model a relation between a predictor\nvariable and response variable. To keep things simple we will consider\nthe fixed design model. We assume a model of the form\n\\[\nY_i = f(x_i) + \\varepsilon_i\n\\]\nwhere $f(x)$ is an unknown function and $\\varepsilon_i$ is an error term,\nrepresenting random errors in the observations or variability from\nsources not included in the $x_i$.\n\nWe assume the errors $\\varepsilon_i$ are IID with mean 0 and finite\nvariance $\\var(\\varepsilon_i) = \\sigma^2$. \n\nWe make no global assumptions about the function $f$ but assume that\nlocally it can be well approximated with a member of a simple class of\nparametric function, e.g. a constant or straight line. Taylor's\ntheorem says that any continuous function can be approximated with\npolynomial. \n \n\\section{Taylor's theorem}\nWe are going to show three forms of Taylor's theorem. \n\\begin{itemize}\n\n\\item This is the original. Suppose $f$ is a real function on $[a,b]$, $f^{(K-1)}$ is continuous on\n$[a,b]$,  $f^{(K)}(t)$ is bounded for $t \\in (a,b)$ then\nfor any distinct points $x_0 < x_1$ in $[a,b]$ there exist a point\n$x$ between $x_0 < x < x_1$ such that \n\\[\nf(x_1) = f(x_0) + \\sum_{k=1}^{K-1} \\frac{f^{(k)}(x_0)}{k!}(x_1-x_0)^k +\n\\frac{f^{(K)}(x)}{K!}(x_1 - x_0)^K.\n\\]\n{\\bf Notice:} if we view $f(x_0) + \\sum_{k=1}^{K-1}\n\\frac{f^{(k)}(x_0)}{k!}(x_1-x_0)^k$ as function of $x_1$, it's a\npolynomial in the family of polynomials  \n\\[\n{\\cal  P}_{K+1}= \\{f(x) = a_0 + a_1 x + \\dots + a_K x^K,\n(a_0,\\dots,a_K)' \\in {\\mathbb R}^{K+1}\\}.\n\\]\n\n\\item Statistician sometimes use what is called Young's form of Taylor's\nTheorem:\n\nLet $f$ be such that $f^{(K)}(x_0)$ is bounded for $x_0$ then\n\\[\nf(x) = f(x_0) +  \\sum_{k=1}^{K} \\frac{f^{(k)}(x_0)}{k!}(x-x_0)^k +\no(|x-x_0|^K), \\mbox{ as } |x-x_0| \\rightarrow 0.\n\\]\n{\\bf Notice:} again the first two term of the right hand side is in ${\\cal P}_{K+1}$.\n\n\n\\item In some of the asymptotic theory presented in this class we are\n  going to use another refinement of Taylor's theorem called Jackson's\n  Inequality: \n\n  Suppose $f$ is a real function on $[a,b]$ with $K$ is continuous\n  derivatives then\n  \\[\n  \\min_{g \\in {\\cal P}_k} \\sup_{x \\in [a,b]} |g(x) - f(x)| \\leq C \\left(\n    \\frac{b-a}{2k}\\right)^K \n  \\]\n  with ${\\cal P}_k$ the linear space of polynomials of degree $k$.\n\\end{itemize}\n\n\\section{Fitting local polynomials}\nWe will now define the recipe to obtain a loess smooth for a target\ncovariate $x_0$. \n\nThe first step in loess is to define a weight function (similar to the\nkernel $K$ we defined for kernel smoothers). For computational\nand theoretical purposes we will define this weight function so that\nonly values within a {\\it smoothing window} $[x_0+h(x_0),x_0-h(x_0)]$ will be\nconsidered in the estimate of $f(x_0)$.  \n\nNotice: In local regression $h(x_0)$ is called the span or bandwidth. It\nis like the kernel smoother scale parameter $h$. As will be seen a bit\nlater, in local regression, the span may depend on the target\ncovariate $x_0$.\n\nThis is easily achieved by\nconsidering  weight functions that are $0$ outside of $[-1,1]$. For example\nTukey's tri-weight function\n\\[\nW(u) = \\left\\{ \\begin{array}{cc}\n(1 - |u|^3)^3&|u| \\leq 1\\\\\n0&|u| > 1.\n\\end{array}\n\\right.\n\\]\n\nThe weight sequence is then easily defined by\n\\[\nw_i(x_0) = W \\left( \\frac{x_i - x_0}{h(x)} \\right)\n\\]\n\nWe define a window by a procedure similar to the $k$ nearest\npoints. We want to include $\\alpha\\times 100$\\% of the data. \n\nWithin the smoothing window, $f(x)$ is approximated by a\npolynomial. For example, a quadratic approximation\n\\[\nf(x) \\approx \\beta_0 + \\beta_1 (x-x_0) + \\frac{1}{2} \\beta_2 (x-x_0)^2 \\mbox{ for\n  } x \\in [x_0 - h(x_0), x_0+h(x_0)].\n\\]\nFor continuous function, Taylor's theorem tells us something about how\ngood an approximation this is.\n\nTo obtain the local regression estimate $\\hat{f}(x_0)$ we simply find\nthe $\\bb = (\\beta_0,\\beta_1,\\beta_2)'$ that minimizes\n\\[\n\\hat{\\bb} = \\arg \\min_{\\bb \\in {\\mathbb R}^3} \\sum_{i=1}^n w_i(x_0)[ Y_i - \\{\\beta_0 + \\beta_1 (x_i-x_0) + \\frac{1}{2} \\beta_2 (x_i-x_0)\\}]^2\n\\]\nand define $\\hat{f}(x_0) = \\hat{\\beta}_0$.\n\nNotice that the Kernel smoother is a special case of local\nregression. Proving this is a Homework problem.\n\n\\section{Defining the span}\nIn practice, it is quite common to have the $x_i$ irregularly\nspaced. If we have a fixed span $h$ then one may have local estimates\nbased on many points and others is very few. For this reason we may\nwant to consider a nearest neighbor strategy to define a span for\neach target covariate $x_0$.\n\nDefine $\\Delta_i(x_0) = |x_0 -\nx_i|$, let $\\Delta_{(i)}(x_0)$ be the ordered values of such\ndistances. One of the arguments in the local regression function {\\tt\n  loess()} (available in the modreg library) is the {\\tt span}. A span\nof $\\alpha$ means that for each local fit we want to use\n $\\alpha \\times 100 \\%$ of the data.  \n\nLet $q$ be equal to $\\alpha$n\ntruncated to an integer. Then we define the span $h(x_0) =\n\\Delta_{(q)}(x_0)$. As $\\alpha$ increases the estimate\nbecomes smoother. \n\nIn Figures \\ref{f3.1} -- \\ref{f3.3} we see loess smooths for the CD4\ncell count data using spans of\n0.05, 0.25, 0.75, and 0.95. The smooth presented in the Figures are\nfitting a constant, line, and parabola\nrespectively.\n\n\n\\begin{figure}[htp]\n\\caption{\\label{f3.1} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-03-01.ps,width=\\textwidth}}\n\\end{figure}\n\n\\begin{figure}[htp]\n\\caption{\\label{f3.2} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-03-02.ps,width=\\textwidth}}\n\\end{figure}\n\n\\begin{figure}[htp]\n\\caption{\\label{f3.3} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-03-03.ps,width=\\textwidth}}\n\\end{figure}\n\n\n\\newpage \n\n\\section{Symmetric errors and Robust fitting}\nIf the errors have a symmetric distribution (with long tails), or if\nthere appears to be \noutliers we can use robust loess.\n\n\nWe begin with the estimate described above $\\hat{f}(x)$. The residuals\n\\[\n\\hat{\\varepsilon}_i = y_i  - \\hat{f}(x_i)\n\\]\nare computed.\n\nLet\n\\[\nB(u;b) = \\left\\{ \\begin{array}{cc}\n\\{1 - (u/b)^2\\}^2&|u|<b\\\\\n0& |u|\\geq b\n\\end{array}\n\\right.\n\\]\nbe the bisquare weight function. Let $m$ = median($|\\hat{\\varepsilon}_i|$).\nThe robust weights are\n\\[\nr_i = B(\\hat{\\varepsilon_i}; 6m)\n\\]\nThe local regression is repeated but with new weights $r_i w_i(x)$. The\nrobust estimate is the result of repeating the procedure several times.\n\nIf we believe the variance $\\var(\\varepsilon_i) = a_i \\sigma^2$ we could\nalso use this double-weight procedure with $r_i = 1/a_i$.\n\n\\subsection{Example}\n\nRadiolabeling based gene expression measurements are useful for cancer\nresearch because they can be carried out using small amounts of\nbiological materials.  \nStatistical issues are different from fluorescence\nexpression data, because radiolabeling gives absolute intensities that\nreflect gene expression and \nthere is no internal control. \n\nThe data-set described here was obtained to identify genes that\nmay be associated with lung cancer. Lung cancer tissue was obtained\nfrom various subjects. Normal tissues from the same type of cells was\nobtained from those same subjects. From each of   \nthese tissues 2 samples were prepared using 2 different isotopic\nbatches. Each of these 4 samples were hybridized with a filter\nspotted with cDNA from many genes in a $48 \\times 24$ grid. We refer\nto these spotted filters as arrays. Each of these arrays were scanned to\nproduce an image file \nwhich was then analyzed with \nspecialized software that produced an intensity level for each grid\npoint or {\\it spot} on the array. \n\nNot all the values read  from the arrays are associated with\ngenes. There were 207 spots where\nno cDNA was spotted. They were left empty. Because there is {\\it\n  non-specific} binding between the samples and the filters, positive\nvalues are \nobtained from these empty spots. The intensities read \nfrom these empty spots provide direct evidence about measurement error\nassociated with the system. Spots associated with genes that are not\nexpressed will also have intensities due to non-specific binding.\n\n\nCan we rank genes by differential expression between\ncancer and normal tissues in each subject? \n\nIf we denote with $\\bx$ and $\\by$ the log intensities of each spot we\ncould say a gene is differentially expressed if $\\by - \\bx$ is\nsignificantly bigger than 0 for the spot related to that gene.\nOne problem with this is that there is a filter effect, so $\\by$ can\nbe systematically smaller than $\\bx$.\n\nA common procedure in microarray data analysis is to simply normalize the\nfilters by subtracting the mean of each filter from each value,\ni.e. consider $y^{(normalized)}_{i} =  y_{i} -\n\\bar{y}$ and similarly for the $x$s. The danger with doing\nthis is that many of the genes spotted on the arrays are usually\nselected because researchers consider them likely to be\nover-expressed. This means \nthat the mean of the $y$s should be larger than the $x$s and this\ndifference in mean is confounded with the difference in filter\neffect. By subtracting means we would be subtracting out some of the\ndifferential expression between cancer and normal\ntissues. \n\nIn Figure \\ref{f3.4} we plot the ratio of the intensities vs. the\nproduct of the \nintensities in a log scale, i.e. $y-x$ vs. $x + y$, for the two\nreplicates of subject 1. Notice that the\n{\\it filter effect} seems to change with the total intensity of a\nparticular spot. For this reason using medians or trimmed\nmeans to remove the filter effect is not a good solution. If we model $x$\nand $y$ as random \nvariables then we have that the expected filter effect depends on the\ntotal intensity, i.e. $\\mbox{E}(y - x | x+y )$ is not constant.\nThis arises because\nspecific binding and non-specific binding are two different natural\nprocesses. Because we have no way of knowing which points represent\nnon-specific binding and which represent specific binding we cannot\nnormalize by just estimating two means. Rather, we estimate\n$\\mbox{E}(y-x|y+x)$ using loess. It is critical to use a robust loess,\nso that large differences do not affect the fit too much. Notice in\nFigure \\ref{f3.4} the difference in the robust and non-robust\nestimates.\n\n\n\\begin{figure}[htp]\n\\caption{\\label{f3.4} Total intensity plotted against ratio with a\n  loess prediction using Gaussian and symmetric kernel.}\n\\centerline{\\epsfig{figure=Plots/plot-03-04.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n\n\n\n\n\\section{Multivariate Local Regression}\nBecause Taylor's theorems also applies to multidimensional functions it\nis relatively straight forward to extend local regression to cases\nwhere we have more than one covariate. For example if we have a\nregression model for two covariates\n\\[\nY_i = f(x_{i1},x_{i2}) + \\varepsilon_i\n\\]\nwith $f(x,y)$ unknown. Around a target point $\\bx_0 = (x_{01},x_{02})$\na  local quadratic approximation is now \n\\[\nf(x_1,x_2) \\approx \\beta_0 + \\beta_1 (x_1 - x_{01}) + \\beta_2 (x_2 - x_{02})\n+ \\beta_3 (x_1 - x_{01})(x_2 - x_{02}) + \\frac{1}{2} \\beta_4 (x_1 -\nx_{01})^2 +  \\frac{1}{2} \\beta_5(x_2 -\nx_{02})^2  \n\\]\n\nOnce we define a distance, between a point $\\bx$ and\n$\\bx_0$, and a span $h$ we can define define waits as in the previous\nsections:\n\\[\nw_i(\\bx_0) = W\\left(\\frac{||\\bx_i,\\bx_0||}{h}\\right).\n\\]\nIt makes sense to re-scale $x_1$ and $x_2$ so we smooth the same way\nin both directions. This can be done through the distance function,\nfor example by defining a distance for the space ${\\mathbb R}^d$ with\n\\[\n||\\bx ||^2 = \\sum_{j=1}^d (x_j/v_j)^2\n\\]\nwith $v_j$ a scale for dimension $j$. A natural choice for these $v_j$\nare the standard deviation of the covariates.\n\nNotice: We have not talked about k-nearest neighbors. As we will see in\nChapter VII the {\\it curse of dimensionality} will make this hard.\n\n\\subsection{Example}\nWe look at part of the data obtained from a study by Socket\net. al. (1987) on\nthe factors affecting patterns of insulin-dependent diabetes mellitus\nin children. The objective was to investigate the dependence of the\nlevel of serum C-peptide on various other factors in order to\nunderstand the patterns of residual insulin secretion. The response\nmeasurement is the logarithm of C-peptide concentration (pmol/ml) at\ndiagnosis, and the predictors are age and base deficit, a measure of\nacidity. In Figure \\ref{f3.5} we show a loess two dimensional\nsmooth. Notice that the effect of age is clearly non-linear.\n\n\\begin{figure}[htp]\n\\caption{\\label{f3.5} Loess fit for predicting C.Peptide from  Base.deficit and Age.}\n\\centerline{\\epsfig{figure=Plots/plot-03-05.ps,width=.7\\textwidth}}\n\\end{figure}\n\n\n\\input{references-03}", "meta": {"hexsha": "6b723cde50fa1451fb509ccd3c6d247a88ea79d6", "size": 12766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-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-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-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": 38.2215568862, "max_line_length": 141, "alphanum_fraction": 0.7304558985, "num_tokens": 3840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6559595460616476}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Classification}\n\\label{chap:class}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Logistic Regression}\n\\label{class:logistic}\n\nLogistic regression is a simple method to create a classifier,\ntypically on two classes $y = 0,1$, though multinomial extensions exist.\nIts name comes from the use of the logit, or log-odds, function\n\n\\begin{equation}\\label{eq:logistic:logic}\nl = \\text{logit}\\left(p\\right) = \\log\\left(\\frac{p}{1-p}\\right)\n\\end{equation}\n\n\\noindent on the probability $p$ of class $1$.\n$l$ is estimated linearly from $n$ input features $x_{j}$ with $n+1$ parameters $\\beta_{j}$ as:\n\n\\begin{equation}\\label{eq:logistic:logicBeta}\nl = \\beta_{0} + \\sum_{j=1}^{n} \\, \\beta_{j}\\,x_{j}\\,.\n\\end{equation}\n\n\\noindent The probability $p$ is then\n\n\\begin{equation}\\label{eq:logistic:p}\np = \\frac{e^l}{e^l + 1} = \\frac{1}{1+e^{-l}} = \\text{logit}^{-1}\\left(l\\right)\n\\end{equation}\n\n\\noindent which can be turned into a predicted class through the choice of a suitable decision threshold.\n\nThe model parameters $\\vb*{\\beta}$ are chosen by maximizing\nthe log of the likelihood $L$ \\cref{eq:logistic:L} over $m$ known example points $\\vb{x}_{i}, y_{i}$.\nNote that $P\\left(y \\mid x\\right)$ \\cref{eq:logistic:Pr} is simply the Bernoulli distribution.\nIn practice the log-likelihood $\\log\\left(L\\right)$ is maximized via gradient descent.\nAn example of logistic regression can be found in \\cref{fig:logistic_regression_ex}.\n\n\\begin{subequations} \\label{eq:logistic:L_Pr}\n\\begin{align}\nL\\left(\\vb*{\\beta} \\mid \\vb{x}\\right) &= \\prod_{i=1}^{m} \\, P\\left(y_{i} \\mid \\vb{x}_{i};\\,\\vb*{\\beta}\\right) \\label{eq:logistic:L} \\\\\nP\\left(y \\mid \\vb{x}\\right) &= p^y\\left(1-p\\right)^{1-y}, \\quad y \\in \\{0, 1\\} \\label{eq:logistic:Pr}\n\\end{align}\n\\end{subequations}\n\n\\begin{figure}\n\\centering\n% \\includegraphics[width=0.8\\textwidth]{figures/regression/Exam_pass_logistic_curve.jpeg}\n\\includegraphics[width=0.7\\textwidth]{figures/regression/logistic-regression-probabilities-curve.png}\n\\caption{\n% Example logistic regression curve on one input feature, by \\href{https://en.wikipedia.org/wiki/File:Exam_pass_logistic_curve.jpeg}{Michaelg2015}.\nExample logistic regression curve on one input feature, by \\href{http://www.sthda.com/english/articles/36-classification-methods-essentials/151-logistic-regression-essentials-in-r/}{Kassambara}.\n}\n\\label{fig:logistic_regression_ex}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Assumptions}\n\\label{class:logistic:assumptions}\n% TODO\n\n% TODO any more assumptions?\nSome assumptions of the logistic regression approach are:\n\\begin{enumerate}[noitemsep]\n  \\item $y$ is either present or absent (dichotomous).\n  \\item There are minimal correlations between the $x_{j}$ features (no multicollinearity).\n  \\item There are no major outliers in the data.\n\\end{enumerate}\n\n% TODO pseudo R2, Wald statistic\n% TODO regularized versions?\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Example}\n\\label{class:logistic:example}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{N{a\\\"i}ve Bayes Classification}\n\\label{class:Bayes}\n% TODO\n% TODO maximum a posteriori (italics) probability (MAP) estimator\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Gaussian N{a\\\"i}ve Bayes Classification (GNB)}\n\\label{class:Bayes:GNB}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Support Vector Machines (SVM)}\n\\label{class:SVM}\n\nBasic support vector machines (SVM) work by finding a hyperplane in the $n$-dimensional\nfeature space of the training data which best separate the different classes.\nThis is done by maximizing the margin, $2/\\norm{\\vb{w}}$,\naround the hyperplane defined by $\\innerproduct{\\vb{w}}{\\vb{x}} - b = 0$,\nwhere $\\innerproduct{\\vb{a}}{\\vb{b}}$ is the inner product.\nFor the separable case, as shown in \\cref{fig:svm_sep}, this\ncan be done by minimizing $\\norm{\\vb{w}}$, with the hard-margin condition that\n$y_{i} \\left(\\innerproduct{\\vb{w}}{\\vb{x}_{i}} - b\\right)$ for all $1 \\leq i \\leq m$.\n\nHowever, in reality the data are frequently inseparable and we must switch\nto a soft-margin objective function \\cref{eq:svm:soft_margin_obj}.\nA hinge loss function is included to penalize points on the ``wrong'' side of the margin\nproportionally to their distance from the margin.\nHere the $\\lambda$ hyperparameter sets the tradeoff between\nmargin size and ensuring points land on their correct sides.\n\n\\begin{equation} \\label{eq:svm:soft_margin_obj}\nS\\left(\\vb{w}, b\\right) =\n\\lambda\\, \\norm{\\vb{w}}^{2}\n+ \\frac{1}{m} \\sum_{i=1}^{m} \\,\n\\max{\\big(0,\\, 1 - y_{i} \\left(\\innerproduct{\\vb{w}}{\\vb{x}_{i}} - b\\right)\\big)}.\n\\end{equation}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.42\\textwidth]{figures/ml/svm_margin.png}\n\\vspace{0.2cm}\n\\caption{\nIllustration of the SVM method in the separable case,\nby \\href{https://en.wikipedia.org/wiki/File:SVM_margin.png}{Larhmam}.\nThe trained hyperplane in red separates the two classes by the largest margin.\nThe data points on the margin boundary with black boarders\nare known as support vectors, since out of all the data\nthey are the points really fixing the hyperplane and margin.\n}\n\\label{fig:svm_sep}\n\\end{figure}\n\nTo gain better performance still, we can recast the problem in\na new higher dimensional space where the classes may be easier to separate with a hyperplane.\nFortunately, we don't even need to fully specify the new space,\njust a non-linear kernel function\\footnote{Common kernel choices include\npolynomials of the inner product,\nthe Gaussian radial basis function,\nand the hyperbolic tangent.} $k\\left(\\vb{a},\\vb{b}\\right)$\nin place of the standard inner product. This is known as the kernel trick.\nThe classification boundary in the original feature space can then become non-linear,\nas can be seen in \\cref{fig:svm_kernel_trick}.\n\n\\vspace{-0.3cm}% TODo hard coded to fit on one page\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth,trim={4.0cm 0.8cm 4.0cm 1.4cm},clip]{figures/ml/kernel_trick_example.png}% trim={<left> <lower> <right> <upper>}\n\\caption{\nGraphical example of the kernel trick, by \\href{https://en.wikipedia.org/wiki/File:Kernel_trick_idea.svg}{Shiyu Ji}.\nHere the kernel $k\\left(\\vb{a},\\vb{b}\\right) = \\innerproduct{\\vb{a}}{\\vb{b}} + \\norm{\\vb{a}}^{2} \\norm{\\vb{b}}^{2}$\ntransforms the red and purple classes, linearly inseparable in $n=2$ dimensions on the left,\nto a separable $3$-dimensional space on the right.\n}\n\\label{fig:svm_kernel_trick}\n\\end{figure}\n\nIn practice minimizing $S\\left(\\vb{w}, b\\right)$ can be\nperformed more readily by instead solving the Lagrangian dual problem,\nwhich is computationally efficient to solve with quadratic programming algorithms.\nOther modern techniques developed to tackle large and sparse data include\nsub-gradient methods and coordinate descent\\footnote{Sub-gradient methods work better for large $m$,\ncoordinate descent for large $n$.}.\nHowever, compared to other classifiers SVM training times\ntend to slow significantly for large datasets,\nin \\sklearn\\footnote{See the\n\\href{https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html}{documentation}\nfor \\texttt{sklearn.svm.SVC}.\n\\texttt{LinearSVC} may be faster.\nThe best performance I've seen quoted is $\\order{n m \\log{\\left(m\\right)}}$.} by\nat least $\\order{m^{2}}$, limiting $m \\sim \\num{e4}$.\n\n%\\begin{figure}[H]\n%  \\centering\n%  \\begin{subfigure}[b]{0.48\\textwidth}\\centering\n%      \\includegraphics[width=\\textwidth]{figures/ml/svm_separable}\n%  \\caption{Separable}\n%  \\label{fig:svm:separable}\n%  \\end{subfigure}\n%  ~\n%  \\begin{subfigure}[b]{0.48\\textwidth}\\centering\n%      \\includegraphics[width=\\textwidth]{figures/ml/svm_nonseparable}\n%  \\caption{Nonseparable}\n%  \\label{fig:svm:nonseparable}\n%  \\end{subfigure}\n%\\caption{\n%Illustrations of SVMs in the separable and nonseparable case \\cite{HastieTF09}.\n%\\label{fig:svm}\n%}\n%\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Decision Trees, \\texorpdfstring{\\ie}{ie} Classification and Regression Trees (CART)}\n\\label{class:CART}\n\nA basic classifier can be created from a tree of selections on $\\mathbf{X}$ designed to\nseparate the classes at each branch.\nSuch a model is known as a classification and regression tree (CART) \\cite{Breiman:2253780}\nand a simple example can be found in \\cref{class:CART:small_example_CART}.\nAs the splits are just selections on the input variables,\nthey are --- somewhat --- possible to understand,\nand conveniently do not need any kind of feature scaling, unlike other methods.\nTo make a prediction for an event the tree and its branches are traversed\nuntil the event lands in one of the weighted leaves.\nThe weight of the leaf $w$ is positive (negative) for signal-like (background-like) events.\nA logistic function is used to properly transform $w$ into an output score\n$\\yhat = 1 /\\left(1+e^{-w}\\right)$ within $0 < \\yhat < 1$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/ml/tree7_g2000_n1200}\n\\caption{\nSimple classification and regression tree (CART).\nSignal-like (background-like) events receive positive (negative) weights in the leaves.\n}\n\\label{class:CART:small_example_CART}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Gini Impurity}\n\\label{class:CART:gini}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Boosted Decision Trees (BDT)}\n\\label{class:BDT}\n\nIndividual CARTs are rather poor and limited models\nin terms of the behaviors they can successfully predict.\nHowever, by taking an ensemble of $K$ complementary trees, \\ie boosting \\cite{FREUND1997119,friedman2000},\nand summing each CART's individual weight $w_{k}$ a much more flexible BDT\\footnote{As the leaf weights\nare reals rather than integer classes this approach may be better described as a boosted regression tree,\nand can indeed handle regression problems without the logistic function.} is formed.\nThe component trees of a BDT are generated by iteratively adding new trees $f_{k}\\left(x_{i}\\right)$ to those which came before \\cite{XGBoost},\n\n\\begin{equation} \\label{eq:boosting}\n\\begin{aligned}\n\\yhat^{\\left(0\\right)} &= 0\\,, \\\\\n\\yhat^{\\left(1\\right)} &= f_1\\left(\\mathbf{X}\\right) = \\yhat^{\\left(0\\right)} + f_1\\left(\\mathbf{X}\\right), \\\\\n\\yhat^{\\left(2\\right)} &= f_1\\left(\\mathbf{X}\\right) + f_2\\left(\\mathbf{X}\\right)= \\yhat^{\\left(1\\right)} + f_2\\left(\\mathbf{X}\\right), \\\\\n                           &\\vdotswithin{\\displaystyle =} \\\\\n\\yhat^{\\left(t\\right)} &= \\sum_{k=1}^t f_k\\left(\\mathbf{X}\\right)= \\yhat^{\\left(t-1\\right)} + f_t\\left(\\mathbf{X}\\right),\n\\end{aligned}\n\\end{equation}\n\n\\noindent where each tree $f_{k}$ is grown from zero branches while minimizing $S\\left(\\beta\\right)$.\nThrough the ingenious use of a second order Taylor expansion this process can\nbe recast as a form of gradient descent, and thus is known as\nstochastic gradient boosting \\cite{10.2307/2699986,FRIEDMAN2002367}.\nThe number of boosting rounds, and thus trees, $K$ can be chosen in advance\nbut is better optimized during the training process via early stopping.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{\\xgboost}% would rather have the \\textsc caps than italics\n\\label{class:BDT:xgboost}\n% TODO see https://towardsdatascience.com/boosting-algorithm-xgboost-4d9ec0207d\n% TODO how does the Hessian come into play\n\nThe \\xgboost\\footnote{\\xgboost: eXtreme Gradient Boosting, \\href{https://github.com/dmlc/xgboost}{github.com/dmlc/xgboost}.} library \\cite{XGBoost}\nis a modern open source implementation of gradient boosted decision tree methods.\nThrough various algorithmic and memory optimizations \\xgboost demonstrates good performance\\footnote{\\xgboost has lost\nits lead in recent years to newer libraries such as LightGBM \\cite{LightGBM}\nand CatBoost \\cite{CatBoost}.}.\nL1 and L2 regularization is incorporated via\n\n\\begin{equation} \\label{eq:bdt_omega_reg}\n\\Omega\\left(f\\right) = \\alpha T + \\frac{1}{2}\\lambda \\sum_{j=1}^T w_j^2\\,,\n\\end{equation}\n\n\\noindent where $T$ is the number of leaves in a tree and $w_{j}$ are the leaf weights;\nhowever, the default hyperparameters $\\alpha=0$ and $\\lambda=1$ only enable L2 regularization.\nOther important hyperparameters in \\xgboost include the\nlearning rate $\\eta$, which scales the corrections added by each new tree,\nmaximum tree depth, which sets a limit on the complexity of any tree via its depth,\nand the early stopping validation threshold.\nFor reference $\\eta=0.3$ and a maximum depth of 6 are the default values.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{AdaBoost}\n\\label{class:BDT:AdaBoost}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Random Forest}\n\\label{class:RF}\n% TODO\n\n% TODO best results occur when you chose $\\sqrt{n}$ features randomly to build each tree\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{\\texorpdfstring{$k$}{k}-Nearest Neighbors (\\texorpdfstring{$k$}{k}-NN)}\n\\label{class:kNN}\n% TODO\n% TODO \\kNN\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Artificial Neural Networks (NN)}\n\\label{class:ANN}\n% TODO\n\n% TODO add back prop somewhere, here or in grad descent\n\n\\begin{figure}[H]\n  \\centering\n  \\begin{subfigure}[b]{0.48\\textwidth}\\centering\n      \\includegraphics[width=\\textwidth]{figures/ml/NN_diagram/NN_diagram}\n  \\caption{NN Example}\n  \\label{fig:NN:ex}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[b]{0.48\\textwidth}\\centering\n      \\includegraphics[width=\\textwidth]{figures/ml/NN_neuron/NN_neuron}\n  \\caption{Neuron}\n  \\label{fig:NN:Neuron}\n  \\end{subfigure}\n\\caption{\nIllustrations of the components of a neural network.\n\\label{fig:NN}\n}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Recursive Neural Networks (RNN)}\n\\label{class:RNN}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Long Short Term Memory (LSTM)}\n\\label{class:RNN:LSTM}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Convolutional Neural Networks (CNN)}\n\\label{class:CNN}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Learning Vector Quantization (LVQ)}\n\\label{class:kNN:LVQ}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Addressing Class Imbalance}\n\\label{class:imbalance}\n% TODO\n", "meta": {"hexsha": "f6f83f3fc13d75ba5b1700aa7597729a8be09d92", "size": 15237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/class.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/class.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/class.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": 42.6806722689, "max_line_length": 194, "alphanum_fraction": 0.6526875369, "num_tokens": 4061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6558903444553016}}
{"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 24, 2014}\n\\maketitle\n\\section*{assignment}\nassignment 3.1 no 23, 3.2no 3,6,7\n\nif $(G,\\cdot), a\\in G$ then the cyclic subgroup generated by a is $<a>=\\{\\dots,a^{-2},a^{-1},e,a,a^2,a^3,\\dots\\}\\subseteq G$.\n\n$<a>$ is a subgroup of $G$ and if $H$ is a subgroup of $G$ and $a\\in H$ then $<a>\\subseteq H$, hence $<a>$ is the smallest subgroup of $G$\n\nexample: $(\\mathbb{Z},+)\\to <n>=n\\mathbb{Z}$\n\n$<1>=<-1>=\\mathbb{Z}$\n\nwe say that the group $G$ is cyclic if there exists $a\\in G$ such that $<a>=G$. So $(\\mathbb{Z},+)$ is cyclic because $<1>=\\mathbb{Z}$\n\nanother example $(\\mathbb{Z}_n,+)$, $<[1]>=\\mathbb{Z}_n$.\n\n\\section*{definition}\nif there exists $n>0, n\\in\\mathbb{Z}$ such that $a^n=e$ we say that a has finite order and $\\text{ord}(a)=\\min\\{n|n>0,n\\in\\mathbb{Z},a^n=e\\}$. otherwise it has infinite order \n\n\\subsection*{proposition}\nif $G$ is a finite group, $a\\in G$ then $a$ has finite order. $\\{e,a,a^2,a^3,\\dots\\}\\in G$. Since $G$ is finite, we have some m,n where $a^m=a^n$ wlog $m>n$, $a^ma^-n=a^na^-n=e=a^{m-n}$\n\\section*{examples}\n$(\\mathbb{Q}^*,\\cdot)$, $\\text{ord}(-1)=2, \\text{ord}(1)=1, \\text{ord}(2)=\\infty$\n\\subsubsection*{proof for proposition3.2.8ii}\nuse division algorithm, $k=ord(a)\\cdot q+r$ with $0\\le r<ord(a)$\n\nthen $e=a^k=a^{ord(a)q+r=[a^{ord(a)}]^{q}}a^r=a^r$\n\nexcercise, complete this proof\n\\end{document}\n\n", "meta": {"hexsha": "a6fffcab47bc0214aeda30b64b08b0ea367dc4cd", "size": 1576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-09-24.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-24.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-24.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.0222222222, "max_line_length": 185, "alphanum_fraction": 0.644035533, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.6558903396646111}}
{"text": "\\documentclass{article}\n\n\\newcommand{\\implies}{\\Rightarrow}\n\\newcommand{\\have}{{.~}}\n\\newcommand{\\bstate}{{\\mbox{\\cal S}}}\n\\newcommand{\\blocks}{{\\mbox{\\cal B}}}\n\\newcommand{\\tabtop}{{\\mbox{\\sc t}}}\n\\newcommand{\\tblocks}{{\\blocks_\\tabtop}}\n\n\\begin{document}\n\n\\section{Preliminaries}\n\n\\begin{itemize}\n\\item Let\n  $$ \\blocks = \\{ 1 \\ldots N \\} $$\nrepresent a set of $N$ blocks in a blocks-world problem.\nWe represent the tabletop with the symbol $\\tabtop$, and\nlet\n  $$ \\tblocks = \\blocks \\cup \\{ \\tabtop \\} $$\n  \n\\item Call any \n  $$ \\bstate \\subseteq \\blocks \\times \\tblocks $$\na {\\em state} of the blocks-world problem. The pairs of blocks in\n$\\bstate$ represent {\\em on} relations.\n\n\\item A state $\\bstate$ is {\\em legal} iff\n  \\begin{itemize}\n  \\item  Every block is on something: $$\n    \\forall i \\in \\blocks \\have\n      \\exists j \\in \\tblocks \\have\n\t\\langle i , j \\rangle \\in \\bstate\n  $$\n  \\item No block is on two things: $$\n    \\forall i \\in \\blocks \\have\n      \\langle i , j \\rangle \\in \\bstate \\implies\n      \\not \\exists j' \\in \\tblocks \\have\n\tj \\neq j' \\wedge \\langle i , j' \\rangle \\in \\bstate\n  $$\n  \\item No two blocks are on the same block: $$\n    \\forall j \\in \\blocks \\have\n      \\langle i , j \\rangle \\in \\bstate \\implies\n      \\not \\exists i' \\in \\blocks \\have\n\ti \\neq i' \\wedge \\langle i' , j \\rangle \\in \\bstate\n  $$\n  \\end{itemize}\n  \n\\item A block $j$ is {\\em clear} in a legal state $\\bstate$ iff no block is above it:\n  $$ \\not \\exists i \\in \\blocks \\have \\langle i , j \\rangle \\in \\bstate $$\n\n\\item A block $i$ is {\\em above} a block $i'$ in a legal\nstate $\\bstate$ if there is a sequence\nof blocks whose {\\em on} relationships lead from $i$ to $i'$: $$\n  \\exists \\{ j_1 , j_2 , \\ldots , j_k \\} \\subseteq \\blocks \\have\n    \\{ \\langle i , j_1 \\rangle , \\langle j_1 , j_2 \\rangle ,\n       \\ldots , \\langle j_k , i' \\rangle \\} \\subseteq \\bstate\n$$\n\n\\item A legal state $\\bstate$ is {\\em realizable} iff no block\nis above itself.\n\n\\item {\\em Moves} are functions $m_{ij}$ which take a realizable state in\nwhich blocks $i$ and $j$ are clear to a\nrealizable state in which $i$ is on $j$.\n\nLet $i \\in \\blocks$ and $j \\in \\tblocks$, and let $C(ij)$ be the set\nof realizable states\nin which $i$ is clear, and either $j = \\tabtop$ or $j$ is clear.\nThen the domain of $m_{ij}$ is\n$C(ij)$, and the range is the set of realizable states.\nDefine the functions $\\theta_i(\\bstate)$ mapping legal states to\nblocks to have the value $j$\nsuch that $\\langle i, j \\rangle \\in \\bstate$.\nBy the definition of a legal state, these functions are well-defined.\nWe then define\n$m_{ij}$ by $$\n  m_{ij}(\\bstate) =\n    \\left ( \\bstate - \\{ \\langle i, \\theta_i(\\bstate) \\rangle \\} \\right )\n    \\cup \\{ \\langle i, j \\rangle \\}\n$$\n\n\\item A blocks world {\\em problem} consists of two realizable states: an\ninitial state $I$ and a goal state $G$.  A {\\em solution} consists of\na sequence of pairs $$\n  \\langle i_1, j_1 \\rangle , \\langle i_2 , j_2 \\rangle , \\ldots ,\n  \\langle i_k , j_k \\rangle \\in \\left ( \\blocks \\times \\tblocks \\right ) ^ \\ast\n$$\nsuch that $$\n  \\left ( m_{i_k j_k} \\circ \\cdots \\circ m_{i_2 j_2} \\circ\n  m_{i_1 j_1} \\right ) (I) = G\n$$\n\\end{itemize}\n\n\\section{Move Restriction}\n\n\n\\end{document}\n", "meta": {"hexsha": "939ccbb9128403e7889a328ad9a1eb7392c0b87d", "size": 3205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thm/bak/thm-0.tex", "max_stars_repo_name": "BartMassey/blocks", "max_stars_repo_head_hexsha": "6dbb39186595b6e2b80c9a5dcd616056f6cb3117", "max_stars_repo_licenses": ["MIT"], "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/thm/bak/thm-0.tex", "max_issues_repo_name": "BartMassey/blocks", "max_issues_repo_head_hexsha": "6dbb39186595b6e2b80c9a5dcd616056f6cb3117", "max_issues_repo_licenses": ["MIT"], "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/thm/bak/thm-0.tex", "max_forks_repo_name": "BartMassey/blocks", "max_forks_repo_head_hexsha": "6dbb39186595b6e2b80c9a5dcd616056f6cb3117", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-15T18:45:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-15T18:45:13.000Z", "avg_line_length": 32.7040816327, "max_line_length": 85, "alphanum_fraction": 0.6427457098, "num_tokens": 1106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6558333053020263}}
{"text": "% 19 April 1993 mg\n\\chapter{Catalog of Program packages and entries}\n\\section*{Arithmetic Routines}\n\\begin{DLtt}{12345678901}\n\\item[A105 MPA] Multiple-Precision Floating-Point Arithmetic\n\\end{DLtt}\n\\section*{Elementary Functions}\n\\begin{DLtt}{12345678901}\n\\item[B100 BINOM] Binomial Coefficient\n\\item[B101 ATG] Arc Tangent Function\n\\item[B102 ASINH] Hyperbolic Arcsine\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 ZEROX] Zero of a Function of One Real Variable\n\\item[C201 SNLEQ] 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 RTEQ3] Roots of a Cubic Equation\n\\item[C208 RTEQ4] 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 DILOG] Dilogarithm Function\n\\item[C306 CGAMMA] Complex Gamma Function\n\\item[C307 CDIGAM] Complex Digamma or Psi Function\n\\item[C309 CCLBES] Coulomb Wave, Bessel, and Spherical Bessel Functions for Complex Argument(s) and Order\n\\item[C310 ALGAMA] Logarithm of the Gamma Function\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 Zero and One\n\\item[C315 RRIZET] Riemann Zeta Function\n\\item[C316 RPSIPG] Psi (Digamma) and Polygamma Functions\n\\item[C318 ELFUN] Jacobian Elliptic Functions sn, cn, dn\n\\item[C320 CELFUN] Jacobian Elliptic Functions sn, cn, dn for Complex Argument\n\\item[C321 CGPLG] Nielsen's Generalized Polylogarithm\n\\item[C322 FRSIN] Fresnel Integrals\n\\item[C323 FERDR] Fermi-Dirac Function\n\\item[C324 ATANI] Arctangent integral\n\\item[C327 BSIR4] Modified Bessel Functions I and K of Order 1/4, 1/2 and 3/4\n\\item[C328 CWHITM] Whittaker Function M of Complex Argument and Complex Indices\n\\item[C330 ASLGF] Legendre and Associated Legendre Functions \n\\item[C331 FCONC] Conical Functions of the First Kind\n\\item[C333 CLOGAM] Logarithm of the Complex Gamma Function\n\\item[C334 GAPNC] Incomplete Gamma Functions\n\\item[C335 CWERF] Complex Error Function\n\\item[C336 SININT] Sine and Cosine Integrals\n\\item[C337 EXPINT] Exponential Integral\n\\item[C338 CEXPIN] Complex Exponential Integral\n\\item[C339 DAWSON] Dawson's Integral\n\\item[C340 BSIR3] Modified Bessel Functions I and K of Order 1/3 and 2/3\n\\item[C342 STRH0] Struve Functions of Orders Zero and One\n\\item[C343 BSJA] Bessel Functions J and I with Positive Argument and Non-Integer Order\n\\item[C344 CBSJA] Bessel Functions J with Complex Argument and Non-Integer Order\n\\item[C345 BZEJY] 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, Second, 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[D103 GAUSS] Adaptive Gaussian Quadrature\n\\item[D104 CAUCHY] Cauchy Principal Value Integration\n\\item[D105 TRIINT] Integration over a Triangle\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[D111 GPINDP] General Purpose Integration in Double-Precision\n\\item[D113 CGAUSS] Adaptive Complex Integration Along a Line Segment\n\\item[D114 RIWIAD] Adaptive Multidimensional Monte-Carlo Integration \n\\item[D115 CHEBQU] Double-Precision Clenshaw-Curtis Integration\n\\item[D151 DIVON4] Multidimensional Integration or Random Number Generation\n\\item[D200 RKSTP] First-order Differential Equations (Runge-Kutta)\n\\item[D201 DEQBS] First-order Differential Equations (Gragg--Bulirsch--Stoer)\n\\item[D202 DEQMR] First-order Differential Equations (Runge--Kutta--Merson)\n\\item[D203 RKNYS] Second-order Differential Equations (Runge--Kutta--Nystr{\\accent \"7F o}m)\n\\item[D300 EPDE1] Elliptic Partial Differential Equation\n\\item[D302 ELPAHY] Fast Partial Differential Equation Solver\n\\item[D401 DERIV] Numerical Differentiation\n\\item[D501 LEAMAX] Constrained Non-Linear Least Squares and Maximum\n                   Likelihood Estimation\n\\item[D506 MINUIT] Function Minimization and Error Analysis\n\\item[D509 MINVAR] Minimum of a Function of One Variable\n\\item[D510 FUMILI] Fitting Chisquare and Likelihood Functions\n\\item[D601 RFRDH1] Solution of a Linear Fredholm Integral Equation of Second Kind\n\\item[D700 RFT] Real Fast Fourier Transform\n\\item[D701 FFTRC] Real and Complex Fast Fourier Transform\n\\item[D702 CFT] Complex Fast Fourier Transform\n\\item[D703 RFFT] Real Fast Fourier Transform\n\\item[D704 CFFT] 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 LOCATF] Binary Search for Element in Ordered Array\n\\item[E207 TRISUM] Summation of Trigonometric Series\n\\item[E208 LSQ] Least Squares Polynomial Fit\n\\item[E210 NORBAS] Polynomial Splines / Normalized B-Splines\n\\item[E211 RCSPLN] Cubic Splines and their Integrals\n\\item[E221 CHEB] Solution of Overdetermined Linear System in the Chebychev 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\n\\item[E401 ECTRAD] Telescoping of Power Series, Double-Precision\n\\item[E406 DCHECF] Chebyshev Series Coefficients of a Function\n\\item[E407 CHSUM] Summation of Chebyshev Series\n\\item[E410 CPSC] Complex Power Series Coefficients\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, Matrix Inversion, Determinant\n\\item[F012 RSINV] Symmetric Positive-Definite Linear Systems\n\\item[F105 POLROT] Rotate a Three-Dimensional Polar Coordinate System\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[F202 LRCH] Eigenvalues of a Real Symmetric Band Matrix\n%\\item[F220 EISPAC] Matrix Eigenvalue/Eigenvector Package\n%\\item[F221 EISCG1] Eigenvalues/Eigenvectors of Complex General Matrix\n%\\item[F222 EISCH1] Eigenvalues/Eigenvectors of Complex Hermitian Matrix\n%\\item[F223 EISRG1] Eigenvalues/Eigenvectors of Real General Matrix\n%\\item[F224 EISRS1] Eigenvalues/Eigenvectors of Real Symmetric Matrix\n%\\item[F225 EISST1] Eigenvalues/Eigenvectors of Real Tridiagonal Matrix\n\\item[F230 DEFLS] Deflate Matrix with Known Eigenvalue/Eigenvector\n\\item[F406 RBEQN] Banded Linear Equations\n\\item[F500 LIHOIN] Linear Homogenous Inequalities\n%\\item[F600 SVD] Singular Value Matrix Decomposition\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[G111 DISVAV] Vavilov Distribution and Its Inverse\n\\item[G900 RANF] Random Number Generator\n\\item[G901 RAN2VS] Random Points on a Circle or Sphere\n\\end{DLtt}\n\\section*{Operation Research Techniques and Management Science}\n\\begin{DLtt}{12345678901}\n\\item[H100 SIMPLE] Linear Optimization Using the Simplex Algorithm\n\\item[H300 ASSIGN] 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\n\\item[I303 RDWORD] Read a Format-Free Number\n\\end{DLtt}\n\\section*{Output and Graphical Data Presentation}\n\\begin{DLtt}{12345678901}\n\\item[J200 VIZPRI] Print Large Characters\n\\item[J401 BANNER] Print Banner Page in Large Characters\n\\item[J403 XBANNER] Print Banner Text\n\\item[J509 CONPRT] Print Function Contours in Two Variables\n\\item[J511 MAP] Table and Plot of Real Function\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[M108 SORTMQ] Sort Rows of a Matrix\n\\item[M109 SORTRQ] Sort Rows of a Matrix\n\\item[M214 CVTVAX] Conversion To and From VAX Number Formats on IBM\n\\item[M215 PSCALE] Find Power-of-Ten Scale for Printing\n\\item[M216 GETWI] Read and Convert a CDC NOS/BE or Scope 2 W/I File\n\\item[M218 CVTCDC] Convert Between CDC and IBM Floating-Point Number Formats\n\\item[M220 IE3CONV] Conversion To and From IEEE Number Format\n\\item[M224 SETFMT] Edit Format for Printing a Floating-Point Vector\n\\item[M231 CVTIB] Convert Floating-Point Numbers Between Host Machine and IBM Formats\n\\item[M232 CVTND] Convert Floating-Point Numbers Between Host Machine and NORD Formats\n\\item[M233 TRTCH] Translate Between Different Character Sets\n\\item[M250 FLOARG] Assure Floating or Integer Representation\n\\item[M251 UFLINT] Assure Integer or Floating Representation of Numbers\n\\item[M400 CHTOI] Portable Conversion Between Type CHARACTER and Type INTEGER\n\\item[M409 UBUNCH] Concentrate and Disperse Character Strings\n\\item[M410 A1MANI] Manipulating BCD Strings in A1 Representation\n\\item[M416 UBLOW1] Concentrate and Disperse Bit Strings\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 ASCII Form\n\\item[M432 CHPACK] Utility Routines for Character String Parsing and 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[M440 FIO999] Fortran Read/Write Simulation and Internal Input/Output Buffer\n\\item[M441 BITPAK] Handling Bits and Bytes, Bit Zero the Least Significant\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[M506 IUMODE] Mode of Argument\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\\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 Mathematical 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\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\\end{DLtt}\n\\section*{Logical and Symbolic}\n\\begin{DLtt}{12345678901}\n\\item[R205 REDUCE] REDUCE 3.3 - A System for Symbolic Algebra\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 Two-Dimensional Regions\n\\end{DLtt}\n\\section*{Quantum Mechanics, Particle Physics}\n\\begin{DLtt}{12345678901}\n\\item[U100 CLEBS] Clebsch-Gordan Coefficients in Algebraic Form\n\\item[U101 LOREN4] Lorentz Transformation\n\\item[U102 LORENF] Lorentz Transformations\n\\item[U110 CLEBSG] Clebsch-Gordan Coefficients; Wigner 3-j, 6-j, 9-j Symbols; Racah Coefficients; Jahn U-Function\n\\item[U501 DJMNB] Beta-Term in Wigner's D-Function\n\\end{DLtt}\n\\section*{Random Numbers and General Purpose Utilities}\n\\begin{DLtt}{12345678901}\n\\item[V100 RANNOR] Random Numbers in Normal Distribution\n\\item[V101 NORRAN] Fast Random Numbers in Normal Distribution\n\\item[V102 NORMCO] Pair of Random Numbers in Normal Distribution\n\\item[V103 IRND01] Random Bits\n\\item[V104 RNDM] Uniform Random Numbers\n\\item[V105 NRAN] Arrays of Uniform Random Numbers\n\\item[V106 RN32] Machine-Independent Uniform Random Numbers\n\\item[V107 RNDM2] IBM Uniform Random Number Generator\n\\item[V108 RG32] Portable Gaussian Random Number Generator\n\\item[V109 RANGAM] Random Numbers in Gamma or Chisquare Distribution\n\\item[V110 POISSN] Poisson Random Numbers\n\\item[V111 BINOMI] Binomial Random Numbers\n\\item[V112 MUNOMI] Multinomial Random Numbers\n\\item[V113 RANMAR] Uniform Random Number Generator\n\\item[V114 RANECU] Uniform Random Number Generator\n\\item[V130 RAN3D] Random Three-Dimensional Vectors\n\\item[V150 HISRAN] Random Numbers According to Any Histogram\n\\item[V151 FUNRAN] 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 with 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] HBOOK Graphics Interface for Histogram Plotting\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[Z008 TIMAL] Job Time in IBM Accounting Units\n\\item[Z009 CALDAT] Calendar Date Conversion\n\\item[Z020 UMON] Usage Monitor for VAX/VMS\n\\item[Z029 NOARG] Number of Arguments Supplied in a Call Statement\n\\item[Z034 WHICH] Computer Mainframe Identification\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\n\\item[Z044 INTRAC] Identify Job as Interactive\n\\item[Z100 JOBNAM] Get User Job Name\n\\item[Z203 XINOUT] Short List Reading and Writing\n\\item[Z204 FNZERO] Cray File Name with Blank or Zero Fill\n\\item[Z262 GOPARM] Provide the User with the G Step PARM-String (IBM)\n\\item[Z264 IARGC] Returns UNICOS command line Arguments\n\\item[Z265 CINTF] Immediate Interface Routines to the C Library\n\\item[Z267 FTOVAX] Convert file-name to and from UNIX syntax\n\\item[Z300 IOPACK] IBM-Dependent Input/Output Package\n\\item[Z301 VAXTIO] VAX Fortran Interface for Reading and Writing 'Foreign' Tapes\n\\item[Z303 KAPACK] Random Access I/O Using Keywords\n\\item[Z304 IOSPACK] General Purpose IBM VM/CMS Non-Graphics Full Screen Interface Package\n\\item[Z305 VMPACK] IBM VM/CMS System Interface\n\\item[Z306 MAXDSK] Find CMS R/W minidisk with most free space\n\\item[Z307 JOB\\dollar VM] Return details about CMS virtual machine\n\\item[Z308 IOSPAK2] 3270 Full Screen I/O Routines\n\\item[Z309 VMIO] CMS Macro I/O Package\n\\item[Z310 CFIO] Handle Fixed-length records on Unix streams\n\\item[Z311 CIO] Handle Unix Disk Files\n\\item[Z312 VAXTAP] VAX Tape Handling Utilities\n\\end{DLtt}\n", "meta": {"hexsha": "7f14439e0ebe485fd0b50d6be5930524835015bf", "size": 17874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geant/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": "geant/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": "geant/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": 50.7784090909, "max_line_length": 113, "alphanum_fraction": 0.8032337473, "num_tokens": 5194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6558332989837192}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\n\\section{Introduction}\\label{S:introduction}\n\\subsection{Preliminary information}\nWe assume that the reader has already learned the parabola in the physics class and the rectangular coordinate system in the math class. If you do not have the required knowledge, it does not matter, you can follow the information provided in this article, learning while reading.\n\n\n\\subsection{Projectile Motion}\nPerhaps we have been told by our parents since childhood that, 45 degrees is the ideal angle to throw a football without air resistance, to understand the reasons why 45 degrees is the best angle without air resistance, we should start with projectile motion\\cite{wiki:projectile_motion}.\n\n\\begin{defnbox}{Projectile motion}\n    Projectile motion is a form of motion experienced by an object or particle (a projectile) that is thrown near the Earth's surface and moves along a curved path under the action of gravity only\\footnote{In particular, the effects of air resistance are assumed to be negligible.}.\n\\end{defnbox}\n\nIn the following article, we call the curved path a trajectory\\cite{wiki:trajectory}. Through experiments or simulations, we can get the trajectories of football at different angles, as shown in Figure~\\ref{F:trajectory}. From the picture we can see that, the footballs are thrown from the origin, the speed remains unchanged, while the angle has changed. Intuitively, 45 degrees is indeed the ideal angle to throw a football for maximum range, and complementary angles have the same range.\n\nThe trajectory was shown by Galileo to be a parabola, which is relevant to quadratic equation. No rush, we will learn the basics of quadratic equation, in the next section.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/quadratic_equation-1.png}\n    \\caption{Parabolic trajectories at different angles}\\label{F:trajectory}\n\\end{figure}\n\n\n\n\\section{Quadratic Equation}\\label{S:quadratic}\n\\subsection{Definition}\n\\begin{defnbox}{Quadratic equation\\cite{wiki:quadratic_equation}}\n    In algebra, a quadratic equation (from the Latin \\emph{quadratus} for ``square'') is any equation having the form\n    \\begin{equation}\\label{E:1}\n        c_2 x^2 + c_1 x + c_0 = 0,\n    \\end{equation}\n    where $x$ represents an unknown, and $c_n$ ($n=0,1,2$) represent known numbers, with $a\\neq 0$. If $a=0$, then the equation is linear, not quadratic, as there is no $c_2 x^2$ term. Then we can divide both sides of the equation by $c_2$, and replace $c_1/c_2$ with $b$, $c_0/c_2$ with $c$.\n    \\begin{equation}\\label{E:quadratic-equation}\n        x^2 + bx + c = 0.\n    \\end{equation}\n    That is, every quadratic equation can be transformed into the form of Equation~\\eqref{E:quadratic-equation}.\n\\end{defnbox}\n\n\n\\subsection{Quadratic Formula and Its Derivation}\nFrom Equation~\\eqref{E:quadratic-equation}, we can complete the square to derive a general formula to solve quadratic equations. Then we have noticed that, coefficient of $x^2$ is 1, coefficient of $x$ is $b$, if we want to complete the square form, we have\n\\begin{equation}\\label{E:quadratic-formula-1}\n    \\begin{aligned}\n        x^2 + bx + c &= 0 \\\\\n        x^2 + 2\\frac{b}{2}x &= -c \\\\\n        \\left(x+\\frac{b}{2}\\right)^2 &= -c + \\frac{b^2}{4} \\\\\n        \\left(x+\\frac{b}{2}\\right)^2 &= \\frac{b^2-4c}{4}.\n    \\end{aligned}\n\\end{equation}\n\nThe left side of the Equation~\\eqref{E:quadratic-formula-1} is a squared form, which means that it may have multiple solutions. That is, if $b^2-4c\\geq 0$,\n\\begin{equation}\\label{E:quadratic-formula-2}\n    \\begin{aligned}\n        x + \\frac{b}{2} &= \\pm \\frac{\\sqrt{b^2-4c}}{2} \\\\\n        x &= -\\frac{b}{2} \\pm \\frac{\\sqrt{b^2-4c}}{2} \\\\\n        x &= \\frac{-b\\pm\\sqrt{b^2-4c}}{2}.\n    \\end{aligned}\n\\end{equation}\n\nIf we substitute the Equation~\\eqref{E:quadratic-formula-2} back to the Equation~\\eqref{E:quadratic-equation}, we will find that the equation still holds. That is the quadratic formula is\n\\begin{equation}\\label{E:quadratic-formula}\n    x = \\begin{cases}\n        \\frac{-b\\pm\\sqrt{b^2-4c}}{2} & \\text{If $b^2-4c\\geq 0$;} \\\\\n        \\frac{-b\\pm i\\sqrt{4c-b^2}}{2} & \\text{If $b^2-4c<0$.}\n    \\end{cases}\n\\end{equation}\n\nYou can get an intuitive feel for the quadratic equation from Figure~\\ref{F:quadratic-formula}. Moreover, we found other interesting phenomena --- vertex, which is the extreme point of the parabola, whether minimum or maximum. The $x$-coordinate of the vertex will be located at $x=-\\tfrac{b}{2}$, and the $y$-coordinate of the vertex may be found by substituting this $x$-value into the function, which gives that $y=\\tfrac{1-(b^2-4c)}{4}$.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.35\\textwidth]{figures/quadratic_equation-2.png}\n    \\caption{Visualization of quadratic equations (with $a=1$)}\\label{F:quadratic-formula}\n\\end{figure}\n", "meta": {"hexsha": "853b11cc137de4b99408f67fdcf6ffbd4e1f0f43", "size": 4867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA320/sections/quadratic_equation/introduction.tex", "max_stars_repo_name": "iydon/homework", "max_stars_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-20T08:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T12:14:56.000Z", "max_issues_repo_path": "MA320/sections/quadratic_equation/introduction.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": "MA320/sections/quadratic_equation/introduction.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": 63.2077922078, "max_line_length": 490, "alphanum_fraction": 0.7222108075, "num_tokens": 1427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6558332887809646}}
{"text": "\\subsection{Performance estimation}\n\\label{sec:performance}\n\nIn this section, we describe the first phase of Elo-MMR. For notational convenience, we assume all probability expressions to be conditioned on the \\textbf{prior context} $P_{i,< t}$, and omit the subscript $t$.\n\nOur prior belief on each player's skill $S_i$ implies a prior distribution on $P_i$. Let's denote its probability density function (pdf) by\n\\begin{equation}\n\\label{eq:perf-prior} \nf_i(p) := \\Pr(P_i = p) = \\int \\pi_i(s) \\Pr(P_i = p \\mid S_i=s) \\,\\mathrm{d}s,\n\\end{equation}\nwhere $\\pi_i(s)$ was defined in \\Cref{eq:pi-s}. Let\n\\[F_i(p) := \\Pr(P_i\\le p) = \\int_{-\\infty}^p f_i(x) \\,\\dx,\\]\nbe the corresponding cumulative distribution function (cdf). For the purpose of analysis, we'll also define the following ``loss'', ``draw'', and ``victory'' functions:\n\\begin{align*}\nl_i(p) &:= \\ddp\\ln(1-F_i(p)) = \\frac{-f_i(p)}{1 - F_i(p)},\n\\\\d_i(p) &:= \\ddp\\ln f_i(p) = \\frac{f'_i(p)}{f_i(p)},\n\\\\v_i(p) &:= \\ddp\\ln F_i(p) = \\frac{f_i(p)}{F_i(p)}.\n\\end{align*}\n\nEvidently, $l_i(p) < 0 < v_i(p)$. Now we define what it means for the deviation $P_i - S_i$ to be log-concave.\n\\begin{definition}\n\\label{def:log-concave}\nAn absolutely continuous random variable on a convex domain is \\textbf{log-concave} if its probability density function $f$ is positive on its domain and satisfies\n\\[f(\\theta x + (1-\\theta) y) > f(x)^\\theta f(y)^{1-\\theta},\\;\\forall\\theta\\in(0,1),x\\neq y.\\]\n\\end{definition}\n\nLog-concave distributions appear widely, and include the Gaussian and logistic distributions used in Glicko, TrueSkill, and many others. We'll see inductively that our prior $\\pi_i$ is log-concave at every round. Since log-concave densities are closed under convolution~\\cite{concave}, the independent sum $P_i=S_i+(P_i-S_i)$ is also log-concave. Log-concavity is made very convenient by the following lemma, proved in the extended version of this paper:\n\\begin{lemma}\n\\label{lem:decrease}\nIf $f_i$ is continuously differentiable and log-concave, then the functions $l_i,d_i,v_i$ are continuous, strictly decreasing, and\n\\[l_i(p) < d_i(p) < v_i(p) \\text{ for all }p.\\]\n\\end{lemma}\n\nFor the remainder of this section, we fix the analysis with respect to some player $i$. As argued in \\Cref{sec:bayes_model}, $P_i$ concentrates very narrowly in the posterior. Hence, we can estimate $P_i$ by its MAP, choosing $p$ so as to maximize:\n\\[\\Pr(P_i=p\\mid E^L_i,E^W_i) \\propto f_i(p) \\Pr(E^L_i,E^W_i\\mid P_i=p).\\]\n\nDefine $j\\succ i$, $j\\prec i$, $j\\sim i$ as shorthand for $j\\in E^L_i$, $j\\in E^W_i$, $j\\in \\mathcal P\\setminus (E^L_i\\cup E^W_i)$ (that is, $P_j>P_i$, $P_j<P_i$, $P_j=P_i$), respectively. The following theorem yields our MAP estimate:\n\\begin{theorem}\n\\label{thm:uniq-max}\nSuppose that for all $j$, $f_j$ is continuously differentiable and log-concave. Then the unique maximizer of $\\Pr(P_i=p\\mid E^L_i,E^W_i)$ is given by the unique zero of\n\\[Q_i(p) := \\sum_{j \\succ i} l_j(p) + \\sum_{j \\sim i} d_j(p) + \\sum_{j \\prec i} v_j(p).\\]\n\\end{theorem}\nThe proof appears in the extended version of this paper. Intuitively, we're saying that the performance is the balance point between appropriately weighted wins, draws, and losses. Let's look at two specializations of our general model, to serve as running examples in this paper.\n\n\\paragraph{Gaussian performance model}\nIf both $S_j$ and $P_j-S_j$ are assumed to be Gaussian with known means and variances, then their independent sum $P_j$ will also be a known Gaussian. It is analytic and log-concave, so \\Cref{thm:uniq-max} applies.\n\nWe substitute the well-known Gaussian pdf and cdf for $f_j$ and $F_j$, respectively. A simple binary search, or faster numerical techniques such as the Illinois algorithm or Newton's method, can be employed to solve for the unique zero of $Q_i$.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=1.05\\columnwidth]{images/l2-lr-plot.eps}\n    \\caption{$L_2$ versus $L_R$ for typical values (left). Gaussian versus logistic probability density functions (right).}\n    \\label{fig:l2-lr-plot}\n\\end{figure}\n\n\\paragraph{Logistic performance model}\nNow we assume the performance deviation $P_j-S_j$ has a logistic distribution with mean 0 and variance $\\beta^2$. In general, the rating system administrator is free to set $\\beta$ differently for each contest. Since shorter contests tend to be more variable, one reasonable choice might be to make $1/\\beta^2$ proportional to the contest duration.\n\nGiven the mean and variance of the skill prior, the independent sum $P_j = S_j + (P_j-S_j)$ would have the same mean, and a variance that's increased by $\\beta^2$. Unfortunately, we'll see that the logistic performance model implies a form of skill prior from which it's tough to extract a mean and variance. Even if we could, the sum does not yield a simple distribution.\n\nFor experienced players, we expect $S_j$ to contribute much less variance than $P_j-S_j$; thus, in our heuristic approximation, we take $P_j$ to have the same form of distribution as the latter. That is, we take $P_j$ to be logistic, centered at the prior rating $\\mu^\\pi_j = \\argmax \\pi_j$, with variance $\\delta_j^2 = \\sigma_j^2 + \\beta^2$, where $\\sigma_j$ will be given by \\Cref{eq:variance}. This distribution is analytic and log-concave, so the same methods based on \\Cref{thm:uniq-max} apply. \nDefine the scale parameter $\\bar\\delta_j := \\frac{\\sqrt{3}}{\\pi} \\delta_j$. A logistic distribution with variance $\\delta_j^2$ has cdf and pdf:\n\\begin{align*}\nF_j(x) &= \\frac { 1 } { 1 + e^{-(x-\\mu^\\pi_j)/\\bar\\delta_j} }\n= \\frac 12 \\left(1 + \\tanh\\frac{x-\\mu^\\pi_j}{2\\bar\\delta_j} \\right),\n\\\\f_j(x) &= \\frac { e^{(x-\\mu^\\pi_j)/\\bar\\delta_j} } { \\bar\\delta_j\\left( 1 + e^{(x-\\mu^\\pi_j)/\\bar\\delta_j} \\right)^2}\n= \\frac { 1 } { 4\\bar\\delta_j} \\sech^2\\frac{x-\\mu^\\pi_j}{2\\bar\\delta_j}.\n\\end{align*}\n\nThe logistic distribution satisfies two very convenient relations:\n\\begin{align*}\nF'_j(x) = f_j(x) &= F_j(x) (1 - F_j(x)) / \\bar\\delta_j,\n\\\\f'_j(x) &= f_j(x) (1 - 2F_j(x)) / \\bar\\delta_j,\n\\end{align*}\nfrom which it follows that\n\\[d_j(p)\n= \\frac{1 - 2F_j(p)}{\\bar\\delta}\n= \\frac{-F_j(p)}{\\bar\\delta} + \\frac{1 - F_j(p)}{\\bar\\delta}\n= l_j(p) + v_j(p).\\]\n\nIn other words, a tie counts as the sum of a win and a loss. This can be compared to the approach (used in Elo, Glicko, BAR, Topcoder, and Codeforces) of treating each tie as half a win plus half a loss.\\footnote{Elo-MMR, too, can be modified to split ties into half win plus half loss. It's easy to check that \\Cref{lem:decrease} still holds if $d_j(p)$ is replaced by\n$w_l l_j(p) + w_v v_j(p)$,\nprovided that $w_l,w_v\\in [0,1]$ and $|w_l-w_v|<1$.\nIn particular, we can set $w_l=w_v=0.5$. The results in \\Cref{sec:properties} won't be altered by this change.}\n\nFinally, putting everything together:\n\\[Q_i(p) = \\sum_{j \\succeq i} l_j(p) + \\sum_{j \\preceq i} v_j(p)\n= \\sum_{j \\succeq i} \\frac{-F_j(p)}{\\bar\\delta_j} + \\sum_{j \\preceq i} \\frac{1 - F_j(p)}{\\bar\\delta_j}.\\]\nOur estimate for $P_i$ is the zero of this expression. The terms on the right correspond to probabilities of winning and losing against each player $j$, weighted by $1/\\bar\\delta_j$. Accordingly, we can interpret $\\sum_{j\\in \\cP} (1-F_j(p))/\\bar\\delta_j$ as a weighted expected rank of a player whose performance is $p$. Similar to the performance computations in Codeforces and Topcoder, $P_i$ can thus be viewed as the performance level at which one's expected rank would equal $i$'s actual rank.\n\n", "meta": {"hexsha": "39af103b228a6be59c6214e665086d96f109cd38", "size": 7438, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/source/sections/s3_1_perf.tex", "max_stars_repo_name": "kiwec/Elo-MMR", "max_stars_repo_head_hexsha": "bf64ea75e8c0dbb946d379b9bee1753e604b388a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 57, "max_stars_repo_stars_event_min_datetime": "2021-02-12T18:28:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T10:59:36.000Z", "max_issues_repo_path": "paper/source/sections/s3_1_perf.tex", "max_issues_repo_name": "cesartxt/Elo-MMR", "max_issues_repo_head_hexsha": "7ef860d599e8325ae1f615ce08120369b39bfecc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:42:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T08:41:23.000Z", "max_forks_repo_path": "paper/source/sections/s3_1_perf.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": 80.847826087, "max_line_length": 500, "alphanum_fraction": 0.7152460339, "num_tokens": 2327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6558332848965165}}
{"text": "\\section{Introduction}\nIn this paper we are going to study Lie algebras over unital commutative rings $R$, with $2 \\nmid \\mathrm{char}(R)$ which are projective of finite type as $R$-modules.\n\\subsection{Lie algebras and their coalgebras}\nA Lie algebra $\\lieg$ is an $R$-module with $R$-linear map:\n$$\\mu : \\lieg \\otimes_R \\lieg \\longrightarrow \\lieg$$\nthat is antisymmetric ($\\mu = -\\tau \\mu$) and Jacobi-identity holds:\n$$\\mu (1 \\otimes \\mu) (1 + \\zeta_3 + \\zeta_3^2)(x_1 \\otimes x_2 \\otimes x_3) = 0, x_i \\in \\lieg$$\nwhere $\\zeta_3$ is the cyclic permutation of the tensors, $\\tau = [x \\otimes y \\longmapsto y \\otimes x]$ the flip map and $1$ the identity map. In \\cite{SongSu}, they proposed\n$$\\ker (1 - \\tau) \\subset \\ker \\mu$$\nas an alternative for antisymmetry.\n\\begin{defi}\nAn $R$-module $\\lieg$ with $R$-linear map $\\Delta : \\lieg \\longrightarrow \\lieg \\otimes \\lieg$ is called an Lie $R$-coalgebra if:\n\\bi\n\\item $\\mathrm{im} \\Delta \\subset \\mathrm{im} (1 - \\tau)$\n\\item $(1 + \\zeta_3 + \\zeta_3^2) (1 \\otimes \\Delta) \\Delta = 0$.\n\\ei\n\\end{defi}\nWe recall that an coassociative coalgebra fulfills $(1 \\otimes \\Delta)\\Delta = (\\Delta \\otimes 1)\\Delta)$. For clarity we repeat:\na bialgebra is an $R$-module $B$, with multiplication $\\mu$, comultiplication $\\Delta$ (and optional unit and counit), such that $\\mu, \\eta$ are homomorphisms of coalgebras and $\\Delta, \\eps$ are homomorphisms of algebras over $R$.\n\\begin{defi}\nAn Lie bialgebra $(\\lieg,\\mu,\\Delta)$ is a:\n\\bi\n\\item Lie algebra $(\\lieg,\\mu)$ and\n\\item Lie coalgebra $(\\lieg,\\Delta)$,\n\\ei\nsuch that the following diagram commutes:\n$$\\xymatrix{\n\\lieg \\otimes \\lieg \\ar[rr]^\\mu\\ar[d]_{D \\otimes D} && \\lieg \\ar[rr]^\\Delta && \\lieg \\otimes \\lieg\\\\\n\\lieg^{\\otimes 4} \\ar[d]_{id \\otimes \\tau\\otimes id} &&&&\\\\\n\\lieg^{\\otimes 4} \\ar[d]_{id \\otimes id \\otimes \\tau} &&&&\\\\\n\\lieg^{\\otimes4} \\ar[rr]_{id \\otimes \\Delta \\otimes id \\otimes \\Delta} &&\\lieg^{\\otimes 6} \\ar[rr]_{\\mu \\otimes id \\otimes \\mu \\otimes id} && \\lieg^{\\otimes4}\\ar[uuu]_{\\pi_1 - \\pi_2}\\\\\n}$$\nwhere $D : \\lieg \\longrightarrow \\lieg \\otimes \\lieg, x \\longmapsto x \\otimes x$, $\\pi_1 : \\lieg^{\\otimes 4} \\longrightarrow \\lieg\\otimes\\lieg, x \\otimes y \\otimes z \\otimes u \\longmapsto x \\otimes y$, $\\pi_2 : \\lieg^{\\otimes 4} \\longrightarrow \\lieg \\otimes \\lieg$, $x \\otimes y \\otimes z \\otimes u \\longmapsto z \\otimes u$.\n\\end{defi}", "meta": {"hexsha": "6d30f87753be6e5936ce3e2f5721163bcd3fb8de", "size": 2356, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lie_bialgebra/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": "Lie_bialgebra/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": "Lie_bialgebra/intro.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.2941176471, "max_line_length": 325, "alphanum_fraction": 0.6740237691, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6557958816593473}}
{"text": "\n\n\\section{Open questions}\n\nUnder previous insights, we ask respectively:\n\\begin{enumerate}\n    \\item let $\\mathcal{R}_{h(t)}=\\left(g(h(t)), h(t)\\right)$ a $h$-characterization \n        of $\\mathcal{R}$, and consider the series expansion of funtion $g$:\n        \\begin{displaymath}\n            \\left.\\left[g(y)=g_0 + g_1 y + g_2 y^2 + \\ldots\\right|y=h(t)\\right] \n        \\end{displaymath}\n        what's the interpretation of coefficients in the sequence\n        $\\lbrace g_i\\rbrace_{i\\in\\mathbb{N}}$? \n        \n        We've seen that if $\\mathcal{R}=\\left(d(t), td(t)\\right)$, then \n        $[g(y)=A(y)|y=h(t)]$ where $A(t)$ is $\\mathcal{R}$'s A-sequence: \n        does exist a deep relation among those sequences for \\emph{arbitrary} arrays?   \n        For instance, what about Fibonacci array $\\mathcal{F}$: \n        \\begin{displaymath}\n            \\begin{split}\n                \\big[ g_{\\mathcal{F}}(y) &= 1 + y + y^{2} - y^{3} -2y^{4} \n                -3 y^{5}  +3 y^{7} \\\\\n                &+7 y^{8} +4 y^{9} + \\mathcal{O}\\left(y^{10}\\right) | y=h_{\\mathcal{F}}(t) \\big]\n            \\end{split}\n        \\end{displaymath}\n        or about Delannoy array $\\mathcal{D}$: \n        \\begin{displaymath}\n            \\begin{split}\n                \\big[ g_{\\mathcal{D}}(y) &= 1 + y - y^{2} + 3 y^{3} -11y^{4} + 45 y^{5} -197y^{6}\\\\ \n                &+ 903 y^{7} -4279y^{8} + \\mathcal{O}\\left(y^{9}\\right)| y=h_{\\mathcal{D}}(t) \\big]\n            \\end{split}\n        \\end{displaymath}\n    \\item let $\\mathcal{P}$ and $\\mathcal{C}$ be Pascal and Catalan arrays, respectively: \n        what does $\\mathcal{C}^{\\stackrel{\\frac{t}{1-t}}{\\rightarrow}}$ count? \n        More generally, chosen two Riordan arrays $\\mathcal{A}$ and $\\mathcal{B}$, \n        $\\mathcal{A}^{\\stackrel{h_{\\mathcal{B}}(t)}{\\rightarrow}}$ also has a combinatorial meaning? \n        So does $\\mathcal{B}^{\\stackrel{h_{\\mathcal{A}}(t)}{\\rightarrow}}$? What about considering\n        combinations involving  $\\mathcal{A}^{-1}$ and $\\mathcal{B}^{-1}$ too?\n\n\n    \\item let $\\mathcal{R}(d(t),h(t))$ be a Riordan array in \n        natural notation. If function $\\hat{h}$, the compositional inverse\n        of function $h$, has the following structure:\n        \\begin{displaymath}\n            \\hat{h}(y) = \\frac{y}{\\Pi(y)}\n        \\end{displaymath}\n        where $\\Pi$ is a polynomial such that $\\Pi(0)\\not=0$, the question is:\n        is it always the case that there exists a sequence of polynomials\n        $\\lbrace \\Omega_{i} \\rbrace_{i\\in\\mathbb{N}}$, where function $\\Omega_{i}$\n        is defined as:\n        \\begin{displaymath}\n            \\Omega_{i}(y)=\\left(\\frac{[t^{1+i}]d(t)h(t)} {\\Pi(y)}\\right)\n        \\end{displaymath}\n        such that $\\mathcal{R}$'s $A$-sequence can be be factored respect to\n        function $\\hat{h}$ as:\n        \\begin{displaymath}\n                \\left.\\left[\n                    A_{\\mathcal{R}}(y) = \\sum_{i \\geq0}{\n                        \\Omega_{i}(y) \\hat{h}(y)^{i}} \n                        \\right| y = h(t) \\right]\n        \\end{displaymath}\n        in other words, the sequence of coefficients of the function defining\n        the second column of array $\\mathcal{R}$, namely the convolution of functions \n        $d$ and $h$, shifted by \\emph{one} position, does occur in\n        the given factorization?\n\n\\end{enumerate}\n\n\\subsection{An hint\\ldots}\n\nIn this section we offer an hint to tackle question number $1$\nasked in previous enumeration. Let $\\mathcal{R}_{h(t)}(\\gamma(h(t)), h(t))$\nbe a Riordan array written in $h$-characterization form, for some function $\\gamma$. \nNow, with abuse of notation, do a \\emph{standard} matrix-vector product, namely\nconsider $\\mathcal{R}_{h(t)}$ as a matrix: multiply it by a vector $\\vect{\\omega}$\nwhose coefficients are defined by a sequence $\\lbrace \\omega_i \\rbrace_{i\\in\\mathbb{N}}$\nand set equal to a vector $\\vect{a}$ whose coefficients are defined by $\\mathcal{R}$'s\n$A$-sequence. Formally:\n\n\\begin{displaymath}\n    \\mathcal{R}_{h(t)}\\left[\\begin{array}{c} \\omega_0 \\\\ \\omega_1 \\\\ \\omega_2 \\\\ \\vdots \\end{array}\\right] =\n        \\left[\\begin{array}{c} a_0 \\\\ a_1 \\\\ a_2 \\\\ \\vdots \\end{array}\\right]\n\\end{displaymath}\nInterpreting columns of $\\mathcal{R}_{h(t)}$ and vector $\\vect{a}$ via\ncorresponding generating functions, rewrite as follow:\n\\begin{displaymath}\n    \\begin{split}\n            \\omega_0\\,\\gamma(h(t))\\,h(t)^{0} + \n            \\omega_1\\,\\gamma(h(t))\\,h(t)^{1} + \n            \\omega_2\\,\\gamma(h(t))\\,h(t)^{2} + \n            \\ldots &= A(t) \\\\\n            \\gamma(h(t))\\left(\\omega_0\\,h(t)^{0} + \n            \\omega_1\\,h(t)^{1} + \n            \\omega_2\\,h(t)^{2} + \n            \\ldots \\right) &= A(t) \\\\\n            \\gamma(h(t))\\,\\Omega(h(t)) &= A(t) \\\\\n    \\end{split}\n\\end{displaymath}\nwhere functions $A$ and $\\Omega$ are \\ac{fps} over sequences\n$\\lbrace a_i \\rbrace_{i\\in\\mathbb{N}}$ and\n$\\lbrace \\omega_i \\rbrace_{i\\in\\mathbb{N}}$, respectively. Note that abstracting\nover function $h$ yield:\n\\begin{displaymath}\n    \\left.\\left[\n        \\gamma(y)\\,\\Omega(y) = A(\\hat{h}(y)) \\right| y = h(t) \\right]\n\\end{displaymath}\nbut this relationship is quite difficult since introduces function $\\hat{h}$,\nthe compositional inverse of function $h$. Therefore, function\n$\\gamma$, parameterized by function $h$, is related to $\\mathcal{R}$'s\n$A$-sequence, parameterized over variable $t$, by the existence of \na function $\\Omega$, parameterized over function $h$, such that:\n\\begin{displaymath}\n    \\gamma(h(t))\\,\\Omega(h(t)) = A(t) \n\\end{displaymath}\nFor the sake of clarity, let $\\mathcal{M}$ be the Motzkin array, so:\n\\begin{displaymath}\n        \\left.\\left[\n            \\Omega_{\\mathcal{M}}(y) = \\frac{y^{4} + 3 \\, y^{3} + 5 \\, y^{2} + 3 \\, y + 1}{{\\left(y^{2} + y + 1\\right)}^{3}}\n                \\right| y = h(t) \\right]\n\\end{displaymath}\nand the first terms of fps expansion:\n\\begin{displaymath}\n        \\left.\\left[\n            \\Omega_{\\mathcal{M}}(y) = 1 -y^{2} -y^{3} + 4 y^{4} -2\\,y^{5} \n                -6\\,y^{6} + 11 y^{7}+\\mathcal{O}\\left(y^{8}\\right)\n                \\right| y = h(t) \\right]\n\\end{displaymath}\nIn turn another question arises: \\emph{there\nexists a smart way to compute function $\\Omega$}? If there exists such a method, then\n$\\mathcal{R}$'s $A$-sequence could be computed easily, since function $\\gamma$ \nis read directly from the factorization, for \\emph{any} Riordan array\\ldots\n", "meta": {"hexsha": "f1d0e8255998a3e87cf2bed730afce5fa1a2c2b1", "size": 6364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classicthesis/Chapters/h-characterization/open-questions.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/open-questions.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/open-questions.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": 48.2121212121, "max_line_length": 123, "alphanum_fraction": 0.5839094909, "num_tokens": 2066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6557921648528345}}
{"text": "\\subsection{Gaussian Mixture}\n\\label{sec:ctm-gm}\n\nThe second clustering algorithm we tried was Gaussian Mixture \\cite{dempster1977maximum}. Similar to the K-Means algorithm, it also groups unlabeled data points but with different criteria. As its name suggests, it assumes the points are randomly distributed following a Gaussian distribution. It iteratively tries to assign groups to maximize the likelihood of each data point belonging to their assigned groups. Likewise, we hypothesized that the closer a point (student solution) is to the centroid, in this case the central probability contour, the higher the probability of the student receiving a high score. In practice, we designated each student's score to be equal to the probability of them belonging to their assigned cluster, returned from the Gaussian Mixture algorithm.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{conversion-to-mark/marking_paster_nbio_ece459-a1-w2017_gm}\n\\caption[Gaussian Mixture Clustering]{This is a probability contour graph of our data points grouped by the Gaussian Mixture algorithm. Points closer to the center of the contours, i.e. lighter areas, have a higher probability of belonging to their corresponding group.}\n\\label{fig:ctm-gm}\n\\end{figure}\n", "meta": {"hexsha": "c99ee69e72f95dc01a81b6741792192ec4674e09", "size": 1248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/thesis/body/conversion-to-mark/gaussian-mixture.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/gaussian-mixture.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/gaussian-mixture.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": 113.4545454545, "max_line_length": 784, "alphanum_fraction": 0.8181089744, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6557887960979898}}
{"text": "%\\documentclass{article}\n\\documentclass[18pt]{extarticle}\n% Comment the following line to NOT allow the usage of umlauts\n\\usepackage[utf8]{inputenc}\n% Uncomment the following line to allow the usage of graphics (.png, .jpg)\n%\\usepackage{graphicx}\n\n\\newcommand*{\\pd}[3][]{\\ensuremath{\\frac{\\partial^{#1} #2}{\\partial #3}}}\n% Start the document\n\\begin{document}\n\n% Create a new 1st level heading\n\\section{Finding a function's derivative in chart coordinates}\nFront matter\n$\n\\\\ f(x) = f(\\psi^{-1}(\\psi(x)))\n%\n\\\\ \\frac{\\partial}{\\partial x} f(x) =\n\\frac{\\partial }{\\partial x} \nf(\\psi^{-1}(\\psi(x)))\n%\n\\\\ =\\pd{f}{x}(\\psi^{-1}(\\psi(x))) *\n\\pd{}{x}(\\psi^{-1}(\\psi(x))) \n%\n\\\\ =\\pd{f}{x}(\\psi^{-1}(\\psi(x))) *\n\\pd{\\psi^{-1}}{x}(\\psi(x)) *\n\\pd{}{x}\\psi(x)\n\\\\ $\n\\newline\nNow also consider the following:\n\\newline\n$\n\\\\ \\pd{}{x}f(\\psi^{-1}(x)) =\n\\pd{f}{x}(\\psi^{-1}(x)) *\n\\pd{\\psi^{-1}}{x}(x)\n$\n\\newline\n\\newline\nThis is the derivative of the function in the chart coordinates on the left hand side and then applying the chain rule on the right.\n\\newline \nBut from the above equalities we see we can relate\nthe derivative of the function in chart coordinates, to its derivative in manifold coordinates by (a) evaluating it at $\\psi(x)$ and then (b) multiplying by $\\pd{\\psi}{x}$.\n\\newline \n\\newline\nSo we finally have:\n\\newline\n$\n\\\\ \\pd{}{x}f(x) = \\pd{\\psi}{x} * \n\\pd{}{x}f(\\psi^{-1}(x)) @ \\psi(x)\n$\n\\end{document}\n", "meta": {"hexsha": "2284df474c39f0050a55c2a58868224607aaa2cb", "size": 1403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/manifold.tex", "max_stars_repo_name": "sillsm/shmensor", "max_stars_repo_head_hexsha": "277eea622c2f4ce3b1fd2e433d5cd625db1f2b72", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-02T21:32:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-18T20:16:23.000Z", "max_issues_repo_path": "notes/manifold.tex", "max_issues_repo_name": "sillsm/shmensor", "max_issues_repo_head_hexsha": "277eea622c2f4ce3b1fd2e433d5cd625db1f2b72", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-16T18:06:29.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-16T18:06:29.000Z", "max_forks_repo_path": "notes/manifold.tex", "max_forks_repo_name": "sillsm/shmensor", "max_forks_repo_head_hexsha": "277eea622c2f4ce3b1fd2e433d5cd625db1f2b72", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-16T18:00:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-16T18:00:00.000Z", "avg_line_length": 26.9807692308, "max_line_length": 172, "alphanum_fraction": 0.6429080542, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6556700566280345}}
{"text": "\\newcommand\\chapternumber{2}\n\\input{../tex_header/header.tex}\n\\usepackage{enumerate}\n\\usepackage{float}\n\n\\begin{document}\n\n\\section{Find constants / partition functions.}\n\\subsection{}\n\\begin{align*}\n    f(x|a,b) = 1 \\text{ on } x \\in [a,b]\n\\end{align*}\n\nFirst, let's take integral of $f(x)$:\n\\begin{align*}\n    \\int f(x) \\ dx\n    &= \\int_a^b 1 \\ dx\\\\\n    &= b-a\n\\end{align*}\n\nSo, if we want $\\int p(x) \\ dx = 1$, and $p(x) = \\frac{1}{\\mathcal{Z}} f(x)$, we have:\n\\begin{align}\n    \\int \\frac{1}{\\mathcal{Z}} f(x) \\ dx&= 1 \\nonumber \\\\\n    \\frac{1}{\\mathcal{Z}} \\int  f(x) \\ dx&= 1 \\nonumber \\\\\n    \\int f(x) \\ dx&= \\mathcal{Z}  \\\\\n    b-a &= \\mathcal{Z} \\nonumber \n\\end{align}\n\nSo, $\\mathcal{Z} = b-a$. \n\nEquation (1) can also apply to other functions in question 1, and it indicates that the normalizing constant is just the integral of the function.\n\n\\subsection{}\n\\begin{align*}\n    f(x|\\beta) = \\exp(-\\frac{x}{\\beta}) \\text{ on } x \\in (0,\\infty) \\text{ and } \\beta \\in (0, \\infty)\n\\end{align*}\n\nFirst, let's take integral of $f(x)$:\n\\begin{align*}\n    \\int f(x) \\ dx\n    &= \\int_0^{\\infty} \\exp(-\\frac{x}{\\beta})\\ dx \\\\\n    &= (-\\beta \\cdot \\exp(-\\frac{x}{\\beta})) \\biggr\\rvert _0^{\\infty} \\\\\n    &= -\\beta \\cdot (\\exp(-\\infty)-\\exp(0)) \\\\\n    &= \\beta \n\\end{align*}\n\nSo, substitude to equation (1), we have $\\mathcal{Z} = \\beta$.\n\n\\subsection{}\n\\begin{align*}\n    f(x|\\mu,\\sigma)=\\exp[-\\frac{(x-\\mu)^2}{2\\sigma^2}]\n\\end{align*}\nwhere $x \\in (-\\infty, \\infty)$, $\\mu \\in (-\\infty, \\infty)$, $\\sigma \\in (0, \\infty)$.\n\nTo find the integral of $f$, we need to square it:\n\\begin{align*}\n    \\int f(x|\\mu, \\sigma) \\ dx &= \\sqrt{\\int_{-\\infty}^{\\infty} f(x|\\mu, \\sigma) \\ dx \\cdot \\int_{-\\infty}^{\\infty} f(x|\\mu, \\sigma) \\ dx} \\\\\n    &= \\sqrt{\\int_{-\\infty}^{\\infty} f(x|\\mu, \\sigma) \\ dx \\cdot \\int_{-\\infty}^{\\infty} f(y|\\mu, \\sigma) \\ dy} \\\\\n    &= \\sqrt{\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} f(x|\\mu, \\sigma) \\cdot f(y|\\mu, \\sigma) \\ dx\\ dy} \\\\\n    &= \\sqrt{\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \\exp[-\\frac{(x-\\mu)^2}{2\\sigma^2}] \\cdot \\exp[-\\frac{(y-\\mu)^2}{2\\sigma^2}] \\ dx\\ dy} \\\\\n    &= \\sqrt{\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \\exp[-\\frac{(x-\\mu)^2}{2\\sigma^2}-\\frac{(y-\\mu)^2}{2\\sigma^2}] \\ dx\\ dy} \\\\\n    &= \\sqrt{\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \\exp[-\\frac{(x-\\mu)^2 + (y-\\mu)^2}{2\\sigma^2}] \\ dx\\ dy} \\\\\n\\end{align*}\n\nLet's set the new origin at $(\\mu, \\mu)$, and turn the equation into polar coordinate:\n\\begin{align*}\n    \\int f(x|\\mu, \\sigma) \\ dx\n    &= \\sqrt{\\int_{-0}^{2 \\pi} \\int_{0}^{\\infty} \\exp[-\\frac{r^2}{2\\sigma^2}] \\cdot r \\ dx\\ dy} \\\\\n    &= \\sqrt{\\int_{-0}^{2 \\pi} \\sigma^2 \\ dy} \\\\\n    &= \\sqrt{2 \\sigma^2 \\pi } \\\\\n\\end{align*}\n\nWe know $\\sigma > 0$, so $\\mathcal{Z} = \\sigma \\sqrt{2 \\pi}$.\n% First, we start from the PDF of the Normal distribution: \n% \\begin{align*}\n%     p(x) &= \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\cdot \\exp[-\\frac{(x-\\mu)^2}{2\\sigma^2}] \\\\\n%     &= \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\cdot f(x|\\mu, \\sigma)\n% \\end{align*}\n\n% So,\n% \\begin{align*}\n%     f(x|\\mu,\\sigma) = \\sigma \\sqrt{2 \\pi} \\cdot p(x)\n% \\end{align*}\n\n% We know that Normal distribution is a probability distribution, so $\\int p(x) \\ dx=1$. \n% Thus $\\int f(x|\\mu, \\sigma) \\ dx  = \\sigma \\sqrt{2 \\pi} \\cdot 1$, and $\\mathcal{Z} = \\sigma \\sqrt{2 \\pi}$.\n\\subsection{}\n\\begin{align*}\n    f(x|a,\\gamma)=\\frac{1}{x^\\gamma}\n\\end{align*}\nwhere $x \\in (a, \\infty)$, $a \\in (0, \\infty)$, $\\gamma \\in (0, \\infty)$.\n\nThere are three cases: (1) $\\gamma>1$, (2) $\\gamma=1$, (3) $0<\\gamma<1$.\n\nIn case (1) $\\gamma>1$:\n\\begin{align*}\n    \\int_a^{\\infty} \\frac{1}{x^{\\gamma}} \\ dx\n    &= \\frac{x^{1-\\gamma}}{1-\\gamma} \\biggr\\rvert _a^{\\infty} \\\\\n    &= 0 - \\frac{a^{1-\\gamma}}{1-\\gamma} \\\\\n    &= \\frac{1}{a^{\\gamma-1} (\\gamma-1)}\n\\end{align*}\n\nSo, in case (1), $\\mathcal{Z} = \\frac{1}{a^{\\gamma-1} (\\gamma-1)}$.\n\nIn case (2) $\\gamma=1$:\n\\begin{align*}\n    \\int_a^{\\infty} \\frac{1}{x} \\ dx\n    &= \\log(x) \\biggr\\rvert _a^{\\infty} \\\\\n    &= \\infty\n\\end{align*}\n\nSo, in case (2), $\\mathcal{Z}$ doesn't exist.\n\nIn case (3) $0<\\gamma<1$:\n\\begin{align*}\n    \\int_a^{\\infty} \\frac{1}{x^{\\gamma}} \\ dx\n    &= \\frac{x^{1-\\gamma}}{1-\\gamma} \\biggr\\rvert _a^{\\infty} \\\\\n    &= \\infty    \n\\end{align*}\n\nSo, in case (3), $\\mathcal{Z}$ doesn't exist.\n\nThus, in summary, if $f(x|a,\\gamma)$ is defined on $\\gamma \\in (0, \\infty)$, $\\mathcal{Z}$ doesn't exist.\n\n\\section{1st and 2nd moment}\nIn the previous question, only 1.1 and 1.2 can be properly-normalized.\n\n\\subsection{}\nFor 1.1, $\\mathcal{Z}=b-a$, and $p(x)=\\frac{1}{b-a}$.\n\\begin{align*}\n    m_1 &= E_{x \\sim p(x)}[x] \\\\\n    &= \\int_a^b p(x) x \\ dx\\\\\n    &= \\int_a^b \\frac{x}{b-a} \\ dx\\\\\n    &= \\frac{a+b}{2}\n\\end{align*}\n\n\\begin{align*}\n    m_2 &= E_{x \\sim p(x)}[(x-m_1)^2] \\\\\n    &= E_{x \\sim p(x)}[(x-\\frac{a+b}{2})^2] \\\\\n    &= \\int_a^b p(x) (x-\\frac{a+b}{2})^2 \\ dx\\\\\n    &= \\int_a^b \\frac{(x-\\frac{a+b}{2})^2}{b-a}  \\ dx\\\\\n    &= \\frac{1}{b-a} \\int_a^b (x^2 - (a+b)x + \\frac{1}{4}(a+b)^2) )  \\ dx\\\\\n    &= \\frac{1}{b-a} (\\frac{1}{3}(b^3-a^3) - \\frac{1}{2}(a+b)(b^2-a^2) + \\frac{1}{4}(b-a)(a+b)^2) \\\\\n    &= \\frac{1}{12} (b-a)^2\n\\end{align*}\n\n\\subsection{}\nFor 1.2, $\\mathcal{Z}=\\beta$, and $p(x)=\\frac{1}{\\beta} \\exp(-\\frac{x}{\\beta})$.\n\\begin{align*}\n    m_1 &= E_{x \\sim p(x)}[x] \\\\\n    &= \\int_0^{\\infty} p(x) x \\ dx\\\\\n    &= \\int_0^{\\infty} \\frac{1}{\\beta} \\exp(-\\frac{x}{\\beta}) x \\ dx\\\\\n    &= \\frac{1}{\\beta} \\int_0^{\\infty} \\exp(-\\frac{x}{\\beta}) x \\ dx\\\\\n    &= \\frac{1}{\\beta} [\\beta (-\\exp(-\\frac{x}{\\beta})(\\beta+x))] \\biggr\\rvert _0^{\\infty} \\\\\n\\end{align*}\nHere, we have $\\beta>0$, so, $\\exp(-\\frac{x}{\\beta}) x \\rightarrow 0$ when $x \\rightarrow 0$.\n\\begin{align*}\n    m_1 &= \\frac{1}{\\beta} [0 + \\beta (\\beta+0))] \\\\\n    &= \\beta\n\\end{align*}\n\n\\begin{align*}\n    m_2 &= E_{x \\sim p(x)}[(x-m_1)^2] \\\\\n    &= E_{x \\sim p(x)}[(x-\\beta)^2] \\\\\n    &= \\int_0^{\\infty} p(x) (x-\\beta)^2 \\ dx \\\\\n    &= \\int_0^{\\infty} \\frac{1}{\\beta} \\exp(-\\frac{x}{\\beta}) (x-\\beta)^2 \\ dx \\\\\n    &= \\frac{1}{\\beta} \\int_0^{\\infty} \\exp(-\\frac{x}{\\beta}) (x^2-2\\beta x + \\beta^2) \\ dx \\\\\n    &= \\frac{1}{\\beta} [ \\int_0^{\\infty} \\exp(-\\frac{x}{\\beta}) x^2 \\ dx -2 \\int_0^{\\infty} \\exp(-\\frac{x}{\\beta}) \\beta x \\ dx + \\int_0^{\\infty} \\exp(-\\frac{x}{\\beta}) \\beta^2 \\ dx ] \\\\\n    &= \\frac{1}{\\beta} [ (\\beta(-\\exp(-\\frac{x}{\\beta})(2\\beta^2+x^2+2\\beta x)))|_0^{\\infty} -2 (\\beta^2(-\\exp(-\\frac{x}{\\beta})(\\beta+x)))|_0^{\\infty} \\\\\n    &\\  + (\\beta^3(-\\exp(-\\frac{x}{\\beta})))|_0^{\\infty} ]\n\\end{align*}\nFor the same argument in case of $\\beta>0$, $\\exp(-\\frac{x}{\\beta}) x \\rightarrow 0$ and $\\exp(-\\frac{x}{\\beta}) x^2 \\rightarrow 0$ when $x \\rightarrow 0$:\n\\begin{align*}\n    m_2 &= \\frac{1}{\\beta} [ 2 \\beta^3 -2 \\beta^3 + \\beta^3 ] \\\\\n    &= \\beta^2\n\\end{align*}\n\n\\subsection{}\nFor 1.3, $\\mathcal{Z} = \\sigma \\sqrt{2 \\pi}$, and $p(x)=\\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp(-\\frac{(x-\\mu)^2}{2 \\sigma^2})$.\n\\begin{align*}\n    m_1 &= E_{x \\sim p(x)}[x] \\\\\n    &= \\int_{-\\infty}^{\\infty} p(x) x \\ dx \\\\\n    &= \\int_{-\\infty}^{\\infty} \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp(-\\frac{(x-\\mu)^2}{2 \\sigma^2}) x \\ dx \\\\\n    &= \\int_{-\\infty}^{\\infty} \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp(-\\frac{(x-\\mu)^2}{2 \\sigma^2}) (x-\\mu) + \\mu \\cdot \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp(-\\frac{(x-\\mu)^2}{2 \\sigma^2}) \\ dx \\\\\n\\end{align*}\n\nLet $y = x - \\mu$, we can see the first part is 0 (from question 1.3).\nAnd we write the second part back into the form of $p(x)$, which is the normalized probability density function.\n\\begin{align*}\n    m_1\n    &= \\int_{-\\infty}^{\\infty} \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp(-\\frac{y^2}{2 \\sigma^2}) y + \\mu \\cdot p(x) \\ dx \\\\\n    &= \\int_{-\\infty}^{\\infty} \\mu \\cdot p(x) \\ dx \\\\\n    &= \\mu\n\\end{align*}\n\n\\begin{align*}\n    m_2 &= E_{x \\sim p(x)}[(x-m_1)^2] \\\\\n    &= E_{x \\sim p(x)}[(x-\\mu)^2] \\\\\n    &= \\int_{-\\infty}^{\\infty} p(x) (x-\\mu)^2 \\ dx \\\\\n    &= \\int_{-\\infty}^{\\infty} \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp[-\\frac{(x-\\mu)^2}{2 \\sigma^2}] (x-\\mu)^2 \\ dx \\\\\n\\end{align*}\n\nLet $y=\\frac{x-\\mu}{\\sqrt{2}\\sigma}$, so, $dx = \\sqrt{2} \\sigma\\ dy$, we have:\n\\begin{align*}\n    m_2 &= \n    \\int_{-\\infty}^{\\infty} \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp[-y^2] 2\\sigma^2 y^2  \\sqrt{2} \\sigma \\ dy \\\\\n    &= \\sigma^2 \\int_{-\\infty}^{\\infty} \\frac{2}{\\sqrt{\\pi}} \\exp[-y^2]  y^2  \\ dy \\\\\n\\end{align*}\n\nWe know from question 1, $\\int_{-\\infty}^{\\infty} \\exp[-\\frac{(x-\\mu)^2}{2\\sigma^2}] \\ dx = \\sigma \\sqrt{2 \\pi}$.\nIf we differentiate both sides w.r.t. $y$, we have :\n\\begin{align*}\n    \\int_{-\\infty}^{\\infty} 2 y^2 \\exp[-y^2] \\sigma \\sqrt{2} \\ dy &= \\sigma \\sqrt{2 \\pi} \\\\\n    \\int_{-\\infty}^{\\infty} \\frac{2}{\\sqrt{\\pi}} \\exp[-y^2]  y^2  \\ dy &= 1\n\\end{align*}\n\nSubstitude back in, we have:\n\\begin{align*}\n    m_2 &= \\sigma^2\n\\end{align*}\n\n\\subsection{}\nFor 1.4, first, we have:\n\\begin{align*}\n    m_1 &= E_{x \\sim p(x)}[x] \\\\\n    &= \\int_{a}^{\\infty} p(x) x \\ dx \\\\\n    &= \\frac{1}{\\mathcal{Z}} \\int_{a}^{\\infty} \\frac{1}{x^\\gamma} x \\ dx \\\\\n    &= \\frac{1}{\\mathcal{Z}} \\int_{a}^{\\infty} x^{1-\\gamma} \\ dx \\\\\n    &= \\frac{1}{\\mathcal{Z}} \\frac{1}{2-\\gamma} [x^{2-\\gamma}] \\biggr\\rvert_a^{\\infty} \\\\\n\\end{align*}\n\nWe can see, (1) in the case of $\\gamma<=2$, $m_1 \\rightarrow \\infty$; \n\n(2) in the case of $\\gamma>2$, $x^{2-\\gamma} |_a^{\\infty}=-a^{2-\\gamma}$, so:\n\\begin{align*}\n    m_1 \n    &= a^{\\gamma-1} (\\gamma-1) \\frac{1}{2-\\gamma} (-a^{2-\\gamma}) \\\\\n    &= \\frac{\\gamma-1}{\\gamma-2} \\cdot a \\\\\n\\end{align*}\n\nNow in order to calculate $m_2$, we need $m_1$ to be finite, (and for case $\\gamma<=2$ we don't have finite $m_2$ ):\n\\begin{align*}\n    m_2 &= E_{x \\sim p(x)}[(x-m_1)^2] \\\\\n    &= \\frac{1}{\\mathcal{Z}} \\int_{a}^{\\infty} x^{-\\gamma} (x-m_1)^2 \\ dx \\\\\n    &= \\frac{1}{\\mathcal{Z}} \\int_{a}^{\\infty} x^{-\\gamma} (x^2 - 2 m_1 x + m_1 ^2) \\ dx \\\\\n    &= \\frac{1}{\\mathcal{Z}} \\int_{a}^{\\infty} (x^{2-\\gamma} - 2 m_1 x^{1-\\gamma} + m_1 ^2 x^{-\\gamma}) \\ dx \\\\\n\\end{align*}\n\nFor the same argument when calculating $m_1$, we can see, (1) in the case of $\\gamma<=3$, $m_2 \\rightarrow \\infty$;\n\n(2) in the case of $\\gamma>3$, we have:\n\\begin{align*}\n    m_2 &= \\frac{1}{\\mathcal{Z}} \\int_{a}^{\\infty} (x^{2-\\gamma} - 2 m_1 x^{1-\\gamma} + m_1 ^2 x^{-\\gamma}) \\ dx \\\\\n    &= a^{\\gamma-1} (\\gamma-1) \\biggr[ \\int_{a}^{\\infty} (x^{2-\\gamma} - 2 m_1 x^{1-\\gamma} + m_1 ^2 x^{-\\gamma}) \\ dx \\biggr] \\\\\n    &= a^{\\gamma-1} (\\gamma-1) \\biggr[ \\int_{a}^{\\infty} x^{2-\\gamma} \\ dx - 2 m_1 \\int_{a}^{\\infty} x^{1-\\gamma} \\ dx + m_1 ^2 \\int_{a}^{\\infty} x^{-\\gamma} \\ dx \\biggr] \\\\\n    &= a^{\\gamma-1} (\\gamma-1) \\biggr[ \\frac{a^{3-\\gamma}}{\\gamma-3} - 2 m_1 \\frac{a^{2-\\gamma}}{\\gamma-2} + m_1 ^2 \\frac{a^{1-\\gamma}}{\\gamma-1} \\biggr] \\\\\n    &= a^{\\gamma-1} (\\gamma-1) \\biggr[ \\frac{a^{3-\\gamma}}{\\gamma-3} - 2 \\frac{\\gamma-1}{\\gamma-2} \\cdot a \\frac{a^{2-\\gamma}}{\\gamma-2} + (\\frac{\\gamma-1}{\\gamma-2} \\cdot a)^2 \\frac{a^{1-\\gamma}}{\\gamma-1} \\biggr] \\\\\n    &= a^2 (\\gamma-1) \\biggr[ \\frac{1}{\\gamma-3} - 2 \\frac{\\gamma-1}{\\gamma-2} \\frac{1}{\\gamma-2} + (\\frac{\\gamma-1}{\\gamma-2})^2 \\frac{1}{\\gamma-1} \\biggr] \\\\\n    &= a^2 (\\gamma-1) \\biggr[ \\frac{1}{\\gamma-3} - 2 \\frac{\\gamma-1}{(\\gamma-2)^2} + \\frac{\\gamma-1}{(\\gamma-2)^2} \\biggr] \\\\\n    &= a^2 (\\gamma-1) \\biggr[ \\frac{1}{\\gamma-3} - \\frac{\\gamma-1}{(\\gamma-2)^2} \\biggr] \\\\\n    &= a^2 \\biggr[ \\frac{\\gamma-1}{\\gamma-3} - \\frac{(\\gamma-1)^2}{(\\gamma-2)^2} \\biggr] \\\\\n\\end{align*}\n\n\\subsection*{Comments}\nWhen analyzing data, we can compute the 1st and 2nd moment of the samples, and guess the distribution according to them.\n\nFor example, if we found $m_2 = m_1^2$, it might suggest that the data is from an exponential distribution.\n\n\\section{Simulation}\nPython code please refer to:\n\n\\href{https://github.com/liusida/ds2/blob/main/assignment2/code/}{https://github.com/liusida/ds2/blob/main/assignment2/code/}\n\n\\input{table}\n\n\\subsection*{Convergence}\nThe estimated $m_1$ and $m_2$ converge to analytical solutions of $m_1$ and $m_2$.\nThe variance of $m_1$ and $m_2$ decrease with $K$.\nYes, the simulation confirms the analytical solutions are good.\n\n\n\\section{Derivation from (11) to (12)}\nBecause the constraints are:\n\\begin{align*}\n    E_{x \\sim p(x)}[f_i(x)] = F_i\n\\end{align*}\nfor $1 \\leq i \\leq I$, let's write the function $J$ in this way:\n\\begin{align*}\n    J = \\sum_x p(x) \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\lambda_i (E_{x \\sim p(x)}[f_i(x)]-F_i)\n\\end{align*}\nAnd we start to solve for $\\partial_{p(x)} J = 0$, we have:\n\\begin{align*}\n    \\partial_{p(x)} \\biggr[ \\sum_x p(x) \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\lambda_i \\biggr(E_{x \\sim p(x)}[f_i(x)]-F_i\\biggr) \\biggr] &= 0 \\\\\n    \\partial_{p(x)} \\biggr[ \\sum_x p(x) \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\lambda_i \\biggr(\\sum_{x} p(x) f_i(x)-F_i\\biggr) \\biggr] &= 0 \\\\\n    \\sum_x \\partial_{p(x)} p(x) \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\partial_{p(x)} \\lambda_i \\biggr(\\sum_{x} p(x) f_i(x)-F_i\\biggr) &= 0 \\\\\n    \\sum_x \\partial_{p(x)} p(x) \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\partial_{p(x)} \\lambda_i \\sum_{x} p(x) f_i(x) - \\sum_{1 \\leq i \\leq I} \\partial_{p(x)} \\lambda_i F_i &= 0 \\\\\n    \\sum_x \\partial_{p(x)} p(x) \\log \\frac{1}{p(x)} - \\sum_x \\partial_{p(x)} p(x) \\sum_{1 \\leq i \\leq I} \\lambda_i f_i(x) - 0 &= 0 \\\\\n    \\sum_x \\partial_{p(x)} p(x) \\biggr[ \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\lambda_i f_i(x) \\biggr] &= 0 \\\\\n\\end{align*}\nBecause in general $\\partial_{p(x)} p(x) \\neq 0$, so:\n\\begin{align*}\n    \\log \\frac{1}{p(x)} - \\sum_{1 \\leq i \\leq I} \\lambda_i f_i(x) &= 0 \\\\\n    \\log p(x) &= - \\sum_{1 \\leq i \\leq I} \\lambda_i f_i(x)  \\\\\n    p(x) &= \\exp \\biggr( - \\sum_{1 \\leq i \\leq I} \\lambda_i f_i(x) \\biggr) \\\\\n\\end{align*}\nThough ``$\\propto$'' is used in the lecture note, but since $\\lambda_i$ can be any constants, I think it is OK to use ``$=$''.\n\n\\section{Prove there is a maximum entropy distribution on R}\nProof:\n\nThe Normal distribution is a maximum entropy distribution, and the Normal distribution has a support of $R$,\nthus there is a maximum entropy distribution on $R$.\n\n\\end{document}", "meta": {"hexsha": "b2c7a212c9cb46481626f10703fc5c24b8a4368c", "size": 13976, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment2/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": "assignment2/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": "assignment2/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": 44.5095541401, "max_line_length": 217, "alphanum_fraction": 0.5480108758, "num_tokens": 6024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6556700535702354}}
{"text": "\\section{Introduction: Covering spaces}\nA continuous map between spaces $p: Y \\rightarrow X$ is a \\emph{cover} or a \\emph{covering map} if every point $x \\in X$ has an open neighborhood $U$ such that \\begin{enumerate}\n  \\item $p^{-1}(U)$ is a disjoint union of open sets $\\sqcup_{i \\in \\cali} U_i$,\n  \\item $p$ restricted to each $U_i$ is an isomorphism.\n\\end{enumerate}\n% \\footnote{We'll later on show that the size of fiber does not depend on the point $x$.}\n\\begin{figure}[H]\n  \\centering\n  \\input{images/pancake.tex}\n  \\caption{Pancake picture of covering spaces}\n\\end{figure}\n$U$ is said to be an \\emph{evenly covered neighborhood}.\nIf $\\abs{p^{-1}(x)} = k$ for ever $x \\in X$, we say that $p$ is a $k$-cover.\n\n\\begin{ex}\n  The most basic example of a covering space is\n  \\begin{equation*}\n    I \\rightarrow \\{*\\}\n  \\end{equation*}\n  where $I$ is a discrete set.\n  This is not very interesting, so from now on \\textbf{we will assume that all our spaces connected.}\n\\end{ex}\n\n\\begin{ex}\n  The only connected cover of $[0,1]$ is the space $[0,1]$ inself.\n\\end{ex}\n\n\\begin{ex}\n  The first non-trivial example of a cover comes from a circle.\n  \\begin{align*}\n    S^1 &\\longrightarrow S^1 \\\\\n    \\theta \\mod 2 \\pi &\\longmapsto n \\theta \\mod 2\\pi\n  \\end{align*}\n  The real line is also a cover of $S^1$.\n  \\begin{align*}\n    \\bbr^1 &\\longrightarrow S^1 \\\\\n    \\theta &\\longmapsto \\theta \\mod 2\\pi\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Turns out, the cylinder is a 2-covering of a mobius strip.\n  It is hard to describe this using coordinates or equations, we'll instead do this combinatorially.\n\\end{ex}\n\n\n\n\n\n\n\\subsection{Spaces}\nWe will use cell complexes as a combinatorial model for spaces.\nA \\emph{2-cell complex} $X$ is a triple $(V, E, F)$ consisting of:\n  \\begin{enumerate}\n    \\item A non-empty set of vertices $V$.\n    \\item A set of directed edges $E$. For each edge $e \\in E$, denote by $d_0 e$ and $d_1 e$ the starting and ending vertex of $e$ respectively. Denote by $e^{-1}$ the same edge but going in the opposite direction so that $d_0 e^{-1} = d_1 e$ and $d_1 e^{-1} = d_0 e$.\n    \\item A set of faces $F$.\n  \\end{enumerate}\n  We further assume that our cell complexes are\n  \\begin{enumerate}\n    \\item \\emph{locally finite} i.e. there are finitely many edges between any two vertices, and\n    \\item \\emph{connected} i.e. there is a path of undirected edges connecting any two vertices.\n  \\end{enumerate}\n\nA \\emph{simplical map} between two cell complexes $p: X_0 \\rightarrow X_1$ is a compatible triple of maps.\n\\begin{align*}\n  V_0 \\rightarrow V_1 && E_0 \\rightarrow E_1 && F_0 \\rightarrow F_1\n\\end{align*}\nA simplical map is a covering space map if the induced map on the underlying topological spaces is one.\n\n\\begin{remark}\n  Not every continuous map can be represented by a simplicial map, but every covering map can be. Further, there are more than one ways to describe a space using a graph.\n\\end{remark}\n\n\n\n\n\n\n\\subsubsection{Example: Covers of $S^1$}\nFor every integer $n$, there exists a unique $n$-cover of a circle.\n  \\begin{figure}[H]\n  \\centering\n    \\begin{tikzpicture}[thick]\n      \\begin{scope}[shift={(3,0)}, scale=0.5]\n        \\input{images/circle.tex}\n      \\end{scope}\n\n      \\draw [->] (-0.5,0) to node[midway, above] {$p$} (2.5,0);\n\n      \\begin{scope}[shift={(-3,0)}]\n        \\input{images/circle.tex}\n      \\end{scope}\n    \\end{tikzpicture}\n    \\caption{2-covering of a circle}\n  \\end{figure}\n  Further, these covering maps form a poset: $nS^1$ is a cover of $mS^1$ if and only if $m$ divides $n$.\n  $S^1$ has an infinite covering given by the real line.\n\n  \\begin{figure}[H]\n  \\centering\n    \\begin{tikzpicture}[thick]\n      \\begin{scope}[shift={(3,0)}, scale=0.5]\n        \\filldraw (0,0) circle (4pt);\n        \\draw [->] (0,0) to [bend left=45] (1,1) to [bend left=45] (2,0);\n        \\draw (2,0) to [bend left=45] (1,-1)  node [below] {$S^1$} to [bend left=45] (0,0);\n      \\end{scope}\n\n      \\draw [->] (-0.5,0) to node[midway, above] {$p$} (2.5,0);\n\n      \\begin{scope}[shift={(-5,0)}, scale=0.5]\n        \\filldraw (0,0) circle (4pt)\n                  (2,0) circle (4pt)\n                  (4,0) circle (4pt)\n                  (6,0) circle (4pt);\n        \\draw [dashed] (-1,0) to (0,0);\n        \\draw [->] (0,0) to (1,0);\n        \\draw (1,0) to (2,0);\n        \\draw [->] (2,0) to (3,0);\n        \\draw (3,0) to node[midway, below] {$\\bbr^1$} (4,0);\n        \\draw [->] (4,0) to (5,0);\n        \\draw (5,0) to (6,0);\n        \\draw [dashed] (6,0) to (7,0);\n      \\end{scope}\n    \\end{tikzpicture}\n    \\caption{Covering of $S^1$ by $\\bbr^1$.}\n  \\end{figure}\n\n  We will show that these covering spaces correspond to the subgroups of $\\bbz$ and the inclusions of subgroups correspond to covering maps.\n  \\begin{align*}\n    n \\bbz &\\longleftrightarrow nS^1 \\\\\n    \\set{0} &\\longleftrightarrow \\bbr^1 \\\\\n    n \\bbz \\subseteq d \\bbz &\\longleftrightarrow nS^1 \\rightarrow dS^1\n  \\end{align*}\n  This is because the fundamental group of the circle is $\\bbz$.\n\n\n  \\subsection{Example: $S^1 \\vee S^1$}\n  The space $S^1 \\vee S^1$ (two circles glued at point) with 1 vertex, 2 edges, and 0 faces has very interesting covering spaces, see Figure \\ref{fig:CoveringsOfS1S1}. The meanings of the various notations in Figure \\ref{fig:CoveringsOfS1S1} will become clear later.\n  \\begin{figure}[H]\n  \\centering\n    \\begin{tikzpicture}[thick, scale=0.75]\n      \\input{images/s1s1.tex}\n    \\end{tikzpicture}\n    \\caption{$S^1 \\vee S^1$}\n  \\end{figure}\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    \\label{fig:CoveringsOfS1S1}\n  \\end{figure}\n\n\n\n\n\n\n  \\subsubsection{Example: Gluing diagrams}\n  We can form surfaces using 2-complexes, however these are harder to describe on paper.\n  Instead, we use a trick called \\emph{gluing diagrams}, Figure \\ref{fig:GluingDiagrams}.\n  These are ways to draw non-planar things on a plane, so there is some ambiguity and gluing going on in a gluing diagram that you should be careful about.\n\n  \\begin{qbox}\n    In each of the gluing diagrams in Figure \\ref{fig:GluingDiagrams}, count the number of vertices, edges, and faces.\n  \\end{qbox}\n\n  \\begin{qbox}\n    Show that there are 2-cover maps\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  \\begin{qbox}\n    Guess the poset of covers of\n    \\begin{enumerate}\n      \\item Cylinder,\n      \\item Mobius Strip,\n      \\item Torus.\n    \\end{enumerate}\n    Can you interpret these posets as subgroups of some groups?\n  \\end{qbox}\n\n\n  \\begin{figure}[p]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{cylinderGluingDiagram.png}\n    \\includegraphics[width=0.8\\textwidth]{MobiusStripGluingDiagram.png}\n\n    \\includegraphics[width=0.8\\textwidth]{torusGluingDiagram.png}\n    \\includegraphics[width=0.8\\textwidth]{KleinBottleGluingDiagram.png}\n\n    \\includegraphics[width=0.8\\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    \\label{fig:GluingDiagrams}\n  \\end{figure}\n", "meta": {"hexsha": "a698ec7dfa876c8109c5b08f66771ddfe7d65f6d", "size": 7365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.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": "01.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": "01.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": 36.6417910448, "max_line_length": 269, "alphanum_fraction": 0.661371351, "num_tokens": 2439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.6556700454846133}}
{"text": "%% SECTION HEADER /////////////////////////////////////////////////////////////////////////////////////\r\n\\section{Example: Equations}\r\n\\label{sec12}\r\n\r\n%% SECTION CONTENT ////////////////////////////////////////////////////////////////////////////////////\r\n\r\nThis section shows a few equation examples. Labels can be used to reference equations.\r\n\\begin{itemize}\r\n\t\\item Example (Equation \\ref{eq:1_1})\r\n\t\\item Example (Equation \\ref{eq:1_2})\r\n\t\\item Example (Equation \\ref{eq:1_3})\r\n\t\\item Example (Equation \\ref{eq:1_4})\r\n\t\\item Example (Equation \\ref{eq:1_5})\r\n\\end{itemize}\r\n\r\n\\begin{equation}\r\n\\label{eq:1_1}\r\n\\overline{M}_{i}=\\iint\\limits_A \\rho\\;u_{i}\\left(u_{k}\\;n_{k} \\right)\\;dA\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n\\label{eq:1_2}\r\nV_{REF} = \\left( \\frac{2 \\times 144 \\times P_{DYN}}{\\rho} \\right)^{\\frac{1}{2}}\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n\\label{eq:1_3}\r\nV_{MOM} = \\left( \\frac{A_{TIP} (\\frac{V_{REF}}{2})^{2} + A_{MIDDLE} V_{REF}^{2} + A_{HUB} V_{HUB}^{2}}{A_{JET} V_{AVG}} \\right)\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n\\label{eq:1_4}\r\n\\begin{aligned}\r\n& Q_{J}= \\int_0^\\delta Vdy+\\left(y-\\delta \\right)b\\;V_{s}\\\\\r\n& Q_{J}= b\\;V_{s} \\int_0^\\delta \\left(\\frac{y}{\\delta} \\right)^\\frac{1}{n}dy+\\left(y-\\delta \\right)b\\;V_{s}\\\\\r\n& Q_{J}=\\frac{b\\;V_{s}}{\\left(\\frac{n+1}{n} \\right)}\\delta+\\left(y-\\delta \\right)b\\;V_{s}\\\\\r\n& Q_{J}=b\\;V_{s}\\left(y-\\frac{\\delta}{n+1} \\right)\r\n\\end{aligned}\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n\\label{eq:1_5}\r\nB_{K_{T_{Jx}}}=\\sqrt{\\left(\\theta_{Q_{J}}B_{Q_{J}} \\right )^{2}+\\left(\\theta_{D}B_{D} \\right )^{2}+\\left(\\theta_{n}B_{n} \\right )^{2}+\\left(\\theta_{ \\alpha }B_{ \\alpha } \\right )^{2}+\\left(\\theta_{\\rho}\\left(B_{\\rho}+\\theta_{\\rho tw}B_{tw} \\right ) \\right )}\r\n\\end{equation}\r\n", "meta": {"hexsha": "201c52728467c77996b5c3c420dd31b536841530", "size": 1733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Chapter1/sect12.tex", "max_stars_repo_name": "SeaShadow/LaTeX-AMC-PhD-Thesis-Template", "max_stars_repo_head_hexsha": "9e8255d5406211b07253fca29788a3557860edc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-09-05T01:29:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T10:40:13.000Z", "max_issues_repo_path": "reports/project_reports/Ijjeh_thesis_template/Chapters/Intro/sect12.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/project_reports/Ijjeh_thesis_template/Chapters/Intro/sect12.tex", "max_forks_repo_name": "IFFM-PAS-MISD/aidd", "max_forks_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-09-11T05:12:18.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-22T10:10:01.000Z", "avg_line_length": 38.5111111111, "max_line_length": 259, "alphanum_fraction": 0.5591459896, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.655670039748734}}
{"text": "\\section{Leave One Covariate Out}\n\n\\begin{frame}[c]\n\\Huge{\\centerline{Leave One Covariate Out}}\n\\end{frame}\n\n%----------------------------------------------------------------------------------------\n\\begin{frame}\\frametitle{Leave One Covariate Out}\n\t\\begin{itemize}\t\t\n\t\t\t\\item Leave-one-covariate-out (LOCO) provides the feature importance values at a per-observation level (i.e. what is the feature importance of $X_j$ for observation $\\mathbf{x}^{(i)}$).\n\t\t\t\\bigskip\n\t\t\t\\item LOCO is calculated by subtracting a model's prediction, $g(\\mathbf{x}^{(i)})$, for a row-observation with all its features, from that model's prediction for the same row \\textit{without} the input feature $X_j$ of interest. \t\n\t\t\\begin{equation}\n                           \\begin{aligned}\\label{eq:rf}\n                            g(\\mathbf{x}_{(-j)}^{(i)}) - g(\\mathbf{x}^{(i)}),\n                            \\end{aligned}\n\t\t\\end{equation}\nwhere $\\mathbf{x}_{(-j)}^{(i)} \\in \\mathcal{P}_{(-j)}$, given that $\\mathcal{P}_{(-j)}$ is the complement set to $\\{X_j\\} \\in \\mathcal{P}$ (i.e $\\{X_j\\} \\cup \\mathcal{P}_{(-j)} = \\mathcal{P}$).\n\t\\end{itemize}\n\\end{frame}\n%----------------------------------------------------------------------------------------\n\n\n\n\n\n", "meta": {"hexsha": "9ac3129597e4cfcd5b655c47b894a6b0a1f67789", "size": 1232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/sections/loco.tex", "max_stars_repo_name": "sparsh999gupta/interpretable-ml", "max_stars_repo_head_hexsha": "a2c06777f686cb8e23c210e23120ccab6650c508", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-08-21T09:37:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-04T17:34:07.000Z", "max_issues_repo_path": "tex/sections/loco.tex", "max_issues_repo_name": "sparsh999gupta/interpretable-ml", "max_issues_repo_head_hexsha": "a2c06777f686cb8e23c210e23120ccab6650c508", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 32, "max_issues_repo_issues_event_min_datetime": "2018-09-03T19:27:19.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-06T21:27:47.000Z", "max_forks_repo_path": "tex/sections/loco.tex", "max_forks_repo_name": "sparsh999gupta/interpretable-ml", "max_forks_repo_head_hexsha": "a2c06777f686cb8e23c210e23120ccab6650c508", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-22T16:22:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T17:24:41.000Z", "avg_line_length": 45.6296296296, "max_line_length": 234, "alphanum_fraction": 0.5267857143, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6556700377273283}}
{"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 03}\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}\nFeature reduction techniques including Exploring All Subsets or Best Subset Selection, Ridge Regression, and Principle Component Analysis (PCA).\n\\end{abstract}\n\n\\newpage\n\\section{Best Subset Selection}\n\\subsection{Problem Description}\nReproduce Figure 3.5 from the \\emph{Elements of Statistical Learning} book. In this exercise, we need to use the prostate cancer data set found on the book's website and explore the performance of linear regression using subsets of the given features. The error for each subset is plotted, and a line indicating the best subsets for each subset size $k$ is indicated.\n\n\\subsection{Results}\nMy figure looks pretty similar to the one in the book, however, I think that the book excluded some points from their figure, which mine does include. I think this because the regression weights (or $\\vec{\\beta}$) match those found in the book, so my results should match theirs very closely.\n\nIt should be noted that in the subsets, the intercept ``feature\" was used \\emph{along with} each subset; the term \\emph{subsets} refers to subsets of the actual features.\n\n  \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=.8\\linewidth]{HW03_Exercise01}\n    \\caption{An error plot for all subsets of features for the prostate cancer data set.}\n    \\label{fig:HW03_Exercise01}\n  \\end{figure}\n\n\\subsection{Code}\nThe following R code was used to reproduce the figure from the book.\n\\begin{verbatim}\n##################\n# STAT775\n# HW 03\n# Exercise 01\n#\n# Reproduce Figure 3-5 from the\n# Elements of Statistical Learning\n# (This is a scatterplot of the\n# errors produced by models built\n# from all possible subsets of\n# predictors, except for an\n# intercept, for simplicity)\n#\n##################\n\n#\n# Initial Setup\n#\nsetwd(\"C:/Users/Terence/Documents/GitHub/STAT775/HW03\")\n# setwd(\"~/STAT775/HW03/\")\n\nRESULTS.FILE.NAME = \"HW03_Exercise01.png\"\nDATA.FILE.NAME <- \"prostate_cancer/prostate_cancer_data\"\n# these include the intercept that gets added to the matrices\nFEATURE.INDICES <- 1:9\nTARGET.INDEX <- 10\nTRAIN.SET.FLAG <- 11\n\n\ndata <- read.table(DATA.FILE.NAME)\n# according to the dataset info, this needs to be done\ndata[, 1:8] <- scale(data[, 1:8], T, T)\nintercept <- rep(1, nrow(data))\ndata <- data.frame(Intercept = intercept, data)\n\n\n# store data with rows as observations\ntrain.data <- data.matrix(subset(data, data$train == T))[, FEATURE.INDICES]\ntrain.targets <- data.matrix(subset(data, data$train == T))[, TARGET.INDEX]\ntest.data <- data.matrix(subset(data, data$train == F))[, FEATURE.INDICES]\ntest.targets <- data.matrix(subset(data, data$train == F))[, TARGET.INDEX]\n\n\n#\n# Regression\n#\nmodel.betas <-\n  solve(t(train.data) %*% train.data) %*% t(train.data) %*% train.targets\n\n\n#\n# Test errors\n#\nfeature.subsets <- set_power(as.set(2:9))  # skip excluding intercept\n\nk <- rep(0, length(feature.subsets))\nsubset.as.string <- rep(\"\", length(feature.subsets))\nerror <- rep(0, length(feature.subsets))\nbest.for.k <- rep(F, length(feature.subsets))\n\nsubset.selection.results <- data.frame(\n  K = k,\n  Subset = subset.as.string,\n  Error = error,\n  Best.For.K = best.for.k,\n  stringsAsFactors = F\n)\n\nindex = 1\nresidual.sum.of.squares <- 0\nfor (subset in feature.subsets) {\n  subset.betas <- matrix(rep(0, 9))\n  subset.betas[1, ] <- model.betas[1, ]\n  for (i in subset) {\n    subset.betas[i, ] <- model.betas[i, ]\n  }\n  \n  # do the eror test here\n  residual.sum.of.squares <- 0.0\n  for (i in 1:nrow(train.data)) {\n    prediction <- t(subset.betas) %*% data.matrix(train.data[i, ])\n    residual.sum.of.squares <-\n      residual.sum.of.squares + (train.targets[i] - prediction)^2\n  }\n  \n  # append the results\n  subset.selection.results$K[[index]] <- length(subset)\n  subset.selection.results$Subset[[index]] <-\n    if(set_is_empty(subset)){\"Empty\"} else{subset}\n  # str_c(list, collapse = ',') or paste(list, collapse = ',')\n  subset.selection.results$Error[[index]] <- residual.sum.of.squares\n  index = index + 1\n}\n\nsubset.selection.results$K <- as.factor(subset.selection.results$K)\n\nfor (level in levels(subset.selection.results$K)) {\n  print(level)\n  working.set <-\n    subset(subset.selection.results, subset.selection.results$K == level)\n  working.set <- working.set[order(working.set$Error), ]\n  best.subset <- working.set[1, \"Subset\"]\n  print(best.subset)\n  i=1\n  for (i in nrow(subset.selection.results)) {\n    if (set_is_equal(best.subset, subset.selection.results[i, \"Subset\"])) {\n      subset.selection.results$Best.For.K[[i]] <- T\n    }\n  }\n}\n\n# have to do this manually because R sux #########\nsubset.selection.results[  1, \"Best.For.K\"] <- T\nsubset.selection.results[  2, \"Best.For.K\"] <- T\nsubset.selection.results[ 10, \"Best.For.K\"] <- T\nsubset.selection.results[ 40, \"Best.For.K\"] <- T\nsubset.selection.results[ 99, \"Best.For.K\"] <- T\nsubset.selection.results[181, \"Best.For.K\"] <- T\nsubset.selection.results[231, \"Best.For.K\"] <- T\nsubset.selection.results[249, \"Best.For.K\"] <- T\nsubset.selection.results[256, \"Best.For.K\"] <- T\n##################################################\n\n\n#\n# Plot Results\n#\nlibrary(ggplot2)\n\nplot.theme <- theme(\n  plot.background = element_blank(), \n  panel.grid.major = element_blank(), \n  panel.grid.minor = element_blank(), \n  panel.border = element_blank(), \n  panel.background = element_blank(),\n  axis.line = element_line(size=.4),\n  axis.title.x = element_text(face=\"bold\", color=\"black\", size=10),\n  axis.title.y = element_text(face=\"bold\", color=\"black\", size=10),\n  plot.title = element_text(face=\"bold\", color = \"black\", size=12)\n)\n\nsubset.error.plot <- ggplot(\n  subset.selection.results,\n  aes(x = K, y = Error, group = Best.For.K)\n) +\n  plot.theme +\n  geom_point(shape = 16, size = 3) +\n  geom_point(aes(color = Best.For.K)) +\n  geom_line(aes(alpha = Best.For.K, color = Best.For.K)) +\n  scale_color_manual(\n    name = \"Selection\",\n    labels = c(\"Other Subsets\", \"Best Subset\"),\n    values = c(\"green\", \"red\")\n  ) +\n  scale_shape_manual(\n    name = \"Selection\",\n    labels = c(\"Other Subsets\", \"Best Subset\"),\n    values = c(16, 8)\n  ) +\n  scale_alpha_discrete(guide = F) + #continuous\n  scale_y_continuous(\n    limits = c(0, 140),\n    breaks = seq(0, 140, 10)\n  ) +\n  labs(\n    title = \"Errors for Subsets of Predictors\",\n    x = \"Subset Size k\",\n    y = \"Residual Sum-of-Squares\"\n  )\n\nggsave(filename = RESULTS.FILE.NAME, plot = subset.error.plot)\n\\end{verbatim}\n\n\\newpage\n\\section{Ridge Regression}\n\\subsection{Problem Description}\nApply the Ridge Regression Technique to the prostate cancer data. Plot the error results as a function of $\\lambda$. The choice of $\\lambda$ values is up to you.\n\n\\subsection{Results}\n  \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=.8\\linewidth]{HW03_Exercise02}\n    \\caption{An error plot for Ridge Regression of the prostate cancer data with varying values of the parameter $\\lambda$.}\n    \\label{fig:HW03_Exercise02}\n  \\end{figure}\n\n\\subsection{Code}\n\\begin{verbatim}\n##################\n# STAT775\n# HW 03\n# Exercise 02\n#\n# Perform Ridge Regression\n# and explore the performance\n# of using different\n# lambda values. Plot the\n# results.\n#\n##################\n\n#\n# Initial Setup\n#\nsetwd(\"C:/Users/Terence/Documents/GitHub/STAT775/HW03\")\n# setwd(\"~/STAT775/HW03/\")\n\nRESULTS.FILE.NAME = \"HW03_Exercise02.png\"\nDATA.FILE.NAME <- \"../DataSets/prostate_cancer/prostate_cancer_data\"\n# no intercept will be applied since we are performing\n# ridge regression\nFEATURE.INDICES <- 1:8\nTARGET.INDEX <- 9\nTRAIN.SET.FLAG <- 10\n\ndata <- read.table(DATA.FILE.NAME)\n# according to the dataset info, this needs to be done\ndata[, FEATURE.INDICES] <- scale(data[, FEATURE.INDICES], center = T, scale = T)\n\n# store data with rows as observations\ntrain.data <- data.matrix(subset(data, data$train == T))[, FEATURE.INDICES]\nintercepts <- rep(1, nrow(train.data))\ntrain.data.with.intercepts <- cbind(intercepts, train.data)\ntrain.targets <- data.matrix(subset(data, data$train == T))[, TARGET.INDEX]\n\ntest.data <- data.matrix(subset(data, data$train == F))[, FEATURE.INDICES]\nintercepts <- rep(1, nrow(test.data))\ntest.data.with.intercepts <- cbind(intercepts, test.data)\ntest.targets <- data.matrix(subset(data, data$train == F))[, TARGET.INDEX]\n\n\n#\n# Ridge Regression\n#\nridge.regression <- function(x, y, lambda) {\n #\n # Args:\n #   x: a matrix of training observations where observations are rows\n #   y: a column vector of regression targets\n #   lamba: the ridge coefficient; larger values reduce the effect of less\n #          relevant features\n\n  lambda.I <- diag(lambda, nrow = ncol(x))\n  model.betas <- solve( (t(x) %*% x) + lambda.I) %*% t(x) %*% y\n  model.betas <- rbind(mean(y), model.betas)\n\n  return(list(\n    beta.hat = matrix(model.betas, nrow = 1)\n  ))\n}\n\npredict <- function(model, x) {\n  #\n  # Args:\n  #   model: an n x 1 column vector of regression coefficients\n  #   x: a ? x n matrix of observation data\n\n  return(model$beta.hat %*% t(x))\n}\n\n#\n# Main\n#\nlambda.values <- seq(from = 0, to = 8, by = .5)\nridge.regression.results <- data.frame(\n  row.names = lapply(as.list(lambda.values), toString),\n  'Lambda' = lambda.values,\n  'RSS' = rep(0, length(lambda.values)),\n  stringsAsFactors = F\n)\n\ntrial <- 1\nfor (lambda in lambda.values) {\n   model <- ridge.regression(x = train.data, y = train.targets, lambda = lambda)\n#   model <- list(beta.hat = matrix(c(2.452, 0.42, 0.238, -0.046, 0.162, 0.227, 0.000, 0.040, 0.133), nrow = 1))\n  predictions <- predict(model, cbind(1, train.data))\n\n  ridge.regression.results[toString(lambda), 'RSS'] <-\n    sum((matrix(train.targets, nrow = 1) - predictions) ^ 2)\n}\n\n#\n# Plot Results\n#\nlibrary(ggplot2)\n\nplot.theme <- theme(\n  plot.background = element_blank(),\n  panel.grid.major = element_blank(),\n  panel.grid.minor = element_blank(),\n  panel.border = element_blank(),\n  panel.background = element_blank(),\n  axis.line = element_line(size=.4),\n  axis.title.x = element_text(face=\"bold\", color=\"black\", size=10),\n  axis.title.y = element_text(face=\"bold\", color=\"black\", size=10),\n  plot.title = element_text(face=\"bold\", color = \"black\", size=12)\n)\n\nerror.plot <- ggplot(\n  ridge.regression.results,\n  aes(x = Lambda, y = RSS)\n) +\n  plot.theme +\n  geom_point(shape = 16, size = 3) +\n  geom_line() +\n  scale_x_continuous(\n    limits = c(-5, 50),\n    breaks = seq(-5, 50, 5)\n  ) +\n  scale_y_continuous(\n    limits = c(35, 80),\n    breaks = seq(35, 80, 5)\n  ) +\n  labs(\n    title = \"Errors for Ridge Regressions Using Varying Lambda Values\",\n    x = \"Lambda\",\n    y = \"Residual Sum-of-Squares\"\n  )\nerror.plot\n\nggsave(filename = RESULTS.FILE.NAME, plot = error.plot)\n\\end{verbatim}\n\n\\newpage\n\\section{Principle Component Analysis}\n\\subsection{Problem Description}\nUse the zipcode digit data from the ESL website, repeat the exercise from HW02 (Na\\\"{i}ve Bayes Classification), but this time use the $16$ best ``Eigen-features\", aka principle components, (or as many as you can if $16$ eigen-vectors do not exist for the data) for classification instead of the $256$ pixel value features.\n\n\\subsection{Results}\nIt might be said that using the principle components performed worse than naive Bayes classification, but only 16 principle component features were used, meaning some information was lost. Perhaps finding an ideal number of principle components or using enough to encode some high percentage of the information would give us extremely good classification results. The confusion matrix below details the classification performance:\n\n\\begin{tabular}{| c || c | c | c | c | c | c | c | c | c | c | c |}\n  \\hline\n  Actual/Prediction &   0 &   1 &   2 &   3 &   4 &   5 &   6 &   7 &   8 &   9 &\\% Correct \\\\\n  \\hline\n  \\hline\n  0                 & 344 &   0 &   5 &   0 &   1 &   3 &   3 &   0 &   2 &   1 & 95.8 \\\\\n  \\hline\n  1                 &   0 & 241 &   2 &   0 &   8 &   1 &   5 &   0 &   6 &   1 & 91.3 \\\\\n  \\hline\n  2                 &   4 &   0 & 182 &   2 &   1 &   6 &   0 &   0 &   3 &   0 & 91.9 \\\\\n  \\hline\n  3                 &   1 &   0 &   2 & 143 &   0 &  15 &   0 &   1 &   4 &   0 & 86.1 \\\\\n  \\hline\n  4                 &   0 &   1 &  10 &   0 & 181 &   2 &   0 &   0 &   0 &   6 & 90.5 \\\\\n  \\hline\n  5                 &   1 &   0 &   0 &   7 &   1 & 144 &   0 &   0 &   4 &   3 & 90.0 \\\\\n  \\hline\n  6                 &   0 &   0 &   3 &   0 &   3 &   4 & 158 &   0 &   2 &   0 & 92.9 \\\\\n  \\hline\n  7                 &   0 &   0 &   4 &   0 &   2 &   4 &   0 & 130 &   4 &   3 & 88.4 \\\\\n  \\hline\n  0                 &   1 &   0 &   3 &   7 &   0 &   6 &   0 &   0 & 150 &   4 & 90.4 \\\\\n  \\hline\n  0                 &   0 &   0 &   2 &   1 &   4 &   0 &   0 &   2 &   6 & 162 & 91.5 \\\\\n  \\hline\n  \\hline\n  Overall           & & & & & & & & & &                                         & 91.43 \\\\\n  \\hline\n\\end{tabular}\n\n\\subsection{Code}\nThe following R code was used to solve the classification problem:\n\\begin{verbatim}\nsetwd(\"C:/Users/Terence/Documents/GitHub/STAT775/HW06\")\n\nDATA.PATH <- \"../DataSets/zip.data/\"\nZIP.TRAIN.FILE.NAME <- paste0(DATA.PATH, \"zip.train\")\nZIP.TEST.FILE.NAME <- paste0(DATA.PATH, \"zip.test\")\n\n\nread.data.tuples <- function(file.path.name) {\n  data.fram.e <- read.table(file.path.name)\n\n  data <- data.matrix(data.fram.e[, -1])\n\n  data.tuple <- list(\n    observations = data,\n    labels = data.matrix(data.fram.e[, 1])\n  )\n  return(data.tuple)\n}\n\n#\n# PCA\n#\n\nget.pca.summary <- function(data, num.components = 20) {\n  #\n  # Args:\n  #   data: an n x m matrix of n observations of m dimensions\n  #   num.components: the number of principle components to keep\n\n  num.component.s <- min(ncol(data), num.components)\n  n.obs <- nrow(data)\n  full.dimensionality <- ncol(data)\n  mu <- colMeans(data)\n\n  # get centered data\n  x <- data\n  for (i in 1:n.obs) {\n    x[i, ] <- data[i, ] - mu\n  }\n\n  # covariance matrix\n  sigma <- t(x) %*% x\n  sigma <- sigma * (1.0 / n.obs)\n\n  eigen.decomposition <- eigen(sigma, F)  # TODO: is cov symmetric? Not sure...\n  eigen.vectors <- eigen.decomposition$vectors[, 1:num.component.s]\n\n  pca.summary <- list(\n    rotation = eigen.vectors,\n    mu = matrix(mu, nrow = 1, ncol = full.dimensionality)\n  )\n\n  return(pca.summary)\n}\n\npredict <- function(pca.summary, data) {\n  #\n  # Args:\n  #   data: an n x d matrix of observations; rows are observations\n  #   pca.summary: a tuple of the rotation matrix (eigenvectors as columns) and\n  #                the mean (row vector of column means) computed in the pca\n  #                computations\n\n  x <- data\n  for (i in 1:nrow(data)) {\n    x[i, ] <- data[i, ] - pca.summary$mu\n  }\n\n  return (t(t(pca.summary$rotation) %*% t(x)))\n}\n\n\ntrain <- read.data.tuples(ZIP.TRAIN.FILE.NAME)\n\npca.model <- get.pca.summary(train$observations, 16)\n\ntrain$observations <- predict(pca.model, train$observations)\n\ntrain.frame <- data.frame('class' = train$labels, train$observations)\n\nCLASSES <- list(0,1,2,3,4,5,6,7,8,9)\nclass.summaries <- list(10)\nfor (k in CLASSES) {\n  data.subset <- subset(train.frame, class == k)\n  n <- nrow(data.subset)\n  mu <- colMeans(data.subset[, -1])\n  sigma <- cov(data.subset[, -1])\n  class.summaries[[k + 1]] <- list(\n    label = k,\n    n = n,\n    mu = mu,\n    sigma = sigma\n  )\n}\n\ngaussian.pdf <- function(k, x) {\n  x <- matrix(x, ncol = 1)\n  scale.f <- 1.0 / sqrt(((2.0 * pi) ^ 16) * det(k$sigma))\n  difference <- x - matrix(k$mu, ncol = 1)\n  exponent <- -0.5 * (t(difference) %*% solve(k$sigma) %*% difference)\n  return(scale.f * exp(exponent))\n}\n\nclassify.object <- function(classes, x) {\n  highest.prob <- 0.0\n  most.probable.class.label <- 0\n  for (i in 1:length(classes)) {\n    prob <- gaussian.pdf(k = classes[[i]], x = x) * classes[[i]]$n\n    if (prob > highest.prob) {\n      highest.prob <- prob\n      most.probable.class.label <- classes[[i]]$label\n    }\n  }\n\n  return(most.probable.class.label)\n}\n\ntest <- read.data.tuples(ZIP.TEST.FILE.NAME)\ntest$observations <- as.matrix(predict(pca.model, test$observations))\ntest$observations <- matrix(\n  test$observations[, 1:16],\n  nrow = nrow(test$observations),\n  ncol = 16\n)\n\nnum.correct <- 0\nconfusion.matrix <- matrix(0, nrow = 10, ncol = 11)\nfor (i in 1:nrow(test$labels)) {\n  prediction <- classify.object(class.summaries, x = test$observations[i, ])\n  if (prediction == test$labels[[i]]) {\n    num.correct <- num.correct + 1\n  }\n\n  confusion.matrix[test$labels[[i]] + 1, prediction + 1] <-\n    confusion.matrix[test$labels[[i]] + 1, prediction + 1] + 1\n\n}\n\ntotals <- rowSums(confusion.matrix)\nfor (i in 1:nrow(confusion.matrix)) {\n  confusion.matrix[i, 11] <- (confusion.matrix[i,i] / totals[[i]]) * 100\n}\n\n\nprint(100 * num.correct / nrow(test$labels))\nprint(confusion.matrix)\n\\end{verbatim}\n\n\\section{The student would like to thank...}\nThe student would like to thank the authors of the Eigen C++ matrix library. This library has proved quick, easy and effective numerous times, this time being no exception. The Eigen library and more information can both be found at\\hfill\\\\\n\\texttt{http://eigen.tuxfamily.org}.\n\n\\end{document}\n", "meta": {"hexsha": "2bfafcbedb9138f697c2637b43546160d01ce9d7", "size": 17375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "STAT775/HW03/HW03.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/HW03/HW03.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/HW03/HW03.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": 31.0267857143, "max_line_length": 430, "alphanum_fraction": 0.6461582734, "num_tokens": 5147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317475, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.6556700349978666}}
{"text": "\n\\section{Linearly separable sets and margin}\nGiven dataset $(\\bm x_i, y_i)$, $i = 1,2,\\cdots,N$, $y$ is the label of $\\bm x$ where $y\\in \\{1,2,\\cdots,k\\}$ or $\\{e_1,e_2,\\cdots,e_k\\}$.\n\n\\begin{definition}[Unbiasedly Linearly Separable]\n\tA collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$ are unbiased\n\tlinearly separable if there exists $\\bm \\theta$ where\n\t\\begin{equation}\n\t\\label{theta}\n\t\\bm\\theta=\n\t\\begin{pmatrix}\n\t\\theta_1\\\\\n\t\\vdots\\\\\n\t\\theta_k\n\t\\end{pmatrix}\n\t\\in \\mathbb{R}^{k\\times d}, \n\t\\end{equation}\n\tsuch that for each $1\\le i\\le k$ and $ j \\neq i$\n\t\\begin{equation}\n\t\\label{eq:3}\n\t\\theta_i x > \\theta_j x,\\ \\forall x\\in A_i.\n\t\\end{equation}\n\tor\n\t\\begin{equation}\n\t\\label{eq:3}\n\t(e_i-e_j)\\cdot\\bm\\theta x > 0,\\ \\forall x\\in A_i,\n\t\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Linearly Separable]\n\tA collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$ are\n\tlinearly separable if there exists $\\bm \\theta = (W,b)$ where\n\t\\begin{equation}\n\t\\label{Wb}\n\tW=\n\t\\begin{pmatrix}\n\tw_1\\\\\n\t\\vdots\\\\\n\tw_k\n\t\\end{pmatrix}\n\t\\in \\mathbb{R}^{k\\times d}, \n\tb=\n\t\\begin{pmatrix}\n\tb_1\\\\\n\t\\vdots\\\\\n\tb_k\n\t\\end{pmatrix}\n\t\\in \\mathbb{R}^{k}, \n\t\\end{equation}\n\tsuch that for each $1\\le i\\le k$ and $ j \\neq i$\n\t\\begin{equation}\n\t\\label{eq:3}\n\tw_ix+b_i > w_jx+b_j,\\ \\forall x\\in A_i.\n\t\\end{equation}\n\tor\n\t\\begin{equation}\n\t\\label{eq:3}\n\t(e_i-e_j)\\cdot(Wx+b) > 0,\\ \\forall x\\in A_i,\n\t\\end{equation}\n\t\n\\end{definition}\n\n\\begin{lemma}{\\label{Interplation}}\n\tDefine\n\t\\begin{equation}\n\t\\label{Gammai}\n\t\\Gamma_i(\\bm\\theta) = \\{x\\in\\mathbb R^n: (Wx+b)_i > (Wx+b)_j,\\ \\forall j \\neq i\\}     \n\t\\end{equation}\n\tThen for any set collection $A_1,\\cdots,A_k$, $\\bm\\theta$ can separate $A_1,\\cdots,A_k$ iff for each $i$, \n\t\\begin{equation}\n\t\\label{AiGamma}\n\tA_i \\subset \\Gamma_i(W,b)  \n\t\\end{equation}\n\\end{lemma}\nWe note that  each $\\Gamma_i(W,b)  $ is a polygon whose boundary consists of hyperplanes\n\\begin{equation}\n\\label{Hij}\nH_{ij}=\\{(w_i-w_j)\\cdot x+(b_i-b_j) = 0\\}, \\quad \\forall j\\neq i.\n\\end{equation}\n\nDenote $\\tilde x = \n\\begin{pmatrix}\nx\\\\\n1\n\\end{pmatrix}\n$, we have $\\bm\\theta \\tilde{x} = Wx+b$. For $x\\in A_i$, then we have\n\n\\begin{lemma}\n\tA collection of subsets $A_1,...,A_k\\subset \\mathbb{R}^d$ are\n\tlinearly separable iff $\\tilde A_1,\\cdots,\\tilde{A}_k$ are unbiasedly linearly separable.\n\\end{lemma}\n\nDenote \n\\begin{align}\n&m_j^i(x,\\bm\\theta) = (e_i - e_j)\\cdot (Wx+b) = (e_i - e_j)\\cdot (\\bm\\theta \\tilde{x}),\\\\\n&\\bm m^i(x,\\bm\\theta) = (m^i_1(x,\\bm\\theta),\\cdots,m^i_{i-1}(x,\\bm\\theta),m^i_{i+1}(x,\\bm\\theta),\\cdots,m^i_{k}(x,\\bm\\theta))\n\\end{align}\neasy to observe that $x$ is correctly classified by $\\bm\\theta$ if and only if $m_j^i(x,\\bm\\theta) > 0$ for all $j\\neq i$.\n\nDefine $\\rho: \\mathbb{R}^{k\\times (d+1)} \\rightarrow \\mathbb{R}$ which can be chosen as $\\rho(\\bm\\theta) = \\|\\bm\\theta\\|$ or  $\\rho(\\bm\\theta) = \\|W\\|$. Notice that when $\\rho(\\bm\\theta) = 0$, $\\bm\\theta$ can not classify any linearly separable set collections. So we only focus on those $\\bm\\theta$ where $\\rho(\\bm\\theta) > 0$.\n\n\n\\begin{definition}[margin]\n\tThe \\textbf{soft margin} $m(\\bm\\theta)$ of a linearly separable subset collection $A_1,...,A_k\\subset \\mathbb{R}^d$ with respect to $\\bm\\theta = (W,b)$ and the \\textbf{feasible separating parameter set} $\\bm\\Theta_0$ is defined as \n\t\\begin{equation}\n\tm(\\bm\\theta) =  \\min_{i} \\min_{x\\in \\tilde{A}_i} \\min_{j\\neq i} m_j^i(x,\\bm\\theta)\n\t\\end{equation}\n\twhere $\\tilde x = \n\t\\begin{pmatrix}\n\tx\\\\\n\t1\n\t\\end{pmatrix}$,  $\\tilde A_i = \\{\\tilde{x}: x\\in A_i\\}$, and $\\bm \\theta \\tilde{x} = Wx + b$, and\n\t\\begin{equation}\n\t\\bm\\Theta_0 = \\{\\bm\\theta: m(\\bm\\theta) > 0, \\forall j\\neq i, x\\in A_i, i = 1,\\cdots,k.\\}\n\t\\end{equation}\n\tAnd we can define the \\textbf{max margin} $m^*$ and the \\textbf{max margin parameter set} $\\bm\\Theta^*$ w.r.t $\\rho(\\cdot)$ as \n\t\\begin{equation}\n\tm^* = \\max_{\\rho(\\bm \\theta)>0}\\ \\frac{m(\\bm\\theta)}{\\rho(\\bm\\theta)} = \\max_{\\rho(\\bm \\theta)= 1}\\ m(\\bm\\theta)\n\t\\end{equation}\n\t\n\t\\begin{equation}\n\t\\bm\\Theta^* = \\mathop{\\rm argmax}_{\\rho(\\bm \\theta)= 1}\\ m(\\bm\\theta).\n\t\\end{equation} \n\\end{definition}\n\n\n\n\\begin{remark}\n\t$m(\\bm\\theta)>0$ implies $\\rho(\\bm\\theta)>0$. Because if $\\rho(\\bm\\theta)$ = 0, namely, $\\bm\\theta = 0$ or $\\bm W = 0$, we have $m(\\bm\\theta) \\leq \\min (b_1-b_2,b_2-b_1) \\leq 0$.\n\\end{remark}\n\nNotice that the min of a famlily of concave functions is still concave, so $m(\\bm\\theta)$ is a concave function w.r.t $\\bm\\theta$. More precisely, $m(\\bm\\theta)$ is a concave homogeneous piecewise linear function w.r.t $\\bm\\theta$. \\\\\nBecause $m(\\cdot)$ is continuous and $\\{\\bm\\theta\\ | \\ \\rho(\\bm\\theta) = 1\\}$ is compact in a finite-dimensional space, we can easily obtain the following lemma:\n\n\\begin{lemma}\n\tIf $\\rho(\\cdot) = \\|\\cdot\\|$ is a norm on $\\mathbb{R}^{k\\times (d+1)} $ then $\\bm\\Theta^*$ must be nonempty.\n\\end{lemma}\n\n\n\\begin{lemma}\n\tIf $\\rho(\\cdot) = \\|\\cdot\\|$ is a strictly convex norm on $\\mathbb{R}^{k\\times (d+1)} $, then $\\bm\\Theta^*$ is a singleton set.\n\\end{lemma}\n\n\n\\begin{proof}\n\tsuppose not, we can find $\\bm\\theta_1\\neq\\bm\\theta_2$ such that $\\|\\bm\\theta_1\\| = \\|\\bm\\theta_2\\| = 1$ and $m(\\bm\\theta_1) = m(\\bm\\theta_2) = m^*$. \\\\\n\t\\indent Take $\\bm\\theta = \\frac{\\bm\\theta_1+\\bm\\theta_2}{2}$, we have $\\|\\bm\\theta\\| < 1$ and $m(\\bm\\theta) \\geq \\frac{m(\\bm\\theta_1)+m(\\bm\\theta_2)}{2} = m^*$ because of the concaveness of $m(\\cdot)$. So we obtain\n\t\\[\n\tm(\\frac{\\bm\\theta}{\\|\\bm\\theta\\|}) > m(\\bm\\theta) \\geq m^*,\n\t\\]\n\twhich leads to a contradiction to the definition of $m^*$.\n\\end{proof}\n\n\n\\begin{lemma}\n\tGiven any $\\bm\\theta \\in \\mathbb{R}^{k\\times (d+1)}$, we have \n\t\\[\n\tm(\\bm\\theta + \\bm{1}\\alpha^T) = m(\\bm\\theta),\n\t\\]\n\tfor any $\\alpha \\in \\mathbb{R}^{d+1}$.\n\\end{lemma}\n\\begin{proof}\n\tWe only need to notice that\n\t\\begin{equation}\n\t\tm^i_j(x,\\bm\\theta + \\bm{1}\\alpha^T) = (\\theta_i + \\alpha)\\tilde{x} - (\\theta_j + \\alpha)\\tilde{x} = (\\theta_i - \\theta_j)\\tilde{x} = m^i_j(x,\\bm\\theta).\n\t\\end{equation}\n\tSo \n\t\\begin{equation}\n\t\tm(\\bm\\theta + \\bm{1}\\alpha^T) = \\min_{i} \\min_{x\\in \\tilde{A}_i} \\min_{j\\neq i} m_j^i(x,\\bm\\theta + \\bm{1}\\alpha^T) = \\min_{i} \\min_{x\\in \\tilde{A}_i} \\min_{j\\neq i} m_j^i(x,\\bm\\theta) = m(\\bm\\theta).\n\t\\end{equation}\n\\end{proof}\n\n\\begin{corollary}\n\t\\begin{equation}\n\t\t\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) \\subset \\mathop{\\rm argmax}_{\\|W\\| = 1} m(\\bm\\theta).\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tThe case of $\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) = \\emptyset$ is trivial. We only consider the situation of $\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) \\neq \\emptyset$. For any $\\bm\\theta^*\\in\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) = \\emptyset$ and any $\\bm\\theta\\in \\{\\bm\\theta: \\|W\\| = 1\\}$ we have \n\t\\begin{equation}\n\t\tm(\\bm\\theta^*) \\geq m(\\bm\\theta + \\bm{1}^T\\alpha) = m(\\bm\\theta)\n\t\\end{equation}\n\twhere $\\alpha = (\\bm{0},-b_1)^T$, which implies $\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) \\subset \\mathop{\\rm argmax}_{\\|W\\| = 1} m(\\bm\\theta).$\n\\end{proof}\n\n\n\\begin{lemma}\n\tIf $\\rho(\\cdot)$ satisfies $\\rho(\\bm\\theta) = \\|W\\|$ where $\\|\\cdot\\|$ is a norm on $\\mathbb{R}^{k\\times d}$,  then $\\bm\\Theta^*$ is nonempty.\n\\end{lemma}\n\n\\begin{proof}\n\tTake $x_i\\in A_i,\\ i = 1,\\dots,k$, then we have\n\t\\begin{align}\n\t(e_j-e_l)\\cdot(W x_j) + b_j - b_l > 0,\\\\\n\t(e_l-e_j)\\cdot(W x_l) + b_l - b_j > 0,\n\t\\end{align}\n\twhich implies\n\t\\begin{equation}\n\t|b_j-b_l|\\leq \\|e_j-e_l\\|(\\|Wx_l\\|+\\|Wx_j\\|)\\leq  (\\sum_{i=1}^{k}\\|e_i\\|)(\\sum_{i=1}^{k} \\|x_i\\|),\n\t\\end{equation}\n\tfor all $i \\neq j$, $ (W,b)\\in \\bm\\Theta_0$.\\\\\n\tAccording to the last corollary, we only need to prove that $\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) \\neq \\emptyset.$ Because $b_1 = 0$, we fix $l = 1$, let $j \\neq 1$, and we obtain\n\t\\begin{equation}\n\t\t|b_j|\\leq (\\sum_{i=1}^{k}\\|e_i\\|)(\\sum_{i=1}^{k} \\|x_i\\|),\n\t\\end{equation}\n\tfor all $j \\neq 1$. so $\\overline{\\{\\bm\\theta: \\|W\\| = 1, b_1 = 0\\}\\cap \\bm\\Theta_0}$ is closed and bounded, thus compact, which implies $\\mathop{\\rm argmax}_{\\|W\\| = 1, b_1 = 0} m(\\bm\\theta) \\neq \\emptyset.$\n\\end{proof}\n\n\n\\section{Relation between margin and geometric margin}\nSuppose that $X$ is a banach space with norm $\\|\\cdot\\|$, $f$ is a bounded linear functional on $X$. Denote the kernel of $f$ as $\\ker f$, then we can induce a quotient space $X/\\ker f = \\{x + \\ker f : x\\in X\\}$, and we denote $x+\\ker f $ as $[x]$. According to the quotient space theory in functional analysis, we can define a norm $\\|\\cdot\\|_q$ on $X/\\ker f$ as\n\\begin{equation}\n\t\\|[x]\\|_q = \\inf_{y\\in \\ker f} \\|x-y\\| = d(x, \\ker f),\n\\end{equation}\nwhere $d$ is a distance induced by norm $\\|\\cdot\\|$ on $X$, and $X/\\ker f$ is a banach space. Also we can define a linear functional $f_q$ on $X/\\ker f$ such that\n\\begin{equation}\n\tf_q([x]) = f(x),\n\\end{equation}\neasy to check that $f_q$ is bounded and $\\|f_q\\| = \\|f\\|$. Because $\\ker f$ is a maximal linear subspace of $X$, so $X/\\ker f$ is a one-dimensional linear space. Thus we have\n\\begin{equation}\n\t|f_q([x])| = \\|f_q\\|_{dual} \\|[x]\\|_q,\n\\end{equation}\nor namely,\n\\begin{equation}\n\t|f(x)| = \\|f\\|_{dual} \\inf_{y\\in \\ker f} \\|x-y\\| = d(x,\\ker f).\n\\end{equation}\nSuppose that $x_0$ satisfy $f(x_0) + b = 0$, then\n\\begin{equation}\n\t|f(x) + b| = \\|f(x-x_0)\\| = \\|f\\|_{dual} \\inf_{y\\in \\ker f} \\|x-x_0-y\\| = \\|f\\|_{dual} d(x, x_0+\\ker f)\n\\end{equation}\nSo $\\frac{|f(x)+b|}{\\|f\\|_{dual}}$ equals to the distance between $x$ and a hyperplane $\\{x: f(x) + b = 0\\}$ in a sense of norm $\\|\\cdot\\|$ on $X$. Specially, if $X$ is a Hilbert space, then there must exist a $w \\in X$ such that $f(x) = <x,w>$. and we have\n\\begin{equation}\n\t\\frac{|<x,w>+b|}{\\|w\\|_{dual}} = \\inf_{y\\in\\{x: <x,w> + b = 0\\}} \\|x-y\\|.\n\\end{equation}\n\n\\begin{definition}[Geometric margin]\n\tSuppose that $k$ subsets of $\\mathbb{R}^n$, $A_1,...,A_k$ are linearly separable by $\\bm\\theta = (W,b)$,\n\tthe \\textbf{geometric margin} of separation with respect to a metric \n\t$d$ is given by\n\t\\begin{equation}\n\t\\widehat{m}(\\bm\\theta) = \\min_{i} \\min_{x\\in A_i} d(x,\\partial\\Gamma_i(\\bm\\theta)).\n\t\\end{equation}\n\twhere \n\t\\begin{equation}\n\td(x,\\partial\\Gamma_i(\\bm\\theta)) = \\min_{y\\in \\partial\\Gamma_i(\\bm\\theta) } d(x,y).\n\t\\end{equation}\n\\end{definition}\n\n\\begin{lemma}\n\tIf $d$ is a metric induced by a norm $\\|\\cdot\\|$, we have\n\t\\begin{equation}\n\t\\widehat{m}(\\bm\\theta) =  \\min_{i} \\min_{x\\in A_i} \\min_{j\\neq i} \\frac{m_j^i(x,\\bm\\theta)}{\\|w_i-w_j\\|_{dual}}.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{lemma}\n\tIf $\\rho(\\bm\\theta) = \\|W\\|$, there must exist a positive number $\\alpha$ which relies on the choice of vector and matrix norm such that \n\t\\begin{equation}\n\t\tm(\\bm\\theta) \\leq \\alpha \\widehat{m}(\\bm\\theta), \\ \\forall \\bm\\theta\\in \\bm\\Theta_0,\n\t\\end{equation}\n\tor namely, geometric margin can always dominate margin.\n\\end{lemma}\n\\begin{proof}\n\tNotice that for any classifiable $\\bm\\theta$ (which means $\\bm\\theta\\in\\bm\\Theta_0$), we have\n\t\\begin{equation}\n\t\t\\widehat{m}(\\bm\\theta) \\geq \\frac{1}{2} \\min_{i} \\min_{x\\in A_i} \\min_{j\\neq i} \\frac{m_j^i(x,\\bm\\theta)}{\\max_i \\|w_i\\|} = \\frac{\\|W\\|}{2\\max_i \\|w_i\\|} m(\\bm\\theta)\n\t\\end{equation}\n\tBecause $2\\max_i \\|w_i\\|$ is also a matrix norm of $W$, so there must exist a positive number $\\alpha$ such that \n\t\\begin{equation}\n\t\t\\frac{\\|W\\|}{2\\max_i \\|w_i\\|} \\geq \\frac{1}{\\alpha},\\ \\forall W\\neq 0.\n\t\\end{equation}\n\tthus we obtain $m(\\bm\\theta) \\leq \\alpha \\widehat{m}(\\bm\\theta), \\ \\forall \\bm\\theta\\in \\bm\\Theta_0$.\n\\end{proof}\n\n\nNext, we will discuss the equivalence between margin maximization and geometric margin maximization in binary classification ($k = 2$). To simplify the statement, we may just denote $m(\\bm\\theta)$ and $\\tilde{m}(\\bm\\theta)$ as $m(w_1,w_2,b)$ and $\\widehat{m}(w_1,w_2,b)$. An easy observation is that\n\\begin{equation}\n\t\\widehat{m}(w_1+w,w_2+w,b) = \\widehat{m}(w_1,w_2,b),\\ \\forall w\\in \\mathbb{R}^{1\\times d}.\n\\end{equation}\nSpecailly, if we take $w = -\\frac{w_1+w_2}{2}$, we have\n\\begin{equation}\n\\widehat{m}(w_1,w_2,b) = \\widehat{m}(\\frac{w_1-w_2}{2},\\frac{w_2-w_1}{2},b).\n\\end{equation}\nSo without loss of classifiers, we may restrict $W$ to have the form $W = \\begin{pmatrix}\nw\\\\\n-w\n\\end{pmatrix}$ when maximizing geometric margin. \n\n\n\\begin{lemma}\n\tIf $k = 2$ and $\\rho(\\bm\\theta) = \\|W\\| = \\max_i \\|w_i\\|$, then $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} m(\\bm\\theta)$ and  $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} \\widehat{m}(\\bm\\theta)$ contains the same classifiers.\n\\end{lemma}\n\\begin{proof}\nNotice that \n\\begin{equation}\n\t\\max_i \\|w_i +w\\| \\geq \\frac{1}{2}\\|w_1-w_2\\|, \\forall w\\in \\mathbb{R}^{1\\times d},\n\\end{equation}\nand the equality holds when $w = -\\frac{w_1+w_2}{2}$, which implies\n\\begin{equation}\n\tm(w_1,w_2,b) \\leq m(\\frac{w_1-w_2}{2},\\frac{w_2-w_1}{2},b).\n\\end{equation}\nSo both margin maximization and geometric margin maximization can be restricted on $\\{\\bm\\theta: W = \\begin{pmatrix}\nw\\\\-w\n\\end{pmatrix}\\}$ without loss of classifiers. Notice that\n\\[\nm(w,-w,b) = 2\\widehat{m}(w,-w,b),\n\\]\nso $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} m(\\bm\\theta)$ and  $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} \\widehat{m}(\\bm\\theta)$ contains the same classifiers.\n\\end{proof}\n\n\\begin{lemma}\n\tIf $k = 2$ and $\\rho(\\bm\\theta) = \\|W\\| = \\|w_1\\| + \\|w_2\\|$, then $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} m(\\bm\\theta)$ and  $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} \\widehat{m}(\\bm\\theta)$ contains the same classifiers.\n\\end{lemma}\n\n\\begin{proof}\n\tWe only need to notice that\n\t\\begin{equation}\n\t\\|w_1+w\\| + \\|w_2+w\\| \\geq \\|w_1-w_2\\|, \\forall w\\in \\mathbb{R}^{1\\times d},\n\t\\end{equation}\n\tand the equality holds when $w = -\\frac{w_1+w_2}{2}$. The rest are the same to the proof of the last lemma .\n\n\\end{proof}\n\n\\begin{lemma}\n\tIf $k = 2$ and $\\rho(\\bm\\theta) = \\|W\\| = (\\|w_1\\|^p + \\|w_2\\|^p)^{\\frac{1}{p}}$ where $p\\geq 1$, then $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} m(\\bm\\theta)$ and  $\\mathop{\\rm argmax}_{\\bm\\theta\\in \\bm\\Theta_0} \\widehat{m}(\\bm\\theta)$ contains the same classifiers.\n\\end{lemma}\n\n\\section{Margin Maximizing Loss Functions}\n\nDenote the extended real number system as $\\bar{\\mathbb{R}} = \\mathbb{R}\\cup \\{-\\infty,+\\infty\\}$ and we use $\\bm m = (m_1,m_2,\\cdots,m_{k-1})$ to represent an elemnt of $\\bar{\\mathbb{R}}^k$. Consider functions $l: \\bar{\\mathbb{R}}^{k-1} \\rightarrow \\mathbb{R}$ with the following assumptions:\n\\begin{itemize}\n\t\\item $l(\\cdot)$ is commutative and decreasing in each coordinate, and is continuous on $\\bar{\\mathbb{R}}^{k-1}$.\n\t\\item There exists a $T>0$ in $\\bar{\\mathbb{R}} $ such that \n\t\\begin{equation}\n\tl(\\bm m)\n\t\\begin{cases}\n\t> 0,\\ \\ \\min_i m_i < T,\\\\\n\t= 0,\\ \\ \\min_i m_i \\geq T.\n\t\\end{cases}\n\t\\end{equation}\n\tNotice that when $T = \\infty$, $l(\\bm m) = 0$ if and only if $m_i = \\infty$ for all $i = 1,2,\\cdots,k-1$.\n\t\\item If $T = \\infty$, we assume for any $\\bm u, \\bm v \\in \\bar{\\mathbb{R}}^{k-1}$ where $\\min_i u_i < \\min_i v_i$ must satisfy\n\t\\begin{equation}\n\t\\lim\\limits_{t\\rightarrow \\infty}\\frac{l(t\\bm u)}{l(t\\bm v)} = \\infty.\n\t\\end{equation}\n\tSpecially, we have\n\t\\begin{equation*}\n\t\\lim\\limits_{t\\rightarrow \\infty}\\frac{l(tu,\\infty,\\cdots,\\infty)}{l(tv,tv,\\cdots,tv)} = \\infty,\\ \\ \\forall u<v.\n\t\\end{equation*}\n\t\n\\end{itemize}\n\nDenote that $R: \\mathbb{R}^{+}\\rightarrow \\mathbb{R}^{+}$ which is a strictly increasing function such that $R(0) = 0$ and $R(x) \\rightarrow +\\infty$ as $x\\rightarrow +\\infty$. The final loss function has the following fomulation\n\\begin{equation}\nL(\\bm\\theta,\\lambda) = \\sum_{i =  1}^{k} \\sum_{x\\in A_i} l(\\bm m^i(x,\\bm  \\theta)) + \\lambda R(\\rho(\\bm\\theta))\n\\end{equation}\nAnd we denote the optimal parameter set of the above problem as\n\\begin{equation}\n\\bm\\Theta(\\lambda) = \\mathop{\\rm argmin}_{\\bm\\theta} L(\\bm\\theta,\\lambda) \n\\end{equation}\n\n\n\n\\begin{lemma}\n\tIf $\\rho: \\bm\\theta \\mapsto \\|\\bm\\theta\\|$ where $\\|\\cdot\\|$ is a norm on $\\mathbb{R}^{k\\times (d+1)} $, then $\\bm\\Theta(\\lambda)$ must be nonempty for any $\\lambda > 0$.\n\\end{lemma}\n\n\\begin{lemma}\n\tIf $\\rho: \\bm\\theta \\mapsto \\|W\\|$ where $\\|\\cdot\\|$ is a norm on $\\mathbb{R}^{k\\times d} $, then $\\bm\\Theta(\\lambda)$ must be nonempty for sufficiently small $\\lambda > 0$.\n\\end{lemma}\n\n\nHere we show the loss function of logistic regression and SVM as examples.\n\nLogistic regression($T = \\infty$):\\\\\n\\[\n\\sum_{i =  1}^{k} \\sum_{x\\in A_i} \\log(1+\\sum_{j\\neq i} e^{(\\theta_j - \\theta_i) x}) + \\lambda R(\\rho(\\bm\\theta))\n\\]\n\nwhere\n\\[\nl(\\bm m) = \\log(1 + \\sum_{j}^{k-1} e^{-m_j})\n\\]\n\n\\indent Support vector machine($T = 1$):\\\\\n\\[\n\\sum_{i =  1}^{k} \\sum_{x\\in A_i}\\sum_{j\\neq i} {\\rm ReLU}(1 - (\\theta_i - \\theta_j) x) + \\lambda R(\\rho(\\bm\\theta))\n\\]\nwhere \n\\[\nl(\\bm m) = \\sum_{j = 1}^{k-1} {\\rm ReLU}(1 - m_j)\n\\]\n%\\begin{lemma}\n%\tIf $l(\\bm m(x,\\bm\\theta))$ is convex w.r.t $\\bm\\theta$ for any fixed $x$, $R(\\cdot)$ is convex and $\\rho(\\cdot)$ is a strictly convex norm, then $L(\\bm\\theta,\\lambda)$ is strictly convex w.r.t $\\bm\\theta$ and $\\bm\\Theta(\\lambda)$ contains the unique element for any $\\lambda > 0$.\n%\\end{lemma}\n\n\nFrom now on, for any given $\\lambda > 0$, we fix a $\\bm\\theta(\\lambda)\\in \\bm\\Theta(\\lambda)$. We'll prove that this kind of loss functions has the margin maxmizing property.\n\n\n\n\\begin{lemma}\n\t\n\t\\begin{equation}\n\t\\lim\\limits_{\\lambda\\rightarrow 0} L(\\bm\\theta(\\lambda),\\lambda) = 0. \n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n    It's sufficient to show that $\\mathop{\\rm limsup}_{\\lambda \\rightarrow 0} L(\\bm\\theta(\\lambda),\\lambda) = 0$.\\\\\n    Given any $\\epsilon>0$, there must exist a $\\bm\\theta_{\\epsilon}\\in\\bm\\Theta_0$ such that\n    \\[\n    \\sum_{i =  1}^{k} \\sum_{x\\in A_i} l(\\bm m^i(x,\\bm  \\theta_{\\epsilon})) < \\epsilon.\n    \\]\n    So\n    \\begin{equation}\n    \t\\mathop{\\rm limsup}_{\\lambda \\rightarrow 0} L(\\bm\\theta(\\lambda),\\lambda) \\leq \\mathop{\\rm limsup}_{\\lambda \\rightarrow 0} L(\\bm\\theta_\\epsilon,\\lambda) \\leq \\epsilon.\n    \\end{equation}\n    Because of the arbitrariness of $\\epsilon$, we have\n    \\[\n    \\mathop{\\rm limsup}_{\\lambda \\rightarrow 0} L(\\bm\\theta(\\lambda),\\lambda) = 0.\n    \\]\n\\end{proof}\n\n\n\\begin{corollary}\n\tFor sufficiently small $\\lambda$, we must have $\\bm\\Theta(\\lambda) \\subset \\bm\\Theta_0 $, or namely, \n\t\\[\n\tm(\\bm\\theta) > 0,\\ \\rho(\\bm\\theta) >0,\n\t\\]\n\tfor any $\\bm\\theta \\in \\bm\\Theta(\\lambda)$, \n\\end{corollary}\n\n\nIn order to make the problem more intuitive, we can transfer the problem to a new coordinate system similarily to the polar coordinate system. Define\n\\begin{equation}\n\\bm S = \\{\\bm\\omega\\in \\mathbb{R}^{k\\times (d+1)}: \\rho(\\bm \\omega) = 1\\}\n\\end{equation}\nGiven any $\\bm\\theta\\in \\{\\bm\\theta: \\rho(\\bm\\theta) > 0\\}$, we can define its $\\rho$-polar coordinates $(r,\\omega) \\in [0,+\\infty) \\times \\bm S$ as \n\\begin{equation}\nr = \\rho(\\bm\\theta),\\ \\bm\\omega = \\frac{\\bm\\theta}{\\rho(\\bm\\theta)}.\n\\end{equation}\n\nNotice that this coordinate transformation is a bijection from $\\{\\bm\\theta: \\rho(\\bm\\theta) > 0\\}$ to  $(0,+\\infty)\\times \\bm S$.\nCorrespondingly, we can define a new loss function in this new coordinate as\n\\begin{equation}\n \\mathcal L(r,\\bm\\omega,\\lambda) = L(r\\bm\\omega, \\lambda) = \\sum_{i =  1}^{k} \\sum_{x\\in A_i} l(r\\bm m^i(x,\\bm\\omega)) + \\lambda R(r)\n\\end{equation}\nAnd define the minima set of this new loss as \n\\begin{equation}\n\\bm Z(\\lambda) = \\mathop{\\rm argmin}_{r, \\bm\\omega} \\mathcal L(r,\\bm\\omega,\\lambda) \n\\end{equation}\n\nGiven any $\\lambda>0$, we fix a $ (r(\\lambda),\\omega(\\lambda))\\in \\bm Z(\\lambda)$. Similarily, we have the following lemma.\n\\begin{lemma}\n\t\\begin{equation}\n\t\\lim\\limits_{\\lambda\\rightarrow 0} \\mathcal L(r(\\lambda),\\bm\\omega(\\lambda),\\lambda) = 0. \n\t\\end{equation}\n\\end{lemma}\n\n\n\n\\begin{corollary}\\label{Maxmargin3}\n\tFor sufficiently small $\\lambda >0$, we must have\n\t\\[\n\tr> 0,\\ m(\\bm\\omega) > 0,\n\t\\]\n\tfor any $(r,\\bm\\omega) \\in \\bm Z(\\lambda)$.\n\\end{corollary}\n\n\\begin{lemma}\n\tFor sufficiently small $\\lambda >0$, the coordinate transformation restricted on $\\bm\\Theta(\\lambda)$ is a bijection from $\\bm\\Theta(\\lambda)$ to $\\bm Z(\\lambda)$. \n\\end{lemma}\n\n\nSo to study the convergence of $\\frac{\\bm\\theta(\\lambda)}{\\|\\bm\\theta(\\lambda)\\|}$, we only need to figure out the convergence of $\\bm\\omega(\\lambda)$ as $\\lambda\\rightarrow 0$.\n\n\n\n\\subsection{Case 1: $T<\\infty$}\n\nWe first discuss the case of $T<\\infty$.\n\n\\begin{lemma}\n\t\\begin{equation}\n\t\tr(\\lambda) \\leq \\frac{T}{m^*}, \\forall \\lambda>0.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\tFind any $\\bm\\omega^*\\in\\bm\\Theta^*$, we have\n\t\\[\n\t\\lambda R(r(\\lambda)) \\leq \\mathcal{L}(r(\\lambda),\\bm\\omega(\\lambda),\\lambda)\\leq\\mathcal{L}(\\frac{T}{m^*},\\bm\\omega^*,\\lambda) = \\lambda R(\\frac{T}{m^*}).\n\t\\]\n\twhich implies\n\t\\[\n\tr(\\lambda) \\leq \\frac{T}{m^*}.\n\t\\]\n\t\n\\end{proof}\n\n\\begin{theorem}\n\tIf $T<\\infty$, any convergence point of $\\bm\\omega(\\lambda)$ must be a margin maximizing parameter in $\\bm\\Theta^*$.\n\\end{theorem}\n\n\\begin{proof}\n\tSuppose that there is a sequence $\\lambda_n \\searrow 0$ such that  $\\bm\\omega(\\lambda_n)\\rightarrow \\overline{\\bm\\omega}$ and $m(\\overline{\\bm\\omega})< m^*$. So there exsits a $\\epsilon>0$ and $K\\in \\mathbb{N}$ such that\n\t\\[\n\tm(\\bm\\omega(\\lambda_n)) < m^* - \\epsilon, \\ \\forall n>K.\n\t\\]\n\tThen we have\n\t\\begin{align}\n\t&\\mathcal{L}(r(\\lambda_n),\\bm\\omega(\\lambda_n),\\lambda_n) \\\\\n\t\\geq\\ &\\sum_{i =  1}^{k} \\sum_{x\\in A_i} l(r(\\lambda_n)\\bm m^i(x,\\bm\\omega(\\lambda_n)))\\\\\n\t\\geq\\ & l(\\frac{m^*-\\epsilon}{m^*}T,\\infty,\\cdots,\\infty) > 0,\\ \\forall n>K,\n\t\\end{align}\n\twhich leads to a contradiction with $\\lim\\limits_{\\lambda\\rightarrow 0} \\mathcal L(r(\\lambda),\\bm\\omega(\\lambda),\\lambda) = 0$.\n\\end{proof}\n\n\n\\subsection{Case 2: $T=\\infty$}\nNext, we discuss the case of $T=\\infty$.\n\n\\begin{lemma}\\label{Maxmargin7}\n\tIf $T = \\infty$, we have\n\t\\begin{equation}\n\t\\lim\\limits_{\\lambda\\rightarrow 0}\\ r(\\lambda) = \\infty.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\tSuppose that there is an $M>0$ and a sequence $\\lambda_n \\searrow 0$ such that  $r(\\lambda_n) \\leq M$. Then we have\n\t\\[\n\t\\mathcal{L}(r(\\lambda_n),\\bm\\omega(\\lambda_n),\\lambda_n) \\geq l(Mm^*,\\infty,\\cdots,\\infty) > 0,\\ \\forall n\\in\\mathbb{N},\n\t\\]\n\twhich is contradictory to $\\lim\\limits_{\\lambda\\rightarrow 0} \\mathcal L(r(\\lambda),\\bm\\omega(\\lambda),\\lambda) = 0$.\n\\end{proof}\n\n\n\\begin{theorem}\n\tIf $T = \\infty$, any convergence point of $\\bm\\omega(\\lambda)$ must be a margin maximizing parameter in $\\bm\\Theta^*$.\n\\end{theorem}\n\n\\begin{proof}\n\tSuppose that there is a sequence $\\lambda_n \\searrow 0$ such that  $\\bm\\omega(\\lambda_n)\\rightarrow \\widehat{\\bm\\omega}$ and $m(\\widehat{\\bm\\omega})< m^*$. So there exsits a $\\epsilon>0$ and $K_1\\in \\mathbb{N}$ such that\n\t\\[\n\tm(\\bm\\omega(\\lambda_n)) < m^* - \\epsilon, \\ \\forall n>K_1.\n\t\\]\n\tTake\n\t\\[\n\t\\bm u = (m^*-\\epsilon,\\infty,\\cdots,\\infty),\\ \\bm v = (m^*, m^*,\\cdots,m^*),\n\t\\]\n\tthen there exists a $K_2\\in\\mathbb{N}$ such that\n\t\\[\n\tl(r(\\lambda_n) \\bm u) > N l(r(\\lambda_n) \\bm v), \\forall n>K_2.\n\t\\]\n\tLet $K = \\max\\{K_1,K_2\\}$. Notice that\n\t\\[\n\t\\mathcal{L}(r(\\lambda_n),\\bm\\omega(\\lambda_n),\\lambda_n) \\geq  l(r(\\lambda_n)\\bm u) + \\lambda_n \\rho(r(\\lambda_n)),\n\t\\]\n\t\\[\n\t\\mathcal{L}(r(\\lambda_n),\\bm\\omega^*,\\lambda_n) \\leq N l(r(\\lambda_n) \\bm v) + \\lambda_n \\rho(r(\\lambda_n)).\n\t\\]\n\tThus given any $\\bm\\omega^*\\in \\bm\\Theta^*$, we have\n\t\\[\n\t\\mathcal{L}(r(\\lambda_n),\\bm\\omega^*,\\lambda_n) < \\mathcal{L}(r(\\lambda_n),\\bm\\omega(\\lambda_n),\\lambda_n),\\ \\forall n > K,\n\t\\]\n\twhich is contradictory to $(r(\\lambda_n),\\bm\\omega(\\lambda_n))\\in \\bm Z(\\lambda)$.\n\\end{proof}\n\n\\begin{corollary}\n\tIf $\\bm\\Theta^*$ only contains the unique element $\\bm\\theta^*$, then $\\frac{\\bm\\theta(\\lambda)}{\\rho(\\bm\\theta(\\lambda))}$ must converge to $\\bm\\theta^*$ as $\\lambda\\rightarrow 0$.\n\\end{corollary}\n\n\\begin{corollary}\n\tIf $\\rho(\\cdot)$ is a strictly convex norm, then $\\frac{\\bm\\theta(\\lambda)}{\\rho(\\bm\\theta(\\lambda))}$ must converge to $\\bm\\theta^*$ as $\\lambda\\rightarrow 0$.\n\\end{corollary}\n\n\\newpage\n\\section{Regularization by maximizing margins $k=2$}\nThe classic SVM, without kernels, is based on the belief that\nbigger margin will give better generalization.\n\nThe question is \n\\begin{itemize}\n\\item What is the right metric to define margin?\n\\end{itemize}\n\nWe make the following observations:\n\\begin{enumerate}\n\\item  The regularization norm for the loss function should be dual to the\nnorm  for the data space\n\\item The norm for the data space ideally should reflect the features\n  of the image, such as \n\n\\begin{enumerate}\n\\item rotation invariant (continuity)\n\\item translation invariant (continuity)\n\\item deformation invariant (continuity)\n\\end{enumerate}\n\n\\item One possibility is to use the following metrix\n$$\nd(\\phi(x), \\phi(y) )\n$$\nwhere $\\phi(x)$ is some CNN function transferred from other data \n\\end{enumerate}\n\nIn LR, we have\n$$\nL(x)=(\\Theta, x)\n$$\n\n\\subsection{Conclusion}\n\\begin{itemize}\n\\item The commonly used regularization such as $\\ell^2$ norm should\n  not be helpful to increase genearlization accuracy, since its dual norm is not\n  a good metric to measure the dat, but such a regularization may be\n  useful for noisy.\n\\end{itemize}\n\n\\newpage\n\n\\section{Some comments on the metric of images}\n$\\ell^2$ norm might not be a proper norm for us to do classification in the digital image space, because if you rotate the index of an image, the new image you get might have larger distance to the original than some images from other labels. That means defferent classes of images are not separated very well as we imagine, but are mixed together and not linearly separable. \\\\\n\\indent What kind of 'metric' is reasonable for image classification? At least, it should satisfy some invariance like translation-invariance and rotation-invariance in index space. Theoretically, we can define a 'metric' using the notion of quotient space. Abstractly, We regard a digital image as a function from $\\mathbb{R}^2$ to $\\mathbb{R}$. And we can assume the whole digital image space to be a $L^p(\\mathbb{R}^2)$ space. And given $Q\\in \\mathbb{R}^{2\\times 2}$, $b\\in ]\\mathbb{R}^2$, we define an operation $A(Q,b): L^p(\\mathbb{R}^2)\\circlearrowleft$ such that\n\\[\nA(Q,b)\\circ f(x) = f(Qx+b).\n\\]\nWhen we take $Q$ is an orthogonal matrix, it's a rotation or reflection in the domain, while $A(Q,b)$ ia a bijectiction in $L^p$ space which keeps the value of norm.\n\\begin{definition}{equivalence of images}\n\tWe say two images $f,g \\in L^p(\\mathbb{R}^2)$ are equivalent if there is an orthogonal matrix $Q$ and a vector $b$ such that $A(Q,b)\\circ f = g$, denoted as $f \\sim g$.\n\\end{definition}\nThus we can naturally induce a quotient space by the notion of image equivalence. We define a equivalence class from the quotient space as $\\bar{f} = \\{g: g\\sim f\\}$. But unfortunately, the natural way to define plus opration in the quotient space dosen't work in this situation. If we define $\\bar{f}+\\bar{g} = \\bar{f+g}$, then we will find this plus opration rely on the representitive you choose, so is not well-defined. But we can still define a metric in this quotient space as\n\\begin{equation}\n\td(\\bar{f},\\bar{g}) = \\inf_{s\\in \\bar{f},t\\in \\bar{g}} \\|s-t\\|_{L^p}.\n\\end{equation}\nAlthough this metric satisfy those invariance we expect, the quotient space is not linear at all, so this metric can not be a norm which means it's hard to use in the real situation. \\\\\n\\indent Another way to achieve those invariance is to find some feature mapping $F$ to map those equivalent points to be very close to each other in feature space and then we use the norm in feature space to determine the metric. For example, we define $d(f,g) = \\|F(f)-F(g)\\|$. How to achieve those invariance via this $F$? Roughly speaking, it's concerned with your data and model. First, your model should have the capacity to get a proper function $F$ with those expected property. Second, your image data should contain those rotation or translation from the same image to help your model build such invariance properties. For example, data augmentation can  do such things.\\\\\n\\indent So an interesting question is, do those deep learning models have the ability to achieve or approximately achieve those invariance?", "meta": {"hexsha": "0d2e65f277970fb24c26bf041002509a1a416d98", "size": 27887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MaxMarginLoss.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/MaxMarginLoss.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/MaxMarginLoss.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.5734375, "max_line_length": 681, "alphanum_fraction": 0.6541399218, "num_tokens": 10530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6556700340128545}}
{"text": "% !TeX root = ./apxthy.tex\n\n\n\\section{Splines}\n%\n\\label{sec:splines}\n%\nIn this very short chapter we will briefly introduce and explore some\nconsequences of piecewise polynomial approximation (as opposed to global\npolynomial approximation as in \\S~\\ref{sec:poly}). The basic results will be\nvery easy to obtain. For lack of time we will skip the more interesting\nalgorithmic aspects, in particular B-Splines (we will briefly define them and\nshow some examples, but we won't go into the implementation details, at least\nnot this year).\n\n\\subsection{Motivation} \n%\n\\label{sec:splines:motivation}\n%\nLet us motivate the idea of splines as follows: consider\nthe function $f(x) = \\sqrt{x}$ on $[0, 1]$. After rescaling to $[-1,1]$ we can\napproximate it with polynomials to obtain the convergence rate (cf. Jackson's\nTheorem \\ref{eq:poly:jackson1}) \n\\[\n    \\inf_{p \\in \\Poly_N} \\|f - p\\|_{L^\\infty(0,1)} \\lesssim N^{-1/2}.\n\\]\nThis is a very slow rate of convergence, purely caused by the singularity at \n$x = 0$. But in $[1/2, 1]$ $f$ is analytic and on that interval we would \nexpect \n\\[\n    \\inf_{p \\in \\Poly_N} \\|f - p\\|_{L^\\infty(1/2,1)} \\lesssim \\rho^{-N},\n\\]\nfor some $\\rho > 1$. We can then prescribe a second polynomial on $[1/4, 1/2]$,\nand so forth, thus obtaining a piecewise polynomial approximation. The\nsubintervals $[1/2,1], [1/4, 1/2], \\dots$ are called a mesh and the flexibility\nin choosing these sub-intervals can lead to very strong results. We will later\nsee that in this particular case we obtain almost exponential convergence.\n\n\n\\subsection{Splines for $C^j$ functions}\n%\n\\label{sec:splines:Cj}\n%\nTo work with splines we will need to construct polynomial approximations on\narbitrary sub-intervals $[a,b] \\subset \\R$. The Chebyshev nodes on $[a,b]$ are\nsimply the rescaled nodes \n\\[\n    x_j^{[a,b]}  = a + \\frac{(x_j+1)(b-a)}{2},\n\\]\nwhere $x_j$ are the Chebyshev nodes on $[-1,1]$. The resulting \ninterpolation operator is denoted by $I_N^{[a,b]}$. \n\nWe can now quantify the effect of domain size with the following lemma. \n\n\\begin{lemma}\n    Let $f \\in C^{p-1,1}([a,b])$ where $a < b$, and $N \\leq p$, then \n    \\[\n        \\|f - I_N^{[a,b]} f \\|_{L^\\infty(a,b)} \n        \\leq \\frac{c^N \\log N}{N!} \\b(b-a\\big)^N \\| f^{(N)} \\|_{L^\\infty(a,b)},\n    \\]\n    where $c$ is a generic constant.\n\\end{lemma}\n\\begin{proof}\n    Let $g(y) = f(\\xi(y))$ where $\\xi(y) = a + (b-a)(1+y)/2$, i.e., \n    \\[ \n        \\xi : [-1,1] \\to [a, b]\n    \\]\n    is affine and bijective. Then according to Jackson's theorem (the sharp\n    version; cf. Exercise~\\ref{exr:poly:convergence}), \n    \\[\n        \\|f - I_N^{[a,b]} f\\|_{L^\\infty(a,b)} = \n        \\| g - I_N g \\|_{L^\\infty(-1,1)}  \n        \\leq  \\frac{c_1^N\\log N}{N!} \\| g^{(N)} \\|_{L^\\infty(-1,1)}.\n    \\]\n    Next, since $\\xi$ is affine it is easy to show that \n    \\[\n        g'(y) = f'(\\xi(y)) \\xi'(y) = f'(\\xi(y)) \\smfrac{b-a}{2},\n    \\]\n    and hence \n    \\[\n        g^{(j)}(y) = f^{(j)}(\\xi(y)) \\B(\\smfrac{b-a}{2}\\B)^j.\n    \\]\n    Combining this with the interpolation error estimate for $g$ \n    yields the stated result.\n\\end{proof}\n\nThus we see that we now have two parameters to control the approximation error:\nthe polynomial degree $N$ and the interval lengths $(b-a)$. This extra freedom\nis what can make splines a powerful alternative to polynomials. \n\n\n\\begin{definition}\n    Let $y_0 < y_1 < \\dots < y_M$ be a partition of an interval $[y_0, y_M]$,\n    then we define the space of splines (piecewise polynomials) of degree $N$ on\n    that partition to be \n    \\[\n        \\Spl_N(\\{y_i\\}) := \\b\\{ s : [y_0, y_M] \\to \\R, \\quad \n            s|_{[y_{m-1}, y_m]} \\in \\Poly_N \\text{ for all }\n            m = 1, \\dots, M \\b\\}\n    \\]\n    Splines are of course $C^\\infty$ in each interval $[y_{j-1}, y_j]$, but \n    sometimes it is also interesting to require that splines have a certain \n    regularity on the entire interval $[y_0, y_M]$. We therefore define \n    \\[\n        \\Spl_N^p(\\{y_i\\}) := \\Spl_N(\\{y_i\\}) \\cap C^p([y_0, y_M]).\n    \\]\n    It is worth nothing that $s \\in \\Spl_N^p$ implies in fact that $s \\in\n    C^{p,1}$.\n\\end{definition}\n\n\\begin{remark}\n    It is of course also possible to define splines with varying polynomial\n    degree, i.e. in each subinterval $[y_{j-1}, y_j]$ we might impose a degree\n    $N_j$. This has advantages for some applications but we will not consider it\n    here. \n\\end{remark}\n\nIt takes a bit more work to construct splines of regularity $p = 1$ or higher,\nbut $\\Spl_N^0$ splines are obtained by simply taking Chebyshev interpolants on\neach sub-interval. We call the resulting interpolant $I_{N,M}$, \n\\[\n    I_{N,M} f(x) := I_N^{[y_{m-1},y_m]} f(x)    \\qquad \\text{for }\n    x \\in [y_{m-1}, y_m].\n\\]\nWe then obtain the following basic approximation \nerror estimates. \n\n\\begin{theorem} \\label{th:splines:convergence_Cj}\n    Let $f \\in C^p([a,b])$ and $a = y_0 < \\dots < y_M = b$ a partition of $[a,\n    b]$, and let $h_m := y_m - y_{m-1})$ be the mesh size, and $N \\leq p$, then \n    \\[\n        \\| f - I_{N,M} f \\|_{L^\\infty(a,b)}\n        \\leq  C_N \\max_{m = 1, \\dots, M} h_m^N\n        \\| f^{(N)} \\|_{L^\\infty(y_{m-1}, y_m)},\n    \\]\n    where $C_N = \\frac{c^N \\log N}{N!}$.\n    In particular, if the partition is uniform, \n    $y_m = a + h m$ where $h = (b-a)/M$ then \n    \\[\n        \\| f - I_{N,M} f \\|_{L^\\infty(a,b)}\n        \\leq C_N h^N \\|f^{(N)}\\|_{L^\\infty(a,b)}.\n    \\]\n\\end{theorem}\n\\begin{proof}\n    Left as an exercise. \n\\end{proof}\n\n\n\\subsection{Splines for functions with singularities}\n%\n\\label{sec:splines:sing}\n%\nWe will demonstrate how splines can be used to effectively resolve singular\nbehaviour using the example from the beginning of this chapter, \n\\[ \n    f(x) = \\sqrt{x} \\qquad \\text{on } x \\in [0, 1]\n\\]\nA possible analytic continuation is given by \n\\[\n    f(r e^{i \\varphi}) = \\sqrt{r} e^{i \\varphi / 2},\n\\]\nwhich is analytic in $\\C \\setminus (-\\infty, 0]$. Moreover, we have $|f(z)| =\n\\sqrt{|z|}$ which will make it easy to estimate $\\|f\\|_{L^\\infty(E_\\rho)}$ where\n$E_\\rho$ will be some suitable Bernstein ellipsi.\n\nOur strategy will be to use a partition  \n\\[\n    0, 2^{-M}, 2^{-M+1}, \\dots, 2^{-1}, 1.\n\\]\nSince $f$ is analytic in each subinterval $[2^{-m}, 2^{-m+1}]$ we will be able\nto use the exponential convergence rates from\nTheorem~\\ref{th:poly:err_analytic}.\n\nLet us therefore consider $f$ on $[2^{-m}, 2^{-m+1}]$. We rescale \n\\[\n    g(y) = f\\b(2^{-m} + 2^{-m-1}(1+y)\\b),\n\\]\nthen the singularity $x = 0$ maps to $y = -3$, hence $g$ in analytic in $\\Re z >\n-3$. In particular taking $\\rho = 4$ we have $a = \\smfrac12(\\rho+\\rho^{-1}) < 3$ \nand \n\\begin{align*}\n    \\|g\\|_{L^\\infty(E_\\rho)} &\\leq g(a) \\leq f(2^{-m} + 2^{-m-1}(1+a)) \\\\\n    &\\leq  f(2^{-m} + 2^{-m+1}) \\\\ \n    &\\leq \\sqrt{2^{-m+2}} \\\\ \n    &= 2^{-m/2+1}.\n\\end{align*}\nThus, we obtain \n\\[\n    \\| f - I_N^{[2^{-m},2^{-m+1}]} f\\|_{L^\\infty(2^{-m},2^{-m+1})}\n    =\n    \\| f - I_N g \\|_{L^\\infty(-1,1)} \n    \\leq C 4^{-N} 2^{-m/2}\n\\]\nTo make our life a little easier we can just estimate \n\\[\n    \\| f - I_N^{[2^{-m},2^{-m+1}]} f\\|_{L^\\infty(2^{-m},2^{-m+1})}\n    \\leq \n    C 4^{-N} \\qquad \\text{for } m = M, M-1, \\dots, 1;\n\\]\nthat is, \n\\[\n    \\| f - I_{N,M} f \\|_{L^\\infty(2^{-M}, 1)} \\leq \n    C N^{-4}.    \n\\]\n\nFinally, we address the first interval $[0, 2^{-M}]$. We rescale again \nas before, but now the singularity becomes part of the domain $[-1,1]$, i.e.,\n$g \\in C^{0,1/2}([-1,1])$ and no better. Jackson's theorem therefore tells \nus the \n\\[\n    \\| g - I_N g \\|_{L^\\infty(0, 2^{-M})}\n    \\leq \n    C \\omega_g(N^{-1}) = C N^{-1/2}.\n\\]\nBut the constant matters here! Specifically, we can show that \n\\[\n    \\omega_g(r) = c 2^{-M/2} \\sqrt{r},\n\\]\nthat is, we even have \n\\[\n     \\|f - I_N^{[0, 2^{-M}]} f \\|_{L^\\infty(0, 2^{-M})} \n     \\leq C 2^{-M/2} N^{-1/2}.\n\\]\nLet us again make our life a little easier and ignore the $N^{-1/2}$ term, then \nwe want to balance $2^{-M/2} = 4^{-N}$; that is, \n\\[\n    M = 4 N.    \n\\]\nWith this choice, we finally obtain \n\\[\n    \\| f - I_{N,M} f \\|_{L^\\infty(0, 1)} \\leq C 4^{-N}.\n\\]\n\nTo conclude we convert this into a cost estimate. The cost of evaluating \n$I_{N,M} f$ at a single point in space is the same as evaluating a \npolynomial of degree $N$, that is \n\\[\n    {\\rm COST-EVAL}(I_{N,M} f) = O(N)\n\\]\nand in particular, we obtain the very nice exponential convergence \nresult \n\\[\n    \\| f - I_{N,M} f \\|_{L^\\infty(0, 1)} \\leq C \\rho^{-{\\rm COST-EVAL}},\n\\]\nfor some $\\rho > 0$. The cost to ``build and store'' $I_{N,M} f$ is the cost of\nevaluating $f$ at $M \\cdot N$ points, i.e., $O(N^2)$ so this cost is a little\nhigher, but still very attractive.\n\nThis example is intended to demonstrate the power of adapting the spline grid to\nthe features of the function to be approximated. Automating this process is of\ngreat interest but goes beyond the scope of this module.\n\n\\begin{remark}\n    We can do slightly better by balancing the two terms in \n    \\[\n        \\| f - I_N^{[2^{-m},2^{-m+1}]} f\\|_{L^\\infty(2^{-m},2^{-m+1})}\n        \\leq \n        C 4^{-N_m} 2^{-m/2}\n        = C 4^{- N_m - m/4},\n    \\]\n    i.e., choosing $N_m +  m/4 = N = {\\rm const}$. But one can easily \n    check that this only gives an improvement in some constants, but \n    not qualitatively.\n\\end{remark}\n\n\\subsection{Exercises}\n\n\n\\begin{exercise} \\label{exr:splines:}\n    Prove Theorem~\\ref{th:splines:convergence_Cj}\n\\end{exercise}\n\n\\begin{exercise}\n    \\begin{enumerate} \\ilist \n    \\item Suppose you are given a function $f \\in C^{p-1,1}([-1,1])$. For\n    simplicity, assume even that in each subinterval $[a,b] \\subset\n    [-1,1]$ the regularity of $f$ is no better than $C^{p-1,1}$. Assume\n    you discretise $[-1,1]$ with a uniform grid. How would you optimally\n    balance the grid spacing $h$ against the polynomial degree $N$?\n    (i.e. minimise the error against the number of function evaluations\n    you need to specify the approximant)\n\n    \\item Now suppose that $f \\in A([-1,1])$; how would you balance $h$\n    against $N$ now?\n\n    \\item For the following functions compare the performance of \n    global polynomial versus $\\Spl_N^0$ approximation on a uniform grid:\n    \\begin{itemize}\n        \\item $f(x) = |x|$ \n        \\item $f(x) = |x+\\pi|$ \n        \\item $f(x) = |\\sin(x/2)|$ \n        \\item $f(x) = (1+25 x^2)^{-1}$\n        \\item $f(x) = x \\sin(1/x)$ \n    \\end{itemize}\n    \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n    For the following functions $f : [-1,1] \\to \\R$, design a spline\n    approximation with quasi-optimal rate of convergence in\n    $\\|\\cdot\\|_{L^\\infty(-1,1)}$ in terms of evaluation cost. \n    \\begin{itemize}\n        \\item $f(x) = |x|$ \n        \\item $f(x) = |\\sin(x/2)|$ \n        \\item $f(x) = (1+25 x^2)^{-1}$\n        \\item $f(x) = x \\sin(1/x)$ \n    \\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}[Linear Splines] Show that for we can write continuous linear\n    spline interpolations, i.e. $s \\in \\Spl_1^0(\\{y_m\\})$ in terms of a nodal\n    basis, \n    \\[\n        s(y) = \\sum_{m = 0}^M f(y_m) \\phi_m(y),\n    \\]\n    where $\\phi_m$ are ``hat-functions'' that you should specify \n    explicitly. \n\\end{exercise}\n\n\n\\begin{exercise}[Hermite Interpolation with Cubic Splines]\n    Let $y_0 < \\dots < y_M$ be a grid and let $f_m, f_m'$ be \n    function and derivative values at those grid points. Show that there \n    exists a unique cubic spline $s \\in \\Spl_3^1(\\{y_m\\})$ such that \n    \\[\n        s(y_m) = f_m, \\quad \\text{and} \\quad \n        s'(y_m) = f_m' \\quad \\text{for } m = 0, \\dots, M.    \n    \\]\n    {\\it HINT: in each interval $[y_{m}, y_{m+1}]$ write $s(x) = f_{m} + f_{m}'\n        (x-x_{m}) + a_m (x-x_m)^2 + b_m (x-x_m)^3$ and show that there exist\n        unique $a_m, b_m$ such that $s(x_{m+1}) = f_{m+1}, s'(x_{m+1}) =\n        f_{m+1}'$. You may wish to derive explicit expressions for \n        $a_m, b_m$ in preparation for the next exercise.}\n\\end{exercise}\n\n\n\\begin{exercise}[B-Splines]\n    Depending on regularity requirements of an application it is\n    sometimes advantageous to require higher regularity of the approximant,\n    i.e., we should consider $\\Spl_N^p$, $p > 0$. The case $\\Spl_N^{N-1}$\n    turns out to be particularly natural; these are alled the B-splines. And\n    amongst those, the cubic splines enjoy particular polularity.\n\n    \\begin{enumerate} \\ilist \n        \\item Suppose for the moment that $s \\in \\Spl_3^2(\\{y_m\\})$ with \n        $s(y_m) = f_m$ where $f_m$ are some nodal values. Prove that, \n        for {\\em any} $g \\in C^2[a,b]$ with $g(y_m) = f_m$, \n        \\[\n            \\int_{a}^b |s''(x)|^2 \\,dx \\leq \\int_a^b |g''(x)|^2 \\,dx,\n        \\]\n        {\\em provided} that $s$ satisfies a condition at the end-points \n        $a = y_0, b = y_M$, which you should derive. \n\n        Thus, $s''$ with this end-point condition minimises curvature amongst\n        all $C^2$ functions satisfying the nodal interpolation conditions. \n        These splines are therefore called natural splines. \n\n        {\\it HINT: } Consider $\\int_a^b |s''|^2 + 2 s'' (g''-s'') + |s'' - g''|^2 \\, dx$\n        and show that the middle term vanishes if the correct end-point \n        condition is applied.\n\n        \\item Given $(f_m)_{m = 0}^M \\in \\R^{M+1}$, prove that there exists a\n        unique $s \\in \\Spl_3^2(\\{y_m\\})$ satisfying the nodal interpolation\n        conditions $s(y_m) = f_m$ and the end-point conditions found in part\n        (ii). For the sake of simplicity you may wish to assume that the nodes\n        are equispaced, i.e. $y_m = y_0 + h m$.\n\n        {\\it HINT: Prescribe artificial derivative values $f_m'$, then derive a\n        tridiagonal linear system for $(f_m')_{m=0}^M$ and show that it has a\n        unique solution. Note that this system can be solved in $O(M)$ time.}\n        \\qedhere\n    \\end{enumerate}\n\\end{exercise}\n\n", "meta": {"hexsha": "1ae65d00cf5a04da2c8ac5fc870fd4cf62ca9bf3", "size": 13725, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/splines.tex", "max_stars_repo_name": "cortner/MA3J8ApxThyApp", "max_stars_repo_head_hexsha": "9400c557187dbd82468df2dbd0a7da99d7f08f8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-05-22T05:11:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-03T02:47:25.000Z", "max_issues_repo_path": "tex/splines.tex", "max_issues_repo_name": "cortner/MA3J8ApxThyApp", "max_issues_repo_head_hexsha": "9400c557187dbd82468df2dbd0a7da99d7f08f8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-03T22:23:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T01:58:58.000Z", "max_forks_repo_path": "tex/splines.tex", "max_forks_repo_name": "cortner/ApxThyApp", "max_forks_repo_head_hexsha": "0b28c5c4370eb4d9c5a9063c2c5c1b938aa54a3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-02T02:44:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T02:44:56.000Z", "avg_line_length": 36.6, "max_line_length": 88, "alphanum_fraction": 0.6012386157, "num_tokens": 4763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.6556619383513707}}
{"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\n, but all of them summed to some number 2 through 12. How\nmany different ways could three 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% KA: https://www.khanacademy.org/computing/pixar/crowds/crowds-1/v/combinatorics1\n\nHow can we 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 seven dice, each with 20 sides? There would be $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% ADD: This situation is a little confusing given if they're doing the plaques before hand, they wouldn't know who came in each place\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% ADD: Same issue here\n\n$$6! = 6 \\times 5 \\times 4 \\times 3 \\times 2 \\times 1 = 720$$\n\nWe use the word ``permutation'' to mean a particular ordering.\nThis rule says $n$ items can be ordered in $n!$ ways. Thus\nmathematicians actually say ``If you have a list of $n$ items then we\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 a 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% KA: https://www.khanacademy.org/computing/pixar/crowds/crowds2/v/combinatorics8\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% ADD: This is the probability that one person would be chosen\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% ADD: Needs a bit more explanation for claretiy, might just be my understanding\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% KA Binomial Therom: https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:series/x9e81a4f98389efdf:binomial/v/binomial-theorem\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": "e9ab407be4e1641cd77b12e244ea72c4033b963f", "size": 5093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/DiscreteProbability/combinatorics-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/DiscreteProbability/combinatorics-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/DiscreteProbability/combinatorics-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": 43.9051724138, "max_line_length": 137, "alphanum_fraction": 0.7402316906, "num_tokens": 1481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.6556619370345932}}
{"text": "\nTensors are required to have the following information.\n\\begin{itemize}\n\\item A commutative ring $K$ of coefficients.\n\\item A valence $\\vav$ indicating the number of variables to include in its \nassociated multilinear map.\n\\item A list $[U_{\\vav},\\dots, U_0]$ of $K$-modules called the \\emph{frame}.\n\\item A function $U_{\\vav}\\times \\cdots \\times U_1\\rightarrowtail U_0$ that is $K$-linear in each $U_i$.\n\\end{itemize}\nTensors have type \\texttt{TenSpcElt} and are formally elements of a tensor space \n(type \\texttt{TenSpc}).  \nBy default, a tensor's parent space is a universal tensor space:\n\\begin{align*}\n\t\\hom_K(U_v,\\dots,\\hom_K(U_1,U_0)\\cdots) \\cong \\hom_K(U_v\\otimes_K\\cdots \\otimes_K U_1,U_0).\n\\end{align*}\nThe left hand module is used primarily as it avoids the need to work with the\nequivalence classes of a tensor product. Operations such as linear combinations\nof tensors take place within a tensor space. Attributes such as coefficients,\nvalence, and frame  apply to the tensor space as well.\n\nWhen necessary, the user may further direct the operations on tensors to\nappropriate tensor categories (type \\texttt{TenCat}).  For instance, covariant\nand contravariant variables may be specified together with symmetry\nconditions.  If no tensor category is prescribed, then a default tensor category\nis used based on the method of creation.\n\\medskip\n\n\\minitoc\n\n\\section{Creating tensors}\n\n\\subsection{Black-box tensors}\nA user can specify a tensor by a black-box function that evaluates the required\nmultilinear map.\n\n\\index{Tensor!black-box}\n\\begin{intrinsics}\nTensor(S, F) : SeqEnum, UserProgram -> TenSpcElt, List\nTensor(S, F) : List, UserProgram -> TenSpcElt, List\nTensor(S, F, Cat) : SeqEnum, UserProgram, TenCat -> TenSpcElt, List\nTensor(S, F, Cat) : List, UserProgram, TenCat -> TenSpcElt, List\n\\end{intrinsics}\n\nReturns a tensor $t$ and a list of maps from the given frame into vector spaces\nof the returned frame. Note that $t$ is a tensor over vector\nspaces---essentially forgetting all other structure. The last entry of\n\\texttt{S} is assumed to be the codomain of the multilinear map. The\nuser-defined function $F$ should take as input a tuple of elements of the domain\nand return an element of the codomain. If no tensor category is provided, the\nhomotopism category is used.\n\n\\begin{example}[BBTensorsFrame] We demonstrate the black-box constructions by\nfirst constructing the dot product $\\cdot : \\mathbb{Q}^4\\times\n\\mathbb{Q}^4\\rightarrowtail \\mathbb{Q}$. The function used to evaluate our\nblack-box tensor, \\texttt{Dot}, must take exactly one argument. The argument\nwill be a \\texttt{Tup}, an element of the Cartesian product $U_{\\vav}\\times\n\\cdots\\times U_1$. Note that \\texttt{x[i]} is the $i$th entry in the tuple and\nnot the $i$-axis.\n\\begin{code}\n> Q := Rationals();\n> U := VectorSpace(Q, 4);\n> V := VectorSpace(Q, 4);\n> W := VectorSpace(Q, 1);  // Vector space, not the field Q\n> Dot := func< x | x[1]*Matrix(4, 1, Eltseq(x[2])) >;\n\\end{code}\n\nNow we will construct the tensor from the data above. The first object returned\nis the tensor, and the second is a list of maps, mapping the given frame into\nthe vector space frame. In this example, since the given frame consists of\nvector spaces, these maps are trivial. Note that the list of maps are not needed\nto work with the given tensor, we will demonstrate this later. \n\\begin{code}\n> Tensor([U, V, W], Dot);\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[*\n    Mapping from: ModTupFld: U to ModTupFld: U given by a rule,\n    Mapping from: ModTupFld: U to ModTupFld: U given by a rule,\n    Mapping from: ModTupFld: W to ModTupFld: W given by a rule\n*]\n\\end{code}\n\nWe will provide a tensor category for the dot product tensor, so that the\nreturned tensor is not in the default homotopism category. We will use instead\nthe $\\{2,1\\}$-adjoint category. While the returned tensor prints out the same as\nabove, it does indeed live in a different universe. The details of tensor\ncategories are discussed in Chapter~\\ref{ch:tensor-categories}.\n\\begin{code}\n> Cat := AdjointCategory(3, 2, 1);\n> Cat;\nTensor category of valence 3 (<-,->,==) ({ 1 },{ 2 },{ 0 })\n> \n> t := Tensor([U, V, W], Dot, Cat);\n> t;\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> \n> TensorCategory(t);\nTensor category of valence 3 (<-,->,==) ({ 1 },{ 2 },{ 0 })\n\\end{code}\n\\end{example}\n\n\\begin{example}[BBCrossProduct]\n\nWe will construct the cross product $\\times : \\mathbb{R}^3\\times\n\\mathbb{R}^3\\rightarrowtail \\mathbb{R}^3$ and verify that ${\\bf i}\\times {\\bf j}\n= {\\bf k}$. However, to do this test, we will input integer sequences\n(specifically \\texttt{[RngIntElt]}), and we will still be able to evaluate.\n\\begin{code}\n> K := RealField(5);\n> V := VectorSpace(K, 3);\n> CP := function(x)\nfunction>   return V![x[1][2]*x[2][3] - x[1][3]*x[2][2], \\\nfunction|return>     x[1][3]*x[2][1] - x[1][1]*x[2][3], \\\nfunction|return>     x[1][1]*x[2][2] - x[1][2]*x[2][1] ];\nfunction> end function;\n> t := Tensor([V, V, V], CP);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 3 over Real field of precision 5\nU1 : Full Vector space of degree 3 over Real field of precision 5\nU0 : Full Vector space of degree 3 over Real field of precision 5\n> \n> // test that i x j = k\n> <[1,0,0], [0,1,0]> @ t eq V.3;\ntrue\n\\end{code}\n\\end{example}\n\n\\index{Tensor!black-box}\n\\begin{intrinsics}\nTensor(D, C, F) : SeqEnum, Any, UserProgram -> TenSpcElt, List\nTensor(D, C, F) : List, Any, UserProgram -> TenSpcElt, List\nTensor(D, C, F, Cat) : SeqEnum, Any, UserProgram, TenCat -> TenSpcElt, List\nTensor(D, C, F, Cat) : List, Any, UserProgram, TenCat -> TenSpcElt, List\n\\end{intrinsics}\n\nReturns a tensor $t$ and a list of maps from the given frame into vector spaces\nof the returned frame. Note that $t$ is a tensor over vector\nspaces---essentially forgetting all other structure. The user-defined function\n$F$ should take as input a tuple of elements of $D$ and return an element of\n$C$. If no tensor category is provided, then the homotopism category is used.\n\n\\begin{example}[BBTripleProduct] Tensors make it easy to create algebras that do\nnot fit into traditional categories, such as algebras with triple products.\nHere, we create a triple product $\\langle \\,\\rangle : \\mathbb{M}_{2\\times\n3}(K)\\times \\mathbb{M}_{2\\times 3}(K)\\times\\mathbb{M}_{2\\times\n3}(K)\\rightarrowtail \\mathbb{M}_{2\\times 3}(K)$, given by $\\langle A, B,\nC\\rangle = AB^tC$.\n\n\\begin{code}\n> K := GF(541);\n> U := KMatrixSpace(K,2,3);\n> my_prod := func< x | x[1]*Transpose(x[2])*x[3] >;\n> t := Tensor([U,U,U,U], my_prod );\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 6 over GF(541)\nU2 : Full Vector space of degree 6 over GF(541)\nU1 : Full Vector space of degree 6 over GF(541)\nU0 : Full Vector space of degree 6 over GF(541)\n\\end{code}\n\nNotice that the returned tensor is over vector spaces instead of the universe of \\texttt{KMatrixSpace}.\nTensors can still evaluate elements from the given frame, even though it prints out over vector spaces. \nHowever, the returned value form the tensor will be in the codomain of the tensor, so in this case, $K^6$.\n\\begin{code}\n> A := U![1,0,0,0,0,0];\n> A;\n[  1   0   0]\n[  0   0   0]\n> \n> <A,A,A> @ t;  // A is a generalized idempotent\n(  1   0   0   0   0   0)\n\\end{code}\n\nWe can experiment to see if this triple product is left associative. To do this,\nwe will construct five random matrices $\\{ X_1,\\dots,X_5\\}\\subset\n\\mathbb{M}_{2\\times 3}(K)$, and then we test if \n\\[ \\langle \\langle X_1, X_2, X_3 \\rangle, X_4, X_5\\rangle = \\langle X_1, \\langle X_4, X_3, X_2\\rangle, X_5\\rangle. \\]\nObserve that the tuples have mixed entries, one from $K^6$ and two others from $\\mathbb{M}_{2\\times 3}(K)$. \n\n\\begin{code}\n> X := [Random(U) : i  in [1..5]];\n> X;\n[\n    [485 378 385]\n    [241 505 134],\n\n    [141 531 245]\n    [472 484 339],\n\n    [377  85 170]\n    [451 522 334],\n\n    [211 340 409]\n    [ 95 349 128],\n\n    [264 372 144]\n    [205  47 428]\n]\n> \n> A := <X[1],X[2],X[3]> @ t;\n> B := <X[4],X[3],X[2]> @ t;\n> A, B;\n(460 436 181 341 134 404)\n(465 420 458 421 291 225)\n> \n> <A, X[4], X[5]> @ t eq <X[1], B, X[5]> @ t;\ntrue\n\\end{code}\n\nTo confirm this product is left associative, we can create a new tensor for the\nleft triple-associator and see that its image is $0$. We will create a\n$6$-tensor $\\lla \\cdot \\rra : \\prod_{k=1}^5 \\mathbb{M}_{2\\times\n3}(K)\\rightarrowtail \\mathbb{M}_{2\\times 3}(K)$ where\n\\[ \n    \\lla X_1,\\dots, X_5\\rra = \\langle \\langle X_1, X_2, X_3 \\rangle, \n    X_4, X_5\\rangle - \\langle X_1, \\langle X_4, X_3, X_2\\rangle, X_5\\rangle. \n\\]\nTherefore, if im$(\\lla \\cdot \\rra)=0$, then $\\langle \\cdot\\rangle$ is left\nassociative. \n\n\\begin{code}\n> l_asct := func< X | Eltseq(<<X[1], X[2], X[3]> @ t, X[4], X[5]> @ t \\\n>     - <X[1], <X[4], X[3], X[2]> @ t, X[5]> @ t) >;\n> Lt := Tensor([* U : i in [0..5] *], l_asct);\n> Lt;\nTensor of valence 6, U5 x U4 x U3 x U2 x U1 >-> U0\nU5 : Full Vector space of degree 6 over GF(541)\nU4 : Full Vector space of degree 6 over GF(541)\nU3 : Full Vector space of degree 6 over GF(541)\nU2 : Full Vector space of degree 6 over GF(541)\nU1 : Full Vector space of degree 6 over GF(541)\nU0 : Full Vector space of degree 6 over GF(541)\n> \n> I := Image(Lt);\n> I;\nVector space of degree 6, dimension 0 over GF(541)\nGenerators:\n\n> \n> Dimension(I);\n0\n\\end{code}\n\nObserve that in \\texttt{l\\_asct} the function \\texttt{Eltseq} is called. This is\nbecause $t$ returns vectors in $K^6$ which is not naturally coercible by\n\\textsf{Magma} into $\\mathbb{M}_{2\\times 3}(K)$. On the other hand, sequences\ncan be coerced into $\\mathbb{M}_{2\\times 3}(K)$. \n\\end{example}\n\n\n\n\n\\subsection{Tensors with structure constant sequences}\nMost computations with tensors $t$ will be carried out using structure\nconstants, e.g.~in the homotopism category, $t_{j_{\\vav}\\cdots j_1}^{j_0}\\in K$.\nHere $t$ is framed by free $K$-modules $[U_{\\vav},\\dots,U_0]$ with each $U_i$\nhaving an ordered bases $\\mathcal{B}_i=[e_{i1},\\dots,e_{id_i}]$. The\ninterpretation of structure constants is that the associated multilinear\nfunction $[x_{\\vav},\\dots,x_1]$ from $U_{\\vav}\\times \\cdots \\times U_1$ into\n$U_0$ is determined on bases as follows:\n\\begin{align*}\n\t[e_{\\vav j_{\\vav}},\\dots,e_{1j_1} ]& = \\sum_{k=1}^{d_0} t_{j_{\\vav} \\cdots j_1}^{j_0} e_{0k}.\n\\end{align*}\nStructure constants are input and stored as sequences $S$ in $K$ according to the\nfollowing assignment. Set $f:\\mathbb{Z}^{\\vav+1}\\to \\mathbb{Z}$ to be:\n\\begin{align*}\n\t\t f(j_{\\vav},\\dots,j_0) & = 1+\\sum_{k=0}^{\\vav} (j_k-1)\\prod_{\\ell=0}^{k-1} d_\\ell.\n\\end{align*}\nSo $S[f(j_{\\vav},\\dots,j_0)]=t_{j_{\\vav}\\cdots j_1}^{j_0}$ specifies the structure constants as a sequence.  \n\\smallskip\n\n\\noindent{\\bf Notes.}\n\\begin{itemize}\n\\item \\textsf{Magma} does not presently support the notion of a sparse sequence of structure constants.\nA user can provide this functionality by specifying a tensor with a user program rather\nthan structure constants. \n\n\\item Some routines in \\textsf{Magma} require structure constant sequences.  If they \nare not provided, \\textsf{Magma} may compute and store a structure constant representation\ninside the tensor.\n\n\\item We do not separate structure constant indices that are contravariant.\nInstead contravariant variables are signaled by tensor categories.  So Ricci\nstyled tensors $T_{a_p\\cdots a_1}^{b_q\\cdots b_1}$ should be input as\n$T_{a_{p+q}\\cdots a_{1+q} b_q\\cdots b_1}$ and the tensor category changed to\nmark $\\{q,\\dots,1\\}$ as contravariant. Intrinsics are provided to facilitate\nthis approach. See Chapter~\\ref{ch:tensor-categories} for more details on tensor\ncategories.\n\\end{itemize}\n\\medskip\n\n\\index{Tensor!structure constants}\n\\begin{intrinsics}\nTensor(D, S) : [RngIntElt], [RngElt] -> TenSpcElt\nTensor(R, D, S) : Rng, [RngIntElt], [RngElt] -> TenSpcElt\nTensor(D, S, Cat) : [RngIntElt], [RngElt], TenCat -> TenSpcElt\nTensor(R, D, S, Cat) : Rng, [RngIntElt], [RngElt], TenCat -> TenSpcElt\n\\end{intrinsics}\n\nGiven dimensions $D=[d_{\\vav},\\dots,d_0]$, returns the tensor in\n$R^{d_{\\vav}\\cdots d_0}$ identified by structure constant sequence $S$. If $R$\nis not provided, then the parent ring of the first element of $S$ is used. The\nring $R$ must be commutative and unital. The default tensor category\n\\texttt{Cat} is the homotopism category.\n\n\n\\begin{example}[SCTensors]\n\nWe will create structure constants sequence with all 0s and one 1 that occurs in the first entry.\nFirst, we will input this along with the dimensions of the tensor we are after, $2\\times 2\\times 2$. \nHowever, since we did not specify a ring, it is assumed to be the parent ring of the first entry of the structure constants sequence.\nIn this example, the ring is $\\mathbb{Z}$. \n\n\\begin{code}\n> sc := [ 0 : i in [1..8] ];\n> sc[1] := 1;\n> Tensor([2, 2, 2], sc);\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full RSpace of degree 2 over Integer Ring\nU1 : Full RSpace of degree 2 over Integer Ring\nU0 : Full RSpace of degree 2 over Integer Ring\n\\end{code}\n\nWe do not want the underlying ring to be $\\mathbb{Z}$, so we will input the ring we want: GF$(64)$.\n\\begin{code}\n> K := GF(64);\n> t := Tensor(K, [2, 2, 2], sc);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 2 over GF(2^6)\nU1 : Full Vector space of degree 2 over GF(2^6)\nU0 : Full Vector space of degree 2 over GF(2^6)\n> \n> Image(t);\nVector space of degree 2, dimension 1 over GF(2^6)\nGenerators:\n(     1      0)\nEchelonized basis:\n(     1      0)\n\\end{code}\n\nWe can recover the structure constants by calling \\texttt{StructureConstants} or \\texttt{Eltseq}.\nWe will also test that the tensor evaluates inputs correctly.\n\\begin{code}\n> StructureConstants(t);\n[ 1, 0, 0, 0, 0, 0, 0, 0 ]\n> \n> <[1, 0], [K.1^3, 0]> @ t;\n( K.1^3      0)\n> \n> <[K.1^29, 1], [0, K.1^2]> @ t;\n(     0      0)\n\\end{code}\n\\end{example}\n\n\n\\index{StructureConstants}\\index{Eltseq}\n\\begin{intrinsics}\nStructureConstants(t) : TenSpcElt -> SeqEnum\nEltseq(t) : TenSpcElt -> SeqEnum\n\\end{intrinsics}\n\nReturns the sequence of structure constants of the given tensor $t$. \n\n\\index{Assign}\n\\begin{intrinsics}\nAssign(t, ind, k) : TenSpcElt, [RngIntElt], Any -> TenSpcElt\nAssign(~t, ind, k) : TenSpcElt, [RngIntElt], Any -> \n\\end{intrinsics}\n\nReturns the tensor $t$ where the \\texttt{ind} element (viewed as a\nmulti-dimensional array) is replaced with $k$. For example, replacing the\n$(a,b,c)$ entry of a $3$-tensor, set \\texttt{ind}$\\,=[a,b,c]$. \n\n\\begin{example}[SCFromBBTensors]\n\nWe will construct the natural Lie module action for $\\mathfrak{sl}_2$, but we\nwill construct it as a \\emph{left} module. To do this, we construct a function\nthat takes elements from $\\mathfrak{sl}_2\\times V$ and returns an element that\n\\textsf{Magma} can coerce into $V$. We run a quick test to make sure our function runs on\nthe trivial example; this is the only check the intrinsic runs on black-box\ntensors. Since $\\mathfrak{sl}_2$ and $V$ are part of different universes in\n\\textsf{Magma}, we must use the \\texttt{List} environment when constructing this\nblack-box tensor. \n\n\\begin{code}\n> sl2 := MatrixLieAlgebra(\"A1\", GF(7));\n> V := VectorSpace(GF(7), 2);\n> left_action := func< x | x[2]*Transpose(Matrix(x[1])) >;\n> left_action(<sl2!0, V!0>);\n(0 0)\n> \n> sl2 := MatrixLieAlgebra(\"A1\", GF(7));\n> V := VectorSpace(GF(7), 2);\n> left_action := func< x | x[2]*Transpose(Matrix(x[1])) >;\n> left_action(<sl2!0, V!0>);\n(0 0)\n> \n> t := Tensor([* sl2, V, V *], left_action);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 3 over GF(7)\nU1 : Full Vector space of degree 2 over GF(7)\nU0 : Full Vector space of degree 2 over GF(7)\n\\end{code}\n\nNow we will extract the structure constants from this Lie module action. We will\nthen construct a tensor with these structure constants and compare it with our\nfirst tensor above.\n\n\\begin{code}\n> StructureConstants(T);\n[ 1, 0, 0, 6, 0, 0, 1, 0, 0, 1, 0, 0 ]\n> \n> s := Tensor([3, 2, 2], Eltseq(t));\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 3 over GF(7)\nU1 : Full Vector space of degree 2 over GF(7)\nU0 : Full Vector space of degree 2 over GF(7)\n> \n> t eq s;\ntrue\n\\end{code}\n\\end{example}\n\n\n\\begin{example}[SCStored]\n\nThe structure constants are convenient data structure for nearly all the\nalgorithms in TensorSpace. In fact, most computations require structure\nconstants, so we store the structure constants sequence with the tensor. This\nmeans that after the initial structure constant sequence computation, every time\n\\texttt{StructureConstants} or \\texttt{Eltseq} is called, \\textsf{Magma} retrieves what\nwas previously computed. \n\nWe will demonstrate this on a large black-box example, so some time is spent\ncomputing the structure constants. Of course, the exact timing will vary by\nmachine. We will construct a product of two subalgebras of\n$\\mathbb{M}_{20}(\\mathbb{F}_3)$, namely $* :\n\\mathfrak{sl}_{20}(\\mathbb{F}_3)\\times \\mathbb{M}_4(\\mathbb{F}_3)\\rightarrowtail\n\\mathbb{M}_{20}(\\mathbb{F}_3)$.\n\n\\begin{code}\n> sl20 := MatrixLieAlgebra(\"A19\", GF(3));\n> M4 := MatrixAlgebra(GF(3), 4);\n> Prod := func< x | Matrix(x[1])*DiagonalJoin(<x[2] : i in [1..5]>) >;\n> t := Tensor([* sl20, M4 *], MatrixAlgebra(GF(3), 20), Prod);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 399 over GF(3)\nU1 : Full Vector space of degree 16 over GF(3)\nU0 : Full Vector space of degree 400 over GF(3)\n\\end{code}\n\nWe record the time it takes to initially compute the structure constants\nsequence, and then we record the time when we call the function again.\n\\begin{code}\n> time sc := StructureConstants(t);\nTime: 58.670\n> \n> time sc := StructureConstants(t);\nTime: 0.000\n\\end{code}\n\\end{example}\n\n\n\n\n\n\\subsection{Bilinear tensors}\nA special case of structure constants for bilinear maps $U_2\\times\nU_1\\rightarrowtail U_0$ is to format the data as lists of matrices $[M_1,\\dots,\nM_d]$. This can be considered as a left (resp.~right) representation $U_2\\to\n\\hom_K(U_1,U_0)$, (resp.~$U_1\\to \\hom_K(U_2,U_0)$). Or it can be treated as {\\em\nsystems of bilinear forms} $[M_1,\\dots,M_d]$ where the matrices are the Gram\nmatrices of bilinear forms $\\phi_i:U_2\\times U_1\\rightarrowtail K$. Here the\nassociated bilinear map $U_2\\times U_1\\rightarrowtail U_0$ is specified by\n\\begin{align*}\n\t(u_2,u_1) & \\mapsto ( \\phi_1(u_2,u_1),\\dots, \\phi_a(u_2,u_1)).\n\\end{align*}\n\n\\index{Tensor!bilinear}\\index{Tensor!forms}\n\\begin{intrinsics}\nTensor(M, a, b) : Mtrx, RngIntElt, RngIntElt -> TenSpcElt\nTensor(M, a, b, Cat) : Mtrx, RngIntElt, RngIntElt, TenCat -> TenSpcElt\nTensor(M, a, b) : [Mtrx], RngIntElt, RngIntElt -> TenSpcElt\nTensor(M, a, b, Cat) : [Mtrx], RngIntElt, RngIntElt, TenCat -> TenSpcElt\n\\end{intrinsics}\n\nReturns the bilinear tensor given by the list of matrices.  The interpretation\nof the matrices as structure constants is specified by the coordinates $a$ and\n$b$ which must be positions in $\\{2,1,0\\}$. Optionally a tensor category\n\\texttt{Cat} can be assigned.\n\n\n\\begin{example}[SymplecticForm]\n\nWe will construct a symplectic bilinear form on $V=K^8$. It would be cumbersome\nto construct this tensor as a black-box tensor or by providing the structure\nconstants sequence. Instead, we will provide a (Gram) matrix. \n\\begin{code}\n> K := GF(17);\n> MS := KMatrixSpace(K, 2, 2);\n> J := KroneckerProduct(IdentityMatrix(K, 4), MS![0, 1, -1, 0]);\n> J;\n[ 0  1  0  0  0  0  0  0]\n[16  0  0  0  0  0  0  0]\n[ 0  0  0  1  0  0  0  0]\n[ 0  0 16  0  0  0  0  0]\n[ 0  0  0  0  0  1  0  0]\n[ 0  0  0  0 16  0  0  0]\n[ 0  0  0  0  0  0  0  1]\n[ 0  0  0  0  0  0 16  0]\n> \n> t := Tensor(J, 2, 1);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 8 over GF(17)\nU1 : Full Vector space of degree 8 over GF(17)\nU0 : Full Vector space of degree 1 over GF(17)\n> \n> IsAlternating(t);\ntrue\n\\end{code}\n\nNow we will construct the symplectic form using the black-box construction and\nverify that the two tensors are the same. \n\\begin{code}\n> V := VectorSpace(K, 8);\n> symp := func< x | x[1]*J*Matrix(8, 1, Eltseq(x[2])) >;\n> s := Tensor([V, V], VectorSpace(K, 1), symp);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 8 over GF(17)\nU1 : Full Vector space of degree 8 over GF(17)\nU0 : Full Vector space of degree 1 over GF(17)\n> \n> SystemOfForms(s);\n[\n    [ 0  1  0  0  0  0  0  0]\n    [16  0  0  0  0  0  0  0]\n    [ 0  0  0  1  0  0  0  0]\n    [ 0  0 16  0  0  0  0  0]\n    [ 0  0  0  0  0  1  0  0]\n    [ 0  0  0  0 16  0  0  0]\n    [ 0  0  0  0  0  0  0  1]\n    [ 0  0  0  0  0  0 16  0]\n]\n\\end{code}\n\\end{example}\n\n\\index{AsMatrices}\\index{SystemOfForms}\n\\begin{intrinsics}\nAsMatrices(t, a, b) : TenSpcElt, RngIntElt, RngIntElt -> SeqEnum\nSystemOfForms(t) : TenSpcElt -> SeqEnum\n\\end{intrinsics}\n\nFor a tensor $t$ with frame $[K^{d_{\\vav}},\\dots,K^{d_0}]$, \nreturns a list $[M_1,\\dots,M_d]$, $d=(d_{\\vav}\\cdots d_0)/(d_a d_b)$, \nof $(d_a\\times d_b)$-matrices in $K$ representing the tensor\nas an element of $\\hom_K(K^{d_a}\\otimes_K K^{d_b},K^d)$.\nFor \\texttt{SystemOfForms}, $t$ must have valence $3$ and the implied values are $a=2$ and $b=1$.\n\n\n\\begin{example}[TrilinearAsMats]\n\nWe construct the associator of $\\mathfrak{sl}_2(\\mathbb{Q})$ where \n$\\langle \\,\\rangle : \\prod_{k=1}^3\\mathfrak{sl}_2\\rightarrowtail \\mathfrak{sl}_2$ \ngiven by\n\\[ \n    \\langle x,y,z \\rangle = [[x,y],z] - [x,[y,z]]. \n\\]\nIt can be hard to understand some of the features of this trilinear map by only\nlooking at the structure constants sequence. The function \\texttt{AsMatrices}\nslices the sequence and presents the data as a sequence of matrices.\n\\begin{code}\n> K := Rationals();\n> L := LieAlgebra(\"A1\", K);\n> t := AssociatorTensor(L);\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 3 over Rational Field\nU2 : Full Vector space of degree 3 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 3 over Rational Field\n>\n> Eltseq(t);\n[ 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 0,\n0,-2, 0, 0, 0, 0, 0, 0, 0, 2, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 2, 0, 0, 0,\n0, 0, 0, 0, -2, 0, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2,\n0, 0, 0, 0, 0, 0 ]\n\\end{code}\n\nCalling \\texttt{AsMatrices(t, 3, 1)} returns a sequence of nine matrices, but we\nonly show the first four. As explained in the documentation above, this sequence\nof matrices can be interpreted as the system of bilinear forms for the 3-tensor\n$\\circ_{31} : V_3 \\times V_1 \\rightarrowtail \\Hom_K(V_2,V_0)$ given by\n\\[ x\\circ_{31} z = \\langle x, -,z \\rangle = [[x,-],z] - [x,[-,z]].\\]\n\n\\begin{code}\n> AsMatrices(t, 3, 1)[1..4];\n[\n    [ 0  0  2]\n    [ 0  0  0]\n    [-2  0  0],\n\n    [ 0  0  0]\n    [ 0  0  2]\n    [ 0 -2  0],\n\n    [0 0 0]\n    [0 0 0]\n    [0 0 0],\n\n    [ 0  1  0]\n    [-1  0  0]\n    [ 0  0  0]\n]\n\\end{code}\n\\end{example}\n\n\n\n\\subsection{Tensors from algebraic objects}\nA natural and important source of tensors come from algebraic object with a\ndistributive property. One main source is from algebras, where $*:A\\times\nA\\rightarrowtail A$ is given by multiplication in $A$. Like with the previous\nsections on tensor constructions, all tensors will be constructed over vector\nspaces. The user can still input elements from the original algebra, but map(s)\nwill also be returned. Furthermore, each tensor is assigned a category relevant\nto its origin, see Chapter~\\ref{ch:tensor-categories} for more details on tensor\ncategories. \n\n\n\\index{Tensor!algebra}\n\\begin{intrinsics}\nTensor(A) : Alg -> TenSpcElt, Map\n\\end{intrinsics}\n\nReturns the bilinear tensor given by the product in algebra $A$.\n\n\\begin{example}[D4LieAlgebra]\n\nWe want to get the Lie bracket from $\\mathfrak{so}_8(\\mathbb{F}_{11})$. Tensors created from algebras\nwill have a homotopism category, but with $U_2=U_1=U_0$. This forces the\noperators acting to be the same on all the coordinates; in other words,\n$\\Omega=\\End(U_2)$ instead of $\\Omega=\\End(U_2)\\times\\End(U_1)\\times\\End(U_0)$. \n\\begin{code}\n> D := DerivationAlgebra(T);\n> L := LieAlgebra(\"D4\", GF(11));\n> t := Tensor(L);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 28 over GF(11)\nU1 : Full Vector space of degree 28 over GF(11)\nU0 : Full Vector space of degree 28 over GF(11)\n> IsAlternating(t);\ntrue\n> TensorCategory(t);\nTensor category of valence 3 (->,->,->) ({ 0, 1, 2 })\n\\end{code}\n\nIf we compute the derivation algebra of $L$, our operators will act in the same\nway on each coordinate. This is the standard definition of the derivation\nalgebra of a ring.\n\\begin{code}\n> D := DerivationAlgebra(t);\n> Dimension(D);\n28\n> SemisimpleType(D);\nD4\n\\end{code}\n\nNow we will change the category to the standard homotopism category, where we do\n\\emph{not} fuse $U_2$, $U_1$, and $U_0$. \n\\begin{code}\n> ChangeTensorCategory(~t, HomotopismCategory(3));\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 28 over GF(11)\nU1 : Full Vector space of degree 28 over GF(11)\nU0 : Full Vector space of degree 28 over GF(11)\n> TensorCategory(t);\nTensor category of valence 3 (->,->,->) ({ 1 },{ 2 },{ 0 })\n\\end{code}\n\nWe compare the same computation of derivation algebra. This time, the theory\ntells us that there will be a solvable radical. In this example, Rad$(D)=K^2$. \n\\begin{code}\n> D := DerivationAlgebra(t);\n> Dimension(D);\n30\n> R := SolvableRadical(D);\n> SemisimpleType(D/R);\nD4\n\\end{code}\n\\end{example}\n\n\\index{Tensor!polynomial ring}\n\\begin{intrinsics}\nTensor(Q) : RngUPolRes -> TenSpcElt, Map\n\\end{intrinsics}\n\nReturns the bilinear tensor given by the product in quotient polynomial ring $Q$.\n\n\\begin{example}[WittAlgebra]\n\nThe Witt algebra over a finite field of characteristic $p$ is isomorphic to\nthe derivation algebra of $K[x]/(x^p)$. The Witt algebra is a simple Lie algebra\nwith dimension $p$ and a trivial Killing form. First, we will construct the\ntensor from the ring $\\mathbb{F}_5[x]/(x^5)$. Note that, like with algebras, the\ntensor category will fuse $U_2$, $U_1$, and $U_0$, so that the operators act the\nsame way on every coordinate.\n\\begin{code}\n> p := 5;\n> R<x> := PolynomialRing(GF(p));\n> I := ideal< R | x^p >;\n> Q := quo< R | I >;\n> Q;\nUnivariate Quotient Polynomial Algebra in $.1 over Finite field of size\n5 with modulus $.1^5\n> t := Tensor(Q);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over GF(5)\nU1 : Full Vector space of degree 5 over GF(5)\nU0 : Full Vector space of degree 5 over GF(5)\n> TensorCategory(t);\nTensor category of valence 3 (->,->,->) ({ 0, 1, 2 })\n\\end{code}\n\nNow we will construct a Lie representation of the Witt algebra from the tensor $t$. \n\\begin{code}\n> D := DerivationAlgebra(t);\n> IsSimple(D);\ntrue\n> Dimension(D);\n5\n> KillingForm(D);\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 0]\n\\end{code}\n\\end{example}\n\n\n\\index{CommutatorTensor}\\index{AnticommutatorTensor}\n\\begin{intrinsics}\nCommutatorTensor(A) : Alg -> TenSpcElt, Map\nAnticommutatorTensor(A) : Alg -> TenSpcElt, Map\n\\end{intrinsics}\n\nReturns the bilinear commutator map $[a,b]=ab-ba$ or the anticommutator map\n$\\langle a,b\\rangle = ab+ba$ of the algebra $A$. This should not be used to get\nthe tensor given by the Lie or Jordan product in a Lie or Jordan algebra;\ninstead use \\texttt{Tensor}.\n\n\\begin{example}[CommutatorFromAlgebra]\n\nWe will construct the commutator tensor from $\\mathbb{M}_4(\\mathbb{Q})$. \n\\begin{code}\n> A := MatrixAlgebra(Rationals(), 4);\n> t := CommutatorTensor(A);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 16 over Rational Field\nU1 : Full Vector space of degree 16 over Rational Field\nU0 : Full Vector space of degree 16 over Rational Field\n> IsAlternating(t); // [X, X] = 0?\ntrue\n\\end{code}\n\nWith this tensor, we will compute the dimension of the centralizer of the\ndiagonal matrix $M$ with diagonal entries $(1,1,-1,-1)$ in\n$\\mathbb{M}_4(\\mathbb{Q})$. To do this, we will subtract the dimension of the\nimage of $[M, A]$ from the dimension of $A$. \n\n\\begin{code}\n> M := A![1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,-1];\n> M;\n[ 1  0  0  0]\n[ 0  1  0  0]\n[ 0  0 -1  0]\n[ 0  0  0 -1]\n> Dimension(A) - Dimension(<M, A> @ t);\n8\n\\end{code}\n\\end{example}\n\n\\begin{example}[MatrixJordanAlgebra]\nThis time, we will obtain a Jordan product from $\\mathbb{M}_4(\\mathbb{Q})$. \nThat is, we will construct the bilinear map \n$* : \\mathbb{M}_4(\\mathbb{Q})\\times \\mathbb{M}_4(\\mathbb{Q})\\rightarrowtail \\mathbb{M}_4(\\mathbb{Q})$ \nwhere $A*B = \\frac{1}{2}(AB+BA)$. \n\\begin{code}\n> A := MatrixAlgebra(Rationals(), 4);\n> t := AnticommutatorTensor(A);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 16 over Rational Field\nU1 : Full Vector space of degree 16 over Rational Field\nU0 : Full Vector space of degree 16 over Rational Field\n> SystemOfForms(t)[1];\n[2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0]\n[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n> A.1*t*A.1;\n(2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)\n\\end{code}\n\nFrom the documentation on \\texttt{AnticommutatorTensor}, we have to scale our\ntensor above $t$ by $1/2$ to get what we want. Of course this won't affect the\nproceeding tests though.\n\\begin{code}\n> s := (1/2)*t;\n> A.1*s*A.1;\n(1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)\n\\end{code}\n\nNow we will confirm that $s$ is a Jordan product. First, we check that $s$ is\ncommutative, and then we check that it satisfies the Jordan identity:\n$(xy)(xx)=x(y(xx))$.\n\\begin{code}\n> IsSymmetric(s);\ntrue\n> JordanID := func< x, y | (x*s*y)*s*(x*s*x) - x*s*(y*s*(x*s*x)) >;\n> forall{ <x,y> : x in Basis(A), y in Basis(A) | \\\n>     JordanIdentity(x, y) eq Codomain(s)!0 };\ntrue\n\\end{code}\n\\end{example}\n\n\\index{AssociatorTensor}\n\\begin{intrinsics}\nAssociatorTensor(A) : Alg -> TenSpcElt, Map\n\\end{intrinsics}\n\nReturns the trilinear associator map $[a,b,c]=(ab)c-a(bc)$ of the algebra $A$.\n\n\\begin{example}[AssociatorFromAlgebra]\n\nDo three random octonions associate? Hardly ever.\n\n\\begin{code}\n> O := OctonionAlgebra(GF(1223),-1,-1,-1);\n> t := AssociatorTensor(O);\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 8 over GF(1223)\nU2 : Full Vector space of degree 8 over GF(1223)\nU1 : Full Vector space of degree 8 over GF(1223)\nU0 : Full Vector space of degree 8 over GF(1223)\n> <Random(O),Random(O),Random(O)> @ t eq O!0;\nfalse\n\\end{code}\n\nHowever, for all $a,b\\in\\mathbb{O}$, $(aa)b=a(ab)$ as octonions are alternative algebras.\n\n\\begin{code}\n> a := Random(O); \n> b := Random(O); \n> <a,a,b> @ t eq O!0;\ntrue\n> IsAlternating(t);\ntrue\n\\end{code}\n\\end{example}\n\n\n\\index{pCentralTensor}\n\\begin{intrinsics}\npCentralTensor(G, p, a, b) : Grp, RngIntElt, RngIntElt, RngIntElt -> TenSpcElt, List\npCentralTensor(G, a, b) : Grp, RngIntElt, RngIntElt -> TenSpcElt, List\npCentralTensor(G, a, b) : GrpPC, RngIntElt, RngIntElt -> TenSpcElt, List\npCentralTensor(G) : Grp -> TenSpcElt, List\n\\end{intrinsics}\n\nReturns the bilinear map of commutation from the associated graded Lie algebra\nof the lower exponent-$p$ central series $\\eta$ of $G$.  The bilinear map pairs\n$\\eta_a/\\eta_{a+1}$ with $ \\eta_{b}/\\eta_{b+1}$ into $\\eta_{a+b}/\\eta_{a+b+1}$.\nIf $a=b$ the tensor category is set to force $U_2=U_1$; otherwise it is the\ngeneral homotopism category. In addition, maps from the subgroups into the\nvector spaces are returned as a list. If $p$, $a$, and $b$ are not given, it is\nassumed $G$ is a $p$-group and $a=b=1$.\n\n\\begin{example}[TensorPGroup] \nGroups have a single binary operation. So even when groups are built from rings\nit can be difficult to recover the ring from the group operations. Tensors\nsupply one approach for that task. We will get the $p$-central tensor of a Sylow\n$p$-subgroup $P$ of $\\SL(3,125)$; however, we will lose the fact that there is a\nfield $\\mathbb{F}_{125}$. The tensor we will get back is $[,] : K^6\\times K^6\n\\rightarrowtail K^3$, where $K=\\mathbb{F}_5$. \n\n\\begin{code}\n> P := ClassicalSylow(SL(3,125),5);\n> Q := PCGroup(P); // Loose track of GF(125).\n> Q;\nGrpPC : Q of order 1953125 = 5^9\nPC-Relations:\n    Q.4^Q.1 = Q.4 * Q.7^4, \n    Q.4^Q.2 = Q.4 * Q.8^4, \n    Q.4^Q.3 = Q.4 * Q.9^4, \n    Q.5^Q.1 = Q.5 * Q.8^4, \n    Q.5^Q.2 = Q.5 * Q.9^4, \n    Q.5^Q.3 = Q.5 * Q.7^3 * Q.8^3, \n    Q.6^Q.1 = Q.6 * Q.9^4, \n    Q.6^Q.2 = Q.6 * Q.7^3 * Q.8^3, \n    Q.6^Q.3 = Q.6 * Q.8^3 * Q.9^3\n> t := pCentralTensor(Q);\n> t;\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 3 over GF(5)\n\\end{code}\n\nKnowing that $P$ is defined over $\\mathbb{F}_{125}$, we know that the commutator\nis really just the alternating form $\\cdot : \\mathbb{F}_{125}^2\\times\n\\mathbb{F}_{125}^2\\rightarrowtail \\mathbb{F}_{125}$. This information can be\nextracted from the centroid of $t$ above, and we can rewrite $t$ over the field\n$\\mathbb{F}_{125}$.\n\\begin{code}\n> F := Centroid(t); // Recover GF(125)\n> Dimension(F);\n3\n> IsSimple(F);\ntrue\n> IsCommutative(F);\ntrue\n> s := TensorOverCentroid(t);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 2 over GF(5^3)\nU1 : Full Vector space of degree 2 over GF(5^3)\nU0 : Full Vector space of degree 1 over GF(5^3)\n\\end{code}\n\\end{example}\n\n\n\\index{MatrixTensor}\n\\begin{intrinsics}\nMatrixTensor(K, S) : Fld, [RngIntElt] -> TenSpcElt, List\n\\end{intrinsics}\n\nGiven a field $K$ and a sequence of positive integers $S=[s_1,\\dots, s_{\\vav}]$,\nreturn the tensor \n\\[ \n    \\mathbb{M}_{s_1\\times s_2}(K) \\times \\cdots \n        \\times \\mathbb{M}_{s_{\\vav-1}\\times s_{\\vav}}(K)\\rightarrowtail \\mathbb{M}_{s_1\\times s_{\\vav}}(K), \n\\]\ngiven by matrix multiplication. A list of maps from the matrix spaces to the\nvector spaces is given as well even though the given tensor will evaluate\nmatrices as well. \n\n\n\\index{Polarisation}\\index{Polarization}\n\\begin{intrinsics}\nPolarisation(f) : MPolElt -> TenSpcElt, MPolElt\nPolarisation(f) : RngUPolElt -> TenSpcElt\nPolarization(f) : MPolElt -> TenSpcElt, MPolElt\nPolarization(f) : RngUPolElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the polarization of the homogeneous multivariate polynomial (or\nunivariate polynomial) $f$ as a tensor and as a multivariate polynomial.\nPolarization does \\emph{not} normalize by $1/d!$, where $d$ is the degree of\n$f$.  \n\n\\begin{example}[TensorPolarization] We polarize the polynomial $f(x,y)=x^2y$.\nBecause $f$ is homogeneous of degree 3 with 2 variables, we expect that the\npolarization will have 6 variables and that the corresponding multilinear form\nwill be $K^2\\times K^2\\times K^2\\rightarrowtail K$. The polarization of $f$ is\ngiven by $P(x_1,x_2,y_1,y_2,z_1,z_2 ) = 2 (x_1y_1z_2 + x_1y_2z_1 + x_2y_1z_1)$.\n\n\\begin{code}\n> R<x,y> := PolynomialRing(Rationals(),2);\n> t, p := Polarization(x^2*y);\n> p;\n2*$.1*$.3*$.6 + 2*$.1*$.4*$.5 + 2*$.2*$.3*$.5\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 2 over Rational Field\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> <[1,0],[1,0],[1,0]> @ t;\n(0)\n> <[1,0],[1,0],[0,1]> @ t;\n(2)\n\\end{code}\n\\end{example}\n\n\n\n\n\\subsection{New tensors from old}\nWe can construct new tensors from old.\n\n\\index{AlternatingTensor}\n\\begin{intrinsics}\nAlternatingTensor(t) : TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the alternating tensor induced by the given tensor. If \nthe tensor is already alternating, then the given tensor is returned.\n\n\\index{AntisymmetricTensor}\n\\begin{intrinsics}\nAntisymmetricTensor(t) : TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the antisymmetric tensor induced by the given tensor. If \nthe tensor is already antisymmetric, then the given tensor is returned.\n\n\\index{SymmetricTensor}\n\\begin{intrinsics}\nSymmetricTensor(t) : TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the symmetric tensor induced by the given tensor. If the tensor is \nalready symmetric, then the given tensor is returned.\n\n\\begin{example}[AlternatingTensor]\n\nTensors coming from Lie algebras are alternating.\nIf we call \\texttt{AlternatingTensor} on a tensor from a Lie algebra, nothing will be changed.\n\\begin{code}\n> L := LieAlgebra(\"A3\", GF(3));\n> t := Tensor(L);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 15 over GF(3)\nU1 : Full Vector space of degree 15 over GF(3)\nU0 : Full Vector space of degree 15 over GF(3)\n> AlternatingTensor(t) eq t;\ntrue\n\\end{code}\n\\end{example}\n\n\\begin{example}[MakeSymmetric]\n\nWe will make the tensor coming from the product in $\\mathbb{M}_3(\\mathbb{Q})$ symmetric.\n\\begin{code}\n> A := MatrixAlgebra(Rationals(), 3);\n> t := Tensor(A);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 9 over Rational Field\nU1 : Full Vector space of degree 9 over Rational Field\nU0 : Full Vector space of degree 9 over Rational Field\n> SystemOfForms(t)[1];\n[1 0 0 0 0 0 0 0 0]\n[0 0 0 1 0 0 0 0 0]\n[0 0 0 0 0 0 1 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n\\end{code}\n\nWe see that the first matrix in the sequence of bilinear forms of $t$ is not\nsymmetric, so $t$ is not symmetric (of course matrix multiplication is not\ncommutative also). We will construct a symmetric version of $t$ and inspect the\nfirst matrix of the bilinear forms.\n\\begin{code}\n> s := SymmetricTensor(t);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 9 over Rational Field\nU1 : Full Vector space of degree 9 over Rational Field\nU0 : Full Vector space of degree 9 over Rational Field\n> SystemOfForms(s)[1];\n[2 0 0 0 0 0 0 0 0]\n[0 0 0 1 0 0 0 0 0]\n[0 0 0 0 0 0 1 0 0]\n[0 1 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 1 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n[0 0 0 0 0 0 0 0 0]\n\\end{code}\n\\end{example}\n\n\n\\index{Shuffle!tensors}\n\\begin{intrinsics}\nShuffle(t, g) : TenSpcElt, GrpPermElt -> TenSpcElt\nShuffle(t, g) : TenSpcElt, SeqEnum -> TenSpcElt\n\\end{intrinsics}\n\nFor a tensor $t$ in $\\hom(U_{\\vav},\\dots,\\hom(U_1,U_0)\\cdots)$, \ngenerates a representation of $t$ in \n\\[ \\hom(U_{{\\vav}^g},\\dots,\\hom(U_{1^g},U_{0^g})\\dots). \\]\nIn order to be defined, $g\\in\\text{Sym}(\\zrange{\\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}(\\range{\\vav})$.\nSequences $[a_1,\\dots,a_{\\vav+1}]$ are interpreted as \n\\[ \n    \\begin{array}{cccc} \n        0 & 1 & \\cdots & \\vav \\\\ \n    \\downarrow & \\downarrow & & \\downarrow \\\\ \n    a_1 & a_2 & \\cdots & a_{\\vav+1}. \n    \\end{array}\n\\]\n\n\\begin{example}[ShuffleToTranspose]\n\nWe will shuffle the alternating form\n$\\mathbb{Q}^2\\times\\mathbb{Q}^2\\rightarrowtail \\mathbb{Q}$ as a means of\nperforming a transpose on the Gram matrix. To do this, we need to shuffle by the\ntransposition $(1, 2)$ in Sym$(\\{0,1,2\\})$. \n\\begin{code}\n> t := Tensor(Rationals(), [2, 2, 1], [0, 1, -1, 0]);\n> t;\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 1 over Rational Field\n> SystemOfForms(t);\n[\n    [ 0  1]\n    [-1  0]\n]\n> \n> s := Shuffle(t, [0,2,1]);\n> s;\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 1 over Rational Field\n> SystemOfForms(s);\n[\n    [ 0 -1]\n    [ 1  0]\n]\n\\end{code}\n\\end{example}\n\n\\begin{example}[Shuffling]\n\nWe will generate a random 5-tensor and shuffle it with $(0,2,4,1,3)$.\n\\begin{code}\n> t := RandomTensor(GF(2), [5,4,3,2,1]);\n> t;\nTensor of valence 5, U4 x U3 x U2 x U1 >-> U0\nU4 : Full Vector space of degree 5 over GF(2)\nU3 : Full Vector space of degree 4 over GF(2)\nU2 : Full Vector space of degree 3 over GF(2)\nU1 : Full Vector space of degree 2 over GF(2)\nU0 : Full Vector space of degree 1 over GF(2)\n> \n> G := Sym({0..4});\n> g := G![2, 3, 4, 0, 1];\n> g;\n(0, 2, 4, 1, 3)\n> \n> s := Shuffle(t, g);\n> s;\nTensor of valence 5, U4 x U3 x U2 x U1 >-> U0\nU4 : Full Vector space of degree 2 over GF(2)\nU3 : Full Vector space of degree 1 over GF(2)\nU2 : Full Vector space of degree 5 over GF(2)\nU1 : Full Vector space of degree 4 over GF(2)\nU0 : Full Vector space of degree 3 over GF(2)\n\\end{code}\n\\end{example}\n\n\n\\index{TensorProduct}\n\\begin{intrinsics}\nTensorProduct(t, s) : TenSpcElt, TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nGiven $K$-tensors $t:U_{\\vav}\\times \\cdots \\times U_1\\rightarrowtail U_0$ and\n$s:V_{\\vav}\\times \\cdots \\times V_1\\rightarrowtail V_0$, returns the tensor\n$t\\otimes s : U_{\\vav}\\otimes V_{\\vav}\\times \\cdots \\times U_1\\otimes\nV_1\\rightarrowtail U_0\\otimes V_0$. This is like a generalized Kronecker\nproduct. \n\n\n\\section{Operations with Tensors}\n\nWe take two perspectives for operations with tensors. \nFirst, tensors determine multilinear maps and so behave as\nfunctions.  Second, tensors are elements of a tensor space and \nso behave as elements in a module.  \n\n\\subsection{Elementary operations}\nTreating the tensor space as a $K$-module, we have the standard operations.\n\n\\index{$+$}\\index{$*$!as module}\n\\begin{intrinsics}\ns + t : TenSpcElt, TenSpcElt -> TenSpcElt\ns - t : TenSpcElt, TenSpcElt -> TenSpcElt\nk * t : RngElt, TenSpcElt -> TenSpcElt\n-t : TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the sum, difference, scalar multiple, or additive inverse of the given\ntensor(s) as module elements of the tensor space. The corresponding multilinear\nmaps are the sum, difference, scalar multiple, or additive inverse of the\nmultilinear maps.\n\n\\begin{example}[ModuleOperations]\n\nAs tensors are elements of a tensor space, it inherits module operations. \nWe will demonstrate them all here.\nFirst, here are the tensors we will operate with.\n\\begin{code}\n> K := Rationals();\n> t := Tensor(K, [2, 2, 2], [1..8]);\n> s := Tensor(K, [2, 2, 2], &cat[[2, -1] : i in [1..4]]);\n> SystemOfForms(t);\n[\n    [1 3]\n    [5 7],\n\n    [2 4]\n    [6 8]\n]\n> SystemOfForms(s);\n[\n    [2 2]\n    [2 2],\n\n    [-1 -1]\n    [-1 -1]\n]\n\\end{code}\n\nNow we perform the module operations.\n\\begin{code}\n> SystemOfForms(-t);\n[\n    [-1 -3]\n    [-5 -7],\n\n    [-2 -4]\n    [-6 -8]\n]\n> SystemOfForms((1/3)*s);\n[\n    [2/3 2/3]\n    [2/3 2/3],\n\n    [-1/3 -1/3]\n    [-1/3 -1/3]\n]\n> SystemOfForms(t+s);\n[\n    [3 5]\n    [7 9],\n\n    [1 3]\n    [5 7]\n]\n> SystemOfForms(t-2*s);\n[\n    [-3 -1]\n    [ 1  3],\n\n    [ 4  6]\n    [ 8 10]\n]\n\\end{code}\n\\end{example}\n\n\\index{AssociatedForm}\n\\begin{intrinsics}\nAssociatedForm(t) : TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nFor a tensor $t$ with frame $U_{\\vav}\\times \\cdots \\times U_1\\rightarrowtail U_0$,\ncreates the associated multilinear form\n$U_{\\vav}\\times\\cdots\\times U_1\\times U_0^*\\rightarrowtail K$. \nThe valence is increased by $1$.\n\n\\index{Compress}\n\\begin{intrinsics}\nCompress(t) : TenSpcElt -> TenSpcElt\nCompress(~t) : TenSpcElt -> \n\\end{intrinsics}\n\nReturns the compression of the tensor. This removes all 1-dimensional spaces in the domain.\n\n\\begin{example}[CompressAssocForm]\n\nWe will construct the associated form of the tensor from the Lie algebra of type\n$B_3$ over $\\mathbb{F}_5$. The codomain of the original tensor gets moved (and\ndualized) to the domain. \n\\begin{code}\n> L := LieAlgebra(\"B3\", GF(5));\n> t := Tensor(L); \n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 21 over GF(5)\nU1 : Full Vector space of degree 21 over GF(5)\nU0 : Full Vector space of degree 21 over GF(5)\n> s := AssociatedForm(t);\n> s;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 21 over GF(5)\nU2 : Full Vector space of degree 21 over GF(5)\nU1 : Full Vector space of degree 21 over GF(5)\nU0 : Full Vector space of degree 1 over GF(5)\n> <L.2, L.11> @ t;\n(0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)\n> <L.2, L.11, L.2> @ s;\n(4)\n> <L.2, L.11, L> @ s;\nFull Vector space of degree 1 over GF(5)\nGenerators:\n(4)\n\\end{code}\n\nWe shuffle the associated form by the permutation $(0,3)$ and compress it.\nThe result is just the shuffle of the original bilinear map $t$ by $(0,2,1)$.\n\n\\begin{code}\n> shf := Shuffle(s, [3,1,2,0]);\n> shf;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 1 over GF(5)\nU2 : Full Vector space of degree 21 over GF(5)\nU1 : Full Vector space of degree 21 over GF(5)\nU0 : Full Vector space of degree 21 over GF(5)\n> cmp := Compress(shf);\n> cmp;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 21 over GF(5)\nU1 : Full Vector space of degree 21 over GF(5)\nU0 : Full Vector space of degree 21 over GF(5)\n> cmp eq Shuffle(t, [2, 0, 1]);\ntrue\n\\end{code}\n\\end{example}\n\n\\subsection{General properties}\n\nWe provide basic intrinsics to get data stored in the \\texttt{TenSpcElt} object\nin \\textsf{Magma}. Most of these functions are already stored as attributes. The ones\nthat are not initially stored at construction are stored immediately after the\ninitial computation, such as \\texttt{Image}.\n\n\\index{Parent!tensor}\n\\begin{intrinsics}\nParent(t) : TenSpcElt -> TenSpc\n\\end{intrinsics}\n\nReturns the tensor space that contains $t$. The default space is the universal \ntensor space.\n\n\\index{Domain!tensor}\n\\begin{intrinsics}\nDomain(t) : TenSpcElt -> List\n\\end{intrinsics}\n\nReturns the domain of the tensor as a list of modules.\n\n\\index{Codomain!tensor}\n\\begin{intrinsics}\nCodomain(t) : TenSpcElt -> Any\n\\end{intrinsics}\n\nReturns the codomain of the tensor.\n\n\\index{Valence!tensor}\n\\begin{intrinsics}\nValence(t) : TenSpcElt -> RngIntElt\n\\end{intrinsics}\n\nReturns the valence of the tensor.\n\n\\index{Frame!tensor}\n\\begin{intrinsics}\nFrame(t) : TenSpcElt -> List\n\\end{intrinsics}\n\nReturns the modules in the frame of $t$; this is the concatenation of\nthe domain modules and the codomain.\n\n\\index{BaseRing!tensor}\\index{BaseField!tensor}\n\\begin{intrinsics}\nBaseRing(t) : TenSpcElt -> Rng\nBaseField(t) : TenSpcElt -> Fld\n\\end{intrinsics}\n\nReturns the base ring or field of the tensor.\n\n\\begin{example}[BasicProps]\n\nWe demonstrate how to get basic properties of a tensor and what to expect as an\noutput. We will construct a tensor $\\bra{t}:\\mathbb{M}_{2\\times 3}(\\mathbb{Q})\\times\n\\mathbb{Q}^3\\rightarrowtail \\mathbb{Q}^2$ given by multiplication. Nearly all of\nthis information is displayed when printing a tensor.\n\\begin{code}\n> K := Rationals();\n> U2 := KMatrixSpace(K, 2, 3);\n> U1 := VectorSpace(K, 3);\n> U0 := VectorSpace(K, 2);\n> mult := func< x | Eltseq(x[1]*Matrix(3,1,Eltseq(x[2]))) >;\n> t := Tensor([* U2, U1, U0 *], 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 2 over Rational Field\n> \n> Parent(t);\nTensor space of dimension 36 over Rational Field with valence 3\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 2 over Rational Field\n> \n> Domain(t);\n[*\n    Full Vector space of degree 6 over Rational Field,\n\n    Full Vector space of degree 3 over Rational Field\n*]\n> \n> Codomain(t);\nFull Vector space of degree 2 over Rational Field\n> \n> Valence(t);\n3\n> \n> Frame(t);\n[*\n    Full Vector space of degree 6 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\\index{TensorCategory!tensor}\n\\begin{intrinsics}\nTensorCategory(t) : TenSpcElt -> TenCat\n\\end{intrinsics}\n\nReturns the underlying tensor category of $t$.\n\n\\index{ChangeTensorCategory!tensor}\n\\begin{intrinsics}\nChangeTensorCategory(t, C) : TenSpcElt, TenCat -> TenSpcElt\nChangeTensorCategory(~t, C) : TenSpcElt, TenCat -> \n\\end{intrinsics}\n\nReturns the tensor with the given category.\n\n\\index{IsCovariant!tensor}\\index{IsContravariant!tensor}\n\\begin{intrinsics}\nIsCovariant(t) : TenSpcElt -> BoolElt\nIsContravariant(t) : TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides if the underlying category of $t$ is covariant or contravariant.\n\n\\begin{example}[TensorCatProps]\n\nWe will construct a tensor from a right module, $\\bra{t}:\\mathbb{Q}^2 \\times\n\\mathbb{M}_{2\\times 2}(\\mathbb{Q})\\rightarrowtail \\mathbb{Q}^2$.\n\\begin{code}\n> K := Rationals();\n> U := KMatrixSpace(K, 2, 2);\n> V := VectorSpace(K, 2);\n> mult := func< x | x[1]*x[2] >;\n> t := Tensor([* V, U, V *], mult);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n\\end{code}\n\nBecause this tensor comes from a module, we want the tensor category to reflect this.\nCurrently, the tensor category is the default homotopism category.\nWe will keep everything about the category the same, except we will fuse coordinates 2 and 0.\nThese changes could easily go unnoticed if no operators are constructed.\n\\begin{code}\n> TensorCategory(t);\nTensor category of valence 3 (->,->,->) ({ 1 },{ 2 },{ 0 })\n> Cat := TensorCategory([1, 1, 1], {{2,0},{1}});\n> Cat;\nTensor category of valence 3 (->,->,->) ({ 1 },{ 0, 2 })\n> ChangeTensorCategory(~t, Cat);\n> TensorCategory(t);\nTensor category of valence 3 (->,->,->) ({ 1 },{ 0, 2 })\n> IsCovariant(t);\ntrue\n\\end{code}\n\\end{example}\n\n\\index{NondegenerateTensor}\n\\begin{intrinsics}\nNondegenerateTensor(t) : TenSpcElt -> TenSpcElt, Hmtp\n\\end{intrinsics}\n\nReturns the nondegenerate tensor associated to $t$ along with a homotopism \nfrom the given tensor to the returned nondegenerate tensor.\n\n\\index{IsNondegenerate}\n\\begin{intrinsics}\nIsNondegenerate(t) : TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides whether $t$ is a nondegenerate tensor.\n\n\n\\begin{example}[Nondegeneracy]\n\nAn important property for tensors is nondegeneracy: all radicals are trivial.\nFirst we create a tensor with degeneracy.\n\\begin{code}\n> K := GF(541);\n> V := VectorSpace(K, 10);\n> U := VectorSpace(K, 5);\n> mult := function(x)\nfunction>   M := Matrix(3, 3, Eltseq(x[1])[2..10]);\nfunction>   v := VectorSpace(K, 3)!(Eltseq(x[2])[[1,3,5]]);\nfunction>   return Eltseq(v*M) cat [0,0];\nfunction> end function;\n> t := Tensor([V, U, U], mult);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 10 over GF(541)\nU1 : Full Vector space of degree 5 over GF(541)\nU0 : Full Vector space of degree 5 over GF(541)\n\\end{code}\n\nIn this example, both $U_{2}^\\perp$ and $U_{1}^\\perp$ are nontrivial. We will\nconstruct the associated nondegenerate tensor $\\bra{s} : U_2/U_{2}^\\perp \\times\nU_1/U_{1}^\\perp \\rightarrowtail U_0$. \n\\begin{code}\n> IsNondegenerate(t);\nfalse\n> s, H := NondegenerateTensor(t);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 9 over GF(541)\nU1 : Full Vector space of degree 3 over GF(541)\nU0 : Full Vector space of degree 5 over GF(541)\n> H;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: Mapping from: Full Vector space of degree 10 over GF(541) to \nFull Vector space of degree 9 over GF(541)\nU1 -> V1: Mapping from: Full Vector space of degree 5 over GF(541) to \nFull Vector space of degree 3 over GF(541)\nU0 -> V0: Mapping from: Full Vector space of degree 5 over GF(541) to \nFull Vector space of degree 5 over GF(541)\n\\end{code}\n\\end{example}\n\n\\index{Image!tensor}\n\\begin{intrinsics}\nImage(t) : TenSpcElt -> ModTupRng\n\\end{intrinsics}\n\nReturns the image of the tensor along with a map to the vector space.\n\n\\index{FullyNondegenerateTensor}\n\\begin{intrinsics}\nFullyNondegenerateTensor(t) : TenSpcElt -> TenSpcElt, Hmtp\n\\end{intrinsics}\n\nReturns the fully nondegenerate tensor associated to $t$ along with a\ncohomotopism from the given tensor to the returned tensor.\n\n\\index{IsFullyNondegenerate}\n\\begin{intrinsics}\nIsFullyNondegenerate(t) : TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides whether $t$ is a fully nondegenerate tensor.\n\n\\begin{example}[FullyNondegenerate]\n\nWe use the same tensor as the previous example illustrating the use of \\texttt{NondegenerateTensor}.\n\\begin{code}\n> K := GF(541);\n> V := VectorSpace(K, 10);\n> U := VectorSpace(K, 5);\n> mult := function(x)\nfunction>   M := Matrix(3, 3, Eltseq(x[1])[2..10]);\nfunction>   v := VectorSpace(K, 3)!(Eltseq(x[2])[[1,3,5]]);\nfunction>   return Eltseq(v*M) cat [0,0];\nfunction> end function;\n> t := Tensor([V, U, U], mult);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 10 over GF(541)\nU1 : Full Vector space of degree 5 over GF(541)\nU0 : Full Vector space of degree 5 over GF(541)\n\\end{code}\n\nHere, we want to construct a fully nondegenerate tensor. Of course, the tensor\nfrom the previous example is not fully nondegenerate as it is not degenerate,\nbut we check that the image is not isomorphic to the codomain.\n\\begin{code}\n> IsFullyNondegenerate(t);\nfalse\n> Image(t);\nVector space of degree 5, dimension 3 over GF(541)\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\nNow we will construct the associated fully nondegenerate tensor: $\\bra{s}:\nU_2/U_{2}^\\perp\\times U_1/U_{1}^\\perp\\rightarrowtail \\bra{t} U_2, U_1\\rangle$.\nNotice that the morphism between the original tensor and the fully nondegenerate\ntensor is a cohomotopism.\n\\begin{code}\n> s, H := FullyNondegenerateTensor(t);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 9 over GF(541)\nU1 : Full Vector space of degree 3 over GF(541)\nU0 : Vector space of degree 5, dimension 3 over GF(541)\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> H;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: Mapping from: Full Vector space of degree 10 over GF(541) to\nFull Vector space of degree 9 over GF(541)\nU1 -> V1: Mapping from: Full Vector space of degree 5 over GF(541) to\nFull Vector space of degree 3 over GF(541)\nU0 <- V0: Mapping from: Full Vector space of degree 5 over GF(541) to\nFull Vector space of degree 5 over GF(541)\nComposition of Mapping from: Full Vector space of degree 5 over GF(541)\nto Full Vector space of degree 5 over GF(541) and\nMapping from: Vector space of degree 5, dimension 3 over GF(541) to Full\nVector space of degree 5 over GF(541)\n\\end{code}\n\\end{example}\n\n\\index{IsAlternating!tensor}\\index{IsAntisymmetric!tensor}\n\\begin{intrinsics}\nIsAlternating(t) : TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides whether $t$ is an alternating tensor.\n\n\\index{IsAntisymmetric!tensor}\n\\begin{intrinsics}\nIsAntisymmetric(t) : TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides whether $t$ is an antisymmetric tensor.\n\n\\index{IsSymmetric!tensor}\n\\begin{intrinsics}\nIsSymmetric(t) : TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides whether $t$ is a symmetric tensor.\n\n\\begin{example}[SymmetricPolar]\n\nWe will construct the multilinear form given by polarizing the homogeneous\npolynomial $f(x,y,z)=x^3+y^3+z^3+xyz$. Since $f$ is a symmetric polynomial, its\nmultilinear form is also symmetric. \n\\begin{code}\n> K := Rationals();\n> R<x,y,z> := PolynomialRing(K, 3);\n> f := x^3 + y^3 + z^3 + x*y*z;\n> t, p := Polarization(f);\n> p;\n6*$.1*$.4*$.7 + $.1*$.5*$.9 + $.1*$.6*$.8 + $.2*$.4*$.9 + \n    6*$.2*$.5*$.8 + $.2*$.6*$.7 + $.3*$.4*$.8 + $.3*$.5*$.7 + \n    6*$.3*$.6*$.9\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 3 over Rational Field\nU2 : Full Vector space of degree 3 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n\\end{code} %$ \n\nThe resulting homogeneous polynomial from polarizing is \n\\[ \n    p(x_1,x_2,x_3,y_1,y_2,y_3,z_1,z_2,z_3) \n        =\\sum_{\\sigma\\in S_3} (x_{1^\\sigma}y_{2^\\sigma}z_{3^\\sigma} \n            + 3x_{1^\\sigma}y_{1^\\sigma}z_{1^\\sigma}).\n\\]\n\\begin{code}\n> IsSymmetric(t);\ntrue\n> AsMatrices(t, 3, 1) eq AsMatrices(t, 2, 1);\ntrue\n> AsMatrices(t, 3, 1) eq AsMatrices(t, 3, 2);\ntrue\n> AsMatrices(t, 3, 1);\n[\n    [6 0 0]\n    [0 0 1]\n    [0 1 0],\n\n    [0 0 1]\n    [0 6 0]\n    [1 0 0],\n\n    [0 1 0]\n    [1 0 0]\n    [0 0 6]\n]\n\\end{code}\n\nBecause the underlying field is $\\mathbb{Q}$ and because $t$ \nis symmetric, we know that $t$ is not alternating nor antisymmetric.\n\\begin{code}\n> IsAlternating(t);\nfalse\n> IsAntisymmetric(t);\nfalse\n\\end{code}\n\\end{example}\n\n\n\n\\subsection{As multilinear maps}\nRegarding tensors as multilinear maps, we allow for evaluation and composition.\n\n\\index{AT!tensor}\n\\begin{intrinsics}\nx @ t : Tup, TenSpcElt -> Any\n\\end{intrinsics}\n\nReturns $\\bra{t} x\\rangle$, where $x\\in U_{\\vav}\\times \\cdots \\times U_1$. The\nentries can be elements from the vector space $U_i$ or sequences that\n\\textsf{Magma} can naturally coerce into the vector space $U_i$. In some\ncircumstances, tensors come from algebraic objects (e.g.\\! algebras), and in\nthese cases the entries of $x$ can be contained in the original algebraic object\nas well. \n\n\\begin{example}[MultiMapEval]\n\nHere we create the 4-tensor $\\bra{t}$ of an algebra $A$ given by the Jacobi identity: \n\\[ (x,y,z)\\mapsto (xy)z + (yz)x + (zx)y. \\]\nTherefore, the algebra satisfies the Jacobi identity if $\\bra{t} A, A, A \\rangle\n= 0$. We will also change the tensor category so that all the coordinates are\nfused together.\n\\begin{code}\n> A := MatrixAlgebra(GF(3), 3);\n> JacobiID := func< x | x[1]*x[2]*x[3]+x[2]*x[3]*x[1]+x[3]*x[1]*x[2] >;\n> Cat := TensorCategory([1 : i in [0..3]], {{0..3}});\n> t, maps := Tensor([A : i in [0..3]], JacobiID, Cat);\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 9 over GF(3)\nU2 : Full Vector space of degree 9 over GF(3)\nU1 : Full Vector space of degree 9 over GF(3)\nU0 : Full Vector space of degree 9 over GF(3)\n> TensorCategory(t);\nTensor category of valence 4 (->,->,->,->) ({ 0 .. 3 })\n\\end{code}\n\nEven though our tensor originated over the algebra\n$A=\\mathbb{M}_{3}(\\mathbb{F}_3)$, the returned tensor is over vector spaces\n$\\mathbb{F}_3^9$. However, the tensor $\\bra{t}$ can still evaluate elements from\n$\\mathbb{M}_3(\\mathbb{F}_3)$ as well as $\\mathbb{F}_3^9$. Observe that the out\nof $\\bra{t}$ will be a vector regardless of the input. The second output at\nconstruction, the \\texttt{List} of maps, can be used to map the vectors to\n$\\mathbb{M}_3(\\mathbb{F}_3)$. \n\\begin{code}\n> x := <A.1, A.2, A.2^2>;\n> x;\n<\n    [1 0 0]\n    [0 0 0]\n    [0 0 0],\n\n    [0 1 0]\n    [0 0 1]\n    [1 0 0],\n\n    [0 0 1]\n    [1 0 0]\n    [0 1 0]\n>\n> x @ t;\n(2 0 0 0 1 0 0 0 0)\n> \n> phi := maps[1];\n> x := <A.1 @ phi, A.2 @ phi, (A.2^2) @ phi>;\n> x;\n<(1 0 0 0 0 0 0 0 0), (0 1 0 0 0 1 1 0 0), (0 0 1 1 0 0 0 1 0)>\n> x @ t;\n(2 0 0 0 1 0 0 0 0)\n\\end{code}\n\nBecause \\texttt{@} takes \\texttt{Tup} as input, $\\bra{t}$ can evaluate mixed\ntuples as well: where some entries are contained in $\\mathbb{M}_3(\\mathbb{F}_3)$\nand other entries are contained in $\\mathbb{F}_3^9$. \n\\begin{code}\n> x := <A.1, A.2 @ phi, Eltseq(A.2^2)>;\n> x;\n<\n    [1 0 0]\n    [0 0 0]\n    [0 0 0],\n\n    (0 1 0 0 0 1 1 0 0),\n\n    [ 0, 0, 1, 1, 0, 0, 0, 1, 0 ]\n>\n> <Type(i) : i in x>;\n<AlgMatElt, ModTupFldElt, SeqEnum>\n> x @ t;\n(2 0 0 0 1 0 0 0 0)\n\\end{code}\n\\end{example}\n\n\\index{$*$!as multilinear map}\n\\begin{intrinsics}\nt * f : TenSpcElt, Map -> TenSpcElt\nt * s : TenSpcElt, TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the tensor $f\\bra{t}$ which is the composition of $\\bra{t}$ with the\ngiven map $f$. If a tensor $\\bra{s}$ is used instead of a \\texttt{Map},\n$\\bra{s}$ must have valence $\\leq 1$. \n\n\\index{eq!tensor}\n\\begin{intrinsics}\nt eq s : TenSpcElt, TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides if the tensors $\\bra{t}$ and $\\bra{s}$ are the same. Two tensors are\nequivalent if, and only if, they have the same tensor category, base ring,\nframe, and structure constants. \n\n\\begin{example}[TensorComp]\n\nWe start with the same tensor as the previous example: the tensor given by the\nJacobi identity on the algebra $A=\\mathbb{M}_3(\\mathbb{F}_3)$. \n\\begin{code}\n> A := MatrixAlgebra(GF(3), 3);\n> JacobiID := func< x | x[1]*x[2]*x[3]+x[2]*x[3]*x[1]+x[3]*x[1]*x[2] >;\n> Cat := TensorCategory([1 : i in [0..3]], {{0..3}});\n> t, maps := Tensor([A : i in [0..3]], JacobiID, Cat);\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 9 over GF(3)\nU2 : Full Vector space of degree 9 over GF(3)\nU1 : Full Vector space of degree 9 over GF(3)\nU0 : Full Vector space of degree 9 over GF(3)\n> TensorCategory(t);\nTensor category of valence 4 (->,->,->,->) ({ 0 .. 3 })\n\\end{code}\n\nThe maps in \\texttt{Maps} are vector space isomorphisms and map $A$ to $V$. \nSuppose $\\phi: A\\rightarrow V$ is a vector space isomorphism. If we compose\n$\\bra{t}$ with $\\phi^{-1}$, the returned tensor is \\emph{still} over vector\nspaces. The codomain is \\emph{not} $A$; this is because all tensors are over\nvector spaces. In fact, the returned tensor is exactly the same as $\\bra{t}$.\n\\begin{code}\n> phi := maps[1];\n> t * (phi^-1);\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 9 over GF(3)\nU2 : Full Vector space of degree 9 over GF(3)\nU1 : Full Vector space of degree 9 over GF(3)\nU0 : Full Vector space of degree 9 over GF(3)\n> t * (phi^-1) eq t;\ntrue\n\\end{code}\n\nLet $\\mathcal{E}\\subset A$ be an orthogonal frame---a set of primitive,\northogonal, idempotents. We will compose $\\bra{t}$ with the linear\ntransformation \n\\[ a \\mapsto \\sum_{e\\in\\mathcal{E}} eae.\\]\nBecause the codomain of $\\bra{t}$ is a vector space, we will pre-compose this\nmap by $\\phi^{-1}$. \n\\begin{code}\n> E := [A.1, A.2^-1*A.1*A.2, A.2^-2*A.1*A.2^2];\n> E;\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> f := map< A -> A | x :-> &+[ E[i]*x*E[i] : i in [1..3] ] >;\n> f;\nMapping from: AlgMat: A to AlgMat: A given by a rule [no inverse]\n> s := t*(phi^-1*f);\n> s;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 9 over GF(3)\nU2 : Full Vector space of degree 9 over GF(3)\nU1 : Full Vector space of degree 9 over GF(3)\nU0 : Full Vector space of degree 9 over GF(3)\n> s eq t;\nfalse\n\\end{code}\n\nWe can also wrap $f$ as a 2-tensor and compose it with $\\bra{t}$.\n\\begin{code}\n> g := Tensor([A, A], func< x | x[1]@f >);\n> g;\nTensor of valence 2, U1 >-> U0\nU1 : Full Vector space of degree 9 over GF(3)\nU0 : Full Vector space of degree 9 over GF(3)\n> t * g eq s;\ntrue\n\\end{code}\n\\end{example}\n\n\n\n\n\\subsection{Operations with Bilinear maps}\nTensors of valence $3$, also known as bilinear tensors, or as bilinear maps,\nare commonly described as distributive products. For instance as the product of\nan algebra, the product of a ring on a module, or an inner product.  We support\nthese interpretations in two ways: by permitting an infix $x*t*y$ notation for a\n3-tensor $t$, and a product $x*y$ notation for the evaluation of bilinear\ntensors.  For the latter, we do this by creating special types\n\\texttt{BmpU[Elt]}, \\texttt{BmpV[Elt]}, and \\texttt{BmpW[Elt]} for the frame of\na bilinear tensor. For bilinear maps, we fix an interpretation $\\bra{\\cdot} : T \n\\rightarrow W\\oslash V\\oslash U$. \n\n\\index{$*$!bilinear tensor (infix)}\n\\begin{intrinsics}\nx * t : Any, TenSpcElt -> Any\nt * y : Any, TenSpcElt -> Any\n\\end{intrinsics}\n\nGiven a bilinear tensor $t$ framed by $[U, V, W]$, $x*t$ returns the action on\nthe right as a linear map $L : V\\rightarrow W$ given by $vL = x* v$ if $x$ is an\nelement of $U$. If $x$ is a subspace of $U$, then this returns a subspace of the\ntensor space $T$ with frame $V\\rightarrowtail W$. For the left action use $t*y$\ninstead. If $t$ is valence 1, then the image of either $x$ or $y$ is returned.\nTherefore, the possible outputs are a tensor space \\texttt{TenSpc}, a tensor\n\\texttt{TenSpcElt}, or a vector \\texttt{ModTupFld}. \n\nRelated to this intrinsic is the following: using tensor spaces with the infix notation.\n\n\\index{$*$!bilinear tensor (infix)}\n\\begin{intrinsics}\nx * T : Any, TenSpc -> Any\nT * y : Any, TenSpc -> Any\n\\end{intrinsics}\n\nGiven a subspace of bilinear tensors, return the subspace generated by all\n$x*t$, for $t\\in T$. This is either a tensor space or a vector space. \n\n\\begin{example}[BimapInfix]\n\nWe demonstrate the infix notation by constructing the tensor in\n$A=\\mathbb{M}_2(\\mathbb{Q})$ given by multiplication.\n\\begin{code}\n> A := MatrixAlgebra(Rationals(), 2);\n> t := Tensor(A);\n> t;\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\\end{code}\n\nLike tensor evaluation, the infix notation will accept elements of a vector\nspace (or objects that \\textsf{Magma} can easily coerce into a vector space) or elements\nfrom the original algebraic object. For $M=\\left(\\begin{smallmatrix} 0 & 1 \\\\ 0\n& 0 \\end{smallmatrix}\\right)$, we will use the infix notation to construct the\n2-tensor $* : A\\rightarrowtail A$, where $X\\mapsto MX$. \n\\begin{code}\n> M := A![0, 1, 0, 0];\n> M;\n[0 1]\n[0 0]\n> s := M*t;\n> s;\nTensor of valence 2, U1 >-> U0\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 4 over Rational Field\n> AsMatrices(s, 1, 0);\n[\n    [0 0 0 0]\n    [0 0 0 0]\n    [1 0 0 0]\n    [0 1 0 0]\n]\n\\end{code}\n\nFrom the structure constants above, evaluating \\texttt{M*t} at \\texttt{V.3}\nshould output \\texttt{W.1}. Furthermore, the image of \\texttt{M*t} is\n2-dimensional in $W$.\n\\begin{code}\n> M*t*[0, 0, 1, 0];\n(1 0 0 0)\n> M*t*VectorSpace(Rationals(), 4);\nVector space of degree 4, dimension 2 over Rational Field\nGenerators:\n(1 0 0 0)\n(0 1 0 0)\nEchelonized basis:\n(1 0 0 0)\n(0 1 0 0)\n\\end{code}\n\nIf we switch the order and multiply $t$ by $U$ on the left first, we will get a\ntensor space $T$. Because that tensor space came from $t$, which originally came\nfrom algebraic objects, we can use the returned tensor space to evaluate $M$. An\narbitrary tensor space, however, would not evaluate $M$ unless it is an\nappropriate vector. \n\\begin{code}\n> T := VectorSpace(Rationals(), 4)*t;\n> T;\nTensor space of dimension 4 over Rational Field with valence 2\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 4 over Rational Field\n> T*M;\nVector space of degree 4, dimension 2 over Rational Field\nGenerators:\n(0 1 0 0)\n(0 0 0 1)\nEchelonized basis:\n(0 1 0 0)\n(0 0 0 1)\n\\end{code}\n\\end{example}\n\n\n\nThe next style of notation we support is the product notation, $x*y$. In order\nto use this style, the user needs to coerce both $x$ and $y$ into the\n\\texttt{LeftDomain} and \\texttt{RightDomain} respectively. \n\n\\index{$*$!bilinear tensor (product)}\n\\begin{intrinsics}\nx * y : BmpUElt, BmpVElt -> Any\nx * y : BmpU, BmpV -> Any\nx * y : BmpUElt, BmpV -> Any\nx * y : BmpU, BmpVElt -> Any\n\\end{intrinsics}\n\nIf $x$ and $y$ are associated to the bilinear map $t$, these operations return \n\\texttt{<x,y> @ t}.\n\n\\index{LeftDomain}\n\\begin{intrinsics}\nLeftDomain(t) : TenSpcElt -> BmpU\n\\end{intrinsics}\n\nReturns the left domain $U$ of $t$, framed by $W\\oslash V\\oslash U$, setup for\nuse with infix notation.\n\n\\index{RightDomain}\n\\begin{intrinsics}\nRightDomain(t) : TenSpcElt -> BmpV\n\\end{intrinsics}\n\nReturns the right domain $V$ of $t$ framed by $W\\oslash V\\oslash U$, setup for\nuse with infix notation.\n\n\\index{IsCoercible!bilinear}\\index{BANG!bilinear}\n\\begin{intrinsics}\nIsCoercible(U, x) : BmpU, Any -> BoolElt, BmpUElt\nIsCoercible(V, x) : BmpV, Any -> BoolElt, BmpVElt\nU ! x : BmpU, Any -> BmpUElt\nV ! x : BmpV, Any -> BmpVElt\n\\end{intrinsics}\n\nDecides if $x$ can be coerced into $U$ or $V$, and if it can, it returns the\ncoerced element.\n\n\\begin{example}[BimapProduct]\n\nWe demonstrate the product notation for tensors of valence 3 using a tensor\nderived from a $p$-group. Suppose $G$ is a $p$-group and $[,] : U\\times\nV\\rightarrowtail W$ is the tensor given by commutation where $U=V=G/\\eta_2$ and\n$W=\\eta_2/\\eta_3$, where $\\eta_i$ denotes the $i$th term of the exponent-$p$\ncentral series of $G$.\n\\begin{code}\n> G := SmallGroup(512, 10^6);\n> t := pCentralTensor(G);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over GF(2)\nU1 : Full Vector space of degree 5 over GF(2)\nU0 : Full Vector space of degree 4 over GF(2)\n> U := LeftDomain(t);\n> V := RightDomain(t);\n> U;\nBimap space U: Full Vector space of degree 5 over GF(2)\n> V;\nBimap space V: Full Vector space of degree 5 over GF(2)\n\\end{code}\n\nLike with the other styles of notation (infix and tuple), users can evaluate\nelements from the original algebraic object, vectors from the vector spaces, and\neven sequences that \\textsf{Magma} can easily coerce into vector spaces. To use the\nproduct notation, coerce elements into the \\texttt{LeftDomain} and\n\\texttt{RightDomain}.\n\n\\begin{code}\n> x := U!(G.1*G.2*G.4);\n> y := V![1,0,0,0,0];\n> x;\nBimap element of U: (1 1 0 1 0)\n> y;\nBimap element of V: (1 0 0 0 0)\n> x*y;\n(1 0 0 1)\n\\end{code}\n\nWe can take this further and evaluate subspaces of $U$ or $V$.\n\\begin{code}\n> H := sub< G | G.2,G.4 >;\n> U!H * V!G.1;\nVector space of degree 4, dimension 2 over GF(2)\nGenerators:\n(0 0 0 1)\n(1 0 0 0)\nEchelonized basis:\n(1 0 0 0)\n(0 0 0 1)\n> U!H * V;\nVector space of degree 4, dimension 3 over GF(2)\nGenerators:\n(1 0 0 0)\n(0 0 1 0)\n(0 0 0 1)\n(1 0 0 0)\n(1 0 0 0)\nEchelonized basis:\n(1 0 0 0)\n(0 0 1 0)\n(0 0 0 1)\n\\end{code}\n\\end{example}\n\n\n\\index{Parent!bilinear}\n\\begin{intrinsics}\nParent(x) : BmpUElt -> BmpU\nParent(x) : BmpVElt -> BmpV\n\\end{intrinsics}\n\nReturns the parent space of the bilinear map element.\n\n\\index{Parent!bilinear}\n\\begin{intrinsics}\nParent(X) : BmpU -> TenSpcElt\nParent(X) : BmpV -> TenSpcElt\n\\end{intrinsics}\n\nReturns the original bilinear map where these spaces came from.\n\n\\index{eq!bilinear}\n\\begin{intrinsics}\nu1 eq u2 : BmpUElt, BmpUElt -> BoolElt\nv1 eq v2 : BmpUElt, BmpUElt -> BoolElt\nU1 eq U2 : BmpU, BmpU -> BoolElt\nV1 eq V2 : BmpV, BmpV -> BoolElt\n\\end{intrinsics}\n\nDecides if the elements or spaces are equal.\n\n\\begin{example}[BimapProduct2]\n\nWe will construct the same tensor as the previous example.\n\\begin{code}\n> G := SmallGroup(512, 10^6);\n> t := pCentralTensor(G);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over GF(2)\nU1 : Full Vector space of degree 5 over GF(2)\nU0 : Full Vector space of degree 4 over GF(2)\n> U := LeftDomain(t);\n> V := RightDomain(t);\n> U;\nBimap space U: Full Vector space of degree 5 over GF(2)\n> V;\nBimap space V: Full Vector space of degree 5 over GF(2)\n\\end{code}\n\nThe product notation has some basic functions for comparing objects and retrieving information.\n\\begin{code}\n> V!G.1 eq V![1,0,0,0,0];\ntrue\n> Parent(U);\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over GF(2)\nU1 : Full Vector space of degree 5 over GF(2)\nU0 : Full Vector space of degree 4 over GF(2)\n> Parent(U) eq t;\ntrue\n\\end{code}\n\\end{example}\n\n\n\\subsection{Manipulating tensor data} \nThe data from a tensor is accessible in multiple ways. For tensors given by\nstructure constants this can be described as the multidimensional analog of\nchoosing a row or column of a matrix. Other operations are generalization of the\ntranspose of a matrix. We do these operations with some care towards efficiency,\ne.g.\\! it may not physically move the values in a structure constant sequence\nbut instead permute the lookup of the values.\n\n\n\\index{Slice}\\index{InducedTensor}\n\\begin{intrinsics}\nSlice(t, grid) : TenSpcElt, [SetEnum] -> SeqEnum\nInducedTensor(t, grid) : TenSpcElt, [SetEnum] -> TenSpcElt\n\\end{intrinsics}\n\nReturns the slice of the structure constants running through the given grid. For\na tensor $t$ framed by free modules $[U_{\\vav},\\dots,U_0]$ with $d_i=\\dim U_i$,\na \\texttt{grid} is a sequence $[G_{\\vav},\\dots,G_0]$ of subsets $G_i\\subseteq\n\\{1,\\dots, d_i\\}\\cup \\{-d_i,\\dots, -1\\}$. If an entry $g\\in G_i$ is negative, it\nwill be taken to mean $d_i+g+1$, so $-1$ would be equivalent to $d_i$. The slice\nis the list of entries in the structure constants of the tensor indexed by\n$G_{\\vav}\\times \\cdots \\times G_0$. \\texttt{Slice} returns the structure\nconstants whereas \\texttt{InducedTensor} produces a tensor with these structure\nconstants.\n\n\\begin{example}[TensorSlicing]\n\nWe will construct a tensor $*: \\mathbb{Q}^4\\times \\mathbb{Q}^3\\rightarrowtail\n\\mathbb{Q}^2$ with a structure constants sequence equal to $[1,\\dots,24]$. If\nevery $G_i=\\{1,\\dots, d_i\\}$, then the result is the same as \\texttt{Eltseq}.\n\\begin{code}\n> U := VectorSpace(Rationals(),4);\n> V := VectorSpace(Rationals(),3);\n> W := VectorSpace(Rationals(),2);\n> T := TensorSpace([U, V, W]);\n> t := T![1..24];\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> Slice(t, [{1..4},{1..3},{1..2}]) eq Eltseq(t);\ntrue\n\\end{code}\n\nNow we will slice with the following grid $[\\{1,\\dots,4\\}, \\{2\\}, \\{1\\}]$. \nCompare this with the product $U*v_2$.\n\\begin{code}\n> [ U.i*t*V.2 : i in [1..4]];\n[\n    (3 4),\n    ( 9 10),\n    (15 16),\n    (21 22)\n]\n> Slice(t, [{1..4},{2},{1}]); \n[ 3, 9, 15, 21 ]\n\\end{code}\n\nIf, instead, we slice $W$ at its last basis vector, we get the following.\n\\begin{code}\n> Slice(t, [{1..4},{2},{-1}]);\n[ 4, 10, 16, 22 ]\n\\end{code}\n\nNotice that if we use $-1$ and $2$ in the last set of the grid we get the same\noutput we got above.\n\\begin{code}\n> Slice(t, [{1..4},{2},{-1,2}]);\n[ 4, 10, 16, 22 ]\n\\end{code}\n\nNow we will compare \\texttt{Slice} and \\texttt{InducedTensor}. \n\\texttt{InducedTensor} is basically a \\texttt{Tensor} wrapping the \\texttt{Slice} function.\n\\begin{code}\n> s := InducedTensor(t, [{1..4}, {2}, {1,2}]);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 1 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> s2 := Tensor([4, 1, 2], Slice(t, [{1..4}, {2}, {1,2}]));\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 1 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> \n> s eq s2;\ntrue\n> Eltseq(s);\n[ 3, 4, 9, 10, 15, 16, 21, 22 ]\n\\end{code}\n\\end{example}\n\n\\index{SliceAsMatrices}\n\\begin{intrinsics}\nSliceAsMatrices(t, grid, a, b) : TenSpcElt, [SetEnum], RngIntElt, RngIntElt -> SeqEnum\n\\end{intrinsics}\n\nReturns a sequence of matrices whose output is equivalent to composing\n\\texttt{InducedTensor} and \\texttt{AsMatrices}. This intrinsic will be slightly\nfaster than actually composing those two functions together as a tensor is not\nconstructed with \\texttt{SliceAsMatrices}.\n\n\\begin{example}[SliceAsMatrices]\n\nWe will create the same tensor as the previous example.\n\\begin{code}\n> t := Tensor(Rationals(), [4,3,2], [1..24]);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> AsMatrices(t, 1, 0);\n[\n    [1 2]\n    [3 4]\n    [5 6],\n\n    [ 7  8]\n    [ 9 10]\n    [11 12],\n\n    [13 14]\n    [15 16]\n    [17 18],\n\n    [19 20]\n    [21 22]\n    [23 24]\n]\n\\end{code}\n\nNow we will slice up this sequence of matrices. We will remove the second row\nand the second and third matrix from the sequence above.\n\\begin{code}\n> SliceAsMatrices(t, [{1,-1}, {1,-1}, {1,2}], 1, 0);\n[\n    [1 2]\n    [5 6],\n\n    [19 20]\n    [23 24]\n]\n\\end{code}\n\\end{example}\n\n\\index{Foliation}\n\\begin{intrinsics}\nFoliation(t, a) : TenSpcElt, RngIntElt -> Mtrx\n\\end{intrinsics}\n\nFor a tensor $t$ with frame $U_{\\vav}\\times\\cdots\\times U_1\\rightarrowtail U_0$,\nreturn the matrix representing the linear map \n$U_a\\rightarrow \\hom(\\bigotimes_{b\\ne a}U_b,U_0)$ using the bases of each $U_b$.\nIf $a=0$, then the returned matrix is given by the representation \n$U_0^*\\rightarrow \\hom(\\bigotimes U_b,K)$.\n\n\\begin{example}[ExfoliateFoliation]\n\nWe will, again, construct the same tensor, \n$*:\\mathbb{Q}^4\\times\\mathbb{Q}^3\\rightarrowtail \\mathbb{Q}^2$, \nfrom the previous two examples whose structure constants sequence is $[1,\\dots,24]$.\n\\begin{code}\n> K := Rationals();\n> Forms := [Matrix(K, 3, 2, [6*i+1..6*(i+1)]) : i in [0..3]];\n> t := Tensor(Forms, 1, 0);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n\\end{code}\n\nWe will use \\texttt{Foliation} to compute the 2-radical of $t$. \n(This is essentially what \\texttt{Radical} does in \\textsf{Magma}.)\nThat is, we will compute the subspace $U_{\\hat{2}}^\\perp\\leq \\mathbb{Q}^4$ \nsuch that $U_{\\hat{2}}^\\perp*\\mathbb{Q}^3=0$. \nThis computation can be regarded as a nullspace computation.\n\\begin{code}\n> F2 := Foliation(t, 2);\n> F2;\n[ 1  2  3  4  5  6]\n[ 7  8  9 10 11 12]\n[13 14 15 16 17 18]\n[19 20 21 22 23 24]\n> R := Nullspace(F2);\n> R;\nVector space of degree 4, dimension 2 over Rational Field\nEchelonized basis:\n( 1  0 -3  2)\n( 0  1 -2  1)\n\\end{code}\n\nWe claim this is the 2-radical of $t$. Our claim is verified if \\texttt{R*t} is\na 0-dimensional subspace of the tensor space $T$ with frame\n$\\mathbb{Q}^3\\rightarrowtail\\mathbb{Q}^2$. In other words, \\texttt{R*t} is the\ntrivial 2-tensor.\n\\begin{code}\n> R*t;\nTensor space of dimension 0 over Rational Field with valence 2\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> Dimension(R*t);\n0\n\\end{code}\n\\end{example}\n\n\\index{AsTensorSpace}\n\\begin{intrinsics}\nAsTensorSpace(t, a) : TenSpcElt, RngIntElt -> TenSpc, Mtrx\n\\end{intrinsics}\n\nReturns the associated tensor space of $t$ at $a>0$ along with a matrix given by\nthe foliation of $t$ at $a$. \nThe returned tensor space is framed by \n$U_{\\vav}\\times \\cdots \\times U_{a+1}\\times U_{a-1}\\times \\cdots \\times U_1\\rightarrowtail U_0$\nand is generated by the tensors $t_u$ for each $u$ in the basis of $U_a$.\nFor $a=0$, use \\texttt{AsCotensorSpace}.\n\n\\index{AsCotensorSpace}\n\\begin{intrinsics}\nAsCotensorSpace(t) : TenSpcElt -> TenSpc, Mtrx\n\\end{intrinsics}\n\nReturns the associated cotensor space of $t$ along with a matrix given by the\nfoliation of $t$ at $0$. The returned cotensor space is framed by\n$U_{\\vav}\\times \\cdots \\times U_1\\rightarrowtail K$ and is generated by the\ntensors $t_f$ for each $f$ in the basis of $U_0^*$. In the case that $t$ is a\nbilinear map, this is equivalent to the cotensor space generated by the\n\\texttt{SystemOfForms}.\n\n\\begin{example}[TensorsToSpaces]\n\nWe begin by creating a 4-tensor and constructing the associated tensor space at\nthe third coordinate. \\texttt{AsCotensorSpace} works similarly but when $a=0$. \n\\begin{code}\n> t := Tensor(Rationals(), [5,4,3,2], [1..120]);\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 5 over Rational Field\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> T := AsTensorSpace(t, 3);\n> T;\nTensor space of dimension 2 over Rational Field with valence 3\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n\\end{code}\n\nThe dimension of $T$ cannot be larger than 5 because that is the dimension of\n$U_3$. However, $T$ is 2-dimensional. Slicing $t$ as a sequence of matrices will\nilluminate why $T$ is 2-dimensional.\n\\begin{code}\n> F := [SliceAsMatrices(t, [{k},{1..4},{1..3},{1,2}], 2, 1) : \\\n>     k in [1..5]];\n\\end{code}\n\nHere, $F$ is a sequence of a system of forms for $t$, one for each basis vector\nin $U_3$. If $T$ were 5-dimensional, the systems of forms in $F$ would be\nlinearly independent. However, it is not, and evidently, three of the five\nsystems of forms are linear combinations two systems of forms. We will determine\nthe linear combinations. The first two systems of forms are independent.\n\\begin{code}\n> F[1];\n[\n    [ 1  3  5]\n    [ 7  9 11]\n    [13 15 17]\n    [19 21 23],\n\n    [ 2  4  6]\n    [ 8 10 12]\n    [14 16 18]\n    [20 22 24]\n]\n> F[2];\n[\n    [25 27 29]\n    [31 33 35]\n    [37 39 41]\n    [43 45 47],\n\n    [26 28 30]\n    [32 34 36]\n    [38 40 42]\n    [44 46 48]\n]\n\\end{code}\n\nWe see that \\texttt{F[3]} is \\texttt{2*F[2]-F[1]}, and we fill in the rest of the linear combinations.\n\\begin{code}\n> F[3];\n[\n    [49 51 53]\n    [55 57 59]\n    [61 63 65]\n    [67 69 71],\n\n    [50 52 54]\n    [56 58 60]\n    [62 64 66]\n    [68 70 72]\n]\n> Tensor(F[3], 2, 1) eq 2*Tensor(F[2], 2, 1) - Tensor(F[1], 2, 1);\ntrue\n> Tensor(F[4], 2, 1) eq 3*Tensor(F[2], 2, 1) - 2*Tensor(F[1], 2, 1);\ntrue\n> Tensor(F[5], 2, 1) eq 4*Tensor(F[2], 2, 1) - 3*Tensor(F[1], 2, 1);\ntrue\n\\end{code}\n\nSo, indeed, $T$ is the tensor space generated by the tensors in \\texttt{F}. \nNote that the dimension of the 3-radical of $t$ is 3.\n\\begin{code}\n> SystemOfForms(T.1) eq F[1];\ntrue\n> SystemOfForms(T.2) eq F[2];\ntrue\n> Radical(t, 3);\nVector space of degree 5, dimension 3 over Rational Field\nEchelonized basis:\n( 1  0  0 -4  3)\n( 0  1  0 -3  2)\n( 0  0  1 -2  1)\nMapping from: Full Vector space of degree 5 over Rational Field to Full \nVector space of degree 5 over Rational Field given by a rule\n\\end{code}\n\\end{example}\n\n\\index{AsTensor}\n\\begin{intrinsics}\nAsTensor(T) : TenSpc -> TenSpcElt\n\\end{intrinsics}\n\nReturns a tensor corresponding to the given tensor space $T$. If the given\ntensor space is contravariant, then the returned tensor has the frame\n$U_{\\vav}\\times \\cdots \\times U_1\\rightarrowtail T$, where $T$ is thought of as\na free $K$-module. If the given tensor space is covariant, then the returned\ntensor has the frame $T\\times U_{\\vav}\\times \\cdots \\times U_1\\rightarrowtail\nU_0$. Note that \\texttt{AsTensor} is ``inverse'' to \\texttt{AsCotensorSpace} and\n\\texttt{AsTensorSpace} when $a=\\vav$.\n\n\\begin{example}[SpacesToTensors]\n\nWe will construct the same tensor as the previous example and turn it into a tensor space at the third coordinate.\n\\begin{code}\n> t := Tensor(Rationals(), [5,4,3,2], [1..120]);\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 5 over Rational Field\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> T := AsTensorSpace(t, 3);\n> T;\nTensor space of dimension 2 over Rational Field with valence 3\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n\\end{code}\n\nNow we are going to ``recover'' $t$ by creating a tensor from $T$.\nHowever, it is not equal to $t$ because the 3-radical of the new tensor is trivial.\n\\begin{code}\n> s := AsTensor(T);\n> s;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 2 over Rational Field\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> Radical(s, 3);\nVector space of degree 2, dimension 0 over Rational Field\n\\end{code}\n\nWe can even see the same sequences of matrices in $s$.\n\\begin{code}\n> AsMatrices(s, 2, 1);\n[\n    [ 1  3  5]\n    [ 7  9 11]\n    [13 15 17]\n    [19 21 23],\n\n    [ 2  4  6]\n    [ 8 10 12]\n    [14 16 18]\n    [20 22 24],\n\n    [25 27 29]\n    [31 33 35]\n    [37 39 41]\n    [43 45 47],\n\n    [26 28 30]\n    [32 34 36]\n    [38 40 42]\n    [44 46 48]\n]\n\\end{code}\n\\end{example}\n\n\n\n\n\n\\section{Invariants of tensors}\n\nIn this subsection, we detail functions to construct invariants of tensors. To\naccess the projections or the objects acting on a specific factor $U_i$, the\nfollowing function(s) should be used.\n\n\\index{Induce}\n\\begin{intrinsics}\nInduce(X, a) : AlgMat, RngIntElt -> Map, AlgMat\nInduce(X, a) : AlgMatLie, RngIntElt -> Map, AlgMatLie\nInduce(X, a) : GrpMat, RngIntElt -> Map, GrpMat\n\\end{intrinsics}\n\nReturns the projection from the given object to the induced sub-object on the\n$a$th coordinate and the induced sub-object of the associated tensor.\n\n\\begin{example}[Inducing]\n\nTo demonstrate how to \\texttt{Induce}, we construct the 2-dimensional symplectic\nform on $K =$ GF$(3)$. \n\\begin{code}\n> t := Tensor(GF(3), [2, 2, 1], [0, 1, 2, 0]);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 2 over GF(3)\nU1 : Full Vector space of degree 2 over GF(3)\nU0 : Full Vector space of degree 1 over GF(3)\n> IsAlternating(t);\ntrue\n\\end{code}\n\nThis tensor has a nontrivial derivation algebra, isomorphic to $K^2\\rtimes\n\\mathfrak{sl}_2(3)$. However, $\\Der(t)$ is represented in\n$\\End(U_2)\\times\\End(U_1)\\times \\End(U_0)$. We will induce the action on the\n$1$st coordinate.\n\\begin{code}\n> D := DerivationAlgebra(t);\n> D.1;\n[2 2 0 0 0]\n[1 0 0 0 0]\n[0 0 0 2 0]\n[0 0 1 1 0]\n[0 0 0 0 0]\n> D.2;\n[2 0 0 0 0]\n[0 1 0 0 0]\n[0 0 0 0 0]\n[0 0 0 2 0]\n[0 0 0 0 1]\n> pi, D1 := Induce(D, 1);\n> D1;\nMatrix Lie Algebra of degree 2 over Finite field of size 3\n> pi;\nMapping from: AlgMatLie: D to AlgMatLie: D1 given by a rule [no inverse]\n\\end{code}\n\nNow we can see that have the action of $D$ on $U_1$.\n\\begin{code}\n> D1.1;\n[0 2]\n[1 1]\n> D1.2;\n[0 0]\n[0 2]\n\\end{code}\n\\end{example}\n\nWe include a partner intrinsic to \\texttt{Include} and that is the following procedure.\n\n\\index{DerivedFrom}\n\\begin{intrinsics}\nDerivedFrom(~X, t, C, RC) : Any, TenSpcElt, {RngIntElt}, {RngIntElt}\n    Fused : BoolElt : true\n\\end{intrinsics}\n\nIncludes the following tensor data in the matrix object $X$: the tensor $t$, the\nrelevant coordinates which are in the set $C\\subseteq \\{0,\\dots,\\vav\\}$, and the\ncoordinates $RC\\subseteq C$ for which the object is represented on. The reason\nfor the subset $C$ is so that we know the coordinates which can be induced on,\nsee \\texttt{Induce}. Currently, this only works for objects of type\n\\texttt{AlgMat}, \\texttt{AlgMatLie}, \\texttt{GrpMat}, and \\texttt{ModMatFld}. It\nis assumed that $X$ is block diagonal, whose blocks starting from the top left\ngo in decreasing order in the coordinates---in the same way the coordinates of\nthe frame decrease from left to right for a tensor. \n\n% Maybe include an example at some point.\n\n\\subsection{Standard invariants}\n\nWe integrate the invariant theory associated to bilinear and multilinear maps\ninto the realm of tensors. \n\n\\index{Radical}\n\\begin{intrinsics}\nRadical(t, a) : TenSpcElt, RngIntElt -> ModTupRng\n\\end{intrinsics}\n\nReturns the $a$-radical of $t$ as a subspace of $U_a$. \nThis is the subspace \n\\[ U_{\\comp{a}}^\\perp = \\left\\{ u_a \\in U_a : \\forall \\left| u_{\\comp{a}}\\right\\rangle,\\; \\left\\langle t \\middle| u\\right\\rangle =0\\right\\}. \\] \n\n\\index{Radical}\n\\begin{intrinsics}\nRadical(t) : TenSpcElt -> Tup\n\\end{intrinsics}\n\nReturns the tuple of all the $a$-radicals for each $a\\in \\{1,\\dots,\\vav\\}$.\n\n\\index{Coradical}\n\\begin{intrinsics}\nCoradical(t) : TenSpcElt -> ModTupRng, Map\n\\end{intrinsics}\n\nReturns the coradical of $t$ and a surjection from the codomain to the coradical.\nThis is the quotient $U_0 / \\langle t | U_{\\vav}, \\dots, U_1\\rangle$.\n\n\\begin{example}[Radicals]\n\nWe will construct the tensor for multiplication in\n$\\mathfrak{gl}_3(\\mathbb{Q})$, or equivalently, the commutator tensor of\n$\\mathbb{M}_3(\\mathbb{Q})$. Because $\\mathfrak{gl}_3(\\mathbb{Q})$ contains the\ncenter of $\\mathbb{M}_3(\\mathbb{Q})$, there will be a 2- and 1-radical.\n\\begin{code}\n> K := Rationals();\n> A := MatrixAlgebra(K, 3);\n> t, phi := CommutatorTensor(A);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 9 over Rational Field\nU1 : Full Vector space of degree 9 over Rational Field\nU0 : Full Vector space of degree 9 over Rational Field\n> \n> R2 := Radical(t, 2);\n> R2.1 @@ phi;\n[1 0 0]\n[0 1 0]\n[0 0 1]\n> Radical(t);\n<\n    Vector space of degree 9, dimension 1 over Rational Field\n    Echelonized basis:\n    (1 0 0 0 1 0 0 0 1),\n\n    Vector space of degree 9, dimension 1 over Rational Field\n    Echelonized basis:\n    (1 0 0 0 1 0 0 0 1)\n>\n\\end{code}\n\nSimilarly, the image of $t$ will be 8-dimensional in $\\mathbb{Q}^9$, so the coradical is $\\mathbb{Q}$.\n\\begin{code}\n> Image(t);\nVector space of degree 9, dimension 8 over Rational Field\nGenerators:\n( 1  0  0  0  0  0  0  0 -1)\n( 0  1  0  0  0  0  0  0  0)\n( 0  0  1  0  0  0  0  0  0)\n( 0  0  0  1  0  0  0  0  0)\n( 0  0  0  0  1  0  0  0 -1)\n( 0  0  0  0  0  1  0  0  0)\n( 0  0  0  0  0  0  1  0  0)\n( 0  0  0  0  0  0  0  1  0)\nEchelonized basis:\n( 1  0  0  0  0  0  0  0 -1)\n( 0  1  0  0  0  0  0  0  0)\n( 0  0  1  0  0  0  0  0  0)\n( 0  0  0  1  0  0  0  0  0)\n( 0  0  0  0  1  0  0  0 -1)\n( 0  0  0  0  0  1  0  0  0)\n( 0  0  0  0  0  0  1  0  0)\n( 0  0  0  0  0  0  0  1  0)\n> Coradical(t);\nFull Vector space of degree 1 over Rational Field\nMapping from: Full Vector space of degree 9 over Rational Field to Full\nVector space of degree 1 over Rational Field\n\\end{code}\n\\end{example}\n\n\nWe include some well-known polynomial invariants for bilinear maps.\n\\index{Discriminant}\n\\begin{intrinsics}\nDiscriminant(t) : TenSpcElt -> RngMPolElt\n\\end{intrinsics}\n\nReturns the discriminant of the bilinear map.\n\n\\begin{example}[DiscriminatingOctonions]\n\nWe will compute the discriminant of the tensor $\\cdot :\\mathbb{O}\\times\\mathbb{O}\\rightarrowtail\\mathbb{O}$.\nThe discriminant of this tensor is homogeneous of degree 8 with 330 terms.\n\\begin{code}\n> A := OctonionAlgebra(GF(7), -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 GF(7)\nU1 : Full Vector space of degree 8 over GF(7)\nU0 : Full Vector space of degree 8 over GF(7)\n> R<a,b,c,d,e,f,g,h> := PolynomialRing(GF(7), 8);\n> disc := R!Discriminant(t);\n> Degree(disc);\n8\n> IsHomogeneous(disc);\ntrue\n> #Terms(disc);\n330\n\\end{code}\n\nHowever, if we factor the discriminant, then we can see that $\\texttt{disc} = \\left(x_1^2 + \\cdots x_8^2\\right)^4$.\n\\begin{code}\n> Factorization(disc);\n[\n    <a^2 + b^2 + c^2 + d^2 + e^2 + f^2 + g^2 + h^2, 4>\n]\n\\end{code}\n\\end{example}\n\n\\index{Pfaffian}\n\\begin{intrinsics}\nPfaffian(t) : TenSpcElt -> RngMPolElt\n\\end{intrinsics}\n\nReturns the Pfaffian of the antisymmetric bilinear map.\n\n\\begin{example}[Genus2Pfaff]\n\nIn this demonstration, we pull from \\cite{BMW:genus2}. A $p$-group $G$ has genus\n2, if the image of the exponent-$p$ central tensor of $G$ is 2-dimensional over\nthe centroid. One of the algorithms in \\cite{BMW:genus2} to decide isomorphism\nof such groups depends on the Pfaffian of the tensor. \n\nFirst, we create two $3$-groups with genus 2. \nThe first group we create as a quotient of the Sylow 3-subgroup of $\\GL(3,\\GF(3^5))$. \n\\begin{code}\n> P := ClassicalSylow(GL(3, 3^5), 3);\n> P := PCPresentation(UnipotentMatrixGroup(P));\n> Z := Center(P);\n> N := sub< Z | [Random(Z) : i in [1..3]] >;\n> G := P/N;\n\\end{code}\n\nThe second group we create will be a quotient of the Sylow 3-subgroup of the  of $\\GL(3, \\GF(9))\\times\\GL(3, \\GF(27))$. \n\\begin{code}\n> A := ClassicalSylow(GL(3, 9), 3);\n> B := ClassicalSylow(GL(3, 27), 3);\n> A := PCPresentation(UnipotentMatrixGroup(A));\n> B := PCPresentation(UnipotentMatrixGroup(B));\n> Q, inc := DirectProduct(A, B);\n> ZA := Center(A);\n> ZB := Center(B);\n> gens := [(ZA.i@inc[1])*(ZB.i@inc[2])^-1 : i in [1..2]] \\\n>     cat [ZB.3@inc[2]];\n> M := sub< Q | gens >;\n> H := Q/M;\n\\end{code}\n\nNow we will construct the exponent-$p$ central tensors of $G$ and $H$. \nFrom the way we have created the groups, $G\\cong H$ if, and only if, their tensors are pseudo-isometric.\n\\begin{code}\n> t := pCentralTensor(G);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 10 over GF(3)\nU1 : Full Vector space of degree 10 over GF(3)\nU0 : Full Vector space of degree 2 over GF(3)\n> \n> s := pCentralTensor(H);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 10 over GF(3)\nU1 : Full Vector space of degree 10 over GF(3)\nU0 : Full Vector space of degree 2 over GF(3)\n\\end{code}\n\nAn implication of the main algorithm in \\cite{BMW:genus2} is that if the\nsplitting behavior of the Pfaffians are different, then the groups are not\nisomorphic. Therefore, because the Pfaffian of $G$ has a different splitting\nbehavior from the Pfaffian of $H$, we conclude that $G\\not\\cong H$. \n\\begin{code}\n> R<x,y> := PolynomialRing(GF(3), 2);\n> f := R!Pfaffian(t);\n> g := R!Pfaffian(s);\n> f;\nx^5 + x^3*y^2 + 2*x^2*y^3 + 2*x*y^4 + y^5\n> g;\nx^5 + 2*x^4*y + x^3*y^2 + 2*x^2*y^3 + x*y^4 + y^5\n> Factorization(f), Factorization(g);\n[\n    <x^5 + x^3*y^2 + 2*x^2*y^3 + 2*x*y^4 + y^5, 1>\n]\n[\n    <x^2 + x*y + 2*y^2, 1>,\n    <x^3 + x^2*y + x*y^2 + 2*y^3, 1>\n]\n\\end{code}\n\\end{example}\n\n\n\n\n\n\n\\section{Exporting tensors}\n\nIn the previous sections, we used groups, rings, and algebras to define tensors,\nbut tensors can be used define algebraic structures as well. In this section, we\ndescribe ways to build groups and algebras from tensors. Currently, all\nintrinsics in this section only support 3-tensors.\n\n\\index{HeisenbergAlgebra}\n\\begin{intrinsics}\nHeisenbergAlgebra(t) : TenSpcElt -> AlgGen\n\\end{intrinsics}\n\nReturns the Heisenberg algebra $A$ induced by the bilinear tensor $t: U\\times\nV\\rightarrowtail W$. The algebra $A$ depends on the tensor category of $t$. If\nthe tensor category forces equality between $U$, $V$, and $W$, then $A\\cong U$\nas vector spaces and is a nonassociative algebra (i.e.\\! not necessarily\nassociative). If the tensor category forces equality between $U$ and $V$, then\n$A\\cong U\\oplus W$ as vector spaces and is a nilpotent algebra where $C(A)\\geq\nW$ and $A^2\\leq W$. Otherwise, $A\\cong U\\oplus V\\oplus W$ as vector spaces, and\nusing $*$ for $t$, \n\\[ (u,v,w)\\cdot (u',v',w') = (0,0,u*v'). \\]\n\n\\begin{example}[CraftingAlgebras]\n\nWe will demonstrate some of the nuances of \\texttt{HeisenbergAlgebra} and how it\ninteracts with the tensor category of the given tensor. We will use the same\ntensor throughout but changing the categories. The frame of the tensor is\n$\\mathbb{Q}^3\\times\\mathbb{Q}^3\\rightarrowtail\\mathbb{Q}^3$.\n\\begin{code}\n> t := Tensor(Rationals(), [3, 3, 3], [i : i in [1..27]]);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 3 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 3 over Rational Field\n> SystemOfForms(t);\n[\n    [ 1  4  7]\n    [10 13 16]\n    [19 22 25],\n\n    [ 2  5  8]\n    [11 14 17]\n    [20 23 26],\n\n    [ 3  6  9]\n    [12 15 18]\n    [21 24 27]\n]\n> Radical(t);\n<\n    Vector space of degree 3, dimension 1 over Rational Field\n    Echelonized basis:\n    ( 1 -2  1),\n\n    Vector space of degree 3, dimension 1 over Rational Field\n    Echelonized basis:\n    ( 1 -2  1)\n>\n> Image(t);\nVector space of degree 3, dimension 2 over Rational Field\nGenerators:\n( 1  0 -1)\n( 0  1  2)\nEchelonized basis:\n( 1  0 -1)\n( 0  1  2)\n\\end{code}\n\nThe default tensor category of $t$ above is the homotopism category where none\nof the modules are fused together. Therefore, if we construct the Heisenberg\nalgebra of $t$, the resulting algebra will be 9-dimensional. Looking at the\nsystem of forms, the first 6 matrices will be zero, and the last 3 matrices will\ncontain the above system of forms as a $3\\times 3$ block, starting at the\n$(1,4)$ entry.\n\\begin{code}\n> A := HeisenbergAlgebra(t);\n> A;\nAlgebra of dimension 9 with base ring Rational Field\n> Center(A);\nAlgebra of dimension 5 with base ring Rational Field\n> SystemOfForms(Tensor(A))[7..9];\n[\n    [ 0  0  0  1  4  7  0  0  0]\n    [ 0  0  0 10 13 16  0  0  0]\n    [ 0  0  0 19 22 25  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0],\n\n    [ 0  0  0  2  5  8  0  0  0]\n    [ 0  0  0 11 14 17  0  0  0]\n    [ 0  0  0 20 23 26  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0],\n\n    [ 0  0  0  3  6  9  0  0  0]\n    [ 0  0  0 12 15 18  0  0  0]\n    [ 0  0  0 21 24 27  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0  0]\n]\n\\end{code}\n\nNow we will fuse $U$ and $V$ together with a new category. The resulting algebra\nwill then be 6-dimensional. We will also look at the system of forms of $A$ to\nsee the structure constants of $A$. \n\\begin{code}\n> NilCat := TensorCategory([1, 1, 1], {{2,1},{0}});\n> NilCat;\nTensor category of valence 3 (->,->,->) ({ 0 },{ 1, 2 })\n> ChangeTensorCategory(~t, NilCat);\n> A := HeisenbergAlgebra(t);\n> A;\nAlgebra of dimension 6 with base ring Rational Field\n> Center(A);\nAlgebra of dimension 4 with base ring Rational Field\n> A^2;\nAlgebra of dimension 2 with base ring Rational Field\n> SystemOfForms(Tensor(A))[4..6];\n[\n    [ 1  4  7  0  0  0]\n    [10 13 16  0  0  0]\n    [19 22 25  0  0  0]\n    [ 0  0  0  0  0  0]\n    [ 0  0  0  0  0  0]\n    [ 0  0  0  0  0  0],\n\n    [ 2  5  8  0  0  0]\n    [11 14 17  0  0  0]\n    [20 23 26  0  0  0]\n    [ 0  0  0  0  0  0]\n    [ 0  0  0  0  0  0]\n    [ 0  0  0  0  0  0],\n\n    [ 3  6  9  0  0  0]\n    [12 15 18  0  0  0]\n    [21 24 27  0  0  0]\n    [ 0  0  0  0  0  0]\n    [ 0  0  0  0  0  0]\n    [ 0  0  0  0  0  0]\n]\n\\end{code}\n\nFinally, we will put a tensor category on $t$ where $U$, $V$ and $W$ are all fused together. \nTHe Heisenberg algebra from this tensor is 3-dimensional, and the product is exactly the tensor $t$.\n\\begin{code}\n> AlgCat := TensorCategory([1, 1, 1], {{2,1,0}});\n> AlgCat;\nTensor category of valence 3 (->,->,->) ({ 0, 1, 2 })\n> ChangeTensorCategory(~t, AlgCat);\n> A := HeisenbergAlgebra(t);\n> A;\nAlgebra of dimension 3 with base ring Rational Field\n> SystemOfForms(Tensor(A));\n[\n    [ 1  4  7]\n    [10 13 16]\n    [19 22 25],\n\n    [ 2  5  8]\n    [11 14 17]\n    [20 23 26],\n\n    [ 3  6  9]\n    [12 15 18]\n    [21 24 27]\n]\n\\end{code}\n\\end{example}\n\n\\index{HeisenbergLieAlgebra}\n\\begin{intrinsics}\nHeisenbergLieAlgebra(t) : TenSpcElt -> AlgLie\n\\end{intrinsics}\n\nReturns the Heisenberg Lie algebra $L$ with Lie bracket given by the 3-tensor\n$t:U\\times V\\rightarrowtail W$. If the tensor category of $t$ forces equality\nonly between $U$ and $V$ and $t$ is alternating, then the Heisenberg Lie algebra\nwill have structure constants equal to $t$. In this case, $L\\cong U\\oplus W$ as\nvector spaces. Otherwise, $L\\cong U\\oplus V\\oplus W$ as vector spaces, and,\nusing $*$ in place for $t$, the product in $L$ is given by\n\\[ (u,v,w) * (u',v',w') = (0,0,uv'-u'v). \\]\n\n\\begin{example}[CraftingLieAlgberas]\n\nWe will construct an alternating tensor with frame $\\mathbb{Q}^3\\times\\mathbb{Q}^3\\rightarrowtail \\mathbb{Q}^2$. \n\\begin{code}\n> t := Tensor(Rationals(), [3, 3, 2], &cat[[1,-1,0] : i in [1..6]]);\n> t := AlternatingTensor(t);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 3 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> SystemOfForms(t);\n[\n    [ 0 -1 -2]\n    [ 1  0 -1]\n    [ 2  1  0],\n\n    [ 0  2  1]\n    [-2  0 -1]\n    [-1  1  0]\n]\n\\end{code}\n\nFirst, we will just construct the Heisenberg Lie algebra from $t$ as is. Because\nthe tensor category of $t$ does not fuse together $U$, $V$, and $W$, the Lie\nalgebra will be 8-dimensional.\n\\begin{code}\n> L := HeisenbergLieAlgebra(t);\n> L;\nLie Algebra of dimension 8 with base ring Rational Field\n> SystemOfForms(Tensor(L))[7..8];\n[\n    [ 0  0  0  0 -1 -2  0  0]\n    [ 0  0  0  1  0 -1  0  0]\n    [ 0  0  0  2  1  0  0  0]\n    [ 0 -1 -2  0  0  0  0  0]\n    [ 1  0 -1  0  0  0  0  0]\n    [ 2  1  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0],\n\n    [ 0  0  0  0  2  1  0  0]\n    [ 0  0  0 -2  0 -1  0  0]\n    [ 0  0  0 -1  1  0  0  0]\n    [ 0  2  1  0  0  0  0  0]\n    [-2  0 -1  0  0  0  0  0]\n    [-1  1  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0]\n    [ 0  0  0  0  0  0  0  0]\n]\n\\end{code}\n\nNow if we fuse $U$ and $V$ together, the resulting Lie algebra will be\n5-dimensional, and the Lie bracket will essentially be equal to $t$.\n\\begin{code}\n> NilCat := TensorCategory([1, 1, 1], {{2,1},{0}});\n> NilCat;\nTensor category of valence 3 (->,->,->) ({ 0 },{ 1, 2 })\n> ChangeTensorCategory(~t, NilCat);\n> L := HeisenbergLieAlgebra(t);\n> L;\nLie Algebra of dimension 5 with base ring Rational Field\n> SystemOfForms(Tensor(L))[4..5];\n[\n    [ 0 -1 -2  0  0]\n    [ 1  0 -1  0  0]\n    [ 2  1  0  0  0]\n    [ 0  0  0  0  0]\n    [ 0  0  0  0  0],\n\n    [ 0  2  1  0  0]\n    [-2  0 -1  0  0]\n    [-1  1  0  0  0]\n    [ 0  0  0  0  0]\n    [ 0  0  0  0  0]\n]\n\\end{code}\n\\end{example}\n\n\\index{HeisenbergGroup}\\index{HeisenbergGroupPC}\n\\begin{intrinsics}\nHeisenbergGroup(t) : TenSpcElt -> GrpMat\nHeisenbergGroupPC(t) : TenSpcElt -> GrpPC\n\\end{intrinsics}\n\nReturns the class 2, exponent $p$, Heisenberg $p$-group with commutator given by\nthe bilinear tensor $t: U \\times V \\rightarrowtail W$ over a finite field. If\n$t$ is alternating and the tensor category of $t$ forces equality between $U$\nand $V$, then the group returned is an extension of $V$ by $W$, so $|G| =\n|V|\\cdot |W|$. Otherwise, the group returned is an extension of $U\\oplus V$ by\n$W$, so $|G| = |U|\\cdot |V| \\cdot |W|$. If $t$ is not full, then $G$ is an\nextension of $U\\oplus V\\oplus W/\\im(t)$ (or $V\\oplus W/\\im(t)$) by $\\im(t)$. \n\n\\begin{example}[CraftingPGroups]\n\nHere we demonstrate how to export a group from a tensor. We will start with a\ntensor that is alternating and compare the different outputs based on the\ncategory of the tensor. \n\\begin{code}\n> t := KTensorSpace(GF(5), [5, 5, 4])!0;\n> for i in [1..4] do\nfor>   Assign(~t, [i, i+1, i], 1);   // 1s above diag\nfor>   Assign(~t, [i+1, i, i], -1);  // 4s below diag\nfor> end for;\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over GF(5)\nU1 : Full Vector space of degree 5 over GF(5)\nU0 : Full Vector space of degree 4 over GF(5)\n> IsAlternating(t);\ntrue\n\\end{code}\n\nIn this example, we will focus on the more straight-forward case, when $t$ is full. \nThe next example demonstrates a tensor that is not full.\n\\begin{code}\n> SystemOfForms(t);\n[\n    [0 1 0 0 0]\n    [4 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 0 1 0 0]\n    [0 4 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 0 1 0]\n    [0 0 4 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 0 1]\n    [0 0 0 4 0]\n]\n> IsFullyNondegenerate(t);\ntrue\n\\end{code}\n\nEven though $t$ is alternating, the category does not fuse together $U$ and $V$.\nTherefore, the Heisenberg group $H$ is an extension of $U\\oplus V$ by $W$, and\nhence, $|H|=5^{5+5+4}$.\n\\begin{code}\n> H := HeisenbergGroup(t);\n> LMGOrder(LMGCenter(H)) eq 5^4;\ntrue\n> s := pCentralTensor(H, 5, 1, 1);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 10 over GF(5)\nU1 : Full Vector space of degree 10 over GF(5)\nU0 : Full Vector space of degree 4 over GF(5)\n\\end{code}\n\nNow we will fuse the 2 and 1 coordinate, so that $|H|=5^{5+4}$.\n\\begin{code}\n> PgrpCat := TensorCategory([1, 1, 1], {{2,1},{0}});\n> PgrpCat;\nTensor category of valence 3 (->,->,->) ({ 0 },{ 1, 2 })\n> ChangeTensorCategory(~t, PgrpCat);\n> H := HeisenbergGroup(t);\n> LMGOrder(LMGCenter(H)) eq 5^4;\ntrue\n> s := pCentralTensor(H, 5, 1, 1);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over GF(5)\nU1 : Full Vector space of degree 5 over GF(5)\nU0 : Full Vector space of degree 4 over GF(5)\n\\end{code}\n\nNote that $t$ and $s$ are not the same tensor. However, they are\npseudo-isometric (isotopic in the category with $U_2=U_1$). This effect is\nexaggerated with \\texttt{HeisenbergGroupPC} because of how PC-generators are\norganized.\n\\begin{code}\n> SystemOfForms(s);\n[\n    [0 0 0 0 0]\n    [0 0 0 0 1]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 4 0 0 0],\n\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 4]\n    [0 0 0 0 0]\n    [0 0 1 0 0],\n\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 1 0]\n    [0 0 4 0 0]\n    [0 0 0 0 0],\n\n    [0 0 0 4 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [1 0 0 0 0]\n    [0 0 0 0 0]\n]\n\\end{code}\n\\end{example}\n\n\\begin{example}[PGroupsHalfFull]\n\nWe will start with an alternating tensor that is not full with the frame\n$\\mathbb{F}_3^4\\times\\mathbb{F}_3^4\\rightarrowtail \\mathbb{F}_3^3$.\n\\begin{code}\n> t := Tensor(GF(3), [4, 4, 3], &cat[[1,0,0,1] : i in [1..12]]);\n> t := AlternatingTensor(t);\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 3 over GF(3)\n> Radical(t);\n<\n    Vector space of degree 4, dimension 1 over GF(3)\n    Echelonized basis:\n    (1 2 1 2),\n\n    Vector space of degree 4, dimension 1 over GF(3)\n    Echelonized basis:\n    (1 2 1 2)\n>\n> Image(t);\nVector space of degree 3, dimension 2 over GF(3)\nGenerators:\n(1 0 2)\n(0 1 0)\nEchelonized basis:\n(1 0 2)\n(0 1 0)\n> SystemOfForms(t);\n[\n    [0 0 2 2]\n    [0 0 2 2]\n    [1 1 0 0]\n    [1 1 0 0],\n\n    [0 1 1 0]\n    [2 0 0 2]\n    [2 0 0 2]\n    [0 1 1 0],\n\n    [0 0 1 1]\n    [0 0 1 1]\n    [2 2 0 0]\n    [2 2 0 0]\n]\n\\end{code}\n\nBecause the tensor category of $t$ does not force equality between $U$ and $V$,\nthe group $H$ created from $t$ will have order $3^{11}$ and be 8-generated.\nFurthermore, the tensor has a 2-dimensional image, so the tensor from the\nexponent-$p$ central series of $H$ will have frame $\\mathbb{F}_3^{4+4+1}\\times\n\\mathbb{F}_3^{4+4+1}\\rightarrowtail\\mathbb{F}_3^2$. We display the system of\nforms of the exponent-$p$ central tensor of $H$ to show how different it looks\ncompared to the original. \n\\begin{code}\n> G := HeisenbergGroup(t);\n> LMGOrder(G) eq 3^11;\ntrue\n> s := pCentralTensor(G);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 9 over GF(3)\nU1 : Full Vector space of degree 9 over GF(3)\nU0 : Full Vector space of degree 2 over GF(3)\n> SystemOfForms(s);\n[\n    [0 0 0 0 0 0 1 0 0]\n    [0 0 0 0 0 0 0 2 2]\n    [0 0 0 0 0 0 1 0 0]\n    [0 0 0 0 0 0 2 1 1]\n    [0 0 0 0 0 0 0 0 0]\n    [0 0 0 0 0 0 0 0 0]\n    [2 0 2 1 0 0 0 0 0]\n    [0 1 0 2 0 0 0 0 0]\n    [0 1 0 2 0 0 0 0 0],\n\n    [0 0 0 0 0 0 0 0 1]\n    [0 0 0 0 0 0 0 0 1]\n    [0 0 0 0 0 0 2 2 0]\n    [0 0 0 0 0 0 2 2 0]\n    [0 0 0 0 0 0 0 0 0]\n    [0 0 0 0 0 0 0 0 0]\n    [0 0 1 1 0 0 0 0 0]\n    [0 0 1 1 0 0 0 0 0]\n    [2 2 0 0 0 0 0 0 0]\n]\n\\end{code}\n\\end{example}\n", "meta": {"hexsha": "e3f71e0e43a6d4696e67d6f05af62191b77f8b0f", "size": 106752, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tensors.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": "2022-01-21T19:32:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T07:42:57.000Z", "max_issues_repo_path": "doc/tensors.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/tensors.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.8888888889, "max_line_length": 144, "alphanum_fraction": 0.6681373651, "num_tokens": 39969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.65566193493539}}
{"text": "\\lstset{\n    language=Matlab,%\n    basicstyle=\\fontsize{9}{11},\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=left,%\n    numberstyle={\\tiny \\color{black}},% size of the numbers\n    numbersep=0pt, % this defines how far the numbers are from the text\n    linewidth=\\columnwidth,\n    emph=[1]{for,end,break},emphstyle=[1]\\color{blue}, %some words to emphasize\n}\n\n\\begin{appendices}\n    \\section{Matlab code}\n    \\subsection{Weights' Gradients}\n    \\label{sub:gradients}\n    \\begin{lstlisting}[language=Matlab] \n        function [g1, g2] = gd(example, tau, w1, w2)\n            %GD Compute the gradients of the error function for the given example\n            %with respect to w1 and w1 (weights of the 2 hidden units).\n        \n            tanh_w1 = tanh(example * w1);\n            tanh_w2 = tanh(example * w2);\n            sigma = tanh_w1 + tanh_w2;\n            g_comp = (sigma - tau) * example';\n            g1 = g_comp * (1 - (tanh_w1 ^ 2));\n            g2 = g_comp * (1 - (tanh_w2 ^ 2));\n        end\n    \\end{lstlisting}\n\\end{appendices}\n", "meta": {"hexsha": "c0e5e5c8bcfefcfc9b228059de6a81c877844783", "size": 1353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_3/report/07_appendix.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_3/report/07_appendix.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_3/report/07_appendix.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5675675676, "max_line_length": 100, "alphanum_fraction": 0.623059867, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6556619349353898}}
{"text": "\\chapter{Array}\n\\section{Two-pointer Algorithm}\n\\runinhead{Container With Most Water.} Given coordinate $(i, a_i)$, find two lines, which together with x-axis forms a container, such that the container contains the most water.\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.50]{Container-With-Most-Water.jpg}}\n\\caption{Container with Most Water}\n\\label{fig:Container-With-Most-Water}\n\\end{figure}\nCore clues:\n\\begin{enumerate}\n\\item \\textbf{Two pointers}: $start$, $back$ at two ends. Calculate the current area\n\\item \\textbf{Move one}: Move the shorter (lower height) pointer. \n\\end{enumerate}\n\n\\section{Circular Array}\nThis section describes common patterns for solving problems with circular arrays.\n\nNormally, we should solve the linear problem and circular problem very differently.\n\n\\subsection{Circular max sum}\nLinear problem can be solved linear with dp algorithm for maximum subarray sum - Section \\ref{dpSequence}. \n\nThe circular sum should use dp. \n\nProblem description: Given an integer array, find a continuous rotate subarray where the sum of numbers is the biggest. Return the index of the first number and the index of the last number. \n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item \\textbf{State definitions}: \n\nConstruct left max sum $L_i$ for max sum over the $[0..i]$ with subarray starting at 0 (\\textit{forward} starting from the left side). \n\nConstruct right max sum $R_i$ for max sum over the indexes $[i+1..n -1]$, with subarray ending at -1 (\\textit{backward} starting from the right side). \n\nNotice, for the two max sums, the index ends AT or BEFORE $i$.\n\n\\item \\textbf{Transition functions:}\n\\begin{align*}\nL_i = \\max\\Big(L_{i-1}, sum(A[:i])\\Big) \\\\ \nR_i = \\max\\Big(R_{i+1}, sum(A[i:])\\Big)\n\\end{align*}\n\n\\item \\textbf{Global result}: \n$$maxa = \\max(R_i+L_{i-1}, \\forall i)$$\n\\end{enumerate}\n\n\\subsection{Non-adjacent cell}\nMaximum sum of non-adjacent cells in an array $A$. (House robbery problem)\n\nTo solve circular non-adjacent array problem in linear way, we should consider 2 cases:\n\\begin{enumerate}\n\\item Not consider the $A[1]$\n\\item Not consider the $A[-1]$ \n\\end{enumerate}\nand solve them using linear maximum sum of non-adjacent cells separately  - Section \\ref{dpSequence}. \n\\subsection{Binary search}\nSearching for an element in a circular sorted array. Half of the array is sorted while the other half is not.\n\\begin{enumerate}\n\\item If $A[0] < A[mid]$, then all values in the first half of the array are sorted.\n\\item If $A[mid] < A[-1]$, then all values in the second half of the array are sorted.\n\\item Then \\textit{derive and decide} whether to got the \\textbf{sorted half} or the \\textbf{unsorted half}.\n\\end{enumerate}\n\\section{Voting Algorithm}\n\\subsection{Majority Number}\n\\subsubsection{$\\frac{1}{2}$ of the Size}\nGiven an array of integers, the majority number is the number that occurs more than half of the size of the array. \n\nAlgorithm: Majority Vote Algorithm. Maintain a counter to count how many times the majority number appear more than any other elements before index $i$ and after re-initialization. Re-initialization happens when the counter drops to 0. \n\nProof: Find majority number $x$ in $A$. Mathematically, find $x$ in array $A$ with length $n$ s.t. $cnt_x > n -cnt_x$. \n\nFind a \\textbf{pair} $(a_i, a_j)$ in $A$, if $a_i \\neq a_j$, delete both from $A$. The counter  still\nholds that: $C^{A'}_x > |A'|-C^{A'}_x$. Proof, since $a_i\\neq a_j$, at most 1 of them\nequals $x$, then $C^{A'}_x$ decrements at most by 1, $|A'|$ decrements by 2.\n\nTo find such pair $(a_i, a_j), a_i\\neq a_j$, linear time one-pass algorithm. That's\nwhy \\textit{Moore's voting algorithm} is correct.\n\nAt any time in the execution, let $A'$ be the prefix of $A$ that has been processed,\nif $counter>0$, then keep track the candidate $x$'s counter, the $x$\nis the majority number of $A'$.  If $counter =0$, then for $A'$ we can pair the elements\ns.t. are all pairs has distinct element. Thus, it does not hold that $cnt_x>n-cnt_x$;\nthus $x\\in A'$. $\\blacksquare$\n \nRe-check: This algorithm needs to re-check the current number being counted is indeed the majority number.    \n\n\\begin{python}\ndef majorityElement(self, nums):\n    \"\"\"\n    Algorithm:\n    O(n lgn) sort and take the middle one\n    O(n) Moore's Voting Algorithm\n    \"\"\"\n    mjr = nums[0]\n    cnt = 0\n    for i, v in enumerate(nums):\n        if mjr == v:\n            cnt += 1\n        else:\n            cnt -= 1\n\n        if cnt < 0:\n            mjr = v\n            cnt = 1\n\n    return mjr\n\n\\end{python}\n\\subsubsection{$\\frac{1}{3}$ of the Size}\nGiven an array of integers, the majority number is the number that occurs more than $\\frac{1}{3}$ of the size of the array. This question can be generalized to be solved by $\\frac{1}{k}$ case. \n\n\\subsubsection{$\\frac{1}{k}$ of the Size}\nGiven an array of integers and a number k, the majority number is the number that occurs more than $\\frac{1}{k}$ of the size of the array. In this case, we need to generalize the solution to $\\frac{1}{2}$ majority number problem.\n\\newpag\n\\begin{python}\n\ndef majorityNumber(self, nums, k):\n    \"\"\"\n    Since majority elements appears more \n    than ceil(n/k) times, there are at \n    most k-1 majority number\n    \"\"\"\n    cnt = defaultdict(int)\n    for num in nums:\n        if num in cnt:\n            cnt[num] += 1\n        else:\n            if len(cnt) < k-1:\n                cnt[num] += 1\n            else:\n                for key in cnt.keys():\n                    cnt[key] -= 1\n                    if cnt[key] == 0: del cnt[key]\n    \n    \n    # filter, double-check\n    for key in cnt.keys():\n        if (len(filter(lambda x: x == key, nums)) \n            > len(nums)/k):\n            return key\n\n    raise Exception\n\\end{python}\n\n\n\\section{Two Pointers}\n\\subsection{Interleaving}\n\\runinhead{Interleaving positive and negative numbers.} Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.\n\\begin{lstlisting}\nInput:\n[-33, -19, 30, 26, 21, -9]\nOutput:\n[-33, 30, -19, 26, -9, 21]\n\\end{lstlisting}\nCore clues:\n\\begin{enumerate}\n\\item In 1-pass.\n\\item What (positive or negative) is expected for the current position.\n\\item Where is the next positive and negative element.\n\\end{enumerate}\n\\begin{python}\ndef rerange(self, A):\n    n = len(A)\n    pos_cnt = len(filter(lambda x: x > 0, A))\n    pos_expt = True if pos_cnt*2 > n else False\n\n    neg = 0  # next negative\n    pos = 0  # next positive\n    for i in xrange(n):\n        # search for the next \n        while neg < n and A[neg] > 0: neg += 1\n        while pos < n and A[pos] < 0: pos += 1\n        \n        if pos_expt:\n            A[i], A[pos] = A[pos], A[i]\n        else:\n            A[i], A[neg] = A[neg], A[i]\n\n        if i == neg: neg += 1\n        if i == pos: pos += 1\n\n        pos_expt = not pos_expt\n\\end{python}\n\n\\section{Index Remapping}\n\\subsection{Introduction}\n\\runinhead{Virtual Index.} Analogy to physical machine and virtual machine, the underlying indexing $i$ for array $A$ is the physical index. We can create virtual indexing $i'$ for the same array $A$ to map $A_{i'}$ to the physical entry $A_{i}$.\n\\subsection{Example}\n\\runinhead{Interleaving indexes} Given an array $A$ of length $n$, we want to mapping the virtual indexes to physical indexes such that $A_0$ maps to $A_1$, $A_1$ maps to $A_3$,..., $A_{\\lfloor n/2\\rfloor}$ maps to $A_0$, as followed: \n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.70]{virtual_indexes.png}}\n\\caption{Virtual Indexes. Remapping}\n\\label{fig:virtual_indexes}\n\\end{figure}\n\\begin{lstlisting}\n0 -> 1\n1 -> 3\n2 -> 5\n...\nn/2-1 -> n-1 or n-2\n\nn/2 -> 0\nn/2+1 -> 2\n...\nn -> n-2 or n-1\n\\end{lstlisting}\nIf $n$ is even, \n$$\n(2*i+1)\\%(n+1)\n$$\nIf $n$ is odd,\n$$\n(2*i+1)\\%(n)\n$$\nThus, by combining two cases, we create the mapping relationship: \n\\begin{python}\ndef idx(i):\n    return (2*i+1) % (n|1)\n\\end{python}\n\n", "meta": {"hexsha": "42cb3c0227f5339d0eca8a508a39ec75023b890e", "size": 7893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterArray.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": "chapterArray.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": "chapterArray.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": 35.5540540541, "max_line_length": 246, "alphanum_fraction": 0.6728746991, "num_tokens": 2303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.8376199714402813, "lm_q1q2_score": 0.6555737147754236}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Review of Noninertial Frames}\n\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-14/w14-img1.png}\n\\end{center}\n\n\\begin{p}\nA pendulum is inside of a railcar that is accelerating in the x-direction with acceleration $A$  Find the equilibrium value of the angle $\\phi$. \n\\end{p}\n\\begin{s}\nApply Newton's law in the non-inertial frame:\n\\[m\\ddot{\\v{r}} = \\v{F} - m\\v{A}\\]\nWe have that the forces in the inertial frame are given by $\\v{F} = m\\v{g} + \\v{T}$, (gravity and tension) so:\n\\[m\\ddot{\\v{r}} = m\\v{g} + \\v{T} - m\\v{A}\\]\nGrouping terms:\n\\[m\\ddot{\\v{r}} = \\v{T} + m(\\v{g} - \\v{A})\\]\nWhere we may call $\\v{g} - \\v{A}$ the effective acceleration, $\\v{g}_{eff}$. By trigonometry, the equilibrium angle would be given by:\n\\[\\tan\\phi_{eq} = \\frac{A}{g}\\] As can be seen from the diagram below:\n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-14/w14-img2.png}\n\\end{center}\n\\end{s}\n\n\\begin{center}\n    \\includegraphics[scale=0.75]{Lecture-14/w14-img3.png}\n\\end{center}\n\\begin{center}\n    \\includegraphics[scale=0.75]{Lecture-14/w14-img4.png}\n\\end{center}\n\\begin{p}\nThe earth and moon orbit each other, while both earth and moon frames of reference are accelerating. Find the acceleration in each frame of reference. \n\\end{p}\n\\begin{s}\nIn the inertial frame, the forces on the test mass on the surface of the Earth is given by:\n\\[\\v{F} = m\\v{g} - gM_{m}m\\frac{\\hat{\\v{d}}}{d^2}\\]\nWhere $M_m$ is the mass of the moon. The Earth is not an inertial system, so it experiences some acceleartion. The acceleration of the center of the mass of the earth is given by:\n\\[\\v{A} = -GM_{m}\\frac{\\hat{\\v{d}}_0}{d^2_0}\\]\nHence we have:\n\\[m\\ddot{\\v{r}} = m\\v{g} - GM_mm\\left(\\frac{\\hat{\\v{d}}}{d^2} - \\frac{\\hat{\\v{d}}_0}{d^2_0}\\right) = m\\v{g} - \\v{F}_{tidal}\\]\nThe tidal force is the vector difference between if the mass is at the surface of earth vs. at the center of mass of the earth. This results in tidal effects at either side of the earth, with the same magnitude and in the opposite direction ($\\hat{\\v{d}}$ and $\\hat{\\v{d}}_0$ are parallel at these two points, so the effect is maximal). We end up with a bulge on both sides of the Earth. At the top and bottom, we have that the x components cancel by symmetry, so we only have the y component (weaker effect, inwards pointing). This is shown in the diagram below:\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-14/w14-img5.png}\n\\end{center}\n\\end{s}\n\n\\begin{p}\nFind the equation of motion for a particle on the surface of the ocean of the earth, in the earth’s frame of reference. \n\\end{p}\n\\begin{s}\n\n\\end{s}\n\\end{document}", "meta": {"hexsha": "5a43a0e3c063d28c8bd335304542122e16f7977c", "size": 2670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-14/Worksheet-14.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-14/Worksheet-14.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-14/Worksheet-14.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": 48.5454545455, "max_line_length": 563, "alphanum_fraction": 0.6958801498, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6555737020853464}}
{"text": "%\n% 265\n%\n\\chapter{The Zeta Function of Riemann}\n\n\\Section{13}{1}{Definition of the Zeta-function.}\n\nLet s = a + it where a and t are real*; then, if S > 0, the series\n\n= 1 n=i n is a uniformly convergent series of analytic functions\n(\\hardsubsectionref{2}{3}{3}, \\hardsubsectionref{3}{3}{4}) %TODO:cite multiple\nin any domain in which <r 1 + 8; and consequently the\nseries is an analytic function of s in such a domam. The function is\ncalled the Zeta-function; although it was known to Eulerf, its most\nremarkable properties were not discovered before RiemannJ who\ndiscussed it in his memoir on prime numbers; it has since proved to\nbe of fundamental importance, not onl - in the Theory of Prime\nNumbers, but also in the higher theory of the Gamma-function and\nallied functions.\n\n1311. The generalised Zeta-function .\n\nMany of the properties possessed by the Zeta-function are particular\ncases of properties possessed by a more general function defined, when\ncr' 1 + 8, by the equation\n\nwhere a is a constant. For simplicity, we shall suppose || that < \\$\n1, and then we take arg(a + n) = 0. It is evident that (s, 1) = (s).\n\n1312. The expression of s, a) as an infinite integral.\n\nSince (a-F ??)-' T (s) = / af- e' '' ''''' do-., when arg.r = and o- >\n(and a fortiori when a \\ - S), we have, when o- 1 + 8, V s) s,a)= \\ \\\nm :L | .-r*-' e\" < + '* c a;\n\n.v xjio 1-6- .'o l-e- \"\n\n* The letters o\", t will be used in this sense throughout the chapter.\n\nt Commentatioiies Acad. ScL Imp. Petropolitunae, ix. (1737), pp.\n160-188.\n\n+ Berliner MonaUherichte, 1659, pp. 671-680. Ges. Werke (1876), pp.\n136-141.\n\n§ The definition of this function appears to be due to Hurwitz,\nZeitschrift fiir Math, ttnd Phys. xxvii. (1882), pp. 86-101.\n\nII When a has this range of values, the properties of the function\nare, in general, much simpler than the corresponding properties for\nother values of a. The results of \\hardsubsectionref{13}{1}{4} are true for all values of a\n(negative integer values excepted); and the results of \\hardsubsectionref{13}{1}{2},\n\\hardsubsectionref{13}{1}{3}, \\hardsectionref{13}{2} are true when R (a) > 0.\n\n%\n% 266\n%\n\nNow, when ic' i), e l + x, and so the modulus of the second of these\nintegrals does not exceed\n\nI \"\" A-'-2e-(- + ) rf = (N f aV- r (o- - 1),\n\n-'0\n\nwhich (when o- 1 + 8) tends to as JV x . Hence, when a l + 8 and arg x\n= 0,\n\nthis formula corresponds in some respects to Euler's integral for the\nGamma- function.\n\n\\Subsection{13}{1}{3}{The expression* of (s, a) as a contour integral.}\nWhen a 1 + 8,\nconsider\n\n(0+) / y-i g-a2\n\n' 1 - e\n\nthe contour of integration being of Hankel's t3rpe \\hardsubsectionref{12}{2}{2}) and not\ncontaining the points + 2n7ri(n = l, 2, 3,,..) which are poles of the\nintegrand; it is supposed (as in \\hardsubsectionref{12}{2}{2}) that, arg(- z)\\ ir.\n\nIt is legitimate to modify the contour, precisely as in \\hardsubsectionref{12}{2}{2}, whenf\no- 1 + B; and we get\n\n'(0+) - A -ip-az r° 8-ip-az\n\nTherefore\n\n27n . ' 1 - e\n\nNow this last integral is a one-valued analytic function of s for all\nvalues of s. Hence the only possible singularities of s, a) are at the\nsingularities of r (1 - s), i.e. at the points 1, 2, 3, ..., and, with\nthe exception of these points, the integral affords a representation\nof s, a) valid over the whole plane. The result obtained corresponds\nto Hankel's integral for the Gamma- function. Also, we have seen that\ns, a) is analytic when o- 1 -H 8, and so the only singularity of s, a)\nis at the point .s = 1. Writing 6- = 1 in the\n\nintegral, we get\n\n1 r(o+) e-,\n\nZTTl J 1 - e ' which is the residue at £; = of the integrand, and this\nresidue is 1.\n\nHence lim f \\ = -l.\n\n* il (1 -s)\n\n* Given by Riemann for the ordinary Zeta-function.\n\n+ If (7 1, the integral taken along any straight line up to the origin\ndoes not converge.\n\n%\n% 267\n%\n\nSince T (1 - s) has a single pole at s = 1 with residue - 1, it\nfollows that the only singularity of s, a) is a simple pole with\nresidue + 1 at 5 = 1.\n\nExample 1. Shew that, when R (s) > 0,\n\n(1 \\ 21 -*) /-(s) = i: \\ 1 + 1 \\ i . 1 2* 3' 4s ~\n\n1 / * x ~\n\nExuraple 2. -Shew that, when R s)> 1,\n\nExample 3. Shew that\n\nwhere the contour does not include any of the points +rr ±877 ±57ri',\n....\n\n1314. Values of s, a) for special values of s.\n\nIn the special case when s is an integer (positive or negative),\n\nis a one- valued function of z. We may consequently apply Cauchy's\ntheorem, so that - . -r: dz is the residue of the intesfrand at = 0,\nthat\n\nis to say, it is the coefficient of z'\" in V .\n\n1 - e~\n\nTo obtain this coefficient we differentiate the expansion \\hardsectionref{7}{2})\n\n. e-\" - 1 \\ \\ I (-)n< (a)2 e- -l n=\\ n'.\n\nterm-by-term with regard to a, where (f)n iO denotes the Bernoullian\npoly- nomial.\n\n(This is obviously legitimate, by \\hardsectionref{4}{7}, when | s j < tt, since - \\,\ncan be expanded into a power series in z imiformly convergent with\nrespect to a.)\n\nThen i ll-r Ml\".\n\nTherefore f s is zero or a negative integer (= - m), we have\n\n  - m, a) = - </)', +o(a)/[(m -f- 1) ( i -f- 2)|. In the special case\nwhen a = 1, if s = - m, then (5) is the coefficient\n\n/ y, yji I Z\n\nof z-~ in the expansion of - ' ' .\n\n%\n% 268\n%\n\nHence, by \\hardsectionref{7}{2},\n\n (-2m) = 0, l-2m) = (-y-BJ 2m) (m = 1, 2, S, ...),\n\nr(0)=-|.\n\nThese equations give the value of (s) ivhen s is a negative integer or\nzero.\n\n\\Subsection{13}{1}{5}{TJie forniula* of Hurwitz for s, a) when cr< 0.}\n\nConsider - - -; - r-; - dz taken round a contour C consisting of\n\n27n J c I - e~ °\n\na (large) circle of radius (2iV+l)7r, (iV an integer), starting at the\npoint\n\n(2iV\"+ l)7r and encircling the origin in the positive direction, arg\n(- z) being\n\nzero at z = -(2N+l) ir.\n\nIn the region between C and the contour 2NTr +7r; +), of which the\ncontour of § 13\"lo is the limiting form, (- zy~' e~' (1 - e~ )~ is\nanalytic and one-valued except at the simple poles + 2Tri, + 47, ...,\n± 2N7ri.\n\nHence\n\n27riJc l-e~' 27ri j n+i) n l-e'- n=i\n\nwhere i2, Rn are the residues of the integrand at 2n7ri, - 2 7\nrespectively. At the point at which - z = 2mre~ ', the residue is\n\n(2n7r)'-le- '''('-l)e-2 \"''',\n\nand hence Rn + Rn = (27?7r) ~ 2 sin i ' \" 2'n-an j .\n\nHence\n\n1 /(0+) (\\ )s-ig-a\n\n27riJ(2iv'+i) l-e-\n\n\\ 2 sin STT cos 2'rran) 2 cos sir sin (27ra? ) \" \"(27rr,=i /? - \" ' \\\n2 ) = n':i n'-'\n\n+ H-  T -, dz.\n\n2in J c I - e\n\nNow, since < a 1, it is easy to see that we can find a number K\nindependent of N' such that | e~\" (1 - e~ )~ \\ < K when z is on C.\n\nHence\n\n1 r ( -z\\ \\ ~' e~\"' I 1 f\"\"\n\n-  1 -- . dz\\ < K\\, (2.Y + 1) -rrYe'\"' I rf\n\n27r\n\n<ir (2iV-|-l)7r|' e-l*l as i\\\" X if cr < 0.\n\n* Zeitschrift fill- Math, und Phys. xsvii. (1882), p. 95,\n\n%\n% 269\n%\n\nMaking N y:, we obtain the result of Hurwitz that, if o- < 0,\n\n u. r(l-,v) ( /I cos(27ra ) /i \\ 4 sin(27ra/i))\n\neach of these series being convergent.\n\n13151. Riemairii's relation between (s) and (l - s).\n\nIf we write a = 1 in the formula of Hurwitz given in \\hardsubsectionref{13}{1}{5}, and\nemploy \\hardsubsectionref{12}{1}{4}, we get the remarkable result, due bo Riemann, that\n\n2 -* r (S) (S) cos (I STTJ = (1 \\ s).\n\nSince both sides of this equation are analytic functions of s, save\nfor isolated values of s at which they have poles, this equation,\nproved when a < 0, persists (by \\hardsectionref{5}{5}) for all values of s save those\nisolated values.\n\nExample 1. If m be a positive integer, shew that\n\nC (2>n) = S- \"*- 1 7r2\"' BJ 2m) ! .\n\nExample 2. Shew that r is)n~ C (s) is unaltered by replacing s by 1 -\ns.\n\n\\addexamplecitation{Riemann.}\n\nExample 3. Deduce from Riemann's relation that the zeros of f (5) at -\n2, - 4, - 6, ... are zeros of the tirst order.\n\n\\Section{13}{2}{Hennites* fornuda for TODO (s, a).}\n\nLet us apply Plana's theorem (example 7, p. 145) to the function (p\n(z) =(a + z)~\\ where arg ii + z) has its principal value.\n\nDefine the function q x, y) by the equation\n\n(/ < '' y) = 9- - K + + wT' - ( + A' - iy)~']\n\n= - Ha + A')- + if] ~ * sin \\ s arc tan - - .\n\n  X + a)\n\nSince + arc tan - - does not exceed the smaller of tt and ', we X + a\n' x+ a\n\nhave\n\n\\ q x,ij)\\ \\ (a + x)'+f-] *< 1 y-'; sinh JItt, 5 j j,\n\n' q (X, y) : [ a + xf + f]- -''\\ jsinh | | | . Using the first result\nwhen y > a and the second when y < a it is\n\n* Annali di Matemalica, (3),fv. (1901), pp. 57-72.\n\nt If t>0, arc tan = :,<. I 5; and arc tan < / dt.\n\nJ 1-rt- J 1-i-t- Jo\n\n%\n% 270\n%\n\nevident that, if o- > 0, q (.v, y) (e-\" - 1) dy is convergent when x\nand\n\nJo\n\ntends to as ic - X; also (a + x)~ dx converges if a > 1.\n\n.0\n\nHence, if o- > 1, it is legitimate to make 'o - oo in the result\ncontained in the example cited; and we have\n\n (s,a) = la- +\\ \\ a+ocy dx + 'lj (a2 + 2)-i jsin fs arc tan 0j- J .\n\nSo\n\n  s, a) = la-s + f +2j\\ a + f)-y jsin (. arc tan )| - .\n\nThis is Hermite's formula*; using the results that, if y 0,\n\narc tan y/a y/a f y < dT j, arc tan y/a < 2 tt (y>: a7r],\n\nwe see that the integral involved in the formula converges for all\nvalues of s. Further, the integral defines an analytic function of s\nfor all values of s.\n\nTo prove this, it is sufficient \\hardsubsectionref{5}{3}{1}) to shew that the integral\nobtained by differentiating under the sign of integration converges\nuniformly; that is to say we have to prove that\n\n/ - 1 log a- + \\ y2) (a' +y-) - 5* sin i s arc tan -\n\ndij\n\no ' y\n\n- I (( +y ) * arc tan - cos f s arc tan - j\n\ndi/\n\n~' y -I\n\nconverges uniformly with respect to s in any domain of values of s.\nNow when s ! A, where A is any positive number, we have\n\n1 (a2+y-) ~ * arc tan '- cos (s arc tan j < a- + i/' ')i cosh (|n-A);\n\nsince a-+f)\n\n  J\n\n,2 iA y±y\\\n\nconverges, the second integral converges uniformly by \\hardsubsubsectionref{4}{4}{3}{1} (I).\n\nBy dividing the path of integration of the first integral into two\nparts (0, rra), Una, X ) and using the results\n\nsin'lsarctau- I <sinh -, sin (s arc tan -) l<sinhJr7rA\n\nV / 1 V /,\n\nin the respective parts, we can simihxrly shew that the first integral\nconverges uniformly.\n\nConsequently Hermite's formula is valid \\hardsectionref{5}{5}) for all values of s,\nand it is legitimate to differentiate under the sign of integration,\nand the differentiated integral is a continuous function of s.\n\n* The corresponding formula when = 1 had been previously giveu by\nJensen.\n\n%\n% 271\n%\n\n\\Subsection{13}{2}{1}{Deductions from Hermites formula.}\nWriting s = in Hermite's\nformula, we see that\n\nMaking s - 1, from the uniformity of convergence of the integral\ninvolved in Hermite's formula we see that\n\nli,, 1 (,, a)-- \\ = lim + 1 + 2 r, -,, .\n\n  i( ' *-lj,-*! s-\\ 2a Jo a- + y-') e y-l)\n\nHence, by the example of \\hardsubsectionref{12}{3}{2}, we have\n\nhm|ri., )- - | = -j .\n\nFurther, differentiating* the formula for l s, a) and then making s -\n0, we get\n\n\\ d, A y 1 \\, a -*' log a a'-'\n\n+ 2 - o log (a- + 2/-) . (a- + y-) ~ *' sin ( s arc tan -)\n\nJo i \\ ci/\n\n+ (a- + V-) ~ arc tan - cos ( s arc tan - ) [ - -\n\n    a \\ a)] e' y - 1\n\nI i\\, ' arc tan (Wa),\n\n= ( a-,jlog - + 2J \\ \\ \\ A rfy.\n\nHence, by § 1232,\n\nThese results had previously been obtained in a different manner by\nLerch -j*.\n\nCorollary. lim k(s) 1 = 7> T (0) = -5 log(27r).\n\n\\Section{13}{3}{Euler's product for TODO(s).}\n\nLet (T l+B; and let 2, 3, 5, .../>,... be the prime numbers in order.\nThen, subtracting the series for 2~* (s) from the series for (s), we\nget\n\n (.).(l-2-) = ~ +,+~ +, + ...,\n\n* This was justified in \\hardsectionref{13}{2}.\n\nt The formula for f (s, a) from which Lerch derived these results is\ngiven in a memoir published by the Academy of Sciences of Prague. A\nsummary of his memoir is contained in the Jahrbuch iiber die\nFortschritte der Math. 1893-1894, p. 484.\n\n%\n% 272\n%\n\nall the terms of Sn~ for which n is a multiple of 2 being omitted;\nthen in like manner\n\nall the terms for which n is a miiltiple of 2 or 3 being omitted; and\nso on; so that\n\n (s) . (1 - 2-0(1 - 3-0  (1 -p-') = 1 + 2' -\n\nthe ' denoting that only those values of n (greater than p) which are\nprime to 2, 3, ... j:? occur in the summation.\n\nNow* i t'n-' I \\$ I'n-'- \\$ 2 n' - as ja co .\n\nTherefore if a I + 8, the product (s) Yl (1 -p~ ) converges to 1,\ntuhere\n\np the number p assumes the prime values 2, 3, 5, ... only.\n\nBut the product 11 (1 -p~ ) converges when a I + 8, for it consists of\np\n\nsome of the factors of the absolutely convergent product 11 (1 - n~ ).\n\nConsequently we infer that (s) has no zeros at which a 1 + 8; for if\n\nit had any such zeros, IT (1 -p~ ) would not converge at them. p\n\nTherefore, ii a 1 + 8,\n\nThis is Euler's result.\n\n\\Subsection{13}{3}{1}{Riemanns hypothesis concerning the zeros of (s).}\n\nIt has just been proved that (s) has no zeros at which a >1.\n\nFrom the formula (| 13*1 51)\n\ny s) = 2 -i r(.9)|-isec ( STT Ul-s)\n\nit is now apparent that the only zeros of (.5) for which a < are the\nzeros\n\nof r(s) - sec (2 '''') ) i-e- the points s = - 2, - -4, ....\n\nHence all the zeros of f (s) except those at - 2, - ]>, ... lie in\nthat strip of the domain of the complex variable s ivhich is defined\nby - a 1.\n\nIt was conjectured by Riemann, but it has not yet been proved, that\nall\n\nthe zeros of (.s) in this strip lie on the line o\" = 2 ' \" ' ile it\nhas quite recently\n\nbeen proved by Hardy -f- that an infinity of zeros of (s) actually lie\non cr = : .\n\nIt is highly probable that Riemann's conjecture is correct, and the\nproof of it would have far-reaching consequences in the theory of\nPrime Numbers.\n\n* The first term of S' starts with the prime next greater than p. t\nComptes Rendiif!, clviii. (1914), p. 1012; see p. 280.\n\n%\n% 273\n%\n\n\\Section{13}{4}{Riemanns integral for TODO(s).}\nIt is easy to see that, if cr > 0,\n\nn' Hence, when a > 0,\n\n   s) r ( ) TT - i = lim f 1 e- \"''  x -'- dx.\n\nX\n\nNow, if OT x)= S e\"\"\"' '\", since, by example 17 of Chapter vi (p.\n124), 1 + 2ct x) = x~ ' 1 4- 2ts (I/*'), we have lim x -sr x) = 1;\nand hence\n\n st(x)x ~ dx converges when a > .\n\nJo\n\nConsequently, if a > 2, (s)r ('.7s')7r-'''\"=lim ! (x) x -''' dx- i 1\ne''''''' xi'-' dx'] .\n\nV\" / N o lJt) .0 M = .V+1 J\n\nNow, as in \\hardsubsectionref{13}{1}{2}, the modulus of the last integral does not exceed\n\nJo \\ n = N+l j .'o l\\ e-< V+l) x\n\n.0\n\n= 7r(iY+l)|-'|(iV H2;\\ \\ )7r l-i< rQ<r-l)\n\n-*- as uV - - X, since a > 2. Hence, when cr > 2,\n\n= ri-. + -i +x- -x;7(llx)\\ x -'-' dx+ I t!r( )a:i -l(fa;\n\n= - + 7 + f .rizTOr)a;-i'' + l(- )(;a;+[ nT(x)x '-Ux.\n\nConsequently\n\nr(5)r(L')7r-i*- - v -r,= I (x - -''> +x ')x-' (x)dx.\n\nNow the integral on the right represents an analytic function of s for\nall values of s, by \\hardsubsectionref{5}{3}{2}, since on the path of integration\n\ntn- x) < e-' * S e-\"\" e-\"\" (1 - e-\"\")-'.\n\n;i=0\n\nConsequently, by § o S, the above equation, proved when cr> 2,\npersists for all values of 5.\n\nw. M. A.  18\n\n%\n% 274\n%\n\nIf now we put\n\ns = l + it, ls(s- 1) (s) r ( s 7r- *- = 1(0, we have\n\n  (t) = I - ff + j x-i (x) cos ( tlogx dx.\n\nSince x~ -st x) log x\\ cos U log x + - mr) dx\n\nsatisfies the test of \\hardsubsectionref{4}{4}{4} corollary, we may differentiate any\nnumber of times under the sign of integration, and then put = 0.\nHence, by Taylor's theorem, we have for all values* of\n\n (0= S a t''', =o\n\nby considering the last integral ag i is obviously real. This result\nis fundamental in Riemann's researches.\n\n\\Section{13}{5}{Inequalities satisfied by TODO(s, a) when TODO.}\n\nWe shall now investigate the behaviour of (s, a) as t - + oo, for\ngiven values of cr.\n\nWhen cr> 1, it is easy to see that, if N be any integer,\n\nas, -)=U- + n)- - -,\\ s)il aY- -LM' where\n\n\\ 1 J 1 \\ 1 \\ \\ 1\n\n/'\"+! u-n,\n\nfn\n\nNow, when tr'> 0, l/ ( ) I ! I /\n\nJn (u + a)\n\n\" +] a-n\n\nai\n\nfn+l J n (n\n\ndi\n\n n + af- ' = slin + a)-\"-'. Therefore the series i\" f (s) is a\nuniformly convergent series of analytic functions\n\nwhen cr >; so that 2 / (s) is an analytic function when <t> 0; and\nconsequently, bj'\n\n;i=.V\n\\hardsectionref{5}{5}, the function ( (s, a) may be defined when (r>0 by the series\n\nC (., a) = £ (a + )-.- (i\\,)(; ).-. -j/. . Now let [t] be the\ngreatest integer in | < |; and take iV=[ ]. Then\n\n|C )I 2 \\ \\ {a + nr \\ + \\ \\ { l-sr'i[t] + ay- + 2 \\ s\\ \\ {n + ar'' '\n\n71=0 n=[t] [t] X\n\n< 2 a + 7i)- + \\ t mt] + ay ' + \\ s\\ 2 (n + a) ' \\ n=0 i>=[t]\n\n* In this particular piece of analysis it is convenieut to regard t as\na complex variable, defined by the equation s = + it; and then | (t)\nis an integral function of t.\n\n%\n% 275\n%\n\nUsing the Maclaurin-Cauchy sum formula \\hardsubsectionref{4}{4}{3}), we get\n\nr[t] r\n\nJo J[t]-l\n\nNow when 8 a- 1 - S where S > 0, we have \\ (s, a) \\ <a- + l-a)- a +\n[t]y-'' -a - + \\ t [t] + af-'' + \\ s\\ < r-H[t]-l + a)-''. Hence f (s,\na) = 0 \\ t p\"* ), the constant implied in the symbol being independent\nof s. But, when 1 - 8 cr l + S, we have\n\nI C (, a) I = ( i i \\'-n + / ( + A-)-'' dx\n\n<0 \\ t f-\") + '-'+( + tf-\"] I '' (a+x) - 1 dx,\n\nsince (a + x)~' a ~' a+x)-'>- when o- l, and (a+x)'\" a+[t]) ~' (a +\nx)- when o\" 1, anoJ so\n\nCis, a) = 'Itr'' log \\ t\\ \\ }. When 0- 1+8,\n\n|C(, )| a~ + i (a + r'-* = 6'(l).\n\n\\Subsection{13}{5}{1}{Inequalities satisfied by f (s, a) wlien cr 0.}\n\nWe next obtain inequalities of a similar nature when <j h. In the case\nof the function f (s) we use Riemaim's relation\n\nC(s) = 2''7r -i r (1 -s) f (1 -s) sin (isTr). Now, when o- < 1 - 8, we\nhave, by § 1233,\n\nr(l-s) = 0 e(*\"*)'*' ( -*)-( -*' and ao\n\nC (s) = [exp .V I | + ( -o--i01og|l-s|+iarctan /(l-o-) ]C(l-s).\n\nSince arc tan i/(l - cr)= ±i7r4-0 ( ~ ), according as is positive or\nnegative, we see, from the results already obtained for f (s, a), that\n\ni B) = 0 \\ t\\ \\ -''\\ i s).\n\nIn the case of the function (s, ), we have to use the formula of\nHurwitz \\hardsubsectionref{13}{1}{5}) to obtain the generalisation of this result; we\nhave, when o- < 0,\n\ni s,a): -i ±nY- V s)\\ \\ e ' ' Uiy- )- -''''\" i-a s)\\ where Ca (!-' )=\n2\n\n1 %'-\n\n. - Hence (1 -e\" ''\"') f (l - ) = e2' + 2 e2 ' ' [/i'-i- (n- l) -i]\n\n+ (S-1) i / T' /\"\" tt -2£;\n\nsince the series on the right is a uniformly convergent series of\nanalytic functions whenever o- l-S, this equation gives the\ncontinuation of fa(l-*) over the range O o-: 1-S; so that, whenever cr\n1 - S, we have\n\nsin7raCa(l-s) 1 1+ 2 /i' ~' + (n-l)' -iH-|s-l I 2 /\" n\"-- dv..\n\n1=2 re=iV+l ] n-X\n\n18-2\n\n%\n% 276\n%\n\nAnd obviously\n\nTaking V=[ ], we obtain, as in \\hardsectionref{13}{5},\n\nCa l-s)=0 \\ tr) 8 a l-8) .\n\n= 0 \\ tf\\ og\\ t ) -8 (T<8).\n\nC s)=0 ) a<-8).\n\nConsequently, whether a is unity or not, we have the results\n\nC s,a) = 0 \\ t\\ \\ -'') (a 8)\n\n= 0 \\ t\\ \\ ) (8 0- 1-8)\n\n= Oi\\ t\\ \\ \\ og\\ t ) -8 a 8).\n\nWe may combine these results and those of \\hardsectionref{13}{5}, into the single\nformula\n\nC(s,a) = 0(i<r\" 'log| |), where*\n\nr(o-)-i-(r, (o- O); 7-(o-) = A, (O a i); r(a) = l-(r, (*-\\$<t 1);\nr(cr) = 0, ( r l);\n\nand the log | t \\ may be suppressed except when - 8 o- S or when 1 - S\ncr l + S.\n\n\\Section{13}{6}{The asymptotic expansion of log TODO.}\nFrom \\hardsectionref{12}{1} example 3,\nit follows that\n\n\\ aJ =i (.V a+nJ J T (z + a) Now, the principal values of the\nlogarithms being taken,\n\n= 2\n\nn=l\n\n- az\n\n  (-)\"'\"'\n\n+ 2\n\n(\\ yn-i r\n\nji a + n)J 2 'ni (a - + w)\"'J j,,' ! m a'' If I I < a, the double\nseries is absolutely convergent since\n\n' ' - log 1 + -\n\n aA- n) ° V a+ n) a+ n\n\n= 1 [\\ /i(a + n)\n\nconverges.\n\nConsequently\n\nlog\n\naz\n\n+\n\ne-v r(a)\n\nr ( + a) a =1 71 (a + n) ',,,=2 wi\n\n1 1 772'\n\nX / yn- 1\n\n2 5 z'\"' m,a).\n\nNow consider;;; -; - -. tis, a) ds, the contour of integration being\n\nziri J c ssimrs\n\nsimilar to that of \\hardsubsectionref{12}{2}{2} enclosing the points 5 = 2, 3, 4, ... but\nnot the\n\npoints 1, 0, -1,-2, ...; the residue of the integrand at s = m(m 2) is\n\n- z m, a); and since, as cr x (where s= a + it), s, a) = (1), the\n\nintegral converges if | 2 | < 1.\n\n* It can be proved that t a) may be taken to be i (1 - a) when (t 1.\nSee Landau, Prim- zahlen, % 237.\n\n%\n% 277\n%\n\nConsequently\n\n, e-y'r a) z az \\ -rrz .. ..\n\nI z + a) a =i n (a + m) Ztti q s sin its\n\nHence\n\n- V a) V' a) 1 f -TTZ' .,,\n\n  r ( + a) r (a) 27ri j c- 5 sin tts '\n\nNow let D be a semicircle of (large) radius N with centre at s = f,\nthe semicircle lying on the right of the line <r = |. On this\nsemicircle (s, a)=0(l), !ir*| = |;<'e- ' '-g', and so the integrand\nis* 5:; e-' i'f- ' s3l. Hence if | | < 1 and - tt + 8 arg tt - 8,\nwhere S is positive, the integrand is \\ zY e' *\" ), and hence\n\nt, s, a)ds 0\n\nJ j)S sm 7r5\n\nas iV -* 00 . It follows at once that, if; arg z \\ : 7r - 8 and j [ <\n1,\n\n, T(a) r'(a) i r + '' 'rrz',,,\n\nlog Y ~- -. =-z + r-. ~. (s, a) ds.\n\n° 1 ( + a) 1 (a) 'Itti J s issimrs\n\nBut this integral defines an analytic function of for all values of 12\n| if\n\nj arg z] TT - 8.\n\nHence, by \\hardsectionref{5}{5}, the above equation, proved when [ | < 1, persists for\nall values of I I when ] arg zI' tt - 8.\n\nNow consider I --. (s, a) ds, where n is a fixed integer and\n\n-/ -n- ±iii sin TTS'\n\nR is going to tend to infinity. By \\hardsubsectionref{13}{5}{1}, the integrand is [z' e'\nR\"' ',\"' where - n - - cr :\\$ -; and hence if the upper signs be\ntaken, or if the lower signs be taken, the integral tends to zero as\ni2 - x . Therefore, by Cauchy's theorem,\n\nVia) T'ia) 1 f->'-h + i n\n\nlog \\ \\ = -z j -~- + -. - (s,a)ds+ X R,n,\n\nwhere R is the residue of the integrand at s = - in. Now, on the new\npath of integration\n\nI s sin ITS \\\n\nwhere K is independent of z and t, and t (t) is the function defined\nin \\hardsubsectionref{13}{5}{1}.\n\n* The constants implied in the symbol are independent of s and z\nthroughout.\n\n%\n% 278\n%\n\nConsequently, since j e~ - ',t]' - -i)dt converges, we have\n\nwhen \\ 2\\ is large.\n\nNow, when m is a positive integer, i?, = - - '- and so\n\n- m\n\nby \\hardsubsectionref{13}{1}{4}, Rm = r '-,, where 6,/ (a) denotes the derivate of\n\nm(m + l)(m + 2)\n\nBernoulli's polynomial.\n\nAlso Ro is the residue at s = of\n\nand so i2 = f - - a j log + ' (0, a)\n\n= (i - ) log + log r ( ) - log (27r), by \\hardsubsectionref{13}{2}{1}.\n\nAnd, using \\hardsubsectionref{13}{2}{1}, R\\, is the residue* at >Sf= of\n\n\\ ia\\ s=\\ ..,(i, >...),(i,s, g,+..,(l\\ i:g,...).\n\nXT 75 1 r' (a)\n\nHence R\\ = - z\\ oo'z+ z tt + z.\n\nr(a)\n\nConsequently, finally, if | arg z ir- S and | j is large, log r (z +\na) == (z + a -~ \\ og z - z + l\\ og 27r)\n\n+ i (-)\"'~ </>w+2( -), \\ \\ s\n\nw=i w(77H- l)(m + 2) *\n\nIn the special case when a = 1, this reduces to the formula found\npreviously in \\hardsubsectionref{12}{3}{3} for a more restricted range of values of arg 2.\n\nThe asymptotic expansion just obtained is valid when a is not\nrestricted by the inequality < a 1; but the investigation of it\ninvolves the rather more elaborate methods which are necessary for\nobtaining inequalities satisfied by (s, a) when a does not satisfy the\ninequality 0<a%l. But if, in the formula just obtained, we write a=l\nand then put z + a for z, it is easily seen that, when j arg ( + a) [\n< tt - 8, we have\n\nlog r (2 + a + 1) = f + a + 2) log (z + a)-z-a + l ' + o l);\n\n* Writings = 5+1.\n\n%\n% 279\n%\n\nsubtracting log (z + a) from each side, we easily see that when both\n\nI arg z + a) 7r- 8 and \\ arg zI tt - 8, we have the asymptotic formula\n\nlogr( + a)=( + a- jlog - + . log(27r) + o(l),\n\nwhere the expression which is o (1) tends to zero as \\ Zi->X).\n\nREFERENCES. G. F. B. Riemann, Ges. Werke, pp. 145-155. E. G. H.\nLandau, Handbuch der Primzahlen. (Leipzig, 1909.) E. L. LiNDELOF, Le\nCalcid des Residue, Ch. iv. (Paris, 1905.) E. W. Barnes, Messenger of\nMathematics, xxix. (1899), pp. 64-128. G. H. Hardy and J. E.\nLittlewood, Acta Mathematical xli. (1917), pp. 119-196.\n\nMiscellaneous Examples.\n\n1. Shew that\n\n(2 - 1 ) f (5) = - - + 2 / (i +y2)-* sin (s arc tan 2y)\n\n(Jensen, D Intermediaire des Math. (1895), 'p. 346.)\n\n2. Shew that\n\n2 -i / * dv\n\nC(s)= \\ j-2 j (1+/)-** sin (5 arc tan y) - - .\n\n\\addexamplecitation{Jensen.}\n\n3. Discuss the asymptotic expansion of \\ ogG z + a), (Chapter xii\nexample 48) by aid of the generahsed Zeta-function. \\addexamplecitation{Barnes.}\n\n4. Shew that, if cr > 1,\n\np m=.l mp\"\n\nthe summation extending over the prime numbers jd = 2, 3, 5,\n\n(Dirichlet, Journal de Math. iv. (1839), p. 407.)\n\n5. Shew that, if o-> 1,\n\nwhere A (w) = when n is not a power of a prime, and A n) = \\ ogp when\nis a power of a prime p.\n\n6. Prove that e~- -dx\n\nlog C (5) = 2 2\n\n \\&\n\n'(is) Jo\n\n** r (is) 1\n\n(Lerch, KraMw Rozprawy*, ll. See the Jahrbuch ilber die Fortschritte\nder Math. 1893-1894, p. 482.\n\n%\n% 280\n%\n\n7. If 00\n\nwhere | a; | < 1, and the real part of s is positive, shew that\n\nand, if 5 < 1,\n\nlim (1 - xy- (j) (s, A-) = r (1 - s).\n\n\\addexamplecitation{Appell, Comptes Rendus, lxxxvii.}\n\n8. If X, a, and s be real, and < a < 1, and s > 1, and if\n\n< (--' ' ).= ?,( : .' . .\n\nshew that\n\nand\n\n(b (x, a, 1 - s) = tttVo\n\n\\addexamplecitation{Lerch, Acta Math, xi.}\n\n9. By evaluating the residues at the poles on the left of the straight\nline taken as contour, shew that, if k > 0, and | arg 3/ 1 < Att,\n\n1 fk+cci\n\ne-y= --.l rhi)y-''du,\n\nand deduce that, if - > i,\n\n9 - f ' ' (\")  ('\" )\" \" '') du = w x\\\n\nk - xi\n\nand thence that, if a is an acute angle.\n\nr 1 (0 = TT cos ia - W\" 1 + 2 or (e -) . 1 t + t\n\n\\addexamplecitation{Hardy.}\n\n10. By differentiating 2?i times under the integral sign in the last\nresult of example 9, and then making a - Jtt, deduce from example 17\non p. 124 that\n\nr-*i- <*. (,)*= < -cos|\n\nBy taking n large, deduce that there is no number 0 such that | t) is\nof fixed sign when t > to, and thence that f (s) has an infinity of\nzeros on the line <r = .\n\n\\addexamplecitation{Hardy.}\n\n[Hardy and Littlewood, P?'oc. London Math. Soc. xix. (1920), have\nshewn that the number of zeros on the hue o- = i for which < < T' is\nat least ( T) as - 00; if the\n\nKiemann hypothesis is true, the number is -- 7' log - \" 7\"+ (log 7;\nsee\n\nLandau, Pnmzahlen, i. p. 370.]\n", "meta": {"hexsha": "5b27c7cf3360365f6af188f3cf5faeaae2162b2c", "size": 25512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch13.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-ch13.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-ch13.tex", "max_forks_repo_name": "CdLbB/Whittaker-and-Watson", "max_forks_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2971428571, "max_line_length": 92, "alphanum_fraction": 0.613593603, "num_tokens": 9506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.9005297921244243, "lm_q1q2_score": 0.6555635796749844}}
{"text": "Given a predictor $P$ and a test object $s \\in \\testset$,\nthe performance of the predictor for this conjecture can be computed.\nThe general performance of the predictor for a given $\\testset$\ncan be computed by averaging the values of a metric for all elements in $\\testset$.\n\n\\begin{definition}\n  A metrics function takes a ranking and a known object and yields a rational number\n  that represents how the ranking relates to the actual ranking for the known object.\n  Such a function is of the type $\\rankings \\rightarrow \\objs \\rightarrow \\rat$.\n\\end{definition}\n\n\\begin{definition} The set of dependencies required to solve conjecture $\\type[s]$ is defined as\n  \\[ \\required[s] = \\deps{s} \\]\n\\end{definition}\n\n\\begin{definition} The set of suggestions done in a ranking is defined as\n  \\[ \\suggestions{r} = \\{ d \\in \\depset ~|~ r(d) ~\\text{is defined} \\} \\]\n\\end{definition}\n\n\\begin{definition} We define $\\topn{n}{r}$ to be\n  \\[ \\topn{n}{r} = \\downset{\\depset}{\\nth{n}{(\\suggestions{r}, \\lambda x~y. r(x) > r(y))}} \\]\n\\end{definition}\n\n\\begin{definition}\n  Given a totally ordered set $(X, \\leq)$, and an element $x \\in X$, we define $\\findindex{X}{x}$ to be the position of $x$ in totally ordered set $X$.\n  \\[ \\findindex{X}{x} = \\left\\{\n    \\begin{array}{ll}\n      0 & \\text{if~} x = \\infimum_X \\\\\n      \\findindex{X \\cap \\infimum_X}{x}+1 & \\text{if~} x \\neq \\infimum_X \\\\\n    \\end{array}\n    \\right.\n  \\]\n\\end{definition}\n\nIn this thesis we use the following metrics:\n\\begin{definition}[\\oocover]\n  The recall of the set of proof dependencies by the first 100 suggestions is defined as\n  \\[ \\oocoverf{r}{s} = \\frac{ |\\topn{100}{r} \\bigcap \\required[s]| } { |\\required[s]| } \\]\n  This is our primary metric for evaluating the performance of our premise selection algorithms.\n  An higher recall is better.\n\\end{definition}\n\n\\begin{definition}[\\ooprecision]\n  The precision of the set of proof dependencies by the first 100 suggestions is defined as\n  \\[ \\ooprecisionf{r}{s} = \\frac{ |\\topn{100}{r} \\bigcap \\required[s]| } { |\\topn{100}{r}| } \\]\n  An higher precision is better.\n  Typically by making less suggestions a better precision is achieved.\n  For the corpii we evaluated most of our algorithms yield more than 100 suggestions per proof goal.\n  Thus this metric should often yield around the same value for differing algorithms.\n\\end{definition}\n\n\\begin{definition}[\\recall]\n  The \\recall is defined to be the number of guesses that were made until the entire set of required dependencies is suggested.\n  When the set of guesses does not include all required dependencies $\\recallf{r}{s}$ yields $|\\suggestions{r}|+1$,\n  or the number of suggestions plus one.\n  The function `$\\firstsym$' is defined in Definition \\ref{def:first}.\n  \\[ \\recallf{r}{s} = \\firstsym(\\lambda i. (i \\leq |\\suggestions{r}|) \\rightarrow \\required[s] \\subseteq \\topn{i}{r}) \\]\n  A lower \\recall is better.\n\\end{definition}\n\n\\begin{definition}[\\rank]\n  The \\rank is defined to be the average position of an actual proof dependency in the sequence of suggestions ordered by predicted relevance.\n  \\[ \\rankf{r}{s} = \\frac{\n      \\sum\\limits_{r \\in \\required[s]} \\left\\{\n        \\begin{array}{ll}\n          \\findindex{\\suggestions{s}}{r} & \\text{if~} r \\in \\suggestions{s} \\\\\n          0 & \\text{otherwise} \\\\\n        \\end{array}\n        \\right.\n    }{\n      |\\suggestions{r} \\bigcap \\required[s]|\n    }\n  \\]\n  A lower \\rank is better.\n\\end{definition}\n\n\\begin{definition}[Area Under Curve (AUC)]\n  The area under the ROC Curve is defined to be the probability that a correctly suggested premise is ranked \\emph{better} than an incorrectly suggested premise.\n  Given $X$ to be the correctly suggested premises $X = \\suggestions{r} \\bigcap \\required[s]$ and $Y$ to be the incorrectly suggested premises $Y = \\suggestions{r} - \\required[s]$ we define the \\auc to be:\n  \\[\n    \\aucf{r}{s} = \\frac{\n      \\sum_x^X \\sum_y^Y {\\findindex{\\suggestions{s}}{x} < \\findindex{\\suggestions{s}}{y}}\n    }{\n      |X| \\times |Y|\n    }\n  \\]\n  An higher AUC indicates a better performance.\n\\end{definition}\n\n\\begin{definition}[\\volume]\n  The volume is defined to be the number of suggestions made by a predictor.\n  From a runtime performance standpoint it is better to make less suggestions, with the risk of missing relevant facts.\n  When just the first 100 suggestions are looked at, this metric is of limited importance.\n  \\[\n    \\volumef{r}{s} = |\\suggestions{s}|\n  \\]\n\\end{definition}\n\nWhen reporting these metrics for the entire testset \\testset~the average is taken for every computed prediction.\nTechnically we are then refering to the Mean \\recall and Mean \\rank, but for simplicity sake we will refer to\njust '\\recall' in the following sections when talking about the results for entire testsets.\n\n\\subsubsection{Varying terminology}\nThis thesis uses concepts from both the \\ltr academic field (such as with \\adarank)\nas the premise selection / ATP with machine learning fields (as with the work by Kaliszyk).\nHowever between these fields the terminology used is not always consistent.\nThis is especially the case for the metrics used, as some cross polination has occurred between the fields,\nbut where differing concepts have ended up with the same name.\nTo clarify this I've tabularized the terms used:\n\n\\begin{figure}[H]\n  \\centering\n  \\begin{tabular}{l|l}\n  \\ltr          & \\emph{ATP with Machine Learning} \\\\\\hline\n  \\oocover      & 100Cover \\\\\n  \\ooprecision  & 100Precision \\\\\n  \\recall       & Recall \\\\\n  \\rank         & Rank \\\\\n  \\auc          & \\auc \\\\\n  \\end{tabular}\n  \\caption{The varying terminology used between academic fields.}\n\\end{figure}", "meta": {"hexsha": "4510d98f0f589c1649715c06654edc80c69933af", "size": 5634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/thesis/document-approach-metrics.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-metrics.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-metrics.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": 46.1803278689, "max_line_length": 205, "alphanum_fraction": 0.7014554491, "num_tokens": 1550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6554067931326734}}
{"text": "\\section{Relations}\\label{Relations}\n\nThis library develops closure properties of relations.\n\n\\begin{itemize}\n\\item {\\tt Relation\\_Definitions.v} deals with the general notions\n  about binary relations (orders, equivalences, ...)\n\n\\item {\\tt Relation\\_Operators.v} and {\\tt Rstar.v} define various\n  closures of relations (by symmetry, by transitivity, ...) and\n  lexicographic orderings.\n\n\\item {\\tt Operators\\_Properties.v} states and proves facts on the\n  various closures of a relation.\n\n\\item {\\tt Relations.v} puts {\\tt Relation\\_Definitions.v}, {\\tt\n    Relation\\_Operators.v} and \\\\\n    {\\tt Operators\\_Properties.v} together.\n\n\\item {\\tt Newman.v} proves Newman's lemma on noetherian and locally\n  confluent relations.\n\n\\end{itemize}\n", "meta": {"hexsha": "5056f36f9762ba33e48d11404ee0ee84668cd5a8", "size": 743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Resources/coq-8.3pl2/theories/Relations/intro.tex", "max_stars_repo_name": "mzp/coq-for-ipad", "max_stars_repo_head_hexsha": "4fb3711723e2581a170ffd734e936f210086396e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-01-27T00:11:26.000Z", "max_stars_repo_stars_event_max_datetime": "2015-01-27T00:11:26.000Z", "max_issues_repo_path": "Resources/coq-8.3pl2/theories/Relations/intro.tex", "max_issues_repo_name": "mzp/coq-for-ipad", "max_issues_repo_head_hexsha": "4fb3711723e2581a170ffd734e936f210086396e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Resources/coq-8.3pl2/theories/Relations/intro.tex", "max_forks_repo_name": "mzp/coq-for-ipad", "max_forks_repo_head_hexsha": "4fb3711723e2581a170ffd734e936f210086396e", "max_forks_repo_licenses": ["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.9583333333, "max_line_length": 68, "alphanum_fraction": 0.7456258412, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759128, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6553295939313579}}
{"text": "% -*- TeX-master: \"master.tex\" -*-\n\n\\setcounter{section}{8}\n\\setcounter{subsection}{0}\n\\subsection{Function objects, Exponentials}\n\n\\subsubsection{Function objects}\n\nFunctions are separated from types so far: we learned in Hask that types are\nobjects and functions are morphisms. For category $\\Set$, objects are all the\nsets, and functions are mapping between the objects. Functions from object $a$\nto object $b$ forms a set, called hom-set, denoted as $\\Hom(a,b)$. And because\n$\\Set$ contains all sets, this morphisms representing hom-set $\\Hom(a,b)$ is also\nan object in $\\Set$.\n\nIn an arbitrary category, we don't have the hom-sets as internal objects; but we\ncan view them as external things being in other categories. What we want is\nsomething we can represent these hom-sets inside the category. It is indeed\npossible to define these objects in many categories, although not in arbitrary\ncategory. Just like we define product and coproduct, the same way we can apply\nto define this function object. We can use univeral construction to define\nfunction object.\n\n\\begin{remark} The 3 steps towards universal construction:\n\\begin{enumerate}\n\\item Define a pattern.\n\\item Define ranking between matches.\n\\item Find the best one.\n\\end{enumerate}\n\\end{remark}\n\nIt's clear to see that the pattern will involve three objects, the function $z$,\nthe argument type $a$ and the return type $b$. In a category, we can't directly\nsay $z$ takes argument $a$ returns $b$, so we think how can we work on this. For\nexample, in category $\\Set$, we can say take $z$ and $a$ to form a pair $(z,a)$\nsuch that $(z,a) \\iso b$. This pairing in $\\Set$ represent a cartesian product\nof $z$ and $a$. This perfectly captures the idea of function application, and\nthis pattern can be generalize to any category.\n\nThis pattern implies that in order to define this construction in a category,\nthe category must contain products. This makes more sense when later we discuss\nfunction objects as exponentials.\n\nThe pattern, drawn in communitive diagram, looks like:\n\n\\begin{center}\n  \\begin{tikzcd}[sep=large]\n  z \\rar[dash,dashed] & z\\times a \\rar[swap]{g} & b  \\\\\n  & a \\uar[dash, dashed] &\n  \\end{tikzcd}\n\\end{center}\n\nNote that the morphism $g$ is called a \\emph{eval} morphism. Next we need to\ndefine a ranking to select the best function $z$ from $a$ to $b$.\n\n\\newcommand{\\arb}{\\ensuremath{}(a\\Rightarrow{}b)}\n\nWith the pattern above, we say $\\arb$ is the function object from $a$ to $b$ if\nfor other patterns defined on $z$ and $a$, we have a unique morphism $h:\n\\cd{z\\rar[dashed] \\& \\arb}$, that means we have to be able to factorize\n$g:\\cd{z\\times a\\rar\\& b}$ into $\\textrm{eval}$ arrow and a unique arrow\n$\\cd{z\\times a\\rar[dashed] \\&\\arb\\times a}$. $\\textrm{eval}$ arrow is given by\nthe pattern, so we need to find the other arrow. By previously learned\nfunctoriality of ADTs, we know that product is a bifunctor, thus it not only\nmaps objects, it also maps morphisms. By which we can say the unique arrow we\nare looking for is $h\\times \\id_a$. The whole construct can be shown as the\ndiagram below:\n\n\\begin{center}\n  \\begin{tikzcd}[sep=large]\n    z  \\dar[dashed]{h} &\n    z\\times a \\ar{d}[dashed]{h\\times \\id_a} \\ar[rd, start anchor={east}, bend left=30, \"g\"] & \\\\\n\n    (a\\Rightarrow b)  &\n    (a\\Rightarrow b)\\times a \\ar[r,swap,start anchor={east},\"\\textrm{eval}\"] & b  \\\\\n\n    & a  &\n  \\end{tikzcd}\n  \\\\\n  (arrows representing $\\pi$ maps in products are omitted for clarity)\n\\end{center}\n\n\nIn short, the function object $\\arb$ only exists if for every possible $z$ and\n$g$ in that pattern, there is a unique $h$ from $z$ to $\\arb$ such that:\n\n\\[\n  g = \\textrm{eval} \\circ (h \\times \\id)\n\\]\n\nIn most languages, functions with two arguments are basically functions with one\nargument which is a pair. Think of $g$ as such a function, that takes $z$ and\n$a$ as arguments. Our definition of function objects implies given $z$ and $g$\nwe actually have a unique arrow $h$, that takes a $z$ and returns a function\nobject $\\arb$.\n\nThis captures the idea of partially applying function is\nequivalent to the applying function with its arguments given in a pair; the idea\ncan be generalized to functions with multiple arguments. This gives rise to the\nconcept of currying.\n\n\\begin{lstlisting}\nh :: z -> (a -> b)\ng :: (z, a) -> b\n\ncurry :: ((a,b)->c) -> (a->b->c)\ncurry f = \\lambdaa->(\\lambdab->f (a,b))\n\nuncurry :: (a->b->c) -> ((a,b)->c)\nuncurry f = \\lambda(a,b)->(f a) b\n\\end{lstlisting}\n\n\n\\subsubsection{Exponential}\n\nFunction objects in category theory are actually called exponential. A function\nobject $\\arb$ will be called $b^a$. This makes sense if you think of the\ncardinality of function types. In Haskell, $\\Bool \\to \\Int$ is basically $(\\Int,\n\\Int)$, or $\\Int \\times \\Int$ in category notation, or simpler $\\Int^2$.\nRemember we learned the correspondence between nature numbers and Hask types:\n$1$ corresponds to unit $()$, $2$ corresponds to $\\Bool$, etc. Then $\\Int^2$ is\nbasically $\\Int^\\Bool$.\n\nThe idea shows the connection between products and exponentials (\\ie.\nfunctions). A special kind of categories called \\textbf{Cartesian Closed\n  Category} (CCC) is useful in programming. Cartesian means there is a product\nfor every pair of objects. Closed means the products are \\emph{inside} the\ncategory, which means it has all the exponentials objects as well. Also, it must\nhave the terminal object. Why? Terminal object is like the $0$-th power of any\nobjects. Sometimes we also want co-products in the category, this kind of\ncategories is called Bi-Cartesian Closed Categories (BCCC), which also has the\ninitial object.\n\nWith products and co-products both being monoidal, we can combine them together\nto form a semi-ring, and do algebra on them. Now we add exponential to the\nsystem. With exponentials we can do more algebra, for example, $a^0~=~1$.\n\nWe can interpret $a^0 = 1$ as $\\Void \\to a \\sim ()$, \\ie. a function from void\ntype to $a$ is equivalent to the unit type. We need to show the function on the\nleft hand side exists and is unique. Turns out there is this function, called\n\\textbf{absurd}.\n\nWhat about $1^a=1$? It is a function takes $a$ and returns unit $()$; we say it\nis equivalent to just $()$. There is only one such function indeed, called\n$\\texttt{const}~()$.\n\nLet's try another one, $a^1=a$, This is saying a function from $()$ to $a$ is\nequivalent to $a$. These functions are just the selecting functions; there are\nas many as the number of elements in $a$.\n", "meta": {"hexsha": "65c451cdcdd867bd15dadce95842b463b436a404", "size": 6473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "milewski-cat/chap8.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/chap8.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/chap8.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": 43.1533333333, "max_line_length": 96, "alphanum_fraction": 0.7259385138, "num_tokens": 1800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6553012628906297}}
{"text": "\\subsection{Potential Matching Weight}\\label{sec:matchingweight}\n\n\\Figure[bt](topskip=0pt, botskip=0pt, midskip=0pt){figures/tikz/build/main-figure0.pdf}{\n    A cluster with vertices $\\{a,b,c\\}$ with potential matching weights $\\{2\\frac{1}{2}, 3\\frac{1}{2}, 2\\frac{1}{2}\\}$. The line style and color of the colored edges correspond to the matching in the hypothetical union with an external vertex $v'$ of the same line style and color.\\label{fig0}}\n\n%In the following we give some intuition into the improvement of the Union-Find Balanced Bloom decoder upon the original Union-Find decoder. \n% We compared the ratio of the matchings between the MWPM decoder and our own implementation of the UF decoder, averaged over many simulations, and found that UF matching weight has a constant prefactor of $\\sim 1.043$ over the minimum weight for the toric code (\\Cref{comp_weight}). From this, we suspected that a decreased matching weight is a heuristic for an increased threshold. Within the context of the UF decoder, the matching weight may be decreased by prioritizing the growth of vertices with low PWM's within the cluster. \n\n\\textcolor{cyan}{Let a \\emph{matching} in an cluster be a pairing between its syndrome vertices, such that every syndrome pair is connected via uniquely occupied edges in the cluster. The \\emph{matching weight} is the total number of occupied edges in the matching.} Consider a cluster containing the set of an odd number of non-trivial vertices $V=\\{a,b,c\\}$ and the set of edges $E=\\{(a,b), (b, c)\\}$ of \\Cref{fig0}. Now let us investigate the weight of a matching if an additional non-trivial vertex $w$ is connected to the cluster. If $w$ is connected to $a$ or to $c$, then the resulting matching has a total weight of 2: $(w,a)$ and $(b,c)$, or $(a,b)$ and $(c,w)$. However, if $w$ is connected to vertex $b$, then the total weight is 3: $(w, b)$ and $(a, c)$. %If we want to minimize the weight of the \n\nInspired by this observation, we associate with each vertex $v$ of an odd-parity cluster a \\textbf{Potential Matching Weight} $\\text{PMW}(v)$. The PMW measures the matching weight, assuming a union occurs in the next growth iteration. More precisely,\n%\\begin{definition}\n    % define cluster\n    % define matching size or weight\nlet $v$ be a vertex in the boundary of an odd cluster and let $w$ be a hypothetical non-trivial vertex adjacent to $v$ but exterior to the cluster. We define $\\text{PMW}(v)$ as the minimum-weight perfect-matching's weight of the even cluster that results from adding the $(v,w)$ vertex to the odd cluster. % is given by the \n    %Let there be a hypothetical merger between odd cluster $\\alpha$ of vertices $V_\\alpha$ and edges $E_\\alpha$, and odd cluster $\\beta$ of $V_\\beta$ and $E_\\beta$, on the edge $(v_\\alpha, v_\\beta)$, where $v_\\alpha \\in V_\\alpha$ and $v_\\beta \\in V_\\beta$. In the merged even cluster with edges $E_{\\gamma} = E_\\alpha \\cup E_\\beta \\cup (v_\\alpha, v_\\beta)$, there is a matching $\\m{C}_{(v_\\alpha,v_\\beta)} \\subseteq E_{\\gamma}$  between the syndrome vertices internal to the cluster. The \\textbf{Potential Matching Weight} (PMW) of vertex $v_\\alpha$ is then defined as\n    %\\begin{equation}\n      %\\text{PMW}(v) = \\abs{\\m{C}_{(v_\\alpha,v_\\beta)} \\cap E_\\alpha} + 1.\n     % \\text{PMW}(v) = \\abs{\\m{C'}}.\n    %\\end{equation}\n    %\\end{definition}\n    \nSince per growth iteration half-edges are attached to the odd cluster's boundary, the addition of an edge $(v,w)$ to a cluster occurs in two steps. In the first step, half of $(v,w)$ is added to the cluster of $v$. If $w$ is part of another cluster, and if the other half of $(v,w)$ was already added to the cluster of $w$, $(v,w)$ becomes \\emph{fully grown}. If this is not the case, another round of growth is required to fully grow $(v,w)$ and to merge the clusters of $v$ and $w$. The PWM of $v$ is identical in both cases. To distinguish between the two cases, we add $\\nicefrac{1}{2}$ to the PMW's of vertices with half-edges attached. Using this definition, the vertices $\\{a,b,c\\}$ in the cluster shown in \\Cref{fig0} have PMW's $\\{2\\nicefrac{1}{2}, 3\\nicefrac{1}{2}, 2\\nicefrac{1}{2}\\}$. The PMW can be used to prioritize the growth of vertices with low PMW such that there is an increased probability of mergers between clusters on edges connected to these vertices, and there is an increased probability of a lower matching weight. However, this heuristic is only interesting if the calculation of the PMW's is lighter computationally than performing minimum-weight perfect-matching. %within a cluster is potentially , especially for clusters of increasingly larger size, as all edges of a cluster must be considered in its calculation. Furthermore, the PMWs within a cluster change due to cluster growth and mergers, both of which occur more frequently as the system size increases. For this reason, the scaling of the PMW computation is vital to the decoder. \n\n\n\\Figure[bt](topskip=0pt, botskip=0pt, midskip=0pt){figures/tikz/build/main-figure1.pdf}{\n    The cluster of \\Cref{fig0}, comprised of nodes $\\{A, B, C\\}$ with respective roots $\\{a, b, c\\}$, after two rounds of prioritized growth of $a$ and $c$. There are regions of vertices that are either interior elements or have equal potential matching weights, represented as nodes with different node radii (labelled below the node) in the node-tree $\\nset$. \\label{fig:pmw}}\n", "meta": {"hexsha": "a4cd1db94977eac0a0245c43a932167f9e66551f", "size": 5387, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sec_algo_a_pwm.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_a_pwm.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_a_pwm.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": 192.3928571429, "max_line_length": 1572, "alphanum_fraction": 0.7397438277, "num_tokens": 1422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6553012587997916}}
{"text": "\n\\section{MacDonald's solution: transcritical flow with a shock}\n\nThis is a MacDonald's steady flow test involving a shock in a short channel. This test was used by Delestre et al.~\\cite{Delestre-etal2012} in their \\textsc{SWASHES} benchmark library of shallow water analytical solutions. The original derivation of the analytical solution was given by MacDonald et al.~\\cite{MBNS1995, MBNS1997}.\nMacDonald's analytical solution was derived using a backward framework, that is: given the water depth, we construct the topography which satisfies the shallow water equations.\n\nWhen water is in a steady state, we have a fixed depth and velocity with respect to time. Consider a one dimensional domain. Suppose that we are given the depth $h(x)$. The steady state conditions make the shallow water equations to the single identity\n\\begin{equation}\nz_x = \\left(  \\frac{q^2}{gh^3} -1 \\right) h_x - S_f\n\\end{equation}\nwhere $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}\nThe topography is then determined by\n\\begin{equation}\nz(x) = -\\int_{x}^{L} z_x~dx\n\\end{equation}\nin which $L$ is the channel length.\n\n\\subsection{Results}\n\nFor our test, suppose that the channel length $L = 100$ and at steady state the discharge $q = 2$. The initial condition is $u=v=0$ and $w=2.87870797$. The boundary condition is enforced such that the upstream boundary has $q=2$ and the downstream boundary has $h=3.58431872$. When water is steady, suppose that a shock occurs at $x=66\\frac23$. Following Delestre et al.~\\cite{Delestre-etal2012}, we consider the water depth\n\\begin{equation}\nh(x,y)= \\left\\{ \\begin{array}{ll}\n       \\left( \\frac{4}{g}\\right)^{1/3} \n       \\left(\\frac43 - \\frac{x}{100}  \\right) - \\frac{9x}{1000} \\left( \\frac{x}{100} -\\frac23 \\right)\n        & ~\\textrm{if}\\quad 0 \\leq x < 66\\frac23\\\\\n        ~~ & ~~ \\\\\n       \\left( \\frac{4}{g}\\right)^{1/3}\n       \\left[ a_1\\left( \\frac{x}{100} -\\frac23 \\right)^4 +a_1\\left(  \\frac{x}{100} -\\frac23 \\right)^3 \\right.\\\\\n       \\left. \\quad -a_2 \\left( \\frac{x}{100} -\\frac23 \\right)^2 + a_3 \\left( \\frac{x}{100} -\\frac23 \\right) +a_4\\right] \n       & ~\\textrm{if}\\quad 66\\frac23 \\leq x \\leq 100\\\\\n\\end{array} \\right.\n\\end{equation} \nwhere \n$a_1 = 0.674202$, \n$a_2 = 21.7112$, \n$a_3 = 14.492$, \n$a_4 = 1.4305$, and \n$n  = 0.0328$.\n\n\nThe following three figures show the stage, $x$-momentum, and $x$-velocity when water is steady. We should see excellent agreement between the analytical and numerical 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": "4f4a94eaabe7fc8e82c68fb9b3dc5a55ec8547cf", "size": 3039, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "validation_tests/analytical_exact/mac_donald_short_channel/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/mac_donald_short_channel/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/mac_donald_short_channel/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": 42.8028169014, "max_line_length": 424, "alphanum_fraction": 0.7091148404, "num_tokens": 980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6552529484887581}}
{"text": "\\subsection{Rogue Key Attack}\r\n\r\nWhen Schnorr signatures are used to generate an aggregated signature of a transaction they are vulnerable to an attack known as Rogue Key attack. Rogue Key attacks performed by a malicious entity consists of generating an aggregated signature in such a way that they posses the public/private key pair for that signature. In the Schnorr signature scheme, the public key of participants are aggregated and the sum represent the public key associated to the signature. Assume that an honest participant use its public key $Q_a$ in the transaction and a malicious participant possesses $Q_b$. By sending the public key $Q_m = Q_b - Q_a$ to the honest participant, the malicious entity have access to the transaction as they will hold the private key for $Q_b$. This is because when the keys are aggregated i.e. $Q_m + Q_b$ the aggregated signature would be $Q_b$, for which the malicious user holds the private key (the honest user would not). For an aggregated public key, there should be no user that has a private key equivalent as it should be used to create a signature that can be verified that all users in the transaction participated. \\\\ \t\r\n\r\nThe aggregation of public keys used in Catalyst which is based on Mu-Sig \\cite{musig} signature scheme that is not vulnerable to this form of attack. Mu-Sig is protected from this form of attack as the scheme does not require a user to demonstrate each public key, only the sum of all the public keys. By not verifying individual public keys, a key rogue attack is not possible. Only one public key is needed for the verification (the aggregated key) for which there will not be an equivalent private key.\r\n\r\n\\subsection{Quantum Attack}\r\n\r\nQuantum computers pose a very real threat to the encryption techniques used in blockchains in the medium to long term \\cite{agarwal}. The threat is through the use of Shor's algorithm. A quantum attacker using Shor's algorithm on a quantum computer can gain an exponential speed-up in solving the discrete logarithmic problem. The assumption of security the discrete logarithmic functions the the primary basis as to which all elliptic curve cryptography is based. This means that even the schema demonstrated here will be vulnerable to attack. The use of aggregated signatures would provide some resistance, however this resistance would be negligible. \\\\\r\n\r\nIt must be impressed that this is not an issue for the near term and thereby, these schema are highly secure and efficient currently. The most efficient algorithm for classical computers to solve the discrete logarithm problem is the Pollard's rho\\cite{pollard}, this does not run in polynomial time. While Catalyst is not currently resistant to quantum attack, this is a challenge that will be faced by all major distributed ledgers over time. ", "meta": {"hexsha": "46fae13e3dbb048d5a61d70493e5d93727fd7d21", "size": 2827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper-tex-files/security/signature-scheme/signature-scheme.tex", "max_stars_repo_name": "Atlas3T/consensus-whitepaper", "max_stars_repo_head_hexsha": "68cc6e4938ae266e964448a513d471cc48622fe2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper-tex-files/security/signature-scheme/signature-scheme.tex", "max_issues_repo_name": "Atlas3T/consensus-whitepaper", "max_issues_repo_head_hexsha": "68cc6e4938ae266e964448a513d471cc48622fe2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper-tex-files/security/signature-scheme/signature-scheme.tex", "max_forks_repo_name": "Atlas3T/consensus-whitepaper", "max_forks_repo_head_hexsha": "68cc6e4938ae266e964448a513d471cc48622fe2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-10T10:42:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-21T19:12:41.000Z", "avg_line_length": 257.0, "max_line_length": 1146, "alphanum_fraction": 0.8036788115, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6552200641835294}}
{"text": "\\BoSSSopen{shortTutorialMatlab/tutorialMatlab}\n\\graphicspath{{shortTutorialMatlab/tutorialMatlab.texbatch/}}\n\n\\BoSSScmd{\n/// In this short tutorial we want to use common Matlab commands within the \\BoSSS{} framework.\n/// \\section{Problem statement}\n/// For our matrix analysis we use the following random matrix:\n/// \\begin{equation*}\n/// A = \\begin{bmatrix}\n///      1 & 2 & 3\\\\\n///      4 & 5 & 6\\\\\n///      7 & 8 & 9\n///     \\end{bmatrix}\n/// \\end{equation*}\n/// and the symmetric matrix:\n/// \\begin{equation*}\n/// S = \\begin{bmatrix}\n///      1 & 2 & 3\\\\\n///      2 & 3 & 2\\\\\n///      3 & 2 & 1\n///      \\end{bmatrix}\n/// \\end{equation*}\n/// We are going to evaluate some exemplary properties of the matrices and check if the matrices are symmetric, both in the \\BoSSS{} framework and in Matlab.\n/// \\section{Solution within the \\BoSSS{} framework}\n/// First, we have to initialize the new project:\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nrestart;\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nusing ilPSP.LinSolvers;\\newline \nusing ilPSP.Connectors.Matlab;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We want to implement the two 3x3 matrices in \\BoSSSpad{}:\nint Dim     = 3;\\newline \nMsrMatrix A = new MsrMatrix(Dim,Dim);\\newline \nMsrMatrix S = new MsrMatrix(Dim,Dim);\\newline \ndouble[] A\\_firstRow = new double[]\\{1,2,3\\};\\newline \ndouble[] A\\_secondRow = new double[]\\{4,5,6\\};\\newline \ndouble[] A\\_thirdRow = new double[]\\{7,8,9\\};\\newline \n \\newline \ndouble[] S\\_firstRow = new double[]\\{1,2,3\\};\\newline \ndouble[] S\\_secondRow = new double[]\\{2,3,2\\};\\newline \ndouble[] S\\_thirdRow = new double[]\\{3,2,1\\};\\newline \n \\newline \nfor(int i=0; i<Dim; i++)\\{\\newline \n\\btab A[0, i] = A\\_firstRow[i];\\newline \n\\btab S[0, i] = S\\_firstRow[i];\\newline \n\\}\\newline \n \\newline \nfor(int i=0; i<Dim; i++)\\{\\newline \n\\btab A[1, i] = A\\_secondRow[i];\\newline \n\\btab S[1, i] = S\\_secondRow[i];\\newline \n\\}\\newline \n \\newline \nfor(int i=0; i<Dim; i++)\\{\\newline \n\\btab A[2, i] = A\\_thirdRow[i];\\newline \n\\btab S[2, i] = S\\_thirdRow[i];\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Test for symmetry in \\BoSSS{}:}$~~$\\\\\n/// To analyze if the matrices are symmetric, we need to compare the original matrix with the transpose:\nMsrMatrix AT    = A.Transpose();\\newline \nMsrMatrix ST    = S.Transpose();\\newline \nbool SymmTest\\_A;\\newline \nbool SymmTest\\_S;\\newline \nfor(int i = 0; i<Dim; i++)\\{\\newline \n\\btab for(int j = 0; j<Dim; j++)\\{\\newline \n\\btab \\btab if(A[i,j] == AT[i,j])\\{\\newline \n\\btab \\btab \\btab SymmTest\\_A = true;\\newline \n\\btab \\btab \\btab \\}\\newline \n\\btab \\btab else\\{\\newline \n\\btab \\btab \\btab SymmTest\\_A = false;\\newline \n\\btab \\btab \\btab break;\\newline \n\\btab \\btab \\btab \\}\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \nfor(int i = 0; i<Dim; i++)\\{\\newline \n\\btab for(int j = 0; j<Dim; j++)\\{\\newline \n\\btab \\btab if(S[i,j] == ST[i,j])\\{\\newline \n\\btab \\btab \\btab SymmTest\\_S = true;\\newline \n\\btab \\btab \\btab \\}\\newline \n\\btab \\btab else\\{\\newline \n\\btab \\btab \\btab SymmTest\\_S = false;\\newline \n\\btab \\btab \\btab break;\\newline \n\\btab \\btab \\btab \\}\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \nif(SymmTest\\_A == true)\\{\\newline \nConsole.WriteLine(\"Matrix A seems to be symmetric.\");\\newline \n\\}\\newline \nelse\\{\\newline \nConsole.WriteLine(\"Matrix A seems NOT to be symmetric.\");\\newline \n\\}\\newline \nif(SymmTest\\_S == true)\\{\\newline \nConsole.WriteLine(\"Matrix S seems to be symmetric.\");\\newline \n\\}\\newline \nelse\\{\\newline \nConsole.WriteLine(\"Matrix S seems NOT to be symmetric.\");\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{The interface to Matlab:}$~~$\\\\\n/// The \\code{BatchmodeConnector} initializes an interface to Matlab:\nConsole.WriteLine(\"Calling MATLAB/Octave...\");\\newline \nBatchmodeConnector bmc = new BatchmodeConnector();\\newline \n/// We have to transfer out matrices to Matlab:\nbmc.PutSparseMatrix(A, \"Matrix\\_A\");\\newline \nbmc.PutSparseMatrix(S, \"Matrix\\_S\");\\newline \n/// Now we can do calculations in Matlab within the \\BoSSSpad{} using the \\code{Cmd} command. It commits the Matlab commands as a string. We can calculate e.g. the rank of the matrix or the eigenvalues:\nbmc.Cmd(\"Full\\_A = full(Matrix\\_A)\");\\newline \nbmc.Cmd(\"Full\\_S = full(Matrix\\_S)\");\\newline \nbmc.Cmd(\"Rank\\_A = rank(Full\\_A)\");\\newline \nbmc.Cmd(\"Rank\\_S = rank(Full\\_S)\");\\newline \nbmc.Cmd(\"EV\\_A = eig(Full\\_A)\");\\newline \nbmc.Cmd(\"EV\\_S = eig(Full\\_S)\");\\newline \nbmc.Cmd(\"Det\\_A = det(Full\\_A)\");\\newline \nbmc.Cmd(\"Det\\_S = det(Full\\_S)\");\\newline \nbmc.Cmd(\"Trace\\_A = trace(Full\\_A)\");\\newline \nbmc.Cmd(\"Trace\\_S = trace(Full\\_S)\");\\newline \n/// We can transfer matrices or arrays from Matlab to \\BoSSSpad{} as well, here we want to have the results:\nMultidimensionalArray Results = MultidimensionalArray.Create(2, 3);\\newline \nbmc.Cmd(\"Results = [Rank\\_A, Det\\_A, Trace\\_A; Rank\\_S,  Det\\_S,  Trace\\_S]\");\\newline \nbmc.GetMatrix(Results, \"Results\");\\newline \n/// and the eigenvalues:\nMultidimensionalArray EV\\_A = MultidimensionalArray.Create(3, 1);\\newline \nbmc.GetMatrix(EV\\_A, \"EV\\_A\");\\newline \nMultidimensionalArray EV\\_S = MultidimensionalArray.Create(3, 1);\\newline \nbmc.GetMatrix(EV\\_S, \"EV\\_S\");\\newline \n/// After finishing using Matlab we need to close the interface to Matlab:\nbmc.Execute(false);\\newline \nConsole.WriteLine(\"MATLAB/Octave closed, return to BoSSSPad\");\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// And here are our results back in the \\BoSSSpad{}:\ndouble Rank\\_A  = Results[0,0];\\newline \ndouble Rank\\_S  = Results[1,0];\\newline \ndouble Det\\_A   = Results[0,1];\\newline \ndouble Det\\_S   = Results[1,1];\\newline \ndouble Trace\\_A = Results[0,2];\\newline \ndouble Trace\\_S = Results[1,2];\\newline \nConsole.WriteLine(\"The results of matrix A are: rank: \" + Rank\\_A + \", trace: \" + Trace\\_A + \", dterminant: \" + Det\\_A);\\newline \nConsole.WriteLine(\"The results of matrix S are: rank: \" + Rank\\_S + \", trace: \" + Trace\\_S + \", determinant: \" + Det\\_S);\\newline \nConsole.WriteLine();\\newline \nConsole.WriteLine(\"The eigenvalues of matrix A are: \" + EV\\_A[0,0] + \", \" + EV\\_A[1,0] + \" and \" + EV\\_A[2,0]);\\newline \nConsole.WriteLine(\"The eigenvalues of matrix S are: \" + EV\\_S[0,0] + \", \" + EV\\_S[1,0] + \" and \" + EV\\_S[2,0]);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Test for symmetry within Matlab using the \\code{BatchmodeConnector}:}$~~$\\\\\n/// We do the same test for symmetry for both matrices. In Matlab we can use the convenient command \\code{isequal}:\nConsole.WriteLine(\"Calling MATLAB/Octave...\");\\newline \nBatchmodeConnector bmc = new BatchmodeConnector();\\newline \nbmc.PutSparseMatrix(A, \"Matrix\\_A\");\\newline \nbmc.PutSparseMatrix(S, \"Matrix\\_S\");\\newline \nbmc.Cmd(\"Full\\_A = full(Matrix\\_A)\");\\newline \nbmc.Cmd(\"Full\\_S = full(Matrix\\_S)\");\\newline \nbmc.Cmd(\"A\\_Transpose = transpose(Full\\_A)\");\\newline \nbmc.Cmd(\"S\\_Transpose = transpose(Full\\_S)\");\\newline \nbmc.Cmd(\"SymmTest\\_A = isequal(Full\\_A, A\\_Transpose)\");\\newline \nbmc.Cmd(\"SymmTest\\_S = isequal(Full\\_S, S\\_Transpose)\");\\newline \n \\newline \nMultidimensionalArray SymmTest\\_A = MultidimensionalArray.Create(1, 1);\\newline \nbmc.GetMatrix(SymmTest\\_A, \"SymmTest\\_A\");\\newline \nMultidimensionalArray SymmTest\\_S = MultidimensionalArray.Create(1, 1);\\newline \nbmc.GetMatrix(SymmTest\\_S, \"SymmTest\\_S\");\\newline \nbmc.Execute(false);\\newline \nConsole.WriteLine(\"MATLAB/Octave closed, return to BoSSSPad\");\n }\n\\BoSSSexe\n\\BoSSScmd{\nif(SymmTest\\_A[0,0] == 1)\\{\\newline \nConsole.WriteLine(\"Matrix A seems to be symmetric.\");\\newline \n\\}\\newline \nelse\\{\\newline \nConsole.WriteLine(\"Matrix A seems NOT to be symmetric.\");\\newline \n\\}    \\newline \nif(SymmTest\\_S[0,0] == 1)\\{\\newline \nConsole.WriteLine(\"Matrix S seems to be symmetric.\");\\newline \n\\}\\newline \nelse\\{\\newline \nConsole.WriteLine(\"Matrix S seems NOT to be symmetric.\");\\newline \n\\}\n }\n\\BoSSSexe\n", "meta": {"hexsha": "afaf81017bcc26e0d8e4cb9835c2493d938ed018", "size": 7720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/handbook/shortTutorialMatlab/tutorialMatlab.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/shortTutorialMatlab/tutorialMatlab.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/shortTutorialMatlab/tutorialMatlab.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": 39.793814433, "max_line_length": 202, "alphanum_fraction": 0.6849740933, "num_tokens": 2552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.6552200538924822}}
{"text": "\\chapter{Function}\n\n\\section{Fractional iterate}\n\nGeneralize \\(f^p\\) for real \\(p\\).\n\\begin{align*}\n    f^2 &= f \\circ f\n    \\\\\n    f^{1/2} \\circ f^{1/2} &= f\n\\end{align*}\n\nIf \\(f~x = x \\uparrow a\\) then \\(f~(f~x) = (x \\uparrow a) \\uparrow a\\).\n\nWhat is a \\(g\\) that satisfies \\(g~(g~x) = x^a\\)?\n\nWhat does \\(d~(p \\to f^p)\\) even mean?\nThe \\(d\\) is differential operator.\n\n% http://math.stackexchange.com/questions/676229/fractional-composite-of-functions\n\n% https://en.wikipedia.org/wiki/Iterated_function#Fractional_iterates_and_flows.2C_and_negative_iterates\n", "meta": {"hexsha": "8635b8f1d337bdb96f0088b02b42b446396490cd", "size": 562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/function.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/function.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/function.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 25.5454545455, "max_line_length": 104, "alphanum_fraction": 0.6565836299, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759492, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6552122537384437}}
{"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{gdpower}\n\\section*{\\hspace*{-1.6cm} gdpower}\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 a power-law group delay.\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,gpd,f] = gdpower(N)\n[x,gpd,f] = gdpower(N,k)\n[x,gpd,f] = gdpower(N,k,c)\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 gdpower} generates a signal with a power-law group delay of\n        the form \\[t_x(f) = t_0 + c\\ f^{k-1}.\\] The output signal is of\n        unit energy.\\\\\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          (must be even)\\\\\n        {\\ty k}   & degree of the power-law           & {\\ty 0}\\\\\n        {\\ty c}   & rate-coefficient of the power-law group delay.  \n              {\\ty c} must be non-zero.               & {\\ty 1} \\\\  \n  \\hline {\\ty x}   & time row vector containing the signal samples\\\\\n        {\\ty gpd} & output vector containing the group delay samples, of\n\tlength {\\ty round(N/2)}\\\\ \n        {\\ty f}   & frequency bins\\\\\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Examples}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nConsider a hyperbolic group-delay law, and compute the Bertrand\ndistribution of it :\n\\begin{verbatim}\n         sig=gdpower(128); \n         tfrbert(sig,1:128,0.01,0.3,128,1);\n\\end{verbatim}\nWe note that the perfect localization property of the Bertrand distribution\non hyperbolic group-delay signals is checked in that case. \\\\\n\\end{minipage}\n\\newpage\n\\hspace*{1.5cm}\\begin{minipage}[t]{13.5cm}\nPlot the instantaneous frequency law on which the D-Flandrin distribution\nis perfectly concentrated :\n\\begin{verbatim}\n         [sig,gpd,f]=gdpower(128,1/2); \n         plot(gpd,f); \n         tfrdfla(sig,1:128,.01,.3,218,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}\nfmpower.\n\\end{verbatim}\n\\end{minipage}\n\n", "meta": {"hexsha": "087e0fa901e94dee34c4299af842ffe49fc4cc4d", "size": 2395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/gdpower.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/gdpower.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/gdpower.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": 25.4787234043, "max_line_length": 75, "alphanum_fraction": 0.6354906054, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6549865371811232}}
{"text": "\\section{Background and Notation} \\label{background_and_notation}\nThis section explains the basic sliding window technique as fundamental framework used in this thesis. Furthermore some\nbackground on the well known time series similarity measure DTW is given. The sliding window filter is expounded at the\nend of this section.\n\nA time series $Q$ with the length $l$ over the domain set $\\mathbb{U}$ is a sequence of data points\n$Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with $q_i \\in \\mathbb{U}$. A distance measure function $d$ with\n$d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$ exists on the set $\\mathbb{U}$. Furthermore basic arithmetic operations\nlike a summing function $\\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$ and a scalar multiplication\n$\\mathbb{R} \\times \\mathbb{U} \\to \\mathbb{U}$ should be defined on $\\mathbb{U}$. A common assumption for time series is\nthat the containing data points are elements of the integer numbers $\\mathbb{Z}$ or the real numbers $\\mathbb{R}$. The\ndistance measure function on these common domains is just the absolute value of the difference of two elements. A\nfundamental prerequisite for similarity measures on time series is often the distance measure function $d$ on the set\n$\\mathbb{U}$. Table~\\ref{tab:notation} explains the basic notation that is used in this bachelor thesis.\n\n\\begin{table}\n    \\begin{center}\n        \\begin{tabularx}{\\textwidth}{c X l}\n            \\hline\n            \\textbf{Symbol} \\qquad & \\textbf{Description} & \\qquad \\textbf{Section}\\\\\n            \\hline\n            $\\mathbb{U}$ & a set containing all items of a domain & \\qquad\\\\\n            $d$ & a distance measure function on $\\mathbb{U}$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$\n                & \\qquad\\\\\n            $Q$ & a time series over the set $\\mathbb{U}$ of size $l$ with\n                $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l), q_i \\in \\mathbb{U}$ & \\qquad\\\\\n            $Q[i,j]$ & a subsequence time series of $Q$ over the set $\\mathbb{U}$ with\n                $Q[i,j] = (q_i, q_{i+1}, \\dots, q_{j})$ & \\qquad\\\\\n            $t$ & the current time & \\qquad\\\\\n            $w$ & time series window size & \\qquad \\ref{sliding_window_technique}\\\\\n            $s$ & time series step size & \\qquad \\ref{sliding_window_technique}\\\\\n            $K_i$ & a class of time series & \\qquad\\\\\n            $\\epsilon_i$ & the distance threshold of class $K_i$ & \\qquad\\\\\n            DTW & Dynamic Time Warping, a similarity measure for time series & \\qquad \\ref{dynamic_time_warping}\\\\\n            $\\bar{q}$ & the mean of a time series $Q$ over the set $\\mathbb{U}$, $\\bar{q} \\in \\mathbb{U}$ & \\qquad\n                \\ref{time_series_normalization}\\\\\n            $\\sigma$ & the standard deviation of a time series $Q$ over the set $\\mathbb{U}$, $\\sigma \\in \\mathbb{R}$ &\n                \\qquad \\ref{time_series_normalization}\\\\\n            $\\eta$, $\\eta '$  & two different time series normalizations & \\qquad \\ref{time_series_normalization}\\\\\n            CE & Complexity Estimate & \\qquad \\ref{complexity_estimate}\\\\\n            LNCE & Length normalized Complexity Estimate & \\qquad \\ref{complexity_estimate}\\\\\n            VAR & Sample Variance & \\qquad \\ref{sample_variance}\\\\\n            \\hline\n        \\end{tabularx}\n    \\end{center}\n    \\caption{Basic notation.}\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\\input{background_and_notation/sliding_window_filter.tex}\n\\input{background_and_notation/complexity_estimate.tex}\n\\input{background_and_notation/sample_variance.tex}\n", "meta": {"hexsha": "019b6c6e77f1f360dc38b778f613bb4d3e71b7f1", "size": 3625, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/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": "bachelor-thesis/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": "bachelor-thesis/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": 65.9090909091, "max_line_length": 120, "alphanum_fraction": 0.6626206897, "num_tokens": 1034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789132480439, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.6549214389447079}}
{"text": "\\documentclass{article}\n\\usepackage{color}\n\\usepackage{bigints}\n\\usepackage[italicdiff]{physics}\n\\color{white}\n\\definecolor{Green}{RGB}{0,66,37}\n\\begin{document}\n\\pagecolor{Green}\n\\title{Solution to Mathemaddict\\textsc{\\char13}s Problem}\n\\author{Jose Bedoya}\n\\maketitle\n\\section{Question}\n{\\LARGE\n$$I = \\bigintss_{1}^{\\infty} \\frac{x^2-1}{x^4 \\ln x}\\, dx$$\n}\n\\section{Solution}\n\\vspace{5mm}\n{\\Large\nConsider the substitution $x \\rightarrow \\frac{1}{u}$\n$$ I = \\bigintsss_{0}^{1} \\frac{u^2-1}{\\ln u}\\,du$$\n\n\\vspace{5mm}\nLet\n$$ B\\left(\\alpha \\right) = \\bigintsss_{0}^{1} \\frac{x^{\\alpha} -1}{\\ln x}\\, dx$$\n\n\\vspace{3mm}\nNotice our desire integral is $B\\left(2\\right)$.\n\\newpage\nDifferentiate both sides,\n$$\\dv{B}{\\alpha} = \\dv{\\alpha}\\bigintsss_{0}^{1} \\frac{x^{\\alpha}-1}{\\ln x}\\, dx$$\n\n\\vspace{3mm}\nBy the Leibniz rule for integrals\n$$\\dv{B}{\\alpha}=\\bigintsss_{0}^{1}\\pdv{\\alpha}\\frac{x^{\\alpha}-1}{\\ln x}\\, dx$$\n\n\\vspace{3mm}\nTherefore,\n$$\\dv{B}{\\alpha}=\\bigintsss_{0}^{1} x^{\\alpha}\\,dx$$\n$$=\\frac{1}{\\alpha+1}$$\n\n\\vspace{3mm}\nIntegrating both sides\n$$B\\left(\\alpha\\right)=\\bigintsss \\frac{1}{\\alpha+1}\\,d\\alpha$$\n$$=\\ln (\\alpha+1)+C$$\n\n\\vspace{2mm}\nIf you let $\\alpha=0$, you will get $C=0$.\n\n\\vspace{7mm}\nTherefore,\n}\n\n{\\LARGE\n$$I = \\bigintss_{1}^{\\infty} \\frac{x^2-1}{x^4 \\ln x}\\, dx=\\ln3$$\n}\n\n\\end{document}", "meta": {"hexsha": "5f0a4eb4a73ad695751ae3a7aa32040f814d890c", "size": 1314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Jose Bedoya's questions/Integral with Leibniz rule.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/Jose Bedoya's questions/Integral with Leibniz rule.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/Jose Bedoya's questions/Integral with Leibniz rule.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": 23.0526315789, "max_line_length": 82, "alphanum_fraction": 0.6445966514, "num_tokens": 537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.6549214370716184}}
{"text": "\\chapter{Discriminant analysis}\n\\label{discriminant}\n\nDiscriminant analysis presupposes that we have a number of known groups of individuals, and a set of data which has been collected on individuals within these groups.   We wish to find a way of using that data to predict which group these individuals belong to, either to understand the differences or to be able to predict group membership.  \\cite{Bumpus:1898} collected data on sparrows who survived and didn't survive a storm, these data are extensively analysed in this context by Manly, the primary aim of the analysis being to look for differences between the groups.   Are there different features which help us tell storm survivors from non-survivors?   More usually, we may be interested in predicting group membership.   Common examples can be found in finance; can banks tell good credit risks from bad based on data collected on customers who have subsequently defaulted on loans, see \\cite{Johnson+Wichern:2002} for more details.   Another good account of discriminant analysis is given by \\cite{Flury:1997} who suuggests it may be valuable when we have to carry out destructive procedures to determine group membership (such as in certain quality control investigations).  Finally a rather brief account is given in \\cite{Venables+Ripley:2002}, which gives the example of disease diagnosis.   Consider a set of measurements of patient characterstics, and information determined on whether these patients have breast cancer or not.   We would be very interested in being able to make a determination of breast cancer based on the data, rather than having to wait for biopsy or other pathological information.\n\nDiscriminant analysis in one dimension seems straightforward enough.   We can examine the densities of the two groups and find an optimal cut-off point, which classifies the two groups as accurately as possible.   Some idea of the procedure is given in figure \\ref{discrim}, which illustrates the idea behind discriminant function.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = 0.5\\textwidth]{images/discrim}\n\\caption{Idealised discrimant function}\n\\label{discrim}\n\\end{center}\n\\end{figure}\n\nNote immediately that there is a measureable risk of misclassification, which depends on the variance within groups and the separation between groups.   All we need to do is extent this procedure to work in more than one dimension.   We are going to realise this by seeking a linear combination giving us the largest separation between groups.   In other words, we are going to find linear combinations based on the original variables:\n\n\\begin{equation}\nz = a_{1} x_{1} + a_{2} x_{2} + \\ldots + a_{p} x_{p}\n\\end{equation}\n\n\nHowever our linear combination this time will be optimised to give us the greatest potential for distinguishing the two groups.   Having found a suitable linear combination, we select a cut-off point (denoted by the vertical dotted line in the figure above), and assign observations to group 1 or group 2 based on the value relative to the cut-off.   You can see from the stylised function shown that some observations will be misclassfied!   We check the performance of this aspect of our procedure by means of a confusion matrix.\n\n\nRecall that when conducting the $T^{2}$ test we essentially looked for linear combination of variables which maximised the difference between groups.   Similar ideas apply in discriminant analysis.   We seek a transformation of the data which gives the maximum ratio of group means to group variance within the two groups, i.e. we are maximising the between group variation relative to the within group variance - this should sound vaguely like what goes on in ANOVA:\n\n\n\\begin{tabular}{llll}\nSource & d.f. & Mean Square & F ratio \\\\\n\\hline\nBetween groups & $m-1$ & $M_{B}$ $M_{B} / M_{W}$\\\\\nWithin groups & $N-m$ & $M_{W}$ & \\\\\n & N-1 & & \\\\\n\\end{tabular}\n\nWe need to find a linear combination that yields as large an F ratio as possible, hence the coefficients $a_{1}, \\ldots, a_{p}$ need to be chosen to maximise this value.   More than one discriminant function is available, there are\n\n\\begin{equation}\ns = min(p, m-1)\n\\end{equation}\ndiscriminant functions available, where $p$ is the number of variables, and $m$ is the number of groups.\n\nConsidering the case where we have $m > 2$ groups, and $p > 2$ variables, we are looking for the following discriminant functions:\n\n\n\\begin{eqnarray*}\nz_{1} &=& a_{11}x_{1} + a_{12}x_{2} + \\ldots + a_{1p}x_{p}\\\\\nz_{2} &=& a_{21}x_{1} + a_{22}x_{2} + \\ldots + a_{2p}x_{p}\\\\\n\\ldots\\\\\nz_{s} &=& a_{s1}x_{1} + a_{s2}x_{2} + \\ldots + a_{sp}x_{p}\n\\end{eqnarray*}\n\nalthough hopefully only  a small number of these linear combinations will account for all important differences between groups.\n\n\\section{Fisher discimination}\n%\\section{Fisher, linear and quadratic discimination}\n\\label{fisherdisc}\n\nRemember the $T^{2}$ statistic:\n\n\\begin{equation}\nT^{2}(\\boldsymbol{a}) = \\frac{ \\left( \\boldsymbol{a} (\\boldsymbol{\\bar{x}}_{1} - \\boldsymbol{\\bar{x}}_{2} ) \\right)^{2} n_{1}n_{2}/(n_{1}+n_{2})}{\\boldsymbol{a}^{T}\\boldsymbol{S}\\boldsymbol{a}}\n\\end{equation}\n\nThis is equivalent to finding $\\boldsymbol{a}$ which maximises $|\\boldsymbol{a} (\\boldsymbol{\\bar{x}}_{1} - \\boldsymbol{\\bar{x}}_{2} ) |$ subject to $\\boldsymbol{a}^{T}\\boldsymbol{S}\\boldsymbol{a}$ = 1.   This has a single solution:\n\n\\begin{displaymath}\n\\boldsymbol{a} = \\boldsymbol{S}^{-1}(\\boldsymbol{\\bar{x}}_{1} - \\boldsymbol{\\bar{x}}_{2} )\n\\end{displaymath}\n\nand so the linear discriminant function is given by:\n\n\\begin{displaymath}\nz = (\\boldsymbol{\\bar{x}}_{1} - \\boldsymbol{\\bar{x}}_{2} )^{T}\\boldsymbol{S}^{-1} \\boldsymbol{x}\n\\end{displaymath}\n\nIn two dimensions, an obvious cut-off would be the midpoint between the mean value of $z$ for group 1 and 2.\n\n\nFisher's approach has been extended to cope with more than two groups.  Again, we wish to find a linear combination $z = \\boldsymbol{a}^{T} \\boldsymbol{x}$ which maximised the ratio of between group variance to within group variance.\n\nIf we calculate the within sample matrix of sum of squares and cross products $\\boldsymbol{W}$, and the total sample matrix of sum of squares and cross products $\\boldsymbol{T}$, we can easily find the between-groups sample matrix sum of squares and cross products:\n\n\\begin{equation}\n\\boldsymbol{B} = \\boldsymbol{T} - \\boldsymbol{W}\n\\end{equation}\n\n\n\nIn effect we wish to maximise:\n\n\\begin{equation}\n\\frac{ \\boldsymbol{a}^{T} \\boldsymbol{B} \\boldsymbol{a}}{ \\boldsymbol{a}^{T} \\boldsymbol{W} \\boldsymbol{a}} \n\\end{equation}\nand usually do this subject to the condition that $\\boldsymbol{a}^{T} \\boldsymbol{W} \\boldsymbol{a}$ = 1.   Fisher's method of discriminant analysis reduces to finding the eigenvalues and corresponding eigenvectors of $\\boldsymbol{W}^{-1}\\boldsymbol{B}$.   The ordered eigenvalues $\\lambda_{1}, \\ldots, \\lambda_{s}$ are the ratio of between groups to within groups sum of squares and cross products for $z_{1}, \\ldots, z_{s}$, the corresponding eigenvectors, $\\boldsymbol{a}_{1}, \\ldots, \\boldsymbol{a}_{s}$, where $\\boldsymbol{a}_{i} = \\left( \\begin{array}{c} a_{i1} \\\\ \\vdots \\\\ a_{ip} \\end{array} \\right)$ are the coefficients of $z_{i}$.\n\nWe make a number of big assumptions in discriminant analysis: that observations are a random sample, that they are normally distributed and that the variance is the same for each group.   Discriminant analysis is relatively resistant to some departures from the normality assumption - it can cope with skewness but not with outliers.   %Some transformation of the data may be necessary in this situation.   It is also possible to use prior information to deal with unequal sample sizes.\n\n\n\n%\\begin{displaymath}\n%W = \\frac{ (\\boldsymbol{X} - \\boldsymbol{C} \\boldsymbol{\\bar{X}_{Class}})^{T} (\\boldsymbol{X} - \\boldsymbol{C} \\boldsymbol{\\bar{X}_{Class}})}{n-c}\n%\\end{displaymath} \n\n%\\begin{displaymath}\n%B  = \\frac{  (\\boldsymbol{C \\bar{X}_{Class}} - \\boldsymbol{I \\bar{X}})^{T}(\\boldsymbol{C \\bar{X}_{Class}} - \\boldsymbol{I \\bar{X}})}{c-1}\n%\\end{displaymath} \n\n%where $\\boldsymbol{\\bar{X}_{Class}}$ are the mean values in a group denoted by $\\boldsymbol{C}$, and $\\boldsymbol{\\bar{X}}$ are the overall means for data matrix $\\boldsymbol{X}$.   $n$ denotes the number of individuals observed, $c$ the number of classes.\n\n\n\n%\\begin{displaymath}\n%z = \\alpha_{1} x_{1} + \\alpha_{2} x_{2} + \\ldots + \\alpha_{p} x_{p}\n%\\end{displaymath}\n\n\n\n\n%In principle, we need to carry out an eigen decomposition of the matrix $\\boldsymbol{W^{-1}B}$ (although in modern computational practice a lot of the details are different, for example some rescaling goes on so that the within-group covariance is set to be $\\boldsymbol{I}$).   The linear combination obtained are referred to by Manly as the canonical discriminant functions.   These linear combinations have within group variance $\\boldsymbol{a^{T} W a}$ and between group variance  $\\boldsymbol{a}^{T} \\boldsymbol{B a}$, with the total variance given by:\n\n%\\begin{displaymath}\n%\\boldsymbol{a}^{T} \\boldsymbol{S a}  = \\frac{(n - g) \\boldsymbol{W} + (g - 1) \\boldsymbol{B}}{n - 1}\n%\\end{displaymath}\n\n\n\n\n\n\\section{Accuracy of discrimination}  \n\\label{accuracy}\n\nClearly, one important measure of the success of our discriminant rule is the accuracy of group prediction: note that there are a number of ways of measuring this and that discriminant analysis is one technique among many used in \\emph{supervised classification}.   There are many techniques in machine learning and other areas which are used for classification, for example you have already met the technique of logistic discrimination.   \n\nModel over-fitting is a known problem: we can fit a classifier really really well to our existing data but it doesn't work well next time we carry out a data collection exercise.   A key concept in this regard is the use of training and testing sets, where we split our data into two groups, and use one part to build a classifier, and the other to test it.   There are many other technques which can help in this regard, for example leave one out (loo) cross validation and some of the more recent multivariate texts should be consulted.\n\nAn important idea in terms of measuring the success of our classifier is the \\emph{confusion matrix}.   This sounds rather grand, but is basically a matrix telling us how many times our discriminant function made a correct classification, and how many times it got it wrong.\n\n\\section{Importance of variables in discrimination}\n\\label{imporvar}\n\nSome textbooks refer to questions surrounding selection of variables for use in a classifier.   It is important to consider whether variables are necessary for classification; often a tolerance test may be used prior to the analysis to remove multicollinear and singular variables.   It may even be desirable to carry out a dimension reducing technique.   The reason for carrying out these tests are related to over-fitting.\n\nSome software provides ``standardised'' coefficients, the idea being that perhaps it is safe to remove variables with small standardised coefficients.   However, another approach could well be to consider classifiers with different numbers and combinations of variables and contrast the confusion matrix.   This might help identify variables which do the best job of distinguishing the groups, and those which are the least necessary.\n\n%If $D^{2}$ is large if the discriminant function performs well.   \n%Wilks' $\\Lambda$ is used to assess the importance of variables: the smaller it is the more important the variable is (there are associated F statistics and p values to help in this regard).\n\n\\section{Canonical discriminant functions}\n\\label{candisc}\n\nAs mentioned earlier, we can have more than one discriminant function.   It is usual to plot these on a scatterplot in an attempt to visualise the discriminant ability.   However, there are tests of significance.\n\nFor example, we wish to find discriminants with a small Wilk's lambda ($\\frac{|\\boldsymbol{W}|}{|\\boldsymbol{T}|}$), in our case this can be derived as :\n\n\\begin{equation}\n\\Lambda^{2} = \\left( \\sum_{k=1}^{m} n_{k} - 1 - \\frac{1}{2}(p + m) \\right) \\ln (1 + \\lambda_{j}),\n\\end{equation}\nwhich has a $\\chi^{2}$ distribution with $p + m - 2j$ degrees of freedom.\n\n\n%\\section{Logistic discrimination}\n%\\label{logdisc}\n\n%\\section{Dimension reduction and discriminant analysis}\n%\\label{drdisc}\n\n\n\n\n\n\n\n\\section{Linear discrimination - a worked example}\n\nIn practice, we're going to consider a classification exercise on the Iris data.   This is rather well known data featuring three species of Iris, and four anatomical measures.   First of all we need to load the \\texttt{MASS} to obtain the \\texttt{lda()} function.   Then we are going to pull out a training set from the Iris data.\n\n\\singlespacing\n\\begin{verbatim}\n> library(MASS)\n>  data(iris3)\n>  Iris <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),\n+                         Sp = rep(c(\"s\",\"c\",\"v\"), rep(50,3)))\n>      train <- sample(1:150, 75)\n\\end{verbatim}\n\\onehalfspacing\n\n\\texttt{train} is a set of index numbers which will allow us to extract a training set.   We use \\texttt{lda()} to fit a discriminant analysis, setting all priors equal to 1 (i.e. group memberships the same), and \\texttt{subset = train} to fit the analysis to the training set.   The squiggle dot indicates that we wish to use all other variables within Iris to predict Species (Sp).\n\n\\begin{verbatim}\n> z <- lda(Sp ~ ., Iris, prior = c(1,1,1)/3, subset = train)\n> z\n\\end{verbatim}\n\n\nHaving extracted a training set, we are going to classify the remaining Iris' and see how well the predicted and actual species line up.\n\n\\singlespacing\n\\begin{verbatim}\n> actual <-  Iris[-train,]$Sp\n> preds <- predict(z, Iris[-train, ])$class)\n> xtabs(~actual + preds)\n\\end{verbatim}\n\\onehalfspacing\n\n\nOne little thing to watch when using software is that in practice, Fisher's approach tends not to be used.   An approach based on probability distributions and using Bayes rule is common.   All this does, is correct for the proportions in each group to start with.   Instead of finding a discriminant rule assuming a 50:50 split, we use information on more plausible group numbers.\n\n%%% Local Variables: ***\n%%% mode:latex ***\n%%% TeX-master: \"../book.tex\"  ***\n%%% End: *** ", "meta": {"hexsha": "fc3c048c6e7d1568a644d02b893e1bf6a09f7058", "size": 14321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/discriminant.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/discriminant.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/discriminant.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": 67.234741784, "max_line_length": 1621, "alphanum_fraction": 0.7481321137, "num_tokens": 3688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6548920312228028}}
{"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\\usepackage{hyperref}\n\n\\usetikzlibrary{angles, quotes}\n\n\\pgfplotsset{compat=newest}\n\n\\title{Convex Optimization}\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{\\CC}{\\mathbb{C}}\n\\newcommand{\\p}{\\partial}\n\\newcommand{\\iv}[1]{\\langle #1 \\rangle}\n\\newcommand{\\adj}{\\text{adj}}\n\\newcommand{\\dom}{\\text{dom}}\n\\newcommand{\\st}{\\text{s.t. }}\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{Convex optimization is a subset of mathematical optimizations that centers around optimization of convex functions over convex sets. The following note is taken from CMU 10-725 (watched from YouTube) as well as the book \\emph{Convex Optimization} (Boyd. et al)}. My attempt at relevant programs and exercises can be found at \\url{https://github.com/davidmaamoaix/convex-opt}.\n\t\n\t\\section{Introduction}\n\t\n\tOptimization is the act of minimizing (or maximizing) a function while conforming to certain constraints.\n\t\n\t\\subsection{Examples of Optimization Problems}\n\t\n\tExamples of \\emph{regressions}:\n\t\\begin{itemize}\n\t\t\\item least squares: \\begin{gather*}\n\t\t\t\\min_\\beta \\sum_{i=1}^n(y_i - x_i^\\top \\beta)^2\n\t\t\\end{gather*}\n\t\t\\item least absolute deviations (robust): \\begin{gather*}\n\t\t\t\\min_\\beta \\sum_{i=1}^n \\mo{y_i - x_i^\\top \\beta}\n\t\t\\end{gather*}\n\t\t\\item lasso (with constraints): \\begin{gather*}\n\t\t\t\\min_\\beta \\sum_{i=1}^n(y_i - x_i^\\top \\beta)^2 \\\\\\text{s.t.} \\sum_j^m |\\beta_j| \\le t\n\t\t\\end{gather*}\n\t\t\\end{itemize}\n\t\t\n\tExamples of \\emph{classifications}:\n\t\\begin{itemize}\n\t\t\\item logistic regressions\n\t\t\\item range Loss (SVMs)\n\t\\end{itemize}\n\t\n\tOthers:\n\t\\begin{itemize}\n\t\t\\item traveling salesman\n\t\t\\item planning/discrete optimizations\n\t\t\\item MLE\n\t\\end{itemize}\n\t\n\tThe following problems are \\textbf{not} optimization problems, as their output isn't simple optimal in respect to some criteria:\n\t\\begin{itemize}\n\t\t\\item boosting\n\t\t\\item ensembles (e.g. random forest)\n\t\t\\item CV\n\t\\end{itemize}\n\t\n\t\\subsubsection{Example: 2D Fused Lasso}\n\t2D fused lasso, or 2D total variation de-noising, fits a piecewise constant function over an image ($\\lambda$ is a hyper-parameter to determine the penalty, and $E$ is the set of edges from a pixel $i$ to all adjacent pixels $j$):\n\t\\begin{gather*}\n\t\t\\min_\\theta \\frac{1}{2} \\sum_{i=1}^n (y_i - \\theta_i) ^ 2  + \\lambda \\sum_{(i, j) \\in E} |\\theta_i - \\theta_j|\n\t\\end{gather*}\n\t\n\tSome methods to approach the 2D fused lasso problem (details on algorithms later):\n\t\\begin{itemize}\n\t\t\\item Specialized Alternating Direction Method of Multipliers (ADMM): fast (structured subproblem)\n\t\t\\item Proximal Gradient: slow (poor conditioning)\n\t\t\\item Coordinate Descent: slow (large active set)\n\t\\end{itemize}\n\t\n\t\\textbf{Conclusion}: different algorithms work better in different optimization problems.\n\t\n\t\\subsubsection{Example: 1D Fused Lasso}\n\t\n\t1D fused lasso is similar to its 2D equvalent:\n\t\\begin{gather*}\n\t\t\\min_\\theta \\frac{1}{2} \\sum_{i=1}^n (y_i - \\theta_i) ^ 2  + \\lambda \\sum_{i=1}^{n - 1} |\\theta_i - \\theta_{i + 1}|\n\t\\end{gather*}\n\t\n\tTrivially, as $\\lambda$ decreases, more change points appear. We tune $\\lambda$ to fit the more significant change points.\n\t\n\t\\subsection{Convexity}\n\t\n\tConvexity is an attribute of a function or set.\n\t\n\t\\begin{defn}\n\t\t$C$ is a \\emph{convex set} if:\n\t\t\\begin{gather*}\n\t\t\t\\forall x, y \\in C\\ldotp t \\in [0, 1] \\Rightarrow tx + (1-t) y \\in C\n\t\t\\end{gather*}\n\t\\end{defn}\n\t\n\tAn example of a convex set is the set of points in a convex shape.\n\t\n\t\\begin{defn}\n\t\tA \\emph{convex function} is a function that:\n\t\t\\begin{enumerate}\n\t\t\t\\item has a convex domain:\n\t\t\t\\begin{gather*}\n\t\t\t\tf: \\RR^n \\to \\RR \\Rightarrow \\dom(f) \\in \\RR^n\\ \\text{is convex}\n\t\t\t\\end{gather*}\n\t\t\t\\item any value on the function is less than or equal to the linear equation joined by any two surrounding points:\n\t\t\t\\begin{gather*}\n\t\t\t\tf(tx + (1 - t)y) \\le tf(x) + (1 - t)f(y)\n\t\t\t\\end{gather*}\n\t\t\\end{enumerate}\n\t\\end{defn}\n\t\n\t\\subsection{Optimization Problem}\n\t\n\t\\begin{defn}\n\t\tAny optimization problem can be rewritten as the following:\n\t\t\\begin{align*}\n\t\t\t&\\min_{x \\in D} f(x) \\\\\n\t\t\t\\st &g_i(x) \\leq 0,\\ i = 0, \\dots, m \\\\\n\t\t\t& h_j(x) = 0,\\ j = 0, \\dots, r\n\t\t\\end{align*}\n\t\twhere $D$ is the common domain of the three functions:\n\t\t\\begin{gather*}\n\t\t\tD = \\dom(f) \\cap \\bigcap_{i=1}^m dom(g_i) \\cap \\bigcap_{j=1}^r dom(h_j)\n\t\t\\end{gather*}\n\t\\end{defn}\n\t\n\tA convex problem is an optimization problem such that $f$ (the criterion) and all $g$ (constraints) are convex functions, and all $h$ are affine functions.\n\t\n\\end{document}\n", "meta": {"hexsha": "b198d77d27f77c9b48343c888e33022ba0ac2166", "size": 4864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "convex-opt/convex-opt.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": "convex-opt/convex-opt.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": "convex-opt/convex-opt.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": 33.0884353741, "max_line_length": 386, "alphanum_fraction": 0.6983963816, "num_tokens": 1665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.6548920238306607}}
{"text": "%!TEX root = ../Thesis.tex\n\n\\chapter{Linear Model Coefficients}\\label{cha:coefficients}\n\nThe coefficients of the MLP1 model constitute a linear classifier for predicting the top branching variable according to the Strong Branching algorithm. The input variables are normalized in the prenorm layer as explained in \\Cref{ssec:models_gcnn}, and the coefficients are then min-max normalized between -1 and 1, calculated as:\n\\begin{equation}\n    \\mathbf{x}_{minmax} = 2 \\cdot \\frac{\\mathbf{x} - \\mathbf{1} \\cdot \\min(\\mathbf{x})}{\\mathbf{1} \\cdot (\\max(\\mathbf{x})- \\min(\\mathbf{x}) )} - \\mathbf{1} \n\\end{equation}\nThe result is presented in \\Cref{tab:coeffs}. The variable type features are omitted, as these are equal for all samples and therefore do not contribute to the prediction.\n\nA thorough analysis of the variable features and their correlation with the variable quality and/or Strong Branching score is interesting in its own right and highly relevant in an analysis of the quality of the feature set. This is outside of the scope and purpose of this thesis, but this little result is included in order to encourage future research.\n\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{lrr}\n\t\t\\toprule\n\t\t  \\textbf{Feature} & \\textbf{Auctions} & \\textbf{Setcover}\\\\\n\t\t  \\toprule\n\t\t  objective & 0.99 & 1.00 \\\\\n\t\t  % 4 for free\n\t\t  has\\_lb & 0.37 & 0.58\\\\\n\t\t  has\\_ub & -0.79 & -1.00\\\\\n\t\t  reduced\\_cost & -1.0 & -0.89\\\\\n\t\t  sol\\_value & -0.64 & -0.91\\\\\n          sol\\_frac  & -0.97 & -0.98\\\\\n\t\t  sol\\_is\\_at\\_lb & 1.00 & 0.82\\\\\n\t\t  sol\\_is\\_at\\_ub & -0.76 & -0.94\\\\\n\t\t  scaled\\_age & -0.69 & -0.90 \\\\\n          inc\\_val & -0.09 & 0.34\\\\\n          avg\\_inc\\_val & -0.38 & 0.20\\\\\n\t\t  basis\\_status\\_lower & 0.97 & 0.90 \\\\\n\t\t  basis\\_status\\_basic & -0.77 & -0.93\\\\\n\t\t  basis\\_status\\_upper & -0.76 & -0.94 \\\\\n\t\t  basis\\_status\\_zero & -0.89 & -0.98 \\\\\n\t\t  %Static Features & 18 & Khalil et al. \\cite{khalil2016learning} \\\\\n\t\t  %Dynamic Features & 54 & Khalil et al. \\cite{khalil2016learning} \\\\\n\t\t% \\addlinespace\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{\\label{tab:coeffs}Normalized coefficients for the MLP1 linear models. Irrelevant features are omitted.}\n\\end{table}", "meta": {"hexsha": "4f93b75029ef77296caa14d9de4d12abd49339f6", "size": 2166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/A-coeffs.tex", "max_stars_repo_name": "Sandbergo/master-thesis", "max_stars_repo_head_hexsha": "6da60d22b4423b4f4ca961cec55090e88ca109eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-25T10:42:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-25T10:42:49.000Z", "max_issues_repo_path": "tex/A-coeffs.tex", "max_issues_repo_name": "Sandbergo/master-thesis", "max_issues_repo_head_hexsha": "6da60d22b4423b4f4ca961cec55090e88ca109eb", "max_issues_repo_licenses": ["MIT"], "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/A-coeffs.tex", "max_forks_repo_name": "Sandbergo/master-thesis", "max_forks_repo_head_hexsha": "6da60d22b4423b4f4ca961cec55090e88ca109eb", "max_forks_repo_licenses": ["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.8292682927, "max_line_length": 355, "alphanum_fraction": 0.6805170822, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681086260461, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.6548920192145016}}
{"text": "\\chapter{Vectors}\n\nWe have talked a some about forces, but in the calculations that we\nhave done, we have only talked about the magnitude of a force. It is\nequally important to talk about its direction. To do the math on\nthings with a magnitude and a direction (like forces), we need vectors.\\index{vectors}\n\nFor example, if you jump out of a plane (hopefully with a parachute), \nseveral forces with different magnitudes and directions will be acting upon \nyou. Gravity will push you straight down. That force will be proportional to your weight.\nIf there were a wind from the west, it would push you toward the east. That force\nwill be proportional to the square of speed of the wind and approximately proportional to \nyour size. Once you are falling, there will be resistance from the air \nthat you are pushing through -- that force will point in the opposite direction\nfrom the direction you are moving and will be proportional to the square of your\nspeed.\n\nTo figure out the net force (which will tell us how we will accelerate), we will \nneed to add these forces together. So we need to learn to do math with vectors.\n\n\\section{Adding Vectors}\n\nA vector is typically represented as a list of numbers, with each\nnumber representing a particular dimension. For example, if I am\ncreating a 3-dimensional vector representing a force, it will have\nthree numbers representing the amount of force in each of the three\naxes. For example, if a force of one newton is in the direction of the\n$x$-axis, I might represent the vector as $v = [1, 0, 0]$. \nAnother vector might be $u = [0.5, 0.9, 0.7]$ \\index{vectors!adding}\n\n\\tdplotsetmaincoords{80}{130} \n\\begin{tikzpicture} [scale=4, tdplot_main_coords, axis/.style={->,sdkblue}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (1.5,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,0.9,0) node[anchor=north west]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,0.9) node[anchor=south]{$z$};\n\n%draw a vector from O to P\n\\draw[vector] (O) -- (1,0,0);\n\\draw[vector] (O) -- (0.5,0.9,0.7);\n\\draw (0.2,0.0,0.05) node[left] {v};\n\\draw (0.2,0.35,0.3) node[right] {u};\n\n\\draw[vector guide] (0.5,0,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.0,0.9,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.5,0.9,0) -- (0.5,0.9,0.7);\n\\end{tikzpicture}\n\nThinking visually, when we add to vectors, we put the starting point \nsecond vector at the ending point of the first vector.\n\n\n\\tdplotsetmaincoords{80}{130} \n\\begin{tikzpicture} [scale=4, tdplot_main_coords, axis/.style={->,sdkblue}, \nlight vector/.style={-stealth,dashed,very thick, black}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (1.5,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,0.9,0) node[anchor=north west]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,0.9) node[anchor=south]{$z$};\n\n%draw a vector from O to P\n\\draw[light vector] (0,0,0) -- (0.5,0.9,0.7);\n\\draw[light vector] (0.5, 0.9, 0.7) -- (1.5, 0.9, 0.7);\n\\draw[vector] (0,0,0) -- (1.5,0.9,0.7) node[left] {u + v};\n\\draw (0.7,0.9,0.75) node[left] {v};\n\\draw (0.2,0.35,0.3) node[right] {u};\n\n\\draw[vector guide] (0.5,0,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.0,0.9,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.5,0.9,0) -- (0.5,0.9,0.7);\n\\draw[vector guide] (0.5,0.9,0) -- (1.5,0.9,0.0);\n\\draw[vector guide] (1.5,0.9,0.0) -- (1.5,0.9,0.7);\n\\draw[vector guide] (1.5,0.0,0.0) -- (1.5,0.9,0.0);\n\n\\end{tikzpicture}\n\nIf you know the vectors, you will just add them element-wise:\n\n$$ u + v = [0.5, 0.9, 0.7] + [1.0, 0.0, 0.0] = [1.5, 0.9. 0.7] $$\n\nThese vectors have 3 components, so we say they are \\newterm{3-dimensional}. \nVectors can have any number of components. For example, the vector\n $[-12.2, 3, \\pi, 10000]$ is 4-dimensional.\n\n You can only add two vectors if they have the same dimension.\n\n $$ [12, -4] + [-1, 5] = [11,1] $$\n\n Addition is commutative: If you have two vectors $a$ and $b$, then\n $a + b$ is the same as $b + a$.\n\n Addition is also associative: If you have three vectors $a$, $b$, and $c$,\n it doesn't matter which order you add them in. \n That is, $a + (b + c) = (a + b) + c$.\n\n A 1-dimensional vector is just a number.  We say it is a \n \\newterm{scalar}, not a vector.\n\n \\begin{Exercise}[title={Adding vectors}, label=adding_vectors]\nAdd the following vectors:\n\\begin{itemize}\n    \\item $[1, 2, 3] + [4, 5, 6]$\n    \\item $[-1, -2, -3, -4] + [4, 5, 6, 7]$\n    \\item $[\\pi, 0, 0] + [0, \\pi, 0] + [0, 0, \\pi]$\n\\end{itemize}\n\\end{Exercise}\n\\begin{Answer}[ref=adding_vectors]\n    \\begin{itemize}\n        \\item $[1, 2, 3] + [4, 5, 6] = [5, 7, 9]$\n        \\item $[-1, -2, -3, -4] + [4, 5, 6, 7] = [3, 3, 3, 3]$\n        \\item $[\\pi, 0, 0] + [0, \\pi, 0] + [0, 0, \\pi] = [\\pi, \\pi, \\pi]$ \n    \\end{itemize}\n\\end{Answer}\n\n    \\begin{Exercise}[title={Adding Forces}, label=adding_forces]\n        You are adrift in space. You are near two different stars. \n        The gravity of one star is pulling you towards it with a \n        force of $[4.2, 5.6, 9.0]$ newtons.\n        The gravity of the other star is pulling you towards it with\n        a force of $[-100.2, 30.2, -9.0]$ newtons. What is the net force?\n        \\end{Exercise}\n        \\begin{Answer}[ref=adding_forces]\n            To get the net force, you add the two forces:\n\n            $$F = [4.2, 5.6, 9.0] + [-100.2, 30.2, -9.0] = [-96, 35.8, 0.0] \\text{ newtons}$$\n   \n\\end{Answer}\n\n\\section{Multiplying a vector with a scalar}\n\nIt is not uncommon to multiply a vector by a scalar.  For example, a rocket engine\nmight have a force vector $v$.  If you fire 9 engines in the exact same direction,\nthe resulting force vector would be $9v$.\\index{vectors!multipying by a scalar}\n\nVisually, when we multiply a vector $u$ by a scalar $a$, we get a new vector that\ngoes in the same direction as $u$ but has a magnitude $a$ times as long as $u$.\n\n\\tdplotsetmaincoords{80}{130} \n\\begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,sdkblue}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (1.6,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,2.8,0) node[anchor=north west]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,1.9) node[anchor=south]{$z$};\n\n%draw a vector from O to P\n\\draw[vector] (O) -- (0.5,0.9,0.7);\n\\draw (0.2,0.35,0.3) node[right] {$u$};\n\n\\draw[vector] (O) -- (1.5,2.7,2.1) node[right] {$3u$};\n\n\n\\draw[vector guide] (0.5,0,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.0,0.9,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.5,0.9,0) -- (0.5,0.9,0.7);\n\n\\draw[vector guide] (1.5,0,0) -- (1.5,2.7,0);\n\\draw[vector guide] (0.0,2.7,0) -- (1.5,2.7,0);\n\\draw[vector guide] (1.5,2.7,0) -- (1.5,2.7,2.1);\n\\end{tikzpicture}\n\nWhen you multiply a vector by a scalar, you just multiply each of the components by the scalar:\n\n$$ 3 \\times [0.5, 0.9, 0.7] = [1.5, 2.7, 3.6] $$\n\n\\begin{Exercise}[title={Multiplying a vector and a scalar}, label=mult_scalar]\n    Simplify the following expressions:\n    \\begin{itemize}\n        \\item $2 \\times [1, 2, 3]$\n        \\item $[-1, -2, -3, -4] \\times -2$\n        \\item $\\pi[\\pi, 2\\pi, 3\\pi]$\n    \\end{itemize}\n    \\end{Exercise}\n    \\begin{Answer}[ref=mult_scalar]\n        \\begin{itemize}\n            \\item $2 \\times [1, 2, 3] = [2, 4, 6]$\n            \\item $[-1, -2, -3, -4] \\times -3 = [3, 6, 9, 12]$\n            \\item $\\pi[\\pi, 2\\pi, 3\\pi]  = \\pi^2, 2\\pi^2, 3\\pi^2]$ \n        \\end{itemize}\n    \\end{Answer}\n\nNote that when you multiply a vector times a negative number, the new vector points \nin the opposite direction.\n\n\\tdplotsetmaincoords{80}{130} \n\\begin{tikzpicture} [scale=5, tdplot_main_coords, axis/.style={->,sdkblue}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (0.55,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,0.95,0) node[anchor=north west]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,0.6) node[anchor=south]{$z$};\n\n%draw a vector from O to P\n\\draw[vector] (O) -- (0.5,0.9,0.7);\n\\draw (0.2,0.36,0.3) node[right] {$u$};\n\n\\draw[vector] (O) -- (-0.25,-0.45,-0.35) node[right] {$(-0.5)u$};\n\n\\draw[vector guide] (0.5,0,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.0,0.9,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.5,0.9,0) -- (0.5,0.9,0.7);\n\n\\draw[vector guide] (-0.25,0,0) -- (-0.25,-0.45,0);\n\\draw[vector guide] (0,0,0) -- (-0.25,0,0);\n\\draw[vector guide] (0.0,-0.45,0) -- (-0.25,-0.45,0);\n\\draw[vector guide] (0,0,0) -- (0,-0.45,0);\n\n\\draw[vector guide] (-.25,-0.45,0) -- (-0.25,-0.45,-0.35);\n\\end{tikzpicture}\n\n\\section{Vector Subtraction}\n\nAs you might guess, when you subtract one vector from another, \nyou just do element-wise subtraction:\\index{vectors!subtraction}\n\n$$[4,2,0] - [3,-2, 9] = [1, 4, -9]$$\n\nSo, $u - v = u + (-1v)$.\n\nSo visually, you reverse the one that is being subtracted:\n\n\n\\tdplotsetmaincoords{80}{130} \n\\begin{tikzpicture} [scale=5, tdplot_main_coords, axis/.style={->,sdkblue}, \nlight vector/.style={-stealth,dashed,very thick, black}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (0.55,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,1.0,0) node[anchor=north west]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,0.75) node[anchor=south]{$z$};\n\n%draw a vector from O to P\n\\draw[light vector] (0,0,0) -- (0.5,0.9,0.7);\n\\draw[light vector] (0.5, 0.9, 0.7) -- (-0.5, 0.9, 0.7);\n\\draw[vector] (0,0,0) -- (-0.5,0.9,0.7) node[right] {u - v};\n\\draw (0.1,0.9,0.75) node[left] {-v};\n\\draw (0.29,0.34,0.32) node[right] {u};\n\n\\draw[vector guide] (0.5,0,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.0,0.9,0) -- (0.5,0.9,0);\n\\draw[vector guide] (0.5,0.9,0) -- (0.5,0.9,0.7);\n\\draw[vector guide] (0.5,0.9,0) -- (-0.5,0.9,0.0);\n\\draw[vector guide] (-0.5,0.9,0.0) -- (-0.5,0.9,0.7);\n\\draw[vector guide] (-0.5,0.0,0.0) -- (-0.5,0.9,0.0);\n\\draw[vector guide] (0,0.0,0.0) -- (-0.5,0.0,0.0);\n\n\\end{tikzpicture}\n\n\\section{Magnitude of a Vector}\n\nThe \\newterm{magnitude} of a vector is just its length. We write the \nmagnitude of a vector $v$ as $|v|$.\\index{vectors!magnitude of}\n\nWe compute the magnitude using the pythagorean theorem.  If $v = [3,4,5]$, \nthen\n\n\\begin{equation*}\n    |v| = \\sqrt{3^2 + 4^2 + 5^2} = \\sqrt{50} \\approx 7.07\n\\end{equation*}\n\n(You might notice that the notation for the magnitude is exactly like the notation for absolute value.\nIf you think of a scalar as a 1-dimensional vector, the absolute value and the magnitude are the same. \nFor example, the absolute value of -5 is 5.  If you take the magnitude of the one-dimenional vector $[-5]$,\nyou get $\\sqrt{25} = 5$.)\n\nNotice that if you scale up a vector, its magnitude scales by the same amount.  For example:\n\n\\begin{equation*}\n|7[3,4,5]| = 7 \\sqrt{50} \\approx 7 \\times 7.07    \n\\end{equation*}\n\nThe rule then is: If you have any vector $v$ and any scalar $a$:\n\\begin{equation*}\n    |a v| = |a| |v|\n\\end{equation*}\n\n\n\\begin{Exercise}[title={Magnitude of a Vector}, label=vector_mag]\n    Find the magnitude of the following vectors:\n    \\begin{itemize}\n        \\item $[1, 1, 1]$\n        \\item $[-5, -5, -5]$ (that is the same as $-5 \\times [1, 1, 1]$)\n        \\item $[3, 4, -4] + [-2, -3, 5]$\n    \\end{itemize}\n    \\end{Exercise}\n    \\begin{Answer}[ref=vector_mag]\n        \\begin{itemize}\n            \\item $|[1, 1, 1]| = \\sqrt{3} \\approx 1.73 $\n            \\item $|[-5, -5, -5]| = |-5 \\times [1,1,1]| = 5 \\sqrt{3} \\approx 8.66$\n            \\item $|[3, 4, 5] + [-2, -3, -4]| = | [1,1,1] | = \\sqrt{3} \\approx 1.73$ \n        \\end{itemize}\n    \\end{Answer}\n\n\\section{Vectors in Python}\n\nnumpy is a library that allows you to work with vectors in Python.  \nYou might need to install it on your computer. This is done with \\pyfunction{pip}. \n\\pyfunction{pip3} installs things specifically for Python 3.\\index{vectors!in python}\n\n\\begin{Verbatim}\npip3 install numpy\n\\end{Verbatim}\n\nWe can think of a vector as a list of numbers.  \nThere are also grids of numbers known as \\newterm{matrices}. numpy deals with both the same way, \nso it refer to both of them as arrays.\\index{numpy}\n\nThe study of vectors and matrices is known as \\newterm{Linear Algebra}. Some of the functions we need\nare in a sublibrary of numpy called \\pyfunction{linalg}. \\index{linalg}\n\nAs a convention, everyone who uses numpy, imports it as \\textit{np}. \\index{np}\n\nCreate a file called \\filename{first\\_vectors.py}:\n\n\\begin{Verbatim}\nimport numpy as np\n\n# Create two vectors\nv = np.array([2,3,4])\nu = np.array([-1,-2,3])\nprint(f\"u = {u}, v = {v}\")\n\n# Add them\nw = v + u\nprint(f\"u + v = {w}\")\n\n# Multiply by a scalar\nw = v * 3\nprint(f\"v * 3 = {w}\")\n\n# Get the magnitude\n# Get the magnitude\nmv = np.linalg.norm(v)\nmu = np.linalg.norm(u)\nprint(f\"|v| = {mv}, |u| = {mu}\")\n\\end{Verbatim}\n\nWhen you run it, you should see:\n\n\\begin{Verbatim}\n> python3 first_vectors.py\nu = [-1 -2  3], v = [2 3 4]\nu + v = [1 1 7]\nv * 3 = [ 6  9 12]\n|v| = 5.385164807134504, |u| = 3.7416573867739413\n\\end{Verbatim}\n\n\\subsection{Formatting Floats}\n\nThe numbesr 5.385164807134504 and 3.7416573867739413 are pretty long.  You probably want it \nrounded off after a couple of decimal places.\n\nNumbers with decimal places are called \\newterm{floats}. In the placeholder for your float, you \ncan specify how you want it formatted, including the number of decimal places.\n\nChange the last line to look like this:\\index{floats!formatting}\n\\begin{Verbatim}\n    print(f\"|v| = {mv:.2f}, |u| = {mu:.2f}\")\n\\end{Verbatim}\n\nWhen you run the code, it will be neatly rounded off to two decimal places:\n\\begin{Verbatim}\n|v| = 5.39, |u| = 3.74\n\\end{Verbatim}\n", "meta": {"hexsha": "bcdfcbe17133f98afc19455f235642187732f14c", "size": 14016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/TrianglesCircles/vectors-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/TrianglesCircles/vectors-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/TrianglesCircles/vectors-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": 35.7551020408, "max_line_length": 107, "alphanum_fraction": 0.6357020548, "num_tokens": 5379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673223709251, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.6548720764796001}}
{"text": "% \\section{Introduction}\\label{sec:introduction}\nRefinement types enable specification of complex invariants \nby extending the base type system with \\emph{refinement predicates} \ndrawn from decidable logics. For example,\n%\n\\begin{code}\n  type Nat = {v:Int | 0 <= v}\n  type Pos = {v:Int | 0 < v}\n\\end{code}\n%\nare refinements of the basic type @Int@ with a logical predicate \nthat states the \\emph{values} @v@ being described must be \n\\emph{non-negative} and \\emph{postive} respectively. \n%\nWe can specify \\emph{contracts} of functions by refining function types. \nFor example, the contract for @div@\n%\n\\begin{code}\n  div :: n:Nat -> d:Pos -> {v:Nat | v <= n}\n\\end{code}\n%\nstates that @div@ \\emph{requires} a non-negative dividend @n@ and a positive\ndivisor @d@ and \\emph{ensures} that the result is less than the dividend.\n%\nIf a program (refinement) type checks, we can be sure that @div@ will never \nthrow a divide-by-zero exception.\n\nRefinement types \\citep{ConstableS87,Rushby98} \nhave been implemented for several languages like\nML~\\cite{pfenningxi98,GordonTOPLAS2011,LiquidPLDI08},\nC~\\cite{deputy,LiquidPOPL10},\nTypeScript~\\cite{Vekris16},\nRacket~\\cite{RefinedRacket} and Scala~\\cite{refinedscala}.\n%\nHere we present \\toolname,\na refinement type checker for Haskell.\n%\nIn this chapter we start with an example driven informal and practical overview\nof \\toolname.\n%\nIn particular, we try to answer the following questions:\n%\n\\begin{enumerate}\n  \\item What properties can be specified with refinement types?\n  \\item What inputs are provided and what feedback is received?\n  \\item What is the process for modularly verifying a library?\n  \\item What are the limitations of refinement types? \n\\end{enumerate}\n\nWe attempt to investigate these questions, by using the\nrefinement type checker \\toolname, to specify and verify a variety of \nproperties of over 10,000 lines of Haskell code from popular \nlibraries, including @containers@, \\hbox{@hscolor@,} @bytestring@, @text@, \n@vector-algorithms@ and @xmonad@. \n%\n\\begin{itemize}\n\\item First (\\S~\\ref{sec:liquidhaskell}), \nwe present a high-level overview of \\toolname, through a tour \nof its features.\n%\n\n\\item Second, we present a qualitative discussion of the kinds of properties\nthat can be checked -- ranging from generic application independent \ncriteria like totality (\\S~\\ref{sec:totality}), \n\\ie that a function is defined for all inputs (of a given type)\nand termination, \n(\\S~\\ref{sec:termination}) \n\\ie that a recursive function cannot diverge,\nto application specific concerns like memory safety (\\S~\\ref{sec:memory-safety}) \nand functional correctness properties (\\S~\\ref{sec:structures}).\n%\n\\item Finally (\\S~\\ref{sec:realworld:evaluation}), we present a quantitative evaluation of the approach, with a view\ntowards measuring the efficiency and programmer's effort required for\nverification, \nand we discuss various limitations of the approach which could\nprovide avenues for further work.\n\\end{itemize}\n", "meta": {"hexsha": "3fbef6a92b6d0123d6a92f341a9f5a6a497262b8", "size": 2967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/realworldhaskell/intro.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/intro.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/intro.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": 38.0384615385, "max_line_length": 116, "alphanum_fraction": 0.7637344119, "num_tokens": 782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6548720747240961}}
{"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    \\usepackage{multicol}\n\n    \\usetikzlibrary{positioning}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{Edgar Jacob Rivera Rios - A01184125}\n\n\\begin{document}\n\\section*{2.4.1 First-Order Logic.}\nProve the statements:\n\\begin{itemize}\n    \\item $\\forall x p ( x ) \\wedge \\forall x q ( x ) \\rightarrow \\forall x ( p ( x ) \\wedge q ( x ) )$\n    \\begin{align*}\n        A &= \\forall xp(x) \\wedge \\forall x q(x)\\\\\n        B &= \\forall x( p(x) \\wedge q(x))\\\\\n        A &\\rightarrow B\n    \\end{align*}\n    \\begin{center}\n        \\begin{tikzpicture}[sibling distance=8em, every node/.style = {align=center}]\n            \\node {$\\neg (A \\rightarrow B) \\equiv A \\wedge \\neg B$}\n            child { node {$A, \\neg B$}\n              child { node {$\\forall xp(x) \\wedge \\forall x q(x),\\exists x (\\neg p(x) \\vee \\neg q(x))$}\n                child { node {$p(a) \\wedge q(a), \\neg p(a) \\vee \\neg q(a)$}\n                  child { node {$p(a), q(a), \\neg p(a) \\vee \\neg q(a)$}\n                    child { node {$p(a), q(a), \\neg p(a)$\\\\$\\times$}\n                      edge from parent node [left] {$\\beta$}}\n                    child { node {$p(a), q(a), \\neg q(a)$\\\\$\\times$}\n                      edge from parent node [right] {$\\beta$}}\n                    edge from parent [solid] node [right] {$\\alpha$}}\n                  edge from parent [dashed] node [right] {instantiation}}\n                edge from parent [double] node {}}\n              edge from parent node [right] {$\\alpha$}};\n        \\end{tikzpicture}\n    \\end{center}\n    By contradiction of the inverse we found out that it's valid\n\n    \\item $\\forall x ( p ( x ) \\rightarrow q ( x ) ) \\rightarrow ( \\forall x p ( x ) \\rightarrow \\forall x q ( x ) )$ is a valid formula (but its converse $( \\forall x p ( x ) \\rightarrow \\forall x q ( x ) ) \\rightarrow \\forall x ( p ( x ) \\rightarrow q ( x ) )$ is not).\n    \\begin{align*}\n        A &= \\forall x(p(x) \\rightarrow q(x))\\\\\n        B &= \\forall xp(x) \\rightarrow \\forall x q(x)\\\\\n        A &\\rightarrow B\n    \\end{align*}\n    \\begin{center}\n        \\begin{tikzpicture}[sibling distance=8em, every node/.style = {align=center}]\n          \\node {$\\neg (A \\rightarrow B) \\equiv A \\wedge \\neg B$}\n            child { node {$A, \\neg B$}\n              child { node {$\\forall x(p(x) \\rightarrow q(x)),\\forall xp(x) \\wedge \\exists x \\neg q(x)$}\n                child { node {$p(a) \\rightarrow q(a), p(a) \\wedge \\neg q(a)$}\n                  child { node {$p(a) \\rightarrow q(a), p(a), \\neg q(a)$}\n                    child { node {$\\neg p(a) , p(a), \\neg q(a)$\\\\$\\times$}\n                    edge from parent node [left] {$\\beta$}}\n                    child { node {$q(a), p(a), \\neg q(a)$\\\\$\\times$}\n                    edge from parent node [right] {$\\beta$}}\n                  edge from parent [solid] node [right] {$\\alpha$}}\n                edge from parent [dashed] node [right] {instantiation}}\n              edge from parent [double] node {}}\n            edge from parent node [right] {$\\alpha$}};\n        \\end{tikzpicture}\n    \\end{center}\n    By contradiction of the inverse we found out that it's valid\n\\end{itemize}\n\n\\section*{2.4.2 First-Order Logic.}\nProve that the formula $( \\forall x p ( x ) \\rightarrow \\forall x q ( x ) ) \\rightarrow \\forall x ( p ( x ) \\rightarrow q ( x ) )$ is not valid by constructing a semantic tableau for its negation.\n\\begin{align*}\n    A &= \\forall xp(x) \\rightarrow \\forall x q(x) \\\\\n    B &= \\forall x(p(x) \\rightarrow q(x)) \\\\\n    A &\\rightarrow B\n\\end{align*}\n\\begin{center}\n  \\begin{tikzpicture}[sibling distance=13em, every node/.style = {align=center}]\n    \\node {$\\neg (A \\rightarrow B) \\equiv A \\wedge \\neg B$}\n      child { node {$A, \\neg B$}\n        child { node {$\\forall xp(x) \\rightarrow \\forall x q(x), \\neg \\forall x(p(x) \\rightarrow q(x))$}\n          child {node {$\\neg \\forall x p(x), \\neg \\forall x(p(x) \\rightarrow q(x))$}\n            child {node {$\\neg p(a), \\neg (p(a) \\rightarrow q(a))$}\n              child { node {$p(a), \\neg q(a), \\neg p(a)$}\n              edge from parent node {$\\alpha$}}\n            edge from parent node {instantiation}}\n          edge from parent node {$\\beta$}}\n          child {node {$\\neg \\forall x(p(x) \\rightarrow q(x)), \\forall x q(x)$}}\n        edge from parent [double] node {}}\n      edge from parent node [right] {$\\alpha$}};\n  \\end{tikzpicture}\n\\end{center}\n\\pagebreak\n\\section*{2.4.3 First-Order Logic.}\nProve that the following formulas are valid\n\\begin{itemize}\n    \\item $\\exists x (\\mathrm { A } ( x ) \\rightarrow \\mathrm { B } ( x ) ) \\leftrightarrow ( \\forall x \\mathrm { A } ( x ) \\rightarrow \\exists x \\mathrm { B } ( x ) )$\n    \\begin{align*}\n        F &= \\exists x (\\mathrm { A } ( x ) \\rightarrow \\mathrm { B } ( x ) ) \\\\\n        G &= ( \\forall x \\mathrm { A } ( x ) \\rightarrow \\exists x \\mathrm { B } ( x ) )\\\\\n        F &\\rightarrow G, G \\rightarrow F\n    \\end{align*}\n    \\begin{tikzpicture}[sibling distance=13em, every node/.style = {align=center}]\n      \\node {$\\neg (F \\rightarrow G) \\equiv F \\wedge \\neg G$}\n        child { node {$F, \\neg G$}\n          child { node {$\\exists x(A(x) \\rightarrow B(x)), \\neg (\\forall x A(x) \\rightarrow \\exists x B(x))$}\n            child { node {$\\exists x(A(x) \\rightarrow B(x)),\\forall x A(x), \\forall x \\neg B(x)$}\n              child { node {$A(a) \\rightarrow B(a), A(a), \\neg B(a)$}\n                child { node {$\\neg A(a), A(a), \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [left] {$\\beta$}}\n                child { node {$B(a), A(a), \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\beta$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [right] {$\\alpha$}}\n          edge from parent [double] node {}}\n        edge from parent node [right] {$\\alpha$}};\n    \\end{tikzpicture}\n    \\begin{tikzpicture}[sibling distance=13em, every node/.style = {align=center}]\n      \\node {$\\neg (G \\rightarrow F) \\equiv G \\wedge \\neg F$}\n        child { node {$\\neg F, G$}\n          child { node {$ \\neg \\exists x(A(x) \\rightarrow B(x)), (\\forall x A(x) \\rightarrow \\exists x B(x))$}\n            child { node {$\\neg \\exists x(A(x) \\rightarrow B(x)), \\neg \\forall x A(x)$}\n              child { node {$\\neg (A(a) \\rightarrow B(a)), \\neg A(a)$}\n                child { node {$A(a), \\neg B(a), \\neg A(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\alpha$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [left] {$\\beta$}}\n            child { node {$\\neg \\exists x(A(x) \\rightarrow B(x)), \\exists x B(x)$}\n              child { node {$\\neg (A(a) \\rightarrow B(a)), B(a)$}\n                child { node {$A(a), \\neg B(a), B(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\alpha$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [right] {$\\beta$}}\n          edge from parent [double] node {}}\n        edge from parent node [right] {$\\alpha$}};\n    \\end{tikzpicture}\\\\\n    It's true by contradiction of the inverse implications\n    \\item $(\\exists x A(x) \\rightarrow \\forall x B(x)) \\rightarrow \\forall x(A(x) \\rightarrow B(x))$\n    \\begin{center}\n      \\begin{tikzpicture}[sibling distance=13em, every node/.style = {align=center}]\n        \\node {$\\neg ((\\exists x A(x) \\rightarrow \\forall x B(x)) \\rightarrow \\forall x(A(x) \\rightarrow B(x)))$}\n          child {node {$(\\exists x A(x) \\rightarrow \\forall x B(x)), \\neg \\forall x(A(x) \\rightarrow B(x))$}\n            child {node {$\\neg \\exists x A(x),\\neg \\forall x(A(x) \\rightarrow B(x)))$}\n              child {node {$\\neg A(a), \\neg (A(a) \\rightarrow B(a))$}\n                child {node {$\\neg A(a), A(a) , \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\alpha$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [left] {$\\beta$}}\n            child {node {$\\forall x B(x),\\neg \\forall x(A(x) \\rightarrow B(x))$}\n              child {node {$B(a), \\neg (A(a) \\rightarrow B(a))$}\n                child {node {$B(a), A(a) , \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\alpha$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [right] {$\\beta$}}\n          edge from parent node [right] {$\\alpha$}};\n      \\end{tikzpicture}\n    \\end{center}\n    It's true by contradiction of the inverse\n    \\pagebreak\n    \\item $\\forall x (A(x) \\vee B(x)) \\rightarrow (\\forall x A(x) \\vee \\exists x B(x))$\n    \\begin{center}\n      \\begin{tikzpicture}[sibling distance=13em, every node/.style = {align=center}]\n        \\node {$\\neg(\\forall x (A(x) \\vee B(x)) \\rightarrow (\\forall x A(x) \\vee \\exists x B(x)))$}\n          child {node {$\\forall x (A(x) \\vee B(x)), \\neg (\\forall x A(x) \\vee \\exists x B(x))$}\n            child {node {$\\forall x (A(x) \\vee B(x)), \\neg \\forall x A(x), \\neg \\exists x B(x)$}\n              child {node {$(A(a) \\vee B(a)), \\neg A(a), \\neg B(a)$}\n                child {node {$A(a), \\neg A(a), \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [left] {$\\beta$}}\n                child {node {$B(a), \\neg A(a), \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\beta$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [right] {$\\alpha$}}\n          edge from parent node [right] {$\\alpha$}};\n      \\end{tikzpicture}\n    \\end{center}\n    It's true by contradiction of the inverse\n    \\item $\\forall x (A(x) \\rightarrow B(x)) \\rightarrow (\\exists x A(x) \\rightarrow \\exists x B(x))$\n    \\begin{center}\n      \\begin{tikzpicture}[sibling distance=13em, every node/.style = {align=center}]\n        \\node {$\\neg(\\forall x (A(x) \\rightarrow B(x)) \\rightarrow (\\exists x A(x) \\rightarrow \\exists x B(x)))$}\n          child {node {$\\forall x (A(x) \\rightarrow B(x)), \\neg (\\exists x A(x) \\rightarrow \\exists x B(x))$}\n            child {node {$\\forall x (A(x) \\rightarrow B(x)), \\exists x A(x), \\neg \\exists x B(x)$}\n              child {node {$(A(a) \\rightarrow B(a)), A(a), \\neg B(a)$}\n                child {node {$ \\neg A(a), A(a), \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [left] {$\\beta$}}\n                child {node {$B(a), A(a), \\neg B(a)$\\\\$\\times$}\n                edge from parent [solid] node [right] {$\\beta$}}\n              edge from parent [dashed] node [right] {instantiation}}\n            edge from parent node [right] {$\\alpha$}}\n          edge from parent node [right] {$\\alpha$}};\n      \\end{tikzpicture}\n    \\end{center}\n    It's true by contradiction of the inverse\n\\end{itemize}\n\\end{document}", "meta": {"hexsha": "a4e357d348a1de8957994e6f95389c97ee4ab477", "size": 10998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework2_4.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_4.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_4.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": 55.8274111675, "max_line_length": 271, "alphanum_fraction": 0.5356428442, "num_tokens": 3303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.654872074724096}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#8 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{Backpropagation Computation}\n\nThis question gives a hypothetical neural network and asks about how many\nof the given operations are performed in a single iteration of backpropagation\n(using Stochastic Gradient Descent in one data point).\n\nThe network has $L=2$, $d^{(0)}=5$, $d^{(1)}=3$, $d^{(2)}=1$, and only products\nof the form $w_{ij}^{(l)}x_i^{(l-1)}$, $w_{ij}^{(l)}\\delta_j^{(l)}$, and\n$x_i^{(l-1)}\\delta_j^{(l)}$ count as operations.\n\nMy answer was 47 operations.\n\n\\subsection{Feedforward Step}\n\nFrom the input layer to the first hidden layer there are 18 operations, and from\nthe first hidden layer to the output layer there are 4 operations, resulting in\na total of 22 operations.\n\n\\subsection{Backpropagation Step}\n\nThe computation of delta for the output layer $\\delta_j^{(L)}$ do not count as\nan operation, since no such products are required. However, the computation of\neach delta in the hidden layer does count, resulting in a total of 3 operations.\n\n\\subsection{Weight Update Step}\n\nFinally, we have to update all weights after computing the deltas, resulting\nin a total of 22 operations.\n\n\\end{document}\n", "meta": {"hexsha": "2978398096d2044c150d6ca1d1954286060fe2fa", "size": 1446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-06/math/q08.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/q08.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/q08.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.4347826087, "max_line_length": 80, "alphanum_fraction": 0.7531120332, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6547733846734847}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 6.4 Scalar curavture of a 2-sphere}\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   g^{a b}::InverseMetric.  # essential when using complete (gab, $g^{a b}$)\n\n   Gamma := \\Gamma^{a}_{b c} -> 1/2 g^{a d} (   \\partial_{b}{g_{d c}}\n                                              + \\partial_{c}{g_{b d}}\n                                              - \\partial_{d}{g_{b c}}).\n\n   Rabcd := R^{a}_{b c d} ->   \\partial_{c}{\\Gamma^{a}_{b d}}\n                             - \\partial_{d}{\\Gamma^{a}_{b c}}\n                             + \\Gamma^{e}_{b d} \\Gamma^{a}_{c e}\n                             - \\Gamma^{e}_{b c} \\Gamma^{a}_{d e}.\n\n   Rab := R_{a b} -> R^{c}_{a c b}.\n\n   R := R -> R_{a b} g^{a b}.\n\n   gab := { g_{\\theta\\theta}   = r**2,\n            g_{\\varphi\\varphi} = r**2 \\sin(\\theta)**2 }.      # cdb(ex-0604.101,gab)\n\n   complete   (gab, $g^{a b}$)                                # cdb(ex-0604.102,gab)\n\n   substitute (Rabcd, Gamma)\n   substitute (Rab, Rabcd)\n   substitute (R, Rab)\n\n   evaluate   (Gamma, gab, rhsonly=True)                      # cdb(ex-0604.103,Gamma)\n   evaluate   (Rabcd, gab, rhsonly=True)                      # cdb(ex-0604.104,Rabcd)\n   evaluate   (Rab,   gab, rhsonly=True)                      # cdb(ex-0604.105,Rab)\n   evaluate   (R,     gab, rhsonly=True)                      # cdb(ex-0604.106,R)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{align*}\n   &\\Cdb{ex-0604.101}\\\\[10pt]\n   &\\Cdb{ex-0604.102}\\\\[10pt]\n   &\\Cdb{ex-0604.103}\\\\[10pt]\n   &\\Cdb{ex-0604.104}\\\\[10pt]\n   &\\Cdb{ex-0604.105}\\\\[10pt]\n   &\\Cdb{ex-0604.106}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "d3392e8b273bbdba1c7290069a4d8baf7b2a200d", "size": 1924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0604.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-0604.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-0604.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": 32.6101694915, "max_line_length": 94, "alphanum_fraction": 0.4646569647, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.654773373386333}}
{"text": "\\section{Problem Statement}\n\\label{sec:ProblemStatement}\n\nSimply put: fit a smooth function through a sequence of data points,\n\\textit{e.g.} Figure \\ref{fig:DataFittingExampleFigure}. \\\\\nMore precisely:\n\\begin{itemize}\n  \\setlength\\itemsep{0em}\n  \\item \\textbf{Given:} a time-stamped set of points in space.\n  \\item \\textbf{Find:} a smooth vector function.\n  \\item \\textbf{Minimize:} integral of curvature-rate-squared and sum or squared-error.\n  \\item \\textbf{Subject to:} value, slope, and curvature at the boundaries.\n\\end{itemize}\n\n\\par\nWe will use $\\bm{x}(t)$ to represent value as a function of time.\nThe data set is $\\{t_i, \\bar{\\bm{x}}_i\\}$, which gives measured value at each time stamp.\nThe time-domain of the data set is $[0, T]$.\n\n\\subsection{Objective Function}\n\nThe objective function is a weighted combination of two terms.\nThe first is the sum of the squared-error between the candidate vector function and the points in the data set.\nThe second is a smoothing-term, minimizing the integral of the third derivative of the function.\n\n\\begin{equation}\n  \\bm{J}\\big(\\bm{x}(t)\\big) \\; =   \\;\n    \\frac{T}{N}  \\sum_{i=0}^N \\big( \\bm{x}(t_i) - \\bar{\\bm{x}}_i \\big)^2\n     \\; +   \\; \\alpha \\! \\int_0^T \\! \\dddot{\\bm{x}}^2(t) \\, dt\n  \\label{eqn:continuousObjectiveFunction}\n\\end{equation}\n\n\\subsection{Constraints}\n\nThe vector function $\\bm{x}(t)$ must be smooth: continuous value, slope, and curvature.\n\\begin{equation}\n  \\bm{x}(t) \\in \\mathcal{C}^2\n\\end{equation}\n\nWe also require that the value, slope, and curvature be prescribed at the initial and final times.\nIn practice these boundary constraints can be dropped if not required by the end-user.\n\n\\begin{align}\n  \\bm{x}(0) = \\bm{x}_0  & \\quad &  \\bm{x}(T) = \\bm{x}_T \\\\\n  \\dot{\\bm{x}}(0) = \\dot{\\bm{x}}_0  & \\quad & \\dot{\\bm{x}}(T) = \\dot{\\bm{x}}_T \\\\\n  \\ddot{\\bm{x}}(0) = \\ddot{\\bm{x}}_0  & \\quad & \\ddot{\\bm{x}}(T) = \\ddot{\\bm{x}}_T\n\\end{align}\n", "meta": {"hexsha": "bd0e5e90f3e9567ac65ad1cd7c60aed98645f769", "size": 1912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "supplement/fit-spline-to-data/tex/problemStatement.tex", "max_stars_repo_name": "ShaneRozenLevy/ME149_Spring2018", "max_stars_repo_head_hexsha": "0cd1960cd3699ef4f24f824c89b32a64c73b5b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2018-01-10T15:55:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T22:54:58.000Z", "max_issues_repo_path": "supplement/fit-spline-to-data/tex/problemStatement.tex", "max_issues_repo_name": "Boyang--Li/ME149_Spring2018", "max_issues_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "supplement/fit-spline-to-data/tex/problemStatement.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": 39.8333333333, "max_line_length": 111, "alphanum_fraction": 0.6835774059, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6547733715835781}}
{"text": "\\subsection{System Identification using P. Hudzovic's method}\n\nAn extensive report on the details of P. Hudzovic's method and the accompanied\nMATLAB simulations can be found here\\cite{ref:comet}.\n\nThe method proposed by P. Hudzovic\\cite{ref:hudzovic} is based on a model that\napproximates a plant with a series of  PT1  elements  multiplied together with\nvarying time constants $T_k$ to form a PTn element, $G_n(s)$.\n\n\\begin{equation}\n    G_n(s,r) = K_s\\prod_{k=1}^{n}\\frac{1}{1+s\\cdot T_k(r)}\n    \\label{eq:pt1_series}\n\\end{equation}\n\nThe neat trick P. Hudzovic proposed was rather than having to find individual,\nindependent time constants for each PT1 element -- the effort of which greatly\nincreases with higher orders of $n$  --  one  should  instead  have a function\n$T_k(r)$  which  spaces the time constants in a meaningful  way.  He  defines:\n\n\\begin{equation}\n    T_k(r) = \\frac{T}{1-(k-1)r}\n    \\label{eq:hudzovic}\n\\end{equation}\n\nwhere  the  parameter  $r$  must  be confined to  the  interval  $0  \\le  r  <\n\\frac{1}{n-1}$.\n\nWith  this  approach  the  problem  has  effectively been reduced  to  finding\nappropriate values for $n$,  $T$,  and  $r$  such  that  the  step response of\n$G_n(s,r)$  approximates the measured step response as  closely  as  possible.\n\nIt is not possible to \\textit{directly} calculate these values, however, it is\npossible construct a lookup-table from the  equations  \\ref{eq:pt1_series} and\n\\ref{eq:hudzovic} by calculating  a  (theoretically)  infinite  number of step\nresponses  for  all  values  of  $n$,  $T$,  and $r$, characterising each step\nresponse (i.e. determine $T_u$ and $T_g$),  and performing a reverse lookup on\nthose  results  to  find  the  parameters  $n$  and  $r$.   This   method   of\nreverse-lookup   works   because   the   lookup   curves   are   monotonically\nincreasing/decreasing (see figure \\ref{fig:hudzovic}).\n\n\nIn practice, it is sufficient to calculate about 50 step  response  curves for\neach order  $n$  and  interpolate  between  those  points  when performing the\nlookup.\n\nUsing MATLAB, the lookup table is constructed and the parameters $n$, $r$, and\n$T$ are calculated based on  the  previously  determined  parameters $T_u$ and\n$T_g$. The  transfer  function  $G_2(s)$  is  calculated  and turns out to be:\n\n\\begin{equation}\n    G_2(s) = \\frac{24.68}{1.159 s^2 + 5.365 s + 1}\n\\end{equation}\n\nFigure  \\ref{fig:hudzovic_step}  shows  the  step response of  the  calculated\ntransfer  function  $G_2(s)$  and  compares it to the measured step  response.\n$G_2(s)$ seems to be a much better approximation  than  the  transfer function\n$G_1(s)$ obtained in section \\ref{sec:ident_Tt_PT1}.\n\n\nBy looking  at  the Bode-Diagram of the transfer function $G_2(s)$ (see figure\n\\ref{fig:hudzovic_bode}), we see one potential issue: This system  is a second\norder system, which means  the  phase never exceeds \\SI{180}{\\degree} and thus\nthe parameter $K_{p,crit}$ cannot be  determined  for  any finite value of the\nP-controller's gain! As a result, it will not be possible to use the method of\nZiegler-Nichols for determining controller parameters.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\imagewidth]{images/hudzovic_curves_tu_tg.pdf}\n    \\caption{Lookup curves generated with P. Hudzovic's equations. By measuring $T_u$ and $T_g$ it is possible to look up the parameters $n$, $r$ and $T$ which can be used together with equation \\ref{eq:pt1_series} to construct an accurate transfer function of the measured system.}\n    \\label{fig:hudzovic}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\linewidth]{images/hudzovic}\n    \\caption{Comparison of the calculated step response function $G_2(s)$ (using P. Hudzovic's method) and the measured step response of the motor.}\n    \\label{fig:hudzovic_step}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\linewidth]{images/hudzovic_bode}\n    \\caption{Bode-Diagram of the transfer function $G_2(s)$, acquired using P. Hudzovic's method}\n    \\label{fig:hudzovic_bode}\n\\end{figure}\n\n\\clearpage\n", "meta": {"hexsha": "43d652cced12f7383f126509a137abc929c398ad", "size": 4067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "versuche/rtGL/labor2/sections/simulations/identification_hudzovic.tex", "max_stars_repo_name": "TheComet93/laborjournal", "max_stars_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "versuche/rtGL/labor2/sections/simulations/identification_hudzovic.tex", "max_issues_repo_name": "TheComet93/laborjournal", "max_issues_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "versuche/rtGL/labor2/sections/simulations/identification_hudzovic.tex", "max_forks_repo_name": "TheComet93/laborjournal", "max_forks_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.6966292135, "max_line_length": 282, "alphanum_fraction": 0.7312515368, "num_tokens": 1213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6547733679780677}}
{"text": "\\documentclass{mrl}\n\n\\title{Discrete logarithm equality across groups}\n\\authors{Sarang Noether\\footnote{\\texttt{sarang.noether@protonmail.com}}}\n\\affiliations{Monero Research Lab}\n\\date{\\today}\n\n\\newcommand{\\hg}{\\operatorname{H}_\\mathbb{G}}\n\\newcommand{\\hh}{\\operatorname{H}_\\mathbb{H}}\n\\newcommand{\\zp}{\\mathbb{Z}_p}\n\\newcommand{\\zq}{\\mathbb{Z}_q}\n\n\\type{TECHNICAL NOTE}\n\\ident{MRL-0010}\n\n\\begin{document}\n\n\\begin{abstract}\nThis technical note describes an algorithm used to prove knowledge of the same discrete logarithm across different groups. The scheme expresses the common value as a scalar representation of bits, and uses a set of ring signatures to prove each bit is a valid value that is the same (up to an equivalence) across both scalar groups. \n\\end{abstract}\n\n\\section{Notation}\nWe use the shorthand notation $\\mathbb{Z}_n$ to mean the group $\\mathbb{Z}/n\\mathbb{Z}$. Let $\\mathbb{G}$ and $\\mathbb{H}$ be prime-order groups where the discrete logarithm problem is assumed to be hard: for example, \\texttt{secp256k1} or the $l$-subgroup of \\texttt{curve25519}. Let $G,G' \\in \\mathbb{G}$ and $H,H' \\in \\mathbb{H}$ be generators of their respective groups. Suppose $|G| = p$ and $|H| = q$. Let $\\hg: \\{0,1\\}^* \\to \\zp$ and $\\hh: \\{0,1\\}^* \\to \\zq$ be cryptographic hash functions.\n\nWithout loss of generality, assume $p \\leq q$. Choose $x \\in \\mathbb{Z}$ such that $0 \\leq x < p$. By considering the natural projections $\\mathbb{Z} \\to \\zp$ and $\\mathbb{Z} \\to \\zq$ with this domain restriction, there is a bijection between elements of $\\zp$ and the restriction of $\\zq$. Given this, we wish to prove that, given only the values $xG'$ and $xH'$ (and other proof elements as needed), the discrete logarithm of each is a representation of the same integer. In particular, we do not wish to reveal $x$ to the verifier.\n\nSince there is no meaningful map assumed between the two groups, our approach is to decompose $x$ into bits, treating each bit as a scalar in both $\\zp$ and $\\zq$ using our equivalence, and generate commitments to each bit in both groups. For each bit, we will construct a Schnorr-type ring signature showing that the bit commitment is valid and the same value in each group.\n\nThis method was originally proposed publicly by Andrew Poelstra.\n\\section{Algorithm}\n\\subsection{Prover}\nGiven an integer $0 \\leq x < p$, express in bits: $$x = \\sum_{i=0}^{n-1} b_i2^i$$ Note that because of the equivalence discussed above, each $b_i$ may be considered as an element of either $\\zp$ or $\\zq$ as needed, leading to a representation of $x$ in each group.\nFor each $i \\in [0,n-2]$, generate random blinders $r_i \\in \\zp$ and $s_i \\in \\zq$. For $i = n-1$, set blinders $$r_{n-1} = (2^{n-1})^{-1}\\sum_{i=0}^{n-2} r_i2^i \\in \\zp$$ and $$s_{n-1} = (2^{n-1})^{-1}\\sum_{i=0}^{n-2} s_i2^i \\in \\zq$$ to ensure that $\\sum_{i=0}^{n-1} r_i2^i = \\sum_{i=1}^{n-1} s_i2^i = 0$.\n\nFor each $i \\in [0,n-1]$, use the blinders to compute two Pedersen commitments:\n\\begin{eqnarray*}\nC_i^G &:=& b_iG' + r_iG \\in \\mathbb{G} \\\\\nC_i^H &:=& b_iH' + s_iH \\in \\mathbb{H}\n\\end{eqnarray*}\nBecause of this construction, the weighted commitment sums are $\\sum_{i=0}^{n-1} 2^iC_i^G = xG'$ and $\\sum_{i=0}^{n-1} 2^iC_i^H = xH'$ in their respective groups.\n\nWe next construct a ring signature on each bit to show it is either $0$ or $1$, and that the value is the same (up to our equivalence) in both groups. Specifically, for each $i \\in [0,n-1]$, we consider two cases:\n\n\\textbf{Case:} $b_i = 0$. Choose random $j_i \\in \\zp$ and $k_i \\in \\zq$. Set\n\\begin{eqnarray*}\ne_{1,i}^G &:=& \\hg\\left( C_i^G, C_i^H, j_iG, k_iH \\right) \\in \\zp \\\\\ne_{1,i}^H &:=& \\hh\\left( C_i^G, C_i^H, j_iG, k_iH \\right) \\in \\zq\n\\end{eqnarray*}\nand choose random $a_{0,i} \\in \\zp$ and $b_{0,i} \\in \\zq$. Set\n\\begin{eqnarray*}\ne_{0,i}^G &:=& \\hg\\left( C_i^G, C_i^H, a_{0,i}G - e_{1,i}^G(C_i^G-G'), b_{0,i}H - e_{1,i}^H(C_i^H-H') \\right) \\in \\zp \\\\\ne_{0,i}^H &:=& \\hh\\left( C_i^G, C_i^H, a_{0,i}G - e_{1,i}^G(C_i^G-G'), b_{0,i}H - e_{1,i}^H(C_i^H-H') \\right) \\in \\zq\n\\end{eqnarray*}\nand then define:\n\\begin{eqnarray*}\na_{1,i} &:=& j_i + e_{0,i}^Gr_i \\in \\zp \\\\\nb_{1,i} &:=& k_i + e_{0,i}^Hs_i \\in \\zq\n\\end{eqnarray*}\n\n\\textbf{Case:} $b_i = 1$. Choose random $j_i \\in \\zp$ and $k_i \\in \\zq$. Set\n\\begin{eqnarray*}\ne_{0,i}^G &:=& \\hg\\left( C_i^G, C_i^H, j_iG, k_iH \\right) \\in \\zp \\\\\ne_{0,i}^H &:=& \\hh\\left( C_i^G, C_i^H, j_iG, k_iH \\right) \\in \\zq\n\\end{eqnarray*}\nand choose random $a_{1,i} \\in \\zp$ and $b_{1,i} \\in \\zq$. Set\n\\begin{eqnarray*}\ne_{1,i}^G &:=& \\hg\\left( C_i^G, C_i^H, a_{1,i}G - e_{0,i}^GC_i^G, b_{1,i}H - e_{0,i}^HC_i^H \\right) \\in \\zp \\\\\ne_{1,i}^H &:=& \\hh\\left( C_i^G, C_i^H, a_{1,i}G - e_{0,i}^GC_i^G, b_{1,i}H - e_{0,i}^HC_i^H \\right) \\in \\zq\n\\end{eqnarray*}\nand then define:\n\\begin{eqnarray*}\na_{0,i} &:=& j_i + e_{1,i}^Gr_i \\in \\zp \\\\\nb_{0,i} &:=& k_i + e_{1,i}^Hs_i \\in \\zq\n\\end{eqnarray*}\n\nThe proof is the tuple $\\left( xG',xH',\\{C_i^G\\},\\{C_i^H\\}, \\{e_{0,i}^G\\}, \\{e_{0,i}^H\\}, \\{a_{0,i}\\}, \\{a_{1,i}\\}, \\{b_{0,i}\\}, \\{b_{1,i}\\} \\right)$.\n\n\\subsection{Verifier}\nGiven a proof tuple, we first ensure the bit commitments faithfully represent the discrete logarithm commitments by checking that the following equations hold:\n\\begin{eqnarray*}\n\\sum_{i=0}^{n-1} 2^iC_i^G &=& xG' \\in \\mathbb{G} \\\\\n\\sum_{i=0}^{n-1} 2^iC_i^H &=& xH' \\in \\mathbb{H}\n\\end{eqnarray*}\n\nFor each $i \\in [0,n-1]$, compute the following:\n\\begin{eqnarray*}\ne_{1,i}^G &:=& \\hg\\left( C_i^G, C_i^H, a_{1,i}G - e_{0,i}^GC_i^G, b_{1,i}H - e_{0,i}^HC_i^H \\right) \\in \\zp \\\\\ne_{1,i}^H &:=& \\hh\\left( C_i^G, C_i^H, a_{1,i}G - e_{0,i}^GC_i^G, b_{1,i}H - e_{0,i}^HC_i^H \\right) \\in \\zq \\\\\n(e_{0,i}^G)' &:=& \\hg\\left( C_i^G, C_i^H, a_{0,i}G - e_{1,i}^G(C_i^G-G'), b_{0,i}H - e_{1,i}^H(C_i^H-H') \\right) \\in \\zp \\\\\n(e_{0,i}^H)' &:=& \\hh\\left( C_i^G, C_i^H, a_{0,i}G - e_{1,i}^G(C_i^G-G'), b_{0,i}H - e_{1,i}^H(C_i^H-H') \\right) \\in \\zq\n\\end{eqnarray*}\nCheck that $(e_{0,i}^G)' = e_{0,i}^G$ and $(e_{0,i}^H)' = e_{0,i}^H$ from the proof tuple.\n\nIf all of these checks are successful, the verifier accepts the proof. Otherwise, it rejects the proof. The verifier is assumed to have also checked each proof tuple element to ensure it belongs to the expected group, to account for a malicious prover.\n\\end{document}", "meta": {"hexsha": "5106a75700a1dd0ed2fe0b48466d1202c81c8191", "size": 6253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/bulletins/MRL-0010-discrete/main.tex", "max_stars_repo_name": "SarangNoether/research-lab", "max_stars_repo_head_hexsha": "f6ce10547aa721c6dcd0f65f2ef89a6a5e9b34b0", "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-0010-discrete/main.tex", "max_issues_repo_name": "SarangNoether/research-lab", "max_issues_repo_head_hexsha": "f6ce10547aa721c6dcd0f65f2ef89a6a5e9b34b0", "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-0010-discrete/main.tex", "max_forks_repo_name": "SarangNoether/research-lab", "max_forks_repo_head_hexsha": "f6ce10547aa721c6dcd0f65f2ef89a6a5e9b34b0", "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": 65.8210526316, "max_line_length": 534, "alphanum_fraction": 0.6526467296, "num_tokens": 2523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6547686175231402}}
{"text": "\\chapter{Simple Induction}\n\\label{chapter:simple-induction}\n\\section{Proofs by Induction}\n\\marginurl{%\n  The Induction Principle:\\\\\\noindent\n  Introduction to Mathematical Reasoning \\#4\n}{youtu.be/jOnZTWGpX_I}\n\nLet us consider a simple problem: what is bigger $2^n$ or $n$? In this chapter,\nwe are going to study the simplest way to prove that $2^n > n$ for all positive\nintegers $n$. First, let us check that it is true for small positive integers\n$n$.\n\\begin{center}\n  \\begin{tabular}{l l l  l  l  l  l  l  l}\n    \\toprule\n          & 1 & 2 & 3 & 4  & 5  & 6  & 7   & 8   \\\\\n    \\midrule\n    $n$   & 1 & 2 & 3 & 4  & 5  & 6  & 7   & 8   \\\\\n    $2^n$ & 2 & 4 & 8 & 16 & 32 & 64 & 128 & 256 \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\nWe may also note that $2^n$ is growing faster than $n$, so we expect that if\n$2^n > n$ for small positive integers $n$, then it is true for all positive\nintegers $n$.\n\nConsider the following argument that uses proof by contradiction. Assume the\nstatement is not true; i.e., there is a positive integer $n_0$ such that \n$2^{n_0} \\le n_0$. Consider the minimal such $n_0$ and call it $n^*$; i.e.,\nconsider $n^*$ such that $2^{n^*} \\le n^*$, but $2^{n* - 1} > n* - 1$.\nNote that $2^{n* - 1} + 2^{n* - 1} > n^* - 1 + n^* - 1 = 2n^* - 2 \\ge n*$;\nhence, we get a contradiction. Therefore our assumption is false and $2^n > n$\nfor any positive integer $n$.\n\nThis argument looks simple, but it has a fatal flaw: we assume that the minimal\n$n$ exists, and it is not clear why it is true.\n\nTo overcome this problem and make this proof formal we use the following\nprinciple.\n\\begin{principle}[The Induction Principle]\n  Let $P(n)$ be some statement about a positive integer $n$.\n  Hence, $P(n)$ is true for every positive integer $n$ iff\n  \\begin{description}\n    \\item [(the base case)] $P(1)$ is true and\n    \\item [(the induction step)] $P(k - 1) \\implies P(k)$ is true\n      for all integers $k > 1$.\n  \\end{description}\n\\end{principle}\n\nLet us prove now the statement using this principle.\nWe define $P(n)$ be the statement that ``$2^n > n$''.\n$P(1)$ is true since $2^1 > 1$. Let us assume now that $2^{n - 1} > n - 1$. Note\nthat $2^n = 2 \\cdot 2^{n - 1} > 2n \\ge n - 2 \\ge n$. Hence, we proved the\ninduction step.\n\n\n\\begin{template}\n  \\textbf{Template for proving a statement using simple induction.} \\\\\n\n  We use induction by $n$. Base case for $n = 1$: \\emph{present some argument \n  that proves the statement with $n$ replaced by $1$}. \n\n  Now we need to prove the induction step from $k - 1$ to $k$. Let us assume now\n  that the statement is true for $n = k - 1$ for some $k$. \\emph{Present some\n  argument of the statement with $n$ replaced by $k$ assuming the statement is\n  true if we replace $n$ by $k - 1$}. Hence, the statement is true for all $n$\n  by the induction principle.\n\\end{template}\n\n\n\\begin{exercise}\n  Prove that $(1 + x)^n \\ge 1 + nx$ for all positive integers $n$ and real\n  numbers $x \\ge -1$.\n\\end{exercise}\n\\begin{solution}\n  We are going to prove that using induction by $n$.\n\n  The base case is clear. We prove now the induction step. Assume the\n  induction hypothesis: $(1 + x)^n \\ge 1 + nx$. Note that  $(1 + x)^{n + 1} \\ge\n  (1 + nx) \\cdot (1 + x) = 1 + nx + x + nx^2 \\ge 1 + (n + 1)x$. Which proves the\n  induction step.\n\\end{solution}\n\n\\section{Changing the Base Case}\nLet us consider the functions $n^2$ and $2^n$.\n\n\\begin{center}\n    \\begin{tabular}{l  l  l  l  l  l  l  l  l}\n        \\toprule\n              & 1 & 2 & 3 & 4  & 5  & 6  & 7   & 8   \\\\\n        \\midrule\n        $n^2$ & 1 & 4 & 9 & 16 & 25 & 36 & 49  & 64  \\\\\n        $2^n$ & 2 & 4 & 8 & 16 & 32 & 64 & 128 & 256 \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{center}\nNote that $2^n$ is greater than $n^2$ starting from $5$. But without some trick\nwe cannot prove this using induction since for $n \\le 4$ it is not true!\n\nThe trick is to use the statement $P(n)$ stating that $(n + 4)^2 < 2^{n + 4}$.\nThe base case when $n = 1$ is true.\nLet us now prove the induction step. Assume that $P(k)$ is true; i.e.,\n$(k + 4)^2 < 2^{k + 4}$. Note that $2(k + 4)^2 < 2^{k + 1 + 4}$ but\n$(k + 5)^2 = k^2 + 10k + 25 \\le 2k^2 + 16k + 32 = 2(k + 4)^2$.\nWhich implies that\n$2^{k + 1 + 4} > (k + 5)^2$. So $P(k + 1)$ is also true.\n\nIn order to avoid this strange $+ 4$ we may change the base\ncase and use the following argument.\n\n\\begin{theorem}\n\\label{theorem:induction-shifted-base}\n    Let $P(n)$ be some statement about an integer $n$.\n    Then $P(n)$ is true for every integer $n > n_0$ iff\n    \\begin{description}\n        \\item [(the base case)] $P(n_0 + 1)$ is true and\n        \\item [(the induction step)] $P(k - 1) \\implies P(k)$ is true for all\n            integers $k > n_0 + 1$.\n    \\end{description}\n\\end{theorem}\n\nUsing this generalized induction principle we may prove that $2^n \\ge n^2$ for\n$n \\ge 4$. The base case for $n = 4$ is true. The induction step is also true;\nindeed let $P(k)$ be true i.e. $(k + 4)^2 < 2^{k + 4}$. Hence,\n$2(k + 4)^2 < 2^{k + 1 + 4}$ but\n$(k + 5)^2 = k^2 + 10k + 25 \\le 2k^2 + 16k + 32 = 2(k + 4)^2$.\n\nLet us now prove the theorem. Note that the proof is based on an idea similar\nto the trick with $+ 4$, we just used.\n\\begin{proof}[Proof of Theorem~\\ref{theorem:induction-shifted-base}]\n    \\begin{description}\n        \\item[$\\Rightarrow$] If $P(n)$ is true for any $n > n_0$ it is also true\n            for $n = n_0 + 1$ which implies the base case. Additionally, it true for\n            $n = k$ so the induction step is also true.\n        \\item[$\\Leftarrow$] In this direction the proof is a bit harder. Let us\n            consider a statement $Q(n)$ saying that $P(n + n_0)$ is true. Note that\n            by the base case for $P$, $Q(1)$ is true; by the induction step for $P$\n            we know that $Q(k - 1)$ implies $Q(k)$ since $P(k + n_0 - 1)$\n            implies $P(k + n_0)$. As a result, by the induction\n            principle $Q(n)$ is true for all positive integers $n$. Which implies\n            that $P(n)$ is true for all integers $n > n_0$.\n    \\end{description}\n\\end{proof}\n\n\\section{Inductive Definitions}\n\nWe may also define objects inductively. Consider the sum\n$1 + 2 + \\dots + n$ a line of dots indicating ``and so on'' which indicates the\ndefinition by induction. In this case, a more precise notation is\n$\\sum_{i = 1}^n i$.\n\n\\begin{definition}\n    Let $a(1)$, \\dots, $a(n)$, \\dots be a sequence of integers. Then\n    $\\sum_{i = 1}^n a(i)$ is defined inductively by the following\n    statements:\n    \\begin{itemize}\n        \\item $\\sum_{i = 1}^1 a(i) = a(1)$, and\n        \\item $\\sum_{i = 1}^{k + 1} a(i) =\n            \\sum_{i = 1}^k a(i) + a(k + 1)$.\n    \\end{itemize}\n\\end{definition}\n\\nomenclature[C]{$\\sum_{i = 1}^k \\alpha_i$}{denotes $\\alpha_1 + \\dots +\n\\alpha_k$}\n\nLet us prove that $\\sum_{i = 1}^n i = \\frac{n (n + 1)}{2}$.\nNote that by definition $\\sum_{i = 1}^1 i = 1$ and\n$\\frac{1 (1 + 1)}{2} = 1$; hence, the base case holds. Assume that\n$\\sum_{i = 1}^n i = \\frac{n (n + 1)}{2}$. Note that\n$\\sum_{i = 1}^{n + 1} i = \\sum_{i = 1}^n i + (n + 1)$ and by the\ninduction hypothesis $\\sum_{i = 1}^n i = \\frac{n (n + 1)}{2}$.\nHence, $\\sum_{i = 1}^{n + 1} i = \\frac{n (n + 1)}{2} + (n + 1) =\n\\frac{(n + 1)(n + 2)}{2}$.\n\n\\begin{exercise}\n    Prove that $\\sum_{i = 1}^n 2^i = 2^{n + 1} - 2$.\n\\end{exercise}\n\n\\section{Analysis of Algorithms with Cycles}\n\nInduction is very useful for analysing algorithms using cycles. Let us extend\nthe example we considered in Section~\\ref{section:simple-algorithm}.\n\nLet us consider the following algorithm.\n\\begin{algorithm}\n  \\begin{algorithmic}[1]\n    \\Function{Max}{$a_1$, \\dots, $a_n$}\n      \\State{$r \\gets a_1$}\n      \\For{$i$ from $2$ to $n$}\n        \\If{$a_i > r$}\n          \\State{$r \\gets a_i$}\n        \\EndIf\n      \\EndFor\n      \\State\\Return{r}\n    \\EndFunction\n  \\end{algorithmic}\n  \\caption{The algorithm that finds the maximum element of $a_1$, \\dots, $a_n$.}\n\\end{algorithm}\nWe prove that it is working correctly. First, we need to define $r_1$,\n\\dots, $r_n$ the value of $r$ during the execution of the algorithm.\nIt is easy to see that $r_1 = a_1$ and\n\\[\n    r_{i + 1} =\n    \\begin{cases}\n        r_i & \\text{if } r_i > a_{i + 1} \\\\\n        a_{i + 1} & \\text{otherwise}\n    \\end{cases}.\n\\]\nSecondly, we prove by induction that $r_i$ is the maximum of $a_1$, \\dots,\n$a_i$. It is clear that the base case for $i = 1$ is true. Let us prove the\ninduction step from $k$ to $k + 1$. By the induction hypothesis, $r_k$\nis the maximum of $a_1$, \\dots, $a_k$. We may consider two following cases.\n\\begin{itemize}\n    \\item If $r_k > a_{k + 1}$, then $r_{k + 1} = r_{k}$ is the maximum of $a_1$,\n        \\dots, $a_{k + 1}$ since $r_k$ is the maximum of $a_1$, \\dots, $a_k$.\n    \\item Otherwise, $a_{k + 1}$ is greater than or equal to $a_1$, \\dots, $a_k$,\n        hence, $r_{k + 1} = a_{k + 1}$.\n\\end{itemize}\n\n\\begin{chapterendexercises}\n  \\exercise Show that there does not exist the largest integer.\n  \\exercise[recommended] Show that for any positive integer $n$, $n^2 + n$ is even.\n  \\exercise Show that for any positive integer $n$, $3$ divides $n^3 + 2n$.\n  \\exercise Show that for any integer $n \\ge 10$, $n^3 \\le 2^n$.\n  \\exercise Show that for any positive integer $n$,\n    $\\sum_{i = 0}^n x^i = \\frac{1 - x^{n + 1}}{1 - x}$.\n  \\exercise[recommended] Show that $\\sum_{i = 1}^n i^2 = \n    \\frac{n (n + 1)(2n + 1)}{6}$ for all integers $n \\ge 1$.\n    \\begin{solution}\n      We prove the statement using induction by $n$. The base case for $n = 1$\n      is clear. Let us prove the induction step now. The induction hypothesis is\n      $1^2 + 2^2 + 3^2 + \\dots + n^2 = \\frac{n (n + 1)(2n + 1)}{6}$. \n      Note that\n      \\begin{multline*}\n        1^2 + 2^2 + 3^2 + \\dots + n^2 + (n + 1)^2 = \\frac{n (n + 1)(2n + 1)}{6} +\n        (n + 1)^2 = \\\\\n        (n + 1)\\frac{2n^2 + n + 6n + 6}{6} = (n + 1)\\frac{(n + 2)(2n + 3)}{6}.\n      \\end{multline*}\n      Hence, $1^2 + 2^2 + 3^2 + \\dots + n^2 + (n + 1)^2 = \n      \\frac{(n + 1)(n + 2)(2n + 3)}{6}$.\n    \\end{solution}\n  \\exercise Show that $\\sum_{i = 1}^n \\frac{1}{i (i + 1)} = \n    \\frac{n}{n + 1}$ for all integers $n \\ge 1$.\n  \\exercise Show that $\\sum_{i = 1}^n \\frac{1}{i^2} \\le 2$ for all integers \n    $n \\ge 1$.\n    \\begin{solution}\n      Let us prove a stronger statement:\n      \\[\n        1 + \\frac{1}{2^2} + \\dots + \\frac{1}{n^2} \\le 2 - \\frac{1}{n}.\n      \\]\n\n      The base case is clear. We prove now the induction step. By the induction\n      hypothesis the following inequality holds\n      \\[\n        1 + \\frac{1}{2^2} + \\dots + \\frac{1}{(n - 1)^2} \\le 2 - \\frac{1}{n - 1}.\n      \\]\n      Hence,\n      \\[\n        1 + \\frac{1}{2^2} + \\dots + \\frac{1}{n^2} \\le 2 - \\frac{1}{n - 1} + \\frac{1}{n^2} = 2\n      \\]\n      but $\\frac{1}{n - 1} - \\frac{1}{n^2} \\ge \\frac{1}{n}$. Indeed,\n      $\\frac{1}{n - 1} \\ge \\frac{n + 1}{n^2}$ is equivalent to\n      $\\frac{1}{(n - 1)^2} \\ge \\frac{1}{n^2}$ which is true. As a result we proved\n      the induction step.\n    \\end{solution}\n  \\exercise Show that $\\sum_{i = 1}^n (2i - 1) = n^2$ for any positive integer $n$.\n  \\exercise Prove that $\\sum_{i = 1}^n \\frac{1}{i (i + 1)} = \\frac{n}{n + 1}$\n    for any positive integer $n$.\n  \\exercise Prove that $\\sum_{i = 1}^n (i + 1) 2^i = n 2^{n + 1}$ for all\n    integers $n > 2$.\n    \\begin{solution}\n      First we prove the base case for $n = 1$. Note that \n      $\\sum\\limits_{i = 1}^1 (i + 1) 2^i = 2 \\cdot 2 = 2^2$; hence, the base\n      case is true. Let us check the induction step from $k$ to $k + 1$. By\n      the induction hypothesis \n      $\\sum\\limits_{i = 1}^k (i + 1) 2^i = k 2^{k + 1}$.\n      It is clear that\n      \\begin{multline*}\n        \\sum_{i = 1}^{k + 1} (i + 1) 2^i =\n        \\sum_{i = 1}^k (i + 1) 2^i + (k + 2) 2^{k + 1} = \\\\\n          k 2^{k + 1} + (k + 2) 2^{k + 1} =\n          2 (k + 1) 2^{k + 1} = (k + 1) 2^{k + 2}.\n        \\end{multline*}\n      \\end{solution}\n  \\exercise Let $a_1$, \\dots, $a_n$ be a sequence of real numbers. We define\n    inductively\n    $\\prod_{i = k}^n a_i$ as follows:\n    \\begin{itemize}\n      \\item $\\prod_{i = 1}^1 a_i = a_1$ and\n      \\item $\\prod_{i = 1}^{k + 1} a_i =\n        \\left( \\prod_{i = 1}^k a_i \\right) \\cdot a_{k + 1}$.\n    \\end{itemize}\n    \\nomenclature[C]{$\\prod_{i = 1}^k \\alpha_i$}{denotes $\\alpha_1 \\cdot \n      \\ldots \\cdot \\alpha_k$}\n\n    Prove that\n    $\\prod_{i = 1}^{n - 1} \\left(1 - \\frac{1}{(i + 1)^2} \\right) =\n      \\frac{n + 1}{2n}$ for all integers $n > 1$.\n  \\exercise Let us define $n!$ as follows: $1! = 1$ and\n    $n! = (n - 1)! \\cdot n$. Show that $n! \\ge 2^n$ for any $n \\ge 4$.\n    \\nomenclature[C]{$\\factorial{n}$}{denotes $n \\cdot (n - 1) \\cdot (n - 2) \\cdot \\ldots\n      \\cdot 1$}\n  \\exercise[open] Find all the natural numbers $n$ such that $n! = m^2$ for some\n    integer $m$.\n  \\exercise Show that $\\int\\limits_0^{+\\infty} x^n e^{- x} ~ \\mathrm{d}x = n!$\n    for all $n \\ge 0$.\n    \\begin{solution}\n      We prove the statement using induction by $n$. The base case is for $n =\n      0$. It is easy to see that $\\int\\limits_0^{+\\infty} e^{-x} ~ \\mathrm{d}x\n      = (-e^{-x})\\big\\rvert_0^\\infty = 1$.\n \n      Let us prove the induction step from $k$ to $k + 1$. By the induction\n      hypothesis, $\\int\\limits_0^{+\\infty} x^k e^{- x} ~ \\mathrm{d}x = k!$.\n      Note that\n      \\begin{multline*}\n        \\int_0^{+\\infty} x^{k + 1} e^{- x} ~ \\mathrm{d}x = \n        -x^{k + 1} e^{- x}\\big\\rvert_0^\\infty +\n          \\int_0^{+\\infty} (k + 1) x^k e^{- x} ~ \\mathrm{d}x = \\\\\n        \\int_0^{+\\infty} (k + 1) x^k e^{- x} ~ \\mathrm{d}x = (k + 1)!.\n      \\end{multline*}\n    \\end{solution}\n  \\exercise Show that $\\sum_{k = 1}^n k \\cdot k! = (n + 1)! - 1$.\n  \\exercise Show that \\Cref{algorithm:selection-sort} executes line~6 exactly\n    $\\frac{n (n + 1)}{2}$ times.\n    \\begin{algorithm}\n      \\begin{algorithmic}[1]\n        \\Function{SelectionSort}{$a_1$, \\dots, $a_n$}\n          \\For{$i$ from $1$ to $n$}\n            \\State{$r \\gets a_i$}\n            \\State{$\\ell \\gets i$}\n            \\For{$j$ from $i$ to $n$}\n              \\If{$a_j > r$}\n                \\State $r \\gets a_j$\n                \\State $\\ell \\gets j$\n              \\EndIf\n            \\EndFor\n          \\State{Swap $a_i$ and $a_\\ell$.}\n          \\EndFor\n        \\EndFunction\n      \\end{algorithmic}\n      \\caption{The algorithm is selection sort, it sorts $a_1$, \\dots, $a_n$.}\n      \\label{algorithm:selection-sort}\n    \\end{algorithm}\n  \\exercise Show that \\Cref{algorithm:selection-sort} sorts the array.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "05b8541b8cf9c0dddf13151c6b7118792faa252e", "size": 14471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_3_simple_induction.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_3_simple_induction.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_3_simple_induction.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.9449275362, "max_line_length": 93, "alphanum_fraction": 0.5716260106, "num_tokens": 5446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.6547600838224434}}
{"text": "\n\\section{Problem Formulation}\n\\label{text:approach/formulation}\nIn this work, we are interested in finding the optimal trajectory for a robot navigating among pedestrians on the two-dimensional plane. Let $\\x_t = (x_t, y_t) \\in \\mathbb{R}^2$ and $\\dx_t = (\\dot{x}_t, \\dot{y}_t) \\in \\mathbb{R}^2 $ be the position and velocity of the robot, also referred to as $ego$, at time $t$ and $(\\x, \\dx)_{0:N}$, a trajectory over multiple position-velocity-pairs $((\\x, \\dx)_0, (\\x, \\dx)_1, (\\x, \\dx)_2, \\hdots, (\\x, \\dx)_N)$. Within this work, the robot is assumed to have double integrator dynamics. With control input $\\u_t = (u_{x, t}, u_{y, t}) \\in \\mathbb{R}^2$, we have: \n\n\\begin{equation}\n\\ddx_t = \\u_t\n\\label{eq:robot_dynamics}\n\\end{equation}\n\nFor further simplification, the robot's dynamics are assumed to be deterministic. \nThe pedestrians (also referred to as $ados$) follow single integrator dynamics. As pointed out in \\cite{Ivanovic2018}, this is a natural choice \"as a person's movements are all position-changing, e.g., walking increases position along a direction, running does so faster.\" Other standard models for pedestrian dynamics such as Social Forces \\cite{Helbing1995}, however, regard the pedestrian to be a double integrator, not a single integrator, and describe the forces acting on it introduced by other pedestrians and obstacles. Having a reasonable fast reaction time and a large maximal acceleration in comparison to the robot, both of these descriptions converge so that the single integrator model is the right choice nonetheless. \\footnote{As discussed in Chapter \\ref{text:experiments} the modular implementation allows us to use different pedestrian dynamics. When testing against other prediction environments non-single integrator dynamics are used, but most analysis described in this report relates to the single integrator model.}\n\n\\begin{align}\n\\dxped[k]_t = \\uped[k]_t\n\\label{eq:pedestrian_dynamics}\n\\end{align}\n\nEach pedestrian's future trajectory is predicted as a probabilistic and multimodal using some model $\\distmodel[]$. Thereby, let $\\xped[k]_t \\sim \\dist[k]_t$ be the distribution of the pedestrian $k$s velocity at time $t$, with mean $\\muped[k]_t$, variance $\\sigmaped[k]_t$, and mode-weights vector $\\piped[k]_t$. The prediction is based on the past states of the robot $\\x_{0:t}$ and of every pedestrian in the scene $\\xped[j]_{0:t}$, including pedestrian $k$. Moreover, the function $\\distmodel[]$ is generally not shared across all pedestrians but individually for each one.\n\n\\begin{align}\n\\xped[k]_t &\\sim \\distmodel[k]_t(\\muped[k]_t, \\sigmaped[k]_t, \\piped[k]_t) \\\\\n\\dist[k]_t &= \\distmodel[k] (\\x_{0:t}, \\xped[0]_{0:t}, \\hdots, \\xped[K]_{0:t})\n\\end{align}\n\nLike the robot, the pedestrians are modeled as single point masses, both underlying speed bounds defined by the $L_2$ norm of their velocities. Furthermore, both the robot and the pedestrians underly constraints for their minimal and maximal control effort. Thus, the sets of feasible control inputs $\n\\uset$ and $\\upedset$ respectively, are defined using the $L_1$-norm and the $L_2$-norm respectively:\n\n\\begin{align}\n\\uset &= \\{\\u | \\u \\in \\mathbb{R}^2, ||\\u||_1 \\leq u_{max}\\} \\\\\n\\upedset &= \\{\\uped[] | \\uped[] \\in \\mathbb{R}^2, ||\\uped[]||_2 \\leq \\tilde{u}_{max}\\} \n\\label{eq:controls_bounds}\n\\end{align}\n \nAll actions are assumed to take place in a free-space, two-dimensional environment. \n\\newline\nWithin project \\project, we want to find a robot trajectory $\\x_{0:T}$ over some discrete-time horizon $N$ that makes trade-offs between minimizing the travel time from its current state to some goal state in $\\xset_f = \\{\\boldsymbol{g} | \\boldsymbol{g} \\in \\xset \\}$ on the one side and the interference with the pedestrians in the scene, concerning its dynamic as well as safety boundaries, on the other side. For further simplification, perfect knowledge about the current and all past states of surrounding agents $\\xped[k]_{0:t} \\forall k \\in [0, K]$ is assumed.\n\\newline\\newline\nFor brevity of notation, in the following, the temporal index $t$ and the pedestrian index $k$ will be omitted when not necessary.\n\n", "meta": {"hexsha": "a51e847b3c216378300ea0f47fa91bd24180a78b", "size": 4138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/problem_formulation.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/problem_formulation.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/problem_formulation.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": 100.9268292683, "max_line_length": 1040, "alphanum_fraction": 0.746979217, "num_tokens": 1141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6547196561823316}}
{"text": "This section presents future approaches to optimally reduce the spread of the disease with minimal societal intervention.\n\n\\subsection{Edge Cutting}\nAll non pharmaceutical interventions (NPI) could be understood as some kind of edge removal in our graph-based approach:\n\\begin{itemize}\n\t\\item Isolation of an infected individual removes all of its edges with very high probability.\n\t\\item Quarantine of a contact person removes all of its edges with high probability.\n\t\\item Social distancing removes some edges of of many individuals.\n\t\\item Cancellation of large events remove many edges of many individuals.\n\\end{itemize}\nThese interventions can be modelled in our SIR model by modifying the diffusion rate of the agents.\nThus its effects can be evaluate qualitatively and quantitatively.\n\nBased on our graph-based approach, one could also try to compute the minimal set of interventions, which still contains the disease.\nA good proxy for this containment is to analyse the effect of these measures on $R_0$, which models how many people are infected by a single infected person.\nIt is crucial to constrain $R_0$ below one to avoid exponential growth of the number of infected individuals.\n\nIn our approach $R_0$ can be derived from the ratio of infected people of $H^{(t+1)}$ and of $H^{(t)}$:\n\\begin{equation}\n\tR_0 = \\frac{\\norm{H^{(t+1)}\\mid_{m=1}}_{0}}{\\norm{H^{(t)}\\mid_{m=1}}_{0}} %#TODO betrag\n\\end{equation}\n\nThe square matrix $C$ with dimensions $N \\times N$ models desirable edge cancellations.\nNote, that this matrix does not have to know the edges of a future time step, it only expresses which edges must not exist.\nIt is multiplied element-wise onto the adjacency matrix $A$, thus $\\bar{A} = A \\odot C$ describes a adjacency matrix with applied cancellations.\n\nTo optimally limit the spread of the disease, we seek to minimize the number of cancellations $\\norm{C}_0$, given that $R_0$ is below one:\n\\begin{equation}\n\t\\max_{C} \\norm{C}_0\\text{, s.t. }R_0 < 1\n\\end{equation}\nAlternatively\n\n\\begin{equation}\n\t\\max_{C} \\norm{C}_0\\text{, s.t. } \\norm{H^{(t+1)}\\mid_{m=1}}_{0} <= KapaLimit\n\\end{equation}\n\n% Future Work: This would be more powerful, if there would be some different kinds of edges (social, work, education, large events, etc.)\\\\\n% Future Work: This only takes the current time step into account but it would be desirable to look even further into the future.\n\n\\subsection{Test Prioritization}\nWhen tests are limited, they should be used to discover as much as possible about the health state of the overall population.\nThis in turn allows to reduce the $R_0$ value in further time steps as edge cutting becomes more efficient.\n\nLets assume there are $t_{\\text{max}}$ tests per time step.\nA test reveals the true health state of an individual (ignoring false negatives and false positives)\n\\begin{equation}\n\th_{{v}_i}^{(t)} \\xrightarrow{\\text{test}} h_{{v}_i}^{(t+1)} \\in \\{\\vec{e}_0, \\vec{e}_1, \\vec{e}_2 \\}\n\\end{equation}\n\nThe test assignment $T$ with dimension $N$ is a binary variable describing which individuals should be tested.", "meta": {"hexsha": "8b1c0cf8526ac905065469e1cbf43fe9f5f6ac5b", "size": 3064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/outlook.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/outlook.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/outlook.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": 61.28, "max_line_length": 157, "alphanum_fraction": 0.7610966057, "num_tokens": 797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.654719649354235}}
{"text": "\\section{The Square Root of 2}\n\n\\begin{frame}\n  \\begin{columns}\n    \\begin{column}{0.3\\textwidth}\n      \\centering\n      \\begin{tikzpicture}\n        \\draw[draw=gmitblue] (0,0) --node [midway, left, black] {$1$} (0,3) -- (3,3) -- (3,0) --node [midway, below, black] {$1$} (0,0);\n        \\draw[gmitred] (3,0) -- (0,3) node [midway, above right, black] {$\\sqrt{2}$};\n      \\end{tikzpicture}\n    \\end{column}\n    {\\color{gmitgrey!30}\\vrule{}} \\hspace{0.1\\textwidth}\n    \\begin{column}{0.5\\textwidth}\n      $\\sqrt{2} \\times \\sqrt{2} = 2$ \\\\[16mm]\n      $d^2 = l^2 + w^2$ \\\\[4mm]\n      $d^2 = 1^2 + 1^2$ \\\\[4mm]\n      $d = \\sqrt{2}$ \\\\[8mm]\n    \\end{column}\n  \\end{columns}\n\\end{frame}\n\n\n\\begin{frame}\n  \\begin{columns}\n    \\begin{column}{0.3\\textwidth}\n      \\color{gmitblue} \\fontsize{30}{10}\n      \\[\\frac{a}{b}\\]\n    \\end{column}\n    {\\color{gmitgrey!30}\\vrule{}} \\hspace{0.1\\textwidth}\n    \\begin{column}{0.5\\textwidth}\n      $\\sqrt{2} = \\dfrac{a}{b}$ \\\\[8mm]\n      $\\Rightarrow 2 = \\dfrac{a^2}{b^2}$ \\\\[8mm]\n      $\\Rightarrow 2b^2 = a^2$ \\\\[8mm]\n      $\\Rightarrow 2 \\mid a^2$ \\\\[8mm]\n      $\\Rightarrow 2 \\mid a$\n    \\end{column}\n  \\end{columns}\n\\end{frame}\n\n\n\\begin{frame}\n  \\begin{columns}\n    \\begin{column}{0.3\\textwidth}\n      \\color{gmitblue} \\fontsize{30}{10}\n      \\[2 \\mid a\\]\n    \\end{column}\n    {\\color{gmitgrey!30}\\vrule{}} \\hspace{0.1\\textwidth}\n    \\begin{column}{0.5\\textwidth}\n      $2 \\mid a$ \\\\[8mm]\n      $\\Rightarrow 4 \\mid a^2$ \\\\[8mm]\n      $\\Rightarrow 4 \\mid 2b^2$ \\\\[8mm]\n      $\\Rightarrow 2 \\mid b^2$ \\\\[8mm]\n      $\\Rightarrow 2 \\mid b$\n    \\end{column}\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}[standout]\n\n\\begin{quote}\n  A number is rational if and only if its decimal expansion becomes periodic.\n\\end{quote}\n\n\\end{frame}\n", "meta": {"hexsha": "d33248c49408b218f6468653e05eb992b6ab187d", "size": 1756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content.tex", "max_stars_repo_name": "ianmcloughlin/slides-sqrt2", "max_stars_repo_head_hexsha": "ee0e04fef1804700e4de2551cc31c838ebb021dc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content.tex", "max_issues_repo_name": "ianmcloughlin/slides-sqrt2", "max_issues_repo_head_hexsha": "ee0e04fef1804700e4de2551cc31c838ebb021dc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content.tex", "max_forks_repo_name": "ianmcloughlin/slides-sqrt2", "max_forks_repo_head_hexsha": "ee0e04fef1804700e4de2551cc31c838ebb021dc", "max_forks_repo_licenses": ["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.0153846154, "max_line_length": 136, "alphanum_fraction": 0.555808656, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6547000801108365}}
{"text": "\\label{Ch:4}\nIn this section, we describe our data-driven inverse reinforcement learning based social navigation pipeline.\\\\\n%\\\\ \\textbf{An image showing the block diagram of the pipeline including the environment, the feature extractor, and the other components}\n\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{figures/irl_pipeline.png}\n\t\\caption{An overview of the proposed navigation pipeline. The feature extractor filters data from the environment before relaying it into the RL module. Using the reward network, the RL algorithm trains an optimal policy. The difference between the state visitation frequency of the optimal policy and that of the expert is then utilized to update the parameters of the reward network. On completion, we obtain a reward function and an optimal policy corresponding to that reward function.}\n\t\\label{fig:irl_pipeline}\n\\end{figure}\n\n\\section{The IRL block:}\nInverse reinforcement learning(IRL) or inverse optimal control (IOC) has been extensively explored to train robots in real-world tasks. The appeal of IRL is that it removes the need to manually construct a reward function that dictates the optimal behavior of an agent. Instead, a reward function that induces the desired behavior can be recovered from a set of expert demonstrations which is more readily available compared to an artificially constructed reward structure as needed in reinforcement learning (RL).\n\nTo keep the chapter self-contained, we will briefly recap our definition of a Markov decision process (MDP):\nA Markov decision process or MDP can be defined as a tuple ($\\mathcal{S}$,$\\mathcal{A}$,T,$\\gamma$, $\\mathcal{R}$)  where,\n\\begin{itemize}\n    \\item $\\mathcal{S}$ is the set of all possible states.\n    \\item $\\mathcal{A}$ is the set of all possible actions.\n    \\item T is the state transition dynamics, i.e. the probability of moving to a state given its previous state and action, $P(s^{'}|s, a)$.\n    \\item $\\gamma$ is the discounting factor.\n    \\item $\\mathcal{R}$ is the set of rewards $R:  \\mathbf{f}_{s} \\mapsto \\mathbb{R} $ is the reward function, where $\\mathbf{f_{s}}$ is the feature vector obtained from state $s \\in \\mathcal{S}$.\n    \\begin{align}\n    \\phi(s) &= \\mathbf{f}_{s} \\\\\n    \\mathbf{f}_{\\tau} &= \\sum_{s \\in \\tau} \\mathbf{f}_{s}\n    \\end{align}\n    where $\\phi(.)$ is the feature extractor function used, and $\\mathbf{f}_{\\tau}$ is the feature vector corresponding to a given trajectory $\\tau$ \n    \\end{itemize}  \nThe goal of IRL is to infer a reward function that maximizes the likelihood of the expert behavior. The expert behavior is represented in terms of expert demonstrations or trajectories, $\\mathbf{D} = \\{ \\tau_1, \\tau_2, \\tau_3, \\dots, \n\\tau_{M} \\}$ in the context of navigation. Each of these trajectories, in turn, can be further broken down into a collection of states $\\tau_{i} = \\{ s_{0}, s_{1}, s_{2}, \\dots, s_{T} \\}$ as visited by the expert in the trajectory. \\\\ Abbeel and Ng\n\\cite{abbeel_apprenticeshiplearning_2004} shows that solving the Bellman equations for an analytic solution to obtain the reward $\\mathcal{R}$ is under-constrained. Ziebart et al. \\cite{ziebart_maxent_2008} addresses this by introducing an entropy-based constraint \\cite{jaynes1957information} on the distribution of the trajectories which state that the probability of the occurrence of a trajectory is directly proportional to the reward it receives which is equal to the summation over the reward it receives at each state in the trajectory.\n\\begin{align}\nP(\\tau_{i}| \\theta) = \\frac{1}{Z(\\theta)}\\exp^{\\theta^{T}\\mathbf{f}_{\\tau_{i}}} = \\frac{1}{Z(\\theta)}\\exp^{\\sum_{s_{j}\\in\\tau_{i}}\\theta^{T}\\mathbf{f}_{s_{j}}}\n\\end{align}\n\\begin{align}\nZ = \\sum_{\\tau_{i}\\in \\mathbf{D}}\\exp{\\theta^{T}\\mathbf{f}_{\\tau_{i}}}\n\\end{align}\nwhere, $Z$ is the normalizing term, $\\theta$ are the weights of the reward function, and $\\mathbf{D}$ is the set of all possible trajectories.\\\\\nGiven a set of expert demonstrations, an optimal reward structure should maximize the probability of the occurrence of the expert demonstrations and their associated states. Mathematically, this is given by: \n\\begin{align}\n\\label{eq:loglikelihood-IRL}\n\\theta^{*} = \\argmax_{\\theta} \\mathbf{L}(\\theta) = \\argmax_{\\theta} \\sum_{\\tau \\in D} \\log{P(\\tau| \\theta, T)}\n\\end{align}\nZiebart et al. \\cite{ziebart_maxent_2008} uses a linear combination of weights which lacked the ability to capture complex non-linear reward functions. This drawback was alleviated by Wulfmeier et al. where they restructure the maximum entropy IRL formulation using neural networks \\cite{wulfmeier2015maximum}. Neural networks are universal function approximators. This vastly increases the amount of complexity a reward function can express.\\\\\nThe parameters of the reward network, $\\mathbf{R}_{\\theta}$ represented by $\\theta$ can be found using gradient descent methods. The  update term for the reward network parameters w.r.t. the loss term $\\mathbf{L}$ is equal to the difference in the state visitation frequencies (SVF) of the expert demonstrations and the optimal policy $\\pi_{\\psi} : \\eta(s) \\mapsto \\mathcal{A} $, trained on the parameters of the current reward network $R_{\\theta}$:\n\\begin{align}\n\t\\label{eq:IRL-parameter-update-states}\n\t\\frac{\\partial \\mathbf{L}}{\\partial \\theta} = \\left(\\sum_{\\tau_{i} \\in D}\\sum_{s_{j} \\in \\tau{i}}s_{j} - \\sum_{\\hat{\\tau} \\in \\hat{D}}\\sum_{s_{k} \\in \\hat{\\tau}}s_{k}\\right)\n\\end{align}\nwhere, $\\hat{\\tau}$ is a trajectory sampled by the policy $\\pi_{\\psi}$.\\\\\nReplacing a state, $s_{i}$, by its features, $\\phi(s_{i})$, \\autoref{eq:IRL-parameter-update-states} can be re-written as:\n\\begin{align}\n\t\\label{eq:IRL-parameter-update-features}\n\t\\frac{\\partial \\mathbf{L}}{\\partial \\theta} = \\left(\\expectval_{s \\sim P(s|\\mathcal{D})} \\phi(s) - \\expectval_{s \\sim P(s|\\pi_\\psi)} \\phi(s)\\right) \\frac{\\partial R_\\theta}{\\partial \\theta} \n\\end{align}\nwhere, $P(s|\\mathcal{D})$ and $P(s|\\pi_{\\psi})$ are the probability of occurrence of state $s$ following the expert demonstrations $\\mathcal{D}$ and policy $\\pi_{\\psi}$ respectively.\n%\\thcomment{All the symbols have been defined before. Do I still need to redefine them after each equation?}\n\\subsection{The SVF calculation}\nOne of the main challenges of IRL is calculating the expected state distribution or the state visitation frequency (SVF) of a policy $\\pi_{\\psi}$. The SVF is calculated over all possible trajectories, which is computationally expensive for environments with large but finite state-spaces and intractable for continuous state-spaces. In model-based environments with finite state-space, this can be calculated using the state transition matrix and dynamic programming \\cite{wulfmeier2015maximum}. Access to the underlying state-dynamics of an environment, especially in real-world applications like navigation, is difficult and not readily available. Instead, we relax this by assuming a model-free but deterministic environment.\\\\\n%\\edited{This is a reasonable assumption in the context of a navigation robot because the movements of an agent given a control command are inherently deterministic.}\n%\\thcomment{The reason the environment is deterministic is because the movement of the other pedestrians in the environment are dictated by an annotation-file (as they are data from a real video), which is deterministic. I am finding it hard to reason for why a deterministic environment other that the aforementioned fact. Should I just state this?} \n%This is a reasonable assumption in the context of a navigation problem because the movements of pedestrians, in general, are inherently deterministic. %and any observed uncertainty by the agent can be attributed to the error in measurement by the onboard sensors.\\\\\n\nWe use sampling to get an estimate of the SVF. While this can be time-consuming and computationally expensive, the task is drastically simplified when using greedy policies, especially in a deterministic environment. SVF calculation of a greedy policy in a deterministic environment can be calculated by taking a single sample trajectory (due to the deterministic nature of the environment) for each pedestrian by replacing them with the agent and letting it run till completion. The calculation of the expected state visitation frequency of the agent is shown in equation \\autoref{eq:svf-sampling}\n\n\\begin{align}\n\\label{eq:svf-sampling}\n   \\expectval_{s \\sim P(s|\\pi_\\psi)} \\phi(s) \\approx \\sum_{s_0 \\in p_0} \\sum_{t=0}^{T} \\phi(\\hat{P}(s_{t+1}|s_t, a_t)\\pi_\\psi(a_t|s_t))\n\\end{align}\nwhere, $\\phi(s)$ is the features representation of state $s$, $P(s|\\pi_{\\psi})$ is the probability of state $s$ given policy $\\pi_{psi}$, $\\pi_{\\psi}(a_{t}|s_{t})$ is the action taken at time $t$ in state $s_{t}$ according to the policy $\\pi_{\\psi}$, $s_{0}$ is the starting state, $T$ is the time horizon, and, $\\hat{P}(s_{t+1}| s_{t}, a_{t})$ are the state transitions observed during the process of sampling the trajectories from the environment, and not from a known state transition model.\n%The original formulation of maximum entropy deep inverse reinforcement learning (MEDIRL) is in a model-based setting and the state transition matrix is used to calculate the state visitation frequency (SVF) of the agent. While this produces an exact value of the agent's SVF, assuming the availability of the state transition matrix is fairly optimistic for most real-world tasks including navigation. In an attempt to make things less constrained we take the model-free approach and focus on calculating the SVF using a sampling-based method. \n%The SVF calculation:\n%The main challenge of going model-free is the calculation of the normalizing factor(Z), which in the presence of a state transition matrix could be calculated using dynamic programming [citation of the paper]. \n%Under the assumption of a model-free but deterministic environment, the SVF of a policy can be reasonably computed by taking trajectory samples from the starting context of each of the existing pedestrians in the scene once. \n%\\begin{align}\n%equation 4 from iros2020\n%\\end{align}\n%where the $\\mathcal{P}$ represents state transitions obtained from sampling and not the state transition dynamics. \\textbf{We argue that this assumption is reasonable in a navigation setting because the task is not inherently uncertain, and most transition dynamic uncertainty can be attributed to sensory noise and control error. We summarize our approach in algorithm 1. (Taken word-to-word from IROS manuscript)}\n\\begin{algorithm}[tbhp]\n\t\\caption{Maximum Entropy Deep Deterministic IRL}\n\t\\label{deterministic-medirl}\n\t\n\t\\SetKwInOut{Input}{Input}\n\t\\SetKwInOut{Output}{Output}\n\t\n\t\\Input{$D, \\gamma, p_0$}\n\t\n\t\\SetKwComment{Comment}{$\\triangleright$\\ }{}\n\t\\SetKwFunction{Backprop}{Backprop}\n\t\\SetKwFunction{UpdateWeight}{UpdateWeight}\n\t\\SetKwFunction{SolveMDP}{SolveMDP}\n\t\\BlankLine\n\t$\\theta, \\psi \\gets \\theta_0, \\psi_0$ \\DontPrintSemicolon \\Comment*[r]{Initialize parameters} \n\t$\\mu_e= \\expectval_{s \\sim D}{\\phi(s)}$ \\DontPrintSemicolon \\Comment*[r]{Calculate expert svf}\n\t\\For{$m \\gets 1$ \\KwTo M}{\n\t\t$\\pi_\\psi^m \\gets \\SolveMDP(R_\\theta^m,\\mathcal{S}, \\mathcal{A}, \\mathcal{T}, \\gamma)$\\\\\n\t\t$\\delta_{\\text{svf}} = \\mu_e - \\expectval_{s \\sim P(s|\\pi_\\psi^m)} \\phi(s)$ \\Comment*[r]{from \\autoref{eq:svf-sampling}} \n\t\t$\\frac{\\partial L}{\\partial \\theta^m} = $ \\Backprop($\\theta^m, \\delta_{\\text{svf}}$) \\\\\n\t\t$\\theta^{m+1} \\gets $ \\UpdateWeight($\\frac{\\partial L}{\\partial \\theta^m}, \\theta^m$) \n\t}\n\t\\BlankLine\n\t\\Output{optimal parameters $\\theta, \\psi$}\n\t\n\\end{algorithm}\n\nThe expert policy needs to be retrained every time the parameters of the reward network are updated. We solve the MDP using an actor-critic method \\cite{mnih_actor_critic_2016}.\n\n%\\subsection*{Overview of the algorithm used}\n%The algorithm trains for two networks, the reward network that, given the features of a state returns the reward associated with it,\\\\\n%\\textbf{equation}\\\\ stating this.\n%and the policy network, which given the same, returns the best possible action.\\\\\n%\\textbf{equation}\\\\\n%The method starts with randomly initializing the weights of the reward network. This reward network is then used in the  RL block to train an agent which is optimal for the current reward structure. Once, an optimal policy is obtained, the policy is then sampled from, in the environment to obtain roll-outs or trajectories in this case. A trajectory is given by the sequence of states visited by the agent {s1, s2, ... sn}.\n%Once the trajectories are obtained, they are used to calculate the state visitation frequency. The difference between the expert and the agent SVF is used to calculate the loss\n%\\textbf{equation}\n%This loss is then backpropagated through the reward network to update the weights.\n%Once the weights are updated, the new network is again fed into the RL block. This iterative process continues until completion.\n%Explanation of the L1 regularization over l2 regularization \n\n\\section*{The RL block:}\n\nActor-critic methods are a class of reinforcement learning algorithms that are built upon policy gradient methods. \nIn policy-gradient methods, the goal is to iteratively improve the performance of a given policy. This is achieved by maximizing the expected return of the policy. Mathematically, the objective of a policy gradient method can be expressed as:\n\\begin{align}\nmaximize \\;\\; J( \\psi )  &\\; = \\; \\mathbb{E} [ R | \\pi_{\\psi} ] \\\\\n                       & \\; = \\; \\mathbb{E}[ \\sum^{T-1}_{t=0} r_{t+1}| \\pi_{\\psi}] \n\\end{align}\nwhere, $r_{t}$ is the reward obtained at time $t$ and $\\pi_{\\psi}$ is the policy with parameters $\\psi$.\\\\\nThis leads to an update function:\n\\begin{align}\n\\label{eq:policy-gradient-update}\n\\nabla_{\\psi} J (\\psi) = \\sum_{t=0}^{T-1} \\nabla_{\\theta}\\log \\pi_{\\psi}(a_{t}|s_{t})\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'}\n\\end{align} \nwhere, $\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'}$ is the cumulative discounted reward obtained by following the policy $\\pi_{\\psi}$ from time $t'$. The term,  $\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'}$ is the $Q$ value of the state-action pair $(s_{t}, a_{t})$.\\\\\nIn an actor-critic system, there are two networks. The critic network is responsible for estimating the value function of a state and the actor network updates the policy based on the recommendation from the critic.\nStandard policy gradient methods suffer from high variance because they do not have a normalizing factor for the second term from \\autoref{eq:policy-gradient-update}. This is addressed by introducing a baseline.\n\\begin{align}\n\\label{eq:policy-gradient-update-baseline}\n\\nabla_{\\psi} J (\\psi) = \\sum_{t=0}^{T-1} \\nabla_{\\theta}\\log \\pi_{\\psi}(a_{t}|s_{t})\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'} - \\mathbf{b}(s_{t})\n\\end{align}\nwhere, $\\mathbf{b}(s_{t})$ is a baseline measurement for state $s_{t}$.\n The baseline can be calculated in various ways. One of the resulting algorithms is the Advantage actor-critic algorithm or A2C\\cite{mnih_actor_critic_2016}, where the $V$ value of a state acts as the baseline function. In this case, the `advantage' is the difference between the estimated $V$ value of a state at time $t$, $V(s_t)$ and the discounted cumulative reward obtained by following the policy $\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'}$ as shown in \\autoref{eq:advantage-eq}.\\\\\n\\begin{align}\n\\label{eq:advantage-eq}\nA(s_{t}, a_{t}) = \\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'} - V(s_{t}, a_{t})\n\\end{align}\nThe update equations for the actor and critic network in A2C is given by \\autoref{eq:advantage-actor-update} and \\autoref{eq:advantage-critic-update} respectively.\n\\begin{align}\n\\label{eq:advantage-actor-update}\n\\nabla_{\\psi} J (\\psi_{a}) = & \\sum_{t=0}^{T-1} \\nabla_{\\theta}\\log \\pi_{\\psi}(a_{t}|s_{t}) \\left(\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'} - V_{v}(s_{t})\\right)\\\\\n\\label{eq:advantage-critic-update}\n\\nabla_{\\psi} J (\\psi_{c}) = & \\sum_{t=0}^{T-1} \\left(\\sum_{t'=t+1}^{T} \\gamma^{t'-t-1} r_{t'} - V_{v}(s_{t})\\right)\n\\end{align} \nFor our implementation, instead of having two separate networks for the actor(policy) and the critic(value), we design the network in a way that the actor, $\\psi_{a}$, and the critic, $\\psi_{c}$, share parameters in input and the hidden layers, with a dedicated output layer for the action and value respectively.\n\n%The A2C method:\n%Two symbiotic agents at play here. The actor and the critic. \n%The critic estimates the value function of a given state.\n%The actor uses this information to update its policy distribution.\n\\vfill\n\\begin{algorithm}[tbhp]\n\t\\caption{RL algorithm: Actor Critic}\n\t\\label{alg:actor-critic}\n\t\\SetKwInOut{Input}{Input}\n\t\\SetKwInOut{Output}{Output}\n\t\\Input{$R, \\gamma, p_0$}\n\t\n\t\\SetKwComment{Comment}{$\\triangleright$\\ }{}\n\t\\SetKwFunction{Backprop}{Backprop}\n\t\\SetKwFunction{UpdateWeight}{UpdateWeight}\n\t\\SetKwFunction{SolveMDP}{SolveMDP}\n\t\\BlankLine\n\t$\\psi \\gets \\psi_0$ \\DontPrintSemicolon \\Comment*[r]{Initialize parameters} \n\n\t\\For{$m \\gets 1$ \\KwTo M}{\n\t\tSample $\\{s_{i}, a_{i} \\}$ from $\\pi_{\\psi}$ till termination of an episode.\\\\\n\t\t$\\hat{A}(s_{i}, a_{i})$ = $\\sum_{t'=i+1}^{T} \\gamma^{t'-i-1} r_{t'} - \\pi_{\\psi_{c}}(s_{i})$ \\Comment*[r]{Calculate advantage}\n\t\t$\\mathbf{L_{act}}$ = $\\sum \\log{\\pi_{\\psi_{a}}(a_{i}| s_{i})}\\hat{A}(s_{i}, a_{i})$  \\Comment*[r] {Calculate actor loss}\n$\\mathbf{L_{crit}}$ = $\\sum \\hat{A}(s_{i}, a_{i})$ \\Comment*[r]{Calculate critic loss}\n\t\t$\\frac{\\partial \\mathbf{L}}{\\partial \\psi^m} \\gets $ \\Backprop($\\mathbf{L}_{act} + \\mathbf{L}_{crit}$) \\\\\n\t\t$\\psi^{m+1} \\gets $ \\UpdateWeight($\\frac{\\partial \\mathbf{L}}{\\partial \\psi^m}, \\psi^m$) \n\t}\t\n\t\\BlankLine\n\t\\Output{optimal parameters $\\psi$}\n\t\n\\end{algorithm}\n\n\n\\section{The Feature extractor}\nThe feature extractor is a vital component in the navigation pipeline. It acts as a mechanism that facilitates interaction between the learning algorithm and the environment and heavily influences the performance of the agent \\cite{vasquez_inverse_2014}. We assume the following information available to us: the current position and velocity of the agent, the position of the goal, and the position and velocity of all the pedestrians present in the frame. Although we have access to information about all the pedestrians, the feature representations are designed to be calculated from a partial observation of the environment.\\\\\nThe feature representation consists of the following components:\n\\begin{itemize}\n    \\item The \\textbf{local component} contains information from the vicinity of the agent captured in the form of a binary feature vector. This provides an approximate idea of the nearby obstacles and an estimate of a likely collision. Hence the term: `risk-features'. \n    \\item The \\textbf{global component}, on the other hand, provides an approximation of the goal location on the map. \n\\end{itemize}\n We assume the following information available to us: the current position and velocity of the agent, the position of the goal, and the position and velocity of all the obstacles (pedestrians) in the current frame.  Having access to all this information using sensors on a mobile robot navigating the real world is highly unlikely and difficult to obtain. This is additionally addressed by the feature extractor, which also acts as an information moderator, receiving raw information from the environment and packaging it in a feature vector that can be readily constructed by a mobile robot on the go using off-the-shelf sensors.\\\\\n Both the local and the global components along with their sub-components are described in greater detail below.\n\n\\subsection*{The global component}\nThe global information is further comprised of 4 elements: relative goal orientation, change in orientation, deviation from the goal and speed. Each of them are explained below.\n\\subsubsection*{Relative goal orientation} \nThis acts as a compass, providing a rough estimate of the direction of the goal based on the current position and orientation of the agent. This is denoted by a $9 \\times 1$ indicator variable, where the presence of the goal in any one of the bins is marked by a $1$ keeping the rest to $0$. The $360 \\degree$ around the agent is divided into $8$ equal divisions forming the first 8 bins of $45 \\degree$ each. The $9^{th}$ bin denotes the contact of the agent with the goal.\n\\begin{table}[tbhp]\n\t\\label{tab:goal-vector-bins}\n\t\\begin{center}\n\t\t \\renewcommand{\\arraystretch}{1.3}\n\t\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\t\\textbf{Feature} & \\textbf{Threshold} \\\\\n\t\t\t\\hline\n\t\t\t$\\phi_{GV1}$ & $\\alpha_{GV} \\in \\left[ \\frac{15\\pi}{8} , 2\\pi \\right) \\cup \\left[ 0, 2\\pi \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV2}$ & $\\alpha_{GV} \\in \\left[ \\frac{\\pi}{8} , \\frac{3\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV3}$ & $\\alpha_{GV} \\in \\left[ \\frac{3\\pi}{8} , \\frac{5\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV4}$ & $\\alpha_{GV} \\in \\left[ \\frac{5\\pi}{8} , \\frac{7\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV5}$ & $\\alpha_{GV} \\in \\left[ \\frac{7\\pi}{8} , \\frac{9\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV6}$ & $\\alpha_{GV} \\in \\left[ \\frac{9\\pi}{8} , \\frac{11\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV7}$ & $\\alpha_{GV} \\in \\left[ \\frac{11\\pi}{8} , \\frac{13\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GV8}$ & $\\alpha_{GV} \\in \\left[ \\frac{13\\pi}{8} , \\frac{15\\pi}{8} \\right)$ \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Bin thresholds for goal vector features.}\n\\end{table}\n\n\\begin{figure}[tbhp]\n\t\\centering\n\t\\begin{tikzpicture}[scale=2.5]\n\t\n\t\\fill [fill=green, opacity=0.0] (0.0,0.0) circle [radius=1.5];\n\t\\draw [fill=green, opacity=0.3] \n\t(0,0) -- (-1.5,0) arc(180:135:1.5) -- cycle;\n\t\n\t\\draw [fill=black] (0,0) circle [radius=0.1];\n\t\\draw [->, ultra thick] (0,0) -- (22.5:1.5);\n\t\n\t\\draw [fill=green] (-0.6,0.3) circle [radius=0.1];\n\t\\draw [->, ultra thick, green] (0,0) -- (-0.6,0.3);\n\t\n\t\\draw [dashed, thick] (0,0) -- (0:1.5);\n\t\\draw [dashed, thick] (0,0) -- (45:1.5);\n\t\\draw [dashed, thick] (0,0) -- (90:1.5);\n\t\\draw [dashed, thick] (0,0) -- (135:1.5);\n\t\\draw [dashed, thick] (0,0) -- (180:1.5);\n\t\\draw [dashed, thick] (0,0) -- (225:1.5);\n\t\\draw [dashed, thick] (0,0) -- (270:1.5);\n\t\\draw [dashed, thick] (0,0) -- (315:1.5);\n\t\n\t\n\t\n\t\n\t\\node at (15.5:1.2) {$\\phi_{GV1}$};\n\t\\node at (67.5:1.2) {$\\phi_{GV2}$};\n\t\\node at (115.5:1.2) {$\\phi_{GV3}$};\n\t\\node at (155.5:1.2) {$\\phi_{GV4}$};\n\t\\node at (205.5:1.2) {$\\phi_{GV5}$};\n\t\\node at (247.5:1.2) {$\\phi_{GV6}$};\n\t\\node at (295.5:1.2) {$\\phi_{GV7}$};\n\t\\node at (340.5:1.2) {$\\phi_{GV8}$};\n\t\n\t\\end{tikzpicture}\n\t\n\t\\caption{Goal vector bin representation. The black disk at the center of the diagram and the black arrow represents the agent's position and heading respectively. The green disk depicts the goal position, and since it lies in $\\phi_{GV4}$ that bin is currently active. Note that the features are relative to the agent's orientation and thus rotate with the agent.}\n\t\\label{fig:goal-vector-diagram}\n\\end{figure}\n\n\\subsubsection*{Change in orientation}\nRepresented by a $5 \\times 1$ indicator variable, the change in orientation captures the magnitude of the change in the orientation of the agent in consecutive steps. The value ranges between $0 \\degree$ -  $ 180 \\degree$. This value is allocated to one of 5 asymmetric bins. The rationale behind the uneven distribution is that we have observed empirically that human motion is smooth. The bins are thus constructed in a way to put greater emphasis on smaller changes in orientation. This helps capture the nuances in human motion in greater detail leading to better encapsulation of the essence of the navigational pattern. The division of the range is shown in \\autoref{tab:orientation-change-bins}.\n\n\\begin{table}[!htbp]\n\n    \\begin{center}\n        \\renewcommand{\\arraystretch}{1.3}\n        \\begin{tabular}{|c|c|}\n            \\hline\n            \\textbf{Feature} & \\textbf{Threshold} \\\\\n            \\hline\n            $\\phi_{O1}$ & $\\alpha_{OC} \\in \\left[ 0 , \\frac{\\pi}{9} \\right)$ \\\\\n            \n            $\\phi_{O2}$ & $\\alpha_{OC} \\in \\left[ \\frac{\\pi}{9} , \\frac{2\\pi}{9} \\right)$ \\\\\n            \n            $\\phi_{O3}$ & $\\alpha_{OC} \\in \\left[ \\frac{2\\pi}{9} , \\frac{3\\pi}{9} \\right)$ \\\\\n    \n            \n            $\\phi_{O5}$ & $\\alpha_{OC} \\in \\left[ \\frac{3\\pi}{9} , \\frac{4\\pi}{9} \\right)$ \\\\\n            \n            $\\phi_{O6}$ & $\\alpha_{OC} \\in \\left[ \\frac{4\\pi}{9} , \\pi \\right)$ \\\\\n            \\hline\n        \\end{tabular}\n        \\caption{Bin thresholds orientation change features.}\n    \\label{tab:orientation-change-bins}\n    \\end{center}\n\\end{table}\n\\subsubsection*{Deviation from the goal}\nThe deviation from goal captures the magnitude of the angle between the vector to the goal from the current position of the agent and the current orientation vector of the agent. The value ranges from $0 \\degree$ - $ 180 \\degree$ which is again asymmetrically divided into 4 bins ($4 \\times 1$ indicator variable), with greater emphasis on the smaller angles as described earlier (\\autoref{tab:deviation-from-goal-bins}). \n\n\\begin{table}[!htbp]\n    \\begin{center}\n        \\renewcommand{\\arraystretch}{1.3}\n        \\begin{tabular}{|c|c|}\n            \\hline\n            \\textbf{Feature} & \\textbf{Threshold} \\\\\n            \\hline\n            $\\phi_{GA1}$ & $\\alpha_{GA} \\in \\left[ 0 , \\frac{\\pi}{8} \\right)$ \\\\\n            \n            $\\phi_{GA2}$ & $\\alpha_{GA} \\in \\left[ \\frac{\\pi}{8} , \\frac{\\pi}{4} \\right)$ \\\\\n            \n            $\\phi_{GA3}$ & $\\alpha_{GA} \\in \\left[ \\frac{\\pi}{4} , \\frac{3\\pi}{4} \\right)$ \\\\\n            \n            $\\phi_{GA4}$ & $\\alpha_{GA} \\in \\left[ \\frac{3\\pi}{4} , \\pi \\right]$ \\\\\n            \\hline\n        \\end{tabular}\n        \\caption{Bin thresholds for deviation from the goal.}\n          \\label{tab:deviation-from-goal-bins}\n    \\end{center}\n\\end{table}\n\n\\subsubsection*{Speed}\nThe current speed of the agent is quantized and represented in the form of a $6 \\times 1$ indicator variable. \n%\\begin{table}[htbp]\n%    \\caption{Thresholds for the qantization of the speed of the agent.}\n%    \\label{tab:speed-quantization}\n%    \\begin{center}\n%        \\renewcommand{\\arraystretch}{1.3}\n%        \\begin{tabular}{|c|c|}\n%            \\hline\n%            Raw speed & Speed bin \\\\\n%            \\hline\n%            0 - 0.2 & 0 \\\\\n%            0.2 - 0.4 & 1 \\\\\n%            0.4 - 0.6 & 2 \\\\\n%            \\hline\n%        \\end{tabular}\n%    \\end{center}\n%    \\end{table}\n\n\\subsection*{The local information}\nTaking inspiration from previous work in this field \\cite{fahad_learning_2018} \\cite{vasquez_inverse_2014}, we use spatial bins to effectively divide the region surrounding the agent into discrete segments and calculate a `risk' metric for each of these bins.\n    \\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{figures/risk_features_spatial_bins.png}\n\t\\caption{Segmentation of the local area around the agent. The black square and the arrow denotes the agent and its current direction of heading respectively.}\n\t\\label{fig:risk_local_bins}\n\\end{figure}\n\\subsubsection*{Creation of the bins}\nThere are $16$ spatial bins surrounding the agent arranged in two concentric circles. $8$ equal divisions of the region between the agent and the inner circle form bin $1-8$. Similarly, the divisions in the region between the first and the second concentric circle form bins $9 - 16$.\n\\subsubsection*{Calculation of the risk}\nOxford English Dictionary defines `risk' as ``the possibility of loss, injury, or other adverse or unwelcome circumstance; a chance or situation involving such a possibility'' \\cite{oxford_dictionary}. In this context, `risk' can be loosely correlated to the likelihood of a collision with a nearby obstacle/pedestrian. As a property of the spatial bins, it implies the possibility of a collision with an obstacle located in the given bin. \nThe risk is divided into 3 levels: high, low, and medium.\n\\begin{itemize}\n    \\item High risk:\nWhen the relative motion of an obstacle is towards the agent and can lead to a collision if not intervened.\n    \\item Low risk:\nWhen the relative motion of an obstacle is away from the agent.\n    \\item Medium risk:\nAnything in between.\n\\end{itemize}\nThe calculation of the risk values are based on the following entities:\n\\begin{align}\n    \\vec{o}_{rel} = & \\;\\; \\vec{o}_{obs} - \\vec{o}_{agent}  \\\\\n    \\vec{d}_{rel} =  &\\;\\; \\vec{d}_{agent} - \\vec{d}_{obs} \\\\\n    \\theta_{risk} =  & \\;\\; \\angle (\\vec{o}_{rel}, \\vec{o}_{rel}) \\\\\n    \\mathbf{s}_{obs} = & \\;\\; \\tan(\\theta_{risk}) \\times |\\vec{d_{rel}}| \\\\\n    \\mathbf{T} = & \\;\\; \\text{agent witdh} + \\text{obstacle witdh}\n\\end{align}\nwhere $\\vec{o}_{rel}$ is the relative orientation of the obstacle w.r.t the agent, $\\vec{d}_{rel}$ is the relative position of the agent w.r.t to the obstacle, $\\theta_{risk}$ is the angle between the vectors, $\\vec{o}_{rel}$ and $\\vec{d}_{rel}$,  $\\mathbf{s}_{obs}$ is the estimated safety margin between the agent and the obstacle and $\\mathbf{T}$ is a predefined value which if maintained between the agent and an obstacle should guarantee a collision-free trajectory.\\\\\nAn obstacle is marked as `high risk' when $\\theta$ is less than $90\\degree$ and the safety margin is less than $\\mathbf{T}$. The rationale behind this is,  $\\theta$ < $90 \\degree$ indicates that the involved objects are moving towards each other. Additionally, if the objects are close by, i.e. $ < \\mathbf{T}$, then this describes a condition where two objects in close proximity are moving towards each other: a circumstance that is likely to encounter a collision.  If $\\theta$ > $90 \\degree$, this indicates that the obstacle is moving away from the agent and hence chances of collision are less and hence low risk. Anything that does not fall in the above two categories are considered as medium risk. The risk calculation conditions and values are summarized in \\autoref{risk-categorization-table}\n%\\thcomment{I do not have any citation or study to back the classification but I have added a justification based on common sense if that helps.}\n\\begin{table}[htbp]\n    \\begin{center}\n        \\renewcommand{\\arraystretch}{1.3}\n        \\begin{tabular}{|c|c|}\n            \\hline\n            \\textbf{Risk value}& \\textbf{Risk condition} \\\\\n            \\hline\n            High & $\\theta < 90\\degree$ \\&  $\\mathbf{s}_{obs}$ < $\\mathbf{T}$   \\\\\n            \n            Low & $\\theta > 90\\degree$\\\\\n            \n            Medium & otherwise \\\\\n            \\hline\n        \\end{tabular}\n    \t \\caption{Categorization of the risk.}\n\t\t\\label{risk-categorization-table}\n    \\end{center}\n\n\\end{table}\n\\par\nThe risk value of each bin is represented using a $3 \\times 1$ indicator variable. The risk is calculated for individual obstacles present in a bin separately. In the event of a spatial bin containing more than one obstacle with varying degrees of risk, the risk value assigned to that bin is the highest obtained among all the obstacles that fall under that spatial bin.\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{figures/risk_picture.png}\n    \\label{fig:risk-calculation}\n    \\caption{A pictorial representation of how the risk is classified. Pedestrian $1$, $2$ and $3$ falls under the category of `high' risk, `medium' and `low' risk respectively.}\n\\end{figure}\n\n\n%\\begin{figure}\n%\t\\label{fig:agent-perspective-risk-features}\n%\t\\begin{subfigure}[t]{.5\\linewidth}\n%\n%\t\t\\includegraphics[width=.95\\textwidth]{figures/screenshot_video_frame_agent_perspective.png}\n%\t\t\\label{fig:agent-perspective_screenshot}\n%\t\t\\caption{A frame from the UCY dataset. The pedestrian which is the acting agent for the current episode is marked with a blue triangle.}\n%\t\\end{subfigure}\n%\t\\begin{subfigure}[t]{.5\\linewidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=.95\\textwidth]{figures/env_screenshot_agent_perspective.png}\n%\t\t\\label{fig:agent-perspective_env}\n%\t\t\\centering\n%\t\t\\caption{Representation of the video frame in the in-house built environment. The blue square represents the acting agent, the red squares represent other pedestrians (obstacles), and the green square represents the goal. The yellow circle around the agent is the area around the agent taken into consideration while computing the local information used by the agent.} \n%\t\\end{subfigure}\n%\t\\begin{subfigure}[b]{\\linewidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=.4\\textwidth]{figures/agent_perspective_recreated.png}\n%\t\t\\label{fig:agent-perspective_agent-perspective}\n%\t\t\\caption{The local information from the frame as perceived by the agent using the risk features. The spatial bins are represented by the concentric circles around the agent (black square) and the dotted lines. The squares in green mark pedestrians which pose low risk, while the ones in blue denote medium risk.}\n%\t\\end{subfigure}\n%\\end{figure}\n\n\n\\begin{figure}[!htbp]\n\t\\label{fig:agent-perspective-risk-features}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/env_screenshot_agent_perspective.png}\n\t\t\\label{fig:agent-perspective_env}\n\t\t\\centering\n\t\t\\caption{A screenshot of a frame populated with human obstacles.} \n\\end{figure}\n\n\\begin{figure}[!htbp]\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/agent_perspective_recreated.png}\n\t\t\\label{fig:agent-perspective_agent-perspective}\n\t\t\\caption{The local perspective of the agent in the frame. The arrows mark the relative velocity of the nearby pedestrians w.r.t. the agent. Risk classification is color-coded as mentioned earlier.}\n\\end{figure}\n\n\n\n\n%Additionally, we also introduce a \\textbf{smoothing technique} for the calculated svf. \\\\\n%\\textbf{What is smoothing?}\\\\\n%In the traditional way of calculating the SVF, the observation of a given state contributes to the increment of the visitation frequency of that state by 1. \n%Instead for a single observation, we opt for the increment in the visitation frequency of a set of neighboring states based on the closeness of the neighboring states to the state observed. Here smoothing is defined as the distribution of the visitation weight of a state over its set of neighboring states based on their spatial similarity.\\\\\n%\\textbf{Why smoothing?}\n%Having a 1 to 1 mapping between the observation and the increment of the SVF misses out on the fact that not all states \\textit{are equally different.} \\textbf{differ from each other in equal magnitude} \\\\\n%\\textbf{For example:} consider 3 different states, which differ only in their goal location component. Now, if two of the states indicated the goal to be in the $2^{nd}$ spatial bin and $3^{rd}$ spatial bin, then the difference between these two states is smaller than a $3^{rd}$ state where the goal is in the $6^{th}$ bin.\n%This inequality in the differences among different states is accounted for in the smoothing, by increasing the weighted increment of a set of neighboring states of the observed state (based on their similarity) rather than increasing the value of the observed state only. \\\\ \n%\\textbf{How smoothing?}\n%The state vector comprises of different components, and the 'smoothed' state is obtained by convolving a smoothing kernel to each of them separately. The values used in the kernel, and the type of convolution applied depends on the nature of the spatial division the feature represents and is summarised in the Table \\ref{conv-table}.\n%\n%\\begin{table}\n%    \\caption{Table showing the details of the convolution used for smoothing the state feature vector.}\n%    \\label{conv-table}\n%    \\begin{center}\n%        \\renewcommand{\\arraystretch}{1.3}\n%        \\begin{tabular}{|c|c|c|}\n%            \\hline\n%            Feature component & Convolution Kernel & Convolution type\\\\\n%            \\hline\n%            Relative goal orientation & $ [0.1, \\;0.8, \\; 0.1 ]$ & Wrap  \\\\\n%            \n%            Change in orientation & $[ 0.1, \\; 0.8; \\;0.1 ]$ & Same \\\\\n%            \n%            Deviation from goal & $[0.9,\\; 0.1]$, $[0.1,\\; 0.9]$,\n%                                          $[0.05, \\; 0.9, \\; 0.05]$, $[0.1,\\; 0.9]$ & Same \\\\\n%            Local spatial bins & $[ 0.1, \\; 0.8,\\;0.1 ]$ & Wrap \\\\\n%            Speed info & $[ 0.1, \\; 0.8,\\;0.1 ]$  & Same \\\\\n%            \\hline\n%        \\end{tabular}\n%    \\end{center}\n%\\end{table}\n", "meta": {"hexsha": "44deffce564587805c52815253480dd80834697e", "size": 36064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX-Thesis-Template/base/chapter/chapter4.tex", "max_stars_repo_name": "ranok92/my_masters_thesis", "max_stars_repo_head_hexsha": "5a66e039b5702ff8045bd3f635572ada1d4482ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-17T08:30:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-17T08:30:52.000Z", "max_issues_repo_path": "LaTeX-Thesis-Template/base/chapter/chapter4.tex", "max_issues_repo_name": "ranok92/my_masters_thesis", "max_issues_repo_head_hexsha": "5a66e039b5702ff8045bd3f635572ada1d4482ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX-Thesis-Template/base/chapter/chapter4.tex", "max_forks_repo_name": "ranok92/my_masters_thesis", "max_forks_repo_head_hexsha": "5a66e039b5702ff8045bd3f635572ada1d4482ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.2901878914, "max_line_length": 803, "alphanum_fraction": 0.7135370453, "num_tokens": 10160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6547000775859843}}
{"text": "\\chapter{VECTOR ALGEBRA}\r\n\r\n\\begin{definition}\r\nA vector is defined as a physical quantity having magnitude and a direction associated with it. \r\n\\end{definition}\r\n\\begin{example}\r\n\t Displacement,Velocity, Acceleration, Force ,Torque,Angular momentum etc. \r\n\\end{example}\r\n\\section{Vector representation}\r\nGeometrically  a  vector  is  represented  by  a  directed  line  segment, with length proportional to the magnitude.The direction of the arrow gives the direction of the vector.\\newline\r\nWe will refer to the start of the arrow as the tail and the end as the tip or head. The vector between two points P and Q  will be denoted as, $\\overrightarrow{\\mathrm{P Q}}$(or by a boldface $\\mathbf{PQ}$). And the  magnitude as $|\\mathrm{ PQ}| .$  Magnitude will also be called length or norm.\\\\\\\\ Analytically a three  dimensional  vector  can  be  specified  by  an  ordered  set  of  three  numbers,  called  its  components.The magnitude  of  the  components  depend  on  the  coordinate  system  used. (A vector can be extended to $n$ dimensions). A vector $\\vec{A}$ is represented by $\\left(A_{x}, A_{y}, A_{z}\\right)$ in cartesian (rectangular) coordinate system .\\\\Magnitude of vector $\\vec{\\mathrm A}$ is given by, $|\\vec{\\mathrm A}|=\\sqrt{\\mathrm A_{x}^{2}+\\mathrm A_{y}^{2}+\\mathrm A_{z}^{2}}$\r\n\\subsection{Position vector:} \r\n\\begin{definition}\r\n\tVectors that start at the origin and terminate at any arbitrary point are called position vectors. These are used to determine the position of a point with reference to the origin.\r\n\\end{definition}\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.4\\textwidth]{vector2}\r\n\t\\caption{Representation of position vector $\\vec{A }$}\r\n\\end{figure}\r\n Any vector $\\vec{\\mathrm A}$ in the $3-\\mathrm{\\mathrm D}$ right handed rectangular cartesian coordinate system can be represented as,\r\n \\begin{equation}\r\n$$\\vec{\\mathrm A}=\\mathrm A_{x} \\hat{i}+\\mathrm A_{y} \\hat{j}+\\mathrm A \\hat{k}$$\r\n \\end{equation} \r\nWhere, $\\hat{i}, \\hat{j}$ and $\\hat{k}$ are the unit vectors in direction of $x, y$ and $z$ axis respectively. $\\mathrm A_{x}, \\mathrm A_{y} $ and $ \\mathrm A_{z}$ are the\r\ncartesian components or projections of vector $\\vec{A}$ along $x, y, z$ axis.\r\n \\begin{exercise}\r\n\t If $\\mathrm A$ and $\\mathrm B$ are (3,4,5) and $(6,8,9),$ find $\\vec {\\mathrm {A B}}$.\r\n\t\\end{exercise}\r\n\\begin{answer}\r\n$$\\begin{aligned} \\overrightarrow{\\mathrm {A B}} &=\\text { Position vector of } \\mathrm B-\\text { Position vector of } \\mathrm A \\\\ &=(6 \\hat{i}+8 \\hat{j}+9 \\hat{k})-(3 \\hat{i}+4 \\hat{j}+5 \\hat{k}) \\\\ &=3 \\hat{i}+4 \\hat{j}+4 \\hat{k} \\end{aligned}$$\r\n\\end{answer}\r\n\r\n\\subsection{Unit vector:} \r\n\\begin{definition}\r\n\tA vector quantity having unit magnitude is called unit vector.A unit vector along $\\vec{A}$ is defined as,\r\n\t\\\\$\\hat{\\mathrm A}=\\frac{\\vec{\\mathrm A}} {|\\vec{\\mathrm A}|}=\\frac {\\left(\\mathrm A_{x} \\hat{i}+\\mathrm A_{y} \\hat{j}+\\mathrm A_{z} \\hat{k}\\right) } {\\sqrt{\\mathrm A_{x}^{2}+\\mathrm A_{y}^{2}+\\mathrm A_{z}^{2}}}$\r\n\\end{definition}\r\n \\begin{exercise}\r\n \tFind unit vector in the direction of vector $\\vec{a}=2 \\hat{i}+3 \\hat{j}+\\hat{k}$\r\n \t \\end{exercise}\r\n  \\begin{answer}\r\n  \t\r\n  \t\\begin{align*}\r\n  \t\t\\text{Magnitude of }\\vec{ a}&=\\sqrt{2^{2}+3^{2}+1^{2}}\\\\\r\n  \t\t|\\vec{a}|&=\\sqrt{4+9+1}=\\sqrt{14}\\\\\r\n  \t\t\\text{Unit vector in direction of }\\vec{a}&=\\frac{\\vec{a}}{| \\vec{a}|}\\\\\r\n  \t\t\\hat{a}&=\\frac{1}{\\sqrt{14}}[2 \\hat{i}+3 \\hat{j}+1 \\hat{k}] \\\\\r\n  \t\t\\hat{a}&=\\frac{2}{\\sqrt{14}} \\hat{i}+\\frac{3}{\\sqrt{14}} \\hat{i}+\\frac{1}{\\sqrt{14}} \\hat{k}\r\n  \t\\end{align*}\r\n  \t\r\n  \\end{answer}\r\n  \\subsection{Direction cosines}\r\nIn analytical geometry the direction cosines are the angles made by the vector with  the three coordinate axes.\\\\\\\\\\textbf{Direction cosines of vector $\\vec{\\mathrm A}$} :\r\n\\\\\\newline If $\\vec{\\mathrm A}$ makes angles $\\alpha, \\beta, \\gamma$ with $x, y$ and $z$ axes respectively, then direction cosines of $\\vec{\\mathrm A}$ are defined as,\r\n\\begin{minipage}{0.6\\textwidth}\r\n\t\\begin{flalign*}\r\n\t&l=\\cos \\alpha=\\frac{\\mathrm A_{x}}{\\mathrm A}\\quad ;\\quad  m=\\cos \\beta=\\frac{\\mathrm A_{y}}{\\mathrm A} \\quad ;\\quad  n=\\cos \\gamma=\\frac{\\mathrm A_{z}}{\\mathrm A} \\\\  &l^{2}+m^{2}+n^{2}=1\\\\\\\\\r\n\t&\\text{Then the unit vector along } \\vec{\\mathrm A}\\text{ can be written as,}\\\\\r\n\t& \\hat{\\mathrm A}=l \\hat{i}+m \\hat{j}+n \\hat{k}\\\\\r\n\t\\end{flalign*}\r\n\\end{minipage}\r\n\\begin{minipage}{0.4\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t\\centering\r\n\t\t\\includegraphics[width=6cm,height=6cm]{direction cosine}\\caption{Direction cosine.}\r\n\t\\end{figure}\r\n\\end{minipage}\r\n\\section{Types of vectors}\r\n\\begin{itemize}\r\n\t\\item \\textbf{{Equal vectors}}\\hspace{0.74cm}\\textbf{:}\\quad Vectors having same magnitude and same direction.\r\n\t\\item \\textbf{Null Vectors }\\hspace{0.82cm}\\textbf{:} \\quad Vectors having coincident initial and terminal point i.e its magnitude is zero and it has any arbitrary direction.\r\n\t\\item \\textbf{Reciprocal Vector }\\textbf{:}\\quad Vector having same direction as $\\vec{\\mathrm  A}$ but magnitude reciprocal to that of $\\vec{\\mathrm A},$ is known as the reciprocal vector of $\\mathrm A$ Reciprocal vector of $\\vec{\\mathrm A}$ is $\\vec{\\mathrm A}-\\frac{1}{\\mathrm A} \\hat{\\mathrm A}$.\r\n\t\\item \\textbf{Negative Vector}\\hspace{0.3cm} \\textbf{:}\\quad Vectors having same magnitude as $\\vec{\\mathrm a}$ but direction opposite to that of $\\vec{\\mathrm A},$ is known\r\n\tas the negative vector of $\\vec{\\mathrm a} .$ Negative vector as $\\vec{\\mathrm A}$ is $-\\vec{\\mathrm A}=-|\\mathrm A| \\hat{\\mathrm A}$.\r\n\\end{itemize}\r\n\\section{Vector operations}\\index{Vector operations}\r\n\\subsection{Vector addition}\r\n\\begin{itemize}\r\n\t\\item \t\\textbf{Triangular law of vector addition:}\r\n\t\\begin{itemize}\r\n\t\t\\item Place the tail of $\\vec{\\mathrm A}$ at the head of $\\vec{\\mathrm B} $.\r\n\t\t\\item The resultant vector $\\vec{\\mathrm A}+\\vec{\\mathrm B}$ is formed by connecting the tail of the first vector to the head of the last vector. \r\n\t\\end{itemize}\r\n\\begin{figure}[H]\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width=0.70\\textwidth]{Triangular}\r\n\t\t\\caption{Triangular law of vector addition}\r\n\t\t\\end{minipage}\\hfil\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\\centering\r\n\t\\includegraphics[width=0.75\\textwidth]{parellelogram}\r\n\t\\caption{Parellelogram law of vector addition}\r\n\\end{minipage}\r\n\r\n\\end{figure}\r\n\r\n\\item \\textbf{Parellelogram law of vector addition:}\r\n\\\\ \\\\When two vectors act at a point, their resultant is found by the law of parallelogram of vectors.(We got to use it often in Electricity and magnetism.)\r\n\r\nThe magnitude of Resultant vector ${\\vec{A }+\\vec{B}}$\r\nFrom right angled $\\triangle$ OCD.\r\n\\begin{align*}\r\nO C^{2}&=O D^{2}+C D^{2}\\\\\r\n&=(O A+AD)^{2}+C D^{2}\\\\\r\n&=O A^{2}+A D^{2}+2AD\\cdot OA +C D^{2}\\\\\\\\\r\n\\text{Here,}\\hspace{1.3cm} O A&= A\\ ; \\ AD=B\\cos\\theta \\ ; \\ CD= B\\sin\\theta\\\\\\\\\r\n\\text{Then,}\\hspace{1.1cm}  O C^{2}&=|\\vec{A }+\\vec{B}|^{2}\\\\&=A^{2}+(B\\cos\\theta)^{2}+(B\\sin\\theta)^{2}+2AB\\cos\\theta\\\\&=A^{2}+B^{2}+AB\\cos\\theta\\\\\r\n|\\vec{A }+\\vec{B}|&=\\sqrt{A^{2}+B^{2}+2AB\\cos\\theta}\\\\\r\n\\\\\r\n\\text{The direction of }&\\text{ Resultant vector}\\ {\\vec{A }+\\vec{B}} \\ \\text{with the vector}  \\ {\\vec{A}}\\\\\r\n\\tan \\alpha&=\\frac{B \\sin \\theta}{A+B \\cos \\theta}\\\\\r\n\\alpha&=\\tan ^{-1}\\left(\\frac{B \\sin \\theta}{A+B \\cos \\theta}\\right)\\\\\r\n\\text{If the  two vectors}&\\text{   are parellel i.e., $\\theta=0$ \\ Then,  }\\ \\\\\r\n|\\vec{A }+\\vec{B}|&=\\sqrt{A^{2}+B^{2}+2AB}=\\sqrt{(A+B)^{2}}=(A+B)\\\\\r\n\\text{If the  two vectors}&\\text{   are anti-parellel i.e., $\\theta=180$ \\ Then,  }\\ \\\\\r\n|\\vec{A }+\\vec{B}|&=\\sqrt{A^{2}+B^{2}-2AB}=\\sqrt{(A-B)^{2}}=(A-B)\\\\\r\n\\end{align*}\r\n\\end{itemize}\r\n\\begin{note}\r\n\t\\leavevmode\r\n\t\\\\\\\\\r\n     \tIf $|\\vec{A}|=|\\vec{B}|=A$ Then resultant of these two vectors will be,\r\n\t\\begin{enumerate}\r\n\t\t\\item $\\theta=0\\qquad \\rightarrow \\sqrt{A^{2}+A^{2}+2A A\\cos 0} \\hspace{0.2cm}=\\sqrt{A^{2}+A^{2}+2A^{2}}=2A $ \r\n\t\t\\item $\\theta=60^{\\circ} \\quad\\rightarrow \\sqrt{A^{2}+A^{2}+2A A\\cos 60}=\\sqrt{A^{2}+A^{2}+A^{2}} =\\sqrt{3}A $\r\n\t\t\\item $\\theta=90^{\\circ}\\quad\\rightarrow \\sqrt{A^{2}+A^{2}+2A A\\cos 90}=\\sqrt{A^{2}+A^{2}}=\\sqrt{2} A $\r\n\t\t\t\\item $\\theta=180^{\\circ} \\hspace{0.3cm} \\rightarrow \\sqrt{A^{2}+A^{2}+2A A\\cos 180}=\\sqrt{A^{2}+A^{2}-2A^{2}} =0 $ \r\n\t\\end{enumerate}\r\n\\end{note}\r\n\r\n\\subsubsection{Properties of vector addition}\r\n\\begin{itemize}\r\n\t\\item Commutation property:\r\n\t$\\mathbf{A}+\\mathbf{B}=\\mathbf{B}+\\mathbf{A}$.\r\n\t\\item Associative property:$(\\mathbf{A}+\\mathbf{B})+\\mathbf{C}=\\mathbf{A}+(\\mathbf{B}+\\mathbf{C})$.\r\n\t\\item Additive identity:$\\mathbf{A}+\\mathbf{0}=\\mathbf{A} \\quad$.\r\n\t\\item Additive inverse:$\\mathbf{A}+(-\\mathbf{A})=\\mathbf{0} \\quad$ .\r\n\t\r\n\\end{itemize}\r\n\\subsection{Vector  multiplication}\r\n\\subsubsection{\\large{1}.{Scaling of vector}(Multiplication by scalar)}\r\nScaling a vector means changing it's length by a scale factor.\tMultiplication of a vector by a positive scalar $'c'$, multiplies the magnitude but leaves the\r\ndirection unchanged. If $'c'$ is negative, the direction is reversed.\r\n\\begin{figure}[H]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=0.30\\textwidth]{scaling}\r\n\t\\end{center}\r\n\\caption{Scaling of vector}\r\n\\end{figure}\r\n\\subsubsection{Properties of scalar multiplication}\r\n\\begin{itemize}\r\n\t\\item  Distributive property:\\quad$a(\\vec{\\mathrm A}+\\vec{\\mathrm B})=a \\vec{\\mathrm A}+a \\vec{\\mathrm B}$.\r\n\\end{itemize}\r\n\\subsubsection{\\large{2}.Dot product or scalar product of two vectors}\r\nThe dot product of two vectors is defined as\r\n\\begin{equation}\r\n$$\\vec{A} \\cdot \\vec{B}=|A| | B| \\cos \\theta$$\r\n\\end{equation}\r\nWhere $\\theta$ is the angle they form when placed tail to tail. $\\vec{\\mathrm{A}} \\cdot \\vec{\\mathrm B}$ is itself a scalar.Geometrically $\\vec{\\mathrm A} \\cdot \\vec{\\mathrm B}$ is the product of $\\mathrm A$ times the projection of $\\vec{\\mathrm B}$ along $\\vec{\\mathrm A}$.\r\n\\\\\\newline In general,\\ If \\ $\\vec{\\mathrm A}=\\mathrm A_{z} \\hat{i}+\\mathrm A_{y} \\hat{j}+\\mathrm A_{z} \\hat{k}$ and $\\vec{\\mathrm B}=\\mathrm B_{x} \\hat{i}+\\mathrm B_{y} \\hat{j}+\\mathrm B_{z} \\hat{k},$\\\\\\\\ Then we can construct the scalar product of $\\vec{\\mathrm A}$ and $\\vec{\\mathrm B}$ as,\r\n\\begin{equation}\r\n$$\\vec{\\mathrm A} \\cdot \\vec{ \\mathrm B}=\\mathrm A_{x} \\mathrm B_{x}+\\mathrm A_{y} \\mathrm B_{y}+\\mathrm A_{z} \\mathrm B_{z}$$\r\n\\end{equation}  \r\n\\begin{example}\\textbf{Workdone:}\r\n\tIf a constant force $F$ acting on a particle displaces it from the point A to B then,\\\\\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\\begin{align*}\r\n\t\t\\text{Work done} &=\\text{(component of F along A B ). Displacement}\\\\\r\n\t\t&=\\mathrm{F} \\cos \\theta . A B \\\\\r\n\t\t&=\\vec{F} \\cdot \\overrightarrow{A B}\\\\\r\n\t\t\\text{Work done }&=\\text{Force. Displacement}\r\n\t\t\\end{align*}\r\n\t\\end{minipage}\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t\\begin{center}\r\n\t\t\t\\includegraphics[width=0.65\\textwidth]{workdone}\r\n\t\t\\end{center}\r\n\t\t\\caption{Workdone}\r\n\t\\end{figure}\r\n\\end{minipage}\r\n\\end{example}\r\n\\subsubsection{Projection:}Projection of a vector A on B is the component of vector A in the direction of vector B.$$\\text{Projection of}\\quad \\vec{\\mathrm A} \\text{\\quad along}\\quad \\vec{\\mathrm B} =\\vec{\\mathrm A}\\cos\\theta =\\vec{\\mathrm A} \\cdot \\hat{\\mathrm B}$$.\r\n\\subsubsection{Properties of Dot product}\r\n\\begin{itemize}\r\n\t\\item Commutative property:$\\vec{\\mathrm A} \\cdot \\vec{\\mathrm B} =\\vec{\\mathrm B} \\cdot \\vec{\\mathrm A}$.\r\n\t\\item Asociative property:$ \\vec{\\mathrm A} \\cdot(\\vec{\\mathrm B}+\\vec{\\mathrm C}) =\\vec{\\mathrm A} \\cdot \\vec{\\mathrm B}+\\vec{\\mathrm A} \\cdot \\vec{\\mathrm C}$.\r\n\t\\item For two mutually perpendicular vectors $\\vec{\\mathrm A}$ and $\\mathrm B, \\mathrm A \\cdot \\vec{\\mathrm B}=0$.\r\n\t\\item If the two vectors are parallel, $\\vec{\\mathrm A} \\cdot \\vec{\\mathrm B}=\\mathrm {A B}$.(since, $\\cos0=1$)\r\n\t\\item $\\hat{i} \\cdot \\hat{j}=\\hat{j} \\cdot \\hat{k}=\\hat{k} \\cdot i=0\\newline  \\hat{i} \\cdot \\hat{i}=\\hat{j}\\cdot\\hat{j} = \\hat{k}\\cdot \\hat{k}=1$\\\\\\\\ \r\n\\end{itemize}\r\n\\begin{exercise}\r\n\tFor the two vectors  $ \\vec{A}=6\\hat{i}+4\\hat{j}+3\\hat{k}$ and $ \\vec{B}=2\\hat{i}-3\\hat{j}-3\\hat{k}$\r\n\t\\newline  $$\\begin{aligned}\r\n\t\\vec{\\mathrm A} \\cdot \\vec{ \\mathrm B}&=\\mathrm A_{x} \\mathrm B_{x}+\\mathrm A_{y} \\mathrm B_{y}+\\mathrm A_{z} \\mathrm B_{z}\\\\\r\n\t&=12-12-9\\\\\r\n\t&=-9\r\n\t\\end{aligned}$$\r\n\\end{exercise}\r\n\\subsubsection{{\\large 3}.Vector  product or Cross product}\r\nCross product of two vectors $\\vec{\\mathrm A}$ and $\\vec{\\mathrm B}$  is defined as a vector that is perpendicular (orthogonal) to both $\\vec{\\mathrm A}$ and $\\vec{\\mathrm B}$, with  a magnitude equal to the area of the parallelogram that the vectors span(This suggest that area may be treated as a vector quantity). Since there are two opposite directions which are so perpendicular to $\\vec{A} \\ \\text{and} \\ \\vec{B}$  This does not uniquely determine $\\vec{A} \\times \\vec{B}$ . The direction of $\\vec{A} \\times \\vec{B}$ is fixed by a convention, called the Right Hand Rule.\\\\\\\\\r\n\\textbf{Right Hand Rule :}\\\\\r\nStretch out the fingers of the right hand so that the thumb becomes perpendicular to both the index (fore\r\nfinger) and the middle finger. If the index points in the direction of $\\vec{A}$ and the middle finger in the direction of\r\n$\\vec{B}$ then, $\\vec{A} \\times \\vec{B}$ points in the direction of the thumb.\\\\\\\\\r\nThe vector product of $\\vec{A} \\ \\text{and} \\ \\vec{B}$  is defined as, \r\n\\begin{equation}\r\n$$\\vec{\\mathrm A} \\times \\vec{\\mathrm B}=|\\vec{\\mathrm A}||\\vec{\\mathrm B}| \\sin \\theta  \\hat{n}$$\r\n\\end{equation}\r\nWhere $\\hat{n}$ is unit vector normal to the plane containing $\\vec{\\mathrm A}$ and $\\vec{\\mathrm B}$.\r\n\\\\Using decomposition of vector into their cartesian components,we can find $\\vec{\\mathrm A} \\times \\vec{\\mathrm B}$ as,\r\n\\\\ If $\\vec{\\mathrm A}=\\mathrm A_{z} \\hat{i}+\\mathrm A_{y} \\hat{j}+\\mathrm A_{z} \\hat{k}$ and $\\vec{\\mathrm B}=\\mathrm B_{x} \\hat{i}+\\mathrm B_{y} \\hat{j}+\\mathrm B_{z} \\hat{k},$ then $$\\vec{\\mathrm A} \\times \\vec{\\mathrm B}=\\left|\\begin{array}{lll}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\mathrm A_{x} & \\mathrm A_{y} & \\mathrm A_{z} \\\\ \\mathrm B_{x} & \\mathrm B_{y} & B_{z}\\end{array}\\right|$$\r\n\\begin{example}\r\n\tAngular momentum\r\n\t\\newline The angular momentum of a particle, about a reference point , is defined as the vector product of the potion relative to the reference point, and momentum of the particle\r\n\t $$ L=r\\times p$$\r\n\t \\begin{figure}[H]\r\n\t \t\\begin{center}\r\n\t \t\t\\includegraphics[width=0.30\\textwidth]{angular momentum}\r\n\t \t\\end{center}\r\n \t\\caption{Angular momentum}\r\n\t \\end{figure}\r\n\\end{example}\r\n\\subsubsection{Properties of Cross product} \r\n\\begin{itemize}\r\n\t\\item Distributive property\\hspace{0.7cm}:\\ $\\vec{\\mathrm A} \\times(\\vec{\\mathrm B} + \\vec{\\mathrm C})=(\\vec{\\mathrm A} \\times \\vec{\\mathrm B})+(\\vec{\\mathrm A} \\times \\vec{\\mathrm C})$\r\n\t\\item Commutative property\\quad:\\ $\\vec{\\mathrm A} \\times \\vec{\\mathrm B}=-(\\vec{\\mathrm B} \\times \\vec{\\mathrm A})$.\r\n\t\\item For two collinear vectors (parallel or anti-parallel vectors) $\\vec{\\mathrm A} \\times \\vec{\\mathrm B}=0$.\r\n\t\\item $\\hat{i} \\times \\hat{i}=\\hat{j} \\times \\hat{j}=\\hat{k} \\times \\hat{k}=0\\\\\\\\\r\n\t\\; \\ \\hat{i} \\times \\hat{j}=\\hat{k}\r\n\t\\; \\ \\hat{j} \\times \\hat{k}=\\hat{i}\r\n\t\\; \\ \\hat{k} \\times \\hat{i}=\\hat{j}$.\r\n\t\r\n\\end{itemize}\r\n\\begin{exercise}\r\n\tFind the area of a parallelogram whose adjacent sides are $\\hat{i}-2 \\hat{j}+3 \\hat{k}$ and\r\n\t$2 \\hat{i}+\\hat{j}-4 \\hat{k}$.\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\\text{Vector area of parellelogram}&=\\left|\\begin{array}{rrr}\\hat{i} & \\hat{j} & \\hat{k} \\\\ 1 & -2 & 3 \\\\ 2 & 1 & -4\\end{array}\\right|\\\\\r\n&=(8-3) \\hat{i}-(-4-6) \\hat{j}+(1+4) \\hat{k}=5 \\hat{i}+10 \\hat{j}+5 \\hat{k}\\\\\r\n\\text{Area of parallelogram}&=\\sqrt{(5)^{2}+(10)^{2}+(5)^{2}}=5 \\sqrt{6}\r\n\\end{align*}\r\n\\end{answer}\r\n\r\n\r\n\\subsubsection{4.Triple product}\r\n\\begin{itemize}\r\n\t\\item \\textbf{Scalar Triple product}\r\n\t\\\\The scalar triple product of three vectors $\\vec{\\mathrm{A}}, \\vec{\\mathrm{B}}$, and $\\vec{\\mathrm{C}}$ is $(\\vec{\\mathrm{A}} \\times\\vec{\\mathrm{B}}) \\cdot \\vec{\\mathrm{C}} .$ It is a scalar product because, just like the dot product, it evaluates to a single number.  The absolute value of $|(\\vec{\\mathrm{A}} \\times \\vec{\\mathrm{B}}) \\cdot \\vec{\\mathrm{C}}|$ is the volume of the parallelepiped spanned by $\\vec{\\mathrm{A}}, \\vec{\\mathrm{B}},$ and $\\vec{\\mathrm{C}}$ (i.e., the parallelepiped whose adjacent sides are the vectors $\\vec{\\mathrm{A}}, \\vec{\\mathrm{B}},$ and $\\vec{\\mathrm{C}}$ ).\\begin{figure}[H]\r\n\t\t\\begin{center}\r\n\t\t\t\\includegraphics[width=0.25\\textwidth]{parellelopiped}\r\n\t\t\\end{center}\r\n\t\\caption{Scalar triple product}\r\n\t\\end{figure}\r\n\\begin{align*}\r\n\t\\vec{\\mathrm A} \\cdot(\\vec{\\mathrm B} \\times \\vec{\\mathrm C})&=\\vec{\\mathrm B} \\cdot(\\vec{\\mathrm C} \\times \\vec{\\mathrm A})=\\vec{\\mathrm C} \\cdot(\\vec{\\mathrm A} \\times \\vec{\\mathrm B})\\\\\r\n\t\\text{In component form}\\ \\vec{\\mathrm A} \\cdot(\\vec{\\mathrm B} \\times \\vec{\\mathrm C})&=\\left|\\begin{array}{lll}\\mathrm A_{x} & \\mathrm A_{y} & \\mathrm A_{z} \\\\ \\mathrm B_{x} & \\mathrm B_{y} & \\mathrm B_{z} \\\\ \\mathrm C_{x} & \\mathrm C_{y} & \\mathrm C_{z}\\end{array}\\right|\\\\\r\n\\end{align*}\r\n\r\n\t\\item \\textbf{Vector Triple product}\r\n\t\\\\A vector triple product $\\vec{\\mathrm A} \\times(\\vec{\\mathrm B} \\times \\vec{\\mathrm C})$ of 3 vectors ,$\\vec{\\mathrm A}$ , $\\vec{\\mathrm B}$ and $\\vec{\\mathrm C}$ is simply a vector lying in the plane containing $\\vec{\\mathrm A}$ , $\\vec{\\mathrm B}$ and $\\vec{\\mathrm C}$.\\\\\r\n\r\n\tThe vector triple product can be simplified by the so-called $\\text{ B A C}-\\text{ C A B}$ rule.The equation is linear in  A,B and C.\r\n\t$$\r\n\t\\vec{\\mathrm A} \\times(\\vec{\\mathrm B} \\times \\vec{\\mathrm C})=\\vec{\\mathrm B}(\\vec{\\mathrm A} \\cdot \\vec{\\mathrm C})-\\vec{\\mathrm C}(\\vec{\\mathrm A} \\cdot \\vec{\\mathrm B})\r\n\t$$\r\n\\end{itemize}\r\n\\begin{note}\r\n\r\nSuppose we have two vectors $ \\vec{a}$ and $ \\vec {b}$ as shown in the figure.\r\n\\ref{vector}\r\nWe can write $\\vec{b}$ as\r\n$$\\vec{b}=\\vec{{b_{\\parallel}}}+\\vec{{b_{\\perp}}} $$\r\nWhere ${b_{\\parallel}}$ is the projection of $ \\vec {b}$ along  $ \\vec{a}$ and$ \\vec{{b_{\\perp}}}$ is the projection of  $ \\vec {b}$ perpendicular to $ \\vec{a}$\\\\\r\n\\begin{minipage}{0.65\\textwidth}\r\n\t\\begin{align*}\r\n\t\\vec {b}=&(\\vec{b}\\cdot \\hat{a})\\cdot \\hat{a}+\\vec{{b_{\\perp}}}\\\\\r\n\t\\vec {b}=&\\frac{(\\vec{b}\\cdot \\vec{a})\\cdot\\vec{a}}{a^{2}}+\\vec{{b_{\\perp}}}\\\\\r\n\t\\vec {b}=&\\frac{(\\vec{b}\\cdot \\vec{a})\\cdot\\vec{a}}{a^{2}}+{\\vec{b}-\\frac{(\\vec{b}\\cdot \\vec{a})\\cdot\\vec{a}}{a^{2}}}\\\\\r\n\t\\vec {b}=&\\frac{(\\vec{b}\\cdot \\vec{a})\\cdot\\vec{a}}{a^{2}}+\\frac{\\vec{b}(\\vec{a}\\cdot\\vec{a})-{(\\vec{b}\\cdot\\vec{a})\\vec{a}}}{a^{2}}\\\\\r\n\t\\vec {b}=&\\frac{(\\vec{b}\\cdot \\vec{a})\\cdot\\vec{a}}{a^{2}}+\\frac{\\vec{a}\\times(\\vec{b}\\times\\vec{a})}{a^{2}}\\\\\r\n\t\\vec{b}=&\\vec{{b_{\\parallel}}}(\\text{parellell component})+\\vec{{b_{\\perp}}}(\\text{perpendicular component})\r\n\t\\end{align*}\r\n\\end{minipage}\r\n\\begin{minipage}{0.35\\textwidth}\\hfill\r\n\\begin{figure}[H]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=0.8\\textwidth]{vector1}\r\n\t\\end{center}\r\n\\caption{vector}\r\n\\label{vector}\r\n\\end{figure}\r\n\\end{minipage}\r\n\\end{note}\r\n\r\n\\section{General curvilinear coordinate system}\\index{General culvilinear coordinate system}\r\nNot all Physical problems  are well adapted to a solution in cartesian coordinate system.We have to develop a general system that may be apt for any particular system of intersect.\r\nThe coordinates in general curvilinear coordinate system be described by three coordinates, $q_{1},q_{2} $ and $ q_{3}$\\\\then  a position vector $ \\vec{ r}$ in the system can be represented as,\r\n\\begin{align*}\r\n\\vec{r}&=\\vec{r}(q_{1},q_{2},q_{3})\\\\\r\n\\text{Then,}\\quad\r\n dr&={\\frac{\\partial r}{\\partial q_{1} }} dq_{1}+{\\frac{\\partial r}{\\partial q_{2} }} dq_{2}+{\\frac{\\partial r}{\\partial q_{3} }} dq_{3}\r\n\\end{align*}\r\nWhere,\\ ${\\frac{\\partial r}{\\partial q_{1} }}$,${\\frac{\\partial r}{\\partial q_{2} }}$,${\\frac{\\partial r}{\\partial q_{3} }}$ are the tangent vectors along $q_{1},q_{2}  $ and \\ $q_{3}$.\r\n\\\\\\\\The unit vectors along $q_{1},q_{2}  $ and \\ $q_{3}$ are defined as,\r\n$$ \\hat e_{1}=\\frac{{\\frac{\\partial r}{\\partial q_{1} }}}{|{\\frac{\\partial r}{\\partial q_{1} }}|}\\quad ;\\quad\r\n \\hat e_{2}=\\frac{{\\frac{\\partial r}{\\partial q_{2} }}}{|{\\frac{\\partial r}{\\partial q_{2} }}|}\\quad ;\\quad\\hat e_{3}=\\frac{{\\frac{\\partial r}{\\partial q_{3} }}}{|{\\frac{\\partial r}{\\partial q_{3} }}|}$$\r\n\\\\\r\n\\textbf{Scaling factor:}\\\\\\\\\r\nThe factor ${|{\\frac{\\partial r}{\\partial q_{1} }}|}$ is known as the scaling factor. It is denoted as $h_{1}$.\\\\\\\\\r\nSimiliarly, $h_{2}={|{\\frac{\\partial r}{\\partial q_{2} }}|}$\r\nand $h_{3}={|{\\frac{\\partial r}{\\partial q_{3} }}|}$\\\\\r\n\\\\Then the position vector can be written as,\r\n\\begin{equation}\r\n$$ \\vec dr=h_{1}\\hat e_{1} dq_{1}+h_{2}\\hat e_{2} q_{2}+h_{3}\\hat e_{3}q_{3}$$\r\n\\end{equation}\r\n\\textbf{Cartesian coordinate system}\r\n\\begin{alignat*}{4}\r\n&\\text{Coordinates}&& \\textbf{:} \\ q_{1}=x\\;\\ q_{2}=y\\;\\ q_{3}=z\\\\\r\n&\\text{Scaling factors} && \\textbf{:}\\ h_{1}=1\\; \\ h_{2}=1\\;\\  h_{3}=1\\\\\r\n&\\text{Unit vectors}&&\\textbf{:}\\ \\hat{e}_{1}=\\hat{e}_{x}\\;\\ \\hat{e}_{2}=\\hat{e}_{y}\\;\\ \\hat{e}_{3}=\\hat{e}_{z}\\\\\r\n&\\text{Position vector}&&\\textbf{:} \\ \\vec dr=\\hat e_{x} dx+\\hat e_{y} dy+\\hat e_{z}dz\r\n\\end{alignat*}\r\n\r\n\\section{Differential Operations on Vectors}\\index{Differential Operations on Vectors}\r\n\\begin{alignat*}{2}\r\n&\\text{Gradient }(\\nabla)&&\\textbf{:}\\ \\text{A derivative on a scalar that gives a vector.}\r\n\\\\&\\text{Curl} (\\nabla \\times)&&\\textbf{:}\\ \\text{A derivative on a vector that gives another vector.}\r\n\\\\&\\text{Divergence }(\\nabla \\cdot)&&\\textbf{:}\\ \\text{A derivative on a vector that gives scalar.}\r\n\\end{alignat*}\r\n \r\n\\subsection{Gradient}\r\n The gradient is the multidimensional rate of change of a particular function.\r\nGradient of a continuously differentiable scalar function $\\phi(q_{1}, q_{2}, q_{3})$ is mathematically defined as:\r\n$$ \\nabla \\phi=\\frac{1}{h_{1}}\\frac{\\partial \\phi}{\\partial q_{1}} \\hat e_{1}+\\frac{1}{h_{2}}\\frac{\\partial \\phi}{\\partial q_{2}} d \\hat e_{2}+\\frac{1}{h_{3}}\\frac{\\partial \\phi}{\\partial q_{3}} \\hat e_{3}\r\n$$\r\n\\subsubsection{Physical interpretation}\r\n\tGradient tells you how much something changes as you move from one point to another (such as the pressure in a stream). If a surface $\\phi(x, y, z)=c$ passes through a point $P$. The value of the function at each point on the surface is the same as at $P$. Then such a surface is called a level surface through $P$. At each point of the level surafce, the value of scalar function $f$ will be same. Equipotential surface on which value of electrostatic potential is same at all points.\r\n\r\n\r\n\t\\begin{figure}[H]\r\n\t\t\\includegraphics[width=.85\\textwidth]{Gradient2}\r\n\t\t\\caption{The gradient, represented by the blue arrows, denote the direction of greatest change of a scalar function. The values of the function are represented in greyscale and increase in value from white (low) to dark (high).}\r\n\t\\end{figure}\r\n\r\n\r\n\r\n\r\n\\subsubsection{Product rule}$ \\bullet$ $\\vec{\\nabla}(\\phi \\psi)=\\phi \\vec{\\nabla} \\psi+\\psi \\vec{\\nabla} \\phi$\r\n\\\\$ \\bullet$ $\\vec{\\nabla}(\\overrightarrow{\\mathrm{A}} \\cdot \\overrightarrow{\\mathrm{B}})=\\overrightarrow{\\mathrm{A}} \\times(\\vec{\\nabla} \\times \\overrightarrow{\\mathrm{B}})+\\overrightarrow{\\mathrm{B}} \\times(\\vec{\\nabla} \\times \\overrightarrow{\\mathrm{A}})+(\\overrightarrow{\\mathrm{A}} \\cdot \\vec{\\nabla}) \\overrightarrow{\\mathrm{B}}+(\\overrightarrow{\\mathrm{B}} \\cdot \\vec{\\nabla}) \\overrightarrow{\\mathrm{A}}$\r\n\\\\\r\n\\\\\\textbf{Normal and Directional derivative}\r\n \\\\\\\\\\textbf{ Normal:}\\newline If $\\phi(x, y, z)=c$,  represents a family of surfaces for different values of the constant\r\n c. On differentiating $\\phi,$ \r\n\r\n\\begin{align*}\r\n\t \\text{We get,} \\hspace{0.8cm}  d \\phi&=0\r\n\t\\\\\\text{But,} \\hspace{0.8cm} d \\phi&=\\nabla \\phi \\cdot d \\vec{r} \\quad \\\\\r\n\t\\text{So,} \\hspace{0.05cm} \\quad \\nabla \\phi \\cdot d r&=0\r\n\t\\end{align*}\r\nThe scalar product of two vectors $\\nabla \\phi$ and $d \\vec{r}$ being zero, $\\nabla \\phi$ and $d \\vec{r}$ are perpendicular to each other. Then, $d \\vec{r}$ is in the direction of tangent to the given surface.\r\n\r\n\t\\begin{itemize}\r\n\t\\item  Normal vector to the level surface\\hspace{1.2cm}: $\\vec{\\nabla} \\phi$ \r\n\t\\item   Unit normal vector to the level surface\\quad: $\\hat{n}=\\frac{\\vec{\\nabla} \\phi}{|\\vec{\\nabla} \\phi|}$\r\n\\end{itemize}\r\n\t\r\n\\begin{exercise}\r\n\t Find the unit normal to the surface:$x^{2}+y^{2}=z$ at a point (1,2,5) \\end{exercise}\r\n\t \\begin{answer}\r\n\t \t\t\\begin{align*}\r\n\t \t\t\\text{Let}\\ \\phi&=x^{2}+y^{2}-z\\\\\r\n\t \t\t\\nabla \\phi&=\\left(\\hat{i} \\frac{\\partial}{\\partial x}+\\hat{j} \\frac{\\partial}{\\partial y}+\\hat{k} \\frac{\\partial}{\\partial z}\\right)\\left(x^{2}+y^{2}-z\\right)=2 x \\hat{i}+2 y \\hat{j}-\\hat{k}\\\\\r\n\t \t\t(\\nabla \\phi)_{1,2,5}&=2 \\hat{i}+4 \\hat{j}-\\hat{k}\\\\\r\n\t \t\t\\text { Unit normal vector }&=\\frac{\\Delta \\phi}{|\\Delta \\phi|}\\\\&=\\frac{2 \\hat{i}+4 \\hat{j}-\\hat{k}}{\\sqrt{4+16+1}}\\\\&=\\frac{2}{\\sqrt{21}} \\hat{i}+\\frac{4}{\\sqrt{21}} \\hat{j}-\\frac{\\hat{k}}{\\sqrt{21}}\r\n\t \t\\end{align*}\r\n\t \\end{answer}\r\n\r\n\t\r\n \\subsubsection{Directional derivative} Directional derivative of $\\phi$ in the direction of $\\vec{A}$ is defined as rate of change of\r\n$\\phi$ with distance along the direction of $\\vec{A}$. It is mathematically defined as the component of $\\vec{\\nabla} \\phi$ in the direction of vector $\\vec{A}$ i.e.\r\n\\begin{equation*}\r\n \\vec{\\nabla} \\phi\\cdot{{\\hat A}}=\\vec{\\nabla} \\phi.\\frac{\\vec A}{|\\vec{A}|}\r\n\\end{equation*}\r\n\\begin{exercise}\r\n\tFind the directional derivative of $\\phi(x, y, z)=x^{2} y z+4 x z^{2}$ at (1,-2,1) in the direction of $2 \\hat{i}-\\hat{j}-2 \\hat{k}$.\\end{exercise}\r\n\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\phi(x, y, z)&=x^{2} y z+4 x z^{2}\\\\\r\n\t\t\\nabla \\phi&=\\left(\\hat{i} \\frac{\\partial}{\\partial x}+\\hat{j} \\frac{\\partial}{\\partial y}+\\hat{k} \\frac{\\partial}{\\partial z}\\right)\\left(x^{2} y z+4 x z^{2}\\right)\\\\\r\n\t\t&=\\left(2 x y z+4 z^{2}\\right) \\hat{i}+\\left(x^{2} z\\right) \\hat{j}+\\left(x^{2} y+8 x z\\right) \\hat{k} \\\\\r\n\t\t\\nabla \\phi \\text { at }(1,-2,1) &=\\left\\{2(1)(-2)(1)+4(1)^{2}\\right\\} \\hat{i}+(1 \\times 1) \\hat{j}+\\{1(-2)+8(1)(1)\\} \\hat{k} \\\\\r\n\t\t&=(-4+4) \\hat{i}+\\hat{j}+(-2+8) \\hat{k}=\\hat{j}+6 \\hat{k} \\\\\r\n\t\t\\hat{a} &=\\text { unit vector }=\\frac{2 \\hat{i}-\\hat{j}-2 \\hat{k}}{\\sqrt{4+1+4}}=\\frac{1}{3}(2 \\hat{i}-\\hat{j}-2 \\hat{k})\r\n\t\t\\intertext{So, the  directional derivative at (1,-2,1)}&=\\nabla \\phi \\cdot \\hat{a}\\\\\r\n\t\t&=(\\hat{j}+6 \\hat{k}) \\cdot \\frac{1}{3}(2 \\hat{i}-\\hat{j}-2 \\hat{k})\\\\&=\\frac{1}{3}(-1-12)=\\frac{-13}{3}\r\n\t\\end{align*}\r\n\\end{answer} \r\n\\subsubsection{Tangent planes}\r\n\\vspace{-0.8cm}\r\n\\begin{minipage}{0.6\\textwidth}\r\n\tConsider $\\phi(x, y, z)=c$ be the equation of a level surface, and $\\vec{r}=x_{0} i+y_{0}\\hat{j}+z_{0} \\hat{k}$ be the position vector of\r\nany point $\\mathrm{P}(x, y, z)$ on this surface. \\\\\\\\Since, $ \\vec{\\nabla} \\phi$ is a vector normal to the surface, it is perpendicular to the tangent plane at\r\nP. \r\n\\end{minipage}\r\n\\begin{minipage}{0.4\\textwidth}\r\n\t\\includegraphics[width=8cm]{tangent plane}\r\n\\end{minipage}\r\n\r\n\r\n Let, $\\vec{R}=x\\hat{i}+y \\hat{j}+z\\hat{k}$ be the position vector of any point on the tangent plane at $P$ to the surface.\\\\\\\\  Then,\r\n$\\vec{R}-\\vec{r}=(x-x_{0}) \\hat{i}+(y-y_{0}) \\hat{i}+(z-z_{0}) \\hat{k}$ lies in the tangent plane at $P$ and it will be perpendicular to $\\vec{\\nabla} \\phi$\r\n\\\\Then the tangent plane at the point P :\\begin{align*}\r\n(\\vec{R}-\\vec{r}) \\cdot \\vec{\\nabla} \\phi&=0\\\\\r\n(x-x_{0}) \\frac{\\partial \\phi}{\\partial x}+(y-y_{0}) \\frac{\\partial \\phi}{\\partial y}+(z-z_{0}) \\frac{\\partial \\phi}{\\partial z}&=0\r\n\\end{align*}\r\n\r\n \r\n\r\n\r\n%...........................................................................................\r\n\\subsection{Divergence ($\\nabla \\cdot$)}\r\nThe divergence of a vector field measures how much the flow is expanding at a given point. It does not indicate in which direction the expansion is occuring. Hence the divergence is a scalar. Divergence of a continuous differentiable vector point function $A$ specified in a vector field is given\r\nby,\r\n$$\r\n{\\nabla} \\cdot \\vec{f}=\\frac{1}{h_{1} h_{2} h_{3}}\\left[\\frac{\\partial}{\\partial q_{1}}\\left(h_{2} h_{3} f_{1}\\right)+\\frac{\\partial}{\\partial q_{2}}\\left(h_{3} h_{1} f_{2}\\right)+\\frac{\\partial}{\\partial q_{3}}\\left(h_{1} h_{2} f_{3}\\right)\\right]\r\n$$\r\nIn Cartesian coordinate system,\r\n\r\n$$ \\nabla.f=\\frac{\\partial f_{1}}{\\partial x}+\\frac{\\partial f_{2}}{\\partial y}+\\frac{\\partial f_{3}}{\\partial z}$$\r\nYou can't\r\nhave the divergence of a scalar: that’s meaningless.\r\n\r\n\r\n\\subsubsection{Physical interpretation}\r\n$\\vec{\\nabla} \\cdot \\vec{A}$ is a measure of how much the vector $\\vec{A}$ spreads out (diverges) from a point in space.\r\n\\begin{figure}[H]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=9cm,height=3cm]{divergence-crop}\r\n\t\\end{center}\r\n\\caption{Physical intepretation of divergence.}\r\n\\end{figure}\r\n\r\n\\begin{note}\r\n\t$\\bullet$ If $\\vec{\\nabla} \\cdot \\vec{A}=0,$ then $\\vec{A}$ is known as solenoidal vector field.\r\n\t\\\\$\\bullet$ If $\\vec{\\nabla} \\cdot \\vec{A}=$ negative, then $\\vec{A}$ is known as sink field i.e. vector lines are going inward.\r\n\t\\\\$\\bullet$ If $\\vec{\\nabla} \\cdot \\vec{A}=$ positive, then $\\vec{A}$ is known as source field i.e. vector lines are the going outward.\r\n\\end{note}\r\n\\textbf{Product rules}\\\\\\\\$\\bullet$ $\\vec{\\nabla} \\cdot(f \\overrightarrow{\\mathrm{A}})=f(\\vec{\\nabla} \\cdot \\overrightarrow{\\mathrm{A}})+\\overrightarrow{\\mathrm{A}} \\cdot(\\vec{\\nabla} f)$\r\n$\\\\\\bullet \\vec{\\nabla} \\cdot(\\vec{A} \\times \\vec{B})=\\vec{B} \\cdot(\\vec{\\nabla} \\times \\vec{A})-\\vec{A} \\cdot(\\vec{\\nabla} \\times \\vec{B})$\r\n\\begin{exercise}\r\n\t \r\n\tCalculate $\\nabla \\cdot \\vec{ r}$\\end{exercise}\r\n\t \\begin{answer}\r\n\t \r\n\t \\begin{align*}\r\n\t \t\\vec{ r}&=x\\hat{i}+y\\hat{j}+z\\hat{k}\\\\\r\n\t \t\\nabla \\cdot \\vec{ r} &=\\left(\\hat{i} \\frac{\\partial}{\\partial x}+\\hat{j} \\frac{\\partial}{\\partial y}+\\hat{k} \\frac{\\partial}{\\partial z}\\right) \\cdot (x\\hat{i}+y\\hat{j}+z\\hat{k})\\\\\r\n\t \t&=\\frac{\\partial x}{\\partial x}+\\frac{\\partial y}{\\partial y}+\\frac{\\partial z}{\\partial z}\\\\\r\n\t \t&=1+1+1\\\\\r\n\t \t&=3\r\n\t \\end{align*}\r\n\t \r\n\t \r\n\t \\end{answer}\r\n\t \r\n\t \r\n\r\n\\subsection{Curl}\r\nThe curl is the vector valued derivative of a vector function. Its operation can be geometrically interpreted as the rotation of a field about a point in space.\\\\From the definition of $\\vec{\\nabla}$ we construct the curl of a vector $\\vec{f}=f_1\\hat{e}_{1}+f_2\\hat{e}_{2}+f_3\\hat{e}_{3}$ as\r\n$$\r\n\\nabla \\times \\vec{f\r\n}=\\frac{1}{h_{1} h_{2} h_{3}}\\left|\\begin{array}{lll}\r\n\th_{1} \\hat{e}_{1} & h_{2} \\hat{e}_{2} & h_{3} \\hat{e}_{3} \\\\\r\n\t\\partial / \\partial q_{1} & \\partial / \\partial q_{2} & \\partial / \\partial q_{3} \\\\\r\n\th_{1} f_{1} & h_{2} f_{2} & h_{3} f_{3}\r\n\\end{array}\\right|\r\n$$\r\nIn cartesian coordinate system,\r\n$$\r\n\\nabla \\times \\vec{f\r\n}=\\left|\\begin{array}{lll}\r\n\\hat{{i}} & \\hat{{j}} & \\hat{{k}} \\\\\r\n\\partial / \\partial x & \\partial / \\partial y & \\partial / \\partial z \\\\\r\nf_{1} & f_{2} & f _{3}\r\n\\end{array}\\right|\r\n$$\r\n\r\n%...........................................................................................\r\n\\subsubsection{Physical interpretation}\r\n\\begin{figure}[H]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=9cm,height=4cm]{coordinate2}\r\n\t\\end{center}\r\n\t\\caption{Physical interpretation of Curl}\r\n\\end{figure}\r\nThe curl of a vector field measures the tendency for the vector field to swirl around. Imagine that the vector field represents the velocity vectors of water in a lake. If the vector field swirls around, then when we stick a paddle wheel into the water, it will tend to spin. The amount of the spin will depend on how we orient the paddle. Thus, we should expect the curl to be vector valued.\\\\\r\n\\\\$\\bullet \\ $ If $\\vec{\\nabla} \\times \\vec{V}=0,$ then $\\vec{V}$ is known as an irrotational vector and we can write $\\vec{V}=\\vec{\\nabla} \\phi$\r\n\\\\$\\bullet \\ $ If $\\vec{\\nabla} \\times \\vec{V} \\neq 0,$ then $\\vec{V}$ is known as rotational vector.\r\n\\\\\\\\\\textbf{Product rules}\\\\\r\n\\\\$\\bullet \\ \\vec{\\nabla} \\times(f \\overrightarrow{\\mathrm{A}})=f(\\vec{\\nabla} \\times \\overrightarrow{\\mathrm{A}})-\\overrightarrow{\\mathrm{A}} \\times(\\vec{\\nabla} f)$\r\n$\\\\\\bullet \\ \\vec{\\nabla} \\times(\\overrightarrow{\\mathrm{A}} \\times \\overrightarrow{\\mathrm{B}})=(\\overrightarrow{\\mathrm{B}} \\cdot \\vec{\\nabla} ) \\overrightarrow{\\mathrm{A}}-(\\overrightarrow{\\mathrm{A}} \\cdot \\vec{\\nabla}) \\overrightarrow{\\mathrm{B}}+\\overrightarrow{\\mathrm{A}}(\\vec{\\nabla} \\cdot \\overrightarrow{\\mathrm{B}})-\\overrightarrow{\\mathrm{B}}(\\vec{\\nabla} \\cdot \\overrightarrow{\\mathrm{A}})$\r\n\r\n\\begin{exercise}\r\n\t Prove that $\\left(y^{2}-z^{2}+3 y z-2 x\\right) \\hat{i}+(3 x z+2 x y) \\hat{j}+(3 x y-2 x z+2 z) \\hat{k}$ is  irrotational.\\end{exercise}\r\n\t\\begin{answer}\r\n\t\tFor irrotational, we have to prove Curl $\\bar{F}=0$.\r\n\t\t\\begin{align*}\r\n\t\t\\operatorname{Curl} \\vec{F}&=\\left|  \\begin{array}{lll}\r\n\t\t\\hat{i} & \\hat{j} & \\hat{k} \\\\\r\n\t\t\\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\\r\n\t\ty^{2}-z^{2}+3 y z-2 x & 3 x z+2 x y & 3 x y-2 x z+2 z\r\n\t\t\\end{array}\\right| \\\\\r\n\t\t\t&=(3 x-3 x) \\hat{i}-(-2 z+3 y-3 y+2 z) \\hat{j}+ \r\n\t\t(3 z+2 y-2 y-3 z) \\hat{k}\\\\&=0 \\hat{i}+0 \\hat{j}+0 \\hat{k}=0\r\n\t\t\t\\intertext{Thus, $\\vec{F}$ is irrotational.}\r\n\t\t\\end{align*}\r\n\t\t\\end{answer}\r\n\t\\begin{note}\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item The divergence of a curl of a vector field vanishes.\r\n\t\t\t\\\\$ \\nabla \\cdot(\\nabla \\times u)=0$\\\\If $ \\nabla \\cdot v=0 \\Longrightarrow v= \\nabla \\times u$\r\n\t\t\t\\item The curl of gradient of a scalar field vanishes.\r\n\t\t\t\\\\$ \\nabla \\times(\\nabla \\phi)=0$\\\\If $ \\nabla \\times \\psi=0 \\Longrightarrow \\psi= \\nabla  u$\r\n\t\t\\end{enumerate}\r\n\t\\end{note} \r\n\r\n\r\n\\subsection{Laplacian}\r\n\r\nThe divergence of the gradient of a scalar function is called the Laplacian. In general culvilinear coordinate system laplacian can be written as,\r\n\\begin{align*}\r\n\\nabla^{2}=\\frac{1}{h_{1} h_{2} h_{3}}\\left[\\frac{\\partial}{\\partial u_{1}}\\left(\\frac{h_{2} h_{3}}{h_{1}} \\frac{\\partial}{\\partial u_{1}}\\right)+\\right. \r\n\\left. \\frac{\\partial}{\\partial u_{2}}\\left(\\frac{h_{1} h_{3}}{h_{2}} \\frac{\\partial}{\\partial u_{2}}\\right)+\\frac{\\partial}{\\partial_{u_{3}}}\\left(\\frac{h_{1} h_{2}}{h_{3}} \\frac{\\partial}{\\partial_{u_{3}}}\\right)\\right]\r\n\\end{align*}\r\n\r\nIn cartesian coordinate sytem,\r\n$$ \\nabla^{2}=\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+\\frac{\\partial^{2}}{\\partial z^{2}}$$\r\n\\begin{table}[h]\r\n\t\\overfullrule=0pt\r\n\t\\begin{tabular}{|p{1.8cm}|p{6cm}|p{8.5cm}|}\r\n\t\t\\hline\r\n\t\t\r\n\t\t&\\textbf{Cylindrical polar}($ \\rho,\\phi,z$) & \\textbf{Spherical polar}(r,$\\theta$,$\\phi$)  \\\\\\hline\r\n\t\tScale factor&  ${\\begin{array}{l}\r\n\t\t\t\th_{1}=1  \\\\\r\n\t\t\t\th_{2}=r \\\\\r\n\t\t\t\th_{3}=1\r\n\t\t\\end{array}}$ &${\\begin{array}{l}\r\n\t\t\t\th_{1}=1  \\\\\r\n\t\t\t\th_{2}=r \\\\\r\n\t\t\t\th_{3}=r \\sin \\theta\r\n\t\t\\end{array}}$   \\\\\\hline\r\n\t\tGradient& $$\r\n\t\t\\frac{\\partial {f}}{\\partial \\boldsymbol{\\rho}} \\hat{\\rho}+\\frac{1}{\\rho}\\frac{\\partial {f}}{\\partial {\\phi}} \\hat{\\phi}+\\frac{\\partial {f}}{\\partial {z}} \\hat{{z}}\r\n\t\t$$\\vspace{1cm}&$$\r\n\t\t\\hat{{r}} \\frac{\\partial f}{\\partial r}+\\hat{\\boldsymbol{\\theta}} \\frac{1}{r} \\frac{\\partial f}{\\partial \\theta}+\\hat{{\\phi}} \\frac{1}{r \\sin \\theta} \\frac{\\partial f}{\\partial \\phi}\r\n\t\t$$\\\\\\hline\r\n\t\tDivergence\\vspace{1cm}& $$\r\n\t\t\\frac{1}{\\rho} \\frac{\\partial }{\\partial \\rho}\\left(\\rho F_{\\rho}\\right)+\\frac{1}{\\rho} \\frac{\\partial }{\\partial \\phi}\\left(F_{\\phi}\\right)+\\frac{\\partial }{\\partial z}\\left(F_{z}\\right)\r\n\t\t$$ & $$\r\n\t\t\\frac{1}{\\mathrm{r}^{2}} \\frac{\\partial}{\\partial \\mathrm{r}}\\left(r^{2} F_{\\mathrm{r}}\\right)+\\frac{1}{\\mathrm{rsin} \\theta} \\frac{\\partial}{\\partial \\theta}\\left(F_{\\theta} \\sin \\theta\\right)+\\frac{1}{r \\sin \\theta} \\frac{\\partial \\mathrm{F}_{\\phi}}{\\partial \\phi}\r\n\t\t$$ \\\\\\hline\r\n\t\tCurl\\vspace{1cm}&$$\r\n\t\t\\frac{1}{\\rho } \\left|\\begin{array}{ccc}\r\n\t\t\t\\hat{\\rho} & \\hat{\\phi} & \\hat{{z}} \\\\\r\n\t\t\t\\frac{\\partial}{\\partial \\boldsymbol{\\rho}} & \\frac{\\partial}{\\partial \\phi} & \\frac{\\partial}{\\partial \\mathbf{z}} \\\\\r\n\t\t\t{F}_{\\rho} & {F}_{\\phi} & {F}_{{z}}\r\n\t\t\\end{array}\\right|\r\n\t\t$$ &$$\r\n\t\t\\frac{1}{r^{2} \\sin \\theta}\\left|\\begin{array}{ccc}\r\n\t\t\t\\hat{e}_{r} & r \\hat{e}_{\\theta} & r \\sin \\theta \\hat{e}_{\\phi} \\\\\r\n\t\t\t\\partial / \\partial r & \\partial / \\partial \\theta & \\partial / \\partial \\phi \\\\\r\n\t\t\tF_{r} & r F_{\\theta} & r \\sin \\theta F_{\\phi}\r\n\t\t\\end{array}\\right|\r\n\t\t$$ \\\\\\hline\r\n\tLaplacian\t& $$\\frac{\\partial^{2} f}{\\partial r^{2}}+\\frac{1}{r} \\frac{\\partial f}{\\partial r}+\\frac{1}{r^{2}} \\frac{\\partial^{2} f}{\\partial \\theta^{2}}+\\frac{\\partial^{2} f}{\\partial z^{2}}$$ &$$\r\n\t\\frac{1}{\\mathrm{r}^{2}} \\frac{\\partial}{\\partial \\mathrm{r}}\\left(r^{2} \\frac{\\partial f}{\\partial r}\\right)+\\frac{1}{\\mathrm{r^{2}sin} \\theta} \\frac{\\partial}{\\partial \\theta}\\left( \\sin \\theta \\frac{\\partial f}{\\partial \\theta}\\right)+\\frac{1}{r^{2} \\sin^{2} \\theta} \\frac{\\partial^{2} f}{\\partial \\phi^{2}}\r\n\t$$ \r\n\t\\\\\\hline\r\n\r\n\t\\end{tabular}\r\n\\label{differential operators}\r\n\\caption{Differential operators in general culvilinear coordinate system}\r\n\\end{table}\r\n\\vspace{1cm}\r\n\t\r\n\r\n\r\n\r\n\\subsection{Important identities}\r\n\\begin{enumerate}\r\n\t \r\n\t\\item $\\nabla \\cdot \\nabla \\vec{A}=\\nabla^{2} A=\\frac{\\partial^{2} \\vec{A}}{\\partial x^{2}}+\\frac{\\partial^{2} \\vec{A}}{\\partial y^{2}}+\\frac{\\partial^{2} \\vec{A}}{\\partial z^{2}}$( The Laplace operator.)\r\n\\item $\\nabla \\times \\nabla \\vec{A}=0$\r\n\\item $\\nabla \\cdot \\nabla \\times \\vec{A}=0$\r\n\t\\item $\\nabla \\times(\\nabla \\times \\vec{A})=\\nabla(\\nabla \\cdot \\vec{A}) \\times \\nabla^{2} \\vec{A}$\r\n\t\\item $\\nabla(\\nabla \\cdot \\vec{A})=\\nabla \\times(\\nabla \\times \\vec{A})+\\nabla^{2} \\vec{A}$\r\n\t\\item $\\nabla(\\vec{A}+\\vec{B})=\\nabla \\cdot \\vec{A}+\\nabla \\cdot \\vec{B}$\r\n\\item $\\nabla \\times(\\vec{A}+\\vec{B})=\\nabla \\times \\vec{A}+\\nabla \\times \\vec{B}$\r\n\\item $\\nabla \\cdot(\\vec{A} \\times \\vec{B})=\\vec{B} \\cdot(\\nabla \\times \\vec{A})-\\vec{A} \\cdot(\\nabla \\times \\vec{B})$\r\n\\item $\\nabla \\times(\\vec{A} \\times \\vec{B})=(B \\cdot \\nabla) A-B(\\nabla \\cdot A)-(A \\nabla)$\r\n$\\quad B+A(\\nabla B)$\r\n\\end{enumerate}\r\n\\section{Integral Calculus}\r\n\\subsection{Line integration of vectors}\r\n\\begin{figure}[H]\r\n\t\\begin{center}\r\n\\includegraphics[width=3cm,height=3cm]{cs-01-crop}\r\n\t\t\r\n\t\\end{center}\r\n\\caption{Line integration}\r\n\\label{line integration}\t\r\n\\end{figure}\r\nThe integration of a vector function $\\vec F$ along a curve is known as line integration of vectors.Infact the line integral along the curve is the integral of $\\vec F$ along the tangent to the curve. \r\n Consider a pont P in the curve in figure \\ref{line integration} such that the position vector of P is given by $\\vec r$.\\\\The component of $\\vec F$ along the tangent at P = $\\left(\\vec{F} \\cdot \\frac{d \\vec{r}}{d s}\\right)$ \\newline Then the Line integral of $\\vec{F}$ from $A$ to $B$ along the curve $C$ will be, \r\n $$\\text{ Line integral}=\\int_{c}\\left(\\vec{F} \\cdot \\frac{d \\vec{r}}{d s}\\right) d s=\\int_{c} \\vec{F} \\cdot d \\vec{r}$$\r\n\r\n\r\n\\begin{note}\r\n\t\\begin{itemize}\r\n\t\t\\item If $\\vec{F}$ represents the variable force acting on a particle along arc $\\mathrm{AB}$, then the total work done\r\n\t\t$W_{A B}=\\int_{A}^{B} \\vec{F} \\cdot d \\vec{r}$ \r\n\t\t\\item  If $\\vec{V}$ represents the velocity of a liquid then $\\oint_{c} \\vec{V} \\cdot d \\vec{r}$ is called the circulation of $\\vec{V}$ round closed curve\r\n\t\t$C$\r\n\t\t\\item When the path of integration is a closed curve then notation of integration is $\\oint$ in place of $\\int$.\r\n\t\\end{itemize}\r\n\\end{note}\r\n\\begin{example}\r\n\\textbf{Workdone}\r\n\\\\  Work done by a conservative field $\\vec{A}$ in moving a particle from point $P$ to $Q$ will be\r\n$$\r\n\\int_{P}^{Q} \\vec{F} \\cdot \\overrightarrow{d r}=\\int_{P}^{Q} \\vec{\\nabla} \\phi \\cdot \\overrightarrow{d r}=\\int_{P}^{Q} d \\phi=\\phi_{Q}-\\phi_{P}=\\text { independent of path. }\r\n$$\r\n\\\\ Ordinarily, the value of a line integral depends critically on the particular path taken from\r\n$a$ to $b$, but there is an important special class of vector functions for which the line\r\nintegral is independent of the path, and is determined entirely by the end points $($ A force\r\nthat has this property is called conservative).\\\\$\\vec{A}$ in moving a particle around a closed path $C$ is $\\oint_{c} \\vec{F} \\cdot \\overrightarrow{d r}=0$\r\n\\end{example}\r\n\\begin{exercise}\r\n\t If a force $\\vec{F}=2 x^{2} y \\hat{i}+3 x y \\hat{j}$ displaces a particle in the xy-plane from (0,0) to\r\n\t(1,4) along a curve $y=4 x^{2} .$ Find the work done.\\end{exercise}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\text{Work done}&=\\int_{c} \\vec{F} \\cdot \\overrightarrow{d r} \\\\\r\n\t\t&=\\int_{c}\\left(2 x^{2} y \\hat{i}+3 x y \\hat{j}\\right) \\cdot(d x \\hat{i}+d y \\hat{j}) \\\\\r\n\t\t&=\\int_{c}\\left(2 x^{2} y d x+3 x y d y\\right)\\\\\r\n\t\t&\\left[\\begin{array}{l}\r\n\t\t\\vec{r}=x \\hat{i}+y \\hat{j} \\\\\r\n\t\t\\overrightarrow{d r}=d x \\hat{i}+d y \\hat{j}\r\n\t\t\\end{array}\\right]\r\n\t\t\\intertext{Putting the values of $y$ and $d y$, we get}\r\n\t\t&=\\int_{0}^{1} \\cdot\\left[2 x^{2}\\left(4 x^{2}\\right) d x+3 x\\left(4 x^{2}\\right) 8 x d x\\right]\t\\quad\\left[\\begin{array}{l}\r\n\t\ty=4 x^{2} \\\\\r\n\t\td y=8 x d x\r\n\t\t\\end{array}\\right] \\\\\r\n\t\t&=104 \\int_{0}^{1} x^{4} d x=104\\left(\\frac{x^{5}}{5}\\right)_{0}^{1}=\\frac{104}{5}\r\n\t\t\\end{align*}\r\n\t\\end{answer}\r\n\t\r\n\r\n\r\n\r\n\\subsection{Surface integration of vectors}\r\n\r\nIt's the two dimensional analog of line integral. Physically, it can be thought of as flow of a fluid through a surface. It is \r\nthe integration of a vector on an open or closed surface.\\\\\r\nFor a function $F(x,y,z)$ the surface integral over a surface S is given as,$$S=\\iint_{S}(\\mathbf{F} \\cdot \\hat{n}) d S=\\iint_{S} \\mathbf{F} \\cdot d \\mathbf{S}$$\r\n\\\\\r\n where $n$ is the unit normal vector to an element $d s$ and\r\n$$\r\n\\hat{n}=\\frac{\\operatorname{grad} f}{|\\operatorname{grad} f|} \\quad d s=\\frac{d x d y}{(\\hat{n} \\cdot \\hat{k})}\r\n$$\r\n\\begin{note}\r\nIf $\\iint_{S}(\\vec{F} \\cdot \\hat{n}) d s=0,$ then $\\vec{F}$ is said to be a solenoidal vector point function.\t\r\n\\end{note}\r\n\\begin{example}\\hspace{0.5cm}\\textbf{Flux}\\\\\r\n\t$\\mathrm{Flux}=\\iint_{S}(\\vec{F} \\cdot \\hat{n}) d s$ where, $\\bar{F}$ represents the velocity of a liquid.\r\n\\end{example}\r\n\\begin{exercise}\r\n\tEvaluate $\\iint_{S}(y z \\hat{i}+z x \\hat{j}+x y \\hat{k}) \\cdot \\overrightarrow{d s}$ where $S$ is the surface of the sphere\r\n\t$x^{2}+y^{2}+z^{2}=a^{2}$ in the first octant. \\end{exercise}\r\n\\begin{answer}\r\n\t Here, $\\phi=x^{2}+y^{2}+z^{2}-a^{2}$\r\n\t\\\\Vector normal to the surface \r\n\t\t\\begin{align*}\r\n\t\t\\nabla \\phi&=\\hat{i} \\frac{\\partial \\phi}{\\partial x}+\\hat{j} \\frac{\\partial \\phi}{\\partial y}+\\hat{k} \\frac{\\partial \\phi}{\\partial z}\\\\\r\n\t\t&=\\left(\\hat{i} \\frac{\\partial}{\\partial x}+\\hat{j} \\frac{\\partial}{\\partial y}+\\hat{k} \\frac{\\partial}{\\partial z}\\right)\\left(x^{2}+y^{2}+z^{2}-a^{2}\\right)=2 x \\hat{i}+2 y \\hat{j}+2 z \\hat{k} \\\\ \\hat{n} &=\\frac{\\nabla \\phi}{|\\nabla \\phi|}=\\frac{2 x \\hat{i}+2 y \\hat{j}+2 z \\hat{k}}{\\sqrt{4 x^{2}+4 y^{2}+4 z^{2}}}=\\frac{x \\hat{i}+y \\hat{j}+z \\hat{k}}{\\sqrt{x^{2}+y^{2}+z^{2}}} \\\\ &=\\frac{x \\hat{i}+y \\hat{j}+z \\hat{k}}{a}\\quad\\left[\\because x^{2}+y^{2}+z^{2}=a^{2}\\right]\\\\\t\\vec{F}&=y z \\hat{i}+z x \\hat{j}+x y \\hat{k}\\\\\r\n\t\t\\vec{F} \\cdot \\hat{n}&=(y z \\hat{i}+z x \\hat{j}+x y \\hat{k}) \\cdot\\left(\\frac{x \\hat{i}+\\hat{y}+z \\hat{k}}{a}\\right)=\\frac{3 x y z}{a}  \\end{align*}\r\n\t\r\n\t\\begin{align*}\r\n\t\t\\quad \\iint_{S} F \\cdot \\hat{n} d s&=\\iint_{S}(\\vec{F} \\cdot \\hat{n}) \\frac{d x d y}{|\\hat{k} \\cdot \\hat{n}|}\\\\&=\\int_{0}^{a} \\int_{0}^{\\sqrt{a^{2}-x^{2}}} \\frac{3 x y z d x d y}{a\\left(\\frac{z}{a}\\right)}\\\\\r\n\t\t&=3 \\int_{0}^{a} \\int_{0}^{\\sqrt{a^{2}-x^{2}}} x y d y d x\\\\\r\n\t\t&=3 \\int_{0}^{a} x\\left(\\frac{y^{2}}{2}\\right)_{0}^{\\sqrt{a^{2}-x^{2}}} d x\\\\\r\n\t\t&=\\frac{3}{2} \\int_{0}^{a} x\\left(a^{2}-x^{2}\\right) d x\\\\\r\n\t\t&=\\frac{3}{2}\\left(\\frac{a^{2} x^{2}}{2}-\\frac{x^{4}}{4}\\right)_{0}^{a}\\\\&=\\frac{3}{2}\\left(\\frac{a^{4}}{2}-\\frac{a^{4}}{4}\\right)\\\\&=\\frac{3 a^{4}}{8} .\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\t\r\n\t\r\n\r\n\\subsection{Volume Integration of Vectors}\r\n\r\nVolume integral refers to the integral over a 3 dimensional domain.\r\nVolume integral of a vector field $\\vec{F}$ within the volume $V$ can be written as,\r\n$$\\text{Volume integral=}\\iiint_{V} \\vec{F} \\cdot dV$$ Where, $d V$ is the infinitesimal volume element\\\\\\\\\r\n$dV= dx dy dz$\\hspace{2.2cm}-In Cartesian cooordinate system\\\\\\\\\r\n$dV= r^{2} sin\\theta dr d\\theta d\\phi$\\hspace{0.9cm}-In Spherical polar cordinate \\\\\\\\\r\n$dV= d V=r d \\theta d r d z$\\hspace{0.9cm}-In Cylindrical polar coordinate system\r\n\\begin{exercise}\r\n\t If $\\vec{F}=2 z \\hat{i}-x \\hat{j}+y \\hat{k},$ evaluate $\\iiint_{V} \\vec{F} d v$ where, $v$ is the region bounded by\r\n\tthe surfaces $x=0, y=0, x=2, y=4, \\quad z=x^{2}, \\quad z=2$\\end{exercise}\r\n\t\\begin{answer}\r\n\t\t\t\r\n\t\t\\begin{align*}\r\n\t\t\t\\iiint_{V} \\vec{F} d v&=\\iiint(2 z \\hat{i}-x \\hat{j}+y \\hat{k}) d x d y d z \\\\\r\n\t\t\t&=\\int_{0}^{2} d x \\int_{0}^{4} d y \\int_{x^{2}}^{2}(2 z \\hat{i}-x \\hat{j}+y \\hat{k}) d z\\\\&=\\int_{0}^{2} d x \\int_{0}^{4} d y\\left[z^{2} \\hat{i}-x z \\hat{j}+y z \\hat{k}\\right]_{x^{2}}^{2} \\\\\r\n\t\t\t&=\\int_{0}^{2} d x \\int_{0}^{4} d y\\left[4 \\hat{i}-2 x \\hat{j}+2 y \\hat{k}-x^{4} \\hat{i}+x^{3} \\hat{j}-x^{2} y \\hat{k}\\right] \\\\\r\n\t\t\t&=\\int_{0}^{2} d x\\left[4 y \\hat{i}-2 x y \\hat{j}+y^{2} \\hat{k}-x^{4} y \\hat{i}+x^{3} y \\hat{j}-\\frac{x^{2} y^{2}}{2} \\hat{k}\\right]_{0}^{4}\\\\&=\\int_{0}^{2}\\left(16 \\hat{i}-8 x \\hat{j}+16 \\hat{k}-4 x^{4} \\hat{i}+4 x^{3} \\hat{j}-8 x^{2} \\hat{k}\\right) d x \\\\\r\n\t\t\t&=\\left[16 x \\hat{i}-4 x^{2} \\hat{j}+16 x \\hat{k}-\\frac{4 x^{5}}{5} \\hat{i}+x^{4} \\hat{j}-\\frac{8 x^{3}}{3} \\hat{k}\\right]_{0}^{2} \\\\\r\n\t\t\t&=32 \\hat{i}-16 \\hat{j}+32 \\hat{k}-\\frac{128}{5} \\hat{i}+16 \\hat{j}-\\frac{64}{3} \\hat{k}=\\frac{32 \\hat{i}}{5}+\\frac{32 \\hat{k}}{3}\\\\&=\\frac{32}{15}(3 \\hat{i}+5 \\hat{k})\r\n\t\t\\end{align*}\r\n\t\r\n\t\t\r\n\t\\end{answer}\r\n\r\n\r\n\\section{Theorems}\r\n\\subsection{Divergence Theorem}\r\n\\begin{definition}\r\n\t  The surface integral of the normal component of a vector function $F$ taken around a closed surface $S$ is equal to the integral of the divergence of $F$ taken over the volume $V$ enclosed by the surface $S$. Mathematically\r\n\t$$\r\n\t\\iint_{S} \\vec{F} \\cdot \\hat{n} d s=\\iiint_{V} d i v \\vec{F}\\cdot d V=\\iiint_{V}(\\vec{\\nabla} \\cdot \\vec{F}) d V\r\n\t$$\r\n\tWhere $\\hat{n}$ is the outward normal to ' $S$ ' indicating the positive direction of $S$.\r\n\\end{definition}\r\nThis theorem is applicable only for closed surfaces and it converts surface integral into volume integral and vice versa.\r\n\\\\The divergence theorem is a mathematical statement of the physical fact that, in the absence of the creation or destruction of matter, the density within a region of space can change only by having it flow into or away from the region through its boundary.\r\n\\begin{exercise}\r\nEvaluate  $\\iint_{S} \\vec{F} \\cdot \\hat{n} d s$ where $S$ is the\r\n\tsurface of the sphere $x^{2}+y^{2}+z^{2}=16$ and $\\vec{F}=3 x \\hat{i}+4 y \\hat{j}+5 z \\hat{k}$\\\\By Gauss's divergence theorem,\r\n\\end{exercise}\r\n\\begin{answer}\r\n$$\\begin{aligned}\r\n\t\\iint_{S} \\vec{F} \\cdot \\hat{n} d s&=\\iint_{v} \\int \\nabla \\cdot \\vec{F} d v \\quad\\\\\r\n\tHere ,\\vec{F}&=3 x \\hat{i}+4 y \\hat{j}+5 z \\hat{k}\t\r\n\\end{aligned}$$\r\n$$\r\n\\begin{array}{l}\r\n\t\\nabla \\cdot \\vec{F}=\\left(\\hat{i} \\frac{\\partial}{\\partial x}+\\hat{j} \\frac{\\partial}{\\partial y}+\\hat{k} \\frac{\\partial}{\\partial z}\\right) \\cdot(3 x \\hat{i}+4 y \\hat{j}+5 z \\hat{k}) \\\\\r\n\t\\nabla \\cdot \\vec{F}=3+4+5=14\r\n\\end{array}\r\n$$\r\nPutting the value of $\\nabla . \\mathrm{F}$, we get\r\n$$\r\n\\iint_{S} \\vec{F} \\cdot \\hat{n} d s=\\iint_{v} \\int 14 \\cdot d v\r\n$$\r\nWhere $v$ is volume of a sphere\r\n$$\r\n\\begin{array}{l}\r\n\t=14 v \\\\\r\n\t=14 \\frac{4}{3} \\pi(4)^{3}=\\frac{3584 \\pi}{3}\r\n\\end{array}\r\n$$\r\n\r\n\\end{answer}\t\r\n\r\n\r\n\\subsection{Stoke's  Theorem}\r\n\\begin{definition}\r\nSurface integral of the component of curl $\\vec{F}$ along the normal to the surface $S,$ taken over the surface $S$ bounded by curve $C$ is equal to the line integral of the vector point function\r\n$\\vec{F}$ taken along the closed curve $C$.\\\\\\\\ Mathematically $\r\n\\oint_{C} \\vec{F} \\cdot \\overrightarrow{d r}=\\iint_{S}(\\vec{\\nabla} \\times \\vec{F}) \\hat{n} d s=\\iint_{S}(\\vec{\\nabla} \\times \\vec{F}) \\cdot \\overrightarrow{d s}\r\n$\r\n\\\\\\\\where $\\hat{n}=\\cos \\alpha \\hat{i}+\\cos \\beta \\hat{j}+\\cos \\gamma \\hat{k}$ is a unit\r\nexternal normal to any surface $d S$\t\r\n\\end{definition}\r\nIf we apply Stoke's theorem to a closed surface. Since it has no perimeter, The line integral vanishes. So,\r\n$$ \\iint_{S}(\\vec{\\nabla} \\times \\vec{F})  \\cdot \\overrightarrow{d s}=0 \\rightarrow \\text{For $ S $, a closed surface}$$\r\n\\begin{exercise}\r\n Evaluate by Stokes theorem $\\oint_{C}(y z d x+z x d y+x y d z)$ where $C$ is the curve $x^{2}+y^{2}=1, z=y^{2}$\\end{exercise}\r\n\\begin{answer}\r\n\t Here we have\r\n\t$$ \r\n\t\\begin{aligned}\r\n\t\t\\oint y z d x+z x d y+x y d z&=\\int(y z \\hat{i}+z x \\hat{j}+x y \\hat{k}) \\cdot(\\hat{i} d x+\\hat{j} d y+k d z)\r\n\t\\end{aligned}\r\n\t$$\r\n\t$$\r\n\t\\begin{aligned}\r\n\t\t=\\oint F . d x &  \\\\\r\n\t\t=\\int \\text { curl} F\\cdot nds  =0  \\\\\r\n\t\\end{aligned}\r\n\t$$\r\n\t\r\n\t$$\r\n\t\\begin{aligned}\r\n\t\t\\because\r\n\t\t\\text { Curl } \\vec{F} &=\\left|\\begin{array}{lll}\r\n\t\t\t\\hat{i} & \\hat{j} & \\hat{k} \\\\\r\n\t\t\t\\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\\r\n\t\t\ty z & z x & x y\r\n\t\t\\end{array}\\right|\\\\&=(x-x) \\hat{i}+(y-y) \\hat{j}+(z-z) \\hat{k}=0\r\n\t\\end{aligned}\r\n\t$$\r\n\t\r\n\\end{answer}\r\n\r\n\r\n\\subsection{Green's theorem (In a plane)}\r\n\\begin{definition}\r\n If $\\phi(x, y), \\psi(x, y), \\frac{\\partial \\phi}{\\partial y}$ and $\\frac{\\partial \\psi}{\\partial x}$ be continuous functions over a region $R$ bounded by simple closed curve $C$ in $x-y$ plane, then  $\\oint_{C}(\\phi d x+\\psi d y)=\\iint_{R}\\left(\\frac{\\partial \\psi}{\\partial x}-\\frac{\\partial \\phi}{\\partial y}\\right) d x d y. \\quad$ \r\n\\end{definition}\r\nGreen’s theorem is mainly used for the integration of line combined with a curved plane\r\n.We can write  Green's theorem as\r\n$$\r\n\\int_{c} \\vec{F} \\cdot d \\vec{r}=\\iint_{R}(\\nabla \\times \\vec{F}) \\cdot \\hat{k} d R\r\n$$\r\nWhere, $\\vec{F}=\\phi \\hat{i}+\\psi \\hat{j}, \\bar{r}=x \\hat{i}+y \\hat{j}, \\hat{k}$ is a unit vector along $z$ -axis and $d R=d x d y$\r\n\\begin{exercise}\r\n\t$A$ vector field $\\vec{F}$ is given by $\\vec{F}=\\sin y \\hat{i}+x(1+\\cos y) \\hat{j}$ Evaluate the line integral $\\int_{C} \\vec{F} \\cdot \\overrightarrow{d r}$ where $C$ is the circular path given by $x^{2}+y^{2}=a^{2} .$\\end{exercise}\r\n\\begin{answer}\r\n\t $$\\begin{aligned}\r\n\t\t\\vec{F}&=\\sin y \\hat{i}+x(1+\\cos y) \\hat{j}\\\\\r\n\t\t\\int_{C} \\vec{F} \\cdot \\overrightarrow{d r}&=\\int_{C}[\\sin y \\hat{i}+x(1+\\cos y) \\hat{j}] \\cdot(\\hat{i} d x+\\hat{j} d y)\\\\&=\\int_{C} \\sin y d x+x(1+\\cos y) d y\\\\\r\n\t\t\\text{On applying Green's Theorem, we have}\\\\\r\n\t\t\\oint_{c}(\\phi d x+\\psi d y)&=\\iint_{S}\\left(\\frac{\\partial \\psi}{\\partial x}-\\frac{\\partial \\phi}{\\partial y}\\right) d x d y\\\\\r\n\t\t&=\\iint_{S}[(1+\\cos y)-\\cos y] d x d y\\\\\r\n\t\t\\text{ where S is the circular plane surface of radius a.}\\\\&=\\iint_{S} d x d y=\\text{ Area of circle} =\\pi a^{2} . \r\n\t\\end{aligned}$$\r\n\t\r\n\\end{answer}\r\n\r\n\\newpage\r\n\\pagestyle{plain}\r\n\\begin{abox}\r\n\tProblem Set -1\r\n\\end{abox}\t\r\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\r\n\t\t\\item Let $\\vec{a}$ and $\\vec{b}$ be two distinct three dimensional vectors. Then the component of $\\vec{b}$ that is perpendicular to $\\vec{a}$ is given by\r\n\t{\\exyear{NET/JRF(JUNE-2011)}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $\\frac{\\vec{a} \\times(\\vec{b} \\times \\vec{a})}{a^{2}}$\r\n\t\t\\task[\\textbf{B.}] $\\frac{\\vec{b} \\times(\\vec{a} \\times \\vec{b})}{b^{2}}$\r\n\t\t\\task[\\textbf{C.}] $\\frac{(\\vec{a} \\cdot \\vec{b}) b}{b^{2}}$\r\n\t\t\\task[\\textbf{D.}] $\\frac{(\\vec{b} \\cdot \\vec{a}) \\vec{a}}{a^{2}}$\r\n\t\\end{tasks}\r\n\\item The equation of the plane that is tangent to the surface $x y z=8$ at the point $(1,2,4)$ is\r\n{\\exyear{NET/JRF(DEC-2011)}}\r\n\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{A.}] $x+2 y+4 z=12$\r\n\t\\task[\\textbf{B.}] $4 x+2 y+z=12$\r\n\t\\task[\\textbf{C.}] $x+4 y+2=0$\r\n\t\\task[\\textbf{D.}] $x+y+z=7$\r\n\\end{tasks}\r\nA vector perpendicular to any vector that lies on the plane defined by $x+y+z=5$, is\r\n{\\exyear{NET/JRF(JUNE-2012)}}\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\hat{i}+\\hat{j}$\r\n\t\\task[\\textbf{B.}] $\\hat{j}+\\hat{k}$\r\n\t\\task[\\textbf{C.}] $\\hat{i}+\\hat{j}+\\hat{k}$\r\n\t\\task[\\textbf{D.}] $2 \\hat{i}+3 \\hat{j}+5 \\hat{k}$\r\n\\end{tasks}\r\n\t\\item A unit vector $\\hat{n}$ on the $x y$-plane is at an angle of $120^{\\circ}$ with respect to $\\hat{i}$. The angle between the vectors $\\vec{u}=a \\hat{i}+b \\hat{n}$ and $\\vec{v}=a \\hat{n}+b \\hat{i}$ will be $60^{\\circ}$ if\r\n{\\exyear{NET/JRF(JUNE-2013)}}\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $b=\\sqrt{3} a / 2$\r\n\t\\task[\\textbf{B.}] $b=2 a / \\sqrt{3}$\r\n\t\\task[\\textbf{C.}] $b=a / 2$\r\n\t\\task[\\textbf{D.}] $b=a$\r\n\\end{tasks}\r\n\t\\item The unit normal vector of the point $\\left[\\frac{a}{\\sqrt{3}}, \\frac{b}{\\sqrt{3}}, \\frac{c}{\\sqrt{3}}\\right]$ on the surface of the ellipsoid $\\frac{x^{2}}{a^{2}}+\\frac{y^{2}}{b^{2}}+\\frac{z^{2}}{c^{2}}=1 \\mathrm{is}$\r\n{\\exyear{NET/JRF(DEC-2012)}}\r\n\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\frac{b c \\hat{i}+c a \\hat{j}+a b \\hat{k}}{\\sqrt{a^{2}+b^{2}+c^{2}}}$\r\n\t\\task[\\textbf{B.}] $\\frac{a \\hat{i}+b \\hat{j}+c \\hat{k}}{\\sqrt{a^{2}+b^{2}+c^{2}}}$\r\n\t\\task[\\textbf{C.}] $\\frac{b \\hat{i}+c \\hat{j}+a \\hat{k}}{\\sqrt{a^{2}+b^{2}+c^{2}}}$\r\n\t\\task[\\textbf{D.}] $\\frac{\\hat{i}+\\hat{j}+\\hat{k}}{\\sqrt{3}}$\r\n\\end{tasks}\r\n\\item Let $\\vec{r}$ denote the position vector of any point in three-dimensional space, and $r=|\\vec{r}|$. Then\r\n{\t\\exyear{NET/JRF(DEC-2014)}}\r\n\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{A.}] $\\vec{\\nabla} \\cdot \\vec{r}=0$ and $\\vec{\\nabla} \\times \\vec{r}=\\vec{r} / r$\r\n\t\\task[\\textbf{B.}] $\\vec{\\nabla} \\cdot \\vec{r}=0$ and $\\nabla^{2} r=0$\r\n\t\\task[\\textbf{C.}] $\\vec{\\nabla} \\cdot \\vec{r}=3$ and $\\nabla^{2} \\vec{r}=\\vec{r} / r^{2}$\r\n\t\\task[\\textbf{D.}] $\\vec{\\nabla} \\cdot \\vec{r}=3$ and $\\vec{\\nabla} \\times \\vec{r}=0$\r\n\\end{tasks}\r\n\\item Consider the three vectors $\\vec{v}_{1}=2 \\hat{i}+3 \\hat{k}, \\vec{v}_{2}=\\hat{i}+2 \\hat{j}+2 \\hat{k}$ and $\\vec{v}_{3}=5 \\hat{i}+\\hat{j}+a \\hat{k}$ where $\\hat{i}, \\hat{j}$ and $\\hat{k}$ are the standard unit vectors in a three-dimensional Euclidean space. These vectors will be linearly dependent if the value of $a$ is\r\n{\\exyear{NET/JRF(JUNE-2018)}}\r\n\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\frac{31}{4}$\r\n\t\\task[\\textbf{B.}] $\\frac{23}{4}$\r\n\t\\task[\\textbf{C.}] $\\frac{27}{4}$\r\n\t\\task[\\textbf{D.}] 0\r\n\\end{tasks}\r\n\\begin{note}\r\n\t* For the $4^{th}$ question answer will be $\\frac{b c \\hat{i}+c a \\hat{j}+a b \\hat{k}}{\\sqrt{b^{2} c^{2}+c^{2} a^{2}+a^{2} b^{2}}}$\r\n\\end{note}\r\n\\end{enumerate}\r\n\\colorlet{ocre1}{ocre!70!}\r\n\\colorlet{ocrel}{ocre!30!}\r\n\\setlength\\arrayrulewidth{1pt}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\arrayrulecolor{ocre}\r\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\r\n\t\t\\hline\r\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\r\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\r\n\t\t1&\\textbf{a} &2&\\textbf{b}\\\\\\hline \r\n\t\t3&\\textbf{c} &4&\\textbf{Incorrect option} \\\\\\hline\r\n\t\t5&\\textbf{d} &6&\\textbf{a} \\\\\\hline\r\n\t\t\r\n\t\t\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\begin{abox}\r\n\tProblem Set -2\r\n\\end{abox}\t\r\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\r\n\\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\r\n{\\exyear{GATE 2011}}\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\vec{\\nabla} \\times \\vec{F}=0$\r\n\t\\task[\\textbf{B.}] $\\vec{\\nabla} \\cdot \\vec{F}=0$\r\n\t\\task[\\textbf{C.}] $\\vec{\\nabla} V=0$\r\n\t\\task[\\textbf{D.}] $\\nabla^{2} V=0$\r\n\\end{tasks}\r\n\t\\item The unit vector normal to the surface $x^{2}+y^{2}-z=1$ at the point $P(1,1,1)$ is\r\n{\\exyear{GATE 2011}}\r\n\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\frac{\\hat{i}+\\hat{j}-\\hat{k}}{\\sqrt{3}}$\r\n\t\\task[\\textbf{B.}] $\\frac{2 \\hat{i}+\\hat{j}-\\hat{k}}{\\sqrt{6}}$\r\n\t\\task[\\textbf{C.}] $\\frac{\\hat{i}+2 \\hat{j}-\\hat{k}}{\\sqrt{6}}$\r\n\t\\task[\\textbf{D.}]  $\\frac{2 \\hat{i}+2 \\hat{j}-\\hat{k}}{3}$\r\n\\end{tasks}\r\n\\item Consider a cylinder of height $h$ and radius $a$, closed at both ends, centered at the origin. Let $\\vec{r}=\\hat{i} x+\\hat{j} y+\\hat{k} z$ be the position vector and $\\hat{n}$ be a unit vector normal to the surface. The surface integral $\\int_{S} \\vec{r} \\cdot \\hat{n} d s$ over the closed surface of the cylinder is\r\n{\\exyear{GATE 2011}}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[height=4cm,width=4.5cm]{diagram-20210823(2)-crop}\r\n\\end{figure}\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $2 \\pi a^{2}(a+h)$\r\n\t\\task[\\textbf{B.}] $3 \\pi a^{2} h$\r\n\t\\task[\\textbf{C.}] $2 \\pi a^{2} h$\r\n\t\\task[\\textbf{D.}] Zero\r\n\\end{tasks}\r\n\\item Identify the correct statement for the following vectors $\\vec{a}=3 \\hat{i}+2 \\hat{j}$ and $\\vec{b}=\\hat{i}+2 \\hat{j}$\r\n{\\exyear{GATE 2012}}\r\n\\begin{tasks}(1)\r\n\t\\task[\\textbf{A.}] The vectors $\\vec{a}$ and $\\vec{b}$ are linearly independent\r\n\t\\task[\\textbf{B.}] The vectors $\\vec{a}$ and $\\vec{b}$ are linearly dependent\r\n\t\\task[\\textbf{C.}] The vectors $\\vec{a}$ and $\\vec{b}$ are orthogonal\r\n\t\\task[\\textbf{D.}] The vectors $\\vec{a}$ and $\\vec{b}$ are normalized\r\n\\end{tasks}\r\n\t\\item If $\\vec{A}$ and $\\vec{B}$ are constant vectors, then $\\vec{\\nabla}(\\vec{A} \\cdot(\\vec{B} \\times \\vec{r}))$ is\r\n{\\exyear{GATE 2013}}\r\n\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\vec{A} \\cdot \\vec{B}$\r\n\t\\task[\\textbf{B.}] $\\vec{A} \\times \\vec{B}$\r\n\t\\task[\\textbf{C.}] $\\vec{r}$\r\n\t\\task[\\textbf{D.}]  Zero\r\n\\end{tasks}\r\n\\item The unit vector perpendicular to the surface $x^{2}+y^{2}+z^{2}=3$ at the point $(1,1,1)$ is\r\n{\\exyear{GATE 2014}}\r\n\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\frac{\\hat{x}+\\hat{y}-\\hat{z}}{\\sqrt{3}}$\r\n\t\\task[\\textbf{B.}] $\\frac{\\hat{x}-\\hat{y}-\\hat{z}}{\\sqrt{3}}$\r\n\t\\task[\\textbf{C.}] $\\frac{\\hat{x}-\\hat{y}+\\hat{z}}{\\sqrt{3}}$\r\n\t\\task[\\textbf{D.}] $\\frac{\\hat{x}+\\hat{y}+\\hat{z}}{\\sqrt{3}}$\r\n\\end{tasks}\r\n\t\\item The direction of $\\vec{\\nabla} f$ for a scalar field $f(x, y, z)=\\frac{1}{2} x^{2}-x y+\\frac{1}{2} z^{2}$ at the point $P(1,1,2)$ is\r\n{\\exyear{GATE 2016}}\r\n\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{A.}] $\\frac{(-\\hat{j}-2 \\hat{k})}{\\sqrt{5}}$\r\n\t\\task[\\textbf{B.}] $\\frac{(-\\hat{j}+2 \\hat{k})}{\\sqrt{5}}$\r\n\t\\task[\\textbf{C.}] $\\frac{(\\hat{j}-2 \\hat{k})}{\\sqrt{5}}$\r\n\t\\task[\\textbf{D.}] $\\frac{(\\hat{j}+2 \\hat{k})}{\\sqrt{5}}$\r\n\\end{tasks}\r\n\\question In spherical polar coordinates $(r, \\theta, \\phi)$, the unit vector $\\hat{\\theta}$ at $(10, \\pi / 4, \\pi / 2)$ is\r\n{\\exyear{GATE 2018}}\r\n\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{A.}] $\\hat{k}$\r\n\t\\task[\\textbf{B.}] $\\frac{1}{\\sqrt{2}}(\\hat{j}+\\hat{k})$\r\n\t\\task[\\textbf{C.}]  $\\frac{1}{\\sqrt{2}}(-\\hat{j}+\\hat{k})$\r\n\t\\task[\\textbf{D.}] $\\frac{1}{\\sqrt{2}}(\\hat{j}-\\hat{k})$\r\n\\end{tasks}\r\n\\item Given $\\vec{V}_{1}=\\hat{i}-\\hat{j}$ and $\\vec{V}_{2}=-2 \\hat{i}+3 \\hat{j}+2 \\hat{k}$, which one of the following $\\vec{V}_{3}$ makes $\\left(\\vec{V}_{1}, \\vec{V}_{2}, \\vec{V}_{3}\\right)$\r\na complete set for a three dimensional real linear vector space?\r\n{\\exyear{GATE 2018}}\r\n\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{A.}] $\\vec{V}_{3}=\\hat{i}+\\hat{j}+4 \\hat{k}$\r\n\t\\task[\\textbf{B.}]  $\\vec{V}_{3}=2 \\hat{i}-\\hat{j}+2 \\hat{k}$\r\n\t\\task[\\textbf{C.}] $\\vec{V}_{3}=\\hat{i}+2 \\hat{j}+6 \\hat{k}$\r\n\t\\task[\\textbf{D.}] $\\vec{V}_{3}=2 \\hat{i}+\\hat{j}+4 \\hat{k}$\r\n\\end{tasks}\r\n\\end{enumerate}\r\n\\colorlet{ocre1}{ocre!70!}\r\n\\colorlet{ocrel}{ocre!30!}\r\n\\setlength\\arrayrulewidth{1pt}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\arrayrulecolor{ocre}\r\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\r\n\t\t\\hline\r\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\r\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\r\n\t\t1&\\textbf{a} &2&\\textbf{d}\\\\\\hline \r\n\t\t3&\\textbf{b} &4&\\textbf{a} \\\\\\hline\r\n\t\t5&\\textbf{b} &6&\\textbf{d} \\\\\\hline\r\n\t\t7&\\textbf{b}&8&\\textbf{d}\\\\\\hline\r\n\t\t9&\\textbf{d}&10&\\textbf{}\\\\\\hline\r\n\t\t\r\n\t\t\r\n\t\\end{tabular}\r\n\\end{table}\r\n\r\n\\newpage\r\n\\begin{abox}\r\nProblem Set-3\t\r\n\\end{abox}\r\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\r\n\t\\item Three unit vectors $\\vec{a}, \\vec{b}, \\vec{c}\\left(\\vec{b}\\right.$ and $\\vec{c}$ are not parallel) are such that $\\vec{a} \\times(\\vec{b} \\times \\vec{c})=\\frac{\\sqrt{3}}{2} \\vec{c} .$ The\r\n\tangles which $\\vec{a}$ makes with $\\vec{b}$ and $\\vec{c},$ respectively are\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}]$30^{\\circ}, 90^{\\circ}$  \r\n\t\t\\task[\\textbf{b.}]$150^{\\circ}, 90^{\\circ}$\r\n\t\t\\task[\\textbf{c.}]$60^{\\circ}, 90^{\\circ}$ \r\n\t\t\\task[\\textbf{d.}]$90^{\\circ}, 30^{\\circ}$ \r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{flalign*}\r\n\t\t( \\vec{a} \\times(\\vec{b} \\times \\vec{c})=\\frac{\\sqrt{3}}{2} \\vec{c} &\\Rightarrow \\vec{b}(\\vec{a} \\cdot \\vec{c})-\\vec{c}(\\vec{a} \\cdot \\vec{b})=\\frac{\\sqrt{3}}{2} \\vec{c}\r\n\t\t\\intertext{Comparing coefficients of $\\vec{b}$ and $\\vec{c}$ on both sides.}\r\n\t\t\\vec{a} \\cdot \\vec{c}&=0 \\Rightarrow \\vec{a} \\perp \\vec{c}\\\\\r\n\t\t\\vec{a} \\cdot \\vec{b}&=\\frac{\\sqrt{3}}{2} \\\\\\Rightarrow a b \\cos \\theta&=-\\frac{\\sqrt{3}}{2}\\\\ \\Rightarrow \\cos \\theta&=-\\frac{\\sqrt{3}}{2} \\\\\\Rightarrow \\theta&=150^{\\circ}\r\n\t\t\\intertext{The angle which $ \\quad\\vec{a} $ makes with $ \\vec{b}  $ and $ \\vec{c} $  are $ 150^{\\circ} , 90^{\\circ}$ respectively.Correct option is (b)}\r\n\t\t\\end{flalign*}\r\n\t\\end{answer}\r\n\\item Find the angle between the two surfaces $5 x+y+z=1$ and $3 x+3 y+3 z=5$.\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\cos ^{-1}\\left(\\frac{7}{3}\\right)$   \r\n\t\\task[\\textbf{b.}]$\\cos ^{-1}\\left(\\frac{7}{9}\\right)$ \r\n\t\\task[\\textbf{c.}]$\\cos ^{-1}\\left(\\frac{7}{27}\\right)$ \r\n\t\\task[\\textbf{d.}]$\\cos ^{-1}\\left(\\frac{21}{9}\\right)$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\\begin{align*}\r\n\\text{Given}\\quad\\phi_{1}: 5 x+y+z=1 &\\quad\\text{and}\\quad\\phi_{2}: 3 x+3 y+3 z=5\\\\\r\n\\text{therefore,}\\\\\r\n\\cos \\theta&=\\frac{\\vec{\\nabla} \\phi_{1} \\cdot \\vec{\\nabla} \\phi_{2}}{\\left|\\vec{\\nabla} \\phi_{1}\\right|\\left|\\vec{\\nabla} \\phi_{2}\\right|}\\\\&=\\frac{(5 \\hat{i}+\\hat{j}+\\hat{k}) \\cdot(3 \\hat{i}+3 \\hat{j}+3 \\hat{k})}{\\sqrt{27} \\cdot \\sqrt{27}}\\\\&=\\frac{21}{27} \\\\\\Rightarrow \\theta&=\\cos ^{-1}\\left(\\frac{7}{9}\\right)\r\n\\end{align*}\r\n\\end{answer}\r\n\\item The equation of the plane that is tangent to the surface $x y z=8$ at the point (1,2,4) is\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$x+2 y+4 z=12$  \r\n\t\\task[\\textbf{b.}]$4 x+2 y+z=12$\r\n\t\\task[\\textbf{c.}]$x+4 y+2=0$ \r\n\t\\task[\\textbf{d.}]$x+y+z=7$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\\text{To get a normal at the surface let's take the gradient}\\\\\r\n\t\t\\vec{\\nabla}(x y z)&=y z \\hat{i}+z x \\hat{j}+\\hat{k} x y\\\\&=8 \\hat{i}+4 \\hat{j}+2 \\hat{k}\\\\\r\n\t\t\\text{We want a plane perpendicular to this so:}\\\\\r\n\t\t\\left(\\vec{r}-\\vec{r}_{0}\\right) \\cdot \\frac{(8 \\hat{i}+4 \\hat{j}+2 \\hat{k})}{\\sqrt{64+16+4}}&=0\\\\\r\n\t\t|(x-1) \\hat{i}+(y-2) \\hat{j}+(z-4) \\hat{k}| \\cdot[8 \\hat{i}+4 \\hat{j}+2 \\hat{k}]&=0\\\\ \\Rightarrow 4 x+2 y+z&=12\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\\item If $\\vec{A}=\\hat{i} y z+\\hat{j} x z+\\hat{k} x y$, then the integral $\\oint_{C} \\vec{A} \\cdot d \\vec{l}$ (where $C$ is along the perimeter of a rectangular\r\narea bounded by $x=0, x=a$ and $y=0, y=b)$ is\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{a.}]$\\frac{1}{2}\\left(a^{3}+b^{3}\\right)$  \r\n\t\\task[\\textbf{b.}]$\\pi\\left(a b^{2}+a^{2} b\\right)$\r\n\t\\task[\\textbf{c.}]$\\pi\\left(a^{3}+b^{3}\\right)$ \r\n\t\\task[\\textbf{d.}]0 \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\\oint_{C} \\vec{A} \\cdot d \\vec{l}&=\\int_{S}(\\vec{\\nabla} \\times \\vec{A}) d \\vec{a}=0 \\\\\r\n\t\\because \\vec{\\nabla} \\times \\vec{A}&=0\r\n\t\\end{align*}\r\n\r\n\\end{answer}\r\n\\item Value of the integral $\\oint\\left(x y d y-y^{2} d x\\right)$, where $c$ is\r\nthe square cut from the quadrant by the lines $x=1$ and $y=1$ will be (use Green's theorem to change the line integral into double integral)\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{a.}] $\\frac{1}{2}$ \r\n\t\\task[\\textbf{b.}]1\r\n\t\\task[\\textbf{c.}]$\\frac{3}{2}$ \r\n\t\\task[\\textbf{d.}]$\\frac{5}{3}$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n \\intertext{We know that Green's theorem is given by}\\oint_{c} \\phi d x+\\psi d y&=\\iint_{R}\\left(\\frac{\\partial \\psi}{\\partial x}-\\frac{\\partial \\phi}{\\partial y}\\right) d x d y\\\\\r\n \\text{Here,}I&=\\oint\\left(x y d y-y^{2} d x\\right)\\\\&=\\oint\\left(-y^{2}\\right) d x+(x y) d y\r\n \\intertext{Hence, we can deduce}\\phi &=-y^{2} \\\\\r\n \\psi &=x y \\\\\r\n \\frac{\\partial \\psi}{\\partial x} &=y \\\\\r\n \\frac{\\partial \\phi}{\\partial y} &=-2 y\r\n \\intertext{Substituting in Green's theorem, we get}\r\n I &=\\int_{y=0}^{1} \\int_{x=0}^{1}[y-(-2 y)] d x d y=\\int_{y=0}^{1} \\int_{x=0}^{1} 3 y d x d y \\\\\r\n &=\\int_{y=0}^{1}[3 x y]_{x=0}^{1} d y=\\int_{y=0}^{1} 3 y d y \\\\\r\n &=\\frac{3}{2}\r\n\\end{align*}\r\nThus the correct option is (c).\r\n\\end{answer}\r\n\\item  Evaluate $\\int_{C} \\vec{F} \\cdot \\overrightarrow{d r},$ where $F=x^{2} \\hat{i}+y^{3} \\hat{j}$ and curve $C$ is the arc of parabola $y=x^{2}$ in the $x-y$\r\nplane from (0,0) to (1,1) \r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\frac{7}{12}$  \r\n\t\\task[\\textbf{b.}]$\\frac{7}{12}$ \r\n\t\\task[\\textbf{c.}]$\\frac{7}{12}$  \r\n\t\\task[\\textbf{d.}]$\\frac{7}{12}$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\\text{Along the curve C,}\r\n\ty=x^{2} \\Rightarrow d y=2 x d x ;\\\\\r\n\t\\vec{r}&=x \\hat{i}+x^{2} \\hat{j} \\Rightarrow d \\vec{r}=d x \\hat{i}+2 x d \\hat{x} j\\\\\r\n\t\\text { Therefore, } \\int_{C} \\vec{F} \\cdot d \\vec{r}&=\\int_{x=0}^{1}\\left[x^{2} d x+x^{6}(2 x) d x\\right] \\\\\r\n\t&=\\int_{0}^{1}\\left(x^{2}+2 x^{7}\\right) d x=\\left[\\frac{x^{3}}{3}+\\frac{2 x^{8}}{8}\\right]_{0}^{1}\\\\&=\\frac{7}{12}\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\\item At any point of the curve $x=3 \\cos t, y=3 \\sin t, z=4 t,$ find\r\nThe unit tangent vector \r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\frac{1}{\\sqrt 10}(-3 \\sin t \\hat{i}+3 \\cos t \\hat{j}+4 \\hat{k})$   \r\n\t\\task[\\textbf{b.}]$\\frac{1}{10}(-3 \\sin t \\hat{i}+3 \\cos t \\hat{j}+4 \\hat{k})$ \r\n\t\\task[\\textbf{c.}]$\\frac{1}{5}(-3 \\sin t \\hat{i}+3 \\cos t \\hat{j}+4 \\hat{k})$ \r\n\t\\task[\\textbf{d.}]$\\frac{1}{5(\\sin t+\\cos t)}(-3 \\sin t \\hat{i}+3 \\cos t \\hat{j}+4 \\hat{k})$  \r\n\\end{tasks}\r\n\\begin{answer}\r\n\\begin{align*}\r\n\t\\quad\\vec{r} &=x \\hat{i}+y \\hat{j}+z \\hat{k} \\Rightarrow \\vec{r}=(3 \\cos t) \\hat{i}+(3 \\sin t) \\hat{j}+(4 t) \\hat{k} \\\\\r\n\t\\frac{d \\vec{r}}{d t} &=(-3 \\sin t) \\hat{i}+(3 \\cos t) \\hat{j}+4 \\hat{k}\\quad\r\n\t\\text{which is the required tangent vector.} \\intertext{Magnitude of tangent vector} &=\\sqrt{(-3 \\sin t)^{2}+(3 \\cos t)^{2}+(4)^{2}}=5\r\n\t\\intertext{Unit tangent vector}&=\\frac{1}{5}(-3 \\sin t \\hat{i}+3 \\cos t \\hat{j}+4 \\hat{k})\r\n\\end{align*}\r\n\\end{answer}\r\n\\item The unit normal vector of the point $\\left[\\frac{a}{\\sqrt{3}}, \\frac{b}{\\sqrt{3}}, \\frac{c}{\\sqrt{3}}\\right]$ on the surface of the ellipsoid\r\n$\\frac{x^{2}}{a^{2}}+\\frac{y^{2}}{b^{2}}+\\frac{z^{2}}{c^{2}}=1$ is\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\frac{b c \\hat{i}+c a \\hat{j}+a b \\hat{k}}{\\sqrt{b^{2} c^{2}+c^{2} a^{2}+a^{2} b^{2}}}$  \r\n\t\\task[\\textbf{b.}]$\\frac{a \\hat{i}+b \\hat{j}+c \\hat{k}}{\\sqrt{a^{2}+b^{2}+c^{2}}}$\r\n\t\\task[\\textbf{c.}]$\\frac{b \\hat{i}+c \\hat{j}+a \\hat{k}}{\\sqrt{a^{2}+b^{2}+c^{2}}}$ \r\n\t\\task[\\textbf{d.}]$\\frac{\\hat{i}+\\hat{j}+\\hat{k}}{\\sqrt{3}}$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\\text{Here,}\\phi&=\\frac{x^{2}}{a^{2}}+\\frac{y^{2}}{b^{2}}+\\frac{z^{2}}{c^{2}}-1\\\\\r\n\t\\text{Unit normal vector is}\\frac{\\vec{\\nabla} \\phi}{|\\vec{\\nabla} \\phi|}\\\\\r\n\t\\text{So}\\vec{\\nabla} \\phi&=\\left(i \\frac{\\partial}{\\partial x}+\\hat{j} \\frac{\\partial}{\\partial y}+\\hat{k} \\frac{\\partial}{\\partial z}\\right) \\cdot\\left(\\frac{x^{2}}{a^{2}}+\\frac{y^{2}}{b^{2}}+\\frac{z^{2}}{c^{2}}-1\\right)\\\\&=\\frac{2 x \\hat{i}}{a^{2}}+\\frac{2 y \\hat{j}}{b^{2}}+\\frac{2 z \\hat{k}}{c^{2}}\\\\\r\n\t\\left.\\vec{\\nabla} \\phi\\right|_{\\left(\\frac{a}{\\sqrt{3}}, \\frac{b}{\\sqrt{3}}, \\frac{c}{\\sqrt{3}}\\right)}&=\\frac{2}{a \\sqrt{3}} \\hat{i}+\\frac{2}{b \\sqrt{3}} \\hat{j}+\\frac{2}{c \\sqrt{3}} \\hat{k}\\\\\r\n\t|\\vec{\\nabla} \\phi|&=\\sqrt{\\frac{4}{3 a^{2}}+\\frac{4}{3 b^{2}}+\\frac{4}{3 c^{2}}}\\\\&=\\frac{2}{\\sqrt{3}} \\sqrt{\\frac{b^{2} c^{2}+a^{2} c^{2}+a^{2} c^{2}}{a^{2} b^{2} c^{2}}}\\\\\r\n\t\\left.\\frac{\\vec{\\nabla} \\phi}{|\\vec{\\nabla} \\phi|}\\right|_{\\left(\\frac{a}{\\sqrt{3}}, \\frac{b}{\\sqrt{3}}, \\frac{c}{\\sqrt{3}}\\right)}&=\\frac{\\frac{2}{a \\sqrt{3}} \\hat{i}+\\frac{2}{b \\sqrt{3}} \\hat{j}+\\frac{2}{c \\sqrt{3}} \\hat{k}}{\\frac{2}{\\sqrt{3}} \\frac{\\sqrt{b^{2} c^{2}+c^{2} a^{2}+a^{2} b^{2}}}{a b c}}\\\\&=\\frac{b c \\hat{i}+c a \\hat{j}+a b \\hat{k}}{\\sqrt{b^{2} c^{2}+c^{2} a^{2}+a^{2} b^{2}}}\r\n\t\\end{align*}\r\nThe correct option is (a)\r\n\\end{answer}\r\n\\item For the vector field $\\vec{A}=x z^{2} \\hat{i}-y z^{2} \\hat{j}+z\\left(x^{2}-y^{2}\\right) \\hat{k},$ the volume integral of the divergence of $\\vec{A}$\r\nout of the region defined by $-a \\leq x \\leq a,-b \\leq y \\leq b$ and $0 \\leq z \\leq c$\r\nis:\r\n\\begin{tasks}(2)\r\n\t\\task[\\textbf{a.}]$\\frac{4}{3} a b c\\left[a^{2}-b^{2}\\right]$  \r\n\t\\task[\\textbf{b.}] $\\frac{2}{3} a b c\\left[a^{2}-b^{2}\\right]$\r\n\t\\task[\\textbf{c.}]$\\frac{1}{3} a b c\\left[a^{2}-b^{2}\\right]$ \r\n\t\\task[\\textbf{d.}]$a b c\\left[a^{2}-b^{2}\\right]$ \r\n\\end{tasks}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\\text{Since,} \\vec{A}&=x z^{2} \\hat{i}-y z^{2} \\hat{j}+z\\left(x^{2}-y^{2}\\right) \\hat{k} \\Rightarrow \\vec{\\nabla} \\cdot \\vec{A}=z^{2}-z^{2}+\\left(x^{2}-y^{2}\\right)=x^{2}-y^{2}\\\\\r\n\t\\text{Thus,}\\int_{V}(\\vec{\\nabla} \\cdot \\vec{A}) d \\tau\\\\&=\\int_{x=-a}^{x=+a} \\int_{y=-b}^{y=+b} \\int_{z=0}^{z=c}\\left(x^{2}-y^{2}\\right) d x d y d z\\\\&=\\int_{y=-b}^{y=+b} \\int_{z=0}^{z=c}\\left[\\frac{x^{3}}{3}-y^{2} x\\right]_{-a}^{+a} d y d z\\\\&=\\int_{y=-b}^{y=+b} \\int_{z=0}^{z=c}\\left[\\frac{2}{3} a^{3}-2 a y^{2}\\right] d y d z\\\\\r\n\t\\Rightarrow \\int_{V}(\\vec{\\nabla} \\cdot \\vec{A}) d \\tau&=\\int_{z=0}^{z=c}\\left[\\frac{2}{3} a^{3} y-2 a \\frac{y^{3}}{3}\\right]_{-b}^{+b} d z=\\int_{z=0}^{z=c}\\left[\\frac{4}{3} a^{3} b-\\frac{4}{3} a b^{3}\\right] d z\\\\&=\\frac{4}{3} a b c\\left[a^{2}-b^{2}\\right]\r\n\t\\end{align*}\r\n Correct option is (a)\r\n\\end{answer}\r\n\\item The value of $\\oint \\vec{F} \\cdot d \\vec{r},$ where $C$ is the curve bounded by $x^{2}+y^{2} \\geq 4 ; x^{2}+y^{2} \\leq 16 ; x \\geq 0$\r\nand $\\vec{F}=-y \\hat{i}+x \\hat{j}+z \\hat{k}$ is ....\r\n\\begin{tasks}(4)\r\n\t\\task[\\textbf{a.}]$ 12\\pi$ \r\n\t\\task[\\textbf{b.}]$ 24 \\pi$ \r\n\t\\task[\\textbf{c.}]$ \\frac{14 \\pi}{3}$  \r\n\t\\task[\\textbf{d.}]$ \\frac{10 \\pi}{3}$  \r\n\\end{tasks}\r\n\\begin{answer}\r\n\\begin{align*}\r\n\\intertext{Using Stoke's theorem,}\\int_{C} \\vec{F} \\cdot d \\vec{r}&=\\iint_{S}(\\vec{\\nabla} \\times \\vec{F}) \\cdot d \\vec{S}\\\\\r\n\\int_{C} \\vec{F} \\cdot d \\vec{r}&=\\iint_{S}(\\vec{\\nabla} \\times \\vec{F}) \\cdot d \\vec{S}\\\\\r\n\\vec{\\nabla} \\times \\vec{F}&=\\left|\\begin{array}{ccc}\r\n\\hat{i} & \\hat{j} & \\hat{k} \\\\\r\n\\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\\r\n-y & x & z\r\n\\end{array}\\right|=\\hat{i}(0-0)-\\hat{j}(0-0)+\\hat{k}(1+1)=2 \\hat{k}\\end{align*}\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[height=3.5cm,width=4cm]{pset 3-10}\r\n\\end{figure}\r\n\\begin{align*}\r\n\\text { And } d \\vec{S}&=d x d y \\hat{k}\\\\\r\n\\therefore \\quad \\iint_{S}(\\vec{\\nabla} \\times \\vec{F}) \\cdot d \\vec{S}&=2 \\iint d x d y\\\\\r\n\\intertext { Put, $ x=r \\cos \\theta, y=r \\sin \\theta $  and  $ d x d y=r d r d \\theta $}\r\n&=2 \\int_{\\theta=-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} \\int_{r=2}^{4} r d r d \\theta\\\\&=2\\left(\\frac{r^{2}}{2}\\right)_{2}^{4}( \\pi)= \\pi \\times 12=12 \\pi\r\n\\end{align*}\t\r\n\\end{answer}\r\n\r\n\\end{enumerate}\r\n\r\n\r\n", "meta": {"hexsha": "be5b9e54ea675a8abdd535ac9a668085beb92425", "size": 70496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/vector.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/vector.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/vector.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": 57.4071661238, "max_line_length": 807, "alphanum_fraction": 0.6102473899, "num_tokens": 27680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385542, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6546253535975999}}
{"text": "\\lab{Algorithms}{Multi-Armed Bandit Problems}{Multi-Armed Bandit Problems}\n\\objective{This lesson explains Markov decision processes and \nspecifically multi-armed bandit problems and how to solve them by \nThompson Sampling.}\n\n\\section*{Markov Decision Processes}\nPreviously we considered what we called dynamic programming problems.  \nThese problems involved making sequential decisions in some optimal way, \npossibly under uncertainty.  Dynamic programming problems are closely \nrelated to a class of problems called Markov Decision Processes.\n\nA Markov Decision Process (MDP) involves the following elements\n\n\\begin{itemize}\n\\item   A set of decision times\n\\item   A set of states\n\\item   A set of actions\n\\item   A set of rewards dependent on the state and action\n\\item   Transition probabilities dependent on states and actions.\n\\end{itemize}\nFor our purposes we will consider discrete time problems so that our \nset of decision times is $t = 1,2,3,\\ldots$.  \nIn the dynamic programming problems considered in the previous labs, \nthe set of states was the set of all possible levels of wealth and \nthe actions were how much wealth to save for the next period.  \nThe rewards were given by the utility function $u(\\cdot)$, \nand we considered both deterministic and stochastic transitions.\n\n\\section*{Bandit Problems}\nIn particular, we will consider what is called the multi-armed bandit \nproblem.  The name comes from the following example.  \nSuppose there is a row of $N$ slot machines (``one-armed bandits\") \nthat each pays out with probability $p_i$, $i= 1,2,\\ldots,N$, \nwhere the probabilities are unknown to the gambler.  \nThe gambler seeks to determine the sequence of levers to pull in \norder to maximize their winnings.\n\nBandit problems have a wide range of applications.  \nOne can consider the ``arms\" to be the different treatments in a \nclinical trial, the different forms of advertising a product, \nor the different research projects a company might invest in.\n\nWe now formulate the multi-armed bandit problem.  \nFor simplicity we suppose there are $2$ arms, though the \ndiscussion is easily extended to $N$ arms.  \nAt each time $t= 1,2,\\ldots$ one arm can be pulled.  \nWith unknown probability $p_i$, the $i$th arm gives \nreward $1$ and with probability $1-p_i$ it gives reward $0$.  \nNote we have now defined a set of decision times, actions, and rewards. \nWe define the state to be the number of successful and unsuccessful \npulls on each arm written\n\\begin{equation}\\label{state}\nR(a_1,b_1,a_2,b_2)\n\\end{equation}\nwhere $a_i$ is the number of successful pulls on arm $i$ and $b_i$ \nis the number of unsuccessful pulls on arm $i$.\nAs we pull the arms, we must balance between pulling the arm that has \nthe highest expected payoff and pulling all arms in order to gain \ninformation about the probabilities $p_i$.  \nThis trade-off is often referred to as exploring versus exploiting.  \nIn essence, while gaining rewards, we will also come up with \nestimates of the $p_i$ that improve our decision making.  \nWe will do so by Bayesian Updating.\n\n\\section*{Bayesian Updating}\nWhile a full exposition of Bayesian inference is well beyond the \nscope of this lab, the essential concepts are fairly straightforward.  \nWe recognize that we do not know the values of the $p_i$, \nbut given our past history of successful and unsuccessful \npulls we can say something about what range we think they might be in. \nThis is different than guessing a specific value for the $p_i$.\nFor example the value of $p_i$ might be represented by a curve \nlike those seen in Figure \\ref{fig:priors}.\n\\begin{figure}\n\n\\centering\n\\includegraphics[width=\\textwidth]{priors.pdf}\n\\caption{Bayesian priors}\n\\label{fig:priors}\n\\end{figure}\nThe curves are thought of as probability distributions.  \nSo if you have had $1$ success and $2$ failures, you might \nthink that $p_i$ is around $\\frac{1}{3} = \\frac{1}{1+2}$. \nHowever, you have very little information at this point, \nso better yet you might represent your belief about $p_i$ \nby the blue probability distribution in Figure \\ref{fig:priors}.  \nWe call the distribution that describes our belief about $p_i$ \nthe prior distribution of $p_i$.  If we incorporate new information, \nwe get a new distribution called the posterior distribution.  \nThe posterior distribution can also be thought of as a new prior \ndistribution as we continue to collect information.\n\nAs we get more information, the curve gets narrower.  \nIn the figure, we see that the distributions have expected \nvalue of $1/3$ and become tighter around that value.  \nThis is fitting since the parameter values have success $\\alpha$ one \nthird of the time and the tighter distributions correspond to having \nmore prior information.  If we need an estimate for $p_i$ we can use \nthe expected value of our distribution corresponding to $p_i$.  \nWe will denote this estimate by $\\overline{p_i}$.\n\nIn this manner we approach the multi-armed bandit problem.  \nWe do not know the $p_i$ but each time we pull an arm, we update our distribution of where we think it might be.  \nIn particular we use a beta distribution to represent our opinion on what the $p_i$ are.  \nA beta distribution is a continuous probability distribution on the interval $[0,1]$, \nwhich corresponds nicely to the possible values of the $p_i$.  Beta distributions have two parameters $a,b$.  \nSo in our problem the state \\eqref{state} can be thought of as representing two beta distributions -- one for each $p_i$. \nThe details of the updating process are unimportant for now, except \nfor this important property: the two parameters $a,b$ correspond exactly with successes and failures.  \nSo if we start with a distribution Beta$(a,b)$ and the next pull is success, our new distribution is \nBeta$(a+1,b)$ and if the next pull is a failure then the new distribution is Beta$(a,b+1)$.  \nNotice this corresponds with the way our states evolve.\n\n\\section*{Simulation and Sampling in a Bayesian Framework}\nAlong with the estimate $\\overline{p_i}$, we can also compute many other useful \nquantities in our Bayesian problem via random sampling.  Essentially, we can take \nrandom draws from our prior distribution and estimate the mean, median, or other \nquantities based on the value of those quantities in the random sample.  \nThis is a very powerful concept that will be explored in more detail in future labs.\n\n\\begin{problem}\nWrite a function \\li{sim\\_data} that accepts an $n\\times 2$ array, where each \nrow represents the parameters of a beta distribution, and a positive integer $k$ \nthat represents the number of random draws to return.  \nThe function should return a $k\\times n$ matrix where each row has a random sample\nfrom each of the $n$ arms.  This can be accomplished with ease using the SciPy function\n\\li{scipy.random.beta}.\n\\label{prob:simdata}\n\\end{problem}\n\n\\begin{problem}\nSuppose one of the arms in a bandit problem has the state (or prior distribution of $p_i$) \n$Beta(100,200)$ corresponding to $100$ successes and $200$ failures.  \nSimulate 10,000 data points for the distribution $Beta(100,200)$.  \nCompute $\\overline{p_i}$ by finding the mean of the simulated points. \nCompute the median.  Also compute the $95$th percentile using the command \n\\li{scipy.stats.mstats.mquantiles(data, .95)} where ``data'' is the array \ncontaining the 10,000 simulated data points.\n\\end{problem}\n\n\\section*{Direct Dynamic Programming Solution}\nThis framework lends itself well to a dynamic programming type solutions.  \nRather than just letting $R(a_1,b_1,a_2,b_2)$ represent the state, consider \nit as the value function, meaning the optimal expected value that can be achieved \nstarting from this state.  Then we have\n\\begin{equation}\n\\label{recurs}\n\\begin{aligned}\nR(a_1,b_1,&a_2,b_2) =\\\\\n \\max&\\left\\{\\overline{p}_1\\cdot[1 + \\beta R(a_1+1,b_1,a_2,b_2)] + (1-\\overline{p}_1)\\beta R(a_1,b_1+1,a_2,b_2)\\right. ,\\\\\n&  \\left.\\overline{p}_2\\cdot[1 + \\beta R(a_1,b_1,a_2+1,b_2)] + (1-\\overline{p}_2)\\beta R(a_1,b_1,a_2,b_2+1)\\right\\}\n\\end{aligned}\n\\end{equation}\nThe two terms in the maximization represent the expected value of pulling lever \none or lever two respectively.  For example, if lever one is pulled it is expected \nto yield a reward of 1 with probability $\\overline{p_1}$.  \nWe must also account for the expected value of future rewards \n(discounted by $\\beta$) moving to a state with one more success on arm 1.  \nWith probability $1-\\overline{p_1}$, lever one does not give a reward and so \nrewards are simply the discounted expected reward starting in the next state.\n\nNotice that the expressions inside of $R(\\cdot)$ on the right side have parameter \nvalues that add to one greater than the $R(\\cdot)$ on the left side.  \nSo for example if we want to compute $R(1,1,1,1)$ we need to know \n$R(2,1,1,1)$, $R(1,2,1,1)$, $R(1,1,2,1)$ and $R(1,1,1,2)$ \n(all possible combinations of parameters that add up to 5).  \nTo compute these, we need to know the reward corresponding to all possible \ncombinations of parameters that add up to 6, and so on.  Consequently, we could \nmake a guess for all $R$ for all parameter combinations that add up to some large $N$, \nthen work backward until we get to $R(1,1,1,1)$.  This is backward induction, \njust as we saw in dynamic programming.  However, the number of computations in this \nproblem grow much too quickly because of the branching nature of having multiple arms.  \nIn fact, if there are more than two arms this method of computation is infeasible!\n\n\n\\begin{comment}\n\\section*{Gittins Index Solution}\nOne way we might hope to solve a bandit problem is by computing some sort of ``index'' \nfor each arm.  That is, we want a number associated with each arm that in some sense \ncaptures the value of pulling that arm.   Ideally such an index would depend only on that arm, \nand not on the others.  We could then compare the indices for all of the arms \nand pull the arm with highest index.  It turns out that bandit problems can be \nsolved optimally by such methods and are computationally more feasible than the \ndynamic programming approach we saw above.\n\nTo compute an index for this problem, we consider comparing an arm with unknown \npayoff probability $p_i$ to an arm with known payoff probability $p$.  Then equation \\eqref{recurs} becomes\n\\begin{equation}\\label{index}\n\\begin{aligned}\nR(p,a_i,b_i) = \\max&\\left\\{\\frac{p}{1-\\beta} \\right. ,\\\\\n&  \\left.\\hat{p}_i\\cdot[1 + \\beta R(p,a_i+1,b_i)] + (1-\\hat{p}_i)\\beta R(p, a_i,b_i+1)\\right\\}.\\\\\n\\end{aligned}\n\\end{equation}\n\nWe determine the expected value of pulling the first arm to be $\\frac{p}{1-\\beta}$ \nnoting that if we pull the deterministic arm once, we will continue pulling it \nforever as we gain no new information.  In this case the expected reward from pulling \nthe known arm is $p + \\beta p + \\beta^2 p + \\cdots = \\frac{p}{1-\\beta}$.\n\n\nIf we can find the $p$ such that we are indifferent between the deterministic \narm and the unknown arm, this will give us an index that quantifies the value of arm $p_i$ (this can be proved).\n\nPutting all of this together, our algorithm for solving the multi-armed bandit \nproblem with two arms is as follows.  For each arm $i$, compute \\eqref{recurs} \nover a range of $p$ values to find the $p$ such that you would be indifferent \nbetween the arm with probability $p$ and arm $i$. Store this as the index $\\lambda_i$.  \nCompare the $\\lambda_i$ and pull the arm with largest index.\n\nIn order to compute \\eqref{index} we use dynamic programming, starting with a guess\nfor $R$ for parameters that add up to some large $N$ and use backward induction. \nIn the process, we find $R$ and $\\lambda_i$ for each combination of parameters \nthat adds up to any $n\\leq N$. Thus we do not have to compute new $\\lambda_i$ after\neach pull, we can just look them up.\n\n\\section*{Algorithm Outline}\nThis section will guide you through creating a function that will compute the indices \nfor a given arm.  It will involve writing a number of functions that you can save in the same .py file.\n\nFirst, we need a function that will compute all the pairs of $a,b$ that add up \nto some $N$.  We also want the user to be able to input the minimum values of \n$a$ and $b$ of interest to avoid unnecessary computation.  For example if in practice \nall of the arms have $a_i \\geq 5$ and $b_i \\geq 10$, then we are uninterested in smaller $a$, $b$.  \nThe following code accepts the value of $N$ and a minimum value of a and b and \nreturns an $N$ by 2 array with the $a$'s and $b$'s such that $a + b = N$.\n\\begin{lstlisting}\n# computes pairs of numbers starting with mina and minb that\n# add up to N\n\ndef compute_indices(N,mina,minb):\n    import scipy as sp\n    avec = sp.arange(mina,N-minb+1)\n    avec = sp.reshape(avec,(avec.shape[0],1))\n    bvec  = sp.arange(N-mina, minb-1,-1)\n    bvec = sp.reshape(bvec,(bvec.shape[0],1))\n    values = sp.hstack((avec,bvec))\n\n    return values\n\\end{lstlisting}\n\nIn order to perform the backward induction, we need to be able to estimate the value \n$R(p,a,b)$ for $a+b = N$.  To do so we have to estimate the second quantity in \\eqref{index}.  \nWe will estimate it as $(\\frac{a}{a+b})/(1-\\beta)$.  This is the value one would get by \npulling an arm with $p_i$ equal to the expected value of $Beta(a,b)$ forever.\n\\begin{problem}\nWrite a function ``end\\_reward\" that accepts $p,a,b,$ and $\\beta$ and returns the \nestimated value of $R(p,a,b)$ for $a,b$ such that $a+b=N$.\n\\end{problem}\n\nFor convenience it will be nice to have a function that will compute $R(p,a,b)$ \ngiven values of $p,\\overline{p},a,b,\\beta,N$ as well as values of $R(p,a+1,b)$ and $R(p,a,b+1)$.\nThis should follow directly from \\eqref{index}.\n\\end{comment}\n\n\\section*{Thompson Sampling}\nThere is a method for computing the optimal solution to the multi-armed bandit problem \nbased on what is commonly known as the Gittins Index Theorem.  \nComputationally it is similar to the dynamic programming approach, but it is significantly less costly.  \nUnfortunately, for large scale problems, it can still be too costly.\n\nThere are, however, many heuristic methods of solving the multi-armed bandit problem.\nIn particular we will use a method known as Thompson Sampling, or Randomized Probability Matching.\nThe idea is that we should choose arm $i$ with probability equal to the probability \nthat arm $i$ is the best arm.  So if we believe there is an $80\\%$ probability that \narm 2 is the best arm we will pull it $80\\%$ of the time.  The other $20\\%$ of the \ntime we would pull arm one which will help give more information about the true value of $p_1$.  \nIn this way, we will pull most often the arms from which we expect the most rewards; \nhowever, we will also pull other arms with some probability so that we accomplish some \nexploration and gain information on all arms until we are confident we have found the best arm.\n\n\\begin{problem}\nWrite a function that accepts a $k \\times n$ array of data computed by the function from Problem \\ref{prob:simdata}.\n\nThis function should return a vector of the probabilities that each of the $n$ arms is optimal.  \nThis can be computed for each arm by determining in how many of the $k$ simulations \nthat arm had the highest value.  Dividing this number by $k$ will give the proportion \nof the simulations for which this arm had the greatest probability of success.  \nThis proportion is interpreted as the probability that the arm is the optimal arm.\n\\end{problem}\n\nIn some applications, we might want to run computations once, then pull many arms instead \nof computing before each pull.  In these cases, rather than compute these probabilities, \nchoose an arm, then recompute, it can be more convenient to view the probabilities as weights.  \nFor example we can view the probabilities as the weights of how to distribute the next 100 pulls.  \nSuppose the probabilities resulting from the previous function (with two arms) are $0.4$ and $0.6$.\nThen we would allot 40 of the next 100 pulls to arm 1 and 60 of the next 100 pulls to arm 2.  \nThen we could compute new weights for the next 100 pulls.\n\n\\begin{problem}\nUsing the results from the previous problems, write a function that determines how many \ntimes each arm should be pulled in the next $M$ pulls where $M$ is an input to the function. \nThe function should accept a vector of probabilities that of the form returned by the \nfunction in the previous problem, and a number of pulls $M$. \nNote that you will have to round since the number of pulls for each arm must be in integer.\nReturn a vector of length $n$ (where $n$ is the number of arms) that gives the number of\npulls out of the next $M$ for each arm.  Make sure the entries sum to $M$.\n\\end{problem}\n\nYou now have code that solves the version of the multi-armed bandit problem described here. \nTo solve such a problem you would first start all arms with the state (or prior) $Beta(1,1)$,\nwhich is the uniform distribution, meaning we have no information on the $p_i$.\nThen we can compute the weights for the next $M$ pulls. \nAfter those $M$ pulls we can compute new weights and continue on in this pattern. \nIn some applications we may not continue this forever, but might instead have some stopping\ncriteria for when we think we have identified the best arm. \nA common stopping criteria would be to stop when one of the arms has a $95\\%$ probability\n(or some other specified probability) of being the optimal arm. \nIn the framework we have set up, this is already computed at each step and, thus, easy to check for.\n\nIn the following applications lab, we will investigate how this process can be applied \nin web page testing and simulate a bandit problem using the functions in this lab. \n", "meta": {"hexsha": "3fda2b40a0c84bff01c6ea0be95429aa8e9755f8", "size": 17641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/MarkDecProc/Bandits.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/MarkDecProc/Bandits.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/MarkDecProc/Bandits.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": 56.5416666667, "max_line_length": 122, "alphanum_fraction": 0.7575534267, "num_tokens": 4484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6546253425912206}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{enumitem}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1em}\n\n\\begin{document}\n\n\\section{Cauchy-(Bunyakovsky)-Schwarz inequality}\nFor $a_1, \\dots , a_n, b_1, \\dots , b_n \\in \\mathcal{R}$\n\n$$\\left(\\sum_{i=1}^{n} a_i b_i\\right)^2 \\leq \\sum_{i=1}^{n} a_i^2 \\sum_{i=1}^{n} b_i^2 $$\n\n\\begin{enumerate}\n\t\\item\n\tProve Cauchy-Schwarz inequality. When does the equality hold?\n\t\n\t\\item\n\tProve that\n\t$$\n\t\\left(\\sum _{i=1}^{n}a_{i}^{2}\\right) \\left(\\sum _{i=1}^{n}b_{i}^{2}\\right)-\n\t\\left( \\sum ^{n}_{i=1}a_{i}b_{i}\\right) ^{2}=\n\t\\sum_{i< j}(a_ib_j-a_jb_i)^2.\n\t$$\n\n\t\n\t\\item % BW 1992 13\n\tProve that for positive real numbers $a_1,\\dots,a_n,b_1,\\dots,b_n$\n\t$$\\left(\\sum_{i=1}^{n} \\frac{1}{x_iy_i}\\right)\\left(\\sum_{i=1}^{n}(x_i+y_i)^2\\right)\n\t\\geq\n\t4n^2\n\t$$\n\t\n\t\n\t\\item % BW 2008 \n\tProve that if the real numbers $a$, $b$ and $c$ satisfy $a^2+b^2+c^2=3$ then\n\t$$\\frac{a^2}{2+b+c^2}+\\frac{b^2}{2+c+a^2}+\\frac{c^2}{2+a+b^2}\n\t\\ge\\frac{(a+b+c)^2}{12}\\,.\n\t$$\n\t\n\t\\item % Canada 2002\n\t\n\tProve that for all positive real numbers $a, b, c$\n\t$$\\frac{a^3}{bc} + \\frac{b^3}{ac} + \\frac{c^3}{ab}  \\geq a+b+c $$\n\tand determine when equality occurs\n\n\n\t\\item % http://www.math.olympiaadid.ut.ee/latex/imo/Jan_IMO/algebra/87_3.TEX\n\tGiven real numbers $x_1,\\dots,x_n$ for which $\\sum_{i=1}^{n} x_i^2 =1$. Prove that for each integer $k \\geq 2$ we can find integers $a_1,\\dots,a_n$ from which at least one is non-zero and for which $|a_i| \\leq k-1$ and \n\t$$|a_1x_1 + a_2x_2 + \\ldots + a_nx_n| \\leq {{(k-1)\\sqrt n}\\over{k^n -1}}.$$\n\t\n\t\\item %https://artofproblemsolving.com/wiki/index.php?title=2002\\_USAMO\\_Problems/Problem\\_2\n\tLet $ABC$ be a triangle such that \n\t$$\\cot^2 \\frac{A}{2} + 2^2\\cot^2 \\frac{B}{2} +3^2\\cot^2 \\frac{C}{2}=\\left(\\frac{6p}{7r}\\right)^2 $$\n\twhere $p$ is semiperimeter and $r$ is radius of incircle. Find the sidelenghts of $ABC$ if it is known that they are all integers and their $\\gcd$ is $1$. \n\n\t\\item % imo 1995\n\tProve that for positive real numbers $a,b,c$ for which $abc=1$\n\t$$\\frac{1}{a^3(b+c)}+\\frac{1}{b^3(a+c)}+\\frac{1}{c^3(a+b)} \\geq \\frac{3}{2}$$\n\t\n\t\\item % https://artofproblemsolving.com/community/c2473h1038793_cauchyschwarz_inequality\n\tFor positive real numbers $a,b,c$ prove that\n\t$$\\frac{a^2+b^2}{a+b} + \\frac{b^2+c^2}{b+c} + \\frac{a^2+c^2}{a+c} \\geq a+b+c$$\n\t\n\t\\item %\n\tFor positive real number $a,b,c$ prove that\n\t$$ \\sqrt{x^2+1} + \\sqrt{y^2+1} + \\sqrt{z^2+1} \\geq \\sqrt{6(x+y+z)}  $$\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "7b145e90639d4ede00c7f005f2fbf78b9114192a", "size": 2539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04_cauchy.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": "04_cauchy.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": "04_cauchy.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": 34.3108108108, "max_line_length": 220, "alphanum_fraction": 0.6356833399, "num_tokens": 1125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6546253370880308}}
{"text": "\\section{Fiber bundles, fibrations, cofibrations}\nHaving set up the requisite technical background, \nwe can finally launch ourselves from point-set topology to the world of homotopy theory.\n\\subsection{Fiber bundles}\n\\begin{definition}\\label{fiberbundle}\n    A fiber\\footnote{Or ``fibre'', if you're British.} bundle is a map $p:E\\to B$,\n    such that for every $b\\in B$, there exists:\n    \\begin{itemize}\n\t\\item an open subset $U\\subseteq B$ that contains $b$, and\n\t\\item a map $p^{-1}(U)\\to p^{-1}(b)$ such that $p^{-1}(U)\\to U\\times p^{-1}(b)$ is a homeomorphism.\n    \\end{itemize}\n    If $p:E\\to B$ is a fiber bundle, $E$ is called the \\emph{total space}, $B$ is called the\n    \\emph{base space}, $p$ is called a \\emph{projection},\n    and $F$ (sometimes denoted $p^{-1}(b)$) is called the \\emph{fiber over $b$}.\n\\end{definition}\nIn simpler terms: the preimage over every point in $B$ looks like a product,\ni.e., the map $p:E\\to B$ is ``locally trivial'' in the base.\n\nHere is an equivalent way of stating Definition \\ref{fiberbundle}:\nthere is an open cover $\\cU$ (called the \\emph{trivializing cover}) of $B$,\nsuch that for every $U\\subseteq \\cU$,\nthere is a space $F$, and a homeomorphism\n$p^{-1}(U)\\simeq U\\times F$ that is compatible with the projections down to $U$.\n(So, for instance, a trivial example of a fiber bundle is just the projection map $B\\times F\\xar{\\mathrm{pr}_1} B$.)\n\nFiber bundles are naturally occurring objects.\nFor instance, a covering space $E\\to B$ is a fiber bundle with discrete fibers. \n\\begin{example}[The Hopf fibration]\n    The Hopf fibration is an extremely important example of a fiber bundle.\n    Let $S^3\\subset \\cC^2$ be the $3$-sphere.\n    There is a map $S^3\\to \\CP^1 \\simeq S^2$ that is given by sending a vector $v$ to the\n    complex line through $v$ and the origin.\n    This is a non-nullhomotopic map, and is a fiber bundle whose fiber is $S^1$.\n    \n    Here is another way of thinking of the Hopf fibration.\n    Recall that $S^3 = SU(2)$; this contains as a subgroup\n    the collection of matrices $\\begin{pmatrix}\\lambda & \\\\ & \\lambda^{-1}\\end{pmatrix}$.\n\tThis subgroup is simply $S^1$, which acts on $S^3$ by translation; \n\tthe orbit space is $S^2$.\n\\end{example}\nThe Hopf fibration is a map between smooth manifolds.\nA theorem of Ehresmann's says that it is not too hard to construct fiber bundles over smooth manifolds:\n\\begin{theorem}[Ehresmann]\n    Suppose $E$ and $B$ are smooth manifolds, and let $p:E\\to B$ be a smooth (i.e., $C^\\infty$) map.\n    Then $p$ is a fiber bundle if:\n    \\begin{enumerate}\n\t\\item $p$ is a \\emph{submersion}, i.e., $dp:T_e E\\to T_{p(e)} B$ is a surjection, and\n\t\\item $p$ is \\emph{proper}, i.e., preimages of compact sets are compact.\n    \\end{enumerate}\n\\end{theorem}\n%For example, I can look at the complement of a closed set in $S^3$, and then the restriction of $p$ won't be a fiber again.\nThe purpose of this part of the book is to understand fiber bundles through algebraic methods like cohomology and homotopy.\nThis means that we will usually need a ``niceness'' condition on the fiber bundles that we will be studying;\nthis condition is made precise in the following definition (see \\cite{MayConcise}).\n\\begin{definition}\\label{numerable}\n    Let $X$ be a space.\n    An open cover $\\cU$ of $X$ is said to be \\emph{numerable}\n    if there exists a subordinate partition of unity, i.e.,\n    for each $U\\in\\cU$, there is a function $f_U:X\\to [0,1]=I$\n    such that $f^{-1}((0,1]) = U$,\n    and any $x\\in X$ belongs to only finitely many $U\\in\\cU$.\n    The space $X$ is said to be \\emph{paracompact} if any open cover admits a numerable refinement.\n\\end{definition}\nThis isn't too restrictive for us algebraic topologists since CW-complexes are paracompact.\n\\begin{definition}\n    A fiber bundle is said to be \\emph{numerable} if it admits a numerable trivializing cover.\n\\end{definition}\n\n\\subsection{Fibrations and path liftings}\nFor our purposes, though, fiber bundles are still too narrow.\nFibrations capture the essence of fiber bundles, although it is not at all immediate from their definition that this is the case!\n\\begin{definition}\\label{fibration}\n    A map $p:E\\to B$ is called a \\emph{(Hurewicz\\footnote{Named after Witold Hurewicz, who was one of the first algebraic\n    topologists at MIT.}) fibration} if it satisfies the\n    \\emph{homotopy lifting property} (commonly abbreviated as HLP):\n    suppose $h:I\\times W\\to B$ is a homotopy; then there exists a lift\\footnote{Note that we place no restriction on the\n    \\emph{uniqueness} of this lift.}\n    (given by the dotted arrow) that makes the diagram commute:\n    \\begin{equation}\\label{hlp}\n\t\\xymatrix{\n\t    W\\ar[r]^f\\ar[d]_{\\mathrm{in}_0} & E\\ar[d]^p\\\\\n\t    I\\times W\\ar[r]_h\\ar@{-->}[ur]^{\\overline{h}} & B,\n\t    }\n    \\end{equation}\n\\end{definition}\nAt first sight, this seems like an extremely alarming definition, since\nthe HLP has to be checked for \\emph{all} spaces, \\emph{all} maps, and \\emph{all} homotopies! \nThe HLP is not impossible to check, though.\n\n\\begin{exercise}\\label{productfibration}\n    Check that the projection $\\mathrm{pr}_1: B\\times F\\to B$ is a fibration.\n\\end{exercise}\n\n\\begin{exercise}\n    Check the following statements.\n    \\begin{itemize}\n\t\\item Fibrations are closed under pullbacks. In other words, if $p:E\\to B$ is a fibration and $X\\to B$ is any map, then the induced map $E\\times_B X\\to X$ is a fibration.\n\t\\item Fibrations are closed under exponentiation and products. In other words, if $p:E\\to B$ is a fibration, then $E^A\\to B^A$ is another fibration.\n\t\\item Fibrations are closed under composition.\n    \\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\n    Let $p:E_0 \\to B_0$ be a fibration, and let $f:B \\to B_0$ be a homotopy equivalence.\n    Prove that the induced map $B\\times_{B_0} E_0 \\to E_0$ is a homotopy equivalence.\n    (Warning: this exercise has a lot of technical details! The end of this chapter describes an\n    alternative\\footnote{``Alternative'' in the sense that the proof uses statements\n    not covered yet in this book.}\n    solution to this exercise, when $E_0$ and $B\\times_{B_0} E_0$ are CW-complexes.)\n    \\todo{Don't forget to do this!}\n\\end{exercise}\n\n\nThere is a simple geometric interpretation of what it means for a map to be a fibration, in terms of ``path liftings''.\nTo understand this description, we will reformulate the diagram \\eqref{hlp}.\nGiven that we are working in the category of CGWH spaces, one of the first things we can attempt to do is adjoint the $I$;\nthis gives the following diagram.\n\\begin{equation}\\label{hlp2}\n    \\xymatrix{\n\tE\\ar[r]^p & B\\\\\n\tW\\ar[u]^f\\ar[r]_{\\widehat{h}} & B^I\\ar[u]_{\\mathrm{ev}_0}\n    }\n\\end{equation}\nBy the definition of the pullback of a diagram, the data of this diagram is equivalent to a map $W\\to B^I\\times_B E$.\nExplicitly,\n$$B^I\\times_B E = \\{(\\omega, e) \\in B^I\\times E \\text{ such that } \\omega(0) = p(e)\\}.$$\n\nSuppose the desired dotted map exists (i.e., $p:E\\to B$ satisfied the HLP).\nThis would beget (again, by adjointness) a lifted homotopy $\\widehat{\\overline{h}}:W\\to E^I$.\nSince we already have a map\\footnote{Clearly $(p\\omega)(0) = p(\\omega(0))$, so this map is well-defined\n(i.e., the image lands in $B^I\\times_B E$).} $\\widetilde{p}:E^I\\to B^I\\times_B E$ given by $\\omega\\mapsto (p\\omega,\\omega(0))$,\nthe existence of the lift $\\overline{h}$ in the diagram \\eqref{hlp} is equivalent to the existence of a lift in\nthe following diagram.\n\\begin{equation*}\n    \\xymatrix{\n\t& E^I\\ar[d]^{\\widetilde{p}}\\\\\n\tW\\ar[r]\\ar@{-->}[ur]^{\\widehat{\\overline{h}}} & B^I\\times_B E\n    }\n\\end{equation*}\nObviously the universal example of a space $W$ that makes the diagram \\eqref{hlp2} commute is $B^I\\times_B E$ itself.\nIf $p$ is a fibration, we can make the lift in the following diagram.\n%and if I can lift for any $W$, I can obviously construct the lift in the following diagram:\n%idk why the above line was typed in\n\\begin{equation*}\n    \\xymatrix{\n\t& E^I\\ar[d]^{\\widetilde{p}}\\\\\n\tB^I\\times_B E\\ar@{-->}[ur]^\\lambda\\ar[r]^1 & B^I\\times_B E\n    }\n\\end{equation*}\nThe map $\\lambda$ is called a \\emph{lifting function}.\nTo understand why, suppose $(\\omega, e) \\in B^I\\times_B E$, so that $\\omega(0) = p(e)$.\nIn this case, $\\lambda(\\omega,e)$ defines a path in $E$ such that\n$$p\\circ\\lambda(\\omega, e) = \\omega,\\text{ and }\\lambda(\\omega,e)(0) = e.$$\nTaking a step back and assessing the situation, we find that the lifting function $\\lambda$ starts with a path\n$\\omega$ in $B$, and some point in $E$ mapping down to $\\omega(0)$,\nand produces a ``lifted'' path in $E$ which lives over $\\omega$.\nIn other words, the map $\\lambda$ is a path lifting: it's a continuous way to lift paths in the base space $B$ to\nthe total space $E$. \n\nThe following result is a ``consistency check''.\n\\begin{theorem}[Dold]\n    Let $p:E\\to B$ be a map. Assume there's a numerable cover of $B$, say $\\cU$, such that for every $U\\in\\cU$,\n    the restriction $p|_{p^{-1}(U)}:p^{-1}U\\to U$ is a fibration.\n    (In other words, $p$ is \\emph{locally} a fibration over the base).\n    Then $p$ itself is a fibration.\n\\end{theorem}\nIn particular, one consequence of this theorem is that every numerable fiber bundle is a fibration.\nOur discussion above tells us that numerable fiber bundles satisfy the homotopy (and hence path) lifting property.\nThis is great news, as we will see shortly.\n", "meta": {"hexsha": "9ba74c44328fc658efab6ffe3b460ad3c29dc5d1", "size": 9346, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-42-fiber-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-42-fiber-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-42-fiber-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": 54.9764705882, "max_line_length": 171, "alphanum_fraction": 0.7045794993, "num_tokens": 2914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.6545382827405655}}
{"text": "\n\\subsection{Filtering Component}\n\\index{filtering component}\n\\label{sec:filtering-component}\nAs filtering component $k$ nearest neighbours ($k$NN) has been implemented.\nOne of its advantages is, that it does not require any training or whatsoever.\\citep[p.~290]{manning:2009}\n$k$NN will return a list of the $k$ closest vectors around a given centroid.\nTherefore $k$ can be interpreted as a parameter.\nWhen the value for $k$ is already determined (for instance $k=3$), then one can also speak of 3NN.\\citep[p.~297-298]{manning:2009}\nTo measure distance between two vectors the algorithm relies on the Euclidean distance, as it has been suggested by \\citeauthor{manning:2009}.\\citep[p.~292]{manning:2009}\nFor comparison other ways for calculating the distance have also been implemented - namely the Hamming distance.\nThere is a brief evaluation of both algorithms in section~\\ref{sec:hamming-vs-euclidean}.\nWhen using kNN it is recommended to choose a value $k > 1$, since otherwise it is deemed as not robust.\nIt's also better to choose an odd value for $k$.\n\nAn implementation of $k$NN with exchangeable distance function is displayed in listing~\\ref{lst:knn}.\n\n\\begin{lstlisting}[language=Python,caption={$k$NN and distance methods},label={lst:knn},float=h]\ndef hamming_distance(v1, v2):\n    return v1.hamming_distance(v2)\n\ndef euclidean_distance(v1, v2):\n    return v1.euclidean_distance(v2)\n\ndefault_distance = euclidean_distance\n\ndef k_nearest_neighbours(k, vector_origin, vectors, distance_function=default_distance):\n    distances = [(distance_function(vector_origin, v), v) for v in vectors]\n    ratings = distances\n    ratings.sort()  # sorts ascending by distance, then by DocumentVector\n    return [(r, v) for (r, v) in ratings[:k] ]\n\nclass DocumentVector(object):\n\n    # ... omitted uneccesary code\n\n    def hamming_distance(self, other):\n        d = len([ 1 for (v, o) in zip(self.values, other.values) if v != o ])\n        return d\n\n    def euclidean_distance(self, other):\n        t = sum(\n            ((v - o) ** 2  for v, o in zip(self.values, other.values))\n        )\n        d = math.sqrt(t)\n        return d\n\\end{lstlisting}\n\nThe \\textit{k\\_nearest\\_neighbours} function awaits an integer \\textit{k} as first parameter, specifying the size of the list to return.\nAs second parameter the function receives a vector which suits as centroid for calculating the distances called \\textit{vector\\_origin}.\n\\textit{vectors} are all vectors whose distance shall be measured.\nAs an optional argument \\textit{k\\_nearest\\_neighbours} awaits a function for calculating the distance.\nPer default, the function is \\textit{euclidean\\_distance} which calculates the euclidean distance between two vectors.\n\nWhen using this $k$NN with the euclidean distance function on the data of the example, the results will look as in the table~\\ref{tab:knn-result}.\nAs parameter $k$ 2 has been chosen.\n\n\\begin{table}[h]\n    \\center\n    \\rowcolors{1}{\\dustRowFirst}{\\dustRowSecond}\n    \\begin{tabular}{ l | l | l }\n        \\rowcolor{\\dustRowHead}\n        rank    & distance              & document\\_id\\\\\\hline\n        1       & 0.43305340317332686   & 1\\\\\n        2       & 0.45553841769931985   & 2\\\\\n        %3       & 0.8801677396951105    & 3\\\\\n    \\end{tabular}\n    \\caption{Possible $k$NN result for $k=2$ based on the example in section~\\ref{sec:rocchio-impl}}\n    \\label{tab:knn-result}\n\\end{table}\n", "meta": {"hexsha": "138e382ca4210077e4ac793b6983ffa4894494e2", "size": 3400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/inc/implementation/filteringcomponent/filteringcomponent.tex", "max_stars_repo_name": "dustywind/bachelor-thesis", "max_stars_repo_head_hexsha": "be06aaeb1b4d73f727a19029a3416a9b8043194d", "max_stars_repo_licenses": ["MIT"], "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/inc/implementation/filteringcomponent/filteringcomponent.tex", "max_issues_repo_name": "dustywind/bachelor-thesis", "max_issues_repo_head_hexsha": "be06aaeb1b4d73f727a19029a3416a9b8043194d", "max_issues_repo_licenses": ["MIT"], "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/inc/implementation/filteringcomponent/filteringcomponent.tex", "max_forks_repo_name": "dustywind/bachelor-thesis", "max_forks_repo_head_hexsha": "be06aaeb1b4d73f727a19029a3416a9b8043194d", "max_forks_repo_licenses": ["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.8873239437, "max_line_length": 170, "alphanum_fraction": 0.7188235294, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6544984110623752}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\\usepackage{mystyle}\n\n\\begin{document}\n\n\\section{Vector Calculus}\n\n\\begin{thm}[Cosine Theorem]\n\tGiven a triangle with vertices $A,B,C$ and respective opposing edges\n\t$a,b,c$, and edge $b$ along the $x$-axis:\n\t\\[ a^2 = b^2 + c^2 - 2bc\\cos\\theta \\]\n\\end{thm}\n\n\\begin{proof}\n\t\\[\n\t\ta = |\\vec{BC}| = |-\\vec{AC} + \\vec{AB}|\n\t\t= \\left|\\begin{pmatrix}-b\\\\0\\end{pmatrix} +\n\t\t\tc\\begin{pmatrix}\\cos\\theta\\\\\\sin\\theta\\end{pmatrix}\\right|\n\t\\]\n\t\\[\n\t\t\\tf a^2 = {(c\\cos\\theta - b)}^2 + c^2\\sin^2\\theta\n\t\t= b^2 + c^2 - 2bc\\cos\\theta\n\t\\]\n\\end{proof}\n\nA plane is described by a point and two linearly independent vectors i.e.\n\\[\\mathbf{r}(\\lambda, \\mu) = \\mathbf{a} + \\lambda \\mathbf{u} + \\mu \\mathbf{v}\\]\n\nA plane can also be expressed in Cartesian form i.e.\n\\[ax + by + cz = d\\]\n\n\\begin{ex}\n\t\\[\n\t\t\\mathbf{r} =\n\t\t\\begin{pmatrix}\n\t\t\t1\\\\2\\\\3\n\t\t\\end{pmatrix}\n\t\t+ \\lambda\n\t\t\\begin{pmatrix}\n\t\t\t1\\\\1\\\\1\n\t\t\\end{pmatrix}\n\t\t+ \\mu\n\t\t\\begin{pmatrix}\n\t\t\t2\\\\1\\\\0\n\t\t\\end{pmatrix}\n\t\t\\, \\lambda, \\mu \\in \\RR\n\t\\]\n\t\\[ x = 1 + \\lambda + 2\\mu \\]\n\t\\[ y = 2 + \\lambda + \\mu \\]\n\t\\[ z = 3 + \\lambda \\]\n\n\t\\[ \\tf \\lambda = z - 3, \\mu = y - z + 1 \\]\n\t\\[ \\tf x = 2y - z \\tf x - 2y + z = 0 \\]\n\\end{ex}\n\n\\begin{ex}[Alternative approach]\n\tGiven a plane $P$ and two points on the plane described from the origin\n\tas $\\mathbf{r}$ and $\\mathbf{a}$, if $\\mathbf{n}$ is normal to $P$ we\n\thave:\n\t\\[ (\\mathbf{r} - \\mathbf{a}) \\cdot \\mathbf{n} = 0 \\]\n\t\\[ \\tf \\mathbf{r} \\cdot \\mathbf{n} = \\mathbf{a} \\cdot \\mathbf{n} \\]\n\n\tWe can calculate the normal vector using the cross product:\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t1\\\\1\\\\1\n\t\t\\end{pmatrix}\n\t\t\\wedge\n\t\t\\begin{pmatrix}\n\t\t\t2\\\\1\\\\0\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t-1\\\\2\\\\-1\n\t\t\\end{pmatrix}\n\t\\]\n\t\\[ \\tf -x + 2y - z = -1 + 4 - 3 \\tf x - 2y + z = 0 \\]\n\\end{ex}\n\n% TODO: Put this in curves and surfaces?\nIf $r(t)$ is a parameterisation of a curve, then its length can be calculated\nas $ \\int_a^b | r'(t) | dt $.\n\nFor a surface $z = f(x,y)$, $\\mathbf{r} = x\\mathbf{i} + y\\mathbf{j} +\nf(x,y)\\mathbf{k}$. This doesn't work for closed surfaces.\n\n\\subsection{Partial Differentiation}\n\nWe can find the slope on a surface in different directions by fixing one value.\nFor example if $z = xy$ and we fix $y$, then $\\frac{\\partial z}{\\partial x} =\ny$. We can fix $x$ to obtain a similar result.\n\n\\begin{ex}\n\t\\[ f(x,y) = e^{x^2y} \\]\n\t\\[ \\frac{\\partial f}{\\partial x} = 2xy e^{x^2y} \\]\n\t\\[ \\frac{\\partial f}{\\partial y} = x^2 e^{x^2y} \\]\n\\end{ex}\n\n\\begin{ex}\n\t\\[ f(x,y) = x^2 - xy + y^2 \\]\n\t\\[ \\frac{\\partial f}{\\partial x} = 2x - y \\]\n\t\\[ \\frac{\\partial ^2 f}{\\partial y \\partial x} = -1 \\]\n\\end{ex}\n\n\\begin{thm}[Chain Rule]\n\t\\[ \\frac{d}{dx} f(u(x)) = \\frac{df}{du} \\frac{du}{dx} \\]\n\\end{thm}\n\n\\begin{proof}\n\t\\[ \\frac{u(x+h) - u(x)}{h} \\to u'(x), h \\to 0 \\]\n\t\\[ v = \\frac{u(x+h) - u(x)}{h} - u'(x), v \\to 0, h \\to 0 \\]\n\t\\[ \\implies u(x+h) = u(x) + (u'(x) + v)h \\]\n\t\\[ w = \\frac{f(u+k) - f(u)}{k} - f'(u), w \\to 0, k \\to 0 \\]\n\t\\[ \\implies f(u+k) = f(u) + (f'(u) + w)k \\]\n\t\\[ \\frac{df}{dx} = \\frac{f(u(x+h)) - f(u(x))}{h} \\]\n\t\\[ f(u(x+h)) - f(u(x))= f(u(x) + (u'(x)+v)h) - f(u(x))  = (f'(u(x) +\n\tw))(u'(x) + v), \\]\n\twhere $k = (u'(x)+v)h$, $k \\to 0$ as $h \\to 0$\n\t\\[ \\implies \\lim_{h \\to 0} \\frac{f(u(x+h)) - f(u(x))}{h} =\n\tf'(u(x))u'(x) \\]\n\n\\end{proof}\n\n\\begin{lemma}\n\tIf $z(t) = (x(t), y(t))$ then\n\t\\[ \\frac{dz}{dt} = \\frac{\\partial z}{\\partial x}\\frac{dx}{dt} +\n\t\\frac{\\partial z}{\\partial y}\\frac{dy}{dt}. \\]\n\\end{lemma}\n\n\\begin{proof}\n\t\\[ \\frac{dz}{dt} = \\frac{z(x(t+h), y(t+h)) - z(x(t), y(t))}{h} \\]\n\t\\[ = \\frac{z(x(t+h), y(t+h)) - z(x(t), y(t+h))}{h} + \\frac{z(x(t),\n\ty(t+h)) - z(x(t), y(t))}{h} \\]\n\n\tWe now have two differences, one with $y$ fixed and the other with\n\t$x$ fixed. Applying the chain rule to each one, we obtain:\n\n\t\\[ \\frac{dz}{dt} = \\frac{\\partial z}{\\partial x} x'(t) + \\frac{\\partial\n\tz}{\\partial y} y'(t) \\]\n\\end{proof}\n\n\\subsection{Tangents}\n\nIf $\\mathbf{r}(t)$ is a point in space, then the vector tangent to it is $r(t) + \\lambda\n\\mathbf{r}'(t)$.\n\n\\begin{ex}\n\t\\[\n\t\t\\mathbf{r}(t) =\n\t\t\\begin{pmatrix}\n\t\t\tt^2 \\\\ t^3 \\\\ t^4\n\t\t\\end{pmatrix}\n\t\t, t \\in \\RR\n\t\\]\n\t\\[\n\t\t\\mathbf{r}'(t) =\n\t\t\\begin{pmatrix}\n\t\t\t2t \\\\ 3t^2 \\\\ 4t^3\n\t\t\\end{pmatrix}\n\t\\]\n\n\tAt $t=2$ we have:\n\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t4 \\\\ 8 \\\\ 16\n\t\t\\end{pmatrix}\n\t\t+ \\lambda\n\t\t\\begin{pmatrix}\n\t\t\t4 \\\\ 12 \\\\ 32\n\t\t\\end{pmatrix}\n\t\t, \\lambda \\in \\RR\n\t\\]\n\\end{ex}\n\nSimilarly, a tangent plane can be described with a vector to the tangent point\nand the two partial derivatives.\n\n\\[ \\mathbf{p} = \\mathbf{r}(x_0, y_0)\n+ \\lambda \\frac{\\partial \\mathbf{r}}{\\partial x}(x_0, y_0)\n+ \\lambda \\frac{\\partial \\mathbf{r}}{\\partial y}(x_0, y_0)\n, \\lambda, \\mu \\in \\RR \\]\n\n\\begin{ex}\n\tFind the plane tangent to $x^2 + y^2 + z^2 = 9$ at $(1,2,2)$.\n\n\t\\[ \\mathbf{r} = (x,y,z), z = {(9 - x^2 - y^2)}^{1/2} \\]\n\n\t\\[ \\frac{\\partial \\mathbf{r}}{\\partial x} = (1, 0, \\partial z /\n\t\\partial x) \\]\n\t\\[ \\frac{\\partial \\mathbf{r}}{\\partial y} = (0, 1, \\partial z /\n\t\\partial y) \\]\n\n\t\\[ \\frac{\\partial z}{\\partial x} = - \\frac{x}{{(9-x^2-y^2)}^{1/2}} \\]\n\t\\[ \\frac{\\partial z}{\\partial y} = - \\frac{y}{{(9-x^2-y^2)}^{1/2}} \\]\n\n\tPlugging in the values $x=1$ and $y=2$ we obtain:\n\n\t\\[ \\mathbf{p} = (1,2,2) + \\lambda (1, 0, -1/2) + \\mu (0, 1, -1) \\]\n\\end{ex}\n\n\\begin{ex}\n\tFind the plane tangent to $z = 1 - 1/4 x^2 - y^2$ at $(1,1/2,1/2)$.\n\n\t\\[ \\frac{\\partial z}{\\partial x} = -1/2 x \\]\n\t\\[ \\frac{\\partial z}{\\partial y} = -2y \\]\n\n\tPlugging in the values $x=1$ and $y=1/2$ we obtain:\n\n\t\\[ \\mathbf{p} = (1,1/2,1/2) + \\lambda (1, 0, -1/2) + \\mu (0, 1, -1) \\]\n\\end{ex}\n\n\\subsection{Directional Derivatives}\n\nLet $\\mathbf{r} = \\left(x_0 + tn_1, y_0 + tn_2, z(x_0 + tn_1, y_0 +\ntn_2)\\right)$ describe a curve in the plane, where $\\mathbf{n} = (n_1, n_2)$ is\nthe direction vector and $t \\in \\RR$.\n\n\\[ \\frac{d\\mathbf{r}}{dt} = \\left(n_1, n_2, n_1 \\frac{\\partial z}{\\partial x}\n(x_0 + tn_1, y_0 + tn_2) + n_2 \\frac{\\partial z}{\\partial x} (x_0 + tn_1, y_0 +\ntn_2)\\right) \\]\n\nGiven that the gradient of a curve can be expressed as $\\frac{z}{\\sqrt{x^2 +\ny^2}}$,\n\n\\[ \\frac{\\frac{\\partial z}{\\partial x} n_1 + \\frac{\\partial z}{\\partial y}\nn_2}{\\sqrt{n_1^2 + n_2^2}} \\]\n\nHence the slope on the surface $z$ in the direction of $n$ is given by:\n\n\\[ \\bigtriangledown z \\mathbf{\\hat{n}} \\]\n\n\\begin{ex}\n\t\\[ z(x,y) = 4 - x^2 - y^2, n = (1,1) \\]\n\t\\[ \\bigtriangledown z = (-2x, -2y) = (-2, -2) \\]\n\t\\[ \\mathbf{\\hat{n}} = \\frac{\\sqrt{2}}{2} (1,1) \\]\n\t\\[ \\bigtriangledown z \\mathbf{\\hat{n}} = \\frac{-4}{\\sqrt{2}}\n\t   = -2 \\sqrt{2} \\]\n\\end{ex}\n\n\\begin{ex}\n\t$f(x,y,z) = e^{xyz}$ at $(2,-1,2)$ with $n = (1,1,1)$\n\t\\[ \\bigtriangledown f = (yze^{xyz}, xze^{xyz}, xye^{xyz})\n\t\t= (-2e^{-4}, 4e^{-4}, -2^{-4}) \\]\n\t\\[ \\mathbf{\\hat{n}} = 1/\\sqrt{3}(1,1,1) \\]\n\t\\[ \\bigtriangledown f \\cdot \\mathbf{\\hat{n}} = 1/\\sqrt{3}(-2e^{-4} +\n\t4e^{-4} - 2e^{-4}) = 0 \\]\n\\end{ex}\n\n\\subsubsection{Greatest Slope}\n\n\\[ \\bigtriangledown z \\cdot \\mathbf{\\hat{n}} = |\\bigtriangledown\nz||\\mathbf{\\hat{n}}|\\cos \\theta \\]\n\nIn order to maximise this, we let $\\cos \\theta = 1$ and given that\n$\\mathbf{\\hat{n}}$ is a unit vector, the greatest slope is $|\\bigtriangledown\nz|$. Therefore, the direction of the greatest slope is in the direction of\n$\\bigtriangledown z$, since $|a|^2 = a \\cdot a$.\n\n\\begin{ex}\n\t$z(x,y) = 4 - x^2 - y^2$ at $(1,1)$\n\t\\[ \\bigtriangledown z = (-2,-2) \\]\n\t\\[ |\\bigtriangledown z| = 2\\sqrt{2} \\]\n\\end{ex}\n\n\\subsection{Volume under a surface}\n\nLet $f(x,y)$ be a surface, the volume underneath it is\n\\[ v = \\int_a^b \\int_{x_1(y)}^{x_2(y)} f(x,y) dx dy \\]\n\n\\begin{ex}\n\t$z = x^2y^3$ above the region bound by $y=1$, $x=4$, and $y=\\sqrt{x}$.\n\n\t\\[ v = \\int_1^4 \\int_1^{\\sqrt{x}} x^2y^3 dy dx \\]\n\t\\[ = 1/4 \\int_1^4 \\left[ x^2y^4 \\right]_1^{\\sqrt{x}} \\]\n\t\\[ = 1/4 \\int_1^4 x^4 - x^2 dx \\]\n\t\\[ = 1/4 \\left[ 1/5 x^5 - 1/3 x^3 \\right]_1^4 \\]\n\t\\[ = 1024/20 - 64/12 - 1/20 + 1/12 = 45.9 \\]\n\n\tThis can also be calculated by integrating first with respect to $x$.\n\n\t\\[ v = \\int_1^2 \\int_{y^2}^4 x^2y^3 dxdy \\]\n\t\\[ = 1/3 \\int_1^2 \\left [x^3y^3 \\right]_{y^2}^4 dy \\]\n\t\\[ = 1/3 \\int_1^2 64y^3 - y^9 dy \\]\n\t\\[ = 1/3 \\left[ 16y^4 - 1/10 y^10 \\right]_1^2 \\]\n\t\\[ = 1/3 \\left( 256 - 1024/10 - 16 + 1/10 \\right) = 45.9 \\]\n\n\\end{ex}\n\n\\subsection{Changing Coordinates}\n\nWhen changing coordinate system, we have to take into account how that affects\ndifferentiation and integration.\n\nLet $\\mathbf{r}(x,y) = x \\mathbf{i} + y \\mathbf{j}$. A change of $dx$ and $dy$\nwould give:\n\n\\[ (x + dx)\\mathbf{i} + y\\mathbf{j} - (x\\mathbf{i} + y\\mathbf{j}) =\ndx\\mathbf{i} \\]\n\\[ x\\mathbf{i} + (y + dy)\\mathbf{j} - (x\\mathbf{i} + y\\mathbf{j}) =\ndy\\mathbf{j} \\]\n\nThe differential area can be calculated using the cross product (think about\nthe area of a parallelogram). Given that $dx$ and $dy$ are just scalars, and\n$\\mathbf{i}$ and $\\mathbf{j}$ are orthogonal unit vectors:\n\n\\[ |dx\\mathbf{i} \\times dy\\mathbf{j}| = |dxdy\\mathbf{k}| = dxdy \\]\n\nNow lets see how things change when we switch to polar coordinates. Let\n$\\mathbf{f}(r,\\theta) = r\\cos\\theta\\mathbf{i} + r\\sin\\theta\\mathbf{j}$.\n\nA change by $dr$ yields:\n\\[ (r+dr)\\cos\\theta\\mathbf{i} + (r+dr)\\sin\\theta\\mathbf{j} -\nr\\cos\\theta\\mathbf{i} - r\\sin\\theta\\mathbf{j} \\]\n\\[ = dr(\\cos\\theta\\mathbf{i} + \\sin\\theta\\mathbf{j}) \\]\n\nA change by $d\\theta$ yields:\n\\[ r\\cos(\\theta + d\\theta)\\mathbf{i} + r\\sin(\\theta + d\\theta)\\mathbf{j} -\nr\\cos\\theta\\mathbf{i} - r\\sin\\theta\\mathbf{j} \\]\n\\[ = r\\left(\\cos(\\theta + d\\theta) - \\cos(\\theta)\\right)\\mathbf{i}\n+ r\\left(\\sin(\\theta + d\\theta) - \\sin(\\theta)\\right)\\mathbf{j} \\]\n\nGiven that:\n\\[ \\frac{d}{d\\theta} \\cos\\theta = \\frac{\\cos(\\theta + d\\theta) -\n\\cos\\theta}{d\\theta} \\]\n\nWe find that a change by $d\\theta$ is simply:\n\\[ -r\\sin(\\theta)d\\theta \\mathbf{i} + r\\cos(\\theta)d\\theta \\mathbf{j} \\]\n\nNow we compute the full differential area:\n\\[ | dr(\\cos\\theta \\mathbf{i} + \\sin\\theta \\mathbf{j}) \\wedge\nd\\theta(-r \\sin\\theta \\mathbf{i} + r\\cos\\theta \\mathbf{j}) | \\]\n\\[ = | r\\cos^2\\theta + r\\sin^2\\theta | drd\\theta = rdrd\\theta \\]\n\n\\begin{ex}\n\t\\[ I = \\int \\int x^2 y^2 dxdy \\]\n\t\\[ = \\int_0^{\\pi} \\int_0^1 (r^2 \\cos^2\\theta)(r^2 \\sin^2\\theta)\n\trdrd\\theta \\]\n\t\\[ = \\int_0^{\\pi} \\cos^2\\theta \\sin^2\\theta d\\theta\n\t\\int_0^1 r^5 dr \\]\n\n\tGiven that $\\cos2\\theta = \\cos^2\\theta - \\sin^2\\theta$, we have:\n\n\t\\[ \\sin^2\\theta = \\frac{1}{2} - \\frac{1}{2} \\cos2\\theta \\]\n\t\\[ \\cos^2\\theta = \\frac{1}{2} + \\frac{1}{2} \\cos2\\theta \\]\n\n\tHence:\n\n\t\\[\n\t\t\\sin^2\\theta \\cos^2\\theta =\n\t\t(\\frac{1}{2} - \\frac{1}{2} \\cos2\\theta)\n\t\t(\\frac{1}{2} + \\frac{1}{2} \\cos2\\theta)\n\t\\]\n\t\\[\n\t\t= \\frac{1}{4} - \\frac{1}{4} \\cos^2 2\\theta\n\t\\]\n\t\\[\n\t\t= \\frac{1}{4} - \\frac{1}{4}\n\t\t(\\frac{1}{2} + \\frac{1}{2} \\cos4\\theta)\n\t\\]\n\t\\[\n\t\t= \\frac{1}{8} - \\frac{1}{8} \\cos4\\theta\n\t\\]\n\t\\[\n\t\t\\int_0^{\\pi} \\frac{1}{8} - \\frac{1}{8} \\cos4\\theta d\\theta =\n\t\t\\left[ \\theta + \\sin4\\theta \\right]_0^{\\pi} = \\pi/8\n\t\\]\n\t\\[\n\t\t\\int_0^1 r^5 dr = \\left[ \\frac{1}{6} r^6 \\right]_0^1\n\t\t= \\frac{1}{6}\n\t\\]\n\n\tTherefore,\n\n\t\\[ I = \\pi/48. \\]\n\n\\end{ex}\n\nWe can generalise this concept of coordinate transformation for a\ngeneric function\n$ \\mathbf{r} (s,t) = x(s,t)\\mathbf{i} + y(s,t)\\mathbf{j}$.\n\nChanging by $ds$:\n\\[\n\t\\frac{d\\mathbf{r}}{ds} ds =\n\t\\left( \\frac{dx}{ds}\\mathbf{i} + \\frac{dy}{ds}\\mathbf{j} \\right) ds\n\\]\n\nChanging by $dt$:\n\\[\n\t\\frac{d\\mathbf{r}}{dt} dt =\n\t\\left( \\frac{dx}{dt}\\mathbf{i} + \\frac{dy}{dt}\\mathbf{j} \\right) dt\n\\]\n\nThe resultant change in area is:\n\\[\n\t| \\frac{dr}{ds}ds \\wedge \\frac{dr}{dt}dt |\n\t= | \\frac{dx}{ds}\\frac{dy}{dt} - \\frac{dx}{dt}\\frac{dy}{ds} | dsdt\n\\]\n\nThis leads us to the following definition.\n\n% TODO: these should be partial derivatives (and above)\n\\begin{defn}[Jacobian]\n\tLet $x = x(s,t)$, $y = y(s,t)$, then\n\t$J(s,t) = |\\frac{dx}{ds}\\frac{dy}{dt} - \\frac{dx}{dt}\\frac{dy}{ds}|$\n\tis the Jacobian.\n\\end{defn}\n\n\\begin{ex}[Ellipse]\n\tLet $x = r\\cos\\theta$, $y = \\frac{b}{a}r\\sin\\theta$. Let $\\Omega$ be the\n\tregion where $0 <= \\theta <= 2\\pi$, $0 <= r <= a$.\n\n\t\\[\n\t\tJ(r,\\theta) = \\left| \\frac{\\partial x}{\\partial r}\n\t\t\\frac{\\partial y}{\\partial \\theta} -\n\t\t\\frac{\\partial x}{\\partial \\theta}\n\t\t\\frac{\\partial y}{\\partial r} \\right|\n\t\\]\n\t\\[\n\t\t\\frac{\\partial x}{\\partial r} = \\cos\\theta\n\t\t\\quad\n\t\t\\frac{\\partial x}{\\partial \\theta} = -r \\sin\\theta\n\t\\]\n\t\\[\n\t\t\\frac{\\partial y}{\\partial r} = \\frac{b}{a} \\sin\\theta\n\t\t\\quad\n\t\t\\frac{\\partial y}{\\partial \\theta} = \\frac{b}{a}r \\cos\\theta\n\t\\]\n\t\\[\n\t\t\\Rightarrow J(r,\\theta) = \\left| \\frac{b}{a}r \\cos^2\\theta +\n\t\t\\frac{b}{a}r \\sin^2\\theta \\right| = \\frac{b}{a}r\n\t\\]\n\t\\[\n\t\t\\Rightarrow \\int\\int_{\\Omega} dxdy =\n\t\t\\int_0^{2\\pi} \\int_0^a \\frac{b}{a}r drd\\theta\n\t\\]\n\t\\[\n\t\t= \\int_0^{2\\pi} \\frac{ba}{2} d\\theta = ab\\pi\n\t\\]\n\\end{ex}\n\n\\subsection{Surface Area}\n\nTake a parallelogram with corners:\n\n\\[\n\tA = \\begin{pmatrix}\n\t\tx \\\\\n\t\ty \\\\\n\t\tf(x,y)\n\t\\end{pmatrix}\n\tB = \\begin{pmatrix}\n\t\tx+dx \\\\\n\t\ty \\\\\n\t\tf(x+dx,y)\n\t\\end{pmatrix}\n\tC = \\begin{pmatrix}\n\t\tx \\\\\n\t\ty+dy \\\\\n\t\tf(x,y+dy)\n\t\\end{pmatrix}\n\tD = \\begin{pmatrix}\n\t\tx+dx \\\\\n\t\ty+dy \\\\\n\t\tf(x+dx,y+dy)\n\t\\end{pmatrix}\n\\]\n\nWe then calculate the area of this using the cross product:\n\n\\[\n\t\\vec{AB} =\n\t\\begin{pmatrix}\n\t\tx+dx \\\\\n\t\ty \\\\\n\t\tf(x+dx,y)\n\t\\end{pmatrix}\n\t-\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty \\\\\n\t\tf(x,y)\n\t\\end{pmatrix}\n\t=\n\tdx\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0 \\\\\n\t\t\\partial f / \\partial x\n\t\\end{pmatrix}\n\\]\n\\[\n\t\\vec{AC} =\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty+dy \\\\\n\t\tf(x,y+dy)\n\t\\end{pmatrix}\n\t-\n\t\\begin{pmatrix}\n\t\tx \\\\\n\t\ty \\\\\n\t\tf(x,y)\n\t\\end{pmatrix}\n\t=\n\tdy\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t1 \\\\\n\t\t\\partial f / \\partial y\n\t\\end{pmatrix}\n\\]\n\\[\n\t\\vec{AB} \\wedge \\vec{AC} =\n\tdxdy\n\t\\begin{vmatrix}\n\t\ti & j & k \\\\\n\t\t1 & 0 & \\partial f / \\partial x \\\\\n\t\t0 & 1 & \\partial f / \\partial y\n\t\\end{vmatrix}\n\t=\n\tdxdy\n\t\\begin{pmatrix}\n\t\t- \\partial f / \\partial x \\\\\n\t\t- \\partial f / \\partial y \\\\\n\t\t1\n\t\\end{pmatrix}\n\\]\n\\[\n\tarea = dxdy\n\t\\begin{vmatrix}\n\t\t- \\partial f / \\partial x \\\\\n\t\t- \\partial f / \\partial y \\\\\n\t\t1\n\t\\end{vmatrix}\n\t=\n\tdxdy\n\t\\left(\n\t\t(\\partial f / \\partial x)^2,\n\t\t(\\partial f / \\partial y)^2,\n\t\t1\n\t\\right)^{1/2}\n\\]\n\nTo get the full surface area, we need to sum these parallelograms. To do\nthis, we use integration, similarly to calculating the length of a\ncurve. In fact, this is essentially a two dimensional analogue.\n\nGeneralising our derivation, by using the fact that our parallelograms\nare constructed by partial derivatives, we arrive at the following\nformula for surface area.\n\nLet $r(s,t) = (x(s,t), y(s,t), z(s,t))$ where $s,t \\in R$, and $R$ is the\nregion of surface area. The surface area is calulated by:\n\n\\[\n\tS = \\int \\int_R \\left| \\frac{\\partial r}{\\partial s} \\wedge\n\t\\frac{\\partial r}{\\partial t} \\right| dsdt\n\\]\n\nNotice from our derivation of this formula that if the surface can be\nexpressed as $(x,y,f(x,y))$, the surface area is much simpler:\n\n\\[\n\tS = \\int \\int_R \\left|\n\t\\left(\n\t\t(\\partial f / \\partial x)^2,\n\t\t(\\partial f / \\partial y)^2,\n\t\t1\n\t\\right)^{1/2}\n\t\\right|\n\tdxdy\n\\]\n\n\\begin{ex}\n\tLet $z=xy$ and let$R$ be the cylinder defined by $x^2 + y^2 = 1$.\n\n\t\\begin{align*}\n\t\tS &= \\int \\int_R \\left( x^2 + y^2 + 1 \\right)^{1/2} dxdy \\\\\n\t\t&= \\int_0^{2\\pi} \\int_0^1 r(1+r^2)^{1/2} drd\\theta \\\\\n\t\t&= \\int_0^{2\\pi}\n\t\t\\left[\n\t\t\t\\frac{1}{2} \\frac{2}{3} (1+r^2)^{3/2}\n\t\t\\right]_0^1 d\\theta \\\\\n\t\t&= \\frac{1}{3} \\int_0^{2\\pi} 2^{3/2} - 1 d\\theta \\\\\n\t\t&= \\frac{1}{3} \\sqrt{8} 2\\pi - 2\\pi \\\\\n\t\t&= \\frac{2\\pi}{3} (\\sqrt{8} - 1)\n\t\\end{align*}\n\\end{ex}\n\n% TODO: move this to another file\n\\section{Differential Equations}\n\n\\begin{defn}[Fixed Point]\n\tLet $f(x) = \\frac{dx}{dt}$ then $x^*$ is a fixed point if $f(x^*) = 0$.\n\tFurthermore, fixed points can be stable or unstable:\n\t\\begin{align*}\n\t\tf'(x^*) &> 0 \\Rightarrow unstable \\\\\n\t\tf'(x^*) &< 0 \\Rightarrow stable \\\\\n\t\tf'(x^*) &= 0 \\Rightarrow constant\n\t\\end{align*}\n\\end{defn}\n\nLet $x^*$ be a fixed point for $f(x) = \\frac{dx}{dt}$. We can express\npoints around $x^*$ as $x(t) = x^* + z(t)$, where $z$ is small.\n\nGiven that $\\frac{d}{dt}(x^* + z(t)) = f(x^* + z(t))$ and\n$\\frac{d}{dt}(x^*) = 0$, we have\n\\[\n\t\\frac{dz}{dt} = f(x^* + z(t))\n\\]\n\nWe can expand $f(x)$ around the point $x^*$ using a Taylor series:\n\\[\n\tf(x) = f(x^*) + f'(x^*)(x - x^*) + \\frac{1}{2}f''(x^*)(x - x^*)^2 + \\dots \\\\\n\\]\nWith $x = x^* + z$ we have:\n\\[\n\tf(x^* + z) = f(x^*) + f'(x^*)z + \\frac{1}{2}f''(x^*)z^2 + \\dots \\\\\n\\]\n$z$ is small by assumption so we ignore terms with $z^2$ and onwards, yielding:\n\\[\n\t\\frac{dz}{dt} = f(x^* + z) = f(x^*) + f'(x^*)z\n\\]\nGiven that $f(x^*) = 0$, we have\n\\[\n\t\\frac{dz}{dt} = f'(x^*)z\n\\]\n\nWe now aim to find a set of such functions $z(t)$ satisfying this equation.\n\\[\n\t\\frac{dz}{dt} = \\lambda z, \\quad \\lambda = f'(x)\n\\]\n\nWe look for a solution of the form $Ce^{kt}$, where $C$ is constant,\nsince $\\frac{d}{dt} e^t = e^t$.\n\n\\begin{gather*}\n\tz(t) = Ce^{kt} \\\\\n\t\\Rightarrow z'(t) = kCe^{kt} = \\lambda z = \\lambda Ce^{kt} \\\\\n\t\\Rightarrow k = \\lambda \\\\\n\t\\Rightarrow z(t) = Ce^{\\lambda t} \\\\\n\tz(0) = C \\\\\n\t\\Rightarrow z(t) = z(0)e^{\\lambda t}\n\\end{gather*}\n\nIf $\\lambda < 0$, $z \\to 0$ as $t \\to \\infty$ (stable). \\\\\nIf $\\lambda > 0$, $z \\to \\infty$ as $t \\to \\infty$ (unstable). \\\\\nIf $\\lambda = 0$, $z$ is constant.\n\n\\subsection{Linear First Orders}\n\n\\[\n\t\\frac{dy}{dx} + p(x)y = q(x)\n\\]\n\nWe want to get the LHS in the form\n\\[\n\ty\\frac{dg}{dx} + g\\frac{dy}{dx} = \\frac{d}{dx} gy\n\\]\nso that we can solve with one integral.\n\nMutliplying through by $g(x)$ we get:\n\\begin{gather*}\n\tg(x)\\frac{dy}{dx} + g(x)p(x)y = y\\frac{dg}{dx} + g\\frac{dy}{dx} \\\\\n\t\\Rightarrow \\frac{dg}{dx} = p(x)g(x) \\\\\n\t\\Rightarrow \\int \\frac{1}{g(x)} \\frac{dg}{dx} dx = \\int p(x) dx \\\\\n\t\\Rightarrow \\ln |g(x)| = \\int p(x) dx \\\\\n\t\\Rightarrow g(x) = e^{\\int p(x) dx}\n\\end{gather*}\n\nSo now we need to solve\n\\[\n\tg(x)\\frac{dy}{dx} + g(x)p(x)y = g(x)q(x)\n\\]\nwhich can be simplified to\n\\[\n\t\\frac{d}{dx} gy = gq\n\\]\n\nSubstituting in $g(x)$ we have:\n\\[\n\ty = e^{\\int p} \\int q e^{\\int p} dx\n\\]\n\n\\begin{ex}\n\t\\begin{gather*}\n\t\t\\frac{dy}{dx} - \\frac{y}{x^2} = - \\frac{1}{x^2} \\\\\n\t\t\\Rightarrow g(x) = \\exp{\\int -x^{-2}} = e^{1/x} \\\\\n\t\t\\Rightarrow \\frac{d}{dx} gy = - \\frac{e^{1/x}}{x^2} \\\\\n\t\t\\Rightarrow y e^{1/x} = e^{1/x} + c\n\t\\end{gather*}\n\n\tUsing the original equation, it is easy to see that $c=0$ and $y=1$.\n\\end{ex}\n\n\\subsection{Linear Second Order Equations}\n\n\\begin{defn}[Homogeneous Equation]\n\tA differential equation is homogeneous if there are no terms\n\twithout a derivative of $y$ (or $y$ itself), e.g.\n\t\\[\n\t\t\\frac{dy}{dx} + f(x)y = 0\n\t\\]\n\\end{defn}\n\n\\begin{defn}[Eigen Function]\n\tAn Eigen function is a function that when passed through another\n\tfunction results in multiplication, e.g.\n\t\\[ \\frac{d}{dx} e^{kx} = ke^{kx} \\]\n\tHere $e^{kx}$ is the Eigen function that when passed through\n\t$\\frac{d}{dx}$ results in multiplication by $k$, which is\n\trefered to as the Eigen value.\n\\end{defn}\n\nWe will use these definitions to solve linear second order O.D.Es.\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2y}{dx^2} + \\frac{dy}{dx} - 2y = 0\n\t\\]\n\n\tWe try $y = e^{mx}$ as we are aware that it is an Eigen function\n\tunder differentiation. Plugging in, we get:\n\n\t\\begin{gather*}\n\t\t(m^2 + m - 2)e^{mx} = 0 \\\\\n\t\t\\Rightarrow m^2 + m - 2 = 0 \\\\\n\t\t\\Rightarrow (m+2)(m-1) = 0 \\\\\n\t\t\\Rightarrow m = -2, 1\n\t\\end{gather*}\n\n\t% TODO: go into detail with linear combination with Wronskian\n\t% etc.\n\tSo we have two particular solutions to our equation, namely\n\t$e^x$ and $e^{-2x}$. With two independent solutions, we can use a\n\tlinear combination of these to construct our general solution, much\n\tin the same way that we can describe a plane using two linearly\n\tindependent vectors. Hence, the general solution to our equation is:\n\t\\[\n\t\ty = Ae^x + Be^{-2x}\n\t\\]\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2y}{dx^2} + \\frac{dy}{dx} + y = 0\n\t\\]\n\n\t\\begin{gather*}\n\t\tm^2 + m + 1 = 0 \\\\\n\t\tm = \\frac{-1 \\pm \\sqrt{1-4}}{2} \\\\\n\t\t= \\frac{-1 \\pm \\sqrt{3}i}{2}\n\t\\end{gather*}\n\n\tGiven that\n\t\\[\n\t\te^{i\\theta} = \\cos{\\theta} + i\\sin{\\theta}\n\t\\]\n\twe have\n\t\\[\n\t\te^{mx} = e^{-x/2}\\left(\\cos(\\pm \\frac{\\sqrt{3}}{2}x)\n\t\t+ i\\sin(\\pm\\frac{\\sqrt{3}}{2}x)\\right)\n\t\\]\n\tand given that\n\t\\begin{align*}\n\t\t\\cos(-\\theta) &= \\cos(\\theta) \\\\\n\t\t\\sin(-\\theta) &= -\\sin(\\theta)\n\t\\end{align*}\n\tour particular solutions can be simplified to\n\t\\[\n\t\ty = e^{-x/2}\\left(\\cos \\frac{\\sqrt{3}}{2}x\n\t\t\\pm i\\sin\\frac{\\sqrt{3}}{2}x\\right)\n\t\\]\n\n\tGiven that we have two particular solutions, the general solution is:\n\t\\[\n\t\ty = e^{-x/2}\\left(A\\cos \\frac{\\sqrt{3}}{2}x\n\t\t\\pm B\\sin\\frac{\\sqrt{3}}{2}x\\right)\n\t\\]\n\twhere $A,B \\in \\CC$.\n\n\tIn fact, if the roots of the characteristic equation are complex\n\tconjugates $\\alpha \\pm i\\beta$, then the general solution can be\n\texpressed:\n\t\\[\n\t\ty = Ae^{\\alpha x}\\cos\\beta x + Be^{\\alpha x}\\sin\\beta x\n\t\\]\n\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2y}{dx^2} + 6 \\frac{dy}{dx} + 9y = 0\n\t\\]\n\n\t\\begin{gather*}\n\t\t(m^2 + 6m + 9)e^{mx} = 0 \\\\\n\t\tm^2 + 6m + 9 = 0 \\\\\n\t\t(m+3)^2  = 0 \\\\\n\t\tm = -3\n\t\\end{gather*}\n\n\tHere we get repeated roots, rather than distinct, which means we\n\tcan't form a general solution yet.\n\n\t% TODO: explain why factor of x works.\n\tThe general form of these solutions is $(Ax+B)e^{mx}$, so our\n\tgeneral solution is:\n\t\\[\n\t\ty = (Ax+B)e^{-3x}\n\t\\]\n\\end{ex}\n\n\\subsection{Inhomogeneous Equations}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2}{dx^2} - 4\\frac{dy}{dx} + 5y = 1\n\t\\]\n\tWe try a scalar value for $y$ since the RHS is scalar: $y =\n\t\\frac{1}{5}$. It is easy to see that this is a particular\n\tsolution.\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2}{dx^2} - 4\\frac{dy}{dx} + 4y = x\n\t\\]\n\tWe now try $y = Ax+B$ since the RHS is $x$. Plugging in we get:\n\t\\[\n\t\t0 - 4A + 4Ax + 4B = x\n\t\\]\n\tfrom which it is quite easy to see that $A = B = \\frac{1}{4}$. Hence\n\t\\[\n\t\ty = \\frac{1}{4}x + \\frac{1}{4}\n\t\\]\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2}{dx^2} + 4\\frac{dy}{dx} + 5y = x^2\n\t\\]\n\tWe now try $y = Ax^2 + Bx + C$:\n\t\\begin{gather*}\n\t\t2A + 8Ax + 4B + 5Ax^2 + 5Bx + 5C = x^2 \\\\\n\t\t\\Rightarrow A = \\frac{1}{5} \\\\\n\t\t\\Rightarrow \\frac{2}{5} + \\frac{8}{5}x + 4B + 5Bx + 5C = 0 \\\\\n\t\t\\Rightarrow 5B = -\\frac{8}{5} \\\\\n\t\t\\Rightarrow B = -\\frac{8}{25} \\\\\n\t\t\\Rightarrow \\frac{2}{5} - \\frac{32}{25} = -5C \\\\\n\t\t\\Rightarrow C = \\frac{22}{125} \\\\\n\t\t\\Rightarrow y = \\frac{1}{5}x^2 - \\frac{8}{25} x + \\frac{22}{125}\n\t\\end{gather*}\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2}{dx^2} - 3\\frac{dy}{dx} + y = 3\\cos x\n\t\\]\n\tWe try $y = A\\sin x + B \\cos x$\n\t\\begin{gather*}\n\t\t-A\\sin x - B\\cos x - 3A\\cos x + 3B\\sin x + A\\sin x + B\\cos x\n\t\t= 3\\cos x \\\\\n\t\t\\Rightarrow -A + 3B + A = 0 \\Rightarrow B = 0 \\\\\n\t\t\\Rightarrow -B - 3A + B = 3 \\Rightarrow A = -1 \\\\\n\t\t\\Rightarrow y = -\\sin x\n\t\\end{gather*}\n\\end{ex}\n\nTo get the general solution to a second order linear inhomogeneous\nequation, we need to find the general solution to the corresponding\nhomogeneous function, $y_c$, and the particular solution to the\ninhomogeneous equation, $y_p$. Then the general solution to the\ninhomogeneous equation is given by\n\\[\n\ty = y_c + y_p\n\\]\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2}{dx^2} - 4\\frac{dy}{dx} + 4y = x\n\t\\]\n\tAs we saw before, $y_p = \\frac{1}{4}x + \\frac{1}{4}$.\n\n\tThe homogeneous function is:\n\t\\[\n\t\t\\frac{d^2}{dx^2} - 4\\frac{dy}{dx} + 4y = 0\n\t\\]\n\tWe solve using the same method as earlier:\n\t\\begin{gather*}\n\t\tm^2 - 4m + 4 = 0 \\\\\n\t\t(m - 2)^2 = 0 \\\\\n\t\tm = 2 \\\\\n\t\t\\Rightarrow y_c = (Ax+B)e^{2x} \\\\\n\t\\end{gather*}\n\tNow we can calculate the general solution $y = y_c + y_p$:\n\t\\[\n\t\ty = (Ax+B)e^{2x} + \\frac{1}{4}x + \\frac{1}{4}\n\t\\]\n\\end{ex}\n\n\\subsection{Variation of parameters}\n\nLet $y_p = q_1(x) v_1(x) + q_2(x) v_2(x)$, then:\n\\[\n\ty_p' = q_1v_1' + q_1'v_1 + q_2v_2' + q_2'v_2\n\\]\nLetting $q_1'v_1 + q_2'v_2 = 0$ yields\n\\begin{gather*}\n\ty_p' = q_1v_1' + q_2v_2' \\\\\n\t\\Rightarrow y_p'' = q_1'v_1' + q_1v_1'' + q_2'v_2' + q_2v_2''\n\\end{gather*}\n\nSubstituting into\n\\[\n\ty'' + a_1 y' + a_0 y = g(x) \\\\\n\\]\nwe get\n\\begin{multline*}\n\t(q_1'v_1' + q_1v_1'' + q_2'v_2' + q_2v_2'') +\n\ta_1(q_1v_1' + q_1'v_1 + q_2v_2' + q_2'v_2) + \\\\\n\ta_0(q_1v_1 + q_2v_2) = g(x)\n\\end{multline*}\n\nWe omit the coefficient off the $y''$ term since it can always be\ndivided out and it is simpler without it.\n\nRe-aranging the above:\n\\begin{multline*}\n\tq_1(v_1'' + a_1v_1' + a_0v_1) + q_2(v_2'' + a_1v_2' + a_0v_2) \\\\\n\t+ q_1'v_1' + q_2'v_2' = g(x)\n\\end{multline*}\n\nSince $v_1$ and $v_2$ are solutions to the homogeneous differential\nequation, the first two terms are zero. This leaves:\n\\[\n\tq_1'v_1' + q_2'v_2' = g(x)\n\\]\n\nBy assumption we have $q_1'v_1 + q_2'v_2 = 0$ and so we now have two\nequations with which we can work out $q_1$ and $q_2$.\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2y}{dx^2} + \\frac{dy}{dx} - 2y = x\n\t\\]\n\n\tThe general solution of the homogeneous equation is\n\t\\[\n\t\ty_c = Ae^{-2x} + Be^x\n\t\\]\n\tSo we have $v_1 = e^{-2x}$ and $v_2 = e^x$, with $g(x) = x$.\n\n\tUsing variation of parameters, we know that\n\t$q_1'v_1' + q_2v_2' = g(x)$. We then have:\n\t\\begin{align*}\n\t\t-2 q_1' e^{-2x} + q_2' e^x = x \\\\\n\t\tq_1' e^{-2x} + q_2' e^x = 0\n\t\\end{align*}\n\n\tSolve for $q_1$:\n\t\\begin{gather*}\n\t\t-3q_1'e^{-2x} = x \\\\\n\t\t\\Rightarrow q_1' = -\\frac{1}{3} xe^{2x} \\\\\n\t\t\\int xe^{2x} = \\frac{1}{2}xe^{2x} - \\frac{1}{2} \\int e^{2x} dx \\\\\n\t\t= \\frac{1}{2}xe^{2x} - \\frac{1}{4}e^{2x} + c \\\\\n\t\t\\Rightarrow q_1 = -\\frac{1}{6}e^{2x} (x - 1/2) + c\n\t\\end{gather*}\n\n\tSolve for $q_2$:\n\t\\begin{gather*}\n\t\t3q_2'e^x = x \\\\\n\t\t\\Rightarrow q_2' = \\frac{1}{3}xe^{-x} \\\\\n\t\t\\int xe^{-x} dx = -xe_{-x} - \\int -e^{-x} dx \\\\\n\t\t= -xe^{-x} - e{-x} +c \\\\\n\t\t\\Rightarrow q_2 = -\\frac{1}{3}e^{-x}(x+1) + c\n\t\\end{gather*}\n\n\tSo our particular solution is:\n\t\\begin{align*}\n\t\ty_p &= -\\frac{x}{6} + \\frac{1}{12} + c_1e^{-2x}\n\t\t- \\frac{x}{3} - \\frac{1}{3} + c_2e^x \\\\\n\t\t&= -\\frac{x}{2} - \\frac{1}{4} + c_1e^{-2x} + c_2e^x\n\t\\end{align*}\n\n\tCombining with the homogeneous solution, we get our general solution:\n\t\\[\n\t\ty = Ae^{-2x} + Be^{x} - \\frac{x}{2} - \\frac{1}{4}\n\t\\]\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\frac{d^2y}{dx} + y = 1 + \\tan x\n\t\\]\n\n\tSince $g(x)$ is trigonometric, we choose our solution of the\n\thomogeneous in the form\n\t\\[\n\t\ty_c = A\\cos x + B\\sin x\n\t\\]\n\n\t\\begin{align*}\n\t\t-q_1'\\sin x + q_2'\\cos x &= 1 + \\tan x \\\\\n\t\tq_1'\\cos x + q_2\\sin x &= 0\n\t\\end{align*}\n\n\tSolving for $q_2$:\n\t\\begin{gather*}\n\t\t-q_1'\\sin x \\cos x + q_2'\\cos^2x = \\cos x + \\sin x \\\\\n\t\tq_1' \\sin x \\cos x + q_2'\\sin^2x = 0\\\\\n\t\t\\Rightarrow q_2' = \\cos x + \\sin x \\\\\n\t\t\\Rightarrow q_2 = \\sin x - \\cos x\n\t\\end{gather*}\n\n\tSolving for $q_1$:\n\t\\begin{gather*}\n\t\tq_1'\\sin^2x - q_2'\\cos x \\sin x = -\\sin x - \\sin x \\tan x \\\\\n\t\tq_1'\\cos^2x + q_2'\\cos x \\sin x = 0 \\\\\n\t\t\\Rightarrow q_1' = -\\sin x - \\sin x \\tan x \\\\\n\t\t\\Rightarrow q_1 = \\cos x - \\int \\sin x \\tan x dx\n\t\\end{gather*}\n\\end{ex}\n\nNote:\nIf equation is of form\n\\[\n\ty'' + a_1y' + a_0y = f(x) + p(x)\n\\]\nSolve two separate equations\n\\begin{align*}\n\ty_1'' + a_1y_1' + a_0y_1 &= f(x) \\\\\n\ty_2'' + a_1y_2' + a_0y_2 &= p(x) \\\\\n\\end{align*}\nand then $y_1 + y_2$ is a solution of the original equation.\n\n\\end{document}\n", "meta": {"hexsha": "aa8789e50cb0675b10b7a13af3853981c5ede232", "size": 26407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/vectors.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/vectors.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/vectors.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": 25.3913461538, "max_line_length": 88, "alphanum_fraction": 0.5672738289, "num_tokens": 11625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6544984095775277}}
{"text": "\\chapter{Multi-Scale Variance Stabilizing Transform on the Sphere (MS-VSTS)}\n\\label{ch_msvsts}\n\n% \\markright{Multi-Scale Variance Stabilizing Transform on the Sphere (MS-VSTS)}\n\n\\section{Principle of VST}\n\n\\subsection{VST of a Poisson process}\n\nGiven Poisson data $\\mathbf{Y} := (Y_i)_i$, each sample $Y_i \\sim \\mathcal{P} (\\lambda_i)$ has a variance $\\text{Var}[Y_i] = \\lambda_i$. Thus, the variance of $\\mathbf{Y}$ is signal-dependant. The aim of a VST $\\mathbf{ T}$ is to stabilize the data such that each coefficient of $\\mathbf{ T}(\\mathbf{Y})$ has an (asymptotically) constant variance, say $1$, irrespective of the value of $\\lambda_i$. In addition, for the VST used in this study, $T(\\mathbf{Y})$ is asymptotically normally distributed. Thus, the VST-transformed data are asymptotically stationary and gaussian.\n\nThe Anscombe transform \\citep{rest:anscombe48} is a widely used VST which has a simple square-root form\n\\begin{equation}\n\\label{eq14}\n\\mathbf{ T}(Y):=2\\sqrt{Y+3/8}.\n\\end{equation}\nWe can show that $\\mathbf{ T}(Y)$ is asymptotically normal as the intensity increases.\n\\begin{equation}\n\\label{eq15}\n\\mathbf{ T}(Y)-2\\sqrt{\\lambda} \\autorightarrow{$\\mathcal{D}$}{$\\lambda \\rightarrow + \\infty$} \\mathcal{N}(0,1)\n\\end{equation}\nIt can be shown that the Anscombe VST requires a high underlying intensity to well stabilize the data (typically for $\\lambda \\geqslant 10$) \\citep{starck:zhang07}.\n\n\\subsection{VST of a filtered Poisson process}\n\nLet $Z_j := \\sum_i h[i] Y_{j-i}$ be the filtered process obtained by convolving $(Y_i)_i$ with a discrete filter $h$. We will use $Z$ to denote any of the $Z_j$'s. Let us define $\\tau_k := \\sum_i (h[i])^k$ for $k=1,2,\\cdots$. In addition, we adopt a local homogeneity assumption stating that $\\lambda_{j-i} = \\lambda$ for all $i$ within the support of $h$.\n\nWe define the square-root transform $T$ as follows:\n\\begin{equation}\n\\label{eq16}\nT(Z):=b\\cdot \\mathrm{sign}(Z+c) |Z+c|^{1/2},\n\\end{equation}\nwhere $b$ is a normalizing factor.  \\\\\n\\emph{\\textbf{(Square root as VST)}} If $\\tau_1 \\neq 0$, $\\|h\\|_2,\\|h\\|_3<\\infty$, then we have : \\\\\n\\begin{equation} \\label{eq17}\n\\begin{split}\n\\mathrm{sign}(Z+c)\\sqrt{|Z+c|}-\\mathrm{sign}(\\tau_1)\\sqrt{|\\tau_1|\\lambda} \\\\\n \\autorightarrow{$\\mathcal{D}$}{$\\lambda \\rightarrow + \\infty$} \\mathcal{N}\\Big(0,\\frac{\\tau_2}{4|\\tau_1|}\\Big).\n\\end{split}\n\\end{equation}\nThis  proves that $T$ is a VST for a filtered Poisson process (with a nonzero-mean filter) in that $T(Y)$ is asymptotically normally distributed with a stabilized variance as $\\lambda$ becomes large (see \\citet{starck:zhang07} for a proof).\n\n\n\\section{MS-VSTS}\n\n\nThe MS-VSTS~\\citep{Schmitt} consists in combining the square-root VST with a multi-scale transform on the sphere.\n\n\\subsection{MS-VSTS + IUWT}\n\nThis section describes the MS-VSTS + IUWT, which is a combination of a square-root VST with the IUWT. The recursive scheme is:\n\\begin{equation}\n\\label{eq27}\n\\begin{split}\n&\\text{IUWT}\\left\\{\\begin{array}{ccc}a_j  & = &  h_{j-1} \\ast a_{j-1}  \\\\d_j  & = & a_{j-1}  - a_j  \\end{array}\\right. \\\\\n \\Longrightarrow & \\begin{split}\\text{MS-VSTS} \\\\  \\text{+ IUWT} \\end{split}\\left\\{\\begin{array}{ccc}a_j  & = &  h_{j-1} \\ast a_{j-1} \\\\d_j  & = & T_{j-1}(a_{j-1}) - T_j(a_j) \\end{array}\\right. .\n\\end{split}\n\\end{equation}\n\nIn (\\ref{eq27}), the filtering on $a_{j-1}$ can be rewritten as a filtering on $a_0 := \\mathbf{Y}$, i.e., $a_j = h^{(j)} \\ast a_0$, where $h^{(j)} = h_{j-1} \\ast \\cdots \\ast h_{1} \\ast h_0$ for $j \\geqslant 1$ and $h^{(0)} = \\delta$, where $\\delta$ is the Dirac pulse ($\\delta = 1$ on a single pixel and $0$ everywhere else). $T_j$ is the VST operator at scale $j$:\n\\begin{equation}\n\\label{eq28}\nT_j(a_j) = b^{(j)} \\mathrm{sign}(a_j+c^{(j)})\\sqrt{|a_j + c^{(j)}|} .\n\\end{equation}\nLet us define $\\tau_k^{(j)}:=\\sum_i (h^{(j)}[i])^k$. In~\\citet{starck:zhang07}, it has ben shown that, to have an optimal convergence rate for the VST, the constant $c^{(j)}$ associated to $h^{(j)}$ should be set to:\n\\begin{equation}\n\\label{eq29}\nc^{(j)}:=\\frac{7\\tau_2^{(j)}}{8\\tau_1^{(j)}} - \\frac{\\tau_3^{(j)}}{2\\tau_2^{(j)}} .\n\\end{equation}\nThe MS-VSTS+IUWT procedure is directly invertible as we have:\n\\begin{equation}\n\\label{eq30}\na_0 (\\theta,\\varphi) = T_0^{-1} \\Bigg[ T_J(a_J) + \\sum_{j=1}^J d_j \\Bigg] (\\theta,\\varphi).\n\\end{equation}\nSetting $b^{(j)}:=\\text{sgn}(\\tau_1^{(j)})/\\sqrt{|\\tau_1^{(j)}|}$, if $\\lambda$ is constant within the support of the filter.\n$h^{(j)}$, then we have \\citep{starck:zhang07}:\n\\begin{equation}\n\\label{eq31}\n\\begin{split}\nd_j(\\theta,\\varphi) \\autorightarrow{$\\mathcal{D}$}{$\\lambda \\rightarrow + \\infty$} \n\\mathcal{N} \\Bigg( 0 , \\frac{\\tau_2^{(j-1)}}{4\\tau_1^{(j-1)^2}} +\\\\ \\frac{\\tau_2^{(j)}}{4\\tau_1^{(j)^2}} - \\frac{\\langle h^{(j-1)},h^{(j)} \\rangle}{2\\tau_1^{(j-1)}\\tau_1^{(j)}} \\Bigg) ,\n\\end{split}\n\\end{equation}\nwhere $\\langle . , . \\rangle$ denotes inner product.\n\nIt means that the detail coefficients issued from locally homogeneous parts of the signal follow asymptotically a central normal distribution with an intensity-independant variance which relies solely on the filter $h$ and the current scale for a given filter $h$. Consequently, the stabilized variances and the constants $b^{(j)}$,$c^{(j)}$,$\\tau_k^{(j)}$ can all be pre-computed.\nLet us define $\\sigma_{(j)}^2$ the stabilized variance at scale $j$ for a locally homogeneous part of the signal:\n\\begin{equation}\n\\label{eq32}\n\\sigma_{(j)}^2 = \\frac{\\tau_2^{(j-1)}}{4\\tau_1^{(j-1)^2}} + \\frac{\\tau_2^{(j)}}{4\\tau_1^{(j)^2}} - \\frac{\\langle h^{(j-1)},h^{(j)} \\rangle}{2\\tau_1^{(j-1)}\\tau_1^{(j)}} .\n\\end{equation}\n\nTo compute the $\\sigma_{(j)}$, $b^{(j)}$,$c^{(j)}$,$\\tau_k^{(j)}$, we only have to know the filters $h^{(j)}$. We compute these filters thanks to the formula $a_j = h^{(j)} \\ast a_0$, by applying the IUWT to a Dirac pulse $a_0 = \\delta$. Then, the $h^{(j)}$ are the scaling coefficients of the IUWT. The $\\sigma_{(j)}$ have been precomputed for a 6-scaled IUWT (Table~\\ref{sigmaj}). \n\n\\begin{table*}[!h]\n  \\centering\n    \\caption{Precomputed values of the variances $\\sigma_j$ of the wavelet coefficients.\n  }\n  \\begin{tabular}{|c|c|}\n\\hline\nWavelet scale $j$ & Value of $\\sigma_j$ \\\\\n\\hline\n  1 & 0.484704 \\\\\n  2 & 0.0552595 \\\\\n  3 & 0.0236458 \\\\\n  4 & 0.0114056 \\\\\n  5 & 0.00567026 \\\\\n\\hline\n\\end{tabular}\n\n  \\label{sigmaj}\n\\end{table*}\n\nWe have simulated Poisson images of different constant intensities $\\lambda$, computed the IUWT with MS-VSTS on each image and observed the variation of the normalized value of $\\sigma_{(j)}$ ($\\mathbf{ (\\sigma_{(j)})_{\\text{simulated}}} / (\\sigma_{(j)})_{\\text{theoretical}}$) as a function of $\\lambda$ for each scale $j$ (Fig. \\ref{sigma}). We see that the wavelet coefficients are stabilized when $\\lambda \\gtrsim 0.1$ except for the first wavelet scale, which is mostly constituted of noise. On Fig. \\ref{ansc}, we compare the result of MS-VSTS with Anscombe + wavelet shrinkage, on sources of varying intensities. We see that MS-VSTS works well on sources of very low intensities, whereas Anscombe doesn't work when the intensity is too low.\n\n\\begin{figure}[htb]\n\\centering{\n\\hbox{\n%\\psfig{figure=sigma1.ps,widtht=2.9in}\n\\includegraphics[width=2.5in, height=3in]{13822fg1.pdf}\n\\includegraphics[width=2.5in, height=3in]{13822fg2.pdf}\n}\n\\hbox{\n\\includegraphics[width=2.5in, height=3in]{13822fg3.pdf}\n\\includegraphics[width=2.5in, height=3in]{13822fg4.pdf}\n}}\n\\caption{Normalized value ($\\mathbf{ (\\sigma_{(j)})_{\\text{simulated}} }/ (\\sigma_{(j)})_{\\text{theoretical}}$) of the stabilized variances at each scale $j$ as a function of $\\lambda$.}\n\\label{sigma}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centering\n\\includegraphics[width=2.5in]{13822fg6.pdf}\n\\includegraphics[width=2.5in]{13822fg7.pdf}\n\\includegraphics[width=2.5in]{13822fg8.pdf}\n\\includegraphics[width=2.5in]{13822fg9.pdf}\n\\caption{Comparison of MS-VSTS with Anscombe + wavelet shrinkage on a single HEALPix face.\n\\emph{Top Left} : Sources of varying intensity.\n\\emph{Top Right} : Sources of varying intensity with Poisson noise.\n\\emph{Bottom Left} : Poisson sources of varying intensity reconstructed with Anscombe + wavelet shrinkage.\n\\emph{Bottom Right} : Poisson sources of varying intensity reconstructed with MS-VSTS.\n}\n\\label{ansc}\n\\end{figure}\n\n\\subsection{MS-VSTS + Curvelets}\n\nAs the first step of the algorithm is an IUWT, we can stabilize each resolution level as in Equation~(\\ref{eq27}). We then apply the local ridgelet transform on each stabilized wavelet band.\n\nIt is not as straightforward as with the IUWT to derive the asymptotic noise variance in the stabilized curvelet domain. In our experiments, we derived them using simulated Poisson data of stationary intensity level $\\lambda$. After having checked that the standard deviation in the curvelet bands becomes stabilized as the intensity level increases (which means that the stabilization is working properly), we stored the standard deviation $\\sigma_{j,l}$ for each wavelet scale $j$ and each ridgelet band $l$ (Table~\\ref{tabcurv}).\n\n\\begin{table*}[!h]\n  \\centering\n   \\caption{Asymptotic values of the variances $\\sigma_{j,k}$ of the curvelet coefficients.\n  }\n  \\begin{tabular}{|c|c|c|c|c|}\n\\hline\n $j$ & $l=1$ & $l=2$ & $l=3$ & $l=4$ \\\\\n\\hline\n  1 & 1.74550 & 0.348175 & & \\\\\n  2 & 0.230621 & 0.248233 & 0.196981 & \\\\\n  3 & 0.0548140 & 0.0989918 & 0.219056 & \\\\\n  4 & 0.0212912 & 0.0417454 & 0.0875663 & 0.20375 \\\\\n  5 & 0.00989616 & 0.0158273 & 0.0352021 & 0.163248 \\\\\n\\hline\n\\end{tabular}\n \n  \\label{tabcurv}\n\\end{table*}\n", "meta": {"hexsha": "9ce0b89616d5fe9f460ef87ee804c06d7c1c6c1e", "size": 9500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/msvst_info.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_info.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_info.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": 55.8823529412, "max_line_length": 747, "alphanum_fraction": 0.6928421053, "num_tokens": 3303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6544984080968993}}
{"text": "\\chapter{(What?)}\n\n\\paragraph{Cauchy's functional equation}\n\\(f(x+y) = f(x)+f(y)\\).\n\n\\section{Unary numeral via Kleene closure}\n\n\\(\\Nat \\leftrightarrow \\{1\\}^*\\)\nwhere \\(0 \\leftrightarrow \\emptystr\\), \\(1 \\leftrightarrow 1\\), \\(2 \\leftrightarrow 11\\), \\(3 \\leftrightarrow 111\\), and so on.\n\n\\section{Order}\n\nMinimum\n\nMaximum\n\nExtremum\n\nInfimum, greatest lower bound\n\nSupremum, least upper bound\n\n\\index{argmin}%\nDefine \\(m = \\arg\\min_{x \\in X}(f~x)\\) iff \\(\\forall x \\in X : f~m \\le f~x\\).\n\n\\index{min}%\nDefine \\(\\min_{x \\in X}(f~x) = f~(\\arg\\min_{x \\in X}(f~x))\\).\n\n\\section{Lattice}\n\nMeet\n\nJoin\n\nSemilattice\n\n\\section{Limit}\n\n\\(\\lim_{n \\to \\infty} x_n\\)\n\n\\section{Metric}\n\n\\index{distance}%\n\\index{distance!between hyperplane and point}%\nLet \\(\\dist\\) stand for \\emph{distance}.\nIf \\(h\\) is a hyperplane,\nthen \\(\\dist~h~X = \\min_{x \\in X} (\\dist~h~x)\\)\nwhere \\(\\dist~h~x = |x-q|\\) where \\(q\\) is on \\(h\\) and \\(x-q\\) is parallel to \\(n\\).\n\\index{metric}%\nA \\emph{metric} is...\n\n\\section{Norm}\n\n\\index{norm}%\nA \\emph{norm} is...\n\\index{normed space}%\n\\index{space!normed}%\nA \\emph{normed space} is...\n\\index{metric space}%\n\\index{space!metric}%\nA \\emph{metric space} is...\n\\index{Euclidean space}%\n\\index{space!Euclidean}%\nAn \\emph{Euclidean space} is ...\n\\index{pre-Hilbert space}%\n\\index{space!pre-Hilbert}%\nA \\emph{pre-Hilbert space} is ...\n\\index{Hilbert space}%\n\\index{space!Hilbert}%\nA \\emph{Hilbert space} is ...\nUsually we can pretend that a Hilbert space is an infinite-dimensional Euclidean space.\n%A Hilbert space is an infinite-dimensional vector space with inner product,\n%that is also a complete metric space with respect to the distance function induced by the inner product.\n% TODO rephrase using pre-Hilbert space\n\n\\index{Banach space}%\n\\index{space!Banach}%\nA \\emph{Banach space} is a complete normed vector space.\n", "meta": {"hexsha": "225c4d32a03fe1d83d77e27e98ee083e3edcc15e", "size": 1834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/what.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/what.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/what.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": 23.2151898734, "max_line_length": 127, "alphanum_fraction": 0.6837513631, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6544984066120519}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\n\\title{Problem Set 1}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\\section{Linear Algebra}\n\t\\subsection{Problem 1}\n\tShow that if $M\\in \\mathbb{R}^{n\\times n}$ is a symmetric matrix and $d \\leq n$, then $U \\in \\mathbb{R}^{n\\times d}$ and $U^T U=I_{d\\times d}$,\n\t\\[\n\t\\max_d \\text{Tr} \\left(U^T M U\\right) = \\sum_{k=1}^{d}\\lambda_{k}^{(+)}\n\t\\]\n\twhere $\\lambda_{k}^{(+)}$ is the $k$th largest eigenvalue of $M$.\\\\\n\t\\\\\n\tSince $M$ is symmetric, we have the singular value decomposition (SVD)\n\t\\[\n\tM = U D^2 U^T\n\t\\]\n\twhere $D$ is a diagonal matrix with values corresponding to the eigenvalues of $M$, in order of magnitude. Since $U^TU = I \\Rightarrow U^T = U^{-1}$, we have\n\t\\[\n\tU^{-1}M(U^T)^{-1} = D^2\n\t\\]\n\t\\[\n\tU^TMU = D^2\n\t\\]\n\tTherefore, $\\text{Tr} \\left(U^T M U\\right) =\\text{Tr}\\left(D^2\\right) = \\sum_{k=1}^{n}\\lambda_k^{(+)}$\n\t\n\tIn order to maximize this, we can set $d$ such that $\\lambda_{d+1}^{(+)}$ is the first occurrence of a complex eigenvalue in the $\\lambda_k^{(+)}$ sequence who's magnitude is negative. If no such eigenvector exists, $d=n$.\n\t\\\\\n\t\\section{Estimators}\n\t\\subsection{Problem 2}\n\tGiven $x_1, \\dots x_n$ i.i.d samples from a distribution $X$ with mean $\\mu$ and covariance $\\Sigma$, show that\n\t\\[\n\t\\mu_n = \\frac{1}{n}\\sum_{k=1}^{n}x_k \\qquad,\\qquad \\Sigma_n = \\frac{1}{n-1}(x_k - \\mu)(x_k - \\mu)^T\n\t\\]\n\tare unbiased estimators for $\\mu$ and $\\Sigma$. (Show that $\\mathbf{E}[\\mu_n]=\\mu$ and $\\mathbf{E}[\\Sigma_n]=\\Sigma$)\\\\\n\t\\\\\n\t\\[\n\t\\mathbf{E}[\\mu_n] = \\mathbf{E}\\left[\\frac{x_1+\\dots+x_n}{n}\\right] = \n\t\\frac{\\mathbf{E}[x_1]+\\dots+\\mathbf{E}[x_n]}{n}=\n\t\\frac{n\\mu}{n}=\\mu\n\t\\]\n\t\\\\\n\t\\[\n\t\\mathbf{E}[\\Sigma_n] = \\frac{1}{n-1}\\sum_{i=1}^{n}\n\t\\mathbf{E}\\left[(x_i-\\mu_n)(x_i-\\mu_n)^T\\right]=\n\t\\frac{1}{n-1}\\sum_{i=1}^{n}\\mathbf{E}\\left[((x_i-\\mu)-(\\mu_n-\\mu))((x_i-\\mu)-(\\mu_n-\\mu))^T\\right]\n\t\\]\n\t\\[\n\t=\\frac{1}{n-1}\\sum_{i=1}^{n}\\mathbf{E}\\left[\n\t(x_i-\\mu)(x_i-\\mu)^T\\right]+\\mathbf{E}\\left[\n\t(\\mu_n-\\mu)(\\mu_n-\\mu)^T\\right]-\\mathbf{E}\\left[\n\t(x_i-\\mu)(\\mu_n-\\mu)^T\\right]-\\mathbf{E}\\left[\n\t(\\mu_n-\\mu)(x_i-\\mu)^T\\right]\n\t\\]\n\t\\[\n\t=\\frac{1}{n-1}\\sum_{i=1}^{n}\\mathbf{E}\\left[\n\t(x_i-\\mu)(x_i-\\mu)^T\\right] = \n\t\\sum_{i=1}^{n}\\mathbf{E}\\left[\n\t\\frac{(x_i-\\mu)(x_i-\\mu)^T}{n-1}\\right]=\n\t\\mathbf{E}\\left[\\sum_{i=1}^{n}\n\t\\frac{(x_i-\\mu)(x_i-\\mu)^T}{n-1}\\right]=\\Sigma\n\t\\]\n\t\\\\\n\t\\section{Random Matrices}\n\t\\subsection{Problem 3}\n\tLet $W \\in \\mathbb{R}^{n\\times n}$ be a Wigner Matrix, a symmetric random matrix whose diagonal and upper-diagonal entries are independent $W_{ii} \\sim \\mathbb{N}(0,2)$ and for $i<j$, $W_{ij} \\sim N(0,1)$. Show that the distribution of the eigenvalues of $\\frac{1}{\\sqrt{n}}W$ converge to the semi-circle law of support $[-2,2]$\n\t\\[\n\tdSC(x) = \\frac{1}{2\\pi}\\sqrt{4-x^2}1_{[-1,1]}(x)\n\t\\]\n\t\\\\\n\t\\begin{figure}[h!]\n\t\\includegraphics[]{dSC.png}\n\t\\caption{Histogram of eigenvalues for the $\\frac{1}{\\sqrt{n}}W$ ($n=500$)}\n\t\\end{figure}\n\t\\\\\n\t\\subsection{Problem 4}\n\tUse Slepian's Comparison Lemma to show that for a Wigner matrix $W\\in \\mathbb{R}^{n \\times n}$, where $W_{ij | i\\neq j} \\sim N(0,1)$ and $W_{ii} \\sim N(0,2)$.\n\t\\\\\n\t\\[\n\t\\mathbf{E}\\left[\\lambda_{max}(W)\\right] \\leq 2\\sqrt{n}\n\t\\]\n\t\\\\\n\t\\[\n\t\\lambda_{max}(W) = \\max_v v^T W v \\Rightarrow \\mathbf{E}\\left[\\lambda_{max}(W)\\right] = \\mathbf{E}\\left[\\max_v v^t W v\\right]\n\t\\]\n\t\\[\n\t\\text{Let } Y_v \\ddot{=} \\max_v v^T W v \n\t\\]\n\t\\[\n\t\\text{Define } X_v = v^Tg \\qquad g \\sim N(0,I_{n\\times n})\n\t\\]\n\tSlepian's Comparison Lemma states that for random variables $X_v$ and $Y_v$, if $\\mathbf{E}[X_v]=\\mathbf{E}[Y_v]=0$, and $\\forall v1, v2 \\in V$ s.t. $v1 \\neq v2$ $\\mathbf{E}[X_{v1}-X_{v2}]^2 \\geq \\mathbf{E}[Y_{v1}-Y_{v2}]^2$, then\n\t\\[\n\t\\mathbf{E}\\left[\\max_v Y_v\\right] \\leq \\mathbf{E}\\left[\\max_v X_v\\right]\n\t\\]\n\tSince $X_v$ and $Y_v$ are both related to Gaussians about 0, the first condition is satisfied. Monte Carlo simulation of $\\mathbf{E}[2X_{v1}-2X_{v2}]^2 - \\mathbf{E}[Y_{v1}-Y_{v2}]^2$ are shown below; clearly the value is $\\geq 0$, thus satisfying the second condition.\n\t\\begin{figure}[h!]\n\t\t\\includegraphics[scale=0.6]{subtract.png}\n\t\\end{figure}\n\tTherefore, it is sufficient to say that \\[\\mathbf{E}\\left[\\max_v Y_v\\right] \\leq \\mathbf{E}\\left[\\max_v 2X_v\\right]\\]\n\tBy Jensen's inequality, we have that\n\t\\[\n\t\\mathbf{E}\\left[\\max_v X_v\\right]^2 \\leq \\mathbf{E}\\left[\\left(\\max_v X_v\\right)^2\\right]\n\t\\]\n\t\\[\n\t\\mathbf{E}\\left[\\max_v v^Tg\\right]^2 \\leq \\mathbf{E}\\left[\\left(\\max_v v^Tg\\right)^2\\right]\n\t\\]\n\tSince $||v||_2=1$, $v^Tg$ will be maximized when each element of $v$ is equal to $\\frac{1}{\\sqrt{n}}$. Thus, $max_v v^Tg = \\frac{1}{\\sqrt{n}}\\sum_{i=1}^n g_i$. Since $g$ is standard Gaussian, $\\sum_{i=1}^{n}g \\leq n$, thus $max_v v^Tg \\leq \\sqrt{n}$. Therefore, we have \n\t\\[\n\t\\mathbf{E}\\left[\\max_v v^Tg\\right]^2 \\leq n\n\t\\]\n\t\\[\n\t\\mathbf{E}\\left[\\max_v v^Tg\\right] \\leq \\sqrt{n}\n\t\\]\n\tand finally\n\t\\[\n\t\\mathbf{E}[\\max_v Y_v] = \\mathbf{E}[\\lambda_{max}(W)] \\leq 2\\sqrt{n}\n\t\\]\n\t\\subsection{Problem 5}\n\tConsider the matrix $M = \\frac{1}{\\sqrt{n}}W + \\beta vv^T$ for $||v||_2=1$ and $W$ is a standard Gaussian Wigner Matrix. If $v=e_1$, this is a rank 1 perturbation of a Wigner matrix. Derive the limit of the largest eigenvalue.\n\t\\\\\\\\\n\tRather than performing a rigorous proof, the limit can be derived empirically by generating 500 samples of $M$, with $n$ set to a reasonably large number (1000), and $\\beta$ selected randomly each time from a uniform distribution $[0,5]$. \n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.55]{problem_5.png}\n\t\\end{figure}\n\t\n\tWe can see that when $\\beta \\leq 1$, $\\lim\\limits_{n \\rightarrow \\infty} \\lambda_{max} = 2$, and when $\\beta > 1$, $\\lim\\limits_{n \\rightarrow \\infty}\\lambda_{max} = \\beta + \\frac{1}{\\beta}$\n\t\\\\\\\\\n\t\\section{Diffusion Maps}\n\t\\subsection{Problem 6}\n\tDerive the 2-D diffusion map embedding for the $n$-node ring graph. If the eigenvalues are complex, try creating real ones using multiplicity of eigenvalues. Is it a reasonable embedding of this graph in two dimensions?\n\t\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\linewidth]{diffmap.png}\n\t\\end{figure}\n\\end{document}", "meta": {"hexsha": "c6d06f6f2b706406202becd9ded018c2bbaa8cf6", "size": 6174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/PS1/ps1.tex", "max_stars_repo_name": "markditsworth/mds", "max_stars_repo_head_hexsha": "c2fd3e946a4e661606d17e2089a6da351ace2393", "max_stars_repo_licenses": ["MIT"], "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/PS1/ps1.tex", "max_issues_repo_name": "markditsworth/mds", "max_issues_repo_head_hexsha": "c2fd3e946a4e661606d17e2089a6da351ace2393", "max_issues_repo_licenses": ["MIT"], "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/PS1/ps1.tex", "max_forks_repo_name": "markditsworth/mds", "max_forks_repo_head_hexsha": "c2fd3e946a4e661606d17e2089a6da351ace2393", "max_forks_repo_licenses": ["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.5793103448, "max_line_length": 329, "alphanum_fraction": 0.6379980564, "num_tokens": 2531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.6544984006811003}}
{"text": "% !TEX root = lectures.tex\n%!TEX encoding = UTF-8 Unicode\n%\\input{lectureheader.tex}\n\n\\section{Gravity and Central Forces}\n\\bigskip\n\n\\subsection{Gravity}\n\nThe gravitational potential energy and forces involving two masses $a$ and $b$ are\n\\begin{eqnarray}\nU_{ab}&=&-\\frac{Gm_am_b}{|\\vec{r}_a-\\vec{r}_b|},\\\\\n\\nonumber\nF_{ba}&=&-\\frac{Gm_am_b}{|\\vec{r}_a-\\vec{r}_b|^2}\\hat{r}_{ab},\\\\\n\\nonumber\n\\hat{r}_{ab}&=&\\frac{\\vec{r}_b-\\vec{r}_a}{|\\vec{r}_a-\\vec{r}_b|}.\n\\end{eqnarray}\nHere $G=6.67\\times 10^{-11}$ Nm$^2$/kg$^2$, and $F_{ba}$ is the force on $b$ due to $a$. By inspection, one can see that the force on $b$ due to $a$ and the force on $a$ due to $b$ are equal and opposite. The net potential energy for a large number of masses would be\n\\begin{equation}\nU=\\sum_{a<b}U_{ab}=\\frac{1}{2}\\sum_{a\\ne b}U_{ab}.\n\\end{equation}\nJust like electrodynamics, one can define \"fields\", which for a small additional mass $m$ are the force per mass and the additional potential energy per mass. The {\\it gravitational field} related to the force has dimensions of force per mass, or acceleration, and can be labeled $\\vec{g}(\\vec{r})$. The potential energy per mass has dimensions of energy per mass. This is analogous to the electromagnetic potential, which is the potential energy per charge, and the electric field which is the force per charge.\n\nBecause the field $\\vec{g}$ obeys the same inverse square law for a point mass as the electric field does for a point charge, the gravitational field also satisfies a version of Gauss's law,\n\\begin{equation}\n\\label{eq:GravGauss}\n\\oint d\\vec{A}\\cdot\\vec{g}=-4\\pi GM_{\\rm inside}.\n\\end{equation}\nHere, $M_{\\rm inside}$ is the net mass inside a closed area.\n\nGauss's law can be understood by considering a nozzle that sprays paint in all directions uniformly from a point source. Let $B$ be the number of gallons per minute of paint leaving the nozzle. If the nozzle is at the center of a sphere of radius $r$, the paint per square meter per minute that is deposited on some part of the sphere is \n\\begin{eqnarray}\nF(r)&=&\\frac{B}{4\\pi r^2}.\n\\end{eqnarray}\nNow, let $F$ also be assigned a direction, so that it becomes a vector pointing along the direction of the flying paint. For any surface that surrounds the nozzle, not necessarily a sphere, one can state that\n\\begin{eqnarray}\n\\label{eq:paint}\n\\oint \\vec{dA}\\cdot\\vec{F}&=&B,\n\\end{eqnarray}\nregardless of the shape of the surface. This follows because the rate at which paint is deposited on the surface should equal the rate at which it leaves the nozzle. The dot product ensures that only the component of $\\vec{F}$ into the surface contributes to the deposition of paint. Similarly, if $\\vec{F}$ is any radial inverse-square forces, that falls as $B/(4\\pi r^2)$, then one can apply Eq. (\\ref{eq:paint}). For gravitational fields, $B/(4\\pi)$ is replaced by $GM$, and one quickly ``derives'' Gauss's law for gravity, Eq. (\\ref{eq:GravGauss}).\n\n\\example\nConsider Earth to have its mass $M$ uniformly distributed in a sphere of radius $R$. Find the magnitude of the gravitational acceleration as a function of the radius $r$ in terms of the acceleration of gravity at the surface $g(R)$. Assume $r<R$, i.e. you are inside the surface.\n\n{\\bf Solution}: Take the ratio of Eq. (\\ref{eq:GravGauss}) for two radii, $R$ and $r<R$,\n\\begin{eqnarray*}\n\\frac{4\\pi r^2 g(r)}{4\\pi R^2 g(R)}&=&\\frac{4\\pi GM_{\\rm inside~r}}{4\\pi GM_{\\rm inside~R}}\\\\\n\\nonumber\n&=&\\frac{r^3}{R^3}\\\\\n\\nonumber\ng(r)&=&g(R)\\frac{r}{R}~.\n\\end{eqnarray*}\n\nThe potential energy per mass is similar conceptually to the voltage, or electric potential energy per charge, that was studied in electromagnetism, if $V\\equiv U/m$, $\\vec{g}=-\\nabla V$.\n\n\\exampleend\n\n\\subsection{Tidal Forces}\n\nConsider a spherical planet of radius $r$ a distance $D$ from another body of mass $M$. The magnitude of the force due to $M$ on an small object of mass $\\delta m$ on surface of the planet can be calculated by performing a Taylor expansion about the center of the spherical planet.\n\\begin{equation}\nF=-\\frac{GM\\delta m}{D^2}+2\\frac{GM\\delta m}{D^3}\\Delta D+\\cdots\n\\end{equation}\nIf the $z$ direction points toward the large object, $\\Delta D$ can be referred to as $z$. In the accelerating frame of an observer at the center of the planet,\n\\begin{equation}\n\\delta m\\frac{d^2 z}{dt^2}=F-\\delta ma'+{\\rm other~forces~acting~on~} \\delta m,\n\\end{equation}\nwhere $a'$ is the acceleration of the observer. Because $\\delta ma'$ equals the gravitational force on $\\delta m$ if it were located at the planet's center, one can write\n\\begin{equation}\nm\\frac{d^2z}{dt^2}=2\\frac{GM\\delta m}{D^3}z+{\\rm other~forces~acting~on~}\\delta m.\n\\end{equation}\nHere the other forces could represent the forces acting on $\\delta m$ from the spherical planet such as the gravitational force or the contact force with the surface. If $\\theta$ is the angle w.r.t. the $z$ axis, the effective force acting on $\\delta m$ is\n\\begin{equation}\nF_{\\rm eff}\\approx 2\\frac{GM\\delta m}{D^3}r\\cos\\theta\\hat{z}+{\\rm other~forces~acting~on~}\\delta m.\n\\end{equation}\nThis first force is the \"tidal\" force. It pulls objects outward from the center of the object. If the object were covered with water, it would distort the objects shape so that the shape would be elliptical, stretched out along the axis pointing toward the large mass $M$. The force is always along (either parallel or antiparallel to) the $\\hat{z}$ direction.\n\n\\begin{samepage}\n\n\\example\nConsider the Earth to be a sphere of radius $R$ covered with water, with the gravitational acceleration at the surface noted by $g$. Now assume that a distant body provides an additional constant gravitational acceleration $\\vec{a}$ pointed along the $z$ axis. Find the distortion of the radius as a function of $\\theta$. Ignore planetary rotation and assume $a<<g$.\n\n{\\bf Solution}: Because Earth would then accelerate with $a$, the field $a$ would seem invisible in the accelerating frame. A tidal force would only appear if $a$ depended on position, i.e. $\\nabla \\vec{a}\\ne 0$.\n\\end{samepage}\n\n\\example\nNow consider that the field is no longer constant, but that instead $a=-kz$ with $|kR|<<g$.\n\n{\\bf Solution}: The surface of the planet needs to be at constant potential (if the planet is not accelerating). The force per mass, $-kz$ is like a spring, and the potential per mass is $kz^2/2$. Otherwise water would move to a point of lower potential. Thus, the potential energy for a sample mass $\\delta m$ is \n\\begin{eqnarray*}\nV(R)+\\delta m gh(\\theta)-\\frac{\\delta m}{2}kr^2\\cos^2\\theta={\\rm Constant}\\\\\nV(R)+\\delta mgh(\\theta)-\\frac{\\delta m}{2}kR^2\\cos^2\\theta-\\delta m kRh(\\theta)\\cos^2\\theta-\\frac{\\delta m}{2}kh^2(\\theta)\\cos^2\\theta={\\rm Constant}.\n\\end{eqnarray*}\nHere, the potential due to the external field is $(1/2)kz^2$ so that $-\\nabla U=-kz$. One now needs to solve for $h(\\theta)$. Absorbing all the constant terms from both sides of the equation into one constant $C$, and because both $h$ and $kR$ are small, we can through away terms of order $h^2$ or $kRh$. This gives\n\\begin{eqnarray*}\ngh(\\theta)-\\frac{1}{2}kR^2\\cos^2\\theta&=&C,\\\\\nh(\\theta)&=&\\frac{C}{g}+\\frac{1}{2g}kR^2\\cos^2\\theta,\\\\\nh(\\theta)&=&\\frac{1}{2g}kR^2(\\cos^2\\theta-1/3).\n\\end{eqnarray*}\nThe term with the factor of $1/3$ replaced the constant and was chosen so that the average height of the water would be zero.\n\n\\example\nThe Sun's mass is $27\\times 10^6$ the Moon's mass, but the Sun is 390 times further away from Earth as the Sun. What is ratio of the tidal force of the Sun to that of the Moon.\n\n{\\bf Solution}: The gravitational force due to an object $M$ a distance $D$ away goes as $M/D^2$, but the tidal force is only the difference of that force over a distance $R$,\n\\[\nF_{\\rm tidal}\\propto \\frac{M}{D^3}R. \n\\]\nTherefore the ratio of force is\n\\begin{eqnarray*}\n\\frac{F_{\\rm Sun's~tidal~force}}{F_{\\rm Moon's~tidal~force}}\n&=&\\frac{M_{\\rm sun}/D_{\\rm sun}^3}{M_{\\rm moon}/D_{\\rm moon}^3}\\\\\n&=&\\frac{27\\times 10^6}{390^3}=0.46.\n\\end{eqnarray*}\nThe Moon more strongly affects tides than the Sun.\n\n\\exampleend\n\n\\subsection{Deriving Elliptical Orbits}\n\nKepler's laws state that a gravitational orbit should be an ellipse with the source of the gravitational field at one focus. Deriving this is surprisingly messy. To do this, we first use angular momentum conservation to transform the equations of motion so that it is in terms of $r$ and $\\theta$ instead of $r$ and $t$. The overall strategy is to\n\\begin{enumerate}\\itemsep=0pt\n\\item Find equations of motion for $r$ and $t$ with no angle ($\\theta$) mentioned, i.e. $d^2r/dt^2=\\cdots$. Angular momentum conservation will be used, and the equation will involve the angular momentum $L$.\n\\item Use angular momentum conservation to find an expression for $\\dot{\\theta}$ in terms of $r$.\n\\item Use the chain rule to convert the equations of motions for $r$, an expression involving $r,\\dot{r}$ and $\\ddot{r}$, to one involving $r,dr/d\\theta$ and $d^2r/d\\theta^2$. This is quitecomplicated because the expressions will also involve a substitution $u=1/r$ so that one finds an expression in terms of $u$ and $\\theta$.\n\\item Once $u(\\theta)$ is found, you need to show that this can be converted to the familiar form for an ellipse.\n\\end{enumerate}\n\nThe equations of motion give\n\\begin{eqnarray}\n\\label{eq:radialeqofmotion}\n\\frac{d}{dt}r^2&=&\\frac{d}{dt}(x^2+y^2)=2x\\dot{x}+2y\\dot{y}=2r\\dot{r},\\\\\n\\nonumber\n\\dot{r}&=&\\frac{x}{r}\\dot{x}+\\frac{y}{r}\\dot{y},\\\\\n\\nonumber\n\\ddot{r}&=&\\frac{x}{r}\\ddot{x}+\\frac{y}{r}\\ddot{y}\n+\\frac{\\dot{x}^2+\\dot{y}^2}{r}\n-\\frac{\\dot{r}^2}{r}.\n\\end{eqnarray}\nRecognizing that the numerator of the third term is the velocity squared, and that it can be written in polar coordinates, \n\\begin{equation}\nv^2=\\dot{x}^2+\\dot{y}^2=\\dot{r}^2+r^2\\dot{\\theta}^2,\n\\end{equation}\none can write $\\ddot{r}$ as\n\\begin{eqnarray}\n\\label{eq:radialeqofmotion2}\n\\ddot{r}&=&\\frac{F_x\\cos\\theta+F_y\\sin\\theta}{m}+\\frac{\\dot{r}^2+r^2\\dot{\\theta}^2}{r}-\\frac{\\dot{r}^2}{r}\\\\\n\\nonumber\n&=&\\frac{F}{m}+\\frac{r^2\\dot{\\theta}^2}{r}\\\\\n\\nonumber\nm\\ddot{r}&=&F+\\frac{L^2}{mr^3}.\n\\end{eqnarray}\nThis derivation used the fact that the force was radial, $F=F_r=F_x\\cos\\theta+F_y\\sin\\theta$, and that angular momentum is $L=mrv_{\\theta}=mr^2\\dot{\\theta}$. The term $L^2/mr^3=mv^2/r$ behaves like an additional force. Sometimes this is referred to as a centrifugal force, but it is not a force. Instead, it is the consequence of considering the motion in a rotating (and therefore accelerating) frame.\n\nNow, we switch to the particular case of an attractive inverse square force, $F=-\\alpha/r^2$, and show that the trajectory, $r(\\theta)$, is an ellipse. To do this we transform derivatives w.r.t. time to derivatives w.r.t. $\\theta$ using the chain rule combined with angular momentum conservation, $\\dot{\\theta}=L/mr^2$.\n\\begin{eqnarray}\n\\label{eq:rtotheta}\n\\dot{r}&=&\\frac{dr}{d\\theta}\\dot{\\theta}=\\frac{dr}{d\\theta}\\frac{L}{mr^2},\\\\\n\\nonumber\n\\ddot{r}&=&\\frac{d^2r}{d\\theta^2}\\dot{\\theta}^2\n+\\frac{dr}{d\\theta}\\left(\\frac{d}{dr}\\frac{L}{mr^2}\\right)\\dot{r}\\\\\n\\nonumber\n&=&\\frac{d^2r}{d\\theta^2}\\left(\\frac{L}{mr^2}\\right)^2\n-2\\frac{dr}{d\\theta}\\frac{L}{mr^3}\\dot{r}\\\\\n\\nonumber\n&=&\\frac{d^2r}{d\\theta^2}\\left(\\frac{L}{mr^2}\\right)^2\n-\\frac{2}{r}\\left(\\frac{dr}{d\\theta}\\right)^2\\left(\\frac{L}{mr^2}\\right)^2\n\\end{eqnarray}\nEquating the two expressions for $\\ddot{r}$ in Eq.s (\\ref{eq:radialeqofmotion2}) and (\\ref{eq:rtotheta}) eliminates all the derivatives w.r.t. time, and provides a differential equation with only derivatives w.r.t. $\\theta$,\n\\begin{equation}\n\\label{eq:rdotdot}\n\\frac{d^2r}{d\\theta^2}\\left(\\frac{L}{mr^2}\\right)^2\n-\\frac{2}{r}\\left(\\frac{dr}{d\\theta}\\right)^2\\left(\\frac{L}{mr^2}\\right)^2\n=\\frac{F}{m}+\\frac{L^2}{m^2r^3},\n\\end{equation}\nthat when solved yields the trajectory, i.e. $r(\\theta)$. Up to this point the expressions work for any radial force, not just forces that fall as $1/r^2$.\n\nThe trick to simplifying this differential equation for the inverse square problems is to make a substitution, $u\\equiv 1/r$, and rewrite the differential equation for $u(\\theta)$.\n\\begin{eqnarray}\nr&=&1/u,\\\\\n\\nonumber\n\\frac{dr}{d\\theta}&=&-\\frac{1}{u^2}\\frac{du}{d\\theta},\\\\\n\\nonumber\n\\frac{d^2r}{d\\theta^2}&=&\\frac{2}{u^3}\\left(\\frac{du}{d\\theta}\\right)^2-\\frac{1}{u^2}\\frac{d^2u}{d\\theta^2}.\n\\end{eqnarray}\nPlugging these expressions into Eq. (\\ref{eq:rdotdot}) gives an expression in terms of $u$, $du/d\\theta$, and $d^2u/d\\theta^2$. After some tedious algebra,\n\\begin{equation}\n\\frac{d^2u}{d\\theta^2}=-u-\\frac{F m}{L^2u^2}.\n\\end{equation}\nFor the attractive inverse square law force, $F=-\\alpha u^2$,\n\\begin{equation}\n\\frac{d^2u}{d\\theta^2}=-u+\\frac{m\\alpha}{L^2}.\n\\end{equation}\nThe solution has two arbitrary constants, $A$ and $\\theta_0$,\n\\begin{eqnarray}\n\\label{eq:Ctrajectory}\nu&=&\\frac{m\\alpha}{L^2}+A\\cos(\\theta-\\theta_0),\\\\\n\\nonumber\nr&=&\\frac{1}{(m\\alpha/L^2)+A\\cos(\\theta-\\theta_0)}.\n\\end{eqnarray}\nThe radius will be at a minimum when $\\theta=\\theta_0$ and at a maximum when $\\theta=\\theta_0+\\pi$. The constant $A$ is related to the eccentricity of the orbit. When $A=0$ the radius is a constant $r=L^2/(m\\alpha)$, and the motion is circular. If one solved the expression $mv^2/r=-\\alpha/r^2$ for a circular orbit, using the substitution $v=L/(mr)$, one would reproduce the expression $r=L^2/(m\\alpha)$.\n\nThe form describing the elliptical trajectory in Eq. (\\ref{eq:Ctrajectory}) can be identified as an ellipse with one focus being the center of the ellipse by considering the definition of an ellipse as being the points such that the sum of the two distances between the two foci are a constant. Making that distance $2D$, the distance between the two foci as $2a$, and putting one focus at the origin,\n\\begin{eqnarray}\n2D&=&r+\\sqrt{(r\\cos\\theta-2a)^2+r^2\\sin^2\\theta},\\\\\n\\nonumber\n4D^2+r^2-4Dr&=&r^2+4a^2-4ar\\cos\\theta,\\\\\n\\nonumber\nr&=&\\frac{D^2-a^2}{D+a\\cos\\theta}=\\frac{1}{D/(D^2-a^2)-a\\cos\\theta/(D^2-a^2)}.\n\\end{eqnarray}\nBy inspection, this is the same form as Eq. (\\ref{eq:Ctrajectory}) with $D/(D^2-a^2)=m\\alpha/L^2$ and $a/(D^2-a^2)=A$.\n\n\\subsection{Effective or Centrifugal Potential}\n\nThe total energy of a particle is \n\\begin{eqnarray}\nE&=&U(r)+\\frac{1}{2}mv_\\theta^2+\\frac{1}{2}m\\dot{r}^2\\\\\n\\nonumber\n&=&U(r)+\\frac{1}{2}mr^2\\dot{\\theta}^2+\\frac{1}{2}m\\dot{r}^2\\\\\n\\nonumber\n&=&U(r)+\\frac{L^2}{2mr^2}+\\frac{1}{2}m\\dot{r}^2.\n\\end{eqnarray}\nThe second term then contributes to the energy like an additional repulsive potential. The term is sometimes referred to as the \"centrifugal\" potential, even though it is actually the kinetic energy of the angular motion. Combined with $U(r)$, it is sometimes referred to as the \"effective\" potential,\n\\begin{eqnarray}\nU_{\\rm eff}(r)&=&U(r)+\\frac{L^2}{2mr^2}.\n\\end{eqnarray}\nNote that if one treats the effective potential like a real potential, one would expect to be able to generate an effective force,\n\\begin{eqnarray}\nF_{\\rm eff}&=&-\\frac{d}{dr}U(r) -\\frac{d}{dr}\\frac{L^2}{2mr^2}\\\\\n\\nonumber\n&=&F(r)+\\frac{L^2}{mr^3}=F(r)+m\\frac{v_\\perp^2}{r},\n\\end{eqnarray}\nwhich is indeed matches the form for $m\\ddot{r}$ in Eq. (\\ref{eq:radialeqofmotion2}), which included the ``centrifugal'' force.\n\n\\example\nConsider a particle of mass $m$ in a 2-dimensional harmonic oscillator with potential\n\\[\nU=\\frac{1}{2}kr^2=\\frac{1}{2}k(x^2+y^2).\n\\]\nIf the orbit has angular momentum $L$, find\\\\\na) the radius and angular velocity of the circular orbit\\\\\nb) the angular frequency of small radial perturbations\n\n{\\bf Solution}:\\\\\na) Consider the effective potential. The radius of a circular orbit is at the minimum of the potential (where the effective force is zero).\n\\begin{eqnarray*}\nU_{\\rm eff}&=&\\frac{1}{2}kr^2+\\frac{L^2}{2mr^2}\n\\end{eqnarray*}\nThe effective potential looks like that of a harmonic oscillator for large $r$, but for small $r$, the centrifugal potential repels the particle from the origin. The combination of the two potentials has a minimum for at some radius $r_{\\rm min}$.\n\\begin{eqnarray*}\n0&=&kr_{\\rm min}-\\frac{L^2}{mr_{\\rm min}^3},\\\\\nr_{\\rm min}&=&\\left(\\frac{L^2}{mk}\\right)^{1/4},\\\\\n\\dot{\\theta}&=&\\frac{L}{mr_{\\rm min}^2}=\\sqrt{k/m}.\n\\end{eqnarray*}\nFor particles at $r_{\\rm min}$ with $\\dot{r}=0$, the particle does not accelerate and $r$ stays constant, i.e. a circular orbit. The radius of the circular orbit can be adjusted by changing the angular momentum $L$.\n\nb) Now consider small vibrations about $r_{\\rm min}$. The effective spring constant is the curvature of the effective potential.\n\\begin{eqnarray*}\nk_{\\rm eff}&=&\\left.\\frac{d^2}{dr^2}U_{\\rm eff}(r)\\right|_{r=r_{\\rm min}}=k+\\frac{3L^2}{mr_{\\rm min}^4}\\\\\n&=&4k,\\\\\n\\omega&=&\\sqrt{k_{\\rm eff}/m}=2\\sqrt{k/m}=2\\dot{\\theta}.\n\\end{eqnarray*}\nHere, the second step used the result of the last step from part (a). Because the radius oscillates with twice the angular frequency, the orbit has two places where $r$ reaches a minimum in one cycle. This differs from the inverse-square force where there is one minimum in an orbit. One can show that the orbit for the harmonic oscillator is also elliptical, but in this case the center of the potential is at the center of the ellipse, not at one of the foci.\n\nThe solution is also simple to write down exactly in Cartesian coordinates. The $x$ and $y$ equations of motion separate,\n\\begin{eqnarray*}\n\\ddot{x}&=&-kx,\\\\\n\\ddot{y}&=&-ky.\n\\end{eqnarray*}\nSo the general solution can be expressed as\n\\begin{eqnarray*}\nx&=&A\\cos\\omega_0 t+B\\sin\\omega_0 t,\\\\\ny&=&C\\cos\\omega_0 t+D\\sin\\omega_0 t.\n\\end{eqnarray*}\nWith some work using double angle formulas, one can calculate\n\\begin{eqnarray*}\nr^2&=&x^2+y^2\\\\\n\\nonumber\n&=&(A^2+C^2)\\cos^2(\\omega_0t)+(B^2+D^2)\\sin^2\\omega_0t+(AB+CD)\\cos(\\omega_0t)\\sin(\\omega_0t)\\\\\n\\nonumber\n&=&\\alpha+\\beta\\cos 2\\omega_0 t+\\gamma\\sin 2\\omega_0 t,\\\\\n\\alpha&=&\\frac{A^2+B^2+C^2+D^2}{2},~~\\beta=\\frac{A^2-B^2+C^2-D^2}{2},~~\\gamma=AB+CD,\\\\\nr^2&=&\\alpha+(\\beta^2+\\gamma^2)^{1/2}\\cos(2\\omega_0 t-\\delta),~~~\\delta=\\arctan(\\gamma/\\beta),\n\\end{eqnarray*}\nand see that the radius oscillates with frequency $2\\omega_0$. The factor of two comes because the oscillation $x=A\\cos\\omega_0t$ has two maxima for $x^2$, one at $t=0$ and one a half period later.\n\n\\exampleend\n\n\\subsection{Stability of Orbits}\n\nThe effective force can be extracted from the effective potential, $U_{\\rm eff}$. Beginning from the equations of motion, Eq. (\\ref{eq:radialeqofmotion}), for $r$,\n\\begin{eqnarray}\nm\\ddot{r}&=&F+\\frac{L^2}{mr^3}\\\\\n\\nonumber\n&=&F_{\\rm eff}\\\\\n\\nonumber\n&=&-\\partial_rU_{\\rm eff},\\\\\n\\nonumber\nF_{\\rm eff}&=&-\\partial_r\\left[U(r)+(L^2/2mr^2)\\right].\n\\end{eqnarray}\nFor a circular orbit, the radius must be fixed as a function of time, so one must be at a maximum or a minimum of the effective potential. However, if one is at a maximum of the effective potential the radius will be unstable. For the attractive Coulomb force the effective potential will be dominated by the $-\\alpha/r$ term for large $r$ because the centrifugal part falls off more quickly, $\\sim 1/r^2$. At low $r$ the centrifugal piece wins and the effective potential is repulsive. Thus, the potential must have a minimum somewhere with negative potential. The circular orbits are then stable to perturbation.\n\n\\begin{figure}\n\\centerline{\\includegraphics[width=0.45\\textwidth]{figs/Veff}}\n\\caption{\\label{fig:Veff}The effective potential is sketched for two cases, a $1/r$ attractive potential and a $1/r^3$ attractive potential. The $1/r$ case has a stable minimum, whereas the circular orbit in the $1/r^3$ case is unstable. \n}\n\\end{figure}\nIf one considers a potential that falls as $1/r^3$, the situation is reversed and the point where $\\partial_rU$ disappears will be a local maximum rather than a local minimum -- see Fig. \\ref{fig:Veff}. The repulsive centrifugal piece dominates at large $r$ and the attractive Coulomb piece wins out at small $r$. The circular orbit is then at a maximum of the effective potential and the orbits are unstable. It is the clear that for potentials that fall as $r^n$, that one must have $n>-2$ for the orbits to be stable.\n\n\\example\nConsider a potential $U(r)=\\beta r$. For a particle of mass $m$ with angular momentum $L$, find the angular frequency of a circular orbit. Then find the angular frequency for small radial perturbations.\n\n{\\bf Solution}:\\\\\nFor the circular orbit you search for the position $r_{\\rm min}$ where the effective potential is minimized,\n\\begin{eqnarray*}\n\\partial_r\\left\\{\\beta r+\\frac{L^2}{2mr^2}\\right\\}&=&0,\\\\\n\\beta&=&\\frac{L^2}{mr_{\\rm min}^3},\\\\\nr_{\\rm min}&=&\\left(\\frac{L^2}{\\beta m}\\right)^{1/3},\\\\\n\\dot{\\theta}&=&\\frac{L}{mr_{\\rm min}^2}=\\frac{\\beta^{2/3}}{(mL)^{1/3}}\n\\end{eqnarray*}\nNow, we can find the angular frequency of small perturbations about the circular orbit. To do this we find the effective spring constant for the effective potential,\n\\begin{eqnarray*}\nk_{\\rm eff}&=&\\partial_r^2 \\left.U_{\\rm eff}\\right|_{r_{\\rm min}}\\\\\n&=&\\frac{3L^2}{mr_{\\rm min}^4},\\\\\n\\omega&=&\\sqrt{\\frac{k_{\\rm eff}}{m}}\\\\\n&=&\\frac{\\beta^{2/3}}{(mL)^{1/3}}\\sqrt{3}.\n\\end{eqnarray*}\nIf the two frequencies, $\\dot{\\theta}$ and $\\omega$, differ by an integer factor, the orbit's trajectory will repeat itself each time around. This is the case for the inverse-square force, $\\omega=\\dot{\\theta}$, and for the harmonic oscillator, $\\omega=2\\dot{\\theta}$. In this case, $\\omega=\\sqrt{3}\\dot{\\theta}$, and the angles at which the maxima and minima occur change with each orbit.\n \n\\exampleend\n\n\\subsection{Scattering and Cross Sections}\n\nScattering experiments don't measure entire trajectories. For elastic collisions, they measure the distribution of final scattering angles at best. Most experiments use targets thin enough so that the number of scatterings is typically zero or one. The cross section, $\\sigma$, describes the cross-sectional area for particles to scatter with an individual target atom or nucleus. Cross section measurements form the basis for MANY fields of physics. BThe cross section, and the differential cross section, encapsulates everything measurable for a collision where all that is measured is the final state, e.g. the outgoing particle had momentum $\\vec{p}_f$. y studying cross sections, one can infer information about the potential interaction between the two particles. Inferring, or constraining, the potential from the cross section is a classic {\\it inverse} problem. Collisions are either elastic or inelastic. Elastic collisions are those for which the two bodies are in the same internal state before and after the collision. If the collision excites one of the participants into a higher state, or transforms the particles into different species, or creates additional particles, the collision is inelastic. Here, we consider only elastic collisions.\n\nFor Coulomb forces, the cross section is infinite because the range of the Coulomb force is infinite, but for interactions such as the strong interaction in nuclear or particle physics, there is no long-range force and cross-sections are finite. Even for Coulomb forces, the part of the cross section that corresponds to a specific scattering angle, $d\\sigma/d\\Omega$, which is a function of the scattering angle $\\theta_s$ is still finite.\n\nIf a particle travels through a thin target, the chance the particle scatters is $P_{\\rm scatt}=\\sigma dN/dA$, where $dN/dA$ is the number of scattering centers per area the particle encounters. If the density of the target is $\\rho$ particles per volume, and if the thickness of the target is $t$, the areal density (number of target scatterers per area) is $dN/dA=\\rho t$. Because one wishes to quantify the collisions independently of the target, experimentalists measure scattering probabilities, then divide by the areal density to obtain cross-sections,\n\\begin{eqnarray}\n\\sigma=\\frac{P_{\\rm scatt}}{dN/dA}.\n\\end{eqnarray}\nInstead of merely stating that a particle collided, one can measure the probability the particle scattered by a given angle. The scattering angle $\\theta_s$ is defined so that at zero the particle is unscattered and at $\\theta_s=\\pi$ the particle is scattered directly backward. Scattering angles are often described in the center-of-mass frame, but that is a detail we will neglect for this first discussion, where we will consider the scattering of particles moving classically under the influence of fixed potentials $U(\\vec{r})$. Because the distribution of scattering angles can be measured, one expresses the differential cross section,\n\\begin{equation}\n\\frac{d^2\\sigma}{d\\cos\\theta_s~d\\phi}.\n\\end{equation}\nUsually, the literatures expresses differential cross sections as\n\\begin{equation}\nd\\sigma/d\\Omega=\\frac{d\\sigma}{d\\cos\\theta d\\phi}=\\frac{1}{2\\pi}\\frac{d\\sigma}{d\\cos\\theta},\n\\end{equation}\nwhere the last equivalency is true when the scattering does not depend on the azimuthal angle $\\phi$, as is the case for spherically symmetric potentials. \n\nThe differential solid angle $d\\Omega$ can be thought of as the area subtended by a measurement, $dA_d$, divided by $r^2$, where $r$ is the distance to the detector,\n\\begin{eqnarray}\ndA_d=r^2 d\\Omega.\n\\end{eqnarray}\nWith this definition $d\\sigma/d\\Omega$ is independent of the distance from which one places the detector, or the size of the detector (as long as it is small).\n\nDifferential scattering cross sections are calculated by assuming a random distribution of impact parameters $b$. These represent the distance in the $xy$ plane for particles moving in the $z$ direction relative to the scattering center. An impact parameter $b=0$ refers to being aimed directly at the target's center. The impact parameter describes the transverse distance from the $z=0$ axis for the trajectory when it is still far away from the scattering center and has not yet passed it. The differential cross section can be expressed in terms of the impact parameter,\n\\begin{equation}\nd\\sigma=2\\pi bdb,\n\\end{equation}\nwhich is the area of a thin ring of radius $b$ and thickness $db$. In classical physics, one can calculate the trajectory given the incoming kinetic energy $E$ and the impact parameter if one knows the mass and potential. From the trajectory, one then finds the scattering angle $\\theta_s(b)$. The differential cross section is then\n\\begin{equation}\n\\frac{d\\sigma}{d\\Omega}=\\frac{1}{2\\pi}\\frac{d\\sigma}{d\\cos\\theta_s}=b\\frac{db}{d\\cos\\theta_s}=\\frac{b}{(d/db)\\cos\\theta_s(b)}.\n\\end{equation}\nTypically, one would calculate $\\cos\\theta_s$ and $(d/db)\\cos\\theta_s$ as functions of $b$. This is sufficient to plot the differential cross section as a function of $\\theta_s$.\n\nThe total cross section is \n\\begin{equation}\n\\sigma_{\\rm tot}=\\int d\\Omega\\frac{d\\sigma}{d\\Omega}=2\\pi\\int d\\cos\\theta_s~\\frac{d\\sigma}{d\\Omega}. \n\\end{equation}\nEven if the total cross section is infinite, e.g. Coulomb forces, one can still have a finite differential cross section as we will see later on.\n\n\\example\nAn asteroid of mass $m$ and kinetic energy $E$ approaches a planet of radius $R$ and mass $M$. What is the cross section for the asteroid to impact the planet?\n\n{\\bf Solution}:\\\\\nCalculate the maximum impact parameter, $b_{\\rm max}$, for which the asteroid will hit the planet. The total cross  section for impact is $\\sigma_{\\rm impact}=\\pi b_{\\rm max}^2$. The maximum cross-section can be found with the help of angular momentum conservation. The asteroid's incoming momentum is $p_0=\\sqrt{2mE}$ and the angular momentum is $L=p_0b$. If the asteroid just grazes the planet, it is moving with zero radial kinetic energy at impact. Combining energy and angular momentum conservation and having $p_f$ refer to the momentum of the asteroid at a distance $R$,\n\\begin{eqnarray*}\n\\frac{p_f^2}{2m}-\\frac{GMm}{R}&=&E,\\\\\np_fR&=&p_0b_{\\rm max},\n\\end{eqnarray*}\nallows one to solve for $b_{\\rm max}$,\n\\begin{eqnarray*}\nb_{\\rm max}&=&R\\frac{p_f}{p_0}\\\\\n&=&R\\frac{\\sqrt{2m(E+GMm/R)}}{\\sqrt{2mE}}\\\\\n\\sigma_{\\rm impact}&=&\\pi R^2\\frac{E+GMm/R}{E}.\n\\end{eqnarray*}\n\\exampleend\n\n\\subsection{Center-of-Mass Coordinates}\n\nThus far, we have considered the trajectory as if the force is centered around a fixed point. For two bodies interacting only with one another, both masses circulate around the center of mass. One might think that solutions would become more complex when both particles move, but we will see here that the problem can be reduced to one with a single body moving according to a fixed force by expressing the trajectories for $\\vec{r}_1$ and $\\vec{r}_2$ into the center-of-mass coordinate $\\vec{R}_{\\rm cm}$ and the relative coordinate $\\vec{r}$,\n\\begin{eqnarray}\n\\vec{R}_{\\rm cm}&\\equiv&\\frac{m_1\\vec{r}_1+m_2\\vec{r}_2}{m_1+m_2},\\\\\n\\nonumber\n\\vec{r}&\\equiv&\\vec{r}_1-\\vec{r_2}.\n\\end{eqnarray}\nHere, we assume the two particles interact only with one another, so $\\vec{F}_{12}=-\\vec{F}_{21}$ (where $\\vec{F}_{ij}$ is the force on $i$ due to $j$. The equations of motion then become\n\\begin{eqnarray}\n\\ddot{\\vec{R}}_{\\rm cm}&=&\\frac{1}{m_1+m_2}\\left\\{m_1\\ddot{\\vec{r}}_1+m_2\\ddot{\\vec{r}}_2\\right\\}\\\\\n\\nonumber\n&=&\\frac{1}{m_1+m_2}\\left\\{\\vec{F}_{12}+\\vec{F}_{21}\\right\\}=0.\\\\\n\\ddot{\\vec{r}}&=&\\ddot{\\vec{r}}_1-\\ddot{\\vec{r}}_2=\\left(\\frac{\\vec{F}_{12}}{m_1}-\\frac{\\vec{F}_{21}}{m_2}\\right)\\\\\n\\nonumber\n&=&\\left(\\frac{1}{m_1}+\\frac{1}{m_2}\\right)\\vec{F}_{12}.\n\\end{eqnarray}\nThe first expression simply states that the center of mass coordinate $\\vec{R}_{\\rm cm}$ moves at a fixed velocity. The second expression can be rewritten in terms of the reduced mass $\\mu$.\n\\begin{eqnarray}\n\\mu \\ddot{\\vec{r}}&=&\\vec{F}_{12},\\\\\n\\frac{1}{\\mu}&=&\\frac{1}{m_1}+\\frac{1}{m_2},~~~~\\mu=\\frac{m_1m_2}{m_1+m_2}.\n\\end{eqnarray}\nThus, one can treat the trajectory as a one-body problem where the reduced mass is $\\mu$, and a second trivial problem for the center of mass. The reduced mass is especially convenient when one is considering gravitational problems because then\n\\begin{eqnarray}\n\\mu \\ddot{r}&=&-\\frac{Gm_1m_2}{r^2}\\hat{r}\\\\\n\\nonumber\n&=&-\\frac{GM\\mu}{r^2}\\hat{r},~~~M\\equiv m_1+m_2.\n\\end{eqnarray}\nFor the gravitational problem, the reduced mass then falls out and the trajectory depends only on the total mass $M$.\n\nThe kinetic energy and momenta also have analogues in center-of-mass coordinates. The total and relative momenta are\n\\begin{eqnarray}\n\\vec{P}&\\equiv&\\vec{p}_1+\\vec{p}_2=M\\dot{\\vec{R}}_{\\rm cm},\\\\\n\\nonumber\n\\vec{q}&\\equiv&\\mu\\dot{\\vec{r}}.\n\\end{eqnarray}\nWith these definitions, a little algebra shows that the kinetic energy becomes\n\\begin{eqnarray}\nT&=&\\frac{1}{2}m_1|\\vec{v}_1|^2+\\frac{1}{2}m_2|\\vec{v}_2|^2\\\\\n\\nonumber\n&=&\\frac{1}{2}M|\\dot{\\vec{R}}_{\\rm cm}|^2\n+\\frac{1}{2}\\mu|\\dot{\\vec{r}}|^2\\\\\n\\nonumber\n&=&\\frac{P^2}{2M}+\\frac{q^2}{2\\mu}.\n\\end{eqnarray}\nThe standard strategy is to transform into the center of mass frame, then treat the problem as one of a single particle of mass $\\mu$ undergoing a force $\\vec{F}_{12}$. Scattering angles can also be expressed in this frame, then transformed into the lab frame. In practice, one sees examples in the literature where $d\\sigma/d\\Omega$ expressed in both the ``center-of-mass'' and in the ``laboratory'' frame. \n\n\\subsection{Rutherford Scattering}\n\nThis refers to the calculation of $d\\sigma/d\\Omega$ due to an inverse square force, $F_{12}=\\pm\\alpha/r^2$ for repulsive/attractive interaction. Rutherford compared the scattering of $\\alpha$ particles ($^4$He nuclei) off of a nucleus and found the scattering angle at which the formula began to fail. This corresponded to the impact parameter for which the trajectories would strike the nucleus. This provided the first measure of the size of the atomic nucleus. At the time, the distribution of the positive charge (the protons) was considered to be just as spread out amongst the atomic volume as the electrons. After Rutherford's experiment, it was clear that the radius of the nucleus tended to be roughly 4 orders of magnitude smaller than that of the atom, which is less than the size of a football relative to Spartan Stadium.\n\n\\begin{figure}[!htb]\n\\centerline{\\includegraphics[width=0.6\\textwidth]{figs/rutherford}}\n\\caption{\\label{fig:rutherford}\nThe incoming and outgoing angles of the trajectory are at $\\pm\\theta'$. They are related to the scattering angle by $2\\theta'=\\pi+\\theta_s$.}\n\\end{figure}\nIn order to calculate differential cross section, we must find how the impact parameter is related to the scattering angle. This requires analysis of the trajectory. We consider our previous expression for the trajectory where we derived the elliptic form for the trajectory, Eq. (\\ref{eq:Ctrajectory}). For that case we considered an attractive force with the particle's energy being negative, i.e. it was bound. However, the same form will work for positive energy, and repulsive forces can be considered by simple flipping the sign of $\\alpha$. For positive energies, the trajectories will be hyperbolas, rather than ellipses, with the asymptotes of the trajectories representing the directions of the incoming and outgoing tracks. Rewriting Eq. (\\ref{eq:Ctrajectory}),\n\\begin{equation}\\label{eq:ruthtraj}\nr=\\frac{1}{\\frac{m\\alpha}{L^2}+A\\cos\\theta}.\n\\end{equation}\nOnce $A$ is large enough, which will happen when the energy is positive, the denominator will become negative for a range of $\\theta$. This is because the scattered particle will never reach certain angles. The asymptotic angles $\\theta'$ are those for which the denominator goes to zero,\n\\begin{equation}\n\\cos\\theta'=-\\frac{m\\alpha}{AL^2}.\n\\end{equation}\nThe trajectory's point of closest approach is at $\\theta=0$ and the two angles $\\theta'$, which have this value of $\\cos\\theta'$, are the angles of the incoming and outgoing particles. From Fig. \\ref{fig:rutherford}, one can see that the scattering angle $\\theta_s$ is given by,\n\\begin{eqnarray}\n\\label{eq:sthetover2}\n2\\theta'-\\pi&=&\\theta_s,~~~\\theta'=\\frac{\\pi}{2}+\\frac{\\theta_s}{2},\\\\\n\\nonumber\n\\sin(\\theta_s/2)&=&-\\cos\\theta'\\\\\n\\nonumber\n&=&\\frac{m\\alpha}{AL^2}.\n\\end{eqnarray}\nNow that we have $\\theta_s$ in terms of $m,\\alpha,L$ and $A$, we wish to re-express $L$ and $A$ in terms of the impact parameter $b$ and the energy $E$. This will set us up to calculate the differential cross section, which requires knowing $db/d\\theta_s$. It is easy to write the angular momentum as\n\\begin{equation}\nL^2=p_0^2b^2=2mEb^2.\n\\end{equation}\nFinding $A$ is more complicated. To accomplish this we realize that the point of closest approach occurs at $\\theta=0$, so from Eq. (\\ref{eq:ruthtraj})\n\\begin{eqnarray}\n\\label{eq:rminofA}\n\\frac{1}{r_{\\rm min}}&=&\\frac{m\\alpha}{L^2}+A,\\\\\n\\nonumber\nA&=&\\frac{1}{r_{\\rm min}}-\\frac{m\\alpha}{L^2}.\n\\end{eqnarray}\nNext, $r_{\\rm min}$ can be found in terms of the energy because at the point of closest approach the kinetic energy is due purely to the motion perpendicular to $\\hat{r}$ and \n\\begin{equation}\nE=-\\frac{\\alpha}{r_{\\rm min}}+\\frac{L^2}{2mr_{\\rm min}^2}.\n\\end{equation}\nOne can solve the quadratic equation for $1/r_{\\rm min}$,\n\\begin{equation}\n\\frac{1}{r_{\\rm min}}=\\frac{m\\alpha}{L^2}+\\sqrt{(m\\alpha/L^2)^2+2mE/L^2}.\n\\end{equation}\nWe can plug the expression for $r_{\\rm min}$ into the expression for $A$, Eq. (\\ref{eq:rminofA}),\n\\begin{equation}\nA=\\sqrt{(m\\alpha/L^2)^2+2mE/L^2}=\\sqrt{(\\alpha^2/(4E^2b^4)+1/b^2}\n\\end{equation}\nFinally, we insert the expression for $A$ into that for the scattering angle, Eq. (\\ref{eq:sthetover2}),\n\\begin{eqnarray}\n\\label{eq:scattangle}\n\\sin(\\theta_s/2)&=&\\frac{m\\alpha}{AL^2}\\\\\n\\nonumber\n&=&\\frac{a}{\\sqrt{a^2+b^2}}, ~~a\\equiv \\frac{\\alpha}{2E}\n\\end{eqnarray}\nThe differential cross section can now be found by differentiating the expression for $\\theta_s$ with $b$,\n\\begin{eqnarray}\n\\label{eq:rutherford}\n\\frac{1}{2}\\cos(\\theta_s/2)d\\theta_s&=&\\frac{ab~db}{(a^2+b^2)^{3/2}}=\\frac{bdb}{a^2}\\sin^3(\\theta_s/2),\\\\\n\\nonumber\nd\\sigma&=&2\\pi bdb=\\frac{\\pi a^2}{\\sin^3(\\theta_s/2)}\\cos(\\theta_s/2)d\\theta_s\\\\\n\\nonumber\n&=&\\frac{\\pi a^2}{2\\sin^4(\\theta_s/2)}\\sin\\theta_s d\\theta_s\\\\\n\\nonumber\n\\frac{d\\sigma}{d\\cos\\theta_s}&=&\\frac{\\pi a^2}{2\\sin^4(\\theta_s/2)},\\\\\n\\nonumber\n\\frac{d\\sigma}{d\\Omega}&=&\\frac{a^2}{4\\sin^4(\\theta_s/2)}.\n\\end{eqnarray}\nwhere $a= \\alpha/2E$. This the Rutherford formula for the differential cross section. It diverges as $\\theta_s\\rightarrow 0$ because scatterings with arbitrarily large impact parameters still scatter to arbitrarily small scattering angles. The expression for $d\\sigma/d\\Omega$ is the same whether the interaction is positive or negative. \n\n\\example\nConsider a particle of mass $m$ and charge $z$ with kinetic energy $E$ (Let it be the center-of-mass energy) incident on a heavy nucleus of mass $M$ and charge $Z$ and radius $R$. Find the angle at which the Rutherford scattering formula breaks down.\n\n{\\bf Solution}:\\\\\nLet $\\alpha=Zze^2/(4\\pi\\epsilon_0)$. The scattering angle in Eq. (\\ref{eq:scattangle}) is \n\\[\n\\sin(\\theta_s/2)=\\frac{a}{\\sqrt{a^2+b^2}}, ~~a\\equiv \\frac{\\alpha}{2E}.\n\\]\nThe impact parameter $b$ for which the point of closest approach equals $R$ can be found by using angular momentum conservation,\n\\begin{eqnarray*}\np_0b&=&b\\sqrt{2mE}=Rp_f=R\\sqrt{2m(E-\\alpha/R)},\\\\\nb&=&R\\frac{\\sqrt{2m(E-\\alpha/R)}}{\\sqrt{2mE}}\\\\\n&=&R\\sqrt{1-\\frac{\\alpha}{ER}}.\n\\end{eqnarray*}\nPutting these together\n\\[\n\\theta_s=2\\sin^{-1}\\left\\{\n\\frac{a}{\\sqrt{a^2+R^2(1-\\alpha/(RE))}}\n\\right\\},~~~a=\\frac{\\alpha}{2E}.\n\\]\nIt was from this departure of the experimentally measured $d\\sigma/d\\Omega$ from the Rutherford formula that allowed Rutherford to infer the radius of the gold nucleus, $R$.\n\n\\exampleend\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n\n\\item Approximate Earth as a solid sphere of uniform density and radius $R=6360$ km. Suppose you drill a tunnel from the north pole directly to another point on the surface described by a polar angle $\\theta$ relative to the north pole. Drop a mass into the hole and let it slide through tunnel without friction. Find the frequency $f$ with which the mass oscillates back and forth. Ignore Earth's rotation. Compare this to the frequency of a low-lying circular orbit.\n\n\\item Consider the gravitational field of the moon acting on the Earth.\n\\begin{enumerate}\n\\item Calculate the term $k$ in the expansion\n\\[\ng_{\\rm moon}=g_0+kz+\\cdots,\n\\]\nwhere $z$ is measured relative to Earth's center and is measured along the axis connecting the Earth and moon. Give your answer in terms of the distance between the moon and the earth, $R_{m}$ and the mass of the moon $M_m$. \n\\item Calculate the difference between the height of the oceans at maximum and minimum tides. Express your answer in terms of the quantities above, plus Earth's radius, $R_e$. Then give you answer in meters.\n\\end{enumerate}\n\n\\item Consider an ellipse defined by the sum of the distances from the two foci being $2D$, which expressed in a Cartesian coordinates with the middle of the ellipse being at the origin becomes\n\\[\n\\sqrt{(x-a)^2+y^2}+\\sqrt{(x+a)^2+y^2}=2D.\n\\]\nHere the two foci are at $(a,0)$ and $(-a,0)$. Show that this form is can be written as\n\\[\n\\frac{x^2}{D^2}+\\frac{y^2}{D^2-a^2}=1.\n\\]\n\n\\item Consider a particle in an attractive inverse-square potential, $U(r)=-\\alpha/r$, where the point of closest approach is $r_{\\rm min}$ and the total energy of the particle is $E$. Find the parameter $A$ describing the trajectory in Eq. (\\ref{eq:Ctrajectory}). Hint: Use the fact that at $r_{\\rm min}$ there is no radial kinetic energy and $E=-\\alpha/r_{\\rm min}+L^2/2mr_{\\rm min}^2$.\n\n\\item Consider the effective potential for an attractive inverse-square-law force, $F=-\\alpha/r^2$. Consider a particle of mass $m$ with angular momentum $L$.\n\\begin{enumerate}\n\\item Find the radius of a circular orbit by solving for the position of the minimum of the effective potential. \n\\item What is the angular frequency, $\\dot{\\theta}$, of the orbit? Solve this by setting $F=m\\dot{\\theta}^2r$.\n\\item Find the effective spring constant for the particle at the minimum.\n\\item What is the angular frequency for small vibrations about the minimum? How does this compare with the answer to (b)?\n\\end{enumerate}\n\n\\item Consider a particle of mass $m$ moving in a potential\n\\[\nU=\\alpha\\ln(r/a).\n\\]\n\\begin{enumerate}\n\\item If the particle is moving in a circular orbit of radius $R$, find the angular frequency $\\dot{\\theta}$. Solve this by setting $F=-m\\dot{\\theta}^2r$ (force and acceleration point inward).\n\\item Express the angular momentum $L$ in terms of $\\alpha$, $m$ and $R$. Also express $R$ in terms of $L$, $\\alpha$ and $m$.\n\\item Sketch the effective radial potential, $V_{\\rm eff}(r)$, for a particle with angular momentum $L$. (No longer necessarily moving in a circular orbit.)\n\\item Find the position of the minimum of $V_{\\rm eff}$ in terms of $L$, $\\alpha$ and $m$, then compare to the result of (b).\n\\item What is the effective spring constant for a particle at the minimum of $V_{\\rm eff}$? Express your answer in terms of $L$, $m$ and $\\alpha$. \n\\item What is the angular frequency, $\\omega$, for small oscillations of $r$ about the $R_{\\rm min}$?  Express your answer in terms of $\\dot{\\theta}$ from part (a).\n\\end{enumerate}\n\n\\item Consider a particle of mass $m$ in an attractive potential, $U(r)=-\\alpha/r$, with angular momentum $L$ with just the right energy so that\n\\[\nA=m\\alpha/L^2\n\\]\nwhere $A$ comes from the expression\n\\[\nr=\\frac{1}{(m\\alpha/L^2)+A\\cos\\theta}.\n\\]\nThe trajectory can then be rewritten as\n\\[\nr=\\frac{2r_0}{1+\\cos\\theta},~~~r_0=\\frac{L^2}{2m\\alpha}.\n\\]\n\\begin{enumerate}\n\\item Show that for this case the total energy $E$ approaches zero.\n\\item Write this trajectory in a more recognizable parabolic form,\n\\[\nx=x_0-\\frac{y^2}{R}.\n\\]\nI.e., express $x_0$ and $R$ in terms of $r_0$.\n\\item Explain how a particle with zero energy can have its trajectory not go through the origin.\n\\item What is the scattering angle for this trajectory?\n\\end{enumerate}\n\n\\item Show that if one transforms to a reference frame where the total momentum is zero, $\\vec{p}_1=-\\vec{p}_2$, that the relative momentum $\\vec{q}$ corresponds to either $\\vec{p}_1$ or $-\\vec{p}_2$. This means that in this frame the magnitude of $\\vec{q}$ is one half the magnitude of $\\vec{p}_1-\\vec{p}_2$.\n\n\\item Given the center of mass coordinates $\\vec{R}$ and $\\vec{r}$ for particles of mass $m_1$ and $m_2$, find the coordinates $\\vec{r}_1$ and $\\vec{r}_2$ in terms of the masses, $\\vec{R}$ and $\\vec{r}$.\n\n\\item Consider two particles of identical mass scattering at an angle $\\theta_{\\rm cm}$ in the center of mass.\n\\begin{enumerate}\n\\item In a frame where one is the target (initially at rest) and one is the projectile, find the scattering angle in the lab frame, $\\theta$, in terms of $\\theta_{\\rm cm}$.\n\\item Express $d\\sigma/d\\cos\\theta$ in terms of $d\\sigma/d\\cos\\theta_{\\rm cm}$. I.e., find the Jacobian, $d\\cos\\theta_{\\rm cm}/d\\cos\\theta$.\n\\end{enumerate}\n\n\\item Assume you are scattering alpha particles (He-4 nuclei $Z=2, A=4$) off of a gold target ($Z=79, A=197$). If the radius of the nucleus is $7.5\\times 10^{-15}$ meters, and if the energy of the beam is 38 MeV,\n\\begin{enumerate}\n\\item What is the total cross section for having a nuclear collision? Give the answer in millibarns, 1 mb$=10^{-31}$ m$^2$.\n\\item Find the scattering angle (in degrees) at which the Rutherford differential cross section formula breaks down?\n\n\\end{enumerate}\n\\end{enumerate}\n%\\end{document}\n", "meta": {"hexsha": "045377a908f9bc889e3d6c18e177e5429588ff80", "size": 43229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/AdminBackground/lectures/chapter4.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/chapter4.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/chapter4.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": 69.5, "max_line_length": 1257, "alphanum_fraction": 0.7274514793, "num_tokens": 13307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6544983947501484}}
{"text": "\\chapter{Glossary of notations}\n\\section{General}\n\\begin{itemize}\n\t\\ii $\\forall$: for all\n\t\\ii $\\exists$: there exists\n\t\\ii $\\sign(\\sigma)$: sign of permutation $\\sigma$\n\t\\ii $X \\implies Y$: $X$ implies $Y$\n\\end{itemize}\n\\section{Functions and sets}\n\\begin{itemize}\n\t\\ii $f\\im(S)$ is the image of $f : X \\to Y$ for $S \\subseteq X$.\n\t\\ii $f\\inv(y)$ is the inverse for $f : X \\to Y$ when $y \\in Y$.\n\t\\ii $f\\pre(T)$ is the pre-image for $f : X \\to Y$ when $T \\subseteq Y$.\n\t\\ii $f \\restrict{S}$ is the restriction of $f : X \\to Y$ to $S \\subseteq X$.\n\t\\ii $f^n$ is the function $f$ applied $n$ times\n\\end{itemize}\n\nBelow are some common sets.\nThese may also be thought of as groups,\nrings, fields etc.\\ in the obvious way.\n\\begin{itemize}\n\t\\ii $\\CC$: set of complex numbers\n\t\\ii $\\RR$: set of real numbers\n\t\\ii $\\NN$: set of positive integers\n\t\\ii $\\QQ$: set of rational numbers\n\t\\ii $\\ZZ$: set of integers\n\t\\ii $\\varnothing$: empty set\n\\end{itemize}\n\nSome common notation with sets:\n\\begin{itemize}\n\t\\ii $A \\subset B$: $A$ is any subset of $B$\n\t\\ii $A \\subseteq B$: $A$ is any subset of $B$\n\t\\ii $A \\subsetneq B$: $A$ is a \\emph{proper} subset of $B$\n\t\\ii $S \\times T$: Cartesian product of sets $S$ and $T$\n\t\\ii $S \\setminus T$: difference of sets $S$ and $T$\n\t\\ii $S \\cup T$: set union of $S$ and $T$\n\t\\ii $S \\cap T$: set intersection of $S$ and $T$\n\t\\ii $S \\sqcup T$: disjoint union of $S$ and $T$\n\t\\ii $\\left\\lvert S \\right\\rvert$: cardinality of $S$\n\t\\ii $S / {\\sim}$: if $\\sim$ is an equivalence relation on $S$,\n\tthis is the set of equivalence classes\n\t\\ii $x + S$: denotes the set $\\{x+s \\mid s \\in S\\}$.\n\t\\ii $xS$: denotes the set $\\{xs \\mid s \\in S\\}$.\n\\end{itemize}\n\n\\section{Abstract and linear algebra}\nSome common groups/rings/fields:\n\\begin{itemize}\n\t\\ii $\\Zc n$: cyclic group of order $n$\n\t\\ii $\\Zm n$: set of units of $\\Zc n$.\n\t\\ii $S_n$: symmetric group on $\\{1, \\dots, n\\}$\n\t\\ii $D_{2n}$: dihedral group of order $2n$.\n\t\\ii $0$, $1$: trivial group (depending on context)\n\t\\ii $\\FF_p$: integers modulo $p$\n\\end{itemize}\nNotation with groups:\n\\begin{itemize}\n\t\\ii $1_G$: identity element of the group $G$\n\t\\ii $N \\normalin G$: subgroup $N$ is normal in $G$.\n\t\\ii $G/N$: quotient group of $G$ by the normal subgroup $N$\n\t\\ii $Z(G)$: center of group $G$\n\t\\ii $N_G(H)$: normalizer of the subgroup $H$ of $G$\n\t\\ii $G \\times H$: product group of $G$ and $H$\n\t\\ii $G \\oplus H$: also product group,\n\tbut often used when $G$ and $H$ are abelian\n\t(and hence we can think of them as $\\ZZ$-modules)\n\t\\ii $\\Stab_G(x)$: the stabilizer of $x \\in X$, if $X$ is acted on by $G$\n\t\\ii $\\FixPt g$, the set of fixed points by $g \\in G$ (under a group action)\n\\end{itemize}\nNotation with rings:\n\\begin{itemize}\n\t\\ii $R/I$: quotient of ring $R$ by ideal $I$\n\t\\ii $(a_1, \\dots, a_n)$: ideal generated by the $a_i$\n\t\\ii $R^\\times$: the group of units of $R$\n\t\\ii $R[x_1, \\dots, x_n]$: polynomial ring in $x_i$,\n\tor ring obtained by adjoining the $x_i$ to $R$\n\t\\ii $F(x_1, \\dots, x_n)$: field obtained by adjoining $x_i$ to $F$\n\t\\ii $R^d$: $d$th graded part of a graded (pseudo)ring $R$\n\\end{itemize}\nLinear algebra:\n\\begin{itemize}\n\t\\ii $\\id$: the identity matrix\n\t\\ii $V \\oplus W$: direct sum\n\t\\ii $V^{\\oplus n}$: direct sum of $V$, $n$ times\n\t\\ii $V \\otimes W$: tensor product\n\t\\ii $V^{\\otimes n}$: tensor product of $V$, $n$ times\n\t\\ii $V^\\vee$: dual space\n\t\\ii $T^\\vee$: dual map (for $T$ a vector space)\n\t\\ii $T^\\dagger$: conjugate transpose (for $T$ a vector space)\n\t\\ii $\\left< -,-\\right>$: a bilinear form\n\t\\ii $\\Mat(V)$: endomorphisms of $V$, i.e.\\ $\\Hom_k(V,V)$\n\t\\ii $\\ee_1$, \\dots, $\\ee_n$: the ``standard basis'' of $k^{\\oplus n}$\n\\end{itemize}\n\\section{Quantum computation}\n\\begin{itemize}\n\t\\ii $\\ket{\\psi}$: a vector in some vector space $H$\n\t\\ii $\\bra{\\psi}$: a vector in some vector space $H^\\vee$, dual to $\\ket{\\psi}$.\n\t\\ii $\\braket{\\phi|\\psi}$: evaluation of an element $\\bra{\\phi} \\in H^\\vee$ at $\\ket{\\phi} \\in H$.\n\t\\ii $\\zup$, $\\zdown$: spin $z$-up, spin $z$-down\n\t\\ii $\\xup$, $\\xdown$: spin $x$-up, spin $x$-down\n\t\\ii $\\yup$, $\\ydown$: spin $y$-up, spin $y$-down\n\\end{itemize}\n\n\\section{Topology and real/complex analysis}\nCommon topological spaces:\n\\begin{itemize}\n\t\\ii $S^1$: the unit circle\n\t\\ii $S^n$: surface of an $n$-sphere (in $\\RR^{n+1}$)\n\t\\ii $D^{n+1}$: closed $n+1$ dimensional ball (in $\\RR^{n+1}$)\n\t\\ii $\\RP^n$: real projective $n$-space\n\t\\ii $\\CP^n$: complex projective $n$-space\n\\end{itemize}\nSome topological notation:\n\\begin{itemize}\n\t\\ii $\\partial Y$: boundary of a set $Y$ (in some topological space)\n\t\\ii $X/S$: quotient topology of $X$ by $S \\subseteq X$\n\t\\ii $X \\times Y$: product topology of spaces $X$ and $Y$\n\t\\ii $X \\amalg Y$: disjoint union of spaces $X$ and $Y$\n\t\\ii $X \\vee Y$: wedge product of (pointed) spaces $X$ and $Y$\n\\end{itemize}\nReal analysis (calculus 101):\n\\begin{itemize}\n\t\\ii $\\liminf$: limit infimum\n\t\\ii $\\limsup$: limit supremum\n\t\\ii $\\inf$: infimum\n\t\\ii $\\sup$: supremum\n\t\\ii $\\ZZ_p$: $p$-adic integers\n\t\\ii $\\QQ_p$: $p$-adic numbers\n\t\\ii $f'$: derivative of $f$\n\t\\ii $\\int_a^b f(x) \\; dx$: Riemann integral of $f$ on $[a,b]$\n\\end{itemize}\nComplex analysis:\n\\begin{itemize}\n\t\\ii $\\int_\\alpha f \\; dz$: contour integral of $f$ along path $\\alpha$\n\t\\ii $\\Res(f;p)$: the residue of a meromorphic function $f$ at point $p$\n\t\\ii $\\Wind(\\gamma, p)$: winding number of $\\gamma$ around $p$.\n\\end{itemize}\n\\section{Measure theory and probability}\n\\begin{itemize}\n\t\\ii $\\SA\\cme$: the $\\sigma$-algebra of Caratheory-measurable sets\n\t\\ii $\\SB(X)$: the Borel space for $X$\n\t\\ii $\\mu\\cme$: the induced measure on $\\SA\\cme$.\n\t\\ii $\\lambda$: Lebesgue measure\n\t\\ii $\\mathbf{1}_A$: the indicator function for $A$\n\t\\ii $\\int_\\Omega f \\; d\\mu$: the Lebesgue integral of $f$\n\t\\ii $\\lim_{n \\to \\infty} f_n$: pointwise limit of $f_n$\n\t\\ii $\\wh G$: Pontryagin dual for $G$\n\\end{itemize}\n\n\\section{Algebraic topology}\n\\begin{itemize}\n\t\\ii $\\alpha \\simeq \\beta$: for paths, this indicates path homotopy\n\t\\ii $\\ast$: path concatenation\n\t\\ii $\\pi_1(X) = \\pi_1(X, x_0)$: the fundamental group of (pointed) space $X$\n\t\\ii $\\pi_n(X) = \\pi_n(X, x_0)$: the $n$th homotopy group of (pointed) space $X$\n\t\\ii $f_\\sharp$: the induced map $\\pi_1(X) \\to \\pi_1(Y)$ of $f : X \\to Y$\n\t\\ii $\\Delta^n$: the standard $n$-simplex\n\t\\ii $\\partial\\sigma$: the boundary of a singular $n$-simplex $\\sigma$\n\t\\ii $H_n(A_\\bullet)$: the $n$th homology group of the chain complex $A_\\bullet$\n\t\\ii $H_n(X)$: the $n$th homology group of a space $X$\n\t\\ii $\\wt H_n(X)$: the $n$th reduced homology group of $X$\n\t\\ii $H_n(X, A)$: the $n$th relative homology group of $X$ and $A \\subseteq X$\n\t\\ii $f_\\ast$: the induced map on $H_n(A_\\bullet) \\to H_n(B_\\bullet)$\n\tof $f : A_\\bullet \\to B_\\bullet$,\n\tor $H_n(X) \\to H_n(Y)$ for $f : X \\to Y$\n\t\\ii $\\chi(X)$: Euler characteristic of a space $X$\n\t\\ii $H^n(A^\\bullet)$: the $n$th cohomology group of a cochain complex $A^\\bullet$\n\t\\ii $H^n(A_\\bullet; G)$: the $n$th cohomology group of the cochain complex\n\tobtained by applying $\\Hom(-,G)$ to $A_\\bullet$\n\t\\ii $H^n(X; G)$: the $n$th cohomology group/ring of $X$ with $G$-coefficients\n\t\\ii $\\wt H^n(X; G)$: the $n$th reduced cohomology group/ring of $X$ with $G$-coefficients\n\t\\ii $H^n(X,A ; G)$: the $n$th relative cohomology group/ring of $X$ and $A \\subset X$ with $G$-coefficients\n\t\\ii $f^\\sharp$: the induced map on $H^n(A^\\bullet) \\to H^n(B^\\bullet)$\n\tof $f : A^\\bullet \\to B^\\bullet$,\n\tor $H^n(X) \\to H^n(Y)$ for $f : X \\to Y$\n\t\\ii $\\Ext(-,-)$: the Ext functor\n\t\\ii $\\phi \\smile \\psi$: cup product of cochains $\\phi$ and $\\psi$\n\\end{itemize}\n\n\\section{Category theory}\nSome common categories (in alphabetical order):\n\\begin{itemize}\n\t\\ii $\\catname{Grp}$: category of groups\n\t\\ii $\\catname{CRing}$: category of commutative rings\n\t\\ii $\\catname{Top}$: category of topological spaces\n\t\\ii $\\catname{Top}_\\ast$: category of pointed topological spaces\n\t\\ii $\\catname{Vect}_k$: category of $k$-vector spaces\n\t\\ii $\\catname{FDVect}_k$: category of finite-dimensional vector spaces\n\t\\ii $\\catname{Set}$: category of sets\n\t\\ii $\\catname{hTop}$: category of topological spaces,\n\twhose morphisms are homotopy classes of maps\n\t\\ii $\\catname{hTop}_\\ast$: pointed version of $\\catname{hTop}$\n\t\\ii $\\catname{hPairTop}$: category of pairs $(X,A)$ with morphisms\n\tbeing pair-homotopy equivalence classes\n\t\\ii $\\Opens(X)$: the category of open sets of $X$, as a poset\n\\end{itemize}\nOperations with categories:\n\\begin{itemize}\n\t\\ii $\\obj \\AA$: objects of the category $\\AA$\n\t\\ii $\\AA\\op$: opposite category\n\t\\ii $\\AA \\times \\BB$: product category\n\t\\ii $[\\AA, \\BB]$: category of functors from $\\AA$ to $\\BB$\n\t\\ii $\\ker f : \\Ker f \\to B$: for $f : A \\to B$, categorical kernel\n\t\\ii $\\coker f : A \\to \\Coker f$: for $f : A \\to B$, categorical cokernel\n\t\\ii $\\img f : A \\to \\Img f$: for $f : A \\to B$, categorical image\n\\end{itemize}\n\n\\section{Differential geometry}\n\\begin{itemize}\n\t\\ii $Df$: total derivative of $f$\n\t\\ii $(Df)_p$: total derivate of $f$ at point $p$\n\t\\ii $\\fpartial{f}{e_i}$: $i^{\\text{th}}$ partial derivative\n\t\\ii $\\alpha_p$: evaluating a $k$-form $\\alpha$ at $p$\n\t\\ii $\\int_c \\alpha$: integration of the differential form $\\alpha$ over a cell $c$\n\t\\ii $d\\alpha$: exterior derivative of a $k$-form $\\alpha$\n\t\\ii $\\phi^\\ast \\alpha$: pullback of $k$-form $\\alpha$ by $\\phi$\n\\end{itemize}\n\n\\section{Algebraic number theory}\n\\begin{itemize}\n\t\\ii $\\ol \\QQ$: ring of algebraic numbers\n\t\\ii $\\ol \\ZZ$: ring of algebraic integers\n\t\\ii $\\ol F$: algebraic closure of a field $F$\n\t\\ii $\\NK(\\alpha)$: the norm of $\\alpha$ in extension $K/\\QQ$\n\t\\ii $\\TrK(\\alpha)$: the trace of $\\alpha$ in extension $K/\\QQ$\n\t\\ii $\\OO_K$: ring of integers in $K$\n\t\\ii $\\ka+\\kb$: sum of two ideals $\\ka$ and $\\kb$\n\t\\ii $\\ka\\kb$: ideal generated by products of elements in ideals $\\ka$ and $\\kb$\n\t\\ii $\\ka \\mid \\kb$: ideal $\\ka$ divides ideal $\\kb$\n\t\\ii $\\ka\\inv$: the inverse of $\\ka$ in the ideal group\n\t\\ii $\\Norm(I)$: ideal norm\n\t\\ii $\\Cl_K$: class group of $K$\n\t\\ii $\\Delta_K$: discriminant of number field $K$\n\t\\ii $\\mu(\\OO_K)$: set of roots of unity contained in $\\OO_K$\n\t\\ii $[K:F]$: degree of a field extension\n\t\\ii $\\Aut(K/F)$: set of field automorphisms of $K$ fixing $F$\n\t\\ii $\\Gal(K/F)$: Galois group of $K/F$\n\t\\ii $D_\\kp$: decomposition group of prime ideal $\\kp$\n\t\\ii $I_\\kp$: inertia group of prime ideal $\\kp$\n\t\\ii $\\Frob_\\kp$: Frobenius element of $\\kp$ (element of $\\Gal(K/\\QQ)$)\n\t\\ii $P_K(\\km)$: ray of principal ideals of a modulus $\\km$\n\t\\ii $I_K(\\km)$: fractional ideals of a modulus $\\km$\n\t\\ii $C_K(\\km)$: ray class group of a modulus $\\km$\n\t\\ii $\\left( \\frac{L/K}{\\bullet} \\right)$: the Artin symbol\n\t\\ii $\\Ram(L/K)$: primes of $K$ ramifying in $L$\n\t\\ii $\\kf(L/K)$: the conductor of $L/K$\n\\end{itemize}\n\n\\section{Representation theory}\n\\begin{itemize}\n\t\\ii $k[G]$: group algebra\n\t\\ii $V \\oplus W$: direct sum of representations $V = (V, \\rho_V)$\n\tand $W = (W, \\rho_W)$ of an algebra $A$\n\t\\ii $V^\\vee$: dual representation of a representation $V = (V, \\rho_V)$\n\t\\ii $\\Reg(A)$: regular representation of an algebra $A$\n\t\\ii $\\Homrep(V,W)$: algebra of morphisms $V \\to W$ of representations\n\t\\ii $\\chi_V$: the character $A \\to k$ attached to an $A$-representation $V$\n\t\\ii $\\Classes(G)$: set of conjugacy classes of $G$\n\t\\ii $\\FunCl(G)$: the complex vector space of functions $\\Classes(G) \\to \\CC$\n\t\\ii $V \\otimes W$: tensor product of representations $V = (V, \\rho_V)$ and $W = (W, \\rho_W)$\n\tof a \\emph{group} $G$ (rather than an algebra)\n\t\\ii $\\Ctriv$: the trivial representation\n\t\\ii $\\Csign$: the sign representation\n\\end{itemize}\n\n\\section{Algebraic geometry}\n\\begin{itemize}\n\t\\ii $\\VV(-)$: vanishing locus of a set or ideal\n\t\\ii $\\Aff^n$: $n$-dimensional (complex) affine space\n\t\\ii $\\sqrt I$: radical of an ideal $I$\n\t\\ii $\\CC[V]$: coordinate ring of an affine variety $V$\n\t\\ii $\\OO_V(U)$: ring of rational functions on $U$\n\t\\ii $D(f)$: distinguished open set\n\t\\ii $\\CP^n$: complex projective $n$-space (ambient space for projective varieties)\n\t\\ii $(x_0 : \\dots : x_n)$: coordinates of projective space\n\t\\ii $U_i$: standard affine charts\n\t\\ii $\\Vp(-)$: projective vanishing locus.\n\t\\ii $h_I$, $h_V$: Hilbert function of an ideal $I$ or projective variety $V$\n\t\\ii $\\pi^\\sharp$ or $\\pi^\\sharp_U$: the pullback $\\OO_Y \\to \\OO_X(\\pi\\pre(U))$ obtained from $\\pi \\colon X \\to Y$\n\t\\ii $\\SF_p$: the stalk of a (pre-)sheaf $\\SF$ at a point $p$\n\t\\ii $[s]_p:$ the germ of $s \\in \\SF(U)$ at the point $p$\n\t\\ii $\\OO_{X,p}$: shorthand for $(\\OO_X)_p$.\n\t\\ii $\\SF\\sh$: sheafification of pre-sheaf $\\SF$\n\t\\ii $\\alpha_p : \\SF_p \\to \\SG_p$: morphism of stalks obtained from $\\alpha : \\SF \\to \\SG$\n\t\\ii $\\km_{X,p}$: the maximal ideal of $\\OO_{X,p}$\n\t\\ii $\\Spec A$: the spectrum of a ring $A$\n\t\\ii $S\\inv A$: localization of ring $A$ at a set $S$\n\t\\ii $A[1/f]$: localization of ring $A$ away from element $f$\n\t\\ii $A_\\kp$: localization of ring $A$ at prime ideal $\\kp$\n\t\\ii $f(\\kp)$: the value of $f$ at $\\kp$, i.e.\\ $f \\pmod \\kp$\n\t\\ii $\\kappa(\\kp)$: the residue field of $\\Spec A$ at the element $\\kp$.\n\t% \\ii $\\Proj R$: the projective scheme of a graded ring $S$\n\t\\ii $\\pi^\\sharp_{\\kp}$: the induced map of stalks in $\\pi^\\sharp$.\n\\end{itemize}\n\n\\section{Set theory}\n\\begin{itemize}\n\t\\ii $\\ZFC$: standard theory of ZFC\n\t\\ii $\\ZFC^+$: standard theory of ZFC, plus the sentence\n\t``there exists a strongly inaccessible cardinal''\n\t\\ii $2^S$ or $\\PP(S)$: power set of $S$\n\t\\ii $A \\land B$: $A$ and $B$\n\t\\ii $A \\lor B$: $A$ or $B$\n\t\\ii $\\neg A$: not $A$\n\t\\ii $V$: class of all sets (von Neumann universe)\n\t\\ii $\\omega$: the first infinite ordinal, also the set of nonnegative integers\n\t\\ii $V_\\alpha$: level of the von Neumann universe\n\t\\ii $\\On$: class of ordinals\n\t\\ii $\\bigcup A$: the union of elements inside $A$\n\t\\ii $A \\approx B$: sets $A$ and $B$ are equinumerous\n\t\\ii $\\aleph_\\alpha$: the aleph numbers\n\t\\ii $\\cof \\lambda$: the cofinality of $\\lambda$\n\t\\ii $\\MM \\vDash \\phi[b_1, \\dots, b_n]$: model $\\MM$ satisfies sentence $\\phi$\n\twith parameters $b_1$, \\dots, $b_n$\n\t\\ii $\\Delta_n$, $\\Sigma_n$, $\\Pi_n$: levels of the Levy hierarchy\n\t\\ii $\\MM_1 \\subseteq \\MM_2$: $\\MM_1$ is a substructure of $\\MM_2$\n\t\\ii $\\MM_1 \\prec \\MM_2$: $\\MM_1$ is an elementary substructure of $\\MM_2$\n\t\\ii $p \\parallel q$: elements $p$ and $q$ of a poset $\\Po$ are compatible\n\t\\ii $p \\perp q$: elements $p$ and $q$ of a poset $\\Po$ are incompatible\n\t\\ii $\\Name_\\alpha$: the hierarchy of $\\Po$-names\n\t\\ii $\\tau^G$: interpretation of a name $\\tau$ by filter $G$\n\t\\ii $M[G]$: the model obtained from a forcing poset $G \\subseteq \\Po$\n\t\\ii $p \\Vdash \\varphi(\\sigma_1, \\dots, \\sigma_n)$: $p \\in \\Po$ forces the sentence $\\varphi$\n\t\\ii $\\check x$: the name giving an $x \\in M$ when interpreted\n\t\\ii $\\dot G$: the name giving $G$ when interpreted\n\\end{itemize}\n\n\n% Consider adding:\n% lim (convergence)\n% group presentation\n", "meta": {"hexsha": "0b3ffd46c6cc03c3a2869f5b10606674deaae50e", "size": 14769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/backmatter/notation.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/backmatter/notation.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/backmatter/notation.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3513513514, "max_line_length": 114, "alphanum_fraction": 0.6445256957, "num_tokens": 5355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893340314393, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6544280292998086}}
{"text": "\\RequirePackage{amsmath}\r\n\\RequirePackage{fix-cm}\r\n\\documentclass{svmono}\r\n\r\n\\def\\ColoredLinks{}\r\n\\input{Macros.tex}\r\n\\usepackage{xcolor}\r\n\\usepackage{lmodern}\r\n\\usepackage{wrapfig}\r\n\\textwidth160mm\r\n\\textheight220mm\r\n\\oddsidemargin0mm\r\n\\evensidemargin0mm\r\n\\topmargin0mm\r\n\r\n\\def\\cmd#1{\\textbf{\"\\texttt{#1}\"}}\r\n\\def\\cm#1{\\textbf{\\texttt{#1}}}\r\n\r\n\\begin{document}\r\n\r\n\\hypersetup{pageanchor=false}\r\n\\thispagestyle{empty}\r\n\\vskip5cm {\\Huge\\textbf{Distribution XML reference for \\vskip.1cm Warteschlangensimulator}}\r\n\\vskip.5cm \\hrule\r\n\\vskip.5cm {\\large \\textsc{Alexander Herzog} (\\href{mailto:alexander.herzog@tu-clausthal.de}{alexander.herzog@tu-clausthal.de})}\r\n\\vskip.25cm {\\color{gray}\r\nThis reference refers to version \\input{../Version.tex} of Warteschlangensimulator.\\\\\r\nDownload address: \\href{https://github.com/A-Herzog/Warteschlangensimulator/}{https://github.com/A-Herzog/Warteschlangensimulator/}.\r\n}\r\n\\vskip.5cm \\hrule\r\n\\vskip.5cm\r\n\r\nWhen storing distribution settings to xml files the following xml tags will be used:\r\n\r\nEnglish version:\\\\\r\n\\cm{<ModelElementDistribution>distribution name (parameters)</ModelElementDistribution>}\r\n\r\nGerman version:\\\\\r\n\\cm{<ModellElementVerteilung>distribution name (parameters)</ModellElementVerteilung>}\r\n\r\nThe English or German version will be used when storing xml data in Warteschlangensimulator. When reading xml files Warteschlangensimulator will always understand both versions.\r\n\r\nIn the following sections the possible values for \"distribution name\" and the corresponding \"parameters\" will be listed. Distribution parameters \"mean\" and \"sd\" correspond directly to the stochastic characteristics mean and standard deviation.\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Empirical data}\r\n\r\n\\cm{Empirical data (point1;point2;point3;...)}~\\\\\r\n\\cm{Empirische Daten (point1;point2;point3;...)}\r\n\r\nThe data points are interpreted as pdf values at equidistant points on the predefined range of the distribution.\r\n\r\n\r\n\r\n\r\n\r\n\\section*{One point distribution}\r\n\r\n\\cm{One point distribution (point)}~\\\\\r\n\\cm{Ein-Punkt-Verteilung (point)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&point\\\\\r\nsd&=&0\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Uniform distribution}\r\n\r\n\\cm{Uniform distribution (lower;upper)}~\\\\\r\n\\cm{Gleichverteilung (lower;upper)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&(lower+upper)/2\\\\\r\nsd&=&(upper-lower)/\\sqrt{12}\\\\\r\nlower&=&mean-sd\\cdot\\sqrt{12}/2\\\\\r\nupper&=&mean+sd\\cdot\\sqrt{12}/2\\\\\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Exponential distribution}\r\n\\cm{Exponentialverteilung (mean)}~\\\\\r\n\\cm{Exponential distribution (mean)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nsd&=&mean\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Normal distribution}\r\n\\cm{Normal distribution (mean;sd)}~\\\\\r\n\\cm{Normalverteilung (mean;sd)}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Lognormal distribution}\r\n\\cm{Lognormal distribution (mean;sd)}~\\\\\r\n\\cm{Lognormalverteilung (mean;sd)}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Erlang distribution}\r\n\\cm{Erlang distribution (shape;scale)}~\\\\\r\n\\cm{Erlang-Verteilung (shape;scale)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&shape\\cdot scale\\\\\r\nsd&=&\\sqrt{shape}\\cdot scale\\\\\r\nscale&=&sd^2/mean\\\\\r\nshape&=&mean^2/sd^2\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Gamma distribution}\r\n\\cm{Gamma distribution (shape;scale)}~\\\\\r\n\\cm{Gamma-Verteilung (shape;scale)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&shape\\cdot scale\\\\\r\nsd&=&\\sqrt{shape}\\cdot scale\\\\\r\nscale&=&sd^2/mean\\\\\r\nshape&=&mean^2/sd^2\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Beta distribution}\r\n\\cm{Beta distribution (alpha;beta;lower;upper)}~\\\\\r\n\\cm{Beta-Verteilung (alpha;beta;lower;upper)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&alpha/(alpha+beta)\\cdot(upper-lower)+lower\\\\\r\nsd&=&(upper-lower)^2\\cdot alpha\\cdot beta/(alpha+beta)^2/(1+alpha+beta)\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Cauchy distribution}\r\n\\cm{Cauchy-Verteilung (median;scale)}~\\\\\r\n\\cm{Cauchy distribution (median;scale)}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Weibull distribution}\r\n\\cm{Weibull distribution (scaleInvers;shape)}~\\\\\r\n\\cm{Weibull-Verteilung (scaleInvers;shape)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&scale\\cdot\\Gamma(1+(1/shape))\\\\\r\nsd&=&scale\\cdot\\sqrt{\\Gamma(1+2/shape)-(\\Gamma(1+1/shape))^2}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Chi distribution}\r\n\\cm{Chi distribution (degreesOfFreedom)}~\\\\\r\n\\cm{Chi-Verteilung (degreesOfFreedom)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&\\sqrt{2}\\cdot\\Gamma((degreesOfFreedom+1)/2)/\\Gamma(degreesOfFreedom/2)\\\\\r\nsd&=&\\Big[(2\\cdot\\Gamma(degreesOfFreedom/2)*\\Gamma(1+degreesOfFreedom/2)-\\\\\r\n~&~&(\\Gamma((degreesOfFreedom+1)/2))^2)/\\Gamma(degreesOfFreedom/2)\\Big]^{\\frac{1}{2}}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Chi$^2$ distribution}\r\n\\cm{Chi\\^{}2 distribution (degreesOfFreedom)}~\\\\\r\n\\cm{Chi\\^{}2-Verteilung (degreesOfFreedom)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&degreesOfFreedom\\\\\r\nsd&=&\\sqrt{2\\cdot degreesOfFreedom}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{F distribution}\r\n\\cm{F distribution (NumeratorDegreesOfFreedom;DenominatorDegreesOfFreedom)}~\\\\\r\n\\cm{F-Verteilung (NumeratorDegreesOfFreedom;DenominatorDegreesOfFreedom)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\\\\\r\n(let $m:=NumeratorDegreesOfFreedom$ and $n:=DenominatorDegreesOfFreedom$)\r\n\\begin{eqnarray*}\r\nmean&=&\r\n\\frac{n}{n-2}\\\\\r\nsd&=&\r\n\\sqrt{2\\cdot n^2\\cdot\\frac{m+n-2}{m\\cdot(n-2)\\cdot(n-2)\\cdot(n-4)}}\\\\\r\nm&=&\r\nround\\left(2\\cdot (2\\cdot\\widetilde m)^2\\cdot\\frac{2\\cdot\\widetilde m-2}{sd^2\\cdot (2\\cdot\\widetilde m-2)^2\\cdot (2\\cdot\\widetilde m-4)-2\\cdot (2\\cdot\\widetilde m)^2}\\right) ~\\text{with}~ \\widetilde m:=mean/(mean-1)\\\\\r\nn&=&\r\nround(2\\cdot mean/(mean-1))\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Johnson SU distribution}\r\n\\cm{Johnson SU distribution (gamma;xi;delta;lambda)}~\\\\\r\n\\cm{Johnson-SU-Verteilung (gamma;xi;delta;lambda)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&xi-lambda\\cdot\\exp(1/(2\\cdot delta^2))\\cdot\\sinh(gamma/delta)\\\\\r\nsd&=&\\sqrt{lambda^2/2\\cdot(\\exp(1/delta^2)-1)\\cdot(\\exp(1/delta^2)*\\cosh(2*gamma/delta)+1)}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Triangular distribution}\r\n\\cm{Triangular distribution (lowerBound;mostLikelyX;upperBound)}~\\\\\r\n\\cm{Dreiecksverteilung (lowerBound;mostLikelyX;upperBound)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&(lowerBound+mostLikelyX+upperBound)/3\\\\\r\nsd&=&\\Big[(lowerBound^2+upperBound^2+mostLikelyX^2-lowerBound\\cdot upperBound-\\\\\r\n~&~&lowerBound\\cdot mostLikelyX-upperBound\\cdot mostLikelyX)/18\\Big]^{\\frac{1}{2}}\\\\\r\nlowerBound&=&mean-sd\\cdot\\sqrt{6}\\\\\r\nmostLikelyX&=&mean\\\\\r\nupperBound&=&mean+sd\\cdot\\sqrt{6}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Pert distribution}\r\n\\cm{Pert distribution (lowerBound;mostLikelyX;upperBound)}~\\\\\r\n\\cm{Pert-Verteilung (lowerBound;mostLikelyX;upperBound)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&(lowerBound+4\\cdot mostLikelyX+upperBound)/6\\\\\r\nsd&=&\\Big[((lowerBound+4\\cdot mostLikelyX+upperBound)/6-lowerBound)\\cdot\\\\\r\n~&~&(upperBound-(lowerBound+4\\cdot mostLikelyX+upperBound)/6)/7\\Big]^{\\frac{1}{2}}\\\\\r\nlowerBound&=&mean-sd\\cdot\\sqrt{7}\\\\\r\nmostLikelyX&=&mean\\\\\r\nupperBound&=&mean+sd\\cdot\\sqrt{7}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Laplace distribution}\r\n\\cm{Laplace distribution (mean;b)}~\\\\\r\n\\cm{Laplace-Verteilung (mean;b)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nsd&=&b\\cdot\\sqrt{2}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Pareto distribution}\r\n\\cm{Pareto distribution (xmin;alpha)}~\\\\\r\n\\cm{Pareto-Verteilung (xmin;alpha)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&alpha\\cdot xmin/(alpha-1)\\\\\r\nsd&=&xmin^2\\cdot alpha/(alpha-1)^2/(alpha-2)\\\\\r\nalpha&=&mean/(mean-xmin)\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Logistic distribution}\r\n\\cm{Logistic distribution (mean;s)}~\\\\\r\n\\cm{Logistische Verteilung (mean;s)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nsd&=&s\\cdot\\pi/\\sqrt{3}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Inverse gaussian distribution}\r\n\\cm{Inverse gaussian distribution (lambda;mu)}~\\\\\r\n\\cm{Inverse Gauß-Verteilung (lambda;mu)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&mu\\\\\r\nsd&=&mu\\cdot\\sqrt{mu/lambda}\\\\\r\nlambda&=&mean^3/sd^2\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Rayleigh distribution}\r\n\\cm{Rayleigh distribution (mean)}~\\\\\r\n\\cm{Rayleigh-Verteilung (mean)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nsd&=&\\sqrt{(4-\\pi)/2}\\cdot\\sqrt{2/\\pi}\\cdot mean\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Log-logistic distribution}\r\n\\cm{Log-logistic distribution (alpha;beta)}~\\\\\r\n\\cm{Log-Logistische Verteilung (alpha;beta)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&alpha\\cdot\\pi/beta/\\sin(\\pi/beta)\\\\\r\nsd&=&alpha\\cdot\\sqrt{2\\cdot\\pi/beta/\\sin(2\\cdot\\pi/beta)-\\pi^2/beta^2}/sin(\\pi/beta)\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Power distribution}\r\n\\cm{Power distribution (a;b;c)}~\\\\\r\n\\cm{Potenzverteilung (a;b;c)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&a+(b-a)\\cdot c/(c+1)\\\\\r\nsd&=&(b-a)/(c+1)\\cdot\\sqrt{c/(c+2)}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Gumbel distribution}\r\n\\cm{Gumbel distribution (mean;sd)}~\\\\\r\n\\cm{Gumbel-Verteilung (mean;sd)}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Fatigue life distribution}\r\n\\cm{Fatigue life distribution (mu;beta;gamma)}~\\\\\r\n\\cm{Fatigue-Life-Verteilung (mu;beta;gamma)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&mu+beta\\cdot (1+gamma\\cdot gamma/2)\\\\\r\nsd&=&beta\\cdot gamma\\cdot\\sqrt{1+5\\cdot gamma^2/4}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Frechet distribution}\r\n\\cm{Frechet distribution (delta;beta;alpha)}~\\\\\r\n\\cm{Frechet-Verteilung (delta;beta;alpha)}\r\n\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&delta+beta\\cdot gamma(1-1/alpha)\\\\\r\nsd&=&beta\\cdot\\sqrt{gamma(1-2/alpha)-gamma(1-1/alpha)^2}\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Hyperbolic secant distribution}\r\n\\cm{Hyperbolic secant distribution (mean;sd)}~\\\\\r\n\\cm{Hyperbolische Sekanten-Verteilung (mean;sd)}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Left sawtooth distribution}\r\n\\cm{Left sawtooth distribution (a;b)}~\\\\\r\n\\cm{Linke Sägezahnverteilung (a;b)}\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&(2\\cdot a+b)/2\\\\\r\nsd&=&(b-a)^2/18\r\n\\end{eqnarray*}\r\n\r\n\r\n\r\n\r\n\r\n\\section*{Right sawtooth distribution}\r\n\\cm{Right sawtooth distribution (a;b)}~\\\\\r\n\\cm{Rechte Sägezahnverteilung (a;b)}\r\nConversion between distribution parameters and stochastic characteristics\r\n\\begin{eqnarray*}\r\nmean&=&(a+2\\cdot b)/2\\\\\r\nsd&=&(b-a)^2/18\r\n\\end{eqnarray*}\r\n\r\n\\end{document}", "meta": {"hexsha": "af9bbcfd8c679b42f1e40d742245429bb98f7502", "size": 11420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Simulator/build/Help/Distributions/Warteschlangensimulator-Distributions.tex", "max_stars_repo_name": "A-Herzog/Warteschlangensimulator", "max_stars_repo_head_hexsha": "fd83d400944a59147a465a4683b2f9258c3de5d0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-14T05:36:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T14:24:12.000Z", "max_issues_repo_path": "Simulator/build/Help/Distributions/Warteschlangensimulator-Distributions.tex", "max_issues_repo_name": "A-Herzog/Warteschlangensimulator", "max_issues_repo_head_hexsha": "fd83d400944a59147a465a4683b2f9258c3de5d0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-06-17T22:09:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T23:02:50.000Z", "max_forks_repo_path": "Simulator/build/Help/Distributions/Warteschlangensimulator-Distributions.tex", "max_forks_repo_name": "A-Herzog/Warteschlangensimulator", "max_forks_repo_head_hexsha": "fd83d400944a59147a465a4683b2f9258c3de5d0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-06-08T04:26:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-15T22:42:59.000Z", "avg_line_length": 25.2654867257, "max_line_length": 244, "alphanum_fraction": 0.7218038529, "num_tokens": 3560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.6544280238190732}}
{"text": "\\chapter{Buoyancy}\n\nWhen you put a boat into water, it will sink into the water until\nthe mass of the water it displaces is equal to the mass of the\nboat. We think of this in terms of forces. Gravity pulls the mass of\nthe boat down. The \\newterm{buoyant force} pushes the boat up. A boat\ndropped into the water will bob up and down a bit before reaching an\nequilibrium where the two forces are equal.\n% ADD: Explain Action Reaction Pairs in previous chapter\n% ADD: Archimedes principle\n% KA: https://www.khanacademy.org/science/in-in-class9th-physics-india/in-in-gravity/in-in-pressure-in-liquids-archimedes-principle/v/archimedes-principle-buoyancy-fluids-physics-khan-academy\n\nThe buoyant force pushes things up -- against the force of\ngravity. The force is equal to the weight of the fluid being\nreplaced. So, for example, a cubic meter of freshwater has a mass of\nabout 1000kg.  If you submerge anything with a volume of one meter in\nfreshwater on earth, the buoyant force will be about 9800 newtons.\n\nFor some things, like a block of styrofoam, this buoyant force will be\nsufficient to carry it to the surface. Once it reaches the surface, it\nwill continue to rise (displacing less water) until the mass of the\nwater it displaces is equal to its mass. And then we say ``It floats!''\n\n\\includegraphics[width=0.8\\textwidth]{Buoyancy_Displacement_Diagram.png}\n\nFor some things, like a block of lead, the buoyant force is not\n sufficient to lift it to the surface, and thus we say ``It sinks!''\n\nThis is why a helium balloon floats through the air. The air\nthat it displaces weighs more than the balloon and the helium itself. (It is easy to forget that air has a mass, but it does.)\n\n\\begin{Exercise}[title={Buoyancy}, label=buoyancy]\n  You have an aluminum box that has a heavy base, so it will always\n  float upright. The box and its contents weigh 10 kg. Its base is 0.3 m x 0.4 m. It is 1m tall.\n\n  When you drop it into freshwater ($1000 kg/m^3$), how far will it sink\n  before it reaches equilibrium.\n  \n\\end{Exercise}\n\\begin{Answer}[ref=buoyancy]\n  Equilibrium will be achieved when the box has displaced 10 kg of water. That is, when it has displaced $0.01$ cubic meters.\n\n  The area of the base of the box is 0.12 square meters.  So if the\n  box sinks $x$ meters into the water it will displace $0.12 x$ cubic\n  meters.\n\n  Thus at equilibrium $x = \\frac{0.01}{0.12} \\approx 0.083$ m.  So,\n  the box will sink 8.3 cm into the water before reaching equilibrium.\n\\end{Answer}\n\n\\section{The Mechanism of Buoyancy}\n\nAs you dive down in the ocean, you will experience greater and\ngreater pressure from the water. And if you take a balloon with you, you\nwill gradually see it get smaller as the water pressure compresses the\nair in the balloon.\n\nLet's say you are 3 meters below the surface of the water. What is the\npressure in Pascals (newtons per square meter)? You can think of the\nwater as a column of water crushing down upon you. The pressure over\na square meter is the weight of 3 cubic meters of water pressing down.\n\n$$p = (3)(1000)(9.8) = 29,400 \\text{ Pa }$$\n\nThis is called \\newterm{hydrostatic pressure}. The general rule for\nhydrostatic pressure in Pascals $p$ is\n\n$p = d g h$\n\nWhere  $d$ is the density of the fluid\nin kg per cubic meter, $g$ is the acceleration due to gravity in\n$m/s^2$, and $h$ is the height of the column of fluid above you.\n\nSo, where does buoyant force come from? Basically, the pressure pushing up on the\ndeepest part of the object is higher than the pressure pushing down on\nthe shallowest part of the object. That is where bouyancy comes from.\n\n\\includegraphics[width=0.8\\textwidth]{Buoyancy_Diagram.png}\n\n% KA: https://www.khanacademy.org/science/physics/fluids/buoyant-force-and-archimedes-principle/a/buoyant-force-and-archimedes-principle-article\n\n\\begin{Exercise}[title={Hydrostatic Pressure}, label=mars_pressure]\n\n  You dive into a tank of olive oil on Mars. How much more\n  hydrostatic pressure does your body experience at 5 meters deep than\n  it did at the surface?\n\n  The density of olive oil is about 900 kg per square meter. The\n  acceleration due to gravity on Mars is 3.721 $m/s^2$.\n  \n\\end{Exercise}\n\\begin{Answer}[ref=mars_pressure]\n$$p = d g h = (900)(3.721)(5) = 16,744.5 \\text{ Pa}$$\n\\end{Answer}\n\nNotice that although the pressure is increasing as you go deeper, the\nbuoyant force will \\emph{not increase} because the buoyant force is always equal\nto the weight of the fluid that is displaced, regardless if that is 1\nmeter or 100 meters underwater.\n\nAlso, saltwater is denser then freshwater. That is why people float\nbetter in the sea than they do in a river.\n\nAnd, lipids, like fats and oils, are less dense than water. That is why\npeople with a lot of body fat tend to float better than people with\nless body fat. And why oil floats in a glass of water.\n\n\\includegraphics[width=0.8\\textwidth]{Oil_Water.png}\n\n% Image: https://image.shutterstock.com/image-photo/mixture-olive-oil-water-glass-260nw-1576851145.jpg\n\n", "meta": {"hexsha": "6d9425ace715a370bd947b9183a776d58d09fbcf", "size": 4984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/buoyancy-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/buoyancy-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/buoyancy-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": 44.5, "max_line_length": 191, "alphanum_fraction": 0.7616372392, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6544280218510437}}
{"text": "\\section{Applications}\nPlease check exam schedule! Also, a sample exam is posted. This is the payoff day. All this stuff about Poincar\\'e duality has got to be good for something. Recall:\n\\begin{theorem}[Fully relative duality]\nLet $M$ be a $R$-oriented $n$-manifold. Let $L\\subseteq K\\subseteq M$ be compact ($M$ need not be compact). Then $[M]_K\\in H_n(M,M-K)$, and capping gives an isomorphism:\n$$\\cHH^p(K,L;R)\\xrightarrow{\\cap[M]_k,\\cong}H_{n-p}(M-L,M-K;R)$$\n\\end{theorem}\nToday we'll think about the case $L=\\emptyset$, so this is saying:\n$$\\cHH^p(K;R)\\xrightarrow{\\cap[M]_k,\\cong}H_{n-p}(M,M-K;R)$$\n\\begin{corollary}\n$\\cHH^q(K;R)=0$ for $q>n$.\n\\end{corollary}\nWe can contrast this with singular (co)homology. Here's an example:\n\\begin{example}[Barratt-Milnor]\nA two-dimensional version $K$ of the Hawaiian earring, i.e., nested spheres all tangent to a point whose radii are going to zero. What they proved is that $H_q(K;\\QQ)$ is uncountable for every $q>1$. But if you look at the \\v{C}ech cohomology, stuff vanishes.\n\\end{example}\nThat's nice.\n\nHow about an even more special subcase? Suppose $M=\\RR^n$. The result is called Alexander duality. This says:\n\\begin{theorem}[Alexander duality]\nIf $\\emptyset\\neq K\\subseteq \\RR^n$ be compact. Then $\\cHH^{n-q}(K;R)\\xrightarrow{\\cong}\\widetilde{H}_{q-1}(\\RR^n-K;R)$\n\\end{theorem}\n\\begin{proof}\nWe have the LES of a pair, which gives an isomorphism $\\partial:H_q(\\RR^n,\\RR^n-K;R)\\xrightarrow{\\cong}\\widetilde{H}_{q-1}(\\RR^n-K;R)$, so the composition $\\partial\\circ(-\\cap[M]_K)$ is an isomorphism by Poincar\\'e duality.\n\\end{proof}\nFor most purposes, this is the most useful duality theorem.\n\\begin{example}[Jordan curve theorem]\n$q=1$ and $R=\\Z$. Then this is saying that $\\cHH^{n-1}(K)\\xrightarrow{\\cong}\\widetilde{H}_0(\\RR^n-K)$. But $\\widetilde{H}_0(\\RR^n-K)$ is free on $\\#\\pi_0(\\RR^n-K)-1$ generators. If $n=2$, for example, and $K\\cong S^1$, then $\\cHH^{n-1}(K)=H^{n-1}(K)\\cong H^{n-1}(S^1)$, so $H^1(S^1)\\cong \\widetilde{H}_0(\\RR^2-K)$. Hence there are \\emph{two} components in the complement of $K$. This could also be the topologist's sine curve as well. This is the Jordan curve theorem.\n\\end{example}\nConsider the UCT, which states that there's a sexseq $0\\to\\Ext^1_\\Z(H_{q-1}(X),\\Z)\\to H^q(X)\\to\\Hom(H_q(X),\\Z)\\to 0$ that splits, but not naturally. First, note that $\\Hom(H_q(X),\\Z)$ is always torsion-free. If I assume that $H_{q-1}(X)$ is finitely generated, then $\\Ext^1_\\Z(H_{q-1}(X),\\Z)$ is a finite abelian group, but in particular it's torsion.\n\nThe UCT is making the decomposition of $H^q(X)$ into its torsion-free and torsion parts. I can divide by torsion, so that $H^q(X)/\\mathrm{tors}\\cong \\Hom(H_q(X),\\Z)$. But there's also an isomorphism $\\Hom(H_q(X)/\\mathrm{tors},\\Z)\\to \\Hom(H_q(X),\\Z)$ because $\\Z$ is torsion-free. Therefore I get an isomorphism $\\alpha:H^q(X)/\\mathrm{tors}\\to \\Hom(H_q(X)/\\mathrm{tors},\\Z)$. I.e.:\n\\begin{equation*}\n\\xymatrix{\n\t0\\ar[r] & \\Ext^1_\\Z(H_{q-1}(X),\\Z)\\ar[r] & H^{q}(X)\\ar[r]\\ar[d] & \\Hom(H_q(X),\\Z)\\ar[r] & 0\\\\\n & & H^q(X)/\\mathrm{tors}\\ar[ur]^{\\cong}\\ar[r]^{\\alpha} & \\Hom(H_q(X)/\\mathrm{tors}/\\Z)\\ar[u]^{\\cong}\n}\n\\end{equation*}\nOr I could say it like this: the Kronecker pairing can be quotiented by torsion, and you get an induced map $H^q(X)/\\mathrm{tors}\\otimes H_q(X)/\\mathrm{tors}\\to\\Z$ is a perfect pairing, which means that the adjoint map $H^q(X)/\\mathrm{tors}\\xrightarrow{\\cong}\\Hom(H_q(X)/\\mathrm{tors},\\Z)$. Let's combine this with Poincar\\'e duality.\n\nLet $X=M$ be a compact oriented $n$-manifold. Then $H^{n-q}(X)\\xrightarrow{-\\cap[M],\\cong}H_q(M)$, and so we get a perfect pairing $H^q(X)/\\mathrm{tors}\\otimes H^{n-q}(X)/\\mathrm{tors}\\to\\Z$. And what is that pairing? It's the cup product! We have:\n\\begin{equation*}\n\\xymatrix{\n\tH^q(M)\\otimes H^{n-q}(M)\\ar[r]\\ar[d]_{1\\otimes(-\\cap [M])} & \\Z\\\\\n\tH^q(M)\\otimes H_q(M)\\ar[ur]_{\\langle,\\rangle}\n}\n\\end{equation*}\nAnd, well:\n\\begin{equation*}\n\\langle a,b\\cap [M]\\rangle = \\langle a\\cup b,[M]\\rangle\n\\end{equation*}\nThus the map $H^q(M)\\otimes H^{n-q}(M)\\to \\Z$ is $a\\otimes b\\mapsto\\langle a\\cup b,[M]\\rangle$, and it's a perfect pairing. This is a purely cohomological version, and is the most useful statement.\n\\begin{example}\nSuppose $M=\\CP^2=D^0\\cup D^2\\cup D^4$, and its homology is $\\Z \\, 0 \\, \\Z \\, 0\\, \\Z$, and so its cohomology is the same. Let $a\\in H^2(\\CP^2)$. Then we have $H^2(\\CP^2)\\otimes H^2(\\CP^2)\\to \\Z$, and so $a\\cup a$ is a generator of $H^4(\\CP^2)$, and hence specifies an orientation for $\\CP^2$. The conclusion is that $H^\\ast(\\CP^2)=\\Z[a]/(a^3)$ where $|a|=2$.\n\nHow about $\\CP^3$? It just adds a $6$-cell, so its homology is $\\Z \\, 0 \\, \\Z \\, 0\\, \\Z \\, 0 \\, \\Z$, and so its cohomology is the same. But then $a^3=a\\cup a\\cup a$ is a generator of $H^6(\\CP^2)$, and etc. Thus in general, we have:\n$$H^\\ast(\\CP^n)=\\Z[a]/(a^{n+1})$$\nThese things are finite CW-complexes, so you find:\n\\begin{equation}\nH^\\ast(\\CP^\\infty)=\\Z[a]\n\\end{equation}\n\\end{example}\n\\begin{example}\nSuppose I look at maps $f:S^m\\to S^n$. One of the most interesting things is that there are lots of non null-homotopic maps $S^m\\to S^n$ if $m>2$. For example, $\\eta:S^3\\to S^2$ that's the attaching map for the $4$-cell in $\\CP^2$. This is called the Hopf fibration. It's essential. Why is it nullhomotopic? If $\\eta$ was null homotopic, then $\\CP^2\\simeq S^2\\wedge S^4$. That's compatible with the cohomology in each dimension, but not into the cohomology ring! There's a map $S^2\\wedge S^4\\to S^2$ that collapses $S^4$, and the generator in $H^\\ast(S^2)$ has $a^2=0$, so $a^2=0$ in $H^\\ast(S^2\\wedge S^4)$. But this is not compatible with our computation that $H^\\ast(\\CP^2)=\\Z[a]/(a^3)$ where $|a|=2$.\n\\end{example}\n\nWith coefficients in a field $k$, then the torsion is zero, so you find that if $M$ is compact $k$-oriented, then if the characteristic of $k=2$, there's no condition for $M$ to be oriented, and if the characteristic of $k$ is not $2$, then $M$ is $\\Z$-oriented. Thus we get that $H^q(M;k)\\otimes_k H^{n-q}(M;k)\\to k$ is a perfect pairing.\n\\begin{example}\nExactly the same argument as for complex projective space shows that:\n\\begin{equation*}\nH^\\ast(\\RP^n;\\FF_2)=\\FF_2[a]/(a^{n+1})\n\\end{equation*}\nwhere $|a|=1$. So:\n\\begin{equation}\nH^\\ast(\\RP^\\infty;\\FF_2)=\\FF_2[a]\n\\end{equation}\nwhere $|a|=1$.\n\\end{example}\nI'll end with the following application.\n\\begin{theorem}\nSuppose $f:\\RR^{m+1}\\supseteq S^m\\to S^n\\subseteq \\RR^{n+1}$ that is equivariant with respect to the antipodal action, i.e., $f(-x)=-f(x)$. Then $m\\leq n$.\n\\end{theorem}\nSo there are \\emph{no} equivariant maps from $S^m\\to S^n$ if $m>n$!\n\\begin{proof}\nSuppose I have a map like that: the map on spheres induces a map $\\overline{f}:\\RP^m\\to\\RP^n$. We claim that $H_1(\\overline{f})$ is an isomorphism. Let $\\pi:S^n\\to\\RP^n$ denote the map. Let $\\sigma:I\\to S^m$ be defined via $\\sigma(0)=v$ and $\\sigma(1)=-v$. So this gives a $1$-cycle $\\sigma:I\\to S^m\\to\\RP^m$, and $H_1(\\RP^n)=[\\pi\\sigma]$ is generated by this thing. When I map this thing to $\\RP^n$, we send $\\pi\\sigma$ to a generator. What we've actually proved, therefore, is that $H_1(\\RP^m)\\cong H_1(\\RP^n)$. This is also true with mod $2$ coefficients, i.e., $H_1(\\overline{f},\\FF_2)\\neq 0$.\n\nThat means that $H^1(\\overline{f};\\FF_2)\\neq 0$ by UCT. But what is this? This is a map $H^1(f;\\FF_2):H^\\ast(\\RP^n;\\FF_2)\\to H^\\ast(\\RP^n;\\FF_2)$, i.e., a map $\\FF_2[a]/(a^{n+1})\\to \\FF_2[a]\\to(a^{m+1})$. Thus $a\\mapsto a$. There's not a lot of ways to do this if $m>n$. Thus what we've shown that $m\\leq n$.\n\\end{proof}\nThis is the Borsuk-Ulam theorem from the '20s, I think. This is an example of how you can use the cohomology ring structure for projective space.\n\nPlease check the website for details about your finals. I will ask you to sign a form, to make sure that you don't share the questions or that you haven't heard the questions beforehand. I have a fixed set of questions that'll guide the conversation.\n", "meta": {"hexsha": "0e7d3f1e5460ac1e62ae983e9e1b782c7cd4522a", "size": 7926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-38-the-end-applications.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-38-the-end-applications.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-38-the-end-applications.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 87.0989010989, "max_line_length": 704, "alphanum_fraction": 0.6765076962, "num_tokens": 2922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.6544280181266614}}
{"text": "\\section{Join Ordering}\nJoin ordering focuses on conjunctive queries with simple predicates of the type $a_1 = a_2$ where the latter can be either an \\textbf{attribute} or a \\textbf{constant} (commonly algorithms assume join between \\textit{attributes}).\n\nRelations may include selections or complex building blocks, however for simplicity filtering is ignored; having operators other than equality might cause differences within the query planner.\n\nOrdering basically means choosing \\textit{which relation to be joined first}, placing entities in a graph and adding an edge whenever a predicate from a node is joined to another. \n\nThis kind of schema is defined as a \\textbf{query graph}, in which edges consist in predicates and self loops represent equality with a constant. Usually cycles are pushed down, since algorithms only assume attributes. \n\nBased on the query graph it is possible to obtain an overview of the complexity of the problem: there are different shapes which are treated differently. \n\n\\begin{figure}[h]\n\t\\includegraphics[scale=1.5]{query_graph.png}\n\t\\centering\n\\end{figure}\n\n\\begin{enumerate}\n\t\\item \\textbf{Chains} are the simplest kind of query, fairly common in practice;\n\t\\item \\textbf{Cycles} (cyclic) are a chain with a closing edge, the easiest example of cycles;\n\t\\item \\textbf{Stars} are mostly used in data warehouse, in which the center table has large dimension and the ones outside are relatively small, quite different to solve;\n\t\\item \\textbf{Cliques} are instances in which every relation is joined with all the others, and are the hardest to optimize causing the worst runtime;\n\t\\item \\textbf{Trees} are acyclic queries even if the level of nesting can be high;\n\t\\item \\textbf{Grids} are also fairly hard and interesting for research.\n\\end{enumerate}\n\nJoins are represented with \\textbf{join trees}, binary trees with operators as inner nodes and relations as leaves. The most common type is unordered (not distinguish left from right) without cross product, however algorithms might produce other variants.\n\nThere furthermore are different kinds of trees:\n\\begin{itemize}\n\t\\item \\textbf{Left-deep} tree, in which joins only happen on the left side, easy to represent and implement through hash tables ($n!$ trees with cross products);\n\t\\item \\textbf{Right-deep} tree ($n!$);\n\t\\item \\textbf{Zig-zag} tree, a combination of the previous ($n!2^{n-2}$);\n\t\\item \\textbf{Bushy} tree, a full binary tree (non-linear, harder to find optimal solutions but can be the most efficient in some cases, $n!C(n-1) = \\frac{(2n-2)!}{(n-1)!}$ where $C$ represents a Catalan number).\n\\end{itemize}\nIt is relevant to notice that the number of leaf combinations and unlabeled trees grows \\textbf{exponentially}, and increases even more with a flexible structure. However, nodes can often be swapped from left to right.\n\nAnother important information about joins is their \\textbf{selectivity}, the amount of tuples which will result from an equivalence between two attributes: \n$$f_{i, j} = \\frac{\\abs{R_i \\bowtie_{p_{i, j}} R_j}}{\\abs{R_i \\times R_j}}$$\nThis depends on whether the attributes are a key, and gives an estimation of the result cardinality with the aid of assumptions and statistics.\n\nGiven a join tree, the \\textbf{cardinality} (size of the cross product) can be computed recursively as the productory of the selectivity function multiplied by the size of both relations. This allows easy calculations only requiring base cardinalities and independence of predicates:\n$$C_{out}(T) = \\begin{cases}\n0 & T\\text{ is a leaf} \\\\\n\\abs{T} + C_{out}(T_1) + C_{out}(T_2) & T = T_1 \\bowtie T_2\n\\end{cases}$$\nThis formula sums up the sizes of intermediate results, which are the ones causing more works. There are basic specific cost functions for joins, to be summed to the cost of single relations. \n\nAlgorithms are mainly designed for left-deep trees, and some of the cost functions do not work in practice, for instance in the case of cross products. Therefore, those indicators are mainly theoretical and work under strict assumptions. However, join ordering is a main factor \\textit{regardless of the chosen cost methods}.\n\nMost of the time, algorithms for query optimization tend to avoid cross products, despite the enormous number of possibilities to build a join tree: the only exception regards small relations.\n\n\\subsubsection{Symmetry and ASI}\nA cost function is called symmetric if $C_{impl}(e_1 \\bowtie^{impl} e_2) = C_{impl}(e_2 \\bowtie^{impl} e_1)$. Commutativity can be ignored.\n\nASI (Adjacent Sequence Interchange) are a set of properties characterizing simple cost functions, consisting in swapping two adjacent sequences with a larger one. They are relevant since some operations should be performed before others, to optimize costs. \n\n\\textit{Let \\textbf{f} be ASI with rank function \\textbf{r}, and let $\\vec s$ and $\\vec t$ be strings. Consider a job module $\\{\\vec s, \\vec t\\}$ in a general precedence graph, where $\\vec s \\rightarrow \\vec t$ and $r(\\vec t) \\leq r(\\vec s)$. Then there is an optimal permutation with $\\vec s$\nimmediately preceding $\\vec t$.}\n\nThis property will be exploited in one of the most famous join ordering algorithms (IKKBZ), which heavily relies in swapping sequences.\n\n\\subsubsection{Chains}\nChains usually originate a left-deep tree: leaves can be ordered according to different degrees of freedom, as long as all the relations are joined. \n\nThe number of possible left-deep trees can be defined recursively:\n$$\\begin{cases}\nf(0) = 0 \\\\\nf(1) = 1 \\\\\nf(n) = 1 + \\sum_{k=1}^{n-1} f(k-1) \\cdot (n - k)\n\\end{cases}$$\nAdding $R_n$ to all possible join trees can be done at any position following $R_{n-1}$. There are $n - k$ join trees for $R_n$, plus one assuming it can be placed before $R_{n-1}$ in the case of $k=1$. For $R_{n-1}$ to be at $k$, $R_{n-k} - \\dots R_{n-2}$ must be below it.\n\nSolving the recurrence gives the closed form $f(n) = 2^{n-1}$, still exponential yet much smaller than the case with cross products.\n\nA generalization to zig-zag can be made expecting the same result.\n\nBushy trees, on the other hand, are not so easy to obtain: each subtree must contain a subchain to avoid cross products, hence single relations should not be added. It is possible to create a whole chain $R_1 - \\dots R_n$, cut it and place it under another subtree, always considering commutativity.\n\nThis gives the formula:\n$$ f(n) = \\begin{cases}\n1 & n < 2 \\\\\n\\sum_{k=1}^{n-1} 2f(k) \\cdot f(n-k) & n \\geq 2\n\\end{cases}$$\nHaving more than 2 relations implying performing a cut at some point $k$ and placing $k$ on the left side, $n - k$ on the right side. A factor of 2 indicates swapping the two sides. \n\nThis gives the closed form $f(n) = 2^{n-1}C(n-1)$.\n\n\\subsubsection{Stars}\nStar queries have the constraint that \\textit{one relation must be in the center}; all the others can be ordered arbitrarily. This leads to the following formulas:\n\\begin{itemize}\n\t\\item Left-deep: $2 \\cdot (n - 1)!$, since there are $n - 1$ choices for a join partner and a factor of 2 for commutativity;\n\t\\item Zig-zag: $2 \\cdot (n - 1)! \\cdot 2^{n-2}$, in which the last factor represent the possibility to swap left and right for each subtree;\n\t\\item Bushy trees: not possible since they require the first relation to be available. \n\\end{itemize}\n\n\\subsubsection{Cliques}\nCliques are a schema which do not care about cross products, since every relation is connected to the other, hence the number of possibilities is the same as the one obtained allowing cross products. \n\nStill, complexity is very high and runtime is bad, although the worst case usually does not happen. \n\n\\subsection{Greedy heuristics}\nRegardless of the methods and the inclusion of cross products, the search space is in general quite large when the number of relations is larger than 10, and polynomial time is hard to achieve. Some cost functions do not even have a proof of complexity.\n\nDue to the size of the search space, greedy heuristics are ways to easily construct a potential tree in a fast time: they are most suitable for \\textbf{large queries}, but often do not give the best result.\n\nThis class of algorithms assumes no cross products within left-deep trees, and known cardinalities (or some other weight function).\n\n\\subsubsection{GreedyJoinOrdering-1}\nThis algorithm returns a set of ordered relations to be joined according to a cost function in a bushy tree structure, which in this case is the size of each node. \n\nThe output is given starting from the \\textbf{minimum-weight relation}, removes it and searches for the new minimum. \n\nThis method is simple, but not that good in practice: it assumed fixed weight (not depending on the size, for instance) and does not support optimization within intermediate results. \n\n\\subsubsection{GreedyJoinOrdering-2}\nThis variant also considers the \\textbf{previous set of relations}, computing relative weights based on the existing tree. The only difference with the first version is the computation of minima considering also previous results.\n\nIn this case, however, the very first relation has a large relative weight and a major impact on the choices made afterwards. \n\n\\subsubsection{GreedyJoinOrdering-3}\nTo tackle the problem introduced by the second version, a double loop is employed in which not only the set of relations is scanned, but also every relation is tested as a starting one. Then, all computed results are compared and the minimum among them is returned. \n\nThis method is overall the best one and is implemented in some systems, but it is still not optimal.\n\n\\subsubsection{Greedy Operator Ordering}\nThis algorithm is a more complicated heuristic approach allowing to find \\textbf{bushy trees}, while the others are limited to left-deep shapes, taking advantage of semantic information to produce a good join ordering.\n\nIntermediate join trees must be combined in a bottom-up way to obtain larger trees: since some algorithms construct left-deep structures and others return bushy trees, those can be attached if the result is minimal: trees with the smallest weight are iteratively joined and then removed by the set of possibilities. \n\nThe core idea is to \\textit{always perform the most profitable joins first}, according to the size of intermediate results, taking into account earlier steps as well and aiming to lower the cost of intermediate results. After two nodes are selected from the query graph, GOO always updates it to reflect the new cardinalities and selectivities.\n\nThe algorithm constructs an optimal operator tree by \\textbf{merging pairs of graph nodes}. First, each combination of weight (for instance, product of cardinalities and selectivity) is calculated; then the minimum is chosen and the two relations are aggregated into a new one, changing related edges. \n\nIn case both relations are linked to the same (different) one in the query graph, the selectivity of the new edge consists in the product of previous ones. The process is iteratively repeated until only one node is left. \n\nThis algorithm has two pitfalls: one is its computational complexity of $O(n^3)$, which however can be in the order of milliseconds with small input, and the other is its suboptimal output in some cases.\n\nIt is not possible to speed the execution up through auxiliary data structures such as the heap, since weights are modified at each iteration. Furthermore, it is not guaranteed that Greedy Operator Ordering finds the best bushy tree given a set of relations, even if it tends to have better results than the greedy ordering techniques.\n\n\\subsection{IKKBZ}\nIKKBZ is a \\textbf{polynomial time} algorithm for join ordering without cross products, producing \\textbf{left-deep trees} under some assumptions: \\textit{acyclic graphs, ASI cost functions and a fixed join technique}. It was built in two phases: IK, the first proposal, and IKKBZ, the improved version which is currently used.\n\nThe general idea is considering each relation as starting point, trying to obtain a benefit ordering based on a rank function, and constructing compounds if any set violates ordering rules.\n\nThe algorithm will ultimately compute a rank for each predicate, based on its selectivity, obtaining an optimal evaluation order. After the first steps, however, the remaining arguments are independent on the size of the relations.\n\nIt starts considering a cost function as a product of the form:\n$$C(T_i \\bowtie R_j) = \\abs{T_i} \\cdot h_j(\\abs{R_j})$$\nEach relation $R$ can have its own $h$ (cost for each relation), which has a set of parametrized cost functions $C_H$ (cost for a join). Cardinalities are also taken into account, defining $n_i = \\abs{R_i}$ and $h_i(n_i)$ as the cost per input tuple of a join. $T_i$ is the left side of the computation.\n\nA \\textbf{predecence graph} helps identifying which relations should be joined first; it is represented as an oriented query graph, and constructed with root in $R_k$ in the following way:\n\\begin{enumerate}\n\t\\item The root is fixed, removed by the set of possibilities and added to the tree;\n\t\\item As long as there are relations to be chosen, $R_i \\in V \\setminus V_k^P$ is selected such that $\\exists\\ R_j \\in V_k^P : (R_j, R_i) \\in E$;\n\t\\item $R_i$ is added to $V_k^P$ and an edge $R_j \\rightarrow R_i$ is created.\n\\end{enumerate}\n\nRemainder: the algorithm constructs left-deep trees.\n\nNext steps of the algorithms consist in checking whether the nodes respect properties. A sequence of nodes conforms to a precedence graph if two conditions are satisfied:\n\\begin{itemize}\n\t\\item For each position $i$ aside from the first, there exists one $j$ coming before;\n\t\\item There does not exist a position $i$ and a $j$ coming after with an edge from $j$ to $i$ (acyclic).\n\\end{itemize}\n\nIf there exists a path between two sets $R_i$ and $R'_i$, all relations from the first must be joined first; there is no join condition between any pair of relations aside from the one joining the two sets, hence the selectivity is 1.\n\nSelectivity of the join:\n$$s_i = \\begin{cases}\n1 & \\abs{R_i'} = 0 \\\\\n\\prod_{R_j \\in R'_i} f_{i, j} & \\abs{R'_i} > 0\n\\end{cases}$$\nIn case of cycles, the selectivity cannot be uniquely determined: there could be two relations with different values. Therefore, first the precedence graph is fixed, and then selectivities are calculated.\n\nIf the query graph is a chain (total order), then the following properties hold:\n$$n_{1, 2, \\dots, k} = \\prod_{i=1}^{k}s_in_i$$\n$$C_H(G) = \\sum_{i=2}^{n}\\big[n_{1, 2, \\dots, i-1}h_i(n_i)\\big] = \\sum_{i=2}^{n}\\Big[\\Big(\\prod_{j=1}^{i}s_jn_j\\Big)h_i(n_i)\\Big]$$\nThe cardinality of the joins is equal to the productory of each selectivity for each cardinality among all relations.\n\nIf the \\textbf{weight function} is indeed the \\textbf{selectivity}, then $C_H \\equiv C_{out}$. The factor $s_in_i$ determines how much the input relation changes its cardinality before further joins, and can be increasing or decreasing.\n\nThe algorithm employs a recursive definition of the cost function:\n$$\\begin{cases}\nC_H(\\epsilon) = 0 \\\\\nC_H(R_i) = 0 & \\text{the relation is the root} \\\\\nC_H(R_i) = h_i(n_i) & \\text{else} \\\\\nC_H(S_1S_2) = C_H(S_1) + T(S_1) \\cdot C_H(S_2)\n\\end{cases}$$\n$$T(\\epsilon) = 1 \\qquad \\land \\qquad T(S) = \\prod_{R_i \\in S}s_in_i$$\nLast $C_H$ definition corresponds to the cardinality performing all the relation in the sequence (the term $T$) and multiplying for the cost of last element.\n\nThis allows to use \\textit{ASI properties}: in fact, these hold if and only if there exists a function $T$ and a \\textbf{rank function} defined as:\n$$rank(S) = \\frac{T(S) - 1}{C(S)}$$\nThe following must hold:\n$$C(AUVB) \\leq C(AVUB) \\leftrightarrow rank(U) \\leq rank(V)$$\nIn other words, ASI properties hold if and only if the relations can be ordered by rank. The previously defined cost function can be proven to respect these constraints.\n\nIt is possible that the rank contradicts the precedence graph: the following definition is introduced to counter this occurrence.\n\nLet $M = \\{A_1, \\dots, A_n\\}$ be a set of sequences of nodes. Then $M$ is called a module if, for all sequences $B$ that do not overlap with the sequences in $M$, one of the following conditions holds:\n\\begin{itemize}\n\t\\item $B \\rightarrow A_i, \\forall\\ A_i \\in M$;\n\t\\item $A_i \\rightarrow B, \\forall\\ A_i \\in M$;\n\t\\item $B \\nrightarrow A_i \\land A_i \\nrightarrow B, \\forall\\ A_i \\in M$.\n\\end{itemize}\n\nIf $A \\rightarrow B$ and $rank(B) \\leq rank(A)$, then it is possible to find an optimal sequence among those in which $B$ directly follows $A$.\n\nIf the precedence graph contains $A \\rightarrow B$ but $rank(A) \\geq rank(B)$, there is a so called \\textbf{contradictory sequence}, and the two are combined, updating other edges by multiplying the cardinalities and selectivities. \n\nThe continued process of building a compound relation until no more contradictory sequences exist is called \\textbf{normalization}; the opposite is \\textbf{denormalization}.\n\nIKKBZ works performing the following steps for each relation, considering it as a root node:\n\\begin{enumerate}\n\t\\item Calculates the precedence graph;\n\t\\item Executes the subprocedure of finding the subtree all of whose children are chains, and normalizing it, then merging the chains;\n\t\\item The relation returned by the previous step is added to the set.\n\\end{enumerate}\nThe algorithm stops when all trees are single chains, then returns the minimum of the sets according to the cost function.\n\nThe subprocedure constructs a left-deep tree (chain) from the precedence graph, performing a normalization operation and merging based on the rank in ascending order. Normalization happens when there is a contradictory sequence, i. e. one chain has bigger rank than the following.\n\nThis works by taking $r$ and $c$ such that $rank(r) > rank(c)$ and swapping them with a compound relation representing both. This allows to merge relations that would have been reordered if only considering the rank, obtaining the actual ascending order.\n\nIn case the graph contains cycles, it is possible to preprocess it with algorithms such as Minimum Spanning Tree to find a suitable representation to run IKKBZ.\n\n\\subsubsection{IK}\nIK was originally proposed as a heuristic algorithm to minimize the number of page fetches necessary to evaluate a nested loop query in a database, providing a suboptimal solution to a NP-complete problem. \n\nThe paper states the impossibility to solve optimization of the expected number of accesses, yet it determines the solution in the special case in which a query is a tree. \n\nSorting each relation once gives an useful advantage since it decreases the number of pages in which tuples are looked for: if $T_i$ satisfies an attribute, $T_{i+1}$ will likely do it too, and it will be stored right below. This saving usually compensates the cost to sort.\n\nThe $H_i$ in this case is the total \\textbf{number of page fetches}, and all other formulas are similar, taking advantage of pointers and approximation in practice to estimate actual costs.\n\nOnce found a somewhat accurate cost function, the problem of finding an optimal nested structure is divided into:\n\\begin{enumerate}\n\t\\item Finding a nesting order;\n\t\\item Finding a compatible directed spanning tree.\n\\end{enumerate}\n\nA brute force approach would take up to $n!$ permutations into account, which is not feasible: a criterion must be imposed, generally the lexicographical order of the costs of each relation, in which $H$ should be the most dominant and uniquely determined.\n\nFor each relation in the query graph, the one minimizing $H$ is chosen and removed from the set, along with its incident edges, and the final order of choices is returned. This generates a \\textbf{spanning tree}, hence removes all the cycles, in $O(n^3)$. \n\nTree queries are a special case in which \\textbf{direction of edges} is used as ordering constraint: if there is a path between two nodes, then the first must be ordered before the second. The minimization problem then becomes equivalent to minimizing the sum of all cost functions, taken in the best order.\n\nThanks to ASI properties, an optimal sequence can be obtained in $O(n\\log n)$ when the constraints have the form of a directed tree. The algorithm repeatedly finds a \\textbf{wedge}, i. e. two chains joined together at the end, and merges it to get a new chain, until it ends up with only one. At each iteration, a node keeps a well-defined rank regardless of its representation.\n\nAfter the algorithm terminates, each node is again expanded by replacing it by the corresponding sequence of relations, ordered accordingly by their rank. \n\nEach node is considered as starting node, and the best solution over all is chosen, with a total computational runtime of $O(n^2\\log n)$.\n\n\\subsubsection{KBZ}\nKBZ is a variant of IK shown to be heuristically effective for cyclic queries as well, and works comparing different alternatives for each element of the search space. \n\nIt improves IK since it supports different join methods, preprocessing and pushing selects, and it is also better in runtime: its worst case is $O(n^2)$, removing the logarithmic weight caused by the sorting.\n\nThis approach assumes a \\textit{memory resident database}, i. e. there is no paging to disk during the execution. Once again, having the query graph as a tree defines a \\textbf{partial ordering}: the root node must be joined first. \n\nSelectivity of each node here is explicitly defined as the selectivity of the join between it and its \\textbf{parent}, since there is only one, and for the root it is unity: the consequence of this is, given the total ordering, a non-root relation joins with its parent first. Therefore, the best join method can be determined independently from the tree shape.\n\nFor a given tree derived by a query, therefore, two properties must hold for consistency:\n\\begin{itemize}\n\t\\item The sequence is complied with the imposed partial order from the root;\n\t\\item A join operation (not a cross product) must be performed at each non-leaf node.\n\\end{itemize}\n\nCost and computation of cardinality and selectivity remain the same as IK, yet the restrictions above and \\textit{not having more than one temporary relation used in any join operation} limit the search space. \n\nHowever, the approach is slightly different: KBZ presents a method to find the optimal tree which is more efficient than computing the cost for each choice of the root. \n\nFirst of all, the original join tree is transformed so that the total order is respected, imposing that the root has only two children. The core idea is that computations corresponding to two choices for the root have a lot in common, especially if the roots are adjacent. \n\nThen, there is a phase of computing the rank of each relation, and merging in case of contradictory sequences. Cycles can be eliminated by considering the Minimum Spanning Tree.\n\n\\subsection{Maximum Value Precedence}\nMaximum Value precedence is useful in those cases where IKKBZ fails, such as \\textbf{cyclic queries}. It runs in polynomial time ($O(n^2)$) as well, employing a graph theoretic approach to calculate in how many ways joins can be scheduled.\n\nThis approach also provides a formal representation for operations of query and optimization parameters in an uniform manner, giving a cost once an execution plan is obtained in the form of a spanning tree.\n\nThe algorithm requires a weighted directed \\textbf{join graph}, similar to the ones discussed before, which will be modified later, hence the definition must be extended: edges are assigned an \\textbf{order}, and \\textbf{predicates} (nodes) are used to identify sets.\n\nIn this representation, each node corresponds to a join, and a directed edge indicates the order of execution. If there exists an edge between the predicates $p_1$ and $p_2$, and they belong to the same relation, two directed edges are added in the graph.  \n\nIf $p_1$ is connected to $p_2$ and $p_2$ is connected to $p_3$, there will be a so called \\textit{virtual edge} connecting $p_1$ and $p_3$: eventually, all nodes will be connected with either physical or virtual edges, forming a clique.\n\n\\begin{wrapfigure}{R}{0.45\\textwidth}\n\t\\vspace{-20pt}\n\t\\includegraphics[width=0.48\\textwidth]{MVP.png}\n\t\\vspace{-30pt}\n\\end{wrapfigure}\n\nFor instance, \\textbf{every spanning tree in the directed join graph leads to a join tree}: first of all edges are added in both direction, and then one of them gets removed, giving a directed acyclic graph which can easily give a join order (without distinguishing left and right).\n\nMVP has the advantage of also producing bushy trees, however it does not guarantee optimality of the spanning tree; furthermore, the output might not correspond to an effective join tree, especially in uniprocessor environments.\n\nDespite the incorrect representation, it is simple to fix this kind of errors, but there is no specific way to produce the best join tree.\n\nTo remedy the uncertainty, some additional rules are introduced to identify an \\textbf{effective} spanning tree, which also help reducing the search space.\n\n\\textit{For a given query $R_1 \\bowtie R_2 \\bowtie \\dots \\bowtie R_n$, an effective spanning tree of this query is a directed binary spanning tree of its corresponding weighted directed join graph such that query result is obtained without requiring to execute any extra joins in addition to the joins of the spanning tree.}\n\nThe following conditions must be satisfied:\n\\begin{enumerate}\n\t\\item $T$ must be binary (no nodes can have more than two children);\n\t\\item For all inner connected nodes $(u, v)$, $R(T(u)) \\cap R(v) \\neq \\emptyset$ (they must have predicates in common);\n\t\\item For all $(u_1, v)$, $(u_2, v)$ one of the following holds:\n\t\\begin{enumerate}\n\t\t\\item $((R(T(u_1)) \\cap R(v))) \\cap ((R(T(u_2)) \\cap R(v))) = \\emptyset$ (they have a different relation in common);\n\t\t\\item $(R(T(u_1)) = R(v)) \\land (R(T(u_2)) = R(v))$ (the relations in common are the same between pairs).\n\t\\end{enumerate}\n\\end{enumerate}\nAn effective spanning tree corresponds to a \\textit{valid join tree}, despite the definition not being intuitive. Given this, the rest of the assumptions is simple: if every predicate involves two relations and an equi-join condition, then $R(u) \\cap R(v)$ contains only a single relation.\n\nLet $v$ be that relation, then $R_i \\bowtie_v R_j$ is abbreviated by $\\bowtie_v$.\n\nThe next step is adding weight to the edges, obtaining a weighted directed join graph. Each weight is calculated with the formula:\n$$w_{u, v} = \\frac{\\abs{\\bowtie_u}}{R(u) \\cap R(v)}$$\nThis means that each edge has a weight depending on the relation they have in common and the first join cardinality. The intuition implies that if a join is \\textit{executed before another}, the given relation becomes available and the edge weight can explain how the cardinality changes, i. e. how many tuples are generated.\n\nThis value can be bigger or smaller than 1, and can make the total cost bigger or smaller (the input size changes by a factor of $w_{u, v}$). For virtual edges, the weight is 1 by default. \n\nIt is relevant to notice that the weight function used by MVP is the same one as $s_i$ in IKKBZ. However, it can also be chosen arbitrarily.\n\nOf course, a weight smaller than 1 reduces the cost of following join operations. Furthermore, weights change over time depending on a partial spanning tree: \n$$w(p_{i, j}, S) = \\frac{|\\bowtie_{p_{i, j}}^S|}{\\abs{R_i \\bowtie_{p_{i, j}} R_j}}$$\n$\\bowtie_{p_{i, j}}^S$ is the result of the join after all joins preceding $p_{i, j}$ in $S$ have been executed. If the spanning tree is empty, the cost is merely equal to the cost of a simple join. \n\n\\subsubsection{The algorithm}\nThe algorithm works in two phases:\n\\begin{enumerate}\n\t\\item Taking the edges with weight smaller than 1, trying to reduce the work for latter operators as soon as possible;\n\t\\item Adding the remaining edges, potentially causing an increase of the load, yet as late as possible.\n\\end{enumerate}\nAs a weighted directed join graph contains all execution plans of a query and each spanning tree corresponds to an execution plan, the task is to find the minimum cost. However, the minimum spanning tree algorithm cannot be directly applied, since the weights are not constant (they change after each modification). \n\nThe rational is therefore reducing the expensive operations as early as possible. In order to meet this goal, two priority queues are introduced along with two phases, one with largest weights (phase 1) and one with smallest (phase 2). \n\nThe working graph is initially just a set of predicates with no edges, and then the two phases are ran, sorting costs of vertices in descending order.\n\nThe first phase modifies the state of a working tree, taking the head of the first priority queue (the \\textbf{most expensive}) and finding the joins which could make it cheaper, adding nodes with smaller weight while still keeping the graph acyclic. \n\nThe working graph is updated, removing the edge and adding respective virtual ones until no edges can reduce costs, or there are no further nodes with weight less than 1.\n\nIn this case, the cheapest node is swapped from the first queue to the second; else, the edge to be added to the working tree will be the one which maximizes the difference within costs (minimizes the new cost). Weights are then recomputed. \n\nPhase 2 is called when the second queue is non-empty, again considering edges which respect the acyclic property. The procedure tries to minimize the additional cost caused by adding joins, finding edges causing minimum increase of the total result. \n\nThe motivation behind phase 2 is that if an edge causes a large cost increase to its connecting join node, then the effect of this will propagate to all the rest join nodes; hence, these need to be considered as late as possible.\n\nTo effectively modify the working tree, an update function changes the state by performing unions of sets with edges and removal from the graph yet to consider. If there are two incoming physical edges, they are replaced with virtual ones. \n\nThis also ensures the binary property, removing all cases in which a node could have two parents and handling eventual duplicates. However, there is still no guarantee of optimality. \n\n\\subsection{Dynamic Programming}\nDynamic programming approaches can be useful to obtain more insights on possible orders with cost function. Since this kind of algorithm is a macro class, they can be defined on \\textbf{any input} and give \\textbf{any output} (bushy, left-deep).\n\nThese work thanks to an optimality principle: if an option is cheaper than another, \\textit{the latter can be discarded} and the best solution is found only considering the set of further possibilities generated by the first.\n\nFormally, let $T$ be an optimal join tree for relations $R_1, \\dots, R_n$. Then, \\textit{every subtree $S$ of $T$ is an optimal join tree for the relations contained in it}.\n\nDespite some hypothetical concerns of suboptimality and the presence of physical properties which may alter the result, in practice this property holds.\n\n\\begin{wrapfigure}{L}{0.49\\textwidth}\n\t\\vspace{-10pt}\n\t\\includegraphics[width=0.5\\textwidth]{search_space.png}\n\t\\vspace{-40pt}\n\\end{wrapfigure}\n\nThe strategy works starting with a single relation and generating larger trees with a \\textbf{bottom-up strategy}, reusing previous intermediate results.\n\nA possible dynamic programming algorithm calculates the cost functions when joining either on the left or right side (bushy usually works better) for each applicable join implementation. \n\nThe outcome will be a list of pairs with their cost, of which the minimum is chosen and propagated through following iterations.\n\nThe search space gets therefore reduced whenever an option is discarded, hence the number of combinations is never exponential.\n\n\\subsubsection{DPsize}\nIn the case of linear trees, there is a basic strategy which works finding the optimal $T$ by joining all optimal $T'$ with $T \\setminus T'$, with $|T| = |T'| + 1$.\n\nThe most common algorithm is DPsizeLinear: it constructs the optimal \\textbf{left-deep} tree from an empty table mapping the set of relations ($2^R$) to the join tree. \n\nFor each relation, the optimal tree is built, starting from \\textbf{size} 1 and increasing the subsets by adding those of smaller size having the optimal solution of the subproblem.\n\nDPsize is an alternative approach which allows bushy trees as well: the only difference is that instead of adding one relation at the time, subsets can be joined.\n\nIf $S$ is a subset of $\\{R_1, \\dots, R_n\\}$, before a join tree for it can be generated, the join trees for all relevant (valid) subsets of $S$ \\textit{must already be available}.\n\nFor instance, if the query graph is a chain, before computing the optimal order there must be calculations for each connected pair, and of course for single relations.\n\nDPsize can be made more efficient in case $s_1 = s_2 = \\frac{n}{2}$: representing plans as a linked list, it is possible to iterate through it to retrieve all plans joining $s_1$ relations, and considering the succeeding ones for $s_2$, decreasing the complexity to $s_1 \\cdot \\frac{s_2}{2}$.\n\n\\subsubsection{DPsub}\nDPsub is a dynamic programming alternative to DPsize, using \\textbf{integer order}, a numeration used to order relations instead of the size (subset-driven).\n\nThis representation can be seen as a binary number in which a digit is 1 if the set contains the relation corresponding to its position, and 0 otherwise. For instance, having three relations, $011$ is $\\{R_1, R_2\\}$.\n\nInteger order is used to fill the dynamic programming table, calculating all combinations for each $2 \\leq i \\leq 2^n-1$ and finding all subsets such that their \\textbf{binary representation} is 1.\n\nTo get a labeling, an intuitive way is to perform a breadth-first search on the tree picking any arbitrary root (any labeling is however accepted).\n\nThe real implementation does not perform any mathematical operation, since each $i$ already represents a set. \n\nThen, for each relation in the subset, the cost is added to smaller subproblems, similarly to the previous approach. The last bit of the set gets removed after every iteration.\n\nThis algorithm has even better performance when creating bushy trees, and its advantage is the speed of binary calculations (bitwise and). \n\nBushy trees can indeed be generated by combining two optimal trees (children of newly-found node). The dynamic programming principle holds.\n\nA basic strategy is in fact just optimizing over subproblems and aggregating them: the approach is similar to linear trees, with the variant that the combined size of each pair of intermediate result must be equal to $\\abs{S}$. Every relation must also appear once, hence $S_1 \\cap S_2 = \\emptyset$.\n\nConnectedness must also be tested, since the relations might not induce a connected subgraph. This is performed by checking whether there is a join predicate between relations.\n\nIn practice, the number of subsets is exponential, and most of the time sizes are not compatible: a possible implementation uses a linked list of all combinations, and edits it according to the next operation.\n\n\\begin{wrapfigure}{R}{0.52\\textwidth}\n\t\\vspace{-27pt}\n\t\\includegraphics[width=0.52\\textwidth]{dpsize_dpsub.png}\n\t\\vspace{-100pt}\n\\end{wrapfigure}\n\nInteger order is particularly efficient since the complement of a set ($S_2 = S \\setminus S_1$) is found in constant time when the representation is binary.\n\nAll subsets can be enumerated as follows:\n\\begin{lstlisting}[language=C++]\tS_1 = S & (-S)  // gives a number having only 1 as last bit\ndo {\n\tS2 = S - S1\n\tS1 = S & (S1 - S)  // same meaning as plus\n} while (S1 != S)\n\\end{lstlisting}\n\nComputational time is quite low, which is useful for a large amount of relations. However, it always depends on the number of combinations: DPsub is slower than DPsize in the polynomial case, and vice versa.\n\n\\subsection{Memoization}\nMemoization is a top-down formulation of dynamic programming, \\textbf{recursively} generating join tree in a way which allows to avoid duplicates and prune useless solutions.\n\nCode is easier to understand and sometimes more efficient, but usually slower due to recursiveness. However, it allows to generate bushy trees.\n\nThe memoization algorithm fills the table and then performs an auxiliary procedure for each subset: it checks whether the problem has \\textit{already been computed}, otherwise it splits the subset in two and recursively calculates the two values. At the end of all function calls, the best value is picked between the two and cost is returned. \n\nThe most performance-critical operation is the \\textbf{lookup} in the hash table of known combinations, which can be expensive making the whole procedure slow.\n\nThe advantage is the knowledge of a \\textbf{cost boundary} immediately after the first loop, meaning that in further iterations it is possible to propagate values so that more expensive plans can be discarded.\n\nHowever, eliminating solutions might prune other optimal combinations or force suboptimal sets: the table must be extended, also remembering failures, so that it is not necessary to run the procedure another time.\n\nThe cost boundary can grow \\textbf{exponentially}: a rule of thumb would be doubling it when searching for solutions and so on, ensuring a limited number of tries. \n\n\\subsection{Connected subgraphs and DPccp}\nFor large queries, it is not quite efficient to construct subproblems which will be discarded later since they do not correspond to a valid tree. On the other side, it is possible to argue that pruning typically removes invalid subsets.\n\nHaving the query graph also helps to reduce asymptotic search space (polynomial) for chains, while it does not work well for cliques (exponential). Dynamic programming is instead better for cliques, but scales badly.\n\nHowever, chains or quasi-chains are the most common kind of graph in real-world applications of joins, so the first approach is more useful in practice.\n\nConnected subgraphs are another alternative to dynamic programming taking into account the \\textbf{structure} of the query graph and the \\textbf{connectivity} of nodes. \n\nThis method is useful since, as previously stated, each variant of the two DP algorithms is superior to the other for one kind of query graph, but fails for the other, and neither is efficient for stars. Furthermore, it is very difficult to improve them while still excluding cross products.\n\nBefore introducing the algorithm, a few definitions should be stated:\n\\begin{enumerate}\n\t\\item A connected subset is a connected subgraph induced by a subset of relations;\n\t\\item \\texttt{csg} is the number of non-empty connected subsets;\n\t\\item A \\texttt{csg-cmp-pair} (connected subgraph-complement) is a pair $(S_1, S_2)$ such that:\n\t\\begin{itemize}\n\t\t\\item $S_1$, $S_2$ are non-empty and connected;\n\t\t\\item $S_1 \\cap S_= \\emptyset$;\n\t\t\\item There exists $v_1 \\in S_1$, $v_2 \\in S_2$ such that there is an edge between $v_1$ and $v_2$;\n\t\t\\item \\texttt{ccp} is the number of csg-cmp-pairs;\n\t\\end{itemize} \n\\end{enumerate}\nOf course, subsets should be also be connected with each other (a join predicate must exists) since cross products are to be avoided.\n\nThe approach aims to enumerate the number of connected subsets and csg-cmp-pairs, avoiding duplicates. There are some formulas which can be used wit $n$ relations:\n\\begin{itemize}\n\t\\item Chain queries:\n\t\\begin{itemize}\n\t\t\\item \\texttt{csg}($n$) = $\\frac{n(n+1)}{2}$;\n\t\t\\item \\texttt{ccp}($n$) = $\\frac{(n+1)^3 - (n+1)^2 + 2(n+1)}{3}$;\n\t\\end{itemize}\n\t\\item Cycle queries:\n\t\\begin{itemize}\n\t\t\\item \\texttt{csg}($n$) = $n^2 - n + 1$;\n\t\t\\item \\texttt{ccp}($n$) = $n^3 - 2n^2 + n$;\n\t\\end{itemize}\n\t\\item Star queries:\n\t\\begin{itemize}\n\t\t\\item \\texttt{csg}($n$) = $2^{n-1} + n - 1$;\n\t\t\\item \\texttt{ccp}($n$) = $(n-1)2^{n-2}$;\n\t\\end{itemize}\n\t\\item Clique queries:\n\t\\begin{itemize}\n\t\t\\item \\texttt{csg}($n$) = $2^n - 1$;\n\t\t\\item \\texttt{ccp}($n$) = $3^n - 2^{n+1} + 1$.\n\t\\end{itemize}\n\\end{itemize}\nExcept for clique queries, the number of csg-cmp-pairs is orders of magnitude less than the search space for other DP variants.\n\nThe main idea is therefore only considering pairs of connected subproblems, more precisely the csg-cmp-pairs, which also corresponds to the \\textbf{lower bound} of any dynamic programming algorithm. \n\n\\begin{figure}[h]\n\t\\includegraphics[scale=0.45]{dp.png}\n\t\\centering\n\\end{figure}\n\nTo summarize, join ordering formulated as a \\textit{graph theoretical problem} works with the following steps:\n\n\\begin{enumerate}\n\t\\item Enumerating all connected subgraphs among the query graph;\n\t\\item Enumerating all subsets which are disjoint but connected to the subgraph which is being considered;\n\t\\item Trying to join each connected subgraph with its complement pair;\n\t\\item Finding suitable combinations (DP algorithm).\n\\end{enumerate}\n\nThis approach can be merged with DP so that the latter works with already enumerated subgraphs, making it easier to get rid of invalid solutions.\n\nHowever, pairs have to be enumerated correctly and efficiently: this is a two-step procedure starting from the subsets and reaching supersets, avoiding commutative pairs and assuming a total order of connected subgraphs (to guarantee avoidance of duplicates).\n\nFurthermore, the overhead of generating one single csg-cmp-pair must be constant or at least linear, to achieve a runtime better than previous DP approaches.\n\nGenerating all connected subsets can be done in the following way:\n\\begin{itemize}\n\t\\item Emitting each node $\\{v_i\\}$ as a connected subset;\n\t\\item Expanding this by calling a dedicated routine which connects it to bigger connected sets;\n\t\\item Recursively expanding.\n\\end{itemize}\n\n\\begin{figure}[h]\n\t\\includegraphics[scale=0.38]{dpccp.png}\n\t\\centering\n\\end{figure}\n\n\\begin{wrapfigure}{R}{0.55\\textwidth}\n\t\\vspace{-10pt}\n\t\\includegraphics[width=0.55\\textwidth]{dpccp_example.png}\n\t\\vspace{-40pt}\n\\end{wrapfigure}\n\nA total order is achieved by \\textbf{labeling nodes} through a breadth-first search. After this preparatory step, the actual algorithm can start having available all nodes along with their \\textbf{neighborhood} (nodes reached with an edge). Furthermore, each set has a block composed by nodes coming before, to avoid enumerating twice.\n\nAll nodes are considered in descending order and emitted (since each is a connected subgraph), then the graphs are recursively expanded prohibiting nodes with smaller labels. \n\nExpansion is performed similarly to DP-sub, looking in the neighborhood among possible combinations. The set of valid nodes increases over time, allowing more degrees of freedom.\n\nHowever, generating connected subsets is not enough: complement pairs have to also be found. First of all, for each $S_1$ all its complements are generated (only once), again using breadth-first, and the procedure is called recursively.\n\nTo achieve idealistic runtime, set operations should be performed in constant time, but in the general case this is not expected and a linear delay might happen; in practice, values are encoded as integers to gain speed, yet this only works in the order of 64 relations.\n\nAnother solution is using bitsets, implementations with dynamic memory and variable size. This does not guarantee constant time either, even if allocating enough bits should never cause a resize.\n\n\\subsection{Complex queries and DPhyp}\nThere are cases in which the query graph is particularly complicated, such as $abs(r_1.f + r_3.f) = abs(r_4.g + r_6.g)$. This kind of operation generates a hypergraph, connecting more than two relations at once: common algorithms cannot be applied. DPSize does not consider the query graph, so it could be used, but it does not have optimal runtime.\n\nA \\textbf{hypergraph} is a non-empty set of nodes and edges where a \\textbf{hyperedge} is an unordered pair of non-empty proper subsets with empty intersection. They have a total order via an arbitrary relation, to avoid enumerating multiple times, or breadth-first search.\n\nDPhyp extends DPccp in the following way:\n\\begin{enumerate}\n\t\\item Constructing connected complement pairs;\n\t\\item Connects subgraphs and complement pairs by recursively traversing the graph;\n\t\\item Connected subgraphs are increased by following edges to neighboring nodes, interpreting hyperedges as $n : 1$ edges leading from $n$ of one side to one.\n\\end{enumerate}\n\nThe approach is similar as for regular graphs, starting with one node and recursively expanding. However, hyperedges have a many-to-many relationship, and an additional choice of where to expand must be taken, while still guaranteeing DP order. The DP table can be tested to check if nodes into subsets are connected, implying an entry already exists. \n\nFor instance, it is impossible to join a set of relations with only one relation which is connected by a hyperedge, since it means some information is lacking and a cross product would be necessary. Therefore, the single relation is recursively expanded checking for connections.\n\nA minor change to solve this issue is choosing a representative for each hyperedge (\\textit{canonical end node}, the 1), leading to the last node in total order, so that duplicates are prevented. Checks for connectedness are still required, because this method leads to temporarily disconnected graphs which must be further expanded.\n\n\\subsubsection{Non-inner joins}\nAnother interesting case involves \\textbf{non-inner joins} (either outer or unnesting), not freely reorderable (performing an inner join before an outer will reduce the number of output tuples, and vice versa). \n\n\\begin{wrapfigure}{L}{0.4\\textwidth}\n\t\\vspace{-15pt}\n\t\\includegraphics[width=0.4\\textwidth]{matrix.png}\n\t\\vspace{-35pt}\n\\end{wrapfigure}\n\nThere are compatibility matrices stating whether two join operations are commutative assuming syntax constraints, i. e. $(R \\circ_1 S) \\circ_2 T \\equiv R \\circ_1 (S \\circ_2 T)$. For instance, full outer joins can be swapped with themselves. \n\nUsing this information, it is easy to figure out which operations are permitted. Having an expression $E = (R \\circ_{p_1} S) \\circ_{p_2} T$, it might be transformed into $E' = R \\circ_{p_1} (S \\circ_{p_2} T)$ and vice versa. If there is a conflict, the ordering is invalid. \n\nFor each operator, the syntactic eligibility set (SES) is built, a set of relations which \\textbf{must be in the input} before an expression can be evaluated. It contains the tables referenced by a predicate.\n\n\\begin{wrapfigure}{R}{0.5\\textwidth}\n\t\\vspace{-5pt}\n\t\\includegraphics[width=0.5\\textwidth]{ses_tes.png}\n\t\\vspace{-35pt}\n\\end{wrapfigure}\n\nThen, the total eligibility set (TES), capturing syntactic constraints and additional reordability constraints, is constructed in a bottom-up way, starting with SES and checking for conflicts in selectivity. If this is the case, another TES is added, capturing reordering restrictions. \n\nThe output obtained adding TES encodes the necessity of certain relations while constructing hyperedges, eliminating invalid reorderings. TES are used to build hypegraphs and reduce the search space, to directly cover all possible conflicts.\n\n\\subsection{Simplifying the query graph}\nThe dynamic programming approach always considers minimal number of join-pairs, so it is not expected to get a better runtime for exact solutions. The set of possibilities is limited, and algorithms perform slowly for certain query graphs (stars), but the complexity is most likely the best to be achieved.\n\nThere are ways to recognize whether the problem is \\textbf{too complicated} to be solved with DP, and simplify (from an optimizer point of view) the query graph until it gets tractable. \n\nThe core idea is to \\textit{apply safe simplifications before risky ones}. Some possibilities of course are going to be ruled out if edges are removed, hence safe modifications are preferred, using a \\textbf{greedy} method for simpler problems and then performing \\textbf{DP} on intermediate results. \n\nHowever, greedily choosing joins can be really hard in practice, so the chosen approach is to choose joins to \\textbf{avoid} first, based on cardinality and selectivity.\n\nTo effectively decrease the search space size, some joins (shrinking) can be forced to be performed first, \\textit{halving} the number of potential plans with each restriction. \n\nThe steps to be performed are:\n\\begin{enumerate}\n\t\\item Examine all joins that have a relation in common (\\textbf{neighboring}), also considering hyperedges;\n\t\\item Check that a pair can be swapped of order (needs a fast cycle checker, trying to construct a topological ordering);\n\t\\item Compute the \\textbf{ordering benefit} with different heuristics;\n\t\\item Retain the pair with \\textit{maximal estimated ordering benefit}, maintaining priority queues to speed up repeated simplification;\n\t\\item Return the query graph in which the edge corresponding to the join is changed to a hyperedge.\n\\end{enumerate}\nThis method is more restrictive, hence simpler. Repeatedly simplifying graphs allows the complexity of them to decrease monotonically, as each steps adds more restrictions.\n\nThe ordering benefit can be estimated in several ways. One approach is to maximize the following:\n$$\\text{orderingBenefit}(X \\bowtie_1 R_1, X \\bowtie_2 R_2) = \\frac{C((X \\bowtie_1 R_1) \\bowtie_2 R_2)}{C((X \\bowtie_2 R_2) \\bowtie_1 R_1)}$$\n$C$ is an arbitrary cost function, for instance $C_{out}$ when no other information is available.\n\nThe rationale, again, is that if a join is orders of magnitude cheaper than the same join in a different order, it is very likely that the first will come before the second in the optimal solution.\n\nThe program should also know when to \\textbf{stop} simplifying: this is achieved when memory or time constraints are satisfied, along with counting the number of connected subgraphs or bounding through memory consumption.\n\nCounting is fast, but not immediate, and cannot be performed after every simplification: a reasonable choice is 10 000 connected subgraphs.\n\nThe full optimization algorithm runs first of all computing a list of query graphs, in which the elements are the same graph after each step, performing simplifications until a total order is reached; to find a specific plan, binary search is employed and then DPhyp is ran on each of them.\n\nBinary search allows to find the graph with the least number of simplification steps having a complexity $\\leq b$, to then store it in the DP table. \n\nAfter the optimal simplification is obtained, dynamic programming is used to get the ultimate result.\n\nSimplification heuristics are subject to mistakes, hence performing too many probably means at some point the cost will increase, and it would be best to stop earlier. This problem is NP-hard.\n\n\\subsection{Adaptive Query Optimization}\nThe effectiveness of this method comes from the huge variety of possible queries to be performed in the real world, of which most are small, but some can arrive up to thousands of relations.\n\nReducing the search space is essential, but greedy algorithms do not perform that well on large graphs. On the other hand, dynamic programming has exponential runtime and a lot of assumptions, so a large search space leads to NP-hard problems. \n\nFurthermore, \\textit{there are no guarantees that running a computationally expensive procedure leads to the best join plan}: often benchmarks fail to represent the real world: a tradeoff between speed and performance is necessary.\n\nTo summarize, the decision flow chooses the following approaches, considered to be the state of art of join ordering:\n\\begin{itemize}\n\t\\item \\textbf{Dynamic programming} for easy query graphs:\n\t\\begin{itemize}\n\t\t\\item DPhyp with $\\leq 10k$ DP entries, guaranteeing an optimal plan yet not very powerful:\n\t\t\\begin{itemize}\n\t\t\t\\item Up to 100 relations for chains;\n\t\t\t\\item 14 relations for cliques.\n\t\t\\end{itemize}\n\t\t\\item GOO/DPhyp if linearization is impossible;\n\t\\end{itemize}\n\t\\item \\textbf{LDP} (linearized dynamic programming) for medium ones;\n\t\\item \\textbf{Greediness} (still in a limited way, keeping in mind restrictions) to achieve a reasonable optimization time.\n\\end{itemize}\n\nComplexity is measured with both time and space requirements, and it strictly depends on the structure of the query graph. Once queries become reasonably large, not only the join ordering\ralgorithm itself plays an important role, but also the implementation\rof data structures.\n\n\\subsubsection{Search Space Linearization (LDP)}\nSearch space linearization (LDP) is a technique working for medium-sized and large queries (in the order of a hundred relations, scaling well), always assuming no cross products to improve performance. \n\nThe main goal is to transform a complicated query graph in a \\textbf{chain}, since most algorithms perform badly on cliques. Search space is \\textit{linearized} by restricting the DP algorithm to consider only \\textbf{connected subchains} of a linear relation ordering, instead of arbitrary combinations.\n\n\\begin{wrapfigure}{L}{0.6\\textwidth}\n\t\\vspace{-18pt}\n\t\\includegraphics[width=0.6\\textwidth]{lindp.png}\n\t\\vspace{-30pt}\n\\end{wrapfigure}\n\nUnfortunately, hypergraphs cannot be expressed in such a linearized form, hence this algorithm can only be applied to queries that can be represented by a regular graph.\n\nKnowing the order of relations in the optimal plan, LDP generates the optimal plan from the linearization in polynomial time, combining solutions for subchains of increasing size. \n\nFurthermore, as seen above, the DP table is much smaller.\n\nThe way the graph is linearized also has a great impact on the quality of the final plan, thus even if time is greatly reduced, some join orders which may be good are removed.\n\nThis is countered knowing the optimal order can be obtained through \\textbf{IKKBZ} in quadratic runtime (with eventually applying MST if the graph is cyclic), so it is indeed possible to order relations efficiently. The result is as least as good as the best left-deep plan, and the optimal bushy plan can be discovered with further steps.\n\nHowever, a runtime of $O(n^3)$ is still too large for wide query graphs, so a \\textbf{combined approach} is taken in case of joining more than 100 relations:\n\\begin{enumerate}\n\t\\item The query plan is build through a greedy algorithm, such as GOO;\n\t\\item The $k$ most expensive trees are iteratively optimized again using dynamic programming.\n\\end{enumerate}\n\nThe latter algorithm is indeed LDP: most DP approaches would need a relatively small $k$ to achieve reasonable time, while LDP allows to increase the factor $k$ up to 100.\n\nThis way, there is more freedom to correct mistakes the greedy phase has introduced, as relations can move up to 100 places within the tree. For small number of relations, however, DPhyp still performs the best. \n\n\\subsection{Generating Permutations}\nGenerating permutation is a \\textit{lightweight} algorithm: it does not require a DP table, and the solution can be found even without completing the enumeration of possibilities. This allows very low space consumption, imposing \\textbf{stricter time requirements} (stop if time runs out).\n\nGenerating all permutations is too expensive, but some of them can be ignored: if a join is more efficient than another, the latter can be discarded.\n\nThis can be achieved considering left-deep trees: those are permutations of the relations to be joined, which can be generated directly. To make the process cheaper, some permutations can be ignored once again applying the DP reasoning (if a solution is better than another, there is no point extending the latter).\n\n\\textit{A sequence is only explored if exchanging the last two relations does not result in a cheaper alternative. }\n\nThe algorithm performs a recursive search while comparing the costs of adding a relation in the end or earlier in the chain, making the optimal plan better after each iteration. \n\nThis process is implemented considering a \\textbf{prefix} $P$ and the rest $R$, increasing $P$ recursively and keeping track of the best tree found so far. \n\nSince modifications are performed in-place, the occupied memory is linear; however, it potentially runs for a long time, and some constraints need to be placed. An instance of the worst case scenario is when a \\textbf{tie} occurs, since the algorithm must explore both alternatives. \n\n\\subsection{Transformative Approaches}\nThis technique is used among modern commercial DBMS (Microsoft SQL server), but it is likely not the best approach. The main idea is to directly apply properties and equivalences to construct new query plans, yet this raises plenty of problems: there is no order, the optimal solution must be guaranteed and such.\n\nThe algorithm is presented as a transformation-based enumeration to avoid the generation of duplicates, to obtain a lower bound for the number of combinations, employing both \\textbf{memoization} and \\textbf{transformation rules}.\n\nThis works as follows:\n\\begin{enumerate}\n\t\\item A set of visited plans is kept, starting with a simple expression;\n\t\\item All transformation rules are applied to visited plans, adding the result to the set if they are new;\n\t\\item When no new plans can be generated, the complete search space has been explored.\n\\end{enumerate}\n\nCommonly used sets of transformations are:\n\\begin{itemize}\n\t\\item RS-B0 (one of the properties is redundant):\n\t\\begin{itemize}\n\t\t\\item Right associativity: $(A \\bowtie B) \\bowtie C \\rightarrow A \\bowtie (B \\bowtie C)$;\n\t\t\\item Left associativity: $A \\bowtie (B \\bowtie C) \\rightarrow (A \\bowtie B) \\bowtie C$;\n\t\t\\item Commutativity: $A \\bowtie B \\rightarrow B \\bowtie A$;\n\t\\end{itemize}\n\t\\item RS-B1 (not redundant anymore):\n\t\\begin{itemize}\n\t\t\\item Left associativity: $A \\bowtie (B \\bowtie C) \\rightarrow (A \\bowtie B) \\bowtie C$;\n\t\t\\item Commutativity: $A \\bowtie B \\rightarrow B \\bowtie A$;\n\t\\end{itemize}\n\t\\item RS-L1, for left-deep trees:\n\t\\begin{itemize}\n\t\t\\item Swap: $(A \\bowtie B) \\bowtie C \\rightarrow (A \\bowtie C) \\bowtie B$;\n\t\t\\item Bottom commutativity: $B_1 \\bowtie B_2 \\rightarrow B_2 \\bowtie B_1$, for base tables (underlying tables storing metadata for a database);\n\t\\end{itemize}\n\t\\item RS-B2, to avoid duplicates:\n\t\\begin{itemize}\n\t\t\\item Commutativity: $A \\bowtie_0 B \\rightarrow B \\bowtie_1 A$, disabling all other rules for the new operator $\\bowtie_1$;\n\t\t\\item Right associativity: $(A \\bowtie_0 B) \\bowtie_1 C \\rightarrow A \\bowtie_2 (B \\bowtie_3 C)$, disabling associativity and exchange on $\\bowtie_2$;\n\t\t\\item Left associativity: $A \\bowtie_0 (B \\bowtie_1 C) \\rightarrow (A \\bowtie_2 B) \\bowtie_3 C$, disabling associativity and exchange on $\\bowtie_3$;\n\t\t\\item Exchange: $(A \\bowtie_0 B) \\bowtie_1 (C \\bowtie_2 D) \\rightarrow (A \\bowtie_3 C) \\bowtie_4 (B \\bowtie_5 D)$, disabling all other rules for application on $\\bowtie_4$.\n\t\\end{itemize}\n\\end{itemize}\n\nFurthermore, two arbitrary relations can be swapped, or cyclic rotations can be performed. It is possible to obtain the optimal solution just applying RS-0, however the other rules allow a smaller number of steps hence a quicker runtime.\n\nIn practice, the output is easily suboptimal: the whole search space is to be considered and the same plan can be generated more than once. \n\nA memoization approach is therefore introduced to remember the intermediate solutions, using pointers to class and expanding their relative members. Replication is avoided by using \\textit{shared copies} only, organizing a network of \\textit{equivalence classes}.\n\nEach class is a set of operators which all produce the same result, and each operator takes a class as input, meaning that any operator in that class may be applied. A hash table is furthermore used to speed up finding results.\n\n\\textbf{RS-B2} is the only set of rules which effectively avoids duplicates, working with the following logic: some rules should not be applied twice, since their output will be redundant (e. g. commutativity).\n\nThe applicability of a rule can be encoded using a single bit, which is not a huge overhead in memory. Even with restrictions, RS-B2 rules generate all valid bushy join orders.\n\nLinear trees can also be obtained employing a variant of this, using only associativity and commutativity.\n\n\\subsection{Generating Random Join Trees}\nConstructing a \\textbf{random join tree} is quite useful in practice: assuming the cost is random, it is possible to find a solution which is really close to the optimal one, and allows to get information about the distribution.\n\nIn this case, considering cross products make the problem simpler, but the \\textit{uniformity of join trees} (having the same probability for each tree) is a challenge.\n\nTo help this, the concepts of \\textbf{ranking} and \\textbf{unranking} are introduced:\n\\begin{itemize}\n\t\\item A ranking is a mapping $f : S \\rightarrow [0, n[$;\n\t\\item An unranking is a mapping $f : [0, n[ \\rightarrow S$.\n\\end{itemize}\nThe idea is to generate random numbers, to then map them to the and the function must also be able to unrank in a fast way.\n\nA trivial mapping would just be generating all possible trees and incrementing a counter, but this method is not efficient: the solution set should be smaller.\n\nRandom permutations can be applied as a starting point for the algorithm, shuffling an array (for each element in descending order, swap it with a random one up to its position) to generate a left-deep tree. \n\nIn the first call, there are $n$ choices of random elements $r_{n-1}, \\dots, r_0$ where $0 \\leq r_i \\leq i$, in the second one there are $n - 1$ and so on, obtaining a number of $n!$ sequences with an one-to-one relationship with the set of all permutations.\n\nUnranking works trying to find a sequence from the initial value, which is independent from previous ones: $r_{n-1} \\equiv r \\mod n$ is set, and the swap is performed. $r' = \\lfloor r/n\\rfloor$ is defined and iteratively unranked to construct a permutation of $n - 1$ elements. \n\n\\textbf{Bushy trees} are obtained in a similar way, yet using a Catalan number $b$ (the amount of different trees) to obtain the relations, and applying the previous procedure with another random value $p$ smaller than $n!$. Unranking works attaching the relations in order $p$.\n\nTo encode trees, whenever an inner node is encountered a left bracket (1) is added, and when a leaf node is encountered a right bracket (0) is added, except for the last one. Brackets are then substituted with the respective binary value, and the relations correspond to the position of 1s starting from left. \n\nUnranking binary trees also has an unique correspondence with Dyck words (sequences with proper brackets): to count how many possibilities are there, it is possible to plot them knowing that the first character must be a left bracket, and last one a right bracket. A tree is any path in the grid from $(0, 0)$ to $(2n, 0)$.\n\n\\begin{wrapfigure}{L}{0.6\\textwidth}\n\t\\vspace{-10pt}\n\t\\includegraphics[width=0.6\\textwidth]{grid.png}\n\t\\vspace{-30pt}\n\\end{wrapfigure}\n\nThe number of different paths from $(0, 0)$ to $(i, j)$ can be computed with the following formula:\n$$p(i, j) = \\frac{j+1}{i+1} {{i+1}\\choose{\\frac{1}{2}(i+j)+1}}$$\nThese numbers are the \\textit{Ballot numbers} (useful for elections!). Hence, all the paths from beginning to end are $p(2n - i, j)$, which is indeed a Catalan number. Choices which have not been taken are subtracted by the rank at each iteration.\n\nIf the number of paths does not exceed the rank, a parenthesis is open and the grid is traversed upwards. When it does, a parenthesis is closed and a step down is taken, \\textbf{decrementing} the rank by the number of excluded paths.\n\nThe decision of upwards or downwards is as easy as flipping a coin, but this does not respect a uniform probability since there are more trees starting with a left brackets, and going down is not possible in all cases. \n\nThe procedure works in five steps:\n\\begin{enumerate}\n\t\\item List merges (notation, specification);\n\t\\item Join tree construction;\n\t\\item Standard Decomposition Graph;\n\t\\item Counting;\n\t\\item Unranking.\n\\end{enumerate}\nA list $l'$ is the projection of a list $L$ on $P$ if $l'$ contains all the elements of $L$ respecting $P$ in the same order. A list merge $L$ is the union of two disjoint lists, both obtained from $L$.\n\nA merge of two lists whose respective lengths are $l_1$ and $l_2$ is equivalent to an array of non-negative integers whose sum is equal to $l_1$. \n\nTherefore, the number of decomposition of any non-negative integer in a sequence of non-negative integers with $\\sum_{i=1}^{k} \\alpha_k = n$ is ${n+k-1}\\choose{k-1}$.\n\nThe number of possible merges is ${l_1+l_2}\\choose{l_2}$, but this is too expensive to be computed all the iterations, hence it is split in two parts which are then materialized. \n\nTo establish a bijection, the set $S$ is partitioned into disjoint smaller sets: when ranking $x \\in S_k$, first the local rank is computed, obtaining $rank(x) = \\sum_{i=0}^{k-1} \\abs{S_i} + local-rank(x, S_k)$.\n\nThe rank can be interpreted as the number of elements in every previous bucket which have not been chosen plus the local ordering of the element in the current set. \n\nUnranking simply consists in computing $r' = r - \\sum_{i=0}^{k-1} \\abs{S_i}$, i. e. subtracting all the partitions which have not been taken yet. \n\nEach possible merge is partitioned into subsets, each having an increasing number of elements. In each of them, there are $M(l_1 - j, l_2 - 1)$ elements. To unrank a value, its partition is firstly computed, setting $k = min_j r \\leq \\sum_{i=0}^{j} M(j, l_2 - 1)$ and $\\alpha_0 = l_1 - k$. The new rank is then updated and used for the next iteration.\n\nIf the query graph is cyclic, there does not exist a way to generate trees with random probability; not allowing cross products implies choosing only relationships which are \\textbf{connected}, introducing bias. \n\nAnother representation of join trees works through \\textbf{anchored lists}:\n\\begin{itemize}\n\t\\item If $T$ is a single leaf node, then $L = <>$;\n\t\\item if $T = T_1 \\bowtie T_2$ and a leaf $v$ occurs in $T_2$, then $L = <T_1 | L_2>$ where $L_2$ is the anchored list representation of $T_2$.\n\\end{itemize}\nHere, left and right are not distinguished, since there is no way to remember the direction. Leafs are inserted introducing insertion pairs, couples $(T', k)$ of lists and rank in which only one node (missing from $T$) is inserted at position $k$. This is a bijective mapping.\n\n\\newpage\n\\subsubsection{Standard Decomposition Graph}\n\\begin{wrapfigure}{R}{0.55\\textwidth}\n\t\\vspace{-5pt}\n\t\\includegraphics[width=0.55\\textwidth]{std.png}\n\t\\vspace{-70pt}\n\\end{wrapfigure}\nA STD describes the possible constructions of join trees. It uses two kind of nodes:\n\\begin{itemize}\n\t\\item $+$ for \\textbf{leaf} insertion;\n\t\\item $*_w$ for merging \\textbf{subtrees} whose only common leaf is $w$.\n\\end{itemize}\nThis is done with three steps:\n\\begin{enumerate}\n\t\\item Picking an arbitrary root node;\n\t\\item Transforming the query graph into a tree;\n\t\\item Calling the algorithm which turns the query graph into a SDG, looking at how many child nodes there are and performing leaf insertions with one input, else merging to obtain two new $+$ nodes.\n\\end{enumerate}\n\n\\subsection{QuickPick}\nQuickPick is useful to have a first insight into what the search space looks like, building pseudo-random trees by randomly select edges. This algorithm is easy to implement and quite fast, however it loses uniformity: the usual way to take advantage of it is running it multiple times and picking the best output.\n\nIt works without cross products, since each edge must join two relations, and can output any kind of tree shape. The key element of the algorithm is sampling from a \\textbf{mapping} of randomly generated sequences of join predicates to query plans.\n\nQuery plans are constructed in a bottom-up way, simultaneously computing the costs and discarding partial plans as soon as they exceed the best costs found so far. \n\nQuickPick performs biased sampling by selecting edges from the join graph and adding the respective joins to the query plan. \n\nAfter this step, if either the plan is complete or the cost exceeds the best plan so far, the query plan is \\textbf{reset}, eventually updating the cost if a better alternative has been found.\n\nThe procedure only ends when the stopping criterion is fulfilled, usually an amount of time or operations. However, QuickPick tends to \\textbf{converge} due to its biased cost distribution.\n\nThere is a variant starting with all possible sets of trees and randomly joining them by selecting an edge. If an edge connects two subtrees, it is replaced with a join, removing the two subtrees until only one tree is left. \n\nFailure can happen if cycles exist in the graph. Furthermore, some trees are more likely to exist than others, since sometimes swapping two edges makes no difference among the structure.\n\nTo check whether an edge connects two relations in different subtrees, an approach similar to Kruskal's algorithm is used: through an union-find data structure it is possible to do this efficiently.\n\n\\subsection{Metaheuristics}\nMetaheuristics are general optimization strategies working well for even large problems, but are unaware of the real issue and just rely on computational power.\n\nFormally, \\textit{a \\textbf{metaheuristic} is a higher-level procedure or heuristic designed to find, generate, or select a heuristic (partial search algorithm) that may provide a sufficiently good solution to an optimization problem, especially with incomplete or imperfect information or limited computation capacity.}\n\nBy searching over a large set of feasible solutions, they can often find good solutions with less computational effort than optimization algorithms, iterative methods, or simple heuristics.\n\nIt is not proven how well they perform or what kind of problem they solve, but they are widely used by modern DBMS.\n\n\\subsubsection{Iterative Dynamic Programming}\nThe main idea of IDP is to apply dynamic programming several times\rin the process of optimizing a query, either to optimize different parts of a plan\rseparately or in different phases of the optimization process.\n\nThis approach generally works better than simple dynamic programming variants, since when the query it simple the plan will be the same, and it scales better than naive algorithms. It also considers memory limitations, eventually restarting if it exceeds a threshold and using previous results as building blocks. \n\nThe iterative improvement approach starts with a \\textbf{random tree}, applies some rules to improve (e. g. transformative approaches) and stops only when no further improvement is possible. If the tree after random modifications gets worse, the change is undone. \n\nImprovements, therefore, are applied both on a query graph and a tree basis, trying several trees and randomly optimizing each of them.\n\nMetaheuristics work trying to find an optimal, and have the consequence of risking to get stuck into a local minimum: usually a time limit is implemented so that the procedure always terminates, and there are different start points to generate multiple results.\n\nCross products could be generated by accidentally swapping two relations which are not linked, hence a method similar to QuickPick is used, manipulating edges instead of nodes.\n\nIKKBZ can be used with an acyclic query graph to obtain the optimal left-deep tree, which is then compared with the iterative improvement result.\n\n\\subsubsection{Simulated annealing}\nSimulated annealing is another approach which allows moving from a local minimum even if the solution gets worse, defining a \\textbf{probability} based on the temperature for the worse tree to be swapped with the current best one. \n\nThe only problem is \\textit{optimizing temperature and time}, picking initial values and thresholds to decrease or rise the temperature, yet there are some rule of thumbs working well in practice.\n\nSimulating annealing is often used along with iterative improvement, using the latter to find a local minima and the former to try and find a better plan.\n\n\\subsubsection{Tabu search}\nTabu search sets some nodes in the graph as \\textbf{forbidden}, to extend the search space trying to find different solutions. The cheapest results among all neighbors are chosen, even if they are worse than the current one, forcing the algorithm to never go back. This is useful to avoid cycles.  \n\nSize of the tabu set is fixed, otherwise it might eventually contain all the relations: whenever the size is exceeded, the oldest node is removed and allowed back into the search space. \n\n\\subsubsection{Genetic algorithms}\nGenetic algorithm, employed in PostgreSQL [\\href{https://www.postgresql.org/docs/current/geqo.html}{source}], is a heuristic optimization method operating through randomized search. It functions in the same way as a population model, based on \\textit{survival of the fittest}. Join trees are elements which generate successors by \\textbf{crossover} or \\textbf{mutation}, only keeping the best trees.\n\nThe coordinates of an individual in the search space are represented by chromosomes, in essence a set of character strings. A gene is a subsection of a chromosome which encodes the value of a single parameter being optimized.\n\nThrough simulation of the evolutionary operations, new generations of search points are found that show a higher average fitness than their ancestors. \n\nQuery optimization in this case is approached as it was the TSP problem, implementing steady state (replacement only of the least fit individuals) and edge recombination crossover for fast convergence. \n\nThe algorithm works with the following process:\n\\begin{enumerate}\n\t\\item The standard planner generates plans for scans of individual relations;\n\t\\item Transforms each join plan into a sequence, and estimates its cost;\n\t\\item Least fit candidates (more expensive) are discarded;\n\t\\item New candidates are generated by combining genes, i. e. using random portions of low-cost joins to create new sequences.\n\\end{enumerate}\n\nThe problem with this simulation is finding an encoding between trees and population, especially representing crossover and mutation. There are two different possibilities: \n\\begin{itemize}\n\t\\item \\textbf{Ordered list}, showing a tree as a permutation of numbers and joining them from left to right, implementing the bushy variant naming edges instead of nodes;\n\t\\item \\textbf{Ordinal number}, starting with a natural order:\n\t\\begin{itemize}\n\t\t\\item For left-deep trees, finding the index of the first relation to be joined, setting the first character in the chromosome string as $i$ and removing it from the list;\n\t\t\\item For bushy trees, encoding in bottom-up, left-to-right, looking at two positions at once and again removing them, but replacing them with a third symbol to describe the tree.\n\t\\end{itemize}\n\\end{itemize}\nCrossover is simulated either by \\textbf{subsequence} exchange or \\textbf{subset} exchange, generating permutations such that the order of appearance is respected or simply swapping elements of equal length.\n\n\\begin{wrapfigure}{R}{0.6\\textwidth}\n\t\\vspace{-18pt}\n\t\\includegraphics[width=0.6\\textwidth]{genetic.png}\n\t\\vspace{-60pt}\n\\end{wrapfigure}\n\nAn example of crossover by subsequence exchange is:\n\\begin{enumerate}\n\t\\item Assuming two individuals with chromosomes $u_1v_1w_1$ and $u_2v_2w_2$;\n\t\\item Taking $v$ and permuting its relations to obtain $u_1v'_1w_1$, $u_2v'_2w_2$.\n\\end{enumerate}\n\nA mutation, on the other hand, \\textit{randomly alters} a character in the encoding, hence a swap can be considered a mutation as well.\n\nThe algorithm is implemented with a \\textbf{selection} phase: population is sorted according to survival probability (sorting trees by cost and keeping the best) and some of them are selected to be subject of crossover or mutations.\n\nSince crossover increases the population, selection needs to be performed again until the maximum number of iterations or the given size are reached.\n\nLike other metaheuristics, parameters rely on human hand-made benchmarking.\n", "meta": {"hexsha": "c082fee8cdf646d926f8d4d04a9a9a198d42848c", "size": 76143, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Query Optimization/lectures/join_ordering.tex", "max_stars_repo_name": "mrahtapot/TUM", "max_stars_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "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": "Query Optimization/lectures/join_ordering.tex", "max_issues_repo_name": "mrahtapot/TUM", "max_issues_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "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": "Query Optimization/lectures/join_ordering.tex", "max_forks_repo_name": "mrahtapot/TUM", "max_forks_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.0662460568, "max_line_length": 399, "alphanum_fraction": 0.7794413144, "num_tokens": 18043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6543509562252805}}
{"text": "\\documentclass[12pt]{article}\r\n\\usepackage{jansstylefile} % The option nobibliography does not print the bibliography. But bibliography can still be used. \n\n\\title{Posterior distribution}\n\\author{Jan van Waaij}\r\n\r\n\\begin{document}\n\n\\begin{notation}\n    When $A$ is a square matrix, we denote by $|A|$ its determinant. If the inverse of $A$ exist, we denote it by $A^{-1}$. \n\\end{notation}\n\n\\section{Distribution of the posterior of a finite basis expansion with Gaussian coefficients}\n\n\\begin{lemma}\\label{lem:posteriordistribution}\n\tLet \\(X^T=\\rh{X_t:t\\in[0,T]}\\) be an observation of \n\t\\begin{align*}\n\t\tdX_t=b(X_t)dt+\\sigma(X_t)dW_t,\n\t\\end{align*}\n\twhere  \\(\\sigma:\\re\\to \\re_{>0}\\) is a  measurable function, $(W_t:t\\in[0,T])$ is a Brownian motion and \\(b\\) is equipped with the prior distribution defined by \n\t\\[\n\tb=\\sum_{j=1}^k\\theta_j\\phi_j,\n\t\\]\n\twhere \\(\\set{\\phi_1,\\ldots,\\phi_k}\\) is a linearly independent basis, and \\(\\theta=(\\theta_1,\\ldots,\\theta_k)^t\\) has multivariate normal distribution \\(N(\\mu,\\Sigma)\\), with mean vector $\\mu$ and positive definite matrix $\\Sigma$. Then the  posterior distribution of \\(\\theta\\) given $X^T$ is \\(N(\\hat\\mu,\\hat\\Sigma)\\), where \\[\\hat\\mu=(S+\\Sigma^{-1})^{-1}(m+\\Sigma^{-1}\\mu),\\quad\\hat\\Sigma= (S+\\Sigma^{-1})^{-1}\\] and the vector \\(m=(m_1,\\ldots,m_k)^t\\) is defined by \n\t\\[\n\tm_l=\\int_0^T\\frac{\\phi_l(X_t)}{\\sigma(X_t)^2}dX_t, \\quad l=1,\\ldots,k,\n\t\\] \n\tand the symmetric \\(k\\times k\\)-matrix \\(S\\) is given by \n\t\\begin{equation}\\label{eq:girsanovmatrix}\n\tS_{l,l'}=\\int_0^T\\frac{\\phi_l(X_t)\\phi_{l'}(X_t)}{\\sigma^2(X_t)}dt,\\quad l,l'=1,\\ldots,k,\n\t\\end{equation}\n\tprovided \\(S+\\Sigma^{-1}\\) is invertible. \n\tMoreover, the marginal likelihood is given by \n\t\\[\n\\int p(X^T\\mid \\theta)p(\\theta)d\\theta=\t|\\Sigma^{-1}\\hat\\Sigma|^{1/2}e^{-\\frac12\\mu^t\\Sigma^{-1}\\mu} e^{\\frac12\\hat\\mu^t\\hat\\Sigma^{-1}\\hat\\mu}.\n\t\\]\n\t\n\\end{lemma}\n\\begin{proof}Almost surely we have by Girsanov's theorem (e.g. \\cite[chapter 13]{steele2001} or \\cite[section 9.4]{ChungWilliams2014}) \\begin{equation}\\label{eq:girsanov}\np(X^T\\mid \\theta)=\\exp\\left(\\int_0^T\\frac{b(X_t)}{\\sigma(X_t)^2}dX_t-\\frac12\\int_0^T\\rh{\\frac{b(X_t)}{\\sigma(X_t)}}^2dt\\right),\n\\end{equation}with respect to the Wiener measure. So \\begin{equation}\\label{eq:loglikelihoodintermsofmandS}\n\\log p(X^T\\mid b)=\\theta^tm - \\frac 1 2 \\theta^t S\\theta\n\\end{equation}\n and the log of the distribution of \\(\\theta\\) with respect to the Lebesgue measure on \\(\\re^k\\) is given by\n\\begin{align*}\n\t\\log p(\\theta)= &-\\frac k2\\log(2\\pi) - \\frac12 \\log|\\Sigma|  - \\frac 1 2 (\\theta-\\mu)^t\\Sigma^{-1}(\\theta-\\mu) \\\\\n\t= &C_1 - \\frac 1 2 \\theta\\Sigma^{-1}\\theta +\\theta^t\\Sigma^{-1}\\mu,\n\t\\intertext{with}\n\tC_1=& -\\frac k2\\log(2\\pi) - \\frac12 \\log|\\Sigma|  - \\frac 1 2 \\mu^t\\Sigma^{-1}\\mu. \n\\end{align*}\n\n\nSo, %by the Bayes formula, for some constant \\(C_3\\), the posterior density of \\(\\theta\\) is given by\n\\begin{align*}\n\t\\log( p(X^T\\mid \\theta)p(\\theta)) = & C_1 + \\theta^tm - \\frac 1 2 \\theta^t S\\theta - \\frac 1 2 \\theta\\Sigma^{-1}\\theta +\\theta^t\\Sigma^{-1}\\mu\\\\\n\t= & C_1 + \\theta^t ( m + \\Sigma^{-1} \\mu ) - \\frac 1 2 \\theta^t (S+\\Sigma^{-1}) \\theta\\\\\n\t= & C_1 + \\theta^t ( S + \\Sigma^{-1} )  \\Big  ( ( S + \\Sigma^{-1} )^{-1} (m + \\Sigma^{-1}\\mu )\\Big) \\\\\n\t&\\quad- \\frac 1 2 \\theta^t (S+\\Sigma^{-1}) \\theta. \n\\end{align*}\n\nBy the Bayes formula, the posterior density of \\(\\theta\\) is proportional to \\(p(X^T\\mid\\theta)p(\\theta)\\). It follows that  \\(\\theta\\mid X^T\\) is normally distributed with mean \n\\[\\hat\\mu :=( S + \\Sigma^{-1} )^{-1} (m + \\Sigma^{-1}\\mu).\\]\n and covariance matrix \\[\\hat\\Sigma:=(S+\\Sigma^{-1})^{-1},\\]\nprovided $S+\\Sigma^{-1}$ is invertible.  \n Moreover \n \\begin{align*}\n &\\int  p(X^T\\mid\\theta)p(\\theta)d\\theta \\\\\n = & \\int  e^{C_1} e^{\\theta^t\\hat\\Sigma^{-1}\\hat\\mu } e^{-\\frac12\\theta^t \\hat\\Sigma^{-1} \\theta} d\\theta\\\\\n = & (2\\pi)^{k/2}| \\hat\\Sigma|^{1/2}e^{\\frac12\\hat\\mu^t\\hat\\Sigma^{-1}\\hat\\mu}e^{C_1}\\\\\n &\\times \\int (2\\pi)^{-k/2}|\\hat\\Sigma|^{-1/2}e^{\\theta^t\\hat\\Sigma^{-1}\\hat\\mu } e^{-\\frac12\\theta^t \\hat\\Sigma^{-1} \\theta} e^{-\\frac12\\hat\\mu^t\\hat\\Sigma^{-1}\\hat\\mu}d\\theta\\\\\n = & (2\\pi)^{k/2}|\\hat\\Sigma|^{1/2}e^{\\frac12\\hat\\mu^t\\hat\\Sigma^{-1}\\hat\\mu}e^{C_1}\\\\\n = & |\\Sigma^{-1}\\hat\\Sigma|^{1/2}e^{-\\frac12\\mu^t\\Sigma^{-1}\\mu} e^{\\frac12\\hat\\mu^t\\hat\\Sigma^{-1}\\hat\\mu},\n \\end{align*}\n using that the integrant in the third last line is the density of a multivariate normal distribution and therefore integrates to one.\n\\end{proof}\nUsually we refer to $S$ as the Girsanov matrix. \n\n\\section{The marginal maximum likelihood estimator}\n\n\\begin{lemma}\\label{lem:marginallikelihood}\nLet $\\lambda>0$, $\\mu\\in\\re^k$ and let $\\Sigma$ be a positive definite $k\\x k$-matrix. Consider the prior \\(\\theta\\sim N(\\mu,\\Sigma_\\lambda)\\), where \\(\\Sigma_\\lambda=\\lambda^2\\Sigma \\) and denote its density by $p_\\lambda$. Then \n\\begin{equation}\\label{eq:marginallikelihood}\n\\begin{split}\n  &\\log \\int  p_\\lambda(X^T\\mid\\theta)p_\\lambda(\\theta)d\\theta  \\\\= &-\\frac12\\log |\\lambda^2\\Sigma  S + \\II_k|  -\\frac12\\mu^t\\Sigma^{-1}\\mu+ \\frac12(m + \\lambda^{-2}\\Sigma^{-1}\\mu)^t ( S + \\lambda^{-2}\\Sigma^{-1} )^{-1} (m + \\lambda^{-2}\\Sigma^{-1}\\mu).\n\\end{split}\n\\end{equation}\n\n\\end{lemma}\n\\begin{proof}It follows from \\cref{lem:posteriordistribution} that \n  \\[\n\\Sigma_\\lambda \\hat \\Sigma_\\lambda ^{-1} = \\Sigma_\\lambda (S+\\Sigma_\\lambda ^{-1})= \\Sigma_\\lambda  S + \\II_k=\\lambda^2\\Sigma  S + \\II_k\n\\]\nand\\begin{align*}\n\\hat \\mu^t \\hat\\Sigma_\\lambda^{-1} \\hat\\mu =&  (m + \\Sigma_\\lambda^{-1}\\mu)^t( S + \\Sigma_\\lambda^{-1} )^{-1}( S + \\Sigma_\\lambda^{-1} )( S + \\Sigma_\\lambda^{-1} )^{-1} (m + \\Sigma_\\lambda^{-1}\\mu)\\\\\n=&  (m + \\lambda^{-2}\\Sigma^{-1}\\mu)^t ( S + \\lambda^{-2}\\Sigma^{-1} )^{-1} (m + \\lambda^{-2}\\Sigma^{-1}\\mu). \n\\end{align*}\nSo it follows from the same lemma that \n\\begin{align*}\n    &\\log \\int  p_\\lambda(X^T\\mid\\theta)p_\\lambda(\\theta)d\\theta  \\\\= &-\\frac12\\log |\\lambda^2\\Sigma  S + \\II_k|  -\\frac12\\lambda^{-2}\\mu^t\\Sigma^{-1}\\mu+ \\frac12(m + \\lambda^{-2}\\Sigma^{-1}\\mu)^t ( S + \\lambda^{-2}\\Sigma^{-1} )^{-1} (m + \\lambda^{-2}\\Sigma^{-1}\\mu).\n\\end{align*}\n\\end{proof}\n\n{\\color{magenta}\nSo can we calculate $(S+\\lambda^{-2}\\Sigma^{-1})^{-1}$ from $(S+\\Sigma^{-1})^{-1}$?\n}\n{\\color{cyan}\nWhat I found out: if $A$ and $B$ are symmetric matrices that commute, then there is an orthonormal matrix $Q$ so that $D_A = Q^TAQ$ and $D_B=Q^TBQ$ are diagonal. In our set-up this happens when $S$ and $\\Sigma^{-1}$ commute. They commute when $\\Sigma$ is $c\\I$.  \n}\n\n\\opmerking{In de implementatie voor vaste $\\alpha$ kun je  $\\mu^t\\Sigma^{-1}\\mu$ en $\\Sigma^{-1}\\mu$ opslaan en hoef je maar een keer uit te rekenen.}\n\n{\\color{cyan}\nAls $\\mu=0$, dan is \n\\begin{align*}\n    &\\log \\int  p_\\lambda(X^T\\mid\\theta)p_\\lambda(\\theta)d\\theta  \\\\= &-\\frac12\\log |\\lambda^2\\Sigma  S + \\II_k|  + \\frac12m^t ( S + \\lambda^{-2}\\Sigma^{-1} )^{-1}m .\n\\end{align*}\nVerder hebben we\n\\begin{align*}\n    S + \\lambda^{-2}\\Sigma^{-1} = \\lambda^{-2}\\Sigma^{-1}\\rh{\\lambda^2 \\Sigma S + I_k}. \n\\end{align*} \nDus\n\\begin{align*}\n    &\\log \\int  p_\\lambda(X^T\\mid\\theta)p_\\lambda(\\theta)d\\theta  \\\\\n    = &-\\frac12\\log |\\lambda^2\\Sigma  S + \\II_k|  + \\frac12\\lambda^{2}m^t \\rh{\\lambda^2 \\Sigma S + I_k}^{-1}\\Sigma\\, m .\n\\end{align*}\nDus de laatste formule hangt niet af van $\\Sigma^{-1}$. \n}\n{\n\\color{magenta}\nDe vraag is dus, zijn er slimme snelle manieren om de determinant en inverse van $\\lambda^2 \\Sigma S + I_k$ uit te rekenen? \n}\n{\n\\color{red} Conclusie van 3 dagen aan werken is dat de determinant makkelijk uitgerekend kan worden met behulp van de eigenwaarden, maar de inverse naar het schijnt niet zo makkelijk. \n}\n\n\\begin{lemma}\n    If $\\nu_1,\\ldots,\\nu_k$ are the eigenvalues of $\\Sigma S+ I_k$, then $\\lambda^2\\nu_1-\\lambda^2+1,\\ldots,\\lambda^2\\nu_k-\\lambda^2+1$ are the eigenvalues of $\\lambda^2 \\Sigma S + \\I_k$. \n\\end{lemma}\n\\begin{proof}\nNote that \\begin{align*}\n    0=&\\abs{\\nu_i \\I_k - (\\Sigma S + \\I_k) }\\\\\n    &\\desda\\\\\n    0=&\\abs{\\lambda^2\\nu_i \\I_k - (\\lambda^2\\Sigma S +\\lambda^2 \\I_k) }\\\\\n    = &\\abs{(\\lambda^2\\nu_i-\\lambda^2+1) \\I_k - (\\lambda^2\\Sigma S +\\I_k) }.\n\\end{align*}\nSo $\\nu_i$ is an eigenvalue of $\\Sigma S+ \\I_k$ if and only if $\\lambda^2\\nu_i-\\lambda^2+1$ is an eigenvalue of $\\lambda^2\\Sigma S +\\I_k$. \n\\end{proof}\n\n\\begin{lemma}\n    If $\\nu_1,\\ldots,\\nu_k$ are the eigenvalues of $\\Sigma S$, then $\\lambda^2\\nu_1+1,\\ldots,\\lambda^2\\nu_k+1$ are the eigenvalues of $\\lambda^2 \\Sigma S + I_k$. \n\\end{lemma}\n\\begin{proof}\nNote that \\begin{align*}\n    &\\abs{\\nu_i \\I_k - \\Sigma S  }=0\\\\\n    &\\desda\\\\\n    0=&\\abs{\\lambda^2\\nu_i \\I_k - \\lambda^2\\Sigma S  }\\\\\n    =&\\abs{(\\lambda^2\\nu_i+1) \\I_k - (\\lambda^2\\Sigma S +\\I_k) }\\\\\\end{align*}\n\\end{proof}\n\nSo the eigenvalues of $\\lambda^2\\Sigma S + \\I_k$ are easily obtained from the eigenvalues of $\\Sigma S$ or $\\Sigma S + \\I_k$. Note that the determinant \n\n\\section{Random scaling}\n\n\\begin{lemma}\n\tLet \\(X^T=\\rh{X_t:t\\in[0,T]}\\) be an observation of \n\t\\begin{align*}\n\tdX_t=b(X_t)dt+\\sigma(X_t)dW_t,\n\t\\end{align*}\n\twhere \\(b\\) is equipped with the prior distribution defined by \n\t\\begin{align*}\n\t\\lambda^2 \\sim & \\text{Inverse Gamma}(A,B)=IG(A,B)\\\\\n\t\\theta \\mid \\lambda \\sim & N(\\mu,\\lambda^2\\Sigma)\\\\\n\tb\\mid \\theta = & \\sum_{j=1}^k\\theta_j\\phi_j,\n\t\\end{align*}\n\twhere \\(\\set{\\phi_1,\\ldots,\\phi_k}\\) is a linearly independent basis. Then \n\t\\[\n\t\\lambda^2 \\mid \\theta, X^T \\sim \\text{IG}\\rh{ A + k/2 , B+ \\frac12 (\\theta-\\mu)^t\\Sigma^{-1}(\\theta-\\mu) }.\n\t\\] \n\\end{lemma}\n\\begin{proof}\n%\tLet where the vector \\(m=(m_1,\\ldots,m_k)^t\\) is defined by \n%\t\\[\n%\tm_l=\\int_0^T\\frac{\\phi_l(X_t)}{\\sigma(X_t)^2}dX_t, \\quad l=1,\\ldots,k,\n%\t\\] \n%\tand the symmetric \\(k\\times k\\)-matrix \\(S\\) is given by \n%\t\\[\n%\tS_{l,l'}=\\int_0^T\\frac{\\phi_l(X_t)\\phi_{l'}(X_t)}{\\sigma^2(X_t)}dt,\\quad l,l'=1,\\ldots,k.\n%\t\\]\n%\tAlmost surely we have by Girsanov's theorem\\begin{equation}\\label{eq:girsanov}\n%\tp(X^T\\mid b)=\\exp\\left(\\int_0^T\\frac{b(X_t)}{\\sigma(X_t)^2}dX_t-\\frac12\\int_0^T\\rh{\\frac{b(X_t)}{\\sigma(X_t)}}^2dt\\right),\n%\t\\end{equation}with respect to the Wiener measure. \nRecall \\cref{eq:loglikelihoodintermsofmandS}, \\(\\log p(X^T\\mid b)=\\theta^tm - \\frac 1 2 \\theta^t S\\theta\\). The logarithm of the distribution of \\(\\theta\\) given \\(\\lambda\\) with respect to the Lebesgue measure on \\(\\re^k\\) is given by (proportionality w.r.t. \\(\\lambda\\)),\n\t\\begin{align*}\n\t\\log p(\\theta\\mid \\lambda)= &C_1 -k\\log \\lambda - \\frac 1 2 \\lambda^{-2}(\\theta-\\mu)^t\\Sigma^{-1}(\\theta-\\mu). \n\t\\end{align*}\n\tfor some real constant \\(C_1\\), depending on \\(\\theta\\), but not on \\(\\lambda\\).\n\t\n\tIn the following, \\(\\propto\\) means equal up to a multiplicative constant depending on \\(\\theta\\) and \\(X^T\\), but not on \\(\\lambda\\).\n\tBy the Bayes formula, \\begin{align*}\n\t\tp(\\lambda^2\\mid \\theta, X^T)\\propto & p(X^T\\mid \\lambda^2,\\theta)p(\\lambda^2\\mid \\theta)\n\t\t\\intertext{and}\n\t\tp(\\lambda^2\\mid \\theta)\\propto & p(\\theta\\mid \\lambda^2)p(\\lambda^2)\\intertext{so}\n\t\tp(\\lambda^2\\mid \\theta, X^T)\\propto &  p(X^T\\mid \\lambda^2,\\theta)p(\\theta\\mid \\lambda^2)p(\\lambda^2).\n\t\\end{align*}It follows that for some real constants \\(C,\\tilde C\\) depending on \\(\\theta\\) and \\(X^T\\), but not on \\(\\lambda\\), we have \\begin{align*}\n\t\t&\\log p(\\lambda^2\\mid \\theta, X^T)\\\\ \n\t\t= & C + \\theta^tm - \\frac 1 2\\theta^t S\\theta\\\\\n\t\t& -k\\log \\lambda - \\frac12 \\lambda^{-2}(\\theta-\\mu)^t\\Sigma^{-1}(\\theta-\\mu)\\\\\n\t\t&-(A+1)\\log(\\lambda^2) - \\frac B{\\lambda^2}\\\\\n\t\t= &\\tilde{C} -(A+k/2+1)\\log(\\lambda^2) - \\frac {B+ \\frac12 (\\theta-\\mu)^t\\Sigma^{-1}(\\theta-\\mu)}{\\lambda^2},\n\t\\end{align*}\n\twhich is up to an additive constant the logarithm of the density of the inverse gamma distribution with shape parameter \\(A+k/2\\) and scale parameter \\(B+ \\frac12 (\\theta-\\mu)^t\\Sigma^{-1}(\\theta-\\mu)\\).\n\\end{proof}\n\n\\begin{lemma}\n\tWe have \\begin{align*}\n\t&\\log p(X^T\\mid j,\\lambda^2)\\\\\n\t=&-\\frac12\\log |\\lambda^2\\Sigma  S + \\II_k|  -\\frac12\\mu^t\\Sigma^{-1}\\mu+ \\frac12(m + \\lambda^{-2}\\Sigma^{-1}\\mu)^t ( S + \\lambda^{-2}\\Sigma^{-1} )^{-1} (m + \\lambda^{-2}\\Sigma^{-1}\\mu).\n\t\\end{align*}\n\\end{lemma}\n\\begin{proof}\n\tThis follows from \\[\n\tp(X^T\\mid j,\\lambda^2 ) = \\int p(X^T\\mid j,\\theta^j,\\lambda^2)p(\\theta^j\\mid j, \\lambda)d\\theta^j\n\t\\]\n\tand \\cref{lem:marginallikelihood}. \n\\end{proof}\n\n\\section{The sparsity of the Girsanov matrix with Faber-Schauder functions}\n\nThe Faber-Schauder basis functions $\\psi_0, \\psi_{j,k}$ are defined as follows: \\begin{align*}\n\\psi_0(x)=&\\begin{cases}\n    1-2x & \\text{ when } x\\in[0,1/2),\\\\\n    2x-1 & \\text{ when } x\\in[1/2,1],\\\\\n    0 & \\text{ otherwise,} \n\\end{cases}\\\\\n\\Lambda(x) = & \\begin{cases}\n    2x & \\text{ when }x\\in[0,1/2),\\\\\n    2(1-x) & \\text{ when } x\\in [1/2,1],\\\\\n    0 & \\text{ otherwise,}\n\\end{cases} \n\\intertext{and}\n\\psi_{j,k} (x) = &  \\Lambda(2^jx-k+1), \\quad j=0,1,\\ldots, k=1,\\ldots,2^j,\n\\end{align*}\nsee \\cite[p. 607]{meulenschauerwaaij2018}. We say that $\\psi_0$ and $\\psi_{0,1}$ are of level zero, and the basis functions $\\psi_{j,1},\\ldots,\\psi_{j,2^j}$ are said to be of level $j$. The Girsanov matrix $S$ defined in \\cref{eq:girsanovmatrix} with all basis function up to and including level $J$ is denoted by $S^J$. Note that $S^J$ has $2+\\sum_{j=1}^J2^j=2^{J+1}$ rows and columns, and $2^{2J+2}$ entries. \n\n\\begin{definition}\nLet $M^n$ be an $n\\times n$-matrix, and let $nz(M^n)$ the number of non-zero entries of $M^n$.\nThe level of sparsity of $M^n$ is the fraction of nonzero entries, $\\frac{nz(M^n)}{n^2}$. \n\\end{definition}\n\nThe definition of a sparse matrix is vague. Usually, we mean that the number of nonzero entries grows at most linear with the number of rows. We will establish that for $S^n$, the number of nonzero entries grows at most like $r\\log r$ with $r$ the number of rows. \n\nRecall the definition of $S_{l,l'}$ in \\cref{lem:marginallikelihood}.\nNote that $S_{l,l'}=0$  when $\\supp(\\psi_l)\\cap\\supp(\\psi_{l'})$ has Lebesgue measure zero. We say that $\\psi_l$ and $\\psi_{l'}$ have non-overlapping support when their supports are either disjoint or only share a boundary point; otherwise, we say they have overlapping support. \n\n%Note that for level \\(j\\ge 1\\), \\(\\psi_{j,k}\\) and \\(\\psi_{j,l}\\) have non-overlapping support when \\(k=l\\) (obviously, then they are equal). \n\nNote that both functions of level zero,  \\(\\psi_1\\) and \\(\\psi_{0,1}\\), have the same support $[0,1]$. \n\nWhen $j\\ge 0, d\\ge 0$ and $d+j\\ge 1$, there are \\(2^d\\) Faber functions of level \\(j+d\\) that have overlapping support with \\(\\psi_{j,k}\\), \\(j\\ge 0\\). These are \n\\[\n\\psi_{j+d,(k-1)2^d+1},\\psi_{j+d,(k-1)2^d+2},\\ldots,\\psi_{j+d,k2^d}\n\\]\nFor level 0, there are exactly two, and for level $1,\\ldots,j-1$ there is precisely one basis function with overlapping support with $\\psi_{j,k}$. \n\nSo for $\\psi_0$ and $\\psi_{0,1}$ there are \\begin{align*}\n    2 + \\sum_{d=1}^J 2^d = 2^{J+1} \n\\end{align*}\nbasis functions $\\psi_0,\\psi_{j',k'}, j'\\le J$ with overlapping support. \nFor $\\psi_{j,k}$, $j\\ge 1$,  there are \\begin{align*}\n    2+ j-1 + \\sum_{d=0}^{J-j} 2^d = %j+1 + 2^{J-j+1}-1=\n    j+2^{J-j+1}\n\\end{align*}\nbasis functions $\\psi_0,\\psi_{j',k'}, j'\\le J$, with overlapping support. When we make use of \\cref{lem:sumjtwotothepowerj}, we see that $S^n$ has at most \\begin{align*}\n   &2\\cdot 2^{J+1}+\\sum_{ j=1}^J 2^j\\rh{j+2^{J-j+1}}\\\\\n= & 2\\cdot 2^{J+1}+ (J-1)2^{J+1} + 2 + J2^{J+1}  \\\\\n= & (2J+1)2^{J+1}+2\n   %= 2^{J+1}+2^{J+1} + \\sum_{ j=1}^J j2^j + J2^{J+1}\\\\ \n\\end{align*}\nnonzero entries. \n\n%Note that level zero has 2 basis functions, and level $j$, $j\\ge 1$ has $2^j$ basis functions. In total there are \\[\n%2+ \\sum_{j=1}^J2^j=%1+2^{J+1}-1=\n%2^{J+1}\n%\\]\n%basisfunctions. Hence, $S^J$ is a $2^{J+1}\\x 2^{J+1}$-matrix with $2^{2J+2}$ entries. \nSo the number of nonzero entries of $S^n$ grows at most like $r\\log r$ with $r$ the number of rows. It has level of sparsity at most\n\\[\n\\frac{(2J+1)2^{J+1}+2\n}{2^{2J+2}}= (2J+1)2^{-J-1}+2^{-2J-1},\n\\]\nwhich is of the order $\\frac {\\log r}r$. \n\n \\section{Credible bands}\n    Suppose we have a prior $\\Pi$ on $\\theta$, where $\\theta:\\re\\to\\re$ is a 1-periodic function. Let $X^T=(X_t:t\\in[0,T])$ be a sample path of $dX_t=\\theta(X_t)dt+dW_t$. Consider the posterior $\\Pi(\\sdot\\mid X^T)$. \n    \\begin{definition}\n        A \\textbf{pointwise credible band} of \\textbf{credible level} $1-\\alpha$ are two functions $f_L:\\re\\to \\re$ and $f_H:\\re\\to \\re$ so that for each $t\\in\\re$,  \n        \\[\n        \\Pi(\\set{\\theta: f_L(t)\\le\\theta(t)\\le f_H(t)} \\mid X^T) \\ge 1-\\alpha. \n        \\] \n        A \\textbf{simultaneous  credible band} of \\textbf{credible level} $1-\\alpha$ are two functions $f_L:\\re\\to \\re$ and $f_H:\\re\\to \\re$ so that \n        \\[\n        \\Pi(\\set{\\theta: f_L(t)\\le\\theta(t)\\le f_H(t)\\, \\forall t} \\mid X^T) \\ge 1-\\alpha. \n        \\] \n    \\end{definition}\n    So \n\\[  \\text{  \\textbf{simultaneous credible band} }\\implies\\text{ \\textbf{pointwise credible band.}}\\] The reverse does not hold necessarily. \n\n\n\\subsection{How to construct credible bands}\n\n\\subsubsection{Exact pointwise credible bands} \n\nWith Gaussian process priors you can construct exact pointwise credible bands. The posterior is of the form \\[\nf(t)=\\sum_{k=1}^N \\theta_k\\phi_k, \\quad \\begin{pmatrix}\n    \\theta_1\\\\\\vdots\\\\\\theta_N\n\\end{pmatrix} \\sim N(m,V), \n\\]\nwhere $m$ is the $N$-dimensional mean vector and $V$ is the $N\\x N$-covariance matrix. \n\nThe coefficients are multivariate normally distributed, so $f(t)$ is, as a linear combination of the coefficients, normally distributed with mean \\[\n\\E [f(t)] = \\sum_{k=1}^N \\E[\\theta_k]\\phi_k(t)=\\sum_{k=1}^Nm_k\\phi_k(t)\n\\]\nand variance \\begin{align*}\n\\var(f(t))= & \\sum_{k=1}^N\\sum_{\\ell=1}^N \\cov(\\theta_k,\\theta_\\ell)\\phi_k(t)\\phi_\\ell(t)\\\\\n =& \\sum_{k=1}^N\\sum_{\\ell=1}^N V_{k\\ell}\\phi_k(t)\\phi_\\ell(t) \n\\end{align*}\nLet $\\xi_p$ be the quantile function of a standard normally distributed random variable $Z$, so $\\P(Z\\le \\xi_p)=p$. \nThe \\textit{exact} pointwise credible band (around the posterior mean) is \\begin{align*}\nf_L(t) = &\\E [f(t)] - \\sqrt{\\var(f(t))} \\xi_{1-\\alpha/2}\n\\intertext{and}\n f_H(t) =& \\E [f(t)] + \\sqrt{\\var(f(t))} \\xi_{1-\\alpha/2}.  \n\\end{align*}\n\n\\subsubsection{Simulated simultaneous credible bands}\n\nHere I describe a procedure to simulate a $1-\\alpha$-simultaneous credible band around the posterior mean. \n\n\\begin{algorithm}\n    Given a prior $\\Pi$ on a space of drift functions, and data $X^T=(X_t:t\\in[0,T])$. \n    \\begin{enumerate}\n        \\item Calculate the posterior $\\Pi(\\sdot\\mid X^T)$,\n        \\item calculate the posterior mean $\\bar \\theta= \\int \\theta d\\Pi(\\theta \\mid X^T)$ (you may use the \\verb|mean| function in the \\textit{BayesianNonparametricStatistics.jl} package),\n        \\item simulate $\\theta_1,\\ldots,\\theta_M$ from the posterior, \n        \\item for each $i$, calculate $d_i=\\sup\\set{|\\theta_i(t)-\\bar \\theta(t)|:t\\in \\re}$.\n        \\item take the  $\\ceil{(1-\\alpha)\\cdot M}$ functions $\\theta_{(1)},\\ldots, \\theta_{(\\ceil{(1-\\alpha)M})}$ from $\\theta_1,\\ldots,\\theta_M$ for which $d_i$ is the smallest. \n        \\item Define $f_L$ and $f_M$ as \n        \\begin{align*}\n        f_L(t)=& \\min\\set{\\theta_{(1)}(t), \\ldots, \\theta_{(\\ceil{(1-\\alpha)M})}(t)}\n        \\en f_H(t)= \\max\\set{\\theta_{(1)}(t), \\ldots, \\theta_{(\\ceil{(1-\\alpha)M})}(t)}.\n        \\end{align*}\n    \\end{enumerate}\n\\end{algorithm}\n\n\\appendix\n\n\\section{Lemma}\n\n\\begin{lemma}\\label{lem:sumjtwotothepowerj}\n   For each $J\\in \\NN$,  \\[\n    \\sum_{j=1}^Jj2^j=(J-1)2^{J+1} + 2. \n    \\]\n\\end{lemma}\n\\begin{proof}\n    Note that \n    \\begin{align*}\n    \\sum_{j=1}^J j2^j =&\\sum_{j=1}^J \\sum_{k=j}^J2^k\\\\\n    = & \\sum_{j=1}^J 2^j\\sum_{k=0}^{J-j}2^k \\\\\n    = & \\sum_{j=1}^J 2^j (2^{J-j+1}-1)\\\\\n    = & J2^{J+1} - (2^{J+1}-2)\\\\  \n    = & (J-1)2^{J+1} + 2.\n\\end{align*}\n\n\\end{proof}\n\n\n%\r\n%\r\n%Every Faber-Schauder function is obviously dependent with itself. \r\n%\r\n%Indexing with \\(i=2^j+k\\), when \\(\\psi_{j,k}\\) has index \\((j,k)\\) (excluding \\(i=1\\)), we see that, when \\(j\\ge 0\\), \\(\\psi_i\\) is dependent with \\(2^{j'-j}\\), functions \\(\\psi_{j',k'}\\), \\(i'=2^{j'}+k'\\ge i\\) of level \\(j'\\ge j\\)  (including itself, when \\(j'=j\\)).\r\n%\r\n%So if \\(J\\) is the higest level, \\(\\psi_i\\) is dependent with \r\n%\\[\r\n%\\sum_{d=0}^{J-j}2^d=2^{J-j+1}-1.\r\n%\\]\r\n%Faber-Schauder functions \\(\\psi_{i'}\\) with index \\(i'\\ge i\\). \r\n%Hence summing over all levels \\(0,\\ldots,J\\) and indices within a level, the number of combinations of functions \\((\\psi_{j,k},\\psi_{j',k'}),0\\le j,j'\\le J\\) and  \\(i=2^j+k\\le 2^{j'}+k'=i'\\) which are dependent is\r\n%\\begin{align*}\r\n%\\sum_{j=0}^J\\sum_{k=1}^{2^j}(2^{J-j+1}-1)\\\\\r\n%=\\sum_{j=0}^J(2^{J+1}-2^j)\\\\\r\n%=(J+1)2^{J+1}-(2^{J+1}-1)\\\\\r\n%=J2^{J+1}+1. \r\n%\\end{align*}\r\n%\r\n%The Faber-Schauder function \\(\\psi_1\\) is dependent with every Faber-Schauder function (including itself) up to and including level \\(J\\), which counts for \\(2^{J+1}\\) Faber-Schauder functions with a higher index or equal index, up to level \\(J\\). \r\n%\r\n%In total we have \r\n%\r\n%\\[\r\n%J2^{J+1}+1+2^{J+1}=(J+1)2^{J+1}+1. \r\n%\\]\r\n%Faber-Schauder functions up to level \\(J\\) dependent with a Faber-Schauder function with equal (itself) or higher index. \r\n%\r\n%\r\n%If we only consider dependent pairs \\((\\psi_i,\\psi_{i'})\\) with \\(i'>i\\), then we have \r\n%\\[\r\n%J2^{J+1}+1\r\n%\\]\r\n%of such pairs (minus all \\(2^{J+1}\\) diagonal pairs \\((\\psi_i,\\psi_i)\\)).\r\n%\r\n%Hence, by symmetry, there are in total \\(J2^{J+1}+1+J2^{J+1}+1+2^{J+1}=(2J+1)2^{J+1}+2\\) pairs \\((\\psi_i,\\psi_{i'})\\) that are dependent.\r\n%\r\n%\\begin{lemma}\r\n%\tThe Girsanov covariantie matrix is sparse.\r\n%\\end{lemma}\r\n%\\begin{proof}\r\n%\tAt most \\((2J+1)2^{J+1}+2\\) entries of the \\(2^{J+1}\\times 2^{J+1}\\)-matrix (\\(2^{2J+2}\\) entries) are nonzero. The fraction of nonzero elements is at most\r\n%\t\\[\r\n%\t\\frac{(2J+1)2^{J+1}+2}{2^{2J+2}}=(2J+1)2^{-J-1}+2^{-2J-1},\r\n%\t\\]\r\n%\twhich converges to zero. \r\n%\\end{proof}\r\n\\end{document}\r\n", "meta": {"hexsha": "e474d4327b1a7e5ffc98779630b1609b313032a0", "size": 21694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics/math.tex", "max_stars_repo_name": "Jan-van-Waaij/BayesianNonparametricStatistics", "max_stars_repo_head_hexsha": "8ab5c9f995d83528688f061212b2580a53c226ff", "max_stars_repo_licenses": ["MIT"], "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/math.tex", "max_issues_repo_name": "Jan-van-Waaij/BayesianNonparametricStatistics", "max_issues_repo_head_hexsha": "8ab5c9f995d83528688f061212b2580a53c226ff", "max_issues_repo_licenses": ["MIT"], "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/math.tex", "max_forks_repo_name": "Jan-van-Waaij/BayesianNonparametricStatistics", "max_forks_repo_head_hexsha": "8ab5c9f995d83528688f061212b2580a53c226ff", "max_forks_repo_licenses": ["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.1650943396, "max_line_length": 471, "alphanum_fraction": 0.6259795335, "num_tokens": 8492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6543479154771147}}
{"text": "%% AMAT 415 Assignment 3 \n% Safian Omar Qureshi\n% ID 10086638\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*{AMAT 415 Assignment 3}\n\n\\begin{par}\nSafian Omar Qureshi ID 10086638\n\\end{par} \\vspace{1em}\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Question 3(a)\n   \\item Question 3(b)\n   \\item Question 3(c)\n   \\item Question 3(d)\n\\end{itemize}\n\n\n\\subsection*{Question 3(a)}\n\n\\begin{verbatim}\nN = 64;\na = 200;\nn = linspace(0,63,64);\ntn = n/N;\nXn = exp((-a)*(tn - 0.5).^2);\n\n\nfigure;\nplot(tn,Xn);\nxlabel('tn')\nylabel('Xn')\ntitle('Xn vs tn')\n\\end{verbatim}\n\n\\includegraphics [width=4in]{untitled_01.eps}\n\\begin{verbatim}\nDFTXn = fft(Xn);\nimDFTXn = imag(DFTXn);\n\nfigure;\nplot(tn,DFTXn);\nxlabel('tn')\nylabel('DFTXn')\ntitle('DFTXn vs tn')\n\nfigure;\nplot(tn,imDFTXn);\nxlabel('tn')\nylabel('imDFTXn')\ntitle('imDFTXn vs tn')\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}Warning: Imaginary parts of complex X and/or Y arguments ignored \n\\end{verbatim} \\color{black}\n    \n\\includegraphics [width=4in]{untitled_02.eps}\n\n\\includegraphics [width=4in]{untitled_03.eps}\n\n\n\\subsection*{Question 3(b)}\n\n\\begin{verbatim}\nshiftDFTXn = fftshift(DFTXn);\nshiftimDFTXn = fftshift(imDFTXn);\n\nfigure;\nplot(tn,shiftDFTXn);\nxlabel('tn')\nylabel('Shifted DFTXn')\ntitle('Shifted DFTXn vs tn')\n\nfigure;\nplot(tn,shiftimDFTXn);\nxlabel('tn');\nylabel('Shifted imDFTXn');\ntitle('Shifted imDFTXn vs tn');\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}Warning: Imaginary parts of complex X and/or Y arguments ignored \n\\end{verbatim} \\color{black}\n    \n\\includegraphics [width=4in]{untitled_04.eps}\n\n\\includegraphics [width=4in]{untitled_05.eps}\n\n\n\\subsection*{Question 3(c)}\n\n\\begin{verbatim}\nDubXn = exp((-2*a)*(tn - 0.5).^2);\nHafXn = exp((-0.5*a)*(tn - 0.5).^2);\n\nfigure;\nplot(tn,DubXn);\nxlabel('tn')\nylabel('Double a Xn')\ntitle('Double a Xn vs tn')\n\nfigure;\nplot(tn,HafXn);\nxlabel('tn')\nylabel('Half a Xn')\ntitle('Half a Xn vs tn')\n\\end{verbatim}\n\n\\includegraphics [width=4in]{untitled_06.eps}\n\n\\includegraphics [width=4in]{untitled_07.eps}\n\\begin{verbatim}\nDFTDubXn = fft(DubXn);\nDFTHafXn = fft(HafXn);\nIMG_DFTDubXn = imag(DFTDubXn);\nIMG_DFTHafXn = imag(DFTHafXn);\n\nshiftDFTDubXn = fftshift(DFTDubXn);\nshiftDFTHafXn = fftshift(DFTHafXn);\nIMG_shift_DFTDubXn = fftshift(IMG_DFTDubXn);\nIMG_shift_DFTHafXn = fftshift(IMG_DFTHafXn);\n\nfigure;\nplot(tn, shiftDFTDubXn);\nxlabel('tn')\nylabel('Shifted Double a DFTXn')\ntitle('Shifted Double a DFTXn vs tn')\n\nfigure;\nplot(tn, shiftDFTHafXn);\nxlabel('tn')\nylabel('Shifted Half a DFTXn')\ntitle('Shifted Half a DFTXn vs tn')\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}Warning: Imaginary parts of complex X and/or Y arguments ignored \nWarning: Imaginary parts of complex X and/or Y arguments ignored \n\\end{verbatim} \\color{black}\n    \n\\includegraphics [width=4in]{untitled_08.eps}\n\n\\includegraphics [width=4in]{untitled_09.eps}\n\\begin{verbatim}\nfigure;\nplot(tn, IMG_shift_DFTDubXn);\nxlabel('tn')\nylabel('Imaginary Shifted Double a DFTXn')\ntitle('Imaginary Shifted Double a DFTXn vs tn')\n\nfigure;\nplot(tn, IMG_shift_DFTHafXn);\nxlabel('tn')\nylabel('Imaginary Shifted Half a DFTXn')\ntitle('Imaginary Shifted Half a DFTXn vs tn')\n\\end{verbatim}\n\n\\includegraphics [width=4in]{untitled_10.eps}\n\n\\includegraphics [width=4in]{untitled_11.eps}\n\n\n\\subsection*{Question 3(d)}\n\n\\begin{verbatim}\nalternating_row = (-1).^[0:63];\nalternatingDFTXn = (alternating_row).*(DFTXn);\ninv_alternatingDFTXn = ifft(alternatingDFTXn);\n\n\nfigure;\nplot(tn, inv_alternatingDFTXn);\nxlabel('tn')\nylabel('Inverse DFT of Xn multiplied by [1,-1,...]')\ntitle('Inverse DFT of Xn multiplied by [1,-1,...]  vs tn')\n\\end{verbatim}\n\n\\includegraphics [width=4in]{untitled_12.eps}\n\n\n\n\\end{document}\n    \n", "meta": {"hexsha": "b0aa7fa50569a4431cf8342ab71f7277d8fe9d44", "size": 3858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math courses/AMAT415 - Mathematical methods/assignments/as3/assignment3.tex", "max_stars_repo_name": "q-omar/UofC", "max_stars_repo_head_hexsha": "03ad4cb9145854394c98ccdb6292825d2b3927c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-11T10:18:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-11T10:18:55.000Z", "max_issues_repo_path": "math courses/AMAT415 - Mathematical methods/assignments/as3/assignment3.tex", "max_issues_repo_name": "q-omar/UofC", "max_issues_repo_head_hexsha": "03ad4cb9145854394c98ccdb6292825d2b3927c6", "max_issues_repo_licenses": ["MIT"], "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 courses/AMAT415 - Mathematical methods/assignments/as3/assignment3.tex", "max_forks_repo_name": "q-omar/UofC", "max_forks_repo_head_hexsha": "03ad4cb9145854394c98ccdb6292825d2b3927c6", "max_forks_repo_licenses": ["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.5837563452, "max_line_length": 107, "alphanum_fraction": 0.7156557802, "num_tokens": 1348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.6543479052218663}}
{"text": "\\section{Modeling probabilistic design}\n\\label{sect:prob-formulation}\n\nTo verify a deterministic design,\nproperties are often asserted at the primary outputs of a circuit to examine whether\nthere exists an assignment to the primary inputs that falsifies some of the properties.\nIf there exists such an assignment,\na counterexample to a property is found.\n\nHowever, when it comes to probabilistic design,\nthe same approach is not fully adequate.\nSince a probabilistic circuit could produce different output responses for the same input stimulus,\ncomputing the probability of property violation is more meaningful than searching for a counterexample.\nHence we pose the following question:\n\\textit{\n    Given a probabilistic circuit and a property to be verified,\n    what is the average or maximum probability for the property to be violated?\n}\nWe model a probabilistic design as a probabilistic Boolean network and\nformalize \\textit{probabilistic property evaluation} (PPE) to answer the question.\nWhile the evaluation of combinational probabilistic design is of our primary interest,\nthe proposed framework is also extensible to sequential probabilistic design.\n\n\\subsection{Probabilistic Boolean network}\nWe define a probabilistic Boolean network to model circuits with logic gates that exhibit probabilistic behavior.\nA \\textit{probabilistic Boolean network} (PBN) is a Boolean network $G=(V,E)$ with random variables annotated to its vertices.\nThe probabilistic behavior of a PI $v \\in V_I$ is modeled by a Bernoulli random variable\n$B_v\\sim\\textit{Bernoulli}(p_v)$ with $p_v=\\Pr[v=\\top]$.\nThe probabilistic behavior of the output of a vertex $v \\in V\\setminus V_I$ is modeled with a Bernoulli random variable $B_v\\sim\\textit{Bernoulli}(p_v)$ with $p_v$ corresponding to the error rate of $v$.\n\nIn general,\ntwo random variables $B_u$ and $B_v$ for $u,v \\in V$ and $u \\neq v$ can be dependent,\nand their joint distribution has to be considered.\nIn this paper,\nwe first focus on the simplified situation where the random variables of vertices are mutually independent,\nand refer to a PBN whose random variables are mutually independent as an \\textit{independent PBN}.\nWe will show how to extend the proposed framework to a PBN with mutually dependent random variables later.\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics{fig/build/prob-distillation.pdf}\n    \\caption{Distillation of a \\nand gate with an error rate $p$}\n    \\label{fig:prob-distillation}\n\\end{figure}\n\nGiven a PBN $G=(V,E)$,\nwithout loss of generality,\nwe standardize $G$ by converting it to a \\textit{standardized PBN} (SPBN) $G'=(V',E')$\nwith the \\textit{distillation operation} depicted in~\\cref{fig:prob-distillation},\nusing an erroneous \\nand gate as an example.\nFor each node $v \\in V\\setminus V_I$ of $G$ with an error rate $p_v$,\nits probabilistic behavior is distilled into an error source modeled by an auxiliary Boolean input $z$\nwith $B_z\\sim\\textit{Bernoulli}(p_v)$ for $\\Pr[z=\\top]=p_v$.\nMoreover, an \\xor gate is used to conditionally invert the output of the error-free node $v$\nif and only if $z$ valuates to $\\top$.\nNote that an auxiliary input differs from a primary input in that\nthe error rate $p_z$ of an auxiliary input is fixed with respect to the characteristics of a probabilistic node\nrather than determined by the environmental input behavior.\nIn the following, we let $V_Z$ be the set of auxiliary inputs (AIs) of an SPBN.\n\n\\subsection{Probabilistic property evaluation}\nTo formally reason about probabilistic design,\nwe formulate \\textit{probabilistic property evaluation} (PPE) by capturing the degree of property violation with probability.\nWe distinguish between \\textit{input assignment} and \\textit{parameter assignment} in PPE.\nAn \\textit{input assignment} assigns a truth value to a Boolean variable $v$ for every PI.\nOn the other hand,\na \\textit{parameter assignment} specifies a probability $p_v$ for a PI $v$ to be \\textsc{true}.\nNote that the probability of an error source $z \\in V_Z$ is determined by the underlying PBN and needs not be assigned.\n\nTo analyze a probabilistic design,\nwe define \\textit{signal probability} as follows.\n\\begin{definition}[Signal Probability (parameterized)]\n    \\label{def:prob-signal-prob}\n    Given an SPBN $G=(V,E)$ and a parameter assignment $\\pi:V_I\\mapsto[0,1]$,\n    the \\textit{signal probability} or \\textit{satisfying probability} of a node $v \\in V$\n    with respect to the parameter assignment $\\pi$ is $\\Pr[v=\\top]$ under $\\pi$.\n\\end{definition}\nIt is natural to ask under what parameter assignment the signal probability of some node is maximized.\nIt corresponds to the following definition.\n\\begin{definition}[Signal Probability (maximized)]\n    \\label{def:prob-signal-prob-max}\n    Given an SPBN $G=(V,E)$,\n    the \\textit{maximum signal probability} or \\textit{maximum satisfying probability} of a node\n    $v\\in V$ is $\\Pr[v=\\top]$ maximized over all parameter assignments.\n\\end{definition}\n\nNotice that, given a parameter assignment to the PIs of an SPBN $G=(V,E)$,\nwe could associate a random variable $R_v\\sim\\textit{Bernoulli}(p)$ with each node $v \\in V$\nsuch that $p=\\Pr[v=\\top]$ under $\\pi$.\nThose random variables can be mutually dependent (even for an SPBN derived from an independent PBN)\ndue to the reconvergent paths in the Boolean network.\n\nAccording to~\\cref{def:prob-signal-prob-max},\nwe have the following proposition on parameter assignments that maximize signal probability.\n\n\\begin{proposition}\n    Given an SPBN $G=(V,E)$ and an arbitrary $v \\in V$,\n    there exists a parameter assignment $\\pi$ that maximizes the signal probability of $v$\n    such that $\\pi(u)$ equals either probability 0 or 1 for any $u \\in V_I$.\n\\end{proposition}\n\\begin{proof}\n    Assume there exists an optimal parameter assignment $\\pi$ not in such a form.\n    That is, there exists some $u \\in V_I$ such that $0<\\pi(u)<1$.\n    Denote the signal probabilities of $v$ under $\\pi(u)=0$ and $\\pi(u)=1$ by $p_0$ and $p_1$, respectively.\n    Note that $\\Pr[v=\\top]$ under $\\pi$ equals $(1-\\pi(u)) \\times p_0 + \\pi(u) \\times p_1$,\n    and $\\min\\{p_0,p_1\\}\\leq\\Pr[v=\\top]\\leq\\max\\{p_0,p_1\\}$.\n    If $p_0 \\neq p_1$,\n    there is a contradiction since $\\Pr[v=\\top]<\\max\\{p_0,p_1\\}$,\n    and $\\pi$ is not an optimal assignment.\n    If $p_0=p_1$, W.L.O.G., set $\\pi(u)=0$.\n    So the optimal assignment must be in the stated form.\n\\end{proof}\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics{fig/build/prob-spbn-miter.pdf}\n    \\caption{A miter SPBN for probabilistic property evaluation}\n    \\label{fig:prob-spbn-miter}\n\\end{figure}\n\nTo formulate the PPE problem,\nwe construct a \\textit{miter SPBN} as shown in~\\cref{fig:prob-spbn-miter}.\nGiven a \\textit{design SPBN} $G_D$ modeling a probabilistic circuit and\na \\textit{property SPBN} $G_P$ specifying a property under verification,\na miter SPBN $G_M$ is built by connecting relevant primary outputs of $G_D$ to the primary inputs of $G_P$.\nThe property SPBN is used to monitor the design SPBN.\nLet $X$ be the set of PIs of $G_D$,\n$Z$ be the set of AIs of $G_D$,\n$W$ be a subset of PIs of $G_P$,\nand $Y$ be the set of all other vertices.\nNote that $G_P$ may have additional inputs $W$ to enrich the expressiveness of property.\nFor example, they can be used to prioritize the primary outputs of $G_D$.\nBased on signal probability,\ntwo versions of the PPE problem are defined below.\n\n\\begin{definition}[PPE (maximized)]\n    Given a miter SPBN $G_M$ with the vertex sets $X,Y,Z,W$ defined as above,\n    the \\textit{maximum probabilistic property evaluation} (MPPE) problem asks to find the maximum satisfying probability of the output of $G_M$.\n    That is,\n    the signal probability of the miter output corresponds to the maximum probability of property violation under all parameter assignments.\n\\end{definition}\n\n\\begin{definition}[PPE (parameterized)]\n    Given a miter SPBN $G_M$ with the vertex sets $X,Y,Z,W$ defined as above and a parameter assignment $\\pi:X\\mapsto[0,1]$,\n    the \\textit{probabilistic property evaluation} (PPE) problem asks to find the satisfying probability of the output of $G_M$.\n    That is,\n    the signal probability of the miter output corresponds to the probability of property violation under the given parameter assignment.\n\\end{definition}\n\n\\subsection{Extension to sequential probabilistic design}\nAlthough the above PPE and MPPE frameworks mainly focus on combinational design,\nthey are extensible to analyze sequential design by \\textit{circuit unrolling}~\\cite{Clarke2001},\nsimilar to the soft-error reliability analysis for sequential circuits~\\cite{Miskov-Zivanov2008}.\nFor example,\nto find the probability of property violation after $T$ clocks of execution,\nthe sequential circuit is \\textit{unrolled} into a combinational circuit by connecting $T$ copies of the combinational block of the sequential circuit to mimic the state transitions in $T$ time frames.\nFor simplicity,\nthe occurrences of errors among different time frames are assumed to be temporally independent,\ni.e., the random variables governing the probabilistic behavior of errors among different time frames are mutually independent.\nAfter unrolling,\nthe proposed PPE and MPPE frameworks can be applied to the effective combinational circuit and\nanalyze the satisfying probability of the output at the $T^\\mathrm{th}$ time frame.\nThe result corresponds to the probability of property violation of the sequential design after $T$ clocks of execution.", "meta": {"hexsha": "d68b63d5ec4920f00f8a014c751e74dee3b10916", "size": 9467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/prob-design-eval/formulation.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/prob-design-eval/formulation.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/prob-design-eval/formulation.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": 58.0797546012, "max_line_length": 203, "alphanum_fraction": 0.7646561741, "num_tokens": 2419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6543432023384245}}
{"text": "\\subsection{Counting in Graph}\n\n\\lem{Average of Degrees}{\n    In a graph $ G $ with $ n $ vertexes, let $ E $ be the set of all edges.\n    Assign an integer $ f_i $ to every vertex $ v_i $ such that $ f_i $ equals to\n    the everage degree of the neighbors of $ v_i $. We have, \\[ \\sum_{i=1}^{n} f_i\n    \\geq 2|E| \\] \n}\\label{lemma:graph_lemma_1}\n\n\n\\lem{}{In a graph $ G $ with $ n $ vertexes, let $ E $ be the set of all edges. Assign an integer $ g_i $ to every vertex $ v_i $ such that $ g_i $ equals to the maximum degree among its neighbors. We have, \\[ \\sum_{i=1}^{n} g_i \\geq 2|E| \\] }\n\n\n\\prob{https://artofproblemsolving.com/community/c6h568277p3332307}{USA TST 2014 P3}{H}{Let $n$ be an even positive integer, and let $G$ be an $n$-vertex graph with exactly $\\tfrac{n^2}{4}$ edges, where there are no loops or multiple edges (each unordered pair of distinct vertices is joined by either 0 or 1 edge). An unordered pair of distinct vertices $\\{x,y\\}$ is said to be amicable if they have a common neighbor (there is a vertex $z$ such that $xz$ and $yz$ are both edges). Prove that $G$ has at least $2\\textstyle\\binom{n/2}{2}$ pairs of vertices which are amicable.}\n\n\\solu{Define friendship in a different way, bounding below, keeping in mind the equality case. Then using the previous lemma.}\n\n\n\\begin{minipage}{.6\\linewidth}\n    \\theo{https://en.wikipedia.org/wiki/Turan's_theorem}\n    {Turan's theorem}{\n        Let $ G $ be any graph with $ n $ vertices, such that $ G $ is $ K_{r+1} $\n        -free. Then $ G $ is the ``Turán's Graph'' and is a complete $ r $ partite\n        graph. And the number of edges in $ G $ is at most \n\n        \\[\\frac {r-1}{r}\\cdot \\frac {n^{2}}{2}=\\left(1-\\frac {1}{r}\\right)\\cdot\n        \\frac {n^{2}}{2}\\]\n\n        A special case of Turán's theorem for $ n=2 $ is the \\textbf{Mantel's\n        Theorem}. It states that the maximal triangle free graph is a complete\n        bipartite graph with at most $ \\left\\lfloor\\dfrac{n^2}{4}\\right\\rfloor $\n        edges.\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.37\\linewidth}\n    \\figdf{.9}{Turan_13-4}{Turán's Graph}\n\\end{minipage}\n\n\\vspace{1em}\n\n\n\\proof{We need to prove that the maximal graph is the $ r $ partite one, and the rest will follow. We can directly try to prove that this graph is $ r $ colorable, but that is quite troublesome. Instead, we try to show that, we can partition the vertices of $ G $ into equivalence classes based on their non-neighbors. Since this is imply the former. So we need to prove that \\hrf{lemma:criteria_of_partition_equiv}{this} holds for this graph.\\\\ \n\nThe way it is done is quite interesting. We need to show that if the criteria doesn't hold in this graph, then this graph is not the maximal graph. How are we going to do that? We compare the degrees of $ u, w $, and replace either $ u $ by $ w $ or $ w $ by $ u $ to get a graph with more edges and without the nasty situation.}\n\n\n\n\\prob{}{}{E}{$ 155 $ birds $ P_1, P_2, \\dots, P_{155} $ are sitting down no the boundary of a circle $ C $. Two birds $ P_i, P_j $ are mutually visible if the angle at the center of their cord, $ m(P_iP_j)\\le 10^\\circ $. Find the smallest number of mutually visible pairs of birds.}\n\n\n\\prob{}{}{E}{For a pair $ A = (x_1, y_1) $ and $ B = (x_2, y_2) $ of points on the coordinate plane, let $ d(A, B)  = |x_1 - x_2| + |y_1 - y_2|$. We call a pair $ (A,B) $  of unordered points harmonic if $ 1<d(A,B)\\le 2 $. Determine the maximum number of harminc pairs among $ 100 $ points in the plane.}\n\n\n\n\n\n\\prob{www.hehe.com}{Swell coloring}{E}{Let $ K_n $ denote the complete graph on $ n $ vertices, that is, the graph with $ n $ vertices's such that every pair of vertices's is connected by an edge. A swell coloring of $ K_n $ is an assignment of a color to each of the edges such that the edges of any triangle are either all of distinct colors or all the same color. Further, more than one color must be used in total (otherwise trivially if all edges are the same color we would have a swell coloring). Show that if $ K_n $ can be swell colored with $ k $ colors, then $ k \\geq \\sqrt{n} + 1 $.}\\label{problem:forget_and_focus_5}\n\n\\solu{Concentrate on only one vertex.}\n\n\n\n\\prob{www.hehe.com}{Belarus 2001}{MH}{Given $ n $ people, any two are either friends or enemies, and friendship and enmity are mutual. I want to distribute hats to\tthem, in such a way that any two friends possess a hat of the same color but no two enemies possess a hat of the same color. Each person can receive multiple hats. What is the minimum number of colors required to always guarantee that I can do this?}\\label{problem:extremal_case_whole_6}\n\n\\solu{In this problem, finding the worst case is a big help, because once the answer is guessed, the things become really clear.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1468154p8509521}{ELMO 2017 P5}{M (8/10)}{The edges of $ K_{2017} $ are each labeled with $ 1, 2 $ or $ 3 $ such that any triangle has sum of labels at least $ 5. $ Determine the minimum possible average of all labels. (Here $ K_{2017} $ is defined as the complete graph on 2017 vertices's, with an edge between every pair of vertices's.)}\\label{problem:induction_type1_13}\n\n\\solu{A starting idea to get the ans: if we discard of all the $ 2 $-edges, we see that in any triangle, one edge has to be a $ 3 $-edge. So... Turan-kinda...}\n\n\\solu{After getting the ans, and thinking about approaching inductively, if we remove only one vertex, there will be pairs to consider. But if we remove two vertices, we will only need to consider single vertices after the removal of these two vertices.\\\\\n\n    Now which pair of vertices are the best choice to remove? Before doing that, lets first think how much change will we get in the sum after we remove two vertices. Since we have the ans, we do quick maffs: \n    \\[m(4m+1) - (m-1)(4m-3) = 8m -3 = 4\\times (2m-1) + 1\\]\n\nDoesn't this indicate that we remove a $ 1 $-edge, so the other edges coming out of the two vertices will sum up to be at least $ 4*(2m-1) $.}\n\n\n\\solu{The solution by bern is very pretty. What he probably had thought was:\\\\\n\n    If we pick a vertex, say $ u $, and take an $ 1 $-edge from this vertex to another vertex $ v $, we see that there are at least as many $ 3 $-edges in $ u $ than there are $ 1 $-edges in $ v $. Now if to get a more accurate value of $ d_3(u) $ (defined naturally), we need to take the maximum of the values $ d_1(v) $ for all $ v $'s connected to $ u $. \\\\\n\n    Now we need to evaluate the number of $ 3 $ edges from the $ d_1 $ values. Can we put a bound on this sum? We have \\hrf{lemma:graph_lemma_1}{\\textbf{this lemma}}, does this help? Turns out that it does.\\\\\n\nWhat left is to sum it all up to see if we can get the ans.}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h35320p220234}{ARO 2005 P9.4}{M (7/10)}{ $ 100 $ people from $ 50 $ countries, two from each countries, stay on a circle. Prove that one may partition them onto $ 2 $ groups in such way that neither no two countrymen, nor three consecutive people on a circle, are in the same group.\\\\\n\n\\textbf{Variant:} There are $ 100 $ people from $ 25 $ countries sitting around a circular table. Prove that they can be separated into four classes, so that no two countrymen are in the same class, nor any two people sitting adjacent in the circle.}\\label{problem:hall_marriage_2}\n\n\\solu{Thinking of the most natural way of eliminating the consecutive condition -- pair two consecutive verices.}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h478015p2676752}{Romanian TST 2012 P4}{E (7/10)}{Prove that a finite simple planar graph has an orientation so that every vertex has out-degree at most $ 3 $.}\n\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h148822p841243}{USA TST 2006 P1}{E-M (8/10)}{A communications network consisting of some terminals is called a $3$-connector if among any three terminals, some two of them can directly communicate with each other. A communications network contains a windmill with $n$ blades if there exist $n$ pairs of terminals $\\{x_{1},y_{1}\\},\\{x_{2},y_{2}\\},\\ldots,\\{x_{n},y_{n}\\}$ such that each $x_{i}$ can directly communicate with the corresponding $y_{i}$ and there is a hub terminal that can directly communicate with each of the $2n$ terminals $x_{1}, y_{1},\\ldots,x_{n}, y_{n}$ . Determine the minimum value of $f (n)$, in terms of $n$, such that a $3$ -connector with $f (n)$ terminals always contains a windmill with $n$ blades.}\n\n\\solu{Windmills won't be there if among any $ 2n+1 $ vertices, there were one vertex that were not connected to any of the other $ 2n $ vertices. So that means that we are dealing Turan-kinda config here. So we can make several `compact' graphs that are mutually disconnected, and each have at most $ 2n $ verices. Guessing from this, the ans is probably of some form $ k*2n + 1 $. Now we have another condition to consider, $ 3 $-connector. Lets see, if we had $ 3 $ disconnected componets, the resulting graph wouldn't be a $ 3 $-connector. Done...}\n\n\n\n\n\\prob{}{}{E}{Graph $ G $ on $ n $ vertices has the property that the degree of every vertex is greater than $ 2 $. Prove that for every $ 0 < k < n $, there is a simple path with lenght at least $ n/k $ or, $ k $ cycles, such that every cycle has at least one node which none of the other cycles has, and its lenght is not divisible by $ 3 $.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h126200p715463}{ISL 2005 C4}{E}{Let $n\\geq 3$ be a fixed integer. Each side and each diagonal of a regular $n$-gon is labelled with a number from the set $\\left\\{1;\\;2;\\;...;\\;r\\right\\}$ in a way such that the following two conditions are fulfilled:\n    \\vspace{-1em}\n    \\begin{itemize}\n        \\setlength{\\itemindent}{-1.5em}\n    \\itemsep0em\n    \\item Each number from the set $\\left\\{1,2,\\dots r\\right\\}$ occurs at least once as a label.\n    \\item In each triangle formed by three vertices of the $n$-gon, two of the sides are labelled with the same number, and this number is greater than the label of the third side.\n\\end{itemize}\n\\vspace{-1em}\n\\begin{enumerate}\n    \\setlength{\\itemindent}{-1.2em}\n\\itemsep0em\n\\item Find the maximal $r$ for which such a labelling is possible.\n\\item For this maximal value of $r$, how many such labellings are there?\n        \\end{enumerate}\n    }\n\n    \\solu{[Extremal]Take the edges labeled with $ r $, and delete them. Study what is left. For the second part, formulate a recursive function, and try out small cases to find pattern.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h2091306p15108216}\n{St Petersburg 2020 P11.7}{}{\n    $N$ oligarchs built a country with $N$ cities with each one of them owning\n    one city. In addition, each oligarch built some roads such that the\n    maximal amount of roads an oligarch can build between two cities is $1$\n    (note that there can be more than $1$ road going through two cities, but\n    they would belong to different oligarchs).\n\n    A total of $d$ roads were built. Some oligarchs wanted to create a\n    corporation by combining their cities and roads so that from any city of\n    the corporation you can go to any city of the corporation using only\n    corporation roads (roads can go to other cities outside corporation) but\n    it turned out that no group of less than $N$ oligarchs can create a\n    corporation. What is the maximal amount that $d$ can have?\n}\n\n\\begin{solution}\n    At first I thought about ``cuts'' where we can only have roads owned by one\n    oligarch, but it proved to be really complex to work with. So I thought\n    about constructing the best solution. Trying it out for $3, 4$ immediately\n    gave the idea to construct optimally. Now on forward to proving it.\\\\\n\n    The proof is roughly as followed. We will show that if we remove the\n    oligarch indexed $N$, then we need to remove at most ${N \\choose 2}$\n    roads. Since there is no road owned by $N$ that connects to city $N$, the\n    roads owned by $N$ forms a forest of graphs with the other cities.\\\\\n\n    We show that for every edge in that forest, there is one less road leaving\n    city $N$. Which we do by induction. We take the set $\\left\\{1, 2, \\dots\n    N-1\\right\\}$, one of these cities has no road with $N$. WLOG, it is $1$.\n    Then inductively we can assume that city $i$ can have at most $i-1$ roads\n    with $N$.\\\\\n\n    Now for each $i$, starting with $N-1$, and ending at $1$, we show that in\n    reality, $i$ can have at most $i-1 - V_N(i)$ where $V_N(i)$ is the number\n    of roads owned by $N$ leaving $i$. It works inductively, and so after it,\n    we can just remove $N$, and assume our inductive hypothisis. Which gives\n    us our answer of \\[\\boxed{{N \\choose 3}}\\] \n\\end{solution}\n", "meta": {"hexsha": "3653983d8ce5fdd0fccfbe366ee29c000db0acbf", "size": 12717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec5_1_counting_in_graph.tex", "max_stars_repo_name": "M-Ahsan-Al-Mahir/BCS_Question_Bank", "max_stars_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2020-10-14T17:15:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T19:47:04.000Z", "max_issues_repo_path": "combi/sec5_1_counting_in_graph.tex", "max_issues_repo_name": "AnglyPascal/BCS_Question_Bank", "max_issues_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "combi/sec5_1_counting_in_graph.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": 71.8474576271, "max_line_length": 777, "alphanum_fraction": 0.7070850043, "num_tokens": 3653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8633916170039421, "lm_q1q2_score": 0.6542733170167666}}
{"text": "\\section{Countable and Uncountable Sets}\n\n\\begin{definition}\n  A set $A$ is said to be \\textbf{infinite} if it is not finite. It is said to\n  be \\textbf{countably infinite} if there is a bijective correspondence\n  \\begin{equation}\n    f:A \\to \\Zp\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n  A set is said to be \\textbf{countable} if it is either finite or countably\n  infinite. A set that is not countable is said to be \\textbf{uncountable}.\n\\end{definition}\n\n\\begin{theorem}\n  Let $B$ be a nonempty set, then the following are equivalent:\n  \\begin{enumerate}[label=(\\arabic*)]\n    \\item $B$ is countable\n    \\item There is a surjective function $f : \\Zp \\to B$\n    \\item There is an injective function $g : B \\to \\Zp$\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}\n  A countable union of countable sets is countable.\n\\end{theorem}\n\n\\begin{theorem}\n  A finite product of countable sets is countable.\n\\end{theorem}\n\n\\section*{Exercises}\n\n\\bx{\n  Lazy way to prove this, but you can make an injective function\n  $f : \\mathbb{Q} \\to \\Zp \\times \\Zp \\times \\Zp$\n  where given any\n  \\begin{equation*}\n    f(\\pm \\frac{m}{n}) = (m, n, \\pbrac{1 \\text{ if negative}, 2 \\text{ if positive}})\n  \\end{equation*}\n\n  And then we know that $\\Zp \\times \\Zp \\times \\Zp$\n  is a finite product of countable sets, so it is also countable. Since $f$ is\n  an injective function into a countably infinite set, we conclude that\n  $\\mathbb{Q}$ is also countably infinite.\n}\n\n\\bx{\n  Checking for bijections. I'm not going to explicitly show this, but you can find inverse functions to show bijectivity.\n  \\TODO.\n}\n\n\\bx{\n  The bijection is whether or not some $n \\in \\Zp$ is included in a set\n  or not, which corresponds to 0 (not included) and 1 (included) in the tuple of\n  $X^\\omega$.\n}\n\n\\bx{\n  \\ea{\n    \\item For a given $n$, the number of algebraic numbers is $\\prod_{i=0}^{n-1}\n    \\mathbb{Q}$. Then taking the union over $\\Zp$, this would be a\n    countable union of countable sets, which is also countable. Therefore there\n    are a countable number of algebraic numbers.\n    \\item AFSOC transcendental numbers are countable. Then the real numbers are\n    a union of two countable sets, which could make $\\mathbb{R}$ countable,\n    which is a contradiction.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item This set of functions can be bijected to $\\Zp \\times \\Zp$, which is countable.\n    \\item This would be $\\prod_{i=1}^n \\Zp$, which is a finite product of countable sets, which is countable.\n    \\item This is a countable union of countable sets, which is countable.\n    \\item Not countable, you can use diagonalization to construct a function that is not included in a countable map.\n    \\item Not countable, can also use a diagonalization argument to construct a function that differs in the $i^\\text{th}$ spot for $f_i$.\n    \\item Countable, since this is essentially a subset of the countable union of $\\Zp$. \\label{chap1:sec7:prob5:partf}\n    \\item Countable, same reasoning as \\ref{chap1:sec7:prob5:partf}\n    \\item This is a countable union of a countable union of countable sets, which is still countable.\n    \\item Countable, this is a subset of $\\Zp \\times \\Zp$.\n    \\item Countable, this is just $\\cup_{i=0}^\\infty \\prod_{j=1}^i \\Zp$, which is a countable union of a finite product of countable sets.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item Originally I was going to define the identity map $I : B \\to A$, since\n    $B \\subset A$, and say that injections both ways implies bijection, but\n    that's the theorem we are trying to prove in the next step, so let's just do\n    what the problem tells us here.\n\n    To understand the hint a bit more, the reason we can plug in $B$ values for\n    $f$ is because $B \\subset A$. And the reason that we get an $A_i$ value from\n    the result of $f$ is also because $B \\subset A$.\n\n    Now, if we define this new function $h$,\n    \\begin{equation}\n      h(x) = \\begin{cases}\n        f(x) &\\text{if $x \\in A_n - B_n$}\\\\\n        x &\\text{otherwise}\n      \\end{cases}\n    \\end{equation}\n\n    We have to check this function is bijective.\n    \\begin{itemize}\n      \\item \\textbf{Injective}: We have 2 cases for $x$. Either it is in $B$, in which case we just spit out $x$, or it is in $A_n$ but not in $B_n$, in which case we apply $f(x)$, and make $x \\in B$.\n      This is injective, because cases, for some $x_1, x_2 \\in A$,\n      \\begin{enumerate}\n        \\item $x_1, x_2 \\in A_n - B_n$, then we are just looking at $f$, which we know is injective\n        \\item $x_1 \\in A_n - B_n, x_2 \\not\\in A_n - B_n$, then $x_1 \\neq x_2$,\n        and since $x_1 \\in A_n - B_n$, it is never mapped to itself, because it\n        if were, then it would imply it is $\\not\\in A_n - B_n$, which is a\n        contradiction.\n        \\item $x_1, x_2 \\not\\in A_n - B_n$, then we are using the identity map, which is injective\n      \\end{enumerate}\n\n      \\item \\textbf{Surjective}: This is the more difficult part of the proof, but also the more fun.\n\n      The idea of the recursive definition is that we want to partition $B$ into parts, $A_i, B_i$.\n      The only part that we have trouble with is $A_1 - B_1$, since this part is\n      not in $B$. However, by applying $f$ to this portion, we can have it map\n      into $B$, which helps us map $B$. However, since $f(A_1)$ ``takes the\n      spot'' of $A_2$, we then apply $f$ on $A_2$, so that $f(A_2) \\subset B$.\n      $f(A_2)$ takes the spot of $A_3$, so we keep applying this recursive\n      definition. Eventually, we can see that all of $B$ is mapped, so $h$ is\n      also surjective on $B$.\n      I know this is an informal proof, but Figure\n      \\ref{chap1:sec7:prob6:parta:fig} explains the hardest part of the proof.\n\n      \\begin{figure}[H]\n        \\centering\n        \\begin{tikzpicture}\n          \\node[rectangle, draw, fill=gray!40] (r_1) at (0, 0) {$A_1$};\n          \\node[rectangle, draw, anchor=north west] (r_2) at (r_1.north east) {$B_1$};\n          \\node[rectangle, draw, anchor=north west, fill=gray!40] (r_3) at (r_2.north east) {$A_2$};\n          \\node[rectangle, draw, anchor=north west] (r_4) at (r_3.north east) {$B_2$};\n          \\node[rectangle, draw, anchor=north west, fill=gray!40] (r_5) at (r_4.north east) {$A_3$};\n          \\node[rectangle, draw, anchor=north west] (r_6) at (r_5.north east) {$B_3$};\n          \\node[rectangle, draw, anchor=north west, fill=gray!40] (r_7) at (r_6.north east) {$A_4$};\n          \\node[rectangle, draw, anchor=north west] (r_8) at (r_7.north east) {$B_4$};\n\n          \\draw[-stealth] (r_1.north) to[bend left=60] node[above] {$f$} (r_3.north);\n          \\draw[-stealth] (r_3.north) to[bend left=60] node[above] {$f$} (r_5.north);\n          \\draw[-stealth] (r_5.north) to[bend left=60] node[above] {$f$} (r_7.north);\n\n          \\draw[-stealth] (r_2.south) -- ++(0, -0.5);\n          \\draw[-stealth] (r_3.south) -- ++(0, -0.5);\n          \\draw[-stealth] (r_4.south) -- ++(0, -0.5);\n          \\draw[-stealth] (r_5.south) -- ++(0, -0.5);\n          \\draw[-stealth] (r_6.south) -- ++(0, -0.5);\n          \\draw[-stealth] (r_7.south) -- ++(0, -0.5);\n          \\draw[-stealth] (r_8.south) -- ++(0, -0.5);\n\n          \\draw ($(r_2.south west) + (0, -0.5)$) rectangle\n            ($(r_8.south east) + (0, -1)$) node[pos=.5] {$B$};\n        \\end{tikzpicture}\n        \\caption{Showing the subset partitions for $A_i, B_i$}\n        \\label{chap1:sec7:prob6:parta:fig}\n      \\end{figure}\n    \\end{itemize}\n\n    \\textbf{Note:} To be honest, I'm not sure why we had to go through the\n    trouble of defining the recursive definition. To me, it seems like with $f$,\n    the scenario is that $A$ maps to $B$ injectively, except there are some some\n    elements in $B$ that are not mapped.\n\n    \\textbf{Update:} It seems like the reason is that with a naive definition of\n    just $h(x)$ mapping $f(x)$ for $x \\in A-B$ and identity for $x \\in A \\cap\n    B$, we cannot claim that this combo of $f(x), x$ maps $B$ surjectively. See\n    the surjective part of the proof to see why this proof is so fun.\n\n    \\label{chap1:sec7:prob6:parta}\n\n    \\item We have two cases, either $A \\subset C$ or $C \\subset A$. In either\n    case, we can apply part \\ref{chap1:sec7:prob6:parta}.\n  }\n}\n\n\\bx{\n  We can see that $E \\subset D$. Need $f: D \\to E$. We can construct such an $f$\n  by representing each $x \\in \\Zp$ in binary, and mapping it to the\n  corresponding 0-1 tuple in $\\pbrac{0, 1}$.\n}\n\n\\bx{\n  \\TODO. I'm stuck. I assume we want to do the double bijective proof to show equal cardinalities.\n}\n\n\\bx{\n  \\ea{\n    \\item First rearrange, the formula to be easier to apply:\n    \\begin{equation*}\n      h(n+1) = \\sqrt{\n        h(n) + h(n-1)^2\n      }\n    \\end{equation*}\n    Trying out some values,\n    \\begin{align*}\n      h(3) &= \\sqrt{2 + 1} = \\sqrt{3}\\\\\n      h(4) &= \\sqrt{4 + \\sqrt{3}}\\\\\n      h(5) &= \\sqrt{3 + \\sqrt{4 + \\sqrt{3}}}\n    \\end{align*}\n    so we know that there exists such a function\n\n    \\item Notice that when we took the square root, we could have had $\\pm$, so there it is not well defined which one we should take.\n    \\item If we try to solve for\n    \\begin{align*}\n      h(3) &= \\sqrt{\n        2 - 1\n      } = \\pm 1\\\\\n      h(4) &= \\sqrt{\n        \\pm 1 - 2\n      } \\implies \\text{square root of negative number...}\n    \\end{align*}\n    imaginary numbers? Never heard of them.\n  }\n}", "meta": {"hexsha": "23b09a99807aae71b1d47365d8a56ebe11b1630d", "size": 9283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1/chapter1-7.tex", "max_stars_repo_name": "mikinty/Topology-Munkres-Solutions", "max_stars_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T04:11:03.000Z", "max_issues_repo_path": "chapters/chapter1/chapter1-7.tex", "max_issues_repo_name": "mikinty/Topology-Munkres-Solutions", "max_issues_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1/chapter1-7.tex", "max_forks_repo_name": "mikinty/Topology-Munkres-Solutions", "max_forks_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3881278539, "max_line_length": 200, "alphanum_fraction": 0.6366476355, "num_tokens": 3053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.757794360334681, "lm_q2_score": 0.8633916011860785, "lm_q1q2_score": 0.6542732861391403}}
{"text": "%% LyX 2.0.6 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[letterpaper,english]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage[latin9]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{esint}\n\n\\makeatletter\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.\n\\pdfpageheight\\paperheight\n\\pdfpagewidth\\paperwidth\n\n\n\\makeatother\n\n\\usepackage{babel}\n\\begin{document}\nJon Allen\n\nHomework 4\n\nSeptember 25\n\n\n\\section*{2.5}\n\n\n\\subsection*{29}\n\nSolve $(t^{2}-y^{2})\\mathrm{d}y+(y^{2}+ty)\\mathrm{d}t=0$.\n\n$(x^{2}t^{2}-x^{2}y^{2})=x^{2}(t^{2}-y^{2})=(x^{2}y^{2}+xtxy)$\n\nThe equation is homogeneous so we substitute $t=vy$\n\n\\begin{align*}\n(v^{2}y^{2}-y^{2})\\,\\mathrm{d}y+(y^{2}+vy^{2})(y\\,\\mathrm{d}v+v\\,\\mathrm{d}y) & =0\\\\\n(v^{2}y^{2}-y^{2})\\,\\mathrm{d}y+y^{2}y\\,\\mathrm{d}v+vy^{2}y\\,\\mathrm{d}v+y^{2}v\\,\\mathrm{d}y+vy^{2}v\\,\\mathrm{d}y & =0\\\\\n(v^{2}y^{2}-y^{2}+y^{2}v+v^{2}y^{2})\\,\\mathrm{d}y+(y^{3}+vy^{3})\\,\\mathrm{d}v & =0\\\\\ny^{2}(v^{2}-1+v+v^{2})\\,\\mathrm{d}y+y^{3}(1+v)\\,\\mathrm{d}v & =0\\\\\ny^{2}(2v^{2}+v-1)\\,\\mathrm{d}y+y^{3}(1+v)\\,\\mathrm{d}v & =0\\\\\ny^{2}(2v^{2}+v-1)\\,\\mathrm{d}y & =-y^{3}(1+v)\\,\\mathrm{d}v\\\\\n\\frac{1}{y}\\,\\mathrm{d}y & =-\\frac{1+v}{2v^{2}+v-1}\\,\\mathrm{d}v\\\\\n\\frac{1}{y}\\,\\mathrm{d}y & =-\\frac{1+v}{(v+1)(2v-1)}\\,\\mathrm{d}v\\\\\n\\frac{1}{y}\\,\\mathrm{d}y & =-\\frac{1}{2v-1}\\,\\mathrm{d}v & u=2v-1\\\\\n\\int\\frac{1}{y}\\,\\mathrm{d}y & =-\\frac{1}{2}\\int\\frac{1}{u}\\,\\mathrm{d}u & \\mathrm{d}u=2\\mathrm{d}v\\\\\n\\ln y & =\\ln\\frac{1}{\\sqrt{2v-1}}+C_{0}\\\\\ny & =e^{C_{0}}\\frac{1}{\\sqrt{2v-1}} & e^{C_{0}}=C\\\\\ny & =C\\frac{1}{\\sqrt{2\\frac{t}{y}-1}}\n\\end{align*}\n\n\n\n\\subsection*{36}\n\nSolve $(t+y)\\,\\mathrm{d}t-t\\,\\mathrm{d}y=0,y(1)=1$\n\\begin{align*}\n(tx+yx)-tx & =xM(x,y)+xN(x,y)\n\\end{align*}\nThe equation is homogeneous and $N(x,y)$is simpler so set $y=wt$and\n$\\mathrm{d}y=t\\mathrm{\\, d}w+w\\,\\mathrm{d}t$\n\\begin{align*}\n(t+wt)\\,\\mathrm{d}t-t(t\\mathrm{\\, d}w+w\\,\\mathrm{d}t) & =0\\\\\nt\\,\\mathrm{d}t-t^{2}\\,\\mathrm{d}w & =0\\\\\n\\frac{1}{t}\\,\\mathrm{d}t & =\\mathrm{d}w\\\\\n\\int\\frac{1}{t}\\,\\mathrm{d}t & =\\int\\mathrm{d}w\\\\\n\\ln t & =\\frac{y}{t}+C_{0} & C=-C_{0}\\\\\ny & =t(\\ln t+C)\\\\\n1 & =1(0+C)=C\\\\\ny & =t\\ln t+t\n\\end{align*}\n\n\n\n\\section*{2.6}\n\nDo only the case for h=0.1\n\n\n\\subsection*{2}\n\nApproximate the solution to the IVP $y'=4x-y+1,y(0)=0$at $x=1$for\n$h=0.1$\n\\begin{align*}\ny_{0} & =0\\\\\ny_{1} & =0.1*(4*0-0+1)+0=0.1\\\\\ny_{2} & =0.1*(4*0.1-0.1+1)+0.1=0.23\\\\\ny_{3} & =0.1*(4*0.2-0.23+1)+0.23=0.387\\\\\ny_{4} & =0.1*(4*0.3-0.387+1)+0.387=0.5683\\\\\ny_{5} & =0.1*(4*0.4-0.5683+1)+0.5683=0.77147\\\\\ny_{6} & =0.1*(4*0.5-0.77147+1)+0.77147=.9943230000000001\\\\\ny_{7} & =0.1*(4*0.6-.994323+1)+.994323=1.2348907\\\\\ny_{8} & =0.1*(4*0.7-1.2348907+1)+1.2348907=1.49140163\\\\\ny_{9} & =0.1*(4*0.8-1.49140163+1)+1.49140163=1.762261467\\\\\ny_{10} & =0.1*(4*0.9-1.762261467+1)+1.762261467=2.0460353203\\\\\ny(1) & \\approx2.0460353203\n\\end{align*}\n\n\n\n\\subsection*{3}\n\nApproximate the solution to the IVP $y'-x=y^{2}-1,y(0)=1$at $x=1$for\n$h=0.1$\n\\begin{align*}\ny_{0} & =1\\\\\ny_{1} & =0.1*(y_{0}^{2}-1+0)+y_{0}=1\\\\\ny_{2} & =0.1*(y_{1}^{2}-1+0.1)+y_{1}=1.01\\\\\ny_{3} & =0.1*(y_{2}^{2}-1+0.2)+y_{2}=1.03201\\\\\ny_{4} & =0.1*(y_{3}^{2}-1+0.3)+y_{3}=1.06851446401\\\\\ny_{5} & =0.1*(y_{4}^{2}-1+0.4)+y_{4}=1.122686779989858\\\\\ny_{6} & =0.1*(y_{5}^{2}-1+0.5)+y_{5}=1.198729340586257\\\\\ny_{7} & =0.1*(y_{6}^{2}-1+0.6)+y_{6}=1.302424543784494\\\\\ny_{8} & =0.1*(y_{7}^{2}-1+0.7)+y_{7}=1.442055513009718\\\\\ny_{9} & =0.1*(y_{8}^{2}-1+0.8)+y_{8}=1.630007923269891\\\\\ny_{10} & =0.1*(y_{9}^{2}-1+0.9)+y_{9}=1.885700506262153\\\\\ny(1) & \\approx1.885700506262153\n\\end{align*}\n\n\n\n\\section*{3.1}\n\n\n\\subsection*{5}\n\nSuppose that the half-life of an element is 1000 h. If there are initially\n100 g, how much remains after 1 h? How much remains after 500 h?\n\\begin{align*}\ny(0) & =100\\\\\ny(1000) & =50\\\\\ny(t) & =100e^{kt}\\\\\n50 & =100e^{1000m}\\\\\n\\left(\\frac{5}{10}\\right)^{1/1000} & =e^{m}\\\\\n\\frac{\\ln\\frac{1}{2}}{1000} & =m\\\\\ny(1) & =100e^{m}=99.93070929904525\\mathrm{g}\\\\\ny(500) & =100e^{500m}=70.71067811865476\\mathrm{g}\n\\end{align*}\n\n\n\n\\subsection*{6}\n\nSuppose that the population of a small town is initially 5000. Due\nto the construction of an interstate highway, the population doubles\nover the next year. If the rate of growth is proportional to the current\npopulation, when will the population reach 25,000? What is the population\nafter 5 years?\n\\begin{align*}\ny(0) & =5000\\\\\ny(1) & =10000\\\\\ny(t) & =y_{0}e^{mt}\\\\\n10000 & =5000e^{m}\\\\\n\\ln2 & =m\\\\\n25000 & =5000e^{t\\ln2}\\\\\n\\ln5 & =t\\ln2\\\\\nt & =\\frac{\\ln5}{\\ln2}\\approx2.3\\mathrm{years}\\\\\ny(5) & =5000e^{5\\ln2}=5000*2^{5}=160000\\mathrm{people}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "6d5207b168974b423f93762a0fed2a690573632c", "size": 4638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential equations/homework 4.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/homework 4.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/homework 4.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": 28.2804878049, "max_line_length": 120, "alphanum_fraction": 0.5774040535, "num_tokens": 2360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.6541814473824126}}
{"text": "\\section{Planar Approximation}\nIt is time to deal with the pole situation. The north and south poles that is, not the lovely people over in Poland. We run into problems because the latitude longitude grid cells become to small \nnear the poles. Therefore, the magnitudes no longer fit into one cell and overflow into other cells which makes everything kind of funky. So we need to fix that, and we do that by a planar \napproximation. \n\n\\subsection{The Initial Theory}\nAs said earlier, the grid cells on the latitude longitude grid get closer together the closer you get to the poles which poses problems. To fix this, we will be using a planar approximation of \nthe poles. What this means is that we will map the 3D grid near the poles onto a 2D plane parallel to the poles, as if we put a giant flat plane in the exact center of the poles and draw lines\nfrom the grid directly upwards to the plane. For a visual representation, please consult the stream with timestamp 1:38:25 \\cite{polarPlane}, which includes some explanation. In the streamm we\nuse $r$ to indicate the radius of the planet (which we assume is a sphere), $\\theta$ for the longitude and $\\lambda$ for the latitude. So we have spherical coordinates, which we need to transform\ninto $x$ and $y$ coordinates on the plane. We also need the distance between the center point (the point where the plane touches the planet which is the center of the pole) and the projected \npoint on the plane from the grid (the location on the plane where a line from the gird upwards to the plane hits it). This distance is denoted by $a$ (Simon chose this one, not me). We then get \nthe following equations as shown in \\autoref{eq:polar distance}, \\autoref{eq:polar x} and \\autoref{eq:polar y}. \n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:polar distance}\n        a = r \\cos(\\theta)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar x}\n        x = a \\sin(\\lambda)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar y}\n        y = a \\cos(\\lambda)\n    \\end{equation}\n\\end{subequations}\n\nBut what if we know $x$ and $y$ and want to know $\\theta$ and $\\lambda$? Pythagoras' Theorem then comes into play \\cite{pythagoras}. We know that (due to Pythagoras) \\autoref{eq:pythagoras} must \nalways be true. Then if we substitue $a$ by $\\sqrt{x^2 + y^2}$ in \\autoref{eq:polar distance} we get \\autoref{eq:polar theta1}. Then we transform that equation such that we only have $\\theta$ on \none side and the rest on the other side (since we want to know $\\theta$) and we get \\autoref{eq:polar theta3}.\n\\begin{equation}\n    \\label{eq:pythagoras}\n    x^2 + y^2 = a^2\n\\end{equation}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:polar theta1}\n        \\sqrt{x^2 + y^2} = r\\cos(\\theta)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar theta2}\n        \\frac{\\sqrt{x^2 + y^2}}{r} = \\cos(\\theta)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar theta3}\n        \\arccos(\\frac{\\sqrt{x^2 + y^2}}{r}) = \\theta\n    \\end{equation}\n\\end{subequations}\n\nFor $\\lambda$ we need another trigonometric function which is the tangent ($\\tan$). The tangent is defined in \\autoref{eq:tan}. If we then take a look at \\autoref{eq:polar x} and \n\\autoref{eq:polar y}, we see that $\\lambda$ is present in both equations. So we need to use both to get $\\lambda$ \\footnote{Yes you could only use one but since we both know $x$ and $y$ it is a\nbit easier to use both than to only use one as you need to know $\\theta$ at that point as well which may or may not be the case.}. So let's combine \\autoref{eq:polar x} and \\autoref{eq:polar y}\nin \\autoref{eq:polar lambda1}, transform it such that we end up with only $\\lambda$ on one side and the rest on the other side and we end up with \\autoref{eq:polar lambda3}.\n\n\\begin{equation}\n    \\label{eq:tan}\n    \\tan(\\alpha) = \\frac{\\sin(\\alpha)}{\\cos(\\alpha)}\n\\end{equation}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:polar lambda1}\n        \\frac{x}{y} = \\frac{a\\sin(\\lambda)}{a\\cos(\\lambda)} = \\frac{\\sin(\\lambda)}{\\cos(\\lambda)}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar lambda2}\n        \\frac{x}{y} = \\tan(\\lambda)\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:polar lambda3}\n        \\lambda = \\arctan(\\frac{x}{y})\n    \\end{equation}\n\\end{subequations}\n\n\\subsection{The Grid Code}\nTo start the planar approximation, we first need to create a grid. One for the north pole, and one for the south pole. Now since the project is made in Python, Simon uses a function to generate \na grid from two coordinate vectors (lists with a coordinate as elements). Since the documentation is not language specific I instead opt to use words instead of function calls. What that comes \ndown to is use your favourite language and import the libraries that do this for you, or start coding your own after finding out how to do that (your mileage may vary). To implement the grid \nfunction in the exact same way as the numpy packages does, please refer to the following two references \\cite{meshgridDoc} \\cite{meshgridGFG}. Anyway, the code for the grid can be found in \n\\autoref{alg:polar grid south}. To convert $x, y$ coordinates into $lat, lon$ coordinates, we make use of \\autoref{eq:polar theta3} and \\autoref{eq:polar lambda3}. Keep in mind that the equations \nthemselves assume that the angles are in radians, whereas the model uses the angles in degrees so they need to be converted. To convert from $lat, lon$ back into $x, y$ we need to combine \n\\autoref{eq:polar distance}, \\autoref{eq:polar x} and \\autoref{eq:polar y}.\n\n\\begin{algorithm}[htb]\n    \\caption{Generating the grid for polar approximation of the south pole}\n    \\label{alg:polar grid south}\n    \\SetKwComment{Comment}{//}{}\n    $poleLowIndexS \\leftarrow $ find first index where $lat > poleLowerLatLimit$ \\;\n    $poleHighIndexS \\leftarrow $ find first index where $lat > poleHigherLatLimit$ \\;\n    $polarGridResolution \\leftarrow dx[-poleLowIndexS] $ \\Comment*[l]{Will be reused for the north pole}\n    $gridSize \\leftarrow r \\cos(lat[-poleLowIndexS] \\frac{\\pi}{180})$ \\Comment*[l]{Will be reused for the north pole}\n    \\BlankLine\n\n    $gridXAxisS \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridYAxisS \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridXValuesS, gridYValuesS \\leftarrow $ generate the grid from the two axis vectors $gridXAxissS$ and $gridYAxissS$ \\;\n    $gridSideLength \\leftarrow gridXValuesS.length $ \\Comment*[l]{Is globally available\\dots}\n    \\BlankLine \n\n    $gridLatCoordsS \\leftarrow $ empty list \\;\n    $gridLonCoordsS \\leftarrow $ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $gridXValuesS.length$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $gridXValuesS[i].length$}{\n            $x \\leftarrow gridXValuesS[i, j]$ \\;\n            $y \\leftarrow gridYValuesS[i, j]$ \\;\n            $latPoint \\leftarrow -\\arccos(\\frac{\\sqrt{x^2 + y^2}}{r})\\frac{180}{\\pi}$ \\;\n            $lonPoint \\leftarrow 180 - \\arctan(\\frac{x}{y})\\frac{180}{\\pi}$ \\;\n            $gridLatCoordsS.append(latPoint)$ \\;\n            $gridLonCoordsS.append(lonPoint)$ \\;\n        }\n    }\n\n    \\BlankLine\n    $polarXCoordsS \\leftarrow$ empty list \\;\n    $polarYCoordsS \\leftarrow$ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndexS$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $nlon$}{\n            $polarXCoordsS.append(r \\cos(lat[i] \\frac{\\pi}{180}) \\sin(lon[j]\\frac{\\pi}{180}))$ \\;\n            $polarYCoordsS.append(-r \\cos(lat[i] \\frac{\\pi}{180}) \\cos(lon[j]\\frac{\\pi}{180}))$ \\;\n        }\n    }\n\\end{algorithm}\n\nWe need to do a similar thing for the north pole and insert a few changes to some of the equations to correct for different angles and similar things. The code can be found in \n\\autoref{alg:polar grid north}. Again, see the references at the south pole explanation on how to generate the grid itself.\n\n\\begin{algorithm}[htb]\n    \\caption{Generating the grid for polar approximation of the north pole}\n    \\label{alg:polar grid north}\n    \\SetKwComment{Comment}{//}{}\n    $poleLowIndexN \\leftarrow $ find last index where $lat < -poleLowerLatLimit$ \\;\n    $poleHighIndexN \\leftarrow $ find last index where $lat < -poleHigherLatLimit$ \\;\n    \\BlankLine\n\n    $gridXAxisN \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridYAxisN \\leftarrow $ array going from $-gridSize$ to $gridSize$ with steps of $polarGridResolution$ \\;\n    $gridXValuesN, gridYValuesN \\leftarrow $ generate the grid from the two axis vectors $gridXAxisN$ and $gridYAxisN$ \\;\n    \\BlankLine \n    \n    $gridLatCoordsN \\leftarrow $ empty list \\;\n    $gridLonCoordsN \\leftarrow $ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $gridXValuesN.length$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $gridXValuesN[i].length$}{\n            $x \\leftarrow gridXValuesN[i, j]$ \\;\n            $y \\leftarrow gridYValuesN[i, j]$ \\;\n            $latPoint \\leftarrow -\\arccos(\\frac{\\sqrt{x^2 + y^2}}{r})\\frac{180}{\\pi}$ \\;\n            $lonPoint \\leftarrow 180 - \\arctan(\\frac{x}{y})\\frac{180}{\\pi}$ \\;\n            $gridLatCoordsN.append(latPoint)$ \\;\n            $gridLonCoordsN.append(lonPoint)$ \\;\n        }\n    }\n\n    \\BlankLine\n    $polarXCoordsN \\leftarrow$ empty list \\;\n    $polarYCoordsN \\leftarrow$ empty list \\;\n    \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndexN$}{\n        \\For{$j \\leftarrow 0$ \\KwTo $nlon$}{\n            $polarXCoordsN.append(r \\cos(lat[i] \\frac{\\pi}{180}) \\sin(lon[j]\\frac{\\pi}{180}))$ \\;\n            $polarYCoordsN.append(-r \\cos(lat[i] \\frac{\\pi}{180}) \\cos(lon[j]\\frac{\\pi}{180}))$ \\;\n        }\n    }\n\\end{algorithm}\n\nIn both algorithms it is important to make a distinction between $gridLatCoords$ and $polarXCoords$ and their respective variants. $gridLatCoords$ are the latitudinal coordinates on the \n$lat, lon$ grid corresponding to the $x$ and $y$ coordinates on the polar grid. Whereas $polarXCoords$ are the $x$ coordinates on the polar grid corresponding to the latitude and longitude on \nthe $lat, lon$ grid. Those are different to the $gridXValues$ as they represent the values on the $x$ axis as integers which may or may not directly correspond to the $polarXCoords$. So we need \na way of mapping the $polarXCoords$ to $gridXValues$ and their respective values and vice versa. This is done in the next section.\n\n\\subsection{Switching between grids}\nNow that we have defined the polar plane grid, we need code to convert the values from the $lat, lon$ grid to the polar plane grid and vice versa. Let's start with converting to the polar grid. \nWe need 2 versions of the algorithm for that. One that converts in 2 dimensions, and one that converts in 3 dimensions. The code for the 2 dimensional case is shown in \\autoref{alg:beam up 2d}.\nHere we use bivariate spline interpolation \\cite{bivariatespline} which is a different form of linear interpolation than discussed in \\autoref{sec:interpolation} though the same principle \napplies.\n\n\\begin{algorithm}[htb]\n    \\caption{Converting from $lat, lon$ grid to polar plane grid in 2 dimensions}\n    \\label{alg:beam up 2d}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Latitude coordinates $lat$, Longitude coordinates $lon$, Values of the $lat, lon$ grid $data$, Length of one axis of the polar grid? $gridSize$, Latitude coordinates on the polar grid \n        $gridLatCoords$, Longitude coordinates on the polar grid $gridLonCoords$}\n    \\Output{Double array representing the values of the $lat, lon$ grid on the polar grid}\n    \\SetKwComment{Comment}{//}{}\n    $f \\leftarrow $ \\texttt{BivariateSpline}($lat, lon, data$) \\Comment*[l]{Do the interpolation}\n    $polarPlane \\leftarrow f(gridLatCoords, gridLonCoords).$\\texttt{reshape}(($gridSize$, $gridSize$)) \\Comment*[l]{Check the values of the interpolation at the specified coordinates and force \n    them to align to the polar grid}\n    \\Return{$polarPlane$}\n\\end{algorithm}\n\nThe 3 dimensional algorithm is quite similar to the 2 dimensional algorithm, which can be found in \\autoref{alg:beam up 3d}\n\n\\begin{algorithm}[htb]\n    \\caption{Converting from $lat, lon$ grid to polar plane grid in 3 dimensions}\n    \\label{alg:beam up 3d}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Latitude coordinates $lat$, Longitude coordinates $lon$, Values of the $lat, lon$ grid $data$, Length of one axis of the polar grid? $gridSize$, Latitude coordinates on the polar grid \n        $gridLatCoords$, Longitude coordinates on the polar grid $gridLonCoords$}\n    \\Output{Triple array representing the values of the $lat, lon, layer$ grid on the polar grid}\n    \\SetKwComment{Comment}{//}{}\n    $polarPlane \\leftarrow $ 3 Dimensional array where the $1^{\\text{st}}$ and $2^{\\text{nd}}$ dimensions have length $gridSize$ and the $3^{\\text{rd}}$ dimension has length $data[0][0].length$ \\;\n    \\For{$k \\leftarrow 0$ \\KwTo $data[0][0].length$}{\n        $f \\leftarrow $ \\texttt{BivariateSpline}($lat, lon, data[:, :, k]$) \\Comment*[l]{Do the interpolation on this layer}\n        $polarPlane[:, :, k] \\leftarrow f(gridLatCoords, gridLonCoords).$\\texttt{reshape}(($gridSize$, $gridSize$)) \\Comment*[l]{Check the values of the interpolation at the specified \n        coordinates and force them to align to the polar grid}\n    }\n    \\Return{$polarPlane$}\n\\end{algorithm}\n\nHaving dealt with converting to the polar grid, we now also need to deal with converting from the polar grid. In contrast to converting to the polar griod, this is only done in 3 dimensions so \nwe do not need a 2 dimensional algorithm. How we convert from the polar grid can be found in \\autoref{alg:beam down}.\n\n\\begin{algorithm}[htb]\n    \\caption{Converting from the polar plane grid to the $lat, lon$ grid in 3 dimensions}\n    \\label{alg:beam down}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Longitude coordinates $lon$, Values of the $lat, lon$ grid $data$, Polar $x$ value indices $gridXValues$, Polar $y$ value indices $gridYValues$, Polar $x$ coordinates $polarXCoords$, \n        Polar $y$ coordinates $polarYCoords$}\n    \\Output{Triple array representing the values of the polar grid on the $lat, lon, layer$ grid}\n    \\SetKwComment{Comment}{//}{}\n    $resample \\leftarrow $3 Dimensional array where the $1^{\\text{st}}$ dimension has length $\\lfloor \\frac{polarXCoords}{lon.length} \\rfloor$, the $2^{\\text{nd}}$ dimension has length \n    $lon.length$ and the $3^{\\text{rd}}$ dimension has length $data[0][0].length$ \\;\n    \\For{$k \\leftarrow 0$ \\KwTo $data[0][0].length$}{\n        $f \\leftarrow $ \\texttt{BivariateSpline})($gridXValues, gridYValues, data[:, :, k]$) \\Comment*[l]{Do the interpolation on this layer}\n        $resample[:, :, k] \\leftarrow f(polarXCoords, polarYCoords).$\\texttt{reshape}(($\\lfloor \\frac{polarXCoords}{lon.length} \\rfloor, lon.length$)) \\Comment*[l]{Check the values of the \n        interpolation at the specified coordinates and force them to align to the polar grid}\n    }\n    \\Return{$resample$}\n\\end{algorithm}\n\n\\subsection{Gradually changing grids}\nNow that we can convert between grids we also need a way to do so gradually. Otherwise we would move the hard border we had previously around the poles further down the $lat, lon$ grid. Instead \nwe have to do some interpolation between the two grids in order to ensure a smooth transition in the final output, so that there are no hard borders. This interpolation is done in , using the \nlinear interpolation technique as discussed in \\autoref{sec:interpolation}.\n\n\\begin{algorithm}[htb]\n    \\caption{Gradually transition from the $lat, lon$ grid to the polar grid}\n    \\label{alg:polar interpolation}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Index when to start using the polar grid $poleLowIndex$, Index when to only use the polar grid $poleHighIndex$, Polar data $polarData$, $lat, lon$ data $sphericalData$}\n    \\Output{3 Dimensional array representing the values on the polar grid with the part that gradually transitions to the $lat, lon$ grid}\n    \\SetKwComment{Comment}{//}{}\n    $output \\leftarrow$ 3 Dimensional array with the exact same structure as $polarData$ \\;\n    $overlap \\leftarrow $ $|poleLowIndex - poleHighIndex|$ \\;\n    \n    \\BlankLine\n    \\uIf(\\Comment*[h]{Determine whether we are talking about the north or south pole}){$lat[poleLowIndex] < 0$}{\n        \\DontPrintSemicolon\n        \\Comment*[l]{South pole}\n        \\PrintSemicolon\n        \\For{$k \\leftarrow 0$ \\KwTo $output[0][0].length$}{\n            \\For{$i \\leftarrow 0$ \\KwTo $poleLowIndex$}{\n                \\uIf{$i < poleHighIndex$}{\n                    $\\lambda \\leftarrow 0$ \\;\n                } \\uElse{\n                    $\\lambda \\leftarrow \\frac{i - poleHighIndex}{overlap}$ \\;\n                }\n                $output[i, :, k] \\leftarrow (1 - \\lambda) sphericalData[i, :, k] + \\lambda polarData[i, :, k]$ \\;\n            }\n        }\n    } \\uElse{\n        \\DontPrintSemicolon\n        \\Comment*[l]{North pole}\n        \\PrintSemicolon\n        \\For{$k \\leftarrow 0$ \\KwTo $output[0][0].length$}{\n            \\For{$i \\leftarrow 0$ \\KwTo $nlat - poleLowIndex$}{\n                \\uIf{$i + poleLowIndex + 1 > poleHighIndex$}{\n                    $\\lambda \\leftarrow 0$ \\;\n                } \\uElse{\n                    $\\lambda \\leftarrow \\frac{i}{overlap}$ \\;\n                }\n                $output[i, :, k] \\leftarrow (1 - \\lambda) sphericalData[i, :, k] + \\lambda polarData[i, :, k]$ \\;\n            }\n        }\n    }\n\n    \\BlankLine\n    \\Return{$output$}\n\\end{algorithm}\n\n\\subsection{Gradients on the grid}\nWith our new found ability to convert to and from the polar grid, while also gradually transitioning, we now get to the part we are doing it all for. Calculations on the polar grid. In order for\nthat to work, we need some utility functions specifically for the polar grid first. We will need gradients in all 3 dimensions, those being the $x$ dimension, the $y$ dimension and the $p$ \ndimension (pressure). All of the gradients will be quite similar to \\autoref{alg:gradient x}, \\autoref{alg:gradient y} and \\autoref{alg:gradient z} though some small tweaks are required as we \nare not differentiating over a spehere but over a plane. These changes are reflected in \\autoref{alg:polar gradient x}, <Y> and <Z>.\n\n\\begin{algorithm}\n    \\caption{Gradient in the $x$ dimension on the polar grid}\n    \\label{alg:polar gradient x}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{Triple array of data $data$, first index $i$, second index $j$ and third index $k$}\n    \\Output{Gradient in the $x$ dimension for the value of the grid point at the specified coordinates}\n    \\uIf{$p = 0$}{\n        $value \\leftarrow \\frac{data[i, j + 1, k] - data[i, j, k]}{polarGridResolution}$ \\;\n    } \\uElseIf{$y = gridSideLength - 1$}{\n        $value \\leftarrow \\frac{data[i, j, k] - data[i, j - 1, k]}{polarGridResolution}$ \\;\n    } \\uElse{\n        $vale \\leftarrow \\frac{data[i, j + 1, k] - data[i, j - 1, k]}{2 polarGridResolution}$ \\; \n    }\n    \\Return{$value$}\n\\end{algorithm}", "meta": {"hexsha": "a4f8557bbed813edddacbd2d92fd34934349b039", "size": 19130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/topics/planar.tex", "max_stars_repo_name": "WardPearce/claude", "max_stars_repo_head_hexsha": "96f2d6af19c1f5a61148c00df559fb39d272a717", "max_stars_repo_licenses": ["MIT"], "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/topics/planar.tex", "max_issues_repo_name": "WardPearce/claude", "max_issues_repo_head_hexsha": "96f2d6af19c1f5a61148c00df559fb39d272a717", "max_issues_repo_licenses": ["MIT"], "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/topics/planar.tex", "max_forks_repo_name": "WardPearce/claude", "max_forks_repo_head_hexsha": "96f2d6af19c1f5a61148c00df559fb39d272a717", "max_forks_repo_licenses": ["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.3127035831, "max_line_length": 196, "alphanum_fraction": 0.6860951385, "num_tokens": 5481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.6541814432169832}}
{"text": "\\section{Results and Discussion}\n\nWe present results with different types of flow field data sets to evaluate our approach, including synthetic data and spatially aggregated data sets. To demonstrate the effectiveness of the proposed algorithm, we compared it with the Monte Carlo (MC) method, which is the general approach to stochastically trace particles in uncertain flow fields modeled in probability distributions. We performed quantitative comparisons on the resulting streamlines generated by our approach and the MC method with different settings and distance measurements. We also qualitatively compare the most likely streamlines as well as the distributions of possible traces produced by our approach and the MC method by visualizing sample traces on different data sets.\n\n\\subsection{Synthetic Data}\n\nWe first evaluate the proposed algorithm on the analytical static double-gyre data set proposed by Shadden et al. in~\\cite{Shadden2005271}. Gaussian noise is added into the vector field to synthesize the uncertainty. The uncertain flow can be described as the stream-function\n\\begin{equation}\n  \\psi(x,y) = A\\sin(\\pi x)\\sin(\\pi y) + N(0,{\\sigma ^2})\n\\end{equation}\nover the domain $[0,2]\\times[0,1]$. In order to quantitatively evaluate the robustness of the particle filtering algorithm under the influence of noise, we generate streamlines starting from regularly sampled seed positions for the certain double-gyre data set and use those streamlines as our ground truth. Then, a set of sample traces are generated by the MC method and the particle filtering method starting from the same seed position presented above for the uncertain double-gyre data set with different noise level, which is controlled by the standard deviation $\\sigma$ of the Gaussian noise. All the streamlines were generated with a step size of $0.005$ and a maximum step number of $100$. For the particle filtering method, a concentration parameter $\\kappa = 60$ and a resampling threshold $N_t = 4.0$ are used. For the Monte Carlo method and the proposed algorithm, a critical parameter is the number of particles used for each seed. Indeed, more particles will give a more accurate presentation of the target distribution but will take more time to generate the results. Hence, a particle count that balances the accuracy and the computation time need to be studied. Based on~\\cite{journals/mia/PontabryROSKD13}, we use $100$ particles for both of the methods in the experiments. To compare the accuracy of the resulting traces, two pairwise distance metrics between streamlines $L_i$ and $L_j$ were used:\n\n1. Hausdorff distance $d_H$~\\cite{Roessl:2012:TVCG}, which measures how far two streamlines are from each other:\n\\begin{equation}\n\\begin{split}\n  {d_H}({L_i},{L_j}) = max({d_h}({L_i},{L_j}),{d_h}({L_j},{L_i})) \\\\\n  \\text{with  } {d_h}({L_i},{L_j}) = ma{x_{{p_l} \\in {L_i}}}{\\min _{{p_k} \\in {L_j}}}\\left\\| {{p_k} - {p_l}} \\right\\|\n\\end{split}\n\\end{equation}\n\n2. Mean of the closest point distance $d_M$~\\cite{Corouge04towardsa}, which gives the average distance between two streamlines:\n\\begin{equation}\n\\begin{split}\n  {d_M}({L_i},{L_j}) = mean({d_m}({L_i},{L_j}),{d_m}({L_j},{L_i})) \\\\\n  \\text{with  } {d_m}({L_i},{L_j}) = mea{n_{{p_l} \\in {L_i}}}{\\min _{{p_k} \\in {L_j}}}\\left\\| {{p_k} - {p_l}} \\right\\|\n\\end{split}\n\\end{equation}\n\nFigure~\\ref{gerror} gives the average of the distances presented above between the most likely streamlines generated from each method and the ground truth, with increasing $\\sigma$ values for the noise in the vector field. The figure reveals that our method can produce most likely traces that are closer to the ground truth and the average of the distances increases more slowly than the MC method as the noise increases.\n\nBesides comparing the accuracy of the most likely traces, it is also important to compare the whole distribution of possible traces generated by each method. We evaluate the accuracy of uncertain streamlines starting from a given seed position by measuring the distance between each individual trace and the ground truth, then we compute the weighted sum of all the distances. For the MC method, all traces are equally weighted by $\\frac{1}{N_s}$. For the proposed method, the weights of the traces described above are used. Figure~\\ref{gerror_r} shows that the proposed method can generate more accurate traces with less uncertainty.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/doublegyre_h.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/doublegyre_m.eps}\n    \\caption{}\n  \\end{subfigure}\n  \\caption{Comparison of the distance between the most likely traces and the ground truth using Hausdorff and mean of the closest point measurements for our method and the MC method.}\n  \\label{gerror}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/doublegyre_hr.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/doublegyre_mr.eps}\n    \\caption{}\n  \\end{subfigure}\n  \\caption{Comparison of overall trace accuracy. For each method, distances of all sample traces to the ground truth are measured and summed by their weights.}\n  \\label{gerror_r}\n\\end{figure}\n\nFigure~\\ref{case_1} shows sample traces generated by the MC method and the proposed method at a given seed location in the double-gyre flow field. As we can see in the figure, our method can generate more concentrated traces which are also closer to the ground truth compared with the MC method. The most likely trace generated by the proposed method is also closer to the ground truth, as shown in~\\ref{case_1_c}.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}[!htb]{0.25\\textwidth}\n    \\centering\n    \\includegraphics[height=0.8in]{../figures/double_gyre_mc35.eps}\n    \\caption{}\n    \\label{case_1_a}\n  \\end{subfigure}~\n  \\begin{subfigure}[!htb]{0.25\\textwidth}\n    \\centering\n    \\includegraphics[height=0.8in]{../figures/double_gyre_smc35.eps}\n    \\caption{}\n    \\label{case_1_b}\n  \\end{subfigure}\n\n  \\begin{subfigure}[!htb]{0.5\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/double_gyre_opt35.eps}\n    \\caption{}\n    \\label{case_1_c}\n  \\end{subfigure}\n  \\caption{(a): Sampled streamlines computed by the MC method starting from seeding position $x=0.3, y=0.5$ in the analytical double-gyre data set. (b): Sampled streamlines computed by our method from the same seeding position in (a). (c): The most likely traces generated by both methods compared with the ground truth.}\n  \\label{case_1}\n\\end{figure}\n\n\\subsection{Spatially aggregated Data Sets}\n\nIn this section, experiments were done on two real-world flow field data sets, including Hurricane Isabel and 2D Ocean. Hurricane Isabel is a data set with a resolution of $500 \\times 500 \\times 100$ that models a strong hurricane in the west Atlantic region in September 2003. The 2D Ocean data set is a flow data with a resolution of $574 \\times 289$ produced by a 2D computational fluid dynamics simulation. In order to test the performance of our algorithm on uncertain data which represented by non-gaussian distributions, we decompose the data into small cubic blocks and construct a histogram for each block. To compute a histogram from a set of vector directions, we consider the surface patches of a unit sphere as histogram bins. We make use of the recursive zonal equal area sphere partitioning algorithm~\\cite{leopardi2006} to partition the unit sphere into patches of equal area and use them as our histograms bins. Partition results for different number of patches on the $2$-dimensional unit sphere are shown in Figure~\\ref{rzeasp}. In the experiments, we partition the sphere into $2048$ patches to make an accurate histogram. As Carr et at. presented in~\\cite{Carr:2006:HIS:1187627.1187777}, histograms can be poor representations of data since they represent the distribution using the nearest neighbor interpolation. To address this issue, we densely sample the data in each local block to make the histogram converge to the true local distribution. For the test data sets, distribution-based data are generated with three different block size $8^3$, $16^3$, and $32^3$ to evaluate the performance of the proposed algorithm under the influence of uncertainty.\n\nSince the data are represented as block-wise histograms, how to interpolate between neighboring blocks to generate a more accurate probability distribution becomes a challenging question. Developing efficient and accurate interpolation technique from probability density functions is still an active area for research. A variety of techniques~\\cite{10.1109/TVCG.2013.208, 10.1109/TVCG.2012.249} have been proposed to perform linear interpolation on different types of distributions. However, they are only focused on either uniform or parametric distributions. Furthermore, these techniques can only work on point based data sets. They may give incorrect value ranges for block-based data sets used in the experiments. Here, we perform the interpolation by aggregating the contributions of neighboring histograms to the distribution of interest based on the method presented by Clemen et al. in~\\cite{aggregation99}\n\\begin{equation}\n  {h(\\theta)} = k\\prod\\limits_{i = 1}^n {h{{_i}(\\theta)}^{{\\alpha _i}}}\n\\end{equation}\nwhere $k$ is a normalizing constant and the weights ${{\\alpha _i}}$ represent the relative quality of the different histograms. Typically, the weights are restricted to sum to one. The contribution of each histogram is estimated by applying convolution operations on it with a von Mises-Fisher kernel, where the number of the convolution operations is determined based on the distance between the neighboring block and target position.\n\n\\begin{figure}[htb!f]\n  \\centering\n  \\begin{subfigure}[b]{0.16\\textwidth}\n    \\centering\n    \\includegraphics[width=0.8in]{../figures/rzeasp_16.eps}\n    \\caption{16 patches}\n  \\end{subfigure}~\n  \\begin{subfigure}[b]{0.16\\textwidth}\n    \\centering\n    \\includegraphics[width=0.8in]{../figures/rzeasp_64.eps}\n    \\caption{64 patches}\n  \\end{subfigure}~\n  \\begin{subfigure}[b]{0.16\\textwidth}\n    \\centering\n    \\includegraphics[width=0.8in]{../figures/rzeasp_256.eps}\n    \\caption{256 patches}\n  \\end{subfigure}\n  \\caption{Recursive zonal equal area sphere partitioning with different number of patches.}\n  \\label{rzeasp}\n\\end{figure}\n\nAs presented above, we regularly sample a set of seed locations and compute the streamlines for both the raw data and the spatially down sampled data. The sample seed positions and the number of samples for the two test data sets are given in Table~\\ref{seed_position}. To perform the quantitative analysis, we treat the streamlines computed from the raw data as the ground truth and compute the distance between the stochastic particle traces with the ground truth. $100$ particles were used with a integration step size $1.0$ and a maximum step number of $1000$ for the streamline computation. For the particle filtering method, a concentration parameter $\\kappa = 60$ and a resampling threshold $N_t = 4.0$ are used. Figure~\\ref{berror_r} gives the mean of the distances' weighted sum between sample streamline bundles generated from the test methods and the ground truth on different data sets with different block sizes. The figure reveals that the proposed method can produce traces that are closer to the ground truth.\n\n\\begin{table}[ht!b]\n\\centering\n\\begin{tabular}{|l|l|l|}\n\\hline\nData Set & Number of Seeds                 & Interval of Seed Positions  \\\\ \\hline\nIsabel   & $12 \\times 12 \\times 9$ (1296)  & $40 \\times 40 \\times 10$    \\\\ \\hline\nOcean    & $28 \\times 14$ (392)            & $20 \\times 20$              \\\\ \\hline\n\\end{tabular}\n\\caption{Sample seed positions for the two test data sets.}\n\\label{seed_position}\n\\end{table}\n\n% \\begin{figure}[!htb]\n%   \\centering\n%   \\begin{subfigure}[b]{0.24\\textwidth}\n%     \\centering\n%     \\includegraphics[height=0.9in]{../figures/doublegyre_h.eps}\n%     \\caption{}\n%   \\end{subfigure}~\n%   \\begin{subfigure}[b]{0.24\\textwidth}\n%     \\centering\n%     \\includegraphics[height=0.9in]{../figures/doublegyre_m.eps}\n%     \\caption{}\n%   \\end{subfigure}\n\n%   \\begin{subfigure}[b]{0.24\\textwidth}\n%     \\centering\n%     \\includegraphics[height=0.9in]{../figures/doublegyre_h.eps}\n%     \\caption{}\n%   \\end{subfigure}~\n%   \\begin{subfigure}[b]{0.24\\textwidth}\n%     \\centering\n%     \\includegraphics[height=0.9in]{../figures/doublegyre_m.eps}\n%     \\caption{}\n%   \\end{subfigure}\n%   \\caption{Hausdorff and mean of the closest point distances between the ground truth and most likely traces generated by our method and the MC method for the two spacial down-sampled data sets.}\n%   \\label{berror}\n% \\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/ocean_h.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/isabel_h.eps}\n    \\caption{}\n  \\end{subfigure}\n\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/ocean_m.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[b]{0.24\\textwidth}\n    \\centering\n    \\includegraphics[height=1.0in]{../figures/isabel_m.eps}\n    \\caption{}\n  \\end{subfigure}\n  \\caption{Hausdorff and mean of the closest point distances between the ground truth and sample traces generated by our method and the MC method for the two spatially aggregated data sets.}\n  \\label{berror_r}\n\\end{figure}\n\nFigure~\\ref{data_overview} shows the streamlines generated from the two test data sets on the seed positions presented above. In Figure~\\ref{data_overview} (a) and (d), the ground truth streamlines are generated from the raw data. The most likely streamlines generated by the MC method on the distribution-based data set with block size $16^3$ are given in Figure~\\ref{data_overview} (b) and (e); as expected, streamlines generated by the MC method are generally not as smooth as the ground truth and some flow features looks quiet different compare with the ground truth. Figure~\\ref{data_overview} (c) and (f) show the streamlines produced by our method with the same block size, which give more accurate and smoother results. In addition to the most likely traces, the distribution approximated by the estimated sample traces is also important for understanding the distribution-based flow field. The visualization of the estimated streamline bundles on different flow field data sets are shown in Figure~\\ref{case_5} and~\\ref{case_4} to demonstrate the advantage of the proposed method. The resulting trajectories are generated with $1000$ particles for the Monte Carlo method and the particle filtering algorithm. By considering the correlation of vector directions in the spacial domain, our method is less sensitive to the local uncertainty, when MC traces can scatter to wrong directions, as show in ~\\ref{case_5}. Figure~\\ref{case_4} shows that our algorithm can produce more concentrated results than the basic MC method, because the correlation between consecutive integration steps (the prior information) are exploited.\n\n\\begin{figure*}[!htb]\n  \\centering\n  \\begin{subfigure}[!htb]{0.32\\textwidth}\n    \\centering\n    \\includegraphics[width=2.2in]{../figures/ocean_gt.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[!htb]{0.32\\textwidth}\n    \\centering\n    \\includegraphics[width=2.2in]{../figures/ocean_mc.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[!htb]{0.32\\textwidth}\n    \\centering\n    \\includegraphics[width=2.2in]{../figures/ocean_smc.eps}\n    \\caption{}\n  \\end{subfigure}\n\n  \\begin{subfigure}[!htb]{0.32\\textwidth}\n    \\centering\n    \\includegraphics[width=2.2in]{../figures/isabel_gt.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[!htb]{0.32\\textwidth}\n    \\centering\n    \\includegraphics[width=2.2in]{../figures/isabel_mc.eps}\n    \\caption{}\n  \\end{subfigure}~\n  \\begin{subfigure}[!htb]{0.32\\textwidth}\n    \\centering\n    \\includegraphics[width=2.2in]{../figures/isabel_smc.eps}\n    \\caption{}\n  \\end{subfigure}\n\n  \\caption{Streamlines generated on the 2D Ocean and the Hurricane Isabel data sets. The color is used to enhance the contrast among streamlines. (a) and (d): The ground truth streamlines generated on the raw data. (b) and (e): Results produced by the Monte Carlo method on the distribution data with block size $16^3$, introduce noisy patterns on the streamlines due to the local uncertainty and give inaccurate overview of the flow features. Our particle filter method gives more accurate overview results and smoother streamlines by exploiting the spatial coherence of the vector directions, shown in (c) and (f).}\n  \\label{data_overview}\n\\end{figure*}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}[!htb]{0.5\\textwidth}\n    \\centering\n    \\includegraphics[width=2.8in]{../figures/ocean_mc1.eps}\n    \\caption{}\n    \\label{case_5_a}\n  \\end{subfigure}\n\n  \\begin{subfigure}[!htb]{0.5\\textwidth}\n    \\centering\n    \\includegraphics[width=2.8in]{../figures/ocean_smc1.eps}\n    \\caption{}\n    \\label{case_5_b}\n  \\end{subfigure}\n  \\caption{(a): Sampled streamlines computed by the MC method starting from seeding position $x=280, y=140$ in the 2D Ocean data set. (b): Sampled streamlines computed by our method from the same seeding position in (a).}\n  \\label{case_5}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}[!htb]{0.25\\textwidth}\n    \\centering\n    \\includegraphics[height=1.4in]{../figures/isabel_mc1.eps}\n    \\caption{}\n    \\label{case_4_a}\n  \\end{subfigure}~\n  \\begin{subfigure}[!htb]{0.25\\textwidth}\n    \\centering\n    \\includegraphics[height=1.4in]{../figures/isabel_smc1.eps}\n    \\caption{}\n    \\label{case_4_b}\n  \\end{subfigure}\n  \\caption{(a): Sampled streamlines computed by the MC method starting from seeding position $x=250, y=150, z=45$ in the Isabel data set. (b): Sampled streamlines computed by our method from the same seeding position in (a).}\n  \\label{case_4}\n\\end{figure}\n\n\\subsection{Performance}\n\nAll the experiments were performed on a desktop computer with an Intel(R) Core(TM) i7-4790K CPU 4.0GHz processor, 16GB memory, and an NVIDIA GTX 970 GPU. In Table~\\ref{timing}, we compare the performance measurements between the particle filtering algorithm and the Monte Carlo method for streamlines estimated for a given seed position with $100$ sample points for all the test data sets used in this paper. In all the datasets, our approach is almost as fast as the Monte Carlo algorithm.\n\n\\begin{table}[!htb]\n\\centering\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\n\\multirow{2}{*}{Data Set}    & \\multirow{2}{*}{Method}     & \\multicolumn{3}{c|}{Timing(sec)}  \\\\ \\cline{3-5}\n                             &                             & 40 Steps  & 80 Steps & 120 Steps  \\\\ \\hline\n\\multirow{2}{*}{Double Gyre} & MC                          & 0.0026    & 0.005    & 0.008      \\\\ \\cline{2-5}\n                             & Particle Filter             & 0.0035    & 0.007    & 0.01       \\\\ \\hline\n\\multirow{2}{*}{Ocean 2D}    & MC                          & 2.8       & 5.9      & 9.1        \\\\ \\cline{2-5}\n                             & Particle Filter             & 2.9       & 6.1      & 9.3        \\\\ \\hline\n\\multirow{2}{*}{Isabel}      & MC                          & 3.3       & 6.7      & 10.1       \\\\ \\cline{2-5}\n                             & Particle Filter             & 3.4       & 6.8      & 10.7       \\\\ \\hline\n\n\\end{tabular}\n\\caption{Overview of the performance for the particle filtering algorithm and the Monte Carlo method tested on all the distribution-based data sets used in this paper.}\n\\label{timing}\n\\end{table}\n", "meta": {"hexsha": "04c21a6dc89f8253e91b77bafd5730662e673791", "size": 20006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/pvis2016/draft-rs.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-rs.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-rs.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": 69.2249134948, "max_line_length": 1678, "alphanum_fraction": 0.7350794762, "num_tokens": 5361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219503, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.6541814355078585}}
{"text": "\\chapter{Graph}\n\n\\section{Fundamentals}\n\t\\kactlimport{BellmanFord.h}\n\t\\kactlimport{FloydWarshall.h}\n\t\\kactlimport{TopoSort.h}\n\n\\section{Euler walk}\n\t\\kactlimport{EulerWalk.h}\n\n\\section{Network flow}\n\t\\kactlimport{PushRelabel.h}\n\t\\kactlimport{MinCostMaxFlow.h}\n\t\\kactlimport{EdmondsKarp.h}\n\t% \\kactlimport{Dinic.h}\n\t\\kactlimport{MinCut.h}\n\t\\kactlimport{GlobalMinCut.h}\n\t\\kactlimport{GomoryHu.h}\n\n\\section{Matching}\n\t\\kactlimport{hopcroftKarp.h}\n\t\\kactlimport{DFSMatching.h}\n\t\\kactlimport{MinimumVertexCover.h}\n\t\\kactlimport{WeightedMatching.h}\n\t\\kactlimport{GeneralMatching.h}\n\n\\section{DFS algorithms}\n\t\\kactlimport{SCC.h}\n\t\\kactlimport{BiconnectedComponents.h}\n\t\\kactlimport{2sat.h}\n\n\\section{Heuristics}\n\t\\kactlimport{MaximalCliques.h}\n\t\\kactlimport{MaximumClique.h}\n\t\\kactlimport{MaximumIndependentSet.h}\n\n\\section{Trees}\n\t\\kactlimport{BinaryLifting.h}\n\t\\kactlimport{LCA.h}\n\t\\kactlimport{CompressTree.h}\n\t\\kactlimport{HLD.h}\n\t\\kactlimport{LinkCutTree.h}\n\t\\kactlimport{DirectedMST.h}\n\n\\section{Math}\n\t\\subsection{Number of Spanning Trees}\n\t\t% I.e. matrix-tree theorem.\n\t\t% Source: https://en.wikipedia.org/wiki/Kirchhoff%27s_theorem\n\t\t% Test: stress-tests/graph/matrix-tree.cpp\n\t\tCreate an $N\\times N$ matrix \\texttt{mat}, and for each edge $a \\rightarrow b \\in G$, do\n\t\t\\texttt{mat[a][b]--, mat[b][b]++} (and \\texttt{mat[b][a]--, mat[a][a]++} if $G$ is undirected).\n\t\tRemove the $i$th row and column and take the determinant; this yields the number of directed spanning trees rooted at $i$\n\t\t(if $G$ is undirected, remove any row/column).\n\n\t\\subsection{Erdős–Gallai theorem}\n\t\t% Source: https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93Gallai_theorem\n\t\t% Test: stress-tests/graph/matrix-tree.cpp\n\t\tA simple graph with node degrees $d_1 \\ge \\dots \\ge d_n$ exists iff $d_1 + \\dots + d_n$ is even and for every $k = 1\\dots n$,\n\t\t\\[ \\sum _{i=1}^{k}d_{i}\\leq k(k-1)+\\sum _{i=k+1}^{n}\\min(d_{i},k). \\]\n", "meta": {"hexsha": "ec863fe77cf5724aa582e9dcf88ab76f14ce3c90", "size": 1899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/graph/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/graph/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/graph/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": 31.65, "max_line_length": 127, "alphanum_fraction": 0.7319641917, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6539038030424823}}
{"text": "The previous chapter on motion planning and control introduced techniques for developing mathematical models to describe robot motion by analyzing its kinematics and dynamics. These models are typically expressed in the form of differential equations that are functions of a set of generalized coordinates/velocities and inputs to the system.\nThe next step is to discover how these models can be leveraged for robot motion planning and control. In particular this chapter and the next will focus on robot control, where the goal is to determine what inputs to apply to the system to achieve desirable behavior. To address the robot control problem a \\textit{control law} must be developed, which is a set of rules or a mathematical function that determines what inputs should be applied to the system at any given time.\n\nThe ecosystem of techniques for robot control is vast, and control laws can generally be categorized in several ways. One of the most fundamental classifications for a control law is if it is \\textit{open-loop} or \\textit{closed-loop}. Open-loop control laws do not rely on observations to influence the choice of control input, while closed-loop control laws do. As a practical example, suppose you are standing in a room and wanted to walk to the other side and sit in a chair. For open-loop control you might look at where the chair is relative to your current position, think about how to walk there, and then \\textit{with your eyes closed} walk to the chair and sit. Alternatively, for closed-loop control you might keep \\textit{your eyes open} the whole time.\n\nIn practice, open-loop control laws suffer from robustness issues since they do not make corrections based on real-time observations. However, open-loop control is still an extremely important topic within the context of robotics.\nIn particular, suppose you are interested not just in getting your robot from one point to another, but doing so in the \\textit{best} or \\textit{optimal} way. This problem, known as \\textit{trajectory optimization} or \\textit{optimal control}\\footnote{The terms trajectory optimization and optimal control will often be used interchangeably.}, can be solved to obtain an optimal trajectory for the robot along with the corresponding sequence of control inputs. In theory, applying this optimal control sequence as an open-loop control law would then make the robot follow the optimal trajectory. \n\nThis chapter will discuss several common techniques related to optimal control and trajectory optimization, including a brief review on dynamic/kinematic models, the formulation of the optimal control problem, approaches for solving optimal control problems, and some other topics useful in the context of robotics. The next chapter will then focus on the development of closed-loop control laws, including approaches that leverage the open-loop optimal control techniques discussed here.\n\n\\notessection{Open-Loop Motion Planning \\& Control}\nThis chapter and the next will focus on two of the most fundamental classifications for a control law, namely whether it is \\textit{open-loop} or \\textit{closed-loop}. In particular, this chapter will focus on open-loop control laws that arise from the study of optimal control and trajectory optimization problems\\cite{Kirk2004}\\cite[\\baselineskip]{Murray2009}. In general, open-loop control laws depend only on time and initial condition of the system.\n\n\\begin{definition} [Open-loop control] \\label{def:openloop}\nIf the control law is determined as a function of time for a specified initial state value, i.e., \n\\begin{equation}\n    \\bm{u}(t) = f ( \\x ( t_0 ) , t ),\n\\end{equation}\nthen it is said to be in open-loop form.\n\\end{definition}\n\n\n\\subsection{Kinematic and Dynamic Models}\nChapter 1 discussed techniques for deriving kinematic and dynamic models of a robot in the form of ordinary differential equations (ODE). Such models are extremely useful in the context of robot motion planning and control, and are essential in the context of optimal control.\nFor the remainder of this chapter it will be assumed that such a model has already been identified and is expressed in the form\n\\begin{equation} \\label{eq:dynamics}\n    \\dot{\\x}(t) = a(\\x(t),\\bm{u}(t),t),\n\\end{equation}\nwhere $\\x \\in \\R^n$ may be comprised of generalized coordinates $\\xi$ and velocities $\\dot{\\xi}$ and will be referred to as the robot's \\textit{state}, $\\bm{u} \\in \\R^m$ is the control input, and the function $a : \\R^n \\times \\R^m \\times \\R \\xrightarrow{} \\R^n$ defines the model. While the set of ODEs \\eqref{eq:dynamics} may have been derived by considering kinematics, dynamics, or a combination of the two, this model will be generally referred to as the robot's \\textit{dynamics} model.\n\nFor clarity, note that \\eqref{eq:dynamics} is a compact expression written in vector form for the system of $n$ first-order differential equations \n\\begin{align*}\n    \\dot{x}_1(t)&=a_1(x_1(t), x_2(t), \\dots, x_n(t), u_1(t), u_2(t), \\dots, u_m(t), t)\\\\\n    \\dot{x}_2(t)&=a_2(x_1(t), x_2(t), \\dots, x_n(t), u_1(t), u_2(t), \\dots, u_m(t), t)\\\\\n&\\vdots \\\\\n    \\dot{x}_n(t)&=a_1(x_1(t), x_2(t), \\dots, x_n(t), u_1(t), u_2(t), \\dots, u_m(t), t),\n\\end{align*}\nwhere $x_i$ is the $i$-th component of the vector $\\x$ and $u_j$ is the $j$-th component of the vector $\\bm{u}$.\n\nSolutions to the set of differential equations \\eqref{eq:dynamics} are trajectories of the system. Given an initial condition $\\x(t_0)$ and a control function $\\bm{u}(t)$ defined for $t \\geq t_0$, any technique for solving ODEs can be applied to compute the state trajectory $\\x(t)$ for $t > t_0$. Common numerical integration approaches for solving the ODE system include the Runge-Kutta schemes, of which the most common are the forward or backward Euler schemes. The forward Euler scheme approximates $\\dot{\\x}(t) \\approx \\frac{\\x_{i+1} - \\x_i}{h_i}$ with $h_i = t_{i+1} - t_{i}$ and evaluates $a$ at time $t_i$. This leads to the recursive update\n\\begin{equation}\n\\x_{i+1} = \\x_{i} + h_i a(\\x_i,\\bm{u}_i,t_i), \\quad i = 0, 1,\\dots\n\\end{equation}\nwhere $\\bm{u}_i = \\bm{u}(t_i)$ and $\\x_i = \\x(t_i)$.\n\n\n\\subsection{Optimal Control Problem}\nPerhaps the most common open-loop control laws used for motion planning and control in robotics are synthesized by formulating and solving optimal control problems. These problems are designed to answer the question: from the current state of the robot, $\\x(t_0)$, what future control inputs $\\bm{u}(t)$ would make the robot follow an optimal future trajectory? In general, generating optimal open-loop control laws require three major components:\n\\begin{enumerate}\n    \\item A model \\eqref{eq:dynamics} that describes the robot's motion as a function of the input, developed by analyzing the robot's kinematics/dynamics.\n    \\item A metric that defines the quality of a particular trajectory, known as a \\textit{cost function} or a \\textit{reward function}\\footnote{The term \\textit{cost} is more commonly used in optimal control literature, while \\textit{reward} is used in the reinforcement learning literature.}.\n    \\item An algorithm for searching the space of possible control inputs to find one that corresponds to an optimal trajectory\\footnote[][\\baselineskip]{For example, convex optimization solvers}.\n\\end{enumerate}\n\n\n\\subsubsection{Problem Formulation}\nIn this chapter the performance metric that defines the quality of a particular trajectory will be referred to as the \\textit{cost function}. The standard form for defining the cost function in optimal control problems is\n\\begin{equation} \\label{eq:cost}\nJ(\\x(t), \\bm{u}(t), t) = h(\\x(t_f),t_f) + \\int_{t_0}^{t_f} g(\\x(t),\\bm{u}(t),t) dt.\n\\end{equation}\nwhere $h(\\x(t_f),t_f)$ is referred to as a \\textit{terminal cost} and where the integral can be viewed as a sum of \\textit{stage costs} induced along the path from times $t_0$ to $t_f$.\nIn robotics, the function $J$ might quantify objectives such as ``get from point A to point B as quickly as possible” or “get from point A to point B while using as little effort as possible”. \n\nConstraints can also be considered in the optimal control problem. In the field of robotics it is common to consider constraints on the state and control that are expressed compactly as\n\\begin{equation} \\label{eq:constraints}\n\\x(t) \\in \\mathcal{X}, \\quad \\bm{u}(t) \\in \\mathcal{U},\n\\end{equation}\nwhere $\\mathcal{X}$ is the set of all \\textit{admissible} states and $\\mathcal{U}$ is the set of all \\textit{admissible} control inputs. A common way to define the sets $\\mathcal{X}$ and $\\mathcal{U}$ is by a set of inequalities on $x$ and $u$, respectively. For example, let's assume the first element of $\\x$ is constrained by $x_1 \\geq 0$, then $\\mathcal{X} = \\{x \\:|\\: x_1 \\geq 0\\}$ such that any vector $\\x$ with $x_1 \\geq 0$ belongs to the set $\\mathcal{X}$ (and is therefore \\textit{admissible}). \\marginnote{Constraints are commonly used in the context of robotics to account for actuator limits (e.g. how fast the wheels can turn, how much torque a motor can produce), or constraints on the trajectory itself (e.g. avoid collisions with surrounding objects).}\n\nThe optimal control problem is then expressed as an optimization problem over the state trajectory $\\x(t)$ and control inputs $\\bm{u}(t)$ with the goal of minimizing the cost function \\eqref{eq:cost} while also satisfying the constraints \\eqref{eq:constraints}.\n\n\\begin{definition}[Optimal Control Problem] \nAn optimal control problem seeks an \\textit{admissible control} $\\bm{u}(t)$ which causes the system (\\ref{eq:dynamics}) to follow an \\textit{admissible trajectory} $\\bm{x}(t)$ that minimizes a performance metric $J(\\x(t),\\bm{u}(t),t)$. This problem can be expressed as an optimization problem:\n\\begin{equation} \\label{eq:OCP}\n\\begin{split}\n\\underset{\\bm{u},\\x}{\\text{minimize}} \\:\\: & h(\\x(t_f),t_f) + \\int_{t_0}^{t_f} g(\\x(t),\\bm{u}(t),t) dt,\\\\\n\\text{s.t.} \\:\\:& \\dot{\\x}(t) = a(\\x(t),\\bm{u}(t),t), \\\\\n&\\x(t) \\in \\mathcal{X}, \\quad \\bm{u}(t) \\in \\mathcal{U}, \\\\\n&\\x(t_0) = \\x_0,\n\\end{split}\n\\end{equation}\nwhere $t_0$ is the initial time, $t_f$ is either a fixed final time or an optimization variable, and $x_0$ is a known initial condition.\n\\end{definition} \n\nThe solution to the optimal control problem \\eqref{eq:OCP} is an admissible and optimal trajectory defined over the interval $t \\in [t_0, t_f]$, and is denoted by $\\bm{u}^*(t)$ and $\\x^*(t)$.\n\n\\subsubsection{Solving the Optimal Control Problem}\nOnce the optimal control problem \\eqref{eq:OCP} has been formulated, the next step is to find a solution. However, this can be challenging since \\eqref{eq:OCP} is an infinite-dimensional optimization problem (because the optimization is over an infinite-dimensional function and not a finite set of parameters). Unless an analytical solution to the problem can be found, this problem must be transformed into a finite dimensional problem so that it can be solved numerically on a computer.\nIn general, algorithms for numerically solving optimal control problems can be classified as either \\textit{direct} or \\textit{indirect} methods. \n\n\\paragraph{Direct Methods:}\nDirect methods follow a ``first discretize, then optimize\" approach. In the first step the problem \\eqref{eq:OCP} is converted into a finite-dimensional problem by discretizing the functions $\\x(t)$ and $\\bm{u}(t)$. For example this might be accomplished by defining the new optimization variables to be $\\x(t_i)$ and $\\bm{u}(t_i)$ for a finite number of time points $t_i$. This finite-dimensional optimization problem is generally referred to as a \\textit{nonlinear program} (NLP), which can be solved with existing numerical algorithms\\footnote{Several solvers for solving general NLPs include IPOPT and SNOPT, and software packages for solving optimal control problems using the direct method include DIDO, PROPT, and GPOPS.}.\n\n\\paragraph{Indirect Methods:}\nIndirect methods follow a ``first optimize, then discretize\" approach. These methods first derive the necessary conditions of optimality, which are expressed as a two-point boundary value problem. This two-point boundary value problem is essentially a set of ODEs with boundary conditions at two points\\footnote{This is in contrast to initial value problems, which have a single boundary condition and can easily be numerical integrated to find a solution.} that must be numerically solved.\n\n\\vspace{\\baselineskip}\nIndirect methods are less commonly used in robotics because the derivation of the necessary conditions of optimality must be done on a case by case basis, and can become quite challenging. They become particularly difficult to use when constraints are imposed in the problem. In contrast, direct methods offer much more flexibility and have been quite successful in practice.\n\n\\subsection{Differential Flatness}\nSolving optimal control problems to compute optimal trajectories and optimal control inputs for a system can sometimes be computationally challenging. In fact, sometimes it is more desirable to have a computationally efficient way of generating ``good'' trajectories, rather than a challenging way of generating ``optimal'' ones.\n\nFor a special class of models, which are referred to as \\textit{differentially flat}, computing ``good'' trajectories without having to formulate optimal control problems is quite easy. There are several models that are common in robotics that are differentially flat, including a simple car model and quadrotor models.\n\n\\begin{example}[Simple Car Model] \\label{ex:carflatness}\n\\theoremstyle{definition}\n\\begin{marginfigure}\n    \\centering \n    \\includegraphics[width=0.95\\linewidth]{tex/figs/ch02_figs/car.png}\n    \\caption{Simple model for an automobile. The state consists of the $(x,y)$ position of the center of the rear axle and the heading angle $\\theta$. The control inputs are the steering angle $\\phi$ and the forward velocity.}\n    \\label{fig:car-model} \n\\end{marginfigure} \nConsider the car model corresponding to Figure \\ref{fig:car-model}:\n\\begin{equation} \\label{eq:car-dynamics}\n\\begin{split}\n    \\dot{x} &= v\\cos\\theta,\\\\\n    \\dot{y} &= v\\sin\\theta,\\\\\n    \\dot{\\theta} &= \\frac{v}{L}\\tan\\phi, \n\\end{split}\n\\end{equation}\nwhere $(x, y)$ is the position and $\\theta$ is the orientation of the vehicle, $v$ is the speed, $\\phi$ is the steering angle, and $L$ is the length of the wheelbase. The state $\\x$ is therefore defined as $\\x = [x, \\: y, \\: \\theta]^\\top $ and the control is defined as $\\bm{u} = [v, \\:\\phi]^\\top $.\n\nSuppose the motion planning task is to find a control sequence $\\bm{u}(t)$ that will take the car from an initial state $\\x_0$ to a final desired state $\\x_{f}$. One option would be to formulate an optimal control problem with constraints $\\x(t_0) = x_0$ and $\\x(t_f) = \\x_f$. However, it turns out that for this model there is a simpler approach. In fact, for this model it is sufficient to specify a differentiable trajectory for $x(t)$ and $y(t)$, and the remaining state variables and control inputs can be \\textit{analytically} determined!\n\nTo see why this is, consider a differentiable trajectory for for $x(t)$ and $y(t)$ with derivatives $\\dot{x}(t)$ and $\\dot{y}(t)$. From the dynamics model \\eqref{eq:car-dynamics} it can be seen that the first two equations can be leveraged to compute $\\theta(t)$:\n\\begin{equation*}\n\\theta = \\tan^{-1}(\\dot{y}/\\dot{x}).\n\\end{equation*}\nFurthermore, once $\\theta(t)$ has been computed the speed is defined:\n\\begin{equation*}\nv = \\dot{x}/\\cos\\theta, \\quad \\text{or}  \\quad v = \\dot{y}/\\sin\\theta.\n\\end{equation*}\nFinally, given $\\theta(t)$ and $v(t)$ it is possible to directly solve for the steering angle:\n\\begin{equation*}\n\\phi = \\tan ^{-1}(\\frac{L\\dot{\\theta}}{v}).\n\\end{equation*}\n\nThis property, that from the specification of a few variables and their derivatives the remaining state and control values are defined, is known as \\textit{differential flatness}. \n\\end{example}\n\n\\begin{definition}[Differential Flatness]\nA non-linear system\n\\begin{equation} \\label{eq:diffflatsys}\n\\dot{\\x}(t) = a(\\x(t),\\bm{u}(t)),\n\\end{equation}\nis differentially flat with flat output $\\z$ if there exists a function $\\alpha$ such that\n\\begin{equation}\n\\z = \\alpha (\\x,\\bm{u},\\dot{\\bm{u}},\\dots,\\bm{u}^{(p)}),\n\\end{equation}\nand such that the solutions to the system $\\x(t)$ and $\\bm{u}(t)$ can be written as functions of the flat output $\\z$ and a finite number of its derivatives:\n\\begin{equation} \\label{eq:ztoxu}\n\\begin{split}\n\\x &= \\beta (\\z,\\dot{\\z},\\dots,\\z^{(q)}) \\\\\n\\bm{u} &= \\gamma (\\z,\\dot{\\z},\\dots,\\z^{(q)}).\n\\end{split}\n\\end{equation}\n\\end{definition}\n\nFor a differentially flat system, all of the feasible trajectories for the system can be written as functions of a flat output $\\z(t)$ and its time derivatives. Additionally, note that the number of flat outputs is always equal to the number of system inputs. In the context of motion planning and control this is extremely useful for trajectory design because the flat outputs can be specified and then \\textit{directly mapped} to the corresponding control inputs.\n\n\\subsubsection{Trajectory Design for Differentially Flat Systems}\nAs previously mentioned, trajectory design for differentially flat systems only requires specification of the trajectories of the flat outputs, which greatly simplifies motion planning and control.\n\nConsider a nonlinear system model of the form \\eqref{eq:diffflatsys} that is differentially flat with flat output $\\z$ where the objective is to design a trajectory from $\\x_0$ to $\\x_f$ over a horizon of $T$ seconds. First, find the boundary conditions for the flat output $\\z(0)$ and $\\z(T)$ that satisfy the boundary conditions on $\\x$ by noting that\n\\begin{equation} \\label{eq:flatbc}\n\\begin{split}\n\\x_0 &= \\beta (\\z(0),\\dot{\\z}(0),\\dots,\\z^{(q)}(0)), \\\\\n\\x_f &= \\beta (\\z(T),\\dot{\\z}(T),\\dots,\\z^{(q)}(T)). \\\\\n\\end{split}\n\\end{equation}\nSecond, compute \\textit{any} smooth trajectory for the flat outputs $\\z(t)$ that satisfy these boundary conditions. Third, use \\eqref{eq:ztoxu} to map the flat output trajectory $\\z(t)$ to the state and control trajectories $\\x(t)$ and $\\bm{u}(t)$.\n\nSince the flat outputs can be specified as any smooth trajectory, a common choice is to parameterize them using $N$ smooth basis functions:\n\\begin{equation} \\label{eq:flat}\nz_j(t) = \\sum_{i=1}^{N} \\alpha_i^{[j]} \\psi_i(t),\n\\end{equation}\nwhere $z_j$ is the $j$-th element of $\\z$, $\\alpha_i^{[j]} \\in \\mathbb{R}$ are variables that parameterize the trajectory and $\\psi_i(t)$ are the smooth basis functions. One potential choice is to use polynomial basis functions $\\psi_1(t) = 1$, $\\psi_2(t) = t$, $\\psi_3(t) = t^2$, and so on. Another advantage of choosing this parameterization of $z_j(t)$ is that it is linear in the variables $\\alpha_i^{[j]}$. This makes it easy to map specifications on $\\z$ into values for $\\alpha_i$ that define the trajectory. Consider differentiating \\eqref{eq:flat} $q$ times:\n\\begin{equation}\n\\begin{split}\n\\dot{z}_j(t) &= \\sum_{i=1}^{N} \\alpha_i^{[j]} \\dot{\\psi_i}(t), \\\\\n&\\vdots \\\\\nz_j^{(q)}(t) &= \\sum_{i=1}^{N} \\alpha_i^{[j]} \\psi_i^{(q)}(t). \\\\\n\\end{split}\n\\end{equation}\nNow, from the initial and final conditions $z_j(0), \\: \\dot{z}_j(0), \\: \\dots , z_j^{(q)}(0)$ and $z_j(T), \\: \\dot{z}_j(T), \\: \\dots , z_j^{(q)}(T)$ the coefficients $\\alpha_i^{[j]}$ can be computed by solving the following linear system (assuming the matrix is full rank):\n\\begin{equation} \\label{eq:diffflatlinear}\n\\begin{bmatrix}\n    \\psi_1(0) & \\psi_2(0) & \\dots & \\psi_N(0) \\\\\n    \\dot{\\psi_1}(0) & \\dot{\\psi_2}(0) & \\dots & \\dot{\\psi_N}(0) \\\\\n    \\vdots & \\vdots & & \\vdots \\\\\n    \\psi_1^{(q)}(0) & \\psi_2^{(q)}(0) & \\dots & \\psi_N^{(q)}(0) \\\\\n    \\psi_1(T) & \\psi_2(T) & \\dots & \\psi_N(T) \\\\\n    \\dot{\\psi_1}(T) & \\dot{\\psi_2}(T) & \\dots & \\dot{\\psi_N}(T) \\\\\n    \\vdots & \\vdots & & \\vdots \\\\\n    \\psi_1^{(q)}(T) & \\psi_2^{(q)}(T) & \\dots & \\psi_N^{(q)}(T) \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    \\alpha_1^{[j]} \\\\\n    \\alpha_2^{[j]} \\\\\n    \\vdots \\\\\n    \\alpha_N^{[j]} \\\\\n\\end{bmatrix} =\n\\begin{bmatrix}\n    z_j(0) \\\\\n    \\dot{z}_j(0) \\\\\n    \\vdots \\\\\n    z^{(q)}_j(0) \\\\\n    z_j(T) \\\\\n    \\dot{z}_j(T) \\\\\n    \\vdots \\\\\n    z_j^{(q)}(T)\n\\end{bmatrix}.\n\\end{equation}\nOnce the values for $\\alpha_i^{[j]}$ are known, the entire trajectory $z_j(t)$ is therefore known!\n\nNote that this approach is not strictly limited to specifying the initial and final conditions. It is also possible to specify other constraints on $z_j$ and its derivatives as long as they are \\textit{equality} constraints. This is accomplished by simply adding equations corresponding to the desired constraints to the linear system of equations \\eqref{eq:diffflatlinear}. However, if too many constraints are added the linear system \\eqref{eq:diffflatlinear} may not have a solution (i.e. the system is over-determined). Assuming the constraints are not conflicting, this problem can typically be fixed by adding additional basis functions.\n\nTo summarize, for differentially flat nonlinear systems, the motion planning and control problem can be greatly simplified by planning in the flat output space. This is possible because of nonlinear functions that allow the flat output trajectory to be directly mapped to state and control trajectories that satisfy the system dynamics.\n\n\n\\subsubsection{Constraints and Time Scaling}\nAs previously shown, some constraints (e.g. boundary conditions) can be imposed on the trajectory by converting them into conditions on $\\z$ and its derivatives, and then solving the linear system of equations \\eqref{eq:diffflatlinear}. However, applying \\textit{bound} constraints can be slightly more challenging since they are expressed as inequality constraints rather than equality constraints. Nonetheless, bound constraints are common in robotics and therefore it is important to be able to consider them in the trajectory generation process. For example, the simple car robot from Example \\ref{ex:carflatness} could have an upper bound on its speed: \n\\begin{equation*}\n|v(t)| \\leq v_\\text{max}.\n\\end{equation*}\n\nOne technique for handling these types of constraints is to use \\textit{time scaling}. The general approach to satisfy bound constraints by time scaling is:\n\\begin{enumerate}\n    \\item Specify boundary conditions and solve the linear system of equations \\eqref{eq:diffflatlinear} to get a candidate trajectory $\\x(t)$ with control inputs $\\bm{u}(t)$.\n    \\item If the candidate trajectory violates any bound constraints, generate a new trajectory by keeping the same geometric \\textit{path} but decreasing the rate at which it moves along the path.\n\\end{enumerate}\n\n\\subsubsection{Geometric Path}\nA geometric path is a sequence of states for the robot that is not associated with time. Given a candidate trajectory $\\x(t)$, the geometric path can be defined by alternatively expressing the trajectory as $\\x(t) = \\x(s(t))$ where $s$ is a new ``path'' parameter and $s(t)$ is defined with $s(0) = s_0$, $s(T) = s_f$, and $\\dot{s}(t) > 0$. A common choice for the path parameter $s$ is the arc length along the path. The geometric trajectory is then written as just $\\x(s)$, such that the state is now a function of the position along the path and not time. Note that $\\x(t): [0,T] \\xrightarrow{} \\R^n$ and $\\x(s): [s_0, s_f] \\xrightarrow{} \\R^n$ are actually two different functions. In particular, the function $\\x(t)$ can be derived from $\\x(s)$ by the definition of the function $s(t): [0,T] \\xrightarrow{} [s_0, s_f]$ and the composition $\\x(s(t))$.\n\n\\subsubsection{Time Scaling}\nFor some systems, once the geometric path $\\x(s)$ has been extracted from the candidate trajectory $\\x(t)$, it is possible to arbitrarily redefine new trajectories with different time scales by simply redefining $s(t)$. In other words parts of the original candidate trajectory can be sped up or slowed down as desired. \n\nTo motivate why time scaling is important we can consider a simplified problem that does not involve a dynamics model. In particular, consider a scalar variable $x \\in \\R$ and a desired geometric path that connects $x_0$ and $x_f$ that is parameterized as $x(s) = x_0 + s(x_f - x_0)$ for $s \\in [0,1]$ (note that $x(0) = x_0$ and $x(1) = x_f$). By choosing how $s$ varies in time (i.e. the function $s(t)$) this geometric path can be transformed into many different \\textit{trajectories}, $x(t)$. As a simple choice, the function $s(t)$ can be parameterized as the cubic polynomial:\n\\begin{equation*}\n    s(t) = \\frac{3}{T^2}t^2 - \\frac{2}{T^3}t^3.\n\\end{equation*}\nThis specific choice ensures that $s(0) = 0$, $s(T) = 1$, and $\\dot{s}(0) = \\dot{s}(T) = 0$ such that the trajectory will be defined over the time interval $t \\in [0,T]$. Substituting this function into $x(s)$ then yields an expression for the trajectory $x(t)$:\n\\begin{equation*}\n    x(t) = x_0 + \\big(\\frac{3}{T^2}t^2 - \\frac{2}{T^3}t^3 \\big)(x_f - x_0).\n\\end{equation*}\nOne easy way to scale the trajectory in this case is to simply change $T$, with larger values of $T$ meaning that it will take longer for $x$ to traverse the geometric path from $x_0$ to $x_f$. In fact, the maximum velocity can also be computed as:\n\\begin{equation*}\n    \\dot{x}_{\\text{max}} = \\frac{3}{2T}(x_f - x_0).\n\\end{equation*}\nTherefore, not only does rescaling the trajectory by changing $T$ make the path traversal time change, but it can also be used to decrease quantities such as the maximum velocity!\n\n\\paragraph{Time Scaling with Differential Models:}\nSome additional considerations need to be made when time-scaling trajectories that must also satisfy differential models.\nFirst, note that the time derivative of the state can be rewritten by using the chain rule:\n\\begin{equation*}\n\\dot{\\x}(t) = \\frac{d\\x(t)}{dt} = \\frac{d\\x(s)}{ds} \\frac{ds(t)}{dt}.\n\\end{equation*}\nNow consider a candidate trajectory $\\x(t)$ and an associated geometric path $\\x(s)$ for some $s(t)$ that is defined over the interval $t\\in[0,T]$ with $s(0) = s_0$ and $s(T) = s_f$. Since $\\x(t)$ is a trajectory of the dynamics \\eqref{eq:diffflatsys}, the geometric path $\\x(s)$ and time scaling law $s(t)$ satisfy\n\\begin{equation}\n\\frac{d\\x(s)}{ds} \\frac{ds(t)}{dt} = a(\\x(s), \\bm{u}(s)),\n\\end{equation}\nfor every point $s \\in [s_0, s_f]$.\n\nTo design a new time scaling law $\\tilde{s}(t)$ over some potentially new time interval $t \\in [0,\\tilde{T}]$ where $\\tilde{s}(0) = s_0$ and $\\tilde{s}(\\tilde{T}) = s_f$, it is important to note that the dynamics equations must still be satisfied\\footnote{The geometric path is still defined on the interval $[s_0, s_f]$ so this interval must remain the same for any new time scaling law, but the time interval can change.}. In other words, for every $\\tilde{s} \\in [s_0, s_f]$:\n\\begin{equation} \\label{eq:stildedynamics}\n\\frac{d\\x(\\tilde{s})}{d\\tilde{s}} \\dot{\\tilde{s}} = a(\\x(\\tilde{s}), \\tilde{\\bm{u}}(\\tilde{s})).\n\\end{equation}\nSince the geometric path is fixed, the terms $\\frac{d\\x(\\tilde{s})}{d\\tilde{s}}$ and $\\x(\\tilde{s})$ are fixed. Thus a new time scaling law $\\tilde{s}(t)$ is only admissible if a new control $\\tilde{\\bm{u}}(\\tilde{s})$ can also be found that guarantees that \\eqref{eq:stildedynamics} holds.\nLuckily, for some specific systems this is easy with the appropriate choice of path parameter $s$.\n\n\\begin{example}[Time Scaling for Simple Car Model]\n\\theoremstyle{definition} Consider again the simple car model \\eqref{eq:car-dynamics} from Example \\ref{ex:carflatness}. Suppose a candidate trajectory $\\x_c(t)$ with control $\\bm{u}_c(t)$ has been defined by leveraging the differential flatness of the model (i.e. setting up and solving \\eqref{eq:diffflatlinear} and then mapping the flat outputs $\\z_c(t)$ into the state and control). For this system a good choice for the path parameter is the arc-length, such that\n\\begin{equation*}\n    s(t) = \\int_0^\\top  v(t') dt', \\quad \\dot{s}(t) = v(t).\n\\end{equation*}\n\nWith this choice of path parameter the geometric path function $\\x_c(s)$, $s_0 = 0$, and $s_f = L_{\\text{path}}$ are all fixed (where $L_{\\text{path}}$ is the total length of the path). Rewriting the dynamics \\eqref{eq:stildedynamics} based on the simple car model:\n\\begin{equation*}\n\\begin{split}\n\\frac{dx_c(\\tilde{s})}{d\\tilde{s}}\\dot{\\tilde{s}} &= v(\\tilde{s})\\cos\\theta_c(\\tilde{s}),\\\\\n\\frac{dy_c(\\tilde{s})}{d\\tilde{s}}\\dot{\\tilde{s}}&= v(\\tilde{s})\\sin\\theta_c(\\tilde{s}),\\\\\n\\frac{d\\theta_c(\\tilde{s})}{d\\tilde{s}}\\dot{\\tilde{s}} &= \\frac{v(\\tilde{s})}{L}\\tan\\phi(\\tilde{s}).\n\\end{split}\n\\end{equation*}\nAny choice of the time scaling function $\\tilde{s}(t)$ must be able to satisfy these equations, and note that the trivial choice of $\\tilde{s}(t) = s(t)$ will automatically satisfy these equations with the candidate control inputs $\\bm{u}_c(t)$. \n\nSince the choice of the path parameter yields $\\dot{\\tilde{s}} = v(\\tilde{s})$, these equations can be further simplified:\n\\begin{equation*}\n\\begin{split}\n\\frac{dx_c(\\tilde{s})}{d\\tilde{s}} &= \\cos\\theta_c(\\tilde{s}),\\\\\n\\frac{dy_c(\\tilde{s})}{d\\tilde{s}}&= \\sin\\theta_c(\\tilde{s}),\\\\\n\\frac{d\\theta_c(\\tilde{s})}{d\\tilde{s}} &= \\frac{1}{L}\\tan\\phi(\\tilde{s}).\n\\end{split}\n\\end{equation*}\nThe first two equations are guaranteed to be satisfied for all $\\tilde{s} \\in [s_0, s_f]$ because the original candidate trajectory satisfies the dynamics. Additionally, the third equation is guaranteed to be satisfied by choosing $\\phi(\\tilde{s}) = \\phi_c(\\tilde{s})$ (i.e. using the same steering input as with the candidate trajectory).\n\nThis is interesting because it means that the equations are all satisfied \\textit{independently} of the choice of $\\dot{\\tilde{s}}$. Therefore, since $\\dot{\\tilde{s}} = v(\\tilde{s})$ this means that the speed input can be chosen arbitrarily while maintaining the same geometric path! This is extremely useful because it means that bound constraints on the speed $\\lvert v(t)\\rvert \\leq v_\\text{max}$ can be easily enforced.\n\\end{example}\n\n\n\\paragraph{Time Scaling with Kinematic Models:} Time-scaling trajectories is much more straightforward when kinematic models are used. Consider the case where the model of the system is derived from $k$ Pfaffian constraints $\\bm{A}^\\top (\\x)\\dot{\\x} = 0$. In this case the kinematic model can be written in the form:\n\\begin{equation} \\label{eq:kinmodel}\n    \\dot{\\x} = G(\\x) \\bu,\n\\end{equation}\nwhere the columns of the matrix $G(\\x)$ span the null space of the matrix $A^\\top (\\x)$. Now again consider a path parameter $s$ that is used to reparameterize trajectories $\\x(t)$ as $\\x(s(t))$, and satisfies $s(0) = s_0$, $s(T) = s_f$, and $\\dot{s}(t) > 0$\\footnote{The condition $\\dot{s}(t) > 0$ is critical to ensure that the function $s(t)$ is invertible. In other words, to guarantee that there is a one-to-one mapping between $t$ and $s$.}. Rewriting the time derivative of the state using the chain rule yields:\n\\begin{equation}\n    \\frac{d\\x(s)}{ds} \\dot{s} = G(\\x) \\bu(t).\n\\end{equation}\nBy making a substitution that $\\bu(t) =  \\bu_g(s)\\dot{s}$ the dynamics can be further written as:\n\\begin{equation} \\label{eq:kinematicgeometricmodel}\n    \\frac{d\\x(s)}{ds} = G(\\x)\\bu_g(s).\n\\end{equation}\nThe terms $\\bu_g(s)$ are referred to as \\textit{geometric controls}, since they are defined only with respect to the path parameter $s$. Critically, \\eqref{eq:kinematicgeometricmodel} says that once the geometric controls $\\bu_g(s)$ are defined, the entire geometric path $\\x(s)$ is also defined! The choice of the timing law $s(t)$ can then be chosen in any manner and it will not change the geometric path, but will change the time trajectory $\\x(t)$. In particular, once the geometric control $\\bu_g(s)$ and timing law are chosen, the actual controls are computed simply by the previous relationship $\\bu(t) =  \\bu_g(s)\\dot{s}$.\n\nBased on this analysis, the procedure for \\textit{rescaling} a trajectory of a kinematic model can be made more concrete. First, consider a given trajectory $\\x(t)$ with control $\\bu(t)$ defined over $t \\in [0,T]$ that satisfies the kinematic model \\eqref{eq:kinmodel}. For simplicity, consider the path parameter $s$ to be arc-length of the trajectory such that $s(0) = 0$ and $s(T) = L_{\\text{path}}$.\nThe following steps can then be used to define a new control input $\\tilde{\\bu}(t)$ that will make the kinematic model follow the same geometric path but with a different time scale:\n\\begin{enumerate}\n\\item Determine $s(t)$ based on the original trajectory $\\x(t)$. In other words, figure out how far along the trajectory the system is at each time $t$. Then reparameterize the control $\\bu(t)$ as a function of $s$, $\\bu(s(t))$. \n\\item Compute the geometric controls $\\bu_g(s) = \\bu(s(t))/\\dot{s}(t)$ for each point $s \\in [s_0, s_f]$.\n\\item Define a new timing law $\\tilde{s}(t)$ that satisfies $\\tilde{s}(0) = 0$ and $\\tilde{s}(\\tilde{T}) = L_{\\text{path}}$ with $\\dot{\\tilde{s}} > 0$ over the interval $[0, \\tilde{T}]$.\n\\item Compute the new control $\\tilde{\\bu}(t) = \\bu_g(\\tilde{s}(t)) \\dot{\\tilde{s}}(t)$ for all $t \\in [0, \\tilde{T}]$.\n\\end{enumerate}\n\n\n\\begin{example}[Time Scaling for Unicycle Model] \\label{ex:timescaleuni}\n\\theoremstyle{definition}\nConsider the kinematic unicycle model:\n\\begin{equation} \\label{eq:unicycle}\n\\begin{split}\n    \\dot{x} &= v\\cos\\theta,\\\\\n    \\dot{y} &= v\\sin\\theta,\\\\\n    \\dot{\\theta} &= \\omega, \n\\end{split}\n\\end{equation}\nwhere $(x, y)$ is the position and $\\theta$ is the orientation, $v$ is the speed, and $\\omega$ is the rotation rate. The state $\\x$ is defined as $\\x = [x, \\: y, \\: \\theta]^\\top $ and the control is defined as $\\bm{u} = [v, \\:\\omega]^\\top $.\n\nTo time-scale trajectories of this system, consider the use of arc-length as path parameter:\n\\begin{equation*}\n    s(t) = \\int_0^t  v(\\tau) d\\tau, \\quad \\dot{s}(t) = v(t),\n\\end{equation*}\nsuch that for a trajectory defined on the interval $t \\in [0,T]$ with total length $L_{\\text{path}}$, the path parameter is defined with $s(0) = 0$ and $s(T) = L_{\\text{path}}$.\nWith this choice, the geometric controls are given by:\n\\begin{equation*}\n\\begin{split}\nv_g(s) &= \\frac{v(s)}{\\dot{s}(t)} = 1, \\\\\n\\omega_g(s) &= \\frac{\\omega(s)}{\\dot{s}(t)} = \\frac{\\omega(s)}{v(s)},\n\\end{split}\n\\end{equation*}\nwhere $v(s(t))$ has been substituted in for $\\dot{s}(t)$.\nTherefore if a new timing law $\\tilde{s}(t)$ is introduced this will automatically define a new velocity $\\tilde{v}(\\tilde{s})$ at each point $\\tilde{s}$, which can then be used to solve for the new $\\tilde{\\omega}$ inputs by:\n\\begin{equation*}\n\\begin{split}\n\\tilde{\\omega}(\\tilde{s}) &= \\omega_g(\\tilde{s}) \\dot{\\tilde{s}}(t) = \\frac{\\omega(\\tilde{s})}{v(\\tilde{s})} \\tilde{v}(\\tilde{s}).\n\\end{split}\n\\end{equation*}\nAlternatively, since it is easier to work with the velocity directly rather than $\\tilde{s}(t)$, in this case it is possible to just specify $\\tilde{v}(\\tilde{s})$ for all $\\tilde{s} \\in [0, L_{\\text{path}}]$ and then to compute $\\tilde{\\omega}(\\tilde{s}) = \\frac{\\omega(\\tilde{s})}{v(\\tilde{s})} \\tilde{v}(\\tilde{s})$. Then, to determine the new controls as functions of time rather than $\\tilde{s}$, it can be noted that\n\\begin{equation*}\n    \\tau(s) = \\int_0^s \\frac{ds'}{\\tilde{v}(s')},\n\\end{equation*}\ndefines a function $\\tau(s)$ that maps each point $s \\in [0, L_{\\text{path}}]$ to a new time.\n\\end{example}\n\n\n\\subsection{Exercises}\n\\subsubsection{Trajectory Generation via Differential Flatness}\nComplete \\textit{Problem 1:  Trajectory Generation via Differential Flatness} located in the online repository:\n\n\\vspace{\\baselineskip}\n\n\\url{https://github.com/PrinciplesofRobotAutonomy/AA274A_HW1},\n\n\\vspace{\\baselineskip}\n\nwhere you will use an extended unicycle model to practice generating dynamically feasible trajectories by levering the system's differential flatness property. You will also have the chance to use time scaling techniques to design trajectories that satisfy control constraints.\n\n \n\n\n", "meta": {"hexsha": "a8c6b8988540370121eafd27e042a4aa6b87eb93", "size": 35768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch02.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/ch02.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/ch02.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": 94.1263157895, "max_line_length": 855, "alphanum_fraction": 0.7288358309, "num_tokens": 10026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6539037855091172}}
{"text": "%!TEX root = ms.tex\n\\section{Conclusion and future work}\n\\label{sec:conclusion}\nIn this paper, the use of information criteria to compare regression models under general linear restrictions for both fixed and random predictors is discussed. It is shown that general versions for KL-based discrepancy (AICc and RAICc, respectively) and squared error-based discrepancy (C$_p$, FPE, RC$_p$ and S$_p$, respectively) can be formulated as effectively unbiased estimators of the test error (up to some terms that are free of the linear restrictions and hence are irrelevant when comparing criteria for different models). Model comparison based on the KL-based discrepancy measures is shown via simulations to be better-behaved than squared error-based discrepancies (including cross-validation) in selecting models with low predictive error and sparse subset.\n\nThe study of RAICc for variable selection in this paper focuses on OLS fits on pre-fixed predictors (e.g. nested predictors based on their physical orders in $X$). The discussion can be extended to other fitting procedures where the predictors in each subset are decided in a data-dependent way. For instance, \\citet{tian2019use} discussed using AICc for least-squares based subset selection methods, and extending those results to the random-X scenario is a topic for future work. \n\nNote also that only restrictions on the regression coefficients are considered here, corresponding to restrictions on the regression portion of the model. It is also possible that the data analyst could be interested in restrictions on the distributional parameters of the predictors (restricting the variances of some predictors to be equal to each other, for example, or restricting covariances to follow a specified pattern such as autoregressive of order $1$ or compound symmetry), and it would be interesting to try to generalize the criteria discussed here to that situation.", "meta": {"hexsha": "3b7f0e004c589a6ef2f3d314833d37c2877766c8", "size": 1919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/conclusion.tex", "max_stars_repo_name": "sentian/RAICc", "max_stars_repo_head_hexsha": "0e3b620354733de1fe953a2a21559bcb20055b96", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/conclusion.tex", "max_issues_repo_name": "sentian/RAICc", "max_issues_repo_head_hexsha": "0e3b620354733de1fe953a2a21559bcb20055b96", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/conclusion.tex", "max_forks_repo_name": "sentian/RAICc", "max_forks_repo_head_hexsha": "0e3b620354733de1fe953a2a21559bcb20055b96", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 239.875, "max_line_length": 772, "alphanum_fraction": 0.8170922355, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961424, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6539016142150129}}
{"text": "\\chapter{Finite Markov Decision Process}\n\n\\section{Summary}\n\nMDP's are a formal framework to model sequential decision making. It can handle immediate and delayed rewards, incorporating state.\n\n\\subsection{Agent-Environment Interface}\n\n\\begin{enumerate}\n\t\\item agent: Leaner and decision maker.\n\t\\item environment: The thing the agent interacts with.\n\t\\item $P(s', r|s,a)$: dynamics of the system (as probability distribution) \n\\end{enumerate}\n\nIf the next state $S_{t+1}$ only depends on the current state $S_t$ and the input $A_t$, then the state is said to have the \\textbf{Markov property} .\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\n\t\\node at (1, 0) (a) {Agent};\n\t\\node at (4, 0) (b) {Enviroment};\n\t\n\t\\draw [->, auto, bend left] (a) to node {$A_t$} (b);\n\t\\draw [->, auto, bend left] (b) to node {$S_{t+1}$, $R_{t+1}$} (a);\n\t\\end{tikzpicture}\n\t\\caption{Agent Environment}\n\t\\label{fig:agent-enviroment}\n\\end{figure}\n\n\\subsection{Goals and rewards}\n\nThe \\textbf{reward hypothesis} say's that all goals/purposes can be expressed as maximizing reward.\n\nReward should only communicate \\textbf{what} needs to be done, not \\textbf{how}.\n\n\\subsection{Returns and episodes}\nAn \\textbf{episodial task} has a finite number of steps, until it stops in the absorbing state. $G_t = R_{t+1} + R_{t+2} + ... + R_{T}$.\n\nA \\textbf{continuing task} never stops, so it keeps getting rewards. So an extra concept \\textbf{discount factor}($\\gamma$) is needed to define the expected reward.  \n\n\\begin{equation}\n\\begin{split}\nG_T & = R_{t+1} + \\gamma R_{t+2} + ... \\\\\n& = \\sum_{k=0}^{\\infty}\\gamma R_{t+k+1} \\\\\n& 0 \\leq \\gamma \\leq 1\n\\end{split}\n\\label{eq:expected return continuing task}\n\\end{equation}\n\nThe discount factor is a geometric series, and equals to one.\n\\begin{equation}\n\\sum_{k=0}^{\\infty} \\gamma ^k = \\frac{1}{1-\\gamma}\n\\label{eq:discount factor geometry series}\n\\end{equation}\n\n\\subsection{Policies and value function}\nThe \\textbf{state-value function} expressed how it is to be in a certain state under a certain policy($\\pi$). It has a recursive definition that is derived in equation~\\ref{eq:bellman equation value function derivation} and known as the \\textbf{bellman equation}.\n\n\\begin{equation}\n\\begin{split}\nV_{\\pi}(s) & = \\EX\\left[G_t | S_t = s\\right]\\\\\n& = \\EX\\left[\\sum_{k=0}^\\infty \\gamma^k R_{t + k + 1} | S_t = s\\right]\\\\\n& = \\EX\\left[R_{t+1} + \\gamma G_{t+1} | S_t = s \\right]\\\\\n& = \\sum_a \\pi(a|s)\\sum_{s',r} p(s', r|s,a)( r + \\gamma \\EX_\\pi[G_{t+1}|S_{t+1}=s']) \\\\\n& = \\sum_a \\pi(a|s)\\sum_{s',r} p(s', r|s,a)( r + \\gamma v_\\pi(s'))\n\\end{split}\n\\label{eq:bellman equation value function derivation}\n\\end{equation}\n\nThe value of taking action $a$ under state $s$ is defined by the \\textbf{action-value function} equation~\\ref{eq:action-value function}.\n\n\\begin{equation}\n\\begin{split}\nq_\\pi(a, s) \n& = \\EX[G_t | S_t = s, A_t = a]\\\\\n& = \\EX\\left[\\sum_{k=0}^\\infty \\gamma^k R_{t + k + 1} | S_t = s, A_t = a\\right]\\\\\n& = \\sum_{r,s'} p(s', r|s,a)( r + \\gamma v_\\pi(s'))\n\\label{eq:action-value function}\n\\end{split}\n\\end{equation}\n\n\\subsection{Optimal policies and optimal value function}\nSolving a \\textbf{reinforcement learning} problem is finding a policy that gets a lot of reward. The best possible policy is called the \\textbf{optimal policy}, the value-state function of this policy is the \\textbf{optimal state-value function} $v_*(s)=\\max_{\\pi}v_\\pi(s)$. And the action-value function is the \\textbf{optimal value-state function} $q_*(s, a)= \\max_{\\pi} q_\\pi (s, a)$ \n\n\\begin{equation}\n\\begin{split}\nv_* \n& = \\max_a q_\\pi (s, a) \\\\\n& = \\max_a \\EX\\left[ G_t | S_t=a, A_t=a \\right] \\\\\n& = \\max_a \\EX\\left[ R_{t+1} + \\gamma G_t | S_t=a, A_t=a \\right] \\\\\n& = \\max_a \\EX\\left[ R_{t+1} + \\gamma V_*(S_{t+1}) | S_t=a, A_t=a \\right] \\\\\n& = \\max_a \\sum_{s}p(s', r | a, s) [r+ \\gamma V_*(s')] \\\\\n\\end{split}\n\\label{eq:bellman optimality equation state-value function derivation}\n\\end{equation}\n\nThe optimal state-value and action-value functions lead to \\textbf{the bellman optimality equations} equation~\\ref{eq:bellman optimality equation state-value function derivation} and equation~\\ref{eq:bellman optimality equation action-value function derivation}\n\n\\begin{equation}\n\\begin{split}\nq_*(s, a) \n& = \\EX\\left[ R_{t+1} + \\gamma \\max_{a'} q(S_{t+1},a') | S_t=s, A_t=a \\right] \\\\\n& = p(s' r | s, a)[ r + \\gamma \\max_{a'} q(s', a)]\n\\end{split}\n\\label{eq:bellman optimality equation action-value function derivation}\n\\end{equation}\n\n\\section{Exercises}\n\n\\subsection{Exercise 3.1}\nA Robot in a maze has a delayed reward, and needs to make a sequence of decisions. The position of the robot in the maze is the state, and the input is the decisions left/right/straight ahead. The reward is -1 until the absorbing state, which has a reward of zero.\n\nA automatic poker player can be a mdp, the state is the current cards in the hand and the table. ", "meta": {"hexsha": "289a0c3b1855abba4a25ff2e06397e8cff892772", "size": 4858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RL/notes/TeX_files/chapter03.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/chapter03.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/chapter03.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": 42.6140350877, "max_line_length": 387, "alphanum_fraction": 0.6902017291, "num_tokens": 1620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059560743421, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.6538856660761665}}
{"text": "\\section{A Generative Model for Bayesian Sequence Combination}\\label{sec:model}\n%TODO do we state the obvious: that the annotator models effectively weight good annotators more heavily and discard spammers?\n%The generative story for our approach,\nTo construct a generative model for \\emph{Bayesian sequence combination (BSC)}, \nwe first define a hidden Markov model (HMM)\nwith states $t_{n,\\tau}$ and observations $x_{n,\\tau}$\nusing categorical distributions:\n\\begin{flalign}\nt_{n,\\tau} & \\sim \\mathrm{Cat}(\\bs T_{t_{n,\\tau-1}}), \\\\\nx_{n,\\tau} & \\sim \\mathrm{Cat}(\\bs\\rho_{t_{n,\\tau}}), \n\\end{flalign}\nwhere $\\bs T_j$ is a row of a transition matrix $\\bs T$, and $\\bs\\rho_j$ \nis a vector of observation likelihoods for state $j$.\nFor text tagging, $n$ indicates a document and $\\tau$ a token index, while\neach state $t_{n,\\tau}$ is a true sequence label\nand $x_{n,\\tau}$ is a token.\nTo provide a Bayesian treatment, we assume that \n$\\bs T_j$ and $\\bs\\rho_j$ have Dirichlet distribution priors as follows:\n\\begin{flalign}\nT_j & \\sim \\mathrm{Dir}(\\bs \\gamma_j), \\hspace{1.0cm}\n\\bs\\rho_j \\sim \\mathrm{Dir}(\\bs \\kappa_j), &\n\\end{flalign}\nwhere $\\bs \\gamma_j$ and $\\bs \\kappa_j$ are hyperparameters.\n\nNext, we assume one of the annotator \nmodels described in Section \\ref{sec:annomodels} for each of $K$ annotators.\nSelecting an annotator model is a design choice,\nand all can be coupled with the Bayesian HMM above to form\na complete BSC model. In our\nexperiments in Section \\ref{sec:expts_all}, \nwe compare different choices of annotator model as components of BSC.\n%We draw the parameters of the annotator models as follows:\n%%The number of parameters depends on the choice of annotator model:\n%%( t_{\\tau}, c_{\\tau}, c_{\\tau-1})$.\n%for \\emph{acc}, only one parameter, $\\pi^{(k)}$, is drawn per annotator $k$;\n%for \\emph{MACE}, we draw a single value $\\pi^{(k)}$ and a vector $\\xi^{(k)}$ of length $J$, \n%while for \\emph{CV} we draw $J$ independent values of $\\pi_j^{(k)}$, \n%and for \\emph{CM}  \n%we draw a vector $\\bs\\pi^{(k)}_j$ of size $J$ for each true label value $j\\in \\{1,...,J\\}$; in the case of \\emph{seq}, \n%we draw vectors $\\bs\\pi^{(k)}_{j,\\iota}$ for each true label value \n%for each previous label value, $\\iota$.\\\nAll the parameters of these annotator models are probabilities,\nso to provide a Bayesian treatment, we assume that they have Dirichlet priors. \nFor annotator $k$'s annotator model, we refer to the hyperparameters\nof its Dirichlet prior as $\\bs\\alpha^{(k)}$.\n%As shown in Section \\ref{sec:annomodels}, \nThe annotator model defines a categorical likelihood\nover each annotation, $\\bs c^{(k)}_{n,\\tau}$:\n%$A^{(k)}(t_{n,\\tau}, \\bs c^{(k)}_{n,\\tau}, \\bs c^{(k)}_{n,\\tau-1})$, where $\\bs c^{(k)}_{n,\\tau}$ is the $\\tau$th label of document $n$.\n%%The argument $\\bs c_{n,\\tau-1}$ is only required if $A^{(k)}$ is an instance\n%%of \\emph{seq} and is ignored by the other annotator models.\n%We draw annotator $k$'s label $c^{(k)}_{n,\\tau}$ \n%for each token $\\tau$ in each document $n$ \n%according to a categorical distribution:\n\\begin{flalign}\n& c^{(k)}_{n,\\tau} \\sim \\mathrm{Cat}( [A^{(k)}(t_{n,\\tau}, 1, \\bs c_{n,\\tau-1}^{(k)}), ..., & \\nonumber \\\\\n& \\hspace{3cm} A^{(k)}(t_{n,\\tau}, J, \\bs c_{n,\\tau-1}^{(k)}) ]). &\n\\end{flalign}\n\nThe annotators are assumed to be conditionally independent of one another given the true labels,\n$\\bs t$, which means that their errors are assumed to be uncorrelated. This is a strong assumption\nwhen considering that the annotators have to make their decisions based\non the same input data. However, in practice, dependencies do not usually cause the \nmost probable label to change~\\citep{zhang2004optimality}, hence the performance of classifier combination methods \nis only slightly degraded, while avoiding the complexity of modelling dependencies between annotators~\\citep{kim2012bayesian}.\n%\n% \\textbf{Black-box Sequence Taggers}:\n% As an extension to our model, we can integrate $S$ automated methods as\n% additional noisy annotators. \n%  In comparison to human annotators,\n% sequence taggers can quickly label large numbers of documents, \n% providing a cheap source of additional annotations across the whole dataset.\n% We model each sequence tagger, $s$, \n% using an annotator model, $B^{(s)}$,\n% of one of the types described in Section \\ref{sec:annomodels} (analogous to $A^{(k)}$ for a human annotator),\n% with hyperparameters $\\bs \\beta^{(s)}$.\n%\n% We extend the generative model for BSC with additional steps as follows.\n% Each sequence tagger generates a sequence of labels, $\\bs d_{n}^{(s)}$, for each document $n$ \n% (analogous to $\\bs c_n^{(k)}$ produced by human annotators)\n%  according to: \n%  \\begin{flalign}\n%  & d_{n,\\tau}^{(s)} \\sim \\mathrm{Cat}(\n% [B^{(s)}(\\bs t_{n,\\tau}, 1, d_{n,\\tau-1}^{(s)}), ..., && \\nonumber \\\\\n% & \\hspace{3.0cm} B^{(s)}(\\bs t_{n,\\tau}, J, d_{n,\\tau-1}^{(s)})]). &&\n% \\end{flalign}\n%\n% In the generative model, we draw a sequence of text tokens, $\\bs x_n$, \n% from a likelihood, $p \\left(\\bs x_n | \\bs d_{n}^{(s)}, \\bs\\theta^{(s)} \\right) $,\n%  given internal parameters, $\\bs\\theta^{(s)}$, and\n% label sequence, $\\bs d_{n}^{(s)}$.\n% This likelihood is defined by the black-box sequence tagger.\n% If the sequence tagger is Bayesian, its parameters, $\\bs\\theta^{(s)}$, may also be drawn from \n% an unknown prior distribution.\n% However, since we are treating the tagger as a black box, we do not need to know these internal details.\n% In the next section, we explain how we can avoid computing this likelihood explicitly during inference,\n% and instead use only the sequence tagger's existing training and prediction functions to learn\n% $\\bs\\theta^{(s)}$ in parallel with the parameters of the BSC model.\n% Like the human annotators, each sequence tagger is assumed to produce labels that are conditionally independent \n% of the other sequence taggers given $\\bs t$. \n% %Due to the fact that sequence taggers will typically use\n% %the same features, i.e. the text of the documents, this independence assumption may be violated, \n% %yet\n% %%as with the human annotators, \n% %this assumption in other models\n% % has been shown not to hamper performance in \n% %many practical situations~\\citep{zhang2004optimality}.\n\n\\textbf{Joint distribution}: the complete model can be represented by the\njoint distribution, given by:\n\\begin{flalign}\n& p(\\bs t, \\bs A, \\bs T, \\bs\\rho, \\bs c, \\bs x | \\bs \\alpha^{(1)},..., \\bs \\alpha^{(K)}, \\bs\\gamma,\n\\bs \\kappa ) &  \\\\\n%  & \\approx q(\\bs t, \\bs A, \\bs B, \\bs\\A^{(1)},...,\\bs\\A^{(K)},\\bs\\A^{(1)},...,\\bs\\A^{(S)}, \\bs d^{(1)}, ...,\\bs d^{(S)}) = q(\\bs B) \\prod_{n=1}^N q(\\bs t_n) & \\nonumber \\\\\n& = \\prod_{k=1}^K \\left\\{ p(A^{(k)} | \\bs \\alpha^{(k)}) \\prod_{n=1}^N p(\\bs c_n^{(k)} | A^{(k)}, \\bs t)  \\right\\}\n& \\nonumber \\\\\n&  \\prod_{n=1}^N \\prod_{\\tau=1}^{L_n} p(t_{n,\\tau} | \\bs T_{t_{n,\\tau-1}}) p(x_{n,\\tau} | t_{n,\\tau}, \\bs\\rho_{t_{n,\\tau}}) & \\nonumber \\\\\n& \\prod_{j=1}^J p(\\bs T_j | \\bs\\gamma_j) p(\\bs\\rho_j | \\bs\\kappa_j)&\n%\\prod_{s=1}^S \\bigg\\{ p(\\bs \\theta^{(s)})  \\nonumber \\\\\n%& p(B^{(s)} | \\bs\\beta^{(s)}) \\! \\! \\prod_{n=1}^N \\!\\! \\left\\{ p(\\bs x | \\bs d^{(s)}, \\bs \\theta^{(s)}) p(\\bs d^{(s)} | B^{(s)}, \\bs t)  \\right\\} \\!\\! \\bigg\\}, \\nonumber\n& \\label{eq:joint}\n\\end{flalign}\nwhere \n$\\bs c$ is the set of annotations for all documents from all annotators,\n$\\bs t$ is the set of all sequence labels for all documents,\n$N$ is the number of documents, \n$L_n$ is the length of the $n$th document, \n$J$ is the number of classes,\n $\\bs x$ is the set of all word sequences for all documents and\n$\\bs\\rho$, $\\bs\\gamma$ and $\\bs\\kappa$ are the sets of parameters for all\nlabel classes.\n %=\\{\\bs c^{(1)}, .., \\bs c^{(K)} \\}$,\n%\n%Terms distribution omit subscripts and superscripts are the sets of  parameters for all values of the omitted index.\n\n%\\begin{flalign}\n%& \n%=\n%p\\left(d_{n,\\tau}^{(s)} | \\bs t, d_{n,\\tau-1}^{(s)}, A^{(s)} \\right) & \\nonumber\\\\\n%& p \\left(d_{n,\\tau}^{(s)} | \\bs\\phi_n, \\bs\\theta^{(s)} \\right) / p \\left(d_{n,\\tau}^{(s)} | \\bs\\theta^{(s)} \\right),  & \n%\\end{flalign}\n%% Imagine what happens for each of the different combinations of values of d. We could train a squillion different sequence taggers on these, then take a weighted sum.\n%\n%% multiply by p(phi | theta) to get joint, divide by p(d) to get likelihood of phi given d, then since phi is independent of t and A,  p(phi | theta) cancels out. This follows from the generative model, which should be described here. The inference section should \n%% talk about learning theta, and computing the expectation of d.\n%%We could avoid all this if the sequence tagger just learns to represent the left hand side. So t and A stay in the condition for the likelihood of the features. In which case, the first term on the right hand side is like a prior that needs to be\n%% used when learning theta.\n%where the first term on the right-hand side is defined by the annotator model\n%with parameters $A^{(s)}$, and \n%of the sequence tagger, $s$.\n%integrating existing sequence taggers using the learning\n%procedure described in the next section.\n", "meta": {"hexsha": "2a27300e9a166b3f2de4d73c690f12dd02d22571", "size": 9055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/sections/bsc_model.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/bsc_model.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/bsc_model.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": 59.1830065359, "max_line_length": 265, "alphanum_fraction": 0.6840419658, "num_tokens": 2878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.6537754841526153}}
{"text": "\n\\subsection{Commutation of Lie groups}\n\nWe can measure commutation of Lie groups using:\n\n\\(ABA^{-1}B^{-1}\\)\n\nIf the group commutes then:\n\n\\(ABA^{-1}B^{-1}=BA^{-1}B^{-1}=I\\)\n\n\\subsubsection{Commutation of Lie algebra: COMPLETE THIS}\n\nThis corresponds to \\([A,B]=AB-BA\\) in the underlying lie algebra, if we expand.\n\n\\(A=e^{ta}\\)\n\n\\(B=e^{tb}\\)\n\n\\(ABA^{-1}B^{-1}=e\\)\n\n", "meta": {"hexsha": "9d9948ec5b40dcd889d183c7773e8320a922e8c1", "size": 366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/representation/04-03-commutation.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-03-commutation.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-03-commutation.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.6363636364, "max_line_length": 80, "alphanum_fraction": 0.6338797814, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.7057850216484839, "lm_q1q2_score": 0.6537712925950239}}
{"text": "\\documentclass{article}\n\n\\usepackage[english]{babel}\n\\usepackage{naproche}\n\n\\begin{document}\n  \\pagenumbering{gobble}\n\n  \\section*{Cantor's Theorem}\n\n  Let us prove that every set is strictly smaller than ist powerset.\n  This result is known as \\textit{Cantor's Theorem}.\n\n  \\begin{forthel}\n    \\begin{theorem}[Cantor]\n      Let $x$ be a set.\n      There is no surjection from $x$ onto the powerset of $x$.\n    \\end{theorem}\n\n    \\begin{proof}\n      Proof by case analysis.\n\n      Case $x$ is empty. Obvious.\n\n      Case $x$ is nonempty.\n        Assume the contrary.\n        Take a surjection $f$ from $x$ onto the powerset of $x$.\n\n        Define $N = \\{ u \"in\" x : u \"is not an element of\" f(u) \\}$.\n\n        Take an element $u$ of $x$ such that $N = f(u)$.\n\n        Indeed we can show that $N$ is an element of the powerset of $x$.\n          Every element of $N$ is an element of $x$.\n          Hence $N$ is a subset of $x$.\n          Thus $N$ is an element of the powerset of $x$.\n        End.\n\n        Then we have a contradiction.\n      End.\n    \\end{proof}\n  \\end{forthel}\n\\end{document}\n", "meta": {"hexsha": "41d039cb09b3db61a43b96e3c403159b5ac35ae0", "size": 1095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/latex-forthel.ftl.tex", "max_stars_repo_name": "McEarl/language-forthel", "max_stars_repo_head_hexsha": "8c0a458fcbd094d28122ff6079a88292e7a79ecb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-26T10:11:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-26T10:11:36.000Z", "max_issues_repo_path": "examples/latex-forthel.ftl.tex", "max_issues_repo_name": "McEarl/language-ftl", "max_issues_repo_head_hexsha": "8c0a458fcbd094d28122ff6079a88292e7a79ecb", "max_issues_repo_licenses": ["MIT"], "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/latex-forthel.ftl.tex", "max_forks_repo_name": "McEarl/language-ftl", "max_forks_repo_head_hexsha": "8c0a458fcbd094d28122ff6079a88292e7a79ecb", "max_forks_repo_licenses": ["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.8863636364, "max_line_length": 73, "alphanum_fraction": 0.602739726, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571775, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6536960303552027}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{maria}\n\n\\title{Summations \\\\ \\small{Red Group, MOP 2013}}\n\n\\author{Maria Monks}\n\\date{June 6, 2013}\n\n\n\\begin{document}\n\n\\maketitle{}\n\n\\section*{Some summation techniques}\n\n\\begin{itemize}\n\\item \\textbf{Telescoping sums:}\nSuppose we want to evaluate the sum $a_1+a_2+\\cdots+a_n$, and we can write each $a_i$ as $b_i-b_{i+1}$ for some collection of numbers $b_i$.  Then all the $b_i$'s cancel except for $b_1$ and $b_{n+1}$, and we are left with $b_1-b_{n+1}$.\n\nFor instance, we can evaluate the sum $1+3+5+\\cdots+(2k-1)$ by writing the $i$th odd number as $i^2-(i-1)^2$, obtaining the sum: $$(1^2-0^2)+(2^2-1^2)+(3^2-2^2)+\\cdots+(k^2-(k-1)^2)=k^2-0^2=k^2.$$\n\n%Telescoping products, such as $\\frac{1}{2}\\cdot \\frac{2}{3} \\cdot \\frac{3}{4} \\cdot\\cdots\\cdot \\frac{n-1}{n}$, are useful in the same manner.\n\n\\item \\textbf{Induction:} For finite sums, it's often possible to just guess the answer and then prove your guess by induction.\n\n\\item \\textbf{Solve for the sum:} Let $S$ be the sum you wish to find, manipulate $S$ in order to simplify the sum, and finally solve for $S$.  For instance, to evaluate the infinite sum $$S=\\sum_{j=0}^\\infty\\frac{j^2}{2^j},$$ we might consider multiplying by $2$ to shift the indices.  We have  $$2(S-1)=\\sum_{j=1}^\\infty \\frac{j^2}{2^{j-1}}=\\sum_{j=0}^\\infty \\frac{(j+1)^2}{2^j}$$  Subtracting $S$ from this, we find $2(S-1)-S=\\sum_{j=0}^{\\infty} \\frac{2j+1}{2^{j}}$.  So far, we have reduced the $j^2$ to a $2j+1$ in the numerator.  Can you finish it from here?\n\n\\item \\textbf{Generating functions:}  It can be useful to consider the sum as a coefficient in a generating function, especially in the following circumstances:\n\\begin{itemize}\n\\item \\textbf{Partial sums:} Say we want to find a formula for $1^2+2^2+\\cdots+n^2$.  First consider the generating function $S(x)=\\sum_{i=0}^\\infty n^2x^n$.  Now, if we divide by $1-x$, we get the partial sums as the coefficients of the new generating function: $$\\frac{S(x)}{(1-x)}=\\sum_{i=0}^\\infty (1^2+2^2+\\cdots+n^2)x^n.$$  So, we just need to find the coefficient of $x^n$ in $\\frac{S(x)}{(1-x)}$, which equals $\\frac{x^2+x^4}{(1-x)^4}$ (why?).  We expand $(1-x)^{-4}$ using the \\textit{extended binomial theorem}:\n\n\\begin{eqnarray*}\n\\frac{1}{(1-x)^4} &=& \\sum_{n=0}^\\infty (-1)^n\\binom{-4}{n}x^n \\\\\n&=&\\sum (-1)^n\\frac{(-4)(-5)(-6)\\cdots(-4-n+1)}{n!}x^n \\\\\n     &=& \\sum \\frac{4\\cdot 5\\cdot \\cdots\\cdot (n+3)}{n!} x^n \\\\\n     &=& \\sum \\frac{n(n+1)(n+2)}{6}x^n\n\\end{eqnarray*}\n\nMultiplying this by $x+x^2$, the coefficient of $n$ in the result is $$\\frac{(n-1)n(n+1)}{6}+\\frac{n(n+1)(n+2)}{6}=\\frac{n(n+1)(2n+1)}{6},$$ as desired.\n\n\\item \\textbf{Convolutions:}  Sums of the form $$a_0b_n+a_1b_{n-1}+\\cdots+a_nb_0$$ are called \\textit{convolutions}, and they should alert your generating function radar.  Setting $F(x)=\\sum a_nx^n$ and $G(x)=\\sum b_nx^n$, this convolution is the coefficient of $x^n$ in $F(x)\\cdot G(x)$.\n\nCan you use this idea to compute $\\sum_{i=0}^n i(n-i)$?\n\n\\end{itemize}\n\n\\end{itemize}\n\n\\section*{Problems}\n\n\\begin{enumerate}\n\n\n\\item Evaluate the sum $\\sum_{i=0}^n i(n-i)$ using several different summation techniques.  Be creative!\n%The answer turns out to be n(n^2-1)/6.  This is a good one.\n\n\\item Evaluate the sum $\\sum_{k=1}^n \\frac{k}{(k+1)!}$.\n%Easily telescopes, or also by induction it turns out to be $1-\\frac{1}{(n+1)!}$\n\n\\item Evaluate the sum $\\sum_{k=1}^n k\\cdot k!$.\n\n\\item (Brazilian Math Olympiad 2002.)  For a nonempty subset $A$ of $\\{1,2,\\ldots,n\\}$ define $f(A)$ as the largest element of $A$ minus the smallest element of $A$.  Find $\\sum f(A)$ where the sum is taken over all nonempty subsets $A$ of $\\{1,2,\\ldots,n\\}$.\n%Turns out to be (n-3)*2^n+n+3.  Do this by summing the values of all the min and max values separately: each i is the max for 2^{i-1} subsets, etc.\n\n\\item Evaluate the sum $\\sum_{k=1}^n (-1)^{\\frac{k(k+1)}{2}} k$.\n% The answer turns out to be 0 when n is 3 mod 4, and the others are easily determined.  (You can prove the former by induction.)\n\n\\item (IMO Longlist 1978.)  Evaluate the sum $$1\\cdot 2\\cdot 3+2\\cdot 3\\cdot 4+\\cdots+97\\cdot 98\\cdot 99.$$  (Bonus: What happens if we divide by $3!$ and think of the terms as binomial coefficients?)\n%This turns out to be $97*98*99*100/4$, because of the hockey stick identity.  You can also do this by making each term $i(i-1)(i+1)$ and summing $i^3-i$, but this doesn't turn out as nicely in the formula in the end.\n\n\\item Find a closed formula for $\\frac{1}{1\\cdot 2 \\cdot 3}+\\frac{1}{2\\cdot 3 \\cdot 4}+\\cdots+\\frac{1}{n\\cdot (n+1) \\cdot (n+2)}.$\n%%1/4 of n(n+3)/(n+1)(n+2), nicely enough.  Either: 1/1*(1/2-1/3)+1/2*(1/3-1/4)+... and it reduces to 2 products case, or: telescope by making it 1/(2n(n+1))-1/(2(n-1)n).  \n\n\\item (Art and Craft of Problem Solving.)  A 2-inch elastic band is fastened to the wall at one end, and there's a bug at the other end.  Every minute (beginning at time 0), the band is instantaneously and uniformly stretched by 1 inch, and then the bug walks 1 inch toward the fastened end.  Will the bug ever reach the wall?\n%Yep!  It's a harmonic series thing.  Just record the percent along the band that the bug is at at each step.  The ratio starts at 1 and decreases by 1/3, 1/4, 1/5, ... so eventually the ratio will be less than 0, at which point he has reached the wall.\n\n\\item In all of the following, let $F_n$ be the $n$th Fibonacci number, where $F_0=0,F_1=1$, and $F_{n+2}=F_n+F_{n+1}$ for all $n\\ge 0$.\n\\begin{enumerate}\n\\item Evaluate $\\sum_{n=0}^\\infty \\frac{F_n}{F_{n+1}\\cdot F_{n+2}}$.\n%This telescopes because each term is equal to $1/F_{n+1}-1/F_{n+2}$.  We are left with $1/F_1=1$.\n\\item Evaluate $\\sum_{n=1}^\\infty \\frac{F_{n+1}}{F_n\\cdot F_{n+2}}$.\n%Also telescopes, but now we have a jumping thing so it's $1/1+1/1=2$.\n\\item Evaluate $\\sum_{n=1}^\\infty \\frac{1}{F_n\\cdot F_{n+2}}$.\n%Telescope this guy by showing that the nth term equals $1/(F_n*F_{n+1})-1/(F_{n+1}*F_{n+2})$.\n\\item Show that $\\sum_{k=0}^n F_k=F_{n+2}-1$.\n%Induction works just fine here\n\\item Show that $\\sum_{k=0}^n F_k^2=F_n\\cdot F_{n+1}$.\n%Also induction.\n\\end{enumerate}\n\n\\item (Canada 1989.)  Given the numbers $1,2,2^2,\\ldots,2^{n-1}$, for a specific permutation $\\sigma=x_1,x_2,\\ldots,x_n$ of these numbers we define $$S_i(\\sigma)=x_1+x_2+\\cdots+x_i$$ for each $i=1,2,\\ldots,n$.  Define $Q(\\sigma)=S_1(\\sigma)S_2(\\sigma)\\cdots S_n(\\sigma)$.  Evaluate $\\sum 1/Q(\\sigma)$ where the sum is taken over all possible permutations.\n%The answer is 1/2^{n choose 2}.  Basically, you can show by induction that you can group them according to the last factors in the denominators.  You can always factor out a 1/S_n=1/(1+2+...+2^{n-1}), and then to sum what is left, group it by the next largest term, namely the $S_{n-1}(\\sigma)$'s.  Use strong induction to show that these sum corresponding to a fixed $S_{n-1}(\\sigma)$ turn out to be one over the product of the terms in the sum $S_{n-1}(\\sigma)$.  Then in the end we add up all these sums, weighted by 1/S_n, and we get S_n/((product of terms in S_n)*S_n)=1/(1*2*4*...*2^{n-1})=1/2^{n choose 2}.\n\n\\item (Ukraine.) Show that $$\\frac{1}{\\sqrt{1}+\\sqrt{3}}+\\frac{1}{\\sqrt{5}+\\sqrt{7}}+\\cdots+\\frac{1}{\\sqrt{9997}+\\sqrt{9999}}>24.$$\n%Add in the terms $1/(sqrt(3)+sqrt(5))$ etc, which at most doubles the LHS, and then rationalize denominators.  The sum now telescopes, and you can check that the resulting term is greater than 48.\n\n\\item (IMO 1996.)  Show that $$\\frac{1}{\\sin 2x}+\\frac{1}{\\sin 4x}+\\cdots+\\frac{1}{\\sin 2^nx}=\\cot x-\\cot 2^nx.$$\n%It turns out that 1/sin(2x)=cot(x)-cot(2x) and so the sum telescopes.\n\n\\item (Math Olympiad Challenges.) Prove the identity $$\\sum_{k=1}^n \\tan^{-1}\\frac{1}{2k^2}=\\tan^{-1}\\frac{n}{n+1}$$\n%By inverse of tan subtraction formula, show that the kth term is $\\tan^{-1}(2k+1)-\\tan^{-1}(2k-1)$ and the sum now telescopes.  Then use tan subtraction again at the end.\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "34ce33770ee2cf165c47b618bbe33951708e226d", "size": 7940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "data_loading/data/olympiads_tex_converted/red-summations.tex", "max_stars_repo_name": "zhukeepa/mathorg", "max_stars_repo_head_hexsha": "975c275e3ba24af2772563e6f89f0469c3ccde3b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-09T10:45:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-14T08:23:56.000Z", "max_issues_repo_path": "data_loading/data/olympiads_tex_converted/red-summations.tex", "max_issues_repo_name": "zhukeepa/mathorg", "max_issues_repo_head_hexsha": "975c275e3ba24af2772563e6f89f0469c3ccde3b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-08-30T05:09:02.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-30T05:26:08.000Z", "max_forks_repo_path": "data_loading/data/olympiads_tex_converted/red-summations.tex", "max_forks_repo_name": "zhukeepa/mathorg", "max_forks_repo_head_hexsha": "975c275e3ba24af2772563e6f89f0469c3ccde3b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-06T23:10:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-20T04:21:26.000Z", "avg_line_length": 74.9056603774, "max_line_length": 614, "alphanum_fraction": 0.6701511335, "num_tokens": 2946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.653696027203423}}
{"text": "%!TEX root = TTK4215-Summary.tex\n\\section{Parameter estimation}\n\n\\subsection{SPR Lyapunov method}\nBased on choosing an adaptive law so that a \\emph{Lyapunov-like} function guarantees $\\tilde{\\theta} \\rightarrow 0$. The parametric model $z = W(s) \\theta^{*\\T} \\psi$ is rewritten $z = W(s) L(s) \\theta^{*\\T} \\phi$, with $L(s)$ a proper stable t.f., and $W(s)L(s)$ a proper SPR t.f.\n\n\\begin{gather}\n\tz = W(s) L(s) \\theta^{*\\T} \\phi \\\\\n\t\\hat{z} = W(s)L(s) \\theta\\T \\phi \\\\\n\t\\epsilon = z - \\hat{z} - W(s) L(s) \\epsilon n_s^2 \\\\\n\t\\dot{\\theta} = \\Gamma \\epsilon \\phi\n\\end{gather}\n\n\\subsection{Gradient method}\n\\begin{gather}\n\tz = \\theta^{*\\T} \\phi \\\\\n\t\\hat{z} = \\theta\\T \\phi \\\\\n\t\\epsilon = \\frac{z - \\hat{z}}{m^2}\n\\end{gather}\n\n\\subsubsection{Instantaneous cost}\n\\begin{gather}\n\t\\dot{\\theta} = \\Gamma \\epsilon \\phi\n\\end{gather}\n\n\\subsubsection{Integral cost}\n\\begin{gather}\n\t\\dot{\\theta} = - \\Gamma (R \\theta + Q) \\\\\n\t\\dot{R} = - \\beta R + \\frac{\\phi \\phi\\T}{m^2} \\\\\n\t\\dot{Q} = - \\beta Q - \\frac{z \\phi}{m^2}\n\\end{gather}\n\n\\subsection{With projection}\n\\begin{gather}\n\t\\dot{\\theta} =\n\t\\begin{cases}\n\t\t\\Gamma \\epsilon \\phi & \\mbox{if } \\theta \\in \\mathcal{S}^0 \\\\\n\t\t\\Gamma \\epsilon \\phi - \\Gamma \\frac{\\nabla g \\nabla g\\T}{\\nabla g\\T \\Gamma \\nabla g} \\Gamma \\epsilon \\phi & \\mbox{otherwise}\n\t\\end{cases}\n\\end{gather}\n\n\\subsection{Least squares}\n\\begin{gather}\n\tz = \\theta^{*\\T} \\phi \\\\\n\t\\hat{z} = \\theta\\T \\phi \\\\\n\t\\epsilon = \\frac{z - \\hat{z}}{m^2}\n\\end{gather}\n\n\\subsubsection{Pure least squares}\n\\begin{gather}\n\t\\dot{\\theta} = P \\epsilon \\phi \\\\\n\t\\dot{P} = - P \\frac{\\phi \\phi\\T}{m^2} P\n\\end{gather}\n\n\\subsubsection{With covariance resetting}\n\\begin{gather}\n\t\\dot{\\theta} = P \\epsilon \\phi \\\\\n\t\\dot{P} = - P \\frac{\\phi \\phi\\T}{m^2} P, \\quad P(t_r^+) = P_0 = \\rho_0 I\n\\end{gather}\n\n\\subsubsection{With forgetting}\n\\begin{gather}\n\t\\dot{\\theta} = P \\epsilon \\phi \\\\\n\t\\dot{P} =\n\t\\begin{cases}\n\t\t\\beta P - P \\frac{\\phi \\phi\\T}{m^2} P & \\mbox{if } ||P(t)|| \\leq R_0 \\\\\n\t\t0                                     & \\mbox{otherwise}\n\t\\end{cases}\n\\end{gather}", "meta": {"hexsha": "7a1cb12ef49b3bf8dbc992b445542d1d43a409a0", "size": 2042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4215 System identification and adaptive control/sec-estimators.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-estimators.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-estimators.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5942028986, "max_line_length": 281, "alphanum_fraction": 0.6043095005, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326727, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6536671291487507}}
{"text": "\\section{Surrogate Loss Function}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{Surrogate Loss Fn: Intro}\n\nWHAT:\\\\\nhandle some \\textbf{non}convex problems\nby minimizing ``surrogate'' loss functions that are \\text{convex}\n\\vspace{4mm}\n\nWHY:\\\\\nthe natural loss function is not convex, e.g.  $0-1$ loss\n\\vspace{4mm}\n\nHOW:\\\\\nto upper bound the nonconvex loss function by a convex surrogate loss function\nthat\n\\begin{itemize}\n    \\item are convex\n    \\item upper bounds the original loss.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Surrogate Loss Fn: Example}\nIn the context of learning halfspaces:\\\\\nHinge loss as a convex surrogate for the $0-1$ loss\n\\footnote{{\\tiny https://scicomp.stackexchange.com/questions/5628/confusion-related-to-convexity-of-0-1-loss-function}}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{eq_hinge_loss}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{fig_surr_fn}\n\\end{figure}\n\n\\end{frame}\n\n\n\n", "meta": {"hexsha": "204fc9a214756e54890844ce89ffd199ebf19a84", "size": 1020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/cvx-sgd-20180316/surrogate.tex", "max_stars_repo_name": "tttor/robot-foundation", "max_stars_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk/tor/cvx-sgd-20180316/surrogate.tex", "max_issues_repo_name": "tttor/robot-foundation", "max_issues_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk/tor/cvx-sgd-20180316/surrogate.tex", "max_forks_repo_name": "tttor/robot-foundation", "max_forks_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6666666667, "max_line_length": 119, "alphanum_fraction": 0.7480392157, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6536671288081982}}
{"text": "\\subsection{EXAFS: $\\chi(k)$}\n\\begin{frame} \\frametitle{EXAFS: $\\chi(k)$}\n    \n  XAFS is an {\\RedEmph{interference effect}}, and depends on the\n  wave-nature of the photo-electron.  We express the XAFS in terms of\n  {\\RedEmph{photo-electron wavenumber}}, $k$:\n  \n  \\begin{center}$ k= \\sqrt{\\frac{2m(E-E_0)}{\\hbar^2}} $\\end{center}\n   \n    \n  The XAFS dampens quickly with $k$, so $\\chi(k)$ is often\n  shown weighted by ${k^2}$ or ${k^3}$:\n\n    \\begin{center}\n      \\begin{tabular}{lr}\n        \\begin{minipage}{48mm}\n          {\\wgraph{48mm}{general/feo_chi}}\n        \\end{minipage}\n        &\n        \\begin{minipage}{48mm}\n          \\wgraph{48mm}{general/feo_chik}\n        \\end{minipage}\n      \\end{tabular}\n    \\end{center}\n\n%   We can model the EXAFS with the {\\BlueEmph{EXAFS Equation}}:\n%   \\vmm\n\n%   \\begin{center}\n%   \\highlightbox{\n%     \\begin{minipage}{70mm}\n%       \\[\n%       \\chi(k) = \\sum_j { {\\frac{N_j f_j(k) e^{-2k^2\\sigma_j^2}}\n%           {kR_j^2}} \\sin\\bigl[ 2kR_j  +  \\delta_j(k) \\bigr] }\n%       \\]\n%     \\end{minipage}\n%     }\n%     \\end{center}\n  \n\\end{frame} \n\n", "meta": {"hexsha": "06b684d6025990a3d46efba14a08089000d58dfe", "size": 1085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/intro_wave_k.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/intro_wave_k.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/intro_wave_k.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": 25.8333333333, "max_line_length": 69, "alphanum_fraction": 0.5594470046, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6536671078614146}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 17, 2022}\n\\subsection{Special Integers}\n\\subsubsection{Fermat and Mersenne Primes}\nWe make the observation that many small primes are of the form $2^m\\pm 1$ for some natural number m, for example\n\\[3, 5, 7, 17, 31\\]\nWe deal with the $+1$ and $-1$ cases separately.\n\\begin{lemma}\n\tIf $2^m + 1$ is prime, then $m = 2^n$ for some $n\\geq 0$.\n\\end{lemma}\n\\begin{proof}\n\tWe show the contrapositive. Suppose $m$ is not a power of $2$. We write $m=2^n\\cdot q$ for some odd $q>1$.\n\n\tThe polynomial\n\t\\[f(t) = t^q + 1\\]\n\thas $t=-1$ as a root, so\n\t\\[f(t) = (t+1)g(t) \\quad \\text{where $\\deg f = q > 1$}\\]\n\tThus\n\t\\begin{align*}\n\t\tx^m+1 & = f(x^{2^n})                                   \\\\\n\t\t      & = (x^{2^n}+1)g(x^{2^n})\\text{ where $m > 2^n$}\n\t\\end{align*}\n\tPlugging in $x=2$ gives\n\t\\[2^{2^n}+1\\mid 2^m + 1, \\text{ and }2^{2^n}+1 < 2^m+1\\]\n\tso $2^m+1$ is not prime.\n\\end{proof}\n\\begin{definition}[Fermat Numbers]\n\tNumbers of the form $2^{2^n}+1$ are called \\ul{Fermat numbers}.\n\n\tFermat numbers that are prime are called \\ul{Fermat primes}.\n\\end{definition}\nThe first few Fermat numbers happen to be prime: $3, 5, 17, 257, 65537$.\n\n\\begin{conjecture*}\n\tFermat conjectured that Fermat numbers are prime.\n\\end{conjecture*}\nThis is very false! Euler found that\n\\[2^{2^5}+1 = 641\\times 6700417\\]\n\nWe now turn to Mersenne numbers.\n\n\\begin{lemma}\n\tIf $m>1$ and $a^m - 1$ is prime, then $a=2$ and $m$ is prime.\n\\end{lemma}\n\\begin{proof}\n\tSuppose $m$ is composite and, so $m=nk$, $1 < k, n < m$. Then\n\t\\begin{align*}\n\t\ta^m - 1 & = (a^k)^m - 1                        \\\\\n\t\t        & = (a^k - 1)(a^{k(n-1)} + \\cdots + 1)\n\t\\end{align*}\n\n\tThis implies that $a^m - 1$ is composite. Hence $m$ had better be prime.\n\n\tNow $a^m - 1 = (a-1)(a^{m-1} + \\cdots + 1)$, so we further have that $a = 2$.\n\\end{proof}\n\\begin{definition}[Mersenne Numbers]\n\tIntegers of the form $2^p - 1$ where $p$ is a prime are called \\ul{Mersenne numbers}.\n\n\tMersenne numbers that are prime are called \\ul{Mersenne primes}.\n\\end{definition}\nThere is a current ongoing search for more Mersenne primes on the internet. Currently, the largest known Mersenne prime (and largest known prime number) is\n\\[M(82,589,933)\\]\nThat is,\n\\[2^{82,589,933} - 1\\]\n\nMersenne primes are related to perfect numbers. There is a one-to-one correspondence with Mersenne primes and even perfect numbers.\n\\begin{definition}[Perfect Number]\n\t$n\\in\\ZZ_+$ is called \\ul{perfect} if\n\t\\[n = \\sum_{\\substack{d\\mid n \\\\ d < n}} d\\]\n\\end{definition}\n\\begin{example}\n\tWe have\n\t\\begin{align*}\n\t\t6  & = 1 + 2 + 3          \\\\\n\t\t28 & = 1 + 2 + 4 + 7 + 14\n\t\\end{align*}\n\\end{example}\n\\begin{proposition}\n\tIf $n^{2^{p-1}}(2^p - 1)$ where $p\\in \\ZZ_+$, and $p, 2^p - 1$ are prime, then $n$ is perfect.\n\\end{proposition}\n\\begin{proof}\n\tThe function $\\sigma(n) = \\sum_{d\\mid n} d$ is multiplicative. So if\n\t\\[n = 2^{p-1}(2^p - 1)\\]\n\tthen\n\t\\[\\sigma(n) = \\sigma(2^{p-1})\\sigma(2^p - 1).\\]\n\tsince they are coprime. Now we also\n\t\\begin{align*}\n\t\t\\sigma(2^{p-1}) & = \\frac{2^p - 1}{2 - 1} = 2^{p} - 1 \\\\\n\t\t\\sigma(2^p - 1) & = 1 + (2^p - 1) = 2^p\n\t\\end{align*}\n\tHence $\\sigma(n) = (2^{p-1})\\cdot 2^p = 2n$.\n\n\tSo $n$ is a perfect number.\n\\end{proof}\n\\begin{proposition}\n\tIf $n\\in \\ZZ_+$ is even and perfect, then $n = 2^{p-1}(2^p - 1)$ where $p$ and $2^p - 1$ are both prime.\n\\end{proposition}\n\\begin{proof}\n\t\\emph{This is a homework exercise!}\n\\end{proof}\n\nIt is currently conjectured that there are no odd perfect numbers.\n\n\\subsubsection{Pseudoprimes and Carmichael Numbers}\nHomework 2 includes a problem for which a special case is Wilson's Theorem.\n\\begin{theorem}[Wilson's Theorem]\n\tIf $p$ is a prime, then\n\t\\[(p-1)! \\equiv -1\\pmod{p}\\]\n\\end{theorem}\nThe converse is also true.\n\\begin{proposition}\n\tIf $n\\in\\ZZ_+$ where $n \\geq 2$ is such that\n\t\\begin{equation}\n\t\t(n-1)!\\equiv 1\\pmod{n} \\tag{$*$} \\label{eqn:wilson-converse}\n\t\\end{equation}\n\tthen $n$ is prime.\n\\end{proposition}\nWe can think of \\cref{eqn:wilson-converse} as a rudimentary `primality test'.\n\nHowever, this is not a great primality test, because factorials are expensive to compute.\n\nRecall Fermat's little theorem.\n\\begin{theorem}[Fermat's Little Theorem]\n\tIf $p\\in \\ZZ_+$ is a prime and $a\\in \\ZZ$, then\n\t\\[a^p\\equiv a\\mod{p}\\]\n\\end{theorem}\nThus $n\\in\\ZZ_+$ and\n\\[a^n\\equiv a\\mod n\\]\nfor some $a\\in \\ZZ_+$, then $n$ is composite.\n\\begin{example}\n\tIf $a = 2$, then\n\t\\[2^n\\not\\equiv 2\\mod n\\Rightarrow n=2 \\text{ is composite}\\]\n\\end{example}\n\\begin{ques*}\n\tWe might wonder whether a converse to this holds. Disappointingly, no.\n\\end{ques*}\n\n\\begin{example}\n\t$2^{10} = 1024 = 1\\pmod{341}$, so $2^{341} = (2^{10})^34\\cdot 2 = 2\\mod 341$.\n\n\tBut $341 = 11\\cdot 31$, so $341$ is composite.\n\\end{example}\n\\begin{definition}[Pseudoprime]\n\tWe call $n$ a \\ul{pseudoprime} to the \\ul{base $a$} if $n$ is composite and happens to satisfy\n\t\\[a^n\\equiv a\\mod n.\\]\n\\end{definition}\n\\begin{example}\n\t$341$ is a pseudoprime to the base $2$.\n\\end{example}\nWe might hope that if this test failed for a particular $a$, there exists some other $a$ that can test whether $n$ is composite. However, this is not the case.\\footnote{We learn in life to not be too hopeful.}\n\nIt is not true that given a composite $n$, there exists an $a\\in \\ZZ_+$ such that $n$ is not a pseudoprime to the base $a$.\n\\begin{definition}[Carmichael Numers]\n\t$n\\in \\ZZ_+$ is called a \\ul{Carmichael number} if $n$ is composite and\n\t\\[a^n\\equiv a\\mod n,\\quad \\forall a\\in \\ZZ\\]\n\\end{definition}\n\\begin{example}\n\tThe smallest Carmichael number is $561$.\n\\end{example}\n\\begin{ques*}\n\tThere are variants on this question? Can you have pseudoprimes that satisfy all but one base?\n\\end{ques*}\n\n\\begin{proposition}\n\tIf a composite number $n$ is \\emph{not} a Carmichael number, then at least half of the congruence classes $a\\in (\\ZZ/n\\ZZ)^\\times$ are such that $n$ is \\emph{not} a pseudoprime to the base $a$.\n\\end{proposition}\n\\begin{proof}\n\tSuppose $n$ is a pseudoprime to the base:\n\t\\[a_1, a_2, \\dots, a_r\\in (\\ZZ/n\\ZZ)^\\times\\]\n\tand suppose we have some $a$ such that\n\t\\[a^n \\not\\equiv a\\mod n\\]\n\tThen for all $i$,\n\t\\begin{align*}\n\t\t(a\\cdot a_i)^{n-1} & = a^{n-1}a_i^{n-1}   \\\\\n\t\t                   & \\equiv a^{n-1}\\mod n \\\\\n\t\t                   & \\not\\equiv 1\\mod n\n\t\\end{align*}\n\tThus $n$ is not a pseudoprime to the bases $a\\cdot a_1, a\\cdot a_2, \\dots, a\\cdot a_r$.\n\\end{proof}\n\\begin{remark}\n\tThe bases for pseudoprimes form a subgroup of the group of units.\n\\end{remark}\n\\todo{Someone check me on this.}", "meta": {"hexsha": "389b265a427f7ee51f55bd5405238f3216a33140", "size": 6474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-17.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-17.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-17.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": 35.3770491803, "max_line_length": 209, "alphanum_fraction": 0.6453506333, "num_tokens": 2440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.8902942144788077, "lm_q1q2_score": 0.6535823675351525}}
{"text": "\\chapter{Asymmetric-key cryptography}\n\\label{Asymmetric-key cryptography} % For referencing the chapter elsewhere, use \\ref{Chapter1} \n\n%----------------------------------------------------------------------------------------\n\n\\textit{Asymmetric-key} cryptography (also commonly referred to as \\textit{public-key} cryptography) is a system of cryptography which uses \\textit{pairs} of keys to \nencrypt and decrypt data. The pairs of keys consist of public keys which can be distributed, and private keys which are only known to the owner. Essentially,\nasymmetric-key cryptography allows us encrypt and decrypt data where the key for encryption is different than the key for decryption. Knowledge of either\nof these keys does not allow us to find the other one \\cite{classical_algebra}. The name comes from that fact that we use multiple keys in the process of encryption and decryption\nand therefore have \\textit{asymmetric} keys.\n\nSuppose, John and Mary want to securely communicate using the scheme above. First, John would produce a encryption key $K_1$ and a decryption key $K_2$. John \nwould then send Mary the encryption key $K_1$. Mary can now encrypt data using the key $K_1$ and send the result to John who can decrypt her data using his decryption key\n$K_2$. Let's now introduce Bob, who intercepts the transmission of the encryption key $K_1$. Bob can now encrypt messages using the key $K_1$ but is unable to decrypt \nthem---only John can decrypt messages as he is the only one who posses the decryption key $K_2$. If John also wants to send messages to Mary, Mary will have to create\nan encryption key $x$ and a decryption key $y$ and then send the encryption key $x$ to John. Now, John can encrypt his messages using the encryption key $x$ (sent by Mary)\nand then send the encrypted data to Mary where she will decrypt the message using the decryption key $y$. As you can see, in this scheme, we don't care if a third-party \n(such as Bob) gets a hold of one of the encryption keys---hence they could just be \\textit{public knowledge} \\cite{classical_algebra}. \n\n\\section{The Rivest---Shamir---Adleman Scheme}\n\nThe \\textit{Rivest---Shamir---Adleman} scheme (or \\textit{RSA} for short) is one of the first practical asymmetric-key cryptosystems \\cite{classical_algebra}. \nThe cryptosystem is named after it's discoverers \\textit{Ron Rivest}, \\textit{Adi Shamir}, and \\textit{Len Adleman}, who gave a definition on how \nasymmetric-key cryptography could be realized \\cite{classical_algebra}.\n\nThe RSA scheme involves four distinct steps: \\textit{key generation}, \\textit{key distribution}, \\textit{encryption}, and \\textit{decryption}\n\n\\subsection{Key Generation}\n\nA user who wishes to participate in a session of the scheme must first generate two keys: one public key for encryption and one private key for decryption. To do so,\nthe user will first select two large prime numbers $p$ and $q$, and then multiply them together to calculate the integer $n = pq$. \nIf $$\\mathlarger{\\phi(n) = (p-1)(q-1)}$$ then the user will also select an integer $e > 1$ such that $GCD(e,\\phi(n))=1$. \nThe integer $e$ will be used for the calculation of the encryption key. The user now solves for the equation: $$\\mathlarger{ed \\equiv 1 \\pmod{\\phi(n)}}$$\n\nAccording to the \\textit{Linear Congurnece Theorem}, since $GCD(e,\\phi(n))=1$, there is exactly one congruence class modulo $\\phi(n)$ which satisfies the aforementioned\ncongruence---or in other words, there is only one integer between $0$ and $\\phi(n)$ which satisfies the congruence, let $d$ represent this integer \n\\cite{classical_algebra}. Now, the pair of integers $(e,n)$ represent the user's public keys, and the pair of integers $(d,n)$ represent the user's private keys. \nIn other words, we now have the following keys:\n\n\\begin{itemize}\n    \\item $n$---the shared key.\n    \\item $e$---the public encryption key.\n    \\item $d$---the private decryption key.\n\\end{itemize}\n\n\\subsection{Key Distribution}\n\nSuppose that John and Mary are communication using the RSA scheme. John must know Mary's public key $e$ to encrypt his message and Mary must use her private key $d$ to \ndecrypt his message. Therefore, Mary must transmit her $(e,n)$ key pair to John via a reliable (though not secret) route. \n\n\\subsection{Encryption and Decryption}\n\nTo encrypt the message $M$---first, the sender of the message would lookup the recipient's public key pair $(e,n)$ \\cite{classical_algebra}. \nThen the sender would compute the cipertext $C$ using the following equation: \n$$\\mathlarger{M^e \\equiv C \\pmod{n} \\text{\\hspace{1em}where\\;\\;}0 \\leq C < n}$$\n\nThe sender will then take the ciphertext $C$ and send it to the recipient.\n\nDecryption is the inverse of the encryption processes. The recipient of the message, will decrypt the message using the same equation for encryption but rather using it's\nown private decryption key pair $(d,n)$ \\cite{classical_algebra}. Decryption can be expressed as \n$$\\mathlarger{C^d \\equiv R \\pmod{n} \\text{\\hspace{1em}where\\;\\;}0 \\leq R < n}$$\n\nThe decrypted message $R$ is the same as the original message $M$.\n\nIt is very important to note that our message $M$ must be smaller than our $n$. In the case that $M$ is greater than $n$, we must split $M$ into blocks which are smaller\nthan $n$. For example, if $n=12319$ and we want to encrypt the message $06212626$, we would split the message into two blocks---$0621$ and $2626$, encrypt each block, \nand then finally combine the blocks into one block (making sure to maintain the order of the blocks when combining).\n", "meta": {"hexsha": "526e11c81bc463137f51bb741735e8c8b1fc90d0", "size": 5545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/AsymmetricKeyCryptography.tex", "max_stars_repo_name": "GalacticGlum/CryptographyResearchPaper", "max_stars_repo_head_hexsha": "b538ba91fcee47995b2bf102affa9425badafc0c", "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/AsymmetricKeyCryptography.tex", "max_issues_repo_name": "GalacticGlum/CryptographyResearchPaper", "max_issues_repo_head_hexsha": "b538ba91fcee47995b2bf102affa9425badafc0c", "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/AsymmetricKeyCryptography.tex", "max_forks_repo_name": "GalacticGlum/CryptographyResearchPaper", "max_forks_repo_head_hexsha": "b538ba91fcee47995b2bf102affa9425badafc0c", "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": 81.5441176471, "max_line_length": 179, "alphanum_fraction": 0.7466185753, "num_tokens": 1399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401363, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.653540739349884}}
{"text": "\\title{Inference of Probabilistic Models}\n\n\\subsection{Inference of Probabilistic Models}\n\nThis tutorial asks the question: what does it mean to do inference of\nprobabilistic models? This sets the stage for understanding how to\ndesign inference algorithms in Edward.\n\n\\subsubsection{The posterior}\n\nHow can we use a model $p(\\mathbf{x}, \\mathbf{z})$ to analyze some\ndata $\\mathbf{x}$? In other words, what hidden structure $\\mathbf{z}$\nexplains the data? We seek to infer this hidden structure using the\nmodel.\n\nOne method of inference leverages Bayes' rule to define the\n\\emph{posterior}\n\\begin{align*}\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  &=\n  \\frac{p(\\mathbf{x}, \\mathbf{z})}{\\int p(\\mathbf{x}, \\mathbf{z}) \\text{d}\\mathbf{z}}.\n\\end{align*}\nThe posterior is the distribution of the latent variables\n$\\mathbf{z}$, conditioned on some (observed) data $\\mathbf{x}$.\nDrawing analogy to representation learning, it is a probabilistic\ndescription of the data's hidden representation.\n\nFrom the perspective of inductivism, as practiced by classical\nBayesians (and implicitly by frequentists),\nthe posterior is our updated hypothesis about the latent variables.\nFrom the perspective of hypothetico-deductivism, as practiced by\nstatisticians such as Box, Rubin, and Gelman, the posterior is simply\na fitted model to data, to be criticized and thus revised\n\\citep{box1982apology,gelman2013philosophy}.\n\n\\subsubsection{Inferring the posterior}\n\nNow we know what the posterior represents. How do we calculate it? This is the\ncentral computational challenge in inference.\n\nThe posterior is difficult to compute because of its normalizing\nconstant, which is the integral in the denominator.\nThis is often a high-dimensional integral that lacks an analytic (closed-form)\nsolution. Thus, calculating the posterior means \\emph{approximating} the\nposterior.\n\nFor details on how to specify inference in Edward, see the\n\\href{/api/inference}{inference API}. We describe several examples in\ndetail in the \\href{/tutorials/}{tutorials}.\n\n\n\\subsubsection{References}\\label{references}\n\n", "meta": {"hexsha": "07e7c015cb3c23f578d6c6662a01f90c16219776", "size": 2063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/inference.tex", "max_stars_repo_name": "xiangze/edward", "max_stars_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5200, "max_stars_repo_stars_event_min_datetime": "2016-05-03T04:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:32:26.000Z", "max_issues_repo_path": "docs/tex/tutorials/inference.tex", "max_issues_repo_name": "xiangze/edward", "max_issues_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 724, "max_issues_repo_issues_event_min_datetime": "2016-05-04T09:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:41:12.000Z", "max_forks_repo_path": "docs/tex/tutorials/inference.tex", "max_forks_repo_name": "xiangze/edward", "max_forks_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1004, "max_forks_repo_forks_event_min_datetime": "2016-05-03T22:45:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T00:08:08.000Z", "avg_line_length": 38.2037037037, "max_line_length": 86, "alphanum_fraction": 0.7833252545, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6535407359747442}}
{"text": "\\section{Mayer-Vietoris and Subdivision}\n(Is it Meyer-Vietoris or Mayer-Vietoris?) Today is the lecture with a lot of formulae.\n\\begin{theorem}\nLet $\\sca$ be a cover of $X$, so that $X=\\bigcup_{A\\in \\sca}\\mathrm{Int}(A)$. Then the theorem we're going to prove is this. If $S^\\sca_\\ast(X)=\\sum_{A\\in\\sca}S_\\ast(A)\\to S_\\ast(X)$ induces an isomorphism in $ H_\\ast$. (This is a ``quasi-isomorphism'' of chain complexes.)\n\\end{theorem}\nBecause this lecture's full of formulas, I'm going to stand around with a piece of paper in my hand.\n\\begin{example}\nLet $\\sca=\\{A,B\\}$ of X, so that:\n\\begin{equation*}\n\\xymatrix{A\\cap B\\ar[r]^{j_1}\\ar[d]^{j_2} & A\\ar[d]^{i_1}\\\\\nB\\ar[r]_{i_2} & X}\n\\end{equation*}\nThen consider the following diagram:\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & S_\\ast(A\\cap B)\\ar[r]^{\\begin{pmatrix}j_{1\\ast} \\\\ -j_{2\\ast}\\end{pmatrix}}\\ar@{=}[d] & S_\\ast(A)\\oplus S_\\ast(B)\\ar[r]\\ar[d] & S^\\sca_\\ast(X)\\ar[r]\\ar@{=}[d] & 0\\\\\n0\\ar[r] & S_\\ast(A)\\cap S_\\ast(B)\\ar[r] & S_\\ast(A)\\oplus S_\\ast(B)\\ar[dr]\\ar[r]^{(i_{1\\ast},\\ i_{2\\ast})} & S_\\ast(A)+S_\\ast(B)\\ar[r]\\ar@{^(->}[d] & 0\\\\\n & & & S_\\ast(X) &}\n\\end{equation*}\nThe map $S_\\ast(A)+S_\\ast(B)\\hookrightarrow S_\\ast(X)$ is a quasi-isomorphism, this is what locality says. Take the homology of this to get a lexseq:\n\\begin{equation*}\n\\xymatrix{ \\cdots\\ar[rr] & & H_{n+1}(X)\\ar[dll]_{\\begin{pmatrix}j_{1\\ast} \\\\ -j_{2\\ast}\\end{pmatrix}}\\\\\n H_n(A\\cap B)\\ar[r] & H_n(A)\\oplus H_n(B)\\ar[r]^{(i_{1\\ast},\\ i_{2\\ast})} & H_n(X)\\ar[dll]\\\\\n H_{n-1}(A\\cap B)\\ar[r] & H_{n-1}(A)\\oplus H_{n-1}(B)\\ar[r] & \\cdots}\n\\end{equation*}\nVoila, you have Mayer-Vietoris. (I have a different proof of this that I submitted in homework.)\n\\end{example}\n\\subsection{The cone construction}\nLet $X\\subseteq \\mathbf{R}^N$ be a star-shaped region, and let $b\\in\\mathbf{R}^N$. Then we showed that the augmentation $S_\\ast(X)\\xrightarrow{\\epsilon}\\Z$ is a chain homotopy equivalence. There's another map going backwards $\\Z\\xrightarrow{\\eta_b} S_\\ast(X)$ sending $1\\mapsto c^0_b$. Clearly the composition $\\epsilon\\circ\\eta_b$ is the identity. We want to show that $\\eta_b$ ad $\\epsilon$ are chain homotopy inverses to each other. One direction is easy. The other map $S_\\ast(X)\\xrightarrow{\\eta_b\\epsilon}S_\\ast(X)$ being homotopic to $1_{S_\\ast(X)}$ is a little harder. This means that we want to construct a map $b\\ast:S_n(X)\\to S_{n+1}(X)$ such that $db\\ast+b\\ast d=1-\\eta_b\\epsilon$.\n\nConsider some $\\sigma:\\Delta^1\\to X$. Then because $X$ is star shaped, you can send $\\sigma$ to $b$. This gives a $2$-simplex $b\\ast \\sigma$, called the \\emph{join}. We'll define this $2$-simplex and label it so that the zero vertex is $b$ itself, the $1$ vertex is $d_1\\sigma$, and the $2$ vertex is $d_0\\sigma$. Define $b\\ast\\sigma$ as follows (where $(t_0,\\cdots,t_{n+1})\\in \\Delta^{n+1}$):\n\\begin{equation*}\nb\\ast\\sigma(t_0,\\cdots,t_n,t_{n+1})=t_0b + (1-t_0)\\sigma\\left(\\frac{t_1,\\cdots,t_{n+1}}{1-t_0}\\right)\n\\end{equation*}\nWhen $t_0=0$, then you recover exactly $\\sigma(t_1,\\cdots,t_{n+1})$ and when $t_0=1$, this is exactly $b$. (Why can you divide by $1-t_0=0$?) This is a map $b\\ast:\\Sin_n(X)\\to\\Sin_{n+1}(X)$, so we can extend linearly to get $S_n(X)\\to S_{n+1}(X)$, also denoted $b\\ast$. What is $d_i(b\\ast\\sigma)$? This is exactly:\n\\begin{equation*}\nd_i(b\\ast\\sigma)=\\begin{cases}\\sigma & i=0 \\\\ \nc^0_b & i=1,n=0\\\\\nb\\ast d_{i-1}\\sigma & i>0,n>0\\end{cases}\n\\end{equation*}\nThe latter thing seems true because in the case when $n=1$, $d_2(b\\ast\\sigma)$ is the cone on $d_1\\sigma$. The middle thing is true because when $n=0$ you can't use the bottom thing (what is the boundary in that case?), and if you draw this out, noting our convention that when $t_0=1$ you have $d_1\\sigma$ and when $t_0=1$ you have $b$, this automatically yields $d_1(b\\ast\\sigma)=b$ if $\\sigma:\\Delta^0\\to X$. We can rewrite this as follows. Here $c\\in S_n(X)$.\n\\begin{equation*}\nd_i(b\\ast c)=\\begin{cases}\nc & i=0\\\\\nb\\ast d_0c + \\eta_b\\epsilon c & i=1\\\\\nb\\ast d_{i-1}\\sigma & i>1\n\\end{cases}\n\\end{equation*}\nBecause $d_0$ of a $0$-simplex is defined to be zero. This may seem confusing, but it's just a translation of what we wrote down above. We want to compute that this thing is actually a chain homotopy. Let's compute.\n\\begin{align*}\nd(b\\ast c)& = d_0(b\\ast c) - d_1(b\\ast c) + \\sum_{i>1}(-1)^i d_i(b\\ast c)\\\\\n& = c-(b\\ast d_0c + \\eta_b\\epsilon c) + \\sum_{i=2}^n (-1)^ib\\ast d_{i-1}c\\\\\n& = c-\\eta_b\\epsilon c - \\sum_{j=0}^{n-1}(-1)^jb\\ast d_jc\\\\\n& = c-\\eta_b\\epsilon c - b\\ast dc\n\\end{align*}\nHere $j=i-1$. The equality $\\sum_{j=0}^{n-1}(-1)^jb\\ast d_jc=b_\\ast dc$ holds because $b\\ast$ is linear (by definition on $S_n(X)$). This means that $b\\ast$ is a chain homotopy, QED. This completes what we've claimed about the star shaped region. We want to use this cone construction to talk about subdivision.\n\\subsection{Subdivide the standard simplex}\nLet's focus on the standard simplex. This is a nice thing about singular homology. For the $1$-simplex, you just cut in half. For the $2$-simplex, just look at the subdivision of each face, and look at the barycenter\\footnote{The barycenter of the $n$-simplex is $b_n:=\\frac{(1,\\cdots,1)}{n+1}$.}, and join the barycenter to the $1$-simplex between each ``half'' $1$-simplex. We want to formalize this process. Define a natural transformation $\\$:S_n(X)\\to S_n(X)$ by defining on standard $n$-simplex, namely by specifying what $\\$(\\iota_n)$ is where $\\iota_n:\\Delta^n\\xrightarrow{\\mathrm{id}}\\Delta^n$, and then extending by naturality (namely $\\$(\\sigma)=\\sigma_\\ast\\$(\\iota_n)$). Here's the definition. When $n=0$, define $\\$=\\mathrm{id}$, i.e., $\\$(\\iota_0)=\\iota_0$. For $n>0$, define $\\$\\iota_n:=b_n\\ast\\$ d\\iota_n$ where $b_n$ is the barycenter of $\\Delta^n$. This makes a \\emph{lot} of sense if you draw out a picture, and it's a very clever definition that captures the geometry we described. Let me tell you what we'll prove about this, most likely on Wednesday.\n\\begin{prop}\n$\\$$ is a chain map $S_\\ast(X)\\to S_\\ast(X)$, i.e., $\\$d=d\\$$. Also, $\\$\\simeq 1$.\n\\end{prop}\nAlso, class is cancelled on Friday.\n", "meta": {"hexsha": "54155d26f8d37b9ca3aa06356cfcce0de1a62b57", "size": 6076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-12-mayer-vietoris.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-12-mayer-vietoris.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-12-mayer-vietoris.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": 98.0, "max_line_length": 1072, "alphanum_fraction": 0.6774193548, "num_tokens": 2260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.6535407264798327}}
{"text": "\\section{Planes}\n\nIf $(x,y,z)$ is a point on the plane, then given $\\textbf{P}_0=(x_0,y_0,z_0)$, $(x-x_0,y-y_0,z-z_0)$ is a vector on the plane perpendicular to $\\textbf{n}$, the\nnormal vector. Thus, $(A,B,C)\\cdot(x-x_0,y-y_0,z-z_0)=0$ where $A,B,C$ are vector coordinates of $\\textbf{n}$. With expansion:\n\n\\begin{align*}\n    A(x-x_0)+B(y-y_0)+C(z-z_0)&=0\\\\\n    Ax+By+Cz=Ax_0+By_0+Cz_0&=0\\\\\n    Ax+By+Cz=\\textbf{n}\\cdot \\textbf{P}_0\n\\end{align*}\n\nNote that $(A,B,C)$ form coordinates of $\\textbf{n}$.\n\nTo find a plane containing 3 points $\\textbf{v}_1,\\textbf{v}_2,\\textbf{v}_3$, compute, for example $\\textbf{c}_1=\\textbf{v}_3-\\textbf{v}_1$ and $\\textbf{c}_2=\\textbf{v}_2-\\textbf{v}_1$.\nThis finds 2 vectors in the plane. Then compute $\\textbf{c}_1\\times \\textbf{c}_2=\\textbf{n}$. \\newline\n\n\\noindent\nThe trace of a plane is the intersection of a plane $\\mathcal{P}$ with $xy$, $xz$, or $yz$ coordinate planes. Can be found by setting respective variable to 0.\n\n\\subsection{Cross-product rules and identities}\n\n\\begin{center}\n    \\includegraphics[]{figures/cross-product}\n\\end{center}\n\nOverview\n\\begin{itemize}\n    \\item $||\\textbf{a}\\times \\textbf{b}||=||\\textbf{a}||||\\textbf{b}||\\sin\\theta$\n    \\item $\\textbf{a},\\textbf{b}\\perp \\textbf{a}\\times \\textbf{b}$\n\\end{itemize}\n\nAlgebraic\n\\begin{itemize}\n    \\item $\\textbf{a}\\times \\textbf{b}=\\textbf{0}$\n    \\item $\\textbf{a}\\times \\textbf{b}=-\\textbf{b}\\times \\textbf{a}$\n    \\item Distributive properties hold -- preserve direction however\n    \\item $(\\alpha \\textbf{a})\\times \\textbf{b}=\\alpha(\\textbf{a}\\times \\textbf{b})$\n\\end{itemize}\n\n\\section{Graphs}\n\n\\subsection{Multivariable functions}\n\nFunction of $n$-variables is real-valued function with $f(x_1,\\cdots,x_n)$ with domain $\\mathcal{D}$\nbeing a set of $n$-tuples $(x_1,\\cdots,x_n)$ in $\\R^n$, or where $f$ is defined.\nRange of $f$ is all values $f(x_1,\\cdots,x_n)$ for $(x_1,\\cdots,x_n)$ in the domain.\n\n\\subsection{Graphing multivariable functions}\n\nTraces are 2D curves obtained by intersection with planes parallel to coordinate plane.\n\\begin{itemize}\n    \\item Horizontal trace at height $c$ -- intersection of graph with plane $z=c$, so points $(x,y,c)$ such that $f(x,y)=c$\n    \\item Vertical trace in plane $x=a$ -- intersection of graph with vertical plane $x=a$ for all points $(a,y,f(a,y))$\n    \\item Vertical trace in plane $y=b$ -- intersection of graph with vertical plane $y=b$ for all points $(x,b,f(x,b))$\n\\end{itemize}\n\n\\begin{center}\n    \\includegraphics[scale=0.15]{figures/saddle-plot.png}\n\\end{center}\n\nSaddle surface general form is $f(x,y)=x^2-y^2$. The horizontal traces are hyperbolas of the form $c=x^2-y^2$.\nVertical traces are parabolas, as either $x,y$ set to 0.\\newline\n\n\\noindent\nLinear functions in 2 variables are of the form $f(x,y)=mx+ny+r|m,n,r\\in \\R$.\n\n\\subsection{Contour maps and level curves}\n\n\\begin{center}\n    \\includegraphics[scale=0.15]{figures/contour-map.png}\n\\end{center}\n\nCan specify a contour interval for each $z=c$ value. Is a 2D representation of\nlevel curves of $f(x,y)$ at an interval. Going along level curve means change in altitude is\n0. Altitude has change of $\\pm m$ (contour interval) when going up/down contour levels. Average ROC is $\\Delta \\text{elevation}/\\Delta \\text{distance}$.\nPath of steepest ascent follows the shortest possible segment from one contour line to another and always points in steepest direction.\n\n\\begin{center}\n    \\includegraphics[scale=0.3]{figures/steepest-ascent.png}\n\\end{center}\n\n\\section{Partial Derivatives}\n\n\\subsection{Definition}\n\nIf $f:\\R^2\\rightarrow \\R$ is given by $f(x,y)=z$ abd $P_0=(a,b)$ is a point in the domain of $f$,\nthen the partial derivative are:\n\\begin{itemize}\n    \\item If $h:\\R\\rightarrow \\R$ by $h(t)=f(t,b)$, then partial derivative with respect to $x$ at $P_0$\n    is $h\\,'(a)$ with following limit definition\n\n    \\[\\left.\\frac{\\partial f}{\\partial x}\\right|_{(a, b)}=f_{x}(a, b)=\\lim _{h \\rightarrow 0} \\frac{f(x+h, b)-f(x, b)}{h}=\\lim _{x \\rightarrow a} \\frac{f(x, b)-f(a, b)}{x-a}\\]\n\n    \\item If $g:\\R\\rightarrow \\R$ by $g(t)=g(t,b)$ then partial derivative with respect to $y$ at $P_0$ is $g\\,'(b)$ with following limit definition\n    \n    \\[\\left.\\frac{\\partial f}{\\partial y}\\right|_{(a, b)}=f_{y}(a, b)=\\lim _{h \\rightarrow 0} \\frac{f(a, x+h)-f(a, b)}{h}=\\lim _{y \\rightarrow b} \\frac{f(a, y)-f(a, b)}{y-b}\\]\n\n\\end{itemize}\n\nCan be thought of as the intersection of the plane shifted by $b$ with $f$, and the derivative of the resulting trace.\n\n\\subsection{Linear approximation with planes}\n\nLet $z=f(x,y)$ be a scalar-valued function in $\\R^2$ and $P_0=(a,b)$ be a point in domain of $f$. Can have 2 slope vectors representing partial derivatives:\n$(1,0,f_x(a,b))$ and $(0,1,f_y(a,b))$. Can find a linear approximation by finding set of points in plane spanned by these vectors passing through\n$(a,b,f(a,b))$.\n\n\\[\\textbf{n}=(1,0,f_x(a,b))\\times(0,1,f_y(a,b))=(-f_x(a,b),-f_y(a,b),1)\\]\n\nBuilding the plane:\n\n\\begin{align*}\n    (x-a, y-b, z-f(a, b)) \\cdot \\textbf{n} &=0 \\\\\n    (x-a, y-b, z-f(a, b)) \\cdot\\left(-f_{x}(a, b),-f_{y}(a, b), 1\\right) &=0 \\\\\n    -f_{x}(a, b)(x-a)-f_{y}(a, b)(y-b)+z-f(a, b) &=0\n\\end{align*}\n\nThus,\n\n\\[z=f(a, b)+f_{x}(a, b)(x-a)+f_{y}(a, b)(y-b)\\]\n\n\\subsection{Higher-order derivatives}\n\nCan be calculated using derivatives of $f_x$ and $f_y$. Notation:\n\n\\[f_{xx}=\\frac{\\partial}{\\partial x}(\\frac{\\partial f}{\\partial x}),\\; f_{yy}=\\frac{\\partial}{\\partial y}(\\frac{\\partial f}{\\partial y})\\]\n\nCan also have mixed partials (read as with respect to $x$ or $y$):\n\n\\[f_{xy}=\\frac{\\partial}{\\partial y}(\\frac{\\partial f}{\\partial x}),\\; f_{yx}=\\frac{\\partial}{\\partial x}(\\frac{\\partial f}{\\partial y})\\]\n\nBy Clairaut's Theorem, if $f_{xy}$ and $f_{yx}$ are both continuous functions on a disk $D$, then $f_{xy}(a,b)=f_{yx}(a,b)\\: \\forall (a,b)\\in D$. Means that $f_{xyxy}=f_{xxyy}=f_{yyxx}=f_{yxyx}$.\n\n\\section{Extrema}\n\n\\subsection{Definition and proofs}\n\nA function $f$ has:\n\\begin{itemize}\n    \\item local maximum at $P_0$ in domain if $f(P_0)>f(x,y)\\;\\forall\\;(x,y)$ sufficiently near $P_0$\n    \\item local minimum at $P_0$ in domain if $f(P_0)<f(x,y)\\;\\forall\\;(x,y)$ sufficiently near $P_0$\n\\end{itemize}\n\nSufficiently near: positive radius $R$ used to build a circle centered at $P_0$ that traps points in domain with desired property (min or max).\nGlobal extrema redefine sufficiently near as in the domain of $f$.\n\nCritical point is defined as either of the following:\n\\begin{itemize}\n    \\item $f_x(P_0)=f_y(P_0)=0$\n    \\item either $f_x(P),f_y(P)$ does not exist\n\\end{itemize}\n\nMethod: find critical value $y$ from $f_y$ and $x$ from $f_x$ through cross-substitution.\n\nProof that if $f_x(P),f_y(P)$ both exist and there is a local max at $P$, then both partials are 0:\n\nDefine $g:\\;\\R\\rightarrow \\R$ to be single variable function from holding $y=b$ in $f$. Considering points sufficiently near:\n\n\\includegraphics[scale=0.5]{figures/Screen Shot 2021-03-21 at 7.55.34 PM.png}\n\nPlugging into function $g$: $g(x) < f(x,b) \\leq f(P_0)=g(a)$, so for $x$-values sufficiently\nnear $a$, $g(x)\\leq g(a)$, so it is a local max of $g$. Invoking theorem of extrema, either $g'(a)=0$ or DNE. As $g'(a)=f_x(P_0)$, demonstrates that\n$f_x=0$ or DNE for a local max. Same can be done for $f_y$.\n\nCan minimize a function's distance to origin through distance formula. As a square root minimizes\nat its argument, can just concentrate on minimizing the argument.\n\nReiteration: If $f: \\mathbb{R}^{2} \\rightarrow \\mathbb{R}$ has continuous first and second order partial derivatives then $f_{x y}(x, y)=f_{y x}(x, y)$.\nContinuous 2nd order partials: $C^2$; continous $n$ order partials: $C^\\infty$.\n\n\\textbf{Fermat's theorem proof (same as above):} If $f(x,y)$ has a local min/max at $P=(a,b)$, then $P=(a,b)$ is a critical point of $f(x,y)$.\n\nAssuming $f(x,y)$ has a local min at $P$, then this means that $f(x,y) \\geq (a,b)$ for $(x,y)$ in the surrounding disk $D(r,P)$.\nFor some $y=b$, the distance between any 2 $x$-values must be contained in the disk: $|x-a|<r$. Shows that $g(x)=f(x,b)$ has a local min\nat $x=a$, so $g'(a)=0$ or DNE. Because $g'(a)=f_x(a,b)$, $f_x(a,b)$ is either 0 or DNE. As the same can be said for $f_y$, $P$ is a critical point.\n\n\\subsection{Second-derivative test}\n\nGiven a function $f:\\R^2 \\rightarrow \\R$ that has continuous 2nd partials near a critical point $P$, define\nthe discriminant of $f$ at $P$ to be:\n\n\\[D(P)=f_{x x}(P) f_{y y}(P)-\\left(f_{x y}(P)\\right)^{2}\\]\n\nThen:\n\\begin{itemize}\n    \\item If $D>0$, $P$ is a local extreme of $f$\n    \\begin{itemize}\n        \\item $f_{xx}(P)>0$ implies a local min\n        \\item $f_{xx}(P)<0$ implies a local max\n    \\end{itemize}\n    \\item If $D<0$ then there is neither a min or max at $P$, but an inflection point (saddle point)\n    \\item If $D=0$ then there is no information about $P$\n    \\item If $D>0$ and $f_{xx}(a,b)>0$, then local minimum\n    \\item If $D>0$ and $f_{xx}(a,b)<0$, then local maximum\n\\end{itemize}\n\nObserve that $D(P)=\\operatorname{det}\\left(\\begin{array}{ll}\n                f_{x x}(P) & f_{x y}(P) \\\\\n                f_{y x}(P) & f_{y y}(P)\n            \\end{array}\\right)$\n\n\\subsection{Global extrema}\n\nIf $f:\\R^2 \\rightarrow \\R$ is continuous on a closed and bounded subset of $\\R^2$ then it has a global max/min\non the subset (at critical point or along boundary)\n\nA closed subset of $\\R^2$ is one that contains the boundary. Boundary points have the property that\nany circle centered around them with positive radius will contain points in and out of the subset.\nBounded subset is where any distance between 2 points in the set never exceeds some fixed bound $M\\in \\R$.\n\n\\begin{center}\n    \\includegraphics[scale=0.5]{figures/Screen Shot 2021-03-22 at 3.01.05 PM.png}\n\\end{center}\n\nThe boundary curve is denoted as $\\partial D$ where $D$ is a disk. By parameterizing $\\partial D$ and using function\ncomposition to take this curve $\\textbf{c}(t)$ into $f$: $h(t)=f(\\textbf{c}(t))$. A min/max for $f$ along boundary curve\nis a min/max of $h$. Plug resulting coordinates into $f$ and determine global extrema.\n\n\\section{Lagrange Multipliers}\n\n\\subsection{Theory}\n\nLet $f:\\R^2\\rightarrow \\R$ and $\\textbf{c}:\\R\\rightarrow \\R^2$ such that there is a composite function $h(t)=f(\\textbf{c}(t))$.\nThen, $h\\,'(t)=f_x(\\textbf{c}(t))x\\,'(t)+f_y(\\textbf{c}(t))y\\,'(t)=\\left(f_{x}\\left(\\textbf{c}(t)), f_{y} \\textbf{c}(t)\\right) \\cdot \\textbf{c}^{\\prime}(t)\\right.$.\nThis brings definition of gradient vector, so that for $f:\\R^2\\rightarrow \\R$, each point in domain is in domain of $f$ the vector $\\left(f_{x}\\left(P_{0}\\right), f_{y}\\left(P_{0}\\right)\\right)$:\n\n\\[\\nabla f\\left(P_{0}\\right)=\\left(f_{x}\\left(P_{0}\\right), f_{y}\\left(P_{0}\\right)\\right)\\]\n\nRewriting chain rule:\n\n\\[\\frac{d}{dt}f(\\textbf{c}(t_0))=\\nabla f(\\textbf{c}(t_0))\\cdot \\textbf{c}\\,'(t_0)\\]\n\nLet $g(x,y)$ be boundary curve function and $f(x,y)$ be original.\n\nUse a boundary curve which is level curve $c=0$ which represents the boundary of the subset where global extrema can be found. \nIf $f$ achieves maximum at point $P$ along curve, then either $g_x(P)=g_y(P)=0$ ($\\nabla g(P)=\\textbf{0}$) or there is a scalar $\\lambda$ (Lagrange multiplier)\nsuch that $f_x(P)=\\lambda g_x(P)$ and $f_y(P)=\\lambda g_y(P)$ ($\\nabla f(P)=\\lambda \\nabla g(P)$). Can find locations of global extreme without parameterizing.\n\n\\subsection{Proof}\n\nSuppose $f(P)\\geq f(x,y)\\;\\forall\\;(x,y)$ satisfying $g(x,y)=0$ where $g$ is the bounded constraint. Let $\\textbf{c}$ be its parameterization where $\\textbf{c}\\,'(0)\\neq 0$. Parameterizing $g(x,y)=0$ with $\\textbf{c}(t)$\nsuch that $\\textbf{c}(0)=P$: Observe that $h(t)=f(\\textbf{c}(t))$ is from $\\R\\rightarrow\\R$ with local max at $t=0$.\nThus, $h'(t)=0$ or DNE. Taking derivative, $h'(t)=\\nabla f(\\textbf{c}(t))\\cdot \\textbf{c}\\,'(t)$.\nThen, $h^{\\prime}(0)=\\nabla f(\\textbf{c}(0)) \\cdot \\textbf{c}^{\\prime}(0)=0$ or DNE. This dot product is either 0 or DNE because\n1 or both vectors could not exist, or if they are $\\perp$. Thus, $\\nabla f(P)\\perp \\textbf{c}\\,'(0)$ and $\\textbf{c}\\,'(0)\\neq \\textbf{0}$ (because $\\textbf{c}$ is assumed to be regular).\n\nShowing $\\nabla g(P)\\perp \\textbf{c}\\,'(0)$. Define $j(t)=g(\\textbf{c}(t))$. Thus, $j^{\\prime}(t)=\\nabla g(\\textbf{c}(t)) \\cdot \\textbf{c}^{\\prime}(t)$.\nBecause $\\textbf{c}(t)$ is a parameterization of level curve $g(x,y)=0$, it always outputs 0, so $j(t)=g(\\textbf{c}(t))=0$ always. Can the conclude that\n$j^{\\prime}(t)=\\nabla g(\\textbf{c}(t)) \\cdot \\textbf{c}^{\\prime}(t)=0$. Plugging in $t=0$ gives $\\nabla g(\\textbf{c}(0)) \\cdot \\textbf{c}^{\\prime}(0)=0$ so $\\nabla g(P)\\perp \\textbf{c}\\,'(0)$.\n\nBecause both vectors are perpendicular to $\\textbf{c}\\,'(0)$, they are parallel -- $\\nabla f(P)=\\lambda \\nabla g(P)$. Or:\n\n$$\\begin{array}{l}\n    f_{x}(P)=\\lambda g_{x}(P) \\\\\n    f_{y}(P)=\\lambda g_{y}(P)\n\\end{array}$$", "meta": {"hexsha": "739a6c93cafff581fa92b331af499c612d2e0000", "size": 12824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multivariable-calculus/tex/unit-2.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multivariable-calculus/tex/unit-2.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multivariable-calculus/tex/unit-2.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.09375, "max_line_length": 220, "alphanum_fraction": 0.6653930131, "num_tokens": 4488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407016, "lm_q2_score": 0.8757869997529962, "lm_q1q2_score": 0.6534588202174447}}
{"text": "% \\chapter*{Appendix B: The Combined Filtering Method}\n% \\addcontentsline{toc}{chapter}{Appendix B:The Combined Filtering Method}\n\n\\chapter{The Combined Filtering Method}\n \nIn general, suppose that we are given $K$ linear transforms $T_1,\n\\ldots, T_K$ and let $\\alpha_k$ be the coefficient sequence of an\nobject $x$ after applying the transform $T_k$, i.e. $\\alpha_k = T_k\nx$. We will assume that for each transform $T_k$ we have available a\nreconstruction rule that we will denote by $T^{-1}_k$ although this is\nclearly an abuse of notation.  Finally, $T$ will denote the block\ndiagonal matrix with the $T_k$'s as building blocks and $\\alpha$ the\namalgamation of the $\\alpha_k$'s.\n\nA hard thresholding rule associated with the transform $T_k$ synthesizes \nan estimate $\\tilde{s}_k$ via the formula \n\\begin{equation}\n\\label{eq:ht}\n\\tilde{s}_k = T_k^{-1} \\delta(\\alpha_k)\n\\end{equation}\nwhere $\\delta$ is a rule that sets to zero all the coordinates of\n$\\alpha_k$ whose absolute value falls below a given sequence of\nthresholds (such coordinates are said to be non-significant).\n \nGiven data $y$ of the form $y = s + \\sigma z$, where $s$ is the image\nwe wish to recover and $z$ is standard white noise, we propose solving\nthe following optimization problem \\cite{starck:spie01a}:\n\\begin{equation}\n  \\label{eq:l1-min}\n  \\min \\|T\\tilde{s}\\|_{\\ell_1}, \\quad \\mbox{subject to} \\quad s \\in C,  \n\\end{equation}\nwhere $C$ is the set of vectors $\\tilde{s}$ \nwhich obey the linear constraints\n\\begin{equation}\n\\label{eq:constraints}\n\\left\\{  \\begin{array}{ll}\n  \\tilde{s} \\ge 0, \\\\\n  |T\\tilde{s} - Ty| \\le e; \n  \\end{array}\n  \\right. \n\\end{equation}\nhere, the second inequality constraint \nonly concerns the set of significant coefficients, \ni.e. those indices $\\mu$ such that $\\alpha_\\mu =\n(Ty)_\\mu$ exceeds (in absolute value) a threshold $t_\\mu$. Given a\nvector of tolerance $(e_\\mu)$, we seek a solution whose coefficients\n  $(T\\tilde{s})_\\mu$ are within $e_\\mu$ of the noisy\nempirical $\\alpha_\\mu$'s.  Think of $\\alpha_\\mu$ as being given by\n\\[\ny = \\langle y, \\varphi_\\mu \\rangle, \n\\]\nso that $\\alpha_\\mu$ is normally distributed with mean $\\langle f,\n\\varphi_\\mu \\rangle$ and variance $\\sigma^2_\\mu = \\sigma^2\n\\|\\varphi_\\mu\\|^2_2$. In practice, the threshold values range\ntypically between three and four times the noise level $\\sigma_\\mu$\nand in our experiments we will put $e_\\mu = \\sigma_\\mu/2$. In short,\nour constraints guarantee that the reconstruction will take into\naccount any pattern which is detected as significant by  any of the\n$K$ transforms.\n   \n\\subsubsection*{The Minimization Method}\n\nWe propose solving (\\ref{eq:l1-min}) using the method of hybrid\nsteepest descent (HSD) \\cite{wave:yamada01}. HSD consists of building\nthe sequence\n\\begin{eqnarray}\n s^{n+1} = P(s^{n}) - \\lambda_{n+1} \\nabla_J(P(s^{n})); \n\\end{eqnarray}\nHere, $P$ is the $\\ell_2$ projection operator onto the feasible set\n$C$, $\\nabla_J$ is the gradient of equation~\\ref{eq:l1-min}, and\n$(\\lambda_{n})_{n \\ge 1}$ is a sequence obeying $(\\lambda_{n})_{n\\ge\n  1} \\in [0,1] $ and $\\lim_{ n \\rightarrow + \\infty } \\lambda_{n} = 0$.\n\nThe combined filtering algorithm is:\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item Initialize $L_{\\max} = 1$, the number of iterations $N_i$, and\n  $\\delta_{\\lambda} = \\frac{L_{\\max}}{N_i}$.\n\\item Estimate the noise standard deviation $\\sigma$, and set $e_k =\n  \\frac{\\sigma}{2}$.\n\\item For k = 1, .., $K$ calculate the transform: $\\alpha^{(s)}_k\n  = T_k s$.\n\\item Set $\\lambda = L_{\\max}$, $n = 0$, and $\\tilde s^{n}$ to 0.\n\\item While $\\lambda >= 0$ do\n\\begin{itemize}\n\\item $u = \\tilde s^{n}$.\n\\item For k = 1, .., $K$ do\n  \\begin{itemize}\n  \\item Calculate the transform $\\alpha_{k} = T_k u$.\n  \\item For all coefficients $\\alpha_{k,l}$ do\n     \\begin{itemize}\n     \\item Calculate the residual $r_{k,l} = \\alpha^{(s)}_{k,l} -\n       \\alpha_{k,l}$\n       \n     \\item if $\\alpha^{(s)}_{k,l}$ is significant and $ \\mid r_{k,l}\n       \\mid > e_{k,l}$ then $\\alpha_{k,l} = \\alpha^{(s)}_{k,l}$\n     \\item $\\alpha_{k,l} = sgn(\\alpha_{k,l}) ( \\mid \\alpha_{k,l} \\mid - \\lambda)_{+}$.\n     \\end{itemize}\n   \\item $u = T_k^{-1} \\alpha_{k}$\n  \\end{itemize}\n\\item Threshold negative values in $u$ and $\\tilde s^{n+1} = u$.\n\\item $n = n + 1$, $\\lambda = \\lambda - \\delta_{\\lambda} $, and goto 5.\n\\end{itemize}\n\\end{enumerate}\n \n", "meta": {"hexsha": "7e1197ec799b63920b3a033a0788e629e44a4e21", "size": 4351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/archive_tex/annexB.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/annexB.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/annexB.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.6635514019, "max_line_length": 86, "alphanum_fraction": 0.6798437141, "num_tokens": 1437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6534588165889487}}
{"text": "\n\\section{Creating a Gaussian process}\\label{sub:inst}\n\nThis section demonstrates creation of a covariance function, a mean function, and finally several random functions drawn from the Gaussian process distribution defined by those objects.\n\n\\subsection{Creating a mean function}\\label{subsub:mean}\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/mean.pdf,width=8cm}\n    \\caption{The mean function generated by {\\sffamily `examples/mean.py'}.}\n    \\label{fig:mean}\n\\end{figure}\n\nThe mean function of a univariate Gaussian process can be interpreted as a prior guess for the GP, so it is also a univariate function. Mean functions are represented by class \\code{Mean}, which is a wrapper for an ordinary \\proglang{Python} function. The following code (from \\code{pymc/examples/gp/Mean.py}) will produce an instance of class \\code{Mean} called $M$:\n\\begin{CodeChunk}\n\\begin{CodeInput}\nfrom pymc.gp import *\ndef quadfun(x, a, b, c):\n    return (a * x ** 2 + b * x + c)\nM = Mean(quadfun, a = 1., b = .5, c = 2.)        \n\\end{CodeInput}\n\\end{CodeChunk}\n\nThe first argument of \\code{Mean}'s init method is the underlying \\proglang{Python} function, in this case \\code{quadfun}. The extra arguments $a$, $b$  and $c$ will be memorized and passed to \\code{quadfun} whenever $M$ is called; the call $M(x)$ in the plotting portion of the script does not need to pass them in.\n\nMean functions broadcast over their arguments in the same way as \\href{http://docs.scipy.org/doc/numpy/reference/ufuncs.html}{\\pkg{NumPy} universal functions} \\citep{numpybook}, which means that the call $M(x)$, where $x$ is a vector, returns the vector\n\\begin{eqnarray*}\n    [M(x_0),\\ldots, M(x_{N-1})].\n\\end{eqnarray*}\n\nThe last part of the code plots $M(x)$ on $-1<x<1$, and its output is shown in figure \\ref{fig:mean}. As expected, the plot is a parabola.\n\n\\subsection{Creating a covariance function}\\label{subsub:cov}\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/cov.pdf,width=12cm}\n    \\caption{The covariance function generated by {\\sffamily `examples/cov.py'}. On the left is the covariance function $C(x,y)$ evaluated over a square: $-1\\le x\\le 1,\\ -1\\le y\\le 1$. On the right is a slice of the covariance: $C(x,0)$ for $0\\le x \\le 1$}\n    \\label{fig:cov}\n\\end{figure}\n\nCovariance functions are represented by the class \\code{Covariance}, which like \\code{Mean} is essentially a wrapper for ordinary \\proglang{Python} functions. The example in \\code{pymc/examples/gp/cov.py} uses the popular Mat\\`ern function \\citep{banerjee}, which is provided in module \\code{cov_funs}. In addition to the two arguments $x$ and $y$, the Mat\\`ern function takes three parameters: \\code{amp} controls the amount by which realizations may deviate from their mean, \\code{diff_degree} controls the roughness of realizations (the degree of differentiability), and \\code{scale} controls the lengthscale over which realizations change.\n\nThe user is free to write functions to wrap in \\code{Covariance} objects. See \\href{http://code.google.com/p/pymc}{the package documentation} for more information.\n\nThe code in \\code{pymc/examples/gp/cov.py} will produce an instance of class \\code{Covariance} called $C$:\n\\begin{CodeChunk}\n\\begin{CodeInput}\nfrom pymc.gp import *\nfrom pymc.gp.cov_funs import matern\n\nC = Covariance(eval_fun = matern.euclidean, diff_degree = 1.4, amp = .4, scale = 1.)\n\\end{CodeInput}\n\\end{CodeChunk}\n\nThe first argument to \\code{Covariance}'s init method is the \\proglang{Python} function from which the covariance function will be made. In this case, \\code{eval_fun} is \\code{matern.euclidean}. Covariance functions' calling conventions are slightly different from ordinary \\pkg{NumPy} universal functions' \\citep{numpybook} in two ways. First, broadcasting works differently. If $C$ were a \\pkg{NumPy} universal function, $C(x,y)$ would return the following array:\n    \\begin{eqnarray*}\n        \\begin{array}{ccc}\n            [C(x_0,y_0)& \\ldots& C(x_{N-1},y_{N-1})],\n        \\end{array}\n    \\end{eqnarray*}\n    where $x$ and $y$ would need to be vectors of the same length. In fact $C(x,y)$ returns a matrix:\n    \\begin{eqnarray*}\n        \\left[\\begin{array}{ccc}\n            C(x_0,y_0)& \\ldots& C(x_0,y_{N_y-1})\\\\\n            \\vdots&\\ddots&\\vdots\\\\\n            C(x_{N_x-1},y_0)& \\ldots& C(x_{N_x-1},y_{N_y-1})\n        \\end{array}\\right],\n    \\end{eqnarray*}\n    and input arguments $x$ and $y$ don't need to be the same length. Second, covariance functions can be called with just one argument. $C(x)$ returns\n    \\begin{eqnarray*}\n         [C(x_0,x_0)& \\ldots& C(x_{N_x-1},x_{N_x-1})] = \\textup{diag}(C(x,x)),\n    \\end{eqnarray*}\n    but is computed much faster than diag$(C(x,x))$ would be.\nThe extra arguments \\code{diff_degree, amp} and \\code{scale}, which are required by \\code{matern.euclidean}, will be passed to \\code{matern.euclidean} by $C$ every time is called.\n \nThe output of \\code{examples/cov.py} is shown in figure \\ref{fig:cov}.\n\n\\subsubsection{Cholesky algorithms}\n\nThe numerical `heavy lifting' done by this package is primarily handled by \\code{Covariance} and its subclasses. \\texttt{Covariance} itself bases all its computations on the incomplete Cholesky decomposition algorithm used by the \\proglang{Matlab} package \\pkg{chol_incomplete} \\citep{seeger}. \\code{Covariance} computes rows of covariance matrices as they are needed, so if the function it wraps tends to produce covariance matrices with only a few large eigenvalues it can approximate the Cholesky decomposition in less than $O(n^2)$ arithmetic operations \\citep{predictivechol}.\n\n\\code{Covariance} calls back to \\proglang{Python} from \\proglang{Fortran} every time it needs a new row. If the function it wraps tends to produce full-rank covariance matrices (for which all rows are required), this is inefficient. \\code{FullRankCovariance} is a drop-in replacement for \\code{Covariance} that is much faster, but fails (with a helpful error message) if it attempts to factor a matrix that is not full rank. \\code{NearlyFullRankCovariance} provides a compromise between the two: it computes covariance matrices in full in \\proglang{Fortran}, then factors them using the robust algorithm of \\pkg{chol_incomplete}.\n\n\\subsection{Drawing realizations}\\label{subsub:realizations}\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/realizations.pdf,width=8cm}\n    \\caption{Three realizations from a Gaussian process displayed with mean $\\pm$ 1 sd envelope. Generated by {\\sffamily `examples/realizations.py'}.}\n    \\label{fig:realizations}\n\\end{figure}\n\nThe code in \\texttt{pymc/examples/gp/realizations.py} generates a list of \\code{Realization} objects, which represent realizations (draws) from the Gaussian process defined by $M$ and $C$:\n\\begin{CodeChunk}\n\\begin{CodeInput}\nfrom mean import M\nfrom cov import C\nfrom pymc.gp import *\n\nf_list = [Realization(M,C) for i in range(3)]\n\\end{CodeInput}\n\\end{CodeChunk}\n\nThe init method of \\code{Realization} takes only two required arguments, a \\code{Mean} object and a \\code{Covariance} object. Each element of \\code{f_list} is a Gaussian process realization, which is essentially a randomly-generated \\proglang{Python} function. Like \\code{Mean} objects, \\code{Realization} objects use the same broadcasting rules as \\pkg{NumPy} universal functions. The call $f(x)$ returns the vector\n\\begin{eqnarray*}\n    [f(x_0)\\ldots f(x_{N-1})].\n\\end{eqnarray*}\n\nEach of the three realizations in \\code{f_list} is plotted in figure \\ref{fig:realizations}, superimposed on a $\\pm$ 1 standard deviation envelope.\n\n\n\\section{Nonparametric regression: observing Gaussian processes}\\label{sec:observing}\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/obs.pdf,width=5cm}\n        \\epsfig{file=figs/cond.pdf,width=5cm}\n    \\caption{The output of {\\sffamily `examples/observations.py'}: the observed GP with \\code{obs_V = .002} (left) and \\code{obs_V = 0} (right). Note that in the conditioned case, the $\\pm$ 1 SD envelope shrinks to zero at the points where the observations were made, and all realizations pass through the observed values. Compare these plots to those in figure \\ref{fig:realizations}.}\n    \\label{fig:obs}\n\\end{figure}\n\nConsider the following common statistical situation: A Gaussian process prior for an unknown function $f$ is chosen, then the value of $f$ is observed at $N$ input points $[o_0\\ldots o_{N-1}]$, possibly with uncertainty. If the observation error is normally distributed, it turns out that $f$'s posterior distribution given the new information is another Gaussian process, with new mean and covariance functions.\n\nThe probability model that represents this situation is as follows:\n\\begin{equation}\n    \\label{regprior}\n    \\left.\\begin{array}{l}\n        \\textup{data}_i \\stackrel{\\tiny{\\textup{ind}}}{\\sim} \\textup{N}(f(o_i), V_i)\\\\\n        f \\sim \\textup{GP}(M,C)\\\\\n    \\end{array}\\right\\}\\Rightarrow f|\\textup{data} \\sim \\textup{GP}(M_o, C_o).\n\\end{equation}\nFunction \\code{observe} imposes normally-distributed observations on Gaussian process distributions. This function converts $f$'s prior to its posterior by transforming $M$ and $C$ in equation \\ref{regprior} to $M_o$ and $C_o$:\n\nThe code in \\code{pymc/examples/gp/observation.py} imposes the observations\n\\begin{eqnarray*}\n    f(-.5) = 3.1\\\\\n    f(.5) = 2.9\n\\end{eqnarray*}\nwith observation variance $V=.002$ on the GP distribution defined in \\code{mean.py} and \\code{cov.py}:\n\\begin{CodeChunk}\n\\begin{CodeInput}\nfrom mean import M\nfrom cov import C\nfrom pymc.gp import *\nfrom numpy import *\n\nobs_x = array([-.5,.5])\nV = array([.002,.002])\ndata = array([3.1, 2.9])\nobserve(M=M, C=C, obs_mesh=obs_x, obs_V=V, obs_vals=data)\n\nf_list = [Realization(M,C) for i in range(3)]\n\\end{CodeInput}\n\\end{CodeChunk}\n\nThe function \\code{observe} takes a covariance $C$ and a mean $M$ as arguments, and tells them that their `true' realization's value on \\code{obs_mesh} has been observed to be \\code{obs_vals} with variance \\code{obs_V}. \n\nThe output of \\code{observation.py}  is shown in figure \\ref{fig:obs}, along with the output with \\code{obs_V=0}. Compare these to the analogous figure for the unobserved GP, figure \\ref{fig:realizations}. The covariance after observation is visualized in figure \\ref{fig:obscov}. The covariance `tent' has been pressed down at points where $x\\approx \\pm .5$ and/or $y\\approx\\pm .5$, which are the values where the observations were made.\n\n\\begin{figure}\n    \\centering\n        \\epsfig{file=figs/obscov.pdf,width=5cm}\n    \\caption{The covariance function from {\\sffamily `observation.py'} after observation. Compare this with the covariance function before observation, visualized in figure \\ref{fig:cov} }\n    \\label{fig:obscov}\n\\end{figure}\n\n\\section{Higher-dimensional GPs}\\label{sec:highdim}\n\nIn addition to functions of one variable such as $f(x)$, this package supports Gaussian process priors for functions of many variables such as $f(\\mathbf{x})$, where $\\mathbf{x}=[x_0\\ldots x_{n-1}]$. This is useful for modeling dynamical or biological functions of many variables as well as for spatial statistics.\n\nWhen array is passed into a \\code{Mean}, \\code{Covariance} or \\code{Realization}'s init method or one of these objects is evaluated on an array, the array's last index is understood to iterate over spatial dimension. To evaluate a covariance $C$ on the ordered pairs $(0,1)$, $(2,3)$, $(4,5)$ and $(6,7)$, the user could pass in the following two-dimensional \\pkg{NumPy} array:\n\\begin{verbatim}\n[[0,1]\n [2,3]\n [4,5]\n [6,7]]\n\\end{verbatim}\nor the following three-dimensional array:\n\\begin{verbatim}\n[[[0,1]\n  [2,3]],\n\n  [4,5]\n  [6,7]]]\n\\end{verbatim}\nEither is fine, since in both the last index iterates over elements of the ordered pairs.\n\nThe exception to this rule is one-dimensional input arrays. The array\n\\begin{verbatim}\n[0, 1, 2, 3, 4, 5, 6, 7]\n\\end{verbatim}\nis interpreted as an array of eight one-dimensional values, whereas the array\n\\begin{verbatim}\n[[0, 1, 2, 3, 4, 5, 6, 7]]\n\\end{verbatim}\nis interpreted as a single eight-dimensional value according to the convention above.\n\nMeans and covariances learn their spatial dimension the first time they are called or observed. Some covariances, such as those specified in geographic coordinates, have an intrinsic spatial dimension. Realizations inherit their spatial dimension from their means and covariances when possible, otherwise they infer it the first time they are called. If one of these objects is subsequently called with an input of a different dimension, it raises an error.\n\n\\subsection{Covariance function bundles and coordinate systems}\nThe examples so far, starting with \\code{examples/cov.py}, have used the covariance function \\code{matern.euclidean}. This function is an attribute of the \\code{matern} object, which is an instance of class \\code{covariance_function_bundle}.\n\nInstances of \\code{covariance_function_bundle} have three attributes, \\code{euclidean}, \\code{geo_deg} and \\code{geo_rad}, which correspond to standard coordinate systems:\n\\begin{itemize}\n    \\item \\code{euclidean}: $n$-dimensional Euclidean coordinates.\n    \\item \\code{geo_deg}: Geographic coordinates (longitude, latitude) in degrees, with unit radius.\n    \\item \\code{geo_rad}: Geographic coordinates (longitude, latitude) in radians, with unit radius.\n\\end{itemize}\n\nSee \\href{http://code.google.com/p/pymc}{the package documentation} for information regarding creation and extension of covariance function bundles.\n\n\\section{Basis covariances}\\label{sec:basis}\n\n\\begin{figure}[htbp]\n    \\centering\n        \\epsfig{file=figs/basiscov.pdf,width=8cm}\n        \\caption{Three realizations of an observed Gaussian process whose covariance is an instance of \\code{BasisCovariance}. The basis in this case is function \\code{fourier_basis} from module \\code{cov_funs}. 25 basis functions are used.}\n    \\label{fig:basiscov}\n\\end{figure}\n\nIt is possible to create random functions from linear combinations of finite sets of basis functions $\\{e\\}$ with random coefficients $\\{c\\}$:\n\\begin{eqnarray*}\n    f(x) = M(x) + \\sum_{i_0=0}^{n_0-1}\\ldots \\sum_{i_{N-1}=0}^{n_{N-1}-1} c_{i_1\\ldots i_{N-1}} e_{i_1\\ldots i_{N-1}}(x), \\\\\n    \\{c\\}\\sim \\textup{N}(0,K).\n\\end{eqnarray*}\nIt follows that $f$ is a Gaussian process with mean $M$ and covariance defined by\n\\begin{eqnarray*}\n    C(x,y)=\\sum_{i_0=0}^{n_0-1}\\ldots \\sum_{i_{N-1}=0}^{n_{N-1}-1} \\sum_{j_0=0}^{n_0-1}\\ldots \\sum_{j_{N-1}=0}^{n_{N-1}-1} e_{i_0\\ldots i_{N-1}}(x) e_{j_0\\ldots j_{N-1}}(x) K_{i_0\\ldots i_{N-1}, j_0\\ldots j_{N-1}},\n\\end{eqnarray*}\nwhere $K$ is the covariance of the coefficients $c$.\n\nParticularly successful applications of this general idea are:\n\\begin{description}\n    \\item[Random Fourier series:] $e_i(x) = \\sin(i\\pi x/L)$ or $\\cos(i\\pi x/L)$. See \\cite{spanos}.\n    \\item[Gaussian process convolutions:] $e_i(x) = \\exp(-(x-\\mu_n)^2)$. See \\cite{convolution}.\n    \\item[B-splines:] $e_i(x) = $ a polynomial times an interval indicator. See \\href{http://en.wikipedia.org/wiki/Basis_B-spline}{Wikipedia}'s article.\n\\end{description}\nSuch representations can be very efficient when there are many observations in a low-dimensional space, but are relatively inflexible in that they generally produce realizations that are infinitely differentiable. In some applications, this tradeoff makes sense.\n\nThis package supports basis representations via the \\code{BasisCovariance} class:\n\\begin{verbatim}\n    C = BasisCovariance(basis, cov, **basis_params)\n\\end{verbatim}\nThe arguments are:\n\\begin{description}\n    \\item[\\code{basis}:] Must be an array of functions, of any shape. Each basis function will be evaluated at $x$ with the extra parameters. The basis functions should obey the same calling conventions as mean functions: return values should have shape \\code{x.shape[:-1]} unless $x$ is one-dimensional, in which case return values should be of the same shape as \\code{x}. Note that each function should take the entire input array as an argument.\n    \\item[\\code{cov}:] An array whose shape is either:\n        \\begin{itemize}\n            \\item Of the same shape as \\code{basis}. In this case the coefficients are assumed independent, and \\code{cov[i[0],...,i[N-1]]} (an $N$-dimensional index) simply gives the prior variance of the corresponding coefficient.\n            \\item Of shape \\code{basis.shape * 2}, using \\proglang{Python}'s convention for tuple multiplication. In this case \\code{cov[i[0],...,i[N-1], j[0],...,j[N-1]]} (a $2N$-dimensional index) gives the covariance of $c_{i_0\\ldots i_{N-1}}$ and $c_{j_1\\ldots j_{N-1}}$.\n        \\end{itemize}\n        Internally, the basis array is ravelled and this covariance tensor is reshaped into a matrix. This input convention makes it easier to keep track of which covariance value corresponds to which coefficients. The covariance tensor must be symmetric (\\code{cov[i[0],...,i[N-1], j[0],...,j[N-1]]} $=$ \\code{cov[j[0],...,j[N-1], i[0],...,i[N-1]]}), and positive semidefinite when reshaped to a matrix.\n    \\item[\\code{basis_params}:] Any extra parameters required by the basis functions.\n\\end{description}\n\n\\section{Separable bases}\n\nMany bases, such as Fourier series, can be decomposed into products of functions as follows:\n\\begin{eqnarray*}\n    e_{i_0\\ldots i_{N-1}}(x) = \\prod_{j=0}^{N-1}e_{i_j}^j(x)\n\\end{eqnarray*}\nBasis covariances constructed using such bases can be represented more efficiently using \\code{SeparableBasisCovariance} objects. These objects are constructed just like \\code{BasisCovariance} objects, but instead of an $n_0\\times \\ldots \\times n_{N-1}$ array of basis functions they take a nested lists of functions as follows:\n\\begin{verbatim}\n    basis = [ [e[0][0], ... ,e[0][n[0]-1]]\n                       ...\n              [e[N-1][0], ... ,e[N-1][n[N-1]-1]] ].\n\\end{verbatim}\nFor an $N$-dimensional Fourier basis, each of the \\code{e}'s would be a sine or cosine; frequency would increase with the second index. As with \\code{BasisCovariance}, each basis needs to take the entire input array \\code{x} and \\code{basis_params} as arguments. See \\code{fourier_basis} in \\code{examples/gp/basiscov.py} for an example.\n\n\\subsection{Example}\n\nOnce created, a \\code{BasisCovariance} or \\code{SeparableBasisCovariance} object behaves just like a \\code{Covariance} object, but it and any \\code{Mean} and \\code{Realization} objects associated with it will take advantage of the efficient basis representation in their internal computations. An example of \\code{SeparableBasisCovariance} usage is given in \\code{pymc/examples/gp/basis_cov.py}. Compare its output in figure \\ref{fig:basiscov} to that in figure \\ref{fig:obs}.\n", "meta": {"hexsha": "6045e3d70e0f0d2c802917514fa5a18c73b9df43", "size": 18600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pymc/gp/Docs/tutorial1.tex", "max_stars_repo_name": "kyleabeauchamp/pymc", "max_stars_repo_head_hexsha": "6ce0094584f1fa00eed0b2ecee533c2fb7f190d6", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-06T08:17:20.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-06T08:17:20.000Z", "max_issues_repo_path": "pymc/gp/Docs/tutorial1.tex", "max_issues_repo_name": "kyleabeauchamp/pymc", "max_issues_repo_head_hexsha": "6ce0094584f1fa00eed0b2ecee533c2fb7f190d6", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-14T08:57:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T14:55:57.000Z", "max_forks_repo_path": "pymc/gp/Docs/tutorial1.tex", "max_forks_repo_name": "kyleabeauchamp/pymc", "max_forks_repo_head_hexsha": "6ce0094584f1fa00eed0b2ecee533c2fb7f190d6", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-05-11T06:17:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T23:22:46.000Z", "avg_line_length": 68.1318681319, "max_line_length": 643, "alphanum_fraction": 0.7346236559, "num_tokens": 5319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511579973932, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.653428467755992}}
{"text": "\\input{settings}\n\n\\begin{document}\n\n\\lhead{Hyperparameter tuning, Regularization \\\\ and Optimization}\n\\rhead{ Deep Learning specialization}\n\\cfoot{\\thepage \\ of \\pageref{LastPage}}\n\nSince deep learning is a highly empirical and iterative process, it's really helpfull \nto train models quickly. Having fast optimization algorithms is important and can\nreally speed up the efficiency of the process.\n\n\\section*{Mini-batch gradient descent}\n\nInstead of processing the entire dataset all at the same time in mini-batch gradient we\npartition the dataset in $N$ smaller subsets, then each subset $(X^{[t]}, Y^{[t]})$ of \nthe dataset are processed.\n\nWhen every subset of the dataset is processed we say that we did \"1 epoch\" or one single\npass through the training set. Usually several epochs are made.\n\nMini-batch gradient descent is considerably faster than normal gradient descent. A \ncomparison between the cost functions of batch and mini-batch gradient descent is given \nin the following image:\n\n\\begin{figure}[H]\n    \\begin{center}\n            \\includegraphics[width=0.9\\textwidth]{img/minibatch.png}\n            \\caption{Batch vs Mini-batch gradient descent cost function}\n        \\end{center}\n\\end{figure}\n\n\\textbf{Differente mini-batch sizes}\n\\begin{itemize}\n    \\item mini-batch size $m$ : Batch gradient descent.\n    \\item mini-batch size $1$ : Stochastic gradient descent.\n\\end{itemize}\n\nIn practice the best mini-batch size should be between $1$ and $m$; if you take mini-batch\nsize $m$ then it takes too long to train the neural network, in the other case taking\nsize = $1$ is really noisy and losses almost all the speed of doing vectorization.\n\n\\begin{figure}[H]\n    \\begin{center}\n            \\includegraphics[width=0.9\\textwidth]{img/descent.png}\n            \\caption{Comparison between mini-batch sizes}\n        \\end{center}\n\\end{figure}\n\n\\textbf{Which mini-batch size to choose?}\n\\begin{itemize}\n    \\item If the training set is small use batch gradient descent\n    \\item In any other case, typical mini-batch sizes are: $64,128,256,512,1024$. They're \n    all powers of two because of the way computer memory is layed out and accessed, \n    sometimes the code runs faster if the mini-batch size is a power of 2.\n\\end{itemize}\n\n\\section*{Exponentially weighted averages}\n\nExponentially weighted averages is a technique for smoothing time series data using the\nexponential window function. Let's say we have a sequence $\\{x_t\\}_{t=0}^n$, the output\nof the exponentially weighted averages is $\\{v_t\\}_{t=0}^n$ where:\n\\begin{align*}\n    v_0 &= x_0 \\\\\n    v_i &= \\beta v_{i-1} + (1-\\beta) x_i  && \\forall i>0\n\\end{align*}\n\nWhere $\\beta$ is the smoothing factor, $0 < \\beta < 1$ \n\\begin{figure}[H]\n    \\begin{center}\n            \\includegraphics[width=0.9\\textwidth]{img/es.png}\n            \\caption{Comparison between different smoothing factors}\n        \\end{center}\n\\end{figure}\n\nThe green line is for a greater $\\beta$ and the red line for a smaller $\\beta$, in general\nthe bigger the value of the smoothing factor the longer it takes for the exponentially \nweighted average to adapt.\n\nNotice that in general $v_i$ can be expressed as follows:\n\n\\begin{align*}\n    v_i &= \\beta v_{i-1} + (1-\\beta) x_i \\\\\n        &= (1-\\beta) x_i + \\beta(1-\\beta) x_{i-1} + \\beta^2 v_{i-2} \\\\\n        & \\quad \\vdots \\\\\n        &= (1-\\beta) x_i + \\beta(1-\\beta) x_{i-1} + \\beta^2(1-\\beta)x_{i-2} + \\dots + \\beta^i(1-\\beta)x_0\\\\\n        &= \\sum_{k=0}^i \\beta^{i-k} (1-\\beta) x_i\n\\end{align*}\n\nThat means that we have an exponentially decaying function.\n\n\\textbf{Bias correction in exponentially weighted averages}\n\nWhile computing the value og the exponentially weighted averages for small values of $t$\nthere's a bias because we have few observations and for big value of $\\beta$ the \nalgorithm may take a while to react to the inicialization. A way to correct this is by\nchanging $v_t$ with the following expression:\n\\begin{align*}\n    v_t^* := \\frac{v_t}{1-\\beta^t}\n\\end{align*}\nNotice that as $t$ grows $v_t^*$ approaches $v_t$.\n\n\\section*{Gradient descent with momentum}\n\nUsually this algorithm is faster than the standard gradient descent procedure. The idea\nis to compute an exponentially weighted average of the gradients and then use that\nto update the weights instead. Formally, Compute $dW, db$ normally with the current \nmini-batch, then:\n\\begin{align*}\n    V_{dW} &= \\beta V_{dW} + (1 - \\beta)dW \\\\\n    V_{db} &= \\beta V_{db} + (1 - \\beta)db \\\\\n    W &= W - \\alpha V_{dW} \\\\\n    b &= b - \\alpha V_{db}\n\\end{align*}\nSupose that when using the standard gradient descent you get a lot of oscilations \nwhen converging to the optimal value, using momentum can fix this because you are taking\ninto consideration the former results of the gradient therefore the oscilation starts\nto decrease and the covergence is faster.\n\n\\textbf{Intuition:} in the convex combination of $V_{dW}$ and $dW$ the derivative term\nrepresents the acceleration in the current point but the momentum term let's you take\ninto consideration the path traveled before.\n\nNotice that now you have another Hyperparameter, $\\beta$. Usually $\\beta = .9$ works \npretty well.\n\n\\section*{RMSprop}\n\nRMSprop, which stands for root mean square prop is another algorithm that can speed up\ngradient descent, on iteration $t$ we would compute $dW, db$ normally with the current \nmini-batch and then do the following calculation:\n\\begin{align*}\n    S_{dW} &= \\beta S_{dW} + (1 - \\beta)dW^2 \\\\\n    S_{db} &= \\beta S_{db} + (1 - \\beta)db^2 \\\\\n    W &= W - \\alpha \\frac{dW}{\\sqrt{S_{dW}}} \\\\\n    b &= b - \\alpha \\frac{db}{\\sqrt{S_{db}}}\n\\end{align*}\n\nObservation: Using RMSprop makes it posible to use a higher learning rate and perform\nfaster learning without diverging\n\n\\section*{Adam}\nAdam algorithm has been chown to work wll across a wide range of deep learning architectures,\nthe basic idea is to combine momentum and RMSprop. On iteration $t$ we would compute $dW, db$ normally with the current \nmini-batch and then do the following:\n\\begin{align*}\n    & \\text{Compute momentum and RMSprop:} \\\\\n    & V_{dW} = \\beta_1 V_{dW} + (1 - \\beta_1)dW  && V_{db} = \\beta_1 V_{db} + (1 - \\beta_1)db \\\\\n    & S_{dW} = \\beta_2 S_{dW} + (1 - \\beta_2)dW^2 && S_{db} = \\beta_2 S_{db} + (1 - \\beta_2)db^2 \\\\ \\\\\n    & \\text{Perform bias correction:} \\\\\n    & V_{dW}^{\\text{corr}} = \\frac{V_{dW}}{1-\\beta_1^t} && V_{db}^{\\text{corr}} = \\frac{V_{db}}{1-\\beta_1^t} \\\\\n    & S_{dW}^{\\text{corr}} = \\frac{S_{dW}}{1-\\beta_2^t} && S_{db}^{\\text{corr}} = \\frac{S_{db}}{1-\\beta_2^t} \\\\ \\\\\n    & \\text{Perform the update:} \\\\\n    & W = W - \\alpha \\frac{V_{dW}^{\\text{corr}}}{\\sqrt{S_{dW}^{\\text{corr}}}} \\\\\n    & b = b - \\alpha \\frac{V_{db}^{\\text{corr}}}{\\sqrt{S_{db}^{\\text{corr}}}} \\\\\n\\end{align*}\n\nHyperparameters choice:\n\\begin{itemize}\n    \\item $\\alpha : \\text{ needs to be tuned}$\n    \\item $\\beta_1 : .9$ \n    \\item $\\beta_2 : .999$\n\\end{itemize}\nThe betas can be tuned but usually those default values are used.\n\n\\section*{Learning rate decay}\nOne of the things that might help speed up the learning algorithm, is to slowly reduce \nthe learning rate over time. The idea is that during the initial phases while the learning rate \nalpha is still large, the algorithm shows a relatively fast learning. But then as alpha \ngets smaller, the steps it takes will be slower and smaller. And so it ends up oscillating \nin a tighter region around the minimum. If you never reduce the learning rate you might\noscilate a lot around the minimum without converging at all.\n\nThe most used formula to compute the learning rate is the following:\n\\begin{align*}\n    \\alpha = \\frac{1}{1 + \\text{decay\\_rate}*\\text{epoch}}\n\\end{align*}\n\nOther learning rate decay methods:\n\\begin{align*}\n    \\alpha = .95^{\\text{epoch}}\\alpha_0 && \\text{exponentially decay} \\\\\n    \\alpha = \\frac{k}{\\sqrt{\\text{epoch}}}\\alpha_0 && \\text{constant decay} \n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "a6e63b380316f37ed2b5cc419776c3b05016a725", "size": 7888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course-2-improving-neural-networks/notes/Note_2_optimization_algorithms.tex", "max_stars_repo_name": "SergioArnaud/deep-learning-specialization", "max_stars_repo_head_hexsha": "6e2b7f553ad7b15f1c58d6efbce6ed8fb6fbff75", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-03T02:10:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-04T00:07:13.000Z", "max_issues_repo_path": "course-2-improving-neural-networks/notes/Note_2_optimization_algorithms.tex", "max_issues_repo_name": "SergioArnaud/deep-learning-specialization", "max_issues_repo_head_hexsha": "6e2b7f553ad7b15f1c58d6efbce6ed8fb6fbff75", "max_issues_repo_licenses": ["MIT"], "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-2-improving-neural-networks/notes/Note_2_optimization_algorithms.tex", "max_forks_repo_name": "SergioArnaud/deep-learning-specialization", "max_forks_repo_head_hexsha": "6e2b7f553ad7b15f1c58d6efbce6ed8fb6fbff75", "max_forks_repo_licenses": ["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.6378378378, "max_line_length": 120, "alphanum_fraction": 0.6987829615, "num_tokens": 2294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.6533686665357851}}
{"text": "%!TEX root = main.tex\n\\paragraph{An introduction to Bempp}\nBempp \\cite{Betcke2021} is a Python based boundary element library for the Galerkin discretization of boundary integral operators in electrostatics, acoustics and electromagnetics.\nBempp originally started as mixed Python/C++ library.\nRecently, Bempp underwent a complete redevelopment and the current version Bempp-cl is written completely in Python with OpenCL kernels for the low-level computational routines that are just-in-time compiled for the underlying architecture during runtime.\nTo understand Bempp consider the simple boundary integral equation\n$$\n\\int_{\\Gamma} g(\\mathbf{r}, \\mathbf{r'}) \\phi(\\mathbf{r'})ds(\\mathbf{r'}) = f(\\mathbf{r})\n$$\nwhere $\\Gamma\\subset\\mathbb{R}^3$ is the surface of a bounded domain $\\Omega\\subset\\mathbb{R}^3$, and $g(\\mathbf{r}, \\mathbf{r'}) = \\frac{1}{4\\pi|\\mathbf{r}-\\mathbf{r'}|}$ is the electrostatic Green's function.\nA Galerkin discretization of this equation takes the form\n$$\nA\\mathbf{x} = b\n$$\nwith $A_{ij} = \\int_{\\Gamma}\\Psi_i(\\mathbf{r})\\int_{\\Gamma}g(\\mathbf{r}, \\mathbf{r'})\\phi_j(\\mathbf{r'})ds(\\mathbf{r'})ds(\\mathbf{r})$ and $b_i = \\int_{\\Gamma}\\psi_i(\\mathbf{r})f(\\mathbf{r})ds(\\mathbf{r})$.\nHere, the functions $\\Psi_j$ are a finite dimensional basis of $n$ test functions and the $\\phi_j$ are a finite dimensional basis of $n$ trial functions with the Galerkin solution being defined as $\\phi=\\sum_{i}\\mathbf{x}_j\\phi_j$.\nTypical choices for the test and trial functions are either piecewise constant functions or continuous, piecewise linear functions over a surface triangulation of $\\Gamma$. \nBy default, Bempp explicitly computes the matrix $A$ by applying quadrature rules to the arising integrals.\nThe singularity of the Green's function needs to be accounted for in the quadrature rules for integration over adjacent or identical test/trial triangles \\cite{ERICHSEN1998215}.\nFor well separated triangles standard triangle Gauss rules can be used for the quadrature.\nThe memory and computational complexity of this discretization is $\\mathcal{O}(n^2)$, which is practical for problems of size up to twenty or thirty thousand elements on a single workstation, depending on the available memory and number of CPU cores.\nBempp-cl evaluates the quadrature routines with highly optimized OpenCL kernels that make use of explicit AVX2/AVX-512 acceleration on CPUs.\n\n\\paragraph{FMM-accelerated evaluation of integral operators}\nWe can split up the action of the discretized integral operator $A$ onto a vector $\\mathbf{x}$ in the following way.\n\\begin{equation}\n\\label{eq:bempp_fmm_matvec}\nA\\mathbf{x} = P_2^T (G - C)P_1 \\mathbf{x} + S \\mathbf{x}.\n\\end{equation}\nThe matrices $P_1$ and $P_2$ are sparse matrices that convert the action of trial and test functions onto weighted sums over the quadrature points.\nThe matrix $G$ is a large dense matrix that contains the Green's function evaluation $g(\\mathbf{r}_i, \\mathbf{r}_j')$ over all quadrature points $\\mathbf{r}_i$ and $\\mathbf{r}_j'$ across all triangles.\nThe matrix $C$ is a sparse correction matrix that subtracts out the Green's function values over quadrature points associated with  adjacent triangles.\nThis is done since these triangles require a singularity adapted quadrature rule.\nBy explicitly subtracting out these contributions through the matrix $C$, we can use any code for the fast evaluation of particle sums of the type appearing in the $G$ matrix without the requirement to communicate to the summation code the geometry and singularity structure induced by the triangles of the surface mesh, a functionality that most such codes do not offer in any case.\nFinally, the matrix $S$ contains the contributions of $A$ arising from singularity adapted quadrature rules across adjacent or identical test/trial triangles.\nThis matrix is also highly sparse.\n\nWe explicitly compute the matrices $P_1$, $P_2$ and $S$, and keep them in memory using sparse storage.\nThe matrix $C$ is evaluated on the fly for each vector $\\mathbf{x}$ through a fast OpenCL kernel.\nThis leaves the matrix $G$.\nThe action of $G$ on the vector $\\mathbf{y}=P_1 \\mathbf{x}$ can be considered as a black-box to evaluate sums of the form\n%\n\\begin{align}\\label{eq:nbody_sum}\ns(\\mathbf{x}_i) = \\sum_j g(\\mathbf{r}_i, \\mathbf{r}_j')q_j.\n\\end{align}\n%\nTo evaluate this sum we use the C++ Exafmm library, a highly performant library that implements the kernel-independent fast multipole method (\\kifmm) to approximately evaluate sums of the above form.\nThe complexity of this evaluation is $\\mathcal{O}(N)$, where $N$ is the product of the number of surface triangles and the number of regular quadrature points per triangle.\nThe linear complexity means that we can scale the evaluation of the discretized integral operator from tens of thousands to millions of elements, allowing us to solve large electrostatic simulations on a single workstation. Details of the \\fmm implementation are discussed in the following section.\n", "meta": {"hexsha": "9a8119550d7f7e388c467cbdd2e537090350faa0", "size": 4979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/methods_bempp.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/methods_bempp.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/methods_bempp.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": 99.58, "max_line_length": 383, "alphanum_fraction": 0.7786704157, "num_tokens": 1265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.653353735426803}}
{"text": "\\lab{Data Structures II: Trees}{Data Structures II}\n\\label{lab:Python_DataStructures2}\n\n\\objective{A \\emph{Tree} is a linked list where each node in the list may refer to more than one other node. This structural flexibility makes trees more useful and efficient than regular linked lists in many applications. Many trees are most easily constructed recursively, so we begin with an overview of recursion. We then implement a recursively structured doubly linked Binary Search Tree. Finally, we compare the standard linked list, our Binary Search Tree, and an AVL tree to illustrate the relative strengths and weaknesses of each structure.}\n\n\\section*{Recursion} % ========================================================\n\nA \\emph{recursive} function is one that calls itself.\nWhen the function is executed, it continues calling itself until it reaches a specified \\emph{base case} where the solution to the problem is known.\nThe function then exits without calling itself again, and each previous function call is resolved.\n\nAs a simple example, consider the function that sums all positive integers from $1$ to some integer $n$.\nThis function may be represented recursively:\n\\[f(n) = \\sum_{i=1}^ni = n + \\sum_{i=1}^{n-1}i = n + f(n-1)\\]\n$f(n)$ may be calculated by recursively calculating $f(n-1)$, which calculates $f(n-2)$, and so on.\nThe recursion halts with the base case $f(1) = 1$.\n\n\\begin{lstlisting}\ndef recursive_sum(n):\n\t\"\"\"Calculate the sum of all positive integers in [1, n] recursively.\"\"\"\n    # Base Case: the sum of all positive integers in [1, 1] is 1.\n\tif n == 1:\n\t\treturn 1\n\n\t# If the base case hasn't been reached, the function recurses by calling\n    # itself on the next smallest integer. The result of that call, plus the\n    # particular 'n' from this call, gives the result.\n\telse:\n\t\treturn n + recursive_sum(n-1)\n\\end{lstlisting}\n\nThe computer calculates \\li{recursive_sum(5)} with a sequence of function calls.\n\n\\begin{lstlisting}\n# To find the recursive_sum(5), calculate recursive_sum(4).\n# But to find recursive_sum(4), calculate recursive_sum(3).\n# This continues until the base case is reached.\n\nrecursive_sum(5)\t\t# return 5 + recursive_sum(4)\n\trecursive_sum(4)\t\t# return 4 + recursive_sum(3)\n\t\trecursive_sum(3)\t\t# return 3 + recursive_sum(2)\n\t\t\trecursive_sum(2)\t\t# return 2 + recursive_sum(1)\n\t\t\t\trecursive_sum(1)\t\t# Base case: return 1.\n\\end{lstlisting}\n\nSubstituting the values that resulted from each call unwinds the recursion.\n\n\\begin{lstlisting}\nrecursive_sum(5)\t\t# return 5 + 10\n\trecursive_sum(4)\t\t# return 4 + 6\n\t\trecursive_sum(3)\t\t# return 3 + 3\n\t\t\trecursive_sum(2)\t\t# return 2 + 1\n\t\t\t\trecursive_sum(1)\t\t# Base case: return 1.\n\\end{lstlisting}\n\nSo \\li{recursive_sum(5)} returns 15 (which is correct, since $1 + 2 + 3 + 4 + 5 = 15$).\n\nMany problems that can be solved by iterative methods can also be solved (often more intuitively) with a recursive approach.\nConsider the function $g:\\mathbb{N}\\rightarrow\\mathbb{N}$ that calculates the $n^{th}$ Fibonacci number:\n\\[g(n) = g(n-1) + g(n-2),\\quad g(0)=0,\\quad g(1)=1\\]\nThe mathematical function itself is defined recusively, so it makes sense for an implementation to use recursion.\nCompare the following iterative method implementing $g$ to its recursive equivalent.\n\n\\begin{lstlisting}\ndef iterative_fib(n):\n\t\"\"\"Calculate the nth Fibonacci number iteratively.\"\"\"\n\tfibonacci = []          # Initialize an empty list.\n\tfibonacci.append(0)\t\t# Append 0 (the 0th Fibonacci number).\n\tfibonacci.append(1)\t\t# Append 1 (the 1st Fibonacci number).\n\tfor i in range(1, n):\n\t\t# Starting at the third entry, calculate the next number\n\t\t# by adding the last two entries in the list.\n\t\tfibonacci.append(fibonacci[-1] + fibonacci[-2])\n\t# When the entire list has been loaded, return the nth entry.\n\treturn fibonacci[n]\n\ndef recursive_fib(n):\n\t\"\"\"Calculate the nth Fibonacci number recursively.\"\"\"\n\t# The base cases are the first two Fibonacci numbers.\n\tif n == 0:\t\t\t\t# Base case 1: the 0th Fibonacci number is 0.\n\t\treturn 0\n\telif n == 1:\t\t\t# Base case 2: the 1st Fibonacci number is 1.\n\t\treturn 1\n\t# If this call isn't a base case, the function recurses by calling\n\t# itself to calculate the previous two Fibonacci numbers.\n\telse:\n\t\treturn recursive_fib(n-1) + recursive_fib(n-2)\n\\end{lstlisting}\n\nThis time, the sequence of function calls is slightly more complicated because \\li{recursive_fib()} calls itself twice at each step.\n\n\\begin{lstlisting}\nrecursive_fib(5)\t\t# The original call makes two additional calls:\n\trecursive_fib(4)\t\t# this one...\n\t\trecursive_fib(3)\n\t\t\trecursive_fib(2)\n\t\t\t\trecursive_fib(1)\t\t# Base case 2: return 1\n\t\t\t\trecursive_fib(0)\t\t# Base case 1: return 0\n\t\t\trecursive_fib(1)\t\t# Base case 2: return 1\n\t\trecursive_fib(2)\n\t\t\trecursive_fib(1)\t\t# Base case 2: return 1\n\t\t\trecursive_fib(0)\t\t# Base case 1: return 0\n\trecursive_fib(3)\t\t# ...and this one.\n\t\trecursive_fib(2)\n\t\t\trecursive_fib(1)\t\t# Base case 2: return 1\n\t\t\trecursive_fib(0)\t\t# Base case 1: return 0\n\t\trecursive_fib(1)\t\t# Base case 2: return 1\n\\end{lstlisting}\n\nThe sum of all of the base case results, from top to bottom, is $1 + 0 + 1 + 1 + 0 + 1 + 0 + 1 = 5$, so \\li{recursive_fib(5)} returns 5 (correctly).\nThe key to recursion is understanding the base cases correctly and making correct recursive calls.\n\n\\begin{problem} % Simple recursion for linked lists traversal\nThe following code defines a simple class for singly linked lists.\n\\begin{lstlisting}\nclass SinglyLinkedListNode(object):\n    \"\"\"Simple singly linked list node.\"\"\"\n    def __init__(self, data):\n        self.value, self.<<next>> = data, None\n\nclass SinglyLinkedList(object):\n    \"\"\"A very simple singly linked list with a head and a tail.\"\"\"\n    def __init__(self):\n        self.head, self.tail = None, None\n    def append(self, data):\n        \"\"\"Add a Node containing 'data' to the end of the list.\"\"\"\n        n = SinglyLinkedListNode(data)\n        if self.head is None:\n            self.head, self.tail = n, n\n        else:\n            self.tail.<<next>> = n\n            self.tail = n\n\\end{lstlisting}\nRewrite the following iterative function for finding data in a linked list using recursion.\nUse instances of the \\li{SinglyLinkedList} class to test your function.\n\\begin{lstlisting}\ndef iterative_search(linkedlist, data):\n    \"\"\"Search 'linkedlist' iteratively for a node containing 'data'.\"\"\"\n\tcurrent = linkedlist.head\n\twhile current is not None:\n\t\tif current.value == data:\n\t\t\treturn current\n\t\tcurrent = current.<<next>>\n\traise ValueError(str(data) + \" is not in the list.\")\n\\end{lstlisting}\n(Hint: define an inner function to perform the actual recursion.)\n\\label{prob:recursion}\n\\end{problem}\n\n\\begin{warn} % Iterative methods > Recursive methods, usually.\nIt is \\textbf{not} usually better to rewrite an iterative method recursively.\nIn Python, a function may only call itself 999 times.\nOn the $1000^{th}$ call, a \\li{RuntimeError} is raised to prevent a stack overflow.\nWhether or not recursion is appropriate depends on the problem to be solved and the algorithm used to solve it.\n\\end{warn}\n\n\\section*{Trees} % ============================================================\n\nA \\emph{tree} data structure is a specialized linked list.\nTrees are more difficult to build than standard linked lists, but they are almost always more efficient.\nWhile the computational complexity of finding a node in a linked list is $O(n)$, a well-built, balanced tree will find a node with a complexity of $O(\\log{n})$.\nSome types of trees can be constructed quickly but take longer to retrieve data, while others take more time to build and less time to retrieve data.\n\nThe first node in a tree is called the \\emph{root}.\nThe root node points to other nodes, called children.\nEach child node in turn points to its children.\nThis continues on each branch until its end is reached.\nA node with no children is called a \\emph{leaf node}.\n\nMathematically, a tree is a directed graph with no cycles.\nTherefore a linked lists as a graph qualifies as a tree, albeit a boring one.\nThe head node is the root node, and it has one child node.\nThat child node also has one child node, which in turn has one child.\nThe last node in the list is the only leaf node.\n\nOther kinds of trees may be more complicated.\n\n\\section*{Binary Search Trees} % ==============================================\n\nA \\emph{binary search tree} (BST) data structure is a tree that allows each node to have up to two children, usually called \\li{left} and \\li{right}.\nThe left child of a node contains data that is less than its parent node's data.\nThe right child's data is greater.\n\nThe tree on the right in Figure \\ref{fig:trees} is an example of a of binary search tree.\nIn practice, binary search tree nodes have attributes that keep track of their data, their children, and (in doubly linked trees) their parent.\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (4){4}\n        child {node[draw, circle] (5) {5} edge from parent[draw=none]}\n        child {node[circle,draw] (3) {3}edge from parent[draw=none]\n        child{node[draw,circle](2){2}edge from parent[draw=none]}\n        child{node[circle, draw](7){7}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (4a)[above of=4]{}\n        child {node[draw=none] (5a) {} edge from parent[draw=none]}\n        child {node[draw=none] (3a) {}edge from parent[draw=none]\n        child{node[draw=none](2a){}edge from parent[draw=none]}\n        child{node[draw=none](7a){}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (4b)[below of=4]{}\n        child {node[draw=none] (5b) {} edge from parent[draw=none]}\n        child {node[draw=none] (3b) {}edge from parent[draw=none]\n        child{node[draw=none](2b){}edge from parent[draw=none]}\n        child{node[draw=none](7b){}edge from parent[draw=none]}\n        };\n\\foreach \\s/\\t in {4a/5a, 4a/3a, 5a/2a, 3a/7a}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\n\\end{tikzpicture}\n\\qquad\n\\begin{tikzpicture}[\n    auto,\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (5a){5}\n        child {node[circle,draw] (2a) {2}edge from parent[draw=none]\n            child { node[circle,draw] (1a) {1}edge from parent[draw=none]}\n            child {node[draw = none] (invisble){} edge from parent[draw=none]}\n        }\n        child {node[circle,draw] (7a) {7}edge from parent[draw=none]\n        child{node[circle, draw](6a){6}edge from parent[draw=none]}\n        child{node[circle, draw](8a){8}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (i5a)[above of=5a]{}\n        child {node[draw=none] (i2a) {}edge from parent[draw=none]\n            child { node[draw=none] (i1a) {}edge from parent[draw=none]}\n            child {node[draw = none] (invisbleA){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (i7a) {}edge from parent[draw=none]\n        child{node[draw=none](i6a){}edge from parent[draw=none]}\n        child{node[draw=none](i8a){}edge from parent[draw=none]}\n        };\n\\foreach \\s/\\t in {i5a/i2a, i5a/i7a}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\\foreach \\s/\\t in {i2a/i1a, i7a/i6a, i7a/i8a}\n    {\\draw[->, >=stealth', shorten <=.27cm, shorten >=.1cm](\\s)--(\\t);}\n\\end{tikzpicture}\n\\caption{Both of these graphs are trees, but only the tree on the right is a binary search tree. How could the graph on the left be altered to make it a BST?}\n\\label{fig:trees}\n\\end{figure}\n\n\\begin{lstlisting}\nclass BSTNode(object):\n    \"\"\"A Node class for Binary Search Trees. Contains some data, a\n    reference to the parent node, and references to two child nodes.\n    \"\"\"\n    def __init__(self, data):\n        \"\"\"Construct a new node and set the data attribute. The other\n        attributes will be set when the node is added to a tree.\n        \"\"\"\n        self.value = data\n        self.prev = None      # A reference to this node's parent node.\n        self.left = None      # This node's value will be less than self.value\n        self.right = None     # This node's value will be greater than self.value\n\\end{lstlisting}\n\nThe actual binary search tree class has an attribute pointing to its root.\n\n\\begin{lstlisting}\nclass BST(object):\n    \"\"\"Binary Search Tree data structure class.\n    The 'root' attribute references the first node in the tree.\n    \"\"\"\n    def __init__(self):\n        \"\"\"Initialize the root attribute.\"\"\"\n        self.root = None\n\\end{lstlisting}\n\n\\subsection*{find()} % --------------------------------------------------------\n\nFinding a node in a binary search tree can be done recursively.\nStarting at the root, check if the target data matches the current node.\nIf it does not, then if the data is less than the current node's value, search again on the left child.\nIf the data is greater, search on the right child.\nContinue the process until the data is found or, if the data is not in the tree, an empty child is searched.\n\n\\begin{lstlisting}\nclass BST(object):\n    # ...\n    def find(self, data):\n        \"\"\"Return the node containing 'data'. If there is no such node\n        in the tree, or if the tree is empty, raise a ValueError.\n        \"\"\"\n\n        # Define a recursive function to traverse the tree.\n        def _step(current):\n            \"\"\"Recursively step through the tree until the node containing\n            'data' is found. If there is no such node, raise a Value Error.\n            \"\"\"\n            if current is None:                     # Base case 1: dead end.\n                raise ValueError(str(data) + \" is not in the tree.\")\n            if data == current.value:               # Base case 2: data found!\n                return current\n            if data < current.value:                # Recursively search left.\n                return _step(current.left)\n            else:                                   # Recursively search right.\n                return _step(current.right)\n\n        # Start the recursion on the root of the tree.\n        return _step(self.root)\n\\end{lstlisting}\n\n\\begin{info}\nConceptually, each node of a BST partitions the data of its subtree into two halves: the data that is less than the parent, and the data that is greater.\nWe will extend this concept to higher dimensions in the next lab.\n\\end{info}\n\n\\subsection*{insert()} % ------------------------------------------------------\n\nTo insert new data into a binary search tree, add a leaf node at the correct location.\nFirst, find the node that should be the parent of the new node.\nThis parent node is found recursively, using a similar approach to the \\li{find()} method.\nThen the new node is added as the left or right child of the parent.\nSee Figure \\ref{fig:BST.insertion}.\n\n\\begin{figure}[H] % BST.insert()\n\\begin{tikzpicture}[\n    auto,\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (5a){5}\n        child {node[circle,draw] (2a) {2}edge from parent[draw=none]\n            child { node[circle,draw] (1a) {1}edge from parent[draw=none]}\n            child {node[draw = none] (invisble){} edge from parent[draw=none]}\n        }\n        child {node[circle,draw] (7a) {7}edge from parent[draw=none]\n        child{node[circle, draw](3a){3}edge from parent[draw=none]}\n        child{node[circle, draw](8a){8}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (i5a)[above of=5a]{}\n        child {node[draw=none] (i2a) {}edge from parent[draw=none]\n            child { node[draw=none] (i1a) {}edge from parent[draw=none]}\n            child {node[draw = none] (invisbleA){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (i7a) {}edge from parent[draw=none]\n        child{node[draw=none](i3a){}edge from parent[draw=none]}\n        child{node[draw=none](i8a){}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (i5b)[below of=5a]{}\n        child {node[draw=none] (i2b) {}edge from parent[draw=none]\n            child { node[draw=none] (i1b) {}edge from parent[draw=none]}\n            child {node[draw = none] (invisbleB){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (i7b) {}edge from parent[draw=none]\n        child{node[draw=none](i3b){}edge from parent[draw=none]}\n        child{node[draw=none](i8b){}edge from parent[draw=none]}\n        };\n\\node [draw=none, black!20!blue, node distance=1.5cm](root)[above right of=5a]{root};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .1cm](root)--(5a);\n\\foreach \\s/\\t in {i5a/i2a, i2b/i5b, i5a/i7a, i7b/i5b}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\\foreach \\s/\\t in {i2a/i1a, i1b/i2b, i7a/i8a, i8b/i7b}\n    {\\draw[->, >=stealth', shorten <=.27cm, shorten >=.1cm](\\s)--(\\t);}\n\\end{tikzpicture}\n\\qquad\n\\begin{tikzpicture}[\n    auto,\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (5a){5}\n        child {node[circle,draw] (2a) {2}edge from parent[draw=none]\n            child { node[circle,draw] (1a) {1}edge from parent[draw=none]}\n            child {node[draw = none] (invisble){} edge from parent[draw=none]}\n        }\n        child {node[circle,draw] (7a) {7}edge from parent[draw=none]\n        child{node[circle, draw](3a){3}edge from parent[draw=none]}\n        child{node[circle, draw](8a){8}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (i5a)[above of=5a]{}\n        child {node[draw=none] (i2a) {}edge from parent[draw=none]\n            child { node[draw=none] (i1a) {}edge from parent[draw=none]}\n            child {node[draw = none] (invisbleA){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (i7a) {}edge from parent[draw=none]\n        child{node[draw=none](i3a){}edge from parent[draw=none]}\n        child{node[draw=none](i8a){}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (i5b)[below of=5a]{}\n        child {node[draw=none] (i2b) {}edge from parent[draw=none]\n            child { node[draw=none] (i1b) {}edge from parent[draw=none]}\n            child {node[draw = none] (invisbleB){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (i7b) {}edge from parent[draw=none]\n        child{node[draw=none](i3b){}edge from parent[draw=none]}\n        child{node[draw=none](i8b){}edge from parent[draw=none]}\n        };\n\\node [draw=none, black!20!blue, node distance=1.5cm](root)[above right of=5a]{root};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .1cm](root)--(5a);\n\\node [draw=none, black!20!blue, node distance=1.5cm](parent)[above left of=2a]{parent};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .1cm](parent)--(2a);\n\\foreach \\s/\\t in {i5a/i2a, i2b/i5b, i5a/i7a, i7b/i5b}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\\foreach \\s/\\t in {i2a/i1a, i1b/i2b, i2a/i3a, i3b/i2b, i7a/i8a, i8b/i7b}\n    {\\draw[->, >=stealth', shorten <=.27cm, shorten >=.1cm](\\s)--(\\t);}\n\\foreach \\s/\\t in {i2a/i3a, i3b/i2b}\n    {\\draw[red, ->, >=stealth', shorten <=.27cm, shorten >=.1cm](\\s)--(\\t);}\n\\end{tikzpicture}\n\\caption{To insert a node containing 3 to the BST on the left, start at the root and recurse down the tree to find the node that should be 3's parent. Connect that parent to the child, then the child to its new parent.}\n\\label{fig:BST.insertion}\n\\end{figure}\n\n\\begin{problem} % BST.insert()\nImplement the \\li{insert()} method in the \\li{BST} class.\n%\n\\begin{enumerate}\n\\item Find the parent of the new node.\nConsider writing a recursive method, similar to \\li{find()}, to do this.\nDetermine whether the new node will be the parent's left or right child, then double-link the parent and the new child.\n\\item Do not allow for duplicates in the tree. Raise a \\li{ValueError} if there is already a node in the tree containing the input data.\n\\end{enumerate}\n\nBe sure to consider the special case of inserting to an empty tree.\nTo test your tree, use (but do not modify) the provided \\li{BST.__str__()} method.\n\\end{problem}\n\n\\subsection*{remove()} % ------------------------------------------------------\n\nDeleting nodes from a binary search tree is more difficult than finding or inserting.\nInsertion always creates a new leaf node, but removal may delete any kind of node.\nThis leads to several different cases to consider.\n\n\\subsubsection*{Removing a Leaf Node} % - - - - - - - - - - - - - - - - - - - -\n\nIn Python, an object is automatically deleted if there are no references to it.\nCall the node to be removed the \\emph{target node}, and suppose it has no children.\nTo remove the target, find the target's parent, then delete the parent's reference to the target.\nThen there are no references to the target, so the target node is deleted.\nSince the target is a leaf node, removing it does not affect the rest of the tree structure.\n\n\\subsubsection*{Removing a Node with One Child} % - - - - - - - - - - - - - - -\n\nIf the target node has one or more children, be careful not to delete the children when the target is removed.\nSimply removing the target as if it were a leaf node would delete the entire subtree originating from the target.\n\nTo avoid deleting all of the target's descendents, point the target's parent to an appropriate successor.\nIf the target has only one child, then that child is the successor.\nConnect the target's parent to the successor, and double-link by setting the successor's parent to be the target node's parent.\nThen, since the target has no references pointing to it, it is deleted.\nThe target's successor, however, is pointed to by the target's parent, and so it remains in the tree.\n% TODO: Perhaps a figure for this one, as it is the hardest one to implement.\n\n\\subsubsection*{Removing a Node with Two Children} % - - - - - - - - - - - - -\n\nRemoval is more complicated if the target node has two children.\nTo delete this kind of node, first find its immediate in-order successor.\nThis successor is the node with the smallest value that is larger than the target's value.\nIt may be found by moving to the right child of the target (so that it's value is greater than the target's value), and then to the left for as long as possible (so that it has the smallest such value).\nNote that because of how the successor is chosen, any in-order successor can only have at most one child.\n\nOnce the successor is found, the target and its successor must switch places in the graph, and then the target must be removed.\nThis can be done by simply switching the values for the target and its successor.\nThen the node with the target data has at most one child, and may be deleted accordingly.\nIf the successor was chosen appropriately, then the binary search tree structure and ordering will be maintained once the deletion is finished.\n\nThe easiest way to implement this is to use recursion.\nFirst, because the successor has at most one child, remove the successor node recursively by calling \\li{remove()} on the successor's value.\nThen set the data stored in the target node as the successor's value.\nSee Figure \\ref{fig:BST.remove_twoChild}.\n\n\\begin{figure} % BST.remove() for removing a node with two children.\n\\begin{tikzpicture}[\n    auto,\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (5){5}\n        child {node[circle,draw] (2) {2}edge from parent[draw=none]\n            child { node[circle,draw] (1) {1}edge from parent[draw=none]\n            child{node[draw=none](invisible){} edge from parent[draw=none]}\n            child{node[draw,circle](3){3} edge from parent[draw=none]}\n       }\n            child {node[draw, circle] (4){4} edge from parent[draw=none]}\n        }\n    child {node[circle,draw] (9a) {9}edge from parent[draw=none]\n        child{node[draw=none](8){}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (5a)[above of=5]{}\n        child {node[draw=none] (2a) {}edge from parent[draw=none]\n            child { node[draw=none] (1a) {}edge from parent[draw=none]\n            child{node[draw=none](invisibleA){} edge from parent[draw=none]}\n            child{node[draw=none](3a){} edge from parent[draw=none]}\n        }\n            child {node[draw = none] (4a){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (9a) {}edge from parent[draw=none]\n        child{node[draw=none](8a){}edge from parent[draw=none]}\n        };\n\n    \\node [draw=none, node distance=.1cm] (5b)[below of=5]{}\n        child {node[draw=none] (2b) {}edge from parent[draw=none]\n            child { node[draw=none] (1b) {}edge from parent[draw=none]\n            child{node[draw=none](invisibleB){} edge from parent[draw=none]}\n            child{node[draw=none](3b){} edge from parent[draw=none]}\n        }\n            child {node[draw = none] (4b){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (9b) {}edge from parent[draw=none]\n        child{node[draw=none](8b){}edge from parent[draw=none]}\n        };\n\\node [draw=none, black!20!blue, node distance=2cm](target)[left of=2a]{target};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .2cm](target)--(2a);\n\\node [draw=none, black!20!blue, node distance=2cm](successor)[right of=3a]{successor};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .2cm](successor)--(3a);\n\\foreach \\s/\\t in {2a/1a, 1b/2b, 2a/4a, 4b/2b, 5a/2a, 2b/5b, 5a/9a, 9b/5b, 4a/3a, 3b/4b}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\\end{tikzpicture}\n\\qquad\n\\begin{tikzpicture}[\n    auto,\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (5){5}\n        child {node[circle,draw] (2) {3}edge from parent[draw=none]\n            child { node[circle,draw] (1) {1}edge from parent[draw=none]\n            child{node[draw=none](invisible){} edge from parent[draw=none]}\n            child{node[draw,circle](3){2} edge from parent[draw=none]}\n       }\n            child {node[draw, circle] (4){4} edge from parent[draw=none]}\n        }\n    child {node[circle,draw] (9a) {9}edge from parent[draw=none]\n        child{node[draw=none](8){}edge from parent[draw=none]}\n        };\n    \\node [draw=none, node distance=.1cm] (5a)[above of=5]{}\n        child {node[draw=none] (2a) {}edge from parent[draw=none]\n            child { node[draw=none] (1a) {}edge from parent[draw=none]\n            child{node[draw=none](invisibleA){} edge from parent[draw=none]}\n            child{node[draw=none](3a){} edge from parent[draw=none]}\n        }\n            child {node[draw = none] (4a){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (9a) {}edge from parent[draw=none]\n        child{node[draw=none](8a){}edge from parent[draw=none]}\n        };\n\n    \\node [draw=none, node distance=.1cm] (5b)[below of=5]{}\n        child {node[draw=none] (2b) {}edge from parent[draw=none]\n            child { node[draw=none] (1b) {}edge from parent[draw=none]\n            child{node[draw=none](invisibleB){} edge from parent[draw=none]}\n            child{node[draw=none](3b){} edge from parent[draw=none]}\n        }\n            child {node[draw = none] (4b){} edge from parent[draw=none]}\n        }\n        child {node[draw=none] (9b) {}edge from parent[draw=none]\n        child{node[draw=none](8b){}edge from parent[draw=none]}\n        };\n\\node [draw=none, black!20!blue, node distance=2cm](target)[left of=2a]{target};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .2cm](target)--(2a);\n\\node [draw=none, black!20!blue, node distance=2cm](successor)[right of=3a]{successor};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .2cm](successor)--(3a);\n\\foreach \\s/\\t in {2a/1a, 1b/2b, 2a/4a, 4b/2b, 5a/2a, 2b/5b, 5a/9a, 9b/5b}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\\end{tikzpicture}\n\\caption{To remove the node containing 2 from the top left BST, locate the target and its in-order successor. Delete the successor, recording its value. Finally, replace the data in the target with the data that was in the successor.}\n\\label{fig:BST.remove_twoChild}\n\\end{figure}\n\n\\subsubsection*{Removing the Root Node} % - - - - - - - - - - - - - - - - - - -\n\nIn each of the above cases, we must also consider the subcase where the target is the root node.\nIf the root has no children, resetting the root or calling the constructor will do.\nIf the root has one child, that child becomes the new root of the tree.\nIf the root has two children, the successor becomes the new root of the tree.\n\n\\begin{problem} % BST.remove()\nImplement the \\li{remove()} method in the \\li{BST} class.\nIf the tree is empty, or if the target node is not in the tree, raise a \\li{ValueError}.\nTest your solutions thoroughly, accounting for all possible cases:\n\\begin{enumerate}\n\\item The tree is empty (\\li{ValueError}).\n\\item The target is not in the tree (\\li{ValueError}).\n\\item The target is the root node:\n\t\\begin{enumerate}\n\t\\item the root is a leaf node, hence the only node in the tree.\n\t\\item the root has one child.\n\t\\item the root has two children.\n\t\\end{enumerate}\n\\item The target is in the tree but is not the root:\n\t\\begin{enumerate}\n\t\\item the target is a leaf node.\n\t\\item the target has one child.\n\t\\item the target has two children.\n\t\\end{enumerate}\n\\end{enumerate}\n(Hints: \\textbf{Before coding anything}, outline the entire function with comments and \\li{if}-\\li{else} blocks.\nUse the \\li{find()} method wherever appropriate.)\n\\end{problem}\n\n\\section*{AVL Trees} % ========================================================\n\nBinary search trees are a good way of organizing data so that it is quickly accessible.\nHowever, pathologies may arise when certain data sets are stored using a basic binary serch tree.\nThis is best demonstrated by inserting ordered data into a binary search tree.\nSince the data is already ordered, each node will only have one child, and the result is essentially a linked list.\n\n\\begin{lstlisting}\n# Sequentially adding ordered integers destroys the efficiency of a BST.\n>>> unbalanced_tree = BST()\n>>> for i in range(10):\n...     unbalanced_tree.insert(i)\n...\n# The tree is perfectly flat, so it loses its search efficiency.\n>>> print(unbalanced_tree)\n[0]\n[1]\n[2]\n[3]\n[4]\n[5]\n[6]\n[7]\n[8]\n[9]\n\\end{lstlisting}\n\nProblems also arise when one branch of the tree becomes much longer than the others, leading to longer search times.\n\nAn \\emph{AVL tree} (named after Georgy Adelson-Velsky and Evgenii Landis) is a tree that prevents any one branch from getting longer than the others.\nIt accomplishes this by recursively ``balancing'' the branches as nodes are added.\nSee Figure \\ref{fig:avl_balance}.\nThe AVL's balancing algorithm is beyond the scope of this project, but details and exercises on the algorithm can be found in Chapter 2 of the Volume II text.\n\n\\begin{figure}[H] % AVL Tree\n\\begin{tikzpicture}[\n    auto,\n    level 1/.style={sibling distance=2cm},\n    level 2/.style={sibling distance=20mm}]\n\n    \\node [circle,draw] (4){4}\n    child{node[draw, circle](2){2}edge from parent[draw=none]\n        child{node[draw, circle](1){1}edge from parent[draw=none]}\n        child{node[draw, circle](3){3}edge from parent[draw=none]}\n    }\n    child{node[draw,circle](5){5}edge from parent[draw=none]\n        child{node[draw=none](invisible){}edge from parent[draw=none]}\n        child{node[draw, circle](6){6}edge from parent[draw=none]}\n    };\n\n    \\node [draw=none, node distance=.1cm] (4a)[above of=4]{}\n    child{node[draw=none](2a){}edge from parent[draw=none]\n        child{node[draw=none](1a){}edge from parent[draw=none]}\n        child{node[draw=none](3a){}edge from parent[draw=none]}\n    }\n    child{node[draw=none](5a){}edge from parent[draw=none]\n        child{node[draw=none](invisibleA){}edge from parent[draw=none]}\n        child{node[draw=none](6a){}edge from parent[draw=none]}\n    };\n\n    \\node [draw=none, node distance=.1cm] (4b)[below of=4]{}\n    child{node[draw=none](2b){}edge from parent[draw=none]\n        child{node[draw=none](1b){}edge from parent[draw=none]}\n        child{node[draw=none](3b){}edge from parent[draw=none]}\n    }\n    child{node[draw=none](5b){}edge from parent[draw=none]\n        child{node[draw=none](invisibleB){}edge from parent[draw=none]}\n        child{node[draw=none](6b){}edge from parent[draw=none]}\n    };\n\n\\foreach \\s/\\t in {4a/2a, 2a/1a, 2a/3a, 4a/5a, 5a/6a}\n    {\\draw[->, >=stealth', shorten <=.23cm, shorten >=.1cm](\\s)--(\\t);}\n\\node [draw=none, black!20!blue, node distance=1.5cm](root)[above right of=4a]{root};\n\\draw[black!20!blue, ->, >=stealth', shorten >= .1cm](root)--(4);\n\n\\end{tikzpicture}\n\\caption{The balanced AVL tree resulting from inserting 1, 2, 3, 4, 5, and 6, in that order. After each insertion the tree rebalances if necessary.}\n\\label{fig:avl_balance}\n\\end{figure}\n\n\\newpage\n\n\\begin{lstlisting}\n>>> balanced_tree = AVL()\n>>> for i in range(10):\n...     balanced_tree.insert(i)\n...\n# The AVL tree is balanced, so it retains (and optimizes) its search efficiency.\n>>> print(balanced_tree)\n[3]\n[1, 7]\n[0, 2, 5, 8]\n[4, 6, 9]\n\\end{lstlisting}\n\n\\begin{problem} % Compare build and search times.\nWrite a function to compare the build and search times of the data structures we have implemented so far.\n\nRead the file \\texttt{english.txt}, adding the contents of each line to a list of data.\nFor various values of $n$, repeat the following:\n%\n\\begin{enumerate}\n\\item Get a subset of $n$ \\textbf{random} items from the data set.\n\\\\(Hint: use a function from the \\li{random} or \\li{np.random} modules.)\n\\item Time (separately) how long it takes to load a new \\li{SinglyLinkedList}, a \\li{BST}, and an \\li{AVL} with the $n$ items.\n\\item Choose 5 \\textbf{random} items from the subset, and time how long it takes to find all 5 items in each data structure.\nUse the \\li{find()} method for the trees, but to avoid exceeding the maximum recursion depth, use the provided \\li{iterative_search()} function from Problem \\ref{prob:recursion} to search the \\li{SinglyLinkedList}.\n\\end{enumerate}\n\nReport your findings in a single figure with two subplots: one for build times, and one for search times.\nUse log scales if appropriate.\n\n\\begin{comment} % TODO: Decide whether or not to show them these plots.\nYour figure should resemble the following plots, though your results may be less smooth.\n%\n\\begin{figure}[H] % Solution to problem 4.\n    \\centering\n    \\begin{subfigure}[b]{.5\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{BuildTimes.pdf}\n    \\end{subfigure}%\n    \\begin{subfigure}[b]{.5\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{SearchTimes.pdf}\n    \\end{subfigure}\n    % \\caption{The \\li{SinglyLinkedList} has the fastest build times, but the \\li{AVL} has the fastest search times. How would the graphs be different if the data had been sorted to begin with?}\n\\end{figure}\n\\end{comment}\n\\end{problem}\n\n\\section*{Conclusion} % =======================================================\n\nEvery data structure has advantages and disadvantages.\nRecognizing when an application may take advantage of a certain structure, especially when that structure is more complicated than a Python list or set, is an important skill.\nChoosing structures wisely often results in huge speedups and easier data maintenance.\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Improvements to the BST} % ---------------------------------------\n\nThe following are a few ideas for improving the \\li{BST} class.\n\n\\begin{enumerate}\n\\item Add a keyword argument to the constructor so that if an iterable is input, each element of the iterable is immediately added to the tree.\nThis makes it possible to cast other iterables as a \\li{BST}, like\nPython's standard data structures.\n\\item Add an attribute that keeps track of the number of items in the tree.\nUse this attribute to implement the \\li{__len__()} magic method.\n\\item Add a method for translating the \\li{BST} into a sorted Python list using a depth-first search.\n\\\\(Hint: examine the provided \\li{__str__()} method carefully.)\n\\end{enumerate}\n\n\\subsection*{Other Trees} % ---------------------------------------------------\n\nThere are many variations on the Binary Search Tree, each with its own advantages and disadvantages.\nConsider writing classes for the following structures.\n%\n\\begin{enumerate}\n\\item A \\href{https://en.wikipedia.org/wiki/B-tree}{\\emph{B-Tree}} is a tree whose nodes can contain more than one piece of data and point to more than one other node.\nSee Chapter 2 of the Volume II text for details.\n\n\\item The nodes of a \\href{https://en.wikipedia.org/wiki/Red%E2%80%93black_tree}{\\emph{Red-Black Tree}} are labeled either red or black.\nThe tree satisfies the following rules.\n%\n\\begin{enumerate}\n    \\item Every leaf node is black.\n    \\item Red nodes only have black children.\n    \\item Every (directed) path from a node to any of its descendent leaf nodes contains the same number of black nodes.\n\\end{enumerate}\n%\nWhen a node is added that violates one of these constraints, the tree is rebalanced and recolored.\n\n\\item A \\href{https://en.wikipedia.org/wiki/Splay_tree}{\\emph{Splay Tree}} includes an additional operation, called splaying, that makes a specified node the root of the tree.\nSplaying several nodes of interest makes them easier to access because they will be close to the root.\n\\end{enumerate}\n\n", "meta": {"hexsha": "83f6fb24c15939c73c8c34710bf72863caed9f2c", "size": 37440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/DataStructures2-Trees/DS2.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2A/DataStructures2-Trees/DS2.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2A/DataStructures2-Trees/DS2.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 48.3720930233, "max_line_length": 552, "alphanum_fraction": 0.6729700855, "num_tokens": 10644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.6533376206861108}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{color}\n\\usepackage[breaklinks,colorlinks=true]{hyperref}\n\n\\definecolor{Blue}{RGB}{0,122,255}\n\\hypersetup{colorlinks,breaklinks,urlcolor=Blue,linkcolor=Blue,citecolor=Blue,urlcolor=Blue}\n\n\\def\\Pr{\\mathop{\\mathbb{P}}}\n\\newcommand\\Ex{\\mathop{\\mathbb{E}}}\n\\newcommand\\br[1]{\\left(#1\\right)}\n\\newcommand\\bbr[1]{\\left[#1\\right]}\n\\newcommand\\cbr[1]{\\left\\{#1\\right\\}}\n\\newcommand\\pd[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\n\\begin{document}\n\n\\title{Price and greeks of European binary option}\n\\date{}\n\n\\maketitle\n\n\nConsider an asset with spot price $S = \\{S_t; 0 \\leq t \\leq T\\}$ following geometric Brownian motion of volatility $\\sigma$.\n\nA European binary call option with strike $K$ and maturity $T$ pays off\n\\begin{align}\n    \\text{Payoff}_\\text{Call}\n        = 1_{S_T \\geq K} ,\n\\end{align}\nwhere\n$1_{S_T \\geq K}$ is an indicator function.\nA European binary put option with the same strike and maturity pays off\n\\begin{align}\n    \\text{Payoff}_\\text{Put}\n        = 1_{S_T \\leq K} .\n\\end{align}\n\n\n\n\\section*{Price}\n\n\nThe price of the European binary call option is given by\n\\begin{align}\n    \\text{Price}_\\text{Call}\n        = \\Ex[1_{S_T \\geq K}] = N(d_2) ,\n\\end{align}\nwhere\n$N$ is the cumulative distribution function of the normal distribution and\n\\begin{align}\n    d_2\n        = \\frac{\\log (S_0 / K)}{\\sigma \\sqrt{T}} - \\frac12 \\sigma \\sqrt{T} .\n\\end{align}\n\nThe price of a European binary put option is given by $1 - \\text{Price}_\\text{Call}$\nbecause a relation $\\text{Payoff}_\\text{Call} + \\text{Payoff}_\\text{Put} = 1$ holds almost surely.\n\n\n\\section*{Delta}\n\n\nDelta is given by\n\\begin{align}\n    \\text{Delta}_\\text{Call}\n        = \\frac{N^\\prime(d_2)}{S_0 \\sigma \\sqrt{T}} ,\n\\end{align}\nwhere\nwe used a derivative $\\partial d_2 / \\partial S_0 = 1 / (S_0 \\sigma \\sqrt{T})$.\n\nDelta of a European binary put option is $\\text{Delta}_\\text{Put} = - \\text{Delta}_\\text{Call}$.\n\n\n\\section*{Gamma}\n\n\nGamma of the European binary option is given by\n\\begin{align}\n    \\text{Gamma}\n        = \\frac{N^{\\prime\\prime}(d_2)}{S_0^2 \\sigma^2 T}\n            - \\frac{N^{\\prime}(d_2)}{S_0^2 \\sigma \\sqrt{T}}\n        = - \\frac{N^{\\prime}(d_2)}{S_0^2 \\sigma \\sqrt{T}}\n            \\br{\\frac{d_2}{\\sigma \\sqrt{T}} + 1} ,\n    \\label{eq:gamma}\n\\end{align}\nwhere we used a relation $N^{\\prime\\prime}(x) = - x N^\\prime(x)$ to show the second equality.\n\nGamma of a European binary put option is $\\text{Gamma}_\\text{Put} = - \\text{Gamma}_\\text{Call}$.\n\n\n\\end{document}\n", "meta": {"hexsha": "00d8ef853c69a5a812455388182ddf6526e4c876", "size": 2519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/notes/european_binary.tex", "max_stars_repo_name": "YieldLabs/pfhedge", "max_stars_repo_head_hexsha": "a5ba9d054a8418cb8b27bb67d81a8fc8fb83ef57", "max_stars_repo_licenses": ["MIT"], "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/notes/european_binary.tex", "max_issues_repo_name": "YieldLabs/pfhedge", "max_issues_repo_head_hexsha": "a5ba9d054a8418cb8b27bb67d81a8fc8fb83ef57", "max_issues_repo_licenses": ["MIT"], "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/notes/european_binary.tex", "max_forks_repo_name": "YieldLabs/pfhedge", "max_forks_repo_head_hexsha": "a5ba9d054a8418cb8b27bb67d81a8fc8fb83ef57", "max_forks_repo_licenses": ["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.7978723404, "max_line_length": 124, "alphanum_fraction": 0.6645494244, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6531706195418308}}
{"text": "\\chapter{Code Examples}\n\n\\section{Colour Conversion}\n\nThis code enables conversion between RGB channel intensities into greyscale luminance using different conversion methods based on their respective colourspace recommendations in a variety of modes. A starting discussion on the effects of different methods can be found \\hyperlink{http://cadik.posvete.cz/color_to_gray_evaluation/}{here}\n\n\\begin{lstlisting}\nimport numpy as np\nfrom math import sqrt\n\ndef convert_set_to_greyscale(cifar_set, method=0, gamma=1.0):\n\tconverted_set = np.empty((cifar_set.shape[0], 1, cifar_set.shape[2], cifar_set.shape[3]), 'float32')\n\tfor image_index, image in enumerate(cifar_set):\n\t\tfor row_index, row in enumerate(image[0]):\n\t\t\tfor pixel_index, pixel in enumerate(row):\n\t\t\tgrey = 0.0\n\t\t\tif method == 0:  # Rec.709 luminance\n\t\t\t\tgrey = (0.2126 * cifar_set[image_index, 0, row_index, pixel_index]) + \\\n\t\t\t\t(0.7152 * cifar_set[image_index, 1, row_index, pixel_index]) + \\\n\t\t\t\t(0.0722 * cifar_set[image_index, 2, row_index, pixel_index])\n\t\t\telif method == 1:  # NTSC/W3C luminance\n\t\t\t\tgrey = (0.299 * cifar_set[image_index, 0, row_index, pixel_index]) + \\\n\t\t\t\t(0.587 * cifar_set[image_index, 1, row_index, pixel_index]) + \\\n\t\t\t\t(0.114 * cifar_set[image_index, 2, row_index, pixel_index])\n\t\t\telif method == 2:\n\t\t\t\tgrey = sqrt(((0.299 * cifar_set[image_index, 0, row_index, pixel_index]) ** 2) +\n\t\t\t\t((0.587 * cifar_set[image_index, 1, row_index, pixel_index]) ** 2) +\n\t\t\t\t((0.114 * cifar_set[image_index, 2, row_index, pixel_index]) ** 2))\n\t\t\telif method == 3:\n\t\t\t\tgrey = sqrt(((0.2126 * cifar_set[image_index, 0, row_index, pixel_index]) ** 2) +\n\t\t\t\t((0.7152 * cifar_set[image_index, 1, row_index, pixel_index]) ** 2) +\n\t\t\t\t((0.0722 * cifar_set[image_index, 2, row_index, pixel_index]) ** 2))\n\t\t\telif method == 4:  # Simple mean of RGB\n\t\t\t\tgrey = ((cifar_set[image_index, 0, row_index, pixel_index]) +\n\t\t\t\t(cifar_set[image_index, 1, row_index, pixel_index]) +\n\t\t\t\t(cifar_set[image_index, 2, row_index, pixel_index])) / 3\n\t\t\telse:\n\t\t\t\tprint 'Error: This is not a valid conversion mode.\\n Reverting to colour.'\n\t\t\treturn cifar_set.astype('float32') / 255\n\t\t\n\t\tconverted_set[image_index, 0, row_index, pixel_index] = np.float32(grey/255)\n\tprint 'Converted ', len(converted_set), ' images to greyscale.'\n\treturn converted_set\n \n\\end{lstlisting}\n", "meta": {"hexsha": "6c957697d9216bd25e8fccd31f29447f559a7851", "size": 2323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Appendix3/appendix3.tex", "max_stars_repo_name": "Theonik/Convnet-demo", "max_stars_repo_head_hexsha": "ba80f65826cca9485c04ac6322bc752232a8b1b6", "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/Appendix3/appendix3.tex", "max_issues_repo_name": "Theonik/Convnet-demo", "max_issues_repo_head_hexsha": "ba80f65826cca9485c04ac6322bc752232a8b1b6", "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/Appendix3/appendix3.tex", "max_forks_repo_name": "Theonik/Convnet-demo", "max_forks_repo_head_hexsha": "ba80f65826cca9485c04ac6322bc752232a8b1b6", "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.5, "max_line_length": 336, "alphanum_fraction": 0.7072750753, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.653150482137537}}
{"text": "\nIn this section, we present the formal model for the synthesis problem.\nWe model glycan molecules and production rules as labeled trees. The glycan molecules are assembled by applying the production rules repeatedly.\nOur synthesis problem reduces into finding the pieces of trees that represent the production rules.\n\nLet $S$ be the set of sugar monomers that builds glycans,\nthe oligomer molecules. Each $s \\in S$ is associated with arity $m$ \n(written $arity(s) = m$).\n% , {\\em i.e.}, the maximum number of children for $s$.\nThe children of the monomers are indexed. We refer to the $k$th child of $s$ for some $k \\leq arity(s)$.\nThey correspond to bonds at specific positions in the monomers where children are connected.\nNow we define the glycan molecules as labeled trees. Now onward we refer to the glycans simply as molecules.\n\n\\begin{df}\nA {\\em molecule} $m = (V,M,C,v_0)$ is a labeled tree, where \n$V$ is a set of nodes in the tree,\n$M : V \\maps S$ maps nodes to their label, \n$C : V \\times \\naturals \\pmaps V$ maps the indexed children of nodes, and\n$v_0 \\in V$ is the root of $m$.\nA molecule must respect the arity of monomers, i.e., if $M(v) = s$ and $C(v,n) = v'$ then $n \\leq arity(s)$.\n\\end{df}\n% \\todo{Rewrite the following paragraph}\n% \\todo{definitions mixed with algorithms seems strange I think you should define all the formal stuff first and then present the algorithms}\nLet us define notations related to the tree structure.\nLet $\\mathit{m = (V,M,C,v_0)}$ and $m' = (V',M',C',v_0')$ be molecules.\nWith an abuse of notation, we write $v \\in m$ to denote $v \\in V$.\nFor each $v \\in m$, if $(v,n)$ is not in the domain of $C$, we write $C(v,n) = \\bot$.\nWe assume that $C(v,0) = \\bot$.\n%and if $n > n' > 0$ and $C(v,n) \\neq \\bot$, then $C(v,n') \\neq \\bot$.\nLet $NumberOfChildren(v)$ be equal to the number of $n$s such that $C(v,n) \\neq \\bot$. \nA node $v \\in V$ is a {\\em leaf} of $m$ if $C(v,n) = \\bot$ for each $n$.\nLet $depth(v)$ be the length of the path from $v_0$ to $v$.\nA {\\em branch} of $m$ is a path from $v_0$ to some leaf of $m$.\nLet $height(m)$ be the length of the longest branch in $m$.\nWe define ancestor relation recursively as follows. Let $ancestor(m,v,0) = v$.\nFor for $d > 0$, let $ancestor(m,v,d) = ancestor(m,v', d-1)$ if $C(v',i) = v$ for some $i$.\n\nSince we will be matching the parts of the trees and applying rules to expand them,\nlet us introduce notations for matching.\nLet recursively-defined predicate $Match(m,v,m',v')$ state that \n$v \\in m$, $v' \\in m'$, $s = M(v) = M(v')$, and $Match( m, C(v,n), m', C(v',n) )$ for each $n \\leq arity(s)$ such that $C(v,n) \\neq \\bot$.\nIn other words, the subtree in $m$ rooted at $v$ is embedded in $m'$ at node $v'$.\nLet $subtree(m)$ be the set of molecules such that\n$m' = (\\_,\\_,\\_,v_0') \\in subtree(m) \\lequiv Match(m,v_0,m',v_0')$.\nLet us also define a utility to copy a subtree of a molecule into another molecule.\nLet $Copy(m,v)$ return a molecule $m'' = (V'',M'',C'',v_0'')$ such that \n$V''$ is a set of fresh nodes, $Match(m,v,m'',v_0'')$, and $Match(m'',v_0'',m,v)$.\nBoth the $Match$ conditions say that the trees rooted at\n$v$ and $v_0''$ are identical.\n\nNow we define the model of the production process of the molecules.\nA production rule expands a molecule $m$ by attaching a new piece of tree at a node that has a vacant spot among its children if the surroundings of the\nnode satisfy some condition.\nThe rule is modeled as a tree that has two parts.\nOne part should already be there in $m$ and the other part will be appended to $m$.\n\n\\begin{df}\n  A {\\em production rule} $r = (V, M, C, v_0, v_e)$ is a labeled tree, where\n  $V$ is a set of nodes,\n  $M : V \\maps S$ maps nodes to labels, \n  $C : V \\times \\naturals \\pmaps V$ maps the indexed children of nodes,\n  $v_0 \\in V$ is the root, and\n  $v_e \\in V$ is the root of expanding part of the rule.\n\\end{df}\n\nIf we {\\em apply}, a rule $r$ on a molecule $m$, then it is extended at some node\n$v \\in m$. A copy of the descendants of $v_e$ will be attached to\n$v$ in $m$, and the rest of the nodes in the rule have to match $v$ and above.\nWe call the descendants of $v_e$ as {\\em expanding nodes}\nand all the other nodes as {\\em matching nodes}.\n\n\n\\begin{wrapfigure}{r}{0.37\\textwidth}\n  \\vspace{-12mm}\n    % \\begin{minipage}{0.48\\linewidth}\n      \\small\n    % \\center\n  \\begin{tikzpicture}[shorten >=1pt,thick,node distance=1cm,on grid]\n    \\node[loc] (v0) {$A$};\n    \\node[loc, below right of=v0] (v1) {$B$};\n    \\node[sqloc, below left of=v0] (v2) {$A$};\n    \\path[->] (v0) edge (v1);\n    \\path[->] (v0) edge (v2);\n  \\end{tikzpicture}\n  % \\par\n  % (a)\n  % \\end{minipage}\n  % \\begin{minipage}{0.48\\linewidth}\n    % \\small\n    % \\center\n  \\quad\n  \\begin{tikzpicture}[shorten >=1pt,thick,node distance=1cm,on grid]\n    \\node[loc] (v0) {$A$};\n    \\node[loc, below right of=v0] (v1) {$A$};\n    \\node[loc, below right of=v1] (v3) {$B$};\n    \\node[loc, below left of=v1] (v2) {$A$};\n    \\path[->] (v0) edge (v1);\n    \\path[->,dashed] (v1) edge (v2);\n    \\path[->] (v1) edge (v3);\n  \\end{tikzpicture}\n  % \\par\n  \\hfill (a) \\hfill (b)\\hfill\\mbox{}\n  % (b)\n  % \\end{minipage}\n  \\caption{(a) A rule. (b) An application of the rule.}\n  \\label{fig:exrule}\n  \\vspace{-6mm}\n\\end{wrapfigure}\n\\paragraph{Example:} In Figure~\\ref{fig:exrule}(a), we present a rule. It has\n  two kinds of nodes.\n  The rule adds the square node ($v_e$).\n  The circular nodes %$A$ and its right child $B$\n  are the pattern, which must be present in the molecule to apply the rule.\n  In Figure~\\ref{fig:exrule}(b), we present an application of the rule.\n  The solid tree with three nodes is the initial molecule.\n  The middle node $A$ and its right child $B$ form a pattern, where the rule is applicable.\n  %Upon applying the rule,\n  The rule adds a left child with the label $A$ to the middle node.\n  The rule is not applicable at the root $A$ due to pattern mismatch.\n  % , since it has a right child $A$\n  % and the combination does not match the pattern.\n\n\nWe naturally extend the definitions related to molecules, including $Match$ and $Copy$,\nto the production rules.\nLet us formally define the molecule productions using the rules.\nLet $m = (V,M,C,v_0)$ be a molecule and $r = (V_r, M_r, C_r, v_{0r}, v_e)$ be a production rule.\nLet $d$ be such that $v_{0r} = ancestor(r,v_e,d)$, i.e., $v_e$ is at the depth $d$ in $r$.\nLet $i$ be such that $C_r(v',i) = v_{0r}$ for some $v' \\in r$.\nWe apply $r$ on $m$ at node $v \\in m$ such that $C(v,i) = \\bot$.\nWe obtain an expanded molecule as follows.\nLet $(V',M',C',v_0') = Copy(r,v_e)$.\nThe expanded molecule is\n$\nm' = (V \\uplus V', M \\uplus M', C \\uplus C' \\uplus \\{(v,i) \\mapsto v_0'\\}, v_0)\n$ if\n$Match( r, v_{0r}, m', ancestor(m', v_0', d) )$ where $\\uplus$ is the disjoint union.\nThe match condition states that after attaching the new nodes $V'$\nthe rule tree must be embedded in $m'$ at the $d$th ancestor of $v'_0$. \nWe write $m' = Apply(m, v, r)$ to indicate the application of $r$\non molecule $m$ at node $v$ that results in $m'$.\nIf $r$ is not applicable at $v$, we write $Apply(m, v, r) = \\bot$.\nWe write $m' = Apply(m, r)$ if there is a $v \\in m$ such that\n$m' = Apply(m,v,r)$.\n\nLet $R$ be a set of rules.\nA molecule $m$ is {\\em producible} by $R$ from a set of molecules $Q$\nif there is sequence of molecules $m_0,...,m_k$\nsuch that $m_0 \\in Q$, $m_k=m$, and\nfor each $0<i\\leq k$, $m_{i} = Apply(m_{i-1},r)$ for some $r \\in R$.\nLet $P(Q,R)$ denote the set of molecules that are producible from\nrules $R$ from a set of molecules $Q$.\nWe have discussed in Section~\\ref{sec:bio} that all the production rules\nare not applied at the same time.\nThe rules may live in compartments and\nthe rule sets of the compartments are applied one after another.\nTo model compartments for the rules,\nlet us suppose we have a sequence $R_1,...,R_k$ of set of rules.\nLet $P(Q, R_1,..,R_k) = P(..P(P(Q,R_1),R_2),..,R_k)$ denoting the\ntrees obtained after applying the rule sets one after another.\n\n% \\subsection{Synthesis problem}\nIn nature, we observe a set of glycan molecules $\\mu$ present in a cell.\n%\nHowever, we may not know the production rules to produce the molecules.\n%\nWe will be developing a method to find the rules.\n%\nThe {\\em synthesis problem} is to find a set $R$ of production rules\nsuch that $\\mu = P(S,R)$,\nwhere $S$ is the set of monomers.\n\n% %\n% We can define a more general form of the synthesis problem.\n% Let us suppose we are also given $k$ compartments with unknown rules.\n% The goal of synthesis is to find  $R_1,...,R_k$ such that\n% $\\mu = P(S, R_1,..,R_k)$.\n% We may relax the requirement of exactly producing $\\mu$.\n% We may say that molecules in $\\mu$ have to be produced, but we are ok\n% if subtrees of the molecules of $\\mu$ are also produced.\n% Formally, we may weaken the requirement to $\\mu \\subseteq P(Q, R_1,..,R_k) \\subseteq subtree(\\mu)$.\n\n% The above are a few simplified versions of the biological problem.\n% We may generalize the problem further where\n% %rules are partitioned and the partitions are applied in phases one after another,\n% rules are not applied exhaustively due to time constraints,\n% the given $\\mu$ is finite and may not be exhaustive,\n% and we only know the weights of the parts of molecules in $\\mu$.\n% We will first present a method for solving a simplified version of the problem.\n% However, our tool handles some of the above variations.\n% We will discuss the variations in section~\\ref{sec:variations}.\n\n%--------------------- DO NOT ERASE BELOW THIS LINE --------------------------\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "29853f2f539a1717c1f2bb4371d7911b122d7042", "size": 9578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/sugar-synth/model.tex", "max_stars_repo_name": "ashutosh0gupta/sugar-synth", "max_stars_repo_head_hexsha": "774a8c8e4d33334d13d0f836953e448a44c2eb9a", "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/sugar-synth/model.tex", "max_issues_repo_name": "ashutosh0gupta/sugar-synth", "max_issues_repo_head_hexsha": "774a8c8e4d33334d13d0f836953e448a44c2eb9a", "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/sugar-synth/model.tex", "max_forks_repo_name": "ashutosh0gupta/sugar-synth", "max_forks_repo_head_hexsha": "774a8c8e4d33334d13d0f836953e448a44c2eb9a", "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.1306532663, "max_line_length": 152, "alphanum_fraction": 0.6724785968, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427860270573, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6531504684060049}}
{"text": "\\documentclass[24pt, a4]{article}\n\n% \\usepackage[utf8]{inputenc}\n\\usepackage[parfill]{parskip}\n\\usepackage{listings}\n\\usepackage{geometry}\n\n\n\\title{Dynamic Programming}\n\\author{Mustafa Muhammad}\n\\date{25 September 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\nList of Questions:\n\n0-1 Knapsack\n\\begin{enumerate}\n  \\item Subset Sum\n  \\item Equal Sum Partition\n  \\item Count of Subset Sum with given Sum\n  \\item Minimum Subset Sum Difference\n  \\item Count number of subsets with given difference\n  \\item Target Sum\n\\end{enumerate}\nUnbounded Knapsack\n\\begin{enumerate}\n\t\\item Rod Cutting Problem\n\t\\item Max coin change problem\n\t\\item Min number of coins\n\\end{enumerate}\nLongest Common Subsequence (LCS)\n\\begin{enumerate}\n\t\\item Longest common substring\n\t\\item Shortest common supersequence\n\t\\item Min number of insertion\\ deletion to convert string a to b\n\t\\item Longest palindromic subsequence\n\t\\item Min number of deletions to make string into palindrome\n\t\\item Print shorest common supersequence\n\t\\item Longest repeating subsequence\n\t\\item Sequence pattern matching\n\t\\item Min number of insertions in a string to make it a palindrome\n\\end{enumerate}\nDp on Trees \n\\begin{enumerate}\n\t\\item Diameter of binary tree\n\t\\item Max path sum from any node\n\t\\item Max path sum from leaf to leaf\n\\end{enumerate}\n\n\\newpage\n\n\\section{0-1 Knapsack}\n\nYou are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. \n\n\n\n\\begin{lstlisting}\nclass Solution:\n    def __init__(self):\n        self.memo={}\n\n    def knapSack(self,W, wt, val, n):\n        key = (W, n)\n        if n == 0 or W == 0:\n            return 0\n            \n        if key in self.memo:\n            return self.memo[key]\n        \n        #Capacity less than the item's weight, so skip it    \n        if wt[n-1] > W:\n            self.memo[key] = self.knapSack(W, wt, val, n-1)\n            return self.memo[key]\n        \n        #Optimization step, to choose the maximum    \n        max_val = max(val[n-1] + self.knapSack(W-wt[n-1], wt, val, n-1),\n        self.knapSack(W, wt, val, n-1))\n        \n        self.memo[key] = max_val\n        \n        return self.memo[key]\n\\end{lstlisting}\n\n\nInput:\n\nN = 3\n\nW = 4\n\nvalues[] = {1,2,3}\n\nweight[] = {4,5,1}\n\nOutput: 3\n\n\\newpage\n\\section{Subset Sum}\n\nGiven an array of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.\n\n\\begin{lstlisting}\nclass Solution:\n    def __init__(self):\n        self.memo = {}\n        \n    def isSubsetSum (self, N, arr, sum):\n        key = (N, sum)\n        \n        if key in self.memo:\n            return self.memo[key]\n            \n        if N == 0 and sum != 0:\n            return False\n        \n        if sum == 0:\n            return True\n            \n        \n        if arr[N-1] > sum:\n            self.memo[key] = self.isSubsetSum(N-1, arr, sum)\n            return self.memo[key]\n        \n        self.memo[key] = self.isSubsetSum(N-1, arr, sum-arr[N-1]) \n        or self.isSubsetSum(N-1, arr, sum)\n        \n        return self.memo[key]\n\\end{lstlisting}\nInput:\n\nN = 6\n\narr[] = {3, 34, 4, 12, 5, 2}\n\nsum = 9\n\nOutput: 1 \n\nExplanation: Here there exists a subset with\nsum = 9, 4+3+2 = 9.\n\n\\newpage\n\\section{Subset sum -- Using backtracking and memoization}\n\\begin{lstlisting}\nclass Solution:\n    def isSubsetSum (self, N, arr, sum):\n        memo = {}\n        def combinations(N, arr, target, curr_sum):\n        \t\tkey = (N, curr_sum)\n        \t\tif key in memo:\n        \t\t\t\treturn memo[key]\n            if target == curr_sum:\n                return True\n            if N == 0:\n                return False\n            \n            curr_sum += arr[N-1]\n            a = combinations(N-1, arr, target, curr_sum)\n            curr_sum -= arr[N-1]\n            b = combinations(N-1, arr, target, curr_sum)\n            \n            memo[key] = a or b\n            return memo[key]\n            \n        return combinations(N, arr, sum, 0)\n\\end{lstlisting}\n\nIn practice the complexity should be the same as dynamic programming.\n\n\\newpage\n\\section{Equal Sum Partition}\n\nCrux of the solution is the fact that we cannot partition an array into equal parts which has an odd sum. If the array has an even sum, all we need to do is to call the boolean subsetSum on half of the total sum of the array.\n\n\\begin{lstlisting}\nclass Solution:\n    def canPartition(self, nums: List[int]) -> bool:\n        total = sum(nums)\n        \n        if total % 2 == 1:\n            return False\n        \n        memo = {}\n        \n        def subset_sum(i, nums, target):\n            key = (i, target)\n            if key in memo:\n                return memo[key]\n            if target == 0:\n                return True\n            \n            if i == 0 and target != 0:\n                return False\n            \n            if nums[i-1] > target:\n                memo[key] = subset_sum(i-1, nums, target)\n                return memo[key]\n            \n            memo[key] = subset_sum(i-1, nums, target-nums[i-1]) \n            or subset_sum(i-1, nums, target)\n            \n            return memo[key]\n        \n        return subset_sum(len(nums), nums, int(total/2))\n\\end{lstlisting}\n\nGiven a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.\n\nInput: nums = [1,5,11,5]\n\nOutput: true\n\nExplanation: The array can be partitioned as [1, 5, 5] and [11].\n\n\\newpage\n\\section{Count Number of subsets that add up to a target}\n\nThis problem can easily be solved by using backtracking and generating all the possible subsets. However that will lead to exponential time complexity.\n\nDynamic programming is an optimization technique used to reduce time complexity by building up from smaller / previous outputs.\n\n\\begin{lstlisting}\n\n\n\nclass Solution:\n    def perfectSum(self, arr, n, target):\n        memo = {}\n        def helper(arr, pos, target):\n            key = (pos, target)\n            if target == 0:\n                return 1\n            if pos == 0:\n                return 0\n            if key in memo:\n                return memo[key]\n            else:\n                if arr[pos-1] > target:\n                    memo[key] = helper(arr, pos-1, target)\n                    return memo[key]\n                else:\n                    memo[key] = helper(arr, pos-1, target-arr[pos-1])\n                    + helper(arr, pos-1, target)\n                    return memo[key]\n            return memo[key]\n\\end{lstlisting}\n\n\n\\newpage\n\\section{Minimum Subset Sum Difference}\n\nGiven a set of integers, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum. \n\nIf there is a set S with n elements, then if we assume Subset1 has m elements, Subset2 must have n-m elements and the value of abs(sum(Subset1) – sum(Subset2)) should be minimum.\n\n\\begin{lstlisting}\nclass Solution:\n    def minDifference(self, arr, n):        \n        memo = {}\n        \n        def subset_sum(arr, i, target):\n            key = (i, target)\n            if target == 0:\n                return True\n            if i == 0:\n                return False\n            if key in memo:\n                return memo[key]\n            if arr[i-1] > target:\n                memo[key] = subset_sum(arr, i-1, target)\n                return memo[key]\n            memo[key] = subset_sum(arr, i-1, target-arr[i-1]) \n            or subset_sum(arr, i-1, target)\n            return memo[key]\n        \n        Range = sum(arr)\n        ans = float('inf')\n        for i in range(0, int(Range/2)+1):\n            if subset_sum(arr, len(arr) , i):\n                ans = min(ans, Range - 2*i)\n        return ans\n\\end{lstlisting}\n\nThis is a hard question to grasp on the first try. The required answer is two subsets with the minimum difference. They can be labelled as s1 and s2. We also know that the answer lies between the range 0, sum(given array).\n\nAnother thing that we know is that we can split the range between s1 and s2. With s1 on the left and s2 on the right.\n\nSince Range - s1 gives us s2. We can minimize the problem to Range -2 s1. From there on we create a loop from 0 to Range/2 and find the minimum value that satisfies the requirement of min(ans, Range - 2*s1).\n\n\\newpage\n\\section{Count number of subsets with given difference}\n\\begin{lstlisting}\nclass Solution:\n    def count_number_of_subsets_with_difference(self, arr, diff):\n\n        sum_of_arr = sum(arr)\n\n        target = (diff+sum_of_arr)/2\n\n        memo = {}\n\n        def subset_sum(arr, i, target):\n            key = (i, target)\n\n            if target == 0:\n                return 1\n\n            if i == 0:\n                return 0\n\n            if key in memo:\n                return memo[key]\n\n            if arr[i-1] > target:\n                memo[key] = subset_sum(arr, i-1, target)\n                return memo[key]\n\n            memo[key] = subset_sum(arr, i-1, target-arr[i-1]) \n            + subset_sum(arr, i-1, target)\n            return memo[key]\n\n        return subset_sum(arr, len(arr), target)\n\\end{lstlisting}\n\nSince we know the difference, we can model two equations. S2-S1 = diff, S1 + S2 = sum(arr)\n\nHence target = (diff + sum(arr))/2\n\nWe can run subset sum on the target and get the count.\n\n\\newpage\n\\section{Target Sum}\n\nSame problem as Count number of subsets with difference, just with different wording.\n\n\\begin{lstlisting}\nclass Solution:\n    def findTargetSumWays(self, nums: List[int], target: int) -> int:\n        if sum(nums) < target or (sum(nums)-target)%2:\n            return 0\n        s1 = (sum(nums)+target)/2\n        memo = {}\n        def subset_count(arr, i, target):\n            key = (i, target)\n            if i == 0:\n                return 0 if target else 1\n            if key in memo:\n                return memo[key]\n            if arr[i-1] > target:\n                memo[key] = subset_count(arr, i-1, target)\n                return memo[key]\n            \n            memo[key] = subset_count(arr, i-1, target-arr[i-1]) \n            + subset_count(arr, i-1, target)\n            return memo[key]\n        return subset_count(nums, len(nums), s1)\n\\end{lstlisting}\n\nYou are given an integer array nums and an integer target.\n\nYou want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.\n\nFor example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression \"+2-1\".\nReturn the number of different expressions that you can build, which evaluates to target.\n\nInput: nums = [1,1,1,1,1], target = 3\nOutput: 5\nExplanation: There are 5 ways to assign symbols to make the sum of nums be target 3.\n\n-1 + 1 + 1 + 1 + 1 = 3\n\n+1 - 1 + 1 + 1 + 1 = 3\n\n+1 + 1 - 1 + 1 + 1 = 3\n\n+1 + 1 + 1 - 1 + 1 = 3\n\n+1 + 1 + 1 + 1 - 1 = 3\n\n\\newpage\n\\section{Unbounded KnapSack}\n\nIn an unbounded knapsack we are allowed to take multiple occurences of an item. If an item is selected once, it can be taken again. If it is ignored the first time, it will not be taken in subsequent iterations as well.\n\nThere is only a minor change in the coding style for unbounded knapsack.\n\n\\begin{lstlisting}\n# Minor change at the end !\n\nreturn knapsack(arr, i, target-arr[i-1]) or knapsack(arr, i-1, target)\n\\end{lstlisting}\n\n\\section{Rod cutting problem}\n\\begin{lstlisting}\nclass Solution:\n\n    def __init__(self):\n        self.memo = {}\n\n    def unbounded_knapsack(self, items, weight, capacity, index):\n        key = (index, capacity)\n        if key in self.memo:\n            return self.memo[key]\n\n        if index == 0 or capacity == 0:\n            self.memo[key] = 0\n            return self.memo[key]\n\n        if weight[index-1] > capacity:\n            self.memo[key] = self.unbounded_knapsack(items, weight, capacity, index-1)\n            return self.memo[key]\n\n        self.memo[key] = max(items[index-1]+self.unbounded_knapsack(items,weight,capacity-weight[index-1],index),\n            self.unbounded_knapsack(items,weight,capacity,index-1))\n        return self.memo[key]\n\\end{lstlisting}\n\n\\newpage\n\\section{Coin change problem (max number of ways)}\nGiven a value N, find the number of ways to make change for N cents, if we have infinite supply of each of S = { S1, S2, .. , SM } valued coins.\n\\begin{lstlisting}\nclass Solution:\n    def count(self, S, m, n): \n        i = m\n        target = n\n        arr = S\n        memo = {}\n        def subset_sum(arr, i, target):\n            key = (i, target)\n            if target == 0:\n                return 1\n            \n            if i == 0:\n                return 0\n            \n            if key in memo:\n                return memo[key]\n            \n            if arr[i-1] > target:\n                memo[key] = subset_sum(arr, i-1, target)\n                return memo[key]\n\n            memo[key] = subset_sum(arr, i, target-arr[i-1]) + subset_sum(arr, i-1, target)\n            return memo[key]\n        return subset_sum(arr, i, target)\n\\end{lstlisting}\nInput:\n\nn = 4 , m = 3\n\nS[] = {1,2,3}\n\nOutput: 4\n\nExplanation: Four Possible ways are:\n\n{1,1,1,1},{1,1,2},{2,2},{1,3}.\n\n\\newpage\n\\section{Minimum number of coins}\nYou are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.\n\nReturn the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.\n\nYou may assume that you have an infinite number of each kind of coin.\n\\begin{lstlisting}\nclass Solution:\n    def coinChange(self, coins: List[int], amount: int) -> int:\n        memo = {}\n        def unbounded_knapsack(arr, i, target):\n            key = (i, target)\n            if target == 0:\n                return 0\n            \n            if i <= 0 and target > 0:\n                return float('inf')\n            \n            if key in memo:\n                return memo[key]\n            \n            if arr[i-1] > target:\n                memo[key] = unbounded_knapsack(arr, i-1, target)\n                return memo[key]\n            \n            memo[key] = min(1+unbounded_knapsack(arr,i,target-arr[i-1]), \n                           unbounded_knapsack(arr,i-1,target))\n            return memo[key]\n        res = unbounded_knapsack(coins, len(coins), amount)\n        if res == float('inf'):\n            return -1\n        return res\n\\end{lstlisting}\nInput: coins = [1,2,5], amount = 11\n\nOutput: 3\n\nExplanation: 11 = 5 + 5 + 1\n\n\\newpage\n\\section{Longest Common Subsequence}\n\\begin{lstlisting}\ndef longestCommonSubsequence(self, text1: str, text2: str)\n -> int:\n        memo = {}\n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            \n            if i <=0 or j<=0:\n                return 0\n                \n            if key in memo:\n                return memo[key]\n                \n            if s1[i-1] == s2[j-1]:\n                memo[key] = 1+lcs(s1, s2, i-1, j-1)\n                return memo[key]\n            \n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n        \n        return lcs(text1, text2, len(text1), len(text2))\n\\end{lstlisting}\nGiven two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.\n\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.\n\nFor example, \"ace\" is a subsequence of \"abcde\".\nA common subsequence of two strings is a subsequence that is common to both strings.\n\nExample 1:\n\nInput: text1 = \"abcde\", text2 = \"ace\" \n\nOutput: 3  \n\nExplanation: The longest common subsequence is \"ace\" and its length is 3.\n\n\\newpage\n\\section{Longest Common Substring}\n\\begin{lstlisting}\nclass Solution:\n    def __init__(self):\n        self.res = 0\n    def longestCommonSubstr(self, S1, S2, n, m):\n        def helper(s1, s2, n, m):\n\n            if n == 0 or m == 0:\n                return 0\n            \n            if s1[n-1] == s2[m-1]:\n                a  = 1+helper(s1, s2, n-1, m-1)\n                self.res = max(self.res, a)\n                return a\n\n            helper(s1, s2, n-1, m)\n            helper(s1, s2, n, m-1)\n            \n            return 0\n\n        helper(S1, S2, n, m)\n        \n        return self.res\n\\end{lstlisting}\nDifferent from LCS in the sense that we return only when there is a match\n\n\\newpage\n\\section{Printing Longest Common SubSequence}\n\\begin{lstlisting}\nclass Solution:\n    def longestCommonSubsequence(self, text1: str, text2: str) -> int:\n        memo = {}\n        res = []\n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            \n            if i <=0 or j<=0:\n                return 0\n                \n            if key in memo:\n                return memo[key]\n                \n            if s1[i-1] == s2[j-1]:\n                res.append(s1[i-1])\n                memo[key] = 1+lcs(s1, s2, i-1, j-1)\n                return memo[key]\n            \n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n        lcs(text1, text2, len(text1), len(text2))\n        print(res)\n        return \n\\end{lstlisting}\n\n\\newpage\n\\section{Shortest Common SuperSequence (Finding Length)}\n\\begin{lstlisting}\nclass Solution:    \n    def shortestCommonSupersequence(self, X, Y, m, n):\n        memo = {}\n        def helper(s1, s2, i, j):\n            key = (i, j)\n            if i<=0 or j<=0:\n                return 0\n            if key in memo:\n                return memo[key]\n            if s1[i-1] == s2[j-1]:\n                memo[key] = 1+helper(s1, s2, i-1, j-1)\n                return memo[key]\n            memo[key] = max(helper(s1, s2, i-1, j), helper(s1, s2, i, j-1))\n            return memo[key]\n        return m+n - helper(X, Y, m, n)\n\\end{lstlisting}\n\\newpage\n\\section{Printing Shortest Common SuperSequence}\n\\begin{lstlisting}\nclass Solution:\n    def shortestCommonSupersequence(self, str1: str, str2: str) -> str:\n        arr = []\n        memo = {}\n        def helper(s1, s2, i, j):\n            key = (i, j)\n            if not i and not j:\n                return \"\"\n            if i == 0:\n                return s2[:j]\n            if j == 0:\n                return s1[:i]\n            if key in memo:\n                return memo[key]\n            if s1[i-1] == s2[j-1]:\n                memo[key] = helper(s1, s2, i-1, j-1) + s1[i-1]\n            else:\n                a = helper(s1, s2, i-1, j) + s1[i-1]\n                b = helper(s1, s2, i, j-1) + s2[j-1]  \n                if len(a) <= len(b):\n                    memo[key] = a\n                else:\n                    memo[key] = b\n            return memo[key]\n        return helper(str1, str2, len(str1), len(str2))\n\\end{lstlisting}\nGiven two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.\n\nA string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.\n\n \n\nExample 1:\n\nInput: str1 = \"abac\", str2 = \"cab\"\n\nOutput: \"cabac\"\n\nExplanation: \nstr1 = \"abac\" is a subsequence of \"cabac\" because we can delete the first \"c\".\n\nstr2 = \"cab\" is a subsequence of \"cabac\" because we can delete the last \"ac\".\n\nThe answer provided is the shortest such string that satisfies these properties.\n\n\\newpage\n\\section{Minimum Number of insertions/deletions to convert string a to b}\n\\begin{lstlisting}\nclass Solution:\n    def minOperations(self, s1, s2):\n        # code here\n        memo = {}\n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            if i == 0 or j == 0:\n                return 0\n            if key in memo:\n                return memo[key]\n            if s1[i-1] == s2[j-1]:\n                memo[key] = 1 + lcs(s1, s2, i-1, j-1)\n                return memo[key]\n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n        return len(s1) +len(s2) - 2*lcs(s1, s2, len(s1), len(s2))\n\\end{lstlisting}\n\nNumber of deletion = len(s1) - lcs\nNumber of insetion = len(s2) - lcs\n\nHence total = len(s1) + len(s2) - 2*lcs\n\n\\newpage\n\\section{Longest Palindromic Subsequence}\n\\begin{lstlisting}\nclass Solution:\n    def longestPalindromeSubseq(self, s: str) -> int:\n        memo = {}\n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            \n            if i == 0 or j == 0:\n                return 0\n            \n            if key in memo:\n                return memo[key]\n            \n            if s1[i-1] == s2[j-1]:\n                memo[key] = 1+ lcs(s1, s2, i-1, j-1)\n                return memo[key]\n            \n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n        \n        return lcs(s, s[::-1], len(s), len(s))\n\\end{lstlisting}\n\nLCS with s and reverse of s.\n\n\\newpage \n\\section{Min number of deletion in string to make a palindrome}\n\\begin{lstlisting}\nclass Solution:\n    def minimumNumberOfDeletions(self,S):\n        # code here \n        memo = {}\n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            if i == 0 or j == 0:\n                return 0\n                \n            if key in memo:\n                return memo[key]\n                \n            if s1[i-1] == s2[j-1]:\n                memo[key] = 1+ lcs(s1, s2, i-1, j-1)\n                return memo[key]\n                \n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n    \n        return len(S) - lcs(S, S[::-1], len(S), len(S))\n\\end{lstlisting}\n\nMin deletions: len(s) - len of palindromic subsequence\n\n\\newpage\n\\section{Longest Repeating Subsequence}\n\\begin{lstlisting}\nclass Solution:\n    def LongestRepeatingSubsequence(self, str):\n        # Code here\n        memo = {}\n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            if i == 0 or j == 0:\n                return 0\n                \n            if key in memo:\n                return memo[key]\n            \n            # i not eq j    \n            if s1[i-1] == s2[j-1] and i != j:\n                memo[key] = 1+ lcs(s1, s2, i-1, j-1)\n                return memo[key]\n                \n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n        \n        return lcs(str, str, len(str), len(str))\n\\end{lstlisting}\nGiven a string str, find the length of the longest repeating subsequence such that it can be found twice in the given string. The two identified subsequences A and B can use the same ith character from string str if and only if that ith character has different indices in A and B.\n\nExample 2:\n\nInput:\n\nstr = \"aab\"\n\nOutput: 1\n\nExplanation: \n\nThe longest reapting subsequenece is \"a\".\n\n\\newpage\n\\section{Sequence Pattern Matching}\nQ: Does A exist in B in the same order\n\nA: \"AXY\"\n\nB: \"AXYZ\"\n\nReturn True since the LCS of A and B is equal to A.\n\n\\section{Min Number of Insertion to make a String a Palindrome}\n\\begin{lstlisting}\nclass Solution:\n    def countMin(self,S):\n        # code here \n        memo = {}\n        def isPalindrome(s):\n            return s == s[::-1]\n            \n        if isPalindrome(S):\n            return 0\n            \n        def lcs(s1, s2, i, j):\n            key = (i, j)\n            if i == 0 or j == 0:\n                return 0\n                \n            if key in memo:\n                return memo[key]\n                \n            if s1[i-1] == s2[j-1]:\n                memo[key] = 1+ lcs(s1, s2, i-1, j-1)\n                return memo[key]\n                \n            memo[key] = max(lcs(s1, s2, i-1, j), lcs(s1, s2, i, j-1))\n            return memo[key]\n    \n        return len(S) - lcs(S, S[::-1], len(S), len(S))\n\\end{lstlisting}\n\nMin number of insetions is equal to the min number of deletions. Hence its the same problem asked in a different way from before.\n\n\n\\newpage\n\\section{DP On Trees -- Diameter of Tree}\n\\begin{lstlisting}\nclass Solution:    \n    def diameter(self,root):\n        res = [0]\n        def helper(root):\n            if root == None:\n                return 0\n                \n            l = helper(root.left)\n            r = helper(root.right)\n            \n            temp = max(l, r) + 1\n            \n            res[0] = max(l+r+1, res[0])\n            \n            return temp\n        helper(root)\n        return res[0]\n\\end{lstlisting}\n\nWe have two choices at every root, either we pass the left or right branch branch including the root or the the answer passes through the current root itself in an upside down parabola shape.\n\n\\newpage\n\\section{Max Path Sum from any node to any node}\n\\begin{lstlisting}\nclass Solution:\n    def maxPathSum(self, root: Optional[TreeNode]) -> int:\n        res = [float('-inf')]\n        def helper(root):\n            if root == None:\n                return 0\n            \n            l = helper(root.left)\n            r = helper(root.right)\n            \n            temp = max(max(l,r)+root.val, root.val)\n            ans = max(temp ,l+r+root.val )\n            res[0] = max(ans, res[0])\n            \n            return temp\n        \n        helper(root)\n        return res[0]\n\\end{lstlisting}\n\nWe have two choices as before, choose the max of both l,r and add value of root or just the root.val to avoid negatives.\n\n\\section{Max Path Sum from leaf node to leaf node}\n\\begin{lstlisting}\nclass Solution:        \n    def maxPathSum(self, root):\n        res = [float('-inf')]\n        \n        def helper(root):\n            if root == None:\n                return 0\n                \n            l = helper(root.left)\n            r = helper(root.right)\n            \n            temp = max(max(l, r)+root.data, root.data)\n            if root.left == None and root.right == None:\n                temp = max(temp, root.data)\n            ans = max(l+r+root.data, temp)\n            res[0] = max(res[0], ans)\n            return temp\n        \n        helper(root)\n        return res[0]\n\\end{lstlisting}\n\n\\end{document}\n", "meta": {"hexsha": "27e66e2779eafbb23af4c718e838b91e79777bc3", "size": 26086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dp.tex", "max_stars_repo_name": "MoMus2000/Notes", "max_stars_repo_head_hexsha": "54957ebb92436521e375919bef6fa88a81192a9d", "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": "dp.tex", "max_issues_repo_name": "MoMus2000/Notes", "max_issues_repo_head_hexsha": "54957ebb92436521e375919bef6fa88a81192a9d", "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": "dp.tex", "max_forks_repo_name": "MoMus2000/Notes", "max_forks_repo_head_hexsha": "54957ebb92436521e375919bef6fa88a81192a9d", "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.8881506091, "max_line_length": 280, "alphanum_fraction": 0.5523652534, "num_tokens": 6956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6531467430257335}}
{"text": "\\subsubsection{Isochoric Processes}\nIsochoric processes are heating/cooling processes where the volume of the gas does not change ($\\Delta V =0$). For example, consider a situation where I have a gas in a closed box with rigid walls. Now, imagine I heat up the gas by holding a lighted candle underneath it. It is clear that the gas does not change in volume, as the walls are rigid (there is nothing it can expand out to, or for it to be compressed by), but we are changing the energy of the gas. Let's look at the properties of this process a little more closely.\\\\\n\nFirstly, what is the work that's done in this process? This one's fairly simple; We can return to the definition \\[ W = -\\int_{V_1}^{V_2} P(V)dV \\] and we realize that as there is no change in volume, $V_1 = V_2$ and therefore: \\[ W = -\\int_{V_1}^{V_1} P(V)dV = 0 \\]\n\\begin{equation}\n    W=0\n\\end{equation}\nand the work done is zero! Combining this with the first law of thermodynamics, we have that: \\[\\Delta E = Q + W = Q \\]\nwhere we see that the change in energy is just the heat that flows in/out of the system, as we might have expected. Finally, as we know that $\\Delta E = Q$, we also obtain the heat as a function of the change in temperature and amount (and degrees of freedom!) of the gas:\n\\begin{equation} \nQ = nc_v\\Delta T\n\\end{equation}\nOur earlier question about why we have called $c_v$ as we have is now answered! We can see from here that $c_v = \\frac{\\chi}{2}R$ is equivalent to the heat capacity of a material, where we have fixed the volume. \\\\Finally, we may ask what might this process look like on a PV-diagram? Let's return to the candle example. As we heat the gas up, the volume of the gas remains unchanged, so the process should be a graph of a line with constant $V$. Conversely, as the gas goes from a lower temperature $T_1$ to a higher temperature $T_2$, we would expect the pressure to increase. Hence, on a PV diagram, we would expect a straight vertical line:\n\\begin{center}\n    \\begin{tikzpicture}\n \\draw[stealth-stealth] (0,5) node[below left]{$P$} |- (5,0) node[below left]{$V$};\n\\draw[thick,->] (2.5,1) -- (2.5,2.5);\n\\draw[thick] (2.5,2.5) -- (2.5,4);\n\\draw[dashed] (2.5,1) -- (2.5,0);\n\\draw[dashed] (2.5,1) -- (0,1);\n\\draw[dashed] (2.5,4) -- (0,4);\n\\filldraw (2.5,1) circle (2pt);\n\\filldraw (2.5,4) circle (2pt);\n\\node[below] at (2.5,0) {$V_1$};\n\\node[left] at (0,1) {$P_1$};\n\\node[left] at (0,4) {$P_2$};\n\\node[right] at (2.5,1) {$T_1$};\n\\node[right] at (2.5,4) {$T_2$};\n\\end{tikzpicture}\n\\end{center}\nIt's also very easy to see just from this graph that isochoric processes have zero work; The area under a curve on a PV-diagram yields the work done in that process, but a straight vertical line obviously has no area. ", "meta": {"hexsha": "be55075d45684f1b0a9b0086a16091506c5e6e7d", "size": 2730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OneLaw/isochoric.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/isochoric.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/isochoric.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": 88.064516129, "max_line_length": 644, "alphanum_fraction": 0.7076923077, "num_tokens": 859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6531467417599681}}
{"text": "\\section{Parallel strategy} \nWe begin by assigning the original complex array\n$A(0:N_x-1,0:N_y-1,0:N_z-1)$ of data size $N_x \\times N_y \\times N_z$\nin a block distribution onto a $P_x \\times P_y \\times P_z$\ngrid of nodes.  Thus, each node has a local array\n$A'(0:n_x-1,0:n_y-1,0:n_z-1)$ of size $n_x \\times n_y \\times n_z$ where\n$n_x = \\frac{N_x}{P_x},n_y = \\frac{N_y}{P_y}, n_z = \\frac{N_z}{P_z}$.\n \nIf we denote by $A'(i,j,k)[x,y,z]$ the element $(i,j,k)$ of local\narray $A'$ in the node at mesh coordinates $(x,y,z)$, then\n\n\\begin{figure}\n\\includegraphics[keepaspectratio,width=\\columnwidth]{fft_mesh_1}\n\\caption{Data distribution (light lines) and processor mesh (heavy\n  lines) for an $\\mathbf{8\\times 8\\times 8}$ FFT on a $\\mathbf{4\\times 4\\times4}$\n  processor mesh.}\n\\label{fig:domain_decomp}\n\\end{figure}\n\n\\begin{equation}\nA'(i,j,k)[x,y,z] \\equiv A(x n_x+i,y n_y+j,z n_z+k).\n\\end{equation}\nFigure~\\ref{fig:domain_decomp} shows the original data\ndistribution,(i.e. how the data is distributed among all the\nprocessors) before any communication takes place.\n\nFor clarity, we impose the following restrictions on the sizes of the\nlocal array $A'$: $n_x * n_y = \\alpha \\times P_z$, $n_y *n_z = \\beta\n\\times P_y$, and $n_y * n_z = \\gamma \\times P_x$, where $\\alpha$,\n$\\beta$, and $\\gamma$ are integers.\n\nWe use the row-column approach described in the previous publication\nto compute the 3D-FFT. That is, we first compute $N_x \\times N_y $\n1D-FFT along the z axis. Followed by $N_x \\times N_z$ 1D-FFT in the y\naxis and finally, $N_y \\times N_z$ 1D-FFTs in the x axis.  This\nrequires successive transpositions of the global array.\n\nSince the $N_x \\times N_y$ one-dimensional FFTs along the $z$\ndimension are all independent, we need only consider a single\nprocessor row in the z dimension, which has to compute $n_x \\times\nn_y$ one-dimensional FFTs of size $N_z$. Let $A(0:n_x-1, 0:n_y-1,\n0:N_z-1)$ block distributed along the z dimension. Then the local\narray $A'(0:n_x-1, 0:n_y-1, 0:n_z-1)$ one node p in the original\ndecomposition is given by\n \n\\begin{eqnarray}\n&A'_z(i,j,k)[p] \\equiv A_z(i,j ,p \\times  n_z+k)\\\\\n\\end{eqnarray}\n\nThen we redistribute the data along both the $x$ and $y$ dimensions\nonto the $P_z$ nodes. Let us assume that the number of 1D-FFTs to be\ncomputed along the z dimension is smaller than the processor mesh\ndimension $P_z$ (ie $\\alpha=0$).  Then only those processors, p, along the z\naxis that satisfy the condition $p \\pmod {S_z} = 0$ with $S_z\n(=\\frac{P_z}{n_x n_y })$ compute a 1D-FFT along the z dimension. If\n$A''(0:0,0:0, 0:Nz-1)$ array is the local array in node $p$ then,\n\\begin{eqnarray}\n&A''_z(i,j,k)[p] \\equiv A_z(i+\\frac{ (p/S_z) }{n_y},j+(p/S_z)\\pmod{n_y},k),\\\\\n&if \\{ p\\pmod{S_z}=0 \\}, \\\\\n&A''_z(i,j,k)[p]=0,\\\\\n&if \\{ p\\pmod{S_z}\\ne 0\\}, \n\\end{eqnarray}\n \nThis new distribution of array A is shown in Fig 2. Once the data is\nin this new form each node performs one 1D-FFT.\n\nWe expect this approach to have better performance than the one where\nthe 1D-FFTs are computed only on dense subset of nodes in the center\nof the partition as shown in Figure~\\ref{fig:dense}.  In the current\napproach, with nodes computing 1D-FFTs spread evenly throughout the\npartition, we expect reduced link contention.\n", "meta": {"hexsha": "c0e66768a3ea50c5b367b3524a5564c5db825734", "size": 3241, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "BlueMatterDocs/europar07/method.tex", "max_stars_repo_name": "Bhaskers-Blu-Org1/BlueMatter", "max_stars_repo_head_hexsha": "1ab2c41af870c19e2e1b1095edd1d5c85eeb9b5e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-02-25T15:46:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T07:04:47.000Z", "max_issues_repo_path": "BlueMatterDocs/europar07/method.tex", "max_issues_repo_name": "IBM/BlueMatter", "max_issues_repo_head_hexsha": "5243c0ef119e599fc3e9b7c4213ecfe837de59f3", "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": "BlueMatterDocs/europar07/method.tex", "max_forks_repo_name": "IBM/BlueMatter", "max_forks_repo_head_hexsha": "5243c0ef119e599fc3e9b7c4213ecfe837de59f3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-06-06T16:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T19:43:01.000Z", "avg_line_length": 45.0138888889, "max_line_length": 81, "alphanum_fraction": 0.7133600741, "num_tokens": 1094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6530615161307224}}
{"text": "\\subsection{Method Description and Its Implementation}\n\t\n\t\\noindent We will denote the functions space that vanishes at the borders as $H^1_0 (0, 1)$. Setting $A = \\alpha \\partial^2_{\\xi}$ and $B = \\frac{1}{2} \\partial_{\\xi} (x^2)$, $x \\in \\mathcal{H}$, with its domains $D(A) = H^2 (0, 1) \\cap H^1_0 (0, 1)$ and $D(B) = H^1_0 (0, 1)$ respectively, then by (\\ref{stochastic_equation}), the equation (\\ref{burgers_stochastic2}) can be rewritten as\n\t\\begin{align*}\n    \tdX &= [AX + B(X)]dt + dW_t \\\\\n        X(0) &= x, \\hspace{0.2cm} x \\in \\mathcal{H}\n\t\\end{align*}\t\n\twhere $A$  have eigenfunctions in $\\mathcal{H}$ given by\n\t\\begin{align*}\n\t\te_k (\\xi) = \\sqrt{2} \\sin{(k \\pi \\xi)}, \\hspace{3mm} \\xi \\in [0, 1], \\hspace{3mm} k \\in \\mathbb{N}\n\t\\end{align*}\n\t\n\t\\noindent Note that the operator $A$ satisfies $Ae_k = -\\alpha \\pi^2 k^2 e_k$ for $k \\in \\mathbb{N}$, then if we set $\\Lambda = (-A)^{-1}$ we have that $\\Lambda^{-1/2} e_k = \\sqrt{2 \\alpha} \\pi |k| e_k$. \\\\\t\n\t\t\t\t\n\tTherefore, as in (\\ref{infinite_system}) we need to solve the following system\n\t\\begin{align}\n\t\t\\dot{u}_{m} (t) = -u_{m} (t) \\lambda_{m} + \\displaystyle \\sum _{n \\in \\mathcal{J}} u_{n} (t) C_{n, m} , \\hspace{0.1cm} n, m \\in \\mathcal{J}\n\t\\end{align}\n\t\t\n\t\\noindent We need to calculate the value of the constants $C_{n,m}$ , then we need to calculate expressions such as $B(x)$, $D_x H_n (x)$. Note that $x$ can be written as $x = \\displaystyle \\sum_{k} \\beta_k e_k$ , with $\\beta_k := \\langle x, e_k \\rangle_{\\mathcal{H}}$. Then we have\n\t\\begin{align*}\n\t\tB(x) = \\frac{1}{2} \\partial_{\\xi} \\left( \\displaystyle \\sum_k \\beta_k e_k \\right)^2 = \\frac{1}{2} \\partial_{\\xi} \\left[ \\sum_l\n\t\t\\sum_k \\beta_l \\beta_k e_l e_k \\right] = \\frac{1}{2} \\sum_l\n\t\t\\sum_k \\beta_l \\beta_k (e_l e'_k + e'_l e_k)\n\t\\end{align*}\n\tand for $D_x H_n (x)$ we have\n\t\\begin{align*}\n\t\tD_x H_n (x) = \\displaystyle \\sum_{j = 1}^{\\infty} \\prod_{i = 1. i \\neq j}^{\\infty} P_{n_i} (\\langle x, \\Lambda^{-1 / 2} e_i \\rangle_{\\mathcal{H}}) P'_{n_j} (\\langle x, \\Lambda^{-1 / 2} e_j \\rangle_{\\mathcal{H}}) \\Lambda^{-1 / 2} e_j \n\t\\end{align*}\n\t\n\t\\noindent Therefore, $C_{n, m}$ given by (\\ref{Cnm}) gives\n\t\\begin{align*}\n\t\tC_{n, m} =& \\displaystyle \\frac{1}{2} \\int_{\\mathcal{H}} H_m (x) \\mu (dx) \\sum_{j = 1}^{\\infty} \\prod_{i = 1, i \\neq j}^{\\infty} P_{n_i} (\\langle x, \\Lambda^{-1 / 2} e_i \\rangle_{\\mathcal{H}}) P'_{n_j} (\\langle x, \\Lambda^{-1 / 2} e_j \\rangle_{\\mathcal{H}})  \\sqrt{2 \\alpha} \\pi |j| \\\\\n\t\t&\\cdot \\sum_l\n\t\t\\sum_k \\beta_l \\beta_k (e_l e'_k + e'_l e_k) \\\\\n\t\t=& \\displaystyle \\frac{1}{2} \\int_{\\mathcal{H}} \\mu (dx) \\sum_{j = 1}^{\\infty} \\sqrt{2 \\alpha} \\pi |j| P_{m_j} (\\langle x, \\Lambda^{-1 / 2} e_j \\rangle_{\\mathcal{H}}) P'_{n_j} (\\langle x, \\Lambda^{-1 / 2} e_j \\rangle_{\\mathcal{H}}) \\\\  &\\cdot \\prod_{i = 1, i \\neq j}^{\\infty} P_{n_i} (\\langle x, \\Lambda^{-1 / 2} e_i \\rangle_{\\mathcal{H}}) P_{m_i} (\\langle x, \\Lambda^{-1 / 2} e_i \\rangle_{\\mathcal{H}}) \\\\\n\t\t&\\cdot \\sum_l\n\t\t\\sum_k \\beta_l \\beta_k (e_l e'_k + e'_l e_k) \n\t\\end{align*}\n\n\tSo, to obtain a truncated approximation of the solution, the following set of indices is considered\n\t\\begin{align}\n\t\tJ^{M, N} = \\{\\gamma = (\\gamma_i, \\hspace{1mm} 1 \\leq \\gamma_i \\leq M  ) \\hspace{1mm} | \\hspace{1mm} \\gamma_i \\in \\{0, 1, \\cdots, N \\} \\}\n\t\\end{align}\n\tthis is the set of $M$-tuple which can take values in the set $\\{0, 1, \\cdots, N \\}$. \\\\\n\t\n\tFor $N_1 \\in \\mathbb{N}$ define as the set $S_{N_1} = \\{n_1 , n_2 , \\cdots , n_{N_1} : n_i \\in J^{M,N} , i = 1, \\cdots , N_1 \\}$. Then for $n, m \\in S_{N}$ we have \n\t\\begin{align*}\n\t\t\\bar{C}_{n, m} =& \\displaystyle \\frac{1}{2} \\sum_{j = 1}^{\\infty} \\sqrt{2 \\alpha} \\pi |j| \\int_{\\mathcal{\\mathbb{R}^M}} P_{m_j} (\\xi_j) P'_{n_j} (\\xi_j) \\mu (d \\xi_j) \\\\  \n\t\t&\\cdot \\prod_{i = 1, i \\neq j}^{M} P_{m_i} (\\xi_i) P_{n_i} (\\xi_i) \\mu (d \\xi_i) \\sum_{l=1}^{M} \\sum_{k=1}^{M} \\beta_l \\beta_k (e_l e'_k + e'_l e_k)\n\t\\end{align*}\n\n\tand for $m_1, m_2, \\cdots, m_M \\in J^{M, N}$ the system (\\ref{infinite_system}) give us\n\t\\begin{align}\n\t\t\\label{finite_system}\n\t\t\\dot{u}_{m_i} (t) = -u_{m_i} (t) \\lambda_{m_i} + \\displaystyle \\sum_{j=1}^{M} u_{n_j} (t) C_{n_j, m_i} , \\hspace{2mm} 1 \\leq i \\leq M\t\n\t\\end{align}\n\t\n\tThe solutions of the previous system can be calculated in terms of their eigenvectors by establishing the following vector\n\t\\begin{equation*}\n\t\tU^M (t) =\n\t\t\\begin{pmatrix}\n\t\t\tu_{m_1} (t) & u_{m_2} (t) & \\dots & u_{m_M} (t)\n\t\t\\end{pmatrix}^T   \n\t\\end{equation*}\n\tand for its derivatives\n\t\\begin{equation*}\n\t\t\\dot{U}^M (t) =\n\t\t\\begin{pmatrix}\n\t\t\t\\dot{u}_{m_1} (t) & \\dot{u}_{m_2} (t) & \\dots & \\dot{u}_{m_M} (t)\n\t\t\\end{pmatrix}^T   \n\t\\end{equation*}\n\t\n\tSo, we can now write the system (\\ref{finite_system}) as \n\t\\begin{align}\n\t\t\\label{finite_system_vectorial}\n\t\t\\dot{U}^M (t) = A U^M (t)\n\t\\end{align}\n\twhere the matrix $A$ is given by\n\t\\begin{equation*}\n\t\tA =\n\t\t\\begin{pmatrix}\n\t\t\t-\\lambda_1 + C_{1,1} & C_{2,1} & \\dots & C_{M-1,1} & C_{M,1} \n\t\t\t\\\\\n\t\t\tC_{1,2} & -\\lambda_2 + C_{2,2} & \\dots & C_{M-1,2} & C_{M,2}  \n\t\t\t\\\\\n\t\t\t\\vdots & \\vdots & \\ddots & \\vdots & \\vdots\n\t\t\t\\\\\n\t\t\tC_{1,M-1} & C_{2,M-1} & \\dots & -\\lambda_{M-1} + C_{M-1,M-1} & C_{M,M-1} \n\t\t\t\\\\\n\t\t\tC_{1,M} & C_{2,M} & \\dots & C_{M-1,M} & -\\lambda_{M} + C_{M,M} \n\t\t\\end{pmatrix}\n\t\\end{equation*}\n\twhere $\\lambda_i = \\lambda_{mi}$ and $C_{i, j} = C_{n_i, m_j}$ para $1 \\leq i, j \\leq M$. \\\\\n\t\n\t\\noindent Then, if $A$ has $M$ real and distint eigenvalues $\\eta_i$ and $M$ eigenvectors $V_i$, then the solution to (\\ref{finite_system_vectorial}) is given by\n\t\\begin{align}\n\t\t\\label{solution_finite_system}\n\t\tU^M (t) = \\displaystyle \\sum _{j = 1}^{M} c_i V_i e^{\\eta_i t}\n\t\\end{align}\n\n\tIn the case when some eigenvalue is complex, we can write it together with its eigenvector as follows\n\t\\begin{align*}\n\t\tV &= a + i b, \\hspace{3mm} \\eta = \\beta + i \\mu\n\t\\end{align*}\n\tto get the solutions\n\t\\begin{align*}\n\t\te^{\\beta t} (a \\cos(\\mu t) - b \\sin(\\mu t)), \\hspace{2mm} e^{\\beta t} (a \\sin(\\mu t) + b \\cos(\\mu t))\n\t\\end{align*}\n\twhich are real and different. \\\\\n\t\n\tThen we can write the approximation of the solution of (\\ref{kolmogorov}) as\n\t\\begin{align}\n\t\t\\label{finite_approximation}\n\t\tu_M (x, t) = \\displaystyle \\sum_{ n \\in J^{M, N} } u_n (t) H_n (x) = U^M (t) H^M (x), \\hspace{2mm} x \\in \\mathcal{H}, \\hspace{2mm}, t \\in [0, T].\n\t\\end{align}\n\n\tAlso, if $u (\\xi, t) = \\mathbb{E} \\left [X_t (\\xi) \\right]$, then satisfies the problem given by\n\t\\begin{align*}\n\t\t\\frac{\\partial u}{\\partial t} = \\alpha \\frac{\\partial^2 u}{\\partial \\xi^2} + \\partial_{\\xi} \\left[ u(\\xi, t) \\right]^2\n\t\\end{align*}\n\twith the initial condition $u(\\xi, 0) = \\mathbb{E} \\left[ X_0 \\right]$. ", "meta": {"hexsha": "0bf3b8ab5193fc91304738cef84e7a8dc4604526", "size": 6578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/stochastic/numerical_experiments/Implementation.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/Implementation.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/Implementation.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": 53.9180327869, "max_line_length": 408, "alphanum_fraction": 0.5971419884, "num_tokens": 2901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6530615005139214}}
{"text": "\\section{Exercise 01}\n\\subsection{}\n\n\\begin{frame}\n\\frametitleTC{Problem}\n\\framesubtitleTC{This one we solve together}\n\\myPause\n Given the DT LTI dynamic system described in the state space by\n \\begin{displaymath}\n  A = \\begin{bmatrix} 0.4 & 0.4 \\\\ 0.05 & 0.3 \\end{bmatrix}, \\quad\n  b = \\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix}, \\quad\n  c = \\begin{bmatrix} 2 & -1 \\end{bmatrix}, \\quad\n  d = 0,\n \\end{displaymath}\n \\begin{itemize}[<+-| alert@+>]\n \\item[(a)] discuss its stability,\n \\item[(b)] express it in scalar form,\n \\item[(c)] compute its transfer function,\n \\item[(d)] compute the first three values ($k=0,1,2$) of its response to\n            \\begin{displaymath}\n             x(0) = \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix}, \\quad\n             u(k) = 0.4k.\n            \\end{displaymath}\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 need to compute the eigenvalues $\\lambda_{1,2}$ of $A$:\n       \\begin{itemize}[<+-| alert@+>]\n       \\item[] \\vspace{1mm}\n               $\\det(\\lambda I -A) = 0$,\n       \\item[] \\vspace{1mm}\n               $\\det \\left(\n                     \\begin{bmatrix} \\lambda & 0 \\\\ 0 & \\lambda \\end{bmatrix}\n                    -\\begin{bmatrix} 0.4 & 0.4 \\\\ 0.05 & 0.3 \\end{bmatrix}\n                     \\right) = 0 $,\n       \\item[] \\vspace{1mm}\n               $\\det \\begin{bmatrix} \\lambda-0.4 & -0.4 \\\\\n                                    -0.05       & \\lambda-0.3 \\end{bmatrix} = 0 $,\n       \\item[] \\vspace{1mm}\n               $(\\lambda-0.4)(\\lambda-0.3)-(-0.4)(-0.05) = 0$,\n       \\item[] \\vspace{1mm}\n               $\\lambda^2-0.7\\lambda+0.1=0$,\n       \\item[] \\vspace{1mm}\n               $\\lambda=\\cfrac{0.7\\mp\\sqrt{0.7^2-4\\cdot 0.5}}{2} \\quad \\Rightarrow \\quad\n                \\lambda_1=0.2, \\; \\lambda_2=0.5.$\n       \\end{itemize}\n \\item All the eigenvalues of $A$ are strictly less than one in magnitude\\\\\n       $\\Rightarrow$ the system is asymptotically stable.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (b)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Denoting by $x=[x_1\\;x_2]'$ the state vector (sign $'$means transpose) we have\n       \\begin{displaymath}\n        \\left\\{\\begin{array}{rcl}\n         \\begin{bmatrix} x_1(k) \\\\ x_2(k) \\end{bmatrix} \n         &=&             \n         \\begin{bmatrix} 0.4 & 0.4 \\\\ 0.05 & 0.3 \\end{bmatrix}\\,\n         \\begin{bmatrix} x_1(k-1) \\\\ x_2(k-1) \\end{bmatrix}\n         +\n         \\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix}\\,\n         u(k-1) \\\\\n         y(k)\n         &=&          \n         \\begin{bmatrix} 2 & -1 \\end{bmatrix} \\,\n         \\begin{bmatrix} x_1(k) \\\\ x_2(k) \\end{bmatrix}\n        \\end{array}\\right.\n       \\end{displaymath}\n \\item hence in scalar form\n       \\begin{displaymath}\n        \\left\\{\\begin{array}{rcl}\n         x_1(k) &=&  0.4 x_1(k-1) + 0.4 x_2(k-1) +    u(k-1)\\\\\n         x_2(k) &=& 0.05 x_1(k-1) + 0.3 x_2(k-1) + 0.5u(k-1)\\\\\n         y(k)   &=&    2 x_1(k-1) -     x_2(k-1)\n        \\end{array}\\right.\n       \\end{displaymath}\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (c)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item The transfer function $G(z)$ is $c(zI-A)^{-1}b+d$, hence\n       \\begin{itemize}\n       \\item[] \\begin{itemize}[<+-| alert@+>]\n               \\item[$G(z)$] \\vspace{1mm}\n                    $= \\begin{bmatrix} 2 & -1 \\end{bmatrix} \\,\n                       \\begin{bmatrix} z-0.4 & -0.4 \\\\\n                       -0.05& z-0.3 \\end{bmatrix}^{-1} \\,\n                       \\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix}\n                       +0\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{1}{(z-0.5)(z-0.2)}\n                       \\begin{bmatrix} 2 & -1 \\end{bmatrix} \\,\n                       \\begin{bmatrix} z-0.3 & 0.4 \\\\\n                       0.05& z-0.4 \\end{bmatrix} \\,\n                       \\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix}\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{1}{(z-0.5)(z-0.2)}\n                       \\begin{bmatrix} 2z-0.65 &-z+1.2 \\end{bmatrix} \\,\n                       \\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix}\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{1.5z-0.05}{(z-0.5)(z-0.2)}.\n                    $\n               \\end{itemize}\n       \\end{itemize}\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (d)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item We have\\\\\n       $u(0) = 0, \\quad u(1) = 0.4, \\quad u(2) = 0.8, \\quad u(3) = 1.2, \\, \\ldots$\n \\item We need to iteratively apply the state and output equations, whence\n       \\begin{itemize}\n       \\item[] \\begin{itemize}[<+-| alert@+>]\n               \\item[$k=0$:] \\vspace{1mm} \n                    $\\left\\{\\begin{array}{rll}\n                     x(0) &= \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix} (\\text{given}) \\\\\n                     y(0) &= \\begin{bmatrix} 2 & -1 \\end{bmatrix} \\,\n                             \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix}\n                          &= 3\n                     \\end{array}\\right.\n                    $\n               \\item[$k=1$:] \\vspace{1mm} \n                    $\\left\\{\\begin{array}{rll}\n                     x(1) &= \\begin{bmatrix} 0.4 & 0.4 \\\\ 0.05 & 0.3 \\end{bmatrix} \\,\n                             \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix}\n                            +\\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix} \\cdot 0\n                          &= \\begin{bmatrix} 1.2 \\\\ 0.4 \\end{bmatrix}\\\\\n                     y(1) &= \\begin{bmatrix} 2 & -1 \\end{bmatrix} \\,\n                             \\begin{bmatrix} 1.2 \\\\ 0.4 \\end{bmatrix}\n                          &= 2\n                     \\end{array}\\right.\n                    $\n               \\item[$k=2$:] \\vspace{1mm} \n                    $\\left\\{\\begin{array}{rll}\n                     x(1) &= \\begin{bmatrix} 0.4 & 0.4 \\\\ 0.05 & 0.3 \\end{bmatrix} \\,\n                             \\begin{bmatrix} 1.2 \\\\ 0.4 \\end{bmatrix}\n                            +\\begin{bmatrix} 1 \\\\ 0.5 \\end{bmatrix} \\cdot 0.4\n                          &= \\begin{bmatrix} 1.04 \\\\ 0.38 \\end{bmatrix}\\\\\n                     y(1) &= \\begin{bmatrix} 2 & -1 \\end{bmatrix} \\,\n                             \\begin{bmatrix} 1.04 \\\\ 0.38 \\end{bmatrix}\n                          &= 1.7\n                     \\end{array}\\right.\n                    $\n               \\end{itemize}\n       \\end{itemize}\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Addendum}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item We define some signals useful for the following.\n       \\begin{itemize}[<+-| alert@+>]\n       \\item Impulse (precisely, \\TC{unit} impulse as the value is 1):\n             \\begin{displaymath}\n              imp(k) = \\begin{cases} 1 & k=0 \\\\ 0 & \\text{otherwise} \\end{cases}\n             \\end{displaymath}\n       \\item Step (\\TC{unit} step, amplitude is 1):\n             \\begin{displaymath}\n              step(k) = \\begin{cases} 1 & k \\geq 0 \\\\ 0 & \\text{otherwise} \\end{cases}\n             \\end{displaymath}\n       \\item Ramp(\\TC{unit} ramp, slope is 1):\n             \\begin{displaymath}\n              ramp(k) = k\\; step(k) = \\begin{cases} k & k \\geq 0 \\\\ 0 & \\text{otherwise} \\end{cases}\n             \\end{displaymath}\n       \\end{itemize}\n \\item Quite frequently ``unit'' is omitted, e.g. ``step response'' actually\\\\\n       means ``unit step response''.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Proposed exercise 01}\n\\framesubtitleTC{Try this at home, ask questions next time if needed}\n\\myPause\n Given the DT LTI dynamic system described in the state space by\n \\begin{displaymath}\n  A = \\begin{bmatrix} 0.5 & 0 \\\\ 2 & -0.3 \\end{bmatrix}, \\quad\n  b = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}, \\quad\n  c = \\begin{bmatrix} 0 & 4 \\end{bmatrix}, \\quad\n  d = 1,\n \\end{displaymath}\n \\begin{itemize}[<+-| alert@+>]\n \\item[(a)] discuss its stability,\n \\item[(b)] express it in scalar form,\n \\item[(c)] compute its transfer function,\n \\item[(d)] compute the first three values ($k=0,1,2$) of its response to\n            \\begin{displaymath}\n             x(0) = \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}, \\quad\n             u(k) = 2 step(k).\n            \\end{displaymath}\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitleTC{But how can we check our results?}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item With the symbolic package wxMaxima:\n       \\begin{verbatim}\n        A  : matrix([0.4,0.4],[0.05,0.3]);\n        b  : matrix([1],[0.5]);\n        c  : matrix([2,-1]);\n        d  : 0;\n        G  : factor(c.invert(z*ident(2)-A).b+d);\n        Gr : rat(G,z);\n        x0 : matrix([2],[1]);\n        y0 : c.x0;\n        x1 : A.x0+b*0;   /* the 0   is u(0) */\n        y1 : c.x1;\n        x2 : A.x1+b*0.4; /* the 0.4 is u(1) */\n        y2 : c.x2;\n       \\end{verbatim}\n\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{But how can we check our results?}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item We are learning (the bit we need of) wxMaxima by example.\n \\item For the moment:\n       \\begin{itemize}[<+-| alert@+>]\n       \\item you SET with \\texttt{:}, \\texttt{=} is for equations,\n       \\item \\texttt{[} and \\texttt{]} delimit a list,\n       \\item matrices are defined with \\texttt{matrix} as one list per row,\n       \\item you multiply scalars (or by a scalar) with \\texttt{*}, matrices \\& vectors with \\texttt{.} (period), \n       \\item \\texttt{ident(n)} is identity of dimension n,\n       \\item \\texttt{invert} is self-explanatory, you also have \\texttt{transpose}, \\texttt{determinant},\\\\\n             \\texttt{eigenvalues}, \\texttt{eigenvectors} and much more,\n       \\item \\texttt{factor} attempts to factor an expression, \\texttt{rat(expr,var)} to express\\\\\n             \\texttt{expr} rationally wrt \\texttt{var};\n       \\item enjoy \\smiley...\n       \\end{itemize}\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Takeaways}\n\\framesubtitleTC{from exercise 01 (and the proposed one)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item A transfer function is the ratio of two polynomials.\n \\item We call the roots of its numerator the \\TC{zeroes}.\n \\item We call the roots of its denominator the \\TC{poles}. \n \\item The poles are eigenvalues of $A$.\n \\item The degree of the numerator is at most equal to that of the denominator,\n \\item and equal iff $d \\neq 0$ (you will see this in the proposed exercise, try to\\\\\n       prove it holds true in general).\n \\item We call the number of poles minus that of zeroes the \\TC{relative degree}\\\\\n       of the system.\n \\end{itemize}\n\\end{frame}\n\n", "meta": {"hexsha": "ac460c2b89c9f8f9ef050c7799413baa5f57af70", "size": 10684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Unit-03/sections/01-PS01-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-03/sections/01-PS01-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-03/sections/01-PS01-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": 38.1571428571, "max_line_length": 114, "alphanum_fraction": 0.5116997379, "num_tokens": 3643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.6529479029886216}}
{"text": "\\lab{CVXOPT}{CVXOPT}\n\\label{lab:Optimization 2}\n\\objective{Introduce some of the basic optimization functions available in the CVXOPT package}\n\nYou can learn about more about CVXOPT at\n\n\\url{http://abel.ee.ucla.edu/cvxopt/documentation/}.\n\n\\section*{Linear Programs}\n\n%%Cvxopt has linear program solver and can implement integer programming through the Gnu Linear Programming Kit, glpk.\nCVXOPT is a package of Python functions and classes for the purpose of convex optimization.\nIn 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^Tx \\\\\n\\text{subject to}\\qquad &Gx + s = h\\\\\n&Ax = b \\\\\n &s \\geq 0.\n\\end{align*}\nThis is the formulation used by CVXOPT.\nIn this formulation, we require that the matrix $A$ has full row rank,\nand that the block matrix $[G \\quad A]^T$ has full column rank.\n\nNote that the constraint $Gx +s = h$ includes the term $s$, which is not part of the objective\nfunction, and is known as the \\emph{slack variable}. Since $s  \\geq 0$, the constraint\n$Gx + s = h$ is equivalent to $Gx \\leq h$.\n\nThe corresponding \\emph{dual program} for the above linear program has the form\n\\begin{align*}\n\\text{maximize}\\qquad &-h^Tz - b^Ty \\\\\n\\text{subject to}\\qquad &G^Tz + A^Ty + 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\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 \\leq 3 \\\\\n\t\t&x_1, x_2 \\geq 0\n\\end{align*}\nThe final two constraints, $x_1, x_2 \\geq 0$, 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  2 & 1\\\\\n  -1 & 0\\\\\n  0 & -1\n\\end{bmatrix}\n\\]\nand\n\\[\nh = \\begin{bmatrix}\n  3\\\\\n  3\\\\\n  0\\\\\n  0\n\\end{bmatrix},\n\\]\nthen we can express the constraints compactly as\n\\[\nGx \\leq h,\n\\]\nwhere\n\\[\nx = \\begin{bmatrix}\n  x_1\\\\\n  x_2\n\\end{bmatrix}.\n\\]\nBy adding a slack variable $s$, we can write our constraints as\n\\[\nGx + s = h,\n\\]\nwhich matches the form discussed above. In the case of this particular example, we ignore the extra constraints\n\\[\nAx = b,\n\\]\nsince we were given no equality constraints.\n\nNow we proceed to solve the problem using CVXOPT.\nWe need to initialize the arrays $c$, $G$, and $h$, and then pass them to the appropriate function.\nCVXOPT uses its own data type for arrays and matrices, and while similar to the NumPy array, it\ndoes have a few differences, especially when it comes to initialization.\nBelow, we initialize CVXOPT matrices for $c$, $G$, and $h$.\n\n\\begin{lstlisting}\n>>> from cvxopt import matrix\n>>> c = matrix([-4., -5.])\n>>> G = matrix([[1., 2., -1., 0.],[2., 1., 0., -1.]])\n>>> h = matrix([ 3., 3., 0., 0.])\n\\end{lstlisting}\nObserve that CVXOPT matrices are initialized column-wise rather than row-wise (as in the case of NumPy).\n\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>>> c = np.array([-4., -5.])\n>>> G = np.array([[1., 2.],[2., 1.],[-1., 0.],[0., -1]])\n>>> h = np.array([3., 3., 0., 0.])\n\n>>> #Now convert to CVXOPT matrix type\n>>> c = matrix(c)\n>>> G = matrix(G)\n>>> h = matrix(h)\n\\end{lstlisting}\nUse whichever method is most convenient. Note that we made sure the entries in the matrices are floats.\n\nHaving initialized the necessary objects, we are now ready to solve the problem.\nWe will use the function \\li{solvers.lp}, and we simply need to pass $c$, $G$, and $h$ as arguments.\n\\begin{lstlisting}\n>>> from cvxopt import solvers\n>>> sol = solvers.lp(c, G, h)\n     pcost       dcost       gap    pres   dres   k/t\n 0: -8.1000e+00 -1.8300e+01  4e+00  0e+00  8e-01  1e+00\n 1: -8.8055e+00 -9.4357e+00  2e-01  1e-16  4e-02  3e-02\n 2: -8.9981e+00 -9.0049e+00  2e-03  1e-16  5e-04  4e-04\n 3: -9.0000e+00 -9.0000e+00  2e-05  1e-16  5e-06  4e-06\n 4: -9.0000e+00 -9.0000e+00  2e-07  1e-16  5e-08  4e-08\nOptimal solution found.\n>>> print sol['x']\n[ 1.00e+00]\n[ 1.00e+00]\n>>> print sol['primal objective']\n-8.99999981141\n\\end{lstlisting}\nThe function \\li{solvers.lp} returns a dictionary containing useful information.\nFor the time being, we will focus just on the values of $x$ and the primal objective value (i.e. the minimum value achieved by\nthe objective function).\n\\begin{problem}\nSolve the following convex optimization problem\n\\begin{align*}\n\\text{minimize } &2x_1+x_2+3x_3 \\\\\n\\text{subject to } &x_1+2x_2 \\geq 3 \\\\\n\t        &2x_1+x_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*}\nReport the values of $x$ and the primal objective function that you obtain.\nRemember to make the necessary adjustments so that all inequality constraints $\\leq$ rather than $\\geq$.\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.\nHow many pianos should each supply center send 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\\\\\n1 & 5 & 7 & q\\\\\n2 & 4 & 6 & r\\\\\n2 & 5 & 8 & s\\\\\n3 & 4 & 8 & t\\\\\n3 & 5 & 9 & u\\\\\n\\end{tabular}\n\\caption{Cost of transporting one piano from supply center to demand center}\n\\label{tab:cost}\n\\end{table}\n\nThe variables $p,q,r,s,t,$ and $u$ must be nonnegative and satisfy the following three supply and two demand constraints:\n\\begin{align*}\np + q  &= 7\\\\\nr + s  &= 2\\\\\nt + u  &= 4\\\\\np + r + t &= 5\\\\\nq + s + u &= 8\n\\end{align*}\n\nThe objective function is the number of pianos shipped from each location multiplied by the respective cost:\n\\[\n4p + 7q + 6r + 8s + 8t + 9u.\n\\]\n\nThere a several ways to solve this linear program. We want our answers to be integers, and this added constraint turns out to be an NP-hard problem\nin general. There is a whole field devoted to dealing with integer constraints, called 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\nHere, $G$ and $h$ constrain the variables to be non-negative.\nBecause CVXOPT uses the format $Gx \\leq h$, we see that $G$ must be a $6 \\times 6$ identity matrix multiplied by $-1$, and\n$h$ is just a column vector of zeros.\nThe matrices $A$ and $b$ represent the supply and demand constraints, since these are equality constraints.\nTry initializing these arrays and solving the linear program by entering the code below. (Notice that\nwe pass more arguments to \\li{solvers.lp} since we have equality constraints.)\n\\begin{lstlisting}\n>>> c = matrix([4., 7., 6., 8., 8., 9])\n>>> G = matrix(-1*np.eye(6))\n>>> h = matrix(np.zeros(6))\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 = 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  4e-17  2e-01  1e+00\nTerminated (singular KKT matrix).\n>>> print sol['x']\n[ 3.00e+00]\n[ 4.00e+00]\n[ 5.00e-01]\n[ 1.50e+00]\n[ 1.50e+00]\n[ 2.50e+00]\n>>> print sol['primal objective']\n89.5\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).\nFurther, the solution that was obtained does 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 some of the equality constraints into \\emph{inequality} constraints, so that\nthe remaining equality constraints define a new matrix $A$ with linearly independent rows.\n\nRather than fuss about which equality\nconstraints to convert into inequality constraints, let us simply convert all of the equality constraints.\nThis is done as follows. Suppose we have the equality constraint\n\\[\nx + 2y - 3z = 4.\n\\]\nThis is equivalent to the pair of inequality\nconstraints\n\\begin{align*}\nx + 2y - 3z &\\leq 4, \\\\\nx + 2y - 3z &\\geq 4.\n\\end{align*}\nOf course, we require only $\\leq$ constraints, so we obtain the pair\nof constraints\n\\begin{align*}\nx + 2y - 3z &\\leq 4, \\\\\n-x - 2y + 3z &\\leq -4.\n\\end{align*}\n\nApply this process to each of the equality constraints. You will obtain a new matrix $G$ with several additional rows (to account for the new inequality\nconstraints), and a new vector $h$, also with more entries. Having done this, we no longer have equality constraints $A$ and $b$, so these can be ignored.\n\\begin{problem}\nSolve the problem by converting all equality constraints into inequality constraints.\nReport the optimal values for $x$ and the primal objective function.\n\\end{problem}\n\n\\begin{comment}\n\\section*{Example}\n\nWhy are all of the terms in $G$ and $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 except that the objective function is quadratic rather\nthan linear. However, the constraints, if there are any, are still of the same form.\nThus $G, h, A$, and $b$ are optional. The formulation that we will use is\n\\begin{lstlisting}[mathescape]\nminimize $\\frac{1}{2}x^TQx + p^Tx$\nsubject to $Gx\\leq h$\n\t        $Ax = b$.\n\\end{lstlisting}\n\\begin{align*}\n\\text{minimize}\\qquad &\\frac{1}{2}x^TQx + p^Tx \\\\\n\\text{subject to}\\qquad &Gx \\leq h\\\\\n &Ax = b,\n\\end{align*}\nwhere $Q$ is a positive semidefinite symmetric matrix.\nIn this formulation, we require again that $A$ have full row rank, and that the block matrix\n$[P \\quad G \\quad A]^T$ have full column rank.\n\nAs an example, let us minimize the quadratic function\n\\[\nf(x,y) = 2x^2 +2xy + y^2 +x -y.\n\\]\nNote that there are no constraints, so we only need to initialize the matrix $Q$ and the vector $p$.\n\\begin{lstlisting}\n>>> Q = matrix([[4., 2.], [2., 2.]])\n>>> p = matrix([1., -1.])\n>>> sol=solvers.qp(Q, p)\n>>> print(sol['x'])\n[-1.00e+00]\n[ 1.50e+00]\n>>> print sol['primal objective']\n-1.25\n\\end{lstlisting}\nBuilding the matrix $Q$ from the function $f$ is straightforward. The coefficients for each squared term are doubled and then placed on the main diagonal of $Q$ (so the term $2x^2$ yields $4$ in the upper left entry of\n$Q$, and the term $y^2$ yields $2$ in the lower right entry).\nThe coefficient of each mixed term appears twice according to the row and column corresponding to the two\nvariables in the mixed term (so the term $2xy$ yields a $2$ placed in the first row, second column and in\nthe second row, first column). \n\n\\begin{problem}\nFind the minimizer and minimum of\n\\begin{equation*}\ng(x,y,z) = \\frac{3}{2}x^2 +2xy + xz+ 2y^2 +2yz+\\frac{3}{2}z^2+3x + z\n\\end{equation*}\n\\begin{comment}\n\\begin{equation}\nf(x) = \\frac{1}{2}x^TQx - x^Tp\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\\section*{Allocation Models}\nAllocation models lead to simple linear programs. An allocation model seeks to allocate a valuable resource among competing needs. The following example is 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 an assignment of land (in acreage) in each analysis area to each of the \nprescriptions for that analysis area.\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. \nThe first column is the area of analysis $i$. The second column is size of the analysis area (in thousands of acres), denoted $s_i$. The third column is a prescription number denoted $j$. The forth column is net present value (NPV) per acre of all uses in area $i$ under prescription $j$, denoted $p_{i,j}$. The fifth column is protected timber yield (in board feet per acre) in area $i$ under prescription $j$, denoted $t_{i,j}$. The sixth column is protected grazing capability (in animal unit months per acre) for area $i$ under prescription $j$, denoted\n$g_{i,j}$. The seventh and last column is the wilderness index rating (0 to 100) for area $i$ under prescription $j$, denoted $w_{i,j}$. Let $x_{i,j}$ be the amount of land in area $i$ allocated to prescription $j$.\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\\label{tab:forest}\n\\end{table}\n\nUnder this notation, and allocation is just a vector consisting of the $x_{i,j}$'s. For this particular\nexample, the allocation vector is of size $7\\cdot 3 = 21$. \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 animal unit months of grazing, and keeping the average wilderness index at least 70.\n\nOf course, the allocation vector is also constrained to be nonnegative, and all the land must be allocated \nprecisely. \n\nNote that since acres are in thousands we also divide out 1000 from the constraints of timber and animals months of grazing. We can summarize our problem 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 above problem. Output the value of each $x_{i,j}$ and the maximum total net present value (return the primal objective multiplied by -1000).\n\\end{problem} ", "meta": {"hexsha": "9e49ab772f96ba95a7f30239a5a2abd1a38936aa", "size": 18780, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/cvxopt/cvxopt.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": "Python/cvxopt/cvxopt.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": "Python/cvxopt/cvxopt.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": 37.6352705411, "max_line_length": 557, "alphanum_fraction": 0.6496805112, "num_tokens": 6578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6529479028471504}}
{"text": "\\chapter{Calculation of Forces}\n\\label{app:forces}\n\\stoptocwriting\nThe calculation of forces from a given potential model is central to the geometry optimisation routines (see section \\ref{s:geomopt}) employed in many algorithms in this thesis.\nThis appendix derives the equations used to calculate the forces for the potentials covered throughout this work.\nThe notation used will aim to be consistent, and is outlined as follows.\nA position vector is denoted by $\\vr=\\left[x\\, y\\right]^{T}$, with:\n\\begin{align}\n\t\\vrij=\\vrj-\\vri, \\\\\n\tr_{ij}=\\abs{\\vrij}, \\\\\n\t\\vhrij=\\frac{\\vrij}{r_{ij}}.\n\\end{align}\nThe derivative of a function with respect to $\\vr$ is then given by $\\frac{\\partial f\\left(\\vr\\right) }{\\partial \\vr}=\\left[\\frac{\\partial f\\left(\\vr\\right)}{\\partial x}\\, \\frac{\\partial f\\left(\\vr\\right)}{\\partial y}\\right]^{T}$.\nIt therefore follows that:\n\\begin{align}\n\t\\frac{\\partial r_{ij}}{\\partial\\vrij}=\\vhrij\\,,\\quad \\frac{\\partial r_{ij}}{\\partial \\vri}=-\\vhrij\\,,\\quad \\frac{\\partial r_{ij}}{\\partial \\vrj}=\\vhrij .\n\\end{align}\n\nAngles are denoted by $\\theta_{ijk}$, representing the angle between $\\vrij$ and $\\vrik$. \nIt will also be useful to determine the derivative of the cosine of angles with respect to a position vector:\n\\begin{align}\n\t\\frac{\\partial \\cos\\theta_{ijk}}{\\partial \\vrj} &= \\frac{\\partial}{\\partial \\vrj}\\left(\\frac{\\vrij\\cdot\\vrik}{r_{ij}r_{ik}}\\right) \\nonumber \\\\[0.5em]\n\t&= \\frac{r_{ij}r_{ik}\\vrik-\\vrij\\cdot\\vrik\\vhrij\\vrik}{r_{ij}^2r_{ik}^2} \\nonumber \\\\[0.5em]\n\t&= \\frac{1}{r_{ij}}\\left(\\vhrik-\\vhrij\\cdot\\vhrik\\vhrij\\right) \\nonumber \\\\[0.5em]\n\t&= \\frac{1}{r_{ij}}\\left(\\vhrik-\\cos\\theta_{ijk}\\vhrij\\right),\n\\end{align}\nand similarly\n\\begin{equation}\n\t\\frac{\\partial \\cos\\theta_{ijk}}{\\partial \\vrk} = \\frac{1}{r_{ik}}\\left(\\vhrij-\\cos\\theta_{ijk}\\vhrik\\right).\n\\end{equation}\nThese relationships form the basis to derive the forces for the various stretching and angular potentials used in this thesis.\n\nThe force on a given particle at $\\vri$ is given by the negative derivative of the potential:\n\\begin{equation}\n\t\\vfi=-\\frac{\\partial \\mathcal{U}}{\\partial \\vri}.\n\\end{equation}\nAs forces are conservative, the sum of the forces on all particles must be zero \\ie{} for stretching and angular terms respectively:\n\\begin{align}\n\t\\vfi &= -\\vfj, \\label{eq:fistretch}\\\\\n\t\\vfi &= -\\vfj -\\vfk. \\label{eq:fiangle}\\\n\\end{align}\nIn the following sections $\\fk$ denotes a force constant and a subscript zero an equilibrium value.\n\n\\section{Harmonic Stretching Potential}\n\nThe harmonic stretching potential is a simple bonding potential that approximates many atomic potentials at small displacements.\nThe interaction between two particles at separation $\\vrij$ is given by:\n\\begin{equation}\n\t\\mathcal{U} = \\frac{\\fk}{2}\\left(r_{ij}-r_0\\right)^2.\n\\end{equation}\nThe forces are therefore:\n\\begin{align}\n\t\\vfj&=-\\frac{\\partial \\mathcal{U}}{\\partial r_{ij}} \\frac{\\partial r_{ij}}{\\partial \\vrj} = -\\fk\\left(r_{ij}-r_0\\right)\\vhrij,\n\\end{align}\nwith $\\vfi$ given by equation \\eqref{eq:fistretch}.\n\n\\section{Quartic Stretching Potential}\n\nThe quartic stretching potential is related to the harmonic potential, but is even more computationally efficient as no square root operations are required.\nThe interaction between two particles at separation $\\vrij$ is given by:\n\\begin{equation}\n\t\\mathcal{U} = \\frac{\\fk}{4}\\left(r_{ij}^2-r_0^2\\right)^2.\n\\end{equation}\nThe forces are therefore:\n\\begin{align}\n\t\\vfj&=-\\frac{\\partial \\mathcal{U}}{\\partial r_{ij}} \\frac{\\partial r_{ij}}{\\partial \\vrj} = -\\fk\\left(r_{ij}^2-r_0^2\\right)\\vrij,\n\\end{align}\nwith $\\vfi$ given by equation \\eqref{eq:fistretch}.\n\n\\section{Shifted and Cut 24\\--12 Potential}\n\nThe shifted and cut 24\\--12 potential is a computationally efficient way to imitate short range hard repulsions, whilst maintaining continuous forces.\nThe interaction between two particles at separation $\\vrij$ is given by:\n\\begin{equation}\n\t\\mathcal{U} = \n\t\\begin{cases}\n\t\\epsilon \\left[ \\left(\\frac{r_{0}}{r_{ij}}\\right)^{24}-2\\left(\\frac{r_{0}}{r_{ij}}\\right)^{12} \\right] + \\epsilon & r_{ij}\\leq r_{0} \\\\\n\t0 & \\text{otherwise}\n\t\\end{cases}.\n\\end{equation}\nThe forces are therefore:\n\\begin{align}\n\t\\vfj&=-\\frac{\\partial \\mathcal{U}}{\\partial r_{ij}} \\frac{\\partial r_{ij}}{\\partial \\vrj} = \\begin{cases}\n\t\\frac{24\\epsilon}{r} \\left[ \\left(\\frac{r_{0}}{r_{ij}}\\right)^{24}-\\left(\\frac{r_{0}}{r_{ij}}\\right)^{12} \\right] & r_{ij}\\leq r_{0} \\\\\n\t0 & \\text{otherwise}\n\t\\end{cases}    ,\n\\end{align}\nwith $\\vfi$ given by equation \\eqref{eq:fistretch}.\n\n\\section{Harmonic Cosine Angle Potential}\n\nIn analogue with the stretching potential, the harmonic cosine angle is a elegant yet simple form angular potential, utilising the cosine function to reduce overheads when calculating angles.\nThe interaction between three particles with angle $\\theta_{ijk}$ is given by:\n\\begin{equation}\n\t\\mathcal{U} = \\frac{\\fk}{2}\\left(\\cos\\theta_{ijk}-\\cos\\theta_0\\right)^2.\n\\end{equation}\nThe forces are therefore:\n\\begin{align}\n\t\\vfj&=-\\frac{\\partial \\mathcal{U}}{\\partial \\cos\\theta_{ijk}} \\frac{\\partial \\cos\\theta_{ijk}}{\\partial \\vrj} \\nonumber \\\\ \n\t&=-\\frac{\\fk}{r_{ij}}\\left(\\cos\\theta_{ijk}-\\cos\\theta_0\\right)\\left(\\vhrik-\\cos\\theta_{ijk}\\vhrij\\right) ,\n\\end{align}\nwith $\\vfk$ having an analogous form and $\\vfi$ given by equation \\eqref{eq:fiangle}.\n\n\\section{Restricted Bending Potential}\n\nThe restricted bending (ReB) potential is a modification on the harmonic cosine angle potential which diverges at $\\theta_{ijk}=0,\\pi$, ensuring angles cannot become reflex.\nThe interaction between three particles with angle $\\theta_{ijk}$ is given by:\n\\begin{equation}\n\t\\mathcal{U} = \\frac{\\fk}{2}\\frac{\\left(\\cos\\theta_{ijk}-\\cos\\theta_0\\right)^2}{\\sin^2\\theta_{ijk}}.\n\\end{equation}\nThe forces are therefore:\n\\begin{align}\n\t\\vfj&=-\\frac{\\partial \\mathcal{U}}{\\partial \\cos\\theta_{ijk}} \\frac{\\partial \\cos\\theta_{ijk}}{\\partial \\vrj} \\nonumber \\\\ \n\t&=-\\frac{\\fk}{r_{ij}\\sin^4\\theta_{ijk}}\\left(\\cos\\theta_{ijk}-\\cos\\theta_0\\right)\\left(1-\\cos\\theta_{ijk}\\cos\\theta_0\\right)\\left(\\vhrik-\\cos\\theta_{ijk}\\vhrij\\right) ,\n\\end{align}\nwith $\\vfk$ having an analogous form and $\\vfi$ given by equation \\eqref{eq:fiangle}.\n\n\\section{Keating Potential}\n\nThe Keating potential combines the quartic stretching potential with a computationally efficient angle potential of the form:\n\\begin{equation}\n\t\\mathcal{U} = \\frac{\\fk}{2}\\left(\\vrij\\cdot\\vrik-r_0^2\\cos\\theta_0\\right)^2,\n\\end{equation}\nfor three particles with an angle given by $\\vrij$ and $\\vrik$.\nThe forces are therefore:\n\\begin{align}\n\t\\vfj&=-\\frac{\\partial \\mathcal{U}}{\\partial \\vrj} \\nonumber \\\\ \n\t&=-\\fk\\left(\\vrij\\cdot\\vrik-r_0^2\\cos\\theta_0\\right)\\vrik ,\n\\end{align}\nwith $\\vfk$ having an analogous form and $\\vfi$ given by equation \\eqref{eq:fiangle}.\n\n\\section{Proper Line Intersection}\n\nSome potential models have an additional term to prevent overlap of edges in a \\td{} network, termed proper line intersection.\nThis can be detected using standard computational geometry algorithms \\cite{ORourke1998}.\nThe signed area of a triangle, $A$, is given by:\n\\begin{equation}\n\tA\\left(\\mathbf{r}_0, \\mathbf{r}_1, \\mathbf{r}_2\\right) = \\frac{1}{2}\\sum_{i=0}^{2} \\left(x_iy_{i+1}-y_ix_{i+1}\\right).\n\\end{equation}\nA point can then be designated ``left'' of a line segment if $A>0$ and ``right'' otherwise.\nOverlap of two line segments can be detected if one point of one segment is ``left'' and the other point ``right'' with respect to the other segment, and no three points are collinear.\n\\resumetocwriting", "meta": {"hexsha": "ff9d897f598f2dcfe9f61824043c855c6d2ee474", "size": 7514, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/forces.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/forces.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/forces.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": 52.9154929577, "max_line_length": 230, "alphanum_fraction": 0.7222517966, "num_tokens": 2392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6529478973152107}}
{"text": "\\subsection{The Classical Monodromy Theorem}\r\n\\begin{theorem}[Classical Monodromy Theorem]\r\n    Let $D\\subset\\mathbb C$ be a domain and $(f,U)$ is a function element in $D$ that can be analytically continued along any path in $D$ starting in $U$.\r\n    If $(f,U)\\approx_\\alpha (g_1,V)$ and $(f,U)\\approx_\\beta(g_2,V)$ and $\\alpha\\simeq\\beta$, then $g_1=g_2$ on $V$.\r\n\\end{theorem}\r\nTherefore analytically continuing along a path only depends on the homotopy class of the path of continuation.\r\n\\begin{proof}\r\n    Let $\\tilde{\\alpha},\\tilde{\\beta}$ be the lifts of $\\alpha,\\beta$ to $\\mathcal G$ such that $\\tilde{\\alpha}(0)=[f]_{\\alpha(0)}=\\tilde{\\beta(0)}$.\r\n    As $\\alpha\\simeq\\beta$, we have $\\tilde{\\alpha}\\simeq\\tilde{\\beta}$ by Theorem \\ref{monodromy}.\r\n    Hence $\\tilde{\\alpha}(1)=\\tilde{\\beta}(1)$, which means $[g_1]_{\\alpha(1)}=[g_2]_{\\beta(1)}$, so $g_1,g_2$ coincides on some neighbourhood of $\\alpha(1)=\\beta(1)$, which implies $g_1=g_2$ on $V$ by the identity principle.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $D$ be a simply connected domain and $(f,U)$ a function element on $D$.\r\n    If $(f,U)$ can be analytically continued along every path in $D$ starting in $U$, then $(f,U)$ extends to an analytic function $f:D\\to\\mathbb C$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nNice.", "meta": {"hexsha": "20f9a5f88ea13ef1ceec998a2b067dfcea2c6a8b", "size": 1317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9/monod.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": "9/monod.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": "9/monod.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": 69.3157894737, "max_line_length": 226, "alphanum_fraction": 0.6750189825, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6529478954712309}}
{"text": "\\section{Starting to Deal With the Poles}\nIt is time to deal with the pole situation. The north and south poles that is, not the lovely people over in Poland. We run into problems because the latitude longitude grid cells become to small \nnear the poles. Therefore, the magnitudes no longer fit into one cell and overflow into other cells which makes everything kind of funky. So we need to fix that, and we do that by a planar \napproximation. \n\n\\subsection{The Theory Behind the Planar Approximation}\nAs said earlier, the grid cells on the latitude longitude grid get closer together the closer you get to the poles which poses problems. To fix this, we will be using a planar approximation of \nthe poles. What this means is that we will map the 3D grid near the poles onto a 2D plane parallel to the poles, as if we put a giant flat plane in the exact center of the poles and draw lines\nfrom the grid directly upwards to the plane. For a visual representation, please consult the stream with timestamp 1:38:25 \\cite{polarPlane}, which includes some explanation. In the streamm we\nuse $r$ to indicate the radius of the planet (which we assume is a sphere), $\\theta$ for the longitude and $\\lambda$ for the latitude. So we have spherical coordinates, which we need to transform\ninto $x$ and $y$ coordinates on the plane. We also need the distance between the center point (the point where the plane touches the planet which is the center of the pole) and the projected \npoint on the plane from the grid (the location on the plane where a line from the gird upwards to the plane hits it). This distance is denoted by $a$ (Simon chose this one, not me). We then get \nthe following equations as shown in \\autoref{eq:polar distance}, \\autoref{eq:polar x} and \\autoref{polar y}. \n\n\\begin{subequations}\n    \\begin{equation}\n        a = r \\cos(\\theta)\n        \\label{eq:polar distance}\n    \\end{equation}\n    \\begin{equation}\n        x = a \\sin(\\lambda)\n        \\label{eq:polar x}\n    \\end{equation}\n    \\begin{equation}\n        y = a \\cos(\\lambda)\n        \\label{eq:polar y}\n    \\end{equation}\n\\end{subequations}\n\nBut what if we know $x$ and $y$ and want to know $\\theta$ and $\\lambda$? Pythagoras' Theorem then comes into play \\cite{pythagoras}. We know that (due to Pythagoras) \\autoref{eq:pythagoras} must \nalways be true. Then if we substitue $a$ by $\\sqrt{x^2 + y^2}$ in \\autoref{eq:polar distance} we get \\autoref{eq:polar theta1}. Then we transform that equation such that we only have $\\theta$ on \none side and the rest on the other side (since we want to know $\\theta$) and we get \\autoref{eq:polar theta3}.\n\\begin{equation}\n    x^2 + y^2 = a^2\n    \\label{eq:pythagoras}\n\\end{equation}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\sqrt{x^2 + y^2} = r\\cos(\\theta)\n        \\label{eq:polar theta1}\n    \\end{equation}\n    \\begin{equation}\n        \\frac{\\sqrt{x^2 + y^2}}{r} = \\cos(\\theta)\n        \\label{eq:polar theta2}\n    \\end{equation}\n    \\begin{equation}\n        \\cos^{-1}(\\frac{\\sqrt{x^2 + y^2}}{r}) = \\theta\n        \\label{eq:polar theta3}\n    \\end{equation}\n\\end{subequations}\n\nFor $\\lambda$ we need another trigonometric function which is the tangent ($\\tan$). The tangent is defined in \\autoref{eq:tan}. If we then take a look at \\autoref{eq:polar x} and \n\\autoref{eq:polar y}, we see that $\\lambda$ is present in both equations. So we need to use both to get $\\lambda$ \\footnote{Yes you could only use one but since we both know $x$ and $y$ it is a\nbit easier to use both than to only use one as you need to know $\\theta$ at that point as well which may or may not be the case.}. So let's combine \\autoref{eq:polar x} and \\autoref{eq:polar y}\nin \\autoref{eq:polar lambda1}, transform it such that we end up with only $\\lambda$ on one side and the rest on the other side and we end up with \\autoref{eq:polar lambda3}.\n\n\\begin{equation}\n    \\tan(\\alpha) = \\frac{\\sin(\\alpha)}{\\cos(\\alpha)}\n    \\label{eq:tan}\n\\end{equation}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\frac{x}{y} = \\frac{a\\sin(\\lambda)}{a\\cos(\\lambda)} = \\frac{\\sin(\\lambda)}{\\cos(\\lambda)}\n        \\label{eq:polar lambda1}\n    \\end{equation}\n    \\begin{equation}\n        \\frac{x}{y} = \\tan(\\lambda)\n        \\label{eq:polar lambda2}\n    \\end{equation}\n    \\begin{equation}\n        \\lambda = \\tan^{-1}(\\frac{x}{y})\n        \\label{eq:polar lambda3}\n    \\end{equation}\n\\end{subequations}\n\nWith this math we can fix a lot of stuff in the model. With this we can resample (mapping from sphere to plane) the pressure, density, temperarature and advection to the plane and ensure that \nthere are no more overflows and funky business. The implementation (code) for this will be done in a follow up stream, so stay tuned!", "meta": {"hexsha": "921fb6c5b865c2dafb4c1a18949e8f82235b06fa", "size": 4702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/streams/Stream9.tex", "max_stars_repo_name": "balintf/claude", "max_stars_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex-docs/streams/Stream9.tex", "max_issues_repo_name": "balintf/claude", "max_issues_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex-docs/streams/Stream9.tex", "max_forks_repo_name": "balintf/claude", "max_forks_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.5189873418, "max_line_length": 196, "alphanum_fraction": 0.7031050617, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.652947889939291}}
{"text": "\\section{First implementation of plane wave basis: {\\tt PWGrid\\_01.jl}}\n\nTo describe a plane wave basis, we need to define our periodic simulation box\nby specifying three lattice vectors. We also need to specify number sampling\npoints for each lattice vector.\nWe will store the lattice vector in $3\\times3$ matrix.\n({\\color{red} add convention for lattice vectors, probably using\nthe same convention as PWSCF input file}).\n\nIn file {\\tt PWGrid\\_01.jl}, we give an implementation of plane wave basis\nset, which is encapsulated in a user-defined type {\\tt PWGrid}.\nAn instance of {\\tt PWGrid} can be initialize via code like this:\n\n\\begin{juliacode}\nNs = [40, 40, 40]  # sampling points\nLatVecs = 10*diagm(ones(3))  # lattice vectors for cubic system\npw = PWGrid( Ns, LatVecs )\n\\end{juliacode}\n\n\\subsection{Details of {\\tt PWGrid}}\n\nLet's look into details of {\\tt PWGrid}.\n\n\\verb|PWGrid| is defined like this:\n\n\\begin{juliacode}\ntype PWGrid\n  Ns::Array{Int64}\n  LatVecs::Array{Float64,2}\n  RecVecs::Array{Float64,2}\n  Npoints::Int\n  Ω::Float64\n  r::Array{Float64,2}\n  G::Array{Float64,2}\n  G2::Array{Float64}\nend\n\\end{juliacode}\n\nSome explanation about these fields follow:\n\n\\begin{itemize}\n\n\\item {\\tt Ns} is an integer array which defines number of sampling points\nin each lattice vectors.\n\n\\item {\\tt LatVecs} is $3\\times3$ matrix which defines lattice vectors of\nunit cell in real space.\n\n\\item {\\tt RecVecs} is $3\\times3$ matrix which defines lattice vectors of\nunit cell in reciprocal space. It is calculated according to \\eqref{eq:recvecs}.\n\n\\item {\\tt Npoints} Total number of sampling points\n\\item {\\tt Ω} Unit cell volume in real space\n\\item {\\tt r} Real space grid points\n\\item {\\tt G} \\textbf{G}-vectors\n\\item {\\tt G2} Magnitude of \\textbf{G}-vectors\n\n\\end{itemize}\n\nThe constructor for {\\tt PWGrid} is defined as follow.\n\\begin{juliacode}\nfunction PWGrid( Ns::Array{Int,1}, LatVecs::Array{Float64,2} )\n  Npoints = prod(Ns)\n  RecVecs = 2*pi*inv(LatVecs')\n  Ω = det(LatVecs)\n  R,G,G2 = init_grids( Ns, LatVecs, RecVecs )\n  return PWGrid( Ns, LatVecs, RecVecs, Npoints, Ω, R, G, G2 )\nend\n\\end{juliacode}\n\nThe function {\\tt init\\_grid()} is defined as follow. It takes\n{\\tt Ns}, {\\tt LatVecs}, and {\\tt RecVecs} as the arguments.\n\n\\begin{juliacode}\nfunction init_grids( Ns, LatVecs, RecVecs )\n\\end{juliacode}\n\nFirst, grid points in real space are initialized:\n\n\\begin{juliacode}\n  Npoints = prod(Ns)\n  r = Array(Float64,3,Npoints)\n  ip = 0\n  for k in 0:Ns[3]-1\n  for j in 0:Ns[2]-1\n  for i in 0:Ns[1]-1\n    ip = ip + 1\n    r[1,ip] = LatVecs[1,1]*i/Ns[1] + LatVecs[2,1]*j/Ns[2]\n              + LatVecs[3,1]*k/Ns[3]\n    r[2,ip] = LatVecs[1,2]*i/Ns[1] + LatVecs[2,2]*j/Ns[2]\n              + LatVecs[3,2]*k/Ns[3]\n    r[3,ip] = LatVecs[1,3]*i/Ns[1] + LatVecs[2,3]*j/Ns[2]\n              + LatVecs[3,3]*k/Ns[3]\n  end\n  end\n  end\n\\end{juliacode}\n\nIn the next step, grid points in reciprocal space, or \\textbf{G}-vectors\nand also their squared values are initialized\n\n\\begin{juliacode}\n  G  = Array(Float64,3,Npoints)\n  G2 = Array(Float64,Npoints)\n  ip    = 0\n  for k in 0:Ns[3]-1\n  for j in 0:Ns[2]-1\n  for i in 0:Ns[1]-1\n    gi = mm_to_nn( i, Ns[1] )\n    gj = mm_to_nn( j, Ns[2] )\n    gk = mm_to_nn( k, Ns[3] )\n    ip = ip + 1\n    G[1,ip] = RecVecs[1,1]*gi + RecVecs[2,1]*gj + RecVecs[3,1]*gk\n    G[2,ip] = RecVecs[1,2]*gi + RecVecs[2,2]*gj + RecVecs[3,2]*gk\n    G[3,ip] = RecVecs[1,3]*gi + RecVecs[2,3]*gj + RecVecs[3,3]*gk\n    G2[ip] = G[1,ip]^2 + G[2,ip]^2 + G[3,ip]^2\n  end\n  end\n  end\n\\end{juliacode}\n\nThe function {\\tt mm\\_to\\_nn} defines mapping from real space to Fourier space:\n\n\\begin{juliacode}\nfunction mm_to_nn(mm::Int,S::Int)\n  if mm > S/2\n    return mm - S\n  else\n    return mm\n  end\nend\n\\end{juliacode}\n\nFinally, the variables \\verb|r|, \\verb|G|, and \\verb|G2| are returned.\n\n\\begin{juliacode}\n  return r,G,G2\n\\end{juliacode}\n\n\n\\subsection{Visualizing real-space grid points}\n\nIn the directory \\verb|pwgrid_01|, we visualize grid points in real space\nusing Xcrysden program. Originally Xcrysden, is meant to visualize crystalline structure,\nhowever, we also can use it to visualize grid points, taking periodic boundary\nconditions into consideration.\nThis is useful to check whether grid points are generated correctly or not.\nAn example of such visualization is shown in Figure \\ref{fig:R_grid_hex}\n\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.25]{images/R_grid_hexagonal.png}\n\\par\n\\caption{Visualization of real space grid points of a hexagonal unit cell.}\n\\label{fig:R_grid_hex}\n\\end{figure}\n", "meta": {"hexsha": "146f11196e82a36d9cb8fc97e958b8646c6b45cc", "size": 4519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PW/Doc/pwgrid_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/pwgrid_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/pwgrid_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": 28.7834394904, "max_line_length": 89, "alphanum_fraction": 0.6937375526, "num_tokens": 1597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6529351713386294}}
{"text": "\\section{Spectral Approximation for Fokker-Plank-Kolmogorov Equation}\n\n\tThe method that we are going to describe in this section will be developed in a space of Hilbert $\\mathcal{H}$ with interior product $\\langle \\cdot, \\cdot \\rangle_{\\mathcal{H}}$, where we will define a Gaussian measure $\\mu$ with zero mean. Based on \\cite{Delgado2016}, the Fokker-Planck-Kolmogorov equation is presented as follows\n\t\\begin{align}\n\t\t\\label{kolmogorov}\n\t\t\\frac{\\partial u}{\\partial t} = \\frac{1}{2} Tr(D^2 u) + \\langle A(x), Du\\rangle_{\\mathcal{H}} + \\langle B(x), Du\\rangle_{\\mathcal{H}}, \\hspace{0.1cm} x \\in D(A)\n\t\\end{align}\n\twhere $Tr$ is the trace operator, $A: D (A) \\subset \\mathcal{H} \\rightarrow \\mathcal{H}$ is a linear differential operator, $B: D (B) \\subset \\mathcal{H } \\rightarrow \\mathcal{H}$ is a nonlinear operator, and $D$ represents the Frechet derivative. \\\\\n\t\n\tThe main idea of ​​the method is to solve the previous equation associating the following stochastic differential equation\n\t\\begin{align}\n\t\tdX_t = AX_t dt + B(X_t) dt + dW_t\n\t\t\\label{stochastic_equation}\n\t\\end{align}\n\twhere $W_t$ is a process $Q$-Wiener as defined in (\\ref{cylindrical}), and the solution for the equation (\\ref{kolmogorov}) is defined as follows\n\t\\begin{align}\n\t\tu(x, t) = \\mathbb{E} \\left[ u_0 (X^x_t) \\right] \n\t\t\\label{solution_kolmogorov}\n\t\\end{align}\n\twhere $u_0: \\mathcal{H} \\rightarrow \\mathbb{R}$, and $X_t^x$ is the solution of the equation (\\ref{stochastic_equation}). \\\\\n\t\n\tFollowing our reference, the solution to the problem (\\ref{kolmogorov}) is represented by an expansion known as Fourier-Hermite which is given by the following series\n\t\\begin{align}\n\t\t\\label{infinite_approximation}\n\t\tu(x, t) = \\displaystyle \\sum_{n \\in J} u_n (t) H_n (x), \\hspace{2mm} x \\in \\mathcal{H}, \\hspace{2mm} t \\in [0, T],\n\t\\end{align}  \n\twhere $u_n : [0, T] \\rightarrow \\mathbb{R}$ and $H_n (x)$ are the Hermite functionals defined in \\ref{hermite_funcionals}, and $J$ as in \\ref{Conjunto_J}. \\\\\n\t  \n\tThe above expansion can be justified by the Lemmas \\ref{dense} and \\ref{eigen}, and also is known as the deterministic Wiener-Chaos descomposition. Similarly, as we have seen in the previous chapter, it must satisfy the problem (\\ref{kolmogorov}). For this, define the following operator\n\t\\begin{align}\n\t\\label{operator_L}\n\t\t\\mathcal{L} u = \\frac{1}{2} Tr(D^2 u) + \\langle Ax, Du\\rangle_{\\mathcal{H}}, \\hspace{2mm} x \\in \\mathcal{H}\n\t\\end{align}\n\twhich represents the linear part of (\\ref{kolmogorov}), and by Lemma \\ref{eigen} satisfies the following\n\t\\begin{align}\n\t\t\\label{Descomposition_L}\n\t\t\\mathcal{L} u = - \\sum_{n \\in J} u_n (t) \\lambda_n H_n (x).\n\t\\end{align}\t\n\t\n\tSo, substituting the expansion on the left side of the equation (\\ref{kolmogorov}) we get \n\t\\begin{align}\n\t\t\\label{aprox_time}\n\t\t\\frac{\\partial u}{\\partial t} = \\displaystyle \\sum_{n \\in J}  \\dot{u}_n (t) H_n (x),\n\t\\end{align} \n\tand for the non-linear term \n\t\\begin{align*}\n\t\t\\langle B(x), Du\\rangle_{\\mathcal{H}} = \\left\\langle B(x), D_x \\displaystyle \\sum_{n \\in J} u_n (t) H_n (x)  \\right\\rangle_{\\mathcal{H}} \n\t\\end{align*}\t\n\t\\begin{align}\n\t\t\\label{aprox_B}\n\t\t\\hspace{8mm} = \\displaystyle \\sum_{n \\in J} u_n (t) \\left( B(x), D_x H_n (x) \\right)_{\\mathcal{H}}\n\t\\end{align}\n\t\n\tTherefore, by (\\ref{Descomposition_L} - \\ref{aprox_B}) the equation (\\ref{kolmogorov}) can be written as\n\t\\begin{align*}\n\t\t\\displaystyle \\sum_{n \\in J}  \\dot{u}_n (t) H_n (x) = - \\sum_{n \\in J} u_n (t) \\lambda_n H_n (x) + \\sum_{n \\in J} u_n (t) \\left( B(x), D_x H_n (x) \\right)_{\\mathcal{H}}\n\t\\end{align*}\n\n\tTo develop the above, in the space $\\mathcal{H}$ define the Gaussian measure $\\mu (dx) = \\frac{1}{\\sqrt{2 \\pi}} e^{- \\frac{x^2 }{2}}$. So, multiplying the previous equation by $H_m (x)$, $m \\in J$ and integrating over $\\mathcal{H}$ with respect to the measure $\\mu(dx)$ we have to\n\t\\begin{align*}\n\t\t\\displaystyle \\sum_{n \\in J}  \\dot{u}_n (t) \\int_{\\mathcal{H}} H_m (x) H_n (x) \\mu (dx) = &- \\sum_{n \\in J} u_n (t) \\lambda_n \\int_{\\mathcal{H}} H_m (x)  H_n (x) \\mu (dx) \\\\\n\t\t&+ \\sum_{n \\in J} u_n (t) \\int_{\\mathcal{H}} H_m (x) \\left( B(x), D_x H_n (x) \\right)_{\\mathcal{H}} \\mu (dx)\n\t\\end{align*}\n\tand also using the orthogonality of the system $\\{H_m (x) \\}$, we get the following infinite system of coupled ordinary differential equations\n\t\\begin{align}\n\t\t\\label{infinite_system}\n\t\t\\dot{u}_{m} (t) = -u_{m} (t) \\lambda_{m} + \\displaystyle \\sum _{n \\in \\mathcal{J}} u_{n} (t) C_{n, m} , \\hspace{2mm} n, m \\in \\mathcal{J}\t\n\t\\end{align}\\textbf{}\n\twhere $C_{n, m}$ is given by\n\t\\begin{align}\n\t\t\\label{Cnm}\n\t\tC_{n, m} = \\displaystyle  \\int_{\\mathcal{H}} H_m (x) \\left( B(x), D_x H_n (x) \\right)_{\\mathcal{H}} \\mu (dx)\n\t\\end{align} \n\n\tWe need to truncate and solve the above system to get approximations of the solution to the equation (\\ref{kolmogorov}), which will be done in the next section focusing on the Burgers' equation given by (\\ref{burgers_stochastic}).", "meta": {"hexsha": "7caab3bc76c1f0bab9abdbc2189b69828e00a8d5", "size": 4906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/stochastic/numerical_method/Spectral_Approximation.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_method/Spectral_Approximation.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_method/Spectral_Approximation.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": 65.4133333333, "max_line_length": 332, "alphanum_fraction": 0.6785568691, "num_tokens": 1799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6529277202496498}}
{"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\\usepackage{tikz-3dplot}\n\n\\newcommand{\\f}[1]{o_{#1}x_{#1}y_{#1}z_{#1}}\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{\\rx}[1]{\\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & cos(#1) & -sin(#1) \\\\ 0 & sin(#1) & cos(#1) \\end{bmatrix}}\n\\newcommand{\\ry}[1]{\\begin{bmatrix} cos(#1) & 0 & sin(#1) \\\\ 0 & 1 & 0 \\\\ -sin(#1) & 0 & cos(#1) \\end{bmatrix}}\n\\newcommand{\\rz}[1]{\\begin{bmatrix} cos(#1) & -sin(#1) & 0 \\\\ sin(#1) & cos(#1) & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}}\n\n\\newcommand{\\vv}[1]{\\overline{v}_{#1}}\n\n\\title{CSci 5551 - HW2}\n\\author{Yashasvi Sriram Patkuri\\\\patku001@umn.edu}\n\n\\begin{document}\n\\maketitle\n\\pagebreak\n\n\\section{}\n\\subsection*{1.a}\n$ k \\equiv \\begin{bmatrix} k_x \\\\ k_y \\\\ k_z \\end{bmatrix} $ is a unit vector.\nA rotation about k by an angle $\\theta$ is considered.\n\\given\n\nRotation matrix corresponding to this rotation is\n\\[\n  R \\equiv\n  \\begin{bmatrix}\n    k_x^2v\\theta + c\\theta & k_xk_yv\\theta - k_zs\\theta & k_xk_zv\\theta + k_ys\\theta\\\\\n    k_xk_yv\\theta + k_zs\\theta & k_y^2v\\theta + c\\theta & k_yk_zv\\theta - k_xs\\theta \\\\\n    k_xk_zv\\theta - k_ys\\theta & k_yk_zv\\theta + k_xs\\theta & k_z^2v\\theta + c\\theta\n  \\end{bmatrix}\n\\]\nwhere $v\\theta \\equiv 1 - c\\theta$.\n\\rtp\n\nThe rotation matrix for a rotation about z-axis by angle $\\theta$ is\n\\[\n  R_{z,\\theta} \\equiv \\rz{\\theta}\n\\].\n\\fromlectures\n\n\\paragraph{Idea}\nConsider a frame $ F_1 $ in which\n\\begin{enumerate}[nolistsep]\n  \\item The z-axis is aligned with what appears as k from global frame.\n  \\item The x and y axes are arbitrary perpendicular unit vectors in the plane perpendicular to its z-axis.\n\\end{enumerate}\nBy selecting an arbitrary y-axis perpendicular to z-axis, $ F_1 $ is completely known.\nThe rotation transformation matrix $ R_1^0 $ b/w global frame $ F_0 $ and $ F_1 $ is now completely known.\n\nFor a given vector $ v^0_a $ in $ F_0 $, we can get its representation $ v^1_a $ in $ F_1 $ using $ R_1^0 $.\nWe know the rotation matrix for rotation about z-axis by $\\theta$.\nWe can use that to find rotated version of $ v^1_a $ say $ v^1_r $.\nFinally we get the representation of $ v^1_r $ in $ F_0 $ viz. $ v^0_r $.\n\n\\subsubsection*{Finding $R_1^0$}\nLet k be along z-axis of $ F_1 $. In general y-axis can be thought of as $ \\begin{bmatrix} p_x \\\\ p_y \\\\ p_z \\end{bmatrix} $.\nAs these are perpendicular unit vectors we have.\n\\[\n  k_x^2 + k_y^2 + k_z^2 \\equiv 1\n\\]\n\\[\n  p_x^2 + p_y^2 + p_z^2 \\equiv 1\n\\]\n\\[\n  p_x * k_x + p_y * k_y + p_z * k_z \\equiv 0\n\\]\nAs there is no restriction on the choice of y-axis we can choose the it to be in XY plane of $ F_0 $ i.e. it has the form $ \\begin{bmatrix} p_x \\\\ p_y \\\\ 0 \\end{bmatrix} $.\nTherefore above equations become\n\\[\n  k_x^2 + k_y^2 + k_z^2 \\equiv 1\n\\]\n\\[\n  p_x^2 + p_y^2 \\equiv 1\n\\]\n\\[\n  p_x * k_x + p_y * k_y \\equiv 0\n\\]\nRewriting $ p_x $ in terms of $ p_y $ we have\n\\[\n  p_x \\equiv -p_y * \\frac{k_y}{k_x}\n\\]\nSubstituting it back we get\n\\[\n  (-p_y * \\frac{k_y}{k_x})^2 + p_y^2 \\equiv 1\n\\]\n\\[\n  p_y^2 * \\frac{k_y^2 + k_x^2}{k_x^2} \\equiv 1\n\\]\nWe can choose the one of the square root. Therefore we get\n\\[\n  p_y \\equiv \\frac{k_x}{\\sqrt{k_x^2 + k_y^2}}\n\\]\n\\[\n  p_x \\equiv \\frac{-k_y}{\\sqrt{k_x^2 + k_y^2}}\n\\]\nTherefore we have\n\\[\n  p \\equiv\n  \\begin{bmatrix}\n  \\frac{-k_y}{\\sqrt{k_x^2 + k_y^2}} \\\\\n  \\frac{k_x}{\\sqrt{k_x^2 + k_y^2}}  \\\\\n  0\n  \\end{bmatrix}\n\\]\nWe can get the unit vector along x-axis $ t \\equiv \\begin{bmatrix} t_x \\\\ t_y \\\\ t_z \\end{bmatrix} $ by taking a cross product\n\\[\n  t \\equiv p \\times k\n\\]\n\\[\n  t \\equiv \\begin{bmatrix} p_y k_z - p_z k_y \\\\ p_z k_x - p_x k_z \\\\ p_x k_y - p_y k_x \\end{bmatrix}\n\\]\nSubstituting $ p_x, p_y, p_z $ in above equation we get\n\\[\n  t \\equiv\n  \\begin{bmatrix}\n    \\frac{k_1k_3}{\\sqrt{k_1^2 + k_2^2}} \\\\\n    \\frac{k_2k_3}{\\sqrt{k_1^2 + k_2^2}} \\\\\n    -\\sqrt{k_1^2 + k_2^2}\n  \\end{bmatrix}\n\\]\nWe have the rotation matrix\n\\[\n  R_1^0 \\equiv \\begin{bmatrix} i_1i_0 & j_1i_0 & k_1i_0 \\\\ i_1j_0 & j_1j_0 & k_1j_0 \\\\ i_1k_0 & j_1k_0 & k_1k_0 \\end{bmatrix}\n\\]\n\\fromlectures\nSubstituting columns we get\n\\[\n  R_1^0 \\equiv \\begin{bmatrix} t & p & k \\end{bmatrix}\n\\]\n\\[\n  R_1^0 \\equiv\n  \\begin{bmatrix}\n  \\frac{k_1k_3}{\\sqrt{k_1^2 + k_2^2}} & \\frac{-k_y}{\\sqrt{k_x^2 + k_y^2}}  & k_x \\\\\n  \\frac{k_2k_3}{\\sqrt{k_1^2 + k_2^2}} & \\frac{k_x}{\\sqrt{k_x^2 + k_y^2}}   & k_y \\\\\n  -\\sqrt{k_1^2 + k_2^2}               & 0 & k_z\n  \\end{bmatrix}\n\\]\nFor sanity check one can verify that the columns of matrix are orthonormal.\n\n\\subsubsection*{Rotation around $F_1$'s z-axis}\nFor any vector $ v^0 $ in $ F_0 $ its representation in $ F_1 $ is\n\\[\n  v^1 \\equiv R_0^1 * v^0\n\\]\nThe vector that results by rotating $ v^1 $ in $ F_1 $'s z-axis by an angle $ \\theta $ is\n\\[\n  v^1_r \\equiv R_{z,\\theta} * v^1\n\\]\n\\[\n  v^1_r \\equiv R_{z,\\theta} * R_0^1 * v^0\n\\]\nThe representation of $ v^1_r $ in $ F_0 $ is\n\\[\n  v^0_r \\equiv R_1^0 * v^1_r\n\\]\n\\[\n  v^0_r \\equiv R_1^0 * R_{z,\\theta} * R_0^1 * v^0\n\\]\nBut for any vector $ v^0 $ the vector resulted by rotation around k by $\\theta$ is\n\\[\n  v^0_r \\equiv R_{k,\\theta} * v^0\n\\]\nComparing the above two equations we have\n\\[\n  R_{k,\\theta} \\equiv R_1^0 * R_{z,\\theta} * R_0^1\n\\]\n\\paragraph{Gist} Aligning $ F_1 $'s z-axis with k and rotating around $ F_1 $'s z-axis by $ \\theta $ is identical to rotating around k by $ \\theta $.\n\nWe know that\n\\[\n  R_1^{0^{-1}} \\equiv R_1^{0^T} \\equiv R_0^1\n\\]\n\\fromlectures\nTherefore we have\n\\[\n  R_1^{0^{-1}} \\equiv R_{1_0^T} \\equiv R_0^1 \\equiv\n  \\begin{bmatrix}\n  \\frac{k_1k_3}{\\sqrt{k_1^2 + k_2^2}} & \\frac{k_2k_3}{\\sqrt{k_1^2 + k_2^2}} & -\\sqrt{k_1^2 + k_2^2} \\\\\n  \\frac{-k_y}{\\sqrt{k_x^2 + k_y^2}}  & \\frac{k_x}{\\sqrt{k_x^2 + k_y^2}}   & 0 \\\\\n  k_x & k_y & k_z\n  \\end{bmatrix}\n\\]\n\nTherefore everything on the right side is known and therefore we can calculate $ R_{k,\\theta} $\n\\[\n  R_{k,\\theta} \\equiv R_1^0 * R_{z,\\theta} * R_0^1\n\\]\n\\[\n  R_{k,\\theta} \\equiv\n  \\begin{bmatrix}\n  \\frac{k_1k_3}{\\sqrt{k_1^2 + k_2^2}} & \\frac{-k_y}{\\sqrt{k_x^2 + k_y^2}}  & k_x \\\\\n  \\frac{k_2k_3}{\\sqrt{k_1^2 + k_2^2}} & \\frac{k_x}{\\sqrt{k_x^2 + k_y^2}}   & k_y \\\\\n  -\\sqrt{k_1^2 + k_2^2}               & 0 & k_z\n  \\end{bmatrix}\n  *\n  \\rz{\\theta}\n  *\n  \\begin{bmatrix}\n  \\frac{k_1k_3}{\\sqrt{k_1^2 + k_2^2}} & \\frac{k_2k_3}{\\sqrt{k_1^2 + k_2^2}} & -\\sqrt{k_1^2 + k_2^2} \\\\\n  \\frac{-k_y}{\\sqrt{k_x^2 + k_y^2}}  & \\frac{k_x}{\\sqrt{k_x^2 + k_y^2}}   & 0 \\\\\n  k_x & k_y & k_z\n  \\end{bmatrix}\n\\]\nMultiplying matrices and simplifying using $ k_x^2 + k_y^2 + k_z^2 \\equiv 1 $ we get\n\\[\n  R_{k,\\theta} \\equiv\n  \\begin{bmatrix}\n    k_x^2(1 - c\\theta) + c\\theta & k_xk_y(1 - c\\theta) - k_zs\\theta & k_xk_z(1 - c\\theta) + k_ys\\theta\\\\\n    k_xk_y(1 - c\\theta) + k_zs\\theta & k_y^2(1 - c\\theta) + c\\theta & k_yk_z(1 - c\\theta) - k_xs\\theta \\\\\n    k_xk_z(1 - c\\theta) - k_ys\\theta & k_yk_z(1 - c\\theta) + k_xs\\theta & k_z^2(1 - c\\theta) + c\\theta\n  \\end{bmatrix}\n\\]\n\\[\n  R_{k,\\theta} \\equiv\n  \\begin{bmatrix}\n    k_x^2v\\theta + c\\theta & k_xk_yv\\theta - k_zs\\theta & k_xk_zv\\theta + k_ys\\theta\\\\\n    k_xk_yv\\theta + k_zs\\theta & k_y^2v\\theta + c\\theta & k_yk_zv\\theta - k_xs\\theta \\\\\n    k_xk_zv\\theta - k_ys\\theta & k_yk_zv\\theta + k_xs\\theta & k_z^2v\\theta + c\\theta\n  \\end{bmatrix}\n\\]\nwhere $v\\theta \\equiv 1 - c\\theta$.\n\\paragraph{Note} This formulation does not work iff $ k_x^2 + k_y^2 \\equiv 0 $, i.e. $ k_x \\equiv 0, k_y \\equiv 0 $, which means $ k_z \\equiv 1 $.\nThis case means that we are rotating about z-axis of $ F_0 $.\nIf we substitute values $ k_x \\equiv 0, k_y \\equiv 0, k_z \\equiv 1 $ in given matrix in the question we get the rotation matrix about z-axis, thus proving the statement for this case.\n\nHence the required statement is proved.\n\\pagebreak\n\n\\subsection*{1.b}\nWhen $\\theta = 0$, $c\\theta = 1, s\\theta = 0, v\\theta \\equiv 1 - c\\theta = 0$.\nSubstituting these in the matrix $ R_{k,\\theta} $ we have\n\\[\n  R_{k,0} \\equiv\n  \\begin{bmatrix} 0 + 1 & 0 - 0 & 0 + 0 \\\\ 0 + 0 & 0 + 1 & 0 - 0 \\\\ 0 - 0 & 0 + 0 & 0 + 1 \\end{bmatrix}\n\\]\n\\[\n  R_{k,0} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}\n\\]\nThis means that there is no rotation at all.\n\\pagebreak\n\n\\section{}\n\\subsection*{2.a}\nA frame $F_0$ is rotated in the following order\n\\begin{enumerate}[nolistsep]\n  \\item 90 degrees around $z_0$\n  \\item 30 degrees around $y_0$\n  \\item 60 degrees around $x_0$\n\\end{enumerate}\n\\given\n\nFor fixed frame rotations in the following order $R_1, R_2, R_3$ the composite rotation matrix is\n\\[\n  R \\equiv R_3 R_2 R_1\n\\]\n\\fromlectures\n\nRotation matrices around x, y, z axes are\n\\[\n  R_{x,\\theta} \\equiv \\rx{\\theta}\n\\]\n\\[\n  R_{y,\\theta} \\equiv \\ry{\\theta}\n\\]\n\\[\n  R_{z,\\theta} \\equiv \\rz{\\theta}\n\\]\n\\fromlectures\nTherefore the composite rotation matrix for given sequence of rotations is\n\\[\n  R \\equiv\n  \\rx{60^\\circ}\n  \\ry{30^\\circ}\n  \\rz{90^\\circ}\n\\]\nMultiplying we get\n\\[\n  R \\equiv\n  \\begin{bmatrix}\n    0 & -\\frac{\\sqrt{3}}{2} & \\frac{1}{2} \\\\\n    \\frac{1}{2} & -\\frac{\\sqrt{3}}{4} & -\\frac{3}{4} \\\\\n    \\frac{\\sqrt{3}}{2} & \\frac{1}{4} & \\frac{\\sqrt{3}}{4}\n  \\end{bmatrix}\n\\]\n\\pagebreak\n\n\\subsection*{2.b}\nFrom Q1 we have the rotation matrix for a rotation of angle $\\theta$ about a unit vector k as\n\\[\n  R \\equiv\n  \\begin{bmatrix} r_{11} & r_{12} & r_{13} \\\\ r_{21} & r_{22} & r_{23} \\\\ r_{31} & r_{32} & r_{33} \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    k_x^2v\\theta + c\\theta & k_xk_yv\\theta - k_zs\\theta & k_xk_zv\\theta + k_ys\\theta\\\\\n    k_xk_yv\\theta + k_zs\\theta & k_y^2v\\theta + c\\theta & k_yk_zv\\theta - k_xs\\theta \\\\\n    k_xk_zv\\theta - k_ys\\theta & k_yk_zv\\theta + k_xs\\theta & k_z^2v\\theta + c\\theta\n  \\end{bmatrix}\n\\]\nwhere $v\\theta \\equiv 1 - c\\theta$.\n\nObserve that\n\\[\n  r_{32} - r_{23} \\equiv 2k_xs\\theta\n\\]\n\\[\n  r_{13} - r_{31} \\equiv 2k_ys\\theta\n\\]\n\\[\n  r_{21} - r_{12} \\equiv 2k_zs\\theta\n\\]\n\\[\n  \\begin{bmatrix}\n    r_{32} - r_{23}\\\\\n    r_{13} - r_{31}\\\\\n    r_{21} - r_{12}\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    2k_xs\\theta\\\\\n    2k_ys\\theta\\\\\n    2k_zs\\theta\n  \\end{bmatrix}\n  \\equiv\n  2s\\theta\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n\\]\nIn our case we have\n\\[\n  \\begin{bmatrix}\n    r_{32} - r_{23}\\\\\n    r_{13} - r_{31}\\\\\n    r_{21} - r_{12}\n  \\end{bmatrix}\n  \\equiv\n  2s\\theta\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} \\frac{1 + 3}{4} \\\\ \\frac{1 - \\sqrt{3}}{2} \\\\ \\frac{1 + \\sqrt{3}}{2} \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} 1 \\\\ \\frac{1 - \\sqrt{3}}{2} \\\\ \\frac{1 + \\sqrt{3}}{2} \\end{bmatrix}\n\\]\nAs k is unit vector the L2-norm of the above vector is\n\\[\n  \\left\\lVert\n  2s\\theta\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n \\right\\rVert_2\n \\equiv\n  2s\\theta\n  \\left\\lVert\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n \\right\\rVert_2\n \\equiv\n 2s\\theta\n\\]\nHere\n\\[\n  \\left\\lVert\n  2s\\theta\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n  \\right\\rVert_2\n  \\equiv\n  \\left\\lVert\n  \\begin{bmatrix} 1 \\\\ \\frac{1 - \\sqrt{3}}{2} \\\\ \\frac{1 + \\sqrt{3}}{2} \\end{bmatrix}\n  \\right\\rVert_2\n  \\equiv\n  \\sqrt{3}\n\\]\nTherefore\n\\[\n  2s\\theta \\equiv \\sqrt{3} \\implies\n  s\\theta \\equiv \\frac{\\sqrt{3}}{2}\n\\]\nAlso observe\n\\[\n  tr(R) \\equiv (k_x^2 + k_y^2 + k_z^2) (1 - c\\theta) + 3 * c\\theta\n\\]\n\\[\n  c\\theta \\equiv \\frac{tr(R) - 1}{2} \\equiv \\frac{(0 + \\frac{\\sqrt{3}}{4} - \\frac{\\sqrt{3}}{4}) - 1}{2} \\equiv -\\frac{1}{2}\n\\]\n\\[\n  s\\theta \\equiv \\frac{\\sqrt{3}}{2}, c\\theta \\equiv -\\frac{1}{2} \\implies \\theta = 120^\\circ\n\\]\n\nSubstituting value of $\\theta$ back we have\n\\[\n  2s\\theta\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n  \\equiv\n  \\sqrt{3}\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} 1 \\\\ \\frac{1 - \\sqrt{3}}{2} \\\\ \\frac{1 + \\sqrt{3}}{2} \\end{bmatrix}\n\\]\n\\[\n  \\begin{bmatrix}\n    k_x\\\\\n    k_y\\\\\n    k_z\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} \\frac{1}{\\sqrt{3}} \\\\ \\frac{1 - \\sqrt{3}}{2\\sqrt{3}} \\\\ \\frac{1 + \\sqrt{3}}{2\\sqrt{3}} \\end{bmatrix}\n\\]\nTherefore we have\n\\[\n  k \\equiv\n  \\begin{bmatrix} \\frac{1}{\\sqrt{3}} \\\\ \\frac{1 - \\sqrt{3}}{2\\sqrt{3}} \\\\ \\frac{1 + \\sqrt{3}}{2\\sqrt{3}} \\end{bmatrix},\n  \\theta \\equiv 120^\\circ\n\\]\nObserve the same rotation transformation can be achieved by flipping the axis unit vector and angle i.e.\n\\[\n  k \\equiv\n  \\begin{bmatrix} -\\frac{1}{\\sqrt{3}} \\\\ \\frac{-1 + \\sqrt{3}}{2\\sqrt{3}} \\\\ \\frac{-1 - \\sqrt{3}}{2\\sqrt{3}} \\end{bmatrix},\n  \\theta \\equiv -120^\\circ\n\\]\n\\pagebreak\n\n\\section{}\nA given vector $v$ is rotated about a unit vector $k$ by angle $\\theta$\n\\given\n\nThe rotated vector $w$ is\n\\[\n  w \\equiv cos(\\theta) v + sin(\\theta) (k \\times v) + (1 - cos(\\theta)) (k.v) k\n\\]\n\\rtp\nTo show that rodriguez’s formula comes from equation 1 it is enough to show that equation 1 comes from rodriguez’s formula.\nConsider the terms separately\n\\[\n  cos(\\theta) v \\equiv\n  \\begin{bmatrix} v_x c\\theta \\\\ v_y c\\theta \\\\ v_z c\\theta \\end{bmatrix}\n\\]\nConsider\n\\[\n  k \\times v \\equiv\n  \\begin{bmatrix} k_y v_z - k_z v_y \\\\ k_z v_x - k_x v_z \\\\ k_x v_y - k_y v_x \\end{bmatrix}\n\\]\n\\[\n  s\\theta (k \\times v) \\equiv\n  \\begin{bmatrix} s\\theta (k_y v_z - k_z v_y) \\\\ s\\theta (k_z v_x - k_x v_z) \\\\ s\\theta (k_x v_y - k_y v_x) \\end{bmatrix}\n\\]\nConsider\n\\[\n  k.v \\equiv\n  k_x v_x + k_y v_y + k_z v_z\n\\]\n\\[\n  (k.v) k \\equiv\n  \\begin{bmatrix} (k_x v_x + k_y v_y + k_z v_z) k_x \\\\ (k_x v_x + k_y v_y + k_z v_z) k_y \\\\ (k_x v_x + k_y v_y + k_z v_z) k_z \\end{bmatrix}\n\\]\n\\[\n  (1 - c\\theta) (k.v) k \\equiv\n  \\begin{bmatrix} (1 - c\\theta) (k_x v_x + k_y v_y + k_z v_z) k_x \\\\ (1 - c\\theta) (k_x v_x + k_y v_y + k_z v_z) k_y \\\\ (1 - c\\theta) (k_x v_x + k_y v_y + k_z v_z) k_z \\end{bmatrix}\n\\]\nLet $1 - c\\theta \\equiv v\\theta$\n\\[\n  (1 - c\\theta) (k.v) k \\equiv\n  \\begin{bmatrix} v\\theta (k_x v_x + k_y v_y + k_z v_z) k_x \\\\ v\\theta (k_x v_x + k_y v_y + k_z v_z) k_y \\\\ v\\theta (k_x v_x + k_y v_y + k_z v_z) k_z \\end{bmatrix}\n\\]\nNow adding all the terms\n\\[\n  w\n  \\equiv\n  cos(\\theta) v + sin(\\theta) (k \\times v) + (1 - cos(\\theta)) (k.v) k\n\\]\n\\[\n  w\n  \\equiv\n  \\begin{bmatrix} v_x c\\theta \\\\ v_y c\\theta \\\\ v_z c\\theta \\end{bmatrix}\n  +\n  \\begin{bmatrix} s\\theta (k_y v_z - k_z v_y) \\\\ s\\theta (k_z v_x - k_x v_z) \\\\ s\\theta (k_x v_y - k_y v_x) \\end{bmatrix}\n  +\n  \\begin{bmatrix} v\\theta (k_x v_x + k_y v_y + k_z v_z) k_x \\\\ v\\theta (k_x v_x + k_y v_y + k_z v_z) k_y \\\\ v\\theta (k_x v_x + k_y v_y + k_z v_z) k_z \\end{bmatrix}\n\\]\nAdding terms\n\\[\n  w\n  \\equiv\n  \\begin{bmatrix}\n  v_x c\\theta + s\\theta (k_y v_z - k_z v_y) + v\\theta (k_x v_x + k_y v_y + k_z v_z) k_x \\\\\n  v_y c\\theta + s\\theta (k_z v_x - k_x v_z) + v\\theta (k_x v_x + k_y v_y + k_z v_z) k_y \\\\\n  v_z c\\theta + s\\theta (k_x v_y - k_y v_x) + v\\theta (k_x v_x + k_y v_y + k_z v_z) k_z\n  \\end{bmatrix}\n\\]\nRearranging terms we have\n\\[\n  w\n  \\equiv\n  \\begin{bmatrix}\n    (k_x^2v\\theta + c\\theta)v_x + (k_xk_yv\\theta - k_zs\\theta)v_y + (k_xk_zv\\theta + k_ys\\theta)v_z\\\\\n    (k_xk_yv\\theta + k_zs\\theta)v_x + (k_y^2v\\theta + c\\theta)v_y + (k_yk_zv\\theta - k_xs\\theta)v_z \\\\\n    (k_xk_zv\\theta - k_ys\\theta)v_x + (k_yk_zv\\theta + k_xs\\theta)v_y +(k_z^2v\\theta + c\\theta)v_z\n  \\end{bmatrix}\n\\]\nRewriting the right matrix as product of two matrices we have\n\\[\n  w\n  \\equiv\n  \\begin{bmatrix}\n    k_x^2v\\theta + c\\theta & k_xk_yv\\theta - k_zs\\theta & k_xk_zv\\theta + k_ys\\theta\\\\\n    k_xk_yv\\theta + k_zs\\theta & k_y^2v\\theta + c\\theta & k_yk_zv\\theta - k_xs\\theta \\\\\n    k_xk_zv\\theta - k_ys\\theta & k_yk_zv\\theta + k_xs\\theta & k_z^2v\\theta + c\\theta\n  \\end{bmatrix}\n  \\begin{bmatrix} v_x \\\\ v_y \\\\ v_z \\end{bmatrix}\n\\]\n\\[\n  w\n  \\equiv\n  \\begin{bmatrix}\n    k_x^2v\\theta + c\\theta & k_xk_yv\\theta - k_zs\\theta & k_xk_zv\\theta + k_ys\\theta\\\\\n    k_xk_yv\\theta + k_zs\\theta & k_y^2v\\theta + c\\theta & k_yk_zv\\theta - k_xs\\theta \\\\\n    k_xk_zv\\theta - k_ys\\theta & k_yk_zv\\theta + k_xs\\theta & k_z^2v\\theta + c\\theta\n  \\end{bmatrix}\n  v\n\\]\nThe latest equation is identical to equation 1.\nThus we proved that equation 1 comes from rodriguez’s formula.\nTo derive rodriguez’s formula from equation 1 one can just reverse the steps until now, though is a very unnatural way to think.\n\n\\subsection*{Getting rodriguez’s formula from scratch}\n\\subsubsection*{Perpendicular case}\nConsider a case where $v$ is perpendicular to $k$.\nTherefore $v$ and (the rotated vector) $w$ lie in the plane perpendicular to $k$.\nConsider $k \\times v$ which is perpendicular to both $k$ and $v$ and lies on plane perpendicular to $k$ as illustrated in the figures below.\n\\begin{figure}[h]\n  \\centering\n  \\tdplotsetmaincoords{60}{120}\n  \\begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick},\n    vector/.style={-stealth,red,very thick},\n    vector guide/.style={dashed,red,thick}]\n\n  \\coordinate (O) at (0,0,0);\n\n  \\pgfmathsetmacro{\\ax}{0.707}\n  \\pgfmathsetmacro{\\ay}{0.707}\n  \\pgfmathsetmacro{\\az}{0}\n\n  \\coordinate (W) at (\\ax,\\ay,\\az);\n  \\coordinate (V) at (1, 0, 0);\n\n  \\draw[axis] (0,0,0) -- (0,1,0) node[anchor=north west]{$k \\times v$};\n  \\draw[axis] (O) -- (V) node[anchor=north west]{v};\n  \\draw[axis] (O) -- (W) node[anchor=north west]{w};\n  \\draw[vector] (0,0,0) -- (0,0,1) node[anchor=south]{k};\n\n  \\draw[vector guide] (\\ax,\\ay,0) -- (0,\\ay,0);\n  \\draw[vector guide] (\\ax,\\ay,0) -- (\\ax,0,0);\n  \\end{tikzpicture}\n\n  \\begin{tikzpicture}\n  \\node [] at (0.5,0.25) {$\\theta$};\n  \\draw [thick, ->] (0,0) -- (0,5);\n  \\node [above] at (0,5) {$k \\times v$};\n  \\draw [thick, ->] (0,0) -- (5,0);\n  \\node [right] at (5,0) {$v$};\n  \\node [left] at (0,0) {($k$, out of plane)};\n  \\draw [thick, ->] (0,0) -- (3.55,3.55);\n  \\node [right] at (3.55,3.55) {$w$};\n  \\draw [dashed, -] (3.55,0) -- (3.55,3.55);\n  \\node [below] at (2,0) {$\\Vert v \\Vert cos(\\theta)$};\n  \\draw [dashed, -] (0,3.55) -- (3.55,3.55);\n  \\node [left] at (0,2) {$\\Vert v \\Vert sin(\\theta)$};\n  \\end{tikzpicture}\n  \\caption{Perpendicular case - 3D, 2D top view}\n\\end{figure}\n\nAs the angle b/w $v$ and $w$ is $\\theta$ and the length of rotated vector is identical to length of original vector we have\n\\[\n  w . \\hat{v} \\equiv \\Vert w \\Vert \\Vert \\hat{v} \\Vert cos(\\theta) \\equiv \\Vert w \\Vert cos(\\theta) \\equiv \\Vert v \\Vert cos(\\theta)\n\\]\n\\[\n  w . (k \\times \\hat{v}) \\equiv \\Vert w \\Vert \\Vert (k \\times \\hat{v}) \\Vert cos(90 - \\theta) \\equiv \\Vert w \\Vert sin(\\theta) \\equiv \\Vert v \\Vert sin(\\theta)\n\\]\nAs $k$, $v$, and $k \\times v $ form a 3D basis, using the rule of vector addition we can build $w$ in terms of $v$ and $k \\times v$\n\\[\n  w \\equiv cos(\\theta) \\Vert v \\Vert \\hat{v} + sin(\\theta) \\Vert v \\Vert (k \\times \\hat{v})\n\\]\n\\[\n  w \\equiv cos(\\theta) v + sin(\\theta) (k \\times \\Vert v \\Vert \\hat{v})\n\\]\n\\[\n  w \\equiv cos(\\theta) v + sin(\\theta) (k \\times v)\n\\]\nTherefore we expressed rotated vector $w$ in terms of axis vector $k$, original vector v and angle $\\theta$.\n\n\\subsubsection*{General case}\nNow consider a case where $v$ is not perpendicular to $k$.\nWe can split $v$ into two parts $v_{parallel}$ which is parallel to $k$ and $v_{perpendicular}$ which is perpendicular to $k$ as illustrated in the figure below.\n\\begin{figure}[h]\n  \\centering\n  \\tdplotsetmaincoords{60}{120}\n  \\begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,red,thick},\n  vector/.style={-stealth,blue,very thick},\n  vector guide/.style={dashed,red,thick}]\n\n  \\coordinate (O) at (0,0,0);\n\n  \\pgfmathsetmacro{\\ax}{0.8}\n  \\pgfmathsetmacro{\\ay}{0.8}\n  \\pgfmathsetmacro{\\az}{0.8}\n\n  \\coordinate (V) at (\\ax,0,\\az);\n  \\coordinate (W) at (\\ax,\\ay,\\az);\n\n  \\draw[axis] (0,0,0) -- (1,0,0) node[anchor=north east]{};\n  \\draw[axis] (0,0,0) -- (0,1,0) node[anchor=north west]{};\n  \\draw[axis] (0,0,0) -- (0,0,1) node[anchor=south]{$k$};\n\n  \\draw[vector] (O) -- (V);\n  \\node[anchor=east] at (V){$v$};\n  \\draw[vector] (O) -- (W);\n  \\node[anchor=west] at (W){$w$};\n  \\draw[vector]         (O) -- (\\ax,\\ay,0);\n  \\node[anchor=west] at (\\ax,\\ay,0){$w_{perpendicular}$};\n  \\draw[vector]         (O) -- (0,0,\\az);\n  \\node[anchor=west] at (0,0,\\az){$v_{parallel}$};\n  \\draw[vector]         (O) -- (\\ax,0,0);\n  \\node[anchor=south] at (\\ax,0,0){$v_{perpendicular}$};\n  \\node[anchor=north] at (0,0,0){$\\theta$};\n\n  \\draw[vector guide]         (\\ax, 0, 0) -- (V);\n  \\draw[vector guide]         (0, 0, \\az) -- (V);\n  \\draw[vector guide]         (\\ax,\\ay,0) -- (W);\n  \\draw[vector guide]         (0,0,\\az) -- (W);\n  \\end{tikzpicture}\n  \\caption{General case}\n\\end{figure}\n\nTherefore\n\\[\n  v \\equiv v_{parallel} + v_{perpendicular}\n\\]\n\\[\n  v_{parallel} \\equiv (v . k) k\n\\]\n\\[\n  v \\equiv (v . k) k + v_{perpendicular}\n\\]\n\\[\n  v_{perpendicular} \\equiv v - (v . k) k\n\\]\nThe $v_{parallel}$ component doesn't rotate as it is in the direction of axis of rotation.\n\\[\n  w \\equiv v_{parallel} + w_{perpendicular}\n\\]\n\\[\n  w \\equiv (v . k) k + w_{perpendicular}\n\\]\nThe rotated vector of $v_{perpendicular}$ say $w_{perpendicular}$ can be obtained by method similar to the perpendicular case discussed earlier.\n\\[\n  w_{perpendicular} \\equiv cos(\\theta) v_{perpendicular} + sin(\\theta) (k \\times v_{perpendicular})\n\\]\nSubstituting $v_{perpendicular}$\n\\[\n  w_{perpendicular} \\equiv cos(\\theta) (v - (v . k) k) + sin(\\theta) (k \\times (v - (v . k) k))\n\\]\n\\[\n  w_{perpendicular} \\equiv cos(\\theta) (v - (v . k) k) + sin(\\theta) (k \\times v - (v . k) (k \\times k))\n\\]\nAs $k \\times k \\equiv 0$\n\\[\n  w_{perpendicular} \\equiv cos(\\theta) (v - (v . k) k) + sin(\\theta) (k \\times v)\n\\]\nSubstituting $w_{perpendicular}$ back we have,\n\\[\n  w \\equiv (v . k) k + w_{perpendicular}\n\\]\n\\[\n  w \\equiv (v . k) k + cos(\\theta) (v - (v . k) k) + sin(\\theta) (k \\times v)\n\\]\nRearranging we have\n\\[\n  w \\equiv cos(\\theta) v + (1 - cos(\\theta)) (v . k) k + sin(\\theta) (k \\times v)\n\\]\n\\[\n  w \\equiv cos(\\theta) v + sin(\\theta) (k \\times v) + (1 - cos(\\theta)) (v . k) k\n\\]\nAs in all the above analysis $v$ is an arbitrary vector and $k$ is an arbitrary unit vector, from the above formula the required identity is proved.\n\n\\pagebreak\n\n\\section{}\n\\subsection*{4.a}\nThe rotation matrix corresponding to a rotation of $\\theta$ about a unit vector $ k \\equiv (k_x, k_y, k_z)$ is\n\\[\n  R \\equiv\n  \\begin{bmatrix}\n    k_x^2v\\theta + c\\theta & k_xk_yv\\theta - k_zs\\theta & k_xk_zv\\theta + k_ys\\theta\\\\\n    k_xk_yv\\theta + k_zs\\theta & k_y^2v\\theta + c\\theta & k_yk_zv\\theta - k_xs\\theta \\\\\n    k_xk_zv\\theta - k_ys\\theta & k_yk_zv\\theta + k_xs\\theta & k_z^2v\\theta + c\\theta\n  \\end{bmatrix}\n\\]\nwhere $v\\theta \\equiv 1 - c\\theta$ from Q1.\n\nThe rotation is small enough that\n\\[\n  sin(\\theta) \\approx \\theta\n\\]\n\\[\n  cos(\\theta) \\approx 1\n\\]\n\\[\n  \\theta^2 \\approx 0\n\\]\n\\given\n\nThen,\n\\[\n  v(\\theta) \\equiv 1 - cos(\\theta) \\equiv 0\n\\]\n\nSubstituting these values we have\n\\[\n  R \\equiv\n  \\begin{bmatrix}\n    1 & -k_z\\theta & k_y\\theta\\\\\n     k_z\\theta & 1 & -k_x\\theta \\\\\n     -k_y\\theta & k_x\\theta & 1\n  \\end{bmatrix}\n\\]\n\\pagebreak\n\n\\subsection*{4.b}\nConsider two rotations $R_1 \\equiv (a, \\theta)$ and $R_2 \\equiv (b, \\phi)$ where first term is the unit vector in fixed frame and second term is angle of rotation.\nTherefore\n\\[\n  R_1 \\equiv\n  \\begin{bmatrix}\n    1 & -a_z\\theta & a_y\\theta\\\\\n     a_z\\theta & 1 & -a_x\\theta \\\\\n     -a_y\\theta & a_x\\theta & 1\n  \\end{bmatrix}\n  \\equiv\n  I + S_1\n  ,\n  S_1 \\equiv\n  \\begin{bmatrix}\n    0 & -a_z\\theta & a_y\\theta\\\\\n     a_z\\theta & 0 & -a_x\\theta \\\\\n     -a_y\\theta & a_x\\theta & 0\n  \\end{bmatrix}\n\\]\n\\[\n  R_2 \\equiv\n  \\begin{bmatrix}\n    1 & -b_z\\phi & b_y\\phi\\\\\n     b_z\\phi & 1 & -b_x\\phi \\\\\n     -b_y\\phi & b_x\\phi & 1\n  \\end{bmatrix}\n  \\equiv\n  I + S_2\n  ,\n  S_2 \\equiv\n  \\begin{bmatrix}\n    0 & -b_z\\phi & b_y\\phi\\\\\n     b_z\\phi & 0 & -b_x\\phi \\\\\n     -b_y\\phi & b_x\\phi & 0\n  \\end{bmatrix}\n\\]\nwhere I is the 3x3 identity matrix.\n\nConsider the composition $R_1$ after $R_2$, the equivalent composite rotation matrix shall be\n\\[\n  R_1 R_2 \\equiv (I + S_1) (I + S_2)\n\\]\n\\[\n  R_1 R_2 \\equiv I + S_2 + S_1 + S_1S_2\n\\]\n\\[\n  R_1 R_2 \\equiv I + S_2 + S_1 +\n  \\begin{bmatrix}\n    0 & -a_z\\theta & a_y\\theta\\\\\n     a_z\\theta & 0 & -a_x\\theta \\\\\n     -a_y\\theta & a_x\\theta & 0\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    0 & -b_z\\phi & b_y\\phi\\\\\n     b_z\\phi & 0 & -b_x\\phi \\\\\n     -b_y\\phi & b_x\\phi & 0\n  \\end{bmatrix}\n\\]\n\\[\n  R_1 R_2 \\equiv I + S_2 + S_1 +\n  \\begin{bmatrix}\n    c_1\\theta\\phi & c_2\\theta\\phi & c_3\\theta\\phi \\\\\n    c_4\\theta\\phi & c_5\\theta\\phi & c_6\\theta\\phi \\\\\n    c_7\\theta\\phi & c_8\\theta\\phi & c_9\\theta\\phi\n  \\end{bmatrix}\n\\]\nwhere $c_i$ is some function of $(a_x, a_y, a_z, b_x, b_y, b_z)$. But as the rotations are small enough such that\n\\[\n  \\theta\\phi \\approx 0\n\\]\nwe have\n\\[\n  {\\color{green} R_1 R_2 \\equiv I + S_2 + S_1}\n\\]\n\nConsider the composition $R_2$ after $R_1$, the equivalent composite rotation matrix shall be\n\\[\n  R_2 R_1 \\equiv (I + S_2) (I + S_1)\n\\]\n\\[\n  R_2 R_1 \\equiv I + S_1 + S_2 + S_2S_1\n\\]\n\\[\n  R_2 R_1 \\equiv I + S_1 + S_2 +\n  \\begin{bmatrix}\n    0 & -b_z\\phi & b_y\\phi\\\\\n     b_z\\phi & 0 & -b_x\\phi \\\\\n     -b_y\\phi & b_x\\phi & 0\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    0 & -a_z\\theta & a_y\\theta\\\\\n     a_z\\theta & 0 & -a_x\\theta \\\\\n     -a_y\\theta & a_x\\theta & 0\n  \\end{bmatrix}\n\\]\n\\[\n  R_2 R_1 \\equiv I + S_1 + S_2 +\n  \\begin{bmatrix}\n    t_1\\theta\\phi & t_2\\theta\\phi & t_3\\theta\\phi \\\\\n    t_4\\theta\\phi & t_5\\theta\\phi & t_6\\theta\\phi \\\\\n    t_7\\theta\\phi & t_8\\theta\\phi & t_9\\theta\\phi\n  \\end{bmatrix}\n\\]\nwhere $t_i$ is some function of $(a_x, a_y, a_z, b_x, b_y, b_z)$. But as the rotations are small enough such that\n\\[\n  \\theta\\phi \\approx 0\n\\]\nwe have\n\\[\n  {\\color{blue} R_2 R_1 \\equiv I + S_1 + S_2}\n\\]\nHence\n\\[\n  {\\color{green} R_1R_2} \\equiv {\\color{blue} R_2R_1}\n\\]\nSince $R_1, R_2$ are rotation matrices for arbitrary small rotations, small rotations commute.\n\\pagebreak\n\n\\section{}\n\\[\n  q_1 \\equiv a + b \\hat{i} + c \\hat{j} + d \\hat{k}\n\\]\n\\[\n  q_2 \\equiv e + f \\hat{i} + g \\hat{j} + h \\hat{k}\n\\]\n\\[\n  q_3 \\equiv s + t \\hat{i} + u \\hat{j} + v \\hat{k}\n\\]\nare three quaternions\n\\given\n\n\\[\n  q_1(q_2q_3) \\equiv (q_1q_2)q_3\n\\]\n\\rtp\n\nThe product of two quaternions $ q_1 \\equiv (r_1, \\vv{1}) $ and $ q_2 \\equiv (r_2, \\vv{2}) $ is\n\\[\n  q_1q_2 \\equiv (r_1 r_2 - \\vv{1} . \\vv{2}, r_1 \\vv{2} + r_2 \\vv{1} + \\vv{1}\\times\\vv{2})\n\\]\n\\fromlectures\n\nLet\n\\[\n  q_1 \\equiv a + b \\hat{i} + c \\hat{j} + d \\hat{k} \\equiv (r_1, \\vv{1})\n\\]\n\\[\n  q_2 \\equiv e + f \\hat{i} + g \\hat{j} + h \\hat{k} \\equiv (r_2, \\vv{2})\n\\]\n\\[\n  q_3 \\equiv s + t \\hat{i} + u \\hat{j} + v \\hat{k} \\equiv (r_3, \\vv{3})\n\\]\nwhere $r_i, \\vv{i}$ are real and vector parts of the $i^{th}$ quaternion respectively\n\n\\subsubsection*{Expanding $q_1(q_2q_3)$}\nConsider\n\\[\n  q_1(q_2q_3) \\equiv (r_1, \\vv{1}) ((r_2, \\vv{2})(r_3, \\vv{3}))\n\\]\n\\[\n  q_1(q_2q_3) \\equiv (r_1, \\vv{1}) (r_2r_3 - \\vv{2}.\\vv{3}, r_2 \\vv{3} + r_3 \\vv{2} + \\vv{2}\\times\\vv{3})\n\\]\n\\[\n  q_1(q_2q_3) \\equiv (P, Q)\n\\]\nwhere\n\\[\n  P \\equiv r_1(r_2r_3 - \\vv{2}.\\vv{3}) - \\vv{1}.(r_2 \\vv{3} + r_3 \\vv{2} + \\vv{2}\\times\\vv{3})\n\\]\n\\[\n  Q \\equiv  r_1(r_2 \\vv{3} + r_3 \\vv{2} + \\vv{2}\\times\\vv{3})\n    + (r_2r_3 - \\vv{2}.\\vv{3})\\vv{1}\n    + \\vv{1} \\times (r_2 \\vv{3} + r_3 \\vv{2} + \\vv{2}\\times\\vv{3})\n\\]\nRearranging beautifully we get\n\\[\n  q_1(q_2q_3) \\equiv (P, Q)\n\\]\nwhere\n\\[\n  P \\equiv r_1r_2r_3 - r_1\\vv{2}.\\vv{3} - r_2\\vv{1}.\\vv{3} - r_3\\vv{1}.\\vv{2} - {\\color{green} \\vv{1} . (\\vv{2}\\times\\vv{3})}\n\\]\n\\[\n  Q \\equiv\n  r_1r_2\\vv{3}\n  + r_1r_3\\vv{2}\n  + r_2r_3\\vv{1}\n  + r_1 \\vv{2}\\times\\vv{3}\n  + r_2 \\vv{1}\\times\\vv{3}\n  + r_3 \\vv{1}\\times\\vv{2}\n  {\\color{blue}\n  - (\\vv{2}.\\vv{3})\\vv{1}\n  + \\vv{1} \\times (\\vv{2}\\times\\vv{3})}\n\\]\n\n\\subsubsection*{Expanding $(q_1q_2)q_3$}\nConsider\n\\[\n  (q_1q_2)q_3 \\equiv ((r_1, \\vv{1})(r_2, \\vv{2}))(r_3, \\vv{3})\n\\]\n\\[\n  (q_1q_2)q_3 \\equiv (r_1r_2 - \\vv{1}.\\vv{2}, r_1 \\vv{2} + r_2 \\vv{1} + \\vv{1}\\times\\vv{2}) (r_3, \\vv{3})\n\\]\n\\[\n  (q_1q_2)q_3 \\equiv (R, S)\n\\]\nwhere\n\\[\n  R \\equiv (r_1r_2 - \\vv{1}.\\vv{2})r_3 - (r_1 \\vv{2} + r_2 \\vv{1} + \\vv{1}\\times\\vv{2}).\\vv{3}\n\\]\n\\[\n  S \\equiv\n    r_3(r_1 \\vv{2} + r_2 \\vv{1} + \\vv{1}\\times\\vv{2})\n    + (r_1r_2 - \\vv{1}.\\vv{2})\\vv{3}\n    + (r_1 \\vv{2} + r_2 \\vv{1} + \\vv{1}\\times\\vv{2}) \\times \\vv{3}\n\\]\nRearranging beautifully we get\n\\[\n  q_1(q_2q_3) \\equiv (R, S)\n\\]\nwhere\n\\[\n  R \\equiv r_1r_2r_3 - r_1\\vv{2}.\\vv{3} - r_2\\vv{1}.\\vv{3} - r_3\\vv{1}.\\vv{2} - {\\color{green} (\\vv{1}\\times\\vv{2}).\\vv{3}}\n\\]\n\\[\n  S \\equiv\n  r_1r_2\\vv{3}\n  + r_1r_3\\vv{2}\n  + r_2r_3\\vv{1}\n  + r_1 \\vv{2}\\times\\vv{3}\n  + r_2 \\vv{1}\\times\\vv{3}\n  + r_3 \\vv{1}\\times\\vv{2}\n  {\\color{blue}\n  - (\\vv{1}.\\vv{2})\\vv{3}\n  + (\\vv{1}\\times\\vv{2})\\times\\vv{3}}\n\\]\n\n\\subsubsection*{Equivalence}\nExcept the colored terms all other terms are identical.\nBut we know that\n\\[\n  \\vv{1}.(\\vv{2}\\times\\vv{3}) \\equiv (\\vv{1}\\times\\vv{2}).\\vv{3}\n\\]\nfrom the properties of vector cross products, as it represents the signed volume of parallelepiped formed by vectors $\\vv{1}, \\vv{2}, \\vv{3}$.\nTherefore\n\\[\nP \\equiv R\n\\]\nWe also know the following triple product rule of cross products.\n\\[\n  \\vv{1} \\times (\\vv{2}\\times\\vv{3})\n  \\equiv\n  \\vv{2} (\\vv{1}\\vv{3})\n  - \\vv{3} (\\vv{1}\\vv{2})\n\\]\nExpanding the colored terms in Q we have\n\\[\n  {\\color{blue}\n  - (\\vv{2}.\\vv{3})\\vv{1}\n  + \\vv{1} \\times (\\vv{2}\\times\\vv{3})\n  }\n  \\equiv\n  - \\vv{1} (\\vv{2}.\\vv{3})\n  + \\vv{2} (\\vv{1}\\vv{3})\n  - \\vv{3} (\\vv{1}\\vv{2})\n\\]\nExpanding the colored terms in S we have\n\\[\n  {\\color{blue}\n  - (\\vv{1}.\\vv{2})\\vv{3}\n  + (\\vv{1}\\times\\vv{2})\\times\\vv{3}\n  }\n  \\equiv\n  - (\\vv{1}.\\vv{2})\\vv{3}\n  - \\vv{3}\\times(\\vv{1}\\times\\vv{2})\n  \\equiv\n  - \\vv{1} (\\vv{2}.\\vv{3})\n  + \\vv{2} (\\vv{1}\\vv{3})\n  - \\vv{3} (\\vv{1}\\vv{2})\n\\]\n\nTherefore\n\\[\nQ \\equiv S\n\\]\n\\[\n  (P, Q) \\equiv (R, S)\n\\]\n\\[\n  q_1(q_2q_3) \\equiv (q_1q_2)q_3\n\\]\nAs $q_1, q_2, q_3$ are arbitrary quaternions, multiplication of quaternions is associative.\n\\end{document}\n", "meta": {"hexsha": "5da13437e8861b6958cad0bf716e07a3d664f77e", "size": 29755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw2/hw2.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": "hw2/hw2.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": "hw2/hw2.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": 28.1238185255, "max_line_length": 183, "alphanum_fraction": 0.599663922, "num_tokens": 12953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.6528737372614111}}
{"text": "%\n% 61\n%\n\\chapter{The Theory of Riemann Integration}\n\n\\Section{4}{1}{The concept of integration.}\n\nThe reader is doubtless familiar with the idea of integration as the\noperation inverse to that of differentiation; and he is equally well\naware that the integral (in this sense) of a given elementary function\nis not always expressible in terms of elementary functions. In order\ntherefore to give a definition of the integral of a function which\nshall be always available, even though it is not practicable to obtain\na function of which the given function is the differential\ncoefficient, we have recourse to the result that the integral* o f x)\nbetween the limits a and h is the area bounded by the curve y =f(x),\nthe axis of cc and the ordinates x = a, x = b. We proceed to frame a\nformal definition of integration with this idea as the starting-point.\n\n\\Subsection{4}{1}{1}{Upper and lower integrals'f.}\n\nLet f(x) be a bounded function of x in the range a, b). Divide the\ninterval at the points Xi,Xo, ... Xn-iia x - x ... Xn-i b). Let U, L\nbe the bounds of /(a;) in the range (a, b), and let Ur, L be the\nbounds of f(x) in the range (xr-i, Xr), where Xq = a, Xn=b.\n\nConsider the sums:|:\n\nSn = U, (iCi - a) +Uo Xn-X,)+ ...+ Un (b - Xa-,), Sn = L, X - a) + Z/2\n( 2 - i) +    + Ln (b - Xn-i).\n\nThen U(b- a) Sn s., L b- a).\n\nFor a given n, Sn and s are bounded functions of x, x, ... n-i- Let\ntheir lower and upper bounds § respectively be S, Sn, so that Sn, s\ndepend only on n and on the form of f x), and not on the particular\nway of dividing the interval into n parts.\n\n* Defined as the (elementary) function whose differential coefficient\nis/(x).\n\nt The following procedure for establishing existence theorems\nconcerning integrals is based on that given by Goursat, Cours d'\nAnalyse, i. Ch. iv. The concepts of upper and lower integrals are due\nto Darboux, Ann. de I'Ecole norm. sup. (2) iv. (1875), p. 64.\n\n+ The reader will find a figure of great assistance in following the\nargument of this section. Sn and s represent the sums of the areas of\na number of rectangles which are respectively greater and less than\nthe area bounded by y=f(x), x-a, x-h and ?/ = 0, if this area be\nassumed to exist.\n\n§ The bounds of a function of n variables are defined in just the same\nmanner as the bounds of a function of a single variable \\hardsubsectionref{3}{6}{2}).\n\n%\n% 62\n%\n\nLet the lower and upper bounds of these functions of n be S, s. Then\n\nSn > S, Sn S.\n\nWe proceed to shew that s is at most equal to S; i.e. S' s.\n\nLet the intervals (a, x ), x-, x., ... be divided into smaller\nintervals by new points of subdivision, and let\n\na,y,y, ... yu-i, yk = i), yk+i,  yi-i, yi = 2), yi+1,  Vm-i, h be\nthe end points of the smaller intervals; let U L,.' be the bounds of\n/( ) in the interval y,-i, yr)-\n\nm m\n\nLet T,, = X yr- yr-i) UJ, t,n = t y,. - yr-i) L,!.\n\nr=\\ r=l\n\nSince Ui, U.2, ... Uk do not exceed JJi, it follows without difficulty\nthat\n\nNow consider the subdivision of (a, b) into intervals by the points\nx-y, X2, ... Xn-\\, and also the subdivision by a different set of\npoints a? x, ... x'n'-i- Let S'n',s'n' be the sums for the second\nkind of sub- division which correspond to the sums *S, Sn for the\nfirst kind of subdivision. Take all the points x, ... Xn-i] x, ...\nx'n'\\ y as the points y, y., ... y .\n\nThen 8n T, t,, Sn,\n\nand S'n' T n tm s'n' .\n\nHence every expression of the type Sn exceeds (or at least equals)\nevery expression of the type s'n'; and therefore S cannot be less\nthan s.\n\n[For \\ i S<s and s - S - 27] we could find an Sn and an s'n' such that\ng - S<r], s - s'n'<'n and so s'n'>Sn, which is impossible.]\n\nThe bound S is called the upper integral off(x), and is written 1 f(x)\ndx;\n\nJ a\n\ns is called the lower integral, and written I / x) dx.\n\nJ a\n\nIf S = s, their common value is called the integral of f(x) taken\nbetween the limits* of integration a and b.\n\nThe integral is written I f x)dx. .\n\nra rb\n\nWe define | f x)dx, when a< b, to mean - I f(x)dx. Exam'ple 1, I /\n(*') + (*-') dx = \\ f(x) dx+ l (x) dx.\n\nJ a J a J a\n\nExample 2. By means of example 1, define the integral of a continuous\ncomplex function of a real variable.\n\n* ' Extreme values ' would be a more appropriate term but ' limits '\nhas the sanction of custom. 'Termini' has been suggested by Lamb,\nInfinitesimal Calculus (1897), p. 207.\n\n%\n% 63\n%\n\n\\Subsection{4}{1}{2}{Riemann's condition of integrability*.}\n\nA function is said to be ' integrable in the sense of Riemann ' if\n(with the notation of \\hardsubsectionref{4}{1}{1}) Sn and s,i have a common limit (called\nthe Riemann integral of the function) when the number of intervals\nx,.\\ -, x ) tends to infinity in such a way that the length of the\nlongest of them tends to zero.\n\nThe necessa7-y and sufficient condition that a bounded function should\nhe integrahle is that S - Sn should teiid to zero luhen the numher of\nintervals (xr-i, Xr) tends to infinity in such a way that the length\nof the longest tends to zero.\n\nThe condition is obviously necessary, for if S and s,i have a common\nlimit n - Sn - ► as 71 - > 30 . And it is sufficient; for, since Sn\nS' s s,i, it follows that if lim (Sn - Sn) = 0, then\n\nlim *S' = lim s = S = s.\n\nNote. A continuous function f(x) is 'integrable.' For, given e, we can\nfind 8 such that \\ f(af) - f x\")\\ < (l b-a) whenever \\ x' - x\"\\ < 8.\nTake all the intervals Xg\\ i, x-g) less than 8, and then Ug- Lg<€/ b -\na) and so >S' - s <e; therefore <S' - s - -0 under the circumstances\n.specified in the condition of integrahility.\n\nCorollary. If <S' and s have the same limit S for one mode of\nsubdivision of (a, h) into intervals of the specified kind, the limits\nof .S' and of s for any other such mode of subdivision are both 8.\n\nExample I. The product of two integi'able functions is an integrable\nfunction.\n\nExample 2. A function which is continuous except at a finite number of\nordinary discontinuities is integrable.\n\n\\ li f(x) have an ordinary discontinuity at c, enclose c in an\ninterval of length S,; given f, we can find 8 so that j f x')-f x) \\\n< e when i x' -x \\ <8 and x, x' are not in this interval.\n\nThen *S' -s,j f (6-a-8i) + /'Si, where k is the greatest value of \\ f\nx')-f x)\\, when X, x' lie in the interval.\n\nWhen Si- 0, y(-- |/(c + 0)-/(c-0), and hence lim (.S' -s )=0.]\n\n -*\n\nExample 3. A function with limited total fluctuation and a finite\nnumber of ordinary discontinuities is integrable. (See \\hardsubsectionref{3}{6}{4} example\n2.)\n\n\\Subsection{4}{1}{3}{A general theorem on integration.}\n\nLet /(a;) be integrable, and let e be any positive number. Then it is\npossible to choose S so that\n\nn rh\n\nt xp - Xj,\\ i)f(x'p\\ i) - f x)dx < 6,\n\np=\\ J a\n\nprovided that Xy - Xp\\ i- h, Xp\\ i x'p\\ i%Xp.\n\n* Biemann (Ges. Math. Werke, p. 239) bases his definition of an\nintegral on the limit of the sum occurring in § -i-lS; but it is then\ndifficult to prove the uniqueness of the limit. A more general\ndefinition of integration (which is of very great importance in the\nmodern theory of Functions of Real Variables) has been given by\nLebesgue, Annali di Mat. (3) vn. (1902), pp. 231-359. See also his\nLecons sur V integration (Paris, 1904).\n\n%\n% 64\n%\n\nTo prove the theorem we observe that, given e, we can choose the\nlength of the longest interval, B, so small that S - Sn < e.\n\nw\n\nAlso Sn> S ( - \\ i)/(a?' -i) Sn,\n\np = l\n\n  a\n\nTherefore\n\n  rb\n\n2 xp - Xp\\ )f(a;'p\\,) - f(x) dx\n\n9 = 1 J a\n\n s.,\n\n  f-Jn ' n\n\n< 6.\n\nAs an example* of the evaluation of a definite integral directly from\nthe theorem of this section consider I \" - j, where X<1.\n\nJo (1- 2)2\n\nTake S= - arc sin X and let,?,= sin s8, (0 <s8 <h tt), so that\n\n s+i-A's=2 sin |S cos (s+ ) 8< S;\n\nalso let Xg = sin (s + i) 8.\n\n, P . c - - s-i sin sS - sin (5 - 1)S\n\nThen 2 - '- = 2 \\,.\n\ns=i(i\\ y2 \\ j)i .=1 cos(s-A)S\n\n= 2/9 sin 2 S\n\n= arc sin X. sin |S/(JS) .\n\nBy taking p sufficiently large we can make\n\nP dx I Xg-Xs-i\n\nJo (l\\,,.2)i,s=l(l\\ . '2 \\ j)4\n\narbitrarily small.\n\nWe can also make arc sin X . < -j-| 1\n\narbitrarily small.\n\nThat is, given an arbitrary number f, we can make\n\nP dx\n\n/ i~\n\n<e\n\narc sin X\n\nby taking p sufficiently large. But the expression now under\nconsideration does not\n\ndepend on p; and therefore it must be zero; for if not we could take\nc to be less than it,\n\nand we should have a contradiction.\n\nrx f g That is to say I '- - =arc sin X.\n\nJo (i\\ .' )2\n\nExample 1. Shew that\n\nX 2x (n - l)x\n\nI+COS- + COS f-...+cos -\n\n,. 71 n n sm\n\nIim - - - . - - - - - - = .\n\nn-*-'x> *'' -\n\nExample 2. If f(x) has ordinary discontinuities at the points aj, 02,\n..., then\n\nfb ( fu -S, fa.,-S., [b 1\n\nf x)dx = \\ \\ m\\ \\ + +...+ f x)dx\\,\n\nJ a \\ J a J a, +6, J ax + <c J\n\nwhere the limit is taken by making 81, S2, ... §, ei, t i  f* tend\nto +0 independently. * Netto, Zeitschriftfilr Math, und Phys. xl.\n(1895).\n\n%\n% 65\n%\n\nExample 3. If /( ) is integrable when i x i and if, when Oj a < 6 < 6i\n, we write\n\n/ f x)dx = <i> a, b), and if/(6 + 0) exists, then\n\nlim < (,\\& + fi)-> K\\&) ( o)\n\nDeduce that, i f(x) is continuous at a and b,\n\nd\\\n\nda\n\njjix) dx= -f a), -I jjix) dx=f b). Bxample 4. Prove by differentiation\nthat, if (f> x) is a continuous function of ./; and\n\ndx\n\n-y- a continuous function of t, then\n\nat\n\nfxi l ft fir\n\n < x)dx=\\ \\ x)'j dt.\n\nExample 5. If /' x) and < ' x) are continuous when a x b, shew from\nexample 3 that\n\nr / (x) <i> o;) dx + J'l 4>' x)f x) dx=f b) < (b) -f a) cf> (a).\n\nExample 6. If/(.r) is integrable in the range (a, c) and 6 c, shew\nthat I f(x) dx\n\nJ a is a continuous function of b.\n\n\\Subsection{4}{1}{4}{J/c ?i Fa we Theorems.}\n\nThe two following general theorems are frequently useful.\n\n(I) Let U and L be the upper and lower bounds of the integrable\nfunction /(.r) in the range (a, b).\n\nThen from the definition of an integral it is obvious that\n\nJ' U-f x)] dx, j ' fj(x) L) dx\n\nare not negative; and so\n\nU b-a)- l f x)dx L b-a).\n\nThis is known as the First Mean Value Theorem.\n\nli' f(x) is contimious we can find a number | .such that a- b and such\nthat/( ) has any given value lying between U and L \\hardsubsectionref{3}{6}{3}). Therefore\nwe can find | such that\n\nrf x)dx = b-a)f \\$).\n\nJ a\n\nIf F(x) has a continuous differential coefficient F' (x) in the range\n(a, 6), we have, on\n\nwriting F' (x) for f(x),\n\nF b)-F d) = b-a)F' )\n\nfor some value of such that a b.\n\nExample. lif x) is continuous and ( x)' 0, shew that can be found such\nthat\n\n' fix) cf> (x) dx =f (I) / % (x) dx.\n\na J a.\n\nW. M. A.\n\n%\n% 66\n%\n\n(11) Let /(.? ) and 4> .v) be integrable in the range (o, b) and let\n(a-) be a positive decreasing function of .r. Then Bonnefs* form of\nthe Second Mean Value Theorem is that a number exists such that a | 6,\nand\n\n \" f x)ci> x)dx 4> a) \\ \\ f x)dx. \\ y'\n\nJ a J a\n\nFor, with the notation of §§ 4'1-4'13, consider the sum\n\np ♦ .;S'= 2 Xs-x,\\ i)f x,\\ )(i> x,\\ ).\n\ns=l\n\nWriting x - x y) f x,\\ i) = a,\\ i, Xs-i) = 4>s-\\, o + i + --- + 08 =\ns, 'e have\n\nEach term in the summation is increased by writing b for 6g\\ i and\ndecreased by writing b for ftg\\ i, if b, b be the greatest and least\nof 6o, 6i, ... 6p\\ i; and so b(j)(, S b(Po-\n\nm\n\nTherefore S lies between the greatest and least of the sums ( ) xq) 2\n(xg-Xg\\ i)f Xg\\ i)\n\ns=l\n\nwhere m = l, 2, 3, ... p. But, given e, we can find 8 such that, when\nXg-Xg\\ i<d,\n\np f p I\n\n2 x, - x,\\ i)f Xs i) (t> (.r,\\ i) - I f(x) (f) (x) dx < e,\n\nS=l J 0 I\n\nm Cxra [\n\n< (:ro) 2 X, -Xs-i)/ (X, \\ i) - < ( o) / / ( ) < *- < f, s=l a I\n\nand so, writing a, b for a'q, . p, we find that / f x)(j> x)dx lies\nbetween the upper and\n\nJ a'\n\nlower bounds ott < (a) I ' f .v)d.v±2e, where j may take all values\nbetween a and ?>.\n\nLet C and L be the upper and lower bounds of </> (a) j f(x) dx.\n\nJ a\n\nfh\n\nThen U+ 2e I /'(.r) < ( 0 dx' L-2e for a jjositive values of e;\ntherefore\n\nr I f (x) cfi (x) dx L.\n\nSince (j) a) I \\ f(x) dx qua function of j takes all values between\nits upper and lower J\n\nbounds, there is some value, .say, of |i for which it is equal to I f\n(x) (f> (x) dx. This proves the Second Mean Value Theorem.\n\nE.rarnple. By writing ( x) -(f> b)\\ in place of (f) (.v) in Bonnet's\nform of the mean value theorem, .shew that if < (x) is a monotonic\nfunction, then a number | exists such that a \\$ b and\n\n\\ f x)(l> x)dx = 4> a) j f x)dx + 4) b) j f x)dx.\n\n\\addexamplecitation{Du Bois Reymond.}\n\n* Journal de Math. xiv. (1849), p. 249. The proof given is a modified\nform of an iuvestigatiou due to Holder, Gdtt. Nach. (1889), pp. 38-47.\n\n+ By § 413 example 6, since /(.r) is bounded, I ' f(x) d.v is a\ncontinuous function of fj.\n\n%\n% 67\n%\n\n\\Section{4}{2}{Differentiation of integrals containing a parameter.}\n\nThe equation* f x, a)dx=\\ dx is true if f(x, a) possesses a\n\nace J (I (I vCL\n\nRiemann integral with respect to x and fa. = \\ is a continuous\nfunction of hoth-f the variables x and a.\n\nFor I- '/(., ) <fa = lim f .Aj;.\\ ° + A)-/( . )\n\neta j a h-f-O .' a h\n\nif this limit exists. But, by the first mean value theorem, since / is\na continuous function of a, the second integrand is fa x, a + 6h),\nwhere\n\nBut, for any given e, a number 8 independent of x exists (since the\ncon- tinuity of fa is uniform]: with respect to the variable x) such\nthat\n\n\\ fa x, a) -fa (x, a) I < e/(6 - a), whenever | a' - a | < S.\n\nTaking j A | < S we see that ! 6h | < 8, and so whenever \\ h < 8,\n\n[H x, a + h) -fix, a) J i *,,,, [ ., m x w m\n\n - -! y - J \\ ' / dx- \\ /a (, a) dx I fa (x, a + Oh) - / (x, a) \\ dx\n\n< e.\n\nTherefore by the definition of a limit of a function \\hardsectionref{3}{2}), lim\ni'f(-. + h)-f(, .a)\n\nh O J a h\n\nI\"*\n\nexists and is equal to fadx.\n\nJ a\n\nExample 1. If a, b be not constant.s but functions of a with\ncontinuous differential coefficients, shew that\n\n |'/(.- a)d.v=f b, a) -/(a, ) +/ fj:.:\n\nExample 2. If /(.r, a) is a continuous function of both variables, / f\nx, a)dx is a\n\nJ a continuous function of a.\n\n* This formula was given by Leibniz, without specifying the\nrestrictions laid on/(.r, a).\n\nt (p x, y) is defined to be a continuous function of both variables\nif, given e, we can find 5 such that | 4> x', y') - (/> (x, y)\\ < €\nwhenever (x' - x)' + (y' - y)' -<S. It can be shewn by \\hardsectionref{3}{6} that if\n(x, y) is a continuous function of both variables at all points of a\nclosed region in a Cartesian diagram, it is uniformly continuous\nthroughout the region (the proof is almost identical with that of §\n3-61). It should be noticed that, if (.r, y) is a continuous function\nof each variable, it is not necessarily a continuous function of both\n; as an example take\n\n [x,y)=. p!, 0(0,0) 1;\n\nthis is a continuous function of x and of y at (0, 0), but not of both\nx and y.\n\nX It is obvious that it would have been sufficient to assume that /\nhad a Riemann integral and was a continuous function of a (the\ncontinuity being uniform with respect to x), instead of assuming that\n/ was a continuous function of both variables. This is actually done\nby Hobson, FuJictions of a Real Variable, p. 599.\n\n5-2\n\n%\n% 68\n%\n\n\\Section{4}{3}{Double integrals and repeated integrals.}\n\n'Letf x, y) be a function which is continuous with regard to both of\nthe variables x and y, when a x h, a y - /3,\n\nBy \\hardsectionref{4}{2} example 2 it is clear that\n\nj 1 1 /( ' y) dy\\ dx, j U J x, y) dx\\ dy both exist. These are called\nrepeated integrals.\n\nAlso, as in \\hardsubsectionref{3}{6}{2}, f(x, y), being a continuous function of both\nvariables, attains its upper and lower bounds.\n\nConsider the range of values of x and y to be the points inside and on\na rectangle in a Cartesian diagram; divide it into nv rectangles b -\nlines parallel to the axes.\n\nLet Z7 i,, L,n, be the upper and lower bounds of f x, y) in one of\nthe smaller rectangles whose area is, say, Ayn,,j.', and let\n\n71 V n V\n\n- w - m,n -\"-m,!!- n,v y -i - j,n - m,/u h, I'- j/t = 1 jj. = 1 ) = 1\n;u. = 1\n\nThen *S', >?, \\,, and, as in \\hardsubsectionref{4}{1}{1}, we can find numbers h,.-, s,,,\nwhich are the lower and upper bounds of Sn,v, V\" respectively, the\nvalues of Sn,v, Sn,v depending only on the number of the rectangles\nand not on their shapes; and n, s, . We then find the lower and upper\nbounds S and s) respectively of,, Sn,v qua functions of n and v;\nand S v S s s,, as in §411.\n\nAlso, from the uniformity of the continuity of f(x, y), given e, we\ncan find B such that\n\n'J m,iJ. - Hij/i '\" f>\n\n(for all values of m and /i) whenever the sides of all the small\nrectangles are less than the number h which depends only on the form\nof the function f x, y) and on e.\n\nAnd then >S', - Sa, < e (6 - a) (/3 - a),\n\nand so S - s < e h - a) (/3 - a).\n\nBut S and s are independent of e, and so S = s.\n\nThe common value of S and s is called the double integral of f x, y)\nand is written\n\nf(x, y) (dxdy).\n\nIt is easy to shew that the reijeated integrals and the double\nintegral are all equal when f :c, y) is a continuous function of both\nvariables.\n\n%\n% 69\n%\n\nFor let Y j, A, be the uppei- and lower bounds of\n\nas .V varies between x -i and a:, .\n\nThen 2 Y, (x, - x, -i) > \\ f x,y)dy\\ dx A, (a;,,, - x,,,\\ .\n\n\"1 = 1 <' \\ 3 a. ) i = l\n\nBut* 2 Ura,,.i y.-y,.-i) \\,n .\\ n 2 Z,,m (y/x - m-i)-\n\nM = l /n = l\n\nMultiplying these last inequalities by x -Xm x, using the preceding\ninequalities and summing, we get\n\n2 2 r .M,. / ]/ f x,y)dy\\ dx 2 2 L,, A,;\n\n ( = 1 pi = l J a \\ J a. ) m = l /x = l\n\nand so, proceeding to the limit,\n\n'S' £ [jy x,y)dy dx s.\n\nBut ' =s=l lfix,y) dxdy),\n\nand so one of the repeated integrals is equal to the double integral.\nSimilarly the other repeated integral is equal to the double integral.\n\nCorollary. If/(.v, y) be a continuous function of both variables,\n\n\\Section{4}{4}{Infinite integrals.}\n\nIf lini 1 /(.r)c?j;j exists, we denote it by f x)dx; and the limit in\nquestion is called an infinite integral;. Examples.\n\n,. r d'x,. (I \\ \\ 1\n\n  j ( ' + a')' \" b V 2 (62 + a') + 2a2y' 2a '\n\n(3) By integrating by parts, shew that / t\"e~ dt = n. \\addexamplecitation{Euler.}\n\nJ\n\nSimilarly we define / f(x)dx to mean lim / f(x)dx, if this limit\nexists; and\n\nJ -X a- - -o J a\n\n/f x)dx is defined as / f(x)dx+l f .v)dx. In this last definition the\nchoice -00 J -<x>' J a\n\nof a is a matter of indifference.\n\n* The upper bound of f x, y) in the rectangle --i,, is not less than\nthe upper bound of /(.r, y) on that portion of the line .r = | which\nlies in the rectangle.\n\nt This phrase, due to Hardy, Proc. London Math. Soc. xxxiv. (1902), p.\n16, suggests the analogy between an infinite integral and an infinite\nseries.\n\n%\n% 70\n%\n\n\\Subsection{4}{4}{1}{Infinite integrals of continuous functions. Conditions for convergence.}\n\nA necessary and sufficient condition for the convergence of f x)dx is\n\nJ a\n\nthat, corresponding to any positive number e, a positive number X\nshould exist such that f(x) dec \\ < e whenever\n\nThe condition is obviously necessary; to prove that it is sufficient,\nsuppose\n\nra+n\n\nit is satisfied; then, ii n X -a and n be a positive integer and Sn =\nf(so),\n\n. a\n\nwe have j Sn+p - Sn\\ < €.\n\nHence, by \\hardsubsectionref{2}{2}{2}, Sn tends to a limit, S; and then, if > a + n,\n\nS-i f x)da;\\ \\ S-\\'' ''f(a;)dx + t f(x)da;\\\n\nJ a ' -a \\ J a+n I\n\n<26;\n\nand so lim f(x) dx = S; so that the condition is sufficient.\n\n\\Subsection{4}{4}{2}{Uniformity of convergence of an infinite integral.}\n\nThe integral f x, a) dx is said to converge uniformly with regard to a\n\nJ a\n\nin a given domain of values of a if, corresponding to an arbitrary\npositive number e, there exists a number X independent of a such that\n\nJ /( > a)dx\\ \\ <€\n\nfor all values of a in the domain and all values of x X.\n\nThe reader will see without difficulty on comparing §§ 2'22 and 3'31\nwith \\hardsubsectionref{4}{4}{1} that a necessary and sufficient condition that f x, a) dx\nshould\n\n.' a\n\nconverge uniformly in a given domain is that, corresponding to any\npositive number e, there exists a number X independent of a such that\n\nI f(x, a)dx \\ < e\n\n\\ J x' I\n\nfor all values of a in the domain whenever x\" x X.\n\n\\Subsection{4}{4}{3}{Tests for the convergence of an infinite integral.}\n\nThere are conditions for the convergence of an infinite integral\nanalogous to those given in Chapter II for the convergence of an\ninfinite series.\n\nThe following tests are of special importance.\n\n%\n% 71\n%\n\n(I) Absolutely convergent integrals. It may be shewn that f x)dx\n\nJ a\n\ncertainly converges if \\ f(a;) | dx does so; and the former integral\nis then said to be absolutely convergent. The proof is similar to that\nof \\hardsubsectionref{2}{3}{2}.\n\nExample. The comparison test. If \\ f(x) g x) and / g x) dx converges,\nthen / f(x) dx converges absolutely.\n\n[Note. It was observed by Dirichlet* that it is not necessary for the\nconvergence of I f x)dx that f x)-a'0 as x- cc : the reader may see\nthis by considering the function\n\n/( ) = ( n x n + l- n + l)-' ),\n\nf(x) = n + iyin + l-x) x- n+l) + n+l)- n + l -(n + l)- x n + l),\n\nwhere n takes all integral values.\n\nFor / f(x)dx increa.'ses with and / f x)dx=l n+l)-; whence it follows\n\nwithout difficulty that / f x)dx converges. But when a- = n + l -i\n(?n-l)-2, y'(.t>) =; and so f(x) does not tend to zero.]\n\n(II) The Maclaurin-Cauchyf test. Tf/(A-)>0 and/(x')-*0 steadily,\n\nTODO\n\nf x) dx and S /( ) converge or diverge together. 1 M = l\n\nfm + l\n\nFor A -- /( 0 > fix) dx f m + 1 ),\n\nJ m n fn+] n+1\n\nand SO 2 f(m) l f x)dx' 2 /(m).\n\n  m = l J 1 wi=2\n\nThe first inequality shews that, if the series converges, the\nincreasing sequence / f x)dx converges \\hardsectionref{2}{2}) when - -oo through\nintegral values, and hence it follows\n\nfx'\n\nwithout difficulty that / f(.v)dx converges when .r'-*-x; also if the\nintegral diverges, so does the series.\n\nThe second shews that if the series diverges so does the integral, and\nif the integral converges so does the series \\hardsectionref{2}{2}).\n\n(III) Bertrand'sX test. 1 f(x) = 0 x ~' ), f x)dx converges when X <;\nand \\ if x) - x~' loga; \" ), | f(x) dx converges when X, < 0.\n\n. a\n\nThese results are particular cases of the comparison test given in\n(I).\n\n* Dirichlet's example was/(.r) = sin .r'-; Journal fiir Math. xvii.\n(1837), p. 60. t Maclaurin Flit.vions, i. pp. 289, 290) makes a verbal\nstatement practically equivalent to this result. Cauchy's result is\ngiven in his Oeuvrcs (2), vii. p. 269. X Journal de Math. vii. (1842),\npp. 38, 39.\n\n%\n% 72\n%\n\n(IV) Chartiers test for integrals involving periodic functions. If /(\n) - steadily as x and if < x) dx is bounded as x <x>,\n\n1 ' a\n\nthen f(x) (x) dx is convergent.\n\nJ a\n\nFor if the upper bound of I (.r) dx \\ he A, we can choose X such that\nf x)<e/2A\n\n\\ J a\n\nwhen .X > A'; and then by the second mean vahie theorem, when .v\" .v'\nA', we have I /\" \" f(x) 6 (x) dx =\\ f x') f(x) dx =f x') \\ (f) x)dx-\ncf) x) dx 2Af x') < f,\n\nI \\ / a;'  I J x' \\ J a J a\n\nwhich is the condition for convergence.\n\nI ** Sill\n\nExample I. I dt' converges.\n\nJ *'\n\nExample 2. I a; - 1 sin x - ax) dx converges.\n\n\\Subsubsection{4}{4}{3}{1}{Tests for uniformity of convergence of an infinite integral f.}\n\n(I) De la Vallee Poussins test . The reader will easily see by using\n\n(\"00\n\nthe reasoning of \\hardsubsectionref{3}{3}{4} that f x, a) dx converges uniformly with\nregard\n\nto a in a domain of values of a if \\ f x, a) | < fi x), where fM x) is\nindependent\n\nfee r \"\n\nof a and /jl (x) dx converges. [For, choosing X so that fx(x)dx<e\n\nrx\" when x' x' X, we have f x, a)dx < e, and the choice of X is inde-\n\nJ x'\n\npendent of a.]\n\n/oo\n\nExample. \\ x' ~' e~''dx converges uniformly in any interval A, B) such\nthat\n\n(II) The method of change of variable. This may be ilkist rated by an\nexample.\n\nConsider / '- dx where a is real.\n\ny \" sin ax, /\" \" sin y,\n\nWe have / - 7- ' =, ~ 7~\n\n] 3c' X J ax' y\n\n   dy converges we can find Y such that / - - dy <e when y\" y' Y.\n\ny J y y\n\ndx\n\n< 6 whenever | a ' | F; if | a | S > 0, we therefore get\n\nI /\"*\" sin ax, \\ I dx \\ < f\n\nI y a;' -' I\n\n* Journal de Math, xviii. (1853), pp. 201-212. It is remarkable that\nthis test for conditionally convergent integrals should have been\ngiven some years before formal definitions of absolutely convergent\nintegrals.\n\nt The results of this section and of \\hardsubsectionref{4}{4}{4} are due to de la Valine\nPoussin, Ann. de la Soc. Scientifique de Bruxelles, xvi. (1892), pp.\n150-180.\n\nX This name is due to Osgood.\n\n%\n% 73\n%\n\nwhen .'. \" .// X= Y/8; and this choice of X is independent of a. So\nthe convergence is uniform when a S > and 'when a - 8 < 0.\n\nExample. I j/ sm \\& a:: )d > dx is uniformly convergent in any range\nof real values of a. (de la Vallee Poussin.)\n\n2- i sin zdz does not exceed a constant inde-\n\n!\n\nl endent uf a and .v since / z-i sin z dz converges.] J\n\n(III) T/ie method of integration by parts.\n\nIf / / (x, a) dx <p x, a)+ X (* > ) d-''\n\nand if ( f.r, a)-*-0 uniformly as x -X3 and /;( (.r, a)o?jp converges\nuniformly with regard\n\nJ <t\n\nto a, then obviously / f x, a) dx converges uniformly with regard to\na.\n\n(IV) The method of decomposition.\n\nExample. |J c\\ os.r sin a |J sin (a +l) . |J sin (o - l)a. .\n\nloth of the latter integrals converge uniformly in any closed domain\nof real values of a from which the points a= ± 1 are excluded.\n\n\\Subsection{4}{4}{4}{Theorems concerning uniformly convergent infinite integrals.}\n(I)\nLet f x, a) dx converge uniformly luhen a lies in a domain S.\n\n. a\n\n'Then, if f x, a) is a continuous function of both variables ivJien x\na and a lies in S, f x, a)dx is a continuous function* of a.\n\nJ a\n\nI r*\n\nFor, given e, we can find X independent of a, such that ' I f(x, a)dx\n<e whenever X.\n\nAlso we can find 8 independent of x and a, such that \\ f x,a)-f(x,a')\\\n< el X-a) whenever a - a.' < B.\n\nThat is to say, given e, we can find 8 independent of a, such that\n\nf x,a.')dx-\\ f x,a)dx \\$ f x,a)-f x,a')]dx\\\n\n. a J a \\ J a 1\n\n+ I f x, a') dx +\\ I fix, a) dx\n\n\\ Jx \\ Jx\n\n<3e,\n\nwhenever | a' - a | < S; and this is the condition for continuity.\n\n* This result is due to Stokee. His statement is that the integral is\na continuous function of a if it does not ' converge infinitely\nslowly.'\n\n5\n\n%\n% 74\n%\n\n(II) If f x, a) satisfies the same conditions as in (I), and if a.\nlies in S when A <a<B, then\n\nI \\ f x, (x)dx\\ doi= \\ fix, a)da[dx.\n\nFor, by \\hardsectionref{4}{3},\n\nTherefore\n\nIf\n\nA [J a £ A\n\nf x, a) dx r da= \\ \\ \\ f(x, a) day dx. \\ I f x, a) dx[ da- I \\ i f x,\na) da)- dx\n\n< f eda<e B-A),\n\nJ A\n\nfor all sufficiently large values of .\n\nBut, from §§ 2'1 and 4\"41, this is the condition that\n\nlim I \\ i fix, a)da\\ dx\n\nshould exist, and be equal to\n\nf x, a) dx\\ da. Corollary. The equation -r- \\ rb .v, a)dx=l ~ dx is\ntrue if the integral on the\n\nda J a . J a va\n\nright converges uniformly and the integrand is a continuous function\nof both variables, when x' a and a lies in a domain >S', and if the\nintegral on the left is convergent.\n\nLet A be a point of S, and let S=f x, a), so that, by \\hardsubsectionref{4}{1}{3} example\n3,\n\nva\n\n/ f x, a) da = (.r, a) - x, A).\n\nThen / J / /(.r, a) day dx converges, that is / 4> x, a)-( ) x, A) dx\nconverges,\n\nand therefore, since / cf) x, a)dx converges, so does i x, A) dx. J a\nJ a\n\nI (f) x, a) dx \\=j- / 0 (*-', n) - (- j -'1 )\n\nThen\n\nda\n\nd da\n\n/ \\ j f x,a)daydx\\\n\n= T I \\ l f(x.a)dx\\ da daj A [J a- ' ' J\n\n= fjix,a)dx=fy dx, which is the required result; the change of the\norder of the integrations has been justified above, and the\ndifferentiation of / with regard to a is justified by \\hardsubsectionref{4}{4}{4} (I) and §\n4-13 example 3.\n\n%\n% 75\n%\n\n\\Section{4}{5}{Imjiroper integrals. Principal values.}\n\nIf I /(x) - >cc as X - a + 0, then lim f(x) dx may exist, abd is\n\ni- + O J a+\\&\n\nwritten simply I f(x) dx; this limit is called an improper integral.\n\nJ a\n\nIf \\ f(x) I - 00 as a; - > c, where a< c <b, then\n\n/e-5 rb\n\nlim I /( ) c?j: + lim I /(- O c?\n\nS +O J a S' +oJ C+\\&'\n\nmay exist; this is also written I f(x)dx, and is also called an\nimproper\n\nJ a\n\nintegral; it might however happen that neither of these limits exists\nwhen 8, S' - > independently, but\n\nlim ]/ f x)dx+i f(x)dxy exists; this is called 'Cauchy's principal\nvalue of I f x)dx' and is written\n\nJ a\n\nfor brevity P I f(x) dx.\n\nJ a\n\nResults similar to those of §§ 4-4-4-44 may be obtained for improper\nintegrals. But all that is required in practice is (i) the idea of\nabsolute convergence, (ii) the analogue of Bertrand's test for\nconvergence, (iii) the analogue of de la Vallee Poussin's test for\nuniformity of convergence. The construction of these is left to the\nreader, as is also the consideration of integrals in which the\nintegrand has an infinite limit at more than one point of the range of\nintegration*.\n\nExamples. (1) / x - cos .v <ilr is an improper integral. J\n\n- b\n\n(2) r ./\" (1 -.rf \" dx is an improper integral if <X < 1, </i< 1. It\ndoes not converge for negative values of X and /x.\n\ndx is the principal value of an improper mtegral when\n\n1 -A'\n\n0<a<l. . 4-51. The inversion of the order of integration of a certain\nrepeated integral. ?r General conditions for the legitimacy of\ninverting the order of integration when the\n\nintegrand is not continuous are difficult to obtain.\n\nThe following is a good example of the difficulties to be overcome in\ninverting the order of integration in a repeated improper integral.\n\n* For a detailed discussion of improper integrals, the reader is\nreferred either to Hobson's or to Pierpont's Functions of a Real\nVariable. The connexion between infinite integrals and improper\nintegrals is exhibited by Bromwich, Infinite Series, § 164.\n\n%\n% 76\n%\n\nLet f x,y) he a continuous function of both variables, and let 0<X 1,\n0</x l, < v < 1; then\n\nThis integral, which was first employed by Dirichlet, is of\nimportance in the theory of integral equations; the investigation\nwhich we shall give is due to W. A. Hurwitz*.\n\nLet x''~ i/' ~ (1 -x-yy~' f x,y) = (li x,y); and let M be the upper\nbound of \\ f x,y) |. Let S be any positive number less than .\n\nDraw the triangle whose sides ave x = b, y = b, x+y = l-b\\ at all\npoints on and inside this triangle ( x, y) is continuous, and hence,\nby \\hardsectionref{4}{3} corollary,\n\nNow r~''dx 11 \"'' ct> X, y) dy =l'~' dx |P\"' < (, V) l + f]\"' hdx+j'\n'* Ldx,\n\nwhere /i = / </> x, y) dy, L= (f> x, y) dy.\n\nJo J i-a;-6\n\nBut I /i I < r i/.r - y - 1 (1 - .r - y)\" - 1 o y\n\nsince (l- -?/r-i<(l- '-S)''- .\n\nTherefore, writing x = i\\ -S)a'i, we havet\n\nT\"\" /i dr I J/S',x- 1 p~ ./ - 1 ( 1 - .  - S)\" - 1 c\n\n  \\& I Jo\n\n i/r -1 (1 - bt '- C x, - (1 -A-i)\"\"' dx\n\nThe reader will prove similarly that Ly- 0 as 8- 0.\n\nHence I / o?a' i / 4) x,y)dy\\= hm / t/ j / 4> x,y)dy\\\n\n= lim /\n\n1-25 C fl-x-S\n\ndx J: i ( ) x, y) dy\n\n= lim\n\n5H..0\n\nfl-2S ( fi-y-S ]\n\n* Annals of Mathematics, ix. (1908), p. 183.\n\nt I a.-i ~ (l-.ri)''- dxi = £(A, ) exists if 0, j'>0 \\hardsectionref{4}{5}example2).\n\nt The repeated integral exists, and is, in fact, absolutely\nconvergent; for\n\n/\"i ri\n\nwriting 2/ = (1- a.-) s; and/ il/ - (1 - .r)' + ''-i cZx . I ' s' -1\n(1 -s)''\" £?s exists. And since the\n\n \" fl-e - ' fl-ZS\n\nintegral exists, its value which is lim I may be written lim I\n\n5, e O J S S O J S\n\n%\n% 77\n%\n\nby what has beeu already proved; but, by a precisely similar jjiece\nof work, the last integral is\n\nWe have consequently proved the theorem in question.\n\nCorollary. Writing = a + h-a) x, rj = h - b-a)y, we see that, if 4>\ni\\$j ) i con- tinuous,\n\n//I f (|-; ~' ib-vf' iv-\\$r'' a, V) dv\n\n-J/V fli -af-Hb-rir-Hn- )\"-' c >, rj)d Y\n\nThis is called Dirichlet's formula.\n\n[Note. What are now called infinite and improper integrals Avere\ndefined by Cauchy, Leco?iS sur le calc. inf. 1823, though the idea of\ninfinite integrals seems to date from Maclaurin (1742). The test for\nconvergence was employed by Chartier (1853). Stokes (1847)\ndistinguished between 'essentially' (absolutely) and non-essentially\nconvergent integrals though he did not give a formal definition. Such\na definition was given by Dirichlet in 1854 and 1858 (see his\nI'orlesiingen, 1904, p. 39). In the early part of the nineteenth\ncentury improper integrals received more attention than infinite\nintegrals, probably because it was not fully realised that an infinite\nintegral is really the Iwiit of an integi'al.]\n\n\\Section{4}{6}{Complex inteyration*TODO.}\n\nIntegration with regard to a real variable x may be regarded as\nintegration along a particular path (namely part of the real axis) in\nthe Argand diagram. \\ \\ Qtf z), (= 7 -f iQ), be a function of a\ncomplex variable z, which is continuous along a simple curve i in the\nArgand diagram.\n\nLet the equations of the curve be\n\nx = x (t), tj = y it) (a t b).\n\nLet X (a) + iy a) = Zq, x (b) + iy (b) = Z.\n\nThen if-f x(t), y(t) have continuous difierential coefficients J Ave\ndefine z f z)dz taken along the simple curve AB to mean\n\n/\n\ndx . dy Mt dt\n\n F + iQ)( + i' ]dt.\n\nThe 'length' of the curve AB will be defined as I \\/ (--f) +( ) '\n\nIt obviously exists if -7-, -~ are continuous; we have thus reduced\nthe  dt dt\n\ndiscussion of a complex integral to the discussion of four real\nintegrals, viz.\n\n! \\ A-' />!- />\n\ndt\n\n* A treatment of complex integration based on a different set of ideas\nand not making so many assumptions concerning the curve AB will be\nfound in Watson's Complex Integration and Cauchy's Theorem.\n\nf This assumption will be made throughout the subsequent work.\n\nX Cp.\\hardsubsectionref{4}{1}{3} example 4.\n\n%\n% 78\n%\n\nBy \\hardsubsectionref{4}{1}{3} example 4, this definition is consistent with the definition\nof an integral when AB happens to be part of the real axis.\n\nExamples, l f(z) dz= - l \" f(z) dz, the paths of integration being the\nsame (but in opposite directions) in each integral.\n\n/:- /.w:f-s-4f--(4'-4) *\\\n\n\\Subsection{4}{6}{1}{The fundamental theorem of complex integration.}\n\nFrom \\hardsubsectionref{4}{1}{3}, the reader will easily deduce the following theorem :\n\nLet a sequence of points be taken on a simple curve z Z; and let the\nfirst n of them, rearranged in order of magnitude of their parameters,\nbe called i<\">, gC\", . . . z <\"' (iTo\"*' = z +i'\"' = Z); let their\nparameters be j\"*', J\"', . . . <'\", and let the sequence be such that,\ngiven any number h, we can find N such that, when n > N, +i<\"' - <\"' <\nB, for r = 0, 1, 2, ...,n; let,.\"\" be any point whose parameter lies\nbetween < < '', r+i*\"'; then we can make\n\nI (,+i'\") - Zr fiC/- ) - I \\ f(z) dz\n\narbitrarily small by taking n sufficiently large.\n\n\\Subsection{4}{6}{2}{An upper limit to the value of a complex integral.}\n\nLet M be the upper bound of the continuous function \\ f(z) .\n\nThen jJVw,.j £:/(.)sj(| + 4y)],,\n\n Ml, where I is the ' length ' of the curve z yZ.\n\nThat is to say, I f(z) dz cannot exceed Ml.\n\n\\Section{4}{7}{Integration of infinite series.}\n\nWe shall now shew that if S z) = u z) + ii. z)- ... is a uniformly\ncon- vergent series of continuous functions of z, for values of z\ncontained within some region, then the series\n\nI III z) dz + I lu z) dz + ..., J c J c\n\n(where all the integrals are taken along some path C in the region) is\ncon- vergent, and has for sum I S (z) dz.\n\nJ c\n\n%\n% 79\n%\n\nFor, writing\n\n>Sf Z) = Ml Z) + 2 ( ) +    + Ihi Z) + Rn Z),\n\nwe have\n\nI S z) dz =1 u z)dz + ... -\\ Un (z) dz + I R,, (z) dz.\n\nJ c J c J c J c\n\nNow since the series is uniformly convergent, to every positive number\ne there corresponds a number r independent of z, such that when n r we\nhave I Rn (z) I < f> for all values of z in the region considered.\n\nTherefore if I be the length of the path of integration, we have (§\n4'62)\n\nf Rn z) J C\n\n<el\n\ndz\n\nTherefore the modulus of the difference between / S z) dz and\n\nJ c n r\n\nS I Um (z) dz can be made less than any positive number, by giving n\nany\n\nm = lJ c\n\nsufficiently large value. This proves both that the series 2 Um z)dz\nis\n\nOT = 1 J c\n\nconvergent, and that its sum is / S(z)dz.\n\nJ c\n\nCorollary. As in \\hardsubsectionref{4}{4}{4} corollary, it may be shewn that*\n\n0? \",, \" d, .\n\nif the series on the right converges uniformly and the series on the\nleft is convergent.\n\nExample 1. Consider the series\n\n\" 'ix n n +1) 11x x -1 cos x\" ?i 1+ 2 sin2 x ] 1 + n + 1)2 sin- .r '\nin which x is real.\n\nThe Jith term is\n\n2.rw cos x 2x (n + 1) cos x\n\n1 + 71 sin\"- X- 1 + (n + 1 )2 sin- x ' and the sum of n terms is\ntherefore\n\n2x cos x' 2x(n + l) cos x\n\n1+Sin2 2~ l + (7i+l)2sin2a;2*\n\nHence the series is absolutely convergent for all real values of x\nexcept ± /(mrr) where ?>i = 1, 2, . . .; but\n\nr> .,\\ 2x(n+l)cosx -'\"''-l+(K + l)2sin2, :2'\n\nand if n be any integer, by taking x = n + l)~' this has the limit 2\nas n <X) . The series is therefore non-uniformly convergent near x=0.\n\n* - - ' means lira \" where h- 0 along a definite simple curve; this\ndefinition\n\nis modified slightly in \\hardsubsectionref{5}{1}{2} in the case when/(z) is an analytic\nfunction.\n\n%\n% 80\n%\n\nNow the sum to infinity of the series is - - -, and so the integral\nfrom to,r of ' 1 + sm-' x\n\nthe sum of the series is arc tan sin r . On the other hand, the sum of\nthe integrals from\n\nto .V of the first n terms of the series is\n\narc tan sin .r - arc tan ( + !) sin x',\n\nand as /i- X this tends to arc tan sin x-] - hir.\n\nTherefore the integral of the sum of the series difiers from the sum\nof the integi-als of the terms by tt.\n\nExample 2. Discuss, in a similar manner, the series\n\n== 2e .p l- (e-l) + e\" + U'2\n\nfor real values of x.\n\nExample 3. Discuss the series\n\n7(1 + 11-2 + U3+...,\n\nwhere\n\nUi = ze-'\\ Un=nze-'\"' - ( - 1) se-l\"-!), for real values of z.\n\nThe sum of the first n terms is ?i2e~\" \", so the sum to infinity is\nfor all real values of z. Since the terms Un are real and ultimately\nall of the same sign, the convergence is absolute.\n\nIn the series\n\n/ Uidz+ I ti.2dz+ I v.3dz + ...,\n\nthe sum of Ji. terms is -g (1 - e\"\" ), and this tends to the limit |\nas n tends to infinity; this is not equal to the integral from to 2\nof the sum of the series 2?<n-\n\nThe explanation of this discrejjancy is to be found in the\nnon-uniformity of the convergence near 2 = 0, for the remainder after\nn terms in the series Ui + 112 + ...is - -aze~ \"; and by taking z =\n7i~' we can make this equal to e' '\"-, which is not arbitrarily small;\nthe series is therefore non-uniformly convergent near z = 0.\n\nExample 4. Compare the values of\n\n/\\ 2 tin[ dz and 2 / Undz, U=l J n=lj\n\nwhere\n\n2n z 2 n- l) z\n\n\"l+n'z )\\ og n + l) l + n + -iyh'- log n + 2)'\n\n\\addexamplecitation{Trinity, 1903.}\n\nREFERENCES.\n\nG. F. B. Riemann, Ges. Math. Werke, pp. 239-241.\n\nP. G. Lejeuxe-Dirichlet, Yorlesungen. (Brunswick, 1904.)\n\nF. G. Meyer, Bestimmte Integrale. (Leipzig, 1871.)\n\nE. GoDRSAT, Cours d Analyse (Paris, 1910, 1911), Chs. iv, xiv.\n\nC. J. DE LA Vall e Poussix, Cours d' Analyse In fiyiite'stmale (Payis\nand Louvaiu, 1914),\n\nCh. VI. E. W. HoBSON, Functions of a Real Variable (1907), Ch. v. T.\nJ. I'a. Bromwich, Theory of Infinite Series (1908), Appendix ill.\n\n%\n% 81\n%\n\nMiscellaneous Examples.\n\n1. Shew that the integrals\n\nI sin x )dx, I cos (.r-) dx, I x exp ( - x sin- x) dx Jo Jo Jo\n\nconverge. \\addexamplecitation{Dirichlet and Du Bois Eeymoud.}\n\n2. If a be real, the integral\n\nf °° cos (ax),\n\nJo 1+ is a continuous function of a. \\addexamplecitation{Stokes.}\n\n3. Discuss the uniformity of the convergence of j x sin x - ax) dx.\n\nJo\n\n3 /.rsin x -ax)dx= -f - -l-ir-j) cos (x- -ax)\n\n/\"/I a\\,,,, 1 fsin(x -ax), ~\\\n\n- JU + : j \" ' -\" ) ' '+3°\"j - x - \"\"-J\n\n(de la Vallee Poussin.)\n\n4. Shew that / ex ) [-e'< x -nx)]dx converges unifonuly in the range -\nhr, hir) of values of a. \\addexamplecitation{Stokes.}\n\nr \" x' dx\n\n5. Discu.ss the convergence of I, - . when u, p, p are positive.\n\n* Jo l+JT\" |smjp|P - )/- r\n\n(Hardy, Messenger, xxxi. (1902), p. 177.)\n\n6. Examine the convergence of the integrals\n\nJo V 2 l-e'J .r ' jo X\"\n\n\\addexamplecitation{Math. Trip. 1914.}\n\n7. Shew that / - exists.\n\nJ \" x' (sin x)\n\n8. Shew that I .r -\"e\"\" ' sin 2.rc/.r converges if a >0, a >0. (Math.\nTrip. 1908.)\n\nJ a\n\n9. If a series (7(2)= 2 (c - (? + i)sin (2i/+l) Tri:, (in which C(, =\n0), converges uniformly\n\nv=0\n\nTT . . . . C\n\nin an interval, shew that g z) -. is the derivative of the series/\n(2)= 2 - sin 2vTrz.\n\nsm irZ v=i V\n\n(Lerch, Ann. de VEc. norm. sup. (3) xii. (1895), p. 351.)\n\n10. Shew that r r... r |L i tff2- n d r r r dx,dx,...dx\n\nconverge when a>hi' and a~i + /3~i + ...+X~' < 1 respectively. (Math.\nTrip. 1904.)\n\n11. Iff x, ) be a continuous function of both.r andy in the ranges (a\nx b), (a ?/ 6) except that it has ordinary discontinuities at points\non a finite number of curves, with continuously turning tangents, each\nof which meets any line parallel to the coordinate axes\n\nfb\n\nonly a finite number of times, then I f x, y) dx is a continuous\nfunction of y.\n\n/a, - Sj Ca.2-\\&2 [b\n\n+ 1 +...+ I fC 'j y + h)-f(x, y)]dx, where the numbers\n\nSj, \\hardsectionref{2}{5}  fi, f2?  are so chosen as to exclude the\ndiscontinuities ot f x, y + h) from the range of integration; Oj, 02,\n... being the discontinuities off x, y).] \\addexamplecitation{Bocher.}\n\nW. M. A. 6\n", "meta": {"hexsha": "faa10161a14d9a15e843da8b968dd277a0004006", "size": 40585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch04.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-ch04.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-ch04.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.4770872567, "max_line_length": 93, "alphanum_fraction": 0.6562276703, "num_tokens": 13688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6528737353465723}}
{"text": "% Chapter 4\n\\chapter{Results of Calibration and \\gls{3D} Reconstruction} % Main chapter title\n\\label{chapterCaliResultsReconstruction} % For referencing the chapter elsewhere, use \\ref{sens_CalibrationSystem} \nAs discussed in section~\\ref{perpixelDataCollection}, the per-pixel calibration method is supposed to handle both of radial dominated lens distortions and depth distortion. A two-dimensional high-order polynomial model would be employed to remove lens distortions and generate estimated (\\(\\gls{worldX},\\, \\gls{worldY}\\))s from image space (\\(R, \\, C\\))s. And the depth distortion would be removed during the per-pixel \\(D\\) to \\(\\gls{worldZ}\\) mapping during 3D reconstruction. In this chapter, we will show how well the lens distortions and depth distortion are removed by compare both of intuitive image data and quantitative numerical data, before and after calibration, in both of Matlab prototypes and real-time 3D reconstructions. \n%%\n\\section{Calibration and Analysis}\n\\label{sectionPrototypeTwoDtransformation} \n%\n\\indent\nFigure~\\ref{MatlabPrototpyeOfHighOrder} shows the Matlab prototypes of the simulated original image, world space \\(X^WY^W\\) plane result after a two-dimensional \\(1^{st}\\) order polynomial transformation, \\(2^{nd}\\) order polynomial and \\(4^{th}\\) order polynomial transformation. With squared-shaped distributed points (\\(C,\\, R\\))s extracted from image streams, fig.~\\subref*{Original_MatlabPrototype} recovers the original distorted image in Matlab. Using a mathematical distortion (\\(d\\)) measurement \\cite{distortionMeasurement_2012}\n%\n\\begin{equation}\nd (\\%)=  e*100/L ,\n\\label{mathematicalDistortion}\n\\end{equation}%\n%\n\\noindent\nwe can get the original distortion \\(d_0 = (R3 - R1) / (C2 -C1) = (403 - 393) / (492 - 20) = 2.1\\%\\). Figure~\\ref{First_MatlabPrototype} shows estimated world space \\(X^WY^W\\) plane after a two-dimensional \\(1^{st}\\) order polynomial transformation, whose distortion \\(d_1 = (Y1 - Y3) / (X2 -X1) = [-3.772 - (-4.004)] / [5.713 - (-4.735)] = 2.2\\%\\). As we may have expected, the distortion \\(d_1\\) is not getting smaller at all. %\n\\\\\\indent\nFigure~\\ref{Second_MatlabPrototype} and Fig.~\\ref{Fourth_MatlabPrototype} show the transformed world space \\(X^WY^W\\) plane images after the \\(2^{nd}\\) order and \\(4^{th}\\) order polynomial transformation respectively, from which we can get \\(d_2 = [-3.807 - (-4.035)] / [5.779 - (-4.8)] = 2.1\\%\\) and \\(d_4 = [-3.936 - (-3.992)] / [5.923 - (-4.928)] = 0.516\\%\\). %\n%\n\\begin{figure}[!t]\n\\hspace*{-0.3cm}\n\\centering\n\\subfloat[Image Space][Image Space]{\n\\includegraphics[width=0.5\\textwidth]{Original_MatlabPrototype}\n\\label{Original_MatlabPrototype}}\n%\\qquad\n\\subfloat[\\(1^{st}\\) Order][\\(1^{st}\\) Order]{\n\\includegraphics[width = 0.5\\textwidth]{First_MatlabPrototype}\n\\label{First_MatlabPrototype}}\n\n\\subfloat[\\(2^{nd}\\) Order][\\(2^{nd}\\) Order]{\n\\includegraphics[width=0.5\\textwidth]{Second_MatlabPrototype}\n\\label{Second_MatlabPrototype}}\n%\\qquad\n\\subfloat[\\(4^{th}\\) Order][\\(4^{th}\\) Order]{\n\\includegraphics[width = 0.5\\textwidth]{Fourth_MatlabPrototype}\n\\label{Fourth_MatlabPrototype}}\n%\n\\caption{\\(\\gls{worldX}\\)\\(\\gls{worldY}\\) Matlab Polynomial Prototype}\n\\label{MatlabPrototpyeOfHighOrder}\n\\end{figure}%\n%\n%\nIt is straightforward to tell that, \\(d_4\\) is much smaller than \\(d_0\\) and Fig.~\\ref{Fourth_MatlabPrototype} intuitively shows a satisfying undistorted image. From eqn.~(\\ref{secondOrderPolynomial}) and eqn.~(\\ref{fourthOrderPolynomial}), we know that the second order polynomial mapping has $2\\times6=12$ parameters, and the fourth order polynomial mapping has $2\\times15=30$ parameters. The higher order polynomial we use, the better radial distortion we are able to correct. In the meantime, the distortion removal model will have more parameters to calculate, and need more calibrating points to train the model.%\n%\n%%\n\\\\\\indent\n\\begin{figure}[!t]\n\\centering\n\\hspace*{-0.3cm}\n\\subfloat[Before transformation][Before transformation]{\n\\includegraphics[width=0.5\\textwidth, height = 0.425\\textwidth]{BeforeRectification_Single_NIR}\n\\label{BeforeRectification_Single_NIR}}\n%\n\\subfloat[Perspective Correction][Perspective (\\(1^{st}\\))]{\n\\includegraphics[width = 0.5\\textwidth, height = 0.425\\textwidth]{Perspective_QtScreenShot}\n\\label{Perspective_QtScreenShot}}\n%\n\\\\%\\qquad\n\\hspace*{-0.3cm}\n\\subfloat[\\(2^{nd}\\) Order][\\(2^{nd}\\) Order]{\n\\includegraphics[width = 0.5\\textwidth, height = 0.425\\textwidth]{Second_QtScreenShot}\n\\label{Second_QtScreenShot}}\n%\n\\subfloat[\\(4^{th}\\) Order][\\(4^{th}\\) Order]{\n\\includegraphics[width = 0.5\\textwidth, height = 0.425\\textwidth]{Fourth_QtScreenShot}\n\\label{Fourth_QtScreenShot}}\n%\n\\caption{\\gls{NIR} Stream High Order Polynomial Transformation}\n\\label{HighOrderNearIRRectification}\n\\end{figure}%\n%\nBy applying those two-dimensional polynomial models into real-time streams transformation, we can get the transformed stream images. As shown in Fig.~\\ref{HighOrderNearIRRectification}, the outlines of the transformed steam images are same with Matlab prototypes in Fig.~\\ref{MatlabPrototpyeOfHighOrder}. It is easy to tell that the \\(4^{th}\\) order polynomial surface mapping is much better than the second order, and a higher order than \\(4^{th}\\) should be more accurate. However, as the order of the polynomial mapping goes higher, the number of parameters also get larger and larger, which costs more calculations and requires more data (coordinate-pairs) for training the transformation model. Considering that a \\(5^{th}\\) order polynomial mapping will have much more  parameters ($2\\times21=42$) to calculate while may not enhance much accuracy, we choose the \\(4^{th}\\) order polynomial as the main mapping model to get \\(X^WY^W\\) values from \\(RC\\). Limited by the static dot pattern, fewer and fewer dot-clusters could be observed by the camera as the camera getting closer to the dot pattern. Practically, \\(4^{th}\\) order calibration is replaced by \\(2^{nd}\\) order to guarantee a robust software when the observed dot-clusters are too few to train the transformation model.\n\\\\\\indent\n%%\n%%\n%% %% mapping model parameters determination\n%\nThe two-dimensional high-order polynomial mapping model will be applied in the first calibration step of \\(\\gls{worldX} \\gls{worldY} \\gls{worldZ}+\\gls{D}\\) frames data collection. Figure~\\ref{Data63FranesForLUT} shows 63 frames of collected \\(\\gls{worldX} \\gls{worldY} \\gls{worldZ}\\), which gives an pyramid shape of a camera sensor's undistorted world space field of view. For each single pixel, its field of view is a beam, which could be mathematically expressed as equation~(\\ref{kaiBeamEquationCh3}). Some sample beams are shown in Fig.~\\ref{SampleBeams_NearIR}, whose beam equation parameters \\(c\\)/\\(d\\)/\\(e\\)/\\(f\\) are determined as the best-fit totally by the collected undistorted data. \n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.7\\textwidth, height= 0.55\\textwidth]{Data63FranesForLUT}\n\\caption{63 Frames \\gls{NIR} Calibrated \\gls{3D} Reconstruction}\n\\label{Data63FranesForLUT}\n\\end{figure}%\n%\n%\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{SampleBeams_NearIR}\n\\caption{Sample Beams of Calibrated \\gls{NIR} Field of View}\n\\label{SampleBeams_NearIR}\n\\end{figure}\n%\n%As discussed in section~\\ref{sectionDataProcessLUTgeneration}, the per-pixel \\(\\gls{D}\\) to \\(\\gls{worldZ}\\) mapping is linear. \nAs for the handling of depth distortion, a pre-process of depth stream is needed. Considering that there will be irregular noises (different with the regular depth distortion) in the depth stream, especially those brought in by the defects affected by huge transitions of color (or intensity), we will find a best-fit plane for each frame based on its \\(\\gls{worldX} \\gls{worldY} \\gls{D}\\) data and throw away 10\\% worst pixels that are far away from the best-fit plane. Figure~\\ref{depthDistortionComparisonBeforeAfterCalibration} shows 10 frames of flat-shading 3D reconstructions in Matlab for both of before and after calibration. In Fig.~\\subref*{cameraFramesInWorldSpace}, the 3D reconstructions are based on camera space coordinates \\(\\gls{cameraX} \\gls{cameraY} \\gls{cameraZ}\\) generated by eqn.~(\\ref{proportionalBeamEqn}) and (\\ref{parametersABofProportional}); which are then transformed into world space for a better comparison with the calibrated reconstruction, using best fit rotation and translation matrix based on corresponding \\(\\gls{worldX} \\gls{worldY} \\gls{worldZ}\\). In Fig.~\\subref*{worldFramesInWorldSpace}, the 3D reconstructions are based on world space coordinates generated by eqn.~(\\ref{kaiBeamEquationCh3}) and (\\ref{fromD_To_Z}). We can tell that the 10 frames in the LUT calibrated 3D reconstructions are a little bit thinner than that of raw Pin-Hole reconstructions, which means the per-pixel calibration method has positive effect on the removal of depth distortion. The depth distortion removal in real-time is shown in section~\\ref{sectionRealTimeReconstruction} Fig.~\\ref{depthDistortionCalibrationBeforeAfter}.\n\n\\begin{figure}[t]\n\\centering\n\\hspace*{-0.3cm}\n\\subfloat[Raw Pin-Hole Reconstructions in World Space         through best-fit rotation and translation]{\n\\includegraphics[width=0.5\\textwidth]{cameraFramesInWorldSpace}\n\\label{cameraFramesInWorldSpace}}\n%\n\\subfloat[Calibrated \\gls{LUT} based Reconstructions]{\n\\includegraphics[width = 0.5\\textwidth]{worldFramesInWorldSpace}\n\\label{worldFramesInWorldSpace}}\n%\n\\caption{Depth Distortion, before and after Calibration}\n\\label{depthDistortionComparisonBeforeAfterCalibration}\n\\end{figure}%\n%\n%\\clearpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Real-Time \\gls{3D} Reconstruction on \\gls{GPU}}\n\\label{sectionRealTimeReconstruction}\n%\nThe \\gls{3D} Reconstruction of undistorted \\(\\gls{worldX}/\\gls{worldY}/\\gls{worldZ}\\) in real-time is the final aim of a \\gls{3D} camera's calibration. In the traditional camera calibration method, which consist of one pinhole-camera matrix to generate raw world space \\gls{3D} coordinates and another model for lens distortion removal, three big transformations are needed to generate the world space coordinates: from 2D distorted image space to 2D undistorted image space, then to \\gls{3D} camera space, and finally to \\gls{3D} world space. For every single pixel's processing, it needs 5 parameters from distortion removal model for the first step non-linear calculation, and then a $3\\times3$ intrinsic matrix to get its camera space coordinates, and a $3\\times4$ extrinsic matrix to finally acquire the world space coordinates. The \\gls{3D} reconstruction after the traditional calibration requires a lot of calculations for every single pixel, and \\emph{depth distortion} is not corrected at all.\n\\\\\\indent\n%\nUsing the proposed per-pixel calibration method, only three linear calculations with six parameters are needed to determine the world space coordinates for every single pixel. Two parameters \\(e/f\\) are utilized to generate world space \\(\\gls{worldZ}\\), as expressed in eqn.~(\\ref{fromD_To_Z}). And the other four parameters \\(a/b/c/d\\) are applied to get \\(\\gls{worldX}/\\gls{worldY}\\) respectively based on eqn.~(\\ref{kaiBeamEquationCh3}). In this way, there is no need to calculate any non-linear equation for distortions removal, and the camera space is totally left aside. Combining two equations together, the undistorted \\gls{3D} world coordinates (\\(\\gls{worldX}, \\, \\gls{worldY}, \\, \\gls{worldZ}\\)) for every single pixel could be looked up based on \\(\\gls{D}\\) from a \\(\\gls{imageColumn}\\)-by-\\(\\gls{imageRow}\\)-by-\\(6\\) look-up table. Figure~\\ref{perPixelCalibrationBeforeAfter} shows how lens distortions are moved, and Fig.~\\ref{depthDistortionCalibrationBeforeAfter} shows how the \\emph{depth distortion} is removed by per-pixel \\(\\gls{D}\\) to \\(\\gls{worldZ}\\) mapping.\n\\begin{figure}[t]\n\\centering\n\\hspace*{-0.3cm}\n\\subfloat[Raw (Distorted)]{\n\\includegraphics[width=0.5\\textwidth, height = 0.425\\textwidth]{distortedRGB}\n\\label{distortedRGB}}\n%\n\\subfloat[Calibrated]{\n\\includegraphics[width = 0.5\\textwidth, height = 0.425\\textwidth]{CalibratedRGB}\n\\label{CalibratedRGB}}\n%\n\\caption{Lens-Distortions Removal by Per-Pixel Calibration Method}\n\\label{perPixelCalibrationBeforeAfter}\n\\end{figure}%\n%\n\\begin{figure}[t]\n\\centering\n\\hspace*{-0.3cm}\n\\subfloat[Raw]{\n\\includegraphics[width=0.3\\textwidth, height = 0.425\\textwidth]{distortedSideViewRGB}\n\\label{distortedSideViewRGB}}\n\\qquad%\n\\subfloat[Calibrated]{\n\\includegraphics[width = 0.3\\textwidth, height = 0.425\\textwidth]{CalibratedSideView}\n\\label{CalibratedSideView}}\n%\n\\caption{Depth-Distortions Removal by Per-Pixel Calibration Method}\n\\label{depthDistortionCalibrationBeforeAfter}\n\\end{figure}%\n%\n%%\n%\n%\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "cd311c2c3b451a759bf9e6bd57a05cd9aa5e0c9e", "size": 12940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/04_CalibrationReconstruction.tex", "max_stars_repo_name": "SenonLi/Universal_Real-Time_XYZ_Rectified_Reconstruction", "max_stars_repo_head_hexsha": "d015ac2f53c5b0b2d9e12036b6fc69ca3e544596", "max_stars_repo_licenses": ["MIT"], "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/04_CalibrationReconstruction.tex", "max_issues_repo_name": "SenonLi/Universal_Real-Time_XYZ_Rectified_Reconstruction", "max_issues_repo_head_hexsha": "d015ac2f53c5b0b2d9e12036b6fc69ca3e544596", "max_issues_repo_licenses": ["MIT"], "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/04_CalibrationReconstruction.tex", "max_forks_repo_name": "SenonLi/Universal_Real-Time_XYZ_Rectified_Reconstruction", "max_forks_repo_head_hexsha": "d015ac2f53c5b0b2d9e12036b6fc69ca3e544596", "max_forks_repo_licenses": ["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.9428571429, "max_line_length": 1650, "alphanum_fraction": 0.7506955178, "num_tokens": 3584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6528737311396778}}
{"text": "\\section{Universal property}\n\n\\subsection{Natural numbers in set theory and category theory}\n\n\\textbf{A1} is the regular Peano's definition of natural numbers. There is\nnothing new.\n\n\\textbf{A2} is more interesting to investigate. It defines natural\nnumber set ($N$) to be the ``initial'' object of the category of all\nnatural-number-like sets ($X$). The essential part of a univeral\nproperty is the unique arrow, or\n\\emph{factorization}. In our case, it is the $f : X \\to N$. Here is an\nexample of an $X$ in \\textbf{A2}.\n\n\\begin{example}\n  $(-1) \\in X \\rTo^g X$ where\n  $g := a \\rMapsto a-1$. With this case\n  $f := a \\rMapsto -(a+1)$.\n\\end{example}\n\nThis is straightfoward, just a demonstration of what is it about.\n\n\n\\begin{quotation}\n  The \\emph{Recursion Theorem}\n  \\footnote{\\url{https://en.wikipedia.org/wiki/Recursion#The_recursion_theorem}}\n  guarantees recursively defined functions exists. Given a set $X$, an\n  element of $e\\in X$ and a function $g : X \\to X$, the theorem states\n  there is a unique function $f : N \\to X$, such that\n  \\begin{align}\n    f(0) &= e \\\\\n    f(n+1) &= g(f(n))\n  \\end{align}\n\\end{quotation}\n\nThis is essentially defines a factorization from $N$ to $X$.\n\nSo then the proof of \\textbf{A1} and \\textbf{A2} are isomorphic.\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"master.tex\"\n%%% End:\n", "meta": {"hexsha": "1a359d0d78ec820dcb994fa4ac8d6d8d6e8654ea", "size": 1336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "turi-notes/chap1.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": "turi-notes/chap1.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": "turi-notes/chap1.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": 29.6888888889, "max_line_length": 80, "alphanum_fraction": 0.6938622754, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.6528737296020558}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Consider the following diagram of four circuits.\n  \\begin{center}\n    \\scalebox{0.8}{\n      \\begin{circuitikz}[american, scale=0.7] \\draw\n        (0,0) to [battery1, v^= $5\\volt$~~] (0,4)\n        (0,0) to [R = $2 \\ohm$] (4,0)\n        to [R = $5 \\ohm$] (4,4)\n        (0,4) to [R =$3 \\ohm$] (4,4)\n        (6,4) to [battery1, v_= \\raisebox{1ex}{$20\\volt$}] (4,4)\n        (6,4) to [R = $1 \\ohm$] (8,4)\n        to [R = $1 \\ohm$] (8,0)\n        (4,0) to [R = $6 \\ohm$] (8,0)\n        to [R = $3 \\ohm$] (8,-4)\n        to [R = $2 \\ohm$] (4,-4)\n        to [R = $1 \\ohm$] (4,0)\n        (4,-4)to [R = $4 \\ohm$] (0,-4)\n        (0,0 )to [battery1, v_= $10\\volt$~~] (0,-4)\n        (2,2) node[scale=3]{$\\circlearrowleft$}\n        (2,2) node{$I_2$}\n        (6,2) node[scale=3]{$\\circlearrowleft$}\n        (6,2) node{$I_3$}\n        (6,-2) node[scale=3]{$\\circlearrowleft$}\n        (6,-2) node{$I_4$}\n        (2,-2) node[scale=3]{$\\circlearrowleft$}\n        (2,-2) node{$I_1$}\n        ;\n      \\end{circuitikz}\n    }\n  \\end{center}\n  The current in amperes in the four circuits is denoted by $I_1$,\n  $I_2$, $I_3$, and $I_4$. It is understood that a positive\n  current means a current flowing in the counterclockwise direction. If\n  $I_k$ ends up being negative, then it just means the current flows\n  in the clockwise direction.  In the above diagram, the top left\n  circuit should give the equation\n  \\begin{equation*}\n    2I_2 - 2I_1+5I_2 - 5I_3+3I_2=5.\n  \\end{equation*}\n  Write equations for each of the other three circuits and then give a solution\n  to the resulting system of equations.\n  \\begin{sol}\n    The other three equations are\n    \\begin{eqnarray*}\n      4I_1 + I_1 - I_4 + 2I_1 - 2I_2 &=& -10 \\\\\n      6I_3 - 6I_4 + I_3 + I_3 + 5I_3 - 5I_2 &=& -20 \\\\\n      2I_4 + 3I_4 + 6I_4 - 6I_3 + I_4 - I_1 &=& 0.\n    \\end{eqnarray*}\n    Then the system is\n    \\begin{equation*}\n      \\begin{array}{c}\n        2I_2 - 2I_1 + 5I_2 - 5I_3 + 3I_2 = 5 \\\\\n        4I_1 + I_1 - I_4 + 2I_1 - 2I_2 = -10 \\\\\n        6I_3 - 6I_4 + I_3 + I_3 + 5I_3 - 5I_2 = -20 \\\\\n        2I_4 + 3I_4 + 6I_4 - 6I_3 + I_4 - I_1 = 0.\n      \\end{array}\n    \\end{equation*}\n    The solution is:\n    \\begin{eqnarray*}\n      I_1 &=& -\\frac{750}{373} \\\\\n      I_2 &=& -\\frac{1421}{1119} \\\\\n      I_3 &=& -\\frac{3061}{1119} \\\\\n      I_4 &=& -\\frac{1718}{1119}.\n    \\end{eqnarray*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Find $I_1$, $I_2$, and $I_3$, the counterclockwise currents in\n  amperes in the three circuits of the following diagram.\n\n  \\begin{center}\n    \\scalebox{0.8}{\n      \\begin{circuitikz}[american, scale=0.7] \\draw\n        (0,0) to [battery1, v^= $10\\volt$~~] (0,4)\n        (0,0) to [R = $2 \\ohm$] (4,0)\n        to [R = $5 \\ohm$] (4,4)\n        (0,4) to [R =$3 \\ohm$] (4,4)\n        (6,4) to [battery1, v_= \\raisebox{1ex}{$12\\volt$}] (4,4)\n        (6,4) to [R = $7 \\ohm$] (8,4)\n        to [R = $3 \\ohm$] (8,0)\n        (4,0) to [R = $1 \\ohm$] (8,0)\n        to [R = $4 \\ohm$] (8,-4)\n        to [R = $4 \\ohm$] (4,-4)\n        to [R = $2 \\ohm$] (4,0)\n        (2,2) node[scale=3]{$\\circlearrowleft$}\n        (2,2) node{$I_1$}\n        (6,2) node[scale=3]{$\\circlearrowleft$}\n        (6,2) node{$I_2$}\n        (6,-2) node[scale=3]{$\\circlearrowleft$}\n        (6,-2) node{$I_3$}\n        ;\n      \\end{circuitikz}\n    }\n  \\end{center}\n\n  \\begin{sol}\n    We have\n    \\begin{eqnarray*}\n      2I_1 + 5I_1 + 3I_1 - 5I_2 &=& 10 \\\\\n      I_2 - I_3 + 3I_2 + 7I_2 + 5I_2 - 5I_1 &=& -12 \\\\\n      2I_3 + 4I_3 + 4I_3 + I_3 - I_2 &=& 0.\n    \\end{eqnarray*}\n    Simplifying this yields\n    \\begin{eqnarray*}\n      10I_1 - 5I_2 &=& 10 \\\\\n      -5I_1 + 16I_2 - I_3 &=& -12 \\\\\n      -I_2 + 11I_3 &=& 0.\n    \\end{eqnarray*}\n    The solution is given by\n    \\begin{equation*}\n      I_1 = \\frac{218}{295},\\quad\n      I_2 = -\\frac{154}{295},\\quad\n      I_3 = -\\frac{14}{295}.\n    \\end{equation*}\n\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "f796f61f3938d0f16092e9e472bcc39b0da55a36", "size": 3877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-Application-ResistorNetworks.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-Application-ResistorNetworks.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-Application-ResistorNetworks.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 32.3083333333, "max_line_length": 79, "alphanum_fraction": 0.5052875935, "num_tokens": 1766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6528737280644336}}
{"text": "\\setlength{\\parindent}{0pt}\n\n\\clearpage\n\\section{Liveness DFA rules}\n(Prepared by Jai Arora)\n\\vspace{0.3cm}\n\nNow here we will define the transfer function for the Liveness Analysis. Define the function $L(s,x,in/out)$ as follows:\n\n\\begin{itemize}\n    \\item $x$ - the variable for which we want to compute the liveness values\n    \\item $s$ - a program statement $s$\n    \\item $in/out$ - whether it is input to the statement or output to the statement i.e just before the statement or just after the statement.\n    \\begin{itemize}\n        \\item $L(s, x, in)$ = The liveness value of $x$ just before s\n        \\item $L(s, x, out)$ = The liveness value of $x$ just after s i.e just after statement s is executed\n    \\end{itemize}\n\\end{itemize}\n\nAs discussed before, $L(s,x,in/out) \\in \\{{\\tt true}, {\\tt false}\\}~\\forall s,x$.\\\\\n\nFrom now on, the discussion is for a particular variable $x$, but it can be generalized to more than one variables. We are going to define rules for the following 2 cases:\n\n\\begin{itemize}\n    \\item \\textbf{Case 1:} A statement $p$ has one or more successor program points. So in this case, the $out$ value of the statement $p$ is expressed as a function of $in$ values of the successor program points.\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[height=3cm]{images/Module82_1.png}\n    \\end{figure}\n\n    \\item \\textbf{Case 2:} For a given statement $s$, the $in$ value is a function of the $out$ value of that statement.\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[height=3cm]{images/Module82_2.png}\n    \\end{figure}\n\n\\end{itemize}\nIt can be obseved from here that unlike Global Constant Propagation, which is a Forward Dataflow Analysis, this is a Backward Dataflow Analysis (it starts from the exit point).\n\n\\subsection{Rules for the Transfer Function:}\n%Insert Images\n\\begin{itemize}\n    \\item $L(p, x, out) = glb\\{L(s_i, x, in)~|~s_i$ is a successor of $p\\}$\\\\\n    \n    If $x$ is live before any of the successors, then $x$ is live after that statement as it may get used in the downflow logic.\n    \\item If $s$ is of the form $... = f(...,x,...)$, then $$L(s, x, in) = {\\tt true}$$ as the variable $x$ is getting used in this statement.\n    \\item If $s$ is of the form $x := e$, where $e$ is an expression which does not refer to $x$, then $$L(s, x, in) = {\\tt false}$$ as we don't need the values of $x$ just above this statement due to $x$ being rewritten\n    \n    Note: If $e$ referred to $x$, then Rule \\#2 would apply\n    \\item If $s$ does not refer to $x$ at all (neither updating it, nor using it), then $$L(s, x, in) = L(s, x, out)$$\n\\end{itemize}\n\nThese rules are exhaustive. These can be thought of as a system of equations, and our solution should satisfy all these rules.\n\n\\subsection{Liveness DFA Algorithm}\n\\begin{itemize}\n    \\item Initialize $L(s, x, in/out) = {\\tt false}$ for all statements $s$ and variables $x$ (We start from a more aggresive value)\n    \\item Repeat until all program points satisfy Rules 1-4\n    \\begin{itemize}\n        \\item Pick a statement $s$ not satisfying one or more rules in rules 1-4 and update the corresponding $L()$ function value using the appropriate rule\n    \\end{itemize}\n\\end{itemize}\n\nThere is a guarantee that this algorithm will converge.", "meta": {"hexsha": "ee8865671a6018e392f72a60cac50afa1fd52667", "size": 3271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module82.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": "module82.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": "module82.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": 51.109375, "max_line_length": 220, "alphanum_fraction": 0.6875573219, "num_tokens": 945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.652873723763235}}
{"text": "\\gotosection{0}{2}\n\\subsection{Quantifiers and negation}\n\n\\begin{exercise}{1}\n  \\begin{enumerate}\n    \\item There exists a prime number such that if you divide it by 4 you have\n          a remainder of 1 and it is not the sum of two squares.\n\n    \\item There exists $x \\in \\mathbb{R}$ and $\\epsilon > 0$ such that for all\n          $\\delta > 0$, there exists $y \\in \\mathbb{R}$, if $|y - x| < \\delta$,\n          then $|y^2 - x^2| \\geq \\epsilon$.\n\n    \\item There exists $\\epsilon > 0$ such that for all $\\delta > 0$, there\n          exist $x, y \\in \\mathbb{R}$ such that if $|y - x| < \\delta$, then\n          $|y^2 - x^2| \\geq \\delta$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\gotosection{0}{3}\n\\subsection{Set theory}\n\n\\begin{exercise}{1}\n  \\begin{enumerate}\n    \\item\n    $\\begin{aligned}[t]\n    A * B    &= (E - A) \\cap (E - B) = E - (A \\cup B) \\\\\n    A \\cup B &= E - (E - (A \\cup B)) \\\\\n             &= E - A * B \\\\\n             &= (E - A * B) \\cap (E - A * B) \\\\\n             &= (A * B) * (A * B)\n    \\end{aligned}$\n\n    \\item\n    $\\begin{aligned}[t]\n    A \\cap B &= (E - (E - A)) \\cap (E - (E - B)) \\\\\n             &= (E - A) * (E - B) \\\\\n             &= (A * A) * (B * B)\n    \\end{aligned}$\n\n    \\item\n    $\\begin{aligned}[t]\n    E - A &= (E - A) \\cap (E-A) \\\\\n          &= A * A\n    \\end{aligned}$\n  \\end{enumerate}\n\\end{exercise}\n\n\\gotosection{0}{4}\n\\subsection{Functions}\n\n\\begin{exercise}{6}\n  \\begin{enumerate}\n    \\item\n    $f$ can become one to one if it's domain is changed to $[0, \\infty)$, namely, all nonnegative numbers. Then, for each $y \\in [0, \\infty)$, there is one and only one $x$ such that $y = f(x)$, which is $x = \\sqrt{y}$.\n\n    $f$ cannot become one to one by solely changing its codomain. As long as its codomain contains any number other than 0, say $y$, there always exist two possible $x$ such that $f(x) = y$, namely $\\sqrt{y}$ and $-\\sqrt{y}$. If its codomain was changed to the singleton set $\\{0\\}$, the domain will also be changed to $\\{0\\}$. Hence it's impossible to make it one to one by by solely changing its codomain.\n\n    \\item\n    For any real number $x$, as long as both $x$ and $-x$ are removed from $f$'s domain, for $y \\in [0, \\infty), y = x^2$, there doesn't exist $x'$ of $f$'s domain such that $f(x') = y$, because both two roots of the equation $y = x^2$ are removed from $f$'s domain. Hence, $f$ becomes not onto.\n\n    $f$ can become not onto if it's codomain is extended to contain negative real numbers. For every $y < 0$, there doesn't exist $x = \\sqrt{y}$ such that $x$ is a real number.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{8}\n  \\begin{enumerate}\n    \\item $f^{-1}(A \\cap B) = f^{-1}(A) \\cap f^{-1}(B)$.\n\n    \\Proof{} For every $x \\in f^{-1}(A \\cap B)$, there exists $y \\in A \\cap B$\n    such that $y = f(x)$. Because $y \\in A$, $y \\in B$, and $y = f(x)$,\n    $x \\in f^{-1}(A)$ and $x \\in f^{-1}(B)$, or $x \\in f^{-1}(A) \\cap f^{-1}(B)$\n    . Therefore, $f^{-1}(A \\cap B) \\subseteq f^{-1}(A) \\cap f^{-1}(B)$.\n\n    For every $x \\in f^{-1}(A) \\cap f^{-1}(B)$, $x \\in f^{-1}(A)$ and\n    $x \\in f^{-1}(b)$; as a result, there exist $y \\in A$ and $z \\in B$ such\n    that $y = z = f(x)$, or, $y \\in A \\cap B$. By definition, $x \\in f^{-1}(A \\cap B)$.\n    So, $f^{-1}(A) \\cap f^{-1}(B) \\subseteq f^{-1}(A \\cap B)$. Since two sets\n    are subsets of each other, they are equal. \\QED\n\n    \\item $f^{-1}(A \\cup B) = f^{-1}(A) \\cup f^{-1}(B)$.\n\n    \\Proof{} For every $x \\in f^{-1}(A \\cup B)$, there exists $y \\in A \\cup B$\n    such that $y = f(x)$. Because $y$ is an element of either $A$ or $B$ or both\n    , $x$ is the element of $f^{-1}(A)$ and $x \\in f^{-1}(B)$ or both, which\n    means $x \\in f^{-1}(A) \\cup f^{-1}(B)$. Therefore, $f^{-1}(A \\cup B) \\subseteq f^{-1}(A) \\cup f^{-1}(B)$.\n\n    For every $x \\in f^{-1}(A) \\cup f^{-1}(B)$, $x \\in f^{-1}(A)$ or\n    $x \\in f^{-1}(b)$ or both. If $x \\in f^{-1}(A)$, there exists $y \\in A$\n    such that $y = f(x)$; then, $y \\in A \\cup B$, $x \\in f^{-1}(A \\cup B)$ by\n    definition. Similarly, if $x \\in f^{-1}(B)$, $x$ will also be an element of\n    $f^{-1}(A \\cup B)$. So, $f^{-1}(A) \\cup f^{-1}(B) \\subseteq f^{-1}(A \\cup B)$.\n    Since two sets are subsets of each other, they are equal. \\QED\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{10}\n  \\begin{enumerate}\n    \\item Let the function \\FunSS{f}{B}{C} and \\FunSS{g}{A}{B} be onto.\n          Then the composition $f \\circ g$ is onto.\n\n    \\Proof{} For every $c \\in C$: since \\FunSS{f}{B}{C} is surjective, there\n    exists $b \\in B$ such that $f(b) = c$; since \\FunSS{g}{A}{B} is surjective,\n    there exists $a \\in A$ such that $g(a) = b$. Therefore, for every $c \\in C$,\n    there exists $a \\in A$ such that $(f \\circ g)(a) = f(g(a)) = c$.\n    Thus, $f \\circ g$ is surjective, or onto. \\QED\n\n    \\item Let the function \\FunSS{f}{B}{C} and \\FunSS{g}{A}{B} be one to one.\n          Then the composition $f \\circ g$ is one to one.\n\n    \\Proof{} For every $c \\in C$ such that there exists $a \\in A$ such that\n    $f(g(a)) = c$, suppose there do exist $x, y \\in A$ such that both $f(g(x)) = c$\n    and $f(g(y)) = c$. Since $f$ is injective, $g(x) = g(y)$. Since $g$ is injective\n    , $x = y$. Therefore, there is at most one $x$ such that $(f \\circ g)(x) =\n    f(g(x)) = c$. Thus, $f \\circ g$ is injective, or one to one. \\QED\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{12}\n  Let $F$ be a sequence of functions:\n  $$\\begin{array}{rcl}\n      F_0 &=& \\ln \\\\\n      F_1 &=& \\ln \\circ \\ln \\\\\n      F_2 &=& \\ln \\circ \\ln \\circ \\ln \\\\\n      F_3 &=& \\ln \\circ \\ln \\circ \\ln \\circ \\ln \\\\\n      &\\vdots& \\\\\n      F_n &=& \\ln \\text{composed with itself $n$ times}\n    \\end{array}$$\n\n    Let $X_n$ be the (natural) domain of $F_{n}$. $X_{0}$ is the domain of $\\ln$\n    , namely $(0, \\infty)$. For each $n \\in \\mathbb{N}$, $F_{n+1} = F_n \\circ \\ln$\n    , $X_{n+1}$ is the intersection of the inverse image of $X_n$ under $\\ln$\n    and $\\ln$'s domain $(0, \\infty)$. The inverse image of a set $X$ under $\\ln$\n    is also the image of $X$ under the inverse function of $\\ln$, namely\n    $exp(x) = e^x$. Note that $exp$ is a monotonically increasing function.\n\n  \\begin{enumerate}\n    \\item $\\ln \\circ \\ln = F_1 = F_0 \\circ \\ln$.\n\n    $X_0 = (0, \\infty)$, and its image under $exp$ is $(exp(0), exp(\\infty)) = (1, \\infty)$.\n    The natural domain of this function is $X_1 = (1, \\infty) \\cap (0, \\infty) = (1, \\infty)$.\n\n    \\item $\\ln \\circ \\ln \\circ \\ln = F_2 = F_1 \\circ \\ln$\n\n    $X_1 = (1, \\infty)$, and its image under $exp$ is $(exp(1), exp(\\infty)) = (e, \\infty)$.\n    The natural domain of this function is $X_2 = (e, \\infty) \\cap (0, \\infty) = (e, \\infty)$.\n\n    \\item $\\ln$ composed with itself $n$ times $= F_n = F_{n - 1} \\circ \\ln$\n\n    A function \\FunSS{ans}{\\mathbb{Z}^+}{\\mathbb{R}} can be defined as:\n    $$ans(x) = \\left\\{\n    \\begin{array}{lc}\n    1            & x = 1 \\\\\n    e^{ans(x-1)} & x > 1\n    \\end{array}\n    \\right.$$.\n\n    This function is in fact the tetration of $e$:\n    $$ans(x) = {^{n}e} = \\underbrace{e^{e^{\\cdot^{\\cdot^{e}}}}}_n$$\n\n    Assume that for every positive integer $i$, $X_i = (ans(i), \\infty)$. This\n    can be proven inductively as $X_1 = (ans(1), \\infty)$, $X_2 = (ans(2), \\infty)$,\n    and $X_i = (exp(ans(i-1)), exp(\\infty)) \\cap (0, \\infty) = (ans(i), \\infty)$.\n    Therefore, the natural domain of $F_n$, or $\\ln$ composed with itself $n$ times,\n    is $X_n = (ans(n), \\infty)$.\n  \\end{enumerate}\n\\end{exercise}\n", "meta": {"hexsha": "029291440aaa556b77f2c703b334c42b9981c79d", "size": 7423, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW1/sec00.tex", "max_stars_repo_name": "notcome/fa15-linear-algebra", "max_stars_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW1/sec00.tex", "max_issues_repo_name": "notcome/fa15-linear-algebra", "max_issues_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW1/sec00.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": 44.4491017964, "max_line_length": 407, "alphanum_fraction": 0.5462750909, "num_tokens": 2789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6528737219427004}}
{"text": "\\subsection{The Riemann-Hurwitz Theorem}\r\n\\begin{theorem}[Riemann-Hurwitz]\r\n    Let $f:R\\to S$ be any non-constant analytic map of compact Riemann surfaces, then\r\n    $$\\chi(R)=\\deg(f)\\chi(S)-\\sum_{p\\in R}(m_f(p)-1)$$\r\n\\end{theorem}\r\n\\begin{remark}\r\n    As $R$ is compact, the sum only has finitely many nonzero terms.\r\n\\end{remark}\r\n\\begin{proof}[Sketch of proof]\r\n    As in the proof of the valency theorem, each $q\\in S$ has a ``power neighborhood'' $U$ where $f$ restricts to a union of power maps on $f^{-1}(U)$.\r\n    By compactness, there is a finite open cover $\\{U_1,\\ldots,U_k\\}$ of $S$ where each $U_i$ is a ``power neighbourhood'' of $f$.\r\n    In particular, the number of branch points is finite.\r\n    We can subdivide a triangulation on $S$ so that we can eventually reach a triangulation such that each triangle has at most $1$ branch point.\r\n    We can further subdivide such that each branch point is a vertex.\r\n    Continue to subdivide so that each triangle is contained in some $U_i$.\r\n    Now the preimage of this eventual triangulation forms a triangulation of $R$.\r\n    Let $n=\\deg f$ and $V_R,E_R,F_R,V_S,E_S,F_S$ are exactly what you think they mean.\r\n    Then, intuitively, $F_R=nF_S,E_R=nE_S$ while\r\n    $$|f^{-1}(\\{q\\})|=n-\\sum_{p\\in f^{-1}(\\{q\\})}(m_f(p)-1)$$\r\n    Summing up,\r\n    $$V_R=nV_S-\\sum_{q\\in S}\\sum_{p\\in f^{-1}(\\{q\\})}(m_f(p)-1)=nV_S-\\sum_{p\\in R}(m_f(p)-1)$$\r\n    which implies the identity.\r\n\\end{proof}", "meta": {"hexsha": "33294b4406d6ae958a6e51c9867b098102a715b2", "size": 1446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/thm.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/thm.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/thm.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.8695652174, "max_line_length": 152, "alphanum_fraction": 0.6659751037, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6528688259462718}}
{"text": "\\section{Lighting}\n\\subsection{Preface}\nOne of the most important factors that make a scene realistic is how the light interacts with the objects in it.\nThrough time, rendering techniques progressed from various empirical models (e.g. Phong models), that required\ntweaking from the artists in order to make results seem more realistic under different lighting setups, to physical based\nalgorithms (e.g. Microfacet models) that calculate the correct object lighting given the lighting environment and\nits material properties. The Physical Based models are based on the laws of physics on how light interacts with\nmatter depending on a number of environmental variables.\n\n\\subsection{Background}\nAll the physical based rendering models try to solve a simplified version of the rendering equation~\\cite{lighting:ref32}.\nThis equation relates the outgoing light in a particular direction $\\omega_o$ to the incident light at a point $p$ on a surface:\n\n\\begin{equation}\n\\label{eq:rendeq}\nL_o(p,\\omega_o) = L_e(p, \\omega_o) + \\int_\\Omega f_r(p,\\omega_i,\\omega_o)L_i(p,\\omega_i)n\\cdot\\omega_i \\ d\\omega_i\n\\end{equation}\n\n\\noindent Breaking down the equation we get:\n\n\\begin{equation}\n\\underbrace{L_o(p,\\omega_o)}_\\text{Outgoing Light} = \\underbrace{L_e(p, \\omega_o)}_\\text{Emitted Light} + \\underbrace{\\int_\\Omega f_r(p,\\omega_i,\\omega_o)L_i(p,\\omega_i)n\\cdot\\omega_i \\ d\\omega_i}_\\text{Reflected Irradiance}\n\\end{equation}\n\nAccording to the equation the \\textit{outgoing light} in a particular direction from a point on a surface is the\nsum of the \\textit{emitted light} from that point and the contribution of all the incoming light from all directions in a\nhemisphere above the point p (the orientation of the hemisphere is determined by the normal n).\n\n\\noindent Breaking down the integral we get:\n\n\\begin{equation}\n\\int_\\Omega \\underbrace{f_r(p,\\omega_i,\\omega_o)}_\\text{BRDF}\\underbrace{L_i(p,\\omega_i)}_\\text{Incoming Light}\\underbrace{n\\cdot\\omega_i}_\\text{Incident Flow}\\ d\\omega_i\n\\end{equation}\n\nWhere BRDF is a function that returns the ratio of the amount of light reflected in a particular direction $\\omega_o$, to the\namount received from another direction $\\omega_i$ (more details later), incoming light is the light arriving at the point p\nfrom the direction $\\omega_i$, and incident flow is an attenuation factor that makes the incoming light at $p$\ndependent on the cosine of the angle between the normal $n$ and the incoming light direction $\\omega_i$. Note that the\nincoming light does not have to come from a light source (direct light), it may have been reflected or refracted from another\npoint int the scene (indirect light).\n\n\\subsection{Diffuse and Specular lighting}\nWhen light hits a surface there are three possible outcomes. Light may be \\textbf{absorbed} by the material, light may be\n\\textbf{transmitted} through to the other side or light may be \\textbf{reflected} back. For dense objects, light scattered\nback through the surface of incidence near the point of entry is said to be diffusely reflected (diffused). Moreover, surface\nreflection is also called specular reflection. The Cook-Torrance model, that is used in the current implementation,\nalso makes this separation by describing the BRDF function as:\n\n$$f_r = k_d f_{lambert} + k_s f_{cook-torrance}$$\n\nWhere $f_{lambert}$ describes the diffuse component, $f_{cook-torrance}$ describes the specular component, $k_d$ is the amount\nof incoming radiance that gets diffused and $k_s$ is the amount of light that is specularly reflected. If a given material\nexhibits a strong diffusive behaviour it have a high value for $k_d$, while if it behaves more like a mirror it will have high $k_s$.\nFor the diffuse BRDF has been choosen the Lambert's BRDF that is equal to:\n\n$$f_{lambert} = \\frac{c}{\\pi}$$\n\nwhere c is the surface colour. The specular Cook-Torrance BRDF is defined as:\n\n$$f_{cook-torrance} = \\frac{DFG}{(4 \\omega_o \\cdot n)(\\omega_i \\cdot n)}$$\n\nWhere D is the distribution function, F is the fresnel function and G is the geometry function.\nThe Cook-Torrance model falls into the category of the \\textbf{Microfacet Models} which are based on the idea\nthat rough surfaces can be modelled as a collection of small microfacets, where each microfacet is assumed to be a very small perfect mirror,\nand their distribution and orientation define how the light is reflected at a large scale.\\cite{lighting:ref33}\n\n\\subsection{Material properties}\nMaterials are defined by the following properties:\n\n\\begin{enumerate}\n    \\item Base Color (Albedo), defines the color of diffused light\n    \\item Roughness, defines how rough is a surface. Rougher surfaces will show wider but dimmer specular reflections, while smoother\n        surfaces will show brighter but sharper specular reflections.\n    \\item Metallic, defines if a material behaves like a dielectric or metal.\n    \\item Reflectivity, defines the percentage of light a surface reflects. Specifically defines how reflective a surface is when viewed\n        head on.\n    \\item Emissive Color, defines emission light color for emissive materials.\n\\end{enumerate}\n\nThe separation between metals and dielectrics, also affects each light reflection type.\nMetals are assumed to be fully specular materials with base color acting as their specular color and no diffuse color (black)\ndue to very quick absorption near the surface. In the dielectrics category on the other hand the base color acts as their diffuse\ncolor and white as their specular color.\n\nIn the following figures we can see the effects of roughness and reflectivity values for each type of material with\nroughness increasing from left to right and increasing from bottom to top:\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4,clip=true]{./image/pbr_dielectrics.png}\n    \\caption{Dielectrics}\n\\label{fig:pbrdielectrics}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4,clip=true]{./image/pbr_metals.png}\n    \\caption{Metals}\n\\label{fig:pbrmetals}\n\\end{figure}\n\n\\subsection{Environmental lighting}\nAs stated before, light arriving at a point may have been reflected or refracted from another point in the scene.\nOffline algorithms may be able to capture that effect but in realtime applications this is computationally expensive.\nSo in order to emulate indirect lighting quite often many rendering systems resolve to approaches that take advantage of\npreprocessing the surrounding environment of an object.\n\nA technique called Image Base Lighting (IBL) is one solution that addresses that problem. First, an object's environment is\ncaptured as images in a cubemap form\\footnote{Cube mapping is a method of environment mapping that uses the six faces of a cube\nas the map shape. The environment is projected onto the sides of a cube and stored as six square textures, or unfolded into six\nregions of a single texture.} and then the rendering equation integrals are precalculated, treating each pixel in the\nenvironment map as a point sample on the surrounding environment that contributes to the center of the cube map. The result\ncan also be stored in cubemaps that can be queried later and be used to calculate the environmental light contribution on a\nfragment. This way, each texel of the new environment (pre-filterred radiance) map, corresponds to the pre-integrated radiance\nfrom a given lobe of directions centered at the direction of the cubemap texel. The integrant includes the weighting according\nto a BRDF matching the directional lobe, which corresponds to a particular roughness level.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.18,clip=true]{./image/envl_ref.png}\n    \\caption{Radiance Field}\n\\label{fig:envlref}\n\\end{figure}\n\nThe environmental diffuse and specular light contribution can be captured on an Irradiance Maps\\footnote{The irradiance map that is\nadjusted for specular reflections is also known as Prefiltered mipmaped radiance environment map (PMREM)}. The diffuse Irradiance map\ncan be generated by precalculating the BRDF for all the points in a hemisphere around an object according to the normal\ndirection, and similary the specular environment map can be generated by precalculating the BRDF for an area near the ideal reflection\nvector. For the specular reflections, roughness is the main contributor on the tightness of the specular lobe, so with lower roughness\nvalues a less blurry lookup map is needed, while with the higher roughness values a more blurry map must be used in order to make\nthe correct specular lobe. For this reason, multiple versions of increasing roughness radiance maps are created that are chosen\nfor their relevant roughness value. These maps can be stored as different mipmaps of the radiance cubemap in order to sample uniformingly.\nA function that will choose the correct mipmap level according to an object roughness must be also created, that should be tweaked\nfor a specific cubemap resolution.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[scale=0.18,clip=true]{./image/envl_irr.png}\n    \\caption{Diffuse Irradiance Map}\n\\label{fig:envlirr}\n\\end{figure}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[scale=0.36,clip=true]{./image/envl_rad.png}\n    \\caption{Specular Irradiance Map}\n\\label{fig:envlrad}\n\\end{figure}\n\nNote that still, this way only phong lobe shapes are possible to be matched, as the whole microfacet specular\nBRDF is not evaluated for the environment, although more advanced approximations also exist\\footnote{Split sum approximation is a great\nexample, where the part of the BRDF not included in the PMREM is calculated as a separate lookup table that can be used to make\nspecular lobes for the environment lighting that match the direct lighting model\\cite{lighting:ref40}}.\n", "meta": {"hexsha": "b0147f12b3739b5b63a92f9bafb1e98b7ef91b77", "size": 9744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/lighting.tex", "max_stars_repo_name": "ScaryBoxStudios/TheRoom", "max_stars_repo_head_hexsha": "880c8730cb5c271def472df76fa655df1970b94b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-12T11:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-12T11:40:45.000Z", "max_issues_repo_path": "doc/lighting.tex", "max_issues_repo_name": "ScaryBoxStudios/TheRoom", "max_issues_repo_head_hexsha": "880c8730cb5c271def472df76fa655df1970b94b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/lighting.tex", "max_forks_repo_name": "ScaryBoxStudios/TheRoom", "max_forks_repo_head_hexsha": "880c8730cb5c271def472df76fa655df1970b94b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.2727272727, "max_line_length": 224, "alphanum_fraction": 0.7928981938, "num_tokens": 2302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181874, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.652850470005948}}
{"text": "\\input{PreambleCommon}\r\n\\input{../WeekTitles}\r\n\r\n\\begin{document}\r\n\\setfont\r\n\\pagestyle{fancy}\r\n\\renewcommand{\\Week}{9 }\r\n\\renewcommand{\\WeekTitle}{\\WeekTitleNine }\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\r\n\\vspace{5mm}\r\n\\goals\r\n\\begin{itemize}\r\n\\item Take problems that can be modeled by differential equations,\r\n  both first and second order, and give solutions both by hand and\r\n  MATLAB \r\n\\item Examine case studies of differential equations applied to\r\n  engineering problems and reproduce those solutions\r\n\\end{itemize}\r\n\\vspace{5mm}\r\n\r\n%Falling body problem (maybe even the redbull stratos jump?)\r\n%Electric Circuits\r\n%Suspension cable bridge\r\n\r\n\\newpage\r\n\r\n\\topic{Application - Pendulum}\r\n\\subsection*{Application - Pendulum }\r\n\\begin{minipage}[t]{0.25\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{center}\r\n\\includegraphics[width=1.0\\linewidth]{graphics/notes_09_pendulum_diagram}\r\n\\end{center}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{0.70\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{align*}\r\n  \\mbox{Newton's }& \\mbox{ Second Law: } \\\\\r\n   m  L^2 \\theta'' & = T_g + T_f  \\\\\r\n  & = - m L g \\sin(\\theta) - (\\mu L^2 m) \\theta' \\\\[3ex]\r\n  \\mbox{Solving for $\\theta''$: }\\theta'' & = - \\frac{g}{L} \\sin(\\theta) - \\mu \r\n  \\theta'\r\n\\end{align*}\r\n\\end{minipage}\r\n\r\n\\problem Turn this single second-order DE into a pair of first-order\r\nDEs.\r\n\r\n\\newpage\r\n\\problem Compare the system of differential equations we obtained to\r\nthe equations that define the motion of the damped spring/mass system.\r\n\r\n\\begin{minipage}[t]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/notes_08_hanging_mass}\r\n\\begin{align*}\r\n  \\frac{dw_1}{dt} & = w_2 \\\\\r\n  \\frac{dw_2}{dt} & = \\left(\\frac{1}{m}\\right) (- k w_1-c w_2)\r\n\\end{align*}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{center}\r\n\\includegraphics[width=0.2\\linewidth]{graphics/notes_09_pendulum_diagram}\r\n\\end{center}\r\n\\begin{align*}\r\n  \\frac{d w_1}{dt} & = w_2 \\\\\r\n  \\frac{d w_2}{dt} & = -\\frac{g}{L}\\sin(w_1)  - \\mu w_2\r\n\\end{align*}\r\n\\end{minipage}\r\n\r\n\\newpage\r\n\r\n\r\n\\problem Create a new MATLAB function file called \\texttt{pendulumDE.m}.\r\nStart with the first line\r\n\\begin{verbatim}\r\nfunction dw_dt = pendulumDE(t, w, g, L, mu) \r\n\\end{verbatim}\r\n\r\nIn the body of the function, implement the system of differential\r\nequations \r\n\\begin{align*}\r\n  \\frac{d w_1}{dt} & = w_2 \\\\\r\n  \\frac{d w_2}{dt} & = -\\frac{g}{L}\\sin(w_1)  - \\mu w_2\r\n\\end{align*}\r\n\\vsc\r\n\r\n\\newpage\r\n\r\n\\problem Write a MATLAB script that simulates the motion of the\r\npendulum\r\nusing  \\\\\r\n$g = 9.8$ m/s$^2$, $L$ = 2 m, $\\mu = 0.1$, and \\\\\r\ninitial amplitude of 0.05 radians ($\\approx 2.9$ degrees). \\\\\r\nGenerate a plot of the resulting angular position over time.\r\n\r\n\r\n\\newpage \r\n\\topic{Pendulum - Period of Swings}\r\n\\subsection*{Pendulum - Period of Swings}\r\n\r\nGalileo famously noticed the consistent period of pendulum swings,\r\neven if the amplitude of the swings was changed (so the actual\r\ndistance travelled was different).\r\n\r\n\\vspace{2.5in}\r\n\r\n\\problem Compare the periods of the pendulum swings, using a range of\r\ninitial angles from $\\theta_0 = 0.05$ radians up to $\\theta_0 = 0.25$\r\nradians ($\\approx 14$ degrees).\r\n\r\n\r\n\\newpage\r\nHowever, it turns out that pendulums are {\\bf not} perfectly\r\nconsistent in their period, due to the non-linear term\r\n$\\ds -\\frac{g}{L} \\sin(\\theta)$ in one of the forces: as the\r\namplitudes get bigger, there is a gradual lengthening of the period.\r\n\r\n\r\n\\problem Compare the periods of the pendulum swings, using a range of\r\ninitial angles from $\\theta_0 = 0.25$ radians up to $\\theta_0 = \\frac{\\pi}{2}$\r\nradians ($= 90$ degrees).\r\n\r\n\\newpage\r\n\r\n\\problem Use these observations to explain the designs you see for\r\npendulum-based clocks.\r\n\r\n\\newpage\r\n\r\n\\topic{Pendulum -  Including an Initial Velocity}\r\n\\subsection*{Pendulum -  Including an Initial Velocity}\r\n\r\n\\problem Write a new simulation script that starts the pendulum\r\nswinging from $ \\theta_0 = -\\frac{\\pi}{2}$, with no initial velocity.\r\nSimulate the motion for this scenario and generate a graph of the\r\nangle against time.\r\n\r\nUse the  parameters $g = 9.8$ m/s$^2$, $L$ = 2 m, and $\\mu = 0.1$. \\\\\r\n\r\n\\vsc\r\n\r\n\\newpage\r\n\r\nIf we add a high enough initial `kick', or initial velocity, it would\r\nbe possible to make the mass of the pendulum go ``over the top'', or\r\nabove the point of rotation.\r\n\r\n\\problem Sketch what the anglular position graph would look like for\r\nthis scenario.\r\n\r\n\\newpage\r\n\r\n\\problem If we keep the initial angle at $-\\frac{\\pi}{2}$ (pendulum\r\nout horizontally), experiment with the MATLAB code to find the initial\r\nvelocity that will push the pendulum ``over the top''.\r\n\r\n\\newpage\r\n\r\n\\topic{Application - Lake Mixing Model}\r\n\\subsection{Application - Lake Mixing Model}\r\nConsider a small lake that initially contains $10$ million litres of\r\nfresh water.  Water containing an undesirable chemical flows into the\r\nlake at the rate of $5$ million litres per year; the mixture in the\r\nlake flows out at the same rate.  The concentration $c(t)$ of chemical\r\nin the incoming water varies periodically with time according to the\r\nexpression $c(t) = 2 + \\sin(2t) \\; \\text{g} \\cdot \\text{L}^{-1}$.\r\n\r\n  \\problem Construct a mathematical model of this flow process.\r\n\r\n\\newpage\r\n\\problem Use MATLAB and a differential equation solver to determine\r\nthe amount of chemical in the lake over time, assuming that the lake\r\nstarted without any contamination.\r\n\r\n\\newpage\r\n\r\n\\topic{Application - Tailings Pond With Sediment}\r\n\\subsection*{Application - Tailings Pond With Sediment}\r\n% Source: http://faculty.sfasu.edu/judsontw/ode/html/firstlook05.html\r\nConsider a tailings pond, where the the inflow contains both an\r\nenvironmentally sensitive chemical, and sediments that will settle out\r\nof the water.\r\n\r\n\\begin{itemize}\r\n\\item The volume of the pond is 40,000 cubic meters.\r\n\\item Water is flowing in and out of the pond at a rate of 1,500 cubic\r\n  meters per day.\r\n\\item The water flowing into the pond contains 2 g of toxic chemical\r\n  per cubic meter.\r\n\\item The inflow water also contains 1\\% sediments\r\n\\end{itemize}\r\n\r\n\\problem Sketch a diagram of this scenario.\r\n\r\n\\newpage\r\n\r\n\\problem Write a differential equation that describes the rate of\r\nchange of the concentration of the chemical in the water remaining in\r\nthe tailings pond.\r\n\r\n\\newpage\r\n\r\n\\problem Use MATLAB and a differential equation solver to determine\r\nthe concentration of chemical in the water part of the tailings pond,\r\nassuming that the pond started without any contamination.\r\n\r\n\r\n\\newpage\r\n\r\n\\problem Comment on any mismatch between the model and the reality\r\nthat should be addressed to make the model more accurate.\r\n\r\n\\newpage\r\n\\topic{Application - Interconnected Tanks}\r\n\\section*{Application- Interconnected Tanks}\r\n\r\n\\noindent\r\nConsider the tanks shown below, which shows water flowing between the\r\ntanks, and the concentration of a salt solution coming in.  Within\r\neach tank, the water/salt solution is kept well mixed.\r\n\\begin{center}\r\n\\includegraphics[width=0.7\\linewidth]{graphics/notes_09_tanks1}\r\n\\end{center}\r\n\r\n\\begin{problem}\r\n  If both tanks start with no salt, sketch what you expect will happen\r\n  to the concentration within each tank over time.\r\n\\end{problem}\r\n\r\n\\newpage\r\n\\begin{minipage}[h]{0.5\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{problem}\r\nCreate a system of differential equations that dictate \r\nhow the two tank concentrations will evolve over time.\r\n\\end{problem}\r\n\\end{minipage} \\hfill\r\n\\begin{minipage}[h]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\includegraphics[width=1.0\\linewidth]{graphics/notes_09_tanks1}\r\n\\end{minipage}\r\n\r\n\r\n\\newpage\r\n\\begin{minipage}[t]{0.5\\linewidth}\r\n\\vspace{0pt}\r\n\\problem\r\n  Use MATLAB and a differential equation solver to predict the exact salt concentrations over time\r\nin {\\bf both tanks}. \r\n% \\begin{align*}\r\n% \\frac{dc_A}{dt}    & = \\frac{-1}{10} c_A + 3; \\\\\r\n% \\frac{dc_B}{dt}    & = \\frac{1}{20} c_A -\\frac{1}{20} c_B \r\n% \\end{align*}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\includegraphics[width=1.0\\linewidth]{graphics/notes_09_tanks1}\r\n\\end{minipage}\r\n\r\n\\newpage\r\n\r\n\\topic{Tank Model - Example 2}\r\n\\subsection*{Tank Model - Example 2}\r\n\r\nConsider the more complicated tank arrangement shown below.\r\n\\begin{center}\r\n\\includegraphics[width=0.7\\linewidth]{graphics/notes_09_tanks2}\r\n\\end{center}\r\n\\begin{problem}\r\nGiven that the initial concentrations are \\\\\r\n$c_A(0) = 0 $ g/L and $c_B(0)  = 90$ g/L,  \\\\\r\nsketch what you would predict for the concentration in each tank over time.\r\n\\end{problem}\r\n\r\n\\newpage\r\n\\begin{minipage}[h]{0.5\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{problem}\r\n  Construct the differential equation for the salt concentration in\r\n  each tank.\r\n\\end{problem}\r\n\\end{minipage} \\hfill\r\n\\begin{minipage}[h]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\includegraphics[width=1.0\\linewidth]{graphics/notes_09_tanks2}\r\n\\end{minipage}\r\n\r\n%\\newpage\r\n%\\hfill \\includegraphics[width=0.5\\linewidth]{graphics/notes_09_tanks2}\r\n\r\n\\newpage\r\n\r\n\\begin{minipage}[h]{0.5\\linewidth}\r\n  \\vspace{0pt} \\problem Use MATLAB and a differential equation solver\r\n  to predict the salt concentrations over time by solving the system\r\n  of differential equations\r\n  \\begin{align*}\r\n    \\frac{dc_A}{dt} & = -0.09 c_A + 0.02 c_B + 2.1 \\\\\r\n    \\frac{dc_B}{dt} & = 0.18 c_A - 0.18 c_B \\\\\r\n  \\end{align*}\r\n\\end{minipage} \\hfill\r\n\\begin{minipage}[h]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\includegraphics[width=1.0\\linewidth]{graphics/notes_09_tanks2}\r\n\\end{minipage}\r\n\r\n\r\n\\newpage\r\n\r\n\r\n~\\hfill \\begin{minipage}[h]{0.45\\linewidth}\r\n\\vspace{0pt}\r\n\\includegraphics[width=1.0\\linewidth]{graphics/notes_09_tanks2}\r\n\\end{minipage}\r\n\r\n\r\n\r\n\\end{document}\r\n%Confirmation of deflection:\r\n%  http://www.efunda.com/formulae/solid_mechanics/beams/casestudy_display.cfm?case=cantilever_uniformload\r\n\r\n\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "c6fb37b8e036a0c93997dad51e9a93ed5ab9efeb", "size": 9862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/notes09.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/notes09.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/notes09.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": 29.7048192771, "max_line_length": 106, "alphanum_fraction": 0.7160819306, "num_tokens": 2901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8519528057272544, "lm_q1q2_score": 0.6528460192380426}}
{"text": "\\allowdisplaybreaks[4]\n\\section{Adaptive Noise Cancellation}\n\\subsection{Delay of ALE}\nDue to the uncorrelation between interest signal and noise signal, the white noise can be eliminated by the delay version of the signal. The adaptive line enhancer (ALE) is used the delay of the noise-corrupted signal $s(n)$ to estimate the interest signal $\\hat x(n)$. The optimal delay $\\Delta$ can be calculated at the beginning of the Mean Squared Error.\n\\begin{align}\n\t\\mathbb{E}\\{(s(n)-\\hat x(n))^2\\}\n\t&=\\mathbb{E}\\{(x(n)+\\eta(n)-\\hat x(n))^2\\}\\notag\\\\\n\t&=\\underbrace{\\mathbb{E}\\{\\eta(n)^2\\}}_{\\eta^2}+\\underbrace{\\mathbb{E}\\{(x(n)-\\hat x(n))^2\\}}_{\\approx 0}+\\underbrace{2\\mathbb{E}\\{(x(n)-\\hat x(n))\\eta(n)\\}}_{minimize}\n\\end{align}\nTherefore, for the optimal estimation, the MSE should be equal to the noise power. That is, only the last term should minimize.\n\\begin{align}\n\t\\min_{\\Delta} \\mathbb{E}\\left\\{(x(n)-\\hat x(n))\\eta(n)\\} \\right\\}\n\t&\\Rightarrow \\min_{\\Delta} \\mathbb{E}\\left\\{\\hat x(n)\\eta(n)\\} \\right \\}\\notag\\\\\n\t&=\\min_{\\Delta} \\mathbb{E}\\left\\{v(n) + 0.5v(n-2)\\mathbf w^T(n)\\mathbf u(n)\\right\\}\\notag\\\\\n\t&=\\min_{\\Delta} \\mathbb{E}\\left \\{(v(n) + 0.5v(n-2))\\sum_{i=0}^{M-1}\\mathbf w^T(n)s(n-\\Delta -i)\\right\\}\\notag\\\\\n\t&=\\min_{\\Delta} \\mathbb{E}\\left \\{(v(n) + 0.5v(n-2))\\sum_{i=0}^{M-1}\\mathbf w^T(n)(x(n-\\Delta -i)+\\eta(n-\\Delta -i))\\right\\}\n\\end{align}\nAnd due to uncorrelated of $x(n)$ and $v(n)$, equation above can be simplified to\n\\begin{align}\n\t&\\min_{\\Delta} \\mathbb{E}\\left \\{(v(n) + 0.5v(n-2))\\sum_{i=0}^{M-1}\\mathbf w^T(n)(x(n-\\Delta -i)+\\eta(n-\\Delta -i))\\right\\}\\notag\\\\\n\t=&\\min_{\\Delta} \\mathbb{E}\\left \\{(v(n) + 0.5v(n-2))\\sum_{i=0}^{M-1}\\mathbf w^T(n)\\eta(n-\\Delta -i)\\right\\}\\notag\\\\\n\t=&\\min_{\\Delta} \\mathbb{E}\\left \\{(v(n) + 0.5v(n-2))\\sum_{i=0}^{M-1}\\mathbf w^T(n)(v(n-\\Delta -i)+v(n-\\Delta-2 -i))\\right\\}\\label{eq:MSe}\\\\\n\t\\approx& 0 \\to\\Delta=2\\notag\n\\end{align}\nTherefore, observing Eq.\\ref{eq:MSe}, the error will tend to zero only if the delay $\\Delta$ is larger than 2. Since the time indexes of signal $v(n)$  are non-overlapping, resulting in uncorrelated. Fig.\\ref{fig:2_3_a} depicts the effect of the delay $\\Delta=1\\sim4$ on the estimated signal $\\hat x(n)$ with the fixed filter length $M=3$. The top row illustrated 100 realisations of $s(n)$, $\\hat x(n)$, while the bottom row is the average signal of the estimation. When the delay $\\Delta>3$, the noise signal (in yellow) is suppressed a lot, leading to a small MSE. Thus, the results prove the previous analysis.\n\\begin{figure}[htb]\n    \\centering\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a1.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a3.eps}\n    \\end{subfigure} \n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a5.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a7.eps}\n    \\end{subfigure}\n    \\\\\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a2.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a4.eps}\n    \\end{subfigure} \n    \\hspace{-0.4cm} \n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a6.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.26\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23a8.eps}\n    \\end{subfigure}\n    \\caption{ALE: Effect of $\\Delta$ with fixed $M=3$}\n    \\label{fig:2_3_a}\n\\end{figure}\n\\subsection{Effects of $M$ and delay on MSPE }\nIn order to find the optimal delay and the filter length $M$, this experiment calculates the MPSE by varying $\\Delta$ from 1 to 25 and $M$ from 1 to 20. As shown in Fig.\\ref{fig:2_3_b1}, neglecting the inappropriate values of $\\Delta\\leq 2$ and $M=1$, the MPSE curves both keep a increasing tendency with the growing of the delay and filter order. However, the MSPE remains approximately flat with a minimum error in range 3 to 6. When the filter order is large than 6, the over-modelling problem will occur, causing the growth of the MSPE. Notice that the performances of $\\Delta=3$ and $\\Delta=5$ are nearly same.\n\\begin{figure}[htb]\n    \\centering\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.4\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23b2.eps}\n    \\end{subfigure}\n    \\hspace{1cm}\n    \\begin{subfigure}[b]{0.4\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23b1.eps}\n    \\end{subfigure} \n    \\caption{ALE: Effect of $\\Delta$ and $M$ on MSPE}\n    \\label{fig:2_3_b1}\n\\end{figure}\\\\\nObserving the effect on varying delay, the MSPE curves approximately keep same in the range of $\\Delta\\in[3,6]$, which are similar as the ones of varying order $M$. Afterwards, the MSPE gradually rises up to the maximum when $\\Delta=25$. If the delay is set to large, there is a lag between the estimated signal $\\hat x(n)$ and actual signal $x(n)$, resulting in the increasing MSPE. As shown in Fig.\\ref{fig:2_3_b2}, the realisations of optimal parameters ($M=3$, $\\Delta=3$) and large delay ($M=3$, $\\Delta=25$) are plotted. There is an obvious shift of estimated signal which proved the analysis. Due to the computational cost with increasing order, the relatively optimal parameters are $M=3$ and $\\Delta=3$.\n\\begin{figure}[htb]\n    \\centering\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[t]{0.37\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23b3.eps}\n    \\end{subfigure}\n    \\hspace{0.4cm}\n    \\begin{subfigure}[t]{0.37\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23b4.eps}\n    \\end{subfigure} \n    \\caption{ALE: Realisations of increasing $\\Delta$ with fixed $M$}\n    \\label{fig:2_3_b2}\n\\end{figure}\n\\subsection{ANC vs ALE}\nThe adaptive noise cancellation (ANC) applied different input signal $\\mathbf u(n)$ with correlated noise signal $\\epsilon(n)$ whose aim is to estimate the noise $\\eta(n)$. Thus, the desired signal $\\hat x(n)$ is obtained by subtraction. The correlated secondary signal is assumed as $\\epsilon(n) = 0.7\\eta(n) + 0.01$. Fig.\\ref{fig:2_3_c} illustrated the performance of ANC and ALE. At the beginning of the estimation, the noise is quite large. With the increasing of time index, the noise is almost eliminated. Therefore, the MSPE of ANC is 0.1098 which is approximately one third of the ALE. Observing the average plot, the ANC estimation is equal to the actual sine wave after 200 samples. Thus, the ANC has a high performance than the ALE.\n\\begin{figure}[htb]\n    \\centering\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.33\\textwidth}\n     \\centering\n     \\includegraphics[width=1.1\\textwidth]{fig/23/23c1.eps}\n    \\end{subfigure}\n    \\hspace{-0.1cm}\n    \\begin{subfigure}[b]{0.33\\textwidth}\n     \\centering\n     \\includegraphics[width=1.1\\textwidth]{fig/23/23c2.eps}\n    \\end{subfigure} \n    \\hspace{-0.1cm}\n    \\begin{subfigure}[b]{0.33\\textwidth}\n     \\centering\n     \\includegraphics[width=1.1\\textwidth]{fig/23/23c3.eps}\n    \\end{subfigure} \n    \\caption{Performance of ANC and ALE}\n    \\label{fig:2_3_c}\n\\end{figure}\n\\subsection{ANC for EEG data}\nIn order to remove the strong component at $50Hz$, a noisy sine wave $\\epsilon(n)$ with corresponding frequency is synthesised. Fig.\\ref{fig:2_3_d1} shows the spectrogram of the original \\texttt{POz} data with the rectangular window length of $2^{12}$ and 0.5 overlapping. There is an distinct line in yellow at $50Hz$ which should be removed.\n\\begin{figure}[htb]\n    \\centering\n    \\includegraphics[width=0.35\\textwidth]{fig/23/23d1.eps}\n    \\caption{EEG: Original Spectrogram}\n    \\label{fig:2_3_d1}\n\\end{figure}\\\\\nFig.\\ref{fig:2_3_d2} shows the effects ANC by learning rate $\\mu$ and $M$. When increasing the filter order $M$, the noisy component is getting to be removed more effectively. A under-modelling with small order causes residual of $50Hz$ component, while over-modelling results in excessively elimination. As to the $\\mu$, large learning rate will affect the component around $50Hz$, leading to the attenuation of interest signal.\n\\begin{figure}[htb]\n    \\centering\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d2.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d3.eps}\n    \\end{subfigure} \n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d4.eps}\n    \\end{subfigure}\n    \\\\\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d5.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d6.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d7.eps}\n    \\end{subfigure}\n    \\\\\n    \\hspace{-0.4cm} \n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d8.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d9.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.32\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d10.eps}\n    \\end{subfigure}\n    \\caption{ANC POz Spectrogram: Effect of $M$ and $\\mu$}\n    \\label{fig:2_3_d2}\n\\end{figure}\\\\\nFig.\\ref{fig:2_3_d3} shows the periodograms of original and ANC data at $\\mu=0.0001$ and $M=10$. Only the component at $50Hz$ is suppressed and others are nearly same compared with original signal.\n\\begin{figure}[htb]\n    \\centering\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.35\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d11.eps}\n    \\end{subfigure}\n    \\hspace{-0.4cm}\n    \\begin{subfigure}[b]{0.35\\textwidth}\n     \\centering\n     \\includegraphics[width=\\textwidth]{fig/23/23d12.eps}\n    \\end{subfigure}  \n    \\caption{Periodograms and Squared error of Original EEG and de-noising EEG}\n    \\label{fig:2_3_d3}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "ce416242c5bc5b69ec9c220f6a7d753e151f242b", "size": 10659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part2/23.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part2/23.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part2/23.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": 51.4927536232, "max_line_length": 743, "alphanum_fraction": 0.6838352566, "num_tokens": 3605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115012, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.6528460087036803}}
{"text": "\\section{Model Description}\nThe radiation pressure module contains two different models for calculating the effects of solar radiation pressure on spacecraft state. Both methods of calculating solar radiation pressure have simple implementations in Basilisk using basic coefficients and assumptions. The methods of arriving at these coefficients can be complex and making the coefficients time-varying to improve accuracy can greatly increase complexity. The cannonball method used here essentially follows the mathematics described by Vallado\\cite{vallado2001}.\n\n\\subsection{Radiation Pressure Model}\nRadiation is modeled by using the solar flux at one astronomical unit and scaling by distance from the sun relative to 1 AU. The solar flux at one AU is taken as :\n\\begin{equation}\nSF_{\\mathrm{AU}} = 1372.5398    \\bigg[\\frac{W}{m^2}\\bigg]\n\\end{equation}\n\\subsubsection{Cannonball Method}\nThe cannonball model assumes the spacecraft is a simple sphere.  It is the default SRP model when the {\\tt RadiationPressure} module is invoked.  The radiation pressure at 1AU, $p_{SR}$, can be taken as the solar flux divided by the speed of light. \n\\begin{equation}\n\tp_{SR} = \\frac{SF_{\\mathrm{AU}}}{c} \\bigg[\\frac{N}{m^2}\\bigg]\n\\end{equation}\nThen, a ``scaling factor'' can be determined. This ``scaling factor\" is equivalent to the magnitude of the solar radiation force divided by the distance between the spacecraft and the sun:\n\\begin{equation}\n\t\\frac{|\\mathbf{F}_{\\textrm{radiation}}|}{|\\mathbf{r}_{\\textrm{sun}}|} = \\frac{-c_{R}p_{SR}A_{\\odot}{AU}^2}{|\\mathbf{r}_{\\textrm{sun}}|^3} \\bigg[\\frac{N}{m}\\bigg]\n\\end{equation}\n$\\mathbf{r}_{\\textrm{sun}}$ is the vector from the spacecraft to the sun in the spacecraft body frame and $c_R$ is the reflectivity. This factor is then multiplied by the position vector from the spacecraft to the sun to get the force on the spacecraft due to solar radiation pressure.\n\\begin{equation}\n\t{\\mathbf{F}_{\\textrm{radiation}}} = \\frac{|\\mathbf{F}_{\\textrm{radiation}}|}{|\\mathbf{r}_{\\textrm{sun}}|}  \\mathbf{r}_{\\textrm{sun}} [N]\n\\end{equation}\nThe user must provide the coefficient of reflection and the equivalent area of the spacecraft to use this method.\\\\\n\\subsubsection{Table Look-up Method}\nFor the table look-up method, pre-determined values of torque and force acting on the spacecraft due to radiation pressure are given. It is required that these values be given at 1AU from the sun and with a corresponding direction vector from the spacecraft to the sun in the spacecraft body frame.\\\\\\\\\nThe look-up works by finding the direction vector in the given tables which most closely matches the current sun heading vector in the body frame. This is done by taking the maximum of the dot products of each lookup vector entry with the sun heading vector in the body frame. As a visual demonstration, \\ref{fig:lookupMethod} shows that for some current sun heading amongst the body vector entries 1 through 8, the force and torque data corresponding to entry 8 would be chosen due to its proximity to the current sun heading.\n\\begin{figure}[H]\n\t\\centerline{\n\t\t\\includegraphics[height=0.5\\textwidth, keepaspectratio]{Figures/lookupDiagram}}\n\t\\caption{Visual Description of Table Look-up Method}\n\t\\label{fig:lookupMethod}\n\\end{figure}\n\n\nThen, the corresponding force and torque values are taken from the table and scaled according to the magnitude of the spacecraft-sun position vector:\n\\begin{equation}\n{\\mathbf{F}_{\\textrm{radiation,scaled}}} = {\\mathbf{F}_{\\textrm{radiation}}}{\\Big(  \\frac{AU}{|\\textbf{r}_{\\textrm{sun}}|}  \\Big)}^{2} [N]\n\\end{equation}\n\\begin{equation}\n{\\bm{\\tau}_{\\textrm{radiation,scaled}}} = {\\bm{\\tau}_{\\textrm{radiation}}}{\\Big(  \\frac{AU}{|\\textbf{r}_{\\textrm{sun}}|}  \\Big)}^{2} [Nm]\n\\end{equation}\\\\\\\\\nMost important to the user of the table look-up method is the required input and format of data. Data must be recorded in XML format. As an example, see ../cube\\_lookup.xml (in the radiation pressure folder). Additionally, a utility script called parseSRPLookup.py is provided there to read the XML input into numpy arrays. Experienced users are welcome to store their data in their own format and load it into equivalent numpy arrays as they see fit.\\\\\\\\\nAn example of using the provided python script to load data is shown in test\\_radiationPressure.py. Note that this also requires import of the unitTestSupport library.\\\\\n\\subsubsection{Solar Eclipses}\nSolar eclipses are are detected by the basilisk eclipse module. The effects of the eclipse are calculated into a shadow factor, $F_{\\mathrm{s}}$, which is applied to the output forces and torques. \n\\begin{equation}\n\\mathbf{F}_{\\mathrm{out}} = F_{\\mathrm{s}}\\mathbf{F}_{\\mathrm{full\\_sun}}\n\\end{equation}\n\\begin{equation}\n\\bm{\\tau}_{\\mathrm{out}} = F_{\\mathrm{s}}\\bm{\\tau}_{\\mathrm{full\\_sun}}\n\\end{equation}", "meta": {"hexsha": "989bc2b60b69baa731cc748f8a4e182f26bab027", "size": 4827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/dynamics/RadiationPressure/_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/RadiationPressure/_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/RadiationPressure/_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": 96.54, "max_line_length": 534, "alphanum_fraction": 0.765278641, "num_tokens": 1292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6527672796681954}}
{"text": "\\problemname{Small Schedule}\n\n%% Image URL: https://www.pexels.com/photo/bandwidth-close-up-computer-connection-1148820/\n%% Image License: https://www.pexels.com/photo-license/\n\n\\illustration{0.33}{computer.jpg}{~}\n\nEverybody is into cloud computing these days, so quite a few different business models are being experimented with. You are trying a very simple one: you sell time on your machines in one of two batches called {\\em slots}. A customer can buy one second of CPU time or $Q$ seconds for some integer $Q$.\n\nEach time slot a customer purchases must be completed on a single machine, but you get to decide how to allocate the purchased time slots between machines.\n\nAfter coming back from a long vacation, you see that all of your machines are idle and a variety of orders have come in. To keep customers happy, you must decide how to distribute these requests between machines in a way that minimizes the time when the purchased time slots are finally all completed.\n\nWhat is the smallest amount of time in which you can complete all of the purchased time slots?\n\n\\section*{Input}\n\nThe input consists of a single line containing four integers $Q$~($2 \\leq Q \\leq 1\\,000$), which is the time needed to complete the longer batches, $M$~($1 \\leq M \\leq 1\\,000\\,000$), which is the number of machines owned by your company, $S$~($0 \\leq S \\leq 1\\,000\\,000$), which is the number of 1-second time slots purchased, and $L$~($0 \\leq L \\leq 1\\,000\\,000$), which is the number of $Q$-second time slots purchased.\n\n\\section*{Output}\n\nDisplay the smallest amount of time in which you can complete all of the purchased time slots.\n", "meta": {"hexsha": "7b5dd5ad64f58e531b599345256cccca2fc1b5b4", "size": 1630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/smallschedule/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/smallschedule/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/smallschedule/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": 70.8695652174, "max_line_length": 421, "alphanum_fraction": 0.7588957055, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301567, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6527501335071954}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\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{Complex Analysis}\n\\author{Linxuan Ma}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\newcommand{\\mo}[1]{\\lvert #1 \\rvert}\n\t\\newcommand{\\mos}[1]{\\lvert #1 \\rvert^2}\n\t\\newcommand{\\RR}{\\mathbb{R}}\n\t\\newcommand{\\p}{\\partial}\n\t\n\t\\abstract{Convex analysis is the domain of mathematics that investigates functions of complex numbers. Despite its frequent occurrence in applied science, IB Mathematics seems to decide on not covering anything other than \"haha $i^2$ is $-1$\", so here's my attempt at creating notes for it after binging an entire semester of complex analysis in one night and getting sick immediately the next day due to sleep deprivation. Balanced IB life.}\n\t\n\t\\section{Fundamentals}\n\tA complex number $z \\in \\mathbb{C}$ is a number of the form $$a + bi$$ where $a$ and $b$ are both real numbers.\n\t\n\t\\subsection{Definitions}\n\tThe imaginary number $i$ is defined as $\\sqrt{-1}$. Due to its equivalence with $\\sqrt{1}$, $i$ obeys all arithmetic laws that apply to root terms. Similarly, it coerces into $-1 \\in \\RR$ in the case of $i^2$.\n\t\n\tDue to the encapsulation of $z \\in \\mathbb{C}$ over real numbers $a$ and $b$, a complex function $f: \\mathbb{C} \\to \\mathbb{C}$ is isomorphic to $g: \\RR^2 \\to \\RR^2$. Trivially, by decomposition we obtain\n\t\\begin{gather*}\n\t\t\\Re: \\mathbb{C} \\to \\RR \\\\\n\t\t\\Im: \\mathbb{C} \\to \\RR\n\t\\end{gather*}\n\tcorresponding to retrieving real components $a$ and $b$.\n\t\n\tDeriving from $z \\in \\mathbb{C}$'s correspondence to a vector $\\vec{z} \\in \\RR$, the representation of a 2-dimensional coordinate can be concluded from $x$:\n\t\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t\\Re(z) \\\\ \\Im(z)\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tFrom such geometric representation, further vector-like properties can be defined (conjugate, modulus and argument) for $z \\in \\mathbb{C}$ with real part $a$ and imaginary part $b$:\n\t\n\t\\begin{gather*}\n\t\t\\overline{z} = a - bi \\\\\n\t\t\\mo{z} = \\sqrt{a^2 + b^2} \\\\\n\t\t\\arg z = \\arctan \\frac{b}{a}\n\t\\end{gather*}\n\t\n\tNote the isomorphism of the modulus-argument pair with the standard $a + bi$ form under the domain $-\\pi < \\theta \\leq \\pi$ for argument. In the remaining portion of this note, a complex number may take any of the following form:\n\t\n\t\\begin{enumerate}\n\t\t\\item Regular form: $a + bi$ where $a, b \\in \\RR$\n\t\t\\item Tuple form (equivalent to $a + bi$): $(a, b)$\n\t\t\\item Polar form (modulus $r$ and argument $\\theta$): $r(cos \\theta + i \\sin \\theta)$\n\t\\end{enumerate}\n\t\n\t\\subsection{Complex Arithmetic}\n\t\n\tTrivially, due to the nature of square roots:\n\t\n\t\\begin{gather*}\n\t\t(a, b) + (c, d) = (a + c, b + d) \\\\\n\t\t(a, b) - (c, d) = (a - c, b - d) \\\\\n\t\t(a, b) * (c, d) = (ac - bd, ad + bc) \\\\\n\t\t\\frac{(a, b)}{(c, d)} = \\frac{(a, b)(c, -d)}{(c, d)(c, -d)}\n\t\\end{gather*}\n\t\n\tConjugation is distributive over addition, subtraction, multiplication and division:\n\t\n\t\\begin{gather*}\n\t\t\\overline{z + w} = \\overline{z} * \\overline{w} \\\\\n\t\t\\overline{z - w} = \\overline{z} * \\overline{w} \\\\\n\t\t\\overline{z * w} = \\overline{z} * \\overline{w} \\\\\n\t\t\\overline{\\left(\\frac{z}{w}\\right)} = \\frac{\\overline{z}}{\\overline{w}}\n\t\\end{gather*}\n\t\n\tIt is clear that the complex conjugation $z \\to \\overline z$ is an automorphism of $\\mathbb{C}$ (an isomorphic endofunctor).\n\t\n\tTrivially, $z * \\overline z \\in \\RR$.\n\t\n\tRules regarding the polar representation can be trivially obtained via substitution of definitions:\n\t\n\t\\begin{gather*}\n\t\t\\mo{z * w} = \\mo{z} * \\mo{w} \\\\\n\t\t\\arg(z * w) = \\arg z + \\arg w\n\t\\end{gather*}\n\t\n\tModulus can be viewed as the distance of the represented point to the origin, and thereby the rule:\n\t\n\t\\begin{gather*}\n\t\t\\mo{z * w} \\leq \\mo{z} * \\mo{w}\n\t\\end{gather*}\n\t\n\t\\subsection{Simple Applications}\n\t\n\tThe following section explores rudimentary applications we can derive from the previously covered rules of complex numbers.\n\t\n\t\\subsubsection{Magma of Sums of Squares Under Multiplication}\n\t\n\tConsider the number theory problem:\n\t\\begin{center}\n\t\tWhich integers are sums of two squares?\n\t\\end{center}\n\t\n\tWith complex numbers, we realize that the integers that are the sum of two squares form a magma under multiplication.\n\t\\\\\\\\\n\t\\textbf{Proof.} There exists an rearrangement of terms in a product of sums of 2 squares such that: $$(a^2 + b^2)(c^2 + d^2) \\to (ac - bd)^2 (ad + bc)^2$$\n\tThe above transformation is derived from the complex number rules related to complex modulus:\n\t\n\t\\begin{gather*}\n\t\ta^2 + b^2 = \\mos{a + ib} \\\\\n\t\tc^2 + d^2 = \\mos{c + id}\n\t\\end{gather*}\n\tTherefore $(a^2 + b^2)(c^2 + d^2)$ can be written as:\n\t\n\t\\begin{align*}\n\t\t  & (a^2 + b^2)(c^2 + d^2) \\\\\n\t\t= & \\mos{(a + ib)(c + id)} \\\\\n\t\t= & \\mos{ac - bd + i(ad + bc)} \\\\\n\t\t= & (ac - bd)^2 + (ad + bc)^2\n\t\\end{align*}\n\t \n\tExtending from the proof above, consider two given sum of squares:\n\t\n\t\\begin{gather*}\n\t\t5 = 1^2 + 2^2 \\\\\n\t\t13 = 2^2 + 3^2\n\t\\end{gather*}\n\t\n\tBy multiplication we obtain: $$5 * 13 = 65$$\n\t\n\tNote that $65$ can also be represented as different sums of two squares: $1^2 + 8^2 = 4^2 + 7^2 = 65$. By writing the constituent of $5$ and $13$ as complex modulus, we obtain:\n\t\n\t\\begin{gather*}\n\t\t\\mos{1 + 2i} = 5 \\\\\n\t\t\\mos{2 + 3i} = 13\n\t\\end{gather*}\n\t\n\tBy multiplying $1 + 2i$ and $2 + 3i$ and conjugating one of them, we obtain:\n\t\n\t\\begin{gather*}\n\t\t(1 + 2i)(2 + 3i) = -4 + 7i \\\\\n\t\t(1 + 2i)(2 - 3i) = 8 + i\n\t\\end{gather*}\n\tcorresponding to the other two solution $1^2 + 8^2 = 65$ and $4^2 + 7^2 = 65$.\n\t\n\t\\subsubsection{Pythagorean Triples}\n\t\n\tAnother application of complex arithmetic relates to the Pythagorean theorem, easily generating a set of Pythagorean triples from complex numbers. Consider the Pythagorean theorem of edge $a, b, c$ where $c \\leq a + b$ in a right triangle: $$a^2 + b^2 = c^2$$\n\t\n\tConsider the modulus of an arbitrary complex number with integer real and imaginary parts, i.e. $a + bi$ where $a, b \\in \\mathbb{Z}$, then its modulus can be expressed as a single square root of an integer. Therefore, the modulus of the square of any $a + bi$ of integer coordinate is an integer:\n\t\\begin{align*}\n\t\t\\mo{a + bi} &= \\sqrt{a^2 + b^2} \\\\\n\t\t(a + bi)^2 &= a^2 - b^2 + (2ab)i  \\\\\n\t\t\\mo{(a + bi)^2} &= \\mo{a + bi} * \\mo{a + bi} \\\\\n\t\t& = a^2 + b^2\n\t\\end{align*}\n\t\n\tTherefore, we obtain a generalized formula of the Pythagorean triples over the complex plane for any integer substitution of $a$ and $b$:\n\t\\begin{align*}\n\t\ta &= a^2 - b^2 \\\\\n\t\tb &= 2ab \\\\\n\t\tc &= a^2 + b^2\n\t\\end{align*}\n\t\n\t\n\t\\subsubsection{Quaternions}\n\t\n\tA feasible expansion of the complex number system into $\\RR^3$ has yet to be proposed. However, there exists a $\\RR^4$ expansion, the quaternions, of the complex plane.\n\t\n\tIn the quaternion system, a complex number $a + bi$ is expanded into $a + bi + cj + dk$, where the multiplication of $i$, $j$ and $k$ is not communicative:\n\t\\begin{gather*}\n\t\ti^2 = j^2 = k^2 = ijk = -1 \\\\\n\t\tij = k = -ji \\\\\n\t\tjk = i = -kj \\\\\n\t\tki = j = -ik\n\t\\end{gather*}\n\t\n\tSimilar to finding the inverse of a complex number $a + bi$ (multiplying nominator and denominator by its conjugate):\n\t$$\\frac{1}{a + bi} = \\frac{a - bi}{a^2 + b^2}$$\n\t, there also exists an inverse for a quaternion:\n\t$$\\overline{a + bi + cj + dk} = a - bi - cj - dk$$\n\t\n\tThe product of a quaternion with its conjugate is:\n\t\\begin{align*}\n\t\tz\\overline{z} = a^2 + b^2 + c^2 + d^2\n\t\\end{align*}\n\t\n\tNote that the cross terms (such as $bcij$ and $bcji$) in the above equation vanish due to the non-commutativity ($ij$ = $-ji$).\n\t\n\tThe inverse of a quaternion can thus be found:\n\t$$\\frac{1}{a + bi + cj + dk} = \\frac{a - bi - cj - dk}{a^2 + b^2 + c^2 + d^2}$$\n\t\n\tAll none-zero quaternions have inverses, similar to complex numbers.\n\t\n\t\\section{Roots}\n\t\n\tFinding roots of complex numbers is significant in complex analysis. The square root of $x \\in \\RR$ can be represented as a complex number, such as:\n\t\\begin{align*}\n\t\t\\sqrt{10} &= \\sqrt{10} + 0i \\\\\n\t\t\\sqrt{-5} &= \\sqrt{5}i\n\t\\end{align*}\n\t\n\tDue to the complications of working with the cartesian form of complex numbers in multiplication and division, the majority of calculations below feature $z \\in \\mathbb{C}$ in the exponential form, namely $re^{i\\theta}$. This trivially corresponds to the polar form $r(\\cos \\theta + i\\sin \\theta)$ as dicussed previously.\n\t\n\tThe conversion from cartesian to polar can be roughly described as (neglecting the domain restrictions):\n\t\\begin{align*}\n\t\tr &= \\mo{z}\n\t\\end{align*}\n\t\n\t\\subsection{Geometric Interpretation of Multiplication}\n\t\n\tTo better represent multiplication over the complex plane, we shall express multiplication in complex number's polar \n\t\\begin{center}\n\t\t\\begin{tikzpicture}\n\t\t\t\\coordinate (o) at (0, 0);\n\t\t\t\\coordinate (a) at (1, 0);\n\t\t\t\\coordinate (b) at (2, 1);\n\t\t\n\t\t\t\\draw[thin,gray!40] (-3, -3) grid (3, 3);\n\t\t\t\\draw[->] (-3, 0)--(3, 0) node[right]{Real};\n\t\t\t\\draw[->] (0, -3)--(0, 3) node[above]{Imaginary};\n\t\t\t\\draw[line width=2pt,blue,-stealth](0, 0)--(2, 1) node[anchor=south west]{$a + bi$};\n\t\t\t\n\t\t\t\\pic [draw, -, \"$\\theta$\", angle eccentricity=2] {angle = a--o--b};\n\t\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tFrom the above illustration we can conclude that:\n\t\\begin{align*}\n\t\tz &= a + bi \\\\\n\t\tr &= \\mo{z} \\\\\n\t\tx &= r * \\cos \\theta \\\\\n\t\ty &= r * \\sin \\theta \\\\\n\t\t\\frac{y}{x} &= \\tan \\theta\n\t\\end{align*}\n\t\n\tConsider the set of complex numbers $S^1$ ($S$ for sphere, and $1$ for 1-dimensional) whose modulus is 1. This forms a group over multiplication, i.e:\n\t\\begin{gather*}\n\t\t\\forall z_1, z_2 \\in S^1,\\ \\mo{z_1} = \\mo{z_2} = 1 \\\\\n\t\tz_1 * z_2 = 1 \\\\\n\t\t\\mo{z_1^{-1}} = 1\n\t\\end{gather*}\n\t\n\tNote that every complex number can be written in $r * z_i$ for a specific $z_i \\in M$. In other words, there exists a unique isomorphism between any non-zero complex number and a $z_i$ scaled by a constant $r$: $$a + bi \\cong r * z_i \\ \\text{for}\\ a, b, r \\in \\RR,\\ z_i \\in S^1$$\n\t\n\t\n\t$\\mathbb{C}^*$ (non-zero complex number) is the product of $\\RR_{>0} \\times S^1$, and thus $$r_1 e^{i\\theta_1} * r_2 e^{i\\theta_2} = r_1r_2e^{i(\\theta_1 + \\theta_2)}$$\n\tcan be easily deduced. This also hints complex number's proficiency at representing rotations of $\\RR^2$ (and therefore the existence of quaternions to describe rotations in $\\RR^3$).\n\t\n\t\\textbf{Warning:} When multiplying complex numbers on a computer, care must be taken to map the polar angles to $(-\\pi, \\pi]$ when converting from cartesian form to polar form.\n\t\n\t\\subsection{Square Root of $z \\in \\mathbb{C}$}\n\t\n\tWith the aforementioned geometric representation of complex multiplication, $\\sqrt{z}$ for $z \\in \\mathbb{C}$ can be trivially obtained as:\n\t\\begin{gather*}\n\t\t\\sqrt{z} = \\sqrt{re^{i\\theta}} = \\sqrt{r}e^{i\\frac{\\theta}{2}}\n\t\\end{gather*}\n\t\n\tThere exists two solutions for the square root of a complex number. Therefore, in order to preserve continuity, we realize that $\\sqrt{e^{i\\pi}}$ and $\\sqrt{e^{-i\\pi}}$ should be equal, yet the continuity of the square root function insists that:\n\t\\begin{align*}\n\t\t\\sqrt{e^{i\\pi}} &= i \\\\\n\t\t\\sqrt{e^{-i\\pi}} &= -i\n\t\\end{align*}\n\t\n\tThere exists no solution to this inequality; however, since we normally only consider the domain $(-\\pi, \\pi]$, this inconsistency is not \\textit{that} significant.\n\t\n\t\\subsection{$n$-th Root of $z \\in \\mathbb{C}$}\n\t\n\tConsider the complex number $3 + 4i$ and its fifth root. Its modulus is $5$, and therefore $\\mo{\\sqrt[5]{3 + 4i}} = 5$. Interestingly, there exists multiple solutions for $\\arg \\sqrt[5]{3 + 4i}$, as:\n\t$$\\frac{\\theta}{5},\\ \\frac{\\theta + 2\\pi}{5},\\ \\frac{\\theta + 4\\pi}{5},\\ \\dots$$\n\tare all valid solutions to $\\arg \\sqrt[5]{3 + 4i}$ (since the original $3 + 4i$ can also be represented with argument of $\\theta$, $\\theta + 2\\pi$, $\\theta + 4\\pi$, etc). This behavior is distinct from taking an odd root of a real number, and therefore introduces complications.\n\t\n\tInterestingly, the argument of the fifth root of $3 + 4i$, when plotted on the complex plane, forms a pentagon:\n\t\\begin{center}\n\t\\begin{tikzpicture}\n\t\t\\coordinate (o) at (0, 0);\n\t\t\\coordinate (a) at (1, 0);\n\t\t\\coordinate (b) at (2, 1);\n\t\n\t\t\\draw[thin,gray!40] (-3, -3) grid (3, 3);\n\t\t\\draw[->] (-3, 0)--(3, 0) node[right]{Real};\n\t\t\\draw[->] (0, -3)--(0, 3) node[above]{Imaginary};\n\t\t\n\t\t\\draw[red, very thick] (0, 0) circle [radius=1.380];\n\t\t\\node[red] at (-1.5, 1.75) {$\\mo{z} = \\sqrt{5},\\ z \\in \\mathbb{C}$};\n\t\t\n\t\t\\draw[line width=2pt, blue, -stealth](0, 0)--(1.36, 0.254) node[anchor=south west]{$\\sqrt{5}e^{i\\frac{\\theta}{5}}$};\n\t\t\\draw[line width=2pt, blue, -stealth](0, 0)--(0.177, 1.369) node[anchor=south west]{$\\sqrt{5}e^{i\\frac{\\theta + 2\\pi}{5}}$};\n\t\t\\draw[line width=2pt, blue, -stealth](0, 0)--(-1.247, 0.591) node[anchor=south east]{$\\sqrt{5}e^{i\\frac{\\theta + 4\\pi}{5}}$};\n\t\t\\draw[line width=2pt, blue, -stealth](0, 0)--(-0.948, -1.003) node[anchor=north east]{$\\sqrt{5}e^{i\\frac{\\theta + 6\\pi}{5}}$};\n\t\t\\draw[line width=2pt, blue, -stealth](0, 0)--(0.661, -1.211) node[anchor=north west]{$\\sqrt{5}e^{i\\frac{\\theta + 8\\pi}{5}}$};\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tThis pattern generalizes across the $n$-th roots of a complex number, forming a regular $n$-sided polygon around the origin with radius of $\\sqrt[n]{\\mo{z}}$.\n\t\n\tTherefore, any $z \\in \\mathbb{C}$ has $n$-th root. Inductively, the polynomial $z^n - a$ always has a root.\n\t\n\tFor more complicated polynomials there also exists a complex root,  but won't be proved in this section: $$z^n + a_{n-1}z^{n - 1} + a_{n - 2}^2z^{n - 2} + \\dots + a_1z + a_0 = 0$$\n\t\n\t$\\mathbb{C}$ is therefore \"algebraically closed\".\n\t\n\tRecall the formula:\n\t\\begin{align*}\n\t\t\\cos 2\\theta &= \\cos^2 \\theta - sin^2 \\theta \\\\\n\t\t\\cos 3\\theta &= \\cos^3 \\theta - 3\\cos \\theta \\sin^2 \\theta\n\t\\end{align*}\n\tand so on. The above formula can be obtained by the binomial theorem:\n\t\\begin{gather*}\n\t\t\\cos(n\\theta) + i\\sin(n\\theta) = (\\cos \\theta + i \\sin\\theta)^n\n\t\\end{gather*}\n\t\n\tThe above formula correspond to the the geometric interpretation of complex multiplication: addition of the arguments corresponds to multiplication of the numbers (given that modulus is $1$).\n\t\n\tThe right hand side can be expanded via the binomial theorem, resulting in:\n\t\\begin{gather*}\n\t\t\\cos^n \\theta + in\\cos^{n - 1}\\theta\\sin\\theta - \\binom{n}{2} \\cos^{n - 2}\\theta \\sin^2 \\theta + \\dots\n\t\\end{gather*}\n\twhich, after applying the above to $\\Re$, will equal to the original $\\cos(n\\theta)$.\n\t\n\t\\section{Exp, Log and Trigonometry}\n\t\n\tThe exponential function can be defined as a power series that converges:\n\t$$\\exp(z) = 1 + z + \\frac{z^2}{2!} + \\frac{2^3}{3!} + \\dots$$\n\t\n\tIf a series of complex numbers $a_0 + a_1 + a_2 + \\dots$ is convergent, then $\\Re(a_0) + \\Re(a_1) + \\dots$ and $\\Im(a_0) + \\Im(a_1) + \\dots$ also converges due to $\\mo{\\Re(z)} \\leq \\mo{z}$ and $\\mo{\\Im(z)} \\leq \\mo{z}$.\n\t\n\t\\subsection{The Exponential Function}\n\tProperties of the exponential function includes:\n\t\\begin{gather*}\n\t\t\\exp(z_1 + z_2) = \\exp(z_1) * \\exp(z_2)\n\t\\end{gather*}\n\twhich can be proven with:\n\t\\begin{align*}\n\t\t\\sum_{n=0}^\\infty \\frac{(z_1 + z_2)^n}{n!} &= \\sum_{n, m=0}^\\infty \\frac{\\binom{n}{m}z_1^m z_2^{n - m}}{n!} \\\\\n\t\t&= \\sum_{n, m=0}^\\infty \\frac{z_1^m}{m!}*\\frac{z_2^{n-m}}{(n-m)!} \\\\\n\t\t&= \\sum_{n, m=0}^\\infty \\frac{z_1^m}{m!}*\\frac{z_2^n}{n!} \\\\\n\t\t&= \\exp(z_1) * \\exp(z_2)\n\t\\end{align*}\n\t\n\tDefining $z \\in \\mathbb{C}$ as $z = a + bi$, $e^z = e^{a + bi} = e^a*e^{bi}$. Note that the left section $e^a \\in \\RR$, while $e^{bi} \\in \\mathbb{C}$. We can rewrite this as:\n\t\\begin{align*}\n\t\t\\exp(bi) &= 1 + bi + \\frac{b^2i^2}{2!} + \\frac{b^3i^3}{3!} + \\dots \\\\\n\t\t&= 1 + bi - \\frac{b^2}{2!} - \\frac{-b^3i}{3!} + \\frac{b^4}{4!} + \\dots\n\t\\end{align*}\n\t\n\tNote that the series $1,\\ -\\frac{b^2}{2!},\\ \\frac{b^4}{4!},\\ \\dots$ is just the series for $\\cos(b)$, while the series $bi,\\ -\\frac{b^3i}{3!},\\ \\frac{b^5i}{5!},\\ \\dots$ is the series for $i * \\sin(b)$.\n\t\n\tTherefore, Euler's identity can be deduced from the above equation: \n\t\\begin{align*}\n\t\te^{i\\theta} &= \\cos \\theta + i \\sin \\theta \\\\\n\t\te^{i\\pi} &= -1 \\\\\n\t\te^{2i\\pi} &= 1 \\\\\n\t\te^{2ni\\pi} &= 1,\\ n \\in \\mathbb{Z}\n\t\\end{align*}\n \t\t\n \tExponentials can also be viewed as a homomorphism of groups (note that the mapping is surjective but not injective): $$\\exp(z_1 + z_2) = \\exp(z_1)\\exp(z_2)$$\n \tfrom complex numbers under addition to complex numbers under multiplication (in polar coordinates): $$\\mathbb{C} \\xrightarrow{\\exp} \\mathbb{C}^*$$\n\n\tThe above is satisfied if the modulus of the object being mapped is non-zero. In addition, observe that:\n\t\\begin{align*}\n\t\tr(\\cos \\theta + i\\sin \\theta) &= r * \\exp(i\\theta) \\\\\n\t\t&= \\exp(\\ln r) * \\exp(i\\theta) \\\\\n\t\t&= \\exp(\\ln r + i\\theta)\n\t\\end{align*}\n\ttherefore the homomorphism is satisfied for $r \\neq 0$.\n\t\n\tIncidentally, there also exists a homomorphism of real numbers $\\RR$ under addition to $\\RR$ under multiplication that is injective yet not surjective (trivial).\n\t\n\t\\subsection{The Logarithm Function}\n\t\n\tThe $\\ln$ function is the inverse of the exponential function e.g. solving for $a$ and $b$ in $\\exp(a + bi) = z$ becomes $a + bi = \\ln z$. Since the polar representation of $a + bi$ is $r(\\cos \\theta + i\\sin \\theta)$, it can be deduced that:\n\t\\begin{align*}\n\t\t\\exp(a) &= r = \\mo{z} \\\\\n\t\t\\theta &= \\arg z\n\t\\end{align*}\n\t\n\tNote that $\\ln(z)$ is not unique (only defined up to multiples of $2\\pi i$). The logarithm function can't be defined continuously for all non-zero complex numbers (due to the ambiguity in the argument of the complex number):\n\t$$z_1^{z_2} = \\exp(z_2 * \\ln(z_1))$$\n\tis only well-defined when:\n\t\\begin{enumerate}\n\t\t\\item $z_1 > 0$ and $z_1 \\in \\RR$ (trivial)\n\t\t\\item $z_2 \\in \\mathbb{Z}$ (ambiguity is unimpactful as $z_1^{z_2} = 1$)\n\t\\end{enumerate}\n\t\n\t\\subsection{Trigonometric Functions}\n\t\n\tThe $\\cos$ function and $\\sin$ function are just special cases for the exponential function:\n\t\\begin{align*}\n\t\te^{iz} &= \\cos z + i\\sin z \\\\\n\t\te^{-iz} &= \\cos z - i\\sin z \\\\\n\t\t\\frac{e^{iz} + e^{-iz}}{2} &= \\cos z\n\t\\end{align*}\n\t\n\tThe same conclusion is arrived for defining $\\cos$ as the power series derived from the definition (in series form) of the exponential function.\n\t\n\tSimilarly: $$\\frac{e^{iz} + e^{-iz}}{2} = \\cos z$$\n\t\n\tIn addition, identities of the trigonometric functions follow the identity of the exponential function:\n\t\\begin{align*}\n\t\t\\cos(\\theta_1 + \\theta_2) &= \\cos \\theta_1 \\cos \\theta_2 - \\sin \\theta_1 \\sin \\theta_2 \\\\\n\t\t\\exp(z_1 + z_2) &= \\exp(z_1) * \\exp(z_2) \\text{ (substitution)}\n\t\\end{align*}\n\t\n\tNote that the $\\sin$ and $\\cos$ functions are defined over the entire complex plane due to its correspondence with Euler's identity.\n\t\n\t\\subsection{Applications of Complex Trigonometry}\n\t\n\tDue to the flexibility of trigonometric functions in the complex plane, there are numerous applications of it. The following section lists a few simple and significant ones.\n\t\n\t\\subsubsection{Differential Equation}\n\t\n\tConsider the linear differential equation: $$a\\frac{d^2y}{dx^2} + b\\frac{dy}{dx} + cy = 0$$\n\tWith complex numbers, the above can be solved trivially:\n\t\\begin{align*}\n\t\ty &= e^{\\lambda x} \\\\\n\t\ta\\lambda^2e^{\\lambda x} + b\\lambda e^{\\lambda x} + ce^\\lambda &= 0 \\\\\n\t\ta \\lambda^2 + b\\lambda + c &= 0\n\t\\end{align*}\n\t\n\t$\\lambda$ can be solved with a simple quadratic equation. Consider the example: $$\\frac{d^2 y}{dx} + 2\\frac{dy}{dx} + 2y = 0$$\n\tBy implementing the concept above, we obtain:\n\t\\begin{align*}\n\t\t\\lambda^2 + 2\\lambda + 2 &= 0 \\\\\n\t\t\\lambda = -1 \\pm \\sqrt{1^2 - 2} &= -1 \\pm i \\\\\n\t\t\\exp((1 + i)x),\\ \\exp((1 - i)x) &= y\n\t\\end{align*}\n\t\n\t\\subsubsection{Fourier Series}\n\t\n\tWith a periodic function $f$: \n\t\\begin{gather*}\n\t\tf(x) = f(2\\pi + x)\n\t\\end{gather*}\n\t$f$ can be written as a sum of $sin$ and $cos$ functions (thus simplified with complex numbers):\n\t\\begin{align*}\n\t\tf(x) &= \\sum_{n > 0} a_n \\sin(nx) + \\sum_{n \\geq 0} b_n \\cos{nx} \\\\\n\t\t&= \\sum_{n \\in \\mathbb{Z}} c_n e^{inx}\n\t\\end{align*}\n\t\n\t\\subsection{Tangent of $z$}\n\t\n\tThe regular difinition for the trigonometric function $\\tan$ is $\\sin$ divided by $\\cos$:\n\t\\begin{gather*}\n\t\t\\tan z = \\frac{\\sin z}{\\cos z}\n\t\\end{gather*}\n\t\n\tDue to Euler's indetity, $\\tan$ can be represented as:\n\t\\begin{gather*}\n\t\t\\tan z = \\frac{1}{i} * \\frac{e^{iz} - e^{-iz}}{e^{iz} + e^{-iz}}\n\t\\end{gather*}\n\t\n\tExcept near the real axis, the tangent function is almost constant around $\\tan z = i$.\n\t\n\t\\section{Complex Derivatives}\n\t\n\tComplex derivatives refer to the result of differentiating a complex function.\n\t\n\t\\subsection{Real Derivatives of Complex Functions}\n\t\n\tIn real analysis, we recall real differentiation: $$f: \\RR \\to \\RR$$\n\t\n\t$f$ is differentiable at $x_0 \\in \\RR$ if $f$ is approximately linear at $x_0$, i.e. $f(x) = f(x_0) + a(x - x_0)$ where $a$ is the slope at $x$. This is derived from the definition of derivatives.\n\t\n\tAn alternative way of defining derivatives (or the more commonly known one) is: $$\\lim_{dx \\to 0} \\frac{f(x) - f(x_0)}{dx}$$ where $dx = x - x_0$.\n\t\n\tConsider $w(z) = u(z) + iv(z)$ is a function of $z = x + yi$, where $u$, $v$, $x$ and $y$ are real values. $u$ and $v$ can be viewed as functions over two real values that resembles the way in which we deduce derivatives for real functions:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\tu(x, y) \\\\ v(x, y)\n\t\t\\end{bmatrix} = \n\t\t\\begin{bmatrix}\n\t\t\tu(x_0, y_0) \\\\ v(x_0, y_0)\n\t\t\\end{bmatrix} +\n\t\t\\begin{bmatrix}\n\t\t\ta & b \\\\c & d\n\t\t\\end{bmatrix}\n\t\t\\begin{bmatrix}\n\t\t\tx - x_0 \\\\ y - y_0\n\t\t\\end{bmatrix}  + \\epsilon\n\t\\end{equation*}\n\twhere $\\epsilon$ denotes the error value as the (small)  cost $$\\lim_{(x, y)  \\to (x_0, y_0)}\\frac{\\mo{\\epsilon}}{\\mo{(x, y) - (x_0, y_0)}} \\to 0$$\n\tof such linear approximation.\n\t\n\t$w$ being differential at $z$ implies that $w$ can be approximated by the above linear function.\n\t\n\tThe matrix of $a$, $b$, $c$ and $d$ can be rewritten as a matrix of partial derivatives:\n\t\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t\\frac{\\p u}{\\p x} & \\frac{\\p u}{\\p y} \\\\\n\t\t\t\\frac{\\p v}{\\p x} & \\frac{\\p v}{\\p y}\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tThe above function for $w$ only defines the real differentiability of a function.\n\t\n\t\\subsection{Complex Derivatives}\n\t\n\tConsider $w(z) = u(z) + iv(z)$ and $z = x + yi$ in respect of the complex plane: $$w(z) = w(z_0) + A(z - z_0) + \\epsilon$$\n\twhere $\\epsilon$ is less than linear (same as above), $A \\in \\mathbb{C}$.\n\t\n\tThe transformation by $A$ can be described in the matrix form:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t\\Re(A) & -\\Im(A) \\\\ \\Im(A) & \\Re(A)\n\t\t\\end{bmatrix}\n\t\t\\begin{bmatrix}\n\t\t\tx - x_0 \\\\ y - y_0\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\tor via direct definition: $$A(x + yi) = x\\Re(A) - y\\Im(A) + i(x\\Im(A) +y\\Re(A))$$\n\t\n\t$w$ is only differentiable as a complex function when $A$ is equivalent with the differentiation matrix of $w$ over real values:\n\t\\begin{align*}\n\t\t\\Re(A) &= \\frac{\\p u}{\\p x} = \\frac{\\p v}{\\p y} \\\\\n\t\t\\Im(A) &= \\frac{\\p v}{\\p x} = -\\frac{\\p u}{\\p y}\n\t\\end{align*}\n\t\n\tThe above equation is referred to as the \\textit{Cauchy-Riemann Equation}, the condition under which a real function is complex differentiable (if and only if).\n\t\n\tIn terms of limits, $A$ can be represented as: $$A = \\lim_{dz \\to 0} \\frac{w(z) - w(z_0)}{dz},\\ dz = z-z_0$$\n\t\n\t\\subsection{Holomorphic Functions}\n\t\n\tSuppose $w$ is a complex function of $z \\in U \\subseteq \\mathbb{C}$ where $U$ is an open set, $w$ is \\textit{holomorphic} if it is complex differentiable for all points on $U$ (therefore continuous and holds real derivatives that satisfies the Cauchy-Riemann equation). A holomorphic function is also infinitely differentiable. The concept of holomorphic function is crucial to complex analysis.\n\t\n\tAnother representation of the Cauchy-Riemann equation is to define the partial derivatives to $z$ and $\\overline{z}$ respectively, referred to as the \\textit{Wirtinger Derivatives}. The derivatives are defined as:\n\t\\begin{align*}\n\t\t\\frac{\\p}{\\p z} &= \\frac{1}{2}\\left(\\frac{\\p}{\\p x} - i\\frac{\\p}{\\p y}\\right) \\\\\n\t\t\\frac{\\p}{\\p \\overline{z}} &= \\frac{1}{2}\\left(\\frac{\\p}{\\p x} + i\\frac{\\p}{\\p y}\\right)\n\t\\end{align*}\n\t\n\tThe reasoning behind the definition is that:\n\t\\begin{align*}\n\t\t\\frac{\\p z}{\\p z} = 1&,\\ \\frac{\\p \\overline{z}}{\\p z} = 0 \\\\\n\t\t\\frac{\\p z}{\\p \\overline{z}} = 0&,\\ \\frac{\\p \\overline{z}}{\\p \\overline{z}} = 1\n\t\\end{align*}\n\t\n\tInformally, holomorphic can be understood as a function that \"depends on $z$ but not $\\overline{z}$\";  however, such statement is meaningless and merely provides an understanding as a function that depends on $z$ is not dependent on $\\overline{z}$ (definition of complex conjugation) (more explanations on this in the succeeding sections).\n\t\n\tSuppose $f$ and $g$ are holomorphic on open set $U$, then $f + g$, $f - g$, $f * g$, $f / g$ and $f.g$ are all holomorphic.\n\t\n\tTherefore, the trigonometric functions as well as $\\exp$ and $\\ln$ are all differentiable over well-defined points. Surprisingly, $\\frac{df}{dz}$ is holomorphic if $f$ is holomorphic. This is distinct from the properties of real functions.\n\t\n\tSome examples of functions that are not holomorphic: $\\Re(z)$, $\\Im(z)$, $\\mo{z}$, $\\mos{z}$, $\\overline{z}$.\n\t\n\tConsider the function $f(z) = z^2$. $f$ is holomorphic in $\\mathbb{C}$, and can be shown with the Cauchy-Riemann equation. We start by rewriting $f$:\n\t\\begin{align*}\n\t\tf(z) &= z^2 = (x + yi)^2 \\\\\n\t\t&= x^2 + 2xyi - y^2 \\\\\n\t\t&= (x^2 + y^2) + i(2xy)\n\t\\end{align*}\n\t\n\tRecall the Cauchy-Riemann equation:\n\t\\begin{align*}\n\t\tf(z) &= u(x, y) + iz(x, y) \\\\\n\t\t\\frac{\\p u}{\\p x} &= \\frac{\\p v}{\\p y} \\\\\n\t\t\\frac{\\p u}{\\p y} &= -\\frac{\\p v}{\\p x}\n\t\\end{align*}\n\t\n\tThe resulting equation from transforming $f(z) = z^2$ can be pattern matched with the Cauchy-Riemann equation:\n\t\\begin{align*}\n\t\tu(x, y) &= x^2 - y^2 \\\\\n\t\tv(x, y) &= 2xy\n\t\\end{align*}\n\t\n\tTherefore:\n\t\\begin{align*}\n\t\t\\frac{\\p u}{\\p x} &= \\frac{\\p v}{\\p y} = 2x \\\\\n\t\t\\frac{\\p u}{\\p y} &= -2y \\\\\n\t\t\\frac{\\p v}{\\p x} &= 2y\n\t\\end{align*}\n\tThe above shows that $f(z) = z^2$  is indeed holomorphic.\n\t\n\t\\section{Harmonic Functions}\n\t\n\tRecall the definition of complex function $w(z) = u(z) + iv(z)$ where $z$ is complex. Given a function $u$ of $x,\\ y \\in \\mathbb{C}$, there exists no way to find a holomorphic $w$ such that $u(z) = \\Re(w(z))$. If $w$ is holomorphic, it satisfies the Cauchy-Riemann equation. Consider the equation after differentiating with respect to $x$:\n\t\\begin{align*}\n\t\t\\frac{\\p}{\\p x} \\frac{\\p u}{\\p x} &= \\frac{\\p}{\\p x} \\frac{\\p v}{\\p y} \\\\\n\t\t\\frac{\\p^2 u}{\\p x^2} &= \\frac{\\p^2 v}{\\p x \\p y} = \\frac{-\\p^2 u}{\\p y^2}\n\t\\end{align*}\n\t\t\n\tFrom the equation it can be concluded that:\n\t$$\\frac{\\p^2 u}{\\p x^2} + \\frac{\\p^2 u}{\\p y^2} = 0$$\n\t\n\tThe above equation is referred to as the \\emph{Laplace equation}, and functions that satisfy such equation is a \\emph{harmonic equation}. The Laplace equation can be written in terms of the Laplacian operator: $$\\nabla(u) = \\frac{\\p^2 u}{\\p x^2} + \\frac{\\p^2 u}{\\p y^2}$$\n\t\n\tTo find all harmonic polynomials in the cartesian plane, we start by taking complex polynomials of $z$ and take their real and imaginary part:\n\t\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}[t]{lccccc}\n\t\\toprule\n\t\t$$ & $1$ & $z$ & $z^2$ & $z^3$ & $\\dots$ \\\\\n\t\\midrule\n\t\t$\\Re$ & $1$ & $x$ & $x^2 - y^2$ & $x^3 - 3xy^2$ & --\\\\\n\t\t$\\Im$ & -- & -- & $2xy$ & $3x^2y - y^3$ & -- \\\\\n\t\\bottomrule\n\t\\end{tabular}\n\t\\end{table}\n\t\n\tAny linear combination of harmonic polynomials is harmonic. The above table illustrates the basis of all harmonic polynomials.\n\t\n\tAs another example, consider the holomorphic function $ze^z$, its real part is $e^x(x*\\cos y - y*\\sin y)$. From the above, we conclude that for any holomorphic function $w$, $\\Re \\circ w$ is a harmonic function.\n\t\n\tSometimes a harmonic function $u$ is also the real part of some holomorphic function $w(z) = u(z) + iv(z)$. This depends on the open set $U \\subseteq \\mathbb{C}$. Notice the Cauchy-Riemann equation determines $v$ up to constant, as the partial derivative of $v$ with respect to $x$ and $y$ vanishes.\n\t\n\tSuppose real functions $f$ and $g$ each of the domain $x,\\ y$. The equation:\n\t\\begin{align*}\n\t\t\\frac{\\p v}{\\p x} &= f \\\\\n\t\t\\frac{\\p v}{\\p y} &=g\n\t\\end{align*}\n\tcan only be solved under the condition: $$\\frac{\\p f}{\\p y} = \\frac{\\p g}{\\p x}$$\n\t\n\tAs an example, consider rectangle $U$ containing the origin $(0, 0)$, and $v(0, 0) = 0$.\n\t\n\\end{document}", "meta": {"hexsha": "2c056f0719b2ab447fac4be8758ed8e3602324ae", "size": 28212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "complex-analysis/complex-analysis.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": "complex-analysis/complex-analysis.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": "complex-analysis/complex-analysis.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": 45.1392, "max_line_length": 443, "alphanum_fraction": 0.6448674323, "num_tokens": 10133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6527501322757371}}
{"text": "\\section{The Fundamental Group}\r\n\\subsection{Basic Ideas}\r\nFix a space $X$ and a point $x_0\\in X$.\r\nWe consider loops based at $x_0$, i.e. maps $\\gamma:I\\to X$ with $\\gamma(0)=\\gamma(1)=x_0$.\r\n\\begin{example}\r\n    We can take $X=\\mathbb R^2\\setminus{(0,0)}$ and $x_0\\in X$.\r\n    We can take $\\gamma$ to be a loop that doesn't come near $(0,0)$ at all, or one that encloses it.\r\n\\end{example}\r\nThere can be many loops satisfying these conditions, of course, but is it necessary to consider all of them differently?\r\nFor example, we certainly wish to consider two loops to be the same if one can become the other by a ``small perturbation''.\\\\\r\nTo do this, we will define a notion of equivalence relationship characterising this ``equal after perturbation'' condition.\r\nThe fundamental group of $X$ at $x_0$, as a set, will be the set of equivalence classes of loops defined in this way.\\\\\r\nBut how would we make this a group?\r\nCertainly, we want a group operation defined there.\r\nPick two loops starting and finishing at $x_0$, we want to define their product as the loop that first goes through one loop, then the other.\r\nAs one expect, this may or may not be commutative, but we do expect it to be associative and has the obvious identity and inverse.\r\nMore importantly, we do not yet know if it is well defined on the equivalence class of loops.\r\nSo we need some technicalities.\r\n\\subsection{Homotopy}\r\n\\begin{definition}\r\n    Let $f_0,f_1:X\\to Y$ be maps.\r\n    A homotopy between $f_0$ and $f_1$ is a map $F:X\\times I\\to Y$ such that $F(x,0)=f_0(x)$ and $F(x,1)=f_1(x)$.\r\n    We often write $f_t(x)=F(x,t)$ to represent the interpretation of $F$ as some kind of deformation.\\\\\r\n    If such a map exists for $f_0,f_1$, we say $f_0$ is homotopic to $f_1$, written as $f_0\\simeq_F f_1$ or simply $f_0\\simeq f_1$.\r\n\\end{definition}\r\n\\begin{example}\r\n    If $Y\\subset\\mathbb R^2$ is convex, then any maps $f_0,f_1:X\\to Y$ are homotopic by taking $F(x,t)=tf_0(x)+(1-t)f_1(x)$.\r\n\\end{example}\r\n\\begin{definition}\r\n    For $f_0,f_1:X\\to Y$ and $f_0\\simeq_F f_1$, if $Z\\subset X$ has the property that $F(z,t)=f_0(z)=f_1(z)$ for any $z\\in Z,t\\in I$, then we say $f_0\\simeq f_1$ relative to $Z$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    Let $Z\\subset X,Y$ be spaces.\r\n    Then $\\simeq$ relative to $Z$ is an equivalence relation on the set of continuous maps $X\\to Y$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial but let's write it.\r\n    $f_0\\simeq f_0$ via $F(x,t)=f_0(x)$ so it is reflexive.\r\n    If $f_0\\simeq_F f_1$, then $f_1\\simeq_{F'}f_0$ via $F^\\prime(x,t)=F(x,1-t)$.\\\\\r\n    If $f_0\\simeq_{F_0}f_1$ and $f_1\\simeq_{F_1}f_2$, then $f_0\\simeq_F f_2$ via\r\n    $$F(x,t)=\\begin{cases}\r\n        F_0(x,2t)\\text{, for $t\\in[0,1/2]$}\\\\\r\n        F_1(x,2t-1)\\text{, for $t\\in[1/2,1]$}\r\n    \\end{cases}$$\r\n    whose continuity is guaranteed by the gluing lemma.\r\n\\end{proof}\r\nRecall that a map $f:X\\to Y$ is a homeomorphism if it is a bijection and has continuous inverse (in addition to it being continuous itself).\r\nWe can extend this idea to characterise two spaces being ``homotopically the same''.\r\n\\begin{definition}\r\n    A homotopy equivalence between spaces $X,Y$ is a map $f:X\\to Y$ such that there exists a map $g:Y\\to X$ such that $f\\circ g\\simeq \\operatorname{id}_Y,g\\circ f\\simeq\\operatorname{id}_X$.\r\n    If such a map exists, we say $X$ and $Y$ are homotopy equivalent.\r\n\\end{definition}\r\nObviously homeomorphic spaces are homotopy equivalent, but the converse is not true as we shall see.\r\n\\begin{example}\r\n    The letters `$\\delta$' and `$o$', as topological spaces, are homotopy equivalent.\r\n    But obviously they are not homeomorphic.\r\n\\end{example}\r\n\\begin{remark}\r\n    All of the invariants of this course are homotopy invariants, as we will see.\r\n\\end{remark}\r\n\\begin{example}\r\n    Let $\\ast$ be the one-point space and $f:\\mathbb R^n\\to\\ast$ the unique map and $g:\\ast\\to\\mathbb R^n$ constantly $0$.\r\n    Then $f\\circ g=\\operatorname{id}_\\ast\\simeq\\operatorname{id}_\\ast$.\r\n    Now $g\\circ f$ is the zero map, which is not the identity but is homotopically equivalent to the identity via $F(x,t)=tx$.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $X$ is homotopy equivalent to $\\ast$, we say $X$ is contractible.\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $f:S^{n-1}\\hookrightarrow\\mathbb R^n\\setminus\\{0\\}$be the inclusion and $g:\\mathbb R^n\\setminus\\{0\\}\\to S^{n-1}$ be $g(x)=x/\\|x\\|$.\r\n    Then $g\\circ f=\\operatorname{id}_{S^{n-1}}$.\r\n    Although $f\\circ g\\neq\\operatorname{id}_{\\mathbb R^n\\setminus\\{0\\}}$, we can consider\r\n    $$F(x,t)=(1-t)x+t\\frac{x}{\\|x\\|}$$\r\n    which is a homotopy between $f\\circ g$ and $\\operatorname{id}_{\\mathbb R^n\\setminus\\{0\\}}$.\r\n    Therefore $S^{n-1}\\simeq \\mathbb R^n\\setminus\\{0\\}$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $f:X\\to Y,g:Y\\to X$ be maps.\r\n    If $g\\circ f=\\operatorname{id}_X$, we say $X$ is a retract of $Y$ and $g$ is a retraction.\\\\\r\n    If in addition that $f\\circ g\\simeq \\operatorname{id}_Y$ relative to $f(X)$, then we say $X$ is a deformation retract of $Y$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    Homotopy equivalences of spaces is an equivalence relation on spaces.\r\n\\end{lemma}\r\nWe got a bit imprecise here as we usually learnt equivalence relations on sets, but the collection of all topological spaces is a proper class.\r\nNevertheless, we can still simply check for reflexivity, symmetry and transitivity.\r\n\\begin{proof}\r\n    Reflexivity and symmetry is obvious.\r\n    For transitivity, suppose the maps shown below are homotopy equivalences:\r\n    \\[\r\n        \\begin{tikzcd}\r\n            X \\arrow[bend left]{r}{f} & Y \\arrow[bend left]{l}{g} \\arrow[bend left]{r}{f'} & Z \\arrow[bend left]{l}{g'}\r\n        \\end{tikzcd}\r\n    \\]\r\n    Then obviously we want to show $f'\\circ f$ and $g\\circ g'$ are homotopy inverses of each other.\r\n    Suppose $g'\\circ f'\\simeq_{F'}\\operatorname{id}_Y$, then the function\r\n    $$(x,t)\\mapsto g\\circ F'(f(x),t)$$\r\n    is a homotopy between $g\\circ f$ and $g\\circ (g'\\circ f')\\circ f=(g\\circ g')\\circ (f'\\circ f)$.\r\n    Therefore $(g\\circ g')\\circ (f'\\circ f)\\simeq g\\circ f\\simeq \\operatorname{id}_X$.\r\n    Using the exact same idea, $(f'\\circ f)\\circ (g\\circ g')\\simeq\\operatorname{id}_Z$.\r\n\\end{proof}\r\n\\subsection{Loops and the Fundamental Group}\r\n\\begin{definition}\r\n    Let $X$ be a space, a path in $X$ is a map $\\gamma:I\\to X$.\r\n    It is a path from $x_0$ to $x_1$ ($x_0,x_1\\in X$) if $\\gamma(0)=x_0$ and $\\gamma(1)=x_1$.\\\\\r\n    A loop based at $x_0\\in X$ is a path from $x_0$ to $x_0$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $\\gamma_0,\\gamma_1$ be paths from $x_0$ to $x_1$.\r\n    We say $\\gamma_0$ and $\\gamma_1$ are (path-)homotopic if they are homotopic relative to $\\{0,1\\}$.\\\\\r\n    This has been shown to be an equivalence relation.\r\n    We write $[\\gamma]$ to denote the equivalence class containing $\\gamma$ in the set of all paths from $x_0$ to $x_1$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $X$ be a space and $x,y,z\\in X$.\r\n    Let $\\gamma_1$ be a path from $x$ to $y$ and $\\gamma_2$ a path from $y$ to $z$.\\\\\r\n    1. The concatenation $\\gamma_1\\cdot \\gamma_2$ of $\\gamma_1$ and $\\gamma_2$ is the path from $x$ to $z$ defined by\r\n    $$(\\gamma_1\\cdot \\gamma_2)(t)=\\begin{cases}\r\n        \\gamma_1(2t)\\text{, for $t\\in [0,1/2]$}\\\\\r\n        \\gamma_2(2t-1)\\text{, for $t\\in [1/2,1]$}\r\n    \\end{cases}$$\r\n    which is a proper path as it is continuous due to the gluing lemma.\\\\\r\n    2. The constant path at $x$ is the constant function $c_x:t\\mapsto x$.\\\\\r\n    3. The inverse of a path $\\gamma_1$ is a path $\\bar\\gamma_1$ from $y$ to $x$ defined by $\\bar\\gamma_1(t)=\\gamma_1(1-t)$.\r\n\\end{definition}\r\n\\begin{theorem}\\label{fund_group}\r\n    Let $X$ be a space and $x_0\\in X$.\r\n    Write $\\pi_1(X,x_0)$ to denote the set of homotopy classes of loops based at $x_0$.\r\n    Then $\\pi_1(X,x_0)$ is a group under the operation $[\\gamma_1][\\gamma_2]=[\\gamma_1\\cdot\\gamma_2]$, with identity $[c_{x_0}]$ and $[\\gamma]^{-1}=[\\bar\\gamma]$.\r\n\\end{theorem}\r\nThis group is called the fundamental group of $X$.\r\n\\begin{lemma}\\label{fund_group_well_def}\r\n    If $\\gamma_0\\simeq\\gamma_1$ are paths to $y$ and $\\delta_0\\simeq \\delta_1$ are paths from $y$, then $\\gamma_0\\cdot\\delta_0\\simeq\\gamma_1\\cdot\\delta_1$ and $\\bar\\gamma_0\\simeq\\bar\\gamma_1$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $\\gamma_0\\simeq_F\\gamma_1,\\delta_0\\simeq_G\\delta_1$.\r\n    Define\r\n    $$H(s,t)=\\begin{cases}\r\n        F(2s,t)\\text{, for $s\\in[0,1/2]$}\\\\\r\n        G(2s-1,t)\\text{, for $s\\in[1/2,1]$}\r\n    \\end{cases}$$\r\n    Then we immediately have $\\gamma_0\\cdot\\delta_0\\simeq_H\\gamma_1\\cdot\\delta_1$.\\\\\r\n    Now for the inverses, $F'(s,t)=F(1-s,t)$ gives $\\bar\\gamma_0\\simeq_{F'}\\bar\\gamma_1$.\r\n\\end{proof}\r\n\\begin{lemma}\\label{fund_group_ax}\r\n    Let $x,y,z\\in X$.\r\n    If there are paths $\\alpha$ from $w$ to $x$, $\\beta$ from $x$ to $y$, $\\gamma$ from $y$ to $z$.\r\n    Then\\\\\r\n    1. $(\\alpha\\cdot\\beta)\\cdot\\gamma\\simeq\\alpha\\cdot(\\beta\\cdot\\gamma)$.\\\\\r\n    2. $\\alpha\\cdot c_x\\simeq c_x\\cdot\\alpha\\simeq\\alpha$.\\\\\r\n    3. $\\alpha\\cdot\\bar\\alpha\\simeq c_x$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Note that the composition of any path $\\gamma$ and an order-preserving surjection $\\phi I\\to I$ is homotopic to the original path via $F(s,t)=\\gamma(t\\phi(s)+(1-t)s)$.\r\n    This is called a reparameterisation.\r\n    Now take $\\phi$ to be the function\r\n    $$\\phi(t)=\\begin{cases}\r\n        t/2\\text{, for $t\\in[1,1/2]$}\\\\\r\n        t-1/4\\text{, for $t\\in[1/2,3/4]$}\\\\\r\n        2t-1\\text{, for $t\\in[3/4,1]$}\r\n    \\end{cases}$$\r\n    Then, as one can check\r\n    $$(\\alpha\\cdot\\beta)\\cdot\\gamma\\simeq((\\alpha\\cdot\\beta)\\cdot\\gamma)\\circ\\phi=\\alpha\\cdot(\\beta\\cdot\\gamma)$$\r\n    To see $\\alpha\\cdot c_x\\simeq\\alpha$, just reparameterise $\\alpha$ by\r\n    $$t\\mapsto\\begin{cases}\r\n        2t\\text{, for $t\\in [0,1/2]$}\\\\\r\n        1\\text{, for $t\\in[1/2,1]$}\r\n    \\end{cases}$$\r\n    The other side is analogous.\\\\\r\n    Indeed $c_x\\simeq_F\\alpha\\cdot\\bar\\alpha$ via\r\n    $$F(s,t)=\\begin{cases}\r\n        \\alpha(2s)\\text{, for $s\\in[0,t/2]$}\\\\\r\n        \\alpha(t)\\text{, for $s\\in[t/2,1-t/2]$}\\\\\r\n        \\alpha(2-2s)=\\bar\\alpha(2s-1)\\text{, for $s\\in[1-t/2,1]$}\r\n    \\end{cases}$$\r\n    which can be verified to work.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{fund_group}]\r\n    Combining Lemma \\ref{fund_group_well_def} and Lemma \\ref{fund_group_ax} shows the result immediately.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider $X=\\mathbb R^n$ and $x_0=0$, then for any loop $\\gamma$ based at $x_0$ we have $\\gamma\\simeq c_{x_0}$ via the straightline homotopy $F(x,t)=(1-t)\\gamma(x)+tx_0$.\r\n    Therefore $\\pi_1(X,x_0)$ is the trivial group.\r\n\\end{example}\r\nNow, as we mentioned in the introduction, we still want a property of this algebraic invariant regarding maps between the relevant objects.\r\n\\begin{lemma}\r\n    Let $f:X\\to Y$ be a map, $x_0\\in X$ and $y_0=f(x_0)$.\r\n    Then there is an induced group homomorphism $f_\\ast:\\pi_1(X,x_0)\\to\\pi_1(Y,y_0)$ defined by $f_\\ast([\\gamma])=[f\\circ \\gamma]$.\r\n    Further:\\\\\r\n    1. If $f\\simeq f'$ relative to $x_0$, then $f_\\ast=f_\\ast'$.\\\\\r\n    2. if $g:Y\\to Z$ with $g(y_0)=z_0$ is another map, then $g_\\ast\\circ f_\\ast=(g\\circ f)_\\ast$.\\\\\r\n    3. $(\\operatorname{id}_X)_\\ast=\\operatorname{id}_{\\pi_1(X,x_0)}$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $f_\\ast$ is always well-defined as a function.\r\n    Suppose $\\gamma_1\\simeq_F\\gamma_2$, then we obviously have $f\\circ \\gamma_1\\simeq_{f\\circ F}f\\circ \\gamma_2$.\\\\\r\n    To see it is a group homomorphism, we observe\r\n    $$f\\circ(\\gamma_1\\cdot\\gamma_2)=(f\\circ \\gamma_1)\\cdot(f\\circ\\gamma_2)\\implies f_\\ast([\\gamma_1\\cdot\\gamma_2])=f_\\ast([\\gamma_1])\\cdot f_\\ast([\\gamma_2])$$\r\n    For 1, if $f\\simeq_F f'$ relative to $x_0$, then $f\\circ\\gamma\\simeq_{F'} f'\\circ\\gamma$ via $F'(s,t)=F(\\gamma(s),t)$, so $f_\\ast([\\gamma])=[f\\circ\\gamma]=[f'\\circ\\gamma]=f_\\ast'([\\gamma])$.\r\n    2 and 3 are completely obvious.\r\n\\end{proof}\r\nOne thing we are not satisfied:\r\nWe define the fundamental group with reference to a basepoint.\r\nIs there a way to remove it, at least for path-connected space?\r\n\\begin{lemma}\\label{indep_basepoint}\r\n    Let $X$ be a space.\r\n    A path $\\alpha$ from $x_0$ to $x_1$ induces a group isomorphism $\\alpha_\\#:\\pi_1(X,x_0)\\to\\pi_1(X,x_1)$ via $\\alpha_\\#([\\gamma])=[\\bar\\alpha\\cdot\\gamma\\cdot\\alpha]$.\r\n    Further:\\\\\r\n    1. If $\\alpha\\simeq\\alpha'$, then $\\alpha_\\#=\\alpha_\\#'$.\\\\\r\n    2. $(c_{x_0})_\\#=\\operatorname{id}_{\\pi_1(X,x_0)}$.\\\\\r\n    3. If $\\beta$ is a path from $x_1$ to $x_2$, then $(\\alpha\\cdot\\beta)_\\#=\\beta_\\#\\circ\\alpha_\\#$.\\\\\r\n    4. If $f:X\\to Y$ is a map with $y_i=f(x_i)$, then\r\n    $$(f\\circ\\alpha)_\\#\\circ f_\\ast=f_\\ast\\circ\\alpha_\\#$$\r\n\\end{lemma}\r\nIn short, the path $\\alpha_\\#(\\gamma)$ goes from $x_1$, walk through $\\bar\\alpha$ to $x_0$, do the loop, then go back to $x_1$ via $\\alpha$.\r\n\\begin{proof}\r\n    It is very easy to see that $\\alpha$ is well-defined.\r\n    To see it is a group homomorphism, observe that for loops $\\gamma,\\delta$ based at $x_0$, we have\r\n    \\begin{align*}\r\n        \\alpha_\\#(\\gamma)\\cdot\\alpha_\\#(\\delta)&\\simeq(\\bar\\alpha\\cdot\\gamma\\cdot\\alpha)\\cdot(\\bar\\alpha\\cdot\\delta\\cdot\\alpha)\\\\\r\n        &\\simeq\\bar\\alpha\\cdot\\gamma\\cdot(\\alpha\\cdot\\bar\\alpha)\\cdot\\delta\\cdot\\alpha\\\\\r\n        &\\simeq\\bar\\alpha\\cdot(\\gamma\\cdot\\delta)\\cdot \\alpha\\\\\r\n        &\\simeq\\alpha_\\#(\\gamma\\cdot\\delta)\r\n    \\end{align*}\r\n    Note also that $\\bar\\alpha_\\#$ has\r\n    $$\\bar\\alpha_\\#\\circ\\alpha_\\#(\\gamma)\\simeq \\alpha\\cdot(\\bar\\alpha\\cdot\\gamma\\cdot\\alpha)\\cdot\\bar\\alpha\\simeq(\\alpha\\cdot\\bar\\alpha)\\cdot\\gamma\\cdot(\\alpha\\cdot\\bar\\alpha)\\simeq c_{x_0}\\cdot\\gamma\\cdot c_{x_0}\\simeq\\gamma$$\r\n    for any $\\gamma$, so $\\bar\\alpha_\\#$ is inverse to $\\alpha_\\#$, hence $\\alpha_\\#$ is indeed a group isomorphism.\\\\\r\n    1,2,3 are completely trivial.\r\n    For 4, we basically just want\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(X,x_0)\\arrow{r}{\\alpha_\\#}\\arrow[swap]{d}{f_\\ast}&\\pi_1(X,x_1)\\arrow{d}{f_\\ast}\\\\\r\n            \\pi_1(Y,y_0)\\arrow[swap]{r}{(f\\circ\\alpha)_\\#}&\\pi_1(Y,y_1)\r\n        \\end{tikzcd}\r\n    \\]\r\n    to commute.\r\n    To see this,\r\n    \\begin{align*}\r\n        ((f\\circ\\alpha)_\\#\\circ f_\\ast)([\\gamma])&=(f\\circ\\alpha)_\\#([f\\circ\\gamma])\\\\\r\n        &=[(\\overline{f\\circ\\alpha})\\cdot(f\\circ\\gamma)\\cdot (f\\circ\\alpha)]\\\\\r\n        &=[f\\circ(\\bar\\alpha\\cdot\\gamma\\cdot\\alpha)]\\\\\r\n        &=f_\\ast(\\alpha_\\#(\\gamma))\r\n    \\end{align*}\r\n    As we want.\r\n\\end{proof}\r\nIn particular, the fundamental group does not depend on the basepoint if the space is path-connected.\r\n\\begin{definition}\r\n    If $X$ is a path-connected soace and $\\pi_1(X,x_0)$ is trivial for some (hence every) $x_0\\in X$, then we say $X$ is simply connected.\r\n\\end{definition}\r\n\\begin{lemma}\\label{hom_commute_path}\r\n    Let $x_0\\in X_1$ and $f,g:X\\to Y$ with $f\\simeq_Fg$.\r\n    Set $\\alpha(t)=F(x_0,t)$ a path from $f(x_0)$ to $g(x_0)$.\r\n    Then\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(Y,f(x_0))\\arrow{r}{\\alpha_\\#}&\\pi_1(Y,g(x_0))\\\\\r\n            \\pi_1(X,x_0)\\arrow{u}{f_\\ast}\\arrow[swap]{ur}{g_\\ast}&\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We need to check that for a loop $\\gamma$ based at $x_0$, we have $\\bar\\alpha\\cdot(f\\circ\\gamma)\\cdot\\alpha\\simeq g\\circ\\gamma$.\r\n    Consider $G:I\\times I\\to Y$ defined by $G(s,t)=F(\\gamma(s),t)$.\r\n    Let $a,b_1,b_2,b_3,b:I\\to I^2$ be paths defined by\r\n    $$a(t)=(t,1),b_1(t)=(0,1-t),b_2(t)=(t,0),b_3(t)=(1,t),b=b_1\\cdot b_2\\cdot b_3$$\r\n    Easily $a\\simeq b$.\r\n    Then $(G\\circ a)(s)=G(s,1)=F(\\gamma(s),1)=(g\\circ\\gamma)(s)$, so $G\\circ a=g\\circ\\gamma$.\r\n    Calculation shows that $G\\circ b_1=\\bar\\alpha, G\\circ b_2=f\\circ\\gamma, G\\circ b_3=\\alpha$.\r\n    Hence\r\n    $$g\\circ\\gamma\\simeq G\\circ a\\simeq G\\circ b\\simeq G\\circ (b_1\\cdot b_2\\cdot b_3)\\simeq (G\\circ b_1)\\cdot(G\\circ b_2)\\cdot(G\\circ b_3)\\simeq \\bar\\alpha\\cdot(f\\circ\\gamma)\\cdot\\alpha$$\r\n    As desired.\r\n\\end{proof}\r\n\\begin{theorem}\\label{hom_eqv_iso}\r\n    If $f:X\\to Y$ is a homotopy equivalence, then for any $x_0\\in X$,\r\n    $$f_\\ast:\\pi_1(X,x_0)\\to\\pi_1(Y,f(x_0))$$\r\n    is an isomorphism of groups.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $g:Y\\to X$ be an homotopy inverse of $f$.\r\n    Then $\\operatorname{id}_X\\simeq_Fg\\circ f$ and $\\operatorname{id}_Y\\simeq_Gf\\circ g$ for some homotopy $F,G$.\r\n    Let $\\alpha(t)=F(x_0,t)$ be a path joining $\\operatorname{id}_X(x_0)=x_0$ and $g(f(x_0))$, then by Lemma \\ref{hom_commute_path} we have\r\n    $$g_\\ast\\circ f_\\ast=(g\\circ f)_\\ast=\\alpha_\\#\\circ (\\operatorname{id}_X)_\\ast=\\alpha_\\#$$\r\n    But $\\alpha_\\#$ is an isomorphism hence injective by Lemma \\ref{indep_basepoint}, so in particular $f_\\ast$ is an injection.\r\n    By the same argument $\\beta(t)=G(f(x_0),t)$ has $f_\\ast\\circ g_\\ast=\\beta_\\#$ which is an isomorphism hence surjective, so $f_\\ast$ is surjective.\r\n    Therefore $f_\\ast$ is bijective, hence an isomorphism.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Contractible spaces are simply connected.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    By definition and Theorem \\ref{hom_eqv_iso}.\r\n\\end{proof}", "meta": {"hexsha": "70a81ce385b99ce197bde23d1efdd93eb5c377bb", "size": 17026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/fund.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": "1/fund.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": "1/fund.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": 58.1092150171, "max_line_length": 229, "alphanum_fraction": 0.6455421121, "num_tokens": 6145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.6527501307614152}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{pylatex}\n\\usepackage{matlatex}\n\\usepackage{geometry}\n\\usepackage{amsmath}\n\\usepackage{pgf}\n\\usepackage{caption}\n\\usepackage{hyperref}\n\\usepackage{examples}\n\n% portrait\n\\geometry{papersize={210mm,297mm},hmargin=2cm,tmargin=1.0cm,bmargin=1.5cm}\n\\parskip=8pt plus 4pt minus 2pt\n\n% landscape\n% \\geometry{papersize={297mm,210mm},hmargin=2cm,tmargin=1.0cm,bmargin=1.5cm}\n% \\parskip=6pt plus 3pt minus 2pt\n\n\\begin{document}\n\n\\section*{A mixed Matlab-Python example}\n\nThis example demonstrates a cooperative effort where Matlab is used to do the analytic computations while Python is used to plot the data.\n\nThe example chosen here is to find and plot the solution to the boundary value problem defined by\n\\begin{align*}\n   \\frac{d^2y}{dx^2} + 2 \\frac{dy}{dx} +10 y = 0\\quad\\quad\\text{with }y(0)=3,\\> y'(0)=0\n\\end{align*}\n\nThis example requires to passes, once for Matlab and once for Python (and in that order). This example can be run using\n\n\\begin{lstlisting}\n   matlatex.sh -x -i mixed\n   pylatex.sh  -x -i mixed\n   pdflatex          mixed\n\\end{lstlisting}\n\nNote that the last pair of commands could also be combined as {\\small\\tt pylatex.sh -i mixed}.\n\n\\subsection*{The Matlab code}\n\nHere Matlab is used to first find the general solution of th differential equation. The boundary conitions are then imposed and finally a uniform sampling of the solution is written to a file for later use by Python and Matplotlib.\n\n\\begin{matlab}\n   syms x y(x)\n   % a second order ode\n   ode = diff(y(x), x, x) + 2*diff(y(x),x) + 10*y(x) == 0;  % mat (ans.101,ode)\n   ddx = diff(y,x);\n\n   % find the general solution\n   sol = dsolve(ode);                     % mat (ans.102,sol)\n\n   % set initial conditions\n   ics = [y(0) == 3, ddx(0) == 0];\n   tmp = ics';                            % mat (ans.103,tmp)\n\n   % find the particular solution\n   sol = dsolve(ode,ics);                 % mat (ans.104,sol)\n   ddx = diff(sol,x);                     % mat (ans.105,ddx)\n\n   xvals = linspace (0.0,2.0*pi,300);\n    f = vpa(subs(sol,x,xvals),10);\n   df = vpa(subs(ddx,x,xvals),10);\n\n   dlmwrite ('mixed.txt',[xvals;f;df]','delimiter',' ','precision','% .8e');\n\n\\end{matlab}\n\n\\clearpage\n\nThe general solution of the differential equation is\n\\begin{equation*}\n   y(x) = \\mat{ans.102}\n\\end{equation*}\nwhile the particular solution satifying the boundary conditions is given by\n\\vspace{5pt}\n\\begin{align*}\n   y(x) &= \\mat{ans.104}\n\\end{align*}\n\n\\subsection*{The Python code}\n\nThis is a straighforward use of Matplotlib to plot two functions. The code reads the datafile created previously by Matlab and then calls Matplotlib to plot that data.\n\n\\begin{python}\n   import numpy as np\n   import matplotlib.pyplot as plt\n\n   plt.matplotlib.rc('text', usetex = True)\n   plt.matplotlib.rc('grid', linestyle = 'dotted')\n   plt.matplotlib.rc('figure', figsize = (5.5,4.1)) # (width,height) inches\n\n   x, y, dy = np.loadtxt ('mixed.txt', unpack=True)\n\n   plt.plot (x,y)\n   plt.plot (x,dy)\n\n   plt.xlim (0.0,4.0)\n\n   plt.legend(('$y(x)$', '$dy(x)/dx$'), loc = 0)\n   plt.xlabel('$x$')\n   plt.ylabel('$y(x),\\> dy/dx$')\n   plt.grid(True)\n   plt.tight_layout(0.5)\n\n   plt.savefig('mixed_fig.pdf')\n\\end{python}\n\n\\vspace{10pt}\n\n\\begin{minipage}{\\textwidth}\n   \\centering\n   \\IfFileExists{mixed_fig.pdf}%\n   {\\includegraphics[width=0.75\\textwidth]{mixed_fig.pdf}}{Failed to create pdf plot.}\n   \\captionof{figure}{The function and its derivative.}\n\\end{minipage}\n\n\\end{document}\n", "meta": {"hexsha": "51f0ea53663b2fc109f0a859ce4a1da170f890f5", "size": 3474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/examples/mixed.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "matlab/examples/mixed.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/examples/mixed.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": 29.1932773109, "max_line_length": 231, "alphanum_fraction": 0.6735751295, "num_tokens": 1086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839876, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6527501299128264}}
{"text": "\\documentclass{article}\r\n\\usepackage{fullpage}\r\n\\usepackage{nopageno}\r\n\\usepackage{amsmath}\r\n\\allowdisplaybreaks\r\n\\begin{document}\r\n\\title{Homework 5}\r\n\\author{Jon Allen}\r\n\\date{October 2, 2013}\r\n\\maketitle\r\n\\section*{Section 3.1 Problems 19,20}\r\n\\subsection*{19}\r\nSolve the logistic equation $\\frac{\\mathrm{d}y}{\\mathrm{d}t}=\\alpha y\\left(1-\\frac{1}{K}y\\right)$ by viewing it as a Bernoulli equation.\r\n\\begin{align*}\r\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}&=\\alpha y-\\frac{\\alpha}{K}y^2\\\\\r\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}-\\alpha y&=-\\frac{\\alpha}{K}y^2 & w&=\\frac{1}{y}\\\\\r\n-\\frac{1}{y^2}\\frac{\\mathrm{d}y}{\\mathrm{d}t}+\\alpha\\frac{1}{y}&=\\frac{\\alpha}{K} & \\frac{\\mathrm{d}w}{\\mathrm{d}t}&=-\\frac{1}{y^2}\\frac{\\mathrm{d}y}{\\mathrm{d}t}\\\\\r\n\\frac{\\mathrm{d}w}{\\mathrm{d}t}+\\alpha w&=\\frac{\\alphae}{K} & \\mu(t)&=e^{\\int{\\alpha\\,\\mathrm{d}t}}\\\\\r\n\\mu(t)w&=\\int{\\mu(t)\\frac{\\alpha}{K}\\,\\mathrm{d}t} & \\mu(t)&=e^{\\alpha t}\\\\\r\ne^{\\alpha t}w&=\\frac{1}{K}\\int{\\alpha e^{\\alpha t}\\,\\mathrm{d}t}=\\frac{e^{\\alpha t}+C}{K}\\\\\r\n\\frac{1}{y}&=\\frac{1+Ce^{-\\alpha t}}{K}&y&=\\frac{K}{1+Ce^{-\\alpha t}}\r\n\\end{align*}\r\n\\subsection*{20}\r\nWhat is the limmiting population, $\\displaystyle\\lim_{t\\to\\infty}y(t)$, of the United states population using the result obtained in Example 3.1.5?\r\n\\begin{align*}\r\ny(t)&=\\frac{0.159}{0.00053+0.02947e^{-0.03t}}\\\\\r\n\\lim_{t\\to\\infty}y(t)&=\\lim_{t\\to\\infty}\\frac{0.159}{0.00053+0.02947e^{-0.03t}}\\\\\r\n\\lim_{t\\to\\infty}y(t)&=\\frac{0.159}{0.00053+0.02947e^{-0.03\\infty}}\\\\\r\n\\lim_{t\\to\\infty}y(t)&=\\frac{0.159}{0.00053+0.02947e^{-\\infty}}\\\\\r\n\\lim_{t\\to\\infty}y(t)&=\\frac{0.159}{0.00053+0.02947\\frac{1}{e^{\\infty}}}\\\\\r\n\\lim_{t\\to\\infty}y(t)&=\\frac{0.159}{0.00053+0.02947\\cdot0}\\\\\r\n\\lim_{t\\to\\infty}y(t)&=300\r\n\\end{align*}\r\n\\section*{Section 3.2 Problems 7,8}\r\nUse equation $T=(T_0-T_s)e^{kt}+T_s$\r\n\\subsection*{7}\r\nA thermometer that reads 90$^\\circ$F is placed in a room with temperature 70$^\\circ$F. After 3 min, the thermometer reads 80$^\\circ$F. What does the thermometer read after 5 min?\r\n\\begin{align*}\r\n\tT_s&=70\\\\\r\n\tT_0&=90\\\\\r\n\tT(3)&=80=(90-70)e^{3k}+70\\\\\r\n\t\\frac{10}{20}&=e^{3k}\\\\\r\n\t\\ln\\frac{1}{2}&=3k\\\\\r\n\tk&=\\frac{1}{3}\\ln\\frac{1}{2}\\\\\r\n\tT(5)&=20e^{\\frac{5}{3}\\ln\\frac{1}{2}}+70\\approx76.3^\\circ\\mathrm{F}\r\n\\end{align*}\r\n\\subsection*{8}\r\nA thermometer is placed outdoors with temperature 80$^\\circ$F. After 2 min, the thermometer reads 68$^\\circ$F, and after 5 min, it reads 72$^\\circ$F. What was the initial temperature reading of the thermometer?\r\n\\begin{align*}\r\n\tT_s&=80\\\\\r\n\tT(2)&=68\\\\\r\n\tT(5)&=72\\\\\r\n\tT(t)-T_s&=(T_0-T_s)e^{kt}\\\\\r\n\t\\frac{T(t)-T_s}{e^{kt}}&=T_0-T_s\\\\\r\n\t\\frac{T(t)-T_s}{e^{kt}}+T_s&=T_0\\\\\r\n\t\\frac{T(2)-80}{e^{2k}}&=\\frac{T(5)-80}{e^{5k}}=\\frac{T(5)-80}{e^{2k}e^{3k}}\\\\\r\n\t68-80&=\\frac{72-80}{e^{3k}}\\\\\r\n\te^{3k}&=\\frac{-8}{-12}\\\\\r\n\tk&=\\frac{1}{3}\\ln\\frac{2}{3}\\\\\r\n\tT_0&=\\frac{T(2)-80}{e^{\\frac{2}{3}\\ln\\frac{2}{3}}}+80=\\frac{68-80}{(2/3)^{2/3}}+80=-\\frac{12}{(2/3)^{2/3}}+80\\\\\r\n\tT_0&\\approx64.3^\\circ\\mathrm{F}\r\n\\end{align*}\r\n\\end{document}\r\n", "meta": {"hexsha": "df5e0bd7ef5d415db57ba71e719ce5476e3eb60a", "size": 2969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential equations/diffeq-hw-2013-10-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": "differential equations/diffeq-hw-2013-10-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": "differential equations/diffeq-hw-2013-10-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": 46.390625, "max_line_length": 211, "alphanum_fraction": 0.609632873, "num_tokens": 1356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.6527250918188878}}
{"text": "% !TEX root = ./main.tex\n\\section{Stochastic reproduction and the Moran process}\n\nOur approach to derive the equation that governs the time evolution of the\nallele frequency starts from a discrete state space. As mentioned before, we\nwill be working in the context of the one-locus two-allele model. To capture the\nstochastic nature of the reproduction of these organisms we will adopt the Moran\nprocess, shown schematically in Fig.~\\ref{fig01:moran}(A). The Moran process is\na stochastic process with a fixed population size $N$. Organisms in this\ndiscrete population die with a characteristic rate $\\gamma$. Which type of\norganisms, $A$ or $a$, dies during a small time window $\\Delta t$ depends only\non the relative abundance of each allele type. When the organism that dies it is\nimmediately replaced when any of the organisms in the population reproduces. The\nprobability of which organism gets to reproduce depends on the relative fitness\nvalues of each allele. Furthermore, when the organism reproduces, there is an\nintrinsic probability that the progeny mutates to the opposite allele. As we\nwill show below for the different evolutionary forces, all of these stochastic\nevents--type of organism that dies, type of organism that replaces the dead\norganism, change of allele type due to mutation--are taken as multiplicative\nfactors in the rate of change of the population structure.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics {../../fig/spread_the_butter/fig01_moran.pdf}\n  \\caption{\\textbf{Schematic of the Moran process}. (A) In the Moran process the\n  population size $N$ remains constant at all times. Organisms stochastically\n  die at a rate $\\gamma$ to be immediately replaced by another organism that is\n  able to reproduce. For the composition of the population to change two things\n  can happen: 1. An organism of the same type as the one that died reproduces\n  --with a probability depending on the fitness--,and then this organism mutates\n  to the opposite allele type, or 2. An organism of the opposite allele\n  reproduces--also with a probability depending on the fitness--, and this\n  organism does not mutate when doing so. (B) Schematic representation of the\n  construction of the master equation for the number of organisms carrying\n  allele $A$. On a small discrete time step $\\Delta t$ the probability of\n  transitioning to from a number $n$ to a number $n + 1$ or $n-1$ is given by\n  $w^+(n)$ and $w^-(n)$, respectively. (C) In the limit of a large population we\n  can approximate the probability mass function for the number of organisms\n  $p(n, t)$ with a probability density function for the allele frequency $P(x,\n  t)$.}\n  \\label{fig01:moran}\n\\end{figure}\n\n\\subsection{General master equation for the Moran process}\n\nGiven the discrete nature of the Moran process, our first task consists of\nwriting the probability mass function (PMF) for the number of organisms carrying\nallele $A$. Fig~\\ref{fig01:moran}(B) shows a schematic of how to build such\ndistribution. Focusing on a particular number of organisms $n$, during a\nsufficiently small time window $\\Delta t$ such that we can neglect changes\nlarger than one organism, we must take into account all of the inflow and\noutflow of probability from this particular bin. Let us define $w^+(n)$ and\n$w^-(n)$ to be the transition rates (in units of time$^{-1}$) of jumping from\nbin $n$ to bin $n+1$ and from bin $n$ to bin $n-1$, respectively. Writing down\nthe checks and balances during this small time window allows us to predict the\nprobability of having a particular number of organisms. This is mathematically\nwritten as\n\\begin{equation}\n    p(n, t + \\Delta t) = \n    p(n, t)\n    + \\overbrace{w^+(n - 1)\\Delta t p(n - 1, t)}^\n    {n - 1 \\rightarrow n}\n    + \\overbrace{w^-(n + 1)\\Delta t p(n + 1, t)}^\n    {n + 1 \\rightarrow n}\n    - \\overbrace{w^-(n)\\Delta t p(n, t)}^\n    {n \\rightarrow n - 1}\n    - \\overbrace{w^+(n)\\Delta t p(n, t)}^\n    {n \\rightarrow n + 1}.\n    \\label{eq:master_n_discrete}\n\\end{equation}\nIt is in the definition of these rates $w^\\pm(n)$ that we include the effects\nthat different evolutionary forces have on the probability of changing the\ncomposition of the population as schematized in Fig.~\\ref{fig01:moran}(A).\n\nWe can further simplify Eq.~\\ref{eq:master_n_discrete} by sending the first term\non the right hand side to the left, dividing both sides by $\\Delta t$, and\ntaking the limit $\\Delta t \\rightarrow 0$. This results in the so-called master\nequation for the number of organisms carrying allele $A$\n\\begin{equation}\n    \\frac{dp(n, t)}{dt} = \n    w^+(n - 1) p(n - 1, t)\n    + w^-(n + 1) p(n + 1, t)\n    - w^+(n) p(n, t)\n    - w^-(n) p(n, t).\n    \\label{eq:master_n}\n\\end{equation}\n\n\\subsection{Fokker-Planck equation for allele frequency}\n\nPart of the beauty and power of diffusion theory is that we can work with smooth\ncontinuous equations that track the evolution of the population composition.\nTherefore, rather than tracking the discrete number of organisms, we will work\ninstead with allele frequency. In the limit of a very large population--one of\nthe conditions for diffusion theory to apply--we can approximate the allele\nfrequency $x$ to be a continuous variable between 0 and 1. As schematized in\nFig.~\\ref{fig01:moran}(C), we can bin the continuous probability density\nfunction for the allele frequency $P(x, t)$ into small bins of width $\\Delta x$.\nThe natural width of such bins is given by the minimum change that can happen in\nthe discrete language, i.e., $\\Delta x \\approx 1 / N$. With this definition in\nhand we can then approximate the PMF of $n$ as\n\\begin{equation}\n  p(n, t) \\approx\n  \\overbrace{P(x, t)}^{\\text{base}} \\;\n  \\overbrace{\\Delta x}^{\\text{width}}.\n\\end{equation}\nThe transition rates $w^\\pm(n)$, having units of time$^{-1}$, are not affected\nby this approximation. In other words, the transition rate to jump from $n$ to\n$n \\pm 1$ is the exact same transition rate to jump from $x$ to $x \\pm \\Delta\nx$. We then define the transition rates in allele frequency as\n\\begin{equation}\n  W^\\pm(x) \\equiv w^\\pm(n).\n\\end{equation}\nSubstituting these definitions we can rewrite Eq.~\\ref{eq:master_n} as\n\\begin{equation}\n\\begin{split}\n    \\frac{dP(x, t) \\Delta x}{dt} = \n    &W^+(x - \\Delta x) P(x - \\Delta x, t) \\Delta x\n    + W^-(x + \\Delta x) P(x + \\Delta x, t) \\Delta x\\\\\n    &- W^+(x) P(x, t) \\Delta x\n    - W^-(x) P(x, t) \\Delta x.\n\\end{split}\n\\end{equation}\nGiven that $\\Delta x$ does not depend on the time $t$ we can take it out of the\nderivative and simplify it from both sides, obtaining the master equation for\nthe time evolution of the probability density function of the allele frequency\n\\begin{equation}\n    \\frac{dP(x, t)}{dt} = \n    W^+(x - \\Delta x) P(x - \\Delta x, t)\n    + W^-(x + \\Delta x) P(x + \\Delta x, t)\n    - W^+(x) P(x, t) \n    - W^-(x) P(x, t).\n    \\label{eq:master_x} \n\\end{equation}\nGiven the continuous nature of Eq.~\\ref{eq:master_x} we can Taylor expand the\nterms involving $x \\pm \\Delta x$. The expansion of these terms up to second\norder takes the form\n\\begin{equation}\n  W^{\\mp}(x \\pm \\Delta x) P(x \\pm \\Delta x) \\approx\n  W^\\mp(x) P(x, t) \\pm\n  \\frac{d}{dx} \\left[W^\\mp(x) P(x, t) \\right] \\Delta x\n  + \\frac{1}{2} \\frac{d^2}{dx^2} \\left[ W^\\mp(x) P(x, t) \\right] (\\Delta x)^2\n  + \\mathcal{O}((\\Delta x)^3)\n\\end{equation}\nSubstituting these expansions into Eq.\\ref{eq:master_x} results in a partial\ndifferential equation of the form\n\\begin{equation}\n\\begin{aligned}\n  \\frac{\\partial}{\\partial t} P(x, t) &= \n  W^{+}(x) P(x, t)\n  -\\frac{\\partial}{\\partial x}\n  \\left[W^{+}(x) P(x, t)\\right] \\Delta x\n  +\\frac{1}{2} \\frac{\\partial^{2}}{\\partial x^{2}}\n  \\left[W^{+}(x) P(x, t)\\right](\\Delta x)^{2} \\\\\n  &+W^{-}(x) P(x, t)+\n  \\frac{\\partial}{\\partial x}\n  \\left[W^{-}(x) P(x, t)\\right] \\Delta x\n  + \\frac{1}{2} \\frac{\\partial^{2}}{\\partial x^{2}}\n  \\left[W^{-(x)} P(x, t)\\right](\\Delta x)^{2} \\\\\n  &-W^{+}(x, t) P(x, t) -W^{-}(x) P(x, t).\n\\end{aligned}\n\\end{equation}\nSimplifying terms and using the linearity of the derivatives we can rewrite this\nas\n\\begin{equation}\n\\frac{\\partial}{\\partial t} P(x, t)=\n-\\frac{\\partial}{\\partial x}\n\\left[\\left(W^{+}(x)-W^{-}(x)\\right) P(x, t)\\right] \\Delta x \n+\\frac{1}{2} \\frac{\\partial^{2}}{\\partial x^{2}}\n\\left[\\left(W^{+}(x)+W^{-}(x)\\right) P(x, t)\\right](\\Delta x)^{2}\n\\end{equation}\nFinally, recall that we define $\\Delta x \\equiv 1 / N$. Substituting this gives\nus the partial differential equation in which we will implement the different\nevolutionary forces via the transition rates\n\\begin{equation}\n\\frac{\\partial}{\\partial t} P(x, t)=\n-\\frac{1}{N}\\frac{\\partial}{\\partial x}\n\\left[\\left(W^{+}(x)-W^{-}(x)\\right) P(x, t)\\right] \n+\\frac{1}{2N^2} \\frac{\\partial^{2}}{\\partial x^{2}}\n\\left[\\left(W^{+}(x)+W^{-}(x)\\right) P(x, t)\\right]\n\\label{eq:pde_x_general}\n\\end{equation}\n\nIn the following section we will implement one-by-one the three evolutionary\nforces via the definition of the transition rates.", "meta": {"hexsha": "dfeb9eed1de75e887242e580691dab16841eb1e1", "size": 8934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/spread_the_butter/section_02_moran.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_moran.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_moran.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": 48.8196721311, "max_line_length": 80, "alphanum_fraction": 0.7022610253, "num_tokens": 2690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6527037763906249}}
{"text": "\\lab{Image Segmentation}{Image Segmentation}\n\n\\objective{Graph theory has a variety of applications.\nA graph (or network) can be represented in many ways on a computer.\nIn this lab we study a common matrix representation for graphs and show how certain properties of the matrix representation correspond to inherent properties of the original graph.\n% In this lab, we learn to represent a graph as a matrix and to calculate properties of the graph using the matrix representation.\nWe also introduce tools for working with images in Python, and conclude with an application of using graphs and linear algebra to segment images.\n}\n\n\\section*{Graphs as Matrices} % ===============================================\n\nA \\emph{graph} is a mathematical structure that represents relationships between objects.\nGraphs are defined by $G = (V,E)$, where $V$ is a set of \\emph{vertices} (or \\emph{nodes}) and $E$ is a set of \\emph{edges}, each of which connects one node to another.\nA graph can be classified in several ways.\n\\begin{itemize}\n    \\item The edges of an \\emph{undirected} graph are bidirectional: if an edge goes from node $A$ to node $B$, then that same edge also goes from $B$ to $A$.\n    For example, the graphs $G_1$ and $G_2$ in Figure \\ref{fig:imgseg-example-graphs} are both undirected.\n    In a \\emph{directed graph}, edges only go one way, usually indicated by an arrow pointing from one node to another.\n    In this lab, we focus on undirected graphs.\n\n    \\item The edges of a \\emph{weighted} graph have a weight assigned to them, such as $G_2$.\n    A weighted graph could represent a collection of cities with roads connecting them: each vertex would represent a city, and the edges would represent roads between the cities.\n    The length of each road could be the weight of the corresponding edge.\n    An \\emph{unweighted} graph like $G_1$ does not have weights assigned to its edges, but any unweighted graph can be thought of as a weighted graph by assigning a weight of $1$ to every edge.\n\n    % \\item A graph is \\emph{simple} if no edge connects a node to itself.\n    % The graph in Figure [TODO] is simple, but the graph in Figure [TODO] is not.\n\\end{itemize}\n\n\\begin{figure}[H] % Two graphs.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.45\\textwidth}\n    \\centering\n    \\begin{tikzpicture}[auto,node distance=1.5cm,\n     thick,main node/.style={circle,draw}]\n\n      \\node[main node] (5) [] {6};\n      \\node[main node] (2) [below right of=5] {3};\n      \\node[main node] (3) [above right of=5] {4};\n      \\node[main node] (4) [right of=3] {5};\n      \\node[main node] (1) [right of=2] {2};\n      \\node[main node] (0) [below right of=4] {1};\n\n      \\foreach \\s/\\t in {5/3, 3/4, 4/0, 0/1, 1/2, 2/3, 1/4, 5/0} {\n       \\path[draw] (\\s) edge (\\t);}\n    \\end{tikzpicture}\n    \\caption{$G_1$, an unweighted undirected graph.}\n    \\label{fig:graphexample-unweighted}\n\\end{subfigure}\n\\quad\n\\begin{subfigure}{.45\\textwidth}\n    \\centering\n    \\begin{tikzpicture}[auto,node distance=2cm,\n    thick,main node/.style={circle,draw}]\n\n    \\node[main node] (0) [] {1};\n    \\node[main node] (1) [below of=0] {2};\n    \\node[main node] (2) [right of=0] {3};\n    \\node[main node] (3) [below of=2] {4};\n    \\node[main node] (4) [right of=2] {5};\n    \\node[main node] (5) [right of=3] {6};\n\n    \\path[draw] (0) edge node [left] {3} (1);\n    \\path[draw] (2) edge node [left] {1} (3);\n    \\path[draw] (4) edge node{1} (5);\n    \\path[draw] (3) edge node{2} (4);\n    \\path[draw] (3) edge node [below]{.5} (5);\n    \\end{tikzpicture}\n    \\caption{$G_2$, a weighted undirected graph.}\n    \\label{fig:graphexample-weighted}\n\\end{subfigure}\n% \\qquad\n% \\begin{subfigure}{.28\\textwidth}\n%     \\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,\n%     thick,main node/.style={circle,draw}]\n%\n%      \\node[main node] (A) [] {A};\n%      \\node[main node] (B) [below of=A] {B};\n%      \\node[main node] (C) [right of=A] {C};\n%      \\node[main node] (D) [below of=C] {D};\n%      \\node[main node] (E) [right of=C] {E};\n%      \\node[main node] (F) [right of=D] {F};\n%\n%      \\foreach \\s/\\t in {A/C, B/A, B/D, C/E, C/F, D/C} {\n%       \\path[draw] (\\s) edge (\\t);}\n%     \\end{tikzpicture}\n%     \\caption{A directed graph.}\n% \\end{subfigure}\n\\caption{}\n\\label{fig:imgseg-example-graphs}\n\\end{figure}\n\n\\subsection*{Adjacency, Degree, and Laplacian Matrices} % ---------------------\n\nFor computation and analysis, graphs are commonly represented by a few special matrices.\nFor these definitions, let $G$ be a graph with $N$ nodes and let $w_{ij}$ be the weight of the edge connecting node $i$ to node $j$ (if such an edge exists).\n%\n\\begin{enumerate}\n\\item The \\emph{adjacency matrix} of $G$ is the $N\\times N$ matrix $A$ with entries\n\\[\na_{ij} =\n\\begin{cases}\nw_{ij} & \\text{if an edge connects node i and node j} \\\\\n0 & \\text{otherwise.}\n\\end{cases}\n\\]\n% If the graph is not simple, there are differing conventions for how to define the diagonal of the adjacency matrix.\nThe adjacency matrices $A_1$ of $G_1$ and $A_2$ of $G_2$ are\n\\begin{align*}\nA_1 = \\left[\\begin{array}{cccccc}\n0 & 1 & 0 & 0 & 1 & 1\\\\\n1 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 1 & 1\\\\\n1 & 1 & 0 & 1 & 0 & 0\\\\\n1 & 0 & 0 & 1 & 0 & 0\n\\end{array}\\right],\n\\qquad A_2 =\n\\left[\\begin{array}{cccccc}\n0 & 3 & 0 & 0 & 0 & 0\\\\\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 2 & .5\\\\\n0 & 0 & 0 & 2 & 0 & 1\\\\\n0 & 0 & 0 & .5 & 1 & 0\n\\end{array}\\right].\n\\end{align*}\nNotice that these adjacency matrices are symmetric.\nThis is always the case for undirected graphs since the edges are bidirectional.\n\n\\begin{comment} % Paths of a certain length via matrix powers. Not relevant. ==\nRaising the adjacency matrix to a power yields some very interesting information.\nWe can discover the number of paths of length $n$ between two nodes by raising a graph's adjacency matrix to the $n$th power.\nFor example, by squaring $A$, we can find the number of paths of length two between every pair of nodes.\n\\begin{lstlisting}\n>>> A = np.array([[0,1,0,0,1,0],[1,0,1,0,1,0],\n                  [0,1,0,1,0,0],[0,0,1,0,1,1],\n                  [1,1,0,1,0,0],[0,0,0,1,0,0]])\n\n>>> np.linalg.matrix_power(A,2)\narray([[2, 1, 1, 1, 1, 0],\n       [1, 3, 0, 2, 1, 0],\n       [1, 0, 2, 0, 2, 1],\n       [1, 2, 0, 3, 0, 0],\n       [1, 1, 2, 0, 3, 1],\n       [0, 0, 1, 0, 1, 1]])\n\\end{lstlisting}\nWe can see that no paths of length two exist between node 0 and node 5 because $A^2_{0,5} = 0$.\nBy calculating $A^6$ we can find the number of paths of length six from node 3 to itself.\n\\begin{lstlisting}\n>>> np.linalg.matrix_power(A, 6)\narray([[45, 54, 38, 45, 54, 16],\n       [54, 86, 29, 77, 51, 11],\n       [38, 29, 55, 15, 70, 27],\n       [45, 77, 15, 75, 31,  4],\n       [54, 51, 70, 31, 93, 34],\n       [16, 11, 27,  4, 34, 14]])\n\\end{lstlisting}\nTherefore there are 75 unique paths of length six from node 3 to itself.\nImagine trying to count all of those paths by hand!\nIt would be very easy to count incorrectly.\nThis method makes it very simple to count paths without mistakes.\n\nAdjacency matrices can also be composed of \\li{True} and \\li{False} values.\nIn this case, the $n$th power of such a matrix (using boolean arithmetic)\nis again a matrix of\nboolean values which simply indicate whether there exists a path of length $n$ between the given pair of nodes, rather than indicating the number of such\npaths.\n\n\\begin{problem}\nLet the following matrix represent a directed graph\n\\[\n\\begin{array}{ccccccc}\n0 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 1 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0\n\\end{array}\\right]\n\\]\nBetween which pair of nodes does there exist the greatest number of paths\nof length five?\nFrom which node to which node is there no path of length seven?\n\\end{problem}\n\\end{comment} % ===============================================================\n\n\\item The \\emph{degree matrix} of $G$ is the $N \\times N$ diagonal matrix $D$ whose $i$th diagonal entry is\n\\begin{equation}\nd_{ii} = \\sum_{j=1}^N w_{ij}.\n\\label{eq:degree-matrix-formula}\n\\end{equation}\n%For a directed graph, each node has an \\emph{out-degree} (the number of edges directed away from a node) and an \\emph{in-degree} (the number edges directed toward a node).\nThe degree matrices $D_1$ of $G_1$ and $D_2$ of $G_2$ are\n\\begin{align*}\nD_1 = \\left[\\begin{array}{cccccc}\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 2 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 3 & 0 & 0\\\\\n0 & 0 & 0 & 0 & 3 & 0\\\\\n0 & 0 & 0 & 0 & 0 & 2\n\\end{array}\\right],\n\\qquad D_2 =\n\\left[\\begin{array}{cccccc}\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 3.5 & 0 & 0\\\\\n0 & 0 & 0 & 0 & 3 & 0\\\\\n0 & 0 & 0 & 0 & 0 & 1.5\n\\end{array}\\right].\n\\end{align*}\nThe $i$th diagonal entry of $D$ is called the \\emph{degree} of node $i$, the sum of the weights of the edges leaving node $i$.\n\n\\item The \\emph{Laplacian matrix} of $G$ is the $N\\times N$ matrix $L$ defined as\n\\begin{equation}\nL = D - A,\n\\label{eq:laplacian-matrix-formula}\n\\end{equation}\nwhere $D$ is the degree matrix of $G$ and $A$ is the adjacency matrix of $G$.\nFor $G_1$ and $G_2$, the Laplacian matrices $L_1$ and $L_2$ are\n\\begin{align*}\nL_1 =\\left[\\begin{array}{rrrrrr}\n3 & -1 & 0 & 0 & -1 & -1\\\\\n-1 & 3 & -1 & 0 & -1 & 0\\\\\n0 & -1 & 2 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3 & -1 & -1\\\\\n-1 & -1 & 0 & -1 & 3& 0\\\\\n-1 & 0 & 0 & -1 & 0 & 2\n\\end{array}\\right],\n\\qquad L_2 =\n \\left[\\begin{array}{rrrrrr}\n3 & -3 & 0 & 0 & 0 & 0\\\\\n-3 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3.5 & -2 & -.5\\\\\n0 & 0 & 0 & -2 & 3 & -1\\\\\n0 & 0 & 0 &- .5 & -1 & 1.5\n\\end{array}\\right].\n\\end{align*}\n\\end{enumerate}\n\n\\begin{problem}\nWrite a function that accepts the adjacency matrix $A$ of a graph $G$.\nUse (\\ref{eq:degree-matrix-formula}) and (\\ref{eq:laplacian-matrix-formula}) to compute the Laplacian matrix $L$ of $G$.\n\\\\(Hint: The diagonal entries of $D$ can be computed in one line by summing $A$ over an axis.)\n\nTest your function on the graphs $G_1$ and $G_2$ from Figure \\ref{fig:imgseg-example-graphs} and validate your results with \\li{scipy.sparse.csgraph.laplacian()}.\n\\label{prob:imgseg-laplacian}\n\\end{problem}\n\n\\subsection*{Connectivity} % --------------------------------------------------\n\nA \\emph{connected graph} is a graph where every vertex is connected to every other vertex by at least one path.\nFor example, $G_1$ is connected, whereas $G_2$ is not because there is no path from node $1$ (or node $2$) to node $3$ (or nodes $4$, $5$, or $6$).\nThe na\\\"ive brute-force algorithm for determining if a graph is connected is to check that there is a path from each edge to every other edge.\nWhile this may work for very small graphs, most interesting graphs have thousands of vertices, and for such graphs this approach is prohibitively expensive.\nLuckily, an interesting result from algebraic graph theory relates the connectivity of a graph to its Laplacian matrix.\n\nIf $L$ is the Laplacian matrix of a graph, then the definition of $D$ and the construction $L = D - A$ guarantees that the rows (and columns) of $L$ must each sum to $0$.\nTherefore $L$ cannot have full rank, so $\\lambda = 0$ must be an eigenvalue of $L$.\nFurthermore, if $L$ represents a graph that is \\textbf{not} connected, more than one of the eigenvalues of $L$ must be zero.\nTo see this, let $J \\subset \\{1,2,\\ldots,N\\}$ such that the vertices $\\{v_j\\}_{j \\in J}$ form a connected component of the graph, meaning that there is a path between each pair of vertices in the set.\nNext, let $\\x$ be the vector with entries\n \\[\nx_k = \\begin{cases}\n1, & k \\in J    \\\\\n0, & k \\not\\in J.\n\\end{cases}\n  \\]\nThen $\\x$ is an eigenvector of $L$ corresponding to the eigenvalue $\\lambda = 0$.\n% In other words, for each connected component, $0$ appears at least once as an eigenvalue.\n\nFor example, the example graph $G_2$ has two connected components.\n\\begin{enumerate}\n\\item $J_1 = \\{1,2\\}$ so that $\\x_1 = [1, 1, 0, 0, 0, 0]\\trp$.\nThen\n\\[\nL_2\\x_1 =\n\\left[\\begin{array}{rrrrrr}\n3 & -3 & 0 & 0 & 0 & 0\\\\\n-3 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3.5 & -2 & -.5\\\\\n0 & 0 & 0 & -2 & 3 & -1\\\\\n0 & 0 & 0 &- .5 & -1 & 1.5\n\\end{array}\\right]\n\\left[\\begin{array}{c}\n1 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\n0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\\end{array}\\right]\n= \\0.\n\\]\n\n\\item $J_2 = \\{3,4,5,6\\}$ and hence $\\x_2 = [0, 0, 1, 1, 1, 1]\\trp$.\nThen\n\\[\nL_2\\x_2 =\n\\left[\\begin{array}{rrrrrr}\n3 & -3 & 0 & 0 & 0 & 0\\\\\n-3 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3.5 & -2 & -.5\\\\\n0 & 0 & 0 & -2 & 3 & -1\\\\\n0 & 0 & 0 &- .5 & -1 & 1.5\n\\end{array}\\right]\n\\left[\\begin{array}{c}\n0 \\\\ 0 \\\\ 1 \\\\ 1 \\\\ 1 \\\\ 1\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\n0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\\end{array}\\right]\n= \\0.\n\\]\n\\end{enumerate}\n\nIn fact, it can be shown that the number of zero eigenvalues of the Laplacian exactly equals the number of connected components.\nThis makes calculating how many connected components are in a graph only as hard as calculating the eigenvalues of its Laplacian.\n\nA Laplacian matrix $L$ is always a positive semi-definite matrix when all weights in the graph are positive, meaning that its eigenvalues are each nonnegative.\nThe second smallest eigenvalue of $L$ is called the \\emph{algebraic connectivity} of the graph.\nIt is clearly $0$ for non-connected graphs, but for a connected graph, the algebraic connectivity provides useful information about its sparsity or ``connectedness.''\nA higher algebraic connectivity indicates that the graph is more strongly connected.\n\n\\begin{problem}\nWrite a function that accepts the adjacency matrix $A$ of a graph $G$ and a small tolerance value \\li{tol}.\nCompute the number of connected components in $G$ and its algebraic connectivity.\nConsider all eigenvalues that are less than the given \\li{tol} to be zero.\n\nUse \\li{scipy.linalg.eig()} or \\li{scipy.linalg.eigvals()} to compute the eigenvalues of the Laplacian matrix.\nThese functions return complex eigenvalues (with negligible imaginary parts); use \\li{np.real()} to extract the real parts.\n\\end{problem}\n\n\\begin{comment} % Likelihood of connectedness.\n\\begin{problem}\n% Used to be part of the previous problem.\n% Rmoved because these is no great way to evaluate it.\nThe folowing function creates a random symmetric matrix of Boolean values with sparsity determined by the input \\li{c}.\n\\begin{lstlisting}\ndef sparse_generator(n, c):\n    \"\"\"Return a symmetric nxn matrix with sparsity determined by c.\"\"\"\n    A = np.random.rand(n**2).reshape((n, n))\n    A = ( A > c**(.5) )\n    return A.T @ A\n\\end{lstlisting}\n\nTest your function from the previous problem on matrices created by \\li{sparse_generator()} with inputs $n = 10, 100$ and $c = .25, .5, .95$.\nWhat do you notice about the likelihood that a random graph is connected?\n\\end{problem}\n\\end{comment}\n\n\\section*{Images as Matrices} % ===============================================\n\nComputer images are stored as arrays of integers that indicate pixel values.\nMost $m\\times n$ grayscale (black and white) images are stored in Python as a $m\\times n$ NumPy arrays, while most $m\\times n$ color images are stored as $3$-dimensional $m\\times n \\times 3$ arrays.\nColor image arrays can be thought of as a stack of three $m\\times n$ arrays, one each for red, green, and blue values.\n% \\footnote{See \\url{http://scikit-image.org/docs/dev/user_guide/numpy_images.html\\#coordinate-conventions} for other conventions.}\nThe datatype for an image array is \\li{np.uint8}, unsigned 8-bit integers that range from $0$ to $255$.\nA $0$ indicates a black pixel while a $255$ indicates a white pixel.\n\nUse \\li{imageio.imread()} to read an image from a file and \\li{imageio.imwrite()} to save an image.\nMatplotlib's \\li{plt.imshow()} displays an image array, but it displays arrays of floats between $0$ and $1$ more cleanly than arrays of 8-bit integers.\nTherefore it is customary to scale the array by dividing each entry by $255$ before processing or showing the image.\nIn this case, a $0$ still indicates a black pixel, but now a $1$ indicates pure white.\n\n\\begin{lstlisting}\n>>> from imageio import imread\n>>> from matplotlib import pyplot as plt\n\n>>> image = imread(\"dream.png\")     # Read a (very) small image.\n>>> print(image.shape)              # Since the array is 3-dimensional,\n(48, 48, 3)                         # this is a color image.\n\n# The image is read in as integers from 0 to 255.\n>>> print(image.<<min>>(), image.<<max>>(), image.dtype)\n0 254 uint8\n\n# Scale the image to floats between 0 and 1 for Matplotlib.\n>>> scaled = image / 255.\n>>> print(scaled.<<min>>(), scaled.<<max>>(), scaled.dtype)\n0.0 0.996078431373 float64\n\n# Display the scaled image.\n>>> plt.imshow(scaled)\n>>> plt.axis(\"off\")\n\\end{lstlisting}\n\nA color image can be converted to grayscale by averaging the RGB values of each pixel, resulting in a 2-D array called the \\emph{brightness} of the image.\nTo properly display a grayscale image, specify the keyword argument \\li{cmap=\"gray\"} in \\li{plt.imshow()}.\n\n\\begin{lstlisting}\n# Average the RGB values of a colored image to obtain a grayscale image.\n>>> brightness = scaled.mean(axis=2)        # Average over the last axis.\n>>> print(brightness.shape)                 # Note that the array is now 2-D.\n(48, 48)\n\n# Display the image in gray.\n>>> plt.imshow(brightness, cmap=\"gray\")\n>>> plt.axis(\"off\")\n\\end{lstlisting}\n\nFinally, it is often important in applications to flatten an image matrix into a large 1-D array.\nUse \\li{np.ravel()} to convert a $m\\times n$ array into a 1-D array with $mn$ entries.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> A = np.random.randint(0, 10, (3,4))\n>>> print(A)\n[[4 4 7 7]\n [8 1 2 0]\n [7 0 0 9]]\n\n# Unravel the 2-D array (by rows) into a 1-D array.\n>>> np.ravel(A)\narray([4, 4, 7, 7, 8, 1, 2, 0, 7, 0, 0, 9])\n\n# Unravel a grayscale image into a 1-D array and check its size.\n>>> M,N = brightness.shape\n>>> flat_brightness = np.ravel(brightness)\n>>> M*N == flat_brightness.size\n<<True>>\n>>> print(flat_brightness.shape)\n(2304,)\n\\end{lstlisting}\n\n\\begin{problem} % Read and display an image.\nDefine a class called \\li{ImageSegmenter}.\n\\begin{enumerate}\n    \\item Write the constructor so that it accepts the name of an image file.\n    Read the image, scale it so that it contains floats between $0$ and $1$, then store it as an attribute.\n    If the image is in color, compute its brightness matrix by averaging the RGB values at each pixel (if it is a grayscale image, the image array itself is the brightness matrix).\n    Flatten the brightness matrix into a 1-D array and store it as an attribute.\n\n    \\item Write a method called \\li{show_original()} that displays the original image.\n    If the original image is grayscale, remember to use \\li{cmap=\"gray\"} as part of \\li{plt.imshow()}.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{warn} % Do not use plt.imread() because it is inconsistent.\nMatplotlib's \\li{plt.imread()} also reads image files.\nHowever, this function automatically scales PNG image entries to floats between $0$ and $1$, but it still reads non-PNG image entries as 8-bit integers.\nTo avoid this inconsistent behavior, always use \\li{imageio.imread()} to read images and divide by $255$ when scaling is desired.\n\\end{warn}\n\n\\section*{Graph-based Image Segmentation} % ===================================\n\n\\emph{Image segmentation} is the process of finding natural boundaries in an image and partitioning the image along those boundaries (see Figure \\ref{fig:imgseg-segmentation-example}).\nThough humans can easily pick out portions of an image that ``belong together,'' it takes quite a bit of work to teach a computer to recognize boundaries and sections in an image.\nHowever, segmenting an image often makes it easier to analyze, so image segmentation is ongoing area of research in computer vision and image processing.\n\n\\begin{figure}[H] % Segmentation example.\n    \\centering\n    \\begin{subfigure}{.32\\textwidth}\n        \\includegraphics[width=\\textwidth]{figures/dream.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.32\\textwidth}\n        \\includegraphics[width=\\textwidth]{figures/dream_pos.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.32\\textwidth}\n        \\includegraphics[width=\\textwidth]{figures/dream_neg.pdf}\n    \\end{subfigure}\n\\caption{The image \\texttt{dream.png} and its segments.}\n\\label{fig:imgseg-segmentation-example}\n\\end{figure}\n\nThere are many ways to approach image segmentation.\nThe following algorithm, developed by Jianbo Shi and Jitendra Malik in 2000 \\cite{Shi2000}, converts the image to a graph and ``cuts'' it into two connected components.\n\n\\subsection*{Constructing the Image Graph} % ----------------------------------\n\nLet $G$ be a graph whose vertices are the $mn$ pixels of an $m\\times n$ image (either grayscale or color).\n% That is, vertex $i$ in $G$ represents the pixel at index $i$ when the image is flattened to a vector with $mn$ entries.\nEach vertex $i$ has a brightness $B(i)$, the grayscale or average RGB value of the pixel, as well as a coordinate location $X(i)$, the indices of the pixel in the original image array.\n\nDefine $w_{ij}$, the weight of the edge between pixels $i$ and $j$, by\n\\begin{equation}\n\\label{eq:imgseg-edge-weight}\nw_{ij} = \\begin{cases}\n\\exp\\left(-\\frac{|B(i) - B(j)|}{\\sigma_B^2}-\\frac{\\|X(i) - X(j)\\|}{\\sigma_X^2}\\right) & \\text{if}\\ \\|X(i) - X(j)\\| < r \\\\ 0 & \\text{otherwise,}\n\\end{cases}\n\\end{equation}\nwhere $r$, $\\sigma_B^2$ and $\\sigma_X^2$ are constants for tuning the algorithm.\nIn this context, $\\|\\cdot\\|$ is the standard \\emph{euclidean norm}, meaning that $\\|X(i) - X(j)\\|$ is the physical distance between vertices $i$ and $j$, measured in pixels.\n\nWith this definition for $w_{ij}$, pixels that are farther apart than the radius $r$ are not connected at all in $G$.\nPixels within $r$ of each other are more strongly connected if they are similar in brightness and close together (the value in the exponential is negative but close to zero).\nOn the other hand, highly contrasting pixels where $|B(i) - B(j)|$ is large have weaker connections (the value in the exponential is highly negative).\n\n\\begin{figure}[H] % The adjacency matrix. DO NOT DELETE. EVER.\n\\begin{tikzpicture}[dot/.style={circle,fill=black,minimum\n    size=4pt,inner sep=0pt,outer sep=-1pt}, >=stealth]\n%scale=.85, transform shape,\n\n%image\n\\draw[step=.75,thick](2.999,0)grid(6,3);\n%numbers 1-16\n\\foreach \\x in {0,1,2,3}\n    \\foreach \\y in {4}\n        \\node[draw=none, anchor=south west]at(\\x*.75+3.25, \\y-1.4){\\x};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+4)]in {0,1,2,3}\n    \\foreach \\y in {3}\n        \\node[draw=none, anchor=south west]at(\\x*.75+3.25, \\y-1.2){\\r};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+8)] in {0,1,2,3}\n    \\foreach \\y in {2}\n        \\node[draw=none, anchor=south west]at(\\x*.75+3.25, \\y-.95){\\r};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+12)] in {0,1,2,3}\n    \\foreach \\y in {1}\n        \\node[draw=none, anchor=south west]at(\\x*.75+3.25, \\y-.7){\\r};\n\n\\node[draw=none](image)at(4.5, -.5){\\emph{image}};\n\\node[draw=none](flattened)at(7.25,-3){\\emph{flattened image}};\n\\node[draw=none](adjacency)at(12,-3){\\emph{adjacency matrix} $A$};\n\n%dots within grid\n\\foreach \\x in {1,2,3,4}\n    \\foreach \\y in {1,2,3,4}\n        \\node[draw, dot]at(\\x*.75+2.6,\\y*.75-.4){};\n\n%color fill\n\\foreach \\x/\\y in {2/3.75, 1.25/3, 2/3, 2.75/3, 2/2.25} {\\node[draw, minimum\n    size=.75cm, fill=green!30!black, fill opacity=.25]at(\\x+2.118,\\y-1.118){};}\n\n%circle in image\n\\node[draw, circle, minimum size=2cm,thick](circle)at(4.13,1.86){};\n\n%flattened image\n\\draw[step=.5, thick](6.999,-2.5)grid(7.5,5.5);\n\\foreach \\x in {7}\n    \\foreach \\y in {0,...,15}\n        \\node[draw=none]at(\\x+.25,\\y*-.5+5.25){\\y};\n\n\\draw[->,thick](6.1, 1.5)--(6.9,1.5);\n\n%adjancey matrix\n\\draw[step=.5](7.9999,-2.5)grid(16,5.5);\n%\\draw[step=2,thick](7.999,-2.5)grid(16,5.5);\n\n%outside labels\n\\foreach \\x in {0,4,8,12} {\\node[draw=none]at(\\x*.5+8.25,5.8){\\x};}\n\\foreach \\y in {0,4,8,12}{\\node[draw=none]at(16.3,\\y*-.5+5.3){\\y};}\n\n%shading of boxes\n\\foreach \\x/\\y in {8.5/5.5, 9/5.5, 8.5/5, 9/5, 9.5/5,9/4.5,9.5/4.5,10/4.5,\n    9.5/4, 10/4, 10.5/5.5, 11/5,11.5/4.5, 12/4, 12.5/3.5,\n    13.5/2.5, 14/2, 14.5/1.5, 15/1, 15.5/.5,16/0, 10.5/3.5, 11/3.5, 11/2.5,\n    11.5/2.5,12/2.5, 11.5/2,12/2, 12.5/1.5, 13/1.5, 12.5/1, 13/1,\n    13.5/1,13/.5,13.5/.5,14/.5, 13.5/0,14/0, 14.5/-.5,15/-.5,14.5/-1,\n    15/-1,15.5/-1, 15/-1.5, 15.5/-1.5, 16/-1.5, 15.5/-2, 16/-2, 8.5/3.5,\n    9.5/2.5,10/2,10.5/1.5,11/1,11.5/.5,12/0, 12.5/-.5, 13/-1, 13.5/-1.5, 14/-2}\n    {\\node[draw, minimum size=.5cm, fill=black, fill opacity=.25]\n    at(\\x-.25,\\y-.25){};}\n\n%green shaded boxes\n\\foreach \\x/\\y in {9/3,11/3, 11.5/3, 10.5/3, 13/3} {\\node\n    [draw, minimum size=.5cm, fill=shadecolor]\n    at(\\x-.25,\\y-.25){};}\n\n\\node[draw=none]at(8.75,2.75){1};\n\\node[draw=none]at(10.25,2.75){4};\n\\node[draw=none]at(10.75,2.75){5};\n\\node[draw=none]at(11.25,2.75){6};\n\\node[draw=none]at(12.75,2.75){9};\n\\end{tikzpicture}\n\n\\caption{The grid on the left represents a $4\\times4$ ($m \\times n$) image with $16$ pixels.\nOn the right is the corresponding $16 \\times 16$ ($mn \\times mn$) adjacency matrix with all nonzero entries shaded.\nFor example, in row $5$, entries $1$, $4$, $5$, $6$, and $9$ are nonzero because those pixels are within radius $r=1.2$ of pixel $5$.}\n\\label{fig:imgseg-adjacency-tikz}\n\\end{figure}\n\nSince there are $mn$ total pixels, the adjacency matrix $A$ of $G$ with entries $w_{ij}$ is $mn\\times mn$.\nWith a relatively small radius $r$, $A$ is relatively sparse, and should therefore be constructed and stored as a sparse matrix.\nThe degree matrix $D$ is diagonal, so it can be stored as a regular 1-dimensional NumPy array.\nThe procedure for constructing these matrices can be summarized in just a few steps.\n\\begin{enumerate}\n    \\item Initialize $A$ as a sparse $mn\\times mn$ matrix and $D$ as a vector with $mn$ entries.\n    \\item For each vertex $i$ ($i=0,1,\\ldots,mn-1$),\n    \\begin{enumerate}\n        \\item Find the set of all vertices $J_i$ such that $\\|X(i) - X(j)\\| < r$ for each $j\\in J_i$.\n        For example, in Figure \\ref{fig:imgseg-adjacency-tikz} $i=5$ and $J_i = \\{1,4,5,6,9\\}$.\n        \\label{step:imgseg-neighborhood}\n        \\item Calculate the weights $w_{ij}$ for each $j\\in J_i$ according to (\\ref{eq:imgseg-edge-weight}) and store them in $A$.\n        \\item Set the $i$th element of $D$ to be the sum of the weights, $d_i = \\sum_{j\\in J_i}w_{ij}$.\n    \\end{enumerate}\n\\end{enumerate}\n\nThe most difficult part to implement efficiently is step \\ref{step:imgseg-neighborhood}, computing the neighborhood $J_i$ of the current pixel $i$.\nHowever, the computation only requires knowing the current index $i$, the radius $r$, and the height and width $m$ and $n$ of the original image.\nThe following function takes advantage of this fact and returns (as NumPy arrays) both $J_i$ and the distances $\\|X(i) - X(j)\\|$ for each $j\\in J_i$.\n\n% get_neighbors() helper function.\n\\begin{lstlisting}\ndef get_neighbors(index, radius, height, width):\n    \"\"\"Calculate the flattened indices of the pixels that are within the given\n    distance of a central pixel, and their distances from the central pixel.\n\n    Parameters:\n        index (int): The index of a central pixel in a flattened image array\n            with original shape (radius, height).\n        radius (float): Radius of the neighborhood around the central pixel.\n        height (int): The height of the original image in pixels.\n        width (int): The width of the original image in pixels.\n\n    Returns:\n        (1-D ndarray): the indices of the pixels that are within the specified\n            radius of the central pixel, with respect to the flattened image.\n        (1-D ndarray): the euclidean distances from the neighborhood pixels to\n            the central pixel.\n    \"\"\"\n    # Calculate the original 2-D coordinates of the central pixel.\n    row, col = index // width, index % width\n\n    # Get a grid of possible candidates that are close to the central pixel.\n    r = int(radius)\n    x = np.arange(max(col - r, 0), min(col + r + 1, width))\n    y = np.arange(max(row - r, 0), min(row + r + 1, height))\n    X, Y = np.meshgrid(x, y)\n\n    # Determine which candidates are within the given radius of the pixel.\n    R = np.sqrt(((X - col)**2 + (Y - row)**2))\n    mask = R < radius\n    return (X[mask] + Y[mask]*width).astype(np.<<int>>), R[mask]\n\\end{lstlisting}\n\nTo see how this works, consider Figure \\ref{fig:imgseg-adjacency-tikz} where the original image is $4\\times 4$ and the goal is to compute the neighborhood of the pixel $i = 5$.\n\n\\begin{lstlisting}\n# Compute the neighbors and corresponding distances from the figure.\n>>> neighbors_1, distances_1 = get_neighbors(5, 1.2, 4, 4)\n>>> print(neighbors_1, distances_1, sep='\\n')\n[1 4 5 6 9]\n[ 1.  1.  0.  1.  1.]\n\n# Increasing the radius from 1.2 to 1.5 results in more neighbors.\n>>> neighbors_2, distances_2 = get_neighbors(5, 1.5, 4, 4)\n>>> print(neighbors_2, distances_2, sep='\\n')\n[ 0  1  2  4  5  6  8  9 10]\n[ 1.41421356  1.          1.41421356  1.          0.          1.\n  1.41421356  1.          1.41421356]\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a method for the \\li{ImageSegmenter} class that accepts floats $r$ defaulting to $5$, $\\sigma_B^2$ defaulting to $.02$, and $\\sigma_X^2$ defaulting to $3$.\nCompute the adjacency matrix $A$ and the degree matrix $D$ according to the weights specified in (\\ref{eq:imgseg-edge-weight}).\n\nInitialize $A$ as a \\li{scipy.sparse.lil_matrix}, which is optimized for incremental construction.\nFill in the nonzero elements of $A$ one row at a time.\nUse \\li{get_neighbors()} at each step to help compute the weights.\n\\\\(Hint: Try to compute and store an entire row of weights at a time.\nWhat does the command \\li{A[5, np.array([1, 4, 5, 6, 9])] = weights} do?)\n\nFinally, convert $A$ to a \\li{scipy.sparse.csc_matrix}, which is faster for computations.\nThen return $A$ and $D$.\n\nUse \\li{blue_heart.png} to test $A$ and $D$, saved as \\texttt{HeartMatrixA.npz} and \\texttt{HeartMatrixD.npy} datafiles.\n\\label{prob:imgseg-compute-adjacency}\n\\end{problem}\n\n\\subsection*{Segmenting the Graph} % ------------------------------------------\n\nWith an image represented as a graph $G$, the goal is to now split $G$ into two distinct connected components by removing edges from the existing graph.\nThis is called \\emph{cutting} $G$, and the set of edges that are removed is called the \\emph{cut}.\nThe cut with the least weight will best segment the image.\n\nLet $D$ be the degree matrix and $L$ be the Laplacian matrix of $G$.\nShi and Malik \\cite{Shi2000} proved that the eigenvector corresponding to the second smallest\\footnote{Both $D$ and $L$ are symmetric matrices, so all eigenvalues of $D^{-1/2}LD^{-1/2}$ are real, and therefore ``the second smallest one'' is well-defined.} eigenvalue of $D^{-1/2}LD^{-1/2}$ can be used to minimize the cut: the indices of its positive entries are the indices of the pixels in the flattened image which belong to one segment, and the indices of its negative entries are the indices of the pixels which belong to the other segment.\nIn this context $D^{-1/2}$ refers to element-wise exponentiation, so the $(i,j)$th entry of $D^{-1/2}$ is $1/\\sqrt{d_{ij}}$.\n\nBecause $A$ is $mn\\times mn$, the desired eigenvector has $mn$ entries.\nReshaping the eigenvector to be $m \\times n$ allows it to align with the original image.\nUse the reshaped eigenvector to create a boolean mask that indexes one of the segments.\nThat is, construct a $m\\times n$ array where the entries belonging to one segment are \\li{True} and the other entries are \\li{False}.\n\n\\begin{lstlisting}\n>>> x = np.arange(-5,5).reshape((5,2)).T\n>>> print(x)\n[[-5 -3 -1  1  3]\n [-4 -2  0  2  4]]\n\n# Construct a boolean mask of x describing which entries of x are positive.\n>>> mask = x > 0\n>>> print(mask)\n<<[[False False False  True  True]\n [False False False  True  True]]>>\n\n# Use the mask to zero out all of the nonpositive entries of x.\n>>> x * mask\narray([[0, 0, 0, 1, 3],\n       [0, 0, 0, 2, 4]])\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a method for the \\li{ImageSegmenter} class that accepts an adjacency matrix $A$ as a \\li{scipy.sparse.csc_matrix} and a degree matrix $D$ as a 1-D NumPy array.\nConstruct an $m\\times n$ boolean mask describing the segments of the image.\n\\begin{enumerate}\n    \\item Compute the Laplacian $L$ with \\li{scipy.sparse.csgraph.laplacian()} or by converting $D$ to a sparse diagonal matrix and computing $L = D - A$ (do not use your function from Problem \\ref{prob:imgseg-laplacian} unless it works correctly and efficiently for sparse matrices).\n\n    \\item Construct $D^{-1/2}$ as a sparse diagonal matrix using $D$ and \\li{scipy.sparse.diags()}, then compute $D^{-1/2}LD^{-1/2}$.\n    Use \\li{@} or the \\li{dot()} method of the sparse matrix for the matrix multiplication, \\textbf{not} \\li{np.dot()}.\n\n    \\item Use \\li{scipy.sparse.linalg.eigsh()} to compute the eigenvector corresponding to the second-smallest eigenvalue of $D^{-1/2} L D^{-1/2}$.\n    Set the keyword arguments \\li{which=\"SM\"} and \\li{k=2} to compute only the two smallest eigenvalues and their eigenvectors.\n\n    \\item Reshape the eigenvector as a $m\\times n$ matrix and use this matrix to construct the desired boolean mask.\n    Return the mask.\n\\end{enumerate}\n\\label{prob:imgseg-compute-mask}\n\\end{problem}\n\nMultiplying the boolean mask component-wise by the original image array produces the \\emph{positive segment}, a copy of the original image where the entries that aren't in the segment are set to $0$.\nComputing the \\emph{negative segment} requires inverting the boolean mask, then multiplying the inverted mask with the original image array.\nFinally, if the original image is a $m \\times n \\times 3$ color image, the mask must be stacked into a $m \\times n \\times 3$ array to facilitate entry-wise multiplication.\n\n\\begin{lstlisting}\n>>> mask = np.arange(-5,5).reshape((5,2)).T > 0\n>>> print(mask)\n<<[[False False False  True  True]\n [False False False  True  True]]>>\n\n# The mask can be negated with the tilde operator ~.\n>>> print(~mask)\n<<[[ True  True  True False False]\n [ True  True  True False False]]>>\n\n# Stack a mask into a 3-D array with np.dstack().\n>>> print(mask.shape, np.dstack((mask, mask, mask)).shape)\n(2, 5) (2, 5, 3)\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a method for the \\li{ImageSegmenter} class that accepts floats $r$, $\\sigma_B^2$, and $\\sigma_X^2$, with the same defaults as in Problem \\ref{prob:imgseg-compute-adjacency}.\nCall your methods from Problems \\ref{prob:imgseg-compute-adjacency} and \\ref{prob:imgseg-compute-mask} to obtain the segmentation mask.\nPlot the original image, the positive segment, and the negative segment side-by-side in subplots.\nYour method should work for grayscale or color images.\n\nUse \\texttt{dream.png} as a test file and compare your results to Figure \\ref{fig:imgseg-segmentation-example}.\n\\end{problem}\n\n\\begin{comment} % TODO\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Products of Adjacency Matrices} % --------------------------------\n\n\\subsection*{Other Methods for Image Segmentation} % --------------------------\n\n\\end{comment}\n", "meta": {"hexsha": "c49d72f887441e25a83b7498abb5c5d5cc086d2e", "size": 35283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/ImageSegmentation/ImageSegmentation.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/ImageSegmentation/ImageSegmentation.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/ImageSegmentation/ImageSegmentation.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.4861660079, "max_line_length": 545, "alphanum_fraction": 0.6639741519, "num_tokens": 11541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8311430541321951, "lm_q1q2_score": 0.6527037723552712}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{cite}\n\\title{Notes on How Combinatorics Improves Tree Enumeration}\n\\begin{document}\n\\maketitle\n\n\\section{Graph Coloring Counting}\n\n\\noindent Definition\n\n\\noindent The chromatic function is a polynomial proved by deletion/contraction\ninduction.\n\n\\noindent Combinatorics gives us counting interpretations of the \\textit{coefficients}\nof the chromatic polynomial.  So the chromatic polynomial is a case of \na \\textbf{generating function} whose \\textit{values} $\\chi(G,n)$ are interesting.  \n\n\n\\section{Tutte Polynomial--Delection/Contraction}\n\n\\[\nT(G,x,y) = \\left\\{ \\begin{array}{ll}\n  x^{\\text{\\# isthmuses}}y^{\\text{\\# loops}} & \\text{if }G\\text{ contains loops or isthmuses only,}\\\\\n  T(G/e,x,y)+T(G\\setminus e,x,y) & \\text{if }e\\in E(G)\n     \\text{ is neither a loop nor an isthmus.}\n  \\end{array}\n  \\right\\}\n\\]\n\nChromatic specialization:\n\n\\[\n\\chi(G,n) = (-1)^{|V(G)|-k(G)}n^{k(G)}T(G,(1-n),0)\n\\]\n\nTutte's activities expansion:\n\\[\nT(G,x,y) = \\sum_{\\text{Bases A}}x^{|IA(A)|}y^{|EA(A)|}\n\\]\n\n\n\\section{Inclusion/Exclusion and Whitney's Solution}\n\n\\[\n\\chi(G,n) = \\sum_{k=0}^{k=|E|}(-1)^k \\text{\\# }n\\text{ colorings violating at least }\nk\\text{ edges}\n\\]\n\n\\[\n\\chi(G,n) = \\sum_{A\\subseteq E}(-1)^{|A|} \n(\\text{\\# }n\\text{ colorings violating at least the edges }A)\n\\]\n\n\\[\n\\chi(G,n) = \\sum_{A\\subseteq E}(-1)^{|A|}\nn^{|V(G/A)|} = n^{|V(G)|} + (\\text{polynomial in } n \\text{ of degree } < |V(G)|)\n\\]\nwhich establishes that $\\chi$ is a polynomial function.  \n\nWhitney\\cite{WhitLogExpMath} observed that \nmany pairs of terms, those for which $A$ contains at least \none \\textbf{broken circuit}, may be cancelled.\n\nIf $A$ contains circuit $C$ and $e\\in C$, then $V(G/A) = V(G/(A\\setminus e))$\n\nSo Whitney's idea was to impose a linear order on a subset $\\mathcal{B}$\nof the $A$'s occurring \nin the sum so that a pairing $\\{A,A'\\}$ of the members of $\\mathcal{B}$ \nis defined for which $\\{A,A'\\}=\\{A'\\cup e, A'\\}$, $e\\not\\in A'$ for some $e$\nand $k(G/A) = k(G/(A\\setminus e))$.  Two benefits result:\n\\begin{enumerate}\n\\item Many of the terms may be omitted.\n\\item The subsets $A$ for the remaining terms all have a simple form with the \nresult $|V(G/A)| = |V(G)| - |A| $.\n\n\\section{Posets, Inclusion/Exclusion and the Mobius Function}\n\nThe M\\\"{o}bius function emerges when the principle of inclusion/exclusion is\napplied to enumerations on elements of general posets.\n\n(I'll try a tutorial that directly relates the M\\\"{o}bius defining recurrance to\nsolving $g(x) = \\sum_{z\\le x}f(z)$ for $f()$.)\n\n(The resulting mathematical abstraction is Stanley's \n\\textbf{Incidence Algebra} of a poset\\cite{StanleyEC1}.)\n\nStanley: ``Hence M\\\"{o}bius inversion results in a simplification\nof Inclusion-Exclusion under appropriate circumstances. However, we shall also see that\nthe applications of M\\\"{o}bius inversion are much \nfurther-reaching than as a generalization of\nInclusion-Exclusion.'' \\cite[ch.~3]{StanleyEC1}.\n\n\n\\subsection{Characteristic Polynomial}\n\n\\[\n\\chi(G,n) = \\sum_{\\textbf{0}\\le z\\le \\textbf{1}}\\mu(\\textbf{0}, z)n^{|V(G)|-\\text{rank}(z)}\n\\]\nwhere the sum is over the geometric lattice of flats (closed subsets of edges)\nin the graphic matroid of $G$.  \n\nProof.  Each flat $z$ corresponds to a graph $G/A$ obtained by \ncontracting some\nsubset $A$ of edges and then removing the loops. \n(The edges in the flat are $A$ plus those removed loops.)\nThe number of unrestricted colorings of $G/A$ is $n^{V(G/A)-\\text{rank}(z)}$.\nThe number of legal colorings of each $G/A'$ is of course $\\chi(G/A',n)$.\nEach unrestricted coloring of $G/A$ corresponds to a unique legal coloring of\nthe graph obtained from $G/A$ by contracting the violated edges of $G/A$.  \nTherefore \n\\[\nn^{V(G/A)-\\text{rank}(z)} = \\sum_{z'\\ge z}\\chi(G/A',n).\n\\]\nThe formula for $\\chi(G,n)$ is the result of M\\\"{o}bius inversion because\n$G$ (with no edges contracted) corresponds to the bottom flat $\\textbf{0}$.\n\nFactoring out $n^{k(G)}$ gives us a polynomial function that generalizes \nto all finite lattices.\n$\\chi(G,n)=n^{k(G)}\\text{char}(\\mathcal{L},n)$ where\n\n\\[\n\\text{char}(\\mathcal{L},n) = \n\\sum_{z\\in\\mathcal{L}}\\mu(z,\\mathbf{1})n^{\\text{rank}(\\mathbf{1}) - \\text{rank}(z)}.\n\\]\n\n\\section{Broken Circuits in the Tutte Computation Tree}\n\nEvery GM computation tree partitions $2^{E(G)}$ into \nboolean intervals\\cite{GordonMcMachonGreedoid}.  The boolean\nintervals correspond to the leaves of the tree.  Each leaf is\ncharacterized by subsets of externally active elements\nEA and internally active elements IA.\n(not explained yet here at all).\nEach interval has cardinality $2^{|\\text{IA}|+|\\text{EA}|}$.\nThe broken-circuit-free subsets are those in the intervals for which\n$\\text{EA}=\\emptyset$.  Thus the subsets with broken circuits are partitioned\namong the intervals with $\\text{EA}\\neq\\emptyset$.  \n\nConsider an interval with $\\text{EA}\\neq\\emptyset$. It has the\nform $[A, A\\cup\\text{IA}\\cup\\text{EA}]$.  Let's further partition\nit into the $2^{|\\text{IA}|}$ subintervals $[A\\cup I, A\\cup I\\cup \\text{EA}]$, \n$I\\subseteq\\text{IA}$.    \n%We now observe, similarly to what Whitney observed, that\nWe now observe, like Whitney observed, that\n$v=V(G/S)$ is the same for all $S\\in[A\\cup I, A\\cup I\\cup \\text{EA}]$.  The\ncontribution of these $S$ to $\\chi(G,n)$ is $n^v\\sum_S(-1)^{|S|}$ $=$\n$n^v(-1)^{|A\\cup I|}(1-1)^{|EA|}$.\n\nThe bases also correspond to the leaves of the GM computation tree.\nThe interval $[A,A\\cup \\text{IA}\\cup\\text{EA}]$ corresponds to basis\n$A\\cup\\text{IA}$.  $A$ is the set of elements contracted on the path from the \nroot to the leaf.  Of course the cobasis is $\\overline{A}\\cup\\text{EA}$ where\n$\\overline{A}$ is the set of elements deleted on the path from the root to the \nleaf.\n\n\n\n\\section{The Broken Circuit Complex}\n\n\\cite{BrokenCctComplexBryl}\n\nThe ``broken-circuit complex'' is the simplicial complex of sets that do not contain\nany broken circuits.  The $f$-vector codes the number of faces of each dimension, ie., \ncardinality $-1$.\nThe coefficients of the chromatic polynomial (characteristic poly in general)\nare the $f$-vector of the broken-circuit complex.\n\n\\section{Activities}\n\n(Goal: Get at the facts about activities being h-vectors of broken-circuit complexes or \nsomething.)\n\n\n\\[\n\\sum_{i=0}^d f_i(x-1)^{d-i}\n=\n\\sum_{i=0}^d h_i(x)^{d-i}\n\\]\n\n??What expansion of $\\chi$ in $n$ = expansion of $\\chi$ in $n-1$?\n\n \n\nTutte's expansion:\n\\[\nT(G,x,y) = \\sum_{\\text{Bases} A\\subseteq E(G)}x^{|IA(A)|}y^{|EA(A)|}\n\\]\n\nSet expansion:\n\\[\nT(G,x,y) = \\sum_{A\\subseteq E(G)}(x-1)^{k(A)-k(E)}(y-1)^{k(A) + |A| - |V|}\n\\]\n\n\\[\n\\chi(G,n) = (-1)^{|V|-k(G)}n^{k(G)}T(G,1-n,0)\n\\]\n\n\\[\n\\chi(G,n) = \\sum_{A \\text{ contains no broken circuits}}\n            (-1)^{|A|}n^{|V|-|A|}\n\\]\n\n\n\\[\n\\chi(G,n) = (-1)^{|V|-k(G)}n^{k(G)}\\sum_{A\\subseteq E(G)}(-n)^{k(A)-k(E)}(-1)^{k(A) + |A| - |V|}\n\\]\n\n\\[\n\\chi(G,n) = (-1)^{|V|}(-1)^{k(G)}n^{k(G)}\\sum_{A\\subseteq E(G)}(-n)^{k(A)}(-n)^{-k(E)}(-1)^{k(A)}(-1)^{|A|}(-1)^{|V|}\n\\]\n\nWe get from ... Whitney's starting point for inclusion/exclusion:\n\\[\n\\chi(G,n) = \\sum_{A\\subseteq E(G)}n^{k(A)}(-1)^{|A|}\n\\]\n\n\n\n(Bigger Goal: Extend that to GM activities, based on a computation tree.  Try to find \nthe more generalized broken circuit complex, if possible!)\n\n\\section{Applications}\n\nWhy are general computation tree orders better?  Suppose an electrical network has resistors\nA, B, and C.  Properties of $N/A$ may depend more on $B$ than $C$, while properties of\n$N\\setminus A$ may depend more on $C$ than $B$. EG: $N=(A \\text{ ser } B) \\text{ par } C$.\n$N/A = B \\text{ par } C$, but $N\\setminus A = C$.  If $g(B) >> g(C)$, \n$g(N/A) = g(B) + g(C) \\approx g(B)$\nbut $g(N\\setminus A) = g(C)$ \n\n\\[\nR(N) = \\frac{g(A)+g(B)}{g(A)g(B)+g(A)g(C)+g(B)g(C)}\n\\]\n\n\\[\nR(N/A) = \\lim_{g(A)\\rightarrow\\infty}R(N) = \\frac{1}{g(B)+g(C)}\n\\]\n\n\\[\nR(N\\setminus A) = \\lim_{g(A)\\rightarrow 0}R(N) = \\frac{g(B)}{g(B)g(C)} = \\frac{1}{g(C)}\n\\]\n\n\n\\section{Topology, $f$\\&$h$ vectors and all that}\n\nThis is addressed by Ellis-Monaghan and Merino\n\\cite{JEM-MerinoGraphPolyAppI}. \n\n\n\n\n\n\n\nFROM \n``Monomial Bases for Broken Circuit Complexes''\nby Jason Brown and  Bruce Sagan\n\\cite{MonBasesBrkCircCompBrownSagan}\n\\begin{quote}\nLet E be a finite set and let $\\Delta$\nbe an abstract simplicial complex on E, ...\n\nLet $f_i = f_i(\\Delta)$ be the number of $S \\in \\Delta$ with\n$|S| = i$. Then $\\Delta$ has f-vector\n$f = f(\\Delta) = (f_0, f_1, . . . , f_r)$\nas well as f-polynomial\n$f(x) = f_{\\Delta}(x) = f_0 + f_1x + · · · + f_rx^r$\nwhere $x$ is a variable. \n\n...\n\nAnother important invariant of $\\Delta$ is its $h$-vector. Define a polynomial\n\\[\nh(x) := (1 - x)^r f(\\frac{x}{1-x})\n\\]\n\\[\n= f_0(1 - x)^r + f_1x(1 - x)^{r-1} + f_2x^2(1-x)^{r-2} + ... + f_rx^r. \n\\]\n\nLet $h_i$ be the coefficient of $x_i$ in h(x) so that \n\n...\n\\end{quote}\n\nJason Brown and  Bruce Sagan go on to give an combinatorial interpretation\nof $h_i$ when $f(-\\lambda)=\\pm$chromatic polynomial's Whitney's expansion.\nIt uses that Cohen-Macauly stuff.\n\nBruce and R. Bloka did a line of research following Las Vergnas' \n\\cite{ActOrdersMatrBasesLasVergnas} on \ntopology of complexes defined in terms of linearly-defined activities\n\\cite{ActTopPropBlokaSagan}.  In his paper, \nLas Vergnas did 3 different complexes? \nand a lattice ordering of matroid bases, \nand wondered why M\\\"{o}bius function values in the lattice were zero.\n\n\n\n\n\n\n\n\\section{Literature}\n\nNew! Doman and Trinks \\cite{DohmenTrinksAbsWitBrok}, paper citing\nDoman's proof \\cite{DohIndProofMatroids}.\n\nMaybe an application clue from Urschel (who's also into football) et. al.\nbecause the abstract mentions a ``heavy edge coarsening scheme''\n\\cite{UrschelFiedlerGraphLaplac}.\n\n\\end{enumerate}\n\\bibliographystyle{plain}\n\\bibliography{../../bib/MathOfElec}\n\\end{document}\n\n", "meta": {"hexsha": "daf93e9c67af7bb24fd042b761d7450b094dda59", "size": 9725, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "drafts/activities/mathenum.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": "drafts/activities/mathenum.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": "drafts/activities/mathenum.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": 30.5817610063, "max_line_length": 117, "alphanum_fraction": 0.6717737789, "num_tokens": 3292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6525771351297576}}
{"text": "\\section{What is optimisation?}\n\n\n\\begin{frame}{What is optimisation?}\n\n\tDiscipline of applied mathematics. The idea is to search values for \\alert{variables}\\hspace{-1pt} in a given \\alert{domain} that\\hspace{-1pt} maximise/minimise\\hspace{-1pt} \\alert{function values}. \n\t\n\tCan be achieved by \n\t\\begin{itemize}[<+->]\n\t\\item Analysing properties of functions \\hspace{-1pt}/ extreme points or\n\t\\item Applying numerical methods \n\t\\end{itemize}\n\t\\onslide<+->\n\t\n\tOptimisation has important applications in fields such as \n\t%\n\t\\begin{itemize}\n\t\\item {\\bf operations research (OR)};\n\t\\item economics;\n\t\\item statistics; \n\t\\item machine learning and artificial intelligence.\n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\subsection{Mathematical programming and optimisation}\n\n\n\\begin{frame}{What is optimisation?}\n\n\tIn this course, optimisation is viewed as the core element of \\alert{mathematical programming}.\n\t\n\tMath. programming is a central OR modelling paradigm:\n\t\\begin{itemize}[<+->]\n\t\\item {\\bf variables} $\\rightarrow$ decisions: business decisions, parameter definitions, settings, geometries, ...;\n\t\\item {\\bf domain} $\\rightarrow$ constraints: logic, design, engineering, ...;\n\t\\item {\\bf function} $\\rightarrow$ objective function: measurement of (decision) quality. \n\t\\end{itemize}\n\t\n\t\\onslide<+->\n\tHowever, math. programming has many applications in fields other than OR, \\alert{which causes some confusion}; \n\t\n\tWe will study math. programming in its most general form: both constraints and objectives are \\alert{nonlinear} functions.\n\n\\end{frame}\n\n\n\\begin{frame}\n\t\\centering\n\t\\includegraphics[scale=0.09]{Figures/Books.jpg}\n\n\\end{frame}\n\n\n\\subsection{Types of mathematical optimisation models}\n\n\n\t\\begin{frame}{Types of programming}\n\t\n\tThe \\alert{simpler are the assumptions} which define a type of problems, the better are the \\alert{methods to solve such problems}.\n\t\n\t\\pause\n\t\n\tSome useful notation:\n\t\n\t\\begin{itemize}[<+->]\n\t\t\\item $x \\in \\reals^n$ - vector of (decision) variables $x_j$, $j = 1,\\dots, n$;\n\t\t\\item $f:\\reals^n \\rightarrow \\reals \\cup \\braces{\\pm \\infty}$ - objective function;\n\t\t\\item $X \\subseteq \\reals^n$ - ground set (physical constraints);\n\t\t\\item $g_i, h_i : \\reals^n \\rightarrow \\reals$ - constraint functions; \n\t\t\\item $g_i(x) \\leq 0$ for $i = 1, \\dots, m$ - inequality constraints;\n\t\t\\item $h_i(x) = 0$ for $i = 1, \\dots, l$ - equality constraints.\n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}{Types of programming}\n\n\tOur goal will be to solve variations of the general problem $P$:\n\t%\n\t\\begin{align*}\n\t\t(P) :~ \\mini \\ & f(x) \\\\\n\t\t\\st & g_i(x) \\leq 0, i = 1, \\dots, m\\\\\n\t\t& h_i(x) = 0, i = 1, \\dots, l \\\\\n\t\t& x \\in X.\n\t\\end{align*}\n\t%\n\t\\pause\n\t\\vspace{-24pt}\n\t\\begin{itemize}\n\t\\item {\\bf Linear programming (LP):} \\alert{linear} $f(x) = c^\\top x$ with $c \\in \\reals^n$; constraint functions $g_i(x)$ and $h_i(x)$ are \\alert{affine} ($a_i^\\top x - b_i$, with $a_i \\in \\reals^n$, $b \\in \\reals$); $X = \\braces{ x \\in \\reals^n : x_j \\geq 0, j =1,\\dots,n}$.  \n\t\\pause\n\t\\item {\\bf Nonlinear programming (NLP):} some (or all) of the functions $f, g_i$ or $h_i$ are \\alert{nonlinear};\n\t\\pause\n\t\\item {\\bf (Mixed-)integer programming ((M)IP):} LP where (some of the) variables are \\alert{binary (or integer)}. $X \\subseteq \\reals^k \\times \\braces{0,1}^{n-k}$ \n\t\\pause \n\t\\item {\\bf Mixed-integer\\hspace{-1pt} nonlinear\\hspace{-2pt} programming\\hspace{-2pt} (MINLP):}\\hspace{-1pt} {\\small MIP\\hspace{-3pt} +\\hspace{-3pt} NLP.} \n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\section{Applications}\n\n\n\\subsection{Resource allocation}\n\n\n\\begin{frame}{Resource allocation and portfolio optimisation}\n\n\t{\\bf Problem statement.} Plan production that maximises return. Let\n\t\\begin{columns}\n\t\t%% Juho\n\t\t\\column{0.64\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item {\\small $I = \\braces{1, \\dots, i, \\dots, M}$} resources; \n\t\t\t\\item {\\small $J = \\braces{1, \\dots, j, \\dots, N}$} products;\n\t\t\t\\item $c_j$ - return per unit of product $j\\in J$;\n\t\t\t\\item $a_{ij}$ - resource $i\\in I$ requirement for making product $j\\in\\hspace{-1pt} J$ ;\n\t\t\t\\item $b_i$ - availability of resource $i\\in I$; \n\t\t\t\\item $x_j$ - production of $j \\in J$.\n\t\t\\end{itemize}\n\t\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\pause\n\t\t\\begin{align*}\n\t\t\t\\maxi \\ & \\sum_{j \\in J} c_jx_j \\\\\n\t\t\t\\st & \\sum_{j \\in J}a_{ij}x_j \\leq b_i, \\forall i \\in I\\\\\n\t\t\t& x_j \\geq 0, \\forall j \\in J\n\t\t\\end{align*} \n\t\\end{columns}\n\t\\pause\n\t\\vfill\n\t{\\bf Remark:} \n\t\\vspace{-6pt}\n\t\\begin{itemize}[<+->]\n\t\t\\item notice that $\\maxi f(x) = \\mini - f(x)$;\n\t\t\\item the base of \\alert{most practical optimisation problems}; exploits mature LP technology.\n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}{Portfolio optimization}\n\n\t{\\bf Problem statement.} Plan portfolio of assets to minimise exposition to risk. Let\n\t\\begin{columns}\n\t\t\\column{0.5\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item {\\small $J = \\braces{1, \\dots, j, \\dots, N}$} assets;\n\t\t\t\\item $\\mu_j$ - expected relative return of asset $j \\in J$;\n\t\t\t\\item $\\Sigma$ - covariance matrix;\n\t\t\t\\item $\\epsilon$ - minimum expected return;\n\t\t\t\\item $x_j$ - position of asset $j \\in J$\n\t\t\\end{itemize}\n\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\pause\n\t\t\\begin{align*}\n\t\t\t\\mini \\ &  x^\\top\\Sigma x  \\\\\n\t\t\t\\st & \\mu^\\top x  \\geq \\epsilon\\\\\n\t\t\t& 0 \\leq x_j \\leq 1, \\forall j \\in J\n\t\t\\end{align*} \n\t\\end{columns}\n\t\\vfill\n\t\\pause\n\t{\\bf Remarks:} \n\t\\vspace{-6pt}\n\t\\begin{itemize}\n\t\t\\item The term $x^\\top\\Sigma x$ measures \\alert{exposition to risk}. It is credited to Harry Markowitz (1952).\n\t\t\\item Another important class: \\alert{quadratic programming} (nonlinear).\n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\subsection{The pooling problem: refinery operations planning}\n\n\n\\begin{frame}{Refinery Operations Planning Problem}\n\n\t\\begin{columns}\n\t\t\\column{0.6\\textwidth}\n\t\t{\\bf Oil refinery operational planning}\n\t\t\\begin{itemize}\n\t\t\t\\item Goal is to maximize profit;\n\t\t\t\\item Several possible configurations;\n\t\t\t\\item \\alert{Product property specifications} must be met;\n\t\t   \\end{itemize}\n\t\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\begin{figure}\n\t\t\t\\includegraphics[width=\\linewidth]{figures/Refinery.png}\n\t\t\\end{figure}\n\t\\end{columns}\n\t\\pause\n\t\\begin{columns}\n\t\t\\column{0.6\\textwidth}\n\t\t{\\bf Model characteristics:}\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item \\alert{Bilinear (nonconvex) and mixed-integer};\n\t\t\t\t\\item Large number of flows;\n\t\t\t\t\\item Several nonlinear constraints.\n\t\t    \\end{itemize}\n\t\t\\column{0.4\\textwidth}\n\t\t\\begin{figure}\n\t\t\t\\includegraphics[width=\\linewidth]{figures/RefinerySchema.png}\n\t\t\\end{figure}\n\t\\end{columns}\n\n\\end{frame}\n\n\n\\begin{frame}{Refinery Operations Planning Problem}\n\n\t\\begin{columns}\n\t\t\\column{0.65\\textwidth}\n\t\t\n\t\t{\\bf Objective:} maximize profit\n\t\t\n\t\t{\\bf Variables:}\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Stream Flows {\\footnotesize(crude, intermediate and final products)};\n\t\t\t    \\item Storage;\n\t\t\t    \\item Stream properties.\n\t\t    \\end{itemize}\n\t\t\\onslide<2->{\n\t\t\n\t\t{\\bf Constraints}\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Mass balance;\n\t\t\t    \\item Market features (supply and demand);\n\t\t\t    \\item Unit capacities;\n\t\t\t    \\item Stream property limits;\n\t\t\t    \\item \\alert{Calculation of mix properties (nonlinear)}.\n\t\t    \\end{itemize}}\n\t\t\\column{0.4\\textwidth}\n\t\t% Second column\n\t\t\\begin{figure}\n\t\t\t\\includegraphics[width=\\linewidth]{figures/Refinery.png}\n\t\t\\end{figure}\n\t\t\\begin{figure}\n\t\t\t\\includegraphics[width=\\linewidth]{figures/RefinerySchema.png}\n\t\t\\end{figure}\n\t\\end{columns}\n\\end{frame}\n\n\n\\begin{frame}{Refinery Operations Planning Problem}\n\n\tThe challenging aspect is how to model the calculation of product properties in a \\alert{mix}. Let:\n\t\n\t\\begin{itemize}\n\t\t\\item $x_p$ be the volume of product $p \\in P$ and\n\t\t\\item $q_p$ the value of a given chemical property (sulphur content, octane content, viscosity...).\n\t\\end{itemize}\n\t%\n\tIn a given mix, mass and property balances are calculated as:\n\t\n\t\\begin{columns}\n\t\t\\column{0.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{Figures/Mixer.pdf}\n\t%\n\t\t\\column{0.5\\textwidth}\n\t\t%\n\t\t\\begin{align*}\n\t\t& x_A = x_B + x_C \\\\ \n\t\t& q_A = \\frac{q_Bx_B + q_Cx_C}{x_A}  \n\t\t\\end{align*}\n\t%\n\t\\end{columns}\n\t\\pause\n\t{\\bf Remarks:}\n\t\\vspace{-6pt} \n\t\\begin{itemize}\n\t\t\\item More complex mixes (such as nonlinear balances) might need to be considered.\n\t\t\\item These are \\alert{bilinear programming} problems (nonlinear).\n\t\\end{itemize}\n\\end{frame}\n\n\n\\subsection{Robust optimisation}\n\n\n\\begin{frame}{Robust optimisation}\n\t\n\tIs a subarea of mathematical programming concerned with \\alert{uncertainty in the input data}.\n\t\n\tIt's a risk-averse perspective that seeks \\alert{protection against variability}.\n\t\n\t\\pause\n\t\n\tConsider the resource allocation problem under uncertainty:\n\t%\n\t\\begin{align*}\n\t\t\\maxi \\ &  c^\\top x \\\\\n\t\t\\st & \\tilde{a}_{i}^\\top x \\leq b_i, \\forall i \\in I\\\\\n\t\t& x_j \\geq 0, \\forall j \\in J,\n\t\\end{align*}\n\t\n\twhere $\\tilde{a}_{i}$ is a \\alert{random variable}.\n\n\\end{frame}\n\n\n\\begin{frame}{Robust optimisation}\n\n\t\\includegraphics[width = 1\\textwidth]{Figures/data_no_ellipsoid.pdf}\n\n\\end{frame}\n\n\n\\begin{frame}{Robust optimisation}\n\n\tAssume that,\\hspace{-2pt} for\\hspace{-2pt} any\\hspace{-2pt} $i \\in I$, $\\tilde{a}_{i} \\in \\epsilon_i = \\braces{\\overline{a}_i + P_iu : ||u||_2 \\leq \\Gamma_i}$, where \n\t\\vspace{-6pt}\n\t\n\t\\begin{itemize}\n\t\t\\item $\\overline{a}_{i}$ is the nominal (average) value; \n\t\t%% Juho: I added the \\epsilon here\n\t\t\\item $P_i$ is the characteristic matrix of the ellipsoid $\\epsilon$;\n\t\t\\item $\\Gamma_i$ is risk-aversion control parameter.\n\t\\end{itemize}\n\t%\n\t\\pause\n\tThen, the \\alert{robust counterpart} can be stated as\n\t%\n\t\\begin{align*}\n\t\t\\maxi \\ &  c^\\top x \\\\\n\t\t\\st & \\maxi_{a_{i} \\in \\epsilon_i}\\braces{a_i^\\top x} \\leq b_i, \\forall i \\in I\\\\\n\t\t& x_j \\geq 0, \\forall j \\in J.\n\t\\end{align*}\n\t\\vspace{-6pt}\n\t%\n\t\\pause\n\tNotice that \n\t$$\n\t\\maxi_{a_{i} \\in \\epsilon_i}\\braces{a_i^\\top x} = \\overline{a}_i^\\top x + \\maxi_u\\braces{u^\\top P_i x : ||u||_2 \\leq \\Gamma_i} = \\overline{a}_i^\\top x + \\Gamma_i||P_i x||_2 \n\t$$\n\n\\end{frame}\n\n\n\\begin{frame}{Robust optimisation}\n\t%\n\tThe \\alert{robust counterpart} can be equivalently stated as:\n\t\\begin{align*}\n\t\t\\maxi \\ &  c^\\top x \\\\\n\t\t\\st & \\overline{a}_i^\\top x + \\Gamma_i||P_i x||_2 \\leq b_i, \\forall i \\in I\\\\\n\t\t& x_j \\geq 0, \\forall j \\in J.\n\t\\end{align*}\n\t%\n\t{\\bf Remarks:}\n\t\\begin{itemize}[<+->]\n\t\t\\item In case data is available, $P_i$ can be obtained from the \\alert{empirical covariance matrix};\n\t\t\\item Values of $\\Gamma_i$ can be drawn, for example, from a Chi-squared distribution. $\\Gamma_i$ is sometimes called the \\alert{budget of uncertainty}.\n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}{Robust optimisation}\n\n\t\\includegraphics[width = 1\\textwidth]{Figures/data_with_ellipsoid.pdf}\n\n\\end{frame}\n\n\n\\subsection{Classification: support vector machines}\n\n\n\\begin{frame}{Classification}\n\n\tSuppose we are given some data $D \\subset \\reals^n$ that can be \\alert{separated} into two sets in $\\reals^n$: $I^- = \\braces{x_1,\\dots, x_N}$ and $I^+ = \\braces{x_1,\\dots,x_M}$. \n\t\n\tEach element in $D$ is an \\alert{observation} of a given set of \\alert{features}; belonging to either $I^-$ or $I^+$ defines a \\alert{classification}.\n\t\n\t\\pause\n\tOur task is to select a function $f:\\reals^n \\rightarrow \\reals$ from a given family of functions such that\n\t$$\n\tf(x_i) < 0, \\ \\forall x_i \\in I^- \\text{ and } f(x_i) > 0, \\ \\forall x_i \\in I^+.\n\t$$ \n\tTypically, $f$ is selected as a \\alert{linear classifier}, i.e., $f(x_i) = a^\\top x_i - b$. \n\t\n\tOf course, there is always the possibility of \\alert{misclassification} and, therefore, we want to determine the \\alert{best} possible classifier.\n\n\\end{frame}\n\n\n\\begin{frame}{Classification}\n\n\t\\centering\n\t\\includegraphics[width = \\textwidth]{Figures/classes_with_classifier.pdf}\n\n\\end{frame}\n\n\n\\begin{frame}{Classification}\n\n\tLet us define the following \\alert{error measures}:\n\t{\\small\n\t\\begin{align*}\n\t\t& e^-(x_i \\in I^-; a, b) := \\begin{cases} 0, \\text{ if } a^\\top x_i - b \\leq 0, \\\\\n\t                                a^\\top x_i - b, \\text{ if } a^\\top x_i - b > 0.\n\t                   \\end{cases} \\\\\n\t\t& e^+(x_i \\in I^+; a, b) := \\begin{cases} 0, \\text{ if } a^\\top x_i - b \\geq 0, \\\\\n\t                                b -  a^\\top x_i, \\text{ if } a^\\top x_i - b < 0.\n\t                   \\end{cases}                   \n\t\\end{align*}}% \n\t\\pause\n\tUsing \\alert{slack variables} $u_i$, $i = 1,\\dots,M$, and $v_i$, $i = 1,\\dots,N$, to represent $e^-$ and $e^+$, the optimal classifier is obtained from:\n\t{\\small\n\t\\begin{align*}\n\t\t(LC) :~ \\mini \\ & \\sum_{i=1}^M u_i + \\sum_{i=1}^N v_i \\\\\n\t\t\\st & a^\\top x_i - b - u_i \\leq 0, i = 1,\\dots,M \\\\\n\t\t& a^\\top x_i - b + v_i \\geq 0, i = 1,\\dots,N \\\\\n\t\t& ||a||_2 = 1\\\\\n\t\t&u_i \\geq 0, i = 1,\\dots,M; v_i \\geq 0, i = 1,\\dots,N; a \\in \\reals^n, b \\in \\reals.\n\t\\end{align*}}\n\t%\n%\t{\\bf Remark:} notice that $||a||_2 = 1$ avoids $(a,b) = (0,0)$. \n\\end{frame}\n\n\n\\begin{frame}{Classification}\n\n\tIn practice, we can enforce a \\alert{slab} $S = \\braces{-1 \\leq a^\\top x_i- b \\leq 1}$ as a buffer to trade off the \\alert{robustness} of the classifier to outliers. \n\t\n\tAccordingly, we redefine our error measures as follows. \n\t%\n\t\\begin{align*}\n\t& e^-(x_i \\in I^-; a, b) := \n\t    \\begin{cases} 0, \\text{ if } a^\\top x_i - b \\leq -1, \\\\\n\t        a^\\top x_i - b, \\text{ if } a^\\top x_i - b > -1.\n\t    \\end{cases} \\\\\n\t& e^+(x_i \\in I^+; a, b) := \n\t    \\begin{cases} 0, \\text{ if } a^\\top x_i - b \\geq 1, \\\\\n\t        b -  a^\\top x_i, \\text{ if } a^\\top x_i - b < 1.\n\t    \\end{cases}                   \n\t\\end{align*}\n\t%\n\t\\pause\n\t$e^-$ and $e^+$ include \\alert{misclassifications} and \\alert{correct classifications that lie within $S$}. The latter are know as \\alert{support vectors}.\n\t\n\tThe \\alert{width of $S$ is given by $2/||a||_2$}, which is the distance between the hyperplanes $a^\\top x_i - b = -1$ and $a^\\top x_i - b = 1$.\n\t\n\\end{frame}\n\n\n\\begin{frame}{Classification}\n\n\tThe robust version of $LC$ incorporating this buffer becomes   \n\t%\n\t\\begin{align*}\n\t\t\\mini \\ & \\sum_{i=1}^M u_i + \\sum_{i=1}^N v_i + \\gamma||a||_2^2\\\\\n\t\t\\st & a^\\top x_i - b - u_i \\leq -1, \\ i = 1,\\dots,M \\\\\n\t\t& a^\\top x_i - b + v_i \\geq -1, \\ i = 1,\\dots,N \\\\\n\t\t& u_i \\geq 0, i = 1,\\dots,M; v_i \\geq 0, i = 1,\\dots, N; \\\\\n\t\t& a \\in \\reals^n, b \\in \\reals.\n\t\\end{align*} \n\t\\pause\n\t{\\bf Remarks:}\n\t\\vspace{-6pt}\n\t\\begin{itemize}[<+->]\n\t\t\\item The parameter $\\gamma$ controls the \\alert{trade-off} between the width of the slab $S$ and the number of observations within the slab.\n\t\t\\item This quadratic programming problem is known in the machine learning literature as \\alert{support vector machine} (SVM).\n\t\\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}{Classification}\n\n\t\\centering\n\t\\includegraphics[width = \\textwidth]{Figures/classes_with_robust_classifier.pdf}\n\n\\end{frame}\n", "meta": {"hexsha": "40026840a4cc06bd66a1c0aa36f4eceffa273477", "size": 14572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/lectures/Lecture_1/Lecture_1-slide_content.tex", "max_stars_repo_name": "gamma-opt/CourseParser.jl", "max_stars_repo_head_hexsha": "be59cf09c2c8b34373a6cd0f972f46528c4233dc", "max_stars_repo_licenses": ["MIT"], "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/lectures/Lecture_1/Lecture_1-slide_content.tex", "max_issues_repo_name": "gamma-opt/CourseParser.jl", "max_issues_repo_head_hexsha": "be59cf09c2c8b34373a6cd0f972f46528c4233dc", "max_issues_repo_licenses": ["MIT"], "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/lectures/Lecture_1/Lecture_1-slide_content.tex", "max_forks_repo_name": "gamma-opt/CourseParser.jl", "max_forks_repo_head_hexsha": "be59cf09c2c8b34373a6cd0f972f46528c4233dc", "max_forks_repo_licenses": ["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.2952182952, "max_line_length": 279, "alphanum_fraction": 0.6529645896, "num_tokens": 5082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6525771341871122}}
{"text": "\n\n\n\\chapter{Some continuity and monotonicity properties of the GNK value}\\label{appendix:continuity_of_GNK}\n\nFrom inspection of equations \\ref{knvalue1} and \\ref{da_value_eq} it defined that the GNK value is a summation over maximum of minimum terms and it should be rather evident that there is present some nice continuity properties:\n\n\\begin{theorem}[GNK continuous with utilities]\nFor utility functions $u_i(x,y)$ if we consider any bounded perturbations $\\epsilon \\Delta_i(x,y)$ then the GNK value is continuous with $\\epsilon$.\n\\end{theorem}\n\\begin{proof}\nTo demonstrate that the GNK value is continuous with change in utility functions we consider that for all $(x,y)\\in A$ we consider any set of utility perturbing functions $\\Delta_i(x,y)$ with a magnitude $\\max_{(x,y)\\in A, i\\in N}|\\Delta_i(x,y)| = d$.\nFor any coalition $S$, if we consider that advantage $v(S)$ with the original utility functions as $v_u(S)$ and with the perturbed utility function multiplied by a parameter $\\epsilon$ as $v_{u+\\epsilon \\Delta}(S)$ then we can realise that:\n$$-n\\epsilon d \\le v_u(S)-v_{u+\\epsilon \\Delta}(S) \\le n\\epsilon d$$\nTherefore for any individual $i\\in N$ the average over the advantage terms $v(S)$ for coalitions which include $i$ of size $k$ is similarly bounded.\n$$-n\\epsilon d \\le \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_u(S)-\\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_{u+\\epsilon \\Delta}(S) \\le n\\epsilon d$$\nTherefore the average of these terms over sizes $k=1\\dots n$ is also bounded.\n$$-n\\epsilon d \\le \\frac{1}{n}\\sum_{k=1}^n \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_u(S)-\\frac{1}{n}\\sum_{k=1}^n \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_{u+\\epsilon \\Delta}(S) \\le n\\epsilon d$$\nWhich is the difference in the GNK value for an individual $i$ between the perturbed and unperturbed utility function.\nThus for any prospective utility perturbation $\\Delta$ with a magnitude $d$ there is a $\\delta$ ($=n\\epsilon d$) such that there exists a perturbation factor $\\epsilon$, such that if the utility functions are $\\epsilon$ perturbed then the GNK value is $\\delta$ bounded.\n\\end{proof}\n\nThis continuity property for utilities is potentially nice in that participants in a system under GNK, can be be assured that regardless of their bids, that small difference in their utility bids will not yield large differences in their utility payoff, this adds regularity and predictability to the system.\nConversely for a potential operator of such a hypothetical GNK system, that this continuity property may add to the predictability of the system.\n\nThe GNK also has elementary monotonicity properties that are partially inherited from its relation to the Shapley Value.\n\n\\begin{theorem}[GNK is monotonic]\\label{thm:monotonicity}\nIf we consider advantage functions $v$ and $v'$ and the GNK value with those advantage function $\\varphi^v_i$ and $\\varphi^{v'}_i$.\nThen for any individual $i\\in N$, if all coalitions $S$ such that $i\\in S$ it is true that $v'(S)\\ge v(S)$ then $\\varphi^{v'}_i \\ge \\varphi^v_i$.\n\\end{theorem}\n\\begin{proof}\n$$\\varphi^v_i = \\frac{1}{n}\\sum_{k=1}^n \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v(S) \\le \\frac{1}{n}\\sum_{k=1}^n \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v'(S) =\\varphi^{v'}_i$$\n\\end{proof}\n\nThis monotonicity property ensures that individuals which have uniformly higher payoff advantages are afforded more utility under the GNK, which is a basic regularity reminiscent of the logic of the GNK value itself.\nParticularly, as the GNK value is an articulation of a bargaining solution concept, then individuals who have greater leverage in negotiation will (or should) have an outcome more favourable to them.\nConversely, we could imagine the potential absurdity of a system opposite were true, in that individuals with greater leverage in bargaining would be afforded less. \n\n\nIn considering this monotonicity property, we can ask what changes in strategies and/or utility functions and network constraints yield this kind of monotonicity condition. The most direct case is shift invariance, which is inherited from Nash bargaining roots \\cite{nash2} and directly stated as an axiom in the case of the `coco' value \\cite{kalai1}.\n\n\\begin{theorem}[GNK is shift invariant]\\label{thm:appendix_shift_invariant}\nFor any two utility profiles $u^1_i(x,y)$ and $u^2_i(x,y)$, and GNK defined by these utility profiles $\\varphi_i^1$ and $\\varphi_i^2$.\nThen for any individual $i\\in N$, if $u_i^2(x,y) = u_i^1(x,y)+c$ for some constant $c$, and for all $j\\neq i$ that $u^2_i(x,y) = u^1_i(x,y)$, then $\\varphi_i^2 = \\varphi_i^1+c$ \n\\end{theorem}\n\\begin{proof}\nIf we consider advantage functions $v_1$ and $v_2$ defined by utility functions $u^1_i(x,y)$ and $u^2_i(x,y)$ then for any coalition $S$ including individual $i$:\n\\begin{align}\nv_2(S) = &\n\\frac{1}{2}\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}(x,y)\\in A}} \\left[\n\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}\\exists y,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y)+c - \\sum_{i\\in N\\setminus S}u_i^2(x,y)\\right)\\right]\\nonumber\\\\\n& +\n\\frac{1}{2}\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}(x,y)\\in A}} \\left[\n\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}\\exists x,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y)+c - \\sum_{i\\in N\\setminus S} u_i^2(x,y) \\right) \\right]\\nonumber\\\\\n&= v_1(S)+c\\nonumber\n\\end{align}\nThe above step simply brings the additive constant out the front of the max and min terms.\nTherefore for every coalition $S$ which includes individual $i$ of size $k$, $v_2(S)=v_1(S)+c$, therefore the average of these values over such coalitions has a similar relation.\n$$\\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_2(S) = \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_1(S) + c$$\ntherefore the average of these averages over sizes of coalitions $k=1\\dots n$ is again similar:\n$$\\frac{1}{n}\\sum_{k=1}^n \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_2(S) = \\frac{1}{n}\\sum_{k=1}^n \\frac{1}{\\binom{n-1}{k-1}} \\sum_{\\substack{S:i\\in S \\\\ |S|=k}}v_2(S) + c$$\nwhich is to say that $\\varphi_i^2 = \\varphi_i^2+c$.\n\\end{proof}\n\nShift invariance is important but not particularly interesting property. It more-or-less identifies that a participant who affords a higher utility should be rewarded with a GNK value which is that same degree higher.\nThis Shift invariance relation is essentially consistent with the idea that utility functions are invariant to affine transformation, more particularly translation.\nIf a participant modifies his/her utility function by an offset, this GNK value will afford that individual with exactly the same physical outcomes and utility transfers to give them a net utility that is that same extent offset.\nThis shift invariance property is good sanity check on a minimally sufficient bargaining solution concept.\n\nSo instead we also consider a very similar monotonicity property with regards to any utility perturbation that non-decreases a player's utility.\n\n\\begin{theorem}[GNK is monotonic with increasing player utility]\\label{thm:appendix_monotone2}\nFor any two utility profiles $u^1_i(x,y)$ and $u^2_i(x,y)$, and GNK values defined by these utility profiles: $\\varphi_i^1$ and $\\varphi_i^2$.\nThen for any individual $i\\in N$, if $u_i^2(x,y) = u_i^1(x,y)+f(x,y)$ for some non-negative function $f$, and for all $j\\neq i$ that $u^2_j(x,y) = u^1_j(x,y)$, then $\\varphi_i^2 \\ge \\varphi_i^1$ \n\\end{theorem}\n\\begin{proof}\nIf we consider advantage functions $v_1$ and $v_2$ defined by utility functions $u^1_i(x,y)$ and $u^2_i(x,y)$ then for any coalition $S$ including individual $i$:\n\\begin{align}\nv_2(S) = &\n\\frac{1}{2}\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}(x,y)\\in A}} \\left[\n\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}\\exists y,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y)+f(x,y) - \\sum_{i\\in N\\setminus S}u_i^2(x,y)\\right)\\right]\\nonumber\\\\\n& +\n\\frac{1}{2}\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}(x,y)\\in A}} \\left[\n\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}\\exists x,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y)+f(x,y) - \\sum_{i\\in N\\setminus S} u_i^2(x,y) \\right) \\right]\\nonumber\\\\\n&= v_1(S)+c\\nonumber\n\\end{align}\nIf we pull out the inner maximisation and minimisation for the perturbed and unperturbed problems respectively, ie:\n$$ g_1(y) = \n\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}\\exists y,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y)+f(x,y) - \\sum_{i\\in N\\setminus S}u_i^2(x,y)\\right)\n$$\n$$g_2(y) = \n\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}\\exists y,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y) - \\sum_{i\\in N\\setminus S}u_i^2(x,y)\\right) $$\n$$h_1(x) = \n\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}\\exists x,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y)+f(x,y) - \\sum_{i\\in N\\setminus S} u_i^2(x,y) \\right)$$\n$$h_2(x) = \n\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}\\exists x,(x,y)\\in A}}\n\t\\left(\\sum_{i\\in S} u^1_i(x,y) - \\sum_{i\\in N\\setminus S} u_i^2(x,y) \\right)$$\n\nNow since $f(x,y)$ is non-negative therefore $g_1(y) \\ge g_2(y)$ and $h_1(x) \\ge h_2(x)$ irrespective of $x$ and $y$.\ntherefore\n$$\\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}(x,y)\\in A}}g_1(y) \\ge \\min_{\\substack{y\\in A^{N\\setminus S} \\\\ \\text{s.t.}(x,y)\\in A}}g_2(y)$$\n$$\\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}(x,y)\\in A}}h_1(x) \\ge \\max_{\\substack{x\\in A^S \\\\ \\text{s.t.}(x,y)\\in A}}h_2(x)$$\n\nand $$v_2(S) \\ge v_1(S)$$\nAnd the result that $\\varphi_i^2 \\ge \\varphi_i^1$ follows by monotonicity (theorem \\ref{thm:monotonicity}).\n\\end{proof}\n\nThis monotonicity property in Theorem \\ref{thm:appendix_monotone2} most directly encodes the idea that the GNK value is monotone with player utilities, particularly if a players utility by some arbitrary non-negative function then their GNK value should also. it is more general in its application than the shift invariance established by Theorem \\ref{thm:appendix_shift_invariant}.\nand is most directly relevant to the logic of the GNK value, that players with a greater payoff advantage will be afforded more utility, and thus if a players utility increases in some way, so too should the GNK value.\nContrastingly we could imagine a system where the opposite is true, in that if a player has a higher utility for a specific outcome that the system would afford them less, would be less intuitive.\n\n%\\section{Some associated concentration inequalities}\\label{Appendix:more_concentration}\n\n%\\begin{theorem}\\label{hoeffdings_inequality22}\n%Let $X$ be a real-valued random variable that is bounded $a\\le X\\le b$, with a mean $\\mu$ of zero.  Then for $t>0$, the mean $\\hat{\\mu}$ of $n$ independent samples of $X$ is probability bounded by:\n%\\begin{equation}\\p(\\hat{\\mu}-\\mu\\ge t)\\le \\left( \\frac{b}{b-a}\\left(\\frac{b(a-t)}{a(b-t)}\\right)^{\\frac{a-t}{b-a}} -\\frac{a}{b-a}\\left(\\frac{b(a-t)}{a(b-t)}\\right)^{\\frac{b-t}{b-a}}  \\right)^n\n%\\end{equation}\n%\\end{theorem}\n%\\begin{proof}\n%Similar to the proof in Theorem \\ref{hoeffdings_inequality} we follow the same steps except do not apply Equation \\ref{Hoeffdings_lemma}, leading to:\n%$$ \\p(\\hat{\\mu}\\ge t) \\le \\left(\\frac{b\\exp(sa) - a\\exp(sb)}{\\exp(st)(b-a)}\\right)^n $$\n%And minimising with respect to $s$ \n%yields the required result.\n%%$$ s = \\frac{1}{b-a}\\log\\left(\\frac{b(a - t)}{a(b - t)}\\right) $$\n%\\end{proof}\n%This concentration inequality is more powerful but more ugly and difficult to manipulate, it is also more commonly stated for variable $X$ with non-zero mean and bounded $0<X<1$:\n\n%\\begin{theorem}[Also called Hoeffding's inequality]\\label{hoeffdings_inequality23}\n%Let $X$ be a real-valued random variable that is bounded $0\\le X\\le 1$, with mean $\\mu$. Then for $t>0$, the mean $\\hat{\\mu}$ of $n$ independent samples of $X$ is probability bounded by:\n%\\begin{equation}\\p(\\hat{\\mu}-\\mu\\ge t)\\le \\left[\\left(\\frac{1-\\mu}{1-t-\\mu}\\right)^{1-t-\\mu}  \\left(\\frac{\\mu}{t+\\mu}\\right)^{t+\\mu}\\right]^n\n%\\end{equation}\n%\\end{theorem}\n%Which follows directly from the substitution $a=-\\mu$ and $b=1-\\mu$.\n\n%Theorems \\ref{hoeffdings_inequality22} and \\ref{hoeffdings_inequality23} will not be used for further derivation, but to illustrate the point that \n\n\n\n%\\section{An Efron-Stein inequality for the sample variance}\\label{appendix:efron_chebyshev}\n\n%It is to be noted that one way to derive a concentration inequality for the variance is to use Chebyshev's inequality for the sample variance itself.\n%Consider that if $\\hat{\\sigma}^2=\\frac{1}{n-1}\\sum_{i=1}^n(x_i-\\mu)^2$ where $\\mu = \\frac{1}{n}\\sum_{i=1}^nx_i$ is the sample mean, then:\n\n%$$\\p\\left(|\\hat{\\sigma}^2-\\sigma^2|\\ge k\\right)\\le \\frac{\\text{Var}(\\hat{\\sigma}^2)}{k^2}$$\n%which gives us a pretty straightforward error on the sample variance if we can bound $\\text{Var}(\\hat{\\sigma}^2)$\n\n%Now since, $\\hat{\\sigma}^2$ is a general function of the samples $x_1,\\dots,x_n$ we can apply Efron-Stein inequality to bound it.\n%The Efron-Stein inequality bounds the variance of a function of random variables by the sum of variances about each of those parameter variables.\n\n%\\begin{theorem}[Efron-Stein inequality]\n%If $f$ is a function of $n$ random variables $x_1,x_2,\\dots,x_n$, let $x'_1,x'_2,\\dots,x'_n$ be independent copies of the same variables, letting $Z=f(x_1,x_2,\\dots,x_n)$ and $Z'_i=f(x_1,x_2,\\dots,x_{i-1},x'_i,x_{i+1},\\dots,x_n)$\n%then:\n%$$ \\text{Var}(Z) \\le \\frac{1}{2}\\sum_{i=1}^n\\E[(Z-Z'_i)^2]$$\n%\\end{theorem}\n\n%Applying the Efron-Stein inequality to the function $\\hat{\\sigma}^2$ gives:\n%$$\\text{Var}(\\hat{\\sigma}^2)\\le \\frac{5-n}{n(n-1)}\\sigma^2 + \\frac{1}{n}\\mu_4 $$\n%where $\\mu_4$ is the forth central moment.\n\n%Therefore there are two primary options, we can eliminate the first term, or we can half reduce the second.\n%For the first option, the $\\sigma^2$ coefficient is non-positive for $n\\ge 5$, therefore for $n\\ge 5$ that:\n%$$\\text{Var}(\\hat{\\sigma}^2)\\le \\frac{1}{n}\\mu_4 $$ and given that if the variables $x_1,\\dots,x_n$ are bounded $a\\le X\\le b$ with $D=b-a$ then\n%$\\mu_4\\le \\frac{D^4}{16}$ and hence:\n%\\begin{equation}\\label{appendix_eq_1}\\p\\left(|\\hat{\\sigma}^2-\\sigma^2|\\ge k\\right)\\le \\frac{D^4}{16nk^2}\\end{equation}\n\n\n%For the second option, since $\\mu_4=\\E[(X-\\mu)^4]\\le D^2\\E[(X-\\mu)^2]=D^2\\sigma^2$ hence:\n%$$\\text{Var}(\\hat{\\sigma}^2)\\le \\frac{5-n}{n(n-1)}\\sigma^2 + \\frac{1}{n}\\mu_4 \\le \\left(\\frac{5-n}{n(n-1)} + \\frac{D^2}{n}\\right)\\sigma^2$$\n%hence:\n%\\begin{equation}\\label{appendix_eq_2}\\p\\left(|\\hat{\\sigma}^2-\\sigma^2|\\ge k\\right)\\le \\left(\\frac{5-n}{n(n-1)} + \\frac{D^2}{n}\\right)\\frac{\\sigma^2}{k^2}\n%\\end{equation}\n\n%Therefore combining these two expressions \\ref{appendix_eq_1} and \\ref{appendix_eq_2} becomes:\n\n%\\begin{equation}\\label{appendix_eq_3}\\p\\left(|\\hat{\\sigma}^2-\\sigma^2|\\ge k\\right)\\le \\min\\left(\\left(\\frac{5-n}{n(n-1)} + \\frac{D^2}{n}\\right)\\frac{\\sigma^2}{k^2},\\frac{D^4}{16nk^2}\\right)\n%\\end{equation}\n%Which is valid for $n\\ge 5$.\n\n\n\n\n\n", "meta": {"hexsha": "2baca47e484cf645de5715924c85ac3ce9861e71", "size": 14897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/appendix1.tex", "max_stars_repo_name": "Markopolo141/Thesis_code", "max_stars_repo_head_hexsha": "df7cffff8127641b0fed0309adf38cfc9372e618", "max_stars_repo_licenses": ["MIT"], "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/appendix1.tex", "max_issues_repo_name": "Markopolo141/Thesis_code", "max_issues_repo_head_hexsha": "df7cffff8127641b0fed0309adf38cfc9372e618", "max_issues_repo_licenses": ["MIT"], "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/appendix1.tex", "max_forks_repo_name": "Markopolo141/Thesis_code", "max_forks_repo_head_hexsha": "df7cffff8127641b0fed0309adf38cfc9372e618", "max_forks_repo_licenses": ["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.9947643979, "max_line_length": 382, "alphanum_fraction": 0.7024233067, "num_tokens": 5081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289835, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.6524618768318802}}
{"text": "\\section{Systems}\n\n\\begin{definition}[Useful fraction property]\n    If there exists some $k\\in \\R$ such that $k=\\frac{a}{b}=\\frac{c}{d}$, then $\\frac{a+c}{b+d}=k$ as well.\n    Can be extended to $n$ equal fractions of this form.\n\\end{definition}", "meta": {"hexsha": "3febef61e5fa4b75289b3a08b1087cb86284bf5f", "size": 245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "competitive-math/tex/linearsystems.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "competitive-math/tex/linearsystems.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "competitive-math/tex/linearsystems.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": 40.8333333333, "max_line_length": 107, "alphanum_fraction": 0.6734693878, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768108626046, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6524618716721651}}
{"text": "% jam 2004-09-10\n\n\\section{Simplicial Meshes}\n\\label{sec:simplicial-meshes}\n\nAn {\\it abstract $d$-simplex} (or just {\\it simplex})\n$\\Ssimplex$, is a set of $d+1$ elements of some ground space.\nThe elements of the simplex are its {\\it vertices}, $\\{ \\Vvertex_0 \\ldots \\Vvertex_d \\}$.\nA typical ground space might be the non-negative integers,\nwhich is what I will assume in the following.\nA typical implementation would be an integer array\nwhose elements are sorted to facilitate equality/containment tests, etc.\n\nThe {\\it dimension} of a $d$-simplex is $d$.\nThe {\\it faces} of a simplex $\\Ssimplex$ are the simplices which are subsets of $\\Ssimplex$.\nThe {\\it facets} of $\\Ssimplex$ are $(d-1)$-simplices contained in $\\Ssimplex$.\nThe {\\it edges} of $\\Ssimplex$ are the $1$-simplices contained in $\\Ssimplex$.\nIf $\\Tsimplex$ is a face of $\\Ssimplex$,\nthen the face {\\it opposite} $\\Tsimplex$ in $\\Ssimplex$\nis the simplex contained those vertices of $\\Ssimplex$\nnot in $\\Tsimplex$.\nIf $\\Tsimplex$ is the facet of $\\Ssimplex = \\{ \\Vvertex_0 \\ldots \\Vvertex_d \\}$\ncontaining, wlog, vertices $\\{ \\Vvertex_0 \\ldots \\Vvertex_{d-1} \\}$\nthen we speak of $\\Vvertex_d$ as the {\\it vertex opposite} $\\Tsimplex$\nand $\\Tsimplex$ as the {\\it facet opposite} $\\Vvertex_d$.\n\nAn {\\it oriented simplex} is a simplex together with a choice\nof one of the two possible circular orderings of its vertices.\nA typical implementation would add an orientation flag\nto the sorted array simplex implementation.\n\nAn {\\it abstract simplicial complex} (or just {\\it simplicial complex}),\n$\\Kcomplex$, is a set of simplices\nthat obey an containment constraint:\nif $\\Ssimplex$ is in $\\Kcomplex$, then all faces of $\\Ssimplex$ are in $\\Kcomplex$.\nThe complex {\\it generated} by a set of simplices $\\{ \\Vvertex \\}$,\n$\\Kcomplex \\left( \\{ \\Vvertex \\} \\right)$ is the union of all $\\{ \\Vvertex \\}$\nand their faces.\n\nThe {\\it dimension} of a simplicial complex is the maximum dimension\nof any simplex in the complex.\nThe {\\it facets} of a complex are its $(d-1)$-simplices.\nThe {\\it edges} of a complex are its $1$-simplices.\nThe {\\it $k$-skeleton} of a complex $\\Kcomplex$\nis the simplicial complex generated by the $k$-simplices in $\\Kcomplex$.\n\nA {\\it pure simplicial complex} is an $d$-dimensional complex\nin which every simplex is contained in some $d$-simplex in the complex,\nthat is, a complex which is generated by its $d$-simplices.\nThe {\\it boundary} of a pure $d$-dimensional simplicial complex $\\Kcomplex$,\n$\\Boundary \\Kcomplex$,\nis the complex generated by the $(d-1)$-simplices in $\\Kcomplex$\nwhich are contained in only 1 $d$-simplex in $\\Kcomplex$.\n\nAn {\\it orientable simplicial complex} is a pure $d$-dimensional simplicial complex\nin which all the $d$-simplices can be assigned consistent orientations,\nand an {\\it oriented simplicial complex} is one in which the simplices\nhave been oriented consistently.\nTwo oriented $d$-simplices that share a $(d-1)$-dimensional facet\nare {\\it oriented consistently} if they have opposite orientations\nrelative to the shared facet. The orientation of a simplex relative to\none of its facets can be computed by permuting the vertices so that\nthe first $d$ vertices belong the the facet and the unshared vertex is last.\nThe sign of the permutation times the $\\pm$ assigned orientation\nis the relative orientation.\n\n\n\n\nA {\\it geometric realization of an abstract simplex,}\nor {\\it geometric simplex}, $\\p(\\Ssimplex)$,  associates points\nin a {\\it realization space,}\n$\\p ( \\Vvertex_i ) \\in \\Vspace$, with the vertices of an abstract simplex.\nThe points are referred to as the {\\it vertex positions.}\nFor the purposes of this paper,\nI assume $\\Vspace$ is\na finite dimensional real inner product space.\n\nNote that this is not the usual definition,\nin which a geometric simplex is the convex hull of its vertex positions\n$\\convex_span \\{ \\p(\\Vvertex_0) \\ldots \\p(\\Vvertex_d) \\} = \\convex_span ( \\p(S) )$.\nI prefer to keep the simplex distinct from its convex hull,\nbut I will often omit explicit mention of the convex hull\n(eg., the 'volume of a simplex', the 'interior of a simplex', etc.).\n\nWith my definition,\na geometric simplex could be viewed as simply an abstract simplex\nwhere the ground space is the realization space, $\\Vspace$.\nHowever, in the context of mesh optimization,\nit is better to preserve the distinction between an abstract simplex\nand its geometric realizations.\n\nA {\\it simplicial mesh} is a pure simplicial complex, $\\Kcomplex$,\nplus a mapping, $\\p()$, from abstract vertices to points.\n\nNote that this differs from the usual definition for\n{\\it geometric simplicial complex}\n(or {\\it geometric realization of a simplicial complex}),\nwhich requires that the convex hulls of the geometric\nsimplices obey a geometric containment constraint:\nIf $\\Ssimplex_0$ and $\\Ssimplex_1$ are in $\\Kcomplex$,\nthen $\\convex_span ( \\p( \\Ssimplex_0 ) ) \\intersection\n\\convex_span ( \\p( \\Ssimplex_1 ) )$\nis either empty or\n$\\convex_span ( \\p( \\Ssimplex_2 ) )$ for some $\\Ssimplex_2 \\in \\Kcomplex$.\nI distinguish 'simplicial mesh' from 'geometric simplicial complex'\nbecause it isn't feasible or desirable to maintain the geometric\ncontainment constraint during optimization.\n\nMy definition differs from many other definitions of 'simplicial mesh',\nwhich are restrictions of 'geometric simplicial complex', for example,\nrequiring a 'simplicial mesh' to be a geometric simplicial complex\nwhich is an orientable manifold with boundary.\n\n\n\n\n", "meta": {"hexsha": "145f63806eb5d06c5aa9ebbee6770925fdc24ec8", "size": 5456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/simplicial-meshes.tex", "max_stars_repo_name": "palisades-lakes/les-elemens", "max_stars_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/old/fosm/simplicial-meshes.tex", "max_issues_repo_name": "palisades-lakes/les-elemens", "max_issues_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/old/fosm/simplicial-meshes.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": 46.2372881356, "max_line_length": 92, "alphanum_fraction": 0.7501832845, "num_tokens": 1467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.652461860609437}}
{"text": "\\SecDef{longtrail}{The Long-Trail Strategy}\n\nLinear and differential cryptanalysis are powerful methods of attacking block ciphers. It became a standard for new designs to be accompanied with arguments for security against linear and differential cryptanalysis.\n\nThe goal of linear and differential cryptanalysis is to find a \\emph{distinguisher} of a cryptographic function. \n\n\\begin{definition}[Linear and Differential Distinguishers]\nLet $E\\colon \\field{n} \\to \\field{n}$.\n\nA pair $\\alpha_{in},\\alpha_{out}\\in \\field{n}$ is called a \\emph{linear distinguisher} of $E$ with linear correlation\n\\eq{\n& \\LC{E}(\\alpha_{in}, \\alpha_{out}) \\eqdef 2^{-n} \\LAT{E}(\\alpha_{in}, \\alpha_{out}), \\\\\n\\text{if}~ &\\pabs{\\LC{E}((\\alpha_{in}, \\alpha_{out})} \\gg 2^{-n/2}.\n}\n\nA pair $\\alpha_{in},\\alpha_{out}\\in \\field{n}$ is called a \\emph{differential distinguisher} of $E$ with differential probability\n\\eq{\n&\\DP{E}(\\alpha_{in}, \\alpha_{out}) \\eqdef \\DDT{E}(\\alpha_{in},\\alpha_{out}), \\\\\n\\text{if}~ &\\DP{E}(\\alpha_{in}, \\alpha_{out}) \\gg 2^{-n}.\n}\n\nFor a keyed permutation $E_k(x)\\colon \\field{n} \\times \\field{\\kappa} \\to \\field{n}$, a pair $\\alpha_{in},\\alpha_{out}\\in \\field{n}$ is a linear/differential distinguisher if for a large enough fraction of keys $k \\in \\field{\\kappa}$, $(\\alpha_{in}, \\alpha_{out}$ is a linear/differential distinguisher of $E_k$.\n\\end{definition}\n\nCryptographic functions are in most cases built in an iterated way.  Intermediate values are analyzed and included in the distinguisher. The iterations of the round function are \\emph{assumed to be independent} and linear/differential distinguishers of each round are linked in a chain, called \\emph{a trail}.\n\n\\newcommand\\vf{\\mathbf{f}}\n\\newcommand\\valpha{\\boldsymbol{\\alpha}}\n\n\\begin{definition}[Linear and Differential trail]\n$ $\\newline\n%Let $\\vf = (f_1,\\ldots,f_r)$, $f_i\\colon \\field{n} \\times \\field{\\kappa} \\to \\field{n}$ and for $k \\in \\field{\\kappa}$ let $f_i^k\\colon \\field{n} \\to \\field{n}$ be such that $f_i^k(x) = f_i(x, k)$.\nLet $\\vf = (f_1,\\ldots,f_r)$, $f_i\\colon \\field{n} \\to \\field{n}$.\n%Let \\emph{trace} of $x \\in \\field{n}$ with respect to $\\vf$ and $\\vk = (k_1, \\ldots, k_r), k_i \\in \\field{\\kappa}$ be defined as\n% \\eq{\n% &\\Tr_{\\vf}^{\\vk} \\colon \\field{n} \\to (\\field{n})^{r+1},\\\\\n% &\\Tr_{\\vf}^{\\vk}(x) \\eqdef \\proundd{\n% x, f_1^{k_1}(x), f_2^{k_2}\\circ f_1^{k_1}(x), \\ldots, f_r\\circ f_{r-1} \\circ \\ldots\\circ f_2 \\circ f_1(x)\n% }.\n% }\nA \\emph{trail} over $\\vf$ is a sequence $\\valpha$ of $r+1$ vectors:\n$$\n\\valpha = (\\alpha_0, \\ldots, \\alpha_r), \\alpha_i \\in \\field{n}.\n$$\n\nThe \\emph{expected differential probability} of the trail $\\valpha$ is defined as \n\\eq{\n\\EDP{\\vf}(\\valpha) \\eqdef \n    \\prod_{i = 1}^r \\DP{f_i}(\\alpha_{i-1}, \\alpha_i).\n}\n\nThe \\emph{expected linear correlation} of the trail $\\valpha$ is defined as \n\\eq{\n\\ELC{\\vf}(\\valpha) \\eqdef \n    \\prod_{i = 1}^r \\LC{f_i}(\\alpha_{i-1}, \\alpha_i).\n}\n\\end{definition}\n\n\\Todo{motivation: trails add up to differential/linear distinguisher (with independent rounds, e.g. with markov assumption}\n\nIn order to ensure that a cryptographic primitive is secure against trail-based differential/linear cryptanalysis, it is necessary to prove an upper-bound of the maximum $\\EDP{}$ and $\\ELC{}$ among all trails.\n\n\\begin{definition}\nLet $\\vf = (f_1,\\ldots,f_r)$, $f_i\\colon \\field{n} \\to \\field{n}$. \n\nThe \\emph{maximum expected differential trail probability} of $\\vf$ is denoted $\\MEDP{\\vf}$ and is equal to:\n$$\n\\MEDP{\\vf} \\eqdef \\max_{\\valpha \\in (\\field{n})^{r+1}, \\valpha \\ne 0} \\EDP{\\vf}(\\valpha).\n$$\n\nThe \\emph{maximum expected linear trail correlation} of $\\vf$ is denoted $\\MELC{\\vf}$ and is equal to:\n$$\n\\MELC{\\vf} \\eqdef \\max_{\\valpha \\in (\\field{n})^{r+1}, \\valpha \\ne 0} \\ELC{\\vf}(\\valpha).\n$$\n\\end{definition}\n\n\n\\SubSecDef{widetrail}{The Wide-Trail Argument}\n\nThe wide-trail strategy is the main method of proving an upper bound on the $\\MEDP{}$ and $\\MELC{}$ of a cryptographic primitive. It was introduced by Daemen and Rijmen~\\cite{WideTrail} and was used to argue about the security of AES against linear and differential attacks.\n\nI describe the argument for the differential trail cryptanalysis, the linear case is completely analogous.\n\nConsider an SPN structure and a trail $\\valpha$ with a nonzero $\\MEDP{}$. Any difference propagates through the linear layer of the structure with probability 1. Furthermore, a zero difference propagates through an S-Box to a zero difference with probability 1. It follows that the $\\MEDP{}$ of the trail depends only on the differential probabilities of S-Boxes with nonzero input/output differences in the trail. Such S-Boxes are called \\emph{active} S-Boxes. \n\nThe idea of the wide-trail strategy is to prove a lower bound on the number of active S-Boxes in a trail. Then, the differential uniformity of the S-Box is used to obtain an upper bound on the expected differential probability of a trail, i.e. the $\\MEDP{}$. This is done by simply raising the minimum differential probability of the S-Box to the power of the minimum number of active S-Boxes.\nThe first step is usually done by proving strong diffusion properties of the linear layer. For example, the MixColumns operation in the AES has branch number 5 and this already proves that every 2 rounds of AES have at least 5 active S-Boxes. The second step suggests that an S-Box with a low differential uniformity (and low linearity) should be used.\n\nAssume that we want to design an ARX-based block cipher with provable security against linear and differential trail-based cryptanalysis. We can use an existing ARX-based block cipher with a small block as a (keyed) S-Box. We then have to use the $\\MEDP{}$ of the small block cipher instead of the differential uniformity. Indeed, for small block sizes, the $\\MEDP{}$ can be obtained for example using the Matsui search algorithm~\\cite{MatsuiAlgo}. This evaluation was performed by Biryukov~\\etal{} in~\\cite{BVL16} for the block ciphers \\speck{32} up to \\speck{64}. See~\\TabRef{speckey-bounds} for the results on 32-bit block size.\n\n\\begin{remark}\nIn order to justify the assumption of independent rounds in trails, the authors of~\\cite{BVL16} consider \\speckey{}, a slightly modified variant of \\speck{32}. The only difference is that, in \\speckey{}, the round keys are added to the whole state. In this way, the independence assumption is lifted from the block cipher structure to the key schedule. In \\sparx{}, we used \\speckey{} in order to have better justified provable security.\n\\end{remark}\n\n\\begin{table}[ht]\n    \\setlength{\\tabcolsep}{4pt}\n    \\footnotesize\n    \\begin{center}\n        \\begin{tabular}{c|rrrrrrrrrrr}\n            \\toprule\n            $r$    &  $1$ &  $2$ &  $3$ &  $4$ &  $5$ &  $6$ &  $7$ &  $8$ &  $9$ & $10$ & \\\\\n            \\midrule\n            $\\MEDP{}$ & $-0$ & $-1$ & $-3$ & $-5$ & $-9$ & $-13$ & $-18$ & $-24$ & $-30$ & $-34$ & \\\\\n            $\\MELC{}$ & $-0$ & $-0$ & $-1$ & $-3$ & $-5$ &  $-7$ &  $-9$ & $-12$ & $-14$ & $-17$ & \\\\ \n            \\bottomrule\n        \\end{tabular}\n    \\end{center}\n    \\TabDef{speckey-bounds}{$\\protect\\MEDP{}$ and $\\protect\\MELC{}$ of \\speck{32} / \\speckey{} ($\\log_2$ scale); $r$ is the number of rounds.}\n\\end{table}\n\nConsider using 1 round of \\speck{32} as the keyed S-Box. Note that it has a differential with probability $1=2^{-0}$. Therefore, the bound on $\\MEDP{}$ obtained from the wide-trail argument will be trivial, i.e. $\\MEDP{} \\le 1$.\n\nNow consider using 3 rounds of \\speck{32} as the keyed S-Box $A$. Assume that we design a block cipher $E$ with 128-bit block, i.e. with 4 parallel \\speck{32}-based S-Boxes. Assume that the linear layer is a $4\\times 4$ MDS matrix over $\\fielde{32}$, i.e. it has branching number 5. Then at least 5 S-Boxes are active every two rounds and each S-Box has $\\MEDP{A} = 2^{-3}$. It follows that for the $r$ round block cipher $E_r$, the wide-trail argument provides bound $\\MEDP{E_r} \\le (2^{-3})^{5r/2}$. In order to get $\\MEDP{E_r} \\le 2^{-128}$, we need $r \\ge 128/7.5 \\approx 17.07$. Therefore, at least 18 rounds of SPN are needed, i.e. 54 rounds of \\speck{32} repeated four times in parallel. Such a block cipher would be very inefficient.\n\nUsing the novel \\emph{long-trail} strategy, we show that it is possible to build much more efficient block ciphers with ARX-based S-Boxes and provable security against linear and differential trail-based cryptanalysis.\n\n\n\\SubSecDef{longtrailsub}{The Long-Trail Argument}\n\nObserve that in the ARX-based block ciphers the $\\MEDP{}$ grows slower at the first few rounds and grows faster afterwards. For example, the $\\MEDP{}$ of the 10 round \\speck{32} is $2^{-34}$, which is much less than the $\\MEDP{}$ of the 5 round \\speck{32} squared: $(2^{-9})^2 = 2^{-18}$. The wide-trail strategy does not exploit this fact and uses the worse bound. Indeed, in general, the better bound can not be used, because the 10 rounds of \\speck{32} are not always isolated inside the trail structure. Therefore, each concrete trail structure must be analyzed separately. We call \\emph{a long trail} such an isolated chain of (keyed) S-Boxes.\n\n\\newcommand\\LT[1]{\\mathsf{LT}({#1})}\n\\begin{definition}[Long Trail]\nConsider an SPN-based block cipher and a fixed trail $\\valpha$. A \\emph{long trail (LT)} is a chain of active S-Boxes in the trail interleaved with key additions, such that no difference comes into the chain from outside (i.e., the linear layers do not mix in differences into the chain).\n\nConsider a partition of active S-Boxes in the trail into long trails. The multiset of lengths of long trails in any such partition is called a \\emph{long trail decomposition} of the trail $T$, denoted $\\LT{\\valpha}$.\n\\end{definition}\n\n\\begin{proposition}[Long-Trail Bound]\n\\PropLabel{longtrailbound}\nLet $\\vf$ be round function of an SPN-based block cipher with an S-Box $S$ and let $\\valpha$ be a trail over $\\vf$. Then\n\\eq{\n&\\EDP{\\vf}(\\valpha) \\le \\prod_{r^{(m)} \\in \\LT{\\valpha}} \\pround{\\MEDP{S^r}}^m,\\\\\n&\\ELC{\\vf}(\\valpha) \\le \\prod_{r^{(m)} \\in \\LT{\\valpha}} \\pround{\\MELC{S^r}}^m,\n}\nwhere $r^{(m)}$ means that element $r$ repeats $m$ times in the multiset $\\LT{\\valpha}$, and $\\MEDP{S^r}$ (resp. $\\MELC{S^r}$) denote the $\\MEDP{}$ of $r$ rounds of $S$ (resp. $\\MELC{}$).\n\\end{proposition}\n\n\\begin{proof}\nRecall that in the definition of $\\EDP{}$ and $\\ELC{}$ all rounds are considered independent. Therefore, all S-Boxes are independent as well. Hence, $\\EDP{\\vf}(\\valpha)$ is a product of some $\\DDT{}$ entry of each S-Box (depending on the trail $\\valpha$). The proposition simply replaces a subset of these factors by the upper bound on their product, which does not depend on the exact trail $\\valpha$, only on the fact that it is a non-zero trail. The same reasoning applies to the case of linear trails.\n\\end{proof}\n\nThis proposition gives an idea of improving a bound on $\\MEDP{}$ and $\\MELC{}$ of a block cipher. Instead of enumerating all valid \\emph{exact} trails, we only need to enumerate all valid \\emph{truncated} trails telling whether each S-Box is active or not. For each such trail, we need to obtain a preferably optimal long-trail decomposition, which leads to an upper bound on $\\EDP{}$ or $\\ELC{}$ of all exact trails fitting the current truncated trail. By taking the maximum bound among all truncated trails, we obtain an upper bound on $\\MEDP{}$ and $\\MELC{}$ of the block cipher.\n\nFor the sake of completeness, I express the wide-trail bound in the same way to highlight that it is a special case of the long-trail bound. Indeed, the long-trail partition of any trail into chains of length 1 is equivalent to counting the number of active S-Boxes. This, in turn, requires less information about each trail and allows to obtain a simple mathematical argument. On the contrary, the long-trail bound requires algorithmic evaluation.\n\n\\begin{proposition}[Wide-Trail Bound]\nLet $\\vf$ be round function of an SPN-based block cipher with an S-Box $S$ and let $\\valpha$ be a trail over $\\vf$. Then\n\\eq{\n&\\EDP{\\vf}(\\valpha) \\le \\prod_{r^{(m)} \\in \\LT{\\valpha}} \\pround{\\MEDP{S}}^{rm},\\\\\n&\\ELC{\\vf}(\\valpha) \\le \\prod_{r^{(m)} \\in \\LT{\\valpha}} \\pround{\\MELC{S}}^{rm}.\n}\n\\end{proposition}\n\n\n\n\\SubSecDef{alg-decomposition}{An Algorithm for Long-Trail Decomposition}\n\nThe most straightforward way to apply the long-trail argument to bound the $\\MEDP{}$ and $\\MELC{}$ of a cipher is as follows:\n\\begin{enumerate}\n    \\item enumerate all possible truncated trails composed of active/inactive S-boxes;\n    \\item find an optimal decomposition of each trail into long trails (LT);\n    \\item bound the probability of each trail using the product of the $\\MEDP{}$ (resp. $\\MELC{}$) of all active long trails i.e. by applying the Long Trail Argument (see~\\PropRef{longtrailbound});\n    \\item the maximum bound over all trails is the final upper bound.\n\\end{enumerate}\n\n\nNote that this approach is feasible only for a small number of rounds, because the number of truncated trails grows exponentially.\n\nIn this section, I sketch an algorithm for the only non-trivial step, step $(2)$, i.e. an algorithm for finding an optimal decomposition of a given truncated trail into long trails. \n\nFirst, note that the trail can be represented as a graph, where nodes are active S-Boxes and an edge corresponds to a possible connection of two S-Boxes in a long trail. Moreover, this graph is a forest. Indeed, an S-Box can't receive two edges from the previous round, because it contradicts a definition of long trail - there must be a single difference coming in. For each tree in the forest, we choose the root to be the S-Box from the earliest round, which is determined uniquely by the same reason. Then, for any node its children may only be in the next round.\n\nThe goal then is to cover all nodes with disjoint ``vertical'' paths, such that the product of the paths' probabilities is minimal. By the path probability we understand the respective long trail's probability. The simplest (and the worst) solution is to choose paths consisting of single nodes. Note that this solution already gives some upper bound and by finding a better decomposition we improve this bound.\n\nI propose an algorithm based on recursive dynamic programming approach. For each node, we recursively solve the sub-problem for the subtree rooted at that node. However, we need to compute some additional information apart from the best decomposition of the subtree. Consider the optimal decomposition of the whole forest into such paths and consider the long trail which goes through the current subtree's root. Clearly, if we fix this long trail, the rest of the subtree becomes completely independent and has to be decomposed optimally. Therefore, from the subtree we need to know only the probability of this decomposition and the length of the long trail's part in the subtree. We don't know the optimal length beforehand, therefore we store the best probabilities for all possible lengths. Another view on this is that we group all possible subtree decompositions by length of the long trail which goes through the subtree root and for each such length we greedily choose the minimum probability. Then, when we obtain such tables for all children of some node, we can easily compute the table for the node itself - we check all possible ways to choose a child of the node and the length of the long trail which goes through the child and we try to join the current node to that long trail. Then the corresponding probability is the product of the best probabilities of the other children with the probability corresponding to the children's long trail and the probability stored in the children's table respectively for that length.\n\n\\paragraph{Complexity.}\nThe complexity is dominated by computing the table for each node. One of the $w$ children has to be selected for the continuation of the trail, and the size of its child's table is limited by the number of rounds $r$.\nTherefore, each node's contribution to the complexity is at most $\\OO(wr)$. The total complexity of the algorithm then is $O(w^2r^2)$, where $w$ is the number of S-Boxes in parallel, and $r$ is the number of rounds. Note that $wr$ corresponds to the total number of S-Boxes in the cipher.\n\nDespite the reasonable efficiency of the algorithm, the amount of all truncated trails for which the algorithm has to be run adds a large factor to the complexity of the evaluation of a block cipher. In the next section, I will describe an algorithm which completes the whole evaluation in a much more efficient way, under a special condition on the linear layer.\n\n\n\\SubSecDef{alg-special}{Efficient Algorithm for Special Linear Layers}\n\nThe most complicated step in the above procedure is finding an optimal decomposition of a given truncated trail into long trails. The difficulty arises from the so-called \\emph{branching}: situation in which a long trail may be extended in more than one way. The definition of long trail relies on the fact that there is no linear transformation on a path between two S-Boxes in a long trail. Therefore, branching happens only when some output word of the linear layer receives two or more active input words without modifications. \n\nIn order to cut off the branching effect (and thus to make finding the optimal decomposition of a long trail trivial), we can put some additional linear functions that will modify the contribution of some of the input words. Equivalently, when choosing a linear layer we simply do not consider layers which cause branching of long trails. As we will show later, this restriction has many advantages. \n\nTo simplify our study of the linear layer, we introduce a matrix representation for it. In an SPN-based block cipher operating on $w$ words, the linear layer may be expressed as a $w\\times w$ block matrix. We will denote the zero and the identity sub-matrices by $0$ and $1$ respectively and an unspecified (arbitrary) sub-matrix by $L$. This information is sufficient for analyzing the high-level structure of a cipher. Using this notation, the linear layers to which we restrict our analysis have matrices in which each column has at most one element $1$.\n\nFor the special subset of linear layers outlined above, I present an algorithm for obtaining $\\MEDP{}$ and $\\MELC{}$ bounds, based on a dynamic programming approach. Since there is no branching, any truncated trail consists of disjoint sequences of active S-Boxes. We can treat each such sequence as a long trail to obtain an optimal decomposition. More importantly, because of this simplification, we can avoid enumerating all trails by grouping them in a particular way.\n\nWe proceed round by round and maintain a set of best truncated trails up to an equivalence relation, which is defined as follows. For all S-Boxes at the current last round $s$, we assign a number, which is equal to the length of the long trail that covers this S-Box, or zero if the S-Box is not active. We say that two truncated trails for $s$ steps are equivalent if the tuples consisting of those numbers (lengths of long trails) are the same for both truncated trails. This equivalence captures the possibility to replace some prefix of a trail by an equivalent one without breaking the validity of the trail or its LT decomposition. The total probability, however, can change. The key observation is that from two equivalent trails we can keep only the one with the highest current probability. Indeed, if the optimal truncated trail for all $r$ rounds is an extension of the trail for $s$ rounds with lower probability, we can take the first $s$ rounds from the trail with higher probability without breaking validity and obtain a better trail, which contradicts the assumed optimality.\n\nThe pseudo-code for the algorithm is given in~\\AlgRef{special}.\nNote that in the case of the $\\MELC{}$ bound, the matrix of the linear layer has to be inverted and transposed. However, instead of inversion, we can build up the trails in the reverse direction: from the ciphertext side to the plaintext side. In this way, it is sufficient to only transpose the linear layer.\n\n\\FigTex{alg-special.tex}\n\n\\paragraph{Complexity.}\nThe complexity of the algorithm can be upper-bounded as follows. The size of the set $S_i$ is upper-bounded by the number of all $w$-tuples of integers in $\\seg{0}{i}$, i.e. $(i+1)^w$. Generating extensions of an element $s \\in S_i$ requires $w2^w$ operations. Repeating this for $r$ rounds results in complexity $\\OO(r \\cdot w 2^w \\cdot (r+1)^w)$. In practice, only a small subset of all possible $w$-tuples is possible. Note that this algorithm implicitly already performs the enumeration of all truncated trails and therefore, this is the complexity of the full evaluation of the $\\MEDP{}$ and $\\MELC{}$ of the block cipher.", "meta": {"hexsha": "ed1709c62a6948f1920c6ba50fdbd1e071a1458c", "size": 20759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9deSPARX/3longtrail.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/9deSPARX/3longtrail.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/9deSPARX/3longtrail.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": 102.2610837438, "max_line_length": 1538, "alphanum_fraction": 0.740979816, "num_tokens": 5544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.652211904243327}}
{"text": "\\section{Information Theory and Dimensionality Reduction}\nThe following section provides a short introduction into information theory and optimal coding.\nFor a more comprehensive introduction it is recommended to look into \n\\cite[Chapter 6 \\& 7]{Applebaum2008}. In the previous section we have talked about\nmodel comparison and we will follow this conception from an information theoretic\npoint of view.\nWe have earlier used the likelihood as a measure for model comparison and we will use it now\nto introduce an information theoretic measure, the cross-entropy. Strictly speaking, the\nlikelihood function maps a set of possible models to a real value, given an observed data\nset. We recognize that the likelihood function is not a probability density function, as it is\nnot normalized.\n\n\\begin{proposition}[Cross-entropy]\nGiven: We have observed a set of data point $D$ generated from a random variable $X \\sim \\rho(x)$, with\n$\\rho(x)$ being unknown to us, and we want to represent the data using the model $\\hat{\\rho}(x)$. \nThe probability of i.i.d. samples $\\{x_1, x_2, x_2, \\dots x_N\\}$\nunder the model $\\hat{\\rho}(x)$ is given by\n\\begin{align*}\n\tp(D|\\hat{\\rho}) = \\prod_{n=1}^N \\hat{\\rho}(x_n)\n\\end{align*}\nand \n\\begin{align*}\n\t\\log L(D;\\hat{\\rho}) = \\log p(D|\\hat{\\rho}) = \\sum_{n=1}^N \\log \\hat{\\rho}(x_n)\n\\end{align*}\nis the log-likelihood. We find the empirical expectation of a function by using the normalized\nsum over all observations, such that for the expected log-likelihood we find\n\\begin{align}\n\t\\begin{split}\n\t   \\Exest{}{\\log \\hat{\\rho}(x)} &= \\frac{1}{N} \\sum_{n=1}^N \\log \\hat{\\rho}(x_n) \\\\\n\t   \t\t\t\t\t\t\t     &= \\Ex{\\rho_{emp}(x)}{\\log \\hat{\\rho}(x)}\n\t\\end{split}\n\\end{align}\nwhere\n\\begin{align*}\n\t\\rho_{emp}(x) = \\frac{1}{N} \\sum_n \\delta(x - x_n)\n\\end{align*}\nis the empirical distribution of $x$. That is, the empirical expectation of the log-likelihood\nis an expectation with respect to the empirical distribution $\\rho_{emp}(x)$. We notice that \nif the number of observations approaches infinity the empirical distribution is equal to\n$\\rho(x)$:\n\\begin{align*}\n\t\\lim_{N \\rightarrow \\infty} \\rho_{emp}(x) = \\rho(x)\n\\end{align*}\nFollowing this observation the expected negative log-likelihood for infinitely many observations\ncan be written as:\n\\begin{align*}\n\t\\lim_{N \\rightarrow \\infty} \\left( \\Ex{\\rho_{emp}(x)}{- \\log \\hat{\\rho}(x)} \\right)\n\t\t\t\t&= \\Ex{\\rho(x)}{- \\log \\hat{\\rho}(x)} \n\\end{align*}\nwhere \n\\begin{align}\n\t\\Ex{\\rho(x)}{- \\log \\hat{\\rho}(x)} \\stackrel{\\text{cont.}}{:=} - \\int_{X}\\rho(x) \\log \\hat{\\rho}(x) \\, \\mathrm{d}x\n\\end{align}\nis called the cross-entropy of using probability distribution $\\hat{\\rho}(x)$ to represent data\nfrom the true distribution $\\rho(x)$. For the \\emph{discrete case} the cross-entropy is given by\n\\begin{align}\n\t\\Ex{p(x)}{- \\log p(x)}\n\t\t&\\stackrel{\\text{disc.}}{:=} - \\sum_{x \\epsilon X} p(x) \\log \\hat{p}(x)\n\\end{align}\nIn information theory the cross-entropy is a measure of the expected code length needed to respresent\nevents from the probability distribution $\\rho(x)$ using another probability distribution\n$\\hat{\\rho}(x)$. We will later see how to understand this definition.\n\\end{proposition}\n\n%The cross-entropy\n%is a measure of the expected information needed to identify an event $A$ from the \n%sample space $S$ given we code random variable $X$  by $\\hat{\\rho}(x)$ rather than $\\rho(x)$.\n%For the \\emph{continuous case} we define the cross-entropy as\n%\t\\begin{align}\n%\t\t\\mathrm{E}_{\\rho(x)}\\left[-\\log \\rho (x) \\right] \n%\t\t\t&\\stackrel{\\text{cont.}}{:=} - \\int_{X}\\rho(x) \\log \\hat{\\rho}(x) \\, \\mathrm{d}x\n%\t\\end{align}\n%where\n%\t\\begin{align}\n%\t\t\\mathrm{I}(A) = -log_b\\rho(A)\n%\t\\end{align}\n%is called the information content of an event $A$. Due to the monotonicity of the logarithm,\n%we see that $\\mathrm{I}(A) \\rightarrow 0$ for $\\rho(A) \\rightarrow 1$. That is, information can be seen\n%as a measure of 'surprise'. If an event if very likely it's information content is low, whereas\n%if an event is very unlikely it's information content is  high.\n%It should be noted that the logarithm is taken to the\n%base $b$ dependent on the coding scheme which defines the unit of information. $b = 2$ for example \n%corresponds to a coding scheme in \\emph{bits} and $b = \\mathrm{e}$ corresponds to a coding scheme\n%in \\emph{nats}. Similar to the continuous case we can measure the cross-entropy for the\n%\\emph{discrete case} using\n%\t\\begin{align}\n%\t \t\t\\mathrm{E}_{p(x)}\\left[-\\log p (x) \\right]\n%\t\t\t&\\stackrel{\\text{disc.}}{:=} - \\sum_{x \\epsilon X} p(x) \\log \\hat{p}(x)\n% \t\\end{align}\n%In general the cross-entropy is a measure of the expected code length needed to respresent\n%events from the probability distribution $\\rho(x)$ using another probability distribution\n%$\\hat{\\rho}(x)$.\n%\\end{proposition}\n%\n%Training set for different classes\n%\n%$c = 0, \\dots, 9 $\n%\n%$\\hat{\\rho}(\\hat{x} | c) = \n%      \\mathcal{N}(\\underbrace{\\mathbf{U}_c\\TT \\mathbf{x}}_{\\mathbf{s}} | \n%                  \\boldsymbol \\mu_c, \\sigma_{1c}^2\t, \\dots, \\sigma_{dc}^2)$\n%                  \n%The log-likelihood of the data is equal to tha negative cross-entropy of the model given the data.\n%\n%Test sets:\n%$\\rho(\\mathbf{x} | c^*) =\\frac{1}{N} \\sum_{\\mathbf{x_k} \\, \\epsilon \\, \\text{testset}} \\delta(\\mathbf{x} - \\mathbf{x_k})$\n%\n%$ \\Rightarrow \\text{cross-entropy} \\hat{=} \n%    - \\sum_{\\mathbf{x_k} \\, \\epsilon \\, \\text{testset*}} \\log \\hat{\\rho} (\\mathbf{x_k}|c)$\n%    \n%$\\mathrm{E}_{\\rho_{emp}} \\left[ f(\\mathbf{x}) \\right] = \\frac{1}{N} \\sum_{k = 1}^N f(\\mathbf{x_k}) $\n%\n%exp(neg cross-entropy) $:=$ likelihood of the model for the entire test set\n\n\\subsection{Consider the best model}\nWe have learned earlier that the true model $\\rho(x)$ has largest likelihood \ngiven the data is generated from $\\rho(x)$. That is, if the expected log-likelihood is maximized\nthen the expectation of the negative log-likelihood will be minimal such that\n\\begin{align}\n   &\\lim_{N \\rightarrow \\infty} \\left( \\frac{1}{N} \\sum_{k = 1}^N -\\log \\rho(\\mathbf{x_k}) \\right)\n   = - \\int \\rho (\\mathbf{x}) \\log \\rho(\\mathbf{x}) \\mathrm{d}\\mathbf{x} \n\\end{align}   \nis minimal for the true generating model $\\rho(x)$. We call \n\\begin{align}\n\t  \\mathrm{h}[X] &\\stackrel{\\text{cont.}}{:=} - \\int \\rho (\\mathbf{x}) \\log \\rho(\\mathbf{x}) \\mathrm{d}\\mathbf{x}\n\\end{align}\nthe \\emph{differential entropy} of a continuous random variable X with \n$\\mathrm{h}[X] \\, \\epsilon \\, \\mathbb{R}$. An eqivalent definition for the case of discrete \nrandom variables has the form\n\\begin{align}\n\t\\mathrm{H}[x] = - \\sum_{k=1}^K p(x_k) \\log p(x_k)\n\\end{align}\nwith $\\mathrm{H}[x] \\, \\epsilon \\, \\mathbb{R}^+$. This is called the \\emph{discrete entropy}.\nThe entropy measures the minimal discription length, or the most compact description, of a random\nvariable. The description length of a random variable will be minimal if the code which describes\nthe random variable comes from true distribution of that random variable. The negative log-probability\nof an observation approximates the code word length for describing that observation.\n\n\\subsection{Information}\nIn information theory the negative log probabilty of an event $A$ under a model $\\rho(x)$\n\t\\begin{align}\n\t\t\\mathrm{I}(A) = -log_b\\rho(A)\n\t\\end{align}\nis called the information content of an event $A$. Due to the monotonicity of the logarithm,\nwe see that $\\mathrm{I}(A) \\rightarrow 0$ for $\\rho(A) \\rightarrow 1$. That is, information can be seen\nas a measure of 'surprise'. If an event if very likely it's information content is low, whereas\nif an event is very unlikely it's information content is  high.\nIt should be noted that the logarithm is taken to the\nbase $b$ dependent on the number of symbols in the alphabet which defines the unit of information. \n$b = 2$ for example corresponds to a binary code which is represented in \\emph{bits}, whereas\n$b = \\mathrm{e}$ corresponds to a coding scheme in \\emph{nats}.\n\n\\begin{exbox}{Discrete distribution (uniform)}\nGiven a discrete random variable $X$ such that\n\\begin{align*}\n\tx \\, \\epsilon \\, \\{1,2,3,4\\} \\qquad p(x) = \\frac{1}{4}\n\\end{align*}\nThen for a binary code the entropy is given by:\n\\begin{flalign*}\n\t\\mathrm{H}[p(x)] &= - \\sum_{x = 1,2,3,4} p(x) \\log p(x) \\\\\n\t \t\t\t\t &= - \\log_2 \\frac{1}{4} \\\\\n\t \t\t\t\t &= \\log_2 4 = 2 [bits]\n\\end{flalign*}\nWhereas for a terniary code with three symbols the entropy is given by:\n\\begin{flalign*}\n\\mathrm{H}[p(x)] &= - \\sum_{x = 1,2,3,4} p(x) \\log p(x) \\\\\n\t \t\t\t\t &= - \\log_3 \\frac{1}{4} \\\\\n\t \t\t\t\t &= \\log_3 4 \\approx 1.26 [trits]\n\\end{flalign*}\n\nBinary alphabet: $p(x) = \\frac{1}{8} \\Rightarrow \\mathrm{H}[p(x)] = 3\\mathrm{bits}.$ \\\\\nTernary alphabet: $p(x) = \\frac{1}{9} \\Rightarrow \\mathrm{H}[p(x)] = 2\\mathrm{trits}.$ \\\\\n\n\\end{exbox}\n\n\n\\subsubsection{Optimality}\nWe understand optimality in the sense that for \\emph{infinitely long} sequences of observations \nthe description length takes a minimum and that this minimum description length is tightly bounded\nby the entropy such that:\n\\begin{align}\n\t\\mathrm{H}[x] \\leq \\frac{\\# \\text{symbols}}{\\# \\text{words}} \\leq \\mathrm{H}[x] + 1\n\\end{align}\nwhere $\\frac{\\# \\text{symbols}}{\\# \\text{words}}$ is the the average code word length. This\nis called \"Shannon's noiseless coding theorem\".\n\n\\subsection{Quantization}\nProblem: The description length of a continuous random variable is infinite. However, we can introduce a quantization which divides the variable space into equally sized bins of size $\\Delta$. By this we are mapping a continuous RV into a discrete space such that we can calculate the discrete Entropy $\\mathrm{H}_\\Delta$ under the quantization $\\Delta$.\n\n\\begin{wrapfigure}{r}{0.5\\textwidth}\n\t\\centering\n\t\\includegraphics[width=0.45\\textwidth]{./lecture12/gauss_quant.pdf}\n\t\\caption{Quantization of a normally distributed random variable.}\n\\end{wrapfigure}\nThe \n\\begin{align}\n\t{H}_\\Delta[x] \\approx \\mathrm{h}[x] - \\log \\Delta\n\\end{align}\n\nIt can be shown that:\n\\begin{align}\n\t\\mathrm{h}[x] = \\lim_{\\Delta \\rightarrow 0} \\left( \\mathrm{H}_\\Delta[x] + \\log \\Delta \\right)\n\\end{align}\n\nMaximum likelihood classification follows the minimum description length principle, \ni.e. find the model that corresponds to the most compact description of the data.\n\n\\subsection{Joint entropy}\n\\begin{definition}[Joint entropy]\nDiscrete case:\n\\begin{align*}\n\t\t\\mathrm{H}[X,Y] = -\\sum_{x_k,y_j} p(x_k,y_j) \\log p(x_k,y_j)\n\\end{align*}\n\nContinuous case:\n\\begin{align*}\n\t\t\\mathrm{h}[X,Y] = - \\mathop{\\int \\! \\! \\! \\int} \\rho(x,y) \\log \\rho(x,y) \\, \\mathrm{d}x \\mathrm{d}y\n\\end{align*}\n\\end{definition}\n\n\\subsection{Mutual Information}\n\n\\begin{align*}\n\t\\underbrace{\\mathbf{X}}_{\\text{Source}} \\stackrel{\\text{channel}}{\\longrightarrow} \\underbrace{\\mathbf{Y}}_{\\text{Receiver}}\n\\end{align*}\n\n\n\\begin{example}[Channel coding with shared bits]\n\tGiven: A bit code with 8 possible words\n\t\\begin{align*}\n\t\t\\mb{b} \\, \\epsilon \\, \\{0,1\\}^3 = \\{000,001,010,011,100,101,110,111\\}\n\t\\end{align*}\n\tand equal probabilities of word occurences\n\t\\begin{align*}\n\t\t\\qquad p(\\mathbf{b}) = \\frac{1}{8}\n\t\\end{align*}\t  \n\tSource and Receiver share one bit such that\n\t\\begin{align*}\n \t\t\\mb{x} = \\begin{pmatrix} b_1 \\\\ b_2 \\end{pmatrix}; \\qquad \n\t\t\\mb{y} = \\begin{pmatrix} b_2 \\\\ b_3 \\end{pmatrix}\n\t\\end{align*} \t\n\tThe optimal code word length for source and receiver is given by\n\t\\begin{align*}\n\t\t\\mathrm{H}[X] = 2 \\, \\mathrm{bits}; \\qquad \\mathrm{H}[Y] = 2 \\, \\mathrm{bits}\n\t\\end{align*}\n\tand for the shared code\n\t\\begin{align*}\n\t\t\t\\mathrm{H}[X,Y] = 3 \\, \\mathrm{bits}\n\t\\end{align*}\n\tWe see that $\\mathrm{H}[X,Y] \\leq \\mathrm{H}[X] + \\mathrm{H}[Y]$ and that\n\t\\begin{align*}\n\t\t\\mathrm{I}[X:Y] = \\mathrm{H}[X] + \\mathrm{H}[Y] - \\mathrm{H}[X,Y] = 1 \\, \\mathrm{bits}\n\t\\end{align*}\n\tis the number of shared bits between source $X$ and receiver $Y$. This is called the mutual\n\tinformation of $X$ and $Y$.\n\\end{example}\n\n\n\\begin{definition}[Mutual information]\n\\begin{align*}\n\t\t\\mathrm{I}[X:Y]\n\t\t      & \\stackrel{\\text{cont.}}{:=} \\mathrm{h}[X] + \\mathrm{h}[Y] - \\mathrm{h}[X,Y] \\\\\n   \t\t      & \\stackrel{\\text{disc.}}{:=} \\mathrm{H}[X] + \\mathrm{H}[Y] - \\mathrm{H}[X,Y]\n\\end{align*}\n\\end{definition}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.45\\textwidth]{./lecture12/venn.pdf}\n\t\\caption{A Venn diagram for the relationship of information theoretic measures.}\n\\end{figure}\n\n\\subsubsection*{Reexpressing mutual information}\n\\begin{align}\n\\begin{split}\n\t\\mathrm{I}[X:Y] &= \\mathrm{h}[X] + \\mathrm{h}[Y] - \\mathrm{h}[X,Y] \\\\\n\t                &= - \\int \\rho (\\mathbf{x}) \\log \\rho(\\mathbf{x}) \\mathrm{d}\\mathbf{x} \n\t                   - \\int \\rho (\\mathbf{y}) \\log \\rho(\\mathbf{y}) \\mathrm{d}\\mathbf{y} \n\t                   + \\mathop{\\int \\! \\! \\! \\int} \\rho(x,y) \\log \\rho(x,y) \\, \\mathrm{d}x \\mathrm{d}y \\\\\n\t                &= \\mathop{\\int \\! \\! \\! \\int} \\rho(x,y) \\log \\frac{\\rho(x,y)}{\\rho(x)\\rho(y)} \\, \\mathrm{d}x \\mathrm{d}y \\\\\n\t                &= \\mathop{\\int \\! \\! \\! \\int} \\rho(x,y) \\log \\frac{\\rho(x|y)}{\\rho(x)} \\, \\mathrm{d}x \\mathrm{d}y \\\\\n\t                &= \\mathop{\\int \\! \\! \\! \\int} \\rho(x,y) \\log \\frac{\\rho(y|x)}{\\rho(y)} \\, \\mathrm{d}x \\mathrm{d}y \\\\\n\t                &= \\mathrm{h}[X] + \\mathop{\\int \\! \\! \\! \\int} \\rho(x|y) \\rho(y) \\log \\rho(x|y) \\, \\mathrm{d}x \\mathrm{d}y \\\\\n\t                &= \\mathrm{h}[X] - \\underbrace{\\int \\rho(y) \n\t                     \\left(- \\int \\rho(x|y) \\log \\rho(x|y) \\, \\mathrm{d}x \\right) \\mathrm{d}y}_{\\text{conditional entropy}} \\\\\n\t                &= \\mathrm{h}[X] - \\mathrm{h}[X|Y] \\\\\n\t                &= \\mathrm{h}[Y] - \\mathrm{h}[Y|X]\n\\end{split}\n\\end{align}\nThe conditional entropy $\\mathrm{h}[Y|X]$ is the entropy of a random variable $Y$ conditioned on \nany possible outcome of random variable $X$. It corresponds to the number of additional bits\nneeded on average to code for $Y$ given that $X$ has been observed. It is a reflection of the uncertainty that\nis introduced by the channel.\n\n\\begin{exbox}{Differential entropy of a Gaussian random variable}\n\t\\begin{align*}\n\t\\mathrm{h}[X] &= \\frac{1}{2} \\log_\\mathrm{e} \\left( 2 \\pi \\mathrm{e} \\mathrm{Var}[X] \\right) \\text{in nats} \\\\\n\t\t\t\t  &= \\frac{1}{2} \\log_2 \\left( 2 \\pi \\mathrm{e} \\mathrm{Var}[X] \\right) \\text{in bits}\n\t\\end{align*}\n\\end{exbox}", "meta": {"hexsha": "b6e09a7e76dea89691495b833f4def5ecfb47016", "size": 14160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture12/lecture12.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/lecture12/lecture12.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/lecture12/lecture12.tex", "max_forks_repo_name": "cne-tum/msne_statsandprob_ss2018", "max_forks_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2018-03-16T07:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T14:02:27.000Z", "avg_line_length": 47.2, "max_line_length": 354, "alphanum_fraction": 0.6688559322, "num_tokens": 4656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.6521552461189817}}
{"text": "\\chapter{Sets and Tables}\n\n\\textsc{Perspective}: Sets and tables are data aggregates that are\nvery useful for a number of common programming tasks.  Nevertheless,\nfew programming languages support these data types, with the notable\nexceptions of Sail (Reiser 1976) and SETL (Dewar, Schonberg, and\nSchwartz 1981). There are many reasons why these obviously useful data\ntypes are not found in most programming languages, but perceived\nimplementation problems certainly rank high among them. If only for\nthis reason, their implementation in Icon is worth studying.\n\nHistorically, tables in Icon were inherited from SNOBOL4 and SL5. Sets\ncame later, as an extension to Icon, and were designed and implemented\nas a class project. Although sets were a late addition to Icon, they\nare simpler than tables.  Nonetheless, they present many of the same\nimplementation problems that tables do. Consequently, sets are\nconsidered here first.\n\nSets and the operations on them support the familiar mathematical\nconcepts of finite sets: membership, the insertion and deletion of\nmembers, and the operations of union, intersection, and\ndifference. What is interesting about a set in Icon is that it can\ncontain members of any data type. This is certainly a case where\nheterogeneity significantly increases the usefulness of a data\naggregate without adding to the difficulty of the implementation,\n\\textit{per se.}\n\nThe ability of a set to grow and shrink in size influences the\nimplementation significantly. Efficient access to members of a set,\nwhich is needed for testing membership as well as the addition and\ndeletion of members, is an important consideration, since sets can be\narbitrarily large.\n\n\nTables have more structure than sets. Abstractly, a table is a set of\npairs that represents a many-to-one relationship-a function. In this\nsense, the default value of a table provides an extension of the\npartial function represented by the entry and assigned value pairs to\na complete function over all possible entry values. Programmers,\nhowever, tend to view tables in a more restricted way, using them to\ntabulate the attributes of a set of values of interest. In fact,\nbefore sets were added to Icon, tables were often used to simulate\nsets by associating a specific assigned value with membership.\n\n\\section{Sets}\n\\subsection{Data Organization for Sets}\n\nHash lookup and linked lists are used to provide an efficient way of\nlocating set members. For every set there is a set-header block that\ncontains a word for the number of members in the set and slots that\nserve as heads for (possibly empty) linked lists of set-element\nblocks. The number of slots is an implementation parameter. In version\n6 of Icon there were thirty-seven slots in table-header blocks on\ncomputers with large address spaces but only thirteen slots on\ncomputers with small address spaces.This worked well for small hash\ntables, but performance degraded for large tables due to the long hash\nchains in each slot.  \n\nNow, the hash table is segmented; each hash table starts out with a\nsingle segment containing a fixed number of slots (typically eight),\nbut the number of slots doubles repeatedly as the number of segments\ngrows. Small hash tables benefit from reduced memory requirements,\nwhile large tables show dramatic performance gains. The price paid is\none extra indirection to get to the lists of members. The maximum\nnumber of segments in a set header block is a configuration parameter:\nThe default is six on machines with small address spaces and ten\notherwise.\n{\\color{blue} Unicon allows up to twenty segments, which places an\nupper limit on the maximum possible number of slots (albeit quite a\nlarge one of $slots \\times 2^{19}$).\n}\nTo reduce the size of the diagrams the maximum number of segments is\nassumed to be six in the figures that follow but, even with this low\nnumber, the maximum number of slots is $256$ ($8 + 8 + 16 + 32 + 64\n+ 128$), which is still a respectable increase compared to version 6.\n\nThe structure for an empty set, produced by\n\n\\iconline{\n\\>s := set()\n}\n\n\\noindent is\n\n\\begin{picture}(300,250)(0,-32)\n\\put(120,32){\\wordpile{5}{\\nullptrbox{}}}\n\\put(120,32){\\blboxlabel{segment 5}}\n\\put(120,94){\\leftboxlabels{segment 0}{segment 1}}\n\\put(120,112){\\wordboxptr{60}{}}\n\\begin{picture}(0,0)(-20,32)\n\\put(240,94){\\rightboxlabels{slot 0}{slot 1}}\n\\put(360,80){\\vdots}\n\\put(240,0){\\brboxlabel{slot 7}}\n\\put(240,0){\\wordpile{8}{\\nullptrbox{}}}\n\\put(240,128){\\blkbox{slots}{40}}\n\\put(240,128){\\brboxlabel{size}}\n\\end{picture}\n\\put(80,80){\\vdots}\n\\put(120,128){\\blkbox{\\textit{id}}{7}}\n\\put(120,128){\\brboxlabel{mask}}\n\\put(120,160){\\blkbox{set}{0}}\n\\put(120,160){\\brboxlabel{number of elements in the set}}\n\\put(0,176){\\dvboxptr{set}{np}{40}{}}\n\\put(0,176){\\tlboxlabel{\\texttt{s}}}\n\\end{picture}\n\nEach member of a set is contained in a separate set-element\nblock. When a value is looked up in a set (for example, to add a new\nmember), a hash number is computed from this value. The absolute value\nof the remainder resulting from dividing the hash number by the number\nof slots is used to select a slot.\n\nEach set-element block contains a descriptor for its value, the\ncorresponding hash number, and a pointer to the next set-element\nblock, if any, on the linked list. For example, the set-element block\nfor the integer 10 is:\n\n\\begin{picture}(300,90)\n\\put(120,0){\\dvbox{integer}{n}{10}}\n\\put(120,0){\\trboxlabel{member value}}\n\\put(120,32){\\wordbox{129}{}}\n\\put(120,32){\\brboxlabel{hash number}}\n\\put(120,48){\\nullptrbox{next set-element block}}\n\\put(120,64){\\wordbox{selem}{}}\n\\end{picture}\n\nAs illustrated by this figure, the hash number for an integer is not\nthe value of the integer (in Icon Version 6 it was). The hash number\nfor an integer is the result of multiplying it by eight times the\ngolden ratio using fixed point arithmetic. Hash computation is\ndiscussed in detail in Sec. 7.3.\n\nThe structures for the set\n\n\\iconline{\n\\ \\ s := set([10,23])\n}\n\n\\noindent are\n\n\\begin{picture}(300,240)(30,0)\n%\\put(0,0){\\graphpaper{40}{23}}\n%set header\n\\put(0,70){\\begin{picture}(0,0)\n\\put(0,96){\\blkbox{\\textit{id}}{7}}\n\\put(0,96){\\brboxlabel{mask}}\n\\put(0,128){\\blkbox{set}{2}}\n\\put(0,128){\\brboxlabel{number of elements in the set}}\n\\put(0,0){\\wordpile{5}{\\nullptrbox{}}}\n\\put(0,80){\\wordboxptr{60}{}}\n\\end{picture}\n}\n%segment 0\n\\put(140,8){\\begin{picture}(0,0)\n\\put(0,0){\\brboxlabel{slot 7}}\n\\put(0,0){\\wordpile{6}{\\nullptrbox{}}}\n\\put(0,96){\\wordboxptr{40}{}}\n\\put(0,112){\\nullptrbox{slot 0}}\n\\put(0,128){\\blkbox{slots}{40}}\n\\put(0,128){\\brboxlabel{size}}\n\\end{picture}\n}\n% set element 1\n\\put(260,40){\\begin{picture}(0,0)\n\\put(0,0){\\dvbox{integer}{n}{10}}\n\\put(0,32){\\wordbox{129}{}}\n\\put(0,32){\\brboxlabel{}}\n\\put(0,48){\\wordboxptr{40}{}}\n\\put(0,64){\\wordbox{selem}{}}\n\\end{picture}\n}\n% set element 2\n\\put(380,24){\\begin{picture}(0,0)\n\\put(0,0){\\dvbox{integer}{n}{23}}\n\\put(0,32){\\wordbox{297}{}}\n\\put(0,32){\\brboxlabel{}}\n\\put(0,48){\\nullptrbox{}}\n\\put(0,64){\\wordbox{selem}{}}\n\\end{picture}\n}\n\n\n\\end{picture}\n\nThis example was chosen for illustration, since both 10 and 23 go in slot 1.\n\nIn searching the list, the hash number of the value being looked up is\ncompared with the hash numbers in the set-element blocks. If a match\nis found, the value in the set-element block may or may not be the same\nas the value being looked up, since collisions in the hash computation\nare unavoidable. Thus, if the hash numbers are the same, it is\nnecessary to determine whether or not their values are equivalent. The\ncomparison that is used is the same one that is used by the\nsource-language operation \\texttt{x === y}.\n\nTo improve the performance of the lookup process, the set-element\nblocks in each linked list are ordered by their hash numbers. When a\nlinked list of set-element blocks is examined, the search stops if a\nhash number of an element on the list is greater than the hash number\nof the value being looked up.\n\nIf the value is not found and the lookup is being performed to insert\na new member, a set-element block for the new member is created and\nlinked into the list at that point. For example,\n\n\\iconline{\n\\>insert(s, 2)\n}\n\n\\noindent inserts a set-element block for 2 at the head of the list\nin slot 1, since its hash value is 25. The word in the set-header\nblock that contains the number of members is incremented to reflect\nthe insertion.\n\n\\subsection{Set Operations}\n\nThe set operations of union, intersection, and difference all produce\nnew sets and do not modify their arguments.\n\n\nIn the case of union, a copy of the larger set is made first to\nprovide the basis for the union. This involves not only copying the\nset-header block but also all of its set-element blocks. These are\nlinked together as in the original set, and no lookup is\nrequired. After this copy is made, each member of the set for the\nother argument is inserted in the copy, using the same technique that\nis used in insert. The larger set is copied, since copying does not\nrequire lookup and the possible comparison of values that insertion\ndoes. The insertion of a member from the second set may take longer,\nhowever, since the linked lists in the copy may be longer.\n\nIn the case of intersection, a copy of the smaller argument set is\nmade, omitting any of its members that are not in the larger set. As\nwith union, this strategy is designed to minimize the number of\nlookups.\n\nFor the difference of two sets, a copy of the first argument set is\nmade, adding only elements that are not in the second argument. This\ninvolves looking up all members in the first argument set in the\nsecond argument set.\n\n\\section{Tables}\n\\subsection{Data Organization for Tables}\n\nThe implementation of tables is similar to the implementation of sets,\nwith a header block containing slots for elements ordered by hash\nnumbers. A table-header block contains an extra descriptor for the\ndefault assigned value.\n{\\color{blue} As with lists (but {\\em not} sets), Unicon replaces the\n  terminating null pointer used by Icon with a pointer to the table\n  header block.\n}\n\nAn empty table with the default assigned value 0 is produced by\n\n\\iconline{\n\\>t := table(0)\n}\n\nThe structure of the table-header is\n\n\\begin{picture}(400,250)(0,-32)\n%\\put(0,-32){\\graphpaper{40}{25}}\n\\put(120,0){\\dvbox{integer}{n}{0}}\n\\put(120,0){\\blboxlabel{default assigned value}}\n\\put(120,32){\\wordpile{5}{\\nullptrbox{}}}\n\\put(120,32){\\blboxlabel{segment 5}}\n\\put(120,94){\\leftboxlabels{segment 0}{segment 1}}\n\\put(120,112){\\wordboxptr{60}{}}\n\\begin{picture}(0,0)(-20,32)\n\\put(240,94){\\rightboxlabels{slot 0}{slot 1}}\n\\put(360,80){\\vdots}\n\\put(240,0){\\brboxlabel{slot 7}}\n\\put(240,0){\\wordpile{8}{\\hdrnullptrbox{}}}\n\\put(240,128){\\blkbox{slots}{40}}\n\\put(240,128){\\brboxlabel{size}}\n\\end{picture}\n\\put(80,80){\\vdots}\n\\put(120,128){\\blkbox{\\textit{id}}{7}}\n\\put(120,128){\\brboxlabel{mask}}\n\\put(120,160){\\blkbox{table}{0}}\n\\put(120,160){\\brboxlabel{number of elements in the table}}\n\\put(0,176){\\dvboxptr{table}{np}{40}{}}\n\\put(0,176){\\tlboxlabel{\\texttt{t}}}\n\\end{picture}\n\nTable lookup is more complicated than set lookup, since table elements\ncontain both an entry value and an assigned value. Furthermore, table\nelements can be referenced by variables. A new table element is\ncreated as a byproduct of assignment to a table reference with an\nentry value that is not in the table.\n\nThe result of evaluating an assignment expression such as\n\n\\iconline{\n\\>t[10] := 1\n}\n\n\\noindent illustrates the structure of a table-element block:\n\n\\begin{picture}(300,120)(0,-32)\n\\put(120,-32){\\dvbox{integer}{n}{1}}\n\\put(120,-32){\\trboxlabel{assigned value}}\n\\put(120,0){\\dvbox{integer}{n}{10}}\n\\put(120,0){\\trboxlabel{entry value}}\n\\put(120,32){\\wordbox{129}{}}\n\\put(120,32){\\brboxlabel{hash number}}\n\\put(120,48){\\hdrnullptrbox{next table-element block}}\n\\put(120,64){\\wordbox{telem}{}}\n\\end{picture}\n\n%% \\begin{picture}(300,150)(50,-10)\n%% \\put(120,0){\\dvbox{integer}{n}{1}}\n%% \\put(120,0){\\trboxlabel{assigned value}}\n%% \\put(120,32){\\dvbox{null}{n}{39}}\n%% \\put(120,32){\\trboxlabel{entry value}}\n%% \\put(120,64){\\dvbox{null}{n}{0}}\n%% \\put(120,64){\\trboxlabel{next table-element block}}\n%% \\put(120,96){\\blkbox{telem}{39}}\n%% \\put(120,96){\\brboxlabel{hash number}}\n%% \\end{picture}\n\nIn the case of a table reference such as \\texttt{t[x]}, the hash\nnumber for the entry value x is used to select a slot, and the\ncorresponding list is searched for a table-element block that contains\nthe same entry value. As in the case of sets, comparison is first made\nusing hash numbers; values are compared only if their hash numbers are\nthe same.\n\nIf a table-element block with a matching entry value is found, a\nvariable that points to the corresponding assigned value is\nproduced. For example, if 10 is in t as illustrated previously,\n\\texttt{t[10]} produces\n\n\\begin{picture}(300,120)(0,-32)\n%\\put(0,-32){\\graphpaper{30}{15}}\n\\put(140,-32){\\dvbox{integer}{n}{1}}\n\\put(140,-32){\\trboxlabel{assigned value}}\n\\put(140,0){\\dvbox{integer}{n}{10}}\n\\put(140,0){\\trboxlabel{entry value}}\n\\put(140,32){\\wordbox{129}{}}\n\\put(140,32){\\brboxlabel{hash number}}\n\\put(140,48){\\hdrnullptrbox{next table-element block}}\n\\put(140,64){\\wordbox{telem}{}}\n%\n\\put(0,-16){\\dvboxptr{5}{npv}{40}{}}\n\\put(120,-8){\\line(0,1){80}}\n\\put(120,72){\\vector(1,0){20}}\n\\multiput(120,-8)(4,0){4}{\\line(1,0){2}}\n\\put(136,-8){\\vector(1,0){4}}\n\\end{picture}\n\nIf this variable is dereferenced, as in\n\n\\iconline{\n\\>write(t[10])\n}\n\n\\noindent the value 1 is written. On the other hand, if an assignment\nis made to this variable, as in\n\n\\iconline{\n\\>t[10] +:= 1\n}\n\n\\noindent the assigned value in the table-element block is changed:\n\n\\begin{picture}(300,120)(0,-32)\n\\put(140,-32){\\dvbox{integer}{n}{2}}\n\\put(140,-32){\\trboxlabel{assigned value}}\n\\put(140,0){\\dvbox{integer}{n}{10}}\n\\put(140,0){\\trboxlabel{entry value}}\n\\put(140,32){\\wordbox{129}{}}\n\\put(140,32){\\brboxlabel{hash number}}\n\\put(140,48){\\hdrnullptrbox{next table-element block}}\n\\put(140,64){\\wordbox{telem}{}}\n\\end{picture}\n\nIf a table element with a matching entry value is not found, the\nsituation is very similar to that in a subscripted string: the\noperation to be performed depends on whether the table reference is\nused in a dereferencing or assignment context. In a dereferencing\ncontext, the default value for the table is produced, while in an\nassignment context, a new element is added to the table.\n\nThe approach taken is similar to that for subscripted strings: a\ntrapped variable is created. As with substring trapped variables,\ntable-element trapped variables contain the information that is\nnecessary to carry out the required computation for either\ndereferencing or assignment.\n\nSuppose, for example, that the entry value \\texttt{36} is not in the\ntable \\texttt{t}. Then \\texttt{t[36]} produces the following result:\n\n\\begin{picture}(300,100)\n\\put(120,0){\\dvbox{integer}{n}{36}}\n\\put(120,0){\\trboxlabel{entry value}}\n\\put(120,32){\\wordbox{465}{}}\n\\put(120,32){\\brboxlabel{hash number}}\n\\put(120,48){\\blkboxptr{tvtbl}{40}{table header block for t}}\n\\put(0,64){\\dvboxptr{tvtbl}{nptv}{40}{}}\n\\end{picture}\n\n%% [DonW]  None of this is true, post V6\n%% Note that the size of a table-element trapped-variable block is the\n%% same as the size of a table-element block. The last descriptor in the\n%% table-element trapped-variable block is reserved for subsequent use,\n%% as described below.\n\nIf this trapped variable is dereferenced, as in\n\n\\iconline{\n\\>write(t[36])\n}\n\n\\noindent the default assigned value, 0, which is in the table-header\nblock for \\texttt{t}, is produced. Unfortunately, the situation is not\nalways this simple. It is possible for elements to be inserted in a\ntable between the time the table-element trapped-variable block is\ncreated and the time it is dereferenced. An example is\n\n\\iconline{\n\\>write(t[36] , t[36] := 2)\n}\n\nSince functions do not dereference their arguments until all the\narguments have been evaluated, the result of dereferencing the first\nargument of write should be 2, not 0. In order to handle such cases,\nwhen a table-element trapped variable is dereferenced, its linked list\nin the table must be searched again to determine whether to return the\nassigned value of a newly inserted element or to return the default\nvalue.\n\nIf an assignment is made to the table reference, as in\n\n\\iconline{\n\\>t[36] +:= 1\n}\n\n%----- post V6 processing\n\\noindent the table-element trapped-variable block is copied to a new\ntable-element block with the assigned value stored in the new block.\n%----- which replaces the V6 text\n%% \\noindent the table-element trapped-variable block is converted to a\n%% table-element block with the assigned value stored in the reserved\n%% descriptor of the table-element trapped-variable block. The\n%% table-element block is then linked in the appropriate place. Note that\n%% the structures of table-element blocks and table-element\n%% trapped-variable blocks are the same, allowing this conversion without\n%% allocating a new table-element block.\n\nIt then is necessary to search the linked list for its slot to % again to\ndetermine the place to insert the table-element block. As in the case\nof dereferencing, elements may have been inserted in the table between\nthe time the table-element trapped variable was created and the time a\nvalue is assigned to it. Normally, no matching entry is found, and the\n%table-element trapped-variable block, transformed into a table-element\nnew table-element\nblock, is inserted with the new assigned value.  If a matching entry\nis found, its assigned value is simply changed, and the block is\ndiscarded.\n\nNote that reference to a value that is not in a table requires only\none computation of its hash value, but two lookups are required in the\nlinked list of table-element blocks for its slot.\n\n\n\\section{Hashing Functions}\n\n\\PrimaryIndexBegin{Hash computations}\nIdeally, a hash computation should produce a different result for\nevery different value to which it is applied, and the distribution of\nthe remainder on division by the number of slots should be\nuniform. Even approaching this ideal requires an impractical amount of\ncomputation and space. In practice, it is desirable to have a fast\ncomputation that produces few collisions.\n\nThe subject of hash computation has been studied extensively.  In\ngeneral, there is a trade-off between faster lookup, on the average,\nand more storage overhead. Beyond this, there is a substantial body of\nknowledge concerning useful techniques (Knuth 1973, pp. 506-549). For\nexample, there are fewer collisions if the number of slots is a prime\nthat is not close to a power of two. Originally, this consideration\nmotivated the choices of 37 and 13 for number of hash table slots on\ncomputers with large and small address spaces, respectively. As\ncomputer memory sizes grew, the one-size-fits-all strategy was\nreplaced with one that increases the number of slots as needed\n(Griswold and Townsend 1993).\n\nIn most situations in which hashing techniques are used, all the\nvalues for which hash computations are performed are strings. In Icon,\nhowever, any kind of value can be the member of a set or the entry\nvalue in a table. The hash computation must, therefore, apply to any\ntype of value. The support routine for computing hash numbers first\nchecks for a string, and then has a switch statement to handle all\nthe other types.\n\nThe string hashing implementation is important and deserves extra\nscrutiny. The Unicon implementation differs from Icon and is shown\nin blue; the \\#ifdef is included for exposition and is not in the code.\n\n\\index{C functions!\\texttt{hash}}%\n\\begin{iconcode}\nuword hash(dp)\\\\\ndptr dp;\\\\\n\\>\\{\\\\\n\\>register char *s;\\\\\n\\>register uword i;\\\\\n\\>register word j, n;\\\\\n\\>register unsigned int *bitarr;\\\\\n\\>double r;\\\\\n\\>if (Qual(*dp)) \\{\\\\\n\\end{iconcode}\n%\n\\begin{specialcode}{\\tt\\color{blue}}\n\\#ifdef Unicon\\\\\n\\>hashstring:\\\\\n\\>\\> /*\\\\\n\\>\\>\\  * Compute the hash value for the string based on a scaled sum\\\\\n\\>\\>\\  *  of its first and last several characters, plus its length.\\\\\n\\>\\>\\  *  Loops are unrolled.\\\\\n\\>\\>\\  */\\\\\n\\>\\> i = 0;\\\\\n\\>\\> s = StrLoc(*dp);\\\\\n\\>\\> n = StrLen(*dp);\\\\\n\\\\\n\\>\\> switch(n)\\{\\\\\n\\>\\>\\> case 20:  i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 19:  i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 18:  i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 17:  i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 16:  i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 15:  i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 14:  i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 13:  i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 12:  i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 11:  i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 10:  i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 9:   i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 8:   i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 7:   i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 6:   i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 5:   i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 4:   i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 3:   i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 2:   i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\> case 1:   i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\> case 0:   break;\\\\\n\\>\\>\\> default:\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>\\\\\n\\>\\>\\>\\>s += n - 20;\\\\\n\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\>\\>i \\^{}= (i <{}< 7)\\^{}(*s++)\\^{}(i >{}> 3);\\\\\n\\>\\>\\>\\>i \\^{}= ~(i <{}< 11)\\^{}(*s++)\\^{}(i >{}> 5);\\\\\n\\>\\>\\}\\\\\n\\>\\> i += n;\\\\\n\\>\\}\\\\\n\\#else /* Icon */\n\\end{specialcode}%blue\n%\n\\begin{iconcode}\n\\>hashstring:\\\\\n\\>\\>/*\\\\\n\\>\\>\\ * Compute the hash value for the string based on a scaled \\\\\n\\>\\>\\ * \\ sum of its first ten characters, plus its length.\\\\\n\\>\\>\\ */\\\\\n\\>\\>i = 0;\\\\\n\\>\\>s = StrLoc(*dp);\\\\\n\\>\\>j = n = StrLen(*dp);\\\\\n\\>\\>if (j > 10)\\ \\ /* limit scan to first ten characters */\\\\\n\\>\\>\\>j = 10;\\\\\n\\>\\>while (j-{}- > 0) \\{\\\\\n\\>\\>\\>i += *s++ \\& 0xFF;\\ \\ /* add unsigned version of char */\\\\\n\\>\\>\\>i *= 37;\\ \\ \\ \\ /* scale by a nice prime number */\\\\\n\\>\\>\\}\\\\\n\\>\\>i += n;\\ \\ \\ \\ \\ \\ /* add (untruncated) string length */\\\\\n\\>\\>\\}\\\\\n\\end{iconcode}\n%\n\\begin{specialcode}{\\tt\\color{blue}}\n\\#endif\\>\\>\\> /* Icon / Unicon */\\\\\n\\end{specialcode}\n%\n\\begin{iconcode}\n\\>else \\{\\\\\n\\>\\>switch (Type(*dp)) \\{\\\\\n\\>\\>\\>/*\\\\\n\\>\\>\\>\\ * The hash value of an integer is itself times eight \\\\\n\\>\\>\\>\\ * \\ times the golden ratio. \\ We do this calculation in \\\\\n\\>\\>\\>\\ * \\ fixed point. \\ We don't just use the integer itself, \\\\\n\\>\\>\\>\\ * \\ for that would give bad results with sets having\\\\\n\\>\\>\\>\\ * \\ entries that are multiples of a power of two.\\\\\n\\>\\>\\>\\ */\\\\\n\\>\\>\\>case T\\_Integer:\\\\\n\\>\\>\\>\\>i = (13255 * (uword)IntVal(*dp)) >> 10;\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>/*\\\\\n\\>\\>\\>\\ * The hash value of a bignum is based on its length and \\\\\n\\>\\>\\>\\ * \\ its most and least significant digits.\\\\\n\\>\\>\\>\\ */\\\\\n\\>\\>case T\\_Lrgint:\\\\\n\\>\\>\\>\\{\\\\\n\\>\\>\\>struct b\\_bignum *b = \\&BlkLoc(*dp)->bignumblk;\\\\\n\\>\\>\\>i = ((b->lsd - b->msd) <{}< 16) \\^{}\\\\\n\\>\\>\\>\\>(b->digits[b->msd] <{}< 8) \\^{}\\\\\n\\>\\>\\>\\>b->digits[b->lsd];\\\\\n\\>\\>\\>\\}\\\\\n\\>\\>\\>break;\\\\\n\\>\\>\\>/*\\\\\n\\>\\>\\>\\ * The hash value of a real number is itself times a \\\\\n\\>\\>\\>\\ * \\ constant, converted to an unsigned integer. \\ The \\\\\n\\>\\>\\>\\ * \\ intent is to scramble the bits well, in the case of \\\\\n\\>\\>\\>\\ * \\ integral values, and to scale up fractional values \\\\\n\\>\\>\\>\\ * \\ so they don't all land in the same bin. The constant\\\\\n\\>\\>\\>\\ * \\ below is 32749 / 29, the quotient of two primes,\\\\\n\\>\\>\\>\\ * \\ and was observed to work well in empirical testing.\\\\\n\\>\\>\\>\\ */\\\\\n\\>\\>\\>case T\\_Real:\\\\\n\\>\\>\\>\\>GetReal(dp,r);\\\\\n\\>\\>\\>\\>i = r * 1129.27586206896558;\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>/*\\\\\n\\>\\>\\>\\ * The hash value of a cset is based on a convoluted \\\\\n\\>\\>\\>\\ * \\ combination of all its bits.\\\\\n\\>\\>\\>\\ */\\\\\n\\>\\>\\>case T\\_Cset:\\\\\n\\>\\>\\>\\>i = 0;\\\\\n\\>\\>\\>\\>bitarr = BlkLoc(*dp)->cset.bits + CsetSize - 1;\\\\\n\\>\\>\\>\\>for (j = 0; j < CsetSize; j++) \\{\\\\\n\\>\\>\\>\\>\\>i += *bitarr-{}-;\\\\\n\\>\\>\\>\\>\\>i *= 37;\\ \\ \\ \\ \\ \\ /* better distribution */\\\\\n\\>\\>\\>\\>\\>\\}\\\\\n\\>\\>\\>\\>i \\%= 1048583;\\ \\ \\ \\ /* scramble the bits */\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>/*\\\\\n\\>\\>\\>\\ * The hash value of a list, set, table, or record is \\\\\n\\>\\>\\>\\ * \\ its id, hashed like an integer.\\\\\n\\>\\>\\>\\ */\\\\\n\\>\\>\\>case T\\_List:\\\\\n\\>\\>\\>\\>i = (13255 * BlkLoc(*dp)->list.id) >> 10;\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>case T\\_Set:\\\\\n\\>\\>\\>\\>i = (13255 * BlkLoc(*dp)->set.id) >> 10;\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>case T\\_Table:\\\\\n\\>\\>\\>\\>i = (13255 * BlkLoc(*dp)->table.id) >> 10;\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>case T\\_Record:\\\\\n\\>\\>\\>\\>i = (13255 * BlkLoc(*dp)->record.id) >> 10;\\\\\n\\>\\>\\>\\>break;\\\\\n\\ \\  case T\\_Proc:\\\\\n\\ \\  \\ \\ \\ dp = \\&(BlkLoc(*dp)->proc.pname);\\\\\n\\ \\  \\ \\ \\ goto hashstring;\\\\\n\\>\\>\\>default:\\\\\n\\>\\>\\>\\>/*\\\\\n\\>\\>\\>\\>\\ * For other types, use the type code as the hash\\\\\n\\>\\>\\>\\>\\ * \\ value.\\\\\n\\>\\>\\>\\>\\ */\\\\\n\\>\\>\\>\\>i = Type(*dp);\\\\\n\\>\\>\\>\\>break;\\\\\n\\>\\>\\>\\}\\\\\n\\>\\>\\}\\\\\n\\>return i;\\\\\n\\>\\}\n\\end{iconcode}\n\nTo hash a string, its characters are combined mathematically as\nintegers. At most the first ten characters are used. {\\color{blue}\nUnicon uses up to the first ten and the last ten, to distinguish\nlong strings such as identifiers with differences at either end}.\nThe limit on the number of characters used in the hash is important\nbecause strings can be very long and adding all the characters does\nnot improve the hashing sufficiently to justify the time spent in the\ncomputation. A maximum of ten or twenty is, however, \\textit{ad hoc}. To\nprovide a measure of discrimination between strings with the same\ninitial substring, the length of the string is added to the sum of the\ncharacters.\n\nIcon's technique for hashing strings is not sophisticated, and others\nthat produce better hashing results are known. However, the\ncomputation is simple, easy to write in C, and works well on most data.\nUnicon's technique is adapted from one due to Arash Partow\n(http://www.partow.net/programming/hashfunctions/), with length\ncaps and loop unrolling.  It was validated empirically on a wide\nrange of data sets.\n\nFor a numeric type, the hash value is derived from the number. In the\ncase of a cset, the words containing the bits for the cset are\ncombined using the exclusive-or operation.\n\nThe remaining data types pose an interesting problem. Hash computation\nmust be based on attributes of a value that are invariant with\ntime. Some types, such as files, have such attributes. On the other\nhand, there is no time-invariant attribute that distinguishes one list\nfrom another. The size of a list may change, the elements in it may\nchange, and even its location in memory may change as the result of\ngarbage collection. For a list, its only time-invariant attribute is\nits type.\n\nThis presents a dilemma{---}the type of such a value can be used as its\nhash number, but if that is done, all values of that type are in the\nsame slot and have the same hash number. Lookup for these values\ndegenerates to a linear search.  The alternative is to add some\ntime-invariant attribute, such as a serial number, to these\nvalues. Icon does this, at the cost of increasing the size of every\nsuch value.\n\\PrimaryIndexEnd{Hash computations}\n\n\\textsc{Retrospective}: Few programming languages support sets or\ntables with Icon's generality. The implementation of sets and tables\nprovides a clear focus on the generality of descriptors and the\nuniformity with which different kinds of data are treated in Icon.\n\nSince sets and tables may be very large, efficient lookup is an\nimportant concern. The hashing and chaining technique used is only one\nof many possibilities. However, there must be a mechanism for\ndetermining the equivalence of values independent of the structure in\nwhich they are stored.\n\nThe fact that elements in tables are accessed by subscripting\nexpressions introduces several complexities. In particular, the fact\nthat the contents of the table that is subscripted may change between\nthe time the subscripting expression is evaluated and the time it is\ndereferenced or assigned to introduces the necessity of two lookups\nfor every table reference.\n\nHashing a variety of different types of data raises interesting\nissues. The hashing techniques used by Icon are not sophisticated and\nthere is considerable room for improvement. The trade-offs involved\nare difficult to evaluate, however.\n\n\\bigskip\n\n\\noindent\\textbf{EXERCISES}\n\n\\liststyleLvii\n\\begin{enumerate}\n\\item \\begin{enumerate}\n\n\\item Contrast sets and csets with respect to their implementation,\ntheir usefulness in programming, and the efficiency of operations on\nthem.\n\n\\item Give an example of a situation in which the heterogeneity of\nsets is useful in programming.\n\n\\item How much space does an empty set occupy?\n\n\\item Diagram the structures resulting from the evaluation of the\nfollowing expressions:\\newline\n t := table()\\newline\n t[t] := t\n\n\\item There are many sophisticated data structures that are designed\nto ensure efficient lookup in data aggregates like sets and tables\n(Gonnet 1984). Consider the importance of speed of lookup in sets and\ntables in Icon and the advantages that these more sophisticated data\nstructures might supply.\n\n\\item Some of the more sophisticated data structures mentioned in the\npreceding exercise have been tried experimentally in Icon and either\nhave introduced unexpected implementation problems or have not\nprovided a significant improvement in performance. What are possible\nreasons for these disappointing results?\n\n\\item Icon goes to a lot of trouble to avoid adding table-element\nblocks to a table unless an assignment is made to them.  Suppose a\ntable-element block were simply added when a reference was made to an\nentry value that is not in the table.\n\\end{enumerate}\n\\end{enumerate}\n\\liststyleLviii\n\\begin{itemize}\n\\item How would this simplify the implementation?\n\n\\item What positive and negative consequences could this change have\non the running speed and space required during program execution?\n\n\\item Give examples of types of programs for which the change would\nhave positive and negative effects on performance, respectively.\n\n\\item Would this change be transparent to the Icon programmer, not\ncounting possible time and space differences?\n\\end{itemize}\n\\liststyleLix\n\\begin{enumerate}\n\\item \\begin{enumerate}\n\n\\item There is space in a table-element trapped-variable block to put\nthe default value for the table. Why is this not done?\n\n\\item \nWhat is the consequence of evaluating the following expressions?\n\\end{enumerate}\n\\end{enumerate}\n\\begin{iconcode}\n\\>t := table(0)\\\\\n\\>t[37] := 2\\\\\n\\>write(t[37], t := table(1))\n\\end{iconcode}\n\nWhat would happen if the last line given previously were\n\n\\iconline{\n\\>write(t[37],t := list(100,3))\n}\n\nor\n\n\\iconline{\n\\>write(t[37], t := \"hello\")\n}\n\n\\liststyleLx\n\\begin{enumerate}\n\\item \\begin{enumerate}\n\n\\item Give examples of different strings that have the same hash numbers.\n\n\\item Design a method for hashing strings that produces a better\ndistribution than the the current one.\n\n\\item What attribute of a table is time-invariant?\n\n\\item What kinds of symptoms might result from a hashing computation\n based on an attribute of a value that is not time-invariant?\n\n\\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "52f16ef4dfd2521b8efbac872ddfbb692d12c415", "size": 32276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/ib/p1-sets-tables.tex", "max_stars_repo_name": "akhand1111/unicon", "max_stars_repo_head_hexsha": "096ebf0692eea58792b36b3cbe3da35842f85b4a", "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/ib/p1-sets-tables.tex", "max_issues_repo_name": "akhand1111/unicon", "max_issues_repo_head_hexsha": "096ebf0692eea58792b36b3cbe3da35842f85b4a", "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/ib/p1-sets-tables.tex", "max_forks_repo_name": "akhand1111/unicon", "max_forks_repo_head_hexsha": "096ebf0692eea58792b36b3cbe3da35842f85b4a", "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": 38.0613207547, "max_line_length": 76, "alphanum_fraction": 0.682953278, "num_tokens": 10011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6521552402092632}}
{"text": "% !TEX root = Main.tex\n\\section{Matrix Approximation \\& Reconstruction}\n\n$\\min_{rank(B)=k}[\\sum_{(i,j)\\in I}{(a_{ij}-b_{ij})^2}], I=\\{(i,j): \\mathit{ob.}\\}$\n\\subsection*{Alternating Least Squares}\n$f(U,v_i) = \\sum_{(i,j)\\in I} (a_{i,j} - \\langle u_j, v_i \\rangle)^2$\\\\\n$f(u_i,V) = \\sum_{(i,j)\\in I} (a_{i,j} - \\langle u_j, v_i \\rangle)^2$\\\\\nConvex when fixed one.\n\n% YZF: delete?\n% \\subsection*{Coordinate Descent}\n% 1. init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\\\\\n% 2. for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\\\\\n% 3. sample $d \\in_{u.a.r.} \\{1, \\ldots, D\\}$\\\\\n% 4. $u^\\star = \\argmin_{u \\in \\mathbb{R}} f(x_1^{(t)}, .., x_{d-1}^{(t)}, u, x_{d+1}^{(t)}, .., x_D^{(t)})$\\\\\n% 5. $\\mathbf{x}_d^{(t+1)} = u^\\star$ and $\\mathbf{x}_i^{(t+1)} = \\mathbf{x}_i^{(t)}$ for $i \\neq d$\n\n% \\subsection*{Projected Gradient Descent (Constrained Opt.)}\n% minimize $f(x)$, $x \\in Q$ (constraint).\\\\\n% \\textbf{Project} $x$ onto $Q$: $P_Q(\\mathbf{x}) = \\argmin_{y \\in Q} \\|\\mathbf{y} - \\mathbf{x}\\|$,\\\\\n% \\textbf{Update}: $\\mathbf{x}^{(t+1)} = P_Q[\\mathbf{x}^{(t)} - \\gamma \\nabla f(\\mathbf{x}^{(t)})]$,\\\\\n% $\\mathbf{x}^{(t+1)}$ is unique if $Q$ convex.\n\n\n% YZF: need revising\n\\subsection*{Convex Optimization}\nDef.: $\\{(x,t)|x \\in dom f, f(x) \\leq t\\}$, $f : \\mathbb{R}^D \\rightarrow \\mathbb{R}$ is convex, if $dom\\ f$ is a convex set, and if $\\forall \\mathbf{x}, \\mathbf{y} \\in dom\\ f$, and $\\forall \\alpha\\in[0,1]$: $f(\\alpha \\mathbf{x} + (1 - \\alpha)\\mathbf{y}) \\leq \\alpha f(\\mathbf{x}) + (1-\\alpha)f(\\mathbf{y})$. \nConvex $\\iff$ Hessian p.s.d $\\iff$ local=global \\\\\nPositive semi-definite: all principal minors (same-indexed rows and columns) $\\geq$ 0\\\\\nPositive definite: leading principal minors $>$ 0\n\n\\subsection*{Convex Relaxation}\nReplace non-convex rank constraints by convex norm constraints (superset). Then project optimum back (hopefully still optimal).\\\\\n$\\min_{\\mathbf{B}\\in P_k}{\\|\\mathbf{A-B}\\|^2_G}, P_k=\\{\\mathbf{B}:\\|\\mathbf{B}\\|_{*}\\leq k\\}\\supseteq Q_k=\\{\\mathbf{B}:\\mathit{rank}(\\mathbf{B})\\leq k\\}$ (in fact tightest convex lowerbound $\\mathit{rank}(\\mathbf{B})\\geq \\|\\mathbf{B}\\|_{*}, for \\|\\mathbf{B}\\|_2 \\leq 1$)\n\n\\subsection*{SVD Thresholding}\n% TBA\n$\\mathbf{B}^{*}=\\mathit{shrink}_\\tau(\\mathbf{A})=\\argmin_{\\mathbf{B}}{\\{\\|\\mathbf{A-B}\\|^2_F + \\tau\\|\\mathbf{B}\\|_{*}\\}}$\\\\\nThen with SVD $\\mathbf{A=UDV_T}, \\mathbf{D}=\\mathit{diag}(\\sigma_i)$, holds $\\mathbf{B^*=UD_\\tau V^T, D_\\tau} = \\mathit{diag}(\\max\\{0,\\sigma_i - \\tau\\})$ \\\\\nIteration: $\\mathbf{B}_{t+1}=\\mathbf{B}_t + \\eta_t \\Pi(\\mathbf{A} - \\mathit{shrink}_\\tau(\\mathbf{B}_t))$", "meta": {"hexsha": "ed41992ecb663fb6038a4015650da19d646d6a4d", "size": 2549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Reconstruction.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": "Reconstruction.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": "Reconstruction.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": 63.725, "max_line_length": 309, "alphanum_fraction": 0.5982738329, "num_tokens": 1093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6521532840523439}}
{"text": "\\section{The matrix of a linear transformation II}\n\n%Requires Linear Transformations.\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the matrix of a linear transformation with respect to\n    general bases.\n  \\end{enumerate}\n\\end{outcome}\n\nWe begin this section with an important lemma.\n\n\\begin{lemma}{Mapping of a basis}{mapping-basis}\nLet $T: \\R^n \\to \\R^n$ be an isomorphism.  Then $T$ maps any basis of\n$\\R^n$ to another basis for $\\R^n$.\n\nConversely, if $T:\n\\R^n \\to \\R^n$ is a linear transformation which\nmaps a basis of $\\R^n$ to another basis of $\\R^n$,\nthen it is an isomorphism.\n\\end{lemma}\n\n\\begin{proof}\nFirst, suppose $T:\\R^n \\to \\R^n$ is a linear\ntransformation which is one to one and onto. Let $\\set{\n\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ be a basis for\n$\\R^n$. We wish to show that $\\set{T(\\vect{v}_{1}),\\ldots,\nT(\\vect{v}_{n})} $ is also a basis for $\\R^n$.\n\nFirst consider why it is linearly independent. Suppose\n$\\sum_{k=1}^{n}a_{k}T(\\vect{v}_{k})=\\vect{0}$. Then by linearity we have $T\\paren{\n\\sum_{k=1}^{n}a_{k}\\vect{v}_{k}} =\\vect{0}$ and since $T$ is one\nto one, it follows that $\\sum_{k=1}^{n}a_{k}\\vect{v}_{k}=\\vect{0}$.\nThis requires that  each $a_{k}=0$ because $\\set{\\vect{v}_{1},\\ldots,\n\\vect{v}_{n}} $ is independent, and it follows that $\\set{\nT(\\vect{v}_{1}),\\ldots, T(\\vect{v}_{n})} $ is linearly\nindependent.\n\nNext take $\\vect{w}\\in \\R^n$. Since $T$ is onto, there exists\n$\\vect{v}\\in \\R^n$ such that $T(\\vect{v})=\\vect{w}$. Since\n$ \\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}}$ is a basis, in particular it\nis a spanning set and there are scalars $b_{k}$ such that\n$T\\paren{\\sum_{k=1}^{n}b_{k}\\vect{v} _{k}} =T(\\vect{v})\n=\\vect{w}$. Therefore $\\vect{w} =\\sum_{k=1}^{n}b_{k}T(\\vect{v}_{k})$\nwhich is in the\n$\\sspan\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})}$. Therefore,\n$\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})}$ is a basis as\nclaimed.\n\nSuppose now that $T: \\R^n \\to \\R^n$ is a linear\ntransformation such that $T(\\vect{v}_{i})=\\vect{w}_{i}$ where\n$\\set{\\vect{v} _{1},\\ldots,\\vect{v}_{n}} $ and $\\set{\n\\vect{w}_{1},\\ldots, \\vect{w}_{n}} $ are two bases for\n$\\R^n$.\n\nTo show that $T$ is one to one, let $T\\paren{\n\\sum_{k=1}^{n}c_{k}\\vect{v}_{k}} =\\vect{0}$. Then\n$\\sum_{k=1}^{n}c_{k}T(\\vect{v}_{k})=\\sum_{k=1}^{n}c_{k}\\vect{w}_{k}=\\vect{\n0}$. It follows that each $c_{k} = 0$ because it is given that\n$\\set{\\vect{w} _{1},\\ldots,\\vect{w}_{n}} $ is linearly\nindependent. Hence $T\\paren{\\sum_{k=1}^{n}c_{k}\\vect{v}_{k}}\n=\\vect{0}$ implies that $\\sum_{k=1}^{n}c_{k}\\vect{v}_{k}=\\vect{0}$ and\nso $T$ is one to one.\n\nTo show that $T$ is onto, let $\\vect{w}$ be an arbitrary vector in\n$\\R^n$. This vector can be written as $\\vect{w} =\n\\sum_{k=1}^{n}d_k\\vect{w}_k =\n\\sum_{k=1}^{n}d_{k}T(\\vect{v}_{k})=T\\paren{\\sum_{k=1}^{n}d_{k}\n\\vect{v}_{k}}$.  Therefore, $T$ is also onto.\n\\end{proof}\n\nConsider now an important definition.\n\n\\begin{definition}{Coordinate vector}{coordinate-vector}\nLet $B = \\set{\\vect{v}_1, \\vect{v}_2,\\ldots, \\vect{v}_n }$\nbe a basis for $\\R^n$ and let $\\vect{x}$ be an arbitrary\nvector in $\\R^n$. Then $\\vect{x}$ is uniquely represented as\n$\\vect{x} = a_1\\vect{v}_1 +\na_2\\vect{v}_2 + \\ldots + a_n\\vect{v}_n$ for scalars $a_1,\\ldots,\na_n$.\n\nThe  \\textbf{coordinate vector}\\index{vector!coordinate vector}\\index{coordinate vector} of $\\vect{x}$ with respect to the\nbasis $B$, written $C_B(\\vect{x})$ or  $[\\vect{x}]_B$,  is given by\n\\[\nC_B(\\vect{x}) =  C_B (a_1\\vect{v}_1 + a_2\\vect{v}_2 + \\ldots + a_n\\vect{v}_n) = \\begin{mymatrix}{c}\na_1 \\\\\na_2 \\\\\n\\vdots \\\\\na_n\n\\end{mymatrix}\n\\]\n\\end{definition}\n\nConsider the following example.\n\n\\begin{example}{Coordinate vector}{coordinate-vector}\nLet $B = \\set{\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}, \\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix} }$ be a basis of $\\R^2$ and let $\\vect{x} = \\begin{mymatrix}{r}\n3 \\\\\n-1\n\\end{mymatrix}$ be a vector in $\\R^2$. Find $C_B(\\vect{x})$.\n\\end{example}\n\n\\begin{solution}\nFirst, note the order of the basis is important so label the vectors in the basis $B$ as\n\\[\nB = \\set{\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}, \\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix} } = \\set{\\vect{v}_1, \\vect{v}_2 } \\]\nNow we need to find $a_1, a_2$ such that $\\vect{x} = a_1 \\vect{v}_1 + a_2 \\vect{v}_2$, that is:\n\\[\n\\begin{mymatrix}{r}\n3 \\\\\n-1\n\\end{mymatrix}\n=\na_1\n\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}\n+ a_2\n\\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix}\\]\nSolving this system gives $a_1 = 2, a_2 = -1$. Therefore the coordinate vector of $\\vect{x}$ with respect to the basis $B$ is\n\\[\nC_B(\\vect{x})\n=\n\\begin{mymatrix}{r}\na_1 \\\\\na_2\n\\end{mymatrix}\n= \\begin{mymatrix}{r}\n2 \\\\\n-1\n\\end{mymatrix}\n\\]\n\\end{solution}\n\nGiven any basis $B$, one can easily verify that the coordinate function is actually an isomorphism.\n\n\\begin{theorem}{$C_B$ is a linear transformation}{coordinate-linear-transformation}\nFor any basis $B$ of $\\R^n$, the coordinate function\n\\[ C_B: \\R^n  \\rightarrow \\R^n  \\]\nis a linear transformation, and moreover an isomorphism.\n\\end{theorem}\n\nWe now discuss the main  result  of this section, that is how\nto represent a linear transformation with respect to different\nbases.\n\n\\begin{theorem}{The matrix of a linear transformation}{matrix-linear-transformation-bases}\nLet $T: \\R^n \\to \\R^m$ be a linear transformation,\nand let $B_1$ and $B_2$ be bases of $\\R^{n}$ and\n$\\R^{m}$ respectively.\n\nThen the following holds\n\\begin{equation}\nC_{B_2} T = M_{B_{2} B_{1}} C_{B_1}   \\label{matrix-equation}\n\\end{equation}\nwhere $M_{B_{2} B_{1}}$  is a unique $m \\times n$-matrix.\n\nIf the basis $B_1$ is given by $B_1=\\set{\\vect{v}_1,\\ldots, \\vect{v}_n}$ in this order, then\n\n\\[  M_{B_{2} B_{1}} = \\mat{C_{B_2}(T(\\vect{v}_1)), C_{B_2}(T(\\vect{v}_2)), \\ldots, C_{B_2}(T(\\vect{v}_n)) } \\]\n\\end{theorem}\n\n\\begin{proof}\nThe above equation {\\eqref{matrix-equation}} can be represented by the following diagram.\n\\begin{equation*}\n\\begin{array}{rrcll}\n&  & T &  &  \\\\\n& \\R^n & \\rightarrow  & \\R^m & \\\\\n& C_{B_{1} }\\downarrow  & \\circ  & \\downarrow C_{B_{2} } &  \\\\\n& \\R^{n} & \\rightarrow  & \\R^{m} &  \\\\\n&  & M_{B_{2} B_{1} } &  &\n\\end{array}\n\\end{equation*}\n\nSince $C_{B_1}$ is an isomorphism, then the matrix we are looking for is the matrix of the linear transformation\n\\[   C_{B_2} T C^{-1}_{B_1} : \\R^n \\to \\R^m. \\]\nBy Theorem~\\ref{thm:matrix-of-linear-transformation}, the columns are\ngiven by the image of the standard basis $\\set{\\vect{e}_1,\n\\vect{e}_2,\\ldots, \\vect{e}_n }$. But since $C^{-1}_{B_1}( \\vect{e}_i) = \\vect{v}_i$, we readily obtain that\n\n\\[ \\begin{array}{ll}\nM_{B_{2} B_{1}}\n& = \\mat{C_{B_2}T C^{-1}_{B_1} (\\vect{e}_1), C_{B_2}T C^{-1}_{B_1} (\\vect{2}_2), \\ldots, C_{B_2}T C^{-1}_{B_1} (\\vect{e}_n) } \\\\\n& = \\mat{C_{B_2}(T(\\vect{v}_1)), C_{B_2}(T(\\vect{v}_2)), \\ldots, C_{B_2}(T(\\vect{v}_n)) }\n\\end{array}\\]\nand this completes the proof.\n\\end{proof}\n\nConsider the following example.\n\n\\begin{example}{Matrix of a linear transformation}{matrix-linear-transformation}\nLet $T: \\R^2 \\to \\R^2$ be a linear transformation defined by $T \\paren{\\begin{mymatrix}{r}\na \\\\\nb\n\\end{mymatrix}} = \\begin{mymatrix}{r}\nb \\\\\na\n\\end{mymatrix}$.\n\nConsider the two bases\n\\[\nB_1 = \\set{\\vect{v}_{1}, \\vect{v}_{2} } = \\set{\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}, \\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix}\n}\n\\]\n and\n\\[\nB_2 = \\set{\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix}, \\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix}\n}\n\\]\n\nFind the matrix $M_{B_2,B_1}$ of $T$ with respect to the bases $B_1$ and $B_2$.\n\\end{example}\n\n\\begin{solution}\nBy Theorem~\\ref{thm:matrix-linear-transformation-bases}, the columns of $M_{B_{2} B_{1}}$ are the\ncoordinate vectors of $T(\\vect{v}_{1}), T(\\vect{v}_{2})$ with respect\nto $B_2$.\n\nSince \\[\nT \\paren{\n\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}}\n= \\begin{mymatrix}{r}\n0 \\\\\n1\n\\end{mymatrix} ,\\]\na standard calculation yields\n\\[\n \\begin{mymatrix}{r}\n0 \\\\\n1\n\\end{mymatrix}\n =\n\\paren{\\frac{1}{2}}\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix}\n+\n\\paren{-\\frac{1}{2}}\n\\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix},\n\\]\nthe first column of $M_{B_{2} B_{1}}$ is $\\begin{mymatrix}{r}\n\\vspace{0.05in}\\frac{1}{2}\\\\\n\\vspace{0.05in}-\\frac{1}{2}\n\\end{mymatrix}$.\n\nThe second column is found in a similar way. We have\n\\[\nT \\paren{\n\\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix}}\n= \\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix} , \\]\nand with respect to $B_2$ calculate:\n\\[\n\\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix}\n=\n0 \\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix}\n+\n1\n\\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix}\n\\]\nHence the second column of $M_{B_{2} B_{1}}$ is given by $\\begin{mymatrix}{r}\n0 \\\\\n1\n\\end{mymatrix}$. We thus obtain\n\\[\nM_{B_{2} B_{1}} = \\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{2} & 0 \\\\\n\\vspace{0.05in}-\\frac{1}{2} & 1\n\\end{mymatrix} \\]\n\nWe can verify that this is the correct matrix $M_{B_{2} B_{1}}$ on the specific example\n\\[\n\\vect{v} = \\begin{mymatrix}{r}\n3 \\\\\n-1\n\\end{mymatrix} \\]\nFirst applying $T$ gives\n\\[\nT( \\vect{v} ) =\nT \\paren{\n\\begin{mymatrix}{r}\n3 \\\\\n-1\n\\end{mymatrix}} = \\begin{mymatrix}{r}\n-1\\\\\n3\n\\end{mymatrix}\n\\]\nand one can compute that\n\\[ C_{B_2}\n \\paren{\n\\begin{mymatrix}{r}\n-1 \\\\\n3\n\\end{mymatrix}} = \\begin{mymatrix}{r}\n1\\\\\n-2\n\\end{mymatrix} .\\]\n\nOn the other hand, one compute $C_{B_1}( \\vect{v})$ as\n\\[ C_{B_1}\n \\paren{\n\\begin{mymatrix}{r}\n3 \\\\\n-1\n\\end{mymatrix}} = \\begin{mymatrix}{r}\n2\\\\\n-1\n\\end{mymatrix} ,\\]\nand finally applying $M_{B_1 B_2}$ gives\n\n\\[\\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{2} & 0 \\\\\n\\vspace{0.05in}-\\frac{1}{2} & 1\n\\end{mymatrix}\n\\begin{mymatrix}{r}\n2 \\\\\n-1\n\\end{mymatrix}\n= \\begin{mymatrix}{r}\n1 \\\\\n-2\n\\end{mymatrix} \\]\nas above.\n\nWe see that the same vector results from either method, as suggested by Theorem~\\ref{thm:matrix-linear-transformation-bases}.\n\\end{solution}\n\nIf the bases $B_1$ and $B_2$ are equal, say $B$, then we write $M_{B}$ instead of  $M_{B B}$.\nThe following example illustrates how to compute  such a matrix. Note that this is what we did earlier when we considered only\n$B_1=B_2$ to be the standard basis.\n\n\\begin{example}{Matrix of a linear transformation with respect to an arbitrary   basis}{arbitrary-bases}\n\nConsider the basis $B$ of $\\R^3$ given by\n\\begin{equation*}\nB = \\set{\\vect{v}_1 , \\vect{v}_2,  \\vect{v}_3} =\n\\set{\n\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n-1 \\\\\n1 \\\\\n0\n\\end{mymatrix} }\n\\]\n\nAnd let $T :\\R^{3}\\to \\R^{3}$ be the linear transformation\ndefined on $B$ as:\n\\begin{equation*}\nT\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n1\n\\end{mymatrix} ,T \\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n-1\n\\end{mymatrix} ,T\\begin{mymatrix}{r}\n-1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\n\\begin{enumerate}\n\\item Find the matrix  $M_{B}$ of $T$ relative to the basis $B$.\n\\item Then find the usual matrix of $T$ with respect to the standard basis of $\\R^{3}$.\n\\end{enumerate}\n\n\\end{example}\n\n\\begin{solution}\n\nEquation  {\\eqref{matrix-equation}}  gives $ C_BT=M_{B}C_B$, and thus\n$M_{B} = C_BTC^{-1}_B$.\n\nNow $C_B(\\vect{v}_i) = \\vect{e}_i$, so the matrix of $C_B^{-1}$ (with respect to the standard basis) is given by\n\\[ \\mat{C_B^{-1}(\\vect{e}_1) \\;\\; C_B^{-1}(\\vect{e}_2) \\;\\; C_B^{-1}(\\vect{e}_2) } =\n\\begin{mymatrix}{rrr}\n1 & 1 & -1 \\\\\n0 & 1 & 1 \\\\\n1 & 1 & 0\n\\end{mymatrix}\n\\]\nMoreover the matrix of  $T C_B^{-1}$ is given by\n\\[ \\mat{TC_B^{-1}(\\vect{e}_1) \\;\\; TC_B^{-1}(\\vect{e}_2) \\;\\; TC_B^{-1}(\\vect{e}_2) } =\n\\begin{mymatrix}{rrr}\n1 & 1 & 0 \\\\\n-1 & 2 & 1 \\\\\n1 & -1 & 1\n\\end{mymatrix}\n\\]\nThus\n\\[ \\begin{array}{ll}\nM_{B} & =  C_BTC^{-1}_B =  [C^{-1}_B]^{-1} [TC^{-1}_B] \\\\\n\t& =\n\\begin{mymatrix}{rrr}\n1 & 1 & -1 \\\\\n0 & 1 & 1 \\\\\n1 & 1 & 0\n\\end{mymatrix} ^{-1}\\begin{mymatrix}{rrr}\n1 & 1 & 0 \\\\\n-1 & 2 & 1 \\\\\n1 & -1 & 1\n\\end{mymatrix} \\\\\n&=\\begin{mymatrix}{rrr}\n2 & -5 & 1 \\\\\n-1 & 4 & 0 \\\\\n0 & -2 & 1\n\\end{mymatrix}\n\\end{array}\n\\]\n\nConsider how this works. Let $\\vect{b} = \\begin{mymatrix}{r}\nb_1 \\\\\nb_2 \\\\\nb_3\n\\end{mymatrix}$ be an arbitrary vector in $\\R^3$.\n\nApply $C^{-1}_{B}$ to $\\vect{b}$ to get\n\\begin{equation*}\nb_1\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} + b_2\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} + b_3\\begin{mymatrix}{r}\n-1 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\nApply $T$ to this linear combination to obtain\n\\begin{equation*}\nb_1\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n1\n\\end{mymatrix} + b_2\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n-1\n\\end{mymatrix} + b_3\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\nb_1+b_2 \\\\\n-b_1 + 2b_2+ b_3 \\\\\nb_1-b_2+b_3\n\\end{mymatrix}\n\\end{equation*}\nNow take the matrix $M_{B}$ of the transformation (as found above) and multiply it by $\\vect{b}$.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n2 & -5 & 1 \\\\\n-1 & 4 & 0 \\\\\n0 & -2 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nb_1 \\\\\nb_2 \\\\\nb_3\n\\end{mymatrix} =\\begin{mymatrix}{c}\n2b_1-5b_2+b_3 \\\\\n-b_1 + 4b_2 \\\\\n-2b_2 + b_3\n\\end{mymatrix}\n\\end{equation*}\nIs this the coordinate vector of the above relative to the given basis? We check as follows.\n\\begin{equation*}\n(2b_1-5b_2+b_3) \\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} +(-b_1 + 4b_2) \\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} +(-2b_2+b_3) \\begin{mymatrix}{c}\n-1 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{equation*}\n= \\begin{mymatrix}{c}\nb_1+b_2 \\\\\n-b_1 + 2b_2+b_3 \\\\\nb_1-b_2+b_3\n\\end{mymatrix}\n\\end{equation*}\nYou see it is the same thing.\n\nNow let us find the matrix of $T$ with respect to the standard basis. Let $A$ be\nthis matrix. That is, multiplication by $A$ is the same as doing $T$. Thus\n\\begin{equation*}\nA\\begin{mymatrix}{rrr}\n1 & 1 & -1 \\\\\n0 & 1 & 1 \\\\\n1 & 1 & 0\n\\end{mymatrix} =\\begin{mymatrix}{rrr}\n1 & 1 & 0 \\\\\n-1 & 2 & 1 \\\\\n1 & -1 & 1\n\\end{mymatrix}\n\\end{equation*}\nHence\n\\begin{equation*}\nA=\\begin{mymatrix}{rrr}\n1 & 1 & 0 \\\\\n-1 & 2 & 1 \\\\\n1 & -1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 1 & -1 \\\\\n0 & 1 & 1 \\\\\n1 & 1 & 0\n\\end{mymatrix} ^{-1}=\\begin{mymatrix}{rrr}\n0 & 0 & 1 \\\\\n2 & 3 & -3 \\\\\n-3 & -2 & 4\n\\end{mymatrix}\n\\end{equation*}\nOf course this is a very different matrix than the matrix of the linear\ntransformation with respect to the non-standard basis.\n\\end{solution}\n", "meta": {"hexsha": "c0881fa6304a2127596f51ce123374d216ed30ce", "size": 14052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/lineartransformationsMatrixTwo.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/lineartransformationsMatrixTwo.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/lineartransformationsMatrixTwo.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 23.5376884422, "max_line_length": 128, "alphanum_fraction": 0.6316538571, "num_tokens": 5807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743167997235783, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.6521126703455292}}
{"text": "\\section{Single-mode squeezing}\n\nLet\n\\begin{equation}\n\\widehat{b}^-\n= \\frac{\\widehat{a}^- - \\beta \\widehat{a}^+}{\\sqrt{1-\\vbr{\\beta}^2}},\\qquad\n\\widehat{b}^+ = \\rbr{\\widehat{b}^-}^\\dagger\n= \\frac{\\widehat{a}^+ - \\beta^*\\widehat{a}^-}{\\sqrt{1-\\vbr{\\beta}^2}},\n\\label{eq:res-bogolyubov-b}\n\\end{equation}\nso that\n\\begin{equation}\n\\sbr{\\widehat{b}^-, \\widehat{b}^+}_- =\n\\rbr{1-\\vbr{\\beta}^2}^{-1}\\rbr{\\sbr{\\widehat{a}^-, \\widehat{a}^+}_-\n+ \\beta\\beta^*\\sbr{\\widehat{a}^+, \\widehat{a}^-}_-} = \\widehat{1}.\n\\end{equation}\nOne seeks the state $\\Ket{\\beta}$ satisfying\n\\begin{equation}\n\\widehat{b}^-\\Ket{\\beta} = 0.\n\\label{eq:squeezed-state-def-1}\n\\end{equation}\n\nNote that \\cref{eq:res-bogolyubov-b} is a restricted \\emph{Bogolyubov\ntransformation}, in that the coefficient of $\\widehat{a}^-$ for $\\widehat{b}^-$\nis real.\n\n\\subsection{Single-mode squeeze operator}\nOne attempts\n\\begin{equation}\n\\rfun{\\widehat{S}}{z}\\widehat{a}^-\\rfun{\\widehat{S}^{-1}}{z},\n\\end{equation}\nwhere\n\\begin{align}\n\t\\rfun{\\widehat{S}}{z} &\\coloneqq \\cfun{\\exp}{\\frac{1}{2}\\rbr{z \n\t\t\\rbr{\\widehat{a}^+}^2 - z^*\\rbr{\\widehat{a}^-}^2}} \\nonumber \\\\\n&\\equiv \\cfun{\\expi}%\n{\\Im z\\rbr{\\frac{m\\Omega}{2}\\widehat{x}^2 - \\frac{2}{m\\Omega}\\widehat{p}^2}\n-\\Re z \\frac{\\widehat{x}\\widehat{p}+\\widehat{p}\\widehat{x}}{2}}\n\\end{align}\nis the \\emph{single-mode squeeze operator}. Note that\n\\begin{equation}\n\\rfun{\\widehat{S}^{-1}}{z} = \\rfun{\\widehat{S}}{-z}\n= \\rfun{\\widehat{S}^\\dagger}{z}.\n\\end{equation}\n\nThe parameterisation $z = r\\ee^{\\ii\\phi}$ will also be used, where $r = \n\\vbr{z}$, $\\phi = \\arg z$.\n\n\\begin{namedthm}{Proposition}\n\t\\label{nthm:prop-ad-aminus}\nLet $X = \\rbr{z\\rbr{\\widehat{a}^+}^2 - z^*\\rbr{\\widehat{a}^-}^2}/2$. Then\n\\begin{align}\n\t\\ad_X^{(2n)} \\widehat{a}^- &= \\vbr{z}^{2n} \\widehat{a}^-\n\t= r^{2n} \\widehat{a}^-,\\\\\n\t\\ad_X^{(2n+1)} \\widehat{a}^-\n\t&= -\\vbr{z}^{2n+1}\\frac{z}{\\vbr{z}}\\widehat{a}^+\n\t= - r^{2n+1} \\ee^{\\ii\\phi} \\widehat{a}^+,\n\t\\qquad \\forall n \\ge 0.\n\\end{align}\n\\end{namedthm} % Proposition\n\\begin{proof}\n\t\\begin{equation}\n\t\t\\ad_X^{(0)}\\widehat{a}^- = \\widehat{a}^-;\n\t\\end{equation}\n\t\\begin{align}\n\t\t\\ad_X^{(1)}\\widehat{a}^- &=\n\t\t\\sbr{\\frac{z}{2}\\rbr{\\widehat{a}^+}^2, \\widehat{a}^-}_- \n\t\t= \\frac{z}{2}\\rbr{\\widehat{a}^+ \\sbr{\\widehat{a}^+, \\widehat{a}^-}_-\n\t\t+ \\sbr{\\widehat{a}^+, \\widehat{a}^-}_- \\widehat{a}^+}\n\t\t= -z\\widehat{a}^+ \\nonumber \\\\\n\t\t&= -\\frac{z}{\\vbr{z}}\\vbr{z}^1\\widehat{a}^+\n\t\t= -\\ee^{\\ii\\phi} r^1 \\widehat{a}^+,\n\t\\end{align}\n\t\\begin{align}\n\t\t\\ad_X^{(2)}\\widehat{a}^- &=\n\t\t\\sbr{-\\frac{z^*}{2}\\rbr{\\widehat{a}^-}^2, -z\\widehat{a}^+}_-\n\t\t= \\frac{\\vbr{z}^2}{2} 2\\widehat{a}^- \\nonumber \\\\\n\t\t&= \\vbr{z}^2\\widehat{a}^- = r^2 \\widehat{a}^-;\n\t\\end{align}\n\t\\begin{align}\n\t\t\\ad_X^{(3)}\\widehat{a}^- &=\n\t\t\\sbr{\\frac{z}{2}\\rbr{\\widehat{a}^+}^2, \\vbr{z}^2\\widehat{a}^-}_-\n\t\t= \\frac{z\\vbr{z}^2}{2} \\rbr{-2} \\widehat{a}^+ \\nonumber \\\\\n\t\t&= -\\frac{z}{\\vbr{z}}\\vbr{z}^3\\widehat{a}^+\n\t\t= -\\ee^{\\ii\\phi} r^3 \\widehat{a}^+.\n\t\\end{align}\n\tProp.~(\\ref{nthm:prop-ad-aminus}) can then be proved by induction for \n\teven and odd integers, respectively.\n\\end{proof}\n\n\\begin{namedthm}{Proposition}\n\\begin{align}\n\t\\rfun{\\widehat{S}}{z} \\widehat{a}^- \\rfun{\\widehat{S}^\\dagger}{z}\n\t&= \\widehat{a}^-\\cosh \\vbr{z}\n\t\t- \\widehat{a}^+ \\frac{z}{\\vbr{z}} \\sinh \\vbr{z}\n\t\\nonumber \\\\\n\t&= \\widehat{a}^-\\cosh r - \\widehat{a}^+ \\ee^{\\ii\\phi} \\sinh r,\n\t\\label{eq:squeezed-aminus-parameter}\n\\end{align}\nso that $z$ or $\\rbr{r, \\phi}$ is a parameterisation of $\\beta$ in \n\\cref{eq:res-bogolyubov-b} in that\n\\begin{equation}\n\t\\vbr{\\beta} = \\tanh\\vbr{z} = \\tanh r,\\qquad \\arg \\beta = \\arg z = \\phi.\n\t\\label{eq:beta-parameter}\n\\end{equation}\n\\end{namedthm} %Proposition\n\\begin{proof}\n\tBy prop.~\\ref{nthm:prop-ad-aminus} and \\cref{eq:bch-sandwich},\n\t\\begin{equation} % \\begin{align}\n\t\t\\rfun{\\widehat{S}}{z} \\widehat{a}^- \\rfun{\\widehat{S}^\\dagger}{z}\n\t\t= \\sum_{n=0}^{+\\infty}\\rbr{\n\t\t\t\\frac{\\vbr{z}^{2n}}{\\rbr{2n}!} \\widehat{a}^-\n- \\frac{z}{\\vbr{z}}\\frac{\\vbr{z}^{2n+1}}{\\rbr{2n+1}!}\\widehat{a}^+}\n\t\t%\\nonumber \\\\\n\t\t%&= \\widehat{a}^-\\cosh \\vbr{z}\n\t\t%- \\widehat{a}^+ \\frac{z}{\\vbr{z}} \\sinh \\vbr{z} \\nonumber \\\\\n\t\t%&= \\widehat{a}^-\\cosh r - \\widehat{a}^+ \\ee^{\\ii\\phi} \\sinh r,\n\t\t\\label{eq:squeezed-aminus-parameter-proof}\n\t\\end{equation} % \\end{align}\n\twhich proves \\cref{eq:squeezed-aminus-parameter}. Comparing \n\t\\cref{eq:squeezed-aminus-parameter-proof} with \\cref{eq:res-bogolyubov-b}, \n\tone gets\n\t\\begin{equation}\n\t\t\\left\\{\\begin{array}{l}\n\t\t\t\\rbr{1-\\vbr{\\beta}^2}^{-1/2} = \\cosh \\vbr{z} = \\cosh r, \\\\\n\t\t\t\\beta (1-\\vbr{\\beta}^2)^{-1/2}\n\t\t\t= \\frac{z}{\\vbr{z}}\\sinh \\vbr{z} = \\ee^{\\ii\\phi}\\sinh r,\n\t\t\\end{array}\\right.\n\t\\end{equation}\n\twhich gives \\cref{eq:beta-parameter}.\n\\end{proof}\n\n\n\\begin{namedthm}{Squeezed ground state}\n\t$\\Ket{\\beta}$ in \\cref{eq:squeezed-state-def-1} is the $\\beta$-squeezed \nground state, namely\n\\begin{equation}\n\t\\Ket{\\beta} = \\rfun{\\widehat{S}}{z}\\Ket{0}.\n\\end{equation}\n\n\\end{namedthm} % Squeezed ground state\n\\begin{proof}\nNote that\n\\begin{equation}\na^-\\Ket{0} \\coloneqq 0 \\eqqcolon \\rfun{S^\\dagger}{\\beta} b^- \\Ket{0}\n= a^- \\rfun{S^\\dagger}{\\beta} \\Ket{\\beta}.\n\\end{equation}\nWith $\\rfun{S}{\\alpha}$ unitary in mind, one finds\n\\begin{equation}\n\\Ket{\\beta} = \\ee^{\\ii\\theta}\\rfun{S}{\\beta}\\Ket{0}.\n\\end{equation}\nOne can fix the phase $\\theta$ to be zero.\n\\end{proof}\n\n\n\\subsection{Time evolution}\n\n\\begin{namedthm}{Proposition}\n\tLet $X = \\ii\\Omega t a^+ a^-$, $Y = \\frac{1}{2}\\rbr{z \n\t\t\\rbr{a^+}^2 - z^*\\rbr{a^-}^2}$.\n\t\\begin{equation}\n\t\t\\ad_X^{(n)}Y = \\frac{1}{2}\\rbr{z \\rbr{+2\\ii\\Omega t}^n\n\t\t\\rbr{a^+}^2 - z^*\\rbr{-2\\ii\\Omega t}^n\\rbr{a^-}^2}.\n\t\\end{equation}\n\n\\end{namedthm} % Proposition\n\\begin{proof}\n\\begin{equation}\n\\ad_X^{(0)}Y = Y = \\rbr{2\\ii t}^0 Y;\n\\end{equation}\n\n\\begin{align}\n\t\\ad_X^{(1)}Y &= \\sbr{\\ii\\Omega t a^+ a^-, \\frac{1}{2}\\rbr{z \n\t\t\\rbr{a^+}^2 - z^*\\rbr{a^-}^2}}_- \\nonumber \\\\\n&= \\ii \\Omega t\\rbr{z\\rbr{a^+}^2 + z^*\\rbr{a^-}^2} \\nonumber \\\\\n&= \\frac{1}{2}\\rbr{z \\rbr{+2\\ii\\Omega t}^1\n\t\t\\rbr{a^+}^2 - z^*\\rbr{-2\\ii\\Omega t}^1\\rbr{a^-}^2};\n\\end{align}\n\\begin{align}\n\t\\ad_X^{(2)}Y &= \\sbr{\\ii\\Omega t a^+ a^-, \\ii \\Omega t \n\\rbr{z\\rbr{a^+}^2 + z^*\\rbr{a^-}^2} }_- \\nonumber \\\\\n&= 2\\rbr{\\ii \\Omega t}^2\\rbr{ z\\rbr{a^+}^2 - z^*\\rbr{a^-}^2} \\nonumber \\\\\n&= \\frac{1}{2}\\rbr{z \\rbr{+2\\ii\\Omega t}^2\n\t\t\\rbr{a^+}^2 - z^*\\rbr{-2\\ii\\Omega t}^2\\rbr{a^-}^2};\n\\end{align}\nCan be proved by induction.\n\\end{proof}\n\n\\begin{namedthm}{Proposition}\n\\begin{equation}\n\\rfun{\\mscrU}{t}\\rfun{S}{z}\t= \\rfun{S}{z^t}\\rfun{\\mscrU}{t},\n\\end{equation}\nwhere\n\\begin{equation}\nz^t \\coloneqq z\\ee^{2\\ii\\Omega t}.\n\\end{equation}\n\n\\end{namedthm} % Proposition\n\\begin{proof}\nSum up.\n\\end{proof}\n\nNote one also has $\\beta^t \\coloneqq \\beta \\ee^{2\\ii\\Omega t}$.\n\n\n\\subsection{Particle numbers}\n\n\\begin{namedthm}{Lemma}[Factorising $\\rfun{\\widehat{S}}{z}$]\n\\begin{alignat}{3}\n\\rfun{\\widehat{S}}{z} &=&&\n\\cfun{\\exp}{+\\frac{1}{2}\\rbr{\\widehat{a}^+}^2\\ee^{+\\ii\\theta}\\tanh r}\n\\nonumber \\\\\n&&\\cdot& \\cfun{\\exp}{\\rbr{\\frac{1}{2}+\\widehat{a}^+\\widehat{a}^-}\\ln\\sech r}\n\\cfun{\\exp}{-\\frac{1}{2}\\rbr{\\widehat{a}^-}^2\\ee^{-\\ii\\theta}\\tanh r}\n\\\\\n&=&&\\cfun{\\exp}{\\frac{\\beta}{2} \\rbr{\\widehat{a}^+}^2} \n\\cfun{\\exp}{\\rbr{\\frac{1}{2}+\\widehat{a}^+\\widehat{a}^-} \n\\ln\\sqrt{1-\\vbr{\\beta}^2}}\n\\cfun{\\exp}{-\\frac{\\beta^*}{2}\\rbr{\\widehat{a}^-}^2}.\n\\end{alignat}\n\\end{namedthm} % Lemma\n\n\\begin{nameddef}{Particle number representation of $\\Ket{\\beta}$}\n\\begin{align}\n\\Braket{2n | \\beta} &= \\rbr{1-\\vbr{\\beta}^2}^{1/4}\n\\frac{\\sqrt{\\rbr{2n}!}}{2^n n!}\\beta^n, \\\\\n\\Braket{2n+1 | \\beta} &= 0.\n\\end{align}\n\n\\end{nameddef}\n\n\n\\begin{equation}\n\t\\Braket{\\beta | \\widehat{a}^+\\widehat{a}^- | \\beta}\n\t= \\Braket{0 | \\rfun{S^\\dagger}{z}\\widehat{a}^+\n\t\\widehat{a}^-\\rfun{S}{z} | 0}\n\t= \\sinh^2 r = \\frac{\\vbr{\\beta}^2}{1-\\vbr{\\beta}^2}.\n\\end{equation}\n\n\\begin{equation}\n\t\\Braket{0 | \\widehat{b}^+\\widehat{b}^- | 0}\n\t= \\Braket{0 | \\rfun{S}{z}\\widehat{a}^+\\rfun{S^\\dagger}{z}\n\t\\rfun{S}{z}\\widehat{a}^-\\rfun{S^\\dagger}{z} | 0}\n\t= \\sinh^2 r = \\frac{\\vbr{\\beta}^2}{1-\\vbr{\\beta}^2}.\n\\end{equation}\n\n\\subsection{Wave function}\n\n\\begin{namedthm}{Lemma}[Factorising $\\rfun{\\widehat{S}}{z}$]\n\\begin{equation}\n\t\\rfun{\\widehat{S}}{z} =\n\t\\rfun{\\expi}{\\frac{m\\Omega}{2}\\sigma_z \\, x^2}\n\t\\rfun{\\expi}{-\\ln \\lambda_z\\,\\frac{\\widehat{x}\\widehat{p} + \n\t\t\t\\widehat{p}\\widehat{x}}{2}}\n\t\\rfun{\\expi}{-\\frac{\\sigma_z}{2m\\Omega}\\, p^2},\n\\end{equation}\nwith\n\\begin{align}\n\t\\lambda_z &\\coloneqq \\cosh r + \\cos\\phi\\,\\sinh r \\equiv\n\t\\ee^{+r} \\cos^2\\frac{\\phi}{2}+\\ee^{-r}\\sin^2\\frac{\\phi}{2}, \\\\\n\t\\sigma_z &\\coloneqq \\frac{1}{\\cot\\phi+\\coth r\\,\\csc\\phi} \\equiv\n\t\\frac{\\sin\\phi\\,\\sinh r}{\\lambda_z}.\n\t\\end{align}\n\\end{namedthm} % Lemma\n\n\\begin{namedthm}{Proposition}\n\\begin{equation}\n\\lambda_z^2\\rbr{1+\\sigma_z^2} = \\lambda_{2z}\n\\end{equation}\n\n\\end{namedthm} % Proposition\n\n\n\\begin{nameddef}{Wave function of $\\Ket{\\beta}$}\n\\begin{align}\n\t&\\phantom{{}={}} \\Braket{x | \\ee^{\\ii b_1 \\widehat{x}^2} \\ee^{\\ii b_2 \n\t\t\\rbr{\\widehat{x} \\widehat{p} + \\widehat{p} \\widehat{x}}/2} \\ee^{\\ii b_3 \n\t\t\\widehat{p}^2} | \\psi} \\nonumber \\\\\n\t&= \\ee^{\\ii b_1 x^2} \\Braket{x | \\ee^{\\ii b_2 \n\t\t\\rbr{\\widehat{x} \\widehat{p} + \\widehat{p} \\widehat{x}}/2} \\ee^{\\ii b_3 \n\t\t\\widehat{p}^2} | \\psi} \\nonumber \\\\\n\t&= \\ee^{\\ii b_1 x^2 + b_2/2} \\Braket{x \\ee^{b_2} | \\ee^{\\ii b_3 \n\t\\widehat{p}^2} | \\psi} \\nonumber \\\\\n\t&= \\frac{\\ee^{\\ii b_1 x^2 + b_2/2}}{\\rbr{-4\\pp\\ii b_3}^{1/2}}\n\t\t\\int_{-\\infty}^{+\\infty}\\dif x'\\,\\cfun{\\expi}{-\\frac{\\rbr{x\\ee^{b_2} \n\t\t-x'}^2}{4b_3}}\\Braket{x' | \\psi}.\n\\end{align}\nFor $\\rfun{\\widehat{S}}{z}$, $b_1 = m\\Omega\\sigma_z/2$, $b_2 = -\\ln \\lambda_z$, \n$b_3 = -\\sigma_z/2m\\Omega$, and $\\Ket{\\psi} = \\Ket{0}$, so that\n\t\\begin{align}\n\t&\\phantom{{}={}} \\rbr{\\frac{m\\Omega}{\\pp}}^{-1/4} \\Braket{x | \n\t\t\\rfun{\\widehat{S}}{z} | 0} \\nonumber \\\\\n\t&= \\rbr{\\lambda_z\\rbr{1+\\ii\\sigma_z}}^{-1/2}\n\t\\cfun{\\exp}{-\\frac{m\\Omega x^2}{2}\n\t\\rbr{\\frac{1}{\\lambda_z^2\\rbr{1+\\ii\\sigma_z}} - \\ii\\sigma_z}} \\nonumber \\\\\n\t&= \\rbr{\\lambda_z^2\\rbr{1+\\sigma_z^2}}^{-1/4}\n\t\\cfun{\\exp}{-\\frac{m\\Omega x^2}{2 \\lambda_z^2\\rbr{1+\\sigma_z^2}}}\n\t\\cfun{\\expi}{\\frac{m\\Omega x^2 \\sigma_z}{2 \\lambda_z^2\\rbr{1+\\sigma_z^2}}\n\t\t- \\frac{\\rfun{\\arg}{1+\\ii\\sigma_z}}{2}} \\nonumber \\\\\n\t&= \\lambda_{2z}^{-1/4}\n\t\\cfun{\\exp}{-\\frac{m\\Omega}{2 \\lambda_{2z}} x^2} \n\t\\cfun{\\expi}{\\frac{m\\Omega\\sigma_{2z}}{2} x^2 - \\frac{1}{2}\n\t\\rfun{\\arg}{1+\\ii\\sigma_z}}.\n\t%\\nonumber \\\\\n\t\\end{align}\n\\end{nameddef} % Wave function of $\\Ket{\\beta}$\n\n\\subsection{Density matrix and Wigner function}\n\n\\begin{nameddef}{Density matrix in the particle number representation}\n\\begin{align}\n\\Braket{2n_1 | \\widehat{\\rho} | 2n_2} &= \\sqrt{1-\\vbr{\\beta}^2}\n\\frac{\\sqrt{\\rbr{2n_1}!\\rbr{2n_2}!}}{2^{n_1+n_2}n_1!n_2!}\n\\beta^{n_1} \\rbr{\\beta^*}^{n_2} \\nonumber \\\\\n&= \\sqrt{1-\\vbr{\\beta}^2}\n\\frac{\\sqrt{\\rbr{2n_1}!\\rbr{2n_2}!}}{2^{n_1+n_2}n_1!n_2!}\n\\ee^{\\ii\\rbr{n1-n2}\\phi}\\rbr{\\tanh r}^{n_1+n_2}.\n\\end{align}\n\\end{nameddef} % Density matrix in the particle number representation\n\n\\begin{nameddef}{Density matrix in the position representation}\n\\begin{equation}\n\\Braket{x_1 | \\widehat{\\rho} | x_2} = \\sqrt{\\frac{m\\Omega}{2\\lambda_{2z}}}\n\\cfun{\\exp}{-\\frac{m\\Omega}{2\\lambda_{2z}}\\rbr{x_1^2 + x_2^2}}\n\\cfun{\\expi}{\\frac{m\\Omega\\sigma_{2z}}{2}\\rbr{x_1^2-x_2^2}}.\n\\end{equation}\n\\end{nameddef} % Density matrix in the position representation\n\n\\begin{nameddef}{Wigner function}\n\\begin{align}\n\t&\\phantom{{}={}} \\rfun{W}{x, p} \\nonumber \\\\\n\t&= \\pp^{-1} \\cfun{\\exp}{- m\\Omega\\lambda_{-2z} x^2\n\t+ 2 \\lambda_{2z} \\sigma_{2z} x p - \\lambda_{2z} \\frac{p^2}{m\\Omega}} \\\\\n\t&\\equiv \\pp^{-1} \\cfun{\\exp}{-m\\Omega \\frac{X^2}{\\ee^{+2r}} - \n\t\t\\frac{1}{m\\Omega}\\frac{P^2}{\\ee^{-2r}}},\n\\end{align}\nwhere\n\\begin{equation}\n\t\\begin{pmatrix} \\rbr{m\\Omega}^{+1/2} X \\\\\n\t\t\\rbr{m\\Omega}^{-1/2} P \\end{pmatrix} \\coloneqq\n\t\\begin{pmatrix}\n\t\\cos\\phi/2 & \\sin\\phi/2 \\\\ -\\sin\\phi/2 & \\cos\\phi/2\n\t\\end{pmatrix}\n\t\\begin{pmatrix} \\rbr{m\\Omega}^{+1/2} x \\\\\n\t\t\\rbr{m\\Omega}^{-1/2} p \\end{pmatrix}\n\\end{equation}\nare principle coordinates of the Wigner ellipse. One sees that \n$\\phi/2$ rotates the canonical coordinates for the Wigner function, while\n$\\ee^{+r}$ ($\\ee^{-r}$) stretches (squeezes) the principle axis of $X$ ($P$),\nif $r > 0$.\n\\end{nameddef} % Wigner function\n", "meta": {"hexsha": "80cfca9503543026d6959b415af764e7d5fc5e26", "size": 12076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/gen-coh-squ/sections/1squeeze.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/1squeeze.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/1squeeze.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": 34.3068181818, "max_line_length": 80, "alphanum_fraction": 0.5993706525, "num_tokens": 5833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6520831004572377}}
{"text": "\\lab{Interior Point II}{Interior Point II}\n\\objective{Learn About Interior Point Methods for Quadratic Constrained Optimization.}\n\nIn this lab, we will explore an extension of Interior Point methods to a broader class of\nproblems, namely quadratic constrained optimization problems.\nA \\emph{quadratic constrained optimization problem}, also known as a quadratic program,\ndiffers from a linear constrained optimization problem (or linear program) only in that\nthe objective function is quadratic rather than linear.\nWe can pose such a problem as follows:\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}&x^TQx + c^Tx\\\\\n\\text{subject to }\\qquad &Ax \\geq b,\\\\\n&Gx = h.\n\\end{align*}\nUnlike linear constrained optimization, the optimal point is not guaranteed to be one of the vertices of the\nfeasible polytope. Thus, any attempt to extend the popular Simplex Algorithm to quadratic\nprograms would require substantial adjustments, as that algorithm is based crucially on locating and searching through\nthe vertices of the feasible region. Interior Point methods, however, generalize readily to the situation at hand.\nIn this lab, you will learn about and implement a primal-dual Interior Point method for quadratic constrained\noptimization. You will then explore applications in elastic membrane theory and in finance.\n\n\\section*{Quadratic Interior Point Method}\nWe will restrict our attention to quadratic programs involving positive semidefinite quadratic terms.\n(In general, indefinite quadratic objective functions admit many local minima, complicating matters\nconsiderably.) Such problems are called \\emph{convex}, since the objective function is convex.\nTo simplify the exposition, we will also only allow inequality constraints (generalizing to\ninclude equality constraints is not a difficult task). Thus, we have the problem\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}&x^TQx + c^Tx\\\\\n\\text{subject to }\\qquad &Ax \\geq b,\\\\\n\\end{align*}\nwhere $Q$ is an $n\\times n$ positive semidefinite matrix, $x, c \\in \\mathbb{R}^n$, $A$ is an $m \\times n$ matrix,\nand $b \\in \\mathbb{R}^m$.\n\nThe Interior Point method we describe here is an adaptation of the method we used with linear\nprogramming. The basic intuition is the same as before: we start at some point in the interior of the\nfeasible region, and we make a series of steps so that we approach the solution to the KKT conditions\niteratively. Since the the solution to the KKT conditions can be seen as the root of a system of equations,\nour first thought might be to use Newton's Method for root-finding. This will not work on its own, however,\nbecause the KKT conditions also require inequality constraints, which will be violated if we blindly apply\nNewton's Method. Hence, we make adjustments to our choice of search direction and step size, so that we\nrespect the constraints while moving closer to the solution of the KKT conditions.\n\nWe begin by deriving the KKT conditions for this problem. The first step is to form the Lagrangian function,\nwhich has the form\n\\[\n\\mathcal{L}(x,\\lambda) = \\frac{1}{2}x^TQx + c^Tx - \\lambda^T(Ax -b).\n\\]\nWe next take the gradient of the Lagrangian with respect to $x$ and set it equal to zero:\n\\begin{align*}\n0 &= \\nabla_x \\mathcal{L}(x,\\lambda)\\\\\n&= Qx + c - A^T\\lambda.\n\\end{align*}\nWe next write the complementary slackness condition:\n\\[\n(Ax - b)_i\\lambda_i = 0, \\qquad i=1,2,\\ldots,m.\n\\]\nWe finish by listing the inequality constraints as well as the nonnegativity constraint for $\\lambda$:\n\\begin{align*}\nAx - b &\\geq 0,\\\\\n\\lambda &\\geq 0.\n\\end{align*}\n\nWhat we have now is a mixture of equations and inequalities. We want to express these conditions as a system of equations,\nso we introduce a nonnegative slack vector $y$ to change the inequality\n\\[\nAx - b \\geq 0\n\\]\ninto an equality\n\\[\nAx - b - y = 0.\n\\]\nThis clearly implies that $y = Ax - b$, so we make this substitution into the complementary slackness conditions.\nWe obtain the following statement of the KKT conditions:\n\\begin{align*}\nQx - A^T\\lambda + c &= 0,\\\\\nAx - y - b &= 0,\\\\\ny_i\\lambda_i &= 0, \\qquad i=1,2,\\ldots,m,\\\\\ny,\\lambda &\\geq 0.\n\\end{align*}\n\nDefine $\\mathcal{Y} = \\text{diag}(y_1,y_2,\\ldots,y_m)$ and $\\Lambda = \\text{diag}(\\lambda_1,\\lambda_2,\\ldots,\\lambda_m)$.\nDenote the vector in $\\mathbb{R}^m$ consisting entirely of ones by $e$. With this notation, we can define a function\n\\[\nF(x,y,\\lambda) =\n\\begin{bmatrix}\nQx-A^Ty + c\\\\\nAx-y-b\\\\\n\\mathcal{Y}\\Lambda e\n\\end{bmatrix}.\n\\]\nThen our KKT conditions can be expressed succinctly in the following manner:\n\\begin{align*}\nF(x,y,\\lambda) &= 0,\\\\\ny,\\lambda &\\geq 0.\n\\end{align*}\nOur goal is to produce a sequence of points that approach the solution to this system of equations, all the while\nrespecting the nonnegativity constraints $y,\\lambda \\geq 0$.\n\nWe achieve this goal using largely the same approach our linear programming Interior Point method.\nWe first apply Newton's method to $F$, obtaining a Newton search direction $(\\triangle x, \\triangle y, \\triangle \\lambda)$\nthat solves the system\n\\begin{equation}\n\\begin{bmatrix}\nQ & 0 & -A^T\\\\\nA & -I & 0\\\\\n0 & \\Lambda & \\mathcal{Y}\n\\end{bmatrix}\n\\begin{bmatrix}\n\\triangle x\\\\\n\\triangle y\\\\\n\\triangle \\lambda\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-Qx + A^T\\lambda - c\\\\\n-Ax + y + b\\\\\n-\\Lambda\\mathcal{Y}e\n\\end{bmatrix}.\n\\label{eq:affine}\n\\end{equation}\nWe may not be able to step far in this direction without violating the nonnegativity constraints, so we calculate\nan improved direction by perturbing the system of equations. This is done by making several small calculations.\n\nFirst calculate the \\emph{duality measure}\n\\[\n\\mu = \\frac{1}{m}y^T\\lambda,\n\\]\nwhich tells us about how close we are to the optimal point (values closer to zero indicate better proximity to the optimizer).\n\nNext, we calculate a maximal allowed step length in the Newton direction:\n\\[\n\\hat{\\alpha} = \\max \\{\\alpha \\in (0,1] \\, | \\, (y,\\lambda) + \\alpha(\\triangle y, \\triangle \\lambda) \\geq 0\\}.\n\\]\nYou can check that this value is given by the minimum of the values\n\\begin{align*}\n\\min\\left(1, \\min_{i : \\triangle y_i < 0} - \\frac{y_i}{\\triangle y_i}\\right),\\\\\n\\min\\left(1, \\min_{i : \\triangle \\lambda_i < 0} -\\frac{\\lambda_i}{\\triangle \\lambda_i}\\right).\n\\end{align*}\n\nContinuing on, we compute the Newton duality measure given by\n\\[\n\\hat{\\mu} = \\frac{1}{m}(y + \\hat{\\alpha}\\triangle y)^T(\\lambda + \\hat{\\alpha}\\triangle \\lambda),\n\\]\nand then the centering parameter\n\\[\n\\sigma = \\left(\\frac{\\hat{\\mu}}{\\mu}\\right)^3.\n\\]\n\nFinally, we obtain our search direction $(\\triangle x', \\triangle y', \\triangle \\lambda')$ by solving the perturbed\nsystem\n\\begin{equation}\n\\begin{bmatrix}\nQ & 0 & -A^T\\\\\nA & -I & 0\\\\\n0 & \\Lambda & \\mathcal{Y}\n\\end{bmatrix}\n\\begin{bmatrix}\n\\triangle x'\\\\\n\\triangle y'\\\\\n\\triangle \\lambda'\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-Qx + A^T\\lambda - c\\\\\n-Ax + y + b\\\\\n-\\Lambda\\mathcal{Y}e - \\triangle \\Lambda\\triangle\\mathcal{Y}e + \\sigma\\mu e\n\\end{bmatrix}.\n\\label{eq:perturbed}\n\\end{equation}\n\nNow that we have our search direction, we select a step length. We want to step nearly as far as possible\nwithout violating the nonnegativity constraints. We back off slightly from the maximum allowed step length, however,\nbecause an overly greedy step at one iteration may prevent a decent step at the next iteration. Thus,\nwe choose our step size\n\\[\n\\alpha = \\max\\{a \\in (0,1] \\, | \\, \\tau(y,\\lambda) +a(\\triangle y', \\triangle \\lambda') \\geq 0\\},\n\\]\nwhere $\\tau \\in (0,1)$ controls how much we back off from the maximal step length. For now, choose $\\tau = 0.9$.\nIn general, $\\tau$ can be made to approach $1$ at each successive iteration, and this may speed up convergence in some cases.\n\nFinally, we step to our new point $(x', y', \\lambda')$ using the formula\n\\[\n(x', y', \\lambda') = (x, y, \\lambda) + \\alpha(\\triangle x', \\triangle y', \\triangle \\lambda').\n\\]\nThis completes one iteration of the algorithm.\nWe summarize the entire procedure in Algorithm \\ref{alg:predcorr}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Predictor-Corrector Algorithm for QP}{}\n    \\State \\textrm{Choose initial point } $(x_0, y_0, \\lambda_0)$.\n    \\For{$k = 0, 1, 2, \\ldots$}\n        \\State \\textrm{Solve \\ref{eq:affine} for } $(\\triangle x, \\triangle y, \\triangle \\lambda)$.\n        \\State \\textrm{Calculate } $\\mu, \\hat{\\alpha}, \\hat{\\mu},$\\textrm{and} $\\sigma$.\n        \\State \\textrm{Solve \\ref{eq:perturbed} for } $(\\triangle x', \\triangle y',\\triangle \\lambda')$.\n        \\State \\textrm{Calculate the step length } $\\alpha$.\n        \\State $(x_{k+1}, y_{k+1}, \\lambda_{k+1}) = (x_k, y_k, \\lambda_k) + \\alpha(\\triangle x', \\triangle y', \\triangle \\lambda').$\n    \\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Predictor-Corrector Algorithm}\n\\label{alg:predcorr}\n\\end{algorithm}\n\nAs with our Interior Point method for linear constrained optimization, the most expensive part of each iteration\nis solving the linear systems \\ref{eq:affine} and \\ref{eq:perturbed}. Note, however, that these systems both have\nthe same matrix on the left-hand side. This allows us to factor the matrix just once per iteration, and use the\nfactorization to solve both systems. A more sophisticated implementation would likely split up these large\nsystems of equations into a few smaller ones, and then use Cholesky-based factorizations. To simplify matters, we\nsuggest simply using as a first attempt an LU decomposition on the entire matrix.\n\nAs usual, the starting point $(x_0, y_0, \\lambda_0)$ has an important effect on the convergence of the algorithm.\nThe code listed below will calculate an appropriate starting point:\n\\begin{lstlisting}\ndef startingPoint(G, c, A, b, guess):\n    \"\"\"\n    Obtain an appropriate initial point for solving the QP\n    .5 x^T Gx + x^T c s.t. Ax >= b.\n    Inputs:\n        G -- symmetric positive semidefinite matrix shape (n,n)\n        c -- array of length n\n        A -- constraint matrix shape (m,n)\n        b -- array of length m\n        guess -- a tuple of arrays (x, y, l) of lengths n, m, and m, resp.\n    Returns:\n        a tuple of arrays (x0, y0, l0) of lengths n, m, and m, resp.\n    \"\"\"\n    m,n = A.shape\n    x0, y0, l0 = guess\n\n    # initialize linear system\n    N = np.zeros((n+m+m, n+m+m))\n    N[:n,:n] = G\n    N[:n, n+m:] = -A.T\n    N[n:n+m, :n] = A\n    N[n:n+m, n:n+m] = -np.eye(m)\n    N[n+m:, n:n+m] = np.diag(l0)\n    N[n+m:, n+m:] = np.diag(y0)\n    rhs = np.empty(n+m+m)\n    rhs[:n] = -(G.dot(x0) - A.T.dot(l0)+c)\n    rhs[n:n+m] = -(A.dot(x0) - y0 - b)\n    rhs[n+m:] = -(y0*l0)\n\n    sol = la.solve(N, rhs)\n    dx = sol[:n]\n    dy = sol[n:n+m]\n    dl = sol[n+m:]\n\n    y0 = np.maximum(1, np.abs(y0 + dy))\n    l0 = np.maximum(1, np.abs(l0+dl))\n\n    return x0, y0, l0\n\\end{lstlisting}\nNotice that you still need to provide a tuple of arrays \\li{guess} as an argument.\nDo your best to provide a reasonable guess for the array $x$, and we suggest setting $y$ and $\\lambda$\nequal to arrays of ones. You will need to call this function at the start of your algorithm.\n\n\\begin{problem}\nWrite a function \\li{qInteriorPoint} that implements the Interior Point method described above.\nThe function should accept the arrays $Q, c, A,$ and $b$, as well as a tuple of arrays \\li{guess}\ngiving initial estimates for $x, y,$ and $\\lambda$ as explained above. Also include keyword\narguments \\li{niter}, giving the number of iterations to execute, and \\li{verbose}, a boolean value\nindicating whether or not to print the current objective function value and duality measure at each\niteration. The function should return the optimal point $x$.\n\\end{problem}\n\nYou can test your algorithm on the simple problem\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}x^2 + &y^2 - xy - 2x - 6y\\\\\n\\text{subject to }\\qquad x+y &\\leq 2,\\\\\n-x+2y &\\leq 2,\\\\\n2x+y&\\leq 3,\\\\\nx, y &\\geq 0.\n\\end{align*}\nIn this case, we have\n\\[\nQ = \\begin{bmatrix}\n1 & -1\\\\\n-1 & 2\n\\end{bmatrix},\n\\]\nwith\n\\[\nc = \\begin{bmatrix}\n-2\\\\\n-6\n\\end{bmatrix}.\n\\]\nWe need to multiply some of the inequality constraints by $-1$ so that they become $\\geq$ constraints.\nAfter doing this, our constraint matrix is\n\\[\nA = \\begin{bmatrix}\n-1 & -1\\\\\n1 & -2\\\\\n-2 & -1\\\\\n1 & 0\\\\\n0 & 1\n\\end{bmatrix},\n\\]\nwith\n\\[\nb = \\begin{bmatrix}\n-2\\\\\n-2\\\\\n-3\\\\\n0\\\\\n0\n\\end{bmatrix}.\n\\]\nWe solve this problem with the following code:\n\\begin{lstlisting}\n>>> # test out our algorithm\n>>> Q = np.array([[1,-1.],[-1,2]])\n>>> c = np.array([-2,-6.])\n>>> A = np.array([[-1, -1], [1, -2.], [-2, -1], [1, 0], [0,1]])\n>>> b = np.array([-2, -2, -3., 0, 0])\n>>> x = np.array([.5, .5])\n>>> y = np.ones(5)\n>>> l = np.ones(5)\n>>> print qInteriorPoint(Q, c, A, b, (x,y,l), niter=7, verbose=True)\n-7.915197 1.125000\n-8.030077 0.172185\n-8.208776 0.068795\n-8.221550 0.004676\n-8.222189 0.000234\n-8.222221 0.000012\n-8.222222 0.000001\n(array([ 0.66666668,  1.3333333 ]), -8.222222138159772)\n\\end{lstlisting}\nCheck that your function gives the same output.\n\n\\section*{Application: Optimal Elastic Membranes}\nThe properties of elastic membranes (stretchy materials like a thin rubber sheet) are of interest in\ncertain fields of mathematics and various sciences. A mathematical model for\nsuch materials can be used by biologists to study interfaces in cellular regions in an organism, or by engineers\nto design tensile structures. Often we can describe configurations of elastic membranes as a solution to an\noptimization problem. As a simple example, we will find the shape of a large circus tent by solving a quadratic\nconstrained optimization problem using our Interior Point method.\n\nImagine a large circus tent held up by a few poles. We can model the tent by a square two-dimensional grid,\nwhere each grid point has an associated number that gives the height of the tent at that point. At each\ngrid point containing a tent pole, the tent height is constrained to be at least as large as the height of\nthe tent pole. At all other grid points, the tent height is simply constrained to be greater than zero (ground height).\nNote that in Python, we can store a two-dimensional grid of values as a simple two-dimensional array.\nWe can then flatten this array to give a one-dimensional vector representation of the grid.\nIf we let $x$ be a one-dimensional array giving the tent height at each grid point, and $L$ be the one-dimensional\narray giving the underlying tent pole structure (consisting mainly of zeros, except at the grid points that contain\na tent pole), we have the following linear constraints:\n\\[\nx \\geq L,\n\\]\nwhere we mean entry-wise inequality between the arrays.\n\nNow, the theory of elastic membranes tells us that such materials tend to naturally minimize a quantity known\nas the \\emph{Dirichlet energy}. This quantity can be expressed as a quadratic function of the membrane.\nSince we have modeled our tent with a discrete grid of values, this energy function has the form\n\\[\n\\frac{1}{2}x^T H x + c^T x,\n\\]\nwhere $H$ is a particular positive semidefinite matrix closely related to Laplace's Equation, and $c$ is a\nvector whose entries are all equal to $-(n-1)^{-2}$, where $n$ is the side length of the grid.\n\nOur circus tent is then given by the solution to the quadratic constrained optimization problem\n\\begin{align*}\n\\text{minimize }\\qquad &\\frac{1}{2}x^T H x + c^T x\\\\\n\\text{subject to }\\qquad &x \\geq L.\\\\\n\\end{align*}\nSee Figure \\ref{fig:tent} for an example of a tent pole configuration and the corresponding tent.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{tent.pdf}\n\\caption{Tent pole configuration (left) and optimal elastic tent (right).}\n\\label{fig:tent}\n\\end{figure}\n\nThe following code is helpful in solving this problem. We first provide a method that calculates the matrix $H$.\n\\begin{lstlisting}\ndef laplacian(n):\n    \"\"\"\n    Construct the discrete Dirichlet energy matrix H for an n x n grid.\n    Inputs:\n        n -- side length of grid\n    Returns:\n        dense array of shape n^2 x n^2\n    \"\"\"\n    n = n+2\n    data = -1*np.ones((5, (n-2)**2))\n    data[2,:] = 4\n    data[1, n-3::n-2] = 0\n    data[3, ::n-2] = 0\n    diags = np.array([-n+2, -1, 0, 1, n-2])\n    return spar.spdiags(data, diags, (n-2)**2, (n-2)**2).todense()\n\\end{lstlisting}\nNext, we initialize the tent pole configuration for a grid of side length $n$.\n\\begin{lstlisting}\n>>> #create the tent pole configuration\n>>> L = np.zeros((n,n))\n>>> L[n/2-1:n/2+1,n/2-1:n/2+1] = .5\n>>> m = [n/6-1, n/6, int(5*(n/6.))-1, int(5*(n/6.))]\n>>> mask1, mask2 = np.meshgrid(m, m)\n>>> L[mask1, mask2] = .3\n>>> L = L.ravel()\n\\end{lstlisting}\nAn appropriate initial guess for $x, y$ and $\\lambda$ is\n\\begin{lstlisting}\n>>> #initial guess\n>>> x = np.ones((n,n))\n>>> x = x.ravel()\n>>> y = np.ones(n**2)\n>>> l = np.ones(n**2)\n\\end{lstlisting}\nWe leave it to you to initialize the vector $c$, the constraint matrix $A$ (it's just the identity matrix of\nappropriate size), and to call the function \\li{laplacian} to initialize the matrix $H$.\nWe can solve and plot the tent with the following code:\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> from mpl_toolkits.mplot3d import axes3d\n>>> z = qInteriorPoint(H, c, A, L, (x,y,l), niter=10, verbose=False).reshape((n,n))\n>>> #plot the solution\n>>> dom = np.arange(n)\n>>> X, Y = np.meshgrid(dom, dom)\n>>> fig = plt.figure()\n>>> ax1 = fig.add_subplot(111, projection='3d')\n>>> ax1.plot_surface(X, Y, z,  rstride=1, cstride=1, color='r')\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nSolve the circus tent problem with the tent pole configuration given above, for grid side length $n = 15$.\nPlot your solution.\n\\end{problem}\n\n\\section*{Application: Markowitz Portfolio Optimization}\nSuppose you have a certain amount of money saved up, with no intention of consuming it any time soon.\nWhat will you do with this money? If you hide it somewhere in your living quarters or on your person,\nit will lose value over time due to inflation, not to mention you run the risk of burglary or accidental\nloss. A safer choice might be to put the money in a bank account. Here, there is less risk of losing the\nmoney, plus you may even add to your savings through interest payments from the bank. You could also\nconsider purchasing bonds from the government or stocks from various companies, which come with their own\nsets of risks and returns. Given all of these possibilities, how can you invest your money in such a way\nthat maximizes the return (i.e. the wealth that you gain over the course of the investment) while still\nexercising caution and avoiding excessive risk? Economist and Nobel laureate Harry Markowitz developed\nthe mathematical underpinnings of and answer to this question in his work on modern portfolio theory.\n\nA \\emph{portfolio} is a set of investments over a period of time. Each\ninvestment is characterized by a financial asset (such as a stock or bond) together with the proportion of\nwealth allocated to the asset. An asset is a random variable, and can be described as a sequence of values over time.\nThe variance or spread of these values is associated with the risk of the asset, and the percent change of the values\nover each time period is related to the return of the asset.\nIn the present treatment, we will assume that each asset has a positive risk, i.e.\nthere are no \\emph{riskless} assets available.\n\nStated more precisely, our portfolio consists of $n$ risky assets together with an allocation vector\n$x := (x_1,\\ldots,x_n)^T$, where $x_i$ indicates the proportion of wealth we invest in\nasset $i$. By definition, the vector $x$ must satisfy\n\\[\n\\sum_{i=1}^n x_i = 1.\n\\]\nThe $i$-th asset has an expected rate of return $\\mu_i$ and a standard deviation $\\sigma_i$.\nThe total return on our portfolio, i.e. the expected percent change in our invested wealth over the investment period,\nis given by\n\\[\n\\sum_{i=1}^n \\mu_ix_i.\n\\]\nWe define the risk of this portfolio in terms of the covariance matrix $Q$ of the $n$ assets:\n\\[\n\\sqrt{x^T Q x}.\n\\]\nThe covariance matrix $Q$ is always positive semidefinite, and captures the variance and correlations of the assets.\n\nGiven that we want our portfolio to have a prescribed return $\\mu$, there are in general many possible allocation vectors $x$\nthat make this possible. It would be wise to choose the vector minimizing the risk. We can state this as a quadratic program:\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}&x^TQx\\\\\n\\text{subject to }\\qquad &\\sum_{i=1}^n x_i = 1,\\\\\n&\\sum_{i=1}^n \\mu_ix_i = \\mu.\\\\\n\\end{align*}\nNote that we have slightly altered our objective function for convenience. Minimizing $\\frac{1}{2}x^TQx$ is equivalent\nto minimizing $\\sqrt{x^T Q x}$.\nThe solution to this problem will give the portfolio with least risk having a return $\\mu$. Because the components of $x$\nare not constrained to be nonnegative, the solution may have some negative entries. This indicates short selling those\nparticular assets. If we want to disallow short selling, we simply include nonnegativity constraints, resulting in the\nfollowing problem:\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}&x^TQx\\\\\n\\text{subject to }\\qquad &\\sum_{i=1}^n x_i = 1,\\\\\n&\\sum_{i=1}^n \\mu_ix_i = \\mu,\\\\\n&x \\geq 0.\n\\end{align*}\n\nEach return value $\\mu$ can be paired with its corresponding minimal risk $\\sigma$. If we plot these risk-return pairs on the\nrisk-return plane, we obtain a hyperbola. In general, the risk-return pair of any portfolio, optimal or not, will be found\nin the region bounded on the left by the hyperbola. The positively-sloped portion of the hyperbola is known as the\n\\emph{efficient frontier}, since the points there correspond to optimal portfolios. Portfolios with risk-return\npairs that lie to the right of the efficient frontier are inefficient portfolios, since we could either\nincrease the return while keeping the risk constant, or we could decrease the risk while keeping the return\nconstant. See Figure \\ref{fig:frontier}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{frontier.pdf}\n\\caption{Efficient frontier on the risk-return plane.}\n\\label{fig:frontier}\n\\end{figure}\n\nOne difficulty of this model is that the risk and return of each asset is in general unknown. After all, no one can predict the stock\nmarket with complete certainty. There are various ways of estimating these values given past stock prices, and we take a very straightforward\napproach. Suppose for each asset we have $k$ previous return values of the asset. That is, for asset $i$, we have the data vector\n\\[\ny^i = [y^i_1,\\,\\, \\ldots, \\,\\,y^i_k]^T.\n\\]\nWe estimate the expected rate of return for asset $i$ by simply taking the average of $y_1,\\ldots,y_k$, and we estimate the variance\nof asset $i$ by taking the variance of the data. We can estimate the covariance matrix for all assets by taking the covariance matrix of the\nvectors $y^1,\\ldots,y^n$. In this way, we obtain estimated values for $Q$ and $\\mu_i$.\n\n\\begin{problem}\nThe text file \\li{portfolio.txt} contains historical stock data for several assets (U.S. bonds, gold, S\\&P 500, etc).\nIn particular, the first column gives the years corresponding to the data, and the remaining eight columns give the historical returns\nof eight assets over the course of these years. Use this data to estimate the covariance matrix $Q$ as well as the expected rates\nof return $\\mu_i$ for each asset. Assuming that we want to guarantee an expected return of $\\mu = 1.13$ for our portfolio,\nfind the optimal portfolio both with and without short selling.\n\nSince the problem contains both equality and inequality constraints, use the QP solver in CVXOPT rather than your Interior Point method.\n\n\\end{problem} ", "meta": {"hexsha": "4d046baff578846c51c85905d8ff64ebb60a364f", "size": 23446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/InteriorPoint2/InteriorPointII.tex", "max_stars_repo_name": "m4webb/numerical_computing", "max_stars_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/InteriorPoint2/InteriorPointII.tex", "max_issues_repo_name": "m4webb/numerical_computing", "max_issues_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/InteriorPoint2/InteriorPointII.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": 44.7442748092, "max_line_length": 141, "alphanum_fraction": 0.7216156274, "num_tokens": 6681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6520830924158494}}
{"text": "\\section{Double-mode squeezing}\n\nLet\n\\begin{equation}\n\\widehat{b}_i^-\n= \\frac{\\widehat{a}_i^- - \\beta \\widehat{a}_j^+}{\\sqrt{1-\\vbr{\\beta}^2}},\\qquad\n\\widehat{b}_i^+ = \\rbr{\\widehat{b}_i^-}^\\dagger\n= \\frac{\\widehat{a}_i^+ - \\beta^*\\widehat{a}_j^-}{\\sqrt{1-\\vbr{\\beta}^2}},\n%\\label{eq:res-bogolyubov-b}\n\\end{equation}\nwhere $\\cbr{i, j} = \\cbr{1,2}$, so that\n\\begin{equation}\n\\sbr{\\widehat{b}_i^-, \\widehat{b}_j^+}_- =\n\\delta_{ij}\\widehat{1}.\n\\end{equation}\nOne seeks the state $\\Ket{\\beta}$ satisfying\n\\begin{equation}\n\\widehat{b}^-\\Ket{\\beta} = 0.\n%\\label{eq:squeezed-state-def-1}\n\\end{equation}\n\nNote that \\cref{eq:res-bogolyubov-b} is again a restricted \\emph{Bogolyubov\ntransformation}, in that the coefficients of $\\widehat{a}_i^-$ for \n$\\widehat{b}_i^-$ are real.\n\n\\subsection{Double-mode squeeze operator}\nOne attempts\n\\begin{equation}\n\\rfun{\\widehat{S}_2}{z}\\widehat{a}^-\\rfun{\\widehat{S_2}^{-1}}{z},\n\\end{equation}\nwhere\n\\begin{equation}\n\\rfun{\\widehat{S}_2}{z} \\coloneqq \\rfun{\\exp}{z \\widehat{a}_1^+ \\widehat{a}_2^+ \n- z^*\\widehat{a}_1^-\\widehat{a}_2^-}\n\\end{equation}\nis the \\emph{double-mode squeeze operator}. Note that\n\\begin{equation}\n\\rfun{\\widehat{S}_2^{-1}}{z} = \\rfun{\\widehat{S}_2}{-z}\n= \\rfun{\\widehat{S}_2^\\dagger}{z}.\n\\end{equation}\n\nThe parameterisation $z = r\\ee^{\\ii\\phi}$ will also be used, where $r = \n\\vbr{z}$, $\\phi = \\arg z$.\n\n\\begin{namedthm}{Proposition}\n\t%\\label{nthm:prop-ad-aminus}\nLet $X = z \\widehat{a}_1^+ \\widehat{a}_2^+ - z^*\\widehat{a}_1^-\\widehat{a}_2^-$. \nThen\n\\begin{align}\n\t\\ad_X^{(2n)} \\widehat{a}_i^- &= \\vbr{z}^{2n} \\widehat{a}_i^-\n\t= r^{2n} \\widehat{a}_i^-,\\\\\n\t\\ad_X^{(2n+1)} \\widehat{a}_i^-\n\t&= -\\vbr{z}^{2n+1}\\frac{z}{\\vbr{z}}\\widehat{a}_j^+\n\t= \\ee^{\\ii\\phi} r^{2n+1}\\ee^{\\ii\\phi} \\widehat{a}_j^+,\n\t\\qquad \\forall n \\ge 0.\n\\end{align}\n\\end{namedthm} % Proposition\n\n\\begin{namedthm}{Proposition}\n\\begin{align}\n\t\\rfun{\\widehat{S}_2}{z} \\widehat{a}_i^- \\rfun{\\widehat{S}_2^\\dagger}{z}\n\t&= \\widehat{a}_i^-\\cosh \\vbr{z}\n\t\t- \\widehat{a}_j^+ \\frac{z}{\\vbr{z}} \\sinh \\vbr{z}\n\t\\nonumber \\\\\n\t&= \\widehat{a}_i^-\\cosh r - \\widehat{a}_j^+ \\ee^{\\ii\\phi} \\sinh r,\n\t%\\label{eq:squeezed-aminus-parameter}\n\\end{align}\nso that $z$ or $\\rbr{r, \\phi}$ is a parameterisation of $\\beta$ in \n\\cref{eq:res-bogolyubov-b} in that\n\\begin{equation}\n\t\\vbr{\\beta} = \\tanh\\vbr{z} = \\tanh r,\\qquad \\arg \\beta = \\arg z = \\phi.\n\t%\\label{eq:beta-parameter}\n\\end{equation}\n\\end{namedthm} %Proposition\n\n\\begin{namedthm}{Squeezed ground state}\n\t$\\Ket{\\beta}$ in \\cref{eq:squeezed-state-def-1} is the $\\beta$-squeezed \nground state, namely\n\\begin{equation}\n\t\\Ket{\\beta} = \\rfun{\\widehat{S}_2}{z}\\Ket{0}.\n\\end{equation}\n\\end{namedthm} % Squeezed ground state\n\n\n\n\\subsection{Time evolution}\n\n%\\begin{namedthm}{Proposition}\n%\tLet $X = \\ii\\Omega t \\rbr{a_1^+ a_1^- + a_2^+a_2^-}$, $Y = z a_1^+ a_2^+\n%- z^* a_1^- a_2^-$.\n%\t\\begin{equation}\n%\t\t\\ad_X^{(n)}Y = z \\rbr{+2\\ii\\Omega t}^n\n%\t\t\\rbr{a^+}^2 - z^*\\rbr{-2\\ii\\Omega t}^n\\rbr{a^-}^2.\n%\t\\end{equation}\n%\\end{namedthm} % Proposition\n\n%\\begin{namedthm}{Proposition}\n%\\begin{equation}\n%\\rfun{\\mscrU}{t}\\rfun{S}{z}\t= \\rfun{S}{z\\ee^{2\\ii\\Omega t}}\\rfun{\\mscrU}{t}.\n%\\end{equation}\n%\\end{namedthm} % Proposition\n%\\begin{proof}\n%Sum up.\n%\\end{proof}\n\n\n\n\n\\subsection{Particle numbers}\n\n%\\begin{equation}\n%\t\\Braket{\\beta | \\widehat{a}^+\\widehat{a}^- | \\beta}\n%\t= \\Braket{0 | \\rfun{S^\\dagger}{z}\\widehat{a}^+\n%\t\\widehat{a}^-\\rfun{S}{z} | 0}\n%\t= \\sinh^2 r = \\frac{\\vbr{\\beta}^2}{1-\\vbr{\\beta}^2}.\n%\\end{equation}\n\n%\\begin{equation}\n%\t\\Braket{0 | \\widehat{b}^+\\widehat{b}^- | 0}\n%\t= \\Braket{0 | \\rfun{S}{z}\\widehat{a}^+\\rfun{S^\\dagger}{z}\n%\t\\rfun{S}{z}\\widehat{a}^-\\rfun{S^\\dagger}{z} | 0}\n%\t= \\sinh^2 r = \\frac{\\vbr{\\beta}^2}{1-\\vbr{\\beta}^2}.\n%\\end{equation}\n\n\\subsection{Wave function}\n\n\\begin{nameddef}{Wave function}\n\\begin{alignat}{3}\n&\\phantom{{}={}}&&\\rbr{\\frac{m\\Omega}{2}}^{-1/2}\\Braket{x_1, x_2 | \\beta} \n\\nonumber \\\\\n&=&& \\rbr{\\cosh^2 r - \\ee^{2\\ii\\phi} \\sinh^2 r}^{-1/2} \\nonumber \\\\\n&&\\cdot& \\cfun{\\exp}{-\\frac{m\\Omega}{2} \\rbr{\\frac{1 + \\ee^{2\\ii\\phi}\\tanh^2 r}%\n{1 - \\ee^{2\\ii\\phi}\\tanh^2 r} \\rbr{x_1^2+x_2^2} - \\frac{4\\ee^{\\ii\\phi}\n\\tanh r}{1 - \\ee^{2\\ii\\phi}\\tanh^2 r} x_1 x_2  }} \\nonumber \\\\\n&=&& \\rbr{\\frac{1-\\vbr{\\beta}^2}{1-\\beta^2}}^{1/2}\n\\cfun{\\exp}{-\\frac{m\\Omega}{2} \\rbr{\\frac{1+\\beta^2}{1-\\beta^2}\\rbr{x_1^2+x_2^2}\n- \\frac{4\\beta}{1-\\beta^2} x_1 x_2}}.\n\\end{alignat}\n\\end{nameddef}\n\n\\subsection{Density matrix and Wigner function}\n\nDid not find any simplification for $\\Braket{x_1, x_2 | \\widehat{\\rho} | y_1,\ny_2} \\equiv \\Braket{x_1, x_2 | \\beta} \\Braket{\\beta | y_1,y_2} $.\n\n\\begin{alignat}{3}\n&\\phantom{{}={}}&&\\rfun{W}{x_i; p_i} = \\pp^{-2}\n\\exp\\mathopen{}\\left\\{ -\\rbr{\n\\frac{x_1^2+x_2^2}{\\rbr{m\\Omega}^{-1}}+\n\\frac{p_1^2+p_2^2}{\\rbr{m\\Omega}^{+1}}}\\cosh 2r \\mathclose{}\\right.\n\\nonumber \\\\\n&&+& \\left.2\\left(\n \\rbr{\\frac{x_1 x_2}{\\rbr{m\\Omega}^{-1}}\n-\\frac{p_1 p_2}{\\rbr{m\\Omega}^{+1}}} \\cos\\phi\n-\\rbr{x_1 p_2 + x_2 p_1} \\sin\\phi\\right)\\sinh 2r\\right\\}\n\\end{alignat}\n\nAny insight?", "meta": {"hexsha": "098d70924bd0041b131cc69253ef7945d4435149", "size": 4961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/gen-coh-squ/sections/2squeeze.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/2squeeze.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/2squeeze.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": 31.3987341772, "max_line_length": 81, "alphanum_fraction": 0.6176174158, "num_tokens": 2352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825659156573, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6520641723268926}}
{"text": "% 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\\date{\\today}\n\\title{Notes from Neural Networks and Deep Learning}\n\\hypersetup{\n pdfauthor={},\n pdftitle={Notes from Neural Networks and Deep Learning},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.1.9)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\n\\section{Using neural nets to recognize handwritten digits}\n\\label{sec:org75be78e}\n\\subsection{The sigmoid function}\n\\label{sec:orgcbcab66}\nThe sigmoid function is defined as:\n\\begin{equation} \\label{eqn:sigmoid}\n\\sigma(z) = \\frac{1}{1 + e^{-z}} = \\frac{e^z}{e^z + 1}\n\\end{equation}\n\n\\subsection{The cost function}\n\\label{sec:org8ed9cda}\nThe cost function is defined as:\n\\begin{equation} \\label{eqn:cost}\nC(w,b) \\equiv \\frac{1}{2n} \\sum_{n=1} ||y(x) - a||^2\n\\end{equation}\n\nThe sum over all the training data of the square of each difference between the correct (or desired) output\nand the network's output.\n\n\\subsection{Gradient descent}\n\\label{sec:org85a25e0}\nCalculus dictates that \\(C\\) changes as follows:\n\\begin{equation} \\label{eqn:deltacost}\n\\Delta C \\approx \\frac{\\partial C}{\\partial v_1} \\Delta v_1 + \\frac{\\partial C}{\\partial v_2} \\Delta v_2\n\\end{equation}\nWe define the gradient vector as:\n\\begin{equation}\n\\nabla C \\equiv (\\frac{\\partial C}{\\partial v_1}, \\frac{\\partial C}{\\partial v_2})^T\n\\end{equation}\nAnd by defining the vector of changes to all the inputs:\n\\begin{equation}\n\\Delta v \\equiv (\\Delta v_1, \\Delta v_2)^T\n\\end{equation}\nWe can now rewrite Equation \\ref{eqn:deltacost} as:\n\\begin{equation} \\label{eqn:deltacostconcise}\n\\Delta C \\approx \\nabla C \\cdot \\Delta v\n\\end{equation}\n\nNow we can define our movement of weights and biases to be in the opposite direction of the gradient\nof the cost function. This is the concept of the ball rolling down the hill. If we define:\n\\begin{equation}\n\\Delta v = - \\eta \\nabla C\n\\end{equation}\nWhere \\(\\eta\\) is the \\emph{learning rate}, we can rewrite Equation \\ref{eqn:deltacostconcise} as:\n\\begin{equation}\n\\Delta C = - \\eta ||\\nabla C||^2\n\\end{equation}\nWe know \\(||\\nabla C||^2\\) will always be positive, and have chosen \\(\\eta\\) as a positive constant, so it \nis guaranteed that \\(\\Delta C\\) will always decrease, as desired.\n\n\\textbf{Stochastic gradient descent} is a cut down version of gradient descent, which reduces computation time by \nrandomly choosing a \\emph{mini batch} from the training data, rather than using all of it.\n\\begin{itemize}\n\\item n.b. a mini batch of size 1 is equivalent to on-line learning.\n\\end{itemize}\n\n\\subsection{Code}\n\\label{sec:org5ef75ad}\nThe code centres around the \\textbf{Network} class, with the following variables:\n\\begin{itemize}\n\\item \\textbf{num\\(_{\\text{layers}}\\)}: the number of layers the network has\n\\item \\textbf{sizes}: a list of integers, with the nth integer defining the number of nodes in the nth layer\n\\item \\textbf{biases}: the biases of the network\n\\item \\textbf{weights}: the weights of the links\n\\end{itemize}\nFor now we initialise the biases and weights to be completely random. Both biases and weights are numpy matrices, so weights[1] is a matrix storing the weights of the links between the second and third row of neurons. \n\nLooking at that particular matrix, which we will name \\(w\\), let us denote the weight of the link joining the \\(k^{\\text{th}}\\) neuron in the second layer with the \\(j^{\\text{th}}\\) neuron in the third layer: \\(w_{jk}\\). While this notation seems to have \\(j\\), and \\(k\\) around the wrong way, it allows for a very concise notation for the activations of the neurons in the 3rd layer:\n\\begin{equation} \\label{eqn:activation}\na' = \\sigma ( wa+b )\n\\end{equation}\nwhere:\n\\begin{itemize}\n\\item a is the vector of activations from the second layer of neurons\n\\item so \\(a'\\) is obtained by multiplying the previous layer's activations by the link weights, and adding the biases. Simple!\n\\end{itemize}\n\nThe \\textbf{SGD} function does a lot of the work here. Each epoch it randomly shuffles the training data, then partitions it into mini batches of the specified size. For each mini-batch, it makes one gradient descent step by using the function update\\(_{\\text{mini}}\\)\\(_{\\text{batch}}\\), updating the network's weights and biases\n\nThe \\textbf{update\\(_{\\text{mini}}\\)\\(_{\\text{batch}}\\)} function also does a lot of work, as it performs the actual update. Within this function, the \\textbf{self.backrop} function does most of the actual work, as it computes the gradient of the cost function. \\textbf{update\\(_{\\text{mini}}\\)\\(_{\\text{batch}}\\)} really works by computing the gradient for every training example in the mini-batch, and updatng self.weights and self.biases. The backprop function is detailed in the next chapter, for now, all that is necessary is an understanding of what it is doing.\n\n\\clearpage\n\n\n\\section{How the back propagation algorithm works}\n\\label{sec:org5a70fa5}\n\\subsection{Using matrices to compute the output of a neural network}\n\\label{sec:org3fe5676}\nIn chapter 1 we introduced the notation \\(w_{jk}\\) leading up to equation \\ref{eqn:activation}. We now extend this slightly, such that \\(w^l_{jk}\\) refers to the weight of the link between the \\(k^{\\text{th}}\\) neuron in the \\((l-1)^{\\text{th}}\\) layer and the \\(j^{\\text{th}}\\) neuron in the \\(l^{\\text{th}}\\) layer. Similarly for biases, \\(b^l_j\\) is the bias of the \\(j^{\\text{th}}\\) neuron in the \\(l^{\\text{th}}\\) layer.\n\nUsing these notations, the activation \\(a^l_j\\) of the \\(j^{\\text{th}}\\) neuron in the \\(l^{\\text{th}}\\) layer is given by:\n\\begin{equation} \\label{eqn:alj}\na^l_j = \\sigma ( \\sum_k w^l_{jk} a^{l-1}_k + b^l_j )\n\\end{equation}\nThe sum here is over all neurons, \\(k\\), in the \\((l-1)^{\\text{th}}\\) layer.\n\n\\vspace{0.3cm}\n\nTo utilise matrix form we define a \\textbf{weights matrix}, \\(w^l\\), for the weights connecting the neurons in the \\(l^{\\text{th}}\\) layer to those in the \\((l-1)^{\\text{th}}\\) layer. \\(w^l\\) will be defined such that the entry in the \\(j^{\\text{th}}\\) row and the \\(k^{\\text{th}}\\) column is \\(w^l_{jk}\\).\n\nSimilarly, we define a \\textbf{bias vector}, \\(b^l\\), which follows naturally as the biases for each neuron in layer \\(l\\). And finally, we define the \\textbf{activation vector}, \\(a^l\\), whose components are the activations \\(a^l_j\\).\n\nThe final step towards writing Equation \\ref{eqn:alj} in matrix form is vectorising a function, such as \\(\\sigma\\). This simply refers to performing the \\(\\sigma\\) operation elementwise.\n\n\\vspace{0.3cm}\n\nEquation \\ref{eqn:alj} can now be written as:\n\\begin{equation} \\label{eqn:almatrix}\na^l = \\sigma(w^l a^{l-1} + b^l)\n\\end{equation}\n\nWe will actually compute the intermediate quantity:\n\\begin{equation}\n  z^l = w^l a^{l-1} + b^l\n\\end{equation}\nIt turns out that this quantity will be useful enough (in time) to be worth naming. We call \\(z^l\\) the \\emph{weighted input} to the neurons in layer \\(l\\). Naturally, Equation \\ref{eqn:almatrix} can be written as:\n\\begin{equation} \na^l = \\sigma(z^l)\n\\end{equation}\n\n\n\\subsection{The two assumptions we need about the cost function}\n\\label{sec:orgc244547}\nThe goal, as discussed, of back propagation is to compute the partial derivatives \\(\\frac{\\partial C}{\\partial w}\\) and \\(\\frac{\\partial C}{\\partial b}\\) of the cost function \\(C\\) with respect to any weight or bias in the network. \n\nAs the title of this section suggests, we need to make two assumptions for back propagation to work. Before we state those assumptions, we should define a cost function. We return to the quadratic cost function defined in Equation \\ref{eqn:cost}:\n\\begin{equation*}\nC(w,b) \\(\\equiv\\) \\frac{1}{2n} \\(\\sum_{\\text{n=1}}\\) ||y(x) - a\\(^{\\text{L}}\\)(x)||\\(^{\\text{2}}\\)\n\\end{equation}\nWe have made some small notational changes, such as the superscript \\(L\\), but it means the same thing. \n\\begin{itemize}\n\\item \\(y(x)\\) is the expected (or correct) outputs of the network\n\\item \\(a^L(x)\\) is the vector of activations of the output layer\n\\end{itemize}\n\\vspace{0.3cm}\n\nOkay, on to the assumptions. \n\n\\textbf{Assumption 1} is that the cost function is an average \\(C = \\frac{1}{n} \\sum_{x} C_x\\) over cost functions \\(C_x\\), for individul training examples, \\(x\\). This is the case for the quadratic cost function, where the cost of a single training example is \\(C_x = \\frac{1}{2} ||y - a^L||^2\\). This assumtion will hold true for all cost functions to be introduced.\n\nThis assumption is important, because the backpropagation algorithm will actually calculate \\(\\frac{\\partial C_x}{\\partial w}\\) and \\(\\frac{\\partial C_x}{\\partial b}\\) for a single training example. We then get \\(\\frac{\\partial C}{\\partial w}\\) and \\(\\frac{\\partial C}{\\partial b}\\) by averaging over training examples. \n\n\\textbf{Assumption 2} is that the cost function can be written as a function of the outputs of the network. That is, for output layer activations \\(a^L\\), the cost function can be expressed as:\n\\begin{equation}\ncost C = C(a^L)\n\\end{equation}\nThis is true of the quadratic cost function, as the expected network outputs can be thought of as a fixed expression (i.e. not a variable because the weights and biases of the network do not change them), and as such it is a function only of \\(a^L\\).\n\n\n\\subsection{The Hadamard product}\n\\label{sec:org421f816}\nThe Hadamard product (\\(\\circ\\)) is like the dot product but it works for matrices of multiple dimensions rather than just vectors.\n\n\n\\subsection{The four fundamental equations behind backpropagation}\n\\label{sec:org07111f6}\nAs has been previousy discussed, backpropagation is concerned with how a change in the weights and biases of the network affects the cost function. This ultimately means calculating \\(\\frac{\\partial C}{\\partial w^l_{jk}}\\) and \\(\\frac{\\partial C}{\\partial b^l_j}\\), but first we will define an intermediate quantity, \\(\\delta^l_j\\), known as the \\emph{error} in the \\(j^{\\text{th}}\\) neuron of the \\(l^{\\text{th}}\\) layer.\n\nSuppose a demon sits at the \\(j^{\\text{th}}\\) neuron in the \\(l^{\\text{th}}\\) layer, and makes a small change \\(\\Delta z^l_j\\) to the neuron's weighted input (\\(z^l_j\\)), such that the neuron now outputs \\(\\sigma (z^l_j + \\Delta z^l_j)\\) instead of \\(\\sigma (z^l_j)\\). This change then propagates through the network, producing a final \\textbf{change} in cost of \\(\\frac{\\partial C}{\\partial z^l_j} \\Delta z^l_j\\). \n\nThe demon is our friend, however, and is trying to make a change that will minimise the cost function. Suppose \\(\\frac{\\partial C}{\\partial z^l_j}\\) has a large magnitude (positive or negative), the demon would then choose a value of \\(\\Delta z^l_j\\) that has the opposite sign of \\(\\frac{\\partial C}{\\partial z^l_j}\\). In contrast, if \\(\\frac{\\partial C}{\\partial z^l_j}\\) small in magnitude, the demon would assume the neuron is near optimal, as he cannot easily change the cost function by perturbing the weighted input. From this we can derive a heuristic sense in which \\(\\frac{\\partial C}{\\partial z^l_j}\\) is a measure of error in the neuron.\n\nMotivated by the demon's story, we will define the error of neuron \\(j\\) in layer \\(l\\) as:\n\\begin{equation}\n\\delta^l_j \\equiv \\frac{\\partial C}{\\partial z^l_j}$\n\\end{equation}\nAnd like we have done before, we will use \\(\\delta^l\\) to define the vector of errors in layer \\(l\\). Backpropagation then gives us a way of computing \\(\\delta^l\\) in each layer, and relating those vectors to \\(\\frac{\\partial C}{\\partial w^l_{jk}}\\) and \\(\\frac{\\partial C}{\\partial b^l_j}\\).\n\n\\subsubsection{Error in the output layer, \\(\\delta^L\\) \\label{orgc4d77df}}\n\\label{sec:org317e585}\nThe components of \\(\\delta^L\\) are given by:\n\\begin{equation} \\label{eqn:bp1}\n\\delta^L_j = \\frac{\\partial C}{\\partial a^L_j} \\sigma' (z^L_j)\n\\end{equation}\n\\begin{itemize}\n\\item \\(\\frac{\\partial C}{\\partial a^L_j}\\) measures how fast the cost is changing as a function of the \\(j^{\\text{th}}\\) output activation.\n\\item \\(\\sigma' (z^L_j)\\) measures how fast the activation function is changing at \\(z^L_j\\)\n\\end{itemize}\n\nTo rewrite Equation \\ref{eqn:bp1} in matrix form:\n\\begin{equation} \\label{eqn:bp1a}\n\\delta^L = \\nabla_a C \\circ \\sigma' (z^L)\n\\end{equation}\n\\begin{itemize}\n\\item \\(\\nabla_a C\\) is a vector whose components are the partials \\(\\frac{\\partial C}{\\partial a^L_j}\\)\n\\end{itemize}\n\nIn the case of the quadratic cost function, \\(C = \\frac{1}{2} \\sum_j(y_j - a_j)^2\\):\n\\begin{align*}\n\\frac{\\partial C}{\\partial a^L_j} &= 2 \\times \\frac{1}{2} \\times (y_j - a_j) \\times -1 \\\\\n&= (a_j - y_j) \\\\\n\\nabla_a C &= (a^L - y)\n\\end{align*}\nSo now we can rewrite Equation \\ref{eqn:bp1a} as:\n\\begin{equation}\n\\delta^L = (a^L - y) \\circ \\sigma' (z^L)\n\\end{equation}\n\n\\subsubsection{Error \\(\\delta^l\\) in terms of error in the next layer, \\(\\delta^{l+1}\\)}\n\\label{sec:org852e550}\n\\begin{equation} \\label{eqn:bp2}\n\\delta^l = ((w^{l+1})^T \\delta^{l+1}) \\circ \\sigma'(z^l)\n\\end{equation}\n\\begin{itemize}\n\\item \\((w^{l+1})^T\\) is the transpose of the weights matrix for the \\(l+1^{\\text{th}}\\) layer.\n\\end{itemize}\n\nSuppose we know the error \\(\\delta^{l+1}\\) at the \\(l+1^{\\text{th}}\\) layer. We can think of applying the transpose matrix to this error as moving the error backward through the network, giving us a sort of measure of the error at the \\(l^{\\text{th}}\\) layer of the network. We then take the hadamard product \\(\\circ \\sigma'(z^l)\\), which moves the error back through the activation function in layer \\(l\\), giving us the error in layer \\(l\\), \\(\\delta^l\\).\n\\vspace{0.3cm}\n\nIt follows then, that by applying Equation \\ref{eqn:bp1a} and then repeatedly applying Equation \\ref{eqn:bp2} for the remaining layers in the network, that we can compute the error for any layer in the network.\n\n\\subsubsection{The rate of change of cost with respect to any bias in the network}\n\\label{sec:orgad59eba}\n\\begin{equation} \\label{eqn:bp3}\n\\frac{\\partial C}{\\partial b^l_j} = \\delta^l_j\n\\end{equation}\nThat is, the error \\(\\delta^{\\text{l}}_{\\text{j}}\\) is \\emph{exactly} the rate of change we are after. Naturally we can write this shorthand as:\n\\begin{equation}\n\\frac{\\partial C}{\\partial b} = \\delta\n\\end{equation}\nwhere it is understood that \\(\\delta\\) is being evaluated at the same neuron as \\(b\\).\n\n\\subsubsection{The rate of change of cost with respect to any weight in the network}\n\\label{sec:org3f4cfe2}\n\\begin{equation} \\label{eqn:bp4}\n\\frac{\\partial C}{\\partial w^l_{jk}} = a^{l-1}_k \\delta^l_j\n\\end{equation}\nWe already know how to compute \\(a^{l-1}_k\\) and \\(\\delta^l_j\\), yay!\n\nWe can write Equation \\ref{eqn:bp4} in a less index-intensive way as:\n\\begin{equation}\n\\frac{\\partial C}{\\partial w} = a_{in} \\delta_{out}\n\\end{equation}\nwhere it is understood that:\n\\begin{itemize}\n\\item \\(a_{in}\\) is the activation of the neuron input to the weight \\(w\\), and \\(\\delta_{out}\\) is the error in the neuron output from the weight \\(w\\). One interesting conclusion from this result is that weights output from low activation neurons learn more slowly than those output from higher activation neurons.\n\\end{itemize}\n\n\n\\subsection{Proofs for the four fundamental equations}\n\\label{sec:orgb9ab6d3}\nThe proofs for the four fundamental equations are mostly derived from the chain rule.\n\\subsubsection{Error in the output layer}\n\\label{sec:org855fe57}\nRecall that:\n\\begin{equation*}\n\\delta^L_j = \\frac{\\partial C}{\\partial z^L_j}\n\\end{equation*}\nAs earlier discussed, the cost function is a function only of output activations \\(a^L\\), so by using the chain rule to break this down we get:\n\\begin{equation*}\n\\delta^L_j = \\frac{\\partial C}{\\partial a^L_j} \\frac{\\partial a^L_j}{\\partial z^L_j}\n\\end{equation*}\nWe can break the first partial down quite easily when using the quadratic cost function, but we have already done this in Section \\ref{orgc4d77df}. The second partial is, by definition:\n\\begin{align*}\na^l &= \\sigma(z^l) \\\\\n\\frac{\\partial a^L_j}{\\partial z^L_j} &= \\sigma'(z^l)\n\\end{align*}\nNaturally this leaves us with the desired result:\n\\begin{equation*} \n\\delta^L_j = \\frac{\\partial C}{\\partial a^L_j} \\sigma' (z^L_j)\n\\end{equation*}\n\n\\subsubsection{Error in layer \\(l\\), in terms of error in layer \\(l+1\\)}\n\\label{sec:org726fed4}\nTo formulate this equation, we want to write \\(\\delta^l_j = \\frac{\\partial C}{\\partial z^l_j}\\) in terms of \\(\\delta^{l+1}_k = \\frac{\\partial C}{\\partial z^{l+1}_k}\\). We do this using the chain rule:\n\\begin{align*}\n\\delta^l_j &= \\frac{\\partial C}{\\partial z^l_j} \\\\\n&= \\sum_k \\frac{\\partial C}{\\partial z^{l+1}_k} \\frac{\\partial z^{l+1}_k}{\\partial z^l_j} \\\\\n&= \\sum_k \\delta^{l+1}_k \\frac{\\partial z^{l+1}_k}{\\partial z^l_j} \\\\\n\\end{align*}\nNow to evaluate the remaining partial term, we use the definition that:\n\\begin{equation*}\nz^{l+1}_k = \\sum_j w^{l+1}_{kj} a^l_j + b^{l+1}_k = \\sum_j w^{l+1}_{kj} \\sigma(z^l_j) + b^{l+1}_k\n\\end{equation*}\n\n\\subsubsection{The rate of change of cost with respect to any bias in the netowrk \\label{org85b26af}}\n\\label{sec:org26126cb}\nRecalling the demon example, he was perturbing the \\textbf{weighted input} to the system. The weighted input is given by:\n\\begin{equation*}\nz^l_j = \\sum_k w^l_{jk} a^{l-1}_k + b^l_j\n\\end{equation*}\n\nWe have defined the error as:\n\\begin{equation*}\n\\delta^l_j \\equiv \\frac{\\partial C}{\\partial z^l_j}$\n\\end{equation*}\n\nNow we use partials:\n\\begin{align*}\n\\frac{\\partial C}{\\partial b^l_j} &= \\frac{\\partial C}{\\partial z^l_j} \\frac{\\partial z^l_j}{\\partial b^l_j} \\\\\n&= \\delta^l_j \\times 1\n\\end{align*}\n\nAs required.\n\n\\subsubsection{The rate of change of cost with respect to any weight in the network}\n\\label{sec:org26c7d14}\nUsing the same approach as in Section \\ref{org85b26af}, we will break down the desired product using partials.\n\\begin{align*}\n\\frac{\\partial C}{\\partial w^l_{jk}} &= \\frac{\\partial C}{\\partial z^l_j} \\frac{\\partial z^l_j}{\\partial w^l_{jk}} \\\\\n&= \\delta^l_j \\frac{\\partial z^l_j}{\\partial w^l_{jk}}\n\\end{align*}\n\nNow we break down the second partial\n\\begin{align*}\nz^l_j &= \\sum_k w^l_{jk} a^{l-1}_k + b^l_j \\\\\n\\frac{\\partial z^l_j}{\\partial w^l_{jk}} &= a^{l-1}_k\n\\end{align*}\n\nTherefore we get, as desired:\n\\begin{equation*}\n\\frac{\\partial C}{\\partial w^l_{jk}} = \\delta^l_j a^{l-1}_k\n\\end{equation*}\n\n\n\n\\subsection{The backpropagation algorithm}\n\\label{sec:org91c6ab6}\n\\subsubsection{For an individual training example}\n\\label{sec:org70fa9e6}\nNow that the equations are established, we can define an algorithm that conducts backpropagation.\n\\begin{enumerate}\n\\item \\textbf{Input} \\(x\\): get the activations of the first layer, \\(a^1\\)\n\\item \\textbf{Feedforward}: For each \\(l = 2,3,...,L\\) compute \\(z^l = w^la^{l-1} + b^l\\) and \\(a^l = \\sigma(z^l)\\)\n\\item \\textbf{Output error \\(\\delta^L\\)}: Compute the vector \\(\\delta^L = \\nabla_a C \\circ \\sigma'(z^L)\\)\n\\item \\textbf{Backpropagate the error}: For each \\(l = L-1, L-2, ... ,2\\) compute \\(\\delta^l = ((w^{l+1})^T \\delta^{l+1}) \\circ \\sigma'(z^l)\\)\n\\item \\textbf{Output}: The gradient of the cost function is given by \\(\\frac{\\partial C}{\\partial w^l_{jk}} = a^{l-1}_k \\delta^l_j\\) and \\(\\frac{\\partial C}{\\partial b^l_j} = \\delta^l_j\\)\n\\end{enumerate}\n\nIt is clear now why this is called \\emph{backpropagation}. The desired products are the partial derivatives of cost with respect to weights and biases, which we can find from the layer errors, which we find by propagating backward through the network from the output layer.\n\\vspace{0.3cm}\n\n\\subsubsection{For a mini-batch of training examples \\label{orgf844af8}}\n\\label{sec:org7a947e7}\nThe steps above outline the algorithm for a single training example, however in practice it is common to combine backpropagation with a learning algorithm such as stochastic gradient descent, in which the gradient is computed for a mini-batch of training examples at a time, and then a learning step is taken. The \\textbf{SGD} algorithm is detailed below, for a mini-batch of \\(m\\) training examples.\n\\begin{enumerate}\n\\item \\textbf{Input} a set of training examples\n\\item \\textbf{For each training example \\(x\\):} set the corresponding input activation \\(a^{x,1}\\), and perform the following steps:\n\\begin{enumerate}\n\\item \\textbf{Feedforward:} for each \\(l = 2, 3, ... , L\\) compute \\(z^{x,l} = w^l a^{x,l-1} + b^l\\) and \\(a^{x,l} = \\sigma(z^{x,l})\\)\n\\item \\textbf{Output error \\(\\delta^{\\text{x,L}}\\):} compute the vector \\(\\delta^{x,L} = \\nabla_a C_x \\circ \\sigma'(z^{x,L})\\)\n\\item \\textbf{Backpropagate the error:} for each \\(l = L-1, L-2, ... , 2\\) compute \\(\\delta^{x,l} = ((w^{l+1})^T \\delta^{x,l+1}) \\circ \\sigma'(z^{x,l})\\)\n\\end{enumerate}\n\\item \\textbf{Gradient descent:} For each \\(l = L, L-1, ... , 2\\) update the weights according to the rule \\(w^l \\rightarrow w^l - \\frac{\\eta}{m} \\sum_x \\delta^{x,l} (a^{x,l-1})^T\\), and the biases according to the rule \\(b^l \\rightarrow b^l - \\frac{\\eta}{m} \\sum_x \\delta^{x,l}\\)\n\\end{enumerate}\n\n\n\n\\subsection{Code}\n\\label{sec:orgbc98a3f}\nFollowing on from the code from the last chapter, we add the \\texttt{update\\_mini\\_batch} and \\texttt{backprop} methods. \n\nThe \\texttt{update\\_mini\\_batch} method, as its name suggests, updates the network's weights and biases for a single mini-batch of training examples, by computing the gradient for the mini-batch. The work is mostly done by calling the \\texttt{backprop} method, which computes \\(\\frac{\\partial C}{\\partial w^l_{jk}}\\) and \\(\\frac{\\partial C}{\\partial b^l_j}\\). \\textbf{Note: The algorithm exploits the useful feature of Python where a negative index in a list gives that index counting from the end of the list.}\n\n\\subsubsection{Modification to use matrix input}\n\\label{sec:org49cb826}\nTo leverage efficient linear algebra methods that are present in most programming languages, we will modify \\texttt{network.py} to apply an activation matrix whose columns are mini-batches. This script is called \\texttt{network\\_matrix.py}. It involves relativey few changes:\n\\begin{itemize}\n\\item Multiplying the weights matrix by the activations matrix automatically gives us a matrix of the correct number of rows, and \\(n\\) columns for \\(n\\) training examples\n\\item The bias vector must become a bias matrix, with \\(n\\) columns (each a copy of the bias vector) for \\(n\\) training examples.\n\\item The sigmoid function and cost derivative work without any modification as they can both be applied elementwise to both vectors and matrices\n\\item \\(\\delta^l\\) is now a matrix, but the operations still work the same way\n\\item \\textbf{The only difference outside the \\texttt{backprop\\_matrix} function is that we sum each row of nabla\\(_{\\text{b}}\\) as it is returned currently.} This could be done within the backprop\\(_{\\text{matrix}}\\) function too\n\\end{itemize}\n\n\\clearpage\n\n\n\\section{Improving the way neural networks learn}\n\\label{sec:org34ae88c}\nThis chapter introduces some new concepts that will help our networks learn faster and be more applicable to data outside our training data, as well as a better way of initialising weights in the network, and heuristics for choosing the network's hyperparameters.\n\n\\subsection{The cross-entropy cost function}\n\\label{sec:org6c949ab}\nWhen one is learning something new, being badly wrong about it tends to lead to very rapid learning. We touched on this in the last chapter, and of course we want the neurons in our network to act the same way. When they are far off producing the correct output, we would like them to rapidly correct themselves. This, however, does not always happen when using the quadratic cost function. The cost derivative, used to modify the weights and biases of a network, hinges upon the sigmoid function, which is nearly flat for a big chunk of its domain. The derivative in these areas is naturally flat, so the learning rate is slow. If the optimal weight or bias is far from the initial value, this can mean training takes a long time.\n\\vspace{0.3cm}\n\nLet us consider a very basic model network: a single neuron with multiple inputs, \\(x_1, x_2, ... x_k\\) and bias \\(b\\). The output of the neuron is still \\(a = \\sigma(z)\\), where \\(z = \\sum_j w_j x_j + b\\). We define the \\emph{cross-entropy cost function} as:\n\\begin{equation} \\label{eqn:cross-entropy-cost}\nC = - \\frac{1}{n} \\sum_x [y \\ln a + (1-y) \\ln (1-a)]\n\\end{equation} \nwhere \\(n\\) is the number of items of training data, the sum is over all training inputs, \\(x\\), and \\(y\\) is the corresponding desired output for input \\(x\\).\n\\vspace{0.3cm}\n\nIt is not immediately clear that this expression is even a valid cost function, let alone one that fixes the learning slowdown problem! Let us first discuss the former point.\n\nFirstly, this cost function is non-negative. Both of the expressions in the summed term are negative by definition, as both \\(y\\) and \\(a\\) are bound to the interval \\([0,1]\\). Paired with the negative sign at the beginning of the expression, this cost function must only give positive values.\n\nSecondly, if the neuron's actual output is close to the desired output for all training inputs, \\(x\\), then the cross-entropy cost will be close to zero. Suppose we have a training example with \\(y = 0\\) and \\(a \\approx 0\\). The first term disappears as \\(y = 0\\), and the second term does too as \\(\\ln(1) = 0\\). A similar logic holds for \\(y = 1\\) and \\(a \\approx 1\\). This does assume that the the desired putputs are 0 or 1, as is often the case in classification problems. With that said, at intermediate values of \\(y\\) (and \\(a\\)) between 0 and 1, the cross-entropy cost function is still minimised. This can be proven with calculus, or simply by plugging the cross-entropy cost function into a graphing calculator such as geogebra.\n\\vspace{0.3cm}\n\nWe will now discuss the learning slowdown problem. We substitute \\(a = \\sigma(z)\\) into Equation \\ref{eqn:cross-entropy-cost}, and apply the chain rule twice.\n\\begin{align*}\nC &= - \\frac{1}{n} \\sum_x [y \\ln \\sigma(z) + (1-y) \\ln (1-\\sigma(z))] \\\\\n\\frac{\\partial C}{\\partial w_j} &= \\frac{\\partial C}{\\partial \\sigma} \\frac{\\partial \\sigma}{\\partial w_j} \\\\\n&= \\frac{\\partial C}{\\partial \\sigma} \\frac{\\partial \\sigma}{\\partial z} \\frac{\\partial z}{\\partial w_j} \\\\ \n&= - \\frac{1}{n} \\sum_x [\\frac{y}{\\sigma(z)} + \\frac{1-y}{1-\\sigma(z)}](-1) \\sigma'(z) x_j \\\\\n\\frac{\\partial C}{\\partial w_j} &= \\frac{1}{n} \\sum_x \\frac{\\sigma'(z)x_j}{\\sigma(z)(1-\\sigma(z))} (\\sigma(z)-y)\\\\\n\\end{align*}\n\nUsing the very helpful fact that \\(\\sigma'(z) = \\sigma(z)(1-\\sigma(z))\\) (relatively easily proven using the quotient rule and Equation \\ref{eqn:sigmoid}), we can simplify this experssion to the very neat:\n\\begin{equation}\n\\frac{\\partial C}{\\partial w_j} = \\frac{1}{n} \\sum_x x_j (\\sigma(z) - y)\n\\end{equation}\n\nThis expression tells us that the cost is controlled \\textbf{only} by the error in the output, where the analogous expression for the quadratic cost function also relates to \\(\\sigma'(z)\\), which caused the learning slowdown. Yay! \n\\vspace{0.3cm}\n\nSimilarly to the expression for \\(w_j\\), the partial derivative of cost with respect to the bias is found as follows (skipping some steps, the derivation is quite simple and can easily be computed in full on paper):\n\\begin{align*}\n\\frac{\\partial C}{\\partial b} &= \\frac{\\partial C}{\\partial \\sigma} \\frac{\\partial \\sigma}{\\partial z} \\frac{\\partial z}{\\partial b} \\\\\n&= -\\frac{1}{n} \\sum_x[\\frac{\\sigma(z) - y}{\\sigma(z)(\\sigma(z)-1)}]\\sigma'(z) \\\\\n\\end{align*}\nWhich simplifies nicely down to:\n\\begin{equation} \\label{del_CEcost_bias}\n\\frac{\\partial C}{\\partial b} = \\frac{1}{n} \\(\\sum_{\\text{x}}\\) [\\(\\sigma\\)(z) - y]\n\\end{euation}\n\nIt is also worth mentioning that the learning rate (\\(\\eta\\)) can be much lower for the cross-entropy cost function than for the quadratic cost function, but this doesn't really mean much.\n\n\\subsubsection{Cross-entropy cost for a network of many neurons}\n\\label{sec:org5d73456}\nEquation \\ref{eqn:cross-entropy-cost} is relevant to a network of one neuron, but can easily be generalised for networks of many neurons. With \\(y = y_1, y_2, ... y_k\\) as the desired outputs of the system, and \\(a^L = a^L_1, a^L_2, ... , a^L_k\\) as the final layer activations (actual outputs) of the system, we define cross entropy as:\n\\begin{equation}\nC = -\\frac{1}{n} \\sum_x \\sum_j [y_j \\ln a^L_j + (1-y_j) \\ln (1-a^L_j)]\n\\end{equation}\n\nThis is the same as equation \\ref{eqn:cross-entropy-cost}, just summing over the output neurons.\n\n\\subsubsection{When should I use cross-entropy cost?}\n\\label{sec:org6c9c449}\nCross-entropy cost is better than the quadratic cost function for almost every network, so long as \\textbf{the sigmoid function is used}.\n\n\n\n\\subsection{Softmax}\n\\label{sec:org8228ed9}\nWhile we will not discuss softmax layers again until chapter 6, they are an interesting aside. A softmax layer replaces the sigmoid activation function with the so-called \\emph{softmax function}. The weighted input is still calculated the same way. According to this function, the activation \\(a^L_j\\) is given by:\n\\begin{equation}\na^L_j = \\frac{e^{z^L_j}}{\\sum_k e^{z^L_k}}\n\\end{equation}\nWhere the denominator is summed over all output neurons.\n\\vspace{0.3cm}\n\nThe point of a softmax layer is that it makes the output of the neurons form a kind of probability distribution. That is to say, their activations sum to 1. This can be verified algebraically but can also be seen intuitively.\n\\vspace{0.3cm}\n\nSoftmax layers can also be used to address the learning slowdown problem. To understand this, we define the \\emph{log-likelihood} cost function. Using the usual notation where \\(x\\) is a training input to the network and \\(y\\) is the corresponding desired output, we define the log-likelihood cost as:\n\\begin{equation} \\label{eqn:log-likelihood-cost}\nC \\equiv -\\ln a^L_y\n\\end{equation}\nNote that \\(a^L_y\\) is the output \\textbf{only from the neuron we want to fire}. Using our MNIST classification as an example, suppose we want to classify a 7, then \\(a^L_y\\) will be the activation of the 7\\(^{\\text{th}}\\) neuron. If the network is doing well and \\(a^L_7 \\approx 1\\), then the cost will be low. We need not consider the other activations in the cost function, as the softmax function already does this. If \\(a^L_7 \\approx 1\\), then by definition, all other activations will be quite low. \n\\vspace{0.3cm}\n\nNow, if we find the partial derivatives of the log-likelihood cost with respect to individual weights and biases in the network, we will find that they, like those of the cross-entropy cost function, are only related to the difference between desired output and the output layer activations.\n\\begin{align}\n\\frac{\\partial C}{\\partial b^L_j} &= a^L_j - y_j \\\\\n\\frac{\\partial C}{\\partial w^L_{jk}} &= a^{L-1}_k (a^L_j - y_j)\n\\end{align}\n\nNote that here \\(y\\) refers to the vector of output activations, where above we were using it to refer to a single output activation.\n\n\n\\subsection{Overfitting}\n\\label{sec:org0af57ba}\nOverfitting is a phenomenon where the network becomes very good at classifying the training data, but worse at generalising to test data or real world data. It is often referred to as \\emph{overtraining}, as it is caused by training for too long and/or on a dataset that is too small. In general the best way to avoid overfitting is to use as big a training dataset as possible, however this is not always pratical.\n\n\\subsubsection{Detecting overfitting}\n\\label{sec:org21a999c}\nThere are some telltale signs of overfitting that we can use to help us detect it. Given our propensity for understanding data when visualised, most of them involve plotting accuracy.\n\\begin{itemize}\n\\item \\textbf{Plotting the accuracy on the test data} - if we see a plateau of acuracy, this usually suggests the network has stopped learning. The cost on training data plotted over the same range of epochs will likely continue to decrease, a clear sign of overfitting.\n\\item \\textbf{Plotting accuracy on the training data} - Overfitting is characterised by accuracy on training data reaching (or getting very close to) 100%.\n\\item \\textbf{Plotting both of these together} - A network that has been overfitted to the training data will show a divergence in the previous two graphs when overfitting really kicks in.\n\\end{itemize}\n\n\\subsubsection{An aside on the MNIST validation data}\n\\label{sec:orgbc2289d}\nUntil now we have not used the \\texttt{validation\\_data} that the MNIST data loading function provides. The intention of this dataset is to be used to tune the network's hyper-parameters (network structure, no. of epochs, mini-batch size, etc.) without testing on the test data. That is to say, we use the validation data as test data while we tune the hyper-parameters, and only once we have finished tuning do we test on the test data. This prevents us from having a network that is biased toward the test data. \n\n\n\\subsection{Regularization}\n\\label{sec:org887a347}\nThere are ways to prevent overfitting other than just having a bigger dataset. We can always reduce the size of our network, though this reduces the power of the network as well, so we would only do this as a last resort.\n\nFortunately we can employ \\emph{regularization} techniques to help reduce the instance of overfitting. We will now intrduce \\emph{weight decay}, also known as \\emph{L2 regularization}. It works by adding a term to the cost function, called the regularization term. The regularized cross entropy is:\n\\begin{equation} \\label{eqn:regularized-cross-entropy}\nC = -\\frac{1}{n} \\sum_{xj}[y_j \\ln a^L_j + (1-y) \\ln (1-a^L_j)] + \\frac{\\lambda}{2n} \\sum_w w^2\n\\end{equation} \n\nThe regularization term here is the sum of the squares of all the weights in the network, scaled by \\(\\frac{\\lambda}{2n}\\), where \\(\\lambda > 0\\) is the \\emph{regularization parameter}, and \\(n\\) (as usual) is the number of training examples. Note here that the regularization term does not include biases. \n\nThe same thing can be done for the quadratic cost function, using exactly the same regularization term. We can use this fact to write the regularized cost function as:\n\\begin{equation}\nC = C_0 + \\frac{\\lambda}{2n} \\sum_w w^2\n\\end{equation} \\label{eqn:regularized-lazy}\nwhere $C_0$ is the original cost function.\n\\vspace{0.3cm}\n\nIntuitively, regularization makes the network prefer to learn small weights. Large weigts will only be allowed if they considerably reduce the cost function. The relative importance of the two terms in the cost function is varied with the regularization parameter, $\\lambda$. Small $\\lambda$ conveys a preference for minimised cost, and large $\\lambda$ conveys a preference for minimised weights.\n\\vspace{0.3cm}\n\nLet us now show algebraically that regularization works. As usual, we are required to compute $\\frac{\\partial C}{\\partial w}$ and $\\frac{\\partial C}{\\partial b}$ for each weight and bias in the network. We will take the partial derivatives of Equation \\ref{eqn:regularized-lazy}:\n\\begin{align*}\n\\frac{\\partial C}{\\partial w} &= \\frac{\\partial C_0}{\\partial w} + \\frac{\\lambda}{n} w \\\\ \n\\frac{\\partial C}{\\partial b} &= \\frac{\\partial C_0}{\\partial b} \n\\end{align*}\n\nWe have already computed the intermediate terms $\\frac{\\partial C_0}{\\partial w}$ and $\\frac{\\partial C_0}{\\partial b}$, so we simply add $\\frac{\\lambda}{n} w$ to the partial derivative of all the weight terms.\n\\vspace{0.3cm}\n\nThe partial derivatives with respect to the biases have not changed, so the gradient descent learning rule for biases remains: \n\\begin{equation*}\nb \\rightarrow b - \\eta \\frac{\\partial C_0}{\\partial b}\n\\end{equation*}\nand the rule for weights becomes:\n\\begin{align}\nw &\\rightarrow w - \\eta \\frac{\\partial C_0}{\\partial w} - \\frac{\\eta \\lambda}{n} w \\\\\n&= (1-\\frac{\\eta \\lambda}{n}) w - \\eta \\frac{\\partial C_0}{\\partial w} \n\\end{align} \nExactly the same as the usual rule, except we first rescale the weight by a factor $1-\\frac{\\eta \\lambda}{n}$. This rescaling is referred to as /weight decay/. It appears from the equation that this will drive the weights unstoppably toward 0, but this is not the case. If increasing the weight will reduce the cost function $C_0$ sufficiently, this term will be overpowered.\n\\vspace{0.3cm}\n\nThe learning rule for /stochastic/ gradient descent for biases remains:\n\\begin{equation*}\nb \\rightarrow b - \\frac{eta}{m} \\sum_x \\frac{\\partial C_x}{\\partial b}\n\\end{equation*}\nAnd the equivalent for weights becomes:\n\\begin{equation}\nw \\rightarrow (1 - \\frac{\\eta \\lambda}{n}) w - \\frac{\\eta}{m} \\sum_x \\frac{\\partial C_x}{\\partial w}\n\\end{equation}\nWhere:\n\\begin{itemize}\n\\item $m$ is the size of the mini-batch\n\\item $n$ is the size of the full training set\n\\item The sum is over training examples $x$ in the mini-batch\n\\end{itemize}\n\nInterestingly, regularization also helps to avoid getting stuck in local minima of the cost function.\n\n\n\\subsubsection{Why does regularization work?}\n\\label{sec:org162219a}\nThe standard explanation for this (which is well explained in the online book with diagrams) involves Ockham's Razor. Suppose we have 9 data points in a mostly linear arrangement, and are trying to deduce the model of \\(y\\) in terms of \\(x\\). We \\textbf{can} perfectly fit a 9\\(^{\\text{th}}\\) order polynomial to the data points, but it will become dominated by the \\(x^9\\) term once we move far beyond the data points. A linear model, on the other hand, will not pass through all points, but logically provides a much better prediction of the model outside the range of the data points, if we assume the original data was polluted with some kind of noise. We \"know\" this because of Ockham's Razor.\n\\vspace{0.3cm}\n\nNow let's think of this in terms of neural networks. Suppose we have a network with mostly small weights, as a regularized cost function generates. The smalless of the weights means that a few random inputs here and there (like noise) will have limited effect on the behaviour of the network. This makes it hard for the network to learn the effects of local noise in the data. It's analogous to think of this as a way of making single pieces of evidence matter less to the output of the network, while a type of evidence seen often across a network will elicit a greater response from the network.\n\n\n\\subsubsection{Why not regularize biases?}\n\\label{sec:org3d0d07d}\nWe can regularize biases in our networks, but it often has little to no effect. This is partly because large biases do not make a neuron sensetive to its inputs in the same way as large weights. Large biases also allow neurons to saturate, which is actually desirable behaviour.\n\n\n\\subsubsection{Other techniques for regularization}\n\\label{sec:orgab39453}\nWe will here discuss three other regularization techniques, though there are many, many more. \n\n\\begin{enumerate}\n\\item \\textbf{L1 regularization}\n\\label{sec:org87a6c6b}\nis similar to L2 regularization, but we add the sum of the absolute values of the weights rather than their squares.\n\\begin{equation}\nC = C_0 + \\frac{\\lambda}{n} \\sum_w |w|\n\\end{equation}\n\nWhile similar to L2 regularization, this will behave slightly differently. Let us look at the partial derivatives of the cost function now, to see if we can establish how differently it will behave.\n\\begin{equation}\n\\frac{\\partial C}{\\partial w} = \\frac{\\partial C_0}{\\partial w} + \\frac{\\lambda}{n} sgn(w)\n\\end{equation}\nWhere \\(sgn(w)\\) is the sign of w, i.e. \\(1\\) if \\(w\\) is positive, and \\(-1\\) if \\(w\\) is negative. Now we can consider the gradient descent learning rules for L1 regularization:\n\\begin{equation}\nw \\rightarrow w' - \\frac{\\eta \\lambda}{n} sgn(w) - \\eta \\frac{\\partial C_0}{\\partial w} \n\\end{equation}\nAs usual, we can replace the final term with an average over a mini-batch if we wish.\n\\vspace{0.3cm}\n\nIf we compare the gradient descent rules for L1 and L2 regularization, we see that L1 regularization drives the weights down by a constant amount, where L2 regularization drives them down by an amount proportional to the size of the weight. This means that when a particular weight is large, it will be driven down by L2 regularization faster than by L1 regularization; but if that weight is small it will be driven down by L1 regularization faster. This tends to concentrate the weight of the network in a small number of important connections.\n\nWe also must note that the derivative \\(\\frac{\\partial C}{\\partial w}\\) is not defined at \\(w = 0\\), because the function \\(|w|\\) has a sharp corner at \\(w = 0\\). This is okay though, as we can simply define \\(sgn(0) = 0\\), which will work because regularization is already trying to reduce weights, and it can't reduce a weight that is already 0.\n\n\n\\item \\textbf{Dropout}\n\\label{sec:org9a8bbb4}\nhas a very different mechanism of action to L1 and L2 regularization, in that it does not modify the cost function, but the network itself. For each mini-batch, half of the hidden neurons (selected at random) are temporarily removed. The training examples are fed through the stripped down network and then backpropagated, and the weights and biases (that have not been removed) are updated as usual. This is repeated, with a new random selection of weights and biases each time. This does mean that running the full network will result in twice the neurons activating, so we halve all weights outgoing from the hidden neurons. The mechanism by which dropout reduces overfitting is analogous to averaging the outputs from multiple networks. Actually doing that is unduly expensive, but does reduce the effect of overfitting. Empirically, dropout is very effective as a regularization tool, especially in deep neural networks. \n\n\n\\item \\textbf{Atrificially expanding the training data}\n\\label{sec:orge3b0b6b}\nis a surprisingly effective tool for reducing overfitting. We know already that larger training datasets are less prone to overfitting than smaller ones, but collecting more data is expensive. We can, however, make small changes to our training data to make it look different on a pixel-by-pixel basis, while retaining the same desired network output. The simplest way to do this is by rotating the input image slightly. This changes the locations of the black and white pixels substantially, but is still the same image.\n\\end{enumerate}\n\n\n\\subsection{Weight Initialisation \\label{org5a09953}}\n\\label{sec:org7b6359d}\nIn our work thus far we have initialised our networks' weights and biases with independent Gaussian random variables, normalised to have mean 0 and standard deviation 1. It turns out we can actually initialise our weights and biases wuite a bit better than this. Let us look at an example network to demonstrate the problem with our current initialisation. \n\\vspace{0.3cm}\n\nSuppose we have a network with 1000 input neurons, with normalised Gaussians used to initialise the weights and biases. Let us focus on the 1000 weights connecting the input neurons and the first neuron in the first hidden layer. Suppose also that we have an input where half of the input neurons are on and half are off. Now consider the weighted sum \\(z = \\sum_j w_j x_j + b\\) of inputs to our hidden neuron. Of course, 500 terms in this sum vanish, so we are left with 500 weight terms and a bias term. Therefore \\(z\\) itself is distributed as a Gaussian with mean 0 and standard deviation \\(\\sqrt{501} \\approx 22.4\\). That is, \\(z\\) has a broad gaussian distribution, and it is highly likely that \\(z\\) wil be much greater than 1 or much less than -1. This means the chance of saturating our hidden neuron is alarmingly high, and as we know a saturated neuron will learn very slowly due to small changes in weights having almost no effect.\n\\vspace{0.3cm}\n\nThis is very similar to the problem we faced earlier with saturated output neurons, which we solved by implementing a better cost function. Unfortunately, a better choice of cost function does not help at all with saturated hidden neurons. \n\\vspace{0.3cm}\n\nConsidering the cause of the excessively large standard deviation in the example above, for a network with \\(n_{in}\\) input weights, we will initialise our weights as Gaussian random variables with mean 0 and standard deviation \\(\\frac{1}{\\sqrt{n_{in}}}\\). We will still initialise our biases with mean 0 and standard deviation 1, because it really doesn't matter what biases start as. Some people initialise them all to 0. \n\n\n\\subsection{Code}\n\\label{sec:org1c4acf5}\nThe code for our updated network, \\texttt{network2.py}, is quite similar to \\texttt{network.py}. We will cover the important changes here.\n\n\\subsubsection{\\texttt{default\\_weight\\_initializer}}\n\\label{sec:org3febd75}\nThis is the function that initialises the weights as discussed in Section \\ref{org5a09953}. It is the same as the \\texttt{large\\_weight\\_initializer}, except it divides the weights by the square root of the number of connections input to that neuron (i.e. the number of neurons in the previous layer).\n\n\\subsubsection{\\texttt{CrossEntropyCost}}\n\\label{sec:org4b347fc}\nThe cost is now implemented as a class rather than a function. This is because different cost functions provide different \\(\\delta\\) functions, so each cost class (we also have \\texttt{QuadraticCost}) has two functions within it. Two important notes about this class are:\n\\begin{itemize}\n\\item \\texttt{np.nan\\_to\\_num()} ensures that we handle the log of numbers very close to 0 appropriately.\n\\item \\texttt{@staticmethod} tells the Python interpreter that the function that follows does not depend on the object in any way, and it is for this reason that both functions in the cost class do not take \\texttt{self} as the first argument.\n\\end{itemize}\n\n\\subsubsection{L2 Regularization}\n\\label{sec:org4f2c35f}\nThe change from L2 regularization is hard to detect, but it is there! In the 4\\(^{\\text{th}}\\) last line of the \\texttt{update\\_mini\\_batch} method, un updating the weights, we have the weight decay term.\n\n\n\\subsection{How to choose hyper-parameters}\n\\label{sec:org1cf1d1a}\nWithout an intuition for appropriate values for a neural network's hyper-parameters, it can be extremely difficult to just pull appropriate values out of a hat, so to speak. \n\n\\subsubsection{Broad strategy}\n\\label{sec:orgfc9ef7c}\nWhen using neural networks to attack a new problem, the first step is to achieve any non-trivial result, i.e. anything better than chance. This can be surprisingly difficult, especially when confronting a new kind of classification problem. There are some strategies we can adopt to help us overcome this, which mostly boil down to training faster so that we can try many different network hyper-parameters. Some techniques for this are covered below:\n\\vspace{0.3cm}\n\n\\textbf{Remove all training examples that aren't ones or zeros}, which will reduce our training and test sets to one fifth of their original size, which provides a training speedup by a factor of 5. \n\\vspace{0.3cm}\n\n\\textbf{Strip the network down to the simplest network that will do meaningful learning}. We may decide that by removing the hidden layer(s) or cutting down their size, our network can still learn in a meaningful way. This will be much faster, but of course this is inappropriate if we are trying to find the correct number of hidden layers or neurons for our network.\n\\vspace{0.3cm}\n\n\\textbf{Increase the frequency of monitoring}. Running \\texttt{network2.py} on a laptop (without matrix optimisation) takes about 10 seconds per epoch. This isn't a huge issue, but when doing a lot of testing it can get very tiresome. Monitoring every epoch means monitoring every 50000 images. We can monitor more frequently than every epoch, or we could also reduce the training set size to achieve a similar effect. Similarly, we could reduce the validation set size from 10000 to, say, 100. \\textbf{Note:} If we decrease the number of training examples we should proportionally decrease \\(\\lambda\\).\n\\vspace{0.3cm}\n\nIt is worth mmentioning here that it can be tempting to discard these methods, on the assumption that we will get a result sooner or later, but this is not always true, and implementing these kinds of methods can save an immense amount of time.\n\\vspace{0.3cm}\n\nWe will now discuss some specific recommendations for setting parameters of our networks, focusing on the learning rate \\(\\eta\\), the L2 regularization parameter \\(\\lambda\\), and the mini-batch size. Many of the remarks will also apply to other hyperparameters, including those of network architecture, other regularization parameters, and some hyper-parameters we are yet to meet, such as momentum co-efficient.\n\n\\subsubsection{Learning rate}\n\\label{sec:org75a3ac8}\nAs we have seen empirically so far, a value of \\(\\eta\\) too low will cause very slow learning, while a value of \\(\\eta\\) too high will cause no or very erratic learning. A process to determine a good value for \\(\\eta\\) is:\n\n\\begin{enumerate}\n\\item Estimate a threshold value for \\(\\eta\\) at which the cost on the training data immediately begins decreasing, rather than oscillating or increasing.\n\\label{sec:orga3d3786}\nThis needs not be accurate, just as an order of magnitude. We could start at \\(\\eta = 0.01\\) and then increase to 0.1 and 1 in turn until we find a value for eta at which the cost oscillates or increases. The same applies in reverse if our initial guess is too high, and the cost oscillates or increases, we should decrease it to 0.001 and 0.0001 in turn until we find a value at which the cost decreases over the first few epochs. This procedure will give us an order of magnitude estimate for the threshold value of \\(\\eta\\). \n\n\\item Suppose we landed on \\(\\eta = 0.1\\) as our threshold value.\n\\label{sec:org17cd02e}\nWe could then optionally bump up the value by 0.1 until we find the threshold at which the cost starts oscillating, let's say \\(\\eta = 0.5\\). \n\n\\item Of course, the actual value for \\(\\eta\\) should be no greater than the threshold value,\n\\label{sec:org80f678b}\nour network wouldn't learn that way. The ideal learning rate should be something like a factor of two below the threshold value, so in our case this would be \\(\\eta = 0.25\\). In the case of the MNIST dataset, this strategy led to these exact figures for the learning rate. Over 30 eopchs, \\(\\eta = 0.5\\) works perfectly well also. \\\\\n\n\\item Holup, why are we measuring this based on the cost rather than accuracy on validation data?\n\\label{sec:org9924578}\nWe will use accuracy on validation data to adjust all of the other parameters, and the choice to use cost to quantify this is really just a preference. This preference is rooted in the fact that learning rate is intended to control the step size in gradient descent, and only incidentally affects the classification accuracy of the network. The other parameters are directly intended to improve classification accuracy.\n\\end{enumerate}\n\n\\subsubsection{Use early stopping to determine the number of epochs to train for}\n\\label{sec:org958eb52}\nUsing early stopping eliminates the number of epochs parameter altogether, but necessarily introduces another parameter to determine when to stop. A common example, at least for MNIST, is the point at which no improvement is seen in 10 epochs. Even at this point, we could be missing future learning (if we are unlucky), but this helps to control the training time until the point at which we have come to know our network well. Once the other parameters are better set, we can relax this imposition to no improvement for, say, 20 epochs or even 50 epochs.\n\n\\subsubsection{Learning rate schedule}\n\\label{sec:org2e75205}\nSo far we have been holding the learning rate \\(\\eta\\) constant, but it is often desirable to vary the learning rate. Intuitively, we want a higher learning rate earlier on in our program when our weights are badly wrong, and later we want a lower learning rate to fie tune the weights, avoiding overshooting the local minima of the cost function. \\\\\n\nA common way to implement this is to use a similar idea to early stopping, hold the learning rate constant until the validation accuracy gets worse. At this pint, we decrease the learning rate by, say, a factor of two or ten. We repeat this until our learning rate is a factor of 1024 or 1000 below its original value, then we terminate.\\\\\n\nThis can lead to a world of headaches, so it is usually best to start with a fixed learning rate while we get to know our network, then implement a learning rate schedule. \n\n\\subsubsection{The regularization parameter}\n\\label{sec:org63f9a94}\nIt is best to start with \\(\\lambda = 0\\) and find a good value for \\(\\eta\\) first. Once this is done, start at \\(\\lambda = 1.0\\) (which is a completely arbitrary choice btw) and increase or decrease by factors of 10 as required to improve performance on validation data. Once the order of magnitude is found, \\(\\lambda\\) can be fine tuned. Once that is done, return to \\(\\eta\\) and make any necessary adjustments. \n\n\\subsubsection{Mini-batch size}\n\\label{sec:org7c35b98}\nTo answer the question of how to set mini-batch size, consider online learning (i.e. mini-batch size 1). A concern about online learning is that it will provide an inaccurate estimate of the gradient of the cost function. In reality this isn't all that important, so long as our gradient estimate still tends to decrease the cost. The positive aspect of online learning is that we are constantly updating our weights, so each new estimate is based on the previous, slightly improved one. \\\\\n\nThe optimal solution is, unsurprisingly, somewhere between online learning and learning with enormous mini-batches. A mini-batch size too small doesn't make good use of optimised matrix algebra libraries that speed up the backpropagation process, and one too big doesn't stop to learn often enough. Fortunately, mini-batch size is independent of other network hyper-parameters (except network architecture), so once acceptable values for the oher hyper-parameters have been found, a little bit of trial and error can be employed to optimise the mini-batch size.\n\n\n\\subsection{Other techniques}\n\\label{sec:orgbf8043e}\n\\subsubsection{Variations on stochastic gradient descent}\n\\label{sec:orgafddd6e}\n\\begin{enumerate}\n\\item \\textbf{The Hessian Technique:}\n\\label{sec:orgd25996b}\nIf we imagine our cost function as a function of the weights of the system (which it is), so \\(C = C(w)\\) for \\(w = w_1, w_2, ... ,w_n\\), we can approximate the cost function near a point using a Taylor approximation:\n\\begin{equation}\nC(w + \\Delta w) = C(w) + \\sum_j \\frac{\\partial C}{\\partial w_j} \\Delta w_j + \\frac{1}{2} \\sum_{jk} \\Delta w_j \\frac{\\partial^2 C}{\\partial w_j \\partial w_k} \\Delta w_k + ...\n\\end{equation}\n\nDiscarding any higher order terms, this can be written more compactly as:\n\\begin{equation} \\label{eqn:compact-hessian}\nC(w + \\Delta w) = C(w) + \\nabla C \\dot \\Delta w + \\frac{1}{2} \\Delta w^T H \\Delta w \n\\end{equation}\n\nWhere \\(\\nabla C\\) is the usual gradient vector, and \\(H\\) is a atrix known as the \\emph{Hessian matrix}, whose \\textit{jk}\\(^{\\text{th}}\\) entry is \\(\\frac{\\partial^2 C}{\\partial w_j \\partial w_k}\\). We can use calculus to show that the expression can be minimised by choosing \n\\begin{equation}\n\\Delta w = -H^{-1} \\nabla C\n\\end{equation}\nProviding that Equation \\ref{eqn:compact-hessian} is a good approximate expression for the cost function, we would expect that moving from point \\(w\\) to \\(w + \\Delta w = w - H^{-1} \\nabla C\\) should significantly reduce the cost function. This suggests we can so something very similar to gradient descent, starting with random weights \\(w\\), then updating the weights:\n\\begin{equation}\nw' = w - \\eta H^{-1} \\nabla C\n\\end{equation}\nWhere \\(\\eta\\) is the learning rate. \\\\\n\nThere are theoretical and empirical results showing that this hessian technique converges in fewer steps than standard gradient descent, which is largely a result of incorporating second order changes in the cost function. So why aren't we using it? Despite its qualities, it is \\textbf{very difficult to apply in practice}, partly due to the sheer size of the Hessian matrix. A neural network with 10\\(^{\\text{7}}\\) weights and biases will have a corresponding Hessian matrix with 10\\(^{\\text{14}}\\) entries! There are, however, variations on gradient descent inspired by the Hessian technique, which avoid the problem of overly large matrices. One example is momentum-based gradient descent.\n\n\\item \\textbf{Momentum-based gradient descent:}\n\\label{sec:orge676e1f}\nThinking back to the notion of the ball rolling down the hill, it was important to be aware that gradient descent didn't behave exactly like a ball rolling down a hill. If we stick with this analogy, the advantage of the Hessian technique is its ability to capture the velocity of the ball, not just its position on the hill. Momentum- based gradient descent emulates this by adding an element of velocity to the parameters we're trying to optimise, as well as an element of friction, giving the ball a kind of momentum. The gradient acts to change the velocity, not (directly) the position, and the friction gradually reduces the velocity. \\\\\n\nFor a more precise definition, we introduce the variables \\(v = v_1, v_2, ... , v_n\\), one for each \\(w_j\\) variable. then we replace the gradient descent update rule \\(w \\rightarrow w' = w - \\eta \\nabla C\\) with: \n\\begin{align}\nv \\rightarrow v' &= \\mu v - \\eta \\nabla C \\\\\nw \\rightarrow w' &= w + v' \n\\end{align}\nWhere \\(\\mu\\) is a hyper-parameter which controls the amount of damping, or friction, in the system. \\\\\n\nTo build up an understanding of how this works, imagine the case where \\(\\mu = 1\\), which corresponds to no friction. The \"force\" term \\(\\nabla C\\) is modifying the velocities, and the velocities are controlling the rate of change of the weights. We build up the velocity by repeatedly adding gradient terms to it, which means if the gradient is roughly the same through several rounds of learning, we could build up quite a considerable velocity. \\\\\n\nThis enables us the momentum technique to work considerably faster than vanilla gradient descent, but what happens when we get to the bottom? With all that velocity we could easily overshoot. With \\(\\mu = 0\\) (maximum friction), the equations reduce to vanilla gradient descent. In practice, a value between 1 and 0 will have the optimal behaviour of building velocity while minimising overshoot. \\\\\n\nThe name, incidentally, of the hyper-parameter \\(\\mu\\), is the poorly chosen \\emph{momentum coefficient}. Poorly chosen because it much more closel affects friction than momentum, but that's the name.\n\\end{enumerate}\n\\subsubsection{Other models of artificial neuron}\n\\label{sec:org2a2ad72}\nIn principle, a network built from sigmoid neurons can compute any function. In practice, however, networks built from different neurons can outperform sigmoid neuron networks. Let us look at some other neuron models in use today.\n\n\\begin{enumerate}\n\\item \\textbf{tanh neuron:}\n\\label{sec:org4b99878}\nThe tanh neuron (pronounced \"tanch\") replaces the sigmoid function with the hyperbolic tangent function. It still takes in the same input, \\(wx + b\\), and looks very similar to the sigmoid function both graphically and algebraically. The tanh function is defined as:\n\\begin{equation}\n\\tanh(z) \\equiv \\frac{e^z - e^{-z}}{e^z + e^{-z}}\n\\end{equation}\nThe tanh function is shaped very similarly to the sigmoid function, with the main difference being that its range is \\([-1,1]\\) rather than \\([0,1]\\). This means that the outputs of (and potentially inputs to) the system may have to be normalised differently to those with sigmoid neurons. \\\\\n\n\\item \\textbf{Rectified linear neuron:}\n\\label{sec:orgdd5b432}\nThe output of a rectified linear neuron is given by:\n\\begin{equation}\n\\max(0, w x + b)\n\\end{equation} \nPlotting the activation \\(a\\) of a rectified linear neuron as a function of \\(Z\\), it looks like the function \\(a = Z\\), but only in the domain \\([0,\\infty)\\), and is not defined in the domain \\((-\\infty,0)\\). \\\\\n\nClearly this is quite different to the sigmoid and tanh activation functions, but it can still be used to compute any function, and can still be trained using backpropagation and gradient descent. The primary advantage of the rectified linear neuron is that it doesn't saturate, but at the same time, any negative input to a rectified linear neuron won't induce any learning at all. \\\\\n\nBoth tanh neurons and rectified linear neurons suffer from a lack of research into the most appropriate circumstances in which to use them, and the same goes for all types of neuron. Generally speaking, sigmoid neurons will perform just fine, but it is worth knowing about the different alternatives that exist for developing our networks with.\n\\end{enumerate}\n\n\n\\section{A visual proof that neural nets can compute any functon}\n\\label{sec:org16ddd46}\nSee the online book, this is all very straightforward. The takeaway is that a network with a single hidden layer can compute any continuous function to an arbitrary degree of accuracy.\n\\clearpage\n\n\n\\section{Why are deep neural networks hard to train?}\n\\label{sec:org6dd5478}\nThere is an intuitive sense in which deep networks should be able to learn better than shallow ones. The first layer can detect basic patterns, like edges and corners and such, with the second detecting compounds of these patterns and so on. Along with this are theoretical results showing that deep neural networks are intrinsically more powerful than shallow ones. Unfortunately, there are often situations where our network won't train as effectively as we hope, manifesting particularly in different layers training at different speeds. This is often due to our gradient based learning techniques.\n\n\\subsection{The vanishing gradient problem}\n\\label{sec:orgedca5ba}\nThe vanishing gradient problem is the phenomenon where the last layer in a network trains the fastest, and the first layer in the network trains the slowest, with intermediate layers following in a linear fashion. The gradient tends to get smaller as we move backward through the hidden layers, which causes this learning slowdown. \n\n\\subsection{The cause of the vanishing gradient problem}\n\\label{sec:org44aa619}\nConsider a network with only one neuron in each layer, and three hidden layers. Using our regular nomenclature, we denote the weight of the link between the input neuron and the first hidden neuron \\(w_1\\), with its bias \\(b_1\\), and so on throughout the network. We will study the gradient \\(\\frac{\\partial C}{\\partial b_1}\\) associated with the first hidden neuron. \\\\\n\nSuppose we make a small change \\(\\Delta b_1\\) in the bias \\(b_1\\). That will trigger a cascade of changes in the rest of the network:\n\\begin{itemize}\n\\item First it will cause a change \\(\\Delta a_1\\) in the activation of the first hidden neuron\n\\item Then it will cause a change \\(\\Delta z_2\\) in the weighted input to the second hidden neuron\n\\item This will cause a change \\(\\Delta a_2\\) in the activation of the second hidden neuron\n\\item etc.\n\\item Finally, this will cause a change \\(\\Delta C\\) in the cost at the output.\n\\end{itemize}\nWe can say:\n\\begin{equation} \\label{eqn:partial_approx_delta}\n\\frac{\\partial C}{\\partial b_1} \\approx \\frac{\\Delta C}{\\Delta b_1}\n\\end{equation} \n\nWhich suggests that we can find an expression for \\(\\frac{\\partial C}{\\partial b_1}\\) by carefully tracking the effect of each step in this cascade. Let us start by considering the first of the above dot points. We have \\(a_1 = \\sigma(z_1) = \\sigma(w_1 a_0 + b_1)\\), so\n\\begin{align}\n\\Delta a_1 &\\approx \\frac{\\partial \\sigma(w_1 a_0 + b_1)}{\\partial b_1} \\Delta b_1 \\\\\n&= \\sigma'(z_1) \\Delta b_1\n\\end{align}\n\nThis change \\(\\Delta a_1\\) then causes a change in the weighted input \\(z_2 = w_2 a_1 + b_2\\) to the second hidden neuron:\n\\begin{align}\n\\Delta z_2 &\\approx \\frac{\\partial z_2}{\\partial a_1} \\Delta a_1 \\\\\n&= w_2 \\Delta a_1\n\\end{align}\n\nCombining the terms from the above two expressions, the change \\(\\Delta b_1\\) in \\(b_1\\) causes \\(z_2\\) to change as:\n\\begin{equation}\n\\Delta z_2 \\approx \\sigma'(z_1) w_2 \\Delta b_1\n\\end{equation} \n\nWe can continue in this fashion, tracking the way changes propagate through the network. At each neuron we pick up a \\(\\sigma'(z_j)\\) term, and through each weight we pick up a \\(w_j\\) term. We also have the term \\(\\frac{\\partial C}{\\partial a_4}\\) relating the cost to the final neuron's activation at the end of the expression, because the cost is a function of the final activation. This leaves us with:\n\\begin{equation}\n\\Delta C \\approx \\sigma'(z_1) w_2 \\sigma'(z_2) w_3 \\sigma'(z_3) w_4 \\sigma'(z_4) \\frac{\\partial C}{\\partial a_4} \\Delta b_1\n\\end{equation}\nDividing by \\(\\Delta b_1\\) and invoking Equation \\ref{eqn:partial_approx_delta}, we get:\n\\begin{equation} \\label{eqn:cost_wrt_b1}\n\\frac{\\partial C}{\\partial b_1} = \\sigma'(z_1) w_2 \\sigma'(z_2) w_3 \\sigma'(z_3) w_4 \\sigma'(z_4) \\frac{\\partial C}{\\partial a_4}\n\\end{equation}\n\n\n\\subsubsection{Why the vanishing gradient problem occurs}\n\\label{sec:org97ad96f}\nWith the exception of the final term, Equation \\ref{eqn:cost_wrt_b1} is a product of the terms \\(w_j \\sigma'(z_j)\\). Looking at this term's components: \n\\begin{itemize}\n\\item \\(\\sigma'(z)\\) is a normal (ish) distribution, which reaches a maximum at \\(z = 0\\) of \\(\\sigma'(0) = \\frac{1}{4}\\).\n\\item With our new way of initialising weights and biases, weights are initialised as gaussian variables with mean 0 and standard deviation 1, so the weights will usually satisfy \\(|w| < 1\\)\n\\end{itemize}\nCombining these two observations, it is clear that \\(w_j \\sigma'(z_j)\\) will usually satisfy \\(|w_j \\sigma'(z_j)| < \\frac{1}{4}\\). When we take the product of many such terms, the product will tend to exponentially decrease. \\\\\n\nFor comparison, we will consider the equivalent of Equation \\ref{eqn:cost_wrt_b1} for \\(b_3\\). We haven't explicitly calculated this expression, but we can just remove terms from \\Equation \\ref{eqn:cost_wrt_b1}.\n\\begin{equation} \\label{eqn:cost_wrt_b3}\n\\frac{\\partial C}{\\partial b_3} = \\sigma'(z_3) w_4 \\sigma'(z_4) \\frac{\\partial C}{\\partial a_4}\n\\end{equation}\nThese two equations are very similar, but \\Equation \\ref{eqn:cost_wrt_b3} has two fewer terms of the form \\(w_j \\sigma'(z_j)\\), and so the gradient \\(\\frac{\\partial C}{\\partial b_1}\\) will be a factor of 16 (or more) smaller than \\(\\frac{\\partial C}{\\partial b_3}\\). \\textbf{This is essentially the origin of the vanishing gradient problem.} \\\\\n\nThis whole argument hingeson the fact that \\(|w_j \\sigma'(z_j)| < \\frac{1}{4}\\), but if the weights grow during training (or are differently initialised), to the point that \\(|w_j \\sigma'(z_j)| > 1\\), then we will no longer have a vanishing gradient, rather the gradient will exlplode! This is called, of course, the \\emph{exploding gradient problem}.\n\n\n\\section{Deep learning}\n\\label{sec:org0cfdf86}\n\\subsection{Introducing convolutional networks}\n\\label{sec:org72a8644}\nIn our earlier networks, every neuron in layer \\(n\\) is connected to every neuron in layer \\(n+1\\) and every neuron in layer \\(n-1\\). At the input layer, this architecture treats pixels that are far apart the same as it treats adjacent pixels. In reality, it is much more likely that the relationship between adjacent pixels is more important than that of pixels on opposite ends of the image, when we are trying to classify images. Convolutional neural networks use a special architecture which is much better adapted to classifying images, and as such is the most common form of network used in image recognition. \\\\\n\nConvolutional neural networks use three basic ideas: \\emph{local receptive fields}, \\emph{shared weights}, and \\emph{pooling}.\n\n\\subsubsection{Local receptive fields}\n\\label{sec:orge998e1b}\nPreviously we have visualised the input neurons in a straight vertical line, but let us now view them as a \\(28 \\times 28\\) grid. Rather than each neuron in the first hidden layer being connected to all of the input neurons, we will connect a small region, say a \\(5 \\times 5\\) square in the top left corner, corresponding to 25 input neurons, to the first neuron in the first hidden layer. This region is called the \\emph{local receptive field}, and we slide it one neuron across and connect all of the input neurons in our new region to the second neuron in the first hidden layer, and so on sliding across until we reach the other side of the image, then jump one input neuron down and repeat, until we have connected all local receptive fields to a neuron in the second hidden layer. This exact architecture (\\(5 \\times 5\\) region jumping one neuron at a time) will lead to a hidden layer of size \\(24 \\times 24\\) The size of the region and the number of neurons to jump by can both be varied if desired.\n\n\\subsubsection{Shared weights and biases}\n\\label{sec:orgd54da36}\nNaturally, each of the \\(24 \\times 24\\) neurons in the first hidden layer will have a bias and a \\(5 \\times 5\\) array of weights connecting to it. Unlike previous networks, however, we are going to use \\textbf{the same} bias and array of weights for each neuron in the first hidden layer. This means that for the \\(j,k^{\\text{th}}\\) hidden neuron, the output is:\n\\begin{equation} \\label{eqn:convolution}\n\\(\\sigma\\)(b + \\(\\sum_{\\text{l=0}}^{\\text{4}}\\) \\(\\sum_{\\text{m=0}}^{\\text{4}}\\) w\\(_{\\text{l,m}}\\) a\\(_{\\text{j+l,k+m}}\\))\n\\end{equation}\n\nThis means that all the neurons in the first hidden layer detect exactly the same feature, just at different locations across the image. For this reason, we somtimes call the map from the input layer to the hidden layer a \\emph{feature map}. We call the weights defining the feature map the \\emph{shared weights}, and the bias defining the feature map the \\emph{shared bias}. The shared weights and bias are often said to define a kernel, or filter. \\\\\n\nOur hidden layer detects a feature in the image, but we will often want to detect many features, so most convolutional networks will have many hidden layers in paralel, all connected to the input layer. Because of the shared weights and biases, we have only 26 parameters per feature map, so having many in paralel isn't a big problem at all. By comparison, our original network has \\(784 \\times 30\\) weights and 30 biases, a total of 23550 parameters! Of course the direct comparison of both networks isn't really valid, but it's good for framing the difference mentally. \\\\\n\nThe name \\emph{convolutional} comes from the fact that Equation \\ref{eqn:convolution} is sometimes known as a convolution. More concisely, people sometimes write that operation as \\(a^1 = \\sigma(b + w * a^0)\\), where \\(a^1\\) denotes the set of output activations from a feature map, \\(a^0\\) is the set of input activations, and \\(*\\) is called the convolution operation.\n\n\\subsubsection{Pooling layers}\n\\label{sec:org0b4b06c}\nIn addition to the convolutional layers, convolutional networks contain \\emph{pooling layers}, which are usually used immediately after convolutional layers. They exist to simplify the information in the output of the convolutional layer by condensing a region (say, \\(2 \\times 2\\)) into a single neuron. \\\\\n\nOne common procedure for pooling is known as \\emph{max-pooling}, where the pooling unit simply outputs the maximum activation in the \\(2 \\times 2\\) input region. We apply \\emph{max-pooling} to each feature map separately, so there is a max-pooling layer for each one. We can think of it of a way of asking our network if there is a feature in the rough region, throwing away exact positional information but drastically cutting the number of parameters needed in later layers. \\\\\n\nMax pooling isn't the only technique for pooling. Another common approach used is called \\emph{L2 pooling}, where we take the square root of the sum of the squares of the activations in the \\(2 \\times 2\\) region.\n\n\\subsubsection{Putting it all together}\n\\label{sec:orgf4321ae}\nWe can now complete the construction of our convolutional neural network. We add to the end of our existing structure 10 output neurons, corresponding to the 10 possible values of a MNIST digit. \n\\subsection{Convolutional networks in practice}\n\\label{sec:org8888709}\nWe will now be itroducing \\texttt{network3.py}, which we will use to build a convolutional neural network. Our earlier programs constructed neural networks from first principles, but this time we will use a library known as \\texttt{Theano}. \\texttt{Theano} makes it easy to implement backpropagation for convolutional neural networks, as it automatically computes all of the mappings involved, and does so quite a bit faster than our easy to read code. It also allows us to use a GPU, if one is available. \n\\end{document}\n", "meta": {"hexsha": "ba2a1fbc4c78dfe51536cf2c78968b4567551ec0", "size": 72584, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes.tex", "max_stars_repo_name": "hacmorgan/neural-networks", "max_stars_repo_head_hexsha": "3872969d208d958731f699f8a2c1b3a207036f0b", "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.tex", "max_issues_repo_name": "hacmorgan/neural-networks", "max_issues_repo_head_hexsha": "3872969d208d958731f699f8a2c1b3a207036f0b", "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.tex", "max_forks_repo_name": "hacmorgan/neural-networks", "max_forks_repo_head_hexsha": "3872969d208d958731f699f8a2c1b3a207036f0b", "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": 79.2401746725, "max_line_length": 1008, "alphanum_fraction": 0.7495729086, "num_tokens": 19669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6520441461629864}}
{"text": "\\documentclass{article}\r\n\\usepackage[top=1.0in,bottom=1.0in,left=1.0in,right=1.0in]{geometry}\r\n\\usepackage{amsmath,amssymb,amsthm,amsfonts}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{hyperref}\r\n\r\n\\newtheorem{definition}{Definition}[section]\r\n\\newtheorem{theorem}{Theorem}[section]\r\n\\newtheorem{lemma}[theorem]{Lemma}\r\n\\newtheorem*{remark}{Remark}\r\n\r\n\\title{Non-negligible Functions and Reduction Proofs}\r\n\\author{coinstudent2048}\r\n\\date{\\today}\r\n\r\n\\begin{document}\r\n\r\n\\maketitle\r\n\r\n\\begin{abstract}\r\nWe present a lemma about non-negligible functions that is helpful in reduction proofs in cryptography. We also provide a reduction proof as a demonstration.\r\n\\end{abstract}\r\n\r\n\\section{The Thing}\r\nLet $\\mathbb{R}_{\\ge 0}$ be the set of non-negative real numbers. Let us define the concept of \\textit{negligible function} first:\r\n\r\n\\begin{definition}\\label{negl}\r\nA function $f:\\mathbb{N}\\rightarrow\\mathbb{R}_{\\ge 0}$ is \\textbf{\\em negligible} if for all polynomial $p(\\cdot)$ there exists an $N\\in\\mathbb{N}$ such that for all integers $n>N$ it holds that $f(n)<\\frac{1}{p(n)}$.\r\n\\end{definition}\r\n\\noindent Definition \\ref{negl} is from Katz \\& Lindell \\cite{katz-lindell}. We now prove the following lemma:\r\n\r\n\\begin{lemma}\\label{non-negl-exp}\r\nIf $f:\\mathbb{N}\\rightarrow\\mathbb{R}_{\\ge 0}$ is non-negligible, then $g(\\cdot)=f(\\cdot)^m$ for any $m\\in\\mathbb{N}$ and $m>1$ is non-negligible.\r\n\\end{lemma}\r\n\\begin{proof}\r\nThe function $f$ being not negligible means that there exists a polynomial $p(\\cdot)$ such that for all $N\\in\\mathbb{N}$, there exists an $n>N$ such that $f(n)\\ge\\frac{1}{p(n)}$. Let $p_f(\\cdot)$ be such polynomial and $n_f$ be such $n>N$. Then setting $p_g(\\cdot)=p_f(\\cdot)^m$ and $n_g=n_f$ suffices for non-negligibility of $g$ because $f(n_f)\\ge\\frac{1}{p_f(n_f)}\\implies f(n_f)^m\\ge\\frac{1}{p_f(n_f)^m}$.\r\n\\end{proof}\r\n\\noindent Lemma \\ref{non-negl-exp} justifies the usage of finite number of ``breaks'' of one hardness assumption in reduction proofs. For a start, the probability of breaking the hardness assumption $\\textsf{HA}$ is a function of the security parameter $\\lambda$. Just here we denote this as $\\textsf{Pr}[\\textsf{HA}(\\lambda)]$. Hence, for $m>1$, the probability for breaking $\\textsf{HA}$ $m$ times, $\\textsf{Pr}[\\wedge_{i=1}^{m}{\\textsf{HA}_i(\\lambda)}]\\ge\\textsf{Pr}[\\textsf{HA}(\\lambda)]^m$. Now Lemma \\ref{non-negl-exp} says that if $\\textsf{Pr}[\\textsf{HA}(\\lambda)]$ is non-negligible (or equivalently, for all negligible function $\\textsf{negl}(\\lambda)$, $\\textsf{Pr}[\\textsf{HA}(\\lambda)]\\ge\\textsf{negl}(\\lambda)$), then $\\textsf{Pr}[\\textsf{HA}(\\lambda)]^m$ must also be non-negligible and hence $\\textsf{Pr}[\\wedge_{i=1}^{m}{\\textsf{HA}_i(\\lambda)}]$ is also non-negligible.\r\n\r\n\\section{The Demo}\r\nLet $\\mathbb{G}$ be a cyclic group where the Discrete Logarithm (DL) assumption holds, and $\\mathbb{F}$ be its scalar field. We now present a hardness assumption used in Bulletproofs \\cite{bp}, Bulletproofs+ \\cite{bp-plus}, and Halo \\cite{halo}:\r\n\r\n\\begin{definition}[Discrete Logarithm Relation Assumption]\r\n\tDL Relation assumption holds relative to $\\emph{\\textsf{Setup}}$ if for all $n \\ge 2$ and  $\\emph{\\textsf{PPT}}$ adversary $\\mathcal{A}$, there exists a negligible function $\\emph{\\textsf{negl}}(\\lambda)$ such that\r\n\t\\begin{align*}\r\n\t\t\\emph{\\textsf{Pr}}\\left[\r\n\t\t\\begin{array}{c|c}\r\n\t\t\t\\begin{gathered}\r\n\t\t\t\t\\exists i \\in \\{1, \\ldots, n\\}: x_i \\ne 0 \\\\\r\n\t\t\t\t\\wedge \\sum_{i=1}^{n} x_i G_i = 0\r\n\t\t\t\\end{gathered}\r\n\t\t\t&\r\n\t\t\t\\begin{gathered}\r\n\t\t\t\t(\\mathbb{G}, \\mathbb{F})\\leftarrow\\emph{\\textsf{Setup}}(1^{\\lambda}); \\\\\r\n\t\t\t\t\\{G_i\\}_{i=1}^n \\xleftarrow{\\$}\\mathbb{G}^n; \\\\\r\n\t\t\t\t\\{x_i\\}_{i=1}^n \\leftarrow\\mathcal{A}(\\mathbb{G}, \\mathbb{F}, \\{G_i\\}_{i=1}^n) \\\\\r\n\t\t\t\\end{gathered}\r\n\t\t\\end{array}\r\n\t\t\\right]\r\n\t\t\\le \\emph{\\textsf{negl}}(\\lambda).\r\n\t\\end{align*}\r\n\\end{definition}\r\n\\noindent Note that the $\\sum_i x_i G_i$ operation is also called \\textit{multi-scalar multiplication}.\r\n\r\n\\begin{theorem}\\label{equiv-demo}\r\nDL relation assumption holds if and only if DL assumption holds.\r\n\\end{theorem}\r\n\\begin{proof}\r\nThe forward direction is trivial. For the backward direction, we prove by induction on $n$:\r\n\r\n\\textit{Base case ($n=2$)}: Assume that $\\mathcal{A}$ breaks DL relation: with non-negligible probability, for $G_1, G_2 \\xleftarrow{\\$} \\mathbb{G}$, $\\mathcal{A}$ outputs $x_1, x_2 \\in \\mathbb{F}$ such that $x_1 G_1 + x_2 G_2 = 0$. Then $G_1 = (-x_2 / x_1) G_2$, breaks DL assumption.\r\n\r\n\\textit{Inductive case}: Assume that the backward direction of Theorem \\ref{equiv-demo} holds for case $n$. Then we prove the same for case $n+1$. Assume that $\\mathcal{A}$ breaks DL relation for case $n+1$. By Lemma \\ref{non-negl-exp}, $\\mathcal{A}$ can break it \\textit{twice}: with non-negligible probability, for $\\{G_i\\}_{i=1}^{n+1} \\xleftarrow{\\$} \\mathbb{G}^{n+1}$, $\\mathcal{A}$ outputs $\\{x_i\\}_{i=1}^{n+1}$ \\textit{and} $\\{x'_i\\}_{i=1}^{n+1}$ such that both satisfy the multi-scalar multiplication with $\\{G_i\\}_{i=1}^{n+1}$ to zero. Now observe that\r\n\\begin{align*}\r\nx'_1 \\sum_{i=1}^{n+1} x_i G_i = x'_1 \\cdot 0 = 0\\ \\wedge\\ x_1 \\sum_{i=1}^{n+1} x'_i G_i = x_1 \\cdot 0 = 0 \\\\\r\n\\implies \\sum_{i=1}^{n+1} x'_1 x_i G_i - \\sum_{i=1}^{n+1} x_1 x'_i G_i = 0 - 0 = 0 \\\\\r\n\\implies \\sum_{n=1}^{n+1} (x'_1 x_i - x_1 x'_i) G_i = 0 \\\\\r\n\\implies  \\sum_{n=2}^{n+1} (x'_1 x_i - x_1 x'_i) G_i = 0\r\n\\end{align*}\r\nwith the last implication because $x'_1 x_1 - x_1 x'_1 = 0$. Now the last implication has only $n$ addends, hence this breaks DL relation assumption for case $n$. From the above assumption of the backward direction of Theorem \\ref{equiv-demo} holding for case $n$, this must also break DL assumption.\r\n\\end{proof}\r\n\\bibliographystyle{plain}\r\n\\bibliography{non-negl}\r\n\\end{document}", "meta": {"hexsha": "d603356fa15dff2cc30a81681553dd10c358aa3f", "size": 5752, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "non-negl.tex", "max_stars_repo_name": "coinstudent2048/writeups", "max_stars_repo_head_hexsha": "56ab74f04a03984c0281a423f3b068a1460fd325", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-09-24T23:41:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T11:18:14.000Z", "max_issues_repo_path": "non-negl.tex", "max_issues_repo_name": "coinstudent2048/writeups", "max_issues_repo_head_hexsha": "56ab74f04a03984c0281a423f3b068a1460fd325", "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": "non-negl.tex", "max_forks_repo_name": "coinstudent2048/writeups", "max_forks_repo_head_hexsha": "56ab74f04a03984c0281a423f3b068a1460fd325", "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": 68.4761904762, "max_line_length": 888, "alphanum_fraction": 0.6861961057, "num_tokens": 2050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754472, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.6520217990326831}}
{"text": "\\section{Scenarios}\\label{sec:scenarios}\n\nIn order to ease the analysis, we have defined three scenarios with different\nvalues for \\(A\\), \\(\\frac{X}{Y}\\) and \\(N\\). Inside each scenario, we will vary\nall other factors and we will evaluate the impact of these factors in the\nperformances of the network. As said in \\secref{sec:factors}, we will also vary\nthe number of users \\(N\\) but we will not consider this a tunable factor to\nimprove the performances of the network.\n\nThe scenarios defined are the following:\n\\begin{enumerate}\n\t\\item \\(A = 22500m^2\\), \\(\\frac{X}{Y} = 1\\) \\idest{\\(150m\\times150m\\)\n\t\tsquare} and \\(N = 1125\\mathit{users}\\) \\idest{\\(\\frac{N}{A} =\n\t\t\\frac{1125\\mathit{users}}{22500m^2} = 0.05\\mathit{users}/m^2 =\n\t\t\\frac{1}{20}\\mathit{users}/m^2\\)}. This is the ``high density\n\t\tscenario''.\n\t\\item \\(A = 250000m^2\\), \\(\\frac{X}{Y} = 1\\) \\idest{\\(500m\\times500m\\)\n\t\tsquare} and \\(N = 1250\\mathit{users}\\) \\idest{\\(\\frac{N}{A} =\n\t\t\\frac{1250\\mathit{users}}{250000m^2} = 0.005\\mathit{users}/m^2 =\n\t\t\\frac{1}{200}\\mathit{users}/m^2\\)}. This is the ``low density\n\t\tscenario''.\n\t\\item \\(A = 30000m^2\\), \\(\\frac{X}{Y} = 3\\) \\idest{\\(300m\\times100m\\)\n\t\trectangle} and \\(N = 1500\\mathit{users}\\) \\idest{\\(\\frac{N}{A} =\n\t\t\\frac{1500\\mathit{users}}{30000m^2} = 0.05\\mathit{users}/m^2\n\t\t\\simeq \\frac{1}{20}\\mathit{users}/m^2\\)}. This is the\n\t\t``rectangular scenario'' (high density).\n\\end{enumerate}\n\n\\input{design/scenarios/calibration}\n", "meta": {"hexsha": "6dbe74a8c097360dd49388e6ab989601d372740f", "size": 1444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapters/design/scenarios.tex", "max_stars_repo_name": "SpeedJack/pecsn", "max_stars_repo_head_hexsha": "40c757cddec978e06de766c9dff00abf57ccd6b3", "max_stars_repo_licenses": ["MIT"], "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/design/scenarios.tex", "max_issues_repo_name": "SpeedJack/pecsn", "max_issues_repo_head_hexsha": "40c757cddec978e06de766c9dff00abf57ccd6b3", "max_issues_repo_licenses": ["MIT"], "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/design/scenarios.tex", "max_forks_repo_name": "SpeedJack/pecsn", "max_forks_repo_head_hexsha": "40c757cddec978e06de766c9dff00abf57ccd6b3", "max_forks_repo_licenses": ["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.1333333333, "max_line_length": 79, "alphanum_fraction": 0.6648199446, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664175, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6520217906868822}}
{"text": "\\subsection{Example: Inverted slider-crank Mechanism}\n\n\\begin{frame}\n\t\\begin{block}{Example 3: Inverted slider-crank Mechanism}\n\t\t\\begin{table}\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\begin{tabular}{l|l}\n\t\t\t\t\t      & $l_{AD}=l_1=0.35m$\\\\\n\t\t\t\t\tGiven & $l_{BC}=l_2=0.20m$\\\\\n\t\t\t\t\t      & $l_{AC}=0.15m$\\\\\n\t\t\t\t\t      & $\\theta_1=60^{\\circ}$\\\\\\hline\n\t\t\t\t\tFind  & $\\vb{r}{B}$, $\\vb{r}{D}$\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{minipage}\\hfill\n\t\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\t\\includegraphics[width=30mm]{images/Inverted-R-RRT.png}\n\t\t\t\t\\end{minipage}\n\t\t\\end{table}\n\t\\end{block}\n\\emph{Solution}\\vskip2.5mm\nPosition of joint $B$: $\\displaystyle \\vb{r}{B} = x_B\\ih + y_B\\jh = l_{AB}\\cos{\\theta_1}\\ih + l_{AB}\\sin{\\theta_1}\\jh$\\\\\nPosition of joint $C$: $\\displaystyle \\vb{r}{C} = x_C\\ih + y_C\\jh = 0.15\\ih$\\\\\nPosition of joint $D$: $\\displaystyle \\vb{r}{D} = x_D\\ih + y_D\\jh = l_1\\cos{\\theta_1}\\ih + l_1\\sin{\\theta_1}\\jh$\n\\end{frame}\n\n\\begin{frame}\n\\emph{Solution}\\vskip2.5mm\nPosition of joint $B$: $\\displaystyle \\vb{r}{B} = x_B\\ih + y_B\\jh = l_{AB}\\cos{\\theta_1}\\ih + l_{AB}\\sin{\\theta_1}\\jh$\\\\\nPosition of joint $C$: $\\displaystyle \\vb{r}{C} = x_C\\ih + y_C\\jh = 0.15\\ih$\\\\\nPosition of joint $D$: $\\displaystyle \\vb{r}{D} = x_D\\ih + y_D\\jh = l_1\\cos{\\theta_1}\\ih+l_1\\sin{\\theta_1}\\jh$\n\\[\n\\Rightarrow\\displaystyle(x_B-x_C)^2+y_B^2=l_2^2\n\\]\n\\[\n\\text{ or } (l_{AB}\\cos{60^\\circ}-0.15)^2+l_{AB}\\sin{60^\\circ}=l_2^2\n\\]\nSolving the system of equations yields $l_{AB}>0$ and $l_{AB}<0$. Then, choose $l_{AB}>0$ and substitute the result into $\\vb{r}{B}$\n\\end{frame}\n\n\n\\begin{frame}{MATLAB R2019a code}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/Inverted-RRRT-position.m}\n\\end{frame}\n\\begin{frame}{Plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/Inverted-RRRT-plot.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/Inverted-RRRT-plot.png}\n\\end{frame}\n\\begin{frame}{Trajectory plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/Inverted-RRRT-trajectory.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/Inverted-RRRT-trajectory.png}\n\\end{frame}\n", "meta": {"hexsha": "c3421c074b622478fd53c972578185814252339b", "size": 2230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/position_analysis_pdf/Sections/Examples/Inverted_RRRT.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/position_analysis_pdf/Sections/Examples/Inverted_RRRT.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/position_analysis_pdf/Sections/Examples/Inverted_RRRT.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4482758621, "max_line_length": 132, "alphanum_fraction": 0.6744394619, "num_tokens": 884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.651948520951367}}
{"text": " \n\\subsection{Finite Elasticity}\n\\label{subsec:FiniteElasticity}\n\n%Deformation can be viewed three ways: A point to point transformation; A\n%coordinate transformation; or as a transformation of metrics (convected coordinates).\n\n\\subsubsection{Kinematics}\n\nAs shown in \\figref{fig:configurationsetting}, consider a \\textit{material\n  body} which is a three-dimensional smooth manifold with a boundary, $\\manifold{B}$,\nwhich consists of a set of points which are refered to as \\textit{material\n  points}. Consider also an ambient space manifold,\n$\\manifold{S}\\in\\rntopology{n}$. The material body is only accessible to\nthe observer when it moves through the ambient space. This motion is a\ntime-dependent embedding on the material body into the ambient space. The\nembedding is known as a \\textit{placement of the body}. It is given by the\nmapping\n\\begin{equation}\n  \\mapping{\\fnof{\\kappa}{\\mathcal{X},t}}{\\manifold{B}}{\\manifold{S}}\n\\end{equation}\n\nThe embedded submanifold occupying a location in the ambient space is is\ncalled a \\textit{configuration} of $\\manifold{B}$ and is given by\n\\begin{equation}\n  \\embedmanifold{B}_{t}=\\fnof{\\kappa_{t}}{\\manifold{B}}=\\fnof{\\kappa}{\\manifold{B},t}\n\\end{equation}\n\nThe customary (but not necessary) \\textit{reference placement} is given by\n\\begin{equation}\n  \\mapping{\\kappa_{0}}{\\manifold{B}}{\\manifold{S}}\n\\end{equation}\nand the region of space occupied by the reference placement \\ie the\n\\textit{reference configuration} is given by\n\\begin{equation}\n  \\embedmanifold{B}_{0}=\\fnof{\\kappa_{0}}{\\manifold{B}}\n\\end{equation}\nPoints in $\\embedmanifold{B}_{0}$ are denoted by capital letters \\ie $X, Y,\n\\ldots$. Points in $\\embedmanifold{B}$ are denoted by lower case leters \\ie\n$x, y, \\dots$.\n\n\\epstexfigure{svgs/EquationSets/Elasticity/FiniteElasticity/setup.eps_tex}{}{}{fig:configurationsetting}{0.75}\n\nA new configuration of $\\manifold{B}$ is given by the deformation mapping\n\\begin{equation}\n  \\mapping{\\chi}{\\embedmanifold{B}}{\\rntopology{3}}\n\\end{equation}\nwhere a configuration represents a deformed state of the body. As the body\nmoves we obtain a family of configurations. If we hold $X\\in\\embedmanifold{B}$\nfixed can write $\\fnof{V_{t}}{X}=\\fnof{V}{X,t}$. We then have\n\\begin{equation}\n  \\fnof{V_{t}}{X}=\\fnof{V}{X,t}=\\delby{\\fnof{\\chi}{X,t}}{t}=\\dby{\\fnof{\\chi_{X}}{t}}{t}\n\\end{equation}\n\nHere $V_{t}$ is called the \\textit{material velocity} of the motion. The\n\\textit{material acceleration} of the body is defined as\n\\begin{equation}\n  \\fnof{A_{t}}{X}=\\fnof{A}{X,t}=\\delby{\\fnof{V}{X,t}}{t}=\\dby{\\fnof{V_{X}}{t}}{t}\n\\end{equation}\n\nThe \\textit{spatial velocity} of the motion is defined by $v_{t}$ and the\n\\textit{spatial acceleration} of the motion is defined by $a_{t}$.\n\n\\subsubsection{Deformation Gradient}\n\nLet\n$\\mapping{\\chi}{\\embedmanifold{B}_{0}}{\\fnof{\\chi}{\\embedmanifold{B}_{0}}\\subset\\manifold{S}}$\nbe a deformation configuration of $\\embedmanifold{B}$ in $\\manifold{S}$. The\ntangent of the mapping \\ie $\\tangentbundle{\\chi}$ is denoted as $\\tensor{F}$\nand is called the \\textit{deformation gradient} of $\\chi$ \\ie\n$\\tensor{F}=\\tangentbundle{\\chi}$. For $X\\in\\embedmanifold{B}$ we have\n\\begin{equation}\n  \\tensor{F}_{X}=\\mapping{\\fnof{\\tensor{F}}{X}}{\\tangentspace{\\embedmanifold{B}}{X}}{\\tangentspace{\\manifold{S}}{\\fnof{\\chi}{X}}}\n\\end{equation}\n \nIf $X^{A}$ and $x^{a}$ are the coordinates on $\\embedmanifold{B}$ and\n$\\manifold{S}$ then the deformation gradient tensor with respect to the\ncoordinate bases are\n\\begin{equation}\n  \\fnof{F^{a}_{A}}{X}=\\delby{\\fnof{\\chi^{a}}{X}}{X^{A}}\n\\end{equation}\n\nNote that $\\tensor{F}$ is a two-point tensor. \n\nThe \\textit{right Cauchy-Green (or Green) deformation tensor}, $\\tensor{C}$, is defined by\n\\begin{equation}\n  \\mapping{\\fnof{\\tensor{C}}{X}}{\\tangentspace{\\embedmanifold{B}}{X}}{\\tangentspace{\\embedmanifold{B}}{X}}\n\\end{equation}\nas the pullback of the spatial metric tensor \\ie $\\fnof{\\tensor{C}}{X}=\\transpose{\\fnof{\\tensor{F}}{X}}\\fnof{\\tensor{g}}{x}\\fnof{\\tensor{F}}{X}$\nor $\\tensor{C}=\\transpose{\\tensor{F}}\\tensor{g}\\tensor{F}$ where $x=\\fnof{\\chi}{X}$. In terms of coordinates we\nhave\n\\begin{equation}\n  C_{AB}=g_{ab}F^{a}_{A}F^{b}_{B}\n\\end{equation}\n\nIf $\\tensor{C}$ is invertible we also have $\\tensor{B}=\\inverse{\\tensor{C}}$\ncalled the \\textit{Piola deformation tensor}.\n\nThe \\textit{left Cauchy-Green (or Finger) deformation tensor}, $\\tensor{b}$, is defined by\n\\begin{equation}\n  \\mapping{\\fnof{\\tensor{b}}{x}}{\\tangentspace{\\fnof{\\chi}{\\embedmanifold{B}}}{x}}{\\tangentspace{\\fnof{\\chi}{\\embedmanifold{B}}}{x}}\n\\end{equation}\nas the push forward of the material metric tensor \\ie $\\fnof{\\tensor{b}}{x}=\\fnof{\\tensor{F}}{X}\\fnof{\\tensor{G}}{X}\\transpose{\\fnof{\\tensor{F}}{X}}$\nor $\\tensor{b}=\\tensor{F}\\tensor{G}\\transpose{\\tensor{F}}$ where $X=\\fnof{\\inverse{\\chi}}{x}$. In terms of coordinates we\nhave\n\\begin{equation}\n  b^{ab}=G^{AB}F^{a}_{A}F^{b}_{B}\n\\end{equation}\n\nWe also have $\\tensor{c}=\\inverse{\\tensor{b}}$.\n\nThe polar decomposition\n\n\\begin{diagram}\n & & \\tangentspace{B}{X} & & \\\\\n & \\ruTo^{\\tensor{U}} & & \\rdTo^{\\tensor{R}} \\\\\n\\tangentspace{B}{X} & & \\rTo^{\\tensor{F}} & & \\tangentspace{S}{x}\\\\\n & \\rdTo_{\\tensor{R}} & & \\ruTo_{\\tensor{V}} \\\\\n & &  \\tangentspace{S}{x} & &\n\\end{diagram}\n\n\nIf we let the deformed coordinates be given by the position vector,\n$\\fnof{\\vectr{z}}{\\vectr{x},t}$ then the deformation gradient tensor with\nrespect to the undeformed $\\vectr{X}$ coordinates is given by\n\\begin{equation}\n  \\fnof{\\tensor{F}}{\\vectr{X}}=\\delby{\\vectr{z}}{\\vectr{X}}\n\\end{equation}\nor, in component form,\n\\begin{equation}\n  F^{i}_{M}=\\delby{z^{i}}{X^{M}}=\\delby{z^{i}}{\\xi^{k}}\\delby{\\xi^{k}}{X^{M}}\n\\end{equation}\n\nIn order to deal with anisotropy we wish to base our stress and strain\ncalculation on fibre, $\\vectr{\\nu}$, coordinates. To change our reference\ncoordinate system from $\\vectr{X}$ to $\\vectr{\\nu}$ we need to transform\n$\\fnof{\\tensor{F}}{\\vectr{X}}$. As $\\fnof{\\tensor{F}}{\\vectr{X}}$ is a two point tensor the transformation\nrule for transforming just the reference coordinates is given by\n\\begin{equation}\n\\fnof{\\tensor{F}}{\\vectr{\\nu}}=\\tensor{Q}\\fnof{\\tensor{F}}{\\vectr{X}}\n\\end{equation}\nwhere $\\tensor{Q}$ is the rotation matrix from $\\vectr{X}$ to $\\vectr{\\nu}$ \\ie\n\\begin{equation}\n  F^{i}_{A}=\\delby{X^{M}}{\\nu^{A}}F^{i}_{M}=\\delby{X^{M}}{\\nu^{A}}\\delby{z^{i}}{\\xi^{k}}\\delby{\\xi^{k}}{X^{M}}\n\\end{equation}\n\nTo allow for growth we use a multiplicative decomposition approach \\ie\n\\begin{equation}\n  \\fnof{\\tensor{F}}{\\vectr{\\nu}}=\\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}\\fnof{\\tensor{F}_{g}}{\\vectr{\\nu}}\n\\end{equation}\nwhere $\\fnof{\\tensor{F}_{g}}{\\vectr{\\nu}}$ is the growth tensor with\nrespect to fibre coordinates and $\\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}$ is the\nelastic component of the deformation gradient tensor in fibre coordinates.\n\nThe elastic component of the deformation gradient tensor can be calculated\nfrom\n\\begin{equation}\n  \\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}=\\fnof{\\tensor{F}}{\\vectr{\\nu}}\\fnof{\\inverse{\\tensor{F}_{g}}}{\\vectr{\\nu}}\n\\end{equation}\n\nIn component form we have\n\\begin{equation}\n  F^{i}_{A}=\\pbrac{F_{e}}^{i}_{B}\\pbrac{F_{g}}^{B}_{A}\n\\end{equation}\nand\n\\begin{equation}\n  \\pbrac{F_{e}}^{i}_{B}=F^{i}_{A}\\pbrac{\\inverse{F_{g}}}^{A}_{B}\n\\end{equation}\n\nThe Jacobian of the growth component of the deformation is given by\n$J_{g}=\\det{\\fnof{\\tensor{F}_{g}}{\\vectr{\\nu}}}$ and the Jacobian of the\nelastic component of the deformation is given by\n$J_{e}=\\det{\\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}}$.\n\nThe right Cauchy Green deformation tensor in fibre coordinates is now given by\nthe pullback of the current configuration metric tensor, $\\tensor{g}$,\n\\begin{equation}\n  \\fnof{\\tensor{C}}{\\vectr{\\nu}}=\\fnof{\\transpose{\\tensor{F}_{e}}}{\\vectr{\\nu}}\\tensor{g}\\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}\n\\end{equation}\nand the Lagrange strain tensor is given by the difference in metric tensors\n\\begin{equation}\n  \\fnof{\\tensor{E}}{\\vectr{\\nu}}=\\frac{1}{2}\\pbrac{\\fnof{\\tensor{C}}{\\vectr{\\nu}}-\\tensor{G}}\n\\end{equation}\n\nIn component form we have\n\\begin{equation}\n  C_{AB}=g_{ij}\\pbrac{F_{e}}^{i}_{A}\\pbrac{F_{e}}^{j}_{B}\n\\end{equation}\nand\n\\begin{equation}\n  E_{AB}=\\frac{1}{2}\\pbrac{C_{AB}-G_{AB}}\n\\end{equation}\n\nThe constituative law can then be used to derive the second Piola Kirchhoff\nstress tensor in fibre coordinates, $\\fnof{\\tensor{T}}{\\vectr{\\nu}}$, from\neither the right Cauchy-Green deformation tensor or the Green-Lagrange strain\ntensor \\ie\n\\begin{equation}\n  \\fnof{\\tensor{T}}{\\vectr{\\nu}}=2\\delby{\\fnof{W}{\\fnof{\\tensor{C}}{\\vectr{\\nu}}}}{\\fnof{\\tensor{C}}{\\vectr{\\nu}}}\n\\end{equation}\nor\n\\begin{equation}\n  \\fnof{\\tensor{T}}{\\vectr{\\nu}}=\\delby{\\fnof{W}{\\fnof{\\tensor{E}}{\\vectr{\\nu}}}}{\\fnof{\\tensor{E}}{\\vectr{\\nu}}}\n\\end{equation}\nwhere $\\fnof{W}{\\fnof{\\tensor{C}}{\\vectr{\\nu}}}$ or\n$\\fnof{W}{\\fnof{\\tensor{E}}{\\vectr{\\nu}}}$ is the strain energy\nfunction. In component form we have\n\\begin{equation}\n  T^{AB}=2\\delby{W}{C_{AB}}\n\\end{equation}\nor\n\\begin{equation}\n  T^{AB}=\\delby{W}{E_{AB}}\n\\end{equation}\n\nBecause $\\tensor{C}$ is symmetric then we can deal with the invariants. The\nthree invariants are\n\\begin{equation}\n  \\begin{split}\n    I_{1} &= \\operatorname{tr}\\tensor{C} \\\\\n    &= C_{11} + C_{22} + C_{33} \\\\\n    I_{2} &=\n    \\dfrac{1}{2}\\pbrac{\\pbrac{\\operatorname{tr}\\tensor{C}}^{2}-\\operatorname{tr}\\tensor{C}^{2}} \\\\\n    &=\n    \\dfrac{1}{2}\\left(\\pbrac{C_{11}+C_{22}+C_{33}}^{2}\\right. \\\\\n      & \\quad\\left.-\\pbrac{C_{11}^{2}+C_{12}C_{21}+C_{13}C_{31}+\n        C_{21}C_{12}+C_{22}^{2}+C_{23}C_{32}+C_{31}C_{13}+C_{32}C_{23}+C_{33}^{2}}\\right) \\\\\n    I_{3} &= \\det{\\tensor{C}} \\\\\n    &=C_{11}C_{22}C_{33}+C_{12}C_{23}C_{31}+C_{13}C_{21}C_{32}\\\\\n    &\\quad-C_{13}C_{22}C_{31}-C_{12}C_{21}C_{33}-C_{11}C_{23}C_{32}\n  \\end{split}\n\\end{equation}\nWe thus have\n$\\fnof{W}{\\fnof{\\tensor{C}}{\\vectr{\\nu}}}=\\fnof{W}{I_{1},I_{2},I_{3}}$ and\nthus\n\\begin{equation}\n  T^{AB}=2\\pbrac{\\delby{W}{I_{1}}\\delby{I_{1}}{C_{AB}}+\\delby{W}{I_{2}}\\delby{I_{2}}{C_{AB}}+\\delby{W}{I_{3}}\\delby{I_{3}}{C_{AB}}}\n\\end{equation}\nor if we have\n$\\fnof{W}{\\fnof{\\tensor{E}}{\\vectr{\\nu}}}=\\fnof{W}{I_{1},I_{2},I_{3}}$ and\nthus\n\\begin{equation}\n  T^{AB}=\\pbrac{\\delby{W}{I_{1}}\\delby{I_{1}}{E_{AB}}+\\delby{W}{I_{2}}\\delby{I_{2}}{E_{AB}}+\\delby{W}{I_{3}}\\delby{I_{3}}{E_{AB}}}\n\\end{equation}\n\nNow we have\n\\begin{equation}\n  \\delby{I_{1}}{C_{AB}}=\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n\\end{equation}\nand\n\\begin{equation}\n  \\delby{I_{2}}{C_{AB}}=\\begin{bmatrix}\n    C_{22}+C_{33} & -C_{21} & -C_{31} \\\\\n    -C_{12} & C_{11}+C_{33} & -C_{32} \\\\\n    -C_{13} & -C_{23} & C_{11}+C_{22}\n  \\end{bmatrix}\n\\end{equation}\nand\n\\begin{equation}\n  \\delby{I_{3}}{C_{AB}}=\\begin{bmatrix}\n    C_{22}C_{33}-C_{23}C_{32} & C_{23}C_{31}-C_{21}C_{33} & C_{23}C_{32}-C_{22}C_{31} \\\\\n    C_{13}C_{32}-C_{12}C_{33} & C_{11}C_{33}-C_{13}C_{31} & C_{12}C_{31}-C_{11}C_{32} \\\\\n    C_{12}C_{32}-C_{22}C_{31} & C_{13}C_{23}-C_{11}C_{23} & C_{11}C_{22}-C_{12}C_{21}\n  \\end{bmatrix}\n\\end{equation}\n\nAs an example consider a Mooney-Rivlin material. The strain energy function is\ngiven by\n\\begin{equation}\n  \\fnof{W}{I_{1},I_{2}}=c_{1}\\pbrac{I_{1}-3}+c_{2}\\pbrac{I_{2}-3}\n\\end{equation}\n\nThe second Piola Kirchhoff tensor is thus\n\\begin{equation}\n  T^{AB}=\\begin{bmatrix}\n    2c_{1}+2c_{2}\\pbrac{C_{22}+C_{33}} & -2c_{2}C_{21} & -2c_{2}C_{31} \\\\\n    -2c_{2}C_{12} & 2c_{1}+2c_{2}\\pbrac{C_{11}+C_{33}} & -2c_{2}C_{32} \\\\\n    -2c_{2}C_{13} & -2c_{2}C_{23} & 2c_{1}+2c_{2}\\pbrac{C_{11}+C_{22}}\n  \\end{bmatrix}\n\\end{equation}\nor\n\\begin{equation}\n  T^{AB}=\\begin{bmatrix}\n    c_{1}+c_{2}\\pbrac{E_{22}+E_{33}} & -c_{2}E_{21} & -c_{2}E_{31} \\\\\n    -c_{2}E_{12} & c_{1}+c_{2}\\pbrac{E_{11}+E_{33}} & -c_{2}E_{32} \\\\\n    -c_{2}E_{13} & -c_{2}E_{23} & c_{1}+c_{2}\\pbrac{E_{11}+E_{22}}\n  \\end{bmatrix}\n\\end{equation}\n\nFor incompressible materials we need to add in the volumetric stress. The\nhydrostatic stress is a Cauchy stress and so we have\n\\begin{equation}\n  \\tensor{\\sigma}_{p} = -p\\tensor{g}\n\\end{equation}\nor in component form\n\\begin{equation}\n  \\sigma_{p}^{ij} = -p g^{ij}\n\\end{equation}\n\nWe can pull this stress back to give a second Piola Kirchhoff stress via the\npullback operation for a second order tensor \\ie\n\\begin{equation}\n  \\tensor{T}_{p}=\n  -\\inverse{\\tensor{F}_{e}}\\tensor{\\sigma}_{p}\\invtranspose{\\tensor{F}_{e}} = -p\\inverse{\\tensor{C}}\n\\end{equation}\nor in component form\n\\begin{equation}\n  T_{p}^{AB}=-\\pbrac{F_{e}}^{A}_{i}p g^{ij}\\pbrac{F_{e}}^{B}_{j}=-p\\pbrac{\\inverse{C}}^{AB}\n\\end{equation}\n\nTo find the stress tensors in deformed coordinates we need to push the second\nPiola Kirchhoff tensor in the reference coordinates forward to the deformed\ncoordinates, $\\vectr{x}$, to give the Kirchhoff stress tensor,\n$\\fnof{\\tensor{\\tau}}{\\vectr{x}}$. The push foward is given by\n\\begin{equation}\n  \\fnof{\\tensor{\\tau}}{\\vectr{x}}=\\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}\\fnof{\\tensor{T}}{\\vectr{\\nu}}\n  \\fnof{\\transpose{\\tensor{F}_{e}}}{\\vectr{\\nu}}\n\\end{equation}\n\nThe Cauchy stress tensor, $\\fnof{\\tensor{\\sigma}}{\\vectr{x}}$, can then be calculated from the Kirchhoff stress\ntensor using the Jacobian of the deformation \\ie\n\\begin{equation}\n  \\fnof{\\tensor{\\sigma}}{\\vectr{x}}=\\inverse{J_{e}}\\fnof{\\tensor{\\tau}}{\\vectr{x}}=\\inverse{J_{e}}\n  \\fnof{\\tensor{F}_{e}}{\\vectr{\\nu}}\\fnof{\\tensor{T}}{\\vectr{\\nu}}\\fnof{\\transpose{\\tensor{F}_{e}}}{\\vectr{\\nu}}\n\\end{equation}\n\nIn component form we have\n\\begin{equation}\n  \\tau^{ij}=\\pbrac{F_{e}}^{i}_{B}T^{BC}\\pbrac{\\transpose{F_{e}}}^{j}_{C}\n\\end{equation}\nand\n\\begin{equation}\n  \\sigma^{ij}=\\inverse{J_{e}}\\pbrac{F_{e}}^{i}_{B}T^{BC}\\pbrac{\\transpose{F_{e}}}^{j}_{C}\n\\end{equation}\n\nNow the principle of virtual work (Marsden and Hughes, pg 168) can be stated as\n\\begin{equation}\n  \\gint{\\embedmanifold{B}}{}{\\rho\\dotprod{\\vectr{a}}{\\delta\\vectr{u}}}{v}=\n  \\gint{\\embedmanifold{B}}{}{\\rho\\dotprod{\\vectr{b}}{\\delta\\vectr{u}}}{v}-\n  \\gint{\\embedmanifold{B}}{}{\\doubledotprod{\\tensor{\\sigma}}{\\gradient{\\delta\\vectr{u}}}}{v}+\n  \\gint{\\boundary{\\embedmanifold{B}}}{}{\\dotprod{\\pbrac{\\dotprod{\\tensor{\\sigma}}{\\vectr{n}}}}{\\delta\\vectr{u}}}{a}\n\\end{equation}\nwhere $\\delta\\vectr{u}$ are the virtual displacements.\n\nIn component form we have\n\\begin{equation}\n  \\gint{\\embedmanifold{B}}{}{\\sigma^{ij}\\covarderiv{\\delta u_{j}}{i}}{v}=\n  \\gint{\\embedmanifold{B}}{}{\\rho\\pbrac{b^{j}-a^{j}}\\delta u_{j}}{v}+\n  \\gint{\\boundary{\\embedmanifold{B}}}{}{t^{j}\\delta u_{j}}{a}\n\\end{equation}\n\nThe left hand side of the virtual work statement is\n\\begin{equation}\n  \\begin{split}\n    \\gint{\\embedmanifold{B}}{}{\\sigma^{ij}\\covarderiv{\\delta u_{j}}{i}}{v}\n    &= \\gint{\\embedmanifold{B}}{}{\\sigma^{ij}\\pbrac{\\partialderiv{\\delta\n          u_{j}}{i}-\\christoffel{k}{j}{i}\\delta u_{k}}}{v} \\\\\n    &= \\gint{\\embedmanifold{B}}{}{\\sigma^{ij}\\pbrac{\\delby{\\delta\n          u_{j}}{x^{i}}-\\christoffel{k}{j}{i}\\delta u_{k}}}{v}\n  \\end{split}\n\\end{equation}\n\nNow\n\\begin{equation}\n  \\vectr{u}=\\vectr{z}-\\vectr{x}\n\\end{equation}\nand so\n\\begin{equation}\n  \\begin{split}\n    \\delta\\vectr{u} &=\\delta\\pbrac{\\vectr{z} -\\vectr{X}} \\\\\n    &=\\delta\\vectr{z}-\\delta\\vectr{X} \\\\\n    &=\\delta\\vectr{z}\n  \\end{split}\n\\end{equation}\n\nIf we now substitute $\\delta\\vectr{u}=\\delta\\vectr{z}$ and convert the left\nhand side of the virtual work statement from an integral with respect to\nspatial coordinates to an integral with respect to $\\vectr{\\xi}$ coordinates we obtain\n\n\\begin{equation}\n  \\begin{split}\n    \\gint{\\embedmanifold{B}}{}{\\sigma^{ij}\\pbrac{\\delby{\\delta\n          u_{j}}{x^{i}}-\\christoffel{k}{j}{i}\\delta u_{k}}}{v}\n    &= \\gint{\\embedmanifold{B}}{}{\\sigma^{ij}\\pbrac{\\delby{\\delta\n          z_{j}}{x^{i}}-\\christoffel{k}{j}{i}\\delta z_{k}}}{v} \\\\\n    &= \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{\\sigma^{ij}}{\\vectr{\\xi}}\\pbrac{\\delby{\\xi_{l}}{x^{i}}\\delby{\\delta\n          \\fnof{z_{j}}{\\vectr{\\xi}}}{\\xi^{l}}-\\christoffel{k}{j}{i}\\delta\\fnof{z_{k}}{\\vect{\\xi}}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n  \\end{split}\n\\end{equation}\n\nNote that in rectangular cartesian coordinates $\\christoffel{k}{j}{i}=0$ \n$\\forall i,j,k$. In addition it is not necessary to transform either the\nCauchy stress tensor or gradient of the virtual displacements so that the\ncomponents are with respect to $\\vectr{\\xi}$ coordinates. What is important is that\nthe stress and displacement are with respect to the same coordinate\nsystem. Because the gradient of $\\delta \\vectr{z}$ is with respect to $\\vectr{x}$ coordinates\nthen $\\tensor{\\sigma}$ needs to be with respect to $\\vectr{x}$ coordinates. As there\nis no coordinate transformations the Christoffel symbols are all zero and can\nbe dropped.\n\nThe right hand side of the virtual work statement is\n\\begin{equation}\n  \\begin{split}\n    \\gint{\\embedmanifold{B}}{}{\\rho\\pbrac{b^{j}-a^{j}}\\delta u_{j}}{v}+\n    \\gint{\\boundary{\\embedmanifold{B}}}{}{t^{j}\\delta u_{j}}{a}\n    &= \\gint{\\embedmanifold{B}}{}{\\rho\\pbrac{b^{j}-a^{j}}\\delta z_{j}}{v}+\n    \\gint{\\boundary{\\embedmanifold{B}}}{}{Pn^{j}\\delta z_{j}}{a} \\\\\n    &= \\gint{\\vectr{0}}{\\vectr{1}}{\\rho\\pbrac{\\fnof{b^{j}}{\\vectr{\\xi}}-\\fnof{a^{j}}{\\vectr{\\xi}}}\\delta\n      \\fnof{z_{j}}{\\vectr{\\xi}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\\\\\n    &\\quad+\\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{P}{\\vectr{\\xi}}\\fnof{n^{j}}{\\vectr{\\xi}}\\delta\n      \\fnof{z_{j}}{\\vectr{\\xi}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}    \n  \\end{split}\n\\end{equation}\nwhere $P$ is the applied surface pressure.\n\nIf we now use basis functions to interpolate the virtual displacements \\ie\n\\begin{equation}\n  \\delta \\fnof{z_{j}}{\\vectr{\\xi}} = \\idxgbfn{j}{m}{\\alpha}{\\vectr{\\xi}}\\delta z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\n\\end{equation}\nwhich, assuming rectangular cartesian coordinates, gives for the left hand side integral\n\\begin{equation}\n  \\begin{split}\n    \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{\\sigma^{ij}}{\\vectr{\\xi}}\\delby{\\xi_{l}}{x^{i}}\\delby{\\delta\n          \\fnof{z_{j}}{\\vectr{\\xi}}}{\\xi^{l}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n    &= \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{\\sigma^{ij}}{\\vectr{\\xi}}\\delby{\\xi_{l}}{x^{i}}\\delby{\n          \\pbrac{\\idxgbfn{j}{m}{\\alpha}{\\vectr{\\xi}}\\delta z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}}}{\\xi^{l}}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}} \\\\\n    &= \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{\\sigma^{ij}}{\\vectr{\\xi}}\\delby{\\xi_{l}}{x^{i}}\\delby{\n          \\idxgbfn{j}{m}{\\alpha}{\\vectr{\\xi}}}{\\xi^{l}}\\delta z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}} \\\\\n    &= \\delta z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\n    \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{\\sigma^{ij}}{\\vectr{\\xi}}\\delby{\\xi_{l}}{x^{i}}\\delby{\n          \\gbfn{m}{j\\alpha}{\\vectr{\\xi}}}{\\xi^{l}}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}} \n  \\end{split}\n\\end{equation}\nand for the first integral on the right hand side integral we have\n\\begin{equation}\n  \\begin{split}\n    \\gint{\\vectr{0}}{\\vectr{1}}{\\rho\\pbrac{\\fnof{b^{j}}{\\vectr{\\xi}}-\\fnof{a^{j}}{\\vectr{\\xi}}}\\delta\n      \\fnof{z_{j}}{\\vectr{\\xi}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n    &= \\gint{\\vectr{0}}{\\vectr{1}}{\\rho\\pbrac{\\fnof{b^{j}}{\\vectr{\\xi}}-\\fnof{a^{j}}{\\vectr{\\xi}}}\n      \\idxgbfn{j}{m}{\\alpha}{\\vectr{\\xi}}\\delta\n      z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}} \\\\\n    &= \\delta\n    z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\\gint{\\vectr{0}}{\\vectr{1}}{\\rho\\pbrac{\\fnof{b^{j}}{\\vectr{\\xi}}-\n        \\fnof{a^{j}}{\\vectr{\\xi}}}\\gbfn{m}{j\\alpha}{\\vectr{\\xi}}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n  \\end{split}\n\\end{equation}\nand for the second integral on the right hand side we have\n\\begin{equation}\n  \\begin{split}\n    \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{P}{\\vectr{\\xi}}\\fnof{n^{j}}{\\vectr{\\xi}}\\delta\n      \\fnof{z_{j}}{\\vectr{\\xi}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n    &= \\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{P}{\\vectr{\\xi}}\\fnof{n^{j}}{\\vectr{\\xi}}\n      \\idxgbfn{j}{m}{\\alpha}{\\vectr{\\xi}}\\delta\n      z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n    \\\\\n    &= \\delta z_{j,\\alpha}^{m}\\gsf{m}{\\alpha}\\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{P}{\\vectr{\\xi}}\\fnof{n^{j}}{\\vectr{\\xi}}\n      \\gbfn{m}{j\\alpha}{\\vectr{\\xi}}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n  \\end{split}\n\\end{equation}\n\nThis can be formulated as\n\\begin{equation}\n  r_{m}^{j\\alpha}\\delta z_{j,\\alpha}^{m}=0\n\\end{equation}\nwhere the residual vector is thus given by\n\\begin{multline}\n  r_{m}^{j\\alpha}=\\gsf{m}{\\alpha}\\left(\n    \\gint{\\vectr{0}}{\\vectr{1}}{\\pbrac{\\fnof{\\sigma^{ij}}{\\vectr{\\xi}}\\delby{\\xi_{l}}{x^{i}}\\delby{\n          \\gbfn{m}{j\\alpha}{\\vectr{\\xi}}}{\\xi^{l}}+\\rho\\pbrac{\n        \\fnof{a^{j}}{\\vectr{\\xi}}-\\fnof{b^{j}}{\\vectr{\\xi}}}\\gbfn{m}{j\\alpha}{\\vectr{\\xi}}}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\\right. \\\\\n    \\left.-\\gint{\\vectr{0}}{\\vectr{1}}{\\fnof{P}{\\vectr{\\xi}}\\fnof{n^{j}}{\\vectr{\\xi}}\n      \\gbfn{m}{j\\alpha}{\\vectr{\\xi}}\n      \\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\\right)\n\\end{multline}\n\nNow, as the virtual displacements are arbitrary we have the residual statement\n\\begin{equation}\n  r_{m}^{j\\alpha}=0\n\\end{equation}\n\nIn order to handle incompressible materials we need an additional constraint\nwhich penalises change in volume. The change in volume is given by\n\\begin{equation}\n  \\Delta V = \\dfrac{J_{\\embedmanifold{B}}}{J_{g}J_{\\embedmanifold{B}_{0}}}\n\\end{equation}\nand the residual equation is\n\\begin{equation}\n  \\begin{split}\n    r_{m}^{\\pbrac{N+1}\\alpha}&=\\gint{\\vectr{0}}{\\vectr{1}}{\\pbrac{\\fnof{\\Delta V}{\\vectr{\\xi}} -\n        1}\\gbfn{m}{\\pbrac{N+1}\\alpha}{\\vectr{\\xi}}\\gsf{m}{\\alpha}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n    \\\\\n    &=\\gsf{m}{\\alpha}\\gint{\\vectr{0}}{\\vectr{1}}{\\pbrac{\\dfrac{\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\fnof{J_{g}}{\\vectr{\\xi}}\\fnof{J_{\\embedmanifold{B}_{0}}}{\\vectr{\\xi}}} -\n        1}\\gbfn{m}{\\pbrac{N+1}\\alpha}{\\vectr{\\xi}}\\fnof{J_{\\embedmanifold{B}}}{\\vectr{\\xi}}}{\\vectr{\\xi}}\n  \\end{split}\n\\end{equation}\nwhere $N$ is the number of dimensions.\n\nIn order to solve the nonlinear system of equations a Newton scheme can be\nused. To calculate the Jacobian of the system we need to calculate the\nvariation of the virtual work statement.\n\nThis requires a linerization.\n\nConsider a linearisation of the second Piola-Kirchoff stress.\n\\begin{equation}\n  L\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}=\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}+\n          \\delta\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}\n\\end{equation}\n\nA linearisation of the Kirchoff stress can thus be calculated from a push\nforward of the linearisation of the second Piola-Kirchoff stress\n\n\\begin{equation}\n  \\begin{split}\n    L\\fnof{\\tensor{\\tau}}{\\vectr{u},\\delta\\vectr{u}}&=\\tensor{F}_{e}L\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}\\transpose{\\tensor{F}_{e}} \\\\\n    &= \\tensor{F}_{e}\\pbrac{\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}+\n      \\delta\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}}\\transpose{\\tensor{F}_{e}}\n    \\\\\n    &=\n    \\tensor{F}_{e}\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}\\transpose{\\tensor{F}_{e}}+\n    \\tensor{F}_{e}\\delta\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}\\transpose{\\tensor{F}_{e}}\n    \\\\\n    & =\\fnof{\\tensor{\\tau}}{\\vectr{u},\\delta\\vectr{u}}+\\tensor{F}_{e}\\delta\\fnof{\\tensor{T}}{\\vectr{u},\\delta\\vectr{u}}\\transpose{\\tensor{F}_{e}}\n  \\end{split}\n\\end{equation}\n\n\n\\clearpage\n\n\\subsection{Old Stuff}\n\nFormulation of finite element equations for finite elasticity (large\ndeformation mechanics) implemented in OpenCMISS is based on the\n\\textit{\\textbf{principle of virtual work}}. The finite element model consists\nof a set of non-linear algebraic equations. Non-linearity of equations stems\nfrom non-linear stress-strain relationship and quadratic terms present in the\nstrain tensor. A typical problem in large deformation mechanics involves\ndetermination of the deformed geometry or mesh nodal parameters, from the\nfinite element point of view, of the continuum from a known undeformed\ngeometry, subject to boundary conditions and satisfying stress-strain\n(constitutive) relationship.\n  \nThe boundary conditions can be either \\textit{\\textbf{Dirichlet}}\n(displacement), \\textit{\\textbf{Neumann}} (force) or a combination of them,\nknown as the mixed boundary conditions. Displacement boundary conditions are\ngenerally nodal based. However, force boundary conditions can take any of the\nfollowing forms or a combination of them - nodal-based, distributed load\n(e.g. pressure) or force acting at a discrete point on the boundary. In the\nlatter two forms, the equivalent nodal forces are determined using the\n\\textit{\\textbf{method of work equivalence}} \\cite{hutton:2004} and the forces\nso obtained will then be added to the right hand side or the residual vector\nof the linear equation system.\n\nThere are a numerous ways of describing the mechanical characteristics of\ndeformable materials in large deformation mechanics or finite elasticity\nanalyses. A predominantly used form for representing constitutive properties\nis a strain energy density function. This model gives the energy required to\ndeform a unit volume (hence energy density) of the deformable continuum as a\nfunction of Green-Lagrange strain tensor components or its derived variables\nsuch as invariants or principal stretches. A material that has a strain energy\ndensity function is known as a \\textit{\\textbf{hyperelastic}} or\n\\textit{\\textbf{Green-elastic material}}.\n\nThe deformed equilibrium state should also give the minimum total elastic\npotential energy. One can therefore formulate finite element equations using\nthe \\textit{\\textbf{Variational method}} approach where an extremum of a\nfunctional (in this case total strain energy) is determined to obtain mesh\nnodal parameters of the deformed continuum. It is also possible to derive the\nfinite element equations starting from the governing equilibrium equations\nknown as Cauchy equation of motion. The weak form of the governing equations\nis obtained by multiplying them with suitable weighting functions and\nintegrating over the domain (method of weighted residuals). If interpolation\nor shape functions are used as weighting functions, then the method is called\nthe Galerkin finite element method. All three approaches (virtual work,\nvariational method and Galerkin formulation) result in the same finite element\nequations.\n\nIn the following sections the derivation of kinematic relationships of\ndeformation, energy conjugacy, constitutive relationships and final form the\nfinite element equations using the virtual work approach will be discussed in\ndetail.\n\n\\subsubsection{Kinematics of Deformation}\nIn order to track the deformation of an infinitesimal length at a particle of\nthe continuum, two coordinates systems are defined. An arbitrary orthogonal\nspatial coordinate system, which is fixed in space and a material coordinate\nsystem which is attached to the continuum and deforms with the continuum. The\nmaterial coordinate system, in general, is a curvi-linear coordinate system\nbut must have mutually orthogonal axes at the undeformed state. However, in\nthe deformed state, these axes are no longer orthogonal as they deform with\nthe continuum (fig 1). In addition to these coordinate systems, there exist\nfinite element coordinate systems (one for each element) as well. These\ncoordinates are normalised and vary from 0.0 to 1.0. The following notations are used to represent various coordinate systems and coordinates of a particle of the continuum.\\\\\n\n\\noindent $Y_{1}$-$Y_{2}$-$Y_{3}$ - fixed spatial coordinate system axes - orthogonal\\\\\n$N_{1}$-$N_{2}$-$N_{3}$ - deforming material coordinate system axes  - orthogonal in the undeformed state\\\\\n$\\Xi_{1}$-$\\Xi_{2}$-$\\Xi_{3}$ - element coordinate system - non-orthogonal in general and deforms with continuum\\\\\n\n\\noindent $x_{1}$-$x_{2}$-$x_{3}$ [$\\vect{x}$] - spatial coordinates of a particle in the undeformed state wrt $Y_{1}$-$Y_{2}$-$Y_{3}$ CS \\\\\n$z_{1}$-$z_{2}$-$z_{3}$ [$\\vect{z}$] - spatial coordinates of the same particle in the deformed state wrt $Y_{1}$-$Y_{2}$-$Y_{3}$ CS \\\\\n$\\nu_{1}$-$\\nu_{2}$-$\\nu_{3}$ [$\\vect{\\nu}$] - material coordinates of the particle wrt $N_{1}$-$N_{2}$-$N_{3}$ CS (these do not change) \\\\\n$\\xi_{1}$-$\\xi_{2}$-$\\xi_{3}$ [$\\vect{\\xi}$] - element coordinates of the particle wrt $\\Xi_{1}$-$\\Xi_{2}$-$\\Xi_{3}$ CS (these too do not change)\\\\\n\nSince the directional vectors of the material coordinate system at any given\npoint in the undeformed state is mutually orthogonal, the relationship between\nspatial $\\vect{x}$ and material $\\vect{\\nu}$ coordinates is simply a\nrotation. The user must define the undeformed material coordinate\nsystem. Typically a nodal based interpolatable field known as fibre\ninformation (fibre, imbrication and sheet angles) is input to OpenCMISS. These\nangles define how much the \\textit{\\textbf{reference or default material\n    coordinate system}} must be rotated about the reference material axes. The\nreference material coordinate system at a given point is defined as\nfollows. The first direction $\\nu_{1}$ is in the $\\xi_{1}$ direction. The\nsecond direction, $\\nu_{2}$ is in the $\\xi_{1}-\\xi_{2}$ plane but orthogonal\nto $\\nu_{1}$. Finally the third direction $\\nu_{3}$ is determined to be normal\nto both $\\nu_{1}$ and $\\nu_{2}$. Once the reference coordinate system is\ndefined, it is then rotated about $\\nu_{3}$ by an angle equal to the\ninterpolated fibre value at the point in counter-clock wise direction. This\nwill be followed by a rotation about new $\\nu_{2}$ axis again in the\ncounter-clock wise direction by an angle equal to the sheet value. The final\nrotation is performed about the current $\\nu_{1}$ by an angle defined by\ninterpolated sheet value. Note that before a rotation is carried out about an\narbitrary axis one must first align(transform) the axis of rotation with one\nof the spatial coordinate system axes. Once the rotation is done, the rotated\ncoordinate system (material) must be inverse-transformed.\n\nHaving defined the undeformed orthogonal material coordinate system, the\nmetric tensor $\\delby{\\vect{x}}{\\vect{\\nu}}$ can be determined. As mentioned,\nthe tensor $\\delby{\\vect{x}}{\\vect{\\nu}}$ contains rotation required to align\nmaterial coordinate system with spatial coordinate system. This tensor is\ntherefore orthogonal. A similar metric tensor can be defined to relate the\ndeformed coordinates $\\vect{z}$ of the point to its material coordinates\n$\\vect{\\nu}$. Note that the latter coordinates do not change as the continuum\ndeforms and more importantly this tensor is not orthogonal as well. The metric\ntensor, $\\delby{\\vect{z}}{\\vect{\\nu}}$ is called the\n\\textit{\\textbf{deformation gradient tensor}} and denoted as $\\matr{F}$.\n\n\\begin{equation}\n  \\matr{F}=\\delby{\\vect{z}}{\\vect{\\nu}}\n  \\label{eqn:deformationgradienttensor}\n\\end{equation}\n \nIt can be shown that the deformation gradient tensor contains rotation when an\ninfinitesimal length $\\vect{dr_{0}}$ in the undeformed state undergoes\ndeformation. Since rotation does not contribute to any strain, it must be\nremoved from the deformation gradient tensor. Any tensor can be decomposed\ninto an orthogonal tensor and a symmetric tensor (known as polar\ndecomposition). In other words, the same deformation can be achieved by first\nrotating $\\vect{dr}$ and then stretching (shearing and scaling) or\nvice-verse. Thus, the deformation gradient tensor can be given by,\n\n\\begin{equation}\n  \\matr{F}=\\delby{\\vect{z}}{\\vect{\\nu}}=\\matr{R}\\matr{U}=\\matr{V}\\matr{R_{1}}\n  \\label{eqn:polardecomposition}\n\\end{equation}\n \nThe rotation present in the deformation gradient tensor can be removed either\nby right or left multiplication of $\\matr{F}$. The resulting tensors lead to\ndifferent strain measures. The right Cauchy deformation tensor $\\matr{C}$ is\nobtained from,\n\n\\begin{equation}\n  \\matr{C}=\\transpose{[\\matr{R}\\matr{U}]}[\\matr{R}\\matr{U}]=\\transpose{\\matr{U}}\\transpose{\\matr{R}}\\matr{R}\\matr{U}=\\transpose{\\matr{U}}\\matr{U}\n  \\label{eqn:rightCauchy}\n\\end{equation}\n\nSimilarly the left Cauchy deformation tensor or the Finger tensor \\matr{B} is\nobtained from the left multiplication of \\matr{F},\n\n\\begin{equation}\n  \\matr{B}=[\\matr{V}\\matr{R_{1}}]\\transpose{[\\matr{V}\\matr{R_{1}}]}=\\matr{V}\\matr{R_{1}}\\transpose{\\matr{R_{1}}}\\transpose{\\matr{V}}=\\matr{V}\\transpose{\\matr{V}}\n  \\label{eqn:leftCauchy}\n\\end{equation}\n\n\\noindent Note that both $\\matr{R}$ and $\\matr{R_{1}}$ are orthogonal tensors\nand therefore satisfy the following condition,\n\n\\begin{equation}\n  \\transpose{\\matr{R}}\\matr{R}=\\matr{R_{1}}\\transpose{\\matr{R_{1}}}=\\matr{I}\n  \\label{eqn:orthoganality}\n\\end{equation}\n\nSince there is no rotation present in both $\\matr{C}$ and $\\matr{B}$, they can\nbe used to define suitable strain measures as follows,\n\n\\begin{equation}\n  \\matr{E}=\\frac{1}{2}\\pbrac{\\transpose{\\delby{\\vect{z}}{\\vect{\\nu}}}\\delby{\\vect{z}}{\\vect{\\nu}}-\n                       \\transpose{\\delby{\\vect{x}}{\\vect{\\nu}}}\\delby{\\vect{x}}{\\vect{\\nu}}}=\n\t    \\frac{1}{2}(\\matr{C}-\\matr{I})\t       \n  \\label{eqn:greenstrain}\n\\end{equation}\n\n\\noindent and\n\n\\begin{equation}\n  \\vect{e}=\\frac{1}{2}\\bbrac{\\pbrac{\\delby{\\vect{x}}{\\vect{\\nu}}\\transpose{\\delby{\\vect{x}}{\\vect{\\nu}}}}^{-1}-\n                             \\pbrac{\\delby{\\vect{z}}{\\vect{\\nu}}\\transpose{\\delby{\\vect{z}}{\\vect{\\nu}}}}^{-1}}=\n\t\t\t     \\frac{1}{2}\\pbrac{\\matr{I}-\\matr{B}^{-1}}  \n  \\label{eqn:almansistrain}\n\\end{equation}\n\n\\noindent where $\\matr{E}$ and $\\vect{e}$ are called Green and Almansi strain tensors respectively. \nAlso note that $\\delby{\\vect{x}}{\\vect{\\nu}}$ is an orthogonal tensor. \\\\\n\nIt is now necessary to establish a relationship between strain and displacement. Referring to figure 1, \n\n\\begin{equation}\n  \\vect{z}=\\vect{x}+\\vect{u}\n  \\label{eqn:displacement}\n\\end{equation}\n\n\\noindent where \\vect{u} is the displacement vector. \\\\\n\n\\noindent Differentiating \\eqnref{eqn:displacement} using the chain rule,\n\n\\begin{equation}\n  \\delby{\\vect{z}}{\\vect{\\nu}}=\\delby{\\vect{x}}{\\vect{\\nu}}+\\delby{\\vect{u}}{\\vect{x}}\\delby{\\vect{x}}{\\vect{\\nu}}=\n                               \\pbrac{\\matr{I}+\\delby{\\vect{u}}{\\vect{x}}}\\delby{\\vect{x}}{\\vect{\\nu}}  \n  \\label{eqn:displacementgradient}\n\\end{equation}\n\n\\noindent Substituting \\eqnref{eqn:displacementgradient} into \\eqnref{eqn:greenstrain},\n\n\\begin{equation}\n  \\matr{E}=\\frac{1}{2}\\bbrac{\\transpose{\\delby{\\vect{x}}{\\vect{\\nu}}}\\transpose{\\pbrac{\\matr{I}+\\delby{\\vect{u}}{\\vect{x}}}}\n                  \\pbrac{\\matr{I}+\\delby{\\vect{u}}{\\vect{x}}}\\delby{\\vect{x}}{\\vect{\\nu}}-\\matr{I}}\n  \\label{eqn:greendisplacement1}\n\\end{equation}\n\n\\noindent Simplifying,\n\n\\begin{equation}\n  \\matr{E}=\\frac{1}{2}\\transpose{\\delby{\\vect{x}}{\\vect{\\nu}}}\n           \\pbrac{\\delby{\\vect{u}}{\\vect{x}}+\\transpose{\\delby{\\vect{u}}{\\vect{x}}}+\n\t   \\transpose{\\delby{\\vect{u}}{\\vect{x}}}\\delby{\\vect{u}}{\\vect{x}}}\n\t   \\delby{\\vect{x}}{\\vect{\\nu}}\n  \\label{eqn:greendisplacement2}\n\\end{equation}\n \nAs can be seen from \\eqnref{eqn:greendisplacement2} the displacement gradient\ntensor $\\delby{\\vect{u}}{\\vect{x}}$ is defined with respect to undeformed\ncoordinates $\\vect{x}$. This means that the strain tensor $\\matr{E}$ has\nLagrangian description and hence it is also also called the Green-Lagrange\nstrain tensor.\n \nA similar derivation can be employed to establish a relationship between the\nAlmansi and displacement gradient tensors and the final form is given by,\n\n\\begin{equation}\n  \\vect{e}=\\frac{1}{2}\\delby{\\vect{u}}{\\vect{z}}+\\transpose{\\delby{\\vect{u}}{\\vect{z}}}-\n\t   \\transpose{\\delby{\\vect{u}}{\\vect{z}}}\\delby{\\vect{u}}{\\vect{z}}\n  \\label{eqn:almansidisplacement}\n\\end{equation}\n \nThe displacement gradient tensor terms in \\eqnref{eqn:almansidisplacement} are defined with respect to deformed coordinates $\\vect{z}$ and\ntherefore the strain tensor has Eulerian description. Thus it is also known as the Almansi-Euler strain tensor.\n\n\\subsubsection{Energy Conjugacy}\n\n\n\n\\subsubsection{Constitutive models}\n\n\n\n\\subsubsection{Principle of Virtual Work}\nElastic potential energy or simply elastic energy associated with the\ndeformation can be given by strain and its energetically conjugate stress.\nNote that the Cauchy stress and Almansi-Euler strain tensors and Second\nPiola-Kirchhoff (2PK) and Green-Lagrange tensors are energetically\nconjugate. Thus, the \\textit{\\textbf{total internal energy}} due to strain in\nthe body at the deformed state (fig. 3.1) can be given by,\n \n\\begin{equation}\n  W_{int}=\\gint{0}{v}{(\\vect{e}:\\vect{\\sigma})}v\n  \\label{eqn:totalenergy}\n\\end{equation}\n\nwhere \\vect{e} and \\vect{\\sigma} are Almansi strain tensor and Cauchy stress\ntensor respectively.\n\nIf the deformed body is further deformed by introducing virtual displacements,\nthen the new internal elastic energy can be given by,\n\n\\begin{equation}\n  {W_{int}+\\delta W_{int}}=\\gint{0}{v}{[\\vect{(e+\\delta{e})}:\\vect{\\sigma}]}v\n  \\label{eqn:virtualtotalenergy}\n\\end{equation}\n\nDeducting \\eqnref{eqn:totalenergy} from \\eqnref{eqn:virtualtotalenergy},\n\n\\begin{equation}\n  \\delta W_{int}=\\gint{0}{v}{\\pbrac{\\vect{\\delta \\epsilon} : \\vect{\\sigma}}}v\n  \\label{eqn:virtualenergy}\n\\end{equation}\n\nUsing \\eqnref{eqn:almansidisplacement} for virtual strain,\n\n\\begin{equation}\n  \\vect{\\delta e}=\\delby{\\vect{\\delta u}}{\\vect{z}} + \\transpose{\\delby{\\vect{\\delta u}}{\\vect{z}}} + \n                  \\transpose{\\delby{\\vect{\\delta u}}{\\vect{z}}}\\delby{\\vect{\\delta u}}{\\vect{z}}\n  \\label{eqn:virtualalmansidisplacement}\n\\end{equation}\n\nSince virtual displacements are infinitesimally small, quadratic terms in\n\\eqnref{eqn:virtualalmansidisplacement} can be neglected.  The resulting\nstrain tensor, known as small strain tensor \\vect{\\epsilon}, can be given as,\n\n\\begin{equation}\n  \\vect{\\delta \\epsilon}=\\delby{\\vect{\\delta u}}{\\vect{z}} + \\transpose{\\delby{\\vect{\\delta u}}{\\vect{z}}} \n  \\label{eqn:virtualsmalldisplacement}\n\\end{equation}\n \nSince both $\\vect{\\sigma}$ and $\\vect{\\delta \\epsilon}$ are symmetric, new\nvectors are defined by inserting tensor components as follows,\n\n\\begin{equation}\n  \\vect{\\delta \\epsilon}=\\transpose{\\sqbrac{\\delta \\epsilon_{11} \\hspace{4 pt} \\delta \\epsilon_{22} \\hspace{4 pt} \\delta \\epsilon_{33} \n      \\hspace{4 pt} 2\\delta \\epsilon_{12} \\hspace{4 pt} 2\\delta \\epsilon_{23} \\hspace{4 pt} 2\\delta \\epsilon_{13}}} :\n  \\vect{\\sigma}=\\transpose{\\sqbrac{\\delta \\sigma_{11} \\hspace{4 pt} \\delta \\sigma_{22} \\hspace{4 pt} \\delta \\sigma_{33} \n      \\hspace{4 pt} 2\\delta \\sigma_{12} \\hspace{4 pt} 2\\delta \\sigma_{23} \\hspace{4 pt} 2\\delta \\sigma_{13} }}\t  \t\t  \n  \\label{eqn:newvectors}\n\\end{equation} \n\nSubstituting \\eqnref{eqn:newvectors} into \\eqnref{eqn:virtualenergy},\n\n\\begin{equation}\n  \\delta W_{int}=\\gint{0}{v}{\\pbrac{\\transpose{\\vect{\\delta \\epsilon}} \\vect{\\sigma}}}v\n  \\label{eqn:virtualenergy1}\n\\end{equation}\n\nThe strain vector $\\vect{\\delta \\epsilon}$ can be related to displacement\nvector using the following equation,\n\n\\begin{equation}\n  \\vect{\\delta \\epsilon}=\\matr{D} \\vect{\\delta u} \n  \\label{eqn:virtualsmalldisplacement1}\n\\end{equation}\n\n\\noindent where $\\matr{D}$ and $\\vect{u}$ are linear differential operator and\ndisplacement vector respectively and given by,\n\n\\begin{equation}\n  \\begin{array}{c} \\matr{D} \\end{array} =\n  \\pbrac{ \\begin{array}{ccc} \\delby{}{z_{1}} & 0 & 0 \\\\ \n      0 & \\delby{}{z_{2}} & 0 \\\\\n      0 & 0 & \\delby{}{z_{3}} \\\\\n      \\delby{}{z_{2}} & \\delby{}{z_{1}} & 0 \\\\ \n      0 & \\delby{}{z_{3}} & \\delby{}{z_{2}} \\\\ \n      \\delby{}{z_{3}} & 0 & \\delby{}{z_{1}} \\\\ \\end{array} }\n  \\label{eqn:differentialoperator}\n\\end{equation}\n\n\\begin{equation}\n  \\vect{\\delta u}=\\transpose{\\pbrac{\\delta u_{1} \\hspace{4 pt} \\delta u_{2} \\hspace{4 pt} \\delta u_{3}}}\n  \\label{eqn:displacementvector}\n\\end{equation}\n\nThe virtual displacement is a finite element field and hence the value at any\npoint can be obtained by interpolating nodal virtual displacements.\n\n\\begin{equation}\n  \\vect{\\delta u}=\\matr{\\Phi}\\matr{\\Delta}\n  \\label{eqn:interpolation}\n\\end{equation}\n\n", "meta": {"hexsha": "dbbe619d91e1d4b70e84fb727d27691fb7f158ba", "size": 39953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/opencmiss/utils/iron/doc/notes/EquationSets/ElasticityClass/FiniteElasticity.tex", "max_stars_repo_name": "tsalemink/opencmiss.utils", "max_stars_repo_head_hexsha": "c727d9b922330e3ca38967fa7dbe6480f698f9a2", "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/opencmiss/utils/iron/doc/notes/EquationSets/ElasticityClass/FiniteElasticity.tex", "max_issues_repo_name": "tsalemink/opencmiss.utils", "max_issues_repo_head_hexsha": "c727d9b922330e3ca38967fa7dbe6480f698f9a2", "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/opencmiss/utils/iron/doc/notes/EquationSets/ElasticityClass/FiniteElasticity.tex", "max_forks_repo_name": "tsalemink/opencmiss.utils", "max_forks_repo_head_hexsha": "c727d9b922330e3ca38967fa7dbe6480f698f9a2", "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.4527872582, "max_line_length": 179, "alphanum_fraction": 0.6828773809, "num_tokens": 14061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6519485018260958}}
{"text": "\\section{Methods}\n\nLet $\\mathbf{x} = (\\mathbf{x}_1, \\dots, \\mathbf{x}_t, \\dots, \\mathbf{x}_T)$ the observations and $\\mathbf{z} = (\\mathbf{z}_1, \\dots, \\mathbf{z}_t, \\dots, \\mathbf{z}_T)$ the corresponding latent embeddings, where $\\mathbf{x}_t \\in \\mathbb{R}^m$ and $\\mathbf{z}_t \\in \\mathbb{R}^n$.\n\nFollowing \\cite{Archer2016} we structure the inverse covariance $\\Sigma^{-1}$ of the approximate posterior $q(z|x) = \\mathcal{N}(\\mu_\\phi(x), \\Sigma_\\phi(x))$ to have a blog tri-diagonal structure.\n\n$$\n\\Sigma_\\phi(x)^{-1} = \\begin{bmatrix}\n  D_0 & B_0^T & & \\\\\n  B_0 & D_1 & B_1^T & \\\\\n   & \\ddots & \\ddots & B^T_{T-1} \\\\\n   & & B_{T-1} & D_T \\\\\n\\end{bmatrix}\n$$\n\nThis particular structure embodies that $z_t$ conditionally only depends on $z_{t-1}$ described by the precision matrix $B_0$.\n\nThe matrices $B$ correspond to the partial correlations of latent variables between adjacent time-points. We here propose to impose linear dynamics for transitions in latent space\n\n\\begin{align*}\n  \\mathbf{z}_t = A_t \\mathbf{z}_{t-1} \\\\\n\\end{align*}\n\nwhere $A_t = L \\Lambda_t L^{-1}$ is the dynamics matrix with eigenvector basis $L$ and eigenvalues $\\Lambda_t$ at time-point $t$. In particular, for factorized latent representations we set $L = I$. \n\nAllowing different eigenvalues for each time-point $t$ admits complex dynamics. We will later impose regularizing constraints on the variation of the eigenvalues across time-points.\n\nThe approximate posterior for a given time point $t$ is an isotropic Gaussian (following standard variational mean-field approximation), thereby reflecting the conditional independence assumption that $q(z_t|x_t) = \\prod_{i}^n q(z^{(i)}_t|x_t)$. We therefore set $D_t$ to I. [\\textit{unclear on that part}]\n\n\\subsection{Unconstrained Eigenvalues}\n\nIn the first case, eigenvalues of $A_t$ can change with every time-point and the mean and eigenvalues are parametrized by a neuronal network:\n\n\\begin{align*}\n    \\Lambda_t & = \\text{NN}_{\\phi_\\Lambda}(\\textbf{x}_t, \\textbf{x}_{t-1}) \\\\\n    \\mu_t & = \\text{NN}_{\\phi_\\mu}(\\textbf{x}_t) \\\\\n\\end{align*}\n\n\\subsection{Constraining dynamics}\n\n\\subsubsection{Slow dynamics}\n\nTo encourage slow dynamical changes in latent space (and therefore learning of slow changing/predictable features) wen can  constraint the transitional dynamics to be slow. In the first step we therefore add a regularizing term to the loss:\n\n\\begin{align*}\n    \\sum_0^{T-1} ||\\text{diag}(\\Lambda_t) - \\mathbf{1}||_1\n\\end{align*}\n\n\\subsubsection{Different dynamics for latents}\n\nInstead of applying the same regularization to all eigenvalues, we can instead specify a prior over eigenvalues. In particular, let $\\lambda^{(i)}_t$ be the eigenvalue corresponding to the $i$-th latent dimension for the transition from time-point $t$ to $t+1$. For instance, defining the regularizing loss as \n\n\\begin{align*}\n    \\sum_0^{T-1} \\sum_i^{n} \\gamma(i) |\\lambda^{(i)}_t - 1|\n\\end{align*}\n\nwhere the regularizing hyperparameter $\\gamma$ allows for different strengths of the 'slow' dynamics regularizer for each latent variable (e.g., $\\gamma(i) \\propto i$). (\\textit{this probably imposes an implicit prior on lambda - there is probably a better way to get this prior than just tuning the regularization.}).\n\n\\subsection{Future directions or additional parts}\nDepending on how well things go (and make sense), this can be the next steps:\n\\subsubsection{Allowing for interactions in latent space}\n\nSome generative factors can only be expressed in more than one dimension (e.g. angle of rotation of an object). The diagonal construction of A might therefore be to constrained.\n\nHence, the idea would be to relax $A$ to deviate from diagonal, hence $A_t = \\text{NN}(\\mathbf{x_t})$ thereby allowing for interactions in latent space, while still regularizing:\n\n\\begin{align*}\n    \\sum_0^{T-1} ||A_t - I||_1\n\\end{align*}\n\n\\subsubsection{Enforcing low-dimensional subspaces}\n\nWhat we actually want (instead of having an A matrix that has small deviations from an identity matrix) are small subspaces (i.e., small Jordan blocks in the Jordan decomposition of A). Therefore, this step would try to actually enforce this constraint directly.\n\n\\subsection{Assessment of disentanglement}\n\n\\subsubsection{Qualitative}\n\n\\begin{itemize}\n\\item Are two generative objects (i.e., an object vs. the background) that change with different dynamics captured in different latent dimensions? \n\\item Can we recover bimodal distributions of learned eigenvalues?\n\\end{itemize}\n\n\\subsection{Quantitative}\n\nUsing established metrics, we will compare the disentanglement of latent representations across the different model variants as well as with established models in the literature.\n\nmissing part: construcing the full covariance matrix from", "meta": {"hexsha": "d06b4f32c40aff3906a1bcf3d122ae4858bb8151", "size": 4751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/methods.tex", "max_stars_repo_name": "zahariaa/disentangled-dynamics", "max_stars_repo_head_hexsha": "2dbdf9884f6f90ff67073f571191227e7abce81d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/methods.tex", "max_issues_repo_name": "zahariaa/disentangled-dynamics", "max_issues_repo_head_hexsha": "2dbdf9884f6f90ff67073f571191227e7abce81d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/methods.tex", "max_forks_repo_name": "zahariaa/disentangled-dynamics", "max_forks_repo_head_hexsha": "2dbdf9884f6f90ff67073f571191227e7abce81d", "max_forks_repo_licenses": ["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.9886363636, "max_line_length": 318, "alphanum_fraction": 0.7472111134, "num_tokens": 1279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6519464569765024}}
{"text": "%\n% 404\n%\n\\chapter{Mathieu Functions}\n\\Section{19}{1}{The differential equation of Mathieu.}\n\nThe preceding five chapters have been occupied with the discussion of\nfunctions which belong to what may be generally described as the\nhyper- geometric type, and many simple properties of these functions\nare now well known.\n\nIn the present chapter we enter upon a region of Analysis which lies\nbeyond this, and which is, as yet, only very imperfectly explored.\n\nThe functions which occur in Mathematical Physics and which come next\nin order of complication to functions of hypergeometric type are\ncalled Mathieu functions; these functions are also known as the\nfunctions associated ivith the elliptic cylinder. They arise from the\nequation of two- dimensional wave motion, namely\n\ndx dy c- dt'\n\nThis partial difterential equation occurs in the theory of the\npropagation of electro- magnetic waves; if the electric vector in the\nwave-front is parallel to OZ and if E denotes the electric force,\nwhile Hx, ffy, 0) are the components of magnetic force, Maxwell's\nfundamental equations are\n\nlo \\ 8 \\ a c\\ H \\ \\ dE dHy\\ dE <? dt ~ dx ly ' at ~ dij ct ~ dx '\n\nc denoting the velocity of light; and these equations give at once\n\nc ct cx' cy' '\n\nIn the case of the scattering of waves, propagated parallel to OX,\nincident on an elliptic cylinder for which OX and OY are axes of a\npi-incipal section, the boundary condition is that E should vanish at\nthe surface of the cylinder.\n\nThe same partial differential equation occurs in connexion with the\nvibrations of a uniform plane membrane, the dependent variable being\nthe displacement perpendiculai- to the membrane; if the membrane be\nin the shape of an ellipse with a rigid boundary, the boundary\ncondition is the same as in the electromagnetic problem just\ndiscussed.\n\nThe differential equation was discussed by Mathieu* in 1868 in\nconnexion with the problem of vibrations of an elliptic membrane in\nthe following manner :\n\n* Journal de Math. (2), xiii. (1868), p. 137.\n\n%\n% 405\n%\n\nSuppose that the membrane, which is in the plane XOY when it is\n\nin equilibrium, is vibrating with frequency p. Then, if we write\n\nV= u (cc, y) cos pt + e),\n\nthe equation becomes\n\nd' u d u p- -, + -, + li = 0. cw dy c-\n\nLet the foci of the elliptic membrane be (+ h, 0, 0), and introduce\nnew\n\nreal variables*, i] defined by the complex equation\n\ncc + iy = h cosh ( + irj),\n\nso that x = h cosh cos t, y = h sinh | sin r].\n\nThe curves, on which or r] is constant, are evidently ellipses or\nhyper- bolas confocal with the boundary; if we take and - tt < ?? \\$\ntt, to each point (w, y, 0) of the plane corresponds one and only onef\nvalue of (, ??).\n\nThe differential equation for u transforms into;]:\n\naf-2 + a + - (cosh- f - cos- 7?) u = 0.\n\nIf we assume a solution of this equation of the form\n\nu = F )G v), where the factors are functions of only and of t) only\nrespectively, we see that\n\n1 d'J(g) Ay )\\ ( 1 d'GM i jf\n\nSince the left-hand side contains but not ? while the right-hand side\ncontains ri but not, F ) and G (tj) must be such that each side is a\nconstant, A, say, since | and tj are independent variables.\n\nWe thus arrive at the equations\n\n ) + ('i!£%osl.f- )l-(f) = 0,\n\nBy a slight change of independent variable in the former equation, we\nsee that both of these equations are linear differential equations, of\nthe second order, of the form\n\n-T-; -f (a -1- 1 65 cos 2z) u = 0,\n\n* The iutroduction of these variables is due to Lame, who called the\nthermometric parameter. They are more usually known as confocal\ncoordinates. See Lame, Sur les fonctions inverses des transcendantes,\n1'\"'' Le(?on.\n\n+ This may be seen most easily by considering the ellipses obtained by\ngiving f various positive values. If the ellipse be drawn through a\ndefinite point (t, v) ot the plane, r? is the eccentric angle of that\npoint on the ellipse.\n\nt A proof of this result, due to Lame, is given in numerous text-books\n; see p. 401, footnote.\n\n%\n% 406\n%\n\nwhere a and q are constants*. It is obvious that every point (infinity\nex- cepted) is a regular point of this equation.\n\nThis is the equation which is known as Jfathieu's equation and, in\ncertain circumstances \\hardsectionref{19}{2}), particular solutions of it are called\nMathieu functions.\n\n1911. The form of the solution of Mathieu s equation.\n\nIn the physical problems which suggested Mathieu's equation, the\nconstant a is not given a priori, and we have to consider how it is to\nbe determined. It is obvious from physical considerations in the\nproblem of the membrane that u (x, y) is a one-valued function of j\nosition, and is consequently unaltered by increasing 77 by 27r; and\nthe condition f G (r) + lif) = G rj) is sufficient to determine a set\nof values of a, in terms of q. And it will appear later (§§ 19'4,\n19*41) that, when a has not one of these values, the equation\n\nG 'n + 2'rr)=G (v) is no longer true.\n\nWhen a is thus determined, q (and thence p) is determined by the fact\nthat F ) = on the boundary; and so the periods of the free vibrations\nof the membrane are obtained.\n\nOther problems of Mathematical Phy.sics which involve Mathieu\nfunctions in their solution are (i) Tidal waves in a cylindrical\nvessel with an elliptic boundary, (ii) Certain forms of steady vortex\nmotion in an elliptic cylinder, (iii) The decay of magnetic force in a\nmetal cylinder . The equation also occurs in a problem of Rigid\nDynamics which is of general interest g.\n\n\\Subsection{19}{1}{2}{Hill's equation.}\n\nA differential equation, similar to Mathieu's but of a more general\nnature, arises in G. W. HiU's]] method of determining the motion of\nthe Lunar Perigee, and in Adams' determination of the motion of the\nLunar Node. Hill's equation is\n\n ' + k + 2 i cos2 ) = 0.\n\nThe theory of Hill's equation is very similar to that of Mathieu's (in\nspite of the increase in generality due to the presence of the\ninfinite series), so the two equations will, to some extent, be\nconsidered together.\n\n* Their actual values are a = A - h-p-l 2c-), q = h-2)-l(S2c-); the\nfactor 16 is inserted to avoid powers of 2 in the solution.\n\nt An elementary analogue of this result is that a solution of -j- +aii\n= has period 2v if,\n\nand only if, a is the square of an integer.\n\n* K. C. Maclaurin, Trans. Camb. Phil. Soc. xvii. p. 41.\n\n§ A. W. Young, Proc. Edinburgh Math. Soc. xxxii. p. 81.\n\nII Acta Math. viii. (1S86). Hill's memoir was originally published in\n1877 at Cambridge, U.S.A.\n\nH Monthly Notices R.A.S. xxxviii. p. 43.\n\n%\n% 407\n%\n\nIn the astronomical applications o> i>  are known constants, so the\nproblem of choosing them in such a way that the solution may be\nperiodic does not arise. The solution of Hill's equation in the Lunar\nTheory is, in fact, not periodic.\n\n\\Section{19}{2}{Periodic solutions of Mathieu's equation.}\n\nWe have seen that in physical (as distinguished from astronomical)\nproblems the constant a in Mathieu's equation has to be chosen to be\nsuch a function of q that the equation possesses a periodic solution.\n\nLet this solution be G (z); then G z), in addition to being periodic,\nis an integral function of z. Three possibilities arise as to the\nnature of G z) : (i) G (z) may be an even function of z, (ii) G z) may\nbe an odd function of z, (iii) G (z) may be neither even nor odd.\n\nIn case (iii), G (z) + G - z)]\n\nis an even periodic solution and\n\n  G z)-G -z)]\n\nis an odd periodic solution of Mathieu's equation, these two solutions\nforming a fundamental system. It is therefore sufficient to confine\nour attention to periodic solutions of Mathieu's equation which are\neither even or odd. These solutions, and these only, will be called 31\nathieu functions.\n\nIt will be observed that, suice the roots of the indicial equation at\nz = are and 1, two even (or two odd) periodic solutions of Mathieu's\nequation cannot form a fundamental system. But, so far, there seems to\nbe no reason why Mathieu's equation, for special values of a and q,\nshould not have one even and one odd periodic solution; for com-\nparatively small values of 1 5' ' it can be seen \\hardsectionref{19}{3} example 2,\n(ii) and (iii)] that Mathieu's equation has two periodic solutions\nonly in the trivial case in which q = 0; but for larger values o \\ q\\\nthere may be pairs of periodic solutions, though no such pairs have,\nas yet, been discovered.\n\n\\Subsection{19}{2}{1}{An integral equation satisfied by even Mathieu functions*.}\n\nIt will now be shewn that, if G r ) is any even Mathieu function, then\nG(r)) satisfies the homogeneous integral equation\n\nG(v)=-\\ [\" e'''°' '''' G(e)dO,\n\nwhere k = \\/(32 ). This result is suggested by the solution of\nLaplace's equation given in \\hardsubsectionref{1}{8}{3}.\n\n* This integral equation and the expansions of \\hardsectionref{19}{3} were published\nby Wbittaker, Proc. Int. Congress of Math. 1912. The integral equation\nwas known to him as early as 1904; see Trans. Camb. Phil. Soc. xxi.\n(1912), p. 193.\n\n%\n% 408\n%\n\nFor, if A' + i/ = h cosh, i +iri) and if F ) and G (v) are solutions\nof the differential equations\n\n d - ( + f cosh I) F( ) = 0, ( '\\ M + (A + nvJf- cos- 7;) G v) = 0,\n\nthen, by § 191, F ) G rj) e\" is a particular solution of Laplace's\nequation. If this solution is a special case of the general solution\n\n/(// cosh cos 77 cos + h sinh sin 7; sin 6 + iz, 6) dO,\n\ngiven in \\hardsectionref{18}{3}, it is natural to expect that*\n\nf(v,e) F 0)e' '<f>(e), where <f> (6) is a function of 6 to be\ndetermined. Thus\n\nF )G (v) e\"\"' =1 F(0)(f) (6) exp mh cosh cos v cos 6\n\n. -IT\n\n+ mh sinh sin rjsmO + miz] dd.\n\nSince and tj are independent, we may put = 0; and we are thus led to\nconsider the possibility of Mathieu's equation possessing a solution\nof the form\n\nJ -77\n\n\\Subsection{19}{2}{2}{Proof that the even Mathieu functions satisfy the integral equation.}\n\nIt is readily verified \\hardsubsectionref{5}{3}{1}) that, if (f> (6) be analytic in the\nrange (- tt, tt) and if 6 (7;) be defined by the equation\n\nG (77) = I \" e'\"'' cosncose ( ) 0\n\nthen G (77) is an even periodic integral function of 7; and\n\n- j- + (A + m-h- cos- 7;) G (7;) drf-\n\n= [\" ?u-/(2 (sin- 77 cos- + cos 77) - mh cos 77 cos + g'\"'' cos >,\ncose ( q\n\nJ - TV\n\n= - n H/i sin e cos 77</) ( ) + </)' 6)] e' ''cos cos6\n\n < \" (6') + ( + ni'h'' cos' ) (/) ( ) e\"'''cos.,cosfl /\n\non integrating by parts.\n\n* The constant F (0) is inserted to simplify the algebra.\n\n%\n% 409\n%\n\nBut if(f) 6) be a ])eriodic function ivith period 27r) such that (f)\"\n(6) + A+ m h- cos 6) </> 6) = 0,\n\nboth the integral and the integrated part vanish; that is to say, G\n(rj), defined by the integral, is a periodic sohition of Mathieu's\nequation.\n\nConsequently G (tj) is an even periodic solution of Mathieu's equation\nif <f) (0) is a periodic solution of Mathieu's equation formed with\nthe same con- stants; and therefore (ft (6) is a constant multiple of\nG (6); let it be \\ G(6).\n\n[In the case when the Mathieu equation has two periodic sokitions, if\nthis case exist, we have (p d) = XG (d) + Gi 6) where 6-'i 6) is an\nodd periodic function; but\n\n mh cosv cos eg g\n\nr\n\nvanishes, so the subsequent work is unaffected.]\n\nIf we take a and q as the parameters of the Mathieu equation instead\nof A and mh, it is obvious that mh = \\/ S2q) = k.\n\nWe have thus proved that, if G 'r]) be an even periodic solution of\nMathieu's equation, then\n\nG r]) = \\ r e''-' ' °' G(0)de,\n\nwhich is the result stated in \\hardsubsectionref{19}{2}{1}.\n\nFrom § 11 \"23, it is known that this integral equation has a solution\nonly when X has one of the ' characteristic values.' It will be shewn\nin \\hardsectionref{19}{3} that for such values of \\, the integral equation affords a\nsimple means of con- structing the even Mathieu functions.\n\nExample 1. Shew that the odd Mathieu functions satisfy the integral\nequation\n\nG i]) = \\ j sin (/ sin r] sin 6) G (d) dd.\n\nExample 2. Shew that both the even and the odd Mathieu functions\nsatisfy the integral equation\n\nG,j) = x[\" e ''''''' G d)de.\n\nExample 3. Shew that when the eccentricity of the fundamental ellipse\ntends to zero, the confluent form of the integral equation for the\neven Mathieu functions is\n\nJ,,(.r) = /\" e'-*' cose cos\n\nZTTi\" j -\n\nd6.\n\n\\Section{19}{3}{The construction of Mathieu functions.}\n\nWe shall now make use of the integral equation of \\hardsubsectionref{19}{2}{1} to construct\nMathieu functions; the canonical form of Mathieu's equation will be\ntaken as\n\n-T 4- (o + 1 6g cos z) u = 0.\n\n%\n% 410\n%\n\nIn the special case when q is zero, the periodic sohitions are\nobtained by taking a= n-, where n is any integer; the solutions are\nthen\n\n1, cos ', cos 22, ...,\n\nsin z, sin z,\n\nThe Mathieu functions, which reduce to these when q- 0, will be called\nceo z, q), cei (z, q), ce. z, q), . . ., se?! z, q), seo (z, q), ....\nTo make the functions precise, we take the coefficients of cos nz and\nsin nz in the respective Fourier series for ce z, q) and sen z, q) to\nbe unity. The functions cen z, q), sen i, Q) will be called Mathie it\nfunctions of oixler n. Let us now construct ce (z, q).\n\nSince ceo(3', 0)=1, we see that A,-*.(27r)~ as (y --* 0. Accordingly\nwe suppose that, for general values of q, the characteristic value of\nX which gives rise to ce z, q) can be expanded in the form\n\n(27r ) -i = 1 + ttig + Oioq- + . . ., and that ce (z, q) = l+ q i z)\n+ q- o ( ) + . . .,\n\nwhere Oj, Oo, ... are numerical constants and x z), 13.2 (z), ... are\nperiodic functions of z which are independent of q and which contain\nno constant term.\n\nOn substituting in the integral equation, we find that\n\n(1 + oc,q+a,q- + ...) l+q/3, (z) -i-q', z) + ...\n\n1 T\" = - / (1 + \\/(32g) . cos cos + 16r/cos- 'cos- + ...\n\nEquating coefficients of successive powers of q in this result and\nmaking use of the fact that i(z), /SjC ),,. .. contain no constant\nterm, we find in succession\n\nOj = 4, /3i (z) = 4 cos 2z,\n\noTo = 14, /Sa (z) = 2 cos 4,\n\nand we thus obtain the following expansion :\n\n/ -77 29 \\ / 160 N\n\ncco (z, q) = l + Uq - 28q + \"- q' - ...jcos2z + i2q-- ~ q + ...j cos\n4iz\n\n+ U'f-' 5' +  ) cos 6z + ( - r/ - . . . j cos 8\n\nthe terms not written down being (q ) as -* 0.\n\n210 99 The value of a is -S2q- + 224>q' l f/+0(r/); it will be\nobserved\n\nthat the coefficient of cos 2z in the series for C6?o(2, q) is\n-ai(8q).\n\n%\n% 411\n%\n\nThe Mathieu functions of higher order may be obtained in a similar\nmanner from the same integral equation and from the integral equation\nof \\hardsubsectionref{19}{2}{2} example 1. The consideration of the convergence of the\nseries thus obtained is postponed to \\hardsubsectionref{19}{6}{1}.\n\nExample 1. Obtain the following expansions*:\n\n(i) ce, (., s, \\ 1 +, J\\ -. ~ \\ y i ~ + (,/  .) CO, 2..,\n\noc I\" gV ' r+l qr + l\n\n(n) cei(2, o) = cos5+ 2 \\ \\ - r ~ /, i m / \"ttv. r=i i(?'+l)!?*! (r +\n1)! (r+1)!\n\n(ni) TODO\n\n(iv) TODO\n\nwhere, in each case, the constant implied in the symbol depends on r\nbut not on z.\n\n\\addexamplecitation{Whittaker.}\n\nExample 2. Shew that the values of a associated with (i) ceo(5, </),\n(ii) cei z, q), (iii) sfij (2, 5'), (iv) ce2 z, q) are respectively :\n\n210 2Q (i) -32(?2 + 224(?4 \\ \\, 6 + ((? ),\n\n(ii) l-8q- + -\\ qi + 0 q%\n\n(iii) l + 8j-8j2\\ 823- <?* + 0(j5\n\n(iv) 4 + j2- g* + 0(? ). \\addexamplecitation{Mathieu.}\n\nExample 3. Shew that, if n be an integer,\n\n\\Subsection{19}{3}{1}{The integral formulae for the Mathieu functions.}\n\nSince all the Mathieu functions satisfy a homogeneous integral\nequation with a symmetrical nucleus \\hardsubsectionref{19}{2}{2} example 3), it follows (§\n11'61) that\n\ncem z, q) cen (z, q)dz = (m n),\n\n.' - jr\n\nsem (z, q) sen (z, q)dz = m i= n)\n\nT\n\ncem z, q) sen (z, q)dz = 0.\n\nT\n\n* The leading terms of these series, as given in example 4 at the end\nof the chapter (p. 427), were obtained by Mathieu.\n\n%\n% 412\n%\n\nExample 1. Obtain expansions of the form :\n\n(ii) cos (/ sin z sin ) = 2 B ce (z, q) ce 6, q),\n\n?l=0\n\n(iii) sin (/ sin z sin 6)= 2 C se (2, q) se 6, q), where i=, 32q).\n\nExample 2. Obtain the expansion\n\n)! = - 3C\n\nas a confluent form of expansions (ii) and (iii) of example 1.\n\n\\Section{19}{4}{The nature of the solution of Mathieu s general equation; Floquet's theory.}\n\nWe shall now discuss the nature of the solution of Mathieu's equation\nwhen the parameter a is no longer restricted so as to give rise to\nperiodic solutions; this is the case which is of importance in\nastronomical problems, as distinguished from other ph -sical\napplications of the theory.\n\nThe method is applicable to any linear equation with periodic\ncoefficients which are one-valued functions of the independent\nvariable; the nature of the general solution of particular equations\nof this type has long been per- ceived by astronomers, by inference\nfrom the circumstances in which the equations arise. These inferences\nhave been confirmed by the following analytical investigation which\nwas published in 1883 by Floquet*.\n\nLet g z), h (z) be a fundamental system of solutions of Mathieu's\nequation (or, indeed, of any linear equation in which the coefficients\nhave period 27r); then, if F(z) be any other integral of such an\nequation, we must have\n\nF z)=Ag(z)+Bh(z), where A and B are definite constants.\n\nSince g z+ 27r), h (z -f 27r) are obviously solutions of the\nequationf, they can be expressed in terms of the continuations of g\n(z) and Ji (z) by equations of the type\n\ng(z + 27r) = a g (z) + a,h (z), h z Itt) =,g z) + 0,h (z), where ttj,\na.>, /S, /?.\\ > are definite constants; and then\n\nF z + 27r) = (Aa + B,) g z) + Aoi., + B/3,) h (z).\n\n* Ann. de VEcole norm. sitj). (2), xii. (1883), p. 47. Floquet's\nanalysis is a natural sequel to Picard's theory of differential\nequations with doubly-periodic coefficients \\hardsectionref{20}{1}), and to the\ntheory of the fundamental equation due to Fuchs and Hamburger.\n\nt These solutions may not be identical with (j(z), h(z) respectively,\nas the solution of an equation with periodic coefficients is not\nnecessarily periodic. To take a simple case, H = e sin z\n\nis a solution of -r - (1 + cot ) 1/ = 0.\n\ndz '\n\n%\n% 413\n%\n\nConsequently F z + 27r)= kF(z), where k is a constant*, if A and B are\nchosen so that\n\nA a, + BI3, = hA, A a, + B/3o = kB.\n\nThese equations will have a solution, other than A = B = 0, if, and\nonly if,\n\noc,-k, A =0;\n\nofo, /5o - A.-\n\nand i k be taken to be either root of this equation, the function F(2)\ncan be constructed so as to be a solution of the differential equation\nsuch that\n\nF(z+27r) = kF(z).\n\nDefining fi by the equation k= e-'\" and writing ( z) for e~' F z), we\nsee that\n\n(f>(z + 27r) = €-''''+-''> F z+-2tt)=( (z).\n\nHence the differential equation has a particular solution of the form\ne' (f) z), where (f)(z) is a periodic function with period 27r.\n\nWe have seen that in physical problems, the jjarameters involved in\nthe differential equation have to be so chosen that k = l is a root of\nthe quadratic, and a solution is periodic. In general, however, in\nastronomical problems, in which the parameters are given, A- 1 and\nthere is no periodic solution.\n\nIn the particular case of Mathieu's general equation or Hill's\nequation, a fundamental system of solutions f is then e' -(f)(z), e~>\n-z), since the equation is unaltered by writing - r for; so that the\ncomplete solution of Mathieu's general equation is then\n\nu = Cie'*-(f) z) + Coe~i ( (- z),\n\nwhere Ci, c, are arbitrary constants, and /i is a definite function of\na and q.\n\nExample. Shew that the roots of the equation\n\na,-k,,3i =0 ao, )io - k are independent of the particular pair of\nsolutions, g z) and h (z), chosen.\n\n\\Subsection{19}{4}{1}{Hill's method of solution.}\n\nNow that the general functional character of the solution of equations\nwith periodic coefficients has been found by Floquet's theory, it\nmight be expected that the determination of an explicit expression for\nthe solutions of Mathieu's and Hill's equations would be a\ncomparatively easy matter; this however is not the case. For example,\nin the particular case of Mathieu's general equation, a solution has\nto be obtained in the form\n\ny = e (f) (z),\n\n* The symbol k is used in this particular sense only in this section.\nIt must not be confused with the constant A; of \\hardsubsectionref{19}{2}{1}, which was\nassociated with the parameter q of Mathieu's equation. t The ratio of\nthese solutions is not even periodic; still less is it a constant.\n\n%\n% 414\n%\n\nwhere <f) (z) is periodic and /i is a function of the parameters a and\nq. The crux of the problem is to determine /j.; when this is done,\nthe determination of (f) (2) presents comparatively little difficulty.\n\nThe first successful method of attacking the problem was published by\nHill in the memoir cited in \\hardsubsectionref{19}{1}{2}; since the method for Hill's\nequation is no more difficult than for the special case of Mathieu's\ngeneral equation, we shall discuss the case of Hill's equation, viz.\n\nwhere J (z) is an even function of z with period tt. Two cases are of\ninterest, the analysis being the same in each :\n\n(I) The astronomical case when z is real and, for real values of z, J\n(z) can be expanded in the form\n\nJ(z) = 00 + 2 1 cos 2z + 202 cos 4>z + 26 cos 6 + . . .; the\ncoefficients 6n are known constants and S 6n converges absolutely.\n\nn=0\n\n(II) The case when is a complex variable and J (2) is analytic in a\nstrip of the plane (containing the real axis), whose sides are\nparallel to the\n\nreal axis. The expansion of J(z) in the Fourier series 6 + 2 \"Z 6n cos\n2nz\n\nH = l\n\nis then valid \\hardsubsectionref{9}{1}{1}) throughout the interior of the strip, and, as\nbefore,\n\n00\n\n2 On converges absolutely. =o\n\nDefining \\ to be equal to 6n, we assume\n\n00\n\n71= -OC\n\nas a solution of Hill's equation.\n\n[In case (II) this is the solution analytic in the strip (§> 10-2,\n19'4); in case (I) it will have to be shewn ultimately (see the note\nat the end of \\hardsubsectionref{19}{4}{2}) that the values of 6\n\nwhich will be determined are such as to make 2 n-bn absolutely\nconvergent, in order to\n\nn= -\n\njustify the processes which we shall now carry out.] On substitution\nin the equation, we find\n\nM=- 00 \\ n=-x / j=- 00 /\n\nMultiplying out the absolutely convergent series and equating\ncoefficients of powers of e ' to zero (§§ 9\"6-9\"632), we obtain the\nsystem of equations\n\n(,i + 2niyb + i e X\\,, = (n = ..., -2,-1,0,1,2, ...).\n\n%\n% 415\n%\n\nIf we eliminate the coefficients bn determinantally (after dividing\nthe typical equation by 6o - 4 n\" to secure convergence) we obtain*\nHill's deter- minantal equation :\n\n( >+4) -\n\nio\n\n- >\n\n-00\n\n-0, 42- 0\n\n-0,\n\n- 4 -0,\n\n4- 0\n\n4- -00\n\n42- 0 \"'\n\n-e.\n\n0> + 2)2-, 2- -00\n\n-0,\n\n 2' -Bo\n\n-02\n\n2- -00\n\n- 3\n\n'\" 22-,,\n\n2- -00 -\n\n-Oo\n\n-6,\n\nW-do\n\n02 -do\n\n-0, 0- -00\n\n-do\n\n  02 -. 0\n\n0- - 6 0\n\n02 -do -\n\n-03\n\n-6-2 22- 0\n\n-0\n\n22 - o\n\n(z>-2)2- 22- 0\n\n00\n\n-01\n\n\" 2 -60\n\n22- do -\n\n-0,\n\n- 3\n\n42-,,\n\n-02\n\ni--0o\n\n- 1 42- 0\n\n ±\n\n-4)2 -do 42 -do -\n\n=0.\n\nWe write A ifx) for the determinant, so the equation determining yu.\nis\n\nA (i = 0.\n\n\\Subsection{19}{4}{2}{The evaluation of Hill's determinant.}\n\nWe shall now obtain an extremely simple expression for Hill's deter-\nminant, namely\n\nA iix) = A (0) - sin- ( tti/x) cosec- (|-7r V o)-\n\nAdopting the notation of \\hardsectionref{2}{8}, we write\n\nA(i =[,,,J, (t'/i - 2m)- - Oq\n\nwhere,, j =\n\n4?7i- - dr,\n\nA m-n\n\n4m2 - 0Q\n\n(m n).\n\nThe determinant [,,ii] is only conditionally convergent, since the\nproduct of the principal diagonal elements does not converge\nabsolutely (§§ 2\"81, 2'7). We can, however, obtain an absolutely\nconvergent determinant, Aj (i/x), by dividing the linear equations of \\hardsubsectionref{19}{4}{1} by 6q- (i/x- 2n)- instead of dividing by (, - 4/1-. We write\nthis determinant Ai(2ju,) in the form [5, \\ ], where\n\n  m,ra - -) - j/i, n - /.\n\n-Or.\n\n(m n).\n\n 2in - i/x)-- Hf)\n\nThe absolute convergence of S 6,1 secures the convergence of the\ndeter-\n\nminant [-S,, ], except when /x has such a value that the denominator\nof one of the expressions B n vanishes.\n\n* Since the coefl\\&cients 6,j are not all zero, we may obtain the\ninfinite determinant as the eliminant of the system of linear\nequations by multiplying these equations by suitably chosen cofactors\nand adding up.\n\n%\n% 416\n%\n\nFrom the definition of an infinite determinant \\hardsectionref{2}{8}) it follows that\n\nsin TT (?> - V o) sin tt (i> + \\/Oo) and so A (i ) = - A, (i ) -\nsmM*7rV ) '\n\nNow, if the determinant A, i/j,) be written out in full, it is easy to\nsee (i) that Ai (ifi) is an even periodic function of /x with period\n2tV(ii) that Aj / ) is an analytic function (cf. §§ 2'81, 8\"34, 5'3)\nof yu, (except at its obvious simple poles), which tends to unity as\nthe real part of /j, tends to ± oo .\n\nIf now we choose the constant K so that the function D (/a), defined\nby the equation\n\nD (ijl) = Ai (i\"/u.) - K [cot ir ifi, + \\/0(,) - cot i TT (ifj, - V o)\n,\n\nhas no pole at the point ij, = i 6, then, since D /j,) is an even\nperiodic function of yu., it follows that D (/x) has no pole at any of\nthe points\n\n2ni ± i V o) where n is any integer.\n\nThe function D (/j.) is therefore a periodic function of /n (with\nperiod 2 ) which has no poles, and which is obviously bounded as R\n(//.) + x . The conditions postulated in Liouville's theorem \\hardsubsectionref{5}{6}{3})\nare satisfied, and so D (fi) is a constant; making / - + go, we see\nthat this constant is unity.\n\nTherefore\n\nAi (ifi) = 1+K cot Itt ifi + \\/d,) - cot -h TT ifi - V(9o), and so\n\nsinl7r(t>- V o)sin 7r(i>+\\/ o), o7- wi ia\\ A rfi) = sinM -V o) \" - '\n'\"' \" \" -\n\nTo determine K, put /a =; then\n\nA(0) = l + 2/i:cot(i7rv/ o)- Hence, on subtraction,\n\nA(, = MO)-| li\n\nwhich is the result stated.\n\nThe roots of Hill's determinantal equation are therefore the roots of\nthe equation\n\nsin -nifi) = A (0) . sin ( tt V o)-\n\nWhen fj, has thus been determined, the coefficients bn can be\ndetermined in terms of b, and cofactors of A ifi); and the solution\nof Hill's differential equation is complete.\n\n%\n% 417\n%\n\n[In case (I) of \\hardsubsectionref{19}{4}{1}, the convergence of 2 | 6 | follows from the\nrearrangement theorem of \\hardsubsectionref{2}{8}{2}; for 2 2 1 6 | is equal to | 6o | 2 |\nC j, o I - i o, o I where C, n is the cofactor of B,\n\nni= - x>\n\nin Ai (ifi.)', and 2 | C i,o I is the determinant obtained by\nreplacing the elements of the row through the origin by numbers whose\nmoduli are bounded.]\n\nIt was shewn by Hill that, for the purposes of his astronomical\nproblem, a remarkably good approximation to the value of fj. could be\nobtained by considering only the three central rows and columns of his\ndeterminant.\n\n\\Section{19}{5}{The Lindemann-Stieltjes' theory of Mathieu's general equation.}\n\nUp to the present, Mathieu's equation has been treated as a linear\ndifferential equation with periodic coefficients. Some extremely\ninteresting properties of the equation have been obtained by\nLindemann* by the sub- stitution =cos, Avhich transforms the equation\ninto an equation with rational coefficients, namely\n\n4 (1 - O, + 2 (1 - 20 + (a -I6q + 32 0 = 0.\n\nThis equation, though it somewhat resembles the hypergeometric\nequation, is of higher type than the equations dealt with in Chapters\nxiv and xvi, inasmuch as it has two regular singularities at and 1 and\nan irregular singularity at x; whereas the three singularities of the\nhypergeometric equation are all regular, while tlie equation for TFj.\\\n(3) has one irregular singularity and only one regular singularity.\n\nWe shall now give a short account of Linderaann's analysis, with some\nmodifications due to Stieltjesf.\n\n\\Subsection{19}{5}{1}{Lindemann' s form of Floquet's theorem.}\n\nSince Mathieu's equation (in Lindemann's form) has singularities at =\nand = 1, the exponents at each being 0, \\, there exist solutions of\nthe form\n\nW=0 M=0\n\n2 o = i an (1 - y\\ u = (1 - 0* i n (1 - KT;\n\n>i = M =\n\nthe first two series converge when ] j < 1, the last two when 1 1 - |\n< 1.\n\nWhen the -plane is cut along the real axis from 1 to + x and from to -\n00, the four functions defined by these series are one-valued in the\ncut plane; and so relations of the form\n\nVw = ay 00 + Voi, Vn = 73/00 + i/oi will exist throughout the cut\nplane.\n\nNow suppose that describes a closed circuit round the origin, so that\nthe circuit crosses the cut from - oo to; the analytic continuation\nof 3/10 is\n\n* Math. Ann. xxii. (1883), p. 117.\n\nt Astr. Nach. cix. (1884), cols. 145-152, 261-266. The analysis is\nvery similar to that employed by Hermite in his lectures at the Ecole\nPolytechnique in 1872-1873 [Oeuvres, iii. (Paris, 1912), pp. 118-122]\nin connexion with Lame's equation. See \\hardsectionref{23}{7}.\n\nW. M. A. 27\n\n%\n% 418\n%\n\noj/oo - /3yoi (since l/ is unaffected by the description of the\ncircuit, but ?/oi changes sign) and the continuation of j/u is 7 00 -\nj/oi; \"c? so Ay - + By - will he unaffected by the description of the\ncircuit if\n\nA ay,o + ySyoi)' + B yy + SyoO' s A ay - /3?/oi)' + B (73/00 - S oi)-,\n\ni.e. if Aa + ByS = 0.\n\nAlso Ay f-h Byii- obviously has not a branch-point at f=l, and so, if\nAal3 + By8 - 0, this function has no branch-points at or 1, and, as it\nhas no other possible singularities in the finite part of the plane,\nit must be an integral function of .\n\nThe two expressions\n\nA y,o + iB -yn, -j/io - iB 'l/u are consequently two solutions of\nMathieu's equation whose product is an integral function of .\n\n[This amounts to the fact \\hardsectionref{19}{4}) that the product of ef\" ( > (z) and\ne~' ~ (- z) is a periodic integral function of z.']\n\n\\Subsection{19}{5}{2}{The determination of the integral function\n  associated with Mathieu's general equation.}\n\nThe integral function F(z) = Ay o\" + By, just introduced, can be\ndeter- mined without difficulty; for, if jo and y are any solutions\nof\n\n :+p(n|+Q(r) =o,\n\ntheir squares (and consequently any linear combination of their\nsquares) satisfy the equation*\n\n ! + 3P (D + [P' (0 + 4Q (0 + 2 [P (or ]\n\nin the case under consideration, this result reduces to\n\n+ (a-l-l6q + S2q ) J - 16qF (f) = 0.\n\nX\n\nLet the Maclaurin series for F ! ) be 1 c,i \"; on substitution, we\neasily obtain the recurrence formula for the coefficients c, namely\n\nwhere\n\n(n + I) (n - ly - a + 16q] \\ \\ n (n -h l)(2n + l)\n\n\"\"\" ieq(2n + l) ' ''\" S2q 2n-1) \"\n\n* Appell, Comptes Rendus, xci. (1880), pp. 211-214; cf. example 10,\np. 298 supra.\n\n%\n% 419\n%\n\nAt first sight, it appears from the recurrence formula that Co and Ci\ncan be chosen arbitrarily, and the remaining coefficients C2, C3, ...\ncalculated in terms of them; but the third order equation has a\nsingularity at t= 1) nd the series thus obtained would have only unit\nradius of convergence. It is necessary to choose the value of the\nratio Ci/Cq so that the series may con- verge for all values of .\n\nThe recurrence formula, when written in the form\n\nsuggests the consideration of the infinite continued firaction\n\nUu+'\n\nV,\n\nW2\n\nn+i 1\" W j o +\n\nlim 1*, +\n\nnn+i + ...+\n\nThe continued fraction on the right can be -sNTitten* w,i/r (n, n +\nm)IK (n + 1, n + m),\n\nwhere K (n, n + m) =\n\n1\n\n- u\n\n-1\n\n- Uni->, 1\n\nThe limit of this, as ??i - x, is a convergent determinant of von\nKoch's type (by the example of \\hardsubsectionref{2}{8}{2}); and since\n\nVr+i\n\nllrUr+l\n\nas n - 00,\n\nit is easily seen that K (n, x ) 1 as 7i -* x .\n\nCn Un K n, X )\n\nTherefore, if\n\nCn+1 K n + 1, co)' then Cn satisfies the recurrence formula and, since\nCn i/Cn - as ?i - x, the resulting series for F ( ) is an integral\nfunction. From the recurrence formula it is obvious that all the\ncoefficients c are finite, since they are finite when n is\nsufficiently large. The construction of the integral function F ( )\nhas therefore been effected.\n\n\\Subsection{19}{5}{3}{The solution of Mathieus equation in terms of F( ).}\nIf Wi and\nWo be two particular solutions of\n\ng+P(r)|+(3(f)\"=o,\n\nthenf\n\nW Wi - W1IV2\n\nr=cexp|-j P(r)fzr >\n\n* Sylvester, Phil. Mag. (4), v. (1S53), p. 446 [Math. Papers, i. p.\n609].\n\nt Abel, Journal fiir Math. ii. (1827), p. 22. Primes denote\ndifferentiations with regard to f.\n\n97 9\n\n%\n% 420\n%\n\nwhere is a definite constant. Taking iv and w to be those two\nsolutions of Mathieu's general equation whose product is -P( ), we\nhave w w. C w/ w,' r( )\n\nW, Wo f (l- t)*i (0' '\"'' '2 iO' the latter following at once from the\nequation tv iu. Fi ).\n\nSolving these equations for iv lic, and tuJ/wo, and then integrating,\nwe at once get\n\nwhere 71, y.. are constants of integration; obviously no real\ngenerality is lost by taking Cq = 71 = 72 = 1-\n\nFrom the former result we have, for small values of | |,\n\nwhile, in the notation of § 1 \"51, we have aJao = - a+ Sq.\n\nHence C = I69 - a - c .\n\nThis equation determines C in terms of a, q and Cj, the value of Ci\nbeing\n\nK(l, cc) uoK(0, x) .\n\nExample 1. If the solutions of Mathieu's equation be e' ' (p ±z),\nwhere </> (s) is periodic, shew that\n\nExample 2. Shew that the zeros oi F C) are all simple, unless (7=0.\n\n\\addexamplecitation{Stieltjes.}\n\n[If F () could have a re jeated zero, v and ivo would then have an\nessential singularity.]\n\n\\Section{19}{6}{A second method of constructing the Mathieu function.}\n\nSo far, it has been assumed that all the various series of \\hardsectionref{19}{3}\ninvolved in the expressions for cey(2, q) and sey(z, q) are\nconvergent. It will noiv be sheton that ce z, q) and scy z, q) are\nintegral functions of z and that the coefficients in their expansions\nas Fourier series are power series in q which converge absolutely when\n\\ q\\ is sufficiently small*.\n\nTo obtain this result for the functions ce2f z, q), we shall shew how\nto determine a particular integral of the equation\n\n- + (a + \\ Qq cos 2z) u = y\\ r a, q) cos Nz\n\n* The essential part of this theorem is the proof of the convergence\nof the series which occur in the coefficients; it is already known §§\n10'2, 10-21) that solutions of Mathieu's equation are integral\nfunctions of z, and (in the case of periodic solutions) the existence\nof the Fourier expansion follows from \\hardsubsectionref{9}{1}{1}.\n\n%\n% 421\n%\n\nin the form of a Fourier series converging over the whole 2 -plane,\nwhere yjr (a, q) is a function of the parameters a and q. The equation\n-v/r (a, q) = then determines a relation between a and q which gives\nrise to a Mathieu function. The reader who is acquainted with the\nmethod of Frobenius* as applied to the solution of linear differential\nequations in power series will recognise the resemblance of the\nfollowing analysis to his work.\n\nWrite a = iY + 8p, where JSf is zero or a positive or negative\ninteger.\n\nMathieu's equation becomes\n\n \\ +:N'Hi = -S (p + 2q cos 2z) 11.\n\nIf jj and q are neglected, a solution of this equation is u - cos Nz=\nUo )> say.\n\nTo obtain a closer approximation, write -8(p + 2q cos 2z) ITq (z) as a\nsum of cosines, i.e. in the form\n\n- 8 cos X-2)z+p cos Nz + q cos (N + 2) z] = Fj z), say.\n\nThen, instead of solving -r-- + X'-u = V z), suppress the terms f in V\nz)\n\nwhich involve cos Nz; i.e. consider the function W z) wherej\n\nIf, ( )=F,( ) + 8; cos iY . A particular integral of\n\n,+NHl=W, z)\n\n18\n\n11 = 9.\n\niro iT) ' ' ( - 2) + roTiT) '°' ' + 1 = ' ' ' '\n\nNow express -S(p + 2q cos 2z) L\\ (z) as a sum of cosines; calling\nthis sum Vo (z), choose a. to be such a function of p and q that V (z)\n+ a . cos Nz contains no term in cos Nz; and let V., z) + a., cos Nz\n= W. z).\n\ncP u Solve the equation -r-j + N- u = Wo z),\n\nand continue the process. Three sets of functions Um z), Vm z), Wm z)\nare thus obtained, such that U,n z) and W,n z) contain no term in cos\nNz when m 0, and\n\nW z) = F, z) + a, cos Nz, F, ( ) = - 8 p + 2q cos 2z) U,n-i (z),\n\n J + NL ( z) = W, z), where, is a function of p and q hut not of z.\n\n* Journal fiir Math, lxxvi. (1873), pp. 214-224.\n\n, d-u -, t The reason for this suppression is that the particular\nintegral of + A'- = cosA\n\ncontains non-periodic terms.\n\n+ Unless N = \\, in which case \\ \\ \\ \\ {z)-1\\ \\ {z) + 9 i) + q) co%z.\n\n%\n% 422\n%\n\nIt follows that\n\n\\ az ) j=o /=i\n\nn-i / n \\\n\n= - 8 (;9 + 25 COS 2ir) S [7',rt\\ i ( ) + S a, ) cos Nz.\n\nTherefore, if U z)= S f/', ( ' be a uniformly convergent series of\nanalytic\n\nm=0\n\nfunctions throughout a two-dimensional region in the -plane, we have\n\n\\hardsectionref{5}{3})\n\nd?U(z\n\n-7-2 + (' + 9. cos 'Iz) U (z) = ylr (a, q) cos Nz,\n\noc\n\nAvhere fr a,q)= 0 .\n\nIt is obvious that, if a be so chosen that yjf (a, q) = 0, then U z)\nreduces to cey z).\n\nA similar process can obviously be carried out for the functions 5e y\nz, q) by making use of sines of multiples of z.\n\n\\Subsection{19}{6}{1}{The convergence of the series defining Mathieu functions.}\n\nWe shall now examine the expansion of \\hardsectionref{19}{6} more closely, with a view\nto investigating the convergence of the series involved.\n\nWhen n\" 1, we may obviously write\n\n/! n\n\nU-a\\ Z)= 2 */3,,.cos(iy-2r)£-|- 2 a rCOfi N->r'2.r)z, r=l r=l\n\nthe asterisk denoting that the first summation ceases at the greatest\nvalue of r for which r N.\n\n (12 1\n\n-jpi+ \\ n+i (-) = an + 1 cos Nz -8 p + 2q cos 22) £/\" (2),\n\nit follows on equating coefficients of cos (iV + 2r) z on each side of\nthe equation t that\n\n0.1 + 1 = !? (\"h,1+3,i),\n\n/(>- + .y)a +,,, = 2 /?a,, + j(a, r-i + a,r + i) (''=1,2, ...),\n\nThese formulae hold universally with the following conventions % :\n\n(i) Vo = 3 .o = ( = 1,2,...); a,. =, = (;> ),\n\n(ii) j, . j = iv-i li6i' - i* 'en and r=|i, (i\") n.H-V+D ' n.H V-i)\nen .V is odd and r=h N- ) . t When A'=0 or 1 these equations must be\nmodified by the suppression of all the coefficients * The conventions\n(ii) and (iii) are due to the fact that cos2; = cos (-2), cos 22 = cos\n(- 22).\n\n%\n% 423\n%\n\nThe reader will easily obtain the following special formulae :\n\n(I) a = 8p, (iV= l); ai = 8ip + q), (iV=l),\n\n(III) a,y and n,r homogeneous polynomials of degree n in p and q.\n\nwe have >/ (a, j) = 8jt? + 8y (Ji+5,) (iV- D,\n\nrir + ]V)A,=2ipAr+q(Ar-, + A, i)] (A),\n\nr(r-.V) B, = 2 pB,+q B,\\, + Br i) (B),\n\nwhere Ao=B = 1 and B,. is subject to conventions due to (ii) and (iii)\nabove. Now write w,.= -q r r + ]V)-2p -\\ '/= -q r (r-y)-2p -\\ The\nresult of eliminating Ai, Ao, ... Aj.-, A + i, ... from the set of\nequations (A) is\n\nwhere A,, is the infinite determinant of von Koch's type \\hardsubsectionref{2}{8}{2})\n\nA,.= 1, il'r+u 0,0,....\n\n, Wr+3, 1, W +3, ...\n\nThe determinant converges absolutely \\hardsubsectionref{2}{8}{2} example) if no\ndenominator vanishes; and Ar-*-l as r- -cc (cf.\\hardsubsectionref{19}{5}{2}). If p and q\nbe given such values that Ao fcO, 2p r r- N), where r = l, 2, 3, ...,\nthe series\n\n2 - yiVx%o.2...Wj.Ar (r cos(iV+2r) z\n\nr=\\\n\nrepresents an integral function of z.\n\nIn like manner B,.D(,= -Y Wi tc ...w ' J),., where D,. is the finite\ndeterminant\n\n1, w'r + i,, ... J,\n\nw'r + 2, 1, w'r + 2,  !\n\nthe last row being 0, 0, ... 0, 2w\\ \\, 1 or 0, 0, ... 0, <''i(jvr-i))\nl + '''i(,v\\ i) according as N is even or odd.\n\nThe series 2 Un (z) is therefore\n\n?t=0\n\nCOS V + Ao\" 2 (-)'\"?<?i?i'2...?<'rArCOS(iV+2r)2 r = l\n\n+ D- 1 2 ( - )' iv; 10,' . . . w,' I), cos (iY- 2;-) z,\n\nthese series converging uniformly in any bounded domain of values of\nz, so that term-by- term differentiations are permissible.\n\nFurther, the condition yj/ (, g') = is equivalent to\n\nIf we multiply by\n\npAo o-q w- Ai Do + Wi'Di Aq) = 0.\n\n%\n% 424\n%\n\nthe expression on the left becomes an integral function of both p and\nq, (a, q), h-a\\; the terms of (a, q\\ which are of lowest degrees.in p\nand q, are respectively p and\n\n ow expand - -. . ..o, o c - - 5 - - - ap\n\nin ascending powers of q (cf.\\hardsubsectionref{7}{3}{1}), the contour being a small\ncii'cle in the p-plane, with centre at the origin, and | q I being so\nsmall that (iV + Sjo, q) has only one zero inside the contour. Then it\nfollows, just as in \\hardsubsectionref{7}{3}{1}, that, for sufficiently small values of \\\nq\\, we may expand p as a power series in q commencing* with a term in\nq; and if | q be sufficiently small D and Aq will not vanish, since\nboth are equal to 1 when =0.\n\nOn substituting for p in terms of q throughout the series for U (z),\nwe see that the series involved in cex (s, q) are absolutely\nconvergent when | | is sufficiently small.\n\nThe series involved in se (2, q) may obviously be investigated in a\nsimilar manner.\n\n\\Section{19}{7}{The method of change of parameter.}\n\nThe methods of Hill and of Lindemann-Stieltjes are effective in\ndetermining, but only after elaborate analysis. Such analysis is\ninevitable, as is by no means a simple function of q; this may be\nseen by giving q an assigned real value and making a vary from - C30\nto + 00; then /x alternates between real and complex values, the\nchanges taking place when, with the Hill-]\\ Iathieu notation, A (0)\nsin- [hir s, a) passes through the values and 1; the complicated\nnature of this condition is due to the fact that A (0) is an elaborate\nexpression involving both a and q.\n\nIt is, however, possible to express fj. and a in terms of q and of a\nnew parameter tr, and\n\nthe results are very well adapted for purposes of numerical\ncomputation when | 5' | is small J.\n\nThe introduction of the parameter a- is suggested by the series for\ncei z, q) and sey z, q)\n\ngiven in \\hardsectionref{19}{3} example 1; a consideration of the.se series leads us\nto investigate the\n\npotentialities of a solution of Mathieu's general equation in the form\ny=e' ' 0(s), where\n\n  if) = sin z-(r) + a-i cos (82 - o-) + 63 sin (82 - cr) + 05 cos hz -\ncr) + 65 sin (52 - tr) + . . ., the parameter o- being rendered\ndefinite by the fact that no term in cos z - a) is to appear in (j)\nz); the special functions 5 1(2, q), cei z, q) are the cases of this\nsolution in which o- is or \\ ir.\n\nOn substituting this expression in Mathieu's equation, the reader will\nhave no difficulty in obtaining the following approximations, valid\nfor § small viilues of q and real values of cr :\n\n  =4 ' sin 2o-- 12 -\" sin 2o-- 12j*sin 4o- + (2\" ),\n\na = 1+ 8y cos 2(7 + ( - 16 + 8 cos 4o-) 2 \\ i cos 2o- + ( f -- 88 cos\n4o-) q + O q% a3=Sq sin 2a- + '3q sin 4:a + - sin 2a- + 9 sin 6a) q +\nq% h =q + q cos 2o- + ( - J f + 5 cos 4(r) j + ( \\ IJ. cos 2o- + 7 cos\n60-) </* + q% a- = Y? sin 2o-4-|f ? sin 4o- + q% h=W + j q cos 2(7 + (\n- Vr + f f cos Aa) q +0 q->), 7 = f'ifs 9* sin 2a + (q ), 67 = q + (/*\ncos 2<t+0 iq% a, = 0 q% h, = l,,q + 0 q% the constants involved in the\nvarious functions 0 q ) depending on a-.\n\n* If A = l this result has to be modified, since there is an\nadditional term q on the right and the term q jiN - 1) does not\nappear. .\n\nt Wbittaker, Proc. Edinburgh Math. Soc. xxxn. (1914), pp. 75-80.\n\nX They have been applied to Hill's problem by luce, Monthly Notices of\nthe R. A. S. lxxv. (1915), pp. 436-448.\n\n§ The parameters q and a are to be regarded as fundamental in this\nanalysis, instead of a and q as hitherto.\n\n%\n% 425\n%\n\nThe domains of values of q and o- for which these series converge have\nnot yet been determined*.\n\nIf the sokition thus obtained be called A z, a, q), then A (z, cr, q)\nand A z, - o\", q) form a fundamental system of solutions of Mathieu's\ngeneral equation if /x= 0.\n\nExample 1. Shew that, if o- = / x 0'5 and = 0-01, then\n\na = M24,841,4..., /x = ?x 0-046,993,5 ...; shew also that, if (r = i\nand 2' = 0'01, then\n\nrt = l-,321, 169,3..., / = ix 0-145,027,6.... Example 2. Obtain the\nequations\n\n/x = 4 sin 2a- - 4 ja3, rt - 1 + 83' cos 2(r - /it- - 8363,\nexpressing n and a in finite terms as functions of q, a, a and 63.\nExample 3. Obtain the recurrence formulae -4:n n+l) +\n8qcos2a--8qb3±8qi 2n+l) as-sin2(r) z.2n + i + 8q z2 \\ i+Z2 3) = 0,\n\nwhere 22jh-i denotes bon+i + ict-in + i oi\" -in + i - i 2)i + i>\naccording as the upper or lower sign is taken.\n\n\\Section{19}{8}{The asymptotic solution of Mathieu's equation.}\n\nIf in Mathieu's equation\n\nd' v. / 1,., \\\n\n-5- + a + - A,- cos 22 I M =\n\ndz- \\ 2 J\n\nwe write k sin 2 =, we get\n\nwhere i/ = + P.\n\nThis equation has an irregular singularity at infinity. From its\nresemblance to Bessel's equation, we are led to write u - e' |~- v,\nand substitute\n\nV=l+ a,/ ) + a,!e) + ... in the resulting equation for v; we then\nfind that\n\nai = - i (i - 3P + F), a., = - Hi - + ') (f - - H F) + IF, the\ngeneral coefficient being given by the recurrence formula\n\n2i(r+l)a, + i = J-J/2 + F + /-(r+l) + (2?--l)zFa \\ l-(/-2-2/- + |)Fa,\\\n2. The two series\n\ne'U~-(l+ + jl+-], e-''r'(l- +\n\n|,p,...), .-.,-.,. . \\\n\nare formal solutions of Mathieu's equation, reducing to the well-known\nasymptotic solutions of Bessel's equation \\hardsectionref{17}{5}) when -- 0. The\ncomplete formulae which connect them with the solutions e ' (f)(±z)\nhave not yet been published, though some steps towards obtaining them\nhave been made by Dougall, F7'oc. Edinburgh Math. Soc. xxxiv. (1916),\npp. 176-196.\n\n* It seems highly probable that, if | g | is sufficiently small, the\nseries converge for all real values of a, and also for complex values\nof cr for which |I((r) | is sufficiently small. It may be noticed\nthat, when q is real, real and purely imaginary values of cr\ncorrespond respectively to real and purely imaginary values of fi.\n\n%\n% 426\n%\n\nKEFEREXCES.\n\nE. L. Mathiec, Journal de Math. (2), xiii. (1868), pp. 137-203.\n\nG. W. Hill, Acta Mathematica, viii. (1886), pp. 1-36.\n\nG. Floquet, Ann. de VEcole norm. sup. (2), xii. (1883), pp. 47-88.\n\nC. L. F. LiNDEMANN, Mcith. Ann. xxii. (1883), pp. 117-123.\n\nT. J. Stieltjes, Astr. Naeh. cix. (1884), cols. 145-152, 261-266.\n\nA. LiXDSTEDT, Astr. Nach. cm. (1882), cols. 211-220, 257-268; Civ.\n(1883), cols. 145-150; cv. (1883), cols. 97-112.\n\nH. Bruns, Astr. Xach. cvi. (1883), cols. 193-204; cvii. (1884), cols.\n129-132.\n\nR. C. Maclaurin, Trans. Camb. Phil. Soc. xvii. (1899), pp. 41-108.\n\nK. AiCHi, Proc. Tokyo Math, and Phys. Soc. (2), iv. (1908), pp.\n266-278.\n\nE. T. Whittaker, Proc. International Congress of Mathematicians,\nCambridge, 1912, I. pp. 366-371.\n\nE. T. Whittaker, Proc. Edinburgh Math. Soc. xxxii. (1914), pp. 75-80.\n\nG. N, Watson, Proc. Edinburgh Math. Soc. xxxiii. (1915), pp. 25-30.\n\nA. W. Young, Proc. Edinburgh Math. Soc. xxxii. (1914), pp. 81-90.\n\nE. Lindsay Inge, Proc. Edinburgh Math. Soc. xxxiii. (1915), pp. 2-15.\n\nJ. Dougall, Proc. Edinburgh Math. Soc. xxxiv. (1916), pp. 176-196.\n\nMiscellaneous Examples.\n\n1. Shew that, if k= l Z \\\n\n2wce(, s, q) = cco 0,q) j cos k sin z sin 6) ccq (0, q) d6. J -It\n\n2. Shew that the even Mathieu functions satisfy the integral equation\n\nG (2)=X j Jo [ik (cos z + cos 6) G 6) d6.\n\n3. Shew that the equation\n\n(a22 + c) +2a5 + (X%2+ 0 =\n\n(where o, c, X, m are constants) is satisfied by\n\nu = \\ \\ v s)ds tAken round an appropriate contour, provided that v (s)\nsatisfies\n\n as + c) + 2as - X cs - + m)v 3) = 0,\n\nwhich is the same as the equation for u.\n\nDerive the integral equations satisfied by the Mathieu functions as\nparticular cases of this result.\n\n%\n% 427\n%\n\n4. Shew that, if powers of q above the fourth are neglected, then\n\nce?! (s, q) = cos 2 + J cos 32 + q (J cos hz - cos 3s)\n\n+ ( (i 8 cos 7s - f cos 5s + J cos 3s)\n\n+ ?* (rl < ~ I's 0* ''' + H cos 5s + cos 3s),\n\nsei (s, j) = sin s + g sin 3s + §'2 (i sin 5s + sin 3s)\n\n+ <f ( jij sin 7s + f sin 5s + A sin 3s)\n\n+ q (yIcj sin 9s + Jj sin 7s + sin 5s - - sin 3s),\n\nC(?2 (s, g-) = cos 2s + g- (cos 4s - 2) + g cog g\n\n+ ? (-/s cos 8s + If cos 4s + -* )\n\n+ ?* (sTO cos 10s + f|§ cos 6s).\n\n\\addexamplecitation{Mathieu.}\n\n5. Shew that\n\n663(0, 2') = cos 32 + 2'( - coss+l cos5s)\n\n+ j2 (cos s + J(5 COS 7s) + j3 ( \\ I COS s + - COS 5s + Jq cos 9s) +\nq*),\n\nand that, in the case of this function\n\na = 9 + 4q -8q +0 q ).\n\n\\addexamplecitation{Mathieu.}\n\n6. Shew that, if 1/ (s) be a Mathieu function, then a second sokition\nof the corresponding differential equation is\n\nShew that a second solution * of the equation for ce (s, q) is zceQ\n(z, q) - 4:qsiB 2s- Sq- sin 4s- ....\n\n7. If ?/ (2) be a solution of Mathieu's general equation, shew that\n\n y(s + 2 )+3/(s-2:r) /j/(2) is constant.\n\n8. Express the Mathieu functions as series of Bessel functions in\nwhich the coefficients are multiples of the coefficients in the\nFourier series for the Mathieu functions.\n\n[Substitute the Fourier series under the integral sign in the integral\nequations of \\hardsubsectionref{19}{2}{2}.]\n\n9. Shew that the confluent form of the equations for ce (s, q) and se\n(2, q), when the eccentricity of the fundamental ellipse tends to\nzero, is, in each case, the equation satisfied by J,, ii- eoH z).\n\n10. Obtain the parabolic cylinder functions of Chapter xvi as\nconfluent forms of the Mathieu functions, by making the eccentricity\nof the fundamental ellipse tend to unity.\n\n11. Shew that ce (s, q) can be expanded in series of the form\n\n2 J,cos2'\"3 or 2 5,,,cos2' + i2,\n\n n=0 m=0\n\naccording as % is even or odd; and that these series converge when j\ncoss [ < 1.\n\n* This solution is called in (z, q); the second sohitions of the\nequations satisfied by Mathieu functions have been investigated by\nInce, Proc. Edinburgh Math. Soc. xxxiii. (1915), pp. 2-15. See also §\n19-2.\n\n%\n% 428\n%\n\n12. With the notation of example 11, shew that, if\n\nce z, q) = X I e*cos3oo60 e,, ((9, q) dd, then A is given by one or\nother of the series\n\nprovided that these series converge.\n\n13. Shew that the differential equation satisfied by the product of\nany two solutions of Bessel's equation for functions of order n is\n\nS S-2n) S+21l)u + -I. S + l) u = 0,\n\nwhere 3 denotes z -j- . dz\n\nShew that one solution of this equation is an integral function of 2;\nand thence, by the methods of 5; \\$ 19'5-19'53, obtain the Bessel\nfunctions, discussing particularly the case in which a is an integer.\n\n14. Shew that an approximate solution of the equation\n\n- -ir(A+k-sm\\ i-z)u=Q dz\n\nis \\ i = C (cosech s) - sin k cosh z + e),\n\nwhere C and e are constants of integration; it is to be assumed that\nk is large, A is not very large and z is not small.\n", "meta": {"hexsha": "7ece859c92849677e2e30ec4cc823ab47e1b1026", "size": 49378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch19.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-ch19.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-ch19.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": 29.0800942285, "max_line_length": 159, "alphanum_fraction": 0.68366479, "num_tokens": 15893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6517872563835349}}
{"text": "\\chapter{\\(K\\)-Compensated de Casteljau}\\label{chap:k-compensated}\n\n\\section{Introduction}\n\nIn computer aided geometric design, polynomials are usually expressed in\nBernstein form. Polynomials in this form are usually evaluated by the\nde Casteljau algorithm. This algorithm has a round-off error bound\nwhich grows only linearly with degree, even though the number of\narithmetic operations grows quadratically. The Bernstein basis is\noptimally suited (\\cite{Farouki1987, Delgado2015, Mainar2005})\nfor polynomial evaluation; it is\ntypically more accurate than the monomial basis, for example in\nFigure~\\ref{fig:horner-inferior} evaluation via Horner's method produces\na jagged curve for points near a triple root, but the de Casteljau algorithm\nproduces a smooth curve. Nevertheless the de Casteljau\nalgorithm returns results arbitrarily less accurate than the working\nprecision \\(\\mach\\) when evaluating \\(p(s)\\) is ill-conditioned.\nThe relative accuracy of the computed\nevaluation with the de Casteljau algorithm (\\texttt{DeCasteljau}) satisfies\n(\\cite{Mainar1999}) the following a priori bound:\n\\begin{equation}\\label{eq:de-casteljau-error}\n  \\frac{\\left|p(s) - \\mathtt{DeCasteljau}(p, s)\\right|}{\\left|p(s)\\right|} \\leq\n  \\cond{p, s} \\times \\bigO{\\mach}.\n\\end{equation}\nIn the right-hand side of this inequality, \\(\\mach\\) is the computing\nprecision and the condition number \\(\\cond{p, s} \\geq 1\\) only depends\non \\(s\\) and the Bernstein coefficients of \\(p\\) --- its expression will\nbe given further.\n\n\\begin{figure}\n  \\includegraphics{../images/k-compensated/horner_inferior.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Comparing Horner's method to the de Casteljau method for\n    evaluating \\(p(s) = (2s - 1)^3\\) in the neighborhood of its\n    multiple root \\(1/2\\).}\n  \\label{fig:horner-inferior}\n\\end{figure}\n\nFor ill-conditioned problems, such as evaluating \\(p(s)\\) near a\nmultiple root, the condition number may be arbitrarily large, i.e.\n\\(\\cond{p, s} > 1 / \\mach\\), in\nwhich case most or all of the computed digits will be incorrect.\nIn some cases, even the order of magnitude of the computed value\nof \\(p(s)\\) can be incorrect.\n\nTo address ill-conditioned problems, error-free transformations (EFT) can\nbe applied in \\emph{compensated algorithms} to account for round-off.\nError-free transformations were studied in great detail in \\cite{Ogita2005}\nand open a large number of applications.\nIn \\cite{langlois_et_al:DSP:2006:442}, a compensated version of Horner's\nalgorithm described to evaluate a polynomial in the monomial basis.\nIn \\cite{Jiang2010},\na similar method was described to perform a compensated version of the de\nCasteljau algorithm. In both cases, the \\(\\cond{p, s}\\) factor is moved\nfrom \\(\\mach\\) to \\(\\mach^2\\) and the computed value is as accurate\nas if the computations were done in twice the working precision. For example,\nthe compensated de Casteljau algorithm (\\texttt{CompDeCasteljau}) satisfies\n\\begin{equation}\\label{eq:de-casteljau-2-error}\n  \\frac{\\left|p(s) - \\mathtt{CompDeCasteljau}(p, s)\\right|}{\n    \\left|p(s)\\right|} \\leq \\mach + \\cond{p, s} \\times\n    \\bigO{\\mach^2}.\n\\end{equation}\nFor problems with \\(\\cond{p, s} < 1 / \\mach^2\\), the relative error\nis \\(\\mach\\), i.e. accurate to full precision, aside from rounding to the\nnearest floating point number. Figure~\\ref{fig:jlcs-10} shows this shift\nin relative error from \\texttt{DeCasteljau} to \\texttt{CompDeCasteljau}.\n\n\\begin{figure}\n  \\includegraphics{../images/k-compensated/jlcs10_plot.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Evaluation of \\(p(s) = (s - 1)\\left(s - 3/4\\right)^7\\)\n    represented in Bernstein form.}\n  \\label{fig:jlcs-10}\n\\end{figure}\n\nIn \\cite{Graillat2009}, the authors generalized the compensated Horner's\nalgorithm to produce a method for evaluating a polynomial as if\nthe computations were done in \\(K\\) times the working precision for\nany \\(K \\geq 2\\). This result motivates this chapter, though the\napproach there is somewhat different than ours. They perform each computation\nwith error-free transformations and interpret the errors as coefficients of new\npolynomials. They then evaluate the error polynomials, which (recursively)\ngenerate second order error polynomials and so on. This recursive property\ncauses the number of operations to grow exponentially in \\(K\\). Here, we\ninstead have a fixed number of error groups, each corresponding to round-off\nfrom the group above it. For example, when\n\\((1 - s) b_j^{(n)} + s b_{j + 1}^{(n)}\\) is computed in floating point, any\nerror is filtered down to the error group below it.\n\nAs in~\\eqref{eq:de-casteljau-error}, the accuracy of the compensated\nresult~\\eqref{eq:de-casteljau-2-error} may be arbitrarily bad for\nill-conditioned\npolynomial evaluations. For example, as the condition number grows in\nFigure~\\ref{fig:jlcs-10}, some points have relative error exactly equal to\n\\(1\\); this indicates that \\\\ \\(\\mathtt{CompDeCasteljau}(p, s) = 0\\), which is\na complete failure to evaluate the order of magnitude of \\(p(s)\\). For\nroot-finding problems \\(\\mathtt{CompDeCasteljau}(p, s) = 0\\) when\n\\(p(s) \\neq 0\\) can cause premature convergence and incorrect results.\nWe describe how to defer rounding into progressively\nsmaller error groups and improve the accuracy of the computed result by a\nfactor of \\(\\mach\\) for every error group added. So we derive\n\\texttt{CompDeCasteljauK}, a \\(K\\)-fold compensated de Casteljau algorithm\nthat satisfies the following a priori bound for any arbitrary integer \\(K\\):\n\\begin{equation}\n  \\frac{\\left|p(s) - \\mathtt{CompDeCasteljauK}(p, s, K)\\right|}{\n    \\left|p(s)\\right|} \\leq \\mach + \\cond{p, s} \\times\n    \\bigO{\\mach^K}.\n\\end{equation}\nThis means that the computed value with \\texttt{CompDeCasteljauK} is now\nas accurate as the result of the de Casteljau algorithm performed in\n\\(K\\) times the working precision with a final rounding back to the\nworking precision.\n\nThe chapter is organized as follows. In Section~\\ref{sec:compensated-2},\nthe compensated algorithm for polynomial evaluation from \\cite{Jiang2010} is\nreviewed and notation is established for the expansion. In\nSection~\\ref{sec:compensated-k}, the \\(K\\)-compensated algorithm is provided\nand a forward error analysis is performed. Finally, in\nSection~\\ref{sec:numerical} we perform two numerical experiments to\ngive practical examples of the theoretical error bounds.\n(See Chapter~\\ref{chap:preliminaries} to review notation for error analysis\nwith floating point operations, review results about error-free\ntransformations or to review the de Casteljau algorithm.)\n\n\\section{Compensated de Casteljau}\\label{sec:compensated-2}\n\nIn this section we review the compensated de Casteljau algorithm\nfrom \\cite{Jiang2010}. In order to track the local errors at\neach update step, we use four EFTs:\n\\begin{align}\n\\left[\\widehat{r}, \\rho\\right] &= \\mathtt{TwoSum}(1, -s) \\\\\n\\left[P_1, \\pi_1\\right] &= \\mathtt{TwoProd}\\left(\n    \\widehat{r}, \\widehat{b}_j^{(k + 1)}\\right) \\\\\n\\left[P_2, \\pi_2\\right] &= \\mathtt{TwoProd}\\left(\n    s, \\widehat{b}_{j + 1}^{(k + 1)}\\right) \\\\\n\\left[\\widehat{b}_j^{(k)}, \\sigma_3\\right] &= \\mathtt{TwoSum}(P_1, P_2)\n\\end{align}\nWith these, we can exactly describe the local error between the exact\nupdate and computed update:\n\\begin{gather}\n\\ell_{1, j}^{(k)} = \\pi_1 + \\pi_2 + \\sigma_3 + \\rho \\cdot\n  \\widehat{b}_j^{(k + 1)} \\label{eq:ell-j} \\\\\n(1 - s) \\cdot \\widehat{b}_j^{(k + 1)} +\n  s \\cdot \\widehat{b}_{j + 1}^{(k + 1)} =\n\\widehat{b}_j^{(k)} + \\ell_{1, j}^{(k)}.\n\\end{gather}\n\n\\begin{figure}\n  \\includegraphics[width=0.375\\textwidth]{tikz_local_err.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Local round-off errors}\n  \\label{fig:loc-err-accumulate}\n\\end{figure}\n\n\\noindent By defining the global errors at each step\n\\begin{equation}\n  \\db{1}_j^{(k)} = b_j^{(k)} - \\widehat{b}_j^{(k)}\n\\end{equation}\nwe can see (Figure~\\ref{fig:loc-err-accumulate}) that the local errors\naccumulate in\n\\(\\db{1}^{(k)}\\):\n\\begin{equation}\\label{eq:err-update}\n  \\db{1}_j^{(k)} = (1 - s) \\cdot \\db{1}_j^{(k + 1)} + s \\cdot\n  \\db{1}_{j + 1}^{(k + 1)} + \\ell_{1, j}^{(k)}.\n\\end{equation}\nWhen computed in exact arithmetic\n\\begin{equation}\n  p(s) = \\widehat{b}_0^{(0)} + \\db{1}_0^{(0)}\n\\end{equation}\nand by using \\eqref{eq:err-update}, we can continue to compute\napproximations of \\(\\db{1}_j^{(k)}\\). The idea behind the compensated\nde Casteljau algorithm is to compute both the local error and the updates\nof the global error with floating point operations:\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Compensated de Casteljau\n      algorithm for polynomial evaluation.}}\n  \\label{alg:comp-de-casteljau}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\mathtt{result} = \\mathtt{CompDeCasteljau}\\)}{$b, s$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\State \\(\\left[\\widehat{r}, \\rho\\right] = \\mathtt{TwoSum}(1, -s)\\)\n      \\\\\n      \\For{\\(j = 0, \\ldots, n\\)}\n        \\State \\(\\widehat{b}_j^{(n)} = b_j\\)\n        \\State \\(\\cdb{1}_j^{(n)} = 0\\)\n      \\EndFor\n      \\\\\n      \\For{\\(k = n - 1, \\ldots, 0\\)}\n        \\For{\\(j = 0, \\ldots, k\\)}\n          \\State \\(\\left[P_1, \\pi_1\\right] = \\mathtt{TwoProd}\\left(\n              \\widehat{r}, \\widehat{b}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\left[P_2, \\pi_2\\right] = \\mathtt{TwoProd}\\left(\n              s, \\widehat{b}_{j + 1}^{(k + 1)}\\right)\\)\n          \\State \\(\\left[\\widehat{b}_j^{(k)}, \\sigma_3\\right] =\n              \\mathtt{TwoSum}(P_1, P_2)\\)\n          \\State \\(\\widehat{\\ell}_{1, j}^{(k)} = \\pi_1 \\oplus \\pi_2 \\oplus\n              \\sigma_3 \\oplus \\left(\\rho \\otimes\n              \\widehat{b}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\cdb{1}_j^{(k)} =\n              \\widehat{\\ell}_{1, j}^{(k)} \\oplus\n              \\left(s \\otimes \\cdb{1}_{j + 1}^{(k + 1)}\n              \\right) \\oplus\n              \\left(\\widehat{r} \\otimes\n              \\cdb{1}_j^{(k + 1)}\\right)\\)\n        \\EndFor\n      \\EndFor\n      \\\\\n      \\State \\(\\mathtt{result} = \\widehat{b}_0^{(0)} \\oplus\n          \\cdb{1}_0^{(0)}\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent  When comparing this computed error to the exact error, the\ndifference depends only on \\(s\\) and the Bernstein\ncoefficients of \\(p\\). Using a bound (Lemma~\\ref{lemma:db-lemma}) on the\nround-off error when computing \\(\\db{1}^{(0)}\\), the algorithm can\nbe shown to be as accurate as if the computations were done in twice\nthe working precision:\n\n\\begin{theorem}[\\cite{Jiang2010}, Theorem 5]\n  If no underflow occurs, \\(n \\geq 2\\) and \\(s \\in \\left[0, 1\\right]\\)\n  \\begin{equation}\n    \\frac{\\left|p(s) - \\mathtt{CompDeCasteljau}(p, s)\\right|}{\n      \\left|p(s)\\right|} \\leq \\mach + 2 \\gamma_{3n}^2 \\cond{p, s}.\n  \\end{equation}\n\\end{theorem}\n\n\\begin{figure}\n  \\includegraphics{../images/k-compensated/compensated_insufficient.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{The compensated de Casteljau method starts to lose accuracy\n    for \\(p(s) = (2s - 1)^3 (s - 1)\\) in the neighborhood of its\n    multiple root \\(1/2\\).}\n  \\label{fig:compensated-insufficient}\n\\end{figure}\n\nUnfortunately, Figure~\\ref{fig:compensated-insufficient} shows how\n\\texttt{CompDeCasteljau} starts to break down in a region of\nhigh condition number (caused by a multiple root with multiplicity\nhigher than two). For example, the point\n\\(s = \\frac{1}{2} + 1001\\mach\\)\n--- which is in the plotted region \\(\\left|s - \\frac{1}{2}\\right|\n\\leq \\frac{3}{2} \\cdot 10^{-11}\\) --- evaluates to exactly \\(0\\) when\nit should be \\(\\bigO{\\mach^3}\\). As shown in\nTable~\\ref{tab:exact-computation}, the breakdown occurs because\n\\(\\widehat{b}_0^{(0)} = -\\cdb{1}_0^{(0)} = \\mach / 16\\).\n\n\\begin{table}\n  %% See: ``scripts/verify_table.py``.\n  \\centering\n  \\begin{adjustbox}{max width=\\textwidth}\n  \\begin{tabular}{>{$}c<{$} >{$}c<{$} >{$}c<{$} >{$}c<{$} >{$}c<{$} >{$}c<{$}}\n    \\toprule\n    k & j & \\widehat{b}_j^{(k)} & \\cdb{1}_j^{(k)} &\n        \\db{1}_j^{(k)} - \\cdb{1}_j^{(k)} \\\\\n    \\midrule\n    3 & 0 & 0.125 - 1.75 (1001 \\mach) - 0.25 \\mach & 0.25\\mach & 0 \\\\\n    3 & 1 & -0.125 + 1.25(1001 \\mach) + 0.25 \\mach & -0.25\\mach & 0 \\\\\n    3 & 2 & 0.125 - 0.75 (1001 \\mach) & 0 & 0 \\\\\n    3 & 3 & -0.125 + 0.25 (1001 \\mach) & 0 & 0 \\\\\n    \\midrule\n    2 & 0 & -0.5 (1001 \\mach) & 3 (1001 \\mach)^2 & 0 \\\\\n    2 & 1 & 0.5(1001 \\mach) + 0.125 \\mach & -0.125\\mach - 2 (1001 \\mach)^2 &\n        0 \\\\\n    2 & 2 & -0.5 (1001 \\mach) & (1001 \\mach)^2 & 0 \\\\\n    \\midrule\n    1 & 0 & 0.0625\\mach + (1001 \\mach)^2 + 239\\mach^2 &\n        -0.0625\\mach + 0.5  (1001 \\mach)^2 - 239 \\mach^2 & -5 (1001\\mach)^3 \\\\\n    1 & 1 & 0.0625\\mach - (1001 \\mach)^2 - 239\\mach^2 &\n        -0.0625\\mach - 0.5  (1001 \\mach)^2 + 239 \\mach^2 & 3 (1001\\mach)^3 \\\\\n    \\midrule\n    0 & 0 & 0.0625 \\mach & -0.0625 \\mach &\n        -4 (1001 \\mach)^3 + 8 (1001 \\mach)^4 \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{adjustbox}\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Terms computed by \\texttt{CompDeCasteljau} when evaluating\n    \\(p(s) = (2s - 1)^3 (s - 1)\\) at the point\n    \\(s = \\frac{1}{2} + 1001 \\mach\\)}\n  \\label{tab:exact-computation}\n\\end{table}\n\n\\section{\\texorpdfstring{\\(K\\)}{K}-Compensated de Casteljau}\n\\label{sec:compensated-k}\n\n\\subsection{Algorithm Specified}\n\nIn order to raise from twice the working precision to \\(K\\) times the\nworking precision, we continue using EFTs when computing\n\\(\\cdb{1}^{(k)}\\). By tracking the round-off from each\nfloating point evaluation via an EFT, we can form a cascade of global errors:\n\\begin{align}\n  b_j^{(k)} &= \\widehat{b}_j^{(k)} + \\db{1}_j^{(k)} \\\\\n  \\db{1}_j^{(k)} &= \\cdb{1}_j^{(k)} + \\db{2}_j^{(k)} \\\\\n  \\db{2}_j^{(k)} &= \\cdb{2}_j^{(k)} +\n  \\db{3}_j^{(k)} \\\\\n  %% H/T: https://tex.stackexchange.com/a/7651/32270\n  &\\mathrel{\\makebox[\\widthof{=}]{\\vdots}} \\nonumber\n\\end{align}\nIn the same way local error can be tracked when updating\n\\(\\widehat{b}_j^{(k)}\\), it can be tracked for updates that happen down\nthe cascade:\n\\begin{alignat}{4}\n  (1 - s) \\cdot \\widehat{b}_j^{(k + 1)} &+\n  s \\cdot \\widehat{b}_{j + 1}^{(k + 1)} &&  &&=\n  \\widehat{b}_j^{(k)} &&+ \\ell_{1, j}^{(k)} \\\\\n  (1 - s) \\cdot \\cdb{1}_j^{(k + 1)} &+\n  s \\cdot \\cdb{1}_{j + 1}^{(k + 1)} &&+ \\ell_{1, j}^{(k)} &&=\n  \\cdb{1}_j^{(k)} &&+ \\ell_{2, j}^{(k)} \\\\\n  (1 - s) \\cdot \\cdb{2}_j^{(k + 1)} &+\n  s \\cdot \\cdb{2}_{j + 1}^{(k + 1)} &&+ \\ell_{2, j}^{(k)} &&=\n  \\cdb{2}_j^{(k)} &&+ \\ell_{3, j}^{(k)} \\\\\n  &  &&  &&\\mathrel{\\makebox[\\widthof{=}]{\\vdots}} && \\nonumber\n\\end{alignat}\n\n\\begin{figure}\n  \\includegraphics[width=0.875\\textwidth]{tikz_filtration.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Filtering errors}\n  \\label{fig:error-filtration}\n\\end{figure}\n\nIn \\texttt{CompDeCasteljau} (Algorithm~\\ref{alg:comp-de-casteljau}), after\na single stage of error filtering we\n``give up'' and use \\(\\cdb{1}\\) instead of\n\\(\\db{1}\\) (without keeping around any information about the\nround-off error). In order to obtain results that are as accurate as if\ncomputed in \\(K\\) times the working precision, we must continue filtering\n(see Figure~\\ref{fig:error-filtration})\nerrors down \\((K - 1)\\) times, and only at the final level do we accept\nthe rounded\n\\(\\cdb{K - 1}\\) in place of the exact\n\\(\\db{K - 1}\\).\n\nWhen computing \\(\\cdb{F}\\) (i.e. the error after\n\\(F\\) stages of filtering)\nthere will be several sources of round-off. In particular, there will be\n\\begin{itemize}\n\\itemsep 0em\n\\item errors when computing \\(\\widehat{\\ell}_{F, j}^{(k)}\\) from the\n  terms in \\(\\ell_{F, j}^{(k)}\\)\n\\item an error\nfor the ``missing'' \\(\\rho \\cdot \\cdb{F}_j^{(k + 1)}\\) in\n\\((1 - s) \\cdot \\cdb{F}_j^{(k + 1)}\\)\n\\item an error from the product\n  \\(\\widehat{r} \\otimes \\cdb{F}_j^{(k + 1)}\\)\n\\item an error from the product\n  \\(s \\otimes \\cdb{F}_{j + 1}^{(k + 1)}\\)\n\\item two errors from the two \\(\\oplus\\) when combining the three\n  terms in\n  \\(\\widehat{\\ell}_{F, j}^{(k)} \\oplus\n  \\left(s \\otimes \\cdb{F}_{j + 1}^{(k + 1)}\\right) \\oplus\n  \\left(\\widehat{r} \\otimes \\cdb{F}_j^{(k + 1)}\\right)\\)\n\\end{itemize}\nFor example, in~\\eqref{eq:ell-j}:\n%% H/T: https://tex.stackexchange.com/a/154333/32270\n\\begin{equation}\n\\ell_{1, j}^{(k)} =\n    \\underbrace{\\vphantom{\\rho \\cdot \\widehat{b}_j^{(k + 1)}} \\pi_1}_{\n        \\vphantom{(1 - s) \\widehat{b}_j^{(k + 1)}}\n        P_1 = \\widehat{r} \\otimes \\widehat{b}_j^{(k + 1)}} +\n    \\underbrace{\\vphantom{\\rho \\cdot \\widehat{b}_j^{(k + 1)}} \\pi_2}_{\n        \\vphantom{(1 - s) \\widehat{b}_j^{(k + 1)}}\n        P_2 = s \\otimes \\widehat{b}_{j + 1}^{(k + 1)}} +\n    \\underbrace{\\vphantom{\\rho \\cdot \\widehat{b}_j^{(k + 1)}} \\sigma_3}_{\n        \\vphantom{(1 - s) \\widehat{b}_j^{(k + 1)}}\n        P_1 \\oplus P_2} +\n    \\underbrace{\\rho \\cdot \\widehat{b}_j^{(k + 1)}}_{\n        (1 - s) \\widehat{b}_j^{(k + 1)}}\n\\end{equation}\nAfter each stage, we'll always have\n\\begin{equation}\n\\ell_{F, j}^{(k)} = e_1 + \\cdots + e_{5F - 2} + \\rho \\cdot\n\\cdb{F - 1}_j^{(k + 1)}\n\\end{equation}\nwhere the terms \\(e_1, \\ldots, e_{5F - 2}\\) come from using \\texttt{TwoSum}\nand \\texttt{TwoProd} when computing \\(\\cdb{F - 1}_j^{(k)}\\)\nand the \\(\\rho\\) term comes from the round-off\nin \\(1 \\ominus s\\) when multiplying \\((1 - s)\\) by\n\\(\\cdb{F - 1}_j^{(k + 1)}\\). With this in mind, we\ncan define an EFT (\\texttt{LocalErrorEFT}) that computes\n\\(\\widehat{\\ell}\\) and tracks all round-off errors generated in\nthe process:\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{EFT for computing the local error.}}\n  \\label{alg:local-error-eft}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\left[\\eta, \\widehat{\\ell}\\right] =\n        \\mathtt{LocalErrorEFT}\\)}{$e, \\rho, \\delta b$}\n      \\State \\(L = \\texttt{length}(e)\\)\n      \\\\\n      \\State \\(\\left[\\widehat{\\ell}, \\eta_1\\right] =\n          \\mathtt{TwoSum}(e_1, e_2)\\)\n      \\For{\\(j = 3, \\ldots, L\\)}\n        \\State \\(\\left[\\widehat{\\ell}, \\eta_{j - 1}\\right] =\n            \\mathtt{TwoSum}\\left(\\widehat{\\ell}, e_j\\right)\\)\n      \\EndFor\n      \\\\\n      \\State \\(\\left[P, \\eta_L\\right] =\n          \\mathtt{TwoProd}\\left(\\rho, \\delta b\\right)\\)\n      \\State \\(\\left[\\widehat{\\ell}, \\eta_{L + 1}\\right] =\n          \\mathtt{TwoSum}\\left(\\widehat{\\ell}, P\\right)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent With this EFT in place\\footnote{And the related\n\\texttt{LocalError} in Algorithm~\\ref{alg:local-error}}, we can\nperform \\((K - 1)\\) error filtrations. Once we've computed the \\(K\\) stages\nof global errors, they can be combined with\n\\texttt{SumK} (Algorithm~\\ref{alg:sum-k}) to produce a sum that is as\naccurate as if computed in \\(K\\) times the working precision.\n\n\\begin{breakablealgorithm}\n  \\caption{\\(K\\)-\\textit{compensated de Casteljau algorithm.}}\n  \\label{alg:k-comp-de-casteljau}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\mathtt{result} = \\mathtt{CompDeCasteljauK}\\)}{$b, s, K$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\State \\(\\left[\\widehat{r}, \\rho\\right] = \\mathtt{TwoSum}(1, -s)\\)\n      \\\\\n      \\For{\\(j = 0, \\ldots, n\\)}\n        \\State \\(\\widehat{b}_j^{(n)} = b_j\\)\n        \\For{\\(F = 1, \\ldots, K - 1\\)}\n          \\State \\(\\cdb{F}_j^{(n)} = 0\\)\n        \\EndFor\n      \\EndFor\n      \\\\\n      \\For{\\(k = n - 1, \\ldots, 0\\)}\n        \\For{\\(j = 0, \\ldots, k\\)}\n          \\State \\(\\left[P_1, \\pi_1\\right] = \\mathtt{TwoProd}\\left(\n              \\widehat{r}, \\widehat{b}_j^{(k + 1)}\\right)\\)\n          \\State \\(\\left[P_2, \\pi_2\\right] = \\mathtt{TwoProd}\\left(\n              s, \\widehat{b}_{j + 1}^{(k + 1)}\\right)\\)\n          \\State \\(\\left[\\widehat{b}_j^{(k)}, \\sigma_3\\right] =\n              \\mathtt{TwoSum}(P_1, P_2)\\)\n          \\\\\n          \\State \\(e = \\left[\\pi_1, \\pi_2, \\sigma_3\\right]\\)\n          \\State \\(\\delta b = \\widehat{b}_j^{(k + 1)}\\)\n          \\\\\n          \\For{\\(F = 1, \\ldots, K - 2\\)}\n            \\State \\(\\left[\\eta, \\widehat{\\ell}\\right] =\n                \\mathtt{LocalErrorEFT}(e, \\rho, \\delta b)\\)\n            \\State \\(L = \\texttt{length}(\\eta)\\)\n            \\\\\n            \\State \\(\\left[P_1, \\eta_{L + 1}\\right] = \\mathtt{TwoProd}\\left(\n                s, \\cdb{F}_{j + 1}^{(k + 1)}\\right)\\)\n            \\State \\(\\left[S_2, \\eta_{L + 2}\\right] =\n                \\mathtt{TwoSum}\\left(\\widehat{\\ell}, P_1\\right)\\)\n            \\State \\(\\left[P_3, \\eta_{L + 3}\\right] = \\mathtt{TwoProd}\\left(\n                \\widehat{r}, \\cdb{F}_j^{(k + 1)}\\right)\\)\n            \\State \\(\\left[\\cdb{F}_j^{(k)}, \\eta_{L + 4}\\right]\n                = \\mathtt{TwoSum}\\left(S_2, P_3\\right)\\)\n            \\\\\n            \\State \\(e = \\eta\\)\n            \\State \\(\\delta b = \\cdb{F}_j^{(k + 1)}\\)\n          \\EndFor\n          \\\\\n          \\State \\(\\widehat{\\ell} =\n                \\mathtt{LocalError}(e, \\rho, \\delta b)\\)\n          \\State \\(\\cdb{K - 1}_j^{(k)} =\n              \\widehat{\\ell} \\oplus\n              \\left(s \\otimes \\cdb{K - 1}_{j + 1}^{(k + 1)}\n              \\right) \\oplus\n              \\left(\\widehat{r} \\otimes\n              \\cdb{K - 1}_j^{(k + 1)}\\right)\\)\n        \\EndFor\n      \\EndFor\n      \\\\\n      \\State \\(\\mathtt{result} = \\mathtt{SumK}\\left(\\left[\n        \\widehat{b}_0^{(0)}, \\ldots, \\cdb{K - 1}_0^{(0)}\\right], K\\right)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\noindent Noting that \\(\\ell_{F, j}\\) contains \\(5F - 1\\) terms, one can\nshow that \\texttt{CompDeCasteljauK} (Algorithm~\\ref{alg:k-comp-de-casteljau})\nrequires\n\\begin{equation}\n(15K^2 + 11K - 34)T_n + 6K^2 - 11K + 11 =\n\\bigO{n^2 K^2}\n\\end{equation}\nflops to evaluate a degree \\(n\\) polynomial, where \\(T_n\\) is the\n\\(n\\)th triangular number. As a comparison, the non-compensated form of\nde Casteljau requires \\(3 T_n + 1\\) flops. In total this will require\n\\((3K - 4)T_n\\) uses of \\texttt{TwoProd}. On hardware that supports\nFMA, \\texttt{TwoProdFMA} (Algorithm~\\ref{alg:two-prod-fma}) can be used\ninstead, lowering the flop count by \\(15(3K - 4)T_n\\). Another way\nto lower the total flop count is to just use\n\\(\\widehat{b}_0^{(0)} \\oplus \\cdots \\oplus \\cdb{K - 1}_0^{(0)}\\)\ninstead of \\texttt{SumK}; this will reduce the total by\n\\(6(K - 1)^2\\) flops. When using a standard sum, the results produced\nare (empirically) identical to those with \\texttt{SumK}. This makes\nsense: the whole point of \\texttt{SumK}\nis to filter errors in a summation so that the final operation produces\na sum of the form \\(v_1 \\oplus \\cdots \\oplus v_K\\) where each\nterm is smaller than the previous by a factor of \\(\\mach\\). This\nproperty is already satisfied for the \\(\\cdb{F}_0^{(0)}\\) so in\npractice the \\(K\\)-compensated summation is likely not needed.\n\n\\subsection{Error bound for polynomial evaluation}\n\n\\begin{theorem}[\\cite{Ogita2005}, Proposition 4.10]\\label{thm:sum-k}\nA summation can be computed (\\texttt{SumK}, Algorithm~\\ref{alg:sum-k})\nwith results that are as accurate as if computed in \\(K\\) times the\nworking precision. When computed this way, the result satisfies:\n\\begin{equation}\n\\left|\\mathtt{SumK}(v, K) - \\sum_{j = 1}^n v_j\\right| \\leq\n\\left(\\mach + 3 \\gamma_{n - 1}^2\\right) \\left|\\sum_{j = 1}^n v_j\\right| +\n\\gamma_{2n - 2}^K \\sum_{j = 1}^n \\left|v_j\\right|.\n\\end{equation}\n\\end{theorem}\n\n\\begin{lemma}[\\cite{Jiang2010}, Theorem 4]\\label{lemma:db-lemma}\nThe second order error \\(\\db{2}^{(0)}_0\\) satisfies\\footnote{The authors\n  missed one round-off error so used \\(\\gamma_{3n + 1}\\) where\n  \\(\\gamma_{3n + 2}\\) would have followed from their arguments.}\n\\begin{equation}\n  \\left|\\db{1}^{(0)}_0 - \\cdb{1}^{(0)}_0\\right| =\n  \\left|\\db{2}^{(0)}_0\\right| \\leq 2 \\gamma_{3n + 2} \\gamma_{3(n - 1)}\n  \\widetilde{p}(s).\n\\end{equation}\n\\end{lemma}\n\nTo enable a bound on the \\(K\\) order error \\(\\db{K}^{(0)}_0\\), it's necessary\nto understand the difference between the exact local errors \\(\\ell_{F, j}\\)\nand the computed equivalents \\(\\widehat{\\ell}_{F, j}\\). To do this, we define\n\\begin{equation}\n\\widetilde{\\ell}_{F, j} \\coloneqq \\left|e_1\\right| +\n\\cdots + \\left|e_{5F - 2}\\right| + \\left|\\rho \\cdot\n\\cdb{F - 1}_j^{(k + 1)}\\right|.\n\\end{equation}\n\n\\begin{lemma}\\label{lemma:ell-tilde}\nThe local error bounds \\(\\widetilde{\\ell}_{F, j}\\) satisfy:\n\\begin{align}\n\\widetilde{\\ell}_{1, j}^{(k)} &\\leq\n  \\gamma_3 \\left(\n  (1 - s) \\left|\\widehat{b}_j^{(k + 1)}\\right| +\n  s \\left|\\widehat{b}_{j + 1}^{(k + 1)}\\right|\\right)\n  \\label{eq:ell-tilde-1} \\\\\n\\widetilde{\\ell}_{F + 1, j}^{(k)} &\\leq\n  \\gamma_3 \\left(\n  (1 - s) \\left|\\cdb{F}_j^{(k + 1)}\\right| +\n  s \\left|\\cdb{F}_{j + 1}^{(k + 1)}\\right|\\right) +\n  \\gamma_{5F} \\cdot \\widetilde{\\ell}_{F, j}^{(k)}\n  \\text{ for } F \\geq 1.\n\\end{align}\n\\end{lemma}\n\n\\begin{proof}\nSee proof in Section~\\ref{proof:ell-tilde}.\n\\end{proof}\n\nAs we'll see soon (Lemma~\\ref{lemma:k-order}), putting a bound on\nsums of the form \\(\\sum_{j = 0}^k \\ell_{F, j}^{(k)} B_{j, k}(s)\\) will\nbe useful to get an overall bound on the relative error for\n\\texttt{CompDeCasteljauK}, so we define\n\\(L_{F, k} \\coloneqq \\sum_{j = 0}^k \\ell_{F, j}^{(k)} B_{j, k}(s)\\).\n\n\\begin{lemma}\\label{lemma:L-and-D-bounds}\nFor \\(s \\in \\left[0, 1\\right]\\), the Bernstein-type error sum defined above\nsatisfies the following bounds:\n\\begin{align}\nL_{F, n - k} &\\leq \\left[\\left(3^F \\binom{k}{F - 1} + \\bigO{k^{F - 1}}\\right)\n  \\mach^F + \\bigO{\\mach^{F + 1}}\\right] \\cdot \\widetilde{p}(s) \\\\\n\\sum_{k = 0}^{n - 1} \\gamma_{3k + 5F} L_{F, k} &\\leq\n  \\left[\\left(3^{F + 1} \\binom{n}{F + 1} + \\bigO{n^F}\\right)\n  \\mach^{F + 1} + \\bigO{\\mach^{F + 2}}\\right] \\cdot \\widetilde{p}(s).\n  \\label{eq:L-sum-bound}\n\\end{align}\nIn particular, this means that\n\\(\\sum_{k = 0}^{n - 1} \\gamma_{3k + 5F} L_{F, k} =\n\\bigO{(3 n \\mach)^{F + 1}} \\cdot \\widetilde{p}(s)\\).\n\\end{lemma}\n\n\\begin{proof}\nSee proof in Section~\\ref{proof:L-and-D-bounds}.\n\\end{proof}\n\n\\begin{lemma}\\label{lemma:k-order}\nThe \\(K\\) order error \\(\\db{K}^{(0)}_0\\) satisfies\n\\begin{equation}\n  \\left|\\db{K - 1}^{(0)}_0 - \\cdb{K - 1}^{(0)}_0\\right| =\n  \\left|\\db{K}^{(0)}_0\\right| \\leq\n  \\left[\\left(3^{K} \\binom{n}{K} + \\bigO{n^{K - 1}}\\right)\n  \\mach^{K} + \\bigO{\\mach^{K + 1}}\\right] \\cdot \\widetilde{p}(s).\n\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\nSee proof in Section~\\ref{proof:k-order}.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:k-comp-result}\nIf no underflow occurs, \\(n \\geq 2\\) and \\(s \\in \\left[0, 1\\right]\\)\n\\begin{multline}\n  \\frac{\\left|p(s) - \\mathtt{CompDeCasteljau}(p, s, K)\\right|}{\n    \\left|p(s)\\right|} \\leq \\left[\\mach + \\bigO{\\mach^2}\n    \\right] + \\\\\n    \\left[\\left(3^{K} \\binom{n}{K} + \\bigO{n^{K - 1}}\\right) \\mach^K +\n    \\bigO{\\mach^{K + 1}}\\right] \\cond{p, s}.\n\\end{multline}\n\\end{theorem}\n\n\\begin{proof}\nSee proof in Section~\\ref{proof:k-comp-result}.\n\\end{proof}\n\nFor the first few values of \\(K\\) the coefficient of\n\\(\\cond{p, s}\\) in the bound is\n\\begin{center}\n  \\begin{tabular}{>{$}c<{$} c >{$}c<{$}}\n    K & Method & \\text{Multiplier} \\\\\n    \\midrule\n    1 & \\texttt{DeCasteljau} & 3 \\binom{n}{1} \\mach =\n      3n \\mach \\approx \\gamma_{3n} \\\\[0.125cm]\n    2 & \\texttt{CompDeCasteljau} & \\left[9 \\binom{n}{2} +\n      15 \\binom{n}{1}\\right]\\mach^2 = \\frac{3n(3n + 7)}{2} \\mach^2\n      \\approx \\frac{1}{4} \\cdot 2 \\gamma_{3n}^2 \\\\[0.125cm]\n    3 & \\texttt{CompDeCasteljau3} & \\left[27 \\binom{n}{3} +\n      135 \\binom{n}{2} + 150 \\binom{n}{1}\\right] \\mach^3 =\n      \\frac{3n(3n^2 + 36n + 61)}{2} \\mach^3 \\\\[0.125cm]\n    4 & \\texttt{CompDeCasteljau4} & \\left[81 \\binom{n}{4} + 810 \\binom{n}{3} +\n      2475 \\binom{n}{2} + 2250 \\binom{n}{1}\\right] \\mach^4 \\\\[0.125cm]\n  \\end{tabular}\n\\end{center}\nSee the proof (Section~\\ref{proof:L-and-D-bounds}) of\nLemma~\\ref{lemma:L-and-D-bounds} for more details on where these\npolynomials come from.\n\n\\section{Numerical experiments}\\label{sec:numerical}\n\n\\begin{figure}\n  \\includegraphics{../images/k-compensated/de_casteljau_smooth_drawing.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Evaluation of \\(p(s) = (s - 1)\\left(s - 3/4\\right)^7\\)\n    in the neighborhood of its multiple root \\(3/4\\).}\n  \\label{fig:smooth-drawing}\n\\end{figure}\n\nAll experiments were performed in IEEE-754 double precision.\nAs in \\cite{Jiang2010}, we consider the evaluation in the neighborhood\nof the multiple root of \\(p(s) = (s - 1)\\left(s - 3/4\\right)^7\\),\nwritten in Bernstein form.\nFigure~\\ref{fig:smooth-drawing} shows the evaluation of \\(p(s)\\) at\nthe 401 equally spaced\\footnote{It's worth noting that \\(0.1\\) cannot\nbe represented exactly in IEEE-754 double precision (or any binary\narithmetic for that matter). Hence (most of) the points of the form\n\\(a + b \\cdot 10^{-c}\\) can only be approximately represented.} points\n\\(\\left\\{\\frac{3}{4} + j \\frac{10^{-7}}{2}\\right\\}_{j=-200}^{200}\\)\nwith \\texttt{DeCasteljau} (Algorithm~\\ref{alg:de-casteljau}),\n\\texttt{CompDeCasteljau} (Algorithm~\\ref{alg:comp-de-casteljau})\nand \\texttt{CompDeCasteljau3} (Algorithm~\\ref{alg:k-comp-de-casteljau}\nwith \\(K = 3\\)). We see that \\texttt{DeCasteljau} fails to get the\nmagnitude correct, \\texttt{CompDeCasteljau} has the right shape but\nlots of noise and \\texttt{CompDeCasteljau3} is able to smoothly evaluate\nthe function. This is in contrast to a similar figure in \\cite{Jiang2010},\nwhere the plot was smooth for the 400 equally spaced points\n\\(\\left\\{\\frac{3}{4} + \\frac{10^{-4}}{2} \\frac{2j - 399}{399}\n\\right\\}_{j=0}^{399}\\). The primary difference is that as the interval\nshrinks by a factor of \\(\\approx \\frac{10^{-4}}{10^{-7}} = 10^3\\), the\ncondition number goes up by \\(\\approx 10^{21}\\) and \\texttt{CompDeCasteljau}\nis no longer accurate.\n\n\\begin{figure}\n  \\includegraphics{../images/k-compensated/de_casteljau_rel_error.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Accuracy of evaluation of \\(p(s) = (s - 1)\\left(s - 3/4\\right)^7\\)\n    represented in Bernstein form.}\n  \\label{fig:compensated-k}\n\\end{figure}\n\nFigure~\\ref{fig:compensated-k} shows the relative forward errors compared\nagainst the condition number. To compute relative errors, each input and\ncoefficient is converted to a fraction (i.e. infinite precision) and\n\\(p(s)\\) is computed exactly as a fraction, then\ncompared to the corresponding computed values. Similar tools are used to\n\\emph{exactly} compute the condition number, though here we can rely\non the fact that \\(\\widetilde{p}(s) = (s - 1)\n\\left(s/2 - 3/4\\right)^7\\). Once the relative errors and\ncondition numbers are computed as fractions, they are rounded to the\nnearest IEEE-754 double precision value. As in \\cite{Jiang2010}, we use\nvalues \\(\\left\\{\\frac{3}{4} - (1.3)^j\\right\\}_{j=-5}^{-90}\\)\\footnote{As with\n\\(0.1\\), it's worth noting that \\((1.3)^j\\) can't be represented exactly in\nIEEE-754 double precision. However, this geometric series still serves a\nuseful purpose since it continues to raise \\(\\cond{p, s}\\) as \\(j\\) decreases\naway from \\(0\\) and because it results in ``random'' changes in the bits of\n\\(0.75\\) that are impacted by subtracting \\((1.3)^j\\).}. The curves for\n\\texttt{DeCasteljau} and \\texttt{CompDeCasteljau} trace the same paths seen\nin \\cite{Jiang2010}. In particular, \\texttt{CompDeCasteljau} has a relative\nerror that is \\(\\bigO{\\mach}\\) until \\(\\cond{p, s}\\) reaches\n\\(1 / \\mach\\), at which point the relative error increases linearly with\nthe condition number until it becomes \\(\\bigO{1}\\) when\n\\(\\cond{p, s}\\) reaches \\(1 / \\mach^2\\).\nSimilarly, the relative error in \\texttt{CompDeCasteljau3}\n(Algorithm~\\ref{alg:k-comp-de-casteljau} with \\(K = 3\\))\nis \\(\\bigO{\\mach}\\) until \\(\\cond{p, s}\\) reaches\n\\(1 / \\mach^2\\) at which point the relative error increases linearly\nto \\(\\bigO{1}\\) when \\(\\cond{p, s}\\) reaches \\(1 / \\mach^3\\)\nand the relative error in \\texttt{CompDeCasteljau4}\n(Algorithm~\\ref{alg:k-comp-de-casteljau} with \\(K = 4\\))\nis \\(\\bigO{\\mach}\\) until \\(\\cond{p, s}\\) reaches\n\\(1 / \\mach^3\\) at which point the relative error increases linearly\nto \\(\\bigO{1}\\) when \\(\\cond{p, s}\\) reaches \\(1 / \\mach^4\\).\n", "meta": {"hexsha": "7314335dec6d617fe38d9d248fb89bef0beb1dd1", "size": 31562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/k-compensated.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/k-compensated.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/k-compensated.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": 43.8361111111, "max_line_length": 79, "alphanum_fraction": 0.6405170775, "num_tokens": 11471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.6517621534582287}}
{"text": "\\chapter{Miscellaneous Transformations}\r\n\\section{Fresnel Term - Schlick's approximation}\r\nThe \\emph{Fresnel equations} describes the reflection and transmission of a electromagnetic wave at an interface. The Fresnel equation provides a reflection and transmission coefficients for waves. In Computer Graphics we often use the \\emph{Schlick's approximation}. The specular reflection coefficient $R$ of the Fresnel equation can be approximated by:\r\n\r\n\\begin{equation}\r\n R(\\theta) = R_0 + (1 - R_0)(1 - \\cos \\theta)^5\r\n\\label{eq:schlickapprox}\r\n\\end{equation}\r\n\r\nand\r\n\r\n\\begin{equation*}\r\n  R_0 = \\left(\\frac{n_1-n_2}{n_1+n_2}\\right)^2\r\n\\end{equation*}\r\n\r\nwhere $\\theta$ is the angle between the viewing direction and the half-angle direction. This is equal to the halfway between the incident \r\nlight direction and the viewing direction, i.e. $\\cos \\theta = (H \\cdot V)$. $n_1$ $n_2$ are the refraction indices of the two medias. $R_0$ is the reflection coefficient for light incoming parallel to the normal (i.e., the value of the Fresnel term when $\\theta = 0 \\degree$ or minimal reflection). In Computer Graphics one of the interfaces is usually air, meaning that $n_1$ is approximately equal to 1.\r\n\r\n\\section{Spherical Coordinates and Space Transformation}\r\n\\label{sec:sphericalcoordinates}\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[scale=0.35]{sphericalcoordinates.png}\r\n  \\caption[Illustration of Spherical Coordinate System]{Illustration$\\footnotemark$ of Spherical coordinates $(r,θ,φ)$ radius $r$, polar (inclination) angle $\\theta$, and azimuthal angle $\\phi$.}\r\n  \\label{fig:sphericalcoordinatesystem}\r\n\\end{figure}\r\n\\footnotetext{image source of figure $\\ref{fig:sphericalcoordinatesystem}$ \\texttt{http://en.wikipedia.org/wiki/Spherical\\textunderscore coordinate\\textunderscore system}} \r\n\r\nTo define a \\emph{spherical coordinate} system as shown in figure $\\ref{fig:sphericalcoordinatesystem}$ we need two particular angles, the \\emph{polar angle} $\\theta$ and the \\emph{azimuthal} $\\phi$ plus a radius $r$. Then the Cartesian coordinates $(x,y,z)$ may be retrieved from their spherical coordinate representation as the following: $\\forall \\colvec[x]{y}{z} \\in \\mathbb{R}^3 : \\exists r \\in [0,\\infty) \\exists \\phi \\in [0,2\\pi] \\exists \\theta \\in [0,\\pi] $ s.t.\r\n\\begin{equation*}\r\n\\colvec[x]{y}{z} = \\colvec[r sin(\\theta)cos(\\phi)]{r sin(\\theta)sin(\\phi)}{r cos(\\theta)}\r\n\\label{eq:sphericalcoordinates}\r\n\\end{equation*}\r\n\r\n\\label{sec:componentw}\r\nFrom the definition $\\ref{eq:uvw}$ of $(u,v,w)= -\\omega_i - \\omega_r$ and using spherical coordinates $\\ref{eq:sphericalcoordinates}$, we get for $w$ the following identity:\r\n\r\n\\begin{align}\r\nw \r\n&= -\\omega_i - \\omega_r \\nonumber \\\\ \r\n&= -(\\omega_i + \\omega_r) \\nonumber \\\\\r\n&= -\\left( cos(\\theta_i)+cos(\\theta_r) \\right) \r\n\\label{eq:sphericalomega}\r\n\\end{align}\r\n\r\nand therefore $w^2$ is equal $(cos(\\theta_i)+cos(\\theta_r))^2$. \r\n\r\n\\section{Tangent Space}\r\n\\label{sec:tangentspace}\r\nThe concept of performing a transformation into the \\emph{tangent space} is used in order to convert a point between the world and and its local (tangent) space.  \\\\\r\n\r\nWe can think of the tangent space as a bumpy surface defined on a flat plane. If the normals of a fragment were defined in a world space coordinate system, we would have to rotate these normals every time the model is rotated - even when just for a small amount. Since lights, the camera and other scene primitives usually are defined in the world space coordinate system we would to have to rotate them according to every fragment position. This would require to apply countless many object-to-world transformations at a pixel level. The workaround for this issue is to transform all vertex primitives into tangent space in the vertex shader. \\\\\r\n\r\nTo make this point clear: Even we would rotate the cube as shown in figure $\\ref{fig:cubeintangentspace}$, its tangent space axis will remain aligned w.r.t its face. This will save us from apply many space transformations on fragments.\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[scale=0.6]{tangentspace.png}\r\n  \\caption[Illustration of a Tangent Space]{Cube in world space $(x,y,z)$ showing the tangent-space $(u,v,n)$ of its face $(2,1,3)$}\r\n  \\label{fig:cubeintangentspace}\r\n\\end{figure}\r\n", "meta": {"hexsha": "d4f5fe3e19e39e9ff82e7dcf6ac5adccd8206859", "size": 4280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/Source/Chapters/appendix.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.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.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": 69.0322580645, "max_line_length": 647, "alphanum_fraction": 0.7448598131, "num_tokens": 1141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6517621476846563}}
{"text": "\\chapter{数学}\n\n\\section{数学符号}\n\n模板定义了一些正体（upright）的数学符号：\n\\begin{center}\n\\begin{tabular}{rl}\n  \\toprule\n    符号                 & 命令 \\\\\n  \\midrule\n    常数$\\eu$     & \\verb|\\eu| \\\\\n    复数单位$\\iu$ & \\verb|\\iu| \\\\\n    微分符号$\\diff$ & \\verb|\\diff| \\\\\n    $\\argmax$         & \\verb|\\argmax| \\\\\n    $\\argmin$         & \\verb|\\argmin| \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{center}\n\n更多的例子：\n\\begin{equation}\n  \\eu^{\\iu\\pi} + 1 = 0\n\\end{equation}\n\\begin{equation}\n  \\frac{\\diff^2u}{\\diff t^2} = \\int f(x) \\diff x\n\\end{equation}\n\\begin{equation}\n  \\argmin_x f(x)\n\\end{equation}\n\n\\section{定理、引理和证明}\n\n\\begin{definition}\n    If the integral of function $f$ is measurable and non-negative, we define\n    its (extended) \\textbf{Lebesgue integral} by\n    \\begin{equation}\n        \\int f = \\sup_g \\int g,\n    \\end{equation}\n    where the supremum is taken over all measurable functions $g$ such that\n    $0 \\leq g \\leq f$, and where $g$ is bounded and supported on a set of\n    finite measure.\n\\end{definition}\n\n\\begin{example}\n    Simple examples of functions on $\\mathbb{R}^d$ that are integrable\n    (or non-integrable) are given by\n    \\begin{equation}\n        f_a(x) =\n        \\begin{cases}\n            |x|^{-a} & \\text{if } |x| \\leq 1,\\\\\n            0 & \\text{if } x > 1.\n        \\end{cases}\n    \\end{equation}\n    \\begin{equation}\n        F_a(x) = \\frac{1}{1 + |x|^a}, \\qquad \\text{all } x \\in \\mathbb{R}^d.\n    \\end{equation}\n    Then $f_a$ is integrable exactly when $a < d$, while $F_a$ is integrable\n    exactly when $a > d$.\n\\end{example}\n\n\\begin{lemma}[Fatou]\n    Suppose $\\{f_n\\}$ is a sequence of measurable functions with $f_n \\geq 0$.\n    If $\\lim_{n \\to \\infty} f_n(x) = f(x)$ for a.e. $x$, then\n    \\begin{equation}\n        \\int f \\leq \\liminf_{n \\to \\infty} \\int f_n.\n    \\end{equation}\n\\end{lemma}\n\n\\begin{remark}\n    We do not exclude the cases $\\int f = \\infty$,\n    or $\\liminf_{n \\to \\infty} f_n = \\infty$.\n\\end{remark}\n\n\\begin{corollary}\n    Suppose $f$ is a non-negative measurable function, and $\\{f_n\\}$ a sequence\n    of non-negative measurable functions with\n    $f_n(x) \\leq f(x)$ and $f_n(x) \\to f(x)$ for almost every $x$. Then\n    \\begin{equation}\n        \\lim_{n \\to \\infty} \\int f_n = \\int f.\n    \\end{equation}\n\\end{corollary}\n\n\\begin{proposition}\n    Suppose $f$ is integrable on $\\mathbb{R}^d$. Then for every $\\epsilon > 0$:\n    \\begin{enumerate}\n        \\renewcommand{\\theenumi}{\\roman{enumi}}\n        \\item There exists a set of finite measure $B$ (a ball, for example) such that\n        \\begin{equation}\n            \\int_{B^c} |f| < \\epsilon.\n        \\end{equation}\n        \\item There is a $\\delta > 0$ such that\n        \\begin{equation}\n            \\int_E |f| < \\epsilon \\qquad \\text{whenever } m(E) < \\delta.\n        \\end{equation}\n    \\end{enumerate}\n\\end{proposition}\n\n\\begin{theorem}\n    Suppose $\\{f_n\\}$ is a sequence of measurable functions such that\n    $f_n(x) \\to f(x)$ a.e. $x$, as $n$ tends to infinity.\n    If $|f_n(x)| \\leq g(x)$, where $g$ is integrable, then\n    \\begin{equation}\n        \\int |f_n - f| \\to 0 \\qquad \\text{as } n \\to \\infty,\n    \\end{equation}\n    and consequently\n    \\begin{equation}\n        \\int f_n \\to \\int f \\qquad \\text{as } n \\to \\infty.\n    \\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n    Trivial.\n\\end{proof}\n\n\n\n\\section{自定义}\n\n\\newtheorem*{axiomofchoice}{Axiom of choice}\n\\begin{axiomofchoice}\n    Suppose $E$ is a set and ${E_\\alpha}$ is a collection of\n    non-empty subsets of $E$. Then there is a function $\\alpha\n    \\mapsto x_\\alpha$ (a ``choice function'') such that\n    \\begin{equation}\n        x_\\alpha \\in E_\\alpha,\\qquad \\text{for all }\\alpha.\n    \\end{equation}\n\\end{axiomofchoice}\n\n\\newtheorem{observation}{Observation}\n\\begin{observation}\n    Suppose a partially ordered set $P$ has the property\n    that every chain has an upper bound in $P$. Then the\n    set $P$ contains at least one maximal element.\n\\end{observation}\n\\begin{proof}[A concise proof]\n    Obvious.\n\\end{proof}\n", "meta": {"hexsha": "c6672e31f3bc227a6fb97a4732c7d132e1eb97b2", "size": 3952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/math.tex", "max_stars_repo_name": "ustcanycall/graduate", "max_stars_repo_head_hexsha": "4c92658dfd4069b3697b1590a0b2b9b61ef35019", "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/math.tex", "max_issues_repo_name": "ustcanycall/graduate", "max_issues_repo_head_hexsha": "4c92658dfd4069b3697b1590a0b2b9b61ef35019", "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/math.tex", "max_forks_repo_name": "ustcanycall/graduate", "max_forks_repo_head_hexsha": "4c92658dfd4069b3697b1590a0b2b9b61ef35019", "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": 28.6376811594, "max_line_length": 86, "alphanum_fraction": 0.6065283401, "num_tokens": 1389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765706, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6517621412519952}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath,amssymb,amsfonts}\n\\usepackage{textcomp}\n\\usepackage{fullpage}\n\\usepackage{setspace}\n\\usepackage{float}\n\\usepackage{cite}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage[pdfborder={0 0 0}, pdfpagemode=UseNone, pdfstartview=FitH]{hyperref}\n\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\n\\def\\keyterm{\\textit}\n\n\\newcommand{\\transp}{{\\scriptstyle{\\mathsf{T}}}}\n\n\n\n\\begin{document}\n\n\\title{Graph SLAM Formulation}\n\\author{Jeff Irion}\n\\date{}\n\n\\maketitle\n\\vspace{3em}\n\n\n\\section{Problem Formulation}\n\nLet a robot's trajectory through its environment be represented by a sequence of $N$ poses: $\\mathbf{p}_1, \\mathbf{p}_2, \\ldots, \\mathbf{p}_N$.  Each pose lies on a manifold: $\\mathbf{p}_i \\in \\mathcal{M}$.  Simple examples of manifolds used in Graph SLAM include 1-D, 2-D, and 3-D space, i.e., $\\mathbb{R}$, $\\mathbb{R}^2$, and $\\mathbb{R}^3$.  These environments are \\keyterm{rectilinear}, meaning that there is no concept of orientation.  By contrast, in $SE(2)$ problem settings a robot's pose consists of its location in $\\mathbb{R}^2$ and its orientation $\\theta$.  Similarly, in $SE(3)$ a robot's pose consists of its location in $\\mathbb{R}^3$ and its orientation, which can be represented via Euler angles, quaternions, or $SO(3)$ rotation matrices.  \n\nAs the robot explores its environment, it collects a set of $M$ measurements $\\mathcal{Z} = \\{\\mathbf{z}_j\\}$.  Examples of such measurements include odometry, GPS, and IMU data.  Given a set of poses $\\mathbf{p}_1, \\ldots, \\mathbf{p}_N$, we can compute the estimated measurement $\\hat{\\mathbf{z}}_j(\\mathbf{p}_1, \\ldots, \\mathbf{p}_N)$.  We can then compute the \\keyterm{residual} $\\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j)$ for measurement $j$.  The formula for the residual depends on the type of measurement.  As an example, let $\\mathbf{z}_1$ be an odometry measurement that was collected when the robot traveled from $\\mathbf{p}_1$ to $\\mathbf{p}_2$.  The expected measurement and the residual are computed as\n%\n\\begin{align*}\n    \\hat{\\mathbf{z}}_1(\\mathbf{p}_1, \\mathbf{p}_2) &= \\mathbf{p}_2 \\ominus \\mathbf{p}_1 \\\\\n    \\mathbf{e}_1(\\mathbf{z}_1, \\hat{\\mathbf{z}}_1) &= \\mathbf{z}_1 \\ominus \\hat{\\mathbf{z}}_1 = \\mathbf{z}_1 \\ominus (\\mathbf{p}_2 \\ominus \\mathbf{p}_1),\n\\end{align*}\n%\nwhere the $\\ominus$ operator indicates inverse pose composition.  We model measurement $\\mathbf{z}_j$ as having independent Gaussian noise with zero mean and covariance matrix $\\Omega_j^{-1}$; we refer to $\\Omega_j$ as the \\keyterm{information matrix} for measurement $j$.  That is,\n\\begin{equation}\n    p(\\mathbf{z}_j \\ | \\ \\mathbf{p}_1, \\ldots, \\mathbf{p}_N) = \\eta_j \\exp \\left( (-\\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j))^\\transp \\Omega_j \\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j) \\right), \\label{eq:observation_probability}\n\\end{equation}\nwhere $\\eta_j$ is the normalization constant.\n\nThe objective of Graph SLAM is to find the maximum likelihood set of poses given the measurements $\\mathcal{Z} = \\{\\mathbf{z}_j\\}$; in other words, we want to find \n%\n\\begin{equation*}\n    \\argmax_{\\mathbf{p}_1, \\ldots, \\mathbf{p}_N} \\ p(\\mathbf{p}_1, \\ldots, \\mathbf{p}_N \\ | \\ \\mathcal{Z}) \n\\end{equation*}\n%\nUsing Bayes' rule, we can write this probability as\n%\n\\begin{align}\n    p(\\mathbf{p}_1, \\ldots, \\mathbf{p}_N \\ | \\ \\mathcal{Z}) &= \\frac{p( \\mathcal{Z} \\ | \\ \\mathbf{p}_1, \\ldots, \\mathbf{p}_N) p(\\mathbf{p}_1, \\ldots, \\mathbf{p}_N) }{ p(\\mathcal{Z}) } \\notag \\\\\n    &\\propto p( \\mathcal{Z} \\ | \\ \\mathbf{p}_1, \\ldots, \\mathbf{p}_N), \\label{eq:bayes}\n\\end{align}\n%\nsince $p(\\mathcal{Z})$ is a constant (albeit, an unknown constant) and we assume that $p(\\mathbf{p}_1, \\ldots, \\mathbf{p}_N)$ is uniformly distributed \\cite{thrun2006graph}.  Therefore, we can use \\eqref{eq:observation_probability} and \\eqref{eq:bayes} to simplify the Graph SLAM optimization as follows:\n%\n\\begin{align*}\n    \\argmax_{\\mathbf{p}_1, \\ldots, \\mathbf{p}_N} \\ p(\\mathbf{p}_1, \\ldots, \\mathbf{p}_N \\ | \\ \\mathcal{Z}) &= \\argmax_{\\mathbf{p}_1, \\ldots, \\mathbf{p}_N} \\ p( \\mathcal{Z} \\ | \\ \\mathbf{p}_1, \\ldots, \\mathbf{p}_N) \\\\\n    &= \\argmax_{\\mathbf{p}_1, \\ldots, \\mathbf{p}_N} \\prod_{j=1}^M p(\\mathbf{z}_j \\ | \\ \\mathbf{p}_1, \\ldots, \\mathbf{p}_N) \\\\\n    &= \\argmax_{\\mathbf{p}_1, \\ldots, \\mathbf{p}_N} \\prod_{j=1}^M \\exp \\left( -(\\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j))^\\transp \\Omega_j \\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j) \\right) \\\\\n    &= \\argmin_{\\mathbf{p}_1, \\ldots, \\mathbf{p}_N} \\sum_{j=1}^M (\\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j))^\\transp \\Omega_j \\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j).\n\\end{align*}\n%\nWe define\n%\n\\begin{equation*}\n    \\chi^2 := \\sum_{j=1}^M (\\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j))^\\transp \\Omega_j \\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j),\n\\end{equation*}\n%\nand this is what we seek to minimize.\n\n\n\\section{Dimensionality and Pose Representation}\n\nBefore proceeding further, it is helpful to discuss the dimensionality of the problem.  We have:\n\\begin{itemize}\n  \\item A set of $N$ poses $\\mathbf{p}_1, \\mathbf{p}_2, \\ldots, \\mathbf{p}_N$, where each pose lies on the manifold $\\mathcal{M}$\n  \\begin{itemize}\n    \\item Each pose $\\mathbf{p}_i$ is represented as a vector in (a subset of) $\\mathbb{R}^d$.  For example:\n    \\begin{itemize}\n      \\item[$\\circ$] An $SE(2)$ pose is typically represented as $(x, y, \\theta)$, and thus $d = 3$.\n      \\item[$\\circ$] An $SE(3)$ pose is typically represented as $(x, y, z, q_x, q_y, q_z, q_w)$, where $(x, y, z)$ is a point in $\\mathbb{R}^3$ and $(q_x, q_y, q_z, q_w)$ is a \\keyterm{quaternion}, and so $d = 7$.  For more information about $SE(3)$ parameterizations and pose transformations, see \\cite{blanco2010tutorial}.\n    \\end{itemize}\n    \\item We also need to be able to represent each pose compactly as a vector in (a subset of) $\\mathbb{R}^c$.\n    \\begin{itemize}\n      \\item[$\\circ$] Since an $SE(2)$ pose has three degrees of freedom, the $(x, y, \\theta)$ representation is again sufficient and $c=3$.  \n      \\item[$\\circ$] An $SE(3)$ pose only has six degrees of freedom, and we can represent it compactly as $(x, y, z, q_x, q_y, q_z)$, and thus $c=6$.\n    \\end{itemize}\n    \\item We use the $\\boxplus$ operator to indicate pose composition when one or both of the poses are represented compactly.  The output can be a pose in $\\mathcal{M}$ or a vector in $\\mathbb{R}^c$, as required by context.\n  \\end{itemize}\n  \\item A set of $M$ measurements $\\mathcal{Z} = \\{\\mathbf{z}_1, \\mathbf{z}_2, \\ldots, \\mathbf{z}_M\\}$\n  \\begin{itemize}\n    \\item Each measurement's dimensionality can be unique, and we will use $\\bullet$ to denote a ``wildcard'' variable.\n    \\item Measurement $\\mathbf{z}_j \\in \\mathbb{R}^\\bullet$ has an associated information matrix $\\Omega_j \\in \\mathbb{R}^{\\bullet \\times \\bullet}$ and residual function $\\mathbf{e}_j(\\mathbf{z}_j, \\hat{\\mathbf{z}}_j) = \\mathbf{e}_j(\\mathbf{z}_j, \\mathbf{p}_1, \\ldots, \\mathbf{p}_N) \\in \\mathbb{R}^\\bullet$.\n    \\item A measurement could, in theory, constrain anywhere from 1 pose to all $N$ poses.  In practice, each measurement usually constrains only 1 or 2 poses.  \n  \\end{itemize}\n\\end{itemize}\n\n\n\\section{Graph SLAM Algorithm}\n\nThe ``Graph'' in Graph SLAM refers to the fact that we view the problem as a graph.  The graph has a set $\\mathcal{V}$ of $N$ vertices, where each vertex $v_i$ has an associated pose $\\mathbf{p}_i$.  Similarly, the graph has a set $\\mathcal{E}$ of $M$ edges, where each edge $e_j$ has an associated measurement $\\mathbf{z}_j$.  In practice, the edges in this graph are either unary (i.e., a loop) or binary.  (Note: $e_j$ refers to the edge in the graph associated with measurement $\\mathbf{z}_j$, whereas $\\mathbf{e}_j$ refers to the residual function associated with $\\mathbf{z}_j$.)  For more information about the Graph SLAM algorithm, see \\cite{grisetti2010tutorial}.\n\nWe want to optimize\n%\n\\begin{equation*}\n    \\chi^2 = \\sum_{e_j \\in \\mathcal{E}} \\mathbf{e}_j^\\transp \\Omega_j \\mathbf{e}_j.\n\\end{equation*}\n%\nLet $\\mathbf{x}_i \\in \\mathbb{R}^c$ be the compact representation of pose $\\mathbf{p}_i \\in \\mathcal{M}$, and let\n%\n\\begin{equation*}\n    \\mathbf{x} := \\begin{bmatrix} \\mathbf{x}_1 \\\\ \\mathbf{x}_2 \\\\ \\vdots \\\\ \\mathbf{x}_N \\end{bmatrix} \\in \\mathbb{R}^{cN}\n\\end{equation*}\n%\nWe will solve this optimization problem iteratively.  Let\n%\n\\begin{equation}\n    \\mathbf{x}^{k+1} := \\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k = \\begin{bmatrix} \\mathbf{x}_1 \\boxplus \\Delta \\mathbf{x}_1 \\\\ \\mathbf{x}_2 \\boxplus \\Delta \\mathbf{x}_2 \\\\ \\vdots \\\\ \\mathbf{x}_N \\boxplus \\Delta \\mathbf{x}_2 \\end{bmatrix} \\label{eq:update}\n\\end{equation}\n%\nThe $\\chi^2$ error at iteration $k+1$ is\n\\begin{equation}\n    \\chi_{k+1}^2 = \\sum_{e_j \\in \\mathcal{E}} \\underbrace{\\left[ \\mathbf{e}_j(\\mathbf{x}^{k+1}) \\right]^\\transp}_{1 \\times \\bullet} \\underbrace{\\Omega_j}_{\\bullet \\times \\bullet} \\underbrace{\\mathbf{e}_j(\\mathbf{x}^{k+1})}_{\\bullet \\times 1}.  \\label{eq:chisq_at_kplusone}\n\\end{equation}\n%\nWe will linearize the residuals as:\n%\n\\begin{align}\n    \\mathbf{e}_j(\\mathbf{x}^{k+1}) &= \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k) \\notag \\\\\n    &\\approx \\mathbf{e}_j(\\mathbf{x}^{k}) + \\frac{\\partial}{\\partial \\Delta \\mathbf{x}^k} \\left[ \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k) \\right] \\Delta \\mathbf{x}^k \\notag \\\\\n    &= \\mathbf{e}_j(\\mathbf{x}^{k}) + \\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right) \\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k} \\Delta \\mathbf{x}^k.  \\label{eq:linearization}\n\\end{align}\n%\nPlugging \\eqref{eq:linearization} into \\eqref{eq:chisq_at_kplusone}, we get:\n%\n\\small\n\\begin{align}\n    \\chi_{k+1}^2 &\\approx \\ \\ \\ \\ \\ \\sum_{e_j \\in \\mathcal{E}} \\underbrace{[ \\mathbf{e}_j(\\mathbf{x}^k)]^\\transp}_{1 \\times \\bullet} \\underbrace{\\Omega_j}_{\\bullet \\times \\bullet} \\underbrace{\\mathbf{e}_j(\\mathbf{x}^k)}_{\\bullet \\times 1} \\notag \\\\\n    &\\hphantom{\\approx} \\ \\ \\ + \\sum_{e_j \\in \\mathcal{E}} \\underbrace{[ \\mathbf{e}_j(\\mathbf{x^k}) ]^\\transp }_{1 \\times \\bullet} \\underbrace{\\Omega_j}_{\\bullet \\times \\bullet} \\underbrace{\\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right)}_{\\bullet \\times dN} \\underbrace{\\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k}}_{dN \\times cN} \\underbrace{\\Delta \\mathbf{x}^k}_{cN \\times 1} \\notag \\\\\n    &\\hphantom{\\approx} \\ \\ \\ + \\sum_{e_j \\in \\mathcal{E}} \\underbrace{(\\Delta \\mathbf{x}^k)^\\transp}_{1 \\times cN} \\underbrace{ \\left( \\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k} \\right)^\\transp}_{cN \\times dN} \\underbrace{\\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right)^\\transp}_{dN \\times \\bullet} \\underbrace{\\Omega_j}_{\\bullet \\times \\bullet} \\underbrace{\\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right)}_{\\bullet \\times dN} \\underbrace{\\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k}}_{dN \\times cN} \\underbrace{\\Delta \\mathbf{x}^k}_{cN \\times 1} \\notag \\\\\n    &= \\chi_k^2 + 2 \\mathbf{b}^\\transp \\Delta \\mathbf{x}^k + (\\Delta \\mathbf{x}^k)^\\transp H \\Delta \\mathbf{x}^k,  \\notag\n\\end{align}\n\\normalsize\n%\nwhere\n%\n\\begin{align*}\n    \\mathbf{b}^\\transp &= \\sum_{e_j \\in \\mathcal{E}} \\underbrace{[ \\mathbf{e}_j(\\mathbf{x^k}) ]^\\transp }_{1 \\times \\bullet} \\underbrace{\\Omega_j}_{\\bullet \\times \\bullet} \\underbrace{\\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right)}_{\\bullet \\times dN} \\underbrace{\\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k}}_{dN \\times cN} \\\\\n    H &= \\sum_{e_j \\in \\mathcal{E}} \\underbrace{ \\left( \\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k} \\right)^\\transp}_{cN \\times dN} \\underbrace{\\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right)^\\transp}_{dN \\times \\bullet} \\underbrace{\\Omega_j}_{\\bullet \\times \\bullet} \\underbrace{\\left( \\left. \\frac{\\partial \\mathbf{e}_j(\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)} \\right|_{\\Delta \\mathbf{x}^k = \\mathbf{0}} \\right)}_{\\bullet \\times dN} \\underbrace{\\frac{\\partial (\\mathbf{x}^k \\boxplus \\Delta \\mathbf{x}^k)}{\\partial \\Delta \\mathbf{x}^k}}_{dN \\times cN}.\n\\end{align*}\n%\nUsing this notation, we obtain the optimal update as\n%\n\\begin{equation}\n    \\Delta \\mathbf{x}^k = -H^{-1} \\mathbf{b}.  \\label{eq:deltax}\n\\end{equation}\n%\nWe apply this update to the poses via \\eqref{eq:update} and repeat until convergence.\n\n\n\n\\bibliographystyle{acm}\n\\bibliography{graphSLAM}{}\n\n\\end{document}\n", "meta": {"hexsha": "25f02cd3bdeff822a5b47c6b79735e677db1455e", "size": 13495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SLAM/GraphBasedSLAM/LaTeX/graphSLAM_formulation.tex", "max_stars_repo_name": "pruidzeko/PythonRobotics", "max_stars_repo_head_hexsha": "5ff9b70d737121c2947d844ecfb1fa07abdd210c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-09-26T06:37:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T12:30:58.000Z", "max_issues_repo_path": "SLAM/GraphBasedSLAM/LaTeX/graphSLAM_formulation.tex", "max_issues_repo_name": "pruidzeko/PythonRobotics", "max_issues_repo_head_hexsha": "5ff9b70d737121c2947d844ecfb1fa07abdd210c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 65, "max_issues_repo_issues_event_min_datetime": "2020-07-28T09:41:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:01:08.000Z", "max_forks_repo_path": "SLAM/GraphBasedSLAM/LaTeX/graphSLAM_formulation.tex", "max_forks_repo_name": "pruidzeko/PythonRobotics", "max_forks_repo_head_hexsha": "5ff9b70d737121c2947d844ecfb1fa07abdd210c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2020-11-18T02:15:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T06:47:00.000Z", "avg_line_length": 76.6761363636, "max_line_length": 935, "alphanum_fraction": 0.6741015191, "num_tokens": 5084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7248702821204019, "lm_q1q2_score": 0.6517463624833051}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb,amsthm}\n\n\\newcommand{\\G}{\\mathbb{G}}\n\n\\begin{document}\nPublic parameters are supposed to consist of $g_1^{\\alpha^i}$ and $g_2^{\\alpha^i}$ for $i$ from $1$ to $2N$, except $N+1$ is omitted. This document describes and argues security of two procedures, one deterministic and one probabilistic, for determining whether an alleged set of parameters is indeed of this form.\n\n\\subsection*{Notation}\n\nFor $1 \\le i \\le 2N, i \\ne N+1$, write\n\\begin{align*}\nf_i \\; &\\text{to denote the $\\G_1$ element that is allegedly} \\; g_1^{\\alpha^i} \\\\\nh_i \\; &\\text{to denote the $\\G_2$ element that is allegedly} \\; g_2^{\\alpha^i} \\\\\n\\intertext{and for notational convenience, write}\nf_0 &= g_1 \\\\\nh_0 &= g_2.\n\\end{align*}\n\nA set of (alleged) parameters \\[\n\\{f_i, h_i\\}_{1 \\le i \\le 2N, i \\ne N+1}\n\\]\nare \\textit{consistent} if $\\exists \\alpha \\notin\\{0,1\\}$ such that $\\forall i, f_i = g_1^{\\alpha^i}$ and $h_i = g_2^{\\alpha^i}$.\n\n\\subsection*{Deterministic consistency check}\nGiven an alleged set of parameters, the following procedure determines whether they are consistent. In the below discussion, without loss of generality, let $\\alpha$ be such that $f_1 = g_1^{\\alpha}$.\n\n\\begin{enumerate}\n\\item Check that none of the $f_i$ or $h_i$ are 1, $g_1$, or $g_2$. (This ensures $\\alpha \\notin \\{0,1\\}$.)\n\n\\item Check that \\[ e(f_i, h_0) = e(f_0, h_i) \\quad\\text{for all $1\\le i \\le N$ and $N+2 \\le i \\le 2N$}\\]\nThis ensures that $\\log_{g_1} f_i = \\log_{g_2} h_i$ for all $i$ --- in other words, the exponents of each $f_i$ and corresponding $h_i$ match. In particular we now know $h_1 = g_2^\\alpha$.\n\n\\item Check that \\[e(f_i, h_1) = e(f_{i+1}, h_0) \\quad \\text{for all $1 \\le i \\le N-1$}\\]\nThis ensures $f_i = g_1^{\\alpha^i}$ (and also $h_i = g_2^{\\alpha^i}$ by the previous check) for $1 \\le i \\le N$. (To see this, consider the $i = 1$ case, where we check $e(f_1, h_1) = e(f_2, h_0)$. $e(f_1, h_1) = e(g_1^\\alpha, g_2^\\alpha)$, so $f_2$ must be $g_1^{\\alpha^2}$. Then the $i=2$ check forces $f_3$ to be $g_1^{\\alpha^3}$ and so on.)\n\n\\item Check that \\[e(f_i, h_N) = e(f_{i+N}, h_0) \\quad \\text{for all $2 \\le i \\le N$}\\]\nIn other words, check $e(f_{i+N}, g_2) = e(g_1^{\\alpha^{i}}, g_2^{\\alpha^{N}})$, which ensures $f_{i+N} = g_1^{\\alpha^{i+N}}$ for $2\\le i \\le N$. (This also ensures $h_{i+N} = g_2^{\\alpha^{i+N}}$ for $2 \\le i \\le N$ because we know the exponents of the $f$'s and $h$'s match.)\n\n\\end{enumerate}\nIf all checks pass, then we know that $f_i = g_1^{\\alpha^i}$ and $h_i = g_2^{\\alpha^i}$ for all $1 \\le i \\le 2N, i\\ne N$, and we know $\\alpha \\notin \\{0,1\\}$. So the parameters are consistent.\n\n\n\n\\subsection*{Probabilistic consistency check}\nA randomized version of the above algorithm can check consistency much more efficiently, using $O(1)$ rather than $O(N)$ pairings, with a soundness error of $O(\\frac1{|\\G_1|})$.\n\n\\begin{enumerate}\n\\item Generate $N$ random scalars $r_1, \\dots, r_N$ and compute the following:\n\\begin{align*}\nR_1 &= \\prod_{i=1}^{N} f_i^{r_i} \\\\\nR_2 &= \\prod_{i=1}^{N} h_i^{r_i} \\\\\nS & = \\prod_{i=1}^{N-1} f_i^{r_i} \\left( = \\frac{R_1}{f_N^{r_N}}\\right)\\\\\nT &= \\prod_{i=1}^{N-1} f_{i+1}^{r_i} \\\\\nU_1 &= \\prod_{i=1}^{N-1} f_{i+N+1}^{r_i} \\\\\nU_2 &= \\prod_{i=1}^{N-1} h_{i+N+1}^{r_i} \\\\\n\\end{align*}\n\n\\item Check that none of the $f$'s or $h$'s are 1, $g_1$, or $g_2$, just like in the deterministic procedure.\n\n\\item Check that\n\\begin{align*}\ne(R_1, h_0) &= e(f_0, R_2) \\\\\n\\intertext{In other words, check that}\ne(\\prod_{i=1}^N f_i^{r_i}, h_0) &= e(f_0, \\prod_{i=1}^N h_i^{r_i})\n\\end{align*}\nThis ensures $e(f_i, h_0) = e(f_0, h_i)$ for all $1 \\le i \\le N$ with soundness error $\\frac1{|\\G_1|}$.\n\n\\item Check that \n\\[\ne(U_1, h_0) = e(f_0, U_2)\n\\]\n\nThis ensures $e(f_i, h_0) = e(f_0, h_i)$ for all $N+2 \\le i \\le 2N$ with soundness error $\\frac1{|\\G_1|}$. Combined with the previous step, this is equivalent to check 2 of the deterministic procedure.\n\n\\item Check that\n\\begin{align*}\ne(S, h_1) &= e(T, h_0)\n\\intertext{or in other words,}\ne(\\prod_{i=1}^{N-1} f_i^{r_i}, h_1) &= e(\\prod_{i=1}^{N-1} f_{i+1}^{r_i}, h_0)\n\\end{align*}\nThis ensures that $e(f_i, h_1) = e(f_{i+1}, h_0)$ for all $1 \\le i \\le N-1$ with soundness error $\\frac1{|\\G_1|}$. This is equivalent to check 3 of the deterministic procedure.\n\n\\item Check that\n\\begin{align*}\ne(U_1, h_0) &= e(T, h_N)\n\\intertext{or in other words,}\ne(\\prod_{i=1}^{N-1} f_{i+N+1}^{r_i}, h_0) &= e(\\prod_{i=1}^{N-1} f_{i+1}^{r_i}, h_N)\n\\end{align*}\nThis ensures that $e(f_{i+N+1}, h_0) = e(f_{i+1}, h_N)$ for all $1 \\le i \\le N-1$ (with soundness error $\\frac1{|\\G_1|}$). This is equivalent to check 4 of the deterministic procedure.\n\\end{enumerate}\nIf all of the above checks pass, then the parameters are consistent with high probability.\n\nThis randomized procedure is equivalent to the deterministic procedure in the previous section but with soundness error $\\frac4{|\\G_1|}$.\n\\end{document}\n", "meta": {"hexsha": "52597ffa26c5f2ac4e61dcbeb4dae52afca9084e", "size": 4914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "consistencycheck.tex", "max_stars_repo_name": "sourcenetwork/pointproofs-paramgen", "max_stars_repo_head_hexsha": "43a92ebf4430fed4e13abc8145f7935d8db26461", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-08T12:54:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T12:16:52.000Z", "max_issues_repo_path": "consistencycheck.tex", "max_issues_repo_name": "sourcenetwork/pointproofs-paramgen", "max_issues_repo_head_hexsha": "43a92ebf4430fed4e13abc8145f7935d8db26461", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "consistencycheck.tex", "max_forks_repo_name": "sourcenetwork/pointproofs-paramgen", "max_forks_repo_head_hexsha": "43a92ebf4430fed4e13abc8145f7935d8db26461", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-04T03:24:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-19T12:17:09.000Z", "avg_line_length": 51.1875, "max_line_length": 344, "alphanum_fraction": 0.6514041514, "num_tokens": 1941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6516712421557764}}
{"text": "\n\n\nAgain, you will need the \\pkg{mosaic} package in R, which provides\nsome of the basic operators for constructing sampling and resampling distributions.\n\\begin{Schunk}\n\\begin{Sinput}\n> require(mosaic)\n\\end{Sinput}\n\\end{Schunk}\n\nThe examples will be based on \nthe Cherry-Blossom 2008 data described earlier: \\datasetCherryBlossomEight\n\\begin{Schunk}\n\\begin{Sinput}\n> runners = fetchData(\"Cherry-Blossom-2008.csv\")\n> names( runners )\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"position\" \"division\" \"total\"    \"name\"     \"age\"      \"place\"   \n[7] \"net\"      \"gun\"      \"sex\"     \n\\end{Soutput}\n\\end{Schunk}\n\n\\subsection{Finding a Sampling Distribution through Bootstrapping}\n\\label{sec:find-sampling-distribution}\n\nYour data are typically a sample from a population.  Collecting the\nsample is usually hard work.  Just to illustrate the context of\na sampling distribution, here is a simulation of selecting a sample of\nsize $n=100$ from the population of runners.  It's essential to keep\nin mind that {\\bf you do not usually} pull out your sample using the\ncomputer in this way.  Instead, you go into the field or laboratory and collect your data.\n\\begin{Schunk}\n\\begin{Sinput}\n> mysamp = deal( runners, 100 ) # A Simulation of sampling\n\\end{Sinput}\n\\end{Schunk}\n\nNow that you have a sample, you can calculate the sample statistic\nthat's of interest to you.  For instance:\n\\begin{Schunk}\n\\begin{Sinput}\n> mean( gun ~ sex, data=mysamp )\n\\end{Sinput}\n\\begin{Soutput}\n  sex     S  N Missing\n1   F 100.4 47       0\n2   M  88.1 53       0\n\\end{Soutput}\n\\end{Schunk}\nNote that the results are slightly different from those found above\nusing the whole population.  That's to be expected, since the sample\nis just a random part of the population.  But ordinarily, you will not\nknow what the population values are; all you have to work with is your\nsample.  \n\nTheoretically, the sampling distribution reflects the variation from\none randomly dealt sample to another, where each sample is taken from\nthe population.  In practice, your only ready access to the population\nis through your sample.  So, to simulate the process of random\nsampling, re-sampling is used and the re-sampling distribution is used\nas a convenient approximation to the sampling distribution.\n\nRe-sampling involves drawing from the set of cases in your sample with replacement.  To\nillustrate, consider this example of a \nvery small, simple set: \nthe numbers 1 to 5:\n\\begin{Schunk}\n\\begin{Sinput}\n> nums = c(1,2,3,4,5)\n> nums\n\\end{Sinput}\n\\begin{Soutput}\n[1] 1 2 3 4 5\n\\end{Soutput}\n\\end{Schunk}\n\nEach resample of size $n$ consists of $n$ members from the set, but in\nany one resample\neach member might appear more than once and some might not appear at\nall.  Here are three different resamples from \\texttt{nums}:\n\\begin{Schunk}\n\\begin{Sinput}\n> resample(nums)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 1 1 4 5 4\n\\end{Soutput}\n\\begin{Sinput}\n> resample(nums)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 4 2 3 4 2\n\\end{Soutput}\n\\begin{Sinput}\n> resample(nums)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 5 2 2 1 1\n\\end{Soutput}\n\\end{Schunk}\n\nTo use resampling to estimate the sampling distribution of a\nstatistic, you apply the calculation of the statistic to a resampled\nversion of your sample.  For instance, here are the group-wise means\nfrom one resample of the running sample:\n\\begin{Schunk}\n\\begin{Sinput}\n> mean( gun ~ sex, data=resample(mysamp) )\n\\end{Sinput}\n\\begin{Soutput}\n  sex    S  N Missing\n1   F 97.9 47       0\n2   M 92.5 53       0\n\\end{Soutput}\n\\end{Schunk}\nAnd here is another:\n\\begin{Schunk}\n\\begin{Sinput}\n> mean( gun ~ sex, data=resample(mysamp) )\n\\end{Sinput}\n\\begin{Soutput}\n  sex     S  N Missing\n1   F 101.3 45       0\n2   M  87.1 55       0\n\\end{Soutput}\n\\end{Schunk}\n\n\\index{C}{bootstrapping}\n\nThe bootstrap procedure involves conducting many such trials and examining the\nvariation from one trial to the next.  \n\nThe \\function{do} function lets\nyou automate the collection of multiple trials.  For instance, here\nare five trials carried out using \\function{do}:\n\\begin{Schunk}\n\\begin{Sinput}\n> do(5) * mean( gun ~ sex, data=resample(mysamp) )\n\\end{Sinput}\n\\begin{Soutput}\n   sex     S  N Missing do.rep\n1    F  97.8 46       0      1\n2    M  89.9 54       0      1\n3    F  99.2 44       0      2\n4    M  87.0 56       0      2\n5    F 100.0 40       0      3\n6    M  90.3 60       0      3\n7    F 100.6 44       0      4\n8    M  87.6 56       0      4\n9    F 102.8 56       0      5\n10   M  88.2 44       0      5\n\\end{Soutput}\n\\end{Schunk}\n\nTypically, you will use several hundred trials for bootstrapping.  The\nmost common way to summarize the variation in bootstrap trials, you\ncan calculate a 95\\% coverage interval.  (When applied to a sampling\ndistribution, the coverage interval is called a \\newword{confidence interval}.)\n\nTo do the computation, give a name to  the results of the repeated\nbootstrap trials, here it's called \\texttt{trials}:\n\\begin{Schunk}\n\\begin{Sinput}\n> trials = do(500) * mean( gun ~ sex, data=resample(mysamp) )\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Sinput}\n> trials\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Soutput}\n  sex    S  N Missing do.rep\n1   F 99.6 44       0      1\n2   M 87.4 56       0      1\n3   F 97.1 48       0      2\n4   M 88.0 52       0      2\n5   F 98.0 55       0      3\n6   M 88.4 45       0      3\n... for 1000 rows altogether ...\n\\end{Soutput}\n\\end{Schunk}\n\nComputing the coverage intervals can be done using \\function{qdata} on\nthe columns, or, for convenience, use the \\function{confint} function.\n\\begin{Schunk}\n\\begin{Sinput}\n> confint(trials)\n\\end{Sinput}\n\\begin{Soutput}\n  sex 2.5% 97.5%\n1   F 96.9 104.2\n2   M 83.6  92.4\n\\end{Soutput}\n\\end{Schunk}\n\nThe idea of sampling distributions is based on\ndrawing at random from the population, not resampling.  Ordinarily,\nyou can't do this calculation since you don't have the population at\nhand.  But in this example, we happen to have the data for all\nrunners.  Here's the population-based confidence interval for the mean\nrunning time, with sample size $n=100$, broken down by sex:\n\n\\index{P}{confint}\n\\index{C}{confidence intervals}\n\n\\begin{Schunk}\n\\begin{Sinput}\n> trials = do(500) * mean( gun ~ sex, data=deal(runners,100) )\n> confint(trials)\n\\end{Sinput}\n\\begin{Soutput}\n  sex 2.5% 97.5%\n1   F 95.1 102.5\n2   M 84.1  92.2\n\\end{Soutput}\n\\end{Schunk}\n\n\\index{C}{confidence level}\n\nThe output of \\function{confint} shows the lower and upper limits of\nthe confidence interval for each of the groups.  The labels on the\ncolumns indicate the confidence level.  By default, the interval is at\nthe 95\\% level, and so the interval runs from the 2.5 percentile to\nthe 97.5 percentile. \n\nHistorically, statisticians have been concerned with very small\nsamples: say $n=2$ or $n=3$.  Even in this era of huge data sets, such\nsmall sample sizes often are encountered in laboratory experiments,\netc. Bootstrapping cannot work well with such\nsmall samples, and other techniques are needed to simulate sampling\nvariability.  Many of these techniques are based in algebra and\nprobability theory, and give somewhat complex formulas for calculating confidence\nintervals from data. The formulas are often found in textbooks, but for most of the modeling techniques you will use\nin later chapters, appropriate formulas for confidence intervals have been implemented in\nsoftware.  For other modeling techniques, bootstrapping is used to \nfind the confidence intervals.  But keep in mind that bootstrapping\ncan only be effective when the sample size $n$ is one or two dozen or\nlarger.  \n\n\n\\subsection{Computing Grade-Point Averages}\n\nThe grade-point average is a kind of group-wise mean, where the group\nis an individual student.  This is not the usual way of looking at\nthings for a student, who sees only his or her own grades.  But\ninstitutions have data on many students.\n\nThe data files \\texttt{grades.csv} and \\texttt{courses.csv} are drawn from\nan institutional database at a college.  They give the grades for more\nthan 400 students who graduated in year 2005.  Another file,\n\\texttt{grade-to-number.csv}, gives the rules used by the institution\nin converting letter grades to numbers.  \n\nThe data files are part of a \\newword{relational data base}, a very\nimportant way of managing large amounts of data used by private and\npublic institutions, corporations and governments --- it's the basis\nfor a multi-billion dollar segment of the economy.  Ordinarily,\nrelational data bases are queried using special-purpose computer\nlanguages that sort, extract, and combine the data.  Here are the R\ncommands for converting the letter grades to numbers and extracting\nthe data for one student:\n\\begin{Schunk}\n\\begin{Sinput}\n> grades = fetchData(\"grades.csv\")\n> gp = fetchData(\"grade-to-number.csv\")\n> all.students = merge(grades, gp)\n> one.student = subset( all.students, sid==\"S31509\" )\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Sinput}\n> one.student\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Soutput}\n     grade    sid   sessionID gradepoint\n192      A S31509 session3443          4\n543      A S31509 session2308          4\n674      A S31509 session2851          4\n1280     A S31509 session2737          4\n... for 13 cases altogether ...\n\\end{Soutput}\n\\end{Schunk}\n\nCalculating the mean grade-point for the one student is a simple matter:\n\\begin{Schunk}\n\\begin{Sinput}\n> mean( gradepoint, data=one.student )\n\\end{Sinput}\n\\begin{Soutput}\n[1] 3.6\n\\end{Soutput}\n\\end{Schunk}\n\nIt's equally straightforward to calculate the grade-point averages\nfor all students as individuals:\n\\begin{Schunk}\n\\begin{Sinput}\n> mean( gradepoint ~ sid, data=all.students )\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Soutput}\n     sid    S  N Missing\n1 S31185 2.41  8       0\n2 S31188 3.02 16       2\n3 S31191 3.21 14       1\n4 S31194 3.36 12       0\n5 S31197 3.36 13       0\n... for 443 cases altogether ...\n\\end{Soutput}\n\\end{Schunk}\n\n\\index{P}{do}\n\\index{P}{confint}\n\\index{P}{mean}\n\nBootstrapping can be used to find the confidence interval on the\ngrade-point average for each student:\n\\begin{Schunk}\n\\begin{Sinput}\n> trials = do(100)*mean(gradepoint ~ sid, data=resample(all.students) )\n\\end{Sinput}\n\\end{Schunk}\n\n\\begin{Schunk}\n\\begin{Sinput}\n> confint(trials)\n\\end{Sinput}\n\\end{Schunk}\n\n\\begin{Schunk}\n\\begin{Soutput}\n     sid 2.5% 97.5%\n1 S31185 1.65  3.14\n2 S31188 2.56  3.47\n3 S31191 3.01  3.43\n4 S31194 3.05  3.70\n5 S31197 3.20  3.52\n... for 443 students altogether ...\n\\end{Soutput}\n\\end{Schunk}\n\nIt's important to point out that there are other methods for calculating\nconfidence intervals that are based on the standard deviation of the\ndata.  Formulas and procedures for such methods are given in just\nabout every standard introductory statistics book and would certainly\nbe used instead of bootstrapping in a simple calculation of the sort\nillustrated here.  \n\nHowever, such formulas don't go to the heart of the problem: \naccounting for variation in the grades and the contribution from\ndifferent sources of that variation.  For example, some of the\nvariation in this student's grades might be due systematically to\nimprovement over time or due to differences between instructor's\npractices.  The modeling techniques introduced in the following\nchapters provide a means to examine and quantify the different sources\nof variation.\n", "meta": {"hexsha": "971658d5079739d1e21f651354664038cd368e7a", "size": 11290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ComputationalTechnique-Orig/StatisticalInference/computer-statistical-inference.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/StatisticalInference/computer-statistical-inference.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/StatisticalInference/computer-statistical-inference.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": 31.0164835165, "max_line_length": 116, "alphanum_fraction": 0.7258635961, "num_tokens": 3406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6516712256223063}}
{"text": "\\section{Dependent Type String Indexing is a Monoid}\\label{sec:monoid}\n\n\n\n\\subsection{String Matching Definition}\n\nWe define the String Matching data type\n@SM target@ to contain a string field @input@ and\na list of all the indices on @input@ where the\n@target@ appears.\n%\n\\begin{code}\ndata SM (target :: Symbol) where\n  SM :: input:RString\n     -> indices:[GoodIndex input target]\n     -> SM target\n\\end{code}\n%\nWe used type literals to parameterize the type over\nthe Symbol @target@.\n%\nThis encoding is required to allow definition of\nan identity element, as explained later~(\\S~\\ref{subsec:monoid:methods}).\n%\nThe input field, of type @RString@, is a refined wrapper on\na String manipulation library that\n1. allows for constant time string indexing, and\n2. provides various string lemmata.\n%\nThe library @RString.hs@~\\footnote{\n\\href{https://github.com/nikivazou/verified_string_indexing/blob/master/src/String.hs}\n     {\\url{https://github.com/nikivazou/verified_string_indexing/blob/master/src/String.hs}}}\nimplements @RString@ as @ByteStrings@,\nand \\textbf{assumes} various String properties,\nlike left identity:\n\\begin{code}\nassume leftIdentity :: s:RSTring -> { s <+> stringMempty == s }\n\\end{code}\n%\nThe indices field is a list of good indices.\n%\nFor simplicity we are using Haskell's built in lists but in the\nimplementation we use a user defined reflected list data type similar\nto that presented in section~\\ref{sec:haskell-proofs}.\n%\nA @GoodIndex input target@ is a refined type alias\nfor an integer @i@ that\n1. is a natural number,\n2. @target@ is a substring of @input@ appearing at position @i@.\n%\n\\begin{code}\ntype GoodIndex Input Target\n  = {i:Nat | isGoodIndex Input (fromString Target) i }\n\nisGoodIndex :: RSTring -> RSTring -> Int -> Bool\nisGoodIndex input target i\n  =  (subString input i (stringLen target)  == target)\n  && (i + stringLen target <= stringLen input)\n\\end{code}\n%\n\nAs an example, the good indices of @\"abcab\"@ on @\"ababcabcab\"@\nare @[2,5]@ while any other index is bad.\n\\begin{code}\ngoodSM :: SM \"abcab\"\ngoodSM = SM \"ababcabcab\" [2, 5]\n\nbadSM  :: SM \"abcab\"\nbadSM  = SM \"ababcabcab\" [0, 7]\n\\end{code}\n\\NV{Liquid Haskell actually will reject both the above, as the stringLen and subString functions are uninterpreted}\n\n\\subsection{Monoid Laws}\nIn the rest of this section we will prove that\nthe String Matching structure is a Monoid.\n%\nA structure @m@ is a monoid,\nthere is an identity element @mempty :: a@\nand an associative appending function @(<>) :: a -> a -> a@.\nThat is, @mempty@ and @(<>)@ should satisfy the following laws\n\\begin{figure}\n\\begin{code}\nidLeft :: x:a -> {x <> mempty == x }\nidRight:: x:a -> {mempty <> x == x }\nassoc  :: x:a -> y:a -> z:a -> {(x <> y) <> z == x <> (y <> z)}\n\\end{code}\n\\caption{Monoid Laws}\n\\label{fig:monoid:laws}\n\\end{figure}\n%\nTo prove that the String Matching operator @SM@\nis a monoid, we use the fact that the String and list\nof indices contained in its fields are also monoids.\n%\nFigure~\\ref{fig:monoids} defines the monoid operators used\nin this section.\n%\n\\begin{figure}\n$$\n\\begin{array}{c c c c }\n\\text{Structure} & \\text{Identity} & \\text{Mappend} & \\text{Laws} \\\\\n\\hline\n\\texttt{List} & \\listMempty & (\\listMappend) & \\text{PROVEN} \\\\\n\\texttt{SM} & \\mempty & (\\mappend) & \\text{PROVEN} \\\\\n\\texttt{RString} & \\stringMempty & (\\stringMappend) & \\text{ASSUMED}\n\\end{array}\n$$\n\\caption{Monoid Structures}\n\\label{fig:monoids}\n\\end{figure}\n\n\n\\subsection{Monoid Methods for String Matching}~\\label{subsec:monoid:methods}\nNext, we define the mappend and identity elements for string matching.\nWe reflect the definitions into logic, to latter use them to prove\nthe monoid laws.\n\nThe \\textit{identity element} of @SM t@, for each target @t@, is\ndefined to contain the identity @RString@ (@stringMempty@) and the\nidentity @List@ (@listMempty@).\n\\begin{code}\nreflect mempty\nmempty:: forall (t :: Symbol). SM t\nmempty = SM stringMempty listMempty\n\\end{code}\n%\nNote, that if target was encoded as a value argument, instead of a\ntype parameter, then there would be no way to define an identity\nelement for each expression argument.\n%\n\\JP{I think the type parameter is more necessary to define mappend}\n\n\nThe @(mappend)@ operator,\nmappends 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 @is1@ from the first input, casted to be good indices in the new structure,\n\\item the new indices @newIs@ created when concatenating the two strings, and\n\\item the indices @is2@ from the second input, shifted right @stringLen i2@ points.\n\\end{enumerate}\n%\n\\begin{figure}\n\\includegraphics[scale=0.5]{makeIndices}\n\\caption{Mappend indices of String Matcher}\n\\label{fig:mappend:indices}\n\\end{figure}\n%\nThe above are summarized in the Haskell definition of @(<>)@\n\\begin{code}\nreflect mappend\n(mappend)::forall (t::Symbol). KnownSymbol t => SM t -> SM t -> SM t\n(SM i1 is1) mappend (SM i2 is2)\n  = SM (i1 stringMappend i2) (is1' listMappend newIs listMappend is2')\n  where\n    tg    = fromString (symbolVal (Proxy :: Proxy t))\n    is1'  = map (castGoodIndexLeft tg i1 i2) is1\n    newIs = makeNewIndices i1 i2 tg\n    is2'  = map (shiftStringRight tg i1 i2) is2\n\\end{code}\n\n\\paragraph{Step 1: Casting Good Indices}\nIf @is@ is a list of good indices for string @i1@ with respect to a target @tg@,\nthen @is@ is a list of good indices for the string @i1 stringMappend i2@, for each @i2@\nfor the same target.\n%\nTo establish the above property,\nwe need the property from refined string\nthat states that\nfor each string @input@ and @input'@\nand each integers @i@ and @j@ whose sum does not exceed the length of @input@,\nthe @subString@ on @input@ from @i@ with length @j@\nis equal to\nthe @subString@ on @input stringMappend input'@ from @i@ with length @j@:\n%\n\\begin{code}\nsubStringConcatLeft\n    :: sl:RString -> sr:RString -> j:Int\n    ->  i:{Int | i + j <= stringLen sl }\n    ->  { subString sl i j == subString (sl stringMappend sr) i j }\n\\end{code}\n%\nTo cast an index list of good indices in the above way,\nwe cast the above property to every element of the list\n%\n\\begin{code}\nreflect castGoodIndexRightList\ncastGoodIndexLeft\n  :: tg:RString -> sl:RString -> sr:RString\n  -> i:GoodIndex sl tg\n  -> {v:GoodIndex (sl stringMappend sr target | v == i}\n\ncastGoodIndexLeft tg sl sr i\n  = cast (subStringConcatLeft sl sr (stringLen tg) i) i\n\\end{code}\n%\nWhere @cast p x@\nreturns @x@, after enforcing the properties of @p@ in the logic\n\\begin{code}\ncast :: b -> x:a -> {v:a | v == x }\ncast _ x = x\n\\end{code}\n%\nMoreover, the translation of @cast p x@ into the logic, is merely @x@\nthus allowing random (\\ie non-reflected) Haskell expressions appearing in @p@.\n\n\\paragraph{Step 2: Creation of new indices}\nWhen concatenating two new string inputs @i1@ and @i2@,\nthe @stringLen tg@ last positions of @i1@ combined with the initial part of @i2@\nmay form new good indices.\n%\n@makeNewIndices s1 s2 target@ creates all such good new indices.\n%\nIf the length of the @target@ is less than 2, then no new good indices are creates,\nthus the function returns the empty list.\nOtherwise, we search @concatString s1 s2@ for substring of @target@\nin the range @[maxInt (stringLen s1 - (stringLen target-1)) 0, stringLen s1 - 1]@\n\\begin{code}\nreflect makeNewIndices\nmakeNewIndices\n  :: s1:RString -> s2:RString -> target:RString\n  -> [GoodIndex {s1 stringMappend s2} target]\nmakeNewIndices s1 s2 target\n  | lenStr target < 2\n  = []\n  | otherwise\n  = makeIndices (s1 stringMappend s2) target lo hi\n  where\n    lo = maxInt (lenStr s1 - (lenStr target-1)) 0\n    hi = lenStr s1 - 1\n\\end{code}\n%\n@makeIndices input target lo hi@\nrecursively searches for good indices on @input@ with respect to @target@\nfrom @lo@ to @hi@.\n%\n\\begin{code}\nreflect makeIndices\nmakeIndices\n  :: input:RString -> target:RString -> lo:Nat\n  -> hi:Int -> [GoodIndex input target]\n  / [hi - lo]\nmakeIndices input target lo hi\n  | hi < lo\n  = N\nmakeIndices input target lo hi\n  | isGoodIndex input target lo\n  = lo `C` rest\n  | otherwise\n  = rest\n  where\n    rest = makeIndices input target (lo + 1) hi\n\\end{code}\n%\nThe notation @[hi-lo]@ declares that @makeIndices@ terminates, as the metric @hi - lo@\nis a non-negative values that decreases at each recursive call.\n\n\\paragraph{Note on complexity.}\nGiven that the implementation of @RString@\nallows substring checking via indexing, that is in constant time,\nthen @makeNewIndices@ and thus @(<>)@ requires @lenStr target@ checks,\nthat is constant checks with respect to the string input.\n\n\\paragraph{Step 3: Shift Good Indices}\nIf @is@ is a list of good indices for string @i2@ with respect to a target @tg@,\nto get a list of good indices for the string @i1 stringMappend i2@,\nwe need to shift each element of @is@ @stringLen i1@ right.\n%\nMoreover, to persuade Liquid Haskell that the shifted indices are good indices\nwe need to apply the refined string theorem that states\nfor each string @sl@ and @sr@\nand each integers @i@ and @j@,\nthe @subString@ on @sr@ from @i@ with length @j@\nis equal to\nthe @subString@ on @sl stringMappend sr@ from @stringLen sl + i@ with length @j@:\n%\n\\begin{code}\nassume subStringConcatRight\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\nThus, @shiftStringRight@ both appropriately shifts the index\nand casts the shifted index using the above theorem:\n\\begin{code}\nshiftStringRight\n  :: tg:RString -> sl:RString -> sr:RString\n  -> i:GoodIndex sr tg\n  -> {v:(GoodIndex (sl stringMappend sr) tg) | v == i + lenStr sl}\nshiftStringRight tg sl sr i\n  = subStringConcatRight sl sr (stringLen tg) i)\n     `cast` shift (stringLen sl) i\n\\end{code}\n\n\n\\subsection{String Matching is a Monoid}\nWe conclude this section by proving\nthat the @mempty@ and @(mappend)@\noperators we defined satisfy the monoid laws.\n%\nIn the prove, we express\n\\begin{itemize}\n\\item the monoid laws as liquid types, and\n\\item the monoid proofs as Haskell functions.\n\\end{itemize}\nThen, Liquid Haskell checks that the functions indeed check the corresponding laws.\n\n\\begin{theorem}\\label{theorem:monoid}\nString Matching is a Monoid for the operations @mempty@ and @(mappend)@.\n\\end{theorem}\n\n\\begin{proof}\nBased on the Monoid Definition~\\ref{definition:monoid},\nto prove that string maching is a monoid, we need to prove that\nthere exist safe implementations of the monoid laws functions.\n%\nWe implemented the monoid laws functions\nand used Liquid Haskell to (machine) check correctness of our proof.\n\nFirst, we prove \\textit{left identity}\n\\begin{code}\nidLeft :: x:SM t -> {x mappend mempty == x }\nidLeft (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      ? idLeftString i\n  ==. SM i (is listMappend N listMappend N)\n      ? (mapCastId tg i stringMempty is &&& newIsNullLeft 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 stringEmp) is\n    isNew = makeNewIndices i stringEmp tg\n    is2   = map (shiftStringRight tg i stringEmp) N\n\\end{code}\nThe proof proceeds by rewriting and using four lemmata\n\\begin{itemize}\n\\item Left Identity on lists, that is proven by structural induction.\n\\begin{code}\nidLeftList :: x:[a] -> {x listMappend listMempty == x}\n\\end{code}\n\\item Left Identity on strings is provided by the string library that we trust.\n\\begin{code}\nidLeftString :: x:RString -> {x stringMappend stringMempty == x}\n\\end{code}\n\\item Identity of casting is proven by induction and identity on casts\n\\begin{code}\nmapCastId :: tg:RString -> x:RString -> y:RString\n  -> is:[GoodIndex x tg] ->\n  -> {map (castGoodIndexRight tg x y) is == is}\n\\end{code}\n\\item No new indices are created by mappend\n\\begin{code}\nnewIsNullLeft :: s:RString -> t:RString\n  -> {makeNewIndices s stringMempty t == listMempty }\n\\end{code}\nThe proof procceds by case splitting\non comparison of the lengths of @s@ and @t@.\nAt each case we prove by induction that all\nthe potential new indices will be out of bounds and thus\nno new good indices can be created.\n\\end{itemize}\n\n\\NV{Actually, the right identity proof is simpler, maybe put it first}\n\n- The proof of \\textit{right identity} is similar\n\\begin{code}\nidRight :: x:SM t -> {mempty mappend x == xs }\nidRight (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       ? idRightString i\n  ==. SM i (N ++ N ++ is)\n       ? (mapShiftZero tg i is &&& newIsNullRight 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 stringEmp) N\n    isNew = makeNewIndices stringEmp i tg\n    is2   = (map (shiftStringRight tg stringEmp i) is)\n\\end{code}\nThe proof uses again four lemmata.\n\\begin{itemize}\n\\item Right Identity on lists, that is proven by structural induction.\n\\begin{code}\nidRightList :: x:[a] -> {listMemtpy listMappend x == x}\n\\end{code}\n\\item Right Identity on strings is provided by the string library that we trust.\n\\begin{code}\nidRightString :: x:RString -> {stringMemepty stringMappend x == x}\n\\end{code}\n\\item Identity of shifting by an empty string is proven by induction and\nthe assumption that empty string has length 0\n\\begin{code}\nmapShiftZero :: tg:RString -> i:RString -> is:[GoodIndex i target]\n  -> {map (shiftStringRight tg stringMempty i) is == is }\n\\end{code}\n\\item No new indices are created by mappend\n\\begin{code}\nnewIsNullLeft :: s:RString -> t:RString\n  -> {makeNewIndices stringMempty s t == listMempty }\n\\end{code}\nThe proofs relies on the fact that @makeIndices@\nwill be called on the range @[0, -1]@ and immediately return @listMemepty@.\n\\end{itemize}\n- Finally we prove \\textit{associativity}.\nFor space, we omit the detailed proof, and only give the interesting steps.\nIn the proof we need to show equality of two string matchers,\nthus we need to show that their input and induces fields are respectively equal.\n%\nEquality of the input fields follows by associativity of RStrings.\n%\nThe proof of index equlity proceeds in three steps.\n\n\\begin{enumerate}\n\\item Firstly, using list associativity and distribution of index shifting,\nwe group the indices in the five lists shown in Figure~\\ref{fig:mappend:assoc}.\nThe indices of the input @x@,\nthe new indices from mappending @x@ to @y@,\nthe indices of the input @y@,\nthe new indices from mappending @x@ to @y@, and\nthe indices of the input @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}\nzis1 = map (shiftStringRight tg xi (yi stringMappend zi))\n       map (shiftStringRight tg yi zi) zis\n\nzis2 = 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 group representation.\nEquivalence of @xis@ and @zis@ is trivial,\nbut for the rest three groups, as we later discuss is more interesting,\nas it depends on the relative lengths of the target and the input of @y@.\n\\item Finally, once we proved equivalence of representations,\nwe use again list associativity and distribution of casts to wrap the index groups\nback in string matchers\n\\end{enumerate}\n\\begin{figure}\n\\includegraphics[scale=0.5]{AssociativeIndices}\n\\label{fig:mappend:assoc}\n\\end{figure}\nBellow we present the skeleton of the proof, while the detailed proof can be found online\\footnote{\\NV{GIVE PRoof link}}.\n\\begin{code}\nassoc 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\n  -- Step 3: Equivalence of representations\n  ==. SM i (xis1 ++ ((xyis1 ++ yis1 ++ yzis1) ++ zis1))\n  ==. SM i (xis1 ++ ((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\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    yzis1 = map (shiftStringRight tg xi (yi <+> zi)) yzis\n    yzis2 = makeNewIndices (xi <+> yi) zi tg\n\n    yzis  = makeNewIndices yi zi tg\n\n    i     = xi stringMappend (yi stringMappend zi)\n\\end{code}\nFinally, we present the lemma @assocNewIndices@\nthat proofs equivalence of representation in the three\ngroups @xyis@, @yis@, and @yzis@.\nThe proof proceeds by case analysis in the relative size of\nthe target @tg@ and the middle input @yi@.\n%\nIf the target is smaller than @yi@\nthen we can prove equivalence of each of the groups independently\nvia respective lemmata.\n%\nOtherwise, independent equivalence does not hold.\nThus, when @yi@ is smaller than the target,\nthe group @xyis1@ (similarly @yzis1@)\nis not provably equal to @xyis2@ (similarly @yzis2@).\nWhen @yi@ is smaller than the target,\nwhen appending @x@ with @y mappend z@ new indices may occur because\nof the suffix of @z@, these indices will not occur when appending @x@ with @y@.\n%\nYet, the appending of the two new index groups are provably equal,\n@xyis1 listMappend yzis1 == xyis2 listMappend yzis2@.\nThe lemma proof using append equivalence and the fact @yis1 == yis2 == []@\nto conclude that the appending of all the three groups is always equivalent.\n\n\\begin{code}\n-- proof that\n-- xyis1 ++ yis1 ++ yzis1 == xyis2 ++ yis2 ++ yzis2\nassocNewIndices y tg xi yi zi yis\n  | stringLen tg <= stringLen yi\n  =   xyisEquivalence xi yi zi tg\n  &&&  yisEquivalence xi yi zi tg yis\n  &&& yzisEquivalence xi yi zi tg\n  | stringLen yi < stringLen tg\n  =  xyis1 listMappend yis1 listMappend yzis1\n  ==. xyis1 listMappend [] listMappend yzis1 ? emptyIndices y yis\n  ==. xyis1 listMappend yzis1 ? idLeftList xyis1\n  ==. xyis2 listMappend yzis2 ? shiftNewIndices xi yi zi tg\n  ==. (xyis2 listMappend []) listMappend yzis2 ? idLeftList xyis2\n  ==. (xyis2 listMappend yis2) listMappend yzis2 ? emptyIndices y yis\n  *** QED\n\\end{code}\n\n\n\\qed\\end{proof}\n", "meta": {"hexsha": "d227c6784671572205ad6f80ae1e85be468cd038", "size": 18690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/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/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/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.1315789474, "max_line_length": 121, "alphanum_fraction": 0.713964687, "num_tokens": 5572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6514483587521877}}
{"text": "\\subsection{Order}\r\nOne way is by this highest order derivative that appears in the equation.\r\n\\begin{definition}\r\n\tThe order of a differential equation is the order of the highest derivative in the equation.\r\n\\end{definition}\r\n\\noindent\r\nBelow is a table of orders and equation numbers.\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{c|c}\r\n\t\tOrder & Equation Number \\\\\r\n\t\t\\hline\r\n\t\t1 &  2, 5, 6, 10 \\\\\r\n\t\t2 & 1, 3, 4, 7, 8, 9 \\\\\r\n\t\\end{tabular}\r\n\\end{table}", "meta": {"hexsha": "04fb8224f2694d21892cfdabecf2024ad09b1ed7", "size": 460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/classification/order.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/order.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/order.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": 28.75, "max_line_length": 94, "alphanum_fraction": 0.6847826087, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7577943603346811, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.6514483460074488}}
{"text": "%\\chapter{Limits of Random Variables}\n\n\n\\chapter{Limit Laws of Statistics}\\label{S:LimitLawsStats}\n\n\\section{Convergence of Random Variables}\\label{S:ConvOfRVs}\n\nThis important topic is concerned with the limiting behavior of sequences of RVs. \nWe want to understand what it means for a sequence of random variables $\\{X_n\\}_{n=1}^{\\infty} := X_1,X_2,\\ldots$ to converge to another random variable $X$, when all RVs are defined on the same probability space $(\\Omega,\\mathcal{F},\\P)$.\n\\[\n\\{X_i \\}_{i=1}^n := X_1,X_2,X_3, \\ldots X_{n-1}, X_n \\qquad \\text{as  $n \\rightarrow \\infty$ .}\n\\]\nFrom a statistical or decision-making viewpoint, as you will see in Inference Theory I course, $n \\rightarrow \\infty$ is associated with the amount of data or information $\\rightarrow \\infty$.  \nMore abstractly, we are interested in what happens to the limiting RV $X := \\lim_{n\\to \\infty} X_n$ when given the DFs $F_n(x)$ for each $X_n$. \n\nWe need different notions of convergence to characterize such a behavior: two simplest behaviors are that the sequence eventually takes a constant value $\\theta$, \ni.e. $X_n$ approaches $X \\sim \\pointmass(\\theta)$ RV, or that values in the sequence continue to change but can be described by an unchanging probability distribution, i.e., $X_n$ approaches $X \\sim F(x)$. See \\url{https://en.wikipedia.org/wiki/Convergence_of_random_variables}.\n\nLet us first refresh ourselves with notions of convergence, limits and continuity in the real line (\\hyperref[S:AnalysisRefresher]{Sec.~\\ref*{S:AnalysisRefresher}}) before proceeding further.\n\nCan the sequences of $\\{\\pointmass(\\theta_i=17)\\}_{i=1}^{\\infty}$ and $\\{\\pointmass(\\theta_i=1/i)\\}_{i=1}^{\\infty}$ RVs be the same as the two sequences of real numbers $\\{ x_i \\}_{i=1}^{\\infty} = 17, 17, 17, \\ldots$ and $\\{ x_i \\}_{i=1}^{\\infty} = \\frac{1}{1},\\frac{1}{2},\\frac{1}{3}, \\ldots$ we saw in Examples~\\ref{EX:limOf17s} and \\ref{EX:limin1overi}?\n\n\nYes why not -- just move to space of distributions over the reals! See Figure~\\ref{F:SequenceOfPointMassRVS17And1Byi}.\n\n\\begin{figure}[htpb]\n\\caption{Sequence of $\\{\\pointmass(17)\\}_{i=1}^{\\infty}$ RVs (left panel) and $\\{\\pointmass(1/i)\\}_{i=1}^{\\infty}$ RVs (only the first seven are shown on right panel) and their limiting RVs in red.\\label{F:SequenceOfPointMassRVS17And1Byi}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/SequenceOfPointMassRVS17And1Byi}}\n\\end{figure}\n\n\\begin{classwork}[Convergence of $X_i \\sim \\normal(0,1/i)$]\\label{CW:Normal01bynConvToPointMass0}\nSuppose you are given an independent sequence of RVs $\\{X_i \\}_{i=1}^n$, where $X_i \\sim \\normal(0,1/i)$.  How would you talk about the convergence of $X_n \\sim \\normal(0,1/n)$ as $n$ approaches $\\infty$ ?  Take a look at \\hyperref[F:PlotNormal01bynConvToPointMass0]{Figure \\ref*{F:PlotNormal01bynConvToPointMass0}} for insight.  The probability mass of $X_n$ increasingly concentrates about $0$ as $n$ approaches $\\infty$ and the variance $1/n$ approaches $0$, as depicted in \\hyperref[F:PlotNormal01bynConvToPointMass0]{Figure \\ref*{F:PlotNormal01bynConvToPointMass0}}.  Based on this observation, can we expect $\\lim_{n \\rightarrow \\infty} X_n = X$, where the limiting RV $X \\sim \\pointmass(0)$ ?\n\nThe answer is {\\bf no}.  This is because $\\P(X_n=X)=0$ for any $n$, since $X \\sim \\pointmass(0)$ is a discrete RV with exactly one outcome $0$ and $X_n \\sim \\normal(0,1/n)$ is a continuous RV for every $n$, however large.  In other words, a continuous RV, such as $X_n$, has $0$ probability of realizing any single real number in its support, such as $0$.    \n\\begin{figure}[htpb]\n\\caption{Distribution functions of several $\\normal(\\mu,\\sigma^2)$ RVs for $\\sigma^2 = 1,\\frac{1}{10},\\frac{1}{100},\\frac{1}{1000}$.\\label{F:PlotNormal01bynConvToPointMass0}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/PlotNormal01bynConvToPointMass0}}\n\\end{figure}\n\\end{classwork}\n\nThus, we need more sophisticated notions of convergence for sequences of RVs.  Two such notions are formalized next as they are minimal prerequisites for a clear understanding of two basic propositions in Statistics :\n\\begin{enumerate} \n\\item Law of Large Numbers,\n\\item Central Limit Theorem,\n%\\item Gilvenko-Cantelli Theorem.\n\\end{enumerate}\n\n\\begin{definition}[Convergence in Distribution (or Weakly, or in Law)]\\label{D:ConvInDist}\nLet $X_1,X_2,\\ldots,$ be a sequence of RVs and let $X$ be another RV.  Let $F_n$ denote the DF of $X_n$ and $F$ denote the DF of $X$.  The we say that $X_n$ converges to $X$ in distribution, and write:\n\\[\nX_n \\rightsquigarrow X\n\\]\nif for any real number $t$ at which $F$ is continuous,\n\\[\n\\lim_{n \\rightarrow \\infty} F_n(t) = F(t) \\qquad \\text{[in the sense of \\hyperref[D:LimitofRealFunction]{Definition \\ref*{D:LimitofRealFunction}}].}\n\\]\nThe above limit, by \\eqref{E:DF} in our \\hyperref[D:DF]{Definition \\ref*{D:DF}} of a DF, can be equivalently expressed as follows: \n\\begin{eqnarray}\n& & \\lim_{n \\rightarrow \\infty} \\P( \\ \\{\\omega: X_n(\\omega) \\leq  t \\} \\ )= \n\\P( \\ \\{\\omega: X(\\omega) \\leq  t \\} \\ ), \\notag \\\\\n&\\text{i.e.~} & \\P( \\ \\{\\omega: X_n(\\omega) \\leq t \\} \\ ) \\rightarrow \\P( \\ \\{\\omega: X(\\omega) \\leq  t \\} \\ ), \\quad \\text{as} \\quad n \\rightarrow \\infty \\notag \\ .\n\\end{eqnarray}\n\\end{definition}\n\nLet us revisit the problem of convergence in \\hyperref[CW:Normal01bynConvToPointMass0]{Classwork \\ref*{CW:Normal01bynConvToPointMass0}} armed with our new notions of convergence.\n\\begin{example}[Convergence in distribution]\\label{EX:Normal01bynConvinDistToPointMass0}\nSuppose you are given an independent sequence of RVs $\\{X_i \\}_{i=1}^n$, where $X_i \\sim \\normal(0,1/i)$ with DF $F_n$ and let $X \\sim \\pointmass(0)$ with DF $F$.  We can formalize our observation in \\hyperref[CW:Normal01bynConvToPointMass0]{Classwork \\ref*{CW:Normal01bynConvToPointMass0}} that $X_n$ is concentrating about $0$ as $n \\to \\infty$ by the statement:\n\\[\n\\text{$X_n$ is converging in distribution to $X$, ie,} \\qquad X_n \\rightsquigarrow X \\ .\n\\]\n{\\normalsize\n\\begin{proof}\nTo check that the above statement is true we need to verify that the definition of convergence in distribution is satisfied for our sequence of RVs $X_1,X_2,\\ldots$ and the limiting RV $X$.  Thus, we need to verify that for any continuity point $t$ of the $\\pointmass(0)$ DF $F$, $\\lim_{n \\to \\infty} F_n(t)=F(t)$.  First note that \n\\[\nX_n \\sim \\normal(0,1/n) \\implies Z := \\sqrt{n} X_n \\sim \\normal(0,1) \\ ,\n\\]\nand thus\n\\[\nF_n(t) = \\P(X_n < t) = \\P(\\sqrt{n} X_n < \\sqrt{n} t) = \\P(Z < \\sqrt{n} t) \\ .\n\\]\nThe only discontinuous point of $F$ is $0$ where $F$ jump from $0$ to $1$.  \n\nWhen $t < 0$, $F(t)$, being the constant $0$ function over the interval $(-\\infty,0)$, is continuous at $t$.  Since $\\sqrt{n} t \\to -\\infty$, as $n \\to \\infty$,\n\\[\n\\lim_{n \\to \\infty} F_n(t)  = \\lim_{n \\to \\infty} \\P(Z < \\sqrt{n} t) = 0 = F(t) \\ .\n\\]\nAnd, when $t >0$, $F(t)$, being the constant $1$ function over the interval $(0,\\infty)$, is again continuous at $t$.  Since $\\sqrt{n} t \\to \\infty$, as $n \\to \\infty$,\n\\[\n\\lim_{n \\to \\infty} F_n(t)  = \\lim_{n \\to \\infty} \\P(Z < \\sqrt{n} t) = 1 = F(t) \\ .\n\\]\nThus, we have proved that $X_n \\rightsquigarrow X$ by verifying that for any $t$ at which the $\\pointmass(0)$ DF $F$ is continuous, we also have the desired equality: $\\lim_{n \\to \\infty} F_n(t)=F(t)$.\n\\end{proof}\nHowever, note that \n\\[\nF_n(0)=\\frac{1}{2} \\neq F(0)=1 \\ ,\n\\]\nand so convergence fails at $0$, i.e.~$\\lim_{n \\to \\infty}F_n(t) \\neq F(t)$ at $t=0$.  But, $t=0$ is not a continuity point of $F$ and the definition of convergence in distribution only requires the convergence to hold at continuity points of $F$.\n}\n\\end{example}\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics[width=10cm]{figures/PDFOf1minusCos2PinxOn01OscillatesIndefinitely.png}\n\\includegraphics[width=5cm]{figures/DFOf1minusCos2PinxOn01To1ApproachesDFOfUniform01.png}\n\\caption{PDF $f_{X_n}(x) := \\BB{1}_{(0,1)}(x)(1-\\cos(2\\pi n x))$ of the RV $X_n$ [the left sub-figure] and its DF $F_n(x) := \\int_{-\\infty}^x\\BB{1}_{(0,1)}(v)(1-\\cos(2\\pi n v))dv$ [the right sub-figure], for $n =1$ [red '- -'], $n=10$ [blue '-.'], and $n=100$ [green '-'], respectively. One can see clear convergence of the DFs $F_n$ to $\\BB{1}_{(0,1)}(x)x$, the DF of the $\\uniform(0,1)$ RV, while the corresponding PDFs $f_n(x)$ keep oscillating wildly with $n$ across $[0,2]$ about $\\BB{1}_{(0,1)}(x)$, the PDF of the $\\uniform(0,1)$ RV $X$. Thus giving a counter-example to the claim that convergence in DFs does not imply convergence in PDFs.\\label{F:ScheffesThmCounterExample}}\n\\end{center}\n\\end{figure}\nConvergence in distribution does not in general imply that the sequence of corresponsing probability density functions will also converge. \nConsider for example RV $X_n$ with density $\\BB{1}_{(0,1)}(x)(1-\\cos(2\\pi n x))$. \nThese RVs converge in distribution to $X \\sim \\uniform(0,1)$, but their densities (PDFs) do not converge at all as evident in Figure~\\ref{F:ScheffesThmCounterExample}. \n\n\\begin{prop}[Scheff\\'e's Theorem]\nAccording to {\\bf Scheff\\'e's Theorem} convergence of the probability density function (for a continuous RV) or probability mass function (for a discrete RV) implies convergence in distribution.\n\\begin{proof}\nWe will state this without a Proof here as Proof of the Theorem requires measure theory in generality \\footnote{See \\url{https://en.wikipedia.org/wiki/Scheff\\%C3\\%A9\\%27s_lemma}.}. However, you should be able to see why convergence of PMFs $f_n(x)$ for discrete RVs $X_n$, to $f(x)$, the PMF of another discrete RV $X$, implies convergence in their corresponding DFs, i.e., $F_n(x) \\to F(x)$ for each $x$ as $n \\to \\infty$. \n\\end{proof}\n\\end{prop}\n\nSince $F(x) = \\P(X \\leq x)$, convergence in distribution means that the probability for $X_n$ to be in a given range is approximately equal to the probability that the value of the limiting RV $X$ is in that range, provided $n$ is sufficiently large. \n\nThus, for a discrete sequence of RVs $X_n$`n to converge in distribution to another discrete RV $X$ taking values in $\\mathbb{Z}_+ = \\{0,1,2,\\ldots\\}$, it is sufficient to show that $\\lim_{n \\to \\infty}\\P(X_n = x) = \\P(X=x)$ for each $x \\in \\mathbb{Z_+}$.  \nWe will use this fact to prove why we can approximate $\\binomial$ RVs by a $\\poisson$ under some limiting conditions.\n\n\\begin{example}[$\\binomial(n,\\lambda/n) {\\rightsquigarrow} \\poisson(\\lambda)$]\\label{EgBinomialConvergesInDistToPoisson}\nIn several situations, as we saw already, it becomes cumbersome to model the events using the $\\binomial(n,\\theta)$ RV, especially when when the parameter $\\theta \\propto 1/n$ and the events become rare.  \n\n\\begin{center}\n\\begin{frame}\n{$\\binomial(n,\\lambda/n)$ converges in distribution to $\\poisson(\\lambda)$ as $n \\to \\infty$, $\\theta=\\lambda/n \\to 0$}\n\\end{frame}\n\\end{center}\n\nHowever, for some real parameter $\\lambda>0$, the $\\binomial(n,\\lambda/n)$ RV with probability of the number of successes in $n$ trials, with per-trial success probability $\\lambda/n$, approaches the Poisson distribution with expectation $\\lambda$, as $n$ approaches $\\infty$ (actually, it converges in distribution).  \nThe $\\poisson(\\lambda)$ RV is much simpler to work with than the combinatorially laden $\\binomial(n,\\theta=\\lambda/n)$ RV.  We sketch the details of this next.\n\nLet $X_n \\sim \\binomial(n,\\theta=\\lambda/n)$ and $Y \\sim \\poisson(\\lambda)$ and let $\\lambda=n\\theta$ remain constant as  $n \\to \\infty$, $\\theta \\to 0$.  \nWe need to show that $\\lim_{n \\to \\infty} \\P(X_n=x) = \\P(Y=x) = e^{-\\lambda}\\lambda^x/x!$ for any $x \\in \\{0,1,2,3,\\ldots,n\\}$. \n%{\\normalsize\n\\begin{eqnarray}\n\\P(X=x)\n&=&\n\\binom{n}{x} \\left( \\frac{\\lambda}{n} \\right)^x \\left( 1- \\frac{\\lambda}{n} \\right)^{n-x} \\notag \\\\\n&=& \\frac{n(n-1)(n-2)\\cdots(n-x+1)}{x(x-1)(x-2)\\cdots (2)(1)}\n\\left( \\frac{\\lambda^x}{n^x} \\right)\n\\left( 1- \\frac{\\lambda}{n} \\right)^n\n\\left( 1- \\frac{\\lambda}{n} \\right)^{-x} \\notag \\\\\n&=&\n\\overbrace{\\left( \\frac{n}{n} \\right) \\left( \\frac{n-1}{n} \\right) \\left( \\frac{n-2}{n} \\right) \\cdots \\left( \\frac{n-x+1}{n} \\right)}\n\\overbrace{\\left( \\frac{\\lambda^x}{x!} \\right)}\n\\underbrace{\\left( 1- \\frac{\\lambda}{n} \\right)^n}\n\\underbrace{\\left( 1- \\frac{\\lambda}{n} \\right)^{-x}}  \\notag \\\\\n\\end{eqnarray}\n\nAs $n \\to \\infty$, the expression below the first overbrace $\\to 1$, while that below the second overbrace, being independent of $n$ remains the same.  By the elementary examples of limits\n%\\remove{\n\\ref*{EX:LimitExpofLambda} and \\ref*{EX:Limit1MinusLambdaOverNToMinusK}%}\n, as $n \\to \\infty$, the expression over the first underbrace approaches $e^{-\\lambda}$ while that over the second underbrace approaches $1$.  Finally, we get the desired limit:\n\n\\[\n\\lim_{n \\to \\infty} \\P(X=x)\n= \\frac{ e^{-\\lambda} \\lambda^x}{x!}  \\ .\n\\]\n%}\n\\end{example}\n\nThe second notion of convergence of RVs is convergence in probability.\n\n\\begin{definition}[Convergence in Probability]\\label{D:ConvInProb}\nLet $X_1,X_2,\\ldots,$ be a sequence of RVs and let $X$ be another RV.  Let $F_n$ denote the DF of $X_n$ and $F$ denote the DF of $X$.  The we say that $X_n$ converges to $X$ in probability, and write:\n\\[\nX_n \\overset{\\P}{\\longrightarrow} X\n\\]\nif for every real number $\\epsilon > 0$,\n\\[\n\\lim_{n \\rightarrow \\infty} \\P(|X_n-X|> \\epsilon) = 0 \\qquad \\text{[in the sense of \\hyperref[D:LimitofRealFunction]{Definition \\ref*{D:LimitofRealFunction}}].}\n\\]\nOnce again, the above limit, by \\eqref{E:ProbOfRV} in our \\hyperref[D:RV]{Definition \\ref*{D:RV}} of a RV, can be equivalently expressed as follows: \n\\[\n\\lim_{n \\rightarrow \\infty} \\P( \\ \\{\\omega: |X_n(\\omega) - X(\\omega)| > \\epsilon\\} \\ )=0, \\qquad \\text{ie,} \\qquad \\P( \\ \\{\\omega: |X_n(\\omega) - X(\\omega)| > \\epsilon\\} \\ ) \\rightarrow 0, \\quad \\text{as} \\quad n \\rightarrow \\infty \\ .\n\\]\n\\end{definition}\n \nFor the same sequence of RVs in  \\hyperref[CW:Normal01bynConvToPointMass0]{Classwork \\ref*{CW:Normal01bynConvToPointMass0}} and \\hyperref[EX:Normal01bynConvinDistToPointMass0]{Example \\ref*{EX:Normal01bynConvinDistToPointMass0}} we are tempted to ask whether $X_n \\sim \\normal(0,1/n)$ converges in probability to $X \\sim \\pointmass(0)$, i.e.~whether $X_n \\overset{\\P}{\\longrightarrow} X$.  We need some elementary inequalities in Probability to help us answer this question.  We visit these inequalities next.\n\n\n\\begin{prop}[Markov's Inequality]\nLet $(\\Omega,\\C{F},P)$ be a probability triple and let $X=X(\\omega)$ be a non-negative RV.  Then,\n\\begin{equation}\\label{E:MarkovNeq}\n\\P(X \\geq \\epsilon) \\leq \\frac{\\E(X)}{\\epsilon}, \\qquad \\text{for any} \\quad \\epsilon > 0 \\ .\n\\end{equation}\n{\\normalsize\n\\begin{proof}\n\\begin{eqnarray}\nX &=& X \\BB{1}_{ \\{y: y \\geq \\epsilon \\} } (x) + X \\BB{1}_{ \\{y: y < \\epsilon \\} } (x) \\notag \\\\\n&\\geq& X \\BB{1}_{ \\{y: y \\geq \\epsilon \\} } (x) \\notag \\\\\n&\\geq& \\epsilon  \\BB{1}_{ \\{y: y \\geq \\epsilon \\} } (x) \\notag \\\\\n\\end{eqnarray}\nFinally, taking expectations on both sides of the above inequality and then using the fact that the expectation of an indicator function of an event is simply the probability of that event \\eqref{E:ExpectationofIndicator}, we get the desired result:\n\\[\n\\E(X) \\geq \\epsilon \\E( \\BB{1}_{ \\{y: y \\geq \\epsilon \\} } (x)) = \\epsilon \\P(X \\geq \\epsilon) \\ .\n\\]\n\\end{proof}\n}\n\\end{prop}\nLet us look at some immediate consequences of Markov's inequality.\n\\begin{prop}[Chebychev's Inequality]\nFor {\\bf any} RV $X$ and any $\\epsilon > 0$,\n\\begin{eqnarray}\n\\P(|X| > \\epsilon) &\\leq& \\frac{\\E(|X|)}{\\epsilon} \\label{E:ChebychevNeq1} \\\\\n\\P(|X| > \\epsilon) = \\P(X^2 \\geq \\epsilon^2) &\\leq& \\frac{\\E(X^2)}{\\epsilon^2} \\label{E:ChebychevNeq2} \\\\\n\\P(|X-\\E(X)| \\geq \\epsilon) = \\P((X-\\E(X))^2 \\geq \\epsilon^2) &\\leq& \\frac{\\E(X-\\E(X))^2}{\\epsilon^2}  = \\frac{\\V(X)}{\\epsilon^2}  \\label{E:ChebychevNeq3} \n\\end{eqnarray}\n{\\normalsize\n\\begin{proof}\nAll three forms of Chebychev's inequality are mere corollaries (careful reapplications) of Markov's inequality.\n\\end{proof}\n}\n\\end{prop}\n\nArmed with Markov's inequality we next enquire the convergence in probability for the sequence of RVs in \\hyperref[CW:Normal01bynConvToPointMass0]{Classwork \\ref*{CW:Normal01bynConvToPointMass0}} and \\hyperref[EX:Normal01bynConvinDistToPointMass0]{Example \\ref*{EX:Normal01bynConvinDistToPointMass0}}.\n\n\\begin{example}[Convergence in probability]\\label{EX:Normal01bynConvinProbToPointMass0}\nDoes the the sequence of RVs $\\{X_n\\}_{n=1}^{\\infty}$, where $X_n \\sim \\normal(0,1/n)$, converge in probability to $X \\sim \\pointmass(0)$, i.e.~does $X_n \\overset{\\P}{\\longrightarrow} X$ ?\n\nTo find out if $X_n \\overset{\\P}{\\longrightarrow} X$, we need to show that for any $\\epsilon >0$, $\\lim_{n \\to \\infty} \\P(|X_n-X|>\\epsilon)=0$.\n\nLet $\\epsilon$ be any real number greater than $0$, then\n\\begin{eqnarray}\n\\P(|X_n|>\\epsilon) &=& \\P(|X_n|^2 > \\epsilon^2) \\notag \\\\\n&\\leq& \\frac{\\E(X_n^2)}{\\epsilon^2} \\qquad \\text{[by Markov's Inequality \\eqref{E:MarkovNeq}]} \\notag \\\\\n&=& \\frac{\\frac{1}{n}}{\\epsilon^2} \\to 0, \\quad \\text{as} \\quad n \\to \\infty \\qquad \\text{[in the sense of \\hyperref[D:LimitofRealFunction]{Definition \\ref*{D:LimitofRealFunction}}].} \\notag\n\\end{eqnarray}\nHence, we have shown that for any $\\epsilon >0$, $\\lim_{n \\to \\infty} \\P(|X_n-X|>\\epsilon)=0$ and therefore by \\hyperref[D:ConvInProb]{Definition \\ref*{D:ConvInProb}}, $X_n \\overset{\\P}{\\longrightarrow} X$ or $X_n \\overset{\\P}{\\longrightarrow} 0$.  \n\n{\\normalsize\n{\\bf Convention:} When $X$ has a $\\pointmass(\\theta)$ distribution and $X_n \\overset{\\P}{\\longrightarrow} X$, we simply write $X_n \\overset{\\P}{\\longrightarrow} \\theta$.\n}\n\\end{example}\n\n\\begin{definition}[Convergence Almost Surely (or with Probability $1$)]\nTo say that the sequence of RVs $\\{X_n\\}_{n=1}^{\\infty}$ converges almost surely (or with probability $1$ or strongly) towards another RV $X$ on the same probability space $(\\Omega,\\mathcal{F},\\P)$, as denoted by\n\\[\nX_n \\overset{a.s.}{\\to} X\n\\]\nmeans that\n\\[\n\\P \\left( \\{ \\lim_{n \\to \\infty} X_n = X \\} \\right) = 1 \\quad \\iff \\quad \\P \\left( \\{\\omega \\in \\Omega : \\lim_{n \\to \\infty} X_n(\\omega) = X(\\omega)\\} \\right) = 1.\n\\]\nThis means that the values of $X_n$ approach the value of $X$, in the sense that events for which $X_n$ does not converge to $X$ have probability $0$.\n\\end{definition}\n\nOther notions of convergence are termed sure convergence or pointwise convergence, such as convergence in mean. \nBut the above three types of convergence are elementary. % and enough to appreciate the subtle issues with convergence of random variables.\n\n\\subsection{Properties of Convergence of RVs$^{**}$}\n\nWe will merely state some properties (without proofs that are hyper-linked for the curious student as they are advanced for this course) and relations between the three notions of convergence with some examples to better appreciate the subtleties among them. \nYou will study the proofs of these statements in Probability Theory II. \nJust remember that subtle implication relations exist between the three notions.\n\n\n%Now that we have been introduced to three notions of convergence for sequences of RVs we can begin to appreciate the  construction of limiting random variables from existing ones. % We will see a limiting sum of $n$ independent $\\bernoulli(\\theta)$ RVs as $n \\to \\infty$ and $\\theta \\to 0$ such that $n \\theta = \\lambda$. %  statements of the basic limit theorems of Statistics.  \n%But first we need some analytic tools.\n\n%But first we formally define a statistic.\n\n\n\\bit\n\\item Convergence almost surely implies convergence in probability\\footnote{{\\tiny \\url{https://en.wikipedia.org/wiki/Proofs\\_of\\_convergence\\_of\\_random\\_variables\\#Convergence\\_almost\\_surely\\_implies\\_convergence\\_in\\_probability}}}\n\\[\n\\boxed{X_n \\overset{a.s.}{\\to} X \\implies X_n \\overset{\\P}{\\to} X \\enspace .}\n\\]\n\\item By the Borel-Cantelli Lemma \\footnote{{\\tiny \\url{https://en.wikipedia.org/wiki/Borel\\%E2\\%80\\%93Cantelli\\_lemma}}}, convergence in probability does not imply almost sure convergence in the discrete case \\footnote{{\\tiny \\url{https://en.wikipedia.org/wiki/Proofs_of_convergence_of_random_variables\\#Convergence_in_probability_does_not_imply_almost_sure_convergence_in_the_discrete_case}}}\n\\item Convergence in probability implies convergence in distribution \\footnote{{\\tiny \\url{https://en.wikipedia.org/wiki/Proofs_of_convergence_of_random_variables\\#Convergence_in_probability_implies_convergence_in_distribution}}} \n\\[\n\\boxed{X_n \\overset{\\P}{\\to} X \\implies X_n \\rightsquigarrow X \\enspace .}\n\\]\n\\item Convergence in distribution to a constant $\\theta$ implies convergence in probability to $\\theta$: \\footnote{{\\tiny \\url{https://en.wikipedia.org/wiki/Proofs_of_convergence_of_random_variables\\#Convergence_in_distribution_to_a_constant_implies_convergence_in_probability}}}\n\\[\nX_n \\rightsquigarrow \\pointmass(\\theta) \\implies X_n \\overset{\\P}{\\to} \\pointmass(\\theta) \\enspace . \n\\] \n\\item In general, convergence in distribution does not imply convergence in probability.  %\\footnote{{\\tiny \\url{}}} \n\\eit\n\n\n\\section{Law of Large Numbers}\n\n\\begin{prop}[Law of Large Numbers (LLN): $\\overline{X}_n \\overset{\\P}{\\longrightarrow} \\E(X_1)$]\nIf we are given a sequence if independent and identically distributed RVs, $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ and if $\\E(X_1)$ exists, as per \\eqref{E:ExpectationExists}, i.e., $\\E(\\abs(X_1))< \\infty$, and the variance is finite, i.e., $\\V(X_1) < \\infty$, then the sample mean $\\overline{X}_n$ converges in probability to the expectation of any one of the IID RVs, say $\\E(X_1)$ by convention.  More formally, we write:\n\\[\n\\text{If} \\quad X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1 \\ \\text{and if } \\ \\E(X_1) \\ \\text{exists, then } \\ \\overline{X}_n \\overset{\\P}{\\longrightarrow} \\E(X_1) \\ .\n\\]\n{\\normalsize\n\\begin{proof}\nBecause $\\V(X_1) < \\infty$, we have:\n\\begin{eqnarray}\n\\P(| \\overline{X}_n - \\E(\\overline{X}_n) | \\geq \\epsilon)\n&=& \\frac{\\V(\\overline{X}_n)}{\\epsilon^2} \\qquad \\text{{\\scriptsize [by applying Chebychev's inequality \\eqref{E:ChebychevNeq3} to the RV $\\overline{X}_n$]}} \\notag \\\\\n&=& \\frac{\\frac{1}{n}\\V(X_1)}{\\epsilon^2} \\qquad \\text{{\\scriptsize [by the IID assumption of $X_1,X_2,\\ldots$ we can apply \\eqref{E:VarOfSampleMeanOfIIDSeq}]}} \\notag \n\\end{eqnarray}\nTherefore, for any given $\\epsilon>0$,\n\\begin{eqnarray}\n\\P(| \\overline{X}_n - \\E(X_1) | \\geq \\epsilon)\n&=&  \\P(| \\overline{X}_n - \\E(\\overline{X}_n) | \\geq \\epsilon) \\qquad \\text{{\\scriptsize [by the IID assumption of $X_1,X_2,\\ldots$,  $\\E(\\overline{X}_n)=\\E(X_1)$, as per \\eqref{E:ExpOfSampleMeanOfIDSeq}]}} \\notag \\\\\n&=&  \\frac{\\frac{1}{n}\\V(X_1)}{\\epsilon^2} \\to 0, \\quad \\text{as} \\quad n \\to \\infty \\ , \\notag\n\\end{eqnarray}\nor equivalently, $\\lim_{n \\to \\infty} \\P(| \\overline{X}_n - \\E(X_1) | \\geq \\epsilon) = 0$.  And the last statement is the definition of the claim made by the law of large numbers (LLN), namely that $\\overline{X}_n \\overset{\\P}{\\longrightarrow} \\E(X_1)$ .\n\\end{proof}\n}\n\n\\begin{prop}[Weak Law of Large Numbers (WLLN): $\\overline{X}_n \\rightsquigarrow \\pointmass(\\E(X_1))$]\nIf we are given a sequence of independently and identically distributed (IID) RVs, $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ and if $\\E(X_1)$ exists, i.e.~$\\E(\\abs(X)) < \\infty$, then the sample mean $\\overline{X}_n$ converges in distribution to the expectation of any one of the IID RVs, say $\\pointmass(\\E(X_1))$ by convention.  More formally, we write:\n\\[\n\\text{If} \\quad X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1 \\ \\text{and if } \\ \\E(X_1) \\ \\text{exists, then } \\ \\overline{X}_n \\rightsquigarrow \\pointmass(\\E(X_1)) \\ \\text{ as } n\\to\\infty \\enspace .\n\\]\n\\end{prop}\n\n{\\normalsize\n\\begin{proof}\nOur proof now is based on the convergence of characteristic functions (CFs) pointwise to the CF of the limiting RV, as this implies, by L\\'evy's Continuity Theorem on CFs \\footnote{\\url{https://en.wikipedia.org/wiki/L\\%C3\\%A9vy\\%27s_continuity_theorem}}, the convergence of the corresponding distribution functions (DFs).  \n\nFirst, the CF of $\\pointmass(\\E(X_1))$ is \n\\[\n\\E(e^{\\imath t \\E(X_1)})=e^{\\imath t \\E(X_1)} \\enspace,\n\\]\nsince $\\E(X_1)$ is just a constant, i.e., a $\\pointmass$ RV that puts all of its probability mass at $\\E(X_1)$.  \n\nSecond, the CF of $\\ol{X}_n$ is \n\\begin{align*}\n\\E \\left( e^{\\imath t \\ol{X}_n}\\right)\n&= \\E \\left( e^{\\imath t \\frac{1}{n} \\sum_{k=1}^n X_k} \\right) = \\E \\left( \\prod_{k=1}^n e^{\\imath t X_k/n} \\right) = \\prod_{k=1}^n \\E \\left( e^{\\imath t X_k/n} \\right) = \\prod_{k=1}^n \\cf_{X_k}(t/n)\\\\ \n&= \\prod_{k=1}^n \\cf_{X_1}(t/n) =\\left(\\cf_{X_1}(t/n)\\right)^n \\enspace .\n\\end{align*}\n\nLet us recall Landau's ``small o'' notation for the relation between two functions.  \nWe say,  $f(x)$ is {\\bf small o} of $g(x)$ if $f$ is dominated by $g$ as $x \\to \\infty$, i.e., $\\frac{|f(x)|}{|g(x)|} \\to 0$ as $x \\to \\infty$.  \nMore formally, for every $\\epsilon > 0$, there exists an $x_{\\epsilon}$ such that for all $x > x_{\\epsilon}$ $|f(x)| < \\epsilon |g(x)|$.  \nFor example, $\\log(x)$ is $o(x)$, $x^2$ is $o(x^3)$ and $x^m$ is $o(x^{m+1})$ for $m\\geq 1$.  \n\nThird, we can expand any CF whose expectation exists as a Taylor series with a remainder term that is $o(t)$ as follows:\n\\[\n\\cf_X(t) = 1 + \\imath t \\E(X) + o(t) \\enspace .\n\\]\nHence,\n\\[\n\\cf_{X_1}(t/n) = 1 + \\imath \\frac{t}{n} \\E(X_1) + o\\left(\\frac{t}{n}\\right) \n\\]\nand\n\\[\nE \\left( e^{\\imath t \\ol{X}_n}\\right) = \\left( 1 + \\imath \\frac{t}{n} \\E(X_1) + o\\left(\\frac{t}{n}\\right) \\right)^n\n\\to e^{\\imath t \\E(X_1)} \\text{ as } n \\to \\infty \\enspace .\n\\]\nFor the last limit we have used $\\left( 1+\\frac{x}{n}\\right)^n \\to e^x$ as $n \\to \\infty$.\n\nFinally, we have shown that $E \\left( e^{\\imath t \\ol{X}_n}\\right)$, the CF of the $n$-sample mean RV $\\ol{X}_n$, converges to $\\E(e^{\\imath t \\E(X_1)})=e^{\\imath t \\E(X_1)}$, the CF of the $\\pointmass(\\E(X_1))$ RV, as the sample size $n$ tends to infinity.\n\\end{proof}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%--too heavy for Inference Course - not introduced to conv in prob, Markov ineq or Chebychev ineq\n%\\begin{proof}\n%For simplicity, we will prove a slightly weaker result by assuming finite variance of $X_1$.  Suppose $\\V(X_1) < \\infty$, then:\n%\\begin{eqnarray}\n%\\P(| \\overline{X}_n - \\E(\\overline{X}_n) | \\geq \\epsilon)\n%&=& \\frac{\\V(\\overline{X}_n)}{\\epsilon^2} \\qquad \\text{{\\scriptsize [by applying Chebychev's inequality \\eqref{E:ChebychevNeq3} to the RV $\\overline{X}_n$]}} \\notag \\\\\n%&=& \\frac{\\frac{1}{n}\\V(X_1)}{\\epsilon^2} \\qquad \\text{{\\scriptsize [by the IID assumption of $X_1,X_2,\\ldots$ we can apply \\eqref{E:VarOfSampleMeanOfIIDSeq}]}} \\notag \n%\\end{eqnarray}\n%Therefore, for any given $\\epsilon>0$,\n%\\begin{eqnarray}\n%\\P(| \\overline{X}_n - \\E(X_1) | \\geq \\epsilon)\n%&=&  \\P(| \\overline{X}_n - \\E(\\overline{X}_n) | \\geq \\epsilon) \\qquad \\text{{\\scriptsize [by the IID assumption of $X_1,X_2,\\ldots$,  $\\E(\\overline{X}_n)=\\E(X_1)$, as per \\eqref{E:ExpOfSampleMeanOfIDSeq}]}} \\notag \\\\\n%&=&  \\frac{\\frac{1}{n}\\V(X_1)}{\\epsilon^2} \\to 0, \\quad \\text{as} \\quad n \\to \\infty \\ , \\notag\n%\\end{eqnarray}\n%or equivalently, $\\lim_{n \\to \\infty} \\P(| \\overline{X}_n - \\E(X_1) | \\geq \\epsilon) = 0$.  And the last statement is the Definition of the claim made by the weak law of large numbers (LLN), namely that $\\overline{X}_n \\overset{\\P}{\\longrightarrow} \\E(X_1)$ .\n%\\end{proof}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n}\n\\end{prop}\n\n\n\\subsubsection{Heuristic Interpretation of LLN}  \nThe distribution of the sample mean RV $\\overline{X}_n$ obtained from an independent and identically distributed sequence of RVs $X_1,X_2,\\ldots$ {\\scriptsize [i.e.~all the RVs $X_i$'s are independent of one another and have the same distribution function, and thereby the same expectation, variance and higher moments]}, concentrates around the expectation of any one of the RVs in the sequence, say that of the first one $\\E(X_1)$ {\\scriptsize [without loss of generality]}, as $n$ approaches infinity.  See Figure~\\ref{F:RunningMeansFairDieFairCoinUnif01Exp1By10} for examples of 20 replicates of the sample mean of IID sequences from four RVs.  All the sample mean trajectories converge to the corresponding population mean. \n\n\\begin{figure}[htpb]\n\\caption{Sample mean $\\ol{X}_n$ as a function of sample size $n$ for 20 replications from independent realizations of a fair die (blue), fair coin (magenta), $\\uniform(0,30)$ RV (green) and $\\exponential(0.1)$ RV (red) with population means $(1+2+3+4+5+6)/6=21/6=3.5$, $(0+1)/2=0.5$, $(30-0)/2=15$ and $1/0.1=10$, respectively.\\label{F:RunningMeansFairDieFairCoinUnif01Exp1By10}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/RunningMeansFairDieFairCoinUnif01Exp1By10}}\n\\end{figure}\n\n\\begin{example}[Bernoulli WLLN and Galton's Quincunx]\\label{EgBernoulliWLLN}\nWe can appreciate the WLLN for $\\overline{X}_n = n^{-1} S_n = \\sum_{i=1}^{n} X_i$, where $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} Bernoulli(p)$ using the paths of balls dropped into Galton's Quincunx of Sec.~\\ref{S:Quincunx}.\n\\end{example}\n\n\\subsubsection{$\\cauchy$ whose expectations does not exist has no Law of Large Numbers}\n\n Recall that the mean of the $\\cauchy$ RV $X$ does not exist since $\\int \\left|x\\right|\\,dF(x) = \\infty$ \\eqref{E:CauchyMeanDoesNotExist}.  We will investigate this in \\hyperref[LW:RunningMeanCauchy]{Labwork~\\ref*{LW:RunningMeanCauchy}}.\n\n \\begin{labwork}[Running mean of the Standard Cauchy RV]\\label{LW:RunningMeanCauchy}\nLet us see what happens when we plot the running sample mean for an increasing sequence of IID samples from the Standard Cauchy RV $X$ by implementing the following script file:\n \\VrbMf[label=PlotStandardCauchyRunningMean.m]{scripts/PlotStandardCauchyRunningMean.m}\n\n%}%end remove\n\n\\begin{figure}[htpb]\n\\caption{Unending fluctuations of  the running means based on $n$ IID samples from the Standard $\\cauchy$ RV $X$ in each of five replicate simulations (blue lines).  The running means, based on $n$ IID samples from the $\\uniform(0,10)$ RV, for each of five replicate simulations (magenta lines). \\label{F:plot5RunningMeansStandardcauchyUnif010}}\n\\centering   \\makebox{\\includegraphics[width=5.5in]{figures/plot5RunningMeansStandardcauchyUnif010}}\n\\end{figure}\n\nThe resulting plot is shown in \\hyperref[F:plot5RunningMeansStandardcauchyUnif010]{Figure~\\ref*{F:plot5RunningMeansStandardcauchyUnif010}}.  Notice that the running means or the sample mean of $n$ samples as  a function of $n$, for each of the five replicate simulations, never settles down to a particular value.  This is because of the ``thick tails'' of the density function for this RV which produces extreme observations.  Compare them with the running means, based on $n$ IID samples from the $\\uniform(0,10)$ RV, for each of five replicate simulations (magenta lines).  The latter sample means have settled down stably to the mean value of $5$ after about $700$ samples.\n%\\remove{\n\\end{labwork}\n%}%end remove\n\n\n\\subsection{Application: Point Estimation of $E(X_1)$}\nLLN gives us a method to obtain a {\\bf point estimator} that gives ``the single best guess'' for the possibly unknown population mean $E(X_1)$ based on $\\ol{X}_n$, the sample mean, of a simple random sequence (SRS) or independent and identically distributed (IID) sequence of $n$ RVs $X_1,X_2,\\ldots, X_n \\overset{IID}{\\sim} X_1$.\n\n\\begin{example}\\label{Eg:LLNExponential}\nLet $X_1,X_2,\\ldots, X_n \\overset{IID}{\\sim} X_1$, where $X_1$ is an $\\exponential(\\lambda^*)$ RV, i.e., let\n\\[\nX_1,X_2,\\ldots, X_n \\overset{IID}{\\sim} \\exponential(\\lambda^*) \\enspace .\n\\]\nTypically, we do not know the ``true'' parameter $\\lambda^* \\in \\BB{\\Lambda} = (0,\\infty)$ or the population mean $E(X_1) = 1/\\lambda^*$.  \nBut by LLN, we know that\n\\[\n\\ol{X}_n \\rightsquigarrow \\pointmass(E(X_1)) \\enspace ,\n\\]\nand therefore, we can use the sample mean $\\ol{X}_n$ as a point estimator of $E(X_1)= 1/\\lambda^*$.  \n\nNow, suppose you model seven waiting times in nearest minutes between Orbiter buses at Balgay street as follows:\n\\[\nX_1,X_2,\\ldots, X_7 \\overset{IID}{\\sim} \\exponential(\\lambda^*) \\enspace ,\n\\]\nand have the following realization as your observed data:\n\\[\n(x_1,x_2,\\ldots,x_7) = (2,12,8,9,14,15,11) \\enspace .\n\\]\nThen you can use the observed sample mean $\\ol{x}_7=(2+12+8+9+14+15+11)/7=71/7 \\approxeq 10.14$ as a {\\bf point estimate} of the population mean $E(X_1)=1/\\lambda^*$.  \nBy the rearrangement $\\lambda^*=1/E(X_1)$, we can also obtain a point estimate of the ``true'' parameter $\\lambda^*$ from $1/\\ol{x}_7=7/71 \\approxeq 0.0986$. \n\\end{example}\n\n\\begin{rem}[Point estimates are realizations of the Point Estimator]\nWe say the statistic $\\ol{X}_n$, which is a random variable that depends on the data \\rv~$(X_1,X_2,\\ldots,X_n)$, is a {\\bf point estimator} of $E(X_1)$.  \nBut once we have a realization of the data \\rv~, i.e., our observed data vector $(x_1,x_2,\\ldots,x_n)$ and its corresponding realization as observed sample mean $\\ol{x}_n$, we say $\\ol{x}_n$ is a {\\bf point estimate} of $E(X_1)$.  In other words, the point estimate $\\ol{x}_n$ is a realization of the the random variable $\\ol{X}_n$ called the point estimator of $E(X_1)$.  \nTherefore, when we observe a new data vector $(x'_1,x'_2,\\ldots,x'_n)$  that is different from our first data vector $(x_1,x_2,\\ldots,x_n)$, our point estimator of $E(X_1)$ is still $\\ol{X}_n$ but the point estimate $n^{-1}\\sum_{i=1}^nx'_i$ may be different from the first point estimate $n^{-1}\\sum_{i=1}^nx_i$.  The sample means from $n$ samples for 20 replications (repeats of the experiment) are typically distinct especially for small $n$ as shown in Figure~\\ref{F:RunningMeansFairDieFairCoinUnif01Exp1By10}.\n\\end{rem}\n\n\\begin{example}\\label{Eg:LLNBernoulli}\nLet $X_1,X_2,\\ldots, X_n \\overset{IID}{\\sim} X_1$, where $X_1$ is an $\\bernoulli(\\theta^*)$ RV, i.e., let\n\\[\nX_1,X_2,\\ldots, X_n \\overset{IID}{\\sim} \\bernoulli(\\theta^*) \\enspace .\n\\]\nTypically, we do not know the ``true'' parameter $\\theta^* \\in \\BB{\\Theta} = [0,1]$, which is the same as the population mean $E(X_1) = \\theta^*$.  \nBut by LLN, we know that\n\\[\n\\ol{X}_n \\rightsquigarrow \\pointmass(E(X_1)) \\enspace ,\n\\]\nand therefore, we can use the sample mean $\\ol{X}_n$ as a point estimator of $E(X_1)= \\theta^*$.  \n\nNow, suppose you model seven coin tosses (encoding {\\sf Heads} as $1$ with probability $\\theta^*$ and {\\sf Tails} as $0$ with probability $1-\\theta^*$) as follows:\n\\[\nX_1,X_2,\\ldots, X_7 \\overset{IID}{\\sim} \\bernoulli(\\theta^*) \\enspace ,\n\\]\nand have the following realization as your observed data:\n\\[\n(x_1,x_2,\\ldots,x_7) = (0,1,1,0,0,1,0) \\enspace .\n\\]\nThen you can use the observed sample mean $\\ol{x}_7=(0+1+1+0+0+1+0)/7=3/7 \\approxeq 0.4286$ as a {\\bf point estimate} of the population mean $E(X_1)=\\theta^*$.  \nThus, our ``single best guess'' for $E(X_1)$ which is the same as the probability of {\\sf Heads} is $\\ol{x}_7=3/7$.  \n\\end{example}\n\nOf course, if we tossed the same coin in the same IID manner another seven times or if we observed another seven waiting times of orbiter buses at a different bus-stop or on a different day we may get a different point estimate for $E(X_1)$.  \nSee the intersection of the twenty magenta sample mean trajectories for simulated tosses of a fair coin from IID $\\bernoulli(\\theta^*=1/2)$ RVs and the twenty red sample mean trajectories for simulated waiting times from IID $\\exponential(\\lambda^*=1/10)$ RVs in Figure~\\ref{F:RunningMeansFairDieFairCoinUnif01Exp1By10} with $n=7$.  \nClearly, the point estimates for such a small sample size are fluctuating wildly!  \nHowever, the fluctuations in the point estimates settles down for larger sample sizes.  \n\n\nThe {\\em next natural question is how large should the sample size be} in order to have a small interval of width, say $2 \\epsilon$, ``contain'' $E(X_1)$, the quantity of interest, with a high probability, say $1-\\alpha$?  If we can answer this then we can make probability statements like the following:\n\\[\nP( \\mathsf{error} < \\mathsf{tolerance}) = P( |\\ol{X}_n - E(X_1)| < \\epsilon ) = P(-\\epsilon < \\ol{X}_n - E(X_1) < \\epsilon) = 1-\\alpha \\enspace .\n\\]\n\nIn order to ensure the $\\mathsf{error}=|\\ol{X}_n - E(X_1)|$ in our estimate of $E(X_1)$ is within a required $\\mathsf{tolerance}=\\epsilon$ we need to know the full distribution of $\\ol{X}_n - E(X_1)$ itself.  The Central Limit Theorem (CLT) helps us here.\n\n\n\\section{Central Limit Theorem}\n\nWhat if we scale the sum of $X_i$`s by $\\sqrt{n}$ instead of $n$?\n\n\\begin{Exercise}[title={What if we scale by $\\sqrt{n}$},label={xSumOFUnifminu1To1DividedBySqrtn}]\nAfter reading Sec.~\\ref{S:ConvOfRVs} up to now, think carefully about what you need to be able to show that $Z_n := 1/\\sqrt{n}\\sum_{i=1}^n X_i$ converges in distribution to the $\\normal(0,1/3)$ RV, where $X_i \\overset{IID}{\\sim} \\uniform(-1,1)$. {Hint: Characteristic functions}\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\n\\remove{ % removing CSE book CLT without proof\n\\begin{prop}[Central Limit Theorem (CLT)]\nLet $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ and suppose $\\E(X_1)$ and $\\V(X_1)$ exists, then \n{\\small\n\\begin{eqnarray}\n%1\n\\overline{X}_n = \\frac{1}{n} \\sum_{i=1}^n X_i \n& \\rightsquigarrow & \nX \\sim \\normal \\left( \\E(X_1),\\frac{\\V(X_1)}{n}  \\right) \\ , \\\\\n%2\n\\overline{X}_n -\\E(X_1) \n& \\rightsquigarrow & \nX-\\E(X_1) \\sim \\normal \\left( 0,\\frac{\\V(X_1)}{n}  \\right) \\ , \\\\\n%3\n\\sqrt{n} \\left( \\overline{X}_n -\\E(X_1) \\right)\n& \\rightsquigarrow & \n\\sqrt{n} \\left( X-\\E(X_1) \\right) \\sim \\normal \\left( 0,\\V(X_1)  \\right) \\ , \\\\\n%4\nZ_n :=  \\frac{\\overline{X}_n-\\E(\\overline{X}_n)}{\\sqrt{\\V(\\overline{X}_n)}} \n= \\frac{\\sqrt{n} \\left( \\overline{X}_n -\\E(X_1) \\right)}{\\sqrt{\\V(X_1)}}\n& \\rightsquigarrow & \nZ  \\sim \\normal \\left( 0,1  \\right) \\ , \\\\\n%5\n\\lim_{n \\to \\infty} P\\left( \\frac{\\overline{X}_n-\\E(\\overline{X}_n)}{\\sqrt{\\V(\\overline{X}_n)}}  \\leq z \\right)\n= \\lim_{n \\to \\infty} \\P(Z_n \\leq z)\n&=&\n\\Phi(z) := \\int_{- \\infty}^z \\left( \\frac{1}{\\sqrt{2 \\pi}} \\ \\exp \\left( \\frac{-x^2}{2} \\right) \\right) dx \\ .\n\\end{eqnarray}\n}\nThus, for sufficiently large $n$ (say $n>30$) we can make the following approximation:\n\\begin{equation}\\label{E:CLTApprox}\nP\\left( \\frac{\\overline{X}_n-\\E(\\overline{X}_n)}{\\sqrt{\\V(\\overline{X}_n)}}  \\leq z \\right) \n\\approxeq \n\\P(Z \\leq z)\n=\n\\Phi(z) := \\int_{- \\infty}^z \\left( \\frac{1}{\\sqrt{2 \\pi}} \\ \\exp \\left( \\frac{-x^2}{2} \\right) \\right) dx \\ .\n\\end{equation}\n{\\scriptsize\n\\begin{proof}\nSee any intermediate to advanced undergraduate text in Probability.  Start from the index looking for ``Central Limit Theorem'' to find the page number for the proof \\ldots .\n\\end{proof}\n}\n{\\bf Heuristic Interpretation of CLT:}  Probability statements about the sample mean RV $\\overline{X}_n$ can be approximated using a Normal distribution. \n\\end{prop}\nHere is a simulation showing CLT in action.\n\\begin{VrbM}\n>> % a demonstration of Central Limit Theorem --\n>> % the sample mean of a sequence of n IID Exponential(lambda) RVs \n>> % itself a Gaussian(1/lambda,lambda/n) RV\n>> lambda=0.1; Reps=10000; n=10; hist(sum(-1/lambda * log(rand(n,Reps)))/n)\n>> lambda=0.1; Reps=10000; n=100; hist(sum(-1/lambda * log(rand(n,Reps)))/n,20)\n>> lambda=0.1; Reps=10000; n=1000; hist(sum(-1/lambda * log(rand(n,Reps)))/n,20)\n\\end{VrbM}\n\nLet us look at an example that makes use of the CLT next.\n\\begin{example}[Errors in computer code (Wasserman03, p.~78)]\\label{EX:CLTPoisson}\nSuppose the collection of RVs $X_1,X_2, \\ldots, X_n$ model the number of errors in $n$ computer programs named $1,2,\\ldots,n$, respectively.  Suppose that the RV $X_i$ modeling the number of errors in the $i$-th program is the $Poisson(\\lambda=5)$ for any $i=1,2,\\ldots,n$.  Further suppose that they are independently distributed.  Succinctly, we suppose that \n\\[\nX_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\poisson(\\lambda=5) \\ . \n\\]\nSuppose we have $n=125$ programs and want to make a probability statement about $\\overline{X}_n$ which is the average error per program out of these $125$ programs.  Since $\\E(X_i) = \\lambda=5$ and $\\V(X_i)=\\lambda=5$, we may want to know how often our sample mean $\\overline{X}_{125}$ differs from the expectation of $5$ errors per program.  Using the CLT we can approximate $\\P(\\overline{X}_n < 5.5)$, for instance, as follows:\n\\begin{eqnarray}\n\\P(\\overline{X}_n < 5.5) \n&=& P \\left( \\frac{\\sqrt{n}(\\overline{X}_n - \\E(X_1))}{\\sqrt{\\V(X_1)}} < \\frac{\\sqrt{n}(5.5-\\E(X_1))}{\\sqrt{\\V(X_1)}} \\right) \\notag \\\\\n&\\approxeq& P \\left( Z < \\frac{\\sqrt{n}(5.5-\\lambda)}{\\sqrt{\\lambda}} \\right) \\qquad \\text{{\\scriptsize [by \\eqref{E:CLTApprox}, and $\\E(X_1)=\\V(X_1)=\\lambda$]}} \\notag \\\\\n&=& P \\left( Z < \\frac{\\sqrt{125}(5.5-5)}{\\sqrt{5}} \\right) \\qquad \\text{{\\scriptsize [Since, $\\lambda=5$ and $n=125$ in this Example]}} \\notag \\\\\n&=& \\P(Z \\leq 2.5) = \\Phi(2.5) =  \\int_{- \\infty}^{2.5} \\left( \\frac{1}{\\sqrt{2 \\pi}} \\ \\exp \\left( \\frac{-x^2}{2} \\right) \\right) dx \\approxeq 0.993790334674224 \\ . \\notag\n\\end{eqnarray}\nThe last number above needed the following:\n\\begin{labwork}[Numerical approximation of $\\Phi(2.5)$]\nThe numerical approximation of $\\Phi(2.5)$ was obtained via the following call to our $\\erf$-based {\\tt NormalCdf} function. % from \\ref*{Mf: NormalCdfPdf}. MATLABback\n\\begin{VrbM}\n>> format long\n>> disp(NormalCdf(2.5,0,1))\n   0.993790334674224\n\\end{VrbM}\n\\end{labwork}\n\\end{example}\nThe CLT says that if $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$, then $Z_n := \\sqrt{n}(\\overline{X}_n-\\E(X_1))/\\sqrt{\\V(X_1)}$ is approximately distributed as $\\normal(0,1)$.  In \\hyperref[EX:CLTPoisson]{Example \\ref*{EX:CLTPoisson}}, we knew $\\sqrt{\\V(X_1)}$.   However, in general, we may not know $\\sqrt{\\V(X_1)}$.  The next proposition says that we may estimate $\\sqrt{\\V(X_1)}$ using the sample standard deviation $S_n$ of $X_1,X_2,\\ldots,X_n$, according to \\eqref{E:SampleStdDevRV}, and still make probability statements about the sample mean $\\overline{X}_n$ using a Normal distribution.\n\\begin{prop}[CLT based on Sample Variance]\nLet $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ and suppose $\\E(X_1)$ and $\\V(X_1)$ exists, then\n\\begin{equation}\\label{E:CLTApproxSn}\n\\frac{\\sqrt{n} \\left( \\overline{X}_n - \\E(X_1) \\right)}{S_n} \\rightsquigarrow \\normal(0,1) \\ .\n\\end{equation}\n\\end{prop}\n\nWe will use \\eqref{E:CLTApproxSn} for statistical estimation in the sequel.\n}% end remove\n\n%The next proposition is often referred to as the fundamental theorem of statistics and is at the heart of non-parametric inference, empirical processes, and computationally-intensive bootstrap techniques.\n%\\begin{prop}[Gilvenko-Cantelli Theorem]\\label{P:Gilvenko-Cantelli}\n%Let $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 Gilvenko-Cantelli Theorem}:  As the sample size $n$ increases the empirical distribution function $\\widehat{F}_n$ converges to the true DF $F$ in probability.\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=7.0in]{figures/GilvenkoCantelliUnif01n10n100n100ECDFs}}\n%\\end{figure}\n\n%\\begin{prop}[The Dvoretzky-Kiefer-Wolfowitz (DKW) Inequality]\n%Let $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F$.  Then, for any $\\epsilon>0$,\n%\\begin{equation}\\label{E:DKWNeq}\n%P \\left( \\sup_x | \\widehat{F}_n(x) - F(x) | > \\epsilon  \\right) \\leq 2 \\exp {(-2 n \\epsilon^2)}\n%\\end{equation}\n%\\end{prop}\n\n\n\n\\begin{prop}[Central Limit Theorem (CLT)]\\label{P:CLT}\n\nIf we are given a sequence of independently and identically distributed (IID) RVs, $X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1$ and if $E(X) < \\infty$ and $V(X_1)<\\infty$, then the sample mean $\\overline{X}_n$ converges in \n%probability \ndistribution to the Normal RV with mean given by any one of the IID RVs, say $\\E(X_1)$ by convention, and variance given by $\\frac{1}{n}$ times the variance of any one of the IID RVs, say $V(X_1)$ by convention.  More formally, we write:\n\\begin{multline}\\label{E:CLT}\n\\text{If} \\quad X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1 \\ \\text{and if } \\ \\E(X_1)<\\infty, V(X_1) < \\infty \\\\ \\text{ then } \\ \\overline{X}_n \\rightsquigarrow \\normal\\left(E(X_1), \\frac{V(X_1)}{n}\\right) \\ \\text{ as } n\\to\\infty \\enspace ,\n\\end{multline}\nor equivalently after standardization:\n\\begin{multline}\\label{E:CLTStd}\n\\text{If} \\quad X_1,X_2,\\ldots \\overset{\\IID}{\\sim} X_1 \\ \\text{and if } \\ \\E(X_1)<\\infty, V(X_1) < \\infty \\\\ \\text{ then } \\ \\frac{\\overline{X}_n - E(X_1)}{\\sqrt{V(X_1)/n}} \\rightsquigarrow Z \\sim \\normal\\left(0,1 \\right) \\ \\text{ as } n\\to\\infty \\enspace .\n\\end{multline}\n\n{\\normalsize\n\\begin{proof}\n{\nOur proof is based on the convergence of characteristic functions (CFs).  \nWe will prove the standardized form of the CLT in Equation~\\eqref{E:CLTStd} by showing that the CF of\n\\[\nU_n := \\frac{\\ol{X}_n-E(X_1)}{\\sqrt{V(X_1)/n}}\n\\]\nconverges to the CF of $Z$, the $\\normal(0,1)$ RV.  \nFirst, note from Equation~\\eqref{E:cfStandardNormal} that the CF of $Z \\sim \\normal(0,1)$ is:\n\\[\n\\cf_Z(t) = E \\left( e^{\\imath t Z}\\right) = e^{-t^2/2} \\enspace .\n\\]\nSecond, \n\\[\nU_n := \\frac{\\ol{X}_n-E(X_1)}{\\sqrt{V(X_1)/n}} \n= \\frac{\\sum_{k=1}^n X_k - n E(X_1)}{\\sqrt{nV(X_1)}}\n= \\frac{1}{\\sqrt{n}} \\sum_{k=1}^n \\left(\\frac{X_k - E(X_1)}{\\sqrt{V(X_1)}}\\right)\\enspace .\n\\]\nTherefore, the CF of $U_n$ is\n\\begin{align*}\n\\cf_{U_n}(t) \n&= E\\left( \\exp\\left({\\imath t U_n}\\right)\\right)\n= E \\left( \\exp\\left({\\imath \\frac{t}{\\sqrt{n}}\\sum_{k=1}^n \\frac{X_k - E(X_1)}{\\sqrt{V(X_1)}} }\\right)\\right)\n= \\prod_{k=1}^n E \\left( \\exp \\left( \\imath \\frac{t}{\\sqrt{n}} \\frac{X_k - E(X_1)}{\\sqrt{V(X_1)}} \\right) \\right)\\\\\n&= \\left( E \\left( \\exp \\left( \\imath \\frac{t}{\\sqrt{n}} \\frac{X_1 - E(X_1)}{\\sqrt{V(X_1)}} \\right) \\right)\\right)^n \\enspace .\n\\end{align*}\nNow, if we let\n\\[\nY = \\frac{X_1 - E(X_1)}{\\sqrt{V(X_1)}}\n\\]\nthen \n\\[\nE(Y) = 0 \\, , \\quad E(Y^2)=1 \\, , \\text{and} \\quad V(Y)=1 \\enspace . \n\\]\nSo, the CF of $U_n$ is\n\\[\n\\cf_{U_n}(t) = \\left( \\cf_Y\\left(\\frac{t}{\\sqrt{n}}\\right)\\right)^n \\enspace ,\n\\]\nand since we can Taylor expand $\\cf_Y(t)$ as follows: \n\\[\n\\cf_Y(t) = 1 + \\imath t E(Y) + \\imath^2 \\frac{t^2}{2} E(Y^2) + o(t^2) \\enspace,\n\\]\nwhich implies\n\\[\n\\cf_Y\\left(\\frac{t}{\\sqrt{n}}\\right) = 1 + \\frac{\\imath t}{\\sqrt{n}} E(Y) + \\frac{\\imath^2 t^2}{2n}  E(Y^2) + o\\left(\\frac{t^2}{n}\\right) \\enspace,\n\\]\nwe finally get\n\\[\n\\cf_{U_n}(t) \n= \\left( \\cf_Y \\left(\\frac{t}{\\sqrt{n}}\\right) \\right)^n\n= \\left( 1 +  \\frac{\\imath t}{\\sqrt{n}} \\times 0 + \\frac{\\imath^2 t^2}{2n}  \\times 1 + o\\left(\\frac{t^2}{n}\\right) \\right)^n\n= \\left( 1 - \\frac{t^2}{2n} + o\\left(\\frac{t^2}{n}\\right) \\right)^n\n\\to e^{-t^2/2} = \\cf_Z(t) \\enspace .\n\\]\nFor the last limit we have used $\\left( 1+\\frac{x}{n}\\right)^n \\to e^x$ as $n \\to \\infty$.  \nThus, we have proved Equation~\\eqref{E:CLTStd} which is equivalent to Equation~\\eqref{E:CLT} by a standardization argument that if $W \\sim \\normal(\\mu,\\sigma^2)$ then $Z=\\frac{W-\\mu}{\\sigma} \\sim \\normal(0,1)$ through the linear transformation $W=\\sigma Z + \\mu$ of Example~\\ref{Eg:LinearTransfStdGaussianGaussian}.\n}\n\\end{proof}\n}\n\\end{prop}\n\n\n\\subsection{Application: Tolerating Errors in our estimate of $E(X_1)$}\nRecall that we wanted to ensure the $\\mathsf{error}=|\\ol{X}_n - E(X_1)|$ in our estimate of $E(X_1)$ is within a required $\\mathsf{tolerance}=\\epsilon$ and make the following probability statement: \n\\[\nP( \\mathsf{error} < \\mathsf{tolerance}) = P( |\\ol{X}_n - E(X_1)| < \\epsilon ) = P(-\\epsilon < \\ol{X}_n - E(X_1) < \\epsilon) = 1-\\alpha \\enspace .\n\\]\nTo be able to do this we needed to know the full distribution of $\\ol{X}_n - E(X_1)$ itself.  \n\nDue to the Central Limit Theorem (CLT) we now know that (assuming $n$ is large)\n\\begin{align*}\nP(-\\epsilon < \\ol{X}_n - E(X_1) < \\epsilon) \n&\\approxeq P\\left(-\\frac{\\epsilon}{\\sqrt{V(X_1)/n}} < \\frac{\\ol{X}_n - E(X_1)}{\\sqrt{V(X_1)/n}} < \\frac{\\epsilon}{\\sqrt{V(X_1)/n}}\\right)\\\\\n&= P\\left(-\\frac{\\epsilon}{\\sqrt{V(X_1)/n}} < Z < \\frac{\\epsilon}{\\sqrt{V(X_1)/n}} \\right) \\enspace ,\n\\end{align*}\nwhere $Z \\sim \\normal(0,1)$.\n\n\\begin{example}\\label{EgProbOfErrorInMeanEstimateFromKnownVar}\nSuppose an IID sequence of observations $(x_1,x_2,\\ldots,x_{80})$ was drawn from a distribution with variance $V(X_1)=4$.  \nWhat is the probability that the error in $\\ol{x}_n$ used to estimate $E(X_1)$ is less than $0.1$?\n\nBy CLT,\n\\[\nP (\\mathsf{error} < 0.1) \\approxeq P \\left( -\\frac{0.1}{\\sqrt{4/80}} < Z < \\frac{0.1}{\\sqrt{4/80}} \\right) \n= P(-0.447 < Z < 0.447)= 0.345 \\enspace .\n\\] \n\\end{example}\n\nSuppose you want the $\\mathsf{error}$ to be less than $\\mathsf{tolerance}=\\epsilon$ with a certain probability $1-\\alpha$.  \nThen we can use CLT to do such {\\bf sample size calculations}.\nRecall the DF $\\Phi(z) = P(Z < z)$ is tabulated in the standard normal table and now we want\n\\[\nP \\left(-\\frac{\\epsilon}{\\sqrt{V(X_1)/n}} < Z < \\frac{\\epsilon}{\\sqrt{V(X_1)/n}} \\right) = 1 -\\alpha \\enspace .\n\\]\nWe know,\n\\[\nP \\left(-z_{\\alpha/2} < Z < z_{\\alpha/2} \\right) = 1 -\\alpha \\enspace ,\n\\]\n\n\\vspace{1.5cm}\n\n{\\tiny make the picture here of $f_Z(z) = \\Phi'(z)$ to recall what $z_{\\alpha/2}$, $z_{-\\alpha/2}$, and the various areas below $f_Z(\\cdot)$ in terms of $\\Phi(\\cdot)$ from the table really mean... (See Example~\\ref{Eg:UsingNormalTables}).}\n\n\\vspace{1.5cm}\n\nwhere, $\\Phi(z_{\\alpha/2}) = 1-\\alpha/2$ and $\\Phi(z_{-\\alpha/2}) = 1- \\Phi(z_{\\alpha/2}) = \\alpha/2$.  \nSo, we set\n\\[\n\\frac{\\epsilon}{\\sqrt{V(X_1)/n}} = z_{\\alpha/2}\n\\]\nand rearrange to get\n\\begin{equation}\\label{E:SampleSizeCalcForPopMean}\nn = \\left( \\frac{\\sqrt{V(X_1)} z_{\\alpha/2}}{\\epsilon}\\right)^2\n\\end{equation}\nfor the needed sample size that will ensure that our $\\mathsf{error}$ is less than our $\\mathsf{tolerance}=\\epsilon$ with probability $1-\\alpha$.  Of course, if $n$ given by Equation~\\eqref{E:SampleSizeCalcForPopMean} is not a natural number then we naturally round up to make it one!\n\nA useful $z_{\\alpha/2}$ value to remember: If $\\alpha=0.05$ when the probability of interest $1-\\alpha=0.95$ then $z_{\\alpha/2} = z_{0.025} = 1.96$.\n\n\\begin{example}\\label{EgHowLargeASampleSizeToEstimateMeanWithinTOL}\nHow large a sample size is needed to make the $\\mathsf{error}$ in our estimate of the population mean $E(X_1)$ to be less than $0.1$ with probability $1-\\alpha=0.95$ if we are observing IID samples from a distribution with a population variance $V(X_1)$ of $4$?\n\nUsing Equation~\\eqref{E:SampleSizeCalcForPopMean} we see that the needed sample size is\n\\[\nn =  \\left( \\frac{\\sqrt{4} \\times 1.96}{0.1} \\right)^2 \\approxeq 1537\n\\]\nThus, it pays to check the sample size needed in advance of experimentation, provided you already know the population variance of the distribution whose population mean you are interested in estimating within a given $\\mathsf{tolerance}$ and with a high probability. \n\\end{example}\n\n\\subsection{Application: Set Estimation of $E(X_1)$}\n\nA useful byproduct of the CLT is the $\\mathbf{(1-\\alpha)}$ {\\bf confidence interval}, a random interval (or bivariate \\rv) that contains $E(X_1)$, the quantity of interest, with probability $1-\\alpha$: \n\\begin{equation}\\label{E:ConfIntForPopMean}\n\\left( \\ol{X}_n \\pm z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right) :=\n\\left( \\ol{X}_n - z_{\\alpha/2} \\sqrt{V(X_1)/n} \\, , \\, \\ol{X}_n + z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right) \\enspace .\n\\end{equation}\n\n{\\scriptsize\nWe can easily see how Equation~\\eqref{E:ConfIntForPopMean} is derived from CLT as follows:\n\\begin{align*}\nP \\left( -z_{\\alpha/2} < Z < z_{\\alpha/2} \\right) \n&= 1-\\alpha \\\\\nP \\left( -z_{\\alpha/2} < \\frac{\\ol{X}_n-E(X_1)}{\\sqrt{V(X_1)/n}} < z_{\\alpha/2} \\right) \n&= 1-\\alpha \\\\\nP \\left( -\\ol{X}_n - z_{\\alpha/2}\\sqrt{V(X_1)/n}  < -E(X_1) < -\\ol{X}_n + z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right) \n&= 1-\\alpha \\\\\nP \\left( \\ol{X}_n + z_{\\alpha/2}\\sqrt{V(X_1)/n}  > E(X_1) > \\ol{X}_n - z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right) \n&= 1-\\alpha \\\\\nP \\left( \\ol{X}_n - z_{\\alpha/2}\\sqrt{V(X_1)/n}  < E(X_1) < \\ol{X}_n + z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right) \n&= 1-\\alpha \\\\\nP \\left( E(X_1) \\in \\left(\\ol{X}_n - z_{\\alpha/2}\\sqrt{V(X_1)/n} , \\ol{X}_n + z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right) \\right) \n&= 1-\\alpha \\enspace .\n\\end{align*}\n}\n\n\\begin{rem}[Heuristic interpretation of the $(1-\\alpha)$ confidence interval]  \nIf we repeatedly produced samples of size $n$ to contain $E(X_1)$ within a $\\left( \\ol{X}_n \\pm z_{\\alpha/2} \\sqrt{V(X_1)/n} \\right)$, say $100$ times, then on average, $(1-\\alpha) \\times 100$ repetitions will actually contain $E(X_1)$ within the random interval and $\\alpha \\times 100$ repetitions will fail to contain $E(X_1)$.\n\\end{rem}\n\nSo far, we have assumed we know the population variance $V(X_1)$ in an IID experiment with $n$ samples and tried to estimate the population mean $E(X_1)$.  \nBut in general, we will not know $V(X_1)$.  We can still get a point estimate of $E(X_1)$ from the sample mean due to LLN but we won't be able to get a confidence interval for $E(X_1)$.  \nFortunately, a more elaborate form of the CLT tells us that even when we substitute the sample variance $S_n^2 = \\frac{1}{n-1}\\sum_{i=1}^n (X_i-\\ol{X}_n)^2$ for the population variance $V(X_1)$ the following $1-\\alpha$ confidence interval for $E(X_1)$ works!\n\\begin{equation}\\label{E:ConfIntForPopMeanUsingSampleVariance}\n\\left( \\ol{X}_n \\pm z_{\\alpha/2} S_n/\\sqrt{n} \\right) :=\n\\left( \\ol{X}_n - z_{\\alpha/2} S_n/\\sqrt{n} \\, , \\, \\ol{X}_n + z_{\\alpha/2} S_n/\\sqrt{n} \\right) \\enspace ,\n\\end{equation}\nwhere, $S_n=\\sqrt{S_n^2}$ is the sample standard deviation.\n\nLet's return to our two examples again.\n\n\\begin{example}\\label{EgExponentialCIOfMeanWaitingTimesWithSampleMeanAndVar}\nWe model the waiting times between Orbiter buses with unknown $E(X_1)=1/\\lambda^*$ as\n\\[\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\exponential(\\lambda^*)\n\\]\nand observed the following data, sample mean, sample variance and sample standard deviation:\n\\[\n(x_1,x_2,\\ldots,x_7) = (2,12,8,9,14,15,11), \\, \\ol{x}_7=10.143, \\,  s^2_7 = 19.143, \\, s_7 = 4.375 \\enspace ,\n\\] \nrespectively.  \nOur point estimate and $1-\\alpha=95\\%$ confidence interval for $E(X_1)$ are:\n\\[\n\\ol{x}_7 = 10.143 \\quad \\text{ and } \\quad (\\ol{x}_7 \\pm z_{\\alpha/2} s_7/\\sqrt{7}) = (10.143 \\pm 1.96 \\times 4.375/\\sqrt{7}) = (6.9016,13.3841) \\enspace ,\n\\]\nrespectively.  So with $95\\%$ probability the true population mean $E(X_1)=1/\\lambda^*$ is contained in $(6.9016,13.3841)$ and since the mean waiting time of $10$ minutes promised by the Orbiter bus company is also within $(6.9016,13.3841)$ we can be fairly certain that the company sticks to its promise.\n\\end{example}\n\n\\begin{example}\\label{EgBernoulliCIWithSampleMeanAndVar}\nWe model the tosses of a coin with unknown $E(X_1)=\\theta^*$ as\n\\[\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\bernoulli(\\theta^*)\n\\]\nand observed the following data, sample mean, sample variance and sample standard deviation:\n\\[\n(x_1,x_2,\\ldots,x_7) = (0,1,1,0,0,1,0), \\, \\ol{x}_7=0.4286, \\,  s^2_7 = 0.2857, \\, s_7 = 0.5345 \\enspace ,\n\\] \nrespectively.  \nOur point estimate and $1-\\alpha=95\\%$ confidence interval for $E(X_1)$ are:\n\\[\n\\ol{x}_7 = 0.4286 \\quad \\text{ and } \\quad (\\ol{x}_7 \\pm z_{\\alpha/2} s_7/\\sqrt{7}) = (0.4286 \\pm 1.96 \\times 0.5345/\\sqrt{7}) = (0.0326,0.8246) \\enspace ,\n\\]\nrespectively.  So with $95\\%$ probability the true population mean $E(X_1)=\\theta^*$ is contained in $(0.0326,0.8246)$ and since $1/2$ is contained in this interval of width $0.792$ we cannot rule out that the flipped coin is not fair with $\\theta^*=1/2$.\n\\end{example}\n\n\\begin{rem}\nThe normal-based confidence interval for $\\theta^*$ (as well as $\\lambda^*$ in the previous example) may not be a valid approximation here with just $n=7$ samples.  After all, the CLT only tells us that the point estimator $\\widehat{\\Theta}_n$ can be approximated by a normal distribution for large sample sizes. \nWhen the sample size $n$ was increased from $7$ to $100$ by tossing the same coin another $93$ times, a total of $57$ trials landed as Heads.  Thus the point estimate and confidence interval for $E(X_1)=\\theta^*$ based on the sample mean and sample standard deviations are:\n\\[\n\\widehat{\\theta}_{100} = \\frac{57}{100} = 0.57 \\qquad \\text{and} \\qquad\n (0.57 \\pm 1.96 \\times 0.4975/\\sqrt{100})\n =(0.4725, 0.6675) \\enspace .\n\\]\nThus our confidence interval shrank considerably from a width of $0.792$ to $0.195$ after an additional $93$ Bernoulli trials.  Thus, we can make the width of the confidence interval as small as we want by making the number of observations or sample size $n$ as large as we can.\n\\end{rem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\input{ExsInLimitsOfRVs.tex}\n", "meta": {"hexsha": "31b2f31576e1b6e15aee7a1570205e9ffa867a87", "size": 56983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/LimitsOfRVs.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/LimitsOfRVs.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/LimitsOfRVs.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": 67.1969339623, "max_line_length": 729, "alphanum_fraction": 0.6895740835, "num_tokens": 19942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.757794360334681, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.6514483405582839}}
{"text": "\n\\section{Carrier--Greenspan transient solution}\n\nA transient solution for flows on a sloping beach was proposed by Carrier and Greenspan~\\cite{CG1958}. The water moves to the shore at an early time, then it becomes still when time is large.\n\nConsider the dimensionless shallow water equations, as presented in the Carrier--Greenspan periodic solution.\n\nThe analytical solution is:\n\\begin{equation}\nw = - \\frac{u^2}{2} + \\epsilon {Re} \n\\left[1- 2 \\frac{5/4 - i\\lambda}{\\left\\{(1-i\\lambda)^2 + \\sigma^2 \\right\\}^{3/2}}\n+ \\frac32 \\frac{(1-i\\lambda)^2}{\\left\\{ (1-i\\lambda)^2 + \\sigma^2 \\right\\}^{5/2}} \\right],\n\\end{equation}\n\\begin{equation}\nu = \\frac{8\\epsilon}{a} {Im} \\left[ \\frac{1}{\\left\\{(1-i\\lambda)^2 + \\sigma^2 \\right\\}^{3/2}}\n- \\frac34 \\frac{1-i\\lambda}{\\left\\{ (1-i\\lambda)^2 + \\sigma^2 \\right\\}^{5/2}}    \\right],\n\\end{equation}\nwhere\n\\begin{equation}\nt = \\frac12 a\\lambda -u\\,, \\quad c = \\frac14 a\\sigma\\,,\n\\end{equation}\nin which $c=\\sqrt{gh}$ is the wave propagation speed.\nHere $\\sigma \\geq 0$ and we take $a=1.5(1+0.9\\epsilon)^{1/2}$. Carrier and Greenspan~\\cite{CG1958} observed that the waves do not break if $\\epsilon$ is very small, namely $\\epsilon \\leq 0.23$. Setting $\\sigma=0$ into this solution, we get the motion of the shoreline.\n\nThe initial condition is given by setting time $t=0$ in this analytical solution. Note that this analytical solution is defined in the dimensionless space. To implement this in the numerical test, we just need to scale it back to the dimensional space.\n\n\\subsection{Results}\n\nWe consider $\\epsilon=0.2$. The following three figures show the stage, $x$-momentum, and $y$-momentum at several instants in time. We should see excellent agreement between the analytical and numerical 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\\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\\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\\endinput\n", "meta": {"hexsha": "f70e776b3fc13dc8cab1906d88be86078c52dcaf", "size": 2170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "validation_tests/analytical_exact/carrier_greenspan_transient/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/carrier_greenspan_transient/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/carrier_greenspan_transient/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": 40.9433962264, "max_line_length": 268, "alphanum_fraction": 0.7248847926, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.6513920273160552}}
{"text": "\\lab{The Finite Element method}{The Finite Element method}\n\\label{lab:finite_element}\n\nRecall that the heat equation is given by\n\\begin{align*}\ny_t = \\epsilon y_{xx} + f(x) %\\label{FEM:diffusion}\n\\end{align*}\nwhere $f(x)$ represents any heat sources in the system, and $\\epsilon y_{xx}$ models the diffusion of heat.\nSuppose we wish to study the distribution of heat in a fluid that is moving at some constant speed $a$.\nWe can model this by adding an advection term to the heat equation, giving us\n\\begin{align*}\ny_t + ay_x = \\epsilon y_{xx} + f(x).\n\\end{align*}\nThis fluid flows through a pipe from $x = 0$ to $x = 1$ at a speed $a = 1$, and as it travels it is warmed a constant rate $f= 1$.\nSuppose also that $y = 2$ at $x = 0$, so that the fluid is already at a constant temperature as it enters the pipe.\n\nAs time increases we expect the temperature of the fluid in the pipe to reach a steady state distribution; this heat distribution would then satisfy the ODE\n\\begin{align}\n\\begin{split}\n&{ } \\epsilon y'' - y' = -1,\\\\\n&{ } y(0) = 2.\n\\end{split}\\label{eqn:FEM_steady_state}\n\\end{align}\nAt the moment this problem is not fully defined, since the ODE is second order and there is only one boundary condition.\nSuppose a device is installed on the end of the pipe that nearly instantaneously brings the heat of the water up to $y = 4$.\nPhysically we expect this extra heat that is introduced at $x = 1$ to diffuse backward through the water in the pipe.\n\nWe will use the finite element method to solve this boundary value problem numerically.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{FEM_solution.pdf}\n\\caption{The analytic solution of \\eqref{eqn:FEM_steady_state} when $\\epsilon = .1$, with the additional condition that $y(1) = 4$.}\n\\label{fig:FEM_analytic_solution}\n\\end{figure}\n\n\\section*{The Weak Formulation}\nConsider the equation\n\\begin{align}\n\t\\begin{split}\n\t&{ }\\epsilon y'' - y' = -1,\\\\\n\t&{ }y(0) = \\alpha, \\quad y(1) = \\beta .\n\t\\end{split}\\label{eqn:FEM_eqn1}\n\\end{align}\nTo find the solution $y$ using the finite element method, we reframe the problem and look at what is known as its weak formulation.\n\n%We may assume that the solution $y$ of \\eqref{eqn:FEM_eqn1} lies in some appropriate function space $V$.\n%; in any case, we can approximate it arbitrarily well in $C^0[0,1]$ by a piecewise linear function.\nLet $w$ be a smooth function on $[0,1]$ satisfying $w(0) = w(1) = 0$.\nMultiplying \\eqref{eqn:FEM_eqn1} by $w$ and integrating over $[0,1]$ yields\n\\begin{align*}\n\t\\int_0^1 f w &= \\int_0^1 \\epsilon y''w - y'w, \\\\\n\t&= \\int_0^1 -\\epsilon y'w' - y'w.\n\\end{align*}\nDefine a bilinear function $a$ and a linear function $l$ by\n\\begin{align*}\na(y,w) &= \\int_0^1 -\\epsilon y'w' - y'w,\\\\\nl(w) &= \\int_0^1 f w.\n\\end{align*}\nRather than trying to solve \\eqref{eqn:FEM_eqn1}, we instead consider the problem of finding a function $y$ such that\n\\begin{align}\n\ta(y,w) &= l(w), \\quad \\forall \\, w \\in V_0,\n\t\\label{eqn:FEM_integral_form}\n\\end{align}\nwhere $V$ is some appropriate vector space that is expected to allow us to approximate the solution $y$, and $V_0 = \\{w \\in V|w(0) = w(1) = 0\\}$.\n(For example, we could consider the space of functions that are piecewise linear with vertices at a fixed set of points.\nThis example is discussed further below.)\nThis equation is called the weak formulation of \\eqref{eqn:FEM_eqn1}.\n\nLet $\\mathrm{P}_n$ be some partition of $[0,1]$, $0 = x_0 < x_1< \\ldots < x_{n} = 1$, and let $V_n$ be the finite-dimensional vector space of continuous functions $v$ on $[0,1]$ where $v$ is linear on each subinterval $[{x_j,x_{j+1}}]$.\nThese subintervals are the finite elements for which this method is named.\n$V_n$ has dimension $n+1$, since there are $n+1$ degrees of freedom for continuous piecewise linear functions in $V$.\nLet $V_{n0}$ be the subspace of $V_n$ of dimension $n-1$ whose elements are zero at the endpoints of $[0,1]$, and let $\\triangle x_n = \\max_{0 \\leq j \\leq n-1}|x_{j+1} - x_j|$.\n\nLet $\\{\\mathrm{P}_n\\}$ be a sequence of partitions that are refinements of each other, such that $\\triangle x_n \\to 0$ as $n \\to \\infty$.\nThen in particular $V_1 \\subset V_2 \\subset \\ldots \\subset V_n \\ldots \\subset V$.\nFor each partition $\\mathrm{P}_n$ we can look for an approximation $y_n \\in V_n$ for the true solution $y$; if this is done  correctly then $y_n \\to y$ as $n \\to \\infty$.\n\n\\section*{The Numerical Method}\nConsider a partition $\\mathrm{P}_5 = \\{x_0, x_1, \\ldots, x_5\\}$.\nWe will define some basis functions $\\phi_i$, $i = 0, \\ldots, 5$ for the corresponding vector space $V_5$.\nLet the $\\phi_i$ be the hat functions \n\\[\\phi_i(x) = \\begin{cases}\n(x - x_{i-1})/h_i \\quad \\quad\\text{ if } x \\in [x_{i-1},x_i]\\\\\n (x_{i+1} - x)/h_{i+1} \\quad \\text{ if } x \\in [x_{i},x_{i+1}]\\\\\n0 \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\,\\,\\text{ otherwise}\n\\end{cases}\\]\nwhere $h_i = x_i - x_{i-1}$; see Figures \\ref{fig:FEM_one_basis_function} and \\ref{fig:FEM_basis_functions}. \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{one_basis_function.pdf}\n\\caption{The basis function $\\phi_3$.}\n\\label{fig:FEM_one_basis_function}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{basis_functions.pdf}\n\\caption{Basis functions for $V_5$.}\n\\label{fig:FEM_basis_functions}\n\\end{figure}\n\nWe look for an approximation $\\hat{y} = \\sum_{i=0}^5 k_i \\phi_i \\in V_5$ of the true solution $y$; to do this we must determine appropriate values for the constants $k_i$.\nWe impose the condition on $\\hat{y}$ that \n\\[a(\\hat{y},w) = l(w) \\quad \\forall \\, w \\in V_{50}.\\]\nEquivalently, we require that \n\\[a \\left( \\sum_{i=0}^5 k_i \\phi_i,\\phi_j \\right) = l(\\phi_j) \\quad \\text{for } j = 1,2,3,4,\\]\nsince $\\phi_1, \\phi_2, \\phi_3, \\phi_4$ form a basis for $V_{50}$.\n\nSince $a$ is bilinear, we obtain \n\\[\\sum_{i=0}^5 k_i  a ( \\phi_i,\\phi_j ) = l(\\phi_j) \\quad \\text{for } j = 1,2,3,4.\\]\nTo satisfy the boundary conditions, we also require that $k_0 = \\alpha$, $k_5 = \\beta$.\nThese equations can be written in matrix form as\n\\begin{align} AK = \\Phi,\\label{eqn:FEM_linear_system}\\end{align}\nwhere\n\\[A = \\left[\\begin{array}{cccccc}1 & 0 & 0 & 0 & 0 & 0 \\\\a(\\phi_0,\\phi_1) & a(\\phi_1,\\phi_1) & a(\\phi_2,\\phi_1) & 0 & 0 & 0 \\\\0 & a(\\phi_1,\\phi_2) & a(\\phi_2,\\phi_2) & a(\\phi_3,\\phi_2) & 0 & 0 \\\\0 & 0 & a(\\phi_2,\\phi_3) & a(\\phi_3,\\phi_3) & a(\\phi_4,\\phi_3) & 0 \\\\0 & 0 & 0 & a(\\phi_3,\\phi_4) & a(\\phi_4,\\phi_4) & a(\\phi_5,\\phi_4) \\\\0 & 0 & 0 & 0 & 0 &1\\end{array}\\right]\\]\nand\n\\[K = \\left[\\begin{array}{c}k_0 \\\\k_1 \\\\k_2 \\\\k_3 \\\\k_4 \\\\k_5\\end{array}\\right] , \\quad\\Phi =  \\left[\\begin{array}{c}\\alpha \\\\l(\\phi_1) \\\\l(\\phi_2) \\\\l(\\phi_3) \\\\l(\\phi_4) \\\\\\beta\\end{array}\\right].\\]\n\nNote that $a(\\phi_i,\\phi_j) = 0$ for most values of $i, j$ (that is, when the hat functions do not have overlapping domains).\nThus the finite element method results in a sparse linear system.\nTo compute the coefficients of \\eqref{eqn:FEM_linear_system} we begin by evaluating some integrals.\nSince\n\\[\\phi_i'(x) = \\begin{cases}\n1/h_i \\quad \\quad \\quad \\, \\text{for } x_{i-1} < x < x_i,\\\\\n -1/h_{i+1} \\quad \\text{ for } x_{i} < x < x_{i+1},\\\\\n0 \\quad \\quad \\quad \\quad \\, \\text{ otherwise},\n\\end{cases}\\]\nwe obtain\n\\begin{align*}\n\\int_0^1  \\phi_i'\\phi_j' &= \\begin{cases}\n- 1/h_{i+1} \\quad \\quad \\quad \\text{ if } j=i+1,\\\\\n1/h_i + 1/h_{i+1} \\quad \\text{if } j=i,\\\\\n0 \\quad \\quad \\quad \\quad \\quad \\quad \\, \\text{ otherwise},\n\\end{cases} \\\\\n\\int_0^1  \\phi_i'\\phi_j &= \\begin{cases}\n- 1/2 \\quad \\,\\text{ if } j=i+1,\\\\\n1/2 \\quad \\quad \\text{ if } j=i-1,\\\\\n0 \\quad \\quad \\quad \\text{ otherwise},\n\\end{cases} \\\\\na(\\phi_i,\\phi_j) &= \\begin{cases}\n\\epsilon/h_{i+1} + 1/2 \\quad \\quad \\, \\text{ if } j=i+1,\\\\\n-\\epsilon/h_i -\\epsilon/h_{i+1} \\quad  \\text{ if } j=i,\\\\\n\\epsilon/h_i - 1/2 \\quad \\quad \\quad \\, \\text{ if } j=i-1,\\\\\n0 \\quad \\quad \\quad \\quad \\quad \\quad \\,\\,\\,\\,\\,\\,\\, \\text{ otherwise},\n\\end{cases}\\\\\nl(\\phi_j) &= -(1/2)(h_j + h_{j+1}).\n\\end{align*}\n\\eqref{eqn:FEM_linear_system} may now be solved using any standard linear solver.\n\nIn this case, in order to handle the large number of elements required for Problem \\ref{prob:FEM_accuracy_comparison}, you will want to use the tridiagonal algorithm provided in several of the earlier labs (for example Lab \\ref{lab:finitedifference1}), or the banded matrix solver included in \\li{scipy.linalg}.\n\n\\begin{problem}\nUse the finite element method to solve\n\\begin{align}\n\t\\begin{split}\n\t&{ }\\epsilon y'' - y' = -1,\\\\\n\t&{ }y(0) = \\alpha, \\quad y(1) = \\beta,\n\t\\end{split} \\label{eqn:FEM_exercise}\n\\end{align}\nwhere $\\alpha = 2, \\beta = 4$, and $\\epsilon = 0.02$.\nUse $N = 100$ finite elements ($101$ grid points).\nCompare your solution with the analytic solution\n\\[y(x) = \\alpha + x + (\\beta - \\alpha - 1 ) \\frac{e^{x/\\epsilon} -1}{e^{1/\\epsilon} -1}.\\]\n\n\\eqref{eqn:FEM_exercise} is a singularly perturbed ODE, so-named because the parameter $\\epsilon$ is a coefficient of the highest order derivative in the equation.\nThe character of the problem changes dramatically when $\\epsilon = 0$: since the limit equation (as $\\epsilon \\to 0$) is first-order, it only allows for one boundary condition.\nThus as $\\epsilon$ gets smaller, the rightmost boundary condition is satisfied at the `last moment',  and cannot be satisfied when $\\epsilon = 0$.\n\\end{problem}\n\n\\begin{problem}\nOne of the strengths of the finite element method is the ability to generate grids that better suit the problem.\nIn two dimensions the finite elements are quadrilaterals and triangles, and can be used to approximate irregular domains.\nThe finite element method can also be used to solve PDEs where the shape and size of the domain changes over time.\n\nThe solution of \\eqref{eqn:FEM_exercise} changes most rapidly near $x = 1$.\nCompare the numerical solution when the grid points are unevenly spaced versus when the grid points are clustered in the area of greatest change. Specifically, use the grid points defined by\n\\begin{lstlisting}\neven_grid = np.linspace(0,1,6)\nclustered_grid = np.linspace(0,1,6)**(1./8)\n\\end{lstlisting}\nWhat is the difference in accuracy?\n\\end{problem}\n\n% \\begin{figure}[ht]\n% \\centering\n% \\includegraphics[width=\\textwidth]{FEM_singular_solution.pdf}\n% \\caption{The analytic solution of \\eqref{FEM:exercise}.}\n% \\label{FEM:analytic_solution}\n% \\end{figure}\n\n\\begin{problem}\n\\label{prob:FEM_accuracy_comparison}\nHigher order methods promise faster convergence, but typically require more work to code.\nSo why do we use them when a low order method will converge just as well, albeit with more grid points?\nThe answer concerns the roundoff error associated with floating point arithmetic.\nLow order methods generally require more floating point operations, so roundoff error has a much greater effect.\n\nThe finite element method introduced here is a second order method, even though the approximate solution is piecewise linear.\n(To see this, note that if the grid points are evenly spaced, the matrix $A$ in \\eqref{eqn:FEM_linear_system} is exactly the same as the matrix for the second order centered finite difference method.)\n\nSolve \\eqref{eqn:FEM_exercise} with the finite element method using $N = 2^i$  finite elements, $i = 4, 5, \\ldots, 21$.\nUse a log-log plot to graph the error.\nThen find the error when using the pseudospectral method and the same number of grid points.\nWhat do you see?\n\\end{problem}\n\n% \\begin{align}\n% \\left[\\begin{array}{cccccc}1 & 0 & 0 & 0 & 0 & 0 \\\\-\\epsilon/h_1 & \\epsilon/h_1 + \\epsilon/h_2 & -\\epsilon/h_2 & 0 & 0 & 0 \\\\0 & -1/h_2 & a(\\phi_2,\\phi_2) & a(\\phi_3,\\phi_2) & 0 & 0 \\\\0 & 0 & a(\\phi_2,\\phi_3) & a(\\phi_3,\\phi_3) & a(\\phi_4,\\phi_3) & 0 \\\\0 & 0 & 0 & a(\\phi_3,\\phi_4) & a(\\phi_4,\\phi_4) & a(\\phi_5,\\phi_4) \\\\0 & 0 & 0 & 0 & 0 &1\\end{array}\\right]\n% \\left[\\begin{array}{c}k_0 \\\\k_1 \\\\k_2 \\\\k_3 \\\\k_4 \\\\k_5\\end{array}\\right] = \\left[\\begin{array}{c}\\alpha \\\\l(\\phi_1) \\\\l(\\phi_2) \\\\l(\\phi_3) \\\\l(\\phi_4) \\\\\\beta\\end{array}\\right] \\label{FE:linear_system}\n% \\end{align}\n\n\\section*{A Comparison of Numerical Methods}\n\n\\begin{table}\n  \\begin{tabular}{ l |l l }\n    % \\hline\n     & Finite Element & Finite Difference  \\\\ \\hline\n    Linear System& sparse& sparse  \\\\\n   Derivative & approximated locally & approximated locally \\\\\nDomain & irregular domains & fairly regular\\\\\n% Problem Formulation & integral & derivative & derivative & integral \\\\\nConvergence & polynomial & polynomial \\\\\nStrengths & adaptive mesh & easier to understand \\\\\n& refinement & and implement \\\\\n& complex geometries & easier for higher dimensions \\\\\n    \\hline\n  \\end{tabular}\n\\end{table}\n\n\\begin{table}\n  \\begin{tabular}{ l |l l }\n    % \\hline\n      & Pseudospectral & Finite Volume \\\\ \\hline\n    Linear System & dense & sparse \\\\\n   Derivative & global & local\\\\\nDomain  & very nice & fairly regular\\\\\nConvergence  & exponential & polynomial\\\\\nStrengths  & fast convergence & handling discontinuities in \\\\\n& accurate to high precisions &the initial conditions \\\\\n& & dealing with shock formation \\\\\n& & and propagation \\\\\n    \\hline\n  \\end{tabular}\n\\end{table}\n\nIt is important to note that these methods are often mixed, so, for example, it is common to work with a finite element mesh in space and a finite differencing scheme in time.", "meta": {"hexsha": "e95209c7469e92a80bd6fa849e63df2c764e3283", "size": 13173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FiniteElement/FiniteElement.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/FiniteElement/FiniteElement.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/FiniteElement/FiniteElement.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 53.1169354839, "max_line_length": 373, "alphanum_fraction": 0.6948303348, "num_tokens": 4350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6513920190822742}}
{"text": "\n\\documentclass[11pt]{article}\n\n%% WRY has commented out some unused packages %%\n%% If needed, activate these by uncommenting\n\\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.\n%\\geometry{letterpaper}                   % ... or a4paper or a5paper or ... \n\\geometry{a4paper,left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}\n%\\geometry{landscape}                % Activate for rotated page geometry\n%\\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent\n\n%for figures\n%\\usepackage{graphicx}\n\n\\usepackage{color}\n\\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue\n\\definecolor{mylilas}{RGB}{170,55,241}\n%% for graphics this one is also OK:\n\\usepackage{epsfig}\n\n%% AMS mathsymbols are enabled with\n\\usepackage{amssymb,amsmath}\n\n%% more options in enumerate\n\\usepackage{enumerate}\n\\usepackage{enumitem}\n\n%% insert code\n\\usepackage{listings}\n\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{hyperref}\n\n%% colors\n\\usepackage{graphicx,xcolor,lipsum}\n\n\n\\usepackage{mathtools}\n\n\\usepackage{graphicx}\n\\newcommand*{\\matminus}{%\n  \\leavevmode\n  \\hphantom{0}%\n  \\llap{%\n    \\settowidth{\\dimen0 }{$0$}%\n    \\resizebox{1.1\\dimen0 }{\\height}{$-$}%\n  }%\n}\n\n\\title{Notes on spectral estimation, etc.}\n\\author{\nCR \\thanks{Scripps Institution of Oceanography,\nUniversity of California at San Diego, La Jolla, CA\n92093--0230, USA. email:crocha@ucsd.edu. }\n}\n\\date{\\today}\n\n\\begin{document}\n\n\\include{mysymbols}\n\n\\maketitle\n\n\\section{Introduction}\n\nThe Fast Fourier transform (FFT) algorithm implemented in Python defines the one-dimensional discrete Fourier transform (DFT) as\n\n\\beq\n    \\label{eq:dft_dfn}\n    \\hat{A}[m] =  \\sum_{n=0}^{\\nmax-1}\n    A[n]\\exp \\left(-2\\pi i {n \\,m\\over \\nmax}\\right)\\com\n   \\qquad m = 0, \\ldots, \\nmax-1\\com\n\\eeq\nwhere $A_n$ is a list of size $N$ that contains the data in physical domain with uniform spacing\n\\beq\n\\label{eq:x_spacing}\ndx = {L \\over \\nmax}\\com\\qqand x_n = n \\dd x\\com\n\\eeq\nwhere $L$ the length of the domain. Notice that because of the periodicity of the complex exponentials, $\\hat{A}_k$ is also periodic with period $\\nmax$. That is $\\hat{A}[\\nmax] = \\hat{A}[0]$, $\\hat{A}[\\nmax+1] = \\hat{A}[1]$, etc. If $A_n$ is real-valued, then $\\hat{A}_k$ is Hermitian-symmetric about $\\nmax/2$. That is, $\\hat{A}[1] = \\hat{A}^\\star[\\nmax-1]$, $\\hat{A}[2] = \\hat{A}^\\star[\\nmax-2]$, etc, where the superscript $\\star$ denote complex conjugation. We can therefore shift the summation in \\eqref{eq:dft_dfn} by any integer. A popular choice is to sum from $-\\nmax/2$ through $\\nmax/2-1$. The zeroth coefficient $\\hat{A}[0]$ is a special case. Before we discuss it, let's introduce a slightly better notation. With the spectral resolution $dk$, we can define the wavenumber in \\eqref{eq:dft_dfn}\n\\beq\n\\label{eq:sepc_resol}\nk_m \\defn m \\dd k\\com\\qqand \\dd k =\\frac{1}{L} = \\frac{1}{N \\dd x}\\per\n\\eeq\nHence we can rewrite  the DFT in \\eqref{eq:dft_dfn} as\n\\beq\n\\label{eq:dft_dfn_2}\n    \\hat{A}[m] =  \\sum_{n=0}^{\\nmax-1}\n    A[n]\\ee^{-2\\pi i k_m\\, x}\\com\n   \\qquad m = 0, \\ldots, N-1\\per\n\\eeq\nWith $m=0$ we have the zeroth Fourier coefficient\n\\beq\n\\label{eq:zeroth_fc}\n\\hat{A}[0] = \\sum_{n=0}^{N-1} A[n]\\per\n\\eeq\nIt is convenient to normalize the Fourier coefficients in \\eqref{eq:dft_dfn} by  $\\nmax$  so that zeroth Fourier coefficient represents the arithmetic  average of the elements of $A$. This normalization also makes the DFT defined in \\eqref{eq:dft_dfn}  analogous to the continuous Fourier transform (FT) if we recognize the summation in \\eqref{eq:dft_dfn}  times $dx$ as Riemann integral. Some people like \\textit{obtain} DFT as a discretization of the FT. This is sometime advantageous, particularly when we are comparing data against theoretical predictions. I personally do not like that approach. I prefer to \\textit{define} the DFT as \\eqref{eq:dft_dfn} and show that it has analog properties to the FT; all proofs are self-consistent using discrete mathematics.\n\nThis is only a matter of normalization. Mathematically, what really matters is to define the inverse transform accordingly. The inverse DFT (iDFT) consistent with \\eqref{eq:dft_dfn} is\n\\beq\n    \\label{eq:idft_dfn}\n    A[n] =  \\frac{1}{\\nmax}\\sum_{m=0}^{\\nmax-1}\n    \\hat{A}[m]\\exp \\left(2\\pi i {m n\\over \\nmax}\\right)\\com\n   \\qquad n = 0, \\ldots, \\nmax-1\\per\n\\eeq\nThis is the iDFT implemented in Python. If we normalize \\eqref{eq:dft_dfn} by $\\nmax$, then we must multiply \\eqref{eq:idft_dfn} by $\\nmax$. Notice that $\\hat{A}$  has the same units of $A$.\n\n\\section{The spectrum}\nThe Fourier coefficients $\\hat{A}$ are complex-valued. Typically we are more interested in the relative magnitude of those coefficients. Hence we define the spectrum as the square of the absolute value of $\\hat{A}$\n\\beq\n\\label{eq:spec_defn}\n\\hat{S}[m] \\defn |A[m]|^2 = \\hat{A}[m]\\hat{A}^\\star[m]\\per\n\\eeq\nIt can be shown that $S[m]$ are the Fourier coefficients of the auto-correlation function of $A$.\n\n\\section{Parseval's theorem}\nThis important theorem states that\n\\beq\n\\label{eq:parseval}\n\\sum_{n=0}^{\\nmax-1} |A[n]|^2 = \\frac{1}{\\nmax}\\sum_{m=0}^{\\nmax-1} |\\hat{A}[n]|^2 = \\frac{1}{\\nmax}\\sum_{m=0}^{\\nmax-1} \\hat{S}[n] \\per\n\\eeq\nThis theorem is sometime quoted as ``the variance in physical space is equal to the variance in Fourier space''. For this statement to be true, we must normalize the above expression by $\\nmax$\n\\beq\n\\frac{1}{\\nmax}\\sum_{n=0}^{\\nmax-1} |A[n]|^2 = \\frac{1}{\\nmax^2}\\sum_{m=0}^{\\nmax-1} |\\hat{A}[n]|^2 = \\frac{1}{\\nmax^2}\\sum_{m=0}^{\\nmax-1} \\hat{S}[n] \\per\n\\eeq\nNotice that we would not have this normalization if we defined the Fourier coefficients as $\\eqref{eq:dft_defn}$ normalized by $\\nmax$. To be more precise, we would note include the average (zeroth coefficient). In practice, when dealing with data, we typically remove the average before applying the DFT, so that $\\hat{A}[0]$ is zero within machine precision. It is sometimes useful to think of the area under spectrum $\\hat{S}$ as the total variance. An estimate to this area is\n\\beq\n\\text{Area} \\approx \\frac{1}{\\nmax^2}\\sum_{m=0}^{\\nmax-1} \\hat{S}[n] \\dd k\\per\n\\eeq\nTo ensure this property while  satisfying  Parseval's relation \\eqref{eq:parseval} we normalize $\\hat{S}$ by $\\dd k$. Thus the spectrum that we typically plot in a log$\\times$log space is the square of the absolute value of the Fourier coefficients divided by $\\dd k\\,\\nmax^2$, and it has units of $A^2/k$. Notice that if $dx = 1$, then $dk = 1/\\nmax$ and we just need to normalize by $\\nmax$. Another nice property of the spectrum normalized by $\\dd k$ is that it is independent of the spectral resolution $\\dd k$, and therefore it is useful for comparing spectra calculated from data with different sampling characteristics. Furthermore, because typically we deal with real signals, $\\hat{S}$ is symmetric since $\\hat{A}$ is Hermitian-symmetric as discussed above. \n\n\\section{A note on averaging many estimates}\nA spectrum computed from a single realization is useless because the error in this estimate is of the same order as the spectrum (see Bendat and Piersol). Thus we average many realizations to obtain a meaningful estimate. I think it is best to normalize the spectrum by $\\nmax^2$ only after averaging. If $\\nmax$ is large and $\\hat{A}$ is small, we can loose accuracy by normalizing single estimates.\n\n\\end{document}\n\n\n", "meta": {"hexsha": "c826b30fae49c1fbb8d4d71e94f0c6f5228b05d1", "size": 7377, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/pyspec_normalization.tex", "max_stars_repo_name": "wenegrat/pyspec", "max_stars_repo_head_hexsha": "d2f6cc66fe61753c8e6b88dd6b18acb32c6f768b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-04-09T21:50:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T05:03:38.000Z", "max_issues_repo_path": "docs/pyspec_normalization.tex", "max_issues_repo_name": "crocha700/pyspec", "max_issues_repo_head_hexsha": "fa532ef35133ef89a268986a45792cc0dea72b66", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2015-11-11T07:32:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T05:39:43.000Z", "max_forks_repo_path": "docs/pyspec_normalization.tex", "max_forks_repo_name": "crocha700/pyspec", "max_forks_repo_head_hexsha": "fa532ef35133ef89a268986a45792cc0dea72b66", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-01-16T21:03:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-29T06:56:35.000Z", "avg_line_length": 53.4565217391, "max_line_length": 808, "alphanum_fraction": 0.7164158872, "num_tokens": 2358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311856832191, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6513920058024285}}
{"text": "\\chapter{Preface}\n\nThis book is a companion to \\emph{Quantum Mechanics in Simple Matrix Form} \\cite{Jordan2005} by Thomas Jordan. Quantum mechanics was developed using to different, but equivalent mathematical formalisms: wave mechanics and matrix mechanics. Today many introductions to the subject follow the approach invented by Erwin Schr\\\"odinger and begin with waves, which requires knowledge of partial differential equiations. Using Jordan's book as a guide, we're going to follow in the footsteps of Werner Heisenberg and Max Born and develop quantum mechanics using matrix algebra.\n\nMatrix algebra is a nice way to learn quantum mechanics for a few reasons. Firstly, it requires a lower entry to barrier on the mathematical front. The arithmetic of matrices builds on addition and multiplication of real numbers. Secondly, matrix mechanics generalizes in a particularly convenient way. Unlike real numbers, matrix products do not always commute \\sidenote{Remember this fact. Commutation is one of the great big ideas in quantum mechanics.}. That is, given any two real numbers $x$ and $y$, we can multiply $x$ by $y$ or multiply $y$ by $x$. Either way, we get the same result.\n\n$$ x\\cdot y = y \\cdot x $$\n\nGiven two matrices $A$ and $B$, the product $A$ applied to $B$ is not generally the same as the product $B$ applied to $A$.\n\n$$ AB \\neq BA $$\n\nYou'll notice that I wrote \\emph{applied to} instead of \\emph{multiplied by}, when I talked about the product of the matrices $A$ and $B$. Matrices are examples of \\emph{linear operators}. Over time we will come to think of linear operators as representing observable quantites in laboratory experiments such as position, velocity, or momentum.\\sidenote{You can squirrel this idea away for now, too. Linear operators represent observable quantities. I promise it will make sense later. It won't now. But we haven't even started yet.} But for now, you can think of them as a generalization of real numbers in which the order of operations matters. The operator formalism of quantum mechanics puts the commutation of observable quantities front and center. And to study quantum field theory, we'll need to graduate from state vectors to operators. Matrix mechanics will get us ready.\n\nWhile Jordan wrote his book to be accessible to students with little mathematical background, it moves pretty quickly. He requires a great deal of what people often call ``mathematical maturity.''\\sidenote{Said another way, there's very little that is simple in the book, even though it's written in ``simple matrix form.''} This companion text aims to fill in some of the gaps that Jordan must step over. Along the way, we'll explore some of the mathematical structures associated with the physics that Jordan doesn't have the time to introduce himself. He used his book to teach a single-semester course, and it's already packed with more than enough to fill a full semester.\n\nI have included new exercises to flesh out some of the concepts that Jordan covers. Many of these problems are meant to provide extra practice to develop intuition with the material. Others take us too far afield ever to have been included in the original text. Exercises that appear inline with the main text serve as a means to check your understanding as you go along. Those at the end of the chapters will advance your understanding further and are meant to take you longer to complete.\n\nSolutions to all of the problems in this book and in \\emph{Quantum Mechanics in Simple Matrix Form} appear in the second part of this book. But don't peek at an answer until you've given it a good college try! Problem solving is hard work. In a research laboratory there is no answer key. Oftentimes, there is no clear answer at all. So appoach the exercises as bite-sized opportunities to become a better, thinking scientist.\n\nSo without anymore ado, let's get to it.\n", "meta": {"hexsha": "e78ee8e26dd7e6455920df0492cf517478f03574", "size": 3881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/preface.tex", "max_stars_repo_name": "jareyes/qm-companion", "max_stars_repo_head_hexsha": "206d8070af7b19f09d79f0264aef0485c3c72380", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-13T11:03:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-13T11:03:30.000Z", "max_issues_repo_path": "chapters/preface.tex", "max_issues_repo_name": "ofenerci/qm-companion", "max_issues_repo_head_hexsha": "206d8070af7b19f09d79f0264aef0485c3c72380", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/preface.tex", "max_forks_repo_name": "ofenerci/qm-companion", "max_forks_repo_head_hexsha": "206d8070af7b19f09d79f0264aef0485c3c72380", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-20T16:03:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-13T12:35:37.000Z", "avg_line_length": 176.4090909091, "max_line_length": 881, "alphanum_fraction": 0.7912909044, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6513847685430906}}
{"text": "This work makes use of probability meshes to approximate a 4-dimensional (position,velocity) space. The meshes are then used to implement efficient forward estimation, integration of new sensor data, and integration of probabilistic rules. Finally, a pipeline is constructed from these elements to produce refined paths from raw positional input.\n\n\\section{Probability Meshes}\n\nEach trajectory of interest $t$ has an associated 4-dimensional $n*m*i*j$ probability mesh $M_t$, with each cell $M_t(n,m,i,j)$ in the mesh representing the likelihood that the most recent position and velocity in the trajectory lie in that cell.\nHowever $n$, $m$, $i$, and $j$ are integer values while locations and velocities are continuous.\nIn order to account for continuous values, an interpolation scheme can approximate points between cell centers.\n\nInterpolation works as follows: For each dimension $i$ in a query point $q=(q_n, q_m, q_i, q_j)$, calculate $\\mathit{floor}(i)$ and $\\mathit{ceil}(i)$. Then collect the set of adjacent points $P$ by generating all combinations of $floor$ and $ceil$ in each dimension. Interpolation is calculated over $P$ as shown in Equation \\ref{eqn:interpolation}.\n\n\\begin{equation} \\label{eqn:interpolation}\n    \\frac{\\sum_{p \\in P} 1/\\mathit{dist}(p, q) * M_t(p_n, p_m, p_i, p_j)}{\\sum_{p \\in P} (1/\\mathit{dist}(p, q)}\n\\end{equation}\n\nWith interpolation between cells, probability meshes can approximate a bounded continuous probability. Note that the division by \\textit{dist} is undefined when dist is zero. In practice, that can only occur when all indices are integers, and in that case the exact point found is returned. This interpolation algorithm has a property that will be heavily utilized in the remainder of the paper: Because all probabilities are weighted by \\textit{dist}, probabilities generated from a set of points are bounded by the minimum and maximum values stored in those points. Therefore, the point of maximum probability \\textit{must be an exact grid cell}.\n\nHowever, the grid indices have no mapping to real-world positions and velocities. To provide mappings, boundaries and a mapping function must be specified. Given an input position and velocity $(p_x, p_y, v_x, v_y)$ and boundaries $x_{min}, x_{max}, y_{min}, y_{max}, v_{min}, v_{max}$, the appropriate grid point is calculated by Equation \\ref{eqn:normalize}.\n\n\\begin{equation} \\label{eqn:normalize}\n    \\begin{aligned}\n        map(p_x, p_y, v_x, v_y) = &\\\\\n        (&\\frac{(p_x - x_{min})*n}{x_{max}-x_{min}},\\\\\n        &\\frac{(p_y - y_{min})*m}{y_{max}-y_{min}}, \\\\\n        &\\frac{(v_x - v_{min})*i}{v_{max}-v_{min}},\\\\\n        &\\frac{(v_y - v_{min})*j}{v_{max}-v_{min}})\n    \\end{aligned}\n\\end{equation}\n\nWith the inclusion of the mapping function and boundaries, a probability mesh can approximate a continuous probability over arbitrary boundaries. In addition, the mapping function can be reversed to $map_{reverse}$, calculating the corresponding point in the probability space for a particular cell in the mesh.\n\n\\subsection{Forward Propagation}\n\nBecause these probability meshes capture both position and velocity, future probability spaces can be estimated. Equation \\ref{eqn:timeprop} shows how a zeroed mesh $M_t'$ can be calculated from a past mesh $M_t$.\n\n\\begin{equation} \\label{eqn:timeprop}\n    M_t'(n+(t'-t)i,m+(t'-t)j,i,j) += M_t(n,m,i,j)\n\\end{equation}\n\n$M_t'$ represents an accurate estimate, assuming unchanging velocities. However in the real world objects can change velocity over time. To accomodate this, a blur factor can be added by averaging all adjacent points using a stencil algorithm.\n\n\\section{Probabilistic Rules}\n\nOften in addition to sensor input, we have domain knowledge about objects whose positions and velocities are being tracked. Such rules can often be colloquially expressed as \"Cars tend to drive on roads\", or \"Trucks and busses rarely make U-turns\". Under a traditional path refinement system such as a Kalman Filter, these rules cannot be expressed, as they represent non-gaussian probabilities. However, using probability meshes, these rules can be approximated and used to refine any sensor inputs or estimates. In order for a rule to help refine paths, it need not always be true. The examples above discuss things that usually occur, which can be formally defined as a probability. By phrasing rules as probability functions in the same 4-dimensional position, velocity space as the meshes defined above, such probabilistic rules can be expressed.\n\nA rule $R$ can be intersected with a mesh $M$ by applying the pointwise update equation -- Equation \\ref{eqn:ruleupdate} -- to all cells in the mesh, producing a new mesh $M'$. Multiplication allows the probabilities to be combined to generate the probability of both the original mesh and the rule being true for each cell.\n\n\\begin{equation} \\label{eqn:ruleupdate}\n    M'(n, m, i, j) = M(n, m, i, j) * R(map_{reverse}(n,m,i,j))\n\\end{equation}\n\n\\subsection{Road Matching}\n\nAs an example of probabilistic rules, this work implements the rule \\textit{\"vehicles usually drive on roads\"}. The exact equation for this rule is in Equation \\ref{eqn:roadprob}.\n\n\\begin{equation} \\label{eqn:roadprob}\n    \\begin{gathered}\n    R_{road}(p_x, p_y, v_x, v_y) = \\\\\n        \\textit{max}(\\alpha, \\textit{CNDF}(\\textit{distanceToRoad}(p_x, p_y)/\\beta))\n    \\end{gathered}\n\\end{equation}\n\n$\\alpha$ allows for this rule being incorrect, by setting a lower bound on the probability of any cell, regardless of roadways. $\\beta$ allows the allowed distance from the roadway to be scaled. Here CNDF refers to the cumulative normal distribution function, which returns a value between 0.5 and 0 for positive inputs.\n\nThe \\textit{distanceToRoad} function requires additional explanation.\nRoad map data for the city of Edmonton was aquired from OpenStreetMap, and roadways were extracted. Then, to reduce the number of roadways inspected for a particular calculation of this rule, a uniform grid index is overlaid on the area of interest, and roads are placed into each grid cell overlapped by their minimum bounding rectangle~(MBR). Grid cells should be of a width substantially larger than $\\beta$ above, so that a minimum of cells need to be inspected.\n\nWhen calculating \\textit{distanceToRoad} for a given point, all roads in the corresponding index cell are collected, as well as all roads in adjacent cells to account for query points near the edge of a cell. Then, the distance from each segment of each road to the query point is calculated. Finally, the minimum distance found is returned. An example of the probability space rendered from this work is shown in \\figref{fig:ex:osm}.\n\n\\input{figures/fig-ex-osm}\n\n\\section{Grid-Based Trajectory Refinement}\n\nFrom probability meshes and probabilistic rules, a pipeline can be assembled to refine trajectories in real-time. Consider a set of objects being tracked, $O$.\nEach object $o \\in O$ has an associated probability mesh $M(o)$, valid for a particular timestamp in the past $updateTime(o)$. All probability meshes are initialized to an equal uniform distribution.\nAs each sensor update $(o, \\mathit{time}, p_x, p_y)$ comes in, meshes are updated according to the following pipeline:\n\n\\begin{enumerate}\n\n\\item The object mesh is propagated forward in time according to Equation \\ref{eqn:timeprop}, using the time difference $\\textit{time} - \\textit{updateTime}(o)$.\n\n\\item A gaussian probability $\\textit{GPS}$ is constructed around $p_x, p_y$, constructed to match the error distribution that 95\\% of sensor readings are within 2 meters of accurate. The GPS probability is integrated into $M(o)$ according to Equation \\ref{eqn:ruleupdate}.\n\n\\item Any applicable rules can be integrated, again using Equation \\ref{eqn:ruleupdate}.\n\n\\item The new most likely position is found by finding the maximum cell in mesh $M(o)$ and reverse mapping the cell into the real-world position.\n\n\\end{enumerate}\n\n\n", "meta": {"hexsha": "f3b0eda8b101b4d0949125fa300ddec49e49ce59", "size": 7944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "finalReport/sections/work.tex", "max_stars_repo_name": "taylorlloyd/ETSLivePredict", "max_stars_repo_head_hexsha": "e6b70364226d5b11449cb939bb742d2569531060", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-12T04:36:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-12T04:36:56.000Z", "max_issues_repo_path": "finalReport/sections/work.tex", "max_issues_repo_name": "taylorlloyd/ETSLivePredict", "max_issues_repo_head_hexsha": "e6b70364226d5b11449cb939bb742d2569531060", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "finalReport/sections/work.tex", "max_forks_repo_name": "taylorlloyd/ETSLivePredict", "max_forks_repo_head_hexsha": "e6b70364226d5b11449cb939bb742d2569531060", "max_forks_repo_licenses": ["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.2666666667, "max_line_length": 851, "alphanum_fraction": 0.7653575025, "num_tokens": 1931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6513847641088719}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{Nonsmooth FD}{Nonsmooth FD}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf (Non)smooth moves\n\\end{center}\n\nWe derive finite difference formulas by interpolating with a polynomial, then differentiating the interpolant. This leads to, for example, the formulas\n\\begin{align}\n   W_1(h) &=  \\frac{f(h)-f(0)}{h} = f'(0) + O(h), \\label{W1} \\\\\n   W_2(h) &=  \\frac{f(h)-f(-h)}{2h} = f'(0) + O(h^2), \\label{W2} \\\\\n   W_4(h) &=  \\frac{-f(2h) + 8f(h)-8f(-h)+f(-2h)}{12h} = f'(0) + O(h^4). \\label{W4}\n\\end{align}\nThe terms $O(h^p)$ are a statement about the accuracy of the formula, which we say has order $p$.\n\nHowever, interpolation by a polynomial isn't ideal for every $f$ you might encounter. One reason is that polynomials are smooth---they have infinitely many derivatives. Consider $f(x)=|x|$, for example. It's continuous but not differentiable at $x=0$. What value should the finite difference attempt to get there: $+1$, $-1$, or something else? For a function that has one derivative but not two, there is a unique value to converge to, but the convergence rate is slowed by the singularity. \n\n\\subsection*{Goals}\n\nYou will apply finite difference methods of different orders to \nfunctions that lack smoothness at a point, and observe the effects on\nthe order of accuracy.\n\n\\subsection*{Preparation}\n\nRead sections 5.4 and 5.5. Determine the number of continuous derivatives at $x=0$ for the following functions:\n\\begin{align}\n  g_1(x) =\n  \\begin{cases}\n    5x+1, & x \\le 0 \\\\ (x+1)^5, & x > 0\n  \\end{cases}  \\label{g1} \\\\\n  g_2(x) =\n  \\begin{cases}\n    10x^2 + 5\\sin(x) + 1, & x \\le 0 \\\\ (x+1)^5, & x>0\n  \\end{cases} \\label{g2}\n\\end{align}\n\n\\subsection*{Procedure}\n\nDownload the script template and complete it to perform the following tasks, answering all questions in the text of your script. \n\n\\begin{enumerate}\n\\item Define $f(x)=\\exp(\\sin(x+1))$. This is our ``control'' case of a function with infinitely many derivatives everywhere. For each value of $h=2^{-1},2^{-2},2^{-3},\\ldots,2^{-10}$, compute $W_1(h)$, $W_2(h)$, and $W_4(h)$, storing the results in vectors. Then make a log-log plot showing all three cases of $|W_i(h)-f'(0)|$ as functions of $h$. You should see three straight lines with different slopes.\n\n\\item To the graph from step 1, add plots of the functions $h^1$, $h^2$, $h^3$, and $h^4$, as dashed lines. (Use labels, legends, etc.)  Confirm that each solid convergence curve matches well with the dashed line corresponding to the order of accuracy in the presentation of the formulas above.\n\n\\item Now let $f$ be $g_1$ from~\\eqref{g1}, by defining \n\\begin{verbatim}\nf = @(x) (5*x+1).*(x<=0) + ((x+1).^5).*(x>0);\n\\end{verbatim}\n(This defines the function piecewise for negative and positive $x$.) Make a plot of the function over $[-1/4,1/4]$.\n\n\\item Repeat steps 1--2 for the function in step 3. Now what are the observed orders of accuracy for $W_1$, $W_2$, and $W_4$?\n  \n\\item Repeat steps 1--2 for the function $g_2$ in~\\eqref{g2}.\n  \n\\end{enumerate}\n\n\\end{document}\n\n", "meta": {"hexsha": "7e77ef6d30784e118302839338177d2e4b2e8b22", "size": 3153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter05/NonsmoothFD/NonsmoothFD.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/chapter05/NonsmoothFD/NonsmoothFD.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/chapter05/NonsmoothFD/NonsmoothFD.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": 45.0428571429, "max_line_length": 492, "alphanum_fraction": 0.6923564859, "num_tokens": 1008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8947894654011352, "lm_q1q2_score": 0.6513847627517311}}
{"text": "\\section{Polar form}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Convert a complex number from standard form to polar form, and\n    from polar form to standard form.\n  \\end{enumerate}\n\\end{outcome}\n\nIn the previous section, we identified a complex number $z=a+bi$ with\na point $(a, b)$ in the coordinate plane. There is\nanother form in which we can express the same number, called the {\\em\npolar form}. The polar form is the focus of this section. It will turn out to be\nvery useful if not crucial for certain calculations as we shall soon\nsee.\n\nSuppose $z=a+bi$ is a complex number,  and let\n$r=\\sqrt{a^{2}+b^{2}} = |z|$. Recall that $r$ is the \\textbf{modulus}\\index{complex numbers!modulus}\\index{modulus} of $z$. Note first that\n\\begin{equation*}\n\\paren{\\frac{a}{r}} ^{2}+\\paren{\\frac{b}{r}} ^{2}=   \\frac{a^2+b^2}{r^2}=1\n\\end{equation*}\nand so $\\paren{\\frac{a}{r},\\frac{b}{r}}$\nis a point on the unit circle. Therefore, there exists an angle  $\n\\theta$ (in radians) such that\n\\begin{equation*}\n\\cos \\theta =\\frac{a}{r},\\ \\sin \\theta =\\frac{b}{r}\n\\end{equation*}\nIn other words $\\theta$ is an angle such\nthat $ a = r\\cos \\theta$ and $b=r \\sin \\theta$, that is $\\theta = \\cos^{-1}(a/r)$ and $\\theta = \\sin^{-1}(b/r)$. We call\nthis angle $\\theta$ the \\textbf{argument}\\index{complex numbers!argument}\\index{argument} of $z$.\n\nWe often speak of the \\textbf{principal argument}\\index{principal argument} of $z$. This is the unique angle $\\theta \\in (-\\pi, \\pi]$ such that\n\\begin{equation*}\n\\cos \\theta =\\frac{a}{r},\\ \\sin \\theta =\\frac{b}{r}\n\\end{equation*}\n\nThe polar form of the complex number $z=a+bi = r (\\cos \\theta +i\\sin \\theta)$ is for convenience written as:\n\\begin{equation*}\nz = r e^{i \\theta}\n\\end{equation*}\nwhere $\\theta $ is the argument of\n$z$.\n\n\\begin{definition}{Polar form of a complex number}{polar-form}\nLet $z = a + bi$ be a complex number. Then the \\textbf{polar form}\\index{complex numbers!polar form}\\index{polar form} of $z$ is written as\n\\[\nz = re^{i\\theta}\n\\]\nwhere $r = \\sqrt{a^2 + b^2}$ and $\\theta$ is the argument of $z$.\n\\end{definition}\n\nWhen given $z = re^{i\\theta}$, the identity $e^{i\\theta} = \\cos\\theta + i \\sin\\theta$ will convert $z$ back to standard form. Here we think of $ e^{i \\theta}$ as a short cut for $ \\cos \\theta\n+i\\sin \\theta$. This is all we will need in this course, but in\nreality $e^{i \\theta}$ can be considered as the complex equivalent of\nthe exponential function where this turns out to be a true equality.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw(-2,0)--(2,0);\n\\draw(0,-2)--(0,2);\n\\draw[ultra thick, blue, ->](0,0)--(1.5,1.5);\n\\node[right] at (1.5,1.5){$z = a+bi = re^{i\\theta}$};\n\\node[above right] at (0.5,0){$\\theta$};\n\\node[left] at (1,1){$r$};\n\\node at (-1.5,1){$r = \\sqrt{a^2 + b^2}$};\n\\end{tikzpicture}\n\\end{center}\n\nThus we can convert any complex number in the standard (Cartesian) form $z = a+bi$\ninto its polar form. Consider the following example.\n\n\\begin{example}{Standard to polar form}{polar-form}\nLet $z = 2 + 2i$ be a complex number.\nWrite $z$ in the polar form\n\\begin{equation*}\nz = re^{i \\theta}\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\nFirst, find $r$.\nBy the above discussion, $r=\\sqrt{\na^{2}+b^{2}} = |z|$. Therefore,\n\n\\begin{equation*}\nr = \\sqrt{2^{2} + 2^{2}} = \\sqrt{8} =2\\sqrt{2}\n\\end{equation*}\n\nNow, to find $\\theta$, we plot the point $(2, 2)$ and\nfind the angle from the positive $x$ axis to the line between this\npoint and the origin. In this case, $\\theta = 45^{\\circ} =\n\\frac{\\pi}{4}$.  That is we found the unique angle $\\theta$ such that\n$\\theta = \\cos^{-1}(1/\\sqrt{2})$ and $\\theta = \\sin^{-1}(1/\\sqrt{2})$.\n\nNote that in polar form, we always express angles in radians, not degrees.\n\nHence, we can write $z$ as\n\n\\begin{equation*}\nz = 2\\sqrt{2} e^{i\\frac{\\pi}{4}}\n\\end{equation*}\n\n\\end{solution}\n\nNotice that the standard and polar forms are completely equivalent. That is not only can we transform a complex number from standard form\nto its polar form, we can also take a complex number in polar form and\nconvert it back to standard form.\n\n\\begin{example}{Polar to standard form}{polar-standard-form}\nLet $z = 2 e^{ 2\\pi i/3}$. Write $z$ in the standard form\n\\begin{equation*}\nz = a+bi\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\nLet $z = 2 e^{2\\pi i/3}$ be the polar form of a complex number. Recall that\n$e^{i\\theta} = \\cos \\theta + i \\sin \\theta$. Therefore using standard values of $\\sin$ and $\\cos$ we get:\n\\begin{eqnarray*}\nz = 2 e^{i 2\\pi/3} &=& 2 (\\cos (2\\pi/3)+i\\sin (2\\pi/3))\\\\\n&=& 2 \\paren{-\\frac{1}{2} + i \\frac{\\sqrt{3}}{2}} \\\\\n&=&-1 + \\sqrt{3}i\n\\end{eqnarray*}\nwhich is the standard form of this complex number.\n\\end{solution}\n\nYou can always verify your answer by converting it back to polar form and ensuring you reach the original answer.\n", "meta": {"hexsha": "b141f6f54a56f110c792f0192fdde5b27df93393", "size": 4767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/complexnumbersPolarForm.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/complexnumbersPolarForm.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/complexnumbersPolarForm.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.2421875, "max_line_length": 191, "alphanum_fraction": 0.6714915041, "num_tokens": 1626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754371026367, "lm_q2_score": 0.8947894703109853, "lm_q1q2_score": 0.6513847557644763}}
{"text": "\\documentclass{article}\n\\usepackage[a4paper]{geometry}\n\\usepackage{amsmath}\n\\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}\n\n\\begin{document}\n\n\\title{Nonlinear stochastic differential equation generating $1/f$ noise}\n\n\\author{Julius Ruseckas}\n\n\\date{\\today{}}\n\n\\maketitle\n\n\\section{Nonlinear stochastic differential equations with multiplicative noise}\n\nIn Refs.~\\cite{kaulakys2004,kaulakys2006} nonlinear stochastic differential\nequations (SDEs) of the form\n\\begin{equation}\ndx_{t}=\\sigma^{2}\\left(\\eta-\\frac{\\lambda}{2}\\right)x_{t}^{2\\eta-1}dt\n+\\sigma x_{t}^{\\eta}dW_{t}\\label{eq:sde-1}\n\\end{equation}\nhave been proposed. Here $W_{t}$ is a standard Wiener process (the\nBrownian motion), $\\eta$ is the power-law exponent of multiplicative\nnoise and $\\sigma$ is the amplitude of the noise. In order to avoid\nthe divergence of the steady-state probability density function (PDF),\nEq.~(\\ref{eq:sde-1}) should be considered together with appropriate\nrestriction of the diffusion of the stochastic variable $x$. Here\nwe investigate the SDE with the exponential restriction of diffusion\nat $x=x_{\\mathrm{min}}$\n\\begin{equation}\ndx_{t}=\\sigma^{2}\\left(\\eta-\\frac{\\lambda}{2}+\\frac{m}{2}\n\\left(\\frac{x_{\\mathrm{min}}}{x}\\right)^{m}\\right)x_{t}^{2\\eta-1}dt\n+\\sigma x_{t}^{\\eta}dW_{t}\\,.\n\\label{eq:SDE-our}\n\\end{equation}\nEquation (\\ref{eq:SDE-our}) has stationary probability distribution\nfunction (PDF) of the form\n\\begin{equation}\nP_{0}(x)\\sim x^{-\\lambda}\n\\exp\\left(-\\left(\\frac{x_{\\mathrm{min}}}{x}\\right)^{m}\\right)\\,.\n\\end{equation}\nBased on scaling consideration \\cite{ruseckas2014} it is predicted\nthat the power spectral density (PSD) of the signal $x_{t}$ has $f^{-\\beta}$\nbehaviour in a wide range of frequencies, with \n\\begin{equation}\n\\beta=1+\\frac{\\lambda-3}{2(\\eta-1)}\\,.\n\\end{equation}\nUsing the parameters $\\lambda=2\\eta$ and $m=2\\eta-2$, equation\n(\\ref{eq:SDE-our}) takes the form of the \\emph{Constant Elasticity of Variance}\n(CEV) process:\n\\begin{equation}\ndx_{t}=\\sigma^{2}(\\eta-1)x_{\\mathrm{min}}^{2(\\eta-1)}x_{t}dt\n+\\sigma x_{t}^{\\eta}dW_{t}\\,.\n\\end{equation}\nIf $\\lambda=3$ then SDE (\\ref{eq:SDE-our}) gives $1/f$ spectrum.\nThus the CEV process has $1/f$ spectrum when $\\eta=\\frac{3}{2}$:\n\\begin{equation}\ndx_{t}=\\mu x_{t}dt+\\sigma x_{t}^{\\frac{3}{2}}dW_{t}\\,.\\label{eq:SDE-CEV}\n\\end{equation}\nHere\n\\begin{equation}\n\\mu=\\frac{1}{2}\\sigma^{2}x_{\\mathrm{min}}\\,.\n\\end{equation}\n\n\n\\subsection{Derivation of the analytical expression for the power spectral density}\n\nThe analytical expression for the transition probability $P_{x}(x',t|x,0)$\n(the conditional probability that at time $t$ the signal has value\n$x$ with the condition that at time $t=0$ the signal had the value\n$x_{0}$) of the CEV process is \\cite{kazakevicius2016}\n\\begin{equation}\nP_{x}(x,t|x_{0},0)=\\frac{x_{\\mathrm{min}}}{(1-e^{-\\mu t})}\n\\sqrt{\\frac{x_{0}}{x^{5}}}\\exp\\left(\\frac{1}{2}\\mu t\n-\\frac{x_{\\mathrm{min}}}{(1-e^{-\\mu t})}\\left(\\frac{1}{x}\n+\\frac{1}{x_{0}}e^{-\\mu t}\\right)\\right)\nI_{1}\\left(\\frac{x_{\\mathrm{min}}}{\\sinh\\left(\\frac{1}{2}\\mu t\\right)}\n\\frac{1}{\\sqrt{x_{0}x}}\\right)\\,.\n\\label{eq:trans}\n\\end{equation}\nHere $I_{z}$ is the modified Bessel function with index $z$. The\nsteady-state PDF has the form\n\\begin{equation}\nP_{0}(x)=\\frac{x_{\\mathrm{min}}^{2}}{x^{3}}\n\\exp\\left(-\\frac{x_{\\mathrm{min}}}{x}\\right)\\,.\n\\end{equation}\nThe average of the signal is\n\\begin{equation}\n\\bar{x}=\\int_{0}^{\\infty}xP_{0}(x)dx=x_{\\mathrm{min}}\\,.\n\\end{equation}\nThe autocorrelation function can be calculated using the expression\n\\begin{equation}\nC(t)=\\int dx\\int dx'\\,(x-\\bar{x})(x'-\\bar{x})P_{0}(x)P_{x}(x',t|x,0)\\,.\n\\end{equation}\nUsing Eq.~(\\ref{eq:trans}) and performing the integration we obtain\nthe autocorrelation function\n\\begin{equation}\nC(t)=x_{\\mathrm{min}}^{2}\\left[-e^{\\mu t}\n\\ln\\left(1-e^{-\\mu t}\\right)-1\\right]\\,.\n\\label{eq:autocorr}\n\\end{equation}\nWhen $\\mu t\\ll1$ we get\n\\begin{equation}\nC(t)\\approx-x_{\\mathrm{min}}^{2}-x_{\\mathrm{min}}^{2}\\ln(\\mu t)\\,.\n\\end{equation}\nSimilar expansion has been obtained for the autocorrelation function\nin the case of $1/f$ spectrum.\n\nAccording to Wiener-Khintchine relations, the power spectral density\nis connected with the autocorrelation function via the transformation\n\\begin{equation}\nS(f)=2\\int_{-\\infty}^{\\infty}C(t)e^{i\\omega t}dt=4\\int_{0}^{\\infty}C(t)\n\\cos(\\omega t)dt\\,,\n\\label{eq:wk}\n\\end{equation}\nwhere $\\omega=2\\pi f$ . Using Eq.~(\\ref{eq:autocorr}) for the autocorrelation\nfunction we get the following expression for the power spectral density:\n\\begin{equation}\nS(f)=2x_{\\mathrm{min}}^{2}\\left[\\frac{-\\gamma\n-\\psi\\left(-i\\frac{\\omega}{\\mu}\\right)}{\\mu+i\\omega}\n+\\frac{-\\gamma-\\psi\\left(i\\frac{\\omega}{\\mu}\\right)}{\\mu-i\\omega}\\right]\\,,\n\\end{equation}\nwhere $\\gamma\\approx0.577216$ is the Euler's constant and\n$\\psi(z)=\\Gamma^{\\prime}(z)/\\Gamma(z)$ is the digamma function. When\n$\\omega\\gg\\mu$ then the power spectral density is\n\\begin{equation}\nS(f)\\approx\\frac{2\\pi x_{\\mathrm{min}}^{2}}{\\omega}\\,.\n\\end{equation}\n\n\n\\section{Method of numerical solution}\n\nMethod of numerical solution with a variable time step is described\nin Ref.~\\cite{ruseckas2016}. For the numerical solution, we use\nEuler-Marujama approximation, transforming differential equations\nto difference equations. If the time step is $\\Delta t=h$ then the\ndifference equations, corresponding to Eq.~(\\ref{eq:SDE-CEV}) are\n\\begin{align}\nx_{k+1} = & x_{k}+\\mu x_{k}h+\\sigma x_{k}^{\\frac{3}{2}}\\sqrt{h}\\varepsilon_{k}\\\\\nt_{k+1} = & t_{k}+h\n\\end{align}\nHere $\\varepsilon_{k}$ are normally distributed uncorrelated random\nvariables with a zero expectation and unit variance. Variable time\nstep of integration \n\\[\nh_{k}=\\frac{\\kappa^{2}}{\\sigma^{2}x_{k}}\n\\]\nleads to the equations\n\\begin{align}\nx_{k+1} = & x_{k}+\\frac{1}{2}\\kappa^{2}x_{\\mathrm{min}}+\\kappa x_{k}\\varepsilon_{k}\\\\\nt_{k+1} = & t_{k}+\\frac{\\kappa^{2}}{\\sigma^{2}x_{k}}\n\\end{align}\nHere $\\kappa\\ll1$ is a small parameter.\n\n\\begin{thebibliography}{1}\n\\bibitem{kaulakys2004}B.~Kaulakys and J.~Ruseckas, \\textit{Stochastic\nnonlinear differential equation generating 1/f noise}, Phys.~Rev.~E\n\\textbf{70}, 020101 (2004).\n\n\\bibitem{kaulakys2006}B.~Kaulakys, J.~Ruseckas, V.~Gontis and\nM.~Alaburda, \\textit{Nonlinear stochastic models of 1/f noise and power-law\ndistributions}, Physica A \\textbf{365}, 217\\textendash 221 (2006).\n\n\\bibitem{ruseckas2014}J.~Ruseckas and B.~Kaulakys, \\textit{Scaling\nproperties of signals as origin of 1/f noise}, J.~Stat.~Mech.\\ \\textbf{2014},\nP06005 (2014).\n\n\\bibitem{kazakevicius2016}R.~Kazakevi\\v{c}ius and J.~Ruseckas,\n\\textit{Influence of external potentials on heterogeneous diffusion\nprocesses}, Phys.~Rev.~E \\textbf{94}, 032109 (2016).\n\n\\bibitem{ruseckas2016}J.~Ruseckas, R.~Kazakevi\\v{c}ius and B.~Kaulakys,\n\\textit{1/f noise from point process and time-subordinated Langevin\nequations}, J.~Stat.~Mech.\\ \\textbf{2016}, 054022 (2016).\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "7d85e81161bb06df45446dc0ad8d543f355c34a9", "size": 6905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "equations/CEV-1fspectrum.tex", "max_stars_repo_name": "JuliusRuseckas/numerical-sde-variable-step", "max_stars_repo_head_hexsha": "6204ac9d212fd6c73751d215c49e95373b573430", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-28T09:12:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T07:04:28.000Z", "max_issues_repo_path": "equations/CEV-1fspectrum.tex", "max_issues_repo_name": "JuliusRuseckas/numerical-sde-variable-step", "max_issues_repo_head_hexsha": "6204ac9d212fd6c73751d215c49e95373b573430", "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": "equations/CEV-1fspectrum.tex", "max_forks_repo_name": "JuliusRuseckas/numerical-sde-variable-step", "max_forks_repo_head_hexsha": "6204ac9d212fd6c73751d215c49e95373b573430", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3611111111, "max_line_length": 85, "alphanum_fraction": 0.7107892831, "num_tokens": 2482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6513549491636206}}
{"text": "%---- MATH -> Functions\n\\section{Functions}\n%%% Figure: Function exp(x) \n\\begin{marginfigure}[-5\\baselineskip]\n  %\\includegraphics[]{helix}\n  \\begin{tikzpicture}\n     \\begin{axis}[axis lines = left, xlabel = $x$, ylabel = {$f(x)=\\exp{(x)}$}]\n%Below the red parabola is defined\n     \\addplot [domain=0:3, samples=100]{exp(x)};\n     %\\addlegendentry{$f(x)=\\exp(x)$}\n     \\end{axis}\n  \\end{tikzpicture}\n  \\caption{Function as a graph.}\n  \\setfloatalignment{b}\n\\end{marginfigure}\n%%--- Functions\nFunctions are the backbone of calculus and is typically viewed in terms of their graphs of $x$ paired with $f(x)$. It can be viewed more generally as a {\\it mechanism} of producing an output $f(x)$ for an {\\it given} input $x$. With this mechanical view in mind, certain properties of functions can be defined more naturally. The {\\it domain} of a function consists of all possible values of inputs and the {\\it range} is all possible values of outputs. For single-variable calculus, the domain and ranges are going to be simple for example the real number line $R=(-\\infty ~\\infty)$ or certain sub-intervals of that $[a,b], [0, \\infty], etc.$. \nCertain operations on functions are critical, perhaps the most important being \\textit{composition}, \\textit{$f$ composed with $g$}, which takes it's input as $x$ and produces the output $(f\\cdot g)(x)=f(g(x))$ which can be visualized as a chain operation, with proper order.\n\\marginnote[-2\\baselineskip]{$\\sqrt{x^2+2}$ can be decomposed to $(f\\cdot g)(x)$ where, $g(x)=x^2+2$ and $f(x)=\\sqrt{x}$}\n%\n\\marginnote[\\baselineskip]{Note, $f^{-1}(x) \\neq 1/f(x)$}\nAnother important operation of functions is that of \\textit{inverse} of a function which takes it's input as $x$ and produces an output $f^{-1}(x)$ such that, when the output is fed to the input of the function $f(x)$ it's output is $x$. In other words, $f^{-1}(x)$ \\textit{undoes} whatever $f(x)$ \\textit{does}.", "meta": {"hexsha": "b4198ab13acf126b0bb3ac9cfeccdef74a3eddb5", "size": 1908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/section-math-functions.tex", "max_stars_repo_name": "mixignal/book-basic-eng", "max_stars_repo_head_hexsha": "1a6a02bd6156e2beda44172b26d7e271ab07cc1a", "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/section-math-functions.tex", "max_issues_repo_name": "mixignal/book-basic-eng", "max_issues_repo_head_hexsha": "1a6a02bd6156e2beda44172b26d7e271ab07cc1a", "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/section-math-functions.tex", "max_forks_repo_name": "mixignal/book-basic-eng", "max_forks_repo_head_hexsha": "1a6a02bd6156e2beda44172b26d7e271ab07cc1a", "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": 86.7272727273, "max_line_length": 645, "alphanum_fraction": 0.7007337526, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6513275145371399}}
{"text": "\\documentclass{article}\n\n\\usepackage[a4paper, margin=3cm]{geometry}\n\\usepackage{float}\n\\usepackage{algorithm2e}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{multicol}\n\n\\title{Lesson 2 : Problem Solving Paradigms}\n\\author{CPC UTEC - Lecturers Notes}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\setlength{\\parindent}{0mm}\n\n\\textbf{Scope \\& Objectives:}\n\\begin{itemize}\n\t\\item Have a formal understanding of Big-Oh notation.\n\t\\item Learn about the popular problem solving paradigms.\n\t\\item Understand Complete Search and brute force.\n\\end{itemize}\n\n\\setlength{\\parskip}{4mm}\n\n\\section{Algorithmic Analysis}\n\n\\textit{Big-Oh} notation is a tool we can use to measure how the complexity of our solution scales as the input of our program grows. This is done by measuring how our complexity compares to other functions as the input size goes to infinity. For this reason this is know as \\textit{Asymptotic Analysis}.\n\nFormally, we can define Big-Oh notation as:\n$$f(n) = O(g(n)) \\longleftrightarrow f(n) \\leq kg(n)$$\n$$\\text{Where } n > n_0, \\; k > 0 \\text{ and } n_0 \\in \\mathbb{R}$$\n\nThis definition might seem complex but is very simple to understand. We can use the aid of the following graph:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{images/bigoh}\n\t\\caption{Graphical understanding of Big-Oh}\n\\end{figure}\n\nFirst of all we must understand that $O(g(n))$ is not a function but a family (or set) of functions. For this reasons many believe that the `$\\in$' symbol would be more appropriate than the `=' symbol. Therefore, it is a good idea to read the `=' sign as \\textit{belongs} or \\textit{is in}.\n\n\\section{Problem Solving Paradigms}\n\n\\subsection{Paradigm vs Algorithm}\n\n\\begin{multicols}{2}\n\t\\raggedcolumns\n\t\\centering \\textbf{Algorithm}\n\t\\begin{itemize}\n\t\t\\item Solves a specific problem.\n\t\t\\item Gives steps and instructions.\n\t\\end{itemize}\n\n\t\\columnbreak\n\n\t\\centering \\textbf{Paradigm}\n\t\\begin{itemize}\n\t\t\\item Solves a family of problems.\n\t\t\\item Gives ideas and methodologies.\n\t\t\\item Is a conceptual framework for problem solving.\n\t\\end{itemize}\n\\end{multicols}\n\n\\subsection{Popular Paradigms}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{images/programming-paradigms}\n\t\\caption{Popular problem solving paradigms.}\n\\end{figure}\n\n\\section{Complete Search}\n\nMost competitive programming problems (and most problems in general) can be solved by listing all the possible solutions and checking each of them until we find the correct one. This method of problems solving in which we exhaustively check all possible solutions is called \\textit{complete search}.\n\nThis paradigm is extremely important as we can almost always find a complete search solutions to any given problem (even though this solution will probably violate the time constrains). Being good at designing complete search solutions is extremely important to learn the other problems solving paradigms and understanding the importance of optimizations.\n\n\\subsection{Key Terms} \n\n\\begin{itemize}\n\t\\item \\textbf{Solution-Space:} All the candidate or possible solutions there are.\n\t\\item \\textbf{Brute Force:} Iterative complete search.\n\t\\item \\textbf{Fixing:} Assuming a \\textit{variable} has a constant value.\n\\end{itemize}\n\n\\subsection{Example: Number of solutions}\n\nLets consider the following problem. Given the positive integers $a$, $b$, $c$ and $d$, find how many solutions the equation $x + y + z = d$ has, given that $x, y, z \\in \\mathbb{N}^+$, $x \\leq a$, $y \\leq b$ and $z \\leq c$.\n\nA first approach for solving this problem is to fix the values of $x$, $y$ and $z$. We can then find the value of $x + y + z$ and check if it equals $d$.\n\n\\begin{algorithm}\n\t\\SetAlgoNoEnd\n\t$cnt \\gets 0$\\;\n\t\\For{$x \\gets 1$ \\KwTo $a$}{\n\t\t\\For{$y \\gets 1$ \\KwTo $b$}{\n\t\t\t\\For{$z \\gets 1$ \\KwTo $c$}{\n\t\t\t\t\\If{$x + y + z = d$}{\n\t\t\t\t\t$cnt \\gets cnt + 1$\\;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\\Return $cnt$\\;\n\\end{algorithm}\n\nIt is simple to see that this solution has a complexity of $O(n^3)$. In general, for complete search our time complexity can be estimates as:\n\n$$T(n) = |\\text{Solution Space}| \\times \\text{time to check a solution}$$\n\nIn this example we take $O(1)$ to check each candidate solution, but we visit $O(n^3)$ possible solutions, giving the total complexity of $O(n^3)$. Can we improve this solution?\n\nOne important observation is to realize that if we fix the values of $a$ and $b$, then we can re-write the equation as: $z = d - x - y$. This means that for every pair of values $(x, y)$, there exists a single possible value of $z$ that can satisfy the equation. Now we all have to do is verify that the value of $z$ is valid.\n\n\\begin{algorithm}\n\t\\SetAlgoNoEnd\n\t$cnt \\gets 0$\\;\n\t\\For{$x \\gets 1$ \\KwTo $a$}{\n\t\t\\For{$y \\gets 1$ \\KwTo $b$}{\n\t\t\t$z \\gets d - x - y$\\;\n\t\t\t\\If{$1 \\leq z \\leq c$}{\n\t\t\t\t$cnt \\gets cnt + 1$\\;\n\t\t\t}\n\t\t}\n\t}\n\t\\Return $cnt$\\;\n\\end{algorithm}\n\nOur time taken to verify each solution is still $O(1)$, however the size of our solution space is now $O(n^2)$. This drastically improves the solutions complexity, taking it from $O(n^3)$ to $O(n^2)$. Further improvements can be done to make in order to find the answer in $O(n)$ time or faster.\n\nThe most important takeaway of this example should be that a brute force algorithm is not necessarily a dumb or easy algorithm, many time brute force solutions need to be tightly optimized in order to yield a correct solution that works within the time constrains.\n\n\\end{document}\n", "meta": {"hexsha": "c005afa18cc687fb1c40d3825c6794b81d1d618d", "size": 5473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2020-II/Lessons/2/notes.tex", "max_stars_repo_name": "CP-UTEC/theory", "max_stars_repo_head_hexsha": "bd24c10d074ae7c25104460ba164d96d66efa502", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-15T05:34:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-03T03:51:55.000Z", "max_issues_repo_path": "2020-II/Lessons/2/notes.tex", "max_issues_repo_name": "CP-UTEC/theory", "max_issues_repo_head_hexsha": "bd24c10d074ae7c25104460ba164d96d66efa502", "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": "2020-II/Lessons/2/notes.tex", "max_forks_repo_name": "CP-UTEC/theory", "max_forks_repo_head_hexsha": "bd24c10d074ae7c25104460ba164d96d66efa502", "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.0928571429, "max_line_length": 355, "alphanum_fraction": 0.7283025763, "num_tokens": 1583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.6513275101688095}}
{"text": "% This chapter was modified on 1/12/05.\n%\\setcounter{chapter}{7}\n\\chapter{Law of Large Numbers}\\label{chp 8} \n\n\\section[Discrete Random Variables]{Law of Large Numbers for Discrete Random Variables}\n\\label{sec 8.1}\nWe are now in a position to prove our first fundamental theorem of probability.  \nWe have seen that an intuitive way to view the probability of a certain outcome is as the \nfrequency with which that outcome occurs in the long run, when the experiment is repeated a large \nnumber of times.  We have also defined probability mathematically as a value of a distribution \nfunction for the random variable representing the experiment.   The Law of Large Numbers, which is\na theorem proved about the mathematical model of probability, shows that this model is consistent \nwith the frequency interpretation of probability.  This theorem is sometimes called the \\emx {law\nof averages.}  To find out what would happen if this law were not true, see the article  by \nRobert M. Coates.\\index{COATES, R. M.}\\footnote{R.~M.~Coates, ``The Law,\" \\emx {The World of\nMathematics,} ed. James R. Newman (New York: Simon and Schuster, 1956.}\n\n\\subsection*{Chebyshev Inequality}\nTo discuss the Law of Large Numbers, we first need an important inequality\ncalled the \\emx {Chebyshev Inequality.}\n\n\\begin{theorem}{\\bf (Chebyshev Inequality)}\\index{Chebyshev Inequality}\nLet $X$ be a discrete random variable with expected value $\\mu = E(X)$, and let $\\epsilon\n> 0$ be any positive real number.  Then\n$$\nP(|X - \\mu| \\geq \\epsilon) \\leq \\frac {V(X)}{\\epsilon^2}\\ .\n$$\n\\proof\nLet $m(x)$ denote the distribution function of $X$.  Then the probability that $X$\ndiffers from $\\mu$ by at least $\\epsilon$ is given by\n$$P(|X - \\mu| \\geq \\epsilon) = \\sum_{|x - \\mu| \\geq \\epsilon} m(x)\\ .$$\nWe know that \n$$V(X) = \\sum_x (x - \\mu)^2 m(x)\\ ,$$\nand this is clearly at least as large as\n$$\\sum_{|x - \\mu| \\geq \\epsilon} (x - \\mu)^2 m(x)\\ ,$$\nsince all the summands are positive and we have restricted the range of summation in the\nsecond sum.  But this last sum is at least\n\\begin{eqnarray*}\n\\sum_{|x - \\mu| \\geq \\epsilon} \\epsilon^2 m(x) &=& \n\\epsilon^2 \\sum_{|x - \\mu| \\geq \\epsilon} m(x) \\\\\n&=& \\epsilon^2 P(|X - \\mu| \\geq \\epsilon)\\ .\\\\\n\\end{eqnarray*}\nSo,\n$$ P(|X - \\mu| \\geq \\epsilon) \\leq \\frac {V(X)}{\\epsilon^2}\\ .\n$$\n\\end{theorem}\nNote that $X$ in the above theorem can be any discrete random variable, and\n$\\epsilon$ any positive number.\n\n\\begin{example}\nLet $X$ by any random variable with $E(X) = \\mu$ and $V(X) = \\sigma^2$.  Then,\nif $\\epsilon = k\\sigma$, Chebyshev's Inequality states that\n$$\nP(|X - \\mu| \\geq k\\sigma) \\leq \\frac {\\sigma^2}{k^2\\sigma^2} = \\frac 1{k^2}\\ .\n$$\nThus, for any random variable, the probability of a deviation from the mean of\nmore than~$k$ standard deviations is ${} \\leq 1/k^2$.  If, for example,\n$k = 5$, $1/k^2 = .04$.\n\\end{example}\n\nChebyshev's Inequality is the best possible inequality in the sense that, for\nany $\\epsilon > 0$, it is possible to give an example of a random variable for\nwhich Chebyshev's Inequality is in fact an equality.  To see this, given\n$\\epsilon > 0$, choose $X$ with distribution\n$$\np_X = \\pmatrix{\n-\\epsilon & +\\epsilon \\cr\n1/2 & 1/2 \\cr}\\ .\n$$\nThen $E(X) = 0$, $V(X) = \\epsilon^2$, and\n$$\nP(|X - \\mu| \\geq \\epsilon) = \\frac {V(X)}{\\epsilon^2} = 1\\ .\n$$\n\nWe are now prepared to state and prove the Law of Large Numbers.\n\n\\subsection*{Law of Large Numbers}\n\\begin{theorem}{\\bf (Law of Large Numbers)}\\index{Law of Large Numbers}\nLet $X_1$,~$X_2$, \\dots,~$X_n$ be an independent trials process, with\nfinite expected value $\\mu = E(X_j)$ and finite variance $\\sigma^2 =\nV(X_j)$.  Let $S_n = X_1 + X_2 +\\cdots+ X_n$.  Then for\nany $\\epsilon > 0$, \n$$ P\\left( \\left| \\frac {S_n}n - \\mu \\right| \\geq \\epsilon\n\\right) \\to 0\n$$\nas $n \\rightarrow \\infty$.\nEquivalently,\n$$\nP\\left( \\left| \\frac {S_n}n - \\mu \\right| < \\epsilon \\right) \\to 1\n$$\nas $n \\rightarrow \\infty$.\n\\proof\nSince $X_1$,~$X_2$, \\dots,~$X_n$ are independent and have the same distributions,\nwe can apply Theorem~\\ref{thm 6.9}.  We obtain\n$$\nV(S_n) = n\\sigma^2\\ ,\n$$\nand\n$$\nV (\\frac {S_n}n) = \\frac {\\sigma^2}n\\ .\n$$\nAlso we know that\n$$\nE (\\frac {S_n}n) = \\mu\\ .\n$$\nBy Chebyshev's Inequality, for any $\\epsilon > 0$,\n$$\nP\\left( \\left| \\frac {S_n}n - \\mu \\right| \\geq \\epsilon \\right) \\leq \\frac\n{\\sigma^2}{n\\epsilon^2}\\ .\n$$\nThus, for fixed $\\epsilon$,\n$$\nP\\left( \\left| \\frac {S_n}n - \\mu \\right| \\geq \\epsilon \\right) \\to 0\n$$\nas $n \\rightarrow \\infty$, or equivalently,\n$$\nP\\left( \\left| \\frac {S_n}n - \\mu \\right| < \\epsilon \\right) \\to 1\n$$\nas $n \\rightarrow \\infty$.\n\\end{theorem}\n\n\\subsection*{Law of Averages}\nNote that $S_n/n$ is an average of the individual outcomes, and one often\ncalls the Law of Large Numbers the ``law of averages.\" It is a striking fact\nthat we can start with a random experiment about which little can be predicted\nand, by taking averages, obtain an experiment in which the outcome can be\npredicted with a high degree of certainty.  The Law of Large Numbers, as we\nhave stated it, is often called the ``Weak Law of Large Numbers\" to\ndistinguish it from the ``Strong Law of Large Numbers\" described in\nExercise~\\ref{exer 8.1.16}.\n\nConsider the important special case of Bernoulli trials with probability~$p$\nfor success.  Let $X_j = 1$ if the $j$th outcome is a success and~0 if it is a\nfailure.  Then $S_n = X_1 + X_2 +\\cdots+ X_n$ is the number of successes in $n$\ntrials and $\\mu = E(X_1) = p$.  The Law of Large Numbers states that for any\n$\\epsilon > 0$\n$$\nP\\left( \\left| \\frac {S_n}n - p \\right| < \\epsilon \\right) \\to 1\n$$\nas $n \\rightarrow \\infty$.  The above statement says that, in a large number of repetitions\nof a Bernoulli experiment, we can expect the proportion of times the event will\noccur to be near $p$.  This shows that our mathematical model of probability\nagrees with our frequency interpretation of probability.  \n\n\\subsection*{Coin Tossing}\nLet us consider the special case of tossing a coin $n$ times with $S_n$ the\nnumber of heads that turn up.  Then the random variable $S_n/n$ represents the\nfraction of times heads turns up and will have values between 0~and~1.  The Law\nof Large Numbers predicts that the outcomes for this random variable will, for\nlarge~$n$, be near 1/2.\n\nIn Figure~\\ref{fig 8.1}, we have plotted the distribution for this example for increasing values of\n~$n$. We have marked the outcomes between .45~and~.55 by dots at the top of the\nspikes.  We see that as\n$n$ increases the distribution gets more and more concentrated around~.5 and a larger\nand larger percentage of the total area is contained within the interval\n$(.45,.55)$, as predicted by the Law of Large Numbers.\n\n\\putfig{5.0truein}{PSfig8-1}{Bernoulli trials distributions.}{fig 8.1} \n\n\n\\subsection*{Die Rolling}\n\\begin{example}\nConsider $n$ rolls of a die.  Let $X_j$ be the outcome of the $j$th roll.  Then\n$S_n = X_1 + X_2 +\\cdots+ X_n$ is the sum of the first $n$ rolls.  This is an\nindependent trials process with $E(X_j) = 7/2$.  Thus, by the Law of Large\nNumbers, for any $\\epsilon > 0$\n$$\nP\\left( \\left| \\frac {S_n}n - \\frac 72 \\right| \\geq \\epsilon \\right) \\to 0\n$$\nas $n \\rightarrow \\infty$.  An equivalent way to state this is that, for any $\\epsilon > 0$,\n$$\nP\\left( \\left| \\frac {S_n}n - \\frac 72 \\right| < \\epsilon \\right) \\to 1\n$$\nas $n \\rightarrow \\infty$.\n\\end{example}\n\n\\subsection*{Numerical Comparisons}\nIt should be emphasized that, although Chebyshev's Inequality proves the Law of Large\nNumbers, it is actually a very crude inequality for the probabilities involved.  However,\nits strength lies in the fact that it is true for any random variable at all, and it allows\nus to prove a very powerful theorem.\n\\par\nIn the following example, we compare the estimates given by Chebyshev's Inequality with the\nactual values.\n\\begin{example}\nLet $X_1$,~$X_2$, \\dots,~$X_n$ be a Bernoulli trials process with\nprobability~.3 for success and~.7 for failure.  Let $X_j = 1$ if the $j$th\noutcome is a success and~0 otherwise.  Then, $E(X_j) = .3$ and $V(X_j) =\n(.3)(.7) = .21$.  If\n$$\nA_n = \\frac {S_n}n = \\frac {X_1 + X_2 +\\cdots+ X_n}n\n$$\nis the \\emx {average} of the $X_i$, then $E(A_n) = .3$ and $V(A_n) =\nV(S_n)/n^2 = .21/n$.  Chebyshev's Inequality states that if, for example,\n$\\epsilon = .1$,\n$$\nP(|A_n - .3| \\geq .1) \\leq \\frac {.21}{n(.1)^2} = \\frac {21}n\\ .\n$$\nThus, if $n = 100$,\n$$\nP(|A_{100} - .3| \\geq .1) \\leq .21\\ ,\n$$\nor if $n = 1000$,\n$$\nP(|A_{1000} - .3| \\geq .1) \\leq .021\\ .\n$$\nThese can be rewritten as\n \\begin{eqnarray*}\nP(.2 < A_{100} < .4) &\\geq& .79\\ , \\\\\nP(.2 < A_{1000} < .4) &\\geq& .979\\ .\n\\end{eqnarray*} \nThese values should be compared with the actual values, which are (to six decimal\nplaces)\n\\begin{eqnarray*}\nP(.2 < A_{100} < .4) &\\approx& .962549 \\\\\nP(.2 < A_{1000} < .4) &\\approx& 1\\ .\\\\\n\\end{eqnarray*}\nThe program {\\bf Law}\\index{Law (program)} can be used to carry out the above calculations in a\nsystematic way.\n\\end{example}\n\n\n\\subsection*{Historical Remarks}\nThe Law of Large Numbers was first proved by the Swiss mathematician James\nBernoulli\\index{BERNOULLI, J.|(} in the fourth part of his work \\emx {Ars Conjectandi} published\nposthumously in~1713.\\footnote{J. Bernoulli, \\emx {The Art of Conjecturing\nIV,} trans.~Bing Sung, Technical Report No.~2, Dept.\\ of Statistics, Harvard\nUniv., 1966}  As often happens with a first proof, Bernoulli's proof was much\nmore difficult than the proof we have presented using Chebyshev's inequality. \nChebyshev developed his inequality to prove a general form of the Law of Large\nNumbers (see Exercise~\\ref{exer 8.1.13}).  The inequality itself appeared\nmuch earlier in a work by Bienaym\\'e,\\index{BIENAYM\\'E, I.} and in discussing its history\nMaistrov\\index{MAISTROV, L.} remarks that it was referred to as the Bienaym\\'e-Chebyshev\nInequality for a long time.\\footnote{L. E. Maistrov, \\emx {Probability Theory: A Historical\nApproach,} trans.\\ and ed.~Samual Kotz, (New York: Academic Press, 1974),\np.~202}\n\nIn \\emx {Ars Conjectandi} Bernoulli provides his reader with a long discussion\nof the meaning of his theorem with lots of examples.  In modern notation he has\nan event that occurs with probability~$p$ but he does not know $p$.  He wants\nto estimate $p$ by the fraction $\\bar{p}$ of the times the event occurs\nwhen the experiment is repeated a number of times.  He discusses in detail the\nproblem of estimating, by this method, the proportion of white balls in an urn\nthat contains an unknown number of white and black balls.  He would do this by\ndrawing a sequence of balls from the urn, replacing the ball drawn after each\ndraw, and estimating the unknown proportion of white balls in the urn by the\nproportion of the balls drawn that are white.  He shows that, by choosing $n$\nlarge enough he can obtain any desired accuracy and reliability for the\nestimate.  He also provides a lively discussion of the applicability of his\ntheorem to estimating the probability of dying of a particular disease, of\ndifferent kinds of weather occurring, and so forth.\n\nIn speaking of the number of trials necessary for making a judgement, Bernoulli\nobserves that the ``man on the street\" believes the ``law of averages.\"\n\n\\begin{quote}\nFurther, it cannot escape anyone that for judging in this way about any event\nat all, it is not enough to use one or two trials, but rather a great number of\ntrials is required.  And sometimes the stupidest man---by some instinct of\nnature \\emx {per se} and by no previous instruction (this is truly amazing)---\nknows for sure that the more observations of this sort that are taken, the less\nthe danger will be of straying from the mark.\\footnote{Bernoulli, op.\\ cit., p.~38.}\n\\end{quote}\n\n\\noindent But he goes on to say that he must contemplate another possibility.\n\n\\begin{quote}\nSomething futher must be contemplated here which perhaps no one has thought\nabout till now.  It certainly remains to be inquired whether after the number\nof observations has been increased, the probability is increased of attaining\nthe true ratio between the number of cases in which some event can happen and\nin which it cannot happen, so that this probability finally exceeds any given\ndegree of certainty; or whether the problem has, so to speak, its own\nasymptote---that is, whether some degree of certainty is given which one can\nnever exceed.\\footnote{ibid., p.~39.}\n\\end{quote}\n\n\\noindent Bernoulli recognized the importance of this theorem, writing:\n\n\\begin{quote}\nTherefore, this is the problem which I now set forth and make known after I\nhave already pondered over it for twenty years.  Both its novelty and its very\ngreat usefullness, coupled with its just as great difficulty, can exceed in\nweight and value all the remaining chapters of this thesis.\\footnote{ibid.,\np.~42.}\n\\end{quote}\n\n\\noindent Bernoulli concludes his long proof with the remark:\n\n\\begin{quote}\nWhence, finally, this one thing seems to follow: that if observations of all\nevents were to be continued throughout all eternity, (and hence the ultimate\nprobability would tend toward perfect certainty), everything in the world would\nbe perceived to happen in fixed ratios and according to a constant law of\nalternation, so that even in the most accidental and fortuitous occurrences we\nwould be bound to recognize, as it were, a certain necessity and, so to speak,\na certain fate.\n\nI do now know whether Plato wished to aim at this in his doctrine of the\nuniversal return of things, according to which he predicted that all things\nwill return to their original state after countless ages have\npast.\\footnote{ibid., pp.~65--66.}\n\\end{quote}\\index{BERNOULLI, J.|)}\n\n\\exercises\n\\begin{LJSItem}\n\n\\i\\label{exer 8.1.1} A fair coin is tossed 100 times.  The expected number of\nheads is~50, and the standard deviation for the number of heads is $(100 \\cdot\n1/2 \\cdot 1/2)^{1/2} = 5$.  What does Chebyshev's Inequality tell you about the\nprobability that the number of heads that turn up deviates from the expected\nnumber 50 by three or more standard deviations (i.e., by at least 15)?\n\n\\i\\label{exer 8.1.100} Write a program that uses the function \n$\\mbox {binomial}(n,p,x)$ to compute the exact probability that you estimated in\nExercise~\\ref{exer 8.1.1}.  Compare the two results.\n\n\\i\\label{exer 8.1.101} Write a program to toss a coin 10{,}000 times.  Let $S_n$ be the\nnumber of heads in the first $n$ tosses.  Have your program print out, after every\n1000 tosses, $S_n - n/2$.  On the basis of this simulation, is it correct to\nsay that you can expect heads about half of the time when you toss a coin a\nlarge number of times?\n\n\\i\\label{exer 8.1.102} A 1-dollar bet on craps has an expected winning of $-.0141$.  What\ndoes the Law of Large Numbers say about your winnings if you make a large number of\n1-dollar bets at the craps table?  Does it assure you that your losses will be\nsmall?  Does it assure you that if $n$ is very large you will lose?\n\n\\i\\label{exer 8.1.103} Let $X$ be a random variable with $E(X) =0$ and $V(X) = 1$.  What\ninteger value~$k$ will assure us that $P(|X| \\geq k) \\leq .01$?\n\n\\i\\label{exer 8.1.6} Let $S_n$ be the number of successes in $n$ Bernoulli\ntrials with probability~$p$ for success on each trial.  Show, using Chebyshev's\nInequality, that for any $\\epsilon > 0$\n$$\nP\\left( \\left| \\frac {S_n}n - p \\right| \\geq \\epsilon \\right) \\leq \\frac {p(1 -\np)}{n\\epsilon^2}\\ .\n$$\n\n\\i\\label{exer 8.1.7} Find the maximum possible value for $p(1 - p)$ if $0 < p\n< 1$.  Using this result and Exercise~\\ref{exer 8.1.6}, show that the estimate\n$$\nP\\left( \\left| \\frac {S_n}n - p \\right| \\geq \\epsilon \\right) \\leq \\frac\n1{4n\\epsilon^2}\n$$\nis valid for any $p$.\n\n\\i\\label{exer 8.1.104} A fair coin is tossed a large number of times.  Does the Law of Large\nNumbers assure us that, if $n$ is large enough, with $\\mbox {probability} >\n.99$ the number of heads that turn up will not deviate from $n/2$ by more than\n100?\n\n\\i\\label{exer 8.1.105} In Exercise~\\ref{sec 6.2}.\\ref{exer 6.2.16}, you showed that, for the\nhat check problem, the number $S_n$ of people who get their own hats back has $E(S_n) =\nV(S_n) = 1$.  Using Chebyshev's Inequality, show that $P(S_n \\geq 11) \\leq .01$\nfor any $n \\geq 11$.\n\n\\i\\label{exer 8.1.106} Let $X$ by any random variable which takes on values 0,~1,~2,\n\\dots,~$n$ and has $E(X) = V(X) = 1$.  Show that, for any positive integer $k$,\n$$\nP(X \\geq k + 1) \\leq \\frac 1{k^2}\\ .\n$$\n\n\\i\\label{exer 8.1.107} We have two coins: one is a fair coin and the other is a coin that\nproduces heads with probability 3/4.  One of the two coins is picked at random,\nand this coin is tossed $n$ times.  Let $S_n$ be the number of heads that turns\nup in these $n$ tosses.  Does the Law of Large Numbers allow us to predict the\nproportion of heads that will turn up in the long run?  After we have observed\na large number of tosses, can we tell which coin was chosen?  How many tosses\nsuffice to make us 95~percent sure?\n\n\\i\\label{exer 8.1.13} (Chebyshev\\index{CHEBYSHEV, P. L.}\\footnote{P. L. Chebyshev, ``On Mean\nValues,\" \\emx {J.\\ Math.\\ Pure.\\ Appl.,} vol.~12 (1867), pp.~177--184.})  Assume\nthat $X_1$,~$X_2$, \\dots,~$X_n$ are independent random variables with possibly\ndifferent distributions and let $S_n$ be their sum.  Let $m_k = E(X_k)$,\n$\\sigma_k^2 = V(X_k)$, and $M_n = m_1 + m_2 +\\cdots+ m_n$.  Assume that\n$\\sigma_k^2 < R$ for all~$k$.  Prove that, for any $\\epsilon > 0$,\n$$\nP\\left( \\left| \\frac {S_n}n - \\frac {M_n}n \\right| < \\epsilon \\right) \\to 1\n$$\nas $n \\rightarrow \\infty$.\n\n\\i\\label{exer 8.1.108}  A fair coin is tossed repeatedly.  Before each toss, you are allowed\nto decide whether to bet on the outcome.  Can you describe a betting system with infinitely\nmany bets which will enable you, in the long run, to win more than half of your bets? \n(Note that we are disallowing a betting system that says to bet until you are ahead, then\nquit.) Write a computer program that implements this betting system.  As stated above, your\nprogram must decide whether to bet on a particular outcome before that outcome is determined.\nFor example, you might select only outcomes that come after\nthere have been three tails in a row.  See if you can get more than 50\\% heads\nby your ``system.\"\n\n\\istar\\label{exer 8.1.109} Prove the following analogue of Chebyshev's Inequality:\n$$\nP(|X - E(X)| \\geq \\epsilon) \\leq \\frac 1\\epsilon E(|X - E(X)|)\\ .\n$$\n\n\\istar\\label{exer 8.1.16} We have proved a theorem often called the ``Weak Law of\nLarge Numbers.\"  Most people's intuition and our computer simulations suggest\nthat, if we toss a coin a sequence of times, the proportion of heads will really\napproach 1/2; that is, if $S_n$ is the number of heads in $n$ times, then we\nwill have\n$$\nA_n = \\frac {S_n}n \\to \\frac 12\n$$\nas $n \\to \\infty$.  Of course, we cannot be sure of this since we are not able\nto toss the coin an infinite number of times, and, if we could, the coin could\ncome up heads every time.  However, the ``Strong Law of Large Numbers,\"\\index{Strong Law of \nLarge\\\\ Numbers} proved in more advanced courses, states that\n$$\nP\\left( \\frac {S_n}n \\to \\frac 12 \\right) = 1\\ .\n$$\nDescribe a sample space $\\Omega$ that would make it possible for us to talk\nabout the event\n$$\nE = \\left\\{\\, \\omega : \\frac {S_n}n \\to \\frac 12\\, \\right\\}\\ .\n$$\nCould we assign the equiprobable measure to this space?  \n\\choice{}{(See\nExample~\\ref{exam 2.2.12}.)} \n\n\\istar\\label{exer 8.1.16.5} \nIn this exercise, we shall construct an example of a sequence of random\nvariables that satisfies the weak law of large numbers, but not the strong\nlaw. The distribution of $X_i$ will have to depend on $i$, because\notherwise both laws would be satisfied.  (This problem was communicated to us\nby David Maslen.)\n\\vskip .1in\nSuppose we have an infinite sequence of mutually independent events $A_1,\nA_2, \\ldots$. Let $a_i = P(A_i)$, and let $r$ be a positive integer.\n\n\\begin{enumerate}\n\\item Find an expression of the probability that none of the $A_i$ with\n$i>r$ occur.\n\n\\item Use the fact that $x-1 \\leq e^{-x}$ to show that\n$$\nP(\\mbox{No\\ $A_i$\\ with\\ $i > r$\\ occurs}) \\leq e^{-\\sum_{i=r}^{\\infty}\na_i}\n$$\n\\item (The first Borel-Cantelli lemma)  Prove that if $\\sum_{i=1}^{\\infty} a_i$ diverges, then\n$$\nP(\\mbox{infinitely\\ many\\ $A_i$\\ occur}) = 1.\n$$\n\\vskip .1in\n\\noindent\nNow, let $X_i$ be a sequence of mutually independent random variables such\nthat for each positive integer $i \\geq 2$,\n$$\nP(X_i = i) = \\frac{1}{2i\\log i}, \\quad P(X_i = -i) =\n\\frac{1}{2i\\log i}, \\quad P(X_i =0) = 1 - \\frac{1}{i \\log i}.\n$$\nWhen $i=1$ we let $X_i=0$ with probability $1$.  As usual we let $S_n = X_1\n+ \\cdots + X_n$.  Note that the mean of each $X_i$ is $0$.\n\\item Find the variance of $S_n$.\n\\item Show that the sequence $\\langle X_i \\rangle$ satisfies the Weak\nLaw of Large Numbers, i.e. prove that for any $\\epsilon > 0$\n$$\nP\\biggl(\\biggl|{\\frac{S_n}{n}}\\biggr| \\geq \\epsilon\\biggr) \\rightarrow 0\\ ,\n$$\nas $n$ tends to infinity.\n\\vskip .1in\n\\noindent\nWe now show that $\\{ X_i \\}$ does not satisfy the Strong Law of\nLarge Numbers.  Suppose that $S_n / n \\rightarrow 0$. Then because\n$$\n\\frac{X_n}{n} = \\frac{S_n}{n} - \\frac{n-1}{n} \\frac{S_{n-1}}{n-1}\\ ,\n$$\nwe know that $X_n / n \\rightarrow 0$. From the definition of limits, we\nconclude that the inequality $|X_i| \\geq \\frac{1}{2} i$ can only be\ntrue for finitely many $i$.\n\\item Let $A_i$ be the event $|X_i| \\geq \\frac{1}{2} i$. Find\n$P(A_i)$. Show that $\\sum_{i=1}^{\\infty} P(A_i)$ diverges (use the \nIntegral Test).\n\\item Prove that $A_i$ occurs for infinitely many $i$.\n\\item Prove that \n$$\nP\\biggl(\\frac{S_n}{n} \\rightarrow 0\\biggr) = 0,\n$$\nand hence that the Strong Law of Large Numbers fails for the sequence\n$\\{ X_i \\}$.\n\n\\end{enumerate}\n\\istar\\label{exer 8.1.110} Let us toss a biased coin that comes up heads with probability~$p$\nand assume the validity of the Strong Law of Large Numbers as described\nin Exercise~\\ref{exer 8.1.16}.  Then, with probability~1, $$\n\\frac {S_n}n \\to p\n$$\nas $n \\to \\infty$.  If $f(x)$ is a continuous function on the unit interval,\nthen we also have\n$$\nf\\left( \\frac {S_n}n \\right) \\to f(p)\\ .\n$$\n\nFinally, we could hope that\n$$\nE\\left(f\\left( \\frac {S_n}n \\right)\\right) \\to E(f(p)) = f(p)\\ .\n$$\nShow that, if all this is correct, as in fact it is, we would have proven that\nany continuous function on the unit interval is a limit of polynomial\nfunctions.  This is a sketch of a probabilistic proof of an important theorem \nin mathematics called the \\emx {Weierstrass approximation theorem.}\\index{Weierstrass\nApproximation Theorem}\n\\end{LJSItem}\n\n\n\\choice{}{\\section[Continuous Random Variables]{Law of Large Numbers for Continuous Random\nVariables}\n\\label{sec 8.2}\nIn the previous section we discussed in some detail the Law of Large Numbers\nfor discrete probability distributions.  This law has a natural analogue for\ncontinuous probability distributions, which we consider somewhat more briefly\nhere.\n\n\\subsection*{\\bf Chebyshev Inequality} \\hfill\\break\\index{Chebyshev Inequality}\nJust as in the discrete case, we begin our discussion with the Chebyshev\nInequality.\n\n\\begin{theorem}{\\bf (Chebyshev Inequality)} \\index{Chebyshev Inequality}\nLet $X$ be a continuous random variable with density function $f(x)$.  Suppose $X$ has a \nfinite expected value $\\mu = E(X)$ and finite variance $\\sigma^2 = V(X)$.  Then for any\npositive number $\\epsilon > 0$ we have\n$$\nP(|X - \\mu| \\geq \\epsilon) \\leq \\frac {\\sigma^2}{\\epsilon^2}\\ .\n$$\n\\end{theorem}\n\nThe proof is completely analogous to the proof in the discrete case, and we omit it.\n\\par\nNote that this theorem says nothing if $\\sigma^2 = V(X)$ is infinite.\n\n\n\\begin{example}\nLet $X$ be any continuous random variable with $E(X) = \\mu$ and $V(X) =\n\\sigma^2$.  Then, if $\\epsilon = k\\sigma = k$ standard deviations\nfor some integer~$k$, then\n$$\nP(|X - \\mu| \\geq k\\sigma) \\leq \\frac {\\sigma^2}{k^2\\sigma^2} = \\frac 1{k^2}\\ ,\n$$\njust as in the discrete case.\n\\end{example}\n\n\\subsection*{Law of Large Numbers}\nWith the Chebyshev Inequality we can now state and prove the Law of Large\nNumbers for the continuous case.\n\n\\begin{theorem}{\\bf (Law of Large Numbers)}\\index{Law of Large Numbers}\nLet $X_1$,~$X_2$, \\dots,~$X_n$ be an independent trials process with a\ncontinuous density function~$f$, finite expected value~$\\mu$, and finite\nvariance~$\\sigma^2$.  Let $S_n = X_1 + X_2 +\\cdots+ X_n$ be the sum of the\n$X_i$.  Then for any real number $\\epsilon > 0$ we have\n$$\n\\lim_{n \\to \\infty} P\\left( \\left| \\frac {S_n}n - \\mu \\right| \\geq \\epsilon\n\\right) = 0\\ ,\n$$\nor equivalently,\n$$\n\\lim_{n \\to \\infty} P\\left( \\left| \\frac {S_n}n - \\mu \\right| < \\epsilon\n\\right) = 1\\ .\n$$\n\\end{theorem}\n\nNote that this theorem is not necessarily true if $\\sigma^2$ is infinite\n(see Example~\\ref{exam 8.2.5}).\n\nAs in the discrete case, the Law of Large Numbers says that the average value\nof $n$ independent trials tends to the expected value as $n \\to \\infty$, in the\nprecise sense that, given $\\epsilon > 0$, the probability that the average\nvalue and the expected value differ by more than $\\epsilon$ tends to~0 as $n\n\\to \\infty$.\n\nOnce again, we suppress the proof, as it is identical to the proof in the discrete case.\n\\subsection*{Uniform Case}\n\\begin{example}\nSuppose we choose at random $n$ numbers from the interval $[0,1]$ with\nuniform distribution.  Then if $X_i$ describes the $i$th choice, we have\n\\begin{eqnarray*}\n          \\mu & = & E(X_i) = \\int_0^1 x\\, dx = \\frac 12\\ , \\\\\n     \\sigma^2 & = & V(X_i) = \\int_0^1 x^2\\, dx - \\mu^2 \\\\\n              & = & \\frac 13 - \\frac 14 = \\frac 1{12}\\ .\n\\end{eqnarray*}\nHence,\n\\begin{eqnarray*}\nE \\left( \\frac {S_n}n \\right)  & = & \\frac 12\\ , \\\\\nV \\left( \\frac {S_n}n \\right)  & = & \\frac 1{12n}\\ ,\n\\end{eqnarray*}\nand for any $\\epsilon > 0$,\n$$\nP \\left( \\left| \\frac {S_n}n - \\frac 12 \\right| \\geq \\epsilon \\right) \\leq \\frac\n1{12n \\epsilon^2}\\ .\n$$\n\nThis says that if we choose $n$ numbers at random from $[0,1]$, then the\nchances are better than $1 - 1/(12n\\epsilon^2)$ that the difference $|S_n/n -\n1/2|$ is less than~$\\epsilon$.  Note that $\\epsilon$ plays the role of the\namount of error we are willing to tolerate: If we choose $\\epsilon = 0.1$, say,\nthen the chances that $|S_n/n - 1/2|$ is less than~0.1 are better than $1 -\n100/(12n)$.  For $n = 100$, this is about .92, but if $n = 1000$, this is better\nthan .99 and if $n = 10{,}000$, this is better than .999.\n\\putfig{5.0truein}{PSfig8-2}{Illustration of Law of Large Numbers --- uniform case.}{fig 8.2}\n\nWe can illustrate what the Law of Large Numbers says for this example\ngraphically.  The density for $A_n = S_n/n$ is determined by\n$$\nf_{A_n}(x) = nf_{S_n}(nx)\\ .\n$$\n\nWe have seen in Section~\\ref{sec 7.2}, that we can compute the density\n$f_{S_n}(x)$ for the sum of $n$ uniform random variables.  In Figure~\\ref{fig 8.2} we have\nused this to plot the density for $A_n$ for various values of~$n$.  We have\nshaded in the area for which $A_n$ would lie between .45~and~.55.  We see that as\nwe increase $n$, we obtain more and more of the total area inside the shaded\nregion.  The Law of Large Numbers tells us that we can obtain as much of the\ntotal area as we please inside the shaded region by choosing $n$ large enough\n(see also Figure~\\ref{fig 8.1}).\n\\end{example}\n\n\\subsection*{Normal Case}\n\\begin{example}\nSuppose we choose $n$ real numbers at random,\nusing a normal distribution with mean~0 and variance~1.  Then\n\\begin{eqnarray*}\n         \\mu &=& E(X_i) = 0\\ , \\\\\n    \\sigma^2 &=& V(X_i) = 1\\ .\n\\end{eqnarray*}\nHence,\n\\begin{eqnarray*}\nE \\left( \\frac {S_n}n \\right) &=& 0\\ , \\\\\nV \\left( \\frac {S_n}n \\right) &=& \\frac 1n\\ ,\n\\end{eqnarray*}\nand, for any $\\epsilon > 0$,\n$$\nP\\left( \\left| \\frac {S_n}n - 0 \\right| \\geq \\epsilon \\right) \\leq \\frac\n1{n\\epsilon^2}\\ .\n$$\nIn this case it is possible to compare the Chebyshev estimate for $P(|S_n/n -\n\\mu| \\geq \\epsilon)$ in the Law of Large Numbers with exact values, since we\nknow the density function for $S_n/n$ exactly (see Example~\\ref{exam 7.12}). \nThe comparison is shown in Table~\\ref{table 8.1}, for $\\epsilon = .1$.  The data\nin this table was produced by the program {\\bf LawContinuous}.\\index{LawContinuous (program)}\n\\begin{table}\n\\centering\n\\begin{tabular}{r|r|r}\n$n$ & $P(|S_n/n| \\ge .1)$ & Chebyshev \\\\\n\\hline\n100 & .31731 & 1.00000 \\\\\n200 & .15730 & .50000 \\\\\n300 & .08326 & .33333 \\\\\n400 & .04550 & .25000 \\\\\n500 & .02535 & .20000 \\\\\n600 & .01431 & .16667 \\\\\n700 & .00815 & .14286 \\\\\n800 & .00468 & .12500 \\\\\n900 & .00270 & .11111 \\\\\n1000 & .00157 & .10000 \\\\\n\\hline\n\\end{tabular}\n\\caption{Chebyshev estimates.}\n\\label{table 8.1}\n\\end{table}\nWe see here that the Chebyshev estimates are in general \\emx {not} very \naccurate.\n\\end{example}\n\n\\subsection*{Monte Carlo Method}\nHere is a somewhat more interesting example.\n\n\\begin{example}\nLet $g(x)$ be a continuous function defined for $x \\in [0,1]$ with values in\n$[0,1]$.  In Section~\\ref{sec 2.1}, we showed how to estimate the area of\nthe region under the graph of $g(x)$ by the Monte Carlo method, that is, by\nchoosing a large number of random values for $x$~and~$y$ with uniform\ndistribution and seeing what fraction of the points $P(x,y)$ fell inside the\nregion under the graph (see Example~\\ref{exam 2.1.2}).\n\\par\nHere is a better way to estimate the same area (see Figure~\\ref{fig 8.3}).  Let us choose a\nlarge number of independent values $X_n$ at random from $[0,1]$ with uniform\ndensity, set $Y_n = g(X_n)$, and find the average value of the $Y_n$.  Then\nthis average is our estimate for the area.  To see this, note that if the\ndensity function for~$X_n$ is uniform,\n\\begin{eqnarray*}\n\\mu & = & E(Y_n) = \\int_0^1 g(x) f(x)\\, dx \\\\\n    & = & \\int_0^1 g(x)\\, dx \\\\\n    & = & \\mbox {average\\ value\\ of\\ }  g(x)\\ ,\n\\end{eqnarray*}\nwhile the variance is\n$$\n\\sigma^2 = E((Y_n - \\mu)^2) = \\int_0^1 (g(x) - \\mu)^2\\, dx < 1\\ ,\n$$\nsince for all $x$ in $[0, 1]$, $g(x)$ is in $[0, 1]$, hence $\\mu$ is in $[0, 1]$, and\nso $|g(x) - \\mu| \\le 1$.  Now let $A_n = (1/n)(Y_1 + Y_2 +\\cdots+ Y_n)$.  Then by Chebyshev's\nInequality, we have\n$$\nP(|A_n - \\mu| \\geq \\epsilon) \\leq \\frac {\\sigma^2}{n\\epsilon^2} < \\frac\n1{n\\epsilon^2}\\ .\n$$\n\n\\putfig{3truein}{PSfig8-3}{Area problem.}{fig 8.3} \n\nThis says that to get within $\\epsilon$ of the true value for $\\mu = \\int_0^1\ng(x)\\, dx$ with probability at least $p$, we should choose $n$ so that\n$1/n\\epsilon^2 \\leq 1 - p$ (i.e., so that $n \\geq 1/\\epsilon^2(1 - p)$).  Note\nthat this method tells us how large to take $n$ to get a desired accuracy.\n\\end{example}\n\nThe Law of Large Numbers requires that the variance $\\sigma^2$ of the original\nunderlying density be finite: $\\sigma^2 < \\infty$.  In cases where this fails\nto hold, the Law of Large Numbers may fail, too.  An example follows.\n\n\\subsection*{Cauchy Case}\n\\begin{example}\\label{exam 8.2.5}\nSuppose we choose $n$ numbers from $(-\\infty,+\\infty)$ with a Cauchy density\nwith parameter $a = 1$.  We know that for the Cauchy density the expected value\nand variance are undefined (see Example~\\ref{exam 6.23}).  In this case, the\ndensity function for\n$$\nA_n = \\frac {S_n}n\n$$\nis given by (see Example~\\ref{exam 7.9})\n$$\nf_{A_n}(x) = \\frac 1{\\pi(1 + x^2)}\\ ,\n$$\nthat is, \\emx {the density function for $A_n$ is the same for all $n$.}  In this\ncase, as $n$ increases, the density function does not change at all, and the\nLaw of Large Numbers does not hold.\n\\end{example}\n\n\\exercises\n\\begin{LJSItem}\n\n\\i\\label{exer 8.2.1} Let $X$ be a continuous random variable with mean $\\mu =\n10$ and variance $\\sigma^2 = 100/3$.  Using Chebyshev's Inequality, find an upper\nbound for the following probabilities.\n\\begin{enumerate}\n\\item $P(|X - 10| \\geq 2)$.\n\n\\item $P(|X - 10| \\geq 5)$.\n\n\\item $P(|X - 10| \\geq 9)$.\n\n\\item $P(|X - 10| \\geq 20)$.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.2} Let $X$ be a continuous random variable with values\nunformly distributed over the interval $[0,20]$.\n\\begin{enumerate}\n\\item Find the mean and variance of $X$.\n\n\\item Calculate $P(|X - 10| \\geq 2)$, $P(|X - 10| \\geq 5)$, $P(|X - 10| \\geq\n9)$, and $P(|X - 10| \\geq 20)$ exactly.  How do your answers compare with those\nof Exercise~\\ref{exer 8.2.1}?  How good is Chebyshev's Inequality in this case?\n\\end{enumerate}\n\n\\i\\label{exer 8.2.3} Let $X$ be the random variable of Exercise~\\ref{exer\n8.2.2}.\n\\begin{enumerate}\n\\item Calculate the function $f(x) = P(|X - 10| \\geq x)$.\n\n\\item Now graph the function $f(x)$, and on the same axes, graph the\nChebyshev function $g(x) = 100/(3x^2)$.  Show that $f(x) \\leq g(x)$ for all~$x >\n0$, but that $g(x)$ is not a very good approximation for~$f(x)$.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.100} Let $X$ be a continuous random variable with values exponentially\ndistributed over $[0,\\infty)$ with parameter $\\lambda = 0.1$.\n\\begin{enumerate}\n\\item Find the mean and variance of $X$.\n\n\\item Using Chebyshev's Inequality, find an upper bound for the following\nprobabilities: $P(|X - 10| \\geq 2)$, $P(|X - 10| \\geq 5)$, $P(|X - 10| \\geq\n9)$, and $P(|X - 10| \\geq 20)$.\n\n\\item Calculate these probabilities exactly, and compare with the bounds in\n(b).\n\\end{enumerate}\n\\i\\label{exer 8.2.101} Let $X$ be a continuous random variable with values normally\ndistributed over $(-\\infty,+\\infty)$ with mean $\\mu = 0$ and variance $\\sigma^2 = 1$.\n\\begin{enumerate}\n\\item Using Chebyshev's Inequality, find upper bounds for the following\nprobabilities: $P(|X| \\geq 1)$, $P(|X| \\geq 2)$, and $P(|X| \\geq 3)$.\n\n\\item The area under the normal curve between $-1$~and~1 is .6827, between\n$-2$~and~2 is .9545, and between $-3$~and~3 it is .9973 (see the table in\nAppendix~A).  Compare your bounds in (a) with\nthese exact values.  How good is Chebyshev's Inequality in this case?\n\\end{enumerate}\n\n\\i\\label{exer 8.2.102} If $X$ is normally distributed, with mean~$\\mu$ and\nvariance~$\\sigma^2$, find an upper bound for the following probabilities, using Chebyshev's\nInequality.\n\\begin{enumerate}\n\\item $P(|X - \\mu| \\geq \\sigma)$.\n\n\\item $P(|X - \\mu| \\geq 2\\sigma)$.\n\n\\item $P(|X - \\mu| \\geq 3\\sigma)$.\n\n\\item $P(|X - \\mu| \\geq 4\\sigma)$.\n\\end{enumerate}\n\\noindent Now find the exact value using the program {\\bf NormalArea}\\index{NormalArea (program)}\nor the normal table in Appendix~A, and compare.\n\n\\i\\label{exer 8.2.103} If $X$ is a random variable with mean~$\\mu \\ne 0$ and variance~$\\sigma^2$,\ndefine the \\emx {relative deviation} $D$ of $X$ from its mean by\n$$\nD = \\left| \\frac {X - \\mu}\\mu \\right|\\ .\n$$\n\\begin{enumerate}\n\\item Show that $P(D \\geq a) \\leq \\sigma^2/(\\mu^2a^2)$.\n\n\\item If $X$ is the random variable of Exercise~\\ref{exer 8.2.1}, find an\nupper bound for $P(D \\geq .2)$, $P(D \\geq .5)$, $P(D \\geq .9)$, and $P(D \\geq\n2)$.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.104} Let $X$ be a continuous random variable and define the {\\em\nstandardized version} $X^*$ of~$X$ by:\n$$\nX^* = \\frac {X - \\mu}\\sigma\\ .\n$$\n\\begin{enumerate}\n\\item Show that $P(|X^*| \\geq a) \\leq 1/a^2$.\n\n\\item If $X$ is the random variable of Exercise~\\ref{exer 8.2.1}, find\nbounds for $P(|X^*| \\geq 2)$, $P(|X^*| \\geq 5)$, and $P(|X^*| \\geq 9)$.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.105}\n\\begin{enumerate} \n\\item Suppose a number $X$ is chosen at random from $[0,20]$ with uniform\nprobability.  Find a lower bound for the probability that $X$ lies between\n8~and~12, using Chebyshev's Inequality.\n\n\\item Now suppose 20 real numbers are chosen independently from $[0,20]$\nwith uniform probability.  Find a lower bound for the probability that their\naverage lies between 8~and~12.\n\n\\item Now suppose 100 real numbers are chosen independently from\n$[0,20]$.  Find a lower bound for the probability that their average lies\nbetween 8~and~12.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.106} A student's score on a particular calculus final is a random variable\nwith values of $[0,100]$, mean~70, and variance~25.\n\\begin{enumerate}\n\\item Find a lower bound for the probability that the student's score will\nfall between 65~and~75.\n\n\\item If 100 students take the final, find a lower bound for the probability\nthat the class average will fall between 65~and~75.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.107} The Pilsdorff beer company runs a fleet of trucks along the 100~mile\nroad from Hangtown to Dry Gulch, and maintains a garage halfway in between. \nEach of the trucks is apt to break down at a point $X$~miles from Hangtown,\nwhere $X$ is a random variable uniformly distributed over $[0,100]$.\n\\begin{enumerate}\n\\item Find a lower bound for the probability $P(|X - 50| \\leq 10)$.\n\n\\item Suppose that in one bad week, 20 trucks break down.  Find a lower bound\nfor the probability $P(|A_{20} - 50| \\leq 10)$, where $A_{20}$ is the average\nof the distances from Hangtown at the time of breakdown.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.12} A share of common stock in the Pilsdorff beer company\nhas a price $Y_n$ on the $n$th business day of the year.  Finn observes that the\nprice change $X_n = Y_{n + 1} - Y_n$ appears to be a random variable with mean\n$\\mu = 0$ and variance $\\sigma^2 =1/4$.  If $Y_1 = 30$, find a lower bound for\nthe following probabilities, under the assumption that the $X_n$'s are mutually independent.\n\\begin{enumerate}\n\\item $P(25 \\leq Y_2 \\leq 35)$.\n\n\\item $P(25 \\leq Y_{11} \\leq 35)$.\n\n\\item $P(25 \\leq Y_{101} \\leq 35)$.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.108} Suppose one hundred numbers $X_1$,~$X_2$, \\dots,~$X_{100}$ are chosen\nindependently at random from $[0,20]$.  Let $S = X_1 + X_2 +\\cdots+ X_{100}$\nbe the sum, $A = S/100$ the average, and $S^* = (S - 1000)/(10/\\sqrt3)$ the\nstandardized sum.  Find lower bounds for the probabilities\n\\begin{enumerate}\n\\item $P(|S - 1000| \\leq 100)$.\n\n\\item $P(|A - 10| \\leq 1)$.\n\n\\item $P(|S^*| \\leq \\sqrt3)$.\n\\end{enumerate}\n\n\\i\\label{exer 8.2.14} Let $X$ be a continuous random variable normally\ndistributed on $(-\\infty,+\\infty)$ with mean~0 and variance~1.  Using the normal\ntable provided in Appendix~A, or the program {\\bf NormalArea},\nfind values for the function $f(x) = P(|X| \\geq x)$ as $x$ increases from\n0~to~4.0 in steps of~.25.  Note that for $x \\geq 0$ the table gives\n$ NA(0,x) = P(0 \\leq X \\leq x)$ and thus $P(|X| \\geq x) = 2(.5 - NA(0,x)$.\nPlot by hand\nthe graph of~$f(x)$ using these values, and the graph of the Chebyshev function\n$g(x) = 1/x^2$, and compare (see Exercise~\\ref{exer 8.2.3}).\n\n\\i\\label{exer 8.2.109} Repeat Exercise~\\ref{exer 8.2.14}, but this time with mean~10 and\nvariance~3.  Note that the table in Appendix~A presents values for\na standard normal variable.  Find the standardized version $X^*$ for~$X$, find\nvalues for $f^*(x) = P(|X^*| \\geq x)$ as in Exercise~\\ref{exer 8.2.14}, and\nthen rescale these values for $f(x) = P(|X -10| \\geq x)$.  Graph and compare\nthis function with the Chebyshev function $g(x) = 3/x^2$.\n\n\\i\\label{exer 8.2.110} Let $Z = X/Y$ where $X$~and~$Y$ have normal densities with mean~0 and\nstandard deviation~1.  Then it can be shown that $Z$ has a Cauchy density.\n\\begin{enumerate}\n\\item Write a program to illustrate this result by plotting a bar graph of\n1000 samples obtained by forming the ratio of two standard normal outcomes. \nCompare your bar graph with the graph of the Cauchy density.  Depending upon which\ncomputer language you use, you may or may not need to tell the computer how to simulate a\nnormal random variable.  A method for doing this was described in Section~\\ref{sec 5.2}.\n\n\\item We have seen that the Law of Large Numbers does not apply to the\nCauchy density (see Example~\\ref{exam 8.2.5}).  Simulate a large number of\nexperiments with Cauchy density and compute the average of your results.  Do\nthese averages seem to be approaching a limit?  If so can you explain why this\nmight be?\n\\end{enumerate}\n\n\\i\\label{exer 8.2.111} Show that, if $X \\geq 0$, then $P(X \\geq a) \\leq E(X)/a$.\n\n\\i\\label{exer 8.2.112} (Lamperti\\footnote{Private communication.})\n\\index{LAMPERTI, J.} Let $X$ be a non-negative random\nvariable.  What is the best upper bound you can give for $P(X \\geq a)$ if you know\n\\begin{enumerate}\n\\item $E(X) = 20$.\n\n\\item $E(X) = 20$ and $V(X) = 25$.\n\n\\item $E(X) = 20$, $V(X) = 25$, and $X$ is symmetric about its mean.\n\\end{enumerate}\n\\end{LJSItem}}\n", "meta": {"hexsha": "e2a60717cde521ff635d9071646b40218de2c650", "size": 39955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ch8.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/ch8.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/ch8.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": 42.6414087513, "max_line_length": 99, "alphanum_fraction": 0.6983356276, "num_tokens": 13259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6513275025519374}}
{"text": "\n\\documentclass[12pt]{article}\n\\usepackage{amsfonts}\n\\usepackage{graphicx}\n\n\\newcommand{\\real}{{\\rm Re}}\n\\newcommand{\\imag}{{\\rm Im}}\n\n\\begin{document}\n\nThis document explains the history of the DeltaPA class that is the basis for the {\\tt rmfit -r}\nFaraday Rotation Measure refinement algorithm.  Two versions of the algorithm were implemented:\n%\n\\begin{itemize}\n\\item Mark I - computes the phase of the complex-valued cross-correlation between Stokes $Q+iU$ profiles\n\\item Mark II - computes the phase of the inverse-variance weighted cross-correlation\n\\end{itemize}\n\nThe Mark I algorithm was first implemented in September 2006.   On 26 July 2007, the Mark II algorithm\nreplaced it.   On 6 April 2019, the code was reverted to Mark I after discovering a fundamental problem\nwith the Mark II algorithm, as explained in Sections 2 and 3 of this document.\n\n\\section{Mean value of position angle change \\\\ Mark I }\n\nThis section documents the propagation of error when estimating the\nchange in position angle, $\\Delta\\Psi$, between two polarization\nprofiles using the Mark I version of the algorithm implemented by {\\tt rmfit -r}.\n%\nLet\n\\begin{equation}\nP_k = Q_k + i U_k = L_k \\exp i2\\Psi_k\n\\end{equation}\nrepresent the linear polarization of the $k$th phase bin in one profile and\n\\begin{equation}\nP^\\prime_k = Q^\\prime_k + i U^\\prime_k = L^\\prime_k \\exp i2\\Psi^\\prime_k\n\\end{equation}\nthe same in the other profile.  To find the mean value of $\\Delta\\Psi$,\n\\begin{equation}\n\\bar\\Psi = {1\\over N}\\sum_{k=1}^N \\Psi^\\prime_k - \\Psi_k\n\\end{equation}\nuse the cross-correlation\n\\begin{equation}\nZ = \\sum_{k=1}^N P^*_k P^\\prime_k \n  = \\sum_{k=1}^N L_k L^\\prime_k \\exp i2(\\Psi^\\prime_k - \\Psi_k)\n\\end{equation}\nsuch that\n\\begin{equation}\n\\bar\\Psi\n={1\\over2}\\tan^{-1}\\left({\\imag[Z]\\over\\real[Z]}\\right).\n\\end{equation}\nThe variance of this estimate\n\\begin{equation}\n\\sigma_{\\bar\\Psi}^2 = \\sum_{k=1}^N \n\\left({\\partial\\bar\\Psi\\over\\partial Q_k}\\right)^2 \\sigma_Q^2 +\n\\left({\\partial\\bar\\Psi\\over\\partial U_k}\\right)^2 \\sigma_U^2 +\n\\left({\\partial\\bar\\Psi\\over\\partial Q^\\prime_k}\\right)^2 \\sigma_Q^{\\prime2} +\n\\left({\\partial\\bar\\Psi\\over\\partial U^\\prime_k}\\right)^2 \\sigma_U^{\\prime2}.\n\\label{eqn:var_Psi}\n\\end{equation}\nTo compute the partial derivatives, let\n\\begin{equation}\nC = \\real[Z] = \\sum_{k=1}^N Q_kQ^\\prime_k + U_kU^\\prime_k,\n\\label{eqn:real_Z}\n\\end{equation}\n\\begin{equation}\nS = \\imag[Z] = \\sum_{k=1}^N Q_kU^\\prime_k - Q^\\prime_kU_k,\n\\label{eqn:imag_Z}\n\\end{equation}\nand\n\\begin{equation}\nT = {S\\over C},\n\\end{equation}\nso that\n\\begin{equation}\n{\\partial\\bar\\Psi\\over\\partial Q_k} \n= {1\\over1+T^2} \\left( {U^\\prime_k \\over C} - {S Q^\\prime_k\\over C^2} \\right)\n= { C U^\\prime_k - S Q^\\prime_k \\over C^2 + S^2 }\n\\end{equation}\nSimilarly\n\\begin{equation}\n{\\partial\\bar\\Psi\\over\\partial U_k} \n= { -C Q^\\prime_k - S U^\\prime_k \\over C^2 + S^2 }\n\\end{equation}\n\\begin{equation}\n{\\partial\\bar\\Psi\\over\\partial Q^\\prime_k} \n= { -C U_k - S Q_k \\over C^2 + S^2 }\n\\end{equation}\n\\begin{equation}\n{\\partial\\bar\\Psi\\over\\partial U^\\prime_k} \n= { C Q_k - S U_k \\over C^2 + S^2 }\n\\end{equation}\n\nThe above equations have been tested over a range of signal to noise ratios, as shown in \nFigures~\\ref{fig:mark1_error} and~\\ref{fig:mark1_error_ratio}.  Everything looks good, except\ndown at low $S/N < 10$.\n\n\\begin{figure}\n\\centerline{\\includegraphics[angle=-90,width=100mm]{plots/mark1_error.eps}}\n\\caption{\\label{fig:mark1_error}\nStandard deviation of 2500 RM estimates $\\sigma_\\mathrm{RM}$ as a function of signal-to-noise ratio $S/N$\nusing the Mark I implementation of RM refinement.  As expected, the noise scales as $(S/N)^{-1}$, as indicated\nby the dashed line with a slope of -1.}\n\\end{figure}\n\n\\begin{figure}\n\\centerline{\\includegraphics[angle=-90,width=100mm]{plots/mark1_error_ratio.eps}}\n\\caption{\\label{fig:mark1_error_ratio}\nRatio between the mean estimated uncertainty $\\epsilon_\\mathrm{RM}$ and the standard deviation of 2500 RM estimates $\\sigma_\\mathrm{RM}$ as a function of signal-to-noise ratio $S/N$\nusing the Mark I implementation of RM refinement.  As expected, the ratio is approximately unity, as indicated\nby the dashed line.}\n\\end{figure}\n\n\\section{Mean value of position angle change \\\\ Mark II}\n\nThis section documents the Mark II algorithm for estimating the change in\nposition angle, $\\Delta\\Psi$, and its uncertainty.  As before, let\n\\begin{equation}\nP_k = Q_k + i U_k = L_k \\exp i2\\Psi_k\n\\end{equation}\nrepresent the linear polarization of the $k$th phase bin in one profile and\n\\begin{equation}\nP^\\prime_k = Q^\\prime_k + i U^\\prime_k = L^\\prime_k \\exp i2\\Psi^\\prime_k\n\\end{equation}\nthe same in the other profile.  \n\nConsider the {\\bf weighted} cross-correlation,\n$\\bar{Z}=\\bar{C}+i\\bar{S}$, where $\\bar C$ and $\\bar S$ are the\nweighted mean values of the real and imaginary components of\n\\begin{equation}\nz_k = c_k + i s_k \n    = P^*_k P^\\prime_k = L_k L^\\prime_k \\exp i2(\\Psi^\\prime_k - \\Psi_k).\n\\end{equation}\nThat is, where\n\\begin{equation}\nc_k = Q_kQ^\\prime_k + U_kU^\\prime_k,\n\\hspace{1cm}\ns_k = Q_kU^\\prime_k - U_kQ^\\prime_k,\n\\label{eqn:ck_sk}\n\\end{equation}\nand\n\\begin{eqnarray}\n\\sigma_{c_k}^2 & = &\n Q^{\\prime2}_k\\sigma_{Q_k}^2 + U^{\\prime2}_k\\sigma_{U_k}^2 +\n Q^2_k\\sigma_{Q^\\prime_k}^2 + U^2_k\\sigma_{U^\\prime_k}^2 \\label{eqn:var_ck} \\\\\n\\sigma_{s_k}^2 & = &\n U^{\\prime2}_k\\sigma_{Q_k}^2 + Q^{\\prime2}_k\\sigma_{U_k}^2 +\n U^2_k\\sigma_{Q^\\prime_k}^2 + Q^2_k\\sigma_{U^\\prime_k}^2 \\label{eqn:var_sk} \\\\\n\\sigma_{s_k c_k} & = &\n Q^\\prime_k U^\\prime_k (\\sigma_{Q_k}^2 - \\sigma_{U_k}^2) +\n Q_kU_k (\\sigma_{U^\\prime_k}^2 -\\sigma_{Q^\\prime_k}^2)\n\\label{eqn:covar_ck_sk}\n\\end{eqnarray}\nthe weighted means and their variances and covariance are given by\n\\begin{equation}\n\\bar C = \\sigma_{\\bar C}^2 \\sum_{k=1}^N { c_k \\over \\sigma_{c_k}^2 }\n\\hspace{1cm}\n\\bar S = \\sigma_{\\bar S}^2 \\sum_{k=1}^N { s_k \\over \\sigma_{s_k}^2 }\n\\label{eqn:barC_barS}\n\\end{equation}\nand\n\\begin{equation}\n\\sigma_{\\bar C}^2 = \\left[ \\sum_{k=1}^N{1\\over\\sigma_{c_k}^2} \\right]^{-1}\n\\hspace{5mm}\n\\sigma_{\\bar S}^2 = \\left[ \\sum_{k=1}^N{1\\over\\sigma_{s_k}^2} \\right]^{-1}\n\\hspace{5mm}\n\\sigma_{\\bar S \\bar C} = \\sum_{k=1}^N\n\\left[\\sigma_{\\bar S}\\sigma_{\\bar C}\\over\\sigma_{s_k}\\sigma_{c_k}\\right]^2\n                         \\sigma_{s_k c_k}\n\\label{eqn:var_covar_barC_barS}\n\\end{equation}\n\n\\noindent\nThe expectation value of $\\Delta\\Psi=\\Psi^\\prime_k - \\Psi_k$ is given by\n\\begin{equation}\n\\langle\\Delta\\Psi\\rangle\n={1\\over2}\\tan^{-1}\\left({\\bar S\\over\\bar C}\\right).\n\\end{equation}\nand the variance of the expectation value\n\\begin{equation}\n{\\mathrm{var}}(\\langle\\Delta\\Psi\\rangle) = \n{ \\bar C^2\\sigma_{\\bar S}^2 + \\bar S^2\\sigma_{\\bar C}^2\n  + 2 \\bar S\\bar C \\sigma_{\\bar S \\bar C} \\over \n  \\left(\\bar C^2 + \\bar S^2\\right)^2 }\n\\label{eqn:var_delta_Psi}\n\\end{equation}\n\nThe above equations have been tested over a range of signal to noise ratios, as shown in\nFigures~\\ref{fig:mark2_error} and~\\ref{fig:mark2_error_ratio}.  These plots show that\nthe Mark II algorithm\n\n\\begin{enumerate}\n\\item slightly underestimates the uncertainty of $RM$ estimates; and \n\\item more importantly, fails to exploit $S/N$ as expected.\n\\end{enumerate}\n\n\\begin{figure}\n\\centerline{\\includegraphics[angle=-90,width=100mm]{plots/mark2_error.eps}}\n\\caption{\\label{fig:mark2_error}\nStandard deviation of 2500 RM estimates $\\sigma_\\mathrm{RM}$ as a function of signal-to-noise ratio $S/N$\nusing the Mark II implementation of RM refinement.  The dashed line has a slope of -1, as expected when\nthe error scales as $(S/N)^{-1}$.  The Mark II algorithm clearly fails to produce estimates with the expected\nuncertainty; at the highest $S/N$, the standard deviation is over ten times the predicted value.}\n\\end{figure}\n\n\\begin{figure}\n\\centerline{\\includegraphics[angle=-90,width=100mm]{plots/mark2_error_ratio.eps}}\n\\caption{\\label{fig:mark2_error_ratio}\nRatio between the mean estimated uncertainty $\\epsilon_\\mathrm{RM}$ and the standard deviation of 2500 RM estimates $\\sigma_\\mathrm{RM}$ as a function of signal-to-noise ratio $S/N$\nusing the Mark II implementation of RM refinement.  The dashed line indicates the expected ratio of unity;\nthe Mark II algorithm tends to underestimate uncertainty.}\n\\end{figure}\n\n\n\\section{The Problem With Mark II}\n\nConsider the special case when the two profiles are identical,\ni.e. $P_k^\\prime = P_k$, with equal noise in all Stokes parameters, \ni.e. $\\sigma_{Q_k}=\\sigma_{U_k}=\\sigma_{Q^\\prime_k}=\\sigma_{U^\\prime_k}=\\sigma$.\nIn this case, referring to Equations~\\ref{eqn:var_ck} to~\\ref{eqn:covar_ck_sk},\n$\\sigma^2_{c_k}=\\sigma^2_{s_k}=2\\sigma^2 L_k^2$ and $\\sigma_{s_k c_k}=0$.\n%\nReferring to Equation \\ref{eqn:var_covar_barC_barS}, the variance of the weighted\nmean cosine and sine,\n\\begin{equation}\n\\sigma_{\\bar C}^2 = \\sigma_{\\bar S}^2 = 2\\sigma^2 \\left[ \\sum_{k=1}^N{1\\over L_k^2} \\right]^{-1}.\n\\end{equation}\n%\nSubstitution of the above into Equation~\\ref{eqn:barC_barS} yields\n\\begin{equation}\n\\bar C = \\sum_{k=1}^N { c_k \\over L_k^2 } \\left[ \\sum_{k=1}^N { 1 \\over L_k^2 } \\right]^{-1}\n\\hspace{1cm}\n\\bar S = \\sum_{k=1}^N { s_k \\over L_k^2 } \\left[ \\sum_{k=1}^N { 1 \\over L_k^2 } \\right]^{-1}\n\\end{equation}\n\nAlready, the problem is apparent.  The above equations represent weighted averages in which each cross-correlation\n$c_k$ and $s_k$ are weighted by the {\\bf inverse} of the linearly polarized flux $L^2$.  Such a weighted average\ngives less weight to the samples with greater linearly polarized flux!  This is opposite to what is intended,\nand is a consqeuence of sticking too blindly to the rules of first-order linear error propagation.\n\nAlso, in the special case that $P_k^\\prime = P_k$, then (referring to Equation~\\ref{eqn:ck_sk}) \n$c_k=L^2$, $s_k=0$, $\\bar S = 0$, and\n\\begin{equation}\n\\bar C = N \\left[ \\sum_{k=1}^N{1\\over L_k^2} \\right]^{-1}.\n\\end{equation}\n%\nFinally, plugging everything into Equation~\\ref{eqn:var_delta_Psi} yields\n\\begin{equation}\n{\\mathrm{var}}(\\langle\\Delta\\Psi\\rangle) = 2 {\\sigma^2 \\over N^2} \\sum_{k=1}^N{1\\over L_k^2}.\n\\end{equation}\n%\nAt first glance, it may seem reasonable that the variance of the weighted mean position angle change\nshould be inversely proportional to the square of the linearly polarized flux.  However, it is proportional\nto the sum of terms that are inversely proportional to the square of the linearly polarized flux.\nAdding more detectable phase bins increases $N$ (thereby decreasing the variance, as expected) but also adds more terms \nto this sum (thereby {\\bf increasing} the variance!)\n\nBy increasing the $S/N$, we increase each of the $L_k$ terms and decrease the variance of the weighted mean position angle change; however, we also increase the number of phase bins that are detected above the noise and increase the sum in the above equation.  This effect stops the standard deviation of RM estimates from scaling as one over $S/N$.  \n\n\\subsubsection{Revisiting the Mark I Implementation}\n\nAs written, it is not possible to compute the sums in Equations~\\ref{eqn:var_Psi}\nthrough~\\ref{eqn:imag_Z} in a single loop.  After grouping like terms,\n%\n\\begin{equation}\n\\sigma_{\\bar\\Psi}^2 =\n(C^2+S^2)^{-2} \\left(C^2 \\sigma_S^2 + S^2 \\sigma_C^2 - 2 CS \\sigma_{CS} \\right)\n\\label{eqn:var_Psi_simplified}\n\\end{equation}\n%\nwhere\n\\begin{equation}\n\\sigma_C^2 = \\sum_{k=1}^N \\sigma_{c_k}^2\n\\hspace{5mm}\n\\sigma_S^2 = \\sum_{k=1}^N \\sigma_{s_k}^2 \n\\hspace{5mm}\n\\sigma_{CS} = \\sum_{k=1}^N \\sigma_{s_k c_k}\n\\label{eqn:var_covar_C_S}\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "ce1421b70ed6fccceb107a1da3b2856c368ae164", "size": 11432, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "More/Polarimetry/DeltaPA.tex", "max_stars_repo_name": "rossjjennings/psrchive", "max_stars_repo_head_hexsha": "745a59741b56a2f4c1ba9648665dc0e528368f69", "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": "More/Polarimetry/DeltaPA.tex", "max_issues_repo_name": "rossjjennings/psrchive", "max_issues_repo_head_hexsha": "745a59741b56a2f4c1ba9648665dc0e528368f69", "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": "More/Polarimetry/DeltaPA.tex", "max_forks_repo_name": "rossjjennings/psrchive", "max_forks_repo_head_hexsha": "745a59741b56a2f4c1ba9648665dc0e528368f69", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-13T20:08:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T20:08:14.000Z", "avg_line_length": 40.6832740214, "max_line_length": 351, "alphanum_fraction": 0.7204338698, "num_tokens": 3860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6510818760849876}}
{"text": "%!TEX root = ./jctt.tex\n\n\\newcommand{\\rell}{^\\ell} % raise to ellth power \n\\newcommand{\\relll}{^{\\ell+1}} % raise to ell + 1 th power \n\\newcommand{\\rellh}{^{\\ell+1/2}} % raise to ell + 1/2 power\n\n\\newcommand{\\paren}[1]{\\left(#1\\right)} \n\\newcommand{\\br}[1]{\\left[#1\\right]}\n\\newcommand{\\curl}[1]{\\left\\{#1\\right\\}}\n\n\\newcommand{\\eddphi}[1]{\\edd_{#1}\\phi_{#1}}\n\\newcommand{\\ALPHA}[2]{\\frac{#1}{\\sigma_{t,#2} h_{#2}}}\n\n\\section{The VEF Method}\n\\subsection{The Algorithm}\nHere, we describe the VEF method for a planar geometry, fixed-source problem:\n\\change{\n\t\\begin{equation} \n\t\t\\mu \\pderiv{\\psi}{x} \\paren{x, \\mu} + \\sigma_t(x) \\psi(x,\\mu) = \n\t\t\t\\frac{\\sigma_s(x)}{2} \\phi(x) + \\frac{Q(x)}{2} \\,,\n\t\\end{equation}\nwhere $\\mu$ is the $x$--axis cosine of the direction of neutron flow,  $\\sigma_t(x)$ and $\\sigma_s(x)$ are the total and scattering macroscopic cross sections, $Q(x)$ is the isotropic fixed-source and $\\psi(x, \\mu)$ is the angular flux,\nand $\\phi(x)$ is the scalar flux:\n\\begin{equation}\n\\phi(x) = \\int_{-1}^1 \\psi(x,\\mu') \\ud \\mu' \\,.\n\\end{equation}\n}\nApplying the Discrete Ordinates (\\SN) angular discretization yields the following set of $N$ coupled, ordinary differential equations: \n\t\\begin{equation} \\label{eq:sn}\n\t\t\\mu_n \\dderiv{\\psi_n}{x}(x) + \\sigma_t(x) \\psi_n(x) = \n\t\t\\frac{\\sigma_s(x)}{2} \\phi(x) + \\frac{Q(x)}{2} \\,, \\quad 1 \\leq n \\leq N \\,,\n\t\\end{equation}\nwhere $\\psi_n(x) = \\psi(x, \\mu_n)$ is the angular flux due to neutrons with directions in the cone defined by $\\mu_n$.  The $\\mu_n$ are given by an $N$-point Gauss quadrature rule such that the scalar flux is numerically integrated as follows: \n\t\\begin{equation} \\label{eq:phiquad}\n\t\t\\phi(x) = \\sum_{n=1}^N w_n \\psi_n(x) \\,,\n\t\\end{equation}\nwhere $w_n$ is the quadrature weight corresponding to $\\mu_n$. \n\nThe VEF method begins by solving Eq.~\\ref{eq:sn} while lagging the scattering source.  This is called a Source Iteration (SI), \nand is represented as follows:\n\t\\begin{equation} \\label{eq:si}\n\t\t\\mu_n \\dderiv{}{x}\\psi_n\\rellh(x) + \\sigma_t(x) \\psi_n\\rellh(x) = \n\t\t\\frac{\\sigma_s(x)}{2} \\phi^\\ell(x) + \\frac{Q(x)}{2} \\,, \\quad 1 \\leq n \\leq N \\,,\n\t\\end{equation}\nwhere $\\ell$ is the iteration index.  The scalar flux used in the scattering source, $\\phi\\rell$, is assumed to be known either from the previous iteration or from the initial guess if $\\ell=0$.  The use of a half-integral index indicates that SI is the first of a two-step iteration scheme.  If one is only doing SI without acceleration, the second step would simply be to set the final scalar flux iterate to the iterate after the source iteration: \n\t\\begin{equation} \\label{eq:siupdate}\n\t\t\\phi(x)\\relll = \\phi(x)\\rellh \\,.\n\t\\end{equation}\nHowever, SI is slow to converge in optically thick and highly scattering systems. This is the motivation for accelerating \nSI using the VEF method.  \n\nThe second iterative step of the VEF method is to obtain a final ``accelerated'' iterate for \nthe scalar flux by solving the VEF drift-diffusion equation using angular flux shape information from the source iteration step:\n\\begin{equation} \\label{eq:drift}\n-\\dderiv{}{x} \\frac{1}{\\sigma_t(x)} \\dderiv{}{x} \\bracket{\\edd\\rellh(x)\\phi\\relll(x)} + \\sigma_a(x) \\phi\\relll(x) = Q(x) \\,,\n\\end{equation}\nwhere the Eddington factor is given by\n\\begin{equation} \\label{eq:eddington} \n\t\t\\edd\\rellh(x) = \\frac{\\int_{-1}^1 \\mu^2 \\psi\\rellh(x, \\mu) \\ud \\mu}{\\int_{-1}^1 \\psi\\rellh(x, \\mu) \\ud \\mu} \\, .\n\t\\end{equation}\n\\change{While transport-consistent boundary conditions must be defined for Eq. \\ref{eq:drift}, there is not a unique way to do this. Thus, we postpone discussion of the boundary conditions to Sec. 2.3.}\nNote that the Eddington factor depends only upon the angular shape of the angular flux, and not its magnitude.  This drift-diffusion equation is derived by first taking the first two angular moments of Eq.~\\ref{eq:sn}: \n\t\\begin{subequations} \n\t\\begin{equation} \\label{eq:zero}\n\t\t\\dderiv{}{x} J (x) + \\sigma_a(x) \\phi(x) = Q(x) \\,,\n\t\\end{equation} \n\t\\begin{equation} \\label{eq:first}\n\t\t\\dderiv{}{x} \\bracket{\\edd(x) \\phi (x)} + \\sigma_t(x) J(x) = 0 \\,,\n\t\\end{equation}\n\t\\end{subequations}\n% added isotropic part since the MMS solution uses a non-isotropic source (removed JEM 11-18-17) \n% added current definition since it was never defined.\n\\change{where $J(x)$ is the current:\n \\begin{equation}\n J(x) = \\int_{-1}^1 \\mu' \\psi(x,\\mu')  \\ud \\mu' \\,.\n \\end{equation}}\nThen Eq.~\\ref{eq:first} is solved for $J(x)$, and this expression is then substituted into\nEq.~\\ref{eq:zero}. \nPerforming a SI, computing the Eddington factor from the SI angular flux iterate, and then solving \nthe drift-diffusion equation to obtain a new scalar flux iterate completes one accelerated iteration. These iterations \nare repeated until convergence of the scalar flux at step $\\ell+1$ is achieved.  The fluxes at steps $\\ell+1/2$ and $\\ell+1$ will \nindividually converge, but not necessarily to each other unless the \\SN and drift-diffusion equations are consistently \ndifferenced or the spatial truncation error is negligible.\n\nAcceleration occurs because the angular shape of the angular flux, and thus the Eddington factor, converges much faster than the scalar flux. In addition, the solution of the drift-diffusion equation includes scattering. This inclusion compensates for lagging \nthe scattering source in the SI step.  \n\nThe VEF method allows the \\SN equations and drift-diffusion equations to be solved with arbitrarily different spatial discretization methods. The following sections  present the application of the Lumped Linear Discontinuous Galerkin (LLDG) spatial discretization to the \\SN equations and the constant-linear Mixed Finite-Element Method (MFEM) to the VEF drift-diffusion equation. \n\n\\subsection{Lumped Linear Discontinuous Galerkin \\SN}\n\\begin{figure}\n\t\\centering\n\t\\input{figs/lldg.pdf_tex}\n\t\\caption{The distribution of unknowns within an LLDG cell. The superscript $+$ and $-$ indicate the angular fluxes for $\\mu_n>0$ and $\\mu_n<0$, respectively. } \n\t\\label{fig:lldg_grid}\n\\end{figure}\nThe spatial grid and distribution of unknowns for an LLDG cell are shown in Fig.~\\ref{fig:lldg_grid}. We assume a computational domain of length $x_b$ discretized into $I$ cells. The indices for cell centers are integral and the indices for cell edges are half integral. \nThe two unknowns for discrete angle $\\mu_n$ within cell $i$ are the left and right angular fluxes, $\\psi_{n,i,L}\\rellh$ and $\\psi_{n,i,R}\\rellh$.  The angular flux dependence within cells is linear and is given in cell $i$ by\n\\begin{equation} \\label{eq:afdef}\n\\psi_{n,i}\\rellh(x) = \\psi_{n,i,L}\\rellh B_{i,L}(x) + \\psi_{n,i,R}\\rellh B_{i,R}(x) \\,, \\quad x \\in (x_{i-1/2},x_{i+1/2}),\n\\end{equation}\nwhere\n\t\t\\begin{subequations}\n\t\t\\begin{equation}\\label{eq:bfunL}\n\t\t\tB_{i,L}(x) = \\begin{cases}\n\t\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\t\t0 \\,, & \\text{otherwise}\n\t\t\t\\end{cases} \\,,\n\t\t\\end{equation}\n\t\t\\begin{equation}\\label{eq:bfunR}\n\t\t\tB_{i,R}(x) = \\begin{cases}\n\t\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\t\t0 \\,, & \\text{otherwise}\n\t\t\t\\end{cases} \\,,\n\t\t\\end{equation}\n\t\\end{subequations}\nare the LLDG basis functions. \nThe cell centered angular flux is the average of the left and right discontinuous edge fluxes:\n\t\\begin{equation} \\label{eq:lldg_i}\n\t\t\\psi_{n,i}\\rellh = \\half\\left(\\psi_{n,i,L}\\rellh + \\psi_{n,i,R}\\rellh\\right) \\,.\n\t\\end{equation}\nThe interface or cell-edge fluxes are uniquely defined by upwinding:\n\t\\begin{subequations}\n\t\\begin{equation} \\label{eq:downwind}\n\t\t\\psi_{n,i-1/2}\\rellh = \\begin{cases}\n\t\t\t\\psi_{n,i-1,R}\\rellh \\,, & \\mu_n > 0 \\\\ \n\t\t\t\\psi_{n,i,L}\\rellh \\,, & \\mu_n < 0 \n\t\t\\end{cases} \\,,\n\t\\end{equation}\n\t\\begin{equation} \\label{eq:upwind}\n\t\t\\psi_{n,i+1/2}\\rellh = \\begin{cases}\n\t\t\t\\psi_{n,i,R}\\rellh \\,, & \\mu_n > 0 \\\\\n\t\t\t\\psi_{n,i+1,L}\\rellh \\,, & \\mu_n < 0 \n\t\t\\end{cases} \\,.\n\t\\end{equation}\n\t\\end{subequations} \nThe fixed source is also assumed to be linear within each cell:\n\\begin{equation} \\label{eq:Qdef}\nQ_{i}(x) = Q_{i,L} B_{i,L}(x) + Q_{i,R} B_{i,R}(x) \\,, \\quad x \\in [x_{i-1/2},x_{i+1/2}],\n\\end{equation}\nBecause there is no spatial derivative of the fixed source, there is no need to uniquely \ndefine the fixed sources on the cell edges.\n\nThe unlumped Linear Discontinuous Galerkin discretization for Eq.~\\ref{eq:si} is obtained by\nsubstituting $\\psi_{n,i}\\rellh(x)$ from Eq.~\\ref{eq:afdef} and $Q_{i}(x)$ from Eq.~\\ref{eq:Qdef} into Eq.~\\ref{eq:si}, \nsequentially multiplying the resultant equation by each basis function, and integrating over \neach cell with integration by parts of the spatial derivative term.  \nThe lumped discretization equations are obtained simply by performing all volumetric integrals (after formal integration by parts \nof the spatial derivative term) using trapezoidal-rule quadrature.\nThe LLDG discretization of Eq.~\\ref{eq:si} is given by: \n\t\\begin{subequations} \n\t\\begin{equation} \\label{eq:lldg_l}\n\t\t\\mu_n \\left(\\psi_{n,i}\\rellh - \\psi_{n, i-1/2}\\rellh\\right) \n\t\t+ \\frac{\\sigma_{t,i} h_i}{2} \\psi_{n,i,L}\\rellh\n\t\t= \\frac{\\sigma_{s,i} h_i}{4} \\phi_{i,L}\\rell + \\frac{h_i}{4} Q_{i,L} \\,, \n\t\t% 1 \\leq n \\leq N \\,, \n\t\t% 1 \\leq i \\leq I\\,, \n\t\\end{equation}\n\t\\begin{equation} \\label{eq:lldg_r}\n\t\t\\mu_n \\left(\\psi_{n,i+1/2}\\rellh - \\psi_{n,i}\\rellh\\right) \n\t\t+ \\frac{\\sigma_{t,i} h_i}{2} \\psi_{n,i,R}\\rellh\n\t\t= \\frac{\\sigma_{s,i} h_i}{4} \\phi_{i,R}\\rell + \\frac{h_i}{4} Q_{i,R} \\,, \n\t\t% 1 \\leq n \\leq N \\,, \n\t\t% 1 \\leq i \\leq I\\,,\n\t\\end{equation}\n\t\\end{subequations}\nwhere $h_i$, $\\sigma_{t,i}$, $\\sigma_{s,i}$, and $Q_{i,L/R}$ are the cell width, total cross section, scattering cross section, \nand fixed sources in cell $i$. The discontinuous scalar fluxes, $\\phi_{i,L/R}\\rell$, are assumed to be known from \nthe drift-diffusion step of the previous iteration or the initial guess when $\\ell=0$. Equations \\ref{eq:lldg_i}, \\ref{eq:downwind}, \\ref{eq:upwind}, \\ref{eq:lldg_l}, and \\ref{eq:lldg_r} can be combined and rewritten as \nfollows\n\t\\begin{equation} \\label{eq:sweepLR}\n\t\t\\left[\\begin{matrix}\n\t\t\t\\mu_n + \\sigma_{t,i} h_i & \\mu_n  \\\\ \n\t\t\t-\\mu_n & \\sigma_{t,i} + \\mu_n \\\\ \n\t\t\\end{matrix}\\right]\n\t\t\\left[\\begin{matrix}\n\t\t\t\\psi_{n,i,L}\\rellh \\\\ \\psi_{n,i,R}\\rellh\n\t\t\\end{matrix}\\right]\n\t\t= \\left[\\begin{matrix}\n\t\t\t\\frac{\\sigma_{s,i}h_i}{2} \\phi_{i,L}\\rell + \\frac{h_i}{2} Q_{i,L} + 2\\mu_n \\psi_{n,i-1,R}\\rellh \\\\\n\t\t\t\\frac{\\sigma_{s,i}h_i}{2} \\phi_{i,R}\\rell + \\frac{h_i}{2} Q_{i,R} \n\t\t\\end{matrix}\\right] \\,, \n\t\\end{equation}\nfor sweeping from left to right ($\\mu_n > 0$) and \n\t\\begin{equation} \\label{eq:sweepRL}\n\t\t\\left[\\begin{matrix} \n\t\t\t-\\mu_n + \\sigma_{t,i}h_i & \\mu_n \\\\ \n\t\t\t-\\mu_n & -\\mu_n + \\sigma_{t,i}h_i \\\\ \n\t\t\\end{matrix} \\right]\n\t\t\\left[\\begin{matrix}\n\t\t\t\\psi_{n,i,L}\\rellh \\\\ \\psi_{n,i,R}\\rellh\n\t\t\\end{matrix} \\right]\n\t\t= \\left[\\begin{matrix}\n\t\t\t\\frac{\\sigma_{s,i}h_i}{2} \\phi_{i,L}\\rell + \\frac{h_i}{2} Q_{i,L} \\\\ \n\t\t\t\\frac{\\sigma_{s,i}h_i}{2} \\phi_{i,R}\\rell + \\frac{h_i}{2} Q_{i,R} - 2\\mu_n \\psi_{n,i+1,L}\\rellh\n\t\t\\end{matrix} \\right]\n\t\t\\,, \n\t\\end{equation}\nfor sweeping from right to left ($\\mu_n < 0$), respectively. The right hand sides of Eqs.~\\ref{eq:sweepLR} and \\ref{eq:sweepRL} are known \nas the scalar flux from the previous iteration, the fixed source, and the angular flux entering from the upwind cell are all known. By supplying the flux entering the left side of the first cell, the solution for $\\mu_n > 0$ can be propagated from left to right by solving Eq.~\\ref{eq:sweepLR}. Similarly, supplying the incident flux on the right boundary allows the solution for $\\mu_n < 0$ to be propagated from right to left with Eq.~\\ref{eq:sweepRL}. The Variable Eddington Factors needed in the drift-diffusion acceleration step are computed at the cell edges as follows: \n\t\\begin{equation} \\label{lldg:edde}\n\t\t\\edd\\rellh_{i\\pm 1/2} = \\frac{\n\t\t\t\\sum_{n=1}^N \\mu_n^2 \\psi_{n,i\\pm 1/2}\\rellh w_n\n\t\t}{\n\t\t\t\\sum_{n=1}^N \\psi_{n,i\\pm 1/2}\\rellh w_n \n\t\t} \\,,\n\t\\end{equation}\nwhere the $\\psi_{n,i\\pm1/2}\\rellh$ are defined by Eqs.~\\ref{eq:downwind} and \\ref{eq:upwind}. The Eddington factors are \ncomputed within cell $i$ as follows:\n\\begin{equation} \\label{lldg:eddi}\n\t\t\\edd\\rellh(x) = \\frac{\n\t\t\t\\sum_{n=1}^N \\mu_n^2 \\psi_{n}\\rellh(x) w_n\n\t\t}{\n\t\t\t\\sum_{n=1}^N \\psi_{n}\\rellh(x) w_n \n\t\t} \\,, \\quad x\\in(x_{i-1/2},x_{i+1/2}),\n\t\\end{equation}\nwhere $\\psi_{n}\\rellh(x)$ is defined by Eq.~\\ref{eq:afdef}.\n", "meta": {"hexsha": "23fa1c6e5a63ff42712a810dbc1ab9d940476441", "size": 12400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/jctt/body.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/jctt/body.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/jctt/body.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": 56.880733945, "max_line_length": 577, "alphanum_fraction": 0.6849193548, "num_tokens": 4428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332893, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6510818725736789}}
{"text": "\n\\subsection{Real functions are vectors}\n\nThe real function space is a vector space because it is linear in multiplication and addition.\n\n\\(g(x)=cf(x)\\)\n\n\\(h(x)=f(x)+k(x)\\)\n\n\n", "meta": {"hexsha": "29ea28d5f1627fa6034cd655dfc5bf1d1474b36f", "size": 175, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/01-01-real.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/01-01-real.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/01-01-real.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.9090909091, "max_line_length": 94, "alphanum_fraction": 0.6971428571, "num_tokens": 45, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.651039210113775}}
{"text": "\\subsubsection{Autoregressive Integrated Moving Averages}\n\\label{arima}\n\n\\cite{box1962}, \\cite{box1968}, and more papers by the same authors in the\n    1960s introduce a type of model where observations correlate with their\n    neighbors and refer to them as autoregressive integrated moving average\n    (ARIMA) models for stationary time series.\nFor a thorough overview, we refer to \\cite{box2015} and \\cite{brockwell2016}.\n\nA time series $y_t$ is stationary if its moments are independent of the\n    point in time where it is observed.\nA typical example is a white noise $\\epsilon_t$ series.\nTherefore, a trend or seasonality implies non-stationarity.\n\\cite{kwiatkowski1992} provide a test to check the null hypothesis of\n    stationary data.\nTo obtain a stationary time series, one chooses from several techniques:\nFirst, to stabilize a changing variance (i.e., heteroscedasticity), one\n    applies a Box-Cox transformation (e.g., $log$) as first suggested by\n    \\cite{box1964}.\nSecond, to factor out a trend (or seasonal) pattern, one computes differences\n    of consecutive (or of lag $k$) observations or even differences thereof.\nThird, it is also common to pre-process $y_t$ with one of the decomposition\n    methods mentioned in Sub-section \\ref{stl} below with an ARIMA model\n    then trained on an adjusted $y_t$.\n\nIn the autoregressive part, observations are modeled as linear combinations of\n    its predecessors.\nFormally, an $AR(p)$ model is defined with a drift term $c$, coefficients\n    $\\phi_i$ to be estimated (where $i$ is an index with $0 < i \\leq p$), and\n    white noise $\\epsilon_t$ like so:\n$\nAR(p): \\ \\\ny_t = c + \\phi_1 y_{t-1} + \\phi_2 y_{t-2} + \\dots + \\phi_p y_{t-p}\n      + \\epsilon_t\n$.\nThe moving average part considers observations to be regressing towards a\n    linear combination of past forecasting errors.\nFormally, a $MA(q)$ model is defined with a drift term $c$, coefficients\n    $\\theta_j$ to be estimated, and white noise terms $\\epsilon_t$ (where $j$\n    is an index with $0 < j \\leq q$) as follows:\n$\nMA(q): \\ \\\ny_t = c + \\epsilon_t + \\theta_1 \\epsilon_{t-1} + \\theta_2 \\epsilon_{t-2}\n      + \\dots + \\theta_q \\epsilon_{t-q}\n$.\nFinally, an $ARIMA(p,d,q)$ model unifies both parts and adds differencing\n    where $d$ is the degree of differences and the $'$ indicates differenced\n    values:\n$\nARIMA(p,d,q): \\ \\\ny'_t = c + \\phi_1 y'_{t-1} + \\dots + \\phi_p y'_{t-p} + \\theta_1 \\epsilon_{t-1}\n       + \\dots + \\theta_q \\epsilon_{t-q} + \\epsilon_{t}\n$.\n\n$ARIMA(p,d,q)$ models are commonly fitted with maximum likelihood estimation.\nTo find an optimal combination of the parameters $p$, $d$, and $q$, the\n    literature suggests calculating an information theoretical criterion\n    (e.g., Akaike's Information Criterion) that evaluates the fit on\n    historical data.\n\\cite{hyndman2008a} provide a step-wise heuristic to choose $p$, $d$, and $q$,\n    that also decides if a Box-Cox transformation is to be applied, and if so,\n    which one.\nTo obtain a one-step-ahead forecast, the above equation is reordered such\n    that $t$ is substituted with $T+1$.\nFor forecasts further into the future, the actual observations are\n    subsequently replaced by their forecasts.    \nSeasonal ARIMA variants exist; however, the high frequency $k$ in the kind of\n    demand a UDP faces typically renders them impractical as too many\n    coefficients must be estimated.\n", "meta": {"hexsha": "3432b7e994752426edadb165142766d9e5e4fb70", "size": 3397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/2_class/3_arima.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/3_arima.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/3_arima.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": 48.5285714286, "max_line_length": 78, "alphanum_fraction": 0.7241683839, "num_tokens": 913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6510049636605387}}
{"text": "\n\n\\section{Hilbert's nullstellensatz}\n\nThis is by no means the shortest proof of this theorem, \nnor is it the most elegant. \nI chose to do it this way because it's more involved and has a couple extra moving parts. \nIt was also a good excuse to look into Jacobson rings. \n\n\\begin{theorem}[Hilbert's nullstellensatz]\nLet $k$ be an algebraically closed field, \n$A$ be the polynomial ring $A = k[t_1, \\ldots, t_n]$ and $\\mathfrak{a}$ be an ideal of $A$. \nThen\n\\begin{equation*}\n    I(Z(\\mathfrak{a})) = \\sqrt{\\mathfrak{a}}\n\\end{equation*}\n\\end{theorem}\n\nWe are going to do the proof in three smaller steps. \n\\begin{enumerate}\n    \\item Proving that ideals of the form $\\mathfrak{m}_a = (t_1 - a_1, \\ldots t_n - a_n)$ where $a\\in k^n$ are the only maximal ideals in $A$. \n    This is known as the weak Hilbert's nullstellensatz. \n    \\item Proving that the radical of an ideal $\\mathfrak{b}$ in a finitely generated $k$-algebra $B$ is equal to the intersection of the maximal ideals in $B$ that contain $\\mathfrak{b}$. \n    This shows that all finitely generated algebras over a field is a Jacobson ring. \n    \\item Deduce the result. \n\\end{enumerate}\n\n\\subsection{Part 1}\n\\begin{lemma}\nLet $\\mathfrak{m}_a = (t_1 - a_1, \\ldots t_n - a_n)$ where $a\\in k^n$. \nThe ideals of this form are the only maximal ideals in $A$.\n\\end{lemma}\n\\begin{proof}\nLet $a \\in k^n$. \nWe define a the evaluation morphism as follows: \n\\begin{align*}\n    e_{a}: k[t_1,\\ldots, t_n]&\\longrightarrow k \\\\\n    f &\\longmapsto f(a) .\n\\end{align*}\nNote that it is a surjective $k$-algebra homomorphism and since $k$ is algebraically closed, \nit has kernel $\\mathfrak{m}_{a}$. \nLet $\\mathfrak{m}$ be a maximal ideal in $k[t_1, \\ldots, t_n]$. Then $k[t_1, \\ldots, t_n]/\\mathfrak{m}$ is a finitely generated field extension of $k$. \nBy Zariski's lemma, \n$k[t_1, \\ldots, t_n]/\\mathfrak{m}$ is in fact a finite field extension, \nbetter known as a finite dimensional vector space. \nSince $k$ is algebraically closed, \nthere is an isomorphism of $k$-algebras\n\\begin{equation*}\n    k[t_1, \\ldots, t_n]/\\mathfrak{m}\\longrightarrow k .\n\\end{equation*}\nNow, let $a_i$ denote the image of $t_i$. \nThen we get that $\\mathfrak{m}_{a}\\subseteq \\mathfrak{m}$, \nwhich implies $\\mathfrak{m}_{a} = \\mathfrak{m}$ since $\\mathfrak{m}_{a}$ is a maximal ideal. \n\\end{proof}\n\n\\subsection{Part 2}\n\\begin{lemma}\nLet $k$ be an algebraically closed field, \n$B$ be a finitely generated $k$-algebra and $\\mathfrak{b}$ be an ideal in $B$. \nThen we have\n\\begin{equation*}\n    \\sqrt{\\mathfrak{b}} = \\bigcap_{\\mathfrak{b}\\subseteq\\mathfrak{m}}\\mathfrak{m}.\n\\end{equation*}\nwhere $\\mathfrak{m}$ are the maximal ideals in $B$.\n\\end{lemma}\n\\begin{proof}\nFirst, \nwe note that the projection $\\pi:B\\rightarrow B/\\mathfrak{b}$ induces bijections between the sets\n\\begin{itemize}\n    \\item prime ideals in $B/\\mathfrak{b}$ and prime ideals in $B$ that contain $\\mathfrak{b}$,\n    \\item maximal ideals in $B/\\mathfrak{b}$ and maximal ideals in $B$ that contain $\\mathfrak{b}$,\n    \\item radical ideals in $B/\\mathfrak{b}$ and radical ideals in $B$ that contain $\\mathfrak{b}$.\n\\end{itemize}\nHence we only need to prove the statement for $\\mathfrak{b}=(0)$, \nand since it is clear that $\\sqrt{(0)}$ is contained in every maximal ideal because $\\sqrt{(0)}$ consists of all nilpotent elements, \nwe only need to show that every element not contained in $\\sqrt{(0)}$ is not contained in some maximal ideal. \n\nLet $f\\in B$ be non-nilpotent, \ni.e. $f\\in \\sqrt{(0)}$. \nThis implies that $$B_f\\cong B[t]/(ft-1)$$ is a non-trivial $k$-algebra, \nhence it has a maximal ideal $\\mathfrak{m}$. \nConsider the morphism $\\phi: B \\longrightarrow B_f$. \nThis is a morphism of finitely generated $k$-algebras, \nand by Zariski's lemma, \n$k\\subseteq B/\\phi^{-1}(\\mathfrak{m})\\subseteq B_f/\\mathfrak{m}$ is a finite extension, \nand hence $k\\subseteq B/\\phi^{-1}(\\mathfrak{m})$ is an integral extension. \nSince $k$ is a field, it is a field itself. \nThis gives us that the inverse image of a maximal ideal is again a maximal ideal, \ni.e. $\\phi^{-1}(\\mathfrak{m})$ is a maximal ideal of $B$. \nBut this ideal can't contain $f$. \nHence we have shown that every non-nilpotent element is not contained in all maximal ideals. \n\\end{proof}\n\n\n\\subsection{Part 3}\nWe now deduce the result. \n\\begin{proof}\nLet $a \\in k^n$. \nFirst, \nnote that $a \\in Z(\\mathfrak{a})$ if and only if $\\mathfrak{a}\\subseteq \\mathfrak{m}_{a}$. \nHence, \nthe maximal ideals containing $\\mathfrak{a}$ is just the maximal ideals $\\mathfrak{m}_{a}$ such that $a \\in Z(\\mathfrak{a})$. \nIn the second step we showed that the radical of an ideal was equal to the intersection of all maximal ideals containing it, \nhence we have \n\\begin{equation*}\n    \\sqrt{\\mathfrak{a}} = \\bigcap_{a \\in Z(\\mathfrak{a})}\\mathfrak{m}_{a}. \n\\end{equation*}\nFor the final part, \nwe have for $f\\in k[t_1,\\ldots,t_n]$ and $a\\in k^n$ that $f(x) = 0$ if and only if $f \\in \\mathfrak{m}_{a}$. \nHence we have for subsets $V\\subseteq k^n$ that $I(V) = \\bigcap_{a \\in V}\\mathfrak{m}_{a}$. \nAnd since $a \\in Z(\\mathfrak{a})$ if and only if $\\mathfrak{a}\\subseteq \\mathfrak{m}_{a}$ we have finally\n\n\\begin{align*}\n    I(Z(\\mathfrak{a})) \n    &= \\bigcap_{a \\in Z(\\mathfrak{a})}\\mathfrak{m}_{a} \\\\\n    &= \\sqrt{\\mathfrak{a}}.\n\\end{align*}\nAnd by that, we are done!\n\\end{proof}\n\n\n\n\n", "meta": {"hexsha": "94c2669a3d112ba78d38bc6116f11ce5127eaab2", "size": 5310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/theorem.tex", "max_stars_repo_name": "torgeiraamboe/hilberts-nullstellensatz", "max_stars_repo_head_hexsha": "9fb14841c0795a1466bf62ff851e94eb89149fa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/theorem.tex", "max_issues_repo_name": "torgeiraamboe/hilberts-nullstellensatz", "max_issues_repo_head_hexsha": "9fb14841c0795a1466bf62ff851e94eb89149fa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/theorem.tex", "max_forks_repo_name": "torgeiraamboe/hilberts-nullstellensatz", "max_forks_repo_head_hexsha": "9fb14841c0795a1466bf62ff851e94eb89149fa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.8225806452, "max_line_length": 189, "alphanum_fraction": 0.690960452, "num_tokens": 1814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6510049543274767}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[paper=a4paper, left=25mm, right=25mm, top=30mm, bottom=30mm]{geometry}\n\\usepackage{setspace}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\\usepackage{fancyhdr}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{mathtools}\n\n\n\\pagestyle{fancy}\n\\renewcommand{\\headrulewidth}{0pt}\n\\addtolength{\\headheight}{11pt}\n\\title{\\flushleft{\\textbf{Problem Sheet I}}}\n\\date{}\n\\setcounter{secnumdepth}{0}\n\n\\newcommand\\balancedeq{\\stackrel{\\mathclap{\\tiny\\mbox{balanced}}}{=}}\n\n\n\\begin{document}\n\\maketitle\n\\thispagestyle{fancy}\n\n\\subsubsection{3.1 LDA Derivation from the Least Squares Error}\nWe are looking for the global minimum of\n\\begin{equation}\n\\Delta: \\mathbb{R}^{d+1} \\rightarrow \\mathbb{R} \\quad (\\mathbf{m},b) \\mapsto \\sum_{i=1}^N (\\mathbf{w^T x_i} + b - y_i)^2 = \\sum_{i=1}^N (\\mathbf{x_i^T w} + b - y_i)^2 \n\\end{equation}\nFirst, we take a closer look at the summands. Let $i \\in \\{1,...,N\\}$.\\\\\nThe function def. by $f(x):=x^2$ is in $C^\\infty(\\mathbb{R})$ with derivative $f'(x) = 2x$. For the function\n\\begin{equation}\ng_i: \\mathbb{R}^{d+1} \\rightarrow \\mathbb{R} \\quad (\\mathbf{m},b) \\mapsto \\mathbf{w^T x_i} + b - y_i\n\\end{equation}\nholds for $k \\in {1,...,d}$, $\\mathbf{w} \\in \\mathbb{R}^d, b \\in \\mathbb{R}$:\n\\begin{equation}\n\\partial_{w_k} g_i(\\mathbf{w}, b) = \\partial_{w_k} \\left( \\sum_{j=1}^d x_{ij} w_j + b - y_i \\right) = \\sum_{j=1}^d x_{ij} \\delta_{jk} = x_{ik}\n\\end{equation}\n\\begin{equation}\n\\partial_b g_i(\\mathbf{w}, b) = 1\n\\end{equation}\nThe partial derivatives are continuous, thus $g_i \\ in C^1(\\mathbb{R^{d+1}}$\nAs a composition/sum of $C^1$ functions, $\\Delta$ is a $C^1$ function as well and \n\\begin{align*}\nD\\Delta(\\mathbf{w},b) = D\\left(\\sum_{i=1}^N f \\circ g_i \\right)(\\mathbf{w},b) & = \\sum_{i=1}^N Df(g_i(\\mathbf{w}, b)) \\cdot Dg_i(\\mathbf{w}, b) \\\\\n& \\sum_{i=1}^N 2g_i(\\mathbf{w}, b) \\cdot (\\nabla_{\\mathbf{w}} g_i(\\mathbf{w}, b)^T, \\partial_b g_i(\\mathbf{w},b)) \\\\\n& \\sum_{i=1}^N 2(\\mathbf{x_i^Tw} + b - y_i) (\\mathbf{x_i^T}, 1)\\\\\n\\end{align*}\n\\begin{align*}\n\\Rightarrow \\nabla_{(\\mathbf{w},b)} = 2 \\sum_{i=1}^N (\\mathbf{x_i^T w}+b-y_i) \\left(\n\\begin{array}{c}\n\\mathbf{x_i^T}\\\\\n1\\\\\n\\end{array}\n\\right) = \\left(\n\\begin{array}{c}\n2 \\sum_{i=1}^N (\\mathbf{x_i^T w} + b - y_i)  \\mathbf{x_i^T}\\\\\n2 \\sum_{i=1}^N (\\mathbf{x_i^T w} + b - y_i)\\\\\n\\end{array}\n\\right)\n\\end{align*}\nBecause $\\Delta \\in C^1(\\mathbb{R}^{d+1})$ and global maxima in an open set are local maxima, it holds for the argmax $(\\mathbf{\\hat{w}}, \\hat{b})$:\n\\begin{align*}\n\\nabla_{(\\mathbf{w}, b)} \\Delta(\\mathbf{\\hat{w}, \\hat{b}}) = 0\n\\end{align*}\nThis implies\n\\begin{align*}\n\\partial_b \\Delta(\\mathbf{\\hat{w}, \\hat{b}}) = 0 & \\Rightarrow 0 = \\sum_{i=1}^N(\\mathbf{x_i^T \\hat{w}} + \\hat{b} - y_i)\\\\\n& \\Rightarrow 0 = N\\hat{b} + \\sum_{i=1}^N(\\mathbf{x_i^T \\hat{w}} - y_i) \\\\\n& \\Rightarrow \\hat{b} = \\frac{1}{N} \\sum_{i=1}^N(-\\mathbf{x_i^T \\hat{w}} + y_i) = \\frac{-1}{N} \\sum_{i=1}^N \\mathbf{x_i^T \\hat{w}} + \\sum_{i: y_i=1} 1 - \\sum_{i: y_i=-1}^N 1 \\quad \\balancedeq \\quad -\\frac{1}{N} \\sum_{i=1}^N \\mathbf{x_i^T \\hat{w}}\n\\end{align*}\nFurthermore $\\Delta(\\mathbf{\\hat{w}, \\hat{b}}) = 0$ implies\n\\begin{align*}\n0 = \\sum_{i=1}^N(\\mathbf{x_i^T\\hat{w}}+\\hat{b}-y_i)\\mathbf{x_i}\n\\end{align*}\nWe insert our result for $\\hat{b}$ into this equation:\n\\begin{align*}\n0 & = \\sum_{i=1}^N \\left[ \\mathbf{x_i^T \\hat{w}} - \\frac{1}{N} \\sum_{j=1}^N \\mathbf{x_j^T \\hat{w}} - y_i  \\right] \\mathbf{x_i}\\\\\n\\Rightarrow & \\underbrace{\\frac{1}{N} \\sum_{i=1}^N y_i \\mathbf{x_i}}_\\text{a)} = \\underbrace{-\\frac{1}{N} \\sum_{i=1}^N \\frac{1}{N} \\sum_{j=1}^N (\\mathbf{x_j^T\\hat{w}}) \\mathbf{x_i}}_\\text{b)} + \\underbrace{\\frac{1}{N} \\sum_{i=1}^N (\\mathbf{x_i^T \\hat{w}})\\mathbf{x_i}}_\\text{c)}\\\\\n\\end{align*}\nWe will separately discuss the three terms a), b) and c):\\\\\n\\ \\\\\n\\textbf{a)}\n\\begin{align*}\n\\frac{1}{N} \\sum_{i=1}^N y_i \\mathbf{x_i} & = \\frac{1}{N} \\sum_{i:y_i=1}\\mathbf{x_i} - \\frac{1}{N} \\sum_{i:y_i=-1}\\mathbf{x_i}\\\\\n& = \\frac{1}{2} \\left( \\frac{1}{N/2} \\sum_{i:y_i=1} \\mathbf{x_i} - \\frac{1}{N/2} \\sum_{i:y_i=-1} \\mathbf{x_i} \\right)\\\\\n& \\balancedeq \\quad \\frac{1}{2} \\left( \\frac{1}{N_1} \\sum_{i:y_i=1} \\mathbf{x_i} - \\frac{1}{N_2} \\sum_{i:y_i=-1} \\mathbf{x_i} \\right)\\\\\n& = (\\mathbf{\\mu_1} - \\mathbf{\\mu_ {-1}})/2\\\\\n\\end{align*}\n\\ \\\\\n\\textbf{b)}\n\\begin{align*}\n-\\frac{1}{N} \\sum_{i=1} \\frac{1}{N} \\sum_{j=1}^N (\\mathbf{x_j^T \\hat{w}}) \\mathbf{x_i} & = \\left[ - \\frac{1}{N} \\sum_{i=1}^N \\mathbf{x_i}\\right] \\left[ \\left( \\frac{1}{N} \\sum_{j=1}^N \\mathbf{x_j^T} \\right) \\mathbf{\\hat{w}} \\right] \\\\\n& = -\\left[ \\left( \\frac{1}{N} \\sum_{i=1}^N \\mathbf{x_i} \\right) \\left( \\frac{1}{N} \\sum_{j=1}^N \\mathbf{x_j^T} \\right) \\right] \\mathbf{\\hat{w}}\\\\\n& = -\\left(  \\left[  \\left( \\frac{1}{N} \\sum_{i=1}^N \\mathbf{x_i}y_i \\right) + \\left( \\frac{2}{N} \\sum_{i:y_i=1} \\mathbf{x_i}y_i \\right) \\right] \\left[  \\left( \\frac{1}{N} \\sum_{j=1}^N \\mathbf{x_j^T}y_j \\right) + \\left( \\frac{2}{N} \\sum_{j:y_j=1} \\mathbf{x_j^T}y_j \\right) \\right] \\right)\\\\\n& = - (\\frac{1}{2} (\\mathbf{\\mu_1} - \\mathbf{\\mu_{-1}}) + \\mathbf{\\mu_{-1}}) (\\frac{1}{2} (\\mathbf{\\mu_1} - \\mathbf{\\mu_{-1}})^T + \\mathbf{\\mu_{-1}}^T) \\mathbf{\\hat{w}}\\\\\n& = - \\left[ \\frac{1}{4} (\\mathbf{\\mu_1} - \\mathbf{\\mu_{-1}})(\\mathbf{\\mu_1} - \\mathbf{\\mu_{-1}})^T + (\\mathbf{\\mu_1} - \\mathbf{\\mu_{-1}}) \\mathbf{\\mu_{-1}}^T \\right] \\mathbf{\\hat{w}}\\\\\n& = - \\left[ \\frac{S_B}{4} + (\\mathbf{\\mu_1} - \\mathbf{\\mu_{-1}}) \\mathbf{\\mu_{-1}}^T \\right] \\mathbf{\\hat{w}}\n\\end{align*}\n\\ \\\\\n\\textbf{c)}\n\\begin{align*}\n\\frac{1}{N} \\sum_{i=1}^N (\\mathbf{x_i^T \\hat{w}}) \\mathbf{x_i} &= \\frac{1}{N} \\sum_{i=1}^N (\\mathbf{x_i x_i^T}) \\mathbf{\\hat{w}}\\\\\n&= \\frac{1}{N} \\sum_{i=1}^N (\\mathbf{x_i -\\mu_{y_i} + \\mu_{y_i}}) (\\mathbf{x_i -\\mu_{y_i} + \\mu_{y_i}})^T \\mathbf{\\hat{w}}\\\\\n& = \\left[ \\frac{1}{N} \\sum_{i=1}^N (\\mathbf{x_i -\\mu_{y_i}}) (\\mathbf{x_i -\\mu_{y_i}})^T + \\frac{2}{N} \\sum_{i=1}^N (\\mathbf{x_i -\\mu_{y_i}}) \\mathbf{\\mu_{y_i}}^T + \\frac{1}{N} \\sum_{i=1}^N \\mathbf{ \\mu_{y_i}} \\mathbf{\\mu_{y_i}}^T \\right] \\mathbf{\\hat{w}}\\\\\n& = \\left[ S_W + \\frac{1}{N/2} \\sum_{i=1}^N \\mathbf{x_i \\mu_{y_i}^T} - \\frac{2}{N} \\sum_{i=1}^N \\mathbf{\\mu_{y_i} \\mu_{y_i}^T} + \\frac{1}{N} \\sum_{i=1}^N \\mathbf{\\mu_{y_i} \\mu_{y_i}^T} \\right]\\mathbf{\\hat{w}}\\\\\n& = \\left[ S_W + \\underbrace{\\frac{1}{N/2} \\sum_{i:y_i=1} \\mathbf{x_i \\mu_{y_i}^T}}_{=\\mathbf{\\mu_1 \\mu_{1}^T}} + \\underbrace{\\frac{1}{N/2} \\sum_{i:y_i=-1} \\mathbf{x_i \\mu_{y_{-1}}^T}}_{=\\mathbf{\\mu_{-1} \\mu_{-1}^T}}  - \\mathbf{\\mu_1 \\mu_1^T} - \\mathbf{\\mu_{-1} \\mu_{-1}^T} + \\frac{1}{2}\\mathbf{\\mu_1 \\mu_1^T} + \\frac{1}{2} \\mathbf{\\mu_{-1} \\mu_{-1}^T} \\right]\\mathbf{\\hat{w}}\\\\\n& = \\left[ S_W + \\frac{1}{2} (\\mathbf{\\mu_1 - \\mu_{-1}})(\\mathbf{\\mu_1 - \\mu_{-1}})^T + (\\mathbf{\\mu_{1}-\\mu_{-1}})\\mathbf{\\mu_{1}}^T \\right] \\mathbf{\\hat{w}}\\\\\n& = \\left[ S_W + \\frac{S_B}{2} + (\\mathbf{\\mu_{1}-\\mu_{-1}})\\mathbf{\\mu_{1}}^T \\right] \\mathbf{\\hat{w}}\\\\\n\\end{align*}\nNow we insert these results into the equation from last page.\n\\begin{align*}\n(\\mathbf{\\mu_1 - \\mu_{-1}})/2 = \\left[ - \\frac{S_B}{4} - (\\mathbf{\\mu_{1}-\\mu_{-1}})\\mathbf{\\mu_{1}}^T + S_W + \\frac{S_B}{2} + (\\mathbf{\\mu_{1}-\\mu_{-1}})\\mathbf{\\mu_{1}}^T \\right] \\mathbf{\\hat{w}} = \\left[ S_W + \\frac{S_B}{4} \\right] \\mathbf{\\hat{w}}\n\\end{align*}\nThis is equivalent to\n\\begin{equation}\nS_W \\mathbf{\\hat{w}} = \\frac{\\mathbf{\\mu_1 - \\mu_{-1}}}{2} + \\frac{S_B}{4} \\mathbf{\\hat{w}}\n\\end{equation}\nBecause $\\mathbb{R}^d$ is a finite dimensional vector space, we can choose $v_2, ...,v_d \\in \\mathbb{R}^d$ such that $\\{(\\mu_1-\\mu_{-1}),v_2, ..., v_d\\}$ is an orthonormal basis of $\\mathbb{R}^d$.\nThus, we can write: $\\mathbf{\\hat{w}} = \\lambda_1 (\\mu_1-\\mu_{-1}) + \\sum_{i=2}^d \\lambda_i v_i$ for $\\lambda_1, ...,\\lambda_d  \\in \\mathbb{R}$. This way we can show:\n\\begin{align*}\n\\frac{S_B}{4} \\mathbf{\\hat{w}} &= \\frac{1}{4} (\\mu_1-\\mu_{-1})(\\mu_1-\\mu_{-1})^T \\left( \\lambda_1 (\\mu_1-\\mu_{-1}) + \\sum_{i=2}^d \\lambda_i v_i \\right)\\\\\n&= \\frac{1}{4} \\lambda_1 (\\mu_1-\\mu_{-1})(\\mu_1-\\mu_{-1})^T(\\mu_1-\\mu_{-1})\\\\ \n&= \\frac{1}{4} \\lambda_1 (\\mu_1-\\mu_{-1})||\\mu_1-\\mu_{-1}||^2 \n\\end{align*}\nThe second equality holds because the scalar product of $\\mu_1-\\mu_{-1}$ and $v_i$ vanishes for all $i \\in \\{2, ...,d\\}$ (ONB). Thus, we obtain with the equality from above and $\\tau := \\frac{1}{2} + \\frac{1}{4}\\lambda_1 ||\\mu_1-\\mu_{-1}||^2$:\n\\begin{align*}\n\\exists \\tau \\in \\mathbb{R}: S_W\\mathbf{\\hat{w}} = \\tau (\\mu_1-\\mu_{-1})\n\\end{align*}  \nUnder the assumption that $S_W$ is invertible (which is true if $(x_i)$ are not located on a common ($d-1$)-dimensional hyperplane) we get:\n\\begin{align*}\n\\exists \\tau \\in \\mathbb{R}: \\mathbf{\\hat{w}} = \\tau S_W^{-1} (\\mu_1-\\mu_{-1})\n\\end{align*}\n\\end{document}", "meta": {"hexsha": "716ce14ec361ca54449239fb2ff41fec41b27853", "size": 8661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex03/task3/Aufgabe3.tex", "max_stars_repo_name": "Osburg/Fundamentals-of-Machine-Learning", "max_stars_repo_head_hexsha": "cd34194464d3b06cc23b4b91523684f0f01a92f0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex03/task3/Aufgabe3.tex", "max_issues_repo_name": "Osburg/Fundamentals-of-Machine-Learning", "max_issues_repo_head_hexsha": "cd34194464d3b06cc23b4b91523684f0f01a92f0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex03/task3/Aufgabe3.tex", "max_forks_repo_name": "Osburg/Fundamentals-of-Machine-Learning", "max_forks_repo_head_hexsha": "cd34194464d3b06cc23b4b91523684f0f01a92f0", "max_forks_repo_licenses": ["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.6838235294, "max_line_length": 378, "alphanum_fraction": 0.5962360005, "num_tokens": 4115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439707, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6510037316882265}}
{"text": "\\section{Transforms}\n\nTransforms are invertible functions that can be applied to a\nrandom variable to change the distribution.\n\\subsection{Transform (Base Class)}\n\n\\subsection{Inverse Transform}\n\n\\subsection{Chain}\n\n\n\\subsection{Affine}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item Location $\\mu \\in \\mathbb{R}^n$\n    \\item Scale $\\sigma > 0$\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = \\mu + \\sigma \\cdot x\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\frac{y - \\mu}{\\sigma}\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = \\log \\vert \\sigma \\vert\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Exp}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item None\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = e^x\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\log y\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = x\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Expm1}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item None\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = e^x - 1\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\log ( 1 + y )\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = x\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Gumbel}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item Location $\\mu \\in \\mathbb{R}^n$\n    \\item Scale $\\sigma > 0$\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = \\exp \\left( - \\exp \\left( - \\frac{x - \\mu}{\\sigma} \\right) \\right)\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\mu - \\sigma \\cdot \\log \\left( - \\log \\left( y \\right) \\right)\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = - \\log \\left( \\frac{\\sigma}{-\\log(y) \\cdot y} \\right)\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Identity}\n\n\\subsection{Kumaraswamy}\n\n\\subsection{Log}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item None\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = \\log x\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\exp y\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = - y\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Logit}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item None\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = \\log \\left( \\frac{x}{1 - x} \\right)\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\frac{1}{1 + e^{-y}}\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = \\log\\left( 1 + e^{-y} \\right) + \\log\\left( 1 + e^{y} \\right)\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{NICE}\n\n\\subsection{Planar}\n\n\\subsection{Power}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item Power $p$\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = \\begin{cases} e^x & p = 0 \\\\ \\left( 1 + x \\cdot p \\right) ^ {1 / p} & \\text{otherwise} \\end{cases}\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\begin{cases} \\log y & p = 0 \\\\ y^{p - 1} / p & \\text{otherwise} \\end{cases}\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = \\begin{cases} x & p = 0 \\\\ \\left(\\frac{1}{p} - 1 \\right) \\cdot \\log \\left(x \\cdot p + 1 \\right) & \\text{otherwise} \\end{cases}\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Radial}\n\n\\subsection{Reciprocal}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item None\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = 1 / x\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = 1 / y\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = -2 \\cdot \\log \\vert x \\vert\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{Sigmoid}\n\\begin{itemize}\n  \\item \\textbf{Parameters}\n  \\begin{itemize}\n    \\item None\n  \\end{itemize}\n  \\item \\textbf{Forward}\n  \\begin{equation}\n    f(x) = \\frac{1}{1 + e^{-x}}\n  \\end{equation}\n  \\item \\textbf{Inverse}\n  \\begin{equation}\n    f^{-1}(y) = \\log \\left( \\frac{y}{1 - y} \\right)\n  \\end{equation}\n  \\item \\textbf{Log Absolute Determinant Jacobian}\n  \\begin{equation}\n    \\log \\vert \\text{det} \\, \\mathbf{J} \\vert (x, y) = -\\log\\left( 1 + e^{-x} \\right) - \\log\\left( 1 + e^{x} \\right)\n  \\end{equation}\n\\end{itemize}\n\n\\subsection{SinhArcsinh}\n\n\\subsection{Softplus}\n\n\\subsection{Softsign}\n\n\\subsection{Square}\n\n\\subsection{Tanh}\n\n\\subsection{Weibull}\n", "meta": {"hexsha": "3fa5ec8addc8a3ecfd3c61785aec11302182c6ad", "size": 5232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/subsections/transforms.tex", "max_stars_repo_name": "nextBillyonair/DPM", "max_stars_repo_head_hexsha": "840ffaafe15c208b200b74094ffa8fe493b4c975", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-20T14:02:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T14:02:55.000Z", "max_issues_repo_path": "docs/subsections/transforms.tex", "max_issues_repo_name": "nextBillyonair/DPM", "max_issues_repo_head_hexsha": "840ffaafe15c208b200b74094ffa8fe493b4c975", "max_issues_repo_licenses": ["MIT"], "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/subsections/transforms.tex", "max_forks_repo_name": "nextBillyonair/DPM", "max_forks_repo_head_hexsha": "840ffaafe15c208b200b74094ffa8fe493b4c975", "max_forks_repo_licenses": ["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.3348837209, "max_line_length": 181, "alphanum_fraction": 0.628058104, "num_tokens": 2006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6510037288915337}}
{"text": "%########\n% Hvad er totality?\n% Hvorfor totality?\n% Totalitet skal bevises\n%% Hvordan beviser man det?\n% Hvorfor er totalitet ikke standard?\n% Partiality\n% Coverage\n% Termination\n% Produktivitet\n\n% Finite prefix af coinduktiv data ved endeligt antal unfolds\n% Partielle funktioner defineres ved subset-intuition\n\n% Ny viden: Hvorfor totality?, Hvad består totalitet af? Produktivitet vs. terminering, total vs. partiel funktion\n%########\n\n\\section{Totality and Total Functional Programming}\n\\label{sec:totality}\nTotality is a property of functions. In the context of functional programming,\ntotality is thus a property of programs, assuming that our programming language\nmodels mathematical functions. \n\n\\begin{definition}[\\textit{Total function}]\n\\label{def:total_function}\nA function $f$ with domain $A$ and codomain $B$ is total if for \\emph{every}\nelement $x\\in A$, $f$ assigns a value\n$f x\\in B$\\,\\citep{Turner04totalfunctional}.\n\\end{definition}\n\nWithin Definition \\ref{def:total_function} is the implicit assumption that each\nsuch assignment happens in finite time; if $f$ requires infinite time to compute\n$f y$ for some input $y\\in A$, then $f$ does not assign a value $f y\\in B$, and is\ntherefore \\emph{undefined} for $y$. In this case, $f$ is not total. Programming\nsolely with total functions has attracted more and more attention in recent\nyears, and has even given rise to the aptly named discipline of ``total\nfunctional programming''. But why should we care whether the programs we write\nare total?\n\n\\subsection{Partiality and Partial Functional Programming}\nAn appreciation of totality is perhaps best achieved by understanding its\ncounterpart, \\emph{partiality}. Like totality, partiality is also a property of\nfunctions. \n\n\\begin{definition}[\\textit{Partial function}]\n  A function $f$ with domain $A$ and codomain $B$ is partial if $f$ is undefined\n  for some $x\\in A$. Specifically, if $f$ is a partial function, then there\n  exists a total function $g$ with domain $A'$ and codomain $B$, such that\n  $A' \\subset A$.\n  % inhabitant $x\\in A$, $g$ does not assign a value $g x\\in B$. More precisely, there exists\n  % an element $x\\in A$ for which $g$ is undefined, i.e. either $g$\n  % requires infinite time to compute $g x$, or the definition of $g$ has no\n  % reduction rule for $x$.\n  \\centering\n  \\includegraphics[scale=0.8]{figures/partialfunc}\n\\end{definition}\n\nFor input  where a partial function is undefined, we say that\nthe function evaluates to $\\bot$, here denoting either an exceptional state (a\nrun-time error) or infinite recursion\\,\\citep{Turner04totalfunctional}. The\nimplications of programming with partial functions (``partial functional\nprogramming'') is greater than it may seem: Whenever we have no guarantee that a\nfunction is total, $\\bot$ is a possible result, which should be handled\nproperly. When $\\bot$ signifies that program evaluation has reached an\nexceptional state, an error or exception handling machinery can be set in motion\nto recover from the situation, if possible. But when program evaluation reaches\nan infinite recursion, meaningful recovery becomes impossible. First, due to the\nundecidability of the halting problem, it is impossible to determine whether an\ninfinite recursion has, in fact, been reached. Secondly, it might not be\npossible for the runtime system to simply stop evaluating the infinitely\nrecursive function and move on, since later computations could depend on the lost\noutput value. With this in mind, handling $\\bot$ cases for all partial functions\nis clearly undesirable, and simply doing nothing is not necessarily a sensible\nsolution. The main selling point of total functional programming is therefore\nthat $\\bot$ is never a possible result of program evaluation.\n\n\\subsection{A Total Program is a Proof}\nAnother advantage of programming with total functions is that our programs can\nact as proofs. The Curry-Howard isomorphism identifies a deep connection\nbetween logic and computer\nprograms\\,\\citep{Curry1934,Howard80,Wadler2014}. Within this connection, types\nare identified as propositions, (total) programs as proofs, and evaluation of\nprograms as simplification of proofs. Consequently, a program can be viewed as a\nproof script in a logic (which, in this case, is our programming language),\nshowing that a given proposition, specified by the program's type, holds. This\nis not merely an academic curiosity, but leads to a situation where a program\ncan be \\emph{correct by construction}\\,\\citep{Pierce:2002:TPL:509043} if its\ntype sufficiently describes the program's behaviour. The correctness of the\nprogram can then be established statically by the type checker.\n\nA partial function can never be correct by construction, since evaluating it\nmight lead to infinite recursion. Infinite recursion is logically equivalent to\nRussell's paradox (the equivalent type theoretic formulation is given by\nGirard's paradox\\,\\citep{Girard1972}), which is known to introduce an inconsistency into an\nintuitionistic logic, and therefore also into the logic that is our programming\nlanguage. Any proposition can be deduced in an inconsistent logic, and as a\nconsequence, a partial function can never act as a valid proof.\n\n%  which is the general notion that\n% programs are proofs and types are propositions, a well-typed program $p$ of type\n% $T$ constitutes a constructive proof of the proposition $T$. The proof is\n% constructed by providing an inhabitant of the output type. If a total program $p$ has a domain $A$\n% and a codomain $B$, and there is an $x\\in A$, $p$ can construct a proof of $B$ by\n% providing an inbitant of $B$ for $p x$. The implication of\n% having programs as proofs is that given a type specification which is sufficiently\n% strong, we can implement programs which are \\emph{correct by construction},\n% i.e. statically proven correct by the compiler. Partial functions cannot act as\n% proofs, since $\\bot$ is a possible result. If the aforementioned $p$ is a\n% partial program, no inhabitant for $B$ can be provided for input where $p$ is\n% undefined. \n\n\\subsection{Ensuring Totality}\nIf have no guarantee that a function is total, then it must be assumed to be partial. To\nobtain such a guarantee for an arbitrary function $f$, we must be able to\nconstruct a proof showing that $f$ is total. A totality proof is twofold,\nconsisting of a proof of coverage and a proof that all invocations result in an\noutput value in finite time.\n\n\\begin{definition}[\\textit{Covering function}]\n  \\label{def:covering_function}\n  A function $f$ with domain $A$ and codomain $B$ is covering if its definition\n  has a reduction rule for every inhabitant $x\\in A$.\n\\end{definition}\n\nDepending on whether the codomain of a covering function $f$ is an inductive or\na coinductive type, $f$ must be shown to be either \\emph{terminating} or\n\\emph{productive} in order to ensure that all invocations of $f$ lead to a\nresult in finite time.\n\n\\begin{definition}[\\textit{Terminating function}]\n\\label{def:terminating_function}\n  A function $f$ with domain $A$ and codomain $B$, where $B$ is an inductive\n  type, is terminating if for every inhabitant $x\\in A$, the output value\n  $f x\\in B$ is \\emph{fully} constructed in finite time.\n\\end{definition}\n\nSince any inductive data has finite size by definition, a terminating function\nterminates in the literal sense of the word: When the output has been\nconstructed, no further computations can be done for the given\ninput. Termination proofs are often constructed by showing that all recursive\ninvocations of a function happen on structurally smaller input. For\nproductive functions, this is may not the case.\n\n\\begin{definition}[\\textit{Productive function}]\n\\label{def:productive_function}\n  A function $f$ with domain $A$ and codomain $B$, where $B$ is a coinductive\n  type, is productive if for every inhabitant $x\\in A$, a finite number of\n  unfoldings of the output value $f x\\in B$ can be constructed in finite time.\n\\end{definition}\n\nBecause coinductive data is possibly infinite, a productive function continually\nunfolds its output, providing each unfolding in finite time. Notably, it might\nnever terminate, since constructing an infinite term (e.g. a list of all prime\nnumbers) never comes to a natural end. Productive functions are therefore often\nevaluated using a call-by-name strategy, computing exactly the number of\nunfoldings needed, deferring the computation of the remaining term.  A proof\nof productivity can be constructed by showing that the function definition in\nquestion exhibits some continuity property, e.g. causality: that any output only\ndepends on previously computed values.\n\n\\subsection{Automated Totality Proofs}\nManually writing proofs of totality is clearly not feasible in practice, as it\nmust be done for every function in a program individually. Consequently,\nautomated construction of coverage, termination, and productivity proofs has\nreceived much attention in the community in recent years, a development which\nwill be outlined in Chapter~\\ref{cha:related-work}. Most techniques are either\nbased on a purely syntactical analysis of terms or on type checking, where the\ntype of a program is decorated with auxiliary information. A popular and purely\nsyntactical technique for automating termination proofs is to analyze whether a\nprogram is size-change terminating\\,\\citep{LeeJones01SizeChange} by tracing\n(mutually) recursive calls in a statically constructed call graph. Syntactic\nguardedness, which will be the subject of Section~\\ref{sec:synt-guard-1}, is a\npurely syntactical method for approximating productivity, whereas guarded\nrecursion, covered in Section~\\ref{sec:guarded-recursion}, is a type-based\napproach to constructing productivity proofs. A full automation of guarded recursion\nproofs has yet to be described.\n\n% Equational reasoning?\n% partiality and partial functions\n% recursive and corecursive functions\n% Turing-completeness and corecursion\n% Curry-Howard\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../../copatterns-thesis\"\n%%% End:\n", "meta": {"hexsha": "44fd8b199bbe414d689cc292a133fa81f8b64c70", "size": 10038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/background/totality.tex", "max_stars_repo_name": "sualitu/thesis", "max_stars_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "max_stars_repo_licenses": ["MIT"], "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/background/totality.tex", "max_issues_repo_name": "sualitu/thesis", "max_issues_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "max_issues_repo_licenses": ["MIT"], "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/background/totality.tex", "max_forks_repo_name": "sualitu/thesis", "max_forks_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "max_forks_repo_licenses": ["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.3936170213, "max_line_length": 114, "alphanum_fraction": 0.7845188285, "num_tokens": 2409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6510037214511226}}
{"text": "\\documentclass{article}\n\n\\begin{document}\n\\title{interest rate}\n\\begin{itemize}\n\t\\item Interest(I) is the price of money. It is the fee paid for borrowing or investing money.\n\t\\item Principal(P) is the amount of money being borrowed or deposited.\n\t\\item Interest Rate(R) is the percentage of the principal that is paid as a fee over a period of time'\n\t\\item Accumulated Balance(A) is the total amount to be repaid or the total value of money invested.\n\\end{itemize}\n\n\\paragraph{}\n\\begin{equation}\nsimple interest formula I = P*R*T\n\\end{equation}\n\\begin{equation}\nAccumulated balance A = P + I\n\\end{equation}\n\\begin{equation}\nA = P(1 + R*T)\n\\end{equation}\n\\end{document}", "meta": {"hexsha": "eeaee70354af72f0fdab6e32da98e054ed33f2a4", "size": 669, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "csc101 1st ca/document2.tex", "max_stars_repo_name": "Oluwanifemiiii/oluwanifemiiiiCSC101", "max_stars_repo_head_hexsha": "78bc98b6c519cfd2e1adcba17457204feb8743d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "csc101 1st ca/document2.tex", "max_issues_repo_name": "Oluwanifemiiii/oluwanifemiiiiCSC101", "max_issues_repo_head_hexsha": "78bc98b6c519cfd2e1adcba17457204feb8743d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "csc101 1st ca/document2.tex", "max_forks_repo_name": "Oluwanifemiiii/oluwanifemiiiiCSC101", "max_forks_repo_head_hexsha": "78bc98b6c519cfd2e1adcba17457204feb8743d2", "max_forks_repo_licenses": ["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.4090909091, "max_line_length": 103, "alphanum_fraction": 0.7488789238, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387914176259, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6509727542612306}}
{"text": "% !TEX root = thesis.tex\n\n\\chapter{Mathematical foundations of spatial modelling}\n\\label{ch:modelling-mathematics}\n\nSpatial modelling has its origins in the geographical notion of space, which is in turn based on our own observations of the world and empirical experience \\citep{Couclelis99}.\nHowever, these informal notions are error-prone and differ from person to person.\nIn order to describe space unambiguously, people have thus turned to models that still describe geographical phenomena, but do so using formal notions derived from mathematics.\nThese formal models make it possible to create and store digital representations of the world in a computer, and thus to use the power of a computer to easily solve spatial problems \\citep{Burrough86,Bailey95}.\n\nThe current chapter describes some of these formal notions and their relevant context, which are used to study the spatial modelling approaches presented in the upcoming chapters.\n\\refse{se:settheory} introduces some concepts of elementary set theory and mathematical logic, which are later used in definitions in this thesis.\n\\refse{se:geometry} introduces the basic concepts of geometry, which are used to describe the position, shape and orientation of objects.\n\\refse{se:topology} builds on these to present topology, which formalises notions such as the boundary and interior of an object or the relationships between multiple objects.\n\n\\section{Elementary set theory and mathematical logic}\n\\label{se:settheory}\n\nSet theory is the branch of mathematics that studies \\emph{sets}, which are collections of abstract objects.\nWhile the study of set theory only formally started with \\citet{Cantor74}, its intuitive and minimal concepts were later used in order to give a foundation to almost all areas of mathematics\\footnote{Even as some mathematicians and philosophers have argued against set theory as a foundation for all of mathematics.}.\nSince the basic concepts of set theory are used in this thesis in order to describe many other concepts, this section gives a very short primer using the same notation that is used in this thesis.\nHowever, it is worth noting that the descriptions used here are reflect the concepts generally used in GIS, and so are meant to be intuitive and not very formal.\nPerhaps more importantly, these definitions do not reflect modern mathematical thought on the topic\\footnote{In short, these intuitive definitions pretty much assume that anything can be put into a set without leading to paradoxes, which formally is not the case.}, which is much more precise but also less accessible, \\eg\\ axiomatic set theory.\n\nSet theory starts by considering the existence of a given domain of objects from which one may build sets, which is known as the \\emph{universe set} and denoted as $\\mathbb{U}$.\nThese objects can be anything, including other sets.\nSet theory allows sets to be regarded as single entities and operated upon \\citep{Devlin93}.\nIf an object $a$ is part of a set $\\mathbb{X}$, it is denoted as $a \\in \\mathbb{X}$, read as `$a$ is an \\emph{element} of $\\mathbb{X}$'.\nIf $a$ is not part of a set $\\mathbb{X}$, it is denoted as $a \\notin \\mathbb{X}$, read as `$a$ is not an element of $\\mathbb{X}$'.\n\nThere are two broad ways to describe the elements in a set, both using curly braces, \\ie\\ \\{ and \\}.\nOne way to do so is to enumerate all the elements of the set one by one.\nFor instance, the set $\\left\\{ 1,2,3 \\right\\}$ is the set containing $1$, $2$ and $3$ as elements (and no others).\nThe other way to do so is to specify one or more rules that the elements of the set need to fulfil.\nFor instance, the set $\\{ x \\mid x$~\\emph{is~a~prime~number}$\\}$ consists of all prime numbers.\nIt is read as `$x$, such that $x$ is a prime number'.\n\nSets are by definition unordered and contain unique elements---duplicate items are ignored by convention.\nA set may contain an infinite number of elements (\\eg\\ as the prime number example above), or no elements at all, in which case it is a special set known as the \\emph{null set} and denoted as $\\{ \\}$ or $\\emptyset$.\nOther commonly used sets with a special notation and name are: the natural numbers ($\\mathbb{N}$), the real numbers ($\\mathbb{R}$), the rational numbers ($\\mathbb{Q}$) and the integers ($\\mathbb{Z}$).\n\nIn order to build more complex sets, the concepts and notation from mathematical logic are used, in particular \\emph{propositional logic}.\nPropositional logic works with \\emph{propositions}, which are sentences that are either true or false, but not both.\nThese propositions might be altered and combined using various symbols expressing various notions, such as: \\emph{and} ($\\wedge$), \\emph{or} ($\\vee$), \\emph{not} ($\\neg$), \\emph{implies} ($\\Rightarrow$), \\emph{is implied by} ($\\Leftarrow$), \\emph{if and only if} ($\\Leftrightarrow$), \\emph{for all} ($\\forall$) and \\emph{exists} ($\\exists$).\n\nUsing these concepts it becomes possible to state relationships between sets.\nFor instance, $\\mathbb{A}$ and $\\mathbb{B}$ are then equal ($\\mathbb{A} = \\mathbb{B}$) when an element is in $\\mathbb{A}$ if and only if it is also in $\\mathbb{B}$, which can be denoted as $\\forall x : x \\in \\mathbb{A} \\Leftrightarrow x \\in \\mathbb{B}$.\nA set $\\mathbb{A}$ is called a subset of a set $\\mathbb{B}$ ($\\mathbb{A} \\subseteq \\mathbb{B}$), or $\\mathbb{B}$ is a superset of $\\mathbb{A}$ ($\\mathbb{B} \\supseteq \\mathbb{A}$), when if an element is in $\\mathbb{A}$ then it is also in $\\mathbb{B}$, denoted as $\\forall x : x \\in \\mathbb{A} \\Rightarrow x \\in \\mathbb{B}$.\nIf $\\mathbb{A} \\subseteq \\mathbb{B}$ but $\\mathbb{A} \\neq \\mathbb{B}$, \\ie\\ there is at least one extra element in $\\mathbb{B}$, then $\\mathbb{A}$ is a proper subset of $\\mathbb{B}$ ($\\mathbb{A} \\subset \\mathbb{B}$), or alternatively $\\mathbb{B}$ is a proper superset of $\\mathbb{A}$ ($\\mathbb{B} \\supset \\mathbb{A}$).\n\nIt is also possible to use propositional logic to create new sets by defining certain operations between sets, in particular \\emph{Boolean set operations}, consisting of intersection, union, difference and complement\\footnote{These are the most commonly described basic operations. However, it is possible to define other operations that are equally useful as a base. Either can be used to form other operations by composition.}.\nThe intersection of the sets $\\mathbb{A}$ and $\\mathbb{B}$, denoted as $\\mathbb{A} \\cap \\mathbb{B}$, consists of all the elements that are both in $\\mathbb{A}$ and in $\\mathbb{B}$, \\ie\\ $\\mathbb{A} \\cap \\mathbb{B} = \\left\\{ x \\mid x \\in \\mathbb{A} \\wedge x \\in \\mathbb{B} \\right\\}$.\nThe union of the sets $\\mathbb{A}$ and $\\mathbb{B}$, denoted as $\\mathbb{A} \\cup \\mathbb{B}$, consists of all the elements that are either in $\\mathbb{A}$ or in $\\mathbb{B}$, \\ie\\ $\\mathbb{A} \\cup \\mathbb{B} = \\left\\{ x \\mid x \\in \\mathbb{A} \\vee x \\in \\mathbb{B} \\right\\}$.\nThe difference between sets $\\mathbb{A}$ and $\\mathbb{B}$, denoted as $\\mathbb{A} - \\mathbb{B}$, consists of all the elements that are in $\\mathbb{A}$ but not in $\\mathbb{B}$, \\ie\\ $\\mathbb{A} - \\mathbb{B} = \\left\\{ x \\mid x \\in \\mathbb{A} \\wedge x \\notin \\mathbb{B} \\right\\}$.\nThe complement of a set $\\mathbb{A}$, denoted as $\\neg \\mathbb{A}$, consists of all the elements that are in the universe set but are not in $\\mathbb{A}$, \\ie\\ $\\neg \\mathbb{A} = \\left\\{ x \\mid x \\in \\mathbb{U} \\wedge x \\notin \\mathbb{A} \\right\\}$.\n\nApart from sets, it is also possible to consider \\emph{tuples} of elements, which unlike sets are sequences of ordered elements.\nA tuple containing exactly two elements is known as a \\emph{pair}, one containing three elements is a \\emph{treble} and one containing $n$ elements is an $n$-tuple.\nTuples are denoted using parenthesis, \\ie\\ (\\ and~).\n\nA common operation that generates tuples is the Cartesian product.\nThe Cartesian product of sets $\\mathbb{A}$ and $\\mathbb{B}$, denoted as $\\mathbb{A} \\times \\mathbb{B}$, is defined as $\\left\\{ (a,b) \\mid a \\in \\mathbb{A} \\wedge b \\in \\mathbb{B} \\right\\}$.\nIn other words, it is a set of pairs, where the first element of a pair is an element of $\\mathbb{A}$ and the second element of the pair is an element of $\\mathbb{B}$.\nThis can be generalised to more than two sets, such that the $n$-fold Cartesian product of $n$ sets is an $n$-tuple.\nThe $n$-fold Cartesian product of a set $\\mathbb{A}$ with itself, \\ie\\ $\\mathbb{A} \\times \\mathbb{A} \\times \\cdots \\mathbb{A}$, is denoted as $\\mathbb{A}^n$.\n\n\\section{Geometry}\n\\label{se:geometry}\n\nGeometry is the branch of mathematics concerned with the position of objects in space, a topic that was already formalised by the ancient Greek mathematician Euclid in his textbook \\emph{the Elements} around 300 BCE \\citep{Fitzpatrick08}.\nEuclidean geometry consists of a small set of geometric axioms considered to be intuitively obvious, such as the fact that it is possible to draw exactly one line that passes through two points (\\reffig{fig:line}), as well as a long series of postulates derived from these and which describe more complex constructions\\footnote{Non-Euclidean geometry does away with some of these axioms while remaining self-consistent \\citep{Bolyai32,Lobachevsky40}. However, it is much less relevant in the context of spatial modelling.}.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/line}\n\\caption[A single line passes through two points]{There is exactly one line that passes through any pair of points.}\n\\label{fig:line}\n}\n\nHowever, even as Euclidean geometry has the notions of relative distances, angles and areas, objects in Euclidean geometry do not have an absolute position in space.\nAnalytic or Cartesian geometry, developed by \\citet{Descartes37} and \\citet{de-Fermat79}, significantly changed this by introducing the concept of coordinates.\nA coordinate system makes it possible to uniquely describe the absolute location of a point as a tuple of real numbers.\nIn particular, the Cartesian coordinate system uses a tuple of perpendicular directed lines as axes, with a positive direction and a negative direction, all of which intersect at a common point known as the origin.\nA point's coordinates in the system are then given by signed distances to the respective axes\\footnote{A more rigorous and correct explanation would be based on a set of linearly independent vectors, but this creates a recursive definition.}.\n\n$n$-dimensional Euclidean space, which can be described by the set of points $\\mathbb{R}^n$, has $n$ perpendicular axes intersecting at the origin $O$, defined by the $n$-tuple $(0, 0, \\ldots, 0)$, and a point $p$ in $n$D space is thus described by an $n$-tuple $(p_1, p_2, \\ldots, p_n)$, where $p_i$ is the signed distance to the $i$-th axis.\nFor example, as shown in \\reffig{fig:point}, three-dimensional Euclidean space ($\\mathbb{R}^3$), has three axes, usually named $X$, $Y$ and $Z$, such that a given point $p$ in 3D can be described by a treble $(p_x,p_y,p_z)$, where $p_x$ is the signed distance to the $X$ axis, $p_y$ to the $Y$ axis and $p_z$ to the $Z$ axis.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/point}\n\\caption{A point $p$ in 3D described by a treble $(p_x,p_y,p_z)$}\n\\label{fig:point}\n}\n\nA point $a = (a_1, a_2, \\ldots, a_n)$ can also be used to define a vector $\\vec{a}$, which goes from the origin to $a$.\n% Why is            this vvvv necessary for spacing!?!?\nThe norm, or magnitude of\\ \\ $\\vec{a}$, denoted as $\\| \\vec{a} \\|$, gives the length of the line segment between $a$ and the origin and is computed as:\n\\begin{equation*}\n\\| \\vec{a} \\| = \\sqrt{{a_1}^{2} + {a_2}^{2} + \\cdots + {a_n}^{2}}\n\\end{equation*}\n\nThis analytic description of objects also enables using algebra to compute properties, such as the Euclidean distance between two points $a = (a_1, a_2, \\ldots, a_n)$ and $b = (b_1, b_2, \\ldots, b_n)$, also known as the Euclidean metric.\nThis is given by:\n\\begin{equation*}\n\\mathrm{distance}(a,b) = \\sqrt{{(a_1 - b_1)}^{2} + {(a_2 - b_2)}^{2} + \\cdots + {(a_n - b_n)}^{2}}\n\\end{equation*}\n\nSome other objects can be described as a linear combination of linearly independent points (\\ie\\ two different points, three non-collinear points, four non-coplanar points, etc.).\nConsidering the points $p_1,p_2,\\ldots,p_n$, a linear combination of them takes the form $a_1 p_1 + a_2 p_2 + \\cdots + a_n p_n$, where $\\sum_{i=1}^n a_i = 1$.\nFor every point $p_i$, $a_i$ is thus a scalar coefficient that determines its \\emph{weight}.\n\nIf negative weights are allowed, the linear combination of $n+1$ linearly independent points forms an $n$-dimensional unbounded linear object, \\eg\\ a line using two points or a plane using three points.\nAll of these points lie exactly on the object.\nWhen the weights are instead restricted to the interval $[0,1]$, the linear combination of $n+1$ linearly independent points forms an $n$-dimensional simplex (called an $n$-simplex)---a convex shape with $n+1$ vertices.\nA \\emph{0-simplex} is thus a point, a \\emph{1-simplex} is a line segment, a \\emph{2-simplex} is a triangle, a \\emph{3-simplex} is a tetrahedron, and so on.\n\nOther, more complex objects can be described using equations, which describe particular subsets of $\\mathbb{R}^n$.\nA hyperplane in $\\mathbb{R}^n$, \\ie\\ a space of dimension $\\mathbb{R}^{n-1}$ in $\\mathbb{R}^n$, can be described by a linear equation of the form $a_1 x_1 + a_2 x_2 + \\cdots + a_n x_n = b$, where $a_1, a_2, \\ldots, a_n$ are the coefficients of the linear equation.\nApart from the points exactly on the hyperplane, as shown in \\reffig{fig:halfspaces}, such a hyperplane separates $\\mathbb{R}^n$ into two parts on either side of it.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/halfspaces}\n\\caption{A plane separates $\\mathbb{R}^3$ into two parts on either side of it.}\n\\label{fig:halfspaces}\n}\nThese are known as open half-spaces and can be obtained by transforming the linear equation into the strict linear inequalities: $a_1 x_1 + a_2 x_2 + \\cdots + a_n x_n < b$ for the half-space below the hyperplane and $a_1 x_1 + a_2 x_2 + \\cdots + a_n x_n > b$ for the one above it.\nIf non-strict linear inequalities are used instead (\\ie\\ using $\\leq$ and $\\geq$ instead of $<$ and $>$), these \\emph{closed half-spaces} also contain the points on the hyperplane.\n\nConsidering that a point can be described as a tuple of its coordinates, a hyperplane as a tuple of its coefficients, and similar constructions are possible for many other objects (\\eg\\ a sphere based on a centre point and radius), it becomes possible to have a \\emph{computer representation} of these objects simply by storing tuples of numbers in a data structure\\footnote{This hides the fact that using real numbers in a computer is very difficult in practice, thus floating-point approximations are generally used instead \\citep{Goldberg91}.\nThe main consequences of this in spatial modelling are discussed in \\refse{se:computerarithmetic}.}.\nMoreover, it becomes possible to use them as a basis to describe other, more complex objects by using them as building blocks, either directly or using some of the topological concepts described in the next section, \\eg\\ them forming the boundary of another object.\n\nSince analytic geometry allows the description of objects as sets of points in $\\mathbb{R}^n$, as shown in \\reffig{fig:boolean}, it is also possible to define objects based on Boolean set operations of their point sets.\n\\begin{figure}[hb]\n\\centering\n\\subfloat[$\\mathbb{A}$ (purple) and $\\mathbb{B}$ (blue)]{\n\\includegraphics[width=0.5\\linewidth]{figs/boolean}\n\\label{subfig:boolean}}\n% \\quad\n\\subfloat[Intersection: $\\mathbb{A} \\cap \\mathbb{B}$]{\n\\includegraphics[width=0.5\\linewidth]{figs/boolean-intersection}\n\\label{subfig:boolean-intersection}}\n\\\\\n\\subfloat[Union: $\\mathbb{A} \\cup \\mathbb{B}$]{\n\\includegraphics[width=0.5\\linewidth]{figs/boolean-union}\n\\label{subfig:boolean-union}}\n% \\quad\n\\subfloat[Difference: $\\mathbb{A} - \\mathbb{B}$]{\n\\includegraphics[width=0.5\\linewidth]{figs/boolean-difference}\n\\label{subfig:boolean-difference}}\n\\caption[Objects can be defined using Boolean set operations]{Based on two balls $\\mathbb{A}$ and $\\mathbb{B}$, other objects that can be defined using Boolean set operations.}\n\\label{fig:boolean}\n\\end{figure}\n\n\\section{Topology}\n\\label{se:topology}\n\nTopology is the mathematical study of the shape of objects, growing out of the analysis of certain problems in geometry, such as the boundaries of objects and the different possible notions of connectedness.\nIn particular, it studies the properties of certain objects that are preserved under so-called \\emph{topological transformations} or \\emph{continuous maps}, which include stretching and bending but exclude tearing or gluing.\n\nThere are two branches of topology that are most relevant in the context of spatial modelling, \\emph{point-set topology} and \\emph{algebraic topology}, respectively presented in \\refse{ss:point-set-topology} and \\refse{ss:algebraic-topology}.\nPoint-set topology describes space using concepts derived mainly from set theory, representing objects as continuous sets of points.\nThe properties of these sets and the relationships between multiple sets can then be analysed and described.\nAlgebraic topology adds concepts from abstract algebra as well, representing objects as structured sets of discrete elements, such as points, edges and faces.\nAs these elements and the relationships between them are both discrete, it is possible to use a wide variety of algorithmic methods on them, including graph theory, combinatorics, algorithmic algebra, and computational geometry and topology.\n\n\\subsection{Point-set topology}\n\\label{ss:point-set-topology}\n\nPoint-set topology, also known as general topology, describes objects as sets of points satisfying certain conditions, such as those in the construction in \\reffig{fig:pointset}.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/pointset}\n\\caption[Two rectangles and two points defined as point sets]{The rectangle $\\mathbb{A}$ is represented by the set of points where $1 \\leq x \\leq 4$ and $1 \\leq y \\leq 3$. In more compact (set builder) notation, $\\mathbb{A} = \\left\\{ (x,y) \\middle| x \\in [1,4] \\wedge y \\in [1,3] \\right\\}$.\nFor the other objects, rectangle $\\mathbb{B} = \\left\\{ (x,y) \\middle| x \\in [2,3] \\wedge y \\in [1,2] \\right\\}$, point $a \\in \\mathbb{A}$, point $b \\in \\mathbb{B}$ and point $b \\in \\mathbb{A}$.\n$\\mathbb{B}$ is a subset of $\\mathbb{A}$ (\\ie\\ $\\mathbb{B} \\subset \\mathbb{A}$).\n}\n\\label{fig:pointset}\n}\nThese objects can then be analysed based on the properties of the sets that describe them, such as whether a set is bounded or unbounded, has a certain number of holes, or is orientable or unorientable.\nWhen multiple objects are present, the relationships between their corresponding sets can be analysed as well, such as whether they are touching or overlapping, or whether it is possible to define a function that maps between these sets.\n\nPoint-set topology works with \\emph{topological spaces}, a much more general notion than that of Euclidean space.\nThis allows the description of different types of space with different properties.\nA topological space consists of a set of points and a \\emph{topology} on them satisfying a series of axioms.\n\\citet{Edelsbrunner14} provides the following simple formulation.\nGiven a set of points $\\mathbb{X}$, a topology of $\\mathbb{X}$ is a collection of subsets, which are called open sets\\footnote{Note that there are alternative definitions based on the concepts of closed sets or of neighbourhoods \\citep{Hausdorff14}. For a simple definition using neighbourhoods in a GIS context see \\citet[\\S{}3.2.2]{Worboys04}.}, such that:\n\\begin{itemize}\n\\item $\\mathbb{X}$ is open and the empty set is open;\n\\item the intersection of any two open sets is open;\n\\item the union of any family of open sets is open.\n\\end{itemize}\n\nWhile the definition of an open set for general topological spaces is rather complex, in the context of spatial modelling we are generally interested in Euclidean space, which has a straightforward definition analogous to the concept of an open interval in 1D (\\reffig{fig:intervals}).\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/intervals}\n\\caption[Open and closed intervals]{An open interval $\\mathbb{C} = (0,3) = \\left\\{x \\middle| 0 < x < 3 \\right\\}$ does not include its endpoints. By contrast, a closed interval $\\mathbb{D} = [0,3] = \\left\\{x \\middle| 0 \\leq x \\leq 3 \\right\\}$ includes its endpoints.}\n\\label{fig:intervals}\n}\nA point set $\\mathbb{S}$ in Euclidean space is open if, given any point $p \\in \\mathbb{S}$, there exists a real number $\\epsilon > 0$ such that, given any point $q$ whose Euclidean distance to $p$ is smaller than $\\epsilon$, then $q \\in \\mathbb{S}$ as well.\nA point set is closed when the point set formed by its complement is open.\nAny point on an open interval fulfils these conditions, but the endpoints of a closed interval do not.\nNote that it is possible for a set to be open \\emph{and} closed (\\eg\\ an interval containing only one of its endpoints).\n\nFor example, in 2D, the plane together with the topology generated by the Euclidean metric is the topological space known as the \\emph{Euclidean topology of the plane}, which can be defined based on \\emph{open disks}, which are analogous to 1D open intervals.\nAn open disk is the set of points closer to a point $p \\in \\mathbb{R}^2$ than a non-zero distance $r$, such as the unit open disk shown in \\reffig{fig:unitopendisk}.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/unitopendisk}\n\\caption[The unit open disk]{The unit open disk, \\ie\\ an open disk of radius 1 centred at the origin can be defined as $\\mathbb{D} = \\left\\{ x \\in \\mathbb{R}^2 \\middle| \\| x \\| < 1 \\right\\}$.}\n\\label{fig:unitopendisk}\n}\nIt is easy to see that as these 2D disks do not contain their boundaries, the intersection of any two open disks and the union of any number of disks are both open.\n\nBased on the concepts of open intervals in 1D, open disks in 2D, or open balls when talking about any dimension, it is possible to partition a Euclidean space into three parts: its \\emph{interior}, \\emph{boundary} and \\emph{exterior}.\nAn example of these is shown in \\reffig{fig:annulus}.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/annulus}\n\\caption[An annulus partitions the Euclidean plane into three parts]{An annulus with boundary partitions the Euclidean plane into three parts: its interior (yellow), its boundary (black) and its exterior (the rest of this page).\nNote that none of these necessarily have to be connected.}\n\\label{fig:annulus}\n}\nThe \\emph{interior} of a point set $\\mathbb{S}$ consists of all points where there exists an open ball centred at them such that all the points in the ball are in $\\mathbb{S}$, the boundary of $\\mathbb{S}$ consists of the points where all possible open balls centred at them have points in $\\mathbb{S}$ and out of $\\mathbb{S}$, and the exterior of $\\mathbb{S}$ consists of all points where there exists an open ball centred at them such that all the points in the ball are out of $\\mathbb{S}$.\nThe \\emph{closure} of $\\mathbb{S}$ is the union of its interior and its boundary.\nThe \\emph{regularisation} of $\\mathbb{S}$ is the closure of its interior and a point set is thus \\emph{regular} when it is equal to its regularisation.\n\nOnce objects are defined as sets of points, point-set topology works with functions that relate these sets to each other.\nA function from one point set to another is said to be \\emph{continuous} if the preimage (\\ie\\ the inverse image) of every open set is open.\nIf a function is continuous and its inverse function is also continuous, it is known as a \\emph{homeomorphism}.\nWhen such a function exists between two point sets, they are said to be \\emph{homeomorphic} or, more informally, \\emph{topologically equivalent}, such as the two objects shown in \\reffig{fig:homeomorphism}.\n\n\\begin{figure}[b]\n\\centering\n\\subfloat[A coffee mug]{\\includegraphics[width=\\marginparwidth]{figs/mug}} \\quad\n\\subfloat[A donut]{\\includegraphics[width=\\marginparwidth]{figs/donut}}\n\\caption[A coffee mug and a donut are homeomorphic]{A coffee mug and a donut are homeomorphic\\protect\\footnotemark.\nIntuitively, this can be known as it is possible to deform one into the other.\nThe mug was rendered from the model at \\url{http://www.thingiverse.com/thing:7953}.}\n\\label{fig:homeomorphism}\n\\end{figure}\n\\footnotetext{Related to the joke: `A topologist is a mathematician who can't tell the difference between a coffee mug and a donut'.}\n\n\\begin{figure*}[tbp]\n\\centering\n\\includegraphics[width=\\linewidth]{figs/konigsberg}\n\\caption[The Seven Bridges of K\\\"onigsberg]{The problem of the Seven Bridges of K\\\"onigsberg asks whether it is possible to find a route through the city that would cross each bridge (highlighted in red) exactly once. \\citet{Euler41} proved that there is no such route in terms of a graph. Whenever one enters a piece of land by a bridge, one has to leave it by another bridge except at the beginning or end of the route. Thus, there must be an \\emph{even} number of bridges connected to all but (at most) two pieces of land. Since all pieces of land have an \\emph{odd} number of bridges, the problem has no solution. Based on an image from a 1613 engraving by Joachim Bering.}\n\\label{fig:konigsberg}\n\\end{figure*}\n\nAnother important topological concept is that of a manifold.\nA manifold is a topological space that is homeomorphic to the Euclidean space of a certain dimension.\nIntuitively, this means that a manifold locally resembles Euclidean space, even if globally it does not.\nFor example, a line and a circle are 1-manifolds, while a plane, a sphere and a torus are 2-manifolds.\nGenerally, when the term manifold is used in GIS it refers to a 2-manifold.\n\n\\subsection{Algebraic topology}\n\\label{ss:algebraic-topology}\n\nConceptually based on point-set topology, \\emph{algebraic topology}, also known as combinatorial topology, uses concepts from abstract algebra in order to analyse topological spaces.\nA famous early application involved the answer to the problem of the Seven Bridges of K\\\"onigsberg by \\citet{Euler41}, explained in \\reffig{fig:konigsberg}.\nHowever, the real foundations of the field were set when many of its concepts were formalised in algebraic form by \\citet{Poincare95}.\n\nAlgebraic topology works by relating topological spaces to groups with specific properties, often by creating combinatorial analogues of such spaces, from which their properties can be extracted using algebraic methods \\citep{Henle94}, which can be applied algorithmically.\nAs it uses discrete structures rather than continuous point sets, it is often more suited to computer implementations of topological concepts than point-set topology \\citep[\\S{}3.3.5]{Worboys04}.\n\nTwo constructions of algebraic topology are widely used as the basis of GIS:\\ \\emph{simplicial complexes} and \\emph{cell complexes}.\nAn $n$-dimensional simplicial complex is a structure made of connected \\emph{simplices}, the simplest objects that can be built in any dimension.\nAs shown in \\reffig{fig:simplex}, an $n$-dimensional simplex ($n$-simplex) is a combinatorial primitive made from a set of $n+1$ vertices.\n\\marginpar{\n\\captionsetup{type=figure}\n\\includegraphics[width=\\marginparwidth]{figs/simplex}\n\\caption[0-, 1-, 2- and 3-simplices]{An $n$-dimensional simplex is a combinatorial primitive made from a set of $n+1$ vertices. A 0-simplex is thus a point, a 1-simplex is a line segment, a 2-simplex is a triangle, and a 3-simplex is a tetrahedron. Here they are shown as if embedded in $\\mathbb{R}^3$.}\n\\label{fig:simplex}\n}\n\\reffig{fig:simplicescampus} shows a group of buildings represented as a 3D simplicial complex.\n\\begin{figure*}[b]\n\\centering\n\\includegraphics[width=\\linewidth]{figs/simplicescampus}\n\\caption[The TU Delft campus as a 3D simplicial complex]{The buildings in the TU Delft campus are represented as a 3D simplicial complex, such that each separate building is a set of adjacent tetrahedra. Note that only the tetrahedra's edges are shown here.}\n\\label{fig:simplicescampus}\n\\end{figure*}\nA 0D simplicial complex consists of a set of discrete points (\\ie\\ a point cloud) and a 1D simplicial complex is a plane graph.\nA 2D simplicial complex is known as a \\emph{triangulation} and a 3D simplicial complex as a \\emph{tetrahedralisation}.\n\nA $j$-dimensional face ($j$-face) of an $i$-simplex, $j < i$, is a $j$-simplex made from a proper subset of its vertices.\nSometimes the dimension of the face is omitted and it can be deduced from the context, but in GIS it generally refers to each of the $i+1$ $(i-1)$-faces of an $i$-simplex.\nIn the context of an $i$-dimensional simplicial complex, a face refers to each of the $i$-simplices in the complex, such as the triangles in a triangular mesh.\n\nMore formally, a simplicial complex can be defined as a collection of simplices such that:\n\\begin{itemize}\n\\item\nevery face of a simplex is also in the simplicial complex;\n\\item\nthe intersection of any two simplices is either empty or is a common face of both of them\\footnote{Note that this implies a definition where a simplex contains its boundary.}.\n\\end{itemize}\n\nBased on the set of common vertices shared by two simplices, it is possible to define certain \\emph{topological relationships} between them.\nTwo $i$-simplices are said to be adjacent if they have a common $(i-1)$-face.\nAn $i$-simplex and a $j$-simplex, $i \\neq j$, are said to be incident if either is a face of the other.\n\nA cell complex is a structure made of connected \\emph{cells}, where an $i$-dimensional cell ($i$-cell) is an object homeomorphic to an open $i$-ball (\\ie\\ point, open arc, open disk and open ball).\n0-cells are known as vertices, 1-cells as edges, 2-cells as faces and 3-cells as volumes.\nConsidering only linear geometries, 1-cells are thus line segments, 2-cells polygons and 3-cells polyhedra.\n\\reffig{fig:cellscampus} shows a group of buildings represented as a 3D cell complex.\n\\begin{figure*}[tbp]\n\\centering\n\\includegraphics[width=\\linewidth]{figs/cellscampus}\n\\caption[The TU Delft campus as a 3D cell complex]{The buildings in the TU Delft campus are represented as a 3D cell complex. All the 2-cells of a 3-cell are shown in the same colour, the 1-cells are shown as black lines.}\n\\label{fig:cellscampus}\n\\end{figure*}\n\nA $j$-dimensional face ($j$-face) of an $i$-cell is a $j$-cell, $j \\leq i$, that lies on the boundary of the $i$-cell.\nA facet of an $i$-cell is an $(i-1)$-face of the cell.\nAs in a simplicial complex, two $i$-cells are said to be adjacent if they have a common facet, and an $i$-cell and a $j$-cell, $i \\neq j$, are said to be incident if either is a face of the other.\nIn the context of an $i$-dimensional cell complex, a face refers to each of the $i$-cells in the complex, such as the polygons in a polygonal mesh.\n\nMore formally, a cell complex can be defined inductively as in \\citet{Hatcher02}.\nAn $n$-dimensional cell complex is built by starting from a set of isolated vertices, and $\\forall 0 < i \\leq n$ an $i$-cell is built by attaching itself to the $(i-1)$-faces (facets) on its boundary, these facets having been previously added to the complex.\nThat is, an edge is built by linking the vertices on its boundary, a surface by linking the edges on its boundary, a volume by linking the surfaces on its boundary, and so on.\nLike in a simplicial complex, a facet of a $n$-cell in an $n$-dimensional cell complex lies between it and an adjacent $n$-cell, unless it is on the boundary of the complex.\n\nApart from the concepts of adjacency, incidence and other relationships between between individual simplices and cells in a complex, it is also possible to define relations and transformations between entire simplicial/cell complexes.\nThe \\emph{Poincar\\'e duality} theorem \\citep{Poincare93}\\footnote{It was only formulated as an observation without proof in \\citet{Poincare93}. \\citet{Poincare95} describes it in more detail but contains a flawed proof.\nValid proofs would have to wait until \\citet{Poincare99,Poincare00}.} states that for every $n$-dimensional simplicial/cell complex, there exists a \\emph{dual simplicial/cell complex} of the same dimension, where for every dimension $i$, the $i$-simplices/cells in the original complex are mapped one-to-one to $(n-i)$-simplices/cells in the dual complex.\nThe \\emph{duality transformation} is an operation that creates the dual of a simplicial/cell complex.\nThis can be seen as a generalisation of the concept of a dual graph in 2D, where a graph $G$ has a dual $G^\\ast$, such that vertices in $G$ correspond to faces in $G^\\ast$, edges in $G$ correspond to edges in $G^\\ast$ and faces in $G$ correspond to vertices in $G^\\ast$.\n\nFor example, considering the Platonic solids in \\reffig{fig:ps}, the tetrahedron is self-dual (\\ie\\ it is dual to itself), the octahedron is dual to the cube (and vice versa), and the dodecahedron is dual to the icosahedron (and vice versa).\n\\begin{figure}[tbp]\n\\centering\n\\subfloat[]{\n\\includegraphics[width=0.15\\textwidth]{figs/ps_tetrahedron}\n\\label{subfig:ps-tetrahedron}}\n\\quad\n\\subfloat[]{\n\\includegraphics[width=0.15\\textwidth]{figs/ps_octahedron}\n\\label{subfig:ps-octahedron}}\n\\quad\n\\subfloat[]{\n\\includegraphics[width=0.15\\textwidth]{figs/ps_hexahedron}\n\\label{subfig:ps-hexahedron}}\n\\quad\n\\subfloat[]{\n\\includegraphics[width=0.15\\textwidth]{figs/ps_dodecahedron}\n\\label{subfig:ps-dodecahedron}}\n\\quad\n\\subfloat[]{\n\\includegraphics[width=0.15\\textwidth]{figs/ps_icosahedron}\n\\label{subfig:ps-icosahedron}}\n\\caption[The Platonic solids]{The Platonic solids are the five regular polyhedra that have regular polygonal faces: (a) tetrahedron, (b) octahedron, (c) cube or hexahedron, (d) dodecahedron, and (e) icosahedron. From Wikimedia Commons.}\n\\label{fig:ps}\n\\end{figure}\nThis transformation can be seen by creating a new vertex at the centre point of the face of the Platonic solid, connecting these vertices when their dual faces are adjacent.\nThe original vertices become faces whose number of vertices is equal to the number of originally incident faces.", "meta": {"hexsha": "421068423c5d1859e32322fd87da8c0965e83c2e", "size": 34250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math.tex", "max_stars_repo_name": "kenohori/thesis", "max_stars_repo_head_hexsha": "31c026184ba535a491d6a3981c29dd897cba84b5", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 38, "max_stars_repo_stars_event_min_datetime": "2016-03-04T13:55:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T07:28:24.000Z", "max_issues_repo_path": "math.tex", "max_issues_repo_name": "kenohori/thesis", "max_issues_repo_head_hexsha": "31c026184ba535a491d6a3981c29dd897cba84b5", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-02-23T16:34:29.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-27T10:12:11.000Z", "max_forks_repo_path": "math.tex", "max_forks_repo_name": "kenohori/thesis", "max_forks_repo_head_hexsha": "31c026184ba535a491d6a3981c29dd897cba84b5", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-10-11T04:08:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-28T23:58:06.000Z", "avg_line_length": 96.4788732394, "max_line_length": 677, "alphanum_fraction": 0.7592116788, "num_tokens": 9410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482725, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6509621881795996}}
{"text": "\\section{Convergence Analysis}\n\nGiven that the result of \\hogwild, in the absence of noise generated by the\nasynchronous updates of $x$, henceforth denoted {\\it asynchronous noise}, is\nequivalent to a stochastic gradient method, we should expect convergence rates\nsimilar to those of stochastic gradient, should noise be small. Take for example\nthe typical linear least squares loss function $f(x) = \\frac{1}{2n}\n\\norm{Dx-b}_2^2$, where $x \\in \\mathbb{R}^n$ and $D \\in \\mathbb{R}^{n \\times n}$\na diagonal matrix. Writing this as a sum of each data entry:\n\\[\n  f(x) \n  = \\frac{1}{2n} \\sum_{k=1}^n (D_{ii}x_i - b_i)^2\n  = \\frac{1}{n} \\sum_{k=1}^n f_i(x)\n  \\implies\n  (\\nabla f_i(x))_k\n  =\n  \\begin{cases}\n    D_{ii}(D_{ii}x_i - b_i), & k = i \\\\\n    0, & k = 0\n  \\end{cases}\n\\]\nBecause our $\\nabla f_i(x)$'s only have a single entry in their own component, we\ncan see that as long as no other thread is working on component $i$\nsimultaneously, no asynchronous noise will be generated; should we use \\hogwild\\\nwithout replacement then this is guaranteed. In the original paper\n\\cite{2011NRRW}, sparsity of the vector $\\nabla f_i(x)$ was required in order to\nguarantee convergence, but as we'll see later, this isn't always necessary.\n\nAs a baseline of comparison, we first state a result on the convergence of the\nstochastic gradient method:\n\\begin{theorem} \\label{thm:sgd}\n  (Convergence of the Stochastic Gradient Method \\cite{2016BCN}) Let $F:\n  \\mathbb{R}^d \\to \\mathbb{R}$ be an objective function we're seeking to\n  minimize. We can write this as either an expected risk $F(x)\n  = \\mathbb{E}_\\xi{f(x, \\xi)}$, or an empirical risk $F(x) = \\frac{1}{n}\n  \\sum_{k=1}^n f_k(x)$.  Under the assumptions:\n  \\begin{enumerate}[(1)]\n    \\item $F$ is continuously differentiable and $\\nabla F$ is Lipschitz\n      continuous with Lipshitz constant $L$, i.e.\n      \\[\n        \\norm{\\nabla F(x) - \\nabla F(y)} \n        \\leq\n        L\\norm{x-y}, \\forall x,y \\in \\mathbb{R}^d\n      \\]\n    \\item $F$ is strongly convex with constant $c$, i.e.\n      \\[\n        F(x) \\geq F(y) + \\nabla F(y)^T (x-y) + \\frac{1}{2}c\\norm{x-y}^2, \n        \\forall x,y \\in \\mathbb{R}^d\n      \\]\n    \\item $F$ is bounded below over the region explored by stochastic gradient\n      method.\n    \\item In expectation, the vector $-\\nabla f(x_k, \\xi_k)$ is a descent\n      direction for $F$ with norm bounded by it's own norm. That is: $\\exists\n      \\mu_G \\geq \\mu > 0$ such that $\\forall k \\in \\mathbb{N}$:\n      \\[\n        \\nabla F(x_k)^T \\E{\\nabla f(x_k,\\xi_k)} \\geq \\mu \\norm{\\nabla F(x_k)}^2\n        \\text{ and }\n        \\norm{ \\E{\\nabla f(x_k,\\xi_k)} } \\geq \\mu_G \\norm{\\nabla F(x_k)}\n      \\]\n    \\item $\\exists M, M_V \\geq 0$ such that $\\forall k\\in \\mathbb{N}$:\n      \\[\n        \\Var{\\nabla f(x_k, \\xi_k)} \\leq M + M_V \\norm{\\nabla F(x_k)}^2\n      \\]\n  \\end{enumerate}\n  Then, assuming a fixed stepsize $\\alpha$ (a.k.a. learning rate), satisfying\n  $\\alpha \\in (0, \\mu/ LM_g]$, we have:\n  \\[\n    \\E{F(x_k) - F_*} \n    \\leq \n    \\frac{\\alpha LM}{2c\\mu} + (1 - \\alpha c \\mu)^{k-1}\n    \\left(\n      F(x_1) - F_* - \\frac{\\alpha LM}{2c\\mu}\n    \\right)\n  \\]\n  and if we instead choose $\\alpha$ diminishing, i.e. let $\\alpha_k\n  = \\frac{\\beta}{\\gamma + k}$ where $\\beta > 1/c\\mu, \\gamma > 0$ are chose such\n  that $\\alpha_1 \\leq \\mu/LM_G$, then:\n  \\[\n    \\E{F(x_k) - F_*} \n    \\leq \n    \\frac{1}{\\gamma + k} \\max\n    \\left\\{\n      \\frac{\\beta^2 LM}{2(\\beta c \\mu -1)},\n      (\\gamma + 1)(F(x) - F_*)\n    \\right\\}\n  \\]\n\\end{theorem}\nThe result is technical, and very long to prove, so I just refer to the article\n\\cite{2016BCN} for it. Regardless, the last result in the above theorem is what\nwe strive for in $\\hogwild$: convergence in $\\mathcal{O}(1/k)$ time.\n\n\\input{./src/convergence/theory.tex}\n\\input{./src/convergence/numerical.tex}\n", "meta": {"hexsha": "e46ff0e8253628000026baddb86f50aa2bd11382", "size": 3799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TeXsrc/src/convergence.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.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.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": 40.414893617, "max_line_length": 81, "alphanum_fraction": 0.6264806528, "num_tokens": 1334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6509554277424383}}
{"text": "\\section[Simplex Algorithm of Nelder and Mead]{Simplex Algorithm of Nelder and Mead with the Extension of O'Neill}\n\\lab{sec:simAlgNelMea}\n\nThe Simplex algorithm of Nelder and Mead is a derivative free optimization algorithm.\nIt can be used to seek a solution of problem $\\mathbf P_c$ defined in~\\eqref{sub:Proc} \nand problem $\\mathbf P_{cg}$ defined in~\\eqref{sub:Procg},\nwith constraints on the dependent parameters implemented as \ndescribed in Section~\\ref{cha:conGen}.\nThe number of independent parameters $n$ must be larger than 1.\\\\\n\nThe Simplex algorithm constructs an $n$-dimensional simplex\nin the space that is spanned by the independent parameters.\nAt each of the $(n+1)$ vertices of the simplex, the value of the cost function is evaluated. In each iteration step, the point with the highest value of the cost function is replaced by another point. The algorithm consists of three main operations: (a) \\emph{point reflection}, (b) \\emph{contraction of the simplex} and (c) \\emph{expansion of the simplex}.\\\\\n\n\nDespite the well known fact \nthat the Simplex algorithm can fail to converge to a stationary \npoint~\\cite{Kelley1999:2,Torczon1989,Kelley1999:1,Wright1996,McKinnon1998,Lagarias1998}, both in practice and theory,\nparticularly if the dimension of independent variables is large, \nsay bigger than $10$~\\cite{Torczon1989}, it is an often used algorithm.\nSeveral improvements to the Simplex algorithm\nor algorithms that were motivated by the Simplex algorithm exist,\nsee for example~\\cite{Kelley1999:2,Torczon1989,Kelley1999:1,Tseng1999}.\nHowever, in GenOpt, we use the original Nelder-Mead algorithm~\\cite{NelderMea1965}\nwith the extension of O'Neill~\\cite{ONeill1971}.\nOptionally, the here implemented algorithm allows using\na modified stopping criteria.\\\\\n\nWe will now explain the different steps of the Simplex algorithm.\n\n\n\\subsection{Main Operations}\n\\begin{figure}\n  \\centering\n  \\mbox{ \\subfigure[Reflection.]{\\epsfig\n      {file=img/nel_mea_ref.eps, bb=35 265 225 420, scale=0.9, clip=}}\n    \\subfigure[Expansion.]{\\epsfig\n      {file=img/nel_mea_exp.eps, bb=35 265 225 420, scale=0.9, clip=}} }\n  \\mbox{ \n    \\subfigure[Partial inside contraction.]{\\epsfig\n      {file=img/nel_mea_par_ins.eps, bb=35 265 225 420, scale=0.9, clip=}}\n    \\subfigure[Partial outside contraction.]{\\epsfig\n      {file=img/nel_mea_par_out.eps, bb=35 265 225 420, scale=0.9, clip=}} }\n  \\mbox{\n    \\subfigure[Total contraction.]{\\epsfig\n      {file=img/nel_mea_tot.eps, bb=35 265 225 420, scale=0.9, clip=}} }\n  \\caption{Simplex operations.}\n  \\label{fig:simOpeAll}\n\\end{figure}\nThe notation defined below is used in describing the main operations. The operations are illustrated in Fig.~\\ref{fig:simOpeAll} where for simplicity \na two-dimensional simplex is illustrated.\\\\\n\nWe now introduce some notation and definitions.\n\\begin{subequations}\n\\begin{enumerate}\n\\item We will denote by $\\mathbf{I} \\triangleq \\{1, \\, \\ldots \\, , \\, n+1\\}$\nthe set of all vertex indices.\n\\item\nWe will denote by $l \\in \\mathbf I$ the smallest index in $\\mathbf I$\nsuch that\n\\begin{equation}\nl = \\argmin_{i \\in \\mathbf{I} }  f(x_i).\n\\label{eq:simIndL}\n\\end{equation}\nHence, $f(x_l) \\le f(x_i)$, for all $i \\in \\mathbf I$. \n\\item\nWe will denote by $h \\in \\mathbf I$ the smallest index in $\\mathbf I$\nsuch that\n\\begin{equation}\nh = \\argmax_{i \\in \\mathbf{I} }  f(x_i).\n\\label{eq:simIndH}\n\\end{equation}\nHence, $f(x_h) \\ge f(x_i)$, for all $i \\in \\mathbf I$. \n\\item \nLet $x_i$, for $i \\in \\mathbf I$, denote the simplex vertices, and let $h$ be as in~\\eqref{eq:simIndH}.\nWe will denote by $x_c \\in \\Re^n$ the {\\em centroid} of the simplex, defined as\n\\begin{equation}\nx_c \\triangleq \\frac{1}{n} \\, \n\\mathop{\\sum_{i=1}}_{i \\neq h}^{n+1} x_i\n\\label{eq:simCenDef}\n\\end{equation}\n\\end{enumerate}\n\\end{subequations}\n\nNext, we introduce the three main operations.\n\\begin{subequations}\n\\begin{description}\n\\item[Reflection]\nLet $h \\in \\mathbf I$ be as in~\\eqref{eq:simIndH} and let\n$x_c$ be as in~\\eqref{eq:simCenDef}.\nThe reflection of $x_h \\in \\Re^n$ to a point denoted as \n$x^* \\in \\Re^n$ is defined as\n\\begin{equation}\n   x^* \\triangleq (1+\\alpha) \\, x_c - \\alpha \\, x_h,\n\\label{eq:simRefOpe}\n\\end{equation}\nwhere $\\alpha \\in \\Re$, with $\\alpha > 0$, is\ncalled the \\emph{reflection coefficient}.\n\n\\item[Expansion of the simplex]\nLet $x^* \\in \\Re^n$ be as in~\\eqref{eq:simRefOpe} and\n$x_c$ be as in~\\eqref{eq:simCenDef}.\nThe expansion of $x^* \\in \\Re^n$ to a point denoted as \n$x^{**} \\in \\Re^n$ is defined as\n\\begin{equation}\n   x^{**} \\triangleq \\gamma \\, x^* + (1-\\gamma) \\, x_c,\n\\label{eq:simExp}\n\\end{equation}\nwhere $\\gamma \\in \\Re$, with $\\gamma > 1$, is\ncalled the \\emph{expansion coefficient}.\n\n\\item[Contraction of the simplex]\nLet $h \\in \\mathbf I$ be as in~\\eqref{eq:simIndH} and\n$x_c$ be as in~\\eqref{eq:simCenDef}.\nThe contraction of $x_h \\in \\Re^n$ to a point denoted as \n$x^{**} \\in \\Re^n$ is defined as\n\\begin{equation}\n   x^{**} \\triangleq \\beta \\, x_h + (1 - \\beta) \\, x_c,\n  \\label{eq:simAlgCon}\n\\end{equation}\nwhere $\\beta \\in \\Re$, with $0 < \\beta < 1$, is\ncalled the \\emph{contraction coefficient}.\n\\end{description}\n\\end{subequations}\n\n% ---------------------------------\n\\subsection{Basic Algorithm}\nIn this section, we describe the basic Nelder and Mead algorithm~\\cite{NelderMea1965}. \nThe extension of O'Neill and the modified restart criterion are discussed later.\nThe algorithm is as follows:\n\\begin{enumerate}\n\n\\item Initialization: \nGiven an initial iterate $x_1 \\in \\Re^n$,\na scalar $c$, with $c=1$ in the initialization,\na vector $s \\in \\Re^n$ with user-specified step sizes for each independent parameter,\nand the set of unit coordinate vectors $\\{ e_i \\}_{i=1}^n$,\nconstruct an initial simplex with vertices,\nfor $i \\in \\{1, \\ldots , n \\}$,\n\\begin{equation}\n  x_{i+1} = x_1 + c \\, s^i \\, e_i.\n\\label{eq:simAlgIni}\n\\end{equation}\nCompute $f(x_i)$, for $i \\in \\mathbf I$.\n\\item \\label{des:simAlgRef} Reflection: \nReflect the worst point, that is, compute $x^*$ as in~\\eqref{eq:simRefOpe}.\n\\item \\label{des:simAlgCheBes} Test whether we got the best point:\nIf $f(x^*) < f(x_l)$, expand the simplex using~\\eqref{eq:simExp}\nsince further improvement in this direction is likely.\nIf $f(x^{**})< f(x_l)$, then \n$x_h$ is replaced by $x^{**}$,\notherwise $x_h$ is replaced by $x^*$, and \nthe procedure is restarted from \\ref{des:simAlgRef}.\n\n\\item \nIf it turned out under \\ref{des:simAlgCheBes} that $f(x^*) \\ge f(x_l)$,\nthen we check if the new point $x^*$ is the worst of all points:\nIf $f(x^*) > f(x_i)$, for all $i \\in \\mathbf I$, with $i \\ne h$, we contract \nthe simplex (see \\ref{des:simAlgCon}); \notherwise we replace $x_h$ by $x^*$ and \ngo to \\ref{des:simAlgRef}.\n\n\\item \\label{des:simAlgCon} \nFor the contraction, we first check if we should try a partial outside \ncontraction or a partial inside contraction: If $f(x^*) \\ge f(x_h)$,\nthen we try a partial inside contraction.\nTo do so, we leave our indices as is and \napply (\\ref{eq:simAlgCon}). \nOtherwise, we try a partial outside contraction. \nThis is done \nby replacing $x_h$ by $x^*$ and applying (\\ref{eq:simAlgCon}). \nAfter the partial inside or the partial outside contraction,\nwe continue at \\ref{des:simAlgCheWor}.\n\n\\item \\label{des:simAlgCheWor}\nIf $f(x^{**}) \\ge f(x_h)$\\footnote{ Nelder and Mead~\\cite{NelderMea1965} use the strict \ninequality $f(x^{**}) > f(x_h)$.\nHowever, if the user writes the cost function value with only a few \nrepresentative digits to a text file, \nthen the function looks like a step function if slow convergence is \nachieved. In such cases, $f(x^{**})$ might sometimes be equal to $f(x_h)$.\nExperimentally, it has been shown \nadvantageous to perform a total contraction rather than continuing with a reflection. \nTherefore, the strict inequality has been changed to a weak inequality.},\nwe do a total contraction of the \nsimplex by replacing $x_i \\leftarrow (x_i + x_l)/2$, for all $i \\in \\mathbf I$.\nOtherwise, we replace $x_h$ by $x^{**}$. \nIn both cases, we continue from \\ref{des:simAlgRef}.\n\\end{enumerate}\n\n\\begin{figure}\n\\centering\n\\epsfig{file=img/nel_mea_mov_tra.eps, bb=98 47 640 400, width=\\headwidth, clip=}\n\\caption{Sequence of iterates generated by the Simplex algorithm.}\n\\label{fig:simSeqAlg}\n\\end{figure}\n\n\n\nFig. \\ref{fig:simSeqAlg} shows a contour plot of a cost function $f \\colon \\Re^n \\to \\Re$ with a sequence of iterates\ngenerated by the Simplex algorithm.\nThe sequence starts with \nconstructing an initial simplex $x_1$, $x_2$, $x_3$. $x_1$ has the highest function value and is therefore \nreflected, which generates $x_4$. $x_4$ is the best point in the set $\\{x_1, x_2, x_3, x_4\\}$. Thus, it is further \nexpanded, which generates $x_5$. $x_2$, $x_3$ and $x_5$ now span the new simplex. In this simplex, $x_3$ is the \nvertex with the highest function value and hence goes over to $x_6$ and further to $x_7$. The process of reflection \nand expansion is continued again two times, which leads to the simplex spanned by $x_7$, $x_9$ and \n$x_{11}$. $x_7$ goes over to $x_{12}$ which turns out to be the worst point. Hence, we do a partial inside \ncontraction, which generates $x_{13}$. $x_{13}$ is better than $x_7$ so we use the simplex spanned by $x_9$, \n$x_{11}$ and $x_{13}$ for the next reflection. \nThe last steps of the optimization are for clarity not shown.\n\n\n% ---------------------------------\n\n\\subsection{Stopping Criteria}\nThe first criterion is a test of the variance of the function values at the vertices of the simplex\n\\begin{equation}\n\\frac{1}{n} \\, \\left(\n\\sum_{i=1}^{n+1} \\bigl( f(x_i) \\bigr)^2 -\n   \\frac{1}{n+1} \\, \\left(\\sum_{i=1}^{n+1} f(x_i)    \\right)^2 \\, \n\\right) < \\epsilon^2,\n \\label{eq:neaMeaVar}\n\\end{equation}\nthen the original implementation of the algorithm stops.\nNelder and Mead have chosen this stopping criterion based on the statistical problem\nof finding the minimum of a sum of squares surface.\nIn this problem, the curvature near the minimum yields information about\nthe unknown parameters.\nA slight curvature indicates a high sampling variance of the estimate.\nNelder and Mead argue that in such cases, there is no reason for finding \nthe minimum point with high accuracy.\nHowever, if the curvature is marked, \nthen the sampling variance is low and a higher accuracy in determining the optimal parameter set is desirable.\n\nNote that the stopping criterion~\\eqref{eq:neaMeaVar} requires the variance\nof the function values at the simplex vertices to be smaller \nthan a prescribed limit.\nHowever, if $f(\\cdot)$ has large discontinuities, which has been observed\nin building energy optimization problems~\\cite{WetterWright2003:1},\nthen the test~\\eqref{eq:neaMeaVar} may never be satisfied.\nFor this reason, among others, \nwe do not recommend using this algorithm if the cost function\nhas large discontinuities.\n\n\\pagebreak[4]\n% -------------------\n\\subsection{O'Neill's Modification}\nO'Neill modified the termination criterion by adding a further condition~\\cite{ONeill1971}. He checks \nwhether any orthogonal step, each starting from the best vertex of the current simplex, leads to a further \nimprovement of the cost function. \nHe therefore sets $c = 0.001$ and tests if\n\\begin{subequations}\n\\label{eq:optCheNelMeaOri}\n\\begin{equation}\n  f(x_l) < f(x)\n\\label{eq:optCheNelMeaOriCon}\n\\end{equation}\nfor all $x$ defined by\n\\begin{equation}\n   x \\triangleq x_l + c \\, s^i \\, e_i, \\qquad i \\in \\{1, \\ldots , n \\},\n  \\label{eq:optCheNelMeaOriCoo}\n\\end{equation}\nwhere $x_l$ denotes the best known point,\nand $s^i$ and $e_i$ are as in \\eqref{eq:simAlgIni}.\\\\\n\n% ----------------------------\n\\subsection{Modification of Stopping Criteria}\n\nIn GenOpt, (\\ref{eq:optCheNelMeaOri}) has been modified. It has been observed that users sometimes \nwrite the cost function value with only few representative digits to the output file. \nIn such cases, \n(\\ref{eq:optCheNelMeaOriCon}) is not satisfied if the write statement \nin the simulation program truncates \ndigits so that the difference $f(x_l)-f(x)$, where $f\\depd$ denotes the value that is\nread from the simulation output file, is zero.\nTo overcome this numerical problem, \n(\\ref{eq:optCheNelMeaOriCoo}) has been modified to\n\\begin{equation}\n   x = x_l + \\exp(j) \\, c \\, s^i \\, e_i, \\qquad i \\in \\{1, \\ldots , n \\}\n\\label{eq:optCheNelMeaOriMod}\n\\end{equation}\n\\end{subequations}\nwhere for each direction $i \\in \\{1, \\ldots , n \\}$, \nthe counter $j \\in \\Na$ is set to zero for the first trial and increased by one as long as \n$f(x_l) = f(x)$.\n\nIf (\\ref{eq:optCheNelMeaOriCon}) fails for any direction, then $x$ computed by \n(\\ref{eq:optCheNelMeaOriMod}) is the new starting point and a new simplex with side lengths $(c\\, s^i)$, $i \\in \\{1, \\ldots, n\\}$, is constructed.\nThe point $x$ that failed (\\ref{eq:optCheNelMeaOriCon}) is then used as the initial point $x_l$ in (\\ref{eq:simAlgIni}).\\\\\n\n\n\\begin{figure}\n  \\mbox{ \\subfigure[Sequence of iterates in the neighborhood of the minimum.]{\n  \\epsfig{file=img/nel_mea_res_tra.eps, bb=25 290 360 575, clip=, width=0.5\\headwidth} \\label{fig:neaMeaResTra} } \\quad\n\\subfigure[2-dimensional test function ``2D1''.]{\n  \\epsfig{file=img/fun_f2d1.eps, bb=120 95 740 500, width=0.5\\headwidth} \n\\label{fig:neaMeaTesFun} } }\n\\caption{Nelder Mead trajectory.}\n\\end{figure}\nNumerical experiments showed that during slow convergence the algorithm was restarted too frequently.\n\nFig.~\\ref{fig:neaMeaResTra} shows a sequence of iterates where the algorithm was restarted too frequently.\nThe iterates in the figure are part of the iteration sequence near the\nminimum of the test function shown in Fig.~\\ref{fig:neaMeaTesFun}. \nThe algorithm gets close to the minimum with appropriately large steps.\nThe last of these steps can be seen at the right of the figure.\nAfter this step, the stopping criterion (\\ref{eq:neaMeaVar}) was satisfied \nwhich led to a restart check, followed by a new construction of the simplex. From there on, the \nconvergence was very slow due to the small step size. After each step, the stopping criterion was satisfied \nagain which led to a new test of the optimality condition (\\ref{eq:optCheNelMeaOriCon}), followed by a \nreconstruction of the simplex. This check is very costly in terms of function evaluations and, furthermore, \nthe restart with a new simplex does not allow increasing the step size, though we are heading locally in \nthe right direction.\\\\\n\nO'Neill's modification prevents both excessive checking of the optimality condition as well as excessive \nreconstruction of the initial simplex. This is done by checking for convergence only after a predetermined \nnumber of steps (e.g., after five iterations). \nHowever, the performance of the algorithm depends \nstrongly on this number. As an extreme case, a few test runs were done where convergence was checked \nafter each step as in Fig. \\ref{fig:neaMeaResTra}. It turned out that in some cases no convergence was \nreached within a moderate number of function evaluations if $\\epsilon$ in (\\ref{eq:neaMeaVar}) is chosen \ntoo large, e.g., $\\epsilon = 10^{-3}$ (see Tab. \\ref{tab:nelMeaBenMarRes}).\\\\\n\n\\pagebreak[2]\nTo make the algorithm more robust, it is modified based on the following arguments:\n\\begin{enumerate}\n\\item\nIf the simplex is moving in the same direction in the last two steps, then the search is not \ninterrupted by checking for optimality since we are making steady progress in the moving direction.\n\\item\nIf we do \\emph{not} have a partial inside or total contraction immediately beyond us, then it is likely \nthat the minimum lies in the direction currently being explored. \nHence, we do not interrupt the search with a restart.\n\\end{enumerate}\n\nThese considerations have led to two criteria that both have to be satisfied to permit the convergence check according to (\\ref{eq:neaMeaVar}), which might be followed by a check for optimality.\\\\\n\nFirst, it is checked if we have done a partial inside contraction or a total contraction. If so, we \ncheck if the direction of the latest two steps in which the simplex is moving has changed by an angle of at \nleast $(\\pi / 2)$. \nTo do so, we introduce the center of the simplex, defined by\n\\begin{equation}\n  x_m \\triangleq \\frac{1}{n+1} \\, \\sum_{i=1}^{n+1} x_i,\n\\end{equation}\nwhere $x_i$, $i \\in \\{ 1, \\ldots, n\\}$, are the simplex vertices.\nWe also introduce the normalized direction of the simplex between two steps,\n\\begin{equation}\n  d_k \\triangleq \\frac{ x_{m, k} - x_{m, k-1} }\n{ \\| x_{m, k} - x_{m, k-1} \\| },\n\\end{equation}\nwhere $k \\in \\Na$ is the current iteration number.\n\nWe determine how much the simplex has changed its direction $d_k$ between two steps by \ncomputing the inner product $\\langle d_{k-1}, d_k \\rangle$. \nThe inner product is equal to the cosine of the angle $d_{k-1}$ and $d_k$.\nIf\n\\begin{equation}\n  \\cos \\phi_k = \\langle d_{k-1}, \\, d_k \\rangle \\le 0,\n  \\label{eq:nelMeaCosMov}\n\\end{equation}\nthen the moving direction of the simplex has changed by at least $\\pi / 2$.\nHence, the simplex has changed the exploration direction.\nTherefore, a minimum might be achieved and we need to test the variance of the \nvertices (\\ref{eq:neaMeaVar}), possibly followed by a test of (\\ref{eq:optCheNelMeaOriCon}).\\\\\n\n%---\nBesides the above modification, a further modification was tested: \nIn some cases, a reconstruction of the simplex after a failed check (\\ref{eq:optCheNelMeaOriCon})\nyields to slow convergence.\nTherefore, the algorithm was modified so that it continues at \npoint \\ref{des:simAlgRef} on page~\\pageref{des:simAlgRef} without reconstructing the simplex after \nfailing the test (\\ref{eq:optCheNelMeaOriCon}).\nHowever, reconstructing the simplex led in most of the benchmark tests to faster convergence. Therefore, \nthis modification is no longer used in the algorithm.\n\n\\subsection{Benchmark Tests}\n\\label{sec:algSimBenTes}\n\n\\begin{table}\n\\newcolumntype{C}{>{\\centering\\arraybackslash}X}\n\\begin{tabularx}{\\headwidth}{|p{2cm}|C|C|C|C|C|C|C|C|}\n\\hline\n & \\multicolumn{8}{|c|}{Accuracy} \\\\ \\cline{2-9}\n& \\multicolumn{4}{|c|}{$\\epsilon = 10^{-3}$} & \\multicolumn{4}{|c|}{$\\epsilon = 10^{-5}$} \\\\ \\hline\n\\raggedright Test function & Rosen-brock & 2D1 & Quad with I matrix & Quad with Q matrix & Rosen-brock & 2D1 & Quad with I matrix & Quad with Q matrix \\\\ \\hline\n\\raggedright Original, with reconstruction &  137  &  120  &  3061  &  1075  &  139  &  109  &  1066  &  1165 \\\\ \\hline\n\\raggedright Original, no reconstruction &  136  &  110  &  1436  &  1356  &  139  &  109  &  1433  &  1253 \\\\ \\hline\n\\raggedright Modified, with reconstruction &  145  &  112  &  1296  &  1015  &  152  &  111  &  1060  &  1185 \\\\ \\hline\n\\raggedright Modified, no reconstruction &  155  &  120  &  1371  &  1347  &  152  &  109  &  1359  &  1312 \\\\ \\hline\n\\end{tabularx}\n\\caption{Comparison of the number of function evaluations for different implementations of the simplex algorithm. See Appendix for the definition of the function.}\n\\label{tab:nelMeaBenMarRes}\n\\end{table}\n\n\\begin{figure}\n  \\centering\n  \\epsfig{file=img/nel_mea_ben.eps, bb=60 255 420 520, clip=} \n  \\caption{Comparison of the benchmark tests.}\n  \\label{fig:nelMeaBenMarRes}\n\\end{figure}\n\nTab.~\\ref{tab:nelMeaBenMarRes} shows the number of function evaluations and \nFig.~\\ref{fig:nelMeaBenMarRes} shows the relative number of function evaluations compared to the original \nimplementation for several test cases. The different functions and the parameter settings are given in the \nAppendix. \nThe only numerical parameter that was changed for the different optimizations is the accuracy, $\\epsilon$.\\\\\n\nIt turned out that modifying the stopping criterion is effective in most cases, \nparticularly if a new simplex is constructed after the check~\\eqref{eq:optCheNelMeaOriCon} failed.\nTherefore, the following two versions of the simplex algorithm are implemented in GenOpt:\n\\begin{enumerate}\n\\item\nThe base algorithm of Nelder and Mead, including the extension of O'Neill.\nAfter failing~\\eqref{eq:optCheNelMeaOriCon},\nthe simplex is \\emph{always} reconstructed with the new step size.\n\\item \nThe base algorithm of Nelder and Mead, including the extension of O'Neill,\nbut with the modified stopping criterion as explained above.\nThat is, the simplex is only reconstructed if its moving direction changed, \nand if we have an inside or total construction beyond us.\n\\end{enumerate}\n\n\\subsection{Keywords}\nFor the Simplex algorithm, the command file (see page~\\pageref{par:comFil}) must only contain continuous parameters.\\\\\n\nTo invoke the Simplex algorithm, the \\texttt{Algorithm} section of the GenOpt command file must \nhave following form:\n\\begin{lstlisting}\nAlgorithm{\n   Main                    = NelderMeadONeill;\n   Accuracy                = Double;   // 0 <  Accuracy\n   StepSizeFactor          = Double;   // 0 <  StepSizeFactor\n   BlockRestartCheck       = Integer;  // 0 <= BlockRestartCheck\n   ModifyStoppingCriterion = Boolean;\n}\n\\end{lstlisting}\n\n\\noindent The key words have following meaning:\n\\begin{codedescription}\n\\item[Main]\n   The name of the main algorithm.\n\\item[Accuracy]\nThe accuracy that has to be reached before the optimality condition is checked. \\texttt{Accuracy} is \ndefined as equal to $\\epsilon$ of (\\ref{eq:neaMeaVar}), page~\\pageref{eq:neaMeaVar}.\n\n\\item[StepSizeFactor]\nA factor that multiplies the step size of each parameter for \n(a) testing the optimality condition and \n(b) reconstructing the simplex.\n\\texttt{StepSizeFactor} is equal to $c$ in \n(\\ref{eq:simAlgIni}) and (\\ref{eq:optCheNelMeaOriMod}).\n\n\\item[BlockRestartCheck]\nNumber that indicates for how many main iterations the restart criterion is not checked. If zero, restart \nmight be checked after each main iteration.\n\n\\item[ModifyStoppingCriterion]\nFlag indicating whether the stopping criterion should be modified. \nIf \\texttt{true}, then the optimality check \n(\\ref{eq:neaMeaVar}) is done only if both of the following conditions are satisfied: \n(a) in the last step, either a partial inside contraction or total contraction was done, and \n(b) the moving direction of the simplex has changed by an angle $\\phi_k$ of at least $(\\pi/2)$, \nwhere $\\phi_k$ is computed using (\\ref{eq:nelMeaCosMov}).\n\\end{codedescription}\n\n\n", "meta": {"hexsha": "6f493ce490eb8ca7fc47b7dce5a8b1e762ab1928", "size": 22095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/manual/algSimplex.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/algSimplex.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/algSimplex.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": 47.2115384615, "max_line_length": 359, "alphanum_fraction": 0.7328807422, "num_tokens": 6634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6509554219439414}}
{"text": "\\section{A Visual Approach to Operations}\\label{sec:rightmost}\n\\epigraph{\n``The fact that the carry chain allows a single bit\nto affect all the bits to its left\nmakes addition a peculiarly powerful data manipulation operation''\n}{\n\\emph{Hacker's Delight}, page \\texttt{xiv}\n\\cite{Warren:2012:HD:2462741}\n}\n\nAs mentioned in \\autoref{sec:book},\nthe goal is to complement \\emph{Hacker's Delight}:\nchapter 2 of the book simply lists formulas.\nWhile it is possible to understand why they work as they do,\nit is a completely different task to create these on your own\n-- this needs a systematic approach.\n\nIn order to develop the interpretations described by Henry Warren,\na \\emph{visual approach} to operations has to be obtained first.\nConsider the \\lstinline$INC$ operator as an example:\nSimilar to performing addition by hand,\nthe value \\lstinline$1$ gets added onto the least significant bit.\nIn the case of performing \\lstinline$1+1$,\nthe overflow gets carried over to the next bit.\n\nThis repeats until the first \\lstinline$0$ is reached.\nSo starting from the right, every bit gets inverted\nuntil the first \\lstinline$0$-bit is found.\nThis latter description is considered\nthe visual interpretation of \\lstinline$INC$.\n\\lstinline$DEC$ follows an analog pattern\nto the presented \\lstinline$INC$ operator.\nThis allows for the visual interpretations\nshown in \\autoref{table:inc} and \\autoref{table:dec}.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|ccc}\n\\lstinline$x$ & left of rightmost \\lstinline$0$\n    & rightmost \\lstinline$0$ & trailings \\lstinline$1$s\\\\\n\\hline\n\\lstinline$(x+1)$ & unchanged & \\lstinline$1$ & \\lstinline$0...0$\\\\\n& \\multicolumn{3}{c}{\n    \\fbox{invert all bits up to the rightmost \\lstinline$0$}}\n\\end{tabular}\n\\caption{\\lstinline$INC$ (visual interpretation)}\n\\label{table:inc}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|ccc}\n\\lstinline$x$ & left of rightmost \\lstinline$1$\n    & rightmost \\lstinline$1$ & trailings \\lstinline$0$s\\\\\n\\hline\n\\lstinline$(x-1)$ & unchanged & \\lstinline$0$ & \\lstinline$1...1$\\\\\n& \\multicolumn{3}{c}{\n    \\fbox{invert all bits up to the rightmost \\lstinline$1$}}\n\\end{tabular}\n\\caption{\\lstinline$DEC$ (visual interpretation)}\n\\label{table:dec}\n\\end{table}\n\nAfter the now covered mathematical operators from\n\\autoref{sec:introduction},\nthe bitwise logical operators are of interest.\n\\lstinline$NOT$ is the trivial one to visually interpret,\nbecause it simply inverts all bits of a given bitword.\n\nRegarding \\lstinline$OR$ and \\lstinline$AND$,\nthe approach is to reduce the original definition of calculating\n\\lstinline$r$$_i$\\lstinline$ = x$$_i \\lor$\\lstinline$y$$_i$ and\n\\lstinline$r$$_i$\\lstinline$ = x$$_i \\land$\\lstinline$y$$_i$ respectively\nfor each bit $i$.\n\nInstead, one might think of the second argument\nmanipulating the first one to become the result:\nSet \\lstinline$r$ to \\lstinline$x$, then\nfor every \\lstinline$1$ in \\lstinline$y$\nset the corresponding bit in \\lstinline$r$ to \\lstinline$1$.\nSet to \\lstinline$0$ for every \\lstinline$0$ in \\lstinline$y$\nwhen executing \\lstinline$AND$.\nThis is summarised in \\autoref{table:or} and \\autoref{table:and}.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|c|c}\n\\lstinline$y$ & bits that are \\lstinline$0$\n    & bits that are \\lstinline$1$\\\\\n\\hline\n\\lstinline$(x|y)$ & \\lstinline$x$ (unchanged) & \\lstinline$1$\\\\\n& \\multicolumn{2}{c}{\\fbox{for each \\lstinline$1$ in \\lstinline$y$,\n    set to \\lstinline$1$ in \\lstinline$x$}}\n\\end{tabular}\n\\caption{\\lstinline$OR$ (visual interpretation)}\n\\label{table:or}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|c|c}\n\\lstinline$y$ & bits that are \\lstinline$0$\n    & bits that are \\lstinline$1$\\\\\n\\hline\n\\lstinline$(x&y)$ & \\lstinline$0$ & \\lstinline$x$ (unchanged)\\\\\n& \\multicolumn{2}{c}{\\fbox{for each \\lstinline$0$ in \\lstinline$y$,\n    set to \\lstinline$0$ in \\lstinline$x$}}\n\\end{tabular}\n\\caption{\\lstinline$AND$ (visual interpretation)}\n\\label{table:and}\n\\end{table}\n\nNotice that there was made a specific choice\nin \\autoref{table:or} and \\autoref{table:and}\nto let the second argument \\lstinline$y$\nmanipulate the first argument \\lstinline$x$\ninstead of the other way round.\nThis will enhance readability in formulas\npresented in \\autoref{sec:combining}.\n", "meta": {"hexsha": "f3b60be6acf3d737d769cfc9cc27aaf3d0be7779", "size": 4238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/3-rightmost.tex", "max_stars_repo_name": "NeoLegends/hackers-delight", "max_stars_repo_head_hexsha": "4cd924e1e10476d116b5e7b8b9504aa6c8d88e23", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-11T12:10:40.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-11T12:10:40.000Z", "max_issues_repo_path": "content/3-rightmost.tex", "max_issues_repo_name": "NeoLegends/hackers-delight", "max_issues_repo_head_hexsha": "4cd924e1e10476d116b5e7b8b9504aa6c8d88e23", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-25T23:16:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-25T23:16:11.000Z", "max_forks_repo_path": "content/3-rightmost.tex", "max_forks_repo_name": "NeoLegends/hackers-delight", "max_forks_repo_head_hexsha": "4cd924e1e10476d116b5e7b8b9504aa6c8d88e23", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-12-16T11:05:07.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-23T22:08:23.000Z", "avg_line_length": 35.3166666667, "max_line_length": 73, "alphanum_fraction": 0.7404436055, "num_tokens": 1304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6509554201055883}}
{"text": "% jam 2004-08-27\n\n\\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\\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[ \\Identity_{\\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[ \\Identity_{\\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\\frac{{ \\n(\\q_{031})  \\perp  \\n(\\q_{012}) }\n{A(\\q_{012})}}\n\\times (\\q_1 - \\q_2)\n\\right]\n\\; + \\;\n\\left[\n\\frac{{ \\n(\\q_{012})  \\perp  \\n(\\q_{031}) }\n{A(\\q_{031})}}\n\\times (\\q_3 - \\q_1)\n\\right]\n\\\\\n\\Gc{\\p_1}{\\|\\dn\\|^2}{\\q}\n& = &\n\\left[\n\\frac{{ \\n(\\q_{031})  \\perp  \\n(\\q_{012}) }\n{A(\\q_{012})}}\n\\times (\\q_2 - \\q_0)\n\\right]\n\\; + \\;\n\\left[\n\\frac{{ \\n(\\q_{012})  \\perp  \\n(\\q_{031}) }\n{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\\frac{{ \\n(\\q_{031})  \\perp  \\n(\\q_{012}) }\n{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\\frac{{ \\n(\\q_{012})  \\perp  \\n(\\q_{031}) }\n{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\\frac{\\Identity - \\left(\\n(\\q_{012}) \\otimes \\n(\\q_{012}) \\right)}{\\| \\a(\\q_{012}) \\|}\n\\; \\Db{\\a_{012}}{\\q}\n\\nonumber \\\\\n& + &\n\\n(\\q_{012}) \\bullet\n\\frac{\\Identity - \\left(\\n(\\q_{031}) \\otimes \\n(\\q_{031}) \\right)}{\\| \\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\\frac{ \\n(\\q_{031}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{012}) }\n{\\| \\a (\\q_{012}) \\| }\n\\times (\\q_2 - \\q_1)\n\\\\\n& \\; + &\n\\frac{ \\n(\\q_{012}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{031})  }\n{\\| \\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\\frac{ \\n(\\q_{031}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{012})  }\n{\\| \\a (\\q_{012}) \\| }\n\\times (\\q_0 - \\q_2)\n\\nonumber \\\\\n& \\; + &\n\\frac{ \\n(\\q_{012}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{031})   }\n{\\| \\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\\frac{ \\n(\\q_{031}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{012})  }\n{\\| \\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\\frac{ \\n(\\q_{012}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{031}) }\n{\\| \\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", "meta": {"hexsha": "d6ae9738adec1a8bf22dbf8e71d94eecbc07b90a", "size": 10609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/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/fosm/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/fosm/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": 28.4423592493, "max_line_length": 88, "alphanum_fraction": 0.5553775097, "num_tokens": 4300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.6509554145905291}}
{"text": "%!TeX root = nagurka_math\n%\\documentclass{article}\n\\documentclass[paper.tex]{subfiles}\n\n\\begin{document}\n\n(coordinates that are determined by the fourier-type series are expressed in capital letters, like X or U).\n\nIn standard form, the differential equation translates one \n\n$$ \\ddot{U} + \\frac{\\beta}{\\alpha} \\dot{U} + \\frac{\\gamma}{\\alpha}U =  \\frac{1}{\\alpha} \\ddot{X} + \\frac{\\phi}{\\alpha}\\dot{X} + \\frac{\\xi}{\\alpha}X $$\n\n$$ P(t)= \\sum_{j=0}^{5} t^{j} {p}_{j} $$\n\n$$L(t) = \\sum_{m=1}^{M} \\sin{\\left(\\frac{2 \\pi m t}{t_{f}} \\right)} {b}_{m} + \\sum_{m=1}^{M} \\cos{\\left(\\frac{2 \\pi m t}{t_{f}} \\right)} {a}_{m}$$\n\n$$X = P + L$$\n\nTerm-by-term derivatives (most symbolic operations were performed via SymPy; small sections offloaded to Maxima):\n\n$$\\dot{X}=\\sum_{j=0}^{5} \\frac{j t^{j} {p}_{j}}{t} + \\sum_{m=1}^{M} - \\frac{2 \\pi m \\sin{\\left(\\frac{2 \\pi m t}{t_{f}} \\right)} {a}_{m}}{t_{f}} + \\sum_{m=1}^{M} \\frac{2 \\pi m \\cos{\\left(\\frac{2 \\pi m t}{t_{f}} \\right)} {b}_{m}}{t_{f}}$$\n$$\\ddot{X} = \\frac{\\sum_{j=0}^{5} j t^{j} \\left(j - 1\\right) {p}_{j}}{t^{2}} - \\frac{4 \\pi^{2} \\sum_{m=1}^{M} m^{2} \\sin{\\left(\\frac{2 \\pi m t}{t_{f}} \\right)} {b}_{m}}{t_{f}^{2}} - \\frac{4 \\pi^{2} \\sum_{m=1}^{M} m^{2} \\cos{\\left(\\frac{2 \\pi m t}{t_{f}} \\right)} {a}_{m}}{t_{f}^{2}}$$\\\\\n\nWhen numerically evaluating these symbolic derivatives are undefined at t=0; a small epsilon was always added to the beginning time vector.\n\n\"The solution is of form $U = U_p(x) + U_c(x)$ where $U_p(x)$ is a particular solution and $U_c(x)$ is\nthe solution of the associated homogeneous ODE.\"\\\\\n\nHomogenous solution:\n\n$$\\ddot{U} + \\beta /\\alpha \\dot{U} + \\gamma/\\alpha U = 0$$\n\n$$(\\beta/\\alpha)^2 - 4(\\gamma/\\alpha) \\approx 10^{17}$$\n \n$$y_c(t) = c_1e^{(m_1t)} + c_2e^{(m_2t)}$$\n\n\n\n\\section{ODEINT}\n\n$$F(t) = \\frac{1}{\\alpha} \\ddot{X} + \\frac{\\phi}{\\alpha}\\dot{X} + \\frac{\\xi}{\\alpha}X$$\n\n$$ \\ddot{U} + \\frac{\\beta}{\\alpha} \\dot{U} + \\frac{\\gamma}{\\alpha}U =  F(t) $$\n\n$$ U1 = \\dot{U} $$\n\n\n\\section{}\n\nDespite the simplicity of the technique, difficulties were encountered trying to implement it. \n\n\\begin{toolchain}\n\\textbf{Lesson learned:} For software architecture, testing, and readability reasons, it may be useful to ensure that intermediate coefficients are physically meaningful, not simply amorphous many-term operations.\n\\end{toolchain}\n\n\\begin{toolchain}\n\t\\textbf{Lesson learned:} Autodiff is an excellent way to cross-check analytic derivatives.\n\\end{toolchain}\n\n\n\nMany Yen and Nagurka's work. One of their formulations used explicit polynomial boundary conditions, but the derivation was not easily at hand (small derivative dots appear to be removed by scanners) so we quickly re-derive the coefficients.\\\\\n\nThis uses a technique very similar to a spline fit. We first wish to create a polynomial with specified boundary conditions $P(0), P(t_f), \\dot P(0), \\dot P(t_f), \\ddot P(0), \\ddot P(t_f)$.\n\n$$P(t) = p_0 + p_1 t + p_2 t^2 + p_3 t^3 + p_4 t^4 + p_5 t^5$$\n\n$$\\dot P(t) = p_1 + 2 p_2 t + 3 p_3 t^2 + 4 p_4 t^3 + 5 p_5 t^4$$\n\n$$\\ddot P(t) = 2 p_2 + 6 p_3 t + 12 p_4 t^2 + 20 p_5 t^3$$\n\n$$P(0) = p_0$$\n\n$$P(t_f) = p_0 + p_1 t_f + p_2 t_f^2 + p_3 t_f^3 + p_4 t_f^4 + p_5 t_f^5$$\n\n$$\\dot P(0) = p_1$$\n\n$$\\dot P(t_f) = p_1 + 2 p_2 t_f + 3 p_3 t_f^2 + 4 p_4 t_f^3 + 5 p_5 t_f^4$$\n\n$$\\ddot P(0) = 2 p_2$$\n\n$$\\ddot P(t_f) = 2 p_2 + 6 p_3 t_f + 12 p_4 t_f^2 + 20 p_5 t_f^3$$\n\nSubstituting, \n\n$$P(t_f) = P(0) + \\dot P(0)t_f + (\\ddot P(0) / 2)t_f^2 + p_3 t_f^3 + p_4 t_f^4 + p_5 t_f^5$$\n\n$$\\dot P(t_f) = \\dot P(0) + \\ddot P(0)t_f + 3 p_3 t_f^2 + 4 p_4 t_f^3 + 5 p_5 t_f^4 $$\n\n$$\\ddot P(t_f) = \\ddot P(0) + 6 p_3 t_f + 12 p_4 t_f^2 + 20 p_5 t_f^3$$\n\nRunning through SymPy, \\url{polynomial_system_of_equations.py}, % PAPERID 10\n\n\n$$p_{0} = {P(0)}$$\n$$p_{1} = {\\dot{P}(0)}$$\n$$p_{2} = \\frac{{\\ddot{P}(0)}}{2}$$\n$$p_{3} = \\frac{t_{f}^{2} \\left(- 3 {\\ddot{P}(0)} + {\\ddot{P}(t_f)}\\right) - 4 t_{f} \\left(3 {\\dot{P}(0)} + 2 {\\dot{P}(t_f)}\\right) - 20 {P(0)} + 20 {P(t_f)}}{2 t_{f}^{3}}$$\n$$p_{4} = \\frac{\\frac{t_{f}^{2} \\left(3 {\\ddot{P}(0)} - 2 {\\ddot{P}(t_f)}\\right)}{2} + t_{f} \\left(8 {\\dot{P}(0)} + 7 {\\dot{P}(t_f)}\\right) + 15 {P(0)} - 15 {P(t_f)}}{t_{f}^{4}}$$\n$$p_{5} = \\frac{t_{f}^{2} \\left(- {\\ddot{P}(0)} + {\\ddot{P}(t_f)}\\right) - 6 t_{f} \\left({\\dot{P}(0)} + {\\dot{P}(t_f)}\\right) - 12 {P(0)} + 12 {P(t_f)}}{2 t_{f}^{5}}$$\n\nGiven the 'physical' boundary conditions $\\{X(0), X(t_f), \\dot X(0), \\dot X(t_f), \\ddot X(0), \\ddot X(t_f)\\}$ and the Fourier-type series boundary conditions $\\{L(0), L(t_f), \\dot L(0), \\dot L(t_f), \\ddot L(0), \\ddot L(t_f)\\}$, $\\{P(0) = X(0) - L(0), ...\\}$.\n\n\\section{}\n\nOne could also generalize the parametrization to arbitrary integer order of derivative, where $z$ is the derivative order and $J = 2(z+1)$ is the necessary polynomial order, $v = \\frac{2\\pi m}{t_f}$, by applying the trig functions\n\n$$\\frac{d^z}{dx^z}\\cos x=\\cos\\left(x+z\\frac{\\pi}2\\right)$$\n\n$$\\frac{d^z}{dx^z}\\sin x=\\sin\\left(x+z\\frac{\\pi}2\\right)$$\n\nwe get\n\n$$\\frac{d^z}{dt^z}=  v^z \\sin(v t+ z\\frac{\\pi}{2}) $$\n\n$$\\frac{d^6}{dt^6} = \\frac{\\sum_{j=0}^{J} j t^{j} \\left(???\\sum_{j=0}^{J-1} j t^{j} ??? \\right) {p}_{j}}{t^{6}}$$\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\end{document}\n\n", "meta": {"hexsha": "3d1a02bd7537c523b987999f8135725de3cc78ec", "size": 5157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/nagurka_math.tex", "max_stars_repo_name": "0xDBFB7/covidinator", "max_stars_repo_head_hexsha": "e9c103e5e62bc128169400998df5f5cd13bd8949", "max_stars_repo_licenses": ["MIT"], "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/nagurka_math.tex", "max_issues_repo_name": "0xDBFB7/covidinator", "max_issues_repo_head_hexsha": "e9c103e5e62bc128169400998df5f5cd13bd8949", "max_issues_repo_licenses": ["MIT"], "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/nagurka_math.tex", "max_forks_repo_name": "0xDBFB7/covidinator", "max_forks_repo_head_hexsha": "e9c103e5e62bc128169400998df5f5cd13bd8949", "max_forks_repo_licenses": ["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.9268292683, "max_line_length": 286, "alphanum_fraction": 0.5908473919, "num_tokens": 2224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.650955109798145}}
{"text": "%!TEX root = paper.tex\r\n\\subsection{Propagating solitary wave}\r\nThe propagating solitary wave tests the balancing of dispersion effects and nonlinearity for an appropriate initial condition.\r\nOn constant bathymetry, the Serre equations \\cite{Serre.1953} have an analytic solitary wave solution\r\n\\begin{align}\r\n\\label{eq:Serre_sol_surface}\r\n\\xi(\\bx,t)&=a \\ \\text{cosh}^{-2}(K(x-ct-x_0)), \\\\\r\nu(\\bx,t)&=c\\frac{\\xi(\\bx,t)}{d+\\xi(\\bx,t)},\r\n\\end{align}\r\nwith the ratio $\\frac{a}{d}=0.2$, propagation velocity $c=\\sqrt{g(d+a)}$ on a constant depth $d=10 \\, \\text{m}$, scale factor $K=\\sqrt{\\left(\\frac{3a}{4d^2(d+a)}\\right)}$ and displacement $x_0=l/2$ on a domain of length $l=800 \\, \\text{m}$.\r\nAgain, we impose double periodic boundary conditions solitary wave propagating in the positive $x$-direction. The simulation time is $30$ seconds.\r\n\r\n\\subsubsection{Results of \\nh\\ model}\r\nThe equations \\eqref{eq:nh_conti}--\\eqref{eq:nh_closure} using the quadratic vertical pressure profile are equivalent to the Serre equations \\cite{Serre.1953}, which is shown in  \\cite{Jeschke.2016}. Using the linear vertical pressure profile, there is no equivalence to the Serre equations.\r\nFor the \\nh\\ model, we also need to initialize the vertical velocity, which directly follows from equation Equation \\eqref{eq:nh_closure}, s.t.\r\n\\begin{align}\r\nw&=-0.5h\\partial_x u. \\label{eq:nh_solit_init_w}\r\n\\end{align}\r\nFigure \\ref{fig:nh_solitarywave} compares our numerical computations with the analytical solution at the end of the simulation time.\r\nThe numerical result using the quadratic pressure profile shows a very good agreement with the analytical solution. In contrast, the application of the linear pressure profile yields a threefold mismatch arising from the inconsistency in initial conditions combined with the underlying equation system: Small amplitude waves propagate to the opposite direction, the wave height increases {because of weaker dispersion of the linear profile and trailing waves start to establish.\r\nIn \\cite{StellingZijlema.2003, Walters.2005, Yamazaki.2008}, different solitary waves are computed with \\nh\\ models using the traditional linear vertical pressure profile. Therein, these mismatches are also visible, except that their amplitudes tend to diminish than to amplify. The reason is the application of another vertical velocity, namely $W(z)=-z\\partial_x u$, so $w=-0.5(\\xi-d)\\partial_x u$. If the term $-d\\partial_x u$ is added, the vertical velocity \\eqref{eq:nh_solit_init_w} results. Hence, in \\cite{StellingZijlema.2003, Walters.2005, Yamazaki.2008}, the vertical velocity is too large on the left hand side of the maximum amplitude and too small on the right hand side, which decreases the nonlinear steepening of the wave.\r\nTheir aim to compute the solitary waves was merely to show that \\nh\\ models produce similar results as \\Bt\\ models. \r\n\r\n\\begin{figure}[htbp]\r\n\\includegraphics[width=\\textwidth]{solitary_nh}\r\n\\caption{Comparison of the analytical (black) sea surface height of the\r\nsolitary wave with the simulation results of the quadratic (yellow) and linear (blue) vertical profile after a propagation time of 10, 20 and 30 seconds to the right.}\r\n\\label{fig:nh_solitarywave}\r\n\\end{figure}\r\n", "meta": {"hexsha": "e0cf56556c39f573c1999922670eda59dfbc4f77", "size": 3227, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/papers/theoretical_1d/B_solitarywave.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_solitarywave.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_solitarywave.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": 107.5666666667, "max_line_length": 740, "alphanum_fraction": 0.7734738147, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6508924015642632}}
{"text": "\\subsection{Function convergence}\\label{subsec:function_convergence}\n\n\\begin{definition}\\label{def:local_convergence}\n  Fix two topological spaces \\( X \\) and \\( Y \\). Let \\( A \\subseteq X \\) be a nonempty set and let \\( f: A \\to Y \\) be a function. We give two equivalent definitions for \\( y_0 \\in Y \\) being a \\term{limit point} of \\( f \\) at \\( x_0 \\in \\cl(A) \\). If \\( y_0 \\) is the unique limit point (e.g. in \\hyperref[def:separation_axioms/T2]{Hausdorff spaces}), we write\n  \\begin{equation*}\n    \\lim_{x \\to x_0} f(x) = y_0.\n  \\end{equation*}\n\n  \\begin{thmenum}\n    \\thmitem{def:local_convergence/neighborhoods}(Cauchy-style condition) For every neighborhood \\( V \\) of \\( y_0 \\) there exists a neighborhood \\( U \\) of \\( x_0 \\) such that \\( f(U \\cap A) \\subseteq V \\).\n\n    \\thmitem{def:local_convergence/nets}(Heine-style condition) For every \\hyperref[def:topological_net]{net} \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq A \\), for which \\( x_0 \\) is a limit \\hyperref[def:net_convergence/limit]{point}, the corresponding net \\( \\{ f(x_k) \\}_{k \\in \\mscrK} \\) has \\( y_0 \\) as a limit point.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:local_convergence/neighborhoods}{def:local_convergence/nets} Let \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq U \\) be a net  with limit point \\( x_0 \\). Consider the net \\( \\{ f(x_k) \\}_{k \\in \\mscrK} \\). Fix a neighborhood \\( V \\) of \\( y_0 \\). We need to show that \\( \\{ f(x_k) \\}_{k \\in \\mscrK} \\) is eventually in \\( V \\).\n\n  By \\fullref{def:local_convergence/neighborhoods}, there exists a neighborhood \\( U \\) of \\( x_0 \\) such that \\( f(U) \\subseteq V \\). Since \\( x_0 \\) is a limit point of \\( \\{ x_k \\}_{k \\in \\mscrK} \\), there exists an index \\( k_0 \\) such that for all \\( k \\geq k_0 \\), \\( x_k \\in U \\) and therefore \\( f(x_k) \\in V \\). Hence, \\( \\{ f(x_k) \\}_{k \\in \\mscrK} \\) is eventually in \\( V \\).\n\n  We conclude that \\( y_0 \\) is a limit point of the net \\( \\{ f(x_k) \\}_{k \\in \\mscrK} \\) and that the Heine-style condition is satisfied.\n\n  \\ImplicationSubProof{def:local_convergence/nets}{def:local_convergence/neighborhoods} Suppose that \\fullref{def:local_convergence/nets} holds while \\fullref{def:local_convergence/neighborhoods} does not. Let \\( V \\) be a neighborhood of \\( y_0 \\). Then there exists no neighborhood \\( U \\) of \\( x_0 \\) such that \\( f(U) \\subseteq V \\).\n\n  For any neighborhood \\( U \\) of \\( x_0 \\) and let \\( y_U \\in f(U) \\setminus V \\) and \\( x_U \\in f^{-1} (U) \\), so that \\( f(x_U) = y_U \\). Consider the families\n  \\begin{balign*}\n    \\{ x_U \\}_{U \\in T(x_0)},\n     &  &\n    \\{ f(x_U) \\}_{U \\in T(x_0)},\n  \\end{balign*}\n  ordered by \\hyperref[ex:reverse_inclusion_net]{reverse inclusion} of the neighborhoods \\( \\mscrT(x_0) \\) of \\( x_0 \\).\n\n  Note that \\( x_0 \\) is a limit point of \\( \\{ x_U \\}_{U \\in T(x_0)} \\). By \\fullref{def:local_convergence/nets}, \\( y_0 \\) is a limit point of \\( \\{ f(x_U) \\}_{U \\in T(x_0)} \\). But this contradicts our choice of the nets because \\( f(x_U) \\not\\in V \\) for any \\( U \\in T(x) \\).\n\n  The obtained contradiction demonstrates that \\fullref{def:local_convergence/nets} implies \\fullref{def:local_convergence/neighborhoods}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:cauchy_function_convergence_via_subbases}\n  Fix two topological spaces \\( X \\) and \\( Y \\) and two points \\( x_0 \\in X \\) and \\( y_0 \\in Y \\). Let \\( \\mscrP(x_0) \\) and \\( \\mscrP(y_0) \\) be local \\hyperref[def:topological_local_subbase]{subbases} for the corresponding points. Then the function \\( f: X \\to Y \\) \\hyperref[def:local_convergence]{converges} to \\( y_0 \\) at \\( x_0 \\) if and only if every \\( V_P \\in P(y_0) \\) there exists \\( U_P \\in B(x_0) \\) such that \\( f(U_P) \\subseteq V_P \\).\n\n  Compare this result to \\fullref{thm:net_convergence_via_subbases}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Obvious consequence of \\fullref{def:local_convergence/neighborhoods}.\n  \\NecessitySubProof Fix a neighborhood \\( V \\) of \\( x \\). We will show that \\fullref{def:local_convergence/neighborhoods} holds.\n\n  Let \\( \\{ V_k \\}_{k=1}^n \\subseteq P(y_0) \\) be a family such that \\( \\bigcap_{k=1}^n V_k \\subseteq V \\) (such a family exists by definition of a local subbase). By the antecedent of the implication we are proving, for every \\( k = 1, \\ldots, n \\) there exists an \\( U_k \\in P(x_0) \\) such that \\( f(U_k) \\subseteq V_k \\). Then \\( U \\coloneqq \\bigcap_{k=1}^n U_k \\) is a neighborhood of \\( x_0 \\) and, furthermore,\n  \\begin{equation*}\n    f(U)\n    =\n    f\\left(\\bigcap_{k=1}^n U_k \\right)\n    \\subseteq\n    \\bigcap_{k=1}^n f(U_k)\n    \\subseteq\n    \\bigcap_{k=1}^n V_k\n    \\subseteq\n    V.\n  \\end{equation*}\n\n  Therefore, \\fullref{def:local_convergence/neighborhoods} holds.\n\\end{proof}\n", "meta": {"hexsha": "c296ad971a40c5892e13e4ca255b30758a7f8f67", "size": 4730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/function_convergence.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/function_convergence.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/function_convergence.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.5409836066, "max_line_length": 453, "alphanum_fraction": 0.65602537, "num_tokens": 1642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.6508923917154185}}
{"text": "\\vsssub\n\\subsubsection{~$S_{bot}$: \\js\\ bottom friction} \\label{sec:BT1}\n\\vsssub\n\n\\opthead{BT1}{\\js\\ experiment}{H. L. Tolman}\n\n\\noindent \nA simple parameterization of bottom friction is the empirical, linear \\js\\\nparameterization \\citep{art:JONSWAP}, as used in the \\wam\\ model\n\\citep{art:WAM88}. Using the notation of \\cite{tol:JPO91b}, this source term\ncan be written as\n\n%-------------------------%\n% JONSWAP bottom friction %\n%-------------------------%\n% eq:JONSWAP_bot\n\n\\begin{equation}\n\\cS_{bot}(k,\\theta) = 2 \\Gamma \\: \\frac{n-0.5}{gd} \\: N(k,\\theta)\n\\: , \\label{eq:JONSWAP_bot}\n\\end{equation}\n\n\\noindent\nwhere $\\Gamma$ is an empirical constant, which is estimated as $\\Gamma =\n-0.038\\:\\mbox m^2 \\mbox s ^{-3}$ for swell \\citep{art:JONSWAP}, and as $\\Gamma\n= -0.067\\:\\mbox m^2 \\mbox s^{-3}$ for wind seas \\citep{art:BK83}. $n$ is the\nratio of phase velocity to group velocity given by (\\ref{eq:cg}). The default\nvalue for $\\Gamma = -0.067$ can be redefined by the user by changing the {\\F SBT1} namelist parameter {\\code GAMMA}.\n", "meta": {"hexsha": "b69a29e21e3421c9f72e81b8409c323fd52a8c54", "size": 1038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WW3/manual/eqs/BT1.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/BT1.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/BT1.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": 35.7931034483, "max_line_length": 116, "alphanum_fraction": 0.661849711, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6508572220386604}}
{"text": "\\documentclass{article}\n\\usepackage[a4paper,margin= 2cm]{geometry}\n\\usepackage{graphicx}\n\n\\title{\\LARGE{\\bf{Task 1 Overview}}}\n\\author{\\Large{\\bf{Kirtan Patel - AE19B038}}}\n\\date{}\n\n\\begin{document}\n\n\\maketitle \n\n\\section{The Amplitude Magnification Frequency Response Graph}\nThis Graph shows the relation between the Amplitude Magnification Function and the Frequency of the Sytem. The Frequency $\\omega$ is given as a ratio over the natural frequency of the system $\\omega_{n}$.\n\\[x(t) = \\delta_{static}~|G(i\\omega)|~e^{i(\\omega t - \\phi)}\\]\nwhere\n\\[|G(i \\omega)|^2 = \\frac{1}{(1 - r^2)^2 + (2 \\zeta r)^2}\\]\n\\begin{figure}\n\\centering\n\\includegraphics[scale = 0.56]{Amplitude Frequency_Response.png}\n\\caption{Frequency Response of Amplitude Magnification}\n\\label{fig1.}\n\\end{figure}\n\nThis Graph helps us analyse the nature of vibrations experienced by the system under study. Studying the graph, we can observe that:\n\\begin{enumerate}\n\t\\item For an undamped system($\\zeta$=0),and G$\\rightarrow$ $\\infty$ as r $\\rightarrow$ 1\n\t\\item Any amount of damping($\\zeta$$>$0)reduces the magnification factor (G) for all values of the forcing frequency.\n\t\\item In the degenerate case of a constant force (when r=0), the value of $|G|$\n\t\\item The reduction in $|G|$ in the presence of damping is very significant at or near resonance.\n\\end{enumerate}\n\nIn System Design, we use this data to design the structure such that the frequency of vibrations handled by the structure are not near the natural frequency of the structure and hence limit the Magnification of the Transferred Vibrations.\\\\ \n\nThe graph even helps us predict the values of Magnification Factor for intermediate Frequency Ratios by interpolation. Hence, this graph is widely used in the study and design of systems which are subjected to vibrations\n\\pagebreak\n\n\n\\section{Sinusoidal Multivariable Function Plot}\nThis Graph shows the sinusoidal relation expressed as\n\\[z(x,y) = \\frac{sin(5x).cos(5y)}{5}\\]\n\nThis Graph helps us analyse the nature of multivariable functions.It contains multiple Saddle Points and can be used in visualizing the concept.\\\\\n\n\\begin{figure} [!ht] %to keep the image where we place it.\n\\centering\n\\includegraphics[scale=0.3]{Octave_3D Plot.png}\n\\caption{Sinusoidal Multivariable Function Plot}\n\\label{fig2.}\n\\end{figure}\n\n\n\\subsection{Saddle Point}\nGiven the function z=f(x,y), the point $(x_{0},y_{0},f(x_{0},y_{0}))$ is a saddle point if both $f_{x}(x_{0},y_{0})=0$ and $f_{y}(x_{0},y_{0})=0$, but f does not have a local extremum at $(x_{0},y_{0})$.\\\\\n\nWhile we have to be careful to not misinterpret the results of this fact it is very useful in helping us to identify relative extrema. Because of this fact we know that if we have all the critical points of a function then we also have every possible relative extrema for the function. The fact tells us that all relative extrema must be critical points so we know that if the function does have relative extrema then they must be in the collection of all the critical points. Remember however, that it will be completely possible that at least one of the critical points won’t be a relative extrema.\\\\\n\nIn machine learning for example, local/global minimums/maximums are important as the indicate the validity and accuracy of the function.\n\\end{document}", "meta": {"hexsha": "2f7cd5f95fd5da755cbe3b624d66a76abc050dad", "size": 3294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AS2101_Labwork/4.Submissions/Task 1/Task1.tex", "max_stars_repo_name": "kirtan2605/Coursework_Codes", "max_stars_repo_head_hexsha": "3455496e8ec0ae3a576cb3fc3b2ed01a055149c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AS2101_Labwork/4.Submissions/Task 1/Task1.tex", "max_issues_repo_name": "kirtan2605/Coursework_Codes", "max_issues_repo_head_hexsha": "3455496e8ec0ae3a576cb3fc3b2ed01a055149c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AS2101_Labwork/4.Submissions/Task 1/Task1.tex", "max_forks_repo_name": "kirtan2605/Coursework_Codes", "max_forks_repo_head_hexsha": "3455496e8ec0ae3a576cb3fc3b2ed01a055149c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.8305084746, "max_line_length": 602, "alphanum_fraction": 0.7610807529, "num_tokens": 875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.650856884515284}}
{"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\\DeclareMathOperator*{\\argmin}{\\mathrm{argmin}}\n\n\\begin{document}\n\n\\title{RPCAKit: MATLAB RPCA Library}\n\\author{Stephen Tierney}\n\\maketitle\n\n%\\tableofcontents\n\n\\section{RPCA}\n\nRobust Principal Component Analysis (RPCA) \\cite{candes2011robust} refers to the following problem\n\\begin{align}\n\\min_{\\mathbf{A, N}} \\|\\mathbf A \\| + \\lambda\\|\\mathbf N\\|_{q} \\\\\n\\text{s.t.} \\quad \\mathbf{X = A + N} \\nonumber\n\\end{align}\nwhere $\\mathbf X$ is observed data, $\\mathbf A$ is the original low-rank data $\\mathbf N$ is some noise and $q$ is a placeholder for the noise type. For example if our data is corrupted by sparse noise we set $q = 1$. In other words the goal is to recover $\\mathbf A$ only knowing $\\mathbf X$ and the type of noise the data has been affected by. It has been shown that the solution to this objective can exactly recover $\\mathbf A$ under reasonable conditions \\cite{candes2011robust}. RPCAKit provides MATLAB functions to solve this problem for Gaussian, sparse and sample specific noise.\n\n\\section{Function Listing}\n\n\\begin{table}[!h]\n{\\small{\n\\centering\n\n\\begin{tabular}{c | c}\n\\hline\nObjective & Function \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{A, N}} \\|\\mathbf A \\| + \\frac{\\lambda}{2} \\|\\mathbf N\\|_F^2 \\\\\n\\text{s.t.} \\quad \\mathbf{X = A + N} \\end{array}$\n\t& rpca\\_fro  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{A, N}} \\|\\mathbf A \\| + \\lambda \\|\\mathbf N\\|_1 \\\\\n\\text{s.t.} \\quad \\mathbf{X = A + N} \\end{array}$\n\t& rpca\\_l1  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{A, N}} \\|\\mathbf A \\| + \\lambda \\|\\mathbf N\\|_{1,2} \\\\\n\\text{s.t.} \\quad \\mathbf{X = A + N} \\end{array}$\n\t& rpca\\_l1l2  \\\\\n\\hline\n\n\\end{tabular}\n}}\n\\end{table}\n\n\\section{Implementation}\n\nWe use Linearised ADMM with Adaptive Penalty \\cite{lin2011linearized} to solve the RPCA problem. First form the Augmented Lagrangian\n\\[\n\\min_{\\mathbf{A, N}} \\|\\mathbf A \\| + \\lambda\\|\\mathbf N\\|_{q} + \\langle \\mathbf{Y, X - A - N} \\rangle + \\frac{\\mu}{2} \\| \\mathbf{X - A - N}  \\|_F^2\n\\]\n\n\\begin{enumerate}\n\\item Fix others and solve for $\\mathbf A$\n\\[\n\\min_{\\mathbf{A}} \\|\\mathbf A \\| + \\langle \\mathbf{Y, X - A - N} \\rangle + \\frac{\\mu}{2} \\| \\mathbf{X - A - N}  \\|_F^2\n\\]\n\\[\n\\min_{\\mathbf{A}} \\|\\mathbf A \\| + \\frac{\\mu}{2} \\| \\mathbf{X - A - N} + \\frac{1}{\\mu}\\mathbf Y  \\|_F^2\n\\]\nwhich has a closed form solution defined by the singular value shrinking operator \\cite{lin2011linearized,candes2011robust}.\n\n\\item Fix others and solve for $\\mathbf N$\n\\[\n\\min_{\\mathbf{N}} \\lambda\\|\\mathbf N\\|_{q} + \\langle \\mathbf{Y, X - A - N} \\rangle + \\frac{\\mu}{2} \\| \\mathbf{X - A - N}  \\|_F^2\n\\]\n\\[\n\\min_{\\mathbf{N}} \\lambda\\|\\mathbf N\\|_{q} + \\frac{\\mu}{2} \\| \\mathbf{X - A - N} + \\frac{1}{\\mu}\\mathbf Y \\|_F^2\n\\]\nwhere the solutions have various closed form solutions, see \\cite{candes2011robust, liu2010robust}.\n\n\\item Update $\\mathbf Y$\n\\[\n\\mathbf Y = \\mathbf Y + \\mu( \\mathbf{X - A - N} )\n\\]\n\n\\item Update $\\mu$\n\\begin{align*}\n \\mu = \\textrm{min}( \\mu_{\\text{max}}, \\gamma \\mu)\n\\end{align*}\nwhere $\\rho$ is defined as\n\\[\n\\gamma = \n\\begin{cases}\n\\gamma_0 & \\text{if} \\;\\; \\mu_k \\frac{\\textrm{max} ( \\| \\mathbf A_{k+1} - \\mathbf A_{k}  \\|_F  , \\|  \\mathbf N_{k+1} - \\mathbf N_{k} \\|_F)}{\\| \\mathbf X \\|_F} < \\epsilon_2 \\\\\n1 & \\text{otherwise,}\n\\end{cases}\n\\]\n$\\mu_{\\text{max}} >>  \\mu_0$ and $\\epsilon > 0$.\n\n\\item Check stopping criteria\n\\[\n\\|\\mathbf X - \\mathbf A^{k+1}  - \\mathbf N^{k+1} \\|_F < \\epsilon_1, \\;\n \\mu_k \\frac{\\textrm{max} ( \\| \\mathbf A_{k+1} - \\mathbf A_{k}  \\|_F  , \\|  \\mathbf N_{k+1} - \\mathbf N_{k} \\|_F)}{\\| \\mathbf X \\|_F} < \\epsilon_2\n\\]\n\n\n\\end{enumerate}\n\n\\bibliographystyle{plain}\n\\bibliography{references}\n\n\\end{document}", "meta": {"hexsha": "1f88dbfcad7ef6d381b1b03264f001e3e281df69", "size": 3910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "libs/RPCAKit/doc/RPCAKit.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": "libs/RPCAKit/doc/RPCAKit.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": "libs/RPCAKit/doc/RPCAKit.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": 32.3140495868, "max_line_length": 588, "alphanum_fraction": 0.647826087, "num_tokens": 1486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079208, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.6508563606300647}}
{"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 2}\n\n\\author{Manish Goregaokar (120260006)}\n\\date{January 26, 2015}\n\\begin{document}\n\\maketitle\n\\section*{Problem 1}\n\n$$n! = \\int_0^\\infty e^{-x}x^n dx$$\n\nIntegrating by parts,\n\\begin{align*}\nI_n &= \\left.x^n\\int e^{-x}\\right|_0^\\infty + \\int_0^\\infty nx^{n-1}\\int e^{-x}\\\\\n &= - \\left.x^n e^{-x}\\right|_0^\\infty + nI_{n-1}\\\\\n &= nI_{n-1}\\\\\n \\therefore I_n &= nI_{n-1}\n\\end{align*}\n\nAdditionally, for $n=0$, $I_0 = \\int_0^\\infty e^{-x} = 1$. So $I_0 = 1,  I_n = nI_{n-1}$. From this we see that this is exactly the factorial function, which obeys the same recursion relation.$\\hfill$ Ans. (i)\n\n\\begin{figure}[!htb]\n\\centering\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{gamma10}\n\\caption{Integrand for $n=10$}\n\\end{subfigure}\n~~~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{gamma20}\n\\caption{Integrand for $n=20$}\n\\end{subfigure}\n\\\\~\\\\~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{gamma50}\n\\caption{Integrand for $n=50$}\n\\end{subfigure}\n\\end{figure}\n\n$$g(x)=A\\exp\\left(-\\frac{(x-x_0)^2}{2\\sigma^2}\\right)$$\n\nNow, $g(x) \\approx e^{-x}x^n$. We take the Taylor expansion about the maxima $x=x_0$.\n \\begin{align*}\ne^{-x}x^n &=x_0^n e^{-x_0} + 0 +\n\\frac{(x-x_0)^2}{2}\\left.\\frac{d^2}{dx^2}e^{-x  +n\\ln x}\\right|_{x=x_0} + \\dots\\\\\n&=x_0^n e^{-x_0} + 0 +\\frac{(x-x_0)^2}{2}\\left(e^{-x_0} x_0^{n-2} \\left(-2 n x_0+(n-1) n+x_0^2\\right)\\right)\n\\end{align*}\n\nWhereas for the Gaussian, the Taylor expansion about the mean is $A(1 + 0(x-x_0) - \\frac{(x-x_0)^2}{2}\\frac{1}{ \\sigma ^2}$\n\nThus, $A = x_0^ne^{-x_0}$, $-\\frac{1}{ \\sigma ^2} = 1 - \\frac{2n}{x_0} + \\frac{n(n-1)}{x_0^2}$\n\n\nTo find $x_0$, we set the derivative to zero: $n e^{-x} x^{n-1}-e^{-x} x^n = 0$, and we find that $x_0 = n$\n\nThus, $\\boxed{A=n^ne^{-n}}$, $\\boxed{x_0 = n}$, $\\frac{1}{\\sigma^2} = 1-\\frac{n-1}{n}$, and $\\boxed{\\sigma = \\sqrt{n}}$\n\nWhile the higher deriviatives of these two functions diverge for large $n$, the approximation still comes closer when plotted. Thus, this approximation improves as $n$ becomes large, but the two curves are not asymptotically equal.\n\n\\begin{figure}[!htb]\n\\centering\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{gaus10}\n\\caption{Gaussian approximation  for $n=10$}\n\\end{subfigure}\n~~~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{gaus20}\n\\caption{Gaussian approximation  for $n=20$}\n\\end{subfigure}\n\\\\~\\\\~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{gaus50}\n\\caption{Gaussian approximation for $n=50$}\n\\end{subfigure}\n\\end{figure}\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[scale=0.5]{error}\n\\end{figure}\n\\newpage\n\\section*{Problem 2}\n\nLet us take the random variable $y = \\left\\lbrace\\begin{array}{ll}1 & \\text{if} (x-\\lambda)^2 > k^2\\\\\n0 & \\text{if} (x-\\lambda)^2 \\leq k^2\\end{array}\\right.$\n\n$\\therefore E(y) = P(\\text{x is not in $k$ neighborhood})$\n\nAdditionally, if $x >0$, $y \\leq \\frac{(x-\\lambda)^2}{k^2}$. Thus, $E[y] \\leq E[\\frac{(x-\\lambda)^2}{k^2}] ~\\implies~ P(\\text{x is not in } k \\text{ neighborhood}) \\leq \\frac{\\sigma^2}{k^2}$\n\nIf $n\\sigma = k$, we get $\\boxed{P(\\text{x is not in } n\\sigma \\text{ neighborhood}) \\leq \\frac1{n^2}}$\n\n\\section*{Problem 3}\n\\newcommand{\\inint}{\\int_{-\\infty}^\\infty}\n$$S(\\alpha, \\beta, p(x)) = -\\inint p(x)\\ln p(x)dx + \\alpha\\left(1-\\inint p(x)dx\\right)+ \\beta\\left(f-\\inint F(x)p(x)dx\\right)$$\n\nBy lagrange multipliers, \\begin{align*}\n0 &= -\\frac{\\delta}{\\delta p(y)}\\inint p(x)\\ln p(x)dx + \\frac{\\delta}{\\delta p(y)} \\alpha\\left(1-\\inint p(x)dx\\right)+\\frac{\\delta}{\\delta p(y)}\\beta\\left(f-\\inint F(x)p(x)dx\\right)\\\\\n&= -\\inint \\ln p(x)\\delta(x-y) - \\inint \\delta{x-y} - \\alpha\\inint \\delta{x-y} -F(x)\\beta\\inint \\delta{x-y} \\\\\n&= -(1+\\ln p(y)) - \\alpha - F(x)\\beta\n\\end{align*} \nThus, $p(y) = \\exp(-1-\\alpha - \\beta F(x))$\nWhen $\\Braket{|v|} = c$, we have the equations:\n\\begin{align*}\np(x) &= \\exp(-1-\\alpha - \\beta |x|)\\\\\n\\inint p(x) dx &= 1\\\\\n\\inint |x| p(x) dx &= c\\\\\n\\therefore 1 &= \\inint \\exp(-1-\\alpha - \\beta |x|) \\\\\n &= 2\\int_0^\\infty \\exp(-1-\\alpha - \\beta x)\\\\\n &= \\frac{2}{\\beta}e^{-1-\\alpha}\\\\\n \\therefore p(y) &= \\frac{\\beta}{2} e^{-\\beta|x|}\\\\\n \\text {Now, } \\inint |x| p(x) dx &= c\\\\\n \\therefore c &= 2\\int_0^\\infty x\\frac{\\beta}{2} e^{-\\beta x}dx \\\\\n c &= \\frac{1}{\\beta}\\\\\n \\beta &= \\frac1 c\n\\end{align*}\n\nThus, for constraining $\\Braket{|v|} = c$, the distribution is $\\boxed{p(v) = \\frac1{2c} e^{-\\frac{1} {c}v}}\\hfill$ Ans.\n\nWhen constraining $\\Braket{v^2} = c^2$, we have \n\\begin{align*}\np(x) &= \\exp(-1-\\alpha - \\beta x^2)\\\\\n\\inint p(x) dx &= 1\\\\\n\\inint |x| p(x) dx &= c\\\\\n\\therefore 1 &= \\inint \\exp(-1-\\alpha - \\beta x^2) \\\\\n &= 2\\int_0^\\infty \\exp(-1-\\alpha - \\beta x^2)\\\\\n &= e^{-1-\\alpha}\\sqrt{\\frac{\\pi}{\\beta}}\\\\\n \\therefore p(y) &= \\sqrt{\\frac{\\beta}{\\pi}} e^{-\\beta x^2}\\\\\n \\text {Now, } \\inint x^2 p(x) dx &= c\\\\\n \\therefore c &= 2\\int_0^\\infty x^2 2 e^{-\\beta x^2}dx \\\\\n c &=  2 \\sqrt{\\frac{\\beta}{\\pi}}\\frac{\\sqrt{\\pi}}{4 \\beta^{3/2}}\\\\\n \\beta &=\\frac{1}{2 c}\n \\end{align*}\n \n Thus, for constraining $\\Braket{v^2} = c^2$, the distribution is $\\boxed{p(v) = \\sqrt{\\frac{\\beta}{\\pi}} e^{-\\frac{1} {2c}v^2}}\\hfill$ Ans.\n\\section*{Problem 4}\nThis is a binomial distribution.\n\nThe mean of one question will be $7$, with standard deviation $\\sqrt{0.7(1-0.3)} = 0.458258$. For the exam, the mean will be $70$ with standard deviation $\\sqrt{10\\times 0.7(1-0.3)} = 1.44914$\n\n\\section*{Problem 5}\n\nHere, RMS distance should be R. Thus, $\\sqrt{\\Braket{x_N^2}} = \\sqrt{N}l = R \\implies N = 5\\times 10^{21}$. Thus, it takes approximately $\\boxed{5\\times 10^{21}}$ steps to reach the radius where convection becomes important.\n\nThe time taken will be $5\\times 10^{21}\\times \\frac{l}{c} = \\boxed{2.30504\\times 10^9 ~\\mathrm s}$\n\n\\section*{Problem 6}\n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[scale=0.5]{random1}\n\\end{figure}\n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[scale=0.5]{random2sm}\n\\end{figure}\n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[scale=0.5]{random2lg}\n\\end{figure}\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[scale=0.5]{scatter}\n\\end{figure}\n\nSuch a variable has a density function as $f(x) = 1$ for all $x$ in the region $[-0.5, 0.5]$. Its RMS step size will be $\\sqrt{\\int_{-0.5}^{0.5}x^2=\\frac1{12}}$, giving us $\\boxed{\\frac1{2\\sqrt3}}$.\n\n\\begin{figure}[!htb]\n\\centering\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.4]{central1}\n\\end{subfigure}\n~~~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.4]{central2}\n\\end{subfigure}\n\\\\~\\\\~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.4]{central3}\n\\end{subfigure}\n~~~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.4]{central4}\n\\end{subfigure}\n\\\\~\\\\~\n\\begin{subfigure}[b]{0.4\\textwidth}\n\\includegraphics[scale=0.5]{central5}\n\\end{subfigure}\n\\caption{As seen in the graphs above, the Gaussian approximates the random walk very quickly.}\n\\end{figure}\n\n\n\\end{document}\n", "meta": {"hexsha": "41fcdedf3e8c4f2bd3381189a0ea78b8216898a0", "size": 7169, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course material/PH 304 - Statistical Physics/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/PH 304 - Statistical Physics/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/PH 304 - Statistical Physics/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.8009708738, "max_line_length": 231, "alphanum_fraction": 0.6402566606, "num_tokens": 2904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.6508270373966117}}
{"text": "\\documentclass{beamer}\n\n\\usepackage{beamerthemevictor,comment,verbatim,graphicx,amssymb}\n\n\\input{tutmacs}\n\\input{slidemacs}\n\\input idxmacs\n\n\\begin{document}\n\n\\title{Raster Graphics}\n\\author{Victor Eijkhout}\n\\date{Notes for CS 594 -- Fall 2004}\n\n\\frame{\\titlepage}\n\n\\frame{\n  \\frametitle{From mathematics to pixels}\n\\begin{itemize}\n\\item Shapes and curves described mathematically (bezier)\n\\item Screen has pixels\n\\item different arithmetic\n\\item rounding behaviour\n\\item Vector graphics vs Bitmap, Raster\n\\end{itemize}\n}\n\n\\section{Basic raster algorithms}\n\\subsection{Lines}\n\n\\frame{\n  \\frametitle{Line drawing}\n\\begin{itemize}\n\\item Symmetry: limit to slope~$\\leq 1$\n\\pgfimage{one-per-column}\n\\item one pixel on per column\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{Incremental drawing}\n\\begin{itemize}\n\\item Line $y=mx+B$, slope $m=\\delta y/\\delta x$.\n\\item Pixels: $\\delta x\\equiv1$, so $\\delta y=m$\n\\[y_{i+1}=y_i+\\delta y.\\]\n\\item implementation\n\\begin{tabbing}\nlet $x_0,y_0$ and $m$ be given, then\\\\\nfor \\=$i=0\\ldots n-1$\\\\\n\\>\\n{WritePixel}$(x_i,\\mathop{\\textrm{Round}}(y_i))$\\\\\n\\>$x_{i+1}=x_i+1$\\\\\n\\>$y_{i+1}=y_i+m$\n\\end{tabbing}\n\\item roundoff, cost\n\\end{itemize}\n}\n\n\\subsection{Midpoint algorithm}\n\n\\frame{\n  \\frametitle{Midpoint algorithm}\n\\begin{itemize}\n\\item Given `on' pixel, choices are 1~right, 2~right-and-up\n\\pgfimage[height=1.5in]{line-midpoint}\n\\item Write\n\\[ y={dy\\over dx}x+B, \\qquad F(x,y)=ax+by+c=0.\\]\nthen $a=dy$, $b=-dx$, $c=B$\n\\item derive $dx,dy$ from the end points\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{Midpoint location}\n\\begin{itemize}\n\\item Does the midpoint~$M$ lie above or under the line?\n\\item  use~$F(\\cdot,\\cdot)$: evaluate the `decision value' of the midpoint:\n\\[ d=F(x_p+1,y_p+1/2). \\]\n\\item The two cases to consider then are\n\\begin{description}\n\\item[$d<0$:] $M$ lies over the line, so we take $y_{p+1}=y_p$;\n\\item[$d\\geq0$:] $M$ lies under the line, so we take $y_{p+1}=y_p+1$.\n\\end{description}\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{Use of $d$}\n\\begin{itemize}\n\\item Use $d$ instead of midpoint:\n\\[ d'=F(x_{p+1}+1,y_{p+1}+1/2). \\]\n\\item Two cases:\n\\begin{footnotesize}\n\\[ \\begin{array}{rll}\n    d'=&a(x_{p+1}+1)+b(y_{p+1}+1/2)+c=\\\\\n    d<0:&= a(x_p+2)+b(y_p+1/2)&=d+a=d+dy\\\\\n    d\\geq0:&= a(x_p+2)+b(y_p+3/2)+c&=d+a+b=d+dy-dx\n\\end{array} \\]\n\\end{footnotesize}\n\\item Update~$d$ with $dy$ or~$dy-dx$ depending on\nwhether it's negative or non-negative.\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{Final refinement}\n\\begin{itemize}\n\\item Start off\n\\[ d_0=F(x_0+1,y_0+1/2)=F(x_0,y_0)+a+b/2=0+dy-dx/2.\\]\n\\item Get rid of the division by~2:\\\\\n$\\tilde F(x,y)=2F(x,y)$;\\\\\n update~$d$ with $2dy$ and~$2(dy-dx)$ in the two cases.\n\\item Digital Differential Analyzers (DDA)\n\\end{itemize}\n}\n\n\\subsectionframe{Circle drawing}\n\\frame{\n  \\frametitle{}\n\\pgfimage[height=1.5in]{circle-midpoint}\n\\begin{itemize}\n\\item Circle: \\[ F(x,y) = x^2+y^2-R^2,\\]\n\\item  decision value in the midpoint~$M$ is\n\\[ d=F(x_p+1,y_p+1/2)=x^2+2x+y^2+y+5/4. \\]\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item Cases\n\\begin{description}\n\\item[$d<0$:] $M$ lies in the circle, so we take $y_{p+1}=y_p$;\n\\item[$d\\geq0$:] $M$ lies outside the circle, so we take $y_{p+1}=y_p+1$.\n\\end{description}\n\\item Updating:\n\\[ \\begin{array}{rll}\n    d'=&F(x_{p+1}+1,y_{p+1}+1/2)=\\\\\n    d<0:&= x^2+4x+y^2+y+4\\,1/4&=d+2x+3\\\\\n    d\\geq0:&= x^2+4x+y^2+3y+6\\,1/4&=d+2(x+y)+5\n\\end{array} \\]\n\\item Construct $2x$,$2y$ by shift\n\\end{itemize}\n}\n\n\\subsectionframe{Cubics}\n\n\\frame{\n  \\frametitle{Stepwise computation}\n\\begin{itemize}\n\\item Cubic function $f(t)=at^3+bt^2+ct+d$\n\\item Strategy: compute the value $f(t+\\delta)$ by updating\n\\[ f(t+\\delta)=f(t)+\\Delta f(t). \\]\n\\item (alternatives: Horner, midpoint)\n\\item Difference:\n\\[ \\begin{array}{rcl}\n    \\Delta f(t)&=&f(t+\\delta)-f(t)\\\\\n        &=&a(3t^2\\delta+3t\\delta^2+\\delta^3)+b(2t\\delta+\\delta^2)+c\\delta\\\\\n        &=&3a\\delta\n    t^2+(3a\\delta^2+2b\\delta)t+a\\delta^3+b\\delta^2+c\\delta\n\\end{array} \\]\n\\item Quadratic term left\n\\end{itemize}\n}\n\n\\frame{\n\\begin{itemize}\n\\item Define\n\\[ \\begin{array}{rcl}\n    \\Delta^2f(t)&=&\\Delta f(t+\\delta)-\\Delta f(t)\\\\\n        &=&3a\\delta(2t\\delta+\\delta^2)+(3a\\delta^2+3b\\delta)\\delta\\\\\n        &=&6a\\delta^2t+6a\\delta^3+2b\\delta^2\n\\end{array} \\]\n\\item Third difference:\n$\\Delta^3f(t)=\\Delta^2f(t+\\delta)-\\Delta^2f(t)=6a\\delta^2$\n\\item Together: compute $f_{n+1}\\equiv f((n+1)\\delta)$ by\n\\[ \\Delta^3f_0=6a\\delta^2,\\quad\n    \\Delta^2f_0=6a\\delta^3+2b\\delta^2,\\quad\n    \\Delta f_0=a\\delta^3+b\\delta^2+c\\delta\n\\]\nand computing by update\n\\[  f_{n+1}=f_n+\\Delta f_n,\\quad\n    \\Delta f_{n+1}=\\Delta f_n+\\Delta^2f_n,\\quad\n    \\Delta^2f_{n+1}=\\Delta^2f_n+\\Delta^3f_0\n\\]\n\\end{itemize}\n}\n\n\\sectionframe{Rasterizing type}\n\n\\frame{\n  \\frametitle{}\nType is tricky: lots of features in small objects\\\\\neveryone immediately sees when it's wrong\\\\\n\\pgfimage[height=1.3in]{raster-problems}\n\\pgfimage[height=1.3in]{illegible}\n}\n\n\\frame{\n  \\frametitle{Badly rasterized characters}\nObvious algorithm: pixel on if center in the contour\\\\\n\\pgfimage[height=1.3in]{e-bad}\n\\pgfimage[height=1.3in]{e-good}\\\\\n\\begin{itemize}\n\\item Problems with curves tangent to $n+1/2$ lines\n\\item Different scalings, different raster\n\\item Variable placement\n\\end{itemize}\n}\n\n\\subsection{Basic algorithms}\n\n\\frame{\n  \\frametitle{Scaling and rasterizing}\n\\parbox[b]{1in}{Original character is on internal raster:}\n\\pgfimage[height=1in]{fig2-1-1}\n\\parbox[b]{1in}{Scale to target raster:}\n\\pgfimage[height=1in]{fig2-1-2}\n\n\\parbox[b]{1in}{Round to target raster:}\n\\pgfimage[height=1in]{fig2-1-3}\n\\parbox[b]{1in}{Set pixels:}\n\\pgfimage[height=1in]{fig2-1-4}\n}\n\n\\frame{\n  \\frametitle{Scaling vs design size}\n\\pgfimage[height=.25in]{design-size}\n\\begin{itemize}\n\\item Scaling is a compromise\n\\item Different design sizes\n\\item Adobe Multiple Master\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{Filling in}\n\\begin{itemize}\n\\item Precisely what does `pixel lies within the contour' mean?\n\\item Complications: letters with `bowls'; multiple contours\n\\pgfimage[height=1in]{overlapping-contours}\n\\pgfimage[height=1in]{winding}\n\\item Winding rules\n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{Winding rules}\n\\pgfimage[height=1.2in]{winding_ar4win_100}\n\\pgfimage[height=1.2in]{winding_ar4win_150}\n}\n\n\\frame{\n  \\frametitle{Dropouts}\n\\pgfimage[height=2.5in]{dropout}\n}\n\n\\subsectionframe{Hinting / instructing}\n\n\\frame{\n  \\frametitle{}\n\\pgfimage[height=1.3in]{o-horizontal}\n\\pgfimage[height=1.3in]{o-vertical}\n\\begin{itemize}\n\\item Small programs per font~/ character\n\\item Give constraints on placement, relations, distance\n\\end{itemize}\n}\n\n\\end{document}\n\\sectionframe{Anti-aliasing}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item \n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item \n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item \n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item \n\\end{itemize}\n}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item \n\\end{itemize}\n}\n\n\\end{document}\n\n\\frame{\n  \\frametitle{}\n\\begin{itemize}\n\\item \n\\end{itemize}\n}\n\n", "meta": {"hexsha": "f72adf210c684408491a94cb6aa43496d2be04a5", "size": 6997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/raster.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/raster.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/raster.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": 22.1424050633, "max_line_length": 75, "alphanum_fraction": 0.6814349007, "num_tokens": 2731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6508270261692272}}
{"text": "\\subsection{Linear Approximations}\\label{sec:LinApprox}\nWe begin by the first derivative as an application of the tangent line to approximate $f$.\n\nRecall that the tangent line to $f(x)$ at a point $x=a$ is given by\n\\[ L(x) = f'(a) (x-a) + f(a).\\]\nThe tangent line in this context is also called the \\dfont{linear approximation} to $f$ at $a$.\n\nIf $f$ is differentiable at $a$ then $L$ is a good approximation of\n$f$ so long as $x$ is ``not too far'' from $a$.  Put another way, if\n$f$ is differentiable at $a$ then under a microscope $f$ will look\nvery much like a straight line, and thus will look very much like $L$;\nsince $L(x)$ is often much easier to compute than $f(x)$, then it makes sense to use $L$ as an approximation. Figure~\\ref{fig:linear_approximation} \nshows a tangent line to $\\ds y=x^2$ at three different magnifications. \n\n\\figure[!ht]\n\\centerline{\\includegraphics[width=2in]{images/linear_approx_1}\\hfill\n\\includegraphics[width=2in]{images/linear_approx_2}\\hfill\n\\includegraphics[width=2in]{images/linear_approx_3}\\hfill}\n\\caption{The linear approximation to $\\ds y=x^2$. \\label{fig:linear_approximation}}\n\\endfigure\n\nThus in practice if we want to approximate a difficult value of $f(b)$,\nthen we may be able to approximate this value using a linear approximation,\nprovided that we can compute the tangent line at some point $a$ close to $b$.\nHere is an example.\n\n\\begin{example}{Linear Approximation}{linear approximation}\nLet $f(x)=\\sqrt{x+4}$, what is $f(6)$?\n\\end{example}\n\n\\begin{solution}\nWe are asked to calculate $f(6)=\\sqrt{6+4}=\\sqrt{10}$ which is not easy\nto do without a calculator. However 9 is (relatively) close to 10 and\nof course $f(5)=\\sqrt{9}$ is easy to compute, and we use this to approximate $\\sqrt{10}$.\n\nTo do so we have $f'(x)=1/(2\\sqrt{x+4})$, and thus the linear approximation to $f$ at $x=5$ is\n\\[L(x)=\\bigg(\\frac{1}{2\\sqrt{5+4}}\\bigg)(x-5)+\\sqrt{5+4}=\\frac{x-5}{6}+3.\\]\n\nNow to estimate $\\sqrt{10}$, we substitute 6 into the linear approximation $L(x)$ instead of $f(x)$, to obtain\n\\[ \\sqrt{6+4}\\approx \\frac{6-5}{6}+3=\\frac{19}{6}=3\\sfrac{1}{6}=3.1\\bar{6}\\approx 3.17 \\]\n\nIt turns out the exact value of $\\sqrt{10}$ is actually 3.16227766\\ldots\nbut our estimate of 3.17 was very easy to obtain and is relatively accurate.\nThis estimate is only accurate to one decimal place.\n\\end{solution}\n \nWith modern calculators and computing software it may not appear\nnecessary to use linear approximations, but in fact they are quite\nuseful. For example in cases requiring an explicit numerical approximation, they\nallow us to get a quick estimate which can be used as a\n``reality check'' on a more complex calculation. Further in some complex\ncalculations involving functions, the linear approximation makes an\notherwise intractable calculation possible without serious loss of\naccuracy.\n\n\\begin{example}{Linear Approximation of Sine}{linear approximation of sine}\nFind the linear approximation of $\\sin x$ at $x=0$, and use it to compute small values of $\\sin x$.\n\\end{example}\n\n\\begin{solution}\nIf $f(x)=\\sin x$, then $f'(x)=\\cos x$, and thus the linear approximation of $\\sin x$ at $x=0$ is:\n\\[ L(x)=\\cos (0)(x-0)+\\sin (0)=x. \\]\nThus when $x$ is small this is quite a good approximation and is used\nfrequently by engineers and scientists to simplify some calculations.\n\nFor example you can use your calculator (in radian mode since the\nderivative of $\\sin x$ is $\\cos x$ only in radian) to see that\n\\[ \\sin (0.1)=0.099833416\\ldots \\]\nand thus $L(0.1)=0.1$ is a very good and quick approximation without any calculator!\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:LinApprox}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex} \nFind the linearization $L(x)$ of $f(x)=\\ln (1+x)$ at $a=0$. Use\nthis linearization to approximate $f(0.1)$.\n\\begin{sol}\n$L(x)=x$, $f(0.1)\\approx L(0.1)=0.1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nUse linear approximation to estimate $(1.9)^3$.\n\\begin{sol}\nChoose $f(x)=x^3$ and $a=2$, the closest integer to 1.9. The\nlinearization of $f$ at $a$ is $L(x)=12(x-2)+8$, and $(1.9)^3=f(1.9)\\approx L(1.9)=12(1.9-2)+8=6.8$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nShow in detail that the linear approximation of\n$\\sin x$ at $x=0$ is $L(x)=x$ and the linear approximation of $\\cos x$\nat $x=0$ is $L(x)=1$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nUse $f(x)=\\sqrt[3]{x+1}$ to approximate $\\sqrt[3]{9}$ by choosing an\nappropriate point $x=a$. Are we over- or under-estimating the value of $\\sqrt[3]{9}$? Explain.\n\\begin{sol}\nChoose $a=7$ since $f(7)=\\sqrt[3]{7+1}=\\sqrt[3]{8}=2$ is an integer\nclose to $\\sqrt[3]{9}$. The linearization of $f$ at $a=7$ is\n$L(x)=\\sfrac{1}{12}(x-7)+2$. Then $f(8)=\\sqrt[3]{8+1}=\\sqrt[3]{9}\\approx L(8)=\\sfrac{1}{12}(8-7)+2=2.08\\bar{3}$. We are over-estimating $\\sqrt[3]{9}$ since $L(x)>f(x)$ for all $x$ around $a=7$.\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "6627b163149d2ca22117b270ca319cc5d7aad977", "size": 4945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-4-1-linear-approximations.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-4-1-linear-approximations.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-4-1-linear-approximations.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0, "max_line_length": 193, "alphanum_fraction": 0.6916076845, "num_tokens": 1606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.9136765263519308, "lm_q1q2_score": 0.6507498280514894}}
{"text": "\n\\chapter{Solution Development}\\label{chapter:analysis}\nIn a previous work on this topic, Wörndl and Herzog  \\parencite{cbrecsys2014} drew inspiration for their formal model based on the Oregon Trail knapsack problem (see Section \\ref{sec:oregon}); they formulated a model that extends the value function of the problem using a penalty function.\n\nFor clarity, we adjusted the notation used in their paper to fit the notations used in previous function values. Wörndl and Herzog formally defined their value function as follows:\n\n\\begin{gather}\n \\tag{1} f_j(x_j, x_{d_j}) = x_j \\cdot v_j - \\sum_{e \\in x_{d_j}} ( t(j, e) \\cdot x_j \\cdot v_j \\cdot [x_e > 0])\\label{eq:3d}\n\\end{gather}\n\nwhere $v_j$ is the value of region $j$ (i.e, item) for the specified user query, and $t(j, e)$ is the penalty function for the two regions $j$ and $e$. Their value function is similar to the function Type \\ref{eq:2g} specified by the original Oregon Trail knapsack model. However, the previously defined value-reducing constant factor $t$, is a function of the two regions $j$ and $e$. \n\nWörndl and Herzog’s formal model is defined as follows:\n\\begin{align}\n    \\tag{1}maximize \\qquad  &\\sum_{i=1}^n  f_j(x_j, x_{d_j}) \\label{eq:3a}\\\\\n    \\tag{2}subject \\ to \\qquad &\\sum_{i=1}^n x_i d_i  \\leq D \\label{eq:3b}\\\\\n    \\tag{3}&\\sum_{i=1}^n x_i\\ b_i \\leq B \\label{eq:3c}\\\\\n    \\tag{4} &x_i \\in \\{0,1\\}\n\\end{align}\n\nwhere $f_j(x_j, x_{d_j})$ is the penalty function defined in \\ref{eq:3d}; $d_i$ is item $i$'s recommended duration of stay, and $b_i$ is item $i$'s recommended daily budget. $D$ is the maximum possible duration of stay and $B$ is the maximum budget the user can spend on their trip. \n\nWörndl and Herzog concluded that the penalty function defined in their work could be improved to produce better results. Building penalty-based functions requires careful consideration of the function parameters and the function itself. Thus, to gain freedom from the influence of the penalty function, we reformulate and extend the problem definition to a non-penalty-based approach. If through further analysis, a penalty-based approach proves to be a better fit for our selected algorithm, we will redefine a penalty function as needed.\n\nThe framework for our \\gls{rs} comprises a knapsack model for the multi-objective \\gls{op}, a data model, and a meta-heuristic solution. In the following sections, we analyze these three parts in detail.\n\n\n\\section{Problem Reformulation} \\label{sec:problem_definition}\n\nLet us consider $n$ regions $(i = 1, ..., n)$. Each region $i$ will have $k$ profits $s_{ik}\\ (p = 1, ...,k)$. Given a set $N$ of $m$ traveling preferences $N = \\{N_1, N_2,...,N_m\\}$, $s_{ik}$ is dependent on $i$'s score on $N$. For example, a region can have a different score for shopping and another for hiking.\nThe recommendation problem can be modeled as a multi-objective \\gls{op}. Given a user query, some regions must be selected to maximize the $p$ total profits while not exceeding the budget limit $B$ and the total stay duration $D$. Each user preference must be fulfilled by at least one of the selected regions. Assuming the system recommends Trip $T$ comprising $n$ regions ($T = {x_1, x_2, ..., x_n}$), the physical distance between a region $x_i$ and its neighbor $x_2$ should not exceed a defined constant $\\sigma$. In a case in which no location coordinates for the regions are available, the regions in the recommended trip should be within reasonable distance from one other. Additionally, the duration of stay in a particular region ${x_i}$ should ensure a minimum utility value, which is defined in the algorithm.\n\nThe mathematical model of the \\gls{moop} is defined as follows:\n\n\\begin{align}\n    \\tag{1}maximize \\qquad  &z_n(x) = \\sum_{k=1}^p x_i\\ s_{ik}, \\hspace{1cm} i = 1,...,n \\label{eq:3_1a}\\\\\n    \\tag{2}subject \\ to \\qquad &\\sum_{i=1}^n x_i\\ d_i  \\leq D \\label{eq:3_1b}\\\\\n    \\tag{3}&\\sum_{i=1}^n x_i\\ b_i \\leq B \\label{eq:3_1c}\\\\\n    \\tag{4}&\\sum_{j \\in N} x_{ij} \\geq 1 \\label{eq:3_1e}\\\\ \n    \\tag{5}&\\sum_{i=1}^n x_{i} \\ g(p_i) \\leq \\sigma,  \\hspace{1cm}  \\label{eq:3_1f} \\\\\n    \\tag{7} x_i \\in \\{0,1\\}, \\qquad &\\forall \\ 1 \\leq i \\leq n \\label{eq:3_1f2}\n\\end{align}\n\nwhere $x_i = 1$ when item $i$ is chosen; otherwise $x_i = 0$. \nConstraints \\ref{eq:3_1b} and \\ref{eq:3_1c} represent the constraints on total stay duration and budget, respectively. Equation \\ref{eq:3_1e} ensures that each user preference is satisfied at least once. Constraint \\ref{eq:3_1f} represents the physical distance between the regions, in which $g$ is a function of the physical location. It is assumed that all coefficients $s_{ik}, b_{i}, B, d_i,$ and $D$ are positive. \n\n\\subsection*{Pareto Optimum}\nThere are multiple scores to be maximized in the objective function. Therefore, choosing an objective maximizing optimal solution without trade-offs is infeasible. In multi-objective optimization, Solution $s$ is said to dominate $s'$ if $s$ is at least as good as $s'$ in every criterion, and $s$ is better in at least one criterion; $s \\succ s'$ is used to denote such a case. If no solution dominates Solution $s^*$, then $s^*$ is said to be \\textit{Pareto optimal} (i.e., non-dominated). The set of all non-dominated vectors is known as the \\textit{Pareto front}.\n\n\\textbf{Example}:\nFigure \\ref{fig:moopsample} a two-objective instance of the \\gls{moop} problem. For simplicity, we assume two given preferences. The gray box displays the user input. When mapped to our problem definition, there are two objectives to be maximized, where an objective represents a single item. An item can be any \\gls{poi}, for example attraction sites, region, or route. $f = (\\Vec{f_1}, \\Vec{f_2}, ... ,\\Vec{f_k})$ represents all feasible solutions. We compute a solution in the objective space $\\Vec{f_i} = (z_1, z_2)$. The objective values are computed on preferences $M$ and $S$, while respecting the necessary constraints. Parameter $x$ in the illustration is a boolean array that encodes the selection of an item combination. The selected item combinations are subject to the notion of Pareto optimality defined above. For example $f_7 \\succ f_2$ because it is better in at least one of its objective values as $f_2$ and it is strictly better in another value. The Pareto front consists of the selections $\\{f_1,f_5,f_7,f_9,f_{10}\\}$, and we achieve a total score of (24, 23). \n\n\n\\begin{figure}[ht!]\n    \\centering\n    \\includegraphics[width=8cm]{Moop}\n    \\caption{Example solution to the multi-objective orienteering problem}\n    \\label{fig:moopsample}\n\\end{figure}\n\nPareto optimality here implies that there is no item combination $f_k$ that will improve the achievable score of at least one item without diminishing the achievable score of another item.\n\nWe can also extend the concept of Pareto optimality from the solution space to the objective space. Given $n$ objective functions $z = (z_1,...,z_n)$, with each objective having a score $\\Vec{v} = (v_1,...,v_j)$ on $j$ criteria, we define the concept of Pareto optimality in the objective space as follows. An objective $z$ dominates an objective $z'$, denoted by $z \\succ z'$, if\n\\begin{itemize}\n    \\item $z_i(v) \\geq z_i'(v)$ on each score of $\\Vec{v_j}$; and\n    \\item there exists one score $v^*$ such that $z_i'(v^*) > z_i'(v)$.\n\\end{itemize}\n\nAgain, Pareto optimality implies that there is no feasible objective $z_i$ such that $v'$ does not make it less effective in at least one other criterion.\\newline\nHaving gained a better understanding of what is deemed optimal, an algorithm that can efficiently compute the Pareto front from a set of given items is what we aim to develop in subsequent sections.\n\n\n\n\\section{Data Model}\nThe underlying data model for this thesis is a travel database curated by Wörndl and Herzog \\parencite{cbrecsys2014} in their previous work. The travel database contains realistic data on a region. Information about each region includes:\n\\begin{enumerate}\n    \\item Minimum weekly budget for a region\n    \\item Minimum duration to achieve a 25\\% and 75\\% utility respectively. An algorithm can either implement a minimum 25\\% threshold or a 75\\% minimum utility from stay threshold;\n    \\item The score of a region for particular travel activity preferences on a five-point Likert scale;\n    \\item The security score of a region on a five-point Likert scale; and\n    \\item The monthly weather score of a region on a five-point Likert scale (i.e., recommended months).\n\\end{enumerate}\nThe data model is hierarchically structured such that a region is always a sub-region of another region. The world is the root region, followed by the continents at the second level. Regions are geographical areas. A region could be a country, a section of a country, or a continent. For example Figure \\ref{fig:datamodel} illustrates the hierarchical structure of the data model. The US and Canada are sub-regions of North America, while Alaska and Texas are sub-regions of the US. Ontario is a sub-region of Canada. The database is composed of 196 regions. All regions (except the root region) have a recommendation for a minimum stay at 25\\%. Unlike previous models that calculate the connection between regions by specifying the necessary effort (time and cost) to travel from one region to another, we model connections between regions based solely on positions in the hierarchical tree structure. We extend the underlying data model to contain all sub-regions of a region. If two regions are sub-regions of the same parent, we consider them connected.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.4\\textwidth, height=.4\\textwidth]{Datamodel}\n    \\caption{Hierarchical structure of the underlying data model}\n    \\label{fig:datamodel}\n\\end{figure}\n\n\n\\section{Analysis of Algorithmic Methodologies}\\label{sec:alg_approaches}\nAccording to Golden et al. \\parencite{Golden1987TheProblem}, \\gls{op} is an NP-hard problem. Hence, no known or expected algorithm can solve the problem optimally in polynomial time (i.e., an exact solution cannot be found within a reasonable amount of time). Computing an optimal solution with multiple objectives is even more intractable. Hence, there is usually a trade-off between time and accuracy. In multi-objective optimization, one is often interested in the Pareto front. However, it is usually infeasible to generate the exact set of a Pareto front. Reasons for this can be that the number of Pareto optima is too large, or the determination of a single Pareto optimum is computationally difficult. Therefore, the goal is usually to identify a satisfactory Pareto set approximation (i.e., a set as close to the optimum as possible \\parencite{Fonseca2005AOptimizers}. Approximate algorithms offer near-optimal solutions to computationally intractable problems (mostly) in a moderate amount of time and are the major alternatives for solving NP-hard optimization problems.\n\n\nApproximate algorithms can be classified as heuristics and meta-heuristics. Heuristics are usually problem dependent and inflexible (i.e., defined for a specific problem). Meta-heuristics are problem independent and can be applied to a broad range of optimization problems. In Chapter \\ref{chapter:literature_review}, we found that meta-heuristic solutions are commonly used to solve \\glspl{op}. Meta-heuristic solutions are also commonly used in multi-objective optimization in various research areas. Certain requirements must be considered when designing or selecting an appropriate algorithm to solve the \\gls{moop}. Some requirements are intuitive for our problem domain. For example, a slow computational time by the end algorithm is intolerable for a user-oriented system. Some issues are not so intuitive. Preserving uniform diversity implies that the selected solutions in the approximated Pareto front are diverse and uniformly distributed. In addition, the \\gls{moop} has been defined such that a single objective represents a single user’s preference. We are unable to pre-determine the number of preferences a user might select. A user could have just one preference. They might also have two or more preferences. Therefore, an appropriate algorithm should be applicable to a dynamic number of objectives. A brief summary of the most important requirements of the desired algorithm is as follows:\n\\begin{itemize}\n    \\item Tolerable computational time,\n    \\item Applicability to problem domain\n    \\item Uniform preservation of diversity, \n    \\item Applicability to large-scale problems,\n    \\item Applicability to a dynamic number of objectives, and\n    \\item Moderate implementation complexity.\n\\end{itemize}\n\n\n\nIn developing an algorithm to solve our optimization problem, we first address the basic methodologies for designing an approximation algorithm. We then analyze possible heuristic and meta-heuristics solutions. In this chapter, we assume a maximization problem in which function $g$ means $f_k$ has to be maximized.\n\n\\subsection{Greedy Methods}\nGreedy methods help find sub-optimal solutions that satisfy some performance guarantee in NP-hard problems. The idea is to generate a solution incrementally by making the best possible choice according to a simple criterion at each decision-making point. For example, a greedy approach to solving the simple knapsack problem is to iteratively select a node with the least weight. This approach is best used together with some form of heuristic rather than as a stand-alone method. When used alone, the heuristics generate only a minimal number of different solutions.\n\n\n\\subsection{Local Search}\nLocal search techniques range from simple heuristics to complex meta-heuristics. The basic idea behind a local search is to start from an initial (partial or non-partial) \\gls{candidate solution}. The solution is improved by making local changes to it and moving from one \\gls{candidate solution} to a neighboring \\gls{candidate solution} until no further improvement is possible. A local change might involve removing elements from the ground set, adding elements, or swapping elements. Local search is a good heuristic for computing near-optimum solutions to reasonably sized problems. Usually, a neighborhood function $N: S \\mapsto 2^S$ where $S $ is the set of feasible solutions specifies for each solution $s \\in S$ a subset $N(s)$ of neighbors of $s$ (neighborhood relation), or solutions that are close to $s$ \\parencite{Gonzalez2007HandbookMetaheuristics}.\n\nFor many problems, computing the locality gap (i.e., the difference between local and global optima) is complex, and the locality gap using a local natural search is commonly very large. Additionally, the algorithm might visit the exact location within the search space more than once. Thus, it can become trapped in a location far away from the global optimum. These situations all lead to very poor approximation. Consequently, many local search techniques use mechanisms to help escape a position or reduce the locality gap. For example, one could use a restart strategy when stuck in a local minimum in the iterative descent algorithm. Alternatively, one could relax the improvement criterion by performing a non-improving step. However, these strategies do not guaranty escaping an arbitrary local minimum \\parencite{HolgerH2005StochasticSearch}.\n\n\n\\subsubsection{Iterative Improvement}\nThe iterative improvement algorithm is the most basic local search algorithm and forms the basis of most local search algorithms. Algorithm \\ref{alg:iterative-improvement} (\\textit{IterativeDescent)} produces a simple iterative improvement (also known as iterative descent). The solution of the iterative descent is the optimum local value, which may or may not be a global optimum. Condition $g(s') > g(s)$ is the evaluation of the candidate solution. solution. Evaluation functions serve as guidance to a solution \\parencite{HolgerH2005StochasticSearch}. In optimization problems, the objective function’s properties usually determine the evaluation function. Below, the algorithm assumes a maximization objective function:\n\n \\begin{algorithm}\n  \\caption{General outline of iterative improvement local search}\\label{alg:iterative-improvement}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\Input{Set of candidate solutions $S$, Neighborhood function $N$, Objective function $g$}\n  \\Output{A local optimum solution $s \\in S$}\n    determine an initial candidate solution $s$\n    \n    \\While {$N(s)$ contains better solution than $s$}{\n        choose a solution $s' \\in N(s)$ such that\\\\\n             \\hspace{0.5cm}$g(s') > g(s)$\\\\\n        $s := s'$\\\\\n    }\n  \\end{algorithm}\n  \nThe simple iterative improvement algorithm can be extended to multi-objective optimization problems. For multiple objectives, the solution of the iterative improvement and all local search-based algorithms, in general, is defined as the approximate set of Pareto optimal solutions (Pareto front) found during the search process. A move improves the current solution when a newly generated candidate solution is added to the approximate Pareto front. This means that the evaluation condition of the single-objective iterative improvement algorithm changes. The Pareto local search proposed by Paquete et al. \\parencite{Paquete2004ParetoStudy} adapts the notion of Pareto optimality in a simple local search. First, the algorithm randomly selects one non-visited candidate solution s and examines all neighbors of s. Second, it adds all neighbors of s that are non-dominated by the set of candidate solutions. It stops when the neighborhood of all candidate solutions has been examined \\parencite{Gonzalez2007HandbookMetaheuristics}. Similar to the Pareto local search, the two-criteria local search \\parencite{Angel2004ApproximatingProblem} is another multi-objective adaptation of the single-objective iterative improvement algorithm. While the Pareto local search chooses only one candidate solution to examine its neighborhood and immediately updates the list of candidate solutions, the two-criteria local search examines the neighborhood of all candidate solutions in an iteration.\n\n\n\n   \n\\subsection{Stochastic Local Search}\nMany local search algorithms use randomized decisions, for example to determine initial solutions or when determining search steps. These are called stochastic local search (SLS) algorithms. The majority of algorithms for computing high-quality approximations to the Pareto optimal set are based on \\gls{sls}. Typically, additional memory is used to store the best candidate solution from previous searches. If the solution is feasible, it is returned upon termination of the algorithm; the objective function is used to determine the quality of the candidate solutions. The performance of any \\gls{sls} algorithm depends significantly on the underlying neighborhood relations and the size of the neighborhood. Determining the choice of a neighborhood relation to use for \\gls{sls} is mostly problem specific. Insertion and swap are two widely used neighborhood relation-generating operators. \\gls{sls} techniques are attractive because they allow solving problems using moderately generic and easily implementable algorithms that can also be extended with or adapted based on problem-specific knowledge \\parencite{HolgerH2005StochasticSearch}. They range from simple constructive algorithms and iterative improvement algorithms to general algorithm frameworks adapted to a specific problem under consideration. Popular \\gls{sls} algorithms include \\gls{vnd}, \\gls{sa}, \\gls{ts}, \\glspl{ea}, \\gls{aoc}, and many others. \n\n\\subsubsection{Randomized Iterative Improvement}\nUsing large neighborhoods is particularly beneficial to escape the local minima. However, there is an associated time complexity with performing search steps in a vast neighborhood. \\gls{sls} algorithms try to implement the concept of large neighborhoods, but with trade-offs. A popular idea in \\gls{sls} algorithms is to use large neighborhoods but reduce their size by never examining neighbors that are unlikely to yield any improvements in evaluation function value\n\nAlgorithm \\ref{alg:randomized-iterative-improvement} is a \\gls{sls}-based iterative improvement to Algorithm \\ref{alg:iterative-improvement}. Algorithm \\ref{alg:randomized-iterative-improvement} uses randomization as a diversification mechanism to improve the algorithm’s quality. The $\\rho$ is a noise parameter that corresponds to the probability of performing a random step instead of an improvement step \\parencite{HolgerH2005StochasticSearch}. The search can be terminated, for example, after a certain number of steps or after no improvement has been achieved in many steps. This algorithm outperforms the pure local search version of iterative descent; when it is run long enough, an optimal solution to any given problem instance can be found \\parencite{HolgerH2005StochasticSearch}.\n\n \\begin{algorithm}\n  \\caption{General outline of randomized iterative improvement local search}\\label{alg:randomized-iterative-improvement}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\Input{Set of candidate solutions $S$, Neighborhood function $N$, Objective function $g$}\n  \\Output{A local optimum solution $s \\in S$}\n    \\While {termination condition not satisfied}{\n        \n        \\eIf{there exists a solution $s ' \\in N(s)$ with probability $\\rho$}{\n        choose solution $s' \\in N(s)$ uniformly at random\\\\\n        }\n        {\n        \\eIf{there exists $g(s') > g(s)$ where $s' \\in N(s)$}{\n        choose solution $s'$ \\\\\n        }{\n        choose a solution $s' \\in N(s)$ such that $s'$ is maximal \\\\\n        }\n        }\n        \n        $s := s'$\\\\\n    }\n  \\end{algorithm}\n\n\n\n\\subsubsection{Variable Neighborhood Descent}\n\\Gls{vnd} algorithms benefit from the advantages of large neighborhoods by reducing the time consumed in the search steps. In the descent phase, standard small neighborhoods are used until a local optimum is encountered. Then, in the perturbation phase, the search process switches to a different neighborhood, which might help exit the corresponding basin of attraction and allow further search progress. Algorithm \\ref{alg:vnd} highlights the general outline of a \\gls{vnd}. Unlike the previously outlined algorithms, $N$ in this algorithm is a set $\\{N_1,..., N_{imax}\\}$ of neighborhood relations, usually ordered according to the increasing size of respective local neighborhoods. Variations of the \\gls{vnd} algorithm have been widely and successfully applied in the single-objective domain in practice and are known to show optimal results. The algorithm can adapt to refinement and solution definitions in a multi-objective setting as defined in the iterative refinement algorithm in the previous section (see \\parencite{Duarte2015Multi-objectiveProblems} for an example adaptation).\n\n\\begin{algorithm}\n  \\caption{General outline of variable neighborhood descent}\\label{alg:vnd}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\Input{Set of candidate solutions $S$, Set of neighborhood relations $N$, Objective function $g$}\n  \\Output{A local optimum solution $s \\in S$}\n    \\While {$i < imax$}{\n        choose the most improving $s'$ of $s \\in N_i$\\\\\n        \\eIf{$g(s') > g(s)$}{\n        $s := s'$\\\\\n        $i := 1$\n        }{\n        $i := i + 1$\n        }\n    }\n  \\end{algorithm}\n\n\\subsubsection{Simulated Annealing}\n\\Gls{sa} is related to a probabilistic iterative improvement. It is based on the idea that the probability of accepting a deteriorating step should depend on the respective deterioration in evaluation function value, such that the worse a step is, the less likely it is that it will be performed \\parencite{HolgerH2005StochasticSearch}.\n\nThe algorithm has a proposal mechanism in which a neighbor $s'$ is chosen at random, and the acceptance criteria are based on statistical mechanics (metropolis condition) as follows:\n\n\\begin{align*}\n    \\rho_{accept}(T,s,s') := \\begin{cases}\n                            1, &\\text{if}\\quad g(s') \\geq g(s);\\\\\n                            exp(\\frac{g(s)-g(s')}{T}), &\\text{otherwise};\n                             \\end{cases}\n\\end{align*}\n$\\rho_{accept}$ is the probability of accepting $s'$ and is parameterized by the temperature $T$ used to decide whether the search accepts $s'$ or stays at $s$. The condition above depicts the case where $T$ is kept constant and can be adjusted throughout the search process according to an annealing schedule. The technique for temperature adjustment used in simulated annealing helps escape the local minima. However, the results of simulated annealing are limited since it requires a cooling process that is typically slow in practice \\parencite{HolgerH2005StochasticSearch}. Additional techniques such as neighborhood pruning, greedy initialization, low-temperature starts, and look-up tables for acceptance probabilities are typically used to achieve competitive results.\n\nSA algorithms have been used for multi-objective optimization. Such adaptations require modifying the acceptance criterion.  Serafini \\parencite{Serafini1994SimulatedProblems} provides guidelines to apply in computing the probability $\\rho_{accept}$ as follows:\n\n\\begin{align*}\n    \\rho_{accept}(T,s,s') := \\begin{cases}\n                            1, &\\text{if}\\quad \\Vec{f}(s') \\succ \\Vec{f}(s);\\\\\n                            [0,1), &\\text{if}\\quad \\Vec{f}(s) \\succ \\Vec{f}(s');\\\\\n                            exp(\\frac{g(s)-g(s')}{T}), &\\text{otherwise};\n                             \\end{cases}\n\\end{align*}\n\n\n\n\\subsubsection{Tabu Search}\n\\Gls{ts} is a meta-heuristic based on adaptive memory and responsive exploration \\parencite{Gonzalez2007HandbookMetaheuristics}. It guides a local heuristic search routine to explore the solution space beyond the local optimum. The algorithm forbids steps to recently visited search positions by preventing the local search from immediately returning to a previously visited candidate solution \\parencite{HolgerH2005StochasticSearch}. This prevention step can be implemented by explicitly memorizing previously visited candidate solutions and ruling out any step that would lead back to those. In contrast to a simple descent method, \\gls{ts} permits worsening steps, but the moves are selected from a modified part of the neighborhood. Hence, the neighborhood of s is not static. \\gls{ts} algorithms are highly efficient and successfully used in a wide range of fields, including \\gls{op}. It is, however, crucial to carefully choose a neighborhood relation and to use efficient caching and incremental updating schemes for the evaluation of candidate solutions \\parencite{HolgerH2005StochasticSearch}. In \\gls{ts} for multi-objective optimization, the central idea is to examine the neighborhood of a set of solutions, extract non-dominated solutions, and accept only some non-tabu solutions for inclusion in the approximate Pareto front. \n\n\\subsection{Evolutionary Algorithms}\n\\Glspl{ea} are meta-heuristics whose methodologies are based on Darwin’s theory of evolution, where an individual in a population (set of candidate solutions) is referred to as a chromosome. A gene represents the individual’s properties. \\glspl{ea} follow the same schema as shown in Algorithm \\ref{alg:ea} \\parencite{Gonzalez2007HandbookMetaheuristics} below. The basic principle behind \\glspl{ea} is the survival of the fittest, where a fitness function based on the objective function, constraints, or some quality measure is used to select individuals from the population. For each generation (iteration), individuals compete to produce offspring \\parencite{Engelbrecht2007ComputationalEdition}. An \\gls{ea} might use a crossover operator to recombine two or more individuals to produce new individuals for the next generation. A mutation operator might also be used to alter the gene (characteristics of an individual) of a chromosome. The used reproduction operators depend on the chosen solution representation and the problem formulation. For example, one-point crossover, uniform crossover, and flip mutation are commonly used for representing binary string solutions. In contrast, binary string encoding is typically used for knapsack problems \\parencite{Gonzalez2007HandbookMetaheuristics}.  \n\n\\begin{algorithm}\n  \\caption{General outline of evolutionary algorithms}\\label{alg:ea}\n  $P$ = apply $\\tau$ on $G$ to generate $\\mu$ individuals (the initial population);\\\\\n    \\While {termination criteria not met}{\n        $P'$ = apply $\\theta$ on $P$\\Comment*[r]{selection}\n        $P''$ = apply $\\omega_r$ on $P'$; $r \\in \\{1,..,n operators\\}$ \\Comment*[r]{reproduction}\n        $P$ = apply $\\psi$ on $P$ and $P''$\\Comment*[r]{replacement}\n        \n    }\n  \\end{algorithm}\n\n\\Glspl{ea} are popularly used across different industries, and Pareto-based \\glspl{ea} are particularly suited for multi-objective optimization. Unlike traditional techniques such as \\gls{ts}, \\gls{sa}, and \\gls{vnd}  that originally output a single local optimum, Pareto-based \\glspl{ea} typically provide the whole set of Pareto optimal solutions in a single run, making them suitable for our problem domain. Examples of Pareto-based \\glspl{ea} in literature include the \\gls{nsga}, \\gls{spea} and \\gls{pma}.The performance of these algorithms relies on specifying a robust fitness function and estimating a good fitness-sharing parameter. The fitness-sharing parameter helps adjust an individual’s fitness based on the fitness of others. Furthermore, as in most population-based meta-heuristics, determining the initial population is important. If the initial population is not diverse, premature convergence might occur \\parencite{Talbi2009Metaheuristics:Implementation}.\n\n\\subsection{Ant Colony Optimization}\n\\Gls{aoc} is a meta-heuristic that is part of swarm intelligence and inspired by ants. Artificial ants are designed to simulate the problem-solving behavior of ants in a colony. Ants coordinate their activities \\textit{stigmergy}, an indirect communication form through modification of the environment. The idea behind ant algorithms is to use a form of artificial stigmergy to coordinate societies of artificial agents \\parencite{Dorigo2018TheMetaheuristic}. An effective solution is found only through cooperation among many individuals in the colony. Inspired by the pheromones deposited by real ants, virtual ants are designed to modify numeric values (virtual pheromones) associated with different problem states. The sequence of pheromone values associated with problem states (pheromone trail) enables communication. Ants can also forget the pheromone trail history and focus on new promising search directions through an evaporation mechanism \\parencite{Gonzalez2007HandbookMetaheuristics}. \n\nSolutions are created incrementally by moving through available problem states and making stochastic decisions at each step. Additionally, many improved and efficient \\gls{aoc} algorithms make use of local searches to improve the probability of an ant choosing a component and consequently improve the quality of the solution constructed by the ants \\parencite{Stutzle2000MAX-MINSystem}. \\Gls{aoc} can be applied to any combinatorial optimization problem for which a constructive heuristic can be defined. However, the problem must be mapped to a representation that artificial ants can use to build solutions \\parencite{Dorigo2018TheMetaheuristic}. Specifically, the problem must be representable as a construction graph $G_c = (C, L)$, where the set $L$ fully connects the components $C$. The ants exploit $G_c$ to search for an optimal solution. Fortunately, knapsack problems can be represented as a construction graph by representing the set of items as the set of components and fully connecting them. Therefore, \\glspl{aoc} algorithms can be applied to our problem domain. Nevertheless, the pheromone trails, heuristics information, and solution construction must be carefully considered for the \\gls{moop}. Strategies for using \\gls{aoc} on multi-objective problems include aggregating the objective functions and using one ant colony with one pheromone structure or using a different colony for each objective function and having multiple pheromone structures \\parencite{Alaya2007AntProblems}.\n\n\\subsection{Bee Colony Optimization}\n\\Gls{bco} is a meta-heuristic that represents a type of swarm intelligence inspired by bees. Artificial agents are created by partially simulating the real-life behavior of bees. Such behaviors include nectar exploration, mating during flight, food foraging, waggle dancing, and division of labor. Bee colony-based optimization algorithms are mainly based on food foraging, nest site search, and mating in the bee colony \\parencite{Talbi2009Metaheuristics:Implementation}.\n\n\nThe \\gls{aoc} algorithm is based on nest site search behavior and consists of alternating forward and backward passes. Every artificial bee explores the search space during the forward pass. It applies a predefined number of moves that construct and improve the solution, thus yielding a new solution. After obtaining new partial solutions, the bees return to the nest and begin the backward pass in which all the artificial bees share information about their solutions \\parencite{Teodorovic2009BeeBCO}. The bee whose solution has the highest fitness score is selected to form the next bee population.\n\n\n\\section{Designing Algorithms for Multi-Objective Problems}\nIn the above sections, we define our optimization problem as a combinatorial multi-objective problem. Solving \\gls{moop} implies obtaining an approximation set of Pareto optimal solutions in such a way that the set fulfills the requirements of convergence to the Pareto front and uniform diversity  \\parencite{Talbi2009Metaheuristics:Implementation}. Exact methods such as branch and bound algorithms, constraint programming, and dynamic programming are used for two-criteria optimization problems. However, such methods are better suited for small-scale problems. In research, optimization problems with more than three objectives are often classified as multi-objective problems. This is due to the added difficulty of handling a higher number of objectives. Unlike many objective problems, two-objective and three-objective problems can be comprehensively visualized by graphical means, which makes it easier for decision makers to analyze and make better decisions \\parencite{Deb2013AnConstraints}. Heuristics methods are needed for this problem scale, and designing heuristics for \\gls{moop} requires additional concepts. The following sections summarize the concepts typically required for designing algorithms for \\gls{moop}.\n\n\n\\subsection{Fitness Assignments}\nThe fitness assignment measures the quality of a solution by assigning a scalar-valued fitness to a vector objective function. This procedure can be classified into scalar approaches, criterion-based approaches, dominance-based approaches, and indicator-based approaches.\n\n\\subsubsection{Scalar Approaches}\nScalar approaches typically transform the \\gls{moop} into single-objective problems. A scalar approach frequently used in designing solutions for multi-objective optimization problems consists of aggregating the objective functions into a single function using either addition, multiplication, or any combination of arithmetic operations. This approach has the advantage of simplifying the objective space such that only a single objective needs to be optimized. However, in order to avoid one function dominating another, aggregating the functions requires behavioral knowledge of each objective function \\parencite{CoelloCoello1999ATechniquesc}. The most common aggregation method is the weighted sum approach, which is defined as follows:\n\n\\begin{gather*}\n   \\Vec{f} = \\sum_{i=1}^k w_i f_i, \\ \\text{where}\\ w_i \\geq 0\\ \\text{and}\\ \\sum_{i=1}^k w_i = 1\n\\end{gather*}\n\nwhere $w_i$ are coefficients representing the objectives’ relative importance, which is usually unknown. The algorithm designer must solve the problem for different values of $w_i$ and decide on the appropriate value for $w_i$ based on their intuition. Constant multipliers $c_i$ are often introduced to further reflect the importance of each objective. This helps normalize the vector function in approximately the exact numerical values. Other popular scalar approaches found in the survey by Carlos et al. \\parencite{CoelloCoello1999ATechniquesc} use goal programming (minimize or maximize the absolute deviation from target to objectives) and $\\varepsilon$-constraint methods (considering the objectives bound by some allowable levels $\\epsilon_i$). However, transforming a \\gls{moop} into a single-objective problem is not always feasible. Ascribing a hierarchy of importance to the objectives is a crucial step in aggregating the function. In our problem domain, the objective function already represents a user preference (i.e., each objective function is mapped to a particular user preference). Ultimately, assigning a level of importance to each objective function defeats the optimization problem’s purpose because the objectives are not comparable.\n\n\\subsubsection{Criterion-Based methods}\nCriterion-based methods are commonly used in population-based meta-heuristics (e.g., \\glspl{ea} and \\gls{aoc}). They conduct the search process by treating the various objectives separately and assigning them fitness values. This procedure usually occurs in parallel or sequentially. For example, parallel approaches are used in \\gls{aoc} (P-\\gls{aoc} \\parencite{Doerner2004ParetoSelection}), where one ant colony tackles an objective. Sequential approaches search sequentially in a defined preference order; the order signifies the importance of each objective function \\parencite{Fishburn1974ExceptionalSurvey}.\n\n\\subsubsection{Dominance-Based approaches}\nDominance-based (or Pareto-based) approaches use dominance and Pareto optimality to guide the search process. In a single run, such approaches can generate a diverse set of Pareto optimal solutions and Pareto solutions in the concave portions of the convex hull of feasible objective space \\parencite{Talbi2009Metaheuristics:Implementation}. Most Pareto approaches use \\glspl{ea}. Compared to scalar methods, Pareto-based fitness assignment evaluates the quality of a solution in relation to the whole population by applying ranking methods. Ranks are scalar values obtained using dominance relation techniques. The rank assigned to a solution is considered its fitness value.\n\n\\subsection{Diversity Preservation}\\label{sec:diversitypreservation}\nInitial population selection and biased sampling during a search in population-based meta-heuristics are crucial for maintaining diversity. Diversity-preserving methods must be considered when designing meta-heuristics for \\gls{moop}; they generally penalize solutions that have high density in their neighborhoods. According to \\parencite{Emmerich2018AMethods}, diversity preservation strategies can be classified into kernel, nearest neighbor, and histogram methods.\n\n\\textit{Kernel methods} Kernel methods define the neighborhood of a solution according to a kernel function that takes the distance between solutions as an argument. The kernel function is applied to all distances. For example, fitness sharing is popularly used in \\glspl{ea} as it degrades the fitness of an individual using a sharing function $sh$. The sharing function depends on a constant $\\sigma$ and the sum of the distance between individuals in the population. $\\sigma$ represents the non-similarity threshold. Nearest neighbor methods estimate the density of a solution while taking into account the distance between a solution and its $k^{th}$ nearest neighbor. For example, \\gls{nsga}-II uses crowding distance sorting to sort solutions within a rank. A crowding distance of an individual $i$ is illustrated in Figure \\ref{fig:crowdeddistance_sorting}. The crowding distance can be pictured as a cuboid on the $i$ and its two nearest neighbors (left and right). Equation \\ref{eq:3.4a} shows the formula used to find the crowding distance for $i$ in an objective $f_k$ from $F$ objectives; it is defined as the circumference between a solution and its left and right neighbors.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=8cm]{CrowdedDistanceSorting}\n    \\caption{Crowding distance sorting in \\gls{nsga}-II}\n    \\label{fig:crowdeddistance_sorting}\n\\end{figure}\n\n\\begin{align}\n    distance(i) = distance(i) + \\frac{f_k(i+1) - f_k(i-1)}{f_k^{max} - f_k^{min}} \\qquad \\forall \\ f_k \\in F \\label{eq:3.4a} \n\\end{align}\n\nMore diversity is obtained using solutions with high crowding distances. Histogram-based diversity-preserving approaches partition the search space into several hyper-grids that define the neighborhood. The density around a solution is estimated by the number of solutions in the same box of a grid \\parencite{Talbi2009Metaheuristics:Implementation}. The technique used to measure the distance between solutions is essential for diversity preservation. Diversity in the decision space may be essential to improve the search for some problems; however, some only require diversity in the objective space.\n\n\\section{Comparative Analysis of Choice Algorithms}\nSo far in this chapter, we have extensively discussed different algorithmic approaches that are commonly used to solve combinatorial optimization problems. We have presented algorithms that are typically suited for \\glspl{moop}. Through our analysis, we can conclude that using traditional techniques such as local search, tabu search, etc., will be more difficult to implement for our \\gls{moop} because such techniques yield a single local optimum. A single-objective optimizer needs to be run multiple times when using such techniques. Additionally, good distribution (uniform diversity) is not guaranteed. Thus, a considerable amount of adaptation is required to use these approaches for our problem domain. In contrast, modern algorithms such as the \\glspl{ea}, \\gls{aoc}, and \\gls{bco} are best suited for multiple objective problems because they can return the Pareto optimal set in a single run. They can also be easily decomposed to find the optimal solution for single objectives. Hence, they do not require more effort than necessary to be implemented for our problem domain.\n\nIt is impossible to implement all algorithms considered suitable for our problem domain in this thesis. Thus, we compare \\glspl{ea} and \\gls{aoc}. These choices are based on their popularity for solving \\glspl{op}, multi-objective knapsack problems, and multi-objective problems in general.\n\n\\begin{table}[htpb]\n  \\caption[Comparison of choice algorithms]{Comparison of choice algorithms.}\\label{tab:comparison_alg}\n  \\centering\n  \\begin{tabular}{|c| c c |}\n    \\toprule\n       &Evolutionary Algorithm &Ant-Colony \\\\\n    \\midrule\n      Computational time & \\checkmark &  \\\\ \\hline\n      Applicability to problem domain & \\checkmark & \\\\\\hline\n      Approximate Pareto front & \\checkmark & \\checkmark \\\\\\hline\n      Diversity Preserving & \\checkmark & \\checkmark \\\\\\hline\n      Applicable to large-sized objectives & & \\checkmark \\\\\\hline\n      Easier to Implement & \\checkmark & \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{table}\n\nIn table \\ref{tab:comparison_alg}, \\glspl{ea} and \\glspl{aoc} are compared using the desired algorithmic properties listed in Section \\ref{sec:alg_approaches} of this chapter. The capabilities of widely used \\gls{ea} variants like \\gls{nsga}-II, \\gls{nsga}-III, \\gls{spea}2 were also taken into account. These scores are based on evaluation results from \\parencite{Lust2012TheApproach, Florios2010SolvingAlgorithms, Alaya2007AntProblems}. as multi-objective knapsack problems were used for evaluation in these studies. A checkmark is awarded when the algorithm has an advantage over the other in that criterion. For example, in comparison to \\glspl{aoc}, \\glspl{ea} have demonstrated faster computational time in solving multi-objective knapsack problems. However, it is unknown which of the two algorithms for approximating to the Pareto front works best. \\gls{aoc} is specifically designed to solve path-search problems. A graph representation of the knapsack model must be constructed, which increases the implementation complexity of the \\gls{aoc}. Unlike \\gls{aoc}, a number of \\gls{ea} variants can be used directly for our optimization problem without adaptation. Moreover, there are several frameworks focusing on implementing \\glspl{ea} that significantly decrease the time needed for implementation.\\\\\nWe can conclude that an \\gls{ea} is the best algorithmic approach for our study.\n\n\n\n \n\n\n\n ", "meta": {"hexsha": "862ea60066ea5432465b8f9164527a102dd82f59", "size": 44671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Item Combination For DestiRec/chapters/03_solution_development.tex", "max_stars_repo_name": "idaShobs/destirec-composite", "max_stars_repo_head_hexsha": "3cfc1ee0d91f7454fd0969092cbb70491b9c35d2", "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": "Item Combination For DestiRec/chapters/03_solution_development.tex", "max_issues_repo_name": "idaShobs/destirec-composite", "max_issues_repo_head_hexsha": "3cfc1ee0d91f7454fd0969092cbb70491b9c35d2", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Item Combination For DestiRec/chapters/03_solution_development.tex", "max_forks_repo_name": "idaShobs/destirec-composite", "max_forks_repo_head_hexsha": "3cfc1ee0d91f7454fd0969092cbb70491b9c35d2", "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": 137.8734567901, "max_line_length": 1502, "alphanum_fraction": 0.7837747084, "num_tokens": 10308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6507219031702194}}
{"text": "\\lab{Pseudorandom Number Generators}{Pseudorandom Number Generators}\n\\label{lab:PRNG}\n\n\\objective{Learn about the strengths and weaknesses of a few pseudorandom number generators}\n\n\\section*{Random Numbers}\nLotteries, most board games, and statistics need random numbers.\nIn real life, we roll dice, take balls out of a bag, or spin a wheel.\nComputers are, by nature, deterministic, meaning that they do exactly what they are told.\nBecause of this, random number generation on a computer can be difficult.\nWe can have a device measure a random process and use the data to generate random numbers, \nbut such sampling is often too slow and too expensive for practical use.\nPseudorandom number generators (PRNGs) are a common solution to this problem.\nThe numbers are not truly random, but they are based on a complex formula that makes them look ``random.\"\nFor convenient use, these generators must also run quickly.\nThe goal is to have something that is fast and looks random.\n\nThere are many different algorithms for developing pseudorandom numbers.\nRobert R. Coveyou titled an article ``The generation of random numbers is too important to be left to chance.\"\nThere has been much study about different PRNGs.\nThis lab will cover Linear Congruential Generators.\n\n\\section*{Linear Congruential Generators}\nLinear Congruential Generators (LCGs) are one of the oldest ways of generating random numbers.\nThe generator is defined by the recurrence relation:\n$X_{n+1}=(a*X_n + c)$ mod $m$ where\n\n\\begin{itemize}\n\\item $X$ is a sequence of pseudorandom values\n\\item $m$ is the modulus, with $m>0$\n\\item $a$ is the multiplier, with $0<a<m$\n\\item $c$ is the increment, with $0\\leq c<m$\n\\item $X_0$ is the seed, with $0\\leq X_0 <m$\n\\end{itemize}\n\nThe $a$, $m$, $c$, and $X_n$ are integer constants.\n\n\\begin{problem}\\label{LCG1}\nWrite an LCG that produces an array of pseudorandom numbers between $0.0$ and $1.0$.\nDefine your LCG to take the size of the array as an argument, and let $a$, $c$, $m$, and $seed$ be optional arguments.\nFor the purpose of this example, let $a=1103515245$, $c=12345$, $m=2^{31}-1$, and $seed=4329$ be the default values.\n\\end{problem}\n\n\\begin{problem}\nWrite an LCG that produces an array of pseudorandom numbers of integers between two input arguments.\nDo it by calling your algorithm from problem \\ref{LCG1} and multiplying it by the values and casting the array as an integer using \\li{.astype()}.\nLet the arguments be the size of the array and the two integers.\nLet $a$, $c$, $m$, and $seed$ continue to be optional arguments.\n\\end{problem}\n\nThis algorithm is used as the default random number generator in Java and C++, and is still used in a wide variety of situations.\nThe length over which your random number generator repeats is called the period.\nThe period is at most $m$, but it may be shorter based on the values of $a$ and $c$.\n\n\\begin{figure}\n\\includegraphics[width=.4\\textwidth]{PRNG1.png}\n\\caption{\nThe bitmap with $a=3$, $c=2$, $m=2^{16}$.\nThere is a clear pattern in the random numbers.}\n\\end{figure}\n\nOne easy way to ``see\" if your generator is random is to look at a bitmap of the output.\nIn python, you will need to import matplotlib and use \\li{.imshow()} to see a bitmap of the array produced by your LCG.\nResize your output to be $512 \\times 512$ (you will need $512^2$ random numbers in your array).\n\n\n\n\\begin{problem}\nFor what values of $a$, $c$, and $m$ does your LCG have a visible pattern?\n\nLook at the bitmap for the output of \\li{np.random.rand(512, 512)}.\nCan you see any patterns?\n\\end{problem}\n\n\n \n\\begin{comment}\nAccording to the Hull-Dobell Theorem (TO DO: find a source), a LCG will have a full period if and only if, \n1. $c$ and $m$ are relatively prime,\n2. $a-1$ is divisible by all prime factors of $m$,\n3. $a-1$ is a multiple of 4 if $m$ is a multiple of 4\n\n\\begin{problem}\nTest values of $a$,$c$, and $m$ that fit these requirements. \n\\end{problem}\n\\end{comment}\n\n\n\n\n\\begin{comment}\n\\section*{Mersenne Twister}\n(TO DO: decide how much of  this we want to keep) All numbers can be represented in bits as a base two number.\nComputers are optimized to work with numbers in that manner.\nThe operators XOR, OR, and AND work on the bit representation of two numbers.\n\nAND - if both numbers have a 1 in the ith place then the ith place is 1.\nOtherwise the ith place is 0.\n\nOR - if one or both numbers have a 1 in the ith place then the ith place is 1.\nOtherwise the ith place is 0.\n\nXOR - if only one of the two numbers has a 1 in the ith place then the ith place is 1.\nIf both or neither of the numbers has a 1 in the ith place, the ith place is 0.\n\nIn addition you can shift the bitwise number over a number of values.\nFor example, shifting 10100 to the right by one yields 1010 and shifting it to the left by one yields 101000.\nThis is really just division and multiplication by 2.\nThis can be done by $\\ll$ and $\\gg$ in python. \n\n\nThe Mersenne twister PRNG does a series of bitwise operations to generate random numbers.\nThe Random class in python uses the Mersenne twister algorithm. \n\n\\begin{problem}\nLook at the bitmap for the of output of \\li{np.random.rand(512, 512)}.\nCan you see any patterns?\n\\end{problem}\n\n\\section*{Randomness Tests}\nMany statistical tests have been devised to measure the quality of a random number generator.\nOne of these tests is the overlapping permutations test.\nThis test involves taking an arbitrarily large collection of sequences of five consecutive random numbers from the generator and finding the probability that one of the 120 possible permutated orderings occurs.\nIn a good PRNG, the 120 orderings should occur with equal probability.\n\nTo simplify this process, instead of considering a specific sequence of five consecutive random numbers, consider the argsort of this sequence.\nFor example: instead of considering how often the sequence $[103, 75, 4, 57, 9]$, or any permutation thereof, shows up, consider argsort([103, 75, 4, 57, 9])=[2, 4, 3, 1, 0]$ (Remember, argsort gives index of increasing values in the array).\nIn this sense, we can now look at the frequency with which the permutations of 0, 1, 2, 3, and 4 show up under argsort.\n\nIt is convenient to use the $plt.bar()$ command under $matplotlib$ to generate a Histogram of the number of times each permutation shows up in the collection of sequences.\n\n\\begin{problem}\nUse the overlapping permutations test to see how random python's random number generator is compared to the LCG you wrote in problem 1.\nCreate a bar graph with 120 bins, one for each ordering, to view graphically the difference. (Hint: Consider using a dictionary to store all possible orderings)\n\\end{problem}\n\n\\end{comment}\n\n\\section*{Blackjack}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Blackjack_game_1.jpg}\n\\caption{Initial Round of a Blackjack game.}\n\\end{figure}\n\nBlackjack is a card game that involves the use of randomness.\nThe game is simple.\nThe dealer deals the player and himself each two cards.\nHe flips over his first card so that the player can see it.\nThe player has to choose to take another card (\"hit\") or not (\"stand\").\nIf 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.\nFace cards are worth 10 points.\nAces can count either as 11 or 1.\nThe value of all other cards are equal to the 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's value goes above 21 he automatically loses.\nIf his value is 21 or below and the dealer has above 21 then the player wins.\nIf they both have 21 or under then the player with the hand of highest value wins.\nIf both hands have the same value, the game is a tie.\n\n\\section*{Shuffling Algorithms}\nOne use of PRNGs is to shuffle cards.\nThe main goal of these algorithms is to make the card order be random--so that no single player has an advantage based on order.\nOften, as strange as it may seem, online gambling sites will post their shuffling algorithms online; the only things they do not post are their seed values.\nOften the time in milliseconds from midnight is used as the seed value.\n\nJohn von Neumann said, ``Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.\"\nAs seen in the first part of this lab, weak PRNGs are periodic and are predictable once a few outputs are known.\nNow we will have you break Blackjack based on a weak PRNG.\n\n\\section*{Cracking Blackjack}\nFor these next problems you will need three files that are provided with this lab: BlackHard.py, BlackEasy.py, and bjCommon.py.\nBlackHard.py and BlackEasy.py are programs that run games of Blackjack that use an LCG to shuffle the cards.\nThey generate 52 random numbers and then use the natural ordering of those numbers as the ordering of the cards.\nThe parameters for BlackEasy.py are $a=2521$, $c=13$, $m=2^{16}$.\nFor BlackHard.py they are $a=25214903917$, $c=11$, $m=2^{48}$.\n\n\\begin{warn}\nBoth BlackEasy.py and BlackHard.py use functions that are incompatible with ipython.\nTo run them, use \\li{python <<filename>><<numberofgames>>} in the command line.\n\\end{warn}\n\nBlackEasy.py uses a seed randomly generated between 0 and 10000000.\nThe seed for BlackHard.py is based on the time, using \\li{ (int)(time.time())}, which is the number of seconds from the start of the epoch cast as an integer.\n(This can be found in the time package).\nBoth programs will make a list of length \\li{<<numberofgames>>}, where each element in the list is a shuffling of the deck.\nDuring each round, the program will choose the next deck in your list generated.\nCards are popped off the deck one at a time: first one to the player, second one to the dealer, third one to the player, and one last one to the dealer. \n\nInitially three cards are visible (the last of the dealer's is face down) so our algorithms will deal with these first three cards, and the ordering (player, dealer, player) will be very important. \nAfter the first four cards are down the next cards are popped off in the order that they appear. \n\nbjCommon.py contains several functions to help you with the game's mechanics.\nCards have a string representation ( '6diamond' for 6 of diamonds, 'Kclub' for king of clubs, 'Aheart' for ace of hearts, and so on) and a number representation that determines their natural ordering. \nbjCommon.py has functions for generating the list of cards and converting arrays to and from the string and integer representation of cards. \nParticularly useful is the function \\li{shuffle}, which when given the number of games, $g$, the LCG parameters, and a seed value, returns the first $g$ decks (or games) in integer representation as $g$ arrays of 52 integers.\n\nYour goal will be to do a sweep of seed values and cross check the decks produced by \\li{shuffle} against the first three cards from several games, then be able to determine the order of cards for future rounds.\n\n\n\\begin{problem}\\label{sweeps}\n\nCreate a function, \\li{getSweepsEasy(games,n)}, which has as its parameters the number of games you selected to play in BlackEasy.py and a seed value.\nThe function needs to return an array of size $n\\times games \\times 52$, representing all possible seed values 0 through $n$ in the first dimension, the different shufflings that occur based on the number of games played in the second dimension, and the ordering of the 52 cards for each shuffle in the third dimension.\n(Be sure to look at \\li{bjCommon.shuffle} to help get the needed results)\n\nWhat seed value $n$ would you use to make sure to cover all possible shufflings?\n(Look at the parameters of the LCG in BlackEasy.py]).\n\n\\end{problem}\n\nFrom problem \\ref{sweeps}, using the right value for $n$ will get you the list of all possible initial shuffles, as well as the appropriate number of future hands depending on the games parameter.\nOnce we have the possible shufflings, we want a convenient way to match the output from BlackEasy.py with the output from problem \\ref{sweeps}.\nThe function \\li{bjCommon.findSeedMatch} provides us the means of comparing these two outputs.\nIt takes as parameters sweeps, game, and cardNames3; sweeps is the output from problem \\ref{sweeps} (an $n \\times games \\times 52$ array), game is the round number, and cardNames3 is a 3-tuple of the names of the first three cards dealt out (using the naming notation mentioned above).\n\n\\begin{problem}\n\nCreate a function \\li{crackBlackJack(sweeps, cardTuples)} to crack the shuffling algorithm of BlackEasy.py.\nThe parameter sweeps represents the output from problem \\ref{sweeps}.\nThe parameter cardTuples is a list of 3-tuples from the 1st, 2nd, etc. rounds played.\nIt should return a subset of shuffles from sweeps whose shuffles match in each round to each 3-tuple in cardTuples.\n\nBe sure to make use of \\li{bjCommon.findSeedMatch} and \\li{bjCommon.convertToName} to see the names associated to the orderings of cards.\n\n\\end{problem}\n\nKeep in mind the key difference between BlackEasy.py and BlackHard.py is the seed that is used and the value $m$ which the shuffling algorithm mods out by for each shuffle.\nBlackEasy.py has a small selection of seeds to choose from, while BlackHard.py uses a seed based on time, which can get pretty big.\nWhile in BlackEasy.py you could easily find all possible seed values and the corresponding shuffles, in BlackHard.py you will need to know the approximate time you initiated the game.\nThis can be done using the \\li{time.time()} function shortly after initializing BlackHard.py in python.\n\n\\begin{problem}\n\nCreate a function, \\li{getSweepsHard(games, time, approx=120)}, which returns all possible shuffles for a range of seed values.\nThe parameter games is how many rounds you want to play (corresponding to different shuffles of a given seed value).\nThe time parameter is the approximate time you started the round of BlackHard.py.\nThe approx parameter will give a range of seed values (120 seconds before and after the approximate time you initiated the game).\nIt should return a $(2*approx) \\times games \\times 52$ array of possible shuffles, similar to problem \\ref{sweeps}.\n\nYou should be able to run \\li{crackBlackJack} using this output to help determine future rounds of BlackHard.py.\n\n\\end{problem}\n", "meta": {"hexsha": "e44b3def575b31ba7fb7659011b979e4c8188297", "size": 14323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/PRNG/PRNG.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/PRNG/PRNG.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/PRNG/PRNG.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.987854251, "max_line_length": 319, "alphanum_fraction": 0.7697409761, "num_tokens": 3543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.8976952866333484, "lm_q1q2_score": 0.6507126303445492}}
{"text": "\\subsection{Luminosity and pile-up}\n\n\\textbf{Luminosity}\n\nIn beam–beam collisions, the event rate for a process is written as~\\cite{Evans_2008}:\n\\begin{equation}\n\tN = \\mathcal{L} \\sigma\n\\end{equation}\nwhere $\\sigma$ is the cross section of the process, and $\\mathcal{L}$ is the luminosity.\nTo study rare events, $\\mathcal{L}$ must be as high as possible.\nThe luminosity only depends on the beam parameters as:\n\\begin{equation} \\label{eq:lumi}\n\t\\mathcal{L} = \\frac{ N_{b}^{2} n f_{r} \\gamma}{4\\pi \\epsilon_{n} \\beta^{*}}\n\\end{equation}\nin which $N_{b}$ represents the number of particles per bunch, $n$ denotes the number of bunches per beam,\n$f_{r}$ is the revolution frequency, and $\\gamma$ is relativistic $\\gamma$ factor, \n$\\epsilon_{n}$ is the normalized transverse emittance and $\\beta^{*}$ denotes the $\\beta$ function at the collision point.\nTo reduce the beam-beam interaction effects, the bunches must have a crossing angle,\nwhich produces a geometrical luminosity reduction factor $F$:\n\\begin{equation}\n\tF = 1 / \\sqrt{1 + \\left( \\frac{\\theta_{c}\\sigma_{Z}}{2\\sigma^{*}} \\right) }\n\\end{equation}\nwhere $\\theta_{c}$ denotes the crossing angle at the interaction point, $\\sigma_{Z}$ is the root mean square (RMS) bunch length\nand $\\sigma^{*}$ is the transverse RMS beam size at crossing point.\n\nThe luminosity expressed in Eq.~\\ref{eq:lumi} is normally the instantaneous luminosity.\nIn fact the running conditions usually vary with time, so the luminosity can change as well.\nTo take into account the time dependence, integrated luminosity is invited, by integraling the instantaneous luminosity over time:\n\\begin{equation}\n\tL = \\int \\mathcal{L}(t) dt\n\\end{equation}\nThe unit of integrated luminosity we commonly use is $b^{-1}$ that satisfying $1 b^{-1} = 10^{24} cm^{-2}$.\nFigure~\\ref{fig:lumi_vs_time} shows integrated luminosity as a function of time delivered to ATLAS (green), \nrecorded by ATLAS (yellow), and certified to be good quality data (blue) during run-2 pp collisions.\nFor most physics analysis, the data with good quality (require to satisfy \\textit{Good Run List}) is used.\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{figures/Detector/intlumivstimeRun2DQall.pdf}\n  \\caption{Integrated luminosity vs delivered month from 2015 to 2018 in ATLAS experiment.}\n  \\label{fig:lumi_vs_time}\n\\end{figure}\n\n\\textbf{Pile-up}\n\nIn collisions, multiple interactions can happen in one single bunch crossing, which is called ``\\textit{pile-up}\".\nThe variable $\\left< \\mu \\right>$, representing the average number of interactions per bunch crossing that used to describe pile-up effect, is defined as:\n\\begin{equation}\n    \\left< \\mu \\right> = \\frac{\\mathcal{L}_{tot}\\sigma}{f_{r}n_{bunch}}\n\\end{equation}\nwhere $\\mathcal{L}_{tot}$ is the instantaneous luminosity, $\\sigma$ denotes the inelastic cross section,\n$f_{r}$ represents the LHC revolution frequency and $n_{bunch}$ is the number of colliding bunches.\nUsually, with increasing luminosity, the pile-up becomes more significant.\nFigure~\\ref{fig:run2_mu} shows the luminosity-weighted distribution of the mean number of interactions per crossing\nfor pp collision data from 2015 to 2018 (full run-2), the challenge of pile-up increased in each year.\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{figures/Detector/mu_2015_2018.pdf}\n  \\caption{Number of interactions per crossing weighted bt luminosity from 2015 to 2018 in ATLAS experiment.}\n  \\label{fig:run2_mu}\n\\end{figure}\n", "meta": {"hexsha": "944883fcde0d2fe3cdcfc0f8a107c08a62c4cad8", "size": 3496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Detector/lumi.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/Detector/lumi.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/Detector/lumi.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": 57.3114754098, "max_line_length": 154, "alphanum_fraction": 0.7542906178, "num_tokens": 981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6507126276093839}}
{"text": "\\Lecture{Jayalal Sarma}{Nov 11, 2020}{29}{Applying Cycle Index in Polya's Theorem}{Bhupathi Narasimha Rao}{$\\alpha$}{JS}\n\\section{Recall the definitions of Type and Cycle Index Polynomial}\nLet $G$ be the set of some permutations of $\\Omega$ , every $g \\in G$ can be decomposed into a collection of disjoint cycles .\\\\\n\\textbf{Example 1:-} Consider $g=\\{2,3,1,5,4\\}$ which is a permutation on set $\\{1,2,3,4,5\\}$ . So , the permutation $g$ can be written as $(1~2~3)(4~5)$ .\\\\\n\\textbf{Example 2:-} Identity on set $[n]$ can be written as $g=(1)(2)(3)\\dots(n)$ which is $n$-cycles of length $1$.\\\\\\\\\n\\textbf{Type of a permutation :-} A permutation $\\pi$ is said to be of type $(b_1,b_2,\\dots,b_m)$ if \n$$b_i = \\textrm{\\# of $i$-length cycles in the cyclic representation of $\\pi$}$$\n\\textbf{Example 1:-} Type of an identity permutation is $(n,0,\\dots,0)$ .\\\\\n\\textbf{Example 2:-} Type of the permutation $g=(1~2~3)(4~5)$ is $(0,1,1,0,0)$ .\\\\\\\\\n\\textbf{Cycle index Polynomial :-}As discussed in previous lectures , a monomial is associated corresponding to every type as follows :\n$$(b_1,b_2,\\dots,b_m)\\longleftrightarrow x_1^{b_1}x_2^{b_2}\\dots x_m^{b_m}$$\nAnd the cycle index polynomial of $G$ is defined as:\n$$P_G(x_1,x_2,\\dots,x_n)=\\frac{1}{|G|}\\sum_{g\\in G}(x_1^{b_1}x_2^{b_2}\\dots x_n^{b_n})~~~\\textrm{where $(b_1,b_1,\\dots,b_n)$ is the type of $g$}$$\n\\textbf{Example 1:-} Let $G=\\{e,(1~2),(3~4),(1~2)(3~4)\\}\\leq S_4$ , then \n$$P_G(x_1,x_2,x_3,x_4) = \\frac{1}{4}\\left(x_1^{4}+x_1^{2}x_2+x_1^{2}x_2+x_2^{2}\\right)$$\n\\textbf{Example 2:-} Let $G=\\{e,(1~2),(1~3),(2~3),(1~2~3),(1~3~2)\\}=S_3$ , then \n$$P_G(x_1,x_2,x_3) = \\frac{1}{6}\\left(x_1^{3}+x_{1}x_{2}+x_{1}x_{2}+x_{1}x_{2}+x_3+x_3\\right)=\\frac{1}{6}\\left(x_1^{3}+3x_{1}x_{2}+2x_3\\right)$$\n\\textbf{Why are we doing this :} The connection to Polya's Theorem will be found by the end of this lecture .\n\\section{Polya's Theorem (Simpler version)}\n\\begin{theorem}Let $G$ be the group of symmetry acting on $\\Omega$ (set of different coloring of the underlying object) , then \n$$\\textrm{\\# of distinct color patterns with $k$-colrs } = P_G(k,k,\\dots,k)$$\n\\begin{proof}\nLet the Domain be of size $m$ and we have $k$ colors , then  $|\\Omega|=k^m$ . Using Burnsides's Lemma ,  \n\\begin{align*}\n    \\textrm{\\# of distinct colorings} &= \\textrm{\\# of different orbits of G acting on} \\Omega\\\\\n    &= \\frac{1}{|G|}\\sum_{g\\in G} |fix(G)|\n\\end{align*}\nWe have to compute $|fix(g)|$ for $g\\in G$ . For example , the cyclic structure of $g$ be $(1~2)(3~4)$ , the coloring should be such that the domain under the permutation looks the same . So , the corners $1,2$ should have same color and $3,4$ should have same color . So , total number of colorings such that the domain looks the same under the permutation $g = k^2$ . Hence all the corners in one cycle should get the same color . So , consider the type of some permutation $g=(b_1,b_2,\\dots,b_m)$ , then\n\\begin{align*}\n    &\\textrm{$b_1$ cycle of length $1$ can have $k^{b_1}$ possible coloring}\\\\\n    &\\textrm{$b_2$ cycle of length $2$ can have $k^{b_2}$ possible coloring}\\\\\n    &\\dots\\\\\n    &\\dots\\\\\n    &\\textrm{$b_m$ cycle of length $m$ can have $k^{b_m}$ possible coloring}\n\\end{align*}\nTherefore , \\# of colors fixed by $g=|fix(g)|=k_{b_1}*k^{b_2}*\\dots*k^{b_m} = x_1^{b_1}*x_2^{b_2}*\\dots*x_m^{b_m} ~~~\\\\\\textrm{where } x_i=k~\\forall i\\in [k]$\n\nHence , \\# of distinct color patterns with $k$-colors is \n$$\\frac{1}{|G|}\\sum_{g\\in G}\\left(k^{b_1}*k^{b_2}*\\dots*k^{b_m}\\right)= P_G(k,k,\\dots,k)$$\n\\end{proof}\n\\end{theorem}\n\\section{Examples}\n\\textbf{Example 1:-} Coloring necklace with 3 regular beads with black and white colors . Symmetries are rotation with respect to the axis passing through the center and rotation with respect to the axis passing through one vertex and center of the opposite edge . Hence ,   $$G=\\{e,R_{120},R_{240},F_{12},F_{23},F_{31}\\}$$ and cyclic representations are $\\{(1)(2)(3),(1~2~3),(1~3~2),(1~2),(2~3),(3~1)\\}=S_3$ . Cyclic index polynomial corresponding to $G$ is:\n$$P_G(x_1,x_2,x_3) = \\frac{1}{6}\\left(x_1^3+3x_1x_2+2x_3\\right)$$\nHence \\# of different colorings with $2$ colors $=\\frac{1}{6}\\left(2^3+3*2^2+2*2\\right) = 4$\\\\\n\\textbf{Example 2:-} Consider cube coloring on faces and the symmetries group $G$ defined previously as :\n\n\n\\begin{tabular}{|l|l|}\n    \\hline\n\\textbf{Permutation} & \\textbf{Corresponding Monomial} \\\\\\hline\nIdentity $(e)$ & $x_1^6$\\\\\n$180^0$ rotation wrt axis through centers of opposite faces ($3$ of them) &  $3x_1^{2}x_2^{2}$\\\\\n$180^0$ rotation wrt axis through centers of opposite edges ($6$ of them) &  $6x_2^3$\\\\\n$90^0$ rotation wrt axis through centers of opposite faces ($3$ of them) &  $3x_1^2x_4$\\\\\n $270^0$ rotation wrt axis through centers of opposite faces ($3$ of them) & $3x_1^2x_4$\\\\\n $120^0$ rotation wrt axis thorough center and opposite corners ($4$ of them) & $4x_3^2$ \\\\\n $240^0$ rotation wrt axis through center and opposite corners ($4$ of them)  &  $4x_3^2$\\\\ \\hline\n    \\end{tabular}\n    \n    \nHence cyclic index polynomial corresponding to above symmetries is:\n$$P_G(x_1,x_2,x_3,x_4,x_5,x_6)=\\frac{1}{24}\\left(x_1^6+3x_1^2x_2^2+6x_2^3+3x_1^2x_4+3x_1^2x_4+4x_3^2+4x_3^2\\right)$$\n$$\\implies P_G(x_1,x_2,x_3,x_4,x_5,x_6)=\\frac{1}{24}\\left(x_1^6+6x_1^2x_4+3x_1^2x_2^2+8x_3^2+6x_2^3\\right)$$\n\\textit{Question:-} If the coloring is done on the corners rather than faces with same $G$, does the polynomial change ?\n\\\\\n\\textbf{Example 3:-} Square Problem discussed in previous lectures , $$G=\\{e,R_{90},R_{180},R_{270},H,V,D,D^{\\prime}\\}$$ and corresponding cyclic representations are $$\\{(1)(2)(3)(4),(1~2~3~4),(1~3)(2~4),(1~4~3~2),(1~4)(2~3),(1~2)(3~4),(1~3),(2~4)\\} {\\ensuremath <} S_4$$\nThere is some connection between $(1~2~3~4)$ and $(1~3)(2~4)$ . If the permutation $(1~2~3~4)$ is applied twice to the domain (square) , we get the permutation $(1~3)(2~4)$ . That is $(1~2~3~4)$ composed with itself gives $(1~3)(2~4)$ . $(1~3)(2~4)$ composed with $(1~2~3~4)$ gives $(1~4~3~2)$ .\n\nHence the set $\\{e,R_{90},R_{180},R_{270}\\}$ forms a subgroup . Suppose the permutation $(1~2~3~4)$ be $g$ , then corresponding permutations are $\\{e,g,g^2,g^3\\}$ ($g^4$ is an identity) \\\\\n\nSuppose we have a group of symmetry as (considering $n$ to be even): $$G=\\{e,g,g^2,g^3,\\dots,g^k\\}=\\{e,(1~2~3\\dots~n),(1~3~5~\\dots~n-1)(2~4~4~\\dots~n),\\dots\\dots\\}~~~\\textrm{with $g^{k+1}$ as identity}$$\nGroups of type $G$ are called as cyclic groups . The monomials corresponding to each permutations are as follows:\\\\\n\\begin{tabular}{|l|l|}\n    \\hline\n\\textbf{Permutation} & \\textbf{Corresponding Monomial} \\\\\\hline\n$e$ & $x_1^n$\\\\\n$g$ & $x_n$\\\\\n$g^2$ & $x_{\\frac{n}{2}}^2$\\\\\n$g^3$ & $x_{\\frac{n}{4}}^4$\\\\\n\\dots & \\dots\\\\ \\hline\n    \\end{tabular}\\\\\nSo , the cyclic index polynomial corresponding to $G$ can be written as:\n$$P_G(x_1,x_2,\\dots,x_n)=\\frac{1}{n}\\sum_{d\\mid n}\\phi(\\frac{n}{d})x_{\\frac{n}{d}}^d$$\nwhere $\\phi(.)$ is the Euler's function . $\\phi(n)$ = \\# of positive integers up to $n$ that are relatively prime to $n$ . If $n$ is odd ,\n$$P_G(x_1,x_2,\\dots,x_n) = \\frac{1}{2n}\\sum_{d\\mid n}x_{\\frac{n}{d}}^d + \\frac{1}{2}x_1x_2^{\\frac{n-1}{2}}$$\n\\section{Dihedral Group}\nFor the permutations $\\sigma=(1~2~\\dots~n)$ and $\\pi=(2~n)(3~n-1)$ , the group defined as:\n$$D_n = \\{e,\\sigma,\\sigma^2,\\dots,\\sigma^{n-1},\\pi\\sigma,\\pi\\sigma^2,\\dots,\\pi\\sigma^{n-1}\\}$$\nare called Dihedral groups . Here $D_n$ is a Dihedral group .\\\\ \n\\textbf{Example 1:-}\nConsider permutation on a square $\\sigma = (1~2~3~4)$ and $\\pi=(2~4)(3~3)=(2~4)(3)(1)$ , then \n\\begin{align*}\n    \\pi\\sigma &= (2~4)(3)(1)(1~2~3~4)\\\\\n    &= (2~1)(3~4)\\\\\n    &= V\n\\end{align*}\n\\textbf{Observation:-}$|D_3|=6=|S_3|$ and $|D_4|=8\\le|S_4|$\n\n\\section{Polya's Theorem (General Version)}\n\\textbf{Motivating Question:- }How many in-equivalent colorings are there using $3$ black and $1$ white ? \n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.6\\linewidth]{images/Set-G.jpeg}\n    \\caption{Symmetries on square}\n\\end{figure}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.6\\linewidth]{images/Square-colorings-black-white.png}\n    \\caption{All possible coloring on square with black and white}\n\\end{figure}\n\n\\textbf{AIM :-} To write a polynomial $Q(b,w)$ such that coefficient of $b^2w^2=$ \\# of inequivalent colorings with $2$ Black and $2$ White colors . Similarly , coefficient fo $b^3w=$\\# of inequivalent colorings with $3$ Black and $1$ White colors .\n\n\\qquad Consider the identity permutation $e$ , no.of colorings fixed by $e$ considering $2$ colors = $16$ . And no.of colorings fixed by $e$ considering $3$ Black and $1$ White = $4$ (from the above fig.)\nIf we write this down for the permutations fixed by $e$ , the expression will be as :\n$$b^4+4b^3w+4bw^3+6b^2w^2+w^4=(b+w)^4$$\nLet us classify elements of $\\Omega=\\{C_1,C_2,\\dots,C_{16}\\}$ into their corresponding coloring structures . The classification will be as follows :\n\\begin{align*}\n    b^4 &\\longleftrightarrow T_1=\\{C_1\\}\\\\\n    b^3w &\\longleftrightarrow T_2=\\{C_2,C_3,C_4,C_5\\}\\\\\n    b^2w^2 &\\longleftrightarrow T_3=\\{C_6,C_7,C_8,C_9,C_{10},C_{11}\\}\\\\\n    bw^3 &\\longleftrightarrow T_4=\\{C_{12},C_{13},C_{14},C_{15}\\}\\\\\n    w^4 &\\longleftrightarrow T_5=\\{C_{16}\\}\n\\end{align*}\nSuppose we want to know how many inequivalent colorings are possible with $3$ Black and $1$ White on a square when group $G$ is applied , then it is enough to apply the group $G$ on $T_2$ and count the inequivalent colorings . So , now we need to understand how many inequivalent colorings are there in each $T_i$ .\n\n\\qquad $G$ acting on $T_i$ is well-defined . It is because when a rotation/flip is applied on a square , the number of colors or number of vertices is not changed . The image will be one of the elements of $T_i$ itself . Hence , it is well-defined . So , for finding number of inequivalent colorings of a specific structure (like $3$ Black and $1$ White) , it is enough to apply $G$ on corresponding $T_i$ ($T_2$ if $3$ Black and $1$ White) and apply Burnside's lemma (\\textit{i.e.,} compute $|fix(g)| \\forall g\\in G$) .\\\\\\\\\n\\textbf{Example 1:-} Find the number of inequivalent colorings using $3$ Black and $1$ White when $G=\\{e,R_{90},R_{180},R_{270},H,V,D,D^{\\prime}\\}$ applied on $\\Omega$ . \\\\\n\\textbf{Solution :-} Consider action of $G$ on $T_2=\\{C_2,C_3,C_4,C_5\\}$ , \n\\begin{align*}\n    \\textrm{\\# of inequivalent colorings }&= \\frac{1}{|G|}\\sum_{g\\in G}|fix(g)|\\\\\n    &= \\frac{1}{8}\\left(|fix(e)|+|fix(D)|+|fix(D^{\\prime})|\\right)~~~\\textrm{Action of other $g$'s gives $|fix(g)|=0$}\\\\\n    &= \\frac{1}{8}\\left(4+2+2\\right)\\\\\n    &= 1\n\\end{align*}\\\\\n\\textbf{Example 2:-} Find the number of inequivalent colorings using $2$ Black and $2$ White when $G=\\{e,R_{90},R_{180},R_{270},H,V,D,D^{\\prime}\\}$ applied on $\\Omega$ . \\\\\n\\textbf{Solution :-} Consider action of $G$ on $T_3=\\{C_6,C_7,C_8,C_9,C_{10},C_{11}\\}$ , \n\\begin{align*}\n    \\textrm{\\# of inequivalent colorings }&= \\frac{1}{|G|}\\sum_{g\\in G}|fix(g)|\\\\\n    &= \\frac{1}{8}\\left(|fix(e)|+|fix(R_{180})|+|fix(H)|+|fix(V)|+|fix(D)|+|fix(D^{\\prime})|\\right)\\\\\n    &= \\frac{1}{8}\\left(6+2+2+2+2+2\\right)\\\\\n    &= 2\n\\end{align*}\\\\\n\\textbf{Example 3:-} Given a permutation $g$ with cycle structure $(1~2)(3)(4)$ . How many inequivalent colorings are possible with different combinations of Black and White colors ?\\\\\n\\textbf{Solution :-} We have to count number of colorings that are fixed by $g$ . So , $1,2$ should have same color , $3,4$ can have any color . Hence , the expression $(b^2+w^2)(b+w)(b+w)$ represents the possible colorings where coefficient of each term correspond to the number of colorings which are inequivalent with that color structure . \n$$(b^2+w^2)(b+w)(b+w) = b^4+2b^3w+2b^2w^2+2bw^3+w^4$$\nHence , $g$ fixes square with $4$ corners coloured Black , $4$ corners colored White , $2$ squares colored with $3$ Black and $1$ White , $2$ squares colored with $2$ Black and $2$ White , $2$ squares colored with $1$ Black and $3$ White .\\\\\n\\textbf{Example 4:-} Given permutation $g$ with cycle structure $(1~2)(3)(4)(5~6~7)$ , the colorings which are fixed by $g$ is given by $(b^2+w^2)(b+w)(b+w)(b^3+w^3)$ .\\\\\n\\section{Polya's Theorem}\n\\begin{theorem}\nIf the colors $\\alpha_1,\\alpha_2,\\dots,\\alpha_k$ are used , then \n$$\\textrm{\\# of inequivalent colorings expressed as generating function } = P_G(\\sum_{i=1}^{k}\\alpha_i,\\sum_{i=1}^{k}\\alpha_i^2,\\dots)$$\n\\end{theorem}\n\n\\textbf{Example 1:-} Consider the necklace with $3$-half beads colored with Black and White . The group of symmetry is $G=\\{e,R_{120},R_{240}\\}$ . Then generating function is :\n$$P_G(x_1,x_2,x_3) = \\frac{1}{3}\\left(x_1^3+2x_3\\right)$$\nSubstitute $x_1$ with $(b+w)$ , $x_2$ with $(b^2+w^2)$ and $x_3$ with $(b^3+w^3)$ . Then the generating function using Polya's theorem is:\n\\begin{align*}\n    P_G(b+w,B62+w^2,b^3+w^3) &= \\frac{1}{3}\\left((b+w)^3+2(b^3+w^3)\\right)\\\\\n    &= b^3+w^3+b^2w+bw^2\n\\end{align*}\n\n\\Lecture{Jayalal Sarma}{Nov 12, 2020}{30}{Partial Order}{Prasannasai Babu}{$\\alpha$}{JS}\n\\section{Formal Definition and Examples}\nA partial order is a homogeneous binary relation $\\leq$ over a set $X$ satisfying particular axioms which are discussed below. When $x\\leq y$, we say that $x$ is related to $y$. (This does not imply that $y$ is also related to $x$, because the relation need not be symmetric.)\\\\\\\\\nThe axioms for a partial order state that the relation $\\leq$ is reflexive, antisymmetric, and transitive. That is, $\\forall a, b, c \\in X$, it must satisfy:\\\\\\\\\n\\textbf{Reflexivity:} $a\\leq a$\\\\\n\\textbf{Transitivity:} if $a\\leq b \\And b \\leq c$ then $a \\leq c$\\\\\n\\textbf{Antisymmetry:} if $a \\leq b \\And b \\leq c$ then $a = b$\\\\\\\\\nPartial Ordered set is also called as \\textbf{\"Poset\"}\\\\\\\\\n\\textbf{Example 1:} Natural numbers $\\mathbb{N}$ with $\\leq$ order\\\\\n\\textbf{Example 2:} Natural numbers $\\mathbb{N}$ with $|~$(division) relation, That is $a\\leq b$ if $a | b$\\\\\n\\textbf{Example 3:} Set $X = \\{1,2,4,3,7,6,9,10\\}$ with $|$ relation. In this example $1$ is less than or equal to every other element in the set as $1$ divides every other element in the set. Now take two elements $3$ and $7$, now we can't say $3 \\leq 7 \\And 7 \\leq 3$ as $3$ doesn't divide $7$ and $7$ doesn't divide $3$. So elements $3$ and $7$ are incomparable.\\\\\nThis leads to the notion of comparable and incomparable elements.\\\\\n\\textbf{Example 4:} Polynomials over $|~$ (division) relation.\\\\\n\\textbf{Example 5:} Words(over English alphabets) over lexicographic order or dictionary order or graded lexicographic order.\\\\\\\\\nA partial order is said to be total order of there are no incomparable elements.\\\\\\\\\n\\textbf{Example 6:} Set of subsets of $[n]$ and the ordering is by inclusion. This is not a total order.\\\\\n\\textbf{Example 7:} Set of the strings over the alphabet $\\{0,1\\}$ of length $n$ over the ordering for two strings $x,y$ we say $x\\leq y$ if $\\forall i \\in [n],~x_i \\leq y_i$\\\\\\\\\nWe know that there is a bijection between the sets in Example $6$ and Example $7$, and it turns out that the bijection is not only a bijection and it also preserves the ordering. Our claim here is \nfor $A,B \\subseteq [N]$, $A \\subseteq B \\iff \\phi(A) \\leq \\phi(B)$, where $\\phi$ is the bijective function.\n\\section{Representation of Posets}\nA poset $p = (X,\\leq)$ can naturally representes as a directed graph with $X$ as the vertex set and the directed edges $xy$ if $x$ and $y$ have a relation $x \\leq y$. For example take three elements $a, b, c$ from $X$, now we will draw edge from $a$ to $b$ if $a\\leq b$ and edge from $b$ to $c$ if $b \\leq c$, Now we don't need to draw edge from $a$ to $c$, although we know $a \\leq c$ through transitivity, because it unnecessarily increases the size of the graph.\\\\\nGraph $G$ has vertices V as $V = X$ and edges E as $E = \\{(x,y) | x,y \\in X, x \\leq y \\}$\\\\\nThe graphs that represents these posets are called as \\textbf{Hasse diagram}. So transitive closure of the graph $G$ is the graph of the relation.\n\\section{New terms and Notations}\n\\textbf{Chain:} $C \\subseteq X$ is said to be a chain if every pair of elements in $C$ is comparable. The chain C is a total order.\\\\\\\\\n\\textbf{Height of Poset:} Length of the longest chain.\\\\\\\\\n\\textbf{Anti-Chain:} $A \\subseteq X$ is said to be anti-chain if every pair of elements in $A$ is incomparable.\\\\\\\\\n\\textbf{Width of Poset:} Size of largest Anti-Chain.\\\\\\\\\n\\textbf{Maximal Elements:}  $\\{x \\in X | \\forall y \\in X, y \\leq x ~or~ x || y$\\}. Here the symbol $||$ represents incomparability.\\\\\\\\\n\\textbf{Minimal Elements:} $\\{x \\in X | \\forall y \\in X, x \\leq y ~or~ x || y\\}$. Here the symbol $||$ represents incomparability.\\\\\\\\\n\\textbf{Note:} Maximal elements set and Minimal elements set, both are anti-chains.\n\\section{Theorems on partitioning poset into chains and anti-chains}\n\\begin{theorem}\nEvery poset $P(X,\\leq)$ can be partitioned into height($P$) many antichains(and not less).\n\\begin{proof}\nWe know that every element in anti-chain are incomparable. Now take the set of the elements in the longest chain. The length of the chain is height($P$). We know every element in the chain are comparable. So every element in the longest chain must belong to different anti-chain. So there must be atleast height($P$) many anti-chains.\n\nNow, let's look at alternate proof using induction.\n\n\\textbf{Claim:} For any max chain $C$ of poset $P$, min($P$) $\\cap ~ C ~\\neq~ \\phi$\n\nWe will do induction on height($P$). Now consider the longest chain C and remove min($P$) from $P$ to get $P'$, so height of $P'$ is height($P$) $ - 1$. We assume that the theorem is true for $P'$.\n\nApplying induction hypothesis, now add min($P$) to $P'$, the height will be increased by $1$ that is height($P$) $=$ height($P'$) $+ 1$ and adding min(P) will result in increasing number of anti-chains by $1$ to get full partition of $P$.\n\\end{proof}\n\\end{theorem}\n\\begin{theorem}\n\\textbf{Dilworth's Theorem:} Every poset $P(X,\\leq)$ can be partitioned into width($P$) many chains(and no less).\n\\begin{proof}\nWe will prove this by applying induction on the size of set $X$ i.e., $|X|$\nLet's take the width of the poset as $w$. Let $A \\subseteq X$ be the anti-chain with size $w$. Now we will decompose $P$ into $P_1 = (X_1,\\leq)$ and $P_2 = (X_2,\\leq)$.\n$$X_1 = \\{y \\in X | \\exists~ x ~ \\in ~ A, x \\leq y\\}$$\n$$X_2 = \\{y \\in X | \\exists~ x ~ \\in ~ A, y \\leq x\\}$$\n\\textbf{Claim:} $X_1 \\cap X_2 = A$. So $A \\subseteq X_1 \\cap X_2$.\\\\\nSuppose $y \\in X_1 \\cap X_2$, then $\\exists~ x_1, x_2$ such that $x_1 \\leq y \\leq x_2$.\\\\\nNow $x_1$ becomes comparable to $x_2$. But $x_1, x_2 \\in A$ which is anti-chain.\\\\\n$\\Rightarrow x_1 = x_2 = y$\\\\\n$\\Rightarrow y \\in A$\\\\\nSuppose $|X_1| < |X| \\And |X_2| < |X|$\nWe can apply induction hypothesis on $P_1$ and $P_2$ to get chains $C_1, C_2, C_3, \\ldots C_w$ and ${C'}_1, {C'}_2, {C'}_3, \\ldots {C'}_w$ each of length $w$.\\\\\nWe know,\\\\\n$$A = min(P_1) = max(P_2)$$\nWe can join the corresponding chains to get chains of poset $P$. Let the elements of set $A = \\{a_1,a_2,a_3,\\ldots,a_w\\}$.\\\\\nWithout loss of generality, let's assume that $C_1$ ends at $a_1$, $C_2$ ends at $a_2$ and so on upto $C_w$ ends at $a_w$. Similarly $C_1'$ starts as $a_1$, $C_2'$ starts at $a_2$ and so on upto $C_w'$ starts at $a_w$. Now partition of $X$ for $P$ can be $C_1 \\cdot {C_1'}, ~C_2 \\cdot {C_2'}$ and so on upto $C_w \\cdot {C_w'}$.\\\\\\\\\nWe need to handle the case when $|X_1| = |X|$ or $|X_2| = |X|$.\\\\\nIf $|X_1| = |X|$ that means $X_1 = X$, which in turn means $A = min(P)$. Similarly if we choose $A = max(P)$ then $X_2 = X$ and $|X_2| = |X|$. If there are anti-chains of size $w$ which are not min($P$) and max($P$), then we can do the same like above.\\\\\\\\\nBut if it is the case that the only max sized anti-chains are max($P$) or min($P$) or both, we should look for alternate approach.\\\\\\\\\nNow consider any max chain in P, and remove that chain $C$ from $P$ to get $P'$. So now,\\\\\n$$max(P) \\cap C \\neq \\phi \\And min(P) \\cap C \\neq \\phi$$\nWe can apply induction hypothesis to get a decomposition of $P'$ in less than $w$ many chains. Now put the $C$ back to get decomposition into $w$ many chains which partition $X$.\n\n\\end{proof}\n\\end{theorem}\n\n\\section{Applications of Dilworth's Theorem}\n\\textbf{Application 1:} Proof of Erdős–Szekeres theorem\\\\\n\\begin{theorem}\nEvery sequence of $rs+1$ distinct integers, there must exist an increasing sequence of length $r+1$ or decreasing sequence of length $s+1$.\n\\begin{proof}\nLet $a_1,a_2,a_3,\\ldots,a_n$ be the sequence of length $n$ where $n = rs+1$.\\\\\nDefine ordering of the sequence as $a_i \\leq a_j$ if $i\\leq j$ and $a_i \\leq a_j$. It is transitive, reflexive and anti-symmetric. So it is a partial order. So we define chains and anti-chains in this poset. A chain in this poset means the elements are in the increasing order.\\\\\n$\\Rightarrow$ A chain in this poset $\\rightarrow$ increasing sub-sequence.\\\\\nSimilarly an anti-chain in this poset means the elements are in the decreasing order.\\\\\n$\\Rightarrow$ An anti-chain in this poset $\\rightarrow$ decreasing sub-sequence.\\\\\nSuppose there is no anti-chain(decreasing sub-sequence) of size $s+1$.\n$$\\Rightarrow w(P) \\leq s$$\nBy Dilworth's theorem there is a decomposition of $P$ into atmost $s$ many chains. So there exists at least one chain with $r+1$ elements, otherwise there will be only $r\\times s$ elements in the ground set. But we have $rs+1$ elements. Therefore there must exist a chain with $r+1$ elements which is an increasing sub-sequence.\n\\end{proof}\n\\end{theorem}\n.\\\\\n\\textbf{Example for size of chain and anti-chain}\\\\\nWe know there is a bijection between example $6$ and example $7$ in section $30.1$ i.e., between the sets\\\\\n$\\Rightarrow$ subset poset of subsets of [n] $\\rightarrow$ Boolean strings poset of length $n$.\\\\\nThe max length of the chain is $n+1$. Intutively we can say that maximum size of the anti-chain is $n \\choose \\frac{n}{2}$. Let's look how to prove it in the next lecture by Sperner's theorem.\n%\\Lecture{Jayalal Sarma}{Nov 13, 2020}{31}{Sperner's Theorem}{Prasannasai Babu}{$\\alpha$}{JS}\n%\\section{{Sperner's theorem}}\n\\begin{theorem}\n\\textbf The maximum size of any anti-chain in the subset poset(Example $6$ of $30.1$) is $n \\choose \\frac{n}{2}$.\n\\begin{proof}\nThe subset poset is equivalent to boolean strings of length $n$ poset. Now let's represent boolean string poset as $B_n$. We need to prove width($B_n$) = $n \\choose \\frac{n}{2}$.\\\\\nLet us first show that width($B_n$) is atleast $n \\choose \\frac{n}{2}$. We can show one anti-chain of size $n \\choose \\frac{n}{2}$, that is subsets of size $\\frac{n}{2}.$\\\\\nNow we need to show that any anti-chain in $B_n$ must have size $\\leq ~{n \\choose \\frac{n}{2}}$\\\\\\\\\nLet F be any anti-chain in $B_n$. We need to show $|F| \\leq {n \\choose \\frac{n}{2}}$. Let us say,\\\\\\\\\nA permutation $\\pi \\in S_n$ is said to meet $A \\subseteq \\{1,2,\\ldots,n\\}$ if $A$ forms prefix of $\\pi$. This statement meaning is, Let's say $|A| = k$ then $\\pi$ said to meet $A$ if $A = \\{\\pi(1),\\pi(2),\\ldots,\\pi(k)\\}$.\\\\\\\\\n\nConsider each subset in $F$ and consider permutations meeting them, As we are taking subsets from $F$, they are incomparable. Hence a single permutation can't meet both $A$ and $B$.Now let's count the size of\n$$\\sum_{A\\in F} \\bigg|\\{\\pi | \\pi ~meets~ A\\}\\bigg|$$\nAs single permutation can meet only one subset of F,\n$$\\sum_{A\\in F} \\bigg|\\{\\pi | \\pi ~meets~ A\\}\\bigg| \\leq n!$$\nNow number of permutations that can meet set $A$ of size $k$ is $k! \\times (n-k)!$.So,\n$$\\sum_{A\\in F} |A|! \\times (n-|A|)! ~~~\\leq~~~ n!$$\nBring that RHS term to LHS, now \n$$\\sum_{A\\in F} \\frac{1}{\\frac{n!}{|A|! \\times (n-|A|)!}} ~~~\\leq~~~ 1$$\n$$\\sum_{A\\in F} \\frac{1}{{n \\choose {|A|}}} ~~~ \\leq ~~~ 1$$\nWe can substitute $n \\choose \\frac{n}{2}$ in place of $|A|$ and the inequality still holds.\n$$\\sum_{A\\in F} \\frac{1}{{n \\choose \\frac{n}{2}}} ~~~ \\leq ~~~ 1$$\n$$\\sum_{A\\in F} 1  ~~~ \\leq ~~~ {n \\choose \\frac{n}{2}}$$\n$$|F| ~~~\\leq~~~ {n \\choose \\frac{n}{2}}$$\nWe showed that,\n$$|F| ~~~\\leq~~~ {n \\choose \\frac{n}{2}} \\And |F| ~~~\\geq~~~ {n \\choose \\frac{n}{2}}$$\nHence the max size of the anti-chain $F$ is \n$$|F| ~~~=~~~ {n \\choose \\frac{n}{2}} $$\nHence proved.\n\\end{proof}\n\\end{theorem}\n\n\n\n\n", "meta": {"hexsha": "67f054f36803e06fe6127521a4d6004bf30940a3", "size": 24105, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week10.tex", "max_stars_repo_name": "Achyuth-Prakash/theory-toolkit", "max_stars_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week10.tex", "max_issues_repo_name": "Achyuth-Prakash/theory-toolkit", "max_issues_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-08T07:34:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-30T06:06:12.000Z", "max_forks_repo_path": "week10.tex", "max_forks_repo_name": "Achyuth-Prakash/theory-toolkit", "max_forks_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2020-09-25T01:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-28T11:22:06.000Z", "avg_line_length": 82.2696245734, "max_line_length": 524, "alphanum_fraction": 0.6655465671, "num_tokens": 8757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.650707800950769}}
{"text": "\\section{Technicalities}\n\n\\subsection{Parity Games}\n\nA \\emph{parity game} is a tuple $G = (V,V_0,V_1,E,\\Omega)$ where $(V,E)$ forms a directed graph\nwhose node set is partitioned into $V = V_0 \\cup V_1$ with $V_0 \\cap V_1 = \\emptyset$, and\n$\\Omega : V \\to \\Nat$ is the \\emph{priority function} that assigns to each node a natural number\ncalled the \\emph{priority} of the node. We assume the underlying graph to be total, i.e.\\ for every\n$v \\in V$ there is a $w \\in W$ s.t.\\ $(v,w) \\in E$.\n\nWe also use infix notation $vEw$ instead of $(v,w) \\in E$ and define the set of all \\emph{successors} of\n$v$ as $vE := \\{ w \\mid vEw \\}$, as well as the set of all \\emph{predecessors} of $w$ as\n$Ew := \\{ v \\mid vEw \\}$.\n\nThe game is played between two players called $0$ and $1$ in the following way. Starting in a node\n$v_0 \\in V$ they construct an infinite path through the graph as follows. If the construction so far\nhas yielded a finite sequence $v_0\\ldots v_n$ and $v_n \\in V_i$ then player $i$ selects a $w \\in v_nE$\nand the play continues with the sequence $v_0\\ldots v_n w$.\n\nEvery play has a unique winner given by the \\emph{parity} of the greatest priority that occurs infinitely \noften in a play. The winner of the play $v_0 v_1 v_2 \\ldots$ is player $i$ iff\n$\\max \\{ p \\mid \\forall j \\in \\Nat \\exists k \\geq j:\\, \\Omega(v_k) = p \\} \\equiv_2 i$ (where $i \\equiv_2 j$ holds iff $|i - j| \\mod 2 = 0$). That is, player $0$ tries to make an even\npriority occur infinitely often without any greater odd priorities occurring infinitely often, player\n$1$ attempts the converse.\n\n% The priorities occurring in a game are often ordered w.r.t. their usefulness to one of the players $i \\in \\{0, 1\\}$ by the \\emph{reward order $\\preceq_i$} which is defined as follows:\n% \\begin{displaymath}\n% p_1 \\preceq_i p_2 \\,:\\iff\\,\\, rew_i(p_1) \\leq rew_i(p_2)\n% \\end{displaymath}\n% where $rew_i(p) := p$ if $p \\equiv_2 i$ and $rew_i(p) := -p$ otherwise.\n% \\TODO{Paragraph nach hinten}\n\nIn the following we will restrict ourselves to finite parity games. It is easy to see that in a finite\nparity game the winner of a play is determined uniquely since the range of $\\Omega$ must necessarily\nbe finite as well. Technically, we are considering so-called max-parity games. There is also the\nmin-parity variant in which the winner is determined by the parity of the \\emph{least} priority occuring\ninfinitely often. On finite graphs, though, these two games are equivalent in the sense that a max-parity\ngame $G = (V,V_0,V_1,E,\\Omega)$ can be converted into a min-parity game $G' = (V,V_0,V_1,E,\\Omega')$\nwhilst preserving important notions like winning regions, strategies, etc. Simply let $p$ an even upper\nbound on all the priorities $\\Omega(v)$ for any $v \\in V$. Then define $\\Omega'(v) := p - \\Omega(v)$.\nThis construction also works the other way round, i.e.\\ in order to transform a min-parity into a\nmax-parity game.\n\nA \\emph{strategy} for player $i$ is a partial function $\\sigma: V^*V_i \\to V$, s.t.\\ for all sequences\n$v_0 \\ldots v_n$ with $v_{i+1} \\in v_iE$ for all $j=0,\\ldots,n-1$, and all $v \\in V_i$:\n$\\sigma(v_0\\ldots v_n) \\in v_nE$. That is, a strategy for player $i$ assigns to every finite path through\n$G$ that ends in $V_i$ a successor of the ending node. A play $v_0 v_1 \\ldots$ \\emph{conforms} to a strategy\n$\\sigma$ for player $i$ if for all $j \\in \\Nat$ we have: if $v_j \\in V_i$ then \n$v_{j+1} = \\sigma(v_0\\ldots v_j)$.\nIntuitively, conforming to a strategy means to always make those choices that are prescribed by the strategy.\nA strategy $\\sigma$ for player $i$ is a \\emph{winning strategy} starting in some node $v \\in V$ if player $i$ wins\nevery play that conforms to this strategy and begins in $v$. We say that player $i$ \\emph{wins} the game $G$\nstarting in $v$ iff he/she has a winning strategy for $G$ starting in $v$.\n\nWith $G$ we associate two sets $W_0,W_1 \\subseteq V$ with the following definition. $W_i$ is the set of\nall nodes $v$ s.t.\\ player $i$ wins the game $G$ starting in $v$. We write $W_i^G$ in order to name the parity \ngame that the winning regions refer to, for example when it cannot uniquely be identified from the context. \n\nClearly, we must have\n$W_0 \\cap W_1 = \\emptyset$ for otherwise assume that there is a node $v$ such that both players $0$ and $1$\nhave winning strategies $\\sigma_0$ and $\\sigma_1$ for $G$ starting in $v$. Then there is a unique play\n$\\pi = v_0 v_1 \\ldots$ such that $v_0 = v$ and $\\pi$ conforms to both $\\sigma_0$ and $\\sigma_1$. It is\nobtained by simply playing the game while both players perform their choices according to their respective\nstrategies. However, by definition $\\pi$ is won by both players, and therefore the maximal priority occurring\ninfinitely often would have to be both even and odd.\n\nOn the other hand, it is not obvious that every node should belong to either of $W_0$ or $W_1$. However, this\nis indeed the case and known as \\emph{determinacy}: a player has a strategy for a game iff the opponent does\nnot have a strategy for that game.\n\n\\begin{theorem}[\\cite{Mart75,Gurevich-Harrington/82,focs91*368}]\nLet $G = (V,V_0,V_1,E,\\Omega)$ be a parity game. Then $W_0 \\cap W_1 = \\emptyset$ and $W_0 \\cup W_1 = V$.\n\\end{theorem}\n\nA strategy $\\sigma$ for player $i$ is called \\emph{positional} or \\emph{memory-less} or \\emph{history-free} if\nfor all $v_0\\ldots v_n \\in V^*V_i$ and all $w_0\\ldots w_m \\in V^*V_i$ we have: if $v_n = w_m$ then\n$\\sigma(v_0\\ldots v_n) = \\sigma(w_0\\ldots w_m)$. That is, the value of the strategy on a finite path\nonly depends on the last node on that path. An important feature of parity games is the fact that such\nstrategies suffice.\n\n\\begin{theorem}[\\cite{focs91*368}]\nLet $G = (V,V_0,V_1,E,\\Omega)$ be a parity game, $v \\in V$, and $i \\in \\{0,1\\}$. Player $i$ has a winning\nstrategy for $G$ starting in $v$ iff player $i$ has a positional winning strategy for $G$ starting in $v$.\n\\end{theorem}\n\nA positional strategy $\\sigma$ for player $i$ induces a \\emph{subgame} \n$G|_\\sigma := (V, V_0, V_1, E|_\\sigma, \\Omega)$ where \n$E|_\\sigma := \\{(u, v) \\in E \\mid u \\in dom(\\sigma) \\Rightarrow \\sigma(u) = v\\}$. Such a subgame $G|_\\sigma$ \nis, roughly speaking, basically the same game as $G$ with the restriction that whenever $\\sigma$ provides a \nstrategy decision for a node $u \\in V_i$ all transitions from $u$ but $\\sigma(u)$ are no longer accessible.\n\nA set $U \\subseteq V$ is said to be $i$-closed iff player $i$ can force any play to stay within $U$. This\nmeans that player $1-i$ must not able to leave $U$ but player $i$ must always have the choice to remain \ninside $U$: \n\\begin{displaymath}\n\\forall v \\in U:\\, \\big(\\ v \\in V_{1-i}\\, \\Rightarrow \\, vE \\subseteq U\\ \\big)\n\\enspace \\mbox{and} \\enspace\n\\big(\\ v \\in V_i\\, \\Rightarrow \\, vE \\cap U \\ne \\emptyset\\ \\big)\n\\end{displaymath}\nNote that $W_0$ is $0$-closed and $W_1$ is $1$-closed.\n\nA set $U \\subseteq V$ induces a \\emph{subgame} \n$G|_U := (U, U \\cap V_0, U \\cap V_1, E \\cap U \\times U, \\Omega|_U)$ iff the underlying transition relation \n$E \\cap U \\times U$ remains total i.e. for all $u \\in U$ there is at least one $v \\in U$ s.t.\\ $uEv$. Clearly, \neach $i$-closed set $U$ induces a subgame. We often identify a set $U \\subseteq V$ that induces a subgame \nw.r.t.\\ a fixed parity game with the induced subgame itself.\n\n\\subsection{Dominions}\n\nA set $U \\subseteq V$ is called an \\emph{$i$-dominion} iff $U$ is $i$-closed and the induced subgame is won by player $i$. Clearly, $W_0$ is a $0$-dominion and $W_1$ is a $1$-dominion. That is, an $i$-dominion $U$ covers the idea of a region in the game graph that is won by player $i$ by forcing player $1-i$ to stay in $U$ on the one hand; but on the other hand an $i$-dominion $U$ is only won by player $i$ when using a winning strategy on $U$.\n\nTo see more precisely what the concept of dominions is used for we need to introduce \\emph{attractors} and \n\\emph{SCC decompositions} of parity games.\n\n\n\\subsection{Attractors and Attractor Strategies}\nLet $U \\subseteq V$ and $i \\in \\{0,1\\}$. Define for all $k \\in \\Nat$\n\\begin{align*}\n\\attr{0}{i}{U} \\enspace := \\enspace &U \\\\\n\\attr{k+1}{i}{U} \\enspace := \\enspace &\\attr{k}{i}{U} \\\\\n\\cup\\enspace &(V_i \\cap \\{ v \\mid vE \\cap \\attr{k}{i}{U} \\ne \\emptyset \\}) \\\\\n\\cup\\enspace &(V_{1-i} \\cap \\{ v \\mid vE \\subseteq \\attr{k}{i}{U} \\}) \\\\\n\\attr{}{i}{U} \\enspace := \\enspace &\\bigcup\\limits_{k \\in \\Nat} \\attr{k}{i}{U}\n\\end{align*}\nIntuitively, $\\attr{k}{i}{U}$ consists of all nodes s.t.\\ player $i$ can force any play to reach $U$ in\nat most $k$ moves. \n%Attractors are necessary in order to be able to use local solvers for the global problem.\n\n\\begin{lemma}[\\cite{TCS::Zielonka1998,Stirling95}]\n\\label{lem:minusattr}\nLet $G = (V,V_0,V_1,E,\\Omega)$ be a parity game and $U \\subseteq V$. Let $V' := V \\setminus \\attr{}{i}{U}$.\nThen $G' = (V',V_0 \\cap V',V_1 \\cap V', E \\cap V'\\times V',\\Omega)$ is again a parity game with its\nunderlying graph being total.\n\\end{lemma}\n\nIn other words $V \\setminus \\attr{}{i}{U}$ is $(1-i)$-closed; if additionally $U$ is an $i$-dominion then \n$\\attr{}{i}{U}$ also is an $i$-dominion. This yields a general procedure for solving parity games: find a \ndominion in the game graph that is won by one of the two players, build its attractor of the dominion and \ninvestigate the complement subgame.\n\nEach attractor for player $i$ induces an \\emph{attractor strategy} for player $i$. It is defined for all\n$v \\in \\attr{k}{i}{U} \\cap V_i$ for any $k \\ge 1$ as $\\sigma(v) = w$ iff $w \\in \\attr{k-1}{i}{U}$.\n\n\n\n\n\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "700340e7d3900638766656f121516a9757920da6", "size": 9568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tech.tex", "max_stars_repo_name": "tcsprojects/pgsolver", "max_stars_repo_head_hexsha": "88202c9452ccdcd4092280b4e76c31a16085d14c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2016-04-03T22:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T20:53:38.000Z", "max_issues_repo_path": "doc/tech.tex", "max_issues_repo_name": "tcsprojects/pgsolver", "max_issues_repo_head_hexsha": "88202c9452ccdcd4092280b4e76c31a16085d14c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-03-28T15:29:29.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-22T16:48:34.000Z", "max_forks_repo_path": "doc/tech.tex", "max_forks_repo_name": "tcsprojects/pgsolver", "max_forks_repo_head_hexsha": "88202c9452ccdcd4092280b4e76c31a16085d14c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-01-06T10:32:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T15:58:23.000Z", "avg_line_length": 61.3333333333, "max_line_length": 447, "alphanum_fraction": 0.6977424749, "num_tokens": 3141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6507077957413648}}
{"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\n\\begin{document}\n\\section*{Miscelleanous revision problems for BMO}\n\n\\begin{enumerate}\n  \\item $(x,y,z)$ is a point on unit sphere. Find the maximal value of $x+2y+3z$.\n\n  % http://artofproblemsolving.com/wiki/index.php?title=2004_USAMO_Problems/Problem_5\n  \\item Prove for $x \\geq 0$ that $x^5+1 \\geq x^3 + x^2$.\n  \\item Prove for $x,y,z \\geq 0$\n  $$3(x^3+y^3+z^3)^2 \\geq (x^2+y^2+z^2)^3 $$\n  \\item Prove for $a,b,c \\geq 0$\n  $$(a^5-a^2+3)(b^5-b^2+3)(c^5-c^2+3)\\geq (a+b+c)^3$$\n\n  % vorrat 104\n\t\\item Given positive real numbers $x_1,\\dots,x_n$ for which $x_1^2+\\dots+x_n^2=1$, find the minimal value of the expression\n\t$$\\frac{x_1^5}{x_2+x_3+\\dots+x_n} + \\frac{x_2^5}{x_1+x_3+\\dots+x_n} + \\dots +\\frac{x_n^5}{x_1+x_2+\\dots+x_{n-1}}$$\n\n\t% vorrat 101\n\t\\item Let $x_1,\\dots,x_n$ be positive real numbers for which $x_1+\\dots+x_n=1$. Prove that\n\t$$\\frac{x_1}{\\sqrt{1-x_1}} + \\dots + \\frac{x_n}{\\sqrt{1-x_n}}\n\t\\geq\n\t\\frac{\\sqrt{x_1}+\\dots+\\sqrt{x_n}}{\\sqrt{n-1}} $$\n\n  \\item % http://www.math.olympiaadid.ut.ee/arhiiv/varia/bwtr/bw18tr/bw18tren.pdf\n  Find all factors of $10^{2013}-1$ which are smaller than $100$.\n\n  \\item % http://www.math.olympiaadid.ut.ee/arhiiv/varia/bwtr/bw18tr/bw18tren.pdf\n  Find the number of possible values for positive integer $k$ if it is known that $\\lcm(6^6,8^8,k)=12^{12}$\n\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "a03b708edd83bfbe8544dc1de3c6d3fb7baf3cec", "size": 1621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "19_miscproblems.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": "19_miscproblems.tex", "max_issues_repo_name": "kauraare/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": "19_miscproblems.tex", "max_forks_repo_name": "kauraare/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": "2019-05-26T15:18:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-26T15:18:18.000Z", "avg_line_length": 35.2391304348, "max_line_length": 124, "alphanum_fraction": 0.6822948797, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8152324893520001, "lm_q1q2_score": 0.650707793784523}}
{"text": "%!TEX root = ../TTT4150-Summary.tex\n\\section{Spherical geometry}\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=.6\\linewidth]{img/spherical_triangle}\n\t\\caption{A triangle on a sphere}\n\t\\label{fig:spherical-triangle}\n\\end{figure}\nA triangle on a sphere is defined by three points on the sphere, as in Figure \\ref{fig:spherical-triangle}. Each corner $A$, $B$, and $C$ has an angle, and each line/arc segment has an angle $a$, $b$, and $c$.\n\nModified cosine rules\n\\begin{equation}\n\\begin{split}\n\t\\cos a &= \\cos b \\cdot \\cos c + \\sin b \\cdot \\sin c \\cdot \\cos A \\\\\n\t\\cos b &= \\cos c \\cdot \\cos a + \\sin c \\cdot \\sin a \\cdot \\cos B \\\\\n\t\\cos c &= \\cos a \\cdot \\cos b + \\sin a \\cdot \\sin b \\cdot \\cos C\n\\end{split}\n\\end{equation}\nand sine rules\n\\begin{equation}\n\t\\frac{\\sin A}{\\sin a} = \\frac{\\sin B}{\\sin b} = \\frac{\\sin C}{\\sin c}\n\\end{equation}\napply.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Intersection between great circles}\n\nEach great circle is defined by two points on the surface of a sphere.\n\\begin{enumerate}\n\t\\item Convert the points to cartesian coordinates.\n\t\\item blabla\n\\end{enumerate}\n", "meta": {"hexsha": "5f6eb3becf67ecfa996e12ab9f89be1f20d5c09a", "size": 1142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTT4150 Navigation systems/tex/sec-spherical-geometry.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTT4150 Navigation systems/tex/sec-spherical-geometry.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTT4150 Navigation systems/tex/sec-spherical-geometry.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": 33.5882352941, "max_line_length": 209, "alphanum_fraction": 0.6567425569, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.650659387022419}}
{"text": "\\chapter{Contrast Enhancement}\n\\section{Introduction}\nBecause some features are hardly detectable by eye in an image, we\noften transform it before display. Histogram equalization is\none the most well-known methods for contrast enhancement.\nSuch an approach is generally useful for images\nwith a poor  intensity distribution. Since 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.  \n \nIn color images, objects can exhibit variations in color saturation\nwith little or no correspondence in luminance variation. \nSeveral methods have been proposed in the past for color image\nenhancement \\cite{col:toet92}.\n  The retinex concept was introduced by Land \\cite{col:land86} as a model\nfor human color constitancy. \nThe single scale retinex (SSR) method \\cite{col:jobson97a} consists of\napplying the following transform to each band $i$ of the color image:\n\\begin{eqnarray}\nR_i(x,y) = \\log( I_i(x,y)) - \\log(F(x,y) * I_i(x,y)) \n\\end{eqnarray}\nwhere $R_i(x,y)$ is the retinex output, $I_i(x,y)$ is the image \ndistribution in the $i$th spectral band, and $F$ is a Gaussian function.\nA gain/offset is applied to the retinex output which clips the highest and\nlowest signal excursions. This can be done by a k-sigma clipping.\nThe retinex method is efficient for dynamic range compression, but does not provide good\ntonal rendition \\cite{col:rahman96}. \nThe Multiscale Retinex (MSR) combines several SSR outputs to produce \na single output image which has both good dynamic range compression and\ncolor constancy, and good tonal rendition \\cite{col:jobson97b}.\nThe MSR can be defined by:\n\\begin{eqnarray}\nR_{MSR_i} = \\sum_{j=1}^N w_j R_{i,j}\n\\end{eqnarray}\nwith \n\\begin{eqnarray}\nR_{i,j}(x,y) = \\log( I_i(x,y)) - \\log(F_j(x,y) * I_i(x,y)) \n\\end{eqnarray}\n$N$ is the number of scales, $R_{i,j}$ is the $i$th spectral\ncomponent of the MSR output, and $w_j$ is the weight associated with\nthe scale $j$. The Gaussian $F_j$ is given by:\n\\begin{eqnarray}\nF_j(x,y) = K \\exp{- {r^2 \\over c_j^2}}\n\\end{eqnarray}\n$c_j$ defines the width of the Gaussian.\nIn \\cite{col:jobson97b}, three scales were recommended with $c_j$ values\nequal respectively to 15,80,250, and all weights $w_j$ fixed to ${1 \\over N}$.\nThe Multiscale Retinex introduces the concept of multiresolution for\ncontrast enhancement. Velde \\cite{col:velde99} has explicitly introduced\nthe wavelet transform and has proposed an algorithm which modifies the \nwavelet coefficients in order to amplify faint features.\n% \\section{Contrast Enhancement using the Wavelet Transform}\n% Velde \\cite{col:velde99} proposed  to use the wavelet transform\n% for edge enhancement.\n The idea is to first transform the image\nusing the dyadic wavelet transform (two directions per scale).\nThe gradient $G_{j,k}$ at scale $j$ and at pixel location $k$\nis calculated at each scale $j$ from\nthe wavelet coefficients $w_{j,k}^{(h)}$ and  $w_{j,k}^{(v)}$ relative to\nthe horizontal and vertical wavelet bands: \n$G_{j,k} = \\sqrt{ (w_{j,k}^{(h)})^2 + (w_{j,k}^{(v)})^2}$. Then the two \nwavelet coefficients at scale $j$ and at position $k$   \nare multiplied by  $y(G_{j,k})$, where $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\\label{eqn_velde}\n\\end{eqnarray}\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=6.5cm,height=4cm,clip=}\n}}\n}\n\\caption{Enhanced coefficients versus  original coefficients.  \nParameters are m=30, c=3 and p=0.5.\n}\n\\label{fig_velde}\n\\end{figure}\nThree parameters are needed: $p$, $m$ and $c$. \n$p$ determines the degree of non-linearity in the nonlinear rescaling\nof the luminance, and must be in $]0,1[$.  \nCoefficients larger than $m$ are not modified by the algorithm.\nThe $c$ parameter corresponds to the noise level.  \nFigure~\\ref{fig_velde} shows the modified wavelet coefficients versus\nthe original wavelet coefficients for a given set of parameters \n($m=30$, $c=3$ and $p=0.5$). \nFinally, the enhanced image is obtained by the inverse wavelet transform\nfrom the modified wavelet coefficients. \nFor color images, a similar method can be used, but by calculating \nthe multiscale gradient $\\Gamma_{j,k}$ from the multiscale gradient of \nthe three $L$, $u$, $v$ components: $\\Gamma_j(i) = \\sqrt{ \\parallel G_{j,k}^L \\parallel^2 + \n                     \\parallel G_{j,k}^u \\parallel^2 +\n\t\t     \\parallel G_{j,k}^v \\parallel^2 }$.\nAll wavelet coefficients at scale $j$ and at position $k$ \nare multiplied by $y(\\Gamma_{j,k})$,  the enhanced $\\tilde L$, $\\tilde u$, $\\tilde v$ components are reconstructed \nfrom the modified wavelet coefficients, and \nthe ($\\tilde L$,$\\tilde u$,$\\tilde v$) image is transformed into\nan RGB image. More details can be found in \\cite{col:velde99}.\n\nWavelet bases present some limitations,\nbecause they are not adapted to the detection of highly anisotropic elements,\nsuch as alignments in an image, or sheets in a cube. \nRecently, other multiscale\nsystems like ridgelets \\cite{Harmnet} and \ncurvelets \\cite{Curvelets-StMalo,starck:sta01_3}    \nwhich are very different from wavelet-like systems have been developed. \nCurvelets and ridgelets take  the form of basis elements which \nexhibit very high directional sensitivity and are highly anisotropic. \nThe curvelet transform uses the ridgelet transform in its digital \nimplementation. We first describe the ridgelet and the curvelet \ntransform, then we show how contrast enhancement can be obtained \nfrom the curvelet coefficients.\n\n\\section{Contrast Enhancement by the Cur\\-ve\\-let Trans\\-form}\n\nSince the curvelet transform is well-adapted to represent images containing edges,\nit is a good candidate for edge enhancement \\cite{starck:capri02,starck:sta02_4}. \nCurvelet coefficients\ncan be modified in order to enhance edges in an image. A function $y_c$\nmust be defined which modifies the values of the curvelet \ncoefficients. It could be a function similar to the one defined for the \nwavelet coefficients \\cite{col:velde99} (see equation~\\ref{eqn_velde}).\nThis function presents however the drawback of amplifying the noise (linearly)\nas well as the signal of interest. We introduce explicitly the noise standard \ndeviation $\\sigma$ in the equation:\n\\begin{eqnarray}\n  y_c(x, \\sigma) & = & 1 \\mbox{ if }   x < c \\sigma \\nonumber \\\\\n  y_c(x, \\sigma) & = & \\frac{x-c\\sigma}{c \\sigma}(\\frac{m}{c \\sigma})^p + \\frac{2c\\sigma-x}{c \\sigma}  \\mbox{ if } x < 2c \\sigma \\nonumber \\\\\n  y_c(x, \\sigma) & = & (\\frac{m}{x})^p  \\mbox{ if } 2c\\sigma \\le x < m \\nonumber \\\\\n  y_c(x, \\sigma) & = & (\\frac{m}{x})^s \\mbox{ if }x \\ge m\n\\label{eqn_velde_curve}\n\\end{eqnarray}\n\n\\begin{figure}[htb]\n\\centerline{  \n\\hbox{\n\\psfig{figure=fig_velde_mod.ps,bbllx=3cm,bblly=13cm,bburx=20cm,bbury=25.cm,width=6.5cm,height=4cm,clip=}\n\\psfig{figure=fig_velde_mod_sat.ps,bbllx=3cm,bblly=13cm,bburx=20cm,bbury=25cm,width=6.5cm,height=4cm,clip=}\n}}\n\\caption{Enhanced coefficients versus  original coefficients. Left, \nparameters are m=30,c=0.5,s=0, and p=0.5. Right, \nparameters are m=30,c=0.5,s=0.7,p=0.9.\n}\n\\label{fig_velde_cur_enhance}\n\\end{figure}\n\nWe have fixed $m=c=p=0.5$ and $s=0$ in all our experiments. $p$ determines \nthe\ndegree of non-linearity and $s$ introduces a saturation.\n$c$ becomes a normalized parameter, and a $c$ value larger than $3$ \nguaranties that the noise \nwill not be amplified. The $m$ parameter can be defined either from\nthe noise standard deviation ($m = K_m \\sigma$) or from the maximum curvelet\ncoefficient $M_c$ of the relative band ($m = l M_c$, with $l < 1$). The first\nchoice allows the user to define the coefficients to amplify as a function\nof their signal-to-noise ratio, while the second one gives an easy    \nand general way to fix the $m$ parameter independently of the range of the\npixel values. Figure~\\ref{fig_velde_cur_enhance} shows the curve representing\nthe enhanced coefficients versus the original coefficients for two\nsets of parameters. In the second case, a saturation is added.\n\nThe curvelet enhancement method for grayscale images consists of \nthe following steps:\n\\begin{enumerate}\n\\item Estimate the noise standard deviation $\\sigma$ in the input\nimage $I$.\n\\item Calculate the curvelet transform of the input image. We get a set \nof bands $w_{j}$, each band $w_j$ contains $N_j$ coefficients \nand corresponds to a given resolution level. \n\\item Calculate the noise  standard deviation $\\sigma_j$ for each\nband $j$ of the curvelet transform (see \\cite{starck:sta01_3} more\ndetails on this step).\n\\item For each band $j$ do\n\\begin{itemize}\n\\item Calculate the maximum $M_j$ of the band.\n\\item Multiply each curvelet coefficient $w_{j,k}$ by $y_c(\\mid w_{j,k} \\mid ,\\sigma_j)$.\n\\end{itemize}\n\\item Reconstruct the enhanced image from the modified curvelet coefficients.\n\\end{enumerate}\n\nFor color images, we apply first the curvelet transform on the\nthree components $L,u,v$. For each cur\\-velet coef\\-fi\\-cient, we  \ncal\\-cu\\-la\\-te $e = \\sqrt{ c_L^2 + c_u^2 + c_v^2}$, where $(c_L, c_u, c_v)$\nare respectively the curvelet coefficients of the three components,\nand the mo\\-di\\-fied coef\\-fi\\-cients are obtained by:\n$(\\tilde c_L, \\tilde  c_u, \\tilde c_v) = \n(y_c(e, \\sigma)c_L , y_c(e, \\sigma)c_u, y_c(e, \\sigma)c_v)$. \n\nValues in the enhanced components can be larger than the \nauthorized upper limit (in general $255$),\nand we found it necessary to add a final step to our method, which is\na sigma-clipping saturation.\n\n\\section{Examples}\n\\subsubsection*{Saturn Image}\n\\begin{figure}[htb]\n\\centerline{  \n\\vbox{\n\\hbox{\n\\psfig{figure=fig_sat512.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=8cm,height=8cm,clip=}\n\\psfig{figure=fig_sat_contrast_histo.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=8cm,height=8cm,clip=}\n}\n\\hbox{\n\\psfig{figure=fig_sat_contrast_wedge.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=8cm,height=8cm,clip=}\n\\psfig{figure=fig_sat_contrast_cur.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=8cm,height=8cm,clip=}\n}}\n}\n\\caption{Top, Saturn image and its histogram equalization. Bottom,\nenhancement image by the wavelet transform and the curvelet transform.}\n\\label{fig_saturn_cur_enhance}\n\\end{figure}\n\nFigure~\\ref{fig_saturn_cur_enhance} shows respectively from left to right\nand from top to bottom \nthe Saturn image, the histogram equalized image, the wavelet multiscale\nedge enhanced image and the curvelet multiscale\nedge enhanced image (parameters were $s=0$, $p=0.5$, $c=3$, and $l=0.5$). \nThe curvelet multiscale edge enhanced image shows clearly better the \nrings and edges of Saturn.\n\n\\subsubsection*{Satellite Image}\n\\begin{figure}[htb]\n\\centerline{  \n\\vbox{\n\\hbox{\n\\psfig{figure=fig_marseille.ps,bbllx=1.9cm,bblly=12.8cm,bburx=14.6cm,bbury=25.5cm,width=10.cm,height=10cm,clip=}\n}\n\\hbox{\n\\psfig{figure=fig_cur_marseille.ps,bbllx=1.9cm,bblly=12.8cm,bburx=14.6cm,bbury=25.5cm,width=10.cm,height=10cm,clip=}\n}}\n}\n\\caption{Top, grayscale image, and bottom,\ncurvelet enhanced image.}\n\\label{fig_marseille_bw_cur_enhance}\n\\end{figure}\n \n\\begin{figure}[htb]\n\\centerline{  \n\\vbox{\n\\hbox{\n\\psfig{figure=kodak140501.ps,bbllx=5.9cm,bblly=8.1cm,bburx=15cm,bbury=21.7cm,width=5.5cm,height=8cm,clip=}\n\\psfig{figure=kodak140501_ret.ps,bbllx=5.9cm,bblly=8.1cm,bburx=15cm,bbury=21.7cm,width=5.5cm,height=8cm,clip=}\n}\n\\hbox{\n\\psfig{figure=kodak140501_mret.ps,bbllx=5.9cm,bblly=8.1cm,bburx=15cm,bbury=21.7cm,width=5.5cm,height=8cm,clip=}\n\\psfig{figure=kodak140501_cur.ps,bbllx=5.9cm,bblly=8.1cm,bburx=15cm,bbury=21.7cm,width=5.5cm,height=8cm,clip=}\n}}\n}\n\\caption{Top, color image (Kodak picture of the day 14/05/02) and retinex\nmethod. Bottom, multiscale retinex method and multiscale edge enhancement.}\n\\label{fig_kodak_col_wt_enhance}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{  \n\\vbox{\n\\hbox{\n\\psfig{figure=K111201.ps,bbllx=4.3cm,bblly=10.8cm,bburx=16.7cm,bbury=19.1cm,width=12.5cm,height=8.2cm,clip=}\n}\n\\hbox{\n\\psfig{figure=K111201_cur.ps,bbllx=4.3cm,bblly=10.8cm,bburx=16.7cm,bbury=19.1cm,width=12.5cm,height=8.2cm,clip=}\n}}\n}\n\\caption{Left, color image (Kodak picture of the day 11/12/01), and right,\ncurvelet enhanced image.}\n\\label{fig_kodak2_col_cur_enhance}\n\\end{figure}\n\nFigure~\\ref{fig_marseille_bw_cur_enhance}  \nshows the results for the enhancement of a grayscale satellite image, and\nFigure~\\ref{fig_kodak_col_wt_enhance}  \nshows the results for the enhancement of a color image (Kodak image of\nthe day 14/05/01) by the retinex,\nthe multiscale retinex and the curvelet multiscale edge enhancement methods.\n Figure~\\ref{fig_kodak2_col_cur_enhance} \nshows the results for the enhancement of a color image (Kodak image of\nthe day 11/12/01).\n\n\\section{Discussion}\nA number of properties, respected by the curvelet filtering \ndescribed here, are important for contrast stretching:\n\\begin{enumerate}\n\\item Noise must not be amplified in enhancing edges.\n\\item Colors should not be unduly modified.  In multiscale retinex,\nfor example, a tendancy towards increased grayness is seen.  This is \nnot the case using curvelets.\n\\item It is very advantageous if block effects do not occur. \nBlock overlapping is usually not necessary in curvelet-based contrast\nenhancement, unlike in the case of noise filtering.  \n\\end{enumerate}\n% A range of further examples can be seen at \\\\\n% http://www-stat.stanford.edu/$\\sim$jstarck/contrast.html.\n\n% \\clearpage\n% \\newpage\n\n\n\n", "meta": {"hexsha": "480687979942511084b2ea46cac6cd95a4d30944", "size": 13903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr4/ch_curcontrast.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_curcontrast.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_curcontrast.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.2866449511, "max_line_length": 141, "alphanum_fraction": 0.7491908221, "num_tokens": 4367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6506593787638751}}
{"text": "\n\\section{Ordinary differential equations}\n\nFor the clearest description of the model, we refer the reader to our code repository, because our object-oriented approach to software development is intended to be highly transparent and readable. For those who prefer dynamical systems such as this presented in the form of ordinary differential equations, we present the following.\n\n\\[\\frac{dS_{a,g}}{dt}=-\\lambda_{a,g}(t) \\sigma_{a} S_{a,g}\\]\n\\[\\frac{dE_{a,g,q=1}}{dt}=\\lambda_{a,g}(t) \\sigma_{a} S_{a,g} -\\alpha E_{a,g,q=1} - \\chi(t) E_{a,g,q=1} \\]\n\\[\\frac{dE_{a,g,q=2}}{dt}=-\\alpha E_{a,g,q=2} + \\chi(t) E_{a,g,q=1} \\]\n\\[\\frac{dP_{a,c,g,q}}{dt}=p_{a,c}(t) \\alpha E_{a,g,q}-\\nu P_{a,c,g,q}\\]\n\\[\\frac{dI_{a,c,g,q}}{dt}=\\nu P_{a,c,g,q}-\\gamma_{c}I_{a,c,g,q}\\]\n\\[\\frac{dL_{a,c,g,q}}{dt}=\\gamma_{c}I_{a,c,g,q}-\\delta_{a,c}L_{a,c,g,q}-\\mu_{a,c}L_{a,c,g,q}\\]\n\\[\\frac{dR_{a,g}}{dt}=\\sum_{c,q}{}\\delta_{a,c}L_{a,c,g,q}\\]\nwhere\n\\[\\lambda_{a,g}=\\beta \\sum_{g'}\\textbf{G}_{g,g'} \\sum_{j,c}\\frac{\\epsilon P_{j,c,g'}(t)+\\iota_{c}I_{j,c,g'}(t)+\\kappa_{c}L_{j,c,g'}(t)}{N_{j,g'}(t)} C_{a,j}(t)\\]\n\n\\[\\sum_{c}p_{a,c}(t)=1,\\forall t\\in\\mathbb{R}\\]\n\n\\[\\chi(t) = \\frac{\\alpha q(t) u(t)}{1 - q(t) u(t)}\\]\n\n\\[\\textbf{C}_{0}=\\textbf{C}_{H}+\\textbf{C}_{S}+\\textbf{C}_{W}+\\textbf{C}_{L}\\]\n\n\\[\\textbf{C}_{g}(t)=\\textbf{C}_{H}+s_{g}(t)^{2}\\textbf{C}_{S}+w_{g}(t)^{2}\\textbf{C}_{W}+l_{g}(t)^{2}\\textbf{C}_{L}\\]\n\n\\[l_{g}(t)=\\frac{re_{g}(t)+gr_{g}(t)+pa_{g}(t)+tr_{g}(t)}{4}\\]\n\n\\begin{table}[ht]\n\\renewcommand{\\baselinestretch}{1}\n    \t\\begin{tabular}{| p{2cm} | p{11.1cm} |}\n    \t\\hline\n    \t\tSymbol & Explanation \\\\\n\t    \t\\hline\n\t    \t$S$ & Persons susceptible to infection \\\\\n    \t\t$E$ & Persons in the non-infectious incubation period \\\\\n    \t\t$P$ & Persons in the incubation period \\\\\n    \t\t$I$ & Persons in the early active disease period, before isolation or hospitalisation may occur \\\\\n    \t\t$L$ & Persons in the late active disease period, after isolation or hospitalisation may have occurred \\\\\n    \t\t$R$ & Persons in the recovered period, from which re-infection cannot occur \\\\\n    \t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\\begin{table}[ht]\n\\renewcommand{\\baselinestretch}{1}\n    \t\\begin{tabular}{| p{2cm} | p{11.1cm} |}\n    \t\\hline\n    \t\tSymbol & Explanation \\\\\n    \t\t\\hline\n    \t\t\\textit{t} & Time  \\\\\n    \t\t$_{\\textit{a}}$ & Compartment of age group a \\\\\n    \t\t$_{\\textit{c}}$ & Compartment of clinical stratification c \\\\\n    \t\t$_{\\textit{g}}$ & Compartment of geographical service stratification g \\\\\n    \t\t$_{\\textit{q}}$ & Compartment of tracing stratification q \\\\\n    \t\t$\\alpha$ & Rate of progression from non-infectious to infectious incubation period \\\\\n    \t\t$\\nu$ & Rate of progression from infectious incubation to early active disease \\\\\n    \t\t$\\gamma$ & Rate of progression from early active disease to late active disease \\\\\n    \t\t$\\mu$ & Rate of disease-related death \\\\\n    \t\t$\\epsilon$ & Relative infectiousness of pre-symptomatic compartment \\\\\n    \t\t$\\iota$ & Clinical stratification infectiousness vector for early active compartment \\\\\n    \t\t$\\kappa$ & Clinical stratification infectiousness vector for late active compartments \\\\\n    \t\t$\\beta$ & Probability of infection per contact between an infectious and susceptible individual \\\\\n\t    \t\\textit{j} & Infectious populations \\\\\n    \t\t\\textit{p} & Proportion progressing to each clinical stratification \\\\\n    \t\t\\textbf{G} & Square matrix of dimensions \\(9 \\times 9\\) for nine services, as presented in Table \\ref{tab:intercluster_mixing} \\\\\n    \\hline\n\t\\end{tabular}\n\\end{table}\n\n\\begin{table}[ht]\n\\renewcommand{\\baselinestretch}{1}\n    \t\\begin{tabular}{| p{2cm} | p{11.1cm} |}\n    \t\\hline\n    \tSymbol & Explanation \\\\\n    \t\\hline\n    \t\\textbf{C} & Mixing matrix \\\\\n    \t\\textbf{H} & Household contribution to mixing matrix \\\\\n    \t\\textbf{W} & Workplace contribution to mixing matrix \\\\\n    \t\\textbf{O} & Other locations contribution to mixing matrix \\\\\n    \t\\textbf{S} & Schools contribution to mixing matrix \\\\\n    \t\\textit{l} & Other locations macrodistancing function of time \\\\\n    \t\\textit{w} & Function fit to Google mobility data for workplaces \\\\\n    \t\\textit{s} & Function fit to Google mobility data for schools \\\\\n    \t\\textit{re} & Function fit to Google mobility data for retail and recreation \\\\\n    \t\\textit{gr} & Function fit to Google mobility data for grocery and pharmacy \\\\\n    \t\\textit{pa} & Function fit to Google mobility data for parks \\\\\n    \t\\textit{tr} & Function fit to Google mobility data for transit stations \\\\\n    \t\\hline\n\t\\end{tabular}\n\\end{table}", "meta": {"hexsha": "8c3d4a9b51cfc34f59030c888be7a018ff45e2c5", "size": 4539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/papers/covid_19/projects/victoria/equations_with_tracing.tex", "max_stars_repo_name": "monash-emu/AuTuMN", "max_stars_repo_head_hexsha": "fa3b81ef54cf561e0e7364a48f4ff96585dc3310", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2020-03-11T06:15:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T03:38:35.000Z", "max_issues_repo_path": "docs/papers/covid_19/projects/victoria/equations_with_tracing.tex", "max_issues_repo_name": "monash-emu/AuTuMN", "max_issues_repo_head_hexsha": "fa3b81ef54cf561e0e7364a48f4ff96585dc3310", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": 96, "max_issues_repo_issues_event_min_datetime": "2020-01-29T05:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:48:46.000Z", "max_forks_repo_path": "docs/papers/covid_19/projects/victoria/equations_with_tracing.tex", "max_forks_repo_name": "monash-emu/AuTuMN", "max_forks_repo_head_hexsha": "fa3b81ef54cf561e0e7364a48f4ff96585dc3310", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-24T00:38:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T16:19:03.000Z", "avg_line_length": 51.0, "max_line_length": 334, "alphanum_fraction": 0.6481603878, "num_tokens": 1499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.6992544147913994, "lm_q1q2_score": 0.6506270429334036}}
{"text": "\\chapter{Naive Bayes}\n\\label{ch:naive_bayes}\n\nNaive Bayes \\marginnote{Naive Bayes assumes class-wise independent features. For a data set where features would actually be independent, which rarely happens in practice, the naive Bayes would be the ideal classifier.} is also a classification method. To see how naive Bayes works, we will use a data set on passengers' survival in the Titanic disaster of 1912. The \\textit{Titanic} data set describes 2201 passengers, with their tickets (first, second, thirds class or crew), age and gender.\n\n\\begin{figure}[h]\n    \\centering\n    \\vspace{-0.2cm}\n    \\includegraphics[scale=0.4]{workflow.png}\n\\end{figure}\n\nWe inspect naive Bayes models with the \\widget{Nomogram} widget. There, we see a scale 'Points' and scales for each feature. Below we can see probabilities. Note the 'Target class' in upper left corner. If it is set to 'yes', the widget will show the probability that a passenger survived.\n\nThe nomogram shows that gender was the most important feature for survival. If we move the blue dot to 'female', the survival probability increases to 73\\%. Furthermore, if that woman also travelled in the first class, she survived with probability of 90\\%. The bottom scales show the conversion from feature contributions to probability.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.45]{nomogram.png}\n    \\caption{According to the probability theory individual contributions should be multiplied. Nomograms get around this by working in a log-space: a sum in the log-space is equivalent to multiplication in the original space. Therefore nomograms sum contributions (in the log-space) of all feature values and then convert them back to probability.}\n\\end{figure}\n", "meta": {"hexsha": "b69ab3643ee3a3b0b6da02880be7a8ef625001a8", "size": 1728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/022-naive-bayes/naive-bayes.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/022-naive-bayes/naive-bayes.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/022-naive-bayes/naive-bayes.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": 82.2857142857, "max_line_length": 493, "alphanum_fraction": 0.78125, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.6505976221752474}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $D=\\begin{mymatrix}{rrr}\n    -2 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 2 \\\\\n  \\end{mymatrix}$ and\n  $E=\\begin{mymatrix}{rrr}\n    1 & 0 & 0 \\\\\n    0 & -1 & 0 \\\\\n    0 & 0 & 3 \\\\\n  \\end{mymatrix}$.\n  Find $D+E$, $DE$, and $D^7$.\n\\end{ex}\n\n\\begin{ex}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      -13 & -28 & 28 \\\\\n      4 & 9 & -8 \\\\\n      -4 & -8 & 9\n    \\end{mymatrix}.\n  \\end{equation*}\n  One eigenvalue is $3$. Diagonalize if possible.\n  \\begin{sol}\n    The eigenvectors and eigenvalues are:\n    \\begin{equation*}\n      \\set{\\begin{mymatrix}{c}\n          2 \\\\\n          0 \\\\\n          1\n        \\end{mymatrix},\n        \\begin{mymatrix}{c}\n          -2 \\\\\n          1 \\\\\n          0\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {1},\n      \\quad\n      \\set{\\begin{mymatrix}{c}\n          7 \\\\\n          -2 \\\\\n          2\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {3}.\n    \\end{equation*}\n    The matrix $P$ needed to diagonalize the above matrix is\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        2 & -2 & 7 \\\\\n        0 & 1 & -2 \\\\\n        1 & 0 & 2\n      \\end{mymatrix}\n    \\end{equation*}\n    and the diagonal matrix $D$ is\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        1 & 0 & 0  \\\\\n        0 & 1 & 0 \\\\\n        0 & 0 & 3\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      5 & -18 & -32 \\\\\n      0 & 5 & 4 \\\\\n      2 & -5 & -11\n    \\end{mymatrix}.\n  \\end{equation*}\n  One eigenvalue is $1$. Diagonalize if possible.\n  \\begin{sol}\n    The eigenvalues are $-1$ and $1$. The eigenvectors corresponding to\n    the eigenvalues are:\n    \\begin{equation*}\n      \\set{\\begin{mymatrix}{c}\n          10 \\\\\n          -2 \\\\\n          3\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {-1},\n      \\quad\n      \\set{\\begin{mymatrix}{c}\n          7 \\\\\n          -2 \\\\\n          2\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {1}.\n    \\end{equation*}\n    Since there are only 2 linearly independent eigenvectors, this\n    matrix is not diagonalizable.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      8 &   0 &  10 \\\\\n      -6 &  -3 &  -6 \\\\\n      -5 &   0 &  -7 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  One eigenvalue is $-3$. Diagonalize if possible.\n  \\begin{sol}\n    The eigenvectors and eigenvalues are:\n    \\begin{equation*}\n      \\set{\\begin{mymatrix}{c}\n          0 \\\\\n          1 \\\\\n          0\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {-3},\n      \\quad\n      \\set{\\begin{mymatrix}{c}\n          -2 \\\\\n          1 \\\\\n          1\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {3},\n      \\quad\n      \\set{\\begin{mymatrix}{c}\n          -1 \\\\\n          0 \\\\\n          1\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {-2}.\n    \\end{equation*}\n    The matrix $P$ needed to diagonalize the above matrix is\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        0 &  -2 &  -1 \\\\\n        1 &   1 &   0 \\\\\n        0 &   1 &   1 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n    and the diagonal matrix $D$ is\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        -3 &   0 &   0 \\\\\n        0 &   3 &   0 \\\\\n        0 &   0 &  -2 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      -1 & -2 & 2 \\\\\n      0 & 5 & -8 \\\\\n      0 & 4 & -7 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  One eigenvalue is $1$. Diagonalize if possible.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      2 &  -1 &   6 \\\\\n      -4 &  -1 &  -6 \\\\\n      -2 &   1 &  -6 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  One eigenvalue is $0$. Diagonalize if possible.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      3 &  -1 &   0 \\\\\n      1 &   4 &  -1 \\\\\n      -1 & -1 &   4 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  One eigenvalue is $3$. Diagonalize if possible.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "eb31b60a4472d0b20858784d135482eb8940bac0", "size": 4368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Diagonalization.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Diagonalization.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Diagonalization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 23.1111111111, "max_line_length": 71, "alphanum_fraction": 0.4983974359, "num_tokens": 1648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.6505976162075646}}
{"text": "\\chapter{Conclusion and Outlook}\n\n\\section{Summary}\nWe defined an algebraic graph structure that expresses the Collatz sequences in the form of a tree. Next, the vertex reachability properties were unveiled by examining the relationship between successive nodes in $H_C$. Moreover, we dealt with graphs that represent other variants of Collatz sequences, for instance $5x+1$ or $181x+1$. The interesting part of both variants just mentioned is that for these sequences the existence of cycles is known. With regard to a proof of the Collatz conjecture, theorems~\\ref{theo:2} and \\ref{theo:3} seem promising. They serve as the basis for further investigations of the problem.\n\n\\section{Further Research}\nIn subsequent studies, the properties of vertices in $H_C$ might be elaborated upon more closely by taking into account a vertex's label as well as its properties. In addition, future steps may include a detailed analysis of theorems~\\ref{theo:2} and \\ref{theo:3}.", "meta": {"hexsha": "0d1143e33089b28103f8490fbc6fb064fff218a9", "size": 967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v4.1/chapter/06_conclusion_update_COX_EDIT.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v4.1/chapter/06_conclusion_update_COX_EDIT.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v4.1/chapter/06_conclusion_update_COX_EDIT.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 138.1428571429, "max_line_length": 622, "alphanum_fraction": 0.8004136505, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6505976117237275}}
{"text": "% 13riemannianmetrics.tex\n% Fund Science! & Help Ernest finish his Physics Research! : quantum super-A-polynomials - a thesis by Ernest Yeung\n% ernestyalumni.tilt.com                                               \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% tilt.com    : 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\\subsection*{Riemannian Manifolds}\n\nRiemannian metric on $M$ - smooth symmetric 2-tensor field positive definite at each pt.   \\\\\n\nRiemannian manifold - pair $(M,g)$ \\\\\n\nIf $g$ on $M$, then $\\forall \\, p \\in M$, $g_p$ inner product on $T_pM$.  Because of this, we will often use the notation $\\langle X, Y\\rangle_g$ to denote \n\n\\[\ng_p(X,Y) \\in \\mathbb{R} \\quad \\, \\forall \\, X, Y \\in T_pM\n\\]\n\n$\\forall \\, $ smooth, local coordinates $(x^i)$, write Riemannian metric\n\\[\ng=g_{ij} dx^i \\otimes dx^j\n\\]\n\nwhere $g_{ij}$ symmetric positive definite matrix of smooth functions.  $g_{ij} = g_{ji}$\n\n\\[\n\\begin{gathered}\n  g = g_{ij} dx^i \\otimes dx^j = \\frac{1}{2} (g_{ij} dx^i \\otimes dx^j + g_{ji} dx^i \\otimes dx^j ) = \\frac{1}{2} (g_{ij} dx^i \\otimes dx^j + g_{ij} dx^j \\otimes dx^i ) = \\\\\n  = g_{ij} dx^i dx^j \\quad \\, (\\text{by Prop. 12.15(b)}) \\quad \\, \\text{Notice that $dx^idx^j$ is symmetrized!}\n\\end{gathered}\n\\]\n\n\n\\textbf{Example 13.1 (The Euclidean Metric)}  Euclidean metric on $\\mathbb{R}^n$, defined in standard coordinates\n\\[\ng = \\delta_{ij} dx^i dx^j\n\\]\n\nIt is common to use the abbreviation $\\omega^2$ for the symmetric product of a tensor $\\omega$ with itself, so the Euclidean metric can also be writen \n\\[\n\\overline{g} = (dx^1)^2 + \\dots + (dx^n)^2 \n\\]\n\nApplied to $v,w \\in T_p\\mathbb{R}^n$ \n\\[\n\\overline{g}_p(v,w) = \\delta_{ij} v^i w^j = \\sum_{i=1}^n v^i w^i = v\\cdot w\n\\]\nunder coordinate change, use Corollary 11.10\n\n\\begin{proposition}[13.3] \\textbf{(Existence of Riemannian Metrics)} \\\\\n                          $\\forall \\, $ smooth manifold $M$, $M$ with or without $\\partial M$, $\\exists \\, $ Riemannian metric $g$\n\\end{proposition}\n\n\\begin{proof}\nChoose covering of $M$ by smooth coordinate charts $(U_{\\alpha}, \\varphi_{\\alpha})$ \\\\\n$\\overline{g}$ Euclidean metric \\\\\n$\\forall \\, U_{\\alpha}$, $\\exists \\, $ Riemannian metric $g_{\\alpha} = \\varphi_{\\alpha}^* \\overline{g}$ \n\\[\n\\varphi_{\\alpha} : U_{\\alpha} \\to \\mathbb{R}^n\n\\]\nLet $\\lbrace \\psi_{\\alpha} \\rbrace$ smooth partition of unity subordinate to cover $\\lbrace U_{\\alpha} \\rbrace$\n\nDefine $g= \\sum_{\\alpha} \\psi_{\\alpha} g_{\\alpha}$\n\ns.t. $\\forall \\, g_{\\alpha}$, $\\psi_{\\alpha} g_{\\alpha} = 0$ outside $\\text{supp}{\\psi_{\\alpha}}$\n\nBy local finiteness, $\\exists \\, $ only finitely many $\\psi_{\\alpha} g_{\\alpha} \\neq 0$ in neighborhood of each pt. \n\nso $g= \\sum_{\\alpha} \\psi_{\\alpha} g_{\\alpha}$ defines a smooth tensor field\n\n\n\\end{proof}\n\n\ndefined on Riemannian manifold $(M,g)$\n\n\\begin{itemize}\n  \\item length or norm of $X \\in T_pM$ defined\n\n\\[\n|X|_g = \\langle X, X \\rangle_g^{1/2} = g_p(X,X)^{1/2}\n\\]\n\\item angle between $X,Y \\in T_pM$, $X,Y \\neq 0$ is unique $\\theta \\in [0,\\pi]$ satisfying \n\\[\n\\cos{\\theta} = \\frac{ \\langle X,Y \\rangle_g }{ |X|_g |Y|_g}\n\\]\n\\item $X,Y \\in T_pM$ orthogonal if $\\langle X,Y\\rangle_g = 0$\n\\item If $\\gamma:[a,b] \\to M$ piecewise smooth curve segment, length of $\\gamma$ is \n\\[\nL_g(\\gamma) = \\int_a^b |\\gamma'(t)|_g dt\n\\]\n\\end{itemize}\n\nJust as we did in Chapter 8 for $\\mathbb{R}^n$ \\\\ % (pp. 253), \\\\\n\\quad define orthonormal frame for $M$ to be local frame $(E_1 \\dots E_n)$ defined on some open subset $U \\subset M$ s.t. \\\\\n\\quad \\quad $( \\left. E_1 \\right|_p \\dots \\left. E_n \\right|_p )$ orthonormal basis for $T_pM$ \\quad \\, $\\forall \\, p \\in U$, or equivalently s.t. $\\langle E_i, E_j \\rangle_g = \\delta_{ij}$ \\\\\n\nExample 13.14.  coordinate frame $\\left( \\frac{ \\partial }{ \\partial x^i} \\right)$ global orthonormal frame on $\\mathbb{R}^n$\n\n\\begin{corollary}[13.8] (Existence of Local Orthonormal Frames).  Let $(M,g)$ Riemannian manifold. \\\\\n$\\forall \\, p \\in M$, $\\exists \\, $ smooth orthonormal frame on neighborhood of $p$.\n\\end{corollary}\n\n\n\nObserve Corollary 13.8.  doesn't show that $\\exists \\, $ smooth coordinates near $p$ for which coordinate frame is orthonormal. \\\\\n\n\\subsubsection*{Pullback Metrics}\n\nSuppose $\\begin{aligned} & \\quad \\\\ \n  & (M,g) \\\\\n  & (\\widetilde{M}, \\widetilde{g}) \\end{aligned}$ \\quad Riemannian manifolds.  \\\\\n\nisometry - smooth $F: M \\to \\widetilde{M}$ if $F$ diffeomorphism s.t. $F^* \\widetilde{g} = g$ \\\\\nif $\\exists \\, $ isometry $F$, $M, \\widetilde{M}$ isometric. \\\\\n$F$ local isometry is $\\forall \\, p \\in M$, $\\exists \\, $ neighborhood $U$ s.t. $\\left. F \\right|_U$ isometry of $U$ onto open $\\widetilde{U} \\subset M$ \\\\\n$g$ on $M$ flat if $\\forall \\, p \\in M$, $\\exists \\,$ neighborhood $U\\subset M$ s.t. $(U , \\left. g \\right|_U)$ isometric to open $\\widetilde{U} \\subset \\mathbb{R}^n$ with Euclidean metric.   \\\\\n\n\n\\staveXXIX\n\n\nProb. 11-14 shows $\\exists \\, $ only if metric flat.\n\n\n\\subsubsection*{Riemannian Submanifolds}\n\n\\subsection*{Riemannian Submanifolds}\n\n$S\\subset M$ \\\\\ndefine $ \\left. g \\right|_S = i^* g$, for $i:S \\hookrightarrow M$\n\\[\n( \\left. g \\right|_S)(X,Y) = i^* g(X,Y) = g( i_* X,i_* Y) = g(X,Y)\n\\]\n\n20131023 EY\n\nin general, $S \\subset M$ \\\\\n$F:S \\to M$\ne.g. $\\begin{aligned} & \\quad \\\\ \n  & F(u^1, u^2) = (x^1, x^2, x^3 ) \\\\ \n  & F(u^1 \\dots u^s ) = (x^1 \\dots x^m) \\text{ s.t. } s\\leq m \\quad (\\text{for this case}) \\end{aligned}$\n\nNote \n\\[\nx^i = x^i(u^1 \\dots u^s ) \\text{ or e.g. } x^2 = x^2(u^1, u^2 )\n\\]\n\nRecall these facts about pullbacks and pushforwards.  \n\n\\[\n\\begin{aligned}\n  & F^*: T_{F(p)}M \\to T_pS \\quad (\\text{pullback!}) \\\\ \n  & F_*: T_pS \\to T_{F(p)}M \\quad (\\text{push forward; remember we can only pushforward if $F$ diffeomorphism, i.e. $F,F^{-1}$ diff. and $F$ bijective}) \\\\\n  &  F^*: \\tau^2(M) \\to \\tau^2(S) \\quad (\\text{can always pullback tensors; in this case (rank 2)})\n\\end{aligned}\n\\]\n\nConsider charts $(U,u)$, $p\\in U\\subset S$, $(V,x)$, \\, $F(p) \\in V \\subset M$, $V \\subset F(U)$ \\\\\n\\quad For $f:M \\to \\mathbb{R}$, i.e. $f\\in \\mathcal{C}^{\\infty}(M)$ \\\\\n\\quad $fF: S \\to \\mathbb{R}$ i.e. $fF \\in \\mathcal{C}^{\\infty}(S)$ \n\\[\nfF = f(x^i)^{-1}x^i F(u^j)^{-1} u^j = (f(x^i)^{-1})(x^i F(u^j)^{-1})u^j = f(x^i(u^j))\n\\]\n\nConsider $\\overline{g}(x_i,x_j)$ \\\\\n\\phantom{Consider } $\\overline{g} = \\delta_{ij} dx^i dx^j$ ($\\overline{g}$ as a tensor (rank 2) in its local coordinate form, with coordinates $y^i$.  So $\\overline{g}$ is (like, or is) a Euclidean metric)\n\n\n\\[\nF_* E_i(f) = E_i(fF) = \\omega^k_{(i)} \\frac{ \\partial }{ \\partial x^k}f = \\frac{ \\partial }{ \\partial u^i} f(F(u)) = \\frac{ \\partial f}{ \\partial x^k } \\frac{ \\partial x^k }{ \\partial u^i } \\quad \\quad \\, \\omega_{(i)}^k = \\frac{ \\partial x^k}{ \\partial u^i }\n\\]\n\nBy definition, for  \\\\\n\\quad $F^*\\overline{g}(x^{(i)}, x^{(j)})$ on by (notation) $F^*g(A,B)$, \\, $A,B \\in T_pS$ \\\\\n\\quad $F^*\\overline{g}(E_i, E_j) = \\overline{g}(F_* E_i, F_* E_j)$\n\n\\[\n\\begin{gathered}\n  F^*\\overline{g}(E_i,E_j) = \\overset{\\circ}{g}(E_i, E_j) = \\overset{\\circ}{g}_{ij} = \\overline{g}(F_* E_i, F_* E_j) = \\overline{g}{ \\left( \\frac{ \\partial x^k}{ \\partial u^i } \\frac{ \\partial }{ \\partial x^k} , \\frac{ \\partial x^l }{ \\partial u^j } \\frac{ \\partial }{ \\partial x^l } \\right) } = \\\\\n  = \\overline{g}_{kl} \\frac{ \\partial x^k}{ \\partial u^i } \\frac{ \\partial x^l }{ \\partial u^j }\n\\end{gathered}\n\\]\n\nFormula for pullback of metric on $M$ to metric on $S$ i.e. formula for metric on $S$\n\\[\n\\boxed{ (F^* \\overline{g} )_{ij} = \\overset{\\circ}{g}_{ij} = \\overline{g}_{kl} \\frac{ \\partial x^k}{ \\partial u^i } \\frac{ \\partial x^l }{ \\partial u^j } }\n\\]\n\nFor $\\overline{g}_{kl} = \\delta_{kl}$ (Euclidean metric)\n\n\\[\n\\overset{\\circ}{g}_{ij} = \\frac{ \\partial x^k}{ \\partial u^i } \\frac{ \\partial x^k}{ \\partial u^j } = \\left( \\frac{ \\partial x^i }{ \\partial u^k } \\right)^T \\frac{ \\partial x^k}{ \\partial u^j } = (D_u x)^T (D_u x) \\equiv (D_u x)^2 \n\\]\n\n$\\overset{\\circ}{g}_{ij}$ is just the square of the Jacobian (The square of the Jacobian is the metric in $S^1$).  \n\nThen you could get the matrix form of the metric.  \\\\\n\n\n\n\n\n\nExample 13.16\n\n$\\overset{ \\circ}{g} = \\left. \\overline{g} \\right|_{S^n}$  \\quad \\, $S^n \\hookrightarrow \\mathbb{R}^{n+1}$ round metric (or standard metric) on sphere. \n\n\n\n\nIt's usually easiest to compute the induced metric on a Riemannian submanifold in terms of local parametrizations (see Chapter 5)\n\n\nExample 13.17 \\textbf{(Induced Metrics in Graph Coordinates.)} \\\\\nLet open $U \\subset \\mathbb{R}^n$ \\\\\n\\phantom{ Let open } $M \\subset \\mathbb{R}^{n+1}$ graph of smooth $f:U \\to \\mathbb{R}$ \\\\\n\nThen $X:U\\to \\mathbb{R}^{n+1}$ \\\\\n\\phantom{ Then }$X(u^1 \\dots u^n) = (u^1 \\dots u^n, f(u))$ smooth (global) parametrization of $M$\n\ninduced metric on $M$,\n\n$\\overline{g} = \\delta_{ij} dy^i dy^j$ (note $y^i$ local coordinates on $\\mathbb{R}^{n+1}$)\n\nRecall Prop.11.9. $F^*(\\sigma \\otimes \\tau) = F^*\\sigma \\otimes F^*\\tau$ \\\\\nCorollary 11.10.  $F:M \\to N$, \\\\\n$F^*(\\sigma_{j_1 \\dots j_k} dy^{j_1} \\otimes \\dots \\otimes dy^{j_k} ) = (\\sigma_{j_1 \\dots j_k} \\circ F) d(y^j F) \\otimes \\dots \\otimes d(y^{j_k}F)$ \n\n\\[\n\\begin{gathered}\n  X^* \\overline{g} = (\\delta_{ij} \\circ X) d(y^i X) d(y^jX) = (du^1)^2 + \\dots + (du^n)^2 + (df)^2 \\\\\n  X^*\\overline{g}_p(E_i , E_j) = \\overline{g}_{X(p)}(X_* E_i, X_* E_j) \n\\end{gathered}\n\\]\n\n\n\\subsubsection*{The Normal Bundle}\n\nSuppose $(M,g)$, Riemannian submanifold $S\\subset M$ \\\\\n\\quad $\\forall \\, p \\in S$, vector $N \\in T_pN$ normal to $S$ if $N$ orthogonal to $T_pS$ with respect to $g$ \\\\\n\\quad \\quad $N_p S\\subset T_pM$, $N_pS = $ all vectors normal to $S$ at $p = \\lbrace N | \\langle N, X \\rangle_g = 0, \\, \\forall \\, X \\in T_pS \\rbrace$ normal space to $S$ at $p$ \\\\\n\n\n\n\\subsection*{The Riemannian Distance Function}\n\n\\exercisehead{13.23}\n\\[\nL_g(\\gamma) = \\int_a^b |\\gamma'(t)|_g dt = \\int_a^c |\\gamma'(t)|_g dt  + \\int_c^b |\\gamma'(t) |_g dt = L_g(\\left. \\gamma \\right|_{ [a,c] } ) + L_g( \\left. \\gamma \\right|_{[c,b]} )\n\\]\n\n\n\\exercisehead{13.24}\n\nOn every coordinate patch, consider on some interval $I \\subset \\mathbb{R}$ parametrizing curve $\\gamma$ on $M$ and $\\widetilde{\\gamma}$ on $\\widetilde{M}$ in the same way, and that $F^* \\widetilde{\\gamma} = \\widetilde{\\gamma}$\n\n\\[\n\\begin{gathered}\n  L_{\\widetilde{g}}(F\\circ \\gamma) = \\int_I |F\\gamma |_{\\widetilde{g}} ds = \\int_I  ( \\widetilde{g}( \\dot{ F \\gamma(t) }, \\dot{ F\\gamma(t)} )^{1/2} ds = \\int_I \\left( \\widetilde{g} ( \\dot{ \\gamma}^i \\frac{ \\partial y^j}{ \\partial x^i } \\frac{ \\partial }{ \\partial y^j }, \\dot{\\gamma}^k \\frac{ \\partial y^l}{ \\partial x^k} \\frac{ \\partial }{ \\partial y^l } ) \\right)^{1/2} ds = \\int_I (\\dot{\\gamma}^i \\dot{\\gamma}^k )^{1/2} \\left( \\widetilde{g}_{jl} \\frac{ \\partial y^j}{ \\partial x^i } \\frac{ \\partial y^l}{ \\partial x^i} \\right)^{1/2} ds = \\\\\n   = \\int_I ( F^* \\widetilde{g}(\\dot{\\gamma}(t), \\dot{\\gamma}(t) ) )^{1/2} dt = \\int_I (g ( \\dot{\\gamma}(t), \\dot{\\gamma}(t) ))^{1/2} = L_g(\\gamma)\n\\end{gathered}\n\\]\n\nRather, think in terms of a coordinate-free manner.\n\n\\[\n\\begin{gathered}\n  L_g(\\gamma) = \\int_a^b |\\gamma(t)|_g dt = \\int_a^b (g(\\dot{\\gamma}(t), \\dot{\\gamma}(t)) )^{1/2} dt = \\int_a^b dt ( F^*\\widetilde{g}(\\dot{\\gamma}(t), \\dot{\\gamma}(t) ) )^{1/2} = \\int_a^b dt (\\widetilde{g}(F_* \\dot{\\gamma}(t), F_* \\dot{\\gamma}(t) ))^{1/2} = \\\\\n  = \\int_a^b | \\dot{F\\gamma}(t) |_{\\widetilde{g}} dt = L_{\\widetilde{g}}(F\\gamma)\n\\end{gathered}\n\\]\n\n\n\n\n\n\n\n\\begin{proposition}[13.25] \\textbf{(Parameter independence of Length)} \\\\\nLet $(M, g)$, $\\gamma:[a,b] \\to M$ \\, piecewise smooth curve segment \\\\\nIf $\\widetilde{\\gamma}$ any reparametrization of $\\gamma$, then $L_g(\\widetilde{\\gamma}) = L_g(\\gamma)$\n\\end{proposition}\n\n\\begin{proof}\n  Suppose $\\gamma$ smooth. \\\\\n\\phantom{Suppose} $\\varphi : [c,d] \\to [a,b]$ diffeomorphism s.t. $\\widetilde{\\gamma} = \\gamma \\circ \\varphi$ \\\\\n$\\varphi$ \\emph{diffeomorphism} \\emph{implies} $\\varphi' >0$ or $\\varphi' <0$ everywhere.   \\\\\n\n(Recall diffeomorphism (cf. wikipedia) \\emph{differentiable}, bijective, inverse \\emph{differentiable}; so $DF$, Jacobian \\emph{matrix}, bijective, \n$F$ differentiable, so it can't be $0$ at any pt. (linear algebra, need $\\exists \\, $ inverse)) \\\\\n\nAssume $\\varphi' >0$\n\\[\n\\begin{gathered}\n  L_g(\\widetilde{\\gamma}) = \\int_c^d |\\widetilde{\\gamma}'(t) |_g dt = \\int_c^d \\left| \\frac{d}{dt} (\\gamma \\circ \\varphi ) \\right|_g  dt = \\int_c^d | \\gamma'(\\varphi(t)) \\dot{\\varphi} |_g dt = \\int_a^b |\\gamma'(\\varphi(t)) |_g \\dot{\\varphi} dt = \\int_a^b |\\gamma'(s)|_g = \\\\\n  = \\int_a^b |\\gamma'(s)|_g ds = L_g(\\gamma)\n\\end{gathered}\n\\]\n\nwhere second-to-last equality follows from change of variables formula for ordinary integrals.\n\n\n\n\n\\end{proof}\n\n\nIf $(M,g)$ connected Riemannian manifold \\\\\n$d_g(p,q)$ (Riemannian) distance between $p,q$ - infinum of $L_g(\\gamma)$ over all piecewise smooth curve segments $\\gamma$ from $p$ to $q$.   \\\\\n\nThe key is the following technical lemma, which shows that any Riemannian metric is locally comparable to Euclidean metric in coordinates.\n\n\\begin{lemma}[13.28] Let $g$ on open $U\\subset \\mathbb{R}^n$ \\\\\nFor compact $K \\subset U$, $\\exists \\, $ constants $c,C$ s.t. $\\begin{aligned} & \\quad \\\\\n  & \\forall \\, x \\in K \\\\\n  & \\forall \\, v\\in T_x\\mathbb{R}^n \\end{aligned}$\n\n\\[\nc|v|_{\\overline{g}} \\leq |v|_g \\leq C |v|_{\\overline{g}}\n\\]\n\n\\end{lemma}\n\n\n\n\n\n\n\n\n\n\n\\begin{theorem}[13.29] (Riemannian Manifolds as Metric Spaces)\n\nLet connected $(M,g)$ \\\\\nwith $d_g(p,q)$; $M$ metric space whose metric topology same as original manifold topology.\n\\end{theorem}\n\n\n\n\nlocal orthonormal frame $(E_1 \\dots E_n)$ for $M$ on open $U\\subset M$ is adapted to $S$ if first $k$ vectors $( \\left. E_1 \\right|_p \\dots \\left. E_k \\right|_p)$ span $T_pS \\quad \\, \\forall \\, p \\in S$. \\\\\n\\quad follows $( \\left. E_{k+1} \\right|_p \\dots \\left. E_n \\right|_p )$ span $N_pS$ \\\\\n\nProp. 11.24 proved exactly some way as counterpart for submanifolds of $\\mathbb{R}^n$ (Prop. 10.17)\n\n\\begin{proposition}[11.24] (Existence of Adapted Orthonormal Fames)\nLet $S\\subset M$ embedded Riemannian submanifold  \\\\\n\\quad $\\forall \\, p \\in S$, $\\exists \\, $ smooth adapted orthonormal frame on neighborhood $U \\ni p \\subset M$\n\\end{proposition}\n\nRecall $F:M \\to N$ immersion if $DF$ injective everywhere, $F$ embedding if $F$ injective (homeomorphism onto its image) and $F$ immersion.\n\n\nnormal bundle to $S$  \n\\[\nNS  = \\coprod_{p \\in S} N_p S\n\\]\n\n\n\n\\subsection*{The Tangent-Cotangent Isomorphism}\n\nEY 20140521, Below, in between the lines, are my notes off the previous edition.  It's frustrating to not be able to obtain instantly the most up-to-date edition automatically, online, available freely for download.  Notation had changed.  It's important to me to keep up-to-date with the latest notation; it's not trivial (cf. Zee, A.; Srednicki's QFT vs. previous QFT notation)\n\n\\hrulefill\n\nGiven $(M,g)$ define bundle map $\\widetilde{g}:TM \\to T^*M$ \\\\\n\\quad \\, $\\forall \\, p \\in M$, $\\forall \\, X_p \\in T_pM$, \\, $\\widetilde{g}(X_p) \\in T_p^*M$ be covector defined $\\widetilde{g}(X_p)(Y_p) = g_p(X_p,Y_p)$ \\quad $\\forall \\, Y_p \\in T_pM$ \\\\\n\nTo see this is a smooth bundle map, consider its action on smooth vector fields:\n\n\\[\n\\widetilde{g}(X)(Y) = g(X,Y) \\quad \\, \\forall \\, X,Y \\in \\tau(M)\n\\]\n\nBecause $\\widetilde{g}(X)(Y)$ linear over $C^{\\infty}(M)$ as a function of $Y$, \\\\\n\\quad from Prob. 6-8, $\\widetilde{g}(X)$ smooth covector field. \\\\\n\\quad because $\\widetilde{g}(X)$ linear over $C^{\\infty}(M)$ as a function of $X$, $\\widetilde{g}$ smooth bundle map by def. by Prop. 5.16. \\\\\n\nUse same symbol: pointwise bundle map $\\widetilde{g}:TM \\to T^*M$ \\\\\n\\phantom{Use same symbol:} linear map on sections $\\widetilde{g}: \\mathcal{T}(M) \\to \\mathcal{T}^*(M)$  \\\\\n\n$\\widetilde{g}$ injective: $\\widetilde{g}(X_p) = 0$ implies $0 = \\widetilde{g}(X_p)(X_p) = \\langle X_p, X_p \\rangle_g$ so $X_p =0$\n\nBy dim., $\\widetilde{g}$ bijective, so it's a bundle isomorphism (Prob. 5-9) \\\\\n\nIf $X,Y$ smooth vector fields, \n\\[\n\\begin{aligned}\n  & \\widetilde{g}(X)(Y) = g_{ij} X^i Y^j \\\\ \n  &  \\widetilde{g}(X) = g_{ij} X^i dy^j\n\\end{aligned}\n\\]\n\ncustomary to denote $X_j = g_{ij} X^i$ so $\\widetilde{g}(X) = X_j dy^j$ \\\\\n\n$\\widetilde{g}^{-1}:T_p^*M\\to T_pM$ is inverse of $(g_{ij})$ (Because $(g_{ij})$ matrix of the isomorphism $\\widetilde{g}$, it is invertible \\, $\\forall \\, p$) \\\\\n\\quad let $(g^{ij})$ inverse of $g_{ij}(p)$ so $g^{ij}g_{jk} = g_{kj} g^{ji} = \\delta^i_k$\n\nThus for covector field $\\omega \\in \\mathcal{T}^*M$, \n\\[\n\\widetilde{g}^{-1}(\\omega) = \\omega^i \\frac{ \\partial}{ \\partial x^i},  \\quad \\, \\omega^i = g^{ij} \\omega_j \n\\]\n\n$\\omega^i$ is a vector, which we visualize as a (sharp) arrow, while $X_j$ covector, which we visualize by means of its (flat) level sets.  \\\\\n\n$\\forall \\, $ smooth $f$ on $(M,g)$, \\, $f\\in \\mathbb{R}$, define vector field \\quad \\, $\\text{grad}{f} =  \\widetilde{g}^{-1}(df)$ \\\\\n\n$\\forall \\, X \\in \\mathcal{T}(M)$\n\n\\[\n\\langle \\text{grad}{f}, X\\rangle_g = \\widetilde{g} (\\text{grad}{f})(X) = df(X) = Xf\n\\]\n\nthus $\\langle \\text{grad}{f}, X\\rangle_g = Xf$ \\quad \\, $\\forall \\, X \\in \\mathcal{\\chi}(M)$ \\\\\n\\phantom{thus } or equivalently $\\langle \\text{grad}{f}, \\cdot \\rangle_g = df$\n\n\\[\n\\text{grad}{f} = g^{ij} \\frac{ \\partial f}{ \\partial x^i} \\frac{ \\partial }{ \\partial x^j}\n\\]\n\\hrulefill\n\n\nbundle isomorphism $\\widehat{g} : TM \\to T^*M$  \\\\\n\n$\\begin{aligned}\n  & \\quad \\\\ \n  & \\forall \\, p \\in M \\\\\n  & \\forall \\, v \\in T_pM \\end{aligned}$ \\quad \\quad \\, $\\begin{aligned} & \\quad \\\\ \n  & \\widehat{g}(v) \\in T_p^*M \\text{ defined by } \\\\\n  & \\widehat{g}(v)(w) = g_p(v,w) \\quad \\, \\forall \\, w \\in T_p M \\end{aligned}$\n\n\\[\n\\widehat{g}(X)(Y) = g(X,Y) \\quad \\quad \\, \\forall \\, X,Y \\in \\mathfrak{X}(M)\n\\]\n\n\n$\\widehat{g}(X)(Y)$ linear over $C^{\\infty}(M)$ as a function of $Y$, Lemma 12.24 $\\Longrightarrow \\widehat{g}(X)$ smooth covector field\n\n$g=g_{ij}dx^i dx^j$ \n\n\\[\n\\widehat{g}(X)(Y) = g_{ij}X^i Y^j \\Longrightarrow \\widehat{g}(X) = g_{ij}X^i dx^j = X_j dx^j \\text{ where } X_j = g_{ij}X^i\n\\]\n\n$X^{\\flat} = \\widehat{g}(X)$\n\n\nNow\n\\[\n\\widehat{g}^{-1}:T_p^*M \\to T_pM\n\\]\n$\\forall \\, $ covector field $\\omega \\in \\mathfrak{X}^*(M)$\n\n\\[\n\\widehat{g}^{-1}(\\omega) = \\omega^i \\frac{ \\partial x^i}, \\quad \\, \\omega^i = g^{ij}\\omega_j\n\\]\n\n$omega^{\\sharp} = \\widehat{g}^{-1}(\\omega)$\n\n\ngradient of $f$ by $\\text{grad}{f} = (df)^{\\sharp} = \\widehat{g}^{-1}(df)$\n\n$\\forall \\, X \\in \\mathfrak{X}(M)$\n\n\\[\n\\langle \\text{grad}f, X\\rangle_g = \\widehat{g}(\\text{grad}f)(X) = df(X) =Xf\n\\]\n\nor\n\n$\\langle \\text{grad}f, \\cdot \\rangle_g = df$\n\n$\\text{grad}f = g^{ij} \\frac{ \\partial f}{ \\partial x^i} \\frac{ \\partial }{ \\partial x^j}$ \\quad \\, so $\\text{grad}f$ is smooth\n\n\n\n\n\\subsection*{ Problems }\n\n\n\n\\problemhead{11-1} Recall $\\forall $ bilinear $A : V\\times W \\to Y$, $\\exists \\, !$ \\, linear $\\widetilde{A} : Z \\to Y$ s.t. \n\n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=2em, column sep=3em, minimum width=1em]\n  {\n    V\\times W  & Z  \\\\\n    V\\otimes W  &   \\\\ };\n  \\path[-stealth]\n  (m-1-1) edge node [right] {$\\widetilde{\\pi}$} (m-1-2)\n  edge node [left] { $\\otimes$} (m-2-1)\n  (m-2-1) edge node [below] {$\\exists \\, ! \\, \\pi$} (m-1-2);\n\\end{tikzpicture} \n\nis the universal property s.t. $\\pi \\otimes = \\widetilde{\\pi}$\n\nSuppose bilinear $\\widetilde{\\pi} : V\\times W \\to Z$ s.t., \\\\\n\\quad \\, $\\forall \\, $ bilinear $A: V\\times W \\to Y$, $\\exists \\, !$ linear $\\widetilde{A} : Z \\to Y$ s.t. \n\n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=2em, column sep=3em, minimum width=1em]\n  {\n    V\\times W  & Y  \\\\\n    Z  &   \\\\ };\n  \\path[-stealth]\n  (m-1-1) edge node [auto] {$A$} (m-1-2)\n  edge node [left] { $\\widetilde{Z}$} (m-2-1)\n  (m-2-1) edge node [below] {$\\widetilde{A}$} (m-1-2);\n\\end{tikzpicture} \n\nConsider \n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=2em, column sep=3em, minimum width=1em]\n  {\n    V\\times W  & Z  \\\\\n    V\\otimes W  &   \\\\ };\n  \\path[->,font=\\scriptsize]\n  (m-1-1) edge node [auto] {$\\widetilde{\\pi}$} (m-1-2)\n  edge node [left] { $\\otimes$} (m-2-1)\n  (m-1-2) edge node [above] {$\\lambda$} (m-2-1)\n  (m-2-1.2) edge node [below] {$\\widetilde{\\Phi}$} (m-1-2.south east);\n\\end{tikzpicture} \n\n$\\Phi \\otimes = \\widetilde{\\pi}$ (by universal property) \\\\\n\\[\n\\Phi(v\\otimes w) = \\widetilde{\\pi}(v,w)\n\\]\n$\\exists \\, ! $ linear $\\lambda : Z \\to V\\otimes W$ \n\\[\n\\begin{aligned}\n  & \\lambda \\circ \\widetilde{\\pi} = \\otimes \\\\  \n  & \\lambda \\otimes \\widetilde{\\pi}(v,w) = v\\otimes w\n\\end{aligned}\n\\]\n\n\\[\n\\begin{aligned}\n  & \\Phi \\lambda ( \\widetilde{\\pi}(v,w) ) = \\Phi(v\\otimes w) = \\widetilde{\\pi}(v,w) \\\\ \n  & \\Phi \\lambda = \\text{id}_{Z} \\\\ \n  & \\lambda \\Phi(v\\otimes w) = \\lambda \\widetilde{\\pi}(v,w) = v\\otimes w \\\\ \n  & \\lambda \\Phi = \\text{id}_{V\\otimes W}\n\\end{aligned}\n\\]\nSo $\\Phi$ is an isomorphism between $Z, V\\otimes W$.  As $\\lambda $ is unique, so is $\\Phi$\n\n\n\n\\problemhead{11-2}\n\ntensor product of $U,V$ is vector space $U\\otimes V$ with bilinear map $\\begin{aligned} & \\quad \\\\ \n  \\otimes : & U \\times V \\to U\\otimes V \\\\ \n  & (u,v) \\mapsto u\\otimes v \\end{aligned}$ \\\\\nwith universal property with any vector space $W$.  \n\n$K \\cong k 1$ \n\nBy bilinearity, \n\n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=2em, column sep=3em]\n  {\n    U \\otimes K  & U\\otimes 1 & U  \\\\\n    u\\otimes k  & ku \\otimes 1 & ku   \\\\ };\n  \\path[->]\n  (m-1-1) edge node [auto] {$$} (m-1-2)\n  (m-1-2) edge node [left] { $$} (m-1-3);\n  \\path[|->]\n  (m-2-1) edge node [auto] {$$} (m-2-2)\n  (m-2-2) edge node [above] {$$} (m-2-3);\n  \\path[|->]\n  (m-2-3) edge node [bend right] {$q$} (m-2-2);\n\\end{tikzpicture} \n\n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=2em, column sep=3em]\n  {\n    u\\otimes k  & ku \\otimes 1 & ku   \\\\ };\n%  \\path[->]\n%  (m-1-1) edge node [auto] {$$} (m-1-2)\n%  (m-1-2) edge node [left] { $$} (m-1-3)\n  \\path[|->]\n  (m-1-1) edge  (m-1-2)\n  (m-1-2) edge  (m-1-3)\n%  \\path[|->]\n  (m-1-3) edge node [bend left] {$q$} (m-1-2);\n\\end{tikzpicture} \n\n$q: U \\to U\\otimes 1$ \\\\\n$u \\mapsto u\\otimes 1$\n\nthen $U\\otimes K \\simeq U$\n\n\n\\problemhead{11-3} $\\begin{aligned} & \\quad \\\\\n  & U^* \\times V \\to \\text{Hom}{(U,V)} \\\\\n  & (u^*, v) \\to ( u \\to u^*(u), v) \\end{aligned}$ induces a natural homomorphism (injective), $U^* \\otimes V \\to \\text{Hom}{(U,V)}$ \n\\begin{tikzpicture}\n  \\matrix (m) [matrix of math nodes, row sep=2em, column sep=3em]\n  {\n    U^* \\otimes V  & \\text{Hom}{(U,V)}    \\\\ };\n%  \\path[->]\n%  (m-1-1) edge node [auto] {$$} (m-1-2)\n%  (m-1-2) edge node [left] { $$} (m-1-3)\n  \\path[->]\n  (m-1-1) edge  (m-1-2)\n    edge node [auto] {$\\otimes$} (m-2-1);\n%  \\path[|->]\n    \\path[dotted,->] \n  (m-2-1) edge  (m-1-2);\n\\end{tikzpicture} \n\nIf $\\text{dim}{U}, \\, \\text{dim}{V} < \\infty$, \n\nfor arbitrary $v_i \\in V$, \\, $\\begin{aligned} & \\quad \\\\\n  & \\sum_i e_i^* \\otimes v_i \\in U^* \\otimes V \\\\\n  & e_j \\to e_i^*(e_j)v_i = v_j \\end{aligned}$ \n\n$\\sum_i e_i^* \\otimes v_i$ corresponds to homomorphism $U\\to V$ mapping $e_i \\to v_i$ \n\n$U^* \\otimes V \\to \\text{Hom}{(U,V)}$ surjective.  \n\n$\\text{dim}{U^* \\otimes V} = \\text{dim}{U^*} \\text{dim}{V}$\n\nisomorphism by dim. reason. \n\n", "meta": {"hexsha": "709f71a9eaf11cd81463d122e1d63cb953911dcb", "size": 23948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LeeJM/13riemannianmetrics.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/13riemannianmetrics.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/13riemannianmetrics.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": 37.4773082942, "max_line_length": 543, "alphanum_fraction": 0.5889427092, "num_tokens": 9290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6505097634423789}}
{"text": "\\subsection{Randomly Created Point Cloud}\n\\subsubsection{Description of the Algorithm}\nThe algorithm creates a point cloud where the x and y values for every point\nwhere calculated by a random function.\n\n\\subsubsection{Implementation description}\nThe implementation uses the std::uniform\\_real\\_distribution function from the\nc++ standard. It creates values from 0 to width and 0 to height.\n\n\\subsubsection{Complexity}\nThe complexity is $\\bigO(n)$ where $n$ is the number of point count.\n\n\\subsubsection{Parameters}\n\\begin{description}\n  \\item [--nodes] how many nodes the polygon has to have. [default: 100]\n  \\item [--sampling-grid] the area within the polygon could grow. [default: 1500x800]\n\\end{description}\n\n\n\\subsubsection{Examples}\n\\begin{figure}[ht]\n  \\centering\n\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(18, 7),(1, 39),(77, 48),(56, 13),(77, 51),(56, 27),(61, 9),(56, 12),(69, 63),(45, 53)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (1) -- (2) -- (3) -- (4) -- (5) -- (6) -- (7) -- (8) -- (9) -- (10)\n      -- (1);\n    \\end{tikzpicture}\n    \\caption{Example point cloud used as a polygon with 10 points}\n    \\label{fig:rcpc:points-10}\n  \\end{minipage}\\hfill\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(70,60), (33,70), (33,10), (70, 20), (0,40)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (1) -- (2) -- (3) -- (4) -- (5) -- (1);\n    \\end{tikzpicture}\n    \\caption{Example point cloud used as a polygon with 5 points}\n    \\label{fig:rcpc:points-2}\n  \\end{minipage}\n\\end{figure}\n\n\\FloatBarrier\n", "meta": {"hexsha": "3249d68950b2007b85bebcd927e54c908a734e99", "size": 1988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/randomly_created_point_cloud.tex", "max_stars_repo_name": "utnapischtim/polygon", "max_stars_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/randomly_created_point_cloud.tex", "max_issues_repo_name": "utnapischtim/polygon", "max_issues_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/randomly_created_point_cloud.tex", "max_forks_repo_name": "utnapischtim/polygon", "max_forks_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.0625, "max_line_length": 111, "alphanum_fraction": 0.6011066398, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8175744850834649, "lm_q1q2_score": 0.6505097614616212}}
{"text": "\\documentclass[12pt,twoside]{article}\n\\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}\n\\usepackage{hyperref}\n\\usepackage{fontspec}\n\\usepackage{tikz}\n\n\\title{The Most Beautiful Math Equations}\n\\author{KaiserKatze}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Euler's identity}\n\n$$ e^{i \\pi} + 1 = 0 $$\n\n\\section{Pythagorean theorem}\n\n$$ a^2 + b^2 = c^2 $$\n\n\\section{Quaternion}\n\n$$ i^2 = j^2 = k^2 = ijk = -1 $$\n\n\\section{Euler characteristic}\n\n$$ V - E + F = 2 $$\n\n\\section{Multinomial theorem}\n\n$$ (x_1+x_2+\\cdots+x_t)^n=\\sum\\frac{n!}{n_1!n_2!\\cdots n_t!}x_1^{n_1}x_2^{n_2}\\cdots x_t^{n_t} $$\n\n\\section{Bayes' theorem}\n\n$$ P\\left(A|B\\right) = \\frac{P\\left(A\\right)P\\left(B|A\\right)}{P\\left(B\\right)} $$\n\nFin.\n\n\\end{document}\n\n\\begin{tikzpicture}[remember picture,overlay]\n   \\node[xshift=1mm,yshift=1mm,anchor=north west] at (current page.north west){%\n   \\includegraphics[width=50mm]{FreeCulturalWorks_seal_x2.jpg}};\n\\end{tikzpicture}\n", "meta": {"hexsha": "3b9ac33b215f680246bcdd2ffc4671bb8bcece8e", "size": 965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "donizyo/LaTeX-Travis", "max_stars_repo_head_hexsha": "81d0485078f9d12762c691284dffdae8c40643d3", "max_stars_repo_licenses": ["MIT"], "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": "donizyo/LaTeX-Travis", "max_issues_repo_head_hexsha": "81d0485078f9d12762c691284dffdae8c40643d3", "max_issues_repo_licenses": ["MIT"], "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": "donizyo/LaTeX-Travis", "max_forks_repo_head_hexsha": "81d0485078f9d12762c691284dffdae8c40643d3", "max_forks_repo_licenses": ["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.9782608696, "max_line_length": 97, "alphanum_fraction": 0.6922279793, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6505044997223478}}
{"text": "\\title{Automated Transformations}\n\n\\subsection{Automated Transformations}\n\nAutomated transformations provide convenient handling of constrained\ncontinuous variables during inference by transforming them to an\nunconstrained space. Automated transformations are crucial for\nexpanding the scope of algorithm classes such as gradient-based Monte\nCarlo and variational inference with reparameterization gradients.\n\nA Jupyter notebook version of this tutorial is available\n\\href{http://nbviewer.jupyter.org/github/blei-lab/edward/blob/master/notebooks/automated_transformations.ipynb}{here}.\n\n\\subsubsection{The Transform Primitive}\n\nAutomated transformations in Edward are enabled through the key\nprimitive\n\\href{/api/ed/transform}{\\texttt{ed.transform}}.\nIt takes as input a (possibly constrained) continuous random variable\n$\\mathbf{x}$, defaults to a choice of transformation $T$, and returns a\n\\href{/api/ed/models/TransformedDistribution}\n{\\texttt{TransformedDistribution}}\n$\\mathbf{y}=T(\\mathbf{x})$ with unconstrained support.\nAn optional argument allows you to manually specify the transformation.\n\nThe returned random variable $\\mathbf{y}$'s density is the original\nrandom variable $\\mathbf{x}$'s density adjusted by the determinant of\nthe Jacobian of the inverse transformation \\citep{casella2002statistical},\n\n$$p(\\mathbf{y}) = p(\\mathbf{x})~|\\mathrm{det}~J_{T^{-1}}(\\mathbf{y}) |.$$\n\nIntuitively, the Jacobian describes how a transformation warps unit\nvolumes across spaces. This matters for transformations of random\nvariables, since probability density functions must always integrate\nto one.\n\n\\subsubsection{Automated Transformations in Inference}\n\nTo use automated transformations during inference, set the flag\nargument \\texttt{auto\\_transform=True} in \\texttt{inference.initialize}\n(or the all-encompassing method \\texttt{inference.run}):\n\n\\begin{lstlisting}[language=Python]\ninference.initialize(auto_transform=True)\n\\end{lstlisting}\n\nBy default, the flag is already set to \\texttt{True}.\nWith this flag, any key-value pair passed into inference's\n\\texttt{latent\\_vars} with unequal support is transformed to the\nunconstrained space; no transformation is applied if already\nunconstrained. The algorithm is then run under\n\\texttt{inference.latent\\_vars}, which explicitly stores the\ntransformed latent variables and forgets the constrained ones.\n\nWe illustrate automated transformations in a few inference examples.\nImagine that the target distribution is a Gamma distribution.\n\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Gamma\n\nx = Gamma(1.0, 2.0)\n\\end{lstlisting}\n\nThis example is only used for illustration, but note this context of\ninference with latent variables of non-negative support occur\nfrequently: for example, this appears when applying topic models with a deep exponential\nfamily where we might use a normal variational\napproximation to implicitly approximate latent variables with Gamma\npriors (in\n\\href{https://github.com/blei-lab/edward/blob/master/examples/deep_exponential_family.py}\n{\\texttt{examples/deep\\_exponential\\_family.py}},\nwe explicitly define a non-negative variational approximation).\n\n\\textbf{Variational inference.}\nConsider a Normal variational approximation\nand use the algorithm \\href{/api/ed/KLqp}{\\texttt{ed.KLqp}}.\n\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Normal\n\nqx = Normal(loc=tf.get_variable(\"qx/loc\", []),\n            scale=tf.nn.softplus(tf.get_variable(\"qx/scale\", [])))\n\ninference = ed.KLqp({x: qx})\ninference.run()\n\\end{lstlisting}\n\nThe Gamma and Normal distribution have unequal support, so inference\ntransforms both to the unconstrained space; normal is already\nunconstrained so only Gamma is transformed. \\texttt{ed.KLqp} then\noptimizes with\n\\href{/api/klqp}{reparameterization gradients}.\nThis means the Normal distribution's parameters are optimized to match\nthe transformed (unconstrained) Gamma distribution.\n\nOftentimes we'd like the approximation on the original (constrained)\nspace. This was never needed for inference, so we must explicitly\nbuild it by first obtaining the target distribution's transformation\nand then inverting the transformation:\n\n\\begin{lstlisting}[language=Python]\nfrom tensorflow.contrib.distributions import bijectors\n\nx_unconstrained = inference.transformations[x]  # transformed prior\nx_transform = x_unconstrained.bijector  # transformed prior's transformation\nqx_constrained = ed.transform(qx, bijectors.Invert(x_transform))\n\\end{lstlisting}\n\nThe set of transformations is given by\n\\texttt{inference.transformations}, which is a dictionary with keys\ngiven by any constrained latent variables and values given by their\ntransformed distribution. We use the\n\\href{https://www.tensorflow.org/versions/master/api_docs/python/tf/distributions/bijectors}{\\texttt{bijectors}}\nmodule in \\texttt{tf.distributions} in order to handle invertible\ntransformations.\n\n\\texttt{qx\\_unconstrained} is a random variable distributed\naccording to a inverse-transformed (constrained) normal distribution.\nFor example, if the automated transformation from non-negative to\nreals is $\\log$, then the constrained approximation is a LogNormal\ndistribution; here, the default transformation is the inverse of\n$\\textrm{softplus}$.\n\nWe can visualize the densities of the distributions.\nThe figure below shows that the inverse-transformed normal\ndistribution has lighter tails than the Gamma but is overall a\ngood fit.\n\n\\begin{lstlisting}[language=Python]\nsns.distplot(x.sample(50000).eval(), hist=False, label='x')\nsns.distplot(qx_constrained.sample(100000).eval(), hist=False, label='qx')\n\\end{lstlisting}\n\n\\includegraphics[width=600px]{/images/automated-transformations-0.png}\n\n\\textbf{Gradient-based Monte Carlo.}\nConsider an Empirical approximation with 1000 samples\nand use the algorithm \\href{/api/ed/HMC}{\\texttt{ed.HMC}}.\n\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Empirical\n\nqx = Empirical(params=tf.get_variable(\"qx/params\", [1000]))\n\ninference = ed.HMC({x: qx})\ninference.run(step_size=0.8)\n\\end{lstlisting}\n\nGamma and Empirical have unequal support so Gamma is transformed to\nthe unconstrained space; by implementation, discrete delta\ndistributions such as Empirical and PointMass are not transformed.\n\\texttt{ed.HMC} then simulates Hamiltonian\ndynamics and writes the unconstrained samples to the empirical\ndistribution.\n\nIn order to obtain the approximation on the original (constrained)\nsupport, we again take the inverse of the target distribution's\ntransformation.\n\n\\begin{lstlisting}[language=Python]\nfrom tensorflow.contrib.distributions import bijectors\n\nx_unconstrained = inference.transformations[x]  # transformed prior\nx_transform = x_unconstrained.bijector  # transformed prior's transformation\nqx_constrained = Empirical(params=x_transform.inverse(qx.params))\n\\end{lstlisting}\n\nUnlike variational inference, we don't use \\texttt{ed.transform} to\nobtain the constrained approximation, as it only applies to continuous\ndistributions. Instead, we define a new Empirical distribution whose\nparameters (samples) are given by transforming all samples stored in\nthe unconstrained approximation.\n\nWe can visualize the densities of the distributions.\nThe figure below indicates that the samples accurately fit the Gamma\ndistribution up to simulation error.\n\n\\begin{lstlisting}[language=Python]\nsns.distplot(x.sample(50000).eval(), hist=False, label='x')\nsns.distplot(qx_constrained.sample(100000).eval(), hist=False, label='qx')\n\\end{lstlisting}\n\n\\includegraphics[width=600px]{/images/automated-transformations-1.png}\n\n\\subsubsection{Acknowledgements \\& Remarks}\n\nAutomated transformations have largely been popularized by Stan\nfor Hamiltonian Monte Carlo \\citep{carpenter2016stan}.\nThis design is inspired by Stan's. However, a key distinction is that Edward\nprovides users the ability to wield transformations and more flexibly\nmanipulate results in both the original (constrained) and inferred\n(unconstrained) space.\n\nAutomated transformations are also core to the algorithm automatic\ndifferentiation variational inference \\citep{kucukelbir2017automatic},\nwhich allows it to select a default variational family of normal\ndistributions. However, note the automated transformation from\nnon-negative to reals in Edward is not $\\log$, which is used in Stan;\nrather, Edward uses $\\textrm{softplus}$ which is more numerically\nstable (see also \\citet[Fig.~9]{kucukelbir2017automatic}).\n\nFinally, note that not all inference algorithms use or even need\nautomated transformations.\n\\href{/api/ed/Gibbs}{\\texttt{ed.Gibbs}}, moment\nmatching with EP using Edward's conjugacy, and\n\\href{/api/ed/KLqp}{\\texttt{ed.KLqp}}\nwith\nscore function gradients all perform inference on the original latent\nvariable space.\nPoint estimation such as \\href{/api/ed/MAP}{\\texttt{ed.MAP}} also\nuse the original latent variable space and only requires a\nconstrained transformation on unconstrained free parameters.\nModel parameter estimation such as\n\\href{/api/ed/GANInference}{\\texttt{ed.GANInference}} do not even\nperform inference over latent variables.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "d91aa1c047e3e1ec5c8723f67c0d45e5505d80b4", "size": 9120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/automated-transformations.tex", "max_stars_repo_name": "skylogic004/edward", "max_stars_repo_head_hexsha": "1864ee832ab4bbf7b35e81c1fdec6e67c7b135c0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-07-18T06:01:03.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-18T06:01:03.000Z", "max_issues_repo_path": "docs/tex/tutorials/automated-transformations.tex", "max_issues_repo_name": "skylogic004/edward", "max_issues_repo_head_hexsha": "1864ee832ab4bbf7b35e81c1fdec6e67c7b135c0", "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/automated-transformations.tex", "max_forks_repo_name": "skylogic004/edward", "max_forks_repo_head_hexsha": "1864ee832ab4bbf7b35e81c1fdec6e67c7b135c0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-23T06:00:42.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-23T06:00:42.000Z", "avg_line_length": 41.8348623853, "max_line_length": 118, "alphanum_fraction": 0.8092105263, "num_tokens": 2117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6505044856882664}}
{"text": "%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\input{../../doc/related_pages/header.tex}\r\n\\input{../../doc/related_pages/newcommands.tex}\r\n\\usepackage{minted}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{document}\r\n\r\n\\title{Testing Advection Schemes}\r\n\\author{ M.~Wiesenberger}\r\n\\maketitle\r\n\r\n\\begin{abstract}\r\n  This is a program to test various advection schemes on the 2d incompressible Euler\r\n  equation used in Reference~\\cite{Einkemmer2014}.\r\n\\end{abstract}\r\n\r\n\\section{Equations}\r\nWe implement the 2d incompressible Euler equation\r\n\\begin{subequations}\r\n\\begin{align}\r\n \\frac{\\partial \\omega}{\\partial t} + \\{ \\phi, \\omega\\} = 0 \\\\\r\n -\\Delta \\phi = \\omega \\label{eq:euler_poisson_elliptic}\r\n\\end{align}\r\n\\label{eq:euler_poisson}\r\n\\end{subequations}\r\nwith vorticity $\\omega$ and stream-function $\\phi$.\r\nThe Poisson bracket is given by $\\{ \\phi, \\omega\\} := \\phi_x \\omega_y - \\phi_y \\omega_x$.\r\nEq.~\\eqref{eq:euler_poisson} is a reformulation of the standard conservative form\r\n\\begin{subequations}\r\n\\begin{align}\r\n    \\frac{\\partial \\omega}{\\partial t} + \\nabla\\cdot({\\vec v \\omega}) = 0 \\\\\r\n\\nabla\\cdot\\vec v = 0 \\quad \\omega = -(\\nabla\\times \\vec v)\\cdot \\zhat\r\n\\end{align}\r\n\\label{eq:euler_conservative}\r\n\\end{subequations}\r\nwith $v_x = - \\phi_y$ and $v_y = \\phi_x$\r\nor since the divergence of $\\vec v$ is $0$, $\\nc \\vec v = 0$ we have the advection form\r\n\\begin{subequations}\r\n\\begin{align}\r\n    \\frac{\\partial \\omega}{\\partial t} + \\vec v\\cn \\omega = 0 \\\\\r\n    -\\Delta\\phi = \\omega \\quad v_x = -\\phi_y \\quad v_y = \\phi_x\r\n\\end{align}\r\n\\label{eq:euler_advection}\r\n\\end{subequations}\r\n\r\nEqs.~\\eqref{eq:euler_poisson} have an infinite amount of conserved quantities\r\namong them the total vorticity $V$, the kinetic energy $E$ and the enstrophy $\\Omega$\r\n \\begin{align}\r\n     V := \\int_D \\omega \\dA\\quad\r\n     E :=\\frac{1}{2} \\int_D \\left( \\nabla \\phi\\right)^2 \\dA \\quad\r\n     \\Omega:= \\frac{1}{2} \\int_D \\omega^2 \\dA\r\n \\end{align}\r\n\r\n\r\n\\section{Initialization}\r\nInput file format: \\href{https://en.wikipedia.org/wiki/JSON}{json} \\\\\r\nWe will consider several different initial conditions in order to test\r\nour numerical methods\r\n\\subsection{Lamb Dipole}\r\nThe Lamb dipole is a stationary solution to the Euler equations~\\cite{Nielsen1997} with infinite\r\nboundary conditions\r\n\\begin{align}\r\n    \\omega(x,y,0) = \\begin{cases}\r\n        \\frac{2\\lambda U}{J_0(\\lambda R)} J_1(\\lambda R) \\cos \\theta,\\ r < R,\\\\\r\n        0, \\text{ else}\r\n    \\end{cases}\r\n\\end{align}\r\nUnfortunately, for a finite box this is not an exact solution any more.\r\non the domain $[0,1]\\times [0,1]$.\r\nThe Lamb dipole is chosen with the following parameters in the input file\r\n\\begin{minted}[texcomments]{js}\r\n\"grid\" :\r\n{\r\n    \"x\" : [0.0,1.0], // Choose x box boundaries appropriately\r\n    \"y\" : [0.0,1.0], // Choose y box boundaries appropriately\r\n    \"bc\" : [\"DIR\", \"PER\"] // Choose boundary conditions [x,y] appropriately\r\n}\r\n\"init\" :\r\n{\r\n    \"type\"      : \"lamb\", // This choice necessitates the following parameters\r\n    \"velocity\"  : 1.0,  //  blob speed $U$\r\n    \"sigma\"     : 0.1,  // dipole radius in units of $l_x$\r\n    \"posX\"      : 0.5,  // in units of $l_x$\r\n    \"posY\"      : 0.8  // in units of $l_y$\r\n}\r\n\\end{minted}\r\n\\subsection{Manufactured Solution}\r\nWe manufacture a solution via\r\n\\begin{align}\r\n    \\phi(x,y,t) &=\r\n    x \\exp\\left( - \\frac{ x^2 + (y+vt)^2}{\\sigma^2}\\right) \\\\\r\n    \\omega(x,y,t) &= -\\Delta \\phi = -\\sigma^{-4} \\left[ 4\\phi(x,y,t) ( x^2-2\\sigma^2  + (y+tv)^2)\\right]\r\n\\end{align}\r\nwhich is solution to the modified equations\r\n\\begin{subequations}\r\n\\begin{align}\r\n    \\frac{\\partial \\omega}{\\partial t} + \\{ \\phi, \\omega\\} = S(x,y,t) \\\\\r\n    -\\Delta \\phi = \\omega\r\n\\end{align}\r\n\\label{eq:euler_poisson_modified}\r\n\\end{subequations}\r\nwith the source\r\n\\begin{align}\r\n    S(x,y,t) =& 8 x \\sigma^{-6}(y+vt)\\exp\\left( - 2\\frac{ x^2 + (y+vt)^2}{\\sigma^2} \\right) \\nonumber\\\\\r\n    &\\left(-\\sigma^2  + \\exp\\left( \\frac{ x^2 + (y+vt)^2}{\\sigma^2} \\right) v( -3\\sigma^2 + x^2 + (y+vt)^2) \\right)\r\n\\end{align}\r\non the domain $[-1,1]\\times [-1,1]$.\r\n\r\nThe manufactured solution is chosen with the following parameters in the input file\r\n\\begin{minted}[texcomments]{js}\r\n\"grid\" :\r\n{\r\n    \"x\" : [-1.0,1.0], // Choose x box boundaries appropriately\r\n    \"y\" : [-1.0,1.0], // Choose y box boundaries appropriately\r\n    \"bc\" : [\"DIR\", \"PER\"] // Choose boundary conditions [x,y] appropriately\r\n}\r\n\"init\" :\r\n{\r\n    \"type\"      : \"mms\", // This choice necessitates the following parameters\r\n    \"velocity\"  : 1.0, //  blob speed $v$\r\n    \"sigma\"     : 0.2  // the width $\\sigma$\r\n}\r\n\\end{minted}\r\n\\subsection{Simple sine function}\r\nA simple sine function is given by\r\n\\begin{align}\r\n    \\omega(x,y,0) = 2 \\sin(x)\\sin(y)\r\n\\end{align}\r\nwhich has an analytical solution\r\n\\begin{align}\r\n\\omega(x,y,t) = 2 \\sin(x)\\sin(y)\\exp( -(2\\nu)^s t)\r\n\\end{align}\r\nif there is artificial viscosity and is invariant else.\r\non the domain $[0,2\\pi]\\times [0,2\\pi]$.\r\nThis solution is chosen with the following parameters in the input file\r\n\\begin{minted}[texcomments]{js}\r\n\"grid\" :\r\n{\r\n    \"x\" : [0.0, 6.283185307179586], // Choose x box boundaries appropriately\r\n    \"y\" : [0.0, 6.283185307179586], // Choose y box boundaries appropriately\r\n    \"bc\" : [\"DIR\", \"PER\"] // Choose boundary conditions [x,y] appropriately\r\n}\r\n\"init\" :\r\n{\r\n    \"type\"      : \"sine\" // No other parameters are necessary\r\n}\r\n\\end{minted}\r\n\r\n\\subsection{ Double Shear layer}\r\nHere, we follow~\\cite{Liu2000} and test the scheme on a double shear layer problem.\r\n\\begin{align}\r\n    \\omega(x,y,0) = \\begin{cases}\r\n        \\delta \\cos(x) - \\frac{1}{\\rho} \\text{sech}^2 \\left(\\frac{y-\\pi/2}{\\rho}\\right),\\ y \\leq \\pi \\\\\r\n        \\delta \\cos(x) + \\frac{1}{\\rho} \\text{sech}^2 \\left(\\frac{3\\pi/2-y}{\\rho}\\right),\\ y > \\pi \\\\\r\n    \\end{cases}\r\n\\end{align}\r\nwhere $\\rho = \\pi/15$ and $\\delta =0.05$ on the domain $[0,2\\pi]\\times [0,2\\pi]$.\r\nThis solution will quickly roll-up and generate smaller and smaller scales.\r\nA thin shear layer corresponds to $\\rho = \\pi/50$ or smaller.\r\nThe double shear layer initialization is chosen with the following parameters in the input file\r\n\\begin{minted}[texcomments]{js}\r\n\"grid\" :\r\n{\r\n    \"x\"  : [0.0, 6.283185307179586], // Choose x box boundaries appropriately\r\n    \"y\"  : [0.0, 6.283185307179586], // Choose y box boundaries appropriately\r\n    \"bc\" : [\"PER\", \"DIR\"] // Choose boundary conditions [x,y] appropriately\r\n}\r\n\"init\" :\r\n{\r\n    \"type\"  : \"shear\", // This choice necessitates the following parameters\r\n    \"rho\"   : 0.20943951023931953, // The width $\\rho = \\pi/15$ \\\\\r\n    \"delta\" : 0.05 // The velocity $v$ \\\\\r\n}\r\n\\end{minted}\r\n\r\n\\section{Numerical methods}\r\nOur goal is to try out various time integration and advection discretization techniques.\r\nWe know from Godunov's theorem\r\nthat any linear advection scheme of order 2 or higher is prone to oscillations.\r\n\\subsection{Spatial grid}\r\nThe spatial grid is a two-dimensional Cartesian product-grid adaptable with the following parameters\r\n\\begin{minted}[texcomments]{js}\r\n\"grid\" :\r\n{\r\n    \"n\"  :  3, // The number of polynomial coefficients\r\n    \"Nx\"  : 48, // Number of cells in x\r\n    \"Ny\"  : 48, // Number of cells in y\r\n    \"x\"  : [0.0,1.0], // Boundaries in x\r\n    \"y\"  : [0.0,1.0], // Boundaries in y\r\n    \"bc\" : [\"DIR\", \"PER\"] // Boundary conditions in [x,y]\r\n}\r\n\\end{minted}\r\n\\subsection{Time steppers}\r\nPossible time-steppers are the explicit and semi-implicit multistep schemes\r\nas well as the Shu-Osher scheme that originally incorporated limiters in the dG scheme.\r\n\\begin{minted}[texcomments]{js}\r\n\"timestepper\" :\r\n{\r\n    // The semi-implicit multistep scheme (only in combination with\r\n    // viscosity regularization)\r\n    \"type\"     : \"ImExMultistep\",\r\n    \"tableau\"  : \"ImEx-BDF-3-3\", //  Any ImEx tableau *\r\n    \"dt\"       : 2e-3, // Fixed timestep\r\n    \"eps_time\" : 1e-9 // Accuracy requirement for implicit solver\r\n},\r\n\"timestepper\":\r\n{\r\n    // An explicit Runge Kutta method with filter (viscosity is treated\r\n    // explicitly)\r\n    \"type\"      : \"Shu-Osher\",\r\n    \"tableau\"   : \"SSPRK-3-3\", // Any Shu-Osher tableau *\r\n    \"dt\"        : 1e-3 // Fixed Time-step\r\n},\r\n\"timestepper\",\r\n{\r\n    // an explicit multistep class with the option to use a filter (viscosity\r\n    // is treated explicitly)\r\n    \"type\"      : \"FilteredExplicitMultistep\"\r\n    \"tableau\"   : \"eBDF-3-3\" // Any explicit multistep tableau *\r\n    \"dt\"        : 2e-3 // Fixed timestep\r\n},\r\n\\end{minted}\r\n*See the dg documentation for what tableaus are available.\r\n\\subsection{Regularization technique}\r\nChoose either no regularization or artificial viscosity or modal filtering by the following\r\nparameters in the input file.\r\n\r\nFor no regularization choose\r\n\\begin{minted}[texcomments]{js}\r\n\"regularization\",\r\n{\r\n    \"type\" : \"none\" //No regularization\r\n}\r\n\\end{minted}\r\n\r\nFor artificial viscosity Eqs.~\\eqref{eq:euler_poisson} are modified to\r\n\\begin{subequations}\r\n\\begin{align}\r\n    \\frac{\\partial \\omega}{\\partial t} + \\{ \\phi, \\omega\\} = -(-\\nu \\Delta)^s \\omega\\\\\r\n -\\Delta \\phi = \\omega\r\n\\end{align}\r\n\\label{eq:euler_poisson_viscous}\r\n\\end{subequations}\r\nwhere $\\nu$ is the viscosity coefficient and $s=1,2,3,\\cdots$ is the order\r\n\\begin{minted}[texcomments]{js}\r\n\"regularization\",\r\n{\r\n    \"type\"      : \"viscosity\", // Artificial viscosity\r\n    \"order\"     : 2 , // Order: 1 is normal diffusion, 2 is hyperdiffusion, can be\r\n    // arbitrarily high, but higher orders might take longer to solve or restrict\r\n    // the CFL condition\r\n    \"nu\"        : 1e-3, // Viscosity coefficient\r\n    \"direction\" : \"centered\" //Direction of Laplacian: forward or centered\r\n}\r\n\\end{minted}\r\nThe other regularization method is the modal filter that applies an exponential filter\r\n\\begin{align}\r\n    \\begin{cases}\r\n    1 \\text{ if } \\eta < \\eta_c \\\\\r\n    \\exp\\left( -\\alpha  \\left(\\frac{\\eta-\\eta_c}{1-\\eta_c} \\right)^{2s}\\right) \\text { if } \\eta \\geq \\eta_c \\\\\r\n    0 \\text{ else} \\\\\r\n    \\eta := \\frac{i}{n-1}\r\n    \\end{cases}\r\n\\end{align}\r\nand is choosable with the following parameters\r\n\\begin{minted}[texcomments]{js}\r\n\"regularization\",\r\n{\r\n    \"type\"  : \"modal\", // Not choosable for \\textbf{ImExMultistep} timestepper\r\n    \"order\" : 8,  // Order: normally 8 or 16\r\n    \"eta_c\" : 0.5, // cutoff wavelength below which no damping is applied\r\n    \"alpha\" : 36.0 // damping coefficient determining damping for highest\r\n    //wavenumber\r\n}\r\n\\end{minted}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Elliptic solver}\r\nCurrently, the multigrid solver is the only one choosable\r\nto solve Eq.~\\eqref{eq:euler_poisson_elliptic}\r\n\\begin{minted}[texcomments]{js}\r\n\"elliptic\",\r\n{\r\n    \"type\"      : \"multigrid\", // Actually a nested iterations method\r\n    \"stages\"    : 3,  // Number of stages (3 is best in virtually all cases)\r\n    \"eps_pol\"   : [1e-6,10,10],\r\n    // Accuracy requirement on each stage of the\r\n    // multigrid scheme. $\\eps_0 = \\eps_{pol,0}$, $\\eps_i = \\eps_{pol,i} \\eps_{pol,0}$  for $i>1$. \\\\\r\n    \"direction\" : \"centered\" // Direction of the Laplacian: forward or centered\r\n}\r\n\\end{minted}\r\n\\subsection{Advection schemes}\r\nThe following parameters control the advection scheme in the code\r\n\\begin{minted}[texcomments]{js}\r\n\"advection\",\r\n{\r\n    \"type\" : \"arakawa\", // Discretize Eqs.\\eqref{eq:euler_poisson} using Arakawa's scheme \\cite{Einkemmer2014}\r\n    \"type\" : \"centered\" // Discretize Eqs.\\eqref{eq:euler_conservative} using the centered flux\r\n    \"type\" : \"upwind\" // Discretize Eqs.\\eqref{eq:euler_conservative} using the upwind flux\r\n    \"type\" : \"centered-advection\" // Discretize Eqs.\\eqref{eq:euler_advection} using the centered flux\r\n    \"type\" : \"upwind-advection\" // Discretize Eqs.\\eqref{eq:euler_advection} using the upwind flux\r\n    \"multiplication\" : \"pointwise\"\r\n    // The multiplications in the scheme are done pointwise in nodal space\r\n    \"multiplication\" : \"projection\"\r\n    // The multiplications in the scheme are done by first interpolating to a\r\n    // higher polynomial grid with $n_{fine} = 2n$, and projecting the result back\r\n    // to the coarse grid\r\n}\r\n\\end{minted}\r\n\r\n\\section{Compilation and useage}\r\nThe program shu\\_b.cu compiles with\r\n\\begin{verbatim}\r\nmake <shu_b> device = <omp gpu>\r\nmake <shu_hpc> device = <omp gpu>\r\n\\end{verbatim}\r\nand depends on both GLFW3 and NETCDF. If GLFW3 is not available then compile shu\\_hpc which avoids this dependency.\r\nRun with\r\n\\begin{verbatim}\r\npath/to/feltor/src/shu/shu_b input.json\r\n\\end{verbatim}\r\n\r\n\\subsection{Output structure}\r\n\r\nWe can either display the results in real-time to screen using the glfw3 library or\r\nwrite the results to a file in netcdf-4 format.\r\nThis is regulated by the output paramters in the input file\r\n\\begin{minted}[texcomments]{js}\r\n\"output\":\r\n{\r\n    // Use glfw to display results in a window while computing (requires to\r\n    // compile with the glfw3 library)\r\n    \"type\"  : \"glfw\"\r\n    \"itstp\"  : 4, // The number of steps between outputs of 2d fields \\\\\r\n    // Use netcdf to write results into a file\r\n    // (see next section for information about what is written in there)\r\n    \"type\"  : \"netcdf\"\r\n    \"itstp\"  : 4, // The number of steps between outputs of 2d fields \\\\\r\n    \"maxout\"  : 500 // The total number of field outputs. The endtime is\r\n    //T=itstp*maxout*dt\r\n}\r\n\\end{minted}\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\ntime                     & Coord. Var. & 1 (time) & time at which fields are written \\\\\r\nx                        & Coord. Var. & 1 (x) & x-coordinate  \\\\\r\ny                        & Coord. Var. & 1 (y) & y-coordinate \\\\\r\nxc                       & Dataset & 2 (y,x) & Cartesian x-coordinate  \\\\\r\nyc                       & Dataset & 2 (y,x) & Cartesian y-coordinate \\\\\r\nvorticity                & Dataset & 3 (time, y, x) & electon density $n$ \\\\\r\npotential                & Dataset & 3 (time, y, x) & electric potential $\\phi$  \\\\\r\nvorticity\\_1d            & Dataset & 1 (time) & Vorticity integral $V$  \\\\\r\nenstrophy\\_1d            & Dataset & 1 (time) & Enstropy integral $\\Omega$  \\\\\r\nenergy\\_1d               & Dataset & 1 (time) & Total energy integral computed using $E = \\int_D \\phi\\omega \\dA$ \\\\\r\ntime\\_per\\_step          & Dataset & 1 (time) & Average computation time for one step \\\\\r\nerror                    & Dataset & 1 (time) & Relative error to analytical solution if available, 0 else \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\nThe output fields are determined in the file \\texttt{feltor/src/lamb\\_dipole/diag.h}.\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": "e129f2ab4323e0fb23500d88e94cab1e791b6b10", "size": 15034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lamb_dipole/shu.tex", "max_stars_repo_name": "RaulGerru/FELTOR_FINAL", "max_stars_repo_head_hexsha": "dd5af5e61d1607eb3b0415b756c1a6cf56b63a2c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-11T10:59:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-11T10:59:44.000Z", "max_issues_repo_path": "src/lamb_dipole/shu.tex", "max_issues_repo_name": "RaulGerru/FELTOR_FINAL", "max_issues_repo_head_hexsha": "dd5af5e61d1607eb3b0415b756c1a6cf56b63a2c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-02T13:43:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-02T13:43:25.000Z", "max_forks_repo_path": "src/lamb_dipole/shu.tex", "max_forks_repo_name": "mrheld/feltor", "max_forks_repo_head_hexsha": "c70bc6bb43f39261f6236df88e16610d08cb98ca", "max_forks_repo_licenses": ["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.0906666667, "max_line_length": 116, "alphanum_fraction": 0.6339630172, "num_tokens": 4609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6505044824147137}}
{"text": "\n\\subsection{Abstract algebra}\n\nAbstract algebra allows us to discuss properties of types of mathematical structures.\n\nRather than construct a specific object, and explore its properties, we can explore the properties of an abstract structure with certain definitions. We can then apply findings from this to an any structure which meets the definition.\n\n\\subsubsection{Examples of abstract algebra}\n\nWe explore:\n\n\\begin{itemize}\n\\item Groups\n\\item Rings\n\\item Fields\n\\item Vector spaces\n\\item Inner product spaces\n\\end{itemize}\n\n", "meta": {"hexsha": "28e080ee0dfe9b18ae50f2efb091c1d29d141ef3", "size": 530, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/01-01-abstract.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/01-01-abstract.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/01-01-abstract.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.5, "max_line_length": 234, "alphanum_fraction": 0.8075471698, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6505044782012902}}
{"text": "\\documentclass{article}\r\n\\title{ALO for Logistic Regression and Poisson Regression}\r\n\\author{Yuze Zhou}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsfonts}\r\n\\usepackage{graphicx}\r\n\\begin{document}\r\n\\section{ALO for Logistic Regression}\r\n\\subsection{ALO for Logistic Regression with Lasso penalty}\r\n\\paragraph{}First Let's rewrite the optimization problem with the loss functions separated for each observation, therefore the loss function goes:\r\n\\begin{center}\r\n$-\\sum\\limits_{i}(y_{i}x_{i}^{\\tau}\\beta+log(1+exp(x_{i}^{\\tau}\\beta)))+\\lambda_{1}||\\beta||_{1}$\r\n\\end{center}\r\n\\paragraph{}Where, separatively, the loss function is $l(x_{i}^{\\tau}\\beta ;y_{i}) = y_{i}x_{i}^{\\tau}\\beta+log(1+exp(x_{i}^{\\tau}\\beta))$ and the regularizer is $R(\\beta) = \\lambda_{1}||\\beta||_{1}$, from which we could derive the dual optimal $\\hat{\\theta} = y - \\frac{e^{X\\beta}}{1+e^{X\\beta}}$, as well as the conjugate functions of them as $l^{*}(-\\theta_{i};y_{i})=(y_{i}-\\theta_{i})ln\\frac{y_{i}-\\theta_{i}}{1-(y_{i}-\\theta_{i})}-ln\\frac{1}{1-(y_{i}-\\theta_{i})}$,\r\n\\begin{center}\r\n$R^{*}(\\beta) = \\left\\{\r\n\\begin{aligned}\r\n0 \\quad ||\\beta||_{\\infty} \\leq \\lambda_{1}\\\\\r\n\\infty \\quad o.w.\\\\\r\n\\end{aligned}\r\n\\right.$\r\n\\end{center}\r\n\\paragraph{}From the results of the conjugate functions above, we could also obtain the derivatives of the loss functions and the Jacobian of the regularizer:\r\n\\begin{center}\r\n$\\dot{l}^{*}(-\\theta_{i};y_{i}) = ln \\frac{y_{i}-\\theta_{i}}{1-(y_{i}-\\theta_{i})}$\\\\\r\n$\\ddot{l}^{*}(-\\theta_{i};y_{i}) = \\frac{1}{(y_{i}-\\theta_{i})(1-(y_{i}-\\theta_{i}))}$\r\n\\end{center}\r\n\\paragraph{}Recall (15) from the \\textbf{General Smooth Loss}, the quadratic surrogate of the dual problem is $\\min\\limits_{u} \\frac{1}{2}\\sum\\limits_{i}(u_{i}-\\frac{\\hat{\\theta}_{i}\\ddot{l}^{*}(-\\hat{\\theta}_{i};y_{i})+\\hat{y}_{i}}{\\sqrt{\\ddot{l}^{*}(-\\hat{\\theta}_{i};y_{i})}})^{2}+R^{*}(X^{\\tau}Ku)$, where $K =diag(\\sqrt{\\ddot{l}^{*}(-\\hat{\\theta}_{i};y_{i})})$ therefore the Jacobian at $y_{u} = \\frac{\\hat{\\theta}_{i}\\ddot{l}^{*}(-\\hat{\\theta}_{i};y_{i})+\\hat{\\theta}_{i}}{\\sqrt{\\ddot{l}^{*}(-\\hat{\\theta}_{i};y_{i})}}$ could locally be treated as the projection onto the orthogonal complement of the polyhedra $\\{||X^{\\tau}Ku||_{\\infty} \\leq \\lambda_{1}\\}$, thus $J = I - X_{u,E}(X_{u,E}^{\\tau}X_{u,E})^{-1}X_{u,E}$, where $X_{u,E}$ are the columns of $X_{u}=X^{\\tau}K$, such that the columns in the set $E = \\{|X_{i}^{\\tau}\\theta| = \\lambda_{1}\\}$ are selected. Take everything to (17), $y^{/i} = K_{ii}(y_{u,i}-\\frac{K_{ii}\\hat{\\theta}_{i}}{J_{ii}})$, we could obtain the alo for the $i$th observation.\r\n\\subsubsection{ALO for Logistic Regression with Lasso Penalty with intercept included}\r\n\\paragraph{}If we include intercept for the model but it will not be penalized, and rewrite $\\tilde{x_{i}} = [1; x_{i}]$, $\\tilde{X} = [\r\n\\textbf{1},X]$ and $\\tilde{\\beta} = [\\beta_{0},\\beta]$, the loss function stays in the same form as the case with no intercept, that is $l(\\tilde{x_{i}}^{\\tau}\\tilde{\\beta};y_{i})= -(y_{i}\\tilde{x_{i}}^{\\tau}\\tilde{\\beta}+log(1+exp(\\tilde{x_{i}}^{\\tau}\\tilde{\\beta})))$, and the but the regularizer will be different, it becomes $R(\\tilde{\\beta}) = \\lambda_{1}||D\\tilde{\\beta}||_{1}$, where $D = [\\textbf{0},I]$. Therefore, the corresponding dual optimal becomes $\\hat{\\theta} = y - \\frac{e^{\\tilde{X}\\tilde{\\beta}}}{1+e^{\\tilde{X}\\tilde{\\beta}}}$, the conjugate of the loss function will stay the same, but the conjugate for $R(\\tilde{\\beta})$ shall be changed.\r\n\\begin{center}\r\n$R^{*}(\\tilde{\\beta}) = \\left\\{\r\n\\begin{aligned}\r\n0 & \\quad if \\quad \\beta_{0} = 0 \\quad and \\quad \\beta_{i} \\leq \\lambda_{1}\\\\\r\n+\\infty & \\quad o.w.\r\n\\end{aligned}\r\n\\right.$\r\n\\end{center}\r\n\\paragraph{}Given the new regularizer and loss function, we could derive the new $\\tilde{X}_{u} = K^{-1}\\tilde{X}$, and the corresponding Jacobian is therefore $J = I -\\tilde{X}_{u,\\tilde{E}}(\\tilde{X}_{u,\\tilde{E}}^{\\tau}\\tilde{X}_{u,\\tilde{E}})^{-1}\\tilde{X}_{u,\\tilde{E}}^{\\tau}$, where $\\tilde{E}$ denotes the columns of $\\tilde{X}_{u}$ such that $\\tilde{E} = \\{j:\\tilde{X}_{j}^{\\tau}\\theta \\leq \\lambda_{1}\\}$.\r\n\\subsection{ALO for Logistic Regression with Elastic Net Penalty}\r\n\\paragraph{}The optimization problem for logistic regression with elastic net penalty is:\r\n\\begin{center}\r\n$-\\sum\\limits_{i}(y_{i}x_{i}^{\\tau}\\beta+log(1+exp(x_{i}^{\\tau}\\beta)))+\\lambda_{1}||\\beta||_{1}+\\lambda_{2}||\\beta||_{2}^{2}$\r\n\\end{center}\r\n\\paragraph{}The optimization problem is the same except the regularizer is changed, therefore the only thing different is the conjugate function of the regularizer, $R^{*}$ and the corresponding Jacobian, here $R(\\beta) = \\lambda_{1}||\\beta||_{1}+\\lambda_{2}||\\beta||_{2}^{2}$:\r\n\\begin{center}\r\n$R^{*}(\\beta) = \\sum\\limits_{|u_{i}| > \\lambda_{1}} \\frac{(\\lambda_{1}-|u_{i}|)^{2}}{4\\lambda_{2}}$\r\n\\end{center}\r\n\\paragraph{}The corresponding Jacobian is $J = (I + \\frac{1}{2\\lambda_{2}}X_{u,E}X_{u,E}^{\\tau})$, where $X_{u,E}$ are the columns of $X_{u}=K^{-1}X$, such that the columns in the set $E = \\{|X_{i}^{\\tau}\\theta| = \\lambda_{1}\\}$ are selected. Take everything to (17), $y^{/i} = K_{ii}(y_{u,i}-\\frac{K_{ii}\\hat{\\theta}_{i}}{J_{ii}})$, we could obtain the alo for the $i$th observation.\r\n\\subsubsection{ALO for Logistic Regression with Elastic Net Penalty with intercept}\r\n\\paragraph{}The loss function for logistic regression with elastic net penalty with intercept is the same as the case without an intercept, however, the regularizer function is different. The dual optimal will also be $\\hat{\\theta} = y - \\frac{e^{X\\beta}}{1+e^{X\\beta}}$. Using the same notations $D$ and $\\tilde{\\beta}$in the logistic regression with lasso penalty with intercept part, the regularizer now becomes $\\lambda_{1}||D\\beta||_{1}+\\lambda_{2}||D\\beta||_{2}^{2}$, the conjugate of which is therefore:\r\n\\begin{center}\r\n$R^{*}(\\beta) = \\left\\{\r\n\\begin{aligned}\r\n\\sum\\limits_{i:|\\beta_{i}|>\\lambda_{1}}\\frac{(\\lambda_{1}-|\\beta_{1}|)^{2}}{4\\lambda_{2}} &\\quad if \\quad \\beta_{0}=0\\\\\r\n+\\infty \\quad o.w.\r\n\\end{aligned}\r\n\\right.$\r\n\\end{center}\r\n\\paragraph{}First denote the set $\\{E:|X_{j}^{\\tau}\\theta| > \\lambda_{1}\\}$ and $A = \\frac{1}{2\\lambda_{2}}\\tilde{X}_{u,E}\\tilde{X}_{u,E}^{\\tau}$, the new Jacobian becomes: \r\n\\begin{center}\r\n$J = (I+A)^{-1}-\\frac{(I+A)^{-1}\\textbf{1}\\textbf{1}^{\\tau}(I+A)^{-1}}{\\textbf{1}^{\\tau}(I+A)^{-1}\\textbf{1}}$\r\n\\end{center}\r\n\\paragraph{}By plugging everything into (17), we could obtain the alo.\r\n\\section{ALO for Poisson Regression}\r\n\\subsection{ALO for Poisson Regression with Lasso Penalty}\r\n\\paragraph{}The optimization function for Poisson regression with lasso penalty is:\r\n\\begin{center}\r\n$\\sum\\limits_{i}-y_{i}x_{i}^{\\tau}\\beta+e^{x_{i}^{\\tau}\\beta}+log(y_{i}!) + \\lambda_{1}||\\beta||_{1}$\r\n\\end{center}\r\n\\paragraph{}The regularizer is the same as the logistic regression with the lasso penalty case, thus the Jacobian will also be the same, therefore we only have to focus on the loss function $l(x_{i}^{\\tau}\\beta ; y_{i}) = -y_{i}x_{i}^{\\tau}\\beta+e^{x_{i}^{\\tau}\\beta}+log(y_{i}!)$. The optimal solution for the dual problem $\\hat{\\theta} = y - e^{X\\beta}$ and the conjugate of the loss function is $l^{*}(-\\theta_{i};y_{i}) = (y_{i}-\\theta_{i})ln(y_{i}-\\theta_{i})-(y_{i}-\\theta_{i})$, the corresponding derivatives are therefore:\r\n\\begin{center}\r\n$\\dot{l}^{*}(-\\theta_{i};y_{i}) = ln(y_{i}-\\theta_{i})$\\\\\r\n$\\ddot{l}^{*}(-\\theta_{i};y_{i}) = \\frac{1}{y_{i}-\\theta_{i}}$\r\n\\end{center}\r\n\\paragraph{}By plugging everything into (17), we obtain the alo for Poisson regression with the lasso penalty.\r\n\\subsubsection{ALO for Poisson Regression with Lasso Penalty with Intercept}\r\n\\paragraph{}Using the same notations $\\tilde{X}$ and $\\tilde{\\beta}$, the loss function now becomes $l(x_{i}^{\\tau}\\beta ; y_{i}) = -y_{i}\\tilde{x}_{i}^{\\tau}\\tilde{\\beta}+e^{\\tilde{x}_{i}^{\\tau}\\tilde{\\beta}}+log(y_{i}!)$, and the dual optimal now becomes $\\hat{\\theta} = y - e^{\\tilde{X}\\beta}$. The regularizer is also the same as the logistic regression with lasso penalty with lasso penalty with intercept case, therefore the Jacobian is of the same formula, thus by plugging everything into (17), we could obtain the alo.\r\n\\subsection{ALO for Poisson Regression with Elastic Net Penalty}\r\n\\paragraph{}The loss function for Poisson regression with elastic net penalty is the same as that of Poisson regression with the lasso penalty and the regularizer of it is the same as that of logistic regression with elastic net penalty, thus by plugging everything into (17), we could obtain the alo for Poisson regression with elastic net penalty.\r\n\\subsubsection{ALO for Poisson Regression with Elastic Net Penalty with Intercept}\r\n\\paragraph{}Here the loss function is the same as that of Poisson Regression with Lasso penalty with intercept case and the regularizer is the same as Logistic Regression with elastic net penalty with intercept, thus the formula for the derivatives of loss functions, the dual optimal as well as the Jacobian could be directly obtained using the same formula as mentioned before.\r\n\\end{document}\r\n", "meta": {"hexsha": "22b82cda91ec9cc08d7ddaa425ca73f14a12659d", "size": 9051, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alologpoi.tex", "max_stars_repo_name": "Geophagus96/Summer-ALO", "max_stars_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-07-25T20:32:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-25T20:32:11.000Z", "max_issues_repo_path": "alologpoi.tex", "max_issues_repo_name": "Geophagus96/Summer-ALO", "max_issues_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "alologpoi.tex", "max_forks_repo_name": "Geophagus96/Summer-ALO", "max_forks_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 106.4823529412, "max_line_length": 1012, "alphanum_fraction": 0.6741796487, "num_tokens": 3064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6504521430969603}}
{"text": "\\subsection{Interpolation}\nThis section decribes all the functions in the file ``ptwXY\\_interpolation.c''.\n\n\\subsubsection{ptwXY\\_interpolatePoint}\n\\setargumentNameLengths{interpolation}\nThis function interpolates an $x$ value between the points (x1,y1) and (x2,y2) to obtain its $y$ value\nfor the requested \\highlight{interpolation}.\n\\CallingC{fnu\\_status ptwXY\\_interpolatePoint(}{statusMessageReporting *smr,\n    \\addArgument{ptwXY\\_interpolation interpolation,}\n    \\addArgument{double x,}\n    \\addArgument{double *y,}\n    \\addArgument{double x1,}\n    \\addArgument{double y1,}\n    \\addArgument{double x2,}\n    \\addArgument{double y2 );}}\n    \\argumentBox{smr}{The \\highlight{statusMessageReporting} instance to record errors.}\n    \\argumentBox{interpolation}{Type of interpolation to perform (see Section~\\ref{interpolationSection}).}\n    \\argumentBox{x}{The $x$ value at which the $y$ value is desired.}\n    \\argumentBox{x1}{The $x$ value of the first point.}\n    \\argumentBox{y1}{The $y$ value of the first point.}\n    \\argumentBox{x2}{The $x$ value of the second point.}\n    \\argumentBox{y2}{The $y$ value of the second point.}\n    \\vskip 0.05 in \\noindent\nIf the interpolation flag is invalid or ( x1 $>$ x2 ) then \\highlight{nfu\\_invalid\\-Interpolation} is returned. \nIf logarithm interpolation is requested for an axis, and one of the input values for that axis is less than or equal to 0., \nthen \\highlight{nfu\\_invalid\\-Interpolation} is also returned. If interpolation is \\highlight{ptwXY\\_interpolationOther} then\n\\highlight{nfu\\_otherInterpolation} is returned.\n\n\\subsubsection{ptwXY\\_flatInterpolationToLinear}\nThis function returns a linear-linear interpolated representation of \\highlight{ptwXY}.\n\\setargumentNameLengths{upperEps}\n\\CallingC{ptwXYPoints *ptwXY\\_flatInterpolationToLinear(}{statusMessageReporting *smr,\n    \\addArgument{ptwXYPoints *ptwXY,}\n    \\addArgument{double lowerEps,}\n    \\addArgument{double upperEps );}}\n    \\argumentBox{smr}{The \\highlight{statusMessageReporting} instance to record errors.}\n    \\argumentBox{ptwXY}{A pointer to a \\highlight{ptwXYPoints} object.}\n    \\argumentBox{lowerEps}{The amount to adjust every interior point down in x.}\n    \\argumentBox{upperEps}{The amount to adjust every interior point up in x}\n    \\vskip 0.05 in \\noindent\nFor every interior point (i.e., $(x_i,y_i)$ for $0 < i < n - 1$ where n is the number of points), two points may be added.\nThe positions of these points depend on \\highlight{lowerEps} and \\highlight{upperEps} as follows:\n\\begin{description}\n    \\item[lowerEps ==  0 and upperEps ==  0:] This condition is not allowed. status is set to \\highlight{nfu\\_bad\\-Input} and NULL is returned.\n        This condition is also returned if either \\highlight{lowerEps} or \\highlight{upperEps} is negative.\n    \\item[lowerEps $>$ 0 and upperEps ==  0:] At each interior point $(x_i,y_i)$ the two points $(x_m,y_{i-1})$ and $(x_i,y_i)$ are set.\n    \\item[lowerEps ==  0 and upperEps $>$ 0:] At each interior point $(x_i,y_i)$ the two points $(x_i,y_{i-1})$ and $(x_p,y_i)$ are set.\n    \\item[lowerEps $>$ 0 and upperEps $>$ 0:] At each interior point $(x_i,y_i)$, this point is removed and the two \n        points $(x_m,y_{i-1})$ and $(x_p,y_i)$ are set.\n\\end{description}\nwhere $x_m$ and $x_p$ are given in Table~\\ref{flatInterpolationToLinear}.\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|l|l|}  \\hline\n                & $x_m$                    & $x_p$                          \\\\ \\hline \\hline\n    $x_i <  0$  & $x_i ( 1 + \\epsilon_l )$ & $x_p = x_i ( 1 - \\epsilon_p )$ \\\\ \\hline\n    $x_i == 0$  & $ -\\epsilon_l $          & $ \\epsilon_p $                 \\\\ \\hline\n    $x_i >  0$  & $x_i ( 1 - \\epsilon_l )$ & $x_p = x_i ( 1 + \\epsilon_p )$ \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\caption{The value of $x_m$ and $x_p$ used to adjust interior points in \\highlight{ptwXY\\_fla-Interpolation\\-To\\-Linear}. \n    Here, $ \\epsilon_l = $ \\highlight{lowerEps} and $ \\epsilon_p = $ \\highlight{upperEps}. \\label{flatInterpolationToLinear}}\n\\end{table}\n\n\\subsubsection{ptwXY\\_toOtherInterpolation}\nThis function returns \\highlight{ptwXY} converted to interpolation \\highlight{interpolation}.\n\\setargumentNameLengths{interpolation}\n\\CallingC{ptwXYPoints *ptwXY\\_toOtherInterpolation(}{statusMessageReporting *smr,\n    \\addArgument{ptwXYPoints *ptwXY,}\n    \\addArgument{ptwXY\\_interpolation interpolation,}\n    \\addArgument{double accuracy );}}\n    \\argumentBox{smr}{The \\highlight{statusMessageReporting} instance to record errors.}\n    \\argumentBox{ptwXY}{A pointer to a \\highlight{ptwXYPoints} object.}\n    \\argumentBox{interpolation}{The interpolation to convert to.}\n    \\argumentBox{accuracy}{The accuracy of the conversion.}\n    \\vskip 0.05 in \\noindent\nCurrently, \\highlight{interpolation} can only be \\highlight{ptwXY\\_\\-interpolation\\-LinLin}.\n\n\\subsubsection{ptwXY\\_toUnitbase}\nThis function returns a unit-based version of \\highlight{ptwXY}.\n\\setargumentNameLengths{scaleRange}\n\\CallingC{ptwXYPoints *ptwXY\\_toUnitbase(}{statusMessageReporting *smr,\n    \\addArgument{ptwXYPoints *ptwXY,}\n    \\addArgument{int scaleRange );}}\n    \\argumentBox{smr}{The \\highlight{statusMessageReporting} instance to record errors.}\n    \\argumentBox{ptwXY}{A pointer to the \\highlight{ptwXYPoints} object.}\n    \\argumentBox{scaleRange}{The y-values are not scaled if this is 0.}\n    \\vskip 0.05 in \\noindent\nUnitbasing maps the domain to 0 to 1 by scaling each x-value as \n\\begin{equation}\n    x_i = ( x_i - x_0 ) / ( x_{n-1} - x_0 )\n\\end{equation}\nand if \\highlight{scaleRange} is not 0, scaling each y-value as\n\\begin{equation}\n    y_i = y_i \\times ( x_{n-1} - x_0 ) \\ \\ \\ . \n\\end{equation}\nUnitbasing is most useful for pdf's.\n\n\\subsubsection{ptwXY\\_fromUnitbase}\nThis function undoes the unit base mapping done by \\highlight{ptwXY\\_toUnitbase}.\n\\setargumentNameLengths{scaleRange}\n\\CallingC{ptwXYPoints *ptwXY\\_fromUnitbase(}{statusMessageReporting *smr,\n    \\addArgument{ptwXYPoints *ptwXY,}\n    \\addArgument{double domainMin,}\n    \\addArgument{double domainMax,}\n    \\addArgument{int scaleRange );}}\n    \\argumentBox{smr}{The \\highlight{statusMessageReporting} instance to record errors.}\n    \\argumentBox{ptwXY}{A pointer to the \\highlight{ptwXYPoints} object.}\n    \\argumentBox{domainMin}{The lower domain for the returned \\highlight{ptwXYPoints} instances.}\n    \\argumentBox{domainMax}{The upper domain for the returned \\highlight{ptwXYPoints} instances.}\n    \\argumentBox{scaleRange}{The y-values are not scaled if this is 0.}\n    \\vskip 0.05 in \\noindent\nEach x-value is scaled as \n\\begin{equation}\n    x_i = ( {\\rm domainMax} - {\\rm domainMin} ) \\times x_i + {\\rm domainMin}\n\\end{equation}\nand if \\highlight{scaleRange} is not 0, each y-value is scaled as \n\\begin{equation}\ny_i = y_i / ( {\\rm domainMax} - {\\rm domainMin} ) \\ \\ \\ \\ \n\\end{equation}\n\n\\subsubsection{ptwXY\\_unitbaseInterpolate}\nThis function returns a \\highlight{ptwXYPoints} instance that is the unit-base interpolation of \\highlight{ptwXY1} at $w_1$\nand \\highlight{ptwXY2} at $w_2$ at the w-value $w$.\n\\setargumentNameLengths{interpolation}\n\\CallingC{ptwXYPoints *ptwXY\\_unitbaseInterpolate(}{statusMessageReporting *smr,\n    \\addArgument{double w,}\n    \\addArgument{double w1,}\n    \\addArgument{ptwXYPoints *ptwXY1,}\n    \\addArgument{double w2,}\n    \\addArgument{ptwXYPoints *ptwXY2,}\n    \\addArgument{scaleRange );}}\n    \\argumentBox{smr}{The \\highlight{statusMessageReporting} instance to record errors.}\n    \\argumentBox{w}{The w-value to interpole to.}\n    \\argumentBox{w1}{The lower w-value}\n    \\argumentBox{ptwXY1}{A pointer to a \\highlight{ptwXYPoints} object at w1.}\n    \\argumentBox{w2}{The upper w-value}\n    \\argumentBox{ptwXY2}{A pointer to a \\highlight{ptwXYPoints} object at w2.}\n    \\argumentBox{scaleRange}{The y-values are not scaled if this is 0.}\n    \\vskip 0.05 in \\noindent\n", "meta": {"hexsha": "d5453df7d96599323d81bd03d50ccf787da41c1f", "size": 7842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "numericalFunctions/Doc/ptwXY_interpolation.tex", "max_stars_repo_name": "Mathnerd314/gidiplus", "max_stars_repo_head_hexsha": "ed4c48ab399a964fe782f73d0a065849b00090bb", "max_stars_repo_licenses": ["MIT-0", "MIT"], "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": "numericalFunctions/Doc/ptwXY_interpolation.tex", "max_issues_repo_name": "Mathnerd314/gidiplus", "max_issues_repo_head_hexsha": "ed4c48ab399a964fe782f73d0a065849b00090bb", "max_issues_repo_licenses": ["MIT-0", "MIT"], "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": "numericalFunctions/Doc/ptwXY_interpolation.tex", "max_forks_repo_name": "Mathnerd314/gidiplus", "max_forks_repo_head_hexsha": "ed4c48ab399a964fe782f73d0a065849b00090bb", "max_forks_repo_licenses": ["MIT-0", "MIT"], "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": 55.6170212766, "max_line_length": 143, "alphanum_fraction": 0.7220096914, "num_tokens": 2434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6504521333323613}}
{"text": "%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\input{../header.tex}\n\\input{../newcommands.tex}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n%\\preprint{}\n\n\\title{The parallel derivative on structured grids}\n\\author{M.~Wiesenberger and M.~ Held}\n\n\\maketitle\n\n\\abstract{\nThis write-up shows how we numerically treat parallel derivatives in a non field\naligned coordinate system. It is mainly based on References~\\cite{Hariri2014,Held2016,Stegmeir2017} and contains parts from References~\\cite{WiesenbergerPhD, HeldPhD}\n}\n\\section{Discretization of parallel derivatives} \\label{sec:parallel}\nWe introduce the method\nand discuss some problems arising from the boundaries of the computational domain.\n\n\\subsection{The flux coordinate independent approach} \\label{sec:parallela}\nGiven is a vector field $\\vec v(R,Z)$ in cylindrical coordinates $R,Z,\\varphi$ independent of $\\varphi$ and we want to\ndiscretize the derivative $\\vec v \\cdot\\nabla f \\equiv \\nabla_\\parallel f$.\nThe vector field $\\vec v$ might be the magnetic unit vector field but the algorithm works\nfor any vector field $\\vec v$ with $v^\\varphi\\neq 0$, in particular $\\vec v$ does not need\nto have unit length.\n\nWe begin with the formulation of a field-aligned discretization.\nTo every smooth vector field $\\vec v(\\vec x)$ there is a unique curve of which the\ntangent in a point $p$ is the value of $\\vec v(p)$ at that point. It is given by\nthe solution of the differential equation\n\\begin{align}\n  \\frac{\\d z^i}{\\d s} = v^i(\\vec z)|_{\\vec z(s)}\n    \\label{eq:integralcurve}\n\\end{align}\nwhere $z^i$ is one of $(R, Z, \\varphi)$ and $v^i$ are the contravariant components\nof $\\vec v$ in cylindrical coordinates.\nNote here that $s$ does NOT necessarily denote the distance\n(especially since we do not require the existence of a metric at this point).\nMoreover, by definition we have\n\\begin{align}\n    \\frac{\\d f(\\vec z(s))}{\\d s} = \\vec v\\cdot \\nabla f|_{\\vec z(s)}\n    \\label{eq:fieldline_original}\n\\end{align}\nalong a field line parameterized by $s$.\nThis means that instead of $\\vec v \\cdot \\nabla f$ we can choose to discretize ${\\d f}/{\\d s}$.\n\nLet us divide the $\\varphi$ direction into $N_\\varphi$ equidistant planes of\n$\\Delta \\varphi$. Unfortunately, from Eq.~\\eqref{eq:integralcurve} we cannot easily determine\n$\\Delta s$ for given $\\Delta \\varphi$.\nThus, it is better to reparameterize Eq.~\\eqref{eq:fieldline_original} with $\\varphi$ instead of $s$:\n\\begin{subequations}\n\\begin{align}\n    \\frac{\\d R}{\\d\\varphi}&= \\frac{v^R}{v^\\varphi},\\\\ %\\frac{R}{I}\\frac{\\partial\\psi}{\\partial Z},\\\\\n    \\frac{\\d Z}{\\d\\varphi}&=\\frac{v^Z}{v^\\varphi},\\\\%-\\frac{R}{I}\\frac{\\partial\\psi}{\\partial R}.\n    \\frac{\\d s}{\\d\\varphi}&=\\frac{1}{v^\\varphi}\n\\end{align}\n\\label{eq:fieldline}\n\\end{subequations}\nWe integrate Eqs.~\\eqref{eq:fieldline} from $\\varphi=\\varphi_k$ to $\\varphi=\\varphi_k\\pm \\Delta \\varphi$\nwith initial condition\n\\begin{align}\n    (R(\\varphi_k), Z(\\varphi_k), s(\\varphi_k) ) = (R, Z, s_k).\n    \\label{}\n\\end{align}\nwhere $k$ is the numbering of the planes and $s_k$ is arbitrary.\nLet us characterize the solution $(R(\\varphi_k\\pm \\Delta \\varphi), Z(\\varphi_k\\pm \\Delta \\varphi))$ to Eqs.~\\eqref{eq:fieldline} as the flow generated by $\\vec v/v^\\varphi$\n\\begin{align}\n    \\Tpm\\vec z \\equiv \\Tpm[R, Z, \\varphi]:= ( R(\\pm \\Delta\\varphi), Z( \\pm \\Delta\\varphi), \\varphi\\pm\\Delta \\varphi),\n    \\label{}\n\\end{align}\nObviously we have $\\Tm\\circ\\Tp = \\Eins$, but $\\Tpm$ is not necessarily unitary since $\\vec v/v^\\varphi$ is in general\nnot divergence free.\n\nWe now fit a second order polynomial through $(R,Z,\\varphi)$, $\\Tp [R,Z,\\varphi]$ and $\\Tm[R,Z,\\varphi]$. We approximate the first and second derivative at $(R,Z,\\varphi)$ by evaluating the derivative of the\npolynomial at that point.\n\\begin{align} \\label{eq:paralleldis}\n    \\nabla_\\parallel f \\equiv \\frac{df}{ds}\n    \\rightarrow\n    \\left(\\frac{ 1}{s_{k+1}-s_{k-1}} - \\frac{1}{s_k - s_{k-1}}\\right) &f_{k-1}  \\nonumber\\\\\n    +\\left(\\frac{ 1}{s_{k}-s_{k-1}} - \\frac{1}{s_{k+1} - s_{k}}\\right) &f_k\\nonumber\\\\\n    +\\left(\\frac{ 1}{s_{k+1}-s_{k}} - \\frac{1}{s_{k+1} - s_{k-1}}\\right) &f_{k+1}\n    %\\frac{f\\left(T_{\\Delta\\varphi}^+\\vec z_k\\right)-f\\left(T_{\\Delta\\varphi}^-\\vec z_k\\right)}{s_{k+1}-s_{k-1}},\n\\end{align}\nwhere $\\vec z_k = (R,Z,\\varphi_k)$ and $f_k = f(\\vec z_k)$\nand $f_{k\\pm 1} := f(\\Tpm \\vec z_k)$.\nNote that Eq.~\\eqref{eq:paralleldis} reduces to\nthe familiar centered difference formula in case of equidistant spacings.\nEq.~\\eqref{eq:paralleldis} is slightly different from Reference~\\cite{Hariri2014}, where the $\\d f/\\d\\varphi v^\\varphi$ is discretized to avoid integrating $s$.\nHowever, our discretization has the advantage that it can be used for higher\norder derivatives as well (e.g. $\\d^2f/\\d \\varphi^2$), which is not possible otherwise due to the chain rule\nfor $v^\\varphi$.\n\nSince the $R$ and $Z$ coordinates are still discretized in the dG framework we note that in our work\nthe interpolation of $f$ on the transformed points $\\Tpm\\vec z$\nis naturally given by interpolating the base polynomials.\nLet us for a moment omit the $Z$ coordinate for ease of notation.\nIf $(R_{nj}, \\varphi_k)$ are the grid points,\nwe call $(R^+_{nj}, \\varphi_{k+1}) := \\Tp[R_{nj}, \\varphi_k]$ and\n$(R_{nj}^-, \\varphi_{k-1}) := \\Tm[R_{nj}, \\varphi_k]$ the transformed coordinates along\nthe field lines. We then have\n\\begin{subequations}\n\\begin{align}\n    f(\\Tp\\vec z) = f( R^+_{nj}, \\varphi_{k+1}) = \\bar f_{k+1}^{ml}p_{ml}(R^+_{nj}) =: (I^+)_{nj}^{ml}f_{(k+1)ml} , \\\\\n    f(\\Tm\\vec z) = f( R^-_{nj}, \\varphi_{k-1}) = \\bar f_{k-1}^{ml}p_{ml}(R^-_{nj}) =: (I^-)_{nj}^{ml}f_{(k-1)ml} , \n\\end{align}\n\\label{eq:interpolation}\n\\end{subequations}\nwhere the backward transformations of $\\bar{ \\vec f}$ are hidden in $I$.\nThus, the interpolation of all the necessary points can simply be written as a matrix-vector product, where the interpolation matrices $I^+$  and $I^-$ are independent of time since\nthe field lines are constant in time. The order of this interpolation is given by $P$, the number of polynomial coefficients.\nA consistency check is the relation $I^+\\circ I^- = \\Eins$.\n\nThe discretization~\\eqref{eq:paralleldis} can now be written as a matrix vector product\n\\begin{align}\n\\nabla_\\parallel f \\rightarrow  \\left[S^+ \\circ \\Eins^+\\otimes I^+ + S^0  + S^-\\circ \\Eins^- \\otimes I^-  \\right] \\vec f,\n    \\label{}\n\\end{align}\nwhere $S^+$, $S^0$ and $S^-$ are the diagonal matrices that contain the prefactors\nin Eq.~\\eqref{eq:paralleldis}.\nThis discretization is not skew-symmetric since the\nfield lines are not volume-preserving, or~$(I^+)^\\mathrm{T} \\neq I^-$.\nIn fact, the adjoint of the parallel derivative is\n\\begin{align}\n    \\nabla_\\parallel^\\dagger f = - \\nabla\\cdot(\\vec v\\ f ) \\neq -\\nabla_\\parallel f.\n    \\label{}\n\\end{align}\nNote that with this relation we can define the parallel\ndiffusion operator as\n\\begin{align}\n    \\Delta_\\parallel := -\\nabla_\\parallel^\\dagger \\nabla_\\parallel = (\\nabla\\cdot \\vec{ \\hat v}) \\nabla_\\parallel + \\nabla_\\parallel^2 , \n    \\label{}\n\\end{align}\nwhich is indeed the parallel part of the full Laplacian $\\Delta = \\nabla\\cdot( \\vec{ \\hat v} \\nabla_\\parallel + \\nabla_\\perp)$.\n$\\vec{ \\hat v} $ is the unit vector $\\vec v/ |\\vec v|$.\n\nNote that the second order derivative $\\nabla_\\parallel^2$ can be\ndiscretized using\n\\begin{align}\\label{eq:second_order}\n    \\frac{\\d^2 f}{\\d s^2} \\rightarrow\n     \\frac{2f_{k+1}}{(s_{k+1}-s_k)(s_{k+1}-s_{k-1})}\n    -\\frac{2f_{k}}{(s_{k+1}-s_k)(s_{k}-s_{k-1})} \\nonumber\\\\\n    +\\frac{2f_{k-1}}{(s_{k}-s_{k-1})(s_{k+1}-s_{k-1})}\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Change of coordinates}\nIn principle the above considerations hold in any\ncoordinate system $\\eta,\\zeta,\\varphi$, since the directional derivative is\nan intrinsic operation.\nThe only question is how to integrate the field lines in the\n$\\eta, \\zeta,\\varphi$ system\nsince we assumed that our vector field $\\vec v(\\vec x)$ was given\nanalytically in\ncylindrical coordinates. There are two possibilities.\nFirst, interpolate $R(\\zeta_i, \\eta_i), Z(\\zeta_i, \\eta_i)$ for\nall $i$, then integrate $\\vec v$ in $(R,Z)$ space and finally use\nNewton iteration to find $\\zeta(R^\\pm_i, Z^\\pm_i), \\eta(R^\\pm_i, Z^\\pm_i)$.\nThe downside here is that it is difficult to tell when and where the fieldline leaves the simulation domain. (However this is true also for the\nfollowing approach, See Section~\\ref{sec:boundary})\n\nThe second possibility (the one currently implemented)\nis to integrate entirely in the\ntransformed coordinate system $\\zeta, \\eta, \\varphi$.\nThe magnetic field can be easily transformed since we have the\nJacobian of the coordinate transformation\n\\begin{align}\n    v^\\zeta(\\zeta, \\eta) &= \\left(\\frac{\\partial \\zeta}{\\partial R} v^{R} + \\frac{\\partial \\zeta}{\\partial Z}v^Z\\right)_{R(\\zeta, \\eta), Z(\\zeta, \\eta)} \\\\\n    v^\\eta(\\zeta, \\eta) &= \\left(\\frac{\\partial \\eta}{\\partial R} v^{R} + \\frac{\\partial \\eta}{\\partial Z}v^Z\\right)_{R(\\zeta, \\eta), Z(\\zeta, \\eta)} \\\\\n    v^\\varphi(\\zeta, \\eta) &= v^\\varphi({R(\\zeta, \\eta), Z(\\zeta, \\eta)})\n    \\label{eq:field_trafo}\n\\end{align}\nThe fieldline equations~\\eqref{eq:fieldline} are still\n\\begin{subequations}\n\\begin{align}\n\\frac{\\d \\zeta}{\\d\\varphi} &= \\frac{v^\\zeta}{v^\\varphi}\\\\\n\\frac{\\d \\eta}{\\d\\varphi} &= \\frac{v^\\eta}{v^\\varphi}\\\\\n\\frac{\\d s}{\\d \\varphi} &= \\frac{1}{v^\\varphi}\n\\end{align}\n\\label{eq:fieldlines_coords}\n\\end{subequations}\nThe issue here is that when integrating fieldlines we\nhave to interpolate the vector field $\\vec v$ at arbitrary points\ninstead of simply evaluating the exact values.\nHowever, the interpolation error vanishes with order $P$ in the\nperpendicular plane so in order to mitigate this error\nwe transform $\\vec v$ on a finer grid/higher order polynomials for more accurate\nintegration.\nApart from the issue of how to get the transformed vector field\nthe remaining algorithm for $\\vec v\\cdot\\nabla$ is entirely unchanged\nand Eq.~\\eqref{eq:paralleldis} still holds.\n\n\\subsection{Boundary conditions} \\label{sec:boundary}\nThe question is what to do when a fieldline intersects with the boundary\nof the simulation domain before reaching the next plane.\nBoundary conditions are formulated by either setting a value\non the boundary of the domain (Dirichlet) or by fixing\nthe derivative perpendicularly to the boundary (Neumann), or\na combination of both ( Robin).\n\n\n\\subsubsection{ Boundary conditions perpendicular to the wall}\nThe issue with Neumann boundary conditions is that they usually prescribe\nderivatives perpendicular to the boundary\nwhile the fieldlines are in general not perpendicular to the boundary.\nOne possible approach is to introduce ghostcells at the\nplaces where fieldlines end. The value of the ghostcells are\nas if we Fourier transformed the fields on the simulation domain\nwith the correct boundary conditions and thus have a periodic\nextension of the fields beyond the boundaries.\nFor example, for Neumann boundary\nconditions the field is effectively mirrored at the boundary, while for\nDirichlet boundary conditions the values are the negative mirror image. In one\ndimension this reads\n\\begin{align}\nf(x) = \\pm f(2x_b-x)\n\\end{align}\nwhere $x_b$ is the closest boundary $+$ is for Neumann, and $-$ for Dirichlet conditions.\nThis is very easily implemented (at least as long as we only allow\nhomogeneous Boundary conditions) since we don't actually have to\nperform the Fourier transformation, we only need to mirror the end\ncoordinates at the boundary and then choose either the positive (Neumann) or\nnegative (Dirichlet) interpolation.\n\nThe above procedure works for cylindrical coordinates where we can\nevaluate and thus integrate the vector field $\\vec v$ even outside the domain.\nThis is unfortunately not true for transformed coordinates.\nFor now we have to rely on the fieldlines being aligned to the\nboundary in these cases to avoid boundary conditions altogether.\n\nThe downside of this approach is that the mirrored point of a field-line\ncan lie very far away from the wall if the resolution in $\\varphi$ is low (which\nis the motivation to implement FCI in the first place) and\nin addition also on a different flux surface.\nIn principle we need to increase the $\\varphi$ resolution until we resolve\nthe perpendicular direction, in order to reliably converge with this method.\nIn practice we can often run a simulation stably with low resolution nevertheless.\n\nIn order to avoid coupling different flux surfaces through the boundary condition, we have the possibility to\nmirror also the flux surfaces at the boundary.\nThis approach converges well and works stably if the flux surface is (or is close to) perpendicular to the wall.\n\n\\subsubsection{ Boundary conditions parallel to the fieldline}\nThe natural way to implement boundary conditions is to work them into the\ninterpolating polynomial. The boundary condition then replaces a third\npoint by setting\neither a predefined value (Dirichlet) or derivative (Neumann) on the boundary.\nEvaluating the interpolating polynomial at the middle point then yields\n(assuming that $\\Tp \\vec z$ lies outside the boundary and $s_k <s_b^+ < s_{k+1}$ is where the boundary lies)\n\\begin{align} \\label{eq:paralleldis_neup}\n    \\frac{df}{ds}\n    \\underset{\\textsc{NEU}}{\\rightarrow}\n    \\left(\\frac{ 1}{s_{k}-s_{k-1}} - \\frac{1}{2(s_b^+-s_k) + (s_k-s_{k-1})} \\right) &(f_k-f_{k-1})\\nonumber\\\\\n    +\\left(\\frac{s_k - s_{k-1}}{2(s_b^+-s_k) + (s_k-s_{k-1})}\\right) &f_{b+}'\\\\\n\\label{eq:second_order_neup}\n    \\frac{\\d^2 f}{\\d s^2}\n    \\underset{\\textsc{NEU}}{\\rightarrow}\n    \\frac{2}{2(s_b^+-s_k) + (s_k-s_{k-1})}\\left(  f_{b+}' - \\frac{1}{s_k - s_{k-1}}(f_k-f_{k-1})\\right)\n\\end{align}\nwhere $f_{b+}'$ is the value of the  derivative on the boundary (currently we only allow homogeneous boundary conditions, i.e. $f_{b+}' \\equiv 0$).\nIf the boundary lies at $s_{k-1}<s_b^-<s_k$ then we have\n\\begin{align} \\label{eq:paralleldis_neum}\n    \\frac{df}{ds}\n    \\underset{\\textsc{NEU}}{\\rightarrow}\n    \\left(\\frac{ 1}{s_{k+1}-s_k} - \\frac{1}{2(s_k - s_b^-) + (s_{k+1}-s_k)} \\right) &(f_{k+1}-f_k)\\nonumber\\\\\n    +\\left(\\frac{s_{k+1} - s_k}{2(s_k - s_b^-) + (s_{k+1}-s_k)}\\right) &f_{b-}'\n    \\\\\n\\label{eq:second_order_neum}\n    \\frac{\\d^2 f}{\\d s^2}\n    \\underset{\\textsc{NEU}}{\\rightarrow}\n    \\frac{2}{2(s_k -s_b^-) + (s_{k+1}-s_{k})}\\left(  -f_{b-}' + \\frac{1}{s_{k+1}-s_k} (f_{k+1} - f_k)\\right)\n\\end{align}\nwhile if the fieldline intersects the wall on both ends we have\n\\begin{align} \\label{eq:paralleldis_neupm}\n    \\frac{df}{ds}\n    \\underset{\\textsc{NEU}}{\\rightarrow}\n    \\frac{ 1}{s_b^+ - s_b^-}\\left[({ s_k - s_b^-})f_{b+}' + ({s_{b}^+-s_k}) f_{b-}'\\right]    \\\\\n\\label{eq:second_order_neupm}\n    \\frac{\\d^2 f}{\\d s^2}\n    \\underset{\\textsc{NEU}}{\\rightarrow}\n    \\frac{ 1}{s_b^+ - s_b^-}( f_{b+}' - f_{b-}')\n\\end{align}\nThe formulas for Dirichlet boundary conditions are the same as the original\nformulas, with $s_{k+1}$, $f_{k+1}$ replaced by $s_b^+$, $f_b^+$ and/or $s_{k-1}$, $f_{k-1}$ replaced by $s_b^-$, $f_b^-$.\n\nThere is no difference between those formulas and actually evaluating the\ninterpolating polynomial at a ghost point and then using that point in the\noriginal formulas. The reason is that the interpolating polynomial is unique\nand thus is the value of its derivatives at $s_k$.\n\nFor the above formulas to work we need to find the exact place where the fieldline intersects\nthe boundary.\nWe have to find\n$\\varphi_b$ such that the result of the integration of Eq.~\\eqref{eq:fieldline} from\n$\\varphi$ to $\\varphi_b$ lies on the boundary.\nThe angle $\\varphi_b$ can be found by a bisection algorithm knowing that $\\varphi_k<\\varphi_b < \\varphi_k + \\Delta\\varphi$.\nThis kind of procedure is known as a shooting method.\nAnother possibility is to trick the fieldline integrator into finding the point for us.\nWe do this by setting $\\vec v \\equiv 0$ on all points outside the simulation box, which\nmakes the ODE integrator stop once it crosses the domain boundary.\nThis works fairly well with the adaptive embedded Runge Kutta method that we use\nand in particular also works in transformed coordinates.\n\nThe advantage of this method is that the parallel derivative\ndoes not couple different field lines through the boundary conditions. Thus\nthe dynamics on each field-line can be completely independent.\n%However, the problem with this procedure in practice is the small\n%distance between the starting point and the point where the corresponding\n%fieldline intersects the boundary. This seriously deteriorates the\n%CFL condition. (To ease the CFL condition\n%was the reason to devise the algorithm in the first place)\n\n\\subsubsection{Avoiding boundary conditions in non-aligned systems} \\label{sec:avoid}\n\nWhen computing in non-aligned coordinate systems\none idea to avoid boundary conditions\nis to simply cut the contribution from field lines\nthat leave the computational domain. While this might work in practice\nit is \\textbf{highly unclear} what numerical and physical side-effects this procedure might have.\n\nAnother solution would be to change the\nvector field $\\vec v$ and only retain the toroidal part of $\\vec v$ on the\nboundary ( $v^R|_{\\partial\\Omega} = v^Z|_{\\partial\\Omega} =0$). The fieldlines then have a kink on the boundary $\\partial\\Omega$.\nOn the other hand we can implement boundary conditions consistent with\nthe perpendicular ones since the fieldlines never leave the domain.\nWe simply interpolate the quantity to derive on the inner side of the\ndomain boundary (Neumann conditions = \"No boundary condition\") or\nset the value to zero (Dirichlet condition).\n\\textbf{Unfortunately, when testing this procedure with an analytical solution\nthe error does not converge neither for Dirichlet nor for Neumann.}\n\n\\subsection{Poloidal limiters}\nA poloidal limiter can simply be implemented via a boundary condition in $\\varphi$.\nAs long as the form of the limiter is aligned with a flux-function we do not have to\nintegrate a field line in order to determine which points lie in the\nlimiter-shadow. It is therefore straightforward to implement ghost-cells\nin that case.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The adjoint methods}\n\\subsection{A grid refinement approach}\nThe idea is to discretize the operation $\\nabla\\cdot( \\vec v .)$ by\ntaking the adjoint of the discretization for $\\nabla_\\parallel$ i.e. Eq.~\\eqref{eq:paralleldis}.\nRemember that the adjoint of a matrix\ninvolves the volume element (including dG weights). This means that after you've transposed the\nparallel derivative Eq.~\\eqref{eq:paralleldis}, simply bracket the result\nby $1/\\sqrt{g}$ and $\\sqrt{g}$ to get the adjoint.\n\nWhile the idea of simply transposing the discretization matrices sounds appealing the problem\nis that the resulting discretization does not converge.\nOne idea to solve this problem \\cite{Stegmeir2017} is\nto bracket the parallel derivative by interpolation ($Q$) and\nprojection ($P$) matrices:\n\\begin{align}\n    \\nabla^c_\\parallel &= P\\nabla_\\parallel^f Q \\\\\n    \\nabla^{c\\dagger}_\\parallel &= P \\nabla^{f\\dagger}_\\parallel Q\n    \\label{eq:sandwich}\n\\end{align}\nwhere $f$ and $c$ denote fine and coarse grid respectively.\nIn this way the projection integrals\n\\begin{align*}\n    \\int\\dV (\\nabla_\\parallel f) p_i(x)p_j(y)\n    \\label{}\n\\end{align*}\nare computed more precisely.\nThe size of the fine grid should therefore be as large as\npossible.\nWe first notice that one interpolation matrix can be absorbed\nin the parallel derivative since this also consists of\ninterpolation operations.\n\\begin{align}\n    \\nabla^c_\\parallel &= P\\nabla_\\parallel^{fc} \\\\\n    \\nabla^{c\\dagger}_\\parallel &= \\nabla^{fc\\dagger}_\\parallel Q\n    \\label{eq:sandwich}\n\\end{align}\nNote that the matrix-matrix multiplications in Eq.~\\eqref{eq:sandwich} can\nbe precomputed and stored. The memory requirements\nin the final computations are\ntherefore the same  as in the old version. (Not entirely, since\nthe diagonal $v^\\varphi/\\Delta \\varphi$ matrix does not commute with $Q$ or $P$).\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Some Thoughts}\nIn order to understand what the adjoint operators do let us denote $\\Tp$ as the push-forwward operator. Then we have\n\\begin{align}\n    \\int f(\\vec x) \\Tp h(\\vec x) \\sqrt{g(\\vec x)}\\d^3x% \\\\\n    %=  \\int f(\\vec x) h(\\Tm \\vec x)\\sqrt{g(\\vec x)}\\d^3x \\\\\n    %=  \\int f(\\Tp \\vec x') h(\\vec x')\\sqrt{g(\\Tp \\vec x')}J^{-1}( \\Tp\\vec x') \\d^3x' \\\\\n    =  \\int \\frac{1}{\\sqrt{g(\\vec x')}}\\Tm\\left[J^{-1}(\\vec x')\\sqrt{g(\\vec x')}f(\\vec x')\\right] h(\\vec x')\\sqrt{g(\\vec x')}   \\d^3x' \\nonumber \\\\\n    \\equiv  \\int (\\Tp)^\\dagger\\left[f(\\vec x)\\right] h(\\vec x)\\sqrt{g(\\vec x)}   \\d^3x\n    \\label{}\n\\end{align}\n$J$ is the determinant of the Jacobian $\\partial(\\vec x')/\\partial(\\vec x)$ with $\\vec x' = \\Tm \\vec x$.\nIn the last step we simply replaced the dummy variable $\\vec x'$ with $\\vec x$ again and identified the relevant terms\nas the adjoint operator:\n\\begin{align}\n    (\\Tp)^\\dagger f(\\vec x ) := \\frac{1}{\\sqrt{g(\\vec x)}} \\Tm\\left[\\sqrt{g(\\vec x)} J^{-1}(\\vec x) f(\\vec x) \\right]\n    \\label{}\n\\end{align}\nThis means that numerically the adjoint of the push-forward\noperator should be a valid discretization of its inverse.\nNote that $\\sqrt{g}J^{-1}(\\vec x) = \\sqrt{g'(\\Tm \\vec x)}$.\nWith this we can write\n\\begin{align}\n    (\\Tp)^\\dagger f(\\vec x ) := \\sqrt{\\frac{g'(\\vec x)}{g(\\vec x)}} \\Tm\\left[f(\\vec x) \\right]\n    \\label{}\n\\end{align}\nNote that $\\Tp [fh] = \\Tp f \\Tp h$ might not\nhold on the discrete level. Also the question is how $J$ enters\non the discrete level. We have to multiply $\\sqrt{g}$ artificially when we form the adjoint.\nTheoretically $J$ could be hidden somehow when we integrate the fieldlines, so the information could be contained in the discrete version? (Maybe in the back-projection?)\n\nIf we integrate streamlines of the any vector field $\\vec v$, then we have\n\\begin{align}\n    \\frac{\\d J}{\\d \\varphi} = J(\\vec x ) \\nabla\\cdot\\vec v\n    \\label{}\n\\end{align}\nalong these streamlines~\\cite{something}.\nIf the streamlines are divergence free, we have $J=1$.\nA numerical test could be ( if we neglect the volume form in the adjoint)\n\\begin{align}\n    (\\Tp)^\\dagger \\left[J(\\vec x)\\Tp f(\\vec x)\\right] - f(\\vec x) = 0\n    \\label{}\n\\end{align}\nThe numerical computation of $J$ might a bit tricky at the boundaries.\nIn a flux-aligned $\\zeta, \\eta$ it should be feasible but in cylindrical coordinates I don't know how. Maybe we can simply cut the last few cells before the boundary.\nEven easier might be\n\\begin{align}\n    \\left(\\Tp\\right)^\\dagger J(\\vec x ) = 1\n    \\label{}\n\\end{align}\n\nFinally, let us assume that $\\vec v = \\bhat$ is the magnetic field\nunit vector. Then we have analytically $\\nabla\\cdot \\vec B= \\nabla_\\parallel^\\dagger B = 0$.\nNumerically, this is true if we have\n\\begin{align}\n\\left(\\Tp\\right)^\\dagger B^\\varphi  = \\left(\\Tm\\right)^\\dagger B^\\varphi = B^\\varphi\n\\end{align}\n\n\n\\section{Algorithm}\nGiven are the components $v^i(R,Z)$ for $i\\in\\{R,Z,\\varphi\\}$ and a compuational grid (in the following the ``coarse grid``)\n\\begin{itemize}\n  \\item generate a fine grid by multiplying the cell numbers of the given coarse grid topologcially (metric and Jacobian of the fine grid are not needed)\n  \\item integrate the fieldlines for the fine grid:\n    \\begin{itemize}\n      \\item evaluate the starting points on the \\textbf{coarse} grid in computational space\n      \\item For a curvilinear grid set up a (higher order, currently 7) grid for the\n        interpolation of the vector components $v^i$ and push forward the vector components\n        to the curvilinear coordinate system\n      \\item Integrate the fieldline equations\n\\begin{subequations}\n\\begin{align}\n\\frac{\\d \\zeta}{\\d\\varphi} &= \\frac{v^\\zeta}{v^\\varphi}\\\\\n\\frac{\\d \\eta}{\\d\\varphi} &= \\frac{v^\\eta}{v^\\varphi} \\\\\n\\frac{\\d s}{\\d\\varphi} &= \\frac{1}{v^\\varphi}\n\\end{align}\n\\label{eq:fieldlines_converted}\n\\end{subequations}\n    with the given starting points and $s=0$ from $\\varphi=0$ until $\\varphi = \\pm\\Delta \\varphi$. (Currently we use a Prince-Dormand method with stepsize control for this step).\n      \\item store the results in $s_{k+1}$ and $s_{k-1}$.\n      \\item create an interpolation matrix that interpolates from the coarse grid\n        to the fine grid\n      \\item use the interpolation matrix to generate the plus/minus points for the fine grid\n    \\end{itemize}\n  \\item create the interpolation matrices that interpolate from the given coarse grid\n    to the plus/minus points of the fine grid\n  \\item create a projection matrix that projects from the fine grid to the coarse grid\n  \\item compute the matrix-matrix multiplications $P\\cdot I^\\pm$ as well as their transposes\n\\end{itemize}\n\n\\paragraph{Notes on the MPI implmentation}\nIt is advantageous to construct $\\nabla_\\parallel^{fc}$\nas s row-distributed matrix with global indices.\nThis is because a column distributed matrix can be easily (without mpi-communication) multiplied\nwith a row distributed matrix especially if the indices are global indices.\nEach process just multiplies its local matrices.\n\\begin{align}\nM = C\\cdot R\n\\end{align}\nThis is not true if we started with a column distributed matrix.\nThe result is then a row distributed matrix with global indices.\nFrom the global indices the gather map/matrix and the local\nindices can be constructed.\nWe note here that we even don't need to construct the gather matrix\nfor $\\nabla_\\parallel^{fc}$, only the one for $\\nabla_\\parallel^c$ is\nneeded.\n\\section{Field aligned initialization} \\label{sec:parallelc}\n\nAn important aspect of our simulations is a judicious initialization of the\nfields. We want structures to be field-aligned in the beginning of the simulation with\na possible modulation along the direction of the field line.\nIf a Gaussian shape is used, we call $\\sigma_\\parallel$ the extension in parallel\ndirection and write\n\\begin{align}\n    f_0(R,Z,\\varphi) = F(R,Z,\\varphi) \\exp\\left( - \\frac{(\\varphi-\\varphi_0)^2}{2\\sigma_\\parallel^2}\\right),\n    \\label{eq:parallelInit}\n\\end{align}\nwhere $F$ is a function that is invariant under the field line transformations\n\\begin{subequations}\n\\begin{align}\n    \\Tp F(\\vec z) &= F( \\Tp \\vec z) \\overset{!}{=} F(\\vec z) \\text{ (pull-back),} \\\\\n    \\Tm F(\\vec z) &= F( \\Tm \\vec z) \\overset{!}{=} F(\\vec z) \\text{ (push-forward).}\n\\end{align}\n\\label{}\n\\end{subequations}\nWe can use these relations to construct aligned structures\nby active transformations of some given field.\nOur idea is to initialize a two-dimensional field $F(R,Z, \\varphi_k)$ in a given plane $k$ and\ntransform this field to all other planes using the recursive relations\n\\begin{subequations}\n\\begin{align}\n    F( R, Z, \\varphi_{k+1}) = \\Tm F( R, Z, \\varphi_{k+1}) = F(R^-, Z^-, \\varphi_k),\\\\\n    F( R, Z, \\varphi_{k-1}) = \\Tp F( R, Z, \\varphi_{k-1}) = F(R^+, Z^+, \\varphi_k),\n\\end{align}\n    \\label{eq:recursiveInit}\n\\end{subequations}\nwhich is the statement that $F$ in the next plane equals the push-forward\nand $F$ in the previous plane equals the pull-back of $F$ in the current plane.\nNote here that Eq.~\\eqref{eq:interpolation} applies for the required interpolation\nprocedures.\n\n\n\\section{Numerical tests}\nThe test programs for the parallel derivative are located in\n\\code{path/to/feltor/inc/geometries}.\nTo every shared memory test \\code{*\\_t.cu}\nthere is a corresponding distributed memory \\code{*\\_mpit.cu} program.\n\\code{ds\\_t.cu} tests the cylindrical grid\nwith boundary conditions.\n\\code{ds\\_guenther\\_t.cu} tests the cylindrical grid\nwithout boundary conditions i.e. no fieldline leaves the domain.\n\\code{ds\\_curv\\_t.cu} tests the implementation\non a flux-aligned grid again with no fieldline leaving the domain.\nFinally, \\code{ds\\_straight\\_t.cu} tests the implementation of\ncompletely straight fieldlines and the boundary conditions in the\nparallel direction.\n\nThe magnetic field in \\textsc{Feltor} is given by\n\\begin{align}\n  \\vec B = \\frac{R_0}{R}( I(\\psi_p) \\hat e_\\varphi + \\nabla\\psi_p \\times\\hat e_\\varphi)\n\\end{align}\nThis gives rise to magnetic field strength and components\n\\begin{align}\n  B = \\frac{R_0}{R} \\sqrt{ I^2 + \\left( \\nabla\\psi_p \\right)^2} \\\\\n  B^R = \\frac{R_0}{R}\\frac{\\partial\\psi_p}{\\partial Z} \\quad\n  B^Z = -\\frac{R_0}{R}\\frac{\\partial\\psi_p}{\\partial R}\\quad \n  B^\\varphi = \\frac{R_0I}{R^2} \\\\\n  \\nabla \\cdot\\bhat = -\\nabla_\\parallel \\ln B = -\\frac{R_0}{RB^2} [B, \\psi_p]  \n  \\label{}\n\\end{align}\nwhere $[.,.]$ is the Poisson bracket. Note that\nin order to compute analytical testfunctions we use\n\\begin{align}\n\\nabla_\\parallel f &= b^R\\partial_R f + b^Z\\partial_Z f + b^\\varphi \\partial_\\varphi f\\\\\n\\Delta_\\parallel f &= \\nabla\\cdot(\\bhat\\bhat\\cdot \\nabla f)\n= (\\nabla\\cdot\\bhat) \\nabla_\\parallel f + (\\nabla_\\parallel b^j) \\partial_j f\n+ b^ib^j\\partial_i \\partial_j f\n\\label{}\n\\end{align}\nwith\n\\begin{align}\n\\nabla_\\parallel b^R &= (\\nabla\\cdot \\bhat) b^R\n+ \\frac{\\psi_Z (\\psi_{RZ} - \\psi_Z/R) - \\psi_{ZZ}\\psi_R}{I^2 + (\\nabla\\psi)^2} \\\\\n\\nabla_\\parallel b^Z &= (\\nabla\\cdot \\bhat) b^Z\n+ \\frac{\\psi_R (\\psi_{RZ} + \\psi_Z/R) - \\psi_{RR}\\psi_Z}{I^2 + (\\nabla\\psi)^2} \\\\\n\\nabla_\\parallel b^\\varphi &= (\\nabla\\cdot\\bhat) b^\\varphi\n+ \\frac{\\psi_Z(I_R/R - 2I/R^2) - I_Z\\psi_R/R}{I^2 + (\\nabla\\psi)^2}\n\\label{}\n\\end{align}\nwhere we used $\\psi_R \\equiv \\partial \\psi_p /\\partial R$ and\n$I_R \\equiv \\partial I(\\psi_p) /\\partial R$.\n\n\\subsection{Cylindrical grid and boundary conditions}\nA simple but non-trivial choice for the poloidal flux is\n\\begin{align}\n  \\psi_p = \\frac{1}{2} \\left( (R-R_0)^2 + Z^2 \\right) \\equiv \\frac{1}{2} r^2\n  \\label{eq:circular}\n\\end{align}\nWe choose $R_0 = 10$ and $I=20$ in order to keep the q-factor for the $r=1$ flux surface at $2$.\nWe set up a domain\n$R\\in[R_0-1, R_0+1]$,\n$Z\\in[-1,1]$ and\n$\\varphi \\in [0,2\\pi]$ and choose\n\\begin{align}\n    f(R,Z,\\varphi) = (\\cos(\\pi (R-R_0))+1)( \\cos(\\pi Z /2)+1)\\sin(\\varphi)\n  \\label{}\n\\end{align}\nOn the chosen domain $f$ respects both Neumann and Dirichlet boundary conditions\nboth along the field and perpendicular to the wall.\nIn Tables~\\ref{tab:ds_cylindrical_dirichlet1} and\n\\ref{tab:ds_cylindrical_dirichlet10} we show the convergence of the solution\nfor various operators and Dirichlet boundary conditions. Note that the same\ntables for Neumann boundary conditions exhibit similar values.\nApparently, the discretization for the divergence does not converge even if we\nincrease the refinement.\n\n\\begin{table*}[ht]\n\\begin{centering}\n\\footnotesize\n\\hspace*{-2cm}\n\\input{ds_cylindrical_dirichlet1.tex}\n\\caption{Convergence Table for Dirichlet boundary conditions and $m=1$,\n$N_R=N_Z=N$. Centered discretization with boundary conditions along the fieldline. The table for Neumann conditions exhibits similar numbers.}\n\\label{tab:ds_cylindrical_dirichlet1}\n\\end{centering}\n\\end{table*}\n\n\\begin{table*}[ht]\n\\begin{centering}\n\\footnotesize\n\\hspace*{-2cm}\n\\input{ds_cylindrical_dirichlet10.tex}\n\\caption{Convergence Table for Dirichlet boundary conditions and $m=10$,\n$N_R=N_Z=N$. Centered discretization with boundary conditions along the fieldline. The table for Neumann conditions exhibits similar numbers.}\n\\label{tab:ds_cylindrical_dirichlet10}\n\\end{centering}\n\\end{table*}\n\n\\subsection{The G\\\"unther field}\nA simple choice for the flux function that makes fieldlines stay\ninside a square box is\n\\begin{align}\n  \\psi_p = \\cos(\\pi (R-R_0)/2) \\cos(\\pi Z /2)\n\\label{}\n\\end{align}\nAgain, we set up a domain\n$R\\in[R_0-1, R_0+1]$,\n$Z\\in[-1,1]$ and\n$\\varphi \\in [0,2\\pi]$ and choose\n\\begin{align}\n  f_1(R,Z,\\varphi) = -\\psi_p(R,Z)\\cos(\\varphi)\\\\\n  f_2(R,Z,\\varphi) = -\\psi_p(R,Z)\\cos(\\varphi) + (R-R_0)^2/4 + Z(R-R_0)/4\n  \\label{}\n\\end{align}\n\\begin{table*}[ht]\n\\begin{centering}\n\\footnotesize\n\\hspace*{-2cm}\n\\input{ds_guenther10.tex}\n\\caption{Convergence Table for $m=10$ and $N_R=N_Z=N$ and the G\\\"unther field. Centered discretizations, no boundary condition.\n}\n\\label{tab:ds_guenther10}\n\\end{centering}\n\\end{table*}\n\\subsection{Curvilinear grid}\nHere we choose the general Solov'ev equilibrium for\n$\\psi_p$ and choose to use $f_1$ or $f_2$ again.\nWe use the simple orthogonal flux to construct\ngrids on the ring bounded by $\\psi_p=-20$ and $\\psi_p=-4$.\n\\begin{table*}[ht]\n\\begin{centering}\n\\footnotesize\n\\hspace*{-2cm}\n\\input{ds_curv1000.tex}\n\\caption{Convergence Table for $m=1000$, $N_R = 2$, $N_Z=N$ on a curvilinear grid. Centered discretizations, no boundary condition.\n}\n\\label{tab:ds_curv1000}\n\\end{centering}\n\\end{table*}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Performance considerations}\nThe performance of the main matrix-vector multiplication depends, as do all our\nroutines, on the number of memory loads and stores per vector element.\nA dG interpolation matrix in two dimensions has $n^2$ points per line since\nit uses all $n^2$ points in one dG-cell to compute the result.\nA matrix-vector multiplication with the interpolation matrix thus needs $n^2+3$\nvector loads and stores, with the $3$ coming from loading the input vector and\nloading and storing the output vector.\nHowever, since we use the refinement-projection aproach to our discretization\nthe number of points per line of the interpolation matrix increases to typically\n$4n^2$ since now also neighboring cells are used for the computation.\n\nFor the discretization of $\\nabla_\\parallel$ this in total means that the number\nof memory operations per element is\n\\begin{align}\nm &= 2\\cdot(4n^2+3)+5\\quad \\text{ (refined)} \\\\\nm &= 2\\cdot(n^2+3)+5\\quad \\text{ (unrefined)}\n\\end{align}\nwith $n$ the number of polynomial coefficients.\nThis is comparable to one iteration of a CG method in three dimensions.\n\n\n\n\n\n%..................................................................\n\\bibliography{../references}\n%..................................................................\n\n\n\\end{document}\n\n", "meta": {"hexsha": "94ff9fe721db16b8d4dac710dd51d9f942c07cd5", "size": 33819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/related_pages/parallel/parallel.tex", "max_stars_repo_name": "gregordecristoforo/feltor", "max_stars_repo_head_hexsha": "d3b7b296e6f5be3a9ff9d602d98461ed9c60033a", "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": "doc/related_pages/parallel/parallel.tex", "max_issues_repo_name": "gregordecristoforo/feltor", "max_issues_repo_head_hexsha": "d3b7b296e6f5be3a9ff9d602d98461ed9c60033a", "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": "doc/related_pages/parallel/parallel.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": 48.3128571429, "max_line_length": 207, "alphanum_fraction": 0.7112274165, "num_tokens": 10263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6504439846912324}}
{"text": "\\section{A Distance Sensitive Encoding Protocol}\n\n\\subsection{Idea}\n\nIn the previous section we discussed various LDP Protocols that function extremely well for numerical values (histogram type), with accuracy that is completely acceptable. However, when the number of users is limited, (eg under 1000), we made the observation that the accuracy error is extremely large. This is mainly due to the fact that the probability of an item to be chosen is independent of the distance between the true and the selected value.\n\n\nThus, for the needs of this Thesis, a new L.D.P. protocol was constructed. The idea proposed is to \\emph{have the probability of choosing an element of the domain to depend on the distance from the true value}. This could prove very helpful for histogram values, but does not make any sense for categorical values. From now on, we are going to focus on histogram values.\n\nBased on our idea, the probabilities' distribution, in comparison with the distribution of the D.E. protocol, will look like the one in the following figures.\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=0.5\\textwidth]{images/D.E. Idea.png}\n    \\caption{D.E. protocol's Probabilistic Distribution}\n\\end{figure}\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=0.5\\textwidth]{images/Our Idea.png}\n    \\caption{Distance Sensitive protocol's Probabilistic Distribution}\n\\end{figure}\n\n\nThus, there is an area around the true value that has high probability to be selected. The width of this area(from now on $\\theta$) is defined by the epsilon setting that the user wants to use. The idea for having a specific area and not decreasing our probabilities as low as it goes when we diverge from the true value, is based on our need to be able to serve low epsilon values, as the first would be a big no for when the users want to use a high privacy setting.\n\n\\subsection{Mathematical Background}\n\nIn order to achieve our goal, when in the selected area, we should include in the denominator the quantity \n$$\n|x - i|\n$$\nwhere x is the true value, and the i the false one that we are looking at in order to report it, in order for the probability to depend on the distance of the reported values.\n\nWhen we are out of this area, the denominator will have a constant value, proportional to the boundaries of the selected area. \n\n\\emph{Example}: Let's suppose that we have a domain size of 100, and our $\\theta$ value is 4. All the probabilities outside the area, should be in reverse proportion of $\\theta$, thus 4.\n\nLike all probabilistic algorithms though, the sum of the probabilities for all the items in the domain size, must be 1. Thus if we chose the probability to be in the shape of $\\frac{a}{|x-i|}$, the partial sum of the series will not give as simple results.\n\nIt is known that the series in the form of $a_n = \\frac{1}{n}$ does not converge, and its partial sums can only be computed using a complex approximation formula. These characteristics make this type of series very hard to use, and so we have to think of a more handy type.\n\n\nA type of series that is known to have easy to compute partial sums, are the telescopic series, such as $b_n = \\frac{1}{n (n+1)}$. It is known that \n$$\n\\sum_{n = 1}^{n = k} b_n = 1 - \\frac{1}{k + 1}\n$$\nsomething that will prove extremely useful moving forward.\n\nSo, taking into consideration the quantity $|x - i|$ and the telescopic series $b_n$, we conclude that the probability of each non-true element in our selected area will be of the shape:\n\n\\begin{align}\n    \\mathbf{q = \\frac{a}{|x-i|(|x-i| + 1)}}\n\\end{align}\nand outside of that area:\n\n\\begin{align}\n    \\mathbf{s = \\frac{a}{\\theta \\cdot (\\theta + 1)}}\n\\end{align}\n\nThe probability $p$ of selecting the true value will have to meet specific criteria that we are going to define later on.\n\n\\subsection{Building the Protocol}\nWw are now going to find what the alpha parameter will be, as it is not constant, but clearly it depends on the domain size and the probability $p$. In order to find it, we must keep in mind that all the probabilities of selecting an item from our domain, must add up to $1$.\n\nIn order to find out the $\\alpha$ value, we must solve the following equation:\n\n\\begin{align*}\n    p + \\sum_{i = x - \\theta}^{i = x + \\theta} q + \\sum_{i = 1}^{i = x - \\theta -1} s + \\sum_{i = x + \\theta + 1}^{i = d} s = 1\n\\end{align*}\n\nAt this point, we must note that $\\alpha$ although not a constant, can be held out of the sums, because it is obviously independent from the $i$ variable, that is the variable parsing through the domain in order to retrieve the false elements' probabilities. Thus, we have:\n\n\\begin{align*}\n        p + \\sum_{i = x - \\theta}^{i = x + \\theta} q + \\sum_{i = 1}^{i = x - \\theta -1} s + \\sum_{i = x + \\theta + 1}^{i = d} s = 1 \\Longleftrightarrow \\\\\n      \\sum_{i = x - \\theta}^{i = x + \\theta} \\frac{a}{|x-i|(|x-i| + 1)} + \\sum_{i = 1}^{i = x - \\theta -1} \\frac{a}{\\theta(\\theta+1)} + \\sum_{i = x + \\theta + 1}^{i = d} \\frac{a}{\\theta(\\theta+1)} = 1 - p \\Longleftrightarrow \\\\ \\dots \\Longleftrightarrow \\\\ \n    a = \\frac{\\theta(\\theta + 1) (1 - p)}{2\\theta^2 - 2\\theta + d - 1}\n\\end{align*}\n\nThe proof for the mathematical equations leading to the extraction of the alpha value, can be found in the First Appendix of the Thesis.\n\n\\subsection{Epsilon Requirements}\n\nThe epsilon value is the most essential in these protocols, as it determines the privacy level that the protocol yields.\n\nRecalling the definition of LDP, we must follow the following rule:\n\n\\begin{center}\nAn algorithm $A$ satisfies \\espilon-LDP \\textit{iff} for any input $v_1$ and $v_2$, we have\n\\begin{align*}\n    \\forall y \\in Range(A): \\frac{Pr[A(v_1) = y]}{Pr[A(v_2) = y]} \\leq e^{\\epsilon}\n\\end{align*}\n    \n\\end{center}\n\nThus, in order to determine the epsilon value for our algorithm, it must satisfy even the worst case of this equation. The fraction gets bigger, if we put on the biggest probability on the numerator, and the smallest probability of all in the denominator. \n\nThe numerator must have the probability $p$, and the denominator $s$, the probability of all of the elements outside of the $\\theta$ area. \n\nWe want for $p$ to be the biggest probability among all, but not extremely high, in order to be able to restrict the growth of epsilon. Hence, we are going to set it as double of the probabilities of its exact neighbours. The 2 neighbours have $|i-x| = 1$, thus $q = \\frac{a}{2}$, so we are going to set $\\mathbf{p = 2 \\cdot \\frac{a}{2} = a}$, where $a$ is the quantity defined above, depending on the domain size, and the $\\theta$ value.\n\nNow, if we set $p = a$, then the $a$ equation changes, and now our aplha parameter only depends on the domain size and the $\\theta$ selected. So, we proceed as following:\n\\begin{align*}\n    a = \\frac{\\theta(\\theta + 1) (1 - p)}{2\\theta^2 - 2\\theta + d - 1} \\Longleftrightarrow{(p = a)}\\\\\n    a = \\frac{\\theta(\\theta + 1) (1 - a)}{2\\theta^2 - 2\\theta + d - 1} \\Longleftrightarrow \\\\\n    a (2\\theta^2 - 2\\theta + d - 1) = \\theta(\\theta + 1) - (\\theta^2 + \\theta)a \\Longleftrightarrow\\\\\n    a (3\\theta^2 - \\theta + d - 1) = \\theta(\\theta + 1) \\Longleftrightarrow \\\\\n    \\mathbf{a = \\frac{\\theta(\\theta + 1)}{3\\theta^2 - \\theta + d - 1}}\n\\end{align*}\n\nObviously, we observe the constraint that $\\theta > 0$, and this is a special case of our protocol, that can be represented by the direct encoding protocol.\n\nWe now have:\n\n\\begin{align*}\n    \\frac{Pr[A(v_1) = y]}{Pr[A(v_2) = y]} = e^{\\espilon} \\Longleftrightarrow \n    q e^{\\epsilon} = p \\Longleftrightarrow \\\\\n    \\frac{a}{\\theta(\\theta + 1)} \\cdot e^{\\epsilon} =  a \\Longleftrightarrow \\\\\n    \\theta(\\theta + 1) = e^{\\epsilon} \\Longrightarrow \\\\\n    \\theta^2 + \\theta - e^\\epsilon = 0\n\\end{align*}\n\nIf we solve the quadratic equation, and reject its one (illegal) solution, we get that:\n\n\\begin{align}\n    \\theta = \\lfloor \\frac{\\sqrt{4e^{\\epsilon} + 1} - 1}{2}\\rfloor\n\\end{align}\n\nSo, to conclude, in order for the protocol to function, the user must provide just the epsilon setting, from which the $\\theta$ constant is computed, and so the probabilities for each item of the domain will be selected.  \n\n\n\\subsection{Protocol Definition}\n\nWe are now ready to define our protocol, by determining the 3 basic operations for an LDP protocol, the \\emph{encoding}, the \\emph{perturbation} and the \\emph{aggregation methods}.\n\n\nWe are going to use the following symbols:\n\\begin{itemize}\n    \\item $D$: The protocol's domain. In this set, we have each $i$ for $1 \\leq i \\leq |D|$ as each item in the domain $D$\n    \\item $a$: The quantity that we computed in the previous section\n    \\item $\\theta$: The constant used in the previous section, which denotes the area around the true value that the probabilities will be higher than others.\n    \n\\end{itemize}\n\n\\textbf{Encoding:} The encoding procedure is trivial. Just like the Wang paper, we are just going to set:\n\\begin{align*}\n    Encode(v) = v\n\\end{align*}\n\nfor each value $v$ of the domain. The values are going to be randomized during the perturbation step.\n\n\\textbf{Perturbation:} Given the previous section, the randomization during the perturbation step is define as following:\n\n\\begin{equation*}\n    Pr[Perturb(x) = i] =\n\t\\begin{cases}\n\t\tp = a & \\mbox{if } i = x \\\\\n\t\tq = \\frac{a}{|c|(|c| + 1)}  &  c = \\min{(\\theta, |i-x|)}  \\mbox{, otherwise}\t\\end{cases}\n\\end{equation*}\n \nwhere $i$ is the value selected each time, and $x$ our initial selection. \n\n\\textbf{Aggregation:} The aggregation step was the most tricky during the building of the protocol. A similar approach to the aggregation of pure protocols was chosen, but with a few changes. After several different tries, the optimal aggregation found, was the following: the protocol supports only the reported values corresponding to the true one, thus $Support(v) = v$. However, the $p^*$ quantity is the sum of all the probabilities inside the area: \n\n\\begin{align*}\n    p^* = \\sum_{x\\in (-\\theta, \\theta)} p(x)\n\\end{align*}\n\nFinally, the $q*$ quantity is the probability of choosing an element from outside the θ area, thus equal to $s$. Hence, the estimation generated for a value $v$ of the possible answers in the domain is defined as following:\n\n\\begin{align*}\n    \\text{Estimation} = \\frac{\\sum_{j} 1_{support(v^j)}(i) - nq^*}{p^* - q^*}\n\\end{align*}\n\n\\subsection{Extreme Cases}\n\nThe downside of a complicated protocol, are of course some extreme cases for the $x, \\theta \\text{ and } i$ values, all of which we are going to examine in this chapter. The definition of the protocol is going to be altered, and the constraints increased, in order to support those extreme cases.\n\n\\textbf{Extreme theta cases:} Of course, we have the constraint that $0 < \\theta \\leq d$, but what happens when its value is equal to one of the bounds?\n\\begin{itemize}\n    \\item When $\\theta \\leq 0$, our protocol can not function, as this assignment will result in $a = 0$, something that is prohibited, because the probabilities will not sum to 1. In order to ensure that $\\theta$ is at least 1, the user must provide at least an $\\epsilon = ln(2)$.\n    \n    \\item When $\\theta = 1$, we can see that the third case in the perturbation step does not exist, thus we have only the first 2 cases. There, $p = a = \\frac{2}{d+1}$, and for every other $i$, $q = \\frac{a}{2}$, something that is similar with the Direct Encoding protocol.\n    \n    \\item When $\\theta = d$, which realistically can only happen when d is extremely small, then our protocol functions as designed, and has its best behavior. However, if the selection of epsilon results in such big a theta, then the user does not have extreme privacy demands.\n\\end{itemize}\n\n\\textbf{Extreme x values:} Even when the epsilon value and the domain size are normal, in some cases we might face a certain difficulty: if $x - \\theta < 0$ or $x + \\theta > d$, some of the items in our area are actually outside of our domain boundaries. This results in the sum of the items in the probabilistic distribution to be below 1, something not acceptable. \n\nIn order to fix it, we are going to \"transfer\" those probabilities inside the boundaries of our domain, while not messing with the highest probability, as this would result in problems with the definition of D.P., an thus the value of theta. \n\nThe idea is to increase the other selections' probabilities by a bit, in order to fill the gap created, while leaving the maximum as initially created. We are going to boost all of the domain's items, by a portion of $\\frac{m}{d - 1}$ (as we are altering $d-1$ elements), where $m$ is the sum of the probabilities of the items outside the bounds of our domain. \n\nHowever, we are not interested in transferring the whole $Pr[Perturb(x) = i]$, but only its difference from the item with the lowest probability, which is $s =  \\frac{a}{\\theta(\\theta+1)}$. Thus, the $m$ values are defined as following:\n\\begin{align*}\n    m = \\sum_{i < 0 \\bigcup |i-x|<\\theta} Pr[Perturb(x) = i] - \\frac{a}{\\theta(\\theta+1)}\n\\end{align*}\n\nfor the case of $x - \\theta < 0$, and as \n\n\\begin{align*}\n    m = \\sum_{i \\geq d \\bigcup |i-x|<\\theta} Pr[Perturb(x) = i] - \\frac{a}{\\theta(\\theta+1)}\n\\end{align*}\n\nfor the second one.\n\\\\\\bigskip\nNow, the probabilistic distribution can be altered as following: \n\n\n\\begin{equation*}\n    Pr[Perturb_{DS}(x) = i] =\n\t\\begin{cases}\n\t\tp = a & \\mbox{if } i = x \\\\\n\t\tq = \\frac{a}{|c|(|c| + 1)} + \\frac{m}{d - 1}  &  c = \\min{(\\theta, |i-x|)}  \\mbox{, otherwise}\t\\end{cases}\n\\end{equation*}\n \n\nThe definition of D.P. is not altered, because again in the best case we have a probability of $p = a$, and in the worst case $s = \\frac{a}{\\theta(\\theta+1)}$.\n\n\\subsection{Implementation}\n\nThe most difficult part of the implementation of our protocol consists of creating the probabilistic distribution for each element of the domain, depending on the true value. This can prove to be costly, if we have a large domain or if we are in the case of the extreme x values.\n\nHowever, we do not need to compute every single probability, as it is clear from the definition that they are independent from the true value: they only depend on $a$ (and on the domain size in case of an extreme x value). The quantity $|i - x|$ can only take values in the range of $[1,\\theta]$, thus constant for every possible true value. Moreover, for the domain values outside of the area, the probability is fixed and equal to $\\frac{a}{\\theta(\\theta + 1)}$. Hence, the probabilities can be computed in advance, either by each user, or given to the protocol by the aggregator. \n\nThe protocol has been implemented using Python, and can be found in the GitHub repository of this Thesis. Moving forward, we are going to use this implementation in order to conduct some testings to ensure the protocol's functionality.\n\n\\subsection{Experiments}\nFirst up, we are going to perform the epsilon measurements that we did for the other protocols, this time excluding the Random Matrix approach, and including the D.S. protocol. The results, when running with the Kantorovich metric, are the following:\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/epsilon_our_kant.png}\n    \\caption{Epsilon measurements for D.S. protocol compared by Kantorovich Distance}\n\\end{figure}\n\nThe first observation is the \\emph{strange form of the curve of our protocol}. This can be easily explained: the theta value used to determine the area around the true value, is depended on epsilon, but has a floor function applied to it. Thus, for a specific range of ε, the protocol produces the same results. \n\nAn other observation is that\\emph{ our protocol lacks efficiency for low values of epsilon}, that is natural, since small θ values do not help our idea at all. However, when epsilon gets higher than 1.5 (and thus theta rises above 2), the results are more than satisfying: \\emph{our protocol has the best behaviour for epsilon in the range of $\\mathbf{(2, 2.5)}$.}\n\nThe real test though, is how our protocol behaves for an increasing number of users: we must check if it produces better accuracy error than the competitors. This is our next testing, where we are going to set $\\epsilon = \\ln(20)$, in order for the conditions to be favorable for each one of the protocols. The results are shown in the \\textbf{Figure 4.10}.\n\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/users_our_kant.png}\n    \\caption{Increasing users measurements for D.S. protocol compared by Kantorovich Distance}\n\\end{figure}\n\nFor the specific epsilon setting, \\emph{our protocol produces extremely good accuracy error for a small number of users.}, beating by a lot the U.E. protocol. The comparisons have been made using the Kantorovich metric, the most characteristic of them all, as it takes into account the distance between the real answers and the projections, exactly what our protocol is designed to do. However, we are also going to perform the same testings using the Manhattan metric. The results are shown in the \\textbf{Figure 4.11}.\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/users_our_l1.png}\n    \\caption{Increasing users measurements for D.S. protocol compared by Manhattan Distance}\n\\end{figure}\n\nThe results of the Manhattan-driven tests are similar to the ones made with the Kant. metric. However, we observe that \\emph{when the number of users rises, our protocol has worse behaviour in comparison to the other pure ones}. This happens mainly because of the other protocols, that by the law of big numbers, have good accuracy because of the higher probability of choosing the true answer. On the other hand, in our protocol, this probability is reduced and shared with the other elements in the area covered by theta. \n\n\\subsection{Conclusions}\nIn general, \\emph{the D.S. protocol succeeds when the number of the participants in a survey is extremely low}, and functions similarly with the other protocols for an increasing number of users. The downside is that it does not always takes full advantage of the epsilon setting, as explained in a previous section. However, the results are more than satisfying. Hence, \\emph{this is a fully functioning protocol that can be used for the application of L.D.P., especially in a situation when few people take part in the survey.} The protocol will be further tested in more extreme cases, but this is beyond the scope of this Thesis.\n", "meta": {"hexsha": "5780068ded5810acc5d3466f08fdac5fbc15d97b", "size": 18406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis_paper/LDP/our_protocol.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/our_protocol.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/our_protocol.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": 71.6186770428, "max_line_length": 633, "alphanum_fraction": 0.7298706943, "num_tokens": 4874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289535, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6504439704205814}}
{"text": "\\section{MST vs. Shortest Path}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Sharing edges}\n  \\begin{exampleblock}{Sharing edges (Problem 6.6)}\n\t\\begin{itemize}\n\t  \\item $G = (V, E), w(e) > 0$\n\t  \\item Given $s$: all sssp trees from $s$ must share some edge with some MST of $G$\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\vspace{0.60cm}\n  \\centerline{a lightest edge leaving $s$}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{SP \\emph{vs.} MST}\n  \\begin{exampleblock}{SP \\emph{vs.} MST (Problem 6.10--6)}\n\t\\xmark\\; The shortest path between two nodes is necessarily part of some MST.\n  \\end{exampleblock}\n\n  \\vspace{0.50cm}\n  \\begin{exampleblock}{SPT \\emph{vs.} MST (Problem 6.17)}\n\t\\xmark\\; The shortest-path tree computed by Dijkstra's algorithm is necessarily an MST.\n  \\end{exampleblock}\n\n  \\fignocaption{width = 0.20\\textwidth}{figs/mst-sssp.pdf}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Edge weights}\n  \\begin{exampleblock}{Edge weights (Problem 6.19)}\n\tMST \\emph{vs.} SPT (from $s$):\n\t\\[\n\t  w(e) \\ge 0, w'(e) = w(e) + 1\n\t\\]\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "d7e4e5bba2f368b5838c5511869e640e9308493a", "size": 1080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/alg-tutorial-mst-20170531/sections/mst-sp.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-sp.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-sp.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.4210526316, "max_line_length": 88, "alphanum_fraction": 0.6203703704, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6504439691576543}}
{"text": "\\section*{\\hypertarget{_some_equations}{Some Equations}}\n\n\\subsection*{\\hypertarget{_number_theory}{Number Theory}}\n\nThe equation\n$a^2 + b^2 = c^2$ has infinitely many\nnon-proportional integer solutions.\nThe integer solutions of the equation\n\\[\n  a^3 + b^3 = c^3\n\\]\nare trivial: at least one entry is\nzero and the others are \"obvious\"\n\n\n\n\n\\subsection*{\\hypertarget{_calculus}{Calculus}}\n\nA definite integral:\n\\[\n  \\int_0^1 x^n dx = \\frac{1}{n}\n\\]\n\n\nThe fundamental theorem of calculus:\n\\[\n   \\frac{d}{dx} \\int_a^x f(t) dt = f(x)\n\\]\n\n\n\n\n\\subsection*{\\hypertarget{_linear_algebra}{Linear algebra}}\n\nA matrix:\n\\[\nM = \\left[\n  \\begin{array}{ c c }\n\t 1 & 2 \\\\\n\t 3 & 4\n  \\end{array} \\right]\n\\]\n\n\n\n\n\n\n", "meta": {"hexsha": "86697a24ebeba658dd0914a237c5bd6011702ad0", "size": 694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "test/examples/tex/eq-latex.tex", "max_stars_repo_name": "thecsw/asciidoctor-latex", "max_stars_repo_head_hexsha": "c0c2b49fa2c87ef82576b6e69accd0023fcfb0af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 104, "max_stars_repo_stars_event_min_datetime": "2015-01-17T19:04:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T18:49:03.000Z", "max_issues_repo_path": "test/examples/tex/eq-latex.tex", "max_issues_repo_name": "thecsw/asciidoctor-latex", "max_issues_repo_head_hexsha": "c0c2b49fa2c87ef82576b6e69accd0023fcfb0af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2015-01-04T12:42:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T06:22:15.000Z", "max_forks_repo_path": "test/examples/tex/eq-latex.tex", "max_forks_repo_name": "thecsw/asciidoctor-latex", "max_forks_repo_head_hexsha": "c0c2b49fa2c87ef82576b6e69accd0023fcfb0af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 35, "max_forks_repo_forks_event_min_datetime": "2015-01-02T13:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-20T15:32:10.000Z", "avg_line_length": 13.88, "max_line_length": 59, "alphanum_fraction": 0.6628242075, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.650388121544353}}
{"text": "\\chapter{Localization}\n\\label{chp:local}\n\nThe localization problem, also known as position estimation or position tracking, is the most basic perceptual problem in robotics.\nThis is because some kind of knowledge about the location of the robot or other objects around the robot are required for almost all robotic tasks.\nThe core principle of robot localization can be seen as a problem of coordinate transformation.\nThe robot will always exist in some kind of \"world map\" with a global coordinate system, that is independent from the robot own pose - position and orientation.\nBeing able to express an object of interest from the world map, in the robots own coordinate frame is essential for robot navigation.\nThe robot pose is therefore needed to be able to do a correct coordinate transformation.\nHerein lies two problems.\nFirst the robot can't measure a perfect pose directly, but instead have to extract that information from noisy sensor data, and second a single measurement often isn't sufficient to do a pose estimate, and the robot instead have to integrate data over time to determined the pose.\n\nThis leads to the sense move cycle seen on figure \\ref{fig:sense_move_cycle}.\nHere the location og the robot is modelled as a probability distribution, because both sensing and moving is noisy actions that cannot guarantee a perfect result.\nEach time the robot do a sensor measurement information is gained in the probability distribution of the robot location, and each time the robot moves information is lost in the probability distribution of the robot location.\n\n\\myFigure{Theory/Localization/sense_move_cycle}{This figure show the basic cycle of localization, with the two steps sense and move. When sensing information is gained about the robots location, and when moving information is lost about the robots location.}{fig:sense_move_cycle}{0.9}\n\n\\section{Markov localization}\n\nThe Markov localization algorithm is a multimodal probabilistic model with a discrete state space.\nThis basically means a multi dimensional grid, where each tile have a probability of the robot being in that specific tile.\nFigure \\ref{fig:markov_localization_code} show the basic steps in the Markov localization algorithm.\nThough a cycle of sensing and measuring the probability of the robot being in each tiles is updated in each iteration og the algorithm.\n\n\\myFigure{Theory/Localization/markov_localization_code}{Basic implementation of Markov localization.}{fig:markov_localization_code}{0.7}\n\nLine 4 in figure \\ref{fig:markov_localization_code} is the sensing step, which is based on Bayes' theorem.\nThe algorithm is iterating though all tiles in the state space, and calculating the probability of being in that tile given a sensor measurement.\nBayes' rule state that the posterior state estimate is the product of the prier state estimate times the measurement probability given the prier state estimate, normalized by the total measurement probability of the entire state space.\n\n\\begin{equation}\n\\label{eq:Bayes_theorem}\nP(X_{i}^{t} \\mid Z^{t}) = \\frac{P(Z^{t} \\mid X_{i}^{t}) * P(X_{i}^{t})}{\\sum_{j} P(Z^{t} \\mid X_{j}^{t}) * P(X_{j}^{t})}\n\\end{equation}\n\nLine 3 in figure \\ref{fig:markov_localization_code} is the movement step, which is based on the theorem of total probability seen in equation \\ref{eq:total_probability}.\nThe algorithm is iterating though all tiles in the state space, and calculating the total sum of all possible way to end up in that tile based on the probability of the motion.\n\n\\begin{equation}\n\\label{eq:total_probability}\nP(X_{i}^{t}) = \\sum_{j} P(X_{j}^{t-1}) * P(X_{i}^{t} \\mid X_{j}^{t-1})\n\\end{equation}\n\n\\pagebreak\n\nFigure \\ref{fig:markov_localization_example} show the Markov localization algorithm in action when preforming measurements and movements.\nIt can be seen that the robot gets an increasing better position estimate after each measurement.\n\n\\myFigure{Theory/Localization/markov_localization_example}{Example of Markov localization algorithm. Each picture depicts the robots position in a hallway, together with a probability distribution of where the robot believe it is and the probability of the measurement. a) Starts with a uniform distribution. b) and d) Acquire a more precise probability distribution by making a measurement. C) and e) Movement result in less accurate probability distribution.}{fig:markov_localization_example}{0.7}\n\nIn general Markov localization is a good algorithm for localization, and it gives the ability of model multi-modal probabilities, but as an expense in memory because the probability of every tile in the state space have to be calculated.\nThis means that Markov localization is not a good choice in cases with a many dimensional state space.", "meta": {"hexsha": "6b2d2b141860bed4f4c3a3afc4b2e77a10a4704a", "size": 4735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/Localization.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/Localization.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/Localization.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": 89.3396226415, "max_line_length": 499, "alphanum_fraction": 0.8027455121, "num_tokens": 1029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6503881188605376}}
{"text": "% arara: pdflatex\n% arara: bibtex\n% arara: pdflatex\n% arara: pdflatex\n\\documentclass{article}\n\n\\usepackage{graphicx}  % for including graphics\n\\usepackage{amsmath}   % math symbols like operator notation\n\\usepackage{siunitx}     % properly format quantities with units\n\\usepackage{fancyhdr}  % control headers\n\\usepackage{physics}\n\\usepackage{fullpage}\n\n\\title{Numerical Evaluation of the Arrhenius Integral}\n\\author{C.D. Clark III}\n\n\n\\begin{document}\n\\maketitle\n\nThe Arrhenius\nIntegral model for thermal damage requires the evaluation of the integral\\cite{WELCH--2011--optical-thermalresponseoflaser-irradiatedtissue}\n\\begin{equation}\n  \\label{eqn:arr}\n  \\Omega\\qty(\\tau) = \\int\\limits_{0}^{\\tau} A e^{\\frac{-Ea}{RT\\qty(t)}} dt.\n\\end{equation}\nIf the temperature, $T\\qty(t)$, is predicted using a numerical simulation, i.e. a finite-difference or finite-element model, then the temperature is calculated at a discrete set of times, $(t_0, t_1,\n\\ldots)$. This limits the methods that can be used to evaluate Eq. \\ref{eqn:arr} numerically to those that work on predefined nodes (Gaussian quadrature, for example, cannot be used).\n\nThe usual methods for numerically evaluating an integral with pre-defined nodes would be Reimann sum, Trapezoid Rule,\nand Simpson's Rule. These methods are simple to implement, but approximate the integrand as piece-wise, linear, and\nparabolic, respectivly.\n\n\n\n\\section{Recasting the integral}\nIf we assume that the temperature between two times, $t_0$ and $t_1$ can be written as a linear function of time,\n\\begin{equation}\n  T\\qty(t) = mt + T_0\n\\end{equation}\nand inserting into this into Eq. \\ref{eqn:arr} gives,\n\\begin{equation}\n  \\Omega = \\int\\limits_{t_0}^{t_1} A e^{\\frac{-Ea}{R\\left(mt + T_0\\right)}} dt.\n\\end{equation}\nChanging the integration variable to $T$,\n\\begin{align}\n  dT &= mdt \\\\\n  \\Omega &= \\int\\limits_{T_0}^{T_1} \\frac{A}{m}e^{\\frac{-Ea}{RT}} dT.\n\\end{align}\nWhere $T_0$ and $T_1$ are the temperature at $t_0$ and $t_1$. Next, we substitute $u = \\frac{E_a}{RT}$ and change the integration variable again to $u$.\n\\begin{align}\n  u &= \\frac{E_a}{R} \\frac{1}{T}  \\\\\n  du &= -\\frac{E_a}{R} \\frac{1}{T^{2}} dT  \\\\\n  dT &= -\\frac{E_a}{R} \\frac{1}{u^{2}} du  \\\\\n  \\Omega &= -\\frac{A}{m}\\frac{E_a}{R} \\int\\limits_{E_a / R T_0}^{E_a / R T_1} \\frac{e^{-u}}{u^2} du  \\\\\n  \\label{eqn:arr_2}\n         &=  \\frac{A}{m}\\frac{E_a}{R} \\int\\limits_{E_a / R T_1}^{E_a / R T_0} \\frac{e^{-u}}{u^2} du.\n\\end{align}\nThe integrand can be evaluated ``analytically'' using the \\emph{exponential integral}, $E_n$, which is defined as\\cite{1970--handbookofmathematicalfunctionswithformulas}\n\\begin{equation}\n  E_n\\qty(x) = \\int\\limits_{1}^{\\infty} \\frac{e^{-xt}}{t^n} dt\n\\end{equation}\nThe variable substitution $y = xt$ gives\n\\begin{align}\n  dy &= xdt \\\\\n  dt &= \\frac{1}{x}dy \\\\\n  E_n\\qty(x) &= x\\int\\limits_{x}^{\\infty} \\frac{e^{-y}}{y^n} dy\n\\end{align}\nComparing this to Eq. \\ref{eqn:arr_2}, it is simple to show that\n\\begin{align}\n  \\Omega &= \\frac{A}{m}\\frac{E_a}{R} \\left[\\frac{E_2\\qty{E_a/RT_1}}{E_a/RT_1} - \\frac{E_2\\qty{E_a/RT_0}}{E_a/RT_0}\\right] \\\\\n         &= \\frac{A}{m}              \\left[T_1 E_2\\qty{E_a/RT_1}              - T_0 E_2\\qty{E_a/RT_0}             \\right]\n\\end{align}\nFinally, we note that the slope, $m$, can be determined from $T_0$ and $T_1$ if $t_1$ and $t_0$ are known (rise over run),\n\\begin{align}\n  \\label{eq:quadrature}\n  \\Omega &= A \\frac{t_1 - t_0}{T_1 - T_0}              \\left[T_1 E_2\\qty{E_a/RT_1}              - T_0 E_2\\qty{E_a/RT_0}             \\right]\n\\end{align}\nThis gives the accumulated damage over a time $t_1 - t_0$, when the temperature rise is linear. If the actual\ntemperature rise is not linear, then we can discretize the profile into small segments, such that\nthe temperature is approximatly linear over the segment.\n\nIt is reasonalble to think that this approximation\n(treating the temperature as linear over some time interval) is better than assuming that the damage rate\nis linear over the same time. Figure \\ref{fig:arrhenius_rate} shows the Arrhenius rate as a function of time for an example\nthermal profile. The figure shows that the Arrhenius rate is concave on both sides its peak, which means that the error accumlated by the\ntrapezoid rule will have the same sign on each side. The trapezoid rule will \\emph{over}-predict the accumulated damage. On the otherhand,\nif the thermal profile is approimated as linear segments, the accumulated damage will be \\emph{under}-predicted while the temperature increases, and\nthen be \\emph{over}-predicted when the temperature begins to fall.\n\n\\section{Numerical Implementation}\n\nEquation \\ref{eq:quadrature} provides an analytic expession to evaluate the Arrhenius integral over some time period where the temperature rise is linear. To numerically integrate\nthe Arrhenius integral for a full thermal profile, we simply break the integral up into small time intervals, use Equation \\ref{eq:quadrature} to evaluate the integral over each\ntime inteval, and then them all up. However, we must be careful because the there is a $T_1 - T_0$ in the denominator. If the temperature is constant, we will divide by zero.\n\nIf $T_0 = T_1 = T$, then Equation \\ref{eq:quadrature} gives\n\\begin{align}\n  \\Omega = A(t_1 - t_0)\\qty( \\frac{ T E_2\\qty{E_a/RT} - T E_2\\qty{E_a/RT} } { T - T} ) = A(t_1 - t_0) \\frac{0}{0}.\n\\end{align}\nTo evaluate, we need to apply L'H\\^{o}pital's rule for $T_1 - T_0 \\rightarrow 0$. Apparently, this limit will give $A(t_1 - t_0) e^{-E_a/RT}$, since this is the integral for a constant temperature.\n\nA numerical implementation will need to check for the case that $T_0 = T_1$ and use the constant temperature quadrature. If $T_0$ and $T_1$ are stored as floating point numbers, then\nwe will probably need to check that they are ``close'', rather than ``equal''. Note that, for a linear temperature rise from $T_0$ and $T_1$, evaluating Equation \\ref{eq:quadrature} will\nto give a numerical value between $Ae^{-E_a/RT_0}(t_1 - t_0)$ and $Ae^{-E_a/RT_1}(t_1 - t_0)$. We can therefore write a limit on the maximum error in incurred by any numerical approximation to integral over duration $t_1 - t_0$.\n\\begin{align}\n  \\epsilon \\le \\frac{\\abs{ Ae^{-E_a/RT_1}(t_1 - t_0) - Ae^{-E_a/RT_0}(t_1 - t_0)} }{Ae^{-E_a/RT_0}(t_1 - t_0)} = \\abs{e^{-\\frac{E_a}{R} \\qty(\\frac{1}{T_1} - \\frac{1}{T_0})} - 1}\n\\end{align}\nThis gives a metric for deciding if $T_1$ and $T_0$ are ``close enough''. Given a tolerance, or maximum allowed error, we \n\\begin{align}\n  \\frac{R}{E_a} \\ln \\qty( \\epsilon + 1 ) \\le \\abs{ \\frac{1}{T_1} - \\frac{1}{T_0} }\n\\end{align}\nFor small $\\epsilon$, $\\ln \\qty(\\epsilon + 1) \\approx \\epsilon$,\n\\begin{align}\n \\frac{1}{T_1} - \\frac{1}{T_0} \\ge \\frac{R}{E_a}\\epsilon\n\\end{align}\n\n\n\n\\begin{figure}\n\\includegraphics{./arrhenius_rate.png}\n\\caption{\\label{fig:arrhenius_rate} The Arrhenius rate, $Ae^{-E_a/RT(t)}$, plotted for an example thermal profile. }\n\\end{figure}\n\n\n\\bibliography{references_database}\n\\bibliographystyle{plain}\n\n\n\\end{document}\n", "meta": {"hexsha": "74290b5cd2cb23b7bfa8d0f1e3b46a17e11a04e3", "size": 6992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/writeups/IntegralEvaluation/Arrhenius_Integral_Quadrature.tex", "max_stars_repo_name": "CD3/libArrhenius", "max_stars_repo_head_hexsha": "2cf65c9935c1661c6150ddfd86a999cf2fff2691", "max_stars_repo_licenses": ["MIT"], "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/writeups/IntegralEvaluation/Arrhenius_Integral_Quadrature.tex", "max_issues_repo_name": "CD3/libArrhenius", "max_issues_repo_head_hexsha": "2cf65c9935c1661c6150ddfd86a999cf2fff2691", "max_issues_repo_licenses": ["MIT"], "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/writeups/IntegralEvaluation/Arrhenius_Integral_Quadrature.tex", "max_forks_repo_name": "CD3/libArrhenius", "max_forks_repo_head_hexsha": "2cf65c9935c1661c6150ddfd86a999cf2fff2691", "max_forks_repo_licenses": ["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.3740458015, "max_line_length": 228, "alphanum_fraction": 0.7072368421, "num_tokens": 2347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.6503881047166825}}
{"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 4}\n\\author{Jiale Shi}\n\\date{Oct/29/2018}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{array}\n\\begin{document}\n\\maketitle\n\n\\newpage\n\\section{Accept-Reject}\nGenerate samples of a standard normal distribution, $f(x) \\sim N(0,1)$, using the accept-reject method with a double-exponential proposal distribution, $g(x|\\alpha) = (\\alpha/2)\\exp(-\\alpha |x|)$.\n\n(a) Derive the upper bound for the likelihood ratio, $M=f(x)/g(x)$ and show that the ideal acceptance rate is obtained when $\\alpha=1$\n\nSolution:\na standard normal distribution, $f(x) \\sim N(0,1)$\n\n\\begin{equation}\n    f(x|0,1) = \\frac{1}{\\sqrt{2\\pi}}\\exp(-\\frac{x^2}{2})\n\\end{equation}\n\n\\begin{equation}\n    M = \\frac{f(x)}{g(x)} = \\frac{\\frac{1}{\\sqrt{2\\pi}}\\exp(-\\frac{x^2}{2})}{(\\alpha/2)\\exp(-\\alpha |x|)} = \\frac{\\sqrt{2}}{\\alpha \\sqrt{\\pi}} \\exp{-\\frac{|x|^2}{2}+\\alpha |x|}\n\\end{equation}\n\nThe ratio $M$ is max at $|x|=\\alpha$.\n\n\\begin{equation}\n    M =  \\frac{\\sqrt{2}}{\\alpha \\sqrt{\\pi}} \\exp{\\frac{\\alpha^2}{2}}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n    &\\pdv{M}{\\alpha} = \\frac{\\sqrt{2}}{\\sqrt{\\pi}} \\exp{\\frac{\\alpha^2}{2}} (1-\\frac{1}{\\alpha^2}) = 0 \\\\\n    & \\alpha = 1, M' = \\frac{\\sqrt{2}}{\\sqrt{\\pi}} \\exp{\\frac{1}{2}}\n\\end{aligned}\n\\end{equation}\n\n(b) Implement the accept-reject method and plot the true PDF and the proposal distribution for $\\alpha=1$ super-imposed on to the normalized histogram of your samples.\n\nSolution:\n\n$\\alpha = 1$ and \n$M' = \\frac{\\sqrt{2}}{\\sqrt{\\pi}} \\exp{\\frac{1}{2}}$\n    \n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1b1.png}\n\\caption{$<E>$- iteration for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1b2.png}\n\\caption{COV- iteration for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1b3.png}\n\\caption{ the true pdf and the proposal distribution for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1b4.png}\n\\caption{histogram of samples for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\newpage\n(c) Repeat part (b) but now use a sub-optimal proposal distribution with $\\alpha=2$, plot both distributions and your histogram. How do the acceptance rates compare?\n\nSolution:\n\n$\\alpha = 2$ and \n$M' = \\frac{\\sqrt{2}}{2\\sqrt{\\pi}} \\exp{2}$\n    \n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1c1.png}\n\\caption{$<E>$- iteration for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1c2.png}\n\\caption{COV- iteration for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1c3.png}\n\\caption{ the true pdf and the proposal distribution for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{h4p1c4.png}\n\\caption{histogram of samples for $\\alpha = 1$}\n%\\label{fig:universe}\n\\end{figure}\n\nBy comparing Figure 1 and Figure 3, it is easy to figure out that the acceptance rates ($\\alpha =2$) is smaller than that acceptance rates ($\\alpha =1$)\n\n\\newpage\n\\section{Independent Metropolis-Hastings}\nTraditionally in the Metropolis-Hastings algorithm the arbitrary proposal distribution is conditioned on the current state of the chain. Namely, one draws samples from $x' \\sim q(x'|x_{t})$ where $x_t$ indicates the state of the chain. Consider a proposal distribution that is independent of the chain's current state $q(x')$. When such a distribution is used, this is referred to as the \\textit{Independent Metropolis-Hasting algorithm}.\n\nProve that the Independent Metropolis-Hastings accepts more than the Accept-Reject method when both have identical target ($f(x')$) and proposal ($g(x')$) distributions.\n\nSolution:\n\nfor Accept-Reject method:\n\\begin{equation}\n\\begin{aligned}\n    & prob_{AJ} = \\frac{f(x')}{M \\cdot g(x')} \\\\\n    & M = sup \\frac{f(x)}{g(x)} \\geq \\frac{f(x)}{g(x)} \n\\end{aligned}\n\\end{equation}\nSince $M \\cdot g(x') \\geq f(x')$, $M \\cdot g(x')$ curve is above $f(x')$ curve, $prob_{AJ} \\leq 1$\n\nfor Metropolis-Hasting algorithm\n\\begin{equation}\n\\begin{aligned}\n     & prob_{MH} = \\min [1,\\frac{\\frac{f(x')}{g(x')}}{\\frac{f(x_t)}{g(x_t)}}]  \\\\ %\\geq \\frac{f(x')}{M \\cdot g(x')} \\\\\n    & if  1 \\leq \\frac{\\frac{f(x')}{g(x')}}{\\frac{f(x_t)}{g(x_t)}} \\to prob_{MH}=1 \\geq prob_{AJ} \\\\\n    & if  1 \\geq \\frac{\\frac{f(x')}{g(x')}}{\\frac{f(x_t)}{g(x_t)}} \\to prob_{MH}=\\frac{\\frac{f(x')}{g(x')}}{\\frac{f(x_t)}{g(x_t)}} \\geq \\frac{f(x')}{M \\cdot g(x')} = prob_{AJ}\n\\end{aligned}\n\\end{equation}\n\nThe prob of Accept-Reject method is smaller than that of Metropolis-Hasting algorithm.\nTherefore,the Independent Metropolis-Hastings accepts more than the Accept-Reject method when both have identical target ($f(x')$) and proposal ($g(x')$) distributions.\n\n\n\\newpage\n\\section{Accept-Reject $\\&$ Metropolis-Hastings}\n(a) Implement the accept-reject algorithm to calculate the mean of a gamma distribution $\\mathcal{G}(4.3,6.2)$ using a $\\mathcal{G}(4,7)$ candidate. Draw the true density function on top of the sample histogram and plot the convergence.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.35]{h4p3a4.png}\n\\caption{ the true pdf and histogram of samples for accept-reject}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.35]{h4p3a2.png}\n\\caption{ COV for accept-reject}\n%\\label{fig:universe}\n\\end{figure}\n\n\\newpage\n(b) Implement the Metropolis-Hastings algorithm to calculate the mean of a gamma distribution $\\mathcal{G}(4.3,6.2)$ using the following candidate densities:\n\nA gamma $\\mathcal{G}(4,7)$ candidate distribution.\n\nA gamma $\\mathcal{G}(5,6)$ candidate distribution.\n\nFor both candidate distributions draw the true and candidate density functions on top of \nthe sampled histogram. Plot the convergence using each candidate distribution on the same axis . How do the means compare?\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.3]{h4p3b13.png}\n\\caption{ $\\mathcal{G}(4,7)$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.3]{h4p3b23.png}\n\\caption{ $\\mathcal{G}(5,6)$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{h4p3bEcompare.png}\n\\caption{ $<E>$ comparation for different proposal functions}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{h4p3bCOVcompare.png}\n\\caption{ COV comparation for different proposal functions}\n%\\label{fig:universe}\n\\end{figure}\n\n$\\mathcal{G}(5,6)$ convergences much quickly than $\\mathcal{G}(4,7)$. And we can see it from COV-iteration and $<E>$-iteration figures.\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\n\\section{Gibbs $\\&$ Metropolis-Hastings}\nConsider sampling from a 2D Gaussian. Suppose $x \\sim \\mathcal{N}(\\mu, \\Sigma) $ where $\\mu = (1,1)$ and $\\Sigma = (1,-0.5;-0.5,1)$.\n\n(a) Derive the full conditional $p(x_1 | x_2)$ and $p(x_2 | x_1)$. Implement the Gibbs algorithm for this case and plot the 1D marginals $p(x_1)$ and $p(x_2)$ as well as (superimposed) the computed histograms.\n\nDerive the full conditional distribution from Bishop-Pattern Recognition and Machine Learning(2.81 and 2.82)\n\\begin{equation}\n\\begin{aligned}\n\\mu_{a|b} = \\mu_{a} + \\Sigma_{ab}\\Sigma_{bb}^{-1}(x_{b}-\\mu_{b})\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n\\Sigma_{a|b} = \\Sigma_{aa} -\\Sigma_{ab}\\Sigma_{bb}^{-1}\\Sigma_{ba}\n\\end{aligned}\n\\end{equation}\n\nTherefore,\n\n\\begin{equation}\n\\begin{aligned}\n& \\mu_{x_1|x_2} = 1 -0.5(x_{2}-1) \\\\\n& \\Sigma_{x_1|x_2} = 0.75 \\\\\n& x_1|x_2 \\sim \\mathcal{N}(1 -0.5(x_{2}-1), 0.75) \\\\\n& \\mu_{x_2|x_1} = 1 -0.5(x_{1}-1) \\\\\n& \\Sigma_{x_2|x_1} = 0.75 \\\\\n& x_2|x_1 \\sim \\mathcal{N}(1 -0.5(x_{1}-1), 0.75) \\\\\n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P41.png}\n\\caption{ }\n%\\label{fig:universe}\n\\end{figure}\n\n(b) Let us now consider block-wise Metropolis Hastings. For our proposal distribution, $q(x)$ let us  use a normal centered at the previous state/sample of the Markov chain/sampler, i.e: $q(x|x^{(t-1)}) \\sim N(x^{(t-1)}, I)$, where I is a 2D identity matrix. Show the 2D target distribution and its sampled approximation.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P42.png}\n\\caption{ }\n%\\label{fig:universe}\n\\end{figure}\n\n(c) We now consider component-wise Metropolis Hastings approximation of the same problem. The proposal distribution $q(x)$ is now a univariate Normal distribution with unit variance in the direction of the i-th dimension to be sampled. Show the sampled and exact target distribution.\nShow your results and compare the convergence with that obtained with the block-wise, component-wise Metropolis-Hastings and Gibbs implementation.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P43.png}\n\\caption{}\n%\\label{fig:universe}\n\\end{figure}\n\nCompare the convergence with that with that obtained with the block-wise, component-wise Metropolis-Hastings and Gibbs implementation.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P44.png}\n\\caption{$<E>$ convergence}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P45.png}\n\\caption{COV convergence}\n%\\label{fig:universe}\n\\end{figure}\n\nFrom $<E>$ convergence and COV convergence, it is easy to find that \nthe convergence rate: Gibbs is the fastest, Block-wise MH is the second, component-wise is the slowest.\n\n\\newpage\n\\section{Metropolis-Hastings}\nConsider the braking data of Tukey. It corresponds to breaking distances $y_{i,j}$ of cars driving at speeds $x_{i}$. It is thought that a good model for this dataset is quadratic model:\n\\begin{equation}\n    y_{i,j} = \\beta_{0} +\\beta_{1}x_{i} + \\beta_{2}x_{i}^{2}+\\epsilon_{i,j}\n\\end{equation}\nwhere $\\epsilon_{i,j} \\sim  N(0,\\sigma^2), i=1, ..., k$ and $j=1,...,n_{i}$\nIf we assume that $\\epsilon_{i,j} \\sim  N(0,\\sigma^2)$ are independent, then the likelihood function is \n\\begin{equation}\n    (\\frac{1}{\\sigma^2})^{N/2} e^{-\\frac{1}{2\\sigma^2}\\sum_{i,j}(y_{i,j}-\\beta_{0}-\\beta_{1}x_{i} - \\beta_{2}x_{i}^{2})}\n\\end{equation}\nWe can view this likelihood as a posterior distribution of $\\beta_{0},\\beta_{1},\\beta_{2},\\sigma^2$ and we can sample from it with a Metropolis-Hasting algorithm.\n\n(a) Obtain maximum likelihood estimate for $\\beta_{0}$, $\\beta_{1}$, $\\beta_{2}$, $\\sigma^{2}$\n\\begin{equation}\n    I(\\beta_{0},\\beta_{1},\\beta_{2},\\sigma^2 | y,X ) =  (\\frac{1}{\\sigma^2})^{N/2} e^{-\\frac{1}{2\\sigma^2}\\sum_{i,j}(y_{i,j}-\\beta_{0}-\\beta_{1}x_{i} - \\beta_{2}x_{i}^{2})}\n\\end{equation}\ntake the log of $I$\n\\begin{equation}\n    \\log I(\\beta_{0},\\beta_{1},\\beta_{2},\\sigma^2 | y,X) = (N/2) \\log(\\frac{1}{\\sigma^2}) -\\frac{1}{2\\sigma^2}\\sum_{i,j}(y_{i,j}-\\beta_{0}-\\beta_{1}x_{i} - \\beta_{2}x_{i}^{2})\n\\end{equation}\n\nfor $\\beta_{0}$, $\\beta_{1}$, $\\beta_{2}$:\n\\begin{equation}\n\\begin{aligned}\n    & \\frac{\\partial I}{\\partial \\beta_{0}} = 0;\\\\\n    & \\frac{\\partial I}{\\partial \\beta_{1}} = 0;\\\\\n    & \\frac{\\partial I}{\\partial \\beta_{2}} = 0;\\\\\n    & \\frac{\\partial I}{\\partial \\sigma} = 0;\n\\end{aligned}\n\\end{equation}\nthen\n\\begin{equation}\n\\begin{aligned}\n    & \\sum_{i,j} y_{i,j} = \\sum_{i} n_{i}(\\beta_{0}+\\beta_{1}x_{i}+\\beta_{2}x_{i}^{2});\\\\\n    & \\sum_{i,j} y_{i,j} x_{i} = \\sum_{i} n_{i}(\\beta_{0}+\\beta_{1}x_{i}+\\beta_{2}x_{i}^{2}) x_{i};\\\\\n    & \\sum_{i,j} y_{i,j} x_{i}^{2} = \\sum_{i} n_{i}(\\beta_{0}+\\beta_{1}x_{i}+\\beta_{2}x_{i}^{2})x_{i}^{2};\\\\\n    & \\sigma^2 = \\frac{1}{N}\\sum_{i,j}(y_{i,j}-\\beta_{0}-\\beta_{1}x_{i} - \\beta_{2}x_{i}^{2})\n\\end{aligned}\n\\end{equation}\n\nWe call\n\\begin{equation}\n\\begin{aligned}\n& Y = [y_{1,1},...,y_{1,n_{1}},y_{2,1},...,y_{k,1},...,y_{k,n_{k}}] \\\\\n& X = [x_{1}I_{(n_{1} \\times 1)},...,x_{k}I_{(n_{k}\\times 1)}]\n\\end{aligned}\n\\end{equation}\n\nThe solution of $\\beta$ satisfying those equation has a closed form:\n\\begin{equation}\n    \\hat{\\beta} = ([I,X,X^2]^{T}[I,X,X^2])^{-1}[I,X,X^2]^{T} Y\n\\end{equation}\n\nfor $\\sigma^2$, put estimated $\\hat{\\beta}$ into the likelihood expression of $\\sigma^{2}$.\n\\begin{equation}\n     \\hat{\\sigma}^2 = \\frac{1}{N}\\sum_{i,j}(y_{i,j}-\\hat{\\beta}_{0}-\\hat{\\beta}_{1}x_{i} - \\hat{\\beta}_{2}x_{i}^{2})\n\\end{equation}\n\nUse the braking data of Tukey,\nMLE of beta is $\\hat{\\beta} = [2.47 0.91 0.1]^{T}$; MLE of sigma is $\\sigma^2 = 216.5$.\n\n(b) Use the estimates to select a candidate distribution. Take normal for $\\beta_{0}$, $\\beta_{1}$, $\\beta_{2}$, and inverted Gamma for $\\sigma^{2}$.\n\nThe MLE estimated $\\hat{\\beta}$ can be used as the mean parameter of normal proposal density for $\\beta$ because it is unbiased estimator. As for the variance parameter in proposal density, we can rely on its covariance matrix approximation.\n\n\\begin{equation}\n    \\mathbb{V} (\\beta) | X,\\sigma^2) = ([I,X,X^2]^{T}[I,X,X^2])^{-1} \\hat{\\sigma}^{2} \n\\end{equation}\n\nThe proposal density for $\\beta$ is then\n\\begin{equation}\n    \\beta \\sim N(\\hat{\\beta}, \\mathbb{V} (\\beta|X,\\sigma^2))\n\\end{equation}\n\nFor the proposal density of parameters $\\sigma^2$, according to Cochran's theorem:\n\\begin{equation}\n    \\frac{N \\hat{\\sigma}^2}{\\sigma^2} \\sim \\mathcal{X}_{N-3}^2 = \\mathcal{G}(\\frac{N-3}{2},2) \\to \\frac{1}{\\sigma^2} \\sim  \\mathcal{G}(\\frac{N-3}{2},\\frac{2}{N\\hat{\\sigma}^2})\n\\end{equation}\n\nTherefore, the final proposal density for $\\beta, \\sigma$ is then\n\\begin{equation}\n\\begin{aligned}\n    p(\\beta, \\sigma^2) &= \\mathcal{N}(\\beta| \\hat{\\beta}, \\mathbb{V}(\\beta|X,\\sigma^2)) \\mathcal{IG}(\\sigma^2|\\frac{N-3}{2},\\frac{2}{N\\hat{\\sigma}^2}) \\\\\n    & = \\mathcal{N}([2.47,0.91,0.1],\\left[ \\begin{array}{ccc}\n206.37 & -27.22 & 0.821 \\\\\n-27.22 & 3.89 & -0.124 \\\\\n0.821 & -0.124 & 0.0041\n\\end{array} \\right]) \\mathcal{IG}(23.5,5405)\n\\end{aligned}\n\\end{equation}\n\nFor student T distribution\n\\begin{equation}\n    \\mathbb{V} (\\beta) | X,\\sigma^2) = ([I,X,X^2]^{T}[I,X,X^2])^{-1} \\hat{\\sigma}^{2} \\frac{v}{v-2} \n\\end{equation}\nThis covariance is bigger than the previous one.\n\n\\begin{equation}\n\\begin{aligned}\n    p(\\beta, \\sigma^2) &= \\mathcal{N}(\\beta| \\hat{\\beta}, \\mathbb{V}(\\beta|X,\\sigma^2)) \\mathcal{IG}(\\sigma^2|\\frac{N-3}{2},\\frac{2}{N\\hat{\\sigma}^2}) \\\\\n    & = \\mathcal{N}([2.47,0.91,0.1],\\left[ \\begin{array}{ccc}\n412.74 & -54.44 & 1.642 \\\\\n-54.44 & 7.78 & -0.248 \\\\\n1.642 & -0.248 & 0.0082\n\\end{array} \\right]) \\mathcal{IG}(23.5,5405)\n\\end{aligned}\n\\end{equation}\n\n(c) Make histogram of the posterior distributions of the parameters. Monitor convergence.\n\nRobustness considerations could lead to using an error distribution with heavier tails. If we assume that $\\epsilon_{i,j} \\sim Gamma(0,\\sigma^{2})$ independent, then the likelihood function is \n\n\\begin{equation}\n    (\\frac{1}{\\sigma^2})^{N/2} \\prod_{i,j} (1+\\frac{1}{v} \\frac{(y_{i,j}-\\beta_{0}-\\beta_{1}x_{i}-\\beta_{2}x_{i}^{2})^2}{\\sigma^2})^{(v+1)/2}\n\\end{equation}\n\nwhere $v$ is the degrees of freedom. For $v=4$, use Metropolis-Hastings to sample  $\\beta_{0}$, $\\beta_{1}$, $\\beta_{2}$, $\\sigma^{2}$ from the posterior distribution. Use either normal or $\\Gamma$ candidates for $\\beta_{0}$, $\\beta_{1}$, $\\beta_{2}$ and inverted Gamma or half-$\\Gamma$ for $\\sigma^2$.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P51.png}\n\\caption{$\\beta$ Normal distribution}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P52.png}\n\\caption{$\\sigma$ Normal distribution}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P53.png}\n\\caption{Normal distribution}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P54.png}\n\\caption{$\\beta$ Student T distribution}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P55.png}\n\\caption{$\\sigma$ Student T distribution}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.45]{HW4P56.png}\n\\caption{Student T distribution}\n%\\label{fig:universe}\n\\end{figure}\n\nNormal distribution candidate is better than student T distribution candidate.\n%\\bibliographystyle{plain}\n%\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "5cbb2778c5d59403f980561ac52d4cb461aa32f4", "size": 16407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW4_SHI_JIALE/HW4_SHI_JIALE_LatexSourceCode/main.tex", "max_stars_repo_name": "shijiale0609/Statistical-Computing-Methods", "max_stars_repo_head_hexsha": "e780746d5f1e4b475bf38eb15d9d825daf45ffa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework/HW4_SHI_JIALE/HW4_SHI_JIALE_LatexSourceCode/main.tex", "max_issues_repo_name": "shijiale0609/Statistical-Computing-Methods", "max_issues_repo_head_hexsha": "e780746d5f1e4b475bf38eb15d9d825daf45ffa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework/HW4_SHI_JIALE/HW4_SHI_JIALE_LatexSourceCode/main.tex", "max_forks_repo_name": "shijiale0609/Statistical-Computing-Methods", "max_forks_repo_head_hexsha": "e780746d5f1e4b475bf38eb15d9d825daf45ffa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3599137931, "max_line_length": 438, "alphanum_fraction": 0.6766014506, "num_tokens": 5863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.6503881033747748}}
{"text": "%! Author = tstreule\n\n\\section*{General}\n\n\\subsection*{Formeln}\n%\n\\textbf{Circle}: $U\\ped{circle} = 2\\pi r$, $A\\ped{circle} = \\pi r^2$\n\n%\t\\textbf{Laplace}:\\\\\n%\t\\begin{tabular}{ c@{$\\;\\laplace\\;$}c c c@{$\\;\\laplace\\;$}c }\n%\t\t$f(at)$\t\t\t& $\\frac{1}{\\abs{a}}F(s/a)$\t&& $f(t-a)$\t\t& $\\eu^{-as}F(s)$\\\\\n%\t\t$f(t)\\eu^{at}$\t& $F(s-a)$\t\t\t\t\t&& $f'(t)$\t\t& $sF(s) - f(0^+)$\\\\\n%\t\t$t^n$\t\t\t& $n!/s^{n+1}$\t\t\t\t&& $t^n f(t)$\t& $(-1)^n F^{(n)}(s)$\\\\\n%\t\t$\\sin(at)$\t\t& $\\frac{a}{s^2 + a^2}$\t\t&& $\\cos(at)$\t& $\\frac{s}{s^2 + a^2}$\\\\\n%\t\t$\\eu^{at}$\t\t& $\\frac{1}{s - a}$\t\t\t&& $t^n \\eu^{at}$& $\\frac{n!}{(s-a)^{n+1}}$\n%\t\\end{tabular}\n\n\\textbf{Constants}:\\\\\n\\begin{tabular}{r@{$\\;=\\;$}l}\n    $h$\t\t\t& $\\unit[6.626 {\\scriptstyle\\mathrm{E}-34}]{Js} = \\unit[4.135 {\\scriptstyle\\mathrm{E}-15}]{eV\\,s}$,\n    \\quad $\\hbar = \\frac{h}{2\\pi}$,\n    \\quad $hc = \\unit[1.986 {\\scriptstyle\\mathrm{E}-25}]{Jm}$\\\\\n    $\\epsilon_0$& $\\unitfrac[8.85 {\\scriptstyle\\mathrm{E}-5}]{As}{Vm}$\\\\\n    $\\mu_0$\t\t& $\\unitfrac[4\\pi {\\scriptstyle\\mathrm{E}-7}]{N}{A^2}$\\\\\n    $k\\ped{B}$\t& $\\unitfrac[1.38 {\\scriptstyle\\mathrm{E}-23}]{J}{K} = \\unitfrac[8.617 {\\scriptstyle\\mathrm{E}-5}]{eV}{K}$\\\\\n    $q$\t\t\t& $\\unit[1.602 {\\scriptstyle\\mathrm{E}-19}]{C}$, \\quad $m_e = \\unit[9.109 {\\scriptstyle\\mathrm{E}-31}]{kg}$, \\quad $m_p = \\unit[1.672 {\\scriptstyle\\mathrm{E}-27}]{kg}$\\\\\n    $F$\t\t\t& $\\unitfrac[96485]{C}{mol}$ (Faraday)\\\\ % charge of 1 mole of electrons\n    $R$         & $N\\ped{A} k\\ped{B} = \\unitfrac[8.314]{J}{mol\\;K}$ (Ideal gas constant)\\\\\n    $N\\ped{A}$\t& $\\unitfrac[6.022 {\\scriptstyle\\mathrm{E}23}]{particles}{mol}$\n    \\qquad $\\SI{0}{\\degreeCelsius} = \\unit[273.15]{K}$\n\\end{tabular}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Einheiten}\n%\n\\formula{Druck}{\\unit[1]{Pa} = \\unitfrac[1]{N}{m^2} = \\unitfrac[1]{J}{m^3} = \\unitfrac[10]{g}{cm\\cdot s^2}}\\\\\n\\formula{Induktivität}{\\unit[1]{H} = \\unitfrac[1]{Vs}{A} = \\unit[1]{\\Omega\\,s}}\\\\\n\\formula{Power}{\\unit[1]{W} = \\unitfrac[1]{J}{s} = \\unit[1]{VA}}\\\\\n\\formula{electron volt}{\\unit[1]{eV} = \\unit[1.602 {\\scriptstyle\\mathrm{E}-19}]{J} = \\unitfrac[23.06]{kcal}{mol}}\\\\\n\\formula{Charge}{\\SI{1}{\\coulomb} = \\SI{1}{\\ampere\\second}}\\\\\n\\formula{Energy}{\\SI{1}{\\joule} = \\unitfrac[1]{kg\\;m^2}{s^2} = \\unit[1]{Nm} = \\unit[1]{VAs} = \\unit[1]{CV} = \\unit[1]{Ws}}\\\\\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Good to know}\n%\n\\formula{Power in \\unit{dB}}{10\\,\\log_{10}\\frac{I}{I_0}}\\\\\n\\formula[\\unit{\\frac{\\!W}{m^2}}]{Intensity}{ I = \\frac{\\textrm{avg. Power }(P)}{\\textrm{area }(A)} }\\\\\n\\formula[\\unit{W} = \\unit{\\frac{kg\\,m^2}{s^3}}]{avg. Power}{P = \\frac{\\textrm{avg. Work in cycle }(\\overline{W})}{\\textrm{cycle }(T)}}\\\\\n\\formula[\\unit{J}=\\unit{Ws}]{(avg.) Work}{\\overline{W} = \\int_{\\textrm{cycle}} \\frac{1}{\\textrm{cycle} (T)} \\cdot \\vec{F}\\cdot\\vec{x} \\diff t }\\\\\n\nmass $m$ vibrates with an amplitude $a$ along $x$-axis:\\\\\n$\\vec{x}(t) = a\\sin(\\omega t)\\cdot \\vec{e}_x, \\quad \\omega = 2\\pi f = 2\\pi/T, \\quad \\vec{F}(t) = m\\,\\ddot{\\vec{x}}(t)$\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{NuS}\n%\n\\formula{Induktivität}{u(t) = L \\deriv{i_L}{t} \\enskip\\laplace\\enskip U(s) = sL\\,I_L(s)}\\\\\n\\formula{Konduktivität}{i(t) = C \\deriv{u_C}{t} \\enskip\\laplace\\enskip U(s) = \\frac{1}{sC}\\,U_C(s)}\\\\\n\n\\formula{Transformator}{u_1 = L_1 \\deriv{i_1}{t} - M \\deriv{i_2}{t} \\textnormal{,\\enskip $M$: mutual inductance}}\\\\\n\\formula{LCR-Schwingkreis}{\\omega_0 = 2\\pi f_0 = 1/\\sqrt{LC}}\\\\\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Laplace}\n%\t%Laplace Transformation: \\;\n%\t$\\phantom{\\laplace} \\dis{0.4} u(t)=\\mathcal{L}^{-1}\\{U(s)\\} = \\frac{1}{2\\pi\\iu} \\int_{\\bar{s}}^s U(s)\\eu^{st} \\diff s$\\\\\n%\t$\\laplace \\dis{0.4} U(s)=\\mathcal{L}\\{u(t)\\} = \\int_0^\\infty u(t)\\eu^{-st} \\diff t$\n%\n\\begin{tabular}{ rcl }\n    \\toprule\n%\t\t$u(t)$\t\t\t\t\t\t\t& \\laplace\t& $U(s)$\t\t\t\t\t\t\t\t\\\\%\\addlinespace\n%\t\t\\midrule\n    $\\lambda\\;u(t) + \\mu\\;v(t)$\t\t& \\laplace\t& $\\lambda\\;U(s) + \\mu\\;V(s)$\t\t\t\\\\\n    ${u(at),\\; \\scriptstyle a>0}$\t& \\laplace\t& $\\frac{1}{a}$ $U(\\frac{s}{a})$\t\t\\\\\n    { \\color{red} $u(t-t_0)$ }\t\t& \\laplace\t& $\\eu^{-st_0}$ $U(s)$\t\t\t\t\t\\\\\n    $\\eu^{-at}$ $u(t)$\t\t\t\t& \\laplace\t& { \\color{red} $U(s+a)$ }\t\t\t\t\\\\\n    ${ (-t)^{n} u(t) }$\t\t\t\t& \\laplace\t& $U^{(n)}(s)$\t\t\t\t\t\t\t\\\\\n    $u^{(n)}(t)$\t\t\t\t\t& \\laplace\t& $ {s^nU(s) - \\ldots - u^{(n-1)}(0)} $\t\\\\\n    \\midrule\n%\t\t$t^n$\t\t\t\t\t\t\t& \\laplace\t& $\\frac{n!}{s^{n+1}}$\t\t\t\t\t\\\\\\addlinespace\n%\t\t$\\eu^{-at}$\t\t\t\t\t\t& \\laplace\t& $\\frac{1}{s+a}$\t\t\t\t\t\t\\\\\\addlinespace\n%\t\t$t\\eu^{-at}$\t\t\t\t\t& \\laplace\t& $\\frac{1}{(s+a)^2}$\t\t\t\t\t\\\\\\addlinespace\n%\t\t$t^n\\eu^{-at}$\t\t\t\t\t& \\laplace\t& $\\frac{n!}{(s+a)^{n+1}}$\t\t\t\t\\\\\\addlinespace\n%\t\t$\\sin (at)$\t\t\t\t\t\t& \\laplace\t& $\\frac{a}{s^2+a^2}$\t\t\t\t\t\\\\\\addlinespace\n%\t\t$\\cos(at)$\t\t\t\t\t\t& \\laplace\t& $\\frac{s}{s^2+a^2}$\t\t\t\t\t\\\\\\addlinespace\n    \\multicolumn{3}{c}{\n        \\begin{minipage}{.45\\columnwidth} \\centering\n        \\begin{tabular}{ ccc }\n%\t\t\t\t\t$u(t)$\t\t\t\t\t\t\t& \\laplace\t& $U(s)$\t\t\t\t\t\t\t\t\\\\%\\addlinespace\n%\t\t\t\t\t\\midrule\n            $t^n$\t\t\t\t\t\t\t& \\laplace\t& $\\frac{n!}{s^{n+1}}$\t\t\t\t\t\\\\\n            $\\eu^{-at}$\t\t\t\t\t\t& \\laplace\t& $\\frac{1}{s+a}$\t\t\t\t\t\t\\\\\n            $t\\eu^{-at}$\t\t\t\t\t& \\laplace\t& $\\frac{1}{(s+a)^2}$\t\t\t\t\t\\\\\n        \\end{tabular}\n        \\end{minipage}%\n        \\begin{minipage}{.45\\columnwidth} \\centering\n        \\begin{tabular}{ ccc }\n%\t\t\t\t\t$u(t)$\t\t\t\t\t\t\t& \\laplace\t& $U(s)$\t\t\t\t\t\t\t\t\\\\%\\addlinespace\n%\t\t\t\t\t\\midrule\n            $t^n\\eu^{-at}$\t\t\t\t\t& \\laplace\t& $\\frac{n!}{(s+a)^{n+1}}$\t\t\t\t\\\\\n            $\\sin (at)$\t\t\t\t\t\t& \\laplace\t& $\\frac{a}{s^2+a^2}$\t\t\t\t\t\\\\\n            $\\cos(at)$\t\t\t\t\t\t& \\laplace\t& $\\frac{s}{s^2+a^2}$\t\t\t\t\t\\\\\n        \\end{tabular}\n        \\end{minipage}\n    }\\\\\n    \\bottomrule\n\\end{tabular}\n", "meta": {"hexsha": "4de68f017756a67c759fe3aacdd6a7c601604eff", "size": 5641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/BE18/sections/01_general.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/BE18/sections/01_general.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/BE18/sections/01_general.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.2403846154, "max_line_length": 179, "alphanum_fraction": 0.4809430952, "num_tokens": 2552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6503880980071437}}
{"text": "\\subsection{Matrix Element Methods}\n\\label{subsec:MEM}\n\nThe ME method is based on \\emph{ab initio} calculations of the probability density function $\\mathcal{P}$ of an event with observed final-state particle momenta ${\\bf x}$ to be due to a physics process $\\xi$ with theory parameters $\\boldsymbol\\alpha$.\nOne can compute $\\mathcal{P}_{\\xi}({\\bf x}|{\\boldsymbol\\alpha})$ by means of the factorization theorem from the corresponding partonic cross-sections of the hard-scattering process involving parton momenta ${\\bf y}$ and is given by\n\\begin{equation}\n \\mathcal{P}_{\\xi}({\\bf x}|{\\boldsymbol\\alpha}) = \\frac{1}{\\sigma^{\\rm fiducial}_{\\xi}(\\boldsymbol\\alpha)} \\int d\\Phi ({\\bf y}_{\\rm final}) \\; dx_1 \\; dx_2~\\frac{f(x_1)f(x_2)}{2s x_1 x_2} \\; |\\mathcal{M}_{\\xi}({\\bf y}|\\boldsymbol\\alpha)|^2 \\; \\delta^{4}({\\bf y}_{\\rm initial}-{\\bf y}_{\\rm final}) \\; W({\\bf x}, {\\bf y})\n \\label{eqn:MEProb}\n\\end{equation}\nwhere and $x_i$ and ${\\bf y}_{{\\rm initial}}$ are related by $y_{{\\rm initial},i}\\equiv \\frac{\\sqrt{s}}{2}(x_i,0,0,\\pm x_i)$, $f(x_i)$ are the parton distribution functions, $\\sqrt{s}$ is the collider center-of-mass energy, $\\sigma^{\\textrm{ fiducial}}_{\\xi}(\\boldsymbol\\alpha)$ is the total cross section for the process $\\xi$ (with $\\boldsymbol\\alpha$) times the detector acceptance, $d\\Phi({\\bf y})$ is the phase space density factor, $\\mathcal{M}_{\\xi}({\\bf y}|\\boldsymbol\\alpha)$ is the matrix element (typically at leading-order (LO)), and $W({\\bf x}, {\\bf y})$ is the probability density (aka ``transfer function'') that a selected event ${\\bf y}$ ends up as a measured event ${\\bf x}$.\nOne can use calculations of Eq.~\\ref{eqn:MEProb} in a number of ways (e.g. likelihood functions) to search for new phenomena at particle colliders.\n\n\n\n%%%\n\n\nAs stated in Sect.~\\ref{sec:applications-MEM}, the ME method has three notable features: it (1) does not require training data being an \\emph{ab initio} calculation of event probabilities, (2) incorporates all available kinematic information of a hypothesized process, including all correlations, and (3) has a clear physical meaning in terms of the transition probabilities within the framework of quantum field theory.\\\\\n\nIn reference to point (1), the matrix element $\\mathcal{M}_{\\xi}({\\bf y}|\\boldsymbol\\alpha)$ in the method involves all partons in the $n\\rightarrow m$ process, so when the 4-momentum of particles are not completely measured experimentally (e.g. neutrinos), one must integrate over the missing information which increases the dimensionality of the integration.\nIn reference to point (2), a clever technique to re-map the phase space in order to reduce the sharpness of integrate in that space in an automated way ({\\sf MADWEIGHT}~\\cite{Artoisenet:2010cn}) is often used in conjunction with a matrix element calculation package ({\\sf MADGRAPH\\_aMC\\@NLO}~\\cite{Alwall:2014hca}).\nIn practice, evaluation of definite integrals by the ME approach invokes techniques such as importance sampling (see {\\sf VEGAS}~\\cite{PETERLEPAGE1978192,Ohl:1998jn} and {\\sf FOAM}~\\cite{JADACH200355}) or recursive stratified sampling (see MISER~\\cite{Press:1989vk}) Monte Carlo integration.\nAcceleration of some of these techniques on modern computing architectures has been achieved, for example concurrent phase space sampling in VEGAS on GPUs.\n", "meta": {"hexsha": "85f72eefb239bff5bb016ce5c1996fe9eeee75b4", "size": 3312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/appendix.tex", "max_stars_repo_name": "iml-wg/cwp", "max_stars_repo_head_hexsha": "1d49b8d5d86e8bc74da41944f028990e16f0eae1", "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/appendix.tex", "max_issues_repo_name": "iml-wg/cwp", "max_issues_repo_head_hexsha": "1d49b8d5d86e8bc74da41944f028990e16f0eae1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-05-07T09:30:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-17T15:13:03.000Z", "max_forks_repo_path": "src/appendix.tex", "max_forks_repo_name": "iml-wg/cwp", "max_forks_repo_head_hexsha": "1d49b8d5d86e8bc74da41944f028990e16f0eae1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-05T23:42:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-05T23:42:57.000Z", "avg_line_length": 138.0, "max_line_length": 693, "alphanum_fraction": 0.740942029, "num_tokens": 944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.650385132309465}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\\usepackage[margin=2.5cm]{geometry}\n\\usepackage{amssymb, amsmath}\n\n\\begin{document}\n\\subsection*{Some interesting formulae to try out:}\n\\begin{itemize}\n\\item\n$z_{n+1} = e^{z_n^2 e^{i\\varphi}}+c$\n\\item\n$z_{n+1} = \\left(\\frac{1}{z_n^2 - e^{i\\varphi}}\\right)^2 + c$\n\\item\n$z_{n+1} = \\tan(z_n^2 e^{i\\varphi}) + c$\n\\item\n$z_{n+1} = (z_n^2 - e^{i\\varphi})^3 + c$\n\\end{itemize}\n\\end{document}", "meta": {"hexsha": "82df0b59d050ffe65d8e9ca2d45735cd44a271c4", "size": 424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "formulae.tex", "max_stars_repo_name": "kheidler/Fractals", "max_stars_repo_head_hexsha": "ba5909af44e71eac5e3faa3eb56fb971ad39c9a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "formulae.tex", "max_issues_repo_name": "kheidler/Fractals", "max_issues_repo_head_hexsha": "ba5909af44e71eac5e3faa3eb56fb971ad39c9a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "formulae.tex", "max_forks_repo_name": "kheidler/Fractals", "max_forks_repo_head_hexsha": "ba5909af44e71eac5e3faa3eb56fb971ad39c9a6", "max_forks_repo_licenses": ["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.9411764706, "max_line_length": 61, "alphanum_fraction": 0.6462264151, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6503073147477989}}
{"text": "\\section{Preliminaries}\n\\subsection{Proofs using the Curry-Howard Correspondence}\nThe Curry-Howard correspondence is a relationship that can be used to interpret typed computer programs as mathematical proofs \\cite{chc}. This is done by representing false statements as empty types, and true statements as non-empty types. For example, take  \\verb|IsTrue b|  where  \\verb|b| is some boolean expression. The type is constructed in such a way that it is empty if  \\verb|b| is false, and non-empty if b is true.  So if there exists a value of type  \\verb|IsTrue b|, this value is a proof that  \\verb|b| must be true. \n\nThese proofs can be used as function arguments, constructor arguments or even as a function result. Since Agda is dependently typed, the proof can also refer to other arguments of a function. For example, this function may only be called when \\verb|n| is greater than 5:\n\\begin{minted}{agda}\ntakesGtFive : (n : Nat) -> IsTrue (n > 5) -> ?\n\\end{minted}\n\n\\subsection{Lenses}\nThe QuadTree library makes extensive use of Lenses. Lenses are composable functional references \\cite{lens}. Using lenses, data in a data-structure can be accessed and modified. This paper chooses to use the Van Laarhoven representation \\cite{laarhovenlens}, since this is what the Haskell implementation of the QuadTree library uses. It is defined as:\n\\begin{minted}{haskell}\ntype Lens s a = forall f. Functor f => (a -> f a) -> s -> f s\n\\end{minted}\nUsing this representation, \\verb|Lens a b| means that given an object of type \\verb|a|, we can view or modify an inner object of type \\verb|b|.\nThe functions to interact with lenses are:\n\\begin{minted}{haskell}\n-- Get the value at this lens\nview :: Lens a b -> a -> b\n-- Set the value at this lens\nset :: Lens a b -> b -> a -> a\n-- Map the value at this lens\nover :: Lens a b -> (b -> b) -> a -> a\n-- Compose two lenses (Note: This is actually just regular function composition!)\ncompose :: Lens a b -> Lens b c -> Lens a c\n\\end{minted}\n\n\\subsection{QuadTrees}\n\\begin{wrapfigure}{r}{0.3\\textwidth} %this figure will be at the right\n\t\\vspace{-40pt}\n\t\\includegraphics[width=0.3\\textwidth]{graphics/test.png}\n\t\\caption{An example QuadTree}\n\t\\label{quadtree_img}\n\t\\vspace{-90pt}\n\\end{wrapfigure}\n\nThe QuadTree is a data structure that is used for storing two-dimensional information in a functional way \\cite{Finkel1974}. It is defined as:\n\\begin{minted}{haskell}\ndata Quadrant t = Leaf t | Node (Quadrant t) \n\t(Quadrant t) (Quadrant t) (Quadrant t)\n\ndata QuadTree t = Wrapper (Nat, Nat) (Quadrant t)\n\\end{minted}\n\nA QuadTree consists of the size (width  ×  height) of the QuadTree, and the root quadrant. A quadrant is either a leaf (in which case all the values inside the region of the quadrant are the same), or four subquadrants. The four subquadrants are then called A (top left), B (top right), C (bottom left), and D (bottom right). Notice that in Figure \\ref{quadtree_img}, space is consistently split into four quadrants.\n\nThere are five functions that can be used to interact with QuadTrees:\n\\begin{minted}{haskell}\n-- Create a new QuadTree with the specified size\nmakeTree :: (Nat, Nat) -> t -> QuadTree t\n-- Obtain a lens to the specified location\natLocation :: (Nat, Nat) -> Lens (QuadTree t) t\n-- Get the value at the specified location\ngetLocation :: (Nat, Nat) -> QuadTree t -> t\n-- Set the value at the specified location\nsetLocation :: (Nat, Nat) -> t -> QuadTree t -> QuadTree t\n-- Map the value at the specified location\nmapLocation :: (Nat, Nat) -> (t -> t) -> QuadTree t -> QuadTree t\n\\end{minted}\n", "meta": {"hexsha": "1c75e290a7a3f3091782b1c9e929f90e4a618499", "size": 3558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/2_preliminaries.tex", "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_issues_repo_path": "paper/sections/2_preliminaries.tex", "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "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/sections/2_preliminaries.tex", "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.3, "max_line_length": 532, "alphanum_fraction": 0.7344013491, "num_tokens": 980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6503073085445941}}
{"text": "\\section{Rigid Bodies}\r\n\\begin{definition}\r\n    A rigit body is an extended mass with a finite volume as a system of particles that are constrained such that the mutual distances between them does not change.\r\n\\end{definition}\r\n\\begin{definition}\r\n    An isometry is a distance-preserving map in the space, e.g. rotation, translation, etc..\r\n\\end{definition}\r\nSo a rigid body is a system of particle moving under isometries.\r\n\\subsection{Angular Velocity}\r\nRecall that we can have a vector angular velocity $\\underline{\\omega}$ which points to the axis of rotation and has magnitude equal to the scalar angular velocity $\\omega$ of the point mass $\\underline{r}$.\r\nSo $\\underline{\\dot{r}}=\\underline{\\omega}\\times\\underline{r}$.\r\nIf the particle has mass $m$, we can write down the kinetic energy $T=m|\\underline{\\dot{r}}|^2/2=m\\omega^2r_\\perp^2/2$ where $r_\\perp=|\\underline{n}\\times\\underline{r}|$ where $\\underline{n}$ is a unit vector and $\\underline{\\omega}=\\omega\\underline{n}$.\r\nWe write $I=mr_\\perp^2$ as the moment of inertia, so $T=I\\omega^2/2$.\r\nNote that the moment of inertia is dependent on the axis.\r\n\\subsection{Moment of Inertia for a Rigid Body}\r\nConsider a rigid body made up of $N$ particles following the notation we introduced earlier.\r\nThe body (i.e. all the particles within it) would rotate about an axis through the origin with angular velocity $\\underline{\\omega}$.\r\nFor particle $i$, we have $\\underline{\\dot{r}_i}=\\underline{\\omega}\\times\\underline{r_i}$.\r\nNote that\r\n$$\\frac{\\mathrm d}{\\mathrm dt}|\\underline{r_i}-\\underline{r_j}|^2=2((\\omega\\times(\\underline{r_i}-\\underline{r_j}))\\cdot(\\underline{r_i}-\\underline{r_j}))=0$$\r\nSo the particles do stay the same distance apart.\r\nThe kinetic energy of the rotating body is then going to be\r\n$$T=\\sum_{i=1}^N\\frac{1}{2}m_i|\\underline{\\dot{r}_i}|^2=\\frac{1}{2}\\omega^2\\sum_{i=1}^Nm_i|\\underline{n}\\times\\underline{r_i}|^2=\\frac{1}{2}\\omega^2\\sum_{i=1}^Nm_i(r_i)_\\perp^2=\\frac{1}{2}\\omega^2I$$\r\nwhere $I$ is called the moment of inertia for the body.\r\nCorrespondingly, we can consider the angular momentum, where\r\n$$\\underline{L}=\\sum_{i=1}^N\\underline{L_i}=\\sum_{i=1}^Nm_i\\underline{r_i}\\times(\\underline{\\omega}\\times\\underline{r_i})=\\omega\\sum_{i=1}^Nm_i\\underline{r_i}\\times(\\underline{n}\\times\\underline{r_i})$$\r\nConsider its component in the direction of the axis of rotation,\r\n$$\\underline{L}\\cdot\\underline{n}=\\omega\\sum_{i=1}^Nm_i\\underline{n}\\cdot(\\underline{r_i}\\times(\\underline{n}\\times\\underline{r_i}))=\\omega\\sum_{i=1}^nm_i|\\underline{n}\\times\\underline{r_i}|^2=I\\omega$$\r\nSo the direction of $\\underline{L}$ in the direction of the axis of rotation is $I\\omega$.\r\nIn general, $\\underline{L}$ is not parallel to $\\underline{\\omega}$, so we need to go back to the vector expression.\r\nObserve that $\\underline{L}$ as a function of $\\omega$ is linear, so\r\n$$\\underline{L}=\\sum_{i=1}^Nm_i\\underline{r_i}\\times(\\underline{\\omega}\\times\\underline{r_i})=\\sum_{i=1}^Nm_i(|\\underline{r_i}|^2\\underline{\\omega}-|\\underline{r_i}\\cdot\\underline{\\omega}|\\underline{r_i})=I\\underline{\\omega}$$\r\nwhere $I$ here is a tensor (i.e. a (multi)linear map) which in this case is a $3\\times 3$ matrix.\r\nSo under suffix notation, $L_\\alpha=I_{\\alpha\\beta}\\omega_\\beta$.\r\n$I$ is a symmetric tensor (matrix) by symmetry.\r\nWe have\r\n$$I_{\\alpha\\beta}=\\sum_{i=1}^Nm_i(|\\underline{r_i}|^2\\delta_{\\alpha\\beta})-(\\underline{r_i})_\\alpha(\\underline{r_i})_\\beta$$\r\nNow $I$ is diagonalizable so we can choose our favourite basis (principal axes) to make $I$ diagonal.\r\nTo get $\\underline{L}$ to be at the same direction as $\\underline{\\omega}$, we need the object to rotate wrt a principal axis\r\n\\subsection{Calculation of Moment of Inertia}\r\nFor a solid body, we replace mass-weighted sums by mass-weighted volume integrals.\r\nConsider a body with volume $V$ with density $\\rho(\\underline{r})$, so its mass, center of mass and moment of inertia are\r\n$$M=\\int_V\\rho\\,\\mathrm dV,\\underline{R}=\\frac{1}{M}\\int_V\\rho(\\underline{r})\\underline{r}\\,\\mathrm dV,I=\\int_V\\rho(\\underline{r})|\\underline{r}_\\perp|^2\\,\\mathrm dV=\\int_V\\rho(\\underline{r})|\\underline{n}\\times\\underline{r}|^2\\,\\mathrm dV$$\r\nFor curves and surfaces, we can use line and area integrals accordingly.\r\n\\begin{example}\r\n    1. For uniform thin ring of mass $M$ and radius $a$ with rotation axis $\\underline{n}$ through the center of the ring and perpendicular to the plane where the ring is on.\r\n    In this case, we can reduce volume integral to line integral.\r\n    We have $\\rho=M/(2\\pi a)$, so\r\n    $$I=\\int_0^{2\\pi}\\left( \\frac{M}{2\\pi a} \\right)a^2a\\,\\mathrm d\\theta=Ma^2$$\r\n    Every point in the body is of the same distance from the axis $|\\underline{r}_\\perp|=|\\underline{n}\\times\\underline{r}|=a$.\\\\\r\n    2. Consider a uniform thin rod of mass $M$ and length $l$ with axis of rotation through one end and perpendicular to the rod.\r\n    So\r\n    $$I=\\int_0^l\\left( \\frac{M}{l} \\right)x^2\\,\\mathrm dx=\\frac{1}{3}Ml^2$$\r\n    3. Consider a uniform thin disk with mass $M$ and radius $a$ with the axis of rotation through its center and perpendicular to the plane where the disk is in.\r\n    So we use an area integral\r\n    $$I=\\int_0^a\\int_0^{2\\pi}\\left( \\frac{M}{\\pi a^2} \\right)r^2r\\,\\mathrm d\\theta\\,\\mathrm dr=\\frac{Ma^2}{2}$$\r\n    4. Using the same disk but choose the axis to be one through the center and in the same plane as the disk.\r\n    In this case,\r\n    $$I=\\int_0^a\\int_0^{2\\pi}\\left( \\frac{M}{\\pi a^2} \\right)(r^2\\sin^2\\theta)r\\,\\mathrm d\\theta\\,\\mathrm dr=\\frac{1}{4}Ma^2$$\r\n    5. Consider a solid sphere (a ball) of mass $M$ and radius $a$ with axis of rotation through its center, so spherical polars will be a good choice.\r\n    We assume WLOG that $\\underline{n}$ is the $z$ direction (so $\\theta=0$ along $\\underline{n}$).\r\n    By uniform density, we have $\\rho=3M/(4\\pi a^3)$, therefore\r\n    $$I=\\int_0^a\\int_0^\\pi\\int_0^{2\\pi}\\frac{3M}{4\\pi a^3}(r^2\\sin^2\\theta)r^2\\sin\\theta\\,\\mathrm d\\phi\\,\\mathrm d\\theta\\,\\mathrm dr=\\frac{2}{5}Ma^2$$\r\n\\end{example}\r\nThere are a few simple but general results to simplify calculation moment of inertia.\r\n\\begin{theorem}[Perpendicular Axis Theorem]\r\n    For a two dimensional body on a plane (aka lamina),\r\n    $$I_z=I_x+I_y$$\r\n    where $I_z$ is the moment of inertia along the $z$ axis chosen to be a normal to the plane and $I_x,I_y$ are the moments of inertia along two chosen perpendicular axes on the plane so that all three axes meet at the origin.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We have\r\n    $$I_x=\\int_A\\rho y^2\\,\\mathrm dA,I_y=\\int_A\\rho x^2\\,\\mathrm dA$$\r\n    But\r\n    $$I_z=\\int_A\\rho r^2\\,\\mathrm dA=\\int_A\\rho(x^2+y^2)\\,\\mathrm dA=I_x+I_y$$\r\n    As desired\r\n\\end{proof}\r\nSometimes the lamina is symmetric enough such that $I_x=I_y$, so $I_z=2I_x$.\r\nThis corresponds to the example of a disk.\r\nNote that this theorem works for lamina but does not work for $3$ dimensional bodies.\r\n\\begin{theorem}[Parallel Axes Theorem]\r\n    If a rigid body of mass $M$ has moment of inertia $I_c$ about an axis through its center of mass, then for another axis parallel to the original axis with a distance $d$ away, then the moment of inertia $I$ about the new axis is $I=I_c+Md^2$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Choose Cartesian axes such that the centre of mass is at the origin and the rotation axis along $z$-axis.\r\n    Also, choose $x,y$-axes such that the second axes of rotation is through the point $d\\underline{\\hat{x}}=(d,0,0)$, then\r\n    \\begin{align*}\r\n        I_c+Md^2&=\\int_V\\rho(x^2+y^2)\\,\\mathrm dV+Md^2\\\\\r\n        &=\\int_V\\rho((x-d)^2+y^2)\\,\\mathrm dV+2d\\int_V\\rho x\\,\\mathrm dV\\\\\r\n        &=\\int_V\\rho((x-d)^2+y^2)\\,\\mathrm dV=I\r\n    \\end{align*}\r\n    Since the axes are chosen in a way that the origin is the center of mass.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider a uniform disk as before with the axis of rotation perpendicular to it through a point on the edge has $I=3Ma^2/2$.\r\n\\end{example}\r\n\\subsection{Motion of a Rigid Body}\r\nGeneral motion of a rigit body can be described by the composition of translation (of the center of mass) following some trajectory $\\underline{R}(t)$ together with a rotation about the center of mass.\r\nFollowing the previous discussion, we specify points in the body relative to the center of mass by writing $\\underline{r_i}=\\underline{R}+\\underline{s_i}$.\r\nAlso recall that $\\sum_im_i\\underline{r_i}=M\\underline{R}$, therefore $\\sum_im_i\\underline{s_i}=0$.\r\nIf a body rotates about its center of mass, with angular velocity $\\underline{\\omega}$, so $\\underline{\\dot{s}_i}=\\underline{\\omega}\\times\\underline{s_i}$ and $\\underline{\\dot{r}_i}=\\underline{\\dot{R}}+\\underline{\\omega}\\times\\underline{s_i}$.\r\nThe kinetic energy, as we recall, satisfies\r\n$$T=\\frac{1}{2}M|\\underline{\\dot{R}}|^2+\\frac{1}{2}\\sum_{i=1}^Nm_i|\\underline{s_i}|^2=\\frac{1}{2}M|\\underline{\\dot{R}}|^2+\\frac{1}{2}I_c\\omega^2$$\r\nwhere $I_c$ is the moment of inertia parallel to $\\underline{\\omega}$ and through the center of mass.\r\nSo $T$ is the sum of translational KE and rotational KE.\r\nWe have also shown before that for a general multiparticle system, linear and angular momentum obey $\\underline{\\dot{P}}=\\underline{F},\\underline{\\dot{L}}=\\underline{G}$ where $\\underline{F},\\underline{G}$ are the total external applied force and torque respectively.\r\nFor a rigit body, these two equations determine the translational and rotational motion.\r\nSometimes, we can exploit the conservation of energy as an easier method of solution.\\\\\r\n$\\underline{L},\\underline{G}$ depend on the choice of origin, and we can the origin to be any point fixed in an inertial frame (shown previously).\r\nOr, we can define $\\underline{L}$ and $\\underline{G}$ about the center of mass, and the equation above, as we shall show, still holds.\r\nTake\r\n\\begin{align*}\r\n    \\underline{G}&=\\frac{\\mathrm d}{\\mathrm dt}\\left(M\\underline{R}\\times\\underline{\\dot{R}}+\\sum_{i=1}^Nm_i\\underline{s_i}\\times\\underline{\\dot{s}_i}\\right)\\\\\r\n    &=M\\underline{R}\\times\\underline{\\ddot{R}}+\\frac{\\mathrm d}{\\mathrm dt}\\left( \\sum_{i=1}^Nm_i\\underline{s_i}\\times\\underline{\\dot{s}_i} \\right)\\\\\r\n    &=\\underline{R}\\times\\underline{F}^{\\rm ext}+\\frac{\\mathrm d}{\\mathrm dt}\\left( \\sum_{i=1}^Nm_i\\underline{s_i}\\times\\underline{\\dot{s}_i} \\right)\r\n\\end{align*}\r\nTherefore\r\n\\begin{align*}\r\n    \\frac{\\mathrm d}{\\mathrm dt}\\left( \\sum_{i=1}^Nm_i\\underline{s_i}\\times\\underline{\\dot{s}_i} \\right)&=\\underline{G}-\\underline{R}\\times\\underline{F}^{\\rm ext}\\\\\r\n    &=\\sum_{i=1}^N\\underline{r_i}\\times\\underline{F_i}^{\\rm ext}-\\underline{R}\\times\\sum_{i=1}^N\\underline{F_i}^{\\rm ext}\\\\\r\n    &=\\sum_{i=1}^N(\\underline{r_i}-\\underline{R})\\times\\underline{F_i}^{\\rm ext}\\\\\r\n    &=\\underline{G_c}\r\n\\end{align*}\r\nConsider now the motion in a uniform gravitational field with acceleration due to gravity $\\underline{g}$, then the total gravitational force and torque acting on a rigit body would be the same as if it is acting on a particle of mass $m$ located in the center of mass (hence it is also called the center of gravity).\r\nSo\r\n$$\\underline{F}=\\sum_{i=1}^N\\underline{F_i}^{\\rm ext}=\\sum_{i=1}^Nm_i\\underline{g}=M\\underline{g}$$\r\nsimilarly\r\n$$\\underline{G}=\\sum_{i=1}^N\\underline{G_i}^{\\rm ext}=\\sum_{i=1}^N\\underline{r_i}\\times(m_i\\underline{g})=M\\underline{R}\\times\\underline{g}$$\r\nNote that the gravitational torque about the center of mass is zero since\r\n$$\\underline{G_c}=\\sum_{i=1}^N\\underline{s_i}\\times(m_i\\underline{g})=\\left( \\sum_{i=1}^Nm_i\\underline{s_i} \\right)\\times\\underline{g}=0$$\r\nConsider the gravitatioinal potential $-m\\underline{r}\\cdot\\underline{g}$, then\r\n$$V^{\\rm ext}=\\sum_{i=1}^NV_i^{\\rm ext}=\\sum_{i=1}^N(-m_i\\underline{r_i}\\cdot\\underline{g})=-M\\underline{R}\\cdot\\underline{G}$$\r\n\\begin{example}\r\n    1. Throw a stick in the air.\r\n    So the center of mass follows a parabolic curve and the angular velocity of the stick about center of mass is constant by conservation of energy (or because gravitational torque about center of mass is $0$).\\\\\r\n    2. A uniform rod of length $l$ and mass $M$ fixed at a pivot point $O$ at one end and makes an angle $\\theta$ with the downward vertical.\r\n    We say this is a compound pendulum since the mass is distributed instead of concentrated.\r\n    Consider the angular velocity and angular momentum about the pivot.\r\n    We have $\\omega=\\dot\\theta,L=I\\dot\\theta=Ml^2\\dot\\theta/3$.\r\n    So the gravitational torque about $O$ becomes $-Mgl\\sin\\theta/2$, so $\\dot{L}=G\\implies I\\ddot\\theta=-Mgl\\sin\\theta/2$, so\r\n    $$\\ddot\\theta=-\\frac{3}{2}\\frac{g}{l}\\sin\\theta$$\r\n    which just looks like a simple pendulum of length $2l/3$ (in fact equivalent to it).\r\n    So for small oscillations, the frequency is $f=\\sqrt{3g/(2l)}$ and period $2\\pi/f$.\\\\\r\n    Alternatively we can think of the energy, then\r\n    $$E=T+V=\\frac{1}{2}I\\omega^2-\\frac{Mgl}{2}\\cos\\theta$$\r\n    So\r\n    $$0=\\frac{\\mathrm dE}{\\mathrm dt}=\\dot\\theta\\left(I\\ddot\\theta+\\frac{Mgl}{2}\\sin\\theta\\right)=0$$\r\n    which produces the same result as above.\r\n\\end{example}\r\n\\subsection{Sliding and Rolling}\r\nConsider a cylinder or sphere with radius $a$ moving along a stationary horizontal surface, then the general motion is a translation of the center of mass with velocity $v$ together with rotation about the center of mass with angular velocity $\\omega$.\r\nLet $P$ be the instantaneous point of contact, then the horizontal velocity of this point is given by $v_{\\rm slip}=v-a\\omega$.\\\\\r\nThere are two extreme cases:\\\\\r\n1. Pure sliding, where we have $\\omega=0,v_{\\rm slip}=v\\neq 0$.\r\nSo the point of contact slips through the surface (probably due to a kinetic frictional force).\\\\\r\n2. Pure rolling, where we have $\\omega,v\\neq 0$ but $v_{\\rm slip}=v-a\\omega=0$.\r\nIn this case, the contact point is stationary at any point, which produces rolling without sliding.\\\\\r\nInstantaneously, we can view the motion of the body as the rotation of the body about the contact point.\r\nAlso note that these also apply to inclined plane.\r\n\\begin{example}\r\n    Consider a cylinder of radius $a$ and mass $m$ rolling through inclined plane at angle $\\alpha$ to the horizontal.\r\n    Let $x$ be the distance down slope travelled by the center of mass, $v=\\dot{x}$ and $Mg$ the gravitational force, $N$ the normal reaction and $F$ the frictional force.\r\n    For the cylinder to be purely rolling, we must have $v-a\\omega=0$, so $v=a\\omega$.\\\\\r\n    The kinetic energy has\r\n    $$T=\\frac{1}{2}Mv^2+\\frac{1}{2}I\\omega^2=\\frac{1}{2}\\left(M+\\frac{I}{a^2}\\right)v^2$$\r\n    Note that due to their directions the normal and frictional force (in the case where $v_{\\rm slip}=0$) do no work.\r\n    Now the energy $T+V$ is conserved where $V=-Mgx\\sin\\alpha$, so\r\n    \\begin{align*}\r\n        0&=\\frac{\\mathrm d(T+V)}{t}\\\\\r\n        &=\\frac{\\mathrm d}{\\mathrm dt}\\left( \\frac{M+I/a^2}{2}\\dot{x}^2-Mgx\\sin\\alpha \\right)\\\\\r\n        &=(M+I/a^2)\\dot{x}\\ddot{x}-Mg\\dot{x}\\sin\\alpha\\\\\r\n        \\implies \\left( M+\\frac{I}{a^2} \\right)\\ddot{x}&=Mg\\sin\\alpha\r\n    \\end{align*}\r\n    Note that when $I=0$, this is exactly the equation for a frictionless particle, therefore the rotation makes acceleration smaller.\r\n    Now for a cylinder in question, we have $I=Ma^2/2$, hence\r\n    $$\\ddot{x}=\\frac{2}{3}g\\sin\\alpha$$\r\n    We can also obtain the result by using forces and torques.\r\n    By considering the rate of change of linear momentum along the plane, we have $M\\dot{v}=Mg\\sin\\alpha-F$ and the rate of change of angular momentum about the center of mass then gives $I\\dot\\omega=aF$.\r\n    So as it is rolling, $\\dot{v}=a\\dot\\omega$, whence\r\n    $$M\\dot{v}=Mg\\sin\\alpha-\\frac{I\\dot{v}}{a^2}$$\r\n    Thus $(M+I/a^2)\\dot{v}=Mg\\sin\\alpha$ as above.\\\\\r\n    There is yet another way to do this:\r\n    Consider the torque about $P$, we have $I_P=I+Ma^2$ by the parallel axis theroem, also the gravitational torque has $I_P\\dot\\omega=Mga\\sin\\alpha$.\r\n    So $v=a\\omega$ gives $(I+Ma^2)\\dot{v}/a=Mga\\sin\\alpha$.\r\n\\end{example}\r\n\\begin{example}\r\n    We want to study the transition from a sliding motion to a rolling one.\r\n    Consider a snooker ball on a horizontal plane hit by a cue instantaneously which gives it an initial velocity $v_0$.\r\n    Initially $v=v_0$ and $\\omega_0$, where sliding occurs (so no rotation at $t=0$).\r\n    The kinetic frictional force obeys $F=\\mu N=\\mu Mg$ where $\\mu$ is a constant (coefficient of kinetic friction).\r\n    The linear motion has $M\\dot{v}=-F$ and the angular motion $I\\dot\\omega=aF$.\r\n    Also for a sphere $I=2Ma^2/5$, hence we have, by integrating,\r\n    $$\\begin{cases}\r\n        v=v_0-\\mu gt\\\\\r\n        \\omega=5\\mu gt/(2a)\r\n    \\end{cases}$$\r\n    So when the ball is still moving,\r\n    $$0\\le v_{\\rm slip}=v-a\\omega=v_0-\\frac{7}{2}\\mu gt$$\r\n    So the total time of rolling is $t_{\\rm roll}=2v_0/(7\\mu g)$.\r\n    During $0\\le t\\le t_{\\rm roll}$, the friction acts to decrease $v$ and increase $\\omega$ till the no-slip condition is satisfied, when $t=t_{\\rm roll}$ and $v=v_{\\rm roll}=5v_0/7$.\r\n    But at $t_{\\rm roll}$, the rolling could as well persist but the friction does no further work.\r\n    At $t=t_{\\rm roll}$, the kinetic energy is\r\n    $$T=\\frac{1}{2}Mv^2+\\frac{1}{2}I\\omega^2=\\frac{1}{2}M\\left( 1+\\frac{2}{5} \\right)v_{\\rm roll}^2=\\frac{5}{7}\\left( \\frac{1}{2}Mv_0^2 \\right)$$\r\n    So the loss of KE due to friction has a total of\r\n    $$\\int_0^{t_{\\rm roll}}Fv_{\\rm slip}\\,\\mathrm dt=\\int_0^{t_{\\rm roll}}F\\left( v_0-\\frac{7}{2}\\mu gt \\right)\\,\\mathrm dt=\\frac{1}{7}Mv_0^2$$\r\n\\end{example}\r\n", "meta": {"hexsha": "e04211b9b1422743c7d5d8fc76ff7759db22deb2", "size": 17402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/rigid.tex", "max_stars_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_stars_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7/rigid.tex", "max_issues_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_issues_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7/rigid.tex", "max_forks_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_forks_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.0676328502, "max_line_length": 318, "alphanum_fraction": 0.6962992759, "num_tokens": 5558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.6502622875395654}}
{"text": "\n%   add on random walks and connection with ergodicity and detailed balance\n%   show connection with eigenvalues of transition matrix and stable solution\n%   mention metropolis-hastings\n\n\n\\chapter{Random walks and the Metropolis algorithm}\\label{chap:mcrandom} \n\\begin{quotation}\n The way that can be spoken of is not the  constant way. (Tao Te Ching, Book I, I.1) {\\em Lao Tzu}\n\\end{quotation}\n\\abstract{We present the theory of random walks, Markov chains and present \nthe Metropolis algorithm.}\n\n\\section{Motivation}\nIn the previous chapter we discussed technical aspects of Monte Carlo integration\nsuch as algorithms for generating random numbers and integration of multidimensional \nintegrals.\nThe latter topic served to illustrate two key topics in Monte Carlo simulations,\nnamely a proper selection of variables and importance sampling. An intelligent selection\nof variables, good sampling techniques \nand guiding functions can be crucial for the outcome of our Monte Carlo simulations.\nExamples of this will be demonstrated in the chapters on statistical and quantum physics\napplications. Here we make a detour from this main area of applications. The focus\nis on diffusion and random walks. Furthermore, we will use these topics to derive the famous Metropolis algorithm.\n\nThe rationale for this is that the tricky part of an actual Monte Carlo simulation \nresides in the appropriate selection of random states, and thereby numbers, \naccording to the probability distribution (PDF)\nat hand. \n\nSuppose our PDF is given by the well-known normal distribution. Think of for\nexample the velocity distribution of an  ideal gas in a container. In our simulations we\ncould then  accept or reject new moves with a probability proportional to\nthe normal distribution. This would parallel our example on the sixth dimensional\nintegral in the previous chapter. However, in this case we would end up rejecting basically\nall moves since the probabilities are exponentially small in most cases. The result would\nbe that we barely moved from the initial position. Our statistical averages would then\nbe significantly biased and most likely not very reliable. \n\nInstead, all Monte Carlo schemes used are based on Markov processes in order to generate new\nrandom states. A Markov process is a random walk with a selected probability for making a\nmove. The new move is independent of the previous history of the system. \nThe Markov process is used repeatedly in Monte Carlo simulations in order to generate\nnew random states. \nThe reason for choosing a Markov process is that when it is run for a \nlong enough time starting with a random state, \nwe will eventually reach the most likely state of the system.\nIn thermodynamics, this means that after a certain number of Markov processes\nwe reach an equilibrium distribution. \nThis mimicks the way a real system reaches \nits most likely state at a given temperature of the surroundings. \n\nTo reach this distribution, the Markov process needs to obey two important conditions, that of\nergodicity and detailed balance. These conditions impose constraints on our algorithms\nfor accepting or rejecting new random states. The Metropolis algorithm discussed here \nabides to both these constraints and is discussed in more detail in Section \n\\ref{sec:metropolis}. \nThe Metropolis algorithm is widely used in Monte Carlo \nsimulations of physical systems and the understanding of it rests within \nthe interpretation of random walks and Markov processes.\nHowever, before we do that we discuss the intimate link between\nrandom walks, Markov processes and the diffusion equation. In section \n\\ref{sec:profrandomdiff}\nwe show that a Markov process is nothing but \nthe discretized version of the diffusion equation.\nDiffusion and random walks are discussed from a more experimental point of view in the \nnext section. There we show also a simple algorithm for random walks and discuss eventual\nphysical implications. \nWe end this chapter with a discussion of one of the most used algorithms for generating new steps, namely the Metropolis\nalgorithm. This algorithm, which is based on  Markovian random walks satisfies both the ergodicity and detailed balance\nrequirements and is widely in applications of Monte Carlo simulations in the natural sciences.  \nThe Metropolis algorithm is used in our studies of phase transitions in statistical physics and \nthe simulations of quantum mechanical systems.  \n\\section{Diffusion Equation and Random Walks}\\label{sec:diffrandom}\nPhysical systems subject to random influences from the ambient have a long history,\ndating back to the famous experiments by the British Botanist R.~Brown on\n pollen of different plants dispersed in water. This lead to the famous concept of Brownian\nmotion. In general, small fractions of any system exhibit the same behavior when exposed \nto random fluctuations of the medium. Although apparently non-deterministic, the rules\nobeyed by such Brownian systems are laid out within the framework of diffusion and \nMarkov chains. The fundamental works on Brownian motion were developed by A.~Einstein\nat the turn of the last century.\n\nDiffusion and the diffusion equation are central topics in both Physics and Mathematics,\nand their ranges of applicability span from stellar dynamics to the diffusion \nof particles governed by Schr\\\"odinger's equation. The latter is, for a free particle, \nnothing but the diffusion equation in complex time!\n\nLet us consider the one-dimensional diffusion equation. We study a large ensemble of particles\nperforming Brownian motion along the $x$-axis. There is no interaction between the particles.\n\nWe define $w(x,t)dx$ as the probability of finding a given number of particles in an\ninterval of length $dx$ in $x\\in [x, x+dx]$ at a time $t$. This quantity is our probability\ndistribution function (PDF). The quantum physics equivalent of \n$w(x,t)$ is the wave \nfunction  itself. This diffusion interpretation of Schr\\\"odinger's equation forms the starting\npoint for diffusion Monte Carlo techniques in quantum physics.\n\nGood overview texts are the books of Robert and Casella and Karatsas, see Refs.~\\cite{robertcasella,karatsas}.\n\n\\subsection{Diffusion Equation}\nFrom experiment there are strong indications that the flux of particles $j(x,t)$, viz., the number of particles passing $x$ at a time $t$ is proportional to the \ngradient of $w(x,t)$. This proportionality is expressed mathematically through \n\\[\n    j(x,t) = -D\\frac{\\partial w(x,t)}{\\partial x},\n\\]\nwhere $D$ is the so-called diffusion constant, with dimensionality length$^2$ per time.\nIf the number of particles is conserved, we have the continuity equation\n\\[\n    \\frac{\\partial j(x,t)}{\\partial x} = -\\frac{\\partial w(x,t)}{\\partial t},\n\\]\nwhich leads to\n\\begin{equation}\\label{eq:diffequation1}\n    \\frac{\\partial w(x,t)}{\\partial t} = \n    D\\frac{\\partial^2w(x,t)}{\\partial x^2},\n\\end{equation}\nwhich is the diffusion equation in one dimension. \n\nWith the probability distribution function $w(x,t)dx$ we can use the results from the\nprevious chapter to compute expectation values such as  the mean distance\n\\[\n   \\langle x(t)\\rangle = \\int_{-\\infty}^{\\infty}xw(x,t)dx,\n\\]\nor\n\\[\n   \\langle x^2(t)\\rangle = \\int_{-\\infty}^{\\infty}x^2w(x,t)dx, \n\\]\nwhich allows for the computation of the variance\n$\\sigma^2=\\langle x^2(t)\\rangle-\\langle x(t)\\rangle^2$. Note well that \nthese expectation values are time-dependent. In a similar way we can also\ndefine expectation values of functions $f(x,t)$ as \n\\[\n   \\langle f(x,t)\\rangle = \\int_{-\\infty}^{\\infty}f(x,t)w(x,t)dx.\n\\]\nSince $w(x,t)$ is now treated as a PDF, it needs to obey the same criteria\nas discussed in the previous chapter. However, the normalization condition\n\\[\n   \\int_{-\\infty}^{\\infty}w(x,t)dx=1\n\\]\nimposes significant constraints on $w(x,t)$. These are\n\\[\n   w(x=\\pm \\infty,t)=0 \\hspace{1cm} \n   \\frac{\\partial^{n}w(x,t)}{\\partial x^n}|_{x=\\pm\\infty} = 0,\n\\]\nimplying that when we study the time-derivative\n${\\partial\\langle x(t)\\rangle}/{\\partial t}$, we obtain after integration by parts and using \nEq.~(\\ref{eq:diffequation1})  \n\\[\n   \\frac{\\partial \\langle x\\rangle}{\\partial t} = \n   \\int_{-\\infty}^{\\infty}x\\frac{\\partial w(x,t)}{\\partial t}dx=\n   D\\int_{-\\infty}^{\\infty}x\\frac{\\partial^2w(x,t)}{\\partial x^2}dx,\n \\]\nleading to\n\\[\n   \\frac{\\partial \\langle x\\rangle}{\\partial t} = \n   Dx\\frac{\\partial w(x,t)}{\\partial x}|_{x=\\pm\\infty}-\n   D\\int_{-\\infty}^{\\infty}\\frac{\\partial w(x,t)}{\\partial x}dx,\n \\]\nimplying that\n\\[\n   \\frac{\\partial \\langle x\\rangle}{\\partial t} = 0.\n \\]\nThis means in turn that $\\langle x\\rangle$ is independent of time.\nIf we choose the initial position $x(t=0)=0$,\nthe average displacement $\\langle x\\rangle= 0$.\nIf we link this discussion to a random walk in one dimension with equal probability\nof jumping to the left or right and with an initial position $x=0$, then our probability\ndistribution remains centered around $\\langle x\\rangle= 0$ as function of time.\nHowever, the variance is not necessarily 0. Consider first\n\\[\n   \\frac{\\partial \\langle x^2\\rangle}{\\partial t} = \n   Dx^2\\frac{\\partial w(x,t)}{\\partial x}|_{x=\\pm\\infty}-\n   2D\\int_{-\\infty}^{\\infty}x\\frac{\\partial w(x,t)}{\\partial x}dx,\n \\]\nwhere we have performed an integration by parts as we did \nfor $\\frac{\\partial \\langle x\\rangle}{\\partial t}$. A further integration by parts \nresults in  \n\\[\n   \\frac{\\partial \\langle x^2\\rangle}{\\partial t} = \n   -Dxw(x,t)|_{x=\\pm\\infty}+\n   2D\\int_{-\\infty}^{\\infty}w(x,t)dx=2D,\n \\]\nleading to\n\\[\n   \\langle x^2\\rangle = 2Dt,\n \\]\nand the variance as \n\\begin{equation}\\label{eq:variancediffeq}\n   \\langle x^2\\rangle-\\langle x\\rangle^2 = 2Dt.\n \\end{equation}\nThe root mean square displacement after a time $t$ is then \n\\[\n   \\sqrt{\\langle x^2\\rangle-\\langle x\\rangle^2} = \\sqrt{2Dt}.\n \\]\nThis should be contrasted to the displacement of a free particle with initial velocity\n$v_0$. In that case the distance from the initial position after a time $t$ is\n$x(t) = vt$ whereas for a diffusion process the root mean square value is \n$\\sqrt{\\langle x^2\\rangle-\\langle x\\rangle^2} \\propto \\sqrt{t}$.\nSince diffusion is strongly linked with random walks, we could say that a random walker\nescapes much more slowly from the starting point than would a free particle.\nWe can vizualize the above in the following figure.\nIn Fig.~\\ref{fig:normal_distribution} we have assumed that our distribution is\ngiven by a normal distribution with variance $\\sigma^2=2Dt$, centered at $x=0$. \nThe distribution reads\n\\[\n    w(x,t)dx = \\frac{1}{\\sqrt{4\\pi Dt}}\\exp{(-\\frac{x^2}{4Dt})}dx.\n\\]\nAt a time $t=2$s the new variance is $\\sigma^2=4D$s, implying that the root mean square value\nis $\\sqrt{\\langle x^2\\rangle-\\langle x\\rangle^2} = 2\\sqrt{D}$.\nAt a further time $t=8$ we have $\\sqrt{\\langle x^2\\rangle-\\langle x\\rangle^2} = 4\\sqrt{D}$.\nWhile time has elapsed by a factor of $4$, the root mean square has only changed by a factor\nof 2. \nFig.~\\ref{fig:normal_distribution} demonstrates the spreadout of the distribution as time elapses.\nA typical example can be the diffusion of gas molecules in a container or the distribution of cream in a cup of coffee. In both cases we can assume that the  \nthe initial distribution is represented by a normal distribution.\n\\begin{figure}\n\\begin{center}\n\\input{figures/spread.tex}\n\\caption{Time development of a normal distribution with variance $\\sigma^2=2Dt$ and with \n$D=1$m$^2$/s. The solid line\nrepresents the distribution at $t=2$s while the dotted line stands for $t=8$s.\\label{fig:normal_distribution}}\n\\end{center}\n\\end{figure}\n\\subsection{Random Walks}\nConsider now a random walker in one dimension, with probability $R$ of moving to the right\nand $L$ for moving to the left. \nAt $t=0$ we place the walker at $x=0$, as indicated in Fig.~\\ref{fig:walker1dim}.\nThe walker can then jump, with the above probabilities, either to the left or to the\nright for each time step. Note that in principle we could also have the possibility that the\nwalker remains in the same position. This is not implemented in this example.\nEvery step has length $\\Delta x = l$. Time is discretized and we have a jump either to the left or\nto the right at every time step.\n\\begin{figure}\n\\setlength{\\unitlength}{1cm}\n\\begin{picture}(16,3)\n\\thicklines\n\\dottedline[$\\bullet$]{2}(0,0)(14,0)\n\\put(0,0){\\line(1,0){14}}\n\\put(0,0.5){\\makebox(0,0){$..$}}\n\\put(2,0.5){\\makebox(0,0){$-3l$}}\n\\put(4,0.5){\\makebox(0,0){$-2$}}\n\\put(6,0.5){\\makebox(0,0){$-l$}}\n\\put(8,0.5){\\makebox(0,0){$x=0$}}\n\\put(10,0.5){\\makebox(0,0){$l$}}\n\\put(12,0.5){\\makebox(0,0){$2l$}}\n\\put(14,0.5){\\makebox(0,0){$3l$}}\n\\put(16,0.5){\\makebox(0,0){$..$}}\n\\end{picture}\n\\caption{One-dimensional walker which can jump either to \nthe left or to the right. Every step has length $\\Delta x = l$.\\label{fig:walker1dim}}\n\\end{figure}\nLet us now assume that we have \nequal probabilities for jumping to the left or to the right, i.e., \n$L=R=1/2$.\nThe average displacement\nafter $n$ time steps is\n\\[\n   \\langle x(n)\\rangle = \\sum_{i}^{n} \\Delta x_i = 0 \\hspace{1cm} \\Delta x_i=\\pm l,\n\\]\nsince we have an equal probability of jumping either to the left or to right.\nThe value of $\\langle x(n)^2\\rangle$ is\n\\[\n   \\langle x(n)^2\\rangle = \\left(\\sum_{i}^{n} \\Delta x_i\\right)\\left(\\sum_{j}^{n} \\Delta x_j\\right)=\\sum_{i}^{n} \\Delta x_i^2+\n\\sum_{i\\ne j}^{n} \\Delta x_i\\Delta x_j=l^2n.\n\\]\nFor many enough steps the non-diagonal contribution is\n\\[\n   \\sum_{i\\ne j}^{N} \\Delta x_i\\Delta x_j=0,\n\\]\nsince $\\Delta x_{i,j} = \\pm l$.\nThe variance is then\n\\begin{equation}\n   \\langle x(n)^2\\rangle - \\langle x(n)\\rangle^2 = l^2n.\n   \\label{eq:rwvariance}\n\\end{equation}\nIt is also rather straightforward to compute the variance for $L\\ne R$. The result is\n\\[\n   \\langle x(n)^2\\rangle - \\langle x(n)\\rangle^2 = 4LRl^2n.\n\\]\nIn Eq.~(\\ref{eq:rwvariance}) the variable $n$ represents the number of time\nsteps. If we define $n=t/\\Delta t$, we can then couple the variance result \nfrom a random walk\nin one dimension with the variance  from the diffusion equation of Eq.~(\\ref{eq:variancediffeq})\nby defining the diffusion constant as \n\\[\n   D = \\frac{l^2}{\\Delta t}.\n\\]\nIn the next section we show in detail that this is the case.\n\nThe program below demonstrates the simplicity of the one-dimensional random walk algorithm.\nIt is straightforward to extend this program to two or three dimensions as well.\nThe input is the number of time steps, the probability for a move to the left or to the right\nand the total number of Monte Carlo samples. It computes the average displacement and the variance\nfor one random walker for a given number of Monte Carlo samples. Each sample is thus to be \nconsidered as one experiment with a given number of walks.\nThe interesting part of the algorithm is described in the \nfunction \\lstinline{mc_sampling}. The other functions read or write the results from screen or file\nand are similar in structure to programs discussed previously.\nThe main program reads the name of the output file from screen and sets up the arrays\ncontaining the walker's position after a given number of steps. The corresponding program for a two-dimensional\nrandom walk (not listed in the main text) is found under programs/chapter12/program2.cpp\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter12/cpp/program1.cpp}}]\n/*\n  1-dim random walk program. \n  A walker makes several trials steps with\n  a given number of walks per trial\n*/\n#include <iostream>\n#include <fstream>\n#include <iomanip>\n#include \"lib.h\"\nusing namespace  std;\n\n// Function to read in data from screen, note call by reference\nvoid initialise(int&, int&, double&) ;\n// The Mc sampling for random walks\nvoid  mc_sampling(int, int, double, int *, int *);\n// prints to screen the results of the calculations \nvoid  output(int, int, int *, int *);\n\nint main()\n{\n  int max_trials, number_walks; \n  double move_probability;\n  // Read in data \n  initialise(max_trials, number_walks, move_probability) ;\n  int *walk_cumulative = new int [number_walks+1];\n  int *walk2_cumulative = new int [number_walks+1];\n  for (int walks = 1; walks <= number_walks; walks++){   \n    walk_cumulative[walks] = walk2_cumulative[walks] = 0;\n  } // end initialization of vectors\n  // Do the mc sampling  \n  mc_sampling(max_trials, number_walks, move_probability, \n              walk_cumulative, walk2_cumulative);\n  // Print out results \n  output(max_trials, number_walks, walk_cumulative, \n         walk2_cumulative);\n  delete [] walk_cumulative; // free memory\n  delete [] walk2_cumulative; \n  return 0; \n} // end main function\n\\end{lstlisting}\nThe  input and output functions are \n\\begin{lstlisting} \nvoid initialise(int& max_trials, int& number_walks, double& move_probability) \n{\n  cout << \"Number of Monte Carlo trials =\"; \n  cin >> max_trials;\n  cout << \"Number of attempted walks=\";\n  cin >> number_walks;\n  cout << \"Move probability=\";\n  cin >> move_probability;\n}  // end of function initialise   \n\n\nvoid output(int max_trials, int number_walks, \n            int *walk_cumulative, int *walk2_cumulative)\n{\n  ofstream ofile(\"testwalkers.dat\");\n  for( int  i = 1; i <=  number_walks; i++){\n    double xaverage = walk_cumulative[i]/((double) max_trials);\n    double x2average = walk2_cumulative[i]/((double) max_trials);\n    double variance = x2average - xaverage*xaverage;\n    ofile << setiosflags(ios::showpoint | ios::uppercase);\n    ofile << setw(6) << i;\n    ofile << setw(15) << setprecision(8) << xaverage;\n    ofile << setw(15) << setprecision(8) << variance << endl;\n  }\n  ofile.close();\n}  // end of function output \n\\end{lstlisting}\nThe algorithm is in the function \\lstinline{mc_sampling} and tests the probability \nof moving to the left or to the right by generating a random number.\n\\begin{lstlisting}\nvoid mc_sampling(int max_trials, int number_walks, \n                 double move_probability, int *walk_cumulative, \n                 int *walk2_cumulative)\n{\n  long idum;\n  idum=-1;  // initialise random number generator\n  for (int trial=1; trial <= max_trials; trial++){\n    int position = 0;\n    for (int walks = 1; walks <= number_walks; walks++){   \n      if (ran0(&idum) <= move_probability) {\n\tposition += 1;\n      } \n      else {\n\tposition -= 1;\n      }\n      walk_cumulative[walks] += position;\n      walk2_cumulative[walks] += position*position;\n    }  // end of loop over walks\n  } // end of loop over trials\n}   // end mc_sampling function  \n\\end{lstlisting}\nFig.~\\ref{fig:random1sigma} shows that the variance increases linearly as function\nof the number of time steps, as expected from the closed-form results.\nSimilarly, the mean displacement in Fig.~\\ref{fig:random1x} oscillates around zero.\n\\begin{figure}\n\\begin{center}\n\\input{figures/random1sigma.tex}\n\\caption{Time development of $\\sigma^2$\n for a random walker. 100000\nMonte Carlo samples were used with the function ran1 and a seed set to  $-1$.\\label{fig:random1sigma}}\n\\end{center}\n\\end{figure}\n\\begin{figure}\n\\begin{center}\n\\input{figures/random1x.tex}\n\\caption{Time development of $\\langle x(t) \\rangle $ for a random walker. 100000\nMonte Carlo samples were used with the function ran1 and a seed set to  $-1$.\\label{fig:random1x}}\n\\end{center}\n\\end{figure}\n\n\n\n\n\\section{Microscopic Derivation of the Diffusion Equation}\\label{sec:profrandomdiff}\n\nWhen solving partial differential equations such as the diffusion equation numerically,\nthe derivatives are always discretized. Recalling our discussions from Chapter \n\\ref{chap:differentiate}, we can rewrite the time derivative as\n\\[\n    \\frac{\\partial w(x,t)}{\\partial t} \\approx \n    \\frac{w(i,n+1)-w(i,n)}{\\Delta t},\n\\]\nwhereas the gradient is approximated as\n\\[\n    D\\frac{\\partial^2w(x,t)}{\\partial x^2}\\approx \n    D\\frac{w(i+1,n)+w(i-1,n)-2w(i,n)}{(\\Delta x)^2},\n\\]\nresulting in the discretized diffusion equation\n\\[\n   \\frac{w(i,n+1)-w(i,n)}{\\Delta t}=D\\frac{w(i+1,n)+w(i-1,n)-2w(i,n)}{(\\Delta x)^2},\n\\]\nwhere $n$ represents a given time step and $i$ a step in the $x$-direction.\nThe solution of such equations is discussed in our chapter on partial differential\nequations, see Chapter \\ref{chap:partial}.\nThe aim here is to show that we can derive the discretized diffusion equation from a Markov process\nand thereby demonstrate the close connection between the important physical process \ndiffusion and random walks. Random walks allow for an intuitive way of picturing the process\nof diffusion. In addition, as demonstrated in the previous section, it is easy to simulate a \nrandom walk.\n\n\\subsection{Discretized Diffusion Equation and Markov Chains}\nA Markov process allows in principle for a microscopic description of Brownian motion.\nAs with the random walk studied in the previous section, we consider a particle \nwhich moves along the  $x$-axis in the form of a series of jumps with step length \n$\\Delta x = l$. Time and space are discretized and the subsequent moves are\nstatistically independent, i.e., the new move depends only on the previous step\nand not on the results from earlier trials. \nWe start at a position $x=jl=j\\Delta x$ and move to \na new position $x =i\\Delta x$ during a step $\\Delta t=\\epsilon$, where \n$i\\ge  0$ and $j\\ge 0$ are integers. \nThe original probability distribution function (PDF) of the particles is given by  \n$w_i(t=0)$ where $i$ refers to a specific position on the grid in \nFig.~\\ref{fig:walker1dim}, with $i=0$ representing $x=0$. \nThe function $w_i(t=0)$ is now the discretized version of $w(x,t)$.\nWe can regard the discretized PDF as a vector.\nFor the Markov process we have a transition probability from a position\n$x=jl$ to a position $x=il$ given by \n\\[\n   W_{ij}(\\epsilon)=W(il-jl,\\epsilon)=\\left\\{\\begin{array}{cc}\\frac{1}{2} & |i-j| = 1\\\\\n             0 & \\mathrm{else} \\end{array} \\right. ,\n\\]\nwhere $W_{ij}$ is normally called \nthe transition probability and we can represent it, see below,\nas a matrix. Note that this matrix is not a stochastic matrix as long as it is a finite matrix.\nOur new PDF $w_i(t=\\epsilon)$ is now related to the PDF at\n$t=0$ through the relation \n\\[ \n   w_i(t=\\epsilon) =\\sum_{j} W(j\\rightarrow i)w_j(t=0).\n\\]   \nThis equation represents the discretized time-development of an original \nPDF. It is a microscopic way of representing the process shown in\nFig.~\\ref{fig:normal_distribution}.\nSince both $W$ and $w$ represent probabilities, they have to be normalized, i.e., we require\nthat at each time step we have \n\\[ \n   \\sum_i w_i(t) = 1, \n\\]\nand \n\\[ \n   \\sum_j W(j\\rightarrow i) = 1,\n\\]\nwhich applies for all $j$-values.\nThe further constraints are\n$0 \\le W_{ij} \\le 1$  and  $0 \\le w_{j} \\le 1$.\nNote that the probability for remaining at the same place is in general \nnot necessarily equal zero. In our Markov process we allow only for jumps to the left or to \nthe right.\n\nThe time development of our initial PDF can now be represented through the action of\nthe transition probability matrix applied $n$ times. At a \ntime  $t_n=n\\epsilon$ our initial distribution has developed into \n\\[\n   w_i(t_n) = \\sum_jW_{ij}(t_n)w_j(0),\n\\]\nand defining \n\\[\n   W(il-jl,n\\epsilon)=(W^n(\\epsilon))_{ij}\n\\]\nwe obtain \n\\[\n   w_i(n\\epsilon) = \\sum_j(W^n(\\epsilon))_{ij}w_j(0),\n\\]\nor in matrix form\n\\be\\label{eq:wfinal}\n   \\hat{w}(n\\epsilon) = \\hat{W}^n(\\epsilon)\\hat{w}(0).\n\\ee\nThe matrix $\\hat{W}$ can be written in terms of two matrices\n\\[\n    \\hat{W} = \\frac{1}{2}\\left(\\hat{L}+\\hat{R}\\right),\n\\]\nwhere $\\hat{L}$ and $\\hat{R}$ represent the transition probabilities for a\njump to the left or the right, respectively.\nFor a $4\\times 4$ case we could write these matrices as\n\\[ \n   \\hat{R} = \\left(\\begin{array}{cccc} 0 & 0 & 0 & 0\\\\                   \n                                 1 & 0 & 0 & 0\\\\                   \n                                 0 & 1 & 0 & 0\\\\                   \n                                 0 & 0 & 1 & 0\\end{array} \\right),\n\\]                   \nand \n\\[ \n   \\hat{L} = \\left(\\begin{array}{cccc} 0 & 1 & 0 & 0\\\\                   \n                                 0 & 0 & 1 & 0\\\\                   \n                                 0 & 0 & 0 & 1\\\\                   \n                                 0 & 0 & 0 & 0\\end{array} \\right).\n\\]                   \nHowever, \nin principle these are infinite dimensional matrices since the number of time\nsteps are very large or infinite. For the infinite case we can write these\nmatrices \n$R_{ij} = \\delta_{i,(j+1)}$  and $L_{ij} =  \\delta_{(i+1),j}$, implying that\n\\be  \\label{eq:rl1}\n   \\hat{L}\\hat{R}=\\hat{R}\\hat{L}=I,\n\\ee\nwhich applies in the case of infinite matrices\nand \n\\be \\label{eq:rl2}\n    \\hat{L}=\\hat{R}^{-1}\n\\ee\nTo see that $\\hat{L}\\hat{R}=\\hat{R}\\hat{L}=1$, perform e.g., the matrix multiplication\n\\[\n    \\hat{L}\\hat{R}= \\sum_{k}\\hat{L}_{ik}\\hat{R}_{kj}=\\sum_k\\delta_{(i+1),k}\\delta_{k,(j+1)}\n     = \\delta_{i+1,j+1}=\\delta_{i,j},\n\\]\nand only the diagonal matrix elements are different from zero. \n\n\nFor the first time step we have thus\n\\[\n    \\hat{W} = \\frac{1}{2}\\left(\\hat{L}+\\hat{R}\\right),\n\\]\nand using the properties in Eqs.~(\\ref{eq:rl1}) and (\\ref{eq:rl2})\nwe have after two time steps\n\\[\n   \\hat{W}^2(2\\epsilon)=\\frac{1}{4}\\left(\\hat{L}^2+\\hat{R}^2+2\\hat{R}\\hat{L}\\right),\n\\]\nand similarly after three time steps\n\\[\n   \\hat{W}^3(3\\epsilon)=\\frac{1}{8}\n      \\left(\\hat{L}^3+\\hat{R}^3+3\\hat{R}\\hat{L}^2+3\\hat{R}^2\\hat{L}\\right).\n\\]\nUsing the binomial formula\n\\[\n\\sum_{k=0}^{n}\\left(\\begin{array}{c} n\\\\k\\end{array}\\right)\n     \\hat{a}^k\\hat{b}^{n-k}=\n    (a+b)^n,\n\\]ee\nwe have that the transition matrix after $n$ time steps can be written as\n \\[\n\\hat{W}^n(n\\epsilon))=\\frac{1}{2^n}\\sum_{k=0}^{n}\\left(\\begin{array}{c} n\\\\k\\end{array}\\right)\n     \\hat{R}^k\\hat{L}^{n-k},\n\\]\nor\n\\[\n\\hat{W}^n(n\\epsilon))=\\frac{1}{2^n}\\sum_{k=0}^{n}\\left(\\begin{array}{c} n\\\\k\\end{array}\\right)\n     \\hat{L}^{n-2k}=\\frac{1}{2^n}\\sum_{k=0}^{n}\\left(\\begin{array}{c} n\\\\k\\end{array}\\right)\n     \\hat{R}^{2k-n},\n\\]\nand using \n$R_{ij}^m = \\delta_{i,(j+m)}$  and $L_{ij}^m = \\delta_{(i+m),j}$\nwe arrive at\n\\be\\label{eq:binomialW}\n   W(il-jl,n\\epsilon)=\n\\left\\{\\begin{array}{cc}\\frac{1}{2^n}\\left(\\begin{array}{c} n\\\\\\frac{1}{2}(n+i-j)\\end{array}\\right) & |i-j| \\le n \\\\\n                                             0 & \\mathrm{else} \\end{array} \\right.,\n\\ee\nand $n+i-j$ has to be an even number.\nWe note that the transition matrix for a Markov process has three important properties:\n\\begin{svgraybox}\n\\begin{itemize} \n\\item It depends only on the difference in space $i-j$, it is thus homogenous in space.\n\\item It is also isotropic in space since it is unchanged when we go from $(i,j)$ to $(-i,-j)$.\n\\item It is homogenous in time since it depends only the difference between the initial time and \nfinal time.\n\\end{itemize}\n\\end{svgraybox}\nIf we place the walker at $x=0$ at $t=0$ we can represent the initial PDF \nwith $w_i(0) = \\delta_{i,0}$. Using Eq.~(\\ref{eq:wfinal}) we have \n\\[\n   w_i(n\\epsilon) = \\sum_j(W^n(\\epsilon))_{ij}w_j(0)=\\sum_j\\frac{1}{2^n}\\left(\\begin{array}{c} n\\\\\\frac{1}{2}(n+i-j)\\end{array}\\right)\\delta_{j,0},\n\\]\nresulting in\n\\[\n   w_i(n\\epsilon)=\\frac{1}{2^n}\\left(\\begin{array}{c} n\\\\\\frac{1}{2}(n+i)\\end{array}\\right) \n   \\hspace{1cm} |i| \\le n .\n\\]\nWe can then use the recursion relation for the binomials \n\\be\n   \\left(\\begin{array}{c} n+1\\\\\\frac{1}{2}(n+1+i)\\end{array}\\right)=\n    \\left(\\begin{array}{c} n\\\\\\frac{1}{2}(n+i+1)\\end{array}\\right)+\n    \\left(\\begin{array}{c} n\\\\\\frac{1}{2}(n+i-1)\\end{array}\\right)\n\\label{eq:recbinomials}\n\\ee\nto obtain the discretized diffusion equation. In order to achieve this,\nwe define $x = il$, where $l$ and $i$ are integers, and $ t = n\\epsilon$. We can then\nrewrite the probability distribution as \n\\[\n   w(x,t) = w(il,n\\epsilon) = w_i(n\\epsilon)=\\frac{1}{2^n}\\left(\\begin{array}{c} n\\\\\\frac{1}{2}(n+i)\\end{array}\\right) \n   \\hspace{1cm} |i| \\le n,\n\\]\nand rewrite Eq.~(\\ref{eq:recbinomials}) as\n\\[\n   w(x,t+\\epsilon)=\\frac{1}{2}w(x+l,t)+\\frac{1}{2}w(x-l,t).\n\\]\nAdding and subtracting $w(x,t)$ and multiplying both sides with \n$l^2/\\epsilon$ we have \n\\[\n      \\frac{w(x,t+\\epsilon)-w(x,t)}{\\epsilon}=\\frac{l^2}{2\\epsilon}\n      \\frac{w(x+l,t)-2w(x,t)+w(x-l,t)}{l^2}.\n\\]\nIf we identify $D=l^2/2\\epsilon$ and $l=\\Delta x$ and \n$\\epsilon = \\Delta t$ we see that this is nothing but the discretized version of the\ndiffusion equation. Taking the limits $\\Delta x \\rightarrow 0$ and\n$\\Delta t \\rightarrow 0$ we recover\n\\[\n    \\frac{\\partial w(x,t)}{\\partial t} =    D\\frac{\\partial^2w(x,t)}{\\partial x^2},\n\\]\nthe diffusion equation.\n\n\\subsubsection{An Illustrative Example}\nThe following simple example may help in understanding the meaning of \nthe transition matrix $\\hat{W}$ and the vector $\\hat{w}$.\nConsider the $4\\times 4$ matrix $\\hat{W}$\n\\[\n   \\hat{W} = \\left(\\begin{array}{cccc} 1/4 & 1/9 & 3/8 & 1/3 \\\\                   \n                                       2/4 & 2/9 & 0 & 1/3\\\\                   \n                                       0   & 1/9 & 3/8 & 0\\\\\n                                       1/4 & 5/9&  2/8 & 1/3 \\end{array} \\right),\n\\]\nand we choose our initial state as \n\\[\n\\hat{w}(t=0)=  \\left(\\begin{array}{c} 1\\\\                   \n                                 0\\\\\n                                 0 \\\\                   \n                                 0 \\end{array} \\right).\n\\]\nWe note that both the vector and the matrix are properly normalized. Summing the vector elements gives one and\nsumming over columns for the matrix results also in one.  Furthermore, the largest eigenvalue is one.\nWe act then on $\\hat{w}$ with $\\hat{W}$.\nThe first iteration is\n\\[\n   \\hat{w}(t=\\epsilon) = \\hat{W}\\hat{w}(t=0),\n\\]   \nresulting in\n\\[\n\\hat{w}(t=\\epsilon)=  \\left(\\begin{array}{c} 1/4\\\\                   \n                                1/2 \\\\\n                                0.0 \\\\                   \n                                1/4 \\end{array} \\right).\n\\]\n\nThe next iteration results in \n\\[\n   \\hat{w}(t=2\\epsilon) = \\hat{W}\\hat{w}(t=\\epsilon),\n\\]   \nresulting in\n\\[\n\\hat{w}(t=2\\epsilon)=  \\left(\\begin{array}{c} 0.201389\\\\\n   0.319444 \\\\\n   0.055556 \\\\\n   0.423611 \\end{array} \\right).\n\\]\nNote that the vector $\\hat{w}$ is always normalized to $1$. \nWe find the steady state of the system by solving the linear set of equations\n\\[ {\\bf w}(t=\\infty) = {\\bf Ww}(t=\\infty). \\]\n\nThis linear set of equations reads\n\\begin{eqnarray}\n W_{11}w_1(t=\\infty) +W_{12}w_2(t=\\infty) +W_{13}w_3(t=\\infty)+ W_{14}w_4(t=\\infty)=&w_1(t=\\infty) \\nonumber \\\\\nW_{21}w_1(t=\\infty) + W_{22}w_2(t=\\infty) + W_{23}w_3(t=\\infty)+ W_{24}w_4(t=\\infty)=&w_2(t=\\infty) \\nonumber \\\\\nW_{31}w_1(t=\\infty) + W_{32}w_2(t=\\infty) + W_{33}w_3(t=\\infty)+ W_{34}w_4(t=\\infty)=&w_3(t=\\infty) \\nonumber \\\\\nW_{41}w_1(t=\\infty) + W_{42}w_2(t=\\infty) + W_{43}w_3(t=\\infty)+ W_{44}w_4(t=\\infty)=&w_4(t=\\infty) \\nonumber \\\\\n\\end{eqnarray}\nwith the constraint that \n\\[\n   \\sum_i w_i(t=\\infty) = 1, \n\\]\nyielding as solution\n\\[\n\\hat{w}(t=\\infty)=  \\left(\\begin{array}{c}0.244318 \\\\                   \n                                 0.319602 \\\\  0.056818 \\\\  0.379261 \\end{array} \\right).\n\\]\nTable \\ref{tab:simplemodelw} demonstrates the convergence as a function of the number of iterations or\ntime steps. After  twelve iterations we have reached the exact value with six leading digits. \n\\begin{table}\n\\caption{Convergence to the steady state as function of number of iterations. \\label{tab:simplemodelw}} \n\\begin{center}\n\\begin{tabular}{rlllll}\\hline\nIteration &$w_1$   &$w_2$  &$w_3$&$w_4$\\\\\\hline\n0  & 1.000000 &0.000000  &0.000000& 0.000000 \\\\\n1  & 0.250000 &0.500000  &0.000000& 0.250000 \\\\\n2  & 0.201389 &  0.319444 &  0.055556 &  0.423611 \\\\\n3  & 0.247878  &  0.312886  &  0.056327  &  0.382909 \\\\\n4   &0.245494  &  0.321106  &  0.055888  &  0.377513\\\\\n5   &0.243847  &  0.319941  &  0.056636  &  0.379575\\\\\n6   & 0.244274  &  0.319547  &  0.056788  &  0.379391\\\\\n7  &0.244333  &  0.319611  &  0.056801  &  0.379255\\\\\n8  &0.244314  &  0.319610  &  0.056813  &  0.379264\\\\\n9  &0.244317  &  0.319603  &  0.056817  &  0.379264\\\\\n10  &0.244318  &  0.319602  &  0.056818  &  0.379262\\\\\n11  &0.244318  &  0.319602  &  0.056818  &  0.379261\\\\\n12  &0.244318  &  0.319602  &  0.056818  &  0.379261\\\\\n$\\hat{w}(t=\\infty)$ & 0.244318  &  0.319602  &  0.056818  &  0.379261\\\\\n\\hline\n\\end{tabular} \n\\end{center}   \n\\end{table}\n\n\nWe have after $t$-steps\n\\[\n   {\\bf \\hat{w}}(t) = {\\bf \\hat{W}^t\\hat{w}}(0),\n\\]\nwith ${\\bf \\hat{w}}(0)$ the distribution at $t=0$ and ${\\bf \\hat{W}}$ representing the \ntransition probability matrix. \nWe can always expand ${\\bf \\hat{w}}(0)$ in terms of the right eigenvectors \n${\\bf \\hat{v}}$ of ${\\bf \\hat{W}}$ as \n\\[\n    {\\bf \\hat{w}}(0)  = \\sum_i\\alpha_i{\\bf \\hat{v}}_i,\n\\]\nresulting in \n\\[\n   {\\bf \\hat{w}}(t) = {\\bf \\hat{W}}^t{\\bf \\hat{w}}(0)={\\bf \\hat{W}}^t\\sum_i\\alpha_i{\\bf \\hat{v}}_i=\n\\sum_i\\lambda_i^t\\alpha_i{\\bf \\hat{v}}_i,\n\\]\nwith $\\lambda_i$ the $i^{\\mathrm{th}}$ eigenvalue corresponding to  \nthe eigenvector ${\\bf \\hat{v}}_i$. \n\nIf we assume that $\\lambda_0$ is the largest eigenvector we see that in the limit $t\\rightarrow \\infty$,\n${\\bf \\hat{w}}(t)$ becomes proportional to the corresponding eigenvector \n${\\bf \\hat{v}}_0$. This is our steady state or final distribution. \n\n \n\\subsection{Continuous Equations}\n\nHitherto we have considered discretized versions of all equations. Our initial probability\ndistribution function was then given by \n\\[\n   w_i(0) = \\delta_{i,0},\n\\]\nand its time-development after a given time step $\\Delta t=\\epsilon$ is\n\\[ \n   w_i(t) = \\sum_{j}W(j\\rightarrow i)w_j(t=0).\n\\]   \nThe continuous analog to $w_i(0)$ is\n\\be\n   w({\\bf x})\\rightarrow \\delta({\\bf x}),\n\\ee\nwhere we now have generalized the one-dimensional position $x$ to a generic-dimensional  \nvector ${\\bf x}$. The Kroenecker $\\delta$ function is replaced by the $\\delta$ distribution\nfunction $\\delta({\\bf x})$ at  $t=0$.  \n\nThe transition from a state $j$ to a state $i$ is now replaced by a transition\nto a state with position ${\\bf y}$ from a state with position ${\\bf x}$. \nThe discrete sum of transition probabilities can then be replaced by an integral\nand we obtain the new distribution at a time $t+\\Delta t$ as \n\\[\n   w({\\bf y},t+\\Delta t)= \\int W({\\bf y}, {\\bf x}, \\Delta t)w({\\bf x},t)d{\\bf x},\n\\]\nand after $m$ time steps we have\n\\[\n   w({\\bf y},t+m\\Delta t)= \\int W({\\bf y}, {\\bf x}, m\\Delta t)w({\\bf x},t)d{\\bf x}.\n\\]\nWhen equilibrium is reached we have\n\\[\n   w({\\bf y})= \\int W({\\bf y}, {\\bf x}, t)w({\\bf x})d{\\bf x}.\n\\]\nWe can solve the equation for $w({\\bf y},t)$ by making a Fourier transform to\nmomentum space. \nThe PDF $w({\\bf x},t)$ is related to its Fourier transform\n$\\tilde{w}({\\bf k},t)$ through\n\\be\\label{eq:fouriertransform}\n   w({\\bf x},t) = \\int_{-\\infty}^{\\infty}d{\\bf k} \\exp{(i{\\bf kx})}\\tilde{w}({\\bf k},t),\n\\ee\nand using the definition of the \n$\\delta$-function \n\\[\n   \\delta({\\bf x}) = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty}d{\\bf k} \\exp{(i{\\bf kx})},\n\\]\n we see that\n\\[\n   \\tilde{w}({\\bf k},0)=1/2\\pi.\n\\]\nWe can then use the Fourier-transformed diffusion equation \n\\begin{equation}\n    \\frac{\\partial \\tilde{w}({\\bf k},t)}{\\partial t} = -D{\\bf k}^2\\tilde{w}({\\bf k},t),\n\\end{equation}\nwith the obvious solution\n\\[\n   \\tilde{w}({\\bf k},t)=\\tilde{w}({\\bf k},0)\\exp{\\left[-(D{\\bf k}^2t)\\right)}=\n    \\frac{1}{2\\pi}\\exp{\\left[-(D{\\bf k}^2t)\\right]}. \n\\]\nUsing Eq.~(\\ref{eq:fouriertransform}) we obtain \n\\begin{equation}\\label{eq:finalw}\n   w({\\bf x},t)=\\int_{-\\infty}^{\\infty}d{\\bf k} \\exp{\\left[i{\\bf kx}\\right]}\\frac{1}{2\\pi}\\exp{\\left[-(D{\\bf k}^2t)\\right]}=\n    \\frac{1}{\\sqrt{4\\pi Dt}}\\exp{\\left[-({\\bf x}^2/4Dt)\\right]}, \n\\end{equation}\nwith the normalization condition\n\\[\n   \\int_{-\\infty}^{\\infty}w({\\bf x},t)d{\\bf x}=1.\n\\]\nIt is rather easy to verify by insertion that Eq.~(\\ref{eq:finalw}) is a solution\nof the diffusion equation. The solution represents the probability of finding\nour random walker at position ${\\bf x}$ at time $t$ if the initial distribution \nwas placed at ${\\bf x}=0$ at $t=0$. \n\nThere is another interesting feature worth observing. The discrete transition probability $W$\nitself is given by a binomial distribution, see Eq.~(\\ref{eq:binomialW}).\nThe results from the central limit theorem, see Sect.~\\ref{subsec:centrallimit}, state that \ntransition probability in the limit $n\\rightarrow \\infty$ converges to the normal \ndistribution. It is then possible to show that\n\\[ \n    W(il-jl,n\\epsilon)\\rightarrow W({\\bf y}, {\\bf x}, \\Delta t)=\n    \\frac{1}{\\sqrt{4\\pi D\\Delta t}}\\exp{\\left[-(({\\bf y}-{\\bf x})^2/4D\\Delta t)\\right]},\n\\]\nand that it satisfies the normalization condition and is itself a solution\nto the diffusion equation.\n\n\n%\\subsection{ESKC equation and the Fokker-Planck equation}\n%In preparation for spring 2010.\n\n\n\\subsection{Numerical Simulation}\nIn the two previous subsections we have given evidence that a Markov process\nactually yields in the limit of infinitely many steps the diffusion equation.\nIt links therefore in a physical intuitive way the fundamental process of diffusion \nwith  random walks. \nIt could therefore be of interest to visualize this connection through a numerical\nexperiment. We saw in the previous subsection that one \npossible solution to the diffusion equation is given by a normal distribution.\nIn addition, the transition rate for a given number of steps develops from a \nbinomial distribution into a normal distribution in the limit of infinitely many\nsteps. \nTo achieve this we construct in addition \na histogram which contains the number of times the walker was in a particular \nposition $x$. This is given by the variable \\lstinline{probability},\nwhich is normalized in the output function. We have omitted the  \ninitialization function, since this identical to program1.cpp or program2.cpp of this\nchapter. The array  \\lstinline{probability} extends from \\lstinline{-number_walks}\nto \\lstinline{+number_walks}\n\\begin{lstlisting}[title={\\url{http://folk.uio.no/mhjensen/compphys/programs/chapter12/cpp/program2.cpp}}]\n/*\n  1-dim random walk program. \n  A walker makes several trials steps with\n  a given number of walks per trial\n*/\n#include <iostream>\n#include <fstream>\n#include <iomanip>\n#include \"lib.h\"\nusing namespace  std;\n\n// Function to read in data from screen, note call by reference\nvoid initialise(int&, int&, double&) ;\n// The Mc sampling for random walks\nvoid  mc_sampling(int, int, double, int *, int *, int *);\n// prints to screen the results of the calculations \nvoid  output(int, int, int *, int *, int *);\n\nint main()\n{\n  int max_trials, number_walks; \n  double move_probability;\n  // Read in data \n  initialise(max_trials, number_walks, move_probability) ;\n  int *walk_cumulative = new int [number_walks+1];\n  int *walk2_cumulative = new int [number_walks+1];\n  int *probability = new int [2*(number_walks+1)];\n  for (int walks = 1; walks <= number_walks; walks++){   \n    walk_cumulative[walks] = walk2_cumulative[walks] = 0;\n  }\n  for (int walks = 0; walks <= 2*number_walks; walks++){   \n    probability[walks] = 0;\n  } // end initialization of vectors\n  // Do the mc sampling  \n  mc_sampling(max_trials, number_walks, move_probability, \n              walk_cumulative, walk2_cumulative, probability);\n  // Print out results \n  output(max_trials, number_walks, walk_cumulative, \n         walk2_cumulative, probability);\n  delete [] walk_cumulative; // free memory\n  delete [] walk2_cumulative; delete [] probability;\n  return 0; \n} // end main function\n\\end{lstlisting}\nThe output function contains now the normalization of the probability as well\nand writes this to its own file.\n\\begin{lstlisting}\nvoid output(int max_trials, int number_walks, \n            int *walk_cumulative, int *walk2_cumulative, int * probability)\n{\n  ofstream ofile(\"testwalkers.dat\");\n  ofstream probfile(\"probability.dat\");\n  for( int  i = 1; i <=  number_walks; i++){\n    double xaverage = walk_cumulative[i]/((double) max_trials);\n    double x2average = walk2_cumulative[i]/((double) max_trials);\n    double variance = x2average - xaverage*xaverage;\n    ofile << setiosflags(ios::showpoint | ios::uppercase);\n    ofile << setw(6) << i;\n    ofile << setw(15) << setprecision(8) << xaverage;\n    ofile << setw(15) << setprecision(8) << variance << endl;\n  }\n  ofile.close();\n  // find norm of probability\n  double norm = 0.;\n  for( int  i = -number_walks; i <=  number_walks; i++){\n    norm += (double) probability[i+number_walks];\n  }\n  // write probability\n  for( int  i = -number_walks; i <=  number_walks; i++){\n    double histogram = probability[i+number_walks]/norm;\n    probfile << setiosflags(ios::showpoint | ios::uppercase);\n    probfile << setw(6) << i;\n    probfile << setw(15) << setprecision(8) << histogram << endl;\n  }\n  probfile.close();\n}  // end of function output \n\\end{lstlisting}\nThe sampling part is still done in the same function, but contains now\nthe setup of a histogram containing the number of times the walker visited \na given position $x$.\n\\begin{lstlisting}\nvoid mc_sampling(int max_trials, int number_walks, \n                 double move_probability, int *walk_cumulative, \n                 int *walk2_cumulative, int *probability)\n{\n  long idum;\n  idum=-1;  // initialise random number generator\n  for (int trial=1; trial <= max_trials; trial++){\n    int position = 0;\n    for (int walks = 1; walks <= number_walks; walks++){   \n      if (ran0(&idum) <= move_probability) {\n\tposition += 1;\n      } \n      else {\n\tposition -= 1;\n      }\n      walk_cumulative[walks] += position;\n      walk2_cumulative[walks] += position*position;\n      probability[position+number_walks] += 1;\n    }  // end of loop over walks\n  } // end of loop over trials\n}   // end mc_sampling function  \n\\end{lstlisting}\nFig.~\\ref{fig:randomprobability} shows the resulting probability distribution after \n$n$ steps\n\\begin{figure} \n\\begin{center}\n\\input{figures/randomprob.tex}\n\\caption{Probability distribution for one walker after 10, 100 and 1000 steps.\\label{fig:randomprobability}}\n\\end{center}\n\\end{figure}\nIn  Fig.~\\ref{fig:randomprobability} we have plotted the probability distribution function after a given number of time steps.\nDo you recognize the shape of the probabiliy distributions?\n\n\n\n\n\\section{Entropy and Equilibrium Features}\nWe use this section to motivate, in a physically intuitive way, the importance of the ergodic hypothesis via \na discussion of how a Markovian process reaches an equilibrium situation after a given number of random walks. \nIt serves then purpose of bridging the gap between a Markovian process and our discussion of the Metropolis \nalgorithm in the next section. \n\nTo achieve this, we will use the program from the previous section, see programs/chapter12/program3.cpp \nand introduce\nthe concept of entropy $S$. We discuss the thermodynamical meaning of the entropy and its \nlink with the second law of thermodynamics in the next chapter. \nHere it will suffice to state that the entropy is a measure of the disorder of the system, thus a system which is fully \nordered and stays in its fundamental state (ground state) has zero entropy, while a disordered system has a large and\nnonzero entropy.\n\nThe definition of the entropy $S$ (as a dimensionless quantity here) is\n\\[\n   S = -\\sum_i w_i ln(w_i),\n\\]\nwhere $w_i$ is the probability of finding our system in a state $i$. For our one-dimensional random walk case discussed\nin the previous sections it represents the probability for being at position $i=i\\Delta x$ after a given number of time steps.\nIn order to test this, we start with the previous program but assume now that we have  $N$ random walkers at\n$i=0$ and $t=0$ and let these random walkers diffuse as function of time. This means simply an additional loop. \nWe compute then, as in the previous program \nexample, the probability distribution for $N$ walkers after a given number of steps $i$ along $x$ and \ntime steps $j$.\nWe can then compute an entropy $S_j$ for a given number of time steps by summing over all probabilities $i$.\nWe show this in Fig.~\\ref{fig:entropyrandom}.\n\\begin{figure} \n\\begin{center}\n\\input{figures/entropy.tex}\n\\caption{Entropy $S_j$ as function of number of time steps $j$ for a random walk in one dimension. Here we have used \n100 walkers on a lattice of length from $L=-50$ to $L=50$ employing periodic boundary conditions meaning\nthat if a walker reaches the point $x=L+1$ it is shifted to $x=-L$ and if $x=-L$ it is shifted to $x=L$. \n\\label{fig:entropyrandom}}\n\\end{center}\n\\end{figure}\nThe code used to compute these results is in programs/chapter12/program4.cpp.\nHere we have used \n100 walkers on a lattice of length from $L=-50$ to $L=50$ employing periodic boundary conditions meaning\nthat if a walker reaches the point $x=L$ it is shifted to $x=-L$ and if $x=-L$ it is shifted to $x=L$.\nWe see from Fig.~\\ref{fig:entropyrandom} that for small time steps, where all particles $N$ \nare in the same position or close to the initial position,\nthe entropy is very small, reflecting the fact that we have an ordered state. As time elapses, the random walkers spread\nout in space (here in one dimension) and the entropy increases as there are more states, that is positions accesible \nto the system. We say that the system shows an increased degree of disorder. \nAfter several time steps, we see that the entropy  reaches a constant value, a situation called a steady state.\nThis signals that the system has reached its equilibrium situation and that the random walkers spread out to\noccupy all possible available states. At equilibrium it means thus that all states\nare equally probable and this is not baked into any dynamical equations such as Newton's law of motion. It occurs\nbecause the system is allowed to explore all possibilities. An important hypothesis, which has never been proven rigorously\nbut for certain systems, is the ergodic hypothesis which states that in equilibrium all available states of a closed\nsystem have equal probability. For a discussion of the ergodicity hypothesis and\nthe Metropoli algorithm, see for example Ref.~\\cite{robertcasella}. \nThis hypothesis states also that if we are able to simulate long enough, then one should be able to trace through all\npossible paths in the space of available states to reach the equilibrium situation. \nOur Markov process should be able to reach any state of the system from any other state if we run for long enough.\nMarkov processes fullfil the requirement of ergodicity since all new steps are independent of the previous ones \nand the random walkers can thus explore with equal probability all possible positions. In general however, we know that\nphysical processes are not independent of each other. The relation between ergodicity and physical systems is an  \nunsettled topic. \n\nThe Metropolis algorithm which we discuss in the next section is based on a Markovian process and fullfils\nthe requirement of ergodicity. In addition, in the next section we impose the criterion of detailed balance.\n\n\n\\section{The Metropolis Algorithm and Detailed Balance}\\label{sec:metropolis}\n\nLet us recapitulate some of our results about Markov chains and random walks.\n\\begin{itemize}\n\\item The time development of our PDF $w(t)$, after one time-step from $t=0$ is given by\n\\[\n   w_i(t=\\epsilon) = W(j\\rightarrow i)w_j(t=0).\n\\]   \nThis equation represents the discretized time-development of an original \nPDF.  We can rewrite this as a \n\\[\n   w_i(t=\\epsilon) = W_{ij}w_j(t=0).\n\\]\nwith the transition matrix $W$ for a random walk given by\n\\[\n   W_{ij}(\\epsilon)=W(il-jl,\\epsilon)=\\left\\{\\begin{array}{cc}\\frac{1}{2} & |i-j| = 1\\\\\n                                             0 & \\mathrm{else} \\end{array} \\right.\n\\]\nWe call $W_{ij}$ for the transition probability and we represent it\nas a matrix. \n\\item Both  $W$ and $w$ represent probabilities and they have to be normalized, meaning that at each time step we have \n\\[\n   \\sum_i w_i(t) = 1, \n\\]\nand \n\\[ \n   \\sum_j W(j\\rightarrow i) = 1.\n\\]\nHere we have written the previous matrix $W_{ij}=W(j\\rightarrow i)$.\nThe further constraints are\n$0 \\le W_{ij} \\le 1$  and  $0 \\le w_{j} \\le 1$.\n\\item We can thus write the action of $W$ as \n\\[\n   w_i(t+1) = \\sum_jW_{ij}w_j(t),\n\\]\nor as vector-matrix relation\n\\[\n   {\\bf \\hat{w}}(t+1) = {\\bf \\hat{W}\\hat{w}}(t),\n\\]\nand if we have that $||{\\bf \\hat{w}}(t+1)-{\\bf \\hat{w}}(t)||\\rightarrow 0$, we say that \nwe have reached the most likely state of the system, the so-called steady state or equilibrium state.\nAnother way of phrasing this is\n       \\be {\\bf w}(t=\\infty) = {\\bf Ww}(t=\\infty). \\ee   \n\\label{eq:finalstage}\n\\end{itemize}\n\nIn most situations, the transition probability $W_{ij}=W(j\\rightarrow i)$ is not known\\footnote{Note that the discrete equations here can easily be replaced by continuous ones.}. It can represent a complicated\nset of chemical reactions which we are not capable of modeling or, we are able to  write down and account for \nall the boundary and the initial conditions\nneeded to describe $W(j\\rightarrow i)$.   A Markov chain is a process where this probability is in general unknown.\nThe question then is how can we model anything under such a severe lack of knowledge? The Metropolis algorithm comes to our rescue here. Since $W(j\\rightarrow i)$ is unknown, we model it as the product of two probabilities, \na probability for accepting the proposed move from the state $j$ to the state $j$, and a probability for making the transition to the state $i$ being in the state $j$. We label these probabilities $A(j\\rightarrow i)$ and $T(j\\rightarrow i)$, respectively.  Our total transition probability is then \n\\[\nW(j\\rightarrow i)=T(j\\rightarrow i)A(j\\rightarrow i).\n\\]\nThe algorithm can then be expressed as\n\\begin{itemize}\n\\item\nWe make a suggested move to the new state $i$ with some transition or moving probability $T_{j\\rightarrow i}$.\n\\item\nWe accept this move to the new state with an acceptance probability $A_{j \\rightarrow i}$. The new state $i$ is in turn\nused as our new starting point for the next move.  We reject this proposed moved with a $1-A_{j\\rightarrow i}$\nand the original state $j$ is used again as a sample.\n\\end{itemize}\nWe wish to derive the required properties of the probabilities $T$ and $A$ such that\n$w_i^{(t\\rightarrow \\infty)} \\rightarrow w_i$, starting\nfrom any distribution, will lead us to the correct distribution.\n\nWe can now derive the dynamical process towards \nequilibrium. To obtain this equation we note that after $t$ time steps the probability for being in a state $i$ is related \nto the probability of being in a state $j$ and performing a transition to the new state together with the probability of actually being in the state $i$ and making a move to any of the possible states $j$ from the previous time step.\nWe can express this as, assuming that $T$ and $A$ are time-independent, \n\\[\nw_i(t+1) = \\sum_j \\left [\nw_j(t)T_{j\\rightarrow i} A_{j\\rightarrow i} \n+w_i(t)T_{i\\rightarrow j}\\left ( 1- A_{i\\rightarrow j} \\right)\n\\right ] \\,.\n\\]\nAll probabilities are normalized, meaning that \n$\\sum_j T_{i\\rightarrow j} = 1$. Using the latter, we can rewrite the previous equation as\n\\[\nw_i(t+1) = w_i(t) +\n \\sum_j \\left [\nw_j(t)T_{j\\rightarrow i} A_{j\\rightarrow i} \n-w_i(t)T_{i\\rightarrow j}A_{i\\rightarrow j}\\right ] \\,,\n\\]\nwhich can be rewritten as \n\\[\nw_i(t+1)-w_i(t) =  \\sum_j \\left [w_j(t)T_{j\\rightarrow i} A_{j\\rightarrow i} \n-w_i(t)T_{i\\rightarrow j}A_{i\\rightarrow j}\\right ] .\n\\]\nThis equation is very similar to the so-called Master equation, which relates the temporal dependence of \na PDF $w_i(t)$ to various transition rates. The equation can be derived from the so-called \nChapman-Einstein-Enskog-Kolmogorov equation, see for example Ref.~\\cite{cd2001}. The equation is given as \n\\be\n\\label{eq:masterequation}\n\\frac{d w_i(t)}{dt} = \\sum_j\\left[ W(j\\rightarrow i)w_j-W(i\\rightarrow j)w_i\\right],\n\\ee \nwhich simply states that the rate at which the systems moves from a state $j$\nto a final state $i$ (the first term on the right-hand side of the last equation) is balanced by the rate at which the system undergoes transitions from the state $i$ to a state $j$ (the second term). If we have reached the so-called steady state, then the temporal development is zero since we are now satisfying\nEq.~(\\ref{eq:finalstage}). This  means that in equilibrium we have\n\\[\n\\frac{d w_i(t)}{dt} = 0.\n\\]\n\n\nIn the limit $t\\rightarrow \\infty$ we require that the  two distributions $w_i(t+1)=w_i$ and $w_i(t)=w_i$\nand we have \n\\[\n \\sum_j w_jT_{j\\rightarrow i} A_{j\\rightarrow i}= \\sum_j w_iT_{i\\rightarrow j}A_{i\\rightarrow j},\n\\]\nwhich is the condition for balance when the most likely state (or steady state) has been reached.\nWe see also that the right-hand side  can be  rewritten as \n\\[ \n\\sum_j w_iT_{i\\rightarrow j}A_{i\\rightarrow j}= \\sum_j w_iW_{i\\rightarrow j},\n\\]\nand using the property that $\\sum_j W_{i\\rightarrow j}=1$, we can rewrite our equation\nas\n\\[\nw_i= \\sum_j w_jT_{j\\rightarrow i} A_{j\\rightarrow i}= \\sum_j w_j W_{j\\rightarrow i},\n\\]\nwhich is nothing but the standard equation for a Markov chain when the steady state has been reached.\n\nHowever, the condition that the rates should equal each other is in general not sufficient\nto guarantee that we, after many simulations, generate the correct distribution.\nWe may risk to end up with so-called cyclic solutions. To avoid this\nwe therefore introduce an additional condition, namely that of detailed balance \n       \\[ W(j\\rightarrow i)w_j= W(i\\rightarrow j)w_i.  \\]\nThese equations were derived by Lars Onsager when studying irreversible processes, see Ref.~\\cite{onsager1931}.\nAt equilibrium detailed balance gives thus\n       \\[ \\frac{W(j\\rightarrow i)}{W(i\\rightarrow j)}=\\frac{w_i}{w_j}.  \\]\nRewriting the last equation in terms of our transition probabilities $T$ and \nacceptance probobalities $A$ we obtain\n\\[ \nw_j(t)T_{j\\rightarrow i}A_{j\\rightarrow i}= w_i(t)T_{i\\rightarrow j}A_{i\\rightarrow j}.\n\\]\nSince we normally have an expression \nfor the probability distribution functions $w_i$,  we can rewrite the last equation as \n\\[ \n\\frac{T_{j\\rightarrow i}A_{j\\rightarrow i}}{T_{i\\rightarrow j}A_{i\\rightarrow j}}= \\frac{w_i}{w_j}.\n\\]\nIn statistical physics this condition ensures that it is e.g., the \nBoltzmann distribution which is generated when equilibrium is reached.\n\nWe introduce  now the Boltzmann distribution \n\\[\n   w_i= \\frac{\\exp{(-\\beta(E_i))}}{Z},\n\\]\nwhich states that the probability of finding the system in a state $i$ with energy $E_i$ \nat an inverse temperature $\\beta = 1/k_BT$ is $w_i\\propto \\exp{(-\\beta(E_i))}$.\nThe denominator $Z$ is a normalization constant which ensures that the sum of all\nprobabilities is normalized to one. It is defined as the sum of probabilities over all microstates\n$j$ of the system\n\\[\n   Z=\\sum_j \\exp{(-\\beta(E_i))}.\n\\]\nFrom the partition function we can in principle generate all interesting quantities\nfor a given system in equilibrium with its surroundings at a temperature $T$. This is\ndemonstrated in the next chapter.\n\nWith the probability distribution given by the Boltzmann distribution we are now in a position\nwhere we can generate expectation values for a given variable $A$ through the\ndefinition\n\\[\n   \\langle A \\rangle = \\sum_jA_jw_j=\n    \\frac{\\sum_jA_j\\exp{(-\\beta(E_j)}}{Z}.\n\\]\nIn general, most systems have an infinity of microstates making thereby the computation\nof $Z$ practically impossible and \na brute force Monte Carlo calculation over a given number of randomly selected microstates\nmay therefore not yield those microstates which are important \nat equilibrium. \nTo select the most important contributions we need to  \nuse the condition for detailed balance. Since this is just given by the ratios of probabilities,\nwe never need to evaluate the partition function $Z$.\nFor the \nBoltzmann distribution, detailed balance results in\n       \\[ \\frac{w_i}{w_j}= \\exp{(-\\beta(E_i-E_j))}. \\]\n\nLet us now specialize to a system whose energy is defined by the orientation of single spins.\nConsider the state $i$, with given energy $E_i$ represented by the following $N$ spins\n\\[\n\\begin{array}{cccccccccc}\n\\uparrow&\\uparrow&\\uparrow&\\dots&\\uparrow&\\downarrow&\\uparrow&\\dots&\\uparrow&\\downarrow\\\\\n1&2&3&\\dots& k-1&k&k+1&\\dots&N-1&N\\end{array}\n\\]\nWe are interested in the transition with one single  spinflip to a new state $j$ with energy $E_j$\n\\[\n\\begin{array}{cccccccccc}\n\\uparrow&\\uparrow&\\uparrow&\\dots&\\uparrow&\\uparrow&\\uparrow&\\dots&\\uparrow&\\downarrow\\\\\n1&2&3&\\dots& k-1&k&k+1&\\dots&N-1&N\\end{array}\n\\]\nThis change from one microstate $i$ (or spin configuration)  to another microstate $j$ is the\nconfiguration space analogue to a random walk on a lattice. Instead of jumping from \none place to another in space, we 'jump' from one microstate to another.\n\nHowever, the selection of states has to generate a final distribution which is the\nBoltzmann distribution. This is again the same we saw for a random walker, for the discrete case we had \nalways a binomial distribution, whereas for the continuous case we had a normal distribution.\nThe way we sample configurations should result, when equilibrium is established, in the \nBoltzmann distribution. Else, our algorithm for selecting microstates is wrong.\n \n\nAs stated above, we do in general not know the closed-form expression of the transition rate and we are free to model it as\n     $W(i\\rightarrow j)=T(i\\rightarrow j)A(i\\rightarrow j)$.\nOur ratio between probabilities gives us\n\\[ \n\\frac{A_{j\\rightarrow i}}{A_{i\\rightarrow j}}= \\frac{w_iT_{i\\rightarrow j}}{w_jT_{j\\rightarrow i}}.\n\\]\nThe simplest form of the Metropolis algorithm (sometimes called for brute force Metropolis) assumes that \nthe transition probability $T(i\\rightarrow j)$ is symmetric, implying that $T(i\\rightarrow j)=T(j\\rightarrow i)$.\nWe obtain then (using the Boltzmann distribution)\n\\[\n\\frac{A(j\\rightarrow i)}{A(i\\rightarrow j)}= \\exp{(-\\beta(E_i-E_j))} .\n\\]\nWe are in this case interested in a new state $E_j$ whose energy is lower than \n$E_i$, viz., $\\Delta E = E_j-E_i \\le 0$. A simple test would then be to accept only those\nmicrostates which lower the energy.  \nSuppose we have ten microstates with energy $E_0 \\le E_1 \\le E_2 \\le E_3 \\le \\dots \\le E_9$.\nOur desired energy is $E_0$.\nAt a given temperature $T$ we start our simulation by randomly choosing state\n$E_9$. Flipping spins we may then find a path from $E_9\\rightarrow E_8 \\rightarrow E_7 \\dots \\rightarrow E_1 \\rightarrow E_0$. \nThis would however lead to biased statistical averages since it would violate the ergodic hypothesis discussed\nin the previous section. This principle states  that \nit should be possible for any Markov process to reach every possible state of the system\nfrom any starting point if the simulations is carried out for a long enough time.\n\nAny state in a Boltzmann distribution has a probability different from zero and if such \na state cannot be reached from a given starting point, then the system is not ergodic.\nThis means that another possible path to $E_0$ could be \n$E_9\\rightarrow E_7 \\rightarrow E_8 \\dots \\rightarrow E_9 \\rightarrow E_5 \\rightarrow E_0$ and so forth.\nEven though such a path could have a negligible probability it is still a possibility, and if\nwe simulate long enough it should be included in our computation of an expectation value.\n\nThus, we require that our algorithm should satisfy the principle of detailed balance and be ergodic. \nThe problem with our ratio\n\\[\n\\frac{A(j\\rightarrow i)}{A(i\\rightarrow j)}= \\exp{(-\\beta(E_i-E_j))}, \n\\]\nis that we do not know the acceptance probability. This equation only specifies the ratio of pairs of probabilities. Normally we want an algorithm which is as efficient as possible and maximizes the number of accepted moves. \nMoreover, we know that the acceptance probability has $0$ as its smallest value and $1$ as its largest. \nIf we assume that the largest possible acceptance probability is $1$,  we adjust thereafter the other acceptance probability\nto this constraint. \n\nTo understand this better, assume that we have two energies, $E_i$ and $E_j$, with $E_i < E_j$. This means that the largest acceptance value must be \n$A(j\\rightarrow i)$ since we move to a state with lower energy.  It follows from also from the fact that the probability $w_i$ is larger than $w_j$. \nThe trick then is to fix this value to $A(j\\rightarrow i)=1$. It means that \nthe other acceptance probability has to be \n\\[\nA(i\\rightarrow j)= \\exp{(-\\beta(E_j-E_i))}.\n\\]\nOne possible way to encode this equation reads\n\\[       \nA(j\\rightarrow i)=\\left\\{\\begin{array}{cc}\n\\exp{(-\\beta(E_i-E_j))} & E_i-E_j > 0 \\\\ 1 & else \\end{array} \\right.,  \n\\]\nimplying that if we move to a state with a lower energy, we always accept\nthis move with acceptance probability $A(j\\rightarrow i)=1$. If the energy is higher, we need to check\nthis acceptance probability with the ratio between the probabilities  from our PDF.  From a practical point of view, \nthe above ratio is compared with a random number.\nIf the ratio is smaller than a given random number we accept the move to a higher energy, else we stay in the same state. \n\nNothing hinders us obviously in choosing another acceptance ratio, like a weighting  of the two energies via\n\\[\nA(j\\rightarrow i)=\\exp{(-\\frac{1}{2}\\beta(E_i-E_j))}.\n\\]\nHowever, it is easy to see that such an acceptance ratio woud result in \nfewer accepted moves.\n\n\n\\subsection{Brief Summary}\nThe Monte Carlo approach, combined with the theory for Markov chains can be summarized as follows:\nA Markov chain Monte Carlo method for the simulation of a distribution $w$ is any method producing an \nergodic Markov chain of events $x$ whose stationary distribution is $w$. The Metropolis algorithm can be phrased as\n\\begin{svgraybox}\n\\begin{itemize}\n\\item Generate an initial value $x^{(i)}$.\n\\item Generate a trial value $y_t$ with probability $T(y_t|x^{(i)})$. The latter quantity represents the probability of generating $y_t$ given $x^{(i)}$.\n\\item Take a new value \n\\[ \nx^{(i+1)}= \\left\\{\\begin{array}{cc} y_t & \\mathrm{with\\hspace{0.1cm}probability} = A(x^{(i)}\\rightarrow y_t) \\\\\n                                          x^{(i)}    & \\mathrm{with \\hspace{0.1cm}probability} = 1-A(x^{(i)}\\rightarrow y_t)\\end{array}\\right .\n\\] \n\\item We have defined the transition (acceptance) probability as \n\\[\n   A(x\\rightarrow y)= \\mathrm{min}\\left\\{\\frac{w(y)T(x|y)}{w(x)T(y|x)},1\\right\\}.\n\\]\nThe distribution $f$ is often called the instrumental (we will relate it to the \njumping of a walker) or proposal distribution while $A$ is the Metropolis-Hastings\nacceptance probability.  When $T(y|x)$ is symmetric it is just called the Metropolis algorithm.\n\\end{itemize}\n\\end{svgraybox}\nUsing the Metropolis algorithm we can in turn set up the general calculational scheme as \nshown in Fig.~\\ref{fig:chartFlowMetro}.\n\\begin{figure}\n\\begin{centering}\n\\begin{tikzpicture}[scale=1., node distance = 2cm, auto]\n  \\footnotesize\n    % Place nodes\n    \\node [block] (init) {Initialize:\\\\\n    Establish an initial state, for example a position $x^{(i)}$};\n    \\node [block, below of=init, node distance=2.0cm] (suggestMove) {Suggest a move $y_t$};\n    \\node [block, below of=suggestMove] (evaluateAcceptance) {Compute acceptance ratio $A(x^{(i)}\\rightarrow y_t)$};\n    \\node [block, left of=evaluateAcceptance, node distance=4.5cm] (randomGenerator) {Generate a uniformly distributed variable $r$};\n    \\node [decision, below of=evaluateAcceptance] (decide) {Is\\\\ $A(x^{(i)}\\rightarrow y_t) \\geq r$?};\n    \\node [block, right of=decide, node distance=3.5 cm] (rejectMove) {Reject move: \\\\ $x^{(i+1)} = x^{(i)}$};\n    \\node [block, below of=decide, node distance=2.2cm] (acceptMove) {Accept move:\\\\$x^{(i)} = y_t=x^{(i+1)}$};\n    \\node [decision, below of=acceptMove, node distance=2.2cm] (lastMove) {Last move?};\n    \\node [block, below of=lastMove, node distance=2.2cm] (getLocalEnergy) {Get local expectation values};\n    \\node [decision, below of=getLocalEnergy] (decideMC) {Last MC step?};\n    \\node [block, below of=decideMC, node distance=2.2cm] (collectSamples) {Collect samples};\n    \\node [block, below of=collectSamples, node distance=2.2cm] (end) {End};\n    \n%     % Draw edges\n    \\path [line] (init) -- (suggestMove);\n    \\path [line] (suggestMove) -- (evaluateAcceptance);\n    \\path [line] (evaluateAcceptance) -- (decide);\n    \\path [line] (randomGenerator) |- (decide);\n    \\path [line] (decide) -- node [, color=black] {yes}(acceptMove);\n    \\path [line] (decide) -- node [, color=black] {no}(rejectMove);\n    \\path [line] (acceptMove) -- (lastMove); \n    \\path [line] (lastMove) -- node [, color=black] {yes}(getLocalEnergy);\n    \\path [line] (rejectMove) |- (lastMove);\n    \\path [line] (getLocalEnergy) -- (decideMC);\n    \\path [line] (decideMC) -- node [, color=black] {yes}(collectSamples);\n\n    % Define a style for shifting a coordinate upwards\n    % Note the curly brackets around the coordinate.\n    \\tikzstyle{s}=[shift={(0mm,\\radius)}]\n    \\path[line] (lastMove.west) -- +(-1.0,0)  -- +(-1.0, 4.34) \n% % % %     % Draw semicircle junction to indicate that the lines are\n% % % %     % not connected. Since we want the semicircle to have its center \n% % % %     % where the lines intersect, we have to shift the intersection \n% % % %     % coordinate using the 's' style to account for this.\n    arc(-90:90:\\radius) -- +(0.0, 4.42) -- (suggestMove.west);\n    \n    \\path [line] (decideMC.west) -- node [, color=black]{no} +(-1.7,0) --+(-1.7,9.05) arc(-90:90:\\radius) --+(0.0,5.4) -- +(2.8,5.4);\n       \n    \\path [line] (collectSamples) -- (end);\n\n\\end{tikzpicture}\\caption{Chart flow for the Metropolis algorithm.}\\label{fig:chartFlowMetro}\n\\end{centering}\n\\end{figure}\n\n\nThe dynamical equation can be written as\n\\begin{equation}\nw_i(t+1) = \\sum_j M_{ij}w_j(t)\n\\end{equation}\nwith the matrix $M$ given by\n\\begin{equation}\nM_{ij} = \\delta_{ij}\\left [ 1 -\\sum_k T_{i\\rightarrow k} A_{i \\rightarrow k}\n\\right ] + T_{j\\rightarrow i} A_{j\\rightarrow i} \\,.\n\\end{equation}\nSumming over $i$ shows that $\\sum_i M_{ij} = 1$, and since\n$\\sum_k T_{i\\rightarrow k} = 1$, and $A_{i \\rightarrow k} \\leq 1$, the\nelements of the matrix satisfy $M_{ij} \\geq 0$. The matrix $M$ is therefore\na stochastic matrix.\n\nThe Metropolis method is simply the power method for computing the\nright eigenvector of $M$ with the largest magnitude eigenvalue.\nBy construction, the correct probability distribution is a right eigenvector\nwith eigenvalue $1$. Therefore, for the Metropolis method to converge\nto this result, one has to  show that $M$ has only one eigenvalue with this\nmagnitude, and all other eigenvalues are smaller. \n%develop examples here or in chapter 7 in connection with power method\n\n\n\\section{Langevin and Fokker-Planck Equations}\nWe end this chapter with a discussion and derivation of the Fokker-Planck and Langevin equations.\nThese equations will in turn be used in our discussion on advanced Monte Carlo methods\nfor quantum mechanical systems, see chapter for example chapter \\ref{chap:improvedvmc}.\n\n\\subsection{Fokker-Planck Equation}\n     For many physical systems initial distributions of a stochastic \nvariable $y$ tend to an equilibrium distribution $w_{\\mathrm{equilibrium}}(y)$, \nthat is $w(y, t)\\rightarrow w_{\\mathrm{equilibrium}}(y)$ \nas $t\\rightarrow\\infty$. In\nequilibrium, detailed balance constrains the transition rates\n\\[\n     W(y\\rightarrow y')w(y ) = W(y'\\rightarrow y)w_{\\mathrm{equilibrium}}(y),\n\\]\nwhere $W(y'\\rightarrow y)$ \nis the probability per unit time that the system changes\nfrom a state $|y\\rangle$ , characterized by the value $y$ \nfor the stochastic variable $Y$ , to a state $|y'\\rangle$.\n\nNote that for a system in equilibrium the transition rate \n$W(y'\\rightarrow y)$ and\nthe reverse $W(y\\rightarrow y')$ may be very different. \n\n\nLet us now assume that we have three probability distribution functions for times $t_0 < t' < t$, that is\n$w({\\bf x}_0,t_0)$, $w({\\bf x}',t')$ and $w({\\bf x},t)$.\nWe have then  \n\\[\n   w({\\bf x},t)= \\int_{-\\infty}^{\\infty} W({\\bf x}.t|{\\bf x}'.t')w({\\bf x}',t')d{\\bf x}',\n\\]\nand\n\\[\n   w({\\bf x},t)= \\int_{-\\infty}^{\\infty} W({\\bf x}.t|{\\bf x}_0.t_0)w({\\bf x}_0,t_0)d{\\bf x}_0,\n\\]\nand\n\\[\n   w({\\bf x}',t')= \\int_{-\\infty}^{\\infty} W({\\bf x}'.t'|{\\bf x}_0,t_0)w({\\bf x}_0,t_0)d{\\bf x}_0.\n\\]\n\nWe can combine these equations and arrive at the \nfamous Einstein-Smoluchenski-Kolmogorov-Chapman (ESKC) relation\n\\[\n W({\\bf x}t|{\\bf x}_0t_0)  = \\int_{-\\infty}^{\\infty} W({\\bf x},t|{\\bf x}',t')W({\\bf x}',t'|{\\bf x}_0,t_0)d{\\bf x}'.\n\\]\nWe can replace the spatial dependence with a dependence upon say the velocity\n(or momentum), that is we have\n\\[\n W({\\bf v},t|{\\bf v}_0,t_0)  = \\int_{-\\infty}^{\\infty} W({\\bf v},t|{\\bf v}',t')W({\\bf v}',t'|{\\bf v}_0,t_0)d{\\bf x}'.\n\\]\n\nWe will now derive the Fokker-Planck equation. \nWe start from the ESKC equation\n\\[\n W({\\bf x},t|{\\bf x}_0,t_0)  = \\int_{-\\infty}^{\\infty} W({\\bf x},t|{\\bf x}',t')W({\\bf x}',t'|{\\bf x}_0,t_0)d{\\bf x}'.\n\\]\nWe define $s=t'-t_0$, $\\tau=t-t'$ and $t-t_0=s+\\tau$. We have then\n\\[\n W({\\bf x},s+\\tau|{\\bf x}_0)  = \\int_{-\\infty}^{\\infty} W({\\bf x},\\tau|{\\bf x}')W({\\bf x}',s|{\\bf x}_0)d{\\bf x}'.\n\\]\n\nAssume now that $\\tau$ is very small so that we can make an expansion \nin terms of a small step $xi$, with ${\\bf x}'={\\bf x}-\\xi$, that is\n\\[\n W({\\bf x},s|{\\bf x}_0)+\\frac{\\partial W}{\\partial s}\\tau +O(\\tau^2) = \\int_{-\\infty}^{\\infty} W({\\bf x},\\tau|{\\bf x}-\\xi)W({\\bf x}-\\xi,s|{\\bf x}_0)d{\\bf x}'.\n\\]\nWe assume that $W({\\bf x},\\tau|{\\bf x}-\\xi)$ takes non-negligible values only when $\\xi$ is small. This is just another way of stating the Master equation!\n\nWe say thus that ${\\bf x}$ changes only by a small amount in the time interval $\\tau$. \nThis means that we can make a Taylor expansion in terms of $\\xi$, that is we\nexpand\n\\[\nW({\\bf x},\\tau|{\\bf x}-\\xi)W({\\bf x}-\\xi,s|{\\bf x}_0) =\n\\sum_{n=0}^{\\infty}\\frac{(-\\xi)^n}{n!}\\frac{\\partial^n}{\\partial x^n}\\left[W({\\bf x}+\\xi,\\tau|{\\bf x})W({\\bf x},s|{\\bf x}_0)\n\\right].\n\\]\nWe can then rewrite the ESKC equation as \n\\[\n\\frac{\\partial W}{\\partial s}\\tau=-W({\\bf x},s|{\\bf x}_0)+\n\\sum_{n=0}^{\\infty}\\frac{(-\\xi)^n}{n!}\\frac{\\partial^n}{\\partial x^n}\n\\left[W({\\bf x},s|{\\bf x}_0)\\int_{-\\infty}^{\\infty} \\xi^nW({\\bf x}+\\xi,\\tau|{\\bf x})d\\xi\\right].\n\\]\nWe have neglected higher powers of $\\tau$ and have used that for $n=0$ \nwe get simply $W({\\bf x},s|{\\bf x}_0)$ due to normalization.\n\nWe say thus that ${\\bf x}$ changes only by a small amount in the time interval $\\tau$. \nThis means that we can make a Taylor expansion in terms of $\\xi$, that is we\nexpand\n\\[\nW({\\bf x},\\tau|{\\bf x}-\\xi)W({\\bf x}-\\xi,s|{\\bf x}_0) =\n\\sum_{n=0}^{\\infty}\\frac{(-\\xi)^n}{n!}\\frac{\\partial^n}{\\partial x^n}\\left[W({\\bf x}+\\xi,\\tau|{\\bf x})W({\\bf x},s|{\\bf x}_0)\n\\right].\n\\]\nWe simplify the above by introducing the moments \n\\[\nM_n=\\frac{1}{\\tau}\\int_{-\\infty}^{\\infty} \\xi^nW({\\bf x}+\\xi,\\tau|{\\bf x})d\\xi=\n\\frac{\\langle [\\Delta x(\\tau)]^n\\rangle}{\\tau},\n\\]\nresulting in\n\\[\n\\frac{\\partial W({\\bf x},s|{\\bf x}_0)}{\\partial s}=\n\\sum_{n=1}^{\\infty}\\frac{(-\\xi)^n}{n!}\\frac{\\partial^n}{\\partial x^n}\n\\left[W({\\bf x},s|{\\bf x}_0)M_n\\right].\n\\]\n\nWhen $\\tau \\rightarrow 0$ we assume that $\\langle [\\Delta x(\\tau)]^n\\rangle \\rightarrow 0$ more rapidly than $\\tau$ itself if $n > 2$. \nWhen $\\tau$ is much larger than the standard correlation time of \nsystem then $M_n$ for $n > 2$ can normally be neglected.\nThis means that fluctuations become negligible at large time scales.\n\nIf we neglect such terms we can rewrite the ESKC equation as \n\\[\n\\frac{\\partial W({\\bf x},s|{\\bf x}_0)}{\\partial s}=\n-\\frac{\\partial M_1W({\\bf x},s|{\\bf x}_0)}{\\partial x}+\n\\frac{1}{2}\\frac{\\partial^2 M_2W({\\bf x},s|{\\bf x}_0)}{\\partial x^2}.\n\\]\n\nIn a more compact form we have\n\\[\n\\frac{\\partial W}{\\partial s}=\n-\\frac{\\partial M_1W}{\\partial x}+\n\\frac{1}{2}\\frac{\\partial^2 M_2W}{\\partial x^2},\n\\]\nwhich is the Fokker-Planck equation.  It is trivial to replace \nposition with velocity (momentum).\n\nThe solution to this equation is a Gaussian distribution and can be used to constrain proposed transitions moves, that one can model the transition probabilities $T$ from our discussion of the Metropolis algorithm.\n\\subsection{Langevin Equation}\nConsider a particle suspended in a liquid. \nOn its path through the liquid it will continuously collide with the liquid molecules. \nBecause on average the particle will collide more often on the front side than on the back side, it will experience a systematic force proportional with its velocity, \nand directed opposite to its velocity. Besides this \nsystematic force the particle will experience a stochastic force  $ \\vec{F}(t)$. \nThe equations of motion then read \n\\[ \n \\frac{d\\vec{r}}{dt} \t=  \\vec{v},\n\\] \t\n\\[\n\\frac{d\\vec{v}}{dt} \t=  -\\xi \\vec{v}+\\vec{F},\n\\]\nThe last equation is the Langevin equation. The original Langevin equation was meant to  describe \nBrownian motion. It is a \nstochastic differential equation used to describe the time evolution of \ncollective (normally macroscopic) variables that change only slowly with respect\nto the microscopic ones. The latter are responsible for the stochastic nature of the Langevin equation.\nWe can say that we model our ignorance about the microscopic physics in a stochastic term.\nFrom the Langevin equation we can in turn derive for example the fluctuation dissipation theorem\ndiscussed below. To see, we need some information about the friction constant from hydrodynamics.\nFrom hydrodynamics  we know that the friction constant  $\\xi$ is given by\n\\[\n\\xi =6\\pi \\eta a/m \n\\]\nwhere $\\eta$ is the viscosity  of the solvent and $a$ is the radius of the particle.\n\nSolving the Langevin equation we get \n\\[\n\\vec{v}(t)=\\vec{v}_{0}e^{-\\xi t}+\\int_{0}^{t}d\\tau e^{-\\xi (t-\\tau )}\\vec{F }(\\tau ). \n\\]\n\nIf we want to get some useful information out of this, we have to average \nover all possible realizations of \n$ \\vec{F}(t)$, with the initial velocity as a condition. A useful quantity is then\n \\[ \n\\langle \\vec{v}(t)\\cdot \\vec{v}(t)\\rangle_{\\vec{v}_{0}}=v_{0}^{-\\xi 2t}\n+2\\int_{0}^{t}d\\tau e^{-\\xi (2t-\\tau)}\\vec{v}_{0}\\cdot \\langle \\vec{F}(\\tau )\\rangle_{\\vec{v}_{0}}\n\\]\n\\[  \t  \t\n +\\int_{0}^{t}d\\tau ^{\\prime }\\int_{0}^{t}d\\tau e^{-\\xi (2t-\\tau -\\tau ^{\\prime })}\n\\langle \\vec{F}(\\tau )\\cdot \\vec{F}(\\tau ^{\\prime })\\rangle_{ \\vec{v}_{0}}.\n\\]\n\nIn order to continue we have to make some assumptions \nabout the conditional averages of the stochastic forces. \nIn view of the chaotic character of the stochastic forces the following \nassumptions seem to be appropriate.\nWe assume that   \n\\[ \\langle \\vec{F}(t)\\rangle \t= \t0, \\]\nand\n\\[\\langle \\vec{F}(t)\\cdot \\vec{F}(t^{\\prime })\\rangle_{\\vec{v}_{0}}=  C_{\\vec{v}_{0}}\\delta (t-t^{\\prime }).\n\\] \t\nWe omit the subscript $\\vec{v}_{0}$ when the quantity of interest \nturns out to be independent of $\\vec{v}_{0}$. Using the last three equations we get\n \\[\n\\langle \\vec{v}(t)\\cdot \\vec{v}(t)\\rangle_{\\vec{v}_{0}}=v_{0}^{2}e^{-2\\xi t}+\\frac{C_{\\vec{v}_{0}}}{2\\xi }(1-e^{-2\\xi t}).\\]\n\nFor large $t$ this should be equal to the well-known result $3kT/m$, from which it follows that\n\\[\n\\langle \\vec{F}(t)\\cdot \\vec{F}(t^{\\prime })\\rangle =6\\frac{kT}{m}\\xi \\delta (t-t^{\\prime }). \\]\nThis result is called the fluctuation-dissipation theorem.\n\nIntegrating \n \\[ \n\\vec{v}(t)=\\vec{v}_{0}e^{-\\xi t}+\\int_{0}^{t}d\\tau e^{-\\xi (t-\\tau )}\\vec{F }(\\tau ), \\] \nwe get\n\\[\n\\vec{r}(t)=\\vec{r}_{0}+\\vec{v}_{0}\\frac{1}{\\xi }(1-e^{-\\xi t})+\n\\int_0^td\\tau \\int_0^{\\tau}\\tau ^{\\prime } e^{-\\xi (\\tau -\\tau ^{\\prime })}\\vec{F}(\\tau ^{\\prime }), \\]\nfrom which we calculate the mean square displacement \n\\[\n\\langle ( \\vec{r}(t)-\\vec{r}_{0})^{2}\\rangle _{\\vec{v}_{0}}=\\frac{v_0^2}{\\xi}(1-e^{-\\xi t})^{2}+\\frac{3kT}{m\\xi ^{2}}(2\\xi t-3+4e^{-\\xi t}-e^{-2\\xi t}). \\]\nFor very large $t$ this becomes\n\\[\n\\langle (\\vec{r}(t)-\\vec{r}_{0})^{2}\\rangle =\\frac{6kT}{m\\xi }t \\] \nfrom which we get the Einstein relation  \n \\[ D= \\frac{kT}{m\\xi } \\] \t\nwhere we have used $\\langle (\\vec{r}(t)-\\vec{r}_{0})^{2}\\rangle =6Dt$.\n\nThe standard approach in for example quantum mechanical diffusion Monte Carlo calculations, is to use the Langevin equation\nto propose new moves (for examples new velocities or positions) since they will depend on the given probability distributions.\nThese new proposed states or values are then used to compute the transition probability $T$, where the latter is the solution\nof for example the Fokker-Planck equation.\n \n\\section{Exercises}\n%\\subsection*{Exercise 9.1: Two dimensional randow walk}\n\\begin{prob}\nExtend the first program discussed in this chapter  \nto a two-dimensional random walk with probability\n$1/4$ for a move to the right, left, up or down. Compute the variance for both the $x$ and $y$\ndirections and the total variance.\n\\end{prob}\n%\\subsection*{Exercise 12.1: Two dimensional randow walk}\n\\begin{prob}\nUse the second program \nto fit the computed probability distribution with a normal distribution\nusing your calculated values of $\\sigma^2$ and $\\langle x\\rangle$.\n\\end{prob}\n%\\subsection*{Project 12.1: simulation of the Boltzmann distribution}\n\\begin{prob}\nIn this exercise the aim is to show that the Metropolis algorithm\ngenerates the Boltzmann distribution\n\\[\n   P(\\beta)=\\frac{e^{-\\beta E}}{Z},\n\\]\nwith $\\beta=1/kT$ being the inverse temperature, $E$ is the energy of\nthe system and\n$Z$ is the partition function. The only functions you will need are those\nto generate random numbers.\n\nWe are going to study one single particle in equilibrium with \nits surroundings, the latter modelled via a large heat bath\nwith temperature $T$.\n\nThe model used to describe this particle is that of an ideal gas\nin {\\bf one} dimension and with velocity $-v$ or $v$. \nWe are interested in finding  $P(v)dv$, which expresses the probability\nfor finding the system with a given velocity $v\\in [v,v+dv]$.\nThe energy for this one-dimensional system is\n\\[\n  E=\\frac{1}{2}kT=\\frac{1}{2}v^2,\n\\]\nwith mass $m=1$.\nIn order to simulate the Boltzmann distribution, your program\nshould contain the following ingredients:  \n\\begin{itemize}\n\\item Reads in the temperature $T$, the number of Monte Carlo cycles, \nand the initial velocity. You should also read in \nthe change in velocity $\\delta v$ used in every Monte Carlo step. \nLet the temperature have dimension energy.\n\\item Thereafter you choose a maximum velocity given by for example  \n$v_{max}\\sim 10\\sqrt{T}$. This should include all relevant velocities which give a non-zero probability. But you need to check whether this is true or not. \n\nThen you construct a velocity interval \ndefined by  $v_{max}$ and divide it in small intervals through \n$v_{max}/N$,\nwith $N\\sim 100-1000$. \nFor each of these intervals your task is to find out how many times\na given velocity during the Monte Carlo sampling appears \nin each specific interval.\n\\item The number of times a given velocity appears in a specific\ninterval is used to construct a histogram representing \n$P(v)dv$. To achieve this you should construct a vector \n$P[N]$ which contains the number of times a given velocity \nappears in the subinterval \n$v,v+dv$. \n\\end{itemize}\n\nIn order to find the number of velocities appearing in each interval\nwe will employ the Metropolis algorithm. A pseudocode for this is\n\\begin{lstlisting}\n   for( montecarlo_cycles=1; Max_cycles; montecarlo_cycles++) {\n      ...\n      // change speed as function of delta v\n      v_change = (2*ran1(&idum) -1 )* delta_v;\n      v_new = v_old+v_change;\n      // energy change\n      delta_E = 0.5*(v_new*v_new - v_old*v_old) ;\n      ......\n      // Metropolis algorithm begins here\n        if ( ran1(&idum) <= exp(-beta*delta_E)  ) {\n            accept_step = accept_step + 1 ;      \n            v_old = v_new ;\n            .....\n        }\n      // thereafter we must fill in  P[N] as a function of\n      // the new speed\n        P[?] = ...\n\n      // upgrade mean velocity, energy and variance\n         ...\n      }\n\\end{lstlisting}\n\n\n\\begin{enumerate}\n\\item  Make your own algorithm which sets up the histogram\n$P(v)dv$, find mean velocity, energy $\\langle E\\rangle$, energy variance $\\mathrm{Var}(E)$ \nand the number of\naccepted steps for a given temperature. Study the change of the number of\naccepted moves as a function of $\\delta v$.\nCompare the final energy with the closed form result\n$\\langle E\\rangle=kT/2$ for one dimension. Find also the closed-form expressions for the energy variance  and the mean velocity and compare your calculations with these results. \nUse $T=4$ and set the intial velocity to zero, i.e., $v_0=0$. \nTry different values of $\\delta v$.\nCheck the final result for the energy as a function \nof the number of Monte Carlo cycles.\n\n\\item   Repeat the calculation in the previous exercise but using now a normal distribution. Does that improve your results compared with the exact expressions?\n\n\\item  Make thereafter a plot of  $\\log{(P(v))}$ as function of $E$\nand see if you get a straight line. Comment the result.\n\n\\item  In our analysis under [1) we have not discussed how the system reaches the most likely state, that is whether equilibrium has been reached or not.\nMake a plot of the mean velocity, energy, energy variance and the number of\naccepted steps for a given temperature as function of the number of\nMonte Carlo samples. Perform these calculations for several temperatures, namely $T=0.5$, $T=1$, $T=2$ and $T=10$ and comment your results. Can you find\na rough measure for when the most likely state has been reached?\n\n\\item \nThe analysis in point [4) \nis rather rough and obviously user dependent, in the sense that it is\nvery much up to the user to define when an equilibrium situation has been reached or not.\nTo improve upon this, compute the so-called time autocorrelation function defined here as\n\\[\n\\phi(t)  = \\frac{1}{t_{\\mathrm{max}}-t}\\sum_{t'=0}^{t_{\\mathrm{max}}-t}\\bar E(t')\\bar E(t'+t)\n-\\frac{1}{t_{\\mathrm{max}}-t}\\sum_{t'=0}^{t_{\\mathrm{max}}-t}\\bar E(t')\\times\n\\frac{1}{t_{\\mathrm{max}}-t}\\sum_{t'=0}^{t_{\\mathrm{max}}-t}\\bar E(t'+t)\n\\]\nfor the mean energy $E\\bar (t)$ and plot it \nas function of the number of Monte Carlo steps for the temperatures in [c).\nThe time $t$ corresponds to a given number of Monte Carlo cycles.\nCan you extract an equilibration measure?  How does the correlation time behave\nas function of temperature?  Comment your results.  \nBe careful in choosing values of $t$, they should not be  too close to $t_{\\mathrm{max}}$.\nCompute the autocorrelation function for all temperatures listed in [d) and compare your results with those in [d). Comment your results. \n\\item  In the previous analysis we computed the time autocorrelation  function. This quantity can be related to the covariance of our measurements. \nTo achieve this you need to store the results of all contributions to the measurements of the mean energy and its variance $\\sigma_E^2$ given by     \n\\[\n\\sigma_E^2 =\\frac{1}{n^2}\\sum_{k=1}^n (E_k - \\bar E)^2 +\n\\frac{2}{n^2}\\sum_{k<l} (E_k - \\bar E)(E_l - \\bar E)\n\\]\nHere we assume that $n$ corresponds to the number of Monte Carlo samples in one\nexperiment and that we repeat these experiments a given time.  We can assume here that we repeat these experiments $m=n$ times.  \nThe value $\\bar E$ is the mean energy while $E_{k,l}$ represent individual measurements. \nThe first term is the same as the error in the uncorrelated case.\nThis means that the second\nterm accounts for the error correction due to correlation between the\nmeasurements. For uncorrelated measurements this second term is zero.\n\nComputationally the uncorrelated first term is much easier to treat\nefficiently than the second.\n\\[\n\\mathrm{Var}(E) = \\frac{1}{n}\\sum_{k=1}^n (E_k - \\langle E\\rangle)^2 =\n\\left(\\frac{1}{n}\\sum_{k=1}^n E_k^2\\right) - \\langle E\\rangle^2\n\\]\nWe just accumulate separately the values $E_k^2$ and $E_k$ for every\nmeasurement $E_k$ we receive. The correlation term, though, has to be\ncalculated at the end of the experiment since we need all the\nmeasurements to calculate the cross terms. Therefore, all measurements\nhave to be stored throughout the experiment.\n\nLet us analyze the problem by splitting up the correlation term into\npartial sums of the form:\n\\[\nf_d = \\frac{1}{n}\\sum_{k=1}^{n-d}(E_k - \\langle E\\rangle)(E_{k+d} - \\langle E\\rangle)\n\\]\nThe correlation term of the error can now be rewritten in terms of\n$f_d$:\n\\[\n\\frac{2}{n}\\sum_{k<l} (E_k - \\langle E\\rangle)(E_l - \\langle E\\rangle) =\n2\\sum_{d=1}^{n-1} f_d\n\\]\nThe value of $f_d$ reflects the correlation between measurements\nseparated by the distance $d$ in the samples.  Notice that for\n$d=0$, $f$ is just the sample variance, $\\mathrm{Var}(E)$. If we divide $f_d$\nby $\\mathrm{Var}(E)$, we arrive at the so called \\emph{autocorrelation\n  function}:\n\\[\n\\kappa_d = \\frac{f_d}{\\mathrm{Var}(E)}\n\\]\nwhich gives us a useful measure of the correlation pair correlation\nstarting always at $1$ for $d=0$.\n\nThe sample variance can now be\nwritten in terms of the autocorrelation function:\n\\bea\n\\sigma_E^2 &=&\n\\frac{1}{n}\\mathrm{Var}(E)+\\frac{2}{n}\\cdot\\mathrm{Var}(E)\\sum_{d=1}^{n-1}\n\\frac{f_d}{\\mathrm{Var}(E)}\\nonumber\\\\ &=&\n\\left(1+2\\sum_{d=1}^{n-1}\\kappa_d\\right)\\frac{1}{n}\\mathrm{Var}(E)\\nonumber\\\\\n&=&\\rule{0pt}{17pt}\n\\frac{\\tau}{n}\\cdot\\mathrm{Var}(E)\n\\label{eq:error_estimate_corr_new}\n\\eea\nand we see that $\\sigma_E^2$ can be expressed in terms the\nuncorrelated sample variance times a correction factor $\\tau$ which\naccounts for the correlation between measurements. We call this\ncorrection factor the \\emph{autocorrelation time}:\n\\[\n\\tau = 1+2\\sum_{d=1}^{n-1}\\kappa_d\n\\]\n%It is closely related to the area under the graph of the\n%autocorrelation function. \nFor a correlation free experiment, $\\tau$\nequals 1. From the point of view of\nEq.~(\\ref{eq:error_estimate_corr_new}) we can interpret a sequential\ncorrelation as an effective reduction of the number of measurements by\na factor $\\tau$. The effective number of measurements becomes\n\\bdm\nn_\\mathrm{eff} = \\frac{n}{\\tau}\n\\edm\nFrom the previous exercise you needed to store all experiments $E_k$ in order to compute the time autocorrelation function. You can reuse these data in this exercise and compute the full variance $\\sigma_E^2$, the covariance, the \nautocorrelation time $\\tau$ and the effective number of measurements\n$n_\\mathrm{eff}$. It is sufficient to choose only one of the temperatures.  Comment your results.\nCan you relate the correlation time $\\tau$ to what you found [5)? What about the covariance and the time autocorrelation function? \n\n\\end{enumerate}\n\n\\end{prob}\n\n\n\\begin{prob}\n\n\nThe aim of this exercise is to simulate financial transactions among financial agents\nusing Monte Carlo methods. The final goal is to extract a distribution of income  as function\nof the income $m$.   From Pareto's work (V.~Pareto, 1897) it is known from empirical studies\nthat the higher end of the distribution of money follows a distribution \n\\[\nw_m\\propto m^{-1-\\alpha},\n\\]\nwith $\\alpha\\in [1,2]$. We will here follow the analysis made by Patriarca {\\em et al} \\cite{patriarca2004}. \n\nHere we will study numerically the relation between the microdynamical \nrelations among financial \nagents and the  resulting macroscopic money distribution.\n\nWe assume we have $N$ agents that exchange money in pairs $(i,j)$. We assume also that all agents\nstart with the same amount of money $m_0 > 0$. At a given 'time step', we choose randomly a pair\nof agents $(i,j)$ and let a transaction take place. This means that agent $i$'s money $m_i$ changes\nto $m_i'$ and similarly we have $m_j\\rightarrow m_j'$. \nMoney is conserved during a transaction, meaning that\n\\begin{equation}\nm_i+m_j=m_i'+m_j'.\n\\label{eq:conserve}\n\\end{equation}\nThe change is done via a random reassignement (a random number) $\\epsilon$, meaning that\n\\[\nm_i' = \\epsilon(m_i+m_j),\n\\]\nleading to\n\\[\nm_j'= (1-\\epsilon)(m_i+m_j).\n\\]\nThe number $\\epsilon$ is extracted from a uniform distribution. \nIn this simple model, no agents are left with a debt, that is $m\\ge 0$. \nDue to the conservation law above, one can show that the system relaxes toward an equilibrium\nstate given by a Gibbs distribution\n\\[\n   w_m=\\beta \\exp{(-\\beta m)},\n\\]\nwith \n\\[\n\\beta = \\frac{1}{\\langle m\\rangle},\n\\]\nand $\\langle m\\rangle=\\sum_i m_i/N=m_0$, the average money.\nIt means that after equilibrium has been reached that the majority of agents is left with a small \nnumber of money, while the number of richest agents, those with $m$ larger than a specific value $m'$,\nexponentially decreases with $m'$. \n\nWe assume that we have $N=500$ agents.   In each simulation, we need a sufficiently large number of transactions, say $10^7$. Our aim is find the final equilibrium distribution $w_m$. In order to do that we would need\nseveral runs of the above simulations, at least $10^3-10^4$ runs (experiments).  \n\n\n\\begin{enumerate}\n\\item[a)] Your task is to first set up an algorithm which simulates the above transactions with an initial\namount $m_0$.\nThe challenge here is to figure out a Monte Carlo  simulation  based on the\nabove equations.  \nYou will in particular need to make an algorithm which sets up a histogram as function of $m$.\nThis histogram contains the number of times a value $m$ is registered and represents\n$w_m\\Delta m$. You will need to set up a value for the interval $\\Delta m$  (typically $0.01-0.05$).\nThat means you need to account for the number of times you register an income in the interval\n$m,m+\\Delta m$. The number of times you register this income, represents the value that enters the histogram.\nYou will also need to find a criterion for when the equilibrium situation has been reached.\n\n\\item[b)] Make thereafter a plot of  $\\log{(w_m)}$ as function of $m$\nand see if you get a straight line. \nComment the result.\n\n\\item[c)] We can then change our model to allow for a saving criterion, meaning that the agents save\na fraction $\\lambda$ of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions.\n\nThe conservation law of Eq.~(\\ref{eq:conserve}) holds, but the money to be shared in a transaction between\nagent $i$ and agent $j$ is now $(1-\\lambda)(m_i+m_j)$. This means that we have \n\\[\nm_i' = \\lambda m_i+\\epsilon(1-\\lambda)(m_i+m_j),\n\\]\nand \n\\[\nm_j' = \\lambda m_j+(1-\\epsilon)(1-\\lambda)(m_i+m_j),\n\\]\nwhich can be written as \n\\[\nm_i'=m_i+\\delta m\n\\]\nand \n\\[\nm_j'=m_j-\\delta m,\n\\]\nwith \n\\[\n\\delta m=(1-\\lambda)(\\epsilon m_j-(1-\\epsilon)m_i),\n\\]\nshowing how money is conserved during a transaction.\nSelect values of $\\lambda =0.25,0.5$ and $\\lambda=0.9$ and try to extract the corresponding\nequilibrium distributions and compare these with the Gibbs distribution. Comment your results.\nIf you have time, see if you can extract a parametrization of the above curves (see \nPatriarca {\\em et al} \\cite{patriarca2004}) \n\\end{enumerate}\n\n\\end{prob}\n\n\n\n", "meta": {"hexsha": "42fb5734feb31dd52d97f420243308e036798fa2", "size": 90558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/src/chapters/chapter12.tex", "max_stars_repo_name": "ManyBodyPhysics/CQMech", "max_stars_repo_head_hexsha": "8395f082392844a0e2831649aab4108324c86312", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-06-18T14:34:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T14:44:41.000Z", "max_issues_repo_path": "doc/src/chapters/chapter12.tex", "max_issues_repo_name": "ManyBodyPhysics/CQMech", "max_issues_repo_head_hexsha": "8395f082392844a0e2831649aab4108324c86312", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/chapters/chapter12.tex", "max_forks_repo_name": "ManyBodyPhysics/CQMech", "max_forks_repo_head_hexsha": "8395f082392844a0e2831649aab4108324c86312", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-02-18T15:21:45.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-18T15:21:45.000Z", "avg_line_length": 46.44, "max_line_length": 313, "alphanum_fraction": 0.7057686786, "num_tokens": 26716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.6502622857943925}}
{"text": "%!TEX root = 497Notes-Temple.tex\n\n\\section{MgNet, pre-act ResNet, variants and generalizations}\\label{sec:relation}\n%\\subsection{Some properties of MgNet}\n%So, this MgNet is corresponded to the multigrid methods \n%with iteration in function space. A natural idea is that there is also a dual version of \n%MgNet similar with the multigrid methods with iteration in dual space.\nThe MgNet model algorithm is one very basic and it can be generalized\nin many different ways. It can also be used as a guidance to modify and \nextend many existing CNN models. \n\nThe following result show how MgNet is related to the pre-act ResNet \\cite{he2016identity}. \n\\begin{theorem}\\label{thm:mgnet1}\nThe MgNet model Algorithm \\ref{alg:mgnet}, \nadmits the following identities\n\\begin{equation}\\label{dualmgnet}\nr^{\\ell, i} = r^{\\ell, i-1} -  A^{\\ell} \\circ \\sigma \\circ B^{\\ell,i}\\circ \\sigma (r^{\\ell,i-1}), \\quad i = 1:\\nu_\\ell, \\\\\n\\end{equation}\nwhere\n\\begin{equation}\n  \\label{eq:5}\n\tr^{\\ell,i} = f^{\\ell} - A^{\\ell} \\ast u^{\\ell,i}.   \n\\end{equation}\nFurthermore, \\eqref{dualmgnet} represents pre-act ResNet~\\cite{he2016identity} \nas shown before.\n\\end{theorem}\n\n\\begin{proof}\n\tBecause of the linearity of $A^\\ell$ and invariant within the same grid $\\ell$, \n\twe can apply $A^\\ell$ on both sides of \\eqref{mgnet} and minus with\n\t$f^\\ell$, thus we have\n\t$$\n\tf^{\\ell} - A^{\\ell} \\ast u^{\\ell,i} = f^{\\ell} - A^\\ell \\ast u^{\\ell,i-1} -\n\tA^{\\ell} \\ast \\sigma \\circ B^{\\ell,i}\\circ \\sigma (f^\\ell - A^\\ell \\ast u^{\\ell,i-1}).\n\t$$\nThis finish the proof with definition in \\eqref{eq:5}.\n\\end{proof}\n\nThe above result is very simple but critically important.\nIn view of Theorem \\ref{thm:mgnet1}, it shows how multigrid and \nCNN are intimately related. Furthermore, it provides a different version\nof iResNet, which can be viewed as the dual version of the original pre-act ResNet.\nThis relation is quit similar with the dual relation of $u$ and $f$\nin multigrid method \\cite{xu2017algebraic}.\n\\begin{lemma}\\label{thm:mgnet2} \n\tThe ResNet~\\cite{he2016deep} step\n \t as in \\eqref{eq:ResNet} \n%\t\\begin{equation}\\label{resnet}\n%\tf^{\\ell,i} = \\sigma( f^{\\ell, i-1} - \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} (f^{\\ell,i-1}) ).\n%\t\\end{equation}\nadmits the following relation:\n%(which resembles closely with \\eqref{dualmgnet}) \n\\begin{equation}\\label{tilde-resnet}\n\\tilde r^{\\ell,i+1} =\\sigma(\\tilde r^{\\ell,i}) -\nA^{\\ell,i} \\ast \\sigma \\circ B^{\\ell,i}\\ast \\sigma( \\tilde r^{\\ell,i}),\n\\end{equation}\nwhere\n\\begin{equation}\\label{tilde-f}\n\\tilde r^{\\ell,i} = r^{\\ell, i-1} -A^{\\ell,i} \\ast \\sigma \\circ B^{\\ell,i} \\ast r^{\\ell,i-1}.\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\n%\tNow, we will establish the connection between classical ResNet and MgNet. \n\tFirst, we apply $ A^{\\ell,i+1} \\circ \\sigma \\circ B^{\\ell,i+1}$ \n\ton the both sides of \\eqref{eq:ResNet} and get\n\t\\begin{equation}\\label{resnet1}\n\tA^{\\ell,i+1} \\ast \\sigma \\circ B^{\\ell,i+1} \\ast r^{\\ell,i} = \n\tA^{\\ell,i+1} \\ast \\sigma \\circ B^{\\ell,i+1}\\ast \\sigma( \\tilde r^{\\ell,i} ).\n\t\\end{equation}\n\tMinus by $r^{\\ell,i}$ on the both sides and recall the definition in \\eqref{tilde-f}, we have\n\t\\begin{equation*}\n\t\\tilde r^{\\ell,i+1} = r^{\\ell,i} - A^{\\ell,i+1} \\ast \\sigma \\circ B^{\\ell,i+1}\\ast \\sigma( \\tilde r^{\\ell,i}).\n\t\\end{equation*}\n\tBy the definition of $r^{\\ell,i} = \\sigma(\\tilde r^{\\ell,i})$, we finish this proof.\n\\end{proof}\n\nWe call the above form \\eqref{tilde-resnet} as\n$\\sigma$-ResNet, similar to the MgNet we replace $A^{\\ell,i}$ by $A^{\\ell}$  and get \nthe next Mg-ResNet form as:\n\\begin{equation}\\label{mg-resnet}\nr^{\\ell,i} =\\sigma(r^{\\ell,i-1}) -\nA^{\\ell} \\ast \\sigma \\circ B^{\\ell,i}\\ast \\sigma(r^{\\ell,i-1}).\n\\end{equation}\n\nIf we take these pooling and prolongation operators\nas discussed in the previous sections and focus on \nthe iterative forms on a certain grid $\\ell$, we may\ncompare them all as:\n\\begin{table}[!htbp]\n\t\\caption{Comparison for all iterative forms }\n\t\\label{comparison-ALL}\n\t\\begin{center}%\\scriptsize\n\t\t\\resizebox{1.0\\textwidth}{!}{\n\t\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\tPrimal-Dual & Model & Iterative form \\\\\n\t\t\t\t\\hline\n\t\t\t\t\\multirow{3}{*}{Feature space} & Abstract-MgNet & Solving $A^\\ell(u^\\ell) = f^\\ell$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& General-MgNet & $u^{\\ell,i} = u^{\\ell, i-1} + B^{\\ell,i} (f^\\ell - A^{\\ell}(u^{\\ell,i-1}))$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& {MgNet} & $u^{\\ell,i} = u^{\\ell, i-1} + \\sigma \\circ B^{\\ell,i}\\circ \\sigma (f^\\ell - A^{\\ell}(u^{\\ell,i-1}))$ \\\\\n\t\t\t\t\\hline\n\t\t\t\\multirow{5}{*}{Data space} & pre-act ResNet & $ r^{\\ell,i} = r^{\\ell, i-1} -  A^{\\ell,i} \\ast \\sigma \\circ B^{\\ell,i} \\ast \\sigma (r^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& Mg pre-act ResNet & $r^{\\ell,i} = r^{\\ell, i-1} -  A^{\\ell} \\ast \\sigma \\circ B^{\\ell,i}\\ast \\sigma (r^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& Mg-ResNet & $r^{\\ell,i} = \\sigma(r^{\\ell,i-1}) - A^{\\ell} \\ast \\sigma \\circ B^{\\ell,i}\\ast \\sigma( r^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& $\\sigma$-ResNet & $r^{\\ell,i} = \\sigma(r^{\\ell,i-1}) - A^{\\ell,i} \\ast \\sigma \\circ B^{\\ell,i}\\ast \\sigma( r^{\\ell,i-1})$ \\\\\n\t\t\t\t\\cline{2-3}\n\t\t\t\t& ResNet & $r^{\\ell,i} = \\sigma(r^{\\ell, i-1} -  A^{\\ell,i} \\ast \\sigma \\circ B^{\\ell,i} \\ast r^{\\ell,i-1})$ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular} \n\t\t}\n\t\\end{center}\n\\end{table}\nWe can have these connections for all iterative scheme in data space:\n%\\begin{equation}\n%\\text{ ResNet} \\xleftrightarrow{\\eqref{tilde-f}} \\sigma\\text{-ResNet } \\xleftrightarrow{A^{\\ell,i} \\leftrightarrow A^{\\ell}} \\text{Mg-ResNet}  \n%\\xleftrightarrow{\\sigma(f^{\\ell,i-1}) \\leftrightarrow f^{\\ell, i-1} } \\text{Mg pre-act ResNet} \\xleftrightarrow{ A^{\\ell} \\leftrightarrow A^{\\ell,i}} \\text{pre-act ResNet}.\n%\\end{equation}\n\\vspace{-19pt}\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=1.0\\textwidth]{Mgnetrelation} \n\t\\end{center}\n\t%\\caption{Connections}\n\t\\label{fig:mgnet}\n\\end{figure}\n\\vspace{-26pt}\n%Because of the linearity of $\\xi^{\\ell,i}$, the above forms of iResNet and ResNet\n%are equivalent to the previous as \\eqref{dualmgnet} and \\eqref{tilde-resnet}.\nIn this sense, these MgNet related models can be understood as\n models between pre-act ResNet and ResNet. And all these models can be\n understood as iteration in the data space as a dual relationship with\n feature space as MgNet.\n \n \nThe rationality of replacing  $A^{\\ell,i}$ by layer independent $A^{\\ell}$ may\nbe justified by the following theorem. \n\\begin{theorem}\\label{thm:CNN}\nOn each grid $\\mathcal T_\\ell$, \n\\begin{enumerate}\n\t\\item Any CNN model with\n%\tCNN and Mg-ResNet] \n\t\\begin{equation}\n\t\\label{CNN1}\n\tf^{\\ell,i} =   \\chi^{\\ell,i} \\circ \\sigma (f^{\\ell,i-1}),\n\t\\end{equation} \n\tcan be written as\n\t\\begin{equation}\\label{Res-CNN1}\n\tf^{\\ell,i} = \\sigma(f^{\\ell,i-1}) - \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i} \\circ\\sigma ( f^{\\ell,i-1}).\n\t\\end{equation}\n\t\\item Any CNN model with \n%\t[CNN and ResNet] \n\t\\begin{equation}\n\t\\label{CNN2}\n\tf^{\\ell,i} =   \\sigma\\circ\\chi^{\\ell,i} (f^{\\ell,i-1}).\n\t\\end{equation}\n\tcan be written as \n\t\\begin{equation}\\label{Res-CNN2}\n\tf^{\\ell,i} = \\sigma\\left(f^{\\ell,i-1} - \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell,i}  ( f^{\\ell,i-1})\\right).\n\t\\end{equation}\n\\end{enumerate}\n\n%\\begin{equation}\n% \\chi^{\\ell,i}: \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell} \n% \\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell},\n%\\end{equation}\n\\end{theorem}\n\\begin{proof}\n%\tWithout loss of generality, consider the classical CNN with \n%\t\\begin{equation}\n%\tf^{\\ell,i} =   ({\\rm id}  + \\tilde \\eta^{\\ell,i} )\\circ \\sigma (f^{\\ell,i-1}).\n%\t\\end{equation}\nLet use prove the first case as an example, \nthe second case can be proven with the same process.\n\nWith similar structure in MgNet, we can take\n\\begin{equation}\n\\label{xi-cnn1}\n\\xi^{\\ell}= \\hat \\delta^\\ell :=  [\\hat \\delta_1, \\cdots, \\hat \\delta_{{c_\\ell}}],\n\\end{equation}\nand \n\\begin{equation}\n\\label{eta-ell}\n\\eta^{\\ell,i} = [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}] \\circ (\\chi^{\\ell,i} - {\\rm id}_{c_\\ell}).\n\\end{equation}\nHere \n\\begin{equation}\n{\\rm id}_{c_\\ell}: \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell} \n\\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell},\n\\end{equation}\nis the identity map and \n\\begin{equation}\n\\hat \\delta_k :  \\mathbb{R}^{n_\\ell \\times n_\\ell \\times 2c_\\ell} \n\\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell},\n\\end{equation}\nwith \n\\begin{equation}\\label{eq:hatdelta}\n\\hat \\delta_k([X ,Y]) = -([X]_k + [Y]_k),\n\\end{equation}\nfor any $X, Y \\in \\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell}$ \nand $[X,Y] \\in \\mathbb{R}^{n_\\ell \\times n_\\ell \\times 2c_\\ell} $.\n\n\n\tFirst, we see that $\\eta^{\\ell,i}$ with the above \n\tform is a convolution from $\\mathbb{R}^{n_\\ell \\times n_\\ell \\times c_\\ell}$\n\tto  $\\mathbb{R}^{n_\\ell \\times n_\\ell \\times 2c_\\ell}$.\n\tFollowing the identity\n\t\\begin{equation}\n\tReLU(x) + ReLU(-x) = x,\n\t\\end{equation}\n\tand the definition of $\\xi^{\\ell}$ i.e. \n\t\\begin{equation}\n\t\\xi^{\\ell} = \\hat \\delta^\\ell,\n\t\\end{equation}\n\tas a special case in MgNet. \n\tFor more details, we can give a exact form of \n\t$\\hat \\delta_k$ as in \\eqref{eq:hatdelta} with\n\t\\begin{equation}\n\t\\hat \\delta_k = [0, \\cdots,0, -\\delta, \\cdots 0;  0, \\cdots,0, -\\delta, \\cdots 0],  \\quad k = 1:{c_\\ell},\n\t\\end{equation}\n\twhere $\\delta$ is the identity kernel during one channel.\n\t\n\tAt last, we have\n\t\\begin{align}\n\t\\left[\\xi^{\\ell} \\circ \\sigma \\circ [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}] (x) \\right]_k &=  \\left[\\xi^{\\ell} \\circ \\sigma \\circ [x, -x]  \\right]_k, \\\\\n\t&= \\hat \\delta_k ( [\\sigma(x), \\sigma(-x)]),  \\\\\n\t&= -\\delta([\\sigma(x)]_k) - \\delta([\\sigma(-x)]_k),\\\\\n\t&=-( \\sigma([x]_k)+ \\sigma(-[x]_k)) , \\\\\n\t&=  -[x]_k\n\t\\end{align}\n\tThus to say,\n\t\\begin{equation}\n\t\\xi^{\\ell} \\circ \\sigma \\circ [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}]  = -{\\rm id}_{c_\\ell}.\n\t\\end{equation}\n\tThen the modified dual form of MgNet in \\eqref{tilde-resnet} becomes\n\t\\begin{align}\n\tf^{\\ell,i} &= \\sigma(f^{\\ell,i-1}) - \\xi^{\\ell,i} \\circ \\sigma \\circ \\eta^{\\ell,i} \\circ\\sigma ( f^{\\ell,i-1}) , \\\\\n\t&=  \\sigma(f^{\\ell,i-1}) - \\left( \\xi^{\\ell} \\circ \\sigma \\circ [{\\rm id}_{c_\\ell}, -{\\rm id}_{c_\\ell}] \\right) \n\t\\circ (\\chi^{\\ell,i} - {\\rm id}_{c_\\ell})\\circ \\sigma(f^{\\ell,i-1})\\\\\n\t&=\\sigma(f^{\\ell,i-1}) + (\\chi^{\\ell,i} -{\\rm id}_{c_\\ell})\\circ \\sigma(f^{\\ell,i-1}),  \\\\\n\t&=\\chi^{\\ell,i} \\circ  \\sigma (f^{\\ell,i-1}).\n\t\\end{align}\n\tThis covers \\eqref{Res-CNN1}.\n\\end{proof}\n\n\n\\begin{remark}\nTheorems~\\ref{thm:CNN} shows that general CNN in\nthe forms of either \\eqref{CNN1} or \\eqref{CNN2} can be written recast\nas \\eqref{Res-CNN1} or \\eqref{Res-CNN2} with the data-feature mapping \n$A^\\ell=\\xi^\\ell$ that is not only independent of the layers, but is\nactually given a priori as in \\eqref{xi-cnn1}.  In\nview of Theorems~\\ref{thm:mgnet1} and \\ref{thm:mgnet2}, the classic\nCNN models can be essentially recovered from MgNet by choosing\n$\\xi^\\ell$ a priori as in  \\eqref{xi-cnn1}.  Since\nthe classic CNN models have been extensively tested to be successful,\nthe more general MgNet with more general $\\xi^\\ell$ (to be trained)\nare expected to be more efficient than the classic CNN models. \n\\end{remark}\n\n%At last we have the next relation:\n%\\input{MgNet-relation.tex}", "meta": {"hexsha": "d8d106ba326f3b5653378c231995a9962613409b", "size": 11062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_relation.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/mgnet_relation.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/mgnet_relation.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.5864661654, "max_line_length": 173, "alphanum_fraction": 0.6450913036, "num_tokens": 4215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126792, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6502622825636074}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{The Blakers-Massey theorem}\nThe Blakers-Massey theorem is a connectivity theorem which can be used to prove the Freudenthal suspension theorem, giving rise to the field of \\emph{stable homotopy theory}. It was proven in the setting of homotopy type theory by Lumsdaine et al, and their proof was the first that was given entirely in an elementary way, using only constructions that are invariant under homotopy equivalence. \n\n\\subsection{The Blakers-Massey theorem}\nConsider a span $A \\leftarrow S \\rightarrow B$, consisting of an $m$-connected map $f:S\\to A$ and an $n$-connected map $g:S\\to B$. We take the pushout of this span, and subsequently the pullback of the resulting cospan, as indicated in the diagram\n\\begin{equation}\\label{eq:BM}\n\\begin{tikzcd}\nS \\arrow[drr,bend left=15,\"g\"] \\arrow[ddr,bend right=15,swap,\"f\"] \\arrow[dr,densely dotted,\"u\" near end] \\\\\n& A \\times_{(A \\sqcup^S B)} B \\arrow[r,\"\\pi_2\"] \\arrow[d,\"\\pi_1\"] & B \\arrow[d,\"\\inr\"] \\\\\n& A \\arrow[r,swap,\"\\inl\"] & A \\sqcup^S B.\n\\end{tikzcd}\n\\end{equation}\nThe universal property of the pullback determines a unique map $u:S\\to A \\times_{(A\\sqcup^S B)} B$ as indicated.\n\n\\begin{thm}[Blakers-Massey]\nThe map $u:S\\to A \\times_{(A\\sqcup^S B)} B$ of \\cref{eq:BM} is $(n+m)$-connected.\n\\end{thm}\n\n\\subsection{The Freudenthal suspension theorem}\n\n\\begin{thm}\n  If $X$ is a $k$-connected pointed type, then the canonical map\n  \\begin{equation*}\n    X \\to \\loopspace{\\susp{X}}\n  \\end{equation*}\n  is $2k$-connected.\n\\end{thm}\n\n\\begin{thm}\n  $\\pi_n(\\sphere{n})=\\Z$ for $n\\geq 1$.\n\\end{thm}\n\n\\subsection{Higher groups}\n\\label{sec:higher-groups}\n\nRecall that types in HoTT may be viewed as $\\infty$-groupoids:\nelements are objects, paths are morphisms, higher paths are higher\nmorphisms, etc.\n\nIt follows that \\emph{pointed connected} types $B$ may be viewed as higher\ngroups, with \\define{carrier} $\\loopspacesym B$.\nThe neutral element is the identity path,\nthe group operation is given by path composition,\nand higher paths witness the unit and associativity laws.\nOf course, these higher paths are themselves subject to further laws,\netc., but the beauty of the type-theoretic definition is\nthat we don't have to worry about that:\nall the (higher) laws follow from the rules of the identity types.\nWriting $G$ for the carrier $\\loopspacesym B$, it is common to write $BG$ for the pointed\nconnected type $B$, which comes equipped with an identification $G = \\loopspacesym BG$.\nWe call $BG$ the \\define{delooping} of $G$.\n\nThe type of pointed types is\n$\\UU_\\pt \\defeq  \\sm{A:\\UU} A$. The type of $n$-truncated types is\n$\\UU^{\\le n} \\defeq  \\sm{A:\\UU}\\istrunc{n}{A}$ and for $n$-connected types it is\n$\\UU^{>n} \\defeq  \\sm{A:\\UU}\\mathsf{is\\usc{}conn}_n(A)$. We will combine these notations as needed.\n\n\\begin{defn}\nWe define the type of \\define{higher groups}, or \\define{$\\infty$-groups}, to be\n\\begin{equation*}\n\\infty\\mathsf{Grp}\\defeq \\sm{G:\\UU}{BG:\\UU_\\pt^{>0}} \\eqv{G}{\\loopspacesym BG}.\n\\end{equation*}\nWhen $G$ is an $\\infty$-group, we also write $G$ for its first projection, called the \\define{carrier} of $G$.\n\\end{defn}\n\n\\begin{rmk}\nNote that we have equivalences\n\\begin{align*}\n  \\infty\\mathsf{Grp}\n  &\\jdeq   \\sm{G:\\UU}{BG:\\UU_\\pt^{>0}} \\eqv{G}{\\loopspacesym BG} \\\\\n  &\\eqvsym \\sm{G:\\UU_\\pt}{BG:\\UU_\\pt^{>0}} G \\eqvsym_\\pt \\loopspacesym BG \\\\\n  &\\eqvsym \\UU_\\pt^{>0}\n\\end{align*}\nfor the type of higher groups. \n\\end{rmk}\n\nAutomorphism groups form a major class of examples of $\\infty$-groups.\nGiven \\emph{any} type $A$ and any object $a : A$, the automorphism group at $a$ is defined as\n\\define{automorphism group} $\\Aut a\\defeq (a=a)$. \nThis is indeed an $\\infty$-group, because it is the loop space of the connected component of $A$ at $a$, i.e. we define~$\\BAut a \\defeq  \\im(a : 1 \\to A) = (x : A) \\times \\trunc{-1}{a=x}$.\nFrom this definition it is immediate that $\\Aut a=\\loopspacesym\\BAut a$, so we see that $\\Aut a$ is indeed an example of an $\\infty$-group. \n\nIf we take $A = \\mathsf{Set}$, we get the usual symmetric groups\n$\\Sym_n \\defeq  \\Aut(\\Fin(n))$, where $\\Fin(n)$ is a set with $n$\nelements. (Note that $\\BS_n = \\BAut(\\Fin (n))$ is the type of all\n$n$-element sets.)\n\nWe recover the ordinary set-level groups by requiring that $G$ is a $0$-type, or equivalently, that $BG$\nis a $1$-type. This leads us to introduce:\n\n\\begin{defn}\nWe define the type of \\define{groupal $(n-1)$-groupoids}, or \\define{$n$-groups}, to be\n\\begin{equation*}\nn\\mathsf{Grp} \\defeq \\sm{G:\\UU_\\pt^{<n}}{BG :\\UU_\\pt^{>0}} G \\eqvsym_\\pt \\loopspacesym BG.\n\\end{equation*}\nWe write $\\mathsf{Grp}$ for the type of $1$-groups.\n\\end{defn}\n\nThe type of $n$-groups is therefore equivalent to the type of pointed connected $(n+1)$-types. Note that if $A$ is an $(n+1)$-type, then $\\Aut a$ is an $(n+1)$-group because $\\Aut a$ is $n$-truncated.\n\nFor example, the integers $\\mathbb{Z}$ as an additive group are from this\nperspective represented by their delooping $\\mathop{\\mathrm{B}\\mathbb{Z}}=\\bS^1$, i.e., the circle.\nIndeed, any set-level group $G$ is represented as its delooping $BG\\defeq K(G,1)$.\n\nMoving across the homotopy hypothesis, for every pointed type $(X,x)$\nwe have the \\define{fundamental $\\infty$-group of $X$},\n$\\Pi_\\infty(X,x)\\defeq \\Aut x$. Its $(n-1)$-truncation (an instance of\ndecategorification, see \\cref{sec:stabilization}) is the\n\\define{fundamental $n$-group of $X$}, $\\Pi_n(X,x)$,\nwith corresponding delooping $\\mathrm{B}\\Pi_n(X,x) = \\trunc{n}{\\BAut x}$.\n\nDouble loop spaces are more well-behaved than mere loop\nspaces. For example, they are commutative up to homotopy\nby the Eckmann-Hilton argument~\\cite[Theorem~2.1.6]{hottbook}.\nTriple loop spaces are even better behaved than double loop spaces, and so on.\n\n\\begin{defn}\nA type $G$ is said to be \\define{$k$-tuply groupal} if it comes equipped with a \\define{$k$-fold delooping}, i.e.~ a pointed $k$-connected\n$B^kG : \\UU_\\pt^{\\ge k}$ and an equivalence $G \\eqvsym \\loopspacesym^kB^kG$.\n\nMixing the two directions, we also define\n\\begin{align*}\n  (n,k)\\GType\n  &\\defeq  \\sm{G : \\UU_\\pt^{\\le n}}{B^kG : \\UU_\\pt^{\\ge k}}\n    G \\eqvsym_\\pt \\loopspacesym^kB^kG \\\\\n  & \\phantom{:}\\eqvsym \\UU_\\pt^{\\ge k,\\le n+k}\n\\end{align*}\nfor the type of \\define{$k$-tuply groupal $n$-groupoids}\\footnote{This\n  is called $n\\UU_k$ in \\cite{BaezDolan1998}, but here we give equal\n  billing to $n$ and $k$,\n  and we add the ``G'' to indicate group-structure.}.\nWe allow taking $n=\\infty$, in which case the truncation requirement\nis simply dropped.\n\\end{defn}\n\nNote that $n\\mathsf{Grp} = (n-1,1)\\GType$. This shift in indexing is slightly\nannoying, but we keep it to stay consistent with the literature.\n\nNote that for each $k\\geq 0$ there is a forgetful map\n\\begin{equation*}\n(n,k+1)\\GType \\to (n,k)\\GType,\n\\end{equation*}\ngiven by $B^{k+1}G\\mapsto \\loopspacesym B^{k+1}G$, defining a sequence\n\\begin{equation*}\n\\begin{tikzcd}\n\\cdots \\arrow[r] & (n,2)\\GType \\arrow[r] & (n,1)\\GType \\arrow[r] & (n,0)\\GType.\n\\end{tikzcd}\n\\end{equation*}\nThus we define $(n,\\infty)\\GType$ as the limit of this sequence:\n\\begin{align*}\n(n,\\infty)\\GType & \\defeq  \\lim_k{}(n,k)\\GType \\\\\n&\\phantom{:}\\eqvsym \\sm{B^{\\blank}G : \\prd{k : \\bN}\\UU_\\pt^{\\ge k,\\le n+k}}\\prd{k : \\bN} B^kG \\eqvsym_\\pt \\loopspacesym B^{k+1}G.\n\\end{align*}\nIn \\cref{sec:stabilization} we prove the stabilization theorem\n(\\cref{thm:stabilization}), from which it follows that\n$(n,\\infty)\\GType=(n,k)\\GType$ for $k\\geq n+2$.\n\nThe type $(\\infty,\\infty)\\GType$ is the type of \\define{stably groupal $\\infty$-groups},\nalso known as \\define{connective spectra}. If we also relax the\nconnectivity requirement, we get the type of all spectra, and we can\nthink of a spectrum as a kind of $\\infty$-groupoid with $k$-morphisms\nfor all $k\\in\\mathbb{Z}$.\n\nThe double hierarchy of higher groups is summarized in~\\cref{tab:periodic}.\nWe shall prove the correctness of the $n=0$ column in~\\cref{sec:n=0}.\n\\begin{table}\n  \\caption{\\label{tab:periodic}Periodic table of $k$-tuply groupal $n$-groupoids.}\n  \\centering\n  \\begin{tabular}{clllll} \\toprule\n    $k\\setminus n$ & $0$ & $1$ & $2$ & $\\cdots$ & $\\infty$ \\\\\n    \\midrule\n    $0$ & pointed set & pointed groupoid & pointed $2$-groupoid & $\\cdots$ & pointed $\\infty$-groupoid \\\\\n    $1$ & group & $2$-group & $3$-group & $\\cdots$ & $\\infty$-group \\\\\n    $2$ & abelian group & braided $2$-group & braided $3$-group & $\\cdots$ & braided $\\infty$-group \\\\\n    $3$ & \\ditto & symmetric $2$-group & sylleptic $3$-group & $\\cdots$ & sylleptic $\\infty$-group \\\\\n    $4$ & \\ditto & \\ditto & symmetric $3$-group & $\\cdots$ & ?? $\\infty$-group \\\\\n    $\\vdots$ & \\mbox{}\\quad$\\vdots$ & \\mbox{}\\quad$\\vdots$ & \\mbox{}\\quad$\\vdots$ & $\\ddots$ & \\mbox{}\\quad$\\vdots$ \\\\\n    $\\loopspacesym$ & \\ditto & \\ditto & \\ditto & $\\cdots$ & connective spectrum \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{table}\n\nA homomorphism between higher groups is any\nfunction that can be suitably delooped.\n\n\\begin{defn}\nFor $G,H : (n,k)\\GType$, we define\n\\begin{align*}\n\\hom_{(n,k)}(G,H) & \\defeq  \n\\sm{h: G \\to_\\pt H}{B^k h: B^kG \\to_\\pt B^kH} \\loopspacesym^k(B^k h) \\sim_\\pt h \\\\\n&\\phantom{:}\\eqvsym (B^k h: B^kG \\to_\\pt B^kH).\n\\end{align*}\nFor (connective) spectra we need\npointed maps between all the deloopings and pointed homotopies showing\nthey cohere.\n\\end{defn}\n\nNote that if $h,k : G \\to H$ are homomorphisms between set-level\ngroups, then $h$ and $k$ are \\define{conjugate} if $Bh, Bk : BG \\to_\\pt BH$ are\n\\define{freely} homotopic (i.e., equal as maps $BG \\to BH$).\n\nAlso observe that \n\\begin{align*}\n\\pi_j(B^kG \\to_\\pt B^kH) & \\eqvsym \\trunc{0}{B^kG \\to_\\pt \\loopspacesym^jB^kH} \\\\\n& \\eqvsym \\trunc{0}{\\Sigma^jB^kG \\to_\\pt B^kH} \\\\\n& \\eqvsym 0\n\\end{align*}\nfor $j>n$, which suggests that $\\hom_{(n,k)}(G,H)$ is $n$-truncated. To prove this, we deviate slightly from the approach in \\cite{BuchholtzDoornRijke} and use the following intermediate result.\n\n\\subsection{The stabilization theorem for higher groups}\n\\label{sec:stabilization}\n\n\\begin{defn}\nThe \\define{decategorification} $\\Decat G$ of a $k$-tuply groupal $(n+1)$-group is defined to be the $k$-tuply groupal $n$-group $\\trunc{n-1}{G}$, which has delooping $\\trunc{n+k-1}{B^kG}$. Thus, decategorification is an operation\n\\begin{equation*}\n\\Decat : (n,k)\\GType \\to (n-1,k)\\GType.\n\\end{equation*}\nThe functorial action of $\\Decat$ is defined in the expected way. We also define the \\define{$\\infty$-decategorification} $\\iDecat G$ of a $k$-tuply groupal $\\infty$-group as the $k$-tuply groupal $n$-group $\\trunc{n}{G}$, which has delooping $\\trunc{n+k}{B^k G}$. \n\\end{defn}\n\n\\begin{defn}\nThe \\define{discrete categorification} $\\Disc G$ of a $k$-tuply-groupal $(n+1)$-group is defined to be the same $\\infty$-group $G$, now considered as a $k$-tuply groupal $(n+2)$-group. Thus, the discrete categorification is an operation\n\\begin{equation*}\n\\Disc : (n,k)\\GType \\to (n+1,k)\\GType.\n\\end{equation*}\nSimilarly, the \\define{discrete $\\infty$-decategorification} $\\iDisc G$ of a $k$-tuply groupal $(n+1)$-group is defined to be the same group, now considered as a $k$-tuply groupal $\\infty$-group.\n\\end{defn}\n\n\\begin{rmk}\nThe decategorification and discrete categorification functors make the $(n+1)$-category $(n,k)\\GType$ a reflective sub-$(\\infty,1)$-category of $(n+1,k)\\GType$. That is, there is an adjunction ${\\Decat} \\dashv {\\Disc}$. These properties are straightforward consequences of the universal property of truncation.\nSimilarly, we have ${\\iDecat} \\dashv {\\iDisc}$ such that the counit induces an isomorphism ${\\iDecat} \\circ {\\iDisc} = \\idfunc$.\n\\end{rmk}\n\nFor the next constructions, we need the following properties.\n\\begin{defn}\n  For $A : \\UU_\\pt$ we define the \\define{$n$-connected cover} of $A$ to be \n  $A{\\angled n} \\defeq  \\fibf{A \\to \\trunc{n}{A}}$. We have the projection $p_1: A{\\angled n} \\to_\\pt A$.\n\\end{defn}\n\n\\begin{lem} \\label{lem:connected-cover-univ}\n  The universal property of the $n$-connected cover states the following. For any $n$-connected pointed type $B$, the pointed map\n  $$(B \\to_\\pt A{\\angled n}) \\to_\\pt (B \\to_\\pt A),$$\n  given by postcomposition with $p_1$, is an equivalence.\\\\\n\\end{lem}\n\n\\begin{proof}\n  Given a map $f:B\\to_\\pt A$, we can form a map $\\widetilde f: B \\to A{\\angled n}$. First note that for $b:B$ the type $\\truncunit{fb}_n=_{\\trunc{n}{A}}\\truncunit{\\pt}_n$ is $(n-1)$-truncated and inhabited for $b=\\pt$. Since $B$ is $n$-connected, the universal property for connected types shows that we can construct a $qb:\\truncunit{fb}_n=\\truncunit{\\pt}_n$ for all $b$ such that $q_0:qb_0\\cdot\\mathsf{ap}_{\\truncunit{\\blank}_n}(f_0)=1$. Then we can define the map $\\widetilde f(b)\\defeq (fb, qb)$. Now $\\widetilde f$ is pointed, because $(f_0,q_0):(fb_0,qb_0)=(a_0,1)$.\n\n  Now we show that this is indeed an inverse to the given map. On the one hand, we need to show that if $f: B \\to_\\pt A$, then $\\proj 1 \\circ \\widetilde f=f$. The underlying functions are equal because they both send $b$ to $f(b)$. They respect points in the same way, because\n  $\\mathsf{ap}{p_1}(\\widetilde f_0)=f_0$. The proof that the other composite is the identity follows from a computation using fibers and connectivity, which we omit here, but can be found in the formalization.\n\\end{proof}\n\nThe next reflective sub-$(\\infty,1)$-category is formed by looping and delooping.\n\\begin{description}\n\\item[looping] $\\loopspacesym : (n,k)\\GType \\to (n-1,k+1)\\GType$ \\\\\n  $\\angled{G,B^kG} \\mapsto \\angled{\\loopspacesym G,B^kG{\\angled k}}$\n\\item[delooping] $\\B : (n,k)\\GType \\to (n+1,k-1)\\GType$ \\\\\n  $\\angled{G,B^kG} \\mapsto \\angled{\\loopspacesym^{k-1}B^kG,B^kG}$\n\\end{description}\nWe have ${\\B} \\dashv {\\loopspacesym}$, which follows from Lemma \\ref{lem:connected-cover-univ} %note: autoref writes \"Theorem\"\nand $\\loopspacesym\\circ{\\B} = \\idfunc$, which follows from the fact that $A{\\angled n}=A$ if $A$ is $n$-connected.\n\nThe last adjoint pair of functors is given by stabilization and forgetting. This does not form a reflective sub-$(\\infty,1)$-category.\n\\begin{description}\n\\item[forgetting] $F : (n,k)\\GType \\to (n,k-1)\\GType$ \\\\\n  $\\angled{G,B^kG} \\mapsto \\angled{G,\\loopspacesym B^kG}$\n\\item[stabilization] $S : (n,k)\\GType \\to (n,k+1)\\GType$ \\\\\n  $\\angled{G,B^kG} \\mapsto \\angled{SG,\\trunc{n+k+1}{\\susp B^kG}}$,\\\\\n  where $SG = \\trunc{n}{\\loopspacesym^{k+1}\\susp B^kG}$\n\\end{description}\nWe have the adjunction ${S} \\dashv {F}$ which follows from the suspension-loop adjunction $\\Sigma\\dashv\\loopspacesym$ on pointed types.\n\nThe next main goal in this section is the stabilization theorem,\nstating that the ditto marks in~\\cref{tab:periodic} are justified.\n\nThe following corollary is almost \\cite[Lemma~8.6.2]{hottbook}, but\nproving this in Book HoTT is a bit tricky. See the\nformalization for details.\n\\begin{lem}[Wedge connectivity]\n  \\label{lem:wedge-connectivity}\n  If $A : \\UU_\\pt$ is $n$-connected and $B: \\UU_\\pt$ is\n  $m$-connected, then the map $A \\vee B \\to A \\times B$ is\n  $(n+m)$-connected.\n\\end{lem}\n\nLet us mention that there is an alternative way to prove the wedge\nconnectivity lemma: Recall that if $A$ is $n$-connected and $B$ is\n$m$-connected, then $A \\ast B$ is\n$(n+m+2)$-connected~\\cite[Theorem~6.8]{joinconstruction}. Hence the\nwedge connectivity lemma is also a direct consequence of the following lemma.\n\\begin{lem}\nLet $A$ and $B$ be pointed types.\nThe fiber of the wedge inclusion $A\\vee B\\to A\\times B$ is equivalent to\n$\\loopspacesym{A}\\ast\\loopspacesym{B}$. \n\\end{lem}\n\\begin{proof}\nNote that the fiber of $A\\to A\\times B$ is $\\loopspacesym B$, the fiber of $B\\to A\\times B$ is $\\loopspacesym A$, and of course the fiber of $1\\to A\\times B$ is $\\loopspacesym A\\times \\loopspacesym B$. We get a commuting cube\n\\begin{equation*}\n\\begin{tikzcd}\n& \\loopspacesym A\\times \\loopspacesym B \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n\\loopspacesym B \\arrow[d] & 1 \\arrow[dl] \\arrow[dr] & \\loopspacesym A \\arrow[dl,crossing over] \\arrow[d] \\\\\nA \\arrow[dr] & 1 \\arrow[d] \\arrow[from=ul,crossing over] & B \\arrow[dl] \\\\\n& A\\times B\n\\end{tikzcd}\n\\end{equation*}\nin which the vertical squares are pullback squares. \n\nBy the descent theorem for pushouts it now follows that $\\loopspacesym A\\ast \\loopspacesym B$ is the fiber of the wedge inclusion.\n\\end{proof}\n\nThe second main tool we need for the stabilization theorem is:\n\\begin{thm}[Freudenthal]\n  If $A : \\UU_\\pt^{>n}$ with $n\\ge 0$, then the map\n  $A \\to \\loopspacesym\\susp A$ is $2n$-connected.\n\\end{thm}\nThis is \\cite[Theorem~8.6.4]{hottbook}.\n\nThe final building block we need is:\n\\begin{lem}\n  There is a pullback square\n  \\[\n    \\begin{tikzcd}\n      \\susp\\loopspacesym A \\ar[d,\"\\varepsilon_A\"']\\ar[r] & A \\vee A \\ar[d] \\\\\n      A \\ar[r,\"\\Delta\"'] & A \\times A\n    \\end{tikzcd}\n  \\]\n  for any $A : \\UU_\\pt$.\n\\end{lem}\n\n\\begin{proof}\nNote that the pullback of $\\Delta:A\\to A\\times A$ along either inclusion $A\\to A\\times A$ is contractible. So we have a cube\n\\begin{equation*}\n\\begin{tikzcd}\n& \\loopspacesym A \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n1 \\arrow[d] & 1 \\arrow[dl] \\arrow[dr] & 1 \\arrow[dl,crossing over] \\arrow[d] \\\\\nA \\arrow[dr] & A \\arrow[d,\"\\Delta\"] \\arrow[from=ul,crossing over] & A \\arrow[dl] \\\\\n& A\\times A\n\\end{tikzcd}\n\\end{equation*}\nin which the vertical squares are all pullback squares. Therefore, if we pull back along the wedge inclusion, we obtain by the descent theorem for pushouts that the square in the statement is indeed a pullback square.\n\\end{proof}\n\n\\begin{thm}[Stabilization]\n  \\label{thm:stabilization}\n  If $k\\ge n+2$, then $S : (n,k)\\GType \\to (n,k+1)\\GType$ is an\n  equivalence, and any $G : (n,k)\\GType$ is an infinite loop space.\n\\end{thm}\n\\begin{proof}\n  We show that $F\\circ S=\\idfunc=S\\circ F : (n,k)\\GType \\to (n,k)\\GType$\n  whenever $k\\ge n+2$.\n\n  For the first, the unit map of the adjunction factors as\n  \\[\n    B^kG \\to \\loopspacesym\\susp B^kG \\to \\loopspacesym\\trunc{n+k+1}{\\susp B^kG}\n  \\]\n  where the first map is $2k-2$-connected by Freudenthal, and the\n  second map is $n+k$-connected. Since the domain is $n+k$-truncated,\n  the composite is an equivalence whenever $2k-2 \\ge n+k$.\n\n  For the second, the counit map of the adjunction factors as\n  \\[\n    \\trunc{n+k}{\\susp\\loopspacesym B^kG} \\to \\trunc{n+k}{B^kG} \\to B^kG,\n  \\]\n  where the second map is an equivalence. By the two lemmas above, the\n  first map is $2k-2$-connected.\n\\end{proof}\nFor example, for $G : (0,2)\\GType$ an abelian group, we have\n$B^nG = K(G,n)$, an Eilenberg-MacLane space.\n\nThe adjunction ${S} \\dashv {F}$ implies that the free group on a\npointed set $X$ is $\\loopspacesym\\trunc{1}{\\susp X}=\\pi_1(\\susp X)$.  If $X$\nhas decidable equality, $\\susp X$ is already $1$-truncated. It is an\nopen problem whether this is true in general.\n\nAlso, the abelianization of a set-level group $G : 1\\mathsf{Grp}$ is\n$\\pi_2(\\susp BG)$. If $G : (n,k)\\GType$ is in the stable range ($k \\ge\nn+2$), then $SFG=G$.\n\n\\subsection{Eilenberg-Mac Lane spaces}\n\n\\begin{exercises}\n\\exercise Show that if $X$ is $m$-connected and $f:X\\to Y$ is $n$-connected, then the map\n\\begin{equation*}\nX \\to \\fib{m_f}{\\ast}\n\\end{equation*}\nwhere $m_f:Y\\to M_f$ is the inclusion of $Y$ into the cofiber of $f$, is $(m+n)$-connected.\n\\exercise Suppose that $X$ is a connected type, and let $f:X\\to Y$ be a map.\nShow that the following are equivalent:\n\\begin{enumerate}\n\\item $f$ is $n$-connected.\n\\item The mapping cone of $f$ is $(n+1)$-connected.\n\\end{enumerate}\n\\exercise Apply the Blakers-Massey theorem to the defining pushout square of the smash product to show that if $A$ and $B$ are $m$- and $n$-connected respectively, then there is a $(m+n+\\min(m,n)+2)$-connected map\n\\begin{equation*}\n\\join{\\loopspace{A}}{\\loopspace{B}}\\to \\loopspace{A \\wedge B}.\n\\end{equation*}\n\\exercise Show that the square\n\\begin{equation*}\n\\begin{tikzcd}\n\\unit \\arrow[r] \\arrow[d] & \\bool \\arrow[d] \\\\\nX \\arrow[r] & X+\\unit\n\\end{tikzcd}\n\\end{equation*}\nis both a pullback and a pushout. Conclude that the result of the Blakers-Massey theorem is not always sharp.\n\\item Show that for every pointed type $X$, and any $n:\\N$, there is a fiber sequence\n  \\begin{equation*}\n    K(\\pi_{n+1}(X),n+1)\\hookrightarrow \\trunc{n+1}{X}\\twoheadrightarrow \\trunc{n}{X}.\n  \\end{equation*}\n\\end{exercises}\n", "meta": {"hexsha": "0609b4210598bcee51b97255096933482f170dc9", "size": 20142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/blakers-massey.tex", "max_stars_repo_name": "tmoux/HoTT-Intro", "max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "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/blakers-massey.tex", "max_issues_repo_name": "tmoux/HoTT-Intro", "max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "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/blakers-massey.tex", "max_forks_repo_name": "tmoux/HoTT-Intro", "max_forks_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "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": 48.8883495146, "max_line_length": 572, "alphanum_fraction": 0.691093238, "num_tokens": 7116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.6502622817849252}}
{"text": "\\chapter{Maxwell's Equations }\n\\section{Electrodynamics Before Maxwell}\nTill now in electromagnetic theory we found out four equations which contribute to the foundation of Electromagnetic theory, and they are,\n\\begin{align*}\n\\vec{\\nabla} \\cdot \\vec{E}&=\\frac{\\rho}{\\epsilon_{0}} \\quad && \\Rightarrow \\text { Gauss' Law }  \\\\\n\\vec{\\nabla} \\cdot \\vec{B}&=0 \\quad && \\Rightarrow \\text { Gauss' Law for magnetism } \\\\\n\\vec{\\nabla} \\times \\vec{E}&=-\\frac{\\partial \\vec{B}}{\\partial t} && \\Rightarrow \\text { Faraday's Law } \\\\\n\\vec{\\nabla} \\times \\vec{B}&=\\mu_{0}\\left(\\vec{J}\\right) && \\Rightarrow \\text { Ampere's Law }\n\\end{align*}\nThere is a fatal inconsistency in these formulas. It has something to do with the old rule that divergence of curl is always zero $ (\\nabla .(\\nabla \\times \\mathbf{E})=0)$. If you apply the divergence to Faraday's law, everything works out: \n$$\\nabla \\cdot(\\nabla \\times \\mathbf{E})=\\nabla \\cdot\\left(-\\frac{\\partial \\mathbf{B}}{\\partial t}\\right)=-\\frac{\\partial}{\\partial t}(\\nabla \\cdot \\mathbf{B})$$\nThe left side is zero because divergence of curl is zero; the right side is zero by virtue of Gauss law for magnetism. But when you do the same thing to Ampere's law, you get into trouble:$$\\boldsymbol{\\nabla} \\cdot(\\boldsymbol{\\nabla} \\times \\mathbf{B})=\\mu_{0}(\\boldsymbol{\\nabla} \\cdot \\mathbf{J})$$ The left side must be zero, but the right side, in general, is not. For steady currents, the divergence of $\\mathbf{J}$ is zero, but evidently when we go beyond magnetostatics Ampère's law cannot be right.\n\\subsection{How Maxwell Fixed Ampere's Law}\nApplying the continuity equation  and Gauss's law, in  Ampere's law the offending term can be rewritten as:\n\\begin{align*}\n\\nabla \\cdot \\mathbf{J}&=-\\frac{\\partial \\rho}{\\partial t}\\\\\n&=-\\frac{\\partial}{\\partial t}\\left(\\epsilon_{0} \\nabla \\cdot \\mathbf{E}\\right)\\\\&=-\\nabla \\cdot\\left(\\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}\\right)\n\\end{align*}\nIf we were to combine $\\epsilon_{0}(\\partial \\mathbf{E} / \\partial t)$ with $\\mathbf{J}$, in Ampère's law, it would be just right to kill off the extra divergence:$$\\nabla \\times \\mathbf{B}=\\mu_{0} \\mathbf{J}+\\mu_{0} \\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}$$ Such a modification changes nothing, as far as magnetostatics is concerned: when $\\mathbf{E}$ isconstant, we still have $\\boldsymbol{\\nabla} \\times \\mathbf{B}=\\mu_{0} \\mathbf{J}$.\\\\\nJust as a changing magnetic field induces an electric field (Faraday's law), so \\textbf{A changing electric field induces a magnetic field}.  Maxwell called his extra term the displacement current:\n\n\\hspace{5.10cm}\\framebox{\n\t\n\t\\parbox[t][2cm]{4cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\tDisplacement Current\n\t\t$$\\mathbf{J}_{d} \\equiv \\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}$$} \n}\n\\\\\\\\ It's a misleading name, since $\\epsilon_{0}(\\partial \\mathbf{E} / \\partial t)$ has nothing to do with current, except that it adds to $\\mathbf{J}$ in Ampère's law.\n\\subsection{Maxwell's Equations}\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][4.2cm]{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\\textbf{(i)} & \\nabla \\cdot \\mathbf{E}=\\frac{1}{\\epsilon_{0}} \\rho&\\text{(Gauss's law)} \\\\\\\\ \\textbf{(ii)} & \\nabla \\cdot \\mathbf{B}=0&\\text{(No name.)}\\\\\\\\ \\textbf{(iii)}& \\boldsymbol{\\nabla} \\times \\mathbf{E}=-\\frac{\\partial \\mathbf{B}}{\\partial t}&\\text{(Faraday's law)}\\\\\\\\\\textbf{(iv)}&\\boldsymbol{\\nabla} \\times \\mathbf{B}=\\mu_{0} \\mathbf{J}+\\mu_{0} \\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}&\\text{(Ampère's law with\n\t\t\t\tMaxwell's correction)}\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\nEvery phenomenon in electricity and magnetism can be derived from these equations. Many of our most important tools for various analyses come from the integral version of these equations, which are.\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][4.2cm]{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\\textbf{(i)} & \\iint_{S} \\overrightarrow{\\mathbf{E}} \\cdot d \\overrightarrow{\\mathbf{A}}=\\frac{Q}{\\varepsilon_{0}} &\\text{(Gauss's law)} \\\\\\\\ \\textbf{(ii)} & \\iint_{S} \\overrightarrow{\\mathbf{B}} \\cdot d \\overrightarrow{\\mathbf{A}}=0&\\text{(No name.)}\\\\\\\\ \\textbf{(iii)}& \\oint \\overrightarrow{\\mathbf{E}} \\cdot d \\overrightarrow{\\mathbf{s}}=-\\frac{d \\mathbf{\\phi_B}}{d t}&\\text{(Faraday's law)}\\\\\\\\\\textbf{(iv)}&\\oint \\overrightarrow{\\mathbf{B}} \\cdot d \\overrightarrow{\\mathbf{s}}=\\mu_{0} I+\\mu_{0} \\varepsilon_{0} \\frac{d \\Phi_{E}}{d t}&\\text{(Ampère's law with\n\t\t\t\tMaxwell's correction)}\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center} \nTogether with the force law,\\ $\\mathbf{F}=q(\\mathbf{E}+\\mathbf{v} \\times \\mathbf{B})$,\\ they summarize the entire theoretical content of classical electrodynamics. Even the continuity equation,\\ $\\boldsymbol{\\nabla} \\cdot \\mathbf{J}=-\\frac{\\partial \\rho}{\\partial t}$ \\ which is the mathematical expression of conservation of charge, can be derived from Maxwell's equations by applying the divergence to Ampere's law.\n\\subsection{Maxwell's Equations In Free Space}\nAn extremely important limit of Maxwell's equations is found when there are no sources: $\\rho=0, \\vec{J}=0 .$ The equations become,\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][4.2cm]{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\\textbf{(i)} & \\nabla \\cdot \\mathbf{E}=0&\\text{(Gauss's law)} \\\\\\\\ \\textbf{(ii)} & \\nabla \\cdot \\mathbf{B}=0&\\text{(No name.)}\\\\\\\\ \\textbf{(iii)}& \\boldsymbol{\\nabla} \\times \\mathbf{E}=-\\frac{\\partial \\mathbf{B}}{\\partial t}&\\text{(Faraday's law)}\\\\\\\\\\textbf{(iv)}&\\boldsymbol{\\nabla} \\times \\mathbf{B}=\\mu_{0} \\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}&\\text{(Ampère's law with\n\t\t\t\tMaxwell's correction)}\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n\\subsection{Maxwell's Equations in Matter}\nFor inside polarized matter there will be accumulations of \"bound\" charge and current over which you exert no direct control. It would be nice to reformulate Maxwell's equations in such a way as to make explicit reference only to those sources we control directly: the \"free\" charges and currents. \\\\\nWe have already learned, from the static case, that an electric polarization $\\mathbf{P}$ produces a bound charge density $$\\rho_{b}=-\\nabla \\cdot \\mathbf{P}$$ Likewise, a magnetic polarization (or \"magnetization\") $\\mathbf{M}$ results in a bound current $$\\mathbf{J}_{b}=\\nabla \\times \\mathbf{\\mathbf { M }}$$ There's just one new feature to consider in the nonstatic case: Any change in the electric polarization involves a flow of (bound) charge (call it $\\mathbf{J}_{p}$), which must be included in the total current. For suppose we examine a tiny chunk of polarized material The polarization introduces a charge density $\\sigma_{b}=P$ at one end and $-\\sigma_{b}$ at the other. If $P$ now increases a bit, the charge on each end increases accordingly. \\\\giving a net current $$d I=\\frac{\\partial \\sigma_{b}}{\\partial t} d a_{\\perp}=\\frac{\\partial P}{\\partial t} d a_{\\perp}$$\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=4cm,height=2cm]{02-crop}\n\t\\end{center}\n\\end{figure}\nThe current density, therefore, is $$\\mathbf{J}_{p}=\\frac{\\partial \\mathbf{P}}{\\partial t}$$\nThis polarization current has nothing whatever to do with the bound current $\\mathbf{J}_{b}$. The latter is associated with magnetization of the material and involves the spin and orbital motion of electrons; $\\mathbf{J}_{p}$, by contrast, is the result of the linear motion of charge when the electric polarization changes. If $\\mathbf{P}$ points to the right and is increasing, then each plus charge moves a bit to the right and each minus charge to the left; the cumulative effect is the polarization current $\\mathbf{J}_{p}$\\\\\\\\\nIn fact, $\\mathbf{J}_{p}$ is essential to account for the conservation of bound charge.\\\\\nIn view of all this, the total charge density can be separated into two parts: $$\\rho=\\rho_{f}+\\rho_{b}=\\rho_{f}-\\boldsymbol{\\nabla} \\cdot \\mathbf{P}$$ and the current density into three parts:\n$$\\mathbf{J}=\\mathbf{J}_{f}+\\mathbf{J}_{b}+\\mathbf{J}_{p}=\\mathbf{J}_{f}+\\mathbf{\\nabla} \\times \\mathbf{M}+\\frac{\\partial \\mathbf{P}}{\\partial t}$$ Gauss's law can now be written as $$\\nabla \\cdot \\mathbf{E}=\\frac{1}{\\epsilon_{0}}\\left(\\rho_{f}-\\nabla \\cdot \\mathbf{P}\\right)$$ \\text{or}$$\\boldsymbol{\\nabla} \\cdot \\mathbf{D}=\\rho_{f}$$ where $\\mathbf{D}$, as in the static case, is given by $$\\mathbf{D} \\equiv \\epsilon_{0} \\mathbf{E}+\\mathbf{P}$$ Meanwhile, Ampère's law (with Maxwell's term) becomes $$\\nabla \\times \\mathbf{B}=\\mu_{0}\\left(\\mathbf{J}_{f}+\\nabla \\times \\mathbf{M}+\\frac{\\partial \\mathbf{P}}{\\partial t}\\right)+\\mu_{0} \\epsilon_{0} \\frac{\\partial \\mathbf{E}}{\\partial t}$$\\text{or}$$\\boldsymbol{\\nabla} \\times \\mathbf{H}=\\mathbf{J}_{f}+\\frac{\\partial \\mathbf{D}}{\\partial t}$$ where, as before,$$\\mathbf{H} \\equiv \\frac{1}{\\mu_{0}} \\mathbf{B}-\\mathbf{M}$$ Faraday's law and $\\nabla \\cdot \\mathbf{B}=0$ are not affected by our separation of charge and current into free and bound parts, since they do not involve $\\rho$ or $\\mathbf{J}$. \\\\\nIn terms of free charges and currents, then, Maxwell's equations read\\\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][2.5cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0cm} \\centering\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\begin{array}{llll}\n\t\t\t\\textbf{(i)} & \\nabla \\cdot \\mathbf{D}=\\rho_{f} &\\textbf{(iii)} & \\boldsymbol{\\nabla} \\times \\mathbf{E}=-\\frac{\\partial \\mathbf{B}}{\\partial t},\\\\\\\\\n\t\t\t\\textbf{(ii)}&\\boldsymbol{\\nabla} \\cdot \\mathbf{B}=0&\\textbf{(iv)}& \\boldsymbol{\\nabla} \\times \\mathbf{H}=\\mathbf{J}_{f}+\\frac{\\partial \\mathbf{D}}{\\partial t}\n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\nfor linear media\n\\begin{align*}\n\\begin{array}{lll}\n\\mathbf{P}=\\epsilon_{0} \\chi_{e} \\mathbf{E} & and& \\mathbf{M}=\\chi_{m} \\mathbf{H}\\\\\\\\\n\\mathbf{D}=\\epsilon \\mathbf{E}&and&\\mathbf{H}=\\frac{1}{\\mu} \\mathbf{B}\n\\end{array}\n\\end{align*}\nwhere $\\epsilon \\equiv \\epsilon_{0}\\left(1+\\chi_{e}\\right)$ and $\\mu \\equiv \\mu_{0}\\left(1+\\chi_{m}\\right)$ D is called the electric \"displacement\"; that's why the second term in the Ampère/Maxwelf equation (iv) is called the displacement current,\\\\\nIn integral form Maxwell's equations in matter can be written as\\\\\n\\begin{align*}\n\\text{(i)}\\hspace{0.5cm}\\oint_{s}D\\cdot da&=\\theta_{fenc}\\\\\n\\text{(ii)}\\hspace{0.5cm}\\oint_{s}B\\cdot da&=0\\\\\n\\text{(iii)}\\hspace{0.5cm}\\oint_{p}E\\cdot dl&=\\frac{-d}{dt}\\int_{s} B\\cdot da\\\\\n\\text{(iv)}\\hspace{0.5cm}\\oint_{p}H\\cdot dl&=I_{end}+\\frac{d}{dt}\\int_{s} D\\cdot da\\\\\n\\end{align*}\n$P$ is the closed loop enclosing the surface $S$\n\\section{Boundary conditions}\nIn general the fields \\textbf{E,B,D,} and \\textbf{H} will be discontineous at a boundary between two different media or at surface that carries charge density $\\sigma$ or current density \\textbf{K}. The explicit form of the discontinities can be deduced from Maxwell's equations,in their integral form\\\\\\\\\n$\\left. \\right. $\\hspace{0.28cm} (i) $\\oint_s \\mathbf{D} \\cdot d \\mathbf{a}=Q_{f_{\\mathrm{enc}}}$\\\\\\\\\n$\\left. \\right. $\\hspace{0.3cm}(ii) $\\oint_s \\mathbf{B} \\cdot d \\mathbf{a}=0$\\\\\\\\\n$\\left.\\begin{array}{ll}\\text { (iii) } \\oint_l \\mathbf{E} \\cdot d \\mathbf{l} & =-\\frac{d}{d t} \\int_s \\mathbf{B} \\cdot d \\mathbf{a} \\\\ \\\\\n\\text { (iv) } \\oint_l \\mathbf{H} \\cdot d \\mathbf{l} & =I_{f_{\\text {enc }}}+\\frac{d}{d t} \\int_s \\mathbf{D} \\cdot d \\mathbf{a}\\end{array}\\right\\} \\begin{aligned}&\\text { for any surface } s \\\\&\\text { bounded by the } \\\\&\\text { closed loop } l .\\end{aligned}$\\\\\\\\\nApplying (i) to a tiny, wafer-thin Gaussian pillbox extending just slightly into the material on either side of the boundary, we obtain \\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=7cm]{diagram-20220103(8)-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n$$\\mathbf{D}_{1} \\cdot \\mathbf{a}-\\mathbf{D}_{2} \\cdot \\mathbf{a}=\\sigma_{f} a$$\nThus ,the component of D that is perperdicular to the interface is discontineous in the amount \\\\\n$$D_{1}^{\\perp}-D_{2}^{\\perp}=\\sigma_{f}$$\nIdentical reasoning,applied to equation(ii) yields\\\\\n$$B_1^{\\perp}-B_2^{\\perp}=0$$\nconsider equation(iii) a very thin Amperian loop straddling the surface gives\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=7cm]{diagram-20220103(9)-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n$$E_1\\cdot L-E_2\\cdot L=-\\frac{d}{dt} \\int_{s} B\\cdot da$$\nBut in the limit as the width of the loop goes to zero ,the flux vanishes.Therefore\\\\\n$$E_1^{\\parallel}-E_2^{\\parallel}=0$$\nThat is the comonents of E parallel to the interface are contineous across the boundary.\\\\\nequation (iv)  implies \\\\\n$$H_1 \\cdot L-H_2\\cdot L=I_{f_{enc}}$$\nWhere $I_{f_{enc}}$ is the free current passing through the Amperian loop.No volume current density will contribute but a surface current can . In fact if $\\hat{n}$ is a unit vector perpendicular to the interface so that $(\\hat{n}\\times L)$ is normal to the Amperian loop then,\n$$I_{f_{enc}}=K_f \\cdot (\\hat{n}\\times L)=(K_f\\times \\hat{n})\\cdot L$$\nAnd hence $$H_1^{\\parallel}-H_2^{\\parallel}=K_f\\times \\hat{n}$$\nSo the parallel components  H are discontinuous by an amount proportional to the free surface charge density.\\\\\nIn the case of linear media they can be expressed in terms of E and B alone \n\n\\begin{enumerate}[label=(\\roman*)]\n\t\\item $\\epsilon_{1} \\mathbf{E}_{1}^{\\perp}-\\epsilon_{2} \\mathbf{E}_{2}^{\\perp}=\\sigma_{f}$\n\t\\item  $\\mathbf{E}_{1}^{\\|}-\\mathbf{E}_{2}^{\\|}=0$\n\t\\item $\\mathbf{B}_{1}^{\\perp}-\\mathbf{B}_{2}^{\\perp}=0$\n\t\\item $\\frac{1}{\\mu_{1}} \\mathbf{B}_{1}^{\\|}-\\frac{1}{\\mu_{2}} \\mathbf{B}_{2}^{\\|}=\\mathbf{K}_{f} \\times \\hat{\\mathbf{n}}$\n\\end{enumerate}\n\nIn particular, if there is no free charge or free current at the interface, then \n\\begin{enumerate}[label=(\\roman*)]\n\t\\item $\\epsilon_{1} \\mathbf{E}_{1}^{\\perp}-\\epsilon_{2} \\mathbf{E}_{2}^{\\perp}=0$\n\t\\item $\\mathbf{E}_{1}^{\\|}-\\mathbf{E}_{2}^{\\|}=0$\n\t\\item $\\mathbf{B}_{1}^{\\perp}-\\mathbf{B}_{2}^{\\perp}=0$\n\t\\item $\\frac{1}{\\mu_{1}} \\mathbf{B}_{1}^{\\|}-\\frac{1}{\\mu_{2}} \\mathbf{B}_{2}^{\\|}=0$\n\\end{enumerate}\n\n\\newpage\n\\begin{abox}\n\tPractise Set-1\n\\end{abox}\n\\begin{enumerate}\n\t\\item The $x$ - and $z$-components of a static magnetic field in a region are $B_{x}=B_{0}\\left(x^{2}-y^{2}\\right)$ and $B_{z}=0$, respectively. Which of the following solutions for its $y$-component is consistent with the Maxwell equations?\n\t{\\exyear{ NET/JRF-(JUNE-2016)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$B_{y}=B_{0} x y$\n\t\t\\task[\\textbf{b.}]$B_{y}=-2 B_{0} x y$\n\t\t\\task[\\textbf{c.}] $B_{y}=-B_{0}\\left(x^{2}-y^{2}\\right)$\n\t\t\\task[\\textbf{d.}]  $B_{y}=B_{0}\\left(\\frac{1}{3} x^{3}-x y^{2}\\right)$\n\t\\end{tasks}\n\t\\item A current $i_{p}$ flows through the primary coil of a transformer. The graph of $i_{p}(t)$ as a function of time $t$ is shown in the figure below.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=4cm]{diagram-20211011(27)-crop}\n\t\\end{figure}\n\tWhich of the following graphs represents the current $i_{S}$ in the secondary coil?\n\t{\\exyear{NET/JRF(JUNE-2014)}}\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=4cm]{diagram-20211011(28)-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=4cm]{diagram-20211011(29)-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=4cm]{diagram-20211011(30)-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=4cm]{diagram-20211011(31)-crop}\n\t\t\\end{figure}\n\t\\end{tasks}\n\t\\item A circular conducting wire loop is placed close to a solenoid as shown in the figure bellow. Also shown is the current through the solenoid as a function of solenoid as a function of time.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=9cm]{diagram-20211028(5)-crop}\n\t\\end{figure}\n\tThe magnitude $|i(t)|$ of the induced current in the wire loop, as a function of time $t$, is best represented as.\n\t{\\exyear{NET/JRF(DEC-2019)}}\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=5cm]{diagram-20211028(6)-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=5cm]{diagram-20211028(7)-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=5cm]{diagram-20211028(8)-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=5cm]{diagram-20211028(9)-crop}\n\t\t\\end{figure}\n\t\\end{tasks}\n\t\\item A horizontal metal disc rotates about the vertical axis in a uniform magnetic field pointing up as shown in the figure. A circuit is made by connecting one end A of a resistor to the centre of the disc and the other end $B$ to its edge through a sliding contact. The current that flows through the resistor is\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{diagram-20211011(22)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] Zero\n\t\t\\task[\\textbf{B.}] $D C$ from $A$ to $B$\n\t\t\\task[\\textbf{C.}] $D C$ from $B$ to $A$\n\t\t\\task[\\textbf{D.}] $A C$,\n\t\\end{tasks}\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/JRF(DEC-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\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] Depends on $\\omega, B, r$ and $\\rho$\n\t\t\\task[\\textbf{B.}] Depends on $\\omega, B$ and $r$ but not on $\\rho$\n\t\t\\task[\\textbf{C.}]  Is zero because the flux through the loop is not changing\n\t\t\\task[\\textbf{D.}] Is zero because a current the flows in the direction of $B$\n\t\\end{tasks}\t\n\t\\item A uniform magnetic field in the positive $z$-direction passes through a circular wire loop of radius $1 \\mathrm{~cm}$ and resistance $1 \\Omega$ lying in the $x y$-plane. The field strength is reduced from 10 tesla to 9 tesla in $1 s$. The charge transferred across any point in the wire is approximately\n\t{\\exyear{ NET/JRF-(JUNE-2015)\t}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $3.1 \\times 10^{-4}$ coulomb\n\t\t\\task[\\textbf{b.}]$3.4 \\times 10^{-4}$ coulomb\n\t\t\\task[\\textbf{c.}]$4.2 \\times 10^{-4}$ coulomb\n\t\t\\task[\\textbf{d.}] $5.2 \\times 10^{-4}$ coulomb\n\t\\end{tasks}\t\n\t\\item A magnetic field $B$ is $B \\hat{z}$ in the region $x>0$ and zero elsewhere. A rectangular loop, in the $x y$-plane, of sides $l$ (along the $x$-direction) and $h$ (along the $y$-direction) is inserted into the $x>0$ region from the $x<0$ region at constant velocity $v=v \\hat{x}$. Which of the following values of $l$ and $h$ will generate the largest EMF?\n\t{\\exyear{ NET/JRF-(JUNE-2016)\t}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $l=8, h=3$\n\t\t\\task[\\textbf{b.}]$l=4, h=6$\n\t\t\\task[\\textbf{c.}]$l=6, h=4$\n\t\t\\task[\\textbf{d.}]  $l=12, h=2$\n\t\\end{tasks}\t\n\t\\item Consider a solenoid of radius $R$ with $n$ turns per unit length, in which a time dependent current $I=I_{0} \\sin \\omega t$ (where $\\omega R / c<<1$ ) flows. The magnitude of the electric field at a perpendicular distance $r<R$ from the axis of symmetry of the solenoid, is\n\t{\\exyear{NET/JRF-(DEC-2011)\t}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]$\\frac{1}{2 r} \\omega \\mu_{0} n I_{0} R^{2} \\cos \\omega t$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{2} \\omega \\mu_{0} n I_{0} r \\sin \\omega t$\n\t\t\\task[\\textbf{d.}]  $\\frac{1}{2} \\omega \\mu_{0} n I_{0} r \\cos \\omega t$\n\t\\end{tasks}\t\n\t\\item A parallel plate capacitor is formed by two circular conducting plates of radius a separated by a distance $d$, where $d \\ll a$. It is being slowly charged by a current that is nearly constant. At an instant when the current is $I$, the magnetic induction between the plates at a distance $\\frac{a}{2}$ from the centre of the plate, is\n\t{\\exyear{ NET/JRF-(DEC-2016)}}\t\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\mu_{0} I}{\\pi a}$\n\t\t\\task[\\textbf{b.}]$\\frac{\\mu_{0} I}{2 \\pi a}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\mu_{0} I}{a}$\n\t\t\\task[\\textbf{d.}]  $\\frac{\\mu_{0} I}{4 \\pi a}$\n\t\\end{tasks}\t\n\t\\item Suppose the $y z$-plane forms a chargeless boundary between two media of permittivities $\\epsilon_{\\text {left }}$ and $\\epsilon_{\\text {right }}$ where $\\epsilon_{\\text {left }}: \\epsilon_{\\text {right }}=1: 2$, if the uniform electric field on the left is $\\vec{E}_{\\text {left }}=c(\\hat{i}+\\hat{j}+\\hat{k})$ (where $c$ is a constant), then the electric field on the right $\\vec{E}_{\\text {right }}$ is\n\t{\\exyear{NET/JRF(JUNE-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}]  $c(2 \\hat{i}+\\hat{j}+\\hat{k})$\n\t\t\\task[\\textbf{B.}] $c(\\hat{i}+2 \\hat{j}+2 \\hat{k})$\n\t\t\\task[\\textbf{C.}] $c\\left(\\frac{1}{2} \\hat{i}+\\hat{j}+\\hat{k}\\right)$\n\t\t\\task[\\textbf{D.}] $c\\left(\\hat{i}+\\frac{1}{2} \\hat{j}+\\frac{1}{2} \\hat{k}\\right)$\n\t\\end{tasks}\n\t\\item  The half space region $x>0$ and $x<0$ are filled with dielectric media of dielectric constants $\\varepsilon_{1}$ and $\\varepsilon_{2}$ respectively. There is a uniform electric field in each part. In the right half, the electric field makes an angle $\\theta_{1}$ to the interface. The corresponding angle $\\theta_{2}$ in the left half satisfies\n\t{{\\exyear{NET/JRF(JUNE-2016)}}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{diagram-20211011(41)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\varepsilon_{1} \\sin \\theta_{2}=\\varepsilon_{2} \\sin \\theta_{1}$\n\t\t\\task[\\textbf{B.}] $\\varepsilon_{1} \\tan \\theta_{2}=\\varepsilon_{2} \\tan \\theta_{1}$\n\t\t\\task[\\textbf{C.}] $\\varepsilon_{1} \\tan \\theta_{1}=\\varepsilon_{2} \\tan \\theta_{2}$\n\t\t\\task[\\textbf{D.}] $\\varepsilon_{1} \\sin \\theta_{1}=\\varepsilon_{2} \\sin \\theta_{2}$\n\t\\end{tasks}\n\t\\item Which of the following is not a correct boundary condition at an interface between two homogeneous dielectric media? (In the following $\\hat{n}$is a unit vector normal to the  interface, $\\sigma$ and $\\vec{j}_s$, are the surface charge and current densities, respectively.)\n\t{\\exyear{NET/JRF(JUNE-2019)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\hat{n} \\times\\left(\\vec{D}_{1}-\\vec{D}_{2}\\right)=0$\n\t\t\\task[\\textbf{B.}] $\\hat{n} \\times\\left(\\vec{H}_{1}-\\vec{H}_{2}\\right)=\\vec{j}_{s}$\n\t\t\\task[\\textbf{C.}] $\\hat{n} \\cdot\\left(\\vec{D}_{1}-\\vec{D}_{2}\\right)=\\sigma$\n\t\t\\task[\\textbf{D.}] $\\hat{n} \\cdot\\left(\\vec{B}_{1}-\\vec{B}_{2}\\right)=0$\n\t\\end{tasks}\n\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b} &2&\\textbf{c}\\\\\\hline \n\t\t3&\\textbf{d} &4&\\textbf{c} \\\\\\hline\n\t\t5&\\textbf{b} &6&\\textbf{a} \\\\\\hline\n\t\t7&\\textbf{b}&8&\\textbf{d}\\\\\\hline\n\t\t9&\\textbf{d}&10&\\textbf{c}\\\\\\hline\n\t\t11&\\textbf{c} &12&\\textbf{a}\\\\\\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}\n\t\\item Two rails of a railroad track are insulated from each other and from the ground, and are connected by a millivoltmeter. What is the reading of the millivoltmeter when a train travels at the speed $90 \\mathrm{~km} / \\mathrm{hr}$ down the track? Assume that the vertical component of the earth's magnetic field is $0.2$ gauss and that the tracks are separated by two meters. Use 1 gauss $=10^{-4}$ Tesla $=10^{-4} \\mathrm{~V} \\cdot \\mathrm{sec} / \\mathrm{m}^{2}$\n\t{\\exyear{ JEST-2020}}\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]10\n\t\t\\task[\\textbf{b.}]1\n\t\t\\task[\\textbf{c.}]$0.2$\n\t\t\\task[\\textbf{d.}]180 \n\t\\end{tasks}\n\\item \tWhich of the following expressions represents an electric field due to a time varying magnetic field?\n\t{\\exyear{ JEST-2015}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$K(x \\hat{x}+y \\hat{y}+z \\hat{z})$\n\t\\task[\\textbf{b.}] $K(x \\hat{x}+y \\hat{y}-z \\hat{z})$\n\t\\task[\\textbf{c.}]$K(x \\hat{x}-y \\hat{y})$\n\t\\task[\\textbf{d.}]$K(y \\hat{y}-x \\hat{y}+2 z \\hat{z})$ \n\\end{tasks}\t\n\\item Two parallel rails of a railroad track are insulated from each other and from the ground. The distance between the rails is 1 meter. A voltmeter is electrically connected between the rails. Assume the vertical component of the earth's magnetic field to the $0.2$ gauss. What is the voltage developed between the rails when a train travels at a speed of $180 \\mathrm{~km} / \\mathrm{h}$ along the track? Give the answer in milli-volts.\n\t{\\exyear{ JEST-2018}}\n\\item \tA very long solenoid (axis along $z$ direction) of $n$ turns per unit length carries a current which increases linearly with time, $i=K t$. What is the magnetic field inside the solenoid at a given time $t$ ?\n\t{\\exyear{ JEST-2019}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\vec{B}=\\mu_{0} n K t \\hat{z}$\n\t\\task[\\textbf{b.}]$\\vec{B}=\\mu_{0} n K \\hat{z}$\n\t\\task[\\textbf{c.}]$\\vec{B}=\\mu_{0} n K t(\\hat{x}+\\hat{y})$\n\t\\task[\\textbf{d.}] $\\vec{B}=\\mu_{0} c n K t \\hat{z}$\n\\end{tasks}\t\n\\item \tA circular metal loop of radius $a=1 \\mathrm{~m}$ spins with a constant angular velocity $\\omega=20 \\pi \\mathrm{rad} / \\mathrm{s}$ in a magnetic field $B=3$ Tesla, as shown in the figure. The resistance of the loop is 10 ohms. Let $P$ be the power dissipated in one complete cycle. What is the value of $\\frac{P}{\\pi^{4}}$ in Watts?\n\t\t{\\exyear{ JEST-2019}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=2.8cm]{ED-20}\n\t\\end{figure}\n\\item Self inductance per unit length of a long solenoid of radius $R$ with $n$ turns per unit length is:\n\t{\\exyear{ JEST-2016}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\mu_{0} \\pi R^{2} n^{2}$\n\t\\task[\\textbf{b.}]$2 \\mu_{0} \\pi R^{2} n$\n\t\\task[\\textbf{c.}]$2 \\mu_{0} \\pi R^{2} n^{2}$\n\t\\task[\\textbf{d.}] $\\mu_{0} \\pi R^{2} n$\n\\end{tasks}\t\n\\item The $x-y$ plane is the boundary between free space and a magnetic material with relative permeability $\\mu_{r}$. The magnetic field in the free space is $B_{x} \\hat{i}+B_{z} \\hat{k}$. The magnetic field in the magnetic material is\n\t{\\exyear{ GATE- 2016}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$B_{x} \\hat{i}+B_{z} \\hat{k}$\n\t\\task[\\textbf{b.}]$B_{x} \\hat{i}+\\mu_{r} B_{z} \\hat{k}$\n\t\\task[\\textbf{c.}] $\\frac{1}{\\mu_{r}} B_{x} \\hat{i}+B_{z} \\hat{k}$\n\t\\task[\\textbf{d.}] $\\mu_{r} B_{x} \\hat{i}+B_{z} \\hat{k}$\n\\end{tasks}\t\n\\item \tAt a surface current, which one of the magnetostatic boundary condition is $\\underline{\\text { NOT }}$ CORRECT?\n{\\exyear{ GATE- 2013}}\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]Normal component of the magnetic field is continuous.\n\t\t\\task[\\textbf{b.}]Normal component of the magnetic vector potential is continuous.\n\t\t\\task[\\textbf{c.}] Tangential component of the magnetic vector potential is continuous.\n\t\t\\task[\\textbf{d.}] Tangential component of the magnetic vector potential is not continuous.\n\t\\end{tasks}\n\\item A circular loop made of a thin wire has radius $2 \\mathrm{~cm}$ and resistance $2 \\Omega$. It is placed perpendicular to a uniform magnetic field of magnitude $\\left|\\vec{B}_{0}\\right|=0.01$ Tesla. At time $t=0$ the field starts decaying as $\\vec{B}=\\vec{B}_{0} e^{-t / t_{0}}$, where $t_{0}=1 s$. The total charge that passes through a cross section of the wire during the decay is $Q$. The value of $Q$ in $\\mu C$ (rounded off to two decimal places) is\n{\\exyear{ GATE- 2019}}\n\\item A long solenoid is embedded in a conducting medium and is insulated from the medium. If the current through the solenoid is increased at a constant rate, the induced current in the medium as a function of the radial distance $r$ from the axis of the solenoid is proportional to\n{\\exyear{GATE- 2015}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}] $r^{2}$ inside the solenoid and $\\frac{1}{r}$ outside\n\t\\task[\\textbf{b.}]$r$ inside the solenoid and $\\frac{1}{r^{2}}$ outside\n\t\\task[\\textbf{c.}]$r^{2}$ inside the solenoid and $\\frac{1}{r^{2}}$ outside\n\t\\task[\\textbf{d.}] $r$ inside the solenoid and $\\frac{1}{r}$ outside\n\\end{tasks}\n\\item Consider an infinitely long solenoid with $N$ turns per unit length, radius $R$ and carrying a current $I(t)=\\alpha \\cos \\omega t$, where $\\alpha$ is a constant and $\\omega$ is the angular frequency. The magnitude of electric field at the surface of the solenoid is\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{1}{2} \\mu_{0} N R \\omega \\alpha \\sin \\omega t$\n\t\\task[\\textbf{b.}]$\\frac{1}{2} \\mu_{0} \\omega N R \\cos \\omega t$\n\t\\task[\\textbf{c.}]$\\mu_{0} N R \\omega \\alpha \\sin \\omega t$\n\t\\task[\\textbf{d.}] $\\mu_{0} \\omega N R \\cos \\omega t$\n\\end{tasks}\n\\item A medium $\\left(\\varepsilon_{r}>1, \\mu_{r}=1, \\sigma>0\\right)$ is semi-transparent to an electromagnetic wave when\n{\\exyear{ GATE- 2020}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]Conduction current $\\gg>$ Displacement current\n\t\\task[\\textbf{b.}]Conduction current $<<$ Displacement current\n\t\\task[\\textbf{c.}]Conduction current $=$ Displacement current\n\t\\task[\\textbf{d.}] Both Conduction current and Displacement current are zero\n\\end{tasks}\n\\item A sinusoidal voltage of the form $V(t)=V_{0} \\cos (\\omega t)$ is applied across a parallel plate capacitor placed in vacuum. Ignoring the edge effects, the induced emf within the region between the capacitor plates can be expressed as a power series in $\\omega$. The lowest nonvanishing exponent in $\\omega$ is -----------\n{\\exyear{ GATE- 2020}}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b} &2&\\textbf{d}\\\\\\hline \n\t\t3&\\textbf{1.0} &4&\\textbf{a} \\\\\\hline\n\t\t5&\\textbf{18} &6&\\textbf{a} \\\\\\hline\n\t\t7&\\textbf{d}&8&\\textbf{d}\\\\\\hline\n\t\t9&\\textbf{6.28}&10&\\textbf{d}\\\\\\hline\n\t\t11&\\textbf{a} &12&\\textbf{b}\\\\\\hline\n\t\t13&\\textbf{2}&14&\\textbf{}\\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\end{enumerate}\n\n\n\n\n\n\n\n\\newpage\n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}\n\t\\item \tThe $x$ and $z$-components of a static magnetic field in a region are $B_{x}=B_{0}\\left(x^{2}-y^{2}\\right)$ and $B_{z}=0$, respectively. Find one of the possible solution for its $y$-component which is consistent with the Maxwell equations?\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t B_{x}&=B_{0}\\left(x^{2}-y^{2}\\right), B_{z}=0\\\\\n\t\t\\because \\vec{\\nabla} \\cdot \\vec{B}&=0 \\Rightarrow \\frac{\\partial B_{x}}{\\partial x}+\\frac{\\partial B_{y}}{\\partial y}+\\frac{\\partial B_{z}}{\\partial z}=0 \\Rightarrow \\frac{\\partial B_{y}}{\\partial y}\\\\&=-\\frac{\\partial B_{x}}{\\partial x}=-2 B_{0} x \\Rightarrow B_{y}=-2 B_{0} x y\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \tWhich of the following expressions represent an electric field due to a time varying magnetic field?\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$K(x \\hat{x}+\\hat{y} \\hat{y}+z \\hat{z})$\n\t\t\\task[\\textbf{b.}]$K(x \\hat{x}+y \\hat{y}-z \\hat{z})$\n\t\t\\task[\\textbf{c.}] $K(x \\hat{x}-y \\hat{y})$\n\t\t\\task[\\textbf{d.}] $K(y \\hat{y}-x \\hat{y}+2 z \\hat{z})$\n\t\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { For time varying fields } &\\vec{\\nabla} \\times \\vec{E} \\neq 0\\\\\n\t\\text { (a) } \\vec{\\nabla} \\times \\vec{E}=K\\left|\\begin{array}{ccc}\n\t\\hat{x} & \\hat{y} & \\hat{z} \\\\\n\tx & \\partial / \\partial y & \\partial / \\partial z \\\\\n\ty & z\n\t\\end{array}\\right|&=\\hat{x}\\left(\\frac{\\partial z}{\\partial y}-\\frac{\\partial y}{\\partial z}\\right)+\\hat{y}\\left(\\frac{\\partial x}{\\partial z}-\\frac{\\partial z}{\\partial x}\\right)+\\hat{z}\\left(\\frac{\\partial y}{\\partial x}-\\frac{\\partial x}{\\partial y}\\right)=0\\\\\n\t\\text { (b) } \\vec{\\nabla} \\times \\vec{E}=K\\left|\\begin{array}{ccc}\n\t\\hat{x} & \\hat{y} & \\hat{z} \\\\\n\t\\partial / \\partial x & \\partial / \\partial y & \\partial / \\partial z \\\\\n\tx & y & -z\n\t\\end{array}\\right|&=\\hat{x}\\left(-\\frac{\\partial z}{\\partial y}-\\frac{\\partial y}{\\partial z}\\right)+\\hat{y}\\left(\\frac{\\partial x}{\\partial z}+\\frac{\\partial z}{\\partial x}\\right)+\\hat{z}\\left(\\frac{\\partial y}{\\partial x}-\\frac{\\partial x}{\\partial y}\\right)=0\\\\\n\t\\text { (c) } \\vec{\\nabla} \\times \\vec{E}=K\\left|\\begin{array}{ccc}\n\t\\hat{x} & \\hat{y} & \\hat{z} \\\\\n\t\\partial / \\partial x & \\partial / \\partial y & \\partial / \\partial z \\\\\n\tx & -y & 0\n\t\\end{array}\\right|&=\\hat{x}\\left(0+\\frac{\\partial y}{\\partial z}\\right)+\\hat{y}\\left(\\frac{\\partial x}{\\partial z}-0\\right)+\\hat{z}\\left(-\\frac{\\partial y}{\\partial x}-\\frac{\\partial x}{\\partial y}\\right)=0\\\\\n\t\\text { (d) } \\vec{\\nabla} \\times \\vec{E}=K\\left|\\begin{array}{ccc}\n\t\\hat{x} & \\hat{y} & \\hat{z} \\\\\n\t\\partial / \\partial x & \\partial / \\partial y & \\partial / \\partial z \\\\\n\ty & -x & 2 z\n\t\\end{array}\\right|&=\\hat{x}\\left(\\frac{\\partial(2 z)}{\\partial y}+\\frac{\\partial x}{\\partial z}\\right)+\\hat{y}\\left(-\\frac{\\partial x}{\\partial z}-\\frac{\\partial(2 z)}{\\partial x}\\right)+\\hat{z}\\left(\\frac{\\partial y}{\\partial x}-\\frac{\\partial y}{\\partial y}\\right)\\\\\n\t\\Rightarrow \\vec{\\nabla} \\times \\vec{E}&=-\\hat{z} \\neq 0\n\t\\end{align*}\n\\end{answer}\n\t\\item A uniform magnetic field in the positive $z$-direction passes through a circular wire loop of radius $1 \\mathrm{~cm}$ and resistance $3.14 \\Omega$ lying in the $x y$-plane. The field strength is reduced from 10 tesla to 9 tesla in $1 s$. Find the charge transferred across any point in the wire. \n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\varepsilon&=-\\frac{d \\phi}{d t} \\Rightarrow I=\\frac{d q}{d t}=\\frac{\\varepsilon}{R}=-\\frac{1}{R} \\frac{d \\phi}{d t}\\\\\n\t\t\\Rightarrow d q&=-\\frac{A}{R} d B=\\frac{-\\pi r^{2}}{R} d B\\\\\n\t\t\\Rightarrow d q&=\\frac{-3.14 \\times\\left(10^{-2}\\right)^{2}}{3.14} \\times 1=10^{-4} \\text { coulomb }\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A small loop of wire of area $A=0.01 \\mathrm{~m}^{2}, N=40$ turns and resistance $R=10 \\Omega$ is initially kept in a uniform magnetic field $B$ in such a way that the field is normal to the loop. When it is pulled out of the magnetic field, a total charge of $Q=2 \\times 10^{-5} C$ flows through the coil. Find the magnitude of the field $B$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { Magnetic flux through the loop }& \\phi=N B A\\\\\n\t\t\\text { Induced e.m.f } \\varepsilon&=-\\frac{d \\phi}{d t} \\text { and induced current } i\\\\&=-\\frac{1}{R} \\frac{d \\phi}{d t}=\\frac{d Q}{d t} \\Rightarrow-\\frac{1}{R} d \\phi=d Q \\text {. }\\\\\n\t\t\\text { Thus } \\frac{1}{10} \\times(40 \\times B \\times 0.01)&=2 \\times 10^{-5} \\Rightarrow B=5 \\times 10^{-4} T\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A rectangular loop of dimension $L$ and width $w$ moves with a constant velocity $v$ away from an infinitely long straight wire carrying a current $I$ in the plane of the loop as shown in the figure below. Let $R$ be the resistance of the loop. Show that the current in the Toop at the instant the near side is at a distance $r$ from the wire is $\\frac{\\mu_{0} I L}{2 \\pi R} \\frac{w v}{r[r+w]}$.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=4cm]{Ass-05}\n\t\\end{figure}\n\\begin{answer}\n\t\\begin{align*}\n\t\\phi_{B}&=\\int_{S} \\vec{B} \\cdot d \\vec{a}=\\int_{r}^{w} \\frac{\\mu_{0} I}{2 \\pi r} L d r=\\frac{\\mu_{0} I L}{2 \\pi R} \\ln \\left(\\frac{r+w}{r}\\right)\\\\\n\t\\Rightarrow I&=-\\frac{1}{R} \\frac{d \\phi_{B}}{d t}=\\frac{\\mu_{0} I L}{2 \\pi R}\\left[\\frac{1}{r+w}-\\frac{1}{r}\\right] \\frac{d r}{d t}=\\frac{\\mu_{0} I L w v}{2 \\pi R r(r+w)}\n\t\\end{align*}\n\\end{answer}\n\t\\item A square loop of side $L$ and mass $M$ is made of a wire of cross-sectional area $A$ and resistance $R$ The loop. moving with a constant velocity $v_{v} \\hat{i}$ in the horizontal xy-plane, enters a region $0 \\leq x \\leq 2 L$ having constant magnetic field $B \\hat{k}$\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=8cm]{Ass-01}\n\t\\end{figure}\n\tFind an expression for the $x$-component of the force $\\vec{F}$ acting on the loop in terms of its velocity $\\vec{v}(t), B, L$ and $R$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text { Initial flux } \\phi_{0}&=B L x\\\\\n\t\t\\text { Flux after time } d t, \\phi&=B L(x+d x)\\\\\n\t\t\\text { Change in flux } d \\phi&=\\phi-\\phi_{0}=B L d x \\text {. }\\\\\n\t\t\\text { Induced e.m.f. } \\varepsilon&=-\\frac{d \\phi}{d t}=-B L \\frac{d x}{d t}=-B L v_{0} \\text {. }\\\\\n\t\t\\text { Induced current } I_{i n d}&=-\\frac{B L v_{0}}{R} \\text { (in clockwise direction } a b c d a \\text { ) }\\\\\n\t\t\\text { Force on element } b c \\vec{F}&=I_{\\text {ind }} \\int(d \\vec{l} \\times \\vec{B})=-\\frac{B^{2} L^{2} v_{0}}{R} \\hat{x}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A coil of 15 turns, each of radius 1 centimeter, is rotating at a constant angular velocity $\\omega=300$ radians per second in a uniform magnetic field of $0.5$ tesla, as shown in the figure. Assume at time $t=0$ that the normal $\\hat{n}$ to the coil plane is along the $y$-direction and that the self-inductance of the coil can be neglected. If the coil resistance is 9 ohms, what will be the magnitude of the induced current in milliamperes?\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.8cm,width=4.3cm]{Ass-02}\n\t\\end{figure}\n\\begin{answer}\n\tThe voltage induced is equal to the change in magnetic flux\n\t\\begin{align*}\n\t\\varepsilon=-\\frac{\\partial \\Phi}{\\partial t}, \\text { where } \\Phi=\\int \\vec{B} \\cdot d \\vec{A}\n\t\\intertext{Noting the initial condition $(\\Phi(t=0)=0)$, since the field and area normal are perpendicular). One finds that $\\Phi=\\int \\vec{B} \\cdot d \\vec{A}=B \\cos (90+\\omega t) \\pi r^{2}=(-B \\sin \\omega t) \\pi r^{2}$.\n\t\tThus, $|d \\Phi / d t|=\\omega B \\cos (\\omega t) \\pi r^{2}$.}\n\t\\intertext{Now, to find the current, one uses Ohm's Law in Faraday's Law to get}\n\tI=\\frac{N \\dot{\\Phi}}{R}&=\\frac{N B \\omega}{R} \\cos (\\omega t) \\pi r^{2} \\text {, where } N \\text { is the number of turns. }\\\\\n\t\\text { Thus, } I=\\frac{15 \\times 0.5 \\times 300}{9} \\cos (\\omega t) \\pi(1 / 100)^{2}&=250 \\times 10^{-4} \\pi \\cos (\\omega t) \\text { Ampere }I=25 \\pi \\cos (\\omega t) \\mathrm{mA}\n\t\\end{align*}\n\\end{answer}\n\t\\item The circuit shown below is in a uniform magnetic lield that is into the page and is decreasing in magnitude at the rate of 150 Tesla/sec. Then tind the ammeter reading.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{Ass-03}\n\t\\end{figure}\n\\begin{answer}\n From Ohm's Law $V-\\varepsilon=I R$, one can obtain the current. (Note that $V=5.0 \\mathrm{~V}$ is the voltage of the battery. The voltage induced acts to oppose this emf from the battery).\n\t\\begin{align*}\n\t\\text { The problem gives } \\frac{d B}{d t}&=150 T / \\mathrm{s} \\text {. The area is just } 0.01 \\mathrm{~m}^{2} \\text {. }\\\\\n\t\\text { Thus, the induced emf is, } \\varepsilon&=\\frac{d B}{d t} \\quad A=150 \\times 0.01=1.5\\\\\n\t\\text { Thus, } V-\\varepsilon&=3.5=I R \\Rightarrow I=0.35 A \\text {, since } R=10 \\Omega \\text {. }\n\t\\end{align*}\n\\end{answer}\n\t\\item A parallel plate air-gap capacitor is made up of two plates of area $10 \\mathrm{~cm}^{2}$ each kept at a distance of $0.88 \\mathrm{~mm}$. A sine wave of amplitude $10 \\mathrm{~V}$ and frequency $50 \\mathrm{~Hz}$ is applied across the capacitor as shown in the figure.\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}]Find the amplitude of the displacement current density between the plates.\n\t\t\\task[\\textbf{b.}]\n\t\t Find the r.m.s value of the displacement current density between the plates.\n\t\t\\task[\\textbf{c.}]Find the average value of the displacement current density (in $\\mathrm{mA} / \\mathrm{m}^{2}$ ) between the plates.\n\t\\end{tasks}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=2.5cm,width=4cm]{Ass-04}\n\t\\end{figure}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { Displacement current density } J_{d}&=\\varepsilon_{0} \\frac{\\partial E}{\\partial t}=\\frac{\\varepsilon_{0}}{d} \\frac{\\partial V(t)}{\\partial t}=-\\frac{\\varepsilon_{0} \\omega V_{0} \\sin \\omega t}{d}\\\\\n\t\\text { (a) Amplitude of the displacement current density } J_{0 d}&=\\frac{\\varepsilon_{0} \\omega V_{0}}{d}=\\frac{2 \\pi \\varepsilon_{0} f V_{0}}{d}\\\\\n\t\\Rightarrow J_{0 d}=4 \\pi \\varepsilon_{0} \\frac{f V_{0}}{2 d}&=\\frac{1}{9 \\times 10^{9}} \\frac{50 \\times 10}{2 \\times 88 \\times 10^{-5}}=0.03 \\mathrm{~mA} / \\mathrm{m}^{2}\n\t\\intertext{(b) The r.m.s value of the displacement current density is }\n\tJ_{d, r m s}=\\frac{\\varepsilon_{0} \\omega V_{0}}{d \\sqrt{2}}=\\frac{2 \\pi \\varepsilon_{0} f V_{0}}{d \\sqrt{2}}&=\\frac{0.03}{\\sqrt{2}}=0.022 \\mathrm{~mA} / \\mathrm{m}^{2}\n\t\\intertext{(c) The average value of the displacement current density is zero. }\n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "394a7803ce5f19cf0c504d78046a9daf7181ac89", "size": 40518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Electrodynamics- CSIR/chapter/Maxwell's Equations.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Electrodynamics- CSIR/chapter/Maxwell's Equations.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Electrodynamics- CSIR/chapter/Maxwell's Equations.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.7075471698, "max_line_length": 1056, "alphanum_fraction": 0.6696776741, "num_tokens": 14830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.6502622788137009}}
{"text": "% !TEX root =../thesis-letomes.tex\n\n\\chapter{Physical Modelling}\nWe will model two systems:\n\\begin{enumerate}\n\t\\item 2D simulator for Earth-Moon system (cartesian coordinates, center-of-mass-centered).\n\t\\item 3D simulator for Sun-Earth-Moon system (spherical coordinates, heliocentric)\n\\end{enumerate}\n\nWe will derive equations of motion using Hamiltonian mechanics, shortly describe symplectic integrators and integrate the equations of motion using symplectic integrators to obtain numerical algorithms.\n\nFinally we will proceed to describe the complexities of Earth-Mars transfer orbits, a simplified Earth-Mars transfer orbit with patched conic approximation.\n\n\\section{Analytical Mechanics}\nNewton's 2nd Law is a very well known physical law of classical mechanics governing all bodies having mass. It can be stated \\cite{Knudsen2002}\n\\begin{align}\n    \\label{eq:newton2}\n    \\textbf{Newton's 2nd Law} \\qquad \\sum{\\vec{F}} = \\dfrac{d \\vec{p}}{dt}.\n\\end{align}\n\nwhere the left-hand side is the total force on the body and the right-hand side is the time derivative of the momentum vector defined as mass times the velocity vector \\(\\vec{p} = m \\vec{v}\\).\n\nHowever we will use the more powerful Hamiltonian formalism from the field of analytical mechanics, which is \\cite{Knudsen2002}\n\n\\begin{align}\n\\textbf{Generalized momenta} \\qquad p_i(\\vec{q},\\dot{\\vec{q}}) &= \\dfrac{\\partial L}{\\partial \\dot{q_i}}, \\qquad i = 1,\\cdots, n \\ , \\label{eq:generalized-momenta} \\\\[1cm]\n\\textbf{Hamiltonian} \\qquad H(\\vec{q}, \\vec{p}, t) &= \\sum\\limits_{i=1}^n p_i \\dot{q_i} - L \\label{eq:hamiltonian}, \\\\[1cm]\n\\textbf{Hamilton's equations} \\qquad\n\\begin{split}\n\\label{eq:hamiltons-equations}\n\\dot{q_i} &= +\\dfrac{\\partial H}{\\partial p_i} ,\n\\\\[0.2cm]\n\\dot{p_i} &= -\\dfrac{\\partial H}{\\partial q_i}.\n\\end{split}\n\\end{align}\nwhere $q_i$ and $p_i$ are the coordinates and the generalized momenta respectively, one for each degree of freedom, $i$ is the index of degrees of freedom (e.g. $x, y$ for a 2D cartesian coordinates or  $r, \\theta, \\phi$ for a 3D spherical coordinates), $n$ is the total degrees of freedom, $\\dot{q}$ is the time-derivative of $q$, $L = T - V$ is the Lagrangian with $T$ being the system's kinetic energy and $V$ it's potential energy. The Hamiltonian, \\cref{eq:hamiltonian} corresponds to the total mechanical energy of the system\\footnote{For most physical systems with some exceptions, see \\cref{ch:HvsE} for details} and \\cref{eq:hamiltons-equations} constitutes the equations of motion, and when solved give the solutions $\\vec{q}(t)$, $\\vec{p}(t)$.\n\nThe reason for using Hamiltonian's equations instead of Newton's is primarily that it yields $2 n$ first order differential equations of motion for $n$ degrees of freedom (dimensions), where as Newton's 2nd Law yields $n$ 2nd order differential equations. As it turns out, first-order differential equations are more straight forward to discretize, i.e. turn into a numerical algorithm that can be typed into a computer program.\n\nFor a guide on how to use Hamilton's formalism in practice, see \\cref{apx:using-hamilton-mechanics}.\n\n\\section{Numerical Algorithms}\nOnce we have derived our equations of motion in the form of Hamilton's equations \\cref{eq:hamiltons-equations}, we need to solve them. In 1887 and 1889, mathematicians Heinrich Bruns and Henri Poincaré showed that there is no general analytical solution to the three-body problem given by simple algebraic expressions and integrals \\cite{Gowers2008}. This means have have to solve them numerically to get time time evolution of the coordinates and velocity for particular initial conditions and delta-v impulses.\n\n\\subsection{Symplectic Integrators}\nSymplectic integrators are a class of integrators typically used in Hamiltonian systems that have the property that they preserve the energy very well over longer time. Informally, ``\\textit{a symplectic map is a map which preserves the sum of areas projected onto the set of $(p_i,q_i)$ planes. It is the generalization of an area-preserving map}'' \\cite{Weisstein}, as illustrated in \\cref{fig:symplectic-area}.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.90\\linewidth]{fig/symplectic-area.png}\n    \\caption{Area preservation in phase space (corresponding to preservation of the Hamiltonian, $H$), for various symplectic numerical methods for a pendulum (Image: \\cite{Hairer})}\n    \\label{fig:symplectic-area}\n\\end{figure}\n\nThus symplectic algorithms have been employed in fields such as molecular dynamics and astronomy. ``\\textit{Symplectic methods belong to the larger class of geometric numerical integration algorithms. These algorithms are constructed so that they preserve certain geometrical properties inherent in the system. Symplectic methods are so named because, when applied to problems in Hamiltonian mechanics, the algorithms preserve the linear symplectic structure inherent in the phase space representation of the dynamics.}'' \\cite{Donnelly2005}. We therefore only use Symplectic integrators for our equations.\n\n\n\\subsubsection{Symplectic Euler (1st Order Method)}\nIn the explicit Euler, all quantities from the Hamiltonian derivative on the right hand refer to the old time step $i$ (index 0). In the implicit, all quantities on the RHS refers to the new time step $i+1$ (index 1), which results in implicit equations that can typically only be solved numerically.\n\nThe 1st order symplectic Euler is mixture between explicit and implicit Euler \\cite{Hairer}:\n\n\\begin{equation}\n    \\begin{split} \\label{eq:symplectic-euler1}\n        \\vec{q}_1 = \\vec{q}_0 + h \\pd{H}{\\vec{p}}(q_0, p_1) \\\\\n        \\vec{p}_1 = \\vec{p}_0 - h \\pd{H}{\\vec{q}}(q_0, p_1)\n    \\end{split}\n\\end{equation}\n\nor\n\n\\begin{equation}\n    \\begin{split} \\label{eq:symplectic-euler2}\n        \\vec{q}_1 = \\vec{q}_0 + h \\pd{H}{\\vec{p}}(q_1, p_0) \\\\\n        \\vec{p}_1 = \\vec{p}_0 - h \\pd{H}{\\vec{q}}(q_1, p_0)\n    \\end{split}\n\\end{equation}\n\n\\subsubsection{Symplectic Störmer-Verlet (2nd Order Method)}\n\nThe 2nd order symplectic Störmer-Verlet (henceforth simply called Verlet) is given by \\cite{Hairer}:\n\n\\begin{equation}\n    \\begin{split} \\label{eq:symplectic-verlet1}\n        \\vec{p}_{1/2} &= \\vec{p}_0 - \\frac{h}{2} \\pd{H}{\\vec{q}}(q_0, p_{1/2}) \\\\\n        \\vec{q}_1 &= \\vec{q}_0 + \\frac{h}{2} \\left( \\pd{H}{\\vec{p}}(q_0, p_{1/2}) + \\pd{H}{\\vec{p}}(q_1, p_{1/2}) \\right) \\\\\n        \\vec{p}_{1} &= \\vec{p}_{1/2} - \\frac{h}{2} \\pd{H}{\\vec{q}}(q_1, p_{1/2}) \\\\\n    \\end{split}\n\\end{equation}\n\nor\n\n\\begin{equation}\n    \\begin{split} \\label{eq:symplectic-verlet2}\n        \\vec{q}_{1/2} &= \\vec{q}_0 + \\frac{h}{2} \\pd{H}{\\vec{p}}(q_{1/2}, p_0) \\\\\n        \\vec{p}_1 &= \\vec{p}_0 - \\frac{h}{2} \\left( \\pd{H}{\\vec{q}}(q_{1/2}, p_0) + \\pd{H}{\\vec{q}}(q_{1/2}, p_1) \\right) \\\\\n        \\vec{q}_{1} &= \\vec{q}_{1/2} + \\frac{h}{2} \\pd{H}{\\vec{p}}(q_{1/2}, p_1) \\\\\n    \\end{split}\n\\end{equation}\n\n\n\n\\section{CM-Centered Restricted 3-Body System (C-R3B), Earth-Moon}\nThe center-of-mass-centered 3-body system (C-R3B) with the Earth and Moon was explored in \\cite{Saxe2015}; refer to this for detailed derivations of C-R3B. We will present the final nondimensionalized equations of motion, and numerical integration algorithms for reference. The model is set up as in \\cref{fig:r3b}.\n\n\\begin{figure}[ht!]\n    \\centering\n    \\includegraphics[scale=0.75]{fig/r3b.pdf}\n    \\caption{Restricted three-body problem. Two coordinate systems both with center of mass as origin: $(\\mathscr{X},\\mathscr{Y})$ is a stationary inertial frame, $(x,y)$ is a co-rotating non-inertial frame that rotates with the moon at angular frequency $\\omega$. $M =$ mass of Earth, $m =$ mass of Moon, $\\vec{R} =$ vector from CM to earth, $\\vec{r} =$ vector from CM to Moon, $m_s =$ mass of spacecraft, $r_{S,E} =$ distance from spacecraft to Earth, $r_{S,M} =$ distance from spacecraft to Moon. In the dimensionless variables we introduce later, unit distance is $R+r$, which makes the dimensionless constant $k = \\text{the CM-Earth distance} = \\dfrac{R}{R+r} = $ and $1-k = \\text{the CM-Moon distance} = \\dfrac{r}{R+r}$ (Image: \\cite{Saxe2015}).}\n    \\label{fig:r3b}\n\\end{figure}\n\n\\subsection{C-R3B Equations of Motion}\n\n\\begin{empheq}[box=\\widefbox]{align}\n\\label{eq:Xdot}\n\\dot{X} = P_x + Y\n\\end{empheq}\n\n\\begin{empheq}[box=\\widefbox]{align}\n\\label{eq:Ydot}\n\\dot{Y} = P_Y - X\n\\end{empheq}\n\n\\begin{empheq}[box=\\widefbox]{align}\n\\label{eq:Pdot_X}\n\\dot{P}_X = P_Y - \\dfrac{(1-k)(X+k)}{((X+k)^2+Y^2)^{3/2}} - \\dfrac{k(X-1+k))}{((X-1+k))^2+Y^2)^{3/2}}\n\\end{empheq}\n\n\\begin{empheq}[box=\\widefbox]{align}\n\\label{eq:Pdot_Y}\n\\dot{P}_Y = -P_X - \\dfrac{(1-k)Y}{((X+k)^2+Y^2)^{3/2}} - \\dfrac{k Y}{((X-1+k))^2+Y^2)^{3/2}}\n\\end{empheq}\nwhere \\(T\\), \\(X\\), \\(Y\\), \\(P_x\\) and \\(P_y\\) are our dimensionless variables for time, positions, generalized impulse, and \\(k=\\dfrac{M_{\\Moon}}{M_{\\Earth} + M_{\\Moon}}\\), that is the ratio of Moon's mass to the total Earth and Moon mass.\n\n\\subsection{C-R3B Numerical Algorithms}\n\\subsubsection{C-R3B Symplectic Euler}\nWe refer to \\cite{Saxe2015} for detailed derivations. The equations of motion of the other system in the next section will be derived in details. Based on \\cref{eq:Xdot,eq:Ydot,eq:Pdot_X,eq:Pdot_Y}, a symplectic Euler algorithm is found:\n\n\\begin{align}\n    X_1 &= \\dfrac{X_0 + h (h P_{Y,0} + P_{X,0} + Y_0)}{1+h^2}, \\\\[0.4cm]\n    Y_1 &= Y_0 + h (P_{Y,0} - X_1), \\label{eq:symplectic-euler-Y_1}\n\\end{align}\n\\begin{align}\n    \\begin{aligned}\n        P_{X,1} &= P_{X,0} \\\\\n        &+ h \\left(P_{Y,0} - \\dfrac{(1-k)(k+X_1)}{((k+X_1)^2+Y_1^2)^{3/2}} + \\dfrac{k(X_1-1+k)}{((X_1-1+k)^2+Y_1^2)^{3/2}}\\right), \\label{eq:symplectic-euler-PX_1}\n    \\end{aligned} \\\\[0.4cm]\n    \\begin{aligned}\n        P_{Y,1} &= P_{Y,0} \\\\\n        &+ h \\left(-P_{X,0} - \\dfrac{(1-k)Y_1}{((k+X_1)^2+Y_1^2)^{3/2}} - \\dfrac{k Y_1}{((X_1-1+k)^2+Y_1^2)^{3/2}}\\right), \\label{eq:symplectic-euler-PY_1}\n    \\end{aligned}\n\\end{align}\nwhere \\(h\\) is the step size, index \\(0\\) designates previous time step ($i$) and index \\(1\\) designates new time step ($i+1$). The algorithm is run in the same order as listed above.\n\n\\subsubsection{C-R3B Symplectic Störmer-Verlet}\nBased on \\cref{eq:Xdot,eq:Ydot,eq:Pdot_X,eq:Pdot_Y}, a symplectic Störmer-Verlet algorithm was also found (For detailed derivation, see \\cite{Saxe2015}):\n\n\\begin{align}\n    X_{1/2} &= \\frac{h^2 P_{Y,0} + 2 h \\dot{P}_{x,0} + 4 X_0}{4 + h^2} \\label{eq:verlet-x_1/2} \\\\\n    Y_{1/2} &= Y_0 + \\dfrac{h}{2} (P_{Y,0} - X_{1/2}), \\label{eq:verlet-y_1/2} \\\\\n    P_{X,1} &= \\frac{h^2 (2 \\dot{P}_{Y,0} + P_{X,0}) + 4 h \\dot{P}_{X,0} + 4 P_{X,0} }{4 + h^2} \\label{eq:verlet-px_1} \\\\\n    P_{Y,1} &= P_{Y,0} + \\dfrac{h}{2} \\left[-\\dot{P}_Y(q_{1/2},p_0) -\\dot{P}_Y(q_{1/2},p_1) \\right], \\label{eq:verlet-py_1} \\\\\n    X_1 &= X_{1/2} + \\dfrac{h}{2} (P_{X,1} + Y_{1/2}), \\label{eq:verlet-x_1} \\\\\n    Y_1 &= Y_{1/2} + \\dfrac{h}{2} (P_{Y,1} - X_{1/2}), \\label{eq:verlet-y_1}\n\\end{align}\nwhere \\(\\dot{P}_X,\\dot{P}_Y\\) are \\cref{eq:Pdot_X,eq:Pdot_Y}, \\(h\\) is the step size, index \\(0\\) designates previous time step ($i$) and \\(1\\) designates new time step ($i+1$). The algorithm is run in the same order as listed above.\n\n\\subsubsection{Adaptive Timesteps}\nFurthermore the Verlet algorithm is made to take adaptive time steps. In areas relatively large accelerations, the step size is decreased and vice versa. The idea is to take both an Euler and a Verlet step, and estimate the error made in the step as the difference between the two.\n\nLet $z$ denote a vector of the position variables $(X,y)$.\n\\begin{align}\n\\text{Euler step result:} \\qquad z_1 = z + O(h), \\\\\n\\text{Verlet step result:} \\qquad z_2 = z + O(h^2), \\\\\n\\end{align}\nwhere O(h) denotes an error term of order h. Then we take the difference\n\\begin{align}\n\\|z_1 - z_2\\| &= O(h) - O(h^2) \\\\\n&\\approx O(h)\\ ,\n\\end{align}\nsince $O(h) \\gg O(h^2)$. Thus we approximate the error difference between the Euler and Verlet method as the actual error we make at step size $h$. The idea is to make both an Euler and a Verlet step for every time-step to assess the error and adjust the step size accordingly. For every single step the step size is changed either up or down, depending on the errors and tolerance. As a result we always stay near the same error in every step, only taking as small steps as necessary in each iteration.\n\nThe non-adaptive algorithm is fixed in step size but varies in error per step.\nThe adaptive algorithm varies in step size in an attempt to fix the error per step.\n\nFor all simulations we have set $10^{-9}$ as the maximum tolerated error per step in the adaptive algorithm. For the non-adaptive algorithm we select a fixed step size, $10^{-6}$, to ensure that it's reasonably low most of the time. This approach was again taken directly from \\cite{Saxe2015}.\n\n\\section{Heliocentric Restricted 4-Body System (H-R4B), Sun-Earth-Mars}\nSimulating orbit from Earth to Mars requires a new model with at least four bodies: Sun, Earth, Mars and the Spacecraft. The coordinate system will be heliocentric and in spherical coordinates, and restricted\\footnote{Meaning that the mass of the spacecraft is considered negligible compared to compared to the celestial masses and therefore is assumed not to affect them}, so we call this system the ``Heliocentric Restricted 4-Body System'', see \\cref{fig:solar-system-model}. We will derive the equations of motion of the spacecraft by using Hamilton's equations, which gives us a set of coupled first-order differential equations, and a set of conserved quantities as ``generalized momenta''.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.80\\linewidth]{fig/solar-system-model}\n    \\caption{ H-R4B model of spacecraft motion.The sun is assumed stationary at the origin of a spherical coordinate system, and the focus of two elliptical orbits of Earth and Mars. (Assets source: \\cite{WikiSpherical,flaticon})}\n    \\label{fig:solar-system-model}\n\\end{figure}\n\n\\subsection{Spherical Coordinate System}\nWe adopt the spherical coordinate system which customary in astrodynamics, as shown in \\cref{fig:solar-system-model}.\n\nThe coordinate transform equations to and from the cartesian coordinate system are:\n\n\\begin{align}\n    x &= r \\sin{\\theta}\\cos{\\phi}, \\label{eq:x(q)} \\\\\n    y &= r \\sin{\\theta}\\sin{\\phi}, \\label{eq:y(q)}\\\\\n    z &= r \\cos{\\theta}, \\label{eq:z(q)}\n\\end{align}\n\nand\n\n\\begin{align}\n    r &= \\sqrt{x^2 + y^2 + z^2}, \\label{eq:r(x,y,z)}\\\\\n    \\theta &= \\arccos{\\frac{z}{r}}, \\label{eq:theta(x,y,z)}\\\\\n    % \\arctan{\\frac{y}{x}}, \\qquad \\theta  \\in [0, 2\\pi]\n    \\phi &= \n    \\arctantwo{(y/x)} \\\\\n    \\label{eq:phi(x,y,z)}\n\\end{align}\n\nwhere \\(r \\in [0, \\infty]\\), \\(\\theta \\in [0, \\pi]\\) and \\(\\phi \\in [0, 2\\pi]\\) and \\(\\arctan2\\) denotes the two-argument version of \\(\\arctan\\) function \\footnote{\\(\\arctan{(a)} \\in (-\\frac{\\pi}{2}, \\frac{\\pi}{2})\\) just takes a slope as input and give an angle in quadrant 1 and 4 only, whereas \\(\\arctantwo{(y,x)} \\in (-\\pi, \\pi]\\) takes both \\(x\\) and \\(y\\) which also gives the correct quadrant 1–4.}\\cite{WikiAtan2}.\n\nFor the calculation of kinetic in the next section we will need the position vector, unit vectors in spherical coordinates, and the Jacobians.\n\nThe position vector in spherical coordinates is\n\\begin{align}\n    \\vec{r}(r, \\theta, \\phi) &= x \\xhat + y \\yhat + z \\zhat \\\\\n    \\Leftrightarrow \\vec{r}(r, \\theta, \\phi) &= r \\sin{\\theta}\\cos{\\phi} \\xhat + r \\sin{\\theta}\\sin{\\phi} \\yhat + r \\cos{\\theta} \\zhat. \\label{eq:position-vec-spherical}\n\\end{align}\n\nThe various coordinate derivatives of the position vector is\n\\begin{align}\n    \\pd{\\vec{r}}{r} &= \\sin{\\theta}\\cos{\\phi} \\xhat + \\sin{\\theta}\\sin{\\phi} \\yhat + \\cos{\\theta} \\zhat \\quad &\\text{and} \\quad &\\left| \\pd{\\vec{r}}{r} \\right| = 1 \\label{eq:position-derived-r} \\\\\n    \\pd{\\vec{r}}{\\theta} &= r \\cos{\\theta}\\cos{\\phi} \\xhat + r \\cos{\\theta}\\sin{\\phi} \\yhat - r \\sin{\\theta} \\zhat \\quad &\\text{and} \\quad &\\left| \\pd{\\vec{r}}{\\theta} \\right| = r \\label{eq:position-derived-theta} \\\\\n    \\pd{\\vec{r}}{\\phi} &= -r\\sin{\\theta}\\sin{\\phi} \\xhat + r\\sin{\\theta}\\cos{\\phi} \\zhat \\quad &\\text{and} \\quad &\\left| \\pd{\\vec{r}}{\\phi} \\right| = r\\sin{\\theta} \\label{eq:position-derived-phi}\n\\end{align}\n\nSo the unit vectors in spherical coordinates are\n\\begin{align}\n    \\rhat = \\dfrac{\\pd{\\vec{r}}{r}}{\\left| \\pd{\\vec{r}}{r} \\right| } &= \\sin{\\theta}\\cos{\\phi} \\xhat + \\sin{\\theta}\\sin{\\phi} \\yhat + \\cos{\\theta} \\zhat \\label{eq:r-hat}\\\\\n    \\thetahat = \\dfrac{\\pd{\\vec{r}}{\\theta}}{\\left| \\pd{\\vec{r}}{\\theta} \\right| } &= \\cos{\\theta}\\cos{\\phi} \\xhat + \\cos{\\theta}\\sin{\\phi} \\yhat - \\sin{\\theta} \\zhat \\label{eq:theta-hat}\\\\\n    \\phihat = \\dfrac{\\pd{\\vec{r}}{\\phi}}{\\left| \\pd{\\vec{r}}{\\phi} \\right| } &= -\\sin{\\phi} \\xhat + \\cos{\\phi} \\zhat \\label{eq:phi-hat}\n\\end{align}\n\n\\subsection{H-R4B Equations of Motion}\nWe will follow the 5-step process of arriving at Hamilton's equations outlined in \\cref{apx:using-hamilton-mechanics}.\n\n\\subsubsection{Step 1: Lagrangian \\(L\\)}\nThe kinetic energy of the system is\n\\begin{align}\n    T = \\frac{1}{2} m_s v^2.\n\\end{align}\n\nIn general the total derivative of a vector is:\n\n\\begin{align}\n    \\vec{v} &= \\od{\\vec{r}}{t} = \\sum\\limits_{j} \\pd{\\vec{r}}{q_j} \\od{q_j}{t}, \\\\\n      &= \\sum\\limits_{j} \\left|\\pd{\\vec{r}}{q_j}\\right| \\frac{\\pd{\\vec{r}}{q_j}}{\\left|\\pd{\\vec{r}}{q_j}\\right|} \\od{q_j}{t}, \\\\\n      &= \\sum\\limits_{j} \\left|\\pd{\\vec{r}}{q_j}\\right| \\od{q_j}{t} \\unitvector{q}_j, \\\\\n      &= \\sum\\limits_{j} \\left|\\pd{\\vec{r}}{q_j}\\right| \\dot{q_j} \\unitvector{q}_j,\n    \\end{align}\n\nwhere we have used that a unit vector for any coordinate system is \\(\\frac{\\pd{\\vec{r}}{q_j}}{\\left|\\pd{\\vec{r}}{q_j}\\right|} = \\unitvector{q}_j\\).\nWe can now use the derivatives of the position vector we found earlier in \\cref{eq:position-derived-r,eq:position-derived-theta,eq:position-derived-phi}, to substitute for \\(\\left|\\pd{\\vec{r}}{q_j}\\right|\\). We don't have to substitute in \\(\\unitvector{q}_j\\) since our unit vectors are orthogonal, so they will yield either 0 or 1 when we square \\(v\\). So for the spherical coordinates we get:\n\n\\begin{align}\n    \\vec{v} = \\dot{r}\\rhat + r\\dot{\\theta}\\thetahat + r\\sin{\\theta}\\,\\dot{\\phi}\\phihat\n\\end{align}\n\nso\n\n\\begin{align}\n    v^2 = \\dot{r}^2 + r^2\\dot{\\theta}^2 + r^2\\sin^2{\\theta}\\,\\dot{\\phi}^2\n\\end{align}\n\nso we get\n\n\\begin{align}\n    T = \\frac{1}{2} m_s (\\dot{r}^2 + r^2\\dot{\\theta}^2 + r^2\\sin^2{\\theta}\\,\\dot{\\phi}^2).\n\\end{align}\n\nThe gravitational potential is \\cite{WikiGravPotential}\n\n\\begin{align}\n    V = -G m_s \\sum\\limits_{k} \\frac{M_k}{\\left| \\vec{r} - \\vec{r_k} \\right|},\n\\end{align}\nwhere \\(i\\) denotes the celestial bodies acting on the spacecraft, i.e. in our system Sun, Earth and Mars.\n\nSo we finally get the Lagrangian\n\n\\begin{align}\n    L &= T - V \\\\\n    \\Leftrightarrow L &= \\frac{1}{2} m_s (\\dot{r}^2 + r^2\\dot{\\theta}^2 + r^2\\sin^2{\\theta}\\,\\dot{\\phi}^2) + G m_s \\sum\\limits_{k} \\frac{M_k}{\\left| \\vec{r} - \\vec{r_k} \\right|}\n\\end{align}\n\n\\subsubsection{Step 2: Generalized Momenta \\(p_j\\)}\n\\begin{align}\n    p_r &= \\pd{L}{\\dot{r}} = m_s \\dot{r} \\label{eq:pr} \\\\\n    p_\\theta &= \\pd{L}{\\dot{\\theta}} = m_s r^2 \\dot{\\theta} \\label{eq:ptheta} \\\\\n    p_\\phi &= \\pd{L}{\\dot{\\phi}} = m_s r^2 \\sin^2{\\theta} \\dot{\\phi} \\label{eq:pphi}\n\\end{align}\n\nWe recognize the three generalized momenta as linear momentum (\\cref{eq:pr}) and angular momentum (\\cref{eq:ptheta,eq:pphi}), respectively.\n\n\\subsubsection{Step 3: \\(\\dot{q} = \\dot{q}_j(\\vec{q}, \\vec{p}, t)\\)}\n\\begin{align}\n    \\dot{r} &= \\frac{p_r}{m_s} \\\\\n    \\dot{\\theta} &= \\frac{p_\\theta}{m_s r^2} \\\\\n    \\dot{\\phi} &= \\frac{p_\\phi}{m_s r^2 \\sin^2{\\theta}}\n\\end{align}\n\nWe can now rewrite \\(L\\) to make it independent of \\(\\dot{q}\\) by substituting the expressions above:\n\n\\begin{align}\n    T &= \\frac{1}{2} m_s (\\dot{r}^2 + r^2\\dot{\\theta}^2 + r^2\\sin^2{\\theta}\\,\\dot{\\phi}^2) \\\\\n    &= \\frac{1}{2} m_s \\left(\\frac{p_r^2}{m_s^2} + r^2\\frac{p_\\theta^2}{m_s^2 r^4} + r^2\\sin^2{\\theta}\\frac{p_\\phi^2}{m_s^2 r^4 \\sin^4{\\theta}} \\right) \\\\\n    &= \\frac{p_r^2}{2 m_s} + \\frac{p_\\theta^2}{2 m_s r^2} + \\frac{p_\\phi^2}{2 m_s r^2 \\sin^2{\\theta}} \\\\\n\\end{align}\n\nSo using \\(L = T - V\\) we have\n\n\\begin{align}\n    L = \\frac{p_r^2}{2 m_s} + \\frac{p_\\theta^2}{2 m_s r^2} + \\frac{p_\\phi^2}{2 m_s r^2 \\sin^2{\\theta}} + G m_s \\sum\\limits_{k} \\frac{M_k}{\\left| \\vec{r} - \\vec{r_k} \\right|}\n\\end{align}\n\n\\subsubsection{Step 4: Hamiltonian \\(H\\)}\n\\begin{align}\n    H(\\vec{q}, \\vec{p}, t) &= \\sum\\limits_{j}p_j \\dot{q_j} - L \\\\\n    &= \\sum\\limits_{j}p_j \\dot{q_j}(\\vec{q}, \\vec{p}, t) - L \\\\\n    &= p_r \\frac{p_r}{m_s} + p_\\theta \\frac{p_\\theta}{m_s r^2} + p_\\phi + \\frac{p_\\phi}{m_s r^2 \\sin^2{\\theta}} \\notag \\\\\n    &- \\left( \\frac{p_r^2}{2 m_s} + \\frac{p_\\theta^2}{2 m_s r^2} + \\frac{p_\\phi^2}{2 m_s r^2 \\sin^2{\\theta}} + G m_s \\sum\\limits_{k} \\frac{M_k}{\\left| \\vec{r} - \\vec{r_k} \\right|} \\right) \\\\\n    \\Leftrightarrow H &= \\frac{p_r^2}{2 m_s} + \\frac{p_\\theta^2}{2 m_s r^2} + \\frac{p_\\phi^2}{2 m_s r^2 \\sin^2{\\theta}} - G m_s \\sum\\limits_{k} \\frac{M_k}{\\left| \\vec{r} - \\vec{r_k} \\right|}\n\\end{align}\n\nAt this point we want to expand the expression \\(\\left| \\vec{r} - \\vec{r_k} \\right|\\) in anticipation of needing to differentiate \\(H\\) with respect to the coordinates. Using the equations for the \\(x, y, z\\) coordinates \\cref{eq:x(q),eq:y(q),eq:z(q)} we get\n\n\\begin{align}\n    d_k = \\left|\\vec{r} - \\vec{r}_k \\right| &= \\sqrt{(x-x_k)^2 + (y-y_k)^2 + (z-z_k)^2}\n\\end{align}\nand (colors added to show which terms factor into each other in next step)\n\\begin{align}\n    (x-x_k)^2 &= (r\\sin{\\theta}\\cos{\\phi} - r\\sin{\\theta}\\cos{\\phi})^2 \\notag \\\\\n    &= \\tikz[baseline]{\n        \\node[fill=orange!20,anchor=base]\n        {\\(r^2\\sin^2{\\theta}\\cos^2{\\phi}\\)}\n    } + \\tikz[baseline]{\n        \\node[fill=red!20,anchor=base]\n        {\\(r_k^2\\sin^2{\\theta_k}\\cos^2{\\phi_k}\\)}\n    } - 2r r_k \\sin{\\theta}\\sin{\\theta_k}\\cos{\\phi}\\cos{\\phi_k} \\label{eq:x-dist-squared} \\\\\n    (y-y_k)^2 &= (r\\sin{\\theta}\\sin{\\phi} - r\\sin{\\theta}\\sin{\\phi})^2 \\notag \\\\\n    &= \\tikz[baseline]{\n        \\node[fill=orange!20,anchor=base]\n        {\\(r^2\\sin^2{\\theta}\\sin^2{\\phi}\\)}\n    } + \\tikz[baseline]{\n        \\node[fill=red!20,anchor=base]\n        {\\(r_k^2\\sin^2{\\theta_k}\\sin^2{\\phi_k}\\)}\n    } - 2r r_k \\sin{\\theta}\\sin{\\theta_k}\\sin{\\phi}\\sin{\\phi_k} \\label{eq:y-dist-squared} \\\\\n    (z-z_k)^2 &= (r\\cos{\\theta} - r\\cos{\\theta})^2 \\notag \\\\\n    &= \\tikz[baseline]{\n        \\node[fill=orange!20,anchor=base]\n        {\\(r^2\\cos^2{\\theta}\\)}\n    } + \\tikz[baseline]{\n        \\node[fill=red!20,anchor=base]\n        {\\(r_k^2\\cos^2{\\theta_k}\\)}\n    } - 2r r_k \\cos{\\theta}\\cos{\\theta_k}. \\label{eq:z-dist-squared}\n\\end{align}\nNow adding all three \\cref{eq:x-dist-squared,eq:y-dist-squared,eq:z-dist-squared} the orange terms factor into \\(r^2\\) and the red terms factor into \\(r_k^2\\) and we get\n\n\\begin{align}\n    d_k &= \\sqrt{\n        \\tikz[baseline]{\\node[fill=orange!20,anchor=base]{\\(r^2\\)}}\n        + \\tikz[baseline]{\\node[fill=red!20,anchor=base]{\\(r_k^2\\)}}\n        -2r r_k(\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}(\n            \\tikz[baseline]{\\node[fill=blue!20,anchor=base]{\n                \\(\\cos{\\phi}\\cos{\\phi_k} + \\sin{\\phi}\\sin{\\phi_k}\\)}}\n        ))\n    } \\\\\n    &= \\sqrt{r^2 + r_k^2 - 2 r r_k(\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k}))},\n\\end{align}\nwhere the blue factor was simplified using the sum rule: \\\\\n\\(\\cos{\\alpha}\\cos{\\beta} + \\sin{\\alpha}\\sin{\\beta} = cos{(\\alpha-\\beta)}\\) \\cite{WeissteinTrig}.\n\nSo we can finally express \\(H\\) as\n\\begin{equation}\n    \\begin{aligned}\n        H &= \\frac{p_r^2}{2 m_s} + \\frac{p_\\theta^2}{2 m_s r^2} + \\frac{p_\\phi^2}{2 m_s r^2 \\sin^2{\\theta}} \\\\\n        &- G m_s \\sum\\limits_{k} \\frac{M_k}{\\sqrt{r^2 + r_k^2 - 2 r r_k \\left[\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k})\\right]}}\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Step 5: Hamilton's Equations}\n\\begin{align}\n    \\dot{r} = \\pd{H}{p_r} &= \\frac{p_r}{m_s} \\label{eq:rdot} \\\\[0.3cm]\n    \\dot{\\theta} = \\pd{H}{p_\\theta} &= \\frac{p_\\theta}{m_s r^2} \\label{eq:thetadot} \\\\[0.3cm]\n    \\dot{\\phi} = \\pd{H}{p_\\phi} &= \\frac{p_\\phi}{m_s r^2 \\sin^2{\\theta}} \\label{eq:phidot}  \\\\[0.3cm]\n    \\begin{split}\n        \\dot{p}_r = -\\pd{H}{r} &= \\frac{p_\\theta^2}{m_s r^3} + \\frac{p_\\phi^2}{m_s r^3 \\sin^2{\\theta} } \\\\\n        &+ G m_s \\sum\\limits_{k} M_k \\frac{-r + r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)}\\right)}{\\left[r^2 + r_k^2 - 2 r r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}} \\label{eq:prdot}\n    \\end{split} \\\\[0.3cm]\n    \\begin{split}\n        \\dot{p}_\\theta = -\\pd{H}{\\theta} &= \\frac{p_\\phi^2}{m_s r^2 \\sin^2{\\theta} \\tan{\\theta}} \\\\\n        &+ G m_s \\sum\\limits_{k} M_k \\frac{r r_k \\left[-\\sin{\\theta}\\cos{\\theta_k} + \\cos{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right]}{\\left[r^2 + r_k^2 - 2 r r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}} \\label{eq:pthetadot}\n    \\end{split} \\\\[0.3cm]\n    \\begin{split}\n        \\dot{p}_\\phi = -\\pd{H}{\\phi} &= G m_s \\sum\\limits_{k} M_k \\frac{- r r_k \\sin{\\theta}\\sin{\\theta_k}\\sin{(\\phi - \\phi_k)}}{\\left[r^2 + r_k^2 - 2 r r_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}} \\label{eq:pphidot}\n    \\end{split}\n\\end{align}\n\nThose are our equations of motion. However before we try to solve them, we will remove all units.\n\n\\subsection{H-R4B Equations Nondimensionalized}\nWe will now choose suitable characteristic units, which has a number of benefits:\n\\begin{itemize}\n    \\item The equations gets slightly simplified\n    \\item The order of the effects of different forces in the system becomes more apparent.\n    \\item Many of the calculations in numerical algorithms happens at an order of about 1, which is desireable for decreasing round-off error due to finite machine precision.\n\\end{itemize}\n\nThe characteristic units are chosen as:\n\\begin{align}\n    \\text{Unit length: } k_r &= a_{\\Earth}\\ {\\color{gray} \\approx \\SI{1.50e8}{\\km}\\ \\text{(1 Earth orbit semi-major axis)}}  \\\\[0.2cm]\n    \\text{Unit time: } k_t &= T_{\\Earth} = \\frac{2\\pi}{\\omega_\\Earth} = 2\\pi \\sqrt{\\frac{a_\\Earth^3}{G M_\\Sun}}\\ {\\color{gray} \\approx \\SI{3.16e7}{\\s}\\ \\text{ (1 year)}} \\\\[0.2cm]\n    \\text{Unit speed: } k_v &= \\frac{k_r}{k_t} = \\frac{a_\\Earth \\omega_\\Earth}{2\\pi} = \\frac{1}{2\\pi} \\sqrt{\\frac{G M_\\Sun}{a_\\Earth}}\\ {\\color{gray} \\approx \\SI{4.74}{\\km/\\s}\\ \\text{(1 AU/y)}}\n\\end{align}\nwhere \\(a_\\Earth\\) is the semi-major axis of Earth's orbit in kilometers, see \\cref{fig:earth-semi-major-axis}, \\(T_\\Earth\\) is Earth's orbital period (i.e. 1 year) in seconds and the characteristic speed thus becomes Earth's average orbital speed with respect to the sun.\n\nWe don't need a characteristic mass \\(m_s\\) since the mass cancels out in the equations of motion for the quantity we care about, delta-v.\n\nThe unit for time is expressed in seconds because we found heuristically we needed time steps on the order of \\(\\SI{1}{\\s}\\) to maintain an error per step of about \\num{10e-9}.\n\nThe unit for length is expressed in kilometers because it is customary to use \\si{\\km/\\s} as unit of speed for celestial objects.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.60\\linewidth]{fig/earth-semi-major-axis}\n    \\caption{Semi-major axis of Earth's elliptical orbit, used as the characteristic length of the system}\n    \\label{fig:earth-semi-major-axis}\n\\end{figure}\n\n\\clearpage\n\nThe nondimensionalization is done in \\cref{apx:hr4b-nondimensionalization}. The resulting equations and the nondimensionalized Hamiltonian is:\n\n\\begin{equation} \\tag{2.67}\n    \\boxed{\n            \\dot{R} = B_R\n    }\n\\end{equation}\n\n\n\\begin{equation} \\tag{2.72}\n    \\boxed{\n            \\dot{\\theta} = \\frac{B_\\theta}{R^2}\n    }\n\\end{equation}\n\n\n\\begin{equation} \\tag{2.76}\n    \\boxed{\n            \\dot{\\phi} = \\frac{B_\\phi}{R^2 \\sin^2{\\theta}}\n    }\n\\end{equation}\n\n\n\\begin{equation} \\tag{2.86}\n    \\boxed{\n        \\!\\begin{aligned}\n            \\dot{B}_r = &\\frac{B_\\theta^2}{R^3} + \\frac{B_\\phi^2}{R^3 \\sin^2{\\theta}} \\\\\n            & + \\sum\\limits_{k} \\eta_k \\frac{-R + R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)}\\right)}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}}\n        \\end{aligned}\n    }\n\\end{equation}\n\n\n\\begin{equation} \\tag{2.87}\n    \\boxed{\n        \\!\\begin{aligned}\n            \\dot{B}_\\theta = &\\frac{B_\\phi^2}{R^2 \\sin^2{\\theta} \\tan{\\theta}} \\\\\n            &+ \\sum\\limits_{k} \\eta_k \\frac{R R_k \\left[-\\sin{\\theta}\\cos{\\theta_k} + \\cos{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right]}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}}\n        \\end{aligned}\n    }\n\\end{equation}\n\n\n\\begin{equation} \\tag{2.88}\n    \\boxed{\n        \\!\\begin{aligned}\n            \\dot{B}_\\phi = &\\sum\\limits_{k} \\eta_k \\frac{- R R_k \\sin{\\theta}\\sin{\\theta_k}\\sin{(\\phi - \\phi_k)}}{\\left[R^2 + R_k^2 - 2 R R_k \\left(\\cos{\\theta}\\cos{\\theta_k} + \\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k)} \\right) \\right]^{3/2}}\n        \\end{aligned}\n    }\n\\end{equation}\n\n\\vspace{0.2cm}\nwhere we renamed $p$ to $B$ because we divided by spacecraft mass $m_s$ on both sides, thus $\\dot{B}_r$ is now linear velocity along r-coordinate and $\\dot{B}_\\theta$ and $\\dot{B}_\\phi$ are now angular velocities.\n\nFor reference, the nondimensionalized Hamiltonian per spacecraft mass:\n\n\\begin{equation} \\tag{2.105}\n    \\begin{aligned}\n        \\mathcal{H}_m &= \\frac{B_r^2}{2} + \\frac{B_\\theta^2}{2 R^2} + \\frac{B_\\phi^2}{2 R^2 \\sin^2{\\theta}} \\\\\n        &- \\sum\\limits_{k} \\eta_k \\frac{1}{\\sqrt{R^2 + R_k^2 - 2 R R_k \\left[\\cos{\\theta}\\cos{\\theta_k}+\\sin{\\theta}\\sin{\\theta_k}\\cos{(\\phi - \\phi_k})\\right]}}        \n    \\end{aligned}\n\\end{equation}\n\n\\subsection{H-R4B Numerical Integration Algorithm}\n\n\\subsubsection{Symplectic Euler for H-R4B System}\n\nOne can choose whichever of the two Symplectic Euler versions \\cref{eq:symplectic-euler1,eq:symplectic-euler2} is easier to solve for the equations at hand. We choose the latter form \\cref{eq:symplectic-euler2} so with our Hamiltonian \\cref{eq:HH_m} we get\n\\begin{align}\n    R_1 &= R_0 + h B_{r,0} \\label{eq:symplectic-euler-R_1}, \\\\[0.4cm]\n    \\theta_1 &= \\theta_0 + h \\frac{B_{\\theta,0}}{R_1^2}, \\label{eq:symplectic-euler-theta_1} \\\\[0.4cm]\n    \\phi_1 &= \\phi_0 + h \\frac{B_{\\phi,0}}{R_1^2 \\sin^2{\\theta_1}}, \\label{eq:symplectic-euler-phi_1}\n\\end{align}\n\\begin{align}    \n    \\begin{aligned}\n        B_{r,1} = & B_{r,0} + h \\left[ \\frac{B_{\\theta,0}^2}{R_1^3} + \\frac{B_{\\phi,0}^2}{R_1^3 \\sin^2{\\theta_1}} \\right. \\\\\n        & \\hspace{-21.0pt} + \\left. \\sum\\limits_{k} \\eta_k \\frac{-R_1 + R_{k,1} \\left(\\cos{\\theta_1}\\cos{\\theta_{k,1}} + \\sin{\\theta_1}\\sin{\\theta_{k,1}}\\cos{(\\phi_1 - \\phi_{k,1})}\\right)}{\\left[R_1^2 + R_{k,1}^2 -2 R_1 R_{k,1}^2 \\left(\\cos{\\theta_1}\\cos{\\theta_{k,1}} + \\sin{\\theta_1}\\sin{\\theta_{k,1}}\\cos{(\\phi_1 - \\phi_{k,1})} \\right) \\right]^{3/2}} \\right] , \\label{eq:symplectic-euler-Br_1}\n    \\end{aligned} \\\\[0.4cm]\n    \\begin{aligned}\n        B_{\\theta,1} = & B_{\\theta,0} + h \\left[ \\frac{B_{\\phi,0}^2}{R_1^2 \\sin^2{\\theta_1} \\tan{\\theta_1}} \\right. \\\\\n        & \\hspace{-21.0pt} + \\left. \\sum\\limits_{k} \\eta_k \\frac{R_1 R_{k,1} \\left[-\\sin{\\theta_1}\\cos{\\theta_{k,1}} + \\cos{\\theta_1}\\sin{\\theta_{k,1}}\\cos{(\\phi_1 - \\phi_{k,1})} \\right]}{\\left[R_1^2 + R_{k,1}^2 -2 R_1 R_{k,1}^2 \\left(\\cos{\\theta_1}\\cos{\\theta_{k,1}} + \\sin{\\theta_1}\\sin{\\theta_{k,1}}\\cos{(\\phi_1 - \\phi_{k,1})} \\right) \\right]^{3/2}} \\right], \\label{eq:symplectic-euler-Btheta_1}\n    \\end{aligned} \\\\[0.4cm]\n    \\begin{aligned}\n        B_{\\phi,1} = & B_{\\phi,0} + h \\left[ \\vphantom{\\frac12} \\right.\\\\\n        & \\hspace{-21.0pt} \\hphantom{+} \\left. \\sum\\limits_{k} \\eta_k \\frac{- R_1 R_{k,1} \\sin{\\theta_1}\\sin{\\theta_{k,1}}\\sin{(\\phi_1 - \\phi_{k,1})}}{\\left[R_1^2 + R_{k,1}^2 -2 R_1 R_{k,1}^2 \\left(\\cos{\\theta_1}\\cos{\\theta_{k,1}} + \\sin{\\theta_1}\\sin{\\theta_{k,1}}\\cos{(\\phi_1 - \\phi_{k,1})} \\right) \\right]^{3/2}} \\right]. \\label{eq:symplectic-euler-Bphi_1}\n    \\end{aligned}\n\\end{align}\nAs we can see, we are lucky with this Hamiltonian since we can simply run all steps in the order above, \\cref{eq:symplectic-euler-R_1,eq:symplectic-euler-theta_1,eq:symplectic-euler-phi_1,eq:symplectic-euler-Br_1,eq:symplectic-euler-Btheta_1,eq:symplectic-euler-Bphi_1} without needing to solve any implicit equations.\n\n\\subsubsection{Symplectic Verlet for H-R4B System}\n\nThese equations of motion follow the procedures of \\cref{eq:symplectic-verlet2}. This algorithm was derived and implemented, but not thoroughly tested. In the interest of time and space, we refer to \\cref{apx:symplectic-verlet-derivations} for derivation and equations.\n\n\\section{Interplanetary Transfer Orbits}\n\n\\subsection{Transfer Orbit to Mars: 2D Patched Conic Approximation} \\label{sec:2d-patched-conic}\nGet get a sense of the initial conditions that will bring us on a transfer orbit from Earth to Mars, we are interested in the following key numbers:\n\\begin{enumerate}\n\t\\item Delta-v for Mars Orbit Insertion (MOI) at Earth.\n\t\\item Delta-v for arrival into circular orbit at Mars.\n\t\\item Relative positions of Earth and Mars for optimal Hohmann trajectory.\n\t\\item Travel time for optimal Hohmann trajectory.\n\\end{enumerate}\n\nKnowing this we have a first good guess on initial conditions to put into the interplanetary 3D simulator, for which we can search for optimal parameters nearby for some good low-delta-v trajectories to mars. To approximate these numbers we can use the \\emph{patched conic approximation}.\n\nFirst we recall that there are four possible orbit types in a two-body system that are all conic sections: circular, elliptic, parabolic and hyperbolic (and the circular is actually a special case of the elliptic), see \\cref{fig:conics-and-orbits}.\n\n\\begin{figure}[ht]\n    \\centering\n    \\subfloat[Conic sections. The parabola is created from an intersecting plane parallel to the cone (Image: \\cite{MagisterMathematicae} (modified)).]{\n        \\includegraphics[width=0.47\\linewidth]{fig/Conic_Sections2.pdf}\n        \\label{fig:conic-sections}\n    }\n    \\hfill\n    \\subfloat[Examples of the four orbit types of a two-body system and their eccentricities (Image: \\cite{Seahen} (modified)).]{\n        \\includegraphics[width=0.40\\linewidth]{fig/Eccentricity.pdf}\n        \\label{fig:orbit-types}\n    }\n    \\caption{The four types of conic sections, corresponding to the four kinds of orbits for a two-body gravitational system. Some authors count three types, with the circle being a special case of the ellipse.}\n    \\label{fig:conics-and-orbits}\n\\end{figure}\n\nThese four orbit types are characterized by the orbit specific energy (mechanical energy per mass) or equivalently by the ranges of eccentricity, see table in \\cref{tab:orbit-type-properties}. As the table shows, a negative mechanical energy corresponds to a closed orbit (either circular or elliptical), zero energy corresponds to a parabolic orbit, i.e. an escape velocity orbit that occurs when a satellite is moving with \\emph{just} enough speed with respect to a central body that it's speed goes towards zero at infinity. Finally, positive mechanical energy corresponds to hyperbolic orbits.\n\n\\begin{table}[tbp]\n    \\centering\n    \\begin{tabular}{@{}llll@{}}\n    \\toprule\n    Conic Section & Eccentricity    & Semi-major axis & Energy  \\\\ \\midrule\n    Circle        & $0$             & = radius        & $<0$    \\\\\n    Ellipse       & $0 < e < 1$     & $>0$            & $<0$    \\\\\n    Parabola      & 1               & infinity        & $0$     \\\\\n    Hyperbola     & $>1$            & $<0$            & $>0$    \\\\ \\bottomrule\n    \\end{tabular}\n    \\caption{Properties of the four orbit types, characterized by their specific energy and eccentricity (Source: \\cite{Braeunig}).}\n    \\label{tab:orbit-type-properties}\n\\end{table}\n\n\nFor a interplanetary transfer orbit we can use the Hohmann transfer orbit as the ``base transfer orbit'' and make some modifications. We recall that the Hohmann transfer is an elliptical orbit that brings a satellite between two different circular orbits around a central body by applying an instantaneous burn twice as depicted back in \\cref{fig:hohmann}. This assumes only one central body. However in our system, we have three central bodies of interest: Earth, Sun and Mars. Each is the dominant body at various points of the journey. We start in a circular orbit around Earth, burn into an elliptical orbit around the Sun and arrive to Mars, burning to a circular orbit again. We can model the transfer orbit to Mars by patching three conic sections:\n\n\\begin{enumerate}\n\t\\item Hyperbolic departure orbit (Geocentric reference frame).\n\t\\item Elliptical transfer orbit (Heliocentric reference frame).\n\t\\item Hyperbolic arrival orbit (Mars-centric reference frame).\n\\end{enumerate}\n\\cref{fig:Hohmann-to-mars-heliocentric} show necessary speeds on Hohmann orbit and the orbit speed of Earth and Mars. \n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{fig/Hohmann-to-mars-heliocentric.png}\n    \\caption{Hohmann transfer to Mars with necessary departure speed (periapsis at Earth) and arrival speed (apoapsis at Mars) on Hohmann orbit relative to Sun (Image: \\cite[p.~127]{Rapp2016} (modified)).}\n    \\label{fig:Hohmann-to-mars-heliocentric}\n\\end{figure}\nWhy are the departure and arrival orbits modelled as hyperbolic? We need extra speed from LEO to enter a transfer orbit that intersects Mars, meaning we need some velocity in excess to escape velocity. Likewise we \\emph{always} arrive at other bodies in a hyperbolic orbit as seen from that body; if we started with zero speed approaching from infinitely far away and waited for infinity, we would get the escape velocity when reaching the planet (this is just escaping with the exact escape velocity in reverse). But since we in practice always come speed already, relative to the body we approach (here Mars), we arrive with speed in excess to the escape velocity, hence along a hyperbolic orbit, as shown in table in \\cref{tab:orbit-type-properties}.\n\nAs \\cref{fig:Hohmann-to-mars-heliocentric} shows, we arrive at Mars' orbit with less speed than Mars \\emph{if Mars wasn't there}, but actually need to slow down due to the attraction of Mars that results in higher speed to necessary for a close circular orbit at target altitude \\SI{125}{\\km}. Thus overall we get a hyperbolic departure orbit, patched with an elliptical orbit, patched with another hyperbolic arrival orbit, with required speeds as illustrated in figure \\cref{fig:Hohmann-to-mars-geocentric-areocentric}.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{fig/Hohmann-to-mars-geocentric-areocentric.png}\n    \\caption{Hohmann transfer to Mars with necessary departure, arrival and parking speeds relative to Earth on the left and Mars on the right (Image: \\cite[p.~133]{Rapp2016} (modified)).}\n    \\label{fig:Hohmann-to-mars-geocentric-areocentric}\n\\end{figure}\n\nAll the numbers of \\cref{fig:Hohmann-to-mars-heliocentric,fig:Hohmann-to-mars-geocentric-areocentric} are derived in \\cref{apx:mars-hohmann-derivations}, answering our four questions from the beginning of the chapter:\n\n\\begin{enumerate}\n\t\\item \\SI{3.62}{\\km\\per\\s} needed to depart Earth circular orbit at altitude 160 km on Mars Orbit Insertion (MOI).\n\t\\item \\SI{-2.11}{\\km\\per\\s} needed at Mars arrival for circular orbit at \\SI{125}{\\km} altitude. Just for illustration, we could also apply less burn at Mars at the expense of entering a highly elliptical orbit as \\cref{fig:mars-arrival-orbit} shows.\n\t\\item Mars must be $44^\\degree$ behind Earth at MOI in order for Mars to be at Hohmann orbit apoapsis at the same time, see \\cref{fig:Hohmann-angle}. This happens about every 26 months.\n\t\\item Travel time for optimal Hohmann trajectory is around 260 days, or around 8.5 months.\n\\end{enumerate}\n\nThese numbers are an important approximate reference point to have when attempting to find low energy transfer orbits to Mars.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.35\\linewidth]{fig/Hohmann-angle.png}\n    \\caption{The angle that Mars travels during the Mars Hohmann transfer orbit can easily be calculated as roughly \\(136^\\degree\\), meaning the optimal launch is when Mars is \\(44^\\degree\\) ahead of Earth in orbit (Image: \\cite{Stern}).}\n    \\label{fig:Hohmann-angle}\n\\end{figure}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.85\\linewidth]{fig/mars-arrival-orbit.png}\n    \\caption{Various closed orbits upon arrival depending on applied $\\Delta v$ (Image: \\cite[p.~137]{Rapp2016} (modified)).}\n    \\label{fig:mars-arrival-orbit}\n\\end{figure}\n\n\\clearpage\n\n\\subsection{Earth-Mars Transfer in 3D}\n\\subsubsection{Ignored Complications}\nIn the section above there are a number of complications that we have ignored. For example, Earth and Mars have different eccentricities (0.0167 vs. 0.0934) meaning that its angular velocity changes considerably depending on whether it is near perihelion or aphelion at the time of transfer. For a better estimate we can no longer consider the orbit to be circular. \\cite{Braeuniga} gives a great analysis of the Earth-Mars Hohmann transfer orbit in 3D.\n\n\n\\subsubsection{Launch into The Right Plane – Actual Hohmann Transfer Orbit in 3D}\nIn the previous section we detailed the important patched conic sections model in 2D. In our 3D simulator we will attempt something similar, but take the inclination of Mars' orbital plane into account.\n\nMars orbital inclination is $1.85^\\degree$ to the ecliptic plane. Therefore if one naively tried to rendezvous with Mars in the ecliptic plane it would be \\( 1.52\\ \\text{AU} \\cdot 1.85^\\degree \\pi / 180 = \\SI{7.4e6}{\\km} \\) away. Instead we will attempt a 3D Hohmann transfer orbit as illustrated in \\cref{fig:hohmann-transfer-orbit-3D} using the same launch parameters as was found in the 2D hohmann model in \\cref{sec:2d-patched-conic}, but allowing the \\(\\phi\\) angle to vary a bit to get slightly out of the plane.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.80\\linewidth]{fig/hohmann-transfer-orbit-3D.png}\n    \\caption{Hohmann orbit in a 3D model needs a small $\\Delta v$ in the $\\phi$ direction to get out of the plane in such a way that it will be in the orbital plane at Mars at apoapsis (Image: \\cite{Daedalis.de})}\n    \\label{fig:hohmann-transfer-orbit-3D}\n\\end{figure}\n ", "meta": {"hexsha": "a94a6dee5948bc480ca95bacdd05684744090cf0", "size": 42614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/chapters/3-Physical-Modelling.tex", "max_stars_repo_name": "GandalfSaxe/letomes", "max_stars_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/chapters/3-Physical-Modelling.tex", "max_issues_repo_name": "GandalfSaxe/letomes", "max_issues_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/chapters/3-Physical-Modelling.tex", "max_forks_repo_name": "GandalfSaxe/letomes", "max_forks_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.56, "max_line_length": 755, "alphanum_fraction": 0.6784155442, "num_tokens": 14448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6502622780350187}}
{"text": "%!TEX root = ../dokumentation.tex\n\n\\chapter{Background and Theory}\\label{cha:Background}\n\nThis chapter introduces the technologies and background that will be utilized in the following chapters. First, an introduction into formal grammars is given and the \\acf{BNF} is described. Following that, the \\ac{TPTP} language is introduced. Then the foundations of lexing and parsing are outlined. After that, Python and relevant Python packages that are used in the implementation of \\ac{Synplifier} are presented.\n\n\\section{Formal languages}\\label{sec:BackgroundFormalLanguage}\n\nThis section introduces terms and concepts in the area of formal languages that are necessary to understand \\ac{Synplifier}.\n\n\\subsection{Alphabet}\nAn alphabet is a finite, non-empty set of symbols usually represented by the uppercase sigma $\\sum$.\nAn example is the binary alphabet $\\sum = \\{0,1\\}$. \\cite{AutomataTheory.2007}\n\n\\subsection{String}\nA string, also called word, is a finite sequence of symbols from some alphabet. For example, the string \\textit{101} is a string from the binary alphabet $\\sum = \\{0,1\\}$.\nThe set of all strings over an alphabet $\\sum$ is denoted as $\\sum ^{*}$. \\cite{AutomataTheory.2007}\n\n\\subsection{Language}\nIf $\\sum$ is an alphabet and $L$ is a subset of $\\sum ^*$, then $L$ is a language over $\\sum$ \\cite{AutomataTheory.2007}.\nIf sigma is the \\ac{ASCII} alphabet $\\sum = \\{a-zA-Z,0-9,\\enspace,!,=,\\#,\\%,\\$,\\&,',(,),*,+,,,-,.,/,:,;,<,>,=,?,@,[,],\\backslash ,\\textasciicircum ,\\textunderscore ,`,\\{,\\},\\mid,\\sim\\}$, then for example the language where words can consist of $a-zA-Z$ is one language over the \\ac{ASCII} alphabet.\\\\\nIn the example the abbreviations $a-zA-Z$ and $0-9$ are used. The first abbreviation represents all alphabetic letters in lower and upper case. The second abbreviation represents all one-digit numbers.\n\n\\subsection{Finite automata}\\label{sec:BackgroundAutomata}\nA finite automaton can recognize words of a language.\nThe language represented by an automaton is the set of all accepted words.\nAn automaton consists of a set of states, a set of input symbols and a transition function.\nThe transition function takes a state and an input symbol as input and returns a state based on these input arguments.\nStates are usually represented graphically by circles and transitions by labelled arrows.\nThere are two special states: The start state and final state(s).\nThe start state is the state in which the automaton starts processing the input symbols.\nIt is represented graphically by an arrow pointing to the start state.\nFinal states are represented graphically by a second circle embedded in the circle of a state.\nStarting from the start state the automaton processes the first input symbol by evaluating the transition function that takes the start state and the first input symbol as arguments. The automaton continues to process the input data by evaluating transition functions until the automaton has read every input symbol. The input word is part of the language the automaton represents if the automaton has reached a final state. If the automaton has not reached a final state, the input words is not part of the language the automaton represents. \\cite{AutomataTheory.2007}\\\\\nDeterministic and non-deterministic automata can be distinguished.\nNon-deterministic automata can have multiple transitions for the same input.\nDeterministic automata have unambiguous transitions for a given input.\nThe concept of finite automata be applied to a lexical analysers for recognizing tokens (see section \\ref{sec:BackgroundLexer}). \\cite{AutomataTheory.2007}\\\\\nFigure \\ref{fig:FiniteAutomaton} shows an automaton consisting of the set of states $\\{z\\textsubscript{0}, z\\textsubscript{1}, z\\textsubscript{2}\\}$ and several transitions. For convenience not all transitions are printed.\nIf the first input symbol would be a zero, the automaton would transit in a so called error state which cannot be left regardless the input symbols.\\\\\nThe automaton accepts words consisting of a one, an arbitrary number of zeros and a one after that.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[->, >=stealth', shorten >= 5pt,auto, node distance = 2.5cm, semithick]\n\n\\node[initial, state] (R) {z\\textsubscript{0}};\n\\node[state] (S) [right of=R] {z\\textsubscript{1}};\n\\node[state, accepting] (T) [right of=S] {z\\textsubscript{2}};\n\n\\path (R) edge [below] node {1}(S)\n\t  (S) edge [loop, above] node{0} (S)\n\t  (S) edge [below] node {1} (T)\n\t  ;\n\\end{tikzpicture}\n\\caption{Finite automaton}\n\\label{fig:FiniteAutomaton}\n\\end{figure}\n\n\\subsection{Regular expression}\\label{sec:BackgroundRegEx}\n\nA regular expression is an algebraic description of a regular language.\nRegular expressions declare strings that are part of the language and can describe the same words that can also be represented by a finite automaton. \nIn comparison to finite automata, the words can be described in an algebraic way. \nDue to the similarities between regular expressions and finite automata, it is possible to convert regular expressions to finite automata and backwards. \nRegular expressions are often used to describe tokens that should be recognized by a lexer (see section \\ref{sec:BackgroundLexer}). \\cite{AutomataTheory.2007}\\\\\nFor example, the regular expression \\textbf{10*} denotes the language consisting of words that are made up a single 1 followed by an arbitrary number of 0's.\\\\\nGiven an alphabet $\\sum$, regular expressions are formally defined as followed \\cite{AutomataTheory.2007}:\n\\begin{enumerate}\n\\item The constants $\\epsilon$ and $\\emptyset$ are regular expressions denoting the empty string and the empty set.\n\\item If $a$ is a symbol of the alphabet $\\sum$, then $a$ is a regular expression.\n\\item If $a$ and $b$ are regular expressions, then the alternation $a|b$ (either $a$ or $b$), the concatenation $ab$ ($a$ followed by $b$) and the Kleene star $a*$ (an arbitrary number of $a's$) are regular expressions.\n\\end{enumerate}\n\n\n\\subsection{Formal grammars}\\label{sec:BackgroundGrammar}\n\nFormal grammars describe how words of a language can be generated. In comparison to regular expressions, more classes of languages can be described. While regular expressions only describe regular grammars, formal grammars are able to describe all types of grammars of the Chomsky hierarchy.\n%Grammars process data using a recursive structure.\n\n%-s Ok, aber for allem können sie viel größer Klassen von Sprachen beschreiben!\n%-...und wenn ich schon dabei bin: Machen REs das nicht auch? Nur halt anders.\n\nThe description of a grammar consists of four components:\n\n\\begin{itemize}\n\n\\item A set of symbols that defines the alphabet of the language. These symbols are called terminal symbols. The words of a language only consist of terminal symbols.\n\n\\item A set of variables called nonterminal symbols. Each nonterminal symbol represents a set of words. \n\n\\item One nonterminal symbol represents the language that is being defined. This nonterminal symbol is called the start symbol. Other nonterminal symbols help to define the language of the start symbol.\n\n\\item A set of productions/rules. They recursively describe the language. Each production consists of a nonterminal symbol on the left-hand side that is being substituted by a sequence of terminal symbols and/or other nonterminal symbols on the right-hand side. There can also be empty productions, meaning a nonterminal symbol is substituted by an empty string.\n\\end{itemize}\n\n%- ambigious grammars\n%- precedence rules?\n\n\\cite{AutomataTheory.2007}\n\n%A grammar is a list of rules that defines the relationships between tokens \\cite{LexYacc.1992}.\n%These rules are also referred to as production rules.\n%Given a start symbol, this symbol can be replaced by other symbols using the production rules.\n%Using a recursive notation, production rules define derivations for words. The derived symbols can then once again be replaced until the derivation\n%\n%s Hier sauber trennen:\n%- Die Ableitung ist eine Folge von Regelanwendungen\n%- Das abgeleitete Wort\n%- Terminale und nicht-terminale Symbole\n%Speziell: Das abgeleitete Wort ist im allgemeinen kein Symbol\n%(weder terminal noch nicht-terminal), sondern es besteht aus\n%Symbolen (und wenn die Ableitung fertig ist, nur aus Terminalsymbolen\n%\n%is a terminal symbol.  \n%Terminal symbols describe symbols that cannot be further derived. The alphabet of the described language is built by the set of terminal symbols.\n%Nonterminal symbols however can be further derived and todo ?build  merged? with the terminal symbols the vocabulary of a grammar. Nonterminal symbols and terminal symbols are disjoint. \n%\\\\\n%- Beispiel\n\n\\subsubsection{Context-free grammars}\n\nA context-free grammar is a grammar that only allows productions rules that are in the form of $V \\rightarrow \\beta$ with V being a nonterminal symbol and $\\beta$ being a sequence of nonterminal and terminal symbol with an arbitrary length.\nContext-free grammars are often the basis of a parser (see section \\ref{sec:BackgroundParser}). \\cite{AutomataTheory.2007}\n\n\\subsubsection{Reduced grammars}\n\nGrammars are called reduced if each nonterminal symbol is terminating and reachable \\cite{Cremers75}.\\\\\nGiven the set of terminal symbols $\\sum$, a nonterminal symbol $A$ is called terminating if there are productions $A \\underrightarrow{*} z$ (meaning some sequence of productions can be applied) so that $z$ can be derived from $A$ in one or multiple steps and $z \\epsilon \\sum$*. \\cite{Cremers75}\\\\\nIn other words, a nonterminal symbol $A$ is terminating if there exist production rules so that  $A$ can be replaced by a string of terminal symbols.\\\\\nGiven the set of terminal symbols $\\sum$ and the start symbol $S$, a nonterminal symbol $A$ is called reachable if there are production rules $S \\underrightarrow{*} uAv$ so that $S$ can be derived to $uAv$ and $u,v \\epsilon \\sum$*. \\cite{Cremers75}\\\\\nIn other words, a nonterminal symbol $A$ is reachable if there exist production rules so that the start symbol can be replaced by a word containing $A$.\n\n%todo beispiel\n\n\\section{\\acf{BNF}}\\label{sec:BackgroundBNF}\n\nThe \\acf{BNF} is a language to describe context-free grammars.\nIn the \\acf{BNF} nonterminal symbols are distinguished from terminal symbols by being enclosed by  angle brackets, e. g. <$TPTP\\_File$> denotes the nonterminal symbol $TPTP\\_File$.\nProductions are described using the $\"::=\"$ symbol and alternatives are specified using the $\"|\"$ symbol. \\cite{BNF.1964} \nAlternative symbols are used to conveniently describe several productions with the same left-hand side nonterminal symbol.\nAn example for a \\ac{BNF} production using an alternative symbol would be \n\\begin{verbatim}\n<TPTP_File> ::= <TPTP_Input> | <comment>\n\\end{verbatim}\nWithout using alternative symbols it would be\n\\begin{verbatim}\n<TPTP_File> ::= <TPTP_Input>\n<TPTP_File> ::= <comment>\n\\end{verbatim}\nwhich is longer than the previous notation. \nUsing the \\ac{BNF} pattern of notation whole grammars can be specified.\\\\\nThe \\ac{EBNF} extends the \\ac{BNF} with following rules:\n\n\\begin{itemize}%[noitemsep]\n\t\\item Optional expressions are surrounded by square brackets.\n\t\\item Repetition is denoted by curly brackets.\n\t\\item Parentheses are used for grouping.\n\t\\item Terminals are enclosed in quotation marks.\n\\end{itemize}\n\\label{itemize:BackgroundBNF}\n\\cite{EBNF.1977}\n\n\\section{TPTP language}\\label{sec:BackgroundTPTP}\n\nThe \\acf{TPTP} is a library of problems for \\ac{ATP}.\nProblems within the library are described in the \\ac{TPTP} language.\nThe \\ac{TPTP} language is a formal language and its syntax is specified in an \\ac{EBNF}. \\cite{Sut17}\n\nOriginally the \\ac{TPTP} used only \\ac{CNF} \\cite{Sut09}, but over the years expanded to various other types of logics including include \\ac{FOF} \\cite{Sut09}, Typed \\ac{FOF} \\cite{SS+12, BP:CADE-2013} and \\ac{THF} \\cite{SB10, KSR:PAAR-2016}.\n\nThe \\ac{TPTP} syntax uses an extended \\ac{BNF}, with distinct rules for syntax, semantic constraints, tokens, and character classes which will be described in more detail in section \\ref{sec:ConceptLexer}.\nA small tool chain based on Lex/Yacc for building a basic parser from the syntax is available \\cite{VS06}.\nWhile the \\ac{TPTP} is a major success story, the resulting syntax is large and complex.\nUnderstanding the syntax is non-trivial.\nFor new developers who want to implement ``only'' a first theorem prover for \\ac{CNF}, identifying the relevant parts of the syntax and implementing a parser is a significant barrier to entry.\n\n\n\\section{Lexing}\\label{sec:BackgroundLexer}\n\nLexing or a so-called lexical analysis is the division of input into units called tokens~\\cite{LexYacc.1992}.\\\\\nThe input is a string containing a sequence of characters.\nThe lexer groups characters of the input string into sequences that are meaningful. These sequences are called lexemes. From each lexeme, the lexer produces a token, which consists of a token name and the lexeme string. The token name is an abstract symbol which is used during parsing. \\cite{Aho.2007} \\\\\nThe tokens are then passed to the parser for syntax analysis.\nA lexer needs to distinguish different types of tokens and furthermore decide which token to use if there are multiple ones that fit the input \\cite{Mogensen.2017}.\\\\\nA simple approach to build a lexer would be building an automaton for each token definition and then test to which automata the input corresponds.\nHowever, this would be inefficient because in the worst case the input needs to pass all automata before the belonging automata is identified.\nBuilding a single automaton that tests each token simultaneously is more suitable.\nThis automaton can be built by combining all regular expressions by disjunction.\nEach final state from each regular expression is marked to know which token has been identified.\\\\\nPotentially final states overlap as a consequence of one token being a substring of another token.\nFor solving such conflicts, a lexer is separating the input in order to divide it into tokens.\nPer convention the lexer chooses the longest input that matches any token.~\\cite{Mogensen.2017} \\\\\nFurthermore, a precedence of tokens can be declared. Usually the token that is being defined first has a higher precedence and thus will be chosen if possible token matches have the same length. \\cite{Mogensen.2017}\n\nBesides of writing a lexer manually it can also be generated by a lexer generator.\nA lexer generator takes a specification of tokens as input and generates the lexer automatically. \nThe specification of the tokens is usually written using regular expressions. \n\n\\section{Parsing}\\label{sec:BackgroundParser}\n\nParsing is the process of analysing the grammatical structure of a sequence of tokens and can be used to verify that the input of the parser is part of the language that the parser accepts \\cite{Aho.2007}.\nTo do so, a parser builds a parse tree out of the tokens~\\cite{Mogensen.2017}.\\\\\nParsers can also be generated automatically.\nA parser generator takes a description of the relationship among tokens in form of a formal grammar (see section \\ref{sec:BackgroundGrammar}) as input. The output is the generated parser. \\cite{LexYacc.1992}\\\\\nDuring the syntax analysis a parser takes a string of tokens and forms a syntax tree by finding the matching derivations. The matching derivation can be found using various approaches. The approaches that are used in this report will be introduced in the following.\n\n\\subsection{Bottom-up parsing}\\label{sec:BackgroundParserBottomUp}\n\nIn bottom-up parsing a parse tree for an input string is constructed beginning at the leaves working up to the root. The idea is to reduce a string to the start symbol of a grammar, constructing a deviation in reverse.\n\\cite{Aho.2007}\\\\\nAt each reduction step, a specific substring matching the body of a production is replaced by the nonterminal at the head of that productions (reduction is reverse step of deviation).\nThe key decisions are when to reduce and what production to apply.\nThese decisions depend on the parser implementation.\nAn example for bottom-up are shift-reduce parsers that are described in the following.\n\\cite{Aho.2007}\n\\subsection{Shift-reduce parsing}\\label{sec:BackgroundParserShiftReduce}\n\nShift-reduce parsers are a class of bottom-up parsers. In shift-reduce parsing a stack is used to hold grammar symbols and an input buffer holds the rest of the input string.\nDuring parsing the input is scanned from left to right. The parser shifts zero or more input symbols on the stack until it can reduce the elements at the top of the stack. The elements at the top of the stack are reduced to the head of the corresponding production. This procedure is repeated until the stack only contains the start symbol and the input buffer is empty or an error is detected. \\cite{Aho.2007}\\\\\nThere are four actions a shift-reduce parser can perform:\n\\begin{itemize}%[noitemsep]\n\t\\item \\textbf{Shift}: Shift next input symbol on top of stack.\n\t\\item \\textbf{Reduce}: With the right end of a string to be reduced being at top of the stack and the left end of the string located within the stack, the string is replaced with a  chosen nonterminal.\n\t\\item \\textbf{Accept}: Declare that input was successfully parsed.\n\t\\item \\textbf{Error}: Detect a syntax error.\n\\end{itemize}\n\\cite{Aho.2007}\n\n%-use justified by, handle will appear on top of stack not inside, proof ...\n\nThere are two kinds of conflicts that can occur during shift-reduce parsing. A shift-reduce conflict occurs if the parser cannot decide whether to shift or reduce.\nA reduce-reduce conflict occurs if the parser cannot decide which of multiple reductions to make. \\cite{Aho.2007}\n\n%-these grammars are not in LR(k) class of grammars (non-LR grammars)\n%for example: ambiguous grammar can never be LR (if else)\n%\\cite{Aho.2007}\n\n\\subsection{LR($k$) parsing}\\label{sec:BackgroundParserLR}\n\nLR($k$) parsing is the most common type of bottom-up parsing. The L stands for left-to-right, meaning the input is read from left to right, and R stands for constructing a rightmost derivation in reverse.\nIn the context of LR parsing, the rightmost derivation refers to reducing the input to the start symbol.\nThe parameter $k$ refers to the number of inputs symbols that are used as a lookahead. When $k$ is omitted, $k = 1$ is assumed.\nAn LR parser makes shift-reduce decisions based on transitioning to different parsing states.\nAn LR parser consists of a stack and a parsing table defining parsing-action functions and goto functions.\nAn action function takes a state and an input symbol as input and defines which action to perform (Shift, Reduce, Accept, Error).\nA goto function takes a state and a nonterminal symbol as input and is used to find the next state after a reduction.\nStates represent set of items.\nAn item is a production of the grammar that the parser is based on with a dot at some position on the right-hand side of the production.\nAn item indicates how much of a right-hand side has already been seen and what the parser is expecting next to apply the production (lookahead).\nFor example $A \\rightarrow B\\cdot C$ indicates that the parsers has already read the input $B$ and expects $C$ in order to reduce the right-hand side to $A$. \\cite{Aho.2007}\\\\\nLR parsers are complex to implement, but LR parser generators can be used, which significantly reduces the effort for creating an LR parser.\n\\cite{Aho.2007}\n\n\\subsubsection{LALR parsing}\\label{sec:BackgroundParserLALR}\n\nAn LALR parser (Look-Ahead LR parser) is a simplified LR parser.\nThe simplification consists of merging items that have identical cores.\nA core is the part of the right-hand side of a production that is left of the dot. \nFor example, an LR parser would separate the items $A \\rightarrow B\\cdot C$ and $A \\rightarrow B\\cdot D$ as their core is identical but their lookahead is different.\nAn LALR parser merges the two items to one item\n$A \\rightarrow B\\cdot \\{C,D\\}$.\nNot considering the lookahead reduces the power of the parser because it might lead to reduce/reduce conflicts.\nLALR parsers are nevertheless often used because the parsing table is much smaller comparing to other LR parsing techniques  due to merging items.\n\\cite{Aho.2007}\n\n\\section{Lex and Yacc}\\label{sec:BackgroundLexYacc}\n\nLex and Yacc are tools for writing lexers and parsers. They often work together, meaning the parser uses the generated tokens from the lexer as input.\n\n\\subsection{Lex}\\label{sec:BackgroundLex}\n\nLex is a tool written in C that generates a lexer by specifying regular expressions and corresponding code fragments. The specified regular expressions are translated into a program that reads an input stream. The program partitions the input stream into strings matching the regular expressions. Once an expression is recognized the corresponding code is executed. For recognizing expressions, Lex builds a deterministic finite automaton. The automaton chooses the longest possible match if the input fits multiple specified regular expressions. \\cite{Lex}\\\\\nFlex is an open-source alternative to Lex and also compatible to Lex. \\cite{Flex}\n\n\\subsection{Yacc}\\label{sec:BackgroundYacc}\nYacc is a tool written in C that can be used for parsing the input of a computer program. \nFor generating a parser using Yacc, a specification that specifies the structure of the input has to be given. In addition to the specification of the structure, the input to the parser generator also consists of code that is invoked once a structure has been recognized. \nYacc turns the input specification into a routine that handles the input. This routine calls Lex to get tokens from the input stream and arranges them based on the specification. \\cite{Yacc}\\\\\nBison is an open-source general-purpose parser generator that can be used as an alternative to Yacc and also accepts Yacc grammars. \\cite{Bison}\n\n\\section{Python}\\label{sec:BackgroundPython}\n\nSince the use cases of \\ac{Synplifier} are all hand-created grammars of relatively small size (dozens to thousands of rules), and the algorithms do not have high complexity, we decided to implement the tool in Python 3. \nPython is a simple but powerful modern multi-paradigm language with good support and excellent libraries.\nPython is easy to learn and its power allows it to create complex applications using Python.\nLibraries that are used in the implementation \\ac{Synplifier} are introduced in the following sections.\n\n\\subsection{PLY}\\label{sec:BackgroundPythonPLY}\n\n\\acf{PLY} is an implementation of Lex and Yacc in Python. It is compatible with Python 2 and 3 and is fully implemented in Python. The goal of \\ac{PLY} is to offer a pure-Python implementation of Lex and Yacc. The implementation aims to rebuild the functionalities of Lex and Yacc and thus includes:\n\\begin{itemize}\n\\item Support for LALR parsing (see chapter \\ref{sec:BackgroundParserLALR})\n\\item Support for empty productions\n\\item Support for ambiguous grammars \n\\item Precedence rules\n\\item Error checking and recovery\n\\end{itemize}\n\n\\ac{PLY} consists of the two modules $lex.py$ and $yacc.py$ that are meant be to execute together. I. e. $yacc.py$ retrieves tokens from the input stream provided by $lex.py$. $Yacc.py$ returns an abstract syntax tree by default. However, it is possible for the user to change the output of $yacc.py$ according to his demands. \\cite{PLY}\n\\ac{PLY} is used to generate the lexer and parser for the \\ac{TPTP} syntax files.\n\n\\subsection{PyQt}\\label{sec:BackgroundPytonPyQt}\n\nPyQt is a Python binding for the cross-platform GUI framework Qt.\nIt is licensed under the GNU GPL version 3.\nQt offers a set of C++ libraries and development tools for various things including tools for building GUIs, defining regular expressions, setting up SQL databases, using NFC or interacting via Bluetooth.\nPyQt implements over 1000 of these Qt tools in Python.\nA simple GUI can be created by subclassing the QMainWindow, which provides a main window for an application.\nThe QTreeView class provides an implementation of a tree view, which can be used to display data in a hierarchically structured way. \\cite{PyQt}\n\n\\subsection{argparse}\\label{sec:BackgroundArgparse}\n\nThe Python module argparse is a module for creating command-line argument parsers.\nIt provides the means to specify input arguments and automatically creates help and usage messages.\nIt also checks if the given arguments are valid.\nFrom the specified input arguments, the module will automatically create a parser for the specified arguments. \\cite{argparse}\\\\\nThis module is used in the implementation of the command-line interface of \\ac{Synplifier}.\n\n\\subsection{Beautiful Soup}\\label{sec:BackgroundBeautifulSoup}\n\nBeautiful Soup is a Python library for extracting data out of HTML and XML files.\nThat makes it especially useful for getting information from web pages. \\cite{BeautifulSoup,BeautifulSoupDoku}\nIn \\ac{Synplifier} Beautiful soup is used to automatically extract the latest \\ac{TPTP} syntax from the HTML version on the \\ac{TPTP} website.\n", "meta": {"hexsha": "835f51b4566009a7f6a8236e1ec166d17e397013", "size": 25009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/GrundlagenUndStandDerTechnik.tex", "max_stars_repo_name": "nahku/CLDTSDocumentation", "max_stars_repo_head_hexsha": "4d4fb68583f4c01a26fa05f1807c3e618acd9ea2", "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/GrundlagenUndStandDerTechnik.tex", "max_issues_repo_name": "nahku/CLDTSDocumentation", "max_issues_repo_head_hexsha": "4d4fb68583f4c01a26fa05f1807c3e618acd9ea2", "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/GrundlagenUndStandDerTechnik.tex", "max_forks_repo_name": "nahku/CLDTSDocumentation", "max_forks_repo_head_hexsha": "4d4fb68583f4c01a26fa05f1807c3e618acd9ea2", "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": 76.9507692308, "max_line_length": 571, "alphanum_fraction": 0.7880363069, "num_tokens": 5832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.650262274285112}}
{"text": "\n\\subsection{Special lnear groups \\(SL(n, F)\\)}\n\nThe special linear group, \\(SL(n,F)\\), is the subgroup of \\(GL(n,F)\\) where the determinants are \\(1\\).\n\nThat is, \\(|M|=1\\)\n\nThese are endomorphisms, not forms.\n\n", "meta": {"hexsha": "44849799d3cb9d0ff906597833b5ca20cb98b3b5", "size": 211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/05-03-SL.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/05-03-SL.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/05-03-SL.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.1, "max_line_length": 103, "alphanum_fraction": 0.6492890995, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6500767926132661}}
{"text": "\\documentclass[12pt, titlepage, oneside]{article}\n\n\\input{settings}\n\n\\begin{document}\n\t\n\t\\textbf{ELECENG 3TQ3}\\\\\n\t\\textbf{Elston A.}\n\n\\section{Lecture 2}\n\\subsection{Counting}\n\nWe need to sometimes count the number of favorable outcomes in order to determine the probability in many cases. These types of problems can be quite complex and require combinatorics; permutations, combinations, and variations.\n\n\\b{Combinations and permuatations} are different arrangements of set elements so that with \\b{combinations the order does not matter} while with \\b{permutations the order does matter}.\n\n\\subsection{Permutations}\n\n\nPermutation is defined as all the possible arrangements of the elements. \n\n\\ex given a set \\{1,2,3\\} all the possible combinations are 123,132,213,231,312,321. There are 3*2*1 permutations of a set with 3 elements. \n\nThe total number of permutations for a set with $n$ elements is $n! = n * (n-1) * \\dots * 2 * 1$ \n\nTo think about this logically, since there are no repetition once an element has been used, it cannot be repeated. So if at first there are $n$ choices as we pick from $n$ elements, the next choice we can only pick from $n-1$ elements. So the total number of combinations we can have is $n!$.\n\nIf we were allowed to have repetitions, then we would have $n^n$ possibilities. However in general, we may only have a set of $n$ elements and need to make $m$ choices.\n\n\\ex If you have a box with 26 balls and each ball has one letter of the English alphabet. Then you try to pick 3 balls from the box without returning them to the box, many different words can you construct.\n\nThe first time you choose, you can get 26 different balls, the next you can only choose 25, and lastly you can only choose 24 different balls. So the total different types of combinations you can choose from is $26*25*24$.\n\nIn the example above we have a special case called k-permutations of $n$ or simply \n\n\\begin{align}\nn * (n-1) * \\dots * (n-k+1) = \\dfrac{n!}{(n-k)!}\n\\end{align}\n\nIf the balls were placed back into the box whenever we picked one, then we would have a total of $26*26*26 = 26^3$ or simply $n^k$.\n\n\\subsection{Combinations}\n\nFor combinations \\b{order does not matter}!. \n\nGiven $n$ objects pick $k$ regardless of order.  \n\nFor example pick $k$ shirts in the closet. How many different shirt combinations are there?\n\nThe answer is given by:\n\n\\begin{align*}\n{n \\choose k} = \\frac{n!}{k!(n-k)!} = \\frac{n(n-1)\\dots (n-k+1)}{k(k-1)\\dots1}\n\\end{align*}\n\nThere are $n * (n-1) * \\dots * (n-k+1)$ ways to pick $k$ elements out of $n$ where the order does matter. If the order does not matter then we can divide by $k!$ since there are $k!$ different orders of k elements.\n\nWhen we say the order does not matter it means that we see $\"abc\" = \"bac\"$ since they contain the same letters. So given a set of 26 lower case characters and we had to pick 3 unique characters, then we would get $\"abc\"$ or $\"bac\"$ which is simply 26*25*24, but now if we said that it does not matter which way the order is then we have\n\\begin{align*}\n \\frac{26*25*24}{3!}\n\\end{align*}\n\n\n\\subsection{Combinations with Repetition}\n\nLet's say you have 5 different ice cream and 3 scoops, how many different flavors options do you have?\n\nSince the question does not mention distinct scoops, we always assume it is not distinct. Since the ice cream flavors do not disappear after being chosen, we have a problem with repetition. The formula for such a condition is\n\n\\begin{align}\n{n + k - 1 \\choose k}  = \\frac{(n+k-1)!}{k! (n-1)!} =\n \\frac{ (n + k -1)*\\dots*n (n-1)!}{k! (n-1)!} = \\frac{(n+k-1)*\\dots*n}{k!} \n\\end{align}\n\n\\subsection{Definitions}\n\n\\b{Outcome} is any possible observation\n\n\\b{Sample Space} is all the possible distinct outcomes\n\n\\b{Procedure} is what you do in the experiment\n\n\\b{Observation} is what you record\n\n\\b{Event} is a subset of the sample space that contains favorable outcomes\n\n\\b{Event Space} is the space that contains specific outcomes. \\ex instead of recording heads or tails of two coins being thrown \\{hh,ht,th,tt\\} we could instead record the outcome based on an event. Let B0 be the event that 0 tails are present, B1 be the event that one coin is tails, B2 be the event that both coins are tails. By recording event space, you are losing resolution (meaning you know the event B1 means one coin was tails, but you cannot say th or ht), but are gaining a better understanding of your data for what you want to analyze.\n\n\n\\subsection{Mutually Exclusive }\n\nConsider an example of tossing a coin 4 times:\n\n\\{tttt,ttth,ttht,tthh,thtt,thth,thht,thhh,httt,htth,htht,hthh,hhtt,hhth,hhht,hhhh\\}\n\nLet $Bi$ be the event of having $i$ number of heads.\n\nSo to find the event $A$ which is the number of heads is less than or equal to 3 we simply have\n\\begin{align*}\nA = B0 \\u B1 \\u B2 \\u B3\n\\end{align*}\n\n\n\n\\end{document}\n\n\n", "meta": {"hexsha": "a0d184eded6b848fb07a94bfc7eecbd3fde50686", "size": 4837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture2/lec2.tex", "max_stars_repo_name": "elston-jja/EE3TQ3", "max_stars_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_stars_repo_licenses": ["MIT"], "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/lec2.tex", "max_issues_repo_name": "elston-jja/EE3TQ3", "max_issues_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_issues_repo_licenses": ["MIT"], "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/lec2.tex", "max_forks_repo_name": "elston-jja/EE3TQ3", "max_forks_repo_head_hexsha": "327a69f24b4f062d2554658405daf140daef2813", "max_forks_repo_licenses": ["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.787037037, "max_line_length": 548, "alphanum_fraction": 0.7341327269, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.6500118445757121}}
